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