@portabletext/editor 4.3.8 → 4.3.9
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 +75 -76
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
1366
|
-
|
|
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
|
|
1384
|
-
|
|
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
|
|
1387
|
-
isCollapsed &&
|
|
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
|
-
|
|
1402
|
-
|
|
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.
|
|
1418
|
+
if (prev.focusedChildPath !== next.focusedChildPath)
|
|
1413
1419
|
return !1;
|
|
1414
|
-
if (prev.
|
|
1415
|
-
if (prev.
|
|
1420
|
+
if (prev.selectedChildPaths !== next.selectedChildPaths) {
|
|
1421
|
+
if (prev.selectedChildPaths.size !== next.selectedChildPaths.size)
|
|
1416
1422
|
return !1;
|
|
1417
|
-
for (const
|
|
1418
|
-
if (!next.
|
|
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
|
|
1427
|
-
if (!next.selectedBlockKeys.has(
|
|
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.
|
|
1439
|
+
return serializePath(child.path);
|
|
1434
1440
|
}
|
|
1435
1441
|
function RenderBlockObject(props) {
|
|
1436
1442
|
const $ = c(34), blockObjectRef = useRef(null), {
|
|
@@ -1496,59 +1502,48 @@ function RenderBlock$1({
|
|
|
1496
1502
|
});
|
|
1497
1503
|
}
|
|
1498
1504
|
function RenderInlineObject(props) {
|
|
1499
|
-
const $ = c(
|
|
1500
|
-
selectedChildKeys,
|
|
1501
|
-
focusedChildKey
|
|
1502
|
-
} = useContext(SelectionStateContext);
|
|
1505
|
+
const $ = c(26), inlineObjectRef = useRef(null), slateEditor = useSlateStatic();
|
|
1503
1506
|
let t0;
|
|
1504
|
-
$[0] !== props.element.
|
|
1505
|
-
|
|
1506
|
-
|
|
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
|
-
|
|
1512
|
-
const legacySchemaType =
|
|
1511
|
+
t0 = $[2];
|
|
1512
|
+
const legacySchemaType = t0;
|
|
1513
1513
|
legacySchemaType || console.error(`Unable to find Inline Object "${props.element._type}" in Schema`);
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
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
|
-
|
|
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 = {
|
|
1532
|
-
_key: props.element._key,
|
|
1533
|
-
_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 = {
|
|
1539
|
-
display: "inline-block"
|
|
1540
|
-
}, $[17] = t6) : t6 = $[17];
|
|
1541
|
-
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: [{
|
|
1522
|
+
const path = block ? [{
|
|
1543
1523
|
_key: block._key
|
|
1544
1524
|
}, "children", {
|
|
1545
1525
|
_key: props.element._key
|
|
1546
|
-
}]
|
|
1547
|
-
let
|
|
1548
|
-
|
|
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 = {
|
|
1531
|
+
_key: props.element._key,
|
|
1532
|
+
_type: props.element._type,
|
|
1533
|
+
...t1
|
|
1534
|
+
}, $[7] = props.element._key, $[8] = props.element._type, $[9] = t1, $[10] = t2) : t2 = $[10];
|
|
1535
|
+
const inlineObject_0 = t2, t3 = !props.readOnly;
|
|
1536
|
+
let t4;
|
|
1537
|
+
$[11] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
|
|
1538
|
+
display: "inline-block"
|
|
1539
|
+
}, $[11] = t4) : t4 = $[11];
|
|
1540
|
+
let t5;
|
|
1541
|
+
$[12] !== focused || $[13] !== inlineObject_0 || $[14] !== legacySchemaType || $[15] !== path || $[16] !== props.renderChild || $[17] !== selected ? (t5 = /* @__PURE__ */ jsx("span", { ref: inlineObjectRef, style: t4, children: 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];
|
|
1542
|
+
let t6;
|
|
1543
|
+
return $[19] !== inlineObject_0._key || $[20] !== inlineObject_0._type || $[21] !== props.attributes || $[22] !== props.children || $[23] !== t3 || $[24] !== t5 ? (t6 = /* @__PURE__ */ jsxs("span", { ...props.attributes, draggable: t3, className: "pt-inline-object", "data-child-key": inlineObject_0._key, "data-child-name": inlineObject_0._type, "data-child-type": "object", children: [
|
|
1549
1544
|
props.children,
|
|
1550
|
-
|
|
1551
|
-
] }), $[
|
|
1545
|
+
t5
|
|
1546
|
+
] }), $[19] = inlineObject_0._key, $[20] = inlineObject_0._type, $[21] = props.attributes, $[22] = props.children, $[23] = t3, $[24] = t5, $[25] = t6) : t6 = $[25], t6;
|
|
1552
1547
|
}
|
|
1553
1548
|
function RenderChild$1({
|
|
1554
1549
|
renderChild,
|
|
@@ -1764,19 +1759,23 @@ function _temp$3(s) {
|
|
|
1764
1759
|
return s.context.schema;
|
|
1765
1760
|
}
|
|
1766
1761
|
function RenderSpan(props) {
|
|
1767
|
-
const $ = c(
|
|
1762
|
+
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
1763
|
let t0;
|
|
1769
|
-
$[0] !==
|
|
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 ? [{
|
|
1764
|
+
$[0] !== block || $[1] !== props.leaf._key ? (t0 = block ? [{
|
|
1773
1765
|
_key: block._key
|
|
1774
1766
|
}, "children", {
|
|
1775
1767
|
_key: props.leaf._key
|
|
1776
|
-
}] : void 0, $[
|
|
1777
|
-
const path =
|
|
1768
|
+
}] : void 0, $[0] = block, $[1] = props.leaf._key, $[2] = t0) : t0 = $[2];
|
|
1769
|
+
const path = t0, selectionState = useContext(SelectionStateContext);
|
|
1770
|
+
let focused, t1;
|
|
1771
|
+
if ($[3] !== path || $[4] !== selectionState) {
|
|
1772
|
+
const serializedPath = path ? serializePath(path) : void 0;
|
|
1773
|
+
focused = serializedPath ? selectionState.focusedChildPath === serializedPath : !1, t1 = serializedPath ? selectionState.selectedChildPaths.has(serializedPath) : !1, $[3] = path, $[4] = selectionState, $[5] = focused, $[6] = t1;
|
|
1774
|
+
} else
|
|
1775
|
+
focused = $[5], t1 = $[6];
|
|
1776
|
+
const selected = t1;
|
|
1778
1777
|
let annotationMarkDefs, children;
|
|
1779
|
-
if ($[
|
|
1778
|
+
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
1779
|
const decoratorSchemaTypes = editorActor.getSnapshot().context.schema.decorators.map(_temp2$1), decorators = [...new Set((props.leaf.marks ?? []).filter((mark) => decoratorSchemaTypes.includes(mark)))];
|
|
1781
1780
|
annotationMarkDefs = (props.leaf.marks ?? []).flatMap((mark_0) => {
|
|
1782
1781
|
if (decoratorSchemaTypes.includes(mark_0))
|
|
@@ -1792,24 +1791,24 @@ function RenderSpan(props) {
|
|
|
1792
1791
|
const legacyAnnotationSchemaType = legacySchema.annotations.find((t) => t.name === annotationMarkDef._type);
|
|
1793
1792
|
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
1793
|
}
|
|
1795
|
-
$[
|
|
1794
|
+
$[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
1795
|
} else
|
|
1797
|
-
annotationMarkDefs = $[
|
|
1796
|
+
annotationMarkDefs = $[17], children = $[18];
|
|
1798
1797
|
if (block && path && props.renderChild) {
|
|
1799
1798
|
let t22;
|
|
1800
|
-
if ($[
|
|
1799
|
+
if ($[19] !== block.children || $[20] !== props.leaf) {
|
|
1801
1800
|
let t3;
|
|
1802
|
-
$[
|
|
1801
|
+
$[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
1802
|
} else
|
|
1804
|
-
t22 = $[
|
|
1803
|
+
t22 = $[21];
|
|
1805
1804
|
const child = t22;
|
|
1806
1805
|
if (child) {
|
|
1807
1806
|
let t3;
|
|
1808
|
-
$[
|
|
1807
|
+
$[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
1808
|
}
|
|
1810
1809
|
}
|
|
1811
1810
|
let t2;
|
|
1812
|
-
return $[
|
|
1811
|
+
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
1812
|
}
|
|
1814
1813
|
function _temp2$1(decorator) {
|
|
1815
1814
|
return decorator.name;
|