@nswds/app 1.75.0 → 1.76.0
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.cjs +58 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +58 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,7 +58,7 @@ var ProgressPrimitive = require('@radix-ui/react-progress');
|
|
|
58
58
|
var tailwindVariants = require('tailwind-variants');
|
|
59
59
|
var ResizablePrimitive = require('react-resizable-panels');
|
|
60
60
|
var SliderPrimitive = require('@radix-ui/react-slider');
|
|
61
|
-
var slugify
|
|
61
|
+
var slugify = require('@sindresorhus/slugify');
|
|
62
62
|
var zustand = require('zustand');
|
|
63
63
|
var middleware = require('zustand/middleware');
|
|
64
64
|
|
|
@@ -17465,18 +17465,19 @@ function FormatToggle({ format, setFormat }) {
|
|
|
17465
17465
|
|
|
17466
17466
|
// package.json
|
|
17467
17467
|
var package_default = {
|
|
17468
|
-
version: "1.
|
|
17468
|
+
version: "1.75.0"};
|
|
17469
|
+
var SluggerContext = React5__namespace.default.createContext(null);
|
|
17469
17470
|
function flattenText(nodes) {
|
|
17470
17471
|
if (nodes == null || typeof nodes === "boolean") return "";
|
|
17471
|
-
if (typeof nodes === "string" || typeof nodes === "number"
|
|
17472
|
+
if (typeof nodes === "string" || typeof nodes === "number" || typeof nodes === "bigint")
|
|
17473
|
+
return String(nodes);
|
|
17472
17474
|
if (Array.isArray(nodes)) return nodes.map(flattenText).join("");
|
|
17473
|
-
if (
|
|
17474
|
-
|
|
17475
|
-
return flattenText(children);
|
|
17475
|
+
if (React5__namespace.default.isValidElement(nodes)) {
|
|
17476
|
+
return flattenText(nodes.props.children);
|
|
17476
17477
|
}
|
|
17477
17478
|
return "";
|
|
17478
17479
|
}
|
|
17479
|
-
function
|
|
17480
|
+
function baseSlug(input) {
|
|
17480
17481
|
return input.toLowerCase().trim().replace(/[\s\W]+/g, "-").replace(/^-+|-+$/g, "");
|
|
17481
17482
|
}
|
|
17482
17483
|
function Heading({
|
|
@@ -17490,6 +17491,7 @@ function Heading({
|
|
|
17490
17491
|
...props
|
|
17491
17492
|
}) {
|
|
17492
17493
|
const Tag = `h${level}`;
|
|
17494
|
+
const slugger = React5.useContext(SluggerContext);
|
|
17493
17495
|
const headingSizeClasses = {
|
|
17494
17496
|
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))]",
|
|
17495
17497
|
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))]",
|
|
@@ -17524,8 +17526,10 @@ function Heading({
|
|
|
17524
17526
|
const computedId = React5.useMemo(() => {
|
|
17525
17527
|
if (idProp) return idProp;
|
|
17526
17528
|
const text = flattenText(children);
|
|
17527
|
-
|
|
17528
|
-
|
|
17529
|
+
if (!text) return void 0;
|
|
17530
|
+
const base = baseSlug(text);
|
|
17531
|
+
return slugger ? slugger.slug(base) : base;
|
|
17532
|
+
}, [idProp, children, slugger]);
|
|
17529
17533
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
17530
17534
|
Tag,
|
|
17531
17535
|
{
|
|
@@ -30636,7 +30640,7 @@ function domToSimple(node) {
|
|
|
30636
30640
|
}
|
|
30637
30641
|
throw new Error("Unsupported node type");
|
|
30638
30642
|
}
|
|
30639
|
-
function getHeadings(
|
|
30643
|
+
function getHeadings(slugify$1 = slugify.slugifyWithCounter()) {
|
|
30640
30644
|
const content = document.querySelector("article");
|
|
30641
30645
|
if (!content) {
|
|
30642
30646
|
return [];
|
|
@@ -30647,7 +30651,7 @@ function getHeadings(slugify2 = slugify$1.slugifyWithCounter()) {
|
|
|
30647
30651
|
headings.forEach((el) => {
|
|
30648
30652
|
const simplifiedNode = domToSimple(el);
|
|
30649
30653
|
const title = getNodeText(simplifiedNode).trim();
|
|
30650
|
-
const slugifiedTitle =
|
|
30654
|
+
const slugifiedTitle = slugify$1(title);
|
|
30651
30655
|
const id3 = el.id || slugifiedTitle;
|
|
30652
30656
|
const level = parseInt(el.tagName[1]);
|
|
30653
30657
|
const node = { level, id: id3, title, children: [] };
|
|
@@ -30670,27 +30674,58 @@ function getHeadings(slugify2 = slugify$1.slugifyWithCounter()) {
|
|
|
30670
30674
|
}
|
|
30671
30675
|
function usePageHeadings() {
|
|
30672
30676
|
const [headings, setHeadings] = React5.useState([]);
|
|
30677
|
+
const pathname = navigation.usePathname();
|
|
30678
|
+
const observerRef = React5.useRef(null);
|
|
30679
|
+
const observedElRef = React5.useRef(null);
|
|
30673
30680
|
React5.useEffect(() => {
|
|
30674
|
-
const
|
|
30675
|
-
|
|
30676
|
-
|
|
30677
|
-
|
|
30678
|
-
|
|
30679
|
-
|
|
30680
|
-
|
|
30681
|
-
|
|
30682
|
-
|
|
30681
|
+
const update = () => setHeadings(getHeadings());
|
|
30682
|
+
const attachToCurrentArticle = () => {
|
|
30683
|
+
const article = document.querySelector("article");
|
|
30684
|
+
if (!article || observedElRef.current === article) return;
|
|
30685
|
+
observerRef.current?.disconnect();
|
|
30686
|
+
const obs = new MutationObserver(() => {
|
|
30687
|
+
update();
|
|
30688
|
+
});
|
|
30689
|
+
obs.observe(article, {
|
|
30683
30690
|
childList: true,
|
|
30684
30691
|
subtree: true,
|
|
30685
30692
|
attributes: true,
|
|
30686
30693
|
attributeFilter: ["id"]
|
|
30687
30694
|
});
|
|
30695
|
+
observerRef.current = obs;
|
|
30696
|
+
observedElRef.current = article;
|
|
30697
|
+
requestAnimationFrame(update);
|
|
30698
|
+
};
|
|
30699
|
+
attachToCurrentArticle();
|
|
30700
|
+
const articleParent = document.querySelector("article")?.parentElement;
|
|
30701
|
+
const rootObserver = new MutationObserver((mutations) => {
|
|
30702
|
+
for (const mutation of mutations) {
|
|
30703
|
+
for (const node of Array.from(mutation.addedNodes)) {
|
|
30704
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === "article") {
|
|
30705
|
+
attachToCurrentArticle();
|
|
30706
|
+
return;
|
|
30707
|
+
}
|
|
30708
|
+
}
|
|
30709
|
+
for (const node of Array.from(mutation.removedNodes)) {
|
|
30710
|
+
if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === "article") {
|
|
30711
|
+
attachToCurrentArticle();
|
|
30712
|
+
return;
|
|
30713
|
+
}
|
|
30714
|
+
}
|
|
30715
|
+
}
|
|
30716
|
+
});
|
|
30717
|
+
if (articleParent) {
|
|
30718
|
+
rootObserver.observe(articleParent, { childList: true });
|
|
30719
|
+
} else {
|
|
30720
|
+
rootObserver.observe(document.body, { childList: true });
|
|
30688
30721
|
}
|
|
30689
30722
|
return () => {
|
|
30690
|
-
|
|
30691
|
-
|
|
30723
|
+
rootObserver.disconnect();
|
|
30724
|
+
observerRef.current?.disconnect();
|
|
30725
|
+
observerRef.current = null;
|
|
30726
|
+
observedElRef.current = null;
|
|
30692
30727
|
};
|
|
30693
|
-
}, []);
|
|
30728
|
+
}, [pathname]);
|
|
30694
30729
|
return headings;
|
|
30695
30730
|
}
|
|
30696
30731
|
function createFormStore(opts) {
|