@unpunnyfuns/swatchbook-blocks 0.64.0 → 0.65.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.d.mts +28 -7
- package/dist/index.mjs +68 -14
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +5 -0
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -99,11 +99,14 @@ interface ProjectSnapshot {
|
|
|
99
99
|
/** The default tuple — `{ axis: axis.default }` for every axis. */
|
|
100
100
|
defaultTuple: Record<string, string>;
|
|
101
101
|
/**
|
|
102
|
-
* Pre-built `resolveAt(tuple)` accessor. The addon's preview
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
102
|
+
* Pre-built `resolveAt(tuple)` accessor. The addon's preview decorator
|
|
103
|
+
* instantiates this once per iframe lifetime. When present, use-project
|
|
104
|
+
* prefers it over building its own from `tokenGraph`, so it MUST preserve
|
|
105
|
+
* alias provenance — back it with `resolveAllWithProvenanceAt`, not the raw
|
|
106
|
+
* leaf `resolveAllAt`, or axis-varying aliases silently lose their chain /
|
|
107
|
+
* reverse refs / description at non-default tuples. Hand-built snapshots
|
|
108
|
+
* (tests, MDX) can omit this; blocks then fall back to a provenance-aware
|
|
109
|
+
* graph-backed resolver built from `tokenGraph`.
|
|
107
110
|
*/
|
|
108
111
|
resolveAt?: (tuple: Record<string, string>) => Record<string, VirtualTokenShape>;
|
|
109
112
|
}
|
|
@@ -765,6 +768,18 @@ declare function TokenUsageSnippet({
|
|
|
765
768
|
path
|
|
766
769
|
}: TokenUsageSnippetProps): ReactElement | null;
|
|
767
770
|
//#endregion
|
|
771
|
+
//#region src/indicators/resolve.d.ts
|
|
772
|
+
/** The individually-toggleable indicators in the row strip. `alias` covers the whole alias unit (forward chain + reverse count). */
|
|
773
|
+
type IndicatorName = 'alias' | 'variance' | 'gamut' | 'deprecation' | 'description';
|
|
774
|
+
/**
|
|
775
|
+
* Consumer-facing indicator config for the strip-hosting blocks:
|
|
776
|
+
* - `true` — every indicator on (including the opt-in `description`)
|
|
777
|
+
* - `false` — every indicator off
|
|
778
|
+
* - object — per-key override layered over the defaults
|
|
779
|
+
* - omitted — the defaults
|
|
780
|
+
*/
|
|
781
|
+
type IndicatorsProp = boolean | Partial<Record<IndicatorName, boolean>>;
|
|
782
|
+
//#endregion
|
|
768
783
|
//#region src/TokenNavigator.d.ts
|
|
769
784
|
interface TokenNavigatorProps {
|
|
770
785
|
/** If provided, mount at this dot-path subtree and hide everything outside it. */
|
|
@@ -805,6 +820,8 @@ interface TokenNavigatorProps {
|
|
|
805
820
|
* props otherwise.
|
|
806
821
|
*/
|
|
807
822
|
id?: string;
|
|
823
|
+
/** Configure the per-row indicator strip. See `IndicatorsProp`. */
|
|
824
|
+
indicators?: IndicatorsProp;
|
|
808
825
|
}
|
|
809
826
|
declare function TokenNavigator({
|
|
810
827
|
root,
|
|
@@ -812,7 +829,8 @@ declare function TokenNavigator({
|
|
|
812
829
|
initiallyExpanded,
|
|
813
830
|
searchable,
|
|
814
831
|
onSelect,
|
|
815
|
-
id
|
|
832
|
+
id,
|
|
833
|
+
indicators
|
|
816
834
|
}: TokenNavigatorProps): ReactElement;
|
|
817
835
|
//#endregion
|
|
818
836
|
//#region src/TokenTable.d.ts
|
|
@@ -855,6 +873,8 @@ interface TokenTableProps {
|
|
|
855
873
|
onSelect?(path: string): void;
|
|
856
874
|
/** Disambiguates persisted UI state for two identical-prop tables on a page. */
|
|
857
875
|
id?: string;
|
|
876
|
+
/** Configure the per-row indicator strip. See `IndicatorsProp`. */
|
|
877
|
+
indicators?: IndicatorsProp;
|
|
858
878
|
}
|
|
859
879
|
declare function TokenTable({
|
|
860
880
|
filter,
|
|
@@ -864,7 +884,8 @@ declare function TokenTable({
|
|
|
864
884
|
sortDir,
|
|
865
885
|
searchable,
|
|
866
886
|
onSelect,
|
|
867
|
-
id
|
|
887
|
+
id,
|
|
888
|
+
indicators
|
|
868
889
|
}: TokenTableProps): ReactElement;
|
|
869
890
|
//#endregion
|
|
870
891
|
//#region src/TypographyScale.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -3640,6 +3640,38 @@ function isInView(path, ctx) {
|
|
|
3640
3640
|
return true;
|
|
3641
3641
|
}
|
|
3642
3642
|
//#endregion
|
|
3643
|
+
//#region src/indicators/resolve.ts
|
|
3644
|
+
/** Established-on set; `description` is opt-in. */
|
|
3645
|
+
const DEFAULT_INDICATORS = {
|
|
3646
|
+
alias: true,
|
|
3647
|
+
variance: true,
|
|
3648
|
+
gamut: true,
|
|
3649
|
+
deprecation: true,
|
|
3650
|
+
description: false
|
|
3651
|
+
};
|
|
3652
|
+
/** Normalize an `IndicatorsProp` into a full enabled-map by layering over the defaults. */
|
|
3653
|
+
function resolveIndicators(prop) {
|
|
3654
|
+
if (prop === void 0) return { ...DEFAULT_INDICATORS };
|
|
3655
|
+
if (prop === true) return {
|
|
3656
|
+
alias: true,
|
|
3657
|
+
variance: true,
|
|
3658
|
+
gamut: true,
|
|
3659
|
+
deprecation: true,
|
|
3660
|
+
description: true
|
|
3661
|
+
};
|
|
3662
|
+
if (prop === false) return {
|
|
3663
|
+
alias: false,
|
|
3664
|
+
variance: false,
|
|
3665
|
+
gamut: false,
|
|
3666
|
+
deprecation: false,
|
|
3667
|
+
description: false
|
|
3668
|
+
};
|
|
3669
|
+
return {
|
|
3670
|
+
...DEFAULT_INDICATORS,
|
|
3671
|
+
...prop
|
|
3672
|
+
};
|
|
3673
|
+
}
|
|
3674
|
+
//#endregion
|
|
3643
3675
|
//#region src/indicators/RowIndicators.tsx
|
|
3644
3676
|
function relativeLabel(path, root) {
|
|
3645
3677
|
if (root && path.startsWith(`${root}.`)) return path.slice(root.length + 1);
|
|
@@ -3788,34 +3820,49 @@ function ReverseCount({ referents, canReference, onReferenceClick }) {
|
|
|
3788
3820
|
/** Per-row indicator strip: alias references, variance, gamut, deprecation. */
|
|
3789
3821
|
function RowIndicators(props) {
|
|
3790
3822
|
const { token, root, variance, colorFormat, canReference, onReferenceClick } = props;
|
|
3823
|
+
const en = props.enabled ?? resolveIndicators(void 0);
|
|
3791
3824
|
const aliasChain = Array.isArray(token.aliasChain) && token.aliasChain.length > 0 ? token.aliasChain : void 0;
|
|
3792
3825
|
const reverseCount = Array.isArray(token.aliasedBy) && token.aliasedBy.length > 0 ? token.aliasedBy.length : 0;
|
|
3793
3826
|
const isVarying = variance !== void 0 && variance.kind !== "constant";
|
|
3794
3827
|
const outOfGamut = token.$type === "color" && (formatColor(token.$value, colorFormat)?.outOfGamut ?? false);
|
|
3795
3828
|
const deprecated = token.$deprecated;
|
|
3796
3829
|
const isDeprecated = deprecated === true || typeof deprecated === "string" && deprecated.length > 0;
|
|
3797
|
-
|
|
3830
|
+
const description = typeof token.$description === "string" && token.$description.length > 0 ? token.$description : void 0;
|
|
3831
|
+
const showDeprecated = en.deprecation && isDeprecated;
|
|
3832
|
+
const showForward = en.alias && aliasChain !== void 0;
|
|
3833
|
+
const showReverse = en.alias && reverseCount > 0;
|
|
3834
|
+
const showVariance = en.variance && isVarying;
|
|
3835
|
+
const showGamut = en.gamut && outOfGamut;
|
|
3836
|
+
const showDescription = en.description && description !== void 0;
|
|
3837
|
+
if (!showDeprecated && !showForward && !showReverse && !showVariance && !showGamut && !showDescription) return null;
|
|
3798
3838
|
return /* @__PURE__ */ jsxs("span", {
|
|
3799
3839
|
className: "sb-indicator__indicators",
|
|
3800
3840
|
children: [
|
|
3801
|
-
|
|
3802
|
-
aliasChain && /* @__PURE__ */ jsx(ForwardChain, {
|
|
3841
|
+
showDeprecated && deprecated !== void 0 && /* @__PURE__ */ jsx(DeprecatedBadge, { deprecated }),
|
|
3842
|
+
showForward && aliasChain && /* @__PURE__ */ jsx(ForwardChain, {
|
|
3803
3843
|
chain: aliasChain,
|
|
3804
3844
|
root,
|
|
3805
3845
|
canReference,
|
|
3806
3846
|
onReferenceClick
|
|
3807
3847
|
}),
|
|
3808
|
-
|
|
3848
|
+
showReverse && token.aliasedBy && /* @__PURE__ */ jsx(ReverseCount, {
|
|
3809
3849
|
referents: token.aliasedBy,
|
|
3810
3850
|
canReference,
|
|
3811
3851
|
onReferenceClick
|
|
3812
3852
|
}),
|
|
3813
|
-
variance && /* @__PURE__ */ jsx(VarianceBadge, { variance }),
|
|
3814
|
-
|
|
3853
|
+
showVariance && variance && /* @__PURE__ */ jsx(VarianceBadge, { variance }),
|
|
3854
|
+
showGamut && /* @__PURE__ */ jsx("span", {
|
|
3815
3855
|
className: "sb-indicator__gamut",
|
|
3816
3856
|
title: "Out of sRGB gamut for this format",
|
|
3817
3857
|
"aria-label": "out of gamut",
|
|
3818
3858
|
children: "⚠"
|
|
3859
|
+
}),
|
|
3860
|
+
showDescription && description !== void 0 && /* @__PURE__ */ jsx("span", {
|
|
3861
|
+
className: "sb-indicator__description",
|
|
3862
|
+
"data-testid": "row-indicator-description",
|
|
3863
|
+
title: description,
|
|
3864
|
+
"aria-label": `description: ${description}`,
|
|
3865
|
+
children: "ⓘ"
|
|
3819
3866
|
})
|
|
3820
3867
|
]
|
|
3821
3868
|
});
|
|
@@ -3924,7 +3971,7 @@ function pruneTreeForMatches(nodes, matches, expandOut) {
|
|
|
3924
3971
|
}
|
|
3925
3972
|
return out;
|
|
3926
3973
|
}
|
|
3927
|
-
function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true, onSelect, id }) {
|
|
3974
|
+
function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true, onSelect, id, indicators }) {
|
|
3928
3975
|
const { resolved, activeTheme, activeAxes, cssVarPrefix } = useProject();
|
|
3929
3976
|
const blockKey = useBlockKey("TokenNavigator", [
|
|
3930
3977
|
root,
|
|
@@ -3935,6 +3982,7 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
|
|
|
3935
3982
|
if (type === void 0) return void 0;
|
|
3936
3983
|
return new Set(Array.isArray(type) ? type : [type]);
|
|
3937
3984
|
}, [type]);
|
|
3985
|
+
const enabledIndicators = useMemo(() => resolveIndicators(indicators), [indicators]);
|
|
3938
3986
|
const tree = useMemo(() => buildTree(resolved, root, typeFilter), [
|
|
3939
3987
|
resolved,
|
|
3940
3988
|
root,
|
|
@@ -4206,6 +4254,7 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
|
|
|
4206
4254
|
root,
|
|
4207
4255
|
resolveInView,
|
|
4208
4256
|
onNavigate: navigateTo,
|
|
4257
|
+
enabled: enabledIndicators,
|
|
4209
4258
|
level: 1,
|
|
4210
4259
|
setsize: visibleTree.length,
|
|
4211
4260
|
posinset: i + 1
|
|
@@ -4219,7 +4268,7 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
|
|
|
4219
4268
|
]
|
|
4220
4269
|
});
|
|
4221
4270
|
}
|
|
4222
|
-
function TreeNodeRow({ node, expanded, focusedPath, registerTreeItem, onToggle, onFocusPath, onLeafClick, root, resolveInView, onNavigate, level, setsize, posinset }) {
|
|
4271
|
+
function TreeNodeRow({ node, expanded, focusedPath, registerTreeItem, onToggle, onFocusPath, onLeafClick, root, resolveInView, onNavigate, enabled, level, setsize, posinset }) {
|
|
4223
4272
|
if (node.kind === "leaf") return /* @__PURE__ */ jsx(LeafRow, {
|
|
4224
4273
|
node,
|
|
4225
4274
|
isFocused: focusedPath === node.path,
|
|
@@ -4229,6 +4278,7 @@ function TreeNodeRow({ node, expanded, focusedPath, registerTreeItem, onToggle,
|
|
|
4229
4278
|
root,
|
|
4230
4279
|
resolveInView,
|
|
4231
4280
|
onNavigate,
|
|
4281
|
+
enabled,
|
|
4232
4282
|
level,
|
|
4233
4283
|
setsize,
|
|
4234
4284
|
posinset
|
|
@@ -4279,6 +4329,7 @@ function TreeNodeRow({ node, expanded, focusedPath, registerTreeItem, onToggle,
|
|
|
4279
4329
|
root,
|
|
4280
4330
|
resolveInView,
|
|
4281
4331
|
onNavigate,
|
|
4332
|
+
enabled,
|
|
4282
4333
|
level: level + 1,
|
|
4283
4334
|
setsize: node.children.length,
|
|
4284
4335
|
posinset: i + 1
|
|
@@ -4286,7 +4337,7 @@ function TreeNodeRow({ node, expanded, focusedPath, registerTreeItem, onToggle,
|
|
|
4286
4337
|
})]
|
|
4287
4338
|
});
|
|
4288
4339
|
}
|
|
4289
|
-
const LeafRow = memo(function LeafRow({ node, isFocused, registerTreeItem, onFocusPath, onLeafClick, root, resolveInView, onNavigate, level, setsize, posinset }) {
|
|
4340
|
+
const LeafRow = memo(function LeafRow({ node, isFocused, registerTreeItem, onFocusPath, onLeafClick, root, resolveInView, onNavigate, enabled, level, setsize, posinset }) {
|
|
4290
4341
|
const type = node.token.$type ?? "";
|
|
4291
4342
|
const project = useProject();
|
|
4292
4343
|
const colorFormat = useColorFormat();
|
|
@@ -4306,7 +4357,7 @@ const LeafRow = memo(function LeafRow({ node, isFocused, registerTreeItem, onFoc
|
|
|
4306
4357
|
children: /* @__PURE__ */ jsxs("div", {
|
|
4307
4358
|
className: "sb-token-navigator__leaf-row",
|
|
4308
4359
|
"data-testid": "token-navigator-leaf-row",
|
|
4309
|
-
"data-deprecated": isDeprecated ? "true" : void 0,
|
|
4360
|
+
"data-deprecated": enabled.deprecation && isDeprecated ? "true" : void 0,
|
|
4310
4361
|
onClick: () => {
|
|
4311
4362
|
onFocusPath(node.path);
|
|
4312
4363
|
onLeafClick(node.path);
|
|
@@ -4332,7 +4383,8 @@ const LeafRow = memo(function LeafRow({ node, isFocused, registerTreeItem, onFoc
|
|
|
4332
4383
|
variance,
|
|
4333
4384
|
colorFormat,
|
|
4334
4385
|
canReference: resolveInView,
|
|
4335
|
-
onReferenceClick: onNavigate
|
|
4386
|
+
onReferenceClick: onNavigate,
|
|
4387
|
+
enabled
|
|
4336
4388
|
}),
|
|
4337
4389
|
/* @__PURE__ */ jsx(LeafPreview, {
|
|
4338
4390
|
path: node.path,
|
|
@@ -4404,7 +4456,7 @@ const LeafPreview = memo(function LeafPreview({ path, token }) {
|
|
|
4404
4456
|
});
|
|
4405
4457
|
//#endregion
|
|
4406
4458
|
//#region src/TokenTable.tsx
|
|
4407
|
-
function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", searchable = true, onSelect, id }) {
|
|
4459
|
+
function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", searchable = true, onSelect, id, indicators }) {
|
|
4408
4460
|
const { resolved, activeTheme, activeAxes, cssVarPrefix, listing, varianceByPath } = useProject();
|
|
4409
4461
|
const colorFormat = useColorFormat();
|
|
4410
4462
|
const blockKey = useBlockKey("TokenTable", [
|
|
@@ -4413,6 +4465,7 @@ function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", s
|
|
|
4413
4465
|
caption,
|
|
4414
4466
|
id
|
|
4415
4467
|
]);
|
|
4468
|
+
const enabledIndicators = useMemo(() => resolveIndicators(indicators), [indicators]);
|
|
4416
4469
|
const [selectedPath, setSelectedPath] = usePersistedState(`${blockKey}::selected`, null);
|
|
4417
4470
|
const [query, setQuery] = usePersistedState(`${blockKey}::query`, "");
|
|
4418
4471
|
const deferredQuery = useDeferredValue(query);
|
|
@@ -4545,7 +4598,7 @@ function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", s
|
|
|
4545
4598
|
children: [
|
|
4546
4599
|
/* @__PURE__ */ jsx("td", {
|
|
4547
4600
|
className: cx("sb-token-table__td", "sb-token-table__path"),
|
|
4548
|
-
"data-deprecated": isDeprecated ? "true" : void 0,
|
|
4601
|
+
"data-deprecated": enabledIndicators.deprecation && isDeprecated ? "true" : void 0,
|
|
4549
4602
|
children: row.path
|
|
4550
4603
|
}),
|
|
4551
4604
|
/* @__PURE__ */ jsx("td", {
|
|
@@ -4597,7 +4650,8 @@ function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", s
|
|
|
4597
4650
|
variance: varianceByPath[row.path],
|
|
4598
4651
|
colorFormat,
|
|
4599
4652
|
canReference: (p) => p in resolved,
|
|
4600
|
-
onReferenceClick: (p) => setSelectedPath(p)
|
|
4653
|
+
onReferenceClick: (p) => setSelectedPath(p),
|
|
4654
|
+
enabled: enabledIndicators
|
|
4601
4655
|
})
|
|
4602
4656
|
})
|
|
4603
4657
|
]
|