git save current version as 0.02

This commit is contained in:
liaibo
2025-11-29 09:35:36 +08:00
parent d350b02fba
commit e5ae2c173e
4 changed files with 217 additions and 25 deletions
@@ -41,6 +41,15 @@ const isPrintableKey = (event: KeyboardEvent) => {
return event.key === "Process" || event.key === "Unidentified";
};
const isInlineEditorVisible = () => {
const inputBox = document.getElementById("luckysheet-input-box");
if (!inputBox) {
return false;
}
const style = window.getComputedStyle(inputBox);
return style.top !== "-10000px" && style.display !== "none";
};
const isElementInsideEditorToolbar = (element: HTMLElement | null) => {
if (!element) return false;
if (element.closest(".luckysheet-wa-editor")) {
@@ -209,11 +218,23 @@ const FullScreenTableEditor: React.FC<FullScreenTableEditorProps> = ({ tableId,
}, [isLuckysheetReady]);
const focusLuckysheetEditor = useCallback(() => {
requestAnimationFrame(() => {
const applyFocus = () => {
const editor = document.getElementById("luckysheet-rich-text-editor");
if (editor && typeof editor.focus === "function") {
editor.focus();
const selection = window.getSelection();
if (selection && editor.childNodes.length > 0) {
const range = document.createRange();
range.selectNodeContents(editor);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
}
}
};
requestAnimationFrame(() => {
applyFocus();
setTimeout(applyFocus, 0);
});
}, []);
@@ -325,18 +346,53 @@ const FullScreenTableEditor: React.FC<FullScreenTableEditorProps> = ({ tableId,
if (!isSingleCellSelection(range)) {
return;
}
setTimeout(() => {
const editor = document.getElementById("luckysheet-rich-text-editor");
if (editor && document.activeElement === editor) {
return;
}
luckysheetInstance.enterEditMode();
focusLuckysheetEditor();
}, 0);
setTimeout(() => {
const editor = document.getElementById("luckysheet-rich-text-editor");
if (editor && document.activeElement === editor && isInlineEditorVisible()) {
return;
}
luckysheetInstance.enterEditMode();
focusLuckysheetEditor();
}, 0);
},
[focusLuckysheetEditor, isSingleCellSelection],
);
useEffect(() => {
if (!isLuckysheetReady) {
return;
}
const container = document.getElementById(LUCKY_SHEET_CONTAINER_ID);
if (!container) {
return;
}
const handlePointerUp = (event: PointerEvent | MouseEvent | TouchEvent) => {
const target = event.target instanceof Node ? event.target : null;
if (target && !container.contains(target)) {
return;
}
requestAnimationFrame(() => {
const selection = window.luckysheet?.getluckysheet_select_save?.();
if (!selection) {
return;
}
const normalized = Array.isArray(selection)
? (selection as LuckysheetSelection[])
: [selection as LuckysheetSelection];
tryEnterSingleClickEdit(normalized);
});
};
const events: Array<keyof DocumentEventMap> = ["pointerup", "mouseup", "touchend"];
events.forEach((eventName) => {
container.addEventListener(eventName, handlePointerUp, true);
});
return () => {
events.forEach((eventName) => {
container.removeEventListener(eventName, handlePointerUp, true);
});
};
}, [isLuckysheetReady, tryEnterSingleClickEdit]);
// Luckysheet 初始化和清理
useEffect(() => {
if (!isLuckysheetReady || !tableData || !containerRef.current || !window.luckysheet) {
@@ -372,6 +428,8 @@ const FullScreenTableEditor: React.FC<FullScreenTableEditorProps> = ({ tableId,
allowUpdate: false,
gridKey,
loadUrl,
pointEdit: true,
pointEditZoom: typeof window !== "undefined" && window.devicePixelRatio ? window.devicePixelRatio : 1,
uploadImage: async (file: File) => {
const formData = new FormData();
formData.append("image", file);