automerge-lexical 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +122 -57
- package/dist/AutomergeChangePlugin.d.ts +6 -1
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohan Shah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,75 +1,140 @@
|
|
|
1
|
-
# React + TypeScript + Vite
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Automerge Lexical Bindings
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
Collaborate on rich text documents which follow the [rich text schema](https://automerge.org/docs/reference/under-the-hood/rich-text-schema/) using Lexical.
|
|
6
5
|
|
|
7
|
-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
|
9
6
|
|
|
10
|
-
##
|
|
7
|
+
## Installation
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install automerge-lexical
|
|
11
|
+
```
|
|
13
12
|
|
|
14
|
-
##
|
|
13
|
+
## Playground
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
You can setup a fully functional example to play around with.
|
|
17
16
|
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
files: ['**/*.{ts,tsx}'],
|
|
23
|
-
extends: [
|
|
24
|
-
// Other configs...
|
|
25
|
-
|
|
26
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
-
tseslint.configs.recommendedTypeChecked,
|
|
28
|
-
// Alternatively, use this for stricter rules
|
|
29
|
-
tseslint.configs.strictTypeChecked,
|
|
30
|
-
// Optionally, add this for stylistic rules
|
|
31
|
-
tseslint.configs.stylisticTypeChecked,
|
|
32
|
-
|
|
33
|
-
// Other configs...
|
|
34
|
-
],
|
|
35
|
-
languageOptions: {
|
|
36
|
-
parserOptions: {
|
|
37
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
-
tsconfigRootDir: import.meta.dirname,
|
|
39
|
-
},
|
|
40
|
-
// other options...
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
])
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/rohankshah/automerge-lexical-plugin.git
|
|
19
|
+
```
|
|
44
20
|
|
|
21
|
+
```bash
|
|
22
|
+
pnpm install
|
|
23
|
+
pnpm build:plugin
|
|
24
|
+
pnpm dev:playground
|
|
45
25
|
```
|
|
46
26
|
|
|
47
|
-
|
|
27
|
+
The playground will run on `http://localhost:5173.`
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
This library provides a plugin which maps between Automerge documents and Lexical. At present it only supports the Automerge [rich text schema](https://automerge.org/docs/reference/under-the-hood/rich-text-schema/).
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { LexicalComposer } from "@lexical/react/LexicalComposer";
|
|
37
|
+
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
|
|
38
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
39
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
40
|
+
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
41
|
+
|
|
42
|
+
// Import automerge-lexical config and change plugin
|
|
43
|
+
import {
|
|
44
|
+
AutomergeChangePlugin,
|
|
45
|
+
automergeConfig
|
|
46
|
+
} from "automerge-lexical-plugin";
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// Obtain a DocHandle somehow
|
|
50
|
+
const docUrl = "some-doc-url";
|
|
51
|
+
const handle = repo.find(docUrl);
|
|
52
|
+
|
|
53
|
+
// wait for the handle to be ready before continuing
|
|
54
|
+
await handle.whenReady();
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import reactX from 'eslint-plugin-react-x'
|
|
52
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
56
|
+
// add path to the rich text object in the automerge document
|
|
57
|
+
const path = ["text"]
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
globalIgnores(['dist']),
|
|
59
|
+
const { initialConfig, registerSync } = automergeConfig(
|
|
56
60
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// Enable lint rules for React DOM
|
|
63
|
-
reactDom.configs.recommended,
|
|
64
|
-
],
|
|
65
|
-
languageOptions: {
|
|
66
|
-
parserOptions: {
|
|
67
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
68
|
-
tsconfigRootDir: import.meta.dirname,
|
|
69
|
-
},
|
|
70
|
-
// other options...
|
|
61
|
+
namespace: "MyEditor",
|
|
62
|
+
nodes: [],
|
|
63
|
+
theme,
|
|
64
|
+
onError(error: Error) {
|
|
65
|
+
throw error;
|
|
71
66
|
},
|
|
72
67
|
},
|
|
73
|
-
|
|
68
|
+
path,
|
|
69
|
+
docUrl
|
|
70
|
+
);
|
|
74
71
|
|
|
72
|
+
return (
|
|
73
|
+
<LexicalComposer initialConfig={initialConfig}>
|
|
74
|
+
<RichTextPlugin
|
|
75
|
+
contentEditable={<ContentEditable />}
|
|
76
|
+
placeholder={<div>Type something...</div>}
|
|
77
|
+
ErrorBoundary={LexicalErrorBoundary}
|
|
78
|
+
/>
|
|
79
|
+
<HistoryPlugin />
|
|
80
|
+
<AutomergeChangePlugin registerSync={registerSync} handle={handle} />
|
|
81
|
+
</LexicalComposer>
|
|
82
|
+
);
|
|
75
83
|
```
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## API
|
|
87
|
+
|
|
88
|
+
### `automergeConfig`
|
|
89
|
+
|
|
90
|
+
Creates a Lexical configuration object that's connected to an Automerge document.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
/**
|
|
94
|
+
* Creates an Automerge configuration for a Lexical editor.
|
|
95
|
+
*
|
|
96
|
+
* @param editorConfig - Lexical editor configuration.
|
|
97
|
+
* @param path - Path to the rich text object in the document.
|
|
98
|
+
* @param docUrl - URL of the Automerge document.
|
|
99
|
+
* @param schema - Optional, schema used to map Lexical nodes to Automerge.
|
|
100
|
+
* @returns A configuration object for the editor.
|
|
101
|
+
*/
|
|
102
|
+
automergeConfig(
|
|
103
|
+
editorConfig,
|
|
104
|
+
path,
|
|
105
|
+
docUrl,
|
|
106
|
+
schema
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `AutomergeChangePlugin`
|
|
111
|
+
|
|
112
|
+
A plugin that two way syncs between Automerge document and Lexical editor
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
interface AutomergeChangePluginProps<T> {
|
|
116
|
+
/**
|
|
117
|
+
* Registers two way synchronization between lexical and automerge
|
|
118
|
+
*
|
|
119
|
+
* @param editor - The Lexical editor instance.
|
|
120
|
+
* @param handle - The Automerge document handle.
|
|
121
|
+
* @param updateSpansConfig - Optional configuration passed to `am.updateSpans()`.
|
|
122
|
+
* @returns A cleanup function that unregisters all listeners.
|
|
123
|
+
*/
|
|
124
|
+
registerSync(
|
|
125
|
+
editor: LexicalEditor,
|
|
126
|
+
handle: DocHandle<T>,
|
|
127
|
+
updateSpansConfig?: UpdateSpansConfig
|
|
128
|
+
): () => void;
|
|
129
|
+
/**
|
|
130
|
+
* The Automerge document handle to synchronize with.
|
|
131
|
+
*/
|
|
132
|
+
handle: DocHandle<T>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
<AutomergeChangePlugin registerSync={...} handle={...} />
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
@@ -3,7 +3,12 @@ import { DocHandle } from '@automerge/automerge-repo';
|
|
|
3
3
|
import { LexicalEditor } from 'lexical';
|
|
4
4
|
interface AutomergeChangePluginProps<T> {
|
|
5
5
|
/**
|
|
6
|
-
* Registers synchronization between
|
|
6
|
+
* Registers two way synchronization between lexical and automerge
|
|
7
|
+
*
|
|
8
|
+
* @param editor - The Lexical editor instance.
|
|
9
|
+
* @param handle - The Automerge document handle.
|
|
10
|
+
* @param updateSpansConfig - Optional configuration passed to `am.updateSpans()`.
|
|
11
|
+
* @returns A cleanup function that unregisters all listeners.
|
|
7
12
|
*/
|
|
8
13
|
registerSync(editor: LexicalEditor, handle: DocHandle<T>, updateSpansConfig?: UpdateSpansConfig): () => void;
|
|
9
14
|
/**
|