mirror of
https://github.com/excalidraw/excalidraw
synced 2025-07-25 13:58:22 +08:00

* feat: update jotai in excalidraw package * feat: update jotai in excalidraw-app * fix: exports from excalidraw/jotai * fix: use isolated react hooks * test: use jotai provider in <Trans /> test * remove unused package * refactor & make safer --------- Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import React from "react";
|
|
import tunnel from "tunnel-rat";
|
|
import { createIsolation } from "jotai-scope";
|
|
|
|
export type Tunnel = ReturnType<typeof tunnel>;
|
|
|
|
type TunnelsContextValue = {
|
|
MainMenuTunnel: Tunnel;
|
|
WelcomeScreenMenuHintTunnel: Tunnel;
|
|
WelcomeScreenToolbarHintTunnel: Tunnel;
|
|
WelcomeScreenHelpHintTunnel: Tunnel;
|
|
WelcomeScreenCenterTunnel: Tunnel;
|
|
FooterCenterTunnel: Tunnel;
|
|
DefaultSidebarTriggerTunnel: Tunnel;
|
|
DefaultSidebarTabTriggersTunnel: Tunnel;
|
|
OverwriteConfirmDialogTunnel: Tunnel;
|
|
TTDDialogTriggerTunnel: Tunnel;
|
|
// this can be removed once we create jotai stores per each editor
|
|
// instance
|
|
tunnelsJotai: ReturnType<typeof createIsolation>;
|
|
};
|
|
|
|
export const TunnelsContext = React.createContext<TunnelsContextValue>(null!);
|
|
|
|
export const useTunnels = () => React.useContext(TunnelsContext);
|
|
|
|
const tunnelsJotai = createIsolation();
|
|
|
|
export const useInitializeTunnels = () => {
|
|
return React.useMemo((): TunnelsContextValue => {
|
|
return {
|
|
MainMenuTunnel: tunnel(),
|
|
WelcomeScreenMenuHintTunnel: tunnel(),
|
|
WelcomeScreenToolbarHintTunnel: tunnel(),
|
|
WelcomeScreenHelpHintTunnel: tunnel(),
|
|
WelcomeScreenCenterTunnel: tunnel(),
|
|
FooterCenterTunnel: tunnel(),
|
|
DefaultSidebarTriggerTunnel: tunnel(),
|
|
DefaultSidebarTabTriggersTunnel: tunnel(),
|
|
OverwriteConfirmDialogTunnel: tunnel(),
|
|
TTDDialogTriggerTunnel: tunnel(),
|
|
tunnelsJotai,
|
|
};
|
|
}, []);
|
|
};
|