@unpunnyfuns/swatchbook-blocks 0.60.7 → 0.60.8

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.mjs CHANGED
@@ -259,11 +259,11 @@ function subscribe$1(cb) {
259
259
  function getSnapshot$1() {
260
260
  return snapshot$1;
261
261
  }
262
- function getServerSnapshot() {
262
+ function getServerSnapshot$1() {
263
263
  return snapshot$1;
264
264
  }
265
265
  function useChannelGlobals() {
266
- return useSyncExternalStore(subscribe$1, getSnapshot$1, getServerSnapshot);
266
+ return useSyncExternalStore(subscribe$1, getSnapshot$1, getServerSnapshot$1);
267
267
  }
268
268
  //#endregion
269
269
  //#region src/contexts.ts
@@ -377,8 +377,11 @@ function subscribe(cb) {
377
377
  function getSnapshot() {
378
378
  return snapshot;
379
379
  }
380
+ function getServerSnapshot() {
381
+ return snapshot;
382
+ }
380
383
  function useTokenSnapshot() {
381
- return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
384
+ return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
382
385
  }
383
386
  //#endregion
384
387
  //#region src/internal/use-project.ts
@@ -2016,10 +2019,13 @@ function stopKey(path, stop, fallback) {
2016
2019
  return `${path}|${stop.position ?? fallback}|${stopCssColor(stop)}`;
2017
2020
  }
2018
2021
  function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" }) {
2019
- const project = useProject();
2020
- const { resolved, activeTheme, activeAxes, cssVarPrefix } = project;
2022
+ const { resolved, activeTheme, activeAxes, cssVarPrefix, listing } = useProject();
2021
2023
  const colorFormat = useColorFormat();
2022
2024
  const rows = useMemo(() => {
2025
+ const projectFields = {
2026
+ listing,
2027
+ cssVarPrefix
2028
+ };
2023
2029
  return sortTokens(Object.entries(resolved).filter(([path, token]) => {
2024
2030
  if (token.$type !== "gradient") return false;
2025
2031
  return matchPath(path, filter);
@@ -2028,13 +2034,14 @@ function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" })
2028
2034
  dir: sortDir
2029
2035
  }).map(([path, token]) => ({
2030
2036
  path,
2031
- cssVar: resolveCssVar(path, project),
2037
+ cssVar: resolveCssVar(path, projectFields),
2032
2038
  stops: asStops(token.$value)
2033
2039
  }));
2034
2040
  }, [
2035
2041
  resolved,
2042
+ listing,
2043
+ cssVarPrefix,
2036
2044
  filter,
2037
- project,
2038
2045
  sortBy,
2039
2046
  sortDir
2040
2047
  ]);
@@ -3572,10 +3579,32 @@ function TokenHeader({ path, heading }) {
3572
3579
  }
3573
3580
  //#endregion
3574
3581
  //#region src/token-detail/TokenUsageSnippet.tsx
3582
+ /**
3583
+ * DTCG `$type`s with a single canonical CSS property. Types whose value is
3584
+ * applied across many properties (`dimension`, `number`, `strokeStyle`,
3585
+ * `typography`) are intentionally absent — they fall back to a commented hint.
3586
+ */
3587
+ const CSS_PROPERTY_BY_TYPE = {
3588
+ color: "color",
3589
+ shadow: "box-shadow",
3590
+ border: "border",
3591
+ fontFamily: "font-family",
3592
+ fontWeight: "font-weight",
3593
+ duration: "transition-duration",
3594
+ cubicBezier: "transition-timing-function",
3595
+ gradient: "background",
3596
+ transition: "transition"
3597
+ };
3598
+ function usageSnippet(cssVar, type) {
3599
+ const property = type ? CSS_PROPERTY_BY_TYPE[type] : void 0;
3600
+ if (property) return `${property}: ${cssVar};`;
3601
+ if (type) return `/* ${type} */ ${cssVar};`;
3602
+ return `${cssVar};`;
3603
+ }
3575
3604
  function TokenUsageSnippet({ path }) {
3576
3605
  const { token, cssVar } = useTokenDetailData(path);
3577
3606
  if (!token) return null;
3578
- const snippet = `color: ${cssVar};`;
3607
+ const snippet = usageSnippet(cssVar, token.$type);
3579
3608
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
3580
3609
  className: "sb-token-detail__section-header",
3581
3610
  children: "Usage"
@@ -3895,9 +3924,12 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
3895
3924
  return out;
3896
3925
  }, [tree, initiallyExpanded]);
3897
3926
  const [expanded, setExpanded] = useState(initialExpanded);
3927
+ const initiallyExpandedRef = useRef(initiallyExpanded);
3898
3928
  useEffect(() => {
3929
+ if (initiallyExpandedRef.current === initiallyExpanded) return;
3930
+ initiallyExpandedRef.current = initiallyExpanded;
3899
3931
  setExpanded(initialExpanded);
3900
- }, [initialExpanded]);
3932
+ }, [initiallyExpanded, initialExpanded]);
3901
3933
  const [selectedPath, setSelectedPath] = useState(null);
3902
3934
  const [query, setQuery] = useState("");
3903
3935
  const deferredQuery = useDeferredValue(query);
@@ -3963,7 +3995,9 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
3963
3995
  const node = treeItemRefs.current.get(focusedPath);
3964
3996
  if (node && document.activeElement !== node) {
3965
3997
  const active = document.activeElement;
3966
- if (active instanceof HTMLElement && active.closest("[role=\"tree\"]")) node.focus();
3998
+ const insideTree = active instanceof HTMLElement && active.closest("[role=\"tree\"]");
3999
+ const orphaned = active === document.body || active === null;
4000
+ if (insideTree || orphaned && storedFocus !== null && storedFocus !== focusedPath) node.focus();
3967
4001
  }
3968
4002
  }, [focusedPath]);
3969
4003
  const handleTreeKeyDown = useCallback((e) => {