@portabletext/editor 1.47.1 → 1.47.3
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/util.is-selection-collapsed.cjs +5 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +5 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/index.cjs +24 -18
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +25 -19
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +1 -4
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.js +3 -6
- package/lib/utils/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/Editable.tsx +42 -24
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var util_sliceBlocks = require("./util.slice-blocks.cjs");
|
|
2
3
|
function getSelectionEndPoint(selection) {
|
|
3
4
|
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
4
5
|
}
|
|
6
|
+
function isEqualSelections(a, b) {
|
|
7
|
+
return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
|
|
8
|
+
}
|
|
5
9
|
function isSelectionCollapsed(selection) {
|
|
6
10
|
return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
|
|
7
11
|
}
|
|
8
12
|
exports.getSelectionEndPoint = getSelectionEndPoint;
|
|
13
|
+
exports.isEqualSelections = isEqualSelections;
|
|
9
14
|
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
10
15
|
//# sourceMappingURL=util.is-selection-collapsed.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isSelectionCollapsed","path","join","offset"],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isEqualSelections","a","b","isEqualSelectionPoints","isSelectionCollapsed","path","join","offset"],"mappings":";;AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEH,QAAQI,EAAEJ,MAAM,KACzCK,wCAAuBF,EAAEF,OAAOG,EAAEH,KAAK;AAE3C;ACdO,SAASK,qBAAqBR,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOO,KAAKC,KAAAA,MAAWV,UAAUG,MAAMM,KAAKC,KAAAA,KACtDV,UAAUE,OAAOS,WAAWX,UAAUG,MAAMQ,SALrC;AAOX;;;;"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { isEqualSelectionPoints } from "./util.slice-blocks.js";
|
|
1
2
|
function getSelectionEndPoint(selection) {
|
|
2
3
|
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
3
4
|
}
|
|
5
|
+
function isEqualSelections(a, b) {
|
|
6
|
+
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
|
|
7
|
+
}
|
|
4
8
|
function isSelectionCollapsed(selection) {
|
|
5
9
|
return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
|
|
6
10
|
}
|
|
7
11
|
export {
|
|
8
12
|
getSelectionEndPoint,
|
|
13
|
+
isEqualSelections,
|
|
9
14
|
isSelectionCollapsed
|
|
10
15
|
};
|
|
11
16
|
//# sourceMappingURL=util.is-selection-collapsed.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-selection-collapsed.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isSelectionCollapsed","path","join","offset"],"mappings":"AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,
|
|
1
|
+
{"version":3,"file":"util.is-selection-collapsed.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.is-equal-selections.ts","../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["import type {EditorSelection, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionEndPoint<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n TEditorSelectionPoint extends\n EditorSelectionPoint | null = TEditorSelection extends NonNullable<EditorSelection>\n ? EditorSelectionPoint\n : null,\n>(selection: TEditorSelection): TEditorSelectionPoint {\n if (!selection) {\n return null as TEditorSelectionPoint\n }\n\n return (\n selection.backward ? selection.anchor : selection.focus\n ) as TEditorSelectionPoint\n}\n","import type {EditorSelection} from '../types/editor'\nimport {isEqualSelectionPoints} from './util.is-equal-selection-points'\n\n/**\n * @public\n */\nexport function isEqualSelections(a: EditorSelection, b: EditorSelection) {\n if (!a && !b) {\n return true\n }\n\n if (!a || !b) {\n return false\n }\n\n return (\n isEqualSelectionPoints(a.anchor, b.anchor) &&\n isEqualSelectionPoints(a.focus, b.focus)\n )\n}\n","import type {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function isSelectionCollapsed(selection: EditorSelection) {\n if (!selection) {\n return false\n }\n\n return (\n selection.anchor.path.join() === selection.focus.path.join() &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","isEqualSelections","a","b","isEqualSelectionPoints","isSelectionCollapsed","path","join","offset"],"mappings":";AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACbgBC,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEH,QAAQI,EAAEJ,MAAM,KACzCK,uBAAuBF,EAAEF,OAAOG,EAAEH,KAAK;AAE3C;ACdO,SAASK,qBAAqBR,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOO,KAAKC,KAAAA,MAAWV,UAAUG,MAAMM,KAAKC,KAAAA,KACtDV,UAAUE,OAAOS,WAAWX,UAAUG,MAAMQ,SALrC;AAOX;"}
|
package/lib/index.cjs
CHANGED
|
@@ -1036,18 +1036,18 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1036
1036
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
1037
1037
|
const editorActor = React.useContext(editorProvider.EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
1038
1038
|
"edit mode": "read only"
|
|
1039
|
-
})),
|
|
1039
|
+
})), slateEditor = slateReact.useSlate(), rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, {
|
|
1040
1040
|
input: {
|
|
1041
1041
|
rangeDecorations: rangeDecorations ?? [],
|
|
1042
1042
|
readOnly,
|
|
1043
|
-
schema:
|
|
1043
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1044
1044
|
slateEditor,
|
|
1045
1045
|
skipSetup: !editorActor.getSnapshot().matches({
|
|
1046
1046
|
setup: "setting up"
|
|
1047
1047
|
})
|
|
1048
1048
|
}
|
|
1049
1049
|
});
|
|
1050
|
-
react.useSelector(rangeDecorationsActor, (
|
|
1050
|
+
react.useSelector(rangeDecorationsActor, (s_0) => s_0.context.updateCount);
|
|
1051
1051
|
const decorate = React.useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1052
1052
|
React.useEffect(() => {
|
|
1053
1053
|
rangeDecorationsActor.send({
|
|
@@ -1059,9 +1059,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1059
1059
|
type: "range decorations updated",
|
|
1060
1060
|
rangeDecorations: rangeDecorations ?? []
|
|
1061
1061
|
});
|
|
1062
|
-
}, [rangeDecorationsActor, rangeDecorations])
|
|
1063
|
-
const blockTypeName = schemaTypes.block.name;
|
|
1064
|
-
React.useMemo(() => {
|
|
1062
|
+
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() => {
|
|
1065
1063
|
if (readOnly)
|
|
1066
1064
|
return debug("Editable is in read only mode"), slateEditor;
|
|
1067
1065
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
@@ -1081,10 +1079,10 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1081
1079
|
})), rendered;
|
|
1082
1080
|
}
|
|
1083
1081
|
return lProps.children;
|
|
1084
|
-
}, [editorActor, portableTextEditor
|
|
1082
|
+
}, [editorActor, portableTextEditor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), restoreSelectionFromProps = React.useCallback(() => {
|
|
1085
1083
|
if (propsSelection) {
|
|
1086
1084
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
1087
|
-
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children,
|
|
1085
|
+
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
1088
1086
|
if (normalizedSelection !== null) {
|
|
1089
1087
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
1090
1088
|
const slateRange = editorProvider.toSlateRange(normalizedSelection, slateEditor);
|
|
@@ -1094,7 +1092,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1094
1092
|
}), slateEditor.onChange());
|
|
1095
1093
|
}
|
|
1096
1094
|
}
|
|
1097
|
-
}, [
|
|
1095
|
+
}, [editorActor, propsSelection, slateEditor]);
|
|
1098
1096
|
React.useEffect(() => {
|
|
1099
1097
|
const onReady = editorActor.on("ready", () => {
|
|
1100
1098
|
rangeDecorationsActor.send({
|
|
@@ -1166,8 +1164,8 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1166
1164
|
});
|
|
1167
1165
|
}
|
|
1168
1166
|
}, [onCut, editorActor, slateEditor]), handlePaste = React.useCallback((event_1) => {
|
|
1169
|
-
const value = editorProvider.
|
|
1170
|
-
schema:
|
|
1167
|
+
const value = editorProvider.fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? editorProvider.slateRangeToSelection({
|
|
1168
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1171
1169
|
editor: slateEditor,
|
|
1172
1170
|
range: slateEditor.selection
|
|
1173
1171
|
}) : null)?.focus.path || [], onPasteResult = onPaste?.({
|
|
@@ -1247,20 +1245,28 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1247
1245
|
});
|
|
1248
1246
|
}
|
|
1249
1247
|
debug("No result from custom paste handler, pasting normally");
|
|
1250
|
-
}, [editorActor, onPaste, portableTextEditor,
|
|
1248
|
+
}, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
1251
1249
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1250
|
+
const selectionBefore = slateEditor.selection ? editorProvider.slateRangeToSelection({
|
|
1251
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1252
|
+
editor: slateEditor,
|
|
1253
|
+
range: slateEditor.selection
|
|
1254
|
+
}) : null;
|
|
1255
|
+
editorActor.send({
|
|
1254
1256
|
type: "notify.focused",
|
|
1255
1257
|
event: event_2
|
|
1256
1258
|
});
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
+
const selectionAfter = slateEditor.selection ? editorProvider.slateRangeToSelection({
|
|
1260
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1261
|
+
editor: slateEditor,
|
|
1262
|
+
range: slateEditor.selection
|
|
1263
|
+
}) : null;
|
|
1264
|
+
selectionBefore && selectionAfter && util_isSelectionCollapsed.isEqualSelections(selectionBefore, selectionAfter) && editorActor.send({
|
|
1259
1265
|
type: "notify.selection",
|
|
1260
|
-
selection:
|
|
1266
|
+
selection: selectionBefore
|
|
1261
1267
|
});
|
|
1262
1268
|
}
|
|
1263
|
-
}, [editorActor, onFocus,
|
|
1269
|
+
}, [editorActor, onFocus, slateEditor]), handleClick = React.useCallback((event_3) => {
|
|
1264
1270
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
1265
1271
|
return;
|
|
1266
1272
|
const position_3 = getEventPosition({
|