@portabletext/editor 2.11.0 → 2.12.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
@@ -14,7 +14,7 @@ import isEqual from "lodash/isEqual.js";
14
14
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
15
15
  import { defineSchema } from "@portabletext/schema";
16
16
  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";
17
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getTrimmedSelection, getActiveAnnotationsMarks, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
17
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getMarkState, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
18
18
  import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
19
19
  import uniq from "lodash/uniq.js";
20
20
  import { setup, fromCallback, assign, and, enqueueActions, emit, assertEvent, raise as raise$1, not, createActor } from "xstate";
@@ -4791,7 +4791,7 @@ const insertChildOperationImplementation = ({
4791
4791
  }) : Transforms.insertNodes(operation.editor, span, {
4792
4792
  at: [focusBlockIndex, focusChildIndex + 1],
4793
4793
  select: !0
4794
- });
4794
+ }), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection);
4795
4795
  return;
4796
4796
  }
4797
4797
  const inlineObject = parseInlineObject({
@@ -4826,44 +4826,9 @@ const insertChildOperationImplementation = ({
4826
4826
  }
4827
4827
  throw new Error("Unable to parse child");
4828
4828
  }, insertTextOperationImplementation = ({
4829
- context,
4830
4829
  operation
4831
4830
  }) => {
4832
- const snapshot = {
4833
- blockIndexMap: operation.editor.blockIndexMap,
4834
- context: {
4835
- value: operation.editor.value,
4836
- selection: operation.editor.selection ? slateRangeToSelection({
4837
- schema: context.schema,
4838
- editor: operation.editor,
4839
- range: operation.editor.selection
4840
- }) : null,
4841
- schema: context.schema,
4842
- keyGenerator: context.keyGenerator,
4843
- converters: [],
4844
- readOnly: !1
4845
- },
4846
- decoratorState: operation.editor.decoratorState
4847
- }, markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot), [focusSpan] = getFocusSpan({
4848
- editor: operation.editor
4849
- });
4850
- if (!focusSpan) {
4851
- Transforms.insertText(operation.editor, operation.text);
4852
- return;
4853
- }
4854
- if (markState && markState.state === "unchanged") {
4855
- const markStateDecorators = (markState.marks ?? []).filter((mark) => context.schema.decorators.map((decorator) => decorator.name).includes(mark));
4856
- if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark))) {
4857
- Transforms.insertText(operation.editor, operation.text);
4858
- return;
4859
- }
4860
- }
4861
- Transforms.insertNodes(operation.editor, {
4862
- _type: focusSpan._type,
4863
- _key: context.keyGenerator(),
4864
- text: operation.text,
4865
- marks: [...activeDecorators, ...activeAnnotations]
4866
- }), EDITOR_TO_PENDING_SELECTION.set(operation.editor, operation.editor.selection), operation.editor.decoratorState = {};
4831
+ Transforms.insertText(operation.editor, operation.text);
4867
4832
  }, moveBackwardOperationImplementation = ({
4868
4833
  operation
4869
4834
  }) => {
@@ -7247,7 +7212,39 @@ const coreDndBehaviors = [
7247
7212
  placement: draggingEntireBlocks ? originEvent.position.block === "start" ? "before" : originEvent.position.block === "end" ? "after" : "auto" : "auto"
7248
7213
  })]]
7249
7214
  })
7250
- ], breakingAtTheEndOfTextBlock = defineBehavior({
7215
+ ], coreInsertBehaviors = [defineBehavior({
7216
+ on: "insert.text",
7217
+ guard: ({
7218
+ snapshot
7219
+ }) => {
7220
+ if (!getFocusSpan$1(snapshot))
7221
+ return !1;
7222
+ const markState = getMarkState(snapshot), activeDecorators = getActiveDecorators(snapshot), activeAnnotations = getActiveAnnotationsMarks(snapshot);
7223
+ if (markState && markState.state === "unchanged") {
7224
+ const markStateDecorators = (markState.marks ?? []).filter((mark) => snapshot.context.schema.decorators.map((decorator) => decorator.name).includes(mark));
7225
+ if (markStateDecorators.length === activeDecorators.length && markStateDecorators.every((mark) => activeDecorators.includes(mark)))
7226
+ return !1;
7227
+ }
7228
+ return {
7229
+ activeDecorators,
7230
+ activeAnnotations
7231
+ };
7232
+ },
7233
+ actions: [({
7234
+ snapshot,
7235
+ event
7236
+ }, {
7237
+ activeDecorators,
7238
+ activeAnnotations
7239
+ }) => [raise({
7240
+ type: "insert.child",
7241
+ child: {
7242
+ _type: snapshot.context.schema.span.name,
7243
+ text: event.text,
7244
+ marks: [...activeDecorators, ...activeAnnotations]
7245
+ }
7246
+ })]]
7247
+ })], breakingAtTheEndOfTextBlock = defineBehavior({
7251
7248
  on: "insert.break",
7252
7249
  guard: ({
7253
7250
  snapshot
@@ -7808,7 +7805,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
7808
7805
  inheritListLevel,
7809
7806
  inheritListItem,
7810
7807
  inheritListProperties
7811
- }, coreBehaviorsConfig = [...coreAnnotationBehaviors, 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) => ({
7808
+ }, coreBehaviorsConfig = [...coreAnnotationBehaviors, coreDecoratorBehaviors.strongShortcut, coreDecoratorBehaviors.emShortcut, coreDecoratorBehaviors.underlineShortcut, coreDecoratorBehaviors.codeShortcut, ...coreDndBehaviors, coreBlockObjectBehaviors.clickingAboveLonelyBlockObject, coreBlockObjectBehaviors.clickingBelowLonelyBlockObject, coreBlockObjectBehaviors.arrowDownOnLonelyBlockObject, coreBlockObjectBehaviors.arrowUpOnLonelyBlockObject, coreBlockObjectBehaviors.breakingBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockAfterBlockObject, coreBlockObjectBehaviors.deletingEmptyTextBlockBeforeBlockObject, ...coreInsertBehaviors, 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) => ({
7812
7809
  behavior,
7813
7810
  priority: corePriority
7814
7811
  }));