generated from qq15725/starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,849 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,63 @@ | ||
<h1 align="center">starter-ts</h1> | ||
<h1 align="center">Vue CRDT</h1> | ||
|
||
<p align="center"> | ||
<a href="https://unpkg.com/starter-ts"> | ||
<img src="https://img.shields.io/bundlephobia/minzip/starter-ts" alt="Minzip"> | ||
<a href="https://unpkg.com/vue-crdt"> | ||
<img src="https://img.shields.io/bundlephobia/minzip/vue-crdt" alt="Minzip"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/starter-ts"> | ||
<img src="https://img.shields.io/npm/v/starter-ts.svg" alt="Version"> | ||
<a href="https://www.npmjs.com/package/vue-crdt"> | ||
<img src="https://img.shields.io/npm/v/vue-crdt.svg" alt="Version"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/starter-ts"> | ||
<img src="https://img.shields.io/npm/dm/starter-ts" alt="Downloads"> | ||
<a href="https://www.npmjs.com/package/vue-crdt"> | ||
<img src="https://img.shields.io/npm/dm/vue-crdt" alt="Downloads"> | ||
</a> | ||
<a href="https://github.com/qq15725/starter-ts/issues"> | ||
<img src="https://img.shields.io/github/issues/qq15725/starter-ts" alt="Issues"> | ||
<a href="https://github.com/qq15725/vue-crdt/issues"> | ||
<img src="https://img.shields.io/github/issues/qq15725/vue-crdt" alt="Issues"> | ||
</a> | ||
<a href="https://github.com/qq15725/starter-ts/blob/main/LICENSE"> | ||
<img src="https://img.shields.io/npm/l/starter-ts.svg" alt="License"> | ||
<a href="https://github.com/qq15725/vue-crdt/blob/main/LICENSE"> | ||
<img src="https://img.shields.io/npm/l/vue-crdt.svg" alt="License"> | ||
</a> | ||
</p> | ||
|
||
## Try it now! | ||
## 📦 Install | ||
|
||
### GitHub Template | ||
```shell | ||
npm i vue-crdt | ||
``` | ||
|
||
|
||
## 🦄 Usage | ||
|
||
```ts | ||
import { reactive, ref } from 'vue' | ||
import { defineStore, useHistory } from 'vue-crdt' | ||
|
||
const useEditorStore = defineStore(doc => { | ||
// use y-webrtc | ||
// | ||
// new WebrtcProvider( | ||
// 'your-room-name', | ||
// doc, | ||
// { password: 'optional-room-password' }, | ||
// ) | ||
|
||
return { | ||
workspace: reactive({ | ||
pages: { a: 'b' }, | ||
activePage: null, | ||
}), | ||
width: ref(800), | ||
height: ref(600), | ||
} | ||
}) | ||
|
||
[Create a repo from this template on GitHub](https://github.com/qq15725/starter-ts/generate). | ||
const { workspace, width, height } = useEditorStore() | ||
|
||
### Clone to local | ||
const history = useHistory(workspace) | ||
|
||
If you prefer to do it manually with the cleaner git history | ||
workspace.activePage = 123 | ||
history.stopCapturing() | ||
workspace.activePage = 456 | ||
history.undo() | ||
|
||
```bash | ||
npx degit qq15725/starter-ts my-ts-lib | ||
cd my-ts-lib | ||
pnpm i # If you don't have pnpm installed, run: npm install -g pnpm | ||
console.log(workspace) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "docs", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vue-tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"vue": "^3.3.13" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^4.5.2", | ||
"typescript": "^5.2.2", | ||
"vite": "^5.0.8", | ||
"vue-tsc": "^1.8.25" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script setup lang="ts"> | ||
import { reactive, ref } from 'vue' | ||
import { WebrtcProvider } from 'y-webrtc' | ||
import { defineStore, useHistory } from '../../src' | ||
// clients connected to the same room-name share document updates | ||
const useDocStore = defineStore(doc => { | ||
new WebrtcProvider( | ||
'your-room-name', | ||
doc, | ||
{ password: 'optional-room-password' }, | ||
) | ||
const workspace = reactive({ | ||
pages: { a: 'b' }, | ||
activePage: null, | ||
}) | ||
const width = ref(0) | ||
const height = ref(0) | ||
const test2 = ref([]) | ||
return { workspace, width, height, test2 } | ||
}) | ||
const { workspace, width, height, test2 } = useDocStore() | ||
const { canUndo, canRedo, undo, redo, sync, reset } = useHistory(workspace) | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div> | ||
<div>{{ workspace.activePage }}</div> | ||
<input v-model="workspace.activePage"> | ||
<div> | ||
<button :disabled="!canUndo" @click="undo()">undo</button> | ||
<button :disabled="!canRedo" @click="redo()">redo</button> | ||
<button @click="sync()">sync</button> | ||
<button @click="reset()">reset</button> | ||
</div> | ||
</div> | ||
<div>{{ width }}</div> <input v-model="width"> | ||
<div>{{ height }}</div> <input v-model="height"> | ||
<div>{{ test2 }}</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createApp } from 'vue' | ||
import App from './App.vue' | ||
createApp(App).mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [vue()], | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.