@portabletext/editor 2.1.10 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +2 -2
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-es/selector.is-selection-expanded.js +1 -1
- package/lib/_chunks-es/util.merge-text-blocks.js +2 -2
- package/lib/_chunks-es/util.merge-text-blocks.js.map +1 -1
- package/lib/index.cjs +166 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +169 -28
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/utils/index.d.ts +2 -2
- package/package.json +7 -7
- package/src/behaviors/behavior.abstract.split.ts +77 -1
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -3
- package/src/converters/converter.portable-text.ts +1 -1
- package/src/converters/converter.text-html.ts +1 -1
- package/src/converters/converter.text-plain.ts +1 -1
- package/src/editor/Editable.tsx +2 -2
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +29 -35
- package/src/editor/plugins/createWithEditableAPI.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +110 -1
- package/src/internal-utils/applyPatch.ts +1 -1
- package/src/internal-utils/test-editor.tsx +2 -0
- package/src/internal-utils/text-marks.ts +1 -1
- package/src/internal-utils/to-slate-range.ts +1 -1
- package/src/operations/behavior.operation.annotation.add.ts +1 -1
- package/src/operations/behavior.operation.delete.ts +31 -2
- package/src/operations/behavior.operation.insert.block.ts +85 -13
- package/src/utils/util.merge-text-blocks.ts +1 -1
|
@@ -12,8 +12,8 @@ function mergeTextBlocks({
|
|
|
12
12
|
context,
|
|
13
13
|
block: incomingBlock,
|
|
14
14
|
options: {
|
|
15
|
-
refreshKeys: !
|
|
16
|
-
validateFields: !
|
|
15
|
+
refreshKeys: !1,
|
|
16
|
+
validateFields: !1
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys:
|
|
1
|
+
{"version":3,"file":"util.merge-text-blocks.cjs","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: false, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["isTextBlock","context","block","isTypedObject","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","validateFields","children","markDefs"],"mappings":";;AAOO,SAASA,YACdC,SACAC,OACgC;AAChC,SAAOC,iBAAAA,cAAcD,KAAK,KAAKA,MAAME,UAAUH,QAAQI,OAAOH,MAAMI;AACtE;ACJO,SAASC,gBAAgB;AAAA,EAC9BN;AAAAA,EACAO;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,iBAAAA,WAAW;AAAA,IACrCV;AAAAA,IACAC,OAAOO;AAAAA,IACPG,SAAS;AAAA,MAACC,aAAa;AAAA,MAAOC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CACpD;AAED,SAAI,CAACJ,uBAAuB,CAACV,YAAYC,SAASS,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHO,UAAU,CAAC,GAAGP,YAAYO,UAAU,GAAGL,oBAAoBK,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIR,YAAYQ,YAAY,CAAA,GAC5B,GAAIN,oBAAoBM,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, isSpan, isSpan$1, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint
|
|
1
|
+
import { getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, isSpan, isSpan$1, sliceBlocks, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint } from "./util.slice-blocks.js";
|
|
2
2
|
import { isKeySegment } from "@sanity/types";
|
|
3
3
|
const getFocusBlock = (snapshot) => {
|
|
4
4
|
if (!snapshot.context.selection)
|
|
@@ -11,8 +11,8 @@ function mergeTextBlocks({
|
|
|
11
11
|
context,
|
|
12
12
|
block: incomingBlock,
|
|
13
13
|
options: {
|
|
14
|
-
refreshKeys: !
|
|
15
|
-
validateFields: !
|
|
14
|
+
refreshKeys: !1,
|
|
15
|
+
validateFields: !1
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
return !parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock) ? targetBlock : {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.merge-text-blocks.js","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys:
|
|
1
|
+
{"version":3,"file":"util.merge-text-blocks.js","sources":["../../src/utils/util.is-text-block.ts","../../src/utils/util.merge-text-blocks.ts"],"sourcesContent":["import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {isTypedObject} from '../internal-utils/asserters'\n\n/**\n * @public\n */\nexport function isTextBlock(\n context: Pick<EditorContext, 'schema'>,\n block: unknown,\n): block is PortableTextTextBlock {\n return isTypedObject(block) && block._type === context.schema.block.name\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport type {EditorContext} from '..'\nimport {parseBlock} from '../internal-utils/parse-blocks'\nimport {isTextBlock} from './util.is-text-block'\n\n/**\n * @beta\n */\nexport function mergeTextBlocks({\n context,\n targetBlock,\n incomingBlock,\n}: {\n context: Pick<EditorContext, 'keyGenerator' | 'schema'>\n targetBlock: PortableTextTextBlock\n incomingBlock: PortableTextTextBlock\n}) {\n const parsedIncomingBlock = parseBlock({\n context,\n block: incomingBlock,\n options: {refreshKeys: false, validateFields: false},\n })\n\n if (!parsedIncomingBlock || !isTextBlock(context, parsedIncomingBlock)) {\n return targetBlock\n }\n\n return {\n ...targetBlock,\n children: [...targetBlock.children, ...parsedIncomingBlock.children],\n markDefs: [\n ...(targetBlock.markDefs ?? []),\n ...(parsedIncomingBlock.markDefs ?? []),\n ],\n }\n}\n"],"names":["isTextBlock","context","block","isTypedObject","_type","schema","name","mergeTextBlocks","targetBlock","incomingBlock","parsedIncomingBlock","parseBlock","options","refreshKeys","validateFields","children","markDefs"],"mappings":";AAOO,SAASA,YACdC,SACAC,OACgC;AAChC,SAAOC,cAAcD,KAAK,KAAKA,MAAME,UAAUH,QAAQI,OAAOH,MAAMI;AACtE;ACJO,SAASC,gBAAgB;AAAA,EAC9BN;AAAAA,EACAO;AAAAA,EACAC;AAKF,GAAG;AACD,QAAMC,sBAAsBC,WAAW;AAAA,IACrCV;AAAAA,IACAC,OAAOO;AAAAA,IACPG,SAAS;AAAA,MAACC,aAAa;AAAA,MAAOC,gBAAgB;AAAA,IAAA;AAAA,EAAK,CACpD;AAED,SAAI,CAACJ,uBAAuB,CAACV,YAAYC,SAASS,mBAAmB,IAC5DF,cAGF;AAAA,IACL,GAAGA;AAAAA,IACHO,UAAU,CAAC,GAAGP,YAAYO,UAAU,GAAGL,oBAAoBK,QAAQ;AAAA,IACnEC,UAAU,CACR,GAAIR,YAAYQ,YAAY,CAAA,GAC5B,GAAIN,oBAAoBM,YAAY,CAAA,CAAG;AAAA,EAAA;AAG7C;"}
|
package/lib/index.cjs
CHANGED
|
@@ -1136,7 +1136,7 @@ const converterJson = {
|
|
|
1136
1136
|
context: snapshot.context,
|
|
1137
1137
|
block,
|
|
1138
1138
|
options: {
|
|
1139
|
-
refreshKeys: !
|
|
1139
|
+
refreshKeys: !1,
|
|
1140
1140
|
validateFields: !1
|
|
1141
1141
|
}
|
|
1142
1142
|
});
|
|
@@ -1200,7 +1200,7 @@ function createConverterTextHtml(legacySchema) {
|
|
|
1200
1200
|
block,
|
|
1201
1201
|
options: {
|
|
1202
1202
|
refreshKeys: !1,
|
|
1203
|
-
validateFields: !
|
|
1203
|
+
validateFields: !1
|
|
1204
1204
|
}
|
|
1205
1205
|
});
|
|
1206
1206
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -1248,7 +1248,7 @@ function createConverterTextPlain(legacySchema) {
|
|
|
1248
1248
|
block,
|
|
1249
1249
|
options: {
|
|
1250
1250
|
refreshKeys: !1,
|
|
1251
|
-
validateFields: !
|
|
1251
|
+
validateFields: !1
|
|
1252
1252
|
}
|
|
1253
1253
|
});
|
|
1254
1254
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -3276,9 +3276,17 @@ const addAnnotationOperationImplementation = ({
|
|
|
3276
3276
|
context,
|
|
3277
3277
|
operation
|
|
3278
3278
|
}) => {
|
|
3279
|
-
const anchorBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(operation.at.focus), endBlockKey = operation.at.backward ? anchorBlockKey : focusBlockKey, endOffset = operation.at.backward ? operation.at.focus.offset : operation.at.anchor.offset;
|
|
3279
|
+
const anchorBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(operation.at.anchor), focusBlockKey = util_sliceBlocks.getBlockKeyFromSelectionPoint(operation.at.focus), startBlockKey = operation.at.backward ? focusBlockKey : anchorBlockKey, endBlockKey = operation.at.backward ? anchorBlockKey : focusBlockKey, endOffset = operation.at.backward ? operation.at.focus.offset : operation.at.anchor.offset;
|
|
3280
|
+
if (!startBlockKey)
|
|
3281
|
+
throw new Error("Failed to get start block key");
|
|
3280
3282
|
if (!endBlockKey)
|
|
3281
3283
|
throw new Error("Failed to get end block key");
|
|
3284
|
+
const startBlockIndex = operation.editor.blockIndexMap.get(startBlockKey);
|
|
3285
|
+
if (startBlockIndex === void 0)
|
|
3286
|
+
throw new Error("Failed to get start block index");
|
|
3287
|
+
const startBlock = operation.editor.value.at(startBlockIndex);
|
|
3288
|
+
if (!startBlock)
|
|
3289
|
+
throw new Error("Failed to get start block");
|
|
3282
3290
|
const endBlockIndex = operation.editor.blockIndexMap.get(endBlockKey);
|
|
3283
3291
|
if (endBlockIndex === void 0)
|
|
3284
3292
|
throw new Error("Failed to get end block index");
|
|
@@ -3309,11 +3317,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
3309
3317
|
if (!range)
|
|
3310
3318
|
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
3311
3319
|
const hanging = util_sliceBlocks.isTextBlock(context, endBlock) && endOffset === 0;
|
|
3312
|
-
operation.editor
|
|
3320
|
+
slate.deleteText(operation.editor, {
|
|
3313
3321
|
at: range,
|
|
3314
3322
|
reverse: operation.direction === "backward",
|
|
3315
3323
|
unit: operation.unit,
|
|
3316
3324
|
hanging
|
|
3325
|
+
}), operation.editor.selection && util_sliceBlocks.isTextBlock(context, startBlock) && util_sliceBlocks.isTextBlock(context, endBlock) && slate.setSelection(operation.editor, {
|
|
3326
|
+
anchor: operation.editor.selection.focus,
|
|
3327
|
+
focus: operation.editor.selection.focus
|
|
3317
3328
|
});
|
|
3318
3329
|
}, insertInlineObjectOperationImplementation = ({
|
|
3319
3330
|
context,
|
|
@@ -3405,19 +3416,19 @@ const addAnnotationOperationImplementation = ({
|
|
|
3405
3416
|
if (!fragment)
|
|
3406
3417
|
throw new Error(`Failed to convert block to Slate fragment ${JSON.stringify(parsedBlock)}`);
|
|
3407
3418
|
insertBlock({
|
|
3419
|
+
context,
|
|
3408
3420
|
block: fragment,
|
|
3409
3421
|
placement: operation.placement,
|
|
3410
3422
|
select: operation.select ?? "start",
|
|
3411
|
-
editor: operation.editor
|
|
3412
|
-
schema: context.schema
|
|
3423
|
+
editor: operation.editor
|
|
3413
3424
|
});
|
|
3414
3425
|
};
|
|
3415
3426
|
function insertBlock({
|
|
3427
|
+
context,
|
|
3416
3428
|
block,
|
|
3417
3429
|
placement,
|
|
3418
3430
|
select,
|
|
3419
|
-
editor
|
|
3420
|
-
schema: schema2
|
|
3431
|
+
editor
|
|
3421
3432
|
}) {
|
|
3422
3433
|
const [startBlock, startBlockPath] = getSelectionStartBlock({
|
|
3423
3434
|
editor
|
|
@@ -3439,7 +3450,7 @@ function insertBlock({
|
|
|
3439
3450
|
at: nextPath
|
|
3440
3451
|
}), select === "start" ? slate.Transforms.select(editor, slate.Editor.start(editor, nextPath)) : select === "end" && slate.Transforms.select(editor, slate.Editor.end(editor, nextPath));
|
|
3441
3452
|
} else {
|
|
3442
|
-
if (lastBlock && isEqualToEmptyEditor([lastBlock],
|
|
3453
|
+
if (lastBlock && isEqualToEmptyEditor([lastBlock], context.schema)) {
|
|
3443
3454
|
slate.Transforms.removeNodes(editor, {
|
|
3444
3455
|
at: lastBlockPath
|
|
3445
3456
|
}), slate.Transforms.insertNodes(editor, [block], {
|
|
@@ -3490,14 +3501,14 @@ function insertBlock({
|
|
|
3490
3501
|
node: block,
|
|
3491
3502
|
path: [newSelection.anchor.path[0]]
|
|
3492
3503
|
}) : newSelection;
|
|
3493
|
-
select === "none" && adjustedSelection && slate.Transforms.select(editor, adjustedSelection), focusBlock && isEqualToEmptyEditor([focusBlock],
|
|
3504
|
+
select === "none" && adjustedSelection && slate.Transforms.select(editor, adjustedSelection), focusBlock && isEqualToEmptyEditor([focusBlock], context.schema) && slate.Transforms.removeNodes(editor, {
|
|
3494
3505
|
at: focusBlockPath
|
|
3495
3506
|
});
|
|
3496
3507
|
return;
|
|
3497
3508
|
}
|
|
3498
3509
|
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
3499
3510
|
const selectionStartPoint = slate.Range.start(currentSelection);
|
|
3500
|
-
if (isEqualToEmptyEditor([endBlock],
|
|
3511
|
+
if (isEqualToEmptyEditor([endBlock], context.schema)) {
|
|
3501
3512
|
const currentSelection2 = editor.selection;
|
|
3502
3513
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3503
3514
|
at: endBlockPath,
|
|
@@ -3507,17 +3518,46 @@ function insertBlock({
|
|
|
3507
3518
|
}), select === "start" ? slate.Transforms.select(editor, selectionStartPoint) : select === "end" ? slate.Transforms.select(editor, slate.Editor.end(editor, endBlockPath)) : slate.Transforms.select(editor, currentSelection2);
|
|
3508
3519
|
return;
|
|
3509
3520
|
}
|
|
3510
|
-
|
|
3511
|
-
|
|
3521
|
+
const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
3522
|
+
if (endBlockMarkDefsKeys.includes(markDef._key)) {
|
|
3523
|
+
const newKey = context.keyGenerator();
|
|
3524
|
+
return markDefKeyMap.set(markDef._key, newKey), {
|
|
3525
|
+
...markDef,
|
|
3526
|
+
_key: newKey
|
|
3527
|
+
};
|
|
3528
|
+
}
|
|
3529
|
+
return markDef;
|
|
3530
|
+
}), adjustedChildren = block.children.map((child) => {
|
|
3531
|
+
if (util_sliceBlocks.isSpan(context, child)) {
|
|
3532
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
3533
|
+
if (!isEqual__default.default(child.marks, marks))
|
|
3534
|
+
return {
|
|
3535
|
+
...child,
|
|
3536
|
+
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
3537
|
+
marks
|
|
3538
|
+
};
|
|
3539
|
+
}
|
|
3540
|
+
return endBlockChildKeys.includes(child._key) ? {
|
|
3541
|
+
...child,
|
|
3542
|
+
_key: context.keyGenerator()
|
|
3543
|
+
} : child;
|
|
3544
|
+
});
|
|
3545
|
+
slate.Transforms.setNodes(editor, {
|
|
3546
|
+
markDefs: [...endBlock.markDefs ?? [], ...adjustedMarkDefs ?? []]
|
|
3512
3547
|
}, {
|
|
3513
3548
|
at: endBlockPath
|
|
3514
|
-
})
|
|
3515
|
-
|
|
3549
|
+
});
|
|
3550
|
+
const adjustedBlock = isEqual__default.default(block.children, adjustedChildren) ? block : {
|
|
3551
|
+
...block,
|
|
3552
|
+
children: adjustedChildren
|
|
3553
|
+
};
|
|
3554
|
+
if (select === "end") {
|
|
3555
|
+
slate.Transforms.insertFragment(editor, [adjustedBlock], {
|
|
3516
3556
|
voids: !0
|
|
3517
3557
|
});
|
|
3518
3558
|
return;
|
|
3519
3559
|
}
|
|
3520
|
-
slate.Transforms.insertFragment(editor, [
|
|
3560
|
+
slate.Transforms.insertFragment(editor, [adjustedBlock], {
|
|
3521
3561
|
at: currentSelection,
|
|
3522
3562
|
voids: !0
|
|
3523
3563
|
}), select === "start" ? slate.Transforms.select(editor, selectionStartPoint) : slate.Point.equals(selectionStartPoint, endBlockEndPoint) || slate.Transforms.select(editor, selectionStartPoint);
|
|
@@ -3527,9 +3567,7 @@ function insertBlock({
|
|
|
3527
3567
|
slate.Transforms.insertNodes(editor, [block], {
|
|
3528
3568
|
at: endBlockPath,
|
|
3529
3569
|
select: !1
|
|
3530
|
-
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, endBlockPath)), util_isSelectionCollapsed.isEmptyTextBlock({
|
|
3531
|
-
schema: schema2
|
|
3532
|
-
}, endBlock) && slate.Transforms.removeNodes(editor, {
|
|
3570
|
+
}), (select === "start" || select === "end") && slate.Transforms.select(editor, slate.Editor.start(editor, endBlockPath)), util_isSelectionCollapsed.isEmptyTextBlock(context, endBlock) && slate.Transforms.removeNodes(editor, {
|
|
3533
3571
|
at: slate.Path.next(endBlockPath)
|
|
3534
3572
|
});
|
|
3535
3573
|
else if (slate.Range.isCollapsed(currentSelection) && slate.Point.equals(selectionEndPoint, endBlockEndPoint2)) {
|
|
@@ -4065,6 +4103,58 @@ function createWithObjectKeys(editorActor) {
|
|
|
4065
4103
|
});
|
|
4066
4104
|
return;
|
|
4067
4105
|
}
|
|
4106
|
+
if (operation.type === "merge_node") {
|
|
4107
|
+
const index = operation.path[operation.path.length - 1], prevPath = slate.Path.previous(operation.path), prevIndex = prevPath[prevPath.length - 1];
|
|
4108
|
+
if (operation.path.length !== 1 || prevPath.length !== 1) {
|
|
4109
|
+
apply2(operation);
|
|
4110
|
+
return;
|
|
4111
|
+
}
|
|
4112
|
+
const block = editor.value.at(index), previousBlock = editor.value.at(prevIndex);
|
|
4113
|
+
if (!block || !previousBlock) {
|
|
4114
|
+
apply2(operation);
|
|
4115
|
+
return;
|
|
4116
|
+
}
|
|
4117
|
+
if (!util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, block) || !util_sliceBlocks.isTextBlock(editorActor.getSnapshot().context, previousBlock)) {
|
|
4118
|
+
apply2(operation);
|
|
4119
|
+
return;
|
|
4120
|
+
}
|
|
4121
|
+
const previousBlockChildKeys = previousBlock.children.map((child) => child._key), previousBlockMarkDefKeys = previousBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
4122
|
+
if (previousBlockMarkDefKeys.includes(markDef._key)) {
|
|
4123
|
+
const newKey = editorActor.getSnapshot().context.keyGenerator();
|
|
4124
|
+
return markDefKeyMap.set(markDef._key, newKey), {
|
|
4125
|
+
...markDef,
|
|
4126
|
+
_key: newKey
|
|
4127
|
+
};
|
|
4128
|
+
}
|
|
4129
|
+
return markDef;
|
|
4130
|
+
});
|
|
4131
|
+
let childIndex = 0;
|
|
4132
|
+
for (const child of block.children) {
|
|
4133
|
+
if (util_sliceBlocks.isSpan(editorActor.getSnapshot().context, child)) {
|
|
4134
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
4135
|
+
isEqual__default.default(child.marks, marks) || slate.Transforms.setNodes(editor, {
|
|
4136
|
+
marks
|
|
4137
|
+
}, {
|
|
4138
|
+
at: [index, childIndex]
|
|
4139
|
+
});
|
|
4140
|
+
}
|
|
4141
|
+
previousBlockChildKeys.includes(child._key) && slate.Transforms.setNodes(editor, {
|
|
4142
|
+
_key: editorActor.getSnapshot().context.keyGenerator()
|
|
4143
|
+
}, {
|
|
4144
|
+
at: [index, childIndex]
|
|
4145
|
+
}), childIndex++;
|
|
4146
|
+
}
|
|
4147
|
+
apply2({
|
|
4148
|
+
...operation,
|
|
4149
|
+
properties: {
|
|
4150
|
+
...operation.properties,
|
|
4151
|
+
// Make sure the adjusted markDefs are carried along for the merge
|
|
4152
|
+
// operation
|
|
4153
|
+
markDefs: adjustedMarkDefs
|
|
4154
|
+
}
|
|
4155
|
+
});
|
|
4156
|
+
return;
|
|
4157
|
+
}
|
|
4068
4158
|
apply2(operation);
|
|
4069
4159
|
}, editor.normalizeNode = (entry) => {
|
|
4070
4160
|
const [node, path] = entry;
|
|
@@ -4239,7 +4329,7 @@ function setPatch(editor, patch) {
|
|
|
4239
4329
|
children,
|
|
4240
4330
|
...nextRest
|
|
4241
4331
|
} = value, {
|
|
4242
|
-
children:
|
|
4332
|
+
children: _prevChildren,
|
|
4243
4333
|
...prevRest
|
|
4244
4334
|
} = block.node || {
|
|
4245
4335
|
children: void 0
|
|
@@ -6967,6 +7057,57 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
6967
7057
|
at: selection
|
|
6968
7058
|
})]]
|
|
6969
7059
|
}),
|
|
7060
|
+
behaviors_index.defineBehavior({
|
|
7061
|
+
on: "split",
|
|
7062
|
+
guard: ({
|
|
7063
|
+
snapshot
|
|
7064
|
+
}) => {
|
|
7065
|
+
const selection = snapshot.context.selection;
|
|
7066
|
+
if (!selection || util_isSelectionCollapsed.isSelectionCollapsed(selection))
|
|
7067
|
+
return !1;
|
|
7068
|
+
const selectionStartBlock = selector_isSelectingEntireBlocks.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectingEntireBlocks.getSelectionEndBlock(snapshot);
|
|
7069
|
+
if (!selectionStartBlock || !selectionEndBlock || selectionStartBlock.node._key === selectionEndBlock.node._key)
|
|
7070
|
+
return !1;
|
|
7071
|
+
const startPoint = util_sliceBlocks.getSelectionStartPoint(selection), startBlockEndPoint = util_isSelectionCollapsed.getBlockEndPoint({
|
|
7072
|
+
context: snapshot.context,
|
|
7073
|
+
block: selectionStartBlock
|
|
7074
|
+
}), endPoint = util_sliceBlocks.getSelectionEndPoint(selection), endBlockStartPoint = util_sliceBlocks.getBlockStartPoint({
|
|
7075
|
+
context: snapshot.context,
|
|
7076
|
+
block: selectionEndBlock
|
|
7077
|
+
}), blocksInBetween = selector_isSelectionExpanded.getSelectedValue(snapshot).filter((block) => block._key !== selectionStartBlock.node._key && block._key !== selectionEndBlock.node._key);
|
|
7078
|
+
return {
|
|
7079
|
+
startPoint,
|
|
7080
|
+
startBlockEndPoint,
|
|
7081
|
+
endPoint,
|
|
7082
|
+
endBlockStartPoint,
|
|
7083
|
+
blocksInBetween
|
|
7084
|
+
};
|
|
7085
|
+
},
|
|
7086
|
+
actions: [(_, {
|
|
7087
|
+
startPoint,
|
|
7088
|
+
startBlockEndPoint,
|
|
7089
|
+
endPoint,
|
|
7090
|
+
endBlockStartPoint,
|
|
7091
|
+
blocksInBetween
|
|
7092
|
+
}) => [behaviors_index.raise({
|
|
7093
|
+
type: "delete",
|
|
7094
|
+
at: {
|
|
7095
|
+
anchor: startPoint,
|
|
7096
|
+
focus: startBlockEndPoint
|
|
7097
|
+
}
|
|
7098
|
+
}), ...blocksInBetween.map((block) => behaviors_index.raise({
|
|
7099
|
+
type: "delete.block",
|
|
7100
|
+
at: [{
|
|
7101
|
+
_key: block._key
|
|
7102
|
+
}]
|
|
7103
|
+
})), behaviors_index.raise({
|
|
7104
|
+
type: "delete",
|
|
7105
|
+
at: {
|
|
7106
|
+
anchor: endBlockStartPoint,
|
|
7107
|
+
focus: endPoint
|
|
7108
|
+
}
|
|
7109
|
+
})]]
|
|
7110
|
+
}),
|
|
6970
7111
|
behaviors_index.defineBehavior({
|
|
6971
7112
|
on: "split",
|
|
6972
7113
|
guard: ({
|
|
@@ -7013,8 +7154,8 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior
|
|
|
7013
7154
|
}),
|
|
7014
7155
|
context: snapshot.context,
|
|
7015
7156
|
options: {
|
|
7016
|
-
refreshKeys: !
|
|
7017
|
-
validateFields: !
|
|
7157
|
+
refreshKeys: !1,
|
|
7158
|
+
validateFields: !1
|
|
7018
7159
|
}
|
|
7019
7160
|
});
|
|
7020
7161
|
return newTextBlock ? {
|
|
@@ -11341,8 +11482,8 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11341
11482
|
},
|
|
11342
11483
|
blocks: result_1.insert,
|
|
11343
11484
|
options: {
|
|
11344
|
-
refreshKeys: !
|
|
11345
|
-
validateFields: !
|
|
11485
|
+
refreshKeys: !1,
|
|
11486
|
+
validateFields: !1
|
|
11346
11487
|
}
|
|
11347
11488
|
}),
|
|
11348
11489
|
placement: "auto"
|