@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.
- package/lib/_chunks-cjs/editor-provider.cjs +879 -169
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-focus-inline-object.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.get-text-before.cjs +2 -2
- package/lib/_chunks-cjs/selector.get-text-before.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs +464 -19
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +9 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -2
- package/lib/_chunks-es/editor-provider.js +773 -65
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/selector.get-focus-inline-object.js +1 -1
- package/lib/_chunks-es/selector.get-text-before.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +448 -3
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +9 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +2 -2
- package/lib/behaviors/index.cjs +27 -377
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +3696 -13915
- package/lib/behaviors/index.d.ts +3696 -13915
- package/lib/behaviors/index.js +22 -377
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +17 -17
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +3008 -394
- package/lib/index.d.ts +3008 -394
- package/lib/index.js +4 -5
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +347 -30
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +3008 -395
- package/lib/plugins/index.d.ts +3008 -395
- package/lib/plugins/index.js +324 -8
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +29 -29
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +3007 -387
- package/lib/selectors/index.d.ts +3007 -387
- package/lib/selectors/index.js +2 -3
- package/lib/selectors/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +3008 -389
- package/lib/utils/index.d.ts +3008 -389
- package/lib/utils/index.js +2 -3
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.emoji-picker.ts +0 -6
- package/src/behaviors/behavior.markdown.ts +0 -48
- package/src/behaviors/index.ts +0 -15
- package/src/editor/create-editor.ts +0 -3
- package/src/editor/editor-machine.ts +105 -52
- package/src/editor/sync-machine.ts +10 -4
- package/src/internal-utils/__tests__/operationToPatches.test.ts +0 -2
- package/src/internal-utils/__tests__/patchToOperations.test.ts +0 -2
- package/src/plugins/plugin.core.tsx +1 -1
- package/lib/_chunks-cjs/behavior.core.cjs +0 -700
- package/lib/_chunks-cjs/behavior.core.cjs.map +0 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs +0 -321
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +0 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +0 -449
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +0 -1
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs +0 -10
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +0 -1
- package/lib/_chunks-es/behavior.core.js +0 -703
- package/lib/_chunks-es/behavior.core.js.map +0 -1
- package/lib/_chunks-es/behavior.markdown.js +0 -325
- package/lib/_chunks-es/behavior.markdown.js.map +0 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js +0 -451
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +0 -1
- package/lib/_chunks-es/util.get-selection-start-point.js +0 -11
- package/lib/_chunks-es/util.get-selection-start-point.js.map +0 -1
- package/src/behaviors/behavior.code-editor.ts +0 -77
- package/src/behaviors/behavior.links.ts +0 -84
- package/src/internal-utils/looks-like-url.test.ts +0 -19
- package/src/internal-utils/looks-like-url.ts +0 -15
package/lib/plugins/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), editorProvider = require("../_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"),
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), editorProvider = require("../_chunks-cjs/editor-provider.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), xstate = require("xstate"), util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), selector_isSelectingEntireBlocks = require("../_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), selector_getTextBefore = require("../_chunks-cjs/selector.get-text-before.cjs"), behaviors_index = require("../behaviors/index.cjs"), useEffectEvent = require("use-effect-event"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
@@ -23,7 +23,7 @@ function _temp(unregister) {
|
|
|
23
23
|
function CoreBehaviorsPlugin() {
|
|
24
24
|
const $ = reactCompilerRuntime.c(1);
|
|
25
25
|
let t0;
|
|
26
|
-
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(BehaviorPlugin, { behaviors:
|
|
26
|
+
return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsxRuntime.jsx(BehaviorPlugin, { behaviors: editorProvider.coreBehaviors }), $[0] = t0) : t0 = $[0], t0;
|
|
27
27
|
}
|
|
28
28
|
function createPairRegex(char, amount) {
|
|
29
29
|
const prePrefix = `(?<!\\${char})`, prefix = `\\${char}`.repeat(Math.max(amount, 1)), postPrefix = "(?!\\s)", content = `([^${char}\\n]+?)`, preSuffix = "(?<!\\s)", suffix = `\\${char}`.repeat(Math.max(amount, 1)), postSuffix = `(?!\\${char})`;
|
|
@@ -32,7 +32,7 @@ function createPairRegex(char, amount) {
|
|
|
32
32
|
function createDecoratorPairBehavior(config) {
|
|
33
33
|
config.pair.amount < 1 && console.warn("The amount of characters in the pair should be greater than 0");
|
|
34
34
|
const pairRegex = createPairRegex(config.pair.char, config.pair.amount), regEx = new RegExp(`(${pairRegex})$`);
|
|
35
|
-
return
|
|
35
|
+
return behaviors_index.defineBehavior({
|
|
36
36
|
on: "insert.text",
|
|
37
37
|
guard: ({
|
|
38
38
|
snapshot,
|
|
@@ -45,7 +45,7 @@ function createDecoratorPairBehavior(config) {
|
|
|
45
45
|
});
|
|
46
46
|
if (decorator === void 0)
|
|
47
47
|
return !1;
|
|
48
|
-
const focusTextBlock =
|
|
48
|
+
const focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionStartPoint = selector_isSelectingEntireBlocks.getSelectionStartPoint(snapshot), selectionStartOffset = selectionStartPoint ? util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
49
49
|
context: {
|
|
50
50
|
schema: snapshot.context.schema,
|
|
51
51
|
value: snapshot.context.value
|
|
@@ -84,7 +84,7 @@ function createDecoratorPairBehavior(config) {
|
|
|
84
84
|
const prefixSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection({
|
|
85
85
|
context: snapshot.context,
|
|
86
86
|
offsets: prefixOffsets
|
|
87
|
-
}), inlineObjectBeforePrefixFocus =
|
|
87
|
+
}), inlineObjectBeforePrefixFocus = selector_isSelectingEntireBlocks.getPreviousInlineObject({
|
|
88
88
|
context: {
|
|
89
89
|
...snapshot.context,
|
|
90
90
|
selection: prefixSelection ? {
|
|
@@ -106,7 +106,7 @@ function createDecoratorPairBehavior(config) {
|
|
|
106
106
|
return !1;
|
|
107
107
|
}
|
|
108
108
|
if (suffixOffsets.focus.offset - suffixOffsets.anchor.offset > 1) {
|
|
109
|
-
const previousInlineObject =
|
|
109
|
+
const previousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject(snapshot), previousInlineObjectOffset = previousInlineObject ? util_selectionPointToBlockOffset.childSelectionPointToBlockOffset({
|
|
110
110
|
context: {
|
|
111
111
|
schema: snapshot.context.schema,
|
|
112
112
|
value: snapshot.context.value
|
|
@@ -129,14 +129,14 @@ function createDecoratorPairBehavior(config) {
|
|
|
129
129
|
// Insert the text as usual in its own undo step
|
|
130
130
|
({
|
|
131
131
|
event
|
|
132
|
-
}) => [
|
|
132
|
+
}) => [behaviors_index.execute(event)],
|
|
133
133
|
(_, {
|
|
134
134
|
prefixOffsets,
|
|
135
135
|
suffixOffsets,
|
|
136
136
|
decorator
|
|
137
137
|
}) => [
|
|
138
138
|
// Decorate the text between the prefix and suffix
|
|
139
|
-
|
|
139
|
+
behaviors_index.execute({
|
|
140
140
|
type: "decorator.add",
|
|
141
141
|
decorator,
|
|
142
142
|
at: {
|
|
@@ -145,21 +145,21 @@ function createDecoratorPairBehavior(config) {
|
|
|
145
145
|
}
|
|
146
146
|
}),
|
|
147
147
|
// Delete the suffix
|
|
148
|
-
|
|
148
|
+
behaviors_index.execute({
|
|
149
149
|
type: "delete.text",
|
|
150
150
|
at: suffixOffsets
|
|
151
151
|
}),
|
|
152
152
|
// Delete the prefix
|
|
153
|
-
|
|
153
|
+
behaviors_index.execute({
|
|
154
154
|
type: "delete.text",
|
|
155
155
|
at: prefixOffsets
|
|
156
156
|
}),
|
|
157
157
|
// Toggle the decorator off so the next inserted text isn't emphasized
|
|
158
|
-
|
|
158
|
+
behaviors_index.execute({
|
|
159
159
|
type: "decorator.remove",
|
|
160
160
|
decorator
|
|
161
161
|
}),
|
|
162
|
-
|
|
162
|
+
behaviors_index.effect(() => {
|
|
163
163
|
config.onDecorate({
|
|
164
164
|
...suffixOffsets.anchor,
|
|
165
165
|
offset: suffixOffsets.anchor.offset - (prefixOffsets.focus.offset - prefixOffsets.anchor.offset)
|
|
@@ -198,7 +198,7 @@ const emphasisListener = ({
|
|
|
198
198
|
sendBack,
|
|
199
199
|
input
|
|
200
200
|
}) => input.editor.registerBehavior({
|
|
201
|
-
behavior:
|
|
201
|
+
behavior: behaviors_index.defineBehavior({
|
|
202
202
|
on: "select",
|
|
203
203
|
guard: ({
|
|
204
204
|
snapshot,
|
|
@@ -236,17 +236,17 @@ const emphasisListener = ({
|
|
|
236
236
|
blockOffsets
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
|
-
},
|
|
239
|
+
}, behaviors_index.forward(event)]]
|
|
240
240
|
})
|
|
241
241
|
}), deleteBackwardListenerCallback = ({
|
|
242
242
|
sendBack,
|
|
243
243
|
input
|
|
244
244
|
}) => input.editor.registerBehavior({
|
|
245
|
-
behavior:
|
|
245
|
+
behavior: behaviors_index.defineBehavior({
|
|
246
246
|
on: "delete.backward",
|
|
247
|
-
actions: [() => [
|
|
247
|
+
actions: [() => [behaviors_index.execute({
|
|
248
248
|
type: "history.undo"
|
|
249
|
-
}),
|
|
249
|
+
}), behaviors_index.effect(() => {
|
|
250
250
|
sendBack({
|
|
251
251
|
type: "delete.backward"
|
|
252
252
|
});
|
|
@@ -350,11 +350,328 @@ function EventListenerPlugin(props) {
|
|
|
350
350
|
let t1;
|
|
351
351
|
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], React.useEffect(t0, t1), null;
|
|
352
352
|
}
|
|
353
|
+
function createMarkdownBehaviors(config) {
|
|
354
|
+
const automaticBlockquoteOnSpace = behaviors_index.defineBehavior({
|
|
355
|
+
on: "insert.text",
|
|
356
|
+
guard: ({
|
|
357
|
+
snapshot,
|
|
358
|
+
event
|
|
359
|
+
}) => {
|
|
360
|
+
if (event.text !== " ")
|
|
361
|
+
return !1;
|
|
362
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
363
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
364
|
+
return !1;
|
|
365
|
+
const previousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject(snapshot), blockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
366
|
+
context: snapshot.context,
|
|
367
|
+
selectionPoint: {
|
|
368
|
+
path: [{
|
|
369
|
+
_key: focusTextBlock.node._key
|
|
370
|
+
}, "children", {
|
|
371
|
+
_key: focusSpan.node._key
|
|
372
|
+
}],
|
|
373
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
if (previousInlineObject || !blockOffset)
|
|
377
|
+
return !1;
|
|
378
|
+
const blockText = util_sliceBlocks.getTextBlockText(focusTextBlock.node), caretAtTheEndOfQuote = blockOffset.offset === 1, looksLikeMarkdownQuote = /^>/.test(blockText), blockquoteStyle = config.blockquoteStyle?.(snapshot.context);
|
|
379
|
+
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
380
|
+
focusTextBlock,
|
|
381
|
+
style: blockquoteStyle
|
|
382
|
+
} : !1;
|
|
383
|
+
},
|
|
384
|
+
actions: [() => [behaviors_index.execute({
|
|
385
|
+
type: "insert.text",
|
|
386
|
+
text: " "
|
|
387
|
+
})], (_, {
|
|
388
|
+
focusTextBlock,
|
|
389
|
+
style
|
|
390
|
+
}) => [behaviors_index.execute({
|
|
391
|
+
type: "block.unset",
|
|
392
|
+
props: ["listItem", "level"],
|
|
393
|
+
at: focusTextBlock.path
|
|
394
|
+
}), behaviors_index.execute({
|
|
395
|
+
type: "block.set",
|
|
396
|
+
props: {
|
|
397
|
+
style
|
|
398
|
+
},
|
|
399
|
+
at: focusTextBlock.path
|
|
400
|
+
}), behaviors_index.execute({
|
|
401
|
+
type: "delete.text",
|
|
402
|
+
at: {
|
|
403
|
+
anchor: {
|
|
404
|
+
path: focusTextBlock.path,
|
|
405
|
+
offset: 0
|
|
406
|
+
},
|
|
407
|
+
focus: {
|
|
408
|
+
path: focusTextBlock.path,
|
|
409
|
+
offset: 2
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
})]]
|
|
413
|
+
}), automaticHr = behaviors_index.defineBehavior({
|
|
414
|
+
on: "insert.text",
|
|
415
|
+
guard: ({
|
|
416
|
+
snapshot,
|
|
417
|
+
event
|
|
418
|
+
}) => {
|
|
419
|
+
const hrCharacter = event.text === "-" ? "-" : event.text === "*" ? "*" : event.text === "_" ? "_" : void 0;
|
|
420
|
+
if (hrCharacter === void 0)
|
|
421
|
+
return !1;
|
|
422
|
+
const hrObject = config.horizontalRuleObject?.(snapshot.context), focusBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot);
|
|
423
|
+
if (!hrObject || !focusBlock || !selectionCollapsed)
|
|
424
|
+
return !1;
|
|
425
|
+
const previousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject(snapshot), textBefore = selector_getTextBefore.getBlockTextBefore(snapshot), hrBlockOffsets = {
|
|
426
|
+
anchor: {
|
|
427
|
+
path: focusBlock.path,
|
|
428
|
+
offset: 0
|
|
429
|
+
},
|
|
430
|
+
focus: {
|
|
431
|
+
path: focusBlock.path,
|
|
432
|
+
offset: 3
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
return !previousInlineObject && textBefore === `${hrCharacter}${hrCharacter}` ? {
|
|
436
|
+
hrObject,
|
|
437
|
+
focusBlock,
|
|
438
|
+
hrCharacter,
|
|
439
|
+
hrBlockOffsets
|
|
440
|
+
} : !1;
|
|
441
|
+
},
|
|
442
|
+
actions: [(_, {
|
|
443
|
+
hrCharacter
|
|
444
|
+
}) => [behaviors_index.execute({
|
|
445
|
+
type: "insert.text",
|
|
446
|
+
text: hrCharacter
|
|
447
|
+
})], (_, {
|
|
448
|
+
hrObject,
|
|
449
|
+
hrBlockOffsets
|
|
450
|
+
}) => [behaviors_index.execute({
|
|
451
|
+
type: "insert.block",
|
|
452
|
+
placement: "before",
|
|
453
|
+
block: {
|
|
454
|
+
_type: hrObject.name,
|
|
455
|
+
...hrObject.value ?? {}
|
|
456
|
+
}
|
|
457
|
+
}), behaviors_index.execute({
|
|
458
|
+
type: "delete.text",
|
|
459
|
+
at: hrBlockOffsets
|
|
460
|
+
})]]
|
|
461
|
+
}), automaticHrOnPaste = behaviors_index.defineBehavior({
|
|
462
|
+
on: "clipboard.paste",
|
|
463
|
+
guard: ({
|
|
464
|
+
snapshot,
|
|
465
|
+
event
|
|
466
|
+
}) => {
|
|
467
|
+
const text = event.originEvent.dataTransfer.getData("text/plain"), hrRegExp = /^(---)$|(___)$|(\*\*\*)$/, hrCharacters = text.match(hrRegExp)?.[0], hrObject = config.horizontalRuleObject?.(snapshot.context), focusBlock = selector_isSelectingEntireBlocks.getFocusBlock(snapshot);
|
|
468
|
+
return !hrCharacters || !hrObject || !focusBlock ? !1 : {
|
|
469
|
+
hrCharacters,
|
|
470
|
+
hrObject,
|
|
471
|
+
focusBlock
|
|
472
|
+
};
|
|
473
|
+
},
|
|
474
|
+
actions: [(_, {
|
|
475
|
+
hrCharacters
|
|
476
|
+
}) => [behaviors_index.execute({
|
|
477
|
+
type: "insert.text",
|
|
478
|
+
text: hrCharacters
|
|
479
|
+
})], ({
|
|
480
|
+
snapshot
|
|
481
|
+
}, {
|
|
482
|
+
hrObject,
|
|
483
|
+
focusBlock
|
|
484
|
+
}) => util_sliceBlocks.isTextBlock(snapshot.context, focusBlock.node) ? [behaviors_index.execute({
|
|
485
|
+
type: "insert.block",
|
|
486
|
+
block: {
|
|
487
|
+
_type: snapshot.context.schema.block.name,
|
|
488
|
+
children: focusBlock.node.children
|
|
489
|
+
},
|
|
490
|
+
placement: "after"
|
|
491
|
+
}), behaviors_index.execute({
|
|
492
|
+
type: "insert.block",
|
|
493
|
+
block: {
|
|
494
|
+
_type: hrObject.name,
|
|
495
|
+
...hrObject.value ?? {}
|
|
496
|
+
},
|
|
497
|
+
placement: "after"
|
|
498
|
+
}), behaviors_index.execute({
|
|
499
|
+
type: "delete.block",
|
|
500
|
+
at: focusBlock.path
|
|
501
|
+
})] : [behaviors_index.execute({
|
|
502
|
+
type: "insert.block",
|
|
503
|
+
block: {
|
|
504
|
+
_type: hrObject.name,
|
|
505
|
+
...hrObject.value ?? {}
|
|
506
|
+
},
|
|
507
|
+
placement: "after"
|
|
508
|
+
})]]
|
|
509
|
+
}), automaticHeadingOnSpace = behaviors_index.defineBehavior({
|
|
510
|
+
on: "insert.text",
|
|
511
|
+
guard: ({
|
|
512
|
+
snapshot,
|
|
513
|
+
event
|
|
514
|
+
}) => {
|
|
515
|
+
if (event.text !== " ")
|
|
516
|
+
return !1;
|
|
517
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
518
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
519
|
+
return !1;
|
|
520
|
+
const blockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
521
|
+
context: snapshot.context,
|
|
522
|
+
selectionPoint: {
|
|
523
|
+
path: [{
|
|
524
|
+
_key: focusTextBlock.node._key
|
|
525
|
+
}, "children", {
|
|
526
|
+
_key: focusSpan.node._key
|
|
527
|
+
}],
|
|
528
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
if (!blockOffset)
|
|
532
|
+
return !1;
|
|
533
|
+
const previousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject(snapshot), blockText = util_sliceBlocks.getTextBlockText(focusTextBlock.node), markdownHeadingSearch = /^#+/.exec(blockText), level = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0, caretAtTheEndOfHeading = blockOffset.offset === level;
|
|
534
|
+
if (previousInlineObject || !caretAtTheEndOfHeading)
|
|
535
|
+
return !1;
|
|
536
|
+
const style = level !== void 0 ? config.headingStyle?.({
|
|
537
|
+
schema: snapshot.context.schema,
|
|
538
|
+
level
|
|
539
|
+
}) : void 0;
|
|
540
|
+
return level !== void 0 && style !== void 0 ? {
|
|
541
|
+
focusTextBlock,
|
|
542
|
+
style,
|
|
543
|
+
level
|
|
544
|
+
} : !1;
|
|
545
|
+
},
|
|
546
|
+
actions: [({
|
|
547
|
+
event
|
|
548
|
+
}) => [behaviors_index.execute(event)], (_, {
|
|
549
|
+
focusTextBlock,
|
|
550
|
+
style,
|
|
551
|
+
level
|
|
552
|
+
}) => [behaviors_index.execute({
|
|
553
|
+
type: "block.unset",
|
|
554
|
+
props: ["listItem", "level"],
|
|
555
|
+
at: focusTextBlock.path
|
|
556
|
+
}), behaviors_index.execute({
|
|
557
|
+
type: "block.set",
|
|
558
|
+
props: {
|
|
559
|
+
style
|
|
560
|
+
},
|
|
561
|
+
at: focusTextBlock.path
|
|
562
|
+
}), behaviors_index.execute({
|
|
563
|
+
type: "delete.text",
|
|
564
|
+
at: {
|
|
565
|
+
anchor: {
|
|
566
|
+
path: focusTextBlock.path,
|
|
567
|
+
offset: 0
|
|
568
|
+
},
|
|
569
|
+
focus: {
|
|
570
|
+
path: focusTextBlock.path,
|
|
571
|
+
offset: level + 1
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
})]]
|
|
575
|
+
}), clearStyleOnBackspace = behaviors_index.defineBehavior({
|
|
576
|
+
on: "delete.backward",
|
|
577
|
+
guard: ({
|
|
578
|
+
snapshot
|
|
579
|
+
}) => {
|
|
580
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
581
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
582
|
+
return !1;
|
|
583
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0, defaultStyle = config.defaultStyle?.(snapshot.context);
|
|
584
|
+
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
585
|
+
defaultStyle,
|
|
586
|
+
focusTextBlock
|
|
587
|
+
} : !1;
|
|
588
|
+
},
|
|
589
|
+
actions: [(_, {
|
|
590
|
+
defaultStyle,
|
|
591
|
+
focusTextBlock
|
|
592
|
+
}) => [behaviors_index.execute({
|
|
593
|
+
type: "block.set",
|
|
594
|
+
props: {
|
|
595
|
+
style: defaultStyle
|
|
596
|
+
},
|
|
597
|
+
at: focusTextBlock.path
|
|
598
|
+
})]]
|
|
599
|
+
}), automaticListOnSpace = behaviors_index.defineBehavior({
|
|
600
|
+
on: "insert.text",
|
|
601
|
+
guard: ({
|
|
602
|
+
snapshot,
|
|
603
|
+
event
|
|
604
|
+
}) => {
|
|
605
|
+
if (event.text !== " ")
|
|
606
|
+
return !1;
|
|
607
|
+
const selectionCollapsed = selector_isSelectingEntireBlocks.isSelectionCollapsed(snapshot), focusTextBlock = selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot), focusSpan = selector_isSelectingEntireBlocks.getFocusSpan(snapshot);
|
|
608
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
609
|
+
return !1;
|
|
610
|
+
const previousInlineObject = selector_isSelectingEntireBlocks.getPreviousInlineObject(snapshot), blockOffset = util_sliceBlocks.spanSelectionPointToBlockOffset({
|
|
611
|
+
context: snapshot.context,
|
|
612
|
+
selectionPoint: {
|
|
613
|
+
path: [{
|
|
614
|
+
_key: focusTextBlock.node._key
|
|
615
|
+
}, "children", {
|
|
616
|
+
_key: focusSpan.node._key
|
|
617
|
+
}],
|
|
618
|
+
offset: snapshot.context.selection?.focus.offset ?? 0
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
if (previousInlineObject || !blockOffset)
|
|
622
|
+
return !1;
|
|
623
|
+
const blockText = util_sliceBlocks.getTextBlockText(focusTextBlock.node), defaultStyle = config.defaultStyle?.(snapshot.context), looksLikeUnorderedList = /^(-|\*)/.test(blockText), unorderedListStyle = config.unorderedListStyle?.(snapshot.context), caretAtTheEndOfUnorderedList = blockOffset.offset === 1;
|
|
624
|
+
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
625
|
+
return {
|
|
626
|
+
focusTextBlock,
|
|
627
|
+
listItem: unorderedListStyle,
|
|
628
|
+
listItemLength: 1,
|
|
629
|
+
style: defaultStyle
|
|
630
|
+
};
|
|
631
|
+
const looksLikeOrderedList = /^1\./.test(blockText), orderedListStyle = config.orderedListStyle?.(snapshot.context), caretAtTheEndOfOrderedList = blockOffset.offset === 2;
|
|
632
|
+
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
633
|
+
focusTextBlock,
|
|
634
|
+
listItem: orderedListStyle,
|
|
635
|
+
listItemLength: 2,
|
|
636
|
+
style: defaultStyle
|
|
637
|
+
} : !1;
|
|
638
|
+
},
|
|
639
|
+
actions: [({
|
|
640
|
+
event
|
|
641
|
+
}) => [behaviors_index.execute(event)], (_, {
|
|
642
|
+
focusTextBlock,
|
|
643
|
+
style,
|
|
644
|
+
listItem,
|
|
645
|
+
listItemLength
|
|
646
|
+
}) => [behaviors_index.execute({
|
|
647
|
+
type: "block.set",
|
|
648
|
+
props: {
|
|
649
|
+
listItem,
|
|
650
|
+
level: 1,
|
|
651
|
+
style
|
|
652
|
+
},
|
|
653
|
+
at: focusTextBlock.path
|
|
654
|
+
}), behaviors_index.execute({
|
|
655
|
+
type: "delete.text",
|
|
656
|
+
at: {
|
|
657
|
+
anchor: {
|
|
658
|
+
path: focusTextBlock.path,
|
|
659
|
+
offset: 0
|
|
660
|
+
},
|
|
661
|
+
focus: {
|
|
662
|
+
path: focusTextBlock.path,
|
|
663
|
+
offset: listItemLength + 1
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
})]]
|
|
667
|
+
});
|
|
668
|
+
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, automaticHr, automaticHrOnPaste, clearStyleOnBackspace, automaticListOnSpace];
|
|
669
|
+
}
|
|
353
670
|
function MarkdownPlugin(props) {
|
|
354
671
|
const $ = reactCompilerRuntime.c(17), editor = editorProvider.useEditor();
|
|
355
672
|
let t0, t1;
|
|
356
673
|
$[0] !== editor || $[1] !== props.config ? (t0 = () => {
|
|
357
|
-
const unregisterBehaviors =
|
|
674
|
+
const unregisterBehaviors = createMarkdownBehaviors(props.config).map((behavior) => editor.registerBehavior({
|
|
358
675
|
behavior
|
|
359
676
|
}));
|
|
360
677
|
return () => {
|
|
@@ -407,16 +724,16 @@ const oneLineBehaviors = [
|
|
|
407
724
|
* Hitting Enter on an expanded selection should just delete that selection
|
|
408
725
|
* without causing a line break.
|
|
409
726
|
*/
|
|
410
|
-
|
|
727
|
+
behaviors_index.defineBehavior({
|
|
411
728
|
on: "insert.break",
|
|
412
729
|
guard: ({
|
|
413
730
|
snapshot
|
|
414
|
-
}) => snapshot.context.selection &&
|
|
731
|
+
}) => snapshot.context.selection && selector_isSelectingEntireBlocks.isSelectionExpanded(snapshot) ? {
|
|
415
732
|
selection: snapshot.context.selection
|
|
416
733
|
} : !1,
|
|
417
734
|
actions: [(_, {
|
|
418
735
|
selection
|
|
419
|
-
}) => [
|
|
736
|
+
}) => [behaviors_index.execute({
|
|
420
737
|
type: "delete",
|
|
421
738
|
at: selection
|
|
422
739
|
})]]
|
|
@@ -424,14 +741,14 @@ const oneLineBehaviors = [
|
|
|
424
741
|
/**
|
|
425
742
|
* All other cases of `insert.break` should be aborted.
|
|
426
743
|
*/
|
|
427
|
-
|
|
744
|
+
behaviors_index.defineBehavior({
|
|
428
745
|
on: "insert.break",
|
|
429
746
|
actions: []
|
|
430
747
|
}),
|
|
431
748
|
/**
|
|
432
749
|
* `insert.block` `before` or `after` is not allowed in a one-line editor.
|
|
433
750
|
*/
|
|
434
|
-
|
|
751
|
+
behaviors_index.defineBehavior({
|
|
435
752
|
on: "insert.block",
|
|
436
753
|
guard: ({
|
|
437
754
|
event
|
|
@@ -442,15 +759,15 @@ const oneLineBehaviors = [
|
|
|
442
759
|
* An ordinary `insert.block` is acceptable if it's a text block. In that
|
|
443
760
|
* case it will get merged into the existing text block.
|
|
444
761
|
*/
|
|
445
|
-
|
|
762
|
+
behaviors_index.defineBehavior({
|
|
446
763
|
on: "insert.block",
|
|
447
764
|
guard: ({
|
|
448
765
|
snapshot,
|
|
449
766
|
event
|
|
450
|
-
}) => !(!
|
|
767
|
+
}) => !(!selector_isSelectingEntireBlocks.getFocusTextBlock(snapshot) || !util_mergeTextBlocks.isTextBlock(snapshot.context, event.block)),
|
|
451
768
|
actions: [({
|
|
452
769
|
event
|
|
453
|
-
}) => [
|
|
770
|
+
}) => [behaviors_index.execute({
|
|
454
771
|
type: "insert.block",
|
|
455
772
|
block: event.block,
|
|
456
773
|
placement: "auto",
|
|
@@ -461,7 +778,7 @@ const oneLineBehaviors = [
|
|
|
461
778
|
* Fallback Behavior to avoid `insert.block` in case the Behaviors above all
|
|
462
779
|
* end up with a falsy guard.
|
|
463
780
|
*/
|
|
464
|
-
|
|
781
|
+
behaviors_index.defineBehavior({
|
|
465
782
|
on: "insert.block",
|
|
466
783
|
actions: []
|
|
467
784
|
}),
|
|
@@ -469,7 +786,7 @@ const oneLineBehaviors = [
|
|
|
469
786
|
* If multiple blocks are inserted, then the non-text blocks are filtered out
|
|
470
787
|
* and the text blocks are merged into one block
|
|
471
788
|
*/
|
|
472
|
-
|
|
789
|
+
behaviors_index.defineBehavior({
|
|
473
790
|
on: "insert.blocks",
|
|
474
791
|
guard: ({
|
|
475
792
|
snapshot,
|
|
@@ -485,7 +802,7 @@ const oneLineBehaviors = [
|
|
|
485
802
|
actions: [
|
|
486
803
|
// `insert.block` is raised so the Behavior above can handle the
|
|
487
804
|
// insertion
|
|
488
|
-
(_, block) => [
|
|
805
|
+
(_, block) => [behaviors_index.raise({
|
|
489
806
|
type: "insert.block",
|
|
490
807
|
block,
|
|
491
808
|
placement: "auto"
|
|
@@ -496,7 +813,7 @@ const oneLineBehaviors = [
|
|
|
496
813
|
* Fallback Behavior to avoid `insert.blocks` in case the Behavior above
|
|
497
814
|
* ends up with a falsy guard.
|
|
498
815
|
*/
|
|
499
|
-
|
|
816
|
+
behaviors_index.defineBehavior({
|
|
500
817
|
on: "insert.blocks",
|
|
501
818
|
actions: []
|
|
502
819
|
})
|