@portabletext/editor 1.50.5 → 1.50.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/_chunks-cjs/util.selection-point-to-block-offset.cjs +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +24 -16
- package/lib/behaviors/index.d.ts +24 -16
- package/lib/index.cjs +324 -252
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +24 -16
- package/lib/index.d.ts +24 -16
- package/lib/index.js +326 -254
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +24 -16
- package/lib/plugins/index.d.ts +24 -16
- package/lib/selectors/index.d.cts +24 -16
- package/lib/selectors/index.d.ts +24 -16
- package/lib/utils/index.d.cts +24 -16
- package/lib/utils/index.d.ts +24 -16
- package/package.json +4 -4
- package/src/behaviors/behavior.abstract.delete.ts +60 -0
- package/src/behaviors/behavior.abstract.split.ts +23 -13
- package/src/behaviors/behavior.types.event.ts +23 -16
- package/src/editor/plugins/create-with-event-listeners.ts +41 -1
- package/src/editor/sync-machine.ts +26 -20
- package/src/internal-utils/applyPatch.ts +298 -207
- package/src/internal-utils/slate-utils.ts +31 -0
- package/src/internal-utils/test-editor.tsx +45 -0
- package/src/operations/behavior.operation.delete.ts +36 -22
- package/src/operations/behavior.operations.ts +0 -27
- package/src/utils/util.is-selection-collapsed.ts +2 -1
- package/src/internal-utils/__tests__/dmpToOperations.test.ts +0 -207
- package/src/operations/behavior.operation.delete.backward.ts +0 -8
- package/src/operations/behavior.operation.delete.block.ts +0 -24
- package/src/operations/behavior.operation.delete.forward.ts +0 -8
|
@@ -7,7 +7,7 @@ function getSelectionStartPoint(selection) {
|
|
|
7
7
|
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
8
8
|
}
|
|
9
9
|
function isSelectionCollapsed(selection) {
|
|
10
|
-
return selection ? selection.anchor.path
|
|
10
|
+
return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
|
|
11
11
|
}
|
|
12
12
|
function selectionPointToBlockOffset({
|
|
13
13
|
context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.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","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.
|
|
1
|
+
{"version":3,"file":"util.selection-point-to-block-offset.cjs","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.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","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 JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\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 context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\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 context,\n selectionPoint,\n })\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","isSelectionCollapsed","JSON","stringify","path","offset","selectionPointToBlockOffset","context","selectionPoint","length","isKeyedSegment","_key","childSelectionPointToBlockOffset"],"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;ACdO,SAASG,qBAAqBL,WAA4B;AAC/D,SAAKA,YAKHM,KAAKC,UAAUP,UAAUE,OAAOM,IAAI,MAClCF,KAAKC,UAAUP,UAAUG,MAAMK,IAAI,KACrCR,UAAUE,OAAOO,WAAWT,UAAUG,MAAMM,SANrC;AAQX;ACNO,SAASC,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC;AAIF,GAA4B;AAExBA,SAAAA,eAAeJ,KAAKK,WAAW,KAC/BC,gCAAeF,eAAeJ,KAAK,CAAC,CAAC,IAE9B;AAAA,IACLA,MAAM,CAAC;AAAA,MAACO,MAAMH,eAAeJ,KAAK,CAAC,EAAEO;AAAAA,IAAAA,CAAK;AAAA,IAC1CN,QAAQG,eAAeH;AAAAA,MAIpBO,uEAAiC;AAAA,IACtCL;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;;;;;"}
|
|
@@ -7,7 +7,7 @@ function getSelectionStartPoint(selection) {
|
|
|
7
7
|
return selection ? selection.backward ? selection.focus : selection.anchor : null;
|
|
8
8
|
}
|
|
9
9
|
function isSelectionCollapsed(selection) {
|
|
10
|
-
return selection ? selection.anchor.path
|
|
10
|
+
return selection ? JSON.stringify(selection.anchor.path) === JSON.stringify(selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
|
|
11
11
|
}
|
|
12
12
|
function selectionPointToBlockOffset({
|
|
13
13
|
context,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.selection-point-to-block-offset.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.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","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.
|
|
1
|
+
{"version":3,"file":"util.selection-point-to-block-offset.js","sources":["../../src/utils/util.get-selection-end-point.ts","../../src/utils/util.get-selection-start-point.ts","../../src/utils/util.is-selection-collapsed.ts","../../src/utils/util.selection-point-to-block-offset.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","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 JSON.stringify(selection.anchor.path) ===\n JSON.stringify(selection.focus.path) &&\n selection.anchor.offset === selection.focus.offset\n )\n}\n","import type {EditorContext} from '../editor/editor-snapshot'\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 context,\n selectionPoint,\n}: {\n context: Pick<EditorContext, 'schema' | 'value'>\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 context,\n selectionPoint,\n })\n}\n"],"names":["getSelectionEndPoint","selection","backward","anchor","focus","getSelectionStartPoint","isSelectionCollapsed","JSON","stringify","path","offset","selectionPointToBlockOffset","context","selectionPoint","length","isKeyedSegment","_key","childSelectionPointToBlockOffset"],"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;ACdO,SAASG,qBAAqBL,WAA4B;AAC/D,SAAKA,YAKHM,KAAKC,UAAUP,UAAUE,OAAOM,IAAI,MAClCF,KAAKC,UAAUP,UAAUG,MAAMK,IAAI,KACrCR,UAAUE,OAAOO,WAAWT,UAAUG,MAAMM,SANrC;AAQX;ACNO,SAASC,4BAA4B;AAAA,EAC1CC;AAAAA,EACAC;AAIF,GAA4B;AAExBA,SAAAA,eAAeJ,KAAKK,WAAW,KAC/BC,eAAeF,eAAeJ,KAAK,CAAC,CAAC,IAE9B;AAAA,IACLA,MAAM,CAAC;AAAA,MAACO,MAAMH,eAAeJ,KAAK,CAAC,EAAEO;AAAAA,IAAAA,CAAK;AAAA,IAC1CN,QAAQG,eAAeH;AAAAA,MAIpBO,iCAAiC;AAAA,IACtCL;AAAAA,IACAC;AAAAA,EAAAA,CACD;AACH;"}
|
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
} from '@sanity/types'
|
|
17
17
|
import {FocusEvent as FocusEvent_2} from 'react'
|
|
18
18
|
import type {KeyboardEvent as KeyboardEvent_2} from 'react'
|
|
19
|
-
import type {Descendant, Operation
|
|
19
|
+
import type {Descendant, Operation} from 'slate'
|
|
20
20
|
import type {DOMNode} from 'slate-dom'
|
|
21
21
|
import type {ReactEditor} from 'slate-react'
|
|
22
22
|
import {
|
|
@@ -60,6 +60,18 @@ declare type AbstractBehaviorEvent =
|
|
|
60
60
|
focus: BlockOffset
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
| {
|
|
64
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
|
|
65
|
+
unit: 'character' | 'word' | 'line' | 'block'
|
|
66
|
+
}
|
|
67
|
+
| {
|
|
68
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
69
|
+
at: [KeyedSegment]
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
73
|
+
unit: 'character' | 'word' | 'line' | 'block'
|
|
74
|
+
}
|
|
63
75
|
| {
|
|
64
76
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
|
|
65
77
|
at: {
|
|
@@ -190,6 +202,9 @@ declare type AbstractBehaviorEvent =
|
|
|
190
202
|
declare const abstractBehaviorEventTypes: readonly [
|
|
191
203
|
'annotation.toggle',
|
|
192
204
|
'decorator.toggle',
|
|
205
|
+
'delete.backward',
|
|
206
|
+
'delete.block',
|
|
207
|
+
'delete.forward',
|
|
193
208
|
'delete.text',
|
|
194
209
|
'deserialize',
|
|
195
210
|
'deserialization.success',
|
|
@@ -2791,18 +2806,14 @@ export declare type SyntheticBehaviorEvent =
|
|
|
2791
2806
|
| {
|
|
2792
2807
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
|
|
2793
2808
|
at: NonNullable<EditorSelection>
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
}
|
|
2803
|
-
| {
|
|
2804
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
2805
|
-
unit: TextUnit
|
|
2809
|
+
/**
|
|
2810
|
+
* Defaults to forward deletion.
|
|
2811
|
+
*/
|
|
2812
|
+
direction?: 'backward' | 'forward'
|
|
2813
|
+
/**
|
|
2814
|
+
* Defaults to character deletion.
|
|
2815
|
+
*/
|
|
2816
|
+
unit?: 'character' | 'word' | 'line' | 'block'
|
|
2806
2817
|
}
|
|
2807
2818
|
| {
|
|
2808
2819
|
type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
|
|
@@ -2877,9 +2888,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
2877
2888
|
'decorator.add',
|
|
2878
2889
|
'decorator.remove',
|
|
2879
2890
|
'delete',
|
|
2880
|
-
'delete.backward',
|
|
2881
|
-
'delete.block',
|
|
2882
|
-
'delete.forward',
|
|
2883
2891
|
'history.redo',
|
|
2884
2892
|
'history.undo',
|
|
2885
2893
|
'insert.inline object',
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
} from '@sanity/types'
|
|
17
17
|
import {FocusEvent as FocusEvent_2} from 'react'
|
|
18
18
|
import type {KeyboardEvent as KeyboardEvent_2} from 'react'
|
|
19
|
-
import type {Descendant, Operation
|
|
19
|
+
import type {Descendant, Operation} from 'slate'
|
|
20
20
|
import type {DOMNode} from 'slate-dom'
|
|
21
21
|
import type {ReactEditor} from 'slate-react'
|
|
22
22
|
import {
|
|
@@ -60,6 +60,18 @@ declare type AbstractBehaviorEvent =
|
|
|
60
60
|
focus: BlockOffset
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
| {
|
|
64
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.backward'>
|
|
65
|
+
unit: 'character' | 'word' | 'line' | 'block'
|
|
66
|
+
}
|
|
67
|
+
| {
|
|
68
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.block'>
|
|
69
|
+
at: [KeyedSegment]
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
73
|
+
unit: 'character' | 'word' | 'line' | 'block'
|
|
74
|
+
}
|
|
63
75
|
| {
|
|
64
76
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete.text'>
|
|
65
77
|
at: {
|
|
@@ -190,6 +202,9 @@ declare type AbstractBehaviorEvent =
|
|
|
190
202
|
declare const abstractBehaviorEventTypes: readonly [
|
|
191
203
|
'annotation.toggle',
|
|
192
204
|
'decorator.toggle',
|
|
205
|
+
'delete.backward',
|
|
206
|
+
'delete.block',
|
|
207
|
+
'delete.forward',
|
|
193
208
|
'delete.text',
|
|
194
209
|
'deserialize',
|
|
195
210
|
'deserialization.success',
|
|
@@ -2791,18 +2806,14 @@ export declare type SyntheticBehaviorEvent =
|
|
|
2791
2806
|
| {
|
|
2792
2807
|
type: StrictExtract<SyntheticBehaviorEventType, 'delete'>
|
|
2793
2808
|
at: NonNullable<EditorSelection>
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
}
|
|
2803
|
-
| {
|
|
2804
|
-
type: StrictExtract<SyntheticBehaviorEventType, 'delete.forward'>
|
|
2805
|
-
unit: TextUnit
|
|
2809
|
+
/**
|
|
2810
|
+
* Defaults to forward deletion.
|
|
2811
|
+
*/
|
|
2812
|
+
direction?: 'backward' | 'forward'
|
|
2813
|
+
/**
|
|
2814
|
+
* Defaults to character deletion.
|
|
2815
|
+
*/
|
|
2816
|
+
unit?: 'character' | 'word' | 'line' | 'block'
|
|
2806
2817
|
}
|
|
2807
2818
|
| {
|
|
2808
2819
|
type: StrictExtract<SyntheticBehaviorEventType, 'history.redo'>
|
|
@@ -2877,9 +2888,6 @@ declare const syntheticBehaviorEventTypes: readonly [
|
|
|
2877
2888
|
'decorator.add',
|
|
2878
2889
|
'decorator.remove',
|
|
2879
2890
|
'delete',
|
|
2880
|
-
'delete.backward',
|
|
2881
|
-
'delete.block',
|
|
2882
|
-
'delete.forward',
|
|
2883
2891
|
'history.redo',
|
|
2884
2892
|
'history.undo',
|
|
2885
2893
|
'insert.inline object',
|