@nswds/app 6.0.6 → 6.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -5987,6 +5987,12 @@ declare function ThemeSelector(props: ThemeSelectorProps): react.JSX.Element;
5987
5987
  declare function ThemeSwitcher(): react.JSX.Element;
5988
5988
 
5989
5989
  declare const TocContext: react.Context<TocContextType>;
5990
+ /**
5991
+ * Turns the table of contents back on for each page. It must not do that with
5992
+ * `key={pathname}`: a key remounts everything below it, and this provider wraps
5993
+ * the whole app, so every client-side navigation would throw away and rebuild
5994
+ * every layout and page, along with their state.
5995
+ */
5990
5996
  declare function TocProvider({ children }: {
5991
5997
  children: ReactNode;
5992
5998
  }): react.JSX.Element;
package/dist/index.d.ts CHANGED
@@ -5987,6 +5987,12 @@ declare function ThemeSelector(props: ThemeSelectorProps): react.JSX.Element;
5987
5987
  declare function ThemeSwitcher(): react.JSX.Element;
5988
5988
 
5989
5989
  declare const TocContext: react.Context<TocContextType>;
5990
+ /**
5991
+ * Turns the table of contents back on for each page. It must not do that with
5992
+ * `key={pathname}`: a key remounts everything below it, and this provider wraps
5993
+ * the whole app, so every client-side navigation would throw away and rebuild
5994
+ * every layout and page, along with their state.
5995
+ */
5990
5996
  declare function TocProvider({ children }: {
5991
5997
  children: ReactNode;
5992
5998
  }): react.JSX.Element;
package/dist/index.js CHANGED
@@ -14436,7 +14436,7 @@ function FormatToggle({ format, setFormat }) {
14436
14436
 
14437
14437
  // package.json
14438
14438
  var package_default = {
14439
- version: "6.0.6"};
14439
+ version: "6.0.7"};
14440
14440
  var SluggerContext = React5__default.createContext(null);
14441
14441
  function flattenText(nodes) {
14442
14442
  if (nodes == null || typeof nodes === "boolean") return "";
@@ -20464,16 +20464,22 @@ var TocContext = createContext({
20464
20464
  setToc: () => {
20465
20465
  }
20466
20466
  });
20467
- function InnerTocProvider({ children }) {
20468
- const [toc, setToc] = useState(true);
20469
- const handleSetToc = (value) => {
20470
- setToc(value);
20471
- };
20472
- return /* @__PURE__ */ jsx(TocContext.Provider, { value: { toc, setToc: handleSetToc }, children });
20473
- }
20474
20467
  function TocProvider({ children }) {
20475
- const pathname = usePathname();
20476
- return /* @__PURE__ */ jsx(InnerTocProvider, { children }, pathname);
20468
+ return /* @__PURE__ */ jsx(TocStateProvider, { pathname: usePathname(), children });
20469
+ }
20470
+ function TocStateProvider({ pathname, children }) {
20471
+ const [state, setState] = useState({ pathname, toc: true });
20472
+ if (state.pathname !== pathname) setState({ pathname, toc: true });
20473
+ const toc = state.pathname === pathname ? state.toc : true;
20474
+ const setToc = useCallback(
20475
+ (value2) => setState((current) => {
20476
+ const previous = current.pathname === pathname ? current.toc : true;
20477
+ return { pathname, toc: typeof value2 === "function" ? value2(previous) : value2 };
20478
+ }),
20479
+ [pathname]
20480
+ );
20481
+ const value = useMemo(() => ({ toc, setToc }), [toc, setToc]);
20482
+ return /* @__PURE__ */ jsx(TocContext.Provider, { value, children });
20477
20483
  }
20478
20484
  function useToc() {
20479
20485
  return useContext(TocContext);