@portabletext/editor 1.47.11 → 1.47.13
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/behavior.core.cjs +61 -3
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +88 -58
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs +10 -0
- package/lib/_chunks-cjs/util.get-selection-start-point.cjs.map +1 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -8
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +63 -4
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +90 -59
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.get-selection-start-point.js +11 -0
- package/lib/_chunks-es/util.get-selection-start-point.js.map +1 -0
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -8
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +4876 -288
- package/lib/behaviors/index.d.ts +4876 -288
- package/lib/index.cjs +3 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +29 -42
- package/lib/index.d.ts +29 -42
- package/lib/index.js +1 -1
- package/lib/plugins/index.cjs +0 -9
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +29 -42
- package/lib/plugins/index.d.ts +29 -42
- package/lib/plugins/index.js +0 -9
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +29 -41
- package/lib/selectors/index.d.ts +29 -41
- package/lib/utils/index.cjs +3 -3
- package/lib/utils/index.d.cts +29 -41
- package/lib/utils/index.d.ts +29 -41
- package/lib/utils/index.js +2 -1
- package/lib/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.block.ts +136 -45
- package/src/behaviors/behavior.abstract.insert.ts +2 -2
- package/src/behaviors/behavior.abstract.split.ts +2 -46
- package/src/behaviors/behavior.core.insert-break.ts +113 -0
- package/src/behaviors/behavior.core.ts +2 -0
- package/src/behaviors/behavior.perform-event.ts +2 -7
- package/src/behaviors/behavior.types.action.ts +7 -13
- package/src/behaviors/behavior.types.event.ts +31 -33
- package/src/internal-utils/slate-utils.ts +50 -1
- package/src/plugins/plugin.one-line.tsx +0 -7
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function getSelectionEndPoint(selection) {
|
|
2
|
+
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
3
|
+
}
|
|
4
|
+
function getSelectionStartPoint(selection) {
|
|
5
|
+
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
getSelectionEndPoint,
|
|
9
|
+
getSelectionStartPoint
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=util.get-selection-start-point.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.get-selection-start-point.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.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, EditorSelectionPoint} from '..'\n\n/**\n * @public\n */\nexport function getSelectionStartPoint<\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.focus : selection.anchor\n ) as TEditorSelectionPoint\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint"],"mappings":"AAKO,SAASA,qBAMdC,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUE,SAASF,UAAUG,QAJ3C;AAMX;ACdO,SAASC,uBAMdJ,WAAoD;AACpD,SAAKA,YAKHA,UAAUC,WAAWD,UAAUG,QAAQH,UAAUE,SAJ1C;AAMX;"}
|
|
@@ -72,12 +72,6 @@ function childSelectionPointToBlockOffset({
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function getSelectionEndPoint(selection) {
|
|
76
|
-
return selection ? selection.backward ? selection.anchor : selection.focus : null;
|
|
77
|
-
}
|
|
78
|
-
function getSelectionStartPoint(selection) {
|
|
79
|
-
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
80
|
-
}
|
|
81
75
|
function selectionPointToBlockOffset({
|
|
82
76
|
value,
|
|
83
77
|
selectionPoint
|
|
@@ -97,8 +91,6 @@ export {
|
|
|
97
91
|
blockOffsetToSelectionPoint,
|
|
98
92
|
blockOffsetsToSelection,
|
|
99
93
|
childSelectionPointToBlockOffset,
|
|
100
|
-
getSelectionEndPoint,
|
|
101
|
-
getSelectionStartPoint,
|
|
102
94
|
selectionPointToBlockOffset
|
|
103
95
|
};
|
|
104
96
|
//# sourceMappingURL=util.selection-point-to-block-offset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.selection-point-to-block-offset.js","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.
|
|
1
|
+
{"version":3,"file":"util.selection-point-to-block-offset.js","sources":["../../src/utils/util.block-offset-to-block-selection-point.ts","../../src/utils/util.block-offset-to-selection-point.ts","../../src/utils/util.block-offsets-to-selection.ts","../../src/utils/util.child-selection-point-to-block-offset.ts","../../src/utils/util.selection-point-to-block-offset.ts"],"sourcesContent":["import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\n\n/**\n * @public\n */\nexport function blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n}): EditorSelectionPoint | undefined {\n let selectionPoint: EditorSelectionPoint | undefined\n\n for (const block of value) {\n if (block._key === blockOffset.path[0]._key) {\n selectionPoint = {\n path: [{_key: block._key}],\n offset: blockOffset.offset,\n }\n break\n }\n }\n\n return selectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {blockOffsetToSpanSelectionPoint} from './util.block-offset'\nimport {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetToSelectionPoint({\n value,\n blockOffset,\n direction,\n}: {\n value: Array<PortableTextBlock>\n blockOffset: BlockOffset\n direction: 'forward' | 'backward'\n}): EditorSelectionPoint | undefined {\n const spanSelectionPoint = blockOffsetToSpanSelectionPoint({\n value,\n blockOffset,\n direction,\n })\n\n if (!spanSelectionPoint) {\n return blockOffsetToBlockSelectionPoint({\n value,\n blockOffset,\n })\n }\n\n return spanSelectionPoint\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {EditorSelection} from '..'\nimport type {BlockOffset} from '../types/block-offset'\nimport {blockOffsetToSelectionPoint} from './util.block-offset-to-selection-point'\n\n/**\n * @public\n */\nexport function blockOffsetsToSelection({\n value,\n offsets,\n backward,\n}: {\n value: Array<PortableTextBlock>\n offsets: {anchor: BlockOffset; focus: BlockOffset}\n backward?: boolean\n}): EditorSelection {\n const anchor = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.anchor,\n direction: backward ? 'backward' : 'forward',\n })\n const focus = blockOffsetToSelectionPoint({\n value,\n blockOffset: offsets.focus,\n direction: backward ? 'forward' : 'backward',\n })\n\n if (!anchor || !focus) {\n return null\n }\n\n return {\n anchor,\n focus,\n backward,\n }\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextBlock,\n} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n let offset = 0\n\n const blockKey = isKeyedSegment(selectionPoint.path[0])\n ? selectionPoint.path[0]._key\n : undefined\n const childKey = isKeyedSegment(selectionPoint.path[2])\n ? selectionPoint.path[2]._key\n : undefined\n\n if (!blockKey || !childKey) {\n return undefined\n }\n\n for (const block of value) {\n if (block._key !== blockKey) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n for (const child of block.children) {\n if (child._key === childKey) {\n return {\n path: [{_key: block._key}],\n offset: offset + selectionPoint.offset,\n }\n }\n\n if (isPortableTextSpan(child)) {\n offset += child.text.length\n }\n }\n }\n}\n","import type {PortableTextBlock} from '@sanity/types'\nimport type {BlockOffset} from '../types/block-offset'\nimport type {EditorSelectionPoint} from '../types/editor'\nimport {childSelectionPointToBlockOffset} from './util.child-selection-point-to-block-offset'\nimport {isKeyedSegment} from './util.is-keyed-segment'\n\n/**\n * @public\n */\nexport function selectionPointToBlockOffset({\n value,\n selectionPoint,\n}: {\n value: Array<PortableTextBlock>\n selectionPoint: EditorSelectionPoint\n}): BlockOffset | undefined {\n if (\n selectionPoint.path.length === 1 &&\n isKeyedSegment(selectionPoint.path[0])\n ) {\n return {\n path: [{_key: selectionPoint.path[0]._key}],\n offset: selectionPoint.offset,\n }\n }\n\n return childSelectionPointToBlockOffset({\n value,\n selectionPoint,\n })\n}\n"],"names":["blockOffsetToBlockSelectionPoint","value","blockOffset","selectionPoint","block","_key","path","offset","blockOffsetToSelectionPoint","direction","blockOffsetToSpanSelectionPoint","blockOffsetsToSelection","offsets","backward","anchor","focus","childSelectionPointToBlockOffset","blockKey","isKeyedSegment","undefined","childKey","isPortableTextTextBlock","child","children","isPortableTextSpan","text","length","selectionPointToBlockOffset"],"mappings":";;AAOO,SAASA,iCAAiC;AAAA,EAC/CC;AAAAA,EACAC;AAIF,GAAqC;AAC/BC,MAAAA;AAEJ,aAAWC,SAASH;AAClB,QAAIG,MAAMC,SAASH,YAAYI,KAAK,CAAC,EAAED,MAAM;AAC1B,uBAAA;AAAA,QACfC,MAAM,CAAC;AAAA,UAACD,MAAMD,MAAMC;AAAAA,QAAAA,CAAK;AAAA,QACzBE,QAAQL,YAAYK;AAAAA,MACtB;AACA;AAAA,IAAA;AAIGJ,SAAAA;AACT;AClBO,SAASK,4BAA4B;AAAA,EAC1CP;AAAAA,EACAC;AAAAA,EACAO;AAKF,GAAqC;AAOnC,SAN2BC,gCAAgC;AAAA,IACzDT;AAAAA,IACAC;AAAAA,IACAO;AAAAA,EAAAA,CACD,KAGQT,iCAAiC;AAAA,IACtCC;AAAAA,IACAC;AAAAA,EAAAA,CACD;AAIL;ACxBO,SAASS,wBAAwB;AAAA,EACtCV;AAAAA,EACAW;AAAAA,EACAC;AAKF,GAAoB;AAClB,QAAMC,SAASN,4BAA4B;AAAA,IACzCP;AAAAA,IACAC,aAAaU,QAAQE;AAAAA,IACrBL,WAAWI,WAAW,aAAa;AAAA,EAAA,CACpC,GACKE,QAAQP,4BAA4B;AAAA,IACxCP;AAAAA,IACAC,aAAaU,QAAQG;AAAAA,IACrBN,WAAWI,WAAW,Y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