edytor 7.0.0 → 7.0.2
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 +2 -2
- package/dist/components/Content.svelte +7 -16
- package/dist/components/Edytor.svelte +14 -5
- package/dist/components/Text.svelte +36 -33
- package/dist/components/Text.svelte.d.ts +2 -1
- package/dist/crdt/operations.d.ts +15 -0
- package/dist/crdt/placement/model.d.ts +5 -1
- package/dist/crdt/providers/room.js +1 -1
- package/dist/edytor.svelte.js +6 -3
- package/dist/events/onBeforeInput.js +7 -0
- package/dist/events/onKeyDown.js +3 -2
- package/dist/plugins/blockHandles/BlockHandles.svelte +32 -5
- package/dist/plugins/suggestions/shared.svelte.js +88 -27
- package/dist/session/attempt.d.ts +6 -0
- package/dist/session/attempt.js +6 -0
- package/dist/session/composition.svelte.js +19 -7
- package/dist/surface/cells.d.ts +7 -0
- package/dist/surface/cells.js +7 -0
- package/dist/surface/observer.svelte.js +17 -9
- 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
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
Edytor aims to be for Svelte what Slate.js is for React: a heavily customizable editor with an API to build any kind of collaborative rich text editor.
|
|
19
19
|
|
|
20
|
-
> **7.0.** Edytor `7.0.
|
|
20
|
+
> **7.0.** Edytor `7.0.2` is on npm as `edytor`: its API follows semantic versioning, and every change is listed in the changelog. It has no production track record yet: read the [limitations](https://edytor.dev/docs/reference/limitations) before you build on it. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
|
|
21
21
|
|
|
22
22
|
## Features
|
|
23
23
|
|
|
@@ -40,7 +40,7 @@ Edytor aims to be for Svelte what Slate.js is for React: a heavily customizable
|
|
|
40
40
|
|
|
41
41
|
## Install
|
|
42
42
|
|
|
43
|
-
Edytor `7.0.
|
|
43
|
+
Edytor `7.0.2` is on npm under `latest`:
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
46
|
pnpm add edytor
|
|
@@ -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
|
/><!--
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
spellcheck = true,
|
|
208
208
|
autocorrect = 'off',
|
|
209
209
|
autocomplete = 'off',
|
|
210
|
-
autocapitalize
|
|
210
|
+
autocapitalize,
|
|
211
211
|
inputmode,
|
|
212
212
|
enterkeyhint
|
|
213
213
|
}: EdytorProps & {
|
|
@@ -327,6 +327,8 @@
|
|
|
327
327
|
|
|
328
328
|
/** The chrome popup open on this view (`edytor.popups`): the root names it while it is. */
|
|
329
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');
|
|
330
332
|
|
|
331
333
|
// The display projector: the root `$effect.pre` notes the focused
|
|
332
334
|
// element before the flush writes the DOM; the root `$effect` — the last
|
|
@@ -368,11 +370,13 @@
|
|
|
368
370
|
autocorrect,
|
|
369
371
|
autocomplete,
|
|
370
372
|
autocapitalize,
|
|
371
|
-
|
|
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,
|
|
372
376
|
enterkeyhint
|
|
373
377
|
}}
|
|
374
378
|
data-edytor
|
|
375
|
-
data-edytor-selection={
|
|
379
|
+
data-edytor-selection={blocks ? 'blocks' : undefined}
|
|
376
380
|
contenteditable={!readonly}
|
|
377
381
|
role="textbox"
|
|
378
382
|
{id}
|
|
@@ -443,11 +447,16 @@
|
|
|
443
447
|
|
|
444
448
|
/*
|
|
445
449
|
* Room below the last block, where a press puts the caret in a trailing
|
|
446
|
-
* paragraph (`nav.trailing.press`): `--edytor-trailing-space`.
|
|
447
|
-
*
|
|
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.
|
|
448
456
|
*/
|
|
449
457
|
:global(:where([data-edytor])) {
|
|
450
458
|
padding-block-end: var(--edytor-trailing-space, 2em);
|
|
459
|
+
overflow-wrap: anywhere;
|
|
451
460
|
}
|
|
452
461
|
/*
|
|
453
462
|
* Long pages, opt-in: the `edytor-long-page` class on the editor or an
|
|
@@ -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`). */
|
|
@@ -24,6 +24,12 @@ import type { JSONBlock, JSONDoc, JSONInlineBlock, JSONText } from '../utils/jso
|
|
|
24
24
|
/** The document's writes: each one transaction, answering what it did (`OpResult`). */
|
|
25
25
|
export interface DocumentWrites {
|
|
26
26
|
insertBlocks(dest: Destination, specs: readonly (JSONBlock | BlockSpec)[]): OpResult;
|
|
27
|
+
/**
|
|
28
|
+
* Move `ids` (with their children), in order, to `dest`. Its `index`
|
|
29
|
+
* counts the parent's children without the moved blocks: to move a block
|
|
30
|
+
* one place right within its parent, give its index plus one (not plus
|
|
31
|
+
* two).
|
|
32
|
+
*/
|
|
27
33
|
moveBlocks(ids: readonly BlockId[], dest: Destination): OpResult;
|
|
28
34
|
nestBlock(id: BlockId, parent: BlockId): OpResult;
|
|
29
35
|
unNestBlock(id: BlockId): OpResult;
|
|
@@ -38,9 +44,18 @@ export interface DocumentWrites {
|
|
|
38
44
|
mergeBlocks(fromId: BlockId, intoId: BlockId): OpResult;
|
|
39
45
|
mergeBackward(id: BlockId): OpResult;
|
|
40
46
|
mergeForward(id: BlockId): OpResult;
|
|
47
|
+
/**
|
|
48
|
+
* Delete block `id`. Its children take its place (promoted into its
|
|
49
|
+
* parent) unless `keepChildren: false`, which deletes them with it, the
|
|
50
|
+
* whole subtree.
|
|
51
|
+
*/
|
|
41
52
|
deleteBlock(id: BlockId, options?: {
|
|
42
53
|
keepChildren?: boolean;
|
|
43
54
|
}): OpResult;
|
|
55
|
+
/**
|
|
56
|
+
* Delete `ids` as a block selection: only the members leave; a member's
|
|
57
|
+
* children that are not members take its place.
|
|
58
|
+
*/
|
|
44
59
|
deleteBlocks(ids: readonly BlockId[]): OpResult;
|
|
45
60
|
setBlock(id: BlockId, value: {
|
|
46
61
|
type?: string;
|
|
@@ -69,7 +69,11 @@ import { type BlockSlot, type Unit, type SeqItem, type Stamp } from './slots.js'
|
|
|
69
69
|
import { type SlotRef } from './resolve.js';
|
|
70
70
|
/** Logical block identifier — caller-assigned, immutable per block. */
|
|
71
71
|
export type BlockId = string;
|
|
72
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Where a block goes: `parent` = logical block id or `null` for root;
|
|
74
|
+
* `index` among its children. `moveBlocks` counts them without the moved
|
|
75
|
+
* blocks (within one parent, one place right of index `i` is `i + 1`).
|
|
76
|
+
*/
|
|
73
77
|
export type Destination = {
|
|
74
78
|
parent: BlockId | null;
|
|
75
79
|
index: number;
|
|
@@ -368,7 +368,7 @@ export const validRoomId = (id) => id.length > 0 && id.length <= 256 && id !== '
|
|
|
368
368
|
export const assertRoomId = (id) => {
|
|
369
369
|
if (validRoomId(id))
|
|
370
370
|
return;
|
|
371
|
-
throw new TypeError(`room id ${JSON.stringify(id)} cannot be dialed:
|
|
371
|
+
throw new TypeError(`room id ${JSON.stringify(id)} cannot be dialed: 1-256 characters, not "." or "..", no lone surrogate`);
|
|
372
372
|
};
|
|
373
373
|
/** A close code that refuses this client for good: policy (`1008`) or an application code (`4xxx`) but `expired`. */
|
|
374
374
|
export const isRefusal = (code) => code === CLOSE.refused || (code >= 4000 && code < 5000 && code !== CLOSE.expired);
|
package/dist/edytor.svelte.js
CHANGED
|
@@ -612,8 +612,11 @@ export class Edytor {
|
|
|
612
612
|
if (result && typeof result.then === 'function') {
|
|
613
613
|
// A failed async handler (a command's hook or write) surfaces
|
|
614
614
|
// through the platform's error reporting; the DOM ignores
|
|
615
|
-
// the listener's promise.
|
|
616
|
-
|
|
615
|
+
// the listener's promise. Read when one fails: a test DOM
|
|
616
|
+
// without it (happy-dom) only meets it then.
|
|
617
|
+
void Promise.resolve(result)
|
|
618
|
+
.finally(clear)
|
|
619
|
+
.catch((error) => reportError(error));
|
|
617
620
|
}
|
|
618
621
|
else {
|
|
619
622
|
clear();
|
|
@@ -735,7 +738,7 @@ export class Edytor {
|
|
|
735
738
|
if (!at)
|
|
736
739
|
return [];
|
|
737
740
|
const { cell, segment } = at;
|
|
738
|
-
return this.pin.shown(cell, segment, this.definitionOf(cell.type).transformText)
|
|
741
|
+
return this.pin.shown(cell, segment, this.definitionOf(cell.type).transformText);
|
|
739
742
|
};
|
|
740
743
|
/** @internal The handle of inline atom `atom`, shown in block `id`. */
|
|
741
744
|
atomAt = (id, atom) => this.idToBlock.atom(id, atom);
|
|
@@ -322,6 +322,7 @@ const runKeyAttempt = async (edytor, attempt) => {
|
|
|
322
322
|
// A real `beforeinput` or a newer key may have taken over meanwhile.
|
|
323
323
|
if (edytor.attempts.key !== attempt)
|
|
324
324
|
return;
|
|
325
|
+
edytor.attempts.ran = attempt.inputType;
|
|
325
326
|
await edytor.userInput(() => occur(edytor, { inputType: attempt.inputType, cancelable: false }, attempt, INTENTS[attempt.inputType]?.key ?? null, attempt));
|
|
326
327
|
};
|
|
327
328
|
export async function onBeforeInput(event) {
|
|
@@ -329,6 +330,12 @@ export async function onBeforeInput(event) {
|
|
|
329
330
|
const [key, offered] = keyed(this);
|
|
330
331
|
const { inputType } = event;
|
|
331
332
|
const kind = kindOf(inputType);
|
|
333
|
+
// The key the deadline ran, announced late (iOS's software keyboard,
|
|
334
|
+
// `sel.key.late-announcement`): that occurrence again, never run twice.
|
|
335
|
+
const ran = this.attempts.ran;
|
|
336
|
+
this.attempts.ran = null;
|
|
337
|
+
if (ran === inputType)
|
|
338
|
+
return event.preventDefault();
|
|
332
339
|
if (inputType === 'deleteByDrag' && event.isTrusted) {
|
|
333
340
|
event.preventDefault();
|
|
334
341
|
return this.selection.pointer.release();
|
package/dist/events/onKeyDown.js
CHANGED
|
@@ -73,8 +73,9 @@ const getStructuralFallbackInputType = (edytor, event) => {
|
|
|
73
73
|
return !isCollapsed || atBlockEdge || atTextEdge || atMarker ? intent : null;
|
|
74
74
|
};
|
|
75
75
|
export function onKeyDown(e) {
|
|
76
|
-
// A keydown the bindings are not offered offers no key to its `beforeinput
|
|
77
|
-
|
|
76
|
+
// A keydown the bindings are not offered offers no key to its `beforeinput`,
|
|
77
|
+
// and a key's late announcement comes before the next key's keydown.
|
|
78
|
+
this.keymap.offered = this.attempts.ran = null;
|
|
78
79
|
if (e.defaultPrevented) {
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
@@ -48,16 +48,28 @@
|
|
|
48
48
|
if (change.order.size || change.added.size || change.removed.size) structure++;
|
|
49
49
|
})
|
|
50
50
|
);
|
|
51
|
+
/**
|
|
52
|
+
* The blocks whose handle stays mounted beyond the near and hovered ones,
|
|
53
|
+
* and shows on a touch screen (no hover there): the selected blocks, the
|
|
54
|
+
* focused handle's, the dragged one. The blocks the selection's text is in
|
|
55
|
+
* show theirs too (`data-active`), mounted once near: a new block paints
|
|
56
|
+
* before its handle mounts (`handles.after-paint`).
|
|
57
|
+
*/
|
|
58
|
+
const active = $derived.by(() => {
|
|
59
|
+
const out = new Set<string>();
|
|
60
|
+
for (const block of edytor.selection.selectedBlocks) out.add(block.id);
|
|
61
|
+
if (focused !== null) out.add(focused);
|
|
62
|
+
if (controller.dragging) out.add(controller.dragging);
|
|
63
|
+
return out;
|
|
64
|
+
});
|
|
65
|
+
|
|
51
66
|
/**
|
|
52
67
|
* The few blocks that show a handle, sorted into document order: never a
|
|
53
68
|
* walk of the whole document (a structural commit on a long page).
|
|
54
69
|
*/
|
|
55
70
|
const ids = $derived.by(() => {
|
|
56
71
|
void structure;
|
|
57
|
-
const shown = new Set([...near, ...hovered]);
|
|
58
|
-
for (const block of edytor.selection.selectedBlocks) shown.add(block.id);
|
|
59
|
-
if (focused !== null) shown.add(focused);
|
|
60
|
-
if (controller.dragging) shown.add(controller.dragging);
|
|
72
|
+
const shown = new Set([...near, ...hovered, ...active]);
|
|
61
73
|
// Document order by index paths (O(depth) each): no whole-document order is rebuilt.
|
|
62
74
|
const paths = new Map<string, number[]>();
|
|
63
75
|
for (const id of shown) {
|
|
@@ -161,6 +173,9 @@
|
|
|
161
173
|
data-edytor-block-handle-host
|
|
162
174
|
data-block-id={id}
|
|
163
175
|
data-visible={hovered.has(id) ? 'true' : undefined}
|
|
176
|
+
data-active={active.has(id) || edytor.selection.projection.blocks.includes(id)
|
|
177
|
+
? 'true'
|
|
178
|
+
: undefined}
|
|
164
179
|
data-over-gap={overGaps.has(id) ? 'true' : undefined}
|
|
165
180
|
data-dragging={controller.dragging && controller.dragging !== id ? 'true' : undefined}
|
|
166
181
|
data-selecting={edytor.selection.dragging ? 'true' : undefined}
|
|
@@ -237,10 +252,22 @@
|
|
|
237
252
|
opacity: 1;
|
|
238
253
|
}
|
|
239
254
|
|
|
255
|
+
/* A touch screen has no hover: a handle shows for the block the selection
|
|
256
|
+
* is in (Notion's), never for a touched one (the hover a touch leaves
|
|
257
|
+
* behind), and only a shown one takes a tap, so a tap in the gutter never
|
|
258
|
+
* opens a hidden block's menu. A touch that showed a handle would also
|
|
259
|
+
* cost a tap: iOS Safari takes a touch whose hover reveals content as a
|
|
260
|
+
* hover only, and sends no click. */
|
|
240
261
|
@media (hover: none) {
|
|
241
262
|
[data-edytor-block-handle-host] {
|
|
242
|
-
opacity: 1;
|
|
243
263
|
padding-inline-end: 0;
|
|
244
264
|
}
|
|
265
|
+
[data-edytor-block-handle-host]:not([data-active='true']) {
|
|
266
|
+
opacity: 0;
|
|
267
|
+
pointer-events: none;
|
|
268
|
+
}
|
|
269
|
+
[data-edytor-block-handle-host][data-active='true'] {
|
|
270
|
+
opacity: 1;
|
|
271
|
+
}
|
|
245
272
|
}
|
|
246
273
|
</style>
|
|
@@ -33,8 +33,33 @@ import { Suggestion } from '../../session/suggestions.svelte.js';
|
|
|
33
33
|
import SuggestionRuns from './SuggestionRuns.svelte';
|
|
34
34
|
/** A block change's mark (`marked`): its kind's, but for these. */
|
|
35
35
|
const MARKS = { block: 'inserted', remove: 'removed' };
|
|
36
|
+
/** `block` without its ids (its children's too). */
|
|
37
|
+
const bare = ({ id: _, children, ...block }) => ({
|
|
38
|
+
...block,
|
|
39
|
+
...(children ? { children: children.map(bare) } : {})
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* A block's canonical key without its ids, kept per block object: a written
|
|
43
|
+
* block is never changed (its update is a new object), so each update keys
|
|
44
|
+
* only the new content.
|
|
45
|
+
*/
|
|
46
|
+
const keys = new WeakMap();
|
|
47
|
+
const keyOf = (block) => {
|
|
48
|
+
let key = keys.get(block);
|
|
49
|
+
if (key === undefined)
|
|
50
|
+
keys.set(block, (key = canonKey(bare(block))));
|
|
51
|
+
return key;
|
|
52
|
+
};
|
|
36
53
|
/** Two blocks alike but for their ids. */
|
|
37
|
-
const same = (a, b) =>
|
|
54
|
+
const same = (a, b) => keyOf(a) === keyOf(b);
|
|
55
|
+
/** `block` as written: with the ids `spec` gave it and its children. */
|
|
56
|
+
const withIds = (block, spec) => ({
|
|
57
|
+
...block,
|
|
58
|
+
id: spec.id,
|
|
59
|
+
...(block.children
|
|
60
|
+
? { children: block.children.map((child, i) => withIds(child, spec.children[i])) }
|
|
61
|
+
: {})
|
|
62
|
+
});
|
|
38
63
|
/**
|
|
39
64
|
* The runs `next` adds after `prev`'s content when it extends it (one kind
|
|
40
65
|
* and data, `prev`'s content its start), else `null`.
|
|
@@ -104,8 +129,10 @@ class Shared extends Suggestion {
|
|
|
104
129
|
get by() {
|
|
105
130
|
return this.#record?.by;
|
|
106
131
|
}
|
|
132
|
+
/** Its record's (none for one a member typed), else, before this view's first write, its option's. */
|
|
107
133
|
get via() {
|
|
108
|
-
|
|
134
|
+
const record = this.#record;
|
|
135
|
+
return record ? record.via : this.#via;
|
|
109
136
|
}
|
|
110
137
|
get changes() {
|
|
111
138
|
return this.#c.changes().filter((c) => c.suggestion === this.id);
|
|
@@ -187,8 +214,13 @@ export class SharedSuggestionsController {
|
|
|
187
214
|
const parent = 'inside' in resolved ? anchor : (facade.parentOf(anchor) ?? null);
|
|
188
215
|
const kind = document.defaultChild(parent === null ? null : (facade.blockTypeOf(parent) ?? null));
|
|
189
216
|
const status = options.status ?? (content === undefined ? 'streaming' : 'ready');
|
|
190
|
-
const suggestion =
|
|
191
|
-
|
|
217
|
+
const suggestion = new Shared(suggestions, resolved, kind, options, status);
|
|
218
|
+
// Added again under its id, it continues what the earlier one wrote: those
|
|
219
|
+
// blocks are brought to the new content, never left beside it.
|
|
220
|
+
const earlier = this.#mine.find((s) => s.id === suggestion.id);
|
|
221
|
+
if (earlier)
|
|
222
|
+
suggestion.written = earlier.written;
|
|
223
|
+
this.#mine = [...this.#mine.filter((s) => s !== earlier), suggestion];
|
|
192
224
|
if (content !== undefined)
|
|
193
225
|
suggestion.update(content);
|
|
194
226
|
suggestions.revision++;
|
|
@@ -199,10 +231,17 @@ export class SharedSuggestionsController {
|
|
|
199
231
|
this.#mine = this.#mine.filter((s) => s !== suggestion);
|
|
200
232
|
this.edytor.suggestions.revision++;
|
|
201
233
|
};
|
|
202
|
-
/**
|
|
234
|
+
/**
|
|
235
|
+
* @internal The list with the shared ones (`Suggestions.shared`): this
|
|
236
|
+
* view's while it streams, has pending changes or has written nothing yet
|
|
237
|
+
* (no block, no proposed deletion: it waits for its content), so a decided
|
|
238
|
+
* one leaves; then the others'.
|
|
239
|
+
*/
|
|
203
240
|
list = (mine) => {
|
|
204
241
|
const shared = new Set(this.changes().map((c) => c.suggestion));
|
|
205
|
-
const own = this.#mine.filter((s) => s.status === 'streaming' ||
|
|
242
|
+
const own = this.#mine.filter((s) => s.status === 'streaming' ||
|
|
243
|
+
shared.has(s.id) ||
|
|
244
|
+
!(s.written.length || (s.at && 'replace' in s.at)));
|
|
206
245
|
for (const s of own)
|
|
207
246
|
shared.delete(s.id);
|
|
208
247
|
const others = [...shared].map((id) => this.#others.get(id) ??
|
|
@@ -303,9 +342,8 @@ export class SharedSuggestionsController {
|
|
|
303
342
|
/**
|
|
304
343
|
* @internal Write shared `suggestion`'s content as it is now (`update`,
|
|
305
344
|
* `append`), live (`sugg.ai.live`): the first time at its position (a
|
|
306
|
-
* `replace` proposed for deletion), then only what changed
|
|
307
|
-
*
|
|
308
|
-
* it, the rest replaced. Its own writer's blocks, outside the undo history.
|
|
345
|
+
* `replace` proposed for deletion), then only what changed (`#sync`). Its
|
|
346
|
+
* own writer's blocks, outside the undo history.
|
|
309
347
|
*/
|
|
310
348
|
write = (suggestion) => {
|
|
311
349
|
const { facade, dispatcher } = this.edytor;
|
|
@@ -331,31 +369,54 @@ export class SharedSuggestionsController {
|
|
|
331
369
|
}
|
|
332
370
|
}
|
|
333
371
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
372
|
+
this.#sync(put, prev, next, () => this.#slot(at));
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Bring `prev` (the blocks written, with their ids) to `next`: the equal
|
|
377
|
+
* blocks kept; the last one grown in place, its text extended when the new
|
|
378
|
+
* one extends it, or, the same block but for its children, its children
|
|
379
|
+
* brought along the same way (a code block's lines); the rest replaced,
|
|
380
|
+
* deleted with their children and the new ones inserted after the kept
|
|
381
|
+
* ones, else at `start`.
|
|
382
|
+
*/
|
|
383
|
+
#sync = (put, prev, next, start) => {
|
|
384
|
+
const { facade } = this.edytor;
|
|
385
|
+
const { prepare } = facade;
|
|
386
|
+
let p = 0;
|
|
387
|
+
while (p < prev.length && p < next.length && same(prev[p], next[p]))
|
|
388
|
+
p++;
|
|
389
|
+
if (p === prev.length - 1 && p < next.length) {
|
|
390
|
+
const [old, now] = [prev[p], next[p]];
|
|
391
|
+
const block = old.id;
|
|
392
|
+
// Its own fields alike (its children aside) and children still: those grow.
|
|
393
|
+
const children = now.children?.length && same({ ...old, children: [] }, { ...now, children: [] })
|
|
394
|
+
? [...(old.children ?? [])]
|
|
395
|
+
: null;
|
|
396
|
+
const runs = children ? null : grown(old, now);
|
|
397
|
+
if (runs)
|
|
340
398
|
for (const run of runs) {
|
|
341
399
|
const offset = facade.displayLength(block);
|
|
342
400
|
put('text' in run
|
|
343
401
|
? prepare.insertText(block, offset, run.text, run.marks ?? {})
|
|
344
402
|
: prepare.insertInline(block, offset, run));
|
|
345
403
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
put(prepare.deleteBlocks(doomed));
|
|
352
|
-
const specs = next.slice(p).map((b) => jsonBlockToSpec(b, true));
|
|
353
|
-
const dest = p ? facade.positionOf(prev[p - 1].id) : this.#slot(at);
|
|
354
|
-
if (specs.length && dest) {
|
|
355
|
-
put(prepare.insertBlocks({ parent: dest.parent, index: dest.index + (p ? 1 : 0) }, specs));
|
|
356
|
-
prev.push(...specs.map((spec, i) => ({ ...next[p + i], id: spec.id })));
|
|
404
|
+
else if (children)
|
|
405
|
+
this.#sync(put, children, now.children ?? [], () => ({ parent: block, index: 0 }));
|
|
406
|
+
if (runs || children) {
|
|
407
|
+
const kept = children ?? old.children;
|
|
408
|
+
prev[p++] = { ...now, id: block, ...(kept ? { children: kept } : {}) };
|
|
357
409
|
}
|
|
358
|
-
}
|
|
410
|
+
}
|
|
411
|
+
// The replaced blocks go whole: a code block's lines are its own.
|
|
412
|
+
for (const { id } of prev.splice(p))
|
|
413
|
+
put(prepare.deleteBlock(id, { keepChildren: false }));
|
|
414
|
+
const specs = next.slice(p).map((b) => jsonBlockToSpec(b, true));
|
|
415
|
+
const dest = p ? facade.positionOf(prev[p - 1].id) : start();
|
|
416
|
+
if (specs.length && dest) {
|
|
417
|
+
put(prepare.insertBlocks({ parent: dest.parent, index: dest.index + (p ? 1 : 0) }, specs));
|
|
418
|
+
prev.push(...specs.map((spec, i) => withIds(next[p + i], spec)));
|
|
419
|
+
}
|
|
359
420
|
};
|
|
360
421
|
/** Where a shared suggestion's blocks go: its position's slot (a `replace`: after what it replaces). */
|
|
361
422
|
#slot = (at) => {
|
|
@@ -180,6 +180,12 @@ export declare class Attempts {
|
|
|
180
180
|
private closed;
|
|
181
181
|
/** The last attempt admitted. */
|
|
182
182
|
last: Attempt | null;
|
|
183
|
+
/**
|
|
184
|
+
* The intent the missing-`beforeinput` deadline ran for the keydown: its
|
|
185
|
+
* `beforeinput` may still come, before the next keydown
|
|
186
|
+
* (`sel.key.late-announcement`).
|
|
187
|
+
*/
|
|
188
|
+
ran?: string | null;
|
|
183
189
|
/** `closed`: an attempt closed (its deadline, a newer one): the observer compares again. */
|
|
184
190
|
constructor(closed?: () => void);
|
|
185
191
|
/** Queue `attempt`; a model-owned one supersedes every live attempt, a browser-owned one the browser-owned ones. */
|
package/dist/session/attempt.js
CHANGED
|
@@ -145,6 +145,12 @@ export class Attempts {
|
|
|
145
145
|
#timers = new Map();
|
|
146
146
|
/** The last attempt admitted. */
|
|
147
147
|
last = null;
|
|
148
|
+
/**
|
|
149
|
+
* The intent the missing-`beforeinput` deadline ran for the keydown: its
|
|
150
|
+
* `beforeinput` may still come, before the next keydown
|
|
151
|
+
* (`sel.key.late-announcement`).
|
|
152
|
+
*/
|
|
153
|
+
ran;
|
|
148
154
|
/** `closed`: an attempt closed (its deadline, a newer one): the observer compares again. */
|
|
149
155
|
constructor(closed = () => { }) {
|
|
150
156
|
this.closed = closed;
|
|
@@ -117,9 +117,11 @@ export class Composition {
|
|
|
117
117
|
// With no target, the caret the browser parked for the IME.
|
|
118
118
|
const parked = targetless && dom?.anchorNode;
|
|
119
119
|
const point = parked ? this.edytor.ports.surface.pointAt(parked, dom.anchorOffset) : null;
|
|
120
|
+
// With no target the value is `none`: nothing to replace.
|
|
121
|
+
const replaced = shown === 'blocks' || shown === 'atom' || blocks;
|
|
120
122
|
const at = targetless
|
|
121
123
|
? point && { text: point.text, from: point.offset, to: point.offset }
|
|
122
|
-
:
|
|
124
|
+
: replaced
|
|
123
125
|
? this.#rangeless()
|
|
124
126
|
: startText && {
|
|
125
127
|
text: startText,
|
|
@@ -127,7 +129,7 @@ export class Composition {
|
|
|
127
129
|
to: endText === startText ? yEnd : startText.length
|
|
128
130
|
};
|
|
129
131
|
if (at)
|
|
130
|
-
this.#pin(at.text, at.from, at.to);
|
|
132
|
+
this.#pin(at.text, at.from, at.to, replaced);
|
|
131
133
|
this.host = at?.text ?? null;
|
|
132
134
|
this.#where = this.#place();
|
|
133
135
|
};
|
|
@@ -291,8 +293,8 @@ export class Composition {
|
|
|
291
293
|
* and remove the render's anchors between them before the change renders
|
|
292
294
|
* (Firefox, `ime.range.blocks`). Its start target is replaced now (blocks:
|
|
293
295
|
* `flow.slot`, one empty block in their place; an atom: removed; a range:
|
|
294
|
-
* its blocks merged around the caret)
|
|
295
|
-
* caret
|
|
296
|
+
* its blocks merged around the caret) and the change rendered; `#pin`
|
|
297
|
+
* parks the DOM caret where the preview goes before the IME writes
|
|
296
298
|
* (`projector.park`, the DOM-selection writer). When the replacement is
|
|
297
299
|
* refused, the IME writes where Escape leaves for (`selectedBlocksExit`;
|
|
298
300
|
* an atom or a range: before it) and the tail restores it: nothing is
|
|
@@ -310,7 +312,6 @@ export class Composition {
|
|
|
310
312
|
flushSync();
|
|
311
313
|
if (!at.text.node)
|
|
312
314
|
return null;
|
|
313
|
-
edytor.ports.surface.park(at.text, at.offset);
|
|
314
315
|
return { text: at.text, from: at.offset, to: at.offset };
|
|
315
316
|
}
|
|
316
317
|
/**
|
|
@@ -402,14 +403,25 @@ export class Composition {
|
|
|
402
403
|
this.edytor.facade.deleteText(blockId, offset, length);
|
|
403
404
|
this.#own.clear();
|
|
404
405
|
}
|
|
405
|
-
/**
|
|
406
|
-
|
|
406
|
+
/**
|
|
407
|
+
* Pin the host's cell and segment: the renderer never rewrites the IME's
|
|
408
|
+
* node (`surface/pin`). The DOM caret is parked where the preview goes
|
|
409
|
+
* when the start target was `replaced` (`#rangeless`), and in an empty
|
|
410
|
+
* host, which shows its filler text node from now on, not the `<br>` of
|
|
411
|
+
* an empty line: the IME composes into a node the render owns
|
|
412
|
+
* (`ime.empty.filler`).
|
|
413
|
+
*/
|
|
414
|
+
#pin(host, from, to, replaced) {
|
|
407
415
|
const { edytor } = this;
|
|
408
416
|
const at = edytor.segmentOf(host);
|
|
409
417
|
if (!at)
|
|
410
418
|
return;
|
|
411
419
|
const transform = edytor.definitionOf(at.cell.type).transformText;
|
|
412
420
|
edytor.pin.acquire(at.cell, at.segment, transform, from, to, host.node ?? null);
|
|
421
|
+
if (!replaced && at.segment.text)
|
|
422
|
+
return;
|
|
423
|
+
flushSync();
|
|
424
|
+
edytor.ports.surface.park(host, from);
|
|
413
425
|
}
|
|
414
426
|
/** A mechanical tracked write: the region holds `value`. */
|
|
415
427
|
#write(value) {
|
package/dist/surface/cells.d.ts
CHANGED
|
@@ -57,6 +57,13 @@ export type RenderDelta = {
|
|
|
57
57
|
/** Mark entries in nesting order (the first run's order when runs merge). */
|
|
58
58
|
readonly marks: readonly (readonly [string, unknown])[];
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* The text node an empty text renders where a `<br>` would break its line
|
|
62
|
+
* (beside an atom or a suggestion), or where the IME composes (`Pin.shown`):
|
|
63
|
+
* a zero-width space. An empty text alone in its block renders a `<br>`, so
|
|
64
|
+
* a phone's keyboard finds nothing before the caret and capitalizes.
|
|
65
|
+
*/
|
|
66
|
+
export declare const FILLER: readonly RenderDelta[];
|
|
60
67
|
/** One delta per maximal stretch of equal marks; empty runs render nothing. */
|
|
61
68
|
export declare const renderDeltas: (items: readonly {
|
|
62
69
|
text: string;
|
package/dist/surface/cells.js
CHANGED
|
@@ -145,6 +145,13 @@ export const rendersMark = (marks, name) => {
|
|
|
145
145
|
const mark = marks.get(name);
|
|
146
146
|
return Boolean(mark?.tag || mark?.snippet);
|
|
147
147
|
};
|
|
148
|
+
/**
|
|
149
|
+
* The text node an empty text renders where a `<br>` would break its line
|
|
150
|
+
* (beside an atom or a suggestion), or where the IME composes (`Pin.shown`):
|
|
151
|
+
* a zero-width space. An empty text alone in its block renders a `<br>`, so
|
|
152
|
+
* a phone's keyboard finds nothing before the caret and capitalizes.
|
|
153
|
+
*/
|
|
154
|
+
export const FILLER = [{ text: '\u200B', marks: [] }];
|
|
148
155
|
/** Mark payloads compare by canonical value: key-sorted, `undefined` values dropped. */
|
|
149
156
|
const marksKey = (marks) => marks
|
|
150
157
|
? JSON.stringify(Object.entries(marks)
|
|
@@ -46,7 +46,7 @@ import { getDomSelectionSnapshot } from '../selection/domSelection.js';
|
|
|
46
46
|
import { domOffsetIn } from '../selection/selection.utils.js';
|
|
47
47
|
import { diverges, heal, ownText, ownedOf } from './attributes.js';
|
|
48
48
|
import { getTextContentOffsetAtPoint, textLeaves } from '../events/domTextOffset.js';
|
|
49
|
-
import { rendersMark } from './cells.js';
|
|
49
|
+
import { FILLER, rendersMark } from './cells.js';
|
|
50
50
|
/** The empty filler (and the trailing newline's marker). */
|
|
51
51
|
const ZWSP = '\u200B';
|
|
52
52
|
const ATOM = '\uFFFC';
|
|
@@ -682,11 +682,12 @@ export class SurfaceObserver {
|
|
|
682
682
|
};
|
|
683
683
|
/**
|
|
684
684
|
* Equal text, compared structurally: each text element (a strict
|
|
685
|
-
* container) holds one node per render delta
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
685
|
+
* container) holds one node per render delta — a text node, or a
|
|
686
|
+
* registered mark element whose registered marks follow the delta's
|
|
687
|
+
* chain and that renders one text node — and an empty one its filler's
|
|
688
|
+
* (a `<br>`, or the zero-width text node). Svelte's anchors and the newline
|
|
689
|
+
* marker stand for none. Answers whether it differs; `write`: a content
|
|
690
|
+
* that does not gets each delta's text back in its node.
|
|
690
691
|
*/
|
|
691
692
|
#shape = (id, write) => {
|
|
692
693
|
const { edytor } = this;
|
|
@@ -696,7 +697,7 @@ export class SurfaceObserver {
|
|
|
696
697
|
if (!element)
|
|
697
698
|
continue;
|
|
698
699
|
const deltas = edytor.deltasOf(text);
|
|
699
|
-
const shown = deltas.length ? deltas :
|
|
700
|
+
const shown = deltas.length ? deltas : FILLER;
|
|
700
701
|
const nodes = [...element.childNodes].filter((node) => !isAnchor(node) &&
|
|
701
702
|
!(node instanceof Element && node.hasAttribute('data-edytor-trailing-newline')));
|
|
702
703
|
if (nodes.length !== shown.length)
|
|
@@ -719,6 +720,8 @@ export class SurfaceObserver {
|
|
|
719
720
|
return true;
|
|
720
721
|
leaf = leaves[0];
|
|
721
722
|
}
|
|
723
|
+
else if (node.nodeName === 'BR' && shown === FILLER)
|
|
724
|
+
continue;
|
|
722
725
|
else if (node.nodeType !== Node.TEXT_NODE)
|
|
723
726
|
return true;
|
|
724
727
|
if (leaf.data !== delta.text)
|
|
@@ -939,8 +942,13 @@ export const adopt = async (edytor, text, dom, domCaret, prefer) => {
|
|
|
939
942
|
return;
|
|
940
943
|
// The render patches only the runs the command changed: when the one
|
|
941
944
|
// insertion rule (`marksForInsertion`) gave the text other marks than the
|
|
942
|
-
// node the browser wrote, that node
|
|
943
|
-
|
|
945
|
+
// node the browser wrote, or that node is not the render's (the text was
|
|
946
|
+
// empty, `grow` is all of it: the browser typed into its `<br>`), that
|
|
947
|
+
// node keeps its copy — re-render.
|
|
948
|
+
if (grow === value.length ||
|
|
949
|
+
!adopted ||
|
|
950
|
+
drifted ||
|
|
951
|
+
(insert && shown !== modelMarks(edytor, text, at)))
|
|
944
952
|
text.refreshFromModel();
|
|
945
953
|
// Deferred past the re-render (selecting in the same turn left the
|
|
946
954
|
// native caret at 0), so it checks the gesture serial: a gesture since the
|
|
@@ -38,16 +38,13 @@ export declare class Pin {
|
|
|
38
38
|
owns: (node: Node | null | undefined) => boolean;
|
|
39
39
|
/** The segment list `cell` renders: frozen while it hosts the pin. */
|
|
40
40
|
parts: (cell: Cell) => readonly Part[];
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
shown: (cell: Cell, segment: Segment, transform: TextTransform | undefined) =>
|
|
48
|
-
deltas: RenderDelta[];
|
|
49
|
-
empty: boolean;
|
|
50
|
-
};
|
|
41
|
+
/**
|
|
42
|
+
* The render of `segment` of `cell`: its kind's (`segmentDeltas`), or the
|
|
43
|
+
* pinned one while it hosts the IME, an empty host's the filler text node
|
|
44
|
+
* (never the `<br>` of an empty line): the IME composes into a node the
|
|
45
|
+
* render owns.
|
|
46
|
+
*/
|
|
47
|
+
shown: (cell: Cell, segment: Segment, transform: TextTransform | undefined) => readonly RenderDelta[];
|
|
51
48
|
/** What follows the pinned segment `key` of `block` in its own element (`merge`). */
|
|
52
49
|
rest: (block: BlockId, key: string) => RenderDelta[];
|
|
53
50
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { partsOf, renderDeltas, segmentDeltas } from './cells.js';
|
|
1
|
+
import { FILLER, partsOf, renderDeltas, segmentDeltas } from './cells.js';
|
|
2
2
|
const textOf = (items) => items.map((item) => item.text).join('');
|
|
3
3
|
/** The items of `deltas` before and after unit `at`. */
|
|
4
4
|
const cut = (deltas, at) => {
|
|
@@ -25,7 +25,6 @@ export class Pin {
|
|
|
25
25
|
key: segment.key,
|
|
26
26
|
parts: partsOf(cell.runs),
|
|
27
27
|
frozen,
|
|
28
|
-
empty: segment.text === '',
|
|
29
28
|
head: cut(frozen, from)[0],
|
|
30
29
|
tail: cut(frozen, Math.max(from, to))[1],
|
|
31
30
|
merged: [],
|
|
@@ -62,21 +61,19 @@ export class Pin {
|
|
|
62
61
|
owns = (node) => Boolean(node && this.#held?.element?.contains(node));
|
|
63
62
|
/** The segment list `cell` renders: frozen while it hosts the pin. */
|
|
64
63
|
parts = (cell) => this.#held?.block === cell.id ? this.#held.parts : partsOf(cell.runs);
|
|
65
|
-
/**
|
|
66
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The render of `segment` of `cell`: its kind's (`segmentDeltas`), or the
|
|
66
|
+
* pinned one while it hosts the IME, an empty host's the filler text node
|
|
67
|
+
* (never the `<br>` of an empty line): the IME composes into a node the
|
|
68
|
+
* render owns.
|
|
69
|
+
*/
|
|
70
|
+
shown = (cell, segment, transform) => {
|
|
67
71
|
const held = this.#held;
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
72
|
+
if (held?.block !== cell.id || held.key !== segment.key)
|
|
73
|
+
return segmentDeltas(cell, segment, transform);
|
|
70
74
|
const { preview, head, tail } = held;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const items = [...head, preview, ...tail];
|
|
74
|
-
return { deltas: renderDeltas(items), empty: !textOf(items) };
|
|
75
|
-
};
|
|
76
|
-
/** The render of `segment` of `cell`: pinned while it hosts the IME, else its kind's (`segmentDeltas`). */
|
|
77
|
-
shown = (cell, segment, transform) => this.render(cell.id, segment.key) ?? {
|
|
78
|
-
deltas: segmentDeltas(cell, segment, transform),
|
|
79
|
-
empty: segment.text === ''
|
|
75
|
+
const deltas = !preview || preview.native ? held.frozen : renderDeltas([...head, preview, ...tail]);
|
|
76
|
+
return deltas.length ? deltas : FILLER;
|
|
80
77
|
};
|
|
81
78
|
/** What follows the pinned segment `key` of `block` in its own element (`merge`). */
|
|
82
79
|
rest = (block, key) => {
|
|
@@ -80,9 +80,12 @@ export declare class Projector {
|
|
|
80
80
|
*/
|
|
81
81
|
pressed: () => void;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
* `selectionchange`
|
|
85
|
-
* runs input ahead of it on a busy main thread)
|
|
83
|
+
* The DOM selection moved since the last observation, its
|
|
84
|
+
* `selectionchange` still queued (`sel.key.before-adoption`; Chromium
|
|
85
|
+
* runs input ahead of it on a busy main thread): a press placed a caret,
|
|
86
|
+
* or the browser moved it for a key of its own (an arrow, Shift+arrow:
|
|
87
|
+
* Mod+B right after Shift+→ held down acts on the whole extension). A key
|
|
88
|
+
* reads the DOM first.
|
|
86
89
|
*/
|
|
87
90
|
unobserved: () => boolean;
|
|
88
91
|
/**
|
|
@@ -218,17 +218,22 @@ export class Projector {
|
|
|
218
218
|
#unreported = () => {
|
|
219
219
|
const { edytor } = this;
|
|
220
220
|
const { selection } = edytor;
|
|
221
|
-
|
|
222
|
-
const node = edytor.node;
|
|
223
|
-
if (!at || !node || selection.value.kind !== 'text' || edytor.intentSerial !== this.#serial)
|
|
221
|
+
if (selection.value.kind !== 'text' || edytor.intentSerial !== this.#serial)
|
|
224
222
|
return false;
|
|
225
223
|
if (selection.request !== this.#request || selection.dragging || edytor.composition.live)
|
|
226
224
|
return false;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
225
|
+
return this.#moved();
|
|
226
|
+
};
|
|
227
|
+
/** The DOM selection in the host is no longer where the last observation found it. */
|
|
228
|
+
#moved = () => {
|
|
229
|
+
const at = this.#at;
|
|
230
|
+
const node = this.edytor.node;
|
|
231
|
+
const dom = node && getDomSelection(node);
|
|
232
|
+
return (!!at &&
|
|
233
|
+
!!dom &&
|
|
234
|
+
isOwnPoint(node, dom.anchorNode) &&
|
|
235
|
+
!(samePoint(at.anchor, dom.anchorNode, dom.anchorOffset) &&
|
|
236
|
+
samePoint(at.focus, dom.focusNode, dom.focusOffset)));
|
|
232
237
|
};
|
|
233
238
|
/**
|
|
234
239
|
* Classify a `selectionchange` by comparing the DOM selection with the
|
|
@@ -302,11 +307,14 @@ export class Projector {
|
|
|
302
307
|
this.#press = this.edytor.intentSerial;
|
|
303
308
|
};
|
|
304
309
|
/**
|
|
305
|
-
*
|
|
306
|
-
* `selectionchange`
|
|
307
|
-
* runs input ahead of it on a busy main thread)
|
|
310
|
+
* The DOM selection moved since the last observation, its
|
|
311
|
+
* `selectionchange` still queued (`sel.key.before-adoption`; Chromium
|
|
312
|
+
* runs input ahead of it on a busy main thread): a press placed a caret,
|
|
313
|
+
* or the browser moved it for a key of its own (an arrow, Shift+arrow:
|
|
314
|
+
* Mod+B right after Shift+→ held down acts on the whole extension). A key
|
|
315
|
+
* reads the DOM first.
|
|
308
316
|
*/
|
|
309
|
-
unobserved = () => this.#press > this.#serial;
|
|
317
|
+
unobserved = () => this.#press > this.#serial || this.#moved();
|
|
310
318
|
/**
|
|
311
319
|
* Whether the host holds a DOM caret a gesture may have placed: a range
|
|
312
320
|
* inside it that is not the browser's parked one (`parked`; a key such as
|
package/dist/themes/notion.css
CHANGED
|
@@ -369,6 +369,13 @@
|
|
|
369
369
|
.edytor-notion button[data-edytor-callout-icon][data-empty]:focus-visible::before {
|
|
370
370
|
opacity: 1;
|
|
371
371
|
}
|
|
372
|
+
/* A touch screen shows it: a touch that revealed it would cost the tap (iOS
|
|
373
|
+
* Safari takes it for a hover and sends no click). */
|
|
374
|
+
@media (hover: none) {
|
|
375
|
+
.edytor-notion button[data-edytor-callout-icon][data-empty]::before {
|
|
376
|
+
opacity: 1;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
372
379
|
/* No icon in a readonly view: the text starts at the panel's edge. */
|
|
373
380
|
.edytor-notion [data-edytor-type='callout']:not(:has(> [data-edytor-callout-icon])) {
|
|
374
381
|
grid-template-columns: minmax(0, 1fr);
|