@portabletext/editor 1.40.4 → 1.41.0
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 +11 -6
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +4 -0
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +11 -6
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +4 -0
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/index.cjs +260 -131
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +262 -133
- package/lib/index.js.map +1 -1
- package/lib/utils/index.cjs +5 -0
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +22 -0
- package/lib/utils/index.d.ts +22 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/converters/converter.text-plain.ts +24 -11
- package/src/editor/Editable.tsx +336 -223
- package/src/editor/components/drop-indicator.tsx +4 -1
- package/src/internal-utils/dragging-on-drag-origin.ts +22 -0
- package/src/internal-utils/event-position.ts +32 -4
- package/src/internal-utils/slate-utils.ts +18 -9
- package/src/utils/index.ts +2 -0
- package/src/utils/util.get-selection-end-point.ts +20 -0
- package/src/utils/util.get-selection-start-point.ts +20 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
function getSelectionEndPoint(selection) {
|
|
3
|
+
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
4
|
+
}
|
|
2
5
|
function isSelectionCollapsed(selection) {
|
|
3
6
|
return selection ? selection.anchor.path.join() === selection.focus.path.join() && selection.anchor.offset === selection.focus.offset : !1;
|
|
4
7
|
}
|
|
8
|
+
exports.getSelectionEndPoint = getSelectionEndPoint;
|
|
5
9
|
exports.isSelectionCollapsed = isSelectionCollapsed;
|
|
6
10
|
//# sourceMappingURL=util.is-selection-collapsed.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.is-selection-collapsed.cjs","sources":["../../src/utils/util.is-selection-collapsed.ts"],"sourcesContent":["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":["
|
|
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":";AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,SAASC,qBAAqBJ,WAA4B;AAC/D,SAAKA,YAKHA,UAAUE,OAAOG,KAAKC,KAAAA,MAAWN,UAAUG,MAAME,KAAKC,KAAAA,KACtDN,UAAUE,OAAOK,WAAWP,UAAUG,MAAMI,SALrC;AAOX;;;"}
|
|
@@ -356,14 +356,17 @@ function getFocusChild({
|
|
|
356
356
|
const focusChild = Node.child(focusBlock, childIndex);
|
|
357
357
|
return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
|
|
358
358
|
}
|
|
359
|
+
function getFirstBlock({
|
|
360
|
+
editor
|
|
361
|
+
}) {
|
|
362
|
+
const firstBlockPath = Editor.start(editor, []).path.at(0);
|
|
363
|
+
return firstBlockPath !== void 0 ? Editor.node(editor, [firstBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
364
|
+
}
|
|
359
365
|
function getLastBlock({
|
|
360
366
|
editor
|
|
361
367
|
}) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
at: [],
|
|
365
|
-
reverse: !0
|
|
366
|
-
})).at(0) ?? [void 0, void 0];
|
|
368
|
+
const lastBlockPath = Editor.end(editor, []).path.at(0);
|
|
369
|
+
return lastBlockPath !== void 0 ? Editor.node(editor, [lastBlockPath]) ?? [void 0, void 0] : [void 0, void 0];
|
|
367
370
|
}
|
|
368
371
|
function getNodeBlock({
|
|
369
372
|
editor,
|
|
@@ -2616,7 +2619,7 @@ const converterJson = {
|
|
|
2616
2619
|
data: sliceBlocks({
|
|
2617
2620
|
blocks: snapshot.context.value,
|
|
2618
2621
|
selection
|
|
2619
|
-
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : "").join("") : "").filter((block) => block !== "").join(`
|
|
2622
|
+
}).map((block) => isPortableTextTextBlock(block) ? block.children.map((child) => child._type === snapshot.context.schema.span.name ? child.text : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.inlineObjects.find((inlineObjectType) => inlineObjectType.name === child._type)?.title ?? "Object"}]` : "").join("") : snapshot.beta.hasTag("dragging internally") ? `[${snapshot.context.schema.blockObjects.find((blockObjectType) => blockObjectType.name === block._type)?.title ?? "Object"}]` : "").filter((block) => block !== "").join(`
|
|
2620
2623
|
|
|
2621
2624
|
`),
|
|
2622
2625
|
mimeType: "text/plain",
|
|
@@ -7730,6 +7733,8 @@ export {
|
|
|
7730
7733
|
defineSchema,
|
|
7731
7734
|
fromSlateValue,
|
|
7732
7735
|
getEditorSnapshot,
|
|
7736
|
+
getFirstBlock,
|
|
7737
|
+
getLastBlock,
|
|
7733
7738
|
getNodeBlock,
|
|
7734
7739
|
isEqualToEmptyEditor,
|
|
7735
7740
|
moveRangeByOperation,
|