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