@portabletext/editor 1.52.7 → 1.53.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/index.cjs +122 -76
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +122 -76
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/behaviors/behavior.abstract.keyboard.ts +10 -0
- package/src/behaviors/behavior.abstract.split.ts +105 -87
- package/src/behaviors/behavior.core.insert-break.ts +14 -0
- package/src/behaviors/behavior.core.ts +1 -0
- package/src/editor/components/render-text-block.tsx +1 -1
- package/src/internal-utils/key-is.ts +1 -0
package/lib/index.cjs
CHANGED
|
@@ -965,7 +965,7 @@ function RenderTextBlock(props) {
|
|
|
965
965
|
style: props.textBlock.style,
|
|
966
966
|
type: legacyBlockSchemaType,
|
|
967
967
|
value: props.textBlock
|
|
968
|
-
}) :
|
|
968
|
+
}) : children }),
|
|
969
969
|
dragPositionBlock === "end" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null
|
|
970
970
|
] });
|
|
971
971
|
}
|
|
@@ -5843,11 +5843,26 @@ const coreDndBehaviors = [
|
|
|
5843
5843
|
type: "delete.block",
|
|
5844
5844
|
at: block.path
|
|
5845
5845
|
}))]]
|
|
5846
|
+
}), breakingInlineObject = behaviors_index.defineBehavior({
|
|
5847
|
+
on: "insert.break",
|
|
5848
|
+
guard: ({
|
|
5849
|
+
snapshot
|
|
5850
|
+
}) => {
|
|
5851
|
+
const selectionCollapsed = selector_isSelectionExpanded.isSelectionCollapsed(snapshot), focusInlineObject = selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot);
|
|
5852
|
+
return selectionCollapsed && focusInlineObject;
|
|
5853
|
+
},
|
|
5854
|
+
actions: [() => [behaviors_index.raise({
|
|
5855
|
+
type: "move.forward",
|
|
5856
|
+
distance: 1
|
|
5857
|
+
}), behaviors_index.raise({
|
|
5858
|
+
type: "split"
|
|
5859
|
+
})]]
|
|
5846
5860
|
}), coreInsertBreakBehaviors = {
|
|
5847
5861
|
breakingAtTheEndOfTextBlock,
|
|
5848
5862
|
breakingAtTheStartOfTextBlock,
|
|
5849
5863
|
breakingEntireDocument,
|
|
5850
|
-
breakingEntireBlocks
|
|
5864
|
+
breakingEntireBlocks,
|
|
5865
|
+
breakingInlineObject
|
|
5851
5866
|
}, MAX_LIST_LEVEL = 10, clearListOnBackspace = behaviors_index.defineBehavior({
|
|
5852
5867
|
on: "delete.backward",
|
|
5853
5868
|
guard: ({
|
|
@@ -5959,7 +5974,7 @@ const coreDndBehaviors = [
|
|
|
5959
5974
|
clearListOnEnter,
|
|
5960
5975
|
indentListOnTab,
|
|
5961
5976
|
unindentListOnShiftTab
|
|
5962
|
-
}, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks].map((behavior) => ({
|
|
5977
|
+
}, coreBehaviorsConfig = [coreAnnotationBehaviors.addAnnotationOnCollapsedSelection, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, coreListBehaviors.clearListOnBackspace, coreListBehaviors.unindentListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
|
|
5963
5978
|
behavior,
|
|
5964
5979
|
priority: corePriority
|
|
5965
5980
|
}));
|
|
@@ -6254,8 +6269,19 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
6254
6269
|
`
|
|
6255
6270
|
})]]
|
|
6256
6271
|
})], keyIs = {
|
|
6272
|
+
break: (event) => event.key === "Enter" && !event.shiftKey,
|
|
6257
6273
|
lineBreak: (event) => event.key === "Enter" && event.shiftKey
|
|
6258
6274
|
}, abstractKeyboardBehaviors = [
|
|
6275
|
+
behaviors_index.defineBehavior({
|
|
6276
|
+
on: "keyboard.keydown",
|
|
6277
|
+
guard: ({
|
|
6278
|
+
snapshot,
|
|
6279
|
+
event
|
|
6280
|
+
}) => keyIs.break(event.originEvent) && selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6281
|
+
actions: [() => [behaviors_index.raise({
|
|
6282
|
+
type: "insert.break"
|
|
6283
|
+
})]]
|
|
6284
|
+
}),
|
|
6259
6285
|
/**
|
|
6260
6286
|
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
6261
6287
|
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
@@ -6453,28 +6479,82 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
6453
6479
|
type: "select",
|
|
6454
6480
|
at: selection
|
|
6455
6481
|
})]]
|
|
6456
|
-
})], abstractSplitBehaviors = [
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6482
|
+
})], abstractSplitBehaviors = [
|
|
6483
|
+
/**
|
|
6484
|
+
* You can't split an inline object.
|
|
6485
|
+
*/
|
|
6486
|
+
behaviors_index.defineBehavior({
|
|
6487
|
+
on: "split",
|
|
6488
|
+
guard: ({
|
|
6489
|
+
snapshot
|
|
6490
|
+
}) => selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectingEntireBlocks.getFocusInlineObject(snapshot),
|
|
6491
|
+
actions: []
|
|
6492
|
+
}),
|
|
6493
|
+
/**
|
|
6494
|
+
* You can't split a block object.
|
|
6495
|
+
*/
|
|
6496
|
+
behaviors_index.defineBehavior({
|
|
6497
|
+
on: "split",
|
|
6498
|
+
guard: ({
|
|
6499
|
+
snapshot
|
|
6500
|
+
}) => selector_isSelectionExpanded.isSelectionCollapsed(snapshot) && selector_isSelectionExpanded.getFocusBlockObject(snapshot),
|
|
6501
|
+
actions: []
|
|
6502
|
+
}),
|
|
6503
|
+
behaviors_index.defineBehavior({
|
|
6504
|
+
on: "split",
|
|
6505
|
+
guard: ({
|
|
6506
|
+
snapshot
|
|
6507
|
+
}) => {
|
|
6508
|
+
const selection = snapshot.context.selection;
|
|
6509
|
+
if (!selection || util_selectionPointToBlockOffset.isSelectionCollapsed(selection))
|
|
6510
|
+
return !1;
|
|
6511
|
+
const selectionStartBlock = selector_isSelectionExpanded.getSelectionStartBlock(snapshot), selectionEndBlock = selector_isSelectionExpanded.getSelectionEndBlock(snapshot);
|
|
6512
|
+
return !selectionStartBlock || !selectionEndBlock ? !1 : !selectionPoint.isTextBlock(snapshot.context, selectionStartBlock.node) && selectionPoint.isTextBlock(snapshot.context, selectionEndBlock.node) ? {
|
|
6513
|
+
selection
|
|
6514
|
+
} : !1;
|
|
6515
|
+
},
|
|
6516
|
+
actions: [(_, {
|
|
6517
|
+
selection
|
|
6518
|
+
}) => [behaviors_index.raise({
|
|
6519
|
+
type: "delete",
|
|
6520
|
+
at: selection
|
|
6521
|
+
})]]
|
|
6522
|
+
}),
|
|
6523
|
+
behaviors_index.defineBehavior({
|
|
6524
|
+
on: "split",
|
|
6525
|
+
guard: ({
|
|
6526
|
+
snapshot
|
|
6527
|
+
}) => {
|
|
6528
|
+
const selection = snapshot.context.selection;
|
|
6529
|
+
return !selection || util_selectionPointToBlockOffset.isSelectionCollapsed(selection) ? !1 : {
|
|
6530
|
+
selection
|
|
6531
|
+
};
|
|
6532
|
+
},
|
|
6533
|
+
actions: [(_, {
|
|
6534
|
+
selection
|
|
6535
|
+
}) => [behaviors_index.raise({
|
|
6536
|
+
type: "delete",
|
|
6537
|
+
at: selection
|
|
6538
|
+
}), behaviors_index.raise({
|
|
6539
|
+
type: "split"
|
|
6540
|
+
})]]
|
|
6541
|
+
}),
|
|
6542
|
+
behaviors_index.defineBehavior({
|
|
6543
|
+
on: "split",
|
|
6544
|
+
guard: ({
|
|
6545
|
+
snapshot
|
|
6546
|
+
}) => {
|
|
6547
|
+
const selection = snapshot.context.selection;
|
|
6548
|
+
if (!selection || !util_selectionPointToBlockOffset.isSelectionCollapsed(selection))
|
|
6549
|
+
return !1;
|
|
6550
|
+
const selectionStartPoint = selectionPoint.getSelectionStartPoint(selection), focusTextBlock = selector_isSelectionExpanded.getFocusTextBlock(snapshot);
|
|
6551
|
+
if (!focusTextBlock)
|
|
6552
|
+
return !1;
|
|
6473
6553
|
const blockEndPoint = util_isEqualSelectionPoints.getBlockEndPoint({
|
|
6474
6554
|
context: snapshot.context,
|
|
6475
6555
|
block: focusTextBlock
|
|
6476
6556
|
}), newTextBlockSelection = {
|
|
6477
|
-
anchor:
|
|
6557
|
+
anchor: selectionStartPoint,
|
|
6478
6558
|
focus: blockEndPoint
|
|
6479
6559
|
}, newTextBlock = selectionPoint.parseBlock({
|
|
6480
6560
|
block: selectionPoint.sliceBlocks({
|
|
@@ -6490,64 +6570,30 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
6490
6570
|
validateFields: !0
|
|
6491
6571
|
}
|
|
6492
6572
|
});
|
|
6493
|
-
return !newTextBlock || !selectionPoint.isTextBlock(snapshot.context, newTextBlock) ? !1 : {
|
|
6494
|
-
newTextBlock,
|
|
6495
|
-
newTextBlockSelection,
|
|
6496
|
-
selection: {
|
|
6497
|
-
anchor: selectionStartPoint,
|
|
6498
|
-
focus: blockEndPoint
|
|
6499
|
-
}
|
|
6500
|
-
};
|
|
6501
|
-
}
|
|
6502
|
-
if (selector_isSelectionExpanded.getFocusBlockObject({
|
|
6503
|
-
context: {
|
|
6504
|
-
...snapshot.context,
|
|
6505
|
-
selection: {
|
|
6506
|
-
anchor: selectionStartPoint,
|
|
6507
|
-
focus: selectionEndPoint
|
|
6508
|
-
}
|
|
6509
|
-
}
|
|
6510
|
-
})) {
|
|
6511
|
-
const newTextBlock = selectionPoint.parseBlock({
|
|
6512
|
-
block: {
|
|
6513
|
-
_type: snapshot.context.schema.block.name,
|
|
6514
|
-
children: []
|
|
6515
|
-
},
|
|
6516
|
-
context: snapshot.context,
|
|
6517
|
-
options: {
|
|
6518
|
-
refreshKeys: !0,
|
|
6519
|
-
validateFields: !0
|
|
6520
|
-
}
|
|
6521
|
-
});
|
|
6522
6573
|
return newTextBlock ? {
|
|
6523
6574
|
newTextBlock,
|
|
6524
|
-
newTextBlockSelection
|
|
6525
|
-
anchor: selectionEndPoint,
|
|
6526
|
-
focus: selectionEndPoint
|
|
6527
|
-
},
|
|
6528
|
-
selection: snapshot.context.selection
|
|
6575
|
+
newTextBlockSelection
|
|
6529
6576
|
} : !1;
|
|
6530
|
-
}
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
})], abstractStyleBehaviors = [behaviors_index.defineBehavior({
|
|
6577
|
+
},
|
|
6578
|
+
actions: [(_, {
|
|
6579
|
+
newTextBlock,
|
|
6580
|
+
newTextBlockSelection
|
|
6581
|
+
}) => util_selectionPointToBlockOffset.isSelectionCollapsed(newTextBlockSelection) ? [behaviors_index.raise({
|
|
6582
|
+
type: "insert.block",
|
|
6583
|
+
block: newTextBlock,
|
|
6584
|
+
placement: "after",
|
|
6585
|
+
select: "start"
|
|
6586
|
+
})] : [behaviors_index.raise({
|
|
6587
|
+
type: "delete",
|
|
6588
|
+
at: newTextBlockSelection
|
|
6589
|
+
}), behaviors_index.raise({
|
|
6590
|
+
type: "insert.block",
|
|
6591
|
+
block: newTextBlock,
|
|
6592
|
+
placement: "after",
|
|
6593
|
+
select: "start"
|
|
6594
|
+
})]]
|
|
6595
|
+
})
|
|
6596
|
+
], abstractStyleBehaviors = [behaviors_index.defineBehavior({
|
|
6551
6597
|
on: "style.add",
|
|
6552
6598
|
guard: ({
|
|
6553
6599
|
snapshot
|