@portabletext/editor 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.core.cjs +283 -64
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +8 -8
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +412 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs +2 -2
- package/lib/_chunks-cjs/util.is-empty-text-block.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs +46 -0
- package/lib/_chunks-cjs/util.is-equal-selection-points.cjs.map +1 -0
- package/lib/_chunks-cjs/util.reverse-selection.cjs +0 -16
- package/lib/_chunks-cjs/util.reverse-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +259 -40
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +2 -2
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +414 -0
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/util.is-empty-text-block.js +1 -1
- package/lib/_chunks-es/util.is-equal-selection-points.js +47 -0
- package/lib/_chunks-es/util.is-equal-selection-points.js.map +1 -0
- package/lib/_chunks-es/util.reverse-selection.js +0 -16
- package/lib/_chunks-es/util.reverse-selection.js.map +1 -1
- package/lib/behaviors/index.cjs +27 -27
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +2208 -171
- package/lib/behaviors/index.d.ts +2208 -171
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +306 -298
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +10499 -521
- package/lib/index.d.ts +10499 -521
- package/lib/index.js +302 -294
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +26 -171
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +16 -0
- package/lib/selectors/index.d.ts +16 -0
- package/lib/selectors/index.js +5 -151
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -3
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +19 -0
- package/lib/utils/index.d.ts +19 -0
- package/lib/utils/index.js +4 -2
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action-utils.insert-block.ts +3 -3
- package/src/behavior-actions/behavior.action.block.set.ts +23 -0
- package/src/behavior-actions/behavior.action.block.unset.ts +21 -0
- package/src/behavior-actions/behavior.action.insert-break.ts +2 -69
- package/src/behavior-actions/behavior.action.insert.block.ts +29 -0
- package/src/behavior-actions/behavior.actions.ts +116 -96
- package/src/behaviors/behavior.core.annotations.ts +29 -0
- package/src/behaviors/behavior.core.block-objects.ts +13 -13
- package/src/behaviors/behavior.core.decorators.ts +19 -0
- package/src/behaviors/behavior.core.insert-break.ts +122 -0
- package/src/behaviors/behavior.core.lists.ts +57 -23
- package/src/behaviors/behavior.core.style.ts +19 -0
- package/src/behaviors/behavior.core.ts +18 -2
- package/src/behaviors/behavior.types.ts +103 -88
- package/src/converters/converter.json.ts +4 -4
- package/src/converters/converter.portable-text.deserialize.test.ts +1 -1
- package/src/converters/converter.portable-text.ts +4 -4
- package/src/converters/converter.text-html.deserialize.test.ts +1 -1
- package/src/converters/converter.text-html.serialize.test.ts +1 -1
- package/src/converters/converter.text-html.ts +4 -4
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +3 -3
- package/src/converters/{converter.ts → converter.types.ts} +6 -0
- package/src/editor/create-editor.ts +50 -7
- package/src/editor/editor-machine.ts +46 -3
- package/src/editor/editor-snapshot.ts +1 -1
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +41 -106
- package/src/selectors/index.ts +2 -0
- package/src/selectors/selector.is-at-the-end-of-block.ts +22 -0
- package/src/selectors/selector.is-at-the-start-of-block.ts +25 -0
- package/src/selectors/selector.is-selection-collapsed.ts +6 -2
- package/src/utils/index.ts +2 -0
- package/src/utils/util.get-block-end-point.ts +34 -0
- package/src/utils/util.is-equal-selection-points.ts +13 -0
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs +0 -231
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +0 -1
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs +0 -6
- package/lib/_chunks-cjs/util.is-keyed-segment.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js +0 -232
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +0 -1
- package/lib/_chunks-es/util.is-keyed-segment.js +0 -7
- package/lib/_chunks-es/util.is-keyed-segment.js.map +0 -1
- /package/src/converters/{converters.ts → converters.core.ts} +0 -0
|
@@ -1,7 +1,50 @@
|
|
|
1
|
+
import { isActiveAnnotation, getFocusBlockObject, getNextBlock, getPreviousBlock, isSelectionCollapsed, getFocusTextBlock, isActiveDecorator, isAtTheEndOfBlock, getFocusSpan, isAtTheStartOfBlock, isActiveListItem, getFocusListBlock, getSelectedBlocks, createGuards, isActiveStyle } from "./selector.is-at-the-start-of-block.js";
|
|
1
2
|
import { isPortableTextTextBlock } from "@sanity/types";
|
|
2
|
-
import { getFocusBlockObject, getNextBlock, getPreviousBlock, isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getFocusListBlock, getSelectedBlocks, createGuards } from "./selector.is-selection-collapsed.js";
|
|
3
3
|
import { isEmptyTextBlock } from "./util.is-empty-text-block.js";
|
|
4
|
-
|
|
4
|
+
function isCustomBehaviorEvent(event) {
|
|
5
|
+
return event.type.startsWith("custom.");
|
|
6
|
+
}
|
|
7
|
+
function raise(event) {
|
|
8
|
+
return {
|
|
9
|
+
type: "raise",
|
|
10
|
+
event
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function defineBehavior(behavior) {
|
|
14
|
+
return behavior;
|
|
15
|
+
}
|
|
16
|
+
const toggleAnnotationOff = {
|
|
17
|
+
on: "annotation.toggle",
|
|
18
|
+
guard: ({
|
|
19
|
+
context,
|
|
20
|
+
event
|
|
21
|
+
}) => isActiveAnnotation(event.annotation.name)({
|
|
22
|
+
context
|
|
23
|
+
}),
|
|
24
|
+
actions: [({
|
|
25
|
+
event
|
|
26
|
+
}) => [raise({
|
|
27
|
+
type: "annotation.remove",
|
|
28
|
+
annotation: event.annotation
|
|
29
|
+
})]]
|
|
30
|
+
}, toggleAnnotationOn = {
|
|
31
|
+
on: "annotation.toggle",
|
|
32
|
+
guard: ({
|
|
33
|
+
context,
|
|
34
|
+
event
|
|
35
|
+
}) => !isActiveAnnotation(event.annotation.name)({
|
|
36
|
+
context
|
|
37
|
+
}),
|
|
38
|
+
actions: [({
|
|
39
|
+
event
|
|
40
|
+
}) => [raise({
|
|
41
|
+
type: "annotation.add",
|
|
42
|
+
annotation: event.annotation
|
|
43
|
+
})]]
|
|
44
|
+
}, coreAnnotationBehaviors = {
|
|
45
|
+
toggleAnnotationOff,
|
|
46
|
+
toggleAnnotationOn
|
|
47
|
+
}, IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
5
48
|
alt: "altKey",
|
|
6
49
|
control: "ctrlKey",
|
|
7
50
|
meta: "metaKey",
|
|
@@ -113,18 +156,6 @@ function toKeyName(name) {
|
|
|
113
156
|
const keyName = name.toLowerCase();
|
|
114
157
|
return aliases[keyName] ?? keyName;
|
|
115
158
|
}
|
|
116
|
-
function isCustomBehaviorEvent(event) {
|
|
117
|
-
return event.type.startsWith("custom.");
|
|
118
|
-
}
|
|
119
|
-
function raise(event) {
|
|
120
|
-
return {
|
|
121
|
-
type: "raise",
|
|
122
|
-
event
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
function defineBehavior(behavior) {
|
|
126
|
-
return behavior;
|
|
127
|
-
}
|
|
128
159
|
const arrowDownOnLonelyBlockObject = {
|
|
129
160
|
on: "key.down",
|
|
130
161
|
guard: ({
|
|
@@ -138,10 +169,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
138
169
|
});
|
|
139
170
|
return isArrowDown && focusBlockObject && !nextBlock;
|
|
140
171
|
},
|
|
141
|
-
actions: [() => [{
|
|
172
|
+
actions: [() => [raise({
|
|
142
173
|
type: "insert.text block",
|
|
143
174
|
placement: "after"
|
|
144
|
-
}]]
|
|
175
|
+
})]]
|
|
145
176
|
}, arrowUpOnLonelyBlockObject = {
|
|
146
177
|
on: "key.down",
|
|
147
178
|
guard: ({
|
|
@@ -155,12 +186,12 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
155
186
|
});
|
|
156
187
|
return isArrowUp && focusBlockObject && !previousBlock;
|
|
157
188
|
},
|
|
158
|
-
actions: [() => [{
|
|
189
|
+
actions: [() => [raise({
|
|
159
190
|
type: "insert.text block",
|
|
160
191
|
placement: "before"
|
|
161
|
-
}, {
|
|
192
|
+
}), raise({
|
|
162
193
|
type: "select.previous block"
|
|
163
|
-
}]]
|
|
194
|
+
})]]
|
|
164
195
|
}, breakingBlockObject = {
|
|
165
196
|
on: "insert.break",
|
|
166
197
|
guard: ({
|
|
@@ -173,10 +204,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
173
204
|
context
|
|
174
205
|
}) && focusBlockObject !== void 0;
|
|
175
206
|
},
|
|
176
|
-
actions: [() => [{
|
|
207
|
+
actions: [() => [raise({
|
|
177
208
|
type: "insert.text block",
|
|
178
209
|
placement: "after"
|
|
179
|
-
}]]
|
|
210
|
+
})]]
|
|
180
211
|
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
181
212
|
on: "delete.backward",
|
|
182
213
|
guard: ({
|
|
@@ -197,10 +228,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
197
228
|
actions: [(_, {
|
|
198
229
|
focusTextBlock,
|
|
199
230
|
previousBlock
|
|
200
|
-
}) => [{
|
|
231
|
+
}) => [raise({
|
|
201
232
|
type: "delete.block",
|
|
202
233
|
blockPath: focusTextBlock.path
|
|
203
|
-
}, {
|
|
234
|
+
}), raise({
|
|
204
235
|
type: "select",
|
|
205
236
|
selection: {
|
|
206
237
|
anchor: {
|
|
@@ -212,7 +243,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
212
243
|
offset: 0
|
|
213
244
|
}
|
|
214
245
|
}
|
|
215
|
-
}]]
|
|
246
|
+
})]]
|
|
216
247
|
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
217
248
|
on: "delete.forward",
|
|
218
249
|
guard: ({
|
|
@@ -233,10 +264,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
233
264
|
actions: [(_, {
|
|
234
265
|
focusTextBlock,
|
|
235
266
|
nextBlock
|
|
236
|
-
}) => [{
|
|
267
|
+
}) => [raise({
|
|
237
268
|
type: "delete.block",
|
|
238
269
|
blockPath: focusTextBlock.path
|
|
239
|
-
}, {
|
|
270
|
+
}), raise({
|
|
240
271
|
type: "select",
|
|
241
272
|
selection: {
|
|
242
273
|
anchor: {
|
|
@@ -248,7 +279,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
248
279
|
offset: 0
|
|
249
280
|
}
|
|
250
281
|
}
|
|
251
|
-
}]]
|
|
282
|
+
})]]
|
|
252
283
|
}, coreBlockObjectBehaviors = {
|
|
253
284
|
arrowDownOnLonelyBlockObject,
|
|
254
285
|
arrowUpOnLonelyBlockObject,
|
|
@@ -256,6 +287,36 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
256
287
|
deletingEmptyTextBlockAfterBlockObject,
|
|
257
288
|
deletingEmptyTextBlockBeforeBlockObject
|
|
258
289
|
}, coreDecoratorBehaviors = {
|
|
290
|
+
toggleDecoratorOff: {
|
|
291
|
+
on: "decorator.toggle",
|
|
292
|
+
guard: ({
|
|
293
|
+
context,
|
|
294
|
+
event
|
|
295
|
+
}) => isActiveDecorator(event.decorator)({
|
|
296
|
+
context
|
|
297
|
+
}),
|
|
298
|
+
actions: [({
|
|
299
|
+
event
|
|
300
|
+
}) => [raise({
|
|
301
|
+
type: "decorator.remove",
|
|
302
|
+
decorator: event.decorator
|
|
303
|
+
})]]
|
|
304
|
+
},
|
|
305
|
+
toggleDecoratorOn: {
|
|
306
|
+
on: "decorator.toggle",
|
|
307
|
+
guard: ({
|
|
308
|
+
context,
|
|
309
|
+
event
|
|
310
|
+
}) => !isActiveDecorator(event.decorator)({
|
|
311
|
+
context
|
|
312
|
+
}),
|
|
313
|
+
actions: [({
|
|
314
|
+
event
|
|
315
|
+
}) => [raise({
|
|
316
|
+
type: "decorator.add",
|
|
317
|
+
decorator: event.decorator
|
|
318
|
+
})]]
|
|
319
|
+
},
|
|
259
320
|
strongShortcut: {
|
|
260
321
|
on: "key.down",
|
|
261
322
|
guard: ({
|
|
@@ -328,7 +389,129 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
328
389
|
...deserializeEvent,
|
|
329
390
|
dataTransfer: event.dataTransfer
|
|
330
391
|
})]]
|
|
331
|
-
},
|
|
392
|
+
}, atTheEndOfTextBlock = {
|
|
393
|
+
on: "insert.break",
|
|
394
|
+
guard: ({
|
|
395
|
+
context
|
|
396
|
+
}) => {
|
|
397
|
+
const focusTextBlock = getFocusTextBlock({
|
|
398
|
+
context
|
|
399
|
+
}), selectionCollapsed = isSelectionCollapsed({
|
|
400
|
+
context
|
|
401
|
+
});
|
|
402
|
+
if (!context.selection || !focusTextBlock || !selectionCollapsed)
|
|
403
|
+
return !1;
|
|
404
|
+
const atTheEndOfBlock = isAtTheEndOfBlock(focusTextBlock)({
|
|
405
|
+
context
|
|
406
|
+
}), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
407
|
+
return atTheEndOfBlock ? {
|
|
408
|
+
focusListItem,
|
|
409
|
+
focusLevel
|
|
410
|
+
} : !1;
|
|
411
|
+
},
|
|
412
|
+
actions: [({
|
|
413
|
+
context
|
|
414
|
+
}, {
|
|
415
|
+
focusListItem,
|
|
416
|
+
focusLevel
|
|
417
|
+
}) => [raise({
|
|
418
|
+
type: "insert.block",
|
|
419
|
+
block: {
|
|
420
|
+
_type: context.schema.block.name,
|
|
421
|
+
_key: context.keyGenerator(),
|
|
422
|
+
children: [{
|
|
423
|
+
_key: context.keyGenerator(),
|
|
424
|
+
_type: context.schema.span.name,
|
|
425
|
+
text: "",
|
|
426
|
+
marks: []
|
|
427
|
+
}],
|
|
428
|
+
markDefs: [],
|
|
429
|
+
listItem: focusListItem,
|
|
430
|
+
level: focusLevel,
|
|
431
|
+
style: context.schema.styles[0]?.value
|
|
432
|
+
},
|
|
433
|
+
placement: "after"
|
|
434
|
+
})]]
|
|
435
|
+
}, atTheStartOfTextBlock = {
|
|
436
|
+
on: "insert.break",
|
|
437
|
+
guard: ({
|
|
438
|
+
context
|
|
439
|
+
}) => {
|
|
440
|
+
const focusTextBlock = getFocusTextBlock({
|
|
441
|
+
context
|
|
442
|
+
}), selectionCollapsed = isSelectionCollapsed({
|
|
443
|
+
context
|
|
444
|
+
});
|
|
445
|
+
if (!context.selection || !focusTextBlock || !selectionCollapsed)
|
|
446
|
+
return !1;
|
|
447
|
+
const focusSpan = getFocusSpan({
|
|
448
|
+
context
|
|
449
|
+
}), focusDecorators = focusSpan?.node.marks?.filter((mark) => context.schema.decorators.some((decorator) => decorator.value === mark) ?? []), focusAnnotations = focusSpan?.node.marks?.filter((mark) => !context.schema.decorators.some((decorator) => decorator.value === mark)) ?? [], focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
450
|
+
return isAtTheStartOfBlock(focusTextBlock)({
|
|
451
|
+
context
|
|
452
|
+
}) ? {
|
|
453
|
+
focusAnnotations,
|
|
454
|
+
focusDecorators,
|
|
455
|
+
focusListItem,
|
|
456
|
+
focusLevel
|
|
457
|
+
} : !1;
|
|
458
|
+
},
|
|
459
|
+
actions: [({
|
|
460
|
+
context
|
|
461
|
+
}, {
|
|
462
|
+
focusAnnotations,
|
|
463
|
+
focusDecorators,
|
|
464
|
+
focusListItem,
|
|
465
|
+
focusLevel
|
|
466
|
+
}) => [raise({
|
|
467
|
+
type: "insert.block",
|
|
468
|
+
block: {
|
|
469
|
+
_key: context.keyGenerator(),
|
|
470
|
+
_type: context.schema.block.name,
|
|
471
|
+
children: [{
|
|
472
|
+
_key: context.keyGenerator(),
|
|
473
|
+
_type: context.schema.span.name,
|
|
474
|
+
marks: focusAnnotations.length === 0 ? focusDecorators : [],
|
|
475
|
+
text: ""
|
|
476
|
+
}],
|
|
477
|
+
listItem: focusListItem,
|
|
478
|
+
level: focusLevel,
|
|
479
|
+
style: context.schema.styles[0]?.value
|
|
480
|
+
},
|
|
481
|
+
placement: "before"
|
|
482
|
+
})]]
|
|
483
|
+
}, coreInsertBreakBehaviors = {
|
|
484
|
+
atTheEndOfTextBlock,
|
|
485
|
+
atTheStartOfTextBlock
|
|
486
|
+
}, MAX_LIST_LEVEL = 10, toggleListItemOff = {
|
|
487
|
+
on: "list item.toggle",
|
|
488
|
+
guard: ({
|
|
489
|
+
context,
|
|
490
|
+
event
|
|
491
|
+
}) => isActiveListItem(event.listItem)({
|
|
492
|
+
context
|
|
493
|
+
}),
|
|
494
|
+
actions: [({
|
|
495
|
+
event
|
|
496
|
+
}) => [raise({
|
|
497
|
+
type: "list item.remove",
|
|
498
|
+
listItem: event.listItem
|
|
499
|
+
})]]
|
|
500
|
+
}, toggleListItemOn = {
|
|
501
|
+
on: "list item.toggle",
|
|
502
|
+
guard: ({
|
|
503
|
+
context,
|
|
504
|
+
event
|
|
505
|
+
}) => !isActiveListItem(event.listItem)({
|
|
506
|
+
context
|
|
507
|
+
}),
|
|
508
|
+
actions: [({
|
|
509
|
+
event
|
|
510
|
+
}) => [raise({
|
|
511
|
+
type: "list item.add",
|
|
512
|
+
listItem: event.listItem
|
|
513
|
+
})]]
|
|
514
|
+
}, clearListOnBackspace = {
|
|
332
515
|
on: "delete.backward",
|
|
333
516
|
guard: ({
|
|
334
517
|
context
|
|
@@ -346,11 +529,11 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
346
529
|
},
|
|
347
530
|
actions: [(_, {
|
|
348
531
|
focusTextBlock
|
|
349
|
-
}) => [{
|
|
532
|
+
}) => [raise({
|
|
350
533
|
type: "text block.unset",
|
|
351
534
|
props: ["listItem", "level"],
|
|
352
535
|
at: focusTextBlock.path
|
|
353
|
-
}]]
|
|
536
|
+
})]]
|
|
354
537
|
}, unindentListOnBackspace = {
|
|
355
538
|
on: "delete.backward",
|
|
356
539
|
guard: ({
|
|
@@ -371,11 +554,11 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
371
554
|
actions: [(_, {
|
|
372
555
|
focusTextBlock,
|
|
373
556
|
level
|
|
374
|
-
}) => [{
|
|
557
|
+
}) => [raise({
|
|
375
558
|
type: "text block.set",
|
|
376
559
|
level,
|
|
377
560
|
at: focusTextBlock.path
|
|
378
|
-
}]]
|
|
561
|
+
})]]
|
|
379
562
|
}, clearListOnEnter = {
|
|
380
563
|
on: "insert.break",
|
|
381
564
|
guard: ({
|
|
@@ -392,11 +575,11 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
392
575
|
},
|
|
393
576
|
actions: [(_, {
|
|
394
577
|
focusListBlock
|
|
395
|
-
}) => [{
|
|
578
|
+
}) => [raise({
|
|
396
579
|
type: "text block.unset",
|
|
397
580
|
props: ["listItem", "level"],
|
|
398
581
|
at: focusListBlock.path
|
|
399
|
-
}]]
|
|
582
|
+
})]]
|
|
400
583
|
}, indentListOnTab = {
|
|
401
584
|
on: "key.down",
|
|
402
585
|
guard: ({
|
|
@@ -417,7 +600,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
417
600
|
},
|
|
418
601
|
actions: [(_, {
|
|
419
602
|
selectedListBlocks
|
|
420
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
603
|
+
}) => selectedListBlocks.map((selectedListBlock) => raise({
|
|
421
604
|
type: "text block.set",
|
|
422
605
|
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
|
|
423
606
|
at: selectedListBlock.path
|
|
@@ -442,12 +625,14 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
442
625
|
},
|
|
443
626
|
actions: [(_, {
|
|
444
627
|
selectedListBlocks
|
|
445
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
628
|
+
}) => selectedListBlocks.map((selectedListBlock) => raise({
|
|
446
629
|
type: "text block.set",
|
|
447
630
|
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
|
|
448
631
|
at: selectedListBlock.path
|
|
449
632
|
}))]
|
|
450
633
|
}, coreListBehaviors = {
|
|
634
|
+
toggleListItemOff,
|
|
635
|
+
toggleListItemOn,
|
|
451
636
|
clearListOnBackspace,
|
|
452
637
|
unindentListOnBackspace,
|
|
453
638
|
clearListOnEnter,
|
|
@@ -486,20 +671,54 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
486
671
|
mimeType: event.mimeType
|
|
487
672
|
})]]
|
|
488
673
|
}
|
|
674
|
+
}, toggleStyleOff = {
|
|
675
|
+
on: "style.toggle",
|
|
676
|
+
guard: ({
|
|
677
|
+
context,
|
|
678
|
+
event
|
|
679
|
+
}) => isActiveStyle(event.style)({
|
|
680
|
+
context
|
|
681
|
+
}),
|
|
682
|
+
actions: [({
|
|
683
|
+
event
|
|
684
|
+
}) => [raise({
|
|
685
|
+
type: "style.remove",
|
|
686
|
+
style: event.style
|
|
687
|
+
})]]
|
|
688
|
+
}, toggleStyleOn = {
|
|
689
|
+
on: "style.toggle",
|
|
690
|
+
guard: ({
|
|
691
|
+
context,
|
|
692
|
+
event
|
|
693
|
+
}) => !isActiveStyle(event.style)({
|
|
694
|
+
context
|
|
695
|
+
}),
|
|
696
|
+
actions: [({
|
|
697
|
+
event
|
|
698
|
+
}) => [raise({
|
|
699
|
+
type: "style.add",
|
|
700
|
+
style: event.style
|
|
701
|
+
})]]
|
|
702
|
+
}, coreStyleBehaviors = {
|
|
703
|
+
toggleStyleOff,
|
|
704
|
+
toggleStyleOn
|
|
489
705
|
}, softReturn = {
|
|
490
706
|
on: "insert.soft break",
|
|
491
|
-
actions: [() => [{
|
|
707
|
+
actions: [() => [raise({
|
|
492
708
|
type: "insert.text",
|
|
493
709
|
text: `
|
|
494
710
|
`
|
|
495
|
-
}]]
|
|
496
|
-
}, coreBehaviors = [softReturn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreDeserializeBehavior, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreSerializeBehaviors.serialize, coreSerializeBehaviors["serialization.success"]], coreBehavior = {
|
|
711
|
+
})]]
|
|
712
|
+
}, coreBehaviors = [softReturn, coreAnnotationBehaviors.toggleAnnotationOff, coreAnnotationBehaviors.toggleAnnotationOn, coreDecoratorBehaviors.toggleDecoratorOff, coreDecoratorBehaviors.toggleDecoratorOn, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, coreDeserializeBehavior, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.toggleListItemOff, coreListBehaviors.toggleListItemOn, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.atTheEndOfTextBlock, coreInsertBreakBehaviors.atTheStartOfTextBlock, coreSerializeBehaviors.serialize, coreSerializeBehaviors["serialization.success"], coreStyleBehaviors.toggleStyleOff, coreStyleBehaviors.toggleStyleOn], coreBehavior = {
|
|
497
713
|
softReturn,
|
|
714
|
+
annotation: coreAnnotationBehaviors,
|
|
498
715
|
decorators: coreDecoratorBehaviors,
|
|
499
716
|
deserialize: coreDeserializeBehavior,
|
|
500
717
|
blockObjects: coreBlockObjectBehaviors,
|
|
718
|
+
insertBreak: coreInsertBreakBehaviors,
|
|
501
719
|
lists: coreListBehaviors,
|
|
502
|
-
...coreSerializeBehaviors
|
|
720
|
+
...coreSerializeBehaviors,
|
|
721
|
+
style: coreSerializeBehaviors
|
|
503
722
|
};
|
|
504
723
|
export {
|
|
505
724
|
coreBehavior,
|