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 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
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
2
+ # Automerge Lexical Bindings
4
3
 
5
- Currently, two official plugins are available:
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
- ## React Compiler
7
+ ## Installation
11
8
 
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
9
+ ```bash
10
+ npm install automerge-lexical
11
+ ```
13
12
 
14
- ## Expanding the ESLint configuration
13
+ ## Playground
15
14
 
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
15
+ You can setup a fully functional example to play around with.
17
16
 
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
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
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
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
- ```js
50
- // eslint.config.js
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
- export default defineConfig([
55
- globalIgnores(['dist']),
59
+ const { initialConfig, registerSync } = automergeConfig(
56
60
  {
57
- files: ['**/*.{ts,tsx}'],
58
- extends: [
59
- // Other configs...
60
- // Enable lint rules for React
61
- reactX.configs['recommended-typescript'],
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 a Lexical editor and an Automerge document.
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
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "automerge-lexical",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "main": "./dist/automerge-lexical-plugin.es.js",
7
7
  "module": "./dist/automerge-lexical-plugin.es.js",