oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

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.
3import * as Y from 'yjs'
4import assert from 'node:assert/strict'
5import { readFileSync, writeFileSync } from 'node:fs'
6const doc = new Y.Doc()
7Y.applyUpdate(doc, readFileSync(process.argv[2]))
8const root = doc.getXmlFragment('prosemirror')
9assert.equal(root.length, 1)
10const paragraph = root.get(0)
11assert.equal(paragraph.nodeName, 'paragraph')
12const text = paragraph.get(0)
13assert.equal(text.toString().replace(/<[^>]+>/g, ''), 'Native 😀 text')
14const emoji = text.toDelta().find(run => run.insert === '😀')
15assert.deepEqual(emoji.attributes.strong, {})
16assert.deepEqual(emoji.attributes.size_18, {})
17const vector = Y.encodeStateVector(doc)
18text.insert(0, 'browser ')
19writeFileSync(process.argv[3], Y.encodeStateAsUpdate(doc, vector))
20