@portabletext/editor 1.47.9 → 1.47.11
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 +105 -73
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs +0 -4
- package/lib/_chunks-cjs/util.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +8 -0
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +108 -76
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/util.is-selection-collapsed.js +0 -4
- package/lib/_chunks-es/util.is-selection-collapsed.js.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +8 -0
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +359 -339
- package/lib/behaviors/index.d.ts +359 -339
- package/lib/behaviors/index.js +1 -1
- package/lib/index.cjs +3 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +4 -4
- package/lib/index.d.ts +4 -4
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +4 -4
- package/lib/plugins/index.d.ts +4 -4
- package/lib/selectors/index.d.cts +4 -4
- package/lib/selectors/index.d.ts +4 -4
- package/lib/utils/index.cjs +2 -5
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +4 -4
- package/lib/utils/index.d.ts +4 -4
- package/lib/utils/index.js +2 -5
- package/lib/utils/index.js.map +1 -1
- package/package.json +4 -4
- package/src/behavior-actions/behavior.actions.ts +0 -9
- package/src/behaviors/behavior.abstract.split.ts +162 -0
- package/src/behaviors/behavior.default.ts +2 -0
- package/src/behaviors/behavior.types.event.ts +4 -4
- package/src/behavior-actions/behavior.action.split.block.ts +0 -146
package/lib/plugins/index.d.cts
CHANGED
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5841,9 +5845,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5841
5845
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5842
5846
|
at: EditorSelection
|
|
5843
5847
|
}
|
|
5844
|
-
| {
|
|
5845
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5846
|
-
}
|
|
5847
5848
|
|
|
5848
5849
|
declare type SyntheticBehaviorEventNamespace =
|
|
5849
5850
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5875,7 +5876,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5875
5876
|
'move.block',
|
|
5876
5877
|
'move.forward',
|
|
5877
5878
|
'select',
|
|
5878
|
-
'split.block',
|
|
5879
5879
|
]
|
|
5880
5880
|
|
|
5881
5881
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
package/lib/plugins/index.d.ts
CHANGED
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5841,9 +5845,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5841
5845
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5842
5846
|
at: EditorSelection
|
|
5843
5847
|
}
|
|
5844
|
-
| {
|
|
5845
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5846
|
-
}
|
|
5847
5848
|
|
|
5848
5849
|
declare type SyntheticBehaviorEventNamespace =
|
|
5849
5850
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5875,7 +5876,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5875
5876
|
'move.block',
|
|
5876
5877
|
'move.forward',
|
|
5877
5878
|
'select',
|
|
5878
|
-
'split.block',
|
|
5879
5879
|
]
|
|
5880
5880
|
|
|
5881
5881
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5930,9 +5934,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5930
5934
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5931
5935
|
at: EditorSelection
|
|
5932
5936
|
}
|
|
5933
|
-
| {
|
|
5934
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5935
|
-
}
|
|
5936
5937
|
|
|
5937
5938
|
declare type SyntheticBehaviorEventNamespace =
|
|
5938
5939
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5964,7 +5965,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5964
5965
|
'move.block',
|
|
5965
5966
|
'move.forward',
|
|
5966
5967
|
'select',
|
|
5967
|
-
'split.block',
|
|
5968
5968
|
]
|
|
5969
5969
|
|
|
5970
5970
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
package/lib/selectors/index.d.ts
CHANGED
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5930,9 +5934,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5930
5934
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5931
5935
|
at: EditorSelection
|
|
5932
5936
|
}
|
|
5933
|
-
| {
|
|
5934
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5935
|
-
}
|
|
5936
5937
|
|
|
5937
5938
|
declare type SyntheticBehaviorEventNamespace =
|
|
5938
5939
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5964,7 +5965,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5964
5965
|
'move.block',
|
|
5965
5966
|
'move.forward',
|
|
5966
5967
|
'select',
|
|
5967
|
-
'split.block',
|
|
5968
5968
|
]
|
|
5969
5969
|
|
|
5970
5970
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
package/lib/utils/index.cjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
3
|
var util_sliceBlocks = require("../_chunks-cjs/util.slice-blocks.cjs"), util_selectionPointToBlockOffset = require("../_chunks-cjs/util.selection-point-to-block-offset.cjs"), util_isSelectionCollapsed = require("../_chunks-cjs/util.is-selection-collapsed.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
|
|
4
|
-
function getSelectionStartPoint(selection) {
|
|
5
|
-
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
6
|
-
}
|
|
7
4
|
function isEqualSelections(a, b) {
|
|
8
5
|
return !a && !b ? !0 : !a || !b ? !1 : util_sliceBlocks.isEqualSelectionPoints(a.anchor, b.anchor) && util_sliceBlocks.isEqualSelectionPoints(a.focus, b.focus);
|
|
9
6
|
}
|
|
@@ -63,12 +60,12 @@ exports.blockOffsetToBlockSelectionPoint = util_selectionPointToBlockOffset.bloc
|
|
|
63
60
|
exports.blockOffsetToSelectionPoint = util_selectionPointToBlockOffset.blockOffsetToSelectionPoint;
|
|
64
61
|
exports.blockOffsetsToSelection = util_selectionPointToBlockOffset.blockOffsetsToSelection;
|
|
65
62
|
exports.childSelectionPointToBlockOffset = util_selectionPointToBlockOffset.childSelectionPointToBlockOffset;
|
|
63
|
+
exports.getSelectionEndPoint = util_selectionPointToBlockOffset.getSelectionEndPoint;
|
|
64
|
+
exports.getSelectionStartPoint = util_selectionPointToBlockOffset.getSelectionStartPoint;
|
|
66
65
|
exports.selectionPointToBlockOffset = util_selectionPointToBlockOffset.selectionPointToBlockOffset;
|
|
67
|
-
exports.getSelectionEndPoint = util_isSelectionCollapsed.getSelectionEndPoint;
|
|
68
66
|
exports.isSelectionCollapsed = util_isSelectionCollapsed.isSelectionCollapsed;
|
|
69
67
|
exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
|
|
70
68
|
exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
|
|
71
|
-
exports.getSelectionStartPoint = getSelectionStartPoint;
|
|
72
69
|
exports.isEqualSelections = isEqualSelections;
|
|
73
70
|
exports.splitTextBlock = splitTextBlock;
|
|
74
71
|
//# sourceMappingURL=index.cjs.map
|
package/lib/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["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 {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","selection","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,iBAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,wCAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,iBAAAA,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQ;AAAA,QACNe,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMV,WAAWU;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACAhB,OAAOI;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDU,QAAQN,iBAAAA,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQK;AAAAA,MACRJ,OAAO;AAAA,QACLc,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMP,UAAUO;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,iBAAOhB,OAAAA,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACO,UAIZ,EAACG,CAAAA,qBAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,qBAAYlB,YAAAA,SAASe,KAAK;AAIzD,WAAA;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAK;AACvB;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5764,9 +5768,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5764
5768
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5765
5769
|
at: EditorSelection
|
|
5766
5770
|
}
|
|
5767
|
-
| {
|
|
5768
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5769
|
-
}
|
|
5770
5771
|
|
|
5771
5772
|
declare type SyntheticBehaviorEventNamespace =
|
|
5772
5773
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5798,7 +5799,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5798
5799
|
'move.block',
|
|
5799
5800
|
'move.forward',
|
|
5800
5801
|
'select',
|
|
5801
|
-
'split.block',
|
|
5802
5802
|
]
|
|
5803
5803
|
|
|
5804
5804
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -171,6 +171,9 @@ declare type AbstractBehaviorEvent =
|
|
|
171
171
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
172
172
|
select?: 'start' | 'end'
|
|
173
173
|
}
|
|
174
|
+
| {
|
|
175
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
176
|
+
}
|
|
174
177
|
| {
|
|
175
178
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
176
179
|
style: string
|
|
@@ -213,6 +216,7 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
213
216
|
'serialize',
|
|
214
217
|
'serialization.success',
|
|
215
218
|
'serialization.failure',
|
|
219
|
+
'split.block',
|
|
216
220
|
'style.add',
|
|
217
221
|
'style.remove',
|
|
218
222
|
'style.toggle',
|
|
@@ -5764,9 +5768,6 @@ declare type SyntheticBehaviorEvent =
|
|
|
5764
5768
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
5765
5769
|
at: EditorSelection
|
|
5766
5770
|
}
|
|
5767
|
-
| {
|
|
5768
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
5769
|
-
}
|
|
5770
5771
|
|
|
5771
5772
|
declare type SyntheticBehaviorEventNamespace =
|
|
5772
5773
|
ExtractNamespace<SyntheticBehaviorEventType>
|
|
@@ -5798,7 +5799,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
5798
5799
|
'move.block',
|
|
5799
5800
|
'move.forward',
|
|
5800
5801
|
'select',
|
|
5801
|
-
'split.block',
|
|
5802
5802
|
]
|
|
5803
5803
|
|
|
5804
5804
|
declare type TextBlockWithOptionalKey = Omit<PortableTextTextBlock, '_key'> & {
|
package/lib/utils/index.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { isEqualSelectionPoints, sliceBlocks, isSpan } from "../_chunks-es/util.slice-blocks.js";
|
|
2
2
|
import { blockOffsetToSpanSelectionPoint, getBlockEndPoint, getBlockStartPoint, getTextBlockText, isEmptyTextBlock, isKeyedSegment, reverseSelection, spanSelectionPointToBlockOffset } from "../_chunks-es/util.slice-blocks.js";
|
|
3
|
-
import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
|
|
4
|
-
import {
|
|
3
|
+
import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset, getSelectionEndPoint, getSelectionStartPoint, selectionPointToBlockOffset } from "../_chunks-es/util.selection-point-to-block-offset.js";
|
|
4
|
+
import { isSelectionCollapsed } from "../_chunks-es/util.is-selection-collapsed.js";
|
|
5
5
|
import { isTextBlock } from "../_chunks-es/util.merge-text-blocks.js";
|
|
6
6
|
import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
|
|
7
|
-
function getSelectionStartPoint(selection) {
|
|
8
|
-
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
9
|
-
}
|
|
10
7
|
function isEqualSelections(a, b) {
|
|
11
8
|
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
|
|
12
9
|
}
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/util.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.split-text-block.ts"],"sourcesContent":["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 {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelectionPoint} from '..'\nimport type {EditorContext} from '../editor/editor-snapshot'\nimport {isSpan} from './util.is-span'\nimport {isTextBlock} from './util.is-text-block'\nimport {sliceBlocks} from './util.slice-blocks'\n\n/**\n * @beta\n */\nexport function splitTextBlock({\n context,\n block,\n point,\n}: {\n context: Pick<EditorContext, 'schema'>\n block: PortableTextTextBlock\n point: EditorSelectionPoint\n}): {before: PortableTextTextBlock; after: PortableTextTextBlock} | undefined {\n const firstChild = block.children.at(0)\n const lastChild = block.children.at(block.children.length - 1)\n\n if (!firstChild || !lastChild) {\n return undefined\n }\n\n const before = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n }).at(0)\n const after = sliceBlocks({\n blocks: [block],\n selection: {\n anchor: point,\n focus: {\n path: [{_key: block._key}, 'children', {_key: lastChild._key}],\n offset: isSpan(context, lastChild) ? lastChild.text.length : 0,\n },\n },\n }).at(0)\n\n if (!before || !after) {\n return undefined\n }\n\n if (!isTextBlock(context, before) || !isTextBlock(context, after)) {\n return undefined\n }\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceBlocks","blocks","selection","path","_key","offset","after","isSpan","text","isTextBlock"],"mappings":";;;;;;AAMgBA,SAAAA,kBAAkBC,GAAoBC,GAAoB;AACpE,SAAA,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACTO,SAASC,eAAe;AAAA,EAC7BC;AAAAA,EACAC;AAAAA,EACAC;AAKF,GAA8E;AAC5E,QAAMC,aAAaF,MAAMG,SAASC,GAAG,CAAC,GAChCC,YAAYL,MAAMG,SAASC,GAAGJ,MAAMG,SAASG,SAAS,CAAC;AAEzD,MAAA,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,YAAY;AAAA,IACzBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQ;AAAA,QACNe,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMV,WAAWU;AAAAA,QAAAA,CAAK;AAAA,QAC9DC,QAAQ;AAAA,MACV;AAAA,MACAhB,OAAOI;AAAAA,IAAAA;AAAAA,EAEV,CAAA,EAAEG,GAAG,CAAC,GACDU,QAAQN,YAAY;AAAA,IACxBC,QAAQ,CAACT,KAAK;AAAA,IACdU,WAAW;AAAA,MACTd,QAAQK;AAAAA,MACRJ,OAAO;AAAA,QACLc,MAAM,CAAC;AAAA,UAACC,MAAMZ,MAAMY;AAAAA,WAAO,YAAY;AAAA,UAACA,MAAMP,UAAUO;AAAAA,QAAAA,CAAK;AAAA,QAC7DC,QAAQE,OAAOhB,SAASM,SAAS,IAAIA,UAAUW,KAAKV,SAAS;AAAA,MAAA;AAAA,IAC/D;AAAA,EACF,CACD,EAAEF,GAAG,CAAC;AAEP,MAAI,EAACG,CAAAA,UAAU,CAACO,UAIZ,EAACG,CAAAA,YAAYlB,SAASQ,MAAM,KAAK,CAACU,YAAYlB,SAASe,KAAK;AAIzD,WAAA;AAAA,MAACP;AAAAA,MAAQO;AAAAA,IAAK;AACvB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.47.
|
|
3
|
+
"version": "1.47.11",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"@types/debug": "^4.1.12",
|
|
94
94
|
"@types/lodash": "^4.17.16",
|
|
95
95
|
"@types/lodash.startcase": "^4.4.9",
|
|
96
|
-
"@types/react": "^19.1.
|
|
97
|
-
"@types/react-dom": "^19.1.
|
|
96
|
+
"@types/react": "^19.1.2",
|
|
97
|
+
"@types/react-dom": "^19.1.2",
|
|
98
98
|
"@typescript-eslint/eslint-plugin": "^8.29.0",
|
|
99
99
|
"@typescript-eslint/parser": "^8.29.0",
|
|
100
100
|
"@vitejs/plugin-react": "^4.3.4",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"vite": "^6.2.5",
|
|
113
113
|
"vitest": "^3.1.1",
|
|
114
114
|
"vitest-browser-react": "^0.1.1",
|
|
115
|
-
"racejar": "1.2.
|
|
115
|
+
"racejar": "1.2.4"
|
|
116
116
|
},
|
|
117
117
|
"peerDependencies": {
|
|
118
118
|
"@sanity/schema": "^3.85.1",
|
|
@@ -27,7 +27,6 @@ import {moveBlockActionImplementation} from './behavior.action.move.block'
|
|
|
27
27
|
import {moveForwardActionImplementation} from './behavior.action.move.forward'
|
|
28
28
|
import {noopActionImplementation} from './behavior.action.noop'
|
|
29
29
|
import {selectActionImplementation} from './behavior.action.select'
|
|
30
|
-
import {splitBlockActionImplementation} from './behavior.action.split.block'
|
|
31
30
|
|
|
32
31
|
const debug = debugWithName('behaviors:action')
|
|
33
32
|
|
|
@@ -74,7 +73,6 @@ const behaviorActionImplementations: BehaviorActionImplementations = {
|
|
|
74
73
|
'move.forward': moveForwardActionImplementation,
|
|
75
74
|
'noop': noopActionImplementation,
|
|
76
75
|
'select': selectActionImplementation,
|
|
77
|
-
'split.block': splitBlockActionImplementation,
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
export function performAction({
|
|
@@ -234,13 +232,6 @@ export function performAction({
|
|
|
234
232
|
})
|
|
235
233
|
break
|
|
236
234
|
}
|
|
237
|
-
case 'split.block': {
|
|
238
|
-
behaviorActionImplementations['split.block']({
|
|
239
|
-
context,
|
|
240
|
-
action,
|
|
241
|
-
})
|
|
242
|
-
break
|
|
243
|
-
}
|
|
244
235
|
default: {
|
|
245
236
|
behaviorActionImplementations.select({
|
|
246
237
|
context,
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import {isTextBlock, parseBlock} from '../internal-utils/parse-blocks'
|
|
2
|
+
import * as selectors from '../selectors'
|
|
3
|
+
import {getSelectionStartPoint, isEqualSelectionPoints} from '../utils'
|
|
4
|
+
import {getBlockEndPoint} from '../utils/util.get-block-end-point'
|
|
5
|
+
import {getBlockStartPoint} from '../utils/util.get-block-start-point'
|
|
6
|
+
import {getSelectionEndPoint} from '../utils/util.get-selection-end-point'
|
|
7
|
+
import {sliceBlocks} from '../utils/util.slice-blocks'
|
|
8
|
+
import {raise} from './behavior.types.action'
|
|
9
|
+
import {defineBehavior} from './behavior.types.behavior'
|
|
10
|
+
|
|
11
|
+
export const abstractSplitBehaviors = [
|
|
12
|
+
defineBehavior({
|
|
13
|
+
on: 'split.block',
|
|
14
|
+
guard: ({snapshot}) => {
|
|
15
|
+
if (!snapshot.context.selection) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!selectors.isSelectionExpanded(snapshot)) {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const firstBlock = selectors.getFirstBlock(snapshot)
|
|
24
|
+
const lastBlock = selectors.getLastBlock(snapshot)
|
|
25
|
+
|
|
26
|
+
if (!firstBlock || !lastBlock) {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const firstBlockStartPoint = getBlockStartPoint(firstBlock)
|
|
31
|
+
const selectionStartPoint = getSelectionStartPoint(
|
|
32
|
+
snapshot.context.selection,
|
|
33
|
+
)
|
|
34
|
+
const lastBlockEndPoint = getBlockEndPoint(lastBlock)
|
|
35
|
+
const selectionEndPoint = getSelectionEndPoint(snapshot.context.selection)
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
isEqualSelectionPoints(firstBlockStartPoint, selectionStartPoint) &&
|
|
39
|
+
isEqualSelectionPoints(lastBlockEndPoint, selectionEndPoint)
|
|
40
|
+
) {
|
|
41
|
+
return {selection: snapshot.context.selection}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return false
|
|
45
|
+
},
|
|
46
|
+
actions: [
|
|
47
|
+
(_, {selection}) => [
|
|
48
|
+
raise({
|
|
49
|
+
type: 'delete',
|
|
50
|
+
at: selection,
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
defineBehavior({
|
|
56
|
+
on: 'split.block',
|
|
57
|
+
guard: ({snapshot}) => {
|
|
58
|
+
if (!snapshot.context.selection) {
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const selectionStartPoint = getSelectionStartPoint(
|
|
63
|
+
snapshot.context.selection,
|
|
64
|
+
)
|
|
65
|
+
const selectionEndPoint = getSelectionEndPoint(snapshot.context.selection)
|
|
66
|
+
|
|
67
|
+
const focusTextBlock = selectors.getFocusTextBlock({
|
|
68
|
+
...snapshot,
|
|
69
|
+
context: {
|
|
70
|
+
...snapshot.context,
|
|
71
|
+
selection: {
|
|
72
|
+
anchor: selectionStartPoint,
|
|
73
|
+
focus: selectionEndPoint,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
if (focusTextBlock) {
|
|
79
|
+
const blockEndPoint = getBlockEndPoint(focusTextBlock)
|
|
80
|
+
const newTextBlockSelection = {
|
|
81
|
+
anchor: selectionEndPoint,
|
|
82
|
+
focus: blockEndPoint,
|
|
83
|
+
}
|
|
84
|
+
const newTextBlock = parseBlock({
|
|
85
|
+
block: sliceBlocks({
|
|
86
|
+
blocks: [focusTextBlock.node],
|
|
87
|
+
selection: newTextBlockSelection,
|
|
88
|
+
}).at(0),
|
|
89
|
+
context: snapshot.context,
|
|
90
|
+
options: {refreshKeys: true},
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
!newTextBlock ||
|
|
95
|
+
!isTextBlock(snapshot.context.schema, newTextBlock)
|
|
96
|
+
) {
|
|
97
|
+
return false
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
newTextBlock,
|
|
102
|
+
newTextBlockSelection,
|
|
103
|
+
selection: {
|
|
104
|
+
anchor: selectionStartPoint,
|
|
105
|
+
focus: blockEndPoint,
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const focusBlockObject = selectors.getFocusBlockObject({
|
|
111
|
+
...snapshot,
|
|
112
|
+
context: {
|
|
113
|
+
...snapshot.context,
|
|
114
|
+
selection: {
|
|
115
|
+
anchor: selectionStartPoint,
|
|
116
|
+
focus: selectionEndPoint,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
if (focusBlockObject) {
|
|
122
|
+
const newTextBlock = parseBlock({
|
|
123
|
+
block: {
|
|
124
|
+
_type: snapshot.context.schema.block.name,
|
|
125
|
+
children: [],
|
|
126
|
+
},
|
|
127
|
+
context: snapshot.context,
|
|
128
|
+
options: {refreshKeys: true},
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
if (!newTextBlock) {
|
|
132
|
+
return false
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
newTextBlock,
|
|
137
|
+
newTextBlockSelection: {
|
|
138
|
+
anchor: selectionEndPoint,
|
|
139
|
+
focus: selectionEndPoint,
|
|
140
|
+
},
|
|
141
|
+
selection: snapshot.context.selection,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return false
|
|
146
|
+
},
|
|
147
|
+
actions: [
|
|
148
|
+
(_, {newTextBlock, selection}) => [
|
|
149
|
+
raise({
|
|
150
|
+
type: 'delete',
|
|
151
|
+
at: selection,
|
|
152
|
+
}),
|
|
153
|
+
raise({
|
|
154
|
+
type: 'insert.block',
|
|
155
|
+
block: newTextBlock,
|
|
156
|
+
placement: 'after',
|
|
157
|
+
select: 'start',
|
|
158
|
+
}),
|
|
159
|
+
],
|
|
160
|
+
],
|
|
161
|
+
}),
|
|
162
|
+
]
|
|
@@ -10,6 +10,7 @@ import {abstractInsertBehaviors} from './behavior.abstract.insert'
|
|
|
10
10
|
import {abstractListItemBehaviors} from './behavior.abstract.list-item'
|
|
11
11
|
import {abstractMoveBehaviors} from './behavior.abstract.move'
|
|
12
12
|
import {abstractSelectBehaviors} from './behavior.abstract.select'
|
|
13
|
+
import {abstractSplitBehaviors} from './behavior.abstract.split'
|
|
13
14
|
import {abstractStyleBehaviors} from './behavior.abstract.style'
|
|
14
15
|
import {raiseInsertSoftBreak} from './behavior.default.raise-soft-break'
|
|
15
16
|
import {raise} from './behavior.types.action'
|
|
@@ -454,6 +455,7 @@ export const defaultBehaviors = [
|
|
|
454
455
|
...abstractMoveBehaviors,
|
|
455
456
|
...abstractStyleBehaviors,
|
|
456
457
|
...abstractSelectBehaviors,
|
|
458
|
+
...abstractSplitBehaviors,
|
|
457
459
|
raiseDeserializationSuccessOrFailure,
|
|
458
460
|
raiseSerializationSuccessOrFailure,
|
|
459
461
|
raiseInsertSoftBreak,
|
|
@@ -83,7 +83,6 @@ const syntheticBehaviorEventTypes = [
|
|
|
83
83
|
'move.block',
|
|
84
84
|
'move.forward',
|
|
85
85
|
'select',
|
|
86
|
-
'split.block',
|
|
87
86
|
] as const
|
|
88
87
|
|
|
89
88
|
type SyntheticBehaviorEventType = (typeof syntheticBehaviorEventTypes)[number]
|
|
@@ -195,9 +194,6 @@ export type SyntheticBehaviorEvent =
|
|
|
195
194
|
type: StrictExtract<SyntheticBehaviorEventType, 'select'>
|
|
196
195
|
at: EditorSelection
|
|
197
196
|
}
|
|
198
|
-
| {
|
|
199
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'split.block'>
|
|
200
|
-
}
|
|
201
197
|
|
|
202
198
|
export type InsertPlacement = 'auto' | 'after' | 'before'
|
|
203
199
|
|
|
@@ -231,6 +227,7 @@ const abstractBehaviorEventTypes = [
|
|
|
231
227
|
'serialize',
|
|
232
228
|
'serialization.success',
|
|
233
229
|
'serialization.failure',
|
|
230
|
+
'split.block',
|
|
234
231
|
'style.add',
|
|
235
232
|
'style.remove',
|
|
236
233
|
'style.toggle',
|
|
@@ -362,6 +359,9 @@ export type AbstractBehaviorEvent =
|
|
|
362
359
|
type: StrictExtract<AbstractBehaviorEventType, 'select.next block'>
|
|
363
360
|
select?: 'start' | 'end'
|
|
364
361
|
}
|
|
362
|
+
| {
|
|
363
|
+
type: StrictExtract<AbstractBehaviorEventType, 'split.block'>
|
|
364
|
+
}
|
|
365
365
|
| {
|
|
366
366
|
type: StrictExtract<AbstractBehaviorEventType, 'style.add'>
|
|
367
367
|
style: string
|