edytor 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +2 -2
  2. package/dist/cloudflare/DocumentRoom.d.ts +13 -9
  3. package/dist/cloudflare/DocumentRoom.js +10 -6
  4. package/dist/cloudflare/room/context.d.ts +27 -26
  5. package/dist/cloudflare/room/context.js +2 -2
  6. package/dist/cloudflare/room/purge.d.ts +6 -3
  7. package/dist/cloudflare/room/purge.js +44 -19
  8. package/dist/cloudflare/room/updates.d.ts +3 -4
  9. package/dist/cloudflare/room/updates.js +6 -8
  10. package/dist/crdt/attribution/attribution.d.ts +31 -12
  11. package/dist/crdt/attribution/attribution.js +56 -18
  12. package/dist/crdt/attribution/block.d.ts +3 -3
  13. package/dist/crdt/attribution/block.js +7 -8
  14. package/dist/crdt/attribution/index.d.ts +1 -1
  15. package/dist/crdt/attribution/index.js +1 -1
  16. package/dist/crdt/data.d.ts +62 -31
  17. package/dist/crdt/data.js +211 -103
  18. package/dist/crdt/doc/delete.d.ts +1 -1
  19. package/dist/crdt/doc/delete.js +13 -30
  20. package/dist/crdt/doc/funnel.js +29 -24
  21. package/dist/crdt/doc/gate.d.ts +3 -3
  22. package/dist/crdt/doc/history.d.ts +25 -9
  23. package/dist/crdt/doc/history.js +150 -40
  24. package/dist/crdt/doc/layout.js +11 -22
  25. package/dist/crdt/doc/meta.js +12 -17
  26. package/dist/crdt/doc/moves.d.ts +1 -1
  27. package/dist/crdt/doc/moves.js +52 -32
  28. package/dist/crdt/doc/reads.js +2 -2
  29. package/dist/crdt/doc/seed.js +2 -2
  30. package/dist/crdt/doc/split-merge.js +12 -15
  31. package/dist/crdt/doc/steps.d.ts +25 -13
  32. package/dist/crdt/doc/steps.js +52 -122
  33. package/dist/crdt/doc/types.d.ts +21 -9
  34. package/dist/crdt/document.d.ts +16 -5
  35. package/dist/crdt/document.js +21 -4
  36. package/dist/crdt/edytor-doc.d.ts +62 -64
  37. package/dist/crdt/edytor-doc.js +18 -13
  38. package/dist/crdt/engine-api.d.ts +33 -1
  39. package/dist/crdt/engine.d.ts +0 -1
  40. package/dist/crdt/engine.js +1 -4
  41. package/dist/crdt/flow.d.ts +1 -1
  42. package/dist/crdt/flow.js +25 -27
  43. package/dist/crdt/index.d.ts +26 -25
  44. package/dist/crdt/index.js +1 -1
  45. package/dist/crdt/placement/display.d.ts +5 -30
  46. package/dist/crdt/placement/display.js +39 -144
  47. package/dist/crdt/placement/keys.d.ts +58 -0
  48. package/dist/crdt/placement/keys.js +90 -0
  49. package/dist/crdt/placement/model.d.ts +119 -118
  50. package/dist/crdt/placement/model.js +242 -142
  51. package/dist/crdt/placement/resolve.d.ts +123 -35
  52. package/dist/crdt/placement/resolve.js +187 -153
  53. package/dist/crdt/placement/slots.d.ts +134 -0
  54. package/dist/crdt/placement/slots.js +152 -0
  55. package/dist/crdt/providers/room.d.ts +16 -2
  56. package/dist/crdt/providers/room.js +64 -17
  57. package/dist/crdt/providers/websocket.js +5 -3
  58. package/dist/crdt/purge.d.ts +17 -8
  59. package/dist/crdt/purge.js +236 -126
  60. package/dist/crdt/restore.d.ts +2 -2
  61. package/dist/crdt/restore.js +18 -34
  62. package/dist/crdt/schema.d.ts +22 -21
  63. package/dist/crdt/schema.js +29 -23
  64. package/dist/crdt/storage.d.ts +1 -1
  65. package/dist/crdt/storage.js +1 -1
  66. package/dist/crdt/structs.d.ts +15 -15
  67. package/dist/crdt/structs.js +8 -22
  68. package/dist/crdt/text/index/cache.js +4 -0
  69. package/dist/crdt/text/index/claims.js +12 -0
  70. package/dist/crdt/text/index/fold.d.ts +2 -3
  71. package/dist/crdt/text/index/fold.js +194 -44
  72. package/dist/crdt/text/index/layout.js +5 -8
  73. package/dist/crdt/text/index/placement.d.ts +26 -18
  74. package/dist/crdt/text/index/placement.js +404 -138
  75. package/dist/crdt/text/index/records.d.ts +3 -3
  76. package/dist/crdt/text/index/records.js +24 -31
  77. package/dist/crdt/text/index/shared.d.ts +11 -3
  78. package/dist/crdt/text/index/shared.js +12 -3
  79. package/dist/crdt/text/index/state.d.ts +21 -17
  80. package/dist/crdt/text/index/state.js +15 -17
  81. package/dist/crdt/text/index/streams.d.ts +10 -5
  82. package/dist/crdt/text/index/streams.js +78 -27
  83. package/dist/crdt/text/items.d.ts +10 -3
  84. package/dist/crdt/text/items.js +7 -0
  85. package/dist/crdt/text/model.d.ts +77 -62
  86. package/dist/crdt/text/model.js +84 -169
  87. package/dist/crdt/text/ranges.d.ts +1 -1
  88. package/dist/crdt/text/ranges.js +3 -3
  89. package/dist/crdt/text/rows.d.ts +13 -7
  90. package/dist/crdt/text/rows.js +24 -7
  91. package/dist/crdt/text/runs.d.ts +17 -12
  92. package/dist/crdt/text/runs.js +24 -7
  93. package/dist/crdt/text/streams.d.ts +26 -13
  94. package/dist/crdt/text/streams.js +41 -14
  95. package/dist/crdt/vendor/yjs/UPSTREAM.md +568 -21
  96. package/dist/crdt/vendor/yjs/dts/global.d.ts +2 -0
  97. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  98. package/dist/crdt/vendor/yjs/dts/structs/AbstractStruct.d.ts +7 -0
  99. package/dist/crdt/vendor/yjs/dts/structs/Item.d.ts +194 -10
  100. package/dist/crdt/vendor/yjs/dts/utils/Doc.d.ts +6 -3
  101. package/dist/crdt/vendor/yjs/dts/utils/StructStore.d.ts +5 -18
  102. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +15 -1
  103. package/dist/crdt/vendor/yjs/dts/utils/UpdateDecoder.d.ts +14 -6
  104. package/dist/crdt/vendor/yjs/dts/utils/UpdateEncoder.d.ts +33 -6
  105. package/dist/crdt/vendor/yjs/dts/utils/ids.d.ts +1 -65
  106. package/dist/crdt/vendor/yjs/dts/utils/marks.d.ts +6 -1
  107. package/dist/crdt/vendor/yjs/dts/ynode.d.ts +43 -7
  108. package/dist/crdt/vendor/yjs/global.d.ts +2 -0
  109. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  110. package/dist/crdt/vendor/yjs/src/structs/AbstractStruct.js +10 -0
  111. package/dist/crdt/vendor/yjs/src/structs/Item.js +610 -51
  112. package/dist/crdt/vendor/yjs/src/utils/BlockSet.js +18 -9
  113. package/dist/crdt/vendor/yjs/src/utils/Doc.js +5 -3
  114. package/dist/crdt/vendor/yjs/src/utils/StructStore.js +5 -0
  115. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +36 -13
  116. package/dist/crdt/vendor/yjs/src/utils/UpdateDecoder.js +88 -18
  117. package/dist/crdt/vendor/yjs/src/utils/UpdateEncoder.js +119 -32
  118. package/dist/crdt/vendor/yjs/src/utils/encoding.js +13 -1
  119. package/dist/crdt/vendor/yjs/src/utils/ids.js +7 -7
  120. package/dist/crdt/vendor/yjs/src/utils/marks.js +193 -8
  121. package/dist/crdt/vendor/yjs/src/utils/redo.js +1 -1
  122. package/dist/crdt/vendor/yjs/src/utils/transaction-helpers.js +1 -1
  123. package/dist/crdt/vendor/yjs/src/utils/updates.js +3 -3
  124. package/dist/crdt/vendor/yjs/src/ynode.js +177 -12
  125. package/dist/edytor.svelte.js +4 -1
  126. package/dist/events/beforeInputCommands.js +2 -2
  127. package/dist/events/onPageHide.d.ts +3 -0
  128. package/dist/events/onPageHide.js +16 -0
  129. package/dist/export/forms.d.ts +25 -25
  130. package/dist/surface/observer.svelte.js +2 -2
  131. package/dist/surface/projector.svelte.d.ts +15 -3
  132. package/dist/surface/projector.svelte.js +59 -8
  133. package/package.json +2 -2
  134. package/dist/crdt/placement/rank.d.ts +0 -87
  135. package/dist/crdt/placement/rank.js +0 -332
  136. package/dist/crdt/placement/source.d.ts +0 -43
  137. package/dist/crdt/placement/source.js +0 -66
  138. package/dist/crdt/text/delete-index.d.ts +0 -129
  139. package/dist/crdt/text/delete-index.js +0 -365
  140. package/dist/crdt/text/deletes.d.ts +0 -76
  141. package/dist/crdt/text/deletes.js +0 -362
  142. package/dist/crdt/text/index/anchored.d.ts +0 -17
  143. package/dist/crdt/text/index/anchored.js +0 -197
@@ -5,7 +5,7 @@
5
5
  * facade module.
6
6
  */
7
7
  import type { EngineNode } from './engine-api.js';
8
- /** A replicated value that is a node (a block, its content, claims or `at` map, an atom). */
8
+ /** A replicated value that is a node (a block, its content, an atom). */
9
9
  export declare const isNodeLike: (v: unknown) => v is EngineNode;
10
10
  /** Flat block registry root: blockId → node('block') (`SCHEMA.roots.registry`). */
11
11
  export declare const REGISTRY_KEY = "blocks";
@@ -13,21 +13,19 @@ export declare const REGISTRY_KEY = "blocks";
13
13
  export declare const META_ROOT_KEY = "meta";
14
14
  /** Attribution metadata root (`SCHEMA.roots.attribution`). */
15
15
  export declare const ATTRIBUTION_ROOT = "attribution";
16
- /** The per-block attribution root — `b/<blockId>` records (`SCHEMA.roots.blockAttribution`). */
17
- export declare const BLOCK_ATTR_ROOT = "blockattr";
18
16
  /**
19
- * Per-writer text delete marks (`text/deletes.ts`): one record per text
20
- * delete, naming the characters it deleted; its writer is the record's
21
- * engine client. In the history's scope, so an undo removes the undoer's
22
- * own mark and a redo writes it again.
17
+ * The per-block attribution root — one record per block, keyed by the block's
18
+ * id (`SCHEMA.roots.blockAttribution`): the string table writes the id once
19
+ * for its registry entry and its record (fork patch YP24).
23
20
  */
24
- export declare const TEXT_DELETES_ROOT = "textdel";
21
+ export declare const BLOCK_ATTR_ROOT = "blockattr";
25
22
  /**
26
- * Restoration records (`text/deletes.ts`): which characters an undo's copies
27
- * restore, one attr per record (keyed by its writer and clock). Outside the
28
- * history's scope: a record is never removed.
23
+ * The text hold records (fork patch YP20): a text delete appends one record
24
+ * naming the characters it hides; its writer is the record's engine client.
25
+ * A character shows while no live record holds it. In the history's scope,
26
+ * so an undo deletes the undoer's own record and a redo writes it again.
29
27
  */
30
- export declare const RESTORED_ROOT = "restored";
28
+ export declare const TEXT_DELETES_ROOT = "textdel";
31
29
  /**
32
30
  * The document's own data (`crdt/data.ts`): its leaves, as a block's. In the
33
31
  * history's scope.
@@ -41,13 +39,21 @@ export declare const DOC_DATA_ROOT = "docdata";
41
39
  */
42
40
  export declare const HORIZON_ROOT = "horizon";
43
41
  export declare const HORIZON_ATTR = "h";
42
+ /**
43
+ * The ended histories (`hist.release.end`): a list of release records, one
44
+ * item per session whose history ended (its page left for good). A
45
+ * record's engine id names its writer and the clock it ended at: what that
46
+ * writer deleted before it (its delete and withdraw marks, its text hold
47
+ * records) no history can bring back, so the room's purge removes it at
48
+ * its next tick, past the horizon or not. The purge drops a record the
49
+ * horizon covers.
50
+ */
51
+ export declare const RELEASE_ROOT = "released";
44
52
  /** Named node roles (`SCHEMA.nodes`). */
45
53
  export declare const BLOCK_NODE = "block";
46
54
  export declare const CONTENT_NODE = "content";
47
- export declare const CLAIMS_NODE = "claims";
48
- export declare const AT_NODE = "at";
49
55
  export declare const INLINE_NODE = "inline";
50
- /** Attr keys on a block node (`SCHEMA.blockAttrs`). */
56
+ /** Attr keys on a block node (`SCHEMA.blockAttrs`); `id` is an atom's own (a block's id is its registry key). */
51
57
  export declare const ID = "id";
52
58
  export declare const TYPE = "type";
53
59
  /** A block's or atom's whole data, as documents before 0.1.0-next.6 stored it: no longer read; the room's purge deletes it. */
@@ -84,14 +90,9 @@ export declare const hasWithdrawMark: (node: {
84
90
  /** The per-block `lastChangedBy` LWW attr (`SCHEMA.blockAttrs.lastChanged`). */
85
91
  export declare const LAST_CHANGED_ATTR = "l";
86
92
  export declare const CONTENT = "content";
87
- /** Ordered merge claims `{m: blockId}`. */
88
- export declare const CLAIMS = "claims";
89
- export declare const AT = "at";
90
- /** `b/<blockId>` record-key prefix on the `blockattr` root. */
91
- export declare const REC_PREFIX = "b/";
92
93
  /** The schema generation stamped on the `meta` root (`v`) and its manifest name (`schema`). */
93
94
  export declare const SCHEMA: {
94
- readonly version: 6;
95
+ readonly version: 10;
95
96
  readonly name: "edytor-doc";
96
97
  readonly roots: {
97
98
  readonly registry: "blocks";
@@ -1,4 +1,4 @@
1
- /** A replicated value that is a node (a block, its content, claims or `at` map, an atom). */
1
+ /** A replicated value that is a node (a block, its content, an atom). */
2
2
  export const isNodeLike = (v) => v != null && typeof v.getAttr === 'function';
3
3
  /** Flat block registry root: blockId → node('block') (`SCHEMA.roots.registry`). */
4
4
  export const REGISTRY_KEY = 'blocks';
@@ -6,21 +6,19 @@ export const REGISTRY_KEY = 'blocks';
6
6
  export const META_ROOT_KEY = 'meta';
7
7
  /** Attribution metadata root (`SCHEMA.roots.attribution`). */
8
8
  export const ATTRIBUTION_ROOT = 'attribution';
9
- /** The per-block attribution root — `b/<blockId>` records (`SCHEMA.roots.blockAttribution`). */
10
- export const BLOCK_ATTR_ROOT = 'blockattr';
11
9
  /**
12
- * Per-writer text delete marks (`text/deletes.ts`): one record per text
13
- * delete, naming the characters it deleted; its writer is the record's
14
- * engine client. In the history's scope, so an undo removes the undoer's
15
- * own mark and a redo writes it again.
10
+ * The per-block attribution root — one record per block, keyed by the block's
11
+ * id (`SCHEMA.roots.blockAttribution`): the string table writes the id once
12
+ * for its registry entry and its record (fork patch YP24).
16
13
  */
17
- export const TEXT_DELETES_ROOT = 'textdel';
14
+ export const BLOCK_ATTR_ROOT = 'blockattr';
18
15
  /**
19
- * Restoration records (`text/deletes.ts`): which characters an undo's copies
20
- * restore, one attr per record (keyed by its writer and clock). Outside the
21
- * history's scope: a record is never removed.
16
+ * The text hold records (fork patch YP20): a text delete appends one record
17
+ * naming the characters it hides; its writer is the record's engine client.
18
+ * A character shows while no live record holds it. In the history's scope,
19
+ * so an undo deletes the undoer's own record and a redo writes it again.
22
20
  */
23
- export const RESTORED_ROOT = 'restored';
21
+ export const TEXT_DELETES_ROOT = 'textdel';
24
22
  /**
25
23
  * The document's own data (`crdt/data.ts`): its leaves, as a block's. In the
26
24
  * history's scope.
@@ -34,13 +32,21 @@ export const DOC_DATA_ROOT = 'docdata';
34
32
  */
35
33
  export const HORIZON_ROOT = 'horizon';
36
34
  export const HORIZON_ATTR = 'h';
35
+ /**
36
+ * The ended histories (`hist.release.end`): a list of release records, one
37
+ * item per session whose history ended (its page left for good). A
38
+ * record's engine id names its writer and the clock it ended at: what that
39
+ * writer deleted before it (its delete and withdraw marks, its text hold
40
+ * records) no history can bring back, so the room's purge removes it at
41
+ * its next tick, past the horizon or not. The purge drops a record the
42
+ * horizon covers.
43
+ */
44
+ export const RELEASE_ROOT = 'released';
37
45
  /** Named node roles (`SCHEMA.nodes`). */
38
46
  export const BLOCK_NODE = 'block';
39
47
  export const CONTENT_NODE = 'content';
40
- export const CLAIMS_NODE = 'claims';
41
- export const AT_NODE = 'at';
42
48
  export const INLINE_NODE = 'inline';
43
- /** Attr keys on a block node (`SCHEMA.blockAttrs`). */
49
+ /** Attr keys on a block node (`SCHEMA.blockAttrs`); `id` is an atom's own (a block's id is its registry key). */
44
50
  export const ID = 'id';
45
51
  export const TYPE = 'type';
46
52
  /** A block's or atom's whole data, as documents before 0.1.0-next.6 stored it: no longer read; the room's purge deletes it. */
@@ -73,16 +79,16 @@ export const hasWithdrawMark = (node) => [...node.attrKeys()].some((key) => key.
73
79
  /** The per-block `lastChangedBy` LWW attr (`SCHEMA.blockAttrs.lastChanged`). */
74
80
  export const LAST_CHANGED_ATTR = 'l';
75
81
  export const CONTENT = 'content';
76
- /** Ordered merge claims `{m: blockId}`. */
77
- export const CLAIMS = 'claims';
78
- export const AT = 'at';
79
- /** `b/<blockId>` record-key prefix on the `blockattr` root. */
80
- export const REC_PREFIX = 'b/';
81
82
  /** The schema generation stamped on the `meta` root (`v`) and its manifest name (`schema`). */
82
83
  export const SCHEMA = {
83
- // 6: one update encoding (the columnar one) on the wire and in storage;
84
- // a container or frame of an earlier generation is refused.
85
- version: 6,
84
+ // 7: a text delete is a hold record (fork patch YP20) on the wire and in
85
+ // storage; 8: a merge claim is an item `{m}` in a backing text (fork patch
86
+ // YP21), a block has no `claims` list; 9: a block's place is its home slot
87
+ // in its parent's sequence and a move is a move record (fork patch YP22),
88
+ // a block has no `at` map and an array item no rank; 10: the update encoding
89
+ // writes each distinct string once (fork patch YP24). A container or frame
90
+ // of an earlier generation is refused.
91
+ version: 10,
86
92
  name: 'edytor-doc',
87
93
  roots: { registry: REGISTRY_KEY, meta: META_ROOT_KEY },
88
94
  metaAttrs: { version: 'v', schema: 'schema' }
@@ -4,7 +4,7 @@
4
4
  * when that makes them smaller (`CompressionStream`, in every supported
5
5
  * browser, Node and Workers). A compressed record starts with gzip's magic
6
6
  * `1f 8b`, which no update does (its first byte is the encoder's feature
7
- * flag, `00`), so a record says itself whether it is compressed.
7
+ * flag, the encoding: `01`), so a record says itself whether it is compressed.
8
8
  * Worker-safe: no timers.
9
9
  */
10
10
  /** Whether `bytes` are gzip (its magic `1f 8b`). */
@@ -4,7 +4,7 @@
4
4
  * when that makes them smaller (`CompressionStream`, in every supported
5
5
  * browser, Node and Workers). A compressed record starts with gzip's magic
6
6
  * `1f 8b`, which no update does (its first byte is the encoder's feature
7
- * flag, `00`), so a record says itself whether it is compressed.
7
+ * flag, the encoding: `01`), so a record says itself whether it is compressed.
8
8
  * Worker-safe: no timers.
9
9
  */
10
10
  /** Whether `bytes` are gzip (its magic `1f 8b`). */
@@ -24,6 +24,16 @@ export type StoreStruct = {
24
24
  client: number;
25
25
  clock: number;
26
26
  } | null;
27
+ /** Live hold records naming the item (fork patch YP20): a held item reads as deleted. */
28
+ holds?: number;
29
+ /** Whether the engine deleted it (`deleted` also covers a held or moved item). */
30
+ removed?: boolean;
31
+ /** Removed or held: shown nowhere (fork patch YP22; a moved item shows at its mover). */
32
+ gone?: boolean;
33
+ /** The live move records naming the item (fork patch YP22), `null` at home. */
34
+ movers?: StoreStruct[] | null;
35
+ /** The record that shows the item (the greatest `(priority, client, clock)` of `movers`). */
36
+ mover?: StoreStruct | null;
27
37
  };
28
38
  /**
29
39
  * The engine's IdSet shape (insertSet/deleteSet): per-client range lists —
@@ -85,8 +95,6 @@ export declare const followRedone: (Y: EngineApi, doc: EngineDoc, id: {
85
95
  * drops them the same way after a pop.
86
96
  */
87
97
  export declare const dropSearchMarkers: (node: unknown) => void;
88
- /** The clock `client`'s next struct gets in `doc`. */
89
- export declare const nextClock: (doc: EngineDoc, client: number) => number;
90
98
  /**
91
99
  * Whether `doc` holds updates it cannot integrate yet (vendor-internal
92
100
  * `store.pendingStructs`/`pendingDs`): an out-of-order delivery can apply
@@ -141,6 +149,11 @@ export type StoreLike = {
141
149
  };
142
150
  /** The doc's struct store (vendor `store`). */
143
151
  export declare const storeOf: (doc: EngineDoc | YDoc) => StoreLike;
152
+ /**
153
+ * Whether `doc` holds every id `client:clock … clock+len-1` (none past its
154
+ * clock, none in a gap the engine fills later: vendor `store.skips`).
155
+ */
156
+ export declare const holdsIds: (doc: EngineDoc, client: number, clock: number, len: number) => boolean;
144
157
  /** Whether `doc` collects deleted content at all (vendor `gc`). */
145
158
  export declare const collects: (doc: EngineDoc | YDoc) => boolean;
146
159
  /** Whether `doc`'s collection filter lets it collect `item` (vendor `gcFilter`). */
@@ -156,11 +169,6 @@ export declare const keepFromCollection: <I = StoreStruct>(doc: EngineDoc | YDoc
156
169
  * {@link collects} and {@link collectable}.
157
170
  */
158
171
  export declare const collectNow: (item: object, tr: unknown) => void;
159
- /**
160
- * Listen to `doc`'s transaction events (vendor `beforeTransaction`,
161
- * `afterTransaction`), with the caller's view of a transaction.
162
- */
163
- export declare const onTransaction: <T>(doc: EngineDoc | YDoc, event: "beforeTransaction" | "afterTransaction", f: (tr: T) => void) => void;
164
172
  /**
165
173
  * Whether a transaction changed one of `nodes` or a node under one: its
166
174
  * `changed` types and their ancestors (what a deep observer of `nodes`
@@ -189,8 +197,6 @@ export declare const engineOps: (Y: EngineApi) => {
189
197
  insertInto: (into: IdSetLike, from: IdSetLike) => void;
190
198
  /** Each struct `ids` covers, split at its edges, inside `tr`. */
191
199
  iterate: <I = StoreStruct>(tr: unknown, ids: IdSetLike, f: (item: I) => void) => void;
192
- /** The item starting at `client:clock`, split there, inside `tr`. */
193
- cleanStart: <I = StoreStruct>(tr: unknown, client: number, clock: number) => I;
194
200
  /**
195
201
  * Re-create deleted `item` (`redoItem`, fork patch YP18): its copy, or
196
202
  * `null` when it cannot come back. `items` are re-created with it (a
@@ -217,12 +223,6 @@ export declare const engineOps: (Y: EngineApi) => {
217
223
  /** Listen to a doc event (vendor `on`/`off`), with the caller's view of its arguments. */
218
224
  on: (doc: EngineDoc, event: string, f: (...args: never[]) => void) => void;
219
225
  off: (doc: EngineDoc, event: string, f: (...args: never[]) => void) => void;
220
- /**
221
- * Integrate a new item holding `content` right after `left` (its
222
- * origin: `left`'s last id) in `parent`, written by `client` at
223
- * `clock`, inside `tr`.
224
- */
225
- appendAfter: (tr: unknown, left: StoreStruct, parent: EngineNode, client: number, clock: number, content: unknown[]) => void;
226
226
  /** Whether `item` is a node value a concurrent write replaced and its doc keeps. */
227
227
  isKeptReplaced: (item: unknown) => boolean;
228
228
  };
@@ -121,12 +121,6 @@ export const dropSearchMarkers = (node) => {
121
121
  if (markers)
122
122
  markers.length = 0;
123
123
  };
124
- /** The clock `client`'s next struct gets in `doc`. */
125
- export const nextClock = (doc, client) => {
126
- const structs = clientsOf(doc).get(client);
127
- const last = structs?.[structs.length - 1];
128
- return last === undefined ? 0 : last.id.clock + last.length;
129
- };
130
124
  /**
131
125
  * Whether `doc` holds updates it cannot integrate yet (vendor-internal
132
126
  * `store.pendingStructs`/`pendingDs`): an out-of-order delivery can apply
@@ -177,6 +171,14 @@ export const sequenceLength = (node) => node._length;
177
171
  export const itemOf = (node) => node._item;
178
172
  /** The doc's struct store (vendor `store`). */
179
173
  export const storeOf = (doc) => doc.store;
174
+ /**
175
+ * Whether `doc` holds every id `client:clock … clock+len-1` (none past its
176
+ * clock, none in a gap the engine fills later: vendor `store.skips`).
177
+ */
178
+ export const holdsIds = (doc, client, clock, len) => {
179
+ const store = doc;
180
+ return (clock + len <= store.store.getClock(client) && !store.store.skips.intersects(client, clock, len));
181
+ };
180
182
  /** Whether `doc` collects deleted content at all (vendor `gc`). */
181
183
  export const collects = (doc) => doc.gc;
182
184
  /** Whether `doc`'s collection filter lets it collect `item` (vendor `gcFilter`). */
@@ -196,11 +198,6 @@ export const keepFromCollection = (doc, keep) => {
196
198
  * {@link collects} and {@link collectable}.
197
199
  */
198
200
  export const collectNow = (item, tr) => item.gc(tr, false);
199
- /**
200
- * Listen to `doc`'s transaction events (vendor `beforeTransaction`,
201
- * `afterTransaction`), with the caller's view of a transaction.
202
- */
203
- export const onTransaction = (doc, event, f) => doc.on(event, f);
204
201
  /**
205
202
  * Whether a transaction changed one of `nodes` or a node under one: its
206
203
  * `changed` types and their ancestors (what a deep observer of `nodes`
@@ -229,8 +226,6 @@ export const engineOps = (Y) => {
229
226
  insertInto: (into, from) => Y.insertIntoIdSet(into, from),
230
227
  /** Each struct `ids` covers, split at its edges, inside `tr`. */
231
228
  iterate: (tr, ids, f) => Y.iterateStructsByIdSet(tr, ids, f),
232
- /** The item starting at `client:clock`, split there, inside `tr`. */
233
- cleanStart: (tr, client, clock) => Y.getItemCleanStart(tr, Y.createID(client, clock)),
234
229
  /**
235
230
  * Re-create deleted `item` (`redoItem`, fork patch YP18): its copy, or
236
231
  * `null` when it cannot come back. `items` are re-created with it (a
@@ -262,15 +257,6 @@ export const engineOps = (Y) => {
262
257
  /** Listen to a doc event (vendor `on`/`off`), with the caller's view of its arguments. */
263
258
  on: (doc, event, f) => doc.on(event, f),
264
259
  off: (doc, event, f) => doc.off(event, f),
265
- /**
266
- * Integrate a new item holding `content` right after `left` (its
267
- * origin: `left`'s last id) in `parent`, written by `client` at
268
- * `clock`, inside `tr`.
269
- */
270
- appendAfter: (tr, left, parent, client, clock, content) => {
271
- const item = new Y.Item(Y.createID(client, clock), left, left.lastId, null, null, asYNode(parent), null, new Y.ContentAny(content));
272
- item.integrate(tr, 0);
273
- },
274
260
  /** Whether `item` is a node value a concurrent write replaced and its doc keeps. */
275
261
  isKeptReplaced: (item) => Y.isKeptReplaced(item)
276
262
  };
@@ -32,12 +32,16 @@ export const indexCache = (ix) => {
32
32
  get foldedStructs() {
33
33
  return foldStats.structs;
34
34
  },
35
+ get placements() {
36
+ return foldStats.placed;
37
+ },
35
38
  reset() {
36
39
  debug.recomputes = 0;
37
40
  debug.recomputed.clear();
38
41
  foldStats.folds = 0;
39
42
  foldStats.pairs = 0;
40
43
  foldStats.structs = 0;
44
+ foldStats.placed = 0;
41
45
  rangeStats.items = 0;
42
46
  rangeStats.markers = 0;
43
47
  }
@@ -117,6 +117,7 @@ export const indexClaims = (ix) => {
117
117
  // The tops a seed's claims (now, and those it dropped: noted in `claimersOf` changes) decide.
118
118
  const affected = new Set();
119
119
  const stack = [];
120
+ const seeds = [...ownerSeeds];
120
121
  for (const x of ownerSeeds) {
121
122
  stack.push(x);
122
123
  for (const m of claimTargets.get(x) ?? [])
@@ -150,6 +151,17 @@ export const indexClaims = (ix) => {
150
151
  setDisplay(x, was, now);
151
152
  ownerChanged.add(x);
152
153
  }
154
+ // A holder whose claims changed re-slots what shows through them: their
155
+ // order among its claims is the key of the blocks shown under it
156
+ // (`claimedRank`) — under its owner when it is itself merged away.
157
+ for (const x of seeds) {
158
+ if (!blocks.has(x))
159
+ continue;
160
+ ownerChanged.add(x);
161
+ const o = owners.get(x);
162
+ if (typeof o === 'string' && o !== x)
163
+ ownerChanged.add(o);
164
+ }
153
165
  };
154
166
  /** The claims each seed held before its record changed (their tops are re-decided too). */
155
167
  const claimTargets = new Map();
@@ -1,6 +1,5 @@
1
- import { type BlockId } from '../../placement/model.js';
1
+ import type { BlockId } from '../../placement/model.js';
2
2
  import type { ContentRun } from '../runs.js';
3
- import type { IndexAnchored } from './anchored.js';
4
3
  import type { IndexCache } from './cache.js';
5
4
  import type { IndexClaims } from './claims.js';
6
5
  import type { IndexPlacement } from './placement.js';
@@ -9,7 +8,7 @@ import type { FoldCtx, IndexState, Tx } from './state.js';
9
8
  import type { IndexStreams } from './streams.js';
10
9
  import type { IndexLayout } from './layout.js';
11
10
  /** The fold of one doc's index, over every part it folds into. */
12
- export declare const indexFold: (ix: IndexState & IndexClaims & IndexStreams & IndexAnchored & IndexLayout & IndexPlacement & IndexRecords & IndexCache) => {
11
+ export declare const indexFold: (ix: IndexState & IndexClaims & IndexStreams & IndexLayout & IndexPlacement & IndexRecords & IndexCache) => {
13
12
  runs: (b: BlockId) => readonly ContentRun[];
14
13
  settle: (affected: Iterable<BlockId>, ctx: FoldCtx | null) => void;
15
14
  syncPending: (tr: Tx | null | undefined) => boolean;