@nswds/app 1.75.0 → 1.76.1

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.js CHANGED
@@ -5,7 +5,7 @@ import { twMerge } from 'tailwind-merge';
5
5
  import { cva } from 'class-variance-authority';
6
6
  import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
7
7
  import * as React5 from 'react';
8
- import React5__default, { forwardRef, useEffect, createContext, useState, useContext, useMemo, useRef, useInsertionEffect, useLayoutEffect, Fragment as Fragment$1, createElement, useCallback, Suspense, useId, isValidElement, Component } from 'react';
8
+ import React5__default, { forwardRef, useEffect, createContext, useState, useContext, useMemo, useRef, useInsertionEffect, useLayoutEffect, Fragment as Fragment$1, createElement, useCallback, Suspense, useId, Component } from 'react';
9
9
  import * as Headless4 from '@headlessui/react';
10
10
  import { PopoverGroup, Popover as Popover$1, PopoverButton, PopoverPanel, Dialog as Dialog$1, DialogPanel } from '@headlessui/react';
11
11
  import Link12 from 'next/link';
@@ -17412,18 +17412,19 @@ function FormatToggle({ format, setFormat }) {
17412
17412
 
17413
17413
  // package.json
17414
17414
  var package_default = {
17415
- version: "1.74.0"};
17415
+ version: "1.75.0"};
17416
+ var SluggerContext = React5__default.createContext(null);
17416
17417
  function flattenText(nodes) {
17417
17418
  if (nodes == null || typeof nodes === "boolean") return "";
17418
- if (typeof nodes === "string" || typeof nodes === "number") return String(nodes);
17419
+ if (typeof nodes === "string" || typeof nodes === "number" || typeof nodes === "bigint")
17420
+ return String(nodes);
17419
17421
  if (Array.isArray(nodes)) return nodes.map(flattenText).join("");
17420
- if (isValidElement(nodes)) {
17421
- const { children } = nodes.props;
17422
- return flattenText(children);
17422
+ if (React5__default.isValidElement(nodes)) {
17423
+ return flattenText(nodes.props.children);
17423
17424
  }
17424
17425
  return "";
17425
17426
  }
17426
- function slugify(input) {
17427
+ function baseSlug(input) {
17427
17428
  return input.toLowerCase().trim().replace(/[\s\W]+/g, "-").replace(/^-+|-+$/g, "");
17428
17429
  }
17429
17430
  function Heading({
@@ -17437,6 +17438,7 @@ function Heading({
17437
17438
  ...props
17438
17439
  }) {
17439
17440
  const Tag = `h${level}`;
17441
+ const slugger = useContext(SluggerContext);
17440
17442
  const headingSizeClasses = {
17441
17443
  1: "text-[calc(var(--heading-font-size-1)_*_var(--heading-font-size-adjust))] leading-[var(--line-height-52)] tracking-[calc(var(--heading-letter-spacing-2)_+_var(--heading-letter-spacing))]",
17442
17444
  2: "text-[calc(var(--heading-font-size-2)_*_var(--heading-font-size-adjust))] leading-[var(--line-height-44)] tracking-[calc(var(--heading-letter-spacing-2)_+_var(--heading-letter-spacing))]",
@@ -17471,8 +17473,10 @@ function Heading({
17471
17473
  const computedId = useMemo(() => {
17472
17474
  if (idProp) return idProp;
17473
17475
  const text = flattenText(children);
17474
- return text ? slugify(text) : void 0;
17475
- }, [idProp, children]);
17476
+ if (!text) return void 0;
17477
+ const base = baseSlug(text);
17478
+ return slugger ? slugger.slug(base) : base;
17479
+ }, [idProp, children, slugger]);
17476
17480
  return /* @__PURE__ */ jsx(
17477
17481
  Tag,
17478
17482
  {
@@ -30583,7 +30587,7 @@ function domToSimple(node) {
30583
30587
  }
30584
30588
  throw new Error("Unsupported node type");
30585
30589
  }
30586
- function getHeadings(slugify2 = slugifyWithCounter()) {
30590
+ function getHeadings(slugify = slugifyWithCounter()) {
30587
30591
  const content = document.querySelector("article");
30588
30592
  if (!content) {
30589
30593
  return [];
@@ -30594,7 +30598,7 @@ function getHeadings(slugify2 = slugifyWithCounter()) {
30594
30598
  headings.forEach((el) => {
30595
30599
  const simplifiedNode = domToSimple(el);
30596
30600
  const title = getNodeText(simplifiedNode).trim();
30597
- const slugifiedTitle = slugify2(title);
30601
+ const slugifiedTitle = slugify(title);
30598
30602
  const id3 = el.id || slugifiedTitle;
30599
30603
  const level = parseInt(el.tagName[1]);
30600
30604
  const node = { level, id: id3, title, children: [] };
@@ -30617,27 +30621,58 @@ function getHeadings(slugify2 = slugifyWithCounter()) {
30617
30621
  }
30618
30622
  function usePageHeadings() {
30619
30623
  const [headings, setHeadings] = useState([]);
30624
+ const pathname = usePathname();
30625
+ const observerRef = useRef(null);
30626
+ const observedElRef = useRef(null);
30620
30627
  useEffect(() => {
30621
- const raf = requestAnimationFrame(() => {
30622
- setHeadings(getHeadings());
30623
- });
30624
- const observer = new MutationObserver(() => {
30625
- setHeadings(getHeadings());
30626
- });
30627
- const article = document.querySelector("article");
30628
- if (article) {
30629
- observer.observe(article, {
30628
+ const update = () => setHeadings(getHeadings());
30629
+ const attachToCurrentArticle = () => {
30630
+ const article = document.querySelector("article");
30631
+ if (!article || observedElRef.current === article) return;
30632
+ observerRef.current?.disconnect();
30633
+ const obs = new MutationObserver(() => {
30634
+ update();
30635
+ });
30636
+ obs.observe(article, {
30630
30637
  childList: true,
30631
30638
  subtree: true,
30632
30639
  attributes: true,
30633
30640
  attributeFilter: ["id"]
30634
30641
  });
30642
+ observerRef.current = obs;
30643
+ observedElRef.current = article;
30644
+ requestAnimationFrame(update);
30645
+ };
30646
+ attachToCurrentArticle();
30647
+ const articleParent = document.querySelector("article")?.parentElement;
30648
+ const rootObserver = new MutationObserver((mutations) => {
30649
+ for (const mutation of mutations) {
30650
+ for (const node of Array.from(mutation.addedNodes)) {
30651
+ if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === "article") {
30652
+ attachToCurrentArticle();
30653
+ return;
30654
+ }
30655
+ }
30656
+ for (const node of Array.from(mutation.removedNodes)) {
30657
+ if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === "article") {
30658
+ attachToCurrentArticle();
30659
+ return;
30660
+ }
30661
+ }
30662
+ }
30663
+ });
30664
+ if (articleParent) {
30665
+ rootObserver.observe(articleParent, { childList: true });
30666
+ } else {
30667
+ rootObserver.observe(document.body, { childList: true });
30635
30668
  }
30636
30669
  return () => {
30637
- cancelAnimationFrame(raf);
30638
- observer.disconnect();
30670
+ rootObserver.disconnect();
30671
+ observerRef.current?.disconnect();
30672
+ observerRef.current = null;
30673
+ observedElRef.current = null;
30639
30674
  };
30640
- }, []);
30675
+ }, [pathname]);
30641
30676
  return headings;
30642
30677
  }
30643
30678
  function createFormStore(opts) {