lib0 0.2.115-0 → 0.2.115-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/delta/d2.d.ts +103 -97
- package/delta/d2.d.ts.map +1 -1
- package/delta/d2.js +150 -96
- package/delta/d2.test.d.ts +1 -0
- package/delta/d2.test.d.ts.map +1 -1
- package/diff.d.ts +1 -1
- package/diff.d.ts.map +1 -1
- package/diff.js +1 -1
- package/dist/component.cjs +1 -1
- package/dist/d2.cjs +154 -97
- package/dist/d2.cjs.map +1 -1
- package/dist/delta/d2.d.ts +103 -97
- package/dist/delta/d2.d.ts.map +1 -1
- package/dist/delta/d2.test.d.ts +1 -0
- package/dist/delta/d2.test.d.ts.map +1 -1
- package/dist/{diff-f0776c15.cjs → diff-1832cb43.cjs} +2 -2
- package/dist/diff-1832cb43.cjs.map +1 -0
- package/dist/diff.cjs +1 -1
- package/dist/diff.d.ts +1 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/list.test.d.ts +1 -0
- package/dist/list.test.d.ts.map +1 -1
- package/dist/testing.cjs +1 -1
- package/isomorphic.js +0 -3
- package/list.test.d.ts +1 -0
- package/list.test.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/diff-f0776c15.cjs.map +0 -1
- package/dist/isomorphic.d.ts +0 -2
- package/dist/isomorphic.d.ts.map +0 -1
- package/isomorphic.d.ts +0 -2
- package/isomorphic.d.ts.map +0 -1
package/dist/d2.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var list = require('./list.cjs');
|
|
6
|
-
var map$1 = require('./map-24d263c0.cjs');
|
|
7
6
|
var object = require('./object-18980796.cjs');
|
|
8
7
|
var traits = require('./traits.cjs');
|
|
9
8
|
var array$1 = require('./array-78849c95.cjs');
|
|
@@ -13,6 +12,7 @@ var error = require('./error-0c1f634f.cjs');
|
|
|
13
12
|
var math = require('./math-96d5e8c4.cjs');
|
|
14
13
|
require('./set-5b47859e.cjs');
|
|
15
14
|
require('./environment-90227ead.cjs');
|
|
15
|
+
require('./map-24d263c0.cjs');
|
|
16
16
|
require('./string-fddc5f8b.cjs');
|
|
17
17
|
require('./conditions-f5c0c102.cjs');
|
|
18
18
|
require('./storage.cjs');
|
|
@@ -61,11 +61,11 @@ const $attribution = schema.$object({
|
|
|
61
61
|
*/
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* @typedef {{ insert: string|Array<any>, format?: { [key: string]: any }, attribution?: Attribution } | { delete: number } | { retain: number, format?: { [key:string]: any }, attribution?: Attribution } | { modify: object }} DeltaListOpJSON
|
|
64
|
+
* @typedef {{ type: 'insert', insert: string|Array<any>, format?: { [key: string]: any }, attribution?: Attribution } | { delete: number } | { type: 'retain', retain: number, format?: { [key:string]: any }, attribution?: Attribution } | { type: 'modify', value: object }} DeltaListOpJSON
|
|
65
65
|
*/
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify',
|
|
68
|
+
* @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify', value: DeltaJSON }} DeltaAttrOpJSON
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
71
|
/**
|
|
@@ -73,7 +73,7 @@ const $attribution = schema.$object({
|
|
|
73
73
|
*/
|
|
74
74
|
const $deltaMapChangeJson = schema.$union(
|
|
75
75
|
schema.$object({ type: schema.$literal('insert'), value: schema.$any, prevValue: schema.$any.optional, attribution: $attribution.optional }),
|
|
76
|
-
schema.$object({ type: schema.$literal('modify'),
|
|
76
|
+
schema.$object({ type: schema.$literal('modify'), value: schema.$any }),
|
|
77
77
|
schema.$object({ type: schema.$literal('delete'), prevValue: schema.$any.optional, attribution: $attribution.optional })
|
|
78
78
|
);
|
|
79
79
|
|
|
@@ -129,7 +129,7 @@ class TextOp extends list.ListNode {
|
|
|
129
129
|
*/
|
|
130
130
|
toJSON () {
|
|
131
131
|
const { insert, format, attribution } = this;
|
|
132
|
-
return object.assign({ insert }, format != null ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
132
|
+
return object.assign(/** @type {{type: 'insert', insert: string}} */ ({ type: 'insert', insert }), format != null ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
/**
|
|
@@ -189,7 +189,7 @@ class InsertOp extends list.ListNode {
|
|
|
189
189
|
*/
|
|
190
190
|
toJSON () {
|
|
191
191
|
const { insert, format, attribution } = this;
|
|
192
|
-
return object.assign({ insert: insert.map(ins => $deltaAny.check(ins) ? ins.toJSON() : ins) }, format ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
192
|
+
return object.assign({ type: /** @type {'insert'} */ ('insert'), insert: insert.map(ins => $deltaAny.check(ins) ? ins.toJSON() : ins) }, format ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
/**
|
|
@@ -295,7 +295,7 @@ class RetainOp extends list.ListNode {
|
|
|
295
295
|
*/
|
|
296
296
|
toJSON () {
|
|
297
297
|
const { retain, format, attribution } = this;
|
|
298
|
-
return object.assign({ retain }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
298
|
+
return object.assign({ type: /** @type {'retain'} */ ('retain'), retain }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/**
|
|
@@ -323,7 +323,7 @@ class ModifyOp extends list.ListNode {
|
|
|
323
323
|
*/
|
|
324
324
|
constructor (delta, format, attribution) {
|
|
325
325
|
super();
|
|
326
|
-
this.
|
|
326
|
+
this.value = delta;
|
|
327
327
|
this.format = format;
|
|
328
328
|
this.attribution = attribution;
|
|
329
329
|
}
|
|
@@ -352,28 +352,28 @@ class ModifyOp extends list.ListNode {
|
|
|
352
352
|
* @return {DeltaListOpJSON}
|
|
353
353
|
*/
|
|
354
354
|
toJSON () {
|
|
355
|
-
const {
|
|
356
|
-
return object.assign({ modify:
|
|
355
|
+
const { value, attribution, format } = this;
|
|
356
|
+
return object.assign({ type: /** @type {'modify'} */ ('modify'), value: value.toJSON() }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
/**
|
|
360
360
|
* @param {ModifyOp<any>} other
|
|
361
361
|
*/
|
|
362
362
|
[traits.EqualityTraitSymbol] (other) {
|
|
363
|
-
return this.
|
|
363
|
+
return this.value[traits.EqualityTraitSymbol](other.value) && _function.equalityDeep(this.format, other.format) && _function.equalityDeep(this.attribution, other.attribution)
|
|
364
364
|
}
|
|
365
365
|
|
|
366
366
|
/**
|
|
367
367
|
* @return {ModifyOp<DTypes>}
|
|
368
368
|
*/
|
|
369
369
|
clone () {
|
|
370
|
-
return new ModifyOp(this.
|
|
370
|
+
return new ModifyOp(this.value.clone(), _cloneAttrs(this.format), _cloneAttrs(this.attribution))
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
/**
|
|
375
375
|
* @template V
|
|
376
|
-
* @template [K=
|
|
376
|
+
* @template {string|number|symbol} [K=any]
|
|
377
377
|
*/
|
|
378
378
|
class MapInsertOp {
|
|
379
379
|
/**
|
|
@@ -480,7 +480,7 @@ class MapDeleteOp {
|
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
/**
|
|
483
|
-
* @template {
|
|
483
|
+
* @template {DeltaAny} Modifier
|
|
484
484
|
* @template [K=string]
|
|
485
485
|
*/
|
|
486
486
|
class MapModifyOp {
|
|
@@ -510,7 +510,7 @@ class MapModifyOp {
|
|
|
510
510
|
toJSON () {
|
|
511
511
|
return {
|
|
512
512
|
type: this.type,
|
|
513
|
-
|
|
513
|
+
value: this.value.toJSON()
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
|
|
@@ -567,14 +567,14 @@ const $retainOp = schema.$constructedBy(RetainOp);
|
|
|
567
567
|
const $modifyOp = schema.$custom(o => o != null && (o.constructor === MapModifyOp || o.constructor === ModifyOp));
|
|
568
568
|
|
|
569
569
|
/**
|
|
570
|
-
* @template {
|
|
570
|
+
* @template {DeltaAny} Modify
|
|
571
571
|
* @param {s.Schema<Modify>} $content
|
|
572
572
|
* @return {s.Schema<MapModifyOp<Modify> | ModifyOp<Modify>>}
|
|
573
573
|
*/
|
|
574
574
|
const $modifyOpWith = $content => schema.$custom(o =>
|
|
575
575
|
o != null && (
|
|
576
576
|
(o.constructor === MapModifyOp && $content.check(/** @type {MapModifyOp<Modify>} */ (o).value)) ||
|
|
577
|
-
(o.constructor === ModifyOp && $content.check(/** @type {ModifyOp<Modify>} */ (o).
|
|
577
|
+
(o.constructor === ModifyOp && $content.check(/** @type {ModifyOp<Modify>} */ (o).value))
|
|
578
578
|
)
|
|
579
579
|
);
|
|
580
580
|
|
|
@@ -611,11 +611,27 @@ const $anyOp = schema.$union($insertOp, $deleteOp, $textOp, $modifyOp);
|
|
|
611
611
|
* @typedef {_AnyToNull<Schema> extends null ? Delta<any,{[key:string|number|symbol]:any},any,string> : (Schema extends s.Schema<infer D> ? D : never)} AllowedDeltaFromSchema
|
|
612
612
|
*/
|
|
613
613
|
|
|
614
|
+
/**
|
|
615
|
+
* @typedef {Delta<any,{ [k:string]: any },any,any,any>} DeltaAny
|
|
616
|
+
*/
|
|
617
|
+
|
|
618
|
+
// note: simply copy the values from Delta.attrs as the parameter of the function
|
|
619
|
+
/**
|
|
620
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
621
|
+
* @param {Delta<any,Attrs,any,any,any>} d
|
|
622
|
+
* @param {(v:{ [K in keyof Attrs]: MapInsertOp<Attrs[K],K>|MapDeleteOp<Attrs[K],K>|(Delta extends Attrs[K] ? MapModifyOp<Extract<Attrs[K],Delta>,K> : never) }[keyof Attrs])=>any} handler
|
|
623
|
+
*/
|
|
624
|
+
const forEachAttr = (d, handler) => {
|
|
625
|
+
for (const k in d.attrs) {
|
|
626
|
+
handler(/** @type {any} */ (d.attrs[k]));
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
|
|
614
630
|
/**
|
|
615
631
|
* @template {string} [NodeName=any]
|
|
616
|
-
* @template {{[key:string|number|symbol]:any}} [
|
|
617
|
-
* @template {any} [
|
|
618
|
-
* @template {string|never} [
|
|
632
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
633
|
+
* @template {any} [Children=never]
|
|
634
|
+
* @template {string|never} [Text=never]
|
|
619
635
|
* @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
|
|
620
636
|
*/
|
|
621
637
|
class Delta {
|
|
@@ -627,27 +643,26 @@ class Delta {
|
|
|
627
643
|
this.name = name || null;
|
|
628
644
|
this.$schema = $schema || null;
|
|
629
645
|
/**
|
|
630
|
-
* @type {
|
|
646
|
+
* @type {{ [K in keyof Attrs]?: MapInsertOp<Attrs[K],K>|MapDeleteOp<Attrs[K],K>|(Delta extends Attrs[K] ? MapModifyOp<Extract<Attrs[K],Delta>,K> : never) } & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: MapInsertOp<Attrs[K],K>|MapDeleteOp<Attrs[K],K>|(Delta extends Attrs[K] ? MapModifyOp<Extract<Attrs[K],Delta>,K> : never) }[keyof Attrs]> }}
|
|
631
647
|
*/
|
|
632
|
-
this.attrs =
|
|
648
|
+
this.attrs = /** @type {any} */ ({
|
|
649
|
+
* [Symbol.iterator] () {
|
|
650
|
+
for (const k in this) {
|
|
651
|
+
yield this[k];
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
|
|
633
656
|
/**
|
|
634
657
|
* @type {list.List<
|
|
635
658
|
* RetainOp
|
|
636
659
|
* | DeleteOp
|
|
637
660
|
* | (Text extends never ? never : TextOp)
|
|
638
661
|
* | (Children extends never ? never : InsertOp<Children>)
|
|
639
|
-
* | (Delta extends Children ? ModifyOp<Extract<Children,Delta
|
|
662
|
+
* | (Delta extends Children ? ModifyOp<Extract<Children,Delta<any,any,any,any,any>>> : never)
|
|
640
663
|
* >}
|
|
641
664
|
*/
|
|
642
665
|
this.children = /** @type {any} */ (list.create());
|
|
643
|
-
/**
|
|
644
|
-
* @type {FormattingAttributes?}
|
|
645
|
-
*/
|
|
646
|
-
this.usedAttributes = null;
|
|
647
|
-
/**
|
|
648
|
-
* @type {Attribution?}
|
|
649
|
-
*/
|
|
650
|
-
this.usedAttribution = null;
|
|
651
666
|
/**
|
|
652
667
|
* @type {any}
|
|
653
668
|
*/
|
|
@@ -655,7 +670,7 @@ class Delta {
|
|
|
655
670
|
}
|
|
656
671
|
|
|
657
672
|
isEmpty () {
|
|
658
|
-
return this.attrs
|
|
673
|
+
return object.isEmpty(this.attrs) && list.isEmpty(this.children)
|
|
659
674
|
}
|
|
660
675
|
|
|
661
676
|
/**
|
|
@@ -670,7 +685,7 @@ class Delta {
|
|
|
670
685
|
* @type {any}
|
|
671
686
|
*/
|
|
672
687
|
const children = [];
|
|
673
|
-
this
|
|
688
|
+
forEachAttr(this, attr => {
|
|
674
689
|
attrs[attr.key] = attr.toJSON();
|
|
675
690
|
});
|
|
676
691
|
this.children.forEach(val => {
|
|
@@ -696,13 +711,13 @@ class Delta {
|
|
|
696
711
|
*/
|
|
697
712
|
clone () {
|
|
698
713
|
/**
|
|
699
|
-
* @type {Delta<any,
|
|
714
|
+
* @type {Delta<any,Attrs,any,any,any>}
|
|
700
715
|
*/
|
|
701
|
-
const d = new
|
|
716
|
+
const d = new DeltaBuilder(/** @type {any} */ (this.name), this.$schema);
|
|
702
717
|
d.origin = this.origin;
|
|
703
|
-
this.attrs
|
|
704
|
-
d.attrs
|
|
705
|
-
}
|
|
718
|
+
for (const op of this.attrs) {
|
|
719
|
+
d.attrs[op.key] = /** @type {any} */ (op);
|
|
720
|
+
}
|
|
706
721
|
this.children.forEach(op => {
|
|
707
722
|
list.pushEnd(d.children, op.clone());
|
|
708
723
|
});
|
|
@@ -716,6 +731,32 @@ class Delta {
|
|
|
716
731
|
[traits.EqualityTraitSymbol] (other) {
|
|
717
732
|
return this.name === other.name && _function.equalityDeep(this.attrs, other.attrs) && _function.equalityDeep(this.children, other.children)
|
|
718
733
|
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* @template {string} [NodeName=any]
|
|
738
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
739
|
+
* @template {any} [Children=never]
|
|
740
|
+
* @template {string|never} [Text=never]
|
|
741
|
+
* @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
|
|
742
|
+
* @extends {Delta<NodeName,Attrs,Children,Text,Schema>}
|
|
743
|
+
*/
|
|
744
|
+
class DeltaBuilder extends Delta {
|
|
745
|
+
/**
|
|
746
|
+
* @param {NodeName} [name]
|
|
747
|
+
* @param {Schema} [$schema]
|
|
748
|
+
*/
|
|
749
|
+
constructor (name, $schema) {
|
|
750
|
+
super(name, $schema);
|
|
751
|
+
/**
|
|
752
|
+
* @type {FormattingAttributes?}
|
|
753
|
+
*/
|
|
754
|
+
this.usedAttributes = null;
|
|
755
|
+
/**
|
|
756
|
+
* @type {Attribution?}
|
|
757
|
+
*/
|
|
758
|
+
this.usedAttribution = null;
|
|
759
|
+
}
|
|
719
760
|
|
|
720
761
|
/**
|
|
721
762
|
* @param {Attribution?} attribution
|
|
@@ -776,7 +817,7 @@ class Delta {
|
|
|
776
817
|
* @param {NewContent} insert
|
|
777
818
|
* @param {FormattingAttributes?} [formatting]
|
|
778
819
|
* @param {Attribution?} [attribution]
|
|
779
|
-
* @return {
|
|
820
|
+
* @return {DeltaBuilder<
|
|
780
821
|
* NodeName,
|
|
781
822
|
* Attrs,
|
|
782
823
|
* Exclude<NewContent,string>[number]|Children,
|
|
@@ -813,7 +854,7 @@ class Delta {
|
|
|
813
854
|
* @param {NewContent} modify
|
|
814
855
|
* @param {FormattingAttributes?} formatting
|
|
815
856
|
* @param {Attribution?} attribution
|
|
816
|
-
* @return {
|
|
857
|
+
* @return {DeltaBuilder<
|
|
817
858
|
* NodeName,
|
|
818
859
|
* Attrs,
|
|
819
860
|
* Exclude<NewContent,string>[number]|Children,
|
|
@@ -847,7 +888,6 @@ class Delta {
|
|
|
847
888
|
|
|
848
889
|
/**
|
|
849
890
|
* @param {number} len
|
|
850
|
-
* @return {this}
|
|
851
891
|
*/
|
|
852
892
|
delete (len) {
|
|
853
893
|
const lastOp = /** @type {DeleteOp|InsertOp<any>} */ (this.children.end);
|
|
@@ -866,7 +906,7 @@ class Delta {
|
|
|
866
906
|
* @param {Val} val
|
|
867
907
|
* @param {Attribution?} attribution
|
|
868
908
|
* @param {Val|undefined} [prevValue]
|
|
869
|
-
* @return {
|
|
909
|
+
* @return {DeltaBuilder<
|
|
870
910
|
* NodeName,
|
|
871
911
|
* { [K in keyof AddToAttrs<Attrs,Key,Val>]: AddToAttrs<Attrs,Key,Val>[K] },
|
|
872
912
|
* Children,
|
|
@@ -875,7 +915,7 @@ class Delta {
|
|
|
875
915
|
* >}
|
|
876
916
|
*/
|
|
877
917
|
set (key, val, attribution = null, prevValue) {
|
|
878
|
-
this.attrs
|
|
918
|
+
this.attrs[key] = /** @type {any} */ (new MapInsertOp(key, val, prevValue, mergeAttrs(this.usedAttribution, attribution)));
|
|
879
919
|
return /** @type {any} */ (this)
|
|
880
920
|
}
|
|
881
921
|
|
|
@@ -883,7 +923,7 @@ class Delta {
|
|
|
883
923
|
* @template {AllowedDeltaFromSchema<Schema> extends Delta<any,infer Attrs,any,any,any> ? Attrs : never} NewAttrs
|
|
884
924
|
* @param {NewAttrs} attrs
|
|
885
925
|
* @param {Attribution?} attribution
|
|
886
|
-
* @return {
|
|
926
|
+
* @return {DeltaBuilder<
|
|
887
927
|
* NodeName,
|
|
888
928
|
* { [K in keyof MergeAttrs<Attrs,NewAttrs>]: MergeAttrs<Attrs,NewAttrs>[K] },
|
|
889
929
|
* Children,
|
|
@@ -903,7 +943,7 @@ class Delta {
|
|
|
903
943
|
* @param {Key} key
|
|
904
944
|
* @param {Attribution?} attribution
|
|
905
945
|
* @param {any} [prevValue]
|
|
906
|
-
* @return {
|
|
946
|
+
* @return {DeltaBuilder<
|
|
907
947
|
* NodeName,
|
|
908
948
|
* { [K in keyof AddToAttrs<Attrs,Key,never>]: AddToAttrs<Attrs,Key,never>[K] },
|
|
909
949
|
* Children,
|
|
@@ -912,8 +952,8 @@ class Delta {
|
|
|
912
952
|
* >}
|
|
913
953
|
*/
|
|
914
954
|
unset (key, attribution = null, prevValue) {
|
|
915
|
-
this.attrs
|
|
916
|
-
return this
|
|
955
|
+
this.attrs[key] = /** @type {any} */ (new MapDeleteOp(key, prevValue, mergeAttrs(this.usedAttribution, attribution)));
|
|
956
|
+
return /** @type {any} */ (this)
|
|
917
957
|
}
|
|
918
958
|
|
|
919
959
|
/**
|
|
@@ -921,7 +961,7 @@ class Delta {
|
|
|
921
961
|
* @template {AllowedDeltaFromSchema<Schema> extends Delta<any,infer As,any,any,any> ? Extract<As[Key],Delta<any,any,any,any,any>> : never} D
|
|
922
962
|
* @param {Key} key
|
|
923
963
|
* @param {D} modify
|
|
924
|
-
* @return {
|
|
964
|
+
* @return {DeltaBuilder<
|
|
925
965
|
* NodeName,
|
|
926
966
|
* { [K in keyof AddToAttrs<Attrs,Key,D>]: AddToAttrs<Attrs,Key,D>[K] },
|
|
927
967
|
* Children,
|
|
@@ -930,29 +970,27 @@ class Delta {
|
|
|
930
970
|
* >}
|
|
931
971
|
*/
|
|
932
972
|
update (key, modify) {
|
|
933
|
-
this.attrs
|
|
973
|
+
this.attrs[key] = /** @type {any} */ (new MapModifyOp(key, modify));
|
|
934
974
|
return /** @type {any} */ (this)
|
|
935
975
|
}
|
|
936
976
|
|
|
937
977
|
/**
|
|
938
|
-
* @param {Delta<NodeName,
|
|
939
|
-
* @return {this}
|
|
978
|
+
* @param {Delta<NodeName,Attrs,Children,Text,any>} other
|
|
940
979
|
*/
|
|
941
980
|
apply (other) {
|
|
942
|
-
this.$schema?.expect(other)
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
const c = this.attrs.get(op.key);
|
|
981
|
+
this.$schema?.expect(other);
|
|
982
|
+
forEachAttr(/** @type {Delta<NodeName,Attrs,Children,Text,any>} */ (/** @type {any} */ (other)), op => {
|
|
983
|
+
const c = this.attrs[op.key];
|
|
946
984
|
if ($modifyOp.check(op)) {
|
|
947
985
|
if ($deltaAny.check(c?.value)) {
|
|
948
|
-
/** @type {
|
|
986
|
+
/** @type {DeltaBuilder} */ (c.value).apply(op.value);
|
|
949
987
|
} else {
|
|
950
988
|
// then this is a simple modify
|
|
951
|
-
this.attrs
|
|
989
|
+
this.attrs[op.key] = /** @type {any} */ (op);
|
|
952
990
|
}
|
|
953
991
|
} else {
|
|
954
992
|
/** @type {MapInsertOp<any>} */ (op).prevValue = c?.value;
|
|
955
|
-
this.attrs
|
|
993
|
+
this.attrs[op.key] = /** @type {any} */ (op);
|
|
956
994
|
}
|
|
957
995
|
});
|
|
958
996
|
// apply children
|
|
@@ -1031,14 +1069,14 @@ class Delta {
|
|
|
1031
1069
|
return
|
|
1032
1070
|
}
|
|
1033
1071
|
if ($modifyOp.check(opsI)) {
|
|
1034
|
-
opsI.
|
|
1072
|
+
/** @type {any} */ (opsI.value).apply(op.value);
|
|
1035
1073
|
} else if ($textOp.check(opsI) || $insertOp.check(opsI)) {
|
|
1036
1074
|
const d = opsI.insert[offset];
|
|
1037
1075
|
if (!$deltaAny.check(d)) {
|
|
1038
1076
|
// probably incompatible delta. can only modify deltas
|
|
1039
1077
|
error.unexpectedCase();
|
|
1040
1078
|
}
|
|
1041
|
-
d.apply(op.
|
|
1079
|
+
/** @type {any} */ (d).apply(op.value);
|
|
1042
1080
|
} else if ($retainOp.check(opsI)) {
|
|
1043
1081
|
if (offset > 0) {
|
|
1044
1082
|
const cpy = opsI.clone();
|
|
@@ -1081,28 +1119,31 @@ class Delta {
|
|
|
1081
1119
|
* - delete vs delete ⇒ current delete op is removed because item has already been deleted
|
|
1082
1120
|
* - modify vs modify ⇒ rebase using priority
|
|
1083
1121
|
*/
|
|
1084
|
-
this
|
|
1122
|
+
forEachAttr(this, op => {
|
|
1085
1123
|
if ($insertOp.check(op)) {
|
|
1086
|
-
if ($insertOp.check(other.attrs
|
|
1087
|
-
this.attrs
|
|
1124
|
+
if ($insertOp.check(other.attrs[op.key]) && !priority) {
|
|
1125
|
+
delete this.attrs[op.key];
|
|
1088
1126
|
}
|
|
1089
1127
|
} else if ($deleteOp.check(op)) {
|
|
1090
|
-
const otherOp = other.attrs
|
|
1128
|
+
const otherOp = other.attrs[/** @type {any} */ (op.key)];
|
|
1091
1129
|
if ($insertOp.check(otherOp)) {
|
|
1092
|
-
this.attrs
|
|
1130
|
+
delete this.attrs[otherOp.key];
|
|
1093
1131
|
}
|
|
1094
1132
|
} else if ($modifyOp.check(op)) {
|
|
1095
|
-
const otherOp = other.attrs
|
|
1133
|
+
const otherOp = other.attrs[/** @type {any} */ (op.key)];
|
|
1096
1134
|
if (otherOp == null) ; else if ($modifyOp.check(otherOp)) {
|
|
1097
1135
|
op.value.rebase(otherOp.value, priority);
|
|
1098
1136
|
} else {
|
|
1099
|
-
this.attrs
|
|
1137
|
+
delete this.attrs[otherOp.key];
|
|
1100
1138
|
}
|
|
1101
1139
|
}
|
|
1102
1140
|
});
|
|
1103
1141
|
return this
|
|
1104
1142
|
}
|
|
1105
1143
|
|
|
1144
|
+
/**
|
|
1145
|
+
* @return {Delta<NodeName,Attrs,Children,Text,Schema>}
|
|
1146
|
+
*/
|
|
1106
1147
|
done () {
|
|
1107
1148
|
const cs = this.children;
|
|
1108
1149
|
for (let end = cs.end; end !== null && $retainOp.check(end) && end.format == null; end = cs.end) {
|
|
@@ -1117,7 +1158,7 @@ class Delta {
|
|
|
1117
1158
|
* @template {{ [key: string|number|symbol]: any }} [Attrs={}]
|
|
1118
1159
|
* @template {any} [Children=never]
|
|
1119
1160
|
* @template {string|never} [Text=never]
|
|
1120
|
-
* @typedef {Delta<NodeName,Attrs,Children|RecursiveDelta<NodeName,Attrs,Children>,Text>} RecursiveDelta
|
|
1161
|
+
* @typedef {Delta<NodeName,Attrs,Children|Delta<NodeName,Attrs,Children,Text>|RecursiveDelta<NodeName,Attrs,Children,Text>,Text>} RecursiveDelta
|
|
1121
1162
|
*/
|
|
1122
1163
|
|
|
1123
1164
|
/**
|
|
@@ -1149,8 +1190,8 @@ const $delta = ({ name, attrs, children, hasText, recursive }) => {
|
|
|
1149
1190
|
const $d = schema.$instanceOf(Delta, /** @param {Delta<any,any,any,any,any>} d */ d => {
|
|
1150
1191
|
if (
|
|
1151
1192
|
!name.check(d.name) ||
|
|
1152
|
-
|
|
1153
|
-
(
|
|
1193
|
+
object.some(d.attrs,
|
|
1194
|
+
(op, k) => $insertOp.check(op) && !$attrsPartial.check({ [k]: op.value })
|
|
1154
1195
|
)
|
|
1155
1196
|
) return false
|
|
1156
1197
|
for (const op of d.children) {
|
|
@@ -1166,7 +1207,10 @@ const $delta = ({ name, attrs, children, hasText, recursive }) => {
|
|
|
1166
1207
|
return /** @type {any} */ ($d)
|
|
1167
1208
|
};
|
|
1168
1209
|
|
|
1169
|
-
|
|
1210
|
+
/**
|
|
1211
|
+
* @type {s.Schema<DeltaAny>}
|
|
1212
|
+
*/
|
|
1213
|
+
const $deltaAny = /** @type {any} */ (schema.$instanceOf(Delta));
|
|
1170
1214
|
|
|
1171
1215
|
/**
|
|
1172
1216
|
* Helper function to merge attribution and attributes. The latter input "wins".
|
|
@@ -1178,7 +1222,7 @@ const $deltaAny = schema.$instanceOf(Delta);
|
|
|
1178
1222
|
const mergeAttrs = (a, b) => object.isEmpty(a) ? b : (object.isEmpty(b) ? a : object.assign({}, a, b));
|
|
1179
1223
|
|
|
1180
1224
|
/**
|
|
1181
|
-
* @template {
|
|
1225
|
+
* @template {DeltaBuilder?} D
|
|
1182
1226
|
* @param {D} a
|
|
1183
1227
|
* @param {D} b
|
|
1184
1228
|
* @return {D}
|
|
@@ -1194,62 +1238,58 @@ const mergeDeltas = (a, b) => {
|
|
|
1194
1238
|
|
|
1195
1239
|
/**
|
|
1196
1240
|
* @overload
|
|
1197
|
-
* @return {
|
|
1241
|
+
* @return {DeltaBuilder<any,{},never,never,null>}
|
|
1198
1242
|
*/
|
|
1199
1243
|
/**
|
|
1200
1244
|
* @template {string} NodeName
|
|
1201
1245
|
* @overload
|
|
1202
1246
|
* @param {NodeName} nodeName
|
|
1203
|
-
* @return {
|
|
1247
|
+
* @return {DeltaBuilder<NodeName,{},never,never,null>}
|
|
1204
1248
|
*/
|
|
1205
1249
|
/**
|
|
1206
1250
|
* @template {string} NodeName
|
|
1207
|
-
* @template {s.Schema<
|
|
1251
|
+
* @template {s.Schema<DeltaAny>} Schema
|
|
1208
1252
|
* @overload
|
|
1209
1253
|
* @param {NodeName} nodeName
|
|
1210
1254
|
* @param {Schema} schema
|
|
1211
|
-
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ?
|
|
1255
|
+
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ? DeltaBuilder<NodeName,Attrs,Children,Text,Schema> : never}
|
|
1212
1256
|
*/
|
|
1213
1257
|
/**
|
|
1214
|
-
* @template {s.Schema<
|
|
1258
|
+
* @template {s.Schema<DeltaAny>} Schema
|
|
1215
1259
|
* @overload
|
|
1216
1260
|
* @param {Schema} schema
|
|
1217
|
-
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ?
|
|
1261
|
+
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ? DeltaBuilder<N,Attrs,Children,Text,Schema> : never}
|
|
1218
1262
|
*/
|
|
1219
1263
|
/**
|
|
1220
1264
|
* @template {string|null} NodeName
|
|
1221
1265
|
* @template {{[k:string|number|symbol]:any}|null} Attrs
|
|
1222
|
-
* @template {Array<
|
|
1266
|
+
* @template {Array<any>|string} Children
|
|
1223
1267
|
* @overload
|
|
1224
1268
|
* @param {NodeName} nodeName
|
|
1225
1269
|
* @param {Attrs} attrs
|
|
1226
|
-
* @param {
|
|
1227
|
-
* @return {
|
|
1270
|
+
* @param {Children} [children]
|
|
1271
|
+
* @return {DeltaBuilder<
|
|
1228
1272
|
* NodeName extends null ? any : NodeName,
|
|
1229
1273
|
* Attrs extends null ? {} : Attrs,
|
|
1230
|
-
* Extract<Children
|
|
1231
|
-
* Extract<Children
|
|
1274
|
+
* Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
1275
|
+
* Extract<Children,string>,
|
|
1232
1276
|
* null
|
|
1233
1277
|
* >}
|
|
1234
1278
|
*/
|
|
1235
1279
|
/**
|
|
1236
|
-
* @param {string|s.Schema<
|
|
1237
|
-
* @param {{[K:string|number|symbol]:any}|s.Schema<
|
|
1238
|
-
* @param {Array<
|
|
1239
|
-
* @return {
|
|
1280
|
+
* @param {string|s.Schema<DeltaAny>} [nodeNameOrSchema]
|
|
1281
|
+
* @param {{[K:string|number|symbol]:any}|s.Schema<DeltaAny>} [attrsOrSchema]
|
|
1282
|
+
* @param {(Array<any>|string)} [children]
|
|
1283
|
+
* @return {DeltaBuilder<any,any,any,any,any>}
|
|
1240
1284
|
*/
|
|
1241
|
-
const create = (nodeNameOrSchema, attrsOrSchema,
|
|
1285
|
+
const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
1242
1286
|
const nodeName = /** @type {any} */ (schema.$string.check(nodeNameOrSchema) ? nodeNameOrSchema : null);
|
|
1243
1287
|
const schema$1 = /** @type {any} */ (schema.$$schema.check(nodeNameOrSchema) ? nodeNameOrSchema : (schema.$$schema.check(attrsOrSchema) ? attrsOrSchema : null));
|
|
1244
|
-
const d = /** @type {
|
|
1288
|
+
const d = /** @type {DeltaBuilder<any,any,any,string,null>} */ (new DeltaBuilder(nodeName, schema$1));
|
|
1245
1289
|
if (schema.$objectAny.check(attrsOrSchema)) {
|
|
1246
1290
|
d.setMany(attrsOrSchema);
|
|
1247
1291
|
}
|
|
1248
|
-
|
|
1249
|
-
children.forEach(v => {
|
|
1250
|
-
d.insert(v);
|
|
1251
|
-
});
|
|
1252
|
-
}
|
|
1292
|
+
children && d.insert(children);
|
|
1253
1293
|
return d
|
|
1254
1294
|
};
|
|
1255
1295
|
|
|
@@ -1260,6 +1300,11 @@ const create = (nodeNameOrSchema, attrsOrSchema, ...children) => {
|
|
|
1260
1300
|
* @typedef {Delta<any,{},Embeds,string>} TextDelta
|
|
1261
1301
|
*/
|
|
1262
1302
|
|
|
1303
|
+
/**
|
|
1304
|
+
* @template [Embeds=never]
|
|
1305
|
+
* @typedef {DeltaBuilder<any,{},Embeds,string>} TextDeltaBuilder
|
|
1306
|
+
*/
|
|
1307
|
+
|
|
1263
1308
|
/**
|
|
1264
1309
|
* @template {Array<s.Schema<any>>} [$Embeds=any]
|
|
1265
1310
|
* @param {$Embeds} $embeds
|
|
@@ -1271,7 +1316,7 @@ const $textOnly = $text();
|
|
|
1271
1316
|
/**
|
|
1272
1317
|
* @template {s.Schema<Delta<any,{},any,any,null>>} [Schema=s.Schema<Delta<any,{},never,string,null>>]
|
|
1273
1318
|
* @param {Schema} [$schema]
|
|
1274
|
-
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ?
|
|
1319
|
+
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ? DeltaBuilder<N,Attrs,Children,Text,Schema> : never}
|
|
1275
1320
|
*/
|
|
1276
1321
|
const text = $schema => /** @type {any} */ (create($schema || $textOnly));
|
|
1277
1322
|
|
|
@@ -1280,6 +1325,11 @@ const text = $schema => /** @type {any} */ (create($schema || $textOnly));
|
|
|
1280
1325
|
* @typedef {Delta<any,{},Children,never>} ArrayDelta
|
|
1281
1326
|
*/
|
|
1282
1327
|
|
|
1328
|
+
/**
|
|
1329
|
+
* @template {any} Children
|
|
1330
|
+
* @typedef {DeltaBuilder<any,{},Children,never>} ArrayDeltaBuilder
|
|
1331
|
+
*/
|
|
1332
|
+
|
|
1283
1333
|
/**
|
|
1284
1334
|
* @template {s.Schema<any>} $Children
|
|
1285
1335
|
* @param {$Children} [$children]
|
|
@@ -1290,7 +1340,7 @@ const $array = $children => $delta({ children: $children });
|
|
|
1290
1340
|
/**
|
|
1291
1341
|
* @template {s.Schema<ArrayDelta<any>>} [$Schema=never]
|
|
1292
1342
|
* @param {$Schema} $schema
|
|
1293
|
-
* @return {$Schema extends never ?
|
|
1343
|
+
* @return {$Schema extends never ? ArrayDeltaBuilder<never> : DeltaBuilder<any,{},never,never,$Schema>}
|
|
1294
1344
|
*/
|
|
1295
1345
|
const array = $schema => /** @type {any} */ ($schema ? create($schema) : create());
|
|
1296
1346
|
|
|
@@ -1299,6 +1349,11 @@ const array = $schema => /** @type {any} */ ($schema ? create($schema) : create(
|
|
|
1299
1349
|
* @typedef {Delta<any,Attrs,never,never>} MapDelta
|
|
1300
1350
|
*/
|
|
1301
1351
|
|
|
1352
|
+
/**
|
|
1353
|
+
* @template {{ [K: string|number|symbol]: any }} Attrs
|
|
1354
|
+
* @typedef {DeltaBuilder<any,Attrs,never,never>} MapDeltaBuilder
|
|
1355
|
+
*/
|
|
1356
|
+
|
|
1302
1357
|
/**
|
|
1303
1358
|
* @template {{ [K: string|number|symbol]: any }} $Attrs
|
|
1304
1359
|
* @param {s.Schema<$Attrs>} $attrs
|
|
@@ -1309,7 +1364,7 @@ const $map = $attrs => /** @type {any} */ ($delta({ attrs: $attrs }));
|
|
|
1309
1364
|
/**
|
|
1310
1365
|
* @template {s.Schema<MapDelta<any>>|undefined} [$Schema=undefined]
|
|
1311
1366
|
* @param {$Schema} [$schema]
|
|
1312
|
-
* @return {$Schema extends s.Schema<MapDelta<infer Attrs>> ?
|
|
1367
|
+
* @return {$Schema extends s.Schema<MapDelta<infer Attrs>> ? DeltaBuilder<any,Attrs,never,never,$Schema> : MapDeltaBuilder<{}>}
|
|
1313
1368
|
*/
|
|
1314
1369
|
const map = $schema => /** @type {any} */ (create(/** @type {any} */ ($schema)));
|
|
1315
1370
|
|
|
@@ -1331,6 +1386,7 @@ exports.$textOnly = $textOnly;
|
|
|
1331
1386
|
exports.$textOp = $textOp;
|
|
1332
1387
|
exports.DeleteOp = DeleteOp;
|
|
1333
1388
|
exports.Delta = Delta;
|
|
1389
|
+
exports.DeltaBuilder = DeltaBuilder;
|
|
1334
1390
|
exports.InsertOp = InsertOp;
|
|
1335
1391
|
exports.MapDeleteOp = MapDeleteOp;
|
|
1336
1392
|
exports.MapInsertOp = MapInsertOp;
|
|
@@ -1340,6 +1396,7 @@ exports.RetainOp = RetainOp;
|
|
|
1340
1396
|
exports.TextOp = TextOp;
|
|
1341
1397
|
exports.array = array;
|
|
1342
1398
|
exports.create = create;
|
|
1399
|
+
exports.forEachAttr = forEachAttr;
|
|
1343
1400
|
exports.map = map;
|
|
1344
1401
|
exports.mergeAttrs = mergeAttrs;
|
|
1345
1402
|
exports.mergeDeltas = mergeDeltas;
|