Initial QOffice implementation

This commit is contained in:
Курнат Андрей
2026-06-01 05:31:05 +03:00
commit 9bf4dd3672
44 changed files with 16854 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { useEffect, useRef } from "react";
export type QOfficeCommand = "open" | "save" | "export-pdf" | "print";
export type QOfficeCommandHandlers = Partial<Record<QOfficeCommand, () => void | Promise<void>>>;
export function useQOfficeCommand(handlers: QOfficeCommandHandlers) {
const handlersRef = useRef(handlers);
useEffect(() => {
handlersRef.current = handlers;
}, [handlers]);
useEffect(() => {
function onCommand(event: WindowEventMap["qoffice-command"]) {
const command = event.detail.command;
const handler = handlersRef.current[command];
if (handler) {
void handler();
}
}
window.addEventListener("qoffice-command", onCommand);
return () => window.removeEventListener("qoffice-command", onCommand);
}, []);
}