@portabletext/editor 1.48.14 → 1.49.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 (48) hide show
  1. package/lib/_chunks-cjs/editor-provider.cjs +117 -34
  2. package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
  3. package/lib/_chunks-cjs/util.slice-blocks.cjs +2 -0
  4. package/lib/_chunks-cjs/util.slice-blocks.cjs.map +1 -1
  5. package/lib/_chunks-es/editor-provider.js +117 -34
  6. package/lib/_chunks-es/editor-provider.js.map +1 -1
  7. package/lib/_chunks-es/util.slice-blocks.js +2 -0
  8. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  9. package/lib/behaviors/index.d.cts +222 -208
  10. package/lib/behaviors/index.d.ts +222 -208
  11. package/lib/index.cjs +346 -257
  12. package/lib/index.cjs.map +1 -1
  13. package/lib/index.d.cts +222 -216
  14. package/lib/index.d.ts +222 -216
  15. package/lib/index.js +353 -264
  16. package/lib/index.js.map +1 -1
  17. package/lib/plugins/index.d.cts +222 -216
  18. package/lib/plugins/index.d.ts +222 -216
  19. package/lib/selectors/index.d.cts +222 -208
  20. package/lib/selectors/index.d.ts +222 -208
  21. package/lib/utils/index.d.cts +222 -208
  22. package/lib/utils/index.d.ts +222 -208
  23. package/package.json +1 -1
  24. package/src/behaviors/behavior.config.ts +7 -0
  25. package/src/behaviors/behavior.core.block-element.ts +108 -0
  26. package/src/behaviors/behavior.core.ts +6 -2
  27. package/src/converters/converter.portable-text.ts +4 -1
  28. package/src/converters/converter.text-html.ts +4 -1
  29. package/src/converters/converter.text-plain.ts +4 -1
  30. package/src/editor/Editable.tsx +2 -4
  31. package/src/editor/__tests__/PortableTextEditor.test.tsx +6 -0
  32. package/src/editor/components/Leaf.tsx +8 -1
  33. package/src/editor/components/render-block-object.tsx +90 -0
  34. package/src/editor/components/render-default-object.tsx +21 -0
  35. package/src/editor/components/render-element.tsx +140 -0
  36. package/src/editor/components/render-inline-object.tsx +93 -0
  37. package/src/editor/components/render-text-block.tsx +148 -0
  38. package/src/editor/components/use-core-block-element-behaviors.ts +39 -0
  39. package/src/editor/create-editor.ts +17 -5
  40. package/src/editor/editor-machine.ts +21 -18
  41. package/src/internal-utils/parse-blocks.ts +2 -2
  42. package/src/internal-utils/slate-utils.ts +1 -1
  43. package/src/priority/priority.core.ts +3 -0
  44. package/src/priority/priority.sort.test.ts +319 -0
  45. package/src/priority/priority.sort.ts +121 -0
  46. package/src/priority/priority.types.ts +24 -0
  47. package/src/editor/components/DefaultObject.tsx +0 -21
  48. package/src/editor/components/Element.tsx +0 -435
package/lib/index.js CHANGED
@@ -1,22 +1,22 @@
1
1
  import { c } from "react-compiler-runtime";
2
- import { useEffect, useContext, useRef, useState, useMemo, startTransition, useCallback, forwardRef, useImperativeHandle } from "react";
2
+ import { useEffect, useRef, useState, useMemo, startTransition, useCallback, useContext, forwardRef, useImperativeHandle } from "react";
3
3
  import { useEffectEvent } from "use-effect-event";
4
- import { useEditor, getNodeBlock, getFirstBlock, getLastBlock, slateRangeToSelection, toSlateRange, debugWithName, EditorActorContext, fromSlateValue, KEY_TO_VALUE_ELEMENT, usePortableTextEditor, PortableTextEditor, isHotkey, moveRangeByOperation, isEqualToEmptyEditor, getEditorSnapshot } from "./_chunks-es/editor-provider.js";
4
+ import { useEditor, getNodeBlock, getFirstBlock, getLastBlock, slateRangeToSelection, toSlateRange, debugWithName, usePortableTextEditor, PortableTextEditor, createEditorPriority, corePriority, EditorActorContext, getPointBlock, isHotkey, moveRangeByOperation, isEqualToEmptyEditor, fromSlateValue, KEY_TO_VALUE_ELEMENT, getEditorSnapshot } from "./_chunks-es/editor-provider.js";
5
5
  import { EditorProvider, defineSchema, defaultKeyGenerator, useEditorSelector, usePortableTextEditorSelection } from "./_chunks-es/editor-provider.js";
6
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
6
+ import { jsx, Fragment, jsxs } from "react/jsx-runtime";
7
7
  import { useSelector, useActorRef } from "@xstate/react";
8
8
  import noop from "lodash/noop.js";
9
- import { Editor, Range, Element as Element$2, Text, Path, Transforms } from "slate";
10
- import { useSlateStatic, useSelected, ReactEditor, useSlate, Editable } from "slate-react";
11
- import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
9
+ import { Editor, Text, Range, Element as Element$1, Path, Transforms } from "slate";
10
+ import { useSelected, useSlateStatic, useSlate, ReactEditor, Editable } from "slate-react";
11
+ import { getBlockEndPoint, getBlockStartPoint, isKeyedSegment, parseInlineObject, parseTextBlock, parseBlockObject, parseBlocks } from "./_chunks-es/util.slice-blocks.js";
12
12
  import { isSelectionCollapsed, getFocusTextBlock, getFocusSpan, getSelectedBlocks, isSelectionExpanded, getSelectionStartBlock, getSelectionEndBlock, isOverlappingSelection, getFocusBlock, isSelectingEntireBlocks } from "./_chunks-es/selector.is-selecting-entire-blocks.js";
13
13
  import { getFocusInlineObject } from "./_chunks-es/selector.get-focus-inline-object.js";
14
14
  import { DOMEditor, isDOMNode } from "slate-dom";
15
15
  import { isSelectionCollapsed as isSelectionCollapsed$1 } from "./_chunks-es/util.is-selection-collapsed.js";
16
16
  import isEqual from "lodash/isEqual.js";
17
17
  import { getSelectionEndPoint } from "./_chunks-es/util.selection-point-to-block-offset.js";
18
- import { defineBehavior, forward } from "./behaviors/index.js";
19
18
  import uniq from "lodash/uniq.js";
19
+ import { defineBehavior, forward } from "./behaviors/index.js";
20
20
  import { setup, fromCallback, assign, and } from "xstate";
21
21
  function EditorEventListener(props) {
22
22
  const $ = c(5), editor = useEditor(), on = useEffectEvent(props.on);
@@ -343,260 +343,6 @@ function getSelectionDomNodes({
343
343
  childNodes: childEntries.map(([childNode]) => DOMEditor.toDOMNode(slateEditor, childNode))
344
344
  };
345
345
  }
346
- function DefaultBlockObject(props) {
347
- const $ = c(4);
348
- let t0;
349
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
350
- userSelect: "none"
351
- }, $[0] = t0) : t0 = $[0];
352
- let t1;
353
- return $[1] !== props.value._key || $[2] !== props.value._type ? (t1 = /* @__PURE__ */ jsxs("div", { style: t0, children: [
354
- "[",
355
- props.value._type,
356
- ": ",
357
- props.value._key,
358
- "]"
359
- ] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
360
- }
361
- function DefaultInlineObject(props) {
362
- const $ = c(4);
363
- let t0;
364
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
365
- userSelect: "none"
366
- }, $[0] = t0) : t0 = $[0];
367
- let t1;
368
- return $[1] !== props.value._key || $[2] !== props.value._type ? (t1 = /* @__PURE__ */ jsxs("span", { style: t0, children: [
369
- "[",
370
- props.value._type,
371
- ": ",
372
- props.value._key,
373
- "]"
374
- ] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
375
- }
376
- function DropIndicator() {
377
- const $ = c(1);
378
- let t0;
379
- return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
380
- position: "absolute",
381
- width: "100%",
382
- height: 1,
383
- borderBottom: "1px solid currentColor",
384
- zIndex: 5
385
- }, children: /* @__PURE__ */ jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
386
- }
387
- debugWithName("components:Element");
388
- const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
389
- display: "inline-block"
390
- }, Element$1 = ({
391
- attributes,
392
- children,
393
- element,
394
- schemaTypes,
395
- readOnly,
396
- renderBlock,
397
- renderChild,
398
- renderListItem,
399
- renderStyle,
400
- spellCheck
401
- }) => {
402
- const editorActor = useContext(EditorActorContext), slateEditor = useSlateStatic(), selected = useSelected(), blockRef = useRef(null), inlineBlockObjectRef = useRef(null), focused = selected && slateEditor.selection && Range.isCollapsed(slateEditor.selection) || !1, [dragPositionBlock, setDragPositionBlock] = useState();
403
- useEffect(() => {
404
- const behavior = defineBehavior({
405
- on: "drag.dragover",
406
- guard: ({
407
- snapshot,
408
- event
409
- }) => {
410
- const dropFocusBlock = getFocusBlock({
411
- context: {
412
- ...snapshot.context,
413
- selection: event.position.selection
414
- }
415
- });
416
- if (!dropFocusBlock || dropFocusBlock.node._key !== element._key)
417
- return !1;
418
- const dragOrigin = snapshot.beta.internalDrag?.origin;
419
- return !dragOrigin || getSelectedBlocks({
420
- context: {
421
- ...snapshot.context,
422
- selection: dragOrigin.selection
423
- }
424
- }).some((draggedBlock) => draggedBlock.node._key === element._key) ? !1 : isSelectingEntireBlocks({
425
- context: {
426
- ...snapshot.context,
427
- selection: dragOrigin.selection
428
- }
429
- });
430
- },
431
- actions: [({
432
- event: event_0
433
- }) => [{
434
- type: "effect",
435
- effect: () => {
436
- setDragPositionBlock(event_0.position.block);
437
- }
438
- }]]
439
- });
440
- return editorActor.send({
441
- type: "add behavior",
442
- behavior
443
- }), () => {
444
- editorActor.send({
445
- type: "remove behavior",
446
- behavior
447
- });
448
- };
449
- }, [editorActor, element._key]), useEffect(() => {
450
- const behavior_0 = defineBehavior({
451
- on: "drag.*",
452
- guard: ({
453
- event: event_1
454
- }) => event_1.type !== "drag.dragover",
455
- actions: [({
456
- event: event_2
457
- }) => [{
458
- type: "effect",
459
- effect: () => {
460
- setDragPositionBlock(void 0);
461
- }
462
- }, forward(event_2)]]
463
- });
464
- return editorActor.send({
465
- type: "add behavior",
466
- behavior: behavior_0
467
- }), () => {
468
- editorActor.send({
469
- type: "remove behavior",
470
- behavior: behavior_0
471
- });
472
- };
473
- }, [editorActor]);
474
- const value = useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor))[0], [slateEditor, element, schemaTypes.block.name]);
475
- let renderedBlock = children, className;
476
- const blockPath = useMemo(() => [{
477
- _key: element._key
478
- }], [element]);
479
- if (typeof element._type != "string")
480
- throw new Error("Expected element to have a _type property");
481
- if (typeof element._key != "string")
482
- throw new Error("Expected element to have a _key property");
483
- if (slateEditor.isInline(element)) {
484
- const path = ReactEditor.findPath(slateEditor, element), [block] = Editor.node(slateEditor, path, {
485
- depth: 1
486
- }), schemaType = schemaTypes.inlineObjects.find((_type) => _type.name === element._type);
487
- if (!schemaType)
488
- throw new Error("Could not find type for inline block element");
489
- if (Element$2.isElement(block)) {
490
- const elmPath = [{
491
- _key: block._key
492
- }, "children", {
493
- _key: element._key
494
- }];
495
- return /* @__PURE__ */ jsxs("span", { ...attributes, children: [
496
- children,
497
- /* @__PURE__ */ jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
498
- renderChild && renderChild({
499
- annotations: EMPTY_ANNOTATIONS,
500
- // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.
501
- children: /* @__PURE__ */ jsx(DefaultInlineObject, { value }),
502
- editorElementRef: inlineBlockObjectRef,
503
- focused,
504
- path: elmPath,
505
- schemaType,
506
- selected,
507
- type: schemaType,
508
- value
509
- }),
510
- !renderChild && /* @__PURE__ */ jsx(DefaultInlineObject, { value })
511
- ] }, element._key)
512
- ] });
513
- }
514
- throw new Error("Block not found!");
515
- }
516
- if (element._type === schemaTypes.block.name) {
517
- className = "pt-block pt-text-block";
518
- const isListItem = "listItem" in element, style = "style" in element && element.style || "normal";
519
- className = `pt-block pt-text-block pt-text-block-style-${style}`;
520
- const blockStyleType = schemaTypes.styles.find((item) => item.value === style);
521
- renderStyle && blockStyleType && (renderedBlock = renderStyle({
522
- block: element,
523
- children,
524
- focused,
525
- selected,
526
- value: style,
527
- path: blockPath,
528
- schemaType: blockStyleType,
529
- editorElementRef: blockRef
530
- }));
531
- let level;
532
- if (isListItem && (typeof element.level == "number" && (level = element.level), className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`), slateEditor.isListBlock(value) && isListItem && element.listItem) {
533
- const listType = schemaTypes.lists.find((item_0) => item_0.value === element.listItem);
534
- renderListItem && listType && (renderedBlock = renderListItem({
535
- block: value,
536
- children: renderedBlock,
537
- focused,
538
- selected,
539
- value: element.listItem,
540
- path: blockPath,
541
- schemaType: listType,
542
- level: value.level || 1,
543
- editorElementRef: blockRef
544
- }));
545
- }
546
- const renderProps = Object.defineProperty({
547
- children: renderedBlock,
548
- editorElementRef: blockRef,
549
- focused,
550
- level,
551
- listItem: isListItem ? element.listItem : void 0,
552
- path: blockPath,
553
- selected,
554
- style,
555
- schemaType: schemaTypes.block,
556
- value
557
- }, "type", {
558
- enumerable: !1,
559
- get() {
560
- return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
561
- }
562
- }), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
563
- return /* @__PURE__ */ jsxs("div", { ...attributes, className, spellCheck, children: [
564
- dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
565
- /* @__PURE__ */ jsx("div", { ref: blockRef, children: propsOrDefaultRendered }),
566
- dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
567
- ] }, element._key);
568
- }
569
- const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
570
- if (!schemaType_0)
571
- throw new Error(`Could not find schema type for block element of _type ${element._type}`);
572
- className = "pt-block pt-object-block";
573
- const block_0 = fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor))[0];
574
- let renderedBlockFromProps;
575
- if (renderBlock) {
576
- const _props = Object.defineProperty({
577
- children: /* @__PURE__ */ jsx(DefaultBlockObject, { value }),
578
- editorElementRef: blockRef,
579
- focused,
580
- path: blockPath,
581
- schemaType: schemaType_0,
582
- selected,
583
- value: block_0
584
- }, "type", {
585
- enumerable: !1,
586
- get() {
587
- return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaType_0;
588
- }
589
- });
590
- renderedBlockFromProps = renderBlock(_props);
591
- }
592
- return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
593
- dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
594
- children,
595
- /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, draggable: !readOnly, children: renderedBlockFromProps || /* @__PURE__ */ jsx(DefaultBlockObject, { value }) }),
596
- dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
597
- ] }, element._key);
598
- };
599
- Element$1.displayName = "Element";
600
346
  const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
601
347
  const {
602
348
  editorActor,
@@ -718,9 +464,352 @@ const debug$2 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
718
464
  }
719
465
  return returnedChildren;
720
466
  }, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
721
- return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
467
+ return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, "data-child-key": leaf._key, "data-child-name": leaf._type, "data-child-type": "span", children: content }, leaf._key), [leaf, attributes, content]);
722
468
  };
723
469
  Leaf.displayName = "Leaf";
470
+ function DropIndicator() {
471
+ const $ = c(1);
472
+ let t0;
473
+ return $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsx("div", { contentEditable: !1, className: "pt-drop-indicator", style: {
474
+ position: "absolute",
475
+ width: "100%",
476
+ height: 1,
477
+ borderBottom: "1px solid currentColor",
478
+ zIndex: 5
479
+ }, children: /* @__PURE__ */ jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
480
+ }
481
+ function RenderDefaultBlockObject(props) {
482
+ const $ = c(4);
483
+ let t0;
484
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
485
+ userSelect: "none"
486
+ }, $[0] = t0) : t0 = $[0];
487
+ let t1;
488
+ return $[1] !== props.blockObject._key || $[2] !== props.blockObject._type ? (t1 = /* @__PURE__ */ jsxs("div", { style: t0, children: [
489
+ "[",
490
+ props.blockObject._type,
491
+ ": ",
492
+ props.blockObject._key,
493
+ "]"
494
+ ] }), $[1] = props.blockObject._key, $[2] = props.blockObject._type, $[3] = t1) : t1 = $[3], t1;
495
+ }
496
+ function RenderDefaultInlineObject(props) {
497
+ const $ = c(4);
498
+ let t0;
499
+ $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
500
+ userSelect: "none"
501
+ }, $[0] = t0) : t0 = $[0];
502
+ let t1;
503
+ return $[1] !== props.inlineObject._key || $[2] !== props.inlineObject._type ? (t1 = /* @__PURE__ */ jsxs("span", { style: t0, children: [
504
+ "[",
505
+ props.inlineObject._type,
506
+ ": ",
507
+ props.inlineObject._key,
508
+ "]"
509
+ ] }), $[1] = props.inlineObject._key, $[2] = props.inlineObject._type, $[3] = t1) : t1 = $[3], t1;
510
+ }
511
+ function createCoreBlockElementBehaviorsConfig({
512
+ key,
513
+ onSetDragPositionBlock
514
+ }) {
515
+ return [{
516
+ behavior: defineBehavior({
517
+ on: "drag.dragover",
518
+ guard: ({
519
+ snapshot,
520
+ event
521
+ }) => {
522
+ const dropFocusBlock = getFocusBlock({
523
+ context: {
524
+ ...snapshot.context,
525
+ selection: event.position.selection
526
+ }
527
+ });
528
+ if (!dropFocusBlock || dropFocusBlock.node._key !== key)
529
+ return !1;
530
+ const dragOrigin = snapshot.beta.internalDrag?.origin;
531
+ return !dragOrigin || getSelectedBlocks({
532
+ context: {
533
+ ...snapshot.context,
534
+ selection: dragOrigin.selection
535
+ }
536
+ }).some((draggedBlock) => draggedBlock.node._key === key) ? !1 : isSelectingEntireBlocks({
537
+ context: {
538
+ ...snapshot.context,
539
+ selection: dragOrigin.selection
540
+ }
541
+ });
542
+ },
543
+ actions: [({
544
+ event
545
+ }) => [{
546
+ type: "effect",
547
+ effect: () => {
548
+ onSetDragPositionBlock(event.position.block);
549
+ }
550
+ }]]
551
+ }),
552
+ priority: createEditorPriority({
553
+ reference: {
554
+ priority: corePriority,
555
+ importance: "lower"
556
+ }
557
+ })
558
+ }, {
559
+ behavior: defineBehavior({
560
+ on: "drag.*",
561
+ guard: ({
562
+ event
563
+ }) => event.type !== "drag.dragover",
564
+ actions: [({
565
+ event
566
+ }) => [{
567
+ type: "effect",
568
+ effect: () => {
569
+ onSetDragPositionBlock(void 0);
570
+ }
571
+ }, forward(event)]]
572
+ }),
573
+ priority: createEditorPriority({
574
+ reference: {
575
+ priority: corePriority,
576
+ importance: "lower"
577
+ }
578
+ })
579
+ }];
580
+ }
581
+ function useCoreBlockElementBehaviors(t0) {
582
+ const $ = c(5), {
583
+ key,
584
+ onSetDragPositionBlock
585
+ } = t0, editorActor = useContext(EditorActorContext);
586
+ let t1, t2;
587
+ $[0] !== editorActor || $[1] !== key || $[2] !== onSetDragPositionBlock ? (t1 = () => {
588
+ const behaviorConfigs = createCoreBlockElementBehaviorsConfig({
589
+ key,
590
+ onSetDragPositionBlock
591
+ });
592
+ for (const behaviorConfig of behaviorConfigs)
593
+ editorActor.send({
594
+ type: "add behavior",
595
+ behaviorConfig
596
+ });
597
+ return () => {
598
+ for (const behaviorConfig_0 of behaviorConfigs)
599
+ editorActor.send({
600
+ type: "remove behavior",
601
+ behaviorConfig: behaviorConfig_0
602
+ });
603
+ };
604
+ }, t2 = [editorActor, key, onSetDragPositionBlock], $[0] = editorActor, $[1] = key, $[2] = onSetDragPositionBlock, $[3] = t1, $[4] = t2) : (t1 = $[3], t2 = $[4]), useEffect(t1, t2);
605
+ }
606
+ function RenderBlockObject(props) {
607
+ const [dragPositionBlock, setDragPositionBlock] = useState(), blockObjectRef = useRef(null), slateEditor = useSlateStatic(), selected = useSelected(), editorActor = useContext(EditorActorContext);
608
+ useCoreBlockElementBehaviors({
609
+ key: props.element._key,
610
+ onSetDragPositionBlock: setDragPositionBlock
611
+ });
612
+ const legacySchemaType = useSelector(editorActor, (s) => s.context.getLegacySchema().blockObjects.find((blockObject) => blockObject.name === props.element._type));
613
+ legacySchemaType || console.error(`Block object type ${props.element._type} not found in Schema`);
614
+ const focused = selected && slateEditor.selection !== null && Range.isCollapsed(slateEditor.selection);
615
+ return /* @__PURE__ */ jsxs("div", { ...props.attributes, className: "pt-block pt-object-block", "data-block-key": props.element._key, "data-block-name": props.element._type, "data-block-type": "object", children: [
616
+ dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
617
+ props.children,
618
+ /* @__PURE__ */ jsx("div", { ref: blockObjectRef, contentEditable: !1, draggable: !props.readOnly, children: props.renderBlock && legacySchemaType ? props.renderBlock({
619
+ children: /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }),
620
+ editorElementRef: blockObjectRef,
621
+ focused,
622
+ path: [{
623
+ _key: props.element._key
624
+ }],
625
+ schemaType: legacySchemaType,
626
+ selected,
627
+ type: legacySchemaType,
628
+ value: props.blockObject
629
+ }) : /* @__PURE__ */ jsx(RenderDefaultBlockObject, { blockObject: props.blockObject }) }),
630
+ dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
631
+ ] }, props.element._key);
632
+ }
633
+ function RenderInlineObject(props) {
634
+ const inlineObjectRef = useRef(null), slateEditor = useSlateStatic(), selected = useSelected(), editorActor = useContext(EditorActorContext), legacySchemaType = useSelector(editorActor, (s) => s.context.getLegacySchema().inlineObjects.find((inlineObject) => inlineObject.name === props.element._type));
635
+ legacySchemaType || console.error(`Inline object type ${props.element._type} not found in Schema`);
636
+ const focused = selected && slateEditor.selection !== null && Range.isCollapsed(slateEditor.selection), path = DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
637
+ editor: slateEditor,
638
+ point: {
639
+ path,
640
+ offset: 0
641
+ }
642
+ });
643
+ return block || console.error(`Unable to find parent block of inline object ${props.element._key}`), /* @__PURE__ */ jsxs("span", { ...props.attributes, children: [
644
+ props.children,
645
+ /* @__PURE__ */ jsx("span", { draggable: !props.readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineObjectRef, style: {
646
+ display: "inline-block"
647
+ }, "data-child-key": props.inlineObject._key, "data-child-name": props.inlineObject._type, "data-child-type": "object", children: props.renderChild && block && legacySchemaType ? props.renderChild({
648
+ annotations: [],
649
+ children: /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }),
650
+ editorElementRef: inlineObjectRef,
651
+ selected,
652
+ focused,
653
+ path: [{
654
+ _key: block._key
655
+ }, "children", {
656
+ _key: props.element._key
657
+ }],
658
+ schemaType: legacySchemaType,
659
+ value: props.inlineObject,
660
+ type: legacySchemaType
661
+ }) : /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: props.inlineObject }) }, props.element._key)
662
+ ] });
663
+ }
664
+ function RenderTextBlock(props) {
665
+ const [dragPositionBlock, setDragPositionBlock] = useState(), blockRef = useRef(null), slateEditor = useSlateStatic(), selected = useSelected(), editorActor = useContext(EditorActorContext);
666
+ useCoreBlockElementBehaviors({
667
+ key: props.element._key,
668
+ onSetDragPositionBlock: setDragPositionBlock
669
+ });
670
+ const legacySchema = useSelector(editorActor, (s) => s.context.getLegacySchema()), focused = selected && slateEditor.selection !== null && Range.isCollapsed(slateEditor.selection);
671
+ let children = props.children;
672
+ const legacyBlockSchemaType = legacySchema.block;
673
+ if (props.renderStyle && props.textBlock.style) {
674
+ const legacyStyleSchemaType = props.textBlock.style !== void 0 ? legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0;
675
+ legacyStyleSchemaType ? children = props.renderStyle({
676
+ block: props.textBlock,
677
+ children,
678
+ editorElementRef: blockRef,
679
+ focused,
680
+ path: [{
681
+ _key: props.textBlock._key
682
+ }],
683
+ schemaType: legacyStyleSchemaType,
684
+ selected,
685
+ value: props.textBlock.style
686
+ }) : console.error(`Unable to find Schema type for text block style ${props.textBlock.style}`);
687
+ }
688
+ if (props.renderListItem && props.textBlock.listItem) {
689
+ const legacyListItemSchemaType = legacySchema.lists.find((list) => list.value === props.textBlock.listItem);
690
+ legacyListItemSchemaType ? children = props.renderListItem({
691
+ block: props.textBlock,
692
+ children,
693
+ editorElementRef: blockRef,
694
+ focused,
695
+ level: props.textBlock.level ?? 1,
696
+ path: [{
697
+ _key: props.textBlock._key
698
+ }],
699
+ selected,
700
+ value: props.textBlock.listItem,
701
+ schemaType: legacyListItemSchemaType
702
+ }) : console.error(`Unable to find Schema type for text block list item ${props.textBlock.listItem}`);
703
+ }
704
+ return /* @__PURE__ */ jsxs("div", { ...props.attributes, className: ["pt-block", "pt-text-block", ...props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], ...props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : []].join(" "), spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", children: [
705
+ dragPositionBlock === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null,
706
+ /* @__PURE__ */ jsx("div", { ref: blockRef, children: props.renderBlock ? props.renderBlock({
707
+ children,
708
+ editorElementRef: blockRef,
709
+ focused,
710
+ level: props.textBlock.level,
711
+ listItem: props.textBlock.listItem,
712
+ path: [{
713
+ _key: props.textBlock._key
714
+ }],
715
+ selected,
716
+ schemaType: legacyBlockSchemaType,
717
+ style: props.textBlock.style,
718
+ type: legacyBlockSchemaType,
719
+ value: props.textBlock
720
+ }) : props.children }),
721
+ dragPositionBlock === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null
722
+ ] }, props.element._key);
723
+ }
724
+ function RenderElement(props) {
725
+ const $ = c(45), editorActor = useContext(EditorActorContext), schema = useSelector(editorActor, _temp);
726
+ if ("__inline" in props.element && props.element.__inline === !0) {
727
+ let t02;
728
+ if ($[0] !== props.element || $[1] !== schema) {
729
+ let t13;
730
+ $[3] !== props.element ? (t13 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[3] = props.element, $[4] = t13) : t13 = $[4], t02 = parseInlineObject({
731
+ context: {
732
+ keyGenerator: _temp2,
733
+ schema
734
+ },
735
+ options: {
736
+ refreshKeys: !1
737
+ },
738
+ inlineObject: {
739
+ _key: props.element._key,
740
+ _type: props.element._type,
741
+ ...t13
742
+ }
743
+ }), $[0] = props.element, $[1] = schema, $[2] = t02;
744
+ } else
745
+ t02 = $[2];
746
+ const inlineObject = t02;
747
+ inlineObject || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
748
+ let t12;
749
+ $[5] !== inlineObject || $[6] !== props.element._key || $[7] !== props.element._type ? (t12 = inlineObject ?? {
750
+ _key: props.element._key,
751
+ _type: props.element._type
752
+ }, $[5] = inlineObject, $[6] = props.element._key, $[7] = props.element._type, $[8] = t12) : t12 = $[8];
753
+ let t22;
754
+ return $[9] !== props.attributes || $[10] !== props.children || $[11] !== props.element || $[12] !== props.readOnly || $[13] !== props.renderChild || $[14] !== t12 ? (t22 = /* @__PURE__ */ jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, inlineObject: t12, readOnly: props.readOnly, renderChild: props.renderChild, children: props.children }), $[9] = props.attributes, $[10] = props.children, $[11] = props.element, $[12] = props.readOnly, $[13] = props.renderChild, $[14] = t12, $[15] = t22) : t22 = $[15], t22;
755
+ }
756
+ let t0;
757
+ $[16] !== props.element || $[17] !== schema ? (t0 = parseTextBlock({
758
+ context: {
759
+ keyGenerator: _temp3,
760
+ schema
761
+ },
762
+ options: {
763
+ refreshKeys: !1
764
+ },
765
+ block: props.element
766
+ }), $[16] = props.element, $[17] = schema, $[18] = t0) : t0 = $[18];
767
+ const textBlock = t0;
768
+ if (textBlock) {
769
+ let t12;
770
+ return $[19] !== props.attributes || $[20] !== props.children || $[21] !== props.element || $[22] !== props.readOnly || $[23] !== props.renderBlock || $[24] !== props.renderListItem || $[25] !== props.renderStyle || $[26] !== props.spellCheck || $[27] !== textBlock ? (t12 = /* @__PURE__ */ jsx(RenderTextBlock, { attributes: props.attributes, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, renderListItem: props.renderListItem, renderStyle: props.renderStyle, spellCheck: props.spellCheck, textBlock, children: props.children }), $[19] = props.attributes, $[20] = props.children, $[21] = props.element, $[22] = props.readOnly, $[23] = props.renderBlock, $[24] = props.renderListItem, $[25] = props.renderStyle, $[26] = props.spellCheck, $[27] = textBlock, $[28] = t12) : t12 = $[28], t12;
771
+ }
772
+ let t1;
773
+ if ($[29] !== props.element || $[30] !== schema) {
774
+ let t22;
775
+ $[32] !== props.element ? (t22 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[32] = props.element, $[33] = t22) : t22 = $[33], t1 = parseBlockObject({
776
+ context: {
777
+ keyGenerator: _temp4,
778
+ schema
779
+ },
780
+ options: {
781
+ refreshKeys: !1
782
+ },
783
+ blockObject: {
784
+ _key: props.element._key,
785
+ _type: props.element._type,
786
+ ...t22
787
+ }
788
+ }), $[29] = props.element, $[30] = schema, $[31] = t1;
789
+ } else
790
+ t1 = $[31];
791
+ const blockObject = t1;
792
+ blockObject || console.error(`Unable to find Block Object "${props.element._type}" in Schema`);
793
+ let t2;
794
+ $[34] !== blockObject || $[35] !== props.element._key || $[36] !== props.element._type ? (t2 = blockObject ?? {
795
+ _key: props.element._key,
796
+ _type: props.element._type
797
+ }, $[34] = blockObject, $[35] = props.element._key, $[36] = props.element._type, $[37] = t2) : t2 = $[37];
798
+ let t3;
799
+ return $[38] !== props.attributes || $[39] !== props.children || $[40] !== props.element || $[41] !== props.readOnly || $[42] !== props.renderBlock || $[43] !== t2 ? (t3 = /* @__PURE__ */ jsx(RenderBlockObject, { attributes: props.attributes, blockObject: t2, element: props.element, readOnly: props.readOnly, renderBlock: props.renderBlock, children: props.children }), $[38] = props.attributes, $[39] = props.children, $[40] = props.element, $[41] = props.readOnly, $[42] = props.renderBlock, $[43] = t2, $[44] = t3) : t3 = $[44], t3;
800
+ }
801
+ function _temp4() {
802
+ return "";
803
+ }
804
+ function _temp3() {
805
+ return "";
806
+ }
807
+ function _temp2() {
808
+ return "";
809
+ }
810
+ function _temp(s) {
811
+ return s.context.schema;
812
+ }
724
813
  const debug$1 = debugWithName("plugin:withHotKeys");
725
814
  function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
726
815
  const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
@@ -1022,7 +1111,7 @@ function createDecorate(rangeDecorationActor) {
1022
1111
  }];
1023
1112
  if (path.length === 0)
1024
1113
  return [];
1025
- if (!Element$2.isElement(node) || node.children.length === 0)
1114
+ if (!Element$1.isElement(node) || node.children.length === 0)
1026
1115
  return [];
1027
1116
  const blockIndex = path.at(0);
1028
1117
  return blockIndex === void 0 ? [] : rangeDecorationActor.getSnapshot().context.decoratedRanges.filter((decoratedRange) => Range.isCollapsed(decoratedRange) ? node.children.some((_, childIndex) => Path.equals(decoratedRange.anchor.path, [blockIndex, childIndex]) && Path.equals(decoratedRange.focus.path, [blockIndex, childIndex])) : Range.intersection(decoratedRange, {
@@ -1105,7 +1194,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
1105
1194
  const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
1106
1195
  return debug("Editable is in edit mode"), withHotKeys(slateEditor);
1107
1196
  }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
1108
- const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(Element$1, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes: portableTextEditor.schemaTypes, spellCheck }), [portableTextEditor, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
1197
+ const renderElement = useCallback((eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), [spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = useCallback((lProps) => {
1109
1198
  if (lProps.leaf._type === "span") {
1110
1199
  let rendered = /* @__PURE__ */ jsx(Leaf, { ...lProps, editorActor, schemaTypes: portableTextEditor.schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
1111
1200
  if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")