@portabletext/editor 1.52.5 → 1.52.7
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/index.cjs +28 -53
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +30 -55
- package/lib/index.js.map +1 -1
- package/package.json +5 -6
- package/src/editor/Editable.tsx +14 -3
- package/src/editor/plugins/createWithEditableAPI.ts +13 -64
- package/src/editor/plugins/with-plugins.ts +8 -8
- package/src/internal-utils/mark-state.ts +28 -6
- package/src/internal-utils/slate-utils.ts +0 -21
package/lib/index.cjs
CHANGED
|
@@ -166,20 +166,6 @@ function getFocusSpan({
|
|
|
166
166
|
}
|
|
167
167
|
return [void 0, void 0];
|
|
168
168
|
}
|
|
169
|
-
function getSelectedSpans({
|
|
170
|
-
editor
|
|
171
|
-
}) {
|
|
172
|
-
if (!editor.selection)
|
|
173
|
-
return [];
|
|
174
|
-
try {
|
|
175
|
-
return Array.from(slate.Editor.nodes(editor, {
|
|
176
|
-
at: editor.selection,
|
|
177
|
-
match: (node) => editor.isTextSpan(node)
|
|
178
|
-
}));
|
|
179
|
-
} catch {
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
169
|
function getSelectionStartBlock({
|
|
184
170
|
editor
|
|
185
171
|
}) {
|
|
@@ -4629,12 +4615,23 @@ function getMarkState({
|
|
|
4629
4615
|
if (!block || !editor.isTextBlock(block) || !span)
|
|
4630
4616
|
return;
|
|
4631
4617
|
if (slate.Range.isExpanded(editor.selection)) {
|
|
4632
|
-
const
|
|
4633
|
-
|
|
4618
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
4619
|
+
schema: schema2,
|
|
4620
|
+
editor,
|
|
4621
|
+
range: editor.selection
|
|
4622
|
+
}) : null, selectedSpans = selector_isSelectingEntireBlocks.getSelectedSpans({
|
|
4623
|
+
context: {
|
|
4624
|
+
value: editor.value,
|
|
4625
|
+
selection,
|
|
4626
|
+
schema: schema2,
|
|
4627
|
+
converters: [],
|
|
4628
|
+
keyGenerator: () => "",
|
|
4629
|
+
readOnly: !1
|
|
4630
|
+
}
|
|
4634
4631
|
});
|
|
4635
4632
|
let index = 0, marks2 = [];
|
|
4636
|
-
for (const
|
|
4637
|
-
index === 0 ? marks2 = span2.marks ?? [] : (span2.marks?.length === 0 || (span2.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4633
|
+
for (const span2 of selectedSpans)
|
|
4634
|
+
index === 0 ? marks2 = span2.node.marks ?? [] : (span2.node.marks?.length === 0 || (span2.node.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4638
4635
|
return {
|
|
4639
4636
|
state: "unchanged",
|
|
4640
4637
|
marks: marks2
|
|
@@ -5040,10 +5037,10 @@ const withPlugins = (editor, options) => {
|
|
|
5040
5037
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5041
5038
|
editorActor
|
|
5042
5039
|
});
|
|
5043
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateSelection({
|
|
5040
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
5044
5041
|
editorActor,
|
|
5045
|
-
editor:
|
|
5046
|
-
}))))))))));
|
|
5042
|
+
editor: e
|
|
5043
|
+
}))))))))))));
|
|
5047
5044
|
}, debug$a = debugWithName("setup");
|
|
5048
5045
|
function createSlateEditor(config) {
|
|
5049
5046
|
debug$a("Creating new Slate editor instance");
|
|
@@ -8311,12 +8308,13 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8311
8308
|
return [];
|
|
8312
8309
|
}
|
|
8313
8310
|
},
|
|
8314
|
-
isAnnotationActive: (annotationType) =>
|
|
8315
|
-
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
}
|
|
8319
|
-
|
|
8311
|
+
isAnnotationActive: (annotationType) => {
|
|
8312
|
+
const snapshot = getEditorSnapshot({
|
|
8313
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8314
|
+
slateEditorInstance: editor
|
|
8315
|
+
});
|
|
8316
|
+
return selector_isSelectingEntireBlocks.isActiveAnnotation(annotationType)(snapshot);
|
|
8317
|
+
},
|
|
8320
8318
|
addAnnotation: (type, value) => {
|
|
8321
8319
|
let paths;
|
|
8322
8320
|
return slate.Editor.withoutNormalizing(editor, () => {
|
|
@@ -8403,29 +8401,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8403
8401
|
}
|
|
8404
8402
|
};
|
|
8405
8403
|
}
|
|
8406
|
-
function isAnnotationActive({
|
|
8407
|
-
editor,
|
|
8408
|
-
annotation
|
|
8409
|
-
}) {
|
|
8410
|
-
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
8411
|
-
return !1;
|
|
8412
|
-
try {
|
|
8413
|
-
const spans = [...slate.Editor.nodes(editor, {
|
|
8414
|
-
at: editor.selection,
|
|
8415
|
-
match: (node) => slate.Text.isText(node)
|
|
8416
|
-
})];
|
|
8417
|
-
if (spans.length === 0 || spans.some(([span]) => !types.isPortableTextSpan(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
8418
|
-
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
8419
|
-
const [block] = slate.Editor.node(editor, path, {
|
|
8420
|
-
depth: 1
|
|
8421
|
-
});
|
|
8422
|
-
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
8423
|
-
}, []);
|
|
8424
|
-
return spans.every(([span]) => types.isPortableTextSpan(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
8425
|
-
} catch {
|
|
8426
|
-
return !1;
|
|
8427
|
-
}
|
|
8428
|
-
}
|
|
8429
8404
|
const relayMachine = xstate.setup({
|
|
8430
8405
|
types: {
|
|
8431
8406
|
context: {},
|
|
@@ -10767,11 +10742,11 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
10767
10742
|
}
|
|
10768
10743
|
debug("No result from custom paste handler, pasting normally");
|
|
10769
10744
|
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
10770
|
-
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || relayActor.send({
|
|
10745
|
+
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
10771
10746
|
type: "focused",
|
|
10772
10747
|
event: event_2
|
|
10773
|
-
});
|
|
10774
|
-
}, [onFocus, relayActor]), handleClick = React.useCallback((event_3) => {
|
|
10748
|
+
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
10749
|
+
}, [editorActor, onFocus, relayActor, slateEditor]), handleClick = React.useCallback((event_3) => {
|
|
10775
10750
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10776
10751
|
return;
|
|
10777
10752
|
const position_3 = getEventPosition({
|