edytor 6.0.0 → 7.0.1
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/README.md +3 -3
- package/dist/cloudflare/DocumentRoom.d.ts +77 -2
- package/dist/cloudflare/DocumentRoom.js +37 -1
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/room/access.d.ts +6 -1
- package/dist/cloudflare/room/access.js +30 -4
- package/dist/cloudflare/room/admission.d.ts +11 -0
- package/dist/cloudflare/room/admission.js +43 -10
- package/dist/cloudflare/room/context.d.ts +11 -2
- package/dist/cloudflare/room/context.js +17 -6
- package/dist/cloudflare/room/forged.d.ts +1 -1
- package/dist/cloudflare/room/forged.js +11 -9
- package/dist/cloudflare/room/frames.d.ts +2 -0
- package/dist/cloudflare/room/frames.js +2 -0
- package/dist/cloudflare/room/presence.js +1 -4
- package/dist/cloudflare/room/reseed.d.ts +93 -0
- package/dist/cloudflare/room/reseed.js +500 -0
- package/dist/cloudflare/room/scheduler.d.ts +1 -1
- package/dist/cloudflare/room/scheduler.js +9 -1
- package/dist/cloudflare/room/shared.d.ts +10 -0
- package/dist/cloudflare/room/shared.js +10 -0
- package/dist/cloudflare/room/storage.d.ts +7 -0
- package/dist/cloudflare/room/storage.js +33 -1
- package/dist/components/Content.svelte +7 -16
- package/dist/components/Edytor.svelte +32 -8
- package/dist/components/Edytor.svelte.d.ts +10 -1
- package/dist/components/EdytorRoot.svelte +17 -0
- package/dist/components/EdytorRoot.svelte.d.ts +4 -0
- package/dist/components/Suggestion.svelte +1 -1
- package/dist/components/Text.svelte +36 -33
- package/dist/components/Text.svelte.d.ts +2 -1
- package/dist/crdt/attribution/block.d.ts +3 -0
- package/dist/crdt/attribution/block.js +3 -2
- package/dist/crdt/doc/suggest.d.ts +6 -2
- package/dist/crdt/doc/suggest.js +6 -5
- package/dist/crdt/edytor-doc.d.ts +1 -1
- package/dist/crdt/edytor-doc.js +1 -1
- package/dist/crdt/engine-room.d.ts +4 -0
- package/dist/crdt/engine-room.js +6 -0
- package/dist/crdt/index.d.ts +2 -1
- package/dist/crdt/protocol.d.ts +2 -2
- package/dist/crdt/protocol.js +2 -2
- package/dist/crdt/protocols/auth.d.ts +8 -1
- package/dist/crdt/protocols/auth.js +14 -1
- package/dist/crdt/providers/index.d.ts +1 -0
- package/dist/crdt/providers/index.js +22 -3
- package/dist/crdt/providers/room.d.ts +15 -0
- package/dist/crdt/providers/room.js +16 -1
- package/dist/crdt/providers/websocket.d.ts +4 -2
- package/dist/crdt/providers/websocket.js +36 -9
- package/dist/crdt/reseed.d.ts +127 -0
- package/dist/crdt/reseed.js +533 -0
- package/dist/crdt/restore.d.ts +13 -1
- package/dist/crdt/restore.js +8 -3
- package/dist/crdt/schema.d.ts +6 -0
- package/dist/crdt/schema.js +6 -0
- package/dist/crdt/structs.d.ts +8 -11
- package/dist/crdt/structs.js +25 -44
- package/dist/crdt/text/index/build.d.ts +3 -9
- package/dist/crdt/text/index/build.js +87 -181
- package/dist/crdt/vendor/yjs/UPSTREAM.md +101 -5
- package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
- package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +10 -10
- package/dist/crdt/vendor/yjs/dts/utils/encoding.d.ts +1 -0
- package/dist/crdt/vendor/yjs/src/index.js +1 -1
- package/dist/crdt/vendor/yjs/src/structs/Item.js +24 -13
- package/dist/crdt/vendor/yjs/src/utils/Transaction.js +12 -10
- package/dist/crdt/vendor/yjs/src/utils/encoding.js +42 -1
- package/dist/edytor.svelte.js +1 -1
- package/dist/events/onBeforeInput.js +7 -0
- package/dist/events/onKeyDown.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/plugins/blockHandles/BlockHandles.svelte +32 -5
- package/dist/selection/selection.svelte.d.ts +1 -1
- package/dist/selection/selection.svelte.js +87 -106
- package/dist/session/attempt.d.ts +6 -0
- package/dist/session/attempt.js +6 -0
- package/dist/session/commands.js +49 -51
- package/dist/session/composition.svelte.js +19 -7
- package/dist/surface/attributes.d.ts +3 -3
- package/dist/surface/attributes.js +2 -2
- package/dist/surface/cells.d.ts +7 -0
- package/dist/surface/cells.js +7 -0
- package/dist/surface/observer.svelte.d.ts +7 -7
- package/dist/surface/observer.svelte.js +225 -313
- package/dist/surface/pin.svelte.d.ts +7 -10
- package/dist/surface/pin.svelte.js +12 -15
- package/dist/surface/projector.svelte.d.ts +6 -3
- package/dist/surface/projector.svelte.js +20 -12
- package/dist/themes/notion.css +7 -0
- package/package.json +1 -1
|
@@ -72,14 +72,12 @@
|
|
|
72
72
|
)
|
|
73
73
|
);
|
|
74
74
|
/** Session content, rendered from JSON as declared view values: no handle, no caret. */
|
|
75
|
-
const ghost = (segment: Segment) =>
|
|
76
|
-
|
|
75
|
+
const ghost = (segment: Segment) =>
|
|
76
|
+
segmentDeltas(
|
|
77
77
|
{ id, type: type ?? '', data: undefined } as Cell,
|
|
78
78
|
segment,
|
|
79
79
|
preview ? undefined : transform
|
|
80
|
-
)
|
|
81
|
-
empty: !segment.text
|
|
82
|
-
});
|
|
80
|
+
);
|
|
83
81
|
|
|
84
82
|
/** The parts this content renders: a preview's (session parts, no handle), else the cell's. */
|
|
85
83
|
const own = $derived(preview ? partsOf(preview) : parts);
|
|
@@ -137,12 +135,9 @@
|
|
|
137
135
|
)}<!--
|
|
138
136
|
-->{#each parts as part, index (index)}<!--
|
|
139
137
|
-->{#if part.kind === 'text'}<!--
|
|
140
|
-
-->{@const shown =
|
|
141
|
-
ghost(part)}<!--
|
|
142
138
|
--><RenderText
|
|
143
139
|
text={undefined}
|
|
144
|
-
deltas={
|
|
145
|
-
empty={shown.empty}
|
|
140
|
+
deltas={ghost(part)}
|
|
146
141
|
newline={part.text.endsWith('\n')}
|
|
147
142
|
/><!--
|
|
148
143
|
-->{:else if rendersAtom(part)}<!--
|
|
@@ -155,19 +150,16 @@
|
|
|
155
150
|
-->{/snippet}<!--
|
|
156
151
|
-->{#key epoch}<RenderText
|
|
157
152
|
text={firstText}
|
|
158
|
-
deltas={firstShown
|
|
159
|
-
|
|
153
|
+
deltas={firstShown}
|
|
154
|
+
line={!entries.length}
|
|
160
155
|
newline={first.text.endsWith('\n')}
|
|
161
156
|
placeholder={preview ? null : placeholder}
|
|
162
157
|
/>{/key}<!--
|
|
163
158
|
-->{#each entries as entry (entry.key)}<!--
|
|
164
159
|
-->{#if entry.kind === 'text'}<!--
|
|
165
|
-
-->{@const shown =
|
|
166
|
-
preview ? ghost(entry.part) : view(entry.part)}<!--
|
|
167
160
|
--><RenderText
|
|
168
161
|
text={preview ? undefined : edytor.textAt(id, entry.ordinal)}
|
|
169
|
-
deltas={
|
|
170
|
-
empty={shown.empty}
|
|
162
|
+
deltas={preview ? ghost(entry.part) : view(entry.part)}
|
|
171
163
|
newline={entry.part.text.endsWith('\n')}
|
|
172
164
|
placeholder={preview ? null : placeholder}
|
|
173
165
|
/><!--
|
|
@@ -180,7 +172,6 @@
|
|
|
180
172
|
--><RenderText
|
|
181
173
|
text={undefined}
|
|
182
174
|
deltas={entry.deltas}
|
|
183
|
-
empty={false}
|
|
184
175
|
newline={false}
|
|
185
176
|
rest
|
|
186
177
|
/><!--
|
|
@@ -193,6 +193,8 @@
|
|
|
193
193
|
params,
|
|
194
194
|
onSyncExpired,
|
|
195
195
|
onSyncRefused,
|
|
196
|
+
rebuild,
|
|
197
|
+
adopt,
|
|
196
198
|
requireHydration,
|
|
197
199
|
snapshot,
|
|
198
200
|
actor,
|
|
@@ -205,10 +207,18 @@
|
|
|
205
207
|
spellcheck = true,
|
|
206
208
|
autocorrect = 'off',
|
|
207
209
|
autocomplete = 'off',
|
|
208
|
-
autocapitalize
|
|
210
|
+
autocapitalize,
|
|
209
211
|
inputmode,
|
|
210
212
|
enterkeyhint
|
|
211
|
-
}: EdytorProps
|
|
213
|
+
}: EdytorProps & {
|
|
214
|
+
/** The view's own rebuild (`EdytorRoot`): a new view on a new document. */
|
|
215
|
+
rebuild?: () => void;
|
|
216
|
+
/**
|
|
217
|
+
* Hands the view to `EdytorRoot`, which a binding cannot: on the server a
|
|
218
|
+
* bound prop renders the tree twice, and the discarded view never ends.
|
|
219
|
+
*/
|
|
220
|
+
adopt?: (view: EdytorClass) => void;
|
|
221
|
+
} = $props();
|
|
212
222
|
|
|
213
223
|
const initialEdytorOptions = untrack(() => ({
|
|
214
224
|
readonly,
|
|
@@ -227,6 +237,7 @@
|
|
|
227
237
|
}));
|
|
228
238
|
|
|
229
239
|
edytor = new EdytorClass(initialEdytorOptions);
|
|
240
|
+
untrack(() => adopt)?.(edytor);
|
|
230
241
|
|
|
231
242
|
// ONE attach path for owned and injected documents: `attachSync`
|
|
232
243
|
// tracks the provider on the DOCUMENT's lifetime (one provider per
|
|
@@ -276,7 +287,11 @@
|
|
|
276
287
|
}
|
|
277
288
|
// Subscribe first, then replay the standing refusal isolated like the
|
|
278
289
|
// later ones: a throwing callback still hears the next refusal.
|
|
279
|
-
offRefused = document.onSyncRefused((next) =>
|
|
290
|
+
offRefused = document.onSyncRefused((next) => {
|
|
291
|
+
onSyncRefused?.(next);
|
|
292
|
+
// A re-seed (`4410`): a view that owns its document builds itself again on a new one.
|
|
293
|
+
if (next.code === CLOSE.reseeded && !edytorDocument) rebuild?.();
|
|
294
|
+
});
|
|
280
295
|
if (refusal) {
|
|
281
296
|
try {
|
|
282
297
|
onSyncRefused?.(refusal);
|
|
@@ -312,6 +327,8 @@
|
|
|
312
327
|
|
|
313
328
|
/** The chrome popup open on this view (`edytor.popups`): the root names it while it is. */
|
|
314
329
|
const popup = $derived(edytor.popups.current);
|
|
330
|
+
/** A block selection: no native highlight, and no virtual keyboard over it. */
|
|
331
|
+
const blocks = $derived(edytor.selection.value.kind === 'blocks');
|
|
315
332
|
|
|
316
333
|
// The display projector: the root `$effect.pre` notes the focused
|
|
317
334
|
// element before the flush writes the DOM; the root `$effect` — the last
|
|
@@ -353,11 +370,13 @@
|
|
|
353
370
|
autocorrect,
|
|
354
371
|
autocomplete,
|
|
355
372
|
autocapitalize,
|
|
356
|
-
|
|
373
|
+
// Selected blocks (a tapped image) open no virtual keyboard; the
|
|
374
|
+
// focus stays, so a hardware keyboard's keys still act on them.
|
|
375
|
+
inputmode: blocks ? 'none' : inputmode,
|
|
357
376
|
enterkeyhint
|
|
358
377
|
}}
|
|
359
378
|
data-edytor
|
|
360
|
-
data-edytor-selection={
|
|
379
|
+
data-edytor-selection={blocks ? 'blocks' : undefined}
|
|
361
380
|
contenteditable={!readonly}
|
|
362
381
|
role="textbox"
|
|
363
382
|
{id}
|
|
@@ -379,7 +398,7 @@
|
|
|
379
398
|
contenteditable="false"
|
|
380
399
|
aria-hidden="true"
|
|
381
400
|
style="display: none"
|
|
382
|
-
use:edytor.surface.
|
|
401
|
+
use:edytor.surface.own
|
|
383
402
|
></span>
|
|
384
403
|
</div>
|
|
385
404
|
{:else if snapshot}
|
|
@@ -428,11 +447,16 @@
|
|
|
428
447
|
|
|
429
448
|
/*
|
|
430
449
|
* Room below the last block, where a press puts the caret in a trailing
|
|
431
|
-
* paragraph (`nav.trailing.press`): `--edytor-trailing-space`.
|
|
432
|
-
*
|
|
450
|
+
* paragraph (`nav.trailing.press`): `--edytor-trailing-space`. A word
|
|
451
|
+
* longer than the line (a pasted URL) breaks anywhere, and counts so in
|
|
452
|
+
* the editor's minimum width: in a flex or grid track the editor never
|
|
453
|
+
* grows past its container (`break-word`, an editing host's default,
|
|
454
|
+
* wraps it too but sizes the track to the whole word). No specificity,
|
|
455
|
+
* so any rule of the app's or a theme's wins.
|
|
433
456
|
*/
|
|
434
457
|
:global(:where([data-edytor])) {
|
|
435
458
|
padding-block-end: var(--edytor-trailing-space, 2em);
|
|
459
|
+
overflow-wrap: anywhere;
|
|
436
460
|
}
|
|
437
461
|
/*
|
|
438
462
|
* Long pages, opt-in: the `edytor-long-page` class on the editor or an
|
|
@@ -113,6 +113,15 @@ export type EdytorProps = {
|
|
|
113
113
|
import type { JSONDoc } from '../utils/json.js';
|
|
114
114
|
import type { HotKey, HotKeyCombination } from '../session/keymap.js';
|
|
115
115
|
import type { EdytorSelection } from '../selection/selection.svelte.js';
|
|
116
|
-
|
|
116
|
+
type $$ComponentProps = EdytorProps & {
|
|
117
|
+
/** The view's own rebuild (`EdytorRoot`): a new view on a new document. */
|
|
118
|
+
rebuild?: () => void;
|
|
119
|
+
/**
|
|
120
|
+
* Hands the view to `EdytorRoot`, which a binding cannot: on the server a
|
|
121
|
+
* bound prop renders the tree twice, and the discarded view never ends.
|
|
122
|
+
*/
|
|
123
|
+
adopt?: (view: EdytorClass) => void;
|
|
124
|
+
};
|
|
125
|
+
declare const Edytor: import("svelte").Component<$$ComponentProps, {}, "edytor">;
|
|
117
126
|
type Edytor = ReturnType<typeof Edytor>;
|
|
118
127
|
export default Edytor;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// The public `<Edytor>`: the view, built again on a new document when the
|
|
3
|
+
// room re-seeds the one it owns (`room.reseed.protocol`).
|
|
4
|
+
import Edytor, { type EdytorProps } from './Edytor.svelte';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line no-useless-assignment -- bindable: `adopt` assigns it
|
|
7
|
+
let { edytor = $bindable(), ...props }: EdytorProps = $props();
|
|
8
|
+
let epoch = $state(0);
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<!-- A view built again loads the room's document: it never seeds its value over it. -->
|
|
12
|
+
{#key epoch}<Edytor
|
|
13
|
+
{...props}
|
|
14
|
+
requireHydration={epoch > 0 || props.requireHydration}
|
|
15
|
+
adopt={(view) => (edytor = view)}
|
|
16
|
+
rebuild={() => epoch++}
|
|
17
|
+
/>{/key}
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
contenteditable="false"
|
|
32
32
|
aria-label={suggestion.label ?? labelsOf(edytor, 'editor', editorEnglish).suggestion}
|
|
33
33
|
role="group"
|
|
34
|
-
use:edytor.surface.
|
|
34
|
+
use:edytor.surface.own={suggestion.id}
|
|
35
35
|
onmousedown={cancel}
|
|
36
36
|
>
|
|
37
37
|
{#each cells as cell (cell.id)}<Block kid={cell} />{/each}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
3
|
import type { Edytor } from '../edytor.svelte.js';
|
|
4
|
-
import { rendersMark, type RenderDelta } from '../surface/cells.js';
|
|
4
|
+
import { FILLER, rendersMark, type RenderDelta } from '../surface/cells.js';
|
|
5
5
|
import { Text } from '../text/text.svelte.js';
|
|
6
6
|
import Mark, { customAt } from './Mark.svelte';
|
|
7
7
|
import CustomMark from './CustomMark.svelte';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* One segment of a cell: its render deltas, the empty filler
|
|
11
|
-
*
|
|
12
|
-
* by the `::before` rule below).
|
|
13
|
-
*
|
|
14
|
-
* shifted rebinds it without remounting
|
|
10
|
+
* One segment of a cell: its render deltas, the empty filler (`FILLER`;
|
|
11
|
+
* a `<br>` for a text alone on its `line`), the trailing-newline marker
|
|
12
|
+
* and the placeholder attribute (shown by the `::before` rule below).
|
|
13
|
+
* `text` is the handle the element maps to for the operations and the
|
|
14
|
+
* selection; a segment re-keyed or shifted rebinds it without remounting
|
|
15
|
+
* the element. The optional props are read as given (no default: a
|
|
16
|
+
* default costs a prop call per text).
|
|
15
17
|
*/
|
|
16
18
|
let {
|
|
17
19
|
text,
|
|
18
20
|
deltas,
|
|
19
|
-
|
|
21
|
+
line,
|
|
20
22
|
newline,
|
|
21
|
-
placeholder
|
|
22
|
-
rest
|
|
23
|
+
placeholder,
|
|
24
|
+
rest
|
|
23
25
|
}: {
|
|
24
26
|
text: Text | undefined;
|
|
25
27
|
deltas: readonly RenderDelta[];
|
|
26
|
-
|
|
28
|
+
/** Nothing follows it in its block's content: empty, it renders a `<br>`. */
|
|
29
|
+
line?: boolean;
|
|
27
30
|
newline: boolean;
|
|
28
31
|
placeholder?: string | null;
|
|
29
32
|
/** The rest a live composition merged into its host, shown after it (`pin.rest`). */
|
|
@@ -32,17 +35,15 @@
|
|
|
32
35
|
|
|
33
36
|
const edytor = getContext<Edytor>('edytor');
|
|
34
37
|
|
|
35
|
-
const attachText = (node: HTMLElement,
|
|
36
|
-
let attachedText = initialText;
|
|
38
|
+
const attachText = (node: HTMLElement, attached: Text | undefined) => {
|
|
37
39
|
// A suggestion's ghost text has no handle and attaches nothing.
|
|
38
|
-
let attachment =
|
|
40
|
+
let attachment = attached?.attach(node);
|
|
39
41
|
|
|
40
42
|
return {
|
|
41
|
-
update(
|
|
42
|
-
if (!
|
|
43
|
+
update(next: Text | undefined) {
|
|
44
|
+
if (!next || next === attached) return;
|
|
43
45
|
attachment?.destroy();
|
|
44
|
-
|
|
45
|
-
attachment = attachedText.attach(node);
|
|
46
|
+
attachment = (attached = next).attach(node);
|
|
46
47
|
},
|
|
47
48
|
destroy() {
|
|
48
49
|
attachment?.destroy();
|
|
@@ -52,19 +53,16 @@
|
|
|
52
53
|
|
|
53
54
|
const getDeltaKey = (delta: RenderDelta, index: number) =>
|
|
54
55
|
`${index}:${JSON.stringify(delta.marks)}`;
|
|
55
|
-
/**
|
|
56
|
-
* An empty text renders the filler as its first unmarked delta: the same
|
|
57
|
-
* text node, so the first character typed or composed into an empty
|
|
58
|
-
* block lands in the node the browser (and the IME) already holds.
|
|
59
|
-
*/
|
|
60
|
-
const FILLER: readonly RenderDelta[] = [{ text: '\u200B', marks: [] }];
|
|
61
56
|
|
|
62
57
|
/** A delta's marks this view renders (an unknown mark renders its text only). */
|
|
63
58
|
const rendered = (delta: RenderDelta): RenderDelta => {
|
|
64
59
|
const known = delta.marks.filter(([name]) => rendersMark(edytor.marks, name));
|
|
65
60
|
return known.length === delta.marks.length ? delta : { text: delta.text, marks: known };
|
|
66
61
|
};
|
|
67
|
-
|
|
62
|
+
/** No deltas, or the IME pin's filler (`Pin.shown`): the text holds no character. */
|
|
63
|
+
const empty = $derived(!deltas.length || deltas === FILLER);
|
|
64
|
+
/** Empty, beside an atom or a suggestion: the zero-width filler; alone on its line, the `<br>`. */
|
|
65
|
+
const shown = $derived(deltas.length || line ? deltas : FILLER);
|
|
68
66
|
/**
|
|
69
67
|
* The first delta's text when it is unmarked: the element's own first
|
|
70
68
|
* text node, never re-created while the text starts unmarked (a plain
|
|
@@ -87,18 +85,23 @@
|
|
|
87
85
|
return items;
|
|
88
86
|
});
|
|
89
87
|
|
|
90
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* A plain click (no drag, no Shift, a single press) places the caret at
|
|
90
|
+
* the pointer. A tap's is the platform's (`sel.press.touch`): iOS puts it
|
|
91
|
+
* at the word's edge, and selects the word at a double tap's second tap,
|
|
92
|
+
* whose click still says `detail` 1.
|
|
93
|
+
*/
|
|
91
94
|
const restoreTextSelectionFromClick = (node: HTMLElement) => {
|
|
92
95
|
let pointerStart: { clientX: number; clientY: number } | null = null;
|
|
93
|
-
const pointerdown = ({ button, shiftKey, clientX, clientY }: PointerEvent) => {
|
|
94
|
-
pointerStart = button
|
|
96
|
+
const pointerdown = ({ button, shiftKey, clientX, clientY, pointerType }: PointerEvent) => {
|
|
97
|
+
pointerStart = button || shiftKey || pointerType === 'touch' ? null : { clientX, clientY };
|
|
95
98
|
};
|
|
96
99
|
const click = (event: MouseEvent) => {
|
|
97
100
|
const start = pointerStart;
|
|
98
101
|
pointerStart = null;
|
|
99
|
-
if (event.button
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
+
if (event.button || event.detail !== 1 || event.shiftKey || !start || !text) return;
|
|
103
|
+
// Moved less than 4px: no drag.
|
|
104
|
+
if (Math.hypot(event.clientX - start.clientX, event.clientY - start.clientY) < 4)
|
|
102
105
|
edytor.selection.pointer.placeAt(text, event.clientX, event.clientY);
|
|
103
106
|
};
|
|
104
107
|
node.addEventListener('pointerdown', pointerdown);
|
|
@@ -118,15 +121,15 @@
|
|
|
118
121
|
<span
|
|
119
122
|
use:attachText={text}
|
|
120
123
|
use:restoreTextSelectionFromClick
|
|
121
|
-
data-edytor-text-empty={empty
|
|
124
|
+
data-edytor-text-empty={String(empty)}
|
|
122
125
|
data-placeholder={placeholder ?? undefined}
|
|
123
126
|
data-edytor-composition-rest={rest || undefined}
|
|
124
127
|
style:white-space="break-spaces"
|
|
125
|
-
>{#if head !== null}{head}{
|
|
128
|
+
>{#if head !== null}{head}{:else if !shown.length}<br
|
|
129
|
+
/>{/if}<!--
|
|
126
130
|
-->{#each tail as item (item.key)}<!--
|
|
127
131
|
-->{#if item.delta === null}<!--
|
|
128
132
|
--><span
|
|
129
|
-
class="newline"
|
|
130
133
|
data-edytor-trailing-newline>​</span
|
|
131
134
|
><!--
|
|
132
135
|
-->{:else if customAt(edytor, item.delta, 0)}<!--
|
|
@@ -3,7 +3,8 @@ import { Text } from '../text/text.svelte.js';
|
|
|
3
3
|
type $$ComponentProps = {
|
|
4
4
|
text: Text | undefined;
|
|
5
5
|
deltas: readonly RenderDelta[];
|
|
6
|
-
|
|
6
|
+
/** Nothing follows it in its block's content: empty, it renders a `<br>`. */
|
|
7
|
+
line?: boolean;
|
|
7
8
|
newline: boolean;
|
|
8
9
|
placeholder?: string | null;
|
|
9
10
|
/** The rest a live composition merged into its host, shown after it (`pin.rest`). */
|
|
@@ -78,6 +78,9 @@ export type BlockAttribution = {
|
|
|
78
78
|
lastChangedBy?: ActorId;
|
|
79
79
|
};
|
|
80
80
|
export { BLOCK_ATTR_ROOT, LAST_CHANGED_ATTR };
|
|
81
|
+
/** A record's `createdBy` key, and the prefix of its contributors' (a re-seed copies them: `crdt/reseed.ts`). */
|
|
82
|
+
export declare const CREATED_KEY = "c";
|
|
83
|
+
export declare const CONTRIBUTOR_PREFIX = "k/";
|
|
81
84
|
/** The `k/` member set on a `b/` record node. */
|
|
82
85
|
export declare const contributorsOfRecord: (rec: EngineNode | null) => Set<ActorId>;
|
|
83
86
|
/**
|
|
@@ -5,8 +5,9 @@ import { attrItems, newNode as makeNode } from '../structs.js';
|
|
|
5
5
|
// `../schema.js` leaf — re-exported so existing import sites stay.
|
|
6
6
|
export { BLOCK_ATTR_ROOT, LAST_CHANGED_ATTR };
|
|
7
7
|
const REC_NODE = 'brec';
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
/** A record's `createdBy` key, and the prefix of its contributors' (a re-seed copies them: `crdt/reseed.ts`). */
|
|
9
|
+
export const CREATED_KEY = 'c';
|
|
10
|
+
export const CONTRIBUTOR_PREFIX = 'k/';
|
|
10
11
|
/** Incarnation stamp on a record: the nonce `n` of the node it belongs to. */
|
|
11
12
|
const INCARNATION_KEY = 'i';
|
|
12
13
|
const recordOf = (doc, id) => {
|
|
@@ -89,8 +89,12 @@ export type SuggestContext = DocBase & DocReads & {
|
|
|
89
89
|
create: (doc: EngineDoc, config: EdytorDocConfig) => SuggestFacade;
|
|
90
90
|
/** Its changes no index fact shows: counted in the facade's `version`. */
|
|
91
91
|
v: number;
|
|
92
|
-
/**
|
|
93
|
-
|
|
92
|
+
/**
|
|
93
|
+
* The document without its pending suggestions, read by `read` (the
|
|
94
|
+
* export `toJSON()` gives unless asked for the suggestions);
|
|
95
|
+
* `undefined` while none is pending.
|
|
96
|
+
*/
|
|
97
|
+
base: (<T>(read: (other: SuggestFacade) => T) => T | undefined) | undefined;
|
|
94
98
|
};
|
|
95
99
|
/** The facade the part is built over: its `part`, and the operations it writes through. */
|
|
96
100
|
export type SuggestFacade = {
|
package/dist/crdt/doc/suggest.js
CHANGED
|
@@ -526,10 +526,11 @@ const docSuggest = (f) => {
|
|
|
526
526
|
return [...map.keys()].sort(c.compare).flatMap((b) => map.get(b));
|
|
527
527
|
};
|
|
528
528
|
/**
|
|
529
|
-
* The document without its pending suggestions (`sugg.json.base`)
|
|
530
|
-
* copy, every pending one rejected; `undefined` while
|
|
529
|
+
* The document without its pending suggestions (`sugg.json.base`), read
|
|
530
|
+
* by `read`: on a copy, every pending one rejected; `undefined` while
|
|
531
|
+
* none is pending.
|
|
531
532
|
*/
|
|
532
|
-
const base = () => {
|
|
533
|
+
const base = (read) => {
|
|
533
534
|
if (root().attrKeys().next().done || !changes().length)
|
|
534
535
|
return;
|
|
535
536
|
const { Y } = c;
|
|
@@ -538,11 +539,11 @@ const docSuggest = (f) => {
|
|
|
538
539
|
const other = c.create(copy, { ...c.config, actor: undefined });
|
|
539
540
|
const all = suggestionsOf(other);
|
|
540
541
|
all.run(all.decide(all.changes(), false));
|
|
541
|
-
const
|
|
542
|
+
const out = read(other);
|
|
542
543
|
all.dispose();
|
|
543
544
|
other.dispose();
|
|
544
545
|
copy.destroy();
|
|
545
|
-
return
|
|
546
|
+
return out;
|
|
546
547
|
};
|
|
547
548
|
c.base = base;
|
|
548
549
|
return {
|
|
@@ -1032,7 +1032,7 @@ export declare const bindEdytorDoc: (Y: EngineApi) => {
|
|
|
1032
1032
|
* Make the visible document `doc` equal `json`, keeping the ids the
|
|
1033
1033
|
* registry holds and writing only what differs (`room.history.restore`), inside the caller's transaction.
|
|
1034
1034
|
*/
|
|
1035
|
-
restoreTo: <Plan>(doc: EngineDoc, facade: import("./restore.js").RestoreFacade<Plan>, json: JSONDoc) => import("./restore.js").RestoreReport;
|
|
1035
|
+
restoreTo: <Plan>(doc: EngineDoc, facade: import("./restore.js").RestoreFacade<Plan>, json: JSONDoc, { rewrite, suggestions }?: import("./restore.js").RestoreOptions<Plan>) => import("./restore.js").RestoreReport;
|
|
1036
1036
|
model: {
|
|
1037
1037
|
REGISTRY_KEY: string;
|
|
1038
1038
|
registryOf: (doc: EngineDoc) => EngineNode;
|
package/dist/crdt/edytor-doc.js
CHANGED
|
@@ -220,7 +220,7 @@ export const docFacade = (Y, layers) => {
|
|
|
220
220
|
*/
|
|
221
221
|
const toJSON = (options) => {
|
|
222
222
|
// A part's export first (the shared suggestions': without the pending ones, `sugg.json.base`).
|
|
223
|
-
const base = !options?.suggestions && part.base?.();
|
|
223
|
+
const base = !options?.suggestions && part.base?.((other) => other.toJSON({ suggestions: true }));
|
|
224
224
|
if (base)
|
|
225
225
|
return base;
|
|
226
226
|
const data = docData();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine calls only the room makes (a re-seed's cut and rebase,
|
|
3
|
+
* `crdt/reseed.ts`): apart from the engine object (`engine.js`), which every
|
|
4
|
+
* app keeps whole, so an app's bundle holds none of them.
|
|
5
|
+
*/
|
|
6
|
+
export { clipUpdate, diffUpdate } from './vendor/yjs/src/index.js';
|
package/dist/crdt/index.d.ts
CHANGED
|
@@ -360,7 +360,7 @@ export declare const bindCrdt: (Y: EngineApi) => {
|
|
|
360
360
|
text: import("./text/model.js").TextEngine;
|
|
361
361
|
}, horizon: import("./purge.js").Horizon | null) => import("./purge.js").PurgeReport;
|
|
362
362
|
horizonOf: (doc: import("./engine-api.js").EngineDoc) => import("./purge.js").Horizon | null;
|
|
363
|
-
restoreTo: <Plan>(doc: import("./engine-api.js").EngineDoc, facade: import("./restore.js").RestoreFacade<Plan>, json: import("./index.js").JSONDoc) => import("./restore.js").RestoreReport;
|
|
363
|
+
restoreTo: <Plan>(doc: import("./engine-api.js").EngineDoc, facade: import("./restore.js").RestoreFacade<Plan>, json: import("./index.js").JSONDoc, { rewrite, suggestions }?: import("./restore.js").RestoreOptions<Plan>) => import("./restore.js").RestoreReport;
|
|
364
364
|
model: {
|
|
365
365
|
REGISTRY_KEY: string;
|
|
366
366
|
registryOf: (doc: import("./engine-api.js").EngineDoc) => import("./engine-api.js").EngineNode;
|
|
@@ -551,6 +551,7 @@ export declare const bindCrdt: (Y: EngineApi) => {
|
|
|
551
551
|
deny(): void;
|
|
552
552
|
allow(): void;
|
|
553
553
|
};
|
|
554
|
+
_rebasing: boolean;
|
|
554
555
|
messageHandlers: Record<number, import("./providers/room.js").RoomMessageHandler</*elided*/ any>>;
|
|
555
556
|
hasSynced: boolean;
|
|
556
557
|
whenSynced: Promise<unknown>;
|
package/dist/crdt/protocol.d.ts
CHANGED
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
export { bindCrdt, type Crdt, type EngineApi, type EngineDoc, type EngineNode, type EngineTransaction, type EngineItemRef, type YNode, type YItem, type YDoc, type YUndoManager, type YTransaction } from './index.js';
|
|
28
28
|
export { SCHEMA_VERSION, META_KEY } from './edytor-doc.js';
|
|
29
29
|
export { GENERATION, generationWord, frame, PROTOCOL_VERSION, GENERATION_RECORD, GenerationMismatchError, readProtocolVersion, type GenerationRecord } from './protocols/envelope.js';
|
|
30
|
-
export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, type ChunkReader, CLOSE } from './providers/room.js';
|
|
30
|
+
export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, messageRebase, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, type ChunkReader, CLOSE } from './providers/room.js';
|
|
31
31
|
export { messageYjsSyncStep1, messageYjsSyncStep2, messageYjsUpdate, type SyncProtocol } from './protocols/sync.js';
|
|
32
|
-
export { messageAccess, messagePermissionDenied, messageReadOnly, writeAccess, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
|
|
32
|
+
export { messageAccess, messageEpoch, messagePermissionDenied, messageReadOnly, writeAccess, writeEpoch, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
|
|
33
33
|
export { commentsSubscribe, commentsSnapshot, commentsChange, writeCommentsSubscribe, writeCommentsSnapshot, writeCommentsChange, readCommentsMessage, type CommentChange, type CommentMessage, type CommentSnapshot, type CommentThread, type ThreadComment } from './protocols/comments.js';
|
|
34
34
|
export { applyAwarenessUpdate, encodeAwarenessUpdate, readAwarenessEntries, writeAwarenessEntries, type AwarenessEntry } from './protocols/awareness.js';
|
|
35
35
|
export { createDecoder, readVarUint, readVarUint8Array, type Decoder } from 'lib0-v14/decoding';
|
package/dist/crdt/protocol.js
CHANGED
|
@@ -30,9 +30,9 @@ export { bindCrdt } from './index.js';
|
|
|
30
30
|
export { SCHEMA_VERSION, META_KEY } from './edytor-doc.js';
|
|
31
31
|
export { GENERATION, generationWord, frame, PROTOCOL_VERSION, GENERATION_RECORD, GenerationMismatchError, readProtocolVersion } from './protocols/envelope.js';
|
|
32
32
|
// ── Message types, acknowledgements and chunks ─────────────────────────
|
|
33
|
-
export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, CLOSE } from './providers/room.js';
|
|
33
|
+
export { messageSync, messageAwareness, messageAuth, messageQueryAwareness, messageSaved, messageChunk, messageComments, messageRebase, MAX_FRAME_BYTES, chunkFrame, createChunkReader, ChunkError, CLOSE } from './providers/room.js';
|
|
34
34
|
export { messageYjsSyncStep1, messageYjsSyncStep2, messageYjsUpdate } from './protocols/sync.js';
|
|
35
|
-
export { messageAccess, messagePermissionDenied, messageReadOnly, writeAccess, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
|
|
35
|
+
export { messageAccess, messageEpoch, messagePermissionDenied, messageReadOnly, writeAccess, writeEpoch, writePermissionDenied, writeReadOnly } from './protocols/auth.js';
|
|
36
36
|
export { commentsSubscribe, commentsSnapshot, commentsChange, writeCommentsSubscribe, writeCommentsSnapshot, writeCommentsChange, readCommentsMessage } from './protocols/comments.js';
|
|
37
37
|
export { applyAwarenessUpdate, encodeAwarenessUpdate, readAwarenessEntries, writeAwarenessEntries } from './protocols/awareness.js';
|
|
38
38
|
// Minimal wire codec for frame bodies (lib0 — the codec the frames are
|
|
@@ -28,6 +28,13 @@ export declare const writeReadOnly: (encoder: encoding.Encoder) => void;
|
|
|
28
28
|
*/
|
|
29
29
|
export declare const messageAccess = 2;
|
|
30
30
|
export declare const writeAccess: (encoder: encoding.Encoder, access: string) => void;
|
|
31
|
+
/**
|
|
32
|
+
* The room's epoch (`room.reseed.protocol`), sent to a socket that dialed an
|
|
33
|
+
* older one, instead of anything else: the room asks it for its old
|
|
34
|
+
* document (`messageRebase`), then closes it `4410`.
|
|
35
|
+
*/
|
|
36
|
+
export declare const messageEpoch = 3;
|
|
37
|
+
export declare const writeEpoch: (encoder: encoding.Encoder, epoch: number) => void;
|
|
31
38
|
export type PermissionDeniedHandler = (ydoc: unknown, reason: string) => void;
|
|
32
39
|
/**
|
|
33
40
|
* Decode one auth payload. Returns the auth message subtype so the caller
|
|
@@ -35,4 +42,4 @@ export type PermissionDeniedHandler = (ydoc: unknown, reason: string) => void;
|
|
|
35
42
|
* do not speak is protocol skew, and this stack's contract is that skew is
|
|
36
43
|
* reported, not silently dropped (same rule as unknown sync subtypes).
|
|
37
44
|
*/
|
|
38
|
-
export declare const readAuthMessage: (decoder: decoding.Decoder, y: unknown, permissionDeniedHandler: PermissionDeniedHandler, readOnlyHandler?: (ydoc: unknown) => void, accessHandler?: (access: string) => void) => number;
|
|
45
|
+
export declare const readAuthMessage: (decoder: decoding.Decoder, y: unknown, permissionDeniedHandler: PermissionDeniedHandler, readOnlyHandler?: (ydoc: unknown) => void, accessHandler?: (access: string) => void, epochHandler?: (epoch: number) => void) => number;
|
|
@@ -36,13 +36,23 @@ export const writeAccess = (encoder, access) => {
|
|
|
36
36
|
encoding.writeVarUint(encoder, messageAccess);
|
|
37
37
|
encoding.writeVarString(encoder, access);
|
|
38
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* The room's epoch (`room.reseed.protocol`), sent to a socket that dialed an
|
|
41
|
+
* older one, instead of anything else: the room asks it for its old
|
|
42
|
+
* document (`messageRebase`), then closes it `4410`.
|
|
43
|
+
*/
|
|
44
|
+
export const messageEpoch = 3;
|
|
45
|
+
export const writeEpoch = (encoder, epoch) => {
|
|
46
|
+
encoding.writeVarUint(encoder, messageEpoch);
|
|
47
|
+
encoding.writeVarUint(encoder, epoch);
|
|
48
|
+
};
|
|
39
49
|
/**
|
|
40
50
|
* Decode one auth payload. Returns the auth message subtype so the caller
|
|
41
51
|
* can surface unknown subtypes — a valid envelope carrying an auth type we
|
|
42
52
|
* do not speak is protocol skew, and this stack's contract is that skew is
|
|
43
53
|
* reported, not silently dropped (same rule as unknown sync subtypes).
|
|
44
54
|
*/
|
|
45
|
-
export const readAuthMessage = (decoder, y, permissionDeniedHandler, readOnlyHandler, accessHandler) => {
|
|
55
|
+
export const readAuthMessage = (decoder, y, permissionDeniedHandler, readOnlyHandler, accessHandler, epochHandler) => {
|
|
46
56
|
const authMessageType = decoding.readVarUint(decoder);
|
|
47
57
|
switch (authMessageType) {
|
|
48
58
|
case messagePermissionDenied:
|
|
@@ -54,6 +64,9 @@ export const readAuthMessage = (decoder, y, permissionDeniedHandler, readOnlyHan
|
|
|
54
64
|
break;
|
|
55
65
|
case messageAccess:
|
|
56
66
|
accessHandler?.(decoding.readVarString(decoder));
|
|
67
|
+
break;
|
|
68
|
+
case messageEpoch:
|
|
69
|
+
epochHandler?.(decoding.readVarUint(decoder));
|
|
57
70
|
}
|
|
58
71
|
return authMessageType;
|
|
59
72
|
};
|
|
@@ -243,6 +243,7 @@ export declare const bindProviders: (Y: EngineApi) => {
|
|
|
243
243
|
deny(): void;
|
|
244
244
|
allow(): void;
|
|
245
245
|
};
|
|
246
|
+
_rebasing: boolean;
|
|
246
247
|
messageHandlers: Record<number, import("./room.js").RoomMessageHandler</*elided*/ any>>;
|
|
247
248
|
hasSynced: boolean;
|
|
248
249
|
whenSynced: Promise<unknown>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { keepingReplaced } from '../incarnations.js';
|
|
2
2
|
import { bindIndexeddbProvider } from './indexeddb.js';
|
|
3
|
-
import { assertRoomId, SyncRefusedError } from './room.js';
|
|
3
|
+
import { assertRoomId, CLOSE, SyncRefusedError } from './room.js';
|
|
4
4
|
import { bindWebsocketProvider } from './websocket.js';
|
|
5
5
|
export const bindProviders = (Y) => {
|
|
6
6
|
const idb = bindIndexeddbProvider(Y);
|
|
@@ -50,7 +50,18 @@ export const bindProviders = (Y) => {
|
|
|
50
50
|
maxBackoffTime,
|
|
51
51
|
connectTimeout,
|
|
52
52
|
disableBc: disableBc || local !== undefined,
|
|
53
|
-
maxFrameBytes
|
|
53
|
+
maxFrameBytes,
|
|
54
|
+
// With a local copy, the dial waits for it: the epoch it names is the copy's.
|
|
55
|
+
connect: local === undefined
|
|
56
|
+
});
|
|
57
|
+
const dial = () => provider._destroyed || provider.connect();
|
|
58
|
+
// A re-seed (`room.reseed.protocol`, a `4410` refusal): the local copy goes,
|
|
59
|
+
// its deletion waiting for every tab's connection to close.
|
|
60
|
+
provider.on('refused', ({ code }) => {
|
|
61
|
+
if (code !== CLOSE.reseeded || !loaded)
|
|
62
|
+
return;
|
|
63
|
+
void release?.();
|
|
64
|
+
void idb.clearDocument(persistName);
|
|
54
65
|
});
|
|
55
66
|
if (onExpired)
|
|
56
67
|
provider.on('expired', (state) => onExpired(state));
|
|
@@ -94,9 +105,17 @@ export const bindProviders = (Y) => {
|
|
|
94
105
|
});
|
|
95
106
|
}
|
|
96
107
|
let release = undefined;
|
|
108
|
+
// The store's load (or its failure) opens the dial.
|
|
109
|
+
const loaded = local &&
|
|
110
|
+
Object.assign((p) => local({
|
|
111
|
+
...p,
|
|
112
|
+
synced: (x) => (p.synced(x), dial()),
|
|
113
|
+
failed: (error, x) => (p.failed?.(error, x), dial())
|
|
114
|
+
}), local);
|
|
97
115
|
try {
|
|
98
116
|
// Called directly (no `attach`), the store only persists: readiness is the socket's.
|
|
99
|
-
release =
|
|
117
|
+
release =
|
|
118
|
+
loaded && (attach ? attach(loaded) : loaded({ doc, awareness, synced: () => { } }));
|
|
100
119
|
}
|
|
101
120
|
catch (error) {
|
|
102
121
|
provider.destroy();
|