@portabletext/editor 7.10.19 → 7.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.
Files changed (40) hide show
  1. package/README.md +57 -64
  2. package/lib/{behavior.types.action-CYtiRDck.d.ts → behavior.types.action-DH6ujvaH.d.ts} +409 -109
  3. package/lib/behavior.types.action-DH6ujvaH.d.ts.map +1 -0
  4. package/lib/{behavior.types.behavior-B_77VtQR.js → behavior.types.behavior-BxSLb73I.js} +5 -5
  5. package/lib/behavior.types.behavior-BxSLb73I.js.map +1 -0
  6. package/lib/behaviors/index.d.ts +1 -1
  7. package/lib/behaviors/index.js +1 -1
  8. package/lib/{get-container-BeXYKpoi.js → get-container-D1nM_ww9.js} +14 -14
  9. package/lib/get-container-D1nM_ww9.js.map +1 -0
  10. package/lib/{get-parent-51Kzgaf9.js → get-parent-Ci5241qs.js} +3 -3
  11. package/lib/get-parent-Ci5241qs.js.map +1 -0
  12. package/lib/{get-path-sub-schema--2I4NJbG.js → get-path-sub-schema-CZd9VcVM.js} +10 -10
  13. package/lib/get-path-sub-schema-CZd9VcVM.js.map +1 -0
  14. package/lib/index.d.ts +2 -2
  15. package/lib/index.js +294 -101
  16. package/lib/index.js.map +1 -1
  17. package/lib/plugins/index.d.ts +6 -6
  18. package/lib/plugins/index.js +5 -5
  19. package/lib/plugins/index.js.map +1 -1
  20. package/lib/{selector.is-at-the-start-of-block-gJIMWRpU.js → selector.is-at-the-start-of-block-D0boZbDu.js} +4 -4
  21. package/lib/selector.is-at-the-start-of-block-D0boZbDu.js.map +1 -0
  22. package/lib/selectors/index.d.ts +6 -6
  23. package/lib/selectors/index.js +6 -6
  24. package/lib/selectors/index.js.map +1 -1
  25. package/lib/traversal/index.d.ts +31 -31
  26. package/lib/traversal/index.js +4 -4
  27. package/lib/traversal/index.js.map +1 -1
  28. package/lib/{util.is-equal-selections-BF4WJtz5.js → util.is-equal-selections-N1hxVUbE.js} +2 -2
  29. package/lib/{util.is-equal-selections-BF4WJtz5.js.map → util.is-equal-selections-N1hxVUbE.js.map} +1 -1
  30. package/lib/{util.slice-blocks-DQnr9X2s.js → util.slice-blocks-B2fZcNok.js} +2 -2
  31. package/lib/{util.slice-blocks-DQnr9X2s.js.map → util.slice-blocks-B2fZcNok.js.map} +1 -1
  32. package/lib/utils/index.d.ts +1 -1
  33. package/lib/utils/index.js +3 -3
  34. package/package.json +3 -3
  35. package/lib/behavior.types.action-CYtiRDck.d.ts.map +0 -1
  36. package/lib/behavior.types.behavior-B_77VtQR.js.map +0 -1
  37. package/lib/get-container-BeXYKpoi.js.map +0 -1
  38. package/lib/get-parent-51Kzgaf9.js.map +0 -1
  39. package/lib/get-path-sub-schema--2I4NJbG.js.map +0 -1
  40. package/lib/selector.is-at-the-start-of-block-gJIMWRpU.js.map +0 -1
package/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { a as getNodeChildren, i as getChildren, l as serializePath, n as parentPath, r as getNode, t as getParent, u as isKeyedSegment } from "./get-parent-51Kzgaf9.js";
2
- import { C as getAncestors, S as hasNode, _ as comparePoints, a as isInline, b as isEditableContainer, c as isSpanNode, d as resolveChildEntryIndex, f as isAncestorPath, g as isAfterPoint, h as isBackwardRange, i as getEnclosingBlock, l as getSibling, m as rangeEdges, n as getEnclosingContainer, o as getBlock, p as isTextBlockNode, s as isBlock, t as getPathSubSchema, u as getNodes, v as comparePaths, x as resolveContainerAt, y as isObject } from "./get-path-sub-schema--2I4NJbG.js";
3
- import { _ as getAncestor, a as getTextBlock, c as pathContains, d as isRange, f as isPoint, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, m as isPath, n as getUnionSchema, o as rangeIntersects, p as isObject$1, r as getLastChild, s as isBeforePoint, t as getContainer, u as getText } from "./get-container-BeXYKpoi.js";
4
- import { a as parseBlocks, b as childAtTextOffset, c as parseSpan, d as getSelectionEndPoint, f as isSelectionCollapsed, g as isEqualSelectionPoints, h as getBlockKeyFromSelectionPoint, i as parseBlock, l as defaultKeyGenerator, m as getBlockEndPoint, n as isListBlock, o as parseInlineObject, p as getBlockStartPoint, r as parseAnnotation, s as parseMarkDefs, u as getSelectionStartPoint, v as blockOffsetToSpanSelectionPoint, x as textOffsetOfChild } from "./util.slice-blocks-DQnr9X2s.js";
5
- import { A as isSelectingEntireBlocks, B as getFocusTextBlock, C as getActiveAnnotationsMarks, D as getSelectionStartPoint$1, E as getPreviousSpan, F as getSelectionStartBlock, H as getFocusSpan, I as getSelectionEndBlock, K as rangesOverlap, L as getFragment, M as isSelectionExpanded, N as isSelectionCollapsed$1, O as getNextSpan, P as isOverlappingSelection, R as getSelectedValue, S as getSelectedTextBlocks, U as getFocusInlineObject, V as getFocusBlock, W as getFocusChild, a as isActiveDecorator, b as isActiveAnnotation, c as getPreviousBlock, d as getFocusListBlock, f as getFocusBlockObject, i as isActiveListItem, j as getSelectedBlocks, k as getSelectionEndPoint$1, l as getNextBlock, n as isAtTheEndOfBlock, o as getSelectionStartChild, p as getCaretWordSelection, r as isActiveStyle, s as getSelectionEndChild, t as isAtTheStartOfBlock, u as getLastBlock, w as getMarkState, x as getActiveDecorators, y as getActiveAnnotations, z as getRootAcceptedTypes } from "./selector.is-at-the-start-of-block-gJIMWRpU.js";
6
- import { n as isEmptyTextBlock, r as getTextBlockText, t as isEqualSelections } from "./util.is-equal-selections-BF4WJtz5.js";
7
- import { a as raise$1, i as forward, n as effect, t as defineBehavior } from "./behavior.types.behavior-B_77VtQR.js";
1
+ import { a as getNodeChildren, i as getChildren, l as serializePath, n as parentPath, r as getNode, t as getParent, u as isKeyedSegment } from "./get-parent-Ci5241qs.js";
2
+ import { C as getAncestors, S as hasNode, _ as comparePoints, a as isInline, b as isEditableContainer, c as isSpanNode, d as resolveChildEntryIndex, f as isAncestorPath, g as isAfterPoint, h as isBackwardRange, i as getEnclosingBlock, l as getSibling, m as rangeEdges, n as getEnclosingContainer, o as getBlock, p as isTextBlockNode, s as isBlock, t as getPathSubSchema, u as getNodes, v as comparePaths, x as resolveContainerAt, y as isObject } from "./get-path-sub-schema-CZd9VcVM.js";
3
+ import { _ as getAncestor, a as getTextBlock, c as pathContains, d as isRange, f as isPoint, g as isLeafObject, h as getLeaf, i as getFirstChild, l as getSpan, m as isPath, n as getUnionSchema, o as rangeIntersects, p as isObject$1, r as getLastChild, s as isBeforePoint, t as getContainer, u as getText } from "./get-container-D1nM_ww9.js";
4
+ import { a as parseBlocks, b as childAtTextOffset, c as parseSpan, d as getSelectionEndPoint, f as isSelectionCollapsed, g as isEqualSelectionPoints, h as getBlockKeyFromSelectionPoint, i as parseBlock, l as defaultKeyGenerator, m as getBlockEndPoint, n as isListBlock, o as parseInlineObject, p as getBlockStartPoint, r as parseAnnotation, s as parseMarkDefs, u as getSelectionStartPoint, v as blockOffsetToSpanSelectionPoint, x as textOffsetOfChild } from "./util.slice-blocks-B2fZcNok.js";
5
+ import { A as isSelectingEntireBlocks, B as getFocusTextBlock, C as getActiveAnnotationsMarks, D as getSelectionStartPoint$1, E as getPreviousSpan, F as getSelectionStartBlock, H as getFocusSpan, I as getSelectionEndBlock, K as rangesOverlap, L as getFragment, M as isSelectionExpanded, N as isSelectionCollapsed$1, O as getNextSpan, P as isOverlappingSelection, R as getSelectedValue, S as getSelectedTextBlocks, U as getFocusInlineObject, V as getFocusBlock, W as getFocusChild, a as isActiveDecorator, b as isActiveAnnotation, c as getPreviousBlock, d as getFocusListBlock, f as getFocusBlockObject, i as isActiveListItem, j as getSelectedBlocks, k as getSelectionEndPoint$1, l as getNextBlock, n as isAtTheEndOfBlock, o as getSelectionStartChild, p as getCaretWordSelection, r as isActiveStyle, s as getSelectionEndChild, t as isAtTheStartOfBlock, u as getLastBlock, w as getMarkState, x as getActiveDecorators, y as getActiveAnnotations, z as getRootAcceptedTypes } from "./selector.is-at-the-start-of-block-D0boZbDu.js";
6
+ import { n as isEmptyTextBlock, r as getTextBlockText, t as isEqualSelections } from "./util.is-equal-selections-N1hxVUbE.js";
7
+ import { a as raise$1, i as forward, n as effect, t as defineBehavior } from "./behavior.types.behavior-BxSLb73I.js";
8
8
  import { n as EditorContext$1, t as useEditor } from "./use-editor-CwNeVwVC.js";
9
9
  import { c } from "react/compiler-runtime";
10
10
  import { useActorRef, useSelector } from "@xstate/react";
@@ -1993,7 +1993,7 @@ const DecorateContext = createContext({}), useDecorations = (node, path, parentD
1993
1993
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ new Set(), $[0] = t0) : t0 = $[0];
1994
1994
  let eventListeners = useRef(t0), latestDecorate = useRef(decorateProp), t1, t2;
1995
1995
  $[1] === decorateProp ? (t1 = $[2], t2 = $[3]) : (t1 = () => {
1996
- latestDecorate.current = decorateProp, eventListeners.current.forEach(_temp$4);
1996
+ latestDecorate.current = decorateProp, eventListeners.current.forEach(_temp$5);
1997
1997
  }, t2 = [decorateProp], $[1] = decorateProp, $[2] = t1, $[3] = t2), useIsomorphicLayoutEffect(t1, t2);
1998
1998
  let t3;
1999
1999
  $[4] === Symbol.for("react.memo_cache_sentinel") ? (t3 = (entry) => latestDecorate.current(entry), $[4] = t3) : t3 = $[4];
@@ -2007,7 +2007,7 @@ const DecorateContext = createContext({}), useDecorations = (node, path, parentD
2007
2007
  addEventListener
2008
2008
  }, $[6] = t5) : t5 = $[6], t5;
2009
2009
  };
2010
- function _temp$4(listener) {
2010
+ function _temp$5(listener) {
2011
2011
  listener();
2012
2012
  }
2013
2013
  const rtlRange = "֑-߿יִ-﷽ﹰ-ﻼ", ltrRange = "A-Za-zÀ-ÖØ-öø-ʸ̀-֐ࠀ-῿‎Ⰰ-﬜︀-﹯﻽-￿", rtl = RegExp(`^[^${ltrRange}]*[${rtlRange}]`), ltr = RegExp(`^[^${rtlRange}]*[${ltrRange}]`);
@@ -2554,7 +2554,7 @@ const useChildren = (props) => {
2554
2554
  * selector re-runs on its component's renders and when a renderer
2555
2555
  * registration map is swapped, not on document or selection changes.
2556
2556
  * Only for selectors that read the registration maps
2557
- * (`engine.containers/spans/textBlocks/blockObjects/inlineObjects`)
2557
+ * (`engine.containers/spans/textBlocks/blockObjects/inlineObjects/decorators/annotations`)
2558
2558
  * exclusively; those maps are mutated only in
2559
2559
  * `register-node-on-engine.ts`, which arms this channel.
2560
2560
  */
@@ -4057,7 +4057,7 @@ const DropPositionStoreContext = createContext({
4057
4057
  * gaining or losing the indicator. Mirrors `SelectionStateProvider`.
4058
4058
  */
4059
4059
  function DropPositionStateProvider(t0) {
4060
- let $ = c(6), { children } = t0, editorActor = useContext(EditorActorContext), [initialSubscribers] = useState(_temp$3), subscribersRef = useRef(initialSubscribers), stateRef = useRef(void 0), t1, t2;
4060
+ let $ = c(6), { children } = t0, editorActor = useContext(EditorActorContext), [initialSubscribers] = useState(_temp$4), subscribersRef = useRef(initialSubscribers), stateRef = useRef(void 0), t1, t2;
4061
4061
  $[0] === editorActor ? (t1 = $[1], t2 = $[2]) : (t1 = () => {
4062
4062
  let behaviorConfigs = createDropPositionBehaviorsConfig({ setDropPosition: (next) => {
4063
4063
  let prev = stateRef.current;
@@ -4095,7 +4095,7 @@ function DropPositionStateProvider(t0) {
4095
4095
  * when no drag is hovering this block. Re-renders only when this block's slice
4096
4096
  * flips, not when the position moves between other blocks.
4097
4097
  */
4098
- function _temp$3() {
4098
+ function _temp$4() {
4099
4099
  return /* @__PURE__ */ new Set();
4100
4100
  }
4101
4101
  function useElementDropPosition(path) {
@@ -4526,14 +4526,40 @@ function findBlockPositionalOverride(parentConfig, type) {
4526
4526
  * for a matching `_type`.
4527
4527
  */
4528
4528
  function findInlinePositionalOverride(parentTextBlock, type) {
4529
- return parentTextBlock?.of ? parentTextBlock.of.find((entry) => "span" in entry ? entry.span.type === type : entry.inlineObject.type === type) || parentTextBlock.of.find((entry) => "span" in entry ? entry.span.type === "*" : entry.inlineObject.type === "*") : void 0;
4529
+ return parentTextBlock?.of ? parentTextBlock.of.find((entry) => isMatchingSpanOrInlineObject(entry, type)) || parentTextBlock.of.find((entry) => isMatchingSpanOrInlineObject(entry, "*")) : void 0;
4530
+ }
4531
+ function isMatchingSpanOrInlineObject(entry, type) {
4532
+ return "span" in entry ? entry.span.type === type : "inlineObject" in entry && entry.inlineObject.type === type;
4533
+ }
4534
+ /**
4535
+ * Decorator positional override lookup. Walks the immediate parent
4536
+ * text block's `of` array (decorator kind) for a matching decorator
4537
+ * name: exact first, then a `'*'` entry.
4538
+ */
4539
+ function findPositionalDecoratorOverride(parentTextBlock, decorator) {
4540
+ return parentTextBlock?.of ? parentTextBlock.of.find((entry) => isMatchingDecorator(entry, decorator)) || parentTextBlock.of.find((entry) => isMatchingDecorator(entry, "*")) : void 0;
4541
+ }
4542
+ function isMatchingDecorator(entry, decorator) {
4543
+ return "decorator" in entry && entry.decorator.type === decorator;
4544
+ }
4545
+ /**
4546
+ * Annotation positional override lookup. Walks the immediate parent
4547
+ * text block's `of` array (annotation kind) for a matching annotation
4548
+ * `_type`: exact first, then a `'*'` entry.
4549
+ */
4550
+ function findPositionalAnnotationOverride(parentTextBlock, type) {
4551
+ return parentTextBlock?.of ? parentTextBlock.of.find((entry) => isMatchingAnnotation(entry, type)) || parentTextBlock.of.find((entry) => isMatchingAnnotation(entry, "*")) : void 0;
4552
+ }
4553
+ function isMatchingAnnotation(entry, type) {
4554
+ return "annotation" in entry && entry.annotation.type === type;
4530
4555
  }
4531
4556
  /**
4532
4557
  * The active text block's resolved config at this render position.
4533
4558
  * Provided by the text-block render branch in `render.element.tsx`;
4534
4559
  * consumed by inline-level dispatch (`useSpanConfig` + the
4535
- * inline-object branch of `render.element.tsx`) for positional
4536
- * override lookup.
4560
+ * inline-object branch of `render.element.tsx`) for positional span/
4561
+ * inline-object override lookup, and directly by `RenderSpan` for
4562
+ * positional decorator/annotation override lookup.
4537
4563
  *
4538
4564
  * Separate from `ParentContainerContext` so inline subscribers only
4539
4565
  * re-render on text-block `of` changes, and block subscribers only
@@ -4574,6 +4600,24 @@ function renderDefaultSpan(props) {
4574
4600
  });
4575
4601
  }
4576
4602
  /**
4603
+ * Engine-default wrapper for Decorator marks: identity. The engine
4604
+ * applies no decorator markup of its own; a decorator's whole visual
4605
+ * effect comes from its `render`.
4606
+ */
4607
+ function renderDefaultDecorator(props) {
4608
+ return props.children;
4609
+ }
4610
+ /**
4611
+ * Engine-default wrapper for Annotation marks: identity. The engine
4612
+ * always anchors the annotated text in a `<span ref>` outside this
4613
+ * render, kept for structural parity with the legacy `renderAnnotation`
4614
+ * path (which hands that anchor to consumers as `editorElementRef`);
4615
+ * the render itself owns no markup by default.
4616
+ */
4617
+ function renderDefaultAnnotation(props) {
4618
+ return props.children;
4619
+ }
4620
+ /**
4577
4621
  * Engine-default wrapper for void block objects. Renders the zero-width
4578
4622
  * editor children plus a non-editable `[_type: _key]` placeholder so the
4579
4623
  * object is visible before a consumer provides a custom `render`.
@@ -4816,7 +4860,7 @@ function SelectionStateProvider(t0) {
4816
4860
  blockIndexMap: editorEngine.blockIndexMap
4817
4861
  }, selection);
4818
4862
  }, $[0] = editorEngine.blockIndexMap, $[1] = editorEngine.snapshot, $[2] = t1) : t1 = $[2];
4819
- let computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$2), subscribersRef = useRef(initialSubscribers), t2, t3;
4863
+ let computeCurrent = t1, [seed] = useState(computeCurrent), stateRef = useRef(seed), [initialSubscribers] = useState(_temp$3), subscribersRef = useRef(initialSubscribers), t2, t3;
4820
4864
  $[3] !== computeCurrent || $[4] !== editorActor ? (t2 = () => {
4821
4865
  let next = computeCurrent();
4822
4866
  if (!selectionStatesEqual(stateRef.current, next)) {
@@ -4850,7 +4894,7 @@ function SelectionStateProvider(t0) {
4850
4894
  * focused. Re-renders only when this boolean flips - not when other
4851
4895
  * containers' focused state changes.
4852
4896
  */
4853
- function _temp$2() {
4897
+ function _temp$3() {
4854
4898
  return /* @__PURE__ */ new Set();
4855
4899
  }
4856
4900
  function useIsFocusedContainer(serializedPath) {
@@ -5626,8 +5670,43 @@ function useSpanConfig(node, _path) {
5626
5670
  let [globalSpan, globalSpanCatchAll] = useRegistrationsSelector(t1, tupleRefEqual);
5627
5671
  return positional && "span" in positional ? positional.span.render === void 0 ? globalSpan ?? globalSpanCatchAll : positional : globalSpan ?? globalSpanCatchAll;
5628
5672
  }
5673
+ /**
5674
+ * Hook: the engine's registered GLOBAL decorator map. Positional
5675
+ * (in-parent) decorator overrides are a separate layer: the caller
5676
+ * resolves them from `ParentTextBlockContext` via
5677
+ * `findPositionalDecoratorOverride` and combines that result with
5678
+ * this map's.
5679
+ *
5680
+ * The per-mark exact-then-`'*'` lookup against this map happens as a
5681
+ * plain `Map` read rather than as one hook call per mark: a span
5682
+ * carries a variable number of decorator marks, and hooks cannot be
5683
+ * called a variable number of times.
5684
+ */
5685
+ function useDecoratorConfigs() {
5686
+ return useRegistrationsSelector(_temp$2);
5687
+ }
5688
+ /**
5689
+ * Hook: the engine's registered GLOBAL annotation map. Positional
5690
+ * (in-parent) annotation overrides are a separate layer: the caller
5691
+ * resolves them from `ParentTextBlockContext` via
5692
+ * `findPositionalAnnotationOverride` and combines that result with
5693
+ * this map's.
5694
+ *
5695
+ * Same plain-`Map`-read reasoning as {@link useDecoratorConfigs}: a
5696
+ * span's marks resolve to a variable number of annotation `markDef`s
5697
+ * per render.
5698
+ */
5699
+ function _temp$2(engine) {
5700
+ return engine.decorators;
5701
+ }
5702
+ function useAnnotationConfigs() {
5703
+ return useRegistrationsSelector(_temp2$1);
5704
+ }
5705
+ function _temp2$1(engine) {
5706
+ return engine.annotations;
5707
+ }
5629
5708
  function RenderSpan(props) {
5630
- let $ = c(41), schema = props.schema, spanRef = useRef(null), t0;
5709
+ let $ = c(33), schema = props.schema, spanRef = useRef(null), t0;
5631
5710
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
5632
5711
  let t1;
5633
5712
  $[1] === schema.span.name ? t1 = $[2] : (t1 = {
@@ -5636,88 +5715,119 @@ function RenderSpan(props) {
5636
5715
  }, $[1] = schema.span.name, $[2] = t1);
5637
5716
  let schemaType = t1, parent = props.children.props.parent, block = parent && isTextBlock({ schema }, parent) ? parent : void 0, t2;
5638
5717
  $[3] !== block?.children || $[4] !== props.leaf._key ? (t2 = block?.children.find((_child) => _child._key === props.leaf._key), $[3] = block?.children, $[4] = props.leaf._key, $[5] = t2) : t2 = $[5];
5639
- let child = t2, subSchema = useBlockSubSchema(props.path), spanConfig = useSpanConfig(child ?? props.leaf, props.path), isInNewPipeline = useContext(NewPipelineContext), t3;
5718
+ let child = t2, subSchema = useBlockSubSchema(props.path), spanConfig = useSpanConfig(child ?? props.leaf, props.path), decoratorConfigs = useDecoratorConfigs(), annotationConfigs = useAnnotationConfigs(), parentTextBlock = useContext(ParentTextBlockContext), isInNewPipeline = useContext(NewPipelineContext), t3;
5640
5719
  $[6] === props.path ? t3 = $[7] : (t3 = serializePath(props.path), $[6] = props.path, $[7] = t3);
5641
- let serializedPath = t3, focused = useIsFocusedLeaf(serializedPath), selected = useIsSelectedLeaf(serializedPath), annotationMarkDefs, children;
5642
- if ($[8] !== block || $[9] !== focused || $[10] !== props.children || $[11] !== props.leaf.marks || $[12] !== props.path || $[13] !== props.renderAnnotation || $[14] !== props.renderDecorator || $[15] !== selected || $[16] !== subSchema.annotations || $[17] !== subSchema.decorators) {
5643
- let decoratorSchemaTypes = subSchema.decorators.map(_temp$1), decorators = [...new Set((props.leaf.marks ?? []).filter((mark) => decoratorSchemaTypes.includes(mark)))];
5644
- annotationMarkDefs = (props.leaf.marks ?? []).flatMap((mark_0) => {
5645
- if (decoratorSchemaTypes.includes(mark_0)) return [];
5646
- let markDef_0 = block?.markDefs?.find((markDef) => markDef._key === mark_0);
5647
- return markDef_0 ? [markDef_0] : [];
5648
- }), children = props.children;
5649
- for (let mark_1 of decorators) {
5650
- let decoratorSchemaType = subSchema.decorators.find((dec) => dec.name === mark_1);
5651
- decoratorSchemaType && props.renderDecorator && (children = /* @__PURE__ */ jsx(RenderDecorator, {
5652
- renderDecorator: props.renderDecorator,
5720
+ let serializedPath = t3, focused = useIsFocusedLeaf(serializedPath), selected = useIsSelectedLeaf(serializedPath), t4 = subSchema.decorators, children, t5;
5721
+ if ($[8] !== annotationConfigs || $[9] !== block || $[10] !== child || $[11] !== decoratorConfigs || $[12] !== focused || $[13] !== isInNewPipeline || $[14] !== parentTextBlock || $[15] !== props.attributes || $[16] !== props.children || $[17] !== props.leaf || $[18] !== props.path || $[19] !== props.readOnly || $[20] !== props.renderAnnotation || $[21] !== props.renderChild || $[22] !== props.renderDecorator || $[23] !== schemaType || $[24] !== selected || $[25] !== spanConfig || $[26] !== subSchema.annotations || $[27] !== subSchema.decorators) {
5722
+ t5 = Symbol.for("react.early_return_sentinel");
5723
+ bb0: {
5724
+ let decoratorSchemaTypes = t4.map(_temp$1), decorators = [...new Set((props.leaf.marks ?? []).filter((mark) => decoratorSchemaTypes.includes(mark)))], annotationMarkDefs = (props.leaf.marks ?? []).flatMap((mark_0) => {
5725
+ if (decoratorSchemaTypes.includes(mark_0)) return [];
5726
+ let markDef_0 = block?.markDefs?.find((markDef) => markDef._key === mark_0);
5727
+ return markDef_0 ? [markDef_0] : [];
5728
+ });
5729
+ children = props.children;
5730
+ for (let mark_1 of decorators) {
5731
+ let decoratorSchemaType = subSchema.decorators.find((dec) => dec.name === mark_1);
5732
+ if (!decoratorSchemaType) continue;
5733
+ let globalDecoratorConfig = decoratorConfigs.get(mark_1) ?? decoratorConfigs.get("*"), positionalDecorator = findPositionalDecoratorOverride(parentTextBlock, mark_1), decoratorConfig = positionalDecorator ? positionalDecorator.decorator.render === void 0 ? globalDecoratorConfig : positionalDecorator : globalDecoratorConfig;
5734
+ if (decoratorConfig) {
5735
+ let render = decoratorConfig.decorator.render, renderProps = {
5736
+ children,
5737
+ decorator: mark_1,
5738
+ focused,
5739
+ path: props.path,
5740
+ readOnly: props.readOnly,
5741
+ renderDefault: renderDefaultDecorator,
5742
+ selected
5743
+ };
5744
+ children = render ? render(renderProps) : renderDefaultDecorator(renderProps);
5745
+ continue;
5746
+ }
5747
+ props.renderDecorator && (children = /* @__PURE__ */ jsx(RenderDecorator, {
5748
+ renderDecorator: props.renderDecorator,
5749
+ editorElementRef: spanRef,
5750
+ focused,
5751
+ path: props.path,
5752
+ selected,
5753
+ schemaType: decoratorSchemaType,
5754
+ value: mark_1,
5755
+ children
5756
+ }));
5757
+ }
5758
+ for (let annotationMarkDef of annotationMarkDefs) {
5759
+ let annotationSchemaType = subSchema.annotations.find((t) => t.name === annotationMarkDef._type);
5760
+ if (annotationSchemaType) {
5761
+ let globalAnnotationConfig = annotationConfigs.get(annotationMarkDef._type) ?? annotationConfigs.get("*"), positionalAnnotation = findPositionalAnnotationOverride(parentTextBlock, annotationMarkDef._type), annotationConfig = positionalAnnotation ? positionalAnnotation.annotation.render === void 0 ? globalAnnotationConfig : positionalAnnotation : globalAnnotationConfig;
5762
+ if (annotationConfig) {
5763
+ let render_0 = annotationConfig.annotation.render, renderProps_0 = {
5764
+ children,
5765
+ focused,
5766
+ annotation: annotationMarkDef,
5767
+ path: props.path,
5768
+ readOnly: props.readOnly,
5769
+ renderDefault: renderDefaultAnnotation,
5770
+ selected
5771
+ };
5772
+ children = /* @__PURE__ */ jsx("span", {
5773
+ ref: spanRef,
5774
+ children: render_0 ? render_0(renderProps_0) : renderDefaultAnnotation(renderProps_0)
5775
+ });
5776
+ continue;
5777
+ }
5778
+ children = block && props.renderAnnotation ? /* @__PURE__ */ jsx("span", {
5779
+ ref: spanRef,
5780
+ children: /* @__PURE__ */ jsx(RenderAnnotation, {
5781
+ renderAnnotation: props.renderAnnotation,
5782
+ block,
5783
+ editorElementRef: spanRef,
5784
+ focused,
5785
+ path: props.path,
5786
+ selected,
5787
+ schemaType: annotationSchemaType,
5788
+ value: annotationMarkDef,
5789
+ children
5790
+ })
5791
+ }) : /* @__PURE__ */ jsx("span", {
5792
+ ref: spanRef,
5793
+ children
5794
+ });
5795
+ }
5796
+ }
5797
+ if (block && props.renderChild && child && !spanConfig && !isInNewPipeline && (children = /* @__PURE__ */ jsx(RenderChild, {
5798
+ renderChild: props.renderChild,
5799
+ annotations: annotationMarkDefs,
5653
5800
  editorElementRef: spanRef,
5654
5801
  focused,
5655
5802
  path: props.path,
5803
+ schemaType,
5656
5804
  selected,
5657
- schemaType: decoratorSchemaType,
5658
- value: mark_1,
5805
+ value: child,
5659
5806
  children
5660
- }));
5661
- }
5662
- for (let annotationMarkDef of annotationMarkDefs) {
5663
- let annotationSchemaType = subSchema.annotations.find((t) => t.name === annotationMarkDef._type);
5664
- annotationSchemaType && (children = block && props.renderAnnotation ? /* @__PURE__ */ jsx("span", {
5665
- ref: spanRef,
5666
- children: /* @__PURE__ */ jsx(RenderAnnotation, {
5667
- renderAnnotation: props.renderAnnotation,
5668
- block,
5669
- editorElementRef: spanRef,
5807
+ })), spanConfig) {
5808
+ let render_1 = spanConfig.span.render, renderProps_1 = {
5809
+ attributes: props.attributes,
5810
+ children,
5670
5811
  focused,
5812
+ node: child ?? props.leaf,
5671
5813
  path: props.path,
5672
- selected,
5673
- schemaType: annotationSchemaType,
5674
- value: annotationMarkDef,
5675
- children
5676
- })
5677
- }) : /* @__PURE__ */ jsx("span", {
5678
- ref: spanRef,
5679
- children
5680
- }));
5814
+ readOnly: props.readOnly,
5815
+ renderDefault: renderDefaultSpan,
5816
+ selected
5817
+ };
5818
+ t5 = render_1 ? render_1(renderProps_1) : renderDefaultSpan(renderProps_1);
5819
+ break bb0;
5820
+ }
5681
5821
  }
5682
- $[8] = block, $[9] = focused, $[10] = props.children, $[11] = props.leaf.marks, $[12] = props.path, $[13] = props.renderAnnotation, $[14] = props.renderDecorator, $[15] = selected, $[16] = subSchema.annotations, $[17] = subSchema.decorators, $[18] = annotationMarkDefs, $[19] = children;
5683
- } else annotationMarkDefs = $[18], children = $[19];
5684
- if (block && props.renderChild && child && !spanConfig && !isInNewPipeline) {
5685
- let t4;
5686
- $[20] !== annotationMarkDefs || $[21] !== child || $[22] !== children || $[23] !== focused || $[24] !== props.path || $[25] !== props.renderChild || $[26] !== schemaType || $[27] !== selected ? (t4 = /* @__PURE__ */ jsx(RenderChild, {
5687
- renderChild: props.renderChild,
5688
- annotations: annotationMarkDefs,
5689
- editorElementRef: spanRef,
5690
- focused,
5691
- path: props.path,
5692
- schemaType,
5693
- selected,
5694
- value: child,
5695
- children
5696
- }), $[20] = annotationMarkDefs, $[21] = child, $[22] = children, $[23] = focused, $[24] = props.path, $[25] = props.renderChild, $[26] = schemaType, $[27] = selected, $[28] = t4) : t4 = $[28], children = t4;
5697
- }
5698
- if (spanConfig) {
5699
- let render = spanConfig.span.render, t4 = child ?? props.leaf, t5;
5700
- if ($[29] !== children || $[30] !== focused || $[31] !== props.attributes || $[32] !== props.path || $[33] !== props.readOnly || $[34] !== render || $[35] !== selected || $[36] !== t4) {
5701
- let renderProps = {
5702
- attributes: props.attributes,
5703
- children,
5704
- focused,
5705
- node: t4,
5706
- path: props.path,
5707
- readOnly: props.readOnly,
5708
- renderDefault: renderDefaultSpan,
5709
- selected
5710
- };
5711
- t5 = render ? render(renderProps) : renderDefaultSpan(renderProps), $[29] = children, $[30] = focused, $[31] = props.attributes, $[32] = props.path, $[33] = props.readOnly, $[34] = render, $[35] = selected, $[36] = t4, $[37] = t5;
5712
- } else t5 = $[37];
5713
- return t5;
5714
- }
5715
- let t4;
5716
- return $[38] !== children || $[39] !== props.attributes ? (t4 = /* @__PURE__ */ jsx("span", {
5822
+ $[8] = annotationConfigs, $[9] = block, $[10] = child, $[11] = decoratorConfigs, $[12] = focused, $[13] = isInNewPipeline, $[14] = parentTextBlock, $[15] = props.attributes, $[16] = props.children, $[17] = props.leaf, $[18] = props.path, $[19] = props.readOnly, $[20] = props.renderAnnotation, $[21] = props.renderChild, $[22] = props.renderDecorator, $[23] = schemaType, $[24] = selected, $[25] = spanConfig, $[26] = subSchema.annotations, $[27] = subSchema.decorators, $[28] = children, $[29] = t5;
5823
+ } else children = $[28], t5 = $[29];
5824
+ if (t5 !== Symbol.for("react.early_return_sentinel")) return t5;
5825
+ let t6;
5826
+ return $[30] !== children || $[31] !== props.attributes ? (t6 = /* @__PURE__ */ jsx("span", {
5717
5827
  ...props.attributes,
5718
5828
  ref: spanRef,
5719
5829
  children
5720
- }), $[38] = children, $[39] = props.attributes, $[40] = t4) : t4 = $[40], t4;
5830
+ }), $[30] = children, $[31] = props.attributes, $[32] = t6) : t6 = $[32], t6;
5721
5831
  }
5722
5832
  function _temp$1(decorator) {
5723
5833
  return decorator.name;
@@ -10329,7 +10439,7 @@ function createEditorEngine(config) {
10329
10439
  value: [placeholderBlock]
10330
10440
  },
10331
10441
  decoratorState: {}
10332
- }, editor.containers = /* @__PURE__ */ new Map(), editor.blockObjects = /* @__PURE__ */ new Map(), editor.inlineObjects = /* @__PURE__ */ new Map(), editor.spans = /* @__PURE__ */ new Map(), editor.textBlocks = /* @__PURE__ */ new Map(), editor.decoratedRanges = [], editor.blockIndexMap = blockIndexMap, editor.history = {
10442
+ }, editor.containers = /* @__PURE__ */ new Map(), editor.annotations = /* @__PURE__ */ new Map(), editor.blockObjects = /* @__PURE__ */ new Map(), editor.decorators = /* @__PURE__ */ new Map(), editor.inlineObjects = /* @__PURE__ */ new Map(), editor.spans = /* @__PURE__ */ new Map(), editor.textBlocks = /* @__PURE__ */ new Map(), editor.decoratedRanges = [], editor.blockIndexMap = blockIndexMap, editor.history = {
10333
10443
  undos: [],
10334
10444
  redos: []
10335
10445
  }, editor.listIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMapDirty = !1, editor.selectorChannelsPending = {
@@ -11185,6 +11295,7 @@ const coreDndBehaviors = [
11185
11295
  };
11186
11296
  },
11187
11297
  actions: [(_, { draggingEntireBlocks, draggedNodes, dragOrigin, dropPosition, originEvent, fittedBlocks, movedInlineObjectKey }) => {
11298
+ if (fittedBlocks.length === 0) return [];
11188
11299
  let movedInlineObjectPath = movedInlineObjectKey ? [
11189
11300
  ...dropPosition.anchor.path.slice(0, -2),
11190
11301
  "children",
@@ -15414,7 +15525,7 @@ function describeContainerFailure(failure, container) {
15414
15525
  * (if present) for inline-content positional overrides.
15415
15526
  */
15416
15527
  function resolveTextBlockConfig(textBlock) {
15417
- let resolvedOf = textBlock.of ? textBlock.of.flatMap((entry) => entry.kind === "span" ? [{ span: entry }] : [{ inlineObject: entry }]) : void 0;
15528
+ let resolvedOf = textBlock.of ? textBlock.of.flatMap((entry) => entry.kind === "span" ? [{ span: entry }] : entry.kind === "inlineObject" ? [{ inlineObject: entry }] : entry.kind === "decorator" ? [{ decorator: entry }] : [{ annotation: entry }]) : void 0;
15418
15529
  return {
15419
15530
  textBlock,
15420
15531
  ...resolvedOf ? { of: resolvedOf } : {}
@@ -15506,9 +15617,27 @@ function registerNodeOnEngine(engine, node) {
15506
15617
  blockObjects.set(node.type, { blockObject: node }), engine.blockObjects = blockObjects, notifyRegistrationsChanged(engine);
15507
15618
  return;
15508
15619
  }
15509
- if (isTypeAlreadyRegistered(engine, "inlineObject", node.type)) return;
15510
- let inlineObjects = new Map(engine.inlineObjects);
15511
- inlineObjects.set(node.type, { inlineObject: node }), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
15620
+ if (node.kind === "inlineObject") {
15621
+ if (isTypeAlreadyRegistered(engine, "inlineObject", node.type)) return;
15622
+ let inlineObjects = new Map(engine.inlineObjects);
15623
+ inlineObjects.set(node.type, { inlineObject: node }), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
15624
+ return;
15625
+ }
15626
+ if (node.kind === "decorator") {
15627
+ if (engine.decorators.has(node.type)) {
15628
+ console.warn(`registerNode: type "${node.type}" is already registered as a decorator. Registration skipped.`);
15629
+ return;
15630
+ }
15631
+ let decorators = new Map(engine.decorators);
15632
+ decorators.set(node.type, { decorator: node }), engine.decorators = decorators, notifyRegistrationsChanged(engine);
15633
+ return;
15634
+ }
15635
+ if (engine.annotations.has(node.type)) {
15636
+ console.warn(`registerNode: type "${node.type}" is already registered as an annotation. Registration skipped.`);
15637
+ return;
15638
+ }
15639
+ let annotations = new Map(engine.annotations);
15640
+ annotations.set(node.type, { annotation: node }), engine.annotations = annotations, notifyRegistrationsChanged(engine);
15512
15641
  }
15513
15642
  /**
15514
15643
  * Mutate the engine's registration maps to remove a registered node.
@@ -15536,8 +15665,18 @@ function unregisterNodeOnEngine(engine, node) {
15536
15665
  blockObjects.delete(node.type), engine.blockObjects = blockObjects, notifyRegistrationsChanged(engine);
15537
15666
  return;
15538
15667
  }
15539
- let inlineObjects = new Map(engine.inlineObjects);
15540
- inlineObjects.delete(node.type), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
15668
+ if (node.kind === "inlineObject") {
15669
+ let inlineObjects = new Map(engine.inlineObjects);
15670
+ inlineObjects.delete(node.type), engine.inlineObjects = inlineObjects, notifyRegistrationsChanged(engine);
15671
+ return;
15672
+ }
15673
+ if (node.kind === "decorator") {
15674
+ let decorators = new Map(engine.decorators);
15675
+ decorators.delete(node.type), engine.decorators = decorators, notifyRegistrationsChanged(engine);
15676
+ return;
15677
+ }
15678
+ let annotations = new Map(engine.annotations);
15679
+ annotations.delete(node.type), engine.annotations = annotations, notifyRegistrationsChanged(engine);
15541
15680
  }
15542
15681
  /**
15543
15682
  * The registration maps are mutated only in this module, so the React
@@ -17279,7 +17418,7 @@ const usePortableTextEditorSelection = () => {
17279
17418
  }, t1 = [editorActor], $[0] = editorActor, $[1] = t0, $[2] = t1), useEffect(t0, t1), selection;
17280
17419
  };
17281
17420
  /**
17282
- * @alpha
17421
+ * @public
17283
17422
  *
17284
17423
  * Define a container renderer. The returned registration is mounted via
17285
17424
  * the `<NodePlugin>` component at the top level, or nested inside
@@ -17317,7 +17456,7 @@ function defineContainer(config) {
17317
17456
  };
17318
17457
  }
17319
17458
  /**
17320
- * @alpha
17459
+ * @public
17321
17460
  *
17322
17461
  * Define a span renderer. The returned registration is mounted via the
17323
17462
  * `<NodePlugin>` component at the top level, or nested inside a
@@ -17345,7 +17484,61 @@ function defineSpan(config) {
17345
17484
  };
17346
17485
  }
17347
17486
  /**
17348
- * @alpha
17487
+ * @public
17488
+ *
17489
+ * Define a decorator renderer for a decorator name declared in the
17490
+ * schema's `decorators` array, or `'*'` to match every decorator.
17491
+ * The returned registration is mounted via the `<NodePlugin>`
17492
+ * component.
17493
+ *
17494
+ * Decorator names live in a different namespace than node
17495
+ * `_type`s, so `type` has no forbidden values here (unlike
17496
+ * `defineSpan`/`defineTextBlock`).
17497
+ *
17498
+ * @example
17499
+ * ```ts
17500
+ * defineDecorator({
17501
+ * type: 'strong',
17502
+ * render: ({children}) => <strong>{children}</strong>,
17503
+ * })
17504
+ * ```
17505
+ */
17506
+ function defineDecorator(config) {
17507
+ return {
17508
+ kind: "decorator",
17509
+ ...config
17510
+ };
17511
+ }
17512
+ /**
17513
+ * @public
17514
+ *
17515
+ * Define an annotation renderer for a `_type` declared in the
17516
+ * schema's `annotations` array, or `'*'` to match every annotation
17517
+ * type. The returned registration is mounted via the `<NodePlugin>`
17518
+ * component.
17519
+ *
17520
+ * Annotation `_type`s live in a different namespace than node
17521
+ * `_type`s, so `type` has no forbidden values here (unlike
17522
+ * `defineInlineObject`/`defineBlockObject`).
17523
+ *
17524
+ * @example
17525
+ * ```ts
17526
+ * defineAnnotation({
17527
+ * type: 'link',
17528
+ * render: ({annotation, children}) => (
17529
+ * <a href={(annotation as {href?: string}).href}>{children}</a>
17530
+ * ),
17531
+ * })
17532
+ * ```
17533
+ */
17534
+ function defineAnnotation(config) {
17535
+ return {
17536
+ kind: "annotation",
17537
+ ...config
17538
+ };
17539
+ }
17540
+ /**
17541
+ * @public
17349
17542
  *
17350
17543
  * Define a non-editable block-level object renderer for a `_type`
17351
17544
  * declared in the schema's `blockObjects` array.
@@ -17375,7 +17568,7 @@ function defineBlockObject(config) {
17375
17568
  };
17376
17569
  }
17377
17570
  /**
17378
- * @alpha
17571
+ * @public
17379
17572
  *
17380
17573
  * Define a non-editable inline object renderer for a `_type` declared
17381
17574
  * in the schema's `inlineObjects` array.
@@ -17405,7 +17598,7 @@ function defineInlineObject(config) {
17405
17598
  };
17406
17599
  }
17407
17600
  /**
17408
- * @alpha
17601
+ * @public
17409
17602
  *
17410
17603
  * Define a text block renderer. The returned registration is mounted
17411
17604
  * via the `<NodePlugin>` component, or nested inside a container's
@@ -17432,6 +17625,6 @@ function defineTextBlock(config) {
17432
17625
  ...config
17433
17626
  };
17434
17627
  }
17435
- export { EditorProvider, PortableTextEditable, PortableTextEditor, defineBlockObject, defineContainer, defineInlineObject, defineSchema, defineSpan, defineTextBlock, defaultKeyGenerator as keyGenerator, resolveContainerAt, useEditor, useEditorSelector, usePortableTextEditor, usePortableTextEditorSelection };
17628
+ export { EditorProvider, PortableTextEditable, PortableTextEditor, defineAnnotation, defineBlockObject, defineContainer, defineDecorator, defineInlineObject, defineSchema, defineSpan, defineTextBlock, defaultKeyGenerator as keyGenerator, resolveContainerAt, useEditor, useEditorSelector, usePortableTextEditor, usePortableTextEditorSelection };
17436
17629
 
17437
17630
  //# sourceMappingURL=index.js.map