@@ -0,0 +1,65 @@
1+import * as Y from "yjs";
2+
3+export const mkYDoc = () => new Y.Doc();
4+
5+export const unsafeEq = (l) => (r) => l == r;
6+
7+export const mkYTextImpl = (initialValue) => new Y.Text(initialValue);
8+
9+export const mkYMap = () => new Y.Map();
10+
11+export const getYMapImpl = (yMap, key) => yMap.get(key);
12+export const setYMapImpl = (yMap, key, value) => yMap.set(key, value);
13+export const mkYXmlFragment = () => {
14+ const yXmlFragment = new Y.XmlFragment();
15+ return yXmlFragment;
16+};
17+
18+export const mkYXmlTextImpl = (content) => {
19+ return new Y.XmlText(content);
20+};
21+
22+export const getArray = (yDoc) => (name) => () => {
23+ console.log("yDoc", yDoc.guid);
24+ return yDoc.getArray(name);
25+};
26+
27+export const mapYArray = (fn) => (yArray) => yArray.map(fn);
28+export const mapYArrayWithIndexImpl = (fn) => (yArray) => yArray.map(fn);
29+export const toArray = (yarray) => yarray.toArray();
30+
31+export const arrayToJSONImpl = (yarray) => yarray.toJSON();
32+
33+export const xmlFragmentToJSONImpl = (xmlFragment) => xmlFragment.toJSON();
34+
35+export const unsafeObserveImpl = (yarray, handler) => {
36+ yarray.observe(handler);
37+ return () => yarray.unobserve(handler);
38+};
39+
40+export const unsafeObserveDeepImpl = (yarray, handler) => {
41+ yarray.observeDeep(handler);
42+ return () => yarray.unobserveDeep(handler);
43+};
44+
45+export const yTextToString = (yText) => yText.toString();
46+
47+export const deleteAtImpl = (yArray, index, length) => {
48+ yArray.delete(index, length);
49+};
50+
51+export const unsafePushImpl = (t, elem) => {
52+ t.push([elem]);
53+};
54+
55+export const insertYXmlFragmentImpl = (yXmlFragment, elem, index) => {
56+ yXmlFragment.insert(index, [elem]);
57+};
58+
59+export const transactImpl = (yDoc, transaction, origin) => {
60+ yDoc.transact(transaction, origin);
61+};
62+
63+export const toDOM = (yXmlFragment) => {
64+ return yXmlFragment.toDOM();
65+};