@pluv/crdt-yjs 0.17.3 → 0.19.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 +15 -15
- package/CHANGELOG.md +15 -0
- package/dist/index.d.mts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +20 -43
- package/dist/index.mjs +20 -43
- package/package.json +7 -7
- package/src/array/CrdtYjsArray.ts +2 -7
- package/src/array/array.ts +1 -3
- package/src/doc/CrdtYjsDoc.ts +21 -49
- package/src/doc/CrdtYjsDocFactory.ts +4 -12
- package/src/doc/doc.ts +1 -3
- package/src/map/CrdtYjsMap.ts +1 -4
- package/src/map/map.ts +1 -3
- package/src/object/CrdtYjsObject.ts +5 -7
- package/src/object/object.ts +1 -3
- package/src/shared/isWrapper.ts +1 -5
- package/src/xmlElement/CrdtYjsXmlElement.ts +4 -14
- package/src/xmlFragment/CrdtYjsXmlFragment.ts +3 -10
- package/src/xmlFragment/xmlFragment.ts +1 -3
- package/src/xmlText/CrdtYjsXmlText.ts +1 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@0.
|
|
2
|
+
> @pluv/crdt-yjs@0.19.0 build /home/runner/work/pluv/pluv/packages/crdt-yjs
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
CLI Building entry: src/index.ts
|
|
6
|
+
CLI Using tsconfig: tsconfig.json
|
|
7
|
+
CLI tsup v8.1.0
|
|
8
|
+
CLI Target: es6
|
|
9
|
+
ESM Build start
|
|
10
|
+
CJS Build start
|
|
11
|
+
ESM dist/index.mjs 14.61 KB
|
|
12
|
+
ESM ⚡️ Build success in 129ms
|
|
13
|
+
CJS dist/index.js 15.31 KB
|
|
14
|
+
CJS ⚡️ Build success in 129ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 2456ms
|
|
17
|
+
DTS dist/index.d.mts 8.38 KB
|
|
18
|
+
DTS dist/index.d.ts 8.38 KB
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/crdt-yjs
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@0.19.0
|
|
8
|
+
- @pluv/types@0.19.0
|
|
9
|
+
|
|
10
|
+
## 0.18.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [99b5ca9]
|
|
15
|
+
- @pluv/types@0.18.0
|
|
16
|
+
- @pluv/crdt@0.18.0
|
|
17
|
+
|
|
3
18
|
## 0.17.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3,10 +3,7 @@ import { Map, Text, XmlText, XmlElement, XmlFragment, Array, Doc } from 'yjs';
|
|
|
3
3
|
import { Json } from '@pluv/types';
|
|
4
4
|
|
|
5
5
|
declare class CrdtYjsMap<T extends unknown> extends AbstractCrdtType<Map<InferYjsType<T>>, Record<string, InferYjsJson<T>>> {
|
|
6
|
-
initialValue: readonly (readonly [
|
|
7
|
-
key: string,
|
|
8
|
-
value: InferYjsType<T>
|
|
9
|
-
])[];
|
|
6
|
+
initialValue: readonly (readonly [key: string, value: InferYjsType<T>])[];
|
|
10
7
|
value: Map<InferYjsType<T>>;
|
|
11
8
|
constructor(value?: readonly (readonly [key: string, value: T])[]);
|
|
12
9
|
get size(): number;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,7 @@ import { Map, Text, XmlText, XmlElement, XmlFragment, Array, Doc } from 'yjs';
|
|
|
3
3
|
import { Json } from '@pluv/types';
|
|
4
4
|
|
|
5
5
|
declare class CrdtYjsMap<T extends unknown> extends AbstractCrdtType<Map<InferYjsType<T>>, Record<string, InferYjsJson<T>>> {
|
|
6
|
-
initialValue: readonly (readonly [
|
|
7
|
-
key: string,
|
|
8
|
-
value: InferYjsType<T>
|
|
9
|
-
])[];
|
|
6
|
+
initialValue: readonly (readonly [key: string, value: InferYjsType<T>])[];
|
|
10
7
|
value: Map<InferYjsType<T>>;
|
|
11
8
|
constructor(value?: readonly (readonly [key: string, value: T])[]);
|
|
12
9
|
get size(): number;
|
package/dist/index.js
CHANGED
|
@@ -96,10 +96,7 @@ var import_yjs2 = require("yjs");
|
|
|
96
96
|
var CrdtYjsObject = class extends import_crdt2.AbstractCrdtType {
|
|
97
97
|
constructor(value = {}) {
|
|
98
98
|
super();
|
|
99
|
-
this.initialValue = Object.entries(value).map(([k, v]) => [
|
|
100
|
-
k,
|
|
101
|
-
toYjsValue(v)
|
|
102
|
-
]);
|
|
99
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, toYjsValue(v)]);
|
|
103
100
|
this.value = new import_yjs2.Map(this.initialValue);
|
|
104
101
|
}
|
|
105
102
|
set(prop, value) {
|
|
@@ -329,19 +326,13 @@ var CrdtYjsDoc = class extends import_crdt8.AbstractCrdtDoc {
|
|
|
329
326
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
330
327
|
}
|
|
331
328
|
if (node instanceof CrdtYjsXmlElement) {
|
|
332
|
-
const yXmlElement = this.value.get(
|
|
333
|
-
key,
|
|
334
|
-
import_yjs8.XmlElement
|
|
335
|
-
);
|
|
329
|
+
const yXmlElement = this.value.get(key, import_yjs8.XmlElement);
|
|
336
330
|
yXmlElement.insert(0, node.initialValue.slice(0));
|
|
337
331
|
node.value = yXmlElement;
|
|
338
332
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
339
333
|
}
|
|
340
334
|
if (node instanceof CrdtYjsXmlFragment) {
|
|
341
|
-
const yXmlFragment = this.value.get(
|
|
342
|
-
key,
|
|
343
|
-
import_yjs8.XmlFragment
|
|
344
|
-
);
|
|
335
|
+
const yXmlFragment = this.value.get(key, import_yjs8.XmlFragment);
|
|
345
336
|
yXmlFragment.insert(0, node.initialValue.slice(0));
|
|
346
337
|
node.value = yXmlFragment;
|
|
347
338
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
@@ -357,33 +348,25 @@ var CrdtYjsDoc = class extends import_crdt8.AbstractCrdtDoc {
|
|
|
357
348
|
}
|
|
358
349
|
applyEncodedState(params) {
|
|
359
350
|
const { origin, update } = params;
|
|
360
|
-
if (update === null || typeof update === "undefined")
|
|
361
|
-
return this;
|
|
351
|
+
if (update === null || typeof update === "undefined") return this;
|
|
362
352
|
const uint8Update = typeof update === "string" ? (0, import_js_base64.toUint8Array)(update) : update;
|
|
363
353
|
(0, import_yjs8.applyUpdate)(this.value, uint8Update, origin);
|
|
364
354
|
return this;
|
|
365
355
|
}
|
|
366
356
|
batchApplyEncodedState(updates) {
|
|
367
|
-
const params = updates.reduce(
|
|
368
|
-
(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
if (typeof update === "string") {
|
|
372
|
-
acc.push({ update });
|
|
373
|
-
return acc;
|
|
374
|
-
}
|
|
375
|
-
if (!!update && typeof update === "object") {
|
|
376
|
-
acc.push(update);
|
|
377
|
-
return acc;
|
|
378
|
-
}
|
|
357
|
+
const params = updates.reduce((acc, update) => {
|
|
358
|
+
if (!update) return acc;
|
|
359
|
+
if (typeof update === "string") {
|
|
360
|
+
acc.push({ update });
|
|
379
361
|
return acc;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
);
|
|
362
|
+
}
|
|
363
|
+
if (!!update && typeof update === "object") {
|
|
364
|
+
acc.push(update);
|
|
365
|
+
return acc;
|
|
366
|
+
}
|
|
367
|
+
return acc;
|
|
368
|
+
}, []);
|
|
369
|
+
return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
|
|
387
370
|
}
|
|
388
371
|
canRedo() {
|
|
389
372
|
var _a;
|
|
@@ -399,8 +382,7 @@ var CrdtYjsDoc = class extends import_crdt8.AbstractCrdtDoc {
|
|
|
399
382
|
this.value.destroy();
|
|
400
383
|
}
|
|
401
384
|
get(key) {
|
|
402
|
-
if (typeof key === "undefined")
|
|
403
|
-
return this._storage;
|
|
385
|
+
if (typeof key === "undefined") return this._storage;
|
|
404
386
|
return this._storage[key];
|
|
405
387
|
}
|
|
406
388
|
getEncodedState() {
|
|
@@ -430,8 +412,7 @@ var CrdtYjsDoc = class extends import_crdt8.AbstractCrdtDoc {
|
|
|
430
412
|
}
|
|
431
413
|
track() {
|
|
432
414
|
var _a;
|
|
433
|
-
if (this._undoManager)
|
|
434
|
-
this._undoManager.destroy();
|
|
415
|
+
if (this._undoManager) this._undoManager.destroy();
|
|
435
416
|
const sharedTypes = Object.values(this._storage).reduce((acc, type) => {
|
|
436
417
|
if (type instanceof CrdtYjsArray || type instanceof CrdtYjsMap || type instanceof CrdtYjsObject || type instanceof CrdtYjsText || type instanceof CrdtYjsXmlElement || type instanceof CrdtYjsXmlFragment || type instanceof CrdtYjsXmlText) {
|
|
437
418
|
acc.push(type.value);
|
|
@@ -486,9 +467,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends import_crdt9.AbstractCr
|
|
|
486
467
|
return new CrdtYjsDoc();
|
|
487
468
|
}
|
|
488
469
|
getFactory(initialStorage) {
|
|
489
|
-
return new _CrdtYjsDocFactory(
|
|
490
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
491
|
-
);
|
|
470
|
+
return new _CrdtYjsDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
492
471
|
}
|
|
493
472
|
getFresh() {
|
|
494
473
|
const storage = this._initialStorage();
|
|
@@ -523,9 +502,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends import_crdt9.AbstractCr
|
|
|
523
502
|
}
|
|
524
503
|
getInitialized(initialStorage) {
|
|
525
504
|
var _a;
|
|
526
|
-
return new CrdtYjsDoc(
|
|
527
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
528
|
-
);
|
|
505
|
+
return new CrdtYjsDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
529
506
|
}
|
|
530
507
|
};
|
|
531
508
|
|
package/dist/index.mjs
CHANGED
|
@@ -77,10 +77,7 @@ import { Map as YMap2 } from "yjs";
|
|
|
77
77
|
var CrdtYjsObject = class extends AbstractCrdtType2 {
|
|
78
78
|
constructor(value = {}) {
|
|
79
79
|
super();
|
|
80
|
-
this.initialValue = Object.entries(value).map(([k, v]) => [
|
|
81
|
-
k,
|
|
82
|
-
toYjsValue(v)
|
|
83
|
-
]);
|
|
80
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, toYjsValue(v)]);
|
|
84
81
|
this.value = new YMap2(this.initialValue);
|
|
85
82
|
}
|
|
86
83
|
set(prop, value) {
|
|
@@ -321,19 +318,13 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
|
|
|
321
318
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
322
319
|
}
|
|
323
320
|
if (node instanceof CrdtYjsXmlElement) {
|
|
324
|
-
const yXmlElement = this.value.get(
|
|
325
|
-
key,
|
|
326
|
-
YXmlElement2
|
|
327
|
-
);
|
|
321
|
+
const yXmlElement = this.value.get(key, YXmlElement2);
|
|
328
322
|
yXmlElement.insert(0, node.initialValue.slice(0));
|
|
329
323
|
node.value = yXmlElement;
|
|
330
324
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
331
325
|
}
|
|
332
326
|
if (node instanceof CrdtYjsXmlFragment) {
|
|
333
|
-
const yXmlFragment = this.value.get(
|
|
334
|
-
key,
|
|
335
|
-
YXmlFragment2
|
|
336
|
-
);
|
|
327
|
+
const yXmlFragment = this.value.get(key, YXmlFragment2);
|
|
337
328
|
yXmlFragment.insert(0, node.initialValue.slice(0));
|
|
338
329
|
node.value = yXmlFragment;
|
|
339
330
|
return __spreadProps(__spreadValues({}, acc), { [key]: node });
|
|
@@ -349,33 +340,25 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
|
|
|
349
340
|
}
|
|
350
341
|
applyEncodedState(params) {
|
|
351
342
|
const { origin, update } = params;
|
|
352
|
-
if (update === null || typeof update === "undefined")
|
|
353
|
-
return this;
|
|
343
|
+
if (update === null || typeof update === "undefined") return this;
|
|
354
344
|
const uint8Update = typeof update === "string" ? toUint8Array(update) : update;
|
|
355
345
|
applyUpdate(this.value, uint8Update, origin);
|
|
356
346
|
return this;
|
|
357
347
|
}
|
|
358
348
|
batchApplyEncodedState(updates) {
|
|
359
|
-
const params = updates.reduce(
|
|
360
|
-
(
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (typeof update === "string") {
|
|
364
|
-
acc.push({ update });
|
|
365
|
-
return acc;
|
|
366
|
-
}
|
|
367
|
-
if (!!update && typeof update === "object") {
|
|
368
|
-
acc.push(update);
|
|
369
|
-
return acc;
|
|
370
|
-
}
|
|
349
|
+
const params = updates.reduce((acc, update) => {
|
|
350
|
+
if (!update) return acc;
|
|
351
|
+
if (typeof update === "string") {
|
|
352
|
+
acc.push({ update });
|
|
371
353
|
return acc;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
);
|
|
354
|
+
}
|
|
355
|
+
if (!!update && typeof update === "object") {
|
|
356
|
+
acc.push(update);
|
|
357
|
+
return acc;
|
|
358
|
+
}
|
|
359
|
+
return acc;
|
|
360
|
+
}, []);
|
|
361
|
+
return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
|
|
379
362
|
}
|
|
380
363
|
canRedo() {
|
|
381
364
|
var _a;
|
|
@@ -391,8 +374,7 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
|
|
|
391
374
|
this.value.destroy();
|
|
392
375
|
}
|
|
393
376
|
get(key) {
|
|
394
|
-
if (typeof key === "undefined")
|
|
395
|
-
return this._storage;
|
|
377
|
+
if (typeof key === "undefined") return this._storage;
|
|
396
378
|
return this._storage[key];
|
|
397
379
|
}
|
|
398
380
|
getEncodedState() {
|
|
@@ -422,8 +404,7 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
|
|
|
422
404
|
}
|
|
423
405
|
track() {
|
|
424
406
|
var _a;
|
|
425
|
-
if (this._undoManager)
|
|
426
|
-
this._undoManager.destroy();
|
|
407
|
+
if (this._undoManager) this._undoManager.destroy();
|
|
427
408
|
const sharedTypes = Object.values(this._storage).reduce((acc, type) => {
|
|
428
409
|
if (type instanceof CrdtYjsArray || type instanceof CrdtYjsMap || type instanceof CrdtYjsObject || type instanceof CrdtYjsText || type instanceof CrdtYjsXmlElement || type instanceof CrdtYjsXmlFragment || type instanceof CrdtYjsXmlText) {
|
|
429
410
|
acc.push(type.value);
|
|
@@ -478,9 +459,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends AbstractCrdtDocFactory
|
|
|
478
459
|
return new CrdtYjsDoc();
|
|
479
460
|
}
|
|
480
461
|
getFactory(initialStorage) {
|
|
481
|
-
return new _CrdtYjsDocFactory(
|
|
482
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
483
|
-
);
|
|
462
|
+
return new _CrdtYjsDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
484
463
|
}
|
|
485
464
|
getFresh() {
|
|
486
465
|
const storage = this._initialStorage();
|
|
@@ -515,9 +494,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends AbstractCrdtDocFactory
|
|
|
515
494
|
}
|
|
516
495
|
getInitialized(initialStorage) {
|
|
517
496
|
var _a;
|
|
518
|
-
return new CrdtYjsDoc(
|
|
519
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
520
|
-
);
|
|
497
|
+
return new CrdtYjsDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
521
498
|
}
|
|
522
499
|
};
|
|
523
500
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-yjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "yjs for @pluv/io",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"js-base64": "^3.7.7",
|
|
21
|
-
"@pluv/crdt": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/crdt": "^0.19.0",
|
|
22
|
+
"@pluv/types": "^0.19.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"yjs": "^13.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
|
-
"tsup": "^8.0
|
|
29
|
+
"tsup": "^8.1.0",
|
|
30
30
|
"typescript": "^5.4.5",
|
|
31
|
-
"yjs": "^13.6.
|
|
32
|
-
"@pluv/tsconfig": "^0.
|
|
33
|
-
"eslint-config-pluv": "^0.
|
|
31
|
+
"yjs": "^13.6.18",
|
|
32
|
+
"@pluv/tsconfig": "^0.19.0",
|
|
33
|
+
"eslint-config-pluv": "^0.19.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -4,13 +4,8 @@ import { Array as YArray } from "yjs";
|
|
|
4
4
|
import { toYjsValue } from "../shared";
|
|
5
5
|
import type { InferYjsJson, InferYjsType } from "../types";
|
|
6
6
|
|
|
7
|
-
export class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<
|
|
8
|
-
|
|
9
|
-
InferYjsJson<T>[]
|
|
10
|
-
> {
|
|
11
|
-
public readonly initialValue:
|
|
12
|
-
| InferYjsType<T>[]
|
|
13
|
-
| readonly InferYjsType<T>[];
|
|
7
|
+
export class CrdtYjsArray<T extends unknown> extends AbstractCrdtType<YArray<InferYjsType<T>>, InferYjsJson<T>[]> {
|
|
8
|
+
public readonly initialValue: InferYjsType<T>[] | readonly InferYjsType<T>[];
|
|
14
9
|
public value: YArray<InferYjsType<T>>;
|
|
15
10
|
|
|
16
11
|
constructor(value: T[] | readonly T[] = []) {
|
package/src/array/array.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtYjsArray } from "./CrdtYjsArray";
|
|
2
2
|
|
|
3
|
-
export const array = <T extends unknown>(
|
|
4
|
-
value: T[] | readonly T[] = [],
|
|
5
|
-
): CrdtYjsArray<T> => {
|
|
3
|
+
export const array = <T extends unknown>(value: T[] | readonly T[] = []): CrdtYjsArray<T> => {
|
|
6
4
|
return new CrdtYjsArray<T>(value);
|
|
7
5
|
};
|
package/src/doc/CrdtYjsDoc.ts
CHANGED
|
@@ -27,9 +27,7 @@ import { CrdtYjsXmlElement } from "../xmlElement/CrdtYjsXmlElement";
|
|
|
27
27
|
import { CrdtYjsXmlFragment } from "../xmlFragment/CrdtYjsXmlFragment";
|
|
28
28
|
import { CrdtYjsXmlText } from "../xmlText/CrdtYjsXmlText";
|
|
29
29
|
|
|
30
|
-
export class CrdtYjsDoc<
|
|
31
|
-
TStorage extends Record<string, AbstractCrdtType<any, any>>,
|
|
32
|
-
> extends AbstractCrdtDoc<TStorage> {
|
|
30
|
+
export class CrdtYjsDoc<TStorage extends Record<string, AbstractCrdtType<any, any>>> extends AbstractCrdtDoc<TStorage> {
|
|
33
31
|
public value: YDoc = new YDoc();
|
|
34
32
|
|
|
35
33
|
private _storage: TStorage;
|
|
@@ -80,10 +78,7 @@ export class CrdtYjsDoc<
|
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
if (node instanceof CrdtYjsXmlElement) {
|
|
83
|
-
const yXmlElement = this.value.get(
|
|
84
|
-
key,
|
|
85
|
-
YXmlElement,
|
|
86
|
-
) as YXmlElement;
|
|
81
|
+
const yXmlElement = this.value.get(key, YXmlElement) as YXmlElement;
|
|
87
82
|
yXmlElement.insert(0, node.initialValue.slice(0));
|
|
88
83
|
|
|
89
84
|
node.value = yXmlElement;
|
|
@@ -92,10 +87,7 @@ export class CrdtYjsDoc<
|
|
|
92
87
|
}
|
|
93
88
|
|
|
94
89
|
if (node instanceof CrdtYjsXmlFragment) {
|
|
95
|
-
const yXmlFragment = this.value.get(
|
|
96
|
-
key,
|
|
97
|
-
YXmlFragment,
|
|
98
|
-
) as YXmlFragment;
|
|
90
|
+
const yXmlFragment = this.value.get(key, YXmlFragment) as YXmlFragment;
|
|
99
91
|
yXmlFragment.insert(0, node.initialValue.slice(0));
|
|
100
92
|
|
|
101
93
|
node.value = yXmlFragment;
|
|
@@ -121,47 +113,33 @@ export class CrdtYjsDoc<
|
|
|
121
113
|
|
|
122
114
|
if (update === null || typeof update === "undefined") return this;
|
|
123
115
|
|
|
124
|
-
const uint8Update =
|
|
125
|
-
typeof update === "string" ? toUint8Array(update) : update;
|
|
116
|
+
const uint8Update = typeof update === "string" ? toUint8Array(update) : update;
|
|
126
117
|
|
|
127
118
|
applyUpdate(this.value, uint8Update, origin);
|
|
128
119
|
|
|
129
120
|
return this;
|
|
130
121
|
}
|
|
131
122
|
|
|
132
|
-
public batchApplyEncodedState(
|
|
133
|
-
updates
|
|
134
|
-
|
|
135
|
-
| string
|
|
136
|
-
| null
|
|
137
|
-
| undefined
|
|
138
|
-
)[],
|
|
139
|
-
): this {
|
|
140
|
-
const params = updates.reduce<DocApplyEncodedStateParams[]>(
|
|
141
|
-
(acc, update) => {
|
|
142
|
-
if (!update) return acc;
|
|
123
|
+
public batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this {
|
|
124
|
+
const params = updates.reduce<DocApplyEncodedStateParams[]>((acc, update) => {
|
|
125
|
+
if (!update) return acc;
|
|
143
126
|
|
|
144
|
-
|
|
145
|
-
|
|
127
|
+
if (typeof update === "string") {
|
|
128
|
+
acc.push({ update });
|
|
146
129
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!!update && typeof update === "object") {
|
|
151
|
-
acc.push(update);
|
|
130
|
+
return acc;
|
|
131
|
+
}
|
|
152
132
|
|
|
153
|
-
|
|
154
|
-
|
|
133
|
+
if (!!update && typeof update === "object") {
|
|
134
|
+
acc.push(update);
|
|
155
135
|
|
|
156
136
|
return acc;
|
|
157
|
-
}
|
|
158
|
-
[],
|
|
159
|
-
);
|
|
137
|
+
}
|
|
160
138
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
);
|
|
139
|
+
return acc;
|
|
140
|
+
}, []);
|
|
141
|
+
|
|
142
|
+
return params.reduce((doc, update) => doc.applyEncodedState(update), this);
|
|
165
143
|
}
|
|
166
144
|
|
|
167
145
|
public canRedo(): boolean {
|
|
@@ -179,9 +157,7 @@ export class CrdtYjsDoc<
|
|
|
179
157
|
|
|
180
158
|
public get(key?: undefined): TStorage;
|
|
181
159
|
public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
182
|
-
public get<TKey extends keyof TStorage>(
|
|
183
|
-
key?: TKey,
|
|
184
|
-
): TStorage | TStorage[TKey] {
|
|
160
|
+
public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {
|
|
185
161
|
if (typeof key === "undefined") return this._storage;
|
|
186
162
|
|
|
187
163
|
return this._storage[key as TKey];
|
|
@@ -201,9 +177,7 @@ export class CrdtYjsDoc<
|
|
|
201
177
|
return this;
|
|
202
178
|
}
|
|
203
179
|
|
|
204
|
-
public subscribe(
|
|
205
|
-
listener: (params: DocSubscribeCallbackParams<TStorage>) => void,
|
|
206
|
-
): () => void {
|
|
180
|
+
public subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void {
|
|
207
181
|
const fn = (update: Uint8Array, origin: any, doc: YDoc) => {
|
|
208
182
|
listener({
|
|
209
183
|
doc: this,
|
|
@@ -223,9 +197,7 @@ export class CrdtYjsDoc<
|
|
|
223
197
|
public track(): this {
|
|
224
198
|
if (this._undoManager) this._undoManager.destroy();
|
|
225
199
|
|
|
226
|
-
const sharedTypes = Object.values(this._storage).reduce<
|
|
227
|
-
YAbstractType<any>[]
|
|
228
|
-
>((acc, type) => {
|
|
200
|
+
const sharedTypes = Object.values(this._storage).reduce<YAbstractType<any>[]>((acc, type) => {
|
|
229
201
|
if (
|
|
230
202
|
type instanceof CrdtYjsArray ||
|
|
231
203
|
type instanceof CrdtYjsMap ||
|
|
@@ -24,12 +24,8 @@ export class CrdtYjsDocFactory<
|
|
|
24
24
|
return new CrdtYjsDoc<TStorage>();
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public getFactory(
|
|
28
|
-
|
|
29
|
-
): CrdtYjsDocFactory<TStorage> {
|
|
30
|
-
return new CrdtYjsDocFactory<TStorage>(
|
|
31
|
-
initialStorage ?? this._initialStorage,
|
|
32
|
-
);
|
|
27
|
+
public getFactory(initialStorage?: (() => TStorage) | undefined): CrdtYjsDocFactory<TStorage> {
|
|
28
|
+
return new CrdtYjsDocFactory<TStorage>(initialStorage ?? this._initialStorage);
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
public getFresh(): CrdtYjsDoc<TStorage> {
|
|
@@ -73,11 +69,7 @@ export class CrdtYjsDocFactory<
|
|
|
73
69
|
);
|
|
74
70
|
}
|
|
75
71
|
|
|
76
|
-
public getInitialized(
|
|
77
|
-
|
|
78
|
-
): CrdtYjsDoc<TStorage> {
|
|
79
|
-
return new CrdtYjsDoc<TStorage>(
|
|
80
|
-
initialStorage?.() ?? this._initialStorage(),
|
|
81
|
-
);
|
|
72
|
+
public getInitialized(initialStorage?: () => TStorage): CrdtYjsDoc<TStorage> {
|
|
73
|
+
return new CrdtYjsDoc<TStorage>(initialStorage?.() ?? this._initialStorage());
|
|
82
74
|
}
|
|
83
75
|
}
|
package/src/doc/doc.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AbstractCrdtType } from "@pluv/crdt";
|
|
2
2
|
import { CrdtYjsDocFactory } from "./CrdtYjsDocFactory";
|
|
3
3
|
|
|
4
|
-
export const doc = <
|
|
5
|
-
TStorage extends Record<string, AbstractCrdtType<any, any>>,
|
|
6
|
-
>(
|
|
4
|
+
export const doc = <TStorage extends Record<string, AbstractCrdtType<any, any>>>(
|
|
7
5
|
value: () => TStorage = () => ({}) as TStorage,
|
|
8
6
|
): CrdtYjsDocFactory<TStorage> => {
|
|
9
7
|
return new CrdtYjsDocFactory<TStorage>(value);
|
package/src/map/CrdtYjsMap.ts
CHANGED
|
@@ -8,10 +8,7 @@ export class CrdtYjsMap<T extends unknown> extends AbstractCrdtType<
|
|
|
8
8
|
YMap<InferYjsType<T>>,
|
|
9
9
|
Record<string, InferYjsJson<T>>
|
|
10
10
|
> {
|
|
11
|
-
public initialValue: readonly (readonly [
|
|
12
|
-
key: string,
|
|
13
|
-
value: InferYjsType<T>,
|
|
14
|
-
])[];
|
|
11
|
+
public initialValue: readonly (readonly [key: string, value: InferYjsType<T>])[];
|
|
15
12
|
public value: YMap<InferYjsType<T>>;
|
|
16
13
|
|
|
17
14
|
constructor(value: readonly (readonly [key: string, value: T])[] = []) {
|
package/src/map/map.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtYjsMap } from "./CrdtYjsMap";
|
|
2
2
|
|
|
3
|
-
export const map = <T extends unknown>(
|
|
4
|
-
value: readonly (readonly [key: string, value: T])[] = [],
|
|
5
|
-
): CrdtYjsMap<T> => {
|
|
3
|
+
export const map = <T extends unknown>(value: readonly (readonly [key: string, value: T])[] = []): CrdtYjsMap<T> => {
|
|
6
4
|
return new CrdtYjsMap<T>(value);
|
|
7
5
|
};
|
|
@@ -4,19 +4,17 @@ import { Map as YMap } from "yjs";
|
|
|
4
4
|
import { toYjsValue } from "../shared";
|
|
5
5
|
import type { InferYjsJson, InferYjsType } from "../types";
|
|
6
6
|
|
|
7
|
-
export class CrdtYjsObject<
|
|
8
|
-
T
|
|
9
|
-
|
|
7
|
+
export class CrdtYjsObject<T extends Record<string, any>> extends AbstractCrdtType<
|
|
8
|
+
YMap<InferYjsType<T[keyof T]>>,
|
|
9
|
+
InferYjsJson<T>
|
|
10
|
+
> {
|
|
10
11
|
public initialValue: readonly (readonly [key: string, value: T[keyof T]])[];
|
|
11
12
|
public value: YMap<InferYjsType<T[keyof T]>>;
|
|
12
13
|
|
|
13
14
|
constructor(value: T = {} as T) {
|
|
14
15
|
super();
|
|
15
16
|
|
|
16
|
-
this.initialValue = Object.entries(value).map(([k, v]) => [
|
|
17
|
-
k,
|
|
18
|
-
toYjsValue(v),
|
|
19
|
-
]);
|
|
17
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, toYjsValue(v)]);
|
|
20
18
|
this.value = new YMap(this.initialValue);
|
|
21
19
|
}
|
|
22
20
|
|
package/src/object/object.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtYjsObject } from "./CrdtYjsObject";
|
|
2
2
|
|
|
3
|
-
export const object = <T extends Record<string, any>>(
|
|
4
|
-
value: T,
|
|
5
|
-
): CrdtYjsObject<T> => {
|
|
3
|
+
export const object = <T extends Record<string, any>>(value: T): CrdtYjsObject<T> => {
|
|
6
4
|
return new CrdtYjsObject(value);
|
|
7
5
|
};
|
package/src/shared/isWrapper.ts
CHANGED
|
@@ -8,11 +8,7 @@ import { CrdtYjsXmlText } from "../xmlText";
|
|
|
8
8
|
|
|
9
9
|
export const isWrapper = (
|
|
10
10
|
item: any,
|
|
11
|
-
): item is
|
|
12
|
-
| CrdtYjsArray<any>
|
|
13
|
-
| CrdtYjsMap<any>
|
|
14
|
-
| CrdtYjsObject<any>
|
|
15
|
-
| CrdtYjsText => {
|
|
11
|
+
): item is CrdtYjsArray<any> | CrdtYjsMap<any> | CrdtYjsObject<any> | CrdtYjsText => {
|
|
16
12
|
return (
|
|
17
13
|
item instanceof CrdtYjsArray ||
|
|
18
14
|
item instanceof CrdtYjsMap ||
|
|
@@ -9,10 +9,7 @@ export class CrdtYjsXmlElement extends AbstractCrdtType<YXmlElement, string> {
|
|
|
9
9
|
public readonly name: string;
|
|
10
10
|
public value: YXmlElement;
|
|
11
11
|
|
|
12
|
-
constructor(
|
|
13
|
-
name: string,
|
|
14
|
-
children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[],
|
|
15
|
-
) {
|
|
12
|
+
constructor(name: string, children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]) {
|
|
16
13
|
super();
|
|
17
14
|
|
|
18
15
|
this.initialValue = children.map((item) => item.value);
|
|
@@ -31,10 +28,7 @@ export class CrdtYjsXmlElement extends AbstractCrdtType<YXmlElement, string> {
|
|
|
31
28
|
return this;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
|
-
public insert(
|
|
35
|
-
index: number,
|
|
36
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
37
|
-
): this {
|
|
31
|
+
public insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
38
32
|
const converted = children.map((child) => toYjsValue(child));
|
|
39
33
|
|
|
40
34
|
this.value.insert(index, converted);
|
|
@@ -42,15 +36,11 @@ export class CrdtYjsXmlElement extends AbstractCrdtType<YXmlElement, string> {
|
|
|
42
36
|
return this;
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
public push(
|
|
46
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
47
|
-
): this {
|
|
39
|
+
public push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
48
40
|
return this.insert(this.length, ...children);
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
public unshift(
|
|
52
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
53
|
-
): this {
|
|
43
|
+
public unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
54
44
|
return this.insert(0, ...children);
|
|
55
45
|
}
|
|
56
46
|
|
|
@@ -27,10 +27,7 @@ export class CrdtYjsXmlFragment extends AbstractCrdtType<YXmlFragment, string> {
|
|
|
27
27
|
return this;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public insert(
|
|
31
|
-
index: number,
|
|
32
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
33
|
-
): this {
|
|
30
|
+
public insert(index: number, ...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
34
31
|
const converted = children.map((child) => toYjsValue(child));
|
|
35
32
|
|
|
36
33
|
this.value.insert(index, converted);
|
|
@@ -38,15 +35,11 @@ export class CrdtYjsXmlFragment extends AbstractCrdtType<YXmlFragment, string> {
|
|
|
38
35
|
return this;
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
public push(
|
|
42
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
43
|
-
): this {
|
|
38
|
+
public push(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
44
39
|
return this.insert(this.length, ...children);
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
public unshift(
|
|
48
|
-
...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]
|
|
49
|
-
): this {
|
|
42
|
+
public unshift(...children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): this {
|
|
50
43
|
return this.insert(0, ...children);
|
|
51
44
|
}
|
|
52
45
|
|
|
@@ -2,8 +2,6 @@ import type { CrdtYjsXmlElement } from "../xmlElement";
|
|
|
2
2
|
import type { CrdtYjsXmlText } from "../xmlText";
|
|
3
3
|
import { CrdtYjsXmlFragment } from "./CrdtYjsXmlFragment";
|
|
4
4
|
|
|
5
|
-
export const xmlFragment = (
|
|
6
|
-
children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[],
|
|
7
|
-
): CrdtYjsXmlFragment => {
|
|
5
|
+
export const xmlFragment = (children: readonly (CrdtYjsXmlElement | CrdtYjsXmlText)[]): CrdtYjsXmlFragment => {
|
|
8
6
|
return new CrdtYjsXmlFragment(children);
|
|
9
7
|
};
|
|
@@ -22,11 +22,7 @@ export class CrdtYjsXmlText extends AbstractCrdtType<YXmlText, string> {
|
|
|
22
22
|
return this;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
public insert(
|
|
26
|
-
index: number,
|
|
27
|
-
text: string,
|
|
28
|
-
attributes?: Record<string, string>,
|
|
29
|
-
): this {
|
|
25
|
+
public insert(index: number, text: string, attributes?: Record<string, string>): this {
|
|
30
26
|
this.value.insert(index, text, attributes);
|
|
31
27
|
|
|
32
28
|
return this;
|