@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.js CHANGED
@@ -9,9 +9,8 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
9
9
  __propIsEnum.call(b, prop) && __defNormalProp(a, prop, b[prop]);
10
10
  return a;
11
11
  };
12
- import { getFirstBlock, getSelectedBlocks, getLastBlock, getFocusBlockObject, getNextBlock, getPreviousBlock, selectionIsCollapsed, getFocusTextBlock, getFocusSpan, getFocusListBlock, createGuards, getBlockTextBefore, getFocusBlock } from "./_chunks-es/selector.get-text-before.js";
13
- import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, defineType, defineField, isKeySegment, isPortableTextListBlock } from "@sanity/types";
14
12
  import { Schema } from "@sanity/schema";
13
+ import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
15
14
  import startCase from "lodash.startcase";
16
15
  import { jsx, Fragment, jsxs } from "react/jsx-runtime";
17
16
  import { useSelector, useActorRef } from "@xstate/react";
@@ -35,959 +34,11 @@ import { setup, assign, assertEvent, emit, enqueueActions, createActor } from "x
35
34
  import get from "lodash/get.js";
36
35
  import isUndefined from "lodash/isUndefined.js";
37
36
  import omitBy from "lodash/omitBy.js";
37
+ import { createGuards } from "./_chunks-es/selectors.js";
38
+ import { blockOffsetToSpanSelectionPoint, coreBehaviors, isHotkey } from "./_chunks-es/behavior.core.js";
38
39
  import getRandomValues from "get-random-values-esm";
39
40
  import { htmlToBlocks, normalizeBlock } from "@sanity/block-tools";
40
- const IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
41
- alt: "altKey",
42
- control: "ctrlKey",
43
- meta: "metaKey",
44
- shift: "shiftKey"
45
- }, aliases = {
46
- add: "+",
47
- break: "pause",
48
- cmd: "meta",
49
- command: "meta",
50
- ctl: "control",
51
- ctrl: "control",
52
- del: "delete",
53
- down: "arrowdown",
54
- esc: "escape",
55
- ins: "insert",
56
- left: "arrowleft",
57
- mod: IS_MAC ? "meta" : "control",
58
- opt: "alt",
59
- option: "alt",
60
- return: "enter",
61
- right: "arrowright",
62
- space: " ",
63
- spacebar: " ",
64
- up: "arrowup",
65
- win: "meta",
66
- windows: "meta"
67
- }, keyCodes = {
68
- backspace: 8,
69
- tab: 9,
70
- enter: 13,
71
- shift: 16,
72
- control: 17,
73
- alt: 18,
74
- pause: 19,
75
- capslock: 20,
76
- escape: 27,
77
- " ": 32,
78
- pageup: 33,
79
- pagedown: 34,
80
- end: 35,
81
- home: 36,
82
- arrowleft: 37,
83
- arrowup: 38,
84
- arrowright: 39,
85
- arrowdown: 40,
86
- insert: 45,
87
- delete: 46,
88
- meta: 91,
89
- numlock: 144,
90
- scrolllock: 145,
91
- ";": 186,
92
- "=": 187,
93
- ",": 188,
94
- "-": 189,
95
- ".": 190,
96
- "/": 191,
97
- "`": 192,
98
- "[": 219,
99
- "\\": 220,
100
- "]": 221,
101
- "'": 222,
102
- f1: 112,
103
- f2: 113,
104
- f3: 114,
105
- f4: 115,
106
- f5: 116,
107
- f6: 117,
108
- f7: 118,
109
- f8: 119,
110
- f9: 120,
111
- f10: 121,
112
- f11: 122,
113
- f12: 123,
114
- f13: 124,
115
- f14: 125,
116
- f15: 126,
117
- f16: 127,
118
- f17: 128,
119
- f18: 129,
120
- f19: 130,
121
- f20: 131
122
- };
123
- function isHotkey(hotkey, event) {
124
- return compareHotkey(parseHotkey(hotkey), event);
125
- }
126
- function parseHotkey(hotkey) {
127
- const parsedHotkey = {
128
- altKey: !1,
129
- ctrlKey: !1,
130
- metaKey: !1,
131
- shiftKey: !1
132
- }, hotkeySegments = hotkey.replace("++", "+add").split("+");
133
- for (const rawHotkeySegment of hotkeySegments) {
134
- 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];
135
- if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
136
- throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
137
- (hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
138
- }
139
- return parsedHotkey;
140
- }
141
- function compareHotkey(parsedHotkey, event) {
142
- 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;
143
- }
144
- function toKeyCode(name) {
145
- var _a;
146
- const keyName = toKeyName(name);
147
- return (_a = keyCodes[keyName]) != null ? _a : keyName.toUpperCase().charCodeAt(0);
148
- }
149
- function toKeyName(name) {
150
- var _a;
151
- const keyName = name.toLowerCase();
152
- return (_a = aliases[keyName]) != null ? _a : keyName;
153
- }
154
- function defineBehavior(behavior) {
155
- return behavior;
156
- }
157
- function createCodeEditorBehaviors(config) {
158
- return [{
159
- on: "key.down",
160
- guard: ({
161
- context,
162
- event
163
- }) => {
164
- var _a;
165
- const isMoveUpShortcut = isHotkey(config.moveBlockUpShortcut, event.keyboardEvent), firstBlock = getFirstBlock({
166
- context
167
- }), selectedBlocks = getSelectedBlocks({
168
- context
169
- }), blocksAbove = (firstBlock == null ? void 0 : firstBlock.node._key) !== ((_a = selectedBlocks[0]) == null ? void 0 : _a.node._key);
170
- return !isMoveUpShortcut || !blocksAbove ? !1 : {
171
- paths: selectedBlocks.map((block) => block.path)
172
- };
173
- },
174
- actions: [({
175
- paths
176
- }) => paths.map((at) => ({
177
- type: "move.block up",
178
- at
179
- }))]
180
- }, {
181
- on: "key.down",
182
- guard: ({
183
- context,
184
- event
185
- }) => {
186
- var _a;
187
- const isMoveDownShortcut = isHotkey(config.moveBlockDownShortcut, event.keyboardEvent), lastBlock = getLastBlock({
188
- context
189
- }), selectedBlocks = getSelectedBlocks({
190
- context
191
- }), blocksBelow = (lastBlock == null ? void 0 : lastBlock.node._key) !== ((_a = selectedBlocks[selectedBlocks.length - 1]) == null ? void 0 : _a.node._key);
192
- return !isMoveDownShortcut || !blocksBelow ? !1 : {
193
- paths: selectedBlocks.map((block) => block.path).reverse()
194
- };
195
- },
196
- actions: [({
197
- paths
198
- }) => paths.map((at) => ({
199
- type: "move.block down",
200
- at
201
- }))]
202
- }];
203
- }
204
- function isEmptyTextBlock(block) {
205
- if (!isPortableTextTextBlock(block))
206
- return !1;
207
- const onlyText = block.children.every(isPortableTextSpan$1), blockText = getTextBlockText(block);
208
- return onlyText && blockText === "";
209
- }
210
- function getTextBlockText(block) {
211
- return block.children.map((child) => {
212
- var _a;
213
- return (_a = child.text) != null ? _a : "";
214
- }).join("");
215
- }
216
- const arrowDownOnLonelyBlockObject = {
217
- on: "key.down",
218
- guard: ({
219
- context,
220
- event
221
- }) => {
222
- const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject = getFocusBlockObject({
223
- context
224
- }), nextBlock = getNextBlock({
225
- context
226
- });
227
- return isArrowDown && focusBlockObject && !nextBlock;
228
- },
229
- actions: [() => [{
230
- type: "insert.text block",
231
- placement: "after"
232
- }]]
233
- }, arrowUpOnLonelyBlockObject = {
234
- on: "key.down",
235
- guard: ({
236
- context,
237
- event
238
- }) => {
239
- const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject = getFocusBlockObject({
240
- context
241
- }), previousBlock = getPreviousBlock({
242
- context
243
- });
244
- return isArrowUp && focusBlockObject && !previousBlock;
245
- },
246
- actions: [() => [{
247
- type: "insert.text block",
248
- placement: "before"
249
- }, {
250
- type: "select previous block"
251
- }]]
252
- }, breakingBlockObject = {
253
- on: "insert.break",
254
- guard: ({
255
- context
256
- }) => {
257
- const focusBlockObject = getFocusBlockObject({
258
- context
259
- });
260
- return selectionIsCollapsed({
261
- context
262
- }) && focusBlockObject !== void 0;
263
- },
264
- actions: [() => [{
265
- type: "insert.text block",
266
- placement: "after"
267
- }]]
268
- }, deletingEmptyTextBlockAfterBlockObject = {
269
- on: "delete.backward",
270
- guard: ({
271
- context
272
- }) => {
273
- const focusTextBlock = getFocusTextBlock({
274
- context
275
- }), selectionCollapsed = selectionIsCollapsed({
276
- context
277
- }), previousBlock = getPreviousBlock({
278
- context
279
- });
280
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(previousBlock.node) ? {
281
- focusTextBlock,
282
- previousBlock
283
- } : !1;
284
- },
285
- actions: [({
286
- focusTextBlock,
287
- previousBlock
288
- }) => [{
289
- type: "delete.block",
290
- blockPath: focusTextBlock.path
291
- }, {
292
- type: "select",
293
- selection: {
294
- anchor: {
295
- path: previousBlock.path,
296
- offset: 0
297
- },
298
- focus: {
299
- path: previousBlock.path,
300
- offset: 0
301
- }
302
- }
303
- }]]
304
- }, deletingEmptyTextBlockBeforeBlockObject = {
305
- on: "delete.forward",
306
- guard: ({
307
- context
308
- }) => {
309
- const focusTextBlock = getFocusTextBlock({
310
- context
311
- }), selectionCollapsed = selectionIsCollapsed({
312
- context
313
- }), nextBlock = getNextBlock({
314
- context
315
- });
316
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !isPortableTextTextBlock(nextBlock.node) ? {
317
- focusTextBlock,
318
- nextBlock
319
- } : !1;
320
- },
321
- actions: [({
322
- focusTextBlock,
323
- nextBlock
324
- }) => [{
325
- type: "delete.block",
326
- blockPath: focusTextBlock.path
327
- }, {
328
- type: "select",
329
- selection: {
330
- anchor: {
331
- path: nextBlock.path,
332
- offset: 0
333
- },
334
- focus: {
335
- path: nextBlock.path,
336
- offset: 0
337
- }
338
- }
339
- }]]
340
- }, coreBlockObjectBehaviors = {
341
- arrowDownOnLonelyBlockObject,
342
- arrowUpOnLonelyBlockObject,
343
- breakingBlockObject,
344
- deletingEmptyTextBlockAfterBlockObject,
345
- deletingEmptyTextBlockBeforeBlockObject
346
- }, decoratorAdd = {
347
- on: "decorator.add",
348
- guard: ({
349
- event
350
- }) => ({
351
- decorator: event.decorator
352
- }),
353
- actions: [({
354
- decorator
355
- }) => [{
356
- type: "decorator.add",
357
- decorator
358
- }, {
359
- type: "reselect"
360
- }]]
361
- }, decoratorRemove = {
362
- on: "decorator.remove",
363
- guard: ({
364
- event
365
- }) => ({
366
- decorator: event.decorator
367
- }),
368
- actions: [({
369
- decorator
370
- }) => [{
371
- type: "decorator.remove",
372
- decorator
373
- }, {
374
- type: "reselect"
375
- }]]
376
- }, decoratorToggle = {
377
- on: "decorator.toggle",
378
- guard: ({
379
- event
380
- }) => ({
381
- decorator: event.decorator
382
- }),
383
- actions: [({
384
- decorator
385
- }) => [{
386
- type: "decorator.toggle",
387
- decorator
388
- }, {
389
- type: "reselect"
390
- }]]
391
- }, coreDecoratorBehaviors = {
392
- decoratorAdd,
393
- decoratorRemove,
394
- decoratorToggle
395
- }, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
396
- on: "delete.backward",
397
- guard: ({
398
- context
399
- }) => {
400
- const selectionCollapsed = selectionIsCollapsed({
401
- context
402
- }), focusTextBlock = getFocusTextBlock({
403
- context
404
- }), focusSpan = getFocusSpan({
405
- context
406
- });
407
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
408
- focusTextBlock
409
- } : !1;
410
- },
411
- actions: [({
412
- focusTextBlock
413
- }) => [{
414
- type: "text block.unset",
415
- props: ["listItem", "level"],
416
- at: focusTextBlock.path
417
- }]]
418
- }, unindentListOnBackspace = {
419
- on: "delete.backward",
420
- guard: ({
421
- context
422
- }) => {
423
- const selectionCollapsed = selectionIsCollapsed({
424
- context
425
- }), focusTextBlock = getFocusTextBlock({
426
- context
427
- }), focusSpan = getFocusSpan({
428
- context
429
- });
430
- 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 ? {
431
- focusTextBlock,
432
- level: focusTextBlock.node.level - 1
433
- } : !1;
434
- },
435
- actions: [({
436
- focusTextBlock,
437
- level
438
- }) => [{
439
- type: "text block.set",
440
- level,
441
- at: focusTextBlock.path
442
- }]]
443
- }, clearListOnEnter = {
444
- on: "insert.break",
445
- guard: ({
446
- context
447
- }) => {
448
- const focusListBlock = getFocusListBlock({
449
- context
450
- }), selectionCollapsed = selectionIsCollapsed({
451
- context
452
- });
453
- return !focusListBlock || !selectionCollapsed || !isEmptyTextBlock(focusListBlock.node) ? !1 : {
454
- focusListBlock
455
- };
456
- },
457
- actions: [({
458
- focusListBlock
459
- }) => [{
460
- type: "text block.unset",
461
- props: ["listItem", "level"],
462
- at: focusListBlock.path
463
- }]]
464
- }, indentListOnTab = {
465
- on: "key.down",
466
- guard: ({
467
- context,
468
- event
469
- }) => {
470
- if (!isHotkey("Tab", event.keyboardEvent))
471
- return !1;
472
- const selectedBlocks = getSelectedBlocks({
473
- context
474
- }), guards = createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
475
- node: block.node,
476
- path: block.path
477
- }] : []);
478
- return selectedListBlocks.length === selectedBlocks.length ? {
479
- selectedListBlocks
480
- } : !1;
481
- },
482
- actions: [({
483
- selectedListBlocks
484
- }) => selectedListBlocks.map((selectedListBlock) => ({
485
- type: "text block.set",
486
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
487
- at: selectedListBlock.path
488
- }))]
489
- }, unindentListOnShiftTab = {
490
- on: "key.down",
491
- guard: ({
492
- context,
493
- event
494
- }) => {
495
- if (!isHotkey("Shift+Tab", event.keyboardEvent))
496
- return !1;
497
- const selectedBlocks = getSelectedBlocks({
498
- context
499
- }), guards = createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
500
- node: block.node,
501
- path: block.path
502
- }] : []);
503
- return selectedListBlocks.length === selectedBlocks.length ? {
504
- selectedListBlocks
505
- } : !1;
506
- },
507
- actions: [({
508
- selectedListBlocks
509
- }) => selectedListBlocks.map((selectedListBlock) => ({
510
- type: "text block.set",
511
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
512
- at: selectedListBlock.path
513
- }))]
514
- }, coreListBehaviors = {
515
- clearListOnBackspace,
516
- unindentListOnBackspace,
517
- clearListOnEnter,
518
- indentListOnTab,
519
- unindentListOnShiftTab
520
- }, softReturn = {
521
- on: "insert.soft break",
522
- actions: [() => [{
523
- type: "insert.text",
524
- text: `
525
- `
526
- }]]
527
- }, 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 = {
528
- softReturn,
529
- decorators: coreDecoratorBehaviors,
530
- blockObjects: coreBlockObjectBehaviors,
531
- lists: coreListBehaviors
532
- };
533
- function createLinkBehaviors(config) {
534
- const pasteLinkOnSelection = {
535
- on: "paste",
536
- guard: ({
537
- context,
538
- event
539
- }) => {
540
- var _a;
541
- const selectionCollapsed = selectionIsCollapsed({
542
- context
543
- }), 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, {
544
- url,
545
- schema: context.schema
546
- }) : void 0;
547
- return annotation && !selectionCollapsed ? {
548
- annotation
549
- } : !1;
550
- },
551
- actions: [({
552
- annotation
553
- }) => [{
554
- type: "annotation.add",
555
- annotation
556
- }]]
557
- }, pasteLinkAtCaret = {
558
- on: "paste",
559
- guard: ({
560
- context,
561
- event
562
- }) => {
563
- var _a;
564
- const focusSpan = getFocusSpan({
565
- context
566
- }), selectionCollapsed = selectionIsCollapsed({
567
- context
568
- });
569
- if (!focusSpan || !selectionCollapsed)
570
- return !1;
571
- 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, {
572
- url,
573
- schema: context.schema
574
- }) : void 0;
575
- return url && annotation && selectionCollapsed ? {
576
- focusSpan,
577
- annotation,
578
- url
579
- } : !1;
580
- },
581
- actions: [({
582
- annotation,
583
- url
584
- }) => [{
585
- type: "insert.span",
586
- text: url,
587
- annotations: [annotation]
588
- }]]
589
- };
590
- return [pasteLinkOnSelection, pasteLinkAtCaret];
591
- }
592
- function looksLikeUrl(text) {
593
- let looksLikeUrl2 = !1;
594
- try {
595
- new URL(text), looksLikeUrl2 = !0;
596
- } catch (e) {
597
- }
598
- return looksLikeUrl2;
599
- }
600
- function blockOffsetToSpanSelectionPoint({
601
- value,
602
- blockOffset
603
- }) {
604
- let offsetLeft = blockOffset.offset, selectionPoint;
605
- for (const block of value)
606
- if (block._key === blockOffset.path[0]._key && isPortableTextTextBlock(block)) {
607
- for (const child of block.children)
608
- if (isPortableTextSpan$1(child)) {
609
- if (offsetLeft === 0) {
610
- selectionPoint = {
611
- path: [...blockOffset.path, "children", {
612
- _key: child._key
613
- }],
614
- offset: 0
615
- };
616
- break;
617
- }
618
- if (offsetLeft <= child.text.length) {
619
- selectionPoint = {
620
- path: [...blockOffset.path, "children", {
621
- _key: child._key
622
- }],
623
- offset: offsetLeft
624
- };
625
- break;
626
- }
627
- offsetLeft -= child.text.length;
628
- }
629
- }
630
- return selectionPoint;
631
- }
632
- function spanSelectionPointToBlockOffset({
633
- value,
634
- selectionPoint
635
- }) {
636
- let offset = 0;
637
- for (const block of value)
638
- if (block._key === selectionPoint.path[0]._key && isPortableTextTextBlock(block)) {
639
- for (const child of block.children)
640
- if (isPortableTextSpan$1(child)) {
641
- if (child._key === selectionPoint.path[2]._key)
642
- return {
643
- path: [{
644
- _key: block._key
645
- }],
646
- offset: offset + selectionPoint.offset
647
- };
648
- offset += child.text.length;
649
- }
650
- }
651
- }
652
- 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) => {
653
- for (var prop in b || (b = {}))
654
- __hasOwnProp$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
655
- if (__getOwnPropSymbols$q)
656
- for (var prop of __getOwnPropSymbols$q(b))
657
- __propIsEnum$q.call(b, prop) && __defNormalProp$q(a, prop, b[prop]);
658
- return a;
659
- };
660
- function createMarkdownBehaviors(config) {
661
- const automaticBlockquoteOnSpace = {
662
- on: "insert.text",
663
- guard: ({
664
- context,
665
- event
666
- }) => {
667
- var _a;
668
- if (event.text !== " ")
669
- return !1;
670
- const selectionCollapsed = selectionIsCollapsed({
671
- context
672
- }), focusTextBlock = getFocusTextBlock({
673
- context
674
- }), focusSpan = getFocusSpan({
675
- context
676
- });
677
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
678
- return !1;
679
- const blockOffset = spanSelectionPointToBlockOffset({
680
- value: context.value,
681
- selectionPoint: {
682
- path: [{
683
- _key: focusTextBlock.node._key
684
- }, "children", {
685
- _key: focusSpan.node._key
686
- }],
687
- offset: context.selection.focus.offset
688
- }
689
- });
690
- if (!blockOffset)
691
- return !1;
692
- const blockText = getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = (_a = config.blockquoteStyle) == null ? void 0 : _a.call(config, context);
693
- return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
694
- focusTextBlock,
695
- style: blockquoteStyle
696
- } : !1;
697
- },
698
- actions: [() => [{
699
- type: "insert.text",
700
- text: " "
701
- }], ({
702
- focusTextBlock,
703
- style
704
- }) => [{
705
- type: "text block.unset",
706
- props: ["listItem", "level"],
707
- at: focusTextBlock.path
708
- }, {
709
- type: "text block.set",
710
- style,
711
- at: focusTextBlock.path
712
- }, {
713
- type: "delete.text",
714
- anchor: {
715
- path: focusTextBlock.path,
716
- offset: 0
717
- },
718
- focus: {
719
- path: focusTextBlock.path,
720
- offset: 2
721
- }
722
- }]]
723
- }, automaticHr = {
724
- on: "insert.text",
725
- guard: ({
726
- context,
727
- event
728
- }) => {
729
- var _a;
730
- const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
731
- if (hrCharacter === void 0)
732
- return !1;
733
- const hrObject = (_a = config.horizontalRuleObject) == null ? void 0 : _a.call(config, context), focusBlock = getFocusTextBlock({
734
- context
735
- }), selectionCollapsed = selectionIsCollapsed({
736
- context
737
- });
738
- if (!hrObject || !focusBlock || !selectionCollapsed)
739
- return !1;
740
- const textBefore = getBlockTextBefore({
741
- context
742
- }), hrBlockOffsets = {
743
- anchor: {
744
- path: focusBlock.path,
745
- offset: 0
746
- },
747
- focus: {
748
- path: focusBlock.path,
749
- offset: 3
750
- }
751
- };
752
- return textBefore === `${hrCharacter}${hrCharacter}` ? {
753
- hrObject,
754
- focusBlock,
755
- hrCharacter,
756
- hrBlockOffsets
757
- } : !1;
758
- },
759
- actions: [({
760
- hrCharacter
761
- }) => [{
762
- type: "insert.text",
763
- text: hrCharacter
764
- }], ({
765
- hrObject,
766
- hrBlockOffsets
767
- }) => [{
768
- type: "insert.block object",
769
- placement: "before",
770
- blockObject: hrObject
771
- }, __spreadValues$q({
772
- type: "delete.text"
773
- }, hrBlockOffsets)]]
774
- }, automaticHrOnPaste = {
775
- on: "paste",
776
- guard: ({
777
- context,
778
- event
779
- }) => {
780
- var _a, _b;
781
- 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 = getFocusBlock({
782
- context
783
- });
784
- return !hrCharacters || !hrObject || !focusBlock ? !1 : {
785
- hrCharacters,
786
- hrObject,
787
- focusBlock
788
- };
789
- },
790
- actions: [({
791
- hrCharacters
792
- }) => [{
793
- type: "insert.text",
794
- text: hrCharacters
795
- }], ({
796
- hrObject,
797
- focusBlock
798
- }) => isPortableTextTextBlock(focusBlock.node) ? [{
799
- type: "insert.text block",
800
- textBlock: {
801
- children: focusBlock.node.children
802
- },
803
- placement: "after"
804
- }, {
805
- type: "insert.block object",
806
- blockObject: hrObject,
807
- placement: "after"
808
- }, {
809
- type: "delete.block",
810
- blockPath: focusBlock.path
811
- }] : [{
812
- type: "insert.block object",
813
- blockObject: hrObject,
814
- placement: "after"
815
- }]]
816
- }, automaticHeadingOnSpace = {
817
- on: "insert.text",
818
- guard: ({
819
- context,
820
- event
821
- }) => {
822
- var _a;
823
- if (event.text !== " ")
824
- return !1;
825
- const selectionCollapsed = selectionIsCollapsed({
826
- context
827
- }), focusTextBlock = getFocusTextBlock({
828
- context
829
- }), focusSpan = getFocusSpan({
830
- context
831
- });
832
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
833
- return !1;
834
- const blockOffset = spanSelectionPointToBlockOffset({
835
- value: context.value,
836
- selectionPoint: {
837
- path: [{
838
- _key: focusTextBlock.node._key
839
- }, "children", {
840
- _key: focusSpan.node._key
841
- }],
842
- offset: context.selection.focus.offset
843
- }
844
- });
845
- if (!blockOffset)
846
- return !1;
847
- const blockText = getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
848
- if (blockOffset.offset !== level)
849
- return !1;
850
- const style = level !== void 0 ? (_a = config.headingStyle) == null ? void 0 : _a.call(config, {
851
- schema: context.schema,
852
- level
853
- }) : void 0;
854
- return level !== void 0 && style !== void 0 ? {
855
- focusTextBlock,
856
- style,
857
- level
858
- } : !1;
859
- },
860
- actions: [() => [{
861
- type: "insert.text",
862
- text: " "
863
- }], ({
864
- focusTextBlock,
865
- style,
866
- level
867
- }) => [{
868
- type: "text block.unset",
869
- props: ["listItem", "level"],
870
- at: focusTextBlock.path
871
- }, {
872
- type: "text block.set",
873
- style,
874
- at: focusTextBlock.path
875
- }, {
876
- type: "delete.text",
877
- anchor: {
878
- path: focusTextBlock.path,
879
- offset: 0
880
- },
881
- focus: {
882
- path: focusTextBlock.path,
883
- offset: level + 1
884
- }
885
- }]]
886
- }, clearStyleOnBackspace = {
887
- on: "delete.backward",
888
- guard: ({
889
- context
890
- }) => {
891
- var _a;
892
- const selectionCollapsed = selectionIsCollapsed({
893
- context
894
- }), focusTextBlock = getFocusTextBlock({
895
- context
896
- }), focusSpan = getFocusSpan({
897
- context
898
- });
899
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
900
- return !1;
901
- 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);
902
- return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
903
- defaultStyle,
904
- focusTextBlock
905
- } : !1;
906
- },
907
- actions: [({
908
- defaultStyle,
909
- focusTextBlock
910
- }) => [{
911
- type: "text block.set",
912
- style: defaultStyle,
913
- at: focusTextBlock.path
914
- }]]
915
- }, automaticListOnSpace = {
916
- on: "insert.text",
917
- guard: ({
918
- context,
919
- event
920
- }) => {
921
- var _a, _b, _c;
922
- if (event.text !== " ")
923
- return !1;
924
- const selectionCollapsed = selectionIsCollapsed({
925
- context
926
- }), focusTextBlock = getFocusTextBlock({
927
- context
928
- }), focusSpan = getFocusSpan({
929
- context
930
- });
931
- if (!selectionCollapsed || !focusTextBlock || !focusSpan)
932
- return !1;
933
- const blockOffset = spanSelectionPointToBlockOffset({
934
- value: context.value,
935
- selectionPoint: {
936
- path: [{
937
- _key: focusTextBlock.node._key
938
- }, "children", {
939
- _key: focusSpan.node._key
940
- }],
941
- offset: context.selection.focus.offset
942
- }
943
- });
944
- if (!blockOffset)
945
- return !1;
946
- 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;
947
- if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
948
- return {
949
- focusTextBlock,
950
- listItem: unorderedListStyle,
951
- listItemLength: 1,
952
- style: defaultStyle
953
- };
954
- const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = (_c = config.orderedListStyle) == null ? void 0 : _c.call(config, context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
955
- return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
956
- focusTextBlock,
957
- listItem: orderedListStyle,
958
- listItemLength: 2,
959
- style: defaultStyle
960
- } : !1;
961
- },
962
- actions: [() => [{
963
- type: "insert.text",
964
- text: " "
965
- }], ({
966
- focusTextBlock,
967
- style,
968
- listItem,
969
- listItemLength
970
- }) => [{
971
- type: "text block.set",
972
- listItem,
973
- level: 1,
974
- style,
975
- at: focusTextBlock.path
976
- }, {
977
- type: "delete.text",
978
- anchor: {
979
- path: focusTextBlock.path,
980
- offset: 0
981
- },
982
- focus: {
983
- path: focusTextBlock.path,
984
- offset: listItemLength + 1
985
- }
986
- }]]
987
- };
988
- return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
989
- }
990
- function getPortableTextMemberSchemaTypes(portableTextType) {
41
+ function createEditorSchema(portableTextType) {
991
42
  var _a, _b, _c;
992
43
  if (!portableTextType)
993
44
  throw new Error("Parameter 'portabletextType' missing (required)");
@@ -1115,7 +166,7 @@ function compileSchemaDefinition(definition) {
1115
166
  }]
1116
167
  }), schema = Schema.compile({
1117
168
  types: [portableTextSchema, ...blockObjects, ...inlineObjects]
1118
- }).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema);
169
+ }).get("portable-text"), pteSchema = createEditorSchema(schema);
1119
170
  return __spreadProps$j(__spreadValues$p({}, pteSchema), {
1120
171
  blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? __spreadProps$j(__spreadValues$p({}, blockObject), {
1121
172
  name: "image",
@@ -6286,7 +5337,7 @@ const behaviorActionImplementations = {
6286
5337
  const newSelection = toSlateRange(action.selection, action.editor);
6287
5338
  newSelection ? Transforms.select(action.editor, newSelection) : Transforms.deselect(action.editor);
6288
5339
  },
6289
- "select previous block": ({
5340
+ "select.previous block": ({
6290
5341
  action
6291
5342
  }) => {
6292
5343
  if (!action.editor.selection) {
@@ -6301,7 +5352,7 @@ const behaviorActionImplementations = {
6301
5352
  const previousBlockPath = Path.previous(blockPath);
6302
5353
  Transforms.select(action.editor, previousBlockPath);
6303
5354
  },
6304
- "select next block": ({
5355
+ "select.next block": ({
6305
5356
  action
6306
5357
  }) => {
6307
5358
  if (!action.editor.selection) {
@@ -6407,15 +5458,15 @@ function performAction({
6407
5458
  });
6408
5459
  break;
6409
5460
  }
6410
- case "select previous block": {
6411
- behaviorActionImplementations["select previous block"]({
5461
+ case "select.previous block": {
5462
+ behaviorActionImplementations["select.previous block"]({
6412
5463
  context,
6413
5464
  action
6414
5465
  });
6415
5466
  break;
6416
5467
  }
6417
- case "select next block": {
6418
- behaviorActionImplementations["select next block"]({
5468
+ case "select.next block": {
5469
+ behaviorActionImplementations["select.next block"]({
6419
5470
  context,
6420
5471
  action
6421
5472
  });
@@ -6655,18 +5706,7 @@ const editorMachine = setup({
6655
5706
  });
6656
5707
  return;
6657
5708
  }
6658
- 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);
6659
- if (!selection) {
6660
- if (console.warn(`Unable to handle event ${event.type} due to missing selection`), !defaultAction)
6661
- return;
6662
- enqueue.raise({
6663
- type: "behavior action intends",
6664
- editor: event.editor,
6665
- actionIntends: [defaultAction]
6666
- });
6667
- return;
6668
- }
6669
- const editorContext = {
5709
+ 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 = {
6670
5710
  keyGenerator: context.keyGenerator,
6671
5711
  schema: context.schema,
6672
5712
  selection,
@@ -6680,7 +5720,10 @@ const editorMachine = setup({
6680
5720
  });
6681
5721
  if (!shouldRun)
6682
5722
  continue;
6683
- const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet(shouldRun));
5723
+ const actionIntendSets = eventBehavior.actions.map((actionSet) => actionSet({
5724
+ context: editorContext,
5725
+ event: event.behaviorEvent
5726
+ }, shouldRun));
6684
5727
  for (const actionIntends of actionIntendSets)
6685
5728
  behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
6686
5729
  type: "behavior action intends",
@@ -6714,7 +5757,7 @@ const editorMachine = setup({
6714
5757
  keyGenerator: input.keyGenerator,
6715
5758
  pendingEvents: [],
6716
5759
  schema: input.schema,
6717
- selection: void 0,
5760
+ selection: null,
6718
5761
  readOnly: (_b = input.readOnly) != null ? _b : !1,
6719
5762
  maxBlocks: input.maxBlocks,
6720
5763
  value: input.value
@@ -6822,10 +5865,7 @@ const editorMachine = setup({
6822
5865
  actions: [assign({
6823
5866
  selection: ({
6824
5867
  event
6825
- }) => {
6826
- var _a;
6827
- return (_a = event.selection) != null ? _a : void 0;
6828
- }
5868
+ }) => event.selection
6829
5869
  }), emit(({
6830
5870
  event
6831
5871
  }) => event)]
@@ -6991,28 +6031,10 @@ function createEditor(config) {
6991
6031
  const editorActor = createActor(editorMachine, {
6992
6032
  input: editorConfigToMachineInput(config)
6993
6033
  });
6994
- editorActor.start();
6995
- const slateEditor = createSlateEditor({
6996
- editorActor
6997
- }), editable = createEditableAPI(slateEditor.instance, editorActor);
6998
- return {
6999
- send: (event) => {
7000
- editorActor.send(event);
7001
- },
7002
- on: (event, listener) => editorActor.on(
7003
- event,
7004
- // @ts-expect-error
7005
- listener
7006
- ),
7007
- _internal: {
7008
- editable,
7009
- editorActor,
7010
- slateEditor
7011
- }
7012
- };
6034
+ return editorActor.start(), createEditorFromActor(editorActor);
7013
6035
  }
7014
6036
  function useCreateEditor(config) {
7015
- const $ = c(18);
6037
+ const $ = c(6);
7016
6038
  let t0;
7017
6039
  $[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
7018
6040
  let t1;
@@ -7020,27 +6042,8 @@ function useCreateEditor(config) {
7020
6042
  input: t0
7021
6043
  }, $[2] = t0, $[3] = t1) : t1 = $[3];
7022
6044
  const editorActor = useActorRef(editorMachine, t1);
7023
- let t2, slateEditor, t3;
7024
- $[4] !== editorActor ? (slateEditor = createSlateEditor({
7025
- editorActor
7026
- }), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
7027
- const editable = t3;
7028
- let t4, t5;
7029
- $[7] !== editorActor ? (t4 = (event) => {
7030
- editorActor.send(event);
7031
- }, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
7032
- let t6;
7033
- $[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
7034
- editable,
7035
- editorActor,
7036
- slateEditor
7037
- }, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
7038
- let t7;
7039
- return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
7040
- send: t4,
7041
- on: t5,
7042
- _internal: t6
7043
- }, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
6045
+ let t2, t3;
6046
+ return $[4] !== editorActor ? (t3 = createEditorFromActor(editorActor), $[4] = editorActor, $[5] = t3) : t3 = $[5], t2 = t3, t2;
7044
6047
  }
7045
6048
  function editorConfigToMachineInput(config) {
7046
6049
  var _a;
@@ -7049,10 +6052,30 @@ function editorConfigToMachineInput(config) {
7049
6052
  keyGenerator: (_a = config.keyGenerator) != null ? _a : defaultKeyGenerator,
7050
6053
  maxBlocks: config.maxBlocks,
7051
6054
  readOnly: config.readOnly,
7052
- schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
6055
+ schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : createEditorSchema(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
7053
6056
  value: config.initialValue
7054
6057
  };
7055
6058
  }
6059
+ function createEditorFromActor(editorActor) {
6060
+ const slateEditor = createSlateEditor({
6061
+ editorActor
6062
+ }), editable = createEditableAPI(slateEditor.instance, editorActor);
6063
+ return {
6064
+ send: (event) => {
6065
+ editorActor.send(event);
6066
+ },
6067
+ on: (event, listener) => editorActor.on(
6068
+ event,
6069
+ // @ts-expect-error
6070
+ listener
6071
+ ),
6072
+ _internal: {
6073
+ editable,
6074
+ editorActor,
6075
+ slateEditor
6076
+ }
6077
+ };
6078
+ }
7056
6079
  const EditorActorContext = createContext({}), PortableTextEditorSelectionContext = createContext(null), usePortableTextEditorSelection = () => {
7057
6080
  const selection = useContext(PortableTextEditorSelectionContext);
7058
6081
  if (selection === void 0)
@@ -7108,7 +6131,7 @@ class PortableTextEditor extends Component {
7108
6131
  }), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor._internal.editable;
7109
6132
  }
7110
6133
  componentDidUpdate(prevProps) {
7111
- !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({
6134
+ !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({
7112
6135
  type: "update schema",
7113
6136
  schema: this.schemaTypes
7114
6137
  })), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
@@ -8144,12 +7167,6 @@ export {
8144
7167
  EditorProvider,
8145
7168
  PortableTextEditable,
8146
7169
  PortableTextEditor,
8147
- coreBehavior,
8148
- coreBehaviors,
8149
- createCodeEditorBehaviors,
8150
- createLinkBehaviors,
8151
- createMarkdownBehaviors,
8152
- defineBehavior,
8153
7170
  defineSchema,
8154
7171
  editorMachine,
8155
7172
  defaultKeyGenerator as keyGenerator,