lib0 1.0.0-rc.29 → 1.0.0-rc.30

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.
@@ -992,70 +992,38 @@ export function create<Schema extends s.Schema<DeltaAny>>(schema: Schema): Schem
992
992
  * @param {NodeName} nodeName
993
993
  * @param {Attrs} attrs
994
994
  * @param {Children} [children]
995
- * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
996
- * attrs: Attrs extends null ? {} : Attrs,
997
- * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
998
- * text: Extract<Children,string> extends never ? false : true
999
- * }>}
995
+ * @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
1000
996
  */
1001
997
  export function create<NodeName extends string | null, Attrs extends {
1002
998
  [k: string | number]: any;
1003
- } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<(NodeName extends string ? {
1004
- name: NodeName;
1005
- } : {}) & {
1006
- attrs: Attrs extends null ? {} : Attrs;
1007
- children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
1008
- text: Extract<Children, string> extends never ? false : true;
1009
- }>;
999
+ } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
1010
1000
  /**
1011
1001
  * @template {string|null} NodeName
1012
1002
  * @template {Array<any>|string} [Children=never]
1013
1003
  * @overload
1014
1004
  * @param {NodeName} nodeName
1015
1005
  * @param {...Array<Children>} children
1016
- * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
1017
- * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
1018
- * text: Extract<Children,string> extends never ? false : true
1019
- * }>}
1006
+ * @return {DeltaBuilder<CondensedDeltaConf<NodeName,null,Children>>}
1020
1007
  */
1021
- export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
1022
- name: NodeName;
1023
- } : {}) & {
1024
- children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
1025
- text: Extract<Children, string> extends never ? false : true;
1026
- }>;
1008
+ export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<NodeName, null, Children>>;
1027
1009
  /**
1028
1010
  * @template {Array<any>|string} [Children=never]
1029
1011
  * @overload
1030
1012
  * @param {...Array<Children>} children
1031
- * @return {DeltaBuilder<{
1032
- * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
1033
- * text: Extract<Children,string> extends never ? false : true
1034
- * }>}
1013
+ * @return {DeltaBuilder<CondensedDeltaConf<null,null,Children>>}
1035
1014
  */
1036
- export function from<Children extends Array<any> | string = never>(...children: Array<Children>[]): DeltaBuilder<{
1037
- children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
1038
- text: Extract<Children, string> extends never ? false : true;
1039
- }>;
1015
+ export function from<Children extends Array<any> | string = never>(...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<null, null, Children>>;
1040
1016
  /**
1041
1017
  * @template {{[k:string|number]:any}|null} Attrs
1042
1018
  * @template {Array<any>|string} [Children=never]
1043
1019
  * @overload
1044
1020
  * @param {Attrs} attrs
1045
1021
  * @param {...Array<Children>} children
1046
- * @return {DeltaBuilder<{
1047
- * attrs: Attrs extends null ? {} : Attrs,
1048
- * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
1049
- * text: Extract<Children,string> extends never ? false : true
1050
- * }>}
1022
+ * @return {DeltaBuilder<CondensedDeltaConf<null,Attrs,Children>>}
1051
1023
  */
1052
1024
  export function from<Attrs extends {
1053
1025
  [k: string | number]: any;
1054
- } | null, Children extends Array<any> | string = never>(attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<{
1055
- attrs: Attrs extends null ? {} : Attrs;
1056
- children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
1057
- text: Extract<Children, string> extends never ? false : true;
1058
- }>;
1026
+ } | null, Children extends Array<any> | string = never>(attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<null, Attrs, Children>>;
1059
1027
  /**
1060
1028
  * @template {string|null} NodeName
1061
1029
  * @template {{[k:string|number]:any}|null} Attrs
@@ -1064,28 +1032,98 @@ export function from<Attrs extends {
1064
1032
  * @param {NodeName} nodeName
1065
1033
  * @param {Attrs} attrs
1066
1034
  * @param {...Array<Children>} children
1067
- * @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
1068
- * attrs: Attrs extends null ? {} : Attrs,
1069
- * children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
1070
- * text: Extract<Children,string> extends never ? false : true
1071
- * }>}
1035
+ * @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
1072
1036
  */
1073
1037
  export function from<NodeName extends string | null, Attrs extends {
1074
1038
  [k: string | number]: any;
1075
- } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
1076
- name: NodeName;
1077
- } : {}) & {
1078
- attrs: Attrs extends null ? {} : Attrs;
1079
- children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
1080
- text: Extract<Children, string> extends never ? false : true;
1081
- }>;
1039
+ } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
1040
+ /**
1041
+ * Shorthand for `delta.create().insert(..)` — see {@link DeltaBuilder#insert}.
1042
+ *
1043
+ * ## Builder shorthands
1044
+ *
1045
+ * A changeset is written as a chain (see the readme's "condensed vs. builder chain"), and the
1046
+ * `create()` head of that chain carries no information. Every content/attr builder method is
1047
+ * therefore also exported standalone — {@link insert}, {@link modify}, {@link retain},
1048
+ * {@link delete_} (trailing underscore: `delete` is a reserved word),
1049
+ * {@link setAttr}, {@link setAttrs}, {@link deleteAttr}, {@link modifyAttr} — each returning the very
1050
+ * same {@link DeltaBuilder}, so the rest of the chain is unchanged:
1051
+ *
1052
+ * delta.retain(5).delete(6).insert('!') // ⇔ delta.create().retain(5).delete(6).insert('!')
1053
+ * delta.delete_(6) // ⇔ delta.create().delete(6)
1054
+ *
1055
+ * There is deliberately no `format` shorthand: formatting is the second argument of
1056
+ * `insert`/`retain`/`modify` (`delta.retain(5, { bold: true })`). The ambient-context setters
1057
+ * (`useFormats` & co), the mark methods, `apply`/`append`/`rebase` and the terminal methods (`done`,
1058
+ * `toJSON`, ..) are not mirrored — they either say nothing on an empty delta or don't build one.
1059
+ *
1060
+ * Each shorthand is typed by indexing the method off {@link DeltaBuilder}, pinned to `create()`'s
1061
+ * zero-arg overload — so a shorthand and its `create()`-headed equivalent infer the identical conf,
1062
+ * with no re-declared generics to drift. The type arguments must be written out
1063
+ * (`DeltaBuilder<{}, false>['insert']`, not `DeltaBuilder['insert']`): a bare reference to a generic
1064
+ * type in JSDoc resolves its parameters to `any` rather than to the declared defaults, and
1065
+ * `FixedConf = any` satisfies both arms of `insert`'s `FixedConf extends true ? ..` branch, which
1066
+ * collapses the accreted conf.
1067
+ *
1068
+ * @type {DeltaBuilder<{}, false>['insert']}
1069
+ */
1070
+ export const insert: DeltaBuilder<{}, false>["insert"];
1071
+ /**
1072
+ * Shorthand for `delta.create().modify(..)` — see {@link DeltaBuilder#modify} and {@link insert}.
1073
+ *
1074
+ * @type {DeltaBuilder<{}, false>['modify']}
1075
+ */
1076
+ export const modify: DeltaBuilder<{}, false>["modify"];
1077
+ /**
1078
+ * Shorthand for `delta.create().retain(..)` — see {@link DeltaBuilder#retain} and {@link insert}.
1079
+ *
1080
+ * @type {DeltaBuilder<{}, false>['retain']}
1081
+ */
1082
+ export const retain: DeltaBuilder<{}, false>["retain"];
1083
+ /**
1084
+ * Shorthand for `delta.create().delete(..)` — see {@link DeltaBuilder}'s `delete` and {@link insert}.
1085
+ *
1086
+ * Trailing underscore because `delete` is a reserved word: `export const delete` is a syntax error,
1087
+ * and the rename clause that would work at runtime (`export { _delete as delete }`) makes `tsc` 6
1088
+ * emit a duplicated specifier into the `.d.ts` (`export { _delete as delete, _delete as delete }`),
1089
+ * which then fails `npm run check-dist-types` with "Duplicate identifier". The bug is specific to
1090
+ * declaration emit from a `.js` file — the same clause emits correctly from a `.ts` — so it cannot
1091
+ * be worked around in source; re-test it when the TypeScript floor moves.
1092
+ *
1093
+ * @type {DeltaBuilder<{}, false>['delete']}
1094
+ */
1095
+ export const delete_: DeltaBuilder<{}, false>["delete"];
1096
+ /**
1097
+ * Shorthand for `delta.create().setAttr(..)` — see {@link DeltaBuilder#setAttr} and {@link insert}.
1098
+ *
1099
+ * @type {DeltaBuilder<{}, false>['setAttr']}
1100
+ */
1101
+ export const setAttr: DeltaBuilder<{}, false>["setAttr"];
1102
+ /**
1103
+ * Shorthand for `delta.create().setAttrs(..)` — see {@link DeltaBuilder#setAttrs} and {@link insert}.
1104
+ *
1105
+ * @type {DeltaBuilder<{}, false>['setAttrs']}
1106
+ */
1107
+ export const setAttrs: DeltaBuilder<{}, false>["setAttrs"];
1108
+ /**
1109
+ * Shorthand for `delta.create().deleteAttr(..)` — see {@link DeltaBuilder#deleteAttr} and {@link insert}.
1110
+ *
1111
+ * @type {DeltaBuilder<{}, false>['deleteAttr']}
1112
+ */
1113
+ export const deleteAttr: DeltaBuilder<{}, false>["deleteAttr"];
1114
+ /**
1115
+ * Shorthand for `delta.create().modifyAttr(..)` — see {@link DeltaBuilder#modifyAttr} and {@link insert}.
1116
+ *
1117
+ * @type {DeltaBuilder<{}, false>['modifyAttr']}
1118
+ */
1119
+ export const modifyAttr: DeltaBuilder<{}, false>["modifyAttr"];
1082
1120
  export function diff<Conf_1 extends DeltaConf>(d1: Delta<Conf_1>, d2: NoInfer<Delta<Conf_1>>, options?: DiffOptions): Delta<Conf_1>;
1083
1121
  export function inverse<Conf_1 extends DeltaConf>(d: DeltaAny, base: Delta<Conf_1>): Delta<Conf_1>;
1084
1122
  export function diffChangesetWithSeparator(changeset: Array<{
1085
1123
  index: number;
1086
1124
  remove: Array<any>;
1087
1125
  insert: Array<any>;
1088
- }>, separator: RegExp): any[];
1126
+ }>, separator: RegExp, leftmostIndex?: number): any[];
1089
1127
  /**
1090
1128
  * Provenance metadata on a content/attr op: *who/what* inserted, deleted, or formatted it. The canonical
1091
1129
  * shape below is a convention — apply/diff/equality treat attribution as an **opaque** object (never branching
@@ -1268,6 +1306,28 @@ export type ReadDeltaConf<DConfSpec extends ReadableDeltaConf> = [DConfSpec exte
1268
1306
  } ? {
1269
1307
  recursiveChildren: true;
1270
1308
  } : {}))>> : never;
1309
+ /**
1310
+ * The conf produced by the condensed factories ({@link create}'s 3-arg form and {@link from}) -
1311
+ * the whole node declared in one call instead of built up with chained `setAttr`/`insert`. Routed
1312
+ * through {@link DeltaConfOverwrite} - and hence `PrettifyDeltaConf`/`_SanifyDelta` - so a condensed
1313
+ * call yields exactly the conf its `create(name).setAttrs(attrs).insert(children)`
1314
+ * equivalent would: delta-valued attrs/children normalize to `Delta<..>` (not `DeltaBuilder<..>`),
1315
+ * and an unsupplied slot is omitted rather than declared as `children: never` / `text: false`.
1316
+ *
1317
+ * The `[X] extends [never]` bracketing is load-bearing: `Extract<never,Array<any>>` is `never`, and
1318
+ * a bare `never extends Array<infer Ac>` matches with `Ac = never`.
1319
+ */
1320
+ export type CondensedDeltaConf<NodeName_1 extends string | null, Attrs_1 extends {
1321
+ [k: string | number]: any;
1322
+ } | null, Children_1 extends Array<any> | string> = DeltaConfOverwrite<NodeName_1 extends string ? {
1323
+ name: NodeName_1;
1324
+ } : {}, (Attrs_1 extends null ? {} : {
1325
+ attrs: Attrs_1;
1326
+ }) & ([Extract<Children_1, Array<any>>] extends [never] ? {} : (Extract<Children_1, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? {} : {
1327
+ children: Ac;
1328
+ }) : {})) & ([Extract<Children_1, string>] extends [never] ? {} : {
1329
+ text: true;
1330
+ })>;
1271
1331
  export type DiffOptions = {
1272
1332
  /**
1273
1333
  * Predicate deciding when two nodes
@@ -1284,6 +1344,24 @@ export type DiffOptions = {
1284
1344
  * manipulates deltas in place, e.g. a transformer).
1285
1345
  */
1286
1346
  clone?: boolean | undefined;
1347
+ /**
1348
+ * Where the change starts, as a position into `d1`: the
1349
+ * `path`'s numbers are content offsets (the trailing number is the gap the change starts at, in pre-edit
1350
+ * coordinates — the `from` of the editor transaction), string steps descend into attributes; `assoc` and
1351
+ * `attrs` are ignored. Places the first edit there when the content allows it (a wrong hint only shifts
1352
+ * placement, never correctness) — see "The hint" above.
1353
+ */
1354
+ hint?: import("./position.js").Pos | undefined;
1355
+ };
1356
+ /**
1357
+ * Where a lockstep walk of two states stands: the current op of each side and the units of it already
1358
+ * consumed from the walked end.
1359
+ */
1360
+ export type Cursors = {
1361
+ a: ChildrenOpAny | null;
1362
+ ai: number;
1363
+ b: ChildrenOpAny | null;
1364
+ bi: number;
1287
1365
  };
1288
1366
  import * as s from '../schema.js';
1289
1367
  import * as list from '../list.js';
@@ -1,4 +1,4 @@
1
- export function diff(as: Array<string>, bs: Array<string>): Array<{
1
+ export function diff(as: Array<string>, bs: Array<string>, leftmost?: boolean): Array<{
2
2
  index: number;
3
3
  remove: Array<string>;
4
4
  insert: Array<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "1.0.0-rc.29",
3
+ "version": "1.0.0-rc.30",
4
4
  "description": "isomorphic utility functions",
5
5
  "sideEffects": false,
6
6
  "type": "module",