Skip to content

Commit 890c144

Browse files
committed
Update to automerge-repo 2.1.0
1 parent 9f142a4 commit 890c144

24 files changed

Lines changed: 4409 additions & 4415 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ let editorConfig = {
2121
```
2222

2323
## Contributors
24+
2425
- @alexjg
2526
- @brianhung

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ const adapter = new SchemaAdapter({
8787
This schema adapter can then be passed to `init` as an option:
8888

8989
```typescript
90-
const { pmDoc, schema, plugin } = init(handle, ["text"], { schemaAdapter: adapter })
90+
const { pmDoc, schema, plugin } = init(handle, ["text"], {
91+
schemaAdapter: adapter,
92+
})
9193
```
9294

9395
There are a number of keys available in the `automerge` mapping. To understand what they all mean you need to understand the goals of schema mapping:

examples/react/package-lock.json

Lines changed: 1408 additions & 976 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/react/package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"@automerge/automerge": "^2.2.1",
14-
"@automerge/automerge-repo": "^1.1.9",
15-
"@automerge/automerge-repo-network-broadcastchannel": "^1.1.9",
16-
"@automerge/automerge-repo-network-websocket": "^1.1.9",
17-
"@automerge/automerge-repo-react-hooks": "^1.1.9",
18-
"@automerge/automerge-repo-storage-indexeddb": "^1.1.9",
19-
"@automerge/prosemirror": "^0.0.12",
20-
"prosemirror-example-setup": "^1.2.2",
21-
"prosemirror-model": "^1.20.0",
13+
"@automerge/automerge": "^3.0.0",
14+
"@automerge/automerge-repo": "^2.1.0",
15+
"@automerge/automerge-repo-network-broadcastchannel": "^2.1.0",
16+
"@automerge/automerge-repo-network-websocket": "^2.1.0",
17+
"@automerge/automerge-repo-react-hooks": "^2.1.0",
18+
"@automerge/automerge-repo-storage-indexeddb": "^2.1.0",
19+
"@automerge/prosemirror": "file://../../",
20+
"prosemirror-example-setup": "^1.2.3",
21+
"prosemirror-model": "^1.25.2",
2222
"prosemirror-state": "^1.4.3",
23-
"prosemirror-view": "^1.33.5",
23+
"prosemirror-view": "^1.40.1",
2424
"react": "^18.2.0",
2525
"react-dom": "^18.2.0"
2626
},

examples/react/src/App.tsx

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
11
import { AutomergeUrl } from "@automerge/automerge-repo"
2-
import { useHandle } from "@automerge/automerge-repo-react-hooks"
3-
import { useEffect, useRef, useState } from "react"
2+
import { useDocHandle } from "@automerge/automerge-repo-react-hooks"
3+
import { useEffect, useRef } from "react"
44
import { EditorState, Transaction } from "prosemirror-state"
55
import { EditorView } from "prosemirror-view"
66
import { exampleSetup } from "prosemirror-example-setup"
7-
import {
8-
syncPlugin,
9-
pmDocFromSpans,
10-
basicSchemaAdapter,
11-
} from "@automerge/prosemirror"
12-
import { next as am } from "@automerge/automerge"
7+
import { init, basicSchemaAdapter } from "@automerge/prosemirror"
138
import "prosemirror-example-setup/style/style.css"
149
import "prosemirror-menu/style/menu.css"
1510
import "prosemirror-view/style/prosemirror.css"
1611
import "./App.css"
1712

1813
function App({ docUrl }: { docUrl: AutomergeUrl }) {
1914
const editorRoot = useRef<HTMLDivElement>(null)
20-
const handle = useHandle<{ text: string }>(docUrl)
21-
const [loaded, setLoaded] = useState(handle && handle.docSync() != null)
22-
useEffect(() => {
23-
if (handle != null) {
24-
handle.whenReady().then(() => {
25-
if (handle.docSync() != null) {
26-
setLoaded(true)
27-
}
28-
})
29-
}
30-
}, [handle])
15+
const handle = useDocHandle<{ text: string }>(docUrl)
3116

3217
useEffect(() => {
33-
const adapter = basicSchemaAdapter
3418
let view: EditorView
35-
if (editorRoot.current != null && loaded) {
19+
20+
if (editorRoot.current != null && handle != null) {
21+
const { pmDoc, schema, plugin } = init(handle, ["text"], {
22+
schemaAdapter: basicSchemaAdapter,
23+
})
3624
view = new EditorView(editorRoot.current, {
3725
state: EditorState.create({
38-
schema: adapter.schema, // It's important that we use the schema from the mirror
39-
plugins: [
40-
...exampleSetup({ schema: adapter.schema }),
41-
syncPlugin({ adapter, handle, path: ["text"] }),
42-
],
26+
schema, // It's important that we use the schema from the mirror
27+
plugins: [...exampleSetup({ schema }), plugin],
4328
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44-
doc: pmDocFromSpans(adapter, am.spans(handle.docSync()!, ["text"])),
29+
doc: pmDoc,
4530
}),
4631
dispatchTransaction: (tx: Transaction) => {
4732
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -54,7 +39,7 @@ function App({ docUrl }: { docUrl: AutomergeUrl }) {
5439
view.destroy()
5540
}
5641
}
57-
}, [editorRoot, loaded, handle])
42+
}, [editorRoot, handle])
5843

5944
return <div id="editor" ref={editorRoot}></div>
6045
}

examples/react/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const repo = new Repo({
1919
const rootDocUrl = `${document.location.hash.substring(1)}`
2020
let handle
2121
if (isValidAutomergeUrl(rootDocUrl)) {
22-
handle = repo.find(rootDocUrl)
22+
handle = await repo.find(rootDocUrl)
2323
} else {
2424
handle = repo.create({ text: "hello world" })
2525
}

examples/react/vite.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineConfig } from "vite"
22
import react from "@vitejs/plugin-react"
33
import wasm from "vite-plugin-wasm"
4+
import path from "path"
45

56
export default defineConfig({
67
// customize this to your repo name for github pages deploy
@@ -14,4 +15,30 @@ export default defineConfig({
1415
format: "es",
1516
plugins: () => [wasm()],
1617
},
18+
19+
// This is only necessary because we are using the local prosemirror build.
20+
// This leads to issues where multiple instances of prosemirror-model are
21+
// loaded, which breaks prosemirror. In a real application you don't need to
22+
// do this
23+
resolve: {
24+
alias: {
25+
"@automerge/prosemirror": path.resolve(__dirname, "../../dist"),
26+
"prosemirror-model": path.resolve(
27+
__dirname,
28+
"../../node_modules/prosemirror-model",
29+
),
30+
"prosemirror-state": path.resolve(
31+
__dirname,
32+
"../../node_modules/prosemirror-state",
33+
),
34+
"prosemirror-view": path.resolve(
35+
__dirname,
36+
"../../node_modules/prosemirror-view",
37+
),
38+
"prosemirror-transform": path.resolve(
39+
__dirname,
40+
"../../node_modules/prosemirror-transform",
41+
),
42+
},
43+
},
1744
})

0 commit comments

Comments
 (0)