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,203 +0,0 @@
1
- import { DEAD, cmpStamp } from '../model.js';
2
- import { addTo, dropFrom } from './shared.js';
3
- /** The claim graph of one doc's index, over its state. */
4
- export const indexClaims = (ix) => {
5
- const { blocks, listConsumers, displaysMap, ownerSeeds, ownerChanged } = ix;
6
- // ── the claim graph (maintained) ─────────────────────────────
7
- // `top(m)` is the max-stamp claim on `m` held by a live block; each
8
- // block's owner follows `top` up (`claimGraph`). A structural change
9
- // of a block (its claims, its delete mark, its record) re-decides the
10
- // `top` of the blocks it claims (before and after) and the owners of
11
- // those blocks and of every block whose `top` chain reaches them —
12
- // never the whole graph.
13
- const owners = new Map();
14
- const topOf = new Map();
15
- /** Claimer → the blocks it tops. */
16
- const topInv = new Map();
17
- /** Claimed block → the blocks whose claims list names it (live or not). */
18
- const claimersOf = new Map();
19
- /** The max-stamp claim on `m` held by a live block. */
20
- const topClaim = (m) => {
21
- let best;
22
- for (const holder of claimersOf.get(m) ?? []) {
23
- const rec = blocks.get(holder);
24
- if (rec === undefined || rec.deleted)
25
- continue;
26
- for (const c of rec.claims)
27
- if (c.m === m && (best === undefined || cmpStamp(c.stamp, best.stamp) > 0))
28
- best = { claimer: holder, stamp: c.stamp };
29
- }
30
- return best;
31
- };
32
- const setTop = (m, t) => {
33
- const old = topOf.get(m);
34
- if (old?.claimer === t?.claimer && (old === undefined || cmpStamp(old.stamp, t.stamp) === 0))
35
- return false;
36
- if (old !== undefined)
37
- dropFrom(topInv, old.claimer, m);
38
- if (t === undefined)
39
- topOf.delete(m);
40
- else {
41
- topOf.set(m, t);
42
- addTo(topInv, t.claimer, m);
43
- }
44
- return true;
45
- };
46
- /** `owner(b)` along `top` (`claimGraph`'s walk), memoized into `owners`. */
47
- const walkOwner = (b) => {
48
- const path = [];
49
- let cur = b;
50
- let result;
51
- for (;;) {
52
- const known = owners.get(cur);
53
- if (known !== undefined) {
54
- result = known;
55
- break;
56
- }
57
- const rec = blocks.get(cur);
58
- if (!rec || rec.deleted) {
59
- result = DEAD;
60
- break;
61
- }
62
- const at = path.indexOf(cur);
63
- if (at >= 0) {
64
- let best = topOf.get(path[at]);
65
- for (const member of path.slice(at)) {
66
- const t = topOf.get(member);
67
- if (cmpStamp(t.stamp, best.stamp) > 0)
68
- best = t;
69
- }
70
- result = best.claimer;
71
- break;
72
- }
73
- const t = topOf.get(cur);
74
- if (t === undefined) {
75
- result = cur;
76
- break;
77
- }
78
- path.push(cur);
79
- cur = t.claimer;
80
- }
81
- if (blocks.has(cur))
82
- owners.set(cur, result);
83
- for (const x of path)
84
- owners.set(x, result);
85
- };
86
- const setDisplay = (b, from, to) => {
87
- if (typeof from === 'string')
88
- dropFrom(displaysMap, from, b);
89
- if (typeof to === 'string')
90
- addTo(displaysMap, to, b);
91
- };
92
- const ensureOwners = () => {
93
- if (ownerSeeds.size === 0)
94
- return;
95
- // The tops a seed's claims (now, and those it dropped: noted in `claimersOf` changes) decide.
96
- const affected = new Set();
97
- const stack = [];
98
- const seeds = [...ownerSeeds];
99
- for (const x of ownerSeeds) {
100
- stack.push(x);
101
- for (const m of claimTargets.get(x) ?? [])
102
- if (setTop(m, topClaim(m)))
103
- stack.push(m);
104
- for (const c of blocks.get(x)?.claims ?? [])
105
- if (setTop(c.m, topClaim(c.m)))
106
- stack.push(c.m);
107
- }
108
- ownerSeeds.clear();
109
- claimTargets.clear();
110
- for (let x = stack.pop(); x !== undefined; x = stack.pop()) {
111
- if (affected.has(x))
112
- continue;
113
- affected.add(x);
114
- for (const m of topInv.get(x) ?? [])
115
- stack.push(m);
116
- }
117
- const before = new Map();
118
- for (const x of affected) {
119
- before.set(x, owners.get(x));
120
- owners.delete(x);
121
- }
122
- for (const x of affected)
123
- if (blocks.has(x))
124
- walkOwner(x);
125
- for (const [x, was] of before) {
126
- const now = owners.get(x);
127
- if (now === was)
128
- continue;
129
- setDisplay(x, was, now);
130
- ownerChanged.add(x);
131
- }
132
- // A holder whose claims changed re-slots what shows through them: their
133
- // order among its claims is the key of the blocks shown under it
134
- // (`claimedRank`) — under its owner when it is itself merged away.
135
- for (const x of seeds) {
136
- if (!blocks.has(x))
137
- continue;
138
- ownerChanged.add(x);
139
- const o = owners.get(x);
140
- if (typeof o === 'string' && o !== x)
141
- ownerChanged.add(o);
142
- }
143
- };
144
- /** The claims each seed held before its record changed (their tops are re-decided too). */
145
- const claimTargets = new Map();
146
- const ownerOf = (b) => {
147
- ensureOwners();
148
- return owners.get(b) ?? DEAD;
149
- };
150
- /** The live claimer of the max-stamp claim on `m` (`DisplayOwnership.top`). */
151
- const top = (m) => {
152
- ensureOwners();
153
- return topOf.get(m)?.claimer;
154
- };
155
- /** The blocks `owner` displays (the delete step's marks). */
156
- const displays = (owner) => {
157
- ensureOwners();
158
- return [...(displaysMap.get(owner) ?? [])];
159
- };
160
- /** Union-ever claim targets per holder (never shrinks: a dropped claim still invalidates). */
161
- const effects = new Map();
162
- const noteEffects = (id, claims) => {
163
- let fx = effects.get(id);
164
- if (fx === undefined)
165
- effects.set(id, (fx = new Set()));
166
- for (const c of claims)
167
- fx.add(c.m);
168
- };
169
- /** `id`'s claims went from `before` to `after`: its claim facts follow. */
170
- const noteClaims = (id, before, after) => {
171
- noteEffects(id, after);
172
- const was = new Set(before.map((c) => c.m));
173
- const now = new Set(after.map((c) => c.m));
174
- for (const m of was)
175
- if (!now.has(m)) {
176
- dropFrom(claimersOf, m, id);
177
- addTo(claimTargets, id, m);
178
- }
179
- for (const m of now)
180
- if (!was.has(m))
181
- addTo(claimersOf, m, id);
182
- ownerSeeds.add(id);
183
- };
184
- /** A structural change of `id`: its readers, and the blocks it claims, re-read. */
185
- const invalidateBlock = (id, ctx, claimsBefore = []) => {
186
- ctx.invalidated.add(id);
187
- for (const c of listConsumers.get(id) ?? [])
188
- ctx.invalidated.add(c);
189
- for (const m of new Set([...(effects.get(id) ?? []), ...claimsBefore.map((c) => c.m)])) {
190
- ctx.invalidated.add(m);
191
- for (const c of listConsumers.get(m) ?? [])
192
- ctx.invalidated.add(c);
193
- }
194
- };
195
- return {
196
- ensureOwners,
197
- ownerOf,
198
- top,
199
- displays,
200
- noteClaims,
201
- invalidateBlock
202
- };
203
- };
@@ -1,21 +0,0 @@
1
- import type { BlockId } from '../../placement/model.js';
2
- import type { ContentRun } from '../runs.js';
3
- import type { IndexCache } from './cache.js';
4
- import type { IndexClaims } from './claims.js';
5
- import type { IndexPlacement } from './placement.js';
6
- import type { IndexRecords } from './records.js';
7
- import type { FoldCtx, IndexState, Tx } from './state.js';
8
- import type { IndexStreams } from './streams.js';
9
- import type { IndexLayout } from './layout.js';
10
- /** The fold of one doc's index, over every part it folds into. */
11
- export declare const indexFold: (ix: IndexState & IndexClaims & IndexStreams & IndexLayout & IndexPlacement & IndexRecords & IndexCache) => {
12
- runs: (b: BlockId) => readonly ContentRun[];
13
- settle: (affected: Iterable<BlockId>, ctx: FoldCtx | null) => void;
14
- syncPending: (tr: Tx | null | undefined) => boolean;
15
- openTx: () => Tx | null | undefined;
16
- syncAll: () => void;
17
- unfolded: () => boolean;
18
- onCommit: (tr: Tx) => void;
19
- committed: WeakSet<Tx>;
20
- };
21
- export type IndexFold = ReturnType<typeof indexFold>;