quoin-editor 1.0.2 → 1.1.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/CHANGELOG.md +32 -0
- package/dist/ai.cjs +169 -249
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.js +38 -121
- package/dist/ai.js.map +1 -1
- package/dist/catalogue.cjs +29 -43
- package/dist/catalogue.cjs.map +1 -1
- package/dist/catalogue.js +21 -37
- package/dist/catalogue.js.map +1 -1
- package/dist/{chunk-DUE3HCZD.js → chunk-2EQ6FKSK.js} +19 -28
- package/dist/chunk-2EQ6FKSK.js.map +1 -0
- package/dist/{chunk-RJRX34BZ.js → chunk-3BXUGX5F.js} +4 -18
- package/dist/chunk-3BXUGX5F.js.map +1 -0
- package/dist/chunk-3QRVAI53.cjs +27 -0
- package/dist/chunk-3QRVAI53.cjs.map +1 -0
- package/dist/{chunk-U3LOLYAU.js → chunk-7FAVFJAS.js} +4 -10
- package/dist/chunk-7FAVFJAS.js.map +1 -0
- package/dist/{chunk-FDRUAL3Z.cjs → chunk-7NAONESM.cjs} +90 -153
- package/dist/chunk-7NAONESM.cjs.map +1 -0
- package/dist/{chunk-6V6GGBDK.cjs → chunk-7SVKLWDT.cjs} +24 -31
- package/dist/chunk-7SVKLWDT.cjs.map +1 -0
- package/dist/{chunk-CW3AFJBR.cjs → chunk-7XQGOCUG.cjs} +1332 -1772
- package/dist/chunk-7XQGOCUG.cjs.map +1 -0
- package/dist/{chunk-EH5KXQXY.cjs → chunk-A6PGQVTR.cjs} +36 -20
- package/dist/chunk-A6PGQVTR.cjs.map +1 -0
- package/dist/{chunk-4SLJNZSM.cjs → chunk-AIS37SL2.cjs} +201 -198
- package/dist/chunk-AIS37SL2.cjs.map +1 -0
- package/dist/{chunk-IQBMAE3F.js → chunk-CKHKCPGL.js} +34 -92
- package/dist/chunk-CKHKCPGL.js.map +1 -0
- package/dist/{chunk-T43RZTUT.js → chunk-DYWU4SQ2.js} +723 -1246
- package/dist/chunk-DYWU4SQ2.js.map +1 -0
- package/dist/chunk-EFRQMYZ6.cjs +33 -0
- package/dist/chunk-EFRQMYZ6.cjs.map +1 -0
- package/dist/{chunk-O4Z2WMFF.js → chunk-HDJ653LM.js} +25 -18
- package/dist/chunk-HDJ653LM.js.map +1 -0
- package/dist/chunk-HQ43EIYO.cjs +94 -0
- package/dist/chunk-HQ43EIYO.cjs.map +1 -0
- package/dist/{chunk-6NULZPVC.js → chunk-HTLWPSMU.js} +8 -61
- package/dist/chunk-HTLWPSMU.js.map +1 -0
- package/dist/{chunk-EPARJI4V.js → chunk-IEP7BPFN.js} +122 -267
- package/dist/chunk-IEP7BPFN.js.map +1 -0
- package/dist/{chunk-P6KYXFZC.cjs → chunk-IGZRZIAF.cjs} +440 -538
- package/dist/chunk-IGZRZIAF.cjs.map +1 -0
- package/dist/chunk-JCEFSTVG.cjs +483 -0
- package/dist/chunk-JCEFSTVG.cjs.map +1 -0
- package/dist/chunk-KXRGY5LK.cjs +612 -0
- package/dist/chunk-KXRGY5LK.cjs.map +1 -0
- package/dist/{chunk-JHQUHFLX.js → chunk-KZ6ZFCGO.js} +38 -120
- package/dist/chunk-KZ6ZFCGO.js.map +1 -0
- package/dist/{chunk-ADSJ42DO.js → chunk-L2QA2UTY.js} +17 -69
- package/dist/chunk-L2QA2UTY.js.map +1 -0
- package/dist/{chunk-OBMBSU2S.js → chunk-L4D23LM2.js} +5 -184
- package/dist/chunk-L4D23LM2.js.map +1 -0
- package/dist/{chunk-4XFXB37X.js → chunk-L6OW2FL3.js} +7 -90
- package/dist/chunk-L6OW2FL3.js.map +1 -0
- package/dist/chunk-LE5XMIFJ.cjs +4 -3
- package/dist/chunk-LE5XMIFJ.cjs.map +1 -1
- package/dist/chunk-MQUCCSWG.js +2 -3
- package/dist/chunk-MQUCCSWG.js.map +1 -1
- package/dist/{chunk-C23RQVRK.js → chunk-MUIPM26J.js} +66 -216
- package/dist/chunk-MUIPM26J.js.map +1 -0
- package/dist/{chunk-AUOEM3SF.cjs → chunk-OKWER2RV.cjs} +102 -155
- package/dist/chunk-OKWER2RV.cjs.map +1 -0
- package/dist/{chunk-TLGX43P6.cjs → chunk-OM7E43ZN.cjs} +89 -86
- package/dist/chunk-OM7E43ZN.cjs.map +1 -0
- package/dist/{chunk-NEZJ7ZP5.js → chunk-QSXPKZ2F.js} +4 -8
- package/dist/chunk-QSXPKZ2F.js.map +1 -0
- package/dist/{chunk-VCLL5C7J.js → chunk-RFLFRIPV.js} +14 -57
- package/dist/chunk-RFLFRIPV.js.map +1 -0
- package/dist/chunk-RIIXJWBR.cjs +24 -0
- package/dist/chunk-RIIXJWBR.cjs.map +1 -0
- package/dist/{chunk-VRS6WCEK.js → chunk-SFMORPWB.js} +60 -167
- package/dist/chunk-SFMORPWB.js.map +1 -0
- package/dist/{chunk-YBMUEEM5.js → chunk-TYZSB7JT.js} +4 -8
- package/dist/chunk-TYZSB7JT.js.map +1 -0
- package/dist/{chunk-BQANU5BH.cjs → chunk-U5BSCAMP.cjs} +34 -44
- package/dist/chunk-U5BSCAMP.cjs.map +1 -0
- package/dist/{chunk-OSHZQR3W.js → chunk-UEVR4B5S.js} +13 -45
- package/dist/chunk-UEVR4B5S.js.map +1 -0
- package/dist/{chunk-N4FGA3H4.js → chunk-VBJY2CSK.js} +38 -105
- package/dist/chunk-VBJY2CSK.js.map +1 -0
- package/dist/{chunk-ZKVOS57Q.cjs → chunk-VFSVN5IQ.cjs} +495 -551
- package/dist/chunk-VFSVN5IQ.cjs.map +1 -0
- package/dist/{chunk-X4HDKFW5.cjs → chunk-VNRI5DAL.cjs} +56 -105
- package/dist/chunk-VNRI5DAL.cjs.map +1 -0
- package/dist/chunk-W7B4WQ3L.cjs +200 -0
- package/dist/chunk-W7B4WQ3L.cjs.map +1 -0
- package/dist/{chunk-623AOJM2.js → chunk-WAGBELKA.js} +7 -25
- package/dist/chunk-WAGBELKA.js.map +1 -0
- package/dist/{chunk-WEYDDIBQ.cjs → chunk-WH56EW3H.cjs} +36 -64
- package/dist/chunk-WH56EW3H.cjs.map +1 -0
- package/dist/{chunk-5MAYUGTE.cjs → chunk-XAS7LANM.cjs} +233 -363
- package/dist/chunk-XAS7LANM.cjs.map +1 -0
- package/dist/comments.cjs +210 -290
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +82 -186
- package/dist/comments.js.map +1 -1
- package/dist/diff.cjs +48 -65
- package/dist/diff.cjs.map +1 -1
- package/dist/diff.d.cts +2 -2
- package/dist/diff.d.ts +2 -2
- package/dist/diff.js +8 -32
- package/dist/diff.js.map +1 -1
- package/dist/docx.cjs +50 -63
- package/dist/docx.cjs.map +1 -1
- package/dist/docx.js +7 -22
- package/dist/docx.js.map +1 -1
- package/dist/embed.cjs +19 -12
- package/dist/embed.cjs.map +1 -1
- package/dist/embed.js +10 -16
- package/dist/embed.js.map +1 -1
- package/dist/emoji-data.cjs +7 -5
- package/dist/emoji-data.cjs.map +1 -1
- package/dist/emoji-data.js +3 -5
- package/dist/emoji-data.js.map +1 -1
- package/dist/emoji.cjs +26 -17
- package/dist/emoji.cjs.map +1 -1
- package/dist/emoji.js +9 -17
- package/dist/emoji.js.map +1 -1
- package/dist/engine.cjs +229 -118
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.js +4 -118
- package/dist/engine.js.map +1 -1
- package/dist/find.cjs +30 -19
- package/dist/find.cjs.map +1 -1
- package/dist/find.js +9 -19
- package/dist/find.js.map +1 -1
- package/dist/headless.cjs +291 -151
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.cts +5 -1
- package/dist/headless.d.ts +5 -1
- package/dist/headless.js +6 -151
- package/dist/headless.js.map +1 -1
- package/dist/index.cjs +349 -183
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +8 -183
- package/dist/index.js.map +1 -1
- package/dist/math.cjs +20 -13
- package/dist/math.cjs.map +1 -1
- package/dist/math.js +11 -17
- package/dist/math.js.map +1 -1
- package/dist/mention.cjs +20 -13
- package/dist/mention.cjs.map +1 -1
- package/dist/mention.js +11 -17
- package/dist/mention.js.map +1 -1
- package/dist/presence.cjs +99 -132
- package/dist/presence.cjs.map +1 -1
- package/dist/presence.js +22 -78
- package/dist/presence.js.map +1 -1
- package/dist/{registry-CWBOSAHm.d.ts → registry-CXegaw5k.d.cts} +25 -2
- package/dist/{registry-CWBOSAHm.d.cts → registry-CXegaw5k.d.ts} +25 -2
- package/dist/stats.cjs +27 -18
- package/dist/stats.cjs.map +1 -1
- package/dist/stats.js +10 -18
- package/dist/stats.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/table.cjs +90 -49
- package/dist/table.cjs.map +1 -1
- package/dist/table.js +9 -49
- package/dist/table.js.map +1 -1
- package/dist/toc.cjs +26 -17
- package/dist/toc.cjs.map +1 -1
- package/dist/toc.js +9 -17
- package/dist/toc.js.map +1 -1
- package/dist/view.cjs +13 -16
- package/dist/view.cjs.map +1 -1
- package/dist/view.d.cts +2 -2
- package/dist/view.d.ts +2 -2
- package/dist/view.js +7 -16
- package/dist/view.js.map +1 -1
- package/dist/yjs.cjs +186 -228
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +12 -80
- package/dist/yjs.js.map +1 -1
- package/package.json +2 -1
- package/dist/chunk-4SLJNZSM.cjs.map +0 -1
- package/dist/chunk-4XFXB37X.js.map +0 -1
- package/dist/chunk-5MAYUGTE.cjs.map +0 -1
- package/dist/chunk-623AOJM2.js.map +0 -1
- package/dist/chunk-6NULZPVC.js.map +0 -1
- package/dist/chunk-6V6GGBDK.cjs.map +0 -1
- package/dist/chunk-73653CJ4.cjs +0 -34
- package/dist/chunk-73653CJ4.cjs.map +0 -1
- package/dist/chunk-ADSJ42DO.js.map +0 -1
- package/dist/chunk-AUOEM3SF.cjs.map +0 -1
- package/dist/chunk-BQANU5BH.cjs.map +0 -1
- package/dist/chunk-C23RQVRK.js.map +0 -1
- package/dist/chunk-CW3AFJBR.cjs.map +0 -1
- package/dist/chunk-DUE3HCZD.js.map +0 -1
- package/dist/chunk-EH5KXQXY.cjs.map +0 -1
- package/dist/chunk-EPARJI4V.js.map +0 -1
- package/dist/chunk-FDRUAL3Z.cjs.map +0 -1
- package/dist/chunk-IQBMAE3F.js.map +0 -1
- package/dist/chunk-JHQUHFLX.js.map +0 -1
- package/dist/chunk-KUYZMSMF.cjs +0 -100
- package/dist/chunk-KUYZMSMF.cjs.map +0 -1
- package/dist/chunk-LLTEGXWZ.cjs +0 -562
- package/dist/chunk-LLTEGXWZ.cjs.map +0 -1
- package/dist/chunk-N4FGA3H4.js.map +0 -1
- package/dist/chunk-NEZJ7ZP5.js.map +0 -1
- package/dist/chunk-O4Z2WMFF.js.map +0 -1
- package/dist/chunk-OBMBSU2S.js.map +0 -1
- package/dist/chunk-OSHZQR3W.js.map +0 -1
- package/dist/chunk-P6KYXFZC.cjs.map +0 -1
- package/dist/chunk-R2BLBV43.cjs +0 -239
- package/dist/chunk-R2BLBV43.cjs.map +0 -1
- package/dist/chunk-RJRX34BZ.js.map +0 -1
- package/dist/chunk-T43RZTUT.js.map +0 -1
- package/dist/chunk-TLGX43P6.cjs.map +0 -1
- package/dist/chunk-U3LOLYAU.js.map +0 -1
- package/dist/chunk-UEKXVCKC.cjs +0 -716
- package/dist/chunk-UEKXVCKC.cjs.map +0 -1
- package/dist/chunk-VCLL5C7J.js.map +0 -1
- package/dist/chunk-VRS6WCEK.js.map +0 -1
- package/dist/chunk-WEYDDIBQ.cjs.map +0 -1
- package/dist/chunk-X4HDKFW5.cjs.map +0 -1
- package/dist/chunk-X4P4TQXH.cjs +0 -30
- package/dist/chunk-X4P4TQXH.cjs.map +0 -1
- package/dist/chunk-XA3UEJIW.cjs +0 -25
- package/dist/chunk-XA3UEJIW.cjs.map +0 -1
- package/dist/chunk-YBMUEEM5.js.map +0 -1
- package/dist/chunk-ZKVOS57Q.cjs.map +0 -1
|
@@ -1,79 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkVFSVN5IQ_cjs = require('./chunk-VFSVN5IQ.cjs');
|
|
4
|
+
var chunkAIS37SL2_cjs = require('./chunk-AIS37SL2.cjs');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var reactDom = require('react-dom');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
3
8
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var _chunkZKVOS57Qcjs = require('./chunk-ZKVOS57Q.cjs');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var _chunk4SLJNZSMcjs = require('./chunk-4SLJNZSM.cjs');
|
|
66
|
-
|
|
67
|
-
// src/view/react/use-editor-state.ts
|
|
68
|
-
var _react = require('react');
|
|
69
9
|
var wholeState = (state) => state;
|
|
70
10
|
function useEditorState(controller, selector, isEqual = Object.is) {
|
|
71
|
-
const last =
|
|
72
|
-
const subscribe =
|
|
11
|
+
const last = react.useRef(null);
|
|
12
|
+
const subscribe = react.useCallback(
|
|
73
13
|
(notify) => controller.editor.subscribe(() => notify()),
|
|
74
14
|
[controller]
|
|
75
15
|
);
|
|
76
|
-
const getSnapshot =
|
|
16
|
+
const getSnapshot = react.useCallback(() => {
|
|
77
17
|
const { state } = controller.editor;
|
|
78
18
|
const previous = last.current;
|
|
79
19
|
if (previous !== null && previous.state === state && previous.selector === selector) return previous.value;
|
|
@@ -82,19 +22,19 @@ function useEditorState(controller, selector, isEqual = Object.is) {
|
|
|
82
22
|
last.current = { state, selector, value };
|
|
83
23
|
return value;
|
|
84
24
|
}, [controller, selector, isEqual]);
|
|
85
|
-
return
|
|
25
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
86
26
|
}
|
|
87
27
|
|
|
88
28
|
// src/view/selection/selection-decorations.ts
|
|
89
29
|
var SELECTED = { class: "quoin-selected" };
|
|
90
30
|
function isCrossSelection(selection) {
|
|
91
|
-
if (
|
|
31
|
+
if (selection?.kind !== "text") return false;
|
|
92
32
|
const { anchor, head } = selection;
|
|
93
33
|
return anchor.block !== head.block || anchor.region !== head.region;
|
|
94
34
|
}
|
|
95
35
|
function selectionDecorations(state, mode) {
|
|
96
36
|
if (mode !== "decorations" || !isCrossSelection(state.selection)) return [];
|
|
97
|
-
return
|
|
37
|
+
return chunkVFSVN5IQ_cjs.markRanges(state).map(({ block, region, from, to }) => ({
|
|
98
38
|
kind: "inline",
|
|
99
39
|
block,
|
|
100
40
|
region,
|
|
@@ -105,9 +45,9 @@ function selectionDecorations(state, mode) {
|
|
|
105
45
|
}
|
|
106
46
|
|
|
107
47
|
// src/view/dom/attributes.ts
|
|
108
|
-
var sortedEntries = (attrs) =>
|
|
48
|
+
var sortedEntries = (attrs) => chunkAIS37SL2_cjs.dataAttributes(attrs, "");
|
|
109
49
|
function setAttributes(element, attrs, prefix = "") {
|
|
110
|
-
for (const [name, value] of
|
|
50
|
+
for (const [name, value] of chunkAIS37SL2_cjs.writtenAttrs(chunkAIS37SL2_cjs.dataAttributes(attrs, prefix))) element.setAttribute(name, value);
|
|
111
51
|
}
|
|
112
52
|
|
|
113
53
|
// src/view/dom/segments.ts
|
|
@@ -122,9 +62,9 @@ function decorationRanges(decorations, length) {
|
|
|
122
62
|
return ranges;
|
|
123
63
|
}
|
|
124
64
|
function toSegments(inline, decorations) {
|
|
125
|
-
const length =
|
|
65
|
+
const length = chunkAIS37SL2_cjs.inlineLength(inline);
|
|
126
66
|
const ranges = decorationRanges(decorations, length);
|
|
127
|
-
const widgets = decorations.filter((decoration) => decoration.kind === "widget").map((decoration) => ({ decoration, at: Math.min(Math.max(decoration.offset, 0), length) })).sort((a, b) => a.at - b.at || (
|
|
67
|
+
const widgets = decorations.filter((decoration) => decoration.kind === "widget").map((decoration) => ({ decoration, at: Math.min(Math.max(decoration.offset, 0), length) })).sort((a, b) => a.at - b.at || (a.decoration.side ?? 1) - (b.decoration.side ?? 1));
|
|
128
68
|
const edges = [...ranges.flatMap((range) => [range.from, range.to]), ...widgets.map((widget) => widget.at)];
|
|
129
69
|
const cuts = [...new Set(edges)].filter((point) => point > 0 && point < length).sort((a, b) => a - b);
|
|
130
70
|
const covering = (from, to) => ranges.filter((range) => range.from <= from && range.to >= to).map((range) => range.attrs);
|
|
@@ -138,7 +78,7 @@ function toSegments(inline, decorations) {
|
|
|
138
78
|
};
|
|
139
79
|
let start = 0;
|
|
140
80
|
for (const node of inline) {
|
|
141
|
-
const end = start +
|
|
81
|
+
const end = start + chunkAIS37SL2_cjs.nodeLength(node);
|
|
142
82
|
if (node.kind === "atom") {
|
|
143
83
|
placeWidgets(start);
|
|
144
84
|
segments.push({ kind: "atom", node, decorations: covering(start, end), from: start });
|
|
@@ -181,6 +121,11 @@ function segmentSignature(segment) {
|
|
|
181
121
|
}
|
|
182
122
|
}
|
|
183
123
|
|
|
124
|
+
// src/view/dom/decoration-attrs.ts
|
|
125
|
+
function withoutEventHandlers(attrs) {
|
|
126
|
+
return Object.fromEntries(Object.entries(attrs).filter(([name]) => !/^on/i.test(name)));
|
|
127
|
+
}
|
|
128
|
+
|
|
184
129
|
// src/view/dom/mark-elements.ts
|
|
185
130
|
function create(doc, tag, attributes) {
|
|
186
131
|
const element = doc.createElement(tag);
|
|
@@ -188,7 +133,7 @@ function create(doc, tag, attributes) {
|
|
|
188
133
|
return element;
|
|
189
134
|
}
|
|
190
135
|
function linkElement({ href = "", title } = {}, doc) {
|
|
191
|
-
const safe =
|
|
136
|
+
const safe = chunkAIS37SL2_cjs.sanitizeHref(href);
|
|
192
137
|
if (safe === null) return create(doc, "span", [["data-quoin-link", ""]]);
|
|
193
138
|
const anchor = create(doc, "a", [["href", safe], ["data-quoin-link", ""]]);
|
|
194
139
|
if (title) anchor.title = title;
|
|
@@ -196,8 +141,8 @@ function linkElement({ href = "", title } = {}, doc) {
|
|
|
196
141
|
}
|
|
197
142
|
function markElement2(mark2, doc) {
|
|
198
143
|
if (mark2.type === "link") return linkElement(mark2.attrs, doc);
|
|
199
|
-
const { tag, attrs } =
|
|
200
|
-
return create(doc, tag,
|
|
144
|
+
const { tag, attrs } = chunkAIS37SL2_cjs.markElement(mark2);
|
|
145
|
+
return create(doc, tag, chunkAIS37SL2_cjs.writtenAttrs(attrs));
|
|
201
146
|
}
|
|
202
147
|
|
|
203
148
|
// src/view/dom/wrappers.ts
|
|
@@ -205,7 +150,7 @@ var created = /* @__PURE__ */ new WeakSet();
|
|
|
205
150
|
function decorationElement(attrs, doc) {
|
|
206
151
|
const element = doc.createElement("span");
|
|
207
152
|
element.setAttribute("data-quoin-deco", "");
|
|
208
|
-
setAttributes(element, attrs);
|
|
153
|
+
setAttributes(element, withoutEventHandlers(attrs));
|
|
209
154
|
return element;
|
|
210
155
|
}
|
|
211
156
|
function wrapperDepth(marks, decorations) {
|
|
@@ -239,8 +184,8 @@ function wrapperEntries(wrappers, from, to) {
|
|
|
239
184
|
|
|
240
185
|
// src/view/dom/atom-specs.ts
|
|
241
186
|
function defaultAtomText(node) {
|
|
242
|
-
if (node.type === "mention") return `@${
|
|
243
|
-
return node.type === "math" ?
|
|
187
|
+
if (node.type === "mention") return `@${node.attrs.label ?? ""}`;
|
|
188
|
+
return node.type === "math" ? node.attrs.latex ?? "" : node.type;
|
|
244
189
|
}
|
|
245
190
|
function mark(element, attribute, name) {
|
|
246
191
|
element.setAttribute("contenteditable", "false");
|
|
@@ -265,10 +210,10 @@ function atomSpec(segment, options, doc) {
|
|
|
265
210
|
sig: segmentSignature(segment),
|
|
266
211
|
create() {
|
|
267
212
|
const render = own(options.atoms, node.type);
|
|
268
|
-
const content = render ? mark(render(node, doc), "data-quoin-atom", node.type) : defaultAtom(node, doc,
|
|
213
|
+
const content = render ? mark(render(node, doc), "data-quoin-atom", node.type) : defaultAtom(node, doc, options.atomText ?? defaultAtomText);
|
|
269
214
|
const wrappers = createWrappers(node.marks, decorations, doc);
|
|
270
|
-
|
|
271
|
-
return
|
|
215
|
+
wrappers[wrappers.length - 1]?.appendChild(content);
|
|
216
|
+
return wrappers[0] ?? content;
|
|
272
217
|
},
|
|
273
218
|
refresh(top) {
|
|
274
219
|
const chain = unwrap(top, depth);
|
|
@@ -285,7 +230,7 @@ function widgetSpec(segment, options, doc) {
|
|
|
285
230
|
return {
|
|
286
231
|
sig: segmentSignature(segment),
|
|
287
232
|
create() {
|
|
288
|
-
const render =
|
|
233
|
+
const render = own(options.widgets, decoration.widget) ?? defaultWidget;
|
|
289
234
|
return mark(render(decoration, doc), "data-quoin-widget", decoration.widget);
|
|
290
235
|
},
|
|
291
236
|
describe: (node, out) => void out.push({ node, from, to: from, kind: "widget" })
|
|
@@ -294,7 +239,7 @@ function widgetSpec(segment, options, doc) {
|
|
|
294
239
|
|
|
295
240
|
// src/view/dom/dom-map.ts
|
|
296
241
|
var TEXT_NODE = 3;
|
|
297
|
-
var textLength = (node) => (
|
|
242
|
+
var textLength = (node) => (node.textContent ?? "").length;
|
|
298
243
|
var indexIn = (node) => Array.prototype.indexOf.call(node.parentNode.childNodes, node);
|
|
299
244
|
var pointAt = (entry, shift) => ({
|
|
300
245
|
node: entry.node.parentNode,
|
|
@@ -326,13 +271,13 @@ function createDomMap(host, length, entries) {
|
|
|
326
271
|
const at = Math.min(Math.max(offset, 0), length);
|
|
327
272
|
const after = texts.find((entry) => entry.from <= at && at < entry.to);
|
|
328
273
|
const before = texts.find((entry) => entry.from < at && at <= entry.to);
|
|
329
|
-
const text = assoc === 1 ?
|
|
274
|
+
const text = assoc === 1 ? after ?? before : before ?? after;
|
|
330
275
|
if (text) return { node: text.node, offset: at - text.from };
|
|
331
276
|
const next = stops.find((entry) => entry.from >= at);
|
|
332
277
|
const previous = breaksAndAtoms.filter((entry) => entry.to <= at).pop();
|
|
333
278
|
const beforeNext = next && pointAt(next, 0);
|
|
334
279
|
const afterPrevious = previous && pointAt(previous, 1);
|
|
335
|
-
return
|
|
280
|
+
return (assoc === 1 ? beforeNext ?? afterPrevious : afterPrevious ?? beforeNext) ?? { node: host, offset: 0 };
|
|
336
281
|
}
|
|
337
282
|
function atChild(parent, offset, end) {
|
|
338
283
|
const children = parent.childNodes;
|
|
@@ -345,7 +290,7 @@ function createDomMap(host, length, entries) {
|
|
|
345
290
|
function enclosingAtom(node) {
|
|
346
291
|
for (let current = node; current && current !== host; current = current.parentNode) {
|
|
347
292
|
const entry = byNode.get(current);
|
|
348
|
-
if (
|
|
293
|
+
if (entry?.kind === "atom" || entry?.kind === "widget") return entry;
|
|
349
294
|
}
|
|
350
295
|
return void 0;
|
|
351
296
|
}
|
|
@@ -353,7 +298,7 @@ function createDomMap(host, length, entries) {
|
|
|
353
298
|
if (!host.contains(node)) return null;
|
|
354
299
|
if (node === host) return atChild(host, offset, length);
|
|
355
300
|
const atom = enclosingAtom(node);
|
|
356
|
-
if (
|
|
301
|
+
if (atom?.kind === "widget") return atom.from;
|
|
357
302
|
if (atom) {
|
|
358
303
|
const inside = textBefore(atom.node, node, offset);
|
|
359
304
|
return inside > 0 && inside * 2 >= textLength(atom.node) ? atom.to : atom.from;
|
|
@@ -370,7 +315,7 @@ function createDomMap(host, length, entries) {
|
|
|
370
315
|
// src/view/dom/reconcile.ts
|
|
371
316
|
var signatures = /* @__PURE__ */ new WeakMap();
|
|
372
317
|
function keeps(node, spec) {
|
|
373
|
-
return signatures.get(node) === spec.sig && (
|
|
318
|
+
return signatures.get(node) === spec.sig && (spec.refresh?.(node) ?? true);
|
|
374
319
|
}
|
|
375
320
|
function reconcileChildren(parent, specs) {
|
|
376
321
|
const old = Array.from(parent.childNodes);
|
|
@@ -382,7 +327,7 @@ function reconcileChildren(parent, specs) {
|
|
|
382
327
|
oldEnd--;
|
|
383
328
|
newEnd--;
|
|
384
329
|
}
|
|
385
|
-
const anchor =
|
|
330
|
+
const anchor = old[oldEnd] ?? null;
|
|
386
331
|
for (let i = head; i < oldEnd; i++) parent.removeChild(old[i]);
|
|
387
332
|
for (let i = head; i < newEnd; i++) {
|
|
388
333
|
const node = specs[i].create();
|
|
@@ -394,8 +339,8 @@ function reconcileChildren(parent, specs) {
|
|
|
394
339
|
// src/view/dom/text-diff.ts
|
|
395
340
|
function textDiff(before, after, caretHint) {
|
|
396
341
|
if (before === after) return null;
|
|
397
|
-
const prefix =
|
|
398
|
-
const suffix =
|
|
342
|
+
const prefix = chunkVFSVN5IQ_cjs.commonPrefix(before, after);
|
|
343
|
+
const suffix = chunkVFSVN5IQ_cjs.commonSuffix(before, after);
|
|
399
344
|
const shared = Math.min(suffix, Math.min(before.length, after.length) - prefix);
|
|
400
345
|
const removed = before.length - prefix - shared;
|
|
401
346
|
const inserted = after.length - prefix - shared;
|
|
@@ -500,12 +445,12 @@ function specsFor(segment, options, doc) {
|
|
|
500
445
|
}
|
|
501
446
|
}
|
|
502
447
|
function needsFiller(inline) {
|
|
503
|
-
const content =
|
|
448
|
+
const content = chunkAIS37SL2_cjs.inlineText(inline);
|
|
504
449
|
return content === "" || content.endsWith("\n");
|
|
505
450
|
}
|
|
506
451
|
function renderInline(host, inline, decorations, options = {}) {
|
|
507
452
|
const doc = host.ownerDocument;
|
|
508
|
-
const length =
|
|
453
|
+
const length = chunkAIS37SL2_cjs.inlineLength(inline);
|
|
509
454
|
const specs = toSegments(inline, decorations).flatMap((segment) => specsFor(segment, options, doc));
|
|
510
455
|
if (needsFiller(inline)) specs.push(fillerSpec(doc, length));
|
|
511
456
|
reconcileChildren(host, specs);
|
|
@@ -542,7 +487,7 @@ function createHostRegistry(onRegister) {
|
|
|
542
487
|
const key = hostKey(entry.block, entry.region);
|
|
543
488
|
if (byKey.get(key) === entry) byKey.delete(key);
|
|
544
489
|
if (byElement.get(entry.element) === entry) byElement.delete(entry.element);
|
|
545
|
-
|
|
490
|
+
releases.get(entry)?.();
|
|
546
491
|
releases.delete(entry);
|
|
547
492
|
}
|
|
548
493
|
return {
|
|
@@ -555,7 +500,7 @@ function createHostRegistry(onRegister) {
|
|
|
555
500
|
if (onRegister) releases.set(entry, onRegister(element));
|
|
556
501
|
return () => forget(entry);
|
|
557
502
|
},
|
|
558
|
-
get: (block, region) =>
|
|
503
|
+
get: (block, region) => byKey.get(hostKey(block, region))?.element,
|
|
559
504
|
locate(node) {
|
|
560
505
|
for (let current = node; current; current = current.parentNode) {
|
|
561
506
|
const entry = byElement.get(current);
|
|
@@ -570,23 +515,23 @@ function createHostRegistry(onRegister) {
|
|
|
570
515
|
// src/view/controller/dom-selection.ts
|
|
571
516
|
function domToPos(registry, node, offset) {
|
|
572
517
|
const host = registry.locate(node);
|
|
573
|
-
const mapped = host &&
|
|
518
|
+
const mapped = host && domMapOf(host.element)?.fromDom(node, offset);
|
|
574
519
|
return host && typeof mapped === "number" ? { block: host.block, region: host.region, offset: mapped } : null;
|
|
575
520
|
}
|
|
576
521
|
function posToDom(registry, pos, assoc) {
|
|
577
522
|
const host = registry.get(pos.block, pos.region);
|
|
578
|
-
return
|
|
523
|
+
return (host && domMapOf(host)?.toDom(pos.offset, assoc)) ?? null;
|
|
579
524
|
}
|
|
580
525
|
function readSelection(registry, domSelection, blockAt2 = () => void 0) {
|
|
581
|
-
const anchorNode =
|
|
582
|
-
const focusNode =
|
|
526
|
+
const anchorNode = domSelection?.anchorNode;
|
|
527
|
+
const focusNode = domSelection?.focusNode;
|
|
583
528
|
if (!domSelection || !anchorNode || !focusNode) return null;
|
|
584
529
|
const anchor = domToPos(registry, anchorNode, domSelection.anchorOffset);
|
|
585
530
|
const head = domToPos(registry, focusNode, domSelection.focusOffset);
|
|
586
|
-
if (anchor && head) return
|
|
531
|
+
if (anchor && head) return chunkVFSVN5IQ_cjs.textSelection(anchor, head);
|
|
587
532
|
if (anchor || head || registry.locate(anchorNode) || registry.locate(focusNode)) return null;
|
|
588
533
|
const block = blockAt2(anchorNode);
|
|
589
|
-
return block !== void 0 && block === blockAt2(focusNode) ?
|
|
534
|
+
return block !== void 0 && block === blockAt2(focusNode) ? chunkVFSVN5IQ_cjs.nodeSelection(block) : null;
|
|
590
535
|
}
|
|
591
536
|
function selectBlock(domSelection, element) {
|
|
592
537
|
if (!element) return false;
|
|
@@ -603,7 +548,7 @@ function writeSelection(registry, selection, domSelection, blockElement) {
|
|
|
603
548
|
if (selection.kind !== "text") return false;
|
|
604
549
|
const { anchor, head } = selection;
|
|
605
550
|
if (anchor.block !== head.block || anchor.region !== head.region) return false;
|
|
606
|
-
if (
|
|
551
|
+
if (chunkVFSVN5IQ_cjs.sameSelection(readSelection(registry, domSelection), selection)) return true;
|
|
607
552
|
const base = posToDom(registry, anchor, anchor.offset < head.offset ? 1 : -1);
|
|
608
553
|
const extent = posToDom(registry, head, head.offset < anchor.offset ? 1 : -1);
|
|
609
554
|
if (!base || !extent) return false;
|
|
@@ -622,12 +567,12 @@ function listen(target, handlers, options) {
|
|
|
622
567
|
|
|
623
568
|
// src/view/navigation/node-entry.ts
|
|
624
569
|
var NODE_ENTRY = "data-quoin-node-entry";
|
|
625
|
-
var entersAsNode = (controller, block) =>
|
|
570
|
+
var entersAsNode = (controller, block) => controller.blockElement(block)?.querySelector(`[${NODE_ENTRY}]`) != null;
|
|
626
571
|
|
|
627
572
|
// src/view/controller/reader-toggles.ts
|
|
628
573
|
var NO_CHOICES = /* @__PURE__ */ new Map();
|
|
629
574
|
var stores = /* @__PURE__ */ new WeakMap();
|
|
630
|
-
var shownOpen = (block, choices) =>
|
|
575
|
+
var shownOpen = (block, choices) => choices.get(block.id) ?? block.attrs.open === true;
|
|
631
576
|
function createReaderToggles(controller) {
|
|
632
577
|
let choices = NO_CHOICES;
|
|
633
578
|
const listeners = /* @__PURE__ */ new Set();
|
|
@@ -665,17 +610,17 @@ var known = /* @__PURE__ */ new WeakMap();
|
|
|
665
610
|
function hidersOf(doc) {
|
|
666
611
|
let hiders = known.get(doc);
|
|
667
612
|
if (hiders === void 0) {
|
|
668
|
-
const first = doc.blocks.findIndex(
|
|
669
|
-
hiders = doc.blocks.map((_, index) => first < 0 || index <= first ? null :
|
|
613
|
+
const first = doc.blocks.findIndex(chunkVFSVN5IQ_cjs.isClosedToggle);
|
|
614
|
+
hiders = doc.blocks.map((_, index) => first < 0 || index <= first ? null : chunkVFSVN5IQ_cjs.hidingToggle(doc, index + 1));
|
|
670
615
|
known.set(doc, hiders);
|
|
671
616
|
}
|
|
672
617
|
return hiders;
|
|
673
618
|
}
|
|
674
|
-
var hidingToggleAt = (doc, index) =>
|
|
619
|
+
var hidingToggleAt = (doc, index) => hidersOf(doc)[index] ?? null;
|
|
675
620
|
function isHiddenAt(doc, index, choices) {
|
|
676
621
|
if (choices.size === 0) return hidingToggleAt(doc, index) !== null;
|
|
677
622
|
const closed = (block) => block.type === "TOGGLE" && !shownOpen(block, choices);
|
|
678
|
-
return
|
|
623
|
+
return chunkVFSVN5IQ_cjs.hidingToggle(doc, index + 1, closed) !== null;
|
|
679
624
|
}
|
|
680
625
|
var visibleBlockIndexes = (doc) => hidersOf(doc).flatMap((hider, index) => hider === null ? [index] : []);
|
|
681
626
|
function drawnBlockCount(doc, start = 0, end = doc.blocks.length) {
|
|
@@ -700,20 +645,25 @@ function neighbourBlock(doc, from, direction, accept = anyBlock) {
|
|
|
700
645
|
}
|
|
701
646
|
function entryEdge(controller, block, direction) {
|
|
702
647
|
const { doc, schema } = controller.editor.state;
|
|
703
|
-
const edge = direction < 0 ?
|
|
648
|
+
const edge = direction < 0 ? chunkVFSVN5IQ_cjs.endOf(doc, schema, block) : chunkVFSVN5IQ_cjs.startOf(doc, schema, block);
|
|
704
649
|
if (edge.kind !== "text") return edge;
|
|
705
650
|
const drawn = controller.registry.get(edge.head.block, edge.head.region) !== void 0;
|
|
706
|
-
return drawn && !entersAsNode(controller, block) ? edge :
|
|
651
|
+
return drawn && !entersAsNode(controller, block) ? edge : chunkVFSVN5IQ_cjs.nodeSelection(block);
|
|
707
652
|
}
|
|
708
|
-
var ownNode = (controller, block, direction) => direction < 0 && entersAsNode(controller, block) ?
|
|
709
|
-
var
|
|
653
|
+
var ownNode = (controller, block, direction) => direction < 0 && entersAsNode(controller, block) ? chunkVFSVN5IQ_cjs.nodeSelection(block) : null;
|
|
654
|
+
var canBeEntered = (controller) => (block) => {
|
|
655
|
+
const { schema } = controller.editor.state;
|
|
656
|
+
const region = chunkVFSVN5IQ_cjs.isTextFlow(schema, block) ? chunkVFSVN5IQ_cjs.primaryRegion(schema, block) : null;
|
|
657
|
+
return region === null || controller.registry.get(block.id, region) !== void 0 || entersAsNode(controller, block.id);
|
|
658
|
+
};
|
|
659
|
+
var holdsTextHead = (controller) => (block) => chunkVFSVN5IQ_cjs.isTextFlow(controller.editor.state.schema, block) && entryEdge(controller, block.id, 1).kind === "text";
|
|
710
660
|
function neighbourHead(controller, from, direction) {
|
|
711
661
|
const target = neighbourBlock(controller.editor.state.doc, from, direction, holdsTextHead(controller));
|
|
712
662
|
const edge = target && entryEdge(controller, target.id, direction);
|
|
713
|
-
return
|
|
663
|
+
return edge?.kind === "text" ? edge.head : null;
|
|
714
664
|
}
|
|
715
665
|
function moveToNeighbour(controller, from, direction) {
|
|
716
|
-
const target = neighbourBlock(controller.editor.state.doc, from, direction);
|
|
666
|
+
const target = neighbourBlock(controller.editor.state.doc, from, direction, canBeEntered(controller));
|
|
717
667
|
if (target === null) return false;
|
|
718
668
|
dispatchSelection(controller, entryEdge(controller, target.id, direction));
|
|
719
669
|
return true;
|
|
@@ -748,7 +698,7 @@ function createAutoScroll(element, onScroll, edge = EDGE) {
|
|
|
748
698
|
function tick() {
|
|
749
699
|
frame = null;
|
|
750
700
|
if (delta === 0) return;
|
|
751
|
-
(
|
|
701
|
+
(container ?? win).scrollBy(0, delta);
|
|
752
702
|
onScroll();
|
|
753
703
|
frame = win.requestAnimationFrame(tick);
|
|
754
704
|
}
|
|
@@ -792,10 +742,10 @@ function nearest(items, element, x, y) {
|
|
|
792
742
|
}
|
|
793
743
|
return best;
|
|
794
744
|
}
|
|
795
|
-
var elementAt = (controller, x, y) =>
|
|
745
|
+
var elementAt = (controller, x, y) => controller.root?.ownerDocument.elementFromPoint(x, y) ?? null;
|
|
796
746
|
function hostAt(controller, x, y) {
|
|
797
747
|
const { registry } = controller;
|
|
798
|
-
return
|
|
748
|
+
return registry.locate(elementAt(controller, x, y)) ?? nearest(registry.all(), (entry) => entry.element, x, y);
|
|
799
749
|
}
|
|
800
750
|
function blockAt(controller, x, y) {
|
|
801
751
|
const element = elementAt(controller, x, y);
|
|
@@ -806,16 +756,16 @@ function blockAt(controller, x, y) {
|
|
|
806
756
|
const shell = controller.blockElement(doc.blocks[index].id);
|
|
807
757
|
return shell ? [{ id: doc.blocks[index].id, shell }] : [];
|
|
808
758
|
});
|
|
809
|
-
return
|
|
759
|
+
return nearest(drawn, (entry) => entry.shell, x, y)?.id ?? null;
|
|
810
760
|
}
|
|
811
761
|
function caretPosAt(controller, host, x, y) {
|
|
812
762
|
const { element, block, region } = host;
|
|
813
763
|
const at = (offset) => ({ block, region, offset });
|
|
814
|
-
const end =
|
|
764
|
+
const end = domMapOf(element)?.length ?? 0;
|
|
815
765
|
const box = element.getBoundingClientRect();
|
|
816
766
|
if (y < box.top) return at(0);
|
|
817
767
|
if (y >= box.bottom) return at(end);
|
|
818
|
-
return
|
|
768
|
+
return caretInHost(controller.registry, element, box, host, x, y) ?? at(x < box.left ? 0 : end);
|
|
819
769
|
}
|
|
820
770
|
|
|
821
771
|
// src/view/selection/native-interaction.ts
|
|
@@ -828,10 +778,10 @@ var CONTROLS = `button, a, input, select, textarea, [${NATIVE_INTERACTION}]`;
|
|
|
828
778
|
var sameHost = (pos, host) => pos.block === host.block && pos.region === host.region;
|
|
829
779
|
function anchorAtCrossing(controller) {
|
|
830
780
|
const native = controller.domSelection();
|
|
831
|
-
const anchor =
|
|
781
|
+
const anchor = native?.anchorNode && domToPos(controller.registry, native.anchorNode, native.anchorOffset);
|
|
832
782
|
if (anchor) return anchor;
|
|
833
783
|
const { selection } = controller.editor.state;
|
|
834
|
-
return
|
|
784
|
+
return selection?.kind === "text" ? selection.anchor : null;
|
|
835
785
|
}
|
|
836
786
|
function createCrossBlockPointer(controller) {
|
|
837
787
|
return {
|
|
@@ -845,7 +795,7 @@ function createCrossBlockPointer(controller) {
|
|
|
845
795
|
let preventMouseDown = false;
|
|
846
796
|
const scroll = createAutoScroll(root, () => follow(last.x, last.y));
|
|
847
797
|
function select(selection) {
|
|
848
|
-
if (
|
|
798
|
+
if (chunkVFSVN5IQ_cjs.sameSelection(selection, controller.editor.state.selection)) return;
|
|
849
799
|
dispatchSelection(controller, selection);
|
|
850
800
|
}
|
|
851
801
|
function startDragging() {
|
|
@@ -861,18 +811,18 @@ function createCrossBlockPointer(controller) {
|
|
|
861
811
|
if (current.anchor === null) return;
|
|
862
812
|
startDragging();
|
|
863
813
|
}
|
|
864
|
-
select(
|
|
814
|
+
select(chunkVFSVN5IQ_cjs.textSelection(current.anchor, caretPosAt(controller, target, x, y)));
|
|
865
815
|
}
|
|
866
816
|
function followBlocks(current, x, y) {
|
|
867
817
|
if (!controller.dragging && Math.hypot(x - current.x, y - current.y) < DRAG_DISTANCE) return;
|
|
868
818
|
const block = blockAt(controller, x, y);
|
|
869
819
|
if (block === null) return;
|
|
870
820
|
startDragging();
|
|
871
|
-
select(
|
|
821
|
+
select(chunkVFSVN5IQ_cjs.blockRangeSelection(current.start, block));
|
|
872
822
|
}
|
|
873
823
|
function follow(x, y) {
|
|
874
|
-
if (
|
|
875
|
-
else if (
|
|
824
|
+
if (press?.kind === "text") followText(press, x, y);
|
|
825
|
+
else if (press?.kind === "blocks") followBlocks(press, x, y);
|
|
876
826
|
}
|
|
877
827
|
function release() {
|
|
878
828
|
unfollow();
|
|
@@ -894,13 +844,20 @@ function createCrossBlockPointer(controller) {
|
|
|
894
844
|
}
|
|
895
845
|
function extendFrom(host, x, y) {
|
|
896
846
|
const { selection } = controller.editor.state;
|
|
897
|
-
if (
|
|
847
|
+
if (selection?.kind !== "text") return;
|
|
898
848
|
if (sameHost(selection.anchor, host) && !isCrossSelection(selection)) return;
|
|
899
849
|
press = { kind: "text", host, anchor: selection.anchor };
|
|
900
850
|
preventMouseDown = true;
|
|
901
851
|
startDragging();
|
|
902
852
|
follow(x, y);
|
|
903
853
|
}
|
|
854
|
+
function pressWhole(block) {
|
|
855
|
+
if (entryEdge(controller, block, 1).kind !== "node") return;
|
|
856
|
+
const pressed = chunkAIS37SL2_cjs.blockById(controller.editor.state.doc, block);
|
|
857
|
+
if (pressed !== void 0 && !canBeEntered(controller)(pressed)) return select(chunkVFSVN5IQ_cjs.blockRangeSelection(block));
|
|
858
|
+
controller.nodeReveal.pressed(block);
|
|
859
|
+
select(chunkVFSVN5IQ_cjs.nodeSelection(block));
|
|
860
|
+
}
|
|
904
861
|
function onPointerDown(event) {
|
|
905
862
|
end();
|
|
906
863
|
preventMouseDown = false;
|
|
@@ -914,10 +871,7 @@ function createCrossBlockPointer(controller) {
|
|
|
914
871
|
if (event.shiftKey) extendFrom(host, event.clientX, event.clientY);
|
|
915
872
|
} else if (block !== void 0 && !(control && root.contains(control))) {
|
|
916
873
|
press = { kind: "blocks", start: block, x: event.clientX, y: event.clientY };
|
|
917
|
-
if (!event.shiftKey
|
|
918
|
-
controller.nodeReveal.pressed(block);
|
|
919
|
-
select(_chunkZKVOS57Qcjs.nodeSelection.call(void 0, block));
|
|
920
|
-
}
|
|
874
|
+
if (!event.shiftKey) pressWhole(block);
|
|
921
875
|
} else {
|
|
922
876
|
return;
|
|
923
877
|
}
|
|
@@ -944,7 +898,7 @@ function createCrossBlockPointer(controller) {
|
|
|
944
898
|
// src/view/selection/paint-selection.ts
|
|
945
899
|
var NAME = "quoin-selection";
|
|
946
900
|
function coveredRanges(controller) {
|
|
947
|
-
return
|
|
901
|
+
return chunkVFSVN5IQ_cjs.markRanges(controller.editor.state).flatMap(({ block, region, from, to }) => {
|
|
948
902
|
const host = controller.registry.get(block, region);
|
|
949
903
|
const map = host && domMapOf(host);
|
|
950
904
|
if (!host || !map) return [];
|
|
@@ -988,7 +942,7 @@ function decorationPainter() {
|
|
|
988
942
|
}
|
|
989
943
|
function createPainter(win) {
|
|
990
944
|
const { CSS: css, Highlight } = win;
|
|
991
|
-
return
|
|
945
|
+
return css?.highlights && Highlight ? highlightPainter(css.highlights, Highlight) : decorationPainter();
|
|
992
946
|
}
|
|
993
947
|
|
|
994
948
|
// src/view/selection/in-place.ts
|
|
@@ -1009,13 +963,13 @@ function inPlace(element, change) {
|
|
|
1009
963
|
}
|
|
1010
964
|
|
|
1011
965
|
// src/view/selection/selection-sink.ts
|
|
1012
|
-
var wholeBlocks = (selection) =>
|
|
966
|
+
var wholeBlocks = (selection) => selection?.kind === "blocks" || selection?.kind === "node";
|
|
1013
967
|
function heldBySink(selection) {
|
|
1014
968
|
return wholeBlocks(selection) || isCrossSelection(selection);
|
|
1015
969
|
}
|
|
1016
970
|
var NO_TEXT = "\xA0";
|
|
1017
971
|
function selectionText(state) {
|
|
1018
|
-
const text =
|
|
972
|
+
const text = chunkVFSVN5IQ_cjs.markRanges(state).map((range) => chunkAIS37SL2_cjs.inlinePlainText(chunkVFSVN5IQ_cjs.rangeContent(state, range), state.schema)).join("\n");
|
|
1019
973
|
return text === "" ? NO_TEXT : text;
|
|
1020
974
|
}
|
|
1021
975
|
var focusInPlace = (sink) => inPlace(sink, () => sink.focus({ preventScroll: true }));
|
|
@@ -1035,11 +989,11 @@ function focusSink(controller) {
|
|
|
1035
989
|
focusing = outer;
|
|
1036
990
|
}
|
|
1037
991
|
}
|
|
1038
|
-
|
|
992
|
+
sink.ownerDocument.getSelection()?.selectAllChildren(sink);
|
|
1039
993
|
}
|
|
1040
994
|
function selectedBlockName({ doc, schema, selection }, blockLabel) {
|
|
1041
|
-
const block =
|
|
1042
|
-
return block === void 0 ? null :
|
|
995
|
+
const block = selection?.kind === "node" ? chunkAIS37SL2_cjs.blockById(doc, selection.block) : void 0;
|
|
996
|
+
return block === void 0 ? null : blockLabel?.(block, schema) ?? "";
|
|
1043
997
|
}
|
|
1044
998
|
function clearSink(controller) {
|
|
1045
999
|
const { sink } = controller;
|
|
@@ -1058,11 +1012,11 @@ function createCrossMode(controller) {
|
|
|
1058
1012
|
const cross = isCrossSelection(state.selection);
|
|
1059
1013
|
synced = state;
|
|
1060
1014
|
if (cross) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1015
|
+
attached?.root.setAttribute(CROSS, "");
|
|
1016
|
+
attached?.painter.paint(controller);
|
|
1063
1017
|
} else if (active) {
|
|
1064
|
-
|
|
1065
|
-
|
|
1018
|
+
attached?.root.removeAttribute(CROSS);
|
|
1019
|
+
attached?.painter.clear();
|
|
1066
1020
|
}
|
|
1067
1021
|
if (!heldBySink(state.selection)) clearSink(controller);
|
|
1068
1022
|
active = cross;
|
|
@@ -1079,7 +1033,7 @@ function createCrossMode(controller) {
|
|
|
1079
1033
|
return active;
|
|
1080
1034
|
},
|
|
1081
1035
|
get mode() {
|
|
1082
|
-
return
|
|
1036
|
+
return attached?.painter.mode ?? "highlight";
|
|
1083
1037
|
},
|
|
1084
1038
|
attach(root) {
|
|
1085
1039
|
const view = root.ownerDocument.defaultView;
|
|
@@ -1103,7 +1057,7 @@ function createCrossMode(controller) {
|
|
|
1103
1057
|
}
|
|
1104
1058
|
|
|
1105
1059
|
// src/view/selection/node-reveal.ts
|
|
1106
|
-
var nodeOf = (selection) =>
|
|
1060
|
+
var nodeOf = (selection) => selection?.kind === "node" ? selection.block : null;
|
|
1107
1061
|
function createNodeReveal(element) {
|
|
1108
1062
|
let shown = null;
|
|
1109
1063
|
let pressed = null;
|
|
@@ -1125,7 +1079,7 @@ function createNodeReveal(element) {
|
|
|
1125
1079
|
show(selection, local) {
|
|
1126
1080
|
const block = nodeOf(selection);
|
|
1127
1081
|
if (block !== null && block !== pressed && (block !== shown || local && block === owed)) {
|
|
1128
|
-
|
|
1082
|
+
element(block)?.scrollIntoView({ block: "nearest" });
|
|
1129
1083
|
}
|
|
1130
1084
|
if (local) owed = null;
|
|
1131
1085
|
shown = block;
|
|
@@ -1143,11 +1097,11 @@ function createAnnouncer(stateOf, throttleMs = THROTTLE_MS) {
|
|
|
1143
1097
|
announce(message) {
|
|
1144
1098
|
const state = stateOf();
|
|
1145
1099
|
const now = Date.now();
|
|
1146
|
-
if (
|
|
1147
|
-
spoken = { message, state, serial: (
|
|
1100
|
+
if (spoken?.message === message && spoken.state === state && now - spoken.at < throttleMs) return;
|
|
1101
|
+
spoken = { message, state, serial: (spoken?.serial ?? 0) + 1, at: now };
|
|
1148
1102
|
for (const listener of [...listeners]) listener();
|
|
1149
1103
|
},
|
|
1150
|
-
current: () =>
|
|
1104
|
+
current: () => spoken?.state === stateOf() ? spoken : null,
|
|
1151
1105
|
subscribe(listener) {
|
|
1152
1106
|
listeners.add(listener);
|
|
1153
1107
|
return () => void listeners.delete(listener);
|
|
@@ -1175,20 +1129,20 @@ function createElementSlot(changed) {
|
|
|
1175
1129
|
|
|
1176
1130
|
// src/view/controller/selection-element.ts
|
|
1177
1131
|
function elementFor({ doc }, selection, rendered) {
|
|
1178
|
-
const id =
|
|
1132
|
+
const id = chunkVFSVN5IQ_cjs.headBlockId(selection);
|
|
1179
1133
|
const index = id === null ? void 0 : doc.index.get(id);
|
|
1180
1134
|
if (id === null || index === void 0) return void 0;
|
|
1181
1135
|
const hiding = hidingToggleAt(doc, index);
|
|
1182
1136
|
if (hiding !== null) return rendered.block(doc.blocks[hiding].id);
|
|
1183
|
-
const host =
|
|
1184
|
-
return
|
|
1137
|
+
const host = selection?.kind === "text" ? rendered.hosts.get(id, selection.head.region) : void 0;
|
|
1138
|
+
return host ?? rendered.block(id);
|
|
1185
1139
|
}
|
|
1186
1140
|
function selectionElement(state, rendered) {
|
|
1187
1141
|
const { doc, schema, selection } = state;
|
|
1188
|
-
if (doc.blocks.length === 0) return
|
|
1189
|
-
const sink = heldBySink(selection) ?
|
|
1142
|
+
if (doc.blocks.length === 0) return rendered.empty?.() ?? void 0;
|
|
1143
|
+
const sink = heldBySink(selection) ? rendered.sink?.() : null;
|
|
1190
1144
|
if (sink) return sink;
|
|
1191
|
-
return
|
|
1145
|
+
return elementFor(state, selection, rendered) ?? elementFor(state, chunkVFSVN5IQ_cjs.startOf(doc, schema, doc.blocks[0].id), rendered);
|
|
1192
1146
|
}
|
|
1193
1147
|
|
|
1194
1148
|
// src/view/controller/tab-stop.ts
|
|
@@ -1232,10 +1186,10 @@ function createDrawnElements(hosts, state) {
|
|
|
1232
1186
|
},
|
|
1233
1187
|
registerBlock: (id, element) => blocks.register(id, "", element),
|
|
1234
1188
|
block: rendered.block,
|
|
1235
|
-
blockAt: (node) =>
|
|
1189
|
+
blockAt: (node) => blocks.locate(node)?.block,
|
|
1236
1190
|
registerSink: sink.register,
|
|
1237
1191
|
registerEmptyHost: empty.register,
|
|
1238
|
-
isEditorElement: (element) => element === sink.element || element === empty.element || [hosts, blocks].some((registry) =>
|
|
1192
|
+
isEditorElement: (element) => element === sink.element || element === empty.element || [hosts, blocks].some((registry) => registry.locate(element)?.element === element),
|
|
1239
1193
|
focusElement,
|
|
1240
1194
|
syncTabStop
|
|
1241
1195
|
};
|
|
@@ -1243,7 +1197,7 @@ function createDrawnElements(hosts, state) {
|
|
|
1243
1197
|
|
|
1244
1198
|
// src/view/controller/focus-ownership.ts
|
|
1245
1199
|
function hasFocus(controller, doc) {
|
|
1246
|
-
const active =
|
|
1200
|
+
const active = doc?.activeElement ?? null;
|
|
1247
1201
|
return active !== null && controller.isEditorElement(active);
|
|
1248
1202
|
}
|
|
1249
1203
|
function ownsFocus(controller, doc) {
|
|
@@ -1255,9 +1209,9 @@ function ownsFocus(controller, doc) {
|
|
|
1255
1209
|
function focusTarget(state, target) {
|
|
1256
1210
|
const { doc, schema, selection } = state;
|
|
1257
1211
|
if (doc.blocks.length === 0) return null;
|
|
1258
|
-
if (target === "end") return
|
|
1259
|
-
if (target === "start" || target === void 0 && selection === null) return
|
|
1260
|
-
return target === void 0 ? selection :
|
|
1212
|
+
if (target === "end") return chunkVFSVN5IQ_cjs.endOf(doc, schema, doc.blocks[doc.blocks.length - 1].id);
|
|
1213
|
+
if (target === "start" || target === void 0 && selection === null) return chunkVFSVN5IQ_cjs.startOf(doc, schema, doc.blocks[0].id);
|
|
1214
|
+
return target === void 0 ? selection : chunkVFSVN5IQ_cjs.textSelection(target);
|
|
1261
1215
|
}
|
|
1262
1216
|
|
|
1263
1217
|
// src/view/controller/host-decorations.ts
|
|
@@ -1273,7 +1227,7 @@ function decorationsByHost(decorations) {
|
|
|
1273
1227
|
return byHost;
|
|
1274
1228
|
}
|
|
1275
1229
|
function sameDecoration(a, b) {
|
|
1276
|
-
if (a.kind !== b.kind || a.block !== b.block || !
|
|
1230
|
+
if (a.kind !== b.kind || a.block !== b.block || !chunkAIS37SL2_cjs.sameAttrs(a.attrs, b.attrs)) return false;
|
|
1277
1231
|
if (a.kind === "inline" && b.kind === "inline") {
|
|
1278
1232
|
return a.region === b.region && a.from === b.from && a.to === b.to;
|
|
1279
1233
|
}
|
|
@@ -1284,7 +1238,7 @@ function sameDecoration(a, b) {
|
|
|
1284
1238
|
return true;
|
|
1285
1239
|
}
|
|
1286
1240
|
function sameDecorations(a, b) {
|
|
1287
|
-
return a === b ||
|
|
1241
|
+
return a === b || chunkAIS37SL2_cjs.sameItems(a, b, sameDecoration);
|
|
1288
1242
|
}
|
|
1289
1243
|
var byMode = { highlight: /* @__PURE__ */ new WeakMap(), decorations: /* @__PURE__ */ new WeakMap() };
|
|
1290
1244
|
function hostDecorations(editor, block, region, mode = "highlight") {
|
|
@@ -1295,12 +1249,12 @@ function hostDecorations(editor, block, region, mode = "highlight") {
|
|
|
1295
1249
|
grouped = decorationsByHost([...editor.decorations(), ...selectionDecorations(state, mode)]);
|
|
1296
1250
|
byState.set(state, grouped);
|
|
1297
1251
|
}
|
|
1298
|
-
return
|
|
1252
|
+
return grouped.get(hostKey(block, region)) ?? NO_DECORATIONS;
|
|
1299
1253
|
}
|
|
1300
1254
|
|
|
1301
1255
|
// src/view/controller/region-inline.ts
|
|
1302
1256
|
function regionInline(state, block, region) {
|
|
1303
|
-
const regions =
|
|
1257
|
+
const regions = chunkAIS37SL2_cjs.blockById(state.doc, block)?.regions;
|
|
1304
1258
|
return regions && Object.hasOwn(regions, region) ? regions[region] : void 0;
|
|
1305
1259
|
}
|
|
1306
1260
|
|
|
@@ -1312,8 +1266,8 @@ function createHostRenderer(editor, options, decorationsOf, afterRender) {
|
|
|
1312
1266
|
if (inline === void 0) return false;
|
|
1313
1267
|
const decorations = decorationsOf(host.block, host.region);
|
|
1314
1268
|
const last = rendered.get(host.element);
|
|
1315
|
-
const restyled =
|
|
1316
|
-
if (!always &&
|
|
1269
|
+
const restyled = last?.inline === inline && !sameDecorations(last.decorations, decorations);
|
|
1270
|
+
if (!always && last?.inline === inline && !restyled) return false;
|
|
1317
1271
|
renderInline(host.element, inline, decorations, options);
|
|
1318
1272
|
afterRender(host.element);
|
|
1319
1273
|
rendered.set(host.element, { inline, decorations });
|
|
@@ -1343,14 +1297,14 @@ function createOutsideChanges(editorHasFocus, movedFrom) {
|
|
|
1343
1297
|
committed(tr) {
|
|
1344
1298
|
const outside = depth === 0 && editorHasFocus();
|
|
1345
1299
|
focused ||= outside;
|
|
1346
|
-
if (
|
|
1300
|
+
if (tr?.selectionSet !== false) {
|
|
1347
1301
|
moved = null;
|
|
1348
1302
|
settled ||= depth === 0;
|
|
1349
1303
|
return;
|
|
1350
1304
|
}
|
|
1351
|
-
const from =
|
|
1305
|
+
const from = moved ?? (outside && !settled ? movedFrom(tr.before.selection) : null);
|
|
1352
1306
|
settled ||= outside;
|
|
1353
|
-
moved = from &&
|
|
1307
|
+
moved = from && chunkVFSVN5IQ_cjs.mapSelection(from, (pos, assoc) => tr.mapPos(pos, assoc), tr.before.doc);
|
|
1354
1308
|
},
|
|
1355
1309
|
takeFocused() {
|
|
1356
1310
|
const value = focused;
|
|
@@ -1401,11 +1355,11 @@ function wrapSliceHTML(html, json) {
|
|
|
1401
1355
|
return `<div data-quoin-slice="${encode(json)}">${html}</div>`;
|
|
1402
1356
|
}
|
|
1403
1357
|
function readSliceHTML(html) {
|
|
1404
|
-
const encoded =
|
|
1358
|
+
const encoded = MARKER.exec(html)?.[2];
|
|
1405
1359
|
if (!encoded) return null;
|
|
1406
1360
|
try {
|
|
1407
1361
|
return decode(encoded);
|
|
1408
|
-
} catch
|
|
1362
|
+
} catch {
|
|
1409
1363
|
return null;
|
|
1410
1364
|
}
|
|
1411
1365
|
}
|
|
@@ -1413,7 +1367,7 @@ function readSliceHTML(html) {
|
|
|
1413
1367
|
// src/view/clipboard/paste-transfer.ts
|
|
1414
1368
|
function caretOf(controller) {
|
|
1415
1369
|
const { selection } = controller.editor.state;
|
|
1416
|
-
return
|
|
1370
|
+
return selection?.kind === "text" ? selection.head : null;
|
|
1417
1371
|
}
|
|
1418
1372
|
function transferFiles(transfer) {
|
|
1419
1373
|
const files = Array.from(transfer.files);
|
|
@@ -1423,7 +1377,7 @@ function transferFiles(transfer) {
|
|
|
1423
1377
|
function pasteTransfer(controller, transfer) {
|
|
1424
1378
|
const files = transferFiles(transfer);
|
|
1425
1379
|
if (files !== null) {
|
|
1426
|
-
|
|
1380
|
+
controller.onFiles?.(files, caretOf(controller));
|
|
1427
1381
|
return;
|
|
1428
1382
|
}
|
|
1429
1383
|
const text = transfer.getData("text/plain");
|
|
@@ -1443,7 +1397,7 @@ function handleCopy(controller, event, cut) {
|
|
|
1443
1397
|
clipboardData.setData("text/plain", copied.text);
|
|
1444
1398
|
clipboardData.setData("text/html", wrapSliceHTML(copied.html, copied.json));
|
|
1445
1399
|
clipboardData.setData(QUOIN_SLICE_TYPE, copied.json);
|
|
1446
|
-
if (cut) controller.run(
|
|
1400
|
+
if (cut) controller.run(chunkVFSVN5IQ_cjs.deleteSelection);
|
|
1447
1401
|
}
|
|
1448
1402
|
function handlePaste(controller, event) {
|
|
1449
1403
|
if (!event.clipboardData) return;
|
|
@@ -1458,9 +1412,9 @@ function dropPos(controller, x, y) {
|
|
|
1458
1412
|
return host && caretPosAt(controller, host, x, y);
|
|
1459
1413
|
}
|
|
1460
1414
|
function textlessBlockAt(controller, x, y) {
|
|
1461
|
-
const element =
|
|
1415
|
+
const element = controller.root?.ownerDocument.elementFromPoint(x, y);
|
|
1462
1416
|
const block = element ? controller.blockAt(element) : void 0;
|
|
1463
|
-
if (block === void 0 || controller.registry.locate(
|
|
1417
|
+
if (block === void 0 || controller.registry.locate(element ?? null) !== null) return null;
|
|
1464
1418
|
const hasText = [...controller.registry.all()].some((host) => host.block === block);
|
|
1465
1419
|
return hasText && !entersAsNode(controller, block) ? null : { block, region: "", offset: 0 };
|
|
1466
1420
|
}
|
|
@@ -1471,15 +1425,15 @@ function handleDrop(controller, event) {
|
|
|
1471
1425
|
const files = transferFiles(dataTransfer);
|
|
1472
1426
|
const onBlock2 = files && textlessBlockAt(controller, event.clientX, event.clientY);
|
|
1473
1427
|
if (files && onBlock2) {
|
|
1474
|
-
|
|
1428
|
+
controller.onFiles?.(files, onBlock2);
|
|
1475
1429
|
return;
|
|
1476
1430
|
}
|
|
1477
1431
|
const pos = dropPos(controller, event.clientX, event.clientY);
|
|
1478
|
-
if (pos) controller.dispatch(controller.editor.createTransaction().setSelection(
|
|
1432
|
+
if (pos) controller.dispatch(controller.editor.createTransaction().setSelection(chunkVFSVN5IQ_cjs.textSelection(pos)).setOrigin("drop"));
|
|
1479
1433
|
pasteTransfer(controller, dataTransfer);
|
|
1480
1434
|
}
|
|
1481
1435
|
function handleDragOver(event) {
|
|
1482
|
-
const types =
|
|
1436
|
+
const types = event.dataTransfer?.types ?? [];
|
|
1483
1437
|
if (DROPPABLE.some((type) => types.includes(type))) event.preventDefault();
|
|
1484
1438
|
}
|
|
1485
1439
|
function handleDragStart(event) {
|
|
@@ -1488,9 +1442,9 @@ function handleDragStart(event) {
|
|
|
1488
1442
|
|
|
1489
1443
|
// src/view/clipboard/attach-clipboard.ts
|
|
1490
1444
|
function attachClipboard(controller, root, catchUp) {
|
|
1491
|
-
const inEmptyHost = (target) =>
|
|
1445
|
+
const inEmptyHost = (target) => target.closest?.("[data-quoin-empty]") != null;
|
|
1492
1446
|
const inEditor = ({ target }) => controller.registry.locate(target) !== null || controller.isEditorElement(target) || inEmptyHost(target);
|
|
1493
|
-
const inField = ({ target }) =>
|
|
1447
|
+
const inField = ({ target }) => target?.closest?.("input, textarea, select") != null;
|
|
1494
1448
|
const droppable = (event) => !controller.readOnly && !inField(event);
|
|
1495
1449
|
const onCopy = (event) => {
|
|
1496
1450
|
if (!inEditor(event)) return;
|
|
@@ -1550,7 +1504,7 @@ function textOutsideSelection(sink) {
|
|
|
1550
1504
|
};
|
|
1551
1505
|
}
|
|
1552
1506
|
function composedText(sink, { before, after }) {
|
|
1553
|
-
let text =
|
|
1507
|
+
let text = sink.textContent ?? "";
|
|
1554
1508
|
if (text.startsWith(before)) text = text.slice(before.length);
|
|
1555
1509
|
return text.endsWith(after) ? text.slice(0, text.length - after.length) : text;
|
|
1556
1510
|
}
|
|
@@ -1558,7 +1512,7 @@ function createSinkComposition(controller) {
|
|
|
1558
1512
|
let outside = null;
|
|
1559
1513
|
let stopWaiting = null;
|
|
1560
1514
|
function settle() {
|
|
1561
|
-
|
|
1515
|
+
stopWaiting?.();
|
|
1562
1516
|
stopWaiting = null;
|
|
1563
1517
|
const { sink } = controller;
|
|
1564
1518
|
const ignored = wholeBlocks(controller.editor.state.selection);
|
|
@@ -1571,7 +1525,7 @@ function createSinkComposition(controller) {
|
|
|
1571
1525
|
}
|
|
1572
1526
|
return {
|
|
1573
1527
|
start() {
|
|
1574
|
-
|
|
1528
|
+
stopWaiting?.();
|
|
1575
1529
|
stopWaiting = null;
|
|
1576
1530
|
if (outside === null && controller.sink !== null) outside = textOutsideSelection(controller.sink);
|
|
1577
1531
|
controller.composingKey = SINK_KEY;
|
|
@@ -1603,29 +1557,29 @@ function createSinkComposition(controller) {
|
|
|
1603
1557
|
var LINE_BREAK = "\n";
|
|
1604
1558
|
var transposeChars = (state, dispatch) => {
|
|
1605
1559
|
const { selection } = state;
|
|
1606
|
-
if (
|
|
1560
|
+
if (selection?.kind !== "text" || !chunkVFSVN5IQ_cjs.isCollapsed(selection)) return false;
|
|
1607
1561
|
const { head } = selection;
|
|
1608
|
-
const inline =
|
|
1562
|
+
const inline = chunkAIS37SL2_cjs.blockById(state.doc, head.block)?.regions[head.region];
|
|
1609
1563
|
if (inline === void 0) return false;
|
|
1610
|
-
const value =
|
|
1564
|
+
const value = chunkAIS37SL2_cjs.inlineText(inline);
|
|
1611
1565
|
const atLineEnd = head.offset === value.length || value[head.offset] === LINE_BREAK;
|
|
1612
|
-
const end = atLineEnd ? head.offset :
|
|
1613
|
-
const middle =
|
|
1614
|
-
const start =
|
|
1566
|
+
const end = atLineEnd ? head.offset : chunkVFSVN5IQ_cjs.nextGraphemeOffset(value, head.offset);
|
|
1567
|
+
const middle = chunkVFSVN5IQ_cjs.prevGraphemeOffset(value, end);
|
|
1568
|
+
const start = chunkVFSVN5IQ_cjs.prevGraphemeOffset(value, middle);
|
|
1615
1569
|
if (start === middle || value.slice(start, end).includes(LINE_BREAK)) return false;
|
|
1616
|
-
const swapped = [...
|
|
1617
|
-
const tr = new
|
|
1618
|
-
tr.step(
|
|
1619
|
-
|
|
1570
|
+
const swapped = [...chunkAIS37SL2_cjs.sliceInline(inline, middle, end), ...chunkAIS37SL2_cjs.sliceInline(inline, start, middle)];
|
|
1571
|
+
const tr = new chunkVFSVN5IQ_cjs.Transaction(state).setOrigin("input");
|
|
1572
|
+
tr.step(chunkVFSVN5IQ_cjs.replaceInlineStep(head.block, head.region, start, end, swapped));
|
|
1573
|
+
dispatch?.(tr.setSelection(chunkVFSVN5IQ_cjs.textSelection({ ...head, offset: end })));
|
|
1620
1574
|
return true;
|
|
1621
1575
|
};
|
|
1622
1576
|
|
|
1623
1577
|
// src/view/input/replace-range.ts
|
|
1624
1578
|
function replaceRange(editor, range, text, withRules) {
|
|
1625
1579
|
const dispatch = (tr) => editor.dispatch(tr);
|
|
1626
|
-
dispatch(editor.createTransaction().setSelection(
|
|
1627
|
-
if (text === "") return
|
|
1628
|
-
return withRules ? editor.insertText(text) :
|
|
1580
|
+
dispatch(editor.createTransaction().setSelection(chunkVFSVN5IQ_cjs.textSelection(range.from, range.to)).setOrigin("input"));
|
|
1581
|
+
if (text === "") return chunkVFSVN5IQ_cjs.deleteSelection(editor.state, (tr) => dispatch(tr.setOrigin("input")));
|
|
1582
|
+
return withRules ? editor.insertText(text) : chunkVFSVN5IQ_cjs.insertText(text, { origin: "input" })(editor.state, dispatch);
|
|
1629
1583
|
}
|
|
1630
1584
|
|
|
1631
1585
|
// src/view/input/target-range.ts
|
|
@@ -1636,13 +1590,13 @@ function targetRangeToModel(controller, event) {
|
|
|
1636
1590
|
const to = domToPos(controller.registry, range.endContainer, range.endOffset);
|
|
1637
1591
|
return from && to && { from, to };
|
|
1638
1592
|
}
|
|
1639
|
-
var isEmpty = ({ from, to }) =>
|
|
1593
|
+
var isEmpty = ({ from, to }) => chunkVFSVN5IQ_cjs.sameSelection(chunkVFSVN5IQ_cjs.textSelection(from), chunkVFSVN5IQ_cjs.textSelection(to));
|
|
1640
1594
|
function targetBeyondSelection(controller, event) {
|
|
1641
1595
|
const range = targetRangeToModel(controller, event);
|
|
1642
1596
|
if (range === null || isEmpty(range)) return null;
|
|
1643
1597
|
const { doc, selection } = controller.editor.state;
|
|
1644
|
-
const selected =
|
|
1645
|
-
const same = selected !== null &&
|
|
1598
|
+
const selected = chunkVFSVN5IQ_cjs.selectionRange(doc, selection);
|
|
1599
|
+
const same = selected !== null && chunkVFSVN5IQ_cjs.sameSelection(chunkVFSVN5IQ_cjs.textSelection(selected.from, selected.to), chunkVFSVN5IQ_cjs.textSelection(range.from, range.to));
|
|
1646
1600
|
return same ? null : range;
|
|
1647
1601
|
}
|
|
1648
1602
|
|
|
@@ -1657,41 +1611,41 @@ var targetOr = (command) => (controller, event) => {
|
|
|
1657
1611
|
};
|
|
1658
1612
|
var leaveToHandlers = () => void 0;
|
|
1659
1613
|
function insertTypedText(controller, event) {
|
|
1660
|
-
const text =
|
|
1614
|
+
const text = event.data ?? event.dataTransfer?.getData("text/plain");
|
|
1661
1615
|
if (!text) return;
|
|
1662
1616
|
const range = targetBeyondSelection(controller, event);
|
|
1663
1617
|
if (range === null) controller.edit(() => controller.editor.insertText(text));
|
|
1664
1618
|
else controller.edit(() => replaceRange(controller.editor, range, text, false));
|
|
1665
1619
|
}
|
|
1666
1620
|
function deleteContentBackward(controller, event) {
|
|
1667
|
-
if (!controller.run(
|
|
1621
|
+
if (!controller.run(chunkVFSVN5IQ_cjs.undoInputRule)) targetOr(chunkVFSVN5IQ_cjs.deleteBackward)(controller, event);
|
|
1668
1622
|
}
|
|
1669
1623
|
function insertReplacementText(controller, event) {
|
|
1670
|
-
const text =
|
|
1624
|
+
const text = event.dataTransfer?.getData("text/plain") || event.data;
|
|
1671
1625
|
if (!text) return;
|
|
1672
1626
|
const range = targetRangeToModel(controller, event);
|
|
1673
|
-
if (range === null) controller.run(
|
|
1627
|
+
if (range === null) controller.run(chunkVFSVN5IQ_cjs.insertText(text, { origin: "input" }));
|
|
1674
1628
|
else controller.edit(() => replaceRange(controller.editor, range, text, false));
|
|
1675
1629
|
}
|
|
1676
1630
|
var actions = {
|
|
1677
1631
|
insertText: insertTypedText,
|
|
1678
1632
|
insertReplacementText,
|
|
1679
1633
|
insertParagraph: (controller) => void controller.edit(() => controller.editor.handleKey(ENTER)),
|
|
1680
|
-
insertLineBreak: run(
|
|
1634
|
+
insertLineBreak: run(chunkVFSVN5IQ_cjs.insertHardBreak),
|
|
1681
1635
|
deleteContentBackward,
|
|
1682
|
-
deleteContentForward: targetOr(
|
|
1683
|
-
deleteWordBackward: targetOr(
|
|
1684
|
-
deleteWordForward: targetOr(
|
|
1685
|
-
deleteSoftLineBackward: targetOr(
|
|
1686
|
-
deleteHardLineBackward: targetOr(
|
|
1687
|
-
deleteSoftLineForward: targetOr(
|
|
1688
|
-
deleteHardLineForward: targetOr(
|
|
1689
|
-
formatBold: run(
|
|
1690
|
-
formatItalic: run(
|
|
1691
|
-
formatUnderline: run(
|
|
1692
|
-
formatStrikeThrough: run(
|
|
1693
|
-
historyUndo: run(
|
|
1694
|
-
historyRedo: run(
|
|
1636
|
+
deleteContentForward: targetOr(chunkVFSVN5IQ_cjs.deleteForward),
|
|
1637
|
+
deleteWordBackward: targetOr(chunkVFSVN5IQ_cjs.deleteWordBackward),
|
|
1638
|
+
deleteWordForward: targetOr(chunkVFSVN5IQ_cjs.deleteWordForward),
|
|
1639
|
+
deleteSoftLineBackward: targetOr(chunkVFSVN5IQ_cjs.deleteToLineStart),
|
|
1640
|
+
deleteHardLineBackward: targetOr(chunkVFSVN5IQ_cjs.deleteToLineStart),
|
|
1641
|
+
deleteSoftLineForward: targetOr(chunkVFSVN5IQ_cjs.deleteToLineEnd),
|
|
1642
|
+
deleteHardLineForward: targetOr(chunkVFSVN5IQ_cjs.deleteToLineEnd),
|
|
1643
|
+
formatBold: run(chunkVFSVN5IQ_cjs.toggleMark("bold")),
|
|
1644
|
+
formatItalic: run(chunkVFSVN5IQ_cjs.toggleMark("italic")),
|
|
1645
|
+
formatUnderline: run(chunkVFSVN5IQ_cjs.toggleMark("underline")),
|
|
1646
|
+
formatStrikeThrough: run(chunkVFSVN5IQ_cjs.toggleMark("strike")),
|
|
1647
|
+
historyUndo: run(chunkVFSVN5IQ_cjs.undo),
|
|
1648
|
+
historyRedo: run(chunkVFSVN5IQ_cjs.redo),
|
|
1695
1649
|
insertTranspose: run(transposeChars),
|
|
1696
1650
|
insertFromPaste: leaveToHandlers,
|
|
1697
1651
|
insertFromDrop: leaveToHandlers,
|
|
@@ -1782,7 +1736,7 @@ function commitEmptyHost(controller) {
|
|
|
1782
1736
|
// src/view/input/composition-snapshot.ts
|
|
1783
1737
|
function composedEnd(controller, block, region) {
|
|
1784
1738
|
const { selection } = controller.editor.state;
|
|
1785
|
-
if (
|
|
1739
|
+
if (selection?.kind !== "text") return void 0;
|
|
1786
1740
|
const ends = [selection.anchor, selection.head];
|
|
1787
1741
|
if (ends.some((pos) => pos.block !== block || pos.region !== region)) return void 0;
|
|
1788
1742
|
return Math.max(...ends.map((pos) => pos.offset));
|
|
@@ -1792,7 +1746,7 @@ function snapshotComposition(controller, block, region) {
|
|
|
1792
1746
|
const element = controller.registry.get(block, region);
|
|
1793
1747
|
const inline = regionInline(editor.state, block, region);
|
|
1794
1748
|
if (element === void 0 || inline === void 0) return null;
|
|
1795
|
-
const text =
|
|
1749
|
+
const text = chunkAIS37SL2_cjs.inlineText(inline);
|
|
1796
1750
|
const end = composedEnd(controller, block, region);
|
|
1797
1751
|
const since = [];
|
|
1798
1752
|
const release = editor.subscribe((_, tr) => void (tr && since.push(tr)));
|
|
@@ -1824,10 +1778,10 @@ var EMPTY_HOST = "empty";
|
|
|
1824
1778
|
function targetAt(controller, node) {
|
|
1825
1779
|
const entry = controller.registry.locate(node);
|
|
1826
1780
|
if (entry !== null) return { block: entry.block, region: entry.region };
|
|
1827
|
-
return node !== null &&
|
|
1781
|
+
return node !== null && controller.emptyHost?.contains(node) ? EMPTY_HOST : null;
|
|
1828
1782
|
}
|
|
1829
1783
|
function elementOf(controller, target) {
|
|
1830
|
-
if (target === EMPTY_HOST) return
|
|
1784
|
+
if (target === EMPTY_HOST) return controller.emptyHost ?? void 0;
|
|
1831
1785
|
return target ? controller.registry.get(target.block, target.region) : void 0;
|
|
1832
1786
|
}
|
|
1833
1787
|
function createCompositionHandlers(controller) {
|
|
@@ -1836,7 +1790,7 @@ function createCompositionHandlers(controller) {
|
|
|
1836
1790
|
let snapshot = null;
|
|
1837
1791
|
let stopWaiting = null;
|
|
1838
1792
|
function settle() {
|
|
1839
|
-
|
|
1793
|
+
stopWaiting?.();
|
|
1840
1794
|
stopWaiting = null;
|
|
1841
1795
|
active = false;
|
|
1842
1796
|
controller.composingKey = null;
|
|
@@ -1845,7 +1799,7 @@ function createCompositionHandlers(controller) {
|
|
|
1845
1799
|
target = null;
|
|
1846
1800
|
snapshot = null;
|
|
1847
1801
|
if (host === EMPTY_HOST) commitEmptyHost(controller);
|
|
1848
|
-
else if (host !== null && !
|
|
1802
|
+
else if (host !== null && !started?.settle()) {
|
|
1849
1803
|
controller.renderHost(host.block, host.region);
|
|
1850
1804
|
controller.syncSelectionToDom();
|
|
1851
1805
|
}
|
|
@@ -1853,17 +1807,17 @@ function createCompositionHandlers(controller) {
|
|
|
1853
1807
|
function waitForInput(element) {
|
|
1854
1808
|
const onInput = () => settle();
|
|
1855
1809
|
const timer = setTimeout(settle, 0);
|
|
1856
|
-
|
|
1810
|
+
element?.addEventListener("input", onInput);
|
|
1857
1811
|
stopWaiting = () => {
|
|
1858
1812
|
clearTimeout(timer);
|
|
1859
|
-
|
|
1813
|
+
element?.removeEventListener("input", onInput);
|
|
1860
1814
|
};
|
|
1861
1815
|
}
|
|
1862
1816
|
return {
|
|
1863
1817
|
start() {
|
|
1864
1818
|
if (stopWaiting !== null) settle();
|
|
1865
|
-
|
|
1866
|
-
target = targetAt(controller,
|
|
1819
|
+
snapshot?.release();
|
|
1820
|
+
target = targetAt(controller, controller.domSelection()?.anchorNode ?? null);
|
|
1867
1821
|
const host = target === EMPTY_HOST ? null : target;
|
|
1868
1822
|
snapshot = host && snapshotComposition(controller, host.block, host.region);
|
|
1869
1823
|
active = true;
|
|
@@ -1875,7 +1829,7 @@ function createCompositionHandlers(controller) {
|
|
|
1875
1829
|
},
|
|
1876
1830
|
release() {
|
|
1877
1831
|
if (stopWaiting !== null) settle();
|
|
1878
|
-
|
|
1832
|
+
snapshot?.release();
|
|
1879
1833
|
snapshot = null;
|
|
1880
1834
|
target = null;
|
|
1881
1835
|
if (active) controller.composingKey = null;
|
|
@@ -1891,7 +1845,7 @@ function createCompositionHandlers(controller) {
|
|
|
1891
1845
|
function domCaretOffset(host) {
|
|
1892
1846
|
const doc = host.ownerDocument;
|
|
1893
1847
|
const selection = doc.getSelection();
|
|
1894
|
-
const node =
|
|
1848
|
+
const node = selection?.focusNode;
|
|
1895
1849
|
if (!selection || !node || !host.contains(node)) return void 0;
|
|
1896
1850
|
const range = doc.createRange();
|
|
1897
1851
|
range.setStart(host, 0);
|
|
@@ -1904,9 +1858,9 @@ function reconcileHost(controller, block, region, caretHint) {
|
|
|
1904
1858
|
const element = controller.registry.get(block, region);
|
|
1905
1859
|
const inline = regionInline(controller.editor.state, block, region);
|
|
1906
1860
|
if (element === void 0 || inline === void 0) return false;
|
|
1907
|
-
const before =
|
|
1861
|
+
const before = chunkAIS37SL2_cjs.inlineText(inline);
|
|
1908
1862
|
const after = readDomText(element);
|
|
1909
|
-
const edit = before === after ? null : textDiff(before, after,
|
|
1863
|
+
const edit = before === after ? null : textDiff(before, after, domCaretOffset(element));
|
|
1910
1864
|
if (edit === null) return false;
|
|
1911
1865
|
const at = (offset) => ({ block, region, offset });
|
|
1912
1866
|
controller.edit(() => {
|
|
@@ -1961,7 +1915,7 @@ function createDomInputFallback(controller) {
|
|
|
1961
1915
|
};
|
|
1962
1916
|
},
|
|
1963
1917
|
drain(host) {
|
|
1964
|
-
|
|
1918
|
+
observers.get(host)?.takeRecords();
|
|
1965
1919
|
},
|
|
1966
1920
|
flush
|
|
1967
1921
|
};
|
|
@@ -1969,33 +1923,33 @@ function createDomInputFallback(controller) {
|
|
|
1969
1923
|
|
|
1970
1924
|
// src/view/navigation/cross-moves.ts
|
|
1971
1925
|
function moveHead(controller, { anchor }, head) {
|
|
1972
|
-
dispatchSelection(controller,
|
|
1926
|
+
dispatchSelection(controller, chunkVFSVN5IQ_cjs.textSelection(anchor, head));
|
|
1973
1927
|
return true;
|
|
1974
1928
|
}
|
|
1975
1929
|
function blockOf(controller, { block }) {
|
|
1976
1930
|
const { doc } = controller.editor.state;
|
|
1977
|
-
return doc.blocks[
|
|
1931
|
+
return doc.blocks[chunkAIS37SL2_cjs.requireBlockIndex(doc, block)];
|
|
1978
1932
|
}
|
|
1979
1933
|
function collapseCross(controller, selection, direction) {
|
|
1980
|
-
const { from, to } =
|
|
1981
|
-
dispatchSelection(controller,
|
|
1934
|
+
const { from, to } = chunkVFSVN5IQ_cjs.selectionRange(controller.editor.state.doc, selection);
|
|
1935
|
+
dispatchSelection(controller, chunkVFSVN5IQ_cjs.textSelection(direction < 0 ? from : to));
|
|
1982
1936
|
return true;
|
|
1983
1937
|
}
|
|
1984
1938
|
function crossHeadVertically(controller, selection, direction) {
|
|
1985
1939
|
const { head } = selection;
|
|
1986
1940
|
const edge = neighbourHead(controller, head.block, direction);
|
|
1987
1941
|
if (edge !== null) {
|
|
1988
|
-
const end2 =
|
|
1942
|
+
const end2 = chunkVFSVN5IQ_cjs.regionLength(blockOf(controller, edge), edge.region);
|
|
1989
1943
|
return moveHead(controller, selection, { ...edge, offset: Math.min(head.offset, end2) });
|
|
1990
1944
|
}
|
|
1991
|
-
const end =
|
|
1945
|
+
const end = chunkVFSVN5IQ_cjs.regionLength(blockOf(controller, head), head.region);
|
|
1992
1946
|
return moveHead(controller, selection, { ...head, offset: direction < 0 ? 0 : end });
|
|
1993
1947
|
}
|
|
1994
1948
|
function crossHeadHorizontally(controller, selection, direction) {
|
|
1995
1949
|
const { head } = selection;
|
|
1996
|
-
const text =
|
|
1950
|
+
const text = chunkAIS37SL2_cjs.inlineText(blockOf(controller, head).regions[head.region] ?? []);
|
|
1997
1951
|
if (direction < 0 ? head.offset > 0 : head.offset < text.length) {
|
|
1998
|
-
const offset = direction < 0 ?
|
|
1952
|
+
const offset = direction < 0 ? chunkVFSVN5IQ_cjs.prevGraphemeOffset(text, head.offset) : chunkVFSVN5IQ_cjs.nextGraphemeOffset(text, head.offset);
|
|
1999
1953
|
return moveHead(controller, selection, { ...head, offset });
|
|
2000
1954
|
}
|
|
2001
1955
|
const edge = neighbourHead(controller, head.block, direction);
|
|
@@ -2008,15 +1962,15 @@ function moveHorizontally(controller, direction, extend) {
|
|
|
2008
1962
|
const { editor } = controller;
|
|
2009
1963
|
const { state } = editor;
|
|
2010
1964
|
const { selection, doc } = state;
|
|
2011
|
-
if (
|
|
2012
|
-
if (
|
|
1965
|
+
if (selection?.kind === "node") return !extend && moveToNeighbour(controller, selection.block, direction);
|
|
1966
|
+
if (selection?.kind !== "text") return false;
|
|
2013
1967
|
if (isCrossSelection(selection)) {
|
|
2014
1968
|
const move = extend ? crossHeadHorizontally : collapseCross;
|
|
2015
1969
|
return move(controller, selection, direction);
|
|
2016
1970
|
}
|
|
2017
|
-
if (!extend && !
|
|
1971
|
+
if (!extend && !chunkVFSVN5IQ_cjs.isCollapsed(selection)) return false;
|
|
2018
1972
|
const { head } = selection;
|
|
2019
|
-
const length =
|
|
1973
|
+
const length = chunkVFSVN5IQ_cjs.regionLength(doc.blocks[chunkAIS37SL2_cjs.requireBlockIndex(doc, head.block)], head.region);
|
|
2020
1974
|
if (direction < 0 ? head.offset > 0 : head.offset < length) return false;
|
|
2021
1975
|
const own2 = extend ? null : ownNode(controller, head.block, direction);
|
|
2022
1976
|
if (own2 !== null) {
|
|
@@ -2026,7 +1980,7 @@ function moveHorizontally(controller, direction, extend) {
|
|
|
2026
1980
|
if (!extend) return moveToNeighbour(controller, head.block, direction);
|
|
2027
1981
|
const edge = neighbourHead(controller, head.block, direction);
|
|
2028
1982
|
if (edge === null) return false;
|
|
2029
|
-
dispatchSelection(controller,
|
|
1983
|
+
dispatchSelection(controller, chunkVFSVN5IQ_cjs.textSelection(selection.anchor, edge));
|
|
2030
1984
|
return true;
|
|
2031
1985
|
}
|
|
2032
1986
|
|
|
@@ -2053,7 +2007,7 @@ function caretClientRect(point) {
|
|
|
2053
2007
|
if (node.nodeType === TEXT_NODE3) return textCaretRect(node, offset);
|
|
2054
2008
|
const after = node.childNodes[offset];
|
|
2055
2009
|
const before = node.childNodes[offset - 1];
|
|
2056
|
-
return
|
|
2010
|
+
return (after && besideNode(after, true)) ?? (before && besideNode(before, false)) ?? null;
|
|
2057
2011
|
}
|
|
2058
2012
|
function contentBox(host) {
|
|
2059
2013
|
const box = host.getBoundingClientRect();
|
|
@@ -2070,7 +2024,7 @@ function lineEdgeRect(host, last) {
|
|
|
2070
2024
|
return caretClientRect(map.toDom(last ? map.length : 0, last ? -1 : 1));
|
|
2071
2025
|
}
|
|
2072
2026
|
function onEdgeLine(host, point, last) {
|
|
2073
|
-
if (
|
|
2027
|
+
if (domMapOf(host)?.length === 0) return true;
|
|
2074
2028
|
const caret = caretClientRect(point);
|
|
2075
2029
|
const edge = lineEdgeRect(host, last);
|
|
2076
2030
|
if (!caret || !edge) return false;
|
|
@@ -2124,12 +2078,12 @@ function caretAtGoal(controller, host, at, y) {
|
|
|
2124
2078
|
}
|
|
2125
2079
|
function landAtGoal(controller, block, direction) {
|
|
2126
2080
|
const { schema } = controller.editor.state;
|
|
2127
|
-
const region =
|
|
2081
|
+
const region = chunkVFSVN5IQ_cjs.isTextFlow(schema, block) ? chunkVFSVN5IQ_cjs.primaryRegion(schema, block) : null;
|
|
2128
2082
|
const host = region === null ? void 0 : controller.registry.get(block.id, region);
|
|
2129
2083
|
if (!host || region === null || controller.goalX === null) return null;
|
|
2130
2084
|
const line = lineInView(host, direction < 0);
|
|
2131
2085
|
const pos = line && caretAtGoal(controller, host, { block: block.id, region }, line.top + line.height / 2);
|
|
2132
|
-
return pos ?
|
|
2086
|
+
return pos ? chunkVFSVN5IQ_cjs.textSelection(pos) : null;
|
|
2133
2087
|
}
|
|
2134
2088
|
function moveInHost(controller, host, head, caret, direction) {
|
|
2135
2089
|
const { goalX } = controller;
|
|
@@ -2144,16 +2098,16 @@ function landing(controller, { head }, direction, extend) {
|
|
|
2144
2098
|
const point = posToDom(registry, head);
|
|
2145
2099
|
if (!host || !point) return null;
|
|
2146
2100
|
const caret = caretClientRect(point);
|
|
2147
|
-
controller.goalX ??=
|
|
2101
|
+
controller.goalX ??= caret?.left ?? null;
|
|
2148
2102
|
if (!(direction < 0 ? isOnFirstLine(host, point) : isOnLastLine(host, point))) {
|
|
2149
2103
|
const pos = moveInHost(controller, host, head, caret, direction);
|
|
2150
|
-
return pos &&
|
|
2104
|
+
return pos && chunkVFSVN5IQ_cjs.textSelection(pos);
|
|
2151
2105
|
}
|
|
2152
2106
|
const own2 = extend ? null : ownNode(controller, head.block, direction);
|
|
2153
2107
|
if (own2 !== null) return own2;
|
|
2154
|
-
const accept = extend ? holdsTextHead(controller) :
|
|
2108
|
+
const accept = extend ? holdsTextHead(controller) : canBeEntered(controller);
|
|
2155
2109
|
const target = neighbourBlock(controller.editor.state.doc, head.block, direction, accept);
|
|
2156
|
-
return target && (
|
|
2110
|
+
return target && (landAtGoal(controller, target, direction) ?? entryEdge(controller, target.id, direction));
|
|
2157
2111
|
}
|
|
2158
2112
|
function moveText(controller, selection, direction, extend) {
|
|
2159
2113
|
const next = landing(controller, selection, direction, extend);
|
|
@@ -2161,21 +2115,21 @@ function moveText(controller, selection, direction, extend) {
|
|
|
2161
2115
|
controller.nativeVerticalMove = true;
|
|
2162
2116
|
return false;
|
|
2163
2117
|
}
|
|
2164
|
-
const moved = extend && next.kind === "text" ?
|
|
2118
|
+
const moved = extend && next.kind === "text" ? chunkVFSVN5IQ_cjs.textSelection(selection.anchor, next.head) : next;
|
|
2165
2119
|
dispatchSelection(controller, moved);
|
|
2166
2120
|
return true;
|
|
2167
2121
|
}
|
|
2168
2122
|
function extendBlocks(controller, { anchor, head }, direction) {
|
|
2169
2123
|
const next = neighbourBlock(controller.editor.state.doc, head, direction);
|
|
2170
2124
|
if (next === null) return false;
|
|
2171
|
-
dispatchSelection(controller,
|
|
2125
|
+
dispatchSelection(controller, chunkVFSVN5IQ_cjs.blockRangeSelection(anchor, next.id));
|
|
2172
2126
|
return true;
|
|
2173
2127
|
}
|
|
2174
2128
|
function moveVertically(controller, direction, extend) {
|
|
2175
2129
|
const { selection } = controller.editor.state;
|
|
2176
|
-
if (
|
|
2177
|
-
if (
|
|
2178
|
-
if (
|
|
2130
|
+
if (selection?.kind === "node") return !extend && moveToNeighbour(controller, selection.block, direction);
|
|
2131
|
+
if (selection?.kind === "blocks") return extend && extendBlocks(controller, selection, direction);
|
|
2132
|
+
if (selection?.kind !== "text") return false;
|
|
2179
2133
|
if (!isCrossSelection(selection)) return moveText(controller, selection, direction, extend);
|
|
2180
2134
|
controller.goalX = null;
|
|
2181
2135
|
return (extend ? crossHeadVertically : collapseCross)(controller, selection, direction);
|
|
@@ -2184,8 +2138,8 @@ function moveVertically(controller, direction, extend) {
|
|
|
2184
2138
|
// src/view/input/flip-block.ts
|
|
2185
2139
|
var isTask = ({ type, attrs }) => type === "MARKDOWN" && attrs.kind === "task";
|
|
2186
2140
|
function flipCommand(block) {
|
|
2187
|
-
if (isTask(block)) return
|
|
2188
|
-
return block.type === "TOGGLE" ?
|
|
2141
|
+
if (isTask(block)) return chunkVFSVN5IQ_cjs.toggleTask;
|
|
2142
|
+
return block.type === "TOGGLE" ? chunkVFSVN5IQ_cjs.setAttrs({ open: block.attrs.open !== true }) : null;
|
|
2189
2143
|
}
|
|
2190
2144
|
var toggleState = (open) => open ? "expanded" : "collapsed";
|
|
2191
2145
|
function stateName(block) {
|
|
@@ -2193,11 +2147,11 @@ function stateName(block) {
|
|
|
2193
2147
|
return toggleState(block.attrs.open === true);
|
|
2194
2148
|
}
|
|
2195
2149
|
function blockHoldingCaret({ doc, selection }) {
|
|
2196
|
-
if (
|
|
2197
|
-
return
|
|
2150
|
+
if (selection?.kind !== "text" || selection.anchor.block !== selection.head.block) return null;
|
|
2151
|
+
return chunkAIS37SL2_cjs.blockById(doc, selection.head.block) ?? null;
|
|
2198
2152
|
}
|
|
2199
2153
|
function flipForReader(controller, block) {
|
|
2200
|
-
if (
|
|
2154
|
+
if (block?.type !== "TOGGLE") return false;
|
|
2201
2155
|
const toggles = readerToggles(controller);
|
|
2202
2156
|
toggles.flip(block);
|
|
2203
2157
|
controller.announce(toggleState(shownOpen(block, toggles.choices)));
|
|
@@ -2209,7 +2163,7 @@ function flipSelectedBlock(controller) {
|
|
|
2209
2163
|
if (controller.readOnly) return flipForReader(controller, block);
|
|
2210
2164
|
const command = block && flipCommand(block);
|
|
2211
2165
|
if (!block || !command || !controller.run(command)) return false;
|
|
2212
|
-
const after =
|
|
2166
|
+
const after = chunkAIS37SL2_cjs.blockById(editor.state.doc, block.id);
|
|
2213
2167
|
if (after) controller.announce(stateName(after));
|
|
2214
2168
|
return true;
|
|
2215
2169
|
}
|
|
@@ -2238,12 +2192,12 @@ function tab(controller, event) {
|
|
|
2238
2192
|
}
|
|
2239
2193
|
function typeOverNode(controller, event) {
|
|
2240
2194
|
const { key } = event;
|
|
2241
|
-
const node =
|
|
2195
|
+
const node = controller.editor.state.selection?.kind === "node";
|
|
2242
2196
|
if (!node || event.ctrlKey || event.metaKey || [...key].length !== 1) return false;
|
|
2243
2197
|
return controller.edit(() => controller.editor.insertText(key));
|
|
2244
2198
|
}
|
|
2245
2199
|
function holdHistoryKeys(controller, event) {
|
|
2246
|
-
const kind =
|
|
2200
|
+
const kind = controller.editor.state.selection?.kind;
|
|
2247
2201
|
if (kind !== "node" && kind !== "blocks") return false;
|
|
2248
2202
|
return Object.hasOwn(ARROWS, event.key) && (event.metaKey || event.ctrlKey || event.altKey);
|
|
2249
2203
|
}
|
|
@@ -2295,12 +2249,12 @@ function attachInput(controller, root) {
|
|
|
2295
2249
|
};
|
|
2296
2250
|
const onInput = (event) => fallback.onInput(event);
|
|
2297
2251
|
const onCompositionStart = (event) => {
|
|
2298
|
-
if (inHost(event) || inEmptyHost(event)) composition.start(
|
|
2252
|
+
if (inHost(event) || inEmptyHost(event)) composition.start();
|
|
2299
2253
|
else if (inSink(event)) sinkComposition.start();
|
|
2300
2254
|
};
|
|
2301
2255
|
const onCompositionEnd = (event) => {
|
|
2302
2256
|
if (inSink(event)) sinkComposition.end();
|
|
2303
|
-
else composition.end(
|
|
2257
|
+
else composition.end();
|
|
2304
2258
|
};
|
|
2305
2259
|
const detachClipboard = attachClipboard(controller, root, catchUp);
|
|
2306
2260
|
const unlisten = listen(root, {
|
|
@@ -2317,7 +2271,7 @@ function attachInput(controller, root) {
|
|
|
2317
2271
|
return {
|
|
2318
2272
|
observe,
|
|
2319
2273
|
unobserve(host) {
|
|
2320
|
-
|
|
2274
|
+
observed.get(host)?.();
|
|
2321
2275
|
observed.delete(host);
|
|
2322
2276
|
},
|
|
2323
2277
|
drain: fallback.drain,
|
|
@@ -2357,10 +2311,10 @@ function watchFocusReturn(root, handlers) {
|
|
|
2357
2311
|
|
|
2358
2312
|
// src/view/controller/selection-sync.ts
|
|
2359
2313
|
var selectionPoints = (selection) => [
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2314
|
+
selection?.anchorNode ?? null,
|
|
2315
|
+
selection?.anchorOffset ?? 0,
|
|
2316
|
+
selection?.focusNode ?? null,
|
|
2317
|
+
selection?.focusOffset ?? 0
|
|
2364
2318
|
];
|
|
2365
2319
|
var samePoints = (a, b) => a.every((point, index) => point === b[index]);
|
|
2366
2320
|
function createSelectionSync(doc, onChange) {
|
|
@@ -2420,17 +2374,17 @@ function bindRoot(controller, root, cross, committed) {
|
|
|
2420
2374
|
function movedSelection(controller, doc, model) {
|
|
2421
2375
|
if (controller.composingKey !== null || controller.dragging || !doc || !ownsFocus(controller, doc)) return null;
|
|
2422
2376
|
const selection = readSelection(controller.registry, doc.getSelection(), (node) => controller.blockAt(node));
|
|
2423
|
-
return selection === null ||
|
|
2377
|
+
return selection === null || chunkVFSVN5IQ_cjs.sameSelection(selection, model) ? null : selection;
|
|
2424
2378
|
}
|
|
2425
2379
|
function writeModelSelection(controller, doc, moved, local) {
|
|
2426
|
-
const domSelection =
|
|
2380
|
+
const domSelection = doc?.getSelection();
|
|
2427
2381
|
if (focusingSink(controller) || controller.composingKey !== null || !doc || !domSelection || !ownsFocus(controller, doc)) {
|
|
2428
2382
|
return;
|
|
2429
2383
|
}
|
|
2430
2384
|
const before = selectionPoints(domSelection);
|
|
2431
2385
|
const { selection } = controller.editor.state;
|
|
2432
2386
|
if (heldBySink(selection) && controller.sink !== null) focusSink(controller);
|
|
2433
|
-
else if (
|
|
2387
|
+
else if (selection?.kind === "blocks") domSelection.removeAllRanges();
|
|
2434
2388
|
else writeSelection(controller.registry, selection, domSelection, (id) => controller.blockElement(id));
|
|
2435
2389
|
controller.nodeReveal.show(selection, local);
|
|
2436
2390
|
if (!samePoints(before, selectionPoints(domSelection))) moved();
|
|
@@ -2438,25 +2392,25 @@ function writeModelSelection(controller, doc, moved, local) {
|
|
|
2438
2392
|
|
|
2439
2393
|
// src/view/controller/view-controller.ts
|
|
2440
2394
|
var runNow = (fn) => fn();
|
|
2441
|
-
var ViewController =
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2395
|
+
var ViewController = class {
|
|
2396
|
+
editor;
|
|
2397
|
+
registry = createHostRegistry((element) => {
|
|
2398
|
+
this.#binding?.input.observe(element);
|
|
2445
2399
|
this.#drawn.syncTabStop();
|
|
2446
2400
|
return () => {
|
|
2447
|
-
|
|
2401
|
+
this.#binding?.input.unobserve(element);
|
|
2448
2402
|
this.#drawn.syncTabStop();
|
|
2449
2403
|
};
|
|
2450
|
-
})
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2404
|
+
});
|
|
2405
|
+
keyInterceptors = /* @__PURE__ */ new Set();
|
|
2406
|
+
nodeReveal = createNodeReveal((id) => this.blockElement(id));
|
|
2407
|
+
announcer = createAnnouncer(() => this.#said);
|
|
2408
|
+
isMac;
|
|
2409
|
+
onFiles;
|
|
2410
|
+
goalX = null;
|
|
2411
|
+
nativeVerticalMove = false;
|
|
2412
|
+
dragging = false;
|
|
2413
|
+
composingKey = null;
|
|
2460
2414
|
#flush;
|
|
2461
2415
|
#hosts;
|
|
2462
2416
|
#drawn = createDrawnElements(this.registry, () => this.editor.state);
|
|
@@ -2471,21 +2425,21 @@ var ViewController = (_class = class {
|
|
|
2471
2425
|
#said;
|
|
2472
2426
|
#detachRoot = null;
|
|
2473
2427
|
#readOnlyState;
|
|
2474
|
-
constructor(options) {
|
|
2428
|
+
constructor(options) {
|
|
2475
2429
|
this.editor = options.editor;
|
|
2476
2430
|
options.editor.subscribe((state, tr) => {
|
|
2477
|
-
if (
|
|
2431
|
+
if (tr?.origin !== "remote") this.#said = state;
|
|
2478
2432
|
});
|
|
2479
|
-
this.#flush =
|
|
2433
|
+
this.#flush = options.flush ?? runNow;
|
|
2480
2434
|
this.onFiles = options.onFiles;
|
|
2481
|
-
this.isMac =
|
|
2435
|
+
this.isMac = options.isMac ?? chunkVFSVN5IQ_cjs.detectMac();
|
|
2482
2436
|
const decorationsOf = (block, region) => this.decorationsFor(block, region);
|
|
2483
|
-
const drain = (element) =>
|
|
2437
|
+
const drain = (element) => this.#binding?.input.drain(element);
|
|
2484
2438
|
this.#hosts = createHostRenderer(options.editor, options.render, decorationsOf, drain);
|
|
2485
|
-
this.#readOnlyState = createReadOnly(this.registry,
|
|
2439
|
+
this.#readOnlyState = createReadOnly(this.registry, options.readOnly ?? false);
|
|
2486
2440
|
}
|
|
2487
2441
|
get root() {
|
|
2488
|
-
return
|
|
2442
|
+
return this.#binding?.root ?? null;
|
|
2489
2443
|
}
|
|
2490
2444
|
get readOnly() {
|
|
2491
2445
|
return this.#readOnlyState.current();
|
|
@@ -2497,10 +2451,10 @@ var ViewController = (_class = class {
|
|
|
2497
2451
|
return this.#drawn.emptyHost;
|
|
2498
2452
|
}
|
|
2499
2453
|
attach(root) {
|
|
2500
|
-
|
|
2454
|
+
this.#detachRoot?.();
|
|
2501
2455
|
const binding = bindRoot(this, root, this.#cross, (_, tr) => {
|
|
2502
|
-
this.#quiet ||=
|
|
2503
|
-
this.#loud ||=
|
|
2456
|
+
this.#quiet ||= tr?.origin === "remote" && tr.docChanged;
|
|
2457
|
+
this.#loud ||= tr?.origin !== "remote";
|
|
2504
2458
|
this.#outside.committed(tr);
|
|
2505
2459
|
this.nodeReveal.follow(this.editor.state.selection);
|
|
2506
2460
|
this.#drawn.syncTabStop();
|
|
@@ -2605,14 +2559,14 @@ var ViewController = (_class = class {
|
|
|
2605
2559
|
const element = this.registry.get(block, region);
|
|
2606
2560
|
const host = element && { block, region, element };
|
|
2607
2561
|
if (!host || this.#isComposing(host) || !this.#hosts.render(host)) return;
|
|
2608
|
-
const inSelection = element.contains(
|
|
2562
|
+
const inSelection = element.contains(this.domSelection()?.focusNode ?? null);
|
|
2609
2563
|
if (inSelection && hasFocus(this, element.ownerDocument)) this.syncSelectionToDom();
|
|
2610
2564
|
}
|
|
2611
2565
|
domSelection() {
|
|
2612
|
-
return
|
|
2566
|
+
return this.#ownerDocument()?.getSelection() ?? null;
|
|
2613
2567
|
}
|
|
2614
2568
|
syncSelectionToDom(local) {
|
|
2615
|
-
writeModelSelection(this, this.#ownerDocument(), () =>
|
|
2569
|
+
writeModelSelection(this, this.#ownerDocument(), () => this.#binding?.selectionSync.suppressNext(), local);
|
|
2616
2570
|
}
|
|
2617
2571
|
// A pointer drag across hosts sets the model selection itself, while the browser keeps extending its own. Leaving
|
|
2618
2572
|
// cross mode re-renders the hosts that drew it as decorations, which can remove the node holding the caret, so the
|
|
@@ -2631,7 +2585,7 @@ var ViewController = (_class = class {
|
|
|
2631
2585
|
focus(target) {
|
|
2632
2586
|
const { editor } = this;
|
|
2633
2587
|
const selection = focusTarget(editor.state, target);
|
|
2634
|
-
if (selection !== null && !
|
|
2588
|
+
if (selection !== null && !chunkVFSVN5IQ_cjs.sameSelection(selection, editor.state.selection)) dispatchSelection(this, selection);
|
|
2635
2589
|
this.#takeFocus();
|
|
2636
2590
|
this.syncSelectionToDom();
|
|
2637
2591
|
}
|
|
@@ -2642,7 +2596,7 @@ var ViewController = (_class = class {
|
|
|
2642
2596
|
return this.#readOnlyState.subscribe(listener);
|
|
2643
2597
|
}
|
|
2644
2598
|
destroy() {
|
|
2645
|
-
|
|
2599
|
+
this.#detachRoot?.();
|
|
2646
2600
|
}
|
|
2647
2601
|
#selectFromDom(selection) {
|
|
2648
2602
|
const { editor } = this;
|
|
@@ -2652,7 +2606,7 @@ var ViewController = (_class = class {
|
|
|
2652
2606
|
return this.composingKey !== null && hostKey(host.block, host.region) === this.composingKey;
|
|
2653
2607
|
}
|
|
2654
2608
|
#ownerDocument() {
|
|
2655
|
-
return
|
|
2609
|
+
return (this.#binding?.root ?? this.registry.all().next().value?.element)?.ownerDocument ?? null;
|
|
2656
2610
|
}
|
|
2657
2611
|
// React replaces a host whose block changes kind, which drops focus, and Firefox does not move focus into another
|
|
2658
2612
|
// host when a script selects inside it.
|
|
@@ -2665,42 +2619,32 @@ var ViewController = (_class = class {
|
|
|
2665
2619
|
if (element === this.sink) focusSink(this);
|
|
2666
2620
|
else element.focus({ preventScroll });
|
|
2667
2621
|
}
|
|
2668
|
-
}
|
|
2669
|
-
|
|
2670
|
-
// src/view/react/editor-context.ts
|
|
2671
|
-
|
|
2672
|
-
var QuoinEditorContext = _react.createContext.call(void 0, null);
|
|
2622
|
+
};
|
|
2623
|
+
var QuoinEditorContext = react.createContext(null);
|
|
2673
2624
|
function useViewController() {
|
|
2674
|
-
const controller =
|
|
2625
|
+
const controller = react.useContext(QuoinEditorContext);
|
|
2675
2626
|
if (controller === null) throw new Error("useViewController must be called inside an EditorView");
|
|
2676
2627
|
return controller;
|
|
2677
2628
|
}
|
|
2678
|
-
|
|
2679
|
-
// src/view/react/use-quoin-editor.ts
|
|
2680
|
-
|
|
2681
|
-
var _reactdom = require('react-dom');
|
|
2682
|
-
|
|
2683
|
-
// src/view/react/use-isomorphic-layout-effect.ts
|
|
2684
|
-
|
|
2685
|
-
var useIsomorphicLayoutEffect = typeof document === "undefined" ? _react.useEffect : _react.useLayoutEffect;
|
|
2629
|
+
var useIsomorphicLayoutEffect = typeof document === "undefined" ? react.useEffect : react.useLayoutEffect;
|
|
2686
2630
|
|
|
2687
2631
|
// src/view/react/use-quoin-editor.ts
|
|
2688
2632
|
function useQuoinEditor(options) {
|
|
2689
2633
|
const { blocks, readOnly = false } = options;
|
|
2690
|
-
const callbacks =
|
|
2691
|
-
const [controller] =
|
|
2692
|
-
const editor =
|
|
2634
|
+
const callbacks = react.useRef(options);
|
|
2635
|
+
const [controller] = react.useState(() => {
|
|
2636
|
+
const editor = chunkVFSVN5IQ_cjs.createEditor({
|
|
2693
2637
|
blocks,
|
|
2694
2638
|
extensions: options.extensions,
|
|
2695
2639
|
onChange: (next) => callbacks.current.onChange(next),
|
|
2696
|
-
onTransaction: (tr, state) =>
|
|
2640
|
+
onTransaction: (tr, state) => callbacks.current.onTransaction?.(tr, state)
|
|
2697
2641
|
});
|
|
2698
2642
|
return new ViewController({
|
|
2699
2643
|
editor,
|
|
2700
|
-
flush:
|
|
2644
|
+
flush: reactDom.flushSync,
|
|
2701
2645
|
render: options.render,
|
|
2702
2646
|
readOnly,
|
|
2703
|
-
onFiles: (files, at) =>
|
|
2647
|
+
onFiles: (files, at) => callbacks.current.onFiles?.(files, at)
|
|
2704
2648
|
});
|
|
2705
2649
|
});
|
|
2706
2650
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -2712,36 +2656,27 @@ function useQuoinEditor(options) {
|
|
|
2712
2656
|
useIsomorphicLayoutEffect(() => {
|
|
2713
2657
|
controller.setReadOnly(readOnly);
|
|
2714
2658
|
}, [controller, readOnly]);
|
|
2715
|
-
|
|
2659
|
+
react.useEffect(() => () => controller.destroy(), [controller]);
|
|
2716
2660
|
return controller;
|
|
2717
2661
|
}
|
|
2718
|
-
|
|
2719
|
-
// src/view/react/SelectionSink.tsx
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
// src/view/react/use-read-only.ts
|
|
2723
|
-
|
|
2724
2662
|
function useReadOnly(controller) {
|
|
2725
|
-
const subscribe =
|
|
2726
|
-
const read =
|
|
2727
|
-
return
|
|
2663
|
+
const subscribe = react.useCallback((notify) => controller.subscribeReadOnly(notify), [controller]);
|
|
2664
|
+
const read = react.useCallback(() => controller.readOnly, [controller]);
|
|
2665
|
+
return react.useSyncExternalStore(subscribe, read, read);
|
|
2728
2666
|
}
|
|
2729
|
-
|
|
2730
|
-
// src/view/react/SelectionSink.tsx
|
|
2731
|
-
var _jsxruntime = require('react/jsx-runtime');
|
|
2732
2667
|
function SelectionSink({ label = "Selected content", blockLabel }) {
|
|
2733
2668
|
const controller = useViewController();
|
|
2734
|
-
const ref =
|
|
2669
|
+
const ref = react.useRef(null);
|
|
2735
2670
|
const readOnly = useReadOnly(controller);
|
|
2736
2671
|
const name = useEditorState(
|
|
2737
2672
|
controller,
|
|
2738
|
-
|
|
2673
|
+
react.useCallback((state) => selectedBlockName(state, blockLabel), [blockLabel])
|
|
2739
2674
|
);
|
|
2740
2675
|
useIsomorphicLayoutEffect(() => {
|
|
2741
2676
|
const sink = ref.current;
|
|
2742
2677
|
return sink ? controller.registerSink(sink) : void 0;
|
|
2743
2678
|
}, [controller]);
|
|
2744
|
-
return /* @__PURE__ */
|
|
2679
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2745
2680
|
"div",
|
|
2746
2681
|
{
|
|
2747
2682
|
ref,
|
|
@@ -2761,35 +2696,26 @@ function SelectionSink({ label = "Selected content", blockLabel }) {
|
|
|
2761
2696
|
}
|
|
2762
2697
|
);
|
|
2763
2698
|
}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
// src/view/react/block-placeholder.ts
|
|
2769
|
-
|
|
2770
|
-
var headingPlaceholder = (_state, { type, attrs }) => type === "MARKDOWN" && attrs.kind === "heading" ? `Heading ${_chunk4SLJNZSMcjs.headingLevel.call(void 0, attrs.level)}` : void 0;
|
|
2771
|
-
var BlockPlaceholderContext = _react.createContext.call(void 0, headingPlaceholder);
|
|
2699
|
+
var headingPlaceholder = (_state, { type, attrs }) => type === "MARKDOWN" && attrs.kind === "heading" ? `Heading ${chunkAIS37SL2_cjs.headingLevel(attrs.level)}` : void 0;
|
|
2700
|
+
var BlockPlaceholderContext = react.createContext(headingPlaceholder);
|
|
2772
2701
|
function regionPlaceholder(state, blockId, region, placeholderOf) {
|
|
2773
|
-
const block =
|
|
2774
|
-
return block !== void 0 &&
|
|
2702
|
+
const block = chunkAIS37SL2_cjs.blockById(state.doc, blockId);
|
|
2703
|
+
return block !== void 0 && chunkVFSVN5IQ_cjs.primaryRegion(state.schema, block) === region ? placeholderOf(state, block) : void 0;
|
|
2775
2704
|
}
|
|
2776
|
-
|
|
2777
|
-
// src/view/react/EditableRegion.tsx
|
|
2778
|
-
|
|
2779
2705
|
var samePainted = (a, b) => a.inline === b.inline && a.placeholder === b.placeholder && sameDecorations(a.decorations, b.decorations);
|
|
2780
2706
|
function EditableRegion({ block, region, label, id, placeholder, className }) {
|
|
2781
2707
|
const controller = useViewController();
|
|
2782
|
-
const placeholderOf =
|
|
2783
|
-
const ref =
|
|
2708
|
+
const placeholderOf = react.useContext(BlockPlaceholderContext);
|
|
2709
|
+
const ref = react.useRef(null);
|
|
2784
2710
|
const readOnly = useReadOnly(controller);
|
|
2785
|
-
const select =
|
|
2711
|
+
const select = react.useCallback(
|
|
2786
2712
|
(state) => {
|
|
2787
2713
|
const inline2 = regionInline(state, block, region);
|
|
2788
|
-
const empty = inline2 === void 0 ||
|
|
2714
|
+
const empty = inline2 === void 0 || chunkAIS37SL2_cjs.inlineLength(inline2) === 0;
|
|
2789
2715
|
return {
|
|
2790
2716
|
inline: inline2,
|
|
2791
2717
|
decorations: controller.decorationsFor(block, region),
|
|
2792
|
-
placeholder: empty ?
|
|
2718
|
+
placeholder: empty ? placeholder ?? regionPlaceholder(state, block, region, placeholderOf) : void 0
|
|
2793
2719
|
};
|
|
2794
2720
|
},
|
|
2795
2721
|
[controller, block, region, placeholder, placeholderOf]
|
|
@@ -2802,7 +2728,7 @@ function EditableRegion({ block, region, label, id, placeholder, className }) {
|
|
|
2802
2728
|
useIsomorphicLayoutEffect(() => {
|
|
2803
2729
|
controller.renderHost(block, region);
|
|
2804
2730
|
}, [controller, block, region, inline, decorations]);
|
|
2805
|
-
return /* @__PURE__ */
|
|
2731
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2806
2732
|
"div",
|
|
2807
2733
|
{
|
|
2808
2734
|
ref,
|
|
@@ -2822,44 +2748,35 @@ function EditableRegion({ block, region, label, id, placeholder, className }) {
|
|
|
2822
2748
|
}
|
|
2823
2749
|
);
|
|
2824
2750
|
}
|
|
2825
|
-
|
|
2826
|
-
// src/view/react/default-renderers.tsx
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
// src/view/react/callout-block.tsx
|
|
2830
|
-
|
|
2831
2751
|
var CalloutBlock = ({ block }) => {
|
|
2832
2752
|
const tone = typeof block.attrs.tone === "string" && block.attrs.tone !== "" ? block.attrs.tone : "info";
|
|
2833
|
-
return /* @__PURE__ */
|
|
2753
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-callout", "data-tone": tone, children: /* @__PURE__ */ jsxRuntime.jsx(EditableRegion, { block: block.id, region: "body", label: `Callout, ${tone}` }) });
|
|
2834
2754
|
};
|
|
2835
2755
|
|
|
2836
2756
|
// src/view/react/block-command.ts
|
|
2837
2757
|
function onBlock(id, command) {
|
|
2838
2758
|
return (state, dispatch) => {
|
|
2839
|
-
const { ok, tr } =
|
|
2759
|
+
const { ok, tr } = chunkVFSVN5IQ_cjs.runCommands(state, [chunkVFSVN5IQ_cjs.setSelection(chunkVFSVN5IQ_cjs.blockRangeSelection(id)), command]);
|
|
2840
2760
|
if (!ok || tr === null) return false;
|
|
2841
|
-
|
|
2761
|
+
dispatch?.(tr.setSelection(state.selection));
|
|
2842
2762
|
return true;
|
|
2843
2763
|
};
|
|
2844
2764
|
}
|
|
2845
2765
|
|
|
2846
2766
|
// src/view/react/prevent-mouse-focus.ts
|
|
2847
2767
|
var keepFocus = (event) => event.preventDefault();
|
|
2848
|
-
|
|
2849
|
-
// src/view/react/TaskCheckbox.tsx
|
|
2850
|
-
|
|
2851
2768
|
function TaskCheckbox({ block, controller, label, labelledBy }) {
|
|
2852
2769
|
const checked = block.attrs.checked === true;
|
|
2853
2770
|
const flip2 = flipCommand(block);
|
|
2854
2771
|
const readOnly = useReadOnly(controller);
|
|
2855
|
-
return /* @__PURE__ */
|
|
2772
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2856
2773
|
"button",
|
|
2857
2774
|
{
|
|
2858
2775
|
type: "button",
|
|
2859
2776
|
role: "checkbox",
|
|
2860
2777
|
"aria-checked": checked,
|
|
2861
2778
|
"aria-readonly": readOnly ? "true" : void 0,
|
|
2862
|
-
"aria-label":
|
|
2779
|
+
"aria-label": chunkAIS37SL2_cjs.firstNamed(label, "Task"),
|
|
2863
2780
|
"aria-labelledby": labelledBy,
|
|
2864
2781
|
className: "quoin-task-box",
|
|
2865
2782
|
contentEditable: false,
|
|
@@ -2868,7 +2785,7 @@ function TaskCheckbox({ block, controller, label, labelledBy }) {
|
|
|
2868
2785
|
onClick: () => {
|
|
2869
2786
|
if (flip2 && !controller.readOnly) controller.run(onBlock(block.id, flip2));
|
|
2870
2787
|
},
|
|
2871
|
-
children: checked ? /* @__PURE__ */
|
|
2788
|
+
children: checked ? /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3.5 8.5l3 3 6-7", fill: "none", stroke: "currentColor", strokeWidth: "2" }) }) : null
|
|
2872
2789
|
}
|
|
2873
2790
|
);
|
|
2874
2791
|
}
|
|
@@ -2890,7 +2807,7 @@ function numberDoc(doc) {
|
|
|
2890
2807
|
numbers[index] = run2.next++;
|
|
2891
2808
|
return;
|
|
2892
2809
|
}
|
|
2893
|
-
const start =
|
|
2810
|
+
const start = chunkAIS37SL2_cjs.orderedStart(block.attrs.start);
|
|
2894
2811
|
numbers[index] = start;
|
|
2895
2812
|
runs.push({ indent: block.indent, next: start + 1 });
|
|
2896
2813
|
});
|
|
@@ -2903,7 +2820,7 @@ function orderedNumber(doc, index) {
|
|
|
2903
2820
|
numbers = numberDoc(doc);
|
|
2904
2821
|
cache.set(doc, numbers);
|
|
2905
2822
|
}
|
|
2906
|
-
return
|
|
2823
|
+
return numbers[index] ?? 1;
|
|
2907
2824
|
}
|
|
2908
2825
|
|
|
2909
2826
|
// src/view/react/use-ordered-number.ts
|
|
@@ -2913,63 +2830,54 @@ function useOrderedNumber(controller, blockId) {
|
|
|
2913
2830
|
return index === void 0 ? 1 : orderedNumber(doc, index);
|
|
2914
2831
|
});
|
|
2915
2832
|
}
|
|
2916
|
-
|
|
2917
|
-
// src/view/react/markdown-block.tsx
|
|
2918
|
-
|
|
2919
2833
|
var REGION = "text";
|
|
2920
2834
|
function TextRegion({ block, label }) {
|
|
2921
|
-
return /* @__PURE__ */
|
|
2835
|
+
return /* @__PURE__ */ jsxRuntime.jsx(EditableRegion, { block: block.id, region: REGION, label });
|
|
2922
2836
|
}
|
|
2923
2837
|
function NumberedItem({ block, controller }) {
|
|
2924
2838
|
const number = useOrderedNumber(controller, block.id);
|
|
2925
|
-
return /* @__PURE__ */
|
|
2926
|
-
/* @__PURE__ */
|
|
2927
|
-
/* @__PURE__ */
|
|
2839
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "quoin-list-item", "data-list": "ordered", children: [
|
|
2840
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "quoin-marker", "aria-hidden": "true", children: `${number}.` }),
|
|
2841
|
+
/* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: `Numbered list item ${number}` })
|
|
2928
2842
|
] });
|
|
2929
2843
|
}
|
|
2930
2844
|
var MarkdownBlock = (props) => {
|
|
2931
2845
|
const { block } = props;
|
|
2932
2846
|
switch (block.attrs.kind) {
|
|
2933
2847
|
case "heading": {
|
|
2934
|
-
const level =
|
|
2935
|
-
return /* @__PURE__ */
|
|
2848
|
+
const level = chunkAIS37SL2_cjs.headingLevel(block.attrs.level);
|
|
2849
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { role: "heading", "aria-level": level, className: "quoin-heading", children: /* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: `Heading ${level}` }) });
|
|
2936
2850
|
}
|
|
2937
2851
|
case "bullet":
|
|
2938
|
-
return /* @__PURE__ */
|
|
2939
|
-
/* @__PURE__ */
|
|
2940
|
-
/* @__PURE__ */
|
|
2852
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "quoin-list-item", "data-list": "bullet", children: [
|
|
2853
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "quoin-marker", "aria-hidden": "true", children: "\u2022" }),
|
|
2854
|
+
/* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: "Bullet list item" })
|
|
2941
2855
|
] });
|
|
2942
2856
|
case "ordered":
|
|
2943
|
-
return /* @__PURE__ */
|
|
2857
|
+
return /* @__PURE__ */ jsxRuntime.jsx(NumberedItem, { ...props });
|
|
2944
2858
|
case "task":
|
|
2945
|
-
return /* @__PURE__ */
|
|
2946
|
-
/* @__PURE__ */
|
|
2947
|
-
/* @__PURE__ */
|
|
2859
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "quoin-task", "data-checked": block.attrs.checked === true, children: [
|
|
2860
|
+
/* @__PURE__ */ jsxRuntime.jsx(TaskCheckbox, { block, controller: props.controller }),
|
|
2861
|
+
/* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: "Task" })
|
|
2948
2862
|
] });
|
|
2949
2863
|
case "quote":
|
|
2950
|
-
return /* @__PURE__ */
|
|
2864
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-quote", children: /* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: "Quote" }) });
|
|
2951
2865
|
default:
|
|
2952
|
-
return /* @__PURE__ */
|
|
2866
|
+
return /* @__PURE__ */ jsxRuntime.jsx(TextRegion, { block, label: "Paragraph" });
|
|
2953
2867
|
}
|
|
2954
2868
|
};
|
|
2955
|
-
|
|
2956
|
-
// src/view/react/use-reader-choices.ts
|
|
2957
|
-
|
|
2958
2869
|
function useReaderChoices(controller) {
|
|
2959
2870
|
const store = readerToggles(controller);
|
|
2960
|
-
return
|
|
2871
|
+
return react.useSyncExternalStore(store.subscribe, () => store.choices, () => store.choices);
|
|
2961
2872
|
}
|
|
2962
2873
|
function useToggleOpen(controller, block) {
|
|
2963
2874
|
return shownOpen(block, useReaderChoices(controller));
|
|
2964
2875
|
}
|
|
2965
|
-
|
|
2966
|
-
// src/view/react/ToggleChevron.tsx
|
|
2967
|
-
|
|
2968
2876
|
function ToggleChevron({ block, controller, label = "Toggle", controls }) {
|
|
2969
2877
|
const open = useToggleOpen(controller, block);
|
|
2970
2878
|
const readOnly = useReadOnly(controller);
|
|
2971
2879
|
const flip2 = flipCommand(block);
|
|
2972
|
-
return /* @__PURE__ */
|
|
2880
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2973
2881
|
"button",
|
|
2974
2882
|
{
|
|
2975
2883
|
type: "button",
|
|
@@ -2984,48 +2892,57 @@ function ToggleChevron({ block, controller, label = "Toggle", controls }) {
|
|
|
2984
2892
|
if (controller.readOnly) readerToggles(controller).flip(block);
|
|
2985
2893
|
else if (flip2) controller.run(onBlock(block.id, flip2));
|
|
2986
2894
|
},
|
|
2987
|
-
children: /* @__PURE__ */
|
|
2895
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 3.5l4.5 4.5L6 12.5", fill: "none", stroke: "currentColor", strokeWidth: "2" }) })
|
|
2988
2896
|
}
|
|
2989
2897
|
);
|
|
2990
2898
|
}
|
|
2991
|
-
|
|
2992
|
-
// src/view/react/toggle-block.tsx
|
|
2993
|
-
|
|
2994
2899
|
var ToggleBlock = ({ block, controller }) => {
|
|
2995
2900
|
const open = useToggleOpen(controller, block);
|
|
2996
|
-
return /* @__PURE__ */
|
|
2997
|
-
/* @__PURE__ */
|
|
2998
|
-
/* @__PURE__ */
|
|
2901
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "quoin-toggle", "data-open": open, children: [
|
|
2902
|
+
/* @__PURE__ */ jsxRuntime.jsx(ToggleChevron, { block, controller }),
|
|
2903
|
+
/* @__PURE__ */ jsxRuntime.jsx(EditableRegion, { block: block.id, region: "text", label: "Toggle" })
|
|
2999
2904
|
] });
|
|
3000
2905
|
};
|
|
3001
|
-
|
|
3002
|
-
// src/view/react/unsupported-block-label.ts
|
|
3003
|
-
|
|
3004
2906
|
var UNSUPPORTED_BLOCK = "Unsupported block";
|
|
3005
|
-
var UnsupportedBlockLabel =
|
|
3006
|
-
|
|
3007
|
-
// src/view/react/default-renderers.tsx
|
|
3008
|
-
|
|
2907
|
+
var UnsupportedBlockLabel = react.createContext(UNSUPPORTED_BLOCK);
|
|
3009
2908
|
var defaultRenderers = {
|
|
3010
2909
|
MARKDOWN: MarkdownBlock,
|
|
3011
2910
|
CALLOUT: CalloutBlock,
|
|
3012
2911
|
TOGGLE: ToggleBlock
|
|
3013
2912
|
};
|
|
3014
2913
|
var VoidBlockFallback = ({ block }) => {
|
|
3015
|
-
const label =
|
|
3016
|
-
if (block.type === "DIVIDER") return /* @__PURE__ */
|
|
3017
|
-
return /* @__PURE__ */
|
|
2914
|
+
const label = react.useContext(UnsupportedBlockLabel);
|
|
2915
|
+
if (block.type === "DIVIDER") return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-void", contentEditable: false, role: "separator" });
|
|
2916
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-void", contentEditable: false, role: "group", "aria-label": label, children: label });
|
|
3018
2917
|
};
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
2918
|
+
var BLOCK_ERROR = "Block could not be drawn";
|
|
2919
|
+
var BlockErrorContext = react.createContext({ label: BLOCK_ERROR });
|
|
2920
|
+
var Boundary = class extends react.Component {
|
|
2921
|
+
state = { block: this.props.block, renderer: this.props.renderer, failed: false };
|
|
2922
|
+
static getDerivedStateFromError() {
|
|
2923
|
+
return { failed: true };
|
|
2924
|
+
}
|
|
2925
|
+
static getDerivedStateFromProps(props, state) {
|
|
2926
|
+
const same = props.block === state.block && props.renderer === state.renderer;
|
|
2927
|
+
return same ? null : { block: props.block, renderer: props.renderer, failed: false };
|
|
2928
|
+
}
|
|
2929
|
+
componentDidCatch(error) {
|
|
2930
|
+
this.props.report?.(error instanceof Error ? error : new Error(String(error)));
|
|
2931
|
+
}
|
|
2932
|
+
render() {
|
|
2933
|
+
if (!this.state.failed) return this.props.children;
|
|
2934
|
+
const { label } = this.props;
|
|
2935
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-void", contentEditable: false, role: "group", "aria-label": label, children: label });
|
|
2936
|
+
}
|
|
2937
|
+
};
|
|
2938
|
+
function BlockErrorBoundary({ block, renderer, children }) {
|
|
2939
|
+
const { label, report } = react.useContext(BlockErrorContext);
|
|
2940
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Boundary, { block, renderer, label, report, children });
|
|
2941
|
+
}
|
|
2942
|
+
var BlockDomIdScope = react.createContext("quoin");
|
|
3026
2943
|
function useBlockDomId() {
|
|
3027
|
-
const scope =
|
|
3028
|
-
return
|
|
2944
|
+
const scope = react.useContext(BlockDomIdScope);
|
|
2945
|
+
return react.useCallback((block) => `${scope}-${encodeURIComponent(block)}`, [scope]);
|
|
3029
2946
|
}
|
|
3030
2947
|
function useRegionDomId(block, region) {
|
|
3031
2948
|
return `${useBlockDomId()(block)}/${encodeURIComponent(region)}`;
|
|
@@ -3042,7 +2959,7 @@ function covers(state, id, index) {
|
|
|
3042
2959
|
if (selection === null) return false;
|
|
3043
2960
|
if (selection.kind === "node") return selection.block === id;
|
|
3044
2961
|
if (selection.kind === "blocks") return within(state, index, [selection.anchor, selection.head]);
|
|
3045
|
-
if (!isCrossSelection(selection) ||
|
|
2962
|
+
if (!isCrossSelection(selection) || chunkVFSVN5IQ_cjs.isTextFlow(schema, doc.blocks[index])) return false;
|
|
3046
2963
|
return within(state, index, [selection.anchor.block, selection.head.block]);
|
|
3047
2964
|
}
|
|
3048
2965
|
function blockStatus(state, id, choices = NO_CHOICES) {
|
|
@@ -3051,16 +2968,18 @@ function blockStatus(state, id, choices = NO_CHOICES) {
|
|
|
3051
2968
|
if (isHiddenAt(state.doc, index, choices)) return "hidden";
|
|
3052
2969
|
return covers(state, id, index) ? "selected" : "plain";
|
|
3053
2970
|
}
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
2971
|
+
function safeAttrs(decorations) {
|
|
2972
|
+
const attrs = Object.assign({}, ...decorations.map((decoration) => decoration.attrs));
|
|
2973
|
+
for (const name of Object.keys(attrs)) if (!/^(data|aria)-/.test(name)) delete attrs[name];
|
|
2974
|
+
return attrs;
|
|
2975
|
+
}
|
|
3057
2976
|
function rendererFor(renderers, type) {
|
|
3058
2977
|
for (const table of [renderers, defaultRenderers]) if (Object.hasOwn(table, type)) return table[type];
|
|
3059
2978
|
return VoidBlockFallback;
|
|
3060
2979
|
}
|
|
3061
|
-
var BlockShell =
|
|
2980
|
+
var BlockShell = react.memo(function BlockShell2({ block, renderers }) {
|
|
3062
2981
|
const controller = useViewController();
|
|
3063
|
-
const ref =
|
|
2982
|
+
const ref = react.useRef(null);
|
|
3064
2983
|
const domId = useBlockDomId();
|
|
3065
2984
|
const choices = useReaderChoices(controller);
|
|
3066
2985
|
const status = useEditorState(controller, (state) => blockStatus(state, block.id, choices));
|
|
@@ -3073,37 +2992,30 @@ var BlockShell = _react.memo.call(void 0, function BlockShell2({ block, renderer
|
|
|
3073
2992
|
if (hidden) return null;
|
|
3074
2993
|
const Renderer = rendererFor(renderers, block.type);
|
|
3075
2994
|
const { kind, color, background, align } = block.attrs;
|
|
3076
|
-
return /* @__PURE__ */
|
|
2995
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3077
2996
|
"div",
|
|
3078
2997
|
{
|
|
3079
|
-
...
|
|
2998
|
+
...safeAttrs(decorations),
|
|
3080
2999
|
ref,
|
|
3081
3000
|
id: domId(block.id),
|
|
3082
3001
|
"data-quoin-block": "",
|
|
3083
3002
|
"data-block-id": block.id,
|
|
3084
3003
|
"data-type": block.type,
|
|
3085
|
-
"data-kind":
|
|
3004
|
+
"data-kind": chunkAIS37SL2_cjs.optionalString(kind),
|
|
3086
3005
|
"data-indent": block.indent,
|
|
3087
|
-
"data-color":
|
|
3088
|
-
"data-bg":
|
|
3089
|
-
"data-align":
|
|
3006
|
+
"data-color": chunkAIS37SL2_cjs.paletteOrUndefined(color),
|
|
3007
|
+
"data-bg": chunkAIS37SL2_cjs.paletteOrUndefined(background),
|
|
3008
|
+
"data-align": chunkAIS37SL2_cjs.alignOrUndefined(align),
|
|
3090
3009
|
style: { "--quoin-indent": block.indent },
|
|
3091
3010
|
tabIndex: -1,
|
|
3092
3011
|
"data-selected": status === "selected" ? "true" : void 0,
|
|
3093
|
-
children: /* @__PURE__ */
|
|
3012
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(BlockErrorBoundary, { block, renderer: Renderer, children: /* @__PURE__ */ jsxRuntime.jsx(Renderer, { block, controller }) })
|
|
3094
3013
|
}
|
|
3095
3014
|
);
|
|
3096
3015
|
});
|
|
3097
|
-
|
|
3098
|
-
// src/view/react/EditorView.tsx
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
// src/view/react/EmptyDocumentHost.tsx
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
3016
|
function EmptyDocumentHost({ placeholder, label = "Paragraph" }) {
|
|
3105
3017
|
const controller = useViewController();
|
|
3106
|
-
const ref =
|
|
3018
|
+
const ref = react.useRef(null);
|
|
3107
3019
|
const readOnly = useReadOnly(controller);
|
|
3108
3020
|
useIsomorphicLayoutEffect(() => {
|
|
3109
3021
|
const host = ref.current;
|
|
@@ -3111,7 +3023,7 @@ function EmptyDocumentHost({ placeholder, label = "Paragraph" }) {
|
|
|
3111
3023
|
renderInline(host, [], []);
|
|
3112
3024
|
return controller.registerEmptyHost(host);
|
|
3113
3025
|
}, [controller]);
|
|
3114
|
-
return /* @__PURE__ */
|
|
3026
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3115
3027
|
"div",
|
|
3116
3028
|
{
|
|
3117
3029
|
ref,
|
|
@@ -3126,7 +3038,7 @@ function EmptyDocumentHost({ placeholder, label = "Paragraph" }) {
|
|
|
3126
3038
|
"data-placeholder": readOnly ? void 0 : placeholder,
|
|
3127
3039
|
"aria-placeholder": readOnly ? void 0 : placeholder,
|
|
3128
3040
|
spellCheck: true,
|
|
3129
|
-
onClick: () =>
|
|
3041
|
+
onClick: () => ref.current?.focus()
|
|
3130
3042
|
}
|
|
3131
3043
|
);
|
|
3132
3044
|
}
|
|
@@ -3134,9 +3046,6 @@ function EmptyDocumentHost({ placeholder, label = "Paragraph" }) {
|
|
|
3134
3046
|
// src/view/react/focus-owners.ts
|
|
3135
3047
|
var focusOwners = /* @__PURE__ */ new WeakMap();
|
|
3136
3048
|
|
|
3137
|
-
// src/view/react/LiveRegion.tsx
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
3049
|
// src/view/selection/selection-announcement.ts
|
|
3141
3050
|
var SILENCE = { key: "", message: "" };
|
|
3142
3051
|
function selectionAnnouncement({ doc, selection }, blocksSelected) {
|
|
@@ -3150,9 +3059,6 @@ function selectionAnnouncement({ doc, selection }, blocksSelected) {
|
|
|
3150
3059
|
const count = drawnBlockCount(doc, Math.min(first, last), Math.max(first, last) + 1);
|
|
3151
3060
|
return { key: `${selection.kind}:${anchor}:${head}`, message: blocksSelected(count) };
|
|
3152
3061
|
}
|
|
3153
|
-
|
|
3154
|
-
// src/view/react/LiveRegion.tsx
|
|
3155
|
-
|
|
3156
3062
|
function heardNow({ editor, announcer }, blocksSelected) {
|
|
3157
3063
|
const spoken = announcer.current();
|
|
3158
3064
|
if (spoken !== null) return { key: `said:${spoken.serial}`, message: spoken.message };
|
|
@@ -3160,7 +3066,7 @@ function heardNow({ editor, announcer }, blocksSelected) {
|
|
|
3160
3066
|
}
|
|
3161
3067
|
function LiveRegion({ blocksSelected }) {
|
|
3162
3068
|
const controller = useViewController();
|
|
3163
|
-
const subscribe =
|
|
3069
|
+
const subscribe = react.useCallback(
|
|
3164
3070
|
(notify) => {
|
|
3165
3071
|
const stopState = controller.editor.subscribe(() => notify());
|
|
3166
3072
|
const stopSpoken = controller.announcer.subscribe(notify);
|
|
@@ -3171,7 +3077,7 @@ function LiveRegion({ blocksSelected }) {
|
|
|
3171
3077
|
},
|
|
3172
3078
|
[controller]
|
|
3173
3079
|
);
|
|
3174
|
-
const read =
|
|
3080
|
+
const read = react.useMemo(() => {
|
|
3175
3081
|
let last = SILENCE;
|
|
3176
3082
|
return () => {
|
|
3177
3083
|
const next = heardNow(controller, blocksSelected);
|
|
@@ -3179,8 +3085,8 @@ function LiveRegion({ blocksSelected }) {
|
|
|
3179
3085
|
return last;
|
|
3180
3086
|
};
|
|
3181
3087
|
}, [controller, blocksSelected]);
|
|
3182
|
-
const { key, message } =
|
|
3183
|
-
return /* @__PURE__ */
|
|
3088
|
+
const { key, message } = react.useSyncExternalStore(subscribe, read, read);
|
|
3089
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "quoin-visually-hidden", role: "status", "aria-live": "polite", "aria-atomic": "true", children: message !== "" && /* @__PURE__ */ jsxRuntime.jsx("span", { children: message }, key) });
|
|
3184
3090
|
}
|
|
3185
3091
|
|
|
3186
3092
|
// src/view/react/SelectionWriter.tsx
|
|
@@ -3190,23 +3096,16 @@ function SelectionWriter() {
|
|
|
3190
3096
|
useIsomorphicLayoutEffect(() => controller.afterRender(), [controller, state]);
|
|
3191
3097
|
return null;
|
|
3192
3098
|
}
|
|
3193
|
-
|
|
3194
|
-
// src/view/react/use-block-elements.tsx
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
3099
|
function useBlockElements(blocks, renderers) {
|
|
3198
|
-
const [made] =
|
|
3100
|
+
const [made] = react.useState(() => /* @__PURE__ */ new WeakMap());
|
|
3199
3101
|
return blocks.map((block) => {
|
|
3200
3102
|
const known2 = made.get(block);
|
|
3201
|
-
if (
|
|
3202
|
-
const element = /* @__PURE__ */
|
|
3103
|
+
if (known2?.renderers === renderers) return known2.element;
|
|
3104
|
+
const element = /* @__PURE__ */ jsxRuntime.jsx(BlockShell, { block, renderers }, block.id);
|
|
3203
3105
|
made.set(block, { renderers, element });
|
|
3204
3106
|
return element;
|
|
3205
3107
|
});
|
|
3206
3108
|
}
|
|
3207
|
-
|
|
3208
|
-
// src/view/react/EditorView.tsx
|
|
3209
|
-
|
|
3210
3109
|
var NO_RENDERERS = {};
|
|
3211
3110
|
var HINT = "Press Escape, then Tab, to leave the editor.";
|
|
3212
3111
|
var BLOCKS_SELECTED = (count) => `${count} ${count === 1 ? "block" : "blocks"} selected`;
|
|
@@ -3221,18 +3120,21 @@ function EditorView({
|
|
|
3221
3120
|
selectedContentLabel,
|
|
3222
3121
|
blockLabel,
|
|
3223
3122
|
unsupportedBlockLabel = UNSUPPORTED_BLOCK,
|
|
3123
|
+
blockErrorLabel = BLOCK_ERROR,
|
|
3124
|
+
onBlockError,
|
|
3224
3125
|
placeholder,
|
|
3225
3126
|
blockPlaceholder = headingPlaceholder,
|
|
3226
3127
|
blocksSelectedLabel = BLOCKS_SELECTED,
|
|
3227
3128
|
children
|
|
3228
3129
|
}) {
|
|
3229
|
-
const root =
|
|
3230
|
-
const hintId =
|
|
3231
|
-
const blockIdScope =
|
|
3130
|
+
const root = react.useRef(null);
|
|
3131
|
+
const hintId = react.useId();
|
|
3132
|
+
const blockIdScope = react.useId();
|
|
3232
3133
|
const blocks = useEditorState(controller, (state) => state.doc.blocks);
|
|
3134
|
+
const blockError = react.useMemo(() => ({ label: blockErrorLabel, report: onBlockError }), [blockErrorLabel, onBlockError]);
|
|
3233
3135
|
const shells = useBlockElements(blocks, renderers);
|
|
3234
3136
|
useIsomorphicLayoutEffect(() => root.current ? controller.attach(root.current) : void 0, [controller]);
|
|
3235
|
-
return /* @__PURE__ */
|
|
3137
|
+
return /* @__PURE__ */ jsxRuntime.jsx(QuoinEditorContext.Provider, { value: controller, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3236
3138
|
"div",
|
|
3237
3139
|
{
|
|
3238
3140
|
ref: root,
|
|
@@ -3243,62 +3145,62 @@ function EditorView({
|
|
|
3243
3145
|
"aria-describedby": hintId,
|
|
3244
3146
|
onFocusCapture: (event) => focusOwners.set(event.target, controller),
|
|
3245
3147
|
children: [
|
|
3246
|
-
/* @__PURE__ */
|
|
3148
|
+
/* @__PURE__ */ jsxRuntime.jsx(BlockDomIdScope.Provider, { value: blockIdScope, children: /* @__PURE__ */ jsxRuntime.jsx(UnsupportedBlockLabel.Provider, { value: unsupportedBlockLabel, children: /* @__PURE__ */ jsxRuntime.jsx(BlockErrorContext.Provider, { value: blockError, children: /* @__PURE__ */ jsxRuntime.jsx(BlockPlaceholderContext.Provider, { value: blockPlaceholder, children: blocks.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(EmptyDocumentHost, { placeholder, label: paragraphLabel }) : shells }) }) }) }),
|
|
3247
3149
|
children,
|
|
3248
|
-
/* @__PURE__ */
|
|
3249
|
-
/* @__PURE__ */
|
|
3250
|
-
/* @__PURE__ */
|
|
3251
|
-
/* @__PURE__ */
|
|
3150
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectionSink, { label: selectedContentLabel, blockLabel }),
|
|
3151
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { id: hintId, className: "quoin-visually-hidden", children: hint }),
|
|
3152
|
+
/* @__PURE__ */ jsxRuntime.jsx(LiveRegion, { blocksSelected: blocksSelectedLabel }),
|
|
3153
|
+
/* @__PURE__ */ jsxRuntime.jsx(SelectionWriter, {})
|
|
3252
3154
|
]
|
|
3253
3155
|
}
|
|
3254
3156
|
) });
|
|
3255
3157
|
}
|
|
3256
3158
|
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
//# sourceMappingURL=chunk-
|
|
3159
|
+
exports.BlockErrorContext = BlockErrorContext;
|
|
3160
|
+
exports.BlockShell = BlockShell;
|
|
3161
|
+
exports.EditableRegion = EditableRegion;
|
|
3162
|
+
exports.EditorView = EditorView;
|
|
3163
|
+
exports.NATIVE_INTERACTION = NATIVE_INTERACTION;
|
|
3164
|
+
exports.NODE_ENTRY = NODE_ENTRY;
|
|
3165
|
+
exports.SelectionSink = SelectionSink;
|
|
3166
|
+
exports.TaskCheckbox = TaskCheckbox;
|
|
3167
|
+
exports.ToggleChevron = ToggleChevron;
|
|
3168
|
+
exports.ViewController = ViewController;
|
|
3169
|
+
exports.VoidBlockFallback = VoidBlockFallback;
|
|
3170
|
+
exports.caretClientRect = caretClientRect;
|
|
3171
|
+
exports.caretFromPoint = caretFromPoint;
|
|
3172
|
+
exports.createAutoScroll = createAutoScroll;
|
|
3173
|
+
exports.defaultRenderers = defaultRenderers;
|
|
3174
|
+
exports.dispatchSelection = dispatchSelection;
|
|
3175
|
+
exports.domMapOf = domMapOf;
|
|
3176
|
+
exports.domToPos = domToPos;
|
|
3177
|
+
exports.drawnBlockCount = drawnBlockCount;
|
|
3178
|
+
exports.focusOwners = focusOwners;
|
|
3179
|
+
exports.handleCopy = handleCopy;
|
|
3180
|
+
exports.hostKey = hostKey;
|
|
3181
|
+
exports.isComposingKey = isComposingKey;
|
|
3182
|
+
exports.isCrossSelection = isCrossSelection;
|
|
3183
|
+
exports.isOnFirstLine = isOnFirstLine;
|
|
3184
|
+
exports.isOnLastLine = isOnLastLine;
|
|
3185
|
+
exports.lineEdgeRect = lineEdgeRect;
|
|
3186
|
+
exports.listen = listen;
|
|
3187
|
+
exports.moveToNeighbour = moveToNeighbour;
|
|
3188
|
+
exports.neighbourBlock = neighbourBlock;
|
|
3189
|
+
exports.onBlock = onBlock;
|
|
3190
|
+
exports.posToDom = posToDom;
|
|
3191
|
+
exports.regionInline = regionInline;
|
|
3192
|
+
exports.renderInline = renderInline;
|
|
3193
|
+
exports.textDiff = textDiff;
|
|
3194
|
+
exports.useBlockDomId = useBlockDomId;
|
|
3195
|
+
exports.useEditorState = useEditorState;
|
|
3196
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
3197
|
+
exports.useOrderedNumber = useOrderedNumber;
|
|
3198
|
+
exports.useQuoinEditor = useQuoinEditor;
|
|
3199
|
+
exports.useReadOnly = useReadOnly;
|
|
3200
|
+
exports.useRegionDomId = useRegionDomId;
|
|
3201
|
+
exports.useToggleOpen = useToggleOpen;
|
|
3202
|
+
exports.useViewController = useViewController;
|
|
3203
|
+
exports.visibleBlockIndexes = visibleBlockIndexes;
|
|
3204
|
+
exports.wholeState = wholeState;
|
|
3205
|
+
//# sourceMappingURL=chunk-IGZRZIAF.cjs.map
|
|
3206
|
+
//# sourceMappingURL=chunk-IGZRZIAF.cjs.map
|