@pluv/crdt-yjs 0.17.3 → 0.18.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 +8 -0
- package/dist/index.d.mts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +18 -37
- package/dist/index.mjs +18 -37
- package/package.json +6 -6
- 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,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-yjs@0.
|
|
2
|
+
> @pluv/crdt-yjs@0.18.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
|
-
[32mCJS[39m [1mdist/index.js [22m[32m15.
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m14.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m15.34 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 193ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m14.63 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 194ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m8.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m8.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 2865ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m8.38 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m8.38 KB[39m
|
package/CHANGELOG.md
CHANGED
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 });
|
|
@@ -364,26 +355,20 @@ var CrdtYjsDoc = class extends import_crdt8.AbstractCrdtDoc {
|
|
|
364
355
|
return this;
|
|
365
356
|
}
|
|
366
357
|
batchApplyEncodedState(updates) {
|
|
367
|
-
const params = updates.reduce(
|
|
368
|
-
(
|
|
369
|
-
if (!update)
|
|
370
|
-
return acc;
|
|
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
|
-
}
|
|
358
|
+
const params = updates.reduce((acc, update) => {
|
|
359
|
+
if (!update)
|
|
379
360
|
return acc;
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
(
|
|
385
|
-
|
|
386
|
-
|
|
361
|
+
if (typeof update === "string") {
|
|
362
|
+
acc.push({ update });
|
|
363
|
+
return acc;
|
|
364
|
+
}
|
|
365
|
+
if (!!update && typeof update === "object") {
|
|
366
|
+
acc.push(update);
|
|
367
|
+
return acc;
|
|
368
|
+
}
|
|
369
|
+
return acc;
|
|
370
|
+
}, []);
|
|
371
|
+
return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
|
|
387
372
|
}
|
|
388
373
|
canRedo() {
|
|
389
374
|
var _a;
|
|
@@ -486,9 +471,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends import_crdt9.AbstractCr
|
|
|
486
471
|
return new CrdtYjsDoc();
|
|
487
472
|
}
|
|
488
473
|
getFactory(initialStorage) {
|
|
489
|
-
return new _CrdtYjsDocFactory(
|
|
490
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
491
|
-
);
|
|
474
|
+
return new _CrdtYjsDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
492
475
|
}
|
|
493
476
|
getFresh() {
|
|
494
477
|
const storage = this._initialStorage();
|
|
@@ -523,9 +506,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends import_crdt9.AbstractCr
|
|
|
523
506
|
}
|
|
524
507
|
getInitialized(initialStorage) {
|
|
525
508
|
var _a;
|
|
526
|
-
return new CrdtYjsDoc(
|
|
527
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
528
|
-
);
|
|
509
|
+
return new CrdtYjsDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
529
510
|
}
|
|
530
511
|
};
|
|
531
512
|
|
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 });
|
|
@@ -356,26 +347,20 @@ var CrdtYjsDoc = class extends AbstractCrdtDoc {
|
|
|
356
347
|
return this;
|
|
357
348
|
}
|
|
358
349
|
batchApplyEncodedState(updates) {
|
|
359
|
-
const params = updates.reduce(
|
|
360
|
-
(
|
|
361
|
-
if (!update)
|
|
362
|
-
return acc;
|
|
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
|
-
}
|
|
350
|
+
const params = updates.reduce((acc, update) => {
|
|
351
|
+
if (!update)
|
|
371
352
|
return acc;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
(
|
|
377
|
-
|
|
378
|
-
|
|
353
|
+
if (typeof update === "string") {
|
|
354
|
+
acc.push({ update });
|
|
355
|
+
return acc;
|
|
356
|
+
}
|
|
357
|
+
if (!!update && typeof update === "object") {
|
|
358
|
+
acc.push(update);
|
|
359
|
+
return acc;
|
|
360
|
+
}
|
|
361
|
+
return acc;
|
|
362
|
+
}, []);
|
|
363
|
+
return params.reduce((doc2, update) => doc2.applyEncodedState(update), this);
|
|
379
364
|
}
|
|
380
365
|
canRedo() {
|
|
381
366
|
var _a;
|
|
@@ -478,9 +463,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends AbstractCrdtDocFactory
|
|
|
478
463
|
return new CrdtYjsDoc();
|
|
479
464
|
}
|
|
480
465
|
getFactory(initialStorage) {
|
|
481
|
-
return new _CrdtYjsDocFactory(
|
|
482
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
483
|
-
);
|
|
466
|
+
return new _CrdtYjsDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
484
467
|
}
|
|
485
468
|
getFresh() {
|
|
486
469
|
const storage = this._initialStorage();
|
|
@@ -515,9 +498,7 @@ var CrdtYjsDocFactory = class _CrdtYjsDocFactory extends AbstractCrdtDocFactory
|
|
|
515
498
|
}
|
|
516
499
|
getInitialized(initialStorage) {
|
|
517
500
|
var _a;
|
|
518
|
-
return new CrdtYjsDoc(
|
|
519
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
520
|
-
);
|
|
501
|
+
return new CrdtYjsDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
521
502
|
}
|
|
522
503
|
};
|
|
523
504
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-yjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "yjs for @pluv/io",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"js-base64": "^3.7.7",
|
|
21
|
-
"@pluv/crdt": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/crdt": "^0.18.0",
|
|
22
|
+
"@pluv/types": "^0.18.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"yjs": "^13.0.0"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"tsup": "^8.0.2",
|
|
30
30
|
"typescript": "^5.4.5",
|
|
31
|
-
"yjs": "^13.6.
|
|
32
|
-
"@pluv/tsconfig": "^0.
|
|
33
|
-
"eslint-config-pluv": "^0.
|
|
31
|
+
"yjs": "^13.6.15",
|
|
32
|
+
"@pluv/tsconfig": "^0.18.0",
|
|
33
|
+
"eslint-config-pluv": "^0.18.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;
|