@pluv/crdt-loro 4.0.0 → 4.0.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/.turbo/turbo-build.log +21 -14
- package/CHANGELOG.md +17 -0
- package/README.md +24 -1
- package/dist/{index.d.mts → browser.d.mts} +23 -21
- package/dist/browser.d.mts.map +1 -0
- package/dist/{index.mjs → browser.mjs} +47 -55
- package/dist/browser.mjs.map +1 -0
- package/dist/chunk-BBjsoOtd.mjs +27 -0
- package/dist/node.mjs +336 -0
- package/dist/node.mjs.map +1 -0
- package/package.json +26 -13
- package/src/counter.ts +1 -1
- package/src/doc/CrdtLoroDoc.ts +5 -5
- package/src/doc/CrdtLoroDocFactory.ts +1 -1
- package/src/doc/builder.ts +2 -2
- package/src/list.ts +2 -2
- package/src/loro-runtime.browser.ts +1 -0
- package/src/loro-runtime.node.ts +1 -0
- package/src/map.ts +2 -2
- package/src/movableList.ts +2 -2
- package/src/object.ts +2 -2
- package/src/text.ts +1 -1
- package/src/tree.ts +1 -1
- package/tsconfig.json +4 -1
- package/tsconfig.node.build.json +8 -0
- package/tsdown.browser.config.ts +14 -0
- package/tsdown.config.ts +3 -13
- package/tsdown.node.config.ts +15 -0
- package/dist/chunk-15K8U1wQ.mjs +0 -18
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/node.mjs
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
2
|
+
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/loro-runtime.node.ts
|
|
30
|
+
var loro_runtime_node_exports = /* @__PURE__ */ __exportAll({});
|
|
31
|
+
import * as import_loro_crdt_nodejs from "loro-crdt/nodejs";
|
|
32
|
+
__reExport(loro_runtime_node_exports, import_loro_crdt_nodejs);
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/counter.ts
|
|
35
|
+
const counter = () => {
|
|
36
|
+
return new loro_runtime_node_exports.LoroCounter();
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/doc/builder.ts
|
|
40
|
+
const builder = (doc) => {
|
|
41
|
+
return {
|
|
42
|
+
counter(name) {
|
|
43
|
+
return doc.getCounter(name);
|
|
44
|
+
},
|
|
45
|
+
list(name, value = []) {
|
|
46
|
+
const list = doc.getList(name);
|
|
47
|
+
value.forEach((item, i) => {
|
|
48
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) list.insertContainer(i, item);
|
|
49
|
+
else list.insert(i, item);
|
|
50
|
+
});
|
|
51
|
+
return list;
|
|
52
|
+
},
|
|
53
|
+
map(name, value = {}) {
|
|
54
|
+
const container = doc.getMap(name);
|
|
55
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
56
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) container.setContainer(key, item);
|
|
57
|
+
else container.set(key, item);
|
|
58
|
+
});
|
|
59
|
+
return container;
|
|
60
|
+
},
|
|
61
|
+
moveableList(name, value = []) {
|
|
62
|
+
const list = doc.getMovableList(name);
|
|
63
|
+
value.forEach((item, i) => {
|
|
64
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) list.insertContainer(i, item);
|
|
65
|
+
else list.insert(i, item);
|
|
66
|
+
});
|
|
67
|
+
return list;
|
|
68
|
+
},
|
|
69
|
+
text(name, value = "") {
|
|
70
|
+
const text = doc.getText(name);
|
|
71
|
+
text.insert(0, value);
|
|
72
|
+
return text;
|
|
73
|
+
},
|
|
74
|
+
tree(name) {
|
|
75
|
+
return doc.getTree(name);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/doc/CrdtLoroDoc.ts
|
|
81
|
+
const MAX_UNDO_STEPS = 100;
|
|
82
|
+
const MERGE_INTERVAL_MS = 1e3;
|
|
83
|
+
const PLUV_ID_FIELD = "__$pluv";
|
|
84
|
+
var CrdtLoroDoc = class {
|
|
85
|
+
value = new loro_runtime_node_exports.LoroDoc();
|
|
86
|
+
#_storage;
|
|
87
|
+
#_undoManager = null;
|
|
88
|
+
constructor(params = () => ({})) {
|
|
89
|
+
const storage = params(builder(this.value));
|
|
90
|
+
const keys = Object.keys(this.value.toJSON()).reduce((set, key) => set.add(key), /* @__PURE__ */ new Set());
|
|
91
|
+
this.#_storage = Object.entries(storage).reduce((acc, [key, node]) => keys.has(key) ? {
|
|
92
|
+
...acc,
|
|
93
|
+
[key]: node
|
|
94
|
+
} : acc, {});
|
|
95
|
+
if (!!Object.keys(storage).length) this.#_setPluvId();
|
|
96
|
+
this.value.commit();
|
|
97
|
+
}
|
|
98
|
+
applyEncodedState(params) {
|
|
99
|
+
const update = typeof params.update === "string" ? toUint8Array(params.update) : params.update;
|
|
100
|
+
if (!update) return this;
|
|
101
|
+
this.value.import(update);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
batchApplyEncodedState(params) {
|
|
105
|
+
const filtered = (params.updates ?? []).reduce((acc, update) => {
|
|
106
|
+
if (!update) return acc;
|
|
107
|
+
if (typeof update === "string") {
|
|
108
|
+
acc.push(toUint8Array(update));
|
|
109
|
+
return acc;
|
|
110
|
+
}
|
|
111
|
+
if (typeof update === "object") {
|
|
112
|
+
acc.push(update);
|
|
113
|
+
return acc;
|
|
114
|
+
}
|
|
115
|
+
return acc;
|
|
116
|
+
}, []);
|
|
117
|
+
if (!filtered.length) return this;
|
|
118
|
+
if (filtered.length === 1) {
|
|
119
|
+
const update = filtered[0] ?? null;
|
|
120
|
+
if (!!update) this.value.import(update);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
this.value.importBatch(filtered);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
canRedo() {
|
|
127
|
+
if (!this.#_undoManager) return false;
|
|
128
|
+
return this.#_undoManager.canRedo();
|
|
129
|
+
}
|
|
130
|
+
canUndo() {
|
|
131
|
+
if (!this.#_undoManager) return false;
|
|
132
|
+
return this.#_undoManager.canUndo();
|
|
133
|
+
}
|
|
134
|
+
destroy() {}
|
|
135
|
+
get(key) {
|
|
136
|
+
if (typeof key === "undefined") return this.#_storage;
|
|
137
|
+
return this.#_storage[key];
|
|
138
|
+
}
|
|
139
|
+
getEncodedState() {
|
|
140
|
+
return fromUint8Array(this.value.export({ mode: "snapshot" }));
|
|
141
|
+
}
|
|
142
|
+
toJson(type) {
|
|
143
|
+
if (typeof type === "string") {
|
|
144
|
+
const container = this.#_storage[type];
|
|
145
|
+
return container instanceof loro_runtime_node_exports.LoroText ? container.toString() : container instanceof loro_runtime_node_exports.LoroCounter ? container.value : container.toJSON();
|
|
146
|
+
}
|
|
147
|
+
return Object.entries(this.#_storage).reduce((acc, [key, value]) => ({
|
|
148
|
+
...acc,
|
|
149
|
+
[key]: value instanceof loro_runtime_node_exports.LoroText ? value.toString() : value.toJSON()
|
|
150
|
+
}), {});
|
|
151
|
+
}
|
|
152
|
+
isEmpty() {
|
|
153
|
+
const serialized = this.value.toJSON();
|
|
154
|
+
return !serialized || !Object.keys(serialized).length;
|
|
155
|
+
}
|
|
156
|
+
rebuildStorage(reference) {
|
|
157
|
+
if (!!Object.keys(this.#_storage).length) {
|
|
158
|
+
console.warn("Attempted to rebuild storage multiple times");
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
this.#_storage = Object.entries(reference).reduce((acc, [key, node]) => {
|
|
162
|
+
if (node instanceof loro_runtime_node_exports.LoroCounter) return {
|
|
163
|
+
...acc,
|
|
164
|
+
[key]: this.value.getCounter(key)
|
|
165
|
+
};
|
|
166
|
+
if (node instanceof loro_runtime_node_exports.LoroList) return {
|
|
167
|
+
...acc,
|
|
168
|
+
[key]: this.value.getList(key)
|
|
169
|
+
};
|
|
170
|
+
if (node instanceof loro_runtime_node_exports.LoroMap) return {
|
|
171
|
+
...acc,
|
|
172
|
+
[key]: this.value.getMap(key)
|
|
173
|
+
};
|
|
174
|
+
if (node instanceof loro_runtime_node_exports.LoroMovableList) return {
|
|
175
|
+
...acc,
|
|
176
|
+
[key]: this.value.getMovableList(key)
|
|
177
|
+
};
|
|
178
|
+
if (node instanceof loro_runtime_node_exports.LoroText) return {
|
|
179
|
+
...acc,
|
|
180
|
+
[key]: this.value.getText(key)
|
|
181
|
+
};
|
|
182
|
+
if (node instanceof loro_runtime_node_exports.LoroTree) return {
|
|
183
|
+
...acc,
|
|
184
|
+
[key]: this.value.getTree(key)
|
|
185
|
+
};
|
|
186
|
+
return acc;
|
|
187
|
+
}, {});
|
|
188
|
+
return this.track();
|
|
189
|
+
}
|
|
190
|
+
redo() {
|
|
191
|
+
this.#_undoManager?.redo();
|
|
192
|
+
return this;
|
|
193
|
+
}
|
|
194
|
+
subscribe(listener) {
|
|
195
|
+
const fn = (event) => {
|
|
196
|
+
const update = fromUint8Array(this.value.export({ mode: "update" }));
|
|
197
|
+
listener({
|
|
198
|
+
doc: this,
|
|
199
|
+
local: event.by === "local",
|
|
200
|
+
origin: event.origin ? String(event.origin) : null,
|
|
201
|
+
update
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
return Object.values(this.#_storage).reduce((acc, crdtType) => {
|
|
205
|
+
const unsubscribe = crdtType.subscribe(fn);
|
|
206
|
+
return () => {
|
|
207
|
+
acc();
|
|
208
|
+
unsubscribe();
|
|
209
|
+
};
|
|
210
|
+
}, () => void 0);
|
|
211
|
+
}
|
|
212
|
+
track() {
|
|
213
|
+
if (this.#_undoManager) {
|
|
214
|
+
this.#_undoManager.clear();
|
|
215
|
+
this.#_undoManager.free();
|
|
216
|
+
this.#_undoManager = null;
|
|
217
|
+
}
|
|
218
|
+
this.#_undoManager = new loro_runtime_node_exports.UndoManager(this.value, {
|
|
219
|
+
maxUndoSteps: MAX_UNDO_STEPS,
|
|
220
|
+
mergeInterval: MERGE_INTERVAL_MS
|
|
221
|
+
});
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @description Unlike Yjs, this method is required to be called after each loro operation.
|
|
226
|
+
* @date January 12, 2025
|
|
227
|
+
*/
|
|
228
|
+
transact(fn) {
|
|
229
|
+
fn();
|
|
230
|
+
this.value.commit();
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
undo() {
|
|
234
|
+
this.#_undoManager?.undo();
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
#_setPluvId() {
|
|
238
|
+
const text = this.value.getText(PLUV_ID_FIELD);
|
|
239
|
+
const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
|
|
240
|
+
text.insert(0, id);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/doc/CrdtLoroDocFactory.ts
|
|
245
|
+
var CrdtLoroDocFactory = class CrdtLoroDocFactory extends AbstractCrdtDocFactory {
|
|
246
|
+
_initialStorage;
|
|
247
|
+
constructor(initialStorage = () => ({})) {
|
|
248
|
+
super(initialStorage);
|
|
249
|
+
this._initialStorage = initialStorage;
|
|
250
|
+
}
|
|
251
|
+
getEmpty() {
|
|
252
|
+
return new CrdtLoroDoc();
|
|
253
|
+
}
|
|
254
|
+
getFactory(initialStorage) {
|
|
255
|
+
return new CrdtLoroDocFactory(initialStorage ?? this._initialStorage);
|
|
256
|
+
}
|
|
257
|
+
getInitialized(initialStorage) {
|
|
258
|
+
return new CrdtLoroDoc(initialStorage ?? this._initialStorage);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/doc/doc.ts
|
|
263
|
+
const doc = (value = () => ({})) => {
|
|
264
|
+
return new CrdtLoroDocFactory(value);
|
|
265
|
+
};
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region src/list.ts
|
|
268
|
+
const list = (value = []) => {
|
|
269
|
+
const container = new loro_runtime_node_exports.LoroList();
|
|
270
|
+
value.forEach((item, i) => {
|
|
271
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) container.insertContainer(i, item);
|
|
272
|
+
else container.insert(i, item);
|
|
273
|
+
});
|
|
274
|
+
return container;
|
|
275
|
+
};
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/map.ts
|
|
278
|
+
const map = (value = []) => {
|
|
279
|
+
const container = new loro_runtime_node_exports.LoroMap();
|
|
280
|
+
value.forEach(([key, item]) => {
|
|
281
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) container.setContainer(key, item);
|
|
282
|
+
else container.set(key, item);
|
|
283
|
+
});
|
|
284
|
+
return container;
|
|
285
|
+
};
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/movableList.ts
|
|
288
|
+
const movableList = (value = []) => {
|
|
289
|
+
const container = new loro_runtime_node_exports.LoroMovableList();
|
|
290
|
+
value.forEach((item, i) => {
|
|
291
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) container.insertContainer(i, item);
|
|
292
|
+
else container.insert(i, item);
|
|
293
|
+
});
|
|
294
|
+
return container;
|
|
295
|
+
};
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/object.ts
|
|
298
|
+
const object = (value) => {
|
|
299
|
+
const container = new loro_runtime_node_exports.LoroMap();
|
|
300
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
301
|
+
if ((0, loro_runtime_node_exports.isContainer)(item)) container.setContainer(key, item);
|
|
302
|
+
else container.set(key, item);
|
|
303
|
+
});
|
|
304
|
+
return container;
|
|
305
|
+
};
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/text.ts
|
|
308
|
+
const text = (value = "") => {
|
|
309
|
+
const container = new loro_runtime_node_exports.LoroText();
|
|
310
|
+
container.insert(0, value);
|
|
311
|
+
return container;
|
|
312
|
+
};
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/tree.ts
|
|
315
|
+
const tree = () => {
|
|
316
|
+
return new loro_runtime_node_exports.LoroTree();
|
|
317
|
+
};
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/loro.ts
|
|
320
|
+
var loro_exports = /* @__PURE__ */ __exportAll({
|
|
321
|
+
CrdtLoroDoc: () => CrdtLoroDoc,
|
|
322
|
+
counter: () => counter,
|
|
323
|
+
doc: () => doc,
|
|
324
|
+
kind: () => kind,
|
|
325
|
+
list: () => list,
|
|
326
|
+
map: () => map,
|
|
327
|
+
movableList: () => movableList,
|
|
328
|
+
object: () => object,
|
|
329
|
+
text: () => text,
|
|
330
|
+
tree: () => tree
|
|
331
|
+
});
|
|
332
|
+
const kind = "loro";
|
|
333
|
+
//#endregion
|
|
334
|
+
export { loro_exports as loro };
|
|
335
|
+
|
|
336
|
+
//# sourceMappingURL=node.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.mjs","names":["LoroCounter","LoroDoc","#_storage","#_setPluvId","#_undoManager","LoroText","LoroCounter","LoroList","LoroMap","LoroMovableList","LoroTree","container","UndoManager","LoroList","LoroMap","LoroMovableList","LoroMap","LoroText","LoroTree"],"sources":["../src/loro-runtime.node.ts","../src/counter.ts","../src/doc/builder.ts","../src/doc/CrdtLoroDoc.ts","../src/doc/CrdtLoroDocFactory.ts","../src/doc/doc.ts","../src/list.ts","../src/map.ts","../src/movableList.ts","../src/object.ts","../src/text.ts","../src/tree.ts","../src/loro.ts"],"sourcesContent":["export * from \"loro-crdt/nodejs\";\n","import { LoroCounter } from \"@loro-runtime\";\nimport { LoroType } from \"./types\";\n\nexport const counter = (): LoroCounter => {\n const counter = new LoroCounter();\n\n return counter as unknown as LoroType<LoroCounter, number>;\n};\n","import type {\n Container,\n LoroCounter,\n LoroDoc,\n LoroList,\n LoroMap,\n LoroMovableList,\n LoroText,\n} from \"@loro-runtime\";\nimport { isContainer } from \"@loro-runtime\";\nimport type { LoroType } from \"../types\";\n\nexport type LoroBuilder = ReturnType<typeof builder>;\n\nexport const builder = (doc: LoroDoc) => {\n return {\n counter(name: string): LoroCounter {\n return doc.getCounter(name);\n },\n list<T extends unknown>(\n name: string,\n value: T[] | readonly T[] = [],\n ): LoroType<LoroList<T>, T[]> {\n const list = doc.getList(name);\n\n value.forEach((item, i) => {\n if (isContainer(item)) list.insertContainer(i, item);\n else list.insert(i, item as Exclude<T, Container>);\n });\n\n return list as unknown as LoroType<LoroList<T>, T[]>;\n },\n map<T extends Record<string, unknown>>(\n name: string,\n value: T = {} as T,\n ): LoroType<LoroMap<T>, T> {\n const container = doc.getMap(name);\n\n Object.entries(value).forEach(([key, item]) => {\n if (isContainer(item)) container.setContainer(key, item);\n else container.set(key, item as Exclude<T, Container>);\n });\n\n return container as unknown as LoroType<LoroMap<T>, T>;\n },\n moveableList<T extends unknown>(\n name: string,\n value: T[] | readonly T[] = [],\n ): LoroType<LoroMovableList<T>, T[]> {\n const list = doc.getMovableList(name);\n\n value.forEach((item, i) => {\n if (isContainer(item)) list.insertContainer(i, item);\n else list.insert(i, item as Exclude<T, Container>);\n });\n\n return list as unknown as LoroType<LoroMovableList<T>, T[]>;\n },\n text(name: string, value: string = \"\"): LoroType<LoroText, string> {\n const text = doc.getText(name);\n\n text.insert(0, value);\n\n return text as unknown as LoroType<LoroText, string>;\n },\n tree(name: string) {\n return doc.getTree(name);\n },\n };\n};\n","import type {\n DocApplyEncodedStateParams,\n DocBatchApplyEncodedStateParams,\n DocSubscribeCallbackParams,\n InferCrdtJson,\n} from \"@pluv/crdt\";\nimport type { CrdtDocLike } from \"@pluv/types\";\nimport { fromUint8Array, toUint8Array } from \"js-base64\";\nimport type { Container } from \"@loro-runtime\";\nimport {\n LoroCounter,\n LoroDoc,\n LoroEventBatch,\n LoroList,\n LoroMap,\n LoroMovableList,\n LoroText,\n LoroTree,\n UndoManager,\n} from \"@loro-runtime\";\nimport type { LoroType } from \"../types\";\nimport type { LoroBuilder } from \"./builder\";\nimport { builder } from \"./builder\";\n\nconst MAX_UNDO_STEPS = 100;\nconst MERGE_INTERVAL_MS = 1_000;\nconst PLUV_ID_FIELD = \"__$pluv\";\n\nexport type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>>> = (\n builder: LoroBuilder,\n) => TStorage;\n\nexport class CrdtLoroDoc<\n TStorage extends Record<string, LoroType<any, any>>,\n> implements CrdtDocLike<LoroDoc, TStorage> {\n public value: LoroDoc = new LoroDoc();\n\n #_storage: TStorage;\n #_undoManager: UndoManager | null = null;\n\n constructor(params: CrdtLoroDocParams<TStorage> = () => ({}) as TStorage) {\n const storage = params(builder(this.value));\n\n const keys = Object.keys(this.value.toJSON()).reduce(\n (set, key) => set.add(key),\n new Set<string>(),\n );\n\n this.#_storage = Object.entries(storage).reduce(\n (acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),\n {} as TStorage,\n );\n if (!!Object.keys(storage).length) this.#_setPluvId();\n\n this.value.commit();\n }\n\n public applyEncodedState(params: DocApplyEncodedStateParams): this {\n const update =\n typeof params.update === \"string\" ? toUint8Array(params.update) : params.update;\n\n if (!update) return this;\n\n this.value.import(update);\n\n return this;\n }\n\n public batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this {\n const updates = params.updates ?? [];\n\n const filtered = updates.reduce<Uint8Array[]>((acc, update) => {\n if (!update) return acc;\n\n if (typeof update === \"string\") {\n acc.push(toUint8Array(update));\n return acc;\n }\n\n if (typeof update === \"object\") {\n acc.push(update);\n return acc;\n }\n\n return acc;\n }, []);\n\n if (!filtered.length) return this;\n\n if (filtered.length === 1) {\n const update = filtered[0] ?? null;\n\n if (!!update) this.value.import(update);\n\n return this;\n }\n\n this.value.importBatch(filtered);\n\n return this;\n }\n\n public canRedo(): boolean {\n if (!this.#_undoManager) return false;\n\n return this.#_undoManager.canRedo();\n }\n\n public canUndo(): boolean {\n if (!this.#_undoManager) return false;\n\n return this.#_undoManager.canUndo();\n }\n\n public destroy(): void {\n return;\n }\n\n public get(key?: undefined): TStorage;\n public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];\n public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {\n if (typeof key === \"undefined\") return this.#_storage;\n\n return this.#_storage[key as TKey];\n }\n\n public getEncodedState(): string {\n return fromUint8Array(this.value.export({ mode: \"snapshot\" }));\n }\n\n public toJson(): InferCrdtJson<TStorage>;\n public toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;\n public toJson<TKey extends keyof TStorage>(type?: TKey) {\n if (typeof type === \"string\") {\n const container = this.#_storage[type] as unknown as Container;\n\n return container instanceof LoroText\n ? container.toString()\n : container instanceof LoroCounter\n ? container.value\n : container.toJSON!();\n }\n\n return Object.entries(this.#_storage).reduce(\n (acc, [key, value]) => ({\n ...(acc as any),\n [key]: value instanceof LoroText ? value.toString() : value.toJSON!(),\n }),\n {} as InferCrdtJson<TStorage>,\n );\n }\n\n public isEmpty(): boolean {\n const serialized = this.value.toJSON();\n\n return !serialized || !Object.keys(serialized).length;\n }\n\n public rebuildStorage(reference: TStorage): this {\n const isBuilt = !!Object.keys(this.#_storage).length;\n\n if (isBuilt) {\n console.warn(\"Attempted to rebuild storage multiple times\");\n return this;\n }\n\n this.#_storage = Object.entries(reference).reduce((acc, [key, node]) => {\n if (node instanceof LoroCounter) return { ...acc, [key]: this.value.getCounter(key) };\n if (node instanceof LoroList) return { ...acc, [key]: this.value.getList(key) };\n if (node instanceof LoroMap) return { ...acc, [key]: this.value.getMap(key) };\n if (node instanceof LoroMovableList) {\n return { ...acc, [key]: this.value.getMovableList(key) };\n }\n if (node instanceof LoroText) return { ...acc, [key]: this.value.getText(key) };\n if (node instanceof LoroTree) return { ...acc, [key]: this.value.getTree(key) };\n\n return acc;\n }, {} as TStorage);\n\n return this.track();\n }\n\n public redo(): this {\n this.#_undoManager?.redo();\n\n return this;\n }\n\n public subscribe(\n listener: (params: DocSubscribeCallbackParams<LoroDoc, TStorage>) => void,\n ): () => void {\n const fn = (event: LoroEventBatch) => {\n const update = fromUint8Array(this.value.export({ mode: \"update\" }));\n\n listener({\n doc: this,\n local: event.by === \"local\",\n origin: event.origin ? String(event.origin) : null,\n update,\n });\n };\n\n const unsubcribeAll = Object.values(this.#_storage).reduce<() => void>(\n (acc, crdtType) => {\n const container = crdtType as unknown as Container;\n const unsubscribe = container.subscribe(fn);\n\n return () => {\n acc();\n unsubscribe();\n };\n },\n () => undefined,\n );\n\n return unsubcribeAll;\n }\n\n public track(): this {\n if (this.#_undoManager) {\n this.#_undoManager.clear();\n this.#_undoManager.free();\n\n this.#_undoManager = null;\n }\n\n this.#_undoManager = new UndoManager(this.value, {\n maxUndoSteps: MAX_UNDO_STEPS,\n mergeInterval: MERGE_INTERVAL_MS,\n });\n\n return this;\n }\n\n /**\n * @description Unlike Yjs, this method is required to be called after each loro operation.\n * @date January 12, 2025\n */\n public transact(fn: () => void): this {\n fn();\n\n this.value.commit();\n\n return this;\n }\n\n public undo(): this {\n this.#_undoManager?.undo();\n\n return this;\n }\n\n #_setPluvId() {\n const text = this.value.getText(PLUV_ID_FIELD);\n const id = typeof crypto !== \"undefined\" ? crypto.randomUUID() : Math.random().toString();\n\n text.insert(0, id);\n }\n}\n","import { AbstractCrdtDocFactory } from \"@pluv/crdt\";\nimport type { LoroDoc } from \"@loro-runtime\";\nimport type { LoroType } from \"../types\";\nimport { CrdtLoroDoc } from \"./CrdtLoroDoc\";\nimport type { LoroBuilder } from \"./builder\";\n\nexport class CrdtLoroDocFactory<\n TStorage extends Record<string, LoroType<any, any>>,\n> extends AbstractCrdtDocFactory<LoroDoc, TStorage> {\n public readonly _initialStorage: (builder: LoroBuilder) => TStorage;\n\n constructor(initialStorage: (builder: LoroBuilder) => TStorage = () => ({}) as TStorage) {\n super(initialStorage);\n\n this._initialStorage = initialStorage;\n }\n\n public getEmpty(): CrdtLoroDoc<TStorage> {\n return new CrdtLoroDoc<TStorage>();\n }\n\n public getFactory(\n initialStorage?: ((builder: LoroBuilder) => TStorage) | undefined,\n ): CrdtLoroDocFactory<TStorage> {\n return new CrdtLoroDocFactory<TStorage>(initialStorage ?? this._initialStorage);\n }\n\n public getInitialized(\n initialStorage?: (builder: LoroBuilder) => TStorage,\n ): CrdtLoroDoc<TStorage> {\n return new CrdtLoroDoc<TStorage>(initialStorage ?? this._initialStorage);\n }\n}\n","import type { LoroType } from \"../types\";\nimport type { LoroBuilder } from \"./builder\";\nimport { CrdtLoroDocFactory } from \"./CrdtLoroDocFactory\";\n\nexport const doc = <TStorage extends Record<string, LoroType<any, any>>>(\n value: (builder: LoroBuilder) => TStorage = () => ({}) as TStorage,\n): CrdtLoroDocFactory<TStorage> => {\n return new CrdtLoroDocFactory<TStorage>(value);\n};\n","import type { Container } from \"@loro-runtime\";\nimport { LoroList, isContainer } from \"@loro-runtime\";\nimport type { LoroType } from \"./types\";\n\nexport const list = <T extends unknown>(\n value: T[] | readonly T[] = [],\n): LoroType<LoroList<T>, T[]> => {\n const container = new LoroList();\n\n value.forEach((item, i) => {\n if (isContainer(item)) container.insertContainer(i, item);\n else container.insert(i, item as Exclude<T, Container>);\n });\n\n return container as unknown as LoroType<LoroList<T>, T[]>;\n};\n","import type { Container } from \"@loro-runtime\";\nimport { LoroMap, isContainer } from \"@loro-runtime\";\nimport type { LoroType } from \"./types\";\n\nexport const map = <T extends unknown>(\n value: readonly (readonly [key: string, value: T])[] = [],\n): LoroType<LoroMap<Record<string, T>>, Record<string, T>> => {\n const container = new LoroMap();\n\n value.forEach(([key, item]) => {\n if (isContainer(item)) container.setContainer(key, item);\n else container.set(key, item as Exclude<T, Container>);\n });\n\n return container as unknown as LoroType<LoroMap<Record<string, T>>, Record<string, T>>;\n};\n","import type { Container } from \"@loro-runtime\";\nimport { isContainer, LoroMovableList } from \"@loro-runtime\";\nimport type { LoroType } from \"./types\";\n\nexport const movableList = <T extends unknown>(value: T[] | readonly T[] = []) => {\n const container = new LoroMovableList();\n\n value.forEach((item, i) => {\n if (isContainer(item)) container.insertContainer(i, item);\n else container.insert(i, item as Exclude<T, Container>);\n });\n\n return container as unknown as LoroType<LoroMovableList<T>, T[]>;\n};\n","import type { Container } from \"@loro-runtime\";\nimport { LoroMap, isContainer } from \"@loro-runtime\";\nimport type { LoroType } from \"./types\";\n\nexport const object = <T extends Record<string, any>>(value: T): LoroType<LoroMap<T>, T> => {\n const container = new LoroMap();\n\n Object.entries(value).forEach(([key, item]) => {\n if (isContainer(item)) container.setContainer(key, item);\n else container.set(key, item as Exclude<T, Container>);\n });\n\n return container as unknown as LoroType<LoroMap<T>, T>;\n};\n","import { LoroText } from \"@loro-runtime\";\nimport type { LoroType } from \"./types\";\n\nexport const text = (value: string = \"\"): LoroType<LoroText, string> => {\n const container = new LoroText();\n\n container.insert(0, value);\n\n return container as unknown as LoroType<LoroText, string>;\n};\n","import { LoroTree } from \"@loro-runtime\";\n\nexport const tree = <T extends Record<string, unknown>>() => {\n const container = new LoroTree<T>();\n\n return container;\n};\n","export { counter } from \"./counter\";\nexport { CrdtLoroDoc, doc } from \"./doc\";\nexport type { LoroBuilder } from \"./doc\";\nexport { list } from \"./list\";\nexport { map } from \"./map\";\nexport { movableList } from \"./movableList\";\nexport { object } from \"./object\";\nexport { text } from \"./text\";\nexport { tree } from \"./tree\";\nexport type { LoroType } from \"./types\";\nexport const kind = \"loro\" as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACGA,MAAa,gBAA6B;CAGtC,OAAO,IAFaA,0BAAAA,YAEP;AACjB;;;ACOA,MAAa,WAAW,QAAiB;CACrC,OAAO;EACH,QAAQ,MAA2B;GAC/B,OAAO,IAAI,WAAW,IAAI;EAC9B;EACA,KACI,MACA,QAA4B,CAAC,GACH;GAC1B,MAAM,OAAO,IAAI,QAAQ,IAAI;GAE7B,MAAM,SAAS,MAAM,MAAM;IACvB,KAAA,GAAA,0BAAA,YAAA,CAAgB,IAAI,GAAG,KAAK,gBAAgB,GAAG,IAAI;SAC9C,KAAK,OAAO,GAAG,IAA6B;GACrD,CAAC;GAED,OAAO;EACX;EACA,IACI,MACA,QAAW,CAAC,GACW;GACvB,MAAM,YAAY,IAAI,OAAO,IAAI;GAEjC,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,UAAU;IAC3C,KAAA,GAAA,0BAAA,YAAA,CAAgB,IAAI,GAAG,UAAU,aAAa,KAAK,IAAI;SAClD,UAAU,IAAI,KAAK,IAA6B;GACzD,CAAC;GAED,OAAO;EACX;EACA,aACI,MACA,QAA4B,CAAC,GACI;GACjC,MAAM,OAAO,IAAI,eAAe,IAAI;GAEpC,MAAM,SAAS,MAAM,MAAM;IACvB,KAAA,GAAA,0BAAA,YAAA,CAAgB,IAAI,GAAG,KAAK,gBAAgB,GAAG,IAAI;SAC9C,KAAK,OAAO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{
|
|
6
6
|
"email": "david@pluv.io",
|
|
@@ -15,34 +15,47 @@
|
|
|
15
15
|
"directory": "packages/crdt-loro"
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
-
"types": "./dist/
|
|
18
|
+
"types": "./dist/browser.d.mts",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@types/node": "^25.
|
|
23
|
+
"@types/node": "^25.9.2",
|
|
24
24
|
"js-base64": "^3.7.8",
|
|
25
|
-
"@pluv/crdt": "^4.0.
|
|
26
|
-
"@pluv/types": "^4.0.
|
|
25
|
+
"@pluv/crdt": "^4.0.2",
|
|
26
|
+
"@pluv/types": "^4.0.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"loro-crdt": "^1.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"eslint": "^
|
|
33
|
-
"loro-crdt": "^1.
|
|
34
|
-
"tsdown": "0.
|
|
32
|
+
"eslint": "^10.4.1",
|
|
33
|
+
"loro-crdt": "^1.13.1",
|
|
34
|
+
"tsdown": "0.22.2",
|
|
35
35
|
"typescript": "^5.9.3",
|
|
36
|
-
"@pluv/tsconfig": "^4.0.
|
|
37
|
-
"eslint-config-pluv": "^4.0.
|
|
36
|
+
"@pluv/tsconfig": "^4.0.2",
|
|
37
|
+
"eslint-config-pluv": "^4.0.2"
|
|
38
38
|
},
|
|
39
39
|
"exports": {
|
|
40
|
-
".":
|
|
40
|
+
".": {
|
|
41
|
+
"types": "./dist/browser.d.mts",
|
|
42
|
+
"browser": "./dist/browser.mjs",
|
|
43
|
+
"node": "./dist/node.mjs",
|
|
44
|
+
"default": "./dist/browser.mjs"
|
|
45
|
+
},
|
|
46
|
+
"./browser": {
|
|
47
|
+
"types": "./dist/browser.d.mts",
|
|
48
|
+
"default": "./dist/browser.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./node": {
|
|
51
|
+
"types": "./dist/browser.d.mts",
|
|
52
|
+
"default": "./dist/node.mjs"
|
|
53
|
+
},
|
|
41
54
|
"./*": "./*"
|
|
42
55
|
},
|
|
43
56
|
"scripts": {
|
|
44
|
-
"build": "tsdown",
|
|
45
|
-
"dev": "tsdown --watch",
|
|
57
|
+
"build": "tsdown --config tsdown.browser.config.ts && tsdown --config tsdown.node.config.ts",
|
|
58
|
+
"dev": "tsdown --config tsdown.browser.config.ts --watch",
|
|
46
59
|
"lint": "eslint \"src/**/*.ts*\" --fix --max-warnings 0",
|
|
47
60
|
"typecheck": "tsc --noEmit",
|
|
48
61
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
package/src/counter.ts
CHANGED
package/src/doc/CrdtLoroDoc.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
} from "@pluv/crdt";
|
|
7
7
|
import type { CrdtDocLike } from "@pluv/types";
|
|
8
8
|
import { fromUint8Array, toUint8Array } from "js-base64";
|
|
9
|
-
import type { Container } from "loro-
|
|
9
|
+
import type { Container } from "@loro-runtime";
|
|
10
10
|
import {
|
|
11
11
|
LoroCounter,
|
|
12
12
|
LoroDoc,
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
LoroText,
|
|
18
18
|
LoroTree,
|
|
19
19
|
UndoManager,
|
|
20
|
-
} from "loro-
|
|
20
|
+
} from "@loro-runtime";
|
|
21
21
|
import type { LoroType } from "../types";
|
|
22
22
|
import type { LoroBuilder } from "./builder";
|
|
23
23
|
import { builder } from "./builder";
|
|
@@ -30,9 +30,9 @@ export type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>
|
|
|
30
30
|
builder: LoroBuilder,
|
|
31
31
|
) => TStorage;
|
|
32
32
|
|
|
33
|
-
export class CrdtLoroDoc<
|
|
34
|
-
|
|
35
|
-
{
|
|
33
|
+
export class CrdtLoroDoc<
|
|
34
|
+
TStorage extends Record<string, LoroType<any, any>>,
|
|
35
|
+
> implements CrdtDocLike<LoroDoc, TStorage> {
|
|
36
36
|
public value: LoroDoc = new LoroDoc();
|
|
37
37
|
|
|
38
38
|
#_storage: TStorage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractCrdtDocFactory } from "@pluv/crdt";
|
|
2
|
-
import type { LoroDoc } from "loro-
|
|
2
|
+
import type { LoroDoc } from "@loro-runtime";
|
|
3
3
|
import type { LoroType } from "../types";
|
|
4
4
|
import { CrdtLoroDoc } from "./CrdtLoroDoc";
|
|
5
5
|
import type { LoroBuilder } from "./builder";
|
package/src/doc/builder.ts
CHANGED
|
@@ -6,8 +6,8 @@ import type {
|
|
|
6
6
|
LoroMap,
|
|
7
7
|
LoroMovableList,
|
|
8
8
|
LoroText,
|
|
9
|
-
} from "loro-
|
|
10
|
-
import { isContainer } from "loro-
|
|
9
|
+
} from "@loro-runtime";
|
|
10
|
+
import { isContainer } from "@loro-runtime";
|
|
11
11
|
import type { LoroType } from "../types";
|
|
12
12
|
|
|
13
13
|
export type LoroBuilder = ReturnType<typeof builder>;
|
package/src/list.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Container } from "loro-
|
|
2
|
-
import { LoroList, isContainer } from "loro-
|
|
1
|
+
import type { Container } from "@loro-runtime";
|
|
2
|
+
import { LoroList, isContainer } from "@loro-runtime";
|
|
3
3
|
import type { LoroType } from "./types";
|
|
4
4
|
|
|
5
5
|
export const list = <T extends unknown>(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "loro-crdt";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "loro-crdt/nodejs";
|
package/src/map.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Container } from "loro-
|
|
2
|
-
import { LoroMap, isContainer } from "loro-
|
|
1
|
+
import type { Container } from "@loro-runtime";
|
|
2
|
+
import { LoroMap, isContainer } from "@loro-runtime";
|
|
3
3
|
import type { LoroType } from "./types";
|
|
4
4
|
|
|
5
5
|
export const map = <T extends unknown>(
|
package/src/movableList.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Container } from "loro-
|
|
2
|
-
import { isContainer, LoroMovableList } from "loro-
|
|
1
|
+
import type { Container } from "@loro-runtime";
|
|
2
|
+
import { isContainer, LoroMovableList } from "@loro-runtime";
|
|
3
3
|
import type { LoroType } from "./types";
|
|
4
4
|
|
|
5
5
|
export const movableList = <T extends unknown>(value: T[] | readonly T[] = []) => {
|
package/src/object.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Container } from "loro-
|
|
2
|
-
import { LoroMap, isContainer } from "loro-
|
|
1
|
+
import type { Container } from "@loro-runtime";
|
|
2
|
+
import { LoroMap, isContainer } from "@loro-runtime";
|
|
3
3
|
import type { LoroType } from "./types";
|
|
4
4
|
|
|
5
5
|
export const object = <T extends Record<string, any>>(value: T): LoroType<LoroMap<T>, T> => {
|
package/src/text.ts
CHANGED
package/src/tree.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: { browser: "src/index.ts" },
|
|
5
|
+
alias: {
|
|
6
|
+
"@loro-runtime": "./src/loro-runtime.browser.ts",
|
|
7
|
+
},
|
|
8
|
+
format: ["esm"],
|
|
9
|
+
target: "esnext",
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
dts: true,
|
|
12
|
+
outDir: "dist",
|
|
13
|
+
clean: true,
|
|
14
|
+
});
|
package/tsdown.config.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import browserConfig from "./tsdown.browser.config.ts";
|
|
2
|
+
import nodeConfig from "./tsdown.node.config.ts";
|
|
2
3
|
|
|
3
|
-
export default
|
|
4
|
-
format: ["esm"],
|
|
5
|
-
dts: true,
|
|
6
|
-
outDir: "dist",
|
|
7
|
-
entry: "src/index.ts",
|
|
8
|
-
target: "esnext",
|
|
9
|
-
sourcemap: true,
|
|
10
|
-
clean: true,
|
|
11
|
-
exports: {
|
|
12
|
-
all: true,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
4
|
+
export default [browserConfig, nodeConfig];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: { node: "src/index.ts" },
|
|
5
|
+
alias: {
|
|
6
|
+
"@loro-runtime": "./src/loro-runtime.node.ts",
|
|
7
|
+
},
|
|
8
|
+
format: ["esm"],
|
|
9
|
+
target: "esnext",
|
|
10
|
+
sourcemap: true,
|
|
11
|
+
tsconfig: "tsconfig.node.build.json",
|
|
12
|
+
dts: false,
|
|
13
|
+
outDir: "dist",
|
|
14
|
+
clean: false,
|
|
15
|
+
});
|
package/dist/chunk-15K8U1wQ.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//#region rolldown:runtime
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) {
|
|
6
|
-
__defProp(target, name, {
|
|
7
|
-
get: all[name],
|
|
8
|
-
enumerable: true
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
if (symbols) {
|
|
12
|
-
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
-
}
|
|
14
|
-
return target;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { __exportAll as t };
|