@trafica/editor 1.0.24 → 1.0.26
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/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7830,6 +7830,43 @@ function EditorCore({
|
|
|
7830
7830
|
}) {
|
|
7831
7831
|
const containerRef = react.useRef(null);
|
|
7832
7832
|
const isRenderingRef = react.useRef(false);
|
|
7833
|
+
const scrollCaretIntoView = react.useCallback(() => {
|
|
7834
|
+
var _a, _b;
|
|
7835
|
+
const sel = window.getSelection();
|
|
7836
|
+
if (!sel || sel.rangeCount === 0) return;
|
|
7837
|
+
const range = sel.getRangeAt(0).cloneRange();
|
|
7838
|
+
range.collapse(true);
|
|
7839
|
+
const caretRect = range.getBoundingClientRect();
|
|
7840
|
+
let rect = caretRect;
|
|
7841
|
+
if (!rect || rect.top === 0 && rect.bottom === 0 && rect.left === 0) {
|
|
7842
|
+
const node = range.startContainer;
|
|
7843
|
+
const el = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
|
|
7844
|
+
if (el) rect = el.getBoundingClientRect();
|
|
7845
|
+
}
|
|
7846
|
+
if (!rect || rect.bottom === 0) return;
|
|
7847
|
+
let scrollEl = (_b = (_a = containerRef.current) == null ? void 0 : _a.parentElement) != null ? _b : null;
|
|
7848
|
+
while (scrollEl) {
|
|
7849
|
+
const style = window.getComputedStyle(scrollEl);
|
|
7850
|
+
const overflow = style.overflow + style.overflowY;
|
|
7851
|
+
if (/auto|scroll/.test(overflow)) break;
|
|
7852
|
+
scrollEl = scrollEl.parentElement;
|
|
7853
|
+
}
|
|
7854
|
+
const PADDING = 24;
|
|
7855
|
+
if (scrollEl) {
|
|
7856
|
+
const containerRect = scrollEl.getBoundingClientRect();
|
|
7857
|
+
if (rect.bottom > containerRect.bottom - PADDING) {
|
|
7858
|
+
scrollEl.scrollBy({ top: rect.bottom - containerRect.bottom + PADDING, behavior: "smooth" });
|
|
7859
|
+
} else if (rect.top < containerRect.top + PADDING) {
|
|
7860
|
+
scrollEl.scrollBy({ top: rect.top - containerRect.top - PADDING, behavior: "smooth" });
|
|
7861
|
+
}
|
|
7862
|
+
} else {
|
|
7863
|
+
if (rect.bottom > window.innerHeight - PADDING) {
|
|
7864
|
+
window.scrollBy({ top: rect.bottom - window.innerHeight + PADDING, behavior: "smooth" });
|
|
7865
|
+
} else if (rect.top < PADDING) {
|
|
7866
|
+
window.scrollBy({ top: rect.top - PADDING, behavior: "smooth" });
|
|
7867
|
+
}
|
|
7868
|
+
}
|
|
7869
|
+
}, []);
|
|
7833
7870
|
const isComposingRef = react.useRef(false);
|
|
7834
7871
|
const stateRef = react.useRef(engine.getState());
|
|
7835
7872
|
const [selectedImagePath, setSelectedImagePath] = react.useState(null);
|
|
@@ -7892,6 +7929,7 @@ function EditorCore({
|
|
|
7892
7929
|
}
|
|
7893
7930
|
if (state.selection) {
|
|
7894
7931
|
restoreSelection(container, state.selection);
|
|
7932
|
+
scrollCaretIntoView();
|
|
7895
7933
|
}
|
|
7896
7934
|
isRenderingRef.current = false;
|
|
7897
7935
|
if (onHTMLChange) {
|
|
@@ -7905,6 +7943,7 @@ function EditorCore({
|
|
|
7905
7943
|
const container = containerRef.current;
|
|
7906
7944
|
if (!container || !state.selection) return;
|
|
7907
7945
|
restoreSelection(container, state.selection);
|
|
7946
|
+
scrollCaretIntoView();
|
|
7908
7947
|
}, [state.selection]);
|
|
7909
7948
|
react.useEffect(() => {
|
|
7910
7949
|
const container = containerRef.current;
|