edytor 0.1.0-next.26 → 0.1.0-next.28
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 +1 -1
- package/dist/block/inlineBlock.svelte.js +3 -0
- package/dist/selection/replaceSelection.d.ts +10 -12
- package/dist/selection/replaceSelection.js +19 -21
- package/dist/selection/selection.svelte.js +19 -12
- package/dist/surface/projector.svelte.d.ts +9 -4
- package/dist/surface/projector.svelte.js +16 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
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.
|
|
17
17
|
|
|
18
|
-
> **Work in progress.** Edytor is a pre-release (`0.1.0-next.
|
|
18
|
+
> **Work in progress.** Edytor is a pre-release (`0.1.0-next.28`, `edytor@next` on npm) and not ready for production; the API changes between releases without a compatibility layer. The untagged `edytor@0.0.11` on npm predates the current API. Issues and PRs are welcome: when you report a bug, include the document's JSON value.
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
@@ -88,6 +88,9 @@ export class InlineBlock {
|
|
|
88
88
|
return selection.setAtTextOffset(after, 0);
|
|
89
89
|
selection.selectInlineBlock(this);
|
|
90
90
|
clearDomSelection(this.edytor.node);
|
|
91
|
+
// The atom took the press: the caret the browser still leaves for it
|
|
92
|
+
// (Chromium parks one at the host's start before the release) is its own.
|
|
93
|
+
this.edytor.projector.parked();
|
|
91
94
|
};
|
|
92
95
|
node.addEventListener('pointerdown', selectInlineBlock);
|
|
93
96
|
return {
|
|
@@ -49,18 +49,16 @@ export declare const flipToggles: (blocks: readonly Block[]) => void;
|
|
|
49
49
|
*/
|
|
50
50
|
export declare const liftLayouts: (blocks: Iterable<Block>) => Block[];
|
|
51
51
|
/**
|
|
52
|
-
* A pointer
|
|
53
|
-
* `
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* layout, or one that starts outside it). Decided from the roles
|
|
63
|
-
* (`isLayout`/`isLayoutItem`).
|
|
52
|
+
* A pointer selection (a drag, a Shift+click) from `anchor` to `focus`,
|
|
53
|
+
* Notion's rule (`sel.drag.across-columns`): once one end is in a column
|
|
54
|
+
* and the other is not in that column (another column of its layout, or
|
|
55
|
+
* outside the layout), it selects blocks — every shown block from one to
|
|
56
|
+
* the other in reading order, but the layouts and columns themselves (each
|
|
57
|
+
* block a member as `selectedMembers` reads it), so a sweep over every
|
|
58
|
+
* block of every column lifts to the layout (`liftLayouts`, D3). `null` (a
|
|
59
|
+
* text range) while both ends lie in the same columns (one column, or none:
|
|
60
|
+
* a range that runs over a whole layout from above it to below it stays
|
|
61
|
+
* text). Decided from the roles (`isLayoutItem`).
|
|
64
62
|
*/
|
|
65
63
|
export declare const acrossColumns: (anchor: Block, focus: Block) => Block[] | null;
|
|
66
64
|
/** Whether a block selection holds `blocks`, a layout it covers whole counting as held (D3). */
|
|
@@ -92,31 +92,29 @@ export const liftLayouts = (blocks) => {
|
|
|
92
92
|
return [...all];
|
|
93
93
|
};
|
|
94
94
|
/**
|
|
95
|
-
* A pointer
|
|
96
|
-
* `
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* layout, or one that starts outside it). Decided from the roles
|
|
106
|
-
* (`isLayout`/`isLayoutItem`).
|
|
95
|
+
* A pointer selection (a drag, a Shift+click) from `anchor` to `focus`,
|
|
96
|
+
* Notion's rule (`sel.drag.across-columns`): once one end is in a column
|
|
97
|
+
* and the other is not in that column (another column of its layout, or
|
|
98
|
+
* outside the layout), it selects blocks — every shown block from one to
|
|
99
|
+
* the other in reading order, but the layouts and columns themselves (each
|
|
100
|
+
* block a member as `selectedMembers` reads it), so a sweep over every
|
|
101
|
+
* block of every column lifts to the layout (`liftLayouts`, D3). `null` (a
|
|
102
|
+
* text range) while both ends lie in the same columns (one column, or none:
|
|
103
|
+
* a range that runs over a whole layout from above it to below it stays
|
|
104
|
+
* text). Decided from the roles (`isLayoutItem`).
|
|
107
105
|
*/
|
|
108
106
|
export const acrossColumns = (anchor, focus) => {
|
|
109
107
|
const { edytor } = anchor;
|
|
110
108
|
const { facade } = edytor;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
109
|
+
const columns = (block) => {
|
|
110
|
+
const items = new Set();
|
|
111
|
+
for (let at = block.parent; at && !at.isRoot; at = at.parent)
|
|
112
|
+
if (facade.isLayoutItem(at.id))
|
|
113
|
+
items.add(at.id);
|
|
114
|
+
return items;
|
|
115
|
+
};
|
|
116
|
+
const [from, to] = [columns(anchor), columns(focus)];
|
|
117
|
+
if (from.size === to.size && [...from].every((id) => to.has(id)))
|
|
120
118
|
return null;
|
|
121
119
|
const [first, last] = edytor.compareBlocks(anchor, focus) <= 0 ? [anchor, focus] : [focus, anchor];
|
|
122
120
|
const blocks = [];
|
|
@@ -662,6 +662,7 @@ export class EdytorSelection {
|
|
|
662
662
|
}
|
|
663
663
|
this.pointerDragStart = this.getTextPointFromClientPoint(event.clientX, event.clientY);
|
|
664
664
|
this.#across = false;
|
|
665
|
+
this.#extending = event.shiftKey;
|
|
665
666
|
};
|
|
666
667
|
clearPointerDragStart = () => {
|
|
667
668
|
this.pointerDragStart = null;
|
|
@@ -671,6 +672,8 @@ export class EdytorSelection {
|
|
|
671
672
|
#held = false;
|
|
672
673
|
/** The pointer drag selected blocks across columns (`acrossColumns`), until its release. */
|
|
673
674
|
#across = false;
|
|
675
|
+
/** The press held Shift: it extends the range it found (a Shift+click). */
|
|
676
|
+
#extending = false;
|
|
674
677
|
/**
|
|
675
678
|
* The drag ended: the DOM selection it left is derived again, now
|
|
676
679
|
* normalized. A drag that ends as a block selection across columns keeps
|
|
@@ -678,6 +681,11 @@ export class EdytorSelection {
|
|
|
678
681
|
* selection as no range).
|
|
679
682
|
*/
|
|
680
683
|
#dropped = () => {
|
|
684
|
+
// A Shift+press's range can reach the adopter only after its release
|
|
685
|
+
// (Chromium queues its `selectionchange`): read here, as the press's.
|
|
686
|
+
if (this.#extending && !this.#across)
|
|
687
|
+
this.#dragAcross(getDomSelectionSnapshot(this.edytor.node));
|
|
688
|
+
this.#extending = false;
|
|
681
689
|
const across = this.#across;
|
|
682
690
|
this.#across = false;
|
|
683
691
|
if (across && this.value.kind === 'blocks') {
|
|
@@ -690,25 +698,24 @@ export class EdytorSelection {
|
|
|
690
698
|
this.applySelectionSnapshot(getDomSelectionSnapshot(this.edytor.node));
|
|
691
699
|
};
|
|
692
700
|
/**
|
|
693
|
-
* Under a pointer drag, a
|
|
694
|
-
*
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
* Answers whether it selected blocks.
|
|
701
|
+
* Under a pointer press (a drag, or a Shift+click extending the range it
|
|
702
|
+
* found), a native range with one end in a column and the other outside
|
|
703
|
+
* that column (another column, or outside the layout) is a block
|
|
704
|
+
* selection (`acrossColumns`, Notion): the blocks it covers are selected
|
|
705
|
+
* and the native range is ignored — the browser keeps extending it, so
|
|
706
|
+
* the drag coming back into the anchor's columns is a text range again.
|
|
707
|
+
* Its highlight is hidden while the value is a block selection
|
|
708
|
+
* (`data-edytor-selection`). The keyboard's ranges stay text ranges in
|
|
709
|
+
* document order (D7). Answers whether it selected blocks.
|
|
703
710
|
*/
|
|
704
711
|
#dragAcross = (dom) => {
|
|
705
712
|
if (!dom?.anchorNode || !dom.focusNode || dom.isCollapsed)
|
|
706
713
|
return false;
|
|
707
714
|
const anchor = this.getTextOfNode(dom.anchorNode, dom.anchorOffset)?.parent;
|
|
708
715
|
const focus = this.getTextOfNode(dom.focusNode, dom.focusOffset)?.parent;
|
|
709
|
-
if (!anchor
|
|
716
|
+
if (!anchor)
|
|
710
717
|
return false;
|
|
711
|
-
const blocks = focus && !anchor.isRoot && acrossColumns(anchor, focus);
|
|
718
|
+
const blocks = focus && !anchor.isRoot && !focus.isRoot && acrossColumns(anchor, focus);
|
|
712
719
|
if (!blocks || !blocks.length)
|
|
713
720
|
return false;
|
|
714
721
|
this.#across = true;
|
|
@@ -35,7 +35,8 @@ export declare class Projector {
|
|
|
35
35
|
* - drift: no gesture since the last observation, and a render since it
|
|
36
36
|
* (a flush the DOM selection was not observed after, or DOM records the
|
|
37
37
|
* observer has not reconciled), or one of the two named signatures,
|
|
38
|
-
* or the caret a browser parks for the editor's own focus
|
|
38
|
+
* or the caret a browser parks for the editor's own focus, a refused key
|
|
39
|
+
* or an atom's press (`parked`);
|
|
39
40
|
* - intent: a gesture since the last observation, or a pointer drag;
|
|
40
41
|
* - foreign: no gesture and no render (host code, assistive tech, O1).
|
|
41
42
|
*/
|
|
@@ -44,9 +45,13 @@ export declare class Projector {
|
|
|
44
45
|
* The browser parks a caret of its own, at the host's start: the editor
|
|
45
46
|
* focused its own host (`takeKeys`: the keys after a gesture on its
|
|
46
47
|
* chrome), or a key the attempt refused for want of a target
|
|
47
|
-
* (`targetless`: Chromium places a caret for it)
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
* (`targetless`: Chromium places a caret for it), or an atom took a press
|
|
49
|
+
* (`InlineBlock.attach`: Chromium parks one for it before the release).
|
|
50
|
+
* Until the next gesture that caret is drift, displayed over by the value —
|
|
51
|
+
* a block selection, an atom or none shows no DOM range — never adopted;
|
|
52
|
+
* under none or an atom, until a press inside or a focus from outside
|
|
53
|
+
* (`pressed`), an adopted move or our own display, whatever key or release
|
|
54
|
+
* came since.
|
|
50
55
|
*/
|
|
51
56
|
parked: () => void;
|
|
52
57
|
/**
|
|
@@ -193,7 +193,8 @@ export class Projector {
|
|
|
193
193
|
* - drift: no gesture since the last observation, and a render since it
|
|
194
194
|
* (a flush the DOM selection was not observed after, or DOM records the
|
|
195
195
|
* observer has not reconciled), or one of the two named signatures,
|
|
196
|
-
* or the caret a browser parks for the editor's own focus
|
|
196
|
+
* or the caret a browser parks for the editor's own focus, a refused key
|
|
197
|
+
* or an atom's press (`parked`);
|
|
197
198
|
* - intent: a gesture since the last observation, or a pointer drag;
|
|
198
199
|
* - foreign: no gesture and no render (host code, assistive tech, O1).
|
|
199
200
|
*/
|
|
@@ -216,8 +217,10 @@ export class Projector {
|
|
|
216
217
|
if (this.#parked === edytor.intentSerial)
|
|
217
218
|
return 'drift';
|
|
218
219
|
// With no value, a caret no press placed stays the browser's, whatever key
|
|
219
|
-
// came since (Mod+Z, Escape: Chromium parks one at the host's start)
|
|
220
|
-
|
|
220
|
+
// came since (Mod+Z, Escape: Chromium parks one at the host's start); over
|
|
221
|
+
// an atom a press selected, so does the one the browser parks for that
|
|
222
|
+
// press, whatever its release marked (`parked`).
|
|
223
|
+
if (this.#parking && (selection.value.kind === 'none' || selection.value.kind === 'atom'))
|
|
221
224
|
return 'drift';
|
|
222
225
|
if (edytor.intentSerial === this.#serial && (this.#snapBack(dom) || this.#jump()))
|
|
223
226
|
return 'drift';
|
|
@@ -231,9 +234,13 @@ export class Projector {
|
|
|
231
234
|
* The browser parks a caret of its own, at the host's start: the editor
|
|
232
235
|
* focused its own host (`takeKeys`: the keys after a gesture on its
|
|
233
236
|
* chrome), or a key the attempt refused for want of a target
|
|
234
|
-
* (`targetless`: Chromium places a caret for it)
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
+
* (`targetless`: Chromium places a caret for it), or an atom took a press
|
|
238
|
+
* (`InlineBlock.attach`: Chromium parks one for it before the release).
|
|
239
|
+
* Until the next gesture that caret is drift, displayed over by the value —
|
|
240
|
+
* a block selection, an atom or none shows no DOM range — never adopted;
|
|
241
|
+
* under none or an atom, until a press inside or a focus from outside
|
|
242
|
+
* (`pressed`), an adopted move or our own display, whatever key or release
|
|
243
|
+
* came since.
|
|
237
244
|
*/
|
|
238
245
|
parked = () => {
|
|
239
246
|
this.#parked = this.edytor.intentSerial;
|
|
@@ -369,7 +376,9 @@ export class Projector {
|
|
|
369
376
|
// A block set or an atom shows as selected elements, not a range.
|
|
370
377
|
// Displayed even when the DOM already holds no range (the atom's
|
|
371
378
|
// own pointerdown cleared it): a caret the browser parks later
|
|
372
|
-
// without a gesture (focusing the host) is then drift, not intent
|
|
379
|
+
// without a gesture (focusing the host) is then drift, not intent;
|
|
380
|
+
// the one it parks for the atom's press is drift through its release
|
|
381
|
+
// (`parked`).
|
|
373
382
|
const inside = Boolean(dom.anchorNode && node.contains(dom.anchorNode));
|
|
374
383
|
if ((inside || dom.rangeCount === 0) && this.#ours(requested)) {
|
|
375
384
|
if (inside)
|