import { useLocal } from "@/utils/use-local"; import { FC, useEffect, useRef } from "react"; import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; import { refreshBread } from "./MDBread"; import { MDHeader } from "./MDHeader"; import { MDTab, should_show_tab } from "./MDTab"; import { masterDetailApplyParams, masterDetailParseHash as masterDetailParseParams, } from "./utils/md-hash"; import { masterDetailInit, masterDetailSelected } from "./utils/md-init"; import { MDLocal, MDLocalInternal, MDRef } from "./utils/typings"; export const MasterDetail: FC<{ child: any; PassProp: any; name: string; mode: "full" | "h-split" | "v-split"; show_head: "always" | "only-master" | "only-child" | "hidden"; tab_mode: "h-tab" | "v-tab" | "hidden"; editor_tab: string; gen_fields: any; gen_table: string; on_init: (md: MDLocal) => void; }> = ({ PassProp, child, name, mode, show_head, tab_mode, editor_tab, gen_fields, gen_table, on_init, }) => { const _ref = useRef({ PassProp, child }); const md = useLocal({ name, actions: [], breadcrumb: [], selected: null, tab: { active: "", list: [], }, internal: { action_should_refresh: true }, childs: {}, props: { mode, show_head, tab_mode, editor_tab, gen_fields, gen_table, on_init, }, params: { hash: {}, tabs: {}, parse: () => { masterDetailParseParams(md); }, apply: () => { masterDetailApplyParams(md); }, }, master: { internal: null, render() {} }, }); const local = useLocal({ init: false }); if (isEditor) { md.props.mode = mode; md.props.show_head = show_head; md.props.tab_mode = tab_mode; md.props.editor_tab = editor_tab; md.props.gen_fields = gen_fields; md.props.gen_table = gen_table; md.props.on_init = on_init; } _ref.current.PassProp = PassProp; _ref.current.child = child; useEffect(() => { local.init = false; local.render(); }, [editor_tab]); refreshBread(md); if (!local.init || isEditor) { local.init = true; masterDetailInit(md, child, editor_tab); masterDetailSelected(md); } return (
{md.props.show_head === "always" && ( )} {md.props.mode === "full" && } {md.props.mode === "v-split" && }
); }; const ModeFull: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { if (should_show_tab(md)) { return ; } return ( <> {!md.selected && } {md.selected && } ); }; const ModeVSplit: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { return (
<> { if (e < 80) { localStorage.setItem(`prasi-md-h-${md.name}`, e.toString()); } }} >
); }; const Master: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => { const PassProp = mdr.PassProp; return ( <> {md.props.show_head === "only-master" && } {md.master.internal} ); };