@bug-on/m3-expressive 1.3.2 → 1.3.3

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/layout.mjs CHANGED
@@ -5861,12 +5861,15 @@ Text.displayName = "Text";
5861
5861
  function TableOfContents({
5862
5862
  items,
5863
5863
  className,
5864
- scrollAreaProps
5864
+ scrollAreaProps,
5865
+ scrollContainerRef
5865
5866
  }) {
5866
5867
  const [activeId, setActiveId] = useState("");
5867
5868
  const itemIds = useMemo(() => items.map((i) => i.id), [items]);
5868
5869
  useEffect(() => {
5870
+ var _a;
5869
5871
  if (typeof IntersectionObserver === "undefined") return;
5872
+ const root = (_a = scrollContainerRef == null ? void 0 : scrollContainerRef.current) != null ? _a : null;
5870
5873
  const observer = new IntersectionObserver(
5871
5874
  (entries) => {
5872
5875
  for (const entry of entries) {
@@ -5874,19 +5877,20 @@ function TableOfContents({
5874
5877
  }
5875
5878
  },
5876
5879
  // rootMargin: top offset ~100px (fixed header), bottom -80% (early switch)
5877
- { rootMargin: "-100px 0% -80% 0%" }
5880
+ { root, rootMargin: "-100px 0% -80% 0%" }
5878
5881
  );
5879
5882
  for (const id of itemIds) {
5880
5883
  const el = document.getElementById(id);
5881
5884
  if (el) observer.observe(el);
5882
5885
  }
5883
5886
  return () => observer.disconnect();
5884
- }, [itemIds]);
5887
+ }, [itemIds, scrollContainerRef]);
5885
5888
  const handleClick = useCallback(
5886
5889
  (e, id) => {
5887
- var _a;
5888
5890
  e.preventDefault();
5889
- (_a = document.getElementById(id)) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth", block: "start" });
5891
+ const target = document.getElementById(id);
5892
+ if (!target) return;
5893
+ target.scrollIntoView({ behavior: "smooth", block: "start" });
5890
5894
  },
5891
5895
  []
5892
5896
  );
@@ -5903,19 +5907,35 @@ function TableOfContents({
5903
5907
  type: "hover"
5904
5908
  }, scrollAreaProps), {
5905
5909
  className: cn("flex-1 min-h-0", scrollAreaProps == null ? void 0 : scrollAreaProps.className),
5906
- children: /* @__PURE__ */ jsx("ul", { className: "space-y-4 pr-4", children: items.map((item) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(
5907
- "a",
5908
- {
5909
- href: `#${item.id}`,
5910
- onClick: (e) => handleClick(e, item.id),
5911
- "aria-current": activeId === item.id ? "true" : void 0,
5912
- className: cn(
5913
- "text-sm transition-colors hover:text-m3-primary block",
5914
- activeId === item.id ? "text-m3-primary font-bold" : "text-m3-on-surface-variant font-medium"
5915
- ),
5916
- children: item.label
5917
- }
5918
- ) }, item.id)) })
5910
+ children: /* @__PURE__ */ jsx("ul", { className: "space-y-2 pr-4", children: items.map((item) => {
5911
+ var _a;
5912
+ const depth = (_a = item.depth) != null ? _a : 1;
5913
+ const isSubItem = depth > 1;
5914
+ return /* @__PURE__ */ jsx(
5915
+ "li",
5916
+ {
5917
+ className: cn(
5918
+ isSubItem && "pl-3.5 border-l border-m3-outline-variant/40 ml-1"
5919
+ ),
5920
+ children: /* @__PURE__ */ jsx(
5921
+ "a",
5922
+ {
5923
+ href: `#${item.id}`,
5924
+ onClick: (e) => handleClick(e, item.id),
5925
+ "aria-current": activeId === item.id ? "true" : void 0,
5926
+ className: cn(
5927
+ "transition-colors hover:text-m3-primary block truncate",
5928
+ isSubItem ? "text-xs py-0.5 leading-relaxed" : "text-sm py-1 font-medium leading-snug",
5929
+ activeId === item.id ? "text-m3-primary font-bold" : "text-m3-on-surface-variant"
5930
+ ),
5931
+ title: item.label,
5932
+ children: item.label
5933
+ }
5934
+ )
5935
+ },
5936
+ item.id
5937
+ );
5938
+ }) })
5919
5939
  })
5920
5940
  )
5921
5941
  ]