-
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
1 parent
248d29d
commit 6d22eb9
Showing
18 changed files
with
3,299 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
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
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,2 +1,27 @@ | ||
# tldraw-yjs-example | ||
An example of using tldraw together with yjs. | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh | ||
|
||
## Expanding the ESLint configuration | ||
|
||
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules: | ||
|
||
- Configure the top-level `parserOptions` property like this: | ||
|
||
```js | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
project: ['./tsconfig.json', './tsconfig.node.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
``` | ||
|
||
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked` | ||
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked` | ||
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
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,32 @@ | ||
{ | ||
"name": "tldraw-yjs-example", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "concurrently \"vite\" \"HOST=localhost PORT=1234 npx y-websocket\" --kill-others", | ||
"build": "tsc && vite build", | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@tldraw/tldraw": "^2.0.0-canary.c7ae756c0b81", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"y-websocket": "^1.5.0", | ||
"yjs": "^13.6.7" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.15", | ||
"@types/react-dom": "^18.2.7", | ||
"@typescript-eslint/eslint-plugin": "^6.0.0", | ||
"@typescript-eslint/parser": "^6.0.0", | ||
"@vitejs/plugin-react": "^4.0.3", | ||
"concurrently": "^8.2.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.3", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.4.5" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,49 @@ | ||
import { Tldraw, track, useEditor } from '@tldraw/tldraw' | ||
import '@tldraw/tldraw/tldraw.css' | ||
import { useYjsStore } from './useYjsStore' | ||
|
||
const HOST_URL = | ||
import.meta.env.MODE === 'development' | ||
? 'ws://localhost:1234' | ||
: 'wss://demos.yjs.dev' | ||
|
||
export default function YjsExample() { | ||
const store = useYjsStore({ | ||
roomId: 'example6', | ||
hostUrl: HOST_URL, | ||
}) | ||
|
||
return ( | ||
<div className="tldraw__editor"> | ||
<Tldraw autoFocus store={store} shareZone={<NameEditor />} /> | ||
</div> | ||
) | ||
} | ||
|
||
const NameEditor = track(() => { | ||
const editor = useEditor() | ||
|
||
const { color, name } = editor.user | ||
|
||
return ( | ||
<div style={{ pointerEvents: 'all', display: 'flex' }}> | ||
<input | ||
type="color" | ||
value={color} | ||
onChange={(e) => { | ||
editor.user.updateUserPreferences({ | ||
color: e.currentTarget.value, | ||
}) | ||
}} | ||
/> | ||
<input | ||
value={name} | ||
onChange={(e) => { | ||
editor.user.updateUserPreferences({ | ||
name: e.currentTarget.value, | ||
}) | ||
}} | ||
/> | ||
</div> | ||
) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,64 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap'); | ||
|
||
html, | ||
body { | ||
padding: 0; | ||
margin: 0; | ||
font-family: 'Inter', sans-serif; | ||
overscroll-behavior: none; | ||
touch-action: none; | ||
min-height: 100vh; | ||
font-size: 16px; | ||
/* mobile viewport bug fix */ | ||
min-height: -webkit-fill-available; | ||
height: 100%; | ||
} | ||
|
||
html, | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
.tldraw__editor { | ||
position: fixed; | ||
inset: 0px; | ||
overflow: hidden; | ||
} | ||
|
||
.examples { | ||
padding: 16px; | ||
} | ||
|
||
.examples__header { | ||
width: fit-content; | ||
padding-bottom: 32px; | ||
} | ||
|
||
.examples__lockup { | ||
height: 56px; | ||
width: auto; | ||
} | ||
|
||
.examples__list { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 0; | ||
margin: 0; | ||
list-style: none; | ||
} | ||
|
||
.examples__list__item { | ||
padding: 8px 12px; | ||
margin: 0px -12px; | ||
} | ||
|
||
.examples__list__item a { | ||
padding: 8px 12px; | ||
margin: 0px -12px; | ||
text-decoration: none; | ||
color: inherit; | ||
} | ||
|
||
.examples__list__item a:hover { | ||
text-decoration: underline; | ||
} |
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,10 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.tsx' | ||
import './index.css' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) |
Oops, something went wrong.