@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.js CHANGED
@@ -994,7 +994,7 @@ function RenderTextBlock(props) {
994
994
  style: props.textBlock.style,
995
995
  type: legacyBlockSchemaType,
996
996
  value: props.textBlock
997
- }) : props.children }),
997
+ }) : children }),
998
998
  dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
999
999
  ] });
1000
1000
  }
@@ -5872,11 +5872,26 @@ const coreDndBehaviors = [
5872
5872
  type: "delete.block",
5873
5873
  at: block.path
5874
5874
  }))]]
5875
+ }), breakingInlineObject = defineBehavior({
5876
+ on: "insert.break",
5877
+ guard: ({
5878
+ snapshot
5879
+ }) => {
5880
+ const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusInlineObject = getFocusInlineObject(snapshot);
5881
+ return selectionCollapsed && focusInlineObject;
5882
+ },
5883
+ actions: [() => [raise({
5884
+ type: "move.forward",
5885
+ distance: 1
5886
+ }), raise({
5887
+ type: "split"
5888
+ })]]
5875
5889
  }), coreInsertBreakBehaviors = {
5876
5890
  breakingAtTheEndOfTextBlock,
5877
5891
  breakingAtTheStartOfTextBlock,
5878
5892
  breakingEntireDocument,
5879
- breakingEntireBlocks
5893
+ breakingEntireBlocks,
5894
+ breakingInlineObject
5880
5895
  }, MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
5881
5896
  on: "delete.backward",
5882
5897
  guard: ({
@@ -5988,7 +6003,7 @@ const coreDndBehaviors = [
5988
6003
  clearListOnEnter,
5989
6004
  indentListOnTab,
5990
6005
  unindentListOnShiftTab
5991
- }, 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) => ({
6006
+ }, 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) => ({
5992
6007
  behavior,
5993
6008
  priority: corePriority
5994
6009
  }));
@@ -6283,8 +6298,19 @@ const abstractAnnotationBehaviors = [defineBehavior({
6283
6298
  `
6284
6299
  })]]
6285
6300
  })], keyIs = {
6301
+ break: (event) => event.key === "Enter" && !event.shiftKey,
6286
6302
  lineBreak: (event) => event.key === "Enter" && event.shiftKey
6287
6303
  }, abstractKeyboardBehaviors = [
6304
+ defineBehavior({
6305
+ on: "keyboard.keydown",
6306
+ guard: ({
6307
+ snapshot,
6308
+ event
6309
+ }) => keyIs.break(event.originEvent) && isSelectionCollapsed$1(snapshot) && getFocusInlineObject(snapshot),
6310
+ actions: [() => [raise({
6311
+ type: "insert.break"
6312
+ })]]
6313
+ }),
6288
6314
  /**
6289
6315
  * On WebKit, Shift+Enter results in an `insertParagraph` input event rather
6290
6316
  * than an `insertLineBreak` input event. This Behavior makes sure we catch
@@ -6482,28 +6508,82 @@ const abstractAnnotationBehaviors = [defineBehavior({
6482
6508
  type: "select",
6483
6509
  at: selection
6484
6510
  })]]
6485
- })], abstractSplitBehaviors = [defineBehavior({
6486
- on: "split",
6487
- guard: ({
6488
- snapshot
6489
- }) => {
6490
- if (!snapshot.context.selection)
6491
- return !1;
6492
- const selectionStartPoint = getSelectionStartPoint(snapshot.context.selection), selectionEndPoint = getSelectionEndPoint(snapshot.context.selection), focusTextBlock = getFocusTextBlock({
6493
- context: {
6494
- ...snapshot.context,
6495
- selection: {
6496
- anchor: selectionStartPoint,
6497
- focus: selectionEndPoint
6498
- }
6499
- }
6500
- });
6501
- if (focusTextBlock) {
6511
+ })], abstractSplitBehaviors = [
6512
+ /**
6513
+ * You can't split an inline object.
6514
+ */
6515
+ defineBehavior({
6516
+ on: "split",
6517
+ guard: ({
6518
+ snapshot
6519
+ }) => isSelectionCollapsed$1(snapshot) && getFocusInlineObject(snapshot),
6520
+ actions: []
6521
+ }),
6522
+ /**
6523
+ * You can't split a block object.
6524
+ */
6525
+ defineBehavior({
6526
+ on: "split",
6527
+ guard: ({
6528
+ snapshot
6529
+ }) => isSelectionCollapsed$1(snapshot) && getFocusBlockObject(snapshot),
6530
+ actions: []
6531
+ }),
6532
+ defineBehavior({
6533
+ on: "split",
6534
+ guard: ({
6535
+ snapshot
6536
+ }) => {
6537
+ const selection = snapshot.context.selection;
6538
+ if (!selection || isSelectionCollapsed(selection))
6539
+ return !1;
6540
+ const selectionStartBlock = getSelectionStartBlock$1(snapshot), selectionEndBlock = getSelectionEndBlock$1(snapshot);
6541
+ return !selectionStartBlock || !selectionEndBlock ? !1 : !isTextBlock(snapshot.context, selectionStartBlock.node) && isTextBlock(snapshot.context, selectionEndBlock.node) ? {
6542
+ selection
6543
+ } : !1;
6544
+ },
6545
+ actions: [(_, {
6546
+ selection
6547
+ }) => [raise({
6548
+ type: "delete",
6549
+ at: selection
6550
+ })]]
6551
+ }),
6552
+ defineBehavior({
6553
+ on: "split",
6554
+ guard: ({
6555
+ snapshot
6556
+ }) => {
6557
+ const selection = snapshot.context.selection;
6558
+ return !selection || isSelectionCollapsed(selection) ? !1 : {
6559
+ selection
6560
+ };
6561
+ },
6562
+ actions: [(_, {
6563
+ selection
6564
+ }) => [raise({
6565
+ type: "delete",
6566
+ at: selection
6567
+ }), raise({
6568
+ type: "split"
6569
+ })]]
6570
+ }),
6571
+ defineBehavior({
6572
+ on: "split",
6573
+ guard: ({
6574
+ snapshot
6575
+ }) => {
6576
+ const selection = snapshot.context.selection;
6577
+ if (!selection || !isSelectionCollapsed(selection))
6578
+ return !1;
6579
+ const selectionStartPoint = getSelectionStartPoint(selection), focusTextBlock = getFocusTextBlock(snapshot);
6580
+ if (!focusTextBlock)
6581
+ return !1;
6502
6582
  const blockEndPoint = getBlockEndPoint({
6503
6583
  context: snapshot.context,
6504
6584
  block: focusTextBlock
6505
6585
  }), newTextBlockSelection = {
6506
- anchor: selectionEndPoint,
6586
+ anchor: selectionStartPoint,
6507
6587
  focus: blockEndPoint
6508
6588
  }, newTextBlock = parseBlock({
6509
6589
  block: sliceBlocks({
@@ -6519,64 +6599,30 @@ const abstractAnnotationBehaviors = [defineBehavior({
6519
6599
  validateFields: !0
6520
6600
  }
6521
6601
  });
6522
- return !newTextBlock || !isTextBlock(snapshot.context, newTextBlock) ? !1 : {
6523
- newTextBlock,
6524
- newTextBlockSelection,
6525
- selection: {
6526
- anchor: selectionStartPoint,
6527
- focus: blockEndPoint
6528
- }
6529
- };
6530
- }
6531
- if (getFocusBlockObject({
6532
- context: {
6533
- ...snapshot.context,
6534
- selection: {
6535
- anchor: selectionStartPoint,
6536
- focus: selectionEndPoint
6537
- }
6538
- }
6539
- })) {
6540
- const newTextBlock = parseBlock({
6541
- block: {
6542
- _type: snapshot.context.schema.block.name,
6543
- children: []
6544
- },
6545
- context: snapshot.context,
6546
- options: {
6547
- refreshKeys: !0,
6548
- validateFields: !0
6549
- }
6550
- });
6551
6602
  return newTextBlock ? {
6552
6603
  newTextBlock,
6553
- newTextBlockSelection: {
6554
- anchor: selectionEndPoint,
6555
- focus: selectionEndPoint
6556
- },
6557
- selection: snapshot.context.selection
6604
+ newTextBlockSelection
6558
6605
  } : !1;
6559
- }
6560
- return !1;
6561
- },
6562
- actions: [(_, {
6563
- newTextBlock,
6564
- selection
6565
- }) => isSelectionCollapsed(selection) ? [raise({
6566
- type: "insert.block",
6567
- block: newTextBlock,
6568
- placement: "after",
6569
- select: "start"
6570
- })] : [raise({
6571
- type: "delete",
6572
- at: selection
6573
- }), raise({
6574
- type: "insert.block",
6575
- block: newTextBlock,
6576
- placement: "after",
6577
- select: "start"
6578
- })]]
6579
- })], abstractStyleBehaviors = [defineBehavior({
6606
+ },
6607
+ actions: [(_, {
6608
+ newTextBlock,
6609
+ newTextBlockSelection
6610
+ }) => isSelectionCollapsed(newTextBlockSelection) ? [raise({
6611
+ type: "insert.block",
6612
+ block: newTextBlock,
6613
+ placement: "after",
6614
+ select: "start"
6615
+ })] : [raise({
6616
+ type: "delete",
6617
+ at: newTextBlockSelection
6618
+ }), raise({
6619
+ type: "insert.block",
6620
+ block: newTextBlock,
6621
+ placement: "after",
6622
+ select: "start"
6623
+ })]]
6624
+ })
6625
+ ], abstractStyleBehaviors = [defineBehavior({
6580
6626
  on: "style.add",
6581
6627
  guard: ({
6582
6628
  snapshot