@portabletext/editor 4.3.8 → 4.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1323,6 +1323,9 @@ function DropIndicator() {
1323
1323
  zIndex: 5
1324
1324
  }, children: /* @__PURE__ */ jsx("span", {}) }), $[0] = t0) : t0 = $[0], t0;
1325
1325
  }
1326
+ function serializePath(path) {
1327
+ return path.map((segment) => isKeyedSegment(segment) ? segment._key : segment).join(".");
1328
+ }
1326
1329
  function defaultCompare(a, b) {
1327
1330
  return a === b;
1328
1331
  }
@@ -1362,8 +1365,8 @@ function getEditorSnapshot({
1362
1365
  };
1363
1366
  }
1364
1367
  const emptySet = /* @__PURE__ */ new Set(), defaultSelectionState = {
1365
- focusedChildKey: void 0,
1366
- selectedChildKeys: emptySet,
1368
+ focusedChildPath: void 0,
1369
+ selectedChildPaths: emptySet,
1367
1370
  focusedBlockKey: void 0,
1368
1371
  selectedBlockKeys: emptySet
1369
1372
  }, SelectionStateContext = createContext(defaultSelectionState);
@@ -1380,11 +1383,14 @@ function SelectionStateProvider(t0) {
1380
1383
  if (!snapshot.context.selection)
1381
1384
  return defaultSelectionState;
1382
1385
  const isCollapsed = isSelectionCollapsed$1(snapshot);
1383
- let focusedChildKey;
1384
- isCollapsed && (focusedChildKey = getFocusChild$1(snapshot)?.node._key);
1386
+ let focusedChildPath;
1387
+ if (isCollapsed) {
1388
+ const focusChild = getFocusChild$1(snapshot);
1389
+ focusChild && (focusedChildPath = serializePath(focusChild.path));
1390
+ }
1385
1391
  const selectedChildren = getSelectedChildren()(snapshot);
1386
- let selectedChildKeys = selectedChildren.length > 0 ? new Set(selectedChildren.map(_temp$4)) : emptySet;
1387
- isCollapsed && focusedChildKey && !selectedChildKeys.has(focusedChildKey) && (selectedChildKeys = new Set(selectedChildKeys), selectedChildKeys.add(focusedChildKey));
1392
+ let selectedChildPaths = selectedChildren.length > 0 ? new Set(selectedChildren.map(_temp$4)) : emptySet;
1393
+ isCollapsed && focusedChildPath && !selectedChildPaths.has(focusedChildPath) && (selectedChildPaths = new Set(selectedChildPaths), selectedChildPaths.add(focusedChildPath));
1388
1394
  const startPoint = getSelectionStartPoint(snapshot), endPoint = getSelectionEndPoint(snapshot), startBlockKey = startPoint ? getBlockKeyFromSelectionPoint(startPoint) : void 0, endBlockKey = endPoint ? getBlockKeyFromSelectionPoint(endPoint) : void 0;
1389
1395
  let selectedBlockKeys = emptySet;
1390
1396
  if (startBlockKey && endBlockKey) {
@@ -1398,8 +1404,8 @@ function SelectionStateProvider(t0) {
1398
1404
  }
1399
1405
  const focusedBlockKey = isCollapsed ? startBlockKey : void 0;
1400
1406
  return {
1401
- focusedChildKey,
1402
- selectedChildKeys: selectedChildKeys.size > 0 ? selectedChildKeys : emptySet,
1407
+ focusedChildPath,
1408
+ selectedChildPaths: selectedChildPaths.size > 0 ? selectedChildPaths : emptySet,
1403
1409
  focusedBlockKey,
1404
1410
  selectedBlockKeys: selectedBlockKeys.size > 0 ? selectedBlockKeys : emptySet
1405
1411
  };
@@ -1409,13 +1415,13 @@ function SelectionStateProvider(t0) {
1409
1415
  return $[2] !== children || $[3] !== selectionState ? (t2 = /* @__PURE__ */ jsx(SelectionStateContext.Provider, { value: selectionState, children }), $[2] = children, $[3] = selectionState, $[4] = t2) : t2 = $[4], t2;
1410
1416
  }
1411
1417
  function _temp2$3(prev, next) {
1412
- if (prev.focusedChildKey !== next.focusedChildKey)
1418
+ if (prev.focusedChildPath !== next.focusedChildPath)
1413
1419
  return !1;
1414
- if (prev.selectedChildKeys !== next.selectedChildKeys) {
1415
- if (prev.selectedChildKeys.size !== next.selectedChildKeys.size)
1420
+ if (prev.selectedChildPaths !== next.selectedChildPaths) {
1421
+ if (prev.selectedChildPaths.size !== next.selectedChildPaths.size)
1416
1422
  return !1;
1417
- for (const key_0 of prev.selectedChildKeys)
1418
- if (!next.selectedChildKeys.has(key_0))
1423
+ for (const path of prev.selectedChildPaths)
1424
+ if (!next.selectedChildPaths.has(path))
1419
1425
  return !1;
1420
1426
  }
1421
1427
  if (prev.focusedBlockKey !== next.focusedBlockKey)
@@ -1423,14 +1429,14 @@ function _temp2$3(prev, next) {
1423
1429
  if (prev.selectedBlockKeys !== next.selectedBlockKeys) {
1424
1430
  if (prev.selectedBlockKeys.size !== next.selectedBlockKeys.size)
1425
1431
  return !1;
1426
- for (const key_1 of prev.selectedBlockKeys)
1427
- if (!next.selectedBlockKeys.has(key_1))
1432
+ for (const key_0 of prev.selectedBlockKeys)
1433
+ if (!next.selectedBlockKeys.has(key_0))
1428
1434
  return !1;
1429
1435
  }
1430
1436
  return !0;
1431
1437
  }
1432
1438
  function _temp$4(child) {
1433
- return child.node._key;
1439
+ return serializePath(child.path);
1434
1440
  }
1435
1441
  function RenderBlockObject(props) {
1436
1442
  const $ = c(34), blockObjectRef = useRef(null), {
@@ -1496,59 +1502,51 @@ function RenderBlock$1({
1496
1502
  });
1497
1503
  }
1498
1504
  function RenderInlineObject(props) {
1499
- const $ = c(33), inlineObjectRef = useRef(null), slateEditor = useSlateStatic(), {
1500
- selectedChildKeys,
1501
- focusedChildKey
1502
- } = useContext(SelectionStateContext);
1505
+ const $ = c(28), inlineObjectRef = useRef(null), slateEditor = useSlateStatic();
1503
1506
  let t0;
1504
- $[0] !== props.element._key || $[1] !== selectedChildKeys ? (t0 = selectedChildKeys.has(props.element._key), $[0] = props.element._key, $[1] = selectedChildKeys, $[2] = t0) : t0 = $[2];
1505
- const selected = t0, focused = focusedChildKey === props.element._key;
1506
- let t1;
1507
- if ($[3] !== props.element._type || $[4] !== props.legacySchema.inlineObjects) {
1508
- let t22;
1509
- $[6] !== props.element._type ? (t22 = (inlineObject) => inlineObject.name === props.element._type, $[6] = props.element._type, $[7] = t22) : t22 = $[7], t1 = props.legacySchema.inlineObjects.find(t22), $[3] = props.element._type, $[4] = props.legacySchema.inlineObjects, $[5] = t1;
1507
+ if ($[0] !== props.element._type || $[1] !== props.legacySchema.inlineObjects) {
1508
+ let t12;
1509
+ $[3] !== props.element._type ? (t12 = (inlineObject) => inlineObject.name === props.element._type, $[3] = props.element._type, $[4] = t12) : t12 = $[4], t0 = props.legacySchema.inlineObjects.find(t12), $[0] = props.element._type, $[1] = props.legacySchema.inlineObjects, $[2] = t0;
1510
1510
  } else
1511
- t1 = $[5];
1512
- const legacySchemaType = t1;
1511
+ t0 = $[2];
1512
+ const legacySchemaType = t0;
1513
1513
  legacySchemaType || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
1514
- let t2;
1515
- if ($[8] !== props.element || $[9] !== slateEditor) {
1516
- const path = DOMEditor.findPath(slateEditor, props.element);
1517
- t2 = getPointBlock({
1518
- editor: slateEditor,
1519
- point: {
1520
- path,
1521
- offset: 0
1522
- }
1523
- }), $[8] = props.element, $[9] = slateEditor, $[10] = t2;
1524
- } else
1525
- t2 = $[10];
1526
- const [block] = t2;
1514
+ const slatePath = DOMEditor.findPath(slateEditor, props.element), [block] = getPointBlock({
1515
+ editor: slateEditor,
1516
+ point: {
1517
+ path: slatePath,
1518
+ offset: 0
1519
+ }
1520
+ });
1527
1521
  block || console.error(`Unable to find parent block of inline object ${props.element._key}`);
1528
- let t3;
1529
- $[11] !== props.element ? (t3 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[11] = props.element, $[12] = t3) : t3 = $[12];
1530
- let t4;
1531
- $[13] !== props.element._key || $[14] !== props.element._type || $[15] !== t3 ? (t4 = {
1522
+ const path = block ? [{
1523
+ _key: block._key
1524
+ }, "children", {
1525
+ _key: props.element._key
1526
+ }] : void 0, selectionState = useContext(SelectionStateContext), serializedPath = path ? serializePath(path) : void 0, selected = serializedPath ? selectionState.selectedChildPaths.has(serializedPath) : !1, focused = serializedPath ? selectionState.focusedChildPath === serializedPath : !1;
1527
+ let t1;
1528
+ $[5] !== props.element ? (t1 = "value" in props.element && typeof props.element.value == "object" ? props.element.value : {}, $[5] = props.element, $[6] = t1) : t1 = $[6];
1529
+ let t2;
1530
+ $[7] !== props.element._key || $[8] !== props.element._type || $[9] !== t1 ? (t2 = {
1532
1531
  _key: props.element._key,
1533
1532
  _type: props.element._type,
1534
- ...t3
1535
- }, $[13] = props.element._key, $[14] = props.element._type, $[15] = t3, $[16] = t4) : t4 = $[16];
1536
- const inlineObject_0 = t4, t5 = !props.readOnly;
1537
- let t6;
1538
- $[17] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t6 = {
1533
+ ...t1
1534
+ }, $[7] = props.element._key, $[8] = props.element._type, $[9] = t1, $[10] = t2) : t2 = $[10];
1535
+ const inlineObject_0 = t2;
1536
+ let t3;
1537
+ $[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = {
1539
1538
  display: "inline-block"
1540
- }, $[17] = t6) : t6 = $[17];
1539
+ }, $[11] = t3) : t3 = $[11];
1540
+ const t4 = !props.readOnly;
1541
+ let t5;
1542
+ $[12] !== focused || $[13] !== inlineObject_0 || $[14] !== legacySchemaType || $[15] !== path || $[16] !== props.renderChild || $[17] !== selected ? (t5 = props.renderChild && path && legacySchemaType ? /* @__PURE__ */ jsx(RenderChild$1, { renderChild: props.renderChild, annotations: [], editorElementRef: inlineObjectRef, selected, focused, path, schemaType: legacySchemaType, value: inlineObject_0, type: legacySchemaType, children: /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }) }) : /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }), $[12] = focused, $[13] = inlineObject_0, $[14] = legacySchemaType, $[15] = path, $[16] = props.renderChild, $[17] = selected, $[18] = t5) : t5 = $[18];
1543
+ let t6;
1544
+ $[19] !== t4 || $[20] !== t5 ? (t6 = /* @__PURE__ */ jsx("span", { ref: inlineObjectRef, style: t3, draggable: t4, children: t5 }), $[19] = t4, $[20] = t5, $[21] = t6) : t6 = $[21];
1541
1545
  let t7;
1542
- $[18] !== block || $[19] !== focused || $[20] !== inlineObject_0 || $[21] !== legacySchemaType || $[22] !== props.element._key || $[23] !== props.renderChild || $[24] !== selected ? (t7 = /* @__PURE__ */ jsx("span", { ref: inlineObjectRef, style: t6, children: props.renderChild && block && legacySchemaType ? /* @__PURE__ */ jsx(RenderChild$1, { renderChild: props.renderChild, annotations: [], editorElementRef: inlineObjectRef, selected, focused, path: [{
1543
- _key: block._key
1544
- }, "children", {
1545
- _key: props.element._key
1546
- }], schemaType: legacySchemaType, value: inlineObject_0, type: legacySchemaType, children: /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }) }) : /* @__PURE__ */ jsx(RenderDefaultInlineObject, { inlineObject: inlineObject_0 }) }), $[18] = block, $[19] = focused, $[20] = inlineObject_0, $[21] = legacySchemaType, $[22] = props.element._key, $[23] = props.renderChild, $[24] = selected, $[25] = t7) : t7 = $[25];
1547
- let t8;
1548
- return $[26] !== inlineObject_0._key || $[27] !== inlineObject_0._type || $[28] !== props.attributes || $[29] !== props.children || $[30] !== t5 || $[31] !== t7 ? (t8 = /* @__PURE__ */ jsxs("span", { ...props.attributes, draggable: t5, className: "pt-inline-object", "data-child-key": inlineObject_0._key, "data-child-name": inlineObject_0._type, "data-child-type": "object", children: [
1546
+ return $[22] !== inlineObject_0._key || $[23] !== inlineObject_0._type || $[24] !== props.attributes || $[25] !== props.children || $[26] !== t6 ? (t7 = /* @__PURE__ */ jsxs("span", { ...props.attributes, className: "pt-inline-object", "data-child-key": inlineObject_0._key, "data-child-name": inlineObject_0._type, "data-child-type": "object", children: [
1549
1547
  props.children,
1550
- t7
1551
- ] }), $[26] = inlineObject_0._key, $[27] = inlineObject_0._type, $[28] = props.attributes, $[29] = props.children, $[30] = t5, $[31] = t7, $[32] = t8) : t8 = $[32], t8;
1548
+ t6
1549
+ ] }), $[22] = inlineObject_0._key, $[23] = inlineObject_0._type, $[24] = props.attributes, $[25] = props.children, $[26] = t6, $[27] = t7) : t7 = $[27], t7;
1552
1550
  }
1553
1551
  function RenderChild$1({
1554
1552
  renderChild,
@@ -1764,19 +1762,23 @@ function _temp$3(s) {
1764
1762
  return s.context.schema;
1765
1763
  }
1766
1764
  function RenderSpan(props) {
1767
- const $ = c(35), slateEditor = useSlateStatic(), editorActor = useContext(EditorActorContext), legacySchema = useSelector(editorActor, _temp$2), spanRef = useRef(null), selectionState = useContext(SelectionStateContext), focused = selectionState.focusedChildKey === props.leaf._key;
1765
+ const $ = c(36), slateEditor = useSlateStatic(), editorActor = useContext(EditorActorContext), legacySchema = useSelector(editorActor, _temp$2), spanRef = useRef(null), parent = props.children.props.parent, block = parent && slateEditor.isTextBlock(parent) ? parent : void 0;
1768
1766
  let t0;
1769
- $[0] !== props.leaf._key || $[1] !== selectionState.selectedChildKeys ? (t0 = selectionState.selectedChildKeys.has(props.leaf._key), $[0] = props.leaf._key, $[1] = selectionState.selectedChildKeys, $[2] = t0) : t0 = $[2];
1770
- const selected = t0, parent = props.children.props.parent, block = parent && slateEditor.isTextBlock(parent) ? parent : void 0;
1771
- let t1;
1772
- $[3] !== block || $[4] !== props.leaf._key ? (t1 = block ? [{
1767
+ $[0] !== block || $[1] !== props.leaf._key ? (t0 = block ? [{
1773
1768
  _key: block._key
1774
1769
  }, "children", {
1775
1770
  _key: props.leaf._key
1776
- }] : void 0, $[3] = block, $[4] = props.leaf._key, $[5] = t1) : t1 = $[5];
1777
- const path = t1;
1771
+ }] : void 0, $[0] = block, $[1] = props.leaf._key, $[2] = t0) : t0 = $[2];
1772
+ const path = t0, selectionState = useContext(SelectionStateContext);
1773
+ let focused, t1;
1774
+ if ($[3] !== path || $[4] !== selectionState) {
1775
+ const serializedPath = path ? serializePath(path) : void 0;
1776
+ focused = serializedPath ? selectionState.focusedChildPath === serializedPath : !1, t1 = serializedPath ? selectionState.selectedChildPaths.has(serializedPath) : !1, $[3] = path, $[4] = selectionState, $[5] = focused, $[6] = t1;
1777
+ } else
1778
+ focused = $[5], t1 = $[6];
1779
+ const selected = t1;
1778
1780
  let annotationMarkDefs, children;
1779
- if ($[6] !== block || $[7] !== editorActor || $[8] !== focused || $[9] !== legacySchema || $[10] !== path || $[11] !== props.children || $[12] !== props.leaf.marks || $[13] !== props.renderAnnotation || $[14] !== props.renderDecorator || $[15] !== selected) {
1781
+ if ($[7] !== block || $[8] !== editorActor || $[9] !== focused || $[10] !== legacySchema || $[11] !== path || $[12] !== props.children || $[13] !== props.leaf.marks || $[14] !== props.renderAnnotation || $[15] !== props.renderDecorator || $[16] !== selected) {
1780
1782
  const decoratorSchemaTypes = editorActor.getSnapshot().context.schema.decorators.map(_temp2$1), decorators = [...new Set((props.leaf.marks ?? []).filter((mark) => decoratorSchemaTypes.includes(mark)))];
1781
1783
  annotationMarkDefs = (props.leaf.marks ?? []).flatMap((mark_0) => {
1782
1784
  if (decoratorSchemaTypes.includes(mark_0))
@@ -1792,24 +1794,24 @@ function RenderSpan(props) {
1792
1794
  const legacyAnnotationSchemaType = legacySchema.annotations.find((t) => t.name === annotationMarkDef._type);
1793
1795
  legacyAnnotationSchemaType && (block && path && props.renderAnnotation ? children = /* @__PURE__ */ jsx("span", { ref: spanRef, children: /* @__PURE__ */ jsx(RenderAnnotation, { renderAnnotation: props.renderAnnotation, block, editorElementRef: spanRef, focused, path, selected, schemaType: legacyAnnotationSchemaType, value: annotationMarkDef, type: legacyAnnotationSchemaType, children }) }) : children = /* @__PURE__ */ jsx("span", { ref: spanRef, children }));
1794
1796
  }
1795
- $[6] = block, $[7] = editorActor, $[8] = focused, $[9] = legacySchema, $[10] = path, $[11] = props.children, $[12] = props.leaf.marks, $[13] = props.renderAnnotation, $[14] = props.renderDecorator, $[15] = selected, $[16] = annotationMarkDefs, $[17] = children;
1797
+ $[7] = block, $[8] = editorActor, $[9] = focused, $[10] = legacySchema, $[11] = path, $[12] = props.children, $[13] = props.leaf.marks, $[14] = props.renderAnnotation, $[15] = props.renderDecorator, $[16] = selected, $[17] = annotationMarkDefs, $[18] = children;
1796
1798
  } else
1797
- annotationMarkDefs = $[16], children = $[17];
1799
+ annotationMarkDefs = $[17], children = $[18];
1798
1800
  if (block && path && props.renderChild) {
1799
1801
  let t22;
1800
- if ($[18] !== block.children || $[19] !== props.leaf) {
1802
+ if ($[19] !== block.children || $[20] !== props.leaf) {
1801
1803
  let t3;
1802
- $[21] !== props.leaf ? (t3 = (_child) => _child._key === props.leaf._key, $[21] = props.leaf, $[22] = t3) : t3 = $[22], t22 = block.children.find(t3), $[18] = block.children, $[19] = props.leaf, $[20] = t22;
1804
+ $[22] !== props.leaf ? (t3 = (_child) => _child._key === props.leaf._key, $[22] = props.leaf, $[23] = t3) : t3 = $[23], t22 = block.children.find(t3), $[19] = block.children, $[20] = props.leaf, $[21] = t22;
1803
1805
  } else
1804
- t22 = $[20];
1806
+ t22 = $[21];
1805
1807
  const child = t22;
1806
1808
  if (child) {
1807
1809
  let t3;
1808
- $[23] !== annotationMarkDefs || $[24] !== child || $[25] !== children || $[26] !== focused || $[27] !== legacySchema.span || $[28] !== path || $[29] !== props.renderChild || $[30] !== selected ? (t3 = /* @__PURE__ */ jsx(RenderChild, { renderChild: props.renderChild, annotations: annotationMarkDefs, editorElementRef: spanRef, focused, path, schemaType: legacySchema.span, selected, value: child, type: legacySchema.span, children }), $[23] = annotationMarkDefs, $[24] = child, $[25] = children, $[26] = focused, $[27] = legacySchema.span, $[28] = path, $[29] = props.renderChild, $[30] = selected, $[31] = t3) : t3 = $[31], children = t3;
1810
+ $[24] !== annotationMarkDefs || $[25] !== child || $[26] !== children || $[27] !== focused || $[28] !== legacySchema.span || $[29] !== path || $[30] !== props.renderChild || $[31] !== selected ? (t3 = /* @__PURE__ */ jsx(RenderChild, { renderChild: props.renderChild, annotations: annotationMarkDefs, editorElementRef: spanRef, focused, path, schemaType: legacySchema.span, selected, value: child, type: legacySchema.span, children }), $[24] = annotationMarkDefs, $[25] = child, $[26] = children, $[27] = focused, $[28] = legacySchema.span, $[29] = path, $[30] = props.renderChild, $[31] = selected, $[32] = t3) : t3 = $[32], children = t3;
1809
1811
  }
1810
1812
  }
1811
1813
  let t2;
1812
- return $[32] !== children || $[33] !== props.attributes ? (t2 = /* @__PURE__ */ jsx("span", { ...props.attributes, ref: spanRef, children }), $[32] = children, $[33] = props.attributes, $[34] = t2) : t2 = $[34], t2;
1814
+ return $[33] !== children || $[34] !== props.attributes ? (t2 = /* @__PURE__ */ jsx("span", { ...props.attributes, ref: spanRef, children }), $[33] = children, $[34] = props.attributes, $[35] = t2) : t2 = $[35], t2;
1813
1815
  }
1814
1816
  function _temp2$1(decorator) {
1815
1817
  return decorator.name;