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/delta/d2.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as list from '../list.js'
|
|
6
|
-
import * as map_ from '../map.js'
|
|
7
6
|
import * as object from '../object.js'
|
|
8
7
|
import * as traits from '../traits.js'
|
|
9
8
|
import * as arr from '../array.js'
|
|
@@ -52,11 +51,11 @@ export const $attribution = s.$object({
|
|
|
52
51
|
*/
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
|
-
* @typedef {{ insert: string|Array<any>, format?: { [key: string]: any }, attribution?: Attribution } | { delete: number } | { retain: number, format?: { [key:string]: any }, attribution?: Attribution } | { modify: object }} DeltaListOpJSON
|
|
54
|
+
* @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
|
|
56
55
|
*/
|
|
57
56
|
|
|
58
57
|
/**
|
|
59
|
-
* @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify',
|
|
58
|
+
* @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify', value: DeltaJSON }} DeltaAttrOpJSON
|
|
60
59
|
*/
|
|
61
60
|
|
|
62
61
|
/**
|
|
@@ -64,7 +63,7 @@ export const $attribution = s.$object({
|
|
|
64
63
|
*/
|
|
65
64
|
export const $deltaMapChangeJson = s.$union(
|
|
66
65
|
s.$object({ type: s.$literal('insert'), value: s.$any, prevValue: s.$any.optional, attribution: $attribution.optional }),
|
|
67
|
-
s.$object({ type: s.$literal('modify'),
|
|
66
|
+
s.$object({ type: s.$literal('modify'), value: s.$any }),
|
|
68
67
|
s.$object({ type: s.$literal('delete'), prevValue: s.$any.optional, attribution: $attribution.optional })
|
|
69
68
|
)
|
|
70
69
|
|
|
@@ -120,7 +119,7 @@ export class TextOp extends list.ListNode {
|
|
|
120
119
|
*/
|
|
121
120
|
toJSON () {
|
|
122
121
|
const { insert, format, attribution } = this
|
|
123
|
-
return object.assign({ insert }, format != null ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
122
|
+
return object.assign(/** @type {{type: 'insert', insert: string}} */ ({ type: 'insert', insert }), format != null ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
/**
|
|
@@ -180,7 +179,7 @@ export class InsertOp extends list.ListNode {
|
|
|
180
179
|
*/
|
|
181
180
|
toJSON () {
|
|
182
181
|
const { insert, format, attribution } = this
|
|
183
|
-
return object.assign({ insert: insert.map(ins => $deltaAny.check(ins) ? ins.toJSON() : ins) }, format ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
182
|
+
return object.assign({ type: /** @type {'insert'} */ ('insert'), insert: insert.map(ins => $deltaAny.check(ins) ? ins.toJSON() : ins) }, format ? { format } : ({}), attribution != null ? { attribution } : ({}))
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
/**
|
|
@@ -286,7 +285,7 @@ export class RetainOp extends list.ListNode {
|
|
|
286
285
|
*/
|
|
287
286
|
toJSON () {
|
|
288
287
|
const { retain, format, attribution } = this
|
|
289
|
-
return object.assign({ retain }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
288
|
+
return object.assign({ type: /** @type {'retain'} */ ('retain'), retain }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
290
289
|
}
|
|
291
290
|
|
|
292
291
|
/**
|
|
@@ -314,7 +313,7 @@ export class ModifyOp extends list.ListNode {
|
|
|
314
313
|
*/
|
|
315
314
|
constructor (delta, format, attribution) {
|
|
316
315
|
super()
|
|
317
|
-
this.
|
|
316
|
+
this.value = delta
|
|
318
317
|
this.format = format
|
|
319
318
|
this.attribution = attribution
|
|
320
319
|
}
|
|
@@ -343,28 +342,28 @@ export class ModifyOp extends list.ListNode {
|
|
|
343
342
|
* @return {DeltaListOpJSON}
|
|
344
343
|
*/
|
|
345
344
|
toJSON () {
|
|
346
|
-
const {
|
|
347
|
-
return object.assign({ modify:
|
|
345
|
+
const { value, attribution, format } = this
|
|
346
|
+
return object.assign({ type: /** @type {'modify'} */ ('modify'), value: value.toJSON() }, format ? { format } : {}, attribution != null ? { attribution } : {})
|
|
348
347
|
}
|
|
349
348
|
|
|
350
349
|
/**
|
|
351
350
|
* @param {ModifyOp<any>} other
|
|
352
351
|
*/
|
|
353
352
|
[traits.EqualityTraitSymbol] (other) {
|
|
354
|
-
return this.
|
|
353
|
+
return this.value[traits.EqualityTraitSymbol](other.value) && fun.equalityDeep(this.format, other.format) && fun.equalityDeep(this.attribution, other.attribution)
|
|
355
354
|
}
|
|
356
355
|
|
|
357
356
|
/**
|
|
358
357
|
* @return {ModifyOp<DTypes>}
|
|
359
358
|
*/
|
|
360
359
|
clone () {
|
|
361
|
-
return new ModifyOp(this.
|
|
360
|
+
return new ModifyOp(this.value.clone(), _cloneAttrs(this.format), _cloneAttrs(this.attribution))
|
|
362
361
|
}
|
|
363
362
|
}
|
|
364
363
|
|
|
365
364
|
/**
|
|
366
365
|
* @template V
|
|
367
|
-
* @template [K=
|
|
366
|
+
* @template {string|number|symbol} [K=any]
|
|
368
367
|
*/
|
|
369
368
|
export class MapInsertOp {
|
|
370
369
|
/**
|
|
@@ -471,7 +470,7 @@ export class MapDeleteOp {
|
|
|
471
470
|
}
|
|
472
471
|
|
|
473
472
|
/**
|
|
474
|
-
* @template {
|
|
473
|
+
* @template {DeltaAny} Modifier
|
|
475
474
|
* @template [K=string]
|
|
476
475
|
*/
|
|
477
476
|
export class MapModifyOp {
|
|
@@ -501,7 +500,7 @@ export class MapModifyOp {
|
|
|
501
500
|
toJSON () {
|
|
502
501
|
return {
|
|
503
502
|
type: this.type,
|
|
504
|
-
|
|
503
|
+
value: this.value.toJSON()
|
|
505
504
|
}
|
|
506
505
|
}
|
|
507
506
|
|
|
@@ -558,14 +557,14 @@ export const $retainOp = s.$constructedBy(RetainOp)
|
|
|
558
557
|
export const $modifyOp = s.$custom(o => o != null && (o.constructor === MapModifyOp || o.constructor === ModifyOp))
|
|
559
558
|
|
|
560
559
|
/**
|
|
561
|
-
* @template {
|
|
560
|
+
* @template {DeltaAny} Modify
|
|
562
561
|
* @param {s.Schema<Modify>} $content
|
|
563
562
|
* @return {s.Schema<MapModifyOp<Modify> | ModifyOp<Modify>>}
|
|
564
563
|
*/
|
|
565
564
|
export const $modifyOpWith = $content => s.$custom(o =>
|
|
566
565
|
o != null && (
|
|
567
566
|
(o.constructor === MapModifyOp && $content.check(/** @type {MapModifyOp<Modify>} */ (o).value)) ||
|
|
568
|
-
(o.constructor === ModifyOp && $content.check(/** @type {ModifyOp<Modify>} */ (o).
|
|
567
|
+
(o.constructor === ModifyOp && $content.check(/** @type {ModifyOp<Modify>} */ (o).value))
|
|
569
568
|
)
|
|
570
569
|
)
|
|
571
570
|
|
|
@@ -602,11 +601,27 @@ export const $anyOp = s.$union($insertOp, $deleteOp, $textOp, $modifyOp)
|
|
|
602
601
|
* @typedef {_AnyToNull<Schema> extends null ? Delta<any,{[key:string|number|symbol]:any},any,string> : (Schema extends s.Schema<infer D> ? D : never)} AllowedDeltaFromSchema
|
|
603
602
|
*/
|
|
604
603
|
|
|
604
|
+
/**
|
|
605
|
+
* @typedef {Delta<any,{ [k:string]: any },any,any,any>} DeltaAny
|
|
606
|
+
*/
|
|
607
|
+
|
|
608
|
+
// note: simply copy the values from Delta.attrs as the parameter of the function
|
|
609
|
+
/**
|
|
610
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
611
|
+
* @param {Delta<any,Attrs,any,any,any>} d
|
|
612
|
+
* @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
|
|
613
|
+
*/
|
|
614
|
+
export const forEachAttr = (d, handler) => {
|
|
615
|
+
for (const k in d.attrs) {
|
|
616
|
+
handler(/** @type {any} */ (d.attrs[k]))
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
605
620
|
/**
|
|
606
621
|
* @template {string} [NodeName=any]
|
|
607
|
-
* @template {{[key:string|number|symbol]:any}} [
|
|
608
|
-
* @template {any} [
|
|
609
|
-
* @template {string|never} [
|
|
622
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
623
|
+
* @template {any} [Children=never]
|
|
624
|
+
* @template {string|never} [Text=never]
|
|
610
625
|
* @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
|
|
611
626
|
*/
|
|
612
627
|
export class Delta {
|
|
@@ -618,27 +633,26 @@ export class Delta {
|
|
|
618
633
|
this.name = name || null
|
|
619
634
|
this.$schema = $schema || null
|
|
620
635
|
/**
|
|
621
|
-
* @type {
|
|
636
|
+
* @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]> }}
|
|
622
637
|
*/
|
|
623
|
-
this.attrs =
|
|
638
|
+
this.attrs = /** @type {any} */ ({
|
|
639
|
+
* [Symbol.iterator] () {
|
|
640
|
+
for (const k in this) {
|
|
641
|
+
yield this[k]
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
})
|
|
645
|
+
|
|
624
646
|
/**
|
|
625
647
|
* @type {list.List<
|
|
626
648
|
* RetainOp
|
|
627
649
|
* | DeleteOp
|
|
628
650
|
* | (Text extends never ? never : TextOp)
|
|
629
651
|
* | (Children extends never ? never : InsertOp<Children>)
|
|
630
|
-
* | (Delta extends Children ? ModifyOp<Extract<Children,Delta
|
|
652
|
+
* | (Delta extends Children ? ModifyOp<Extract<Children,Delta<any,any,any,any,any>>> : never)
|
|
631
653
|
* >}
|
|
632
654
|
*/
|
|
633
655
|
this.children = /** @type {any} */ (list.create())
|
|
634
|
-
/**
|
|
635
|
-
* @type {FormattingAttributes?}
|
|
636
|
-
*/
|
|
637
|
-
this.usedAttributes = null
|
|
638
|
-
/**
|
|
639
|
-
* @type {Attribution?}
|
|
640
|
-
*/
|
|
641
|
-
this.usedAttribution = null
|
|
642
656
|
/**
|
|
643
657
|
* @type {any}
|
|
644
658
|
*/
|
|
@@ -646,7 +660,7 @@ export class Delta {
|
|
|
646
660
|
}
|
|
647
661
|
|
|
648
662
|
isEmpty () {
|
|
649
|
-
return this.attrs
|
|
663
|
+
return object.isEmpty(this.attrs) && list.isEmpty(this.children)
|
|
650
664
|
}
|
|
651
665
|
|
|
652
666
|
/**
|
|
@@ -661,7 +675,7 @@ export class Delta {
|
|
|
661
675
|
* @type {any}
|
|
662
676
|
*/
|
|
663
677
|
const children = []
|
|
664
|
-
this
|
|
678
|
+
forEachAttr(this, attr => {
|
|
665
679
|
attrs[attr.key] = attr.toJSON()
|
|
666
680
|
})
|
|
667
681
|
this.children.forEach(val => {
|
|
@@ -687,13 +701,13 @@ export class Delta {
|
|
|
687
701
|
*/
|
|
688
702
|
clone () {
|
|
689
703
|
/**
|
|
690
|
-
* @type {Delta<any,
|
|
704
|
+
* @type {Delta<any,Attrs,any,any,any>}
|
|
691
705
|
*/
|
|
692
|
-
const d = new
|
|
706
|
+
const d = new DeltaBuilder(/** @type {any} */ (this.name), this.$schema)
|
|
693
707
|
d.origin = this.origin
|
|
694
|
-
this.attrs
|
|
695
|
-
d.attrs
|
|
696
|
-
}
|
|
708
|
+
for (const op of this.attrs) {
|
|
709
|
+
d.attrs[op.key] = /** @type {any} */ (op)
|
|
710
|
+
}
|
|
697
711
|
this.children.forEach(op => {
|
|
698
712
|
list.pushEnd(d.children, op.clone())
|
|
699
713
|
})
|
|
@@ -707,6 +721,32 @@ export class Delta {
|
|
|
707
721
|
[traits.EqualityTraitSymbol] (other) {
|
|
708
722
|
return this.name === other.name && fun.equalityDeep(this.attrs, other.attrs) && fun.equalityDeep(this.children, other.children)
|
|
709
723
|
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* @template {string} [NodeName=any]
|
|
728
|
+
* @template {{[key:string|number|symbol]:any}} [Attrs={}]
|
|
729
|
+
* @template {any} [Children=never]
|
|
730
|
+
* @template {string|never} [Text=never]
|
|
731
|
+
* @template {s.Schema<Delta<any,any,any,any,any>>|null} [Schema=any]
|
|
732
|
+
* @extends {Delta<NodeName,Attrs,Children,Text,Schema>}
|
|
733
|
+
*/
|
|
734
|
+
export class DeltaBuilder extends Delta {
|
|
735
|
+
/**
|
|
736
|
+
* @param {NodeName} [name]
|
|
737
|
+
* @param {Schema} [$schema]
|
|
738
|
+
*/
|
|
739
|
+
constructor (name, $schema) {
|
|
740
|
+
super(name, $schema)
|
|
741
|
+
/**
|
|
742
|
+
* @type {FormattingAttributes?}
|
|
743
|
+
*/
|
|
744
|
+
this.usedAttributes = null
|
|
745
|
+
/**
|
|
746
|
+
* @type {Attribution?}
|
|
747
|
+
*/
|
|
748
|
+
this.usedAttribution = null
|
|
749
|
+
}
|
|
710
750
|
|
|
711
751
|
/**
|
|
712
752
|
* @param {Attribution?} attribution
|
|
@@ -767,7 +807,7 @@ export class Delta {
|
|
|
767
807
|
* @param {NewContent} insert
|
|
768
808
|
* @param {FormattingAttributes?} [formatting]
|
|
769
809
|
* @param {Attribution?} [attribution]
|
|
770
|
-
* @return {
|
|
810
|
+
* @return {DeltaBuilder<
|
|
771
811
|
* NodeName,
|
|
772
812
|
* Attrs,
|
|
773
813
|
* Exclude<NewContent,string>[number]|Children,
|
|
@@ -804,7 +844,7 @@ export class Delta {
|
|
|
804
844
|
* @param {NewContent} modify
|
|
805
845
|
* @param {FormattingAttributes?} formatting
|
|
806
846
|
* @param {Attribution?} attribution
|
|
807
|
-
* @return {
|
|
847
|
+
* @return {DeltaBuilder<
|
|
808
848
|
* NodeName,
|
|
809
849
|
* Attrs,
|
|
810
850
|
* Exclude<NewContent,string>[number]|Children,
|
|
@@ -838,7 +878,6 @@ export class Delta {
|
|
|
838
878
|
|
|
839
879
|
/**
|
|
840
880
|
* @param {number} len
|
|
841
|
-
* @return {this}
|
|
842
881
|
*/
|
|
843
882
|
delete (len) {
|
|
844
883
|
const lastOp = /** @type {DeleteOp|InsertOp<any>} */ (this.children.end)
|
|
@@ -857,7 +896,7 @@ export class Delta {
|
|
|
857
896
|
* @param {Val} val
|
|
858
897
|
* @param {Attribution?} attribution
|
|
859
898
|
* @param {Val|undefined} [prevValue]
|
|
860
|
-
* @return {
|
|
899
|
+
* @return {DeltaBuilder<
|
|
861
900
|
* NodeName,
|
|
862
901
|
* { [K in keyof AddToAttrs<Attrs,Key,Val>]: AddToAttrs<Attrs,Key,Val>[K] },
|
|
863
902
|
* Children,
|
|
@@ -866,7 +905,7 @@ export class Delta {
|
|
|
866
905
|
* >}
|
|
867
906
|
*/
|
|
868
907
|
set (key, val, attribution = null, prevValue) {
|
|
869
|
-
this.attrs
|
|
908
|
+
this.attrs[key] = /** @type {any} */ (new MapInsertOp(key, val, prevValue, mergeAttrs(this.usedAttribution, attribution)))
|
|
870
909
|
return /** @type {any} */ (this)
|
|
871
910
|
}
|
|
872
911
|
|
|
@@ -874,7 +913,7 @@ export class Delta {
|
|
|
874
913
|
* @template {AllowedDeltaFromSchema<Schema> extends Delta<any,infer Attrs,any,any,any> ? Attrs : never} NewAttrs
|
|
875
914
|
* @param {NewAttrs} attrs
|
|
876
915
|
* @param {Attribution?} attribution
|
|
877
|
-
* @return {
|
|
916
|
+
* @return {DeltaBuilder<
|
|
878
917
|
* NodeName,
|
|
879
918
|
* { [K in keyof MergeAttrs<Attrs,NewAttrs>]: MergeAttrs<Attrs,NewAttrs>[K] },
|
|
880
919
|
* Children,
|
|
@@ -894,7 +933,7 @@ export class Delta {
|
|
|
894
933
|
* @param {Key} key
|
|
895
934
|
* @param {Attribution?} attribution
|
|
896
935
|
* @param {any} [prevValue]
|
|
897
|
-
* @return {
|
|
936
|
+
* @return {DeltaBuilder<
|
|
898
937
|
* NodeName,
|
|
899
938
|
* { [K in keyof AddToAttrs<Attrs,Key,never>]: AddToAttrs<Attrs,Key,never>[K] },
|
|
900
939
|
* Children,
|
|
@@ -903,8 +942,8 @@ export class Delta {
|
|
|
903
942
|
* >}
|
|
904
943
|
*/
|
|
905
944
|
unset (key, attribution = null, prevValue) {
|
|
906
|
-
this.attrs
|
|
907
|
-
return this
|
|
945
|
+
this.attrs[key] = /** @type {any} */ (new MapDeleteOp(key, prevValue, mergeAttrs(this.usedAttribution, attribution)))
|
|
946
|
+
return /** @type {any} */ (this)
|
|
908
947
|
}
|
|
909
948
|
|
|
910
949
|
/**
|
|
@@ -912,7 +951,7 @@ export class Delta {
|
|
|
912
951
|
* @template {AllowedDeltaFromSchema<Schema> extends Delta<any,infer As,any,any,any> ? Extract<As[Key],Delta<any,any,any,any,any>> : never} D
|
|
913
952
|
* @param {Key} key
|
|
914
953
|
* @param {D} modify
|
|
915
|
-
* @return {
|
|
954
|
+
* @return {DeltaBuilder<
|
|
916
955
|
* NodeName,
|
|
917
956
|
* { [K in keyof AddToAttrs<Attrs,Key,D>]: AddToAttrs<Attrs,Key,D>[K] },
|
|
918
957
|
* Children,
|
|
@@ -921,29 +960,27 @@ export class Delta {
|
|
|
921
960
|
* >}
|
|
922
961
|
*/
|
|
923
962
|
update (key, modify) {
|
|
924
|
-
this.attrs
|
|
963
|
+
this.attrs[key] = /** @type {any} */ (new MapModifyOp(key, modify))
|
|
925
964
|
return /** @type {any} */ (this)
|
|
926
965
|
}
|
|
927
966
|
|
|
928
967
|
/**
|
|
929
|
-
* @param {Delta<NodeName,
|
|
930
|
-
* @return {this}
|
|
968
|
+
* @param {Delta<NodeName,Attrs,Children,Text,any>} other
|
|
931
969
|
*/
|
|
932
970
|
apply (other) {
|
|
933
971
|
this.$schema?.expect(other)
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
const c = this.attrs.get(op.key)
|
|
972
|
+
forEachAttr(/** @type {Delta<NodeName,Attrs,Children,Text,any>} */ (/** @type {any} */ (other)), op => {
|
|
973
|
+
const c = this.attrs[op.key]
|
|
937
974
|
if ($modifyOp.check(op)) {
|
|
938
975
|
if ($deltaAny.check(c?.value)) {
|
|
939
|
-
/** @type {
|
|
976
|
+
/** @type {DeltaBuilder} */ (c.value).apply(op.value)
|
|
940
977
|
} else {
|
|
941
978
|
// then this is a simple modify
|
|
942
|
-
this.attrs
|
|
979
|
+
this.attrs[op.key] = /** @type {any} */ (op)
|
|
943
980
|
}
|
|
944
981
|
} else {
|
|
945
982
|
/** @type {MapInsertOp<any>} */ (op).prevValue = c?.value
|
|
946
|
-
this.attrs
|
|
983
|
+
this.attrs[op.key] = /** @type {any} */ (op)
|
|
947
984
|
}
|
|
948
985
|
})
|
|
949
986
|
// apply children
|
|
@@ -1022,14 +1059,14 @@ export class Delta {
|
|
|
1022
1059
|
return
|
|
1023
1060
|
}
|
|
1024
1061
|
if ($modifyOp.check(opsI)) {
|
|
1025
|
-
opsI.
|
|
1062
|
+
/** @type {any} */ (opsI.value).apply(op.value)
|
|
1026
1063
|
} else if ($textOp.check(opsI) || $insertOp.check(opsI)) {
|
|
1027
1064
|
const d = opsI.insert[offset]
|
|
1028
1065
|
if (!$deltaAny.check(d)) {
|
|
1029
1066
|
// probably incompatible delta. can only modify deltas
|
|
1030
1067
|
error.unexpectedCase()
|
|
1031
1068
|
}
|
|
1032
|
-
d.apply(op.
|
|
1069
|
+
/** @type {any} */ (d).apply(op.value)
|
|
1033
1070
|
} else if ($retainOp.check(opsI)) {
|
|
1034
1071
|
if (offset > 0) {
|
|
1035
1072
|
const cpy = opsI.clone()
|
|
@@ -1074,30 +1111,33 @@ export class Delta {
|
|
|
1074
1111
|
* - delete vs delete ⇒ current delete op is removed because item has already been deleted
|
|
1075
1112
|
* - modify vs modify ⇒ rebase using priority
|
|
1076
1113
|
*/
|
|
1077
|
-
this
|
|
1114
|
+
forEachAttr(this, op => {
|
|
1078
1115
|
if ($insertOp.check(op)) {
|
|
1079
|
-
if ($insertOp.check(other.attrs
|
|
1080
|
-
this.attrs
|
|
1116
|
+
if ($insertOp.check(other.attrs[op.key]) && !priority) {
|
|
1117
|
+
delete this.attrs[op.key]
|
|
1081
1118
|
}
|
|
1082
1119
|
} else if ($deleteOp.check(op)) {
|
|
1083
|
-
const otherOp = other.attrs
|
|
1120
|
+
const otherOp = other.attrs[/** @type {any} */ (op.key)]
|
|
1084
1121
|
if ($insertOp.check(otherOp)) {
|
|
1085
|
-
this.attrs
|
|
1122
|
+
delete this.attrs[otherOp.key]
|
|
1086
1123
|
}
|
|
1087
1124
|
} else if ($modifyOp.check(op)) {
|
|
1088
|
-
const otherOp = other.attrs
|
|
1125
|
+
const otherOp = other.attrs[/** @type {any} */ (op.key)]
|
|
1089
1126
|
if (otherOp == null) {
|
|
1090
1127
|
// nop
|
|
1091
1128
|
} else if ($modifyOp.check(otherOp)) {
|
|
1092
1129
|
op.value.rebase(otherOp.value, priority)
|
|
1093
1130
|
} else {
|
|
1094
|
-
this.attrs
|
|
1131
|
+
delete this.attrs[otherOp.key]
|
|
1095
1132
|
}
|
|
1096
1133
|
}
|
|
1097
1134
|
})
|
|
1098
1135
|
return this
|
|
1099
1136
|
}
|
|
1100
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* @return {Delta<NodeName,Attrs,Children,Text,Schema>}
|
|
1140
|
+
*/
|
|
1101
1141
|
done () {
|
|
1102
1142
|
const cs = this.children
|
|
1103
1143
|
for (let end = cs.end; end !== null && $retainOp.check(end) && end.format == null; end = cs.end) {
|
|
@@ -1112,7 +1152,7 @@ export class Delta {
|
|
|
1112
1152
|
* @template {{ [key: string|number|symbol]: any }} [Attrs={}]
|
|
1113
1153
|
* @template {any} [Children=never]
|
|
1114
1154
|
* @template {string|never} [Text=never]
|
|
1115
|
-
* @typedef {Delta<NodeName,Attrs,Children|RecursiveDelta<NodeName,Attrs,Children>,Text>} RecursiveDelta
|
|
1155
|
+
* @typedef {Delta<NodeName,Attrs,Children|Delta<NodeName,Attrs,Children,Text>|RecursiveDelta<NodeName,Attrs,Children,Text>,Text>} RecursiveDelta
|
|
1116
1156
|
*/
|
|
1117
1157
|
|
|
1118
1158
|
/**
|
|
@@ -1144,8 +1184,8 @@ export const $delta = ({ name, attrs, children, hasText, recursive }) => {
|
|
|
1144
1184
|
const $d = s.$instanceOf(Delta, /** @param {Delta<any,any,any,any,any>} d */ d => {
|
|
1145
1185
|
if (
|
|
1146
1186
|
!name.check(d.name) ||
|
|
1147
|
-
|
|
1148
|
-
(
|
|
1187
|
+
object.some(d.attrs,
|
|
1188
|
+
(op, k) => $insertOp.check(op) && !$attrsPartial.check({ [k]: op.value })
|
|
1149
1189
|
)
|
|
1150
1190
|
) return false
|
|
1151
1191
|
for (const op of d.children) {
|
|
@@ -1161,7 +1201,10 @@ export const $delta = ({ name, attrs, children, hasText, recursive }) => {
|
|
|
1161
1201
|
return /** @type {any} */ ($d)
|
|
1162
1202
|
}
|
|
1163
1203
|
|
|
1164
|
-
|
|
1204
|
+
/**
|
|
1205
|
+
* @type {s.Schema<DeltaAny>}
|
|
1206
|
+
*/
|
|
1207
|
+
export const $deltaAny = /** @type {any} */ (s.$instanceOf(Delta))
|
|
1165
1208
|
|
|
1166
1209
|
/**
|
|
1167
1210
|
* Helper function to merge attribution and attributes. The latter input "wins".
|
|
@@ -1173,7 +1216,7 @@ export const $deltaAny = s.$instanceOf(Delta)
|
|
|
1173
1216
|
export const mergeAttrs = (a, b) => object.isEmpty(a) ? b : (object.isEmpty(b) ? a : object.assign({}, a, b))
|
|
1174
1217
|
|
|
1175
1218
|
/**
|
|
1176
|
-
* @template {
|
|
1219
|
+
* @template {DeltaBuilder?} D
|
|
1177
1220
|
* @param {D} a
|
|
1178
1221
|
* @param {D} b
|
|
1179
1222
|
* @return {D}
|
|
@@ -1189,62 +1232,58 @@ export const mergeDeltas = (a, b) => {
|
|
|
1189
1232
|
|
|
1190
1233
|
/**
|
|
1191
1234
|
* @overload
|
|
1192
|
-
* @return {
|
|
1235
|
+
* @return {DeltaBuilder<any,{},never,never,null>}
|
|
1193
1236
|
*/
|
|
1194
1237
|
/**
|
|
1195
1238
|
* @template {string} NodeName
|
|
1196
1239
|
* @overload
|
|
1197
1240
|
* @param {NodeName} nodeName
|
|
1198
|
-
* @return {
|
|
1241
|
+
* @return {DeltaBuilder<NodeName,{},never,never,null>}
|
|
1199
1242
|
*/
|
|
1200
1243
|
/**
|
|
1201
1244
|
* @template {string} NodeName
|
|
1202
|
-
* @template {s.Schema<
|
|
1245
|
+
* @template {s.Schema<DeltaAny>} Schema
|
|
1203
1246
|
* @overload
|
|
1204
1247
|
* @param {NodeName} nodeName
|
|
1205
1248
|
* @param {Schema} schema
|
|
1206
|
-
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ?
|
|
1249
|
+
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ? DeltaBuilder<NodeName,Attrs,Children,Text,Schema> : never}
|
|
1207
1250
|
*/
|
|
1208
1251
|
/**
|
|
1209
|
-
* @template {s.Schema<
|
|
1252
|
+
* @template {s.Schema<DeltaAny>} Schema
|
|
1210
1253
|
* @overload
|
|
1211
1254
|
* @param {Schema} schema
|
|
1212
|
-
* @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<N,Attrs,Children,Text,Schema> : never}
|
|
1213
1256
|
*/
|
|
1214
1257
|
/**
|
|
1215
1258
|
* @template {string|null} NodeName
|
|
1216
1259
|
* @template {{[k:string|number|symbol]:any}|null} Attrs
|
|
1217
|
-
* @template {Array<
|
|
1260
|
+
* @template {Array<any>|string} Children
|
|
1218
1261
|
* @overload
|
|
1219
1262
|
* @param {NodeName} nodeName
|
|
1220
1263
|
* @param {Attrs} attrs
|
|
1221
|
-
* @param {
|
|
1222
|
-
* @return {
|
|
1264
|
+
* @param {Children} [children]
|
|
1265
|
+
* @return {DeltaBuilder<
|
|
1223
1266
|
* NodeName extends null ? any : NodeName,
|
|
1224
1267
|
* Attrs extends null ? {} : Attrs,
|
|
1225
|
-
* Extract<Children
|
|
1226
|
-
* Extract<Children
|
|
1268
|
+
* Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
1269
|
+
* Extract<Children,string>,
|
|
1227
1270
|
* null
|
|
1228
1271
|
* >}
|
|
1229
1272
|
*/
|
|
1230
1273
|
/**
|
|
1231
|
-
* @param {string|s.Schema<
|
|
1232
|
-
* @param {{[K:string|number|symbol]:any}|s.Schema<
|
|
1233
|
-
* @param {Array<
|
|
1234
|
-
* @return {
|
|
1274
|
+
* @param {string|s.Schema<DeltaAny>} [nodeNameOrSchema]
|
|
1275
|
+
* @param {{[K:string|number|symbol]:any}|s.Schema<DeltaAny>} [attrsOrSchema]
|
|
1276
|
+
* @param {(Array<any>|string)} [children]
|
|
1277
|
+
* @return {DeltaBuilder<any,any,any,any,any>}
|
|
1235
1278
|
*/
|
|
1236
|
-
export const create = (nodeNameOrSchema, attrsOrSchema,
|
|
1279
|
+
export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
1237
1280
|
const nodeName = /** @type {any} */ (s.$string.check(nodeNameOrSchema) ? nodeNameOrSchema : null)
|
|
1238
1281
|
const schema = /** @type {any} */ (s.$$schema.check(nodeNameOrSchema) ? nodeNameOrSchema : (s.$$schema.check(attrsOrSchema) ? attrsOrSchema : null))
|
|
1239
|
-
const d = /** @type {
|
|
1282
|
+
const d = /** @type {DeltaBuilder<any,any,any,string,null>} */ (new DeltaBuilder(nodeName, schema))
|
|
1240
1283
|
if (s.$objectAny.check(attrsOrSchema)) {
|
|
1241
1284
|
d.setMany(attrsOrSchema)
|
|
1242
1285
|
}
|
|
1243
|
-
|
|
1244
|
-
children.forEach(v => {
|
|
1245
|
-
d.insert(v)
|
|
1246
|
-
})
|
|
1247
|
-
}
|
|
1286
|
+
children && d.insert(children)
|
|
1248
1287
|
return d
|
|
1249
1288
|
}
|
|
1250
1289
|
|
|
@@ -1255,6 +1294,11 @@ export const create = (nodeNameOrSchema, attrsOrSchema, ...children) => {
|
|
|
1255
1294
|
* @typedef {Delta<any,{},Embeds,string>} TextDelta
|
|
1256
1295
|
*/
|
|
1257
1296
|
|
|
1297
|
+
/**
|
|
1298
|
+
* @template [Embeds=never]
|
|
1299
|
+
* @typedef {DeltaBuilder<any,{},Embeds,string>} TextDeltaBuilder
|
|
1300
|
+
*/
|
|
1301
|
+
|
|
1258
1302
|
/**
|
|
1259
1303
|
* @template {Array<s.Schema<any>>} [$Embeds=any]
|
|
1260
1304
|
* @param {$Embeds} $embeds
|
|
@@ -1266,7 +1310,7 @@ export const $textOnly = $text()
|
|
|
1266
1310
|
/**
|
|
1267
1311
|
* @template {s.Schema<Delta<any,{},any,any,null>>} [Schema=s.Schema<Delta<any,{},never,string,null>>]
|
|
1268
1312
|
* @param {Schema} [$schema]
|
|
1269
|
-
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ?
|
|
1313
|
+
* @return {Schema extends s.Schema<Delta<infer N,infer Attrs,infer Children,infer Text,any>> ? DeltaBuilder<N,Attrs,Children,Text,Schema> : never}
|
|
1270
1314
|
*/
|
|
1271
1315
|
export const text = $schema => /** @type {any} */ (create($schema || $textOnly))
|
|
1272
1316
|
|
|
@@ -1275,6 +1319,11 @@ export const text = $schema => /** @type {any} */ (create($schema || $textOnly))
|
|
|
1275
1319
|
* @typedef {Delta<any,{},Children,never>} ArrayDelta
|
|
1276
1320
|
*/
|
|
1277
1321
|
|
|
1322
|
+
/**
|
|
1323
|
+
* @template {any} Children
|
|
1324
|
+
* @typedef {DeltaBuilder<any,{},Children,never>} ArrayDeltaBuilder
|
|
1325
|
+
*/
|
|
1326
|
+
|
|
1278
1327
|
/**
|
|
1279
1328
|
* @template {s.Schema<any>} $Children
|
|
1280
1329
|
* @param {$Children} [$children]
|
|
@@ -1285,7 +1334,7 @@ export const $array = $children => $delta({ children: $children })
|
|
|
1285
1334
|
/**
|
|
1286
1335
|
* @template {s.Schema<ArrayDelta<any>>} [$Schema=never]
|
|
1287
1336
|
* @param {$Schema} $schema
|
|
1288
|
-
* @return {$Schema extends never ?
|
|
1337
|
+
* @return {$Schema extends never ? ArrayDeltaBuilder<never> : DeltaBuilder<any,{},never,never,$Schema>}
|
|
1289
1338
|
*/
|
|
1290
1339
|
export const array = $schema => /** @type {any} */ ($schema ? create($schema) : create())
|
|
1291
1340
|
|
|
@@ -1294,6 +1343,11 @@ export const array = $schema => /** @type {any} */ ($schema ? create($schema) :
|
|
|
1294
1343
|
* @typedef {Delta<any,Attrs,never,never>} MapDelta
|
|
1295
1344
|
*/
|
|
1296
1345
|
|
|
1346
|
+
/**
|
|
1347
|
+
* @template {{ [K: string|number|symbol]: any }} Attrs
|
|
1348
|
+
* @typedef {DeltaBuilder<any,Attrs,never,never>} MapDeltaBuilder
|
|
1349
|
+
*/
|
|
1350
|
+
|
|
1297
1351
|
/**
|
|
1298
1352
|
* @template {{ [K: string|number|symbol]: any }} $Attrs
|
|
1299
1353
|
* @param {s.Schema<$Attrs>} $attrs
|
|
@@ -1304,6 +1358,6 @@ export const $map = $attrs => /** @type {any} */ ($delta({ attrs: $attrs }))
|
|
|
1304
1358
|
/**
|
|
1305
1359
|
* @template {s.Schema<MapDelta<any>>|undefined} [$Schema=undefined]
|
|
1306
1360
|
* @param {$Schema} [$schema]
|
|
1307
|
-
* @return {$Schema extends s.Schema<MapDelta<infer Attrs>> ?
|
|
1361
|
+
* @return {$Schema extends s.Schema<MapDelta<infer Attrs>> ? DeltaBuilder<any,Attrs,never,never,$Schema> : MapDeltaBuilder<{}>}
|
|
1308
1362
|
*/
|
|
1309
1363
|
export const map = $schema => /** @type {any} */ (create(/** @type {any} */ ($schema)))
|
package/delta/d2.test.d.ts
CHANGED
package/delta/d2.test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d2.test.d.ts","sourceRoot":"","sources":["d2.test.js"],"names":[],"mappings":"AAMO,
|
|
1
|
+
{"version":3,"file":"d2.test.d.ts","sourceRoot":"","sources":["d2.test.js"],"names":[],"mappings":"AAMO,wCA2BN;AAKM,0CA0HN;AAEM,iCAWN;AAKM,+BAFI,CAAC,CAAC,QAAQ,QAKpB;AAKM,sCAFI,CAAC,CAAC,QAAQ,QAYpB;AAKM,uCAFI,CAAC,CAAC,QAAQ,QAuBpB;AAKM,wCAFI,CAAC,CAAC,QAAQ,QAsBpB;AAEM,sCAaN;AAKM,wCAFI,CAAC,CAAC,QAAQ,QA4BpB;AAKM,wCAFI,CAAC,CAAC,QAAQ,QA2CpB;AAKM,kCAFI,CAAC,CAAC,QAAQ,QAoDpB;AAKM,gDAFI,CAAC,CAAC,QAAQ,QAoEpB;AAKM,mCAFI,CAAC,CAAC,QAAQ,QAiCpB;AAEM,0CAoBN;mBA3gBkB,cAAc"}
|
package/diff.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export function simpleDiffStringWithCursor(a: string, b: string, cursor: number)
|
|
|
18
18
|
* a === b // values match
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
export type SimpleDiff<T extends string
|
|
21
|
+
export type SimpleDiff<T extends string | Array<any>> = {
|
|
22
22
|
/**
|
|
23
23
|
* The index where changes were applied
|
|
24
24
|
*/
|
package/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["diff.js"],"names":[],"mappings":"AAyCO,oCAJI,MAAM,KACN,MAAM,GACL,UAAU,CAAC,MAAM,CAAC,CAoB7B;AAlBM,8BAJI,MAAM,KACN,MAAM,GACL,UAAU,CAAC,MAAM,CAAC,CAoB7B;AAuBM,gCAPM,CAAC,KAEH,KAAK,CAAC,CAAC,CAAC,KACR,KAAK,CAAC,CAAC,CAAC,YACR,CAAS,IAAC,EAAD,CAAC,EAAE,IAAC,EAAD,CAAC,KAAE,OAAO,GACrB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAgB/B;AASM,8CAJI,MAAM,KACN,MAAM,UACN,MAAM;;;;EAyChB;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["diff.js"],"names":[],"mappings":"AAyCO,oCAJI,MAAM,KACN,MAAM,GACL,UAAU,CAAC,MAAM,CAAC,CAoB7B;AAlBM,8BAJI,MAAM,KACN,MAAM,GACL,UAAU,CAAC,MAAM,CAAC,CAoB7B;AAuBM,gCAPM,CAAC,KAEH,KAAK,CAAC,CAAC,CAAC,KACR,KAAK,CAAC,CAAC,CAAC,YACR,CAAS,IAAC,EAAD,CAAC,EAAE,IAAC,EAAD,CAAC,KAAE,OAAO,GACrB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAgB/B;AASM,8CAJI,MAAM,KACN,MAAM,UACN,MAAM;;;;EAyChB;;;;;;;;;;;;;uBA5HgC,CAAC,SAApB,MAAM,GAAC,KAAK,CAAC,GAAG,CAAE;;;;;;;;;;;;;YAKlB,CAAC"}
|
package/diff.js
CHANGED
|
@@ -18,7 +18,7 @@ import { equalityStrict } from './function.js'
|
|
|
18
18
|
* a === b // values match
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
|
-
* @template {string} T
|
|
21
|
+
* @template {string|Array<any>} T
|
|
22
22
|
* @typedef {Object} SimpleDiff
|
|
23
23
|
* @property {Number} index The index where changes were applied
|
|
24
24
|
* @property {Number} remove The number of characters to delete starting
|
package/dist/component.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var dom = require('./dom-2b123630.cjs');
|
|
6
|
-
var diff = require('./diff-
|
|
6
|
+
var diff = require('./diff-1832cb43.cjs');
|
|
7
7
|
var object = require('./object-18980796.cjs');
|
|
8
8
|
var json = require('./json-092190a1.cjs');
|
|
9
9
|
var string = require('./string-fddc5f8b.cjs');
|