@portabletext/editor 2.2.0 → 2.3.1

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
@@ -11,8 +11,8 @@ import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION } from "slate-dom";
11
11
  import { getBlockStartPoint, getBlockKeyFromSelectionPoint, isTextBlock, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, isSpan, parseBlock, parseAnnotation, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
12
12
  import { getBlockEndPoint, isSelectionCollapsed, isEqualSelectionPoints, isEmptyTextBlock } from "./_chunks-es/util.is-selection-collapsed.js";
13
13
  import isEqual from "lodash/isEqual.js";
14
- import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.is-selection-expanded.js";
15
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
14
+ import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.is-selection-expanded.js";
15
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getActiveAnnotationsMarks, getTrimmedSelection, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveAnnotation, isActiveDecorator, getSelectedTextBlocks, isActiveListItem, isActiveStyle, getActiveAnnotations } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
16
16
  import getRandomValues from "get-random-values-esm";
17
17
  import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
18
18
  import uniq from "lodash/uniq.js";
@@ -6288,6 +6288,126 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
6288
6288
  type: "delete.block",
6289
6289
  at: focusTextBlock.path
6290
6290
  })]]
6291
+ }), deletingListFromStart = defineBehavior({
6292
+ on: "delete",
6293
+ guard: ({
6294
+ snapshot,
6295
+ event
6296
+ }) => {
6297
+ const blocksToDelete = getSelectedBlocks({
6298
+ ...snapshot,
6299
+ context: {
6300
+ ...snapshot.context,
6301
+ selection: event.at
6302
+ }
6303
+ });
6304
+ if (blocksToDelete.length < 2)
6305
+ return !1;
6306
+ const startBlock = blocksToDelete.at(0)?.node, middleBlocks = blocksToDelete.slice(1, -1), endBlock = blocksToDelete.at(-1)?.node;
6307
+ if (!isListBlock(snapshot.context, startBlock) || !isListBlock(snapshot.context, endBlock))
6308
+ return !1;
6309
+ const deleteStartPoint = getSelectionStartPoint$1({
6310
+ context: {
6311
+ ...snapshot.context,
6312
+ selection: event.at
6313
+ }
6314
+ }), deleteEndPoint = getSelectionEndPoint$1({
6315
+ context: {
6316
+ ...snapshot.context,
6317
+ selection: event.at
6318
+ }
6319
+ });
6320
+ if (!deleteStartPoint || !deleteEndPoint)
6321
+ return !1;
6322
+ const startBlockStartPoint = getBlockStartPoint({
6323
+ context: snapshot.context,
6324
+ block: {
6325
+ node: startBlock,
6326
+ path: [{
6327
+ _key: startBlock._key
6328
+ }]
6329
+ }
6330
+ });
6331
+ if (!isEqualSelectionPoints(deleteStartPoint, startBlockStartPoint))
6332
+ return !1;
6333
+ const startBlockEndPoint = getBlockEndPoint({
6334
+ context: snapshot.context,
6335
+ block: {
6336
+ node: startBlock,
6337
+ path: [{
6338
+ _key: startBlock._key
6339
+ }]
6340
+ }
6341
+ }), endBlockEndPoint = getBlockEndPoint({
6342
+ context: snapshot.context,
6343
+ block: {
6344
+ node: endBlock,
6345
+ path: [{
6346
+ _key: endBlock._key
6347
+ }]
6348
+ }
6349
+ }), slicedEndBlock = sliceTextBlock({
6350
+ context: {
6351
+ schema: snapshot.context.schema,
6352
+ selection: {
6353
+ anchor: deleteEndPoint,
6354
+ focus: endBlockEndPoint
6355
+ }
6356
+ },
6357
+ block: endBlock
6358
+ });
6359
+ return {
6360
+ startBlockStartPoint,
6361
+ startBlockEndPoint,
6362
+ middleBlocks,
6363
+ endBlock,
6364
+ slicedEndBlock
6365
+ };
6366
+ },
6367
+ actions: [(_, {
6368
+ startBlockStartPoint,
6369
+ startBlockEndPoint,
6370
+ middleBlocks,
6371
+ endBlock,
6372
+ slicedEndBlock
6373
+ }) => [
6374
+ // All block in between can safely be deleted.
6375
+ ...middleBlocks.map((block) => raise({
6376
+ type: "delete.block",
6377
+ at: block.path
6378
+ })),
6379
+ // The last block is deleted as well.
6380
+ raise({
6381
+ type: "delete.block",
6382
+ at: [{
6383
+ _key: endBlock._key
6384
+ }]
6385
+ }),
6386
+ // But in case the delete operation didn't reach all the way to the end
6387
+ // of it, we first place the caret at the end of the start block...
6388
+ raise({
6389
+ type: "select",
6390
+ at: {
6391
+ anchor: startBlockEndPoint,
6392
+ focus: startBlockEndPoint
6393
+ }
6394
+ }),
6395
+ // ...and insert the rest of the end block at the end of it.
6396
+ raise({
6397
+ type: "insert.block",
6398
+ block: slicedEndBlock,
6399
+ placement: "auto",
6400
+ select: "none"
6401
+ }),
6402
+ // And finally, we delete the original text of the start block.
6403
+ raise({
6404
+ type: "delete",
6405
+ at: {
6406
+ anchor: startBlockStartPoint,
6407
+ focus: startBlockEndPoint
6408
+ }
6409
+ })
6410
+ ]]
6291
6411
  }), clearListOnEnter = defineBehavior({
6292
6412
  on: "insert.break",
6293
6413
  guard: ({
@@ -6452,13 +6572,14 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
6452
6572
  unindentListOnBackspace,
6453
6573
  mergeTextIntoListOnDelete,
6454
6574
  mergeTextIntoListOnBackspace,
6575
+ deletingListFromStart,
6455
6576
  clearListOnEnter,
6456
6577
  indentListOnTab,
6457
6578
  unindentListOnShiftTab,
6458
6579
  inheritListLevel,
6459
6580
  inheritListItem,
6460
6581
  inheritListProperties
6461
- }, 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.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
6582
+ }, 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.mergeTextIntoListOnDelete, coreListBehaviors.mergeTextIntoListOnBackspace, coreListBehaviors.deletingListFromStart, coreListBehaviors.clearListOnEnter, coreListBehaviors.indentListOnTab, coreListBehaviors.unindentListOnShiftTab, coreListBehaviors.inheritListLevel, coreListBehaviors.inheritListItem, coreListBehaviors.inheritListProperties, coreInsertBreakBehaviors.breakingAtTheEndOfTextBlock, coreInsertBreakBehaviors.breakingAtTheStartOfTextBlock, coreInsertBreakBehaviors.breakingEntireDocument, coreInsertBreakBehaviors.breakingEntireBlocks, coreInsertBreakBehaviors.breakingInlineObject].map((behavior) => ({
6462
6583
  behavior,
6463
6584
  priority: corePriority
6464
6585
  })), abstractAnnotationBehaviors = [defineBehavior({
@@ -6587,6 +6708,44 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
6587
6708
  unit: event.unit,
6588
6709
  at: selection
6589
6710
  })]]
6711
+ }), defineBehavior({
6712
+ on: "delete",
6713
+ guard: ({
6714
+ snapshot,
6715
+ event
6716
+ }) => {
6717
+ if (event.direction !== "backward")
6718
+ return !1;
6719
+ const previousBlock = getPreviousBlock(snapshot), focusTextBlock = getFocusTextBlock(snapshot);
6720
+ if (!previousBlock || !focusTextBlock || !isAtTheStartOfBlock(focusTextBlock)(snapshot))
6721
+ return !1;
6722
+ const previousBlockEndPoint = getBlockEndPoint({
6723
+ context: snapshot.context,
6724
+ block: previousBlock
6725
+ });
6726
+ return isTextBlock(snapshot.context, previousBlock.node) ? {
6727
+ previousBlockEndPoint,
6728
+ focusTextBlock
6729
+ } : !1;
6730
+ },
6731
+ actions: [(_, {
6732
+ previousBlockEndPoint,
6733
+ focusTextBlock
6734
+ }) => [raise({
6735
+ type: "delete.block",
6736
+ at: focusTextBlock.path
6737
+ }), raise({
6738
+ type: "select",
6739
+ at: {
6740
+ anchor: previousBlockEndPoint,
6741
+ focus: previousBlockEndPoint
6742
+ }
6743
+ }), raise({
6744
+ type: "insert.block",
6745
+ block: focusTextBlock.node,
6746
+ placement: "auto",
6747
+ select: "start"
6748
+ })]]
6590
6749
  }), defineBehavior({
6591
6750
  on: "delete.forward",
6592
6751
  guard: ({
@@ -6604,6 +6763,30 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
6604
6763
  unit: event.unit,
6605
6764
  at: selection
6606
6765
  })]]
6766
+ }), defineBehavior({
6767
+ on: "delete",
6768
+ guard: ({
6769
+ snapshot,
6770
+ event
6771
+ }) => {
6772
+ if (event.direction !== "forward")
6773
+ return !1;
6774
+ const nextBlock = getNextBlock(snapshot), focusTextBlock = getFocusTextBlock(snapshot);
6775
+ return !nextBlock || !focusTextBlock || !isAtTheEndOfBlock(focusTextBlock)(snapshot) || !isTextBlock(snapshot.context, nextBlock.node) ? !1 : {
6776
+ nextBlock
6777
+ };
6778
+ },
6779
+ actions: [(_, {
6780
+ nextBlock
6781
+ }) => [raise({
6782
+ type: "delete.block",
6783
+ at: nextBlock.path
6784
+ }), raise({
6785
+ type: "insert.block",
6786
+ block: nextBlock.node,
6787
+ placement: "auto",
6788
+ select: "none"
6789
+ })]]
6607
6790
  }), defineBehavior({
6608
6791
  on: "delete.block",
6609
6792
  actions: [({