@pluv/crdt-loro 3.2.0 → 3.2.1
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 +8 -8
- package/CHANGELOG.md +8 -1
- package/dist/index.d.mts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +43 -35
- package/dist/index.mjs +43 -35
- package/package.json +13 -9
- package/src/doc/CrdtLoroDoc.ts +23 -29
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-loro@3.2.
|
|
2
|
+
> @pluv/crdt-loro@3.2.1 build /home/runner/work/pluv/pluv/packages/crdt-loro
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m12.62 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 93ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m11.56 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 95ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4008ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.60 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.60 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @pluv/crdt-loro
|
|
2
2
|
|
|
3
|
+
## 3.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1e0c886: Updated crdt internal private properties to use native [private elements](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_elements).
|
|
8
|
+
- @pluv/crdt@3.2.1
|
|
9
|
+
- @pluv/types@3.2.1
|
|
10
|
+
|
|
3
11
|
## 3.2.0
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -166,7 +174,6 @@
|
|
|
166
174
|
- 945c47d: Updated deprecation warnings to read that features will be removed in v3 instead of v2.
|
|
167
175
|
|
|
168
176
|
Due to an [extremely unfortunate bug in changesets](https://github.com/changesets/changesets/issues/1011), minor and patch changes will create major releases. This caused an unintended v2 release that had no breaking changes. To avoid backtracking and deleting deprecated functionalities right away, the deprecation warnings have been updated so that those APIs will be removed in v3 instead of v2.
|
|
169
|
-
|
|
170
177
|
- @pluv/crdt@2.0.2
|
|
171
178
|
- @pluv/types@2.0.2
|
|
172
179
|
|
package/dist/index.d.mts
CHANGED
|
@@ -22,9 +22,8 @@ declare const builder: (doc: LoroDoc) => {
|
|
|
22
22
|
|
|
23
23
|
type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>>> = (builder: LoroBuilder) => TStorage;
|
|
24
24
|
declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> implements CrdtDocLike<LoroDoc, TStorage> {
|
|
25
|
+
#private;
|
|
25
26
|
value: LoroDoc;
|
|
26
|
-
private _storage;
|
|
27
|
-
private _undoManager;
|
|
28
27
|
constructor(params?: CrdtLoroDocParams<TStorage>);
|
|
29
28
|
applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
30
29
|
batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
@@ -47,8 +46,6 @@ declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> i
|
|
|
47
46
|
*/
|
|
48
47
|
transact(fn: () => void): this;
|
|
49
48
|
undo(): this;
|
|
50
|
-
private _setPluvId;
|
|
51
|
-
private _warn;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
declare class CrdtLoroDocFactory<TStorage extends Record<string, LoroType<any, any>>> extends AbstractCrdtDocFactory<LoroDoc, TStorage> {
|
package/dist/index.d.ts
CHANGED
|
@@ -22,9 +22,8 @@ declare const builder: (doc: LoroDoc) => {
|
|
|
22
22
|
|
|
23
23
|
type CrdtLoroDocParams<TStorage extends Record<string, LoroType<any, any>>> = (builder: LoroBuilder) => TStorage;
|
|
24
24
|
declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> implements CrdtDocLike<LoroDoc, TStorage> {
|
|
25
|
+
#private;
|
|
25
26
|
value: LoroDoc;
|
|
26
|
-
private _storage;
|
|
27
|
-
private _undoManager;
|
|
28
27
|
constructor(params?: CrdtLoroDocParams<TStorage>);
|
|
29
28
|
applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
30
29
|
batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
@@ -47,8 +46,6 @@ declare class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>> i
|
|
|
47
46
|
*/
|
|
48
47
|
transact(fn: () => void): this;
|
|
49
48
|
undo(): this;
|
|
50
|
-
private _setPluvId;
|
|
51
|
-
private _warn;
|
|
52
49
|
}
|
|
53
50
|
|
|
54
51
|
declare class CrdtLoroDocFactory<TStorage extends Record<string, LoroType<any, any>>> extends AbstractCrdtDocFactory<LoroDoc, TStorage> {
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
7
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
10
13
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
14
|
var __spreadValues = (a, b) => {
|
|
12
15
|
for (var prop in b || (b = {}))
|
|
@@ -33,6 +36,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
33
36
|
return to;
|
|
34
37
|
};
|
|
35
38
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
40
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
41
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
42
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
43
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
36
44
|
|
|
37
45
|
// src/index.ts
|
|
38
46
|
var index_exports = {};
|
|
@@ -113,20 +121,23 @@ var builder = (doc2) => {
|
|
|
113
121
|
var MAX_UNDO_STEPS = 100;
|
|
114
122
|
var MERGE_INTERVAL_MS = 1e3;
|
|
115
123
|
var PLUV_ID_FIELD = "__$pluv";
|
|
124
|
+
var __storage, __undoManager, _CrdtLoroDoc_instances, _setPluvId_fn;
|
|
116
125
|
var CrdtLoroDoc = class {
|
|
117
126
|
constructor(params = () => ({})) {
|
|
127
|
+
__privateAdd(this, _CrdtLoroDoc_instances);
|
|
118
128
|
this.value = new import_loro_crdt3.LoroDoc();
|
|
119
|
-
this
|
|
129
|
+
__privateAdd(this, __storage);
|
|
130
|
+
__privateAdd(this, __undoManager, null);
|
|
120
131
|
const storage = params(builder(this.value));
|
|
121
132
|
const keys = Object.keys(this.value.toJSON()).reduce(
|
|
122
133
|
(set, key) => set.add(key),
|
|
123
134
|
/* @__PURE__ */ new Set()
|
|
124
135
|
);
|
|
125
|
-
this
|
|
136
|
+
__privateSet(this, __storage, Object.entries(storage).reduce(
|
|
126
137
|
(acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
|
|
127
138
|
{}
|
|
128
|
-
);
|
|
129
|
-
if (!!Object.keys(storage).length) this.
|
|
139
|
+
));
|
|
140
|
+
if (!!Object.keys(storage).length) __privateMethod(this, _CrdtLoroDoc_instances, _setPluvId_fn).call(this);
|
|
130
141
|
this.value.commit();
|
|
131
142
|
}
|
|
132
143
|
applyEncodedState(params) {
|
|
@@ -160,29 +171,29 @@ var CrdtLoroDoc = class {
|
|
|
160
171
|
return this;
|
|
161
172
|
}
|
|
162
173
|
canRedo() {
|
|
163
|
-
if (!this
|
|
164
|
-
return this.
|
|
174
|
+
if (!__privateGet(this, __undoManager)) return false;
|
|
175
|
+
return __privateGet(this, __undoManager).canRedo();
|
|
165
176
|
}
|
|
166
177
|
canUndo() {
|
|
167
|
-
if (!this
|
|
168
|
-
return this.
|
|
178
|
+
if (!__privateGet(this, __undoManager)) return false;
|
|
179
|
+
return __privateGet(this, __undoManager).canUndo();
|
|
169
180
|
}
|
|
170
181
|
destroy() {
|
|
171
182
|
return;
|
|
172
183
|
}
|
|
173
184
|
get(key) {
|
|
174
|
-
if (typeof key === "undefined") return this
|
|
175
|
-
return this
|
|
185
|
+
if (typeof key === "undefined") return __privateGet(this, __storage);
|
|
186
|
+
return __privateGet(this, __storage)[key];
|
|
176
187
|
}
|
|
177
188
|
getEncodedState() {
|
|
178
189
|
return (0, import_js_base64.fromUint8Array)(this.value.export({ mode: "snapshot" }));
|
|
179
190
|
}
|
|
180
191
|
toJson(type) {
|
|
181
192
|
if (typeof type === "string") {
|
|
182
|
-
const container = this
|
|
193
|
+
const container = __privateGet(this, __storage)[type];
|
|
183
194
|
return container instanceof import_loro_crdt3.LoroText ? container.toString() : container instanceof import_loro_crdt3.LoroCounter ? container.value : container.toJSON();
|
|
184
195
|
}
|
|
185
|
-
return Object.entries(this
|
|
196
|
+
return Object.entries(__privateGet(this, __storage)).reduce(
|
|
186
197
|
(acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
187
198
|
[key]: value instanceof import_loro_crdt3.LoroText ? value.toString() : value.toJSON()
|
|
188
199
|
}),
|
|
@@ -194,12 +205,12 @@ var CrdtLoroDoc = class {
|
|
|
194
205
|
return !serialized || !Object.keys(serialized).length;
|
|
195
206
|
}
|
|
196
207
|
rebuildStorage(reference) {
|
|
197
|
-
const isBuilt = !!Object.keys(this
|
|
208
|
+
const isBuilt = !!Object.keys(__privateGet(this, __storage)).length;
|
|
198
209
|
if (isBuilt) {
|
|
199
210
|
console.warn("Attempted to rebuild storage multiple times");
|
|
200
211
|
return this;
|
|
201
212
|
}
|
|
202
|
-
this
|
|
213
|
+
__privateSet(this, __storage, Object.entries(reference).reduce((acc, [key, node]) => {
|
|
203
214
|
if (node instanceof import_loro_crdt3.LoroCounter) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getCounter(key) });
|
|
204
215
|
if (node instanceof import_loro_crdt3.LoroList) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getList(key) });
|
|
205
216
|
if (node instanceof import_loro_crdt3.LoroMap) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
|
|
@@ -209,12 +220,12 @@ var CrdtLoroDoc = class {
|
|
|
209
220
|
if (node instanceof import_loro_crdt3.LoroText) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
|
|
210
221
|
if (node instanceof import_loro_crdt3.LoroTree) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getTree(key) });
|
|
211
222
|
return acc;
|
|
212
|
-
}, {});
|
|
223
|
+
}, {}));
|
|
213
224
|
return this.track();
|
|
214
225
|
}
|
|
215
226
|
redo() {
|
|
216
227
|
var _a;
|
|
217
|
-
(_a = this
|
|
228
|
+
(_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.redo();
|
|
218
229
|
return this;
|
|
219
230
|
}
|
|
220
231
|
subscribe(listener) {
|
|
@@ -227,7 +238,7 @@ var CrdtLoroDoc = class {
|
|
|
227
238
|
update
|
|
228
239
|
});
|
|
229
240
|
};
|
|
230
|
-
const unsubcribeAll = Object.values(this
|
|
241
|
+
const unsubcribeAll = Object.values(__privateGet(this, __storage)).reduce(
|
|
231
242
|
(acc, crdtType) => {
|
|
232
243
|
const container = crdtType;
|
|
233
244
|
const unsubscribe = container.subscribe(fn);
|
|
@@ -241,15 +252,15 @@ var CrdtLoroDoc = class {
|
|
|
241
252
|
return unsubcribeAll;
|
|
242
253
|
}
|
|
243
254
|
track() {
|
|
244
|
-
if (this
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
247
|
-
this
|
|
255
|
+
if (__privateGet(this, __undoManager)) {
|
|
256
|
+
__privateGet(this, __undoManager).clear();
|
|
257
|
+
__privateGet(this, __undoManager).free();
|
|
258
|
+
__privateSet(this, __undoManager, null);
|
|
248
259
|
}
|
|
249
|
-
this
|
|
260
|
+
__privateSet(this, __undoManager, new import_loro_crdt3.UndoManager(this.value, {
|
|
250
261
|
maxUndoSteps: MAX_UNDO_STEPS,
|
|
251
262
|
mergeInterval: MERGE_INTERVAL_MS
|
|
252
|
-
});
|
|
263
|
+
}));
|
|
253
264
|
return this;
|
|
254
265
|
}
|
|
255
266
|
/**
|
|
@@ -263,20 +274,17 @@ var CrdtLoroDoc = class {
|
|
|
263
274
|
}
|
|
264
275
|
undo() {
|
|
265
276
|
var _a;
|
|
266
|
-
(_a = this
|
|
277
|
+
(_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.undo();
|
|
267
278
|
return this;
|
|
268
279
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
|
|
278
|
-
console.log(...data);
|
|
279
|
-
}
|
|
280
|
+
};
|
|
281
|
+
__storage = new WeakMap();
|
|
282
|
+
__undoManager = new WeakMap();
|
|
283
|
+
_CrdtLoroDoc_instances = new WeakSet();
|
|
284
|
+
_setPluvId_fn = function() {
|
|
285
|
+
const text2 = this.value.getText(PLUV_ID_FIELD);
|
|
286
|
+
const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
|
|
287
|
+
text2.insert(0, id);
|
|
280
288
|
};
|
|
281
289
|
|
|
282
290
|
// src/doc/CrdtLoroDocFactory.ts
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,9 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
7
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
11
|
var __spreadValues = (a, b) => {
|
|
9
12
|
for (var prop in b || (b = {}))
|
|
@@ -21,6 +24,11 @@ var __export = (target, all) => {
|
|
|
21
24
|
for (var name in all)
|
|
22
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
26
|
};
|
|
27
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
28
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
29
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
30
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
31
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
24
32
|
|
|
25
33
|
// src/loro.ts
|
|
26
34
|
var loro_exports = {};
|
|
@@ -103,20 +111,23 @@ var builder = (doc2) => {
|
|
|
103
111
|
var MAX_UNDO_STEPS = 100;
|
|
104
112
|
var MERGE_INTERVAL_MS = 1e3;
|
|
105
113
|
var PLUV_ID_FIELD = "__$pluv";
|
|
114
|
+
var __storage, __undoManager, _CrdtLoroDoc_instances, _setPluvId_fn;
|
|
106
115
|
var CrdtLoroDoc = class {
|
|
107
116
|
constructor(params = () => ({})) {
|
|
117
|
+
__privateAdd(this, _CrdtLoroDoc_instances);
|
|
108
118
|
this.value = new LoroDoc();
|
|
109
|
-
this
|
|
119
|
+
__privateAdd(this, __storage);
|
|
120
|
+
__privateAdd(this, __undoManager, null);
|
|
110
121
|
const storage = params(builder(this.value));
|
|
111
122
|
const keys = Object.keys(this.value.toJSON()).reduce(
|
|
112
123
|
(set, key) => set.add(key),
|
|
113
124
|
/* @__PURE__ */ new Set()
|
|
114
125
|
);
|
|
115
|
-
this
|
|
126
|
+
__privateSet(this, __storage, Object.entries(storage).reduce(
|
|
116
127
|
(acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
|
|
117
128
|
{}
|
|
118
|
-
);
|
|
119
|
-
if (!!Object.keys(storage).length) this.
|
|
129
|
+
));
|
|
130
|
+
if (!!Object.keys(storage).length) __privateMethod(this, _CrdtLoroDoc_instances, _setPluvId_fn).call(this);
|
|
120
131
|
this.value.commit();
|
|
121
132
|
}
|
|
122
133
|
applyEncodedState(params) {
|
|
@@ -150,29 +161,29 @@ var CrdtLoroDoc = class {
|
|
|
150
161
|
return this;
|
|
151
162
|
}
|
|
152
163
|
canRedo() {
|
|
153
|
-
if (!this
|
|
154
|
-
return this.
|
|
164
|
+
if (!__privateGet(this, __undoManager)) return false;
|
|
165
|
+
return __privateGet(this, __undoManager).canRedo();
|
|
155
166
|
}
|
|
156
167
|
canUndo() {
|
|
157
|
-
if (!this
|
|
158
|
-
return this.
|
|
168
|
+
if (!__privateGet(this, __undoManager)) return false;
|
|
169
|
+
return __privateGet(this, __undoManager).canUndo();
|
|
159
170
|
}
|
|
160
171
|
destroy() {
|
|
161
172
|
return;
|
|
162
173
|
}
|
|
163
174
|
get(key) {
|
|
164
|
-
if (typeof key === "undefined") return this
|
|
165
|
-
return this
|
|
175
|
+
if (typeof key === "undefined") return __privateGet(this, __storage);
|
|
176
|
+
return __privateGet(this, __storage)[key];
|
|
166
177
|
}
|
|
167
178
|
getEncodedState() {
|
|
168
179
|
return fromUint8Array(this.value.export({ mode: "snapshot" }));
|
|
169
180
|
}
|
|
170
181
|
toJson(type) {
|
|
171
182
|
if (typeof type === "string") {
|
|
172
|
-
const container = this
|
|
183
|
+
const container = __privateGet(this, __storage)[type];
|
|
173
184
|
return container instanceof LoroText ? container.toString() : container instanceof LoroCounter2 ? container.value : container.toJSON();
|
|
174
185
|
}
|
|
175
|
-
return Object.entries(this
|
|
186
|
+
return Object.entries(__privateGet(this, __storage)).reduce(
|
|
176
187
|
(acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
177
188
|
[key]: value instanceof LoroText ? value.toString() : value.toJSON()
|
|
178
189
|
}),
|
|
@@ -184,12 +195,12 @@ var CrdtLoroDoc = class {
|
|
|
184
195
|
return !serialized || !Object.keys(serialized).length;
|
|
185
196
|
}
|
|
186
197
|
rebuildStorage(reference) {
|
|
187
|
-
const isBuilt = !!Object.keys(this
|
|
198
|
+
const isBuilt = !!Object.keys(__privateGet(this, __storage)).length;
|
|
188
199
|
if (isBuilt) {
|
|
189
200
|
console.warn("Attempted to rebuild storage multiple times");
|
|
190
201
|
return this;
|
|
191
202
|
}
|
|
192
|
-
this
|
|
203
|
+
__privateSet(this, __storage, Object.entries(reference).reduce((acc, [key, node]) => {
|
|
193
204
|
if (node instanceof LoroCounter2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getCounter(key) });
|
|
194
205
|
if (node instanceof LoroList) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getList(key) });
|
|
195
206
|
if (node instanceof LoroMap) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
|
|
@@ -199,12 +210,12 @@ var CrdtLoroDoc = class {
|
|
|
199
210
|
if (node instanceof LoroText) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
|
|
200
211
|
if (node instanceof LoroTree) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getTree(key) });
|
|
201
212
|
return acc;
|
|
202
|
-
}, {});
|
|
213
|
+
}, {}));
|
|
203
214
|
return this.track();
|
|
204
215
|
}
|
|
205
216
|
redo() {
|
|
206
217
|
var _a;
|
|
207
|
-
(_a = this
|
|
218
|
+
(_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.redo();
|
|
208
219
|
return this;
|
|
209
220
|
}
|
|
210
221
|
subscribe(listener) {
|
|
@@ -217,7 +228,7 @@ var CrdtLoroDoc = class {
|
|
|
217
228
|
update
|
|
218
229
|
});
|
|
219
230
|
};
|
|
220
|
-
const unsubcribeAll = Object.values(this
|
|
231
|
+
const unsubcribeAll = Object.values(__privateGet(this, __storage)).reduce(
|
|
221
232
|
(acc, crdtType) => {
|
|
222
233
|
const container = crdtType;
|
|
223
234
|
const unsubscribe = container.subscribe(fn);
|
|
@@ -231,15 +242,15 @@ var CrdtLoroDoc = class {
|
|
|
231
242
|
return unsubcribeAll;
|
|
232
243
|
}
|
|
233
244
|
track() {
|
|
234
|
-
if (this
|
|
235
|
-
this.
|
|
236
|
-
this.
|
|
237
|
-
this
|
|
245
|
+
if (__privateGet(this, __undoManager)) {
|
|
246
|
+
__privateGet(this, __undoManager).clear();
|
|
247
|
+
__privateGet(this, __undoManager).free();
|
|
248
|
+
__privateSet(this, __undoManager, null);
|
|
238
249
|
}
|
|
239
|
-
this
|
|
250
|
+
__privateSet(this, __undoManager, new UndoManager(this.value, {
|
|
240
251
|
maxUndoSteps: MAX_UNDO_STEPS,
|
|
241
252
|
mergeInterval: MERGE_INTERVAL_MS
|
|
242
|
-
});
|
|
253
|
+
}));
|
|
243
254
|
return this;
|
|
244
255
|
}
|
|
245
256
|
/**
|
|
@@ -253,20 +264,17 @@ var CrdtLoroDoc = class {
|
|
|
253
264
|
}
|
|
254
265
|
undo() {
|
|
255
266
|
var _a;
|
|
256
|
-
(_a = this
|
|
267
|
+
(_a = __privateGet(this, __undoManager)) == null ? void 0 : _a.undo();
|
|
257
268
|
return this;
|
|
258
269
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (((_a = process.env) == null ? void 0 : _a.NODE_ENV) === "production") return;
|
|
268
|
-
console.log(...data);
|
|
269
|
-
}
|
|
270
|
+
};
|
|
271
|
+
__storage = new WeakMap();
|
|
272
|
+
__undoManager = new WeakMap();
|
|
273
|
+
_CrdtLoroDoc_instances = new WeakSet();
|
|
274
|
+
_setPluvId_fn = function() {
|
|
275
|
+
const text2 = this.value.getText(PLUV_ID_FIELD);
|
|
276
|
+
const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
|
|
277
|
+
text2.insert(0, id);
|
|
270
278
|
};
|
|
271
279
|
|
|
272
280
|
// src/doc/CrdtLoroDocFactory.ts
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-loro",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "loro for @pluv/io",
|
|
5
|
-
"author":
|
|
5
|
+
"author": {
|
|
6
|
+
"email": "david@pluv.io",
|
|
7
|
+
"name": "i3dly",
|
|
8
|
+
"url": "https://github.com/i3dly"
|
|
9
|
+
},
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"homepage": "https://github.com/pluv-io/pluv",
|
|
8
12
|
"repository": {
|
|
@@ -17,21 +21,21 @@
|
|
|
17
21
|
"access": "public"
|
|
18
22
|
},
|
|
19
23
|
"dependencies": {
|
|
20
|
-
"@types/node": "^
|
|
24
|
+
"@types/node": "^24.0.14",
|
|
21
25
|
"js-base64": "^3.7.7",
|
|
22
|
-
"@pluv/crdt": "^3.2.
|
|
23
|
-
"@pluv/types": "^3.2.
|
|
26
|
+
"@pluv/crdt": "^3.2.1",
|
|
27
|
+
"@pluv/types": "^3.2.1"
|
|
24
28
|
},
|
|
25
29
|
"peerDependencies": {
|
|
26
30
|
"loro-crdt": "^1.0.0"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"eslint": "^9.
|
|
30
|
-
"loro-crdt": "^1.5.
|
|
33
|
+
"eslint": "^9.31.0",
|
|
34
|
+
"loro-crdt": "^1.5.9",
|
|
31
35
|
"tsup": "^8.5.0",
|
|
32
36
|
"typescript": "^5.8.3",
|
|
33
|
-
"@pluv/tsconfig": "^3.2.
|
|
34
|
-
"eslint-config-pluv": "^3.2.
|
|
37
|
+
"@pluv/tsconfig": "^3.2.1",
|
|
38
|
+
"eslint-config-pluv": "^3.2.1"
|
|
35
39
|
},
|
|
36
40
|
"scripts": {
|
|
37
41
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/doc/CrdtLoroDoc.ts
CHANGED
|
@@ -35,8 +35,8 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
35
35
|
{
|
|
36
36
|
public value: LoroDoc = new LoroDoc();
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
#_storage: TStorage;
|
|
39
|
+
#_undoManager: UndoManager | null = null;
|
|
40
40
|
|
|
41
41
|
constructor(params: CrdtLoroDocParams<TStorage> = () => ({}) as TStorage) {
|
|
42
42
|
const storage = params(builder(this.value));
|
|
@@ -46,11 +46,11 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
46
46
|
new Set<string>(),
|
|
47
47
|
);
|
|
48
48
|
|
|
49
|
-
this
|
|
49
|
+
this.#_storage = Object.entries(storage).reduce(
|
|
50
50
|
(acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),
|
|
51
51
|
{} as TStorage,
|
|
52
52
|
);
|
|
53
|
-
if (!!Object.keys(storage).length) this
|
|
53
|
+
if (!!Object.keys(storage).length) this.#_setPluvId();
|
|
54
54
|
|
|
55
55
|
this.value.commit();
|
|
56
56
|
}
|
|
@@ -101,15 +101,15 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
public canRedo(): boolean {
|
|
104
|
-
if (!this
|
|
104
|
+
if (!this.#_undoManager) return false;
|
|
105
105
|
|
|
106
|
-
return this
|
|
106
|
+
return this.#_undoManager.canRedo();
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
public canUndo(): boolean {
|
|
110
|
-
if (!this
|
|
110
|
+
if (!this.#_undoManager) return false;
|
|
111
111
|
|
|
112
|
-
return this
|
|
112
|
+
return this.#_undoManager.canUndo();
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
public destroy(): void {
|
|
@@ -119,9 +119,9 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
119
119
|
public get(key?: undefined): TStorage;
|
|
120
120
|
public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
121
121
|
public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {
|
|
122
|
-
if (typeof key === "undefined") return this
|
|
122
|
+
if (typeof key === "undefined") return this.#_storage;
|
|
123
123
|
|
|
124
|
-
return this
|
|
124
|
+
return this.#_storage[key as TKey];
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
public getEncodedState(): string {
|
|
@@ -132,7 +132,7 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
132
132
|
public toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
133
133
|
public toJson<TKey extends keyof TStorage>(type?: TKey) {
|
|
134
134
|
if (typeof type === "string") {
|
|
135
|
-
const container = this
|
|
135
|
+
const container = this.#_storage[type] as unknown as Container;
|
|
136
136
|
|
|
137
137
|
return container instanceof LoroText
|
|
138
138
|
? container.toString()
|
|
@@ -141,7 +141,7 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
141
141
|
: container.toJSON!();
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
return Object.entries(this
|
|
144
|
+
return Object.entries(this.#_storage).reduce(
|
|
145
145
|
(acc, [key, value]) => ({
|
|
146
146
|
...(acc as any),
|
|
147
147
|
[key]: value instanceof LoroText ? value.toString() : value.toJSON!(),
|
|
@@ -157,14 +157,14 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
public rebuildStorage(reference: TStorage): this {
|
|
160
|
-
const isBuilt = !!Object.keys(this
|
|
160
|
+
const isBuilt = !!Object.keys(this.#_storage).length;
|
|
161
161
|
|
|
162
162
|
if (isBuilt) {
|
|
163
163
|
console.warn("Attempted to rebuild storage multiple times");
|
|
164
164
|
return this;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
this
|
|
167
|
+
this.#_storage = Object.entries(reference).reduce((acc, [key, node]) => {
|
|
168
168
|
if (node instanceof LoroCounter) return { ...acc, [key]: this.value.getCounter(key) };
|
|
169
169
|
if (node instanceof LoroList) return { ...acc, [key]: this.value.getList(key) };
|
|
170
170
|
if (node instanceof LoroMap) return { ...acc, [key]: this.value.getMap(key) };
|
|
@@ -181,7 +181,7 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
public redo(): this {
|
|
184
|
-
this
|
|
184
|
+
this.#_undoManager?.redo();
|
|
185
185
|
|
|
186
186
|
return this;
|
|
187
187
|
}
|
|
@@ -200,7 +200,7 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
200
200
|
});
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
-
const unsubcribeAll = Object.values(this
|
|
203
|
+
const unsubcribeAll = Object.values(this.#_storage).reduce<() => void>(
|
|
204
204
|
(acc, crdtType) => {
|
|
205
205
|
const container = crdtType as unknown as Container;
|
|
206
206
|
const unsubscribe = container.subscribe(fn);
|
|
@@ -217,14 +217,14 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
public track(): this {
|
|
220
|
-
if (this
|
|
221
|
-
this
|
|
222
|
-
this
|
|
220
|
+
if (this.#_undoManager) {
|
|
221
|
+
this.#_undoManager.clear();
|
|
222
|
+
this.#_undoManager.free();
|
|
223
223
|
|
|
224
|
-
this
|
|
224
|
+
this.#_undoManager = null;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
this
|
|
227
|
+
this.#_undoManager = new UndoManager(this.value, {
|
|
228
228
|
maxUndoSteps: MAX_UNDO_STEPS,
|
|
229
229
|
mergeInterval: MERGE_INTERVAL_MS,
|
|
230
230
|
});
|
|
@@ -245,21 +245,15 @@ export class CrdtLoroDoc<TStorage extends Record<string, LoroType<any, any>>>
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
public undo(): this {
|
|
248
|
-
this
|
|
248
|
+
this.#_undoManager?.undo();
|
|
249
249
|
|
|
250
250
|
return this;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
|
|
253
|
+
#_setPluvId() {
|
|
254
254
|
const text = this.value.getText(PLUV_ID_FIELD);
|
|
255
255
|
const id = typeof crypto !== "undefined" ? crypto.randomUUID() : Math.random().toString();
|
|
256
256
|
|
|
257
257
|
text.insert(0, id);
|
|
258
258
|
}
|
|
259
|
-
|
|
260
|
-
private _warn(...data: any[]) {
|
|
261
|
-
if (typeof process === "undefined") return;
|
|
262
|
-
if (process.env?.NODE_ENV === "production") return;
|
|
263
|
-
console.log(...data);
|
|
264
|
-
}
|
|
265
259
|
}
|