@portabletext/editor 1.55.4 → 1.55.6
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.slice-text-block.cjs +67 -0
- package/lib/_chunks-cjs/util.slice-text-block.cjs.map +1 -0
- package/lib/_chunks-es/util.slice-text-block.js +69 -0
- package/lib/_chunks-es/util.slice-text-block.js.map +1 -0
- package/lib/behaviors/index.d.cts +72 -52
- package/lib/behaviors/index.d.ts +72 -52
- package/lib/index.cjs +15 -15
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +117 -69
- package/lib/index.d.ts +117 -69
- package/lib/index.js +8 -8
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +71 -51
- package/lib/plugins/index.d.ts +71 -51
- package/lib/selectors/index.d.cts +68 -51
- package/lib/selectors/index.d.ts +68 -51
- package/lib/utils/index.cjs +12 -13
- package/lib/utils/index.cjs.map +1 -1
- package/lib/utils/index.d.cts +68 -51
- package/lib/utils/index.d.ts +68 -51
- package/lib/utils/index.js +14 -15
- package/lib/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/src/behaviors/behavior.abstract.split.ts +8 -9
- package/src/behaviors/behavior.types.event.ts +3 -0
- package/src/behaviors/index.ts +2 -1
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -5
- package/src/converters/converter.text-html.deserialize.test.ts +2 -2
- package/src/converters/converter.text-html.serialize.test.ts +2 -2
- package/src/converters/converter.text-plain.test.ts +3 -5
- package/src/editor/editor-schema-definition.ts +106 -0
- package/src/editor/editor-schema.ts +65 -107
- package/src/editor.ts +1 -1
- package/src/index.ts +16 -2
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +2 -1
- package/src/internal-utils/build-index-maps.test.ts +2 -1
- package/src/internal-utils/create-test-snapshot.ts +2 -1
- package/src/internal-utils/drag-selection.test.ts +2 -1
- package/src/internal-utils/parse-blocks.test.ts +2 -1
- package/src/internal-utils/selection-text.ts +2 -1
- package/src/internal-utils/terse-pt.test.ts +2 -1
- package/src/internal-utils/test-editor.tsx +4 -1
- package/src/plugins/plugin.markdown.test.tsx +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +2 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +2 -1
- package/src/utils/util.block-offset.test.ts +2 -1
- package/src/utils/util.slice-blocks.test.ts +2 -1
- package/src/utils/util.slice-text-block.test.ts +163 -0
- package/src/utils/util.slice-text-block.ts +89 -0
- package/src/utils/util.split-text-block.ts +7 -16
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -23
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +0 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -25
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +0 -1
package/lib/utils/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"),
|
|
3
|
+
var selectionPoint = require("../_chunks-cjs/selection-point.cjs"), util_childSelectionPointToBlockOffset = require("../_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_isEqualSelectionPoints = require("../_chunks-cjs/util.is-equal-selection-points.cjs"), util_sliceTextBlock = require("../_chunks-cjs/util.slice-text-block.cjs"), util_mergeTextBlocks = require("../_chunks-cjs/util.merge-text-blocks.cjs");
|
|
4
4
|
function isEqualSelections(a, b) {
|
|
5
5
|
return !a && !b ? !0 : !a || !b ? !1 : util_isEqualSelectionPoints.isEqualSelectionPoints(a.anchor, b.anchor) && util_isEqualSelectionPoints.isEqualSelectionPoints(a.focus, b.focus);
|
|
6
6
|
}
|
|
@@ -23,7 +23,7 @@ function splitTextBlock({
|
|
|
23
23
|
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
|
|
24
24
|
if (!firstChild || !lastChild)
|
|
25
25
|
return;
|
|
26
|
-
const before =
|
|
26
|
+
const before = util_sliceTextBlock.sliceTextBlock({
|
|
27
27
|
context: {
|
|
28
28
|
schema: context.schema,
|
|
29
29
|
selection: {
|
|
@@ -38,8 +38,8 @@ function splitTextBlock({
|
|
|
38
38
|
focus: point
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
|
|
42
|
-
})
|
|
41
|
+
block
|
|
42
|
+
}), after = util_sliceTextBlock.sliceTextBlock({
|
|
43
43
|
context: {
|
|
44
44
|
schema: context.schema,
|
|
45
45
|
selection: {
|
|
@@ -54,13 +54,12 @@ function splitTextBlock({
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
57
|
+
block
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
before,
|
|
61
|
+
after
|
|
62
|
+
};
|
|
64
63
|
}
|
|
65
64
|
exports.blockOffsetToSpanSelectionPoint = selectionPoint.blockOffsetToSpanSelectionPoint;
|
|
66
65
|
exports.getBlockStartPoint = selectionPoint.getBlockStartPoint;
|
|
@@ -78,8 +77,8 @@ exports.childSelectionPointToBlockOffset = util_childSelectionPointToBlockOffset
|
|
|
78
77
|
exports.getBlockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint;
|
|
79
78
|
exports.isEmptyTextBlock = util_isEqualSelectionPoints.isEmptyTextBlock;
|
|
80
79
|
exports.isEqualSelectionPoints = util_isEqualSelectionPoints.isEqualSelectionPoints;
|
|
81
|
-
exports.isSelectionCollapsed =
|
|
82
|
-
exports.selectionPointToBlockOffset =
|
|
80
|
+
exports.isSelectionCollapsed = util_sliceTextBlock.isSelectionCollapsed;
|
|
81
|
+
exports.selectionPointToBlockOffset = util_sliceTextBlock.selectionPointToBlockOffset;
|
|
83
82
|
exports.isTextBlock = util_mergeTextBlocks.isTextBlock;
|
|
84
83
|
exports.mergeTextBlocks = util_mergeTextBlocks.mergeTextBlocks;
|
|
85
84
|
exports.isEqualSelections = isEqualSelections;
|
package/lib/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {sliceTextBlock} from './util.slice-text-block'\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 = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\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 },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,4BAAAA,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,4BAAAA,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,oBAAAA,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,mCAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,eAAAA,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/lib/utils/index.d.cts
CHANGED
|
@@ -7,6 +7,13 @@ import type {
|
|
|
7
7
|
} from '@sanity/types'
|
|
8
8
|
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare type AnnotationSchemaType = BaseDefinition & {
|
|
14
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
18
|
* @public
|
|
12
19
|
*/
|
|
@@ -15,6 +22,13 @@ declare type BaseDefinition = {
|
|
|
15
22
|
title?: string
|
|
16
23
|
}
|
|
17
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare type BlockObjectSchemaType = BaseDefinition & {
|
|
29
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
33
|
* @beta
|
|
20
34
|
*/
|
|
@@ -152,6 +166,17 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
|
152
166
|
mimeType: TMIMEType
|
|
153
167
|
}
|
|
154
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
declare type DecoratorSchemaType = BaseDefinition & {
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated
|
|
175
|
+
* Use `name` instead
|
|
176
|
+
*/
|
|
177
|
+
value: string
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
declare type Deserializer<TMIMEType extends MIMEType> = ({
|
|
156
181
|
snapshot,
|
|
157
182
|
event,
|
|
@@ -180,63 +205,18 @@ declare type EditorContext = {
|
|
|
180
205
|
* @public
|
|
181
206
|
*/
|
|
182
207
|
declare type EditorSchema = {
|
|
183
|
-
annotations: ReadonlyArray<
|
|
184
|
-
BaseDefinition & {
|
|
185
|
-
fields: ReadonlyArray<{
|
|
186
|
-
name: string
|
|
187
|
-
type: string
|
|
188
|
-
}>
|
|
189
|
-
}
|
|
190
|
-
>
|
|
208
|
+
annotations: ReadonlyArray<AnnotationSchemaType>
|
|
191
209
|
block: {
|
|
192
210
|
name: string
|
|
193
211
|
}
|
|
194
|
-
blockObjects: ReadonlyArray<
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
name: string
|
|
198
|
-
type: string
|
|
199
|
-
}>
|
|
200
|
-
}
|
|
201
|
-
>
|
|
202
|
-
decorators: ReadonlyArray<
|
|
203
|
-
BaseDefinition & {
|
|
204
|
-
/**
|
|
205
|
-
* @deprecated
|
|
206
|
-
* Use `name` instead
|
|
207
|
-
*/
|
|
208
|
-
value: string
|
|
209
|
-
}
|
|
210
|
-
>
|
|
211
|
-
inlineObjects: ReadonlyArray<
|
|
212
|
-
BaseDefinition & {
|
|
213
|
-
fields: ReadonlyArray<{
|
|
214
|
-
name: string
|
|
215
|
-
type: string
|
|
216
|
-
}>
|
|
217
|
-
}
|
|
218
|
-
>
|
|
212
|
+
blockObjects: ReadonlyArray<BlockObjectSchemaType>
|
|
213
|
+
decorators: ReadonlyArray<DecoratorSchemaType>
|
|
214
|
+
inlineObjects: ReadonlyArray<InlineObjectSchemaType>
|
|
219
215
|
span: {
|
|
220
216
|
name: string
|
|
221
217
|
}
|
|
222
|
-
styles: ReadonlyArray<
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @deprecated
|
|
226
|
-
* Use `name` instead
|
|
227
|
-
*/
|
|
228
|
-
value: string
|
|
229
|
-
}
|
|
230
|
-
>
|
|
231
|
-
lists: ReadonlyArray<
|
|
232
|
-
BaseDefinition & {
|
|
233
|
-
/**
|
|
234
|
-
* @deprecated
|
|
235
|
-
* Use `name` instead
|
|
236
|
-
*/
|
|
237
|
-
value: string
|
|
238
|
-
}
|
|
239
|
-
>
|
|
218
|
+
styles: ReadonlyArray<StyleSchemaType>
|
|
219
|
+
lists: ReadonlyArray<ListSchemaType>
|
|
240
220
|
}
|
|
241
221
|
|
|
242
222
|
/** @public */
|
|
@@ -268,6 +248,14 @@ declare type EditorSnapshot = {
|
|
|
268
248
|
blockIndexMap: Map<string, number>
|
|
269
249
|
}
|
|
270
250
|
|
|
251
|
+
/**
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
declare type FieldDefinition = {
|
|
255
|
+
name: string
|
|
256
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object'
|
|
257
|
+
}
|
|
258
|
+
|
|
271
259
|
/**
|
|
272
260
|
* @public
|
|
273
261
|
*/
|
|
@@ -323,6 +311,13 @@ export declare function getSelectionStartPoint<
|
|
|
323
311
|
*/
|
|
324
312
|
export declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
325
313
|
|
|
314
|
+
/**
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
declare type InlineObjectSchemaType = BaseDefinition & {
|
|
318
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
319
|
+
}
|
|
320
|
+
|
|
326
321
|
/**
|
|
327
322
|
* @public
|
|
328
323
|
*/
|
|
@@ -377,6 +372,17 @@ export declare function isTextBlock(
|
|
|
377
372
|
block: unknown,
|
|
378
373
|
): block is PortableTextTextBlock
|
|
379
374
|
|
|
375
|
+
/**
|
|
376
|
+
* @public
|
|
377
|
+
*/
|
|
378
|
+
declare type ListSchemaType = BaseDefinition & {
|
|
379
|
+
/**
|
|
380
|
+
* @deprecated
|
|
381
|
+
* Use `name` instead
|
|
382
|
+
*/
|
|
383
|
+
value: string
|
|
384
|
+
}
|
|
385
|
+
|
|
380
386
|
/**
|
|
381
387
|
* @beta
|
|
382
388
|
*/
|
|
@@ -471,4 +477,15 @@ export declare function splitTextBlock({
|
|
|
471
477
|
}
|
|
472
478
|
| undefined
|
|
473
479
|
|
|
480
|
+
/**
|
|
481
|
+
* @public
|
|
482
|
+
*/
|
|
483
|
+
declare type StyleSchemaType = BaseDefinition & {
|
|
484
|
+
/**
|
|
485
|
+
* @deprecated
|
|
486
|
+
* Use `name` instead
|
|
487
|
+
*/
|
|
488
|
+
value: string
|
|
489
|
+
}
|
|
490
|
+
|
|
474
491
|
export {}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ import type {
|
|
|
7
7
|
} from '@sanity/types'
|
|
8
8
|
import {PortableTextObject, PortableTextSpan} from '@sanity/types'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare type AnnotationSchemaType = BaseDefinition & {
|
|
14
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
/**
|
|
11
18
|
* @public
|
|
12
19
|
*/
|
|
@@ -15,6 +22,13 @@ declare type BaseDefinition = {
|
|
|
15
22
|
title?: string
|
|
16
23
|
}
|
|
17
24
|
|
|
25
|
+
/**
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare type BlockObjectSchemaType = BaseDefinition & {
|
|
29
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
/**
|
|
19
33
|
* @beta
|
|
20
34
|
*/
|
|
@@ -152,6 +166,17 @@ declare type ConverterEvent<TMIMEType extends MIMEType = MIMEType> =
|
|
|
152
166
|
mimeType: TMIMEType
|
|
153
167
|
}
|
|
154
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
declare type DecoratorSchemaType = BaseDefinition & {
|
|
173
|
+
/**
|
|
174
|
+
* @deprecated
|
|
175
|
+
* Use `name` instead
|
|
176
|
+
*/
|
|
177
|
+
value: string
|
|
178
|
+
}
|
|
179
|
+
|
|
155
180
|
declare type Deserializer<TMIMEType extends MIMEType> = ({
|
|
156
181
|
snapshot,
|
|
157
182
|
event,
|
|
@@ -180,63 +205,18 @@ declare type EditorContext = {
|
|
|
180
205
|
* @public
|
|
181
206
|
*/
|
|
182
207
|
declare type EditorSchema = {
|
|
183
|
-
annotations: ReadonlyArray<
|
|
184
|
-
BaseDefinition & {
|
|
185
|
-
fields: ReadonlyArray<{
|
|
186
|
-
name: string
|
|
187
|
-
type: string
|
|
188
|
-
}>
|
|
189
|
-
}
|
|
190
|
-
>
|
|
208
|
+
annotations: ReadonlyArray<AnnotationSchemaType>
|
|
191
209
|
block: {
|
|
192
210
|
name: string
|
|
193
211
|
}
|
|
194
|
-
blockObjects: ReadonlyArray<
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
name: string
|
|
198
|
-
type: string
|
|
199
|
-
}>
|
|
200
|
-
}
|
|
201
|
-
>
|
|
202
|
-
decorators: ReadonlyArray<
|
|
203
|
-
BaseDefinition & {
|
|
204
|
-
/**
|
|
205
|
-
* @deprecated
|
|
206
|
-
* Use `name` instead
|
|
207
|
-
*/
|
|
208
|
-
value: string
|
|
209
|
-
}
|
|
210
|
-
>
|
|
211
|
-
inlineObjects: ReadonlyArray<
|
|
212
|
-
BaseDefinition & {
|
|
213
|
-
fields: ReadonlyArray<{
|
|
214
|
-
name: string
|
|
215
|
-
type: string
|
|
216
|
-
}>
|
|
217
|
-
}
|
|
218
|
-
>
|
|
212
|
+
blockObjects: ReadonlyArray<BlockObjectSchemaType>
|
|
213
|
+
decorators: ReadonlyArray<DecoratorSchemaType>
|
|
214
|
+
inlineObjects: ReadonlyArray<InlineObjectSchemaType>
|
|
219
215
|
span: {
|
|
220
216
|
name: string
|
|
221
217
|
}
|
|
222
|
-
styles: ReadonlyArray<
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* @deprecated
|
|
226
|
-
* Use `name` instead
|
|
227
|
-
*/
|
|
228
|
-
value: string
|
|
229
|
-
}
|
|
230
|
-
>
|
|
231
|
-
lists: ReadonlyArray<
|
|
232
|
-
BaseDefinition & {
|
|
233
|
-
/**
|
|
234
|
-
* @deprecated
|
|
235
|
-
* Use `name` instead
|
|
236
|
-
*/
|
|
237
|
-
value: string
|
|
238
|
-
}
|
|
239
|
-
>
|
|
218
|
+
styles: ReadonlyArray<StyleSchemaType>
|
|
219
|
+
lists: ReadonlyArray<ListSchemaType>
|
|
240
220
|
}
|
|
241
221
|
|
|
242
222
|
/** @public */
|
|
@@ -268,6 +248,14 @@ declare type EditorSnapshot = {
|
|
|
268
248
|
blockIndexMap: Map<string, number>
|
|
269
249
|
}
|
|
270
250
|
|
|
251
|
+
/**
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
declare type FieldDefinition = {
|
|
255
|
+
name: string
|
|
256
|
+
type: 'string' | 'number' | 'boolean' | 'array' | 'object'
|
|
257
|
+
}
|
|
258
|
+
|
|
271
259
|
/**
|
|
272
260
|
* @public
|
|
273
261
|
*/
|
|
@@ -323,6 +311,13 @@ export declare function getSelectionStartPoint<
|
|
|
323
311
|
*/
|
|
324
312
|
export declare function getTextBlockText(block: PortableTextTextBlock): string
|
|
325
313
|
|
|
314
|
+
/**
|
|
315
|
+
* @public
|
|
316
|
+
*/
|
|
317
|
+
declare type InlineObjectSchemaType = BaseDefinition & {
|
|
318
|
+
fields: ReadonlyArray<FieldDefinition>
|
|
319
|
+
}
|
|
320
|
+
|
|
326
321
|
/**
|
|
327
322
|
* @public
|
|
328
323
|
*/
|
|
@@ -377,6 +372,17 @@ export declare function isTextBlock(
|
|
|
377
372
|
block: unknown,
|
|
378
373
|
): block is PortableTextTextBlock
|
|
379
374
|
|
|
375
|
+
/**
|
|
376
|
+
* @public
|
|
377
|
+
*/
|
|
378
|
+
declare type ListSchemaType = BaseDefinition & {
|
|
379
|
+
/**
|
|
380
|
+
* @deprecated
|
|
381
|
+
* Use `name` instead
|
|
382
|
+
*/
|
|
383
|
+
value: string
|
|
384
|
+
}
|
|
385
|
+
|
|
380
386
|
/**
|
|
381
387
|
* @beta
|
|
382
388
|
*/
|
|
@@ -471,4 +477,15 @@ export declare function splitTextBlock({
|
|
|
471
477
|
}
|
|
472
478
|
| undefined
|
|
473
479
|
|
|
480
|
+
/**
|
|
481
|
+
* @public
|
|
482
|
+
*/
|
|
483
|
+
declare type StyleSchemaType = BaseDefinition & {
|
|
484
|
+
/**
|
|
485
|
+
* @deprecated
|
|
486
|
+
* Use `name` instead
|
|
487
|
+
*/
|
|
488
|
+
value: string
|
|
489
|
+
}
|
|
490
|
+
|
|
474
491
|
export {}
|
package/lib/utils/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
|
|
1
|
+
import { isSpan } from "../_chunks-es/selection-point.js";
|
|
2
|
+
import { blockOffsetToSpanSelectionPoint, getBlockStartPoint, getSelectionEndPoint, getSelectionStartPoint, getTextBlockText, isKeyedSegment, sliceBlocks, spanSelectionPointToBlockOffset } from "../_chunks-es/selection-point.js";
|
|
3
3
|
import { blockOffsetToBlockSelectionPoint, blockOffsetToSelectionPoint, blockOffsetsToSelection, childSelectionPointToBlockOffset } from "../_chunks-es/util.child-selection-point-to-block-offset.js";
|
|
4
4
|
import { isEqualSelectionPoints } from "../_chunks-es/util.is-equal-selection-points.js";
|
|
5
5
|
import { getBlockEndPoint, isEmptyTextBlock } from "../_chunks-es/util.is-equal-selection-points.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
|
|
6
|
+
import { sliceTextBlock } from "../_chunks-es/util.slice-text-block.js";
|
|
7
|
+
import { isSelectionCollapsed, selectionPointToBlockOffset } from "../_chunks-es/util.slice-text-block.js";
|
|
8
|
+
import { isTextBlock, mergeTextBlocks } from "../_chunks-es/util.merge-text-blocks.js";
|
|
9
9
|
function isEqualSelections(a, b) {
|
|
10
10
|
return !a && !b ? !0 : !a || !b ? !1 : isEqualSelectionPoints(a.anchor, b.anchor) && isEqualSelectionPoints(a.focus, b.focus);
|
|
11
11
|
}
|
|
@@ -28,7 +28,7 @@ function splitTextBlock({
|
|
|
28
28
|
const firstChild = block.children.at(0), lastChild = block.children.at(block.children.length - 1);
|
|
29
29
|
if (!firstChild || !lastChild)
|
|
30
30
|
return;
|
|
31
|
-
const before =
|
|
31
|
+
const before = sliceTextBlock({
|
|
32
32
|
context: {
|
|
33
33
|
schema: context.schema,
|
|
34
34
|
selection: {
|
|
@@ -43,8 +43,8 @@ function splitTextBlock({
|
|
|
43
43
|
focus: point
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
})
|
|
46
|
+
block
|
|
47
|
+
}), after = sliceTextBlock({
|
|
48
48
|
context: {
|
|
49
49
|
schema: context.schema,
|
|
50
50
|
selection: {
|
|
@@ -59,13 +59,12 @@ function splitTextBlock({
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
62
|
+
block
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
before,
|
|
66
|
+
after
|
|
67
|
+
};
|
|
69
68
|
}
|
|
70
69
|
export {
|
|
71
70
|
blockOffsetToBlockSelectionPoint,
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/utils/util.is-equal-selections.ts","../../src/utils/util.reverse-selection.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 {EditorSelection} from '../types/editor'\n\n/**\n * @public\n */\nexport function reverseSelection<\n TEditorSelection extends NonNullable<EditorSelection> | null,\n>(selection: TEditorSelection): TEditorSelection {\n if (!selection) {\n return selection\n }\n\n if (selection.backward) {\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: false,\n } as TEditorSelection\n }\n\n return {\n anchor: selection.focus,\n focus: selection.anchor,\n backward: true,\n } as TEditorSelection\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 {sliceTextBlock} from './util.slice-text-block'\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 = sliceTextBlock({\n context: {\n schema: context.schema,\n selection: {\n anchor: {\n path: [{_key: block._key}, 'children', {_key: firstChild._key}],\n offset: 0,\n },\n focus: point,\n },\n },\n block,\n })\n const after = sliceTextBlock({\n context: {\n schema: context.schema,\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 },\n block,\n })\n\n return {before, after}\n}\n"],"names":["isEqualSelections","a","b","isEqualSelectionPoints","anchor","focus","reverseSelection","selection","backward","splitTextBlock","context","block","point","firstChild","children","at","lastChild","length","before","sliceTextBlock","schema","path","_key","offset","after","isSpan","text"],"mappings":";;;;;;;;AAMO,SAASA,kBAAkBC,GAAoBC,GAAoB;AACxE,SAAI,CAACD,KAAK,CAACC,IACF,KAGL,CAACD,KAAK,CAACC,IACF,KAIPC,uBAAuBF,EAAEG,QAAQF,EAAEE,MAAM,KACzCD,uBAAuBF,EAAEI,OAAOH,EAAEG,KAAK;AAE3C;ACdO,SAASC,iBAEdC,WAA+C;AAC/C,SAAKA,cAIDA,UAAUC,WACL;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA,IAIP;AAAA,IACLJ,QAAQG,UAAUF;AAAAA,IAClBA,OAAOE,UAAUH;AAAAA,IACjBI,UAAU;AAAA,EAAA;AAEd;AChBO,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;AAE7D,MAAI,CAACJ,cAAc,CAACG;AAClB;AAGF,QAAME,SAASC,eAAe;AAAA,IAC5BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQ;AAAA,UACNiB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMT,WAAWS;AAAAA,UAAAA,CAAK;AAAA,UAC9DC,QAAQ;AAAA,QAAA;AAAA,QAEVlB,OAAOO;AAAAA,MAAAA;AAAAA,IACT;AAAA,IAEFD;AAAAA,EAAAA,CACD,GACKa,QAAQL,eAAe;AAAA,IAC3BT,SAAS;AAAA,MACPU,QAAQV,QAAQU;AAAAA,MAChBb,WAAW;AAAA,QACTH,QAAQQ;AAAAA,QACRP,OAAO;AAAA,UACLgB,MAAM,CAAC;AAAA,YAACC,MAAMX,MAAMW;AAAAA,UAAAA,GAAO,YAAY;AAAA,YAACA,MAAMN,UAAUM;AAAAA,UAAAA,CAAK;AAAA,UAC7DC,QAAQE,OAAOf,SAASM,SAAS,IAAIA,UAAUU,KAAKT,SAAS;AAAA,QAAA;AAAA,MAC/D;AAAA,IACF;AAAA,IAEFN;AAAAA,EAAAA,CACD;AAED,SAAO;AAAA,IAACO;AAAAA,IAAQM;AAAAA,EAAAA;AAClB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.55.
|
|
3
|
+
"version": "1.55.6",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@portabletext/toolkit": "^2.0.17",
|
|
88
88
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
89
|
-
"@sanity/pkg-utils": "^7.8.
|
|
89
|
+
"@sanity/pkg-utils": "^7.8.6",
|
|
90
90
|
"@sanity/schema": "^3.94.2",
|
|
91
91
|
"@sanity/types": "^3.94.2",
|
|
92
92
|
"@testing-library/react": "^16.3.0",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {isTextBlock, parseBlock} from '../internal-utils/parse-blocks'
|
|
2
2
|
import * as selectors from '../selectors'
|
|
3
3
|
import * as utils from '../utils'
|
|
4
|
+
import {sliceTextBlock} from '../utils/util.slice-text-block'
|
|
4
5
|
import {raise} from './behavior.types.action'
|
|
5
6
|
import {defineBehavior} from './behavior.types.behavior'
|
|
6
7
|
|
|
@@ -102,15 +103,13 @@ export const abstractSplitBehaviors = [
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
const newTextBlock = parseBlock({
|
|
105
|
-
block:
|
|
106
|
-
|
|
107
|
-
...snapshot,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
113
|
-
.at(0),
|
|
106
|
+
block: sliceTextBlock({
|
|
107
|
+
context: {
|
|
108
|
+
...snapshot.context,
|
|
109
|
+
selection: newTextBlockSelection,
|
|
110
|
+
},
|
|
111
|
+
block: focusTextBlock.node,
|
|
112
|
+
}),
|
|
114
113
|
context: snapshot.context,
|
|
115
114
|
options: {refreshKeys: true, validateFields: true},
|
|
116
115
|
})
|
package/src/behaviors/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export {
|
|
2
|
+
effect,
|
|
2
3
|
execute,
|
|
3
4
|
forward,
|
|
4
5
|
raise,
|
|
5
|
-
effect,
|
|
6
6
|
type BehaviorAction,
|
|
7
7
|
type BehaviorActionSet,
|
|
8
8
|
} from './behavior.types.action'
|
|
@@ -10,6 +10,7 @@ export {defineBehavior, type Behavior} from './behavior.types.behavior'
|
|
|
10
10
|
export type {
|
|
11
11
|
BehaviorEvent,
|
|
12
12
|
CustomBehaviorEvent,
|
|
13
|
+
InsertPlacement,
|
|
13
14
|
NativeBehaviorEvent,
|
|
14
15
|
SyntheticBehaviorEvent,
|
|
15
16
|
} from './behavior.types.event'
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {assert, describe, expect, test} from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type SchemaDefinition,
|
|
6
|
-
} from '../editor/editor-schema'
|
|
2
|
+
import {compileSchemaDefinition} from '../editor/editor-schema'
|
|
3
|
+
import {defineSchema} from '../editor/editor-schema-definition'
|
|
4
|
+
import type {SchemaDefinition} from '../editor/editor-schema-definition'
|
|
7
5
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
8
6
|
import {converterPortableText} from './converter.portable-text'
|
|
9
7
|
|
|
@@ -2,9 +2,9 @@ import {describe, expect, test} from 'vitest'
|
|
|
2
2
|
import {
|
|
3
3
|
compileSchemaDefinition,
|
|
4
4
|
compileSchemaDefinitionToLegacySchema,
|
|
5
|
-
defineSchema,
|
|
6
|
-
type SchemaDefinition,
|
|
7
5
|
} from '../editor/editor-schema'
|
|
6
|
+
import {defineSchema} from '../editor/editor-schema-definition'
|
|
7
|
+
import type {SchemaDefinition} from '../editor/editor-schema-definition'
|
|
8
8
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
9
9
|
import {createConverterTextHtml} from './converter.text-html'
|
|
10
10
|
|
|
@@ -4,9 +4,9 @@ import type {EditorSelection} from '..'
|
|
|
4
4
|
import {
|
|
5
5
|
compileSchemaDefinition,
|
|
6
6
|
compileSchemaDefinitionToLegacySchema,
|
|
7
|
-
defineSchema,
|
|
8
|
-
type SchemaDefinition,
|
|
9
7
|
} from '../editor/editor-schema'
|
|
8
|
+
import {defineSchema} from '../editor/editor-schema-definition'
|
|
9
|
+
import type {SchemaDefinition} from '../editor/editor-schema-definition'
|
|
10
10
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
11
11
|
import {createConverterTextHtml} from './converter.text-html'
|
|
12
12
|
|
|
@@ -2,11 +2,9 @@ import type {PortableTextBlock, PortableTextTextBlock} from '@sanity/types'
|
|
|
2
2
|
import {expect, test} from 'vitest'
|
|
3
3
|
import type {EditorSelection} from '..'
|
|
4
4
|
import {schemaType} from '../editor/__tests__/PortableTextEditorTester'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type SchemaDefinition,
|
|
9
|
-
} from '../editor/editor-schema'
|
|
5
|
+
import {compileSchemaDefinition} from '../editor/editor-schema'
|
|
6
|
+
import {defineSchema} from '../editor/editor-schema-definition'
|
|
7
|
+
import type {SchemaDefinition} from '../editor/editor-schema-definition'
|
|
10
8
|
import {createLegacySchema} from '../editor/legacy-schema'
|
|
11
9
|
import {createTestSnapshot} from '../internal-utils/create-test-snapshot'
|
|
12
10
|
import {createConverterTextPlain} from './converter.text-plain'
|