edytor 5.0.0 → 7.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 (137) hide show
  1. package/README.md +3 -3
  2. package/dist/cloudflare/DocumentRoom.d.ts +77 -2
  3. package/dist/cloudflare/DocumentRoom.js +37 -1
  4. package/dist/cloudflare/index.d.ts +1 -1
  5. package/dist/cloudflare/index.js +1 -1
  6. package/dist/cloudflare/room/access.d.ts +6 -1
  7. package/dist/cloudflare/room/access.js +30 -4
  8. package/dist/cloudflare/room/admission.d.ts +11 -0
  9. package/dist/cloudflare/room/admission.js +43 -10
  10. package/dist/cloudflare/room/context.d.ts +73 -76
  11. package/dist/cloudflare/room/context.js +17 -6
  12. package/dist/cloudflare/room/forged.d.ts +1 -1
  13. package/dist/cloudflare/room/forged.js +11 -9
  14. package/dist/cloudflare/room/frames.d.ts +2 -0
  15. package/dist/cloudflare/room/frames.js +2 -0
  16. package/dist/cloudflare/room/presence.js +1 -4
  17. package/dist/cloudflare/room/reseed.d.ts +93 -0
  18. package/dist/cloudflare/room/reseed.js +500 -0
  19. package/dist/cloudflare/room/scheduler.d.ts +1 -1
  20. package/dist/cloudflare/room/scheduler.js +9 -1
  21. package/dist/cloudflare/room/shared.d.ts +10 -0
  22. package/dist/cloudflare/room/shared.js +10 -0
  23. package/dist/cloudflare/room/storage.d.ts +7 -0
  24. package/dist/cloudflare/room/storage.js +33 -1
  25. package/dist/components/Edytor.svelte +18 -3
  26. package/dist/components/Edytor.svelte.d.ts +10 -1
  27. package/dist/components/EdytorRoot.svelte +17 -0
  28. package/dist/components/EdytorRoot.svelte.d.ts +4 -0
  29. package/dist/components/Suggestion.svelte +1 -1
  30. package/dist/crdt/attribution/block.d.ts +3 -0
  31. package/dist/crdt/attribution/block.js +3 -2
  32. package/dist/crdt/doc/history.js +2 -3
  33. package/dist/crdt/doc/ops.d.ts +81 -0
  34. package/dist/crdt/doc/ops.js +1898 -0
  35. package/dist/crdt/doc/suggest.d.ts +6 -2
  36. package/dist/crdt/doc/suggest.js +6 -5
  37. package/dist/crdt/edytor-doc.d.ts +157 -157
  38. package/dist/crdt/edytor-doc.js +15 -43
  39. package/dist/crdt/engine-room.d.ts +4 -0
  40. package/dist/crdt/engine-room.js +6 -0
  41. package/dist/crdt/flow.d.ts +4 -46
  42. package/dist/crdt/flow.js +2 -262
  43. package/dist/crdt/index.d.ts +64 -75
  44. package/dist/crdt/operations.d.ts +1 -1
  45. package/dist/crdt/placement/resolve.d.ts +1 -1
  46. package/dist/crdt/protocol.d.ts +2 -2
  47. package/dist/crdt/protocol.js +2 -2
  48. package/dist/crdt/protocols/auth.d.ts +8 -1
  49. package/dist/crdt/protocols/auth.js +14 -1
  50. package/dist/crdt/protocols/awareness.js +46 -81
  51. package/dist/crdt/providers/index.d.ts +11 -22
  52. package/dist/crdt/providers/index.js +22 -3
  53. package/dist/crdt/providers/indexeddb.d.ts +6 -10
  54. package/dist/crdt/providers/indexeddb.js +10 -16
  55. package/dist/crdt/providers/room.d.ts +26 -0
  56. package/dist/crdt/providers/room.js +41 -12
  57. package/dist/crdt/providers/websocket.d.ts +10 -14
  58. package/dist/crdt/providers/websocket.js +43 -23
  59. package/dist/crdt/rangeDelete.d.ts +2 -47
  60. package/dist/crdt/rangeDelete.js +1 -169
  61. package/dist/crdt/reseed.d.ts +127 -0
  62. package/dist/crdt/reseed.js +533 -0
  63. package/dist/crdt/restore.d.ts +13 -1
  64. package/dist/crdt/restore.js +8 -3
  65. package/dist/crdt/schema.d.ts +6 -0
  66. package/dist/crdt/schema.js +6 -0
  67. package/dist/crdt/structs.d.ts +8 -11
  68. package/dist/crdt/structs.js +25 -44
  69. package/dist/crdt/text/index/build.d.ts +119 -0
  70. package/dist/crdt/text/index/build.js +2801 -0
  71. package/dist/crdt/text/index/shared.d.ts +2 -6
  72. package/dist/crdt/text/index/shared.js +2 -5
  73. package/dist/crdt/text/model.js +2 -3
  74. package/dist/crdt/text/runs.d.ts +9 -12
  75. package/dist/crdt/text/runs.js +2 -165
  76. package/dist/crdt/vendor/yjs/UPSTREAM.md +101 -5
  77. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  78. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +10 -10
  79. package/dist/crdt/vendor/yjs/dts/utils/encoding.d.ts +1 -0
  80. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  81. package/dist/crdt/vendor/yjs/src/structs/Item.js +24 -13
  82. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +12 -10
  83. package/dist/crdt/vendor/yjs/src/utils/encoding.js +42 -1
  84. package/dist/events/domTextOffset.d.ts +2 -0
  85. package/dist/events/domTextOffset.js +8 -0
  86. package/dist/export/forms.d.ts +50 -50
  87. package/dist/index.d.ts +1 -1
  88. package/dist/index.js +1 -1
  89. package/dist/plugins/richtext/RichTextPlugin.svelte +63 -61
  90. package/dist/plugins/richtext/richTextOperations.js +26 -32
  91. package/dist/selection/selection.svelte.d.ts +1 -1
  92. package/dist/selection/selection.svelte.js +87 -106
  93. package/dist/selection/selection.utils.js +5 -8
  94. package/dist/session/commands.js +49 -51
  95. package/dist/session/handles.js +3 -7
  96. package/dist/surface/attributes.d.ts +3 -3
  97. package/dist/surface/attributes.js +2 -2
  98. package/dist/surface/observer.svelte.d.ts +7 -7
  99. package/dist/surface/observer.svelte.js +225 -336
  100. package/dist/surface/projector.svelte.js +2 -2
  101. package/dist/utils.d.ts +5 -0
  102. package/dist/utils.js +7 -0
  103. package/package.json +1 -1
  104. package/dist/crdt/doc/capability.d.ts +0 -56
  105. package/dist/crdt/doc/capability.js +0 -207
  106. package/dist/crdt/doc/content.d.ts +0 -16
  107. package/dist/crdt/doc/content.js +0 -77
  108. package/dist/crdt/doc/delete.d.ts +0 -15
  109. package/dist/crdt/doc/delete.js +0 -84
  110. package/dist/crdt/doc/layout.d.ts +0 -9
  111. package/dist/crdt/doc/layout.js +0 -178
  112. package/dist/crdt/doc/meta.d.ts +0 -19
  113. package/dist/crdt/doc/meta.js +0 -198
  114. package/dist/crdt/doc/moves.d.ts +0 -21
  115. package/dist/crdt/doc/moves.js +0 -274
  116. package/dist/crdt/doc/split-merge.d.ts +0 -10
  117. package/dist/crdt/doc/split-merge.js +0 -179
  118. package/dist/crdt/doc/steps.d.ts +0 -65
  119. package/dist/crdt/doc/steps.js +0 -311
  120. package/dist/crdt/text/index/cache.d.ts +0 -16
  121. package/dist/crdt/text/index/cache.js +0 -175
  122. package/dist/crdt/text/index/claims.d.ts +0 -18
  123. package/dist/crdt/text/index/claims.js +0 -203
  124. package/dist/crdt/text/index/fold.d.ts +0 -21
  125. package/dist/crdt/text/index/fold.js +0 -656
  126. package/dist/crdt/text/index/layout.d.ts +0 -22
  127. package/dist/crdt/text/index/layout.js +0 -258
  128. package/dist/crdt/text/index/placement.d.ts +0 -47
  129. package/dist/crdt/text/index/placement.js +0 -738
  130. package/dist/crdt/text/index/records.d.ts +0 -13
  131. package/dist/crdt/text/index/records.js +0 -139
  132. package/dist/crdt/text/index/report.d.ts +0 -18
  133. package/dist/crdt/text/index/report.js +0 -337
  134. package/dist/crdt/text/index/state.d.ts +0 -197
  135. package/dist/crdt/text/index/state.js +0 -116
  136. package/dist/crdt/text/index/streams.d.ts +0 -25
  137. package/dist/crdt/text/index/streams.js +0 -248
@@ -1,258 +0,0 @@
1
- import { cellKey, LAST_CELL, unlistedCellKey } from '../../placement/keys.js';
2
- import { listedColumns, unlistedRank } from '../../tables.js';
3
- /** The layout rules of one doc's index, over its state. */
4
- export const indexLayout = (ix) => {
5
- const { blocks, kindsOf } = ix;
6
- /** The role of `b`'s stored kind; `undefined` without roles or a record. */
7
- const kindOf = (b) => {
8
- const type = blocks.get(b)?.type;
9
- return ix.roles === null || type === undefined ? undefined : ix.roles.of(type);
10
- };
11
- /** The line kind of `b` when it is an island declared `lines`. */
12
- const lineKind = (b) => kindOf(b)?.line;
13
- /** The item kind of `b` when it is a layout. */
14
- const itemKind = (b) => kindOf(b)?.layout;
15
- /** The row kind of `b` when it is a table (`table.*`). */
16
- const rowKind = (b) => kindOf(b)?.table;
17
- /** `table`'s row kind and that row kind's cell kind, as `[row, cell]`. */
18
- const rowOfTable = (table) => {
19
- const row = ix.roles?.of(table).table;
20
- return row === undefined ? undefined : [row, ix.roles.of(row).child];
21
- };
22
- /** The cell kind of `b` when it is a row of a table kind. */
23
- const cellKind = (b) => ix.rowKinds.get(blocks.get(b)?.type ?? '');
24
- /**
25
- * The column ids of table `table` in their order, each with its
26
- * position (`data.columns[i].id`), or `null` when it is no table or
27
- * holds no `columns` array: its cells then show in their own order.
28
- * Read from the record's data, memoized per data object.
29
- */
30
- const columnsMemo = new WeakMap();
31
- const columnsOf = (table) => {
32
- if (rowKind(table) === undefined)
33
- return null;
34
- const data = blocks.get(table)?.data;
35
- if (data === null || typeof data !== 'object')
36
- return null;
37
- let index = columnsMemo.get(data);
38
- if (index === undefined) {
39
- const ids = listedColumns(data);
40
- columnsMemo.set(data, (index = ids && new Map(ids.map((id, i) => [id, i]))));
41
- }
42
- return index;
43
- };
44
- /** The column a cell names (`data.column`), if any. */
45
- const columnOf = (cell) => {
46
- const c = blocks.get(cell)?.data?.column;
47
- return typeof c === 'string' ? c : undefined;
48
- };
49
- /**
50
- * What of `b`'s data the table rules read, as one key: a table's column
51
- * ids, a cell's column (`''` for any other block). A change of it
52
- * re-places the table's cells.
53
- */
54
- const tableFacts = (b, data) => {
55
- const k = kindsOf.get(b);
56
- if (data === null || typeof data !== 'object')
57
- return '';
58
- if (k?.table)
59
- return JSON.stringify(listedColumns(data));
60
- if (k?.cell) {
61
- const c = data.column;
62
- return typeof c === 'string' ? c : '';
63
- }
64
- return '';
65
- };
66
- /**
67
- * The rank cell `id` displays at in row `row` (`table.columns`): its
68
- * column's position in the table holding the row, so every row shows its
69
- * cells in the table's column order whatever their placements (a key of
70
- * the position, ties by block id); a withdrawn cell of a
71
- * column the table no longer lists after them, its column's place among
72
- * those fixed by its id (`unlistedRank`); any other cell of no listed
73
- * column last (it does not display, `table.cell`).
74
- * `undefined`: no table with columns holds the row — its placement rank.
75
- */
76
- const cellRank = (row, id) => {
77
- const cell = cellKind(row);
78
- if (cell === undefined || blocks.get(id)?.type !== cell)
79
- return undefined;
80
- const table = ix.placementsMap.get(row)?.parent;
81
- const index = typeof table === 'string' ? columnsOf(table) : null;
82
- if (index === null)
83
- return undefined;
84
- const column = columnOf(id);
85
- const at = column === undefined ? undefined : index.get(column);
86
- if (at === undefined && column !== undefined && ix.shells.has(id))
87
- return unlistedCellKey(unlistedRank(column));
88
- return at === undefined ? LAST_CELL : cellKey(at);
89
- };
90
- /**
91
- * The table rules (`table.*`), in the same pass: a cell displays only in
92
- * a row of a table, and, when the table lists its columns, only for a
93
- * listed column — or, withdrawn by an undo while it holds another
94
- * writer's text (`hist.undo.withdraw`), for the column the undo took out
95
- * of the list — and as the first of the row's cells for it
96
- * (`table.cell`); a row displays only in a table and while it shows a
97
- * cell (`table.row`); a table displays while it shows a row
98
- * (`table.empty`). What does not display hands up nothing a table rule
99
- * shows: a cell's text goes with it.
100
- */
101
- const tableVisit = (kids, out, id, ctx, shown) => {
102
- const k = kindsOf.get(id);
103
- const childIds = (kids.get(id) ?? []).map((c) => c.id);
104
- const pass = (sub) => {
105
- out.add(id);
106
- shown.push(...sub.filter((x) => !isTableish(x.id)));
107
- };
108
- if (k.table) {
109
- const sub = dissolveVisit(kids, out, childIds, false, { table: id });
110
- if (sub.some((x) => kindsOf.get(x.id)?.row))
111
- shown.push({ id, kids: sub.map((x) => x.id) });
112
- else
113
- pass(sub);
114
- }
115
- else if (k.row) {
116
- const table = ctx !== null && 'table' in ctx ? ctx.table : null;
117
- const sub = dissolveVisit(kids, out, childIds, false, table === null ? null : { row: id, columns: columnsOf(table), seen: new Set() });
118
- if (table !== null && sub.some((x) => kindsOf.get(x.id)?.cell))
119
- shown.push({ id, kids: sub.map((x) => x.id) });
120
- else
121
- pass(sub);
122
- }
123
- else {
124
- const sub = dissolveVisit(kids, out, childIds, false, null);
125
- const row = ctx !== null && 'row' in ctx ? ctx : null;
126
- let shows = row !== null;
127
- if (row !== null && row.columns !== null) {
128
- const column = columnOf(id);
129
- shows =
130
- column !== undefined &&
131
- (row.columns.has(column) || ix.shells.has(id)) &&
132
- !row.seen.has(column);
133
- if (shows)
134
- row.seen.add(column);
135
- }
136
- if (shows)
137
- shown.push({ id, kids: sub.map((x) => x.id) });
138
- else
139
- pass(sub);
140
- }
141
- };
142
- /** `b`'s kind is a table, a table's row or a row's cell. */
143
- const isTableish = (b) => {
144
- const k = kindsOf.get(b);
145
- return k !== undefined && (k.table || k.row || k.cell);
146
- };
147
- const dissolveVisit = (kids, out, ids, layout, ctx = null) => {
148
- const isItem = (b) => ix.itemKinds.has(blocks.get(b)?.type ?? '');
149
- const shown = [];
150
- for (const id of ids) {
151
- if (isTableish(id)) {
152
- tableVisit(kids, out, id, ctx, shown);
153
- continue;
154
- }
155
- const own = itemKind(id) !== undefined;
156
- const sub = dissolveVisit(kids, out, (kids.get(id) ?? []).map((k) => k.id), own);
157
- if (own) {
158
- if (sub.length > 1)
159
- shown.push({ id, kids: [] });
160
- else {
161
- out.add(id);
162
- for (const k of sub) {
163
- out.add(k.id);
164
- shown.push(...k.kids.map((kid) => ({ id: kid, kids: [] })));
165
- }
166
- }
167
- }
168
- else if (isItem(id) && (!layout || sub.length === 0)) {
169
- out.add(id);
170
- shown.push(...sub);
171
- }
172
- else
173
- shown.push({ id, kids: sub.map((k) => k.id) });
174
- }
175
- return shown;
176
- };
177
- const dissolve = (kids) => {
178
- const out = new Set();
179
- dissolveVisit(kids, out, (kids.get(null) ?? []).map((k) => k.id), false);
180
- return out;
181
- };
182
- /**
183
- * Re-run the layout rules on the layouts `changed` (blocks whose slot
184
- * in `kids0` changed, with their parents) and `kinds` reach: from each
185
- * one up through layouts and items, the topmost such ancestor's
186
- * subtree. Returns the blocks whose dissolved state flipped.
187
- */
188
- const redissolve = (changed, kinds) => {
189
- const flips = new Set();
190
- const isLayoutish = (b) => {
191
- const k = kindsOf.get(b);
192
- return k !== undefined && (k.layout || k.item || k.table || k.row || k.cell);
193
- };
194
- const roots = new Set();
195
- const climb = (b) => {
196
- let top;
197
- for (let x = b; typeof x === 'string' && isLayoutish(x); x = ix.slots0.get(x)?.parent)
198
- top = x;
199
- if (top !== undefined)
200
- roots.add(top);
201
- };
202
- for (const [id, [from, to]] of changed) {
203
- climb(id);
204
- climb(from);
205
- climb(to);
206
- }
207
- for (const id of kinds) {
208
- // Its kind decides its own rule, its parent's count and its children's (`layout`).
209
- climb(id);
210
- climb(ix.slots0.get(id)?.parent);
211
- for (const k of ix.kids0.get(id) ?? [])
212
- climb(k.id);
213
- // Only a layout, an item or a table's block dissolves: one that left those kinds shows again.
214
- if (!isLayoutish(id) && ix.dissolved.delete(id))
215
- flips.add(id);
216
- }
217
- for (const root of roots) {
218
- if (!ix.slots0.has(root))
219
- continue;
220
- const parent = ix.slots0.get(root).parent;
221
- const nodes = [];
222
- const stack = [root];
223
- for (let x = stack.pop(); x !== undefined; x = stack.pop()) {
224
- nodes.push(x);
225
- for (const k of ix.kids0.get(x) ?? [])
226
- stack.push(k.id);
227
- }
228
- const out = new Set();
229
- dissolveVisit(ix.kids0, out, [root], parent !== null && itemKind(parent) !== undefined);
230
- for (const x of nodes) {
231
- if (out.has(x) === ix.dissolved.has(x))
232
- continue;
233
- if (out.has(x))
234
- ix.dissolved.add(x);
235
- else
236
- ix.dissolved.delete(x);
237
- flips.add(x);
238
- }
239
- }
240
- // A block that left the index (hidden, removed) dissolves no more.
241
- for (const id of changed.keys())
242
- if (!ix.slots0.has(id) && ix.dissolved.delete(id))
243
- flips.add(id);
244
- return flips;
245
- };
246
- return {
247
- kindOf,
248
- lineKind,
249
- itemKind,
250
- rowKind,
251
- rowOfTable,
252
- cellKind,
253
- cellRank,
254
- tableFacts,
255
- dissolve,
256
- redissolve
257
- };
258
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * Placements and the children index (maintained), the display
3
- * ownership the display reads (`ownShim`), and THE shown-kind rule
4
- * (`typeOf`).
5
- *
6
- * A structural change re-decides only what it can change: the display
7
- * edge of the blocks whose slot, record or mover changed (fork patch
8
- * YP22), and the display slot of every block whose slot walk
9
- * (`displaySlotOf`) reads one that changed — its stored subtree, through
10
- * the blocks it displays — patched into the parents' child lists. A
11
- * block's candidate edges are its live move records, strongest first, then
12
- * its home slot; it shows at the first that closes no cycle through the
13
- * accepted edges (`settle`): the later move wins, and the block whose edge
14
- * is the oldest of a cycle falls back to its next candidate, back where it
15
- * stood (its previous record, else home; the root's tail only when every
16
- * candidate closes a cycle), so a cycle resolves locally: no global pass.
17
- * The first build places every block the same way (their unique acyclic
18
- * acceptance, whatever the order; the tests' greedy rebuild,
19
- * `src/tests/oracles/placements.ts`, is what the self-checks compare). A
20
- * placed block's order key is found from its sequence neighbours
21
- * (`placement/keys.ts`), never by walking the parent's sequence; a rebuild
22
- * keys every list once, in its sequence's order. The layout rules re-run
23
- * only on the layouts a change reaches.
24
- */
25
- import { type BlockId, type DisplayOwnership, type DocOrder } from '../../placement/model.js';
26
- import { homeOf, type SlotRef } from '../../placement/resolve.js';
27
- import { type Unit } from '../../placement/slots.js';
28
- import type { EngineNode } from '../../engine-api.js';
29
- import type { IndexClaims } from './claims.js';
30
- import type { IndexLayout } from './layout.js';
31
- import type { IndexState } from './state.js';
32
- import type { IndexStreams } from './streams.js';
33
- /** Placement maintenance of one doc's index, over its state, claims, streams and layout rules. */
34
- export declare const indexPlacement: (ix: IndexState & IndexClaims & IndexStreams & IndexLayout) => {
35
- ownShim: DisplayOwnership;
36
- own0: DisplayOwnership;
37
- noteKind: (id: BlockId) => void;
38
- homeFor: (id: BlockId) => ReturnType<typeof homeOf>;
39
- putSlot: (b: BlockId, u: Unit, ref: SlotRef | null) => void;
40
- edgeParent: (id: BlockId) => BlockId | null | undefined;
41
- noteFollowing: (id: BlockId) => void;
42
- ensurePlacements: () => void;
43
- reslot: (node: EngineNode) => void;
44
- typeOf: (id: BlockId) => string;
45
- order: () => DocOrder;
46
- };
47
- export type IndexPlacement = ReturnType<typeof indexPlacement>;