{"version":3,"file":"pageTitle.mjs","names":["useEffect","useState","create","PageTitleState","entries","Record","setEntry","id","title","removeEntry","usePageTitleStore","set","state","selectPageTitle","ids","Object","keys","map","Number","length","undefined","Math","max","nextInstanceId","usePageTitle","PageTitleProps","children","PageTitle","t0"],"sources":["../../src/shell/pageTitle.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { create } from 'zustand';\n\ninterface PageTitleState {\n  entries: Record<number, string>;\n  setEntry: (id: number, title: string) => void;\n  removeEntry: (id: number) => void;\n}\n\nexport const usePageTitleStore = create<PageTitleState>((set) => ({\n  entries: {},\n  setEntry: (id, title) =>\n    set((state) => ({ entries: { ...state.entries, [id]: title } })),\n  removeEntry: (id) =>\n    set((state) => {\n      const entries = { ...state.entries };\n      delete entries[id];\n      return { entries };\n    }),\n}));\n\n/**\n * The winning title is the deepest-rendered instance: ids are assigned during\n * render (parents render before children), so the highest id is the most\n * deeply nested / most recently mounted `PageTitle`.\n */\nexport const selectPageTitle = (state: PageTitleState): string | undefined => {\n  const ids = Object.keys(state.entries).map(Number);\n  if (!ids.length) return undefined;\n  return state.entries[Math.max(...ids)];\n};\n\nlet nextInstanceId = 1;\n\n/**\n * Sets the browser tab title for the page, react-helmet style: render it\n * anywhere; the deepest instance wins, and unmounting falls back to the next\n * one up (so a nested route's title overrides its parent layout's title only\n * while mounted). The shell appends the site name automatically.\n *\n * Passing `undefined`/empty leaves the current title untouched, which allows\n * deferring until data loads: `usePageTitle(record?.name)`.\n */\nexport const usePageTitle = (title?: string | null) => {\n  const [id] = useState(() => nextInstanceId++);\n  const setEntry = usePageTitleStore((state) => state.setEntry);\n  const removeEntry = usePageTitleStore((state) => state.removeEntry);\n\n  useEffect(() => {\n    if (!title) return undefined;\n    setEntry(id, title);\n    return () => removeEntry(id);\n  }, [id, title, setEntry, removeEntry]);\n};\n\nexport interface PageTitleProps {\n  /** The page's tab title. String children work too: `<PageTitle>Home</PageTitle>` */\n  title?: string;\n  children?: string;\n}\n\n/**\n * Component form of {@link usePageTitle}. Renders nothing.\n *\n * ```jsx\n * <PageTitle>Timesheets</PageTitle>          // parent route\n * <PageTitle title={`Timesheet ${id}`} />    // nested route wins while mounted\n * ```\n */\nexport const PageTitle = ({ title, children }: PageTitleProps) => {\n  usePageTitle(title ?? (typeof children === 'string' ? children : undefined));\n  return null;\n};\n"],"mappings":";;;AASA,MAAaU,oBAAoBR,QAAwBS,SAAS;CAChEP,SAAS,EAAE;CACXE,WAAWC,IAAIC,UACbG,KAAKC,WAAW,EAAER,SAAS;EAAE,GAAGQ,MAAMR;GAAUG,KAAKC;EAAM,EAAG,EAAE;CAClEC,cAAcF,OACZI,KAAKC,UAAU;EACb,MAAMR,UAAU,EAAE,GAAGQ,MAAMR,SAAS;AACpC,SAAOA,QAAQG;AACf,SAAO,EAAEH,SAAS;GACnB;CACJ,EAAE;;;;;;AAOH,MAAaS,mBAAmBD,UAA8C;CAC5E,MAAME,MAAMC,OAAOC,KAAKJ,MAAMR,QAAQ,CAACa,IAAIC,OAAO;AAClD,KAAI,CAACJ,IAAIK,OAAQ,QAAOC,KAAAA;AACxB,QAAOR,MAAMR,QAAQiB,KAAKC,IAAI,GAAGR,IAAI;;AAGvC,IAAIS,iBAAiB;;;;;;;;;;AAWrB,MAAaC,gBAAgBhB,UAA0B;CACrD,MAAM,CAACD,MAAMN,eAAesB,iBAAiB;CAC7C,MAAMjB,WAAWI,mBAAmBE,UAAUA,MAAMN,SAAS;CAC7D,MAAMG,cAAcC,mBAAmBE,YAAUA,QAAMH,YAAY;AAEnET,iBAAgB;AACd,MAAI,CAACQ,MAAO,QAAOY,KAAAA;AACnBd,WAASC,IAAIC,MAAM;AACnB,eAAaC,YAAYF,GAAG;IAC3B;EAACA;EAAIC;EAAOF;EAAUG;EAAY,CAAC;;;;;;;;;;AAiBxC,MAAakB,aAAYC,OAAA;CAAC,MAAA,EAAApB,OAAAkB,aAAAE;AACxBJ,cAAahB,UAAU,OAAOkB,aAAa,WAApBA,WAAAN,KAAAA,GAAqD;AAAA,QACrE"}