@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.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,260 +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
- });
427
- return editorActor.send({
428
- type: "add behavior",
429
- behavior
430
- }), () => {
431
- editorActor.send({
432
- type: "remove behavior",
433
- behavior
434
- });
435
- };
436
- }, [editorActor, element._key]), React.useEffect(() => {
437
- const behavior_0 = behaviors_index.defineBehavior({
438
- on: "drag.*",
439
- guard: ({
440
- event: event_1
441
- }) => event_1.type !== "drag.dragover",
442
- actions: [({
443
- event: event_2
444
- }) => [{
445
- type: "effect",
446
- effect: () => {
447
- setDragPositionBlock(void 0);
448
- }
449
- }, behaviors_index.forward(event_2)]]
450
- });
451
- return editorActor.send({
452
- type: "add behavior",
453
- behavior: behavior_0
454
- }), () => {
455
- editorActor.send({
456
- type: "remove behavior",
457
- behavior: behavior_0
458
- });
459
- };
460
- }, [editorActor]);
461
- const value = React.useMemo(() => editorProvider.fromSlateValue([element], schemaTypes.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(slateEditor))[0], [slateEditor, element, schemaTypes.block.name]);
462
- let renderedBlock = children, className;
463
- const blockPath = React.useMemo(() => [{
464
- _key: element._key
465
- }], [element]);
466
- if (typeof element._type != "string")
467
- throw new Error("Expected element to have a _type property");
468
- if (typeof element._key != "string")
469
- throw new Error("Expected element to have a _key property");
470
- if (slateEditor.isInline(element)) {
471
- const path = slateReact.ReactEditor.findPath(slateEditor, element), [block] = slate.Editor.node(slateEditor, path, {
472
- depth: 1
473
- }), schemaType = schemaTypes.inlineObjects.find((_type) => _type.name === element._type);
474
- if (!schemaType)
475
- throw new Error("Could not find type for inline block element");
476
- if (slate.Element.isElement(block)) {
477
- const elmPath = [{
478
- _key: block._key
479
- }, "children", {
480
- _key: element._key
481
- }];
482
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { ...attributes, children: [
483
- children,
484
- /* @__PURE__ */ jsxRuntime.jsxs("span", { draggable: !readOnly, className: "pt-inline-object", "data-testid": "pt-inline-object", ref: inlineBlockObjectRef, style: inlineBlockStyle, contentEditable: !1, children: [
485
- renderChild && renderChild({
486
- annotations: EMPTY_ANNOTATIONS,
487
- // These inline objects currently doesn't support annotations. This is a limitation of the current PT spec/model.
488
- children: /* @__PURE__ */ jsxRuntime.jsx(DefaultInlineObject, { value }),
489
- editorElementRef: inlineBlockObjectRef,
490
- focused,
491
- path: elmPath,
492
- schemaType,
493
- selected,
494
- type: schemaType,
495
- value
496
- }),
497
- !renderChild && /* @__PURE__ */ jsxRuntime.jsx(DefaultInlineObject, { value })
498
- ] }, element._key)
499
- ] });
500
- }
501
- throw new Error("Block not found!");
502
- }
503
- if (element._type === schemaTypes.block.name) {
504
- className = "pt-block pt-text-block";
505
- const isListItem = "listItem" in element, style = "style" in element && element.style || "normal";
506
- className = `pt-block pt-text-block pt-text-block-style-${style}`;
507
- const blockStyleType = schemaTypes.styles.find((item) => item.value === style);
508
- renderStyle && blockStyleType && (renderedBlock = renderStyle({
509
- block: element,
510
- children,
511
- focused,
512
- selected,
513
- value: style,
514
- path: blockPath,
515
- schemaType: blockStyleType,
516
- editorElementRef: blockRef
517
- }));
518
- let level;
519
- 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) {
520
- const listType = schemaTypes.lists.find((item_0) => item_0.value === element.listItem);
521
- renderListItem && listType && (renderedBlock = renderListItem({
522
- block: value,
523
- children: renderedBlock,
524
- focused,
525
- selected,
526
- value: element.listItem,
527
- path: blockPath,
528
- schemaType: listType,
529
- level: value.level || 1,
530
- editorElementRef: blockRef
531
- }));
532
- }
533
- const renderProps = Object.defineProperty({
534
- children: renderedBlock,
535
- editorElementRef: blockRef,
536
- focused,
537
- level,
538
- listItem: isListItem ? element.listItem : void 0,
539
- path: blockPath,
540
- selected,
541
- style,
542
- schemaType: schemaTypes.block,
543
- value
544
- }, "type", {
545
- enumerable: !1,
546
- get() {
547
- return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaTypes.block;
548
- }
549
- }), propsOrDefaultRendered = renderBlock ? renderBlock(renderProps) : children;
550
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...attributes, className, spellCheck, children: [
551
- dragPositionBlock === "start" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null,
552
- /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, children: propsOrDefaultRendered }),
553
- dragPositionBlock === "end" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null
554
- ] }, element._key);
555
- }
556
- const schemaType_0 = schemaTypes.blockObjects.find((_type_0) => _type_0.name === element._type);
557
- if (!schemaType_0)
558
- throw new Error(`Could not find schema type for block element of _type ${element._type}`);
559
- className = "pt-block pt-object-block";
560
- const block_0 = editorProvider.fromSlateValue([element], schemaTypes.block.name, editorProvider.KEY_TO_VALUE_ELEMENT.get(slateEditor))[0];
561
- let renderedBlockFromProps;
562
- if (renderBlock) {
563
- const _props = Object.defineProperty({
564
- children: /* @__PURE__ */ jsxRuntime.jsx(DefaultBlockObject, { value }),
565
- editorElementRef: blockRef,
566
- focused,
567
- path: blockPath,
568
- schemaType: schemaType_0,
569
- selected,
570
- value: block_0
571
- }, "type", {
572
- enumerable: !1,
573
- get() {
574
- return console.warn("Property 'type' is deprecated, use 'schemaType' instead."), schemaType_0;
575
- }
576
- });
577
- renderedBlockFromProps = renderBlock(_props);
578
- }
579
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { ...attributes, className, children: [
580
- dragPositionBlock === "start" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null,
581
- children,
582
- /* @__PURE__ */ jsxRuntime.jsx("div", { ref: blockRef, contentEditable: !1, draggable: !readOnly, children: renderedBlockFromProps || /* @__PURE__ */ jsxRuntime.jsx(DefaultBlockObject, { value }) }),
583
- dragPositionBlock === "end" ? /* @__PURE__ */ jsxRuntime.jsx(DropIndicator, {}) : null
584
- ] }, element._key);
585
- };
586
- Element$1.displayName = "Element";
587
333
  const debug$2 = editorProvider.debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
588
334
  const {
589
335
  editorActor,
@@ -705,9 +451,352 @@ const debug$2 = editorProvider.debugWithName("components:Leaf"), EMPTY_MARKS = [
705
451
  }
706
452
  return returnedChildren;
707
453
  }, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
708
- 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]);
709
455
  };
710
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
+ }
711
800
  const debug$1 = editorProvider.debugWithName("plugin:withHotKeys");
712
801
  function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
713
802
  const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
@@ -1092,7 +1181,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
1092
1181
  const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
1093
1182
  return debug("Editable is in edit mode"), withHotKeys(slateEditor);
1094
1183
  }, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
1095
- 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) => {
1096
1185
  if (lProps.leaf._type === "span") {
1097
1186
  let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes: portableTextEditor.schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
1098
1187
  if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")