@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.cjs
CHANGED
|
@@ -1,945 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty, __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues = (a, b) => {
|
|
6
|
+
for (var prop in b || (b = {}))
|
|
7
|
+
__hasOwnProp.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
8
|
+
if (__getOwnPropSymbols)
|
|
9
|
+
for (var prop of __getOwnPropSymbols(b))
|
|
10
|
+
__propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
|
|
11
|
+
return a;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var
|
|
14
|
+
var schema = require("@sanity/schema"), types = require("@sanity/types"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), throttle = require("lodash/throttle.js"), debounce = require("lodash/debounce.js"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), xstate = require("xstate"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), selectors = require("./_chunks-cjs/selectors.cjs"), behavior_core = require("./_chunks-cjs/behavior.core.cjs"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
|
|
4
15
|
function _interopDefaultCompat(e) {
|
|
5
16
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
17
|
}
|
|
7
18
|
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues);
|
|
8
|
-
const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
9
|
-
alt: "altKey",
|
|
10
|
-
control: "ctrlKey",
|
|
11
|
-
meta: "metaKey",
|
|
12
|
-
shift: "shiftKey"
|
|
13
|
-
}, aliases = {
|
|
14
|
-
add: "+",
|
|
15
|
-
break: "pause",
|
|
16
|
-
cmd: "meta",
|
|
17
|
-
command: "meta",
|
|
18
|
-
ctl: "control",
|
|
19
|
-
ctrl: "control",
|
|
20
|
-
del: "delete",
|
|
21
|
-
down: "arrowdown",
|
|
22
|
-
esc: "escape",
|
|
23
|
-
ins: "insert",
|
|
24
|
-
left: "arrowleft",
|
|
25
|
-
mod: IS_MAC ? "meta" : "control",
|
|
26
|
-
opt: "alt",
|
|
27
|
-
option: "alt",
|
|
28
|
-
return: "enter",
|
|
29
|
-
right: "arrowright",
|
|
30
|
-
space: " ",
|
|
31
|
-
spacebar: " ",
|
|
32
|
-
up: "arrowup",
|
|
33
|
-
win: "meta",
|
|
34
|
-
windows: "meta"
|
|
35
|
-
}, keyCodes = {
|
|
36
|
-
backspace: 8,
|
|
37
|
-
tab: 9,
|
|
38
|
-
enter: 13,
|
|
39
|
-
shift: 16,
|
|
40
|
-
control: 17,
|
|
41
|
-
alt: 18,
|
|
42
|
-
pause: 19,
|
|
43
|
-
capslock: 20,
|
|
44
|
-
escape: 27,
|
|
45
|
-
" ": 32,
|
|
46
|
-
pageup: 33,
|
|
47
|
-
pagedown: 34,
|
|
48
|
-
end: 35,
|
|
49
|
-
home: 36,
|
|
50
|
-
arrowleft: 37,
|
|
51
|
-
arrowup: 38,
|
|
52
|
-
arrowright: 39,
|
|
53
|
-
arrowdown: 40,
|
|
54
|
-
insert: 45,
|
|
55
|
-
delete: 46,
|
|
56
|
-
meta: 91,
|
|
57
|
-
numlock: 144,
|
|
58
|
-
scrolllock: 145,
|
|
59
|
-
";": 186,
|
|
60
|
-
"=": 187,
|
|
61
|
-
",": 188,
|
|
62
|
-
"-": 189,
|
|
63
|
-
".": 190,
|
|
64
|
-
"/": 191,
|
|
65
|
-
"`": 192,
|
|
66
|
-
"[": 219,
|
|
67
|
-
"\\": 220,
|
|
68
|
-
"]": 221,
|
|
69
|
-
"'": 222,
|
|
70
|
-
f1: 112,
|
|
71
|
-
f2: 113,
|
|
72
|
-
f3: 114,
|
|
73
|
-
f4: 115,
|
|
74
|
-
f5: 116,
|
|
75
|
-
f6: 117,
|
|
76
|
-
f7: 118,
|
|
77
|
-
f8: 119,
|
|
78
|
-
f9: 120,
|
|
79
|
-
f10: 121,
|
|
80
|
-
f11: 122,
|
|
81
|
-
f12: 123,
|
|
82
|
-
f13: 124,
|
|
83
|
-
f14: 125,
|
|
84
|
-
f15: 126,
|
|
85
|
-
f16: 127,
|
|
86
|
-
f17: 128,
|
|
87
|
-
f18: 129,
|
|
88
|
-
f19: 130,
|
|
89
|
-
f20: 131
|
|
90
|
-
};
|
|
91
|
-
function isHotkey(hotkey, event) {
|
|
92
|
-
return compareHotkey(parseHotkey(hotkey), event);
|
|
93
|
-
}
|
|
94
|
-
function parseHotkey(hotkey) {
|
|
95
|
-
const parsedHotkey = {
|
|
96
|
-
altKey: !1,
|
|
97
|
-
ctrlKey: !1,
|
|
98
|
-
metaKey: !1,
|
|
99
|
-
shiftKey: !1
|
|
100
|
-
}, hotkeySegments = hotkey.replace("++", "+add").split("+");
|
|
101
|
-
for (const rawHotkeySegment of hotkeySegments) {
|
|
102
|
-
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];
|
|
103
|
-
if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
|
|
104
|
-
throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
|
|
105
|
-
(hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
|
|
106
|
-
}
|
|
107
|
-
return parsedHotkey;
|
|
108
|
-
}
|
|
109
|
-
function compareHotkey(parsedHotkey, event) {
|
|
110
|
-
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;
|
|
111
|
-
}
|
|
112
|
-
function toKeyCode(name) {
|
|
113
|
-
const keyName = toKeyName(name);
|
|
114
|
-
return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
|
|
115
|
-
}
|
|
116
|
-
function toKeyName(name) {
|
|
117
|
-
const keyName = name.toLowerCase();
|
|
118
|
-
return aliases[keyName] ?? keyName;
|
|
119
|
-
}
|
|
120
|
-
function defineBehavior(behavior) {
|
|
121
|
-
return behavior;
|
|
122
|
-
}
|
|
123
|
-
function createCodeEditorBehaviors(config) {
|
|
124
|
-
return [{
|
|
125
|
-
on: "key.down",
|
|
126
|
-
guard: ({
|
|
127
|
-
context,
|
|
128
|
-
event
|
|
129
|
-
}) => {
|
|
130
|
-
const isMoveUpShortcut = isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = selector_getTextBefore.getFirstBlock({
|
|
131
|
-
context
|
|
132
|
-
}), selectedBlocks = selector_getTextBefore.getSelectedBlocks({
|
|
133
|
-
context
|
|
134
|
-
}), blocksAbove = firstBlock?.node._key !== selectedBlocks[0]?.node._key;
|
|
135
|
-
return !isMoveUpShortcut || !blocksAbove ? !1 : {
|
|
136
|
-
paths: selectedBlocks.map((block) => block.path)
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
actions: [({
|
|
140
|
-
paths
|
|
141
|
-
}) => paths.map((at) => ({
|
|
142
|
-
type: "move.block up",
|
|
143
|
-
at
|
|
144
|
-
}))]
|
|
145
|
-
}, {
|
|
146
|
-
on: "key.down",
|
|
147
|
-
guard: ({
|
|
148
|
-
context,
|
|
149
|
-
event
|
|
150
|
-
}) => {
|
|
151
|
-
const isMoveDownShortcut = isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = selector_getTextBefore.getLastBlock({
|
|
152
|
-
context
|
|
153
|
-
}), selectedBlocks = selector_getTextBefore.getSelectedBlocks({
|
|
154
|
-
context
|
|
155
|
-
}), blocksBelow = lastBlock?.node._key !== selectedBlocks[selectedBlocks.length - 1]?.node._key;
|
|
156
|
-
return !isMoveDownShortcut || !blocksBelow ? !1 : {
|
|
157
|
-
paths: selectedBlocks.map((block) => block.path).reverse()
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
actions: [({
|
|
161
|
-
paths
|
|
162
|
-
}) => paths.map((at) => ({
|
|
163
|
-
type: "move.block down",
|
|
164
|
-
at
|
|
165
|
-
}))]
|
|
166
|
-
}];
|
|
167
|
-
}
|
|
168
|
-
function isEmptyTextBlock(block) {
|
|
169
|
-
if (!types.isPortableTextTextBlock(block))
|
|
170
|
-
return !1;
|
|
171
|
-
const onlyText = block.children.every(types.isPortableTextSpan), blockText = getTextBlockText(block);
|
|
172
|
-
return onlyText && blockText === "";
|
|
173
|
-
}
|
|
174
|
-
function getTextBlockText(block) {
|
|
175
|
-
return block.children.map((child) => child.text ?? "").join("");
|
|
176
|
-
}
|
|
177
|
-
const arrowDownOnLonelyBlockObject = {
|
|
178
|
-
on: "key.down",
|
|
179
|
-
guard: ({
|
|
180
|
-
context,
|
|
181
|
-
event
|
|
182
|
-
}) => {
|
|
183
|
-
const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject = selector_getTextBefore.getFocusBlockObject({
|
|
184
|
-
context
|
|
185
|
-
}), nextBlock = selector_getTextBefore.getNextBlock({
|
|
186
|
-
context
|
|
187
|
-
});
|
|
188
|
-
return isArrowDown && focusBlockObject && !nextBlock;
|
|
189
|
-
},
|
|
190
|
-
actions: [() => [{
|
|
191
|
-
type: "insert.text block",
|
|
192
|
-
placement: "after"
|
|
193
|
-
}]]
|
|
194
|
-
}, arrowUpOnLonelyBlockObject = {
|
|
195
|
-
on: "key.down",
|
|
196
|
-
guard: ({
|
|
197
|
-
context,
|
|
198
|
-
event
|
|
199
|
-
}) => {
|
|
200
|
-
const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject = selector_getTextBefore.getFocusBlockObject({
|
|
201
|
-
context
|
|
202
|
-
}), previousBlock = selector_getTextBefore.getPreviousBlock({
|
|
203
|
-
context
|
|
204
|
-
});
|
|
205
|
-
return isArrowUp && focusBlockObject && !previousBlock;
|
|
206
|
-
},
|
|
207
|
-
actions: [() => [{
|
|
208
|
-
type: "insert.text block",
|
|
209
|
-
placement: "before"
|
|
210
|
-
}, {
|
|
211
|
-
type: "select previous block"
|
|
212
|
-
}]]
|
|
213
|
-
}, breakingBlockObject = {
|
|
214
|
-
on: "insert.break",
|
|
215
|
-
guard: ({
|
|
216
|
-
context
|
|
217
|
-
}) => {
|
|
218
|
-
const focusBlockObject = selector_getTextBefore.getFocusBlockObject({
|
|
219
|
-
context
|
|
220
|
-
});
|
|
221
|
-
return selector_getTextBefore.selectionIsCollapsed({
|
|
222
|
-
context
|
|
223
|
-
}) && focusBlockObject !== void 0;
|
|
224
|
-
},
|
|
225
|
-
actions: [() => [{
|
|
226
|
-
type: "insert.text block",
|
|
227
|
-
placement: "after"
|
|
228
|
-
}]]
|
|
229
|
-
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
230
|
-
on: "delete.backward",
|
|
231
|
-
guard: ({
|
|
232
|
-
context
|
|
233
|
-
}) => {
|
|
234
|
-
const focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
235
|
-
context
|
|
236
|
-
}), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
237
|
-
context
|
|
238
|
-
}), previousBlock = selector_getTextBefore.getPreviousBlock({
|
|
239
|
-
context
|
|
240
|
-
});
|
|
241
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
242
|
-
focusTextBlock,
|
|
243
|
-
previousBlock
|
|
244
|
-
} : !1;
|
|
245
|
-
},
|
|
246
|
-
actions: [({
|
|
247
|
-
focusTextBlock,
|
|
248
|
-
previousBlock
|
|
249
|
-
}) => [{
|
|
250
|
-
type: "delete.block",
|
|
251
|
-
blockPath: focusTextBlock.path
|
|
252
|
-
}, {
|
|
253
|
-
type: "select",
|
|
254
|
-
selection: {
|
|
255
|
-
anchor: {
|
|
256
|
-
path: previousBlock.path,
|
|
257
|
-
offset: 0
|
|
258
|
-
},
|
|
259
|
-
focus: {
|
|
260
|
-
path: previousBlock.path,
|
|
261
|
-
offset: 0
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}]]
|
|
265
|
-
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
266
|
-
on: "delete.forward",
|
|
267
|
-
guard: ({
|
|
268
|
-
context
|
|
269
|
-
}) => {
|
|
270
|
-
const focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
271
|
-
context
|
|
272
|
-
}), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
273
|
-
context
|
|
274
|
-
}), nextBlock = selector_getTextBefore.getNextBlock({
|
|
275
|
-
context
|
|
276
|
-
});
|
|
277
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
278
|
-
focusTextBlock,
|
|
279
|
-
nextBlock
|
|
280
|
-
} : !1;
|
|
281
|
-
},
|
|
282
|
-
actions: [({
|
|
283
|
-
focusTextBlock,
|
|
284
|
-
nextBlock
|
|
285
|
-
}) => [{
|
|
286
|
-
type: "delete.block",
|
|
287
|
-
blockPath: focusTextBlock.path
|
|
288
|
-
}, {
|
|
289
|
-
type: "select",
|
|
290
|
-
selection: {
|
|
291
|
-
anchor: {
|
|
292
|
-
path: nextBlock.path,
|
|
293
|
-
offset: 0
|
|
294
|
-
},
|
|
295
|
-
focus: {
|
|
296
|
-
path: nextBlock.path,
|
|
297
|
-
offset: 0
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}]]
|
|
301
|
-
}, coreBlockObjectBehaviors = {
|
|
302
|
-
arrowDownOnLonelyBlockObject,
|
|
303
|
-
arrowUpOnLonelyBlockObject,
|
|
304
|
-
breakingBlockObject,
|
|
305
|
-
deletingEmptyTextBlockAfterBlockObject,
|
|
306
|
-
deletingEmptyTextBlockBeforeBlockObject
|
|
307
|
-
}, decoratorAdd = {
|
|
308
|
-
on: "decorator.add",
|
|
309
|
-
guard: ({
|
|
310
|
-
event
|
|
311
|
-
}) => ({
|
|
312
|
-
decorator: event.decorator
|
|
313
|
-
}),
|
|
314
|
-
actions: [({
|
|
315
|
-
decorator
|
|
316
|
-
}) => [{
|
|
317
|
-
type: "decorator.add",
|
|
318
|
-
decorator
|
|
319
|
-
}, {
|
|
320
|
-
type: "reselect"
|
|
321
|
-
}]]
|
|
322
|
-
}, decoratorRemove = {
|
|
323
|
-
on: "decorator.remove",
|
|
324
|
-
guard: ({
|
|
325
|
-
event
|
|
326
|
-
}) => ({
|
|
327
|
-
decorator: event.decorator
|
|
328
|
-
}),
|
|
329
|
-
actions: [({
|
|
330
|
-
decorator
|
|
331
|
-
}) => [{
|
|
332
|
-
type: "decorator.remove",
|
|
333
|
-
decorator
|
|
334
|
-
}, {
|
|
335
|
-
type: "reselect"
|
|
336
|
-
}]]
|
|
337
|
-
}, decoratorToggle = {
|
|
338
|
-
on: "decorator.toggle",
|
|
339
|
-
guard: ({
|
|
340
|
-
event
|
|
341
|
-
}) => ({
|
|
342
|
-
decorator: event.decorator
|
|
343
|
-
}),
|
|
344
|
-
actions: [({
|
|
345
|
-
decorator
|
|
346
|
-
}) => [{
|
|
347
|
-
type: "decorator.toggle",
|
|
348
|
-
decorator
|
|
349
|
-
}, {
|
|
350
|
-
type: "reselect"
|
|
351
|
-
}]]
|
|
352
|
-
}, coreDecoratorBehaviors = {
|
|
353
|
-
decoratorAdd,
|
|
354
|
-
decoratorRemove,
|
|
355
|
-
decoratorToggle
|
|
356
|
-
}, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
|
|
357
|
-
on: "delete.backward",
|
|
358
|
-
guard: ({
|
|
359
|
-
context
|
|
360
|
-
}) => {
|
|
361
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
362
|
-
context
|
|
363
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
364
|
-
context
|
|
365
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
366
|
-
context
|
|
367
|
-
});
|
|
368
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
369
|
-
focusTextBlock
|
|
370
|
-
} : !1;
|
|
371
|
-
},
|
|
372
|
-
actions: [({
|
|
373
|
-
focusTextBlock
|
|
374
|
-
}) => [{
|
|
375
|
-
type: "text block.unset",
|
|
376
|
-
props: ["listItem", "level"],
|
|
377
|
-
at: focusTextBlock.path
|
|
378
|
-
}]]
|
|
379
|
-
}, unindentListOnBackspace = {
|
|
380
|
-
on: "delete.backward",
|
|
381
|
-
guard: ({
|
|
382
|
-
context
|
|
383
|
-
}) => {
|
|
384
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
385
|
-
context
|
|
386
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
387
|
-
context
|
|
388
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
389
|
-
context
|
|
390
|
-
});
|
|
391
|
-
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 ? {
|
|
392
|
-
focusTextBlock,
|
|
393
|
-
level: focusTextBlock.node.level - 1
|
|
394
|
-
} : !1;
|
|
395
|
-
},
|
|
396
|
-
actions: [({
|
|
397
|
-
focusTextBlock,
|
|
398
|
-
level
|
|
399
|
-
}) => [{
|
|
400
|
-
type: "text block.set",
|
|
401
|
-
level,
|
|
402
|
-
at: focusTextBlock.path
|
|
403
|
-
}]]
|
|
404
|
-
}, clearListOnEnter = {
|
|
405
|
-
on: "insert.break",
|
|
406
|
-
guard: ({
|
|
407
|
-
context
|
|
408
|
-
}) => {
|
|
409
|
-
const focusListBlock = selector_getTextBefore.getFocusListBlock({
|
|
410
|
-
context
|
|
411
|
-
}), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
412
|
-
context
|
|
413
|
-
});
|
|
414
|
-
return !focusListBlock || !selectionCollapsed || !isEmptyTextBlock(focusListBlock.node) ? !1 : {
|
|
415
|
-
focusListBlock
|
|
416
|
-
};
|
|
417
|
-
},
|
|
418
|
-
actions: [({
|
|
419
|
-
focusListBlock
|
|
420
|
-
}) => [{
|
|
421
|
-
type: "text block.unset",
|
|
422
|
-
props: ["listItem", "level"],
|
|
423
|
-
at: focusListBlock.path
|
|
424
|
-
}]]
|
|
425
|
-
}, indentListOnTab = {
|
|
426
|
-
on: "key.down",
|
|
427
|
-
guard: ({
|
|
428
|
-
context,
|
|
429
|
-
event
|
|
430
|
-
}) => {
|
|
431
|
-
if (!isHotkey("Tab", event.keyboardEvent))
|
|
432
|
-
return !1;
|
|
433
|
-
const selectedBlocks = selector_getTextBefore.getSelectedBlocks({
|
|
434
|
-
context
|
|
435
|
-
}), guards = selector_getTextBefore.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
436
|
-
node: block.node,
|
|
437
|
-
path: block.path
|
|
438
|
-
}] : []);
|
|
439
|
-
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
440
|
-
selectedListBlocks
|
|
441
|
-
} : !1;
|
|
442
|
-
},
|
|
443
|
-
actions: [({
|
|
444
|
-
selectedListBlocks
|
|
445
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
446
|
-
type: "text block.set",
|
|
447
|
-
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
|
|
448
|
-
at: selectedListBlock.path
|
|
449
|
-
}))]
|
|
450
|
-
}, unindentListOnShiftTab = {
|
|
451
|
-
on: "key.down",
|
|
452
|
-
guard: ({
|
|
453
|
-
context,
|
|
454
|
-
event
|
|
455
|
-
}) => {
|
|
456
|
-
if (!isHotkey("Shift+Tab", event.keyboardEvent))
|
|
457
|
-
return !1;
|
|
458
|
-
const selectedBlocks = selector_getTextBefore.getSelectedBlocks({
|
|
459
|
-
context
|
|
460
|
-
}), guards = selector_getTextBefore.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
461
|
-
node: block.node,
|
|
462
|
-
path: block.path
|
|
463
|
-
}] : []);
|
|
464
|
-
return selectedListBlocks.length === selectedBlocks.length ? {
|
|
465
|
-
selectedListBlocks
|
|
466
|
-
} : !1;
|
|
467
|
-
},
|
|
468
|
-
actions: [({
|
|
469
|
-
selectedListBlocks
|
|
470
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
471
|
-
type: "text block.set",
|
|
472
|
-
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
|
|
473
|
-
at: selectedListBlock.path
|
|
474
|
-
}))]
|
|
475
|
-
}, coreListBehaviors = {
|
|
476
|
-
clearListOnBackspace,
|
|
477
|
-
unindentListOnBackspace,
|
|
478
|
-
clearListOnEnter,
|
|
479
|
-
indentListOnTab,
|
|
480
|
-
unindentListOnShiftTab
|
|
481
|
-
}, softReturn = {
|
|
482
|
-
on: "insert.soft break",
|
|
483
|
-
actions: [() => [{
|
|
484
|
-
type: "insert.text",
|
|
485
|
-
text: `
|
|
486
|
-
`
|
|
487
|
-
}]]
|
|
488
|
-
}, 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 = {
|
|
489
|
-
softReturn,
|
|
490
|
-
decorators: coreDecoratorBehaviors,
|
|
491
|
-
blockObjects: coreBlockObjectBehaviors,
|
|
492
|
-
lists: coreListBehaviors
|
|
493
|
-
};
|
|
494
|
-
function createLinkBehaviors(config) {
|
|
495
|
-
const pasteLinkOnSelection = {
|
|
496
|
-
on: "paste",
|
|
497
|
-
guard: ({
|
|
498
|
-
context,
|
|
499
|
-
event
|
|
500
|
-
}) => {
|
|
501
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
502
|
-
context
|
|
503
|
-
}), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
504
|
-
url,
|
|
505
|
-
schema: context.schema
|
|
506
|
-
}) : void 0;
|
|
507
|
-
return annotation && !selectionCollapsed ? {
|
|
508
|
-
annotation
|
|
509
|
-
} : !1;
|
|
510
|
-
},
|
|
511
|
-
actions: [({
|
|
512
|
-
annotation
|
|
513
|
-
}) => [{
|
|
514
|
-
type: "annotation.add",
|
|
515
|
-
annotation
|
|
516
|
-
}]]
|
|
517
|
-
}, pasteLinkAtCaret = {
|
|
518
|
-
on: "paste",
|
|
519
|
-
guard: ({
|
|
520
|
-
context,
|
|
521
|
-
event
|
|
522
|
-
}) => {
|
|
523
|
-
const focusSpan = selector_getTextBefore.getFocusSpan({
|
|
524
|
-
context
|
|
525
|
-
}), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
526
|
-
context
|
|
527
|
-
});
|
|
528
|
-
if (!focusSpan || !selectionCollapsed)
|
|
529
|
-
return !1;
|
|
530
|
-
const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
531
|
-
url,
|
|
532
|
-
schema: context.schema
|
|
533
|
-
}) : void 0;
|
|
534
|
-
return url && annotation && selectionCollapsed ? {
|
|
535
|
-
focusSpan,
|
|
536
|
-
annotation,
|
|
537
|
-
url
|
|
538
|
-
} : !1;
|
|
539
|
-
},
|
|
540
|
-
actions: [({
|
|
541
|
-
annotation,
|
|
542
|
-
url
|
|
543
|
-
}) => [{
|
|
544
|
-
type: "insert.span",
|
|
545
|
-
text: url,
|
|
546
|
-
annotations: [annotation]
|
|
547
|
-
}]]
|
|
548
|
-
};
|
|
549
|
-
return [pasteLinkOnSelection, pasteLinkAtCaret];
|
|
550
|
-
}
|
|
551
|
-
function looksLikeUrl(text) {
|
|
552
|
-
let looksLikeUrl2 = !1;
|
|
553
|
-
try {
|
|
554
|
-
new URL(text), looksLikeUrl2 = !0;
|
|
555
|
-
} catch {
|
|
556
|
-
}
|
|
557
|
-
return looksLikeUrl2;
|
|
558
|
-
}
|
|
559
|
-
function blockOffsetToSpanSelectionPoint({
|
|
560
|
-
value,
|
|
561
|
-
blockOffset
|
|
562
|
-
}) {
|
|
563
|
-
let offsetLeft = blockOffset.offset, selectionPoint;
|
|
564
|
-
for (const block of value)
|
|
565
|
-
if (block._key === blockOffset.path[0]._key && types.isPortableTextTextBlock(block)) {
|
|
566
|
-
for (const child of block.children)
|
|
567
|
-
if (types.isPortableTextSpan(child)) {
|
|
568
|
-
if (offsetLeft === 0) {
|
|
569
|
-
selectionPoint = {
|
|
570
|
-
path: [...blockOffset.path, "children", {
|
|
571
|
-
_key: child._key
|
|
572
|
-
}],
|
|
573
|
-
offset: 0
|
|
574
|
-
};
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
if (offsetLeft <= child.text.length) {
|
|
578
|
-
selectionPoint = {
|
|
579
|
-
path: [...blockOffset.path, "children", {
|
|
580
|
-
_key: child._key
|
|
581
|
-
}],
|
|
582
|
-
offset: offsetLeft
|
|
583
|
-
};
|
|
584
|
-
break;
|
|
585
|
-
}
|
|
586
|
-
offsetLeft -= child.text.length;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
return selectionPoint;
|
|
590
|
-
}
|
|
591
|
-
function spanSelectionPointToBlockOffset({
|
|
592
|
-
value,
|
|
593
|
-
selectionPoint
|
|
594
|
-
}) {
|
|
595
|
-
let offset = 0;
|
|
596
|
-
for (const block of value)
|
|
597
|
-
if (block._key === selectionPoint.path[0]._key && types.isPortableTextTextBlock(block)) {
|
|
598
|
-
for (const child of block.children)
|
|
599
|
-
if (types.isPortableTextSpan(child)) {
|
|
600
|
-
if (child._key === selectionPoint.path[2]._key)
|
|
601
|
-
return {
|
|
602
|
-
path: [{
|
|
603
|
-
_key: block._key
|
|
604
|
-
}],
|
|
605
|
-
offset: offset + selectionPoint.offset
|
|
606
|
-
};
|
|
607
|
-
offset += child.text.length;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
function createMarkdownBehaviors(config) {
|
|
612
|
-
const automaticBlockquoteOnSpace = {
|
|
613
|
-
on: "insert.text",
|
|
614
|
-
guard: ({
|
|
615
|
-
context,
|
|
616
|
-
event
|
|
617
|
-
}) => {
|
|
618
|
-
if (event.text !== " ")
|
|
619
|
-
return !1;
|
|
620
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
621
|
-
context
|
|
622
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
623
|
-
context
|
|
624
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
625
|
-
context
|
|
626
|
-
});
|
|
627
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
628
|
-
return !1;
|
|
629
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
630
|
-
value: context.value,
|
|
631
|
-
selectionPoint: {
|
|
632
|
-
path: [{
|
|
633
|
-
_key: focusTextBlock.node._key
|
|
634
|
-
}, "children", {
|
|
635
|
-
_key: focusSpan.node._key
|
|
636
|
-
}],
|
|
637
|
-
offset: context.selection.focus.offset
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
if (!blockOffset)
|
|
641
|
-
return !1;
|
|
642
|
-
const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(context);
|
|
643
|
-
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
644
|
-
focusTextBlock,
|
|
645
|
-
style: blockquoteStyle
|
|
646
|
-
} : !1;
|
|
647
|
-
},
|
|
648
|
-
actions: [() => [{
|
|
649
|
-
type: "insert.text",
|
|
650
|
-
text: " "
|
|
651
|
-
}], ({
|
|
652
|
-
focusTextBlock,
|
|
653
|
-
style
|
|
654
|
-
}) => [{
|
|
655
|
-
type: "text block.unset",
|
|
656
|
-
props: ["listItem", "level"],
|
|
657
|
-
at: focusTextBlock.path
|
|
658
|
-
}, {
|
|
659
|
-
type: "text block.set",
|
|
660
|
-
style,
|
|
661
|
-
at: focusTextBlock.path
|
|
662
|
-
}, {
|
|
663
|
-
type: "delete.text",
|
|
664
|
-
anchor: {
|
|
665
|
-
path: focusTextBlock.path,
|
|
666
|
-
offset: 0
|
|
667
|
-
},
|
|
668
|
-
focus: {
|
|
669
|
-
path: focusTextBlock.path,
|
|
670
|
-
offset: 2
|
|
671
|
-
}
|
|
672
|
-
}]]
|
|
673
|
-
}, automaticHr = {
|
|
674
|
-
on: "insert.text",
|
|
675
|
-
guard: ({
|
|
676
|
-
context,
|
|
677
|
-
event
|
|
678
|
-
}) => {
|
|
679
|
-
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
680
|
-
if (hrCharacter === void 0)
|
|
681
|
-
return !1;
|
|
682
|
-
const hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_getTextBefore.getFocusTextBlock({
|
|
683
|
-
context
|
|
684
|
-
}), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
685
|
-
context
|
|
686
|
-
});
|
|
687
|
-
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
688
|
-
return !1;
|
|
689
|
-
const textBefore = selector_getTextBefore.getBlockTextBefore({
|
|
690
|
-
context
|
|
691
|
-
}), hrBlockOffsets = {
|
|
692
|
-
anchor: {
|
|
693
|
-
path: focusBlock.path,
|
|
694
|
-
offset: 0
|
|
695
|
-
},
|
|
696
|
-
focus: {
|
|
697
|
-
path: focusBlock.path,
|
|
698
|
-
offset: 3
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
return textBefore === `${hrCharacter}${hrCharacter}` ? {
|
|
702
|
-
hrObject,
|
|
703
|
-
focusBlock,
|
|
704
|
-
hrCharacter,
|
|
705
|
-
hrBlockOffsets
|
|
706
|
-
} : !1;
|
|
707
|
-
},
|
|
708
|
-
actions: [({
|
|
709
|
-
hrCharacter
|
|
710
|
-
}) => [{
|
|
711
|
-
type: "insert.text",
|
|
712
|
-
text: hrCharacter
|
|
713
|
-
}], ({
|
|
714
|
-
hrObject,
|
|
715
|
-
hrBlockOffsets
|
|
716
|
-
}) => [{
|
|
717
|
-
type: "insert.block object",
|
|
718
|
-
placement: "before",
|
|
719
|
-
blockObject: hrObject
|
|
720
|
-
}, {
|
|
721
|
-
type: "delete.text",
|
|
722
|
-
...hrBlockOffsets
|
|
723
|
-
}]]
|
|
724
|
-
}, automaticHrOnPaste = {
|
|
725
|
-
on: "paste",
|
|
726
|
-
guard: ({
|
|
727
|
-
context,
|
|
728
|
-
event
|
|
729
|
-
}) => {
|
|
730
|
-
const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(context), focusBlock = selector_getTextBefore.getFocusBlock({
|
|
731
|
-
context
|
|
732
|
-
});
|
|
733
|
-
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
734
|
-
hrCharacters,
|
|
735
|
-
hrObject,
|
|
736
|
-
focusBlock
|
|
737
|
-
};
|
|
738
|
-
},
|
|
739
|
-
actions: [({
|
|
740
|
-
hrCharacters
|
|
741
|
-
}) => [{
|
|
742
|
-
type: "insert.text",
|
|
743
|
-
text: hrCharacters
|
|
744
|
-
}], ({
|
|
745
|
-
hrObject,
|
|
746
|
-
focusBlock
|
|
747
|
-
}) => types.isPortableTextTextBlock(focusBlock.node) ? [{
|
|
748
|
-
type: "insert.text block",
|
|
749
|
-
textBlock: {
|
|
750
|
-
children: focusBlock.node.children
|
|
751
|
-
},
|
|
752
|
-
placement: "after"
|
|
753
|
-
}, {
|
|
754
|
-
type: "insert.block object",
|
|
755
|
-
blockObject: hrObject,
|
|
756
|
-
placement: "after"
|
|
757
|
-
}, {
|
|
758
|
-
type: "delete.block",
|
|
759
|
-
blockPath: focusBlock.path
|
|
760
|
-
}] : [{
|
|
761
|
-
type: "insert.block object",
|
|
762
|
-
blockObject: hrObject,
|
|
763
|
-
placement: "after"
|
|
764
|
-
}]]
|
|
765
|
-
}, automaticHeadingOnSpace = {
|
|
766
|
-
on: "insert.text",
|
|
767
|
-
guard: ({
|
|
768
|
-
context,
|
|
769
|
-
event
|
|
770
|
-
}) => {
|
|
771
|
-
if (event.text !== " ")
|
|
772
|
-
return !1;
|
|
773
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
774
|
-
context
|
|
775
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
776
|
-
context
|
|
777
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
778
|
-
context
|
|
779
|
-
});
|
|
780
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
781
|
-
return !1;
|
|
782
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
783
|
-
value: context.value,
|
|
784
|
-
selectionPoint: {
|
|
785
|
-
path: [{
|
|
786
|
-
_key: focusTextBlock.node._key
|
|
787
|
-
}, "children", {
|
|
788
|
-
_key: focusSpan.node._key
|
|
789
|
-
}],
|
|
790
|
-
offset: context.selection.focus.offset
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
if (!blockOffset)
|
|
794
|
-
return !1;
|
|
795
|
-
const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
796
|
-
if (blockOffset.offset !== level)
|
|
797
|
-
return !1;
|
|
798
|
-
const style = level !== void 0 ? config.headingStyle?.({
|
|
799
|
-
schema: context.schema,
|
|
800
|
-
level
|
|
801
|
-
}) : void 0;
|
|
802
|
-
return level !== void 0 && style !== void 0 ? {
|
|
803
|
-
focusTextBlock,
|
|
804
|
-
style,
|
|
805
|
-
level
|
|
806
|
-
} : !1;
|
|
807
|
-
},
|
|
808
|
-
actions: [() => [{
|
|
809
|
-
type: "insert.text",
|
|
810
|
-
text: " "
|
|
811
|
-
}], ({
|
|
812
|
-
focusTextBlock,
|
|
813
|
-
style,
|
|
814
|
-
level
|
|
815
|
-
}) => [{
|
|
816
|
-
type: "text block.unset",
|
|
817
|
-
props: ["listItem", "level"],
|
|
818
|
-
at: focusTextBlock.path
|
|
819
|
-
}, {
|
|
820
|
-
type: "text block.set",
|
|
821
|
-
style,
|
|
822
|
-
at: focusTextBlock.path
|
|
823
|
-
}, {
|
|
824
|
-
type: "delete.text",
|
|
825
|
-
anchor: {
|
|
826
|
-
path: focusTextBlock.path,
|
|
827
|
-
offset: 0
|
|
828
|
-
},
|
|
829
|
-
focus: {
|
|
830
|
-
path: focusTextBlock.path,
|
|
831
|
-
offset: level + 1
|
|
832
|
-
}
|
|
833
|
-
}]]
|
|
834
|
-
}, clearStyleOnBackspace = {
|
|
835
|
-
on: "delete.backward",
|
|
836
|
-
guard: ({
|
|
837
|
-
context
|
|
838
|
-
}) => {
|
|
839
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
840
|
-
context
|
|
841
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
842
|
-
context
|
|
843
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
844
|
-
context
|
|
845
|
-
});
|
|
846
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
847
|
-
return !1;
|
|
848
|
-
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.defaultStyle?.(context);
|
|
849
|
-
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
850
|
-
defaultStyle,
|
|
851
|
-
focusTextBlock
|
|
852
|
-
} : !1;
|
|
853
|
-
},
|
|
854
|
-
actions: [({
|
|
855
|
-
defaultStyle,
|
|
856
|
-
focusTextBlock
|
|
857
|
-
}) => [{
|
|
858
|
-
type: "text block.set",
|
|
859
|
-
style: defaultStyle,
|
|
860
|
-
at: focusTextBlock.path
|
|
861
|
-
}]]
|
|
862
|
-
}, automaticListOnSpace = {
|
|
863
|
-
on: "insert.text",
|
|
864
|
-
guard: ({
|
|
865
|
-
context,
|
|
866
|
-
event
|
|
867
|
-
}) => {
|
|
868
|
-
if (event.text !== " ")
|
|
869
|
-
return !1;
|
|
870
|
-
const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
|
|
871
|
-
context
|
|
872
|
-
}), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
|
|
873
|
-
context
|
|
874
|
-
}), focusSpan = selector_getTextBefore.getFocusSpan({
|
|
875
|
-
context
|
|
876
|
-
});
|
|
877
|
-
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
878
|
-
return !1;
|
|
879
|
-
const blockOffset = spanSelectionPointToBlockOffset({
|
|
880
|
-
value: context.value,
|
|
881
|
-
selectionPoint: {
|
|
882
|
-
path: [{
|
|
883
|
-
_key: focusTextBlock.node._key
|
|
884
|
-
}, "children", {
|
|
885
|
-
_key: focusSpan.node._key
|
|
886
|
-
}],
|
|
887
|
-
offset: context.selection.focus.offset
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
if (!blockOffset)
|
|
891
|
-
return !1;
|
|
892
|
-
const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
893
|
-
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
894
|
-
return {
|
|
895
|
-
focusTextBlock,
|
|
896
|
-
listItem: unorderedListStyle,
|
|
897
|
-
listItemLength: 1,
|
|
898
|
-
style: defaultStyle
|
|
899
|
-
};
|
|
900
|
-
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
901
|
-
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
902
|
-
focusTextBlock,
|
|
903
|
-
listItem: orderedListStyle,
|
|
904
|
-
listItemLength: 2,
|
|
905
|
-
style: defaultStyle
|
|
906
|
-
} : !1;
|
|
907
|
-
},
|
|
908
|
-
actions: [() => [{
|
|
909
|
-
type: "insert.text",
|
|
910
|
-
text: " "
|
|
911
|
-
}], ({
|
|
912
|
-
focusTextBlock,
|
|
913
|
-
style,
|
|
914
|
-
listItem,
|
|
915
|
-
listItemLength
|
|
916
|
-
}) => [{
|
|
917
|
-
type: "text block.set",
|
|
918
|
-
listItem,
|
|
919
|
-
level: 1,
|
|
920
|
-
style,
|
|
921
|
-
at: focusTextBlock.path
|
|
922
|
-
}, {
|
|
923
|
-
type: "delete.text",
|
|
924
|
-
anchor: {
|
|
925
|
-
path: focusTextBlock.path,
|
|
926
|
-
offset: 0
|
|
927
|
-
},
|
|
928
|
-
focus: {
|
|
929
|
-
path: focusTextBlock.path,
|
|
930
|
-
offset: listItemLength + 1
|
|
931
|
-
}
|
|
932
|
-
}]]
|
|
933
|
-
};
|
|
934
|
-
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
|
|
935
|
-
}
|
|
936
19
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
20
|
+
var _a, _b, _c;
|
|
937
21
|
if (!portableTextType)
|
|
938
22
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
939
|
-
const blockType = portableTextType.of
|
|
23
|
+
const blockType = (_a = portableTextType.of) == null ? void 0 : _a.find(findBlockType);
|
|
940
24
|
if (!blockType)
|
|
941
25
|
throw new Error("Block type is not defined in this schema (required)");
|
|
942
|
-
const childrenField = blockType.fields
|
|
26
|
+
const childrenField = (_b = blockType.fields) == null ? void 0 : _b.find((field) => field.name === "children");
|
|
943
27
|
if (!childrenField)
|
|
944
28
|
throw new Error("Children field for block type found in schema (required)");
|
|
945
29
|
const ofType = childrenField.type.of;
|
|
@@ -948,7 +32,7 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
948
32
|
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
949
33
|
if (!spanType)
|
|
950
34
|
throw new Error("Span type not found in schema (required)");
|
|
951
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of
|
|
35
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = ((_c = portableTextType.of) == null ? void 0 : _c.filter((field) => field.name !== blockType.name)) || [];
|
|
952
36
|
return {
|
|
953
37
|
styles: resolveEnabledStyles(blockType),
|
|
954
38
|
decorators: resolveEnabledDecorators(spanType),
|
|
@@ -962,10 +46,11 @@ function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
|
962
46
|
};
|
|
963
47
|
}
|
|
964
48
|
function resolveEnabledStyles(blockType) {
|
|
965
|
-
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
const styleField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "style");
|
|
966
51
|
if (!styleField)
|
|
967
52
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
968
|
-
const textStyles = styleField.type.options
|
|
53
|
+
const textStyles = ((_b = styleField.type.options) == null ? void 0 : _b.list) && ((_c = styleField.type.options.list) == null ? void 0 : _c.filter((style) => style.value));
|
|
969
54
|
if (!textStyles || textStyles.length === 0)
|
|
970
55
|
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
971
56
|
return textStyles;
|
|
@@ -974,10 +59,11 @@ function resolveEnabledDecorators(spanType) {
|
|
|
974
59
|
return spanType.decorators;
|
|
975
60
|
}
|
|
976
61
|
function resolveEnabledListItems(blockType) {
|
|
977
|
-
|
|
62
|
+
var _a, _b;
|
|
63
|
+
const listField = (_a = blockType.fields) == null ? void 0 : _a.find((btField) => btField.name === "listItem");
|
|
978
64
|
if (!listField)
|
|
979
65
|
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
980
|
-
const listItems = listField.type.options
|
|
66
|
+
const listItems = ((_b = listField.type.options) == null ? void 0 : _b.list) && listField.type.options.list.filter((list) => list.value);
|
|
981
67
|
if (!listItems)
|
|
982
68
|
throw new Error("The list field need at least to be an empty array");
|
|
983
69
|
return listItems;
|
|
@@ -985,11 +71,20 @@ function resolveEnabledListItems(blockType) {
|
|
|
985
71
|
function findBlockType(type) {
|
|
986
72
|
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
987
73
|
}
|
|
74
|
+
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) => {
|
|
75
|
+
for (var prop in b || (b = {}))
|
|
76
|
+
__hasOwnProp$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
77
|
+
if (__getOwnPropSymbols$p)
|
|
78
|
+
for (var prop of __getOwnPropSymbols$p(b))
|
|
79
|
+
__propIsEnum$p.call(b, prop) && __defNormalProp$p(a, prop, b[prop]);
|
|
80
|
+
return a;
|
|
81
|
+
}, __spreadProps$j = (a, b) => __defProps$j(a, __getOwnPropDescs$j(b));
|
|
988
82
|
function defineSchema(definition) {
|
|
989
83
|
return definition;
|
|
990
84
|
}
|
|
991
85
|
function compileSchemaDefinition(definition) {
|
|
992
|
-
|
|
86
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
87
|
+
const blockObjects = (_b = (_a = definition == null ? void 0 : definition.blockObjects) == null ? void 0 : _a.map((blockObject) => types.defineType({
|
|
993
88
|
type: "object",
|
|
994
89
|
// Very naive way to work around `SanitySchema.compile` adding default
|
|
995
90
|
// fields to objects with the name `image`
|
|
@@ -997,13 +92,13 @@ function compileSchemaDefinition(definition) {
|
|
|
997
92
|
title: blockObject.title,
|
|
998
93
|
icon: blockObject.icon,
|
|
999
94
|
fields: []
|
|
1000
|
-
}))
|
|
95
|
+
}))) != null ? _b : [], inlineObjects = (_d = (_c = definition == null ? void 0 : definition.inlineObjects) == null ? void 0 : _c.map((inlineObject) => types.defineType({
|
|
1001
96
|
type: "object",
|
|
1002
97
|
name: inlineObject.name,
|
|
1003
98
|
title: inlineObject.title,
|
|
1004
99
|
icon: inlineObject.icon,
|
|
1005
100
|
fields: []
|
|
1006
|
-
}))
|
|
101
|
+
}))) != null ? _d : [], portableTextSchema = types.defineField({
|
|
1007
102
|
type: "array",
|
|
1008
103
|
name: "portable-text",
|
|
1009
104
|
of: [...blockObjects.map((blockObject) => ({
|
|
@@ -1015,43 +110,49 @@ function compileSchemaDefinition(definition) {
|
|
|
1015
110
|
type: inlineObject.name
|
|
1016
111
|
})),
|
|
1017
112
|
marks: {
|
|
1018
|
-
decorators: definition
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
113
|
+
decorators: (_f = (_e = definition == null ? void 0 : definition.decorators) == null ? void 0 : _e.map((decorator) => {
|
|
114
|
+
var _a2;
|
|
115
|
+
return {
|
|
116
|
+
title: (_a2 = decorator.title) != null ? _a2 : startCase__default.default(decorator.name),
|
|
117
|
+
value: decorator.name,
|
|
118
|
+
icon: decorator.icon
|
|
119
|
+
};
|
|
120
|
+
})) != null ? _f : [],
|
|
121
|
+
annotations: (_h = (_g = definition == null ? void 0 : definition.annotations) == null ? void 0 : _g.map((annotation) => ({
|
|
1024
122
|
name: annotation.name,
|
|
1025
123
|
type: "object",
|
|
1026
124
|
title: annotation.title,
|
|
1027
125
|
icon: annotation.icon
|
|
1028
|
-
}))
|
|
126
|
+
}))) != null ? _h : []
|
|
1029
127
|
},
|
|
1030
|
-
lists: definition
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
128
|
+
lists: (_j = (_i = definition == null ? void 0 : definition.lists) == null ? void 0 : _i.map((list) => {
|
|
129
|
+
var _a2;
|
|
130
|
+
return {
|
|
131
|
+
value: list.name,
|
|
132
|
+
title: (_a2 = list.title) != null ? _a2 : startCase__default.default(list.name),
|
|
133
|
+
icon: list.icon
|
|
134
|
+
};
|
|
135
|
+
})) != null ? _j : [],
|
|
136
|
+
styles: (_l = (_k = definition == null ? void 0 : definition.styles) == null ? void 0 : _k.map((style) => {
|
|
137
|
+
var _a2;
|
|
138
|
+
return {
|
|
139
|
+
value: style.name,
|
|
140
|
+
title: (_a2 = style.title) != null ? _a2 : startCase__default.default(style.name),
|
|
141
|
+
icon: style.icon
|
|
142
|
+
};
|
|
143
|
+
})) != null ? _l : []
|
|
1040
144
|
}]
|
|
1041
145
|
}), schema$1 = schema.Schema.compile({
|
|
1042
146
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
1043
147
|
}).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema$1);
|
|
1044
|
-
return {
|
|
1045
|
-
|
|
1046
|
-
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
1047
|
-
...blockObject,
|
|
148
|
+
return __spreadProps$j(__spreadValues$p({}, pteSchema), {
|
|
149
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
|
|
1048
150
|
name: "image",
|
|
1049
|
-
type: {
|
|
1050
|
-
...blockObject.type,
|
|
151
|
+
type: __spreadProps$j(__spreadValues$p({}, blockObject.type), {
|
|
1051
152
|
name: "image"
|
|
1052
|
-
}
|
|
1053
|
-
} : blockObject)
|
|
1054
|
-
};
|
|
153
|
+
})
|
|
154
|
+
}) : blockObject)
|
|
155
|
+
});
|
|
1055
156
|
}
|
|
1056
157
|
const rootName = "sanity-pte:";
|
|
1057
158
|
var debug$l = debug__default.default(rootName);
|
|
@@ -1186,6 +287,22 @@ function normalizeSelection(selection, value) {
|
|
|
1186
287
|
backward: selection.backward
|
|
1187
288
|
} : null;
|
|
1188
289
|
}
|
|
290
|
+
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) => {
|
|
291
|
+
for (var prop in b || (b = {}))
|
|
292
|
+
__hasOwnProp$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
293
|
+
if (__getOwnPropSymbols$o)
|
|
294
|
+
for (var prop of __getOwnPropSymbols$o(b))
|
|
295
|
+
__propIsEnum$o.call(b, prop) && __defNormalProp$o(a, prop, b[prop]);
|
|
296
|
+
return a;
|
|
297
|
+
}, __spreadProps$i = (a, b) => __defProps$i(a, __getOwnPropDescs$i(b)), __objRest$3 = (source, exclude) => {
|
|
298
|
+
var target = {};
|
|
299
|
+
for (var prop in source)
|
|
300
|
+
__hasOwnProp$o.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
301
|
+
if (source != null && __getOwnPropSymbols$o)
|
|
302
|
+
for (var prop of __getOwnPropSymbols$o(source))
|
|
303
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$o.call(source, prop) && (target[prop] = source[prop]);
|
|
304
|
+
return target;
|
|
305
|
+
};
|
|
1189
306
|
const VOID_CHILD_KEY = "void-child";
|
|
1190
307
|
function keepObjectEquality(object, keyMap) {
|
|
1191
308
|
const value = keyMap[object._key];
|
|
@@ -1195,11 +312,13 @@ function toSlateValue(value, {
|
|
|
1195
312
|
schemaTypes
|
|
1196
313
|
}, keyMap = {}) {
|
|
1197
314
|
return value && Array.isArray(value) ? value.map((block) => {
|
|
1198
|
-
const {
|
|
315
|
+
const _a = block, {
|
|
1199
316
|
_type,
|
|
1200
|
-
_key
|
|
1201
|
-
|
|
1202
|
-
|
|
317
|
+
_key
|
|
318
|
+
} = _a, rest = __objRest$3(_a, [
|
|
319
|
+
"_type",
|
|
320
|
+
"_key"
|
|
321
|
+
]), voidChildren = [{
|
|
1203
322
|
_key: VOID_CHILD_KEY,
|
|
1204
323
|
_type: "span",
|
|
1205
324
|
text: "",
|
|
@@ -1209,11 +328,13 @@ function toSlateValue(value, {
|
|
|
1209
328
|
const textBlock = block;
|
|
1210
329
|
let hasInlines = !1;
|
|
1211
330
|
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
1212
|
-
const {
|
|
331
|
+
const _a2 = child, {
|
|
1213
332
|
_type: cType,
|
|
1214
|
-
_key: cKey
|
|
1215
|
-
|
|
1216
|
-
|
|
333
|
+
_key: cKey
|
|
334
|
+
} = _a2, cRest = __objRest$3(_a2, [
|
|
335
|
+
"_type",
|
|
336
|
+
"_key"
|
|
337
|
+
]);
|
|
1217
338
|
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
1218
339
|
_type: cType,
|
|
1219
340
|
_key: cKey,
|
|
@@ -1222,12 +343,12 @@ function toSlateValue(value, {
|
|
|
1222
343
|
__inline: !0
|
|
1223
344
|
}, keyMap)) : child;
|
|
1224
345
|
});
|
|
1225
|
-
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality({
|
|
346
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].value), keepObjectEquality(__spreadProps$i(__spreadValues$o({
|
|
1226
347
|
_type,
|
|
1227
|
-
_key
|
|
1228
|
-
|
|
348
|
+
_key
|
|
349
|
+
}, rest), {
|
|
1229
350
|
children
|
|
1230
|
-
}, keyMap));
|
|
351
|
+
}), keyMap));
|
|
1231
352
|
}
|
|
1232
353
|
return keepObjectEquality({
|
|
1233
354
|
_type,
|
|
@@ -1253,40 +374,42 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
|
1253
374
|
} = child;
|
|
1254
375
|
if ("value" in child && _cType !== "span") {
|
|
1255
376
|
hasInlines = !0;
|
|
1256
|
-
const {
|
|
377
|
+
const _a = child, {
|
|
1257
378
|
value: v,
|
|
1258
379
|
_key: k,
|
|
1259
380
|
_type: t,
|
|
1260
381
|
__inline: _i,
|
|
1261
|
-
children: _c
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
382
|
+
children: _c
|
|
383
|
+
} = _a, rest = __objRest$3(_a, [
|
|
384
|
+
"value",
|
|
385
|
+
"_key",
|
|
386
|
+
"_type",
|
|
387
|
+
"__inline",
|
|
388
|
+
"children"
|
|
389
|
+
]);
|
|
390
|
+
return keepObjectEquality(__spreadProps$i(__spreadValues$o(__spreadValues$o({}, rest), v), {
|
|
1267
391
|
_key: k,
|
|
1268
392
|
_type: t
|
|
1269
|
-
}, keyMap);
|
|
393
|
+
}), keyMap);
|
|
1270
394
|
}
|
|
1271
395
|
return child;
|
|
1272
396
|
});
|
|
1273
|
-
return hasInlines ? keepObjectEquality({
|
|
1274
|
-
...block,
|
|
397
|
+
return hasInlines ? keepObjectEquality(__spreadProps$i(__spreadValues$o({}, block), {
|
|
1275
398
|
children,
|
|
1276
399
|
_key,
|
|
1277
400
|
_type
|
|
1278
|
-
}, keyMap) : block;
|
|
401
|
+
}), keyMap) : block;
|
|
1279
402
|
}
|
|
1280
403
|
const blockValue = "value" in block && block.value;
|
|
1281
|
-
return keepObjectEquality({
|
|
404
|
+
return keepObjectEquality(__spreadValues$o({
|
|
1282
405
|
_key,
|
|
1283
|
-
_type
|
|
1284
|
-
|
|
1285
|
-
}, keyMap);
|
|
406
|
+
_type
|
|
407
|
+
}, typeof blockValue == "object" ? blockValue : {}), keyMap);
|
|
1286
408
|
});
|
|
1287
409
|
}
|
|
1288
410
|
function isEqualToEmptyEditor(children, schemaTypes) {
|
|
1289
|
-
|
|
411
|
+
var _a;
|
|
412
|
+
return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.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 && slate.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 === "";
|
|
1290
413
|
}
|
|
1291
414
|
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) => {
|
|
1292
415
|
const $ = reactCompilerRuntime.c(4);
|
|
@@ -1586,6 +709,14 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
1586
709
|
] }), $[41] = children, $[42] = handleDrag, $[43] = handleDragEnd, $[44] = handleDragOver, $[45] = handleDragStart, $[46] = handleDrop, $[47] = isVoid, $[48] = t17, $[49] = t18, $[50] = t19) : t19 = $[50], t19;
|
|
1587
710
|
};
|
|
1588
711
|
DraggableBlock.displayName = "DraggableBlock";
|
|
712
|
+
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) => {
|
|
713
|
+
for (var prop in b || (b = {}))
|
|
714
|
+
__hasOwnProp$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
715
|
+
if (__getOwnPropSymbols$n)
|
|
716
|
+
for (var prop of __getOwnPropSymbols$n(b))
|
|
717
|
+
__propIsEnum$n.call(b, prop) && __defNormalProp$n(a, prop, b[prop]);
|
|
718
|
+
return a;
|
|
719
|
+
}, __spreadProps$h = (a, b) => __defProps$h(a, __getOwnPropDescs$h(b));
|
|
1589
720
|
debugWithName("components:Element");
|
|
1590
721
|
const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
1591
722
|
display: "inline-block"
|
|
@@ -1622,7 +753,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1622
753
|
}, "children", {
|
|
1623
754
|
_key: element._key
|
|
1624
755
|
}];
|
|
1625
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", {
|
|
756
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", __spreadProps$h(__spreadValues$n({}, attributes), { children: [
|
|
1626
757
|
children,
|
|
1627
758
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
|
|
1628
759
|
renderChild && renderChild({
|
|
@@ -1639,7 +770,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1639
770
|
}),
|
|
1640
771
|
!renderChild && /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value })
|
|
1641
772
|
] }, element._key)
|
|
1642
|
-
] });
|
|
773
|
+
] }));
|
|
1643
774
|
}
|
|
1644
775
|
throw new Error("Block not found!");
|
|
1645
776
|
}
|
|
@@ -1690,7 +821,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1690
821
|
return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
|
|
1691
822
|
}
|
|
1692
823
|
}), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
|
|
1693
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", {
|
|
824
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, spellCheck, children: /* @__PURE__ */ jsxRuntime.jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered }) }) }), element._key);
|
|
1694
825
|
}
|
|
1695
826
|
const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
|
|
1696
827
|
if (!schemaType_0)
|
|
@@ -1715,13 +846,13 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1715
846
|
});
|
|
1716
847
|
renderedBlockFromProps = renderBlock(_props);
|
|
1717
848
|
}
|
|
1718
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", {
|
|
849
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps$h(__spreadValues$n({}, attributes), { className, children: [
|
|
1719
850
|
children,
|
|
1720
851
|
/* @__PURE__ */ jsxRuntime.jsxs(DraggableBlock, { element, readOnly, blockRef, children: [
|
|
1721
852
|
renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
1722
853
|
!renderedBlockFromProps && /* @__PURE__ */ jsxRuntime.jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsxRuntime.jsx(DefaultObject, { value }) })
|
|
1723
854
|
] })
|
|
1724
|
-
] }, element._key);
|
|
855
|
+
] }), element._key);
|
|
1725
856
|
};
|
|
1726
857
|
Element.displayName = "Element";
|
|
1727
858
|
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
@@ -1749,6 +880,14 @@ function compileType(rawType) {
|
|
|
1749
880
|
types: [rawType]
|
|
1750
881
|
}).get(rawType.name);
|
|
1751
882
|
}
|
|
883
|
+
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) => {
|
|
884
|
+
for (var prop in b || (b = {}))
|
|
885
|
+
__hasOwnProp$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
886
|
+
if (__getOwnPropSymbols$m)
|
|
887
|
+
for (var prop of __getOwnPropSymbols$m(b))
|
|
888
|
+
__propIsEnum$m.call(b, prop) && __defNormalProp$m(a, prop, b[prop]);
|
|
889
|
+
return a;
|
|
890
|
+
}, __spreadProps$g = (a, b) => __defProps$g(a, __getOwnPropDescs$g(b));
|
|
1752
891
|
function validateValue(value, types$1, keyGenerator) {
|
|
1753
892
|
let resolution = null, valid = !0;
|
|
1754
893
|
const validChildTypes = [types$1.span.name, ...types$1.inlineObjects.map((t) => t.name)], validBlockTypes = [types$1.block.name, ...types$1.blockObjects.map((t) => t.name)];
|
|
@@ -1786,10 +925,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1786
925
|
}, !0;
|
|
1787
926
|
if (!blk._key || typeof blk._key != "string")
|
|
1788
927
|
return resolution = {
|
|
1789
|
-
patches: [patches.set({
|
|
1790
|
-
...blk,
|
|
928
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1791
929
|
_key: keyGenerator()
|
|
1792
|
-
}, [index])],
|
|
930
|
+
}), [index])],
|
|
1793
931
|
description: `Block at index ${index} is missing required _key.`,
|
|
1794
932
|
action: "Set the block with a random _key value",
|
|
1795
933
|
item: blk,
|
|
@@ -1805,10 +943,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1805
943
|
if (blk._type === "block") {
|
|
1806
944
|
const currentBlockTypeName = types$1.block.name;
|
|
1807
945
|
return resolution = {
|
|
1808
|
-
patches: [patches.set({
|
|
1809
|
-
...blk,
|
|
946
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1810
947
|
_type: currentBlockTypeName
|
|
1811
|
-
}, [{
|
|
948
|
+
}), [{
|
|
1812
949
|
_key: blk._key
|
|
1813
950
|
}])],
|
|
1814
951
|
description: `Block with _key '${blk._key}' has invalid type name '${blk._type}'. According to the schema, the block type name is '${currentBlockTypeName}'`,
|
|
@@ -1824,14 +961,12 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1824
961
|
}
|
|
1825
962
|
}, !0;
|
|
1826
963
|
}
|
|
1827
|
-
return !blk._type && types.isPortableTextTextBlock({
|
|
1828
|
-
...blk,
|
|
964
|
+
return !blk._type && types.isPortableTextTextBlock(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1829
965
|
_type: types$1.block.name
|
|
1830
|
-
}) ? (resolution = {
|
|
1831
|
-
patches: [patches.set({
|
|
1832
|
-
...blk,
|
|
966
|
+
})) ? (resolution = {
|
|
967
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$m({}, blk), {
|
|
1833
968
|
_type: types$1.block.name
|
|
1834
|
-
}, [{
|
|
969
|
+
}), [{
|
|
1835
970
|
_key: blk._key
|
|
1836
971
|
}])],
|
|
1837
972
|
description: `Block with _key '${blk._key}' is missing a type name. According to the schema, the block type name is '${types$1.block.name}'`,
|
|
@@ -1991,10 +1126,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
1991
1126
|
}
|
|
1992
1127
|
}, !0;
|
|
1993
1128
|
if (!child._key || typeof child._key != "string") {
|
|
1994
|
-
const newChild = {
|
|
1995
|
-
...child,
|
|
1129
|
+
const newChild = __spreadProps$g(__spreadValues$m({}, child), {
|
|
1996
1130
|
_key: keyGenerator()
|
|
1997
|
-
};
|
|
1131
|
+
});
|
|
1998
1132
|
return resolution = {
|
|
1999
1133
|
autoResolve: !0,
|
|
2000
1134
|
patches: [patches.set(newChild, [{
|
|
@@ -2014,10 +1148,9 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
2014
1148
|
}, !0;
|
|
2015
1149
|
}
|
|
2016
1150
|
return child._type ? validChildTypes.includes(child._type) ? child._type === types$1.span.name && typeof child.text != "string" ? (resolution = {
|
|
2017
|
-
patches: [patches.set({
|
|
2018
|
-
...child,
|
|
1151
|
+
patches: [patches.set(__spreadProps$g(__spreadValues$m({}, child), {
|
|
2019
1152
|
text: ""
|
|
2020
|
-
}, [{
|
|
1153
|
+
}), [{
|
|
2021
1154
|
_key: blk._key
|
|
2022
1155
|
}, "children", {
|
|
2023
1156
|
_key: child._key
|
|
@@ -2428,11 +1561,10 @@ function createDeadLine(timeout) {
|
|
|
2428
1561
|
return typeof timeout < "u" && (t = timeout <= 0 ? Number.MAX_VALUE : timeout), Date.now() + t * 1e3;
|
|
2429
1562
|
}
|
|
2430
1563
|
function createInternalOpts(opts) {
|
|
2431
|
-
return {
|
|
1564
|
+
return __spreadValues({
|
|
2432
1565
|
checkLines: !0,
|
|
2433
|
-
deadline: createDeadLine(opts.timeout || 1)
|
|
2434
|
-
|
|
2435
|
-
};
|
|
1566
|
+
deadline: createDeadLine(opts.timeout || 1)
|
|
1567
|
+
}, opts);
|
|
2436
1568
|
}
|
|
2437
1569
|
function combineChar(data, char, dir) {
|
|
2438
1570
|
return dir === 1 ? data + char : char + data;
|
|
@@ -2496,10 +1628,7 @@ const DEFAULT_OPTIONS = {
|
|
|
2496
1628
|
distance: 1e3
|
|
2497
1629
|
};
|
|
2498
1630
|
function applyDefaults(options) {
|
|
2499
|
-
return {
|
|
2500
|
-
...DEFAULT_OPTIONS,
|
|
2501
|
-
...options
|
|
2502
|
-
};
|
|
1631
|
+
return __spreadValues(__spreadValues({}, DEFAULT_OPTIONS), options);
|
|
2503
1632
|
}
|
|
2504
1633
|
const MAX_BITS$1 = 32;
|
|
2505
1634
|
function bitap(text, pattern, loc) {
|
|
@@ -2771,7 +1900,7 @@ function parse(textline) {
|
|
|
2771
1900
|
let line;
|
|
2772
1901
|
try {
|
|
2773
1902
|
line = decodeURI(currentLine.slice(1));
|
|
2774
|
-
} catch {
|
|
1903
|
+
} catch (ex) {
|
|
2775
1904
|
throw new Error("Illegal escape in parse: ".concat(currentLine));
|
|
2776
1905
|
}
|
|
2777
1906
|
const utf8Diff = countUtf8Bytes(line) - line.length;
|
|
@@ -2797,7 +1926,8 @@ function withUndoing(editor, fn) {
|
|
|
2797
1926
|
IS_UDOING.set(editor, !0), fn(), IS_UDOING.set(editor, prev);
|
|
2798
1927
|
}
|
|
2799
1928
|
function isUndoing(editor) {
|
|
2800
|
-
|
|
1929
|
+
var _a;
|
|
1930
|
+
return (_a = IS_UDOING.get(editor)) != null ? _a : !1;
|
|
2801
1931
|
}
|
|
2802
1932
|
function setIsUndoing(editor, isUndoing2) {
|
|
2803
1933
|
IS_UDOING.set(editor, isUndoing2);
|
|
@@ -2807,11 +1937,20 @@ function withRedoing(editor, fn) {
|
|
|
2807
1937
|
IS_REDOING.set(editor, !0), fn(), IS_REDOING.set(editor, prev);
|
|
2808
1938
|
}
|
|
2809
1939
|
function isRedoing(editor) {
|
|
2810
|
-
|
|
1940
|
+
var _a;
|
|
1941
|
+
return (_a = IS_REDOING.get(editor)) != null ? _a : !1;
|
|
2811
1942
|
}
|
|
2812
1943
|
function setIsRedoing(editor, isRedoing2) {
|
|
2813
1944
|
IS_REDOING.set(editor, isRedoing2);
|
|
2814
1945
|
}
|
|
1946
|
+
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) => {
|
|
1947
|
+
for (var prop in b || (b = {}))
|
|
1948
|
+
__hasOwnProp$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
1949
|
+
if (__getOwnPropSymbols$l)
|
|
1950
|
+
for (var prop of __getOwnPropSymbols$l(b))
|
|
1951
|
+
__propIsEnum$l.call(b, prop) && __defNormalProp$l(a, prop, b[prop]);
|
|
1952
|
+
return a;
|
|
1953
|
+
};
|
|
2815
1954
|
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) => {
|
|
2816
1955
|
const state = SAVING.get(editor);
|
|
2817
1956
|
return state === void 0 ? !0 : state;
|
|
@@ -2968,9 +2107,7 @@ function createWithUndoRedo(options) {
|
|
|
2968
2107
|
}
|
|
2969
2108
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2970
2109
|
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)}`));
|
|
2971
|
-
const transformedOperation = {
|
|
2972
|
-
...operation
|
|
2973
|
-
};
|
|
2110
|
+
const transformedOperation = __spreadValues$l({}, operation);
|
|
2974
2111
|
if (patch.type === "insert" && patch.path.length === 1) {
|
|
2975
2112
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual__default.default({
|
|
2976
2113
|
_key: blk._key
|
|
@@ -2990,6 +2127,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2990
2127
|
return !operationTargetBlock || !isEqual__default.default({
|
|
2991
2128
|
_key: operationTargetBlock._key
|
|
2992
2129
|
}, patch.path[0]) ? [transformedOperation] : (parse(patch.value).forEach((diffPatch) => {
|
|
2130
|
+
var _a, _b, _c, _d;
|
|
2993
2131
|
let adjustOffsetBy = 0, changedOffset = diffPatch.utf8Start1;
|
|
2994
2132
|
const {
|
|
2995
2133
|
diffs
|
|
@@ -2998,15 +2136,7 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2998
2136
|
const [diffType, text] = diff2;
|
|
2999
2137
|
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));
|
|
3000
2138
|
}), 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") {
|
|
3001
|
-
const currentFocus = transformedOperation.properties
|
|
3002
|
-
...transformedOperation.properties.focus
|
|
3003
|
-
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
3004
|
-
...transformedOperation.properties.anchor
|
|
3005
|
-
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
3006
|
-
...transformedOperation.newProperties.focus
|
|
3007
|
-
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
3008
|
-
...transformedOperation.newProperties.anchor
|
|
3009
|
-
} : void 0;
|
|
2139
|
+
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;
|
|
3010
2140
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
3011
2141
|
point && changedOffset < point.offset && (point.offset += adjustOffsetBy);
|
|
3012
2142
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -3022,23 +2152,14 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
3022
2152
|
return [transformedOperation];
|
|
3023
2153
|
}
|
|
3024
2154
|
function adjustBlockPath(operation, level, blockIndex) {
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
};
|
|
2155
|
+
var _a, _b, _c, _d;
|
|
2156
|
+
const transformedOperation = __spreadValues$l({}, operation);
|
|
3028
2157
|
if (blockIndex >= 0 && transformedOperation.type !== "set_selection" && Array.isArray(transformedOperation.path) && transformedOperation.path[0] >= blockIndex + level && transformedOperation.path[0] + level > -1) {
|
|
3029
2158
|
const newPath = [transformedOperation.path[0] + level, ...transformedOperation.path.slice(1)];
|
|
3030
2159
|
transformedOperation.path = newPath;
|
|
3031
2160
|
}
|
|
3032
2161
|
if (transformedOperation.type === "set_selection") {
|
|
3033
|
-
const currentFocus = transformedOperation.properties
|
|
3034
|
-
...transformedOperation.properties.focus
|
|
3035
|
-
} : void 0, currentAnchor = transformedOperation?.properties?.anchor ? {
|
|
3036
|
-
...transformedOperation.properties.anchor
|
|
3037
|
-
} : void 0, newFocus = transformedOperation?.newProperties?.focus ? {
|
|
3038
|
-
...transformedOperation.newProperties.focus
|
|
3039
|
-
} : void 0, newAnchor = transformedOperation?.newProperties?.anchor ? {
|
|
3040
|
-
...transformedOperation.newProperties.anchor
|
|
3041
|
-
} : void 0;
|
|
2162
|
+
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;
|
|
3042
2163
|
(currentFocus && currentAnchor || newFocus && newAnchor) && ([currentFocus, currentAnchor, newFocus, newAnchor].forEach((point) => {
|
|
3043
2164
|
point && point.path[0] >= blockIndex + level && point.path[0] + level > -1 && (point.path = [point.path[0] + level, ...point.path.slice(1)]);
|
|
3044
2165
|
}), currentFocus && currentAnchor && (transformedOperation.properties = {
|
|
@@ -3059,12 +2180,8 @@ function withoutSaving(editor, fn) {
|
|
|
3059
2180
|
function createSelectOperation(editor) {
|
|
3060
2181
|
return {
|
|
3061
2182
|
type: "set_selection",
|
|
3062
|
-
properties: {
|
|
3063
|
-
|
|
3064
|
-
},
|
|
3065
|
-
newProperties: {
|
|
3066
|
-
...editor.selection
|
|
3067
|
-
}
|
|
2183
|
+
properties: __spreadValues$l({}, editor.selection),
|
|
2184
|
+
newProperties: __spreadValues$l({}, editor.selection)
|
|
3068
2185
|
};
|
|
3069
2186
|
}
|
|
3070
2187
|
function findOperationTargetBlock(editor, operation) {
|
|
@@ -3138,15 +2255,16 @@ function useSyncValue(props) {
|
|
|
3138
2255
|
isChanged = !0;
|
|
3139
2256
|
}
|
|
3140
2257
|
slateValueFromProps.forEach((currentBlock, currentBlockIndex) => {
|
|
2258
|
+
var _a, _b, _c, _d, _e;
|
|
3141
2259
|
const oldBlock = slateEditor.children[currentBlockIndex];
|
|
3142
2260
|
if (oldBlock && !isEqual__default.default(currentBlock, oldBlock) && isValid) {
|
|
3143
2261
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
3144
|
-
!validation.valid && validation.resolution
|
|
2262
|
+
!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) => {
|
|
3145
2263
|
editorActor.send({
|
|
3146
2264
|
type: "patch",
|
|
3147
2265
|
patch
|
|
3148
2266
|
});
|
|
3149
|
-
})), validation.valid || validation.resolution
|
|
2267
|
+
})), 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({
|
|
3150
2268
|
type: "invalid value",
|
|
3151
2269
|
resolution: validation.resolution,
|
|
3152
2270
|
value
|
|
@@ -3154,7 +2272,7 @@ function useSyncValue(props) {
|
|
|
3154
2272
|
}
|
|
3155
2273
|
if (!oldBlock && isValid) {
|
|
3156
2274
|
const validationValue_0 = [value[currentBlockIndex]], validation_0 = validateValue(validationValue_0, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
3157
|
-
debug$i.enabled && debug$i("Validating and inserting new block in the end of the value", currentBlock), validation_0.valid || validation_0.resolution
|
|
2275
|
+
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 ? slate.Transforms.insertNodes(slateEditor, currentBlock, {
|
|
3158
2276
|
at: [currentBlockIndex]
|
|
3159
2277
|
}) : (debug$i("Invalid", validation_0), editorActor.send({
|
|
3160
2278
|
type: "invalid value",
|
|
@@ -3223,9 +2341,9 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
3223
2341
|
at: [currentBlockIndex, childIndex]
|
|
3224
2342
|
}));
|
|
3225
2343
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
3226
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild
|
|
2344
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild == null ? void 0 : oldBlockChild.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
3227
2345
|
if (isChildChanged)
|
|
3228
|
-
if (currentBlockChild._key === oldBlockChild
|
|
2346
|
+
if (currentBlockChild._key === (oldBlockChild == null ? void 0 : oldBlockChild._key)) {
|
|
3229
2347
|
debug$i("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
3230
2348
|
at: path
|
|
3231
2349
|
});
|
|
@@ -3336,6 +2454,14 @@ function _temp(s) {
|
|
|
3336
2454
|
return s.context.readOnly;
|
|
3337
2455
|
}
|
|
3338
2456
|
Synchronizer.displayName = "Synchronizer";
|
|
2457
|
+
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) => {
|
|
2458
|
+
for (var prop in b || (b = {}))
|
|
2459
|
+
__hasOwnProp$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2460
|
+
if (__getOwnPropSymbols$k)
|
|
2461
|
+
for (var prop of __getOwnPropSymbols$k(b))
|
|
2462
|
+
__propIsEnum$k.call(b, prop) && __defNormalProp$k(a, prop, b[prop]);
|
|
2463
|
+
return a;
|
|
2464
|
+
}, __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
|
|
3339
2465
|
const debug$g = debugWithName("operationToPatches");
|
|
3340
2466
|
function createOperationToPatches(types2) {
|
|
3341
2467
|
const textBlockName = types2.block.name;
|
|
@@ -3375,10 +2501,7 @@ function createOperationToPatches(types2) {
|
|
|
3375
2501
|
const block = editor.children[operation.path[0]];
|
|
3376
2502
|
if (typeof block._key != "string")
|
|
3377
2503
|
throw new Error("Expected block to have a _key");
|
|
3378
|
-
const setNode = omitBy__default.default({
|
|
3379
|
-
...editor.children[operation.path[0]],
|
|
3380
|
-
...operation.newProperties
|
|
3381
|
-
}, isUndefined__default.default);
|
|
2504
|
+
const setNode = omitBy__default.default(__spreadValues$k(__spreadValues$k({}, editor.children[operation.path[0]]), operation.newProperties), isUndefined__default.default);
|
|
3382
2505
|
return [patches.set(fromSlateValue([setNode], textBlockName)[0], [{
|
|
3383
2506
|
_key: block._key
|
|
3384
2507
|
}])];
|
|
@@ -3413,14 +2536,12 @@ function createOperationToPatches(types2) {
|
|
|
3413
2536
|
function insertNodePatch(editor, operation, beforeValue) {
|
|
3414
2537
|
const block = beforeValue[operation.path[0]], isTextBlock = editor.isTextBlock(block);
|
|
3415
2538
|
if (operation.path.length === 1) {
|
|
3416
|
-
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block
|
|
2539
|
+
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;
|
|
3417
2540
|
return targetKey ? [patches.insert([fromSlateValue([operation.node], textBlockName)[0]], position, [{
|
|
3418
2541
|
_key: targetKey
|
|
3419
2542
|
}])] : [patches.setIfMissing(beforeValue, []), patches.insert([fromSlateValue([operation.node], textBlockName)[0]], "before", [operation.path[0]])];
|
|
3420
2543
|
} else if (isTextBlock && operation.path.length === 2 && editor.children[operation.path[0]]) {
|
|
3421
|
-
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = {
|
|
3422
|
-
...operation.node
|
|
3423
|
-
};
|
|
2544
|
+
const position = block.children.length === 0 || !block.children[operation.path[1] - 1] ? "before" : "after", node = __spreadValues$k({}, operation.node);
|
|
3424
2545
|
!node._type && slate.Text.isText(node) && (node._type = "span", node.marks = []);
|
|
3425
2546
|
const child = fromSlateValue([{
|
|
3426
2547
|
_key: "bogus",
|
|
@@ -3459,10 +2580,9 @@ function createOperationToPatches(types2) {
|
|
|
3459
2580
|
if (operation.path.length === 2) {
|
|
3460
2581
|
const splitSpan = splitBlock.children[operation.path[1]];
|
|
3461
2582
|
if (editor.isTextSpan(splitSpan)) {
|
|
3462
|
-
const targetSpans = fromSlateValue([{
|
|
3463
|
-
...splitBlock,
|
|
2583
|
+
const targetSpans = fromSlateValue([__spreadProps$f(__spreadValues$k({}, splitBlock), {
|
|
3464
2584
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
3465
|
-
}], textBlockName)[0].children;
|
|
2585
|
+
})], textBlockName)[0].children;
|
|
3466
2586
|
patches$1.push(patches.insert(targetSpans, "after", [{
|
|
3467
2587
|
_key: splitBlock._key
|
|
3468
2588
|
}, "children", {
|
|
@@ -3498,7 +2618,7 @@ function createOperationToPatches(types2) {
|
|
|
3498
2618
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3499
2619
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
3500
2620
|
if (operation.path.length === 1)
|
|
3501
|
-
if (block
|
|
2621
|
+
if (block != null && block._key) {
|
|
3502
2622
|
const newBlock = fromSlateValue([editor.children[operation.path[0] - 1]], textBlockName)[0];
|
|
3503
2623
|
patches$1.push(patches.set(newBlock, [{
|
|
3504
2624
|
_key: newBlock._key
|
|
@@ -3770,6 +2890,7 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3770
2890
|
apply: apply2
|
|
3771
2891
|
} = editor;
|
|
3772
2892
|
return editor.apply = (operation) => {
|
|
2893
|
+
var _a;
|
|
3773
2894
|
if (editorActor.getSnapshot().context.readOnly) {
|
|
3774
2895
|
apply2(operation);
|
|
3775
2896
|
return;
|
|
@@ -3782,11 +2903,19 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3782
2903
|
apply2(operation);
|
|
3783
2904
|
return;
|
|
3784
2905
|
}
|
|
3785
|
-
const rows = editorActor.getSnapshot().context.maxBlocks
|
|
2906
|
+
const rows = (_a = editorActor.getSnapshot().context.maxBlocks) != null ? _a : -1;
|
|
3786
2907
|
rows > 0 && editor.children.length >= rows && (operation.type === "insert_node" || operation.type === "split_node") && operation.path.length === 1 || apply2(operation);
|
|
3787
2908
|
}, editor;
|
|
3788
2909
|
};
|
|
3789
2910
|
}
|
|
2911
|
+
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) => {
|
|
2912
|
+
for (var prop in b || (b = {}))
|
|
2913
|
+
__hasOwnProp$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2914
|
+
if (__getOwnPropSymbols$j)
|
|
2915
|
+
for (var prop of __getOwnPropSymbols$j(b))
|
|
2916
|
+
__propIsEnum$j.call(b, prop) && __defNormalProp$j(a, prop, b[prop]);
|
|
2917
|
+
return a;
|
|
2918
|
+
}, __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
|
|
3790
2919
|
function createWithObjectKeys(editorActor, schemaTypes) {
|
|
3791
2920
|
return function(editor) {
|
|
3792
2921
|
const {
|
|
@@ -3803,23 +2932,19 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3803
2932
|
return;
|
|
3804
2933
|
}
|
|
3805
2934
|
if (operation.type === "split_node") {
|
|
3806
|
-
apply2({
|
|
3807
|
-
|
|
3808
|
-
properties: {
|
|
3809
|
-
...operation.properties,
|
|
2935
|
+
apply2(__spreadProps$e(__spreadValues$j({}, operation), {
|
|
2936
|
+
properties: __spreadProps$e(__spreadValues$j({}, operation.properties), {
|
|
3810
2937
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3811
|
-
}
|
|
3812
|
-
});
|
|
2938
|
+
})
|
|
2939
|
+
}));
|
|
3813
2940
|
return;
|
|
3814
2941
|
}
|
|
3815
2942
|
if (operation.type === "insert_node" && !slate.Editor.isEditor(operation.node)) {
|
|
3816
|
-
apply2({
|
|
3817
|
-
|
|
3818
|
-
node: {
|
|
3819
|
-
...operation.node,
|
|
2943
|
+
apply2(__spreadProps$e(__spreadValues$j({}, operation), {
|
|
2944
|
+
node: __spreadProps$e(__spreadValues$j({}, operation.node), {
|
|
3820
2945
|
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
3821
|
-
}
|
|
3822
|
-
});
|
|
2946
|
+
})
|
|
2947
|
+
}));
|
|
3823
2948
|
return;
|
|
3824
2949
|
}
|
|
3825
2950
|
apply2(operation);
|
|
@@ -3856,6 +2981,22 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3856
2981
|
}, editor;
|
|
3857
2982
|
};
|
|
3858
2983
|
}
|
|
2984
|
+
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) => {
|
|
2985
|
+
for (var prop in b || (b = {}))
|
|
2986
|
+
__hasOwnProp$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
2987
|
+
if (__getOwnPropSymbols$i)
|
|
2988
|
+
for (var prop of __getOwnPropSymbols$i(b))
|
|
2989
|
+
__propIsEnum$i.call(b, prop) && __defNormalProp$i(a, prop, b[prop]);
|
|
2990
|
+
return a;
|
|
2991
|
+
}, __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b)), __objRest$2 = (source, exclude) => {
|
|
2992
|
+
var target = {};
|
|
2993
|
+
for (var prop in source)
|
|
2994
|
+
__hasOwnProp$i.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
2995
|
+
if (source != null && __getOwnPropSymbols$i)
|
|
2996
|
+
for (var prop of __getOwnPropSymbols$i(source))
|
|
2997
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$i.call(source, prop) && (target[prop] = source[prop]);
|
|
2998
|
+
return target;
|
|
2999
|
+
};
|
|
3859
3000
|
const debug$f = debugWithName("applyPatches"), debugVerbose$2 = debug$f.enabled && !0;
|
|
3860
3001
|
function createApplyPatch(schemaTypes) {
|
|
3861
3002
|
return (editor, patch) => {
|
|
@@ -3945,10 +3086,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3945
3086
|
} = patch;
|
|
3946
3087
|
if (!targetChild || !targetChildPath)
|
|
3947
3088
|
return debug$f("Child not found"), !1;
|
|
3948
|
-
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3949
|
-
...targetBlock,
|
|
3089
|
+
const childrenToInsert = targetBlock && toSlateValue([__spreadProps$d(__spreadValues$i({}, targetBlock), {
|
|
3950
3090
|
children: items
|
|
3951
|
-
}], {
|
|
3091
|
+
})], {
|
|
3952
3092
|
schemaTypes
|
|
3953
3093
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3954
3094
|
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
@@ -3993,21 +3133,19 @@ function setPatch(editor, patch) {
|
|
|
3993
3133
|
return !0;
|
|
3994
3134
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3995
3135
|
debug$f("Setting block property");
|
|
3996
|
-
const {
|
|
3997
|
-
children
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
...prevRest
|
|
4002
|
-
} = block || {
|
|
3136
|
+
const _a = value, {
|
|
3137
|
+
children
|
|
3138
|
+
} = _a, nextRest = __objRest$2(_a, [
|
|
3139
|
+
"children"
|
|
3140
|
+
]), _b = block || {
|
|
4003
3141
|
children: void 0
|
|
4004
|
-
}
|
|
3142
|
+
}, prevRest = __objRest$2(_b, [
|
|
3143
|
+
"children"
|
|
3144
|
+
]);
|
|
4005
3145
|
editor.apply({
|
|
4006
3146
|
type: "set_node",
|
|
4007
3147
|
path: blockPath,
|
|
4008
|
-
properties: {
|
|
4009
|
-
...prevRest
|
|
4010
|
-
},
|
|
3148
|
+
properties: __spreadValues$i({}, prevRest),
|
|
4011
3149
|
newProperties: nextRest
|
|
4012
3150
|
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
4013
3151
|
editor.apply({
|
|
@@ -4024,10 +3162,9 @@ function setPatch(editor, patch) {
|
|
|
4024
3162
|
});
|
|
4025
3163
|
} else if (block && "value" in block) {
|
|
4026
3164
|
const newVal = patches.applyAll([block.value], [patch])[0];
|
|
4027
|
-
return slate.Transforms.setNodes(editor, {
|
|
4028
|
-
...block,
|
|
3165
|
+
return slate.Transforms.setNodes(editor, __spreadProps$d(__spreadValues$i({}, block), {
|
|
4029
3166
|
value: newVal
|
|
4030
|
-
}, {
|
|
3167
|
+
}), {
|
|
4031
3168
|
at: blockPath
|
|
4032
3169
|
}), !0;
|
|
4033
3170
|
}
|
|
@@ -4110,7 +3247,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
4110
3247
|
block,
|
|
4111
3248
|
child,
|
|
4112
3249
|
blockPath,
|
|
4113
|
-
childPath: blockPath
|
|
3250
|
+
childPath: blockPath == null ? void 0 : blockPath.concat(childIndex)
|
|
4114
3251
|
} : {
|
|
4115
3252
|
block,
|
|
4116
3253
|
blockPath,
|
|
@@ -4118,6 +3255,14 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
4118
3255
|
childPath: void 0
|
|
4119
3256
|
};
|
|
4120
3257
|
}
|
|
3258
|
+
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) => {
|
|
3259
|
+
for (var prop in b || (b = {}))
|
|
3260
|
+
__hasOwnProp$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3261
|
+
if (__getOwnPropSymbols$h)
|
|
3262
|
+
for (var prop of __getOwnPropSymbols$h(b))
|
|
3263
|
+
__propIsEnum$h.call(b, prop) && __defNormalProp$h(a, prop, b[prop]);
|
|
3264
|
+
return a;
|
|
3265
|
+
}, __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
|
|
4121
3266
|
const debug$e = debugWithName("plugin:withPatches");
|
|
4122
3267
|
function createWithPatches({
|
|
4123
3268
|
editorActor,
|
|
@@ -4204,10 +3349,9 @@ function createWithPatches({
|
|
|
4204
3349
|
})), editorWasEmpty && patches$1.length > 0 && (patches$1 = [patches.setIfMissing([], []), ...patches$1]), patches$1.length > 0 && patches$1.forEach((patch) => {
|
|
4205
3350
|
editorActor.send({
|
|
4206
3351
|
type: "patch",
|
|
4207
|
-
patch: {
|
|
4208
|
-
...patch,
|
|
3352
|
+
patch: __spreadProps$c(__spreadValues$h({}, patch), {
|
|
4209
3353
|
origin: "local"
|
|
4210
|
-
}
|
|
3354
|
+
})
|
|
4211
3355
|
});
|
|
4212
3356
|
}), editor;
|
|
4213
3357
|
}, editor;
|
|
@@ -4318,6 +3462,14 @@ function getNextSpan({
|
|
|
4318
3462
|
}
|
|
4319
3463
|
return nextSpan;
|
|
4320
3464
|
}
|
|
3465
|
+
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) => {
|
|
3466
|
+
for (var prop in b || (b = {}))
|
|
3467
|
+
__hasOwnProp$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
3468
|
+
if (__getOwnPropSymbols$g)
|
|
3469
|
+
for (var prop of __getOwnPropSymbols$g(b))
|
|
3470
|
+
__propIsEnum$g.call(b, prop) && __defNormalProp$g(a, prop, b[prop]);
|
|
3471
|
+
return a;
|
|
3472
|
+
}, __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
|
|
4321
3473
|
const debug$b = debugWithName("plugin:withPortableTextMarkModel");
|
|
4322
3474
|
function createWithPortableTextMarkModel(editorActor, types2) {
|
|
4323
3475
|
return function(editor) {
|
|
@@ -4326,12 +3478,19 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4326
3478
|
normalizeNode
|
|
4327
3479
|
} = editor, decorators = types2.decorators.map((t) => t.value);
|
|
4328
3480
|
return editor.normalizeNode = (nodeEntry) => {
|
|
3481
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
4329
3482
|
const [node, path] = nodeEntry;
|
|
4330
3483
|
if (editor.isTextBlock(node)) {
|
|
4331
3484
|
const children = slate.Node.children(editor, path);
|
|
4332
3485
|
for (const [child, childPath] of children) {
|
|
4333
3486
|
const nextNode = node.children[childPath[1] + 1];
|
|
4334
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) &&
|
|
3487
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && (_a = child.marks) != null && _a.every((mark) => {
|
|
3488
|
+
var _a2;
|
|
3489
|
+
return (_a2 = nextNode.marks) == null ? void 0 : _a2.includes(mark);
|
|
3490
|
+
}) && (_b = nextNode.marks) != null && _b.every((mark) => {
|
|
3491
|
+
var _a2;
|
|
3492
|
+
return (_a2 = child.marks) == null ? void 0 : _a2.includes(mark);
|
|
3493
|
+
})) {
|
|
4335
3494
|
debug$b("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
4336
3495
|
type: "normalizing"
|
|
4337
3496
|
}), slate.Transforms.mergeNodes(editor, {
|
|
@@ -4369,12 +3528,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4369
3528
|
return;
|
|
4370
3529
|
}
|
|
4371
3530
|
if (editor.isTextSpan(node)) {
|
|
4372
|
-
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks
|
|
3531
|
+
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = (_c = node.marks) == null ? void 0 : _c.filter((mark) => !decorators2.includes(mark));
|
|
4373
3532
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
4374
3533
|
debug$b("Removing annotations from empty span node"), editorActor.send({
|
|
4375
3534
|
type: "normalizing"
|
|
4376
3535
|
}), slate.Transforms.setNodes(editor, {
|
|
4377
|
-
marks: node.marks
|
|
3536
|
+
marks: (_d = node.marks) == null ? void 0 : _d.filter((mark) => decorators2.includes(mark))
|
|
4378
3537
|
}, {
|
|
4379
3538
|
at: path
|
|
4380
3539
|
}), editorActor.send({
|
|
@@ -4387,7 +3546,10 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4387
3546
|
const decorators2 = types2.decorators.map((decorator) => decorator.value);
|
|
4388
3547
|
for (const [child, childPath] of slate.Node.children(editor, path))
|
|
4389
3548
|
if (editor.isTextSpan(child)) {
|
|
4390
|
-
const marks = child.marks
|
|
3549
|
+
const marks = (_e = child.marks) != null ? _e : [], orphanedAnnotations = marks.filter((mark) => {
|
|
3550
|
+
var _a2;
|
|
3551
|
+
return !decorators2.includes(mark) && !((_a2 = node.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3552
|
+
});
|
|
4391
3553
|
if (orphanedAnnotations.length > 0) {
|
|
4392
3554
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
4393
3555
|
type: "normalizing"
|
|
@@ -4405,7 +3567,10 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4405
3567
|
if (editor.isTextSpan(node)) {
|
|
4406
3568
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath);
|
|
4407
3569
|
if (editor.isTextBlock(block)) {
|
|
4408
|
-
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks
|
|
3570
|
+
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = (_f = node.marks) != null ? _f : [], orphanedAnnotations = marks.filter((mark) => {
|
|
3571
|
+
var _a2;
|
|
3572
|
+
return !decorators2.includes(mark) && !((_a2 = block.markDefs) != null && _a2.find((def) => def._key === mark));
|
|
3573
|
+
});
|
|
4409
3574
|
if (orphanedAnnotations.length > 0) {
|
|
4410
3575
|
debug$b("Removing orphaned annotations from span node"), editorActor.send({
|
|
4411
3576
|
type: "normalizing"
|
|
@@ -4421,7 +3586,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4421
3586
|
}
|
|
4422
3587
|
}
|
|
4423
3588
|
if (editor.isTextBlock(node)) {
|
|
4424
|
-
const markDefs = node.markDefs
|
|
3589
|
+
const markDefs = (_g = node.markDefs) != null ? _g : [], markDefKeys = /* @__PURE__ */ new Set(), newMarkDefs = [];
|
|
4425
3590
|
for (const markDef of markDefs)
|
|
4426
3591
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
4427
3592
|
if (markDefs.length !== newMarkDefs.length) {
|
|
@@ -4454,6 +3619,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4454
3619
|
}
|
|
4455
3620
|
normalizeNode(nodeEntry);
|
|
4456
3621
|
}, editor.apply = (op) => {
|
|
3622
|
+
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;
|
|
4457
3623
|
if (isChangingRemotely(editor)) {
|
|
4458
3624
|
apply2(op);
|
|
4459
3625
|
return;
|
|
@@ -4471,17 +3637,17 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4471
3637
|
focus: op.newProperties.focus
|
|
4472
3638
|
});
|
|
4473
3639
|
if (previousSelectionIsCollapsed && newSelectionIsCollapsed) {
|
|
4474
|
-
const focusSpan = Array.from(slate.Editor.nodes(editor, {
|
|
3640
|
+
const focusSpan = (_a = Array.from(slate.Editor.nodes(editor, {
|
|
4475
3641
|
mode: "lowest",
|
|
4476
3642
|
at: op.properties.focus,
|
|
4477
3643
|
match: (n) => editor.isTextSpan(n),
|
|
4478
3644
|
voids: !1
|
|
4479
|
-
}))[0]
|
|
3645
|
+
}))[0]) == null ? void 0 : _a[0], newFocusSpan = (_b = Array.from(slate.Editor.nodes(editor, {
|
|
4480
3646
|
mode: "lowest",
|
|
4481
3647
|
at: op.newProperties.focus,
|
|
4482
3648
|
match: (n) => editor.isTextSpan(n),
|
|
4483
3649
|
voids: !1
|
|
4484
|
-
}))[0]
|
|
3650
|
+
}))[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;
|
|
4485
3651
|
if (movedToNextSpan || movedToPreviousSpan)
|
|
4486
3652
|
return;
|
|
4487
3653
|
}
|
|
@@ -4497,32 +3663,29 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4497
3663
|
editor,
|
|
4498
3664
|
blockPath,
|
|
4499
3665
|
spanPath: op.path
|
|
4500
|
-
}), previousSpanAnnotations = previousSpan ? previousSpan.marks
|
|
3666
|
+
}), previousSpanAnnotations = previousSpan ? (_c = previousSpan.marks) == null ? void 0 : _c.filter((mark) => !decorators.includes(mark)) : [], nextSpan = getNextSpan({
|
|
4501
3667
|
editor,
|
|
4502
3668
|
blockPath,
|
|
4503
3669
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
4504
|
-
}), nextSpanAnnotations = nextSpan ? nextSpan.marks
|
|
4505
|
-
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4506
|
-
slate.Transforms.insertNodes(editor, {
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
});
|
|
3670
|
+
}), 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;
|
|
3671
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && (_f = op.node.marks) != null && _f.some((mark) => annotationsEnding.includes(mark))) {
|
|
3672
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
3673
|
+
marks: (_h = (_g = op.node.marks) == null ? void 0 : _g.filter((mark) => !annotationsEnding.includes(mark))) != null ? _h : []
|
|
3674
|
+
}));
|
|
4510
3675
|
return;
|
|
4511
3676
|
}
|
|
4512
|
-
const annotationsStarting = nextSpanAnnotations
|
|
4513
|
-
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4514
|
-
slate.Transforms.insertNodes(editor, {
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
});
|
|
3677
|
+
const annotationsStarting = (_i = nextSpanAnnotations == null ? void 0 : nextSpanAnnotations.filter((annotation) => !(previousSpanAnnotations != null && previousSpanAnnotations.includes(annotation)))) != null ? _i : [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3678
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && (_j = op.node.marks) != null && _j.some((mark) => annotationsStarting.includes(mark))) {
|
|
3679
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
3680
|
+
marks: (_l = (_k = op.node.marks) == null ? void 0 : _k.filter((mark) => !annotationsStarting.includes(mark))) != null ? _l : []
|
|
3681
|
+
}));
|
|
4518
3682
|
return;
|
|
4519
3683
|
}
|
|
4520
|
-
const nextSpanDecorators = nextSpan
|
|
4521
|
-
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks
|
|
4522
|
-
slate.Transforms.insertNodes(editor, {
|
|
4523
|
-
...op.node,
|
|
3684
|
+
const nextSpanDecorators = (_n = (_m = nextSpan == null ? void 0 : nextSpan.marks) == null ? void 0 : _m.filter((mark) => decorators.includes(mark))) != null ? _n : [];
|
|
3685
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && ((_o = op.node.marks) == null ? void 0 : _o.length) === 0) {
|
|
3686
|
+
slate.Transforms.insertNodes(editor, __spreadProps$b(__spreadValues$g({}, op.node), {
|
|
4524
3687
|
marks: nextSpanDecorators
|
|
4525
|
-
});
|
|
3688
|
+
}));
|
|
4526
3689
|
return;
|
|
4527
3690
|
}
|
|
4528
3691
|
}
|
|
@@ -4534,12 +3697,12 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4534
3697
|
if (selection && collapsedSelection) {
|
|
4535
3698
|
const [_block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4536
3699
|
depth: 1
|
|
4537
|
-
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
3700
|
+
}), [span, spanPath] = (_p = Array.from(slate.Editor.nodes(editor, {
|
|
4538
3701
|
mode: "lowest",
|
|
4539
3702
|
at: selection.focus,
|
|
4540
3703
|
match: (n) => editor.isTextSpan(n),
|
|
4541
3704
|
voids: !1
|
|
4542
|
-
}))[0]
|
|
3705
|
+
}))[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({
|
|
4543
3706
|
editor,
|
|
4544
3707
|
blockPath,
|
|
4545
3708
|
spanPath
|
|
@@ -4547,7 +3710,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4547
3710
|
editor,
|
|
4548
3711
|
blockPath,
|
|
4549
3712
|
spanPath
|
|
4550
|
-
}), nextSpanAnnotations = nextSpan
|
|
3713
|
+
}), 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));
|
|
4551
3714
|
if (spanHasAnnotations && !spanIsEmpty) {
|
|
4552
3715
|
if (atTheBeginningOfSpan) {
|
|
4553
3716
|
if (previousSpanHasSameMarks) {
|
|
@@ -4555,7 +3718,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4555
3718
|
_type: "span",
|
|
4556
3719
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4557
3720
|
text: op.text,
|
|
4558
|
-
marks: previousSpan
|
|
3721
|
+
marks: (_x = previousSpan == null ? void 0 : previousSpan.marks) != null ? _x : []
|
|
4559
3722
|
});
|
|
4560
3723
|
return;
|
|
4561
3724
|
} else if (previousSpanHasSameAnnotations) {
|
|
@@ -4563,7 +3726,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4563
3726
|
_type: "span",
|
|
4564
3727
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4565
3728
|
text: op.text,
|
|
4566
|
-
marks: previousSpan
|
|
3729
|
+
marks: (_y = previousSpan == null ? void 0 : previousSpan.marks) != null ? _y : []
|
|
4567
3730
|
});
|
|
4568
3731
|
return;
|
|
4569
3732
|
} else if (previousSpanHasSameAnnotation) {
|
|
@@ -4585,7 +3748,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4585
3748
|
_type: "span",
|
|
4586
3749
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4587
3750
|
text: op.text,
|
|
4588
|
-
marks: nextSpan
|
|
3751
|
+
marks: (_z = nextSpan == null ? void 0 : nextSpan.marks) != null ? _z : []
|
|
4589
3752
|
});
|
|
4590
3753
|
return;
|
|
4591
3754
|
}
|
|
@@ -4605,7 +3768,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4605
3768
|
_type: "span",
|
|
4606
3769
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4607
3770
|
text: op.text,
|
|
4608
|
-
marks: previousSpanHasAnnotations ? [] : (previousSpan.marks
|
|
3771
|
+
marks: previousSpanHasAnnotations ? [] : ((_A = previousSpan.marks) != null ? _A : []).filter((mark) => decorators.includes(mark))
|
|
4609
3772
|
});
|
|
4610
3773
|
return;
|
|
4611
3774
|
}
|
|
@@ -4618,7 +3781,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4618
3781
|
if (selection && slate.Range.isExpanded(selection)) {
|
|
4619
3782
|
const [block, blockPath] = slate.Editor.node(editor, selection, {
|
|
4620
3783
|
depth: 1
|
|
4621
|
-
}), [span, spanPath] = Array.from(slate.Editor.nodes(editor, {
|
|
3784
|
+
}), [span, spanPath] = (_B = Array.from(slate.Editor.nodes(editor, {
|
|
4622
3785
|
mode: "lowest",
|
|
4623
3786
|
at: {
|
|
4624
3787
|
path: op.path,
|
|
@@ -4626,9 +3789,9 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4626
3789
|
},
|
|
4627
3790
|
match: (n) => editor.isTextSpan(n),
|
|
4628
3791
|
voids: !1
|
|
4629
|
-
}))[0]
|
|
3792
|
+
}))[0]) != null ? _B : [void 0, void 0];
|
|
4630
3793
|
if (span && block && isPortableTextBlock(block)) {
|
|
4631
|
-
const markDefs = block.markDefs
|
|
3794
|
+
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({
|
|
4632
3795
|
editor,
|
|
4633
3796
|
blockPath,
|
|
4634
3797
|
spanPath
|
|
@@ -4636,11 +3799,9 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4636
3799
|
editor,
|
|
4637
3800
|
blockPath,
|
|
4638
3801
|
spanPath
|
|
4639
|
-
}), previousSpanHasSameAnnotation = previousSpan ? previousSpan.marks
|
|
3802
|
+
}), 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;
|
|
4640
3803
|
if (spanHasAnnotations && deletingAllText && !previousSpanHasSameAnnotation && !nextSpanHasSameAnnotation) {
|
|
4641
|
-
const marksWithoutAnnotationMarks = ({
|
|
4642
|
-
...slate.Editor.marks(editor) || {}
|
|
4643
|
-
}.marks || []).filter((mark) => decorators.includes(mark));
|
|
3804
|
+
const marksWithoutAnnotationMarks = (__spreadValues$g({}, slate.Editor.marks(editor) || {}).marks || []).filter((mark) => decorators.includes(mark));
|
|
4644
3805
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
4645
3806
|
apply2(op), slate.Transforms.setNodes(editor, {
|
|
4646
3807
|
marks: marksWithoutAnnotationMarks
|
|
@@ -4673,6 +3834,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4673
3834
|
const addDecoratorActionImplementation = ({
|
|
4674
3835
|
action
|
|
4675
3836
|
}) => {
|
|
3837
|
+
var _a;
|
|
4676
3838
|
const editor = action.editor, mark = action.decorator;
|
|
4677
3839
|
if (editor.selection) {
|
|
4678
3840
|
if (slate.Range.isExpanded(editor.selection)) {
|
|
@@ -4685,7 +3847,10 @@ const addDecoratorActionImplementation = ({
|
|
|
4685
3847
|
at: editor.selection,
|
|
4686
3848
|
match: slate.Text.isText
|
|
4687
3849
|
})] : [];
|
|
4688
|
-
splitTextNodes.length > 1 && splitTextNodes.every((node) =>
|
|
3850
|
+
splitTextNodes.length > 1 && splitTextNodes.every((node) => {
|
|
3851
|
+
var _a2;
|
|
3852
|
+
return (_a2 = node[0].marks) == null ? void 0 : _a2.includes(mark);
|
|
3853
|
+
}) ? editor.removeMark(mark) : splitTextNodes.forEach(([node, path]) => {
|
|
4689
3854
|
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
4690
3855
|
slate.Transforms.setNodes(editor, {
|
|
4691
3856
|
marks
|
|
@@ -4701,7 +3866,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4701
3866
|
depth: 1
|
|
4702
3867
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4703
3868
|
if (lonelyEmptySpan) {
|
|
4704
|
-
const existingMarks = lonelyEmptySpan.marks
|
|
3869
|
+
const existingMarks = (_a = lonelyEmptySpan.marks) != null ? _a : [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
4705
3870
|
slate.Transforms.setNodes(editor, {
|
|
4706
3871
|
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
4707
3872
|
}, {
|
|
@@ -4709,12 +3874,9 @@ const addDecoratorActionImplementation = ({
|
|
|
4709
3874
|
match: (node) => editor.isTextSpan(node)
|
|
4710
3875
|
});
|
|
4711
3876
|
} else {
|
|
4712
|
-
const existingMarks = {
|
|
4713
|
-
...slate.Editor.marks(editor) || {}
|
|
4714
|
-
}.marks || [], marks = {
|
|
4715
|
-
...slate.Editor.marks(editor) || {},
|
|
3877
|
+
const existingMarks = __spreadValues$g({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, slate.Editor.marks(editor) || {}), {
|
|
4716
3878
|
marks: [...existingMarks, mark]
|
|
4717
|
-
};
|
|
3879
|
+
});
|
|
4718
3880
|
editor.marks = marks;
|
|
4719
3881
|
}
|
|
4720
3882
|
}
|
|
@@ -4723,6 +3885,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4723
3885
|
}, removeDecoratorActionImplementation = ({
|
|
4724
3886
|
action
|
|
4725
3887
|
}) => {
|
|
3888
|
+
var _a;
|
|
4726
3889
|
const editor = action.editor, mark = action.decorator, {
|
|
4727
3890
|
selection
|
|
4728
3891
|
} = editor;
|
|
@@ -4749,7 +3912,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4749
3912
|
depth: 1
|
|
4750
3913
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
4751
3914
|
if (lonelyEmptySpan) {
|
|
4752
|
-
const existingMarksWithoutDecorator = (lonelyEmptySpan.marks
|
|
3915
|
+
const existingMarksWithoutDecorator = ((_a = lonelyEmptySpan.marks) != null ? _a : []).filter((existingMark) => existingMark !== mark);
|
|
4753
3916
|
slate.Transforms.setNodes(editor, {
|
|
4754
3917
|
marks: existingMarksWithoutDecorator
|
|
4755
3918
|
}, {
|
|
@@ -4757,12 +3920,9 @@ const addDecoratorActionImplementation = ({
|
|
|
4757
3920
|
match: (node) => editor.isTextSpan(node)
|
|
4758
3921
|
});
|
|
4759
3922
|
} else {
|
|
4760
|
-
const existingMarks = {
|
|
4761
|
-
...slate.Editor.marks(editor) || {}
|
|
4762
|
-
}.marks || [], marks = {
|
|
4763
|
-
...slate.Editor.marks(editor) || {},
|
|
3923
|
+
const existingMarks = __spreadValues$g({}, slate.Editor.marks(editor) || {}).marks || [], marks = __spreadProps$b(__spreadValues$g({}, slate.Editor.marks(editor) || {}), {
|
|
4764
3924
|
marks: existingMarks.filter((eMark) => eMark !== mark)
|
|
4765
|
-
};
|
|
3925
|
+
});
|
|
4766
3926
|
editor.marks = {
|
|
4767
3927
|
marks: marks.marks,
|
|
4768
3928
|
_type: "span"
|
|
@@ -4781,11 +3941,10 @@ function isDecoratorActive({
|
|
|
4781
3941
|
at: editor.selection
|
|
4782
3942
|
}));
|
|
4783
3943
|
return selectedTextNodes.length === 0 ? !1 : slate.Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
3944
|
+
var _a;
|
|
4784
3945
|
const [node] = n;
|
|
4785
|
-
return node.marks
|
|
4786
|
-
}) : ({
|
|
4787
|
-
...slate.Editor.marks(editor) || {}
|
|
4788
|
-
}.marks || []).includes(decorator);
|
|
3946
|
+
return (_a = node.marks) == null ? void 0 : _a.includes(decorator);
|
|
3947
|
+
}) : (__spreadValues$g({}, slate.Editor.marks(editor) || {}).marks || []).includes(decorator);
|
|
4789
3948
|
}
|
|
4790
3949
|
const toggleDecoratorActionImplementation = ({
|
|
4791
3950
|
context,
|
|
@@ -4843,6 +4002,14 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4843
4002
|
}, editor;
|
|
4844
4003
|
};
|
|
4845
4004
|
}
|
|
4005
|
+
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) => {
|
|
4006
|
+
for (var prop in b || (b = {}))
|
|
4007
|
+
__hasOwnProp$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4008
|
+
if (__getOwnPropSymbols$f)
|
|
4009
|
+
for (var prop of __getOwnPropSymbols$f(b))
|
|
4010
|
+
__propIsEnum$f.call(b, prop) && __defNormalProp$f(a, prop, b[prop]);
|
|
4011
|
+
return a;
|
|
4012
|
+
}, __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
|
|
4846
4013
|
const debug$9 = debugWithName("plugin:withSchemaTypes");
|
|
4847
4014
|
function createWithSchemaTypes({
|
|
4848
4015
|
editorActor,
|
|
@@ -4860,11 +4027,10 @@ function createWithSchemaTypes({
|
|
|
4860
4027
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4861
4028
|
editorActor.send({
|
|
4862
4029
|
type: "normalizing"
|
|
4863
|
-
}), slate.Transforms.setNodes(editor, {
|
|
4864
|
-
...span,
|
|
4030
|
+
}), slate.Transforms.setNodes(editor, __spreadProps$a(__spreadValues$f({}, span), {
|
|
4865
4031
|
_type: schemaTypes.span.name,
|
|
4866
4032
|
_key: key
|
|
4867
|
-
}, {
|
|
4033
|
+
}), {
|
|
4868
4034
|
at: path
|
|
4869
4035
|
}), editorActor.send({
|
|
4870
4036
|
type: "done normalizing"
|
|
@@ -4889,6 +4055,14 @@ function createWithSchemaTypes({
|
|
|
4889
4055
|
}, editor;
|
|
4890
4056
|
};
|
|
4891
4057
|
}
|
|
4058
|
+
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) => {
|
|
4059
|
+
for (var prop in b || (b = {}))
|
|
4060
|
+
__hasOwnProp$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4061
|
+
if (__getOwnPropSymbols$e)
|
|
4062
|
+
for (var prop of __getOwnPropSymbols$e(b))
|
|
4063
|
+
__propIsEnum$e.call(b, prop) && __defNormalProp$e(a, prop, b[prop]);
|
|
4064
|
+
return a;
|
|
4065
|
+
}, __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
|
|
4892
4066
|
const debug$8 = debugWithName("plugin:withUtils");
|
|
4893
4067
|
function createWithUtils({
|
|
4894
4068
|
editorActor,
|
|
@@ -4912,29 +4086,26 @@ function createWithUtils({
|
|
|
4912
4086
|
} = 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);
|
|
4913
4087
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4914
4088
|
debug$8("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4915
|
-
anchor: {
|
|
4916
|
-
...selection.anchor,
|
|
4089
|
+
anchor: __spreadProps$9(__spreadValues$e({}, selection.anchor), {
|
|
4917
4090
|
offset: newStartOffset
|
|
4918
|
-
},
|
|
4919
|
-
focus: {
|
|
4920
|
-
...selection.focus,
|
|
4091
|
+
}),
|
|
4092
|
+
focus: __spreadProps$9(__spreadValues$e({}, selection.focus), {
|
|
4921
4093
|
offset: newEndOffset
|
|
4922
|
-
}
|
|
4094
|
+
})
|
|
4923
4095
|
});
|
|
4924
4096
|
return;
|
|
4925
4097
|
}
|
|
4926
4098
|
debug$8("pteExpandToWord: Can't expand to word here");
|
|
4927
4099
|
}
|
|
4928
|
-
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4100
|
+
}, editor.pteCreateTextBlock = (options) => toSlateValue([__spreadProps$9(__spreadValues$e(__spreadValues$e({
|
|
4929
4101
|
_type: schemaTypes.block.name,
|
|
4930
4102
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
4931
|
-
style: schemaTypes.styles[0].value || "normal"
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
} : {},
|
|
4103
|
+
style: schemaTypes.styles[0].value || "normal"
|
|
4104
|
+
}, options.listItem ? {
|
|
4105
|
+
listItem: options.listItem
|
|
4106
|
+
} : {}), options.level ? {
|
|
4107
|
+
level: options.level
|
|
4108
|
+
} : {}), {
|
|
4938
4109
|
markDefs: [],
|
|
4939
4110
|
children: [{
|
|
4940
4111
|
_type: "span",
|
|
@@ -4944,7 +4115,7 @@ function createWithUtils({
|
|
|
4944
4115
|
value
|
|
4945
4116
|
}) => value === decorator))
|
|
4946
4117
|
}]
|
|
4947
|
-
}], {
|
|
4118
|
+
})], {
|
|
4948
4119
|
schemaTypes
|
|
4949
4120
|
})[0], editor;
|
|
4950
4121
|
};
|
|
@@ -4990,6 +4161,14 @@ function createSlateEditor(config) {
|
|
|
4990
4161
|
};
|
|
4991
4162
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4992
4163
|
}
|
|
4164
|
+
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) => {
|
|
4165
|
+
for (var prop in b || (b = {}))
|
|
4166
|
+
__hasOwnProp$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4167
|
+
if (__getOwnPropSymbols$d)
|
|
4168
|
+
for (var prop of __getOwnPropSymbols$d(b))
|
|
4169
|
+
__propIsEnum$d.call(b, prop) && __defNormalProp$d(a, prop, b[prop]);
|
|
4170
|
+
return a;
|
|
4171
|
+
}, __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
|
|
4993
4172
|
const toggleListItemActionImplementation = ({
|
|
4994
4173
|
context,
|
|
4995
4174
|
action
|
|
@@ -4999,16 +4178,14 @@ const toggleListItemActionImplementation = ({
|
|
|
4999
4178
|
listItem: action.listItem
|
|
5000
4179
|
}) ? removeListItemActionImplementation({
|
|
5001
4180
|
context,
|
|
5002
|
-
action: {
|
|
5003
|
-
...action,
|
|
4181
|
+
action: __spreadProps$8(__spreadValues$d({}, action), {
|
|
5004
4182
|
type: "list item.remove"
|
|
5005
|
-
}
|
|
4183
|
+
})
|
|
5006
4184
|
}) : addListItemActionImplementation({
|
|
5007
4185
|
context,
|
|
5008
|
-
action: {
|
|
5009
|
-
...action,
|
|
4186
|
+
action: __spreadProps$8(__spreadValues$d({}, action), {
|
|
5010
4187
|
type: "list item.add"
|
|
5011
|
-
}
|
|
4188
|
+
})
|
|
5012
4189
|
});
|
|
5013
4190
|
}, removeListItemActionImplementation = ({
|
|
5014
4191
|
context,
|
|
@@ -5016,7 +4193,7 @@ const toggleListItemActionImplementation = ({
|
|
|
5016
4193
|
}) => {
|
|
5017
4194
|
if (!action.editor.selection)
|
|
5018
4195
|
return;
|
|
5019
|
-
const guards =
|
|
4196
|
+
const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
5020
4197
|
at: action.editor.selection,
|
|
5021
4198
|
match: (node) => guards.isListBlock(node)
|
|
5022
4199
|
})];
|
|
@@ -5030,7 +4207,7 @@ const toggleListItemActionImplementation = ({
|
|
|
5030
4207
|
}) => {
|
|
5031
4208
|
if (!action.editor.selection)
|
|
5032
4209
|
return;
|
|
5033
|
-
const guards =
|
|
4210
|
+
const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
5034
4211
|
at: action.editor.selection,
|
|
5035
4212
|
match: (node) => guards.isTextBlock(node)
|
|
5036
4213
|
})];
|
|
@@ -5054,6 +4231,14 @@ function isListItemActive({
|
|
|
5054
4231
|
})];
|
|
5055
4232
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => editor.isListBlock(node) && node.listItem === listItem) : !1;
|
|
5056
4233
|
}
|
|
4234
|
+
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) => {
|
|
4235
|
+
for (var prop in b || (b = {}))
|
|
4236
|
+
__hasOwnProp$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4237
|
+
if (__getOwnPropSymbols$c)
|
|
4238
|
+
for (var prop of __getOwnPropSymbols$c(b))
|
|
4239
|
+
__propIsEnum$c.call(b, prop) && __defNormalProp$c(a, prop, b[prop]);
|
|
4240
|
+
return a;
|
|
4241
|
+
}, __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
5057
4242
|
const toggleStyleActionImplementation = ({
|
|
5058
4243
|
context,
|
|
5059
4244
|
action
|
|
@@ -5063,16 +4248,14 @@ const toggleStyleActionImplementation = ({
|
|
|
5063
4248
|
style: action.style
|
|
5064
4249
|
}) ? removeStyleActionImplementation({
|
|
5065
4250
|
context,
|
|
5066
|
-
action: {
|
|
5067
|
-
...action,
|
|
4251
|
+
action: __spreadProps$7(__spreadValues$c({}, action), {
|
|
5068
4252
|
type: "style.remove"
|
|
5069
|
-
}
|
|
4253
|
+
})
|
|
5070
4254
|
}) : addStyleActionImplementation({
|
|
5071
4255
|
context,
|
|
5072
|
-
action: {
|
|
5073
|
-
...action,
|
|
4256
|
+
action: __spreadProps$7(__spreadValues$c({}, action), {
|
|
5074
4257
|
type: "style.add"
|
|
5075
|
-
}
|
|
4258
|
+
})
|
|
5076
4259
|
});
|
|
5077
4260
|
}, removeStyleActionImplementation = ({
|
|
5078
4261
|
context,
|
|
@@ -5080,7 +4263,7 @@ const toggleStyleActionImplementation = ({
|
|
|
5080
4263
|
}) => {
|
|
5081
4264
|
if (!action.editor.selection)
|
|
5082
4265
|
return;
|
|
5083
|
-
const defaultStyle = context.schema.styles[0].value, guards =
|
|
4266
|
+
const defaultStyle = context.schema.styles[0].value, guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
5084
4267
|
at: action.editor.selection,
|
|
5085
4268
|
match: (node) => guards.isTextBlock(node)
|
|
5086
4269
|
})];
|
|
@@ -5096,7 +4279,7 @@ const toggleStyleActionImplementation = ({
|
|
|
5096
4279
|
}) => {
|
|
5097
4280
|
if (!action.editor.selection)
|
|
5098
4281
|
return;
|
|
5099
|
-
const guards =
|
|
4282
|
+
const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
|
|
5100
4283
|
at: action.editor.selection,
|
|
5101
4284
|
match: (node) => guards.isTextBlock(node)
|
|
5102
4285
|
})];
|
|
@@ -5119,6 +4302,14 @@ function isStyleActive({
|
|
|
5119
4302
|
})];
|
|
5120
4303
|
return selectedBlocks.length > 0 ? selectedBlocks.every(([node]) => node.style === style) : !1;
|
|
5121
4304
|
}
|
|
4305
|
+
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) => {
|
|
4306
|
+
for (var prop in b || (b = {}))
|
|
4307
|
+
__hasOwnProp$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4308
|
+
if (__getOwnPropSymbols$b)
|
|
4309
|
+
for (var prop of __getOwnPropSymbols$b(b))
|
|
4310
|
+
__propIsEnum$b.call(b, prop) && __defNormalProp$b(a, prop, b[prop]);
|
|
4311
|
+
return a;
|
|
4312
|
+
};
|
|
5122
4313
|
const debug$6 = debugWithName("API:editable");
|
|
5123
4314
|
function createEditableAPI(editor, editorActor) {
|
|
5124
4315
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
@@ -5181,9 +4372,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5181
4372
|
return console.warn(err), !1;
|
|
5182
4373
|
}
|
|
5183
4374
|
},
|
|
5184
|
-
marks: () => ({
|
|
5185
|
-
...slate.Editor.marks(editor) || {}
|
|
5186
|
-
}).marks || [],
|
|
4375
|
+
marks: () => __spreadValues$b({}, slate.Editor.marks(editor) || {}).marks || [],
|
|
5187
4376
|
undo: () => editor.undo(),
|
|
5188
4377
|
redo: () => editor.redo(),
|
|
5189
4378
|
select: (selection) => {
|
|
@@ -5205,6 +4394,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5205
4394
|
}
|
|
5206
4395
|
},
|
|
5207
4396
|
insertChild: (type, value) => {
|
|
4397
|
+
var _a, _b, _c;
|
|
5208
4398
|
if (type.name !== types2.span.name)
|
|
5209
4399
|
return editorActor.send({
|
|
5210
4400
|
type: "behavior event",
|
|
@@ -5216,7 +4406,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5216
4406
|
}
|
|
5217
4407
|
},
|
|
5218
4408
|
editor
|
|
5219
|
-
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)
|
|
4409
|
+
}), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)) == null ? void 0 : _a.focus.path) != null ? _b : [];
|
|
5220
4410
|
if (!editor.selection)
|
|
5221
4411
|
throw new Error("The editor has no selection");
|
|
5222
4412
|
const [focusBlock] = Array.from(slate.Editor.nodes(editor, {
|
|
@@ -5230,11 +4420,10 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5230
4420
|
const child = toSlateValue([{
|
|
5231
4421
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5232
4422
|
_type: types2.block.name,
|
|
5233
|
-
children: [{
|
|
4423
|
+
children: [__spreadValues$b({
|
|
5234
4424
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
5235
|
-
_type: type.name
|
|
5236
|
-
|
|
5237
|
-
}]
|
|
4425
|
+
_type: type.name
|
|
4426
|
+
}, value || {})]
|
|
5238
4427
|
}], {
|
|
5239
4428
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
5240
4429
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
@@ -5244,27 +4433,30 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5244
4433
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
5245
4434
|
select: !0,
|
|
5246
4435
|
at: editor.selection
|
|
5247
|
-
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)
|
|
4436
|
+
}), editor.onChange(), ((_c = toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)) == null ? void 0 : _c.focus.path) || [];
|
|
5248
4437
|
},
|
|
5249
|
-
insertBlock: (type, value) =>
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
type: "
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
4438
|
+
insertBlock: (type, value) => {
|
|
4439
|
+
var _a, _b;
|
|
4440
|
+
return editorActor.send({
|
|
4441
|
+
type: "behavior event",
|
|
4442
|
+
behaviorEvent: {
|
|
4443
|
+
type: "insert.block object",
|
|
4444
|
+
blockObject: {
|
|
4445
|
+
name: type.name,
|
|
4446
|
+
value
|
|
4447
|
+
},
|
|
4448
|
+
placement: "auto"
|
|
5256
4449
|
},
|
|
5257
|
-
|
|
5258
|
-
},
|
|
5259
|
-
|
|
5260
|
-
}), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? []),
|
|
4450
|
+
editor
|
|
4451
|
+
}), (_b = (_a = toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)) == null ? void 0 : _a.focus.path) != null ? _b : [];
|
|
4452
|
+
},
|
|
5261
4453
|
hasBlockStyle: (style) => {
|
|
5262
4454
|
try {
|
|
5263
4455
|
return isStyleActive({
|
|
5264
4456
|
editor,
|
|
5265
4457
|
style
|
|
5266
4458
|
});
|
|
5267
|
-
} catch {
|
|
4459
|
+
} catch (e) {
|
|
5268
4460
|
return !1;
|
|
5269
4461
|
}
|
|
5270
4462
|
},
|
|
@@ -5274,7 +4466,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5274
4466
|
editor,
|
|
5275
4467
|
listItem
|
|
5276
4468
|
});
|
|
5277
|
-
} catch {
|
|
4469
|
+
} catch (e) {
|
|
5278
4470
|
return !1;
|
|
5279
4471
|
}
|
|
5280
4472
|
},
|
|
@@ -5319,11 +4511,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5319
4511
|
match: (n) => n._key === element._key
|
|
5320
4512
|
}) || [])[0] || [void 0];
|
|
5321
4513
|
node = slateReact.ReactEditor.toDOMNode(editor, item);
|
|
5322
|
-
} catch {
|
|
4514
|
+
} catch (e) {
|
|
5323
4515
|
}
|
|
5324
4516
|
return node;
|
|
5325
4517
|
},
|
|
5326
4518
|
activeAnnotations: () => {
|
|
4519
|
+
var _a;
|
|
5327
4520
|
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
5328
4521
|
return [];
|
|
5329
4522
|
try {
|
|
@@ -5335,12 +4528,12 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5335
4528
|
const [block] = slate.Editor.node(editor, path, {
|
|
5336
4529
|
depth: 1
|
|
5337
4530
|
});
|
|
5338
|
-
editor.isTextBlock(block) && block.markDefs
|
|
4531
|
+
editor.isTextBlock(block) && ((_a = block.markDefs) == null || _a.forEach((def) => {
|
|
5339
4532
|
slate.Text.isText(span) && span.marks && Array.isArray(span.marks) && span.marks.includes(def._key) && activeAnnotations.push(def);
|
|
5340
|
-
});
|
|
4533
|
+
}));
|
|
5341
4534
|
}
|
|
5342
4535
|
return activeAnnotations;
|
|
5343
|
-
} catch {
|
|
4536
|
+
} catch (e) {
|
|
5344
4537
|
return [];
|
|
5345
4538
|
}
|
|
5346
4539
|
},
|
|
@@ -5362,7 +4555,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5362
4555
|
type: "annotation.add",
|
|
5363
4556
|
annotation: {
|
|
5364
4557
|
name: type.name,
|
|
5365
|
-
value: value
|
|
4558
|
+
value: value != null ? value : {}
|
|
5366
4559
|
},
|
|
5367
4560
|
editor
|
|
5368
4561
|
}
|
|
@@ -5375,7 +4568,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5375
4568
|
if (!(range && range.anchor.path.length > 0 && range.focus.path.length > 0))
|
|
5376
4569
|
throw new Error("Invalid range");
|
|
5377
4570
|
if (range) {
|
|
5378
|
-
if (!options
|
|
4571
|
+
if (!(options != null && options.mode) || (options == null ? void 0 : options.mode) === "selected") {
|
|
5379
4572
|
debug$6("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
5380
4573
|
at: range,
|
|
5381
4574
|
hanging: !0,
|
|
@@ -5383,11 +4576,11 @@ function createEditableAPI(editor, editorActor) {
|
|
|
5383
4576
|
}), editor.onChange();
|
|
5384
4577
|
return;
|
|
5385
4578
|
}
|
|
5386
|
-
options
|
|
4579
|
+
(options == null ? void 0 : options.mode) === "blocks" && (debug$6("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
5387
4580
|
at: range,
|
|
5388
4581
|
voids: !0,
|
|
5389
4582
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
5390
|
-
})), options
|
|
4583
|
+
})), (options == null ? void 0 : options.mode) === "children" && (debug$6("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
5391
4584
|
at: range,
|
|
5392
4585
|
voids: !0,
|
|
5393
4586
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -5444,15 +4637,26 @@ function isAnnotationActive({
|
|
|
5444
4637
|
at: editor.selection,
|
|
5445
4638
|
match: (node) => slate.Text.isText(node)
|
|
5446
4639
|
})];
|
|
5447
|
-
if (spans.length === 0 || spans.some(([span]) =>
|
|
4640
|
+
if (spans.length === 0 || spans.some(([span]) => {
|
|
4641
|
+
var _a;
|
|
4642
|
+
return !types.isPortableTextSpan(span) || !span.marks || ((_a = span.marks) == null ? void 0 : _a.length) === 0;
|
|
4643
|
+
})) return !1;
|
|
5448
4644
|
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
5449
4645
|
const [block] = slate.Editor.node(editor, path, {
|
|
5450
4646
|
depth: 1
|
|
5451
4647
|
});
|
|
5452
4648
|
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
5453
4649
|
}, []);
|
|
5454
|
-
return spans.every(([span]) =>
|
|
5455
|
-
|
|
4650
|
+
return spans.every(([span]) => {
|
|
4651
|
+
var _a;
|
|
4652
|
+
if (!types.isPortableTextSpan(span)) return !1;
|
|
4653
|
+
const spanMarkDefs = (_a = span.marks) == null ? void 0 : _a.map((markKey) => {
|
|
4654
|
+
var _a2;
|
|
4655
|
+
return (_a2 = selectionMarkDefs.find((def) => (def == null ? void 0 : def._key) === markKey)) == null ? void 0 : _a2._type;
|
|
4656
|
+
});
|
|
4657
|
+
return spanMarkDefs == null ? void 0 : spanMarkDefs.includes(annotation.name);
|
|
4658
|
+
});
|
|
4659
|
+
} catch (e) {
|
|
5456
4660
|
return !1;
|
|
5457
4661
|
}
|
|
5458
4662
|
}
|
|
@@ -5460,6 +4664,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5460
4664
|
context,
|
|
5461
4665
|
action
|
|
5462
4666
|
}) => {
|
|
4667
|
+
var _a, _b;
|
|
5463
4668
|
const editor = action.editor, {
|
|
5464
4669
|
selection: originalSelection
|
|
5465
4670
|
} = editor;
|
|
@@ -5477,13 +4682,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5477
4682
|
for (const [block, blockPath] of selectedBlocks) {
|
|
5478
4683
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
5479
4684
|
continue;
|
|
5480
|
-
const annotationKey = context.keyGenerator(), markDefs = block.markDefs
|
|
4685
|
+
const annotationKey = context.keyGenerator(), markDefs = (_a = block.markDefs) != null ? _a : [];
|
|
5481
4686
|
markDefs.find((markDef) => markDef._type === action.annotation.name && markDef._key === annotationKey) === void 0 && (slate.Transforms.setNodes(editor, {
|
|
5482
|
-
markDefs: [...markDefs, {
|
|
4687
|
+
markDefs: [...markDefs, __spreadValues$b({
|
|
5483
4688
|
_type: action.annotation.name,
|
|
5484
|
-
_key: annotationKey
|
|
5485
|
-
|
|
5486
|
-
}]
|
|
4689
|
+
_key: annotationKey
|
|
4690
|
+
}, action.annotation.value)]
|
|
5487
4691
|
}, {
|
|
5488
4692
|
at: blockPath
|
|
5489
4693
|
}), markDefPath = [{
|
|
@@ -5498,7 +4702,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5498
4702
|
for (const [span, path] of children) {
|
|
5499
4703
|
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
5500
4704
|
continue;
|
|
5501
|
-
const marks = span.marks
|
|
4705
|
+
const marks = (_b = span.marks) != null ? _b : [], existingSameTypeAnnotations = marks.filter((mark) => markDefs.some((markDef) => markDef._key === mark && markDef._type === action.annotation.name));
|
|
5502
4706
|
slate.Transforms.setNodes(editor, {
|
|
5503
4707
|
marks: [...marks.filter((mark) => !existingSameTypeAnnotations.includes(mark)), annotationKey]
|
|
5504
4708
|
}, {
|
|
@@ -5520,6 +4724,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5520
4724
|
}, removeAnnotationActionImplementation = ({
|
|
5521
4725
|
action
|
|
5522
4726
|
}) => {
|
|
4727
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
5523
4728
|
const editor = action.editor;
|
|
5524
4729
|
if (debug$6("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5525
4730
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
@@ -5528,12 +4733,12 @@ const addAnnotationActionImplementation = ({
|
|
|
5528
4733
|
});
|
|
5529
4734
|
if (!editor.isTextBlock(block))
|
|
5530
4735
|
return;
|
|
5531
|
-
const potentialAnnotations = (block.markDefs
|
|
4736
|
+
const potentialAnnotations = ((_a = block.markDefs) != null ? _a : []).filter((markDef) => markDef._type === action.annotation.name), [selectedChild, selectedChildPath] = slate.Editor.node(editor, editor.selection, {
|
|
5532
4737
|
depth: 2
|
|
5533
4738
|
});
|
|
5534
4739
|
if (!editor.isTextSpan(selectedChild))
|
|
5535
4740
|
return;
|
|
5536
|
-
const annotationToRemove = selectedChild.marks
|
|
4741
|
+
const annotationToRemove = (_b = selectedChild.marks) == null ? void 0 : _b.find((mark) => potentialAnnotations.some((markDef) => markDef._key === mark));
|
|
5537
4742
|
if (!annotationToRemove)
|
|
5538
4743
|
return;
|
|
5539
4744
|
const previousSpansWithSameAnnotation = [];
|
|
@@ -5541,20 +4746,20 @@ const addAnnotationActionImplementation = ({
|
|
|
5541
4746
|
reverse: !0
|
|
5542
4747
|
}))
|
|
5543
4748
|
if (editor.isTextSpan(child) && slate.Path.isBefore(childPath, selectedChildPath))
|
|
5544
|
-
if (child.marks
|
|
4749
|
+
if ((_c = child.marks) != null && _c.includes(annotationToRemove))
|
|
5545
4750
|
previousSpansWithSameAnnotation.push([child, childPath]);
|
|
5546
4751
|
else
|
|
5547
4752
|
break;
|
|
5548
4753
|
const nextSpansWithSameAnnotation = [];
|
|
5549
4754
|
for (const [child, childPath] of slate.Node.children(editor, blockPath))
|
|
5550
4755
|
if (editor.isTextSpan(child) && slate.Path.isAfter(childPath, selectedChildPath))
|
|
5551
|
-
if (child.marks
|
|
4756
|
+
if ((_d = child.marks) != null && _d.includes(annotationToRemove))
|
|
5552
4757
|
nextSpansWithSameAnnotation.push([child, childPath]);
|
|
5553
4758
|
else
|
|
5554
4759
|
break;
|
|
5555
4760
|
for (const [child, childPath] of [...previousSpansWithSameAnnotation, [selectedChild, selectedChildPath], ...nextSpansWithSameAnnotation])
|
|
5556
4761
|
slate.Transforms.setNodes(editor, {
|
|
5557
|
-
marks: child.marks
|
|
4762
|
+
marks: (_e = child.marks) == null ? void 0 : _e.filter((mark) => mark !== annotationToRemove)
|
|
5558
4763
|
}, {
|
|
5559
4764
|
at: childPath
|
|
5560
4765
|
});
|
|
@@ -5573,7 +4778,10 @@ const addAnnotationActionImplementation = ({
|
|
|
5573
4778
|
for (const [child, childPath] of children) {
|
|
5574
4779
|
if (!editor.isTextSpan(child) || !slate.Range.includes(editor.selection, childPath))
|
|
5575
4780
|
continue;
|
|
5576
|
-
const markDefs = block.markDefs
|
|
4781
|
+
const markDefs = (_f = block.markDefs) != null ? _f : [], marks = (_g = child.marks) != null ? _g : [], marksWithoutAnnotation = marks.filter((mark) => {
|
|
4782
|
+
const markDef = markDefs.find((markDef2) => markDef2._key === mark);
|
|
4783
|
+
return (markDef == null ? void 0 : markDef._type) !== action.annotation.name;
|
|
4784
|
+
});
|
|
5577
4785
|
marksWithoutAnnotation.length !== marks.length && slate.Transforms.setNodes(editor, {
|
|
5578
4786
|
marks: marksWithoutAnnotation
|
|
5579
4787
|
}, {
|
|
@@ -5616,11 +4824,12 @@ function insertBlock({
|
|
|
5616
4824
|
editor,
|
|
5617
4825
|
schema: schema2
|
|
5618
4826
|
}) {
|
|
4827
|
+
var _a;
|
|
5619
4828
|
if (editor.selection) {
|
|
5620
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(editor, {
|
|
4829
|
+
const [focusBlock, focusBlockPath] = (_a = Array.from(slate.Editor.nodes(editor, {
|
|
5621
4830
|
at: editor.selection.focus.path.slice(0, 1),
|
|
5622
4831
|
match: (n) => !slate.Editor.isEditor(n)
|
|
5623
|
-
}))[0]
|
|
4832
|
+
}))[0]) != null ? _a : [void 0, void 0];
|
|
5624
4833
|
if (placement === "after") {
|
|
5625
4834
|
const nextPath = [focusBlockPath[0] + 1];
|
|
5626
4835
|
slate.Transforms.insertNodes(editor, block, {
|
|
@@ -5652,15 +4861,22 @@ function insertBlock({
|
|
|
5652
4861
|
});
|
|
5653
4862
|
}
|
|
5654
4863
|
}
|
|
4864
|
+
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) => {
|
|
4865
|
+
for (var prop in b || (b = {}))
|
|
4866
|
+
__hasOwnProp$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4867
|
+
if (__getOwnPropSymbols$a)
|
|
4868
|
+
for (var prop of __getOwnPropSymbols$a(b))
|
|
4869
|
+
__propIsEnum$a.call(b, prop) && __defNormalProp$a(a, prop, b[prop]);
|
|
4870
|
+
return a;
|
|
4871
|
+
};
|
|
5655
4872
|
const insertBlockObjectActionImplementation = ({
|
|
5656
4873
|
context,
|
|
5657
4874
|
action
|
|
5658
4875
|
}) => {
|
|
5659
|
-
const block = toSlateValue([{
|
|
4876
|
+
const block = toSlateValue([__spreadValues$a({
|
|
5660
4877
|
_key: context.keyGenerator(),
|
|
5661
|
-
_type: action.blockObject.name
|
|
5662
|
-
|
|
5663
|
-
}], {
|
|
4878
|
+
_type: action.blockObject.name
|
|
4879
|
+
}, action.blockObject.value ? action.blockObject.value : {})], {
|
|
5664
4880
|
schemaTypes: context.schema
|
|
5665
4881
|
})[0];
|
|
5666
4882
|
insertBlock({
|
|
@@ -5669,19 +4885,29 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5669
4885
|
editor: action.editor,
|
|
5670
4886
|
schema: context.schema
|
|
5671
4887
|
});
|
|
5672
|
-
}
|
|
4888
|
+
};
|
|
4889
|
+
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) => {
|
|
4890
|
+
for (var prop in b || (b = {}))
|
|
4891
|
+
__hasOwnProp$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
4892
|
+
if (__getOwnPropSymbols$9)
|
|
4893
|
+
for (var prop of __getOwnPropSymbols$9(b))
|
|
4894
|
+
__propIsEnum$9.call(b, prop) && __defNormalProp$9(a, prop, b[prop]);
|
|
4895
|
+
return a;
|
|
4896
|
+
}, __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
4897
|
+
const insertBreakActionImplementation = ({
|
|
5673
4898
|
context,
|
|
5674
4899
|
action
|
|
5675
4900
|
}) => {
|
|
4901
|
+
var _a, _b, _c, _d, _e;
|
|
5676
4902
|
const keyGenerator = context.keyGenerator, schema2 = context.schema, editor = action.editor;
|
|
5677
4903
|
if (!editor.selection)
|
|
5678
4904
|
return;
|
|
5679
|
-
const [focusSpan] = Array.from(slate.Editor.nodes(editor, {
|
|
4905
|
+
const [focusSpan] = (_a = Array.from(slate.Editor.nodes(editor, {
|
|
5680
4906
|
mode: "lowest",
|
|
5681
4907
|
at: editor.selection.focus,
|
|
5682
4908
|
match: (n) => editor.isTextSpan(n),
|
|
5683
4909
|
voids: !1
|
|
5684
|
-
}))[0]
|
|
4910
|
+
}))[0]) != null ? _a : [void 0], focusDecorators = (_c = (_b = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _b.filter((mark) => schema2.decorators.some((decorator) => decorator.value === mark))) != null ? _c : [], focusAnnotations = (_e = (_d = focusSpan == null ? void 0 : focusSpan.marks) == null ? void 0 : _d.filter((mark) => !schema2.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 = slate.Node.descendant(editor, focusBlockPath);
|
|
5685
4911
|
if (editor.isTextBlock(focusBlock)) {
|
|
5686
4912
|
const [start, end] = slate.Range.edges(editor.selection), lastFocusBlockChild = focusBlock.children[focusBlock.children.length - 1], atTheEndOfBlock = isEqual__default.default(start, {
|
|
5687
4913
|
path: [...focusBlockPath, focusBlock.children.length - 1],
|
|
@@ -5720,6 +4946,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5720
4946
|
const selectionAcrossBlocks = anchorBlockPath[0] !== focusBlockPath[0];
|
|
5721
4947
|
if (!atTheStartOfBlock && !atTheEndOfBlock && !selectionAcrossBlocks) {
|
|
5722
4948
|
slate.Editor.withoutNormalizing(editor, () => {
|
|
4949
|
+
var _a2;
|
|
5723
4950
|
if (!editor.selection)
|
|
5724
4951
|
return;
|
|
5725
4952
|
slate.Transforms.splitNodes(editor, {
|
|
@@ -5742,20 +4969,28 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5742
4969
|
for (const [child, childPath] of children) {
|
|
5743
4970
|
if (!editor.isTextSpan(child))
|
|
5744
4971
|
continue;
|
|
5745
|
-
const marks = child.marks
|
|
4972
|
+
const marks = (_a2 = child.marks) != null ? _a2 : [];
|
|
5746
4973
|
for (const mark of marks)
|
|
5747
|
-
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) =>
|
|
5748
|
-
|
|
4974
|
+
schema2.decorators.some((decorator) => decorator.value === mark) || prevNodeSpans.some((prevNodeSpan) => {
|
|
4975
|
+
var _a3;
|
|
4976
|
+
return (_a3 = prevNodeSpan.marks) == null ? void 0 : _a3.includes(mark);
|
|
4977
|
+
}) && !newMarkDefKeys.has(mark) && newMarkDefKeys.set(mark, keyGenerator());
|
|
4978
|
+
const newMarks = marks.map((mark) => {
|
|
4979
|
+
var _a3;
|
|
4980
|
+
return (_a3 = newMarkDefKeys.get(mark)) != null ? _a3 : mark;
|
|
4981
|
+
});
|
|
5749
4982
|
isEqual__default.default(marks, newMarks) || slate.Transforms.setNodes(editor, {
|
|
5750
4983
|
marks: newMarks
|
|
5751
4984
|
}, {
|
|
5752
4985
|
at: childPath
|
|
5753
4986
|
});
|
|
5754
4987
|
}
|
|
5755
|
-
const newMarkDefs = nextNode.markDefs.map((markDef) =>
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
4988
|
+
const newMarkDefs = nextNode.markDefs.map((markDef) => {
|
|
4989
|
+
var _a3;
|
|
4990
|
+
return __spreadProps$6(__spreadValues$9({}, markDef), {
|
|
4991
|
+
_key: (_a3 = newMarkDefKeys.get(markDef._key)) != null ? _a3 : markDef._key
|
|
4992
|
+
});
|
|
4993
|
+
});
|
|
5759
4994
|
isEqual__default.default(nextNode.markDefs, newMarkDefs) || slate.Transforms.setNodes(editor, {
|
|
5760
4995
|
markDefs: newMarkDefs
|
|
5761
4996
|
}, {
|
|
@@ -5776,15 +5011,24 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5776
5011
|
}) => {
|
|
5777
5012
|
insertBreakActionImplementation({
|
|
5778
5013
|
context,
|
|
5779
|
-
action: {
|
|
5780
|
-
...action,
|
|
5014
|
+
action: __spreadProps$6(__spreadValues$9({}, action), {
|
|
5781
5015
|
type: "insert.break"
|
|
5782
|
-
}
|
|
5016
|
+
})
|
|
5783
5017
|
});
|
|
5784
|
-
}
|
|
5018
|
+
};
|
|
5019
|
+
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) => {
|
|
5020
|
+
for (var prop in b || (b = {}))
|
|
5021
|
+
__hasOwnProp$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5022
|
+
if (__getOwnPropSymbols$8)
|
|
5023
|
+
for (var prop of __getOwnPropSymbols$8(b))
|
|
5024
|
+
__propIsEnum$8.call(b, prop) && __defNormalProp$8(a, prop, b[prop]);
|
|
5025
|
+
return a;
|
|
5026
|
+
};
|
|
5027
|
+
const insertInlineObjectActionImplementation = ({
|
|
5785
5028
|
context,
|
|
5786
5029
|
action
|
|
5787
5030
|
}) => {
|
|
5031
|
+
var _a, _b;
|
|
5788
5032
|
if (!context.schema.inlineObjects.some((inlineObject) => inlineObject.name === action.inlineObject.name)) {
|
|
5789
5033
|
console.error("Unable to insert unknown inline object");
|
|
5790
5034
|
return;
|
|
@@ -5793,60 +5037,77 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5793
5037
|
console.error("Unable to insert inline object without selection");
|
|
5794
5038
|
return;
|
|
5795
5039
|
}
|
|
5796
|
-
const [focusTextBlock] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5040
|
+
const [focusTextBlock] = (_a = Array.from(slate.Editor.nodes(action.editor, {
|
|
5797
5041
|
at: action.editor.selection.focus.path,
|
|
5798
5042
|
match: (node) => action.editor.isTextBlock(node)
|
|
5799
|
-
})).at(0)
|
|
5043
|
+
})).at(0)) != null ? _a : [void 0, void 0];
|
|
5800
5044
|
if (!focusTextBlock) {
|
|
5801
5045
|
console.error("Unable to perform action without focus text block");
|
|
5802
5046
|
return;
|
|
5803
5047
|
}
|
|
5804
|
-
const
|
|
5048
|
+
const block = toSlateValue([{
|
|
5805
5049
|
_type: context.schema.block.name,
|
|
5806
5050
|
_key: context.keyGenerator(),
|
|
5807
|
-
children: [{
|
|
5051
|
+
children: [__spreadValues$8({
|
|
5808
5052
|
_type: action.inlineObject.name,
|
|
5809
|
-
_key: context.keyGenerator()
|
|
5810
|
-
|
|
5811
|
-
}]
|
|
5053
|
+
_key: context.keyGenerator()
|
|
5054
|
+
}, (_b = action.inlineObject.value) != null ? _b : {})]
|
|
5812
5055
|
}], {
|
|
5813
5056
|
schemaTypes: context.schema
|
|
5814
|
-
}).at(0)
|
|
5057
|
+
}).at(0), child = block == null ? void 0 : block.children.at(0);
|
|
5815
5058
|
if (!child) {
|
|
5816
5059
|
console.error("Unable to insert inline object");
|
|
5817
5060
|
return;
|
|
5818
5061
|
}
|
|
5819
5062
|
slate.Transforms.insertNodes(action.editor, child);
|
|
5820
|
-
}
|
|
5063
|
+
};
|
|
5064
|
+
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) => {
|
|
5065
|
+
for (var prop in b || (b = {}))
|
|
5066
|
+
__hasOwnProp$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5067
|
+
if (__getOwnPropSymbols$7)
|
|
5068
|
+
for (var prop of __getOwnPropSymbols$7(b))
|
|
5069
|
+
__propIsEnum$7.call(b, prop) && __defNormalProp$7(a, prop, b[prop]);
|
|
5070
|
+
return a;
|
|
5071
|
+
};
|
|
5072
|
+
const insertSpanActionImplementation = ({
|
|
5821
5073
|
context,
|
|
5822
5074
|
action
|
|
5823
5075
|
}) => {
|
|
5076
|
+
var _a, _b, _c, _d;
|
|
5824
5077
|
if (!action.editor.selection) {
|
|
5825
5078
|
console.error("Unable to perform action without selection", action);
|
|
5826
5079
|
return;
|
|
5827
5080
|
}
|
|
5828
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
|
|
5081
|
+
const [focusBlock, focusBlockPath] = (_a = Array.from(slate.Editor.nodes(action.editor, {
|
|
5829
5082
|
at: action.editor.selection.focus.path,
|
|
5830
5083
|
match: (node) => action.editor.isTextBlock(node)
|
|
5831
|
-
}))[0]
|
|
5084
|
+
}))[0]) != null ? _a : [void 0, void 0];
|
|
5832
5085
|
if (!focusBlock || !focusBlockPath) {
|
|
5833
5086
|
console.error("Unable to perform action without focus block", action);
|
|
5834
5087
|
return;
|
|
5835
5088
|
}
|
|
5836
|
-
const markDefs = focusBlock.markDefs
|
|
5089
|
+
const markDefs = (_b = focusBlock.markDefs) != null ? _b : [], annotations = action.annotations ? action.annotations.map((annotation) => __spreadValues$7({
|
|
5837
5090
|
_type: annotation.name,
|
|
5838
|
-
_key: context.keyGenerator()
|
|
5839
|
-
|
|
5840
|
-
})) : void 0;
|
|
5091
|
+
_key: context.keyGenerator()
|
|
5092
|
+
}, annotation.value)) : void 0;
|
|
5841
5093
|
annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
|
|
5842
5094
|
markDefs: [...markDefs, ...annotations]
|
|
5843
5095
|
}), slate.Transforms.insertNodes(action.editor, {
|
|
5844
5096
|
_type: "span",
|
|
5845
5097
|
_key: context.keyGenerator(),
|
|
5846
5098
|
text: action.text,
|
|
5847
|
-
marks: [...annotations
|
|
5099
|
+
marks: [...(_c = annotations == null ? void 0 : annotations.map((annotation) => annotation._key)) != null ? _c : [], ...(_d = action.decorators) != null ? _d : []]
|
|
5848
5100
|
});
|
|
5849
|
-
}
|
|
5101
|
+
};
|
|
5102
|
+
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) => {
|
|
5103
|
+
for (var prop in b || (b = {}))
|
|
5104
|
+
__hasOwnProp$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5105
|
+
if (__getOwnPropSymbols$6)
|
|
5106
|
+
for (var prop of __getOwnPropSymbols$6(b))
|
|
5107
|
+
__propIsEnum$6.call(b, prop) && __defNormalProp$6(a, prop, b[prop]);
|
|
5108
|
+
return a;
|
|
5109
|
+
};
|
|
5110
|
+
const textBlockSetActionImplementation = ({
|
|
5850
5111
|
action
|
|
5851
5112
|
}) => {
|
|
5852
5113
|
const at = toSlateRange({
|
|
@@ -5859,17 +5120,13 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5859
5120
|
offset: 0
|
|
5860
5121
|
}
|
|
5861
5122
|
}, action.editor);
|
|
5862
|
-
slate.Transforms.setNodes(action.editor, {
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
|
|
5869
|
-
...action.level ? {
|
|
5870
|
-
level: action.level
|
|
5871
|
-
} : {}
|
|
5872
|
-
}, {
|
|
5123
|
+
slate.Transforms.setNodes(action.editor, __spreadValues$6(__spreadValues$6(__spreadValues$6({}, action.style ? {
|
|
5124
|
+
style: action.style
|
|
5125
|
+
} : {}), action.listItem ? {
|
|
5126
|
+
listItem: action.listItem
|
|
5127
|
+
} : {}), action.level ? {
|
|
5128
|
+
level: action.level
|
|
5129
|
+
} : {}), {
|
|
5873
5130
|
at
|
|
5874
5131
|
});
|
|
5875
5132
|
}, textBlockUnsetActionImplementation = ({
|
|
@@ -5888,7 +5145,16 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5888
5145
|
slate.Transforms.unsetNodes(action.editor, action.props, {
|
|
5889
5146
|
at
|
|
5890
5147
|
});
|
|
5891
|
-
}
|
|
5148
|
+
};
|
|
5149
|
+
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) => {
|
|
5150
|
+
for (var prop in b || (b = {}))
|
|
5151
|
+
__hasOwnProp$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5152
|
+
if (__getOwnPropSymbols$5)
|
|
5153
|
+
for (var prop of __getOwnPropSymbols$5(b))
|
|
5154
|
+
__propIsEnum$5.call(b, prop) && __defNormalProp$5(a, prop, b[prop]);
|
|
5155
|
+
return a;
|
|
5156
|
+
}, __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
|
|
5157
|
+
const behaviorActionImplementations = {
|
|
5892
5158
|
"annotation.add": addAnnotationActionImplementation,
|
|
5893
5159
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
5894
5160
|
"annotation.toggle": toggleAnnotationActionImplementation,
|
|
@@ -5940,10 +5206,10 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5940
5206
|
context,
|
|
5941
5207
|
action
|
|
5942
5208
|
}) => {
|
|
5943
|
-
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), anchor = blockOffsetToSpanSelectionPoint({
|
|
5209
|
+
const value = fromSlateValue(action.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(action.editor)), anchor = behavior_core.blockOffsetToSpanSelectionPoint({
|
|
5944
5210
|
value,
|
|
5945
5211
|
blockOffset: action.anchor
|
|
5946
|
-
}), focus = blockOffsetToSpanSelectionPoint({
|
|
5212
|
+
}), focus = behavior_core.blockOffsetToSpanSelectionPoint({
|
|
5947
5213
|
value,
|
|
5948
5214
|
blockOffset: action.focus
|
|
5949
5215
|
});
|
|
@@ -5977,15 +5243,15 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5977
5243
|
context,
|
|
5978
5244
|
action
|
|
5979
5245
|
}) => {
|
|
5246
|
+
var _a, _b, _c, _d;
|
|
5980
5247
|
const block = toSlateValue([{
|
|
5981
5248
|
_key: context.keyGenerator(),
|
|
5982
5249
|
_type: context.schema.block.name,
|
|
5983
|
-
style: context.schema.styles[0].value
|
|
5250
|
+
style: (_a = context.schema.styles[0].value) != null ? _a : "normal",
|
|
5984
5251
|
markDefs: [],
|
|
5985
|
-
children: action.textBlock
|
|
5986
|
-
...child,
|
|
5252
|
+
children: (_d = (_c = (_b = action.textBlock) == null ? void 0 : _b.children) == null ? void 0 : _c.map((child) => __spreadProps$5(__spreadValues$5({}, child), {
|
|
5987
5253
|
_key: context.keyGenerator()
|
|
5988
|
-
}))
|
|
5254
|
+
}))) != null ? _d : [{
|
|
5989
5255
|
_type: context.schema.span.name,
|
|
5990
5256
|
_key: context.keyGenerator(),
|
|
5991
5257
|
text: ""
|
|
@@ -6078,11 +5344,7 @@ const insertBlockObjectActionImplementation = ({
|
|
|
6078
5344
|
action
|
|
6079
5345
|
}) => {
|
|
6080
5346
|
const selection = action.editor.selection;
|
|
6081
|
-
selection && (slate.Transforms.select(action.editor, {
|
|
6082
|
-
...selection
|
|
6083
|
-
}), action.editor.selection = {
|
|
6084
|
-
...selection
|
|
6085
|
-
});
|
|
5347
|
+
selection && (slate.Transforms.select(action.editor, __spreadValues$5({}, selection)), action.editor.selection = __spreadValues$5({}, selection));
|
|
6086
5348
|
},
|
|
6087
5349
|
"style.toggle": toggleStyleActionImplementation,
|
|
6088
5350
|
"style.add": addStyleActionImplementation,
|
|
@@ -6354,6 +5616,14 @@ function performDefaultAction({
|
|
|
6354
5616
|
});
|
|
6355
5617
|
}
|
|
6356
5618
|
}
|
|
5619
|
+
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) => {
|
|
5620
|
+
for (var prop in b || (b = {}))
|
|
5621
|
+
__hasOwnProp$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5622
|
+
if (__getOwnPropSymbols$4)
|
|
5623
|
+
for (var prop of __getOwnPropSymbols$4(b))
|
|
5624
|
+
__propIsEnum$4.call(b, prop) && __defNormalProp$4(a, prop, b[prop]);
|
|
5625
|
+
return a;
|
|
5626
|
+
}, __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
6357
5627
|
const editorMachine = xstate.setup({
|
|
6358
5628
|
types: {
|
|
6359
5629
|
context: {},
|
|
@@ -6399,11 +5669,11 @@ const editorMachine = xstate.setup({
|
|
|
6399
5669
|
event,
|
|
6400
5670
|
enqueue
|
|
6401
5671
|
}) => {
|
|
5672
|
+
var _a;
|
|
6402
5673
|
xstate.assertEvent(event, ["behavior event"]), debug$l("Behavior event", event);
|
|
6403
|
-
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
6404
|
-
...event.behaviorEvent,
|
|
5674
|
+
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), {
|
|
6405
5675
|
editor: event.editor
|
|
6406
|
-
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5676
|
+
}), eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6407
5677
|
if (eventBehaviors.length === 0) {
|
|
6408
5678
|
if (!defaultAction)
|
|
6409
5679
|
return;
|
|
@@ -6439,7 +5709,10 @@ const editorMachine = xstate.setup({
|
|
|
6439
5709
|
});
|
|
6440
5710
|
if (!shouldRun)
|
|
6441
5711
|
continue;
|
|
6442
|
-
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet(
|
|
5712
|
+
const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
|
|
5713
|
+
context: editorContext,
|
|
5714
|
+
event: event.behaviorEvent
|
|
5715
|
+
}, shouldRun));
|
|
6443
5716
|
for (const actionIntends of actionIntendSets)
|
|
6444
5717
|
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
|
|
6445
5718
|
type: "behavior action intends",
|
|
@@ -6447,7 +5720,7 @@ const editorMachine = xstate.setup({
|
|
|
6447
5720
|
actionIntends
|
|
6448
5721
|
});
|
|
6449
5722
|
if (behaviorOverwritten) {
|
|
6450
|
-
event.nativeEvent
|
|
5723
|
+
(_a = event.nativeEvent) == null || _a.preventDefault();
|
|
6451
5724
|
break;
|
|
6452
5725
|
}
|
|
6453
5726
|
}
|
|
@@ -6466,16 +5739,19 @@ const editorMachine = xstate.setup({
|
|
|
6466
5739
|
id: "editor",
|
|
6467
5740
|
context: ({
|
|
6468
5741
|
input
|
|
6469
|
-
}) =>
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
5742
|
+
}) => {
|
|
5743
|
+
var _a, _b;
|
|
5744
|
+
return {
|
|
5745
|
+
behaviors: (_a = input.behaviors) != null ? _a : behavior_core.coreBehaviors,
|
|
5746
|
+
keyGenerator: input.keyGenerator,
|
|
5747
|
+
pendingEvents: [],
|
|
5748
|
+
schema: input.schema,
|
|
5749
|
+
selection: void 0,
|
|
5750
|
+
readOnly: (_b = input.readOnly) != null ? _b : !1,
|
|
5751
|
+
maxBlocks: input.maxBlocks,
|
|
5752
|
+
value: input.value
|
|
5753
|
+
};
|
|
5754
|
+
},
|
|
6479
5755
|
on: {
|
|
6480
5756
|
"annotation.add": {
|
|
6481
5757
|
actions: xstate.emit(({
|
|
@@ -6578,7 +5854,10 @@ const editorMachine = xstate.setup({
|
|
|
6578
5854
|
actions: [xstate.assign({
|
|
6579
5855
|
selection: ({
|
|
6580
5856
|
event
|
|
6581
|
-
}) =>
|
|
5857
|
+
}) => {
|
|
5858
|
+
var _a;
|
|
5859
|
+
return (_a = event.selection) != null ? _a : void 0;
|
|
5860
|
+
}
|
|
6582
5861
|
}), xstate.emit(({
|
|
6583
5862
|
event
|
|
6584
5863
|
}) => event)]
|
|
@@ -6653,10 +5932,9 @@ const editorMachine = xstate.setup({
|
|
|
6653
5932
|
}) => {
|
|
6654
5933
|
slate.Editor.withoutNormalizing(event.editor, () => {
|
|
6655
5934
|
for (const actionIntend of event.actionIntends) {
|
|
6656
|
-
const action = {
|
|
6657
|
-
...actionIntend,
|
|
5935
|
+
const action = __spreadProps$4(__spreadValues$4({}, actionIntend), {
|
|
6658
5936
|
editor: event.editor
|
|
6659
|
-
};
|
|
5937
|
+
});
|
|
6660
5938
|
performAction({
|
|
6661
5939
|
context,
|
|
6662
5940
|
action
|
|
@@ -6745,28 +6023,10 @@ function createEditor(config) {
|
|
|
6745
6023
|
const editorActor = xstate.createActor(editorMachine, {
|
|
6746
6024
|
input: editorConfigToMachineInput(config)
|
|
6747
6025
|
});
|
|
6748
|
-
editorActor.start();
|
|
6749
|
-
const slateEditor = createSlateEditor({
|
|
6750
|
-
editorActor
|
|
6751
|
-
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
6752
|
-
return {
|
|
6753
|
-
send: (event) => {
|
|
6754
|
-
editorActor.send(event);
|
|
6755
|
-
},
|
|
6756
|
-
on: (event, listener) => editorActor.on(
|
|
6757
|
-
event,
|
|
6758
|
-
// @ts-expect-error
|
|
6759
|
-
listener
|
|
6760
|
-
),
|
|
6761
|
-
_internal: {
|
|
6762
|
-
editable,
|
|
6763
|
-
editorActor,
|
|
6764
|
-
slateEditor
|
|
6765
|
-
}
|
|
6766
|
-
};
|
|
6026
|
+
return editorActor.start(), createEditorFromActor(editorActor);
|
|
6767
6027
|
}
|
|
6768
6028
|
function useCreateEditor(config) {
|
|
6769
|
-
const $ = reactCompilerRuntime.c(
|
|
6029
|
+
const $ = reactCompilerRuntime.c(6);
|
|
6770
6030
|
let t0;
|
|
6771
6031
|
$[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
|
|
6772
6032
|
let t1;
|
|
@@ -6774,38 +6034,40 @@ function useCreateEditor(config) {
|
|
|
6774
6034
|
input: t0
|
|
6775
6035
|
}, $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
6776
6036
|
const editorActor = react.useActorRef(editorMachine, t1);
|
|
6777
|
-
let t2,
|
|
6778
|
-
$[4] !== editorActor ? (
|
|
6779
|
-
editorActor
|
|
6780
|
-
}), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
|
|
6781
|
-
const editable = t3;
|
|
6782
|
-
let t4, t5;
|
|
6783
|
-
$[7] !== editorActor ? (t4 = (event) => {
|
|
6784
|
-
editorActor.send(event);
|
|
6785
|
-
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
|
|
6786
|
-
let t6;
|
|
6787
|
-
$[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
|
|
6788
|
-
editable,
|
|
6789
|
-
editorActor,
|
|
6790
|
-
slateEditor
|
|
6791
|
-
}, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
|
|
6792
|
-
let t7;
|
|
6793
|
-
return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
|
|
6794
|
-
send: t4,
|
|
6795
|
-
on: t5,
|
|
6796
|
-
_internal: t6
|
|
6797
|
-
}, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
|
|
6037
|
+
let t2, t3;
|
|
6038
|
+
return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
|
|
6798
6039
|
}
|
|
6799
6040
|
function editorConfigToMachineInput(config) {
|
|
6041
|
+
var _a;
|
|
6800
6042
|
return {
|
|
6801
6043
|
behaviors: config.behaviors,
|
|
6802
|
-
keyGenerator: config.keyGenerator
|
|
6044
|
+
keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6803
6045
|
maxBlocks: config.maxBlocks,
|
|
6804
6046
|
readOnly: config.readOnly,
|
|
6805
6047
|
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6806
6048
|
value: config.initialValue
|
|
6807
6049
|
};
|
|
6808
6050
|
}
|
|
6051
|
+
function createEditorFromActor(editorActor) {
|
|
6052
|
+
const slateEditor = createSlateEditor({
|
|
6053
|
+
editorActor
|
|
6054
|
+
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
6055
|
+
return {
|
|
6056
|
+
send: (event) => {
|
|
6057
|
+
editorActor.send(event);
|
|
6058
|
+
},
|
|
6059
|
+
on: (event, listener) => editorActor.on(
|
|
6060
|
+
event,
|
|
6061
|
+
// @ts-expect-error
|
|
6062
|
+
listener
|
|
6063
|
+
),
|
|
6064
|
+
_internal: {
|
|
6065
|
+
editable,
|
|
6066
|
+
editorActor,
|
|
6067
|
+
slateEditor
|
|
6068
|
+
}
|
|
6069
|
+
};
|
|
6070
|
+
}
|
|
6809
6071
|
const EditorActorContext = React.createContext({}), PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
|
|
6810
6072
|
const selection = React.useContext(PortableTextEditorSelectionContext);
|
|
6811
6073
|
if (selection === void 0)
|
|
@@ -6829,13 +6091,16 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6829
6091
|
let t2;
|
|
6830
6092
|
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
6831
6093
|
}
|
|
6094
|
+
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) => {
|
|
6095
|
+
for (var prop in b || (b = {}))
|
|
6096
|
+
__hasOwnProp$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6097
|
+
if (__getOwnPropSymbols$3)
|
|
6098
|
+
for (var prop of __getOwnPropSymbols$3(b))
|
|
6099
|
+
__propIsEnum$3.call(b, prop) && __defNormalProp$3(a, prop, b[prop]);
|
|
6100
|
+
return a;
|
|
6101
|
+
}, __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)), __publicField = (obj, key, value) => __defNormalProp$3(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
6832
6102
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6833
6103
|
class PortableTextEditor extends React.Component {
|
|
6834
|
-
static displayName = "PortableTextEditor";
|
|
6835
|
-
/**
|
|
6836
|
-
* An observable of all the editor changes.
|
|
6837
|
-
*/
|
|
6838
|
-
change$ = new rxjs.Subject();
|
|
6839
6104
|
/**
|
|
6840
6105
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6841
6106
|
*/
|
|
@@ -6846,8 +6111,11 @@ class PortableTextEditor extends React.Component {
|
|
|
6846
6111
|
* The editor API (currently implemented with Slate).
|
|
6847
6112
|
*/
|
|
6848
6113
|
constructor(props) {
|
|
6849
|
-
|
|
6850
|
-
|
|
6114
|
+
var _a;
|
|
6115
|
+
super(props), __publicField(this, "change$", new rxjs.Subject()), __publicField(this, "setEditable", (editable) => {
|
|
6116
|
+
this.editor._internal.editable = __spreadValues$3(__spreadValues$3({}, this.editor._internal.editable), editable);
|
|
6117
|
+
}), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6118
|
+
keyGenerator: (_a = props.keyGenerator) != null ? _a : defaultKeyGenerator,
|
|
6851
6119
|
schema: props.schemaType,
|
|
6852
6120
|
initialValue: props.value,
|
|
6853
6121
|
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
@@ -6868,14 +6136,9 @@ class PortableTextEditor extends React.Component {
|
|
|
6868
6136
|
value: this.props.value
|
|
6869
6137
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6870
6138
|
}
|
|
6871
|
-
setEditable = (editable) => {
|
|
6872
|
-
this.editor._internal.editable = {
|
|
6873
|
-
...this.editor._internal.editable,
|
|
6874
|
-
...editable
|
|
6875
|
-
};
|
|
6876
|
-
};
|
|
6877
6139
|
render() {
|
|
6878
|
-
|
|
6140
|
+
var _a;
|
|
6141
|
+
const legacyPatches = this.props.editor ? void 0 : (_a = this.props.incomingPatches$) != null ? _a : this.props.patches$;
|
|
6879
6142
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6880
6143
|
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6881
6144
|
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
@@ -6885,65 +6148,105 @@ class PortableTextEditor extends React.Component {
|
|
|
6885
6148
|
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6886
6149
|
] });
|
|
6887
6150
|
}
|
|
6888
|
-
// Static API methods
|
|
6889
|
-
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
6890
|
-
static isAnnotationActive = (editor, annotationType) => editor && editor.editable ? editor.editable.isAnnotationActive(annotationType) : !1;
|
|
6891
|
-
static addAnnotation = (editor, type, value) => editor.editable?.addAnnotation(type, value);
|
|
6892
|
-
static blur = (editor) => {
|
|
6893
|
-
debug$4("Host blurred"), editor.editable?.blur();
|
|
6894
|
-
};
|
|
6895
|
-
static delete = (editor, selection, options) => editor.editable?.delete(selection, options);
|
|
6896
|
-
static findDOMNode = (editor, element) => editor.editable?.findDOMNode(element);
|
|
6897
|
-
static findByPath = (editor, path) => editor.editable?.findByPath(path) || [];
|
|
6898
|
-
static focus = (editor) => {
|
|
6899
|
-
debug$4("Host requesting focus"), editor.editable?.focus();
|
|
6900
|
-
};
|
|
6901
|
-
static focusBlock = (editor) => editor.editable?.focusBlock();
|
|
6902
|
-
static focusChild = (editor) => editor.editable?.focusChild();
|
|
6903
|
-
static getSelection = (editor) => editor.editable ? editor.editable.getSelection() : null;
|
|
6904
|
-
static getValue = (editor) => editor.editable?.getValue();
|
|
6905
|
-
static hasBlockStyle = (editor, blockStyle) => editor.editable?.hasBlockStyle(blockStyle);
|
|
6906
|
-
static hasListStyle = (editor, listStyle) => editor.editable?.hasListStyle(listStyle);
|
|
6907
|
-
static isCollapsedSelection = (editor) => editor.editable?.isCollapsedSelection();
|
|
6908
|
-
static isExpandedSelection = (editor) => editor.editable?.isExpandedSelection();
|
|
6909
|
-
static isMarkActive = (editor, mark) => editor.editable?.isMarkActive(mark);
|
|
6910
|
-
static insertChild = (editor, type, value) => (debug$4("Host inserting child"), editor.editable?.insertChild(type, value));
|
|
6911
|
-
static insertBlock = (editor, type, value) => editor.editable?.insertBlock(type, value);
|
|
6912
|
-
static insertBreak = (editor) => editor.editable?.insertBreak();
|
|
6913
|
-
static isVoid = (editor, element) => editor.editable?.isVoid(element);
|
|
6914
|
-
static isObjectPath = (_editor, path) => {
|
|
6915
|
-
if (!path || !Array.isArray(path)) return !1;
|
|
6916
|
-
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6917
|
-
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6918
|
-
};
|
|
6919
|
-
static marks = (editor) => editor.editable?.marks();
|
|
6920
|
-
static select = (editor, selection) => {
|
|
6921
|
-
debug$4("Host setting selection", selection), editor.editable?.select(selection);
|
|
6922
|
-
};
|
|
6923
|
-
static removeAnnotation = (editor, type) => editor.editable?.removeAnnotation(type);
|
|
6924
|
-
static toggleBlockStyle = (editor, blockStyle) => (debug$4("Host is toggling block style"), editor.editable?.toggleBlockStyle(blockStyle));
|
|
6925
|
-
static toggleList = (editor, listStyle) => editor.editable?.toggleList(listStyle);
|
|
6926
|
-
static toggleMark = (editor, mark) => {
|
|
6927
|
-
debug$4("Host toggling mark", mark), editor.editable?.toggleMark(mark);
|
|
6928
|
-
};
|
|
6929
|
-
static getFragment = (editor) => (debug$4("Host getting fragment"), editor.editable?.getFragment());
|
|
6930
|
-
static undo = (editor) => {
|
|
6931
|
-
debug$4("Host undoing"), editor.editable?.undo();
|
|
6932
|
-
};
|
|
6933
|
-
static redo = (editor) => {
|
|
6934
|
-
debug$4("Host redoing"), editor.editable?.redo();
|
|
6935
|
-
};
|
|
6936
|
-
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
6937
6151
|
}
|
|
6152
|
+
__publicField(PortableTextEditor, "displayName", "PortableTextEditor"), // Static API methods
|
|
6153
|
+
__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) => {
|
|
6154
|
+
var _a;
|
|
6155
|
+
return (_a = editor.editable) == null ? void 0 : _a.addAnnotation(type, value);
|
|
6156
|
+
}), __publicField(PortableTextEditor, "blur", (editor) => {
|
|
6157
|
+
var _a;
|
|
6158
|
+
debug$4("Host blurred"), (_a = editor.editable) == null || _a.blur();
|
|
6159
|
+
}), __publicField(PortableTextEditor, "delete", (editor, selection, options) => {
|
|
6160
|
+
var _a;
|
|
6161
|
+
return (_a = editor.editable) == null ? void 0 : _a.delete(selection, options);
|
|
6162
|
+
}), __publicField(PortableTextEditor, "findDOMNode", (editor, element) => {
|
|
6163
|
+
var _a;
|
|
6164
|
+
return (_a = editor.editable) == null ? void 0 : _a.findDOMNode(element);
|
|
6165
|
+
}), __publicField(PortableTextEditor, "findByPath", (editor, path) => {
|
|
6166
|
+
var _a;
|
|
6167
|
+
return ((_a = editor.editable) == null ? void 0 : _a.findByPath(path)) || [];
|
|
6168
|
+
}), __publicField(PortableTextEditor, "focus", (editor) => {
|
|
6169
|
+
var _a;
|
|
6170
|
+
debug$4("Host requesting focus"), (_a = editor.editable) == null || _a.focus();
|
|
6171
|
+
}), __publicField(PortableTextEditor, "focusBlock", (editor) => {
|
|
6172
|
+
var _a;
|
|
6173
|
+
return (_a = editor.editable) == null ? void 0 : _a.focusBlock();
|
|
6174
|
+
}), __publicField(PortableTextEditor, "focusChild", (editor) => {
|
|
6175
|
+
var _a;
|
|
6176
|
+
return (_a = editor.editable) == null ? void 0 : _a.focusChild();
|
|
6177
|
+
}), __publicField(PortableTextEditor, "getSelection", (editor) => editor.editable ? editor.editable.getSelection() : null), __publicField(PortableTextEditor, "getValue", (editor) => {
|
|
6178
|
+
var _a;
|
|
6179
|
+
return (_a = editor.editable) == null ? void 0 : _a.getValue();
|
|
6180
|
+
}), __publicField(PortableTextEditor, "hasBlockStyle", (editor, blockStyle) => {
|
|
6181
|
+
var _a;
|
|
6182
|
+
return (_a = editor.editable) == null ? void 0 : _a.hasBlockStyle(blockStyle);
|
|
6183
|
+
}), __publicField(PortableTextEditor, "hasListStyle", (editor, listStyle) => {
|
|
6184
|
+
var _a;
|
|
6185
|
+
return (_a = editor.editable) == null ? void 0 : _a.hasListStyle(listStyle);
|
|
6186
|
+
}), __publicField(PortableTextEditor, "isCollapsedSelection", (editor) => {
|
|
6187
|
+
var _a;
|
|
6188
|
+
return (_a = editor.editable) == null ? void 0 : _a.isCollapsedSelection();
|
|
6189
|
+
}), __publicField(PortableTextEditor, "isExpandedSelection", (editor) => {
|
|
6190
|
+
var _a;
|
|
6191
|
+
return (_a = editor.editable) == null ? void 0 : _a.isExpandedSelection();
|
|
6192
|
+
}), __publicField(PortableTextEditor, "isMarkActive", (editor, mark) => {
|
|
6193
|
+
var _a;
|
|
6194
|
+
return (_a = editor.editable) == null ? void 0 : _a.isMarkActive(mark);
|
|
6195
|
+
}), __publicField(PortableTextEditor, "insertChild", (editor, type, value) => {
|
|
6196
|
+
var _a;
|
|
6197
|
+
return debug$4("Host inserting child"), (_a = editor.editable) == null ? void 0 : _a.insertChild(type, value);
|
|
6198
|
+
}), __publicField(PortableTextEditor, "insertBlock", (editor, type, value) => {
|
|
6199
|
+
var _a;
|
|
6200
|
+
return (_a = editor.editable) == null ? void 0 : _a.insertBlock(type, value);
|
|
6201
|
+
}), __publicField(PortableTextEditor, "insertBreak", (editor) => {
|
|
6202
|
+
var _a;
|
|
6203
|
+
return (_a = editor.editable) == null ? void 0 : _a.insertBreak();
|
|
6204
|
+
}), __publicField(PortableTextEditor, "isVoid", (editor, element) => {
|
|
6205
|
+
var _a;
|
|
6206
|
+
return (_a = editor.editable) == null ? void 0 : _a.isVoid(element);
|
|
6207
|
+
}), __publicField(PortableTextEditor, "isObjectPath", (_editor, path) => {
|
|
6208
|
+
if (!path || !Array.isArray(path)) return !1;
|
|
6209
|
+
const isChildObjectEditPath = path.length > 3 && path[1] === "children";
|
|
6210
|
+
return path.length > 1 && path[1] !== "children" || isChildObjectEditPath;
|
|
6211
|
+
}), __publicField(PortableTextEditor, "marks", (editor) => {
|
|
6212
|
+
var _a;
|
|
6213
|
+
return (_a = editor.editable) == null ? void 0 : _a.marks();
|
|
6214
|
+
}), __publicField(PortableTextEditor, "select", (editor, selection) => {
|
|
6215
|
+
var _a;
|
|
6216
|
+
debug$4("Host setting selection", selection), (_a = editor.editable) == null || _a.select(selection);
|
|
6217
|
+
}), __publicField(PortableTextEditor, "removeAnnotation", (editor, type) => {
|
|
6218
|
+
var _a;
|
|
6219
|
+
return (_a = editor.editable) == null ? void 0 : _a.removeAnnotation(type);
|
|
6220
|
+
}), __publicField(PortableTextEditor, "toggleBlockStyle", (editor, blockStyle) => {
|
|
6221
|
+
var _a;
|
|
6222
|
+
return debug$4("Host is toggling block style"), (_a = editor.editable) == null ? void 0 : _a.toggleBlockStyle(blockStyle);
|
|
6223
|
+
}), __publicField(PortableTextEditor, "toggleList", (editor, listStyle) => {
|
|
6224
|
+
var _a;
|
|
6225
|
+
return (_a = editor.editable) == null ? void 0 : _a.toggleList(listStyle);
|
|
6226
|
+
}), __publicField(PortableTextEditor, "toggleMark", (editor, mark) => {
|
|
6227
|
+
var _a;
|
|
6228
|
+
debug$4("Host toggling mark", mark), (_a = editor.editable) == null || _a.toggleMark(mark);
|
|
6229
|
+
}), __publicField(PortableTextEditor, "getFragment", (editor) => {
|
|
6230
|
+
var _a;
|
|
6231
|
+
return debug$4("Host getting fragment"), (_a = editor.editable) == null ? void 0 : _a.getFragment();
|
|
6232
|
+
}), __publicField(PortableTextEditor, "undo", (editor) => {
|
|
6233
|
+
var _a;
|
|
6234
|
+
debug$4("Host undoing"), (_a = editor.editable) == null || _a.undo();
|
|
6235
|
+
}), __publicField(PortableTextEditor, "redo", (editor) => {
|
|
6236
|
+
var _a;
|
|
6237
|
+
debug$4("Host redoing"), (_a = editor.editable) == null || _a.redo();
|
|
6238
|
+
}), __publicField(PortableTextEditor, "isSelectionsOverlapping", (editor, selectionA, selectionB) => {
|
|
6239
|
+
var _a;
|
|
6240
|
+
return (_a = editor.editable) == null ? void 0 : _a.isSelectionsOverlapping(selectionA, selectionB);
|
|
6241
|
+
});
|
|
6938
6242
|
function RoutePatchesObservableToEditorActor(props) {
|
|
6939
6243
|
const $ = reactCompilerRuntime.c(4);
|
|
6940
6244
|
let t0, t1;
|
|
6941
6245
|
return $[0] !== props.editorActor || $[1] !== props.patches$ ? (t0 = () => {
|
|
6942
6246
|
const subscription = props.patches$.subscribe((payload) => {
|
|
6943
|
-
props.editorActor.send({
|
|
6944
|
-
type: "patches"
|
|
6945
|
-
|
|
6946
|
-
});
|
|
6247
|
+
props.editorActor.send(__spreadValues$3({
|
|
6248
|
+
type: "patches"
|
|
6249
|
+
}, payload));
|
|
6947
6250
|
});
|
|
6948
6251
|
return () => {
|
|
6949
6252
|
subscription.unsubscribe();
|
|
@@ -7008,10 +6311,9 @@ function RouteEventsToChanges(props) {
|
|
|
7008
6311
|
break bb5;
|
|
7009
6312
|
}
|
|
7010
6313
|
case "error": {
|
|
7011
|
-
handleChange({
|
|
7012
|
-
...event,
|
|
6314
|
+
handleChange(__spreadProps$3(__spreadValues$3({}, event), {
|
|
7013
6315
|
level: "warning"
|
|
7014
|
-
});
|
|
6316
|
+
}));
|
|
7015
6317
|
break bb5;
|
|
7016
6318
|
}
|
|
7017
6319
|
case "annotation.add":
|
|
@@ -7038,6 +6340,14 @@ function RouteEventsToChanges(props) {
|
|
|
7038
6340
|
};
|
|
7039
6341
|
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
|
|
7040
6342
|
}
|
|
6343
|
+
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) => {
|
|
6344
|
+
for (var prop in b || (b = {}))
|
|
6345
|
+
__hasOwnProp$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6346
|
+
if (__getOwnPropSymbols$2)
|
|
6347
|
+
for (var prop of __getOwnPropSymbols$2(b))
|
|
6348
|
+
__propIsEnum$2.call(b, prop) && __defNormalProp$2(a, prop, b[prop]);
|
|
6349
|
+
return a;
|
|
6350
|
+
}, __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
7041
6351
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
7042
6352
|
const {
|
|
7043
6353
|
editorActor,
|
|
@@ -7049,10 +6359,13 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
7049
6359
|
renderDecorator,
|
|
7050
6360
|
renderAnnotation
|
|
7051
6361
|
} = props, spanRef = React.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = React.useState(!1), [selected, setSelected] = React.useState(!1), block = children.props.parent, path = React.useMemo(() => block ? [{
|
|
7052
|
-
_key: block
|
|
6362
|
+
_key: block == null ? void 0 : block._key
|
|
7053
6363
|
}, "children", {
|
|
7054
6364
|
_key: leaf._key
|
|
7055
|
-
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) =>
|
|
6365
|
+
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) => {
|
|
6366
|
+
var _a;
|
|
6367
|
+
return !decoratorValues.includes(mark_0) && ((_a = block == null ? void 0 : block.markDefs) == null ? void 0 : _a.find((def) => def._key === mark_0));
|
|
6368
|
+
}).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
7056
6369
|
React.useEffect(() => {
|
|
7057
6370
|
if (!shouldTrackSelectionAndFocus) {
|
|
7058
6371
|
setFocused(!1);
|
|
@@ -7159,7 +6472,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
7159
6472
|
}
|
|
7160
6473
|
return returnedChildren;
|
|
7161
6474
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
7162
|
-
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", {
|
|
6475
|
+
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", __spreadProps$2(__spreadValues$2({}, attributes), { ref: spanRef, children: content }), leaf._key), [leaf, attributes, content]);
|
|
7163
6476
|
};
|
|
7164
6477
|
Leaf.displayName = "Leaf";
|
|
7165
6478
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -7180,7 +6493,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
7180
6493
|
for (const hotkey in activeHotkeys[cat]) {
|
|
7181
6494
|
if (reservedHotkeys.includes(hotkey))
|
|
7182
6495
|
throw new Error(`The hotkey ${hotkey} is reserved!`);
|
|
7183
|
-
if (isHotkey(hotkey, event.nativeEvent)) {
|
|
6496
|
+
if (behavior_core.isHotkey(hotkey, event.nativeEvent)) {
|
|
7184
6497
|
event.preventDefault();
|
|
7185
6498
|
const possibleMark = activeHotkeys[cat];
|
|
7186
6499
|
if (possibleMark) {
|
|
@@ -7200,7 +6513,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
7200
6513
|
for (const hotkey in activeHotkeys[cat]) {
|
|
7201
6514
|
if (reservedHotkeys.includes(hotkey))
|
|
7202
6515
|
throw new Error(`The hotkey ${hotkey} is reserved!`);
|
|
7203
|
-
if (isHotkey(hotkey, event.nativeEvent)) {
|
|
6516
|
+
if (behavior_core.isHotkey(hotkey, event.nativeEvent)) {
|
|
7204
6517
|
const possibleCommand = activeHotkeys[cat];
|
|
7205
6518
|
if (possibleCommand) {
|
|
7206
6519
|
const command = possibleCommand[hotkey];
|
|
@@ -7212,10 +6525,32 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
7212
6525
|
}, editor;
|
|
7213
6526
|
};
|
|
7214
6527
|
}
|
|
6528
|
+
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) => {
|
|
6529
|
+
for (var prop in b || (b = {}))
|
|
6530
|
+
__hasOwnProp$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6531
|
+
if (__getOwnPropSymbols$1)
|
|
6532
|
+
for (var prop of __getOwnPropSymbols$1(b))
|
|
6533
|
+
__propIsEnum$1.call(b, prop) && __defNormalProp$1(a, prop, b[prop]);
|
|
6534
|
+
return a;
|
|
6535
|
+
}, __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b)), __objRest$1 = (source, exclude) => {
|
|
6536
|
+
var target = {};
|
|
6537
|
+
for (var prop in source)
|
|
6538
|
+
__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6539
|
+
if (source != null && __getOwnPropSymbols$1)
|
|
6540
|
+
for (var prop of __getOwnPropSymbols$1(source))
|
|
6541
|
+
exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop) && (target[prop] = source[prop]);
|
|
6542
|
+
return target;
|
|
6543
|
+
};
|
|
7215
6544
|
const debug$1 = debugWithName("plugin:withInsertData");
|
|
7216
6545
|
function createWithInsertData(editorActor, schemaTypes) {
|
|
7217
6546
|
return function(editor) {
|
|
7218
|
-
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) =>
|
|
6547
|
+
const blockTypeName = schemaTypes.block.name, spanTypeName = schemaTypes.span.name, whitespaceOnPasteMode = schemaTypes.block.options.unstable_whitespaceOnPasteMode, toPlainText = (blocks) => blocks.map((block) => {
|
|
6548
|
+
var _a;
|
|
6549
|
+
return editor.isTextBlock(block) ? block.children.map((child) => {
|
|
6550
|
+
var _a2;
|
|
6551
|
+
return child._type === spanTypeName ? child.text : `[${((_a2 = schemaTypes.inlineObjects.find((t) => t.name === child._type)) == null ? void 0 : _a2.title) || "Object"}]`;
|
|
6552
|
+
}).join("") : `[${((_a = schemaTypes.blockObjects.find((t) => t.name === block._type)) == null ? void 0 : _a.title) || "Object"}]`;
|
|
6553
|
+
}).join(`
|
|
7219
6554
|
|
|
7220
6555
|
`);
|
|
7221
6556
|
return editor.setFragmentData = (data, originEvent) => {
|
|
@@ -7253,6 +6588,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7253
6588
|
const fragment = editor.getFragment(), portableText = fromSlateValue(fragment, blockTypeName), asJSON = JSON.stringify(portableText), asPlainText = toPlainText(portableText);
|
|
7254
6589
|
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);
|
|
7255
6590
|
}, editor.insertPortableTextData = (data) => {
|
|
6591
|
+
var _a, _b;
|
|
7256
6592
|
if (!editor.selection)
|
|
7257
6593
|
return !1;
|
|
7258
6594
|
const pText = data.getData("application/x-portable-text"), origin = data.getData("application/x-portable-text-event-origin");
|
|
@@ -7262,8 +6598,8 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7262
6598
|
const slateValue = _regenerateKeys(editor, toSlateValue(parsed, {
|
|
7263
6599
|
schemaTypes
|
|
7264
6600
|
}), editorActor.getSnapshot().context.keyGenerator, spanTypeName, schemaTypes), validation = validateValue(parsed, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7265
|
-
if (!validation.valid && !validation.resolution
|
|
7266
|
-
const errorDescription = `${validation.resolution
|
|
6601
|
+
if (!validation.valid && !((_a = validation.resolution) != null && _a.autoResolve)) {
|
|
6602
|
+
const errorDescription = `${(_b = validation.resolution) == null ? void 0 : _b.description}`;
|
|
7267
6603
|
return editorActor.send({
|
|
7268
6604
|
type: "error",
|
|
7269
6605
|
name: "pasteError",
|
|
@@ -7276,6 +6612,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7276
6612
|
}
|
|
7277
6613
|
return !1;
|
|
7278
6614
|
}, editor.insertTextOrHTMLData = (data) => {
|
|
6615
|
+
var _a;
|
|
7279
6616
|
if (!editor.selection)
|
|
7280
6617
|
return debug$1("No selection, not inserting"), !1;
|
|
7281
6618
|
const html = data.getData("text/html"), text = data.getData("text/plain");
|
|
@@ -7302,7 +6639,7 @@ function createWithInsertData(editorActor, schemaTypes) {
|
|
|
7302
6639
|
const validation = validateValue(portableText, schemaTypes, editorActor.getSnapshot().context.keyGenerator);
|
|
7303
6640
|
if (!validation.valid) {
|
|
7304
6641
|
const errorDescription = `Could not validate the resulting portable text to insert.
|
|
7305
|
-
${validation.resolution
|
|
6642
|
+
${(_a = validation.resolution) == null ? void 0 : _a.description}
|
|
7306
6643
|
Try to insert as plain text (shift-paste) instead.`;
|
|
7307
6644
|
return editorActor.send({
|
|
7308
6645
|
type: "error",
|
|
@@ -7341,46 +6678,37 @@ function escapeHtml(str) {
|
|
|
7341
6678
|
}
|
|
7342
6679
|
function _regenerateKeys(editor, fragment, keyGenerator, spanTypeName, editorTypes) {
|
|
7343
6680
|
return fragment.map((node) => {
|
|
7344
|
-
const newNode = {
|
|
7345
|
-
...node
|
|
7346
|
-
};
|
|
6681
|
+
const newNode = __spreadValues$1({}, node);
|
|
7347
6682
|
if (editor.isTextBlock(newNode)) {
|
|
7348
6683
|
const annotations = editorTypes.annotations.map((t) => t.name);
|
|
7349
6684
|
if (annotations.length === 0) {
|
|
7350
|
-
const
|
|
7351
|
-
markDefs
|
|
7352
|
-
|
|
7353
|
-
}
|
|
7354
|
-
return {
|
|
7355
|
-
...NewNodeNoDefs,
|
|
6685
|
+
const _a = newNode, NewNodeNoDefs = __objRest$1(_a, [
|
|
6686
|
+
"markDefs"
|
|
6687
|
+
]);
|
|
6688
|
+
return __spreadProps$1(__spreadValues$1({}, NewNodeNoDefs), {
|
|
7356
6689
|
_key: keyGenerator()
|
|
7357
|
-
};
|
|
6690
|
+
});
|
|
7358
6691
|
}
|
|
7359
6692
|
if ((newNode.markDefs || []).some((def) => !annotations.includes(def._type))) {
|
|
7360
6693
|
const allowedAnnotations = (newNode.markDefs || []).filter((def) => annotations.includes(def._type));
|
|
7361
|
-
return {
|
|
7362
|
-
...newNode,
|
|
6694
|
+
return __spreadProps$1(__spreadValues$1({}, newNode), {
|
|
7363
6695
|
markDefs: allowedAnnotations,
|
|
7364
6696
|
_key: keyGenerator()
|
|
7365
|
-
};
|
|
6697
|
+
});
|
|
7366
6698
|
}
|
|
7367
6699
|
newNode.markDefs = (newNode.markDefs || []).map((def) => {
|
|
7368
6700
|
const oldKey = def._key, newKey = keyGenerator();
|
|
7369
|
-
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? {
|
|
7370
|
-
...child,
|
|
6701
|
+
return newNode.children = newNode.children.map((child) => child._type === spanTypeName && editor.isTextSpan(child) ? __spreadProps$1(__spreadValues$1({}, child), {
|
|
7371
6702
|
marks: child.marks && child.marks.includes(oldKey) ? [...child.marks].filter((mark) => mark !== oldKey).concat(newKey) : child.marks
|
|
7372
|
-
} : child), {
|
|
7373
|
-
...def,
|
|
6703
|
+
}) : child), __spreadProps$1(__spreadValues$1({}, def), {
|
|
7374
6704
|
_key: newKey
|
|
7375
|
-
};
|
|
6705
|
+
});
|
|
7376
6706
|
});
|
|
7377
6707
|
}
|
|
7378
|
-
const nodeWithNewKeys = {
|
|
7379
|
-
...newNode,
|
|
6708
|
+
const nodeWithNewKeys = __spreadProps$1(__spreadValues$1({}, newNode), {
|
|
7380
6709
|
_key: keyGenerator()
|
|
7381
|
-
};
|
|
7382
|
-
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => ({
|
|
7383
|
-
...child,
|
|
6710
|
+
});
|
|
6711
|
+
return editor.isTextBlock(nodeWithNewKeys) && (nodeWithNewKeys.children = nodeWithNewKeys.children.map((child) => __spreadProps$1(__spreadValues$1({}, child), {
|
|
7384
6712
|
_key: keyGenerator()
|
|
7385
6713
|
}))), nodeWithNewKeys;
|
|
7386
6714
|
});
|
|
@@ -7419,6 +6747,22 @@ function withSyncRangeDecorations(slateEditor, syncRangeDecorations) {
|
|
|
7419
6747
|
slateEditor.apply = originalApply;
|
|
7420
6748
|
};
|
|
7421
6749
|
}
|
|
6750
|
+
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) => {
|
|
6751
|
+
for (var prop in b || (b = {}))
|
|
6752
|
+
__hasOwnProp2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
6753
|
+
if (__getOwnPropSymbols2)
|
|
6754
|
+
for (var prop of __getOwnPropSymbols2(b))
|
|
6755
|
+
__propIsEnum2.call(b, prop) && __defNormalProp2(a, prop, b[prop]);
|
|
6756
|
+
return a;
|
|
6757
|
+
}, __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)), __objRest = (source, exclude) => {
|
|
6758
|
+
var target = {};
|
|
6759
|
+
for (var prop in source)
|
|
6760
|
+
__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0 && (target[prop] = source[prop]);
|
|
6761
|
+
if (source != null && __getOwnPropSymbols2)
|
|
6762
|
+
for (var prop of __getOwnPropSymbols2(source))
|
|
6763
|
+
exclude.indexOf(prop) < 0 && __propIsEnum2.call(source, prop) && (target[prop] = source[prop]);
|
|
6764
|
+
return target;
|
|
6765
|
+
};
|
|
7422
6766
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
7423
6767
|
position: "absolute",
|
|
7424
6768
|
userSelect: "none",
|
|
@@ -7426,7 +6770,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7426
6770
|
left: 0,
|
|
7427
6771
|
right: 0
|
|
7428
6772
|
}, PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
7429
|
-
const {
|
|
6773
|
+
const _a = props, {
|
|
7430
6774
|
hotkeys,
|
|
7431
6775
|
onBlur,
|
|
7432
6776
|
onFocus,
|
|
@@ -7444,9 +6788,27 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7444
6788
|
renderStyle,
|
|
7445
6789
|
selection: propsSelection,
|
|
7446
6790
|
scrollSelectionIntoView,
|
|
7447
|
-
spellCheck
|
|
7448
|
-
|
|
7449
|
-
|
|
6791
|
+
spellCheck
|
|
6792
|
+
} = _a, restProps = __objRest(_a, [
|
|
6793
|
+
"hotkeys",
|
|
6794
|
+
"onBlur",
|
|
6795
|
+
"onFocus",
|
|
6796
|
+
"onBeforeInput",
|
|
6797
|
+
"onPaste",
|
|
6798
|
+
"onCopy",
|
|
6799
|
+
"onClick",
|
|
6800
|
+
"rangeDecorations",
|
|
6801
|
+
"renderAnnotation",
|
|
6802
|
+
"renderBlock",
|
|
6803
|
+
"renderChild",
|
|
6804
|
+
"renderDecorator",
|
|
6805
|
+
"renderListItem",
|
|
6806
|
+
"renderPlaceholder",
|
|
6807
|
+
"renderStyle",
|
|
6808
|
+
"selection",
|
|
6809
|
+
"scrollSelectionIntoView",
|
|
6810
|
+
"spellCheck"
|
|
6811
|
+
]), portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
7450
6812
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
7451
6813
|
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.context.readOnly), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
7452
6814
|
React.useMemo(() => {
|
|
@@ -7456,9 +6818,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7456
6818
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
7457
6819
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
7458
6820
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
7459
|
-
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, {
|
|
6821
|
+
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, __spreadProps(__spreadValues2({}, eProps), { readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck })), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
7460
6822
|
if (lProps.leaf._type === "span") {
|
|
7461
|
-
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, {
|
|
6823
|
+
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, __spreadProps(__spreadValues2({}, lProps), { editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly }));
|
|
7462
6824
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
7463
6825
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
7464
6826
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -7505,10 +6867,9 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7505
6867
|
origin: "local"
|
|
7506
6868
|
});
|
|
7507
6869
|
}
|
|
7508
|
-
newRange !== null && newSlateRanges.push({
|
|
7509
|
-
...newRange || slateRange_0,
|
|
6870
|
+
newRange !== null && newSlateRanges.push(__spreadProps(__spreadValues2({}, newRange || slateRange_0), {
|
|
7510
6871
|
rangeDecoration: rangeDecorationItem
|
|
7511
|
-
});
|
|
6872
|
+
}));
|
|
7512
6873
|
}), newSlateRanges.length > 0) {
|
|
7513
6874
|
setRangeDecorationsState(newSlateRanges);
|
|
7514
6875
|
return;
|
|
@@ -7550,7 +6911,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7550
6911
|
nativeEvent: event
|
|
7551
6912
|
});
|
|
7552
6913
|
}, [onCopy, editorActor, slateEditor]), handlePaste = React.useCallback((event_0) => {
|
|
7553
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor),
|
|
6914
|
+
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({
|
|
7554
6915
|
event: event_0,
|
|
7555
6916
|
value: value_0,
|
|
7556
6917
|
path,
|
|
@@ -7615,8 +6976,8 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7615
6976
|
const existingDOMRange = domSelection.getRangeAt(0);
|
|
7616
6977
|
try {
|
|
7617
6978
|
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
7618
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection
|
|
7619
|
-
} catch {
|
|
6979
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection == null || domSelection.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
6980
|
+
} catch (e) {
|
|
7620
6981
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
7621
6982
|
}
|
|
7622
6983
|
}, [ref, slateEditor]);
|
|
@@ -7704,8 +7065,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7704
7065
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
7705
7066
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
7706
7067
|
slateReact.Editable,
|
|
7707
|
-
{
|
|
7708
|
-
...restProps,
|
|
7068
|
+
__spreadProps(__spreadValues2({}, restProps), {
|
|
7709
7069
|
autoFocus: !1,
|
|
7710
7070
|
className: restProps.className || "pt-editable",
|
|
7711
7071
|
decorate,
|
|
@@ -7722,7 +7082,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
7722
7082
|
renderElement,
|
|
7723
7083
|
renderLeaf,
|
|
7724
7084
|
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
7725
|
-
}
|
|
7085
|
+
})
|
|
7726
7086
|
) : null;
|
|
7727
7087
|
});
|
|
7728
7088
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
@@ -7798,12 +7158,6 @@ exports.EditorEventListener = EditorEventListener;
|
|
|
7798
7158
|
exports.EditorProvider = EditorProvider;
|
|
7799
7159
|
exports.PortableTextEditable = PortableTextEditable;
|
|
7800
7160
|
exports.PortableTextEditor = PortableTextEditor;
|
|
7801
|
-
exports.coreBehavior = coreBehavior;
|
|
7802
|
-
exports.coreBehaviors = coreBehaviors;
|
|
7803
|
-
exports.createCodeEditorBehaviors = createCodeEditorBehaviors;
|
|
7804
|
-
exports.createLinkBehaviors = createLinkBehaviors;
|
|
7805
|
-
exports.createMarkdownBehaviors = createMarkdownBehaviors;
|
|
7806
|
-
exports.defineBehavior = defineBehavior;
|
|
7807
7161
|
exports.defineSchema = defineSchema;
|
|
7808
7162
|
exports.editorMachine = editorMachine;
|
|
7809
7163
|
exports.keyGenerator = defaultKeyGenerator;
|