@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,6 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var selector_isAtTheStartOfBlock = require("./selector.is-at-the-start-of-block.cjs"), types = require("@sanity/types"), util_isEmptyTextBlock = require("./util.is-empty-text-block.cjs");
|
|
3
|
+
function isCustomBehaviorEvent(event) {
|
|
4
|
+
return event.type.startsWith("custom.");
|
|
5
|
+
}
|
|
6
|
+
function raise(event) {
|
|
7
|
+
return {
|
|
8
|
+
type: "raise",
|
|
9
|
+
event
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function defineBehavior(behavior) {
|
|
13
|
+
return behavior;
|
|
14
|
+
}
|
|
15
|
+
const toggleAnnotationOff = {
|
|
16
|
+
on: "annotation.toggle",
|
|
17
|
+
guard: ({
|
|
18
|
+
context,
|
|
19
|
+
event
|
|
20
|
+
}) => selector_isAtTheStartOfBlock.isActiveAnnotation(event.annotation.name)({
|
|
21
|
+
context
|
|
22
|
+
}),
|
|
23
|
+
actions: [({
|
|
24
|
+
event
|
|
25
|
+
}) => [raise({
|
|
26
|
+
type: "annotation.remove",
|
|
27
|
+
annotation: event.annotation
|
|
28
|
+
})]]
|
|
29
|
+
}, toggleAnnotationOn = {
|
|
30
|
+
on: "annotation.toggle",
|
|
31
|
+
guard: ({
|
|
32
|
+
context,
|
|
33
|
+
event
|
|
34
|
+
}) => !selector_isAtTheStartOfBlock.isActiveAnnotation(event.annotation.name)({
|
|
35
|
+
context
|
|
36
|
+
}),
|
|
37
|
+
actions: [({
|
|
38
|
+
event
|
|
39
|
+
}) => [raise({
|
|
40
|
+
type: "annotation.add",
|
|
41
|
+
annotation: event.annotation
|
|
42
|
+
})]]
|
|
43
|
+
}, coreAnnotationBehaviors = {
|
|
44
|
+
toggleAnnotationOff,
|
|
45
|
+
toggleAnnotationOn
|
|
46
|
+
}, IS_MAC = typeof window < "u" && /Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent), modifiers = {
|
|
4
47
|
alt: "altKey",
|
|
5
48
|
control: "ctrlKey",
|
|
6
49
|
meta: "metaKey",
|
|
@@ -112,80 +155,68 @@ function toKeyName(name) {
|
|
|
112
155
|
const keyName = name.toLowerCase();
|
|
113
156
|
return aliases[keyName] ?? keyName;
|
|
114
157
|
}
|
|
115
|
-
function isCustomBehaviorEvent(event) {
|
|
116
|
-
return event.type.startsWith("custom.");
|
|
117
|
-
}
|
|
118
|
-
function raise(event) {
|
|
119
|
-
return {
|
|
120
|
-
type: "raise",
|
|
121
|
-
event
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
function defineBehavior(behavior) {
|
|
125
|
-
return behavior;
|
|
126
|
-
}
|
|
127
158
|
const arrowDownOnLonelyBlockObject = {
|
|
128
159
|
on: "key.down",
|
|
129
160
|
guard: ({
|
|
130
161
|
context,
|
|
131
162
|
event
|
|
132
163
|
}) => {
|
|
133
|
-
const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject =
|
|
164
|
+
const isArrowDown = isHotkey("ArrowDown", event.keyboardEvent), focusBlockObject = selector_isAtTheStartOfBlock.getFocusBlockObject({
|
|
134
165
|
context
|
|
135
|
-
}), nextBlock =
|
|
166
|
+
}), nextBlock = selector_isAtTheStartOfBlock.getNextBlock({
|
|
136
167
|
context
|
|
137
168
|
});
|
|
138
169
|
return isArrowDown && focusBlockObject && !nextBlock;
|
|
139
170
|
},
|
|
140
|
-
actions: [() => [{
|
|
171
|
+
actions: [() => [raise({
|
|
141
172
|
type: "insert.text block",
|
|
142
173
|
placement: "after"
|
|
143
|
-
}]]
|
|
174
|
+
})]]
|
|
144
175
|
}, arrowUpOnLonelyBlockObject = {
|
|
145
176
|
on: "key.down",
|
|
146
177
|
guard: ({
|
|
147
178
|
context,
|
|
148
179
|
event
|
|
149
180
|
}) => {
|
|
150
|
-
const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject =
|
|
181
|
+
const isArrowUp = isHotkey("ArrowUp", event.keyboardEvent), focusBlockObject = selector_isAtTheStartOfBlock.getFocusBlockObject({
|
|
151
182
|
context
|
|
152
|
-
}), previousBlock =
|
|
183
|
+
}), previousBlock = selector_isAtTheStartOfBlock.getPreviousBlock({
|
|
153
184
|
context
|
|
154
185
|
});
|
|
155
186
|
return isArrowUp && focusBlockObject && !previousBlock;
|
|
156
187
|
},
|
|
157
|
-
actions: [() => [{
|
|
188
|
+
actions: [() => [raise({
|
|
158
189
|
type: "insert.text block",
|
|
159
190
|
placement: "before"
|
|
160
|
-
}, {
|
|
191
|
+
}), raise({
|
|
161
192
|
type: "select.previous block"
|
|
162
|
-
}]]
|
|
193
|
+
})]]
|
|
163
194
|
}, breakingBlockObject = {
|
|
164
195
|
on: "insert.break",
|
|
165
196
|
guard: ({
|
|
166
197
|
context
|
|
167
198
|
}) => {
|
|
168
|
-
const focusBlockObject =
|
|
199
|
+
const focusBlockObject = selector_isAtTheStartOfBlock.getFocusBlockObject({
|
|
169
200
|
context
|
|
170
201
|
});
|
|
171
|
-
return
|
|
202
|
+
return selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
172
203
|
context
|
|
173
204
|
}) && focusBlockObject !== void 0;
|
|
174
205
|
},
|
|
175
|
-
actions: [() => [{
|
|
206
|
+
actions: [() => [raise({
|
|
176
207
|
type: "insert.text block",
|
|
177
208
|
placement: "after"
|
|
178
|
-
}]]
|
|
209
|
+
})]]
|
|
179
210
|
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
180
211
|
on: "delete.backward",
|
|
181
212
|
guard: ({
|
|
182
213
|
context
|
|
183
214
|
}) => {
|
|
184
|
-
const focusTextBlock =
|
|
215
|
+
const focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
185
216
|
context
|
|
186
|
-
}), selectionCollapsed =
|
|
217
|
+
}), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
187
218
|
context
|
|
188
|
-
}), previousBlock =
|
|
219
|
+
}), previousBlock = selector_isAtTheStartOfBlock.getPreviousBlock({
|
|
189
220
|
context
|
|
190
221
|
});
|
|
191
222
|
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : util_isEmptyTextBlock.isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
@@ -196,10 +227,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
196
227
|
actions: [(_, {
|
|
197
228
|
focusTextBlock,
|
|
198
229
|
previousBlock
|
|
199
|
-
}) => [{
|
|
230
|
+
}) => [raise({
|
|
200
231
|
type: "delete.block",
|
|
201
232
|
blockPath: focusTextBlock.path
|
|
202
|
-
}, {
|
|
233
|
+
}), raise({
|
|
203
234
|
type: "select",
|
|
204
235
|
selection: {
|
|
205
236
|
anchor: {
|
|
@@ -211,17 +242,17 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
211
242
|
offset: 0
|
|
212
243
|
}
|
|
213
244
|
}
|
|
214
|
-
}]]
|
|
245
|
+
})]]
|
|
215
246
|
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
216
247
|
on: "delete.forward",
|
|
217
248
|
guard: ({
|
|
218
249
|
context
|
|
219
250
|
}) => {
|
|
220
|
-
const focusTextBlock =
|
|
251
|
+
const focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
221
252
|
context
|
|
222
|
-
}), selectionCollapsed =
|
|
253
|
+
}), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
223
254
|
context
|
|
224
|
-
}), nextBlock =
|
|
255
|
+
}), nextBlock = selector_isAtTheStartOfBlock.getNextBlock({
|
|
225
256
|
context
|
|
226
257
|
});
|
|
227
258
|
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : util_isEmptyTextBlock.isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
@@ -232,10 +263,10 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
232
263
|
actions: [(_, {
|
|
233
264
|
focusTextBlock,
|
|
234
265
|
nextBlock
|
|
235
|
-
}) => [{
|
|
266
|
+
}) => [raise({
|
|
236
267
|
type: "delete.block",
|
|
237
268
|
blockPath: focusTextBlock.path
|
|
238
|
-
}, {
|
|
269
|
+
}), raise({
|
|
239
270
|
type: "select",
|
|
240
271
|
selection: {
|
|
241
272
|
anchor: {
|
|
@@ -247,7 +278,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
247
278
|
offset: 0
|
|
248
279
|
}
|
|
249
280
|
}
|
|
250
|
-
}]]
|
|
281
|
+
})]]
|
|
251
282
|
}, coreBlockObjectBehaviors = {
|
|
252
283
|
arrowDownOnLonelyBlockObject,
|
|
253
284
|
arrowUpOnLonelyBlockObject,
|
|
@@ -255,6 +286,36 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
255
286
|
deletingEmptyTextBlockAfterBlockObject,
|
|
256
287
|
deletingEmptyTextBlockBeforeBlockObject
|
|
257
288
|
}, coreDecoratorBehaviors = {
|
|
289
|
+
toggleDecoratorOff: {
|
|
290
|
+
on: "decorator.toggle",
|
|
291
|
+
guard: ({
|
|
292
|
+
context,
|
|
293
|
+
event
|
|
294
|
+
}) => selector_isAtTheStartOfBlock.isActiveDecorator(event.decorator)({
|
|
295
|
+
context
|
|
296
|
+
}),
|
|
297
|
+
actions: [({
|
|
298
|
+
event
|
|
299
|
+
}) => [raise({
|
|
300
|
+
type: "decorator.remove",
|
|
301
|
+
decorator: event.decorator
|
|
302
|
+
})]]
|
|
303
|
+
},
|
|
304
|
+
toggleDecoratorOn: {
|
|
305
|
+
on: "decorator.toggle",
|
|
306
|
+
guard: ({
|
|
307
|
+
context,
|
|
308
|
+
event
|
|
309
|
+
}) => !selector_isAtTheStartOfBlock.isActiveDecorator(event.decorator)({
|
|
310
|
+
context
|
|
311
|
+
}),
|
|
312
|
+
actions: [({
|
|
313
|
+
event
|
|
314
|
+
}) => [raise({
|
|
315
|
+
type: "decorator.add",
|
|
316
|
+
decorator: event.decorator
|
|
317
|
+
})]]
|
|
318
|
+
},
|
|
258
319
|
strongShortcut: {
|
|
259
320
|
on: "key.down",
|
|
260
321
|
guard: ({
|
|
@@ -327,16 +388,138 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
327
388
|
...deserializeEvent,
|
|
328
389
|
dataTransfer: event.dataTransfer
|
|
329
390
|
})]]
|
|
330
|
-
},
|
|
391
|
+
}, atTheEndOfTextBlock = {
|
|
392
|
+
on: "insert.break",
|
|
393
|
+
guard: ({
|
|
394
|
+
context
|
|
395
|
+
}) => {
|
|
396
|
+
const focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
397
|
+
context
|
|
398
|
+
}), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
399
|
+
context
|
|
400
|
+
});
|
|
401
|
+
if (!context.selection || !focusTextBlock || !selectionCollapsed)
|
|
402
|
+
return !1;
|
|
403
|
+
const atTheEndOfBlock = selector_isAtTheStartOfBlock.isAtTheEndOfBlock(focusTextBlock)({
|
|
404
|
+
context
|
|
405
|
+
}), focusListItem = focusTextBlock.node.listItem, focusLevel = focusTextBlock.node.level;
|
|
406
|
+
return atTheEndOfBlock ? {
|
|
407
|
+
focusListItem,
|
|
408
|
+
focusLevel
|
|
409
|
+
} : !1;
|
|
410
|
+
},
|
|
411
|
+
actions: [({
|
|
412
|
+
context
|
|
413
|
+
}, {
|
|
414
|
+
focusListItem,
|
|
415
|
+
focusLevel
|
|
416
|
+
}) => [raise({
|
|
417
|
+
type: "insert.block",
|
|
418
|
+
block: {
|
|
419
|
+
_type: context.schema.block.name,
|
|
420
|
+
_key: context.keyGenerator(),
|
|
421
|
+
children: [{
|
|
422
|
+
_key: context.keyGenerator(),
|
|
423
|
+
_type: context.schema.span.name,
|
|
424
|
+
text: "",
|
|
425
|
+
marks: []
|
|
426
|
+
}],
|
|
427
|
+
markDefs: [],
|
|
428
|
+
listItem: focusListItem,
|
|
429
|
+
level: focusLevel,
|
|
430
|
+
style: context.schema.styles[0]?.value
|
|
431
|
+
},
|
|
432
|
+
placement: "after"
|
|
433
|
+
})]]
|
|
434
|
+
}, atTheStartOfTextBlock = {
|
|
435
|
+
on: "insert.break",
|
|
436
|
+
guard: ({
|
|
437
|
+
context
|
|
438
|
+
}) => {
|
|
439
|
+
const focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
440
|
+
context
|
|
441
|
+
}), selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
442
|
+
context
|
|
443
|
+
});
|
|
444
|
+
if (!context.selection || !focusTextBlock || !selectionCollapsed)
|
|
445
|
+
return !1;
|
|
446
|
+
const focusSpan = selector_isAtTheStartOfBlock.getFocusSpan({
|
|
447
|
+
context
|
|
448
|
+
}), 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;
|
|
449
|
+
return selector_isAtTheStartOfBlock.isAtTheStartOfBlock(focusTextBlock)({
|
|
450
|
+
context
|
|
451
|
+
}) ? {
|
|
452
|
+
focusAnnotations,
|
|
453
|
+
focusDecorators,
|
|
454
|
+
focusListItem,
|
|
455
|
+
focusLevel
|
|
456
|
+
} : !1;
|
|
457
|
+
},
|
|
458
|
+
actions: [({
|
|
459
|
+
context
|
|
460
|
+
}, {
|
|
461
|
+
focusAnnotations,
|
|
462
|
+
focusDecorators,
|
|
463
|
+
focusListItem,
|
|
464
|
+
focusLevel
|
|
465
|
+
}) => [raise({
|
|
466
|
+
type: "insert.block",
|
|
467
|
+
block: {
|
|
468
|
+
_key: context.keyGenerator(),
|
|
469
|
+
_type: context.schema.block.name,
|
|
470
|
+
children: [{
|
|
471
|
+
_key: context.keyGenerator(),
|
|
472
|
+
_type: context.schema.span.name,
|
|
473
|
+
marks: focusAnnotations.length === 0 ? focusDecorators : [],
|
|
474
|
+
text: ""
|
|
475
|
+
}],
|
|
476
|
+
listItem: focusListItem,
|
|
477
|
+
level: focusLevel,
|
|
478
|
+
style: context.schema.styles[0]?.value
|
|
479
|
+
},
|
|
480
|
+
placement: "before"
|
|
481
|
+
})]]
|
|
482
|
+
}, coreInsertBreakBehaviors = {
|
|
483
|
+
atTheEndOfTextBlock,
|
|
484
|
+
atTheStartOfTextBlock
|
|
485
|
+
}, MAX_LIST_LEVEL = 10, toggleListItemOff = {
|
|
486
|
+
on: "list item.toggle",
|
|
487
|
+
guard: ({
|
|
488
|
+
context,
|
|
489
|
+
event
|
|
490
|
+
}) => selector_isAtTheStartOfBlock.isActiveListItem(event.listItem)({
|
|
491
|
+
context
|
|
492
|
+
}),
|
|
493
|
+
actions: [({
|
|
494
|
+
event
|
|
495
|
+
}) => [raise({
|
|
496
|
+
type: "list item.remove",
|
|
497
|
+
listItem: event.listItem
|
|
498
|
+
})]]
|
|
499
|
+
}, toggleListItemOn = {
|
|
500
|
+
on: "list item.toggle",
|
|
501
|
+
guard: ({
|
|
502
|
+
context,
|
|
503
|
+
event
|
|
504
|
+
}) => !selector_isAtTheStartOfBlock.isActiveListItem(event.listItem)({
|
|
505
|
+
context
|
|
506
|
+
}),
|
|
507
|
+
actions: [({
|
|
508
|
+
event
|
|
509
|
+
}) => [raise({
|
|
510
|
+
type: "list item.add",
|
|
511
|
+
listItem: event.listItem
|
|
512
|
+
})]]
|
|
513
|
+
}, clearListOnBackspace = {
|
|
331
514
|
on: "delete.backward",
|
|
332
515
|
guard: ({
|
|
333
516
|
context
|
|
334
517
|
}) => {
|
|
335
|
-
const selectionCollapsed =
|
|
518
|
+
const selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
336
519
|
context
|
|
337
|
-
}), focusTextBlock =
|
|
520
|
+
}), focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
338
521
|
context
|
|
339
|
-
}), focusSpan =
|
|
522
|
+
}), focusSpan = selector_isAtTheStartOfBlock.getFocusSpan({
|
|
340
523
|
context
|
|
341
524
|
});
|
|
342
525
|
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection?.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
@@ -345,21 +528,21 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
345
528
|
},
|
|
346
529
|
actions: [(_, {
|
|
347
530
|
focusTextBlock
|
|
348
|
-
}) => [{
|
|
531
|
+
}) => [raise({
|
|
349
532
|
type: "text block.unset",
|
|
350
533
|
props: ["listItem", "level"],
|
|
351
534
|
at: focusTextBlock.path
|
|
352
|
-
}]]
|
|
535
|
+
})]]
|
|
353
536
|
}, unindentListOnBackspace = {
|
|
354
537
|
on: "delete.backward",
|
|
355
538
|
guard: ({
|
|
356
539
|
context
|
|
357
540
|
}) => {
|
|
358
|
-
const selectionCollapsed =
|
|
541
|
+
const selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
359
542
|
context
|
|
360
|
-
}), focusTextBlock =
|
|
543
|
+
}), focusTextBlock = selector_isAtTheStartOfBlock.getFocusTextBlock({
|
|
361
544
|
context
|
|
362
|
-
}), focusSpan =
|
|
545
|
+
}), focusSpan = selector_isAtTheStartOfBlock.getFocusSpan({
|
|
363
546
|
context
|
|
364
547
|
});
|
|
365
548
|
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 ? {
|
|
@@ -370,19 +553,19 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
370
553
|
actions: [(_, {
|
|
371
554
|
focusTextBlock,
|
|
372
555
|
level
|
|
373
|
-
}) => [{
|
|
556
|
+
}) => [raise({
|
|
374
557
|
type: "text block.set",
|
|
375
558
|
level,
|
|
376
559
|
at: focusTextBlock.path
|
|
377
|
-
}]]
|
|
560
|
+
})]]
|
|
378
561
|
}, clearListOnEnter = {
|
|
379
562
|
on: "insert.break",
|
|
380
563
|
guard: ({
|
|
381
564
|
context
|
|
382
565
|
}) => {
|
|
383
|
-
const selectionCollapsed =
|
|
566
|
+
const selectionCollapsed = selector_isAtTheStartOfBlock.isSelectionCollapsed({
|
|
384
567
|
context
|
|
385
|
-
}), focusListBlock =
|
|
568
|
+
}), focusListBlock = selector_isAtTheStartOfBlock.getFocusListBlock({
|
|
386
569
|
context
|
|
387
570
|
});
|
|
388
571
|
return !selectionCollapsed || !focusListBlock || !util_isEmptyTextBlock.isEmptyTextBlock(focusListBlock.node) ? !1 : {
|
|
@@ -391,11 +574,11 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
391
574
|
},
|
|
392
575
|
actions: [(_, {
|
|
393
576
|
focusListBlock
|
|
394
|
-
}) => [{
|
|
577
|
+
}) => [raise({
|
|
395
578
|
type: "text block.unset",
|
|
396
579
|
props: ["listItem", "level"],
|
|
397
580
|
at: focusListBlock.path
|
|
398
|
-
}]]
|
|
581
|
+
})]]
|
|
399
582
|
}, indentListOnTab = {
|
|
400
583
|
on: "key.down",
|
|
401
584
|
guard: ({
|
|
@@ -404,9 +587,9 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
404
587
|
}) => {
|
|
405
588
|
if (!isHotkey("Tab", event.keyboardEvent))
|
|
406
589
|
return !1;
|
|
407
|
-
const selectedBlocks =
|
|
590
|
+
const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks({
|
|
408
591
|
context
|
|
409
|
-
}), guards =
|
|
592
|
+
}), guards = selector_isAtTheStartOfBlock.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
410
593
|
node: block.node,
|
|
411
594
|
path: block.path
|
|
412
595
|
}] : []);
|
|
@@ -416,7 +599,7 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
416
599
|
},
|
|
417
600
|
actions: [(_, {
|
|
418
601
|
selectedListBlocks
|
|
419
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
602
|
+
}) => selectedListBlocks.map((selectedListBlock) => raise({
|
|
420
603
|
type: "text block.set",
|
|
421
604
|
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level + 1)),
|
|
422
605
|
at: selectedListBlock.path
|
|
@@ -429,9 +612,9 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
429
612
|
}) => {
|
|
430
613
|
if (!isHotkey("Shift+Tab", event.keyboardEvent))
|
|
431
614
|
return !1;
|
|
432
|
-
const selectedBlocks =
|
|
615
|
+
const selectedBlocks = selector_isAtTheStartOfBlock.getSelectedBlocks({
|
|
433
616
|
context
|
|
434
|
-
}), guards =
|
|
617
|
+
}), guards = selector_isAtTheStartOfBlock.createGuards(context), selectedListBlocks = selectedBlocks.flatMap((block) => guards.isListBlock(block.node) ? [{
|
|
435
618
|
node: block.node,
|
|
436
619
|
path: block.path
|
|
437
620
|
}] : []);
|
|
@@ -441,12 +624,14 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
441
624
|
},
|
|
442
625
|
actions: [(_, {
|
|
443
626
|
selectedListBlocks
|
|
444
|
-
}) => selectedListBlocks.map((selectedListBlock) => ({
|
|
627
|
+
}) => selectedListBlocks.map((selectedListBlock) => raise({
|
|
445
628
|
type: "text block.set",
|
|
446
629
|
level: Math.min(MAX_LIST_LEVEL, Math.max(1, selectedListBlock.node.level - 1)),
|
|
447
630
|
at: selectedListBlock.path
|
|
448
631
|
}))]
|
|
449
632
|
}, coreListBehaviors = {
|
|
633
|
+
toggleListItemOff,
|
|
634
|
+
toggleListItemOn,
|
|
450
635
|
clearListOnBackspace,
|
|
451
636
|
unindentListOnBackspace,
|
|
452
637
|
clearListOnEnter,
|
|
@@ -485,20 +670,54 @@ const arrowDownOnLonelyBlockObject = {
|
|
|
485
670
|
mimeType: event.mimeType
|
|
486
671
|
})]]
|
|
487
672
|
}
|
|
673
|
+
}, toggleStyleOff = {
|
|
674
|
+
on: "style.toggle",
|
|
675
|
+
guard: ({
|
|
676
|
+
context,
|
|
677
|
+
event
|
|
678
|
+
}) => selector_isAtTheStartOfBlock.isActiveStyle(event.style)({
|
|
679
|
+
context
|
|
680
|
+
}),
|
|
681
|
+
actions: [({
|
|
682
|
+
event
|
|
683
|
+
}) => [raise({
|
|
684
|
+
type: "style.remove",
|
|
685
|
+
style: event.style
|
|
686
|
+
})]]
|
|
687
|
+
}, toggleStyleOn = {
|
|
688
|
+
on: "style.toggle",
|
|
689
|
+
guard: ({
|
|
690
|
+
context,
|
|
691
|
+
event
|
|
692
|
+
}) => !selector_isAtTheStartOfBlock.isActiveStyle(event.style)({
|
|
693
|
+
context
|
|
694
|
+
}),
|
|
695
|
+
actions: [({
|
|
696
|
+
event
|
|
697
|
+
}) => [raise({
|
|
698
|
+
type: "style.add",
|
|
699
|
+
style: event.style
|
|
700
|
+
})]]
|
|
701
|
+
}, coreStyleBehaviors = {
|
|
702
|
+
toggleStyleOff,
|
|
703
|
+
toggleStyleOn
|
|
488
704
|
}, softReturn = {
|
|
489
705
|
on: "insert.soft break",
|
|
490
|
-
actions: [() => [{
|
|
706
|
+
actions: [() => [raise({
|
|
491
707
|
type: "insert.text",
|
|
492
708
|
text: `
|
|
493
709
|
`
|
|
494
|
-
}]]
|
|
495
|
-
}, 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 = {
|
|
710
|
+
})]]
|
|
711
|
+
}, 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 = {
|
|
496
712
|
softReturn,
|
|
713
|
+
annotation: coreAnnotationBehaviors,
|
|
497
714
|
decorators: coreDecoratorBehaviors,
|
|
498
715
|
deserialize: coreDeserializeBehavior,
|
|
499
716
|
blockObjects: coreBlockObjectBehaviors,
|
|
717
|
+
insertBreak: coreInsertBreakBehaviors,
|
|
500
718
|
lists: coreListBehaviors,
|
|
501
|
-
...coreSerializeBehaviors
|
|
719
|
+
...coreSerializeBehaviors,
|
|
720
|
+
style: coreSerializeBehaviors
|
|
502
721
|
};
|
|
503
722
|
exports.coreBehavior = coreBehavior;
|
|
504
723
|
exports.coreBehaviors = coreBehaviors;
|