@pluv/crdt-yjs 2.3.0 → 3.0.0
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 +19 -0
- package/dist/index.d.mts +1 -9
- package/dist/index.d.ts +1 -9
- package/dist/index.js +80 -188
- package/dist/index.mjs +79 -187
- package/package.json +5 -5
- package/src/doc/CrdtYjsDoc.ts +4 -128
- package/src/yjs.ts +0 -1
- package/src/object/YjsObject.ts +0 -19
- package/src/object/index.ts +0 -2
- package/src/object/object.ts +0 -14
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@
|
|
2
|
+
> @pluv/crdt-yjs@3.0.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
|
|
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
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m17.76 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 85ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m16.84 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 86ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m10.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m10.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4599ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m10.63 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m10.63 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @pluv/crdt-yjs
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- bc1ae91: **BREAKING** Removed deprecated `yjs.object`. These must now be switched over to `yjs.map`.
|
|
8
|
+
- bc1ae91: **BREAKING** Removed deprecated ability to set top-level document types via the yjs shared-type and loro container type utilities (e.g. `yjs.array`, `loro.list`). These must now use the builder type provided in the 1st positional parameter of `yjs.doc` and `loro.doc`.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- @pluv/crdt@3.0.0
|
|
13
|
+
- @pluv/types@3.0.0
|
|
14
|
+
|
|
15
|
+
## 2.3.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- @pluv/crdt@2.3.1
|
|
20
|
+
- @pluv/types@2.3.1
|
|
21
|
+
|
|
3
22
|
## 2.3.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -122,13 +122,6 @@ declare const doc: <TStorage extends Record<string, YjsType<any, any>>>(value?:
|
|
|
122
122
|
|
|
123
123
|
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => YjsType<Map$1<T>, Record<string, T>>;
|
|
124
124
|
|
|
125
|
-
/**
|
|
126
|
-
* @deprecated This will be removed in v3.0.0. Use yjs.map instead
|
|
127
|
-
* @description Creates a Yjs map, but declare it like it's an object
|
|
128
|
-
* @date May 8, 2025
|
|
129
|
-
*/
|
|
130
|
-
declare const object: <T extends Record<string, any>>(value?: T) => YjsType<Map$1<T[keyof T]>, T>;
|
|
131
|
-
|
|
132
125
|
interface PluvYjsProviderParams<TIO extends IOLike<any>, TPresence extends Record<string, any>, TStorage extends Record<string, CrdtType$1<any, any>>, TEvents extends PluvRouterEventConfig, TField extends keyof TPresence | null = null> {
|
|
133
126
|
presenceField?: TField;
|
|
134
127
|
room: RoomLike<TIO, Doc, TPresence, TStorage, TEvents>;
|
|
@@ -200,14 +193,13 @@ declare const yjs_awareness: typeof awareness;
|
|
|
200
193
|
declare const yjs_doc: typeof doc;
|
|
201
194
|
declare const yjs_kind: typeof kind;
|
|
202
195
|
declare const yjs_map: typeof map;
|
|
203
|
-
declare const yjs_object: typeof object;
|
|
204
196
|
declare const yjs_provider: typeof provider;
|
|
205
197
|
declare const yjs_text: typeof text;
|
|
206
198
|
declare const yjs_xmlElement: typeof xmlElement;
|
|
207
199
|
declare const yjs_xmlFragment: typeof xmlFragment;
|
|
208
200
|
declare const yjs_xmlText: typeof xmlText;
|
|
209
201
|
declare namespace yjs {
|
|
210
|
-
export { type yjs_YjsBuilder as YjsBuilder, type yjs_YjsType as YjsType, yjs_array as array, yjs_awareness as awareness, yjs_doc as doc, yjs_kind as kind, yjs_map as map,
|
|
202
|
+
export { type yjs_YjsBuilder as YjsBuilder, type yjs_YjsType as YjsType, yjs_array as array, yjs_awareness as awareness, yjs_doc as doc, yjs_kind as kind, yjs_map as map, yjs_provider as provider, yjs_text as text, yjs_xmlElement as xmlElement, yjs_xmlFragment as xmlFragment, yjs_xmlText as xmlText };
|
|
211
203
|
}
|
|
212
204
|
|
|
213
205
|
export { yjs };
|
package/dist/index.d.ts
CHANGED
|
@@ -122,13 +122,6 @@ declare const doc: <TStorage extends Record<string, YjsType<any, any>>>(value?:
|
|
|
122
122
|
|
|
123
123
|
declare const map: <T extends unknown>(value?: readonly (readonly [key: string, value: T])[]) => YjsType<Map$1<T>, Record<string, T>>;
|
|
124
124
|
|
|
125
|
-
/**
|
|
126
|
-
* @deprecated This will be removed in v3.0.0. Use yjs.map instead
|
|
127
|
-
* @description Creates a Yjs map, but declare it like it's an object
|
|
128
|
-
* @date May 8, 2025
|
|
129
|
-
*/
|
|
130
|
-
declare const object: <T extends Record<string, any>>(value?: T) => YjsType<Map$1<T[keyof T]>, T>;
|
|
131
|
-
|
|
132
125
|
interface PluvYjsProviderParams<TIO extends IOLike<any>, TPresence extends Record<string, any>, TStorage extends Record<string, CrdtType$1<any, any>>, TEvents extends PluvRouterEventConfig, TField extends keyof TPresence | null = null> {
|
|
133
126
|
presenceField?: TField;
|
|
134
127
|
room: RoomLike<TIO, Doc, TPresence, TStorage, TEvents>;
|
|
@@ -200,14 +193,13 @@ declare const yjs_awareness: typeof awareness;
|
|
|
200
193
|
declare const yjs_doc: typeof doc;
|
|
201
194
|
declare const yjs_kind: typeof kind;
|
|
202
195
|
declare const yjs_map: typeof map;
|
|
203
|
-
declare const yjs_object: typeof object;
|
|
204
196
|
declare const yjs_provider: typeof provider;
|
|
205
197
|
declare const yjs_text: typeof text;
|
|
206
198
|
declare const yjs_xmlElement: typeof xmlElement;
|
|
207
199
|
declare const yjs_xmlFragment: typeof xmlFragment;
|
|
208
200
|
declare const yjs_xmlText: typeof xmlText;
|
|
209
201
|
declare namespace yjs {
|
|
210
|
-
export { type yjs_YjsBuilder as YjsBuilder, type yjs_YjsType as YjsType, yjs_array as array, yjs_awareness as awareness, yjs_doc as doc, yjs_kind as kind, yjs_map as map,
|
|
202
|
+
export { type yjs_YjsBuilder as YjsBuilder, type yjs_YjsType as YjsType, yjs_array as array, yjs_awareness as awareness, yjs_doc as doc, yjs_kind as kind, yjs_map as map, yjs_provider as provider, yjs_text as text, yjs_xmlElement as xmlElement, yjs_xmlFragment as xmlFragment, yjs_xmlText as xmlText };
|
|
211
203
|
}
|
|
212
204
|
|
|
213
205
|
export { yjs };
|
package/dist/index.js
CHANGED
|
@@ -49,7 +49,6 @@ __export(yjs_exports, {
|
|
|
49
49
|
doc: () => doc,
|
|
50
50
|
kind: () => kind,
|
|
51
51
|
map: () => map,
|
|
52
|
-
object: () => object,
|
|
53
52
|
provider: () => provider,
|
|
54
53
|
text: () => text,
|
|
55
54
|
xmlElement: () => xmlElement,
|
|
@@ -218,89 +217,10 @@ var awareness = (params) => {
|
|
|
218
217
|
|
|
219
218
|
// src/doc/CrdtYjsDoc.ts
|
|
220
219
|
var import_js_base64 = require("js-base64");
|
|
221
|
-
var import_yjs9 = require("yjs");
|
|
222
|
-
|
|
223
|
-
// src/map/YjsMap.ts
|
|
224
|
-
var import_yjs2 = require("yjs");
|
|
225
|
-
var YjsMap = class extends import_yjs2.Map {
|
|
226
|
-
constructor(value = []) {
|
|
227
|
-
super(value);
|
|
228
|
-
this.initialValue = value;
|
|
229
|
-
}
|
|
230
|
-
__pluvType() {
|
|
231
|
-
return {};
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
// src/object/YjsObject.ts
|
|
236
220
|
var import_yjs3 = require("yjs");
|
|
237
|
-
var YjsObject = class extends import_yjs3.Map {
|
|
238
|
-
constructor(value) {
|
|
239
|
-
super(Object.entries(value));
|
|
240
|
-
this.initialValue = value;
|
|
241
|
-
}
|
|
242
|
-
__pluvType() {
|
|
243
|
-
return {};
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
// src/text/YjsText.ts
|
|
248
|
-
var import_yjs4 = require("yjs");
|
|
249
|
-
var YjsText = class extends import_yjs4.Text {
|
|
250
|
-
constructor(value = "") {
|
|
251
|
-
super();
|
|
252
|
-
this.initialValue = value;
|
|
253
|
-
}
|
|
254
|
-
__pluvType() {
|
|
255
|
-
return {};
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
// src/utils/oneLine.ts
|
|
260
|
-
var oneLine = (strings, ...values) => {
|
|
261
|
-
return strings.map((str) => str.replace(/\s+/g, " ")).reduce((acc, str, i) => acc + str + (i < values.length ? values[i] : ""), "").replace(/\s+/g, " ").trim();
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
// src/xmlElement/YjsXmlElement.ts
|
|
265
|
-
var import_yjs5 = require("yjs");
|
|
266
|
-
var YjsXmlElement = class extends import_yjs5.XmlElement {
|
|
267
|
-
constructor(name, value) {
|
|
268
|
-
super(name);
|
|
269
|
-
if (!!value.length) this.insert(0, value);
|
|
270
|
-
this.initialValue = value;
|
|
271
|
-
}
|
|
272
|
-
__pluvType() {
|
|
273
|
-
return {};
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
// src/xmlFragment/YjsXmlFragment.ts
|
|
278
|
-
var import_yjs6 = require("yjs");
|
|
279
|
-
var YjsXmlFragment = class extends import_yjs6.XmlFragment {
|
|
280
|
-
constructor(value) {
|
|
281
|
-
super();
|
|
282
|
-
if (!!value.length) this.insert(0, value);
|
|
283
|
-
this.initialValue = value;
|
|
284
|
-
}
|
|
285
|
-
__pluvType() {
|
|
286
|
-
return {};
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// src/xmlText/YjsXmlText.ts
|
|
291
|
-
var import_yjs7 = require("yjs");
|
|
292
|
-
var YjsXmlText = class extends import_yjs7.XmlText {
|
|
293
|
-
constructor(value = "") {
|
|
294
|
-
super();
|
|
295
|
-
this.initialValue = value;
|
|
296
|
-
}
|
|
297
|
-
__pluvType() {
|
|
298
|
-
return {};
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
221
|
|
|
302
222
|
// src/doc/builder.ts
|
|
303
|
-
var
|
|
223
|
+
var import_yjs2 = require("yjs");
|
|
304
224
|
var builder = (doc2) => {
|
|
305
225
|
return {
|
|
306
226
|
array(name, value = []) {
|
|
@@ -331,7 +251,7 @@ var builder = (doc2) => {
|
|
|
331
251
|
return xmlFragment2;
|
|
332
252
|
},
|
|
333
253
|
xmlText(name) {
|
|
334
|
-
const xmlText2 = doc2.get(name,
|
|
254
|
+
const xmlText2 = doc2.get(name, import_yjs2.XmlText);
|
|
335
255
|
return xmlText2;
|
|
336
256
|
}
|
|
337
257
|
};
|
|
@@ -341,105 +261,20 @@ var builder = (doc2) => {
|
|
|
341
261
|
var MERGE_INTERVAL_MS = 1e3;
|
|
342
262
|
var CrdtYjsDoc = class {
|
|
343
263
|
constructor(params = () => ({})) {
|
|
344
|
-
this.value = new
|
|
264
|
+
this.value = new import_yjs3.Doc();
|
|
345
265
|
this._undoManager = null;
|
|
346
266
|
const storage = params(builder(this.value));
|
|
347
267
|
const keys = this.value.share.keys().reduce((set, key) => set.add(key), /* @__PURE__ */ new Set());
|
|
348
|
-
this._storage = Object.entries(storage).reduce(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this._warn(oneLine`
|
|
353
|
-
Warning: You are using \`yjs.xmlElement\` to declare top-level storage value \`${key}\`.
|
|
354
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
355
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
356
|
-
https://pluv.io/docs/migration-guides/v3
|
|
357
|
-
`);
|
|
358
|
-
const yXmlElement = this.value.getXmlElement(key);
|
|
359
|
-
if (!!((_a = node.initialValue) == null ? void 0 : _a.length)) {
|
|
360
|
-
yXmlElement.insert(0, (_b = node.initialValue) == null ? void 0 : _b.slice(0));
|
|
361
|
-
}
|
|
362
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlElement });
|
|
363
|
-
}
|
|
364
|
-
if (node instanceof YjsXmlFragment) {
|
|
365
|
-
this._warn(oneLine`
|
|
366
|
-
Warning: You are using \`yjs.xmlFragment\` to declare top-level storage value \`${key}\`.
|
|
367
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
368
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
369
|
-
https://pluv.io/docs/migration-guides/v3
|
|
370
|
-
`);
|
|
371
|
-
const yXmlFragment = this.value.getXmlFragment(key);
|
|
372
|
-
if (!!((_c = node.initialValue) == null ? void 0 : _c.length)) {
|
|
373
|
-
yXmlFragment.insert(0, (_d = node.initialValue) == null ? void 0 : _d.slice(0));
|
|
374
|
-
}
|
|
375
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlFragment });
|
|
376
|
-
}
|
|
377
|
-
if (node instanceof YjsXmlText) {
|
|
378
|
-
this._warn(oneLine`
|
|
379
|
-
Warning: You are using \`yjs.xmlText\` to declare top-level storage value \`${key}\`.
|
|
380
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
381
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
382
|
-
https://pluv.io/docs/migration-guides/v3
|
|
383
|
-
`);
|
|
384
|
-
const yXmlText = this.value.get(key, import_yjs9.XmlText);
|
|
385
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlText });
|
|
386
|
-
}
|
|
387
|
-
if (node instanceof YjsArray) {
|
|
388
|
-
this._warn(oneLine`
|
|
389
|
-
Warning: You are using \`yjs.array\` to declare top-level storage value \`${key}\`.
|
|
390
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
391
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
392
|
-
https://pluv.io/docs/migration-guides/v3
|
|
393
|
-
`);
|
|
394
|
-
const yArray = this.value.getArray(key);
|
|
395
|
-
if (!!((_e = node.initialValue) == null ? void 0 : _e.length)) yArray.insert(0, (_f = node.initialValue) == null ? void 0 : _f.slice(0));
|
|
396
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yArray });
|
|
397
|
-
}
|
|
398
|
-
if (node instanceof YjsMap) {
|
|
399
|
-
this._warn(oneLine`
|
|
400
|
-
Warning: You are using \`yjs.map\` to declare top-level storage value \`${key}\`.
|
|
401
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
402
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
403
|
-
https://pluv.io/docs/migration-guides/v3
|
|
404
|
-
`);
|
|
405
|
-
const yMap = this.value.getMap(key);
|
|
406
|
-
((_g = node.initialValue) != null ? _g : []).forEach(([k, v]) => {
|
|
407
|
-
yMap.set(k.toString(), v);
|
|
408
|
-
});
|
|
409
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yMap });
|
|
410
|
-
}
|
|
411
|
-
if (node instanceof YjsObject) {
|
|
412
|
-
this._warn(oneLine`
|
|
413
|
-
Warning: You are using \`yjs.object\` to declare top-level storage value \`${key}\`.
|
|
414
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
415
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
416
|
-
https://pluv.io/docs/migration-guides/v3
|
|
417
|
-
`);
|
|
418
|
-
const yMap = this.value.getMap(key);
|
|
419
|
-
Object.entries((_h = node.initialValue) != null ? _h : {}).forEach(([k, v]) => {
|
|
420
|
-
yMap.set(k.toString(), v);
|
|
421
|
-
});
|
|
422
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yMap });
|
|
423
|
-
}
|
|
424
|
-
if (node instanceof YjsText) {
|
|
425
|
-
this._warn(oneLine`
|
|
426
|
-
Warning: You are using \`yjs.text\` to declare top-level storage value \`${key}\`.
|
|
427
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
428
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
429
|
-
https://pluv.io/docs/migration-guides/v3
|
|
430
|
-
`);
|
|
431
|
-
const yText = this.value.getText(key);
|
|
432
|
-
if (typeof node.initialValue === "string") yText.insert(0, node.initialValue);
|
|
433
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yText });
|
|
434
|
-
}
|
|
435
|
-
return acc;
|
|
436
|
-
}, {});
|
|
268
|
+
this._storage = Object.entries(storage).reduce(
|
|
269
|
+
(acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
|
|
270
|
+
{}
|
|
271
|
+
);
|
|
437
272
|
}
|
|
438
273
|
applyEncodedState(params) {
|
|
439
274
|
const { origin, update } = params;
|
|
440
275
|
if (update === null || typeof update === "undefined") return this;
|
|
441
276
|
const uint8Update = typeof update === "string" ? (0, import_js_base64.toUint8Array)(update) : update;
|
|
442
|
-
(0,
|
|
277
|
+
(0, import_yjs3.applyUpdate)(this.value, uint8Update, origin);
|
|
443
278
|
return this;
|
|
444
279
|
}
|
|
445
280
|
batchApplyEncodedState(params) {
|
|
@@ -459,7 +294,7 @@ var CrdtYjsDoc = class {
|
|
|
459
294
|
return acc;
|
|
460
295
|
}, []);
|
|
461
296
|
if (!filtered.length) return this;
|
|
462
|
-
const merged = (0,
|
|
297
|
+
const merged = (0, import_yjs3.mergeUpdates)(filtered);
|
|
463
298
|
return this.applyEncodedState({ origin, update: merged });
|
|
464
299
|
}
|
|
465
300
|
canRedo() {
|
|
@@ -480,7 +315,7 @@ var CrdtYjsDoc = class {
|
|
|
480
315
|
return this._storage[type];
|
|
481
316
|
}
|
|
482
317
|
getEncodedState() {
|
|
483
|
-
return (0, import_js_base64.fromUint8Array)((0,
|
|
318
|
+
return (0, import_js_base64.fromUint8Array)((0, import_yjs3.encodeStateAsUpdate)(this.value));
|
|
484
319
|
}
|
|
485
320
|
isEmpty() {
|
|
486
321
|
return !this.value.share.size;
|
|
@@ -492,16 +327,16 @@ var CrdtYjsDoc = class {
|
|
|
492
327
|
return this;
|
|
493
328
|
}
|
|
494
329
|
this._storage = Object.entries(reference).reduce((acc, [key, node]) => {
|
|
495
|
-
if (node instanceof
|
|
330
|
+
if (node instanceof import_yjs3.XmlElement) {
|
|
496
331
|
return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlElement(key) });
|
|
497
332
|
}
|
|
498
|
-
if (node instanceof
|
|
333
|
+
if (node instanceof import_yjs3.XmlFragment) {
|
|
499
334
|
return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlFragment(key) });
|
|
500
335
|
}
|
|
501
|
-
if (node instanceof
|
|
502
|
-
if (node instanceof
|
|
503
|
-
if (node instanceof
|
|
504
|
-
if (node instanceof
|
|
336
|
+
if (node instanceof import_yjs3.XmlText) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.get(key, import_yjs3.XmlText) });
|
|
337
|
+
if (node instanceof import_yjs3.Array) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getArray(key) });
|
|
338
|
+
if (node instanceof import_yjs3.Map) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
|
|
339
|
+
if (node instanceof import_yjs3.Text) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
|
|
505
340
|
return acc;
|
|
506
341
|
}, {});
|
|
507
342
|
return this.track();
|
|
@@ -530,7 +365,7 @@ var CrdtYjsDoc = class {
|
|
|
530
365
|
if (this._undoManager) this._undoManager.destroy();
|
|
531
366
|
const sharedTypes = Object.values(this._storage).reduce(
|
|
532
367
|
(acc, type) => {
|
|
533
|
-
if (type instanceof
|
|
368
|
+
if (type instanceof import_yjs3.Array || type instanceof import_yjs3.Map || type instanceof import_yjs3.Text || type instanceof import_yjs3.XmlElement || type instanceof import_yjs3.XmlFragment || type instanceof import_yjs3.XmlText) {
|
|
534
369
|
acc.push(type);
|
|
535
370
|
}
|
|
536
371
|
return acc;
|
|
@@ -542,7 +377,7 @@ var CrdtYjsDoc = class {
|
|
|
542
377
|
this._undoManager = null;
|
|
543
378
|
return this;
|
|
544
379
|
}
|
|
545
|
-
this._undoManager = new
|
|
380
|
+
this._undoManager = new import_yjs3.UndoManager(sharedTypes, { captureTimeout: MERGE_INTERVAL_MS });
|
|
546
381
|
return this;
|
|
547
382
|
}
|
|
548
383
|
transact(fn) {
|
|
@@ -592,16 +427,23 @@ var doc = (value = () => ({})) => {
|
|
|
592
427
|
return new CrdtYjsDocFactory(value);
|
|
593
428
|
};
|
|
594
429
|
|
|
430
|
+
// src/map/YjsMap.ts
|
|
431
|
+
var import_yjs4 = require("yjs");
|
|
432
|
+
var YjsMap = class extends import_yjs4.Map {
|
|
433
|
+
constructor(value = []) {
|
|
434
|
+
super(value);
|
|
435
|
+
this.initialValue = value;
|
|
436
|
+
}
|
|
437
|
+
__pluvType() {
|
|
438
|
+
return {};
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
595
442
|
// src/map/map.ts
|
|
596
443
|
var map = (value = []) => {
|
|
597
444
|
return new YjsMap(value);
|
|
598
445
|
};
|
|
599
446
|
|
|
600
|
-
// src/object/object.ts
|
|
601
|
-
var object = (value = {}) => {
|
|
602
|
-
return new YjsObject(value);
|
|
603
|
-
};
|
|
604
|
-
|
|
605
447
|
// src/provider/PluvYjsProvider.ts
|
|
606
448
|
var import_types = require("@pluv/types");
|
|
607
449
|
var import_observable2 = require("lib0/observable");
|
|
@@ -682,21 +524,71 @@ var provider = (params) => {
|
|
|
682
524
|
return new PluvYjsProvider(params);
|
|
683
525
|
};
|
|
684
526
|
|
|
527
|
+
// src/text/YjsText.ts
|
|
528
|
+
var import_yjs5 = require("yjs");
|
|
529
|
+
var YjsText = class extends import_yjs5.Text {
|
|
530
|
+
constructor(value = "") {
|
|
531
|
+
super();
|
|
532
|
+
this.initialValue = value;
|
|
533
|
+
}
|
|
534
|
+
__pluvType() {
|
|
535
|
+
return {};
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
|
|
685
539
|
// src/text/text.ts
|
|
686
540
|
var text = (value = "") => {
|
|
687
541
|
return new YjsText(value);
|
|
688
542
|
};
|
|
689
543
|
|
|
544
|
+
// src/xmlElement/YjsXmlElement.ts
|
|
545
|
+
var import_yjs6 = require("yjs");
|
|
546
|
+
var YjsXmlElement = class extends import_yjs6.XmlElement {
|
|
547
|
+
constructor(name, value) {
|
|
548
|
+
super(name);
|
|
549
|
+
if (!!value.length) this.insert(0, value);
|
|
550
|
+
this.initialValue = value;
|
|
551
|
+
}
|
|
552
|
+
__pluvType() {
|
|
553
|
+
return {};
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
|
|
690
557
|
// src/xmlElement/xmlElement.ts
|
|
691
558
|
var xmlElement = (name, children) => {
|
|
692
559
|
return new YjsXmlElement(name, children);
|
|
693
560
|
};
|
|
694
561
|
|
|
562
|
+
// src/xmlFragment/YjsXmlFragment.ts
|
|
563
|
+
var import_yjs7 = require("yjs");
|
|
564
|
+
var YjsXmlFragment = class extends import_yjs7.XmlFragment {
|
|
565
|
+
constructor(value) {
|
|
566
|
+
super();
|
|
567
|
+
if (!!value.length) this.insert(0, value);
|
|
568
|
+
this.initialValue = value;
|
|
569
|
+
}
|
|
570
|
+
__pluvType() {
|
|
571
|
+
return {};
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
695
575
|
// src/xmlFragment/xmlFragment.ts
|
|
696
576
|
var xmlFragment = (children) => {
|
|
697
577
|
return new YjsXmlFragment(children);
|
|
698
578
|
};
|
|
699
579
|
|
|
580
|
+
// src/xmlText/YjsXmlText.ts
|
|
581
|
+
var import_yjs8 = require("yjs");
|
|
582
|
+
var YjsXmlText = class extends import_yjs8.XmlText {
|
|
583
|
+
constructor(value = "") {
|
|
584
|
+
super();
|
|
585
|
+
this.initialValue = value;
|
|
586
|
+
}
|
|
587
|
+
__pluvType() {
|
|
588
|
+
return {};
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
|
|
700
592
|
// src/xmlText/xmlText.ts
|
|
701
593
|
var xmlText = () => {
|
|
702
594
|
return new YjsXmlText();
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,6 @@ __export(yjs_exports, {
|
|
|
30
30
|
doc: () => doc,
|
|
31
31
|
kind: () => kind,
|
|
32
32
|
map: () => map,
|
|
33
|
-
object: () => object,
|
|
34
33
|
provider: () => provider,
|
|
35
34
|
text: () => text,
|
|
36
35
|
xmlElement: () => xmlElement,
|
|
@@ -203,98 +202,19 @@ import {
|
|
|
203
202
|
UndoManager,
|
|
204
203
|
Array as YArray3,
|
|
205
204
|
Doc as YDoc2,
|
|
206
|
-
Map as
|
|
207
|
-
Text as
|
|
208
|
-
XmlElement as
|
|
209
|
-
XmlFragment as
|
|
210
|
-
XmlText as
|
|
205
|
+
Map as YMap2,
|
|
206
|
+
Text as YText2,
|
|
207
|
+
XmlElement as YXmlElement2,
|
|
208
|
+
XmlFragment as YXmlFragment2,
|
|
209
|
+
XmlText as YXmlText2,
|
|
211
210
|
applyUpdate,
|
|
212
211
|
encodeStateAsUpdate,
|
|
213
212
|
mergeUpdates
|
|
214
213
|
} from "yjs";
|
|
215
214
|
|
|
216
|
-
// src/map/YjsMap.ts
|
|
217
|
-
import { Map as YMap } from "yjs";
|
|
218
|
-
var YjsMap = class extends YMap {
|
|
219
|
-
constructor(value = []) {
|
|
220
|
-
super(value);
|
|
221
|
-
this.initialValue = value;
|
|
222
|
-
}
|
|
223
|
-
__pluvType() {
|
|
224
|
-
return {};
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// src/object/YjsObject.ts
|
|
229
|
-
import { Map as YMap2 } from "yjs";
|
|
230
|
-
var YjsObject = class extends YMap2 {
|
|
231
|
-
constructor(value) {
|
|
232
|
-
super(Object.entries(value));
|
|
233
|
-
this.initialValue = value;
|
|
234
|
-
}
|
|
235
|
-
__pluvType() {
|
|
236
|
-
return {};
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// src/text/YjsText.ts
|
|
241
|
-
import { Text as YText } from "yjs";
|
|
242
|
-
var YjsText = class extends YText {
|
|
243
|
-
constructor(value = "") {
|
|
244
|
-
super();
|
|
245
|
-
this.initialValue = value;
|
|
246
|
-
}
|
|
247
|
-
__pluvType() {
|
|
248
|
-
return {};
|
|
249
|
-
}
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// src/utils/oneLine.ts
|
|
253
|
-
var oneLine = (strings, ...values) => {
|
|
254
|
-
return strings.map((str) => str.replace(/\s+/g, " ")).reduce((acc, str, i) => acc + str + (i < values.length ? values[i] : ""), "").replace(/\s+/g, " ").trim();
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// src/xmlElement/YjsXmlElement.ts
|
|
258
|
-
import { XmlElement as YXmlElement } from "yjs";
|
|
259
|
-
var YjsXmlElement = class extends YXmlElement {
|
|
260
|
-
constructor(name, value) {
|
|
261
|
-
super(name);
|
|
262
|
-
if (!!value.length) this.insert(0, value);
|
|
263
|
-
this.initialValue = value;
|
|
264
|
-
}
|
|
265
|
-
__pluvType() {
|
|
266
|
-
return {};
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
// src/xmlFragment/YjsXmlFragment.ts
|
|
271
|
-
import { XmlFragment as YXmlFragment } from "yjs";
|
|
272
|
-
var YjsXmlFragment = class extends YXmlFragment {
|
|
273
|
-
constructor(value) {
|
|
274
|
-
super();
|
|
275
|
-
if (!!value.length) this.insert(0, value);
|
|
276
|
-
this.initialValue = value;
|
|
277
|
-
}
|
|
278
|
-
__pluvType() {
|
|
279
|
-
return {};
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// src/xmlText/YjsXmlText.ts
|
|
284
|
-
import { XmlText as YXmlText } from "yjs";
|
|
285
|
-
var YjsXmlText = class extends YXmlText {
|
|
286
|
-
constructor(value = "") {
|
|
287
|
-
super();
|
|
288
|
-
this.initialValue = value;
|
|
289
|
-
}
|
|
290
|
-
__pluvType() {
|
|
291
|
-
return {};
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
|
|
295
215
|
// src/doc/builder.ts
|
|
296
216
|
import {
|
|
297
|
-
XmlText as
|
|
217
|
+
XmlText as YXmlText
|
|
298
218
|
} from "yjs";
|
|
299
219
|
var builder = (doc2) => {
|
|
300
220
|
return {
|
|
@@ -326,7 +246,7 @@ var builder = (doc2) => {
|
|
|
326
246
|
return xmlFragment2;
|
|
327
247
|
},
|
|
328
248
|
xmlText(name) {
|
|
329
|
-
const xmlText2 = doc2.get(name,
|
|
249
|
+
const xmlText2 = doc2.get(name, YXmlText);
|
|
330
250
|
return xmlText2;
|
|
331
251
|
}
|
|
332
252
|
};
|
|
@@ -340,95 +260,10 @@ var CrdtYjsDoc = class {
|
|
|
340
260
|
this._undoManager = null;
|
|
341
261
|
const storage = params(builder(this.value));
|
|
342
262
|
const keys = this.value.share.keys().reduce((set, key) => set.add(key), /* @__PURE__ */ new Set());
|
|
343
|
-
this._storage = Object.entries(storage).reduce(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
this._warn(oneLine`
|
|
348
|
-
Warning: You are using \`yjs.xmlElement\` to declare top-level storage value \`${key}\`.
|
|
349
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
350
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
351
|
-
https://pluv.io/docs/migration-guides/v3
|
|
352
|
-
`);
|
|
353
|
-
const yXmlElement = this.value.getXmlElement(key);
|
|
354
|
-
if (!!((_a = node.initialValue) == null ? void 0 : _a.length)) {
|
|
355
|
-
yXmlElement.insert(0, (_b = node.initialValue) == null ? void 0 : _b.slice(0));
|
|
356
|
-
}
|
|
357
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlElement });
|
|
358
|
-
}
|
|
359
|
-
if (node instanceof YjsXmlFragment) {
|
|
360
|
-
this._warn(oneLine`
|
|
361
|
-
Warning: You are using \`yjs.xmlFragment\` to declare top-level storage value \`${key}\`.
|
|
362
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
363
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
364
|
-
https://pluv.io/docs/migration-guides/v3
|
|
365
|
-
`);
|
|
366
|
-
const yXmlFragment = this.value.getXmlFragment(key);
|
|
367
|
-
if (!!((_c = node.initialValue) == null ? void 0 : _c.length)) {
|
|
368
|
-
yXmlFragment.insert(0, (_d = node.initialValue) == null ? void 0 : _d.slice(0));
|
|
369
|
-
}
|
|
370
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlFragment });
|
|
371
|
-
}
|
|
372
|
-
if (node instanceof YjsXmlText) {
|
|
373
|
-
this._warn(oneLine`
|
|
374
|
-
Warning: You are using \`yjs.xmlText\` to declare top-level storage value \`${key}\`.
|
|
375
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
376
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
377
|
-
https://pluv.io/docs/migration-guides/v3
|
|
378
|
-
`);
|
|
379
|
-
const yXmlText = this.value.get(key, YXmlText3);
|
|
380
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yXmlText });
|
|
381
|
-
}
|
|
382
|
-
if (node instanceof YjsArray) {
|
|
383
|
-
this._warn(oneLine`
|
|
384
|
-
Warning: You are using \`yjs.array\` to declare top-level storage value \`${key}\`.
|
|
385
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
386
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
387
|
-
https://pluv.io/docs/migration-guides/v3
|
|
388
|
-
`);
|
|
389
|
-
const yArray = this.value.getArray(key);
|
|
390
|
-
if (!!((_e = node.initialValue) == null ? void 0 : _e.length)) yArray.insert(0, (_f = node.initialValue) == null ? void 0 : _f.slice(0));
|
|
391
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yArray });
|
|
392
|
-
}
|
|
393
|
-
if (node instanceof YjsMap) {
|
|
394
|
-
this._warn(oneLine`
|
|
395
|
-
Warning: You are using \`yjs.map\` to declare top-level storage value \`${key}\`.
|
|
396
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
397
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
398
|
-
https://pluv.io/docs/migration-guides/v3
|
|
399
|
-
`);
|
|
400
|
-
const yMap = this.value.getMap(key);
|
|
401
|
-
((_g = node.initialValue) != null ? _g : []).forEach(([k, v]) => {
|
|
402
|
-
yMap.set(k.toString(), v);
|
|
403
|
-
});
|
|
404
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yMap });
|
|
405
|
-
}
|
|
406
|
-
if (node instanceof YjsObject) {
|
|
407
|
-
this._warn(oneLine`
|
|
408
|
-
Warning: You are using \`yjs.object\` to declare top-level storage value \`${key}\`.
|
|
409
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
410
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
411
|
-
https://pluv.io/docs/migration-guides/v3
|
|
412
|
-
`);
|
|
413
|
-
const yMap = this.value.getMap(key);
|
|
414
|
-
Object.entries((_h = node.initialValue) != null ? _h : {}).forEach(([k, v]) => {
|
|
415
|
-
yMap.set(k.toString(), v);
|
|
416
|
-
});
|
|
417
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yMap });
|
|
418
|
-
}
|
|
419
|
-
if (node instanceof YjsText) {
|
|
420
|
-
this._warn(oneLine`
|
|
421
|
-
Warning: You are using \`yjs.text\` to declare top-level storage value \`${key}\`.
|
|
422
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
423
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
424
|
-
https://pluv.io/docs/migration-guides/v3
|
|
425
|
-
`);
|
|
426
|
-
const yText = this.value.getText(key);
|
|
427
|
-
if (typeof node.initialValue === "string") yText.insert(0, node.initialValue);
|
|
428
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: yText });
|
|
429
|
-
}
|
|
430
|
-
return acc;
|
|
431
|
-
}, {});
|
|
263
|
+
this._storage = Object.entries(storage).reduce(
|
|
264
|
+
(acc, [key, node]) => keys.has(key) ? __spreadProps(__spreadValues({}, acc), { [key]: node }) : acc,
|
|
265
|
+
{}
|
|
266
|
+
);
|
|
432
267
|
}
|
|
433
268
|
applyEncodedState(params) {
|
|
434
269
|
const { origin, update } = params;
|
|
@@ -487,16 +322,16 @@ var CrdtYjsDoc = class {
|
|
|
487
322
|
return this;
|
|
488
323
|
}
|
|
489
324
|
this._storage = Object.entries(reference).reduce((acc, [key, node]) => {
|
|
490
|
-
if (node instanceof
|
|
325
|
+
if (node instanceof YXmlElement2) {
|
|
491
326
|
return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlElement(key) });
|
|
492
327
|
}
|
|
493
|
-
if (node instanceof
|
|
328
|
+
if (node instanceof YXmlFragment2) {
|
|
494
329
|
return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getXmlFragment(key) });
|
|
495
330
|
}
|
|
496
|
-
if (node instanceof
|
|
331
|
+
if (node instanceof YXmlText2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.get(key, YXmlText2) });
|
|
497
332
|
if (node instanceof YArray3) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getArray(key) });
|
|
498
|
-
if (node instanceof
|
|
499
|
-
if (node instanceof
|
|
333
|
+
if (node instanceof YMap2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getMap(key) });
|
|
334
|
+
if (node instanceof YText2) return __spreadProps(__spreadValues({}, acc), { [key]: this.value.getText(key) });
|
|
500
335
|
return acc;
|
|
501
336
|
}, {});
|
|
502
337
|
return this.track();
|
|
@@ -525,7 +360,7 @@ var CrdtYjsDoc = class {
|
|
|
525
360
|
if (this._undoManager) this._undoManager.destroy();
|
|
526
361
|
const sharedTypes = Object.values(this._storage).reduce(
|
|
527
362
|
(acc, type) => {
|
|
528
|
-
if (type instanceof YArray3 || type instanceof
|
|
363
|
+
if (type instanceof YArray3 || type instanceof YMap2 || type instanceof YText2 || type instanceof YXmlElement2 || type instanceof YXmlFragment2 || type instanceof YXmlText2) {
|
|
529
364
|
acc.push(type);
|
|
530
365
|
}
|
|
531
366
|
return acc;
|
|
@@ -587,16 +422,23 @@ var doc = (value = () => ({})) => {
|
|
|
587
422
|
return new CrdtYjsDocFactory(value);
|
|
588
423
|
};
|
|
589
424
|
|
|
425
|
+
// src/map/YjsMap.ts
|
|
426
|
+
import { Map as YMap3 } from "yjs";
|
|
427
|
+
var YjsMap = class extends YMap3 {
|
|
428
|
+
constructor(value = []) {
|
|
429
|
+
super(value);
|
|
430
|
+
this.initialValue = value;
|
|
431
|
+
}
|
|
432
|
+
__pluvType() {
|
|
433
|
+
return {};
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
590
437
|
// src/map/map.ts
|
|
591
438
|
var map = (value = []) => {
|
|
592
439
|
return new YjsMap(value);
|
|
593
440
|
};
|
|
594
441
|
|
|
595
|
-
// src/object/object.ts
|
|
596
|
-
var object = (value = {}) => {
|
|
597
|
-
return new YjsObject(value);
|
|
598
|
-
};
|
|
599
|
-
|
|
600
442
|
// src/provider/PluvYjsProvider.ts
|
|
601
443
|
import { StorageState } from "@pluv/types";
|
|
602
444
|
import { ObservableV2 as ObservableV22 } from "lib0/observable";
|
|
@@ -677,21 +519,71 @@ var provider = (params) => {
|
|
|
677
519
|
return new PluvYjsProvider(params);
|
|
678
520
|
};
|
|
679
521
|
|
|
522
|
+
// src/text/YjsText.ts
|
|
523
|
+
import { Text as YText3 } from "yjs";
|
|
524
|
+
var YjsText = class extends YText3 {
|
|
525
|
+
constructor(value = "") {
|
|
526
|
+
super();
|
|
527
|
+
this.initialValue = value;
|
|
528
|
+
}
|
|
529
|
+
__pluvType() {
|
|
530
|
+
return {};
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
680
534
|
// src/text/text.ts
|
|
681
535
|
var text = (value = "") => {
|
|
682
536
|
return new YjsText(value);
|
|
683
537
|
};
|
|
684
538
|
|
|
539
|
+
// src/xmlElement/YjsXmlElement.ts
|
|
540
|
+
import { XmlElement as YXmlElement3 } from "yjs";
|
|
541
|
+
var YjsXmlElement = class extends YXmlElement3 {
|
|
542
|
+
constructor(name, value) {
|
|
543
|
+
super(name);
|
|
544
|
+
if (!!value.length) this.insert(0, value);
|
|
545
|
+
this.initialValue = value;
|
|
546
|
+
}
|
|
547
|
+
__pluvType() {
|
|
548
|
+
return {};
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
|
|
685
552
|
// src/xmlElement/xmlElement.ts
|
|
686
553
|
var xmlElement = (name, children) => {
|
|
687
554
|
return new YjsXmlElement(name, children);
|
|
688
555
|
};
|
|
689
556
|
|
|
557
|
+
// src/xmlFragment/YjsXmlFragment.ts
|
|
558
|
+
import { XmlFragment as YXmlFragment3 } from "yjs";
|
|
559
|
+
var YjsXmlFragment = class extends YXmlFragment3 {
|
|
560
|
+
constructor(value) {
|
|
561
|
+
super();
|
|
562
|
+
if (!!value.length) this.insert(0, value);
|
|
563
|
+
this.initialValue = value;
|
|
564
|
+
}
|
|
565
|
+
__pluvType() {
|
|
566
|
+
return {};
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
690
570
|
// src/xmlFragment/xmlFragment.ts
|
|
691
571
|
var xmlFragment = (children) => {
|
|
692
572
|
return new YjsXmlFragment(children);
|
|
693
573
|
};
|
|
694
574
|
|
|
575
|
+
// src/xmlText/YjsXmlText.ts
|
|
576
|
+
import { XmlText as YXmlText3 } from "yjs";
|
|
577
|
+
var YjsXmlText = class extends YXmlText3 {
|
|
578
|
+
constructor(value = "") {
|
|
579
|
+
super();
|
|
580
|
+
this.initialValue = value;
|
|
581
|
+
}
|
|
582
|
+
__pluvType() {
|
|
583
|
+
return {};
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
|
|
695
587
|
// src/xmlText/xmlText.ts
|
|
696
588
|
var xmlText = () => {
|
|
697
589
|
return new YjsXmlText();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-yjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "yjs for @pluv/io",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@types/node": "^22.15.21",
|
|
21
21
|
"js-base64": "^3.7.7",
|
|
22
22
|
"lib0": "^0.2.108",
|
|
23
|
-
"@pluv/crdt": "^
|
|
24
|
-
"@pluv/types": "^
|
|
23
|
+
"@pluv/crdt": "^3.0.0",
|
|
24
|
+
"@pluv/types": "^3.0.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"yjs": "^13.0.0"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"yjs": "^13.6.27",
|
|
34
|
-
"@pluv/tsconfig": "^
|
|
35
|
-
"eslint-config-pluv": "^
|
|
34
|
+
"@pluv/tsconfig": "^3.0.0",
|
|
35
|
+
"eslint-config-pluv": "^3.0.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/doc/CrdtYjsDoc.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
} from "yjs";
|
|
23
23
|
import { YjsArray } from "../array/YjsArray";
|
|
24
24
|
import { YjsMap } from "../map/YjsMap";
|
|
25
|
-
import { YjsObject } from "../object/YjsObject";
|
|
26
25
|
import { YjsText } from "../text/YjsText";
|
|
27
26
|
import type { YjsType } from "../types";
|
|
28
27
|
import { oneLine } from "../utils";
|
|
@@ -50,133 +49,10 @@ export class CrdtYjsDoc<TStorage extends Record<string, YjsType<any, any>>>
|
|
|
50
49
|
const storage = params(builder(this.value));
|
|
51
50
|
const keys = this.value.share.keys().reduce((set, key) => set.add(key), new Set<string>());
|
|
52
51
|
|
|
53
|
-
this._storage = Object.entries(storage).reduce(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
* @date May 8, 2025
|
|
58
|
-
*/
|
|
59
|
-
if (keys.has(key)) return { ...acc, [key]: node };
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @description It is important that the XML shared-types be checked before the others
|
|
63
|
-
* because they extend off the non-xml types (thereby you can mistakenly identify the
|
|
64
|
-
* wrong type if checked in the reverse order)
|
|
65
|
-
* @date May 9 ,2025
|
|
66
|
-
*/
|
|
67
|
-
if (node instanceof YjsXmlElement) {
|
|
68
|
-
this._warn(oneLine`
|
|
69
|
-
Warning: You are using \`yjs.xmlElement\` to declare top-level storage value \`${key}\`.
|
|
70
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
71
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
72
|
-
https://pluv.io/docs/migration-guides/v3
|
|
73
|
-
`);
|
|
74
|
-
|
|
75
|
-
const yXmlElement = this.value.getXmlElement(key);
|
|
76
|
-
|
|
77
|
-
if (!!node.initialValue?.length) {
|
|
78
|
-
yXmlElement.insert(0, node.initialValue?.slice(0));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return { ...acc, [key]: yXmlElement };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (node instanceof YjsXmlFragment) {
|
|
85
|
-
this._warn(oneLine`
|
|
86
|
-
Warning: You are using \`yjs.xmlFragment\` to declare top-level storage value \`${key}\`.
|
|
87
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
88
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
89
|
-
https://pluv.io/docs/migration-guides/v3
|
|
90
|
-
`);
|
|
91
|
-
|
|
92
|
-
const yXmlFragment = this.value.getXmlFragment(key);
|
|
93
|
-
|
|
94
|
-
if (!!node.initialValue?.length) {
|
|
95
|
-
yXmlFragment.insert(0, node.initialValue?.slice(0));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return { ...acc, [key]: yXmlFragment };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (node instanceof YjsXmlText) {
|
|
102
|
-
this._warn(oneLine`
|
|
103
|
-
Warning: You are using \`yjs.xmlText\` to declare top-level storage value \`${key}\`.
|
|
104
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
105
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
106
|
-
https://pluv.io/docs/migration-guides/v3
|
|
107
|
-
`);
|
|
108
|
-
|
|
109
|
-
const yXmlText = this.value.get(key, YXmlText) as YXmlText;
|
|
110
|
-
|
|
111
|
-
return { ...acc, [key]: yXmlText };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (node instanceof YjsArray) {
|
|
115
|
-
this._warn(oneLine`
|
|
116
|
-
Warning: You are using \`yjs.array\` to declare top-level storage value \`${key}\`.
|
|
117
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
118
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
119
|
-
https://pluv.io/docs/migration-guides/v3
|
|
120
|
-
`);
|
|
121
|
-
|
|
122
|
-
const yArray = this.value.getArray(key);
|
|
123
|
-
|
|
124
|
-
if (!!node.initialValue?.length) yArray.insert(0, node.initialValue?.slice(0));
|
|
125
|
-
|
|
126
|
-
return { ...acc, [key]: yArray };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (node instanceof YjsMap) {
|
|
130
|
-
this._warn(oneLine`
|
|
131
|
-
Warning: You are using \`yjs.map\` to declare top-level storage value \`${key}\`.
|
|
132
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
133
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
134
|
-
https://pluv.io/docs/migration-guides/v3
|
|
135
|
-
`);
|
|
136
|
-
|
|
137
|
-
const yMap = this.value.getMap(key);
|
|
138
|
-
|
|
139
|
-
(node.initialValue ?? []).forEach(([k, v]) => {
|
|
140
|
-
yMap.set(k.toString(), v);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
return { ...acc, [key]: yMap };
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (node instanceof YjsObject) {
|
|
147
|
-
this._warn(oneLine`
|
|
148
|
-
Warning: You are using \`yjs.object\` to declare top-level storage value \`${key}\`.
|
|
149
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
150
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
151
|
-
https://pluv.io/docs/migration-guides/v3
|
|
152
|
-
`);
|
|
153
|
-
|
|
154
|
-
const yMap = this.value.getMap(key);
|
|
155
|
-
|
|
156
|
-
Object.entries(node.initialValue ?? {}).forEach(([k, v]) => {
|
|
157
|
-
yMap.set(k.toString(), v);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return { ...acc, [key]: yMap };
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (node instanceof YjsText) {
|
|
164
|
-
this._warn(oneLine`
|
|
165
|
-
Warning: You are using \`yjs.text\` to declare top-level storage value \`${key}\`.
|
|
166
|
-
Adding top-level values this way has been deprecated, to be removed in v3.
|
|
167
|
-
Please follow the v3 migration guide to declare top-level types correctly:
|
|
168
|
-
https://pluv.io/docs/migration-guides/v3
|
|
169
|
-
`);
|
|
170
|
-
|
|
171
|
-
const yText = this.value.getText(key);
|
|
172
|
-
|
|
173
|
-
if (typeof node.initialValue === "string") yText.insert(0, node.initialValue);
|
|
174
|
-
|
|
175
|
-
return { ...acc, [key]: yText };
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return acc;
|
|
179
|
-
}, {} as TStorage);
|
|
52
|
+
this._storage = Object.entries(storage).reduce(
|
|
53
|
+
(acc, [key, node]) => (keys.has(key) ? { ...acc, [key]: node } : acc),
|
|
54
|
+
{} as TStorage,
|
|
55
|
+
);
|
|
180
56
|
}
|
|
181
57
|
|
|
182
58
|
public applyEncodedState(params: DocApplyEncodedStateParams): this {
|
package/src/yjs.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { awareness } from "./awareness";
|
|
|
3
3
|
export { doc } from "./doc";
|
|
4
4
|
export type { YjsBuilder } from "./doc";
|
|
5
5
|
export { map } from "./map";
|
|
6
|
-
export { object } from "./object";
|
|
7
6
|
export { provider } from "./provider";
|
|
8
7
|
export { text } from "./text";
|
|
9
8
|
export type { YjsType } from "./types";
|
package/src/object/YjsObject.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Map as YMap } from "yjs";
|
|
2
|
-
import type { YjsType } from "../types";
|
|
3
|
-
|
|
4
|
-
export class YjsObject<T extends Record<string, any>>
|
|
5
|
-
extends YMap<T[keyof T]>
|
|
6
|
-
implements YjsType<YMap<T[keyof T]>, T>
|
|
7
|
-
{
|
|
8
|
-
public initialValue?: T;
|
|
9
|
-
|
|
10
|
-
constructor(value: T) {
|
|
11
|
-
super(Object.entries(value));
|
|
12
|
-
|
|
13
|
-
this.initialValue = value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public __pluvType() {
|
|
17
|
-
return {} as unknown as any;
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/object/index.ts
DELETED
package/src/object/object.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Map as YMap } from "yjs";
|
|
2
|
-
import type { YjsType } from "../types";
|
|
3
|
-
import { YjsObject } from "./YjsObject";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated This will be removed in v3.0.0. Use yjs.map instead
|
|
7
|
-
* @description Creates a Yjs map, but declare it like it's an object
|
|
8
|
-
* @date May 8, 2025
|
|
9
|
-
*/
|
|
10
|
-
export const object = <T extends Record<string, any>>(
|
|
11
|
-
value: T = {} as T,
|
|
12
|
-
): YjsType<YMap<T[keyof T]>, T> => {
|
|
13
|
-
return new YjsObject<T>(value);
|
|
14
|
-
};
|