@portabletext/editor 1.15.1 → 1.15.3

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.
Files changed (69) hide show
  1. package/lib/_chunks-cjs/behavior.core.cjs +496 -0
  2. package/lib/_chunks-cjs/behavior.core.cjs.map +1 -0
  3. package/lib/_chunks-cjs/selector.get-text-before.cjs +0 -231
  4. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selectors.cjs +234 -0
  6. package/lib/_chunks-cjs/selectors.cjs.map +1 -0
  7. package/lib/_chunks-es/behavior.core.js +498 -0
  8. package/lib/_chunks-es/behavior.core.js.map +1 -0
  9. package/lib/_chunks-es/selector.get-text-before.js +2 -233
  10. package/lib/_chunks-es/selector.get-text-before.js.map +1 -1
  11. package/lib/_chunks-es/selectors.js +235 -0
  12. package/lib/_chunks-es/selectors.js.map +1 -0
  13. package/lib/behaviors/index.cjs +460 -0
  14. package/lib/behaviors/index.cjs.map +1 -0
  15. package/lib/behaviors/index.d.cts +869 -0
  16. package/lib/behaviors/index.d.ts +869 -0
  17. package/lib/behaviors/index.js +464 -0
  18. package/lib/behaviors/index.js.map +1 -0
  19. package/lib/index.cjs +51 -1035
  20. package/lib/index.cjs.map +1 -1
  21. package/lib/index.d.cts +146 -669
  22. package/lib/index.d.ts +146 -669
  23. package/lib/index.js +44 -1027
  24. package/lib/index.js.map +1 -1
  25. package/lib/selectors/index.cjs +16 -16
  26. package/lib/selectors/index.cjs.map +1 -1
  27. package/lib/selectors/index.d.cts +8 -12
  28. package/lib/selectors/index.d.ts +8 -12
  29. package/lib/selectors/index.js +3 -2
  30. package/lib/selectors/index.js.map +1 -1
  31. package/package.json +11 -5
  32. package/src/{editor/behavior → behavior-actions}/behavior.action-utils.insert-block.ts +4 -6
  33. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-block-object.ts +1 -1
  34. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-break.ts +1 -1
  35. package/src/{editor/behavior → behavior-actions}/behavior.action.insert-inline-object.ts +1 -1
  36. package/src/{editor/behavior → behavior-actions}/behavior.action.list-item.ts +2 -2
  37. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.set.ts +1 -1
  38. package/src/{editor/behavior → behavior-actions}/behavior.action.text-block.unset.ts +1 -1
  39. package/src/{editor/behavior → behavior-actions}/behavior.actions.ts +20 -20
  40. package/src/{editor/behavior → behavior-actions}/behavior.guards.ts +2 -6
  41. package/src/{editor/behavior → behaviors}/behavior.code-editor.ts +4 -4
  42. package/src/{editor/behavior → behaviors}/behavior.core.block-objects.ts +6 -6
  43. package/src/{editor/behavior → behaviors}/behavior.core.decorators.ts +6 -16
  44. package/src/{editor/behavior → behaviors}/behavior.core.lists.ts +17 -17
  45. package/src/{editor/behavior → behaviors}/behavior.links.ts +5 -5
  46. package/src/{editor/behavior → behaviors}/behavior.markdown.ts +25 -43
  47. package/src/{editor/behavior → behaviors}/behavior.types.ts +39 -46
  48. package/src/behaviors/index.ts +29 -0
  49. package/src/editor/PortableTextEditor.tsx +2 -2
  50. package/src/{utils/getPortableTextMemberSchemaTypes.ts → editor/create-editor-schema.ts} +3 -3
  51. package/src/editor/create-editor.ts +28 -48
  52. package/src/editor/define-schema.ts +8 -3
  53. package/src/editor/editor-machine.ts +21 -36
  54. package/src/editor/editor-selector.ts +1 -13
  55. package/src/editor/editor-snapshot.ts +4 -6
  56. package/src/editor/plugins/createWithEditableAPI.ts +3 -3
  57. package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
  58. package/src/editor/utils/utils.block-offset.ts +1 -1
  59. package/src/index.ts +14 -31
  60. package/src/selectors/index.ts +2 -4
  61. package/src/selectors/selector.get-active-list-item.ts +1 -1
  62. package/src/selectors/selectors.ts +1 -1
  63. package/src/type-utils.ts +17 -0
  64. package/src/utils/__tests__/operationToPatches.test.ts +3 -3
  65. package/src/utils/__tests__/patchToOperations.test.ts +3 -3
  66. package/src/utils/__tests__/values.test.ts +2 -2
  67. /package/src/{editor/behavior → behavior-actions}/behavior.action.insert-span.ts +0 -0
  68. /package/src/{editor/behavior → behavior-actions}/behavior.action.style.ts +0 -0
  69. /package/src/{editor/behavior → behaviors}/behavior.core.ts +0 -0
package/lib/index.cjs CHANGED
@@ -11,962 +11,12 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
11
11
  return a;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: !0 });
14
- var selector_getTextBefore = require("./_chunks-cjs/selector.get-text-before.cjs"), types = require("@sanity/types"), schema = require("@sanity/schema"), 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"), getRandomValues = require("get-random-values-esm"), blockTools = require("@sanity/block-tools");
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");
15
15
  function _interopDefaultCompat(e) {
16
16
  return e && typeof e == "object" && "default" in e ? e : { default: e };
17
17
  }
18
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);
19
- const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
20
- alt: "altKey",
21
- control: "ctrlKey",
22
- meta: "metaKey",
23
- shift: "shiftKey"
24
- }, aliases = {
25
- add: "+",
26
- break: "pause",
27
- cmd: "meta",
28
- command: "meta",
29
- ctl: "control",
30
- ctrl: "control",
31
- del: "delete",
32
- down: "arrowdown",
33
- esc: "escape",
34
- ins: "insert",
35
- left: "arrowleft",
36
- mod: IS_MAC ? "meta" : "control",
37
- opt: "alt",
38
- option: "alt",
39
- return: "enter",
40
- right: "arrowright",
41
- space: " ",
42
- spacebar: " ",
43
- up: "arrowup",
44
- win: "meta",
45
- windows: "meta"
46
- }, keyCodes = {
47
- backspace: 8,
48
- tab: 9,
49
- enter: 13,
50
- shift: 16,
51
- control: 17,
52
- alt: 18,
53
- pause: 19,
54
- capslock: 20,
55
- escape: 27,
56
- " ": 32,
57
- pageup: 33,
58
- pagedown: 34,
59
- end: 35,
60
- home: 36,
61
- arrowleft: 37,
62
- arrowup: 38,
63
- arrowright: 39,
64
- arrowdown: 40,
65
- insert: 45,
66
- delete: 46,
67
- meta: 91,
68
- numlock: 144,
69
- scrolllock: 145,
70
- ";": 186,
71
- "=": 187,
72
- ",": 188,
73
- "-": 189,
74
- ".": 190,
75
- "/": 191,
76
- "`": 192,
77
- "[": 219,
78
- "\\": 220,
79
- "]": 221,
80
- "'": 222,
81
- f1: 112,
82
- f2: 113,
83
- f3: 114,
84
- f4: 115,
85
- f5: 116,
86
- f6: 117,
87
- f7: 118,
88
- f8: 119,
89
- f9: 120,
90
- f10: 121,
91
- f11: 122,
92
- f12: 123,
93
- f13: 124,
94
- f14: 125,
95
- f15: 126,
96
- f16: 127,
97
- f17: 128,
98
- f18: 129,
99
- f19: 130,
100
- f20: 131
101
- };
102
- function isHotkey(hotkey, event) {
103
- return compareHotkey(parseHotkey(hotkey), event);
104
- }
105
- function parseHotkey(hotkey) {
106
- const parsedHotkey = {
107
- altKey: !1,
108
- ctrlKey: !1,
109
- metaKey: !1,
110
- shiftKey: !1
111
- }, hotkeySegments = hotkey.replace("++", "+add").split("+");
112
- for (const rawHotkeySegment of hotkeySegments) {
113
- 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];
114
- if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
115
- throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
116
- (hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
117
- }
118
- return parsedHotkey;
119
- }
120
- function compareHotkey(parsedHotkey, event) {
121
- 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;
122
- }
123
- function toKeyCode(name) {
124
- var _a;
125
- const keyName = toKeyName(name);
126
- return (_a = keyCodes[keyName]) != null ? _a : keyName.toUpperCase().charCodeAt(0);
127
- }
128
- function toKeyName(name) {
129
- var _a;
130
- const keyName = name.toLowerCase();
131
- return (_a = aliases[keyName]) != null ? _a : keyName;
132
- }
133
- function defineBehavior(behavior) {
134
- return behavior;
135
- }
136
- function createCodeEditorBehaviors(config) {
137
- return [{
138
- on: "key.down",
139
- guard: ({
140
- context,
141
- event
142
- }) => {
143
- var _a;
144
- const isMoveUpShortcut = isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = selector_getTextBefore.getFirstBlock({
145
- context
146
- }), selectedBlocks = selector_getTextBefore.getSelectedBlocks({
147
- context
148
- }), blocksAbove = (firstBlock == null ? void 0 : firstBlock.node._key) !== ((_a = selectedBlocks[0]) == null ? void 0 : _a.node._key);
149
- return !isMoveUpShortcut || !blocksAbove ? !1 : {
150
- paths: selectedBlocks.map((block) => block.path)
151
- };
152
- },
153
- actions: [({
154
- paths
155
- }) => paths.map((at) => ({
156
- type: "move.block up",
157
- at
158
- }))]
159
- }, {
160
- on: "key.down",
161
- guard: ({
162
- context,
163
- event
164
- }) => {
165
- var _a;
166
- const isMoveDownShortcut = isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = selector_getTextBefore.getLastBlock({
167
- context
168
- }), selectedBlocks = selector_getTextBefore.getSelectedBlocks({
169
- context
170
- }), blocksBelow = (lastBlock == null ? void 0 : lastBlock.node._key) !== ((_a = selectedBlocks[selectedBlocks.length - 1]) == null ? void 0 : _a.node._key);
171
- return !isMoveDownShortcut || !blocksBelow ? !1 : {
172
- paths: selectedBlocks.map((block) => block.path).reverse()
173
- };
174
- },
175
- actions: [({
176
- paths
177
- }) => paths.map((at) => ({
178
- type: "move.block down",
179
- at
180
- }))]
181
- }];
182
- }
183
- function isEmptyTextBlock(block) {
184
- if (!types.isPortableTextTextBlock(block))
185
- return !1;
186
- const onlyText = block.children.every(types.isPortableTextSpan), blockText = getTextBlockText(block);
187
- return onlyText && blockText === "";
188
- }
189
- function getTextBlockText(block) {
190
- return block.children.map((child) => {
191
- var _a;
192
- return (_a = child.text) != null ? _a : "";
193
- }).join("");
194
- }
195
- const arrowDownOnLonelyBlockObject = {
196
- on: "key.down",
197
- guard: ({
198
- context,
199
- event
200
- }) => {
201
- const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject = selector_getTextBefore.getFocusBlockObject({
202
- context
203
- }), nextBlock = selector_getTextBefore.getNextBlock({
204
- context
205
- });
206
- return isArrowDown && focusBlockObject && !nextBlock;
207
- },
208
- actions: [() => [{
209
- type: "insert.text block",
210
- placement: "after"
211
- }]]
212
- }, arrowUpOnLonelyBlockObject = {
213
- on: "key.down",
214
- guard: ({
215
- context,
216
- event
217
- }) => {
218
- const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject = selector_getTextBefore.getFocusBlockObject({
219
- context
220
- }), previousBlock = selector_getTextBefore.getPreviousBlock({
221
- context
222
- });
223
- return isArrowUp && focusBlockObject && !previousBlock;
224
- },
225
- actions: [() => [{
226
- type: "insert.text block",
227
- placement: "before"
228
- }, {
229
- type: "select previous block"
230
- }]]
231
- }, breakingBlockObject = {
232
- on: "insert.break",
233
- guard: ({
234
- context
235
- }) => {
236
- const focusBlockObject = selector_getTextBefore.getFocusBlockObject({
237
- context
238
- });
239
- return selector_getTextBefore.selectionIsCollapsed({
240
- context
241
- }) && focusBlockObject !== void 0;
242
- },
243
- actions: [() => [{
244
- type: "insert.text block",
245
- placement: "after"
246
- }]]
247
- }, deletingEmptyTextBlockAfterBlockObject = {
248
- on: "delete.backward",
249
- guard: ({
250
- context
251
- }) => {
252
- const focusTextBlock = selector_getTextBefore.getFocusTextBlock({
253
- context
254
- }), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
255
- context
256
- }), previousBlock = selector_getTextBefore.getPreviousBlock({
257
- context
258
- });
259
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
260
- focusTextBlock,
261
- previousBlock
262
- } : !1;
263
- },
264
- actions: [({
265
- focusTextBlock,
266
- previousBlock
267
- }) => [{
268
- type: "delete.block",
269
- blockPath: focusTextBlock.path
270
- }, {
271
- type: "select",
272
- selection: {
273
- anchor: {
274
- path: previousBlock.path,
275
- offset: 0
276
- },
277
- focus: {
278
- path: previousBlock.path,
279
- offset: 0
280
- }
281
- }
282
- }]]
283
- }, deletingEmptyTextBlockBeforeBlockObject = {
284
- on: "delete.forward",
285
- guard: ({
286
- context
287
- }) => {
288
- const focusTextBlock = selector_getTextBefore.getFocusTextBlock({
289
- context
290
- }), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
291
- context
292
- }), nextBlock = selector_getTextBefore.getNextBlock({
293
- context
294
- });
295
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
296
- focusTextBlock,
297
- nextBlock
298
- } : !1;
299
- },
300
- actions: [({
301
- focusTextBlock,
302
- nextBlock
303
- }) => [{
304
- type: "delete.block",
305
- blockPath: focusTextBlock.path
306
- }, {
307
- type: "select",
308
- selection: {
309
- anchor: {
310
- path: nextBlock.path,
311
- offset: 0
312
- },
313
- focus: {
314
- path: nextBlock.path,
315
- offset: 0
316
- }
317
- }
318
- }]]
319
- }, coreBlockObjectBehaviors = {
320
- arrowDownOnLonelyBlockObject,
321
- arrowUpOnLonelyBlockObject,
322
- breakingBlockObject,
323
- deletingEmptyTextBlockAfterBlockObject,
324
- deletingEmptyTextBlockBeforeBlockObject
325
- }, decoratorAdd = {
326
- on: "decorator.add",
327
- guard: ({
328
- event
329
- }) => ({
330
- decorator: event.decorator
331
- }),
332
- actions: [({
333
- decorator
334
- }) => [{
335
- type: "decorator.add",
336
- decorator
337
- }, {
338
- type: "reselect"
339
- }]]
340
- }, decoratorRemove = {
341
- on: "decorator.remove",
342
- guard: ({
343
- event
344
- }) => ({
345
- decorator: event.decorator
346
- }),
347
- actions: [({
348
- decorator
349
- }) => [{
350
- type: "decorator.remove",
351
- decorator
352
- }, {
353
- type: "reselect"
354
- }]]
355
- }, decoratorToggle = {
356
- on: "decorator.toggle",
357
- guard: ({
358
- event
359
- }) => ({
360
- decorator: event.decorator
361
- }),
362
- actions: [({
363
- decorator
364
- }) => [{
365
- type: "decorator.toggle",
366
- decorator
367
- }, {
368
- type: "reselect"
369
- }]]
370
- }, coreDecoratorBehaviors = {
371
- decoratorAdd,
372
- decoratorRemove,
373
- decoratorToggle
374
- }, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
375
- on: "delete.backward",
376
- guard: ({
377
- context
378
- }) => {
379
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
380
- context
381
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
382
- context
383
- }), focusSpan = selector_getTextBefore.getFocusSpan({
384
- context
385
- });
386
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
387
- focusTextBlock
388
- } : !1;
389
- },
390
- actions: [({
391
- focusTextBlock
392
- }) => [{
393
- type: "text block.unset",
394
- props: ["listItem", "level"],
395
- at: focusTextBlock.path
396
- }]]
397
- }, unindentListOnBackspace = {
398
- on: "delete.backward",
399
- guard: ({
400
- context
401
- }) => {
402
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
403
- context
404
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
405
- context
406
- }), focusSpan = selector_getTextBefore.getFocusSpan({
407
- context
408
- });
409
- 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 ? {
410
- focusTextBlock,
411
- level: focusTextBlock.node.level - 1
412
- } : !1;
413
- },
414
- actions: [({
415
- focusTextBlock,
416
- level
417
- }) => [{
418
- type: "text block.set",
419
- level,
420
- at: focusTextBlock.path
421
- }]]
422
- }, clearListOnEnter = {
423
- on: "insert.break",
424
- guard: ({
425
- context
426
- }) => {
427
- const focusListBlock = selector_getTextBefore.getFocusListBlock({
428
- context
429
- }), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
430
- context
431
- });
432
- return !focusListBlock || !selectionCollapsed || !isEmptyTextBlock(focusListBlock.node) ? !1 : {
433
- focusListBlock
434
- };
435
- },
436
- actions: [({
437
- focusListBlock
438
- }) => [{
439
- type: "text block.unset",
440
- props: ["listItem", "level"],
441
- at: focusListBlock.path
442
- }]]
443
- }, indentListOnTab = {
444
- on: "key.down",
445
- guard: ({
446
- context,
447
- event
448
- }) => {
449
- if (!isHotkey("Tab", event.keyboardEvent))
450
- return !1;
451
- const selectedBlocks = selector_getTextBefore.getSelectedBlocks({
452
- context
453
- }), guards = selector_getTextBefore.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
454
- node: block.node,
455
- path: block.path
456
- }] : []);
457
- return selectedListBlocks.length === selectedBlocks.length ? {
458
- selectedListBlocks
459
- } : !1;
460
- },
461
- actions: [({
462
- selectedListBlocks
463
- }) => selectedListBlocks.map((selectedListBlock) => ({
464
- type: "text block.set",
465
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
466
- at: selectedListBlock.path
467
- }))]
468
- }, unindentListOnShiftTab = {
469
- on: "key.down",
470
- guard: ({
471
- context,
472
- event
473
- }) => {
474
- if (!isHotkey("Shift+Tab", event.keyboardEvent))
475
- return !1;
476
- const selectedBlocks = selector_getTextBefore.getSelectedBlocks({
477
- context
478
- }), guards = selector_getTextBefore.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
479
- node: block.node,
480
- path: block.path
481
- }] : []);
482
- return selectedListBlocks.length === selectedBlocks.length ? {
483
- selectedListBlocks
484
- } : !1;
485
- },
486
- actions: [({
487
- selectedListBlocks
488
- }) => selectedListBlocks.map((selectedListBlock) => ({
489
- type: "text block.set",
490
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
491
- at: selectedListBlock.path
492
- }))]
493
- }, coreListBehaviors = {
494
- clearListOnBackspace,
495
- unindentListOnBackspace,
496
- clearListOnEnter,
497
- indentListOnTab,
498
- unindentListOnShiftTab
499
- }, softReturn = {
500
- on: "insert.soft break",
501
- actions: [() => [{
502
- type: "insert.text",
503
- text: `
504
- `
505
- }]]
506
- }, 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 = {
507
- softReturn,
508
- decorators: coreDecoratorBehaviors,
509
- blockObjects: coreBlockObjectBehaviors,
510
- lists: coreListBehaviors
511
- };
512
- function createLinkBehaviors(config) {
513
- const pasteLinkOnSelection = {
514
- on: "paste",
515
- guard: ({
516
- context,
517
- event
518
- }) => {
519
- var _a;
520
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
521
- context
522
- }), text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
523
- url,
524
- schema: context.schema
525
- }) : void 0;
526
- return annotation && !selectionCollapsed ? {
527
- annotation
528
- } : !1;
529
- },
530
- actions: [({
531
- annotation
532
- }) => [{
533
- type: "annotation.add",
534
- annotation
535
- }]]
536
- }, pasteLinkAtCaret = {
537
- on: "paste",
538
- guard: ({
539
- context,
540
- event
541
- }) => {
542
- var _a;
543
- const focusSpan = selector_getTextBefore.getFocusSpan({
544
- context
545
- }), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
546
- context
547
- });
548
- if (!focusSpan || !selectionCollapsed)
549
- return !1;
550
- const text = event.data.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? (_a = config.linkAnnotation) == null ? void 0 : _a.call(config, {
551
- url,
552
- schema: context.schema
553
- }) : void 0;
554
- return url && annotation && selectionCollapsed ? {
555
- focusSpan,
556
- annotation,
557
- url
558
- } : !1;
559
- },
560
- actions: [({
561
- annotation,
562
- url
563
- }) => [{
564
- type: "insert.span",
565
- text: url,
566
- annotations: [annotation]
567
- }]]
568
- };
569
- return [pasteLinkOnSelection, pasteLinkAtCaret];
570
- }
571
- function looksLikeUrl(text) {
572
- let looksLikeUrl2 = !1;
573
- try {
574
- new URL(text), looksLikeUrl2 = !0;
575
- } catch (e) {
576
- }
577
- return looksLikeUrl2;
578
- }
579
- function blockOffsetToSpanSelectionPoint({
580
- value,
581
- blockOffset
582
- }) {
583
- let offsetLeft = blockOffset.offset, selectionPoint;
584
- for (const block of value)
585
- if (block._key === blockOffset.path[0]._key && types.isPortableTextTextBlock(block)) {
586
- for (const child of block.children)
587
- if (types.isPortableTextSpan(child)) {
588
- if (offsetLeft === 0) {
589
- selectionPoint = {
590
- path: [...blockOffset.path, "children", {
591
- _key: child._key
592
- }],
593
- offset: 0
594
- };
595
- break;
596
- }
597
- if (offsetLeft <= child.text.length) {
598
- selectionPoint = {
599
- path: [...blockOffset.path, "children", {
600
- _key: child._key
601
- }],
602
- offset: offsetLeft
603
- };
604
- break;
605
- }
606
- offsetLeft -= child.text.length;
607
- }
608
- }
609
- return selectionPoint;
610
- }
611
- function spanSelectionPointToBlockOffset({
612
- value,
613
- selectionPoint
614
- }) {
615
- let offset = 0;
616
- for (const block of value)
617
- if (block._key === selectionPoint.path[0]._key && types.isPortableTextTextBlock(block)) {
618
- for (const child of block.children)
619
- if (types.isPortableTextSpan(child)) {
620
- if (child._key === selectionPoint.path[2]._key)
621
- return {
622
- path: [{
623
- _key: block._key
624
- }],
625
- offset: offset + selectionPoint.offset
626
- };
627
- offset += child.text.length;
628
- }
629
- }
630
- }
631
- var __defProp$q = Object.defineProperty, __getOwnPropSymbols$q = Object.getOwnPropertySymbols, __hasOwnProp$q = Object.prototype.hasOwnProperty, __propIsEnum$q = Object.prototype.propertyIsEnumerable, __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __spreadValues$q = (a, b) => {
632
- for (var prop in b || (b = {}))
633
- __hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
634
- if (__getOwnPropSymbols$q)
635
- for (var prop of __getOwnPropSymbols$q(b))
636
- __propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
637
- return a;
638
- };
639
- function createMarkdownBehaviors(config) {
640
- const automaticBlockquoteOnSpace = {
641
- on: "insert.text",
642
- guard: ({
643
- context,
644
- event
645
- }) => {
646
- var _a;
647
- if (event.text !== " ")
648
- return !1;
649
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
650
- context
651
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
652
- context
653
- }), focusSpan = selector_getTextBefore.getFocusSpan({
654
- context
655
- });
656
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
657
- return !1;
658
- const blockOffset = spanSelectionPointToBlockOffset({
659
- value: context.value,
660
- selectionPoint: {
661
- path: [{
662
- _key: focusTextBlock.node._key
663
- }, "children", {
664
- _key: focusSpan.node._key
665
- }],
666
- offset: context.selection.focus.offset
667
- }
668
- });
669
- if (!blockOffset)
670
- return !1;
671
- const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = (_a = config.blockquoteStyle) == null ? void 0 : _a.call(config, context);
672
- return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
673
- focusTextBlock,
674
- style: blockquoteStyle
675
- } : !1;
676
- },
677
- actions: [() => [{
678
- type: "insert.text",
679
- text: " "
680
- }], ({
681
- focusTextBlock,
682
- style
683
- }) => [{
684
- type: "text block.unset",
685
- props: ["listItem", "level"],
686
- at: focusTextBlock.path
687
- }, {
688
- type: "text block.set",
689
- style,
690
- at: focusTextBlock.path
691
- }, {
692
- type: "delete.text",
693
- anchor: {
694
- path: focusTextBlock.path,
695
- offset: 0
696
- },
697
- focus: {
698
- path: focusTextBlock.path,
699
- offset: 2
700
- }
701
- }]]
702
- }, automaticHr = {
703
- on: "insert.text",
704
- guard: ({
705
- context,
706
- event
707
- }) => {
708
- var _a;
709
- const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
710
- if (hrCharacter === void 0)
711
- return !1;
712
- const hrObject = (_a = config.horizontalRuleObject) == null ? void 0 : _a.call(config, context), focusBlock = selector_getTextBefore.getFocusTextBlock({
713
- context
714
- }), selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
715
- context
716
- });
717
- if (!hrObject || !focusBlock || !selectionCollapsed)
718
- return !1;
719
- const textBefore = selector_getTextBefore.getBlockTextBefore({
720
- context
721
- }), hrBlockOffsets = {
722
- anchor: {
723
- path: focusBlock.path,
724
- offset: 0
725
- },
726
- focus: {
727
- path: focusBlock.path,
728
- offset: 3
729
- }
730
- };
731
- return textBefore === `${hrCharacter}${hrCharacter}` ? {
732
- hrObject,
733
- focusBlock,
734
- hrCharacter,
735
- hrBlockOffsets
736
- } : !1;
737
- },
738
- actions: [({
739
- hrCharacter
740
- }) => [{
741
- type: "insert.text",
742
- text: hrCharacter
743
- }], ({
744
- hrObject,
745
- hrBlockOffsets
746
- }) => [{
747
- type: "insert.block object",
748
- placement: "before",
749
- blockObject: hrObject
750
- }, __spreadValues$q({
751
- type: "delete.text"
752
- }, hrBlockOffsets)]]
753
- }, automaticHrOnPaste = {
754
- on: "paste",
755
- guard: ({
756
- context,
757
- event
758
- }) => {
759
- var _a, _b;
760
- const text = event.data.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/gm, hrCharacters = (_a = text.match(hrRegExp)) == null ? void 0 : _a[0], hrObject = (_b = config.horizontalRuleObject) == null ? void 0 : _b.call(config, context), focusBlock = selector_getTextBefore.getFocusBlock({
761
- context
762
- });
763
- return !hrCharacters || !hrObject || !focusBlock ? !1 : {
764
- hrCharacters,
765
- hrObject,
766
- focusBlock
767
- };
768
- },
769
- actions: [({
770
- hrCharacters
771
- }) => [{
772
- type: "insert.text",
773
- text: hrCharacters
774
- }], ({
775
- hrObject,
776
- focusBlock
777
- }) => types.isPortableTextTextBlock(focusBlock.node) ? [{
778
- type: "insert.text block",
779
- textBlock: {
780
- children: focusBlock.node.children
781
- },
782
- placement: "after"
783
- }, {
784
- type: "insert.block object",
785
- blockObject: hrObject,
786
- placement: "after"
787
- }, {
788
- type: "delete.block",
789
- blockPath: focusBlock.path
790
- }] : [{
791
- type: "insert.block object",
792
- blockObject: hrObject,
793
- placement: "after"
794
- }]]
795
- }, automaticHeadingOnSpace = {
796
- on: "insert.text",
797
- guard: ({
798
- context,
799
- event
800
- }) => {
801
- var _a;
802
- if (event.text !== " ")
803
- return !1;
804
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
805
- context
806
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
807
- context
808
- }), focusSpan = selector_getTextBefore.getFocusSpan({
809
- context
810
- });
811
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
812
- return !1;
813
- const blockOffset = spanSelectionPointToBlockOffset({
814
- value: context.value,
815
- selectionPoint: {
816
- path: [{
817
- _key: focusTextBlock.node._key
818
- }, "children", {
819
- _key: focusSpan.node._key
820
- }],
821
- offset: context.selection.focus.offset
822
- }
823
- });
824
- if (!blockOffset)
825
- return !1;
826
- const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
827
- if (blockOffset.offset !== level)
828
- return !1;
829
- const style = level !== void 0 ? (_a = config.headingStyle) == null ? void 0 : _a.call(config, {
830
- schema: context.schema,
831
- level
832
- }) : void 0;
833
- return level !== void 0 && style !== void 0 ? {
834
- focusTextBlock,
835
- style,
836
- level
837
- } : !1;
838
- },
839
- actions: [() => [{
840
- type: "insert.text",
841
- text: " "
842
- }], ({
843
- focusTextBlock,
844
- style,
845
- level
846
- }) => [{
847
- type: "text block.unset",
848
- props: ["listItem", "level"],
849
- at: focusTextBlock.path
850
- }, {
851
- type: "text block.set",
852
- style,
853
- at: focusTextBlock.path
854
- }, {
855
- type: "delete.text",
856
- anchor: {
857
- path: focusTextBlock.path,
858
- offset: 0
859
- },
860
- focus: {
861
- path: focusTextBlock.path,
862
- offset: level + 1
863
- }
864
- }]]
865
- }, clearStyleOnBackspace = {
866
- on: "delete.backward",
867
- guard: ({
868
- context
869
- }) => {
870
- var _a;
871
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
872
- context
873
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
874
- context
875
- }), focusSpan = selector_getTextBefore.getFocusSpan({
876
- context
877
- });
878
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
879
- return !1;
880
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = (_a = config.defaultStyle) == null ? void 0 : _a.call(config, context);
881
- return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
882
- defaultStyle,
883
- focusTextBlock
884
- } : !1;
885
- },
886
- actions: [({
887
- defaultStyle,
888
- focusTextBlock
889
- }) => [{
890
- type: "text block.set",
891
- style: defaultStyle,
892
- at: focusTextBlock.path
893
- }]]
894
- }, automaticListOnSpace = {
895
- on: "insert.text",
896
- guard: ({
897
- context,
898
- event
899
- }) => {
900
- var _a, _b, _c;
901
- if (event.text !== " ")
902
- return !1;
903
- const selectionCollapsed = selector_getTextBefore.selectionIsCollapsed({
904
- context
905
- }), focusTextBlock = selector_getTextBefore.getFocusTextBlock({
906
- context
907
- }), focusSpan = selector_getTextBefore.getFocusSpan({
908
- context
909
- });
910
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
911
- return !1;
912
- const blockOffset = spanSelectionPointToBlockOffset({
913
- value: context.value,
914
- selectionPoint: {
915
- path: [{
916
- _key: focusTextBlock.node._key
917
- }, "children", {
918
- _key: focusSpan.node._key
919
- }],
920
- offset: context.selection.focus.offset
921
- }
922
- });
923
- if (!blockOffset)
924
- return !1;
925
- const blockText = getTextBlockText(focusTextBlock.node), defaultStyle = (_a = config.defaultStyle) == null ? void 0 : _a.call(config, context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = (_b = config.unorderedListStyle) == null ? void 0 : _b.call(config, context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
926
- if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
927
- return {
928
- focusTextBlock,
929
- listItem: unorderedListStyle,
930
- listItemLength: 1,
931
- style: defaultStyle
932
- };
933
- const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = (_c = config.orderedListStyle) == null ? void 0 : _c.call(config, context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
934
- return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
935
- focusTextBlock,
936
- listItem: orderedListStyle,
937
- listItemLength: 2,
938
- style: defaultStyle
939
- } : !1;
940
- },
941
- actions: [() => [{
942
- type: "insert.text",
943
- text: " "
944
- }], ({
945
- focusTextBlock,
946
- style,
947
- listItem,
948
- listItemLength
949
- }) => [{
950
- type: "text block.set",
951
- listItem,
952
- level: 1,
953
- style,
954
- at: focusTextBlock.path
955
- }, {
956
- type: "delete.text",
957
- anchor: {
958
- path: focusTextBlock.path,
959
- offset: 0
960
- },
961
- focus: {
962
- path: focusTextBlock.path,
963
- offset: listItemLength + 1
964
- }
965
- }]]
966
- };
967
- return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
968
- }
969
- function getPortableTextMemberSchemaTypes(portableTextType) {
19
+ function createEditorSchema(portableTextType) {
970
20
  var _a, _b, _c;
971
21
  if (!portableTextType)
972
22
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -1094,7 +144,7 @@ function compileSchemaDefinition(definition) {
1094
144
  }]
1095
145
  }), schema$1 = schema.Schema.compile({
1096
146
  types: [portableTextSchema, ...blockObjects, ...inlineObjects]
1097
- }).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema$1);
147
+ }).get("portable-text"), pteSchema = createEditorSchema(schema$1);
1098
148
  return __spreadProps$j(__spreadValues$p({}, pteSchema), {
1099
149
  blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
1100
150
  name: "image",
@@ -5143,7 +4193,7 @@ const toggleListItemActionImplementation = ({
5143
4193
  }) => {
5144
4194
  if (!action.editor.selection)
5145
4195
  return;
5146
- const guards = selector_getTextBefore.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4196
+ const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
5147
4197
  at: action.editor.selection,
5148
4198
  match: (node) => guards.isListBlock(node)
5149
4199
  })];
@@ -5157,7 +4207,7 @@ const toggleListItemActionImplementation = ({
5157
4207
  }) => {
5158
4208
  if (!action.editor.selection)
5159
4209
  return;
5160
- const guards = selector_getTextBefore.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4210
+ const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
5161
4211
  at: action.editor.selection,
5162
4212
  match: (node) => guards.isTextBlock(node)
5163
4213
  })];
@@ -5213,7 +4263,7 @@ const toggleStyleActionImplementation = ({
5213
4263
  }) => {
5214
4264
  if (!action.editor.selection)
5215
4265
  return;
5216
- const defaultStyle = context.schema.styles[0].value, guards = selector_getTextBefore.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4266
+ const defaultStyle = context.schema.styles[0].value, guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
5217
4267
  at: action.editor.selection,
5218
4268
  match: (node) => guards.isTextBlock(node)
5219
4269
  })];
@@ -5229,7 +4279,7 @@ const toggleStyleActionImplementation = ({
5229
4279
  }) => {
5230
4280
  if (!action.editor.selection)
5231
4281
  return;
5232
- const guards = selector_getTextBefore.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
4282
+ const guards = selectors.createGuards(context), selectedBlocks = [...slate.Editor.nodes(action.editor, {
5233
4283
  at: action.editor.selection,
5234
4284
  match: (node) => guards.isTextBlock(node)
5235
4285
  })];
@@ -6156,10 +5206,10 @@ const behaviorActionImplementations = {
6156
5206
  context,
6157
5207
  action
6158
5208
  }) => {
6159
- 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({
6160
5210
  value,
6161
5211
  blockOffset: action.anchor
6162
- }), focus = blockOffsetToSpanSelectionPoint({
5212
+ }), focus = behavior_core.blockOffsetToSpanSelectionPoint({
6163
5213
  value,
6164
5214
  blockOffset: action.focus
6165
5215
  });
@@ -6265,7 +5315,7 @@ const behaviorActionImplementations = {
6265
5315
  const newSelection = toSlateRange(action.selection, action.editor);
6266
5316
  newSelection ? slate.Transforms.select(action.editor, newSelection) : slate.Transforms.deselect(action.editor);
6267
5317
  },
6268
- "select previous block": ({
5318
+ "select.previous block": ({
6269
5319
  action
6270
5320
  }) => {
6271
5321
  if (!action.editor.selection) {
@@ -6280,7 +5330,7 @@ const behaviorActionImplementations = {
6280
5330
  const previousBlockPath = slate.Path.previous(blockPath);
6281
5331
  slate.Transforms.select(action.editor, previousBlockPath);
6282
5332
  },
6283
- "select next block": ({
5333
+ "select.next block": ({
6284
5334
  action
6285
5335
  }) => {
6286
5336
  if (!action.editor.selection) {
@@ -6386,15 +5436,15 @@ function performAction({
6386
5436
  });
6387
5437
  break;
6388
5438
  }
6389
- case "select previous block": {
6390
- behaviorActionImplementations["select previous block"]({
5439
+ case "select.previous block": {
5440
+ behaviorActionImplementations["select.previous block"]({
6391
5441
  context,
6392
5442
  action
6393
5443
  });
6394
5444
  break;
6395
5445
  }
6396
- case "select next block": {
6397
- behaviorActionImplementations["select next block"]({
5446
+ case "select.next block": {
5447
+ behaviorActionImplementations["select.next block"]({
6398
5448
  context,
6399
5449
  action
6400
5450
  });
@@ -6634,18 +5684,7 @@ const editorMachine = xstate.setup({
6634
5684
  });
6635
5685
  return;
6636
5686
  }
6637
- const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema);
6638
- if (!selection) {
6639
- if (console.warn(`Unable to handle event ${event.type} due to missing selection`), !defaultAction)
6640
- return;
6641
- enqueue.raise({
6642
- type: "behavior action intends",
6643
- editor: event.editor,
6644
- actionIntends: [defaultAction]
6645
- });
6646
- return;
6647
- }
6648
- const editorContext = {
5687
+ const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema), editorContext = {
6649
5688
  keyGenerator: context.keyGenerator,
6650
5689
  schema: context.schema,
6651
5690
  selection,
@@ -6659,7 +5698,10 @@ const editorMachine = xstate.setup({
6659
5698
  });
6660
5699
  if (!shouldRun)
6661
5700
  continue;
6662
- const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet(shouldRun));
5701
+ const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
5702
+ context: editorContext,
5703
+ event: event.behaviorEvent
5704
+ }, shouldRun));
6663
5705
  for (const actionIntends of actionIntendSets)
6664
5706
  behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
6665
5707
  type: "behavior action intends",
@@ -6689,11 +5731,11 @@ const editorMachine = xstate.setup({
6689
5731
  }) => {
6690
5732
  var _a, _b;
6691
5733
  return {
6692
- behaviors: (_a = input.behaviors) != null ? _a : coreBehaviors,
5734
+ behaviors: (_a = input.behaviors) != null ? _a : behavior_core.coreBehaviors,
6693
5735
  keyGenerator: input.keyGenerator,
6694
5736
  pendingEvents: [],
6695
5737
  schema: input.schema,
6696
- selection: void 0,
5738
+ selection: null,
6697
5739
  readOnly: (_b = input.readOnly) != null ? _b : !1,
6698
5740
  maxBlocks: input.maxBlocks,
6699
5741
  value: input.value
@@ -6801,10 +5843,7 @@ const editorMachine = xstate.setup({
6801
5843
  actions: [xstate.assign({
6802
5844
  selection: ({
6803
5845
  event
6804
- }) => {
6805
- var _a;
6806
- return (_a = event.selection) != null ? _a : void 0;
6807
- }
5846
+ }) => event.selection
6808
5847
  }), xstate.emit(({
6809
5848
  event
6810
5849
  }) => event)]
@@ -6970,28 +6009,10 @@ function createEditor(config) {
6970
6009
  const editorActor = xstate.createActor(editorMachine, {
6971
6010
  input: editorConfigToMachineInput(config)
6972
6011
  });
6973
- editorActor.start();
6974
- const slateEditor = createSlateEditor({
6975
- editorActor
6976
- }), editable = createEditableAPI(slateEditor.instance, editorActor);
6977
- return {
6978
- send: (event) => {
6979
- editorActor.send(event);
6980
- },
6981
- on: (event, listener) => editorActor.on(
6982
- event,
6983
- // @ts-expect-error
6984
- listener
6985
- ),
6986
- _internal: {
6987
- editable,
6988
- editorActor,
6989
- slateEditor
6990
- }
6991
- };
6012
+ return editorActor.start(), createEditorFromActor(editorActor);
6992
6013
  }
6993
6014
  function useCreateEditor(config) {
6994
- const $ = reactCompilerRuntime.c(18);
6015
+ const $ = reactCompilerRuntime.c(6);
6995
6016
  let t0;
6996
6017
  $[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
6997
6018
  let t1;
@@ -6999,27 +6020,8 @@ function useCreateEditor(config) {
6999
6020
  input: t0
7000
6021
  }, $[2] = t0, $[3] = t1) : t1 = $[3];
7001
6022
  const editorActor = react.useActorRef(editorMachine, t1);
7002
- let t2, slateEditor, t3;
7003
- $[4] !== editorActor ? (slateEditor = createSlateEditor({
7004
- editorActor
7005
- }), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
7006
- const editable = t3;
7007
- let t4, t5;
7008
- $[7] !== editorActor ? (t4 = (event) => {
7009
- editorActor.send(event);
7010
- }, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
7011
- let t6;
7012
- $[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
7013
- editable,
7014
- editorActor,
7015
- slateEditor
7016
- }, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
7017
- let t7;
7018
- return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
7019
- send: t4,
7020
- on: t5,
7021
- _internal: t6
7022
- }, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
6023
+ let t2, t3;
6024
+ return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
7023
6025
  }
7024
6026
  function editorConfigToMachineInput(config) {
7025
6027
  var _a;
@@ -7028,10 +6030,30 @@ function editorConfigToMachineInput(config) {
7028
6030
  keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
7029
6031
  maxBlocks: config.maxBlocks,
7030
6032
  readOnly: config.readOnly,
7031
- schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
6033
+ schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
7032
6034
  value: config.initialValue
7033
6035
  };
7034
6036
  }
6037
+ function createEditorFromActor(editorActor) {
6038
+ const slateEditor = createSlateEditor({
6039
+ editorActor
6040
+ }), editable = createEditableAPI(slateEditor.instance, editorActor);
6041
+ return {
6042
+ send: (event) => {
6043
+ editorActor.send(event);
6044
+ },
6045
+ on: (event, listener) => editorActor.on(
6046
+ event,
6047
+ // @ts-expect-error
6048
+ listener
6049
+ ),
6050
+ _internal: {
6051
+ editable,
6052
+ editorActor,
6053
+ slateEditor
6054
+ }
6055
+ };
6056
+ }
7035
6057
  const EditorActorContext = React.createContext({}), PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
7036
6058
  const selection = React.useContext(PortableTextEditorSelectionContext);
7037
6059
  if (selection === void 0)
@@ -7087,7 +6109,7 @@ class PortableTextEditor extends React.Component {
7087
6109
  }), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
7088
6110
  }
7089
6111
  componentDidUpdate(prevProps) {
7090
- !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
6112
+ !this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = createEditorSchema(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
7091
6113
  type: "update schema",
7092
6114
  schema: this.schemaTypes
7093
6115
  })), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
@@ -7457,7 +6479,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
7457
6479
  for (const hotkey in activeHotkeys[cat]) {
7458
6480
  if (reservedHotkeys.includes(hotkey))
7459
6481
  throw new Error(`The hotkey ${hotkey} is reserved!`);
7460
- if (isHotkey(hotkey, event.nativeEvent)) {
6482
+ if (behavior_core.isHotkey(hotkey, event.nativeEvent)) {
7461
6483
  event.preventDefault();
7462
6484
  const possibleMark = activeHotkeys[cat];
7463
6485
  if (possibleMark) {
@@ -7477,7 +6499,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
7477
6499
  for (const hotkey in activeHotkeys[cat]) {
7478
6500
  if (reservedHotkeys.includes(hotkey))
7479
6501
  throw new Error(`The hotkey ${hotkey} is reserved!`);
7480
- if (isHotkey(hotkey, event.nativeEvent)) {
6502
+ if (behavior_core.isHotkey(hotkey, event.nativeEvent)) {
7481
6503
  const possibleCommand = activeHotkeys[cat];
7482
6504
  if (possibleCommand) {
7483
6505
  const command = possibleCommand[hotkey];
@@ -8122,12 +7144,6 @@ exports.EditorEventListener = EditorEventListener;
8122
7144
  exports.EditorProvider = EditorProvider;
8123
7145
  exports.PortableTextEditable = PortableTextEditable;
8124
7146
  exports.PortableTextEditor = PortableTextEditor;
8125
- exports.coreBehavior = coreBehavior;
8126
- exports.coreBehaviors = coreBehaviors;
8127
- exports.createCodeEditorBehaviors = createCodeEditorBehaviors;
8128
- exports.createLinkBehaviors = createLinkBehaviors;
8129
- exports.createMarkdownBehaviors = createMarkdownBehaviors;
8130
- exports.defineBehavior = defineBehavior;
8131
7147
  exports.defineSchema = defineSchema;
8132
7148
  exports.editorMachine = editorMachine;
8133
7149
  exports.keyGenerator = defaultKeyGenerator;