@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.js
CHANGED
|
@@ -13,9 +13,9 @@ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, isTextBlock, parseBl
|
|
|
13
13
|
import { getBlockEndPoint, isEmptyTextBlock, isEqualSelectionPoints } from "./_chunks-es/util.is-equal-selection-points.js";
|
|
14
14
|
import { isSelectionCollapsed, selectionPointToBlockOffset } from "./_chunks-es/util.selection-point-to-block-offset.js";
|
|
15
15
|
import isEqual from "lodash/isEqual.js";
|
|
16
|
-
import { isKeySegment, defineType, defineField
|
|
16
|
+
import { isKeySegment, defineType, defineField } from "@sanity/types";
|
|
17
17
|
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, getFocusBlock as getFocusBlock$1, getFocusBlockObject, getPreviousBlock, getNextBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock } from "./_chunks-es/selector.is-selection-expanded.js";
|
|
18
|
-
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
18
|
+
import { getFocusInlineObject, isOverlappingSelection, isSelectingEntireBlocks, getTrimmedSelection, getSelectedSpans, getCaretWordSelection, isAtTheEndOfBlock, isAtTheStartOfBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations as getActiveAnnotations$1 } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
|
|
19
19
|
import getRandomValues from "get-random-values-esm";
|
|
20
20
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
21
21
|
import uniq from "lodash/uniq.js";
|
|
@@ -195,20 +195,6 @@ function getFocusSpan({
|
|
|
195
195
|
}
|
|
196
196
|
return [void 0, void 0];
|
|
197
197
|
}
|
|
198
|
-
function getSelectedSpans({
|
|
199
|
-
editor
|
|
200
|
-
}) {
|
|
201
|
-
if (!editor.selection)
|
|
202
|
-
return [];
|
|
203
|
-
try {
|
|
204
|
-
return Array.from(Editor.nodes(editor, {
|
|
205
|
-
at: editor.selection,
|
|
206
|
-
match: (node) => editor.isTextSpan(node)
|
|
207
|
-
}));
|
|
208
|
-
} catch {
|
|
209
|
-
return [];
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
198
|
function getSelectionStartBlock({
|
|
213
199
|
editor
|
|
214
200
|
}) {
|
|
@@ -4658,12 +4644,23 @@ function getMarkState({
|
|
|
4658
4644
|
if (!block || !editor.isTextBlock(block) || !span)
|
|
4659
4645
|
return;
|
|
4660
4646
|
if (Range.isExpanded(editor.selection)) {
|
|
4661
|
-
const
|
|
4662
|
-
|
|
4647
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
4648
|
+
schema,
|
|
4649
|
+
editor,
|
|
4650
|
+
range: editor.selection
|
|
4651
|
+
}) : null, selectedSpans = getSelectedSpans({
|
|
4652
|
+
context: {
|
|
4653
|
+
value: editor.value,
|
|
4654
|
+
selection,
|
|
4655
|
+
schema,
|
|
4656
|
+
converters: [],
|
|
4657
|
+
keyGenerator: () => "",
|
|
4658
|
+
readOnly: !1
|
|
4659
|
+
}
|
|
4663
4660
|
});
|
|
4664
4661
|
let index = 0, marks2 = [];
|
|
4665
|
-
for (const
|
|
4666
|
-
index === 0 ? marks2 = span2.marks ?? [] : (span2.marks?.length === 0 || (span2.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4662
|
+
for (const span2 of selectedSpans)
|
|
4663
|
+
index === 0 ? marks2 = span2.node.marks ?? [] : (span2.node.marks?.length === 0 || (span2.node.marks ?? [])?.some((mark) => !marks2.includes(mark))) && (marks2 = []), index++;
|
|
4667
4664
|
return {
|
|
4668
4665
|
state: "unchanged",
|
|
4669
4666
|
marks: marks2
|
|
@@ -5069,10 +5066,10 @@ const withPlugins = (editor, options) => {
|
|
|
5069
5066
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5070
5067
|
editorActor
|
|
5071
5068
|
});
|
|
5072
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateSelection({
|
|
5069
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, pluginUpdateSelection({
|
|
5073
5070
|
editorActor,
|
|
5074
|
-
editor:
|
|
5075
|
-
}))))))))));
|
|
5071
|
+
editor: e
|
|
5072
|
+
}))))))))))));
|
|
5076
5073
|
}, debug$a = debugWithName("setup");
|
|
5077
5074
|
function createSlateEditor(config) {
|
|
5078
5075
|
debug$a("Creating new Slate editor instance");
|
|
@@ -8340,12 +8337,13 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8340
8337
|
return [];
|
|
8341
8338
|
}
|
|
8342
8339
|
},
|
|
8343
|
-
isAnnotationActive: (annotationType) =>
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
}
|
|
8348
|
-
|
|
8340
|
+
isAnnotationActive: (annotationType) => {
|
|
8341
|
+
const snapshot = getEditorSnapshot({
|
|
8342
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
8343
|
+
slateEditorInstance: editor
|
|
8344
|
+
});
|
|
8345
|
+
return isActiveAnnotation(annotationType)(snapshot);
|
|
8346
|
+
},
|
|
8349
8347
|
addAnnotation: (type, value) => {
|
|
8350
8348
|
let paths;
|
|
8351
8349
|
return Editor.withoutNormalizing(editor, () => {
|
|
@@ -8432,29 +8430,6 @@ function createEditableAPI(editor, editorActor) {
|
|
|
8432
8430
|
}
|
|
8433
8431
|
};
|
|
8434
8432
|
}
|
|
8435
|
-
function isAnnotationActive({
|
|
8436
|
-
editor,
|
|
8437
|
-
annotation
|
|
8438
|
-
}) {
|
|
8439
|
-
if (!editor.selection || editor.selection.focus.path.length < 2)
|
|
8440
|
-
return !1;
|
|
8441
|
-
try {
|
|
8442
|
-
const spans = [...Editor.nodes(editor, {
|
|
8443
|
-
at: editor.selection,
|
|
8444
|
-
match: (node) => Text.isText(node)
|
|
8445
|
-
})];
|
|
8446
|
-
if (spans.length === 0 || spans.some(([span]) => !isPortableTextSpan$1(span) || !span.marks || span.marks?.length === 0)) return !1;
|
|
8447
|
-
const selectionMarkDefs = spans.reduce((accMarkDefs, [, path]) => {
|
|
8448
|
-
const [block] = Editor.node(editor, path, {
|
|
8449
|
-
depth: 1
|
|
8450
|
-
});
|
|
8451
|
-
return editor.isTextBlock(block) && block.markDefs ? [...accMarkDefs, ...block.markDefs] : accMarkDefs;
|
|
8452
|
-
}, []);
|
|
8453
|
-
return spans.every(([span]) => isPortableTextSpan$1(span) ? span.marks?.map((markKey) => selectionMarkDefs.find((def) => def?._key === markKey)?._type)?.includes(annotation.name) : !1);
|
|
8454
|
-
} catch {
|
|
8455
|
-
return !1;
|
|
8456
|
-
}
|
|
8457
|
-
}
|
|
8458
8433
|
const relayMachine = setup({
|
|
8459
8434
|
types: {
|
|
8460
8435
|
context: {},
|
|
@@ -10796,11 +10771,11 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10796
10771
|
}
|
|
10797
10772
|
debug("No result from custom paste handler, pasting normally");
|
|
10798
10773
|
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = useCallback((event_2) => {
|
|
10799
|
-
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || relayActor.send({
|
|
10774
|
+
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
10800
10775
|
type: "focused",
|
|
10801
10776
|
event: event_2
|
|
10802
|
-
});
|
|
10803
|
-
}, [onFocus, relayActor]), handleClick = useCallback((event_3) => {
|
|
10777
|
+
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
10778
|
+
}, [editorActor, onFocus, relayActor, slateEditor]), handleClick = useCallback((event_3) => {
|
|
10804
10779
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10805
10780
|
return;
|
|
10806
10781
|
const position_3 = getEventPosition({
|