diff --git a/packages/bridge/.babelrc b/.babelrc similarity index 64% rename from packages/bridge/.babelrc rename to .babelrc index 36dba11..bd08311 100644 --- a/packages/bridge/.babelrc +++ b/.babelrc @@ -3,6 +3,7 @@ "plugins": [ "@babel/proposal-class-properties", "@babel/proposal-object-rest-spread", - "@babel/plugin-proposal-optional-chaining" + "@babel/plugin-proposal-optional-chaining", + "@babel/plugin-transform-runtime" ] } diff --git a/README.md b/README.md index 9aec0b2..94f2846 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ const decorator = useCursor(editor) ## Backend ```ts -const { AutomergeCollaboration } = require('@hiveteams/collab-backend') +const { AutomergeCollaboration } = require('backend/index') const collabBackend = new AutomergeCollaboration(options) ``` diff --git a/lerna.json b/lerna.json deleted file mode 100644 index fabbdd9..0000000 --- a/lerna.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "lerna": "2.7.1", - "version": "0.7.30", - "npmClient": "yarn", - "useWorkspaces": true -} diff --git a/package.json b/package.json index e3ed3f4..8164e24 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,14 @@ { - "private": true, - "description": "Slate collaborative plugin & microservice", + "name": "@hiveteams/collab", + "version": "1.0.3", + "description": "Slate collaborative editing", "scripts": { - "bootstrap": "lerna bootstrap", - "version": "auto-changelog -p ./packages/bridge/package.json --template changelog-template.hbs && git add CHANGELOG.md", - "clean": "rimraf ./packages/**/lib/ && rimraf ./packages/**/tsconfig.tsbuildinfo && lerna clean --yes", - "release": "yarn prebuild && yarn build && lerna version && lerna publish from-package", - "deploy:site": "git subtree push --prefix packages/example heroku master", - "dev": "lerna run --stream build:js && concurrently \"yarn watch\" \"lerna run dev --stream\"", - "build": "lerna run build:module --stream", - "watch": "lerna run --parallel watch", - "clean:module": "lerna clean --yes", - "prebuild": "yarn clean", - "test": "lerna run test --stream", - "format": "prettier --write" + "format": "prettier --write", + "test": "jest", + "clean": "rm -rf ./build", + "build": "./node_modules/typescript/bin/tsc -p ./tsconfig.json", + "deploy": "npm run clean && npm run build && cp package.json ./build && npm publish build" }, - "workspaces": [ - "packages/*" - ], "author": "cudr", "license": "MIT", "repository": { @@ -32,19 +23,62 @@ }, "lint-staged": { "*.{js,jsx,ts,tsx,babelrc}": [ - "yarn run format", + "npm run format", "git add" ] }, "devDependencies": { + "@babel/cli": "^7.6.0", + "@babel/core": "^7.6.0", + "@babel/plugin-proposal-class-properties": "^7.5.5", + "@babel/plugin-proposal-object-rest-spread": "^7.5.5", + "@babel/plugin-proposal-optional-chaining": "^7.9.0", + "@babel/plugin-transform-runtime": "^7.17.0", + "@babel/preset-env": "^7.6.0", + "@babel/preset-typescript": "^7.6.0", "@commitlint/cli": "^9.0.1", "@commitlint/config-conventional": "^9.0.1", "auto-changelog": "^2.1.0", - "concurrently": "^4.1.2", "husky": "^3.0.5", - "lerna": "^3.20.2", + "jest": "^24.9.0", "lint-staged": "^9.2.5", "prettier": "^1.18.2", - "rimraf": "^3.0.2" + "ts-jest": "^25.4.0", + "typescript": "^4.5.5" + }, + "dependencies": { + "@types/jest": "^24.9.0", + "@types/lodash": "^4.14.178", + "@types/react": "^16.12.0", + "@types/socket.io": "^2.1.4", + "@types/socket.io-client": "1.4.32", + "@types/debug": "^4.1.7", + "automerge": "0.14.0", + "debug": "^4.3.3", + "lodash": "4.17.21", + "react": "16.12.0", + "slate": "0.73.1", + "slate-history": "0.66.0", + "socket.io": "^2.3.0" + }, + "jest": { + "preset": "ts-jest", + "moduleDirectories": [ + "node_modules", + "src" + ], + "globals": { + "ts-jest": { + "babelConfig": ".babelrc", + "tsConfig": "tsconfig.json" + } + }, + "roots": [ + "/src" + ], + "transform": { + "^.+\\.ts?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$" } } diff --git a/packages/backend/.babelrc b/packages/backend/.babelrc deleted file mode 100644 index ff47042..0000000 --- a/packages/backend/.babelrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "presets": ["@babel/preset-env", "@babel/typescript"], - "plugins": [ - "@babel/plugin-transform-runtime", - "@babel/proposal-class-properties", - "@babel/proposal-object-rest-spread", - "@babel/plugin-proposal-optional-chaining" - ] -} diff --git a/packages/backend/License.md b/packages/backend/License.md deleted file mode 100644 index 8233070..0000000 --- a/packages/backend/License.md +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License - -Copyright © 2019–2020, [George Kukushin](https://github.com/cudr) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/backend/package.json b/packages/backend/package.json deleted file mode 100644 index f8a3d6b..0000000 --- a/packages/backend/package.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "name": "@hiveteams/collab-backend", - "version": "0.7.30", - "files": [ - "lib" - ], - "main": "lib/index.js", - "types": "lib/index.d.ts", - "description": "slate-collaborative backend", - "repository": { - "type": "git", - "url": "git+https://github.com/cudr/slate-collaborative.git" - }, - "publishConfig": { - "access": "public" - }, - "author": "cudr", - "license": "MIT", - "scripts": { - "prepublishOnly": "yarn run build:module", - "build:module": "yarn run build:types && yarn run build:js", - "build:types": "tsc --emitDeclarationOnly", - "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline", - "watch": "yarn build:js -w" - }, - "dependencies": { - "@babel/plugin-proposal-optional-chaining": "^7.9.0", - "@babel/runtime": "^7.6.3", - "@hiveteams/collab-bridge": "^0.7.27", - "@types/debug": "^4.1.5", - "@types/lodash": "^4.14.150", - "@types/socket.io": "^2.1.4", - "automerge": "0.14.0", - "debug": "^4.2.0", - "lodash": "^4.17.15", - "slate": "0.72.8", - "socket.io": "^2.3.0", - "typescript": "4.5.5" - }, - "devDependencies": { - "@babel/cli": "^7.6.0", - "@babel/core": "^7.6.0", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-object-rest-spread": "^7.5.5", - "@babel/plugin-transform-runtime": "^7.6.0", - "@babel/preset-env": "^7.6.0", - "@babel/preset-typescript": "^7.6.0" - }, - "directories": { - "lib": "lib" - }, - "gitHead": "89dd1657ba1b39db298e00a380f45089b8b52a91" -} diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts deleted file mode 100644 index f25625d..0000000 --- a/packages/backend/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AutomergeCollaboration from './AutomergeCollaboration' - -export { AutomergeCollaboration } diff --git a/packages/backend/tsconfig.json b/packages/backend/tsconfig.json deleted file mode 100644 index 76f8c0f..0000000 --- a/packages/backend/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["./src/**/*"], - "compilerOptions": { - "rootDir": "./src", - "baseUrl": "./src", - "outDir": "./lib", - "composite": true, - "paths": { - "@hiveteams/collab-bridge": ["../../collab-bridge"] - } - }, - "references": [{ "path": "../bridge" }] -} diff --git a/packages/bridge/License.md b/packages/bridge/License.md deleted file mode 100644 index 8233070..0000000 --- a/packages/bridge/License.md +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License - -Copyright © 2019–2020, [George Kukushin](https://github.com/cudr) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/bridge/package.json b/packages/bridge/package.json deleted file mode 100644 index 488d180..0000000 --- a/packages/bridge/package.json +++ /dev/null @@ -1,68 +0,0 @@ -{ - "name": "@hiveteams/collab-bridge", - "version": "0.7.27", - "files": [ - "lib" - ], - "main": "lib/index.js", - "types": "lib/index.d.ts", - "description": "slate-collaborative bridge", - "repository": { - "type": "git", - "url": "git+https://github.com/cudr/slate-collaborative.git" - }, - "publishConfig": { - "access": "public" - }, - "author": "cudr", - "license": "MIT", - "scripts": { - "prepublishOnly": "yarn run build:module", - "build:module": "yarn run build:types && yarn run build:js", - "build:types": "tsc --emitDeclarationOnly", - "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline", - "watch": "yarn build:js -w", - "test": "jest" - }, - "dependencies": { - "automerge": "0.14.0", - "slate": "0.72.8", - "typescript": "4.5.5" - }, - "devDependencies": { - "@babel/cli": "^7.6.0", - "@babel/core": "^7.6.0", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-object-rest-spread": "^7.5.5", - "@babel/plugin-proposal-optional-chaining": "^7.9.0", - "@babel/preset-env": "^7.6.0", - "@babel/preset-typescript": "^7.6.0", - "@types/jest": "^24.9.0", - "jest": "^24.9.0", - "ts-jest": "^25.4.0" - }, - "directories": { - "lib": "lib" - }, - "keywords": [ - "slate", - "automerge", - "bridge" - ], - "jest": { - "preset": "ts-jest", - "globals": { - "ts-jest": { - "babelConfig": ".babelrc" - } - }, - "roots": [ - "/src" - ], - "transform": { - "^.+\\.ts?$": "ts-jest" - }, - "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$" - }, - "gitHead": "89dd1657ba1b39db298e00a380f45089b8b52a91" -} diff --git a/packages/bridge/tsconfig.json b/packages/bridge/tsconfig.json deleted file mode 100644 index f518710..0000000 --- a/packages/bridge/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["./src/**/*"], - "compilerOptions": { - "rootDir": "./src", - "outDir": "./lib", - "composite": true - } -} diff --git a/packages/client/.babelrc b/packages/client/.babelrc deleted file mode 100644 index cc4cab9..0000000 --- a/packages/client/.babelrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "presets": ["@babel/env", "@babel/react", "@babel/typescript"], - "plugins": [ - "@babel/proposal-class-properties", - "@babel/proposal-object-rest-spread", - "@babel/plugin-proposal-optional-chaining" - ] -} diff --git a/packages/client/License.md b/packages/client/License.md deleted file mode 100644 index 8233070..0000000 --- a/packages/client/License.md +++ /dev/null @@ -1,9 +0,0 @@ -The MIT License - -Copyright © 2019–2020, [George Kukushin](https://github.com/cudr) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/packages/client/package.json b/packages/client/package.json deleted file mode 100644 index faa452a..0000000 --- a/packages/client/package.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "name": "@hiveteams/collab-client", - "version": "0.7.30", - "files": [ - "lib" - ], - "main": "lib/index.js", - "types": "lib/index.d.ts", - "description": "slate-collaborative client", - "repository": { - "type": "git", - "url": "git+https://github.com/cudr/slate-collaborative.git" - }, - "publishConfig": { - "access": "public" - }, - "author": "cudr", - "license": "MIT", - "scripts": { - "prepublishOnly": "npm run build:module", - "build:module": "npm run build:types && npm run build:js", - "build:types": "tsc --emitDeclarationOnly", - "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline", - "watch": "yarn build:js -w", - "test": "DEBUG=app* jest" - }, - "dependencies": { - "@babel/plugin-proposal-optional-chaining": "^7.9.0", - "@babel/preset-react": "^7.0.0", - "@hiveteams/collab-bridge": "^0.7.27", - "automerge": "0.14.0", - "lodash": "^4.17.20", - "slate": "0.72.8", - "slate-history": "0.66.0", - "socket.io-client": "^2.3.0", - "typescript": "4.5.5" - }, - "devDependencies": { - "@babel/cli": "^7.6.0", - "@babel/core": "^7.6.0", - "@babel/plugin-proposal-class-properties": "^7.5.5", - "@babel/plugin-proposal-object-rest-spread": "^7.5.5", - "@babel/preset-env": "^7.6.0", - "@babel/preset-typescript": "^7.6.0", - "@hiveteams/collab-backend": "^0.7.30", - "@types/jest": "^24.9.0", - "@types/react": "^16.9.34", - "@types/socket.io-client": "^1.4.32", - "jest": "^26.6.3", - "ts-jest": "^26.4.4" - }, - "directories": { - "lib": "lib" - }, - "gitHead": "89dd1657ba1b39db298e00a380f45089b8b52a91", - "jest": { - "preset": "ts-jest", - "globals": { - "ts-jest": { - "babelConfig": ".babelrc" - } - }, - "roots": [ - "/src" - ], - "transform": { - "^.+\\.ts?$": "ts-jest" - }, - "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$" - } -} diff --git a/packages/client/tsconfig.json b/packages/client/tsconfig.json deleted file mode 100644 index 11681f8..0000000 --- a/packages/client/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["./src/**/*"], - "compilerOptions": { - "rootDir": "./src", - "baseUrl": "./src", - "outDir": "./lib", - "composite": true, - "paths": { - "@hiveteams/collab-bridge": ["../../collab-bridge"], - "@hiveteams/collab-backend": ["../../collab-backend"] - } - }, - "references": [{ "path": "../bridge" }, { "path": "../backend" }] -} diff --git a/packages/example/package.json b/packages/example/package.json deleted file mode 100644 index 95d8d1c..0000000 --- a/packages/example/package.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "@hiveteams/collab-example", - "version": "0.7.30", - "private": true, - "dependencies": { - "@emotion/core": "^10.0.17", - "@emotion/styled": "^10.0.17", - "@hiveteams/collab-backend": "^0.7.30", - "@hiveteams/collab-client": "^0.7.30", - "@types/faker": "^4.1.5", - "@types/is-url": "^1.2.28", - "@types/jest": "24.0.18", - "@types/node": "12.7.5", - "@types/randomcolor": "^0.5.4", - "@types/react-dom": "^16.9.6", - "concurrently": "^4.1.2", - "cross-env": "^6.0.3", - "express": "^4.17.1", - "faker": "^4.1.0", - "is-url": "^1.2.4", - "lodash": "^4.17.15", - "nodemon": "^1.19.2", - "randomcolor": "^0.5.4", - "react": "^16.9.0", - "react-dom": "^16.9.0", - "react-scripts": "3.1.2", - "slate": "0.58.3", - "slate-history": "0.58.3", - "slate-react": "0.58.3", - "typescript": "^3.8.3" - }, - "scripts": { - "start": "node server.js", - "start:cra": "react-scripts start", - "prebuild": "cp -f ./tsconfig.production.json ./tsconfig.json", - "build": "cross-env NODE_ENV=production && react-scripts build", - "dev": "concurrently \"yarn start:cra\" \"yarn serve\"", - "serve": "nodemon --watch ../backend/lib --inspect server.js" - }, - "eslintConfig": { - "extends": "react-app" - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "engines": { - "node": "12.x" - } -} diff --git a/packages/example/public/favicon.ico b/packages/example/public/favicon.ico deleted file mode 100644 index e39507c..0000000 Binary files a/packages/example/public/favicon.ico and /dev/null differ diff --git a/packages/example/public/index.html b/packages/example/public/index.html deleted file mode 100644 index ae8656d..0000000 --- a/packages/example/public/index.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - Slate-collaborative. Collaboration plugin and microservice - - - -
- - diff --git a/packages/example/public/logo192.png b/packages/example/public/logo192.png deleted file mode 100644 index b49f785..0000000 Binary files a/packages/example/public/logo192.png and /dev/null differ diff --git a/packages/example/public/logo512.png b/packages/example/public/logo512.png deleted file mode 100644 index 5063bc7..0000000 Binary files a/packages/example/public/logo512.png and /dev/null differ diff --git a/packages/example/public/manifest.json b/packages/example/public/manifest.json deleted file mode 100644 index 8be1445..0000000 --- a/packages/example/public/manifest.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "short_name": "Slate collaborative", - "name": "collaborative plugin & microservice", - "icons": [ - { - "src": "favicon.ico", - "sizes": "64x64 32x32 24x24 16x16", - "type": "image/x-icon" - }, - { - "src": "logo192.png", - "type": "image/png", - "sizes": "192x192" - }, - { - "src": "logo512.png", - "type": "image/png", - "sizes": "512x512" - } - ], - "start_url": ".", - "display": "standalone", - "theme_color": "#db7093", - "background_color": "#ffffff" -} diff --git a/packages/example/public/robots.txt b/packages/example/public/robots.txt deleted file mode 100644 index 01b0f9a..0000000 --- a/packages/example/public/robots.txt +++ /dev/null @@ -1,2 +0,0 @@ -# https://www.robotstxt.org/robotstxt.html -User-agent: * diff --git a/packages/example/server.js b/packages/example/server.js deleted file mode 100644 index a6606b7..0000000 --- a/packages/example/server.js +++ /dev/null @@ -1,39 +0,0 @@ -const { AutomergeCollaboration } = require('@hiveteams/collab-backend') -const express = require('express') - -const defaultValue = [ - { - type: 'paragraph', - children: [ - { - text: 'Hello collaborator!' - } - ] - } -] - -const PORT = process.env.PORT || 9000 - -const server = express() - .use(express.static('build')) - .listen(PORT, () => console.log(`Listening on ${PORT}`)) - -const config = { - entry: server, // or specify port to start io server - defaultValue, - saveFrequency: 2000, - onAuthRequest: async (query, socket) => { - // some query validation - return true - }, - onDocumentLoad: async pathname => { - // request initial document ValueJSON by pathnme - return defaultValue - }, - onDocumentSave: async (pathname, doc) => { - // save document - // console.log('onDocumentSave', pathname, doc) - } -} - -const connection = new AutomergeCollaboration(config) diff --git a/packages/example/src/App.tsx b/packages/example/src/App.tsx deleted file mode 100644 index 4f1400c..0000000 --- a/packages/example/src/App.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React, { useState, useEffect } from 'react' -import faker from 'faker' - -import styled from '@emotion/styled' - -import Room from './Room' - -const App = () => { - const [rooms, setRooms] = useState([]) - - const addRoom = () => setRooms(rooms.concat(faker.lorem.slug(4))) - - const removeRoom = (room: string) => () => - setRooms(rooms.filter(r => r !== room)) - - useEffect(() => { - addRoom() - }, []) - - return ( -
- - - Add Room - - - {rooms.map(room => ( - - ))} -
- ) -} - -export default App - -const Panel = styled.div` - display: flex; -` - -const Button = styled.button` - padding: 6px 14px; - display: block; - outline: none; - font-size: 14px; - max-width: 200px; - text-align: center; - color: palevioletred; - border: 2px solid palevioletred; -` - -const AddButton = styled(Button)` - margin-left: 0px; - color: violet; - margin-bottom: 10px; - border: 2px solid violet; -` diff --git a/packages/example/src/Caret.tsx b/packages/example/src/Caret.tsx deleted file mode 100644 index 8e0e59c..0000000 --- a/packages/example/src/Caret.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from 'react' - -interface Caret { - color: string - isForward: boolean - name: string -} - -const Caret: React.FC = ({ color, isForward, name }) => { - const cursorStyles = { - ...cursorStyleBase, - background: color, - left: isForward ? '100%' : '0%' - } - const caretStyles = { - ...caretStyleBase, - background: color, - left: isForward ? '100%' : '0%' - } - - caretStyles[isForward ? 'bottom' : 'top'] = 0 - - return ( - <> - - - - {name} - - - - - ) -} - -export default Caret - -const cursorStyleBase = { - position: 'absolute', - top: -2, - pointerEvents: 'none', - userSelect: 'none', - transform: 'translateY(-100%)', - fontSize: 10, - color: 'white', - background: 'palevioletred', - whiteSpace: 'nowrap' -} as any - -const caretStyleBase = { - position: 'absolute', - pointerEvents: 'none', - userSelect: 'none', - height: '1.2em', - width: 2, - background: 'palevioletred' -} as any diff --git a/packages/example/src/Client.tsx b/packages/example/src/Client.tsx deleted file mode 100644 index 92434ca..0000000 --- a/packages/example/src/Client.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import React, { useState, useEffect, useMemo } from 'react' - -import { createEditor, Node } from 'slate' -import { withHistory } from 'slate-history' -import { withReact } from 'slate-react' - -import randomColor from 'randomcolor' - -import styled from '@emotion/styled' - -import { withIOCollaboration, useCursor } from '@hiveteams/collab-client' - -import { Instance, Title, H4, Button } from './Components' - -import EditorFrame from './EditorFrame' - -import { withLinks } from './plugins/link' - -const defaultValue: Node[] = [ - { - type: 'paragraph', - children: [ - { - text: '' - } - ] - } -] - -interface ClientProps { - name: string - id: string - slug: string - removeUser: (id: any) => void -} - -const Client: React.FC = ({ id, name, slug, removeUser }) => { - const [value, setValue] = useState(defaultValue) - const [isOnline, setOnlineState] = useState(false) - - const color = useMemo( - () => - randomColor({ - luminosity: 'dark', - format: 'rgba', - alpha: 1 - }), - [] - ) - - const editor = useMemo(() => { - const slateEditor = withLinks(withReact(withHistory(createEditor()))) - - const origin = - process.env.NODE_ENV === 'production' - ? window.location.origin - : 'http://localhost:9000' - - const options = { - docId: '/' + slug, - cursorData: { - name, - color, - alphaColor: color.slice(0, -2) + '0.2)' - }, - url: `${origin}/${slug}`, - connectOpts: { - query: { - name, - token: id, - slug - } - }, - onConnect: () => setOnlineState(true), - onDisconnect: () => setOnlineState(false) - } - - return withIOCollaboration(slateEditor, options) - }, []) - - useEffect(() => { - editor.connect() - - return editor.destroy - }, []) - - const { decorate } = useCursor(editor) - - const toggleOnline = () => { - const { connect, disconnect } = editor - isOnline ? disconnect() : connect() - } - - return ( - - - <Head>Editor: {name}</Head> - <div style={{ display: 'flex', marginTop: 10, marginBottom: 10 }}> - <Button type="button" onClick={toggleOnline}> - Go {isOnline ? 'offline' : 'online'} - </Button> - <Button type="button" onClick={() => removeUser(id)}> - Remove - </Button> - </div> - - - setValue(value)} - /> - - ) -} - -export default Client - -const Head = styled(H4)` - margin-right: auto; -` diff --git a/packages/example/src/Components.tsx b/packages/example/src/Components.tsx deleted file mode 100644 index 38be5b7..0000000 --- a/packages/example/src/Components.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import styled from '@emotion/styled' - -export const RoomWrapper = styled.div` - padding-bottom: 10px; - border-bottom: 2px solid #e8e8e8; -` - -export const H4 = styled.h4` - margin: 0; - padding-right: 10px; -` - -export const Input = styled.input` - padding: 6px 14px; - font-size: 14px; - margin-top: 10px; - margin-bottom: 10px; - min-width: 240px; - outline: none; - border: 2px solid palevioletred; - margin-right: auto; -` - -export const Button = styled.button` - padding: 6px 14px; - display: block; - outline: none; - background-color: transparent; - font-size: 14px; - text-align: center; - color: palevioletred; - white-space: nowrap; - border: 2px solid palevioletred; - & + button { - margin-left: 10px; - } -` - -export const IconButton = styled(Button)((props: any) => ({ - color: props.active ? 'mediumvioletred' : 'lightpink', - border: 'none', - padding: 0 -})) - -export const Icon = styled.div`` - -export const Grid = styled.div` - display: grid; - grid-gap: 1vw; - grid-template-columns: 1fr 1fr; - @media (max-width: 767px) { - grid-template-columns: 1fr; - } -` - -export const Title = styled.div` - display: flex; - align-items: center; - margin-bottom: 10px; - @media (max-width: 767px) { - flex-wrap: wrap; - } -` - -export const Instance = styled.div<{ online: boolean }>` - background: ${props => - props.online ? 'rgba(128, 128, 128, 0.1)' : 'rgba(247, 0, 0, 0.2)'}; - padding: 20px 20px 30px; -` - -export const ClientFrame = styled.div` - box-shadow: 2px 2px 4px rgba(128, 128, 128, 0.2); - padding: 10px; - min-height: 70px; - margin-left: -10px; - margin-right: -10px; - background: white; - blockquote { - border-left: 2px solid #ddd; - margin-left: 0; - margin-right: 0; - padding-left: 10px; - color: #aaa; - font-style: italic; - } - a { - color: purple; - text-decoration: none; - } - a:visited { - color: darkmagenta; - } -` diff --git a/packages/example/src/EditorFrame.tsx b/packages/example/src/EditorFrame.tsx deleted file mode 100644 index 2db5d67..0000000 --- a/packages/example/src/EditorFrame.tsx +++ /dev/null @@ -1,189 +0,0 @@ -import React, { useCallback } from 'react' - -import { Node } from 'slate' - -import { - Slate, - ReactEditor, - Editable, - RenderLeafProps, - useSlate -} from 'slate-react' - -import { ClientFrame, IconButton, Icon } from './Components' - -import Caret from './Caret' - -import { isBlockActive, toggleBlock } from './plugins/block' -import { isMarkActive, toggleMark } from './plugins/mark' -import { isLinkActive, insertLink, unwrapLink } from './plugins/link' - -export interface EditorFrame { - editor: ReactEditor - value: Node[] - decorate: any - onChange: (value: Node[]) => void -} - -const renderElement = (props: any) => - -const EditorFrame: React.FC = ({ - editor, - value, - decorate, - onChange -}) => { - const renderLeaf = useCallback((props: any) => , [ - decorate - ]) - - return ( - - -
- - - - - - - - - - - - - -
- - -
-
- ) -} - -export default EditorFrame - -const Element: React.FC = ({ attributes, children, element }) => { - switch (element.type) { - case 'link': - return ( - - {children} - - ) - case 'block-quote': - return
{children}
- case 'bulleted-list': - return
    {children}
- case 'heading-one': - return

{children}

- case 'heading-two': - return

{children}

- case 'list-item': - return
  • {children}
  • - case 'numbered-list': - return
      {children}
    - default: - return

    {children}

    - } -} - -const Leaf: React.FC = ({ attributes, children, leaf }) => { - if (leaf.bold) { - children = {children} - } - - if (leaf.code) { - children = {children} - } - - if (leaf.italic) { - children = {children} - } - - if (leaf.underline) { - children = {children} - } - - return ( - - {leaf.isCaret ? : null} - {children} - - ) -} - -const BlockButton: React.FC = ({ format, icon }) => { - const editor = useSlate() - return ( - { - event.preventDefault() - toggleBlock(editor, format) - }} - > - {icon} - - ) -} - -const MarkButton: React.FC = ({ format, icon }) => { - const editor = useSlate() - return ( - { - event.preventDefault() - toggleMark(editor, format) - }} - > - {icon} - - ) -} - -const LinkButton = () => { - const editor = useSlate() - - const isActive = isLinkActive(editor) - - return ( - { - event.preventDefault() - - if (isActive) return unwrapLink(editor) - - const url = window.prompt('Enter the URL of the link:') - - url && insertLink(editor, url) - }} - > - link - - ) -} diff --git a/packages/example/src/Room.tsx b/packages/example/src/Room.tsx deleted file mode 100644 index b082543..0000000 --- a/packages/example/src/Room.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import React, { useState, ChangeEvent } from 'react' - -import faker from 'faker' -import debounce from 'lodash/debounce' - -import { RoomWrapper, H4, Title, Button, Grid, Input } from './Components' - -import Client from './Client' - -interface User { - id: string - name: string -} - -interface RoomProps { - slug: string - removeRoom: () => void -} - -const createUser = (): User => ({ - id: faker.random.uuid(), - name: `${faker.name.firstName()} ${faker.name.lastName()}` -}) - -const Room: React.FC = ({ slug, removeRoom }) => { - const [users, setUsers] = useState([createUser(), createUser()]) - const [roomSlug, setRoomSlug] = useState(slug) - const [isRemounted, setRemountState] = useState(false) - - const remount = debounce(() => { - setRemountState(true) - setTimeout(setRemountState, 50, false) - }, 300) - - const changeSlug = (e: ChangeEvent) => { - setRoomSlug(e.target.value) - remount() - } - - const addUser = () => setUsers(users => users.concat(createUser())) - - const removeUser = (userId: string) => - setUsers(users => users.filter((u: User) => u.id !== userId)) - - return ( - - - <H4>Document slug:</H4> - <Input type="text" value={roomSlug} onChange={changeSlug} /> - <Button type="button" onClick={addUser}> - Add random user - </Button> - <Button type="button" onClick={removeRoom}> - Remove Room - </Button> - - - {users.map((user: User) => - isRemounted ? null : ( - - ) - )} - - - ) -} - -export default Room diff --git a/packages/example/src/index.tsx b/packages/example/src/index.tsx deleted file mode 100644 index 69f4ddf..0000000 --- a/packages/example/src/index.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import React from 'react' -import ReactDOM from 'react-dom' - -import App from './App' - -ReactDOM.render(, document.getElementById('root')) diff --git a/packages/example/src/plugins/block.ts b/packages/example/src/plugins/block.ts deleted file mode 100644 index 5edeea3..0000000 --- a/packages/example/src/plugins/block.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Transforms, Editor } from 'slate' - -const LIST_TYPES: string[] = ['numbered-list', 'bulleted-list'] - -export const toggleBlock = (editor: any, format: any) => { - const isActive = isBlockActive(editor, format) - const isList = LIST_TYPES.includes(format) - - Transforms.unwrapNodes(editor, { - match: n => LIST_TYPES.includes(n.type as any), - split: true - }) - - Transforms.setNodes(editor, { - type: isActive ? 'paragraph' : isList ? 'list-item' : format - }) - - if (!isActive && isList) { - const block = { type: format, children: [] } - Transforms.wrapNodes(editor, block) - } -} - -export const isBlockActive = (editor: any, format: any) => { - const [match] = Editor.nodes(editor, { - match: n => n.type === format - }) - - return !!match -} diff --git a/packages/example/src/plugins/link.ts b/packages/example/src/plugins/link.ts deleted file mode 100644 index eef086f..0000000 --- a/packages/example/src/plugins/link.ts +++ /dev/null @@ -1,73 +0,0 @@ -import isUrl from 'is-url' - -import { Transforms, Editor, Range } from 'slate' - -export interface LinkEditor extends Editor { - insertData: (data: any) => void -} - -export const withLinks = (editor: T) => { - const e = editor as T & LinkEditor - - const { insertData, insertText, isInline } = e - - e.isInline = (element: any) => { - return element.type === 'link' ? true : isInline(element) - } - - e.insertText = (text: string) => { - if (text && isUrl(text)) { - wrapLink(editor, text) - } else { - insertText(text) - } - } - - e.insertData = (data: any) => { - const text = data.getData('text/plain') - - if (text && isUrl(text)) { - wrapLink(editor, text) - } else { - insertData(data) - } - } - - return editor -} - -export const insertLink = (editor: Editor, href: string) => { - if (editor.selection) { - wrapLink(editor, href) - } -} - -export const isLinkActive = (editor: Editor) => { - const [link] = Editor.nodes(editor, { match: n => n.type === 'link' }) - return !!link -} - -export const unwrapLink = (editor: Editor) => { - Transforms.unwrapNodes(editor, { match: n => n.type === 'link' }) -} - -export const wrapLink = (editor: Editor, href: string) => { - if (isLinkActive(editor)) { - unwrapLink(editor) - } - - const { selection } = editor - const isCollapsed = selection && Range.isCollapsed(selection) - const link = { - type: 'link', - href, - children: isCollapsed ? [{ text: href }] : [] - } - - if (isCollapsed) { - Transforms.insertNodes(editor, link) - } else { - Transforms.wrapNodes(editor, link, { split: true }) - Transforms.collapse(editor, { edge: 'end' }) - } -} diff --git a/packages/example/src/plugins/mark.ts b/packages/example/src/plugins/mark.ts deleted file mode 100644 index 453b25f..0000000 --- a/packages/example/src/plugins/mark.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Editor } from 'slate' - -export const toggleMark = (editor: Editor, format: any) => { - const isActive = isMarkActive(editor, format) - - if (isActive) { - Editor.removeMark(editor, format) - } else { - Editor.addMark(editor, format, true) - } -} - -export const isMarkActive = (editor: Editor, format: any) => { - const marks = Editor.marks(editor) - return marks ? marks[format] === true : false -} diff --git a/packages/example/src/react-app-env.d.ts b/packages/example/src/react-app-env.d.ts deleted file mode 100644 index 6431bc5..0000000 --- a/packages/example/src/react-app-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/packages/example/tsconfig.extend.json b/packages/example/tsconfig.extend.json deleted file mode 100644 index e173fa3..0000000 --- a/packages/example/tsconfig.extend.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "baseUrl": ".", - "paths": { - "@hiveteams/collab-bridge": ["../../bridge"], - "@hiveteams/collab-client": ["../../client"] - } - }, - "references": [{ "path": "../client" }, { "path": "../backend" }] -} diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.json deleted file mode 100644 index f669705..0000000 --- a/packages/example/tsconfig.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "include": [ - "src/**/*" - ], - "extends": "./tsconfig.extend.json", - "compilerOptions": { - "rootDir": "../", - "baseUrl": "./src", - "allowJs": true, - "skipLibCheck": true, - "downlevelIteration": true, - "forceConsistentCasingInFileNames": true, - "isolatedModules": true, - "resolveJsonModule": true, - "declaration": false, - "declarationMap": false, - "noEmit": true, - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "module": "esnext", - "moduleResolution": "node", - "jsx": "react" - } -} diff --git a/packages/example/tsconfig.production.json b/packages/example/tsconfig.production.json deleted file mode 100644 index b72500e..0000000 --- a/packages/example/tsconfig.production.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": "./src", - "allowJs": true, - "skipLibCheck": true, - "downlevelIteration": true, - "forceConsistentCasingInFileNames": true, - "isolatedModules": true, - "resolveJsonModule": true, - "declaration": false, - "declarationMap": false, - "noEmit": true, - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "module": "esnext", - "moduleResolution": "node", - "jsx": "react" - }, - "exclude": ["node_modules"], - "include": ["**/*.ts", "**/*.tsx"] - } - \ No newline at end of file diff --git a/packages/backend/src/AutomergeBackend.ts b/src/backend/AutomergeBackend.ts similarity index 96% rename from packages/backend/src/AutomergeBackend.ts rename to src/backend/AutomergeBackend.ts index 5caa586..9d9bf46 100644 --- a/packages/backend/src/AutomergeBackend.ts +++ b/src/backend/AutomergeBackend.ts @@ -2,12 +2,7 @@ import * as Automerge from 'automerge' import { Node } from 'slate' -import { - toCollabAction, - toSync, - SyncDoc, - CollabAction -} from '@hiveteams/collab-bridge' +import { toCollabAction, toSync, SyncDoc, CollabAction } from '../bridge/index' import { debugCollabBackend } from './utils/debug' /** diff --git a/packages/backend/src/AutomergeCollaboration.ts b/src/backend/AutomergeCollaboration.ts similarity index 98% rename from packages/backend/src/AutomergeCollaboration.ts rename to src/backend/AutomergeCollaboration.ts index aee1273..002e51e 100644 --- a/packages/backend/src/AutomergeCollaboration.ts +++ b/src/backend/AutomergeCollaboration.ts @@ -4,7 +4,7 @@ import { Node } from 'slate' import { Server } from 'http' import throttle from 'lodash/throttle' import flatten from 'lodash/flatten' -import { SyncDoc, CollabAction, toJS } from '@hiveteams/collab-bridge' +import { SyncDoc, CollabAction, toJS } from '../bridge/index' import { debugCollabBackend } from './utils/debug' import AutomergeBackend from './AutomergeBackend' import getActiveConnections from './utils/getActiveConnections' @@ -94,13 +94,13 @@ export default class AutomergeCollaboration { /** * Construct error data and call onError callback */ - private handleError(socket: SocketIO.Socket, err: Error, data: any = {}) { + private handleError(socket: SocketIO.Socket, err: unknown, data: any = {}) { const { id } = socket const { name: docId } = socket.nsp if (this.options.onError) { const document = this.backend.getDocument(docId) - this.options.onError(err, { + this.options.onError(err as Error, { user: this.userMap[id], docId, automergeDocument: document ? Automerge.save(document) : null, diff --git a/src/backend/index.ts b/src/backend/index.ts new file mode 100644 index 0000000..e6c2a40 --- /dev/null +++ b/src/backend/index.ts @@ -0,0 +1,6 @@ +import AutomergeCollaboration, { + IAutomergeMetaData +} from './AutomergeCollaboration' +import getActiveConnections from './utils/getActiveConnections' + +export { AutomergeCollaboration, IAutomergeMetaData, getActiveConnections } diff --git a/packages/backend/src/utils/debug.ts b/src/backend/utils/debug.ts similarity index 100% rename from packages/backend/src/utils/debug.ts rename to src/backend/utils/debug.ts diff --git a/packages/backend/src/utils/getActiveConnections.ts b/src/backend/utils/getActiveConnections.ts similarity index 100% rename from packages/backend/src/utils/getActiveConnections.ts rename to src/backend/utils/getActiveConnections.ts diff --git a/packages/backend/src/utils/index.ts b/src/backend/utils/index.ts similarity index 100% rename from packages/backend/src/utils/index.ts rename to src/backend/utils/index.ts diff --git a/packages/bridge/src/apply/apply.spec.ts b/src/bridge/apply/apply.spec.ts similarity index 100% rename from packages/bridge/src/apply/apply.spec.ts rename to src/bridge/apply/apply.spec.ts diff --git a/packages/bridge/src/apply/index.ts b/src/bridge/apply/index.ts similarity index 100% rename from packages/bridge/src/apply/index.ts rename to src/bridge/apply/index.ts diff --git a/packages/bridge/src/apply/node/index.ts b/src/bridge/apply/node/index.ts similarity index 100% rename from packages/bridge/src/apply/node/index.ts rename to src/bridge/apply/node/index.ts diff --git a/packages/bridge/src/apply/node/insertNode.ts b/src/bridge/apply/node/insertNode.ts similarity index 100% rename from packages/bridge/src/apply/node/insertNode.ts rename to src/bridge/apply/node/insertNode.ts diff --git a/packages/bridge/src/apply/node/mergeNode.ts b/src/bridge/apply/node/mergeNode.ts similarity index 100% rename from packages/bridge/src/apply/node/mergeNode.ts rename to src/bridge/apply/node/mergeNode.ts diff --git a/packages/bridge/src/apply/node/moveNode.ts b/src/bridge/apply/node/moveNode.ts similarity index 100% rename from packages/bridge/src/apply/node/moveNode.ts rename to src/bridge/apply/node/moveNode.ts diff --git a/packages/bridge/src/apply/node/removeNode.ts b/src/bridge/apply/node/removeNode.ts similarity index 100% rename from packages/bridge/src/apply/node/removeNode.ts rename to src/bridge/apply/node/removeNode.ts diff --git a/packages/bridge/src/apply/node/setNode.ts b/src/bridge/apply/node/setNode.ts similarity index 100% rename from packages/bridge/src/apply/node/setNode.ts rename to src/bridge/apply/node/setNode.ts diff --git a/packages/bridge/src/apply/node/splitNode.ts b/src/bridge/apply/node/splitNode.ts similarity index 100% rename from packages/bridge/src/apply/node/splitNode.ts rename to src/bridge/apply/node/splitNode.ts diff --git a/packages/bridge/src/apply/text.ts b/src/bridge/apply/text.ts similarity index 100% rename from packages/bridge/src/apply/text.ts rename to src/bridge/apply/text.ts diff --git a/packages/bridge/src/connection/connection.spec.ts b/src/bridge/connection/connection.spec.ts similarity index 100% rename from packages/bridge/src/connection/connection.spec.ts rename to src/bridge/connection/connection.spec.ts diff --git a/packages/bridge/src/convert/constants.ts b/src/bridge/convert/constants.ts similarity index 100% rename from packages/bridge/src/convert/constants.ts rename to src/bridge/convert/constants.ts diff --git a/packages/bridge/src/convert/convert.spec.ts b/src/bridge/convert/convert.spec.ts similarity index 100% rename from packages/bridge/src/convert/convert.spec.ts rename to src/bridge/convert/convert.spec.ts diff --git a/packages/bridge/src/convert/create.ts b/src/bridge/convert/create.ts similarity index 100% rename from packages/bridge/src/convert/create.ts rename to src/bridge/convert/create.ts diff --git a/packages/bridge/src/convert/index.ts b/src/bridge/convert/index.ts similarity index 100% rename from packages/bridge/src/convert/index.ts rename to src/bridge/convert/index.ts diff --git a/packages/bridge/src/convert/insert.ts b/src/bridge/convert/insert.ts similarity index 100% rename from packages/bridge/src/convert/insert.ts rename to src/bridge/convert/insert.ts diff --git a/packages/bridge/src/convert/remove.ts b/src/bridge/convert/remove.ts similarity index 100% rename from packages/bridge/src/convert/remove.ts rename to src/bridge/convert/remove.ts diff --git a/packages/bridge/src/convert/set.ts b/src/bridge/convert/set.ts similarity index 100% rename from packages/bridge/src/convert/set.ts rename to src/bridge/convert/set.ts diff --git a/packages/bridge/src/cursor/index.ts b/src/bridge/cursor/index.ts similarity index 81% rename from packages/bridge/src/cursor/index.ts rename to src/bridge/cursor/index.ts index 81e6054..5619f2f 100644 --- a/packages/bridge/src/cursor/index.ts +++ b/src/bridge/cursor/index.ts @@ -1,4 +1,4 @@ -import { Operation, Range } from 'slate' +import { BaseSetNodeOperation, Operation, Range } from 'slate' import { CursorData } from '../model' import { toJS } from '../utils' @@ -15,7 +15,9 @@ export const setCursor = ( if (!doc.cursors) doc.cursors = {} - const newCursor = cursorOps[cursorOps.length - 1]?.newProperties || {} + const newCursor = + (cursorOps[cursorOps.length - 1] as BaseSetNodeOperation) + ?.newProperties || {} if (selection) { const newCursorData = Object.assign( diff --git a/packages/bridge/src/index.ts b/src/bridge/index.ts similarity index 84% rename from packages/bridge/src/index.ts rename to src/bridge/index.ts index 8a6778a..9751586 100644 --- a/packages/bridge/src/index.ts +++ b/src/bridge/index.ts @@ -1,3 +1,4 @@ +export * from './path' export * from './apply' export * from './convert' export * from './utils' diff --git a/packages/bridge/src/model/index.ts b/src/bridge/model/index.ts similarity index 100% rename from packages/bridge/src/model/index.ts rename to src/bridge/model/index.ts diff --git a/packages/bridge/src/model/slate.ts b/src/bridge/model/slate.ts similarity index 100% rename from packages/bridge/src/model/slate.ts rename to src/bridge/model/slate.ts diff --git a/packages/bridge/src/path/index.ts b/src/bridge/path/index.ts similarity index 89% rename from packages/bridge/src/path/index.ts rename to src/bridge/path/index.ts index 024e269..6aa1c68 100644 --- a/packages/bridge/src/path/index.ts +++ b/src/bridge/path/index.ts @@ -1,8 +1,8 @@ -import { Element, Node, Path } from 'slate' +import { Element, Path } from 'slate' import { SyncValue } from '../model' -export const isTree = (node: Node): boolean => Boolean(node?.children) +export const isTree = (node: Element): boolean => Boolean(node?.children) export const getTarget = (doc: SyncValue | Element, path: Path) => { const iterate = (current: any, idx: number) => { diff --git a/packages/bridge/src/utils/hexGen.ts b/src/bridge/utils/hexGen.ts similarity index 100% rename from packages/bridge/src/utils/hexGen.ts rename to src/bridge/utils/hexGen.ts diff --git a/packages/bridge/src/utils/index.ts b/src/bridge/utils/index.ts similarity index 100% rename from packages/bridge/src/utils/index.ts rename to src/bridge/utils/index.ts diff --git a/packages/bridge/src/utils/testUtils.ts b/src/bridge/utils/testUtils.ts similarity index 100% rename from packages/bridge/src/utils/testUtils.ts rename to src/bridge/utils/testUtils.ts diff --git a/packages/bridge/src/utils/toSync.ts b/src/bridge/utils/toSync.ts similarity index 100% rename from packages/bridge/src/utils/toSync.ts rename to src/bridge/utils/toSync.ts diff --git a/packages/client/src/automerge-connector.ts b/src/client/automerge-connector.ts similarity index 99% rename from packages/client/src/automerge-connector.ts rename to src/client/automerge-connector.ts index 97f59d3..6c6a9f4 100644 --- a/packages/client/src/automerge-connector.ts +++ b/src/client/automerge-connector.ts @@ -12,7 +12,7 @@ import { setCursor, toSlateOp, CursorData -} from '@hiveteams/collab-bridge' +} from '../bridge/index' import { AutomergeEditor } from './interfaces' /** diff --git a/packages/client/src/client.spec.ts b/src/client/client.spec.ts similarity index 95% rename from packages/client/src/client.spec.ts rename to src/client/client.spec.ts index 440f752..c2f4acb 100644 --- a/packages/client/src/client.spec.ts +++ b/src/client/client.spec.ts @@ -3,10 +3,13 @@ import { createServer } from 'http' import fs from 'fs' import isEqual from 'lodash/isEqual' import { createEditor, Editor, Element, Node, Transforms } from 'slate' -import { createDoc, SyncDoc, toJS, toSlateOp } from '@hiveteams/collab-bridge' -import AutomergeCollaboration, { - IAutomergeMetaData -} from '@hiveteams/collab-backend/lib/AutomergeCollaboration' + +import { createDoc, SyncDoc, toJS, toSlateOp, getTarget } from '../bridge/index' +import { + AutomergeCollaboration, + IAutomergeMetaData, + getActiveConnections +} from '../backend/index' import withIOCollaboration from './withIOCollaboration' import { AutomergeEditor, @@ -14,8 +17,6 @@ import { SocketIOPluginOptions, WithSocketIOEditor } from './interfaces' -import { getTarget } from '@hiveteams/collab-bridge/src/path' -import getActiveConnections from '@hiveteams/collab-backend/src/utils/getActiveConnections' const connectionSlug = 'test' const docId = `/${connectionSlug}` @@ -54,13 +55,13 @@ const collabBackend = new AutomergeCollaboration({ entry: server, defaultValue: defaultSlateJson, saveFrequency: 1000, - async onAuthRequest(query) { + async onAuthRequest(query: string) { return { _id: 'test-id', name: 'Eric' } }, - async onDocumentLoad(pathname) { + async onDocumentLoad(pathname: string) { return defaultSlateJson }, - onTrace(metaData, socket, computationFn) { + onTrace(metaData: any, socket: any, computationFn: () => void) { operationTraces.push(metaData) computationFn() } diff --git a/src/client/custom-slate-types.ts b/src/client/custom-slate-types.ts new file mode 100644 index 0000000..dd61c22 --- /dev/null +++ b/src/client/custom-slate-types.ts @@ -0,0 +1,27 @@ +// This example is for an Editor with `ReactEditor` and `HistoryEditor` +import { BaseEditor, BaseRange } from 'slate' +import { HistoryEditor } from 'slate-history' + +export type CustomEditor = BaseEditor & HistoryEditor + +export type CustomElement = { + type?: string + children: CustomText[] +} + +export type CustomRange = { + isCaret?: boolean +} & BaseRange + +export type FormattedText = { text: string; bold?: boolean } + +export type CustomText = FormattedText + +declare module 'slate' { + interface CustomTypes { + Editor: CustomEditor + Element: CustomElement + Text: CustomText + Range: CustomRange + } +} diff --git a/packages/client/src/index.ts b/src/client/index.ts similarity index 100% rename from packages/client/src/index.ts rename to src/client/index.ts diff --git a/packages/client/src/interfaces.ts b/src/client/interfaces.ts similarity index 85% rename from packages/client/src/interfaces.ts rename to src/client/interfaces.ts index a936057..f03eaa9 100644 --- a/packages/client/src/interfaces.ts +++ b/src/client/interfaces.ts @@ -1,12 +1,12 @@ import Automerge from 'automerge' import { Editor } from 'slate' -import { CollabAction, CursorData, SyncDoc } from '@hiveteams/collab-bridge' +import { CollabAction, CursorData, SyncDoc } from 'bridge/index' export interface AutomergeOptions { docId: string cursorData?: CursorData preserveExternalHistory?: boolean - onError?: (msg: string | Error, data: any) => void + onError?: (msg: string | unknown, data: any) => void } export interface AutomergeEditor extends Editor { @@ -29,7 +29,7 @@ export interface AutomergeEditor extends Editor { onCursor: (data: any) => void - handleError: (err: Error | string, data?: any) => void + handleError: (err: unknown | string, data?: any) => void } export interface SocketIOPluginOptions { diff --git a/packages/client/src/test-json/deep-tree.json b/src/client/test-json/deep-tree.json similarity index 100% rename from packages/client/src/test-json/deep-tree.json rename to src/client/test-json/deep-tree.json diff --git a/packages/client/src/useCursor.ts b/src/client/useCursor.ts similarity index 97% rename from packages/client/src/useCursor.ts rename to src/client/useCursor.ts index a6a12a6..5c42252 100644 --- a/packages/client/src/useCursor.ts +++ b/src/client/useCursor.ts @@ -2,7 +2,7 @@ import { useState, useCallback, useEffect, useMemo } from 'react' import { Text, Range, Path, NodeEntry } from 'slate' -import { toJS, Cursor, Cursors } from '@hiveteams/collab-bridge' +import { toJS, Cursor, Cursors } from '../bridge/index' import useMounted from './useMounted' import { AutomergeEditor } from './interfaces' diff --git a/packages/client/src/useMounted.ts b/src/client/useMounted.ts similarity index 100% rename from packages/client/src/useMounted.ts rename to src/client/useMounted.ts diff --git a/packages/client/src/withAutomerge.ts b/src/client/withAutomerge.ts similarity index 94% rename from packages/client/src/withAutomerge.ts rename to src/client/withAutomerge.ts index 4682a59..1a36c1b 100644 --- a/packages/client/src/withAutomerge.ts +++ b/src/client/withAutomerge.ts @@ -4,7 +4,7 @@ import { Editor } from 'slate' import { AutomergeConnector } from './automerge-connector' -import { CollabAction } from '@hiveteams/collab-bridge' +import { CollabAction } from 'bridge/index' import { AutomergeEditor, AutomergeOptions, @@ -31,7 +31,7 @@ const withAutomerge = ( * Helper function for handling errors */ - editor.handleError = (err: Error | string, data: any = {}) => { + editor.handleError = (err: unknown | string, data: any = {}) => { const { onError } = options if (onError) { onError(err, data) diff --git a/packages/client/src/withIOCollaboration.ts b/src/client/withIOCollaboration.ts similarity index 100% rename from packages/client/src/withIOCollaboration.ts rename to src/client/withIOCollaboration.ts diff --git a/packages/client/src/withSocketIO.ts b/src/client/withSocketIO.ts similarity index 97% rename from packages/client/src/withSocketIO.ts rename to src/client/withSocketIO.ts index c899d7c..1cdc1c5 100644 --- a/packages/client/src/withSocketIO.ts +++ b/src/client/withSocketIO.ts @@ -1,7 +1,7 @@ import io from 'socket.io-client' import Automerge from 'automerge' -import { CollabAction } from '@hiveteams/collab-bridge' +import { CollabAction } from 'bridge/index' import { AutomergeEditor, AutomergeOptions, diff --git a/tsconfig.base.json b/tsconfig.base.json deleted file mode 100644 index a7a55f3..0000000 --- a/tsconfig.base.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "compilerOptions": { - "rootDir": ".", - "baseUrl": "./packages", - "lib": ["dom", "dom.iterable", "esnext"], - "allowSyntheticDefaultImports": true, - "declaration": true, - "skipLibCheck": true, - "declarationMap": true, - "esModuleInterop": true, - "jsx": "react", - "module": "esnext", - "moduleResolution": "node", - "sourceMap": true, - "strict": true, - "suppressImplicitAnyIndexErrors": true, - "target": "esnext" - }, - "exclude": ["node_modules"], - "include": ["**/*.ts", "**/*.tsx"] -} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c88ca87 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "rootDir": "./src", + "baseUrl": "./src", + "outDir": "./build", + "declaration": true, + "skipLibCheck": true, + "declarationMap": true, + "esModuleInterop": true, + "jsx": "react", + "sourceMap": true, + "strict": true, + "suppressImplicitAnyIndexErrors": true + }, + "exclude": ["node_modules", "build"], + "include": ["**/*.ts", "**/*.tsx"] +}