@portabletext/editor 1.15.0 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +494 -0
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.get-text-before.cjs +12 -232
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selectors.cjs +234 -0
- package/lib/_chunks-cjs/selectors.cjs.map +1 -0
- package/lib/_chunks-es/behavior.core.js +496 -0
- package/lib/_chunks-es/behavior.core.js.map +1 -0
- package/lib/_chunks-es/selector.get-text-before.js +14 -234
- package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
- package/lib/_chunks-es/selectors.js +235 -0
- package/lib/_chunks-es/selectors.js.map +1 -0
- package/lib/behaviors/index.cjs +460 -0
- package/lib/behaviors/index.cjs.map +1 -0
- package/lib/behaviors/index.d.cts +875 -0
- package/lib/behaviors/index.d.ts +875 -0
- package/lib/behaviors/index.js +464 -0
- package/lib/behaviors/index.js.map +1 -0
- package/lib/index.cjs +843 -1489
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +17 -536
- package/lib/index.d.ts +17 -536
- package/lib/index.js +837 -1482
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +16 -16
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +3 -2
- package/lib/selectors/index.js.map +1 -1
- package/package.json +13 -7
- package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +2 -2
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-block-object.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-break.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.insert-inline-object.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.list-item.ts +2 -2
- package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.set.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.unset.ts +1 -1
- package/src/{editor/behavior → behavior-actions}/behavior.actions.ts +14 -14
- package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +1 -1
- package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
- package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +5 -5
- package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
- package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +15 -15
- package/src/{editor/behavior → behaviors}/behavior.links.ts +4 -4
- package/src/{editor/behavior → behaviors}/behavior.markdown.ts +15 -25
- package/src/{editor/behavior → behaviors}/behavior.types.ts +32 -39
- package/src/behaviors/index.ts +28 -0
- package/src/editor/create-editor.ts +26 -46
- package/src/editor/editor-machine.ts +14 -12
- package/src/editor/plugins/createWithEditableAPI.ts +3 -3
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
- package/src/editor/utils/utils.block-offset.ts +1 -1
- package/src/index.ts +11 -26
- package/src/selectors/selector.get-active-list-item.ts +1 -1
- package/src/selectors/selectors.ts +1 -1
- package/src/type-utils.ts +17 -0
- package/src/utils/__tests__/operationToPatches.test.ts +1 -1
- package/src/utils/__tests__/patchToOperations.test.ts +1 -1
- /package/src/{editor/behavior → behavior-actions}/behavior.action.insert-span.ts +0 -0
- /package/src/{editor/behavior → behavior-actions}/behavior.action.style.ts +0 -0
- /package/src/{editor/behavior → behaviors}/behavior.core.ts +0 -0
package/lib/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
5
|
+
for (var prop in b || (b = {}))
|
|
6
|
+
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
7
|
+
if (__getOwnPropSymbols)
|
|
8
|
+
for (var prop of __getOwnPropSymbols(b))
|
|
9
|
+
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
10
|
+
return a;
|
|
11
|
+
};
|
|
3
12
|
import { Schema } from "@sanity/schema";
|
|
13
|
+
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
4
14
|
import startCase from "lodash.startcase";
|
|
5
15
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
6
16
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
@@ -24,943 +34,18 @@ import { setup, assign, assertEvent, emit, enqueueActions, createActor } from "x
|
|
|
24
34
|
import get from "lodash/get.js";
|
|
25
35
|
import isUndefined from "lodash/isUndefined.js";
|
|
26
36
|
import omitBy from "lodash/omitBy.js";
|
|
37
|
+
import { createGuards } from "./_chunks-es/selectors.js";
|
|
38
|
+
import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chunks-es/behavior.core.js";
|
|
27
39
|
import getRandomValues from "get-random-values-esm";
|
|
28
40
|
import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
|
|
29
|
-
const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
30
|
-
alt: "altKey",
|
|
31
|
-
control: "ctrlKey",
|
|
32
|
-
meta: "metaKey",
|
|
33
|
-
shift: "shiftKey"
|
|
34
|
-
}, aliases = {
|
|
35
|
-
add: "+",
|
|
36
|
-
break: "pause",
|
|
37
|
-
cmd: "meta",
|
|
38
|
-
command: "meta",
|
|
39
|
-
ctl: "control",
|
|
40
|
-
ctrl: "control",
|
|
41
|
-
del: "delete",
|
|
42
|
-
down: "arrowdown",
|
|
43
|
-
esc: "escape",
|
|
44
|
-
ins: "insert",
|
|
45
|
-
left: "arrowleft",
|
|
46
|
-
mod: IS_MAC ? "meta" : "control",
|
|
47
|
-
opt: "alt",
|
|
48
|
-
option: "alt",
|
|
49
|
-
return: "enter",
|
|
50
|
-
right: "arrowright",
|
|
51
|
-
space: " ",
|
|
52
|
-
spacebar: " ",
|
|
53
|
-
up: "arrowup",
|
|
54
|
-
win: "meta",
|
|
55
|
-
windows: "meta"
|
|
56
|
-
}, keyCodes = {
|
|
57
|
-
backspace: 8,
|
|
58
|
-
tab: 9,
|
|
59
|
-
enter: 13,
|
|
60
|
-
shift: 16,
|
|
61
|
-
control: 17,
|
|
62
|
-
alt: 18,
|
|
63
|
-
pause: 19,
|
|
64
|
-
capslock: 20,
|
|
65
|
-
escape: 27,
|
|
66
|
-
" ": 32,
|
|
67
|
-
pageup: 33,
|
|
68
|
-
pagedown: 34,
|
|
69
|
-
end: 35,
|
|
70
|
-
home: 36,
|
|
71
|
-
arrowleft: 37,
|
|
72
|
-
arrowup: 38,
|
|
73
|
-
arrowright: 39,
|
|
74
|
-
arrowdown: 40,
|
|
75
|
-
insert: 45,
|
|
76
|
-
delete: 46,
|
|
77
|
-
meta: 91,
|
|
78
|
-
numlock: 144,
|
|
79
|
-
scrolllock: 145,
|
|
80
|
-
";": 186,
|
|
81
|
-
"=": 187,
|
|
82
|
-
",": 188,
|
|
83
|
-
"-": 189,
|
|
84
|
-
".": 190,
|
|
85
|
-
"/": 191,
|
|
86
|
-
"`": 192,
|
|
87
|
-
"[": 219,
|
|
88
|
-
"\\": 220,
|
|
89
|
-
"]": 221,
|
|
90
|
-
"'": 222,
|
|
91
|
-
f1: 112,
|
|
92
|
-
f2: 113,
|
|
93
|
-
f3: 114,
|
|
94
|
-
f4: 115,
|
|
95
|
-
f5: 116,
|
|
96
|
-
f6: 117,
|
|
97
|
-
f7: 118,
|
|
98
|
-
f8: 119,
|
|
99
|
-
f9: 120,
|
|
100
|
-
f10: 121,
|
|
101
|
-
f11: 122,
|
|
102
|
-
f12: 123,
|
|
103
|
-
f13: 124,
|
|
104
|
-
f14: 125,
|
|
105
|
-
f15: 126,
|
|
106
|
-
f16: 127,
|
|
107
|
-
f17: 128,
|
|
108
|
-
f18: 129,
|
|
109
|
-
f19: 130,
|
|
110
|
-
f20: 131
|
|
111
|
-
};
|
|
112
|
-
function isHotkey(hotkey, event) {
|
|
113
|
-
return compareHotkey(parseHotkey(hotkey), event);
|
|
114
|
-
}
|
|
115
|
-
function parseHotkey(hotkey) {
|
|
116
|
-
const parsedHotkey = {
|
|
117
|
-
altKey: !1,
|
|
118
|
-
ctrlKey: !1,
|
|
119
|
-
metaKey: !1,
|
|
120
|
-
shiftKey: !1
|
|
121
|
-
}, hotkeySegments = hotkey.replace("++", "+add").split("+");
|
|
122
|
-
for (const rawHotkeySegment of hotkeySegments) {
|
|
123
|
-
const optional = rawHotkeySegment.endsWith("?") && rawHotkeySegment.length > 1, hotkeySegment = optional ? rawHotkeySegment.slice(0, -1) : rawHotkeySegment, keyName = toKeyName(hotkeySegment), modifier = modifiers[keyName], alias = aliases[hotkeySegment], code = keyCodes[keyName];
|
|
124
|
-
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
|
|
125
|
-
throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
|
|
126
|
-
(hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
|
|
127
|
-
}
|
|
128
|
-
return parsedHotkey;
|
|
129
|
-
}
|
|
130
|
-
function compareHotkey(parsedHotkey, event) {
|
|
131
|
-
return (parsedHotkey.altKey == null || parsedHotkey.altKey === event.altKey) && (parsedHotkey.ctrlKey == null || parsedHotkey.ctrlKey === event.ctrlKey) && (parsedHotkey.metaKey == null || parsedHotkey.metaKey === event.metaKey) && (parsedHotkey.shiftKey == null || parsedHotkey.shiftKey === event.shiftKey) ? parsedHotkey.keyCode !== void 0 && event.keyCode !== void 0 ? parsedHotkey.keyCode === 91 && event.keyCode === 93 ? !0 : parsedHotkey.keyCode === event.keyCode : parsedHotkey.keyCode === event.keyCode || parsedHotkey.key === event.key.toLowerCase() : !1;
|
|
132
|
-
}
|
|
133
|
-
function toKeyCode(name) {
|
|
134
|
-
const keyName = toKeyName(name);
|
|
135
|
-
return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
|
|
136
|
-
}
|
|
137
|
-
function toKeyName(name) {
|
|
138
|
-
const keyName = name.toLowerCase();
|
|
139
|
-
return aliases[keyName] ?? keyName;
|
|
140
|
-
}
|
|
141
|
-
function defineBehavior(behavior) {
|
|
142
|
-
return behavior;
|
|
143
|
-
}
|
|
144
|
-
function createCodeEditorBehaviors(config) {
|
|
145
|
-
return [{
|
|
146
|
-
on: "key.down",
|
|
147
|
-
guard: ({
|
|
148
|
-
context,
|
|
149
|
-
event
|
|
150
|
-
}) => {
|
|
151
|
-
const isMoveUpShortcut = isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = getFirstBlock({
|
|
152
|
-
context
|
|
153
|
-
}), selectedBlocks = getSelectedBlocks({
|
|
154
|
-
context
|
|
155
|
-
}), blocksAbove = firstBlock?.node._key !== selectedBlocks[0]?.node._key;
|
|
156
|
-
return !isMoveUpShortcut || !blocksAbove ? !1 : {
|
|
157
|
-
paths: selectedBlocks.map((block) => block.path)
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
actions: [({
|
|
161
|
-
paths
|
|
162
|
-
}) => paths.map((at) => ({
|
|
163
|
-
type: "move.block up",
|
|
164
|
-
at
|
|
165
|
-
}))]
|
|
166
|
-
}, {
|
|
167
|
-
on: "key.down",
|
|
168
|
-
guard: ({
|
|
169
|
-
context,
|
|
170
|
-
event
|
|
171
|
-
}) => {
|
|
172
|
-
const isMoveDownShortcut = isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = getLastBlock({
|
|
173
|
-
context
|
|
174
|
-
}), selectedBlocks = getSelectedBlocks({
|
|
175
|
-
context
|
|
176
|
-
}), blocksBelow = lastBlock?.node._key !== selectedBlocks[selectedBlocks.length - 1]?.node._key;
|
|
177
|
-
return !isMoveDownShortcut || !blocksBelow ? !1 : {
|
|
178
|
-
paths: selectedBlocks.map((block) => block.path).reverse()
|
|
179
|
-
};
|
|
180
|
-
},
|
|
181
|
-
actions: [({
|
|
182
|
-
paths
|
|
183
|
-
}) => paths.map((at) => ({
|
|
184
|
-
type: "move.block down",
|
|
185
|
-
at
|
|
186
|
-
}))]
|
|
187
|
-
}];
|
|
188
|
-
}
|
|
189
|
-
function isEmptyTextBlock(block) {
|
|
190
|
-
if (!isPortableTextTextBlock(block))
|
|
191
|
-
return !1;
|
|
192
|
-
const onlyText = block.children.every(isPortableTextSpan$1), blockText = getTextBlockText(block);
|
|
193
|
-
return onlyText && blockText === "";
|
|
194
|
-
}
|
|
195
|
-
function getTextBlockText(block) {
|
|
196
|
-
return block.children.map((child) => child.text ?? "").join("");
|
|
197
|
-
}
|
|
198
|
-
const arrowDownOnLonelyBlockObject = {
|
|
199
|
-
on: "key.down",
|
|
200
|
-
guard: ({
|
|
201
|
-
context,
|
|
202
|
-
event
|
|
203
|
-
}) => {
|
|
204
|
-
const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject = getFocusBlockObject({
|
|
205
|
-
context
|
|
206
|
-
}), nextBlock = getNextBlock({
|
|
207
|
-
context
|
|
208
|
-
});
|
|
209
|
-
return isArrowDown && focusBlockObject && !nextBlock;
|
|
210
|
-
},
|
|
211
|
-
actions: [() => [{
|
|
212
|
-
type: "insert.text block",
|
|
213
|
-
placement: "after"
|
|
214
|
-
}]]
|
|
215
|
-
}, arrowUpOnLonelyBlockObject = {
|
|
216
|
-
on: "key.down",
|
|
217
|
-
guard: ({
|
|
218
|
-
context,
|
|
219
|
-
event
|
|
220
|
-
}) => {
|
|
221
|
-
const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject = getFocusBlockObject({
|
|
222
|
-
context
|
|
223
|
-
}), previousBlock = getPreviousBlock({
|
|
224
|
-
context
|
|
225
|
-
});
|
|
226
|
-
return isArrowUp && focusBlockObject && !previousBlock;
|
|
227
|
-
},
|
|
228
|
-
actions: [() => [{
|
|
229
|
-
type: "insert.text block",
|
|
230
|
-
placement: "before"
|
|
231
|
-
}, {
|
|
232
|
-
type: "select previous block"
|
|
233
|
-
}]]
|
|
234
|
-
}, breakingBlockObject = {
|
|
235
|
-
on: "insert.break",
|
|
236
|
-
guard: ({
|
|
237
|
-
context
|
|
238
|
-
}) => {
|
|
239
|
-
const focusBlockObject = getFocusBlockObject({
|
|
240
|
-
context
|
|
241
|
-
});
|
|
242
|
-
return selectionIsCollapsed({
|
|
243
|
-
context
|
|
244
|
-
}) && focusBlockObject !== void 0;
|
|
245
|
-
},
|
|
246
|
-
actions: [() => [{
|
|
247
|
-
type: "insert.text block",
|
|
248
|
-
placement: "after"
|
|
249
|
-
}]]
|
|
250
|
-
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
251
|
-
on: "delete.backward",
|
|
252
|
-
guard: ({
|
|
253
|
-
context
|
|
254
|
-
}) => {
|
|
255
|
-
const focusTextBlock = getFocusTextBlock({
|
|
256
|
-
context
|
|
257
|
-
}), selectionCollapsed = selectionIsCollapsed({
|
|
258
|
-
context
|
|
259
|
-
}), previousBlock = getPreviousBlock({
|
|
260
|
-
context
|
|
261
|
-
});
|
|
262
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
|
|
263
|
-
focusTextBlock,
|
|
264
|
-
previousBlock
|
|
265
|
-
} : !1;
|
|
266
|
-
},
|
|
267
|
-
actions: [({
|
|
268
|
-
focusTextBlock,
|
|
269
|
-
previousBlock
|
|
270
|
-
}) => [{
|
|
271
|
-
type: "delete.block",
|
|
272
|
-
blockPath: focusTextBlock.path
|
|
273
|
-
}, {
|
|
274
|
-
type: "select",
|
|
275
|
-
selection: {
|
|
276
|
-
anchor: {
|
|
277
|
-
path: previousBlock.path,
|
|
278
|
-
offset: 0
|
|
279
|
-
},
|
|
280
|
-
focus: {
|
|
281
|
-
path: previousBlock.path,
|
|
282
|
-
offset: 0
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}]]
|
|
286
|
-
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
287
|
-
on: "delete.forward",
|
|
288
|
-
guard: ({
|
|
289
|
-
context
|
|
290
|
-
}) => {
|
|
291
|
-
const focusTextBlock = getFocusTextBlock({
|
|
292
|
-
context
|
|
293
|
-
}), selectionCollapsed = selectionIsCollapsed({
|
|
294
|
-
context
|
|
295
|
-
}), nextBlock = getNextBlock({
|
|
296
|
-
context
|
|
297
|
-
});
|
|
298
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
|
|
299
|
-
focusTextBlock,
|
|
300
|
-
nextBlock
|
|
301
|
-
} : !1;
|
|
302
|
-
},
|
|
303
|
-
actions: [({
|
|
304
|
-
focusTextBlock,
|
|
305
|
-
nextBlock
|
|
306
|
-
}) => [{
|
|
307
|
-
type: "delete.block",
|
|
308
|
-
blockPath: focusTextBlock.path
|
|
309
|
-
}, {
|
|
310
|
-
type: "select",
|
|
311
|
-
selection: {
|
|
312
|
-
anchor: {
|
|
313
|
-
path: nextBlock.path,
|
|
314
|
-
offset: 0
|
|
315
|
-
},
|
|
316
|
-
focus: {
|
|
317
|
-
path: nextBlock.path,
|
|
318
|
-
offset: 0
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}]]
|
|
322
|
-
}, coreBlockObjectBehaviors = {
|
|
323
|
-
arrowDownOnLonelyBlockObject,
|
|
324
|
-
arrowUpOnLonelyBlockObject,
|
|
325
|
-
breakingBlockObject,
|
|
326
|
-
deletingEmptyTextBlockAfterBlockObject,
|
|
327
|
-
deletingEmptyTextBlockBeforeBlockObject
|
|
328
|
-
}, decoratorAdd = {
|
|
329
|
-
on: "decorator.add",
|
|
330
|
-
guard: ({
|
|
331
|
-
event
|
|
332
|
-
}) => ({
|
|
333
|
-
decorator: event.decorator
|
|
334
|
-
}),
|
|
335
|
-
actions: [({
|
|
336
|
-
decorator
|
|
337
|
-
}) => [{
|
|
338
|
-
type: "decorator.add",
|
|
339
|
-
decorator
|
|
340
|
-
}, {
|
|
341
|
-
type: "reselect"
|
|
342
|
-
}]]
|
|
343
|
-
}, decoratorRemove = {
|
|
344
|
-
on: "decorator.remove",
|
|
345
|
-
guard: ({
|
|
346
|
-
event
|
|
347
|
-
}) => ({
|
|
348
|
-
decorator: event.decorator
|
|
349
|
-
}),
|
|
350
|
-
actions: [({
|
|
351
|
-
decorator
|
|
352
|
-
}) => [{
|
|
353
|
-
type: "decorator.remove",
|
|
354
|
-
decorator
|
|
355
|
-
}, {
|
|
356
|
-
type: "reselect"
|
|
357
|
-
}]]
|
|
358
|
-
}, decoratorToggle = {
|
|
359
|
-
on: "decorator.toggle",
|
|
360
|
-
guard: ({
|
|
361
|
-
event
|
|
362
|
-
}) => ({
|
|
363
|
-
decorator: event.decorator
|
|
364
|
-
}),
|
|
365
|
-
actions: [({
|
|
366
|
-
decorator
|
|
367
|
-
}) => [{
|
|
368
|
-
type: "decorator.toggle",
|
|
369
|
-
decorator
|
|
370
|
-
}, {
|
|
371
|
-
type: "reselect"
|
|
372
|
-
}]]
|
|
373
|
-
}, coreDecoratorBehaviors = {
|
|
374
|
-
decoratorAdd,
|
|
375
|
-
decoratorRemove,
|
|
376
|
-
decoratorToggle
|
|
377
|
-
}, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
|
|
378
|
-
on: "delete.backward",
|
|
379
|
-
guard: ({
|
|
380
|
-
context
|
|
381
|
-
}) => {
|
|
382
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
383
|
-
context
|
|
384
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
385
|
-
context
|
|
386
|
-
}), focusSpan = getFocusSpan({
|
|
387
|
-
context
|
|
388
|
-
});
|
|
389
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
390
|
-
focusTextBlock
|
|
391
|
-
} : !1;
|
|
392
|
-
},
|
|
393
|
-
actions: [({
|
|
394
|
-
focusTextBlock
|
|
395
|
-
}) => [{
|
|
396
|
-
type: "text block.unset",
|
|
397
|
-
props: ["listItem", "level"],
|
|
398
|
-
at: focusTextBlock.path
|
|
399
|
-
}]]
|
|
400
|
-
}, unindentListOnBackspace = {
|
|
401
|
-
on: "delete.backward",
|
|
402
|
-
guard: ({
|
|
403
|
-
context
|
|
404
|
-
}) => {
|
|
405
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
406
|
-
context
|
|
407
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
408
|
-
context
|
|
409
|
-
}), focusSpan = getFocusSpan({
|
|
410
|
-
context
|
|
411
|
-
});
|
|
412
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
413
|
-
focusTextBlock,
|
|
414
|
-
level: focusTextBlock.node.level - 1
|
|
415
|
-
} : !1;
|
|
416
|
-
},
|
|
417
|
-
actions: [({
|
|
418
|
-
focusTextBlock,
|
|
419
|
-
level
|
|
420
|
-
}) => [{
|
|
421
|
-
type: "text block.set",
|
|
422
|
-
level,
|
|
423
|
-
at: focusTextBlock.path
|
|
424
|
-
}]]
|
|
425
|
-
}, clearListOnEnter = {
|
|
426
|
-
on: "insert.break",
|
|
427
|
-
guard: ({
|
|
428
|
-
context
|
|
429
|
-
}) => {
|
|
430
|
-
const focusListBlock = getFocusListBlock({
|
|
431
|
-
context
|
|
432
|
-
}), selectionCollapsed = selectionIsCollapsed({
|
|
433
|
-
context
|
|
434
|
-
});
|
|
435
|
-
return !focusListBlock || !selectionCollapsed || !isEmptyTextBlock(focusListBlock.node) ? !1 : {
|
|
436
|
-
focusListBlock
|
|
437
|
-
};
|
|
438
|
-
},
|
|
439
|
-
actions: [({
|
|
440
|
-
focusListBlock
|
|
441
|
-
}) => [{
|
|
442
|
-
type: "text block.unset",
|
|
443
|
-
props: ["listItem", "level"],
|
|
444
|
-
at: focusListBlock.path
|
|
445
|
-
}]]
|
|
446
|
-
}, indentListOnTab = {
|
|
447
|
-
on: "key.down",
|
|
448
|
-
guard: ({
|
|
449
|
-
context,
|
|
450
|
-
event
|
|
451
|
-
}) => {
|
|
452
|
-
if (!isHotkey("Tab", event.keyboardEvent))
|
|
453
|
-
return !1;
|
|
454
|
-
const selectedBlocks = getSelectedBlocks({
|
|
455
|
-
context
|
|
456
|
-
}), guards = createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
457
|
-
node: block.node,
|
|
458
|
-
path: block.path
|
|
459
|
-
}] : []);
|
|
460
|
-
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
461
|
-
selectedListBlocks
|
|
462
|
-
} : !1;
|
|
463
|
-
},
|
|
464
|
-
actions: [({
|
|
465
|
-
selectedListBlocks
|
|
466
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
467
|
-
type: "text block.set",
|
|
468
|
-
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
|
|
469
|
-
at: selectedListBlock.path
|
|
470
|
-
}))]
|
|
471
|
-
}, unindentListOnShiftTab = {
|
|
472
|
-
on: "key.down",
|
|
473
|
-
guard: ({
|
|
474
|
-
context,
|
|
475
|
-
event
|
|
476
|
-
}) => {
|
|
477
|
-
if (!isHotkey("Shift+Tab", event.keyboardEvent))
|
|
478
|
-
return !1;
|
|
479
|
-
const selectedBlocks = getSelectedBlocks({
|
|
480
|
-
context
|
|
481
|
-
}), guards = createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
482
|
-
node: block.node,
|
|
483
|
-
path: block.path
|
|
484
|
-
}] : []);
|
|
485
|
-
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
486
|
-
selectedListBlocks
|
|
487
|
-
} : !1;
|
|
488
|
-
},
|
|
489
|
-
actions: [({
|
|
490
|
-
selectedListBlocks
|
|
491
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
492
|
-
type: "text block.set",
|
|
493
|
-
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
|
|
494
|
-
at: selectedListBlock.path
|
|
495
|
-
}))]
|
|
496
|
-
}, coreListBehaviors = {
|
|
497
|
-
clearListOnBackspace,
|
|
498
|
-
unindentListOnBackspace,
|
|
499
|
-
clearListOnEnter,
|
|
500
|
-
indentListOnTab,
|
|
501
|
-
unindentListOnShiftTab
|
|
502
|
-
}, softReturn = {
|
|
503
|
-
on: "insert.soft break",
|
|
504
|
-
actions: [() => [{
|
|
505
|
-
type: "insert.text",
|
|
506
|
-
text: `
|
|
507
|
-
`
|
|
508
|
-
}]]
|
|
509
|
-
}, coreBehaviors = [softReturn, coreDecoratorBehaviors.decoratorAdd, coreDecoratorBehaviors.decoratorRemove, coreDecoratorBehaviors.decoratorToggle, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab], coreBehavior = {
|
|
510
|
-
softReturn,
|
|
511
|
-
decorators: coreDecoratorBehaviors,
|
|
512
|
-
blockObjects: coreBlockObjectBehaviors,
|
|
513
|
-
lists: coreListBehaviors
|
|
514
|
-
};
|
|
515
|
-
function createLinkBehaviors(config) {
|
|
516
|
-
const pasteLinkOnSelection = {
|
|
517
|
-
on: "paste",
|
|
518
|
-
guard: ({
|
|
519
|
-
context,
|
|
520
|
-
event
|
|
521
|
-
}) => {
|
|
522
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
523
|
-
context
|
|
524
|
-
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
525
|
-
url,
|
|
526
|
-
schema: context.schema
|
|
527
|
-
}) : void 0;
|
|
528
|
-
return annotation && !selectionCollapsed ? {
|
|
529
|
-
annotation
|
|
530
|
-
} : !1;
|
|
531
|
-
},
|
|
532
|
-
actions: [({
|
|
533
|
-
annotation
|
|
534
|
-
}) => [{
|
|
535
|
-
type: "annotation.add",
|
|
536
|
-
annotation
|
|
537
|
-
}]]
|
|
538
|
-
}, pasteLinkAtCaret = {
|
|
539
|
-
on: "paste",
|
|
540
|
-
guard: ({
|
|
541
|
-
context,
|
|
542
|
-
event
|
|
543
|
-
}) => {
|
|
544
|
-
const focusSpan = getFocusSpan({
|
|
545
|
-
context
|
|
546
|
-
}), selectionCollapsed = selectionIsCollapsed({
|
|
547
|
-
context
|
|
548
|
-
});
|
|
549
|
-
if (!focusSpan || !selectionCollapsed)
|
|
550
|
-
return !1;
|
|
551
|
-
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
552
|
-
url,
|
|
553
|
-
schema: context.schema
|
|
554
|
-
}) : void 0;
|
|
555
|
-
return url && annotation && selectionCollapsed ? {
|
|
556
|
-
focusSpan,
|
|
557
|
-
annotation,
|
|
558
|
-
url
|
|
559
|
-
} : !1;
|
|
560
|
-
},
|
|
561
|
-
actions: [({
|
|
562
|
-
annotation,
|
|
563
|
-
url
|
|
564
|
-
}) => [{
|
|
565
|
-
type: "insert.span",
|
|
566
|
-
text: url,
|
|
567
|
-
annotations: [annotation]
|
|
568
|
-
}]]
|
|
569
|
-
};
|
|
570
|
-
return [pasteLinkOnSelection, pasteLinkAtCaret];
|
|
571
|
-
}
|
|
572
|
-
function looksLikeUrl(text) {
|
|
573
|
-
let looksLikeUrl2 = !1;
|
|
574
|
-
try {
|
|
575
|
-
new URL(text), looksLikeUrl2 = !0;
|
|
576
|
-
} catch {
|
|
577
|
-
}
|
|
578
|
-
return looksLikeUrl2;
|
|
579
|
-
}
|
|
580
|
-
function blockOffsetToSpanSelectionPoint({
|
|
581
|
-
value,
|
|
582
|
-
blockOffset
|
|
583
|
-
}) {
|
|
584
|
-
let offsetLeft = blockOffset.offset, selectionPoint;
|
|
585
|
-
for (const block of value)
|
|
586
|
-
if (block._key === blockOffset.path[0]._key && isPortableTextTextBlock(block)) {
|
|
587
|
-
for (const child of block.children)
|
|
588
|
-
if (isPortableTextSpan$1(child)) {
|
|
589
|
-
if (offsetLeft === 0) {
|
|
590
|
-
selectionPoint = {
|
|
591
|
-
path: [...blockOffset.path, "children", {
|
|
592
|
-
_key: child._key
|
|
593
|
-
}],
|
|
594
|
-
offset: 0
|
|
595
|
-
};
|
|
596
|
-
break;
|
|
597
|
-
}
|
|
598
|
-
if (offsetLeft <= child.text.length) {
|
|
599
|
-
selectionPoint = {
|
|
600
|
-
path: [...blockOffset.path, "children", {
|
|
601
|
-
_key: child._key
|
|
602
|
-
}],
|
|
603
|
-
offset: offsetLeft
|
|
604
|
-
};
|
|
605
|
-
break;
|
|
606
|
-
}
|
|
607
|
-
offsetLeft -= child.text.length;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
return selectionPoint;
|
|
611
|
-
}
|
|
612
|
-
function spanSelectionPointToBlockOffset({
|
|
613
|
-
value,
|
|
614
|
-
selectionPoint
|
|
615
|
-
}) {
|
|
616
|
-
let offset = 0;
|
|
617
|
-
for (const block of value)
|
|
618
|
-
if (block._key === selectionPoint.path[0]._key && isPortableTextTextBlock(block)) {
|
|
619
|
-
for (const child of block.children)
|
|
620
|
-
if (isPortableTextSpan$1(child)) {
|
|
621
|
-
if (child._key === selectionPoint.path[2]._key)
|
|
622
|
-
return {
|
|
623
|
-
path: [{
|
|
624
|
-
_key: block._key
|
|
625
|
-
}],
|
|
626
|
-
offset: offset + selectionPoint.offset
|
|
627
|
-
};
|
|
628
|
-
offset += child.text.length;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
function createMarkdownBehaviors(config) {
|
|
633
|
-
const automaticBlockquoteOnSpace = {
|
|
634
|
-
on: "insert.text",
|
|
635
|
-
guard: ({
|
|
636
|
-
context,
|
|
637
|
-
event
|
|
638
|
-
}) => {
|
|
639
|
-
if (event.text !== " ")
|
|
640
|
-
return !1;
|
|
641
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
642
|
-
context
|
|
643
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
644
|
-
context
|
|
645
|
-
}), focusSpan = getFocusSpan({
|
|
646
|
-
context
|
|
647
|
-
});
|
|
648
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
649
|
-
return !1;
|
|
650
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
651
|
-
value: context.value,
|
|
652
|
-
selectionPoint: {
|
|
653
|
-
path: [{
|
|
654
|
-
_key: focusTextBlock.node._key
|
|
655
|
-
}, "children", {
|
|
656
|
-
_key: focusSpan.node._key
|
|
657
|
-
}],
|
|
658
|
-
offset: context.selection.focus.offset
|
|
659
|
-
}
|
|
660
|
-
});
|
|
661
|
-
if (!blockOffset)
|
|
662
|
-
return !1;
|
|
663
|
-
const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
|
|
664
|
-
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
665
|
-
focusTextBlock,
|
|
666
|
-
style: blockquoteStyle
|
|
667
|
-
} : !1;
|
|
668
|
-
},
|
|
669
|
-
actions: [() => [{
|
|
670
|
-
type: "insert.text",
|
|
671
|
-
text: " "
|
|
672
|
-
}], ({
|
|
673
|
-
focusTextBlock,
|
|
674
|
-
style
|
|
675
|
-
}) => [{
|
|
676
|
-
type: "text block.unset",
|
|
677
|
-
props: ["listItem", "level"],
|
|
678
|
-
at: focusTextBlock.path
|
|
679
|
-
}, {
|
|
680
|
-
type: "text block.set",
|
|
681
|
-
style,
|
|
682
|
-
at: focusTextBlock.path
|
|
683
|
-
}, {
|
|
684
|
-
type: "delete.text",
|
|
685
|
-
anchor: {
|
|
686
|
-
path: focusTextBlock.path,
|
|
687
|
-
offset: 0
|
|
688
|
-
},
|
|
689
|
-
focus: {
|
|
690
|
-
path: focusTextBlock.path,
|
|
691
|
-
offset: 2
|
|
692
|
-
}
|
|
693
|
-
}]]
|
|
694
|
-
}, automaticHr = {
|
|
695
|
-
on: "insert.text",
|
|
696
|
-
guard: ({
|
|
697
|
-
context,
|
|
698
|
-
event
|
|
699
|
-
}) => {
|
|
700
|
-
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
701
|
-
if (hrCharacter === void 0)
|
|
702
|
-
return !1;
|
|
703
|
-
const hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusTextBlock({
|
|
704
|
-
context
|
|
705
|
-
}), selectionCollapsed = selectionIsCollapsed({
|
|
706
|
-
context
|
|
707
|
-
});
|
|
708
|
-
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
709
|
-
return !1;
|
|
710
|
-
const textBefore = getBlockTextBefore({
|
|
711
|
-
context
|
|
712
|
-
}), hrBlockOffsets = {
|
|
713
|
-
anchor: {
|
|
714
|
-
path: focusBlock.path,
|
|
715
|
-
offset: 0
|
|
716
|
-
},
|
|
717
|
-
focus: {
|
|
718
|
-
path: focusBlock.path,
|
|
719
|
-
offset: 3
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
return textBefore === `${hrCharacter}${hrCharacter}` ? {
|
|
723
|
-
hrObject,
|
|
724
|
-
focusBlock,
|
|
725
|
-
hrCharacter,
|
|
726
|
-
hrBlockOffsets
|
|
727
|
-
} : !1;
|
|
728
|
-
},
|
|
729
|
-
actions: [({
|
|
730
|
-
hrCharacter
|
|
731
|
-
}) => [{
|
|
732
|
-
type: "insert.text",
|
|
733
|
-
text: hrCharacter
|
|
734
|
-
}], ({
|
|
735
|
-
hrObject,
|
|
736
|
-
hrBlockOffsets
|
|
737
|
-
}) => [{
|
|
738
|
-
type: "insert.block object",
|
|
739
|
-
placement: "before",
|
|
740
|
-
blockObject: hrObject
|
|
741
|
-
}, {
|
|
742
|
-
type: "delete.text",
|
|
743
|
-
...hrBlockOffsets
|
|
744
|
-
}]]
|
|
745
|
-
}, automaticHrOnPaste = {
|
|
746
|
-
on: "paste",
|
|
747
|
-
guard: ({
|
|
748
|
-
context,
|
|
749
|
-
event
|
|
750
|
-
}) => {
|
|
751
|
-
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = getFocusBlock({
|
|
752
|
-
context
|
|
753
|
-
});
|
|
754
|
-
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
755
|
-
hrCharacters,
|
|
756
|
-
hrObject,
|
|
757
|
-
focusBlock
|
|
758
|
-
};
|
|
759
|
-
},
|
|
760
|
-
actions: [({
|
|
761
|
-
hrCharacters
|
|
762
|
-
}) => [{
|
|
763
|
-
type: "insert.text",
|
|
764
|
-
text: hrCharacters
|
|
765
|
-
}], ({
|
|
766
|
-
hrObject,
|
|
767
|
-
focusBlock
|
|
768
|
-
}) => isPortableTextTextBlock(focusBlock.node) ? [{
|
|
769
|
-
type: "insert.text block",
|
|
770
|
-
textBlock: {
|
|
771
|
-
children: focusBlock.node.children
|
|
772
|
-
},
|
|
773
|
-
placement: "after"
|
|
774
|
-
}, {
|
|
775
|
-
type: "insert.block object",
|
|
776
|
-
blockObject: hrObject,
|
|
777
|
-
placement: "after"
|
|
778
|
-
}, {
|
|
779
|
-
type: "delete.block",
|
|
780
|
-
blockPath: focusBlock.path
|
|
781
|
-
}] : [{
|
|
782
|
-
type: "insert.block object",
|
|
783
|
-
blockObject: hrObject,
|
|
784
|
-
placement: "after"
|
|
785
|
-
}]]
|
|
786
|
-
}, automaticHeadingOnSpace = {
|
|
787
|
-
on: "insert.text",
|
|
788
|
-
guard: ({
|
|
789
|
-
context,
|
|
790
|
-
event
|
|
791
|
-
}) => {
|
|
792
|
-
if (event.text !== " ")
|
|
793
|
-
return !1;
|
|
794
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
795
|
-
context
|
|
796
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
797
|
-
context
|
|
798
|
-
}), focusSpan = getFocusSpan({
|
|
799
|
-
context
|
|
800
|
-
});
|
|
801
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
802
|
-
return !1;
|
|
803
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
804
|
-
value: context.value,
|
|
805
|
-
selectionPoint: {
|
|
806
|
-
path: [{
|
|
807
|
-
_key: focusTextBlock.node._key
|
|
808
|
-
}, "children", {
|
|
809
|
-
_key: focusSpan.node._key
|
|
810
|
-
}],
|
|
811
|
-
offset: context.selection.focus.offset
|
|
812
|
-
}
|
|
813
|
-
});
|
|
814
|
-
if (!blockOffset)
|
|
815
|
-
return !1;
|
|
816
|
-
const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
817
|
-
if (blockOffset.offset !== level)
|
|
818
|
-
return !1;
|
|
819
|
-
const style = level !== void 0 ? config.headingStyle?.({
|
|
820
|
-
schema: context.schema,
|
|
821
|
-
level
|
|
822
|
-
}) : void 0;
|
|
823
|
-
return level !== void 0 && style !== void 0 ? {
|
|
824
|
-
focusTextBlock,
|
|
825
|
-
style,
|
|
826
|
-
level
|
|
827
|
-
} : !1;
|
|
828
|
-
},
|
|
829
|
-
actions: [() => [{
|
|
830
|
-
type: "insert.text",
|
|
831
|
-
text: " "
|
|
832
|
-
}], ({
|
|
833
|
-
focusTextBlock,
|
|
834
|
-
style,
|
|
835
|
-
level
|
|
836
|
-
}) => [{
|
|
837
|
-
type: "text block.unset",
|
|
838
|
-
props: ["listItem", "level"],
|
|
839
|
-
at: focusTextBlock.path
|
|
840
|
-
}, {
|
|
841
|
-
type: "text block.set",
|
|
842
|
-
style,
|
|
843
|
-
at: focusTextBlock.path
|
|
844
|
-
}, {
|
|
845
|
-
type: "delete.text",
|
|
846
|
-
anchor: {
|
|
847
|
-
path: focusTextBlock.path,
|
|
848
|
-
offset: 0
|
|
849
|
-
},
|
|
850
|
-
focus: {
|
|
851
|
-
path: focusTextBlock.path,
|
|
852
|
-
offset: level + 1
|
|
853
|
-
}
|
|
854
|
-
}]]
|
|
855
|
-
}, clearStyleOnBackspace = {
|
|
856
|
-
on: "delete.backward",
|
|
857
|
-
guard: ({
|
|
858
|
-
context
|
|
859
|
-
}) => {
|
|
860
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
861
|
-
context
|
|
862
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
863
|
-
context
|
|
864
|
-
}), focusSpan = getFocusSpan({
|
|
865
|
-
context
|
|
866
|
-
});
|
|
867
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
868
|
-
return !1;
|
|
869
|
-
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
|
|
870
|
-
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
871
|
-
defaultStyle,
|
|
872
|
-
focusTextBlock
|
|
873
|
-
} : !1;
|
|
874
|
-
},
|
|
875
|
-
actions: [({
|
|
876
|
-
defaultStyle,
|
|
877
|
-
focusTextBlock
|
|
878
|
-
}) => [{
|
|
879
|
-
type: "text block.set",
|
|
880
|
-
style: defaultStyle,
|
|
881
|
-
at: focusTextBlock.path
|
|
882
|
-
}]]
|
|
883
|
-
}, automaticListOnSpace = {
|
|
884
|
-
on: "insert.text",
|
|
885
|
-
guard: ({
|
|
886
|
-
context,
|
|
887
|
-
event
|
|
888
|
-
}) => {
|
|
889
|
-
if (event.text !== " ")
|
|
890
|
-
return !1;
|
|
891
|
-
const selectionCollapsed = selectionIsCollapsed({
|
|
892
|
-
context
|
|
893
|
-
}), focusTextBlock = getFocusTextBlock({
|
|
894
|
-
context
|
|
895
|
-
}), focusSpan = getFocusSpan({
|
|
896
|
-
context
|
|
897
|
-
});
|
|
898
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
899
|
-
return !1;
|
|
900
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
901
|
-
value: context.value,
|
|
902
|
-
selectionPoint: {
|
|
903
|
-
path: [{
|
|
904
|
-
_key: focusTextBlock.node._key
|
|
905
|
-
}, "children", {
|
|
906
|
-
_key: focusSpan.node._key
|
|
907
|
-
}],
|
|
908
|
-
offset: context.selection.focus.offset
|
|
909
|
-
}
|
|
910
|
-
});
|
|
911
|
-
if (!blockOffset)
|
|
912
|
-
return !1;
|
|
913
|
-
const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
914
|
-
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
915
|
-
return {
|
|
916
|
-
focusTextBlock,
|
|
917
|
-
listItem: unorderedListStyle,
|
|
918
|
-
listItemLength: 1,
|
|
919
|
-
style: defaultStyle
|
|
920
|
-
};
|
|
921
|
-
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
922
|
-
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
923
|
-
focusTextBlock,
|
|
924
|
-
listItem: orderedListStyle,
|
|
925
|
-
listItemLength: 2,
|
|
926
|
-
style: defaultStyle
|
|
927
|
-
} : !1;
|
|
928
|
-
},
|
|
929
|
-
actions: [() => [{
|
|
930
|
-
type: "insert.text",
|
|
931
|
-
text: " "
|
|
932
|
-
}], ({
|
|
933
|
-
focusTextBlock,
|
|
934
|
-
style,
|
|
935
|
-
listItem,
|
|
936
|
-
listItemLength
|
|
937
|
-
}) => [{
|
|
938
|
-
type: "text block.set",
|
|
939
|
-
listItem,
|
|
940
|
-
level: 1,
|
|
941
|
-
style,
|
|
942
|
-
at: focusTextBlock.path
|
|
943
|
-
}, {
|
|
944
|
-
type: "delete.text",
|
|
945
|
-
anchor: {
|
|
946
|
-
path: focusTextBlock.path,
|
|
947
|
-
offset: 0
|
|
948
|
-
},
|
|
949
|
-
focus: {
|
|
950
|
-
path: focusTextBlock.path,
|
|
951
|
-
offset: listItemLength + 1
|
|
952
|
-
}
|
|
953
|
-
}]]
|
|
954
|
-
};
|
|
955
|
-
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
|
|
956
|
-
}
|
|
957
41
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
42
|
+
var _a, _b, _c;
|
|
958
43
|
if (!portableTextType)
|
|
959
44
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
960
|
-
const blockType = portableTextType.of
|
|
45
|
+
const blockType = (_a = portableTextType.of) == null ? void 0 : _a.find(findBlockType);
|
|
961
46
|
if (!blockType)
|
|
962
47
|
throw new Error("Block type is not defined in this schema (required)");
|
|
963
|
-
const childrenField = blockType.fields
|
|
48
|
+
const childrenField = (_b = blockType.fields) == null ? void 0 : _b.find((field) => field.name === "children");
|
|
964
49
|
if (!childrenField)
|
|
965
50
|
throw new Error("Children field for block type found in schema (required)");
|
|
966
51
|
const ofType = childrenField.type.of;
|
|
@@ -969,7 +54,7 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
969
54
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
970
55
|
if (!spanType)
|
|
971
56
|
throw new Error("Span type not found in schema (required)");
|
|
972
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of
|
|
57
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = ((_c = portableTextType.of) == null ? void 0 : _c.filter((field) => field.name !== blockType.name)) || [];
|
|
973
58
|
return {
|
|
974
59
|
styles: resolveEnabledStyles(blockType),
|
|
975
60
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -983,10 +68,11 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
983
68
|
};
|
|
984
69
|
}
|
|
985
70
|
function resolveEnabledStyles(blockType) {
|
|
986
|
-
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
987
73
|
if (!styleField)
|
|
988
74
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
989
|
-
const textStyles = styleField.type.options
|
|
75
|
+
const textStyles = ((_b = styleField.type.options) == null ? void 0 : _b.list) && ((_c = styleField.type.options.list) == null ? void 0 : _c.filter((style) => style.value));
|
|
990
76
|
if (!textStyles || textStyles.length === 0)
|
|
991
77
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
992
78
|
return textStyles;
|
|
@@ -995,10 +81,11 @@ function resolveEnabledDecorators(spanType) {
|
|
|
995
81
|
return spanType.decorators;
|
|
996
82
|
}
|
|
997
83
|
function resolveEnabledListItems(blockType) {
|
|
998
|
-
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
999
86
|
if (!listField)
|
|
1000
87
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
1001
|
-
const listItems = listField.type.options
|
|
88
|
+
const listItems = ((_b = listField.type.options) == null ? void 0 : _b.list) && listField.type.options.list.filter((list) => list.value);
|
|
1002
89
|
if (!listItems)
|
|
1003
90
|
throw new Error("The list field need at least to be an empty array");
|
|
1004
91
|
return listItems;
|
|
@@ -1006,11 +93,20 @@ function resolveEnabledListItems(blockType) {
|
|
|
1006
93
|
function findBlockType(type) {
|
|
1007
94
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
1008
95
|
}
|
|
96
|
+
var __defProp$p = Object.defineProperty, __defProps$j = Object.defineProperties, __getOwnPropDescs$j = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$p = Object.getOwnPropertySymbols, __hasOwnProp$p = Object.prototype.hasOwnProperty, __propIsEnum$p = Object.prototype.propertyIsEnumerable, __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$p = (a, b) => {
|
|
97
|
+
for (var prop in b || (b = {}))
|
|
98
|
+
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
99
|
+
if (__getOwnPropSymbols$p)
|
|
100
|
+
for (var prop of __getOwnPropSymbols$p(b))
|
|
101
|
+
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
102
|
+
return a;
|
|
103
|
+
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
1009
104
|
function defineSchema(definition) {
|
|
1010
105
|
return definition;
|
|
1011
106
|
}
|
|
1012
107
|
function compileSchemaDefinition(definition) {
|
|
1013
|
-
|
|
108
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
109
|
+
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => defineType({
|
|
1014
110
|
type: "object",
|
|
1015
111
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
1016
112
|
// fields to objects with the name `image`
|
|
@@ -1018,13 +114,13 @@ function compileSchemaDefinition(definition) {
|
|
|
1018
114
|
title: blockObject.title,
|
|
1019
115
|
icon: blockObject.icon,
|
|
1020
116
|
fields: []
|
|
1021
|
-
}))
|
|
117
|
+
}))) != null ? _b : [], inlineObjects = (_d = (_c = definition == null ? void 0 : definition.inlineObjects) == null ? void 0 : _c.map((inlineObject) => defineType({
|
|
1022
118
|
type: "object",
|
|
1023
119
|
name: inlineObject.name,
|
|
1024
120
|
title: inlineObject.title,
|
|
1025
121
|
icon: inlineObject.icon,
|
|
1026
122
|
fields: []
|
|
1027
|
-
}))
|
|
123
|
+
}))) != null ? _d : [], portableTextSchema = defineField({
|
|
1028
124
|
type: "array",
|
|
1029
125
|
name: "portable-text",
|
|
1030
126
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -1036,43 +132,49 @@ function compileSchemaDefinition(definition) {
|
|
|
1036
132
|
type: inlineObject.name
|
|
1037
133
|
})),
|
|
1038
134
|
marks: {
|
|
1039
|
-
decorators: definition
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
135
|
+
decorators: (_f = (_e = definition == null ? void 0 : definition.decorators) == null ? void 0 : _e.map((decorator) => {
|
|
136
|
+
var _a2;
|
|
137
|
+
return {
|
|
138
|
+
title: (_a2 = decorator.title) != null ? _a2 : startCase(decorator.name),
|
|
139
|
+
value: decorator.name,
|
|
140
|
+
icon: decorator.icon
|
|
141
|
+
};
|
|
142
|
+
})) != null ? _f : [],
|
|
143
|
+
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
1045
144
|
name: annotation.name,
|
|
1046
145
|
type: "object",
|
|
1047
146
|
title: annotation.title,
|
|
1048
147
|
icon: annotation.icon
|
|
1049
|
-
}))
|
|
148
|
+
}))) != null ? _h : []
|
|
1050
149
|
},
|
|
1051
|
-
lists: definition
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
150
|
+
lists: (_j = (_i = definition == null ? void 0 : definition.lists) == null ? void 0 : _i.map((list) => {
|
|
151
|
+
var _a2;
|
|
152
|
+
return {
|
|
153
|
+
value: list.name,
|
|
154
|
+
title: (_a2 = list.title) != null ? _a2 : startCase(list.name),
|
|
155
|
+
icon: list.icon
|
|
156
|
+
};
|
|
157
|
+
})) != null ? _j : [],
|
|
158
|
+
styles: (_l = (_k = definition == null ? void 0 : definition.styles) == null ? void 0 : _k.map((style) => {
|
|
159
|
+
var _a2;
|
|
160
|
+
return {
|
|
161
|
+
value: style.name,
|
|
162
|
+
title: (_a2 = style.title) != null ? _a2 : startCase(style.name),
|
|
163
|
+
icon: style.icon
|
|
164
|
+
};
|
|
165
|
+
})) != null ? _l : []
|
|
1061
166
|
}]
|
|
1062
167
|
}), schema = Schema.compile({
|
|
1063
168
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
1064
169
|
}).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema);
|
|
1065
|
-
return {
|
|
1066
|
-
|
|
1067
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
1068
|
-
...blockObject,
|
|
170
|
+
return __spreadProps$j(__spreadValues$p({}, pteSchema), {
|
|
171
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
|
|
1069
172
|
name: "image",
|
|
1070
|
-
type: {
|
|
1071
|
-
...blockObject.type,
|
|
173
|
+
type: __spreadProps$j(__spreadValues$p({}, blockObject.type), {
|
|
1072
174
|
name: "image"
|
|
1073
|
-
}
|
|
1074
|
-
} : blockObject)
|
|
1075
|
-
};
|
|
175
|
+
})
|
|
176
|
+
}) : blockObject)
|
|
177
|
+
});
|
|
1076
178
|
}
|
|
1077
179
|
const rootName = "sanity-pte:";
|
|
1078
180
|
var debug$l = debug$m(rootName);
|
|
@@ -1207,6 +309,22 @@ function normalizeSelection(selection, value) {
|
|
|
1207
309
|
backward: selection.backward
|
|
1208
310
|
} : null;
|
|
1209
311
|
}
|
|
312
|
+
var __defProp$o = Object.defineProperty, __defProps$i = Object.defineProperties, __getOwnPropDescs$i = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$o = Object.getOwnPropertySymbols, __hasOwnProp$o = Object.prototype.hasOwnProperty, __propIsEnum$o = Object.prototype.propertyIsEnumerable, __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$o = (a, b) => {
|
|
313
|
+
for (var prop in b || (b = {}))
|
|
314
|
+
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
315
|
+
if (__getOwnPropSymbols$o)
|
|
316
|
+
for (var prop of __getOwnPropSymbols$o(b))
|
|
317
|
+
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
318
|
+
return a;
|
|
319
|
+
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
320
|
+
var target = {};
|
|
321
|
+
for (var prop in source)
|
|
322
|
+
__hasOwnProp$o.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
323
|
+
if (source != null && __getOwnPropSymbols$o)
|
|
324
|
+
for (var prop of __getOwnPropSymbols$o(source))
|
|
325
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$o.call(source, prop) && (target[prop] = source[prop]);
|
|
326
|
+
return target;
|
|
327
|
+
};
|
|
1210
328
|
const VOID_CHILD_KEY = "void-child";
|
|
1211
329
|
function keepObjectEquality(object, keyMap) {
|
|
1212
330
|
const value = keyMap[object._key];
|
|
@@ -1216,11 +334,13 @@ function toSlateValue(value, {
|
|
|
1216
334
|
schemaTypes
|
|
1217
335
|
}, keyMap = {}) {
|
|
1218
336
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
1219
|
-
const {
|
|
337
|
+
const _a = block, {
|
|
1220
338
|
_type,
|
|
1221
|
-
_key
|
|
1222
|
-
|
|
1223
|
-
|
|
339
|
+
_key
|
|
340
|
+
} = _a, rest = __objRest$3(_a, [
|
|
341
|
+
"_type",
|
|
342
|
+
"_key"
|
|
343
|
+
]), voidChildren = [{
|
|
1224
344
|
_key: VOID_CHILD_KEY,
|
|
1225
345
|
_type: "span",
|
|
1226
346
|
text: "",
|
|
@@ -1230,11 +350,13 @@ function toSlateValue(value, {
|
|
|
1230
350
|
const textBlock = block;
|
|
1231
351
|
let hasInlines = !1;
|
|
1232
352
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
1233
|
-
const {
|
|
353
|
+
const _a2 = child, {
|
|
1234
354
|
_type: cType,
|
|
1235
|
-
_key: cKey
|
|
1236
|
-
|
|
1237
|
-
|
|
355
|
+
_key: cKey
|
|
356
|
+
} = _a2, cRest = __objRest$3(_a2, [
|
|
357
|
+
"_type",
|
|
358
|
+
"_key"
|
|
359
|
+
]);
|
|
1238
360
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
1239
361
|
_type: cType,
|
|
1240
362
|
_key: cKey,
|
|
@@ -1243,12 +365,12 @@ function toSlateValue(value, {
|
|
|
1243
365
|
__inline: !0
|
|
1244
366
|
}, keyMap)) : child;
|
|
1245
367
|
});
|
|
1246
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
368
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$o({
|
|
1247
369
|
_type,
|
|
1248
|
-
_key
|
|
1249
|
-
|
|
370
|
+
_key
|
|
371
|
+
}, rest), {
|
|
1250
372
|
children
|
|
1251
|
-
}, keyMap));
|
|
373
|
+
}), keyMap));
|
|
1252
374
|
}
|
|
1253
375
|
return keepObjectEquality({
|
|
1254
376
|
_type,
|
|
@@ -1274,40 +396,42 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
1274
396
|
} = child;
|
|
1275
397
|
if ("value" in child && _cType !== "span") {
|
|
1276
398
|
hasInlines = !0;
|
|
1277
|
-
const {
|
|
399
|
+
const _a = child, {
|
|
1278
400
|
value: v,
|
|
1279
401
|
_key: k,
|
|
1280
402
|
_type: t,
|
|
1281
403
|
__inline: _i,
|
|
1282
|
-
children: _c
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
404
|
+
children: _c
|
|
405
|
+
} = _a, rest = __objRest$3(_a, [
|
|
406
|
+
"value",
|
|
407
|
+
"_key",
|
|
408
|
+
"_type",
|
|
409
|
+
"__inline",
|
|
410
|
+
"children"
|
|
411
|
+
]);
|
|
412
|
+
return keepObjectEquality(__spreadProps$i(__spreadValues$o(__spreadValues$o({}, rest), v), {
|
|
1288
413
|
_key: k,
|
|
1289
414
|
_type: t
|
|
1290
|
-
}, keyMap);
|
|
415
|
+
}), keyMap);
|
|
1291
416
|
}
|
|
1292
417
|
return child;
|
|
1293
418
|
});
|
|
1294
|
-
return hasInlines ? keepObjectEquality({
|
|
1295
|
-
...block,
|
|
419
|
+
return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$o({}, block), {
|
|
1296
420
|
children,
|
|
1297
421
|
_key,
|
|
1298
422
|
_type
|
|
1299
|
-
}, keyMap) : block;
|
|
423
|
+
}), keyMap) : block;
|
|
1300
424
|
}
|
|
1301
425
|
const blockValue = "value" in block && block.value;
|
|
1302
|
-
return keepObjectEquality({
|
|
426
|
+
return keepObjectEquality(__spreadValues$o({
|
|
1303
427
|
_key,
|
|
1304
|
-
_type
|
|
1305
|
-
|
|
1306
|
-
}, keyMap);
|
|
428
|
+
_type
|
|
429
|
+
}, typeof blockValue == "object" ? blockValue : {}), keyMap);
|
|
1307
430
|
});
|
|
1308
431
|
}
|
|
1309
432
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
1310
|
-
|
|
433
|
+
var _a;
|
|
434
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !((_a = children[0].children[0].marks) != null && _a.join("")) && children[0].children[0].text === "";
|
|
1311
435
|
}
|
|
1312
436
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_PROCESSING_LOCAL_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
|
|
1313
437
|
const $ = c(4);
|
|
@@ -1607,6 +731,14 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
1607
731
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
1608
732
|
};
|
|
1609
733
|
DraggableBlock.displayName = "DraggableBlock";
|
|
734
|
+
var __defProp$n = Object.defineProperty, __defProps$h = Object.defineProperties, __getOwnPropDescs$h = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$n = Object.getOwnPropertySymbols, __hasOwnProp$n = Object.prototype.hasOwnProperty, __propIsEnum$n = Object.prototype.propertyIsEnumerable, __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$n = (a, b) => {
|
|
735
|
+
for (var prop in b || (b = {}))
|
|
736
|
+
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
737
|
+
if (__getOwnPropSymbols$n)
|
|
738
|
+
for (var prop of __getOwnPropSymbols$n(b))
|
|
739
|
+
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
740
|
+
return a;
|
|
741
|
+
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
1610
742
|
debugWithName("components:Element");
|
|
1611
743
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
1612
744
|
display: "inline-block"
|
|
@@ -1643,7 +775,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1643
775
|
}, "children", {
|
|
1644
776
|
_key: element._key
|
|
1645
777
|
}];
|
|
1646
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
778
|
+
return /* @__PURE__ */ jsxs("span", __spreadProps$h(__spreadValues$n({}, attributes), { children: [
|
|
1647
779
|
children,
|
|
1648
780
|
/* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
1649
781
|
renderChild && renderChild({
|
|
@@ -1660,7 +792,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1660
792
|
}),
|
|
1661
793
|
!renderChild && /* @__PURE__ */ jsx(DefaultObject, { value })
|
|
1662
794
|
] }, element._key)
|
|
1663
|
-
] });
|
|
795
|
+
] }));
|
|
1664
796
|
}
|
|
1665
797
|
throw new Error("Block not found!");
|
|
1666
798
|
}
|
|
@@ -1711,7 +843,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1711
843
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
1712
844
|
}
|
|
1713
845
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
1714
|
-
return /* @__PURE__ */ jsx("div", {
|
|
846
|
+
return /* @__PURE__ */ jsx("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
|
|
1715
847
|
}
|
|
1716
848
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
1717
849
|
if (!schemaType_0)
|
|
@@ -1736,13 +868,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1736
868
|
});
|
|
1737
869
|
renderedBlockFromProps = renderBlock(_props);
|
|
1738
870
|
}
|
|
1739
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
871
|
+
return /* @__PURE__ */ jsxs("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, children: [
|
|
1740
872
|
children,
|
|
1741
873
|
/* @__PURE__ */ jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
1742
874
|
renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
1743
875
|
!renderedBlockFromProps && /* @__PURE__ */ jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsx(DefaultObject, { value }) })
|
|
1744
876
|
] })
|
|
1745
|
-
] }, element._key);
|
|
877
|
+
] }), element._key);
|
|
1746
878
|
};
|
|
1747
879
|
Element.displayName = "Element";
|
|
1748
880
|
const PortableTextEditorContext = createContext(null), usePortableTextEditor = () => {
|
|
@@ -1770,6 +902,14 @@ function compileType(rawType) {
|
|
|
1770
902
|
types: [rawType]
|
|
1771
903
|
}).get(rawType.name);
|
|
1772
904
|
}
|
|
905
|
+
var __defProp$m = Object.defineProperty, __defProps$g = Object.defineProperties, __getOwnPropDescs$g = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$m = Object.getOwnPropertySymbols, __hasOwnProp$m = Object.prototype.hasOwnProperty, __propIsEnum$m = Object.prototype.propertyIsEnumerable, __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$m = (a, b) => {
|
|
906
|
+
for (var prop in b || (b = {}))
|
|
907
|
+
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
908
|
+
if (__getOwnPropSymbols$m)
|
|
909
|
+
for (var prop of __getOwnPropSymbols$m(b))
|
|
910
|
+
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
911
|
+
return a;
|
|
912
|
+
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
1773
913
|
function validateValue(value, types, keyGenerator) {
|
|
1774
914
|
let resolution = null, valid = !0;
|
|
1775
915
|
const validChildTypes = [types.span.name, ...types.inlineObjects.map((t) => t.name)], validBlockTypes = [types.block.name, ...types.blockObjects.map((t) => t.name)];
|
|
@@ -1807,10 +947,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1807
947
|
}, !0;
|
|
1808
948
|
if (!blk._key || typeof blk._key != "string")
|
|
1809
949
|
return resolution = {
|
|
1810
|
-
patches: [set({
|
|
1811
|
-
...blk,
|
|
950
|
+
patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1812
951
|
_key: keyGenerator()
|
|
1813
|
-
}, [index])],
|
|
952
|
+
}), [index])],
|
|
1814
953
|
description: `Block at index ${index} is missing required _key.`,
|
|
1815
954
|
action: "Set the block with a random _key value",
|
|
1816
955
|
item: blk,
|
|
@@ -1826,10 +965,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1826
965
|
if (blk._type === "block") {
|
|
1827
966
|
const currentBlockTypeName = types.block.name;
|
|
1828
967
|
return resolution = {
|
|
1829
|
-
patches: [set({
|
|
1830
|
-
...blk,
|
|
968
|
+
patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1831
969
|
_type: currentBlockTypeName
|
|
1832
|
-
}, [{
|
|
970
|
+
}), [{
|
|
1833
971
|
_key: blk._key
|
|
1834
972
|
}])],
|
|
1835
973
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1845,14 +983,12 @@ function validateValue(value, types, keyGenerator) {
|
|
|
1845
983
|
}
|
|
1846
984
|
}, !0;
|
|
1847
985
|
}
|
|
1848
|
-
return !blk._type && isPortableTextTextBlock({
|
|
1849
|
-
...blk,
|
|
986
|
+
return !blk._type && isPortableTextTextBlock(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1850
987
|
_type: types.block.name
|
|
1851
|
-
}) ? (resolution = {
|
|
1852
|
-
patches: [set({
|
|
1853
|
-
...blk,
|
|
988
|
+
})) ? (resolution = {
|
|
989
|
+
patches: [set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1854
990
|
_type: types.block.name
|
|
1855
|
-
}, [{
|
|
991
|
+
}), [{
|
|
1856
992
|
_key: blk._key
|
|
1857
993
|
}])],
|
|
1858
994
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types.block.name}'`,
|
|
@@ -2012,10 +1148,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
2012
1148
|
}
|
|
2013
1149
|
}, !0;
|
|
2014
1150
|
if (!child._key || typeof child._key != "string") {
|
|
2015
|
-
const newChild = {
|
|
2016
|
-
...child,
|
|
1151
|
+
const newChild = __spreadProps$g(__spreadValues$m({}, child), {
|
|
2017
1152
|
_key: keyGenerator()
|
|
2018
|
-
};
|
|
1153
|
+
});
|
|
2019
1154
|
return resolution = {
|
|
2020
1155
|
autoResolve: !0,
|
|
2021
1156
|
patches: [set(newChild, [{
|
|
@@ -2035,10 +1170,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
2035
1170
|
}, !0;
|
|
2036
1171
|
}
|
|
2037
1172
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types.span.name && typeof child.text != "string" ? (resolution = {
|
|
2038
|
-
patches: [set({
|
|
2039
|
-
...child,
|
|
1173
|
+
patches: [set(__spreadProps$g(__spreadValues$m({}, child), {
|
|
2040
1174
|
text: ""
|
|
2041
|
-
}, [{
|
|
1175
|
+
}), [{
|
|
2042
1176
|
_key: blk._key
|
|
2043
1177
|
}, "children", {
|
|
2044
1178
|
_key: child._key
|
|
@@ -2449,11 +1583,10 @@ function createDeadLine(timeout) {
|
|
|
2449
1583
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
2450
1584
|
}
|
|
2451
1585
|
function createInternalOpts(opts) {
|
|
2452
|
-
return {
|
|
1586
|
+
return __spreadValues({
|
|
2453
1587
|
checkLines: !0,
|
|
2454
|
-
deadline: createDeadLine(opts.timeout || 1)
|
|
2455
|
-
|
|
2456
|
-
};
|
|
1588
|
+
deadline: createDeadLine(opts.timeout || 1)
|
|
1589
|
+
}, opts);
|
|
2457
1590
|
}
|
|
2458
1591
|
function combineChar(data, char, dir) {
|
|
2459
1592
|
return dir === 1 ? data + char : char + data;
|
|
@@ -2517,10 +1650,7 @@ const DEFAULT_OPTIONS = {
|
|
|
2517
1650
|
distance: 1e3
|
|
2518
1651
|
};
|
|
2519
1652
|
function applyDefaults(options) {
|
|
2520
|
-
return {
|
|
2521
|
-
...DEFAULT_OPTIONS,
|
|
2522
|
-
...options
|
|
2523
|
-
};
|
|
1653
|
+
return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
2524
1654
|
}
|
|
2525
1655
|
const MAX_BITS$1 = 32;
|
|
2526
1656
|
function bitap(text, pattern, loc) {
|
|
@@ -2792,7 +1922,7 @@ function parse(textline) {
|
|
|
2792
1922
|
let line;
|
|
2793
1923
|
try {
|
|
2794
1924
|
line = decodeURI(currentLine.slice(1));
|
|
2795
|
-
} catch {
|
|
1925
|
+
} catch (ex) {
|
|
2796
1926
|
throw new Error("Illegal escape in parse: ".concat(currentLine));
|
|
2797
1927
|
}
|
|
2798
1928
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
@@ -2818,7 +1948,8 @@ function withUndoing(editor, fn) {
|
|
|
2818
1948
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
2819
1949
|
}
|
|
2820
1950
|
function isUndoing(editor) {
|
|
2821
|
-
|
|
1951
|
+
var _a;
|
|
1952
|
+
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
2822
1953
|
}
|
|
2823
1954
|
function setIsUndoing(editor, isUndoing2) {
|
|
2824
1955
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2828,11 +1959,20 @@ function withRedoing(editor, fn) {
|
|
|
2828
1959
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2829
1960
|
}
|
|
2830
1961
|
function isRedoing(editor) {
|
|
2831
|
-
|
|
1962
|
+
var _a;
|
|
1963
|
+
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
2832
1964
|
}
|
|
2833
1965
|
function setIsRedoing(editor, isRedoing2) {
|
|
2834
1966
|
IS_REDOING.set(editor, isRedoing2);
|
|
2835
1967
|
}
|
|
1968
|
+
var __defProp$l = Object.defineProperty, __getOwnPropSymbols$l = Object.getOwnPropertySymbols, __hasOwnProp$l = Object.prototype.hasOwnProperty, __propIsEnum$l = Object.prototype.propertyIsEnumerable, __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$l = (a, b) => {
|
|
1969
|
+
for (var prop in b || (b = {}))
|
|
1970
|
+
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
1971
|
+
if (__getOwnPropSymbols$l)
|
|
1972
|
+
for (var prop of __getOwnPropSymbols$l(b))
|
|
1973
|
+
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
1974
|
+
return a;
|
|
1975
|
+
};
|
|
2836
1976
|
const debug$j = debugWithName("plugin:withUndoRedo"), debugVerbose$4 = debug$j.enabled && !1, SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
2837
1977
|
const state = SAVING.get(editor);
|
|
2838
1978
|
return state === void 0 ? !0 : state;
|
|
@@ -2989,9 +2129,7 @@ function createWithUndoRedo(options) {
|
|
|
2989
2129
|
}
|
|
2990
2130
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2991
2131
|
debugVerbose$4 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2992
|
-
const transformedOperation = {
|
|
2993
|
-
...operation
|
|
2994
|
-
};
|
|
2132
|
+
const transformedOperation = __spreadValues$l({}, operation);
|
|
2995
2133
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2996
2134
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2997
2135
|
_key: blk._key
|
|
@@ -3011,6 +2149,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3011
2149
|
return !operationTargetBlock || !isEqual({
|
|
3012
2150
|
_key: operationTargetBlock._key
|
|
3013
2151
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2152
|
+
var _a, _b, _c, _d;
|
|
3014
2153
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
3015
2154
|
const {
|
|
3016
2155
|
diffs
|
|
@@ -3019,15 +2158,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3019
2158
|
const [diffType, text] = diff2;
|
|
3020
2159
|
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
3021
2160
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
3022
|
-
const currentFocus = transformedOperation.properties
|
|
3023
|
-
...transformedOperation.properties.focus
|
|
3024
|
-
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
3025
|
-
...transformedOperation.properties.anchor
|
|
3026
|
-
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
3027
|
-
...transformedOperation.newProperties.focus
|
|
3028
|
-
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
3029
|
-
...transformedOperation.newProperties.anchor
|
|
3030
|
-
} : void 0;
|
|
2161
|
+
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
|
|
3031
2162
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
3032
2163
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
3033
2164
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -3043,23 +2174,14 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3043
2174
|
return [transformedOperation];
|
|
3044
2175
|
}
|
|
3045
2176
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
};
|
|
2177
|
+
var _a, _b, _c, _d;
|
|
2178
|
+
const transformedOperation = __spreadValues$l({}, operation);
|
|
3049
2179
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
3050
2180
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
3051
2181
|
transformedOperation.path = newPath;
|
|
3052
2182
|
}
|
|
3053
2183
|
if (transformedOperation.type === "set_selection") {
|
|
3054
|
-
const currentFocus = transformedOperation.properties
|
|
3055
|
-
...transformedOperation.properties.focus
|
|
3056
|
-
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
3057
|
-
...transformedOperation.properties.anchor
|
|
3058
|
-
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
3059
|
-
...transformedOperation.newProperties.focus
|
|
3060
|
-
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
3061
|
-
...transformedOperation.newProperties.anchor
|
|
3062
|
-
} : void 0;
|
|
2184
|
+
const currentFocus = (_a = transformedOperation.properties) != null && _a.focus ? __spreadValues$l({}, transformedOperation.properties.focus) : void 0, currentAnchor = (_b = transformedOperation == null ? void 0 : transformedOperation.properties) != null && _b.anchor ? __spreadValues$l({}, transformedOperation.properties.anchor) : void 0, newFocus = (_c = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _c.focus ? __spreadValues$l({}, transformedOperation.newProperties.focus) : void 0, newAnchor = (_d = transformedOperation == null ? void 0 : transformedOperation.newProperties) != null && _d.anchor ? __spreadValues$l({}, transformedOperation.newProperties.anchor) : void 0;
|
|
3063
2185
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
3064
2186
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
3065
2187
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -3080,12 +2202,8 @@ function withoutSaving(editor, fn) {
|
|
|
3080
2202
|
function createSelectOperation(editor) {
|
|
3081
2203
|
return {
|
|
3082
2204
|
type: "set_selection",
|
|
3083
|
-
properties: {
|
|
3084
|
-
|
|
3085
|
-
},
|
|
3086
|
-
newProperties: {
|
|
3087
|
-
...editor.selection
|
|
3088
|
-
}
|
|
2205
|
+
properties: __spreadValues$l({}, editor.selection),
|
|
2206
|
+
newProperties: __spreadValues$l({}, editor.selection)
|
|
3089
2207
|
};
|
|
3090
2208
|
}
|
|
3091
2209
|
function findOperationTargetBlock(editor, operation) {
|
|
@@ -3159,15 +2277,16 @@ function useSyncValue(props) {
|
|
|
3159
2277
|
isChanged = !0;
|
|
3160
2278
|
}
|
|
3161
2279
|
slateValueFromProps.forEach((currentBlock, currentBlockIndex) => {
|
|
2280
|
+
var _a, _b, _c, _d, _e;
|
|
3162
2281
|
const oldBlock = slateEditor.children[currentBlockIndex];
|
|
3163
2282
|
if (oldBlock && !isEqual(currentBlock, oldBlock) && isValid) {
|
|
3164
2283
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
3165
|
-
!validation.valid && validation.resolution
|
|
2284
|
+
!validation.valid && (_a = validation.resolution) != null && _a.autoResolve && ((_b = validation.resolution) == null ? void 0 : _b.patches.length) > 0 && !readOnly && previousValue.current && previousValue.current !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${(_c = validation.resolution) == null ? void 0 : _c.description}`), validation.resolution.patches.forEach((patch) => {
|
|
3166
2285
|
editorActor.send({
|
|
3167
2286
|
type: "patch",
|
|
3168
2287
|
patch
|
|
3169
2288
|
});
|
|
3170
|
-
})), validation.valid || validation.resolution
|
|
2289
|
+
})), validation.valid || (_d = validation.resolution) != null && _d.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$i.enabled && debug$i("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$i.enabled && debug$i("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), isChanged = !0) : (editorActor.send({
|
|
3171
2290
|
type: "invalid value",
|
|
3172
2291
|
resolution: validation.resolution,
|
|
3173
2292
|
value
|
|
@@ -3175,7 +2294,7 @@ function useSyncValue(props) {
|
|
|
3175
2294
|
}
|
|
3176
2295
|
if (!oldBlock && isValid) {
|
|
3177
2296
|
const validationValue_0 = [value[currentBlockIndex]], validation_0 = validateValue(validationValue_0, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
3178
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || validation_0.resolution
|
|
2297
|
+
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || (_e = validation_0.resolution) != null && _e.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3179
2298
|
at: [currentBlockIndex]
|
|
3180
2299
|
}) : (debug$i("Invalid", validation_0), editorActor.send({
|
|
3181
2300
|
type: "invalid value",
|
|
@@ -3244,9 +2363,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3244
2363
|
at: [currentBlockIndex, childIndex]
|
|
3245
2364
|
}));
|
|
3246
2365
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3247
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild
|
|
2366
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild == null ? void 0 : oldBlockChild.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3248
2367
|
if (isChildChanged)
|
|
3249
|
-
if (currentBlockChild._key === oldBlockChild
|
|
2368
|
+
if (currentBlockChild._key === (oldBlockChild == null ? void 0 : oldBlockChild._key)) {
|
|
3250
2369
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3251
2370
|
at: path
|
|
3252
2371
|
});
|
|
@@ -3357,6 +2476,14 @@ function _temp(s) {
|
|
|
3357
2476
|
return s.context.readOnly;
|
|
3358
2477
|
}
|
|
3359
2478
|
Synchronizer.displayName = "Synchronizer";
|
|
2479
|
+
var __defProp$k = Object.defineProperty, __defProps$f = Object.defineProperties, __getOwnPropDescs$f = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$k = Object.getOwnPropertySymbols, __hasOwnProp$k = Object.prototype.hasOwnProperty, __propIsEnum$k = Object.prototype.propertyIsEnumerable, __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$k = (a, b) => {
|
|
2480
|
+
for (var prop in b || (b = {}))
|
|
2481
|
+
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2482
|
+
if (__getOwnPropSymbols$k)
|
|
2483
|
+
for (var prop of __getOwnPropSymbols$k(b))
|
|
2484
|
+
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2485
|
+
return a;
|
|
2486
|
+
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
3360
2487
|
const debug$g = debugWithName("operationToPatches");
|
|
3361
2488
|
function createOperationToPatches(types) {
|
|
3362
2489
|
const textBlockName = types.block.name;
|
|
@@ -3396,10 +2523,7 @@ function createOperationToPatches(types) {
|
|
|
3396
2523
|
const block = editor.children[operation.path[0]];
|
|
3397
2524
|
if (typeof block._key != "string")
|
|
3398
2525
|
throw new Error("Expected block to have a _key");
|
|
3399
|
-
const setNode = omitBy({
|
|
3400
|
-
...editor.children[operation.path[0]],
|
|
3401
|
-
...operation.newProperties
|
|
3402
|
-
}, isUndefined);
|
|
2526
|
+
const setNode = omitBy(__spreadValues$k(__spreadValues$k({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined);
|
|
3403
2527
|
return [set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
3404
2528
|
_key: block._key
|
|
3405
2529
|
}])];
|
|
@@ -3434,14 +2558,12 @@ function createOperationToPatches(types) {
|
|
|
3434
2558
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
3435
2559
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
3436
2560
|
if (operation.path.length === 1) {
|
|
3437
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2561
|
+
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block == null ? void 0 : block._key : beforeBlock == null ? void 0 : beforeBlock._key;
|
|
3438
2562
|
return targetKey ? [insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
3439
2563
|
_key: targetKey
|
|
3440
2564
|
}])] : [setIfMissing(beforeValue, []), insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
3441
2565
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
3442
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
3443
|
-
...operation.node
|
|
3444
|
-
};
|
|
2566
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$k({}, operation.node);
|
|
3445
2567
|
!node._type && Text.isText(node) && (node._type = "span", node.marks = []);
|
|
3446
2568
|
const child = fromSlateValue([{
|
|
3447
2569
|
_key: "bogus",
|
|
@@ -3480,10 +2602,9 @@ function createOperationToPatches(types) {
|
|
|
3480
2602
|
if (operation.path.length === 2) {
|
|
3481
2603
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
3482
2604
|
if (editor.isTextSpan(splitSpan)) {
|
|
3483
|
-
const targetSpans = fromSlateValue([{
|
|
3484
|
-
...splitBlock,
|
|
2605
|
+
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$k({}, splitBlock), {
|
|
3485
2606
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
3486
|
-
}], textBlockName)[0].children;
|
|
2607
|
+
})], textBlockName)[0].children;
|
|
3487
2608
|
patches.push(insert(targetSpans, "after", [{
|
|
3488
2609
|
_key: splitBlock._key
|
|
3489
2610
|
}, "children", {
|
|
@@ -3519,7 +2640,7 @@ function createOperationToPatches(types) {
|
|
|
3519
2640
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3520
2641
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
3521
2642
|
if (operation.path.length === 1)
|
|
3522
|
-
if (block
|
|
2643
|
+
if (block != null && block._key) {
|
|
3523
2644
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
3524
2645
|
patches.push(set(newBlock, [{
|
|
3525
2646
|
_key: newBlock._key
|
|
@@ -3791,6 +2912,7 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3791
2912
|
apply: apply2
|
|
3792
2913
|
} = editor;
|
|
3793
2914
|
return editor.apply = (operation) => {
|
|
2915
|
+
var _a;
|
|
3794
2916
|
if (editorActor.getSnapshot().context.readOnly) {
|
|
3795
2917
|
apply2(operation);
|
|
3796
2918
|
return;
|
|
@@ -3803,11 +2925,19 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3803
2925
|
apply2(operation);
|
|
3804
2926
|
return;
|
|
3805
2927
|
}
|
|
3806
|
-
const rows = editorActor.getSnapshot().context.maxBlocks
|
|
2928
|
+
const rows = (_a = editorActor.getSnapshot().context.maxBlocks) != null ? _a : -1;
|
|
3807
2929
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3808
2930
|
}, editor;
|
|
3809
2931
|
};
|
|
3810
2932
|
}
|
|
2933
|
+
var __defProp$j = Object.defineProperty, __defProps$e = Object.defineProperties, __getOwnPropDescs$e = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$j = Object.getOwnPropertySymbols, __hasOwnProp$j = Object.prototype.hasOwnProperty, __propIsEnum$j = Object.prototype.propertyIsEnumerable, __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$j = (a, b) => {
|
|
2934
|
+
for (var prop in b || (b = {}))
|
|
2935
|
+
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2936
|
+
if (__getOwnPropSymbols$j)
|
|
2937
|
+
for (var prop of __getOwnPropSymbols$j(b))
|
|
2938
|
+
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2939
|
+
return a;
|
|
2940
|
+
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3811
2941
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3812
2942
|
return function(editor) {
|
|
3813
2943
|
const {
|
|
@@ -3824,23 +2954,19 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3824
2954
|
return;
|
|
3825
2955
|
}
|
|
3826
2956
|
if (operation.type === "split_node") {
|
|
3827
|
-
apply2({
|
|
3828
|
-
|
|
3829
|
-
properties: {
|
|
3830
|
-
...operation.properties,
|
|
2957
|
+
apply2(__spreadProps$e(__spreadValues$j({}, operation), {
|
|
2958
|
+
properties: __spreadProps$e(__spreadValues$j({}, operation.properties), {
|
|
3831
2959
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3832
|
-
}
|
|
3833
|
-
});
|
|
2960
|
+
})
|
|
2961
|
+
}));
|
|
3834
2962
|
return;
|
|
3835
2963
|
}
|
|
3836
2964
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
3837
|
-
apply2({
|
|
3838
|
-
|
|
3839
|
-
node: {
|
|
3840
|
-
...operation.node,
|
|
2965
|
+
apply2(__spreadProps$e(__spreadValues$j({}, operation), {
|
|
2966
|
+
node: __spreadProps$e(__spreadValues$j({}, operation.node), {
|
|
3841
2967
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3842
|
-
}
|
|
3843
|
-
});
|
|
2968
|
+
})
|
|
2969
|
+
}));
|
|
3844
2970
|
return;
|
|
3845
2971
|
}
|
|
3846
2972
|
apply2(operation);
|
|
@@ -3877,6 +3003,22 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3877
3003
|
}, editor;
|
|
3878
3004
|
};
|
|
3879
3005
|
}
|
|
3006
|
+
var __defProp$i = Object.defineProperty, __defProps$d = Object.defineProperties, __getOwnPropDescs$d = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$i = Object.getOwnPropertySymbols, __hasOwnProp$i = Object.prototype.hasOwnProperty, __propIsEnum$i = Object.prototype.propertyIsEnumerable, __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$i = (a, b) => {
|
|
3007
|
+
for (var prop in b || (b = {}))
|
|
3008
|
+
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3009
|
+
if (__getOwnPropSymbols$i)
|
|
3010
|
+
for (var prop of __getOwnPropSymbols$i(b))
|
|
3011
|
+
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
3012
|
+
return a;
|
|
3013
|
+
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
3014
|
+
var target = {};
|
|
3015
|
+
for (var prop in source)
|
|
3016
|
+
__hasOwnProp$i.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
3017
|
+
if (source != null && __getOwnPropSymbols$i)
|
|
3018
|
+
for (var prop of __getOwnPropSymbols$i(source))
|
|
3019
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$i.call(source, prop) && (target[prop] = source[prop]);
|
|
3020
|
+
return target;
|
|
3021
|
+
};
|
|
3880
3022
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3881
3023
|
function createApplyPatch(schemaTypes) {
|
|
3882
3024
|
return (editor, patch) => {
|
|
@@ -3966,10 +3108,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3966
3108
|
} = patch;
|
|
3967
3109
|
if (!targetChild || !targetChildPath)
|
|
3968
3110
|
return debug$f("Child not found"), !1;
|
|
3969
|
-
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3970
|
-
...targetBlock,
|
|
3111
|
+
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$i({}, targetBlock), {
|
|
3971
3112
|
children: items
|
|
3972
|
-
}], {
|
|
3113
|
+
})], {
|
|
3973
3114
|
schemaTypes
|
|
3974
3115
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3975
3116
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -4014,21 +3155,19 @@ function setPatch(editor, patch) {
|
|
|
4014
3155
|
return !0;
|
|
4015
3156
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
4016
3157
|
debug$f("Setting block property");
|
|
4017
|
-
const {
|
|
4018
|
-
children
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
...prevRest
|
|
4023
|
-
} = block || {
|
|
3158
|
+
const _a = value, {
|
|
3159
|
+
children
|
|
3160
|
+
} = _a, nextRest = __objRest$2(_a, [
|
|
3161
|
+
"children"
|
|
3162
|
+
]), _b = block || {
|
|
4024
3163
|
children: void 0
|
|
4025
|
-
}
|
|
3164
|
+
}, prevRest = __objRest$2(_b, [
|
|
3165
|
+
"children"
|
|
3166
|
+
]);
|
|
4026
3167
|
editor.apply({
|
|
4027
3168
|
type: "set_node",
|
|
4028
3169
|
path: blockPath,
|
|
4029
|
-
properties: {
|
|
4030
|
-
...prevRest
|
|
4031
|
-
},
|
|
3170
|
+
properties: __spreadValues$i({}, prevRest),
|
|
4032
3171
|
newProperties: nextRest
|
|
4033
3172
|
}), debug$f("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
4034
3173
|
editor.apply({
|
|
@@ -4045,10 +3184,9 @@ function setPatch(editor, patch) {
|
|
|
4045
3184
|
});
|
|
4046
3185
|
} else if (block && "value" in block) {
|
|
4047
3186
|
const newVal = applyAll([block.value], [patch])[0];
|
|
4048
|
-
return Transforms.setNodes(editor, {
|
|
4049
|
-
...block,
|
|
3187
|
+
return Transforms.setNodes(editor, __spreadProps$d(__spreadValues$i({}, block), {
|
|
4050
3188
|
value: newVal
|
|
4051
|
-
}, {
|
|
3189
|
+
}), {
|
|
4052
3190
|
at: blockPath
|
|
4053
3191
|
}), !0;
|
|
4054
3192
|
}
|
|
@@ -4131,7 +3269,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
4131
3269
|
block,
|
|
4132
3270
|
child,
|
|
4133
3271
|
blockPath,
|
|
4134
|
-
childPath: blockPath
|
|
3272
|
+
childPath: blockPath == null ? void 0 : blockPath.concat(childIndex)
|
|
4135
3273
|
} : {
|
|
4136
3274
|
block,
|
|
4137
3275
|
blockPath,
|
|
@@ -4139,6 +3277,14 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
4139
3277
|
childPath: void 0
|
|
4140
3278
|
};
|
|
4141
3279
|
}
|
|
3280
|
+
var __defProp$h = Object.defineProperty, __defProps$c = Object.defineProperties, __getOwnPropDescs$c = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$h = Object.getOwnPropertySymbols, __hasOwnProp$h = Object.prototype.hasOwnProperty, __propIsEnum$h = Object.prototype.propertyIsEnumerable, __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$h = (a, b) => {
|
|
3281
|
+
for (var prop in b || (b = {}))
|
|
3282
|
+
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3283
|
+
if (__getOwnPropSymbols$h)
|
|
3284
|
+
for (var prop of __getOwnPropSymbols$h(b))
|
|
3285
|
+
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3286
|
+
return a;
|
|
3287
|
+
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
4142
3288
|
const debug$e = debugWithName("plugin:withPatches");
|
|
4143
3289
|
function createWithPatches({
|
|
4144
3290
|
editorActor,
|
|
@@ -4225,10 +3371,9 @@ function createWithPatches({
|
|
|
4225
3371
|
})), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0 && patches.forEach((patch) => {
|
|
4226
3372
|
editorActor.send({
|
|
4227
3373
|
type: "patch",
|
|
4228
|
-
patch: {
|
|
4229
|
-
...patch,
|
|
3374
|
+
patch: __spreadProps$c(__spreadValues$h({}, patch), {
|
|
4230
3375
|
origin: "local"
|
|
4231
|
-
}
|
|
3376
|
+
})
|
|
4232
3377
|
});
|
|
4233
3378
|
}), editor;
|
|
4234
3379
|
}, editor;
|
|
@@ -4339,6 +3484,14 @@ function getNextSpan({
|
|
|
4339
3484
|
}
|
|
4340
3485
|
return nextSpan;
|
|
4341
3486
|
}
|
|
3487
|
+
var __defProp$g = Object.defineProperty, __defProps$b = Object.defineProperties, __getOwnPropDescs$b = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$g = Object.getOwnPropertySymbols, __hasOwnProp$g = Object.prototype.hasOwnProperty, __propIsEnum$g = Object.prototype.propertyIsEnumerable, __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$g = (a, b) => {
|
|
3488
|
+
for (var prop in b || (b = {}))
|
|
3489
|
+
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
3490
|
+
if (__getOwnPropSymbols$g)
|
|
3491
|
+
for (var prop of __getOwnPropSymbols$g(b))
|
|
3492
|
+
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
3493
|
+
return a;
|
|
3494
|
+
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
4342
3495
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
4343
3496
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
4344
3497
|
return function(editor) {
|
|
@@ -4347,12 +3500,19 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4347
3500
|
normalizeNode
|
|
4348
3501
|
} = editor, decorators = types.decorators.map((t) => t.value);
|
|
4349
3502
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3503
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4350
3504
|
const [node, path] = nodeEntry;
|
|
4351
3505
|
if (editor.isTextBlock(node)) {
|
|
4352
3506
|
const children = Node.children(editor, path);
|
|
4353
3507
|
for (const [child, childPath] of children) {
|
|
4354
3508
|
const nextNode = node.children[childPath[1] + 1];
|
|
4355
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) &&
|
|
3509
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (_a = child.marks) != null && _a.every((mark) => {
|
|
3510
|
+
var _a2;
|
|
3511
|
+
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3512
|
+
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3513
|
+
var _a2;
|
|
3514
|
+
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3515
|
+
})) {
|
|
4356
3516
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
4357
3517
|
type: "normalizing"
|
|
4358
3518
|
}), Transforms.mergeNodes(editor, {
|
|
@@ -4390,12 +3550,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4390
3550
|
return;
|
|
4391
3551
|
}
|
|
4392
3552
|
if (editor.isTextSpan(node)) {
|
|
4393
|
-
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks
|
|
3553
|
+
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = (_c = node.marks) == null ? void 0 : _c.filter((mark) => !decorators2.includes(mark));
|
|
4394
3554
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
4395
3555
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
4396
3556
|
type: "normalizing"
|
|
4397
3557
|
}), Transforms.setNodes(editor, {
|
|
4398
|
-
marks: node.marks
|
|
3558
|
+
marks: (_d = node.marks) == null ? void 0 : _d.filter((mark) => decorators2.includes(mark))
|
|
4399
3559
|
}, {
|
|
4400
3560
|
at: path
|
|
4401
3561
|
}), editorActor.send({
|
|
@@ -4408,7 +3568,10 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4408
3568
|
const decorators2 = types.decorators.map((decorator) => decorator.value);
|
|
4409
3569
|
for (const [child, childPath] of Node.children(editor, path))
|
|
4410
3570
|
if (editor.isTextSpan(child)) {
|
|
4411
|
-
const marks = child.marks
|
|
3571
|
+
const marks = (_e = child.marks) != null ? _e : [], orphanedAnnotations = marks.filter((mark) => {
|
|
3572
|
+
var _a2;
|
|
3573
|
+
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3574
|
+
});
|
|
4412
3575
|
if (orphanedAnnotations.length > 0) {
|
|
4413
3576
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
4414
3577
|
type: "normalizing"
|
|
@@ -4426,7 +3589,10 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4426
3589
|
if (editor.isTextSpan(node)) {
|
|
4427
3590
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath);
|
|
4428
3591
|
if (editor.isTextBlock(block)) {
|
|
4429
|
-
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks
|
|
3592
|
+
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = (_f = node.marks) != null ? _f : [], orphanedAnnotations = marks.filter((mark) => {
|
|
3593
|
+
var _a2;
|
|
3594
|
+
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3595
|
+
});
|
|
4430
3596
|
if (orphanedAnnotations.length > 0) {
|
|
4431
3597
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
4432
3598
|
type: "normalizing"
|
|
@@ -4442,7 +3608,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4442
3608
|
}
|
|
4443
3609
|
}
|
|
4444
3610
|
if (editor.isTextBlock(node)) {
|
|
4445
|
-
const markDefs = node.markDefs
|
|
3611
|
+
const markDefs = (_g = node.markDefs) != null ? _g : [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
4446
3612
|
for (const markDef of markDefs)
|
|
4447
3613
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
4448
3614
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -4475,6 +3641,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4475
3641
|
}
|
|
4476
3642
|
normalizeNode(nodeEntry);
|
|
4477
3643
|
}, editor.apply = (op) => {
|
|
3644
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
4478
3645
|
if (isChangingRemotely(editor)) {
|
|
4479
3646
|
apply2(op);
|
|
4480
3647
|
return;
|
|
@@ -4492,17 +3659,17 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4492
3659
|
focus: op.newProperties.focus
|
|
4493
3660
|
});
|
|
4494
3661
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
4495
|
-
const focusSpan = Array.from(Editor.nodes(editor, {
|
|
3662
|
+
const focusSpan = (_a = Array.from(Editor.nodes(editor, {
|
|
4496
3663
|
mode: "lowest",
|
|
4497
3664
|
at: op.properties.focus,
|
|
4498
3665
|
match: (n) => editor.isTextSpan(n),
|
|
4499
3666
|
voids: !1
|
|
4500
|
-
}))[0]
|
|
3667
|
+
}))[0]) == null ? void 0 : _a[0], newFocusSpan = (_b = Array.from(Editor.nodes(editor, {
|
|
4501
3668
|
mode: "lowest",
|
|
4502
3669
|
at: op.newProperties.focus,
|
|
4503
3670
|
match: (n) => editor.isTextSpan(n),
|
|
4504
3671
|
voids: !1
|
|
4505
|
-
}))[0]
|
|
3672
|
+
}))[0]) == null ? void 0 : _b[0], movedToNextSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] + 1 && focusSpan.text.length === op.properties.focus.offset && op.newProperties.focus.offset === 0, movedToPreviousSpan = focusSpan && newFocusSpan && op.newProperties.focus.path[0] === op.properties.focus.path[0] && op.newProperties.focus.path[1] === op.properties.focus.path[1] - 1 && op.properties.focus.offset === 0 && newFocusSpan.text.length === op.newProperties.focus.offset;
|
|
4506
3673
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4507
3674
|
return;
|
|
4508
3675
|
}
|
|
@@ -4518,32 +3685,29 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4518
3685
|
editor,
|
|
4519
3686
|
blockPath,
|
|
4520
3687
|
spanPath: op.path
|
|
4521
|
-
}), previousSpanAnnotations = previousSpan ? previousSpan.marks
|
|
3688
|
+
}), previousSpanAnnotations = previousSpan ? (_c = previousSpan.marks) == null ? void 0 : _c.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4522
3689
|
editor,
|
|
4523
3690
|
blockPath,
|
|
4524
3691
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4525
|
-
}), nextSpanAnnotations = nextSpan ? nextSpan.marks
|
|
4526
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4527
|
-
Transforms.insertNodes(editor, {
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
});
|
|
3692
|
+
}), nextSpanAnnotations = nextSpan ? (_d = nextSpan.marks) == null ? void 0 : _d.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = (_e = previousSpanAnnotations == null ? void 0 : previousSpanAnnotations.filter((annotation) => !(nextSpanAnnotations != null && nextSpanAnnotations.includes(annotation)))) != null ? _e : [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3693
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
|
|
3694
|
+
Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
3695
|
+
marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
|
|
3696
|
+
}));
|
|
4531
3697
|
return;
|
|
4532
3698
|
}
|
|
4533
|
-
const annotationsStarting = nextSpanAnnotations
|
|
4534
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4535
|
-
Transforms.insertNodes(editor, {
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
});
|
|
3699
|
+
const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3700
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
|
|
3701
|
+
Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
3702
|
+
marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
|
|
3703
|
+
}));
|
|
4539
3704
|
return;
|
|
4540
3705
|
}
|
|
4541
|
-
const nextSpanDecorators = nextSpan
|
|
4542
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4543
|
-
Transforms.insertNodes(editor, {
|
|
4544
|
-
...op.node,
|
|
3706
|
+
const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
|
|
3707
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && ((_o = op.node.marks) == null ? void 0 : _o.length) === 0) {
|
|
3708
|
+
Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
4545
3709
|
marks: nextSpanDecorators
|
|
4546
|
-
});
|
|
3710
|
+
}));
|
|
4547
3711
|
return;
|
|
4548
3712
|
}
|
|
4549
3713
|
}
|
|
@@ -4555,12 +3719,12 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4555
3719
|
if (selection && collapsedSelection) {
|
|
4556
3720
|
const [_block, blockPath] = Editor.node(editor, selection, {
|
|
4557
3721
|
depth: 1
|
|
4558
|
-
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
3722
|
+
}), [span, spanPath] = (_p = Array.from(Editor.nodes(editor, {
|
|
4559
3723
|
mode: "lowest",
|
|
4560
3724
|
at: selection.focus,
|
|
4561
3725
|
match: (n) => editor.isTextSpan(n),
|
|
4562
3726
|
voids: !1
|
|
4563
|
-
}))[0]
|
|
3727
|
+
}))[0]) != null ? _p : [void 0, void 0], marks = (_q = span.marks) != null ? _q : [], marksWithoutAnnotations = marks.filter((mark) => decorators.includes(mark)), spanHasAnnotations = marks.length > marksWithoutAnnotations.length, spanIsEmpty = span.text.length === 0, atTheBeginningOfSpan = selection.anchor.offset === 0, atTheEndOfSpan = selection.anchor.offset === span.text.length, previousSpan = getPreviousSpan({
|
|
4564
3728
|
editor,
|
|
4565
3729
|
blockPath,
|
|
4566
3730
|
spanPath
|
|
@@ -4568,7 +3732,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4568
3732
|
editor,
|
|
4569
3733
|
blockPath,
|
|
4570
3734
|
spanPath
|
|
4571
|
-
}), nextSpanAnnotations = nextSpan
|
|
3735
|
+
}), nextSpanAnnotations = (_s = (_r = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _r.filter((mark) => !decorators.includes(mark))) != null ? _s : [], spanAnnotations = marks.filter((mark) => !decorators.includes(mark)), previousSpanHasAnnotations = previousSpan ? (_t = previousSpan.marks) == null ? void 0 : _t.some((mark) => !decorators.includes(mark)) : !1, previousSpanHasSameAnnotations = previousSpan ? (_u = previousSpan.marks) == null ? void 0 : _u.filter((mark) => !decorators.includes(mark)).every((mark) => marks.includes(mark)) : !1, previousSpanHasSameAnnotation = previousSpan ? (_v = previousSpan.marks) == null ? void 0 : _v.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, previousSpanHasSameMarks = previousSpan ? (_w = previousSpan.marks) == null ? void 0 : _w.every((mark) => marks.includes(mark)) : !1, nextSpanSharesSomeAnnotations = spanAnnotations.some((mark) => nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.includes(mark));
|
|
4572
3736
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4573
3737
|
if (atTheBeginningOfSpan) {
|
|
4574
3738
|
if (previousSpanHasSameMarks) {
|
|
@@ -4576,7 +3740,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4576
3740
|
_type: "span",
|
|
4577
3741
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4578
3742
|
text: op.text,
|
|
4579
|
-
marks: previousSpan
|
|
3743
|
+
marks: (_x = previousSpan == null ? void 0 : previousSpan.marks) != null ? _x : []
|
|
4580
3744
|
});
|
|
4581
3745
|
return;
|
|
4582
3746
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4584,7 +3748,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4584
3748
|
_type: "span",
|
|
4585
3749
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4586
3750
|
text: op.text,
|
|
4587
|
-
marks: previousSpan
|
|
3751
|
+
marks: (_y = previousSpan == null ? void 0 : previousSpan.marks) != null ? _y : []
|
|
4588
3752
|
});
|
|
4589
3753
|
return;
|
|
4590
3754
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4606,7 +3770,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4606
3770
|
_type: "span",
|
|
4607
3771
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4608
3772
|
text: op.text,
|
|
4609
|
-
marks: nextSpan
|
|
3773
|
+
marks: (_z = nextSpan == null ? void 0 : nextSpan.marks) != null ? _z : []
|
|
4610
3774
|
});
|
|
4611
3775
|
return;
|
|
4612
3776
|
}
|
|
@@ -4626,7 +3790,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4626
3790
|
_type: "span",
|
|
4627
3791
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4628
3792
|
text: op.text,
|
|
4629
|
-
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks
|
|
3793
|
+
marks: previousSpanHasAnnotations ? [] : ((_A = previousSpan.marks) != null ? _A : []).filter((mark) => decorators.includes(mark))
|
|
4630
3794
|
});
|
|
4631
3795
|
return;
|
|
4632
3796
|
}
|
|
@@ -4639,7 +3803,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4639
3803
|
if (selection && Range.isExpanded(selection)) {
|
|
4640
3804
|
const [block, blockPath] = Editor.node(editor, selection, {
|
|
4641
3805
|
depth: 1
|
|
4642
|
-
}), [span, spanPath] = Array.from(Editor.nodes(editor, {
|
|
3806
|
+
}), [span, spanPath] = (_B = Array.from(Editor.nodes(editor, {
|
|
4643
3807
|
mode: "lowest",
|
|
4644
3808
|
at: {
|
|
4645
3809
|
path: op.path,
|
|
@@ -4647,9 +3811,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4647
3811
|
},
|
|
4648
3812
|
match: (n) => editor.isTextSpan(n),
|
|
4649
3813
|
voids: !1
|
|
4650
|
-
}))[0]
|
|
3814
|
+
}))[0]) != null ? _B : [void 0, void 0];
|
|
4651
3815
|
if (span && block && isPortableTextBlock(block)) {
|
|
4652
|
-
const markDefs = block.markDefs
|
|
3816
|
+
const markDefs = (_C = block.markDefs) != null ? _C : [], marks = (_D = span.marks) != null ? _D : [], spanHasAnnotations = marks.some((mark) => markDefs.find((markDef) => markDef._key === mark)), deletingFromTheEnd = op.offset + op.text.length === span.text.length, deletingAllText = op.offset === 0 && deletingFromTheEnd, previousSpan = getPreviousSpan({
|
|
4653
3817
|
editor,
|
|
4654
3818
|
blockPath,
|
|
4655
3819
|
spanPath
|
|
@@ -4657,11 +3821,9 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4657
3821
|
editor,
|
|
4658
3822
|
blockPath,
|
|
4659
3823
|
spanPath
|
|
4660
|
-
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks
|
|
3824
|
+
}), previousSpanHasSameAnnotation = previousSpan ? (_E = previousSpan.marks) == null ? void 0 : _E.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1, nextSpanHasSameAnnotation = nextSpan ? (_F = nextSpan.marks) == null ? void 0 : _F.some((mark) => !decorators.includes(mark) && marks.includes(mark)) : !1;
|
|
4661
3825
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4662
|
-
const marksWithoutAnnotationMarks = ({
|
|
4663
|
-
...Editor.marks(editor) || {}
|
|
4664
|
-
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
3826
|
+
const marksWithoutAnnotationMarks = (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
|
|
4665
3827
|
Editor.withoutNormalizing(editor, () => {
|
|
4666
3828
|
apply2(op), Transforms.setNodes(editor, {
|
|
4667
3829
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4694,6 +3856,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
4694
3856
|
const addDecoratorActionImplementation = ({
|
|
4695
3857
|
action
|
|
4696
3858
|
}) => {
|
|
3859
|
+
var _a;
|
|
4697
3860
|
const editor = action.editor, mark = action.decorator;
|
|
4698
3861
|
if (editor.selection) {
|
|
4699
3862
|
if (Range.isExpanded(editor.selection)) {
|
|
@@ -4706,7 +3869,10 @@ const addDecoratorActionImplementation = ({
|
|
|
4706
3869
|
at: editor.selection,
|
|
4707
3870
|
match: Text.isText
|
|
4708
3871
|
})] : [];
|
|
4709
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) =>
|
|
3872
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
3873
|
+
var _a2;
|
|
3874
|
+
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
3875
|
+
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4710
3876
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4711
3877
|
Transforms.setNodes(editor, {
|
|
4712
3878
|
marks
|
|
@@ -4722,7 +3888,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4722
3888
|
depth: 1
|
|
4723
3889
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4724
3890
|
if (lonelyEmptySpan) {
|
|
4725
|
-
const existingMarks = lonelyEmptySpan.marks
|
|
3891
|
+
const existingMarks = (_a = lonelyEmptySpan.marks) != null ? _a : [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4726
3892
|
Transforms.setNodes(editor, {
|
|
4727
3893
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4728
3894
|
}, {
|
|
@@ -4730,12 +3896,9 @@ const addDecoratorActionImplementation = ({
|
|
|
4730
3896
|
match: (node) => editor.isTextSpan(node)
|
|
4731
3897
|
});
|
|
4732
3898
|
} else {
|
|
4733
|
-
const existingMarks = {
|
|
4734
|
-
...Editor.marks(editor) || {}
|
|
4735
|
-
}.marks || [], marks = {
|
|
4736
|
-
...Editor.marks(editor) || {},
|
|
3899
|
+
const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
|
|
4737
3900
|
marks: [...existingMarks, mark]
|
|
4738
|
-
};
|
|
3901
|
+
});
|
|
4739
3902
|
editor.marks = marks;
|
|
4740
3903
|
}
|
|
4741
3904
|
}
|
|
@@ -4744,6 +3907,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4744
3907
|
}, removeDecoratorActionImplementation = ({
|
|
4745
3908
|
action
|
|
4746
3909
|
}) => {
|
|
3910
|
+
var _a;
|
|
4747
3911
|
const editor = action.editor, mark = action.decorator, {
|
|
4748
3912
|
selection
|
|
4749
3913
|
} = editor;
|
|
@@ -4770,7 +3934,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4770
3934
|
depth: 1
|
|
4771
3935
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4772
3936
|
if (lonelyEmptySpan) {
|
|
4773
|
-
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks
|
|
3937
|
+
const existingMarksWithoutDecorator = ((_a = lonelyEmptySpan.marks) != null ? _a : []).filter((existingMark) => existingMark !== mark);
|
|
4774
3938
|
Transforms.setNodes(editor, {
|
|
4775
3939
|
marks: existingMarksWithoutDecorator
|
|
4776
3940
|
}, {
|
|
@@ -4778,12 +3942,9 @@ const addDecoratorActionImplementation = ({
|
|
|
4778
3942
|
match: (node) => editor.isTextSpan(node)
|
|
4779
3943
|
});
|
|
4780
3944
|
} else {
|
|
4781
|
-
const existingMarks = {
|
|
4782
|
-
...Editor.marks(editor) || {}
|
|
4783
|
-
}.marks || [], marks = {
|
|
4784
|
-
...Editor.marks(editor) || {},
|
|
3945
|
+
const existingMarks = __spreadValues$g({}, Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, Editor.marks(editor) || {}), {
|
|
4785
3946
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4786
|
-
};
|
|
3947
|
+
});
|
|
4787
3948
|
editor.marks = {
|
|
4788
3949
|
marks: marks.marks,
|
|
4789
3950
|
_type: "span"
|
|
@@ -4802,11 +3963,10 @@ function isDecoratorActive({
|
|
|
4802
3963
|
at: editor.selection
|
|
4803
3964
|
}));
|
|
4804
3965
|
return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
3966
|
+
var _a;
|
|
4805
3967
|
const [node] = n;
|
|
4806
|
-
return node.marks
|
|
4807
|
-
}) : ({
|
|
4808
|
-
...Editor.marks(editor) || {}
|
|
4809
|
-
}.marks || []).includes(decorator);
|
|
3968
|
+
return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
|
|
3969
|
+
}) : (__spreadValues$g({}, Editor.marks(editor) || {}).marks || []).includes(decorator);
|
|
4810
3970
|
}
|
|
4811
3971
|
const toggleDecoratorActionImplementation = ({
|
|
4812
3972
|
context,
|
|
@@ -4864,6 +4024,14 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4864
4024
|
}, editor;
|
|
4865
4025
|
};
|
|
4866
4026
|
}
|
|
4027
|
+
var __defProp$f = Object.defineProperty, __defProps$a = Object.defineProperties, __getOwnPropDescs$a = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$f = Object.getOwnPropertySymbols, __hasOwnProp$f = Object.prototype.hasOwnProperty, __propIsEnum$f = Object.prototype.propertyIsEnumerable, __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$f = (a, b) => {
|
|
4028
|
+
for (var prop in b || (b = {}))
|
|
4029
|
+
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4030
|
+
if (__getOwnPropSymbols$f)
|
|
4031
|
+
for (var prop of __getOwnPropSymbols$f(b))
|
|
4032
|
+
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4033
|
+
return a;
|
|
4034
|
+
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4867
4035
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4868
4036
|
function createWithSchemaTypes({
|
|
4869
4037
|
editorActor,
|
|
@@ -4881,11 +4049,10 @@ function createWithSchemaTypes({
|
|
|
4881
4049
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4882
4050
|
editorActor.send({
|
|
4883
4051
|
type: "normalizing"
|
|
4884
|
-
}), Transforms.setNodes(editor, {
|
|
4885
|
-
...span,
|
|
4052
|
+
}), Transforms.setNodes(editor, __spreadProps$a(__spreadValues$f({}, span), {
|
|
4886
4053
|
_type: schemaTypes.span.name,
|
|
4887
4054
|
_key: key
|
|
4888
|
-
}, {
|
|
4055
|
+
}), {
|
|
4889
4056
|
at: path
|
|
4890
4057
|
}), editorActor.send({
|
|
4891
4058
|
type: "done normalizing"
|
|
@@ -4910,6 +4077,14 @@ function createWithSchemaTypes({
|
|
|
4910
4077
|
}, editor;
|
|
4911
4078
|
};
|
|
4912
4079
|
}
|
|
4080
|
+
var __defProp$e = Object.defineProperty, __defProps$9 = Object.defineProperties, __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$e = Object.getOwnPropertySymbols, __hasOwnProp$e = Object.prototype.hasOwnProperty, __propIsEnum$e = Object.prototype.propertyIsEnumerable, __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$e = (a, b) => {
|
|
4081
|
+
for (var prop in b || (b = {}))
|
|
4082
|
+
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4083
|
+
if (__getOwnPropSymbols$e)
|
|
4084
|
+
for (var prop of __getOwnPropSymbols$e(b))
|
|
4085
|
+
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4086
|
+
return a;
|
|
4087
|
+
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4913
4088
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4914
4089
|
function createWithUtils({
|
|
4915
4090
|
editorActor,
|
|
@@ -4933,29 +4108,26 @@ function createWithUtils({
|
|
|
4933
4108
|
} = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
4934
4109
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4935
4110
|
debug$8("pteExpandToWord: Expanding to focused word"), Transforms.setSelection(editor, {
|
|
4936
|
-
anchor: {
|
|
4937
|
-
...selection.anchor,
|
|
4111
|
+
anchor: __spreadProps$9(__spreadValues$e({}, selection.anchor), {
|
|
4938
4112
|
offset: newStartOffset
|
|
4939
|
-
},
|
|
4940
|
-
focus: {
|
|
4941
|
-
...selection.focus,
|
|
4113
|
+
}),
|
|
4114
|
+
focus: __spreadProps$9(__spreadValues$e({}, selection.focus), {
|
|
4942
4115
|
offset: newEndOffset
|
|
4943
|
-
}
|
|
4116
|
+
})
|
|
4944
4117
|
});
|
|
4945
4118
|
return;
|
|
4946
4119
|
}
|
|
4947
4120
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4948
4121
|
}
|
|
4949
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4122
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$e(__spreadValues$e({
|
|
4950
4123
|
_type: schemaTypes.block.name,
|
|
4951
4124
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4952
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
} : {},
|
|
4125
|
+
style: schemaTypes.styles[0].value || "normal"
|
|
4126
|
+
}, options.listItem ? {
|
|
4127
|
+
listItem: options.listItem
|
|
4128
|
+
} : {}), options.level ? {
|
|
4129
|
+
level: options.level
|
|
4130
|
+
} : {}), {
|
|
4959
4131
|
markDefs: [],
|
|
4960
4132
|
children: [{
|
|
4961
4133
|
_type: "span",
|
|
@@ -4965,7 +4137,7 @@ function createWithUtils({
|
|
|
4965
4137
|
value
|
|
4966
4138
|
}) => value === decorator))
|
|
4967
4139
|
}]
|
|
4968
|
-
}], {
|
|
4140
|
+
})], {
|
|
4969
4141
|
schemaTypes
|
|
4970
4142
|
})[0], editor;
|
|
4971
4143
|
};
|
|
@@ -5011,6 +4183,14 @@ function createSlateEditor(config) {
|
|
|
5011
4183
|
};
|
|
5012
4184
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
5013
4185
|
}
|
|
4186
|
+
var __defProp$d = Object.defineProperty, __defProps$8 = Object.defineProperties, __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$d = Object.getOwnPropertySymbols, __hasOwnProp$d = Object.prototype.hasOwnProperty, __propIsEnum$d = Object.prototype.propertyIsEnumerable, __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$d = (a, b) => {
|
|
4187
|
+
for (var prop in b || (b = {}))
|
|
4188
|
+
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4189
|
+
if (__getOwnPropSymbols$d)
|
|
4190
|
+
for (var prop of __getOwnPropSymbols$d(b))
|
|
4191
|
+
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4192
|
+
return a;
|
|
4193
|
+
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
5014
4194
|
const toggleListItemActionImplementation = ({
|
|
5015
4195
|
context,
|
|
5016
4196
|
action
|
|
@@ -5020,16 +4200,14 @@ const toggleListItemActionImplementation = ({
|
|
|
5020
4200
|
listItem: action.listItem
|
|
5021
4201
|
}) ? removeListItemActionImplementation({
|
|
5022
4202
|
context,
|
|
5023
|
-
action: {
|
|
5024
|
-
...action,
|
|
4203
|
+
action: __spreadProps$8(__spreadValues$d({}, action), {
|
|
5025
4204
|
type: "list item.remove"
|
|
5026
|
-
}
|
|
4205
|
+
})
|
|
5027
4206
|
}) : addListItemActionImplementation({
|
|
5028
4207
|
context,
|
|
5029
|
-
action: {
|
|
5030
|
-
...action,
|
|
4208
|
+
action: __spreadProps$8(__spreadValues$d({}, action), {
|
|
5031
4209
|
type: "list item.add"
|
|
5032
|
-
}
|
|
4210
|
+
})
|
|
5033
4211
|
});
|
|
5034
4212
|
}, removeListItemActionImplementation = ({
|
|
5035
4213
|
context,
|
|
@@ -5075,6 +4253,14 @@ function isListItemActive({
|
|
|
5075
4253
|
})];
|
|
5076
4254
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
5077
4255
|
}
|
|
4256
|
+
var __defProp$c = Object.defineProperty, __defProps$7 = Object.defineProperties, __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$c = Object.getOwnPropertySymbols, __hasOwnProp$c = Object.prototype.hasOwnProperty, __propIsEnum$c = Object.prototype.propertyIsEnumerable, __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$c = (a, b) => {
|
|
4257
|
+
for (var prop in b || (b = {}))
|
|
4258
|
+
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4259
|
+
if (__getOwnPropSymbols$c)
|
|
4260
|
+
for (var prop of __getOwnPropSymbols$c(b))
|
|
4261
|
+
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4262
|
+
return a;
|
|
4263
|
+
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
5078
4264
|
const toggleStyleActionImplementation = ({
|
|
5079
4265
|
context,
|
|
5080
4266
|
action
|
|
@@ -5084,16 +4270,14 @@ const toggleStyleActionImplementation = ({
|
|
|
5084
4270
|
style: action.style
|
|
5085
4271
|
}) ? removeStyleActionImplementation({
|
|
5086
4272
|
context,
|
|
5087
|
-
action: {
|
|
5088
|
-
...action,
|
|
4273
|
+
action: __spreadProps$7(__spreadValues$c({}, action), {
|
|
5089
4274
|
type: "style.remove"
|
|
5090
|
-
}
|
|
4275
|
+
})
|
|
5091
4276
|
}) : addStyleActionImplementation({
|
|
5092
4277
|
context,
|
|
5093
|
-
action: {
|
|
5094
|
-
...action,
|
|
4278
|
+
action: __spreadProps$7(__spreadValues$c({}, action), {
|
|
5095
4279
|
type: "style.add"
|
|
5096
|
-
}
|
|
4280
|
+
})
|
|
5097
4281
|
});
|
|
5098
4282
|
}, removeStyleActionImplementation = ({
|
|
5099
4283
|
context,
|
|
@@ -5140,6 +4324,14 @@ function isStyleActive({
|
|
|
5140
4324
|
})];
|
|
5141
4325
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
5142
4326
|
}
|
|
4327
|
+
var __defProp$b = Object.defineProperty, __getOwnPropSymbols$b = Object.getOwnPropertySymbols, __hasOwnProp$b = Object.prototype.hasOwnProperty, __propIsEnum$b = Object.prototype.propertyIsEnumerable, __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$b = (a, b) => {
|
|
4328
|
+
for (var prop in b || (b = {}))
|
|
4329
|
+
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4330
|
+
if (__getOwnPropSymbols$b)
|
|
4331
|
+
for (var prop of __getOwnPropSymbols$b(b))
|
|
4332
|
+
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4333
|
+
return a;
|
|
4334
|
+
};
|
|
5143
4335
|
const debug$6 = debugWithName("API:editable");
|
|
5144
4336
|
function createEditableAPI(editor, editorActor) {
|
|
5145
4337
|
const types = editorActor.getSnapshot().context.schema;
|
|
@@ -5202,9 +4394,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5202
4394
|
return console.warn(err), !1;
|
|
5203
4395
|
}
|
|
5204
4396
|
},
|
|
5205
|
-
marks: () => ({
|
|
5206
|
-
...Editor.marks(editor) || {}
|
|
5207
|
-
}).marks || [],
|
|
4397
|
+
marks: () => __spreadValues$b({}, Editor.marks(editor) || {}).marks || [],
|
|
5208
4398
|
undo: () => editor.undo(),
|
|
5209
4399
|
redo: () => editor.redo(),
|
|
5210
4400
|
select: (selection) => {
|
|
@@ -5226,6 +4416,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5226
4416
|
}
|
|
5227
4417
|
},
|
|
5228
4418
|
insertChild: (type, value) => {
|
|
4419
|
+
var _a, _b, _c;
|
|
5229
4420
|
if (type.name !== types.span.name)
|
|
5230
4421
|
return editorActor.send({
|
|
5231
4422
|
type: "behavior event",
|
|
@@ -5237,7 +4428,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5237
4428
|
}
|
|
5238
4429
|
},
|
|
5239
4430
|
editor
|
|
5240
|
-
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)
|
|
4431
|
+
}), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _a.focus.path) != null ? _b : [];
|
|
5241
4432
|
if (!editor.selection)
|
|
5242
4433
|
throw new Error("The editor has no selection");
|
|
5243
4434
|
const [focusBlock] = Array.from(Editor.nodes(editor, {
|
|
@@ -5251,11 +4442,10 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5251
4442
|
const child = toSlateValue([{
|
|
5252
4443
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5253
4444
|
_type: types.block.name,
|
|
5254
|
-
children: [{
|
|
4445
|
+
children: [__spreadValues$b({
|
|
5255
4446
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5256
|
-
_type: type.name
|
|
5257
|
-
|
|
5258
|
-
}]
|
|
4447
|
+
_type: type.name
|
|
4448
|
+
}, value || {})]
|
|
5259
4449
|
}], {
|
|
5260
4450
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5261
4451
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
|
|
@@ -5265,27 +4455,30 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5265
4455
|
})), Transforms.insertNodes(editor, child, {
|
|
5266
4456
|
select: !0,
|
|
5267
4457
|
at: editor.selection
|
|
5268
|
-
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)
|
|
4458
|
+
}), editor.onChange(), ((_c = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _c.focus.path) || [];
|
|
5269
4459
|
},
|
|
5270
|
-
insertBlock: (type, value) =>
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
type: "
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
4460
|
+
insertBlock: (type, value) => {
|
|
4461
|
+
var _a, _b;
|
|
4462
|
+
return editorActor.send({
|
|
4463
|
+
type: "behavior event",
|
|
4464
|
+
behaviorEvent: {
|
|
4465
|
+
type: "insert.block object",
|
|
4466
|
+
blockObject: {
|
|
4467
|
+
name: type.name,
|
|
4468
|
+
value
|
|
4469
|
+
},
|
|
4470
|
+
placement: "auto"
|
|
5277
4471
|
},
|
|
5278
|
-
|
|
5279
|
-
},
|
|
5280
|
-
|
|
5281
|
-
}), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? []),
|
|
4472
|
+
editor
|
|
4473
|
+
}), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)) == null ? void 0 : _a.focus.path) != null ? _b : [];
|
|
4474
|
+
},
|
|
5282
4475
|
hasBlockStyle: (style) => {
|
|
5283
4476
|
try {
|
|
5284
4477
|
return isStyleActive({
|
|
5285
4478
|
editor,
|
|
5286
4479
|
style
|
|
5287
4480
|
});
|
|
5288
|
-
} catch {
|
|
4481
|
+
} catch (e) {
|
|
5289
4482
|
return !1;
|
|
5290
4483
|
}
|
|
5291
4484
|
},
|
|
@@ -5295,7 +4488,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5295
4488
|
editor,
|
|
5296
4489
|
listItem
|
|
5297
4490
|
});
|
|
5298
|
-
} catch {
|
|
4491
|
+
} catch (e) {
|
|
5299
4492
|
return !1;
|
|
5300
4493
|
}
|
|
5301
4494
|
},
|
|
@@ -5340,11 +4533,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5340
4533
|
match: (n) => n._key === element._key
|
|
5341
4534
|
}) || [])[0] || [void 0];
|
|
5342
4535
|
node = ReactEditor.toDOMNode(editor, item);
|
|
5343
|
-
} catch {
|
|
4536
|
+
} catch (e) {
|
|
5344
4537
|
}
|
|
5345
4538
|
return node;
|
|
5346
4539
|
},
|
|
5347
4540
|
activeAnnotations: () => {
|
|
4541
|
+
var _a;
|
|
5348
4542
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
5349
4543
|
return [];
|
|
5350
4544
|
try {
|
|
@@ -5356,12 +4550,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5356
4550
|
const [block] = Editor.node(editor, path, {
|
|
5357
4551
|
depth: 1
|
|
5358
4552
|
});
|
|
5359
|
-
editor.isTextBlock(block) && block.markDefs
|
|
4553
|
+
editor.isTextBlock(block) && ((_a = block.markDefs) == null || _a.forEach((def) => {
|
|
5360
4554
|
Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
5361
|
-
});
|
|
4555
|
+
}));
|
|
5362
4556
|
}
|
|
5363
4557
|
return activeAnnotations;
|
|
5364
|
-
} catch {
|
|
4558
|
+
} catch (e) {
|
|
5365
4559
|
return [];
|
|
5366
4560
|
}
|
|
5367
4561
|
},
|
|
@@ -5383,7 +4577,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5383
4577
|
type: "annotation.add",
|
|
5384
4578
|
annotation: {
|
|
5385
4579
|
name: type.name,
|
|
5386
|
-
value: value
|
|
4580
|
+
value: value != null ? value : {}
|
|
5387
4581
|
},
|
|
5388
4582
|
editor
|
|
5389
4583
|
}
|
|
@@ -5396,7 +4590,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5396
4590
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
5397
4591
|
throw new Error("Invalid range");
|
|
5398
4592
|
if (range) {
|
|
5399
|
-
if (!options
|
|
4593
|
+
if (!(options != null && options.mode) || (options == null ? void 0 : options.mode) === "selected") {
|
|
5400
4594
|
debug$6("Deleting content in selection"), Transforms.delete(editor, {
|
|
5401
4595
|
at: range,
|
|
5402
4596
|
hanging: !0,
|
|
@@ -5404,11 +4598,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5404
4598
|
}), editor.onChange();
|
|
5405
4599
|
return;
|
|
5406
4600
|
}
|
|
5407
|
-
options
|
|
4601
|
+
(options == null ? void 0 : options.mode) === "blocks" && (debug$6("Deleting blocks touched by selection"), Transforms.removeNodes(editor, {
|
|
5408
4602
|
at: range,
|
|
5409
4603
|
voids: !0,
|
|
5410
4604
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && Element$1.isElement(node)
|
|
5411
|
-
})), options
|
|
4605
|
+
})), (options == null ? void 0 : options.mode) === "children" && (debug$6("Deleting children touched by selection"), Transforms.removeNodes(editor, {
|
|
5412
4606
|
at: range,
|
|
5413
4607
|
voids: !0,
|
|
5414
4608
|
match: (node) => node._type === types.span.name || // Text children
|
|
@@ -5465,15 +4659,26 @@ function isAnnotationActive({
|
|
|
5465
4659
|
at: editor.selection,
|
|
5466
4660
|
match: (node) => Text.isText(node)
|
|
5467
4661
|
})];
|
|
5468
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
4662
|
+
if (spans.length === 0 || spans.some(([span]) => {
|
|
4663
|
+
var _a;
|
|
4664
|
+
return !isPortableTextSpan$1(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
4665
|
+
})) return !1;
|
|
5469
4666
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5470
4667
|
const [block] = Editor.node(editor, path, {
|
|
5471
4668
|
depth: 1
|
|
5472
4669
|
});
|
|
5473
4670
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5474
4671
|
}, []);
|
|
5475
|
-
return spans.every(([span]) =>
|
|
5476
|
-
|
|
4672
|
+
return spans.every(([span]) => {
|
|
4673
|
+
var _a;
|
|
4674
|
+
if (!isPortableTextSpan$1(span)) return !1;
|
|
4675
|
+
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
4676
|
+
var _a2;
|
|
4677
|
+
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
4678
|
+
});
|
|
4679
|
+
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
4680
|
+
});
|
|
4681
|
+
} catch (e) {
|
|
5477
4682
|
return !1;
|
|
5478
4683
|
}
|
|
5479
4684
|
}
|
|
@@ -5481,6 +4686,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5481
4686
|
context,
|
|
5482
4687
|
action
|
|
5483
4688
|
}) => {
|
|
4689
|
+
var _a, _b;
|
|
5484
4690
|
const editor = action.editor, {
|
|
5485
4691
|
selection: originalSelection
|
|
5486
4692
|
} = editor;
|
|
@@ -5498,13 +4704,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5498
4704
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5499
4705
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5500
4706
|
continue;
|
|
5501
|
-
const annotationKey = context.keyGenerator(), markDefs = block.markDefs
|
|
4707
|
+
const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
|
|
5502
4708
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (Transforms.setNodes(editor, {
|
|
5503
|
-
markDefs: [...markDefs, {
|
|
4709
|
+
markDefs: [...markDefs, __spreadValues$b({
|
|
5504
4710
|
_type: action.annotation.name,
|
|
5505
|
-
_key: annotationKey
|
|
5506
|
-
|
|
5507
|
-
}]
|
|
4711
|
+
_key: annotationKey
|
|
4712
|
+
}, action.annotation.value)]
|
|
5508
4713
|
}, {
|
|
5509
4714
|
at: blockPath
|
|
5510
4715
|
}), markDefPath = [{
|
|
@@ -5519,7 +4724,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5519
4724
|
for (const [span, path] of children) {
|
|
5520
4725
|
if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
|
|
5521
4726
|
continue;
|
|
5522
|
-
const marks = span.marks
|
|
4727
|
+
const marks = (_b = span.marks) != null ? _b : [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5523
4728
|
Transforms.setNodes(editor, {
|
|
5524
4729
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5525
4730
|
}, {
|
|
@@ -5541,6 +4746,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5541
4746
|
}, removeAnnotationActionImplementation = ({
|
|
5542
4747
|
action
|
|
5543
4748
|
}) => {
|
|
4749
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
5544
4750
|
const editor = action.editor;
|
|
5545
4751
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5546
4752
|
if (Range.isCollapsed(editor.selection)) {
|
|
@@ -5549,12 +4755,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5549
4755
|
});
|
|
5550
4756
|
if (!editor.isTextBlock(block))
|
|
5551
4757
|
return;
|
|
5552
|
-
const potentialAnnotations = (block.markDefs
|
|
4758
|
+
const potentialAnnotations = ((_a = block.markDefs) != null ? _a : []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
|
|
5553
4759
|
depth: 2
|
|
5554
4760
|
});
|
|
5555
4761
|
if (!editor.isTextSpan(selectedChild))
|
|
5556
4762
|
return;
|
|
5557
|
-
const annotationToRemove = selectedChild.marks
|
|
4763
|
+
const annotationToRemove = (_b = selectedChild.marks) == null ? void 0 : _b.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5558
4764
|
if (!annotationToRemove)
|
|
5559
4765
|
return;
|
|
5560
4766
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5562,20 +4768,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5562
4768
|
reverse: !0
|
|
5563
4769
|
}))
|
|
5564
4770
|
if (editor.isTextSpan(child) && Path.isBefore(childPath, selectedChildPath))
|
|
5565
|
-
if (child.marks
|
|
4771
|
+
if ((_c = child.marks) != null && _c.includes(annotationToRemove))
|
|
5566
4772
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5567
4773
|
else
|
|
5568
4774
|
break;
|
|
5569
4775
|
const nextSpansWithSameAnnotation = [];
|
|
5570
4776
|
for (const [child, childPath] of Node.children(editor, blockPath))
|
|
5571
4777
|
if (editor.isTextSpan(child) && Path.isAfter(childPath, selectedChildPath))
|
|
5572
|
-
if (child.marks
|
|
4778
|
+
if ((_d = child.marks) != null && _d.includes(annotationToRemove))
|
|
5573
4779
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5574
4780
|
else
|
|
5575
4781
|
break;
|
|
5576
4782
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5577
4783
|
Transforms.setNodes(editor, {
|
|
5578
|
-
marks: child.marks
|
|
4784
|
+
marks: (_e = child.marks) == null ? void 0 : _e.filter((mark) => mark !== annotationToRemove)
|
|
5579
4785
|
}, {
|
|
5580
4786
|
at: childPath
|
|
5581
4787
|
});
|
|
@@ -5594,7 +4800,10 @@ const addAnnotationActionImplementation = ({
|
|
|
5594
4800
|
for (const [child, childPath] of children) {
|
|
5595
4801
|
if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
|
|
5596
4802
|
continue;
|
|
5597
|
-
const markDefs = block.markDefs
|
|
4803
|
+
const markDefs = (_f = block.markDefs) != null ? _f : [], marks = (_g = child.marks) != null ? _g : [], marksWithoutAnnotation = marks.filter((mark) => {
|
|
4804
|
+
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
4805
|
+
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
4806
|
+
});
|
|
5598
4807
|
marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
|
|
5599
4808
|
marks: marksWithoutAnnotation
|
|
5600
4809
|
}, {
|
|
@@ -5637,11 +4846,12 @@ function insertBlock({
|
|
|
5637
4846
|
editor,
|
|
5638
4847
|
schema
|
|
5639
4848
|
}) {
|
|
4849
|
+
var _a;
|
|
5640
4850
|
if (editor.selection) {
|
|
5641
|
-
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(editor, {
|
|
4851
|
+
const [focusBlock, focusBlockPath] = (_a = Array.from(Editor.nodes(editor, {
|
|
5642
4852
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5643
4853
|
match: (n) => !Editor.isEditor(n)
|
|
5644
|
-
}))[0]
|
|
4854
|
+
}))[0]) != null ? _a : [void 0, void 0];
|
|
5645
4855
|
if (placement === "after") {
|
|
5646
4856
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5647
4857
|
Transforms.insertNodes(editor, block, {
|
|
@@ -5673,15 +4883,22 @@ function insertBlock({
|
|
|
5673
4883
|
});
|
|
5674
4884
|
}
|
|
5675
4885
|
}
|
|
4886
|
+
var __defProp$a = Object.defineProperty, __getOwnPropSymbols$a = Object.getOwnPropertySymbols, __hasOwnProp$a = Object.prototype.hasOwnProperty, __propIsEnum$a = Object.prototype.propertyIsEnumerable, __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$a = (a, b) => {
|
|
4887
|
+
for (var prop in b || (b = {}))
|
|
4888
|
+
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4889
|
+
if (__getOwnPropSymbols$a)
|
|
4890
|
+
for (var prop of __getOwnPropSymbols$a(b))
|
|
4891
|
+
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4892
|
+
return a;
|
|
4893
|
+
};
|
|
5676
4894
|
const insertBlockObjectActionImplementation = ({
|
|
5677
4895
|
context,
|
|
5678
4896
|
action
|
|
5679
4897
|
}) => {
|
|
5680
|
-
const block = toSlateValue([{
|
|
4898
|
+
const block = toSlateValue([__spreadValues$a({
|
|
5681
4899
|
_key: context.keyGenerator(),
|
|
5682
|
-
_type: action.blockObject.name
|
|
5683
|
-
|
|
5684
|
-
}], {
|
|
4900
|
+
_type: action.blockObject.name
|
|
4901
|
+
}, action.blockObject.value ? action.blockObject.value : {})], {
|
|
5685
4902
|
schemaTypes: context.schema
|
|
5686
4903
|
})[0];
|
|
5687
4904
|
insertBlock({
|
|
@@ -5690,19 +4907,29 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5690
4907
|
editor: action.editor,
|
|
5691
4908
|
schema: context.schema
|
|
5692
4909
|
});
|
|
5693
|
-
}
|
|
4910
|
+
};
|
|
4911
|
+
var __defProp$9 = Object.defineProperty, __defProps$6 = Object.defineProperties, __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$9 = Object.getOwnPropertySymbols, __hasOwnProp$9 = Object.prototype.hasOwnProperty, __propIsEnum$9 = Object.prototype.propertyIsEnumerable, __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$9 = (a, b) => {
|
|
4912
|
+
for (var prop in b || (b = {}))
|
|
4913
|
+
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
4914
|
+
if (__getOwnPropSymbols$9)
|
|
4915
|
+
for (var prop of __getOwnPropSymbols$9(b))
|
|
4916
|
+
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
4917
|
+
return a;
|
|
4918
|
+
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
4919
|
+
const insertBreakActionImplementation = ({
|
|
5694
4920
|
context,
|
|
5695
4921
|
action
|
|
5696
4922
|
}) => {
|
|
4923
|
+
var _a, _b, _c, _d, _e;
|
|
5697
4924
|
const keyGenerator = context.keyGenerator, schema = context.schema, editor = action.editor;
|
|
5698
4925
|
if (!editor.selection)
|
|
5699
4926
|
return;
|
|
5700
|
-
const [focusSpan] = Array.from(Editor.nodes(editor, {
|
|
4927
|
+
const [focusSpan] = (_a = Array.from(Editor.nodes(editor, {
|
|
5701
4928
|
mode: "lowest",
|
|
5702
4929
|
at: editor.selection.focus,
|
|
5703
4930
|
match: (n) => editor.isTextSpan(n),
|
|
5704
4931
|
voids: !1
|
|
5705
|
-
}))[0]
|
|
4932
|
+
}))[0]) != null ? _a : [void 0], focusDecorators = (_c = (_b = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _b.filter((mark) => schema.decorators.some((decorator) => decorator.value === mark))) != null ? _c : [], focusAnnotations = (_e = (_d = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _d.filter((mark) => !schema.decorators.some((decorator) => decorator.value === mark))) != null ? _e : [], anchorBlockPath = editor.selection.anchor.path.slice(0, 1), focusBlockPath = editor.selection.focus.path.slice(0, 1), focusBlock = Node.descendant(editor, focusBlockPath);
|
|
5706
4933
|
if (editor.isTextBlock(focusBlock)) {
|
|
5707
4934
|
const [start, end] = Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual(start, {
|
|
5708
4935
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5741,6 +4968,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5741
4968
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5742
4969
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5743
4970
|
Editor.withoutNormalizing(editor, () => {
|
|
4971
|
+
var _a2;
|
|
5744
4972
|
if (!editor.selection)
|
|
5745
4973
|
return;
|
|
5746
4974
|
Transforms.splitNodes(editor, {
|
|
@@ -5763,20 +4991,28 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5763
4991
|
for (const [child, childPath] of children) {
|
|
5764
4992
|
if (!editor.isTextSpan(child))
|
|
5765
4993
|
continue;
|
|
5766
|
-
const marks = child.marks
|
|
4994
|
+
const marks = (_a2 = child.marks) != null ? _a2 : [];
|
|
5767
4995
|
for (const mark of marks)
|
|
5768
|
-
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5769
|
-
|
|
4996
|
+
schema.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => {
|
|
4997
|
+
var _a3;
|
|
4998
|
+
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
4999
|
+
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
5000
|
+
const newMarks = marks.map((mark) => {
|
|
5001
|
+
var _a3;
|
|
5002
|
+
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
5003
|
+
});
|
|
5770
5004
|
isEqual(marks, newMarks) || Transforms.setNodes(editor, {
|
|
5771
5005
|
marks: newMarks
|
|
5772
5006
|
}, {
|
|
5773
5007
|
at: childPath
|
|
5774
5008
|
});
|
|
5775
5009
|
}
|
|
5776
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) =>
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5010
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
5011
|
+
var _a3;
|
|
5012
|
+
return __spreadProps$6(__spreadValues$9({}, markDef), {
|
|
5013
|
+
_key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
|
|
5014
|
+
});
|
|
5015
|
+
});
|
|
5780
5016
|
isEqual(nextNode.markDefs, newMarkDefs) || Transforms.setNodes(editor, {
|
|
5781
5017
|
markDefs: newMarkDefs
|
|
5782
5018
|
}, {
|
|
@@ -5797,15 +5033,24 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5797
5033
|
}) => {
|
|
5798
5034
|
insertBreakActionImplementation({
|
|
5799
5035
|
context,
|
|
5800
|
-
action: {
|
|
5801
|
-
...action,
|
|
5036
|
+
action: __spreadProps$6(__spreadValues$9({}, action), {
|
|
5802
5037
|
type: "insert.break"
|
|
5803
|
-
}
|
|
5038
|
+
})
|
|
5804
5039
|
});
|
|
5805
|
-
}
|
|
5040
|
+
};
|
|
5041
|
+
var __defProp$8 = Object.defineProperty, __getOwnPropSymbols$8 = Object.getOwnPropertySymbols, __hasOwnProp$8 = Object.prototype.hasOwnProperty, __propIsEnum$8 = Object.prototype.propertyIsEnumerable, __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$8 = (a, b) => {
|
|
5042
|
+
for (var prop in b || (b = {}))
|
|
5043
|
+
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5044
|
+
if (__getOwnPropSymbols$8)
|
|
5045
|
+
for (var prop of __getOwnPropSymbols$8(b))
|
|
5046
|
+
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5047
|
+
return a;
|
|
5048
|
+
};
|
|
5049
|
+
const insertInlineObjectActionImplementation = ({
|
|
5806
5050
|
context,
|
|
5807
5051
|
action
|
|
5808
5052
|
}) => {
|
|
5053
|
+
var _a, _b;
|
|
5809
5054
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5810
5055
|
console.error("Unable to insert unknown inline object");
|
|
5811
5056
|
return;
|
|
@@ -5814,60 +5059,77 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5814
5059
|
console.error("Unable to insert inline object without selection");
|
|
5815
5060
|
return;
|
|
5816
5061
|
}
|
|
5817
|
-
const [focusTextBlock] = Array.from(Editor.nodes(action.editor, {
|
|
5062
|
+
const [focusTextBlock] = (_a = Array.from(Editor.nodes(action.editor, {
|
|
5818
5063
|
at: action.editor.selection.focus.path,
|
|
5819
5064
|
match: (node) => action.editor.isTextBlock(node)
|
|
5820
|
-
})).at(0)
|
|
5065
|
+
})).at(0)) != null ? _a : [void 0, void 0];
|
|
5821
5066
|
if (!focusTextBlock) {
|
|
5822
5067
|
console.error("Unable to perform action without focus text block");
|
|
5823
5068
|
return;
|
|
5824
5069
|
}
|
|
5825
|
-
const
|
|
5070
|
+
const block = toSlateValue([{
|
|
5826
5071
|
_type: context.schema.block.name,
|
|
5827
5072
|
_key: context.keyGenerator(),
|
|
5828
|
-
children: [{
|
|
5073
|
+
children: [__spreadValues$8({
|
|
5829
5074
|
_type: action.inlineObject.name,
|
|
5830
|
-
_key: context.keyGenerator()
|
|
5831
|
-
|
|
5832
|
-
}]
|
|
5075
|
+
_key: context.keyGenerator()
|
|
5076
|
+
}, (_b = action.inlineObject.value) != null ? _b : {})]
|
|
5833
5077
|
}], {
|
|
5834
5078
|
schemaTypes: context.schema
|
|
5835
|
-
}).at(0)
|
|
5079
|
+
}).at(0), child = block == null ? void 0 : block.children.at(0);
|
|
5836
5080
|
if (!child) {
|
|
5837
5081
|
console.error("Unable to insert inline object");
|
|
5838
5082
|
return;
|
|
5839
5083
|
}
|
|
5840
5084
|
Transforms.insertNodes(action.editor, child);
|
|
5841
|
-
}
|
|
5085
|
+
};
|
|
5086
|
+
var __defProp$7 = Object.defineProperty, __getOwnPropSymbols$7 = Object.getOwnPropertySymbols, __hasOwnProp$7 = Object.prototype.hasOwnProperty, __propIsEnum$7 = Object.prototype.propertyIsEnumerable, __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$7 = (a, b) => {
|
|
5087
|
+
for (var prop in b || (b = {}))
|
|
5088
|
+
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5089
|
+
if (__getOwnPropSymbols$7)
|
|
5090
|
+
for (var prop of __getOwnPropSymbols$7(b))
|
|
5091
|
+
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5092
|
+
return a;
|
|
5093
|
+
};
|
|
5094
|
+
const insertSpanActionImplementation = ({
|
|
5842
5095
|
context,
|
|
5843
5096
|
action
|
|
5844
5097
|
}) => {
|
|
5098
|
+
var _a, _b, _c, _d;
|
|
5845
5099
|
if (!action.editor.selection) {
|
|
5846
5100
|
console.error("Unable to perform action without selection", action);
|
|
5847
5101
|
return;
|
|
5848
5102
|
}
|
|
5849
|
-
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
|
|
5103
|
+
const [focusBlock, focusBlockPath] = (_a = Array.from(Editor.nodes(action.editor, {
|
|
5850
5104
|
at: action.editor.selection.focus.path,
|
|
5851
5105
|
match: (node) => action.editor.isTextBlock(node)
|
|
5852
|
-
}))[0]
|
|
5106
|
+
}))[0]) != null ? _a : [void 0, void 0];
|
|
5853
5107
|
if (!focusBlock || !focusBlockPath) {
|
|
5854
5108
|
console.error("Unable to perform action without focus block", action);
|
|
5855
5109
|
return;
|
|
5856
5110
|
}
|
|
5857
|
-
const markDefs = focusBlock.markDefs
|
|
5111
|
+
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$7({
|
|
5858
5112
|
_type: annotation.name,
|
|
5859
|
-
_key: context.keyGenerator()
|
|
5860
|
-
|
|
5861
|
-
})) : void 0;
|
|
5113
|
+
_key: context.keyGenerator()
|
|
5114
|
+
}, annotation.value)) : void 0;
|
|
5862
5115
|
annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
|
|
5863
5116
|
markDefs: [...markDefs, ...annotations]
|
|
5864
5117
|
}), Transforms.insertNodes(action.editor, {
|
|
5865
5118
|
_type: "span",
|
|
5866
5119
|
_key: context.keyGenerator(),
|
|
5867
5120
|
text: action.text,
|
|
5868
|
-
marks: [...annotations
|
|
5121
|
+
marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
|
|
5869
5122
|
});
|
|
5870
|
-
}
|
|
5123
|
+
};
|
|
5124
|
+
var __defProp$6 = Object.defineProperty, __getOwnPropSymbols$6 = Object.getOwnPropertySymbols, __hasOwnProp$6 = Object.prototype.hasOwnProperty, __propIsEnum$6 = Object.prototype.propertyIsEnumerable, __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$6 = (a, b) => {
|
|
5125
|
+
for (var prop in b || (b = {}))
|
|
5126
|
+
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5127
|
+
if (__getOwnPropSymbols$6)
|
|
5128
|
+
for (var prop of __getOwnPropSymbols$6(b))
|
|
5129
|
+
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5130
|
+
return a;
|
|
5131
|
+
};
|
|
5132
|
+
const textBlockSetActionImplementation = ({
|
|
5871
5133
|
action
|
|
5872
5134
|
}) => {
|
|
5873
5135
|
const at = toSlateRange({
|
|
@@ -5880,17 +5142,13 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5880
5142
|
offset: 0
|
|
5881
5143
|
}
|
|
5882
5144
|
}, action.editor);
|
|
5883
|
-
Transforms.setNodes(action.editor, {
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
...action.level ? {
|
|
5891
|
-
level: action.level
|
|
5892
|
-
} : {}
|
|
5893
|
-
}, {
|
|
5145
|
+
Transforms.setNodes(action.editor, __spreadValues$6(__spreadValues$6(__spreadValues$6({}, action.style ? {
|
|
5146
|
+
style: action.style
|
|
5147
|
+
} : {}), action.listItem ? {
|
|
5148
|
+
listItem: action.listItem
|
|
5149
|
+
} : {}), action.level ? {
|
|
5150
|
+
level: action.level
|
|
5151
|
+
} : {}), {
|
|
5894
5152
|
at
|
|
5895
5153
|
});
|
|
5896
5154
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5909,7 +5167,16 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5909
5167
|
Transforms.unsetNodes(action.editor, action.props, {
|
|
5910
5168
|
at
|
|
5911
5169
|
});
|
|
5912
|
-
}
|
|
5170
|
+
};
|
|
5171
|
+
var __defProp$5 = Object.defineProperty, __defProps$5 = Object.defineProperties, __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$5 = Object.getOwnPropertySymbols, __hasOwnProp$5 = Object.prototype.hasOwnProperty, __propIsEnum$5 = Object.prototype.propertyIsEnumerable, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$5 = (a, b) => {
|
|
5172
|
+
for (var prop in b || (b = {}))
|
|
5173
|
+
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5174
|
+
if (__getOwnPropSymbols$5)
|
|
5175
|
+
for (var prop of __getOwnPropSymbols$5(b))
|
|
5176
|
+
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5177
|
+
return a;
|
|
5178
|
+
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5179
|
+
const behaviorActionImplementations = {
|
|
5913
5180
|
"annotation.add": addAnnotationActionImplementation,
|
|
5914
5181
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5915
5182
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5998,15 +5265,15 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5998
5265
|
context,
|
|
5999
5266
|
action
|
|
6000
5267
|
}) => {
|
|
5268
|
+
var _a, _b, _c, _d;
|
|
6001
5269
|
const block = toSlateValue([{
|
|
6002
5270
|
_key: context.keyGenerator(),
|
|
6003
5271
|
_type: context.schema.block.name,
|
|
6004
|
-
style: context.schema.styles[0].value
|
|
5272
|
+
style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
|
|
6005
5273
|
markDefs: [],
|
|
6006
|
-
children: action.textBlock
|
|
6007
|
-
...child,
|
|
5274
|
+
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$5({}, child), {
|
|
6008
5275
|
_key: context.keyGenerator()
|
|
6009
|
-
}))
|
|
5276
|
+
}))) != null ? _d : [{
|
|
6010
5277
|
_type: context.schema.span.name,
|
|
6011
5278
|
_key: context.keyGenerator(),
|
|
6012
5279
|
text: ""
|
|
@@ -6099,11 +5366,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
6099
5366
|
action
|
|
6100
5367
|
}) => {
|
|
6101
5368
|
const selection = action.editor.selection;
|
|
6102
|
-
selection && (Transforms.select(action.editor, {
|
|
6103
|
-
...selection
|
|
6104
|
-
}), action.editor.selection = {
|
|
6105
|
-
...selection
|
|
6106
|
-
});
|
|
5369
|
+
selection && (Transforms.select(action.editor, __spreadValues$5({}, selection)), action.editor.selection = __spreadValues$5({}, selection));
|
|
6107
5370
|
},
|
|
6108
5371
|
"style.toggle": toggleStyleActionImplementation,
|
|
6109
5372
|
"style.add": addStyleActionImplementation,
|
|
@@ -6375,6 +5638,14 @@ function performDefaultAction({
|
|
|
6375
5638
|
});
|
|
6376
5639
|
}
|
|
6377
5640
|
}
|
|
5641
|
+
var __defProp$4 = Object.defineProperty, __defProps$4 = Object.defineProperties, __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$4 = Object.getOwnPropertySymbols, __hasOwnProp$4 = Object.prototype.hasOwnProperty, __propIsEnum$4 = Object.prototype.propertyIsEnumerable, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$4 = (a, b) => {
|
|
5642
|
+
for (var prop in b || (b = {}))
|
|
5643
|
+
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5644
|
+
if (__getOwnPropSymbols$4)
|
|
5645
|
+
for (var prop of __getOwnPropSymbols$4(b))
|
|
5646
|
+
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5647
|
+
return a;
|
|
5648
|
+
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
6378
5649
|
const editorMachine = setup({
|
|
6379
5650
|
types: {
|
|
6380
5651
|
context: {},
|
|
@@ -6420,11 +5691,11 @@ const editorMachine = setup({
|
|
|
6420
5691
|
event,
|
|
6421
5692
|
enqueue
|
|
6422
5693
|
}) => {
|
|
5694
|
+
var _a;
|
|
6423
5695
|
assertEvent(event, ["behavior event"]), debug$l("Behavior event", event);
|
|
6424
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
6425
|
-
...event.behaviorEvent,
|
|
5696
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : __spreadProps$4(__spreadValues$4({}, event.behaviorEvent), {
|
|
6426
5697
|
editor: event.editor
|
|
6427
|
-
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5698
|
+
}), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6428
5699
|
if (eventBehaviors.length === 0) {
|
|
6429
5700
|
if (!defaultAction)
|
|
6430
5701
|
return;
|
|
@@ -6460,7 +5731,10 @@ const editorMachine = setup({
|
|
|
6460
5731
|
});
|
|
6461
5732
|
if (!shouldRun)
|
|
6462
5733
|
continue;
|
|
6463
|
-
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet(
|
|
5734
|
+
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
5735
|
+
context: editorContext,
|
|
5736
|
+
event: event.behaviorEvent
|
|
5737
|
+
}, shouldRun));
|
|
6464
5738
|
for (const actionIntends of actionIntendSets)
|
|
6465
5739
|
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
|
|
6466
5740
|
type: "behavior action intends",
|
|
@@ -6468,7 +5742,7 @@ const editorMachine = setup({
|
|
|
6468
5742
|
actionIntends
|
|
6469
5743
|
});
|
|
6470
5744
|
if (behaviorOverwritten) {
|
|
6471
|
-
event.nativeEvent
|
|
5745
|
+
(_a = event.nativeEvent) == null || _a.preventDefault();
|
|
6472
5746
|
break;
|
|
6473
5747
|
}
|
|
6474
5748
|
}
|
|
@@ -6487,16 +5761,19 @@ const editorMachine = setup({
|
|
|
6487
5761
|
id: "editor",
|
|
6488
5762
|
context: ({
|
|
6489
5763
|
input
|
|
6490
|
-
}) =>
|
|
6491
|
-
|
|
6492
|
-
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6496
|
-
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
|
|
5764
|
+
}) => {
|
|
5765
|
+
var _a, _b;
|
|
5766
|
+
return {
|
|
5767
|
+
behaviors: (_a = input.behaviors) != null ? _a : coreBehaviors,
|
|
5768
|
+
keyGenerator: input.keyGenerator,
|
|
5769
|
+
pendingEvents: [],
|
|
5770
|
+
schema: input.schema,
|
|
5771
|
+
selection: void 0,
|
|
5772
|
+
readOnly: (_b = input.readOnly) != null ? _b : !1,
|
|
5773
|
+
maxBlocks: input.maxBlocks,
|
|
5774
|
+
value: input.value
|
|
5775
|
+
};
|
|
5776
|
+
},
|
|
6500
5777
|
on: {
|
|
6501
5778
|
"annotation.add": {
|
|
6502
5779
|
actions: emit(({
|
|
@@ -6599,7 +5876,10 @@ const editorMachine = setup({
|
|
|
6599
5876
|
actions: [assign({
|
|
6600
5877
|
selection: ({
|
|
6601
5878
|
event
|
|
6602
|
-
}) =>
|
|
5879
|
+
}) => {
|
|
5880
|
+
var _a;
|
|
5881
|
+
return (_a = event.selection) != null ? _a : void 0;
|
|
5882
|
+
}
|
|
6603
5883
|
}), emit(({
|
|
6604
5884
|
event
|
|
6605
5885
|
}) => event)]
|
|
@@ -6674,10 +5954,9 @@ const editorMachine = setup({
|
|
|
6674
5954
|
}) => {
|
|
6675
5955
|
Editor.withoutNormalizing(event.editor, () => {
|
|
6676
5956
|
for (const actionIntend of event.actionIntends) {
|
|
6677
|
-
const action = {
|
|
6678
|
-
...actionIntend,
|
|
5957
|
+
const action = __spreadProps$4(__spreadValues$4({}, actionIntend), {
|
|
6679
5958
|
editor: event.editor
|
|
6680
|
-
};
|
|
5959
|
+
});
|
|
6681
5960
|
performAction({
|
|
6682
5961
|
context,
|
|
6683
5962
|
action
|
|
@@ -6766,28 +6045,10 @@ function createEditor(config) {
|
|
|
6766
6045
|
const editorActor = createActor(editorMachine, {
|
|
6767
6046
|
input: editorConfigToMachineInput(config)
|
|
6768
6047
|
});
|
|
6769
|
-
editorActor.start();
|
|
6770
|
-
const slateEditor = createSlateEditor({
|
|
6771
|
-
editorActor
|
|
6772
|
-
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
6773
|
-
return {
|
|
6774
|
-
send: (event) => {
|
|
6775
|
-
editorActor.send(event);
|
|
6776
|
-
},
|
|
6777
|
-
on: (event, listener) => editorActor.on(
|
|
6778
|
-
event,
|
|
6779
|
-
// @ts-expect-error
|
|
6780
|
-
listener
|
|
6781
|
-
),
|
|
6782
|
-
_internal: {
|
|
6783
|
-
editable,
|
|
6784
|
-
editorActor,
|
|
6785
|
-
slateEditor
|
|
6786
|
-
}
|
|
6787
|
-
};
|
|
6048
|
+
return editorActor.start(), createEditorFromActor(editorActor);
|
|
6788
6049
|
}
|
|
6789
6050
|
function useCreateEditor(config) {
|
|
6790
|
-
const $ = c(
|
|
6051
|
+
const $ = c(6);
|
|
6791
6052
|
let t0;
|
|
6792
6053
|
$[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
|
|
6793
6054
|
let t1;
|
|
@@ -6795,38 +6056,40 @@ function useCreateEditor(config) {
|
|
|
6795
6056
|
input: t0
|
|
6796
6057
|
}, $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
6797
6058
|
const editorActor = useActorRef(editorMachine, t1);
|
|
6798
|
-
let t2,
|
|
6799
|
-
$[4] !== editorActor ? (
|
|
6800
|
-
editorActor
|
|
6801
|
-
}), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
|
|
6802
|
-
const editable = t3;
|
|
6803
|
-
let t4, t5;
|
|
6804
|
-
$[7] !== editorActor ? (t4 = (event) => {
|
|
6805
|
-
editorActor.send(event);
|
|
6806
|
-
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
|
|
6807
|
-
let t6;
|
|
6808
|
-
$[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
|
|
6809
|
-
editable,
|
|
6810
|
-
editorActor,
|
|
6811
|
-
slateEditor
|
|
6812
|
-
}, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
|
|
6813
|
-
let t7;
|
|
6814
|
-
return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
|
|
6815
|
-
send: t4,
|
|
6816
|
-
on: t5,
|
|
6817
|
-
_internal: t6
|
|
6818
|
-
}, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
|
|
6059
|
+
let t2, t3;
|
|
6060
|
+
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6819
6061
|
}
|
|
6820
6062
|
function editorConfigToMachineInput(config) {
|
|
6063
|
+
var _a;
|
|
6821
6064
|
return {
|
|
6822
6065
|
behaviors: config.behaviors,
|
|
6823
|
-
keyGenerator: config.keyGenerator
|
|
6066
|
+
keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6824
6067
|
maxBlocks: config.maxBlocks,
|
|
6825
6068
|
readOnly: config.readOnly,
|
|
6826
6069
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6827
6070
|
value: config.initialValue
|
|
6828
6071
|
};
|
|
6829
6072
|
}
|
|
6073
|
+
function createEditorFromActor(editorActor) {
|
|
6074
|
+
const slateEditor = createSlateEditor({
|
|
6075
|
+
editorActor
|
|
6076
|
+
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
6077
|
+
return {
|
|
6078
|
+
send: (event) => {
|
|
6079
|
+
editorActor.send(event);
|
|
6080
|
+
},
|
|
6081
|
+
on: (event, listener) => editorActor.on(
|
|
6082
|
+
event,
|
|
6083
|
+
// @ts-expect-error
|
|
6084
|
+
listener
|
|
6085
|
+
),
|
|
6086
|
+
_internal: {
|
|
6087
|
+
editable,
|
|
6088
|
+
editorActor,
|
|
6089
|
+
slateEditor
|
|
6090
|
+
}
|
|
6091
|
+
};
|
|
6092
|
+
}
|
|
6830
6093
|
const EditorActorContext = createContext({}), PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
|
|
6831
6094
|
const selection = useContext(PortableTextEditorSelectionContext);
|
|
6832
6095
|
if (selection === void 0)
|
|
@@ -6850,13 +6113,16 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6850
6113
|
let t2;
|
|
6851
6114
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6852
6115
|
}
|
|
6116
|
+
var __defProp$3 = Object.defineProperty, __defProps$3 = Object.defineProperties, __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$3 = Object.getOwnPropertySymbols, __hasOwnProp$3 = Object.prototype.hasOwnProperty, __propIsEnum$3 = Object.prototype.propertyIsEnumerable, __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$3 = (a, b) => {
|
|
6117
|
+
for (var prop in b || (b = {}))
|
|
6118
|
+
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6119
|
+
if (__getOwnPropSymbols$3)
|
|
6120
|
+
for (var prop of __getOwnPropSymbols$3(b))
|
|
6121
|
+
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6122
|
+
return a;
|
|
6123
|
+
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6853
6124
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6854
6125
|
class PortableTextEditor extends Component {
|
|
6855
|
-
static displayName = "PortableTextEditor";
|
|
6856
|
-
/**
|
|
6857
|
-
* An observable of all the editor changes.
|
|
6858
|
-
*/
|
|
6859
|
-
change$ = new Subject();
|
|
6860
6126
|
/**
|
|
6861
6127
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6862
6128
|
*/
|
|
@@ -6867,8 +6133,11 @@ class PortableTextEditor extends Component {
|
|
|
6867
6133
|
* The editor API (currently implemented with Slate).
|
|
6868
6134
|
*/
|
|
6869
6135
|
constructor(props) {
|
|
6870
|
-
|
|
6871
|
-
|
|
6136
|
+
var _a;
|
|
6137
|
+
super(props), __publicField(this, "change$", new Subject()), __publicField(this, "setEditable", (editable) => {
|
|
6138
|
+
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6139
|
+
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6140
|
+
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6872
6141
|
schema: props.schemaType,
|
|
6873
6142
|
initialValue: props.value,
|
|
6874
6143
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6889,14 +6158,9 @@ class PortableTextEditor extends Component {
|
|
|
6889
6158
|
value: this.props.value
|
|
6890
6159
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6891
6160
|
}
|
|
6892
|
-
setEditable = (editable) => {
|
|
6893
|
-
this.editor._internal.editable = {
|
|
6894
|
-
...this.editor._internal.editable,
|
|
6895
|
-
...editable
|
|
6896
|
-
};
|
|
6897
|
-
};
|
|
6898
6161
|
render() {
|
|
6899
|
-
|
|
6162
|
+
var _a;
|
|
6163
|
+
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6900
6164
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6901
6165
|
legacyPatches ? /* @__PURE__ */ jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6902
6166
|
/* @__PURE__ */ jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6906,65 +6170,105 @@ class PortableTextEditor extends Component {
|
|
|
6906
6170
|
/* @__PURE__ */ jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsx(Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6907
6171
|
] });
|
|
6908
6172
|
}
|
|
6909
|
-
// Static API methods
|
|
6910
|
-
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6911
|
-
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6912
|
-
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6913
|
-
static blur = (editor) => {
|
|
6914
|
-
debug$4("Host blurred"), editor.editable?.blur();
|
|
6915
|
-
};
|
|
6916
|
-
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6917
|
-
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6918
|
-
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6919
|
-
static focus = (editor) => {
|
|
6920
|
-
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6921
|
-
};
|
|
6922
|
-
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6923
|
-
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6924
|
-
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6925
|
-
static getValue = (editor) => editor.editable?.getValue();
|
|
6926
|
-
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6927
|
-
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6928
|
-
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6929
|
-
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6930
|
-
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6931
|
-
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6932
|
-
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6933
|
-
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6934
|
-
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6935
|
-
static isObjectPath = (_editor, path) => {
|
|
6936
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6937
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6938
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6939
|
-
};
|
|
6940
|
-
static marks = (editor) => editor.editable?.marks();
|
|
6941
|
-
static select = (editor, selection) => {
|
|
6942
|
-
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6943
|
-
};
|
|
6944
|
-
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6945
|
-
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6946
|
-
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6947
|
-
static toggleMark = (editor, mark) => {
|
|
6948
|
-
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6949
|
-
};
|
|
6950
|
-
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6951
|
-
static undo = (editor) => {
|
|
6952
|
-
debug$4("Host undoing"), editor.editable?.undo();
|
|
6953
|
-
};
|
|
6954
|
-
static redo = (editor) => {
|
|
6955
|
-
debug$4("Host redoing"), editor.editable?.redo();
|
|
6956
|
-
};
|
|
6957
|
-
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6958
6173
|
}
|
|
6174
|
+
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6175
|
+
__publicField(PortableTextEditor, "activeAnnotations", (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : []), __publicField(PortableTextEditor, "isAnnotationActive", (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1), __publicField(PortableTextEditor, "addAnnotation", (editor, type, value) => {
|
|
6176
|
+
var _a;
|
|
6177
|
+
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6178
|
+
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6179
|
+
var _a;
|
|
6180
|
+
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6181
|
+
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6182
|
+
var _a;
|
|
6183
|
+
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6184
|
+
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6185
|
+
var _a;
|
|
6186
|
+
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6187
|
+
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6188
|
+
var _a;
|
|
6189
|
+
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6190
|
+
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6191
|
+
var _a;
|
|
6192
|
+
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6193
|
+
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6194
|
+
var _a;
|
|
6195
|
+
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6196
|
+
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6197
|
+
var _a;
|
|
6198
|
+
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6199
|
+
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6200
|
+
var _a;
|
|
6201
|
+
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6202
|
+
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6203
|
+
var _a;
|
|
6204
|
+
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6205
|
+
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6206
|
+
var _a;
|
|
6207
|
+
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6208
|
+
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6209
|
+
var _a;
|
|
6210
|
+
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6211
|
+
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6212
|
+
var _a;
|
|
6213
|
+
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6214
|
+
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6215
|
+
var _a;
|
|
6216
|
+
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6217
|
+
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6218
|
+
var _a;
|
|
6219
|
+
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6220
|
+
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6221
|
+
var _a;
|
|
6222
|
+
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6223
|
+
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6224
|
+
var _a;
|
|
6225
|
+
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6226
|
+
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6227
|
+
var _a;
|
|
6228
|
+
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6229
|
+
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6230
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6231
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6232
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6233
|
+
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6234
|
+
var _a;
|
|
6235
|
+
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6236
|
+
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6237
|
+
var _a;
|
|
6238
|
+
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6239
|
+
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6240
|
+
var _a;
|
|
6241
|
+
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6242
|
+
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6243
|
+
var _a;
|
|
6244
|
+
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6245
|
+
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6246
|
+
var _a;
|
|
6247
|
+
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6248
|
+
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6249
|
+
var _a;
|
|
6250
|
+
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6251
|
+
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6252
|
+
var _a;
|
|
6253
|
+
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6254
|
+
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6255
|
+
var _a;
|
|
6256
|
+
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6257
|
+
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6258
|
+
var _a;
|
|
6259
|
+
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6260
|
+
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6261
|
+
var _a;
|
|
6262
|
+
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6263
|
+
});
|
|
6959
6264
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6960
6265
|
const $ = c(4);
|
|
6961
6266
|
let t0, t1;
|
|
6962
6267
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6963
6268
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6964
|
-
props.editorActor.send({
|
|
6965
|
-
type: "patches"
|
|
6966
|
-
|
|
6967
|
-
});
|
|
6269
|
+
props.editorActor.send(__spreadValues$3({
|
|
6270
|
+
type: "patches"
|
|
6271
|
+
}, payload));
|
|
6968
6272
|
});
|
|
6969
6273
|
return () => {
|
|
6970
6274
|
subscription.unsubscribe();
|
|
@@ -7029,10 +6333,9 @@ function RouteEventsToChanges(props) {
|
|
|
7029
6333
|
break bb5;
|
|
7030
6334
|
}
|
|
7031
6335
|
case "error": {
|
|
7032
|
-
handleChange({
|
|
7033
|
-
...event,
|
|
6336
|
+
handleChange(__spreadProps$3(__spreadValues$3({}, event), {
|
|
7034
6337
|
level: "warning"
|
|
7035
|
-
});
|
|
6338
|
+
}));
|
|
7036
6339
|
break bb5;
|
|
7037
6340
|
}
|
|
7038
6341
|
case "annotation.add":
|
|
@@ -7059,6 +6362,14 @@ function RouteEventsToChanges(props) {
|
|
|
7059
6362
|
};
|
|
7060
6363
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), null;
|
|
7061
6364
|
}
|
|
6365
|
+
var __defProp$2 = Object.defineProperty, __defProps$2 = Object.defineProperties, __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$2 = Object.getOwnPropertySymbols, __hasOwnProp$2 = Object.prototype.hasOwnProperty, __propIsEnum$2 = Object.prototype.propertyIsEnumerable, __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$2 = (a, b) => {
|
|
6366
|
+
for (var prop in b || (b = {}))
|
|
6367
|
+
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6368
|
+
if (__getOwnPropSymbols$2)
|
|
6369
|
+
for (var prop of __getOwnPropSymbols$2(b))
|
|
6370
|
+
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6371
|
+
return a;
|
|
6372
|
+
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
7062
6373
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
7063
6374
|
const {
|
|
7064
6375
|
editorActor,
|
|
@@ -7070,10 +6381,13 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
7070
6381
|
renderDecorator,
|
|
7071
6382
|
renderAnnotation
|
|
7072
6383
|
} = props, spanRef = useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = useSelected(), [focused, setFocused] = useState(!1), [selected, setSelected] = useState(!1), block = children.props.parent, path = useMemo(() => block ? [{
|
|
7073
|
-
_key: block
|
|
6384
|
+
_key: block == null ? void 0 : block._key
|
|
7074
6385
|
}, "children", {
|
|
7075
6386
|
_key: leaf._key
|
|
7076
|
-
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) =>
|
|
6387
|
+
}] : [], [block, leaf._key]), decoratorValues = useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = useMemo(() => uniq((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = useMemo(() => annotationMarks.map((mark_0) => {
|
|
6388
|
+
var _a;
|
|
6389
|
+
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6390
|
+
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
7077
6391
|
useEffect(() => {
|
|
7078
6392
|
if (!shouldTrackSelectionAndFocus) {
|
|
7079
6393
|
setFocused(!1);
|
|
@@ -7180,7 +6494,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
7180
6494
|
}
|
|
7181
6495
|
return returnedChildren;
|
|
7182
6496
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
7183
|
-
return useMemo(() => /* @__PURE__ */ jsx("span", {
|
|
6497
|
+
return useMemo(() => /* @__PURE__ */ jsx("span", __spreadProps$2(__spreadValues$2({}, attributes), { ref: spanRef, children: content }), leaf._key), [leaf, attributes, content]);
|
|
7184
6498
|
};
|
|
7185
6499
|
Leaf.displayName = "Leaf";
|
|
7186
6500
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -7233,10 +6547,32 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
7233
6547
|
}, editor;
|
|
7234
6548
|
};
|
|
7235
6549
|
}
|
|
6550
|
+
var __defProp$1 = Object.defineProperty, __defProps$1 = Object.defineProperties, __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors, __getOwnPropSymbols$1 = Object.getOwnPropertySymbols, __hasOwnProp$1 = Object.prototype.hasOwnProperty, __propIsEnum$1 = Object.prototype.propertyIsEnumerable, __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$1 = (a, b) => {
|
|
6551
|
+
for (var prop in b || (b = {}))
|
|
6552
|
+
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6553
|
+
if (__getOwnPropSymbols$1)
|
|
6554
|
+
for (var prop of __getOwnPropSymbols$1(b))
|
|
6555
|
+
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6556
|
+
return a;
|
|
6557
|
+
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6558
|
+
var target = {};
|
|
6559
|
+
for (var prop in source)
|
|
6560
|
+
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6561
|
+
if (source != null && __getOwnPropSymbols$1)
|
|
6562
|
+
for (var prop of __getOwnPropSymbols$1(source))
|
|
6563
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6564
|
+
return target;
|
|
6565
|
+
};
|
|
7236
6566
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
7237
6567
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
7238
6568
|
return function(editor) {
|
|
7239
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) =>
|
|
6569
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6570
|
+
var _a;
|
|
6571
|
+
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6572
|
+
var _a2;
|
|
6573
|
+
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6574
|
+
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6575
|
+
}).join(`
|
|
7240
6576
|
|
|
7241
6577
|
`);
|
|
7242
6578
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -7274,6 +6610,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7274
6610
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
7275
6611
|
data.clearData(), data.setData("text/plain", asPlainText), data.setData("text/html", asHTML), data.setData("application/json", asJSON), data.setData("application/x-portable-text", asJSON), debug$1("text", asPlainText), data.setData("application/x-portable-text-event-origin", originEvent || "external"), debug$1("Set fragment data", asJSON, asHTML);
|
|
7276
6612
|
}, editor.insertPortableTextData = (data) => {
|
|
6613
|
+
var _a, _b;
|
|
7277
6614
|
if (!editor.selection)
|
|
7278
6615
|
return !1;
|
|
7279
6616
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -7283,8 +6620,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7283
6620
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
7284
6621
|
schemaTypes
|
|
7285
6622
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7286
|
-
if (!validation.valid && !validation.resolution
|
|
7287
|
-
const errorDescription = `${validation.resolution
|
|
6623
|
+
if (!validation.valid && !((_a = validation.resolution) != null && _a.autoResolve)) {
|
|
6624
|
+
const errorDescription = `${(_b = validation.resolution) == null ? void 0 : _b.description}`;
|
|
7288
6625
|
return editorActor.send({
|
|
7289
6626
|
type: "error",
|
|
7290
6627
|
name: "pasteError",
|
|
@@ -7297,6 +6634,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7297
6634
|
}
|
|
7298
6635
|
return !1;
|
|
7299
6636
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
6637
|
+
var _a;
|
|
7300
6638
|
if (!editor.selection)
|
|
7301
6639
|
return debug$1("No selection, not inserting"), !1;
|
|
7302
6640
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7323,7 +6661,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7323
6661
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7324
6662
|
if (!validation.valid) {
|
|
7325
6663
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7326
|
-
${validation.resolution
|
|
6664
|
+
${(_a = validation.resolution) == null ? void 0 : _a.description}
|
|
7327
6665
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7328
6666
|
return editorActor.send({
|
|
7329
6667
|
type: "error",
|
|
@@ -7362,46 +6700,37 @@ function escapeHtml(str) {
|
|
|
7362
6700
|
}
|
|
7363
6701
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7364
6702
|
return fragment.map((node) => {
|
|
7365
|
-
const newNode = {
|
|
7366
|
-
...node
|
|
7367
|
-
};
|
|
6703
|
+
const newNode = __spreadValues$1({}, node);
|
|
7368
6704
|
if (editor.isTextBlock(newNode)) {
|
|
7369
6705
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7370
6706
|
if (annotations.length === 0) {
|
|
7371
|
-
const
|
|
7372
|
-
markDefs
|
|
7373
|
-
|
|
7374
|
-
}
|
|
7375
|
-
return {
|
|
7376
|
-
...NewNodeNoDefs,
|
|
6707
|
+
const _a = newNode, NewNodeNoDefs = __objRest$1(_a, [
|
|
6708
|
+
"markDefs"
|
|
6709
|
+
]);
|
|
6710
|
+
return __spreadProps$1(__spreadValues$1({}, NewNodeNoDefs), {
|
|
7377
6711
|
_key: keyGenerator()
|
|
7378
|
-
};
|
|
6712
|
+
});
|
|
7379
6713
|
}
|
|
7380
6714
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7381
6715
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7382
|
-
return {
|
|
7383
|
-
...newNode,
|
|
6716
|
+
return __spreadProps$1(__spreadValues$1({}, newNode), {
|
|
7384
6717
|
markDefs: allowedAnnotations,
|
|
7385
6718
|
_key: keyGenerator()
|
|
7386
|
-
};
|
|
6719
|
+
});
|
|
7387
6720
|
}
|
|
7388
6721
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7389
6722
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7390
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
7391
|
-
...child,
|
|
6723
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? __spreadProps$1(__spreadValues$1({}, child), {
|
|
7392
6724
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7393
|
-
} : child), {
|
|
7394
|
-
...def,
|
|
6725
|
+
}) : child), __spreadProps$1(__spreadValues$1({}, def), {
|
|
7395
6726
|
_key: newKey
|
|
7396
|
-
};
|
|
6727
|
+
});
|
|
7397
6728
|
});
|
|
7398
6729
|
}
|
|
7399
|
-
const nodeWithNewKeys = {
|
|
7400
|
-
...newNode,
|
|
6730
|
+
const nodeWithNewKeys = __spreadProps$1(__spreadValues$1({}, newNode), {
|
|
7401
6731
|
_key: keyGenerator()
|
|
7402
|
-
};
|
|
7403
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
7404
|
-
...child,
|
|
6732
|
+
});
|
|
6733
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => __spreadProps$1(__spreadValues$1({}, child), {
|
|
7405
6734
|
_key: keyGenerator()
|
|
7406
6735
|
}))), nodeWithNewKeys;
|
|
7407
6736
|
});
|
|
@@ -7440,6 +6769,22 @@ function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
|
|
|
7440
6769
|
slateEditor.apply = originalApply;
|
|
7441
6770
|
};
|
|
7442
6771
|
}
|
|
6772
|
+
var __defProp2 = Object.defineProperty, __defProps = Object.defineProperties, __getOwnPropDescs = Object.getOwnPropertyDescriptors, __getOwnPropSymbols2 = Object.getOwnPropertySymbols, __hasOwnProp2 = Object.prototype.hasOwnProperty, __propIsEnum2 = Object.prototype.propertyIsEnumerable, __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues2 = (a, b) => {
|
|
6773
|
+
for (var prop in b || (b = {}))
|
|
6774
|
+
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
6775
|
+
if (__getOwnPropSymbols2)
|
|
6776
|
+
for (var prop of __getOwnPropSymbols2(b))
|
|
6777
|
+
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
6778
|
+
return a;
|
|
6779
|
+
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
6780
|
+
var target = {};
|
|
6781
|
+
for (var prop in source)
|
|
6782
|
+
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6783
|
+
if (source != null && __getOwnPropSymbols2)
|
|
6784
|
+
for (var prop of __getOwnPropSymbols2(source))
|
|
6785
|
+
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
6786
|
+
return target;
|
|
6787
|
+
};
|
|
7443
6788
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7444
6789
|
position: "absolute",
|
|
7445
6790
|
userSelect: "none",
|
|
@@ -7447,7 +6792,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7447
6792
|
left: 0,
|
|
7448
6793
|
right: 0
|
|
7449
6794
|
}, PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
7450
|
-
const {
|
|
6795
|
+
const _a = props, {
|
|
7451
6796
|
hotkeys,
|
|
7452
6797
|
onBlur,
|
|
7453
6798
|
onFocus,
|
|
@@ -7465,9 +6810,27 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7465
6810
|
renderStyle,
|
|
7466
6811
|
selection: propsSelection,
|
|
7467
6812
|
scrollSelectionIntoView,
|
|
7468
|
-
spellCheck
|
|
7469
|
-
|
|
7470
|
-
|
|
6813
|
+
spellCheck
|
|
6814
|
+
} = _a, restProps = __objRest(_a, [
|
|
6815
|
+
"hotkeys",
|
|
6816
|
+
"onBlur",
|
|
6817
|
+
"onFocus",
|
|
6818
|
+
"onBeforeInput",
|
|
6819
|
+
"onPaste",
|
|
6820
|
+
"onCopy",
|
|
6821
|
+
"onClick",
|
|
6822
|
+
"rangeDecorations",
|
|
6823
|
+
"renderAnnotation",
|
|
6824
|
+
"renderBlock",
|
|
6825
|
+
"renderChild",
|
|
6826
|
+
"renderDecorator",
|
|
6827
|
+
"renderListItem",
|
|
6828
|
+
"renderPlaceholder",
|
|
6829
|
+
"renderStyle",
|
|
6830
|
+
"selection",
|
|
6831
|
+
"scrollSelectionIntoView",
|
|
6832
|
+
"spellCheck"
|
|
6833
|
+
]), portableTextEditor = usePortableTextEditor(), ref = useRef(null), [editableElement, setEditableElement] = useState(null), [hasInvalidValue, setHasInvalidValue] = useState(!1), [rangeDecorationState, setRangeDecorationsState] = useState([]);
|
|
7471
6834
|
useImperativeHandle(forwardedRef, () => ref.current);
|
|
7472
6835
|
const rangeDecorationsRef = useRef(rangeDecorations), editorActor = useContext(EditorActorContext), readOnly = useSelector(editorActor, (s) => s.context.readOnly), schemaTypes = useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = useSlate(), blockTypeName = schemaTypes.block.name;
|
|
7473
6836
|
useMemo(() => {
|
|
@@ -7477,9 +6840,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7477
6840
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7478
6841
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7479
6842
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7480
|
-
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, {
|
|
6843
|
+
const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element, __spreadProps(__spreadValues2({}, eProps), { readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck })), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
|
|
7481
6844
|
if (lProps.leaf._type === "span") {
|
|
7482
|
-
let rendered = /* @__PURE__ */ jsx(Leaf, {
|
|
6845
|
+
let rendered = /* @__PURE__ */ jsx(Leaf, __spreadProps(__spreadValues2({}, lProps), { editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly }));
|
|
7483
6846
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7484
6847
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7485
6848
|
/* @__PURE__ */ jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7526,10 +6889,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7526
6889
|
origin: "local"
|
|
7527
6890
|
});
|
|
7528
6891
|
}
|
|
7529
|
-
newRange !== null && newSlateRanges.push({
|
|
7530
|
-
...newRange || slateRange_0,
|
|
6892
|
+
newRange !== null && newSlateRanges.push(__spreadProps(__spreadValues2({}, newRange || slateRange_0), {
|
|
7531
6893
|
rangeDecoration: rangeDecorationItem
|
|
7532
|
-
});
|
|
6894
|
+
}));
|
|
7533
6895
|
}), newSlateRanges.length > 0) {
|
|
7534
6896
|
setRangeDecorationsState(newSlateRanges);
|
|
7535
6897
|
return;
|
|
@@ -7571,7 +6933,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7571
6933
|
nativeEvent: event
|
|
7572
6934
|
});
|
|
7573
6935
|
}, [onCopy, editorActor, slateEditor]), handlePaste = useCallback((event_0) => {
|
|
7574
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6936
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), ptRange = toPortableTextRange(value_0, slateEditor.selection, schemaTypes), path = (ptRange == null ? void 0 : ptRange.focus.path) || [], onPasteResult = onPaste == null ? void 0 : onPaste({
|
|
7575
6937
|
event: event_0,
|
|
7576
6938
|
value: value_0,
|
|
7577
6939
|
path,
|
|
@@ -7636,8 +6998,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7636
6998
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7637
6999
|
try {
|
|
7638
7000
|
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7639
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7640
|
-
} catch {
|
|
7001
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection == null || domSelection.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
7002
|
+
} catch (e) {
|
|
7641
7003
|
debug("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7642
7004
|
}
|
|
7643
7005
|
}, [ref, slateEditor]);
|
|
@@ -7725,8 +7087,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7725
7087
|
ref.current = ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7726
7088
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsx(
|
|
7727
7089
|
Editable,
|
|
7728
|
-
{
|
|
7729
|
-
...restProps,
|
|
7090
|
+
__spreadProps(__spreadValues2({}, restProps), {
|
|
7730
7091
|
autoFocus: !1,
|
|
7731
7092
|
className: restProps.className || "pt-editable",
|
|
7732
7093
|
decorate,
|
|
@@ -7743,7 +7104,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7743
7104
|
renderElement,
|
|
7744
7105
|
renderLeaf,
|
|
7745
7106
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7746
|
-
}
|
|
7107
|
+
})
|
|
7747
7108
|
) : null;
|
|
7748
7109
|
});
|
|
7749
7110
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
@@ -7820,12 +7181,6 @@ export {
|
|
|
7820
7181
|
EditorProvider,
|
|
7821
7182
|
PortableTextEditable,
|
|
7822
7183
|
PortableTextEditor,
|
|
7823
|
-
coreBehavior,
|
|
7824
|
-
coreBehaviors,
|
|
7825
|
-
createCodeEditorBehaviors,
|
|
7826
|
-
createLinkBehaviors,
|
|
7827
|
-
createMarkdownBehaviors,
|
|
7828
|
-
defineBehavior,
|
|
7829
7184
|
defineSchema,
|
|
7830
7185
|
editorMachine,
|
|
7831
7186
|
defaultKeyGenerator as keyGenerator,
|