34 lines
823 B
TypeScript
34 lines
823 B
TypeScript
"use client";
|
|
|
|
import { create } from "zustand";
|
|
|
|
type OnlyOfficeAiBridgeState = {
|
|
pluginReady: boolean;
|
|
targetOrigin: string;
|
|
targetWindow: Window | null;
|
|
lastReadyAt: number | null;
|
|
captureReady: (payload: { targetOrigin: string; targetWindow: Window | null }) => void;
|
|
reset: () => void;
|
|
};
|
|
|
|
export const useOnlyOfficeAiBridgeStore = create<OnlyOfficeAiBridgeState>((set) => ({
|
|
pluginReady: false,
|
|
targetOrigin: "*",
|
|
targetWindow: null,
|
|
lastReadyAt: null,
|
|
captureReady: ({ targetOrigin, targetWindow }) =>
|
|
set({
|
|
pluginReady: Boolean(targetWindow),
|
|
targetOrigin: targetOrigin || "*",
|
|
targetWindow,
|
|
lastReadyAt: Date.now(),
|
|
}),
|
|
reset: () =>
|
|
set({
|
|
pluginReady: false,
|
|
targetOrigin: "*",
|
|
targetWindow: null,
|
|
lastReadyAt: null,
|
|
}),
|
|
}));
|