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