lib0 1.0.0-rc.34 → 1.0.0-rc.35
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/dist/delta/delta.d.ts +47 -57
- package/package.json +2 -2
- package/src/delta/delta.js +39 -49
package/dist/delta/delta.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export const $attribution: s.Schema<Attribution>;
|
|
|
58
58
|
* @typedef {{ type: 'insert', value: any, attribution?: Attribution } | { type: 'delete', attribution?: Attribution } | { type: 'modify', value: DeltaJSON, attribution?: Attribution|null }} DeltaAttrOpJSON
|
|
59
59
|
*/
|
|
60
60
|
/**
|
|
61
|
-
* @typedef {TextOp|InsertOp<any>|DeleteOp
|
|
61
|
+
* @typedef {TextOp|InsertOp<any>|DeleteOp<any>|RetainOp|ModifyOp<any>} ChildrenOpAny
|
|
62
62
|
*/
|
|
63
63
|
/**
|
|
64
64
|
* @typedef {SetAttrOp<any>|DeleteAttrOp<any>|ModifyAttrOp} AttrOpAny
|
|
@@ -249,14 +249,14 @@ export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
|
|
|
249
249
|
* @param {number} [end]
|
|
250
250
|
* @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
|
|
251
251
|
* delete holds no nested content).
|
|
252
|
-
* @return {DeleteOp}
|
|
252
|
+
* @return {DeleteOp<any>}
|
|
253
253
|
*/
|
|
254
|
-
clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp
|
|
254
|
+
clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp<any>;
|
|
255
255
|
$type: s.Schema<DeleteOp<any>>;
|
|
256
256
|
/**
|
|
257
|
-
* @param {DeleteOp} other
|
|
257
|
+
* @param {DeleteOp<any>} other
|
|
258
258
|
*/
|
|
259
|
-
[equalityTrait.EqualityTraitSymbol](other: DeleteOp): boolean;
|
|
259
|
+
[equalityTrait.EqualityTraitSymbol](other: DeleteOp<any>): boolean;
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
|
|
@@ -321,10 +321,10 @@ export class RetainOp extends list.ListNode {
|
|
|
321
321
|
/**
|
|
322
322
|
* Delta that can be applied on a YType Embed
|
|
323
323
|
*
|
|
324
|
-
* @template {Delta} [DTypes=DeltaAny]
|
|
324
|
+
* @template {Delta<any>} [DTypes=DeltaAny]
|
|
325
325
|
* @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
|
|
326
326
|
*/
|
|
327
|
-
export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
|
|
327
|
+
export class ModifyOp<DTypes extends Delta<any> = DeltaAny> extends list.ListNode {
|
|
328
328
|
/**
|
|
329
329
|
* @param {DTypes} delta
|
|
330
330
|
* @param {Formats|null|undefined} format tri-state: `undefined` skip / `null` clear / object merge
|
|
@@ -530,9 +530,9 @@ export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string
|
|
|
530
530
|
get type(): "modify";
|
|
531
531
|
get fingerprint(): string;
|
|
532
532
|
/**
|
|
533
|
-
* @return {DeltaBuilder}
|
|
533
|
+
* @return {DeltaBuilder<any>}
|
|
534
534
|
*/
|
|
535
|
-
get _modValue(): DeltaBuilder
|
|
535
|
+
get _modValue(): DeltaBuilder<any>;
|
|
536
536
|
/**
|
|
537
537
|
* @return {DeltaAttrOpJSON}
|
|
538
538
|
*/
|
|
@@ -737,13 +737,13 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
|
|
|
737
737
|
text: true;
|
|
738
738
|
})>, FixedConf>;
|
|
739
739
|
/**
|
|
740
|
-
* @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta
|
|
740
|
+
* @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta<any>|DeltaData<any,any,any,any>|DeltaBuilder<any>>} NewContent
|
|
741
741
|
* @param {NewContent} modify
|
|
742
742
|
* @param {Formats?} [formatting] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
|
|
743
743
|
* @param {Attribution?} [attribution] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
|
|
744
744
|
* @return {DeltaBuilder<DeltaConfOverwrite<Conf, {children: DeltaConfGetChildren<Conf>|NewContent}>, FixedConf>}
|
|
745
745
|
*/
|
|
746
|
-
modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta | DeltaData<any, any, any, any> | DeltaBuilder
|
|
746
|
+
modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta<any> | DeltaData<any, any, any, any> | DeltaBuilder<any>>>(modify: NewContent, formatting?: Formats | null, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
|
|
747
747
|
children: DeltaConfGetChildren<Conf> | NewContent;
|
|
748
748
|
}>, FixedConf>;
|
|
749
749
|
/**
|
|
@@ -1009,45 +1009,35 @@ export function create<NodeName extends string | null, Attrs extends {
|
|
|
1009
1009
|
[k: string | number]: any;
|
|
1010
1010
|
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
|
|
1011
1011
|
/**
|
|
1012
|
-
*
|
|
1013
|
-
* @
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
*
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
* @
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
*
|
|
1029
|
-
*
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
[
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
* @template {Array<any>|string} [Children=never]
|
|
1042
|
-
* @overload
|
|
1043
|
-
* @param {NodeName} nodeName
|
|
1044
|
-
* @param {Attrs} attrs
|
|
1045
|
-
* @param {...Array<Children>} children
|
|
1046
|
-
* @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
|
|
1047
|
-
*/
|
|
1048
|
-
export function from<NodeName extends string | null, Attrs extends {
|
|
1049
|
-
[k: string | number]: any;
|
|
1050
|
-
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
|
|
1012
|
+
* Build a delta from positional args: an optional node name, optional attrs, then any number of
|
|
1013
|
+
* children (each either a string or an array of embeds) - see {@link create} for the fixed-arity
|
|
1014
|
+
* condensed form.
|
|
1015
|
+
*
|
|
1016
|
+
* Typed as a set of call signatures instead of `@overload` tags, because a rest parameter can't be
|
|
1017
|
+
* declared consistently in an `@overload` tag: the checker only turns `@param {...X} children`
|
|
1018
|
+
* into `X[]` if the implementation's rest parameter has the same name, otherwise it takes `X` as
|
|
1019
|
+
* the type of the whole rest array - while the declaration emit always writes `...children: X[]`.
|
|
1020
|
+
* lib0's source check and the consumers of the emitted declarations hence saw different
|
|
1021
|
+
* signatures. `Children` is the tuple of all children arguments, so that string and array children
|
|
1022
|
+
* can be mixed (`Children[number]` is the union of them).
|
|
1023
|
+
*
|
|
1024
|
+
* @type {{
|
|
1025
|
+
* <NodeName extends string|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,null,Children[number]>>,
|
|
1026
|
+
* <Children extends Array<Array<any>|string> = []>(...children: Children): DeltaBuilder<CondensedDeltaConf<null,null,Children[number]>>,
|
|
1027
|
+
* <Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<null,Attrs,Children[number]>>,
|
|
1028
|
+
* <NodeName extends string|null, Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children[number]>>
|
|
1029
|
+
* }}
|
|
1030
|
+
*/
|
|
1031
|
+
export const from: {
|
|
1032
|
+
<NodeName_1 extends string | null, Children_1 extends Array<Array<any> | string> = []>(nodeName: NodeName_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<NodeName_1, null, Children_1[number]>>;
|
|
1033
|
+
<Children_1 extends Array<Array<any> | string> = []>(...children: Children_1): DeltaBuilder<CondensedDeltaConf<null, null, Children_1[number]>>;
|
|
1034
|
+
<Attrs_1 extends {
|
|
1035
|
+
[k: string | number]: any;
|
|
1036
|
+
} | null, Children_1 extends Array<Array<any> | string> = []>(attrs: Attrs_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<null, Attrs_1, Children_1[number]>>;
|
|
1037
|
+
<NodeName_1 extends string | null, Attrs_1 extends {
|
|
1038
|
+
[k: string | number]: any;
|
|
1039
|
+
} | null, Children_1 extends Array<Array<any> | string> = []>(nodeName: NodeName_1, attrs: Attrs_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<NodeName_1, Attrs_1, Children_1[number]>>;
|
|
1040
|
+
};
|
|
1051
1041
|
/**
|
|
1052
1042
|
* Shorthand for `delta.create().insert(..)` — see {@link DeltaBuilder#insert}.
|
|
1053
1043
|
*
|
|
@@ -1222,7 +1212,7 @@ export type DeltaAttrOpJSON = {
|
|
|
1222
1212
|
value: DeltaJSON;
|
|
1223
1213
|
attribution?: Attribution | null;
|
|
1224
1214
|
};
|
|
1225
|
-
export type ChildrenOpAny = TextOp | InsertOp<any> | DeleteOp | RetainOp | ModifyOp<any>;
|
|
1215
|
+
export type ChildrenOpAny = TextOp | InsertOp<any> | DeleteOp<any> | RetainOp | ModifyOp<any>;
|
|
1226
1216
|
export type AttrOpAny = SetAttrOp<any> | DeleteAttrOp<any> | ModifyAttrOp;
|
|
1227
1217
|
export type _OpAny = ChildrenOpAny | AttrOpAny;
|
|
1228
1218
|
export type AddToAttrs<Attrs_1 extends { [Key in string | number]: any; }, Key extends string | number, Val extends unknown> = { [K in (Key | keyof Attrs_1)]: (unknown extends Attrs_1[K] ? never : Attrs_1[K]) | (Key extends K ? Val : never); } & {};
|
|
@@ -1574,20 +1564,20 @@ declare class DeltaData<Name extends string, Attrs extends { [K in string | numb
|
|
|
1574
1564
|
name: Name;
|
|
1575
1565
|
$schema: s.Schema<Delta<any>> | null;
|
|
1576
1566
|
/**
|
|
1577
|
-
* @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Attrs[K]
|
|
1578
|
-
* & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta
|
|
1567
|
+
* @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }
|
|
1568
|
+
* & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }[keyof Attrs]> }
|
|
1579
1569
|
* }
|
|
1580
1570
|
*/
|
|
1581
|
-
attrs: { [K in keyof Attrs]?: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Attrs[K]
|
|
1582
|
-
[Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta
|
|
1571
|
+
attrs: { [K in keyof Attrs]?: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta<any>>, K> : never))) : never; } & {
|
|
1572
|
+
[Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta<any>>, K> : never))) : never; }[keyof Attrs]>;
|
|
1583
1573
|
};
|
|
1584
1574
|
/**
|
|
1585
1575
|
* @type {list.List<
|
|
1586
1576
|
* | (Text extends true ? (RetainOp|TextOp|DeleteOp<any>) : never)
|
|
1587
|
-
* | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta extends Children ? ModifyOp<Extract<Children,Delta
|
|
1577
|
+
* | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta<any> extends Children ? ModifyOp<Extract<Children,Delta<any>>> : never))
|
|
1588
1578
|
* >}
|
|
1589
1579
|
*/
|
|
1590
|
-
children: list.List<(Text extends true ? (RetainOp | TextOp | DeleteOp<any>) : never) | (RetainOp | InsertOp<Children> | DeleteOp<any> | (Delta extends Children ? ModifyOp<Extract<Children, Delta
|
|
1580
|
+
children: list.List<(Text extends true ? (RetainOp | TextOp | DeleteOp<any>) : never) | (RetainOp | InsertOp<Children> | DeleteOp<any> | (Delta<any> extends Children ? ModifyOp<Extract<Children, Delta<any>>> : never))>;
|
|
1591
1581
|
/**
|
|
1592
1582
|
* All child-ops sizes combined. Note that delete-ops also have a length
|
|
1593
1583
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lib0",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.35",
|
|
4
4
|
"description": "isomorphic utility functions",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
"scripts": {
|
|
342
342
|
"clean": "rm -rf dist",
|
|
343
343
|
"types": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
344
|
-
"check-dist-types": "tsc -p tsconfig.dist-check.json",
|
|
344
|
+
"check-dist-types": "node ./dist-check/copy-tests.js && tsc -p tsconfig.dist-check.json",
|
|
345
345
|
"dist": "npm run clean && npm run types && npm run check-dist-types",
|
|
346
346
|
"debug": "npm run gentesthtml && node ./src/bin/0serve.js -o test.html",
|
|
347
347
|
"test": "c8 --check-coverage --lines 97 --branches 96 --functions 94 --statements 97 node --unhandled-rejections=strict ./src/test.js",
|
package/src/delta/delta.js
CHANGED
|
@@ -116,7 +116,7 @@ export const $attribution = /* @__PURE__ */(() => s.$object({
|
|
|
116
116
|
*/
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* @typedef {TextOp|InsertOp<any>|DeleteOp
|
|
119
|
+
* @typedef {TextOp|InsertOp<any>|DeleteOp<any>|RetainOp|ModifyOp<any>} ChildrenOpAny
|
|
120
120
|
*/
|
|
121
121
|
|
|
122
122
|
/**
|
|
@@ -635,7 +635,7 @@ export class DeleteOp extends list.ListNode {
|
|
|
635
635
|
}
|
|
636
636
|
|
|
637
637
|
/**
|
|
638
|
-
* @param {DeleteOp} other
|
|
638
|
+
* @param {DeleteOp<any>} other
|
|
639
639
|
*/
|
|
640
640
|
[equalityTrait.EqualityTraitSymbol] (other) {
|
|
641
641
|
return $deleteOp.check(other) && this.delete === other.delete
|
|
@@ -646,7 +646,7 @@ export class DeleteOp extends list.ListNode {
|
|
|
646
646
|
* @param {number} [end]
|
|
647
647
|
* @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
|
|
648
648
|
* delete holds no nested content).
|
|
649
|
-
* @return {DeleteOp}
|
|
649
|
+
* @return {DeleteOp<any>}
|
|
650
650
|
*/
|
|
651
651
|
clone (start = 0, end = this.delete, _markAsDone = true) {
|
|
652
652
|
const cpy = new DeleteOp(end - start)
|
|
@@ -758,7 +758,7 @@ export class RetainOp extends list.ListNode {
|
|
|
758
758
|
/**
|
|
759
759
|
* Delta that can be applied on a YType Embed
|
|
760
760
|
*
|
|
761
|
-
* @template {Delta} [DTypes=DeltaAny]
|
|
761
|
+
* @template {Delta<any>} [DTypes=DeltaAny]
|
|
762
762
|
* @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
|
|
763
763
|
*/
|
|
764
764
|
export class ModifyOp extends list.ListNode {
|
|
@@ -1088,7 +1088,7 @@ export class ModifyAttrOp {
|
|
|
1088
1088
|
}
|
|
1089
1089
|
|
|
1090
1090
|
/**
|
|
1091
|
-
* @return {DeltaBuilder}
|
|
1091
|
+
* @return {DeltaBuilder<any>}
|
|
1092
1092
|
*/
|
|
1093
1093
|
get _modValue () {
|
|
1094
1094
|
return modValue(this)
|
|
@@ -1403,8 +1403,8 @@ class DeltaData {
|
|
|
1403
1403
|
this.name = /** @type {Name} */ (name)
|
|
1404
1404
|
this.$schema = $schema
|
|
1405
1405
|
/**
|
|
1406
|
-
* @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Attrs[K]
|
|
1407
|
-
* & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta
|
|
1406
|
+
* @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }
|
|
1407
|
+
* & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }[keyof Attrs]> }
|
|
1408
1408
|
* }
|
|
1409
1409
|
*/
|
|
1410
1410
|
this.attrs = /** @type {any} */ ({
|
|
@@ -1418,7 +1418,7 @@ class DeltaData {
|
|
|
1418
1418
|
/**
|
|
1419
1419
|
* @type {list.List<
|
|
1420
1420
|
* | (Text extends true ? (RetainOp|TextOp|DeleteOp<any>) : never)
|
|
1421
|
-
* | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta extends Children ? ModifyOp<Extract<Children,Delta
|
|
1421
|
+
* | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta<any> extends Children ? ModifyOp<Extract<Children,Delta<any>>> : never))
|
|
1422
1422
|
* >}
|
|
1423
1423
|
*/
|
|
1424
1424
|
this.children = /** @type {any} */ (list.create())
|
|
@@ -2239,7 +2239,7 @@ export class DeltaBuilder extends Delta {
|
|
|
2239
2239
|
}
|
|
2240
2240
|
|
|
2241
2241
|
/**
|
|
2242
|
-
* @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta
|
|
2242
|
+
* @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta<any>|DeltaData<any,any,any,any>|DeltaBuilder<any>>} NewContent
|
|
2243
2243
|
* @param {NewContent} modify
|
|
2244
2244
|
* @param {Formats?} [formatting] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
|
|
2245
2245
|
* @param {Attribution?} [attribution] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
|
|
@@ -3926,58 +3926,48 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
|
|
|
3926
3926
|
}
|
|
3927
3927
|
|
|
3928
3928
|
/**
|
|
3929
|
-
* @
|
|
3930
|
-
*
|
|
3931
|
-
*
|
|
3932
|
-
* @param {NodeName} nodeName
|
|
3933
|
-
* @param {...Array<Children>} children
|
|
3934
|
-
* @return {DeltaBuilder<CondensedDeltaConf<NodeName,null,Children>>}
|
|
3935
|
-
*/
|
|
3936
|
-
/**
|
|
3937
|
-
* @template {Array<any>|string} [Children=never]
|
|
3938
|
-
* @overload
|
|
3939
|
-
* @param {...Array<Children>} children
|
|
3940
|
-
* @return {DeltaBuilder<CondensedDeltaConf<null,null,Children>>}
|
|
3941
|
-
*/
|
|
3942
|
-
/**
|
|
3943
|
-
* @template {{[k:string|number]:any}|null} Attrs
|
|
3944
|
-
* @template {Array<any>|string} [Children=never]
|
|
3945
|
-
* @overload
|
|
3946
|
-
* @param {Attrs} attrs
|
|
3947
|
-
* @param {...Array<Children>} children
|
|
3948
|
-
* @return {DeltaBuilder<CondensedDeltaConf<null,Attrs,Children>>}
|
|
3949
|
-
*/
|
|
3950
|
-
/**
|
|
3951
|
-
* @template {string|null} NodeName
|
|
3952
|
-
* @template {{[k:string|number]:any}|null} Attrs
|
|
3953
|
-
* @template {Array<any>|string} [Children=never]
|
|
3954
|
-
* @overload
|
|
3955
|
-
* @param {NodeName} nodeName
|
|
3956
|
-
* @param {Attrs} attrs
|
|
3957
|
-
* @param {...Array<Children>} children
|
|
3958
|
-
* @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
|
|
3959
|
-
*/
|
|
3960
|
-
/**
|
|
3961
|
-
* `...X` (not `Array<X>`) is the rest-parameter form — `@param {Array<X>} args` declares a single
|
|
3962
|
-
* array-typed parameter, which makes the overloads above incompatible with this signature. TS only
|
|
3963
|
-
* cross-checks overloads against the implementation for function declarations, so it stayed silent.
|
|
3929
|
+
* Returns `any` because the resulting conf is computed by the call signatures of {@link from} at
|
|
3930
|
+
* the type level only - as in a ts overload implementation, the body can't be checked against
|
|
3931
|
+
* each of them.
|
|
3964
3932
|
*
|
|
3965
|
-
* @param {...
|
|
3966
|
-
* @return {
|
|
3933
|
+
* @param {...any} args
|
|
3934
|
+
* @return {any}
|
|
3967
3935
|
*/
|
|
3968
|
-
|
|
3936
|
+
const _from = (...args) => {
|
|
3969
3937
|
const hasName = s.$string.check(args[0])
|
|
3970
3938
|
let i = hasName ? 1 : 0
|
|
3971
3939
|
const d = create(hasName ? /** @type {string} */ (args[0]) : null)
|
|
3972
3940
|
if (s.$objectAny.check(args[i])) {
|
|
3973
|
-
d.setAttrs(
|
|
3941
|
+
d.setAttrs(args[i++])
|
|
3974
3942
|
}
|
|
3975
3943
|
for (; i < args.length; i++) {
|
|
3976
|
-
d.insert(
|
|
3944
|
+
d.insert(args[i])
|
|
3977
3945
|
}
|
|
3978
3946
|
return d
|
|
3979
3947
|
}
|
|
3980
3948
|
|
|
3949
|
+
/**
|
|
3950
|
+
* Build a delta from positional args: an optional node name, optional attrs, then any number of
|
|
3951
|
+
* children (each either a string or an array of embeds) - see {@link create} for the fixed-arity
|
|
3952
|
+
* condensed form.
|
|
3953
|
+
*
|
|
3954
|
+
* Typed as a set of call signatures instead of `@overload` tags, because a rest parameter can't be
|
|
3955
|
+
* declared consistently in an `@overload` tag: the checker only turns `@param {...X} children`
|
|
3956
|
+
* into `X[]` if the implementation's rest parameter has the same name, otherwise it takes `X` as
|
|
3957
|
+
* the type of the whole rest array - while the declaration emit always writes `...children: X[]`.
|
|
3958
|
+
* lib0's source check and the consumers of the emitted declarations hence saw different
|
|
3959
|
+
* signatures. `Children` is the tuple of all children arguments, so that string and array children
|
|
3960
|
+
* can be mixed (`Children[number]` is the union of them).
|
|
3961
|
+
*
|
|
3962
|
+
* @type {{
|
|
3963
|
+
* <NodeName extends string|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,null,Children[number]>>,
|
|
3964
|
+
* <Children extends Array<Array<any>|string> = []>(...children: Children): DeltaBuilder<CondensedDeltaConf<null,null,Children[number]>>,
|
|
3965
|
+
* <Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<null,Attrs,Children[number]>>,
|
|
3966
|
+
* <NodeName extends string|null, Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children[number]>>
|
|
3967
|
+
* }}
|
|
3968
|
+
*/
|
|
3969
|
+
export const from = _from
|
|
3970
|
+
|
|
3981
3971
|
/**
|
|
3982
3972
|
* Shorthand for `delta.create().insert(..)` — see {@link DeltaBuilder#insert}.
|
|
3983
3973
|
*
|