slate-react 0.110.0 → 0.110.1-20240912214053
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/dist/components/editable.d.ts.map +1 -1
- package/dist/index.es.js +46 -13
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +63 -13
- package/dist/index.js.map +1 -1
- package/dist/plugin/react-editor.d.ts +5 -0
- package/dist/plugin/react-editor.d.ts.map +1 -1
- package/dist/slate-react.js +63 -13
- package/dist/slate-react.min.js +1 -1
- package/dist/utils/dom.d.ts +8 -0
- package/dist/utils/dom.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editable.d.ts","sourceRoot":"","sources":["../../../../packages/slate-react/src/components/editable.tsx"],"names":[],"mappings":"AAGA,OAAO,KASN,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAE3B,OAAO,EAEL,OAAO,EAEP,SAAS,EAET,KAAK,EACL,IAAI,EAEL,MAAM,OAAO,CAAA;AAQd,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEpD,OAAO,EAEL,QAAQ,EAQT,MAAM,cAAc,CAAA;AAuCrB;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE;QACV,iBAAiB,EAAE,SAAS,CAAA;QAC5B,mBAAmB,CAAC,EAAE,IAAI,CAAA;QAC1B,iBAAiB,CAAC,EAAE,IAAI,CAAA;QACxB,GAAG,CAAC,EAAE,KAAK,CAAA;QACX,GAAG,EAAE,GAAG,CAAA;KACT,CAAA;CACF;AAED;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,GAAG,CAAA;IACb,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE;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
package/dist/index.es.js
CHANGED
|
@@ -179,6 +179,7 @@ var MARK_PLACEHOLDER_SYMBOL = Symbol('mark-placeholder');
|
|
|
179
179
|
// COMPAT: This is required to prevent TypeScript aliases from doing some very
|
|
180
180
|
// weird things for Slate's types with the same name as globals. (2019/11/27)
|
|
181
181
|
// https://github.com/microsoft/TypeScript/issues/35002
|
|
182
|
+
var DOMNode = globalThis.Node;
|
|
182
183
|
var DOMText = globalThis.Text;
|
|
183
184
|
/**
|
|
184
185
|
* Returns the host window of a DOM node
|
|
@@ -397,6 +398,14 @@ var getActiveElement = () => {
|
|
|
397
398
|
}
|
|
398
399
|
return activeElement;
|
|
399
400
|
};
|
|
401
|
+
/**
|
|
402
|
+
* @returns `true` if `otherNode` is before `node` in the document; otherwise, `false`.
|
|
403
|
+
*/
|
|
404
|
+
var isBefore = (node, otherNode) => Boolean(node.compareDocumentPosition(otherNode) & DOMNode.DOCUMENT_POSITION_PRECEDING);
|
|
405
|
+
/**
|
|
406
|
+
* @returns `true` if `otherNode` is after `node` in the document; otherwise, `false`.
|
|
407
|
+
*/
|
|
408
|
+
var isAfter = (node, otherNode) => Boolean(node.compareDocumentPosition(otherNode) & DOMNode.DOCUMENT_POSITION_FOLLOWING);
|
|
400
409
|
|
|
401
410
|
/**
|
|
402
411
|
* An auto-incrementing identifier for keys.
|
|
@@ -742,7 +751,8 @@ var ReactEditor = {
|
|
|
742
751
|
toSlatePoint: (editor, domPoint, options) => {
|
|
743
752
|
var {
|
|
744
753
|
exactMatch,
|
|
745
|
-
suppressThrow
|
|
754
|
+
suppressThrow,
|
|
755
|
+
searchDirection = 'backward'
|
|
746
756
|
} = options;
|
|
747
757
|
var [nearestNode, nearestOffset] = exactMatch ? domPoint : normalizeDOMPoint(domPoint);
|
|
748
758
|
var parentNode = nearestNode.parentNode;
|
|
@@ -757,6 +767,8 @@ var ReactEditor = {
|
|
|
757
767
|
// if this editor is within a void node of another editor ("nested editors", like in
|
|
758
768
|
// the "Editable Voids" example on the docs site).
|
|
759
769
|
var voidNode = potentialVoidNode && editorEl.contains(potentialVoidNode) ? potentialVoidNode : null;
|
|
770
|
+
var potentialNonEditableNode = parentNode.closest('[contenteditable="false"]');
|
|
771
|
+
var nonEditableNode = potentialNonEditableNode && editorEl.contains(potentialNonEditableNode) ? potentialNonEditableNode : null;
|
|
760
772
|
var leafNode = parentNode.closest('[data-slate-leaf]');
|
|
761
773
|
var domNode = null;
|
|
762
774
|
// Calculate how far into the text node the `nearestNode` is, so that we
|
|
@@ -812,6 +824,33 @@ var ReactEditor = {
|
|
|
812
824
|
offset -= el.textContent.length;
|
|
813
825
|
});
|
|
814
826
|
}
|
|
827
|
+
} else if (nonEditableNode) {
|
|
828
|
+
// Find the edge of the nearest leaf in `searchDirection`
|
|
829
|
+
var getLeafNodes = node => node ? node.querySelectorAll(
|
|
830
|
+
// Exclude leaf nodes in nested editors
|
|
831
|
+
'[data-slate-leaf]:not(:scope [data-slate-editor] [data-slate-leaf])') : [];
|
|
832
|
+
var elementNode = nonEditableNode.closest('[data-slate-node="element"]');
|
|
833
|
+
if (searchDirection === 'forward') {
|
|
834
|
+
var _leafNodes$find;
|
|
835
|
+
var _leafNodes = [...getLeafNodes(elementNode), ...getLeafNodes(elementNode === null || elementNode === void 0 ? void 0 : elementNode.nextElementSibling)];
|
|
836
|
+
leafNode = (_leafNodes$find = _leafNodes.find(leaf => isAfter(nonEditableNode, leaf))) !== null && _leafNodes$find !== void 0 ? _leafNodes$find : null;
|
|
837
|
+
} else {
|
|
838
|
+
var _leafNodes2$findLast;
|
|
839
|
+
var _leafNodes2 = [...getLeafNodes(elementNode === null || elementNode === void 0 ? void 0 : elementNode.previousElementSibling), ...getLeafNodes(elementNode)];
|
|
840
|
+
leafNode = (_leafNodes2$findLast = _leafNodes2.findLast(leaf => isBefore(nonEditableNode, leaf))) !== null && _leafNodes2$findLast !== void 0 ? _leafNodes2$findLast : null;
|
|
841
|
+
}
|
|
842
|
+
if (leafNode) {
|
|
843
|
+
textNode = leafNode.closest('[data-slate-node="text"]');
|
|
844
|
+
domNode = leafNode;
|
|
845
|
+
if (searchDirection === 'forward') {
|
|
846
|
+
offset = 0;
|
|
847
|
+
} else {
|
|
848
|
+
offset = domNode.textContent.length;
|
|
849
|
+
domNode.querySelectorAll('[data-slate-zero-width]').forEach(el => {
|
|
850
|
+
offset -= el.textContent.length;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
}
|
|
815
854
|
}
|
|
816
855
|
if (domNode && offset === domNode.textContent.length &&
|
|
817
856
|
// COMPAT: Android IMEs might remove the zero width space while composing,
|
|
@@ -965,14 +1004,6 @@ var ReactEditor = {
|
|
|
965
1004
|
if (IS_FIREFOX && (_focusNode$textConten = focusNode.textContent) !== null && _focusNode$textConten !== void 0 && _focusNode$textConten.endsWith('\n\n') && focusOffset === focusNode.textContent.length) {
|
|
966
1005
|
focusOffset--;
|
|
967
1006
|
}
|
|
968
|
-
// COMPAT: Triple-clicking a word in chrome will sometimes place the focus
|
|
969
|
-
// inside a `contenteditable="false"` DOM node following the word, which
|
|
970
|
-
// will cause `toSlatePoint` to throw an error. (2023/03/07)
|
|
971
|
-
if ('getAttribute' in focusNode && focusNode.getAttribute('contenteditable') === 'false' && focusNode.getAttribute('data-slate-void') !== 'true') {
|
|
972
|
-
var _anchorNode$textConte;
|
|
973
|
-
focusNode = anchorNode;
|
|
974
|
-
focusOffset = ((_anchorNode$textConte = anchorNode.textContent) === null || _anchorNode$textConte === void 0 ? void 0 : _anchorNode$textConte.length) || 0;
|
|
975
|
-
}
|
|
976
1007
|
var anchor = ReactEditor.toSlatePoint(editor, [anchorNode, anchorOffset], {
|
|
977
1008
|
exactMatch,
|
|
978
1009
|
suppressThrow
|
|
@@ -980,9 +1011,11 @@ var ReactEditor = {
|
|
|
980
1011
|
if (!anchor) {
|
|
981
1012
|
return null;
|
|
982
1013
|
}
|
|
1014
|
+
var focusBeforeAnchor = isBefore(anchorNode, focusNode) || anchorNode === focusNode && focusOffset < anchorOffset;
|
|
983
1015
|
var focus = isCollapsed ? anchor : ReactEditor.toSlatePoint(editor, [focusNode, focusOffset], {
|
|
984
1016
|
exactMatch,
|
|
985
|
-
suppressThrow
|
|
1017
|
+
suppressThrow,
|
|
1018
|
+
searchDirection: focusBeforeAnchor ? 'forward' : 'backward'
|
|
986
1019
|
});
|
|
987
1020
|
if (!focus) {
|
|
988
1021
|
return null;
|
|
@@ -2949,8 +2982,8 @@ var Editable = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
|
2949
2982
|
focusNode
|
|
2950
2983
|
} = domSelection;
|
|
2951
2984
|
var anchorNodeSelectable = ReactEditor.hasEditableTarget(editor, anchorNode) || ReactEditor.isTargetInsideNonReadonlyVoid(editor, anchorNode);
|
|
2952
|
-
var
|
|
2953
|
-
if (anchorNodeSelectable &&
|
|
2985
|
+
var focusNodeInEditor = ReactEditor.hasTarget(editor, focusNode);
|
|
2986
|
+
if (anchorNodeSelectable && focusNodeInEditor) {
|
|
2954
2987
|
var range = ReactEditor.toSlateRange(editor, domSelection, {
|
|
2955
2988
|
exactMatch: false,
|
|
2956
2989
|
suppressThrow: true
|
|
@@ -2964,7 +2997,7 @@ var Editable = /*#__PURE__*/forwardRef((props, forwardedRef) => {
|
|
|
2964
2997
|
}
|
|
2965
2998
|
}
|
|
2966
2999
|
// Deselect the editor if the dom selection is not selectable in readonly mode
|
|
2967
|
-
if (readOnly && (!anchorNodeSelectable || !
|
|
3000
|
+
if (readOnly && (!anchorNodeSelectable || !focusNodeInEditor)) {
|
|
2968
3001
|
Transforms.deselect(editor);
|
|
2969
3002
|
}
|
|
2970
3003
|
}
|