@portabletext/editor 1.48.9 → 1.48.11

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 (80) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +879 -169
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
  4. package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
  5. package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
  6. package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
  7. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +464 -19
  8. package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
  9. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +9 -1
  10. package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
  11. package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
  12. package/lib/_chunks-es/editor-provider.js +773 -65
  13. package/lib/_chunks-es/editor-provider.js.map +1 -1
  14. package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -1
  15. package/lib/_chunks-es/selector.get-text-before.js +1 -1
  16. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +448 -3
  17. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
  18. package/lib/_chunks-es/util.selection-point-to-block-offset.js +9 -1
  19. package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
  20. package/lib/_chunks-es/util.slice-blocks.js +2 -2
  21. package/lib/behaviors/index.cjs +27 -377
  22. package/lib/behaviors/index.cjs.map +1 -1
  23. package/lib/behaviors/index.d.cts +3696 -13915
  24. package/lib/behaviors/index.d.ts +3696 -13915
  25. package/lib/behaviors/index.js +22 -377
  26. package/lib/behaviors/index.js.map +1 -1
  27. package/lib/index.cjs +17 -17
  28. package/lib/index.cjs.map +1 -1
  29. package/lib/index.d.cts +3008 -394
  30. package/lib/index.d.ts +3008 -394
  31. package/lib/index.js +4 -5
  32. package/lib/index.js.map +1 -1
  33. package/lib/plugins/index.cjs +347 -30
  34. package/lib/plugins/index.cjs.map +1 -1
  35. package/lib/plugins/index.d.cts +3008 -395
  36. package/lib/plugins/index.d.ts +3008 -395
  37. package/lib/plugins/index.js +324 -8
  38. package/lib/plugins/index.js.map +1 -1
  39. package/lib/selectors/index.cjs +29 -29
  40. package/lib/selectors/index.cjs.map +1 -1
  41. package/lib/selectors/index.d.cts +3007 -387
  42. package/lib/selectors/index.d.ts +3007 -387
  43. package/lib/selectors/index.js +2 -3
  44. package/lib/selectors/index.js.map +1 -1
  45. package/lib/utils/index.cjs +5 -5
  46. package/lib/utils/index.cjs.map +1 -1
  47. package/lib/utils/index.d.cts +3008 -389
  48. package/lib/utils/index.d.ts +3008 -389
  49. package/lib/utils/index.js +2 -3
  50. package/lib/utils/index.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/behaviors/behavior.emoji-picker.ts +0 -6
  53. package/src/behaviors/behavior.markdown.ts +0 -48
  54. package/src/behaviors/index.ts +0 -15
  55. package/src/editor/create-editor.ts +0 -3
  56. package/src/editor/editor-machine.ts +105 -52
  57. package/src/editor/sync-machine.ts +10 -4
  58. package/src/internal-utils/__tests__/operationToPatches.test.ts +0 -2
  59. package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -2
  60. package/src/plugins/plugin.core.tsx +1 -1
  61. package/lib/_chunks-cjs/behavior.core.cjs +0 -700
  62. package/lib/_chunks-cjs/behavior.core.cjs.map +0 -1
  63. package/lib/_chunks-cjs/behavior.markdown.cjs +0 -321
  64. package/lib/_chunks-cjs/behavior.markdown.cjs.map +0 -1
  65. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -449
  66. package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +0 -1
  67. package/lib/_chunks-cjs/util.get-selection-start-point.cjs +0 -10
  68. package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +0 -1
  69. package/lib/_chunks-es/behavior.core.js +0 -703
  70. package/lib/_chunks-es/behavior.core.js.map +0 -1
  71. package/lib/_chunks-es/behavior.markdown.js +0 -325
  72. package/lib/_chunks-es/behavior.markdown.js.map +0 -1
  73. package/lib/_chunks-es/selector.is-overlapping-selection.js +0 -451
  74. package/lib/_chunks-es/selector.is-overlapping-selection.js.map +0 -1
  75. package/lib/_chunks-es/util.get-selection-start-point.js +0 -11
  76. package/lib/_chunks-es/util.get-selection-start-point.js.map +0 -1
  77. package/src/behaviors/behavior.code-editor.ts +0 -77
  78. package/src/behaviors/behavior.links.ts +0 -84
  79. package/src/internal-utils/looks-like-url.test.ts +0 -19
  80. package/src/internal-utils/looks-like-url.ts +0 -15
@@ -1,700 +0,0 @@
1
- "use strict";
2
- var selector_isOverlappingSelection = require("./selector.is-overlapping-selection.cjs"), util_sliceBlocks = require("./util.slice-blocks.cjs"), util_getSelectionStartPoint = require("./util.get-selection-start-point.cjs");
3
- function execute(event) {
4
- return {
5
- type: "execute",
6
- event
7
- };
8
- }
9
- function forward(event) {
10
- return {
11
- type: "forward",
12
- event
13
- };
14
- }
15
- function raise(event) {
16
- return {
17
- type: "raise",
18
- event
19
- };
20
- }
21
- function effect(effect2) {
22
- return {
23
- type: "effect",
24
- effect: effect2
25
- };
26
- }
27
- function defineBehavior(behavior) {
28
- return behavior;
29
- }
30
- const addAnnotationOnCollapsedSelection = {
31
- on: "annotation.add",
32
- guard: ({
33
- snapshot
34
- }) => {
35
- if (!selector_isOverlappingSelection.isSelectionCollapsed(snapshot))
36
- return !1;
37
- const caretWordSelection = selector_isOverlappingSelection.getCaretWordSelection(snapshot);
38
- return !caretWordSelection || !selector_isOverlappingSelection.isSelectionExpanded({
39
- context: {
40
- ...snapshot.context,
41
- selection: caretWordSelection
42
- }
43
- }) ? !1 : {
44
- caretWordSelection
45
- };
46
- },
47
- actions: [({
48
- event
49
- }, {
50
- caretWordSelection
51
- }) => [raise({
52
- type: "select",
53
- at: caretWordSelection
54
- }), raise({
55
- type: "annotation.add",
56
- annotation: event.annotation
57
- })]]
58
- }, coreAnnotationBehaviors = {
59
- addAnnotationOnCollapsedSelection
60
- }, IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
61
- alt: "altKey",
62
- control: "ctrlKey",
63
- meta: "metaKey",
64
- shift: "shiftKey"
65
- }, aliases = {
66
- add: "+",
67
- break: "pause",
68
- cmd: "meta",
69
- command: "meta",
70
- ctl: "control",
71
- ctrl: "control",
72
- del: "delete",
73
- down: "arrowdown",
74
- esc: "escape",
75
- ins: "insert",
76
- left: "arrowleft",
77
- mod: IS_MAC ? "meta" : "control",
78
- opt: "alt",
79
- option: "alt",
80
- return: "enter",
81
- right: "arrowright",
82
- space: " ",
83
- spacebar: " ",
84
- up: "arrowup",
85
- win: "meta",
86
- windows: "meta"
87
- }, keyCodes = {
88
- backspace: 8,
89
- tab: 9,
90
- enter: 13,
91
- shift: 16,
92
- control: 17,
93
- alt: 18,
94
- pause: 19,
95
- capslock: 20,
96
- escape: 27,
97
- " ": 32,
98
- pageup: 33,
99
- pagedown: 34,
100
- end: 35,
101
- home: 36,
102
- arrowleft: 37,
103
- arrowup: 38,
104
- arrowright: 39,
105
- arrowdown: 40,
106
- insert: 45,
107
- delete: 46,
108
- meta: 91,
109
- numlock: 144,
110
- scrolllock: 145,
111
- ";": 186,
112
- "=": 187,
113
- ",": 188,
114
- "-": 189,
115
- ".": 190,
116
- "/": 191,
117
- "`": 192,
118
- "[": 219,
119
- "\\": 220,
120
- "]": 221,
121
- "'": 222,
122
- f1: 112,
123
- f2: 113,
124
- f3: 114,
125
- f4: 115,
126
- f5: 116,
127
- f6: 117,
128
- f7: 118,
129
- f8: 119,
130
- f9: 120,
131
- f10: 121,
132
- f11: 122,
133
- f12: 123,
134
- f13: 124,
135
- f14: 125,
136
- f15: 126,
137
- f16: 127,
138
- f17: 128,
139
- f18: 129,
140
- f19: 130,
141
- f20: 131
142
- };
143
- function isHotkey(hotkey, event) {
144
- return compareHotkey(parseHotkey(hotkey), event);
145
- }
146
- function parseHotkey(hotkey) {
147
- const parsedHotkey = {
148
- altKey: !1,
149
- ctrlKey: !1,
150
- metaKey: !1,
151
- shiftKey: !1
152
- }, hotkeySegments = hotkey.replace("++", "+add").split("+");
153
- for (const rawHotkeySegment of hotkeySegments) {
154
- 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];
155
- if (hotkeySegment.length > 1 && modifier === void 0 && alias === void 0 && code === void 0)
156
- throw new TypeError(`Unknown modifier: "${hotkeySegment}"`);
157
- (hotkeySegments.length === 1 || modifier === void 0) && (parsedHotkey.key = keyName, parsedHotkey.keyCode = toKeyCode(hotkeySegment)), modifier !== void 0 && (parsedHotkey[modifier] = optional ? null : !0);
158
- }
159
- return parsedHotkey;
160
- }
161
- function compareHotkey(parsedHotkey, event) {
162
- 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;
163
- }
164
- function toKeyCode(name) {
165
- const keyName = toKeyName(name);
166
- return keyCodes[keyName] ?? keyName.toUpperCase().charCodeAt(0);
167
- }
168
- function toKeyName(name) {
169
- const keyName = name.toLowerCase();
170
- return aliases[keyName] ?? keyName;
171
- }
172
- const arrowDownOnLonelyBlockObject = {
173
- on: "keyboard.keydown",
174
- guard: ({
175
- snapshot,
176
- event
177
- }) => {
178
- if (!isHotkey("ArrowDown", event.originEvent) || !selector_isOverlappingSelection.isSelectionCollapsed(snapshot))
179
- return !1;
180
- const focusBlockObject = selector_isOverlappingSelection.getFocusBlockObject(snapshot), nextBlock = selector_isOverlappingSelection.getNextBlock(snapshot);
181
- return focusBlockObject && !nextBlock;
182
- },
183
- actions: [({
184
- snapshot
185
- }) => [raise({
186
- type: "insert.block",
187
- block: {
188
- _type: snapshot.context.schema.block.name
189
- },
190
- placement: "after"
191
- })]]
192
- }, arrowUpOnLonelyBlockObject = {
193
- on: "keyboard.keydown",
194
- guard: ({
195
- snapshot,
196
- event
197
- }) => {
198
- if (!isHotkey("ArrowUp", event.originEvent) || !selector_isOverlappingSelection.isSelectionCollapsed(snapshot))
199
- return !1;
200
- const focusBlockObject = selector_isOverlappingSelection.getFocusBlockObject(snapshot), previousBlock = selector_isOverlappingSelection.getPreviousBlock(snapshot);
201
- return focusBlockObject && !previousBlock;
202
- },
203
- actions: [({
204
- snapshot
205
- }) => [raise({
206
- type: "insert.block",
207
- block: {
208
- _type: snapshot.context.schema.block.name
209
- },
210
- placement: "before"
211
- })]]
212
- }, breakingBlockObject = {
213
- on: "insert.break",
214
- guard: ({
215
- snapshot
216
- }) => {
217
- const focusBlockObject = selector_isOverlappingSelection.getFocusBlockObject(snapshot);
218
- return selector_isOverlappingSelection.isSelectionCollapsed(snapshot) && focusBlockObject !== void 0;
219
- },
220
- actions: [({
221
- snapshot
222
- }) => [raise({
223
- type: "insert.block",
224
- block: {
225
- _type: snapshot.context.schema.block.name
226
- },
227
- placement: "after"
228
- })]]
229
- }, clickingAboveLonelyBlockObject = {
230
- on: "mouse.click",
231
- guard: ({
232
- snapshot,
233
- event
234
- }) => {
235
- if (snapshot.context.readOnly || snapshot.context.selection && !selector_isOverlappingSelection.isSelectionCollapsed(snapshot))
236
- return !1;
237
- const focusBlockObject = selector_isOverlappingSelection.getFocusBlockObject({
238
- context: {
239
- ...snapshot.context,
240
- selection: event.position.selection
241
- }
242
- }), previousBlock = selector_isOverlappingSelection.getPreviousBlock({
243
- context: {
244
- ...snapshot.context,
245
- selection: event.position.selection
246
- }
247
- });
248
- return event.position.isEditor && event.position.block === "start" && focusBlockObject && !previousBlock;
249
- },
250
- actions: [({
251
- snapshot,
252
- event
253
- }) => [raise({
254
- type: "select",
255
- at: event.position.selection
256
- }), raise({
257
- type: "insert.block",
258
- block: {
259
- _type: snapshot.context.schema.block.name
260
- },
261
- placement: "before",
262
- select: "start"
263
- })]]
264
- }, clickingBelowLonelyBlockObject = {
265
- on: "mouse.click",
266
- guard: ({
267
- snapshot,
268
- event
269
- }) => {
270
- if (snapshot.context.readOnly || snapshot.context.selection && !selector_isOverlappingSelection.isSelectionCollapsed(snapshot))
271
- return !1;
272
- const focusBlockObject = selector_isOverlappingSelection.getFocusBlockObject({
273
- context: {
274
- ...snapshot.context,
275
- selection: event.position.selection
276
- }
277
- }), nextBlock = selector_isOverlappingSelection.getNextBlock({
278
- context: {
279
- ...snapshot.context,
280
- selection: event.position.selection
281
- }
282
- });
283
- return event.position.isEditor && event.position.block === "end" && focusBlockObject && !nextBlock;
284
- },
285
- actions: [({
286
- snapshot,
287
- event
288
- }) => [raise({
289
- type: "select",
290
- at: event.position.selection
291
- }), raise({
292
- type: "insert.block",
293
- block: {
294
- _type: snapshot.context.schema.block.name
295
- },
296
- placement: "after",
297
- select: "start"
298
- })]]
299
- }, deletingEmptyTextBlockAfterBlockObject = {
300
- on: "delete.backward",
301
- guard: ({
302
- snapshot
303
- }) => {
304
- const focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot), previousBlock = selector_isOverlappingSelection.getPreviousBlock(snapshot);
305
- return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, previousBlock.node) ? {
306
- focusTextBlock,
307
- previousBlock
308
- } : !1;
309
- },
310
- actions: [(_, {
311
- focusTextBlock,
312
- previousBlock
313
- }) => [raise({
314
- type: "delete.block",
315
- at: focusTextBlock.path
316
- }), raise({
317
- type: "select",
318
- at: {
319
- anchor: {
320
- path: previousBlock.path,
321
- offset: 0
322
- },
323
- focus: {
324
- path: previousBlock.path,
325
- offset: 0
326
- }
327
- }
328
- })]]
329
- }, deletingEmptyTextBlockBeforeBlockObject = {
330
- on: "delete.forward",
331
- guard: ({
332
- snapshot
333
- }) => {
334
- const focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot), nextBlock = selector_isOverlappingSelection.getNextBlock(snapshot);
335
- return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusTextBlock.node) && !util_sliceBlocks.isTextBlock(snapshot.context, nextBlock.node) ? {
336
- focusTextBlock,
337
- nextBlock
338
- } : !1;
339
- },
340
- actions: [(_, {
341
- focusTextBlock,
342
- nextBlock
343
- }) => [raise({
344
- type: "delete.block",
345
- at: focusTextBlock.path
346
- }), raise({
347
- type: "select",
348
- at: {
349
- anchor: {
350
- path: nextBlock.path,
351
- offset: 0
352
- },
353
- focus: {
354
- path: nextBlock.path,
355
- offset: 0
356
- }
357
- }
358
- })]]
359
- }, coreBlockObjectBehaviors = {
360
- arrowDownOnLonelyBlockObject,
361
- arrowUpOnLonelyBlockObject,
362
- breakingBlockObject,
363
- clickingAboveLonelyBlockObject,
364
- clickingBelowLonelyBlockObject,
365
- deletingEmptyTextBlockAfterBlockObject,
366
- deletingEmptyTextBlockBeforeBlockObject
367
- }, coreDecoratorBehaviors = {
368
- strongShortcut: {
369
- on: "keyboard.keydown",
370
- guard: ({
371
- snapshot,
372
- event
373
- }) => isHotkey("mod+b", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "strong"),
374
- actions: [() => [raise({
375
- type: "decorator.toggle",
376
- decorator: "strong"
377
- })]]
378
- },
379
- emShortcut: {
380
- on: "keyboard.keydown",
381
- guard: ({
382
- snapshot,
383
- event
384
- }) => isHotkey("mod+i", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "em"),
385
- actions: [() => [raise({
386
- type: "decorator.toggle",
387
- decorator: "em"
388
- })]]
389
- },
390
- underlineShortcut: {
391
- on: "keyboard.keydown",
392
- guard: ({
393
- snapshot,
394
- event
395
- }) => isHotkey("mod+u", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "underline"),
396
- actions: [() => [raise({
397
- type: "decorator.toggle",
398
- decorator: "underline"
399
- })]]
400
- },
401
- codeShortcut: {
402
- on: "keyboard.keydown",
403
- guard: ({
404
- snapshot,
405
- event
406
- }) => isHotkey("mod+'", event.originEvent) && snapshot.context.schema.decorators.some((decorator) => decorator.name === "code"),
407
- actions: [() => [raise({
408
- type: "decorator.toggle",
409
- decorator: "code"
410
- })]]
411
- }
412
- }, coreDndBehaviors = [
413
- /**
414
- * When dragging over the drag origin, we don't want to show the caret in the
415
- * text.
416
- */
417
- {
418
- on: "drag.dragover",
419
- guard: ({
420
- snapshot,
421
- event
422
- }) => {
423
- const dragOrigin = snapshot.beta.internalDrag?.origin;
424
- return dragOrigin ? selector_isOverlappingSelection.isOverlappingSelection(event.position.selection)({
425
- ...snapshot,
426
- context: {
427
- ...snapshot.context,
428
- selection: dragOrigin.selection
429
- }
430
- }) : !1;
431
- },
432
- actions: []
433
- }
434
- ], breakingAtTheEndOfTextBlock = {
435
- on: "insert.break",
436
- guard: ({
437
- snapshot
438
- }) => {
439
- const focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
440
- if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
441
- return !1;
442
- const atTheEndOfBlock = selector_isOverlappingSelection.isAtTheEndOfBlock(focusTextBlock)(snapshot), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
443
- return atTheEndOfBlock ? {
444
- focusListItem,
445
- focusLevel
446
- } : !1;
447
- },
448
- actions: [({
449
- snapshot
450
- }, {
451
- focusListItem,
452
- focusLevel
453
- }) => [raise({
454
- type: "insert.block",
455
- block: {
456
- _type: snapshot.context.schema.block.name,
457
- children: [{
458
- _type: snapshot.context.schema.span.name,
459
- text: "",
460
- marks: []
461
- }],
462
- markDefs: [],
463
- listItem: focusListItem,
464
- level: focusLevel,
465
- style: snapshot.context.schema.styles[0]?.name
466
- },
467
- placement: "after"
468
- })]]
469
- }, breakingAtTheStartOfTextBlock = {
470
- on: "insert.break",
471
- guard: ({
472
- snapshot
473
- }) => {
474
- const focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot);
475
- if (!snapshot.context.selection || !focusTextBlock || !selectionCollapsed)
476
- return !1;
477
- const focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot), focusDecorators = focusSpan?.node.marks?.filter((mark) => snapshot.context.schema.decorators.some((decorator) => decorator.name === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !snapshot.context.schema.decorators.some((decorator) => decorator.name === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
478
- return selector_isOverlappingSelection.isAtTheStartOfBlock(focusTextBlock)(snapshot) ? {
479
- focusAnnotations,
480
- focusDecorators,
481
- focusListItem,
482
- focusLevel
483
- } : !1;
484
- },
485
- actions: [({
486
- snapshot
487
- }, {
488
- focusAnnotations,
489
- focusDecorators,
490
- focusListItem,
491
- focusLevel
492
- }) => [raise({
493
- type: "insert.block",
494
- block: {
495
- _type: snapshot.context.schema.block.name,
496
- children: [{
497
- _type: snapshot.context.schema.span.name,
498
- marks: focusAnnotations.length === 0 ? focusDecorators : [],
499
- text: ""
500
- }],
501
- listItem: focusListItem,
502
- level: focusLevel,
503
- style: snapshot.context.schema.styles[0]?.name
504
- },
505
- placement: "before",
506
- select: "none"
507
- })]]
508
- }, breakingEntireDocument = {
509
- on: "insert.break",
510
- guard: ({
511
- snapshot
512
- }) => {
513
- if (!snapshot.context.selection || !selector_isOverlappingSelection.isSelectionExpanded(snapshot))
514
- return !1;
515
- const firstBlock = selector_isOverlappingSelection.getFirstBlock(snapshot), lastBlock = selector_isOverlappingSelection.getLastBlock(snapshot);
516
- if (!firstBlock || !lastBlock)
517
- return !1;
518
- const firstBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
519
- context: snapshot.context,
520
- block: firstBlock
521
- }), selectionStartPoint = util_getSelectionStartPoint.getSelectionStartPoint(snapshot.context.selection), lastBlockEndPoint = util_sliceBlocks.getBlockEndPoint({
522
- context: snapshot.context,
523
- block: lastBlock
524
- }), selectionEndPoint = util_getSelectionStartPoint.getSelectionEndPoint(snapshot.context.selection);
525
- return util_sliceBlocks.isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) && util_sliceBlocks.isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint) ? {
526
- selection: snapshot.context.selection
527
- } : !1;
528
- },
529
- actions: [(_, {
530
- selection
531
- }) => [raise({
532
- type: "delete",
533
- at: selection
534
- })]]
535
- }, breakingEntireBlocks = {
536
- on: "insert.break",
537
- guard: ({
538
- snapshot
539
- }) => {
540
- if (!snapshot.context.selection || !selector_isOverlappingSelection.isSelectionExpanded(snapshot))
541
- return !1;
542
- const selectedBlocks = selector_isOverlappingSelection.getSelectedBlocks(snapshot), selectionStartBlock = selector_isOverlappingSelection.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isOverlappingSelection.getSelectionEndBlock(snapshot);
543
- if (!selectionStartBlock || !selectionEndBlock)
544
- return !1;
545
- const startBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
546
- context: snapshot.context,
547
- block: selectionStartBlock
548
- }), selectionStartPoint = util_getSelectionStartPoint.getSelectionStartPoint(snapshot.context.selection), endBlockEndPoint = util_sliceBlocks.getBlockEndPoint({
549
- context: snapshot.context,
550
- block: selectionEndBlock
551
- }), selectionEndPoint = util_getSelectionStartPoint.getSelectionEndPoint(snapshot.context.selection);
552
- return util_sliceBlocks.isEqualSelectionPoints(selectionStartPoint, startBlockStartPoint) && util_sliceBlocks.isEqualSelectionPoints(selectionEndPoint, endBlockEndPoint) ? {
553
- selectedBlocks
554
- } : !1;
555
- },
556
- actions: [({
557
- snapshot
558
- }, {
559
- selectedBlocks
560
- }) => [raise({
561
- type: "insert.block",
562
- block: {
563
- _type: snapshot.context.schema.block.name,
564
- children: [{
565
- _type: snapshot.context.schema.span.name,
566
- text: "",
567
- marks: []
568
- }]
569
- },
570
- placement: "before",
571
- select: "start"
572
- }), ...selectedBlocks.map((block) => raise({
573
- type: "delete.block",
574
- at: block.path
575
- }))]]
576
- }, coreInsertBreakBehaviors = {
577
- breakingAtTheEndOfTextBlock,
578
- breakingAtTheStartOfTextBlock,
579
- breakingEntireDocument,
580
- breakingEntireBlocks
581
- }, MAX_LIST_LEVEL = 10, clearListOnBackspace = {
582
- on: "delete.backward",
583
- guard: ({
584
- snapshot
585
- }) => {
586
- const selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot), focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot);
587
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
588
- focusTextBlock
589
- } : !1;
590
- },
591
- actions: [(_, {
592
- focusTextBlock
593
- }) => [raise({
594
- type: "block.unset",
595
- props: ["listItem", "level"],
596
- at: focusTextBlock.path
597
- })]]
598
- }, unindentListOnBackspace = {
599
- on: "delete.backward",
600
- guard: ({
601
- snapshot
602
- }) => {
603
- const selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot), focusTextBlock = selector_isOverlappingSelection.getFocusTextBlock(snapshot), focusSpan = selector_isOverlappingSelection.getFocusSpan(snapshot);
604
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
605
- focusTextBlock,
606
- level: focusTextBlock.node.level - 1
607
- } : !1;
608
- },
609
- actions: [(_, {
610
- focusTextBlock,
611
- level
612
- }) => [raise({
613
- type: "block.set",
614
- props: {
615
- level
616
- },
617
- at: focusTextBlock.path
618
- })]]
619
- }, clearListOnEnter = {
620
- on: "insert.break",
621
- guard: ({
622
- snapshot
623
- }) => {
624
- const selectionCollapsed = selector_isOverlappingSelection.isSelectionCollapsed(snapshot), focusListBlock = selector_isOverlappingSelection.getFocusListBlock(snapshot);
625
- return !selectionCollapsed || !focusListBlock || !util_sliceBlocks.isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
626
- focusListBlock
627
- };
628
- },
629
- actions: [(_, {
630
- focusListBlock
631
- }) => [raise({
632
- type: "block.unset",
633
- props: ["listItem", "level"],
634
- at: focusListBlock.path
635
- })]]
636
- }, indentListOnTab = {
637
- on: "keyboard.keydown",
638
- guard: ({
639
- snapshot,
640
- event
641
- }) => {
642
- if (!isHotkey("Tab", event.originEvent))
643
- return !1;
644
- const selectedBlocks = selector_isOverlappingSelection.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
645
- node: block.node,
646
- path: block.path
647
- }] : []);
648
- return selectedListBlocks.length === selectedBlocks.length ? {
649
- selectedListBlocks
650
- } : !1;
651
- },
652
- actions: [(_, {
653
- selectedListBlocks
654
- }) => selectedListBlocks.map((selectedListBlock) => raise({
655
- type: "block.set",
656
- props: {
657
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1))
658
- },
659
- at: selectedListBlock.path
660
- }))]
661
- }, unindentListOnShiftTab = {
662
- on: "keyboard.keydown",
663
- guard: ({
664
- snapshot,
665
- event
666
- }) => {
667
- if (!isHotkey("Shift+Tab", event.originEvent))
668
- return !1;
669
- const selectedBlocks = selector_isOverlappingSelection.getSelectedBlocks(snapshot), selectedListBlocks = selectedBlocks.flatMap((block) => util_sliceBlocks.isListBlock(snapshot.context, block.node) ? [{
670
- node: block.node,
671
- path: block.path
672
- }] : []);
673
- return selectedListBlocks.length === selectedBlocks.length ? {
674
- selectedListBlocks
675
- } : !1;
676
- },
677
- actions: [(_, {
678
- selectedListBlocks
679
- }) => selectedListBlocks.map((selectedListBlock) => raise({
680
- type: "block.set",
681
- props: {
682
- level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1))
683
- },
684
- at: selectedListBlock.path
685
- }))]
686
- }, coreListBehaviors = {
687
- clearListOnBackspace,
688
- unindentListOnBackspace,
689
- clearListOnEnter,
690
- indentListOnTab,
691
- unindentListOnShiftTab
692
- }, coreBehaviors = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks];
693
- exports.coreBehaviors = coreBehaviors;
694
- exports.defineBehavior = defineBehavior;
695
- exports.effect = effect;
696
- exports.execute = execute;
697
- exports.forward = forward;
698
- exports.isHotkey = isHotkey;
699
- exports.raise = raise;
700
- //# sourceMappingURL=behavior.core.cjs.map