Download this file
| 1 | // Native editor interoperability: Yjs must see typed content/marks and the |
| 2 | // native engine must subsequently incorporate this browser-owned delta. |
| 3 | import * as Y from 'yjs' |
| 4 | import assert from 'node:assert/strict' |
| 5 | import { readFileSync, writeFileSync } from 'node:fs' |
| 6 | const doc = new Y.Doc() |
| 7 | Y.applyUpdate(doc, readFileSync(process.argv[2])) |
| 8 | const root = doc.getXmlFragment('prosemirror') |
| 9 | assert.equal(root.length, 1) |
| 10 | const paragraph = root.get(0) |
| 11 | assert.equal(paragraph.nodeName, 'paragraph') |
| 12 | const text = paragraph.get(0) |
| 13 | assert.equal(text.toString().replace(/<[^>]+>/g, ''), 'Native 😀 text') |
| 14 | const emoji = text.toDelta().find(run => run.insert === '😀') |
| 15 | assert.deepEqual(emoji.attributes.strong, {}) |
| 16 | assert.deepEqual(emoji.attributes.size_18, {}) |
| 17 | const vector = Y.encodeStateVector(doc) |
| 18 | text.insert(0, 'browser ') |
| 19 | writeFileSync(process.argv[3], Y.encodeStateAsUpdate(doc, vector)) |
| 20 | |