@portabletext/editor 2.7.2 → 2.8.1
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/selector.is-selecting-entire-blocks.cjs +3 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs +10 -4
- package/lib/_chunks-cjs/selector.is-selection-expanded.cjs.map +1 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +0 -1
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.slice-blocks.cjs +60 -9
- package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +149 -149
- package/lib/_chunks-dts/behavior.types.action.d.ts +86 -86
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +4 -2
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +10 -4
- package/lib/_chunks-es/selector.is-selection-expanded.js.map +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +0 -1
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/_chunks-es/util.slice-blocks.js +56 -8
- package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
- package/lib/index.cjs +94 -131
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +90 -128
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/selectors/index.d.cts +13 -3
- package/lib/selectors/index.d.ts +13 -3
- package/package.json +13 -14
- package/src/behaviors/behavior.abstract.insert.ts +58 -1
- package/src/behaviors/behavior.abstract.split.ts +0 -1
- package/src/behaviors/behavior.core.annotations.ts +24 -2
- package/src/behaviors/behavior.core.ts +1 -1
- package/src/behaviors/behavior.types.event.ts +18 -18
- package/src/converters/converter.portable-text.ts +0 -1
- package/src/converters/converter.text-html.serialize.test.ts +27 -17
- package/src/converters/converter.text-html.ts +0 -1
- package/src/converters/converter.text-plain.test.ts +1 -1
- package/src/converters/converter.text-plain.ts +0 -1
- package/src/editor/Editable.tsx +0 -1
- package/src/editor/plugins/createWithEditableAPI.ts +16 -0
- package/src/internal-utils/parse-blocks.test.ts +23 -23
- package/src/internal-utils/parse-blocks.ts +13 -24
- package/src/internal-utils/test-editor.tsx +15 -21
- package/src/operations/behavior.operation.annotation.add.ts +2 -13
- package/src/operations/behavior.operation.block.set.ts +1 -1
- package/src/operations/behavior.operation.block.unset.ts +2 -2
- package/src/operations/behavior.operation.insert.block.ts +1 -1
- package/src/operations/behavior.operations.ts +0 -18
- package/src/plugins/plugin.internal.auto-close-brackets.test.tsx +25 -71
- package/src/plugins/plugin.markdown.test.tsx +12 -30
- package/src/selectors/selector.get-selected-value.test.ts +748 -0
- package/src/selectors/selector.get-selected-value.ts +28 -7
- package/src/selectors/selector.get-trimmed-selection.test.ts +0 -1
- package/src/selectors/selector.is-active-annotation.test.ts +320 -0
- package/src/selectors/selector.is-active-annotation.ts +24 -0
- package/src/utils/util.merge-text-blocks.ts +1 -1
- package/src/utils/util.slice-blocks.ts +36 -3
- package/src/editor/__tests__/PortableTextEditor.test.tsx +0 -430
- package/src/editor/__tests__/PortableTextEditorTester.tsx +0 -58
- package/src/editor/__tests__/RangeDecorations.test.tsx +0 -213
- package/src/editor/__tests__/insert-block.test.tsx +0 -224
- package/src/editor/__tests__/self-solving.test.tsx +0 -183
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +0 -298
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +0 -177
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +0 -538
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +0 -162
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +0 -65
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +0 -612
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +0 -103
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +0 -147
- package/src/internal-utils/__tests__/valueNormalization.test.tsx +0 -79
- package/src/operations/behavior.operation.insert-inline-object.ts +0 -59
- package/src/operations/behavior.operation.insert-span.ts +0 -48
- package/src/utils/util.slice-blocks.test.ts +0 -465
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"),
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$f = require("debug"), slateDom = require("slate-dom"), util_sliceBlocks = require("./_chunks-cjs/util.slice-blocks.cjs"), util_isSelectionCollapsed = require("./_chunks-cjs/util.is-selection-collapsed.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isSelectionExpanded = require("./_chunks-cjs/selector.is-selection-expanded.cjs"), selector_isSelectingEntireBlocks = require("./_chunks-cjs/selector.is-selecting-entire-blocks.cjs"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), xstate = require("xstate"), sanityBridge = require("@portabletext/sanity-bridge"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), isPlainObject = require("lodash/isPlainObject.js"), rxjs = require("rxjs");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual),
|
|
7
|
+
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$f), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(4), editor = useEditor.useEditor();
|
|
10
10
|
let t0, t1;
|
|
@@ -740,28 +740,9 @@ function getDragSelection({
|
|
|
740
740
|
}
|
|
741
741
|
return dragSelection;
|
|
742
742
|
}
|
|
743
|
-
const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
|
|
744
|
-
let table;
|
|
745
|
-
return () => {
|
|
746
|
-
if (table)
|
|
747
|
-
return table;
|
|
748
|
-
table = [];
|
|
749
|
-
for (let i = 0; i < 256; ++i)
|
|
750
|
-
table[i] = (i + 256).toString(16).slice(1);
|
|
751
|
-
return table;
|
|
752
|
-
};
|
|
753
|
-
})();
|
|
754
|
-
function whatwgRNG(length = 16) {
|
|
755
|
-
const rnds8 = new Uint8Array(length);
|
|
756
|
-
return getRandomValues__default.default(rnds8), rnds8;
|
|
757
|
-
}
|
|
758
|
-
function randomKey(length) {
|
|
759
|
-
const table = getByteHexTable();
|
|
760
|
-
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
761
|
-
}
|
|
762
743
|
function createEditorPriority(config) {
|
|
763
744
|
return {
|
|
764
|
-
id: defaultKeyGenerator(),
|
|
745
|
+
id: util_sliceBlocks.defaultKeyGenerator(),
|
|
765
746
|
name: config?.name,
|
|
766
747
|
reference: config?.reference
|
|
767
748
|
};
|
|
@@ -1938,7 +1919,6 @@ const RelayActorContext = React.createContext({}), debug$d = debugWithName("comp
|
|
|
1938
1919
|
},
|
|
1939
1920
|
blocks: result_1.insert,
|
|
1940
1921
|
options: {
|
|
1941
|
-
refreshKeys: !1,
|
|
1942
1922
|
validateFields: !1
|
|
1943
1923
|
}
|
|
1944
1924
|
}),
|
|
@@ -2403,7 +2383,6 @@ const converterJson = {
|
|
|
2403
2383
|
context: snapshot.context,
|
|
2404
2384
|
block,
|
|
2405
2385
|
options: {
|
|
2406
|
-
refreshKeys: !1,
|
|
2407
2386
|
validateFields: !1
|
|
2408
2387
|
}
|
|
2409
2388
|
});
|
|
@@ -2466,7 +2445,6 @@ function createConverterTextHtml(legacySchema) {
|
|
|
2466
2445
|
context: snapshot.context,
|
|
2467
2446
|
block,
|
|
2468
2447
|
options: {
|
|
2469
|
-
refreshKeys: !1,
|
|
2470
2448
|
validateFields: !1
|
|
2471
2449
|
}
|
|
2472
2450
|
});
|
|
@@ -2514,7 +2492,6 @@ function createConverterTextPlain(legacySchema) {
|
|
|
2514
2492
|
context: snapshot.context,
|
|
2515
2493
|
block,
|
|
2516
2494
|
options: {
|
|
2517
|
-
refreshKeys: !1,
|
|
2518
2495
|
validateFields: !1
|
|
2519
2496
|
}
|
|
2520
2497
|
});
|
|
@@ -3699,7 +3676,7 @@ function withUndoStep(editor, fn) {
|
|
|
3699
3676
|
return;
|
|
3700
3677
|
}
|
|
3701
3678
|
CURRENT_UNDO_STEP.set(editor, current ?? {
|
|
3702
|
-
undoStepId: defaultKeyGenerator()
|
|
3679
|
+
undoStepId: util_sliceBlocks.defaultKeyGenerator()
|
|
3703
3680
|
}), fn(), CURRENT_UNDO_STEP.set(editor, void 0);
|
|
3704
3681
|
}
|
|
3705
3682
|
function getCurrentUndoStepId(editor) {
|
|
@@ -3977,7 +3954,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
3977
3954
|
},
|
|
3978
3955
|
context,
|
|
3979
3956
|
options: {
|
|
3980
|
-
refreshKeys: !1,
|
|
3981
3957
|
validateFields: !0
|
|
3982
3958
|
}
|
|
3983
3959
|
});
|
|
@@ -4016,9 +3992,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
4016
3992
|
for (const [span, path] of children) {
|
|
4017
3993
|
if (!editor.isTextSpan(span) || !slate.Range.includes(editor.selection, path))
|
|
4018
3994
|
continue;
|
|
4019
|
-
const marks = span.marks ?? []
|
|
3995
|
+
const marks = span.marks ?? [];
|
|
4020
3996
|
slate.Transforms.setNodes(editor, {
|
|
4021
|
-
marks: [...marks
|
|
3997
|
+
marks: [...marks, annotationKey]
|
|
4022
3998
|
}, {
|
|
4023
3999
|
at: path
|
|
4024
4000
|
}), spanPath = [{
|
|
@@ -4140,7 +4116,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
4140
4116
|
...filteredProps
|
|
4141
4117
|
},
|
|
4142
4118
|
options: {
|
|
4143
|
-
refreshKeys: !1,
|
|
4144
4119
|
validateFields: !0
|
|
4145
4120
|
}
|
|
4146
4121
|
});
|
|
@@ -4190,7 +4165,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
4190
4165
|
context,
|
|
4191
4166
|
block: omit__default.default(parsedBlock, propsToRemove),
|
|
4192
4167
|
options: {
|
|
4193
|
-
refreshKeys: !1,
|
|
4194
4168
|
validateFields: !0
|
|
4195
4169
|
}
|
|
4196
4170
|
});
|
|
@@ -4208,7 +4182,6 @@ const addAnnotationOperationImplementation = ({
|
|
|
4208
4182
|
context,
|
|
4209
4183
|
block: omit__default.default(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
|
|
4210
4184
|
options: {
|
|
4211
|
-
refreshKeys: !1,
|
|
4212
4185
|
validateFields: !0
|
|
4213
4186
|
}
|
|
4214
4187
|
});
|
|
@@ -4589,77 +4562,7 @@ function domRectsIntersect(rect, compareRect) {
|
|
|
4589
4562
|
const middle = (compareRect.top + compareRect.bottom) / 2;
|
|
4590
4563
|
return rect.top <= middle && rect.bottom >= middle;
|
|
4591
4564
|
}
|
|
4592
|
-
const
|
|
4593
|
-
context,
|
|
4594
|
-
operation
|
|
4595
|
-
}) => {
|
|
4596
|
-
const parsedInlineObject = util_sliceBlocks.parseInlineObject({
|
|
4597
|
-
context,
|
|
4598
|
-
inlineObject: {
|
|
4599
|
-
_type: operation.inlineObject.name,
|
|
4600
|
-
...operation.inlineObject.value ?? {}
|
|
4601
|
-
},
|
|
4602
|
-
options: {
|
|
4603
|
-
refreshKeys: !1,
|
|
4604
|
-
validateFields: !0
|
|
4605
|
-
}
|
|
4606
|
-
});
|
|
4607
|
-
if (!parsedInlineObject)
|
|
4608
|
-
throw new Error(`Failed to parse inline object ${JSON.stringify(operation.inlineObject)}`);
|
|
4609
|
-
if (!operation.editor.selection) {
|
|
4610
|
-
console.error("Unable to insert inline object without selection");
|
|
4611
|
-
return;
|
|
4612
|
-
}
|
|
4613
|
-
const [focusTextBlock] = Array.from(slate.Editor.nodes(operation.editor, {
|
|
4614
|
-
at: operation.editor.selection.focus.path,
|
|
4615
|
-
match: (node) => operation.editor.isTextBlock(node)
|
|
4616
|
-
})).at(0) ?? [void 0, void 0];
|
|
4617
|
-
if (!focusTextBlock) {
|
|
4618
|
-
console.error("Unable to perform action without focus text block");
|
|
4619
|
-
return;
|
|
4620
|
-
}
|
|
4621
|
-
const child = toSlateValue([{
|
|
4622
|
-
_type: context.schema.block.name,
|
|
4623
|
-
_key: context.keyGenerator(),
|
|
4624
|
-
children: [parsedInlineObject]
|
|
4625
|
-
}], {
|
|
4626
|
-
schemaTypes: context.schema
|
|
4627
|
-
}).at(0)?.children.at(0);
|
|
4628
|
-
if (!child) {
|
|
4629
|
-
console.error("Unable to insert inline object");
|
|
4630
|
-
return;
|
|
4631
|
-
}
|
|
4632
|
-
slate.Transforms.insertNodes(operation.editor, child);
|
|
4633
|
-
}, insertSpanOperationImplementation = ({
|
|
4634
|
-
context,
|
|
4635
|
-
operation
|
|
4636
|
-
}) => {
|
|
4637
|
-
if (!operation.editor.selection) {
|
|
4638
|
-
console.error("Unable to perform action without selection", operation);
|
|
4639
|
-
return;
|
|
4640
|
-
}
|
|
4641
|
-
const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(operation.editor, {
|
|
4642
|
-
at: operation.editor.selection.focus.path,
|
|
4643
|
-
match: (node) => operation.editor.isTextBlock(node)
|
|
4644
|
-
}))[0] ?? [void 0, void 0];
|
|
4645
|
-
if (!focusBlock || !focusBlockPath) {
|
|
4646
|
-
console.error("Unable to perform action without focus block", operation);
|
|
4647
|
-
return;
|
|
4648
|
-
}
|
|
4649
|
-
const markDefs = focusBlock.markDefs ?? [], annotations = operation.annotations ? operation.annotations.map((annotation) => ({
|
|
4650
|
-
_type: annotation.name,
|
|
4651
|
-
_key: context.keyGenerator(),
|
|
4652
|
-
...annotation.value
|
|
4653
|
-
})) : void 0;
|
|
4654
|
-
annotations && annotations.length > 0 && slate.Transforms.setNodes(operation.editor, {
|
|
4655
|
-
markDefs: [...markDefs, ...annotations]
|
|
4656
|
-
}), slate.Transforms.insertNodes(operation.editor, {
|
|
4657
|
-
_type: "span",
|
|
4658
|
-
_key: context.keyGenerator(),
|
|
4659
|
-
text: operation.text,
|
|
4660
|
-
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...operation.decorators ?? []]
|
|
4661
|
-
});
|
|
4662
|
-
}, insertBlockOperationImplementation = ({
|
|
4565
|
+
const insertBlockOperationImplementation = ({
|
|
4663
4566
|
context,
|
|
4664
4567
|
operation
|
|
4665
4568
|
}) => {
|
|
@@ -4667,7 +4570,6 @@ const insertInlineObjectOperationImplementation = ({
|
|
|
4667
4570
|
block: operation.block,
|
|
4668
4571
|
context,
|
|
4669
4572
|
options: {
|
|
4670
|
-
refreshKeys: !1,
|
|
4671
4573
|
validateFields: !0
|
|
4672
4574
|
}
|
|
4673
4575
|
});
|
|
@@ -4943,8 +4845,6 @@ const moveBackwardOperationImplementation = ({
|
|
|
4943
4845
|
"history.redo": historyRedoOperationImplementation,
|
|
4944
4846
|
"history.undo": historyUndoOperationImplementation,
|
|
4945
4847
|
"insert.block": insertBlockOperationImplementation,
|
|
4946
|
-
"insert.inline object": insertInlineObjectOperationImplementation,
|
|
4947
|
-
"insert.span": insertSpanOperationImplementation,
|
|
4948
4848
|
"insert.text": insertTextOperationImplementation,
|
|
4949
4849
|
"move.backward": moveBackwardOperationImplementation,
|
|
4950
4850
|
"move.block": moveBlockOperationImplementation,
|
|
@@ -5041,20 +4941,6 @@ function performOperation({
|
|
|
5041
4941
|
});
|
|
5042
4942
|
break;
|
|
5043
4943
|
}
|
|
5044
|
-
case "insert.inline object": {
|
|
5045
|
-
behaviorOperationImplementations["insert.inline object"]({
|
|
5046
|
-
context,
|
|
5047
|
-
operation
|
|
5048
|
-
});
|
|
5049
|
-
break;
|
|
5050
|
-
}
|
|
5051
|
-
case "insert.span": {
|
|
5052
|
-
behaviorOperationImplementations["insert.span"]({
|
|
5053
|
-
context,
|
|
5054
|
-
operation
|
|
5055
|
-
});
|
|
5056
|
-
break;
|
|
5057
|
-
}
|
|
5058
4944
|
case "insert.text": {
|
|
5059
4945
|
behaviorOperationImplementations["insert.text"]({
|
|
5060
4946
|
context,
|
|
@@ -5097,7 +4983,7 @@ function performOperation({
|
|
|
5097
4983
|
}
|
|
5098
4984
|
const CURRENT_OPERATION_ID = /* @__PURE__ */ new WeakMap();
|
|
5099
4985
|
function withApplyingBehaviorOperations(editor, fn) {
|
|
5100
|
-
CURRENT_OPERATION_ID.set(editor, defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
4986
|
+
CURRENT_OPERATION_ID.set(editor, util_sliceBlocks.defaultKeyGenerator()), slate.Editor.withoutNormalizing(editor, fn), CURRENT_OPERATION_ID.set(editor, void 0);
|
|
5101
4987
|
}
|
|
5102
4988
|
function getCurrentOperationId(editor) {
|
|
5103
4989
|
return CURRENT_OPERATION_ID.get(editor);
|
|
@@ -6683,9 +6569,24 @@ const addAnnotationOnCollapsedSelection = behaviors_index.defineBehavior({
|
|
|
6683
6569
|
type: "annotation.add",
|
|
6684
6570
|
annotation: event.annotation
|
|
6685
6571
|
})]]
|
|
6686
|
-
}),
|
|
6687
|
-
|
|
6688
|
-
|
|
6572
|
+
}), preventOverlappingAnnotations = behaviors_index.defineBehavior({
|
|
6573
|
+
// Given an `annotation.add` event
|
|
6574
|
+
on: "annotation.add",
|
|
6575
|
+
// When the annotation is active in the selection
|
|
6576
|
+
guard: ({
|
|
6577
|
+
snapshot,
|
|
6578
|
+
event
|
|
6579
|
+
}) => selector_isSelectingEntireBlocks.isActiveAnnotation(event.annotation.name, {
|
|
6580
|
+
mode: "partial"
|
|
6581
|
+
})(snapshot),
|
|
6582
|
+
// Then the existing annotation is removed
|
|
6583
|
+
actions: [({
|
|
6584
|
+
event
|
|
6585
|
+
}) => [behaviors_index.raise({
|
|
6586
|
+
type: "annotation.remove",
|
|
6587
|
+
annotation: event.annotation
|
|
6588
|
+
}), behaviors_index.raise(event)]]
|
|
6589
|
+
}), coreAnnotationBehaviors = [addAnnotationOnCollapsedSelection, preventOverlappingAnnotations], defaultKeyboardShortcuts = {
|
|
6689
6590
|
arrowDown: keyboardShortcuts.createKeyboardShortcut({
|
|
6690
6591
|
default: [{
|
|
6691
6592
|
key: "ArrowDown",
|
|
@@ -7813,7 +7714,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
7813
7714
|
inheritListLevel,
|
|
7814
7715
|
inheritListItem,
|
|
7815
7716
|
inheritListProperties
|
|
7816
|
-
}, coreBehaviorsConfig = [coreAnnotationBehaviors
|
|
7717
|
+
}, coreBehaviorsConfig = [...coreAnnotationBehaviors, 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.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
|
|
7817
7718
|
behavior,
|
|
7818
7719
|
priority: corePriority
|
|
7819
7720
|
})), abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
@@ -8447,6 +8348,23 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8447
8348
|
actions: [() => [behaviors_index.raise({
|
|
8448
8349
|
type: "split"
|
|
8449
8350
|
})]]
|
|
8351
|
+
}), behaviors_index.defineBehavior({
|
|
8352
|
+
on: "insert.inline object",
|
|
8353
|
+
actions: [({
|
|
8354
|
+
snapshot,
|
|
8355
|
+
event
|
|
8356
|
+
}) => [behaviors_index.execute({
|
|
8357
|
+
type: "insert.block",
|
|
8358
|
+
block: {
|
|
8359
|
+
_type: snapshot.context.schema.block.name,
|
|
8360
|
+
children: [{
|
|
8361
|
+
_type: event.inlineObject.name,
|
|
8362
|
+
...event.inlineObject.value
|
|
8363
|
+
}]
|
|
8364
|
+
},
|
|
8365
|
+
placement: "auto",
|
|
8366
|
+
select: "end"
|
|
8367
|
+
})]]
|
|
8450
8368
|
}), behaviors_index.defineBehavior({
|
|
8451
8369
|
on: "insert.soft break",
|
|
8452
8370
|
actions: [() => [behaviors_index.raise({
|
|
@@ -8454,6 +8372,37 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8454
8372
|
text: `
|
|
8455
8373
|
`
|
|
8456
8374
|
})]]
|
|
8375
|
+
}), behaviors_index.defineBehavior({
|
|
8376
|
+
on: "insert.span",
|
|
8377
|
+
guard: ({
|
|
8378
|
+
snapshot,
|
|
8379
|
+
event
|
|
8380
|
+
}) => ({
|
|
8381
|
+
markDefs: event.annotations?.map((annotation) => ({
|
|
8382
|
+
_type: annotation.name,
|
|
8383
|
+
_key: snapshot.context.keyGenerator(),
|
|
8384
|
+
...annotation.value
|
|
8385
|
+
})) ?? []
|
|
8386
|
+
}),
|
|
8387
|
+
actions: [({
|
|
8388
|
+
snapshot,
|
|
8389
|
+
event
|
|
8390
|
+
}, {
|
|
8391
|
+
markDefs
|
|
8392
|
+
}) => [behaviors_index.execute({
|
|
8393
|
+
type: "insert.block",
|
|
8394
|
+
block: {
|
|
8395
|
+
_type: snapshot.context.schema.block.name,
|
|
8396
|
+
children: [{
|
|
8397
|
+
_type: snapshot.context.schema.span.name,
|
|
8398
|
+
text: event.text,
|
|
8399
|
+
marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
|
|
8400
|
+
}],
|
|
8401
|
+
markDefs
|
|
8402
|
+
},
|
|
8403
|
+
placement: "auto",
|
|
8404
|
+
select: "end"
|
|
8405
|
+
})]]
|
|
8457
8406
|
})], abstractKeyboardBehaviors = [
|
|
8458
8407
|
/**
|
|
8459
8408
|
* Allow raising an `insert.break` event when pressing Enter on an inline
|
|
@@ -8893,7 +8842,6 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
8893
8842
|
}),
|
|
8894
8843
|
context: snapshot.context,
|
|
8895
8844
|
options: {
|
|
8896
|
-
refreshKeys: !1,
|
|
8897
8845
|
validateFields: !1
|
|
8898
8846
|
}
|
|
8899
8847
|
});
|
|
@@ -9066,7 +9014,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
9066
9014
|
function isSyntheticBehaviorEvent(event) {
|
|
9067
9015
|
return !isCustomBehaviorEvent(event) && !isNativeBehaviorEvent(event) && !isAbstractBehaviorEvent(event);
|
|
9068
9016
|
}
|
|
9069
|
-
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.soft break", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
9017
|
+
const abstractBehaviorEventTypes = ["annotation.set", "annotation.toggle", "decorator.toggle", "delete.backward", "delete.block", "delete.child", "delete.forward", "delete.text", "deserialize", "deserialize.data", "deserialization.success", "deserialization.failure", "insert.blocks", "insert.break", "insert.inline object", "insert.soft break", "insert.span", "list item.add", "list item.remove", "list item.toggle", "move.block down", "move.block up", "select.previous block", "select.next block", "serialize", "serialize.data", "serialization.success", "serialization.failure", "split", "style.add", "style.remove", "style.toggle"];
|
|
9070
9018
|
function isAbstractBehaviorEvent(event) {
|
|
9071
9019
|
return abstractBehaviorEventTypes.includes(event.type);
|
|
9072
9020
|
}
|
|
@@ -10341,7 +10289,22 @@ function createEditableAPI(editor, editorActor) {
|
|
|
10341
10289
|
},
|
|
10342
10290
|
addAnnotation: (type, value) => {
|
|
10343
10291
|
let paths;
|
|
10344
|
-
|
|
10292
|
+
const snapshot = getEditorSnapshot({
|
|
10293
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
10294
|
+
slateEditorInstance: editor
|
|
10295
|
+
});
|
|
10296
|
+
return selector_isSelectingEntireBlocks.isActiveAnnotation(type.name, {
|
|
10297
|
+
mode: "partial"
|
|
10298
|
+
})(snapshot) && editorActor.send({
|
|
10299
|
+
type: "behavior event",
|
|
10300
|
+
behaviorEvent: {
|
|
10301
|
+
type: "annotation.remove",
|
|
10302
|
+
annotation: {
|
|
10303
|
+
name: type.name
|
|
10304
|
+
}
|
|
10305
|
+
},
|
|
10306
|
+
editor
|
|
10307
|
+
}), slate.Editor.withoutNormalizing(editor, () => {
|
|
10345
10308
|
paths = addAnnotationOperationImplementation({
|
|
10346
10309
|
context: {
|
|
10347
10310
|
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
@@ -11469,7 +11432,7 @@ function editorConfigToMachineInput(config) {
|
|
|
11469
11432
|
return {
|
|
11470
11433
|
converters: createCoreConverters(legacySchema),
|
|
11471
11434
|
getLegacySchema: () => legacySchema,
|
|
11472
|
-
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
11435
|
+
keyGenerator: config.keyGenerator ?? util_sliceBlocks.defaultKeyGenerator,
|
|
11473
11436
|
maxBlocks: config.maxBlocks,
|
|
11474
11437
|
readOnly: config.readOnly,
|
|
11475
11438
|
schema: schema2,
|
|
@@ -12135,6 +12098,7 @@ const usePortableTextEditorSelection = () => {
|
|
|
12135
12098
|
}, t1 = [editorActor], $[0] = editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), React.useEffect(t0, t1), selection;
|
|
12136
12099
|
};
|
|
12137
12100
|
exports.useEditor = useEditor.useEditor;
|
|
12101
|
+
exports.keyGenerator = util_sliceBlocks.defaultKeyGenerator;
|
|
12138
12102
|
Object.defineProperty(exports, "defineSchema", {
|
|
12139
12103
|
enumerable: !0,
|
|
12140
12104
|
get: function() {
|
|
@@ -12145,7 +12109,6 @@ exports.EditorEventListener = EditorEventListener;
|
|
|
12145
12109
|
exports.EditorProvider = EditorProvider;
|
|
12146
12110
|
exports.PortableTextEditable = PortableTextEditable;
|
|
12147
12111
|
exports.PortableTextEditor = PortableTextEditor;
|
|
12148
|
-
exports.keyGenerator = defaultKeyGenerator;
|
|
12149
12112
|
exports.useEditorSelector = useEditorSelector;
|
|
12150
12113
|
exports.usePortableTextEditor = usePortableTextEditor;
|
|
12151
12114
|
exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
|