@astryxdesign/cli 0.7.0-canary.e92e36f → 0.7.0-canary.ed07233
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/README.md +61 -61
- package/api/integration/pack-check.test.mjs +8 -0
- package/api/template/template.doc.mjs +1 -1
- package/api/template/template.type.mjs +1 -1
- package/api/theme/build/build.d.mts +0 -1
- package/api/theme/build/build.mjs +4 -29
- package/api/theme/build/family.mjs +1 -1
- package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
- package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
- package/assets/codemods/transforms/next/index.mjs +16 -0
- package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
- package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -1
- package/assets/docs/tree/tokens-data.doc.mjs +2 -2
- package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
- package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
- package/assets/templates/pages/canvas-editor/page.tsx +2 -2
- package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
- package/assets/templates/pages/payment-form/page.tsx +1 -1
- package/assets/templates/pages/table-filter/page.tsx +3 -3
- package/assets/templates/pages/theme-showcase/page.tsx +2 -2
- package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
- package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
- package/foundation/discovery/template-needs.mjs +93 -11
- package/foundation/discovery/template-needs.test.mjs +106 -3
- package/foundation/env/package-manager.d.mts +13 -0
- package/foundation/env/package-manager.mjs +106 -63
- package/foundation/response/response-types.doc.mjs +1 -2
- package/package.json +9 -9
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../validate-data-token-ownership.mjs';
|
|
5
|
+
|
|
6
|
+
async function run(source, file = 'test.tsx') {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const parser =
|
|
9
|
+
file.endsWith('.ts') || file.endsWith('.tsx') ? 'tsx' : 'babel';
|
|
10
|
+
const api = {
|
|
11
|
+
jscodeshift: jscodeshift.withParser(parser),
|
|
12
|
+
stats: () => {},
|
|
13
|
+
report: () => {},
|
|
14
|
+
};
|
|
15
|
+
return transform({source, path: file}, api);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe('validate-data-token-ownership', () => {
|
|
19
|
+
it('reports direct string and static-template consumers with both migration paths', async () => {
|
|
20
|
+
for (const source of [
|
|
21
|
+
`const fill = 'var(--color-data-categorical-green)';`,
|
|
22
|
+
'const fill = `var(--color-data-categorical-green)`;',
|
|
23
|
+
`const border = '1px solid var(--color-data-categorical-green)';`,
|
|
24
|
+
'const border = `${width}px solid var(--color-data-categorical-green)`;',
|
|
25
|
+
]) {
|
|
26
|
+
await expect(run(source)).rejects.toThrow(
|
|
27
|
+
/CSS-capable code imports dataVars.*Canvas.*resolveThemeToken/s,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('leaves fallbacks, dataVars access, and comments unchanged', async () => {
|
|
33
|
+
const source = `
|
|
34
|
+
// var(--color-data-categorical-green)
|
|
35
|
+
const fallback = 'var(--color-data-categorical-green, #008000)';
|
|
36
|
+
const fill = dataVars['--color-data-categorical-green'];
|
|
37
|
+
`;
|
|
38
|
+
expect(await run(source)).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('reports stale generated theme CSS with root data defaults', async () => {
|
|
42
|
+
const source = `/* @generated by \`astryx theme build\` */
|
|
43
|
+
@layer astryx-base {
|
|
44
|
+
:root { --color-data-categorical-green: #008000; }
|
|
45
|
+
}`;
|
|
46
|
+
await expect(run(source, 'theme.css')).rejects.toThrow(
|
|
47
|
+
/Rebuild it with `astryx theme build`/,
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('reports raw stylesheet uses without a fallback', async () => {
|
|
52
|
+
await expect(
|
|
53
|
+
run('.bar { fill: var(--color-data-categorical-green); }', 'chart.css'),
|
|
54
|
+
).rejects.toThrow(/Raw var\(--color-data-categorical-green\).*line 1/s);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('leaves stylesheet uses with a fallback, and comments, unchanged', async () => {
|
|
58
|
+
expect(
|
|
59
|
+
await run(
|
|
60
|
+
`/* var(--color-data-categorical-green) */
|
|
61
|
+
.bar { fill: var(--color-data-categorical-green, #008000); }`,
|
|
62
|
+
'chart.css',
|
|
63
|
+
),
|
|
64
|
+
).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('does not claim ownership of hand-authored CSS or sparse theme overrides', async () => {
|
|
68
|
+
expect(
|
|
69
|
+
await run(
|
|
70
|
+
':root { --color-data-categorical-green: #008000; }',
|
|
71
|
+
'app.css',
|
|
72
|
+
),
|
|
73
|
+
).toBeUndefined();
|
|
74
|
+
expect(
|
|
75
|
+
await run(
|
|
76
|
+
`/* @generated by \`astryx theme build\` */
|
|
77
|
+
@scope ([data-astryx-theme="ocean"]) {
|
|
78
|
+
:scope { --color-data-categorical-green: #008000; }
|
|
79
|
+
}`,
|
|
80
|
+
'theme.css',
|
|
81
|
+
),
|
|
82
|
+
).toBeUndefined();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
import migrateDeprecatedThemeSurface, {
|
|
11
11
|
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
12
12
|
} from './migrate-deprecated-theme-surface.mjs';
|
|
13
|
+
import migrateFieldInputStyling, {
|
|
14
|
+
meta as migrateFieldInputStylingMeta,
|
|
15
|
+
} from './migrate-field-input-styling.mjs';
|
|
16
|
+
import validateDataTokenOwnership, {
|
|
17
|
+
meta as validateDataTokenOwnershipMeta,
|
|
18
|
+
} from './validate-data-token-ownership.mjs';
|
|
13
19
|
|
|
14
20
|
export default [
|
|
15
21
|
{
|
|
@@ -17,4 +23,14 @@ export default [
|
|
|
17
23
|
transform: migrateDeprecatedThemeSurface,
|
|
18
24
|
meta: migrateDeprecatedThemeSurfaceMeta,
|
|
19
25
|
},
|
|
26
|
+
{
|
|
27
|
+
name: 'validate-data-token-ownership',
|
|
28
|
+
transform: validateDataTokenOwnership,
|
|
29
|
+
meta: validateDataTokenOwnershipMeta,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'migrate-field-input-styling',
|
|
33
|
+
transform: migrateFieldInputStyling,
|
|
34
|
+
meta: migrateFieldInputStylingMeta,
|
|
35
|
+
},
|
|
20
36
|
];
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Migrate root styling on Field-composed inputs to their named parts.
|
|
5
|
+
*
|
|
6
|
+
* Field-composed inputs no longer accept root `xstyle`, `className`, or
|
|
7
|
+
* `style` (family:input-fields FR10). Each rename keeps the element the
|
|
8
|
+
* styling reached before: components whose root styling painted the visual
|
|
9
|
+
* control box move to `controlXstyle`/`controlClassName`/`controlStyle`;
|
|
10
|
+
* components whose root styling reached the Field box move to
|
|
11
|
+
* `containerXstyle`/`containerClassName`/`containerStyle`.
|
|
12
|
+
*
|
|
13
|
+
* Only JSX attributes written directly on an element bound to an Astryx import
|
|
14
|
+
* are renamed (named, aliased, or namespace imports). Spread attributes,
|
|
15
|
+
* wrappers that forward their own props, and unrelated components of the same
|
|
16
|
+
* name are left alone; those callsites fail type-checking and are migrated by
|
|
17
|
+
* hand. When the target attribute is already present, the root attribute gets a
|
|
18
|
+
* TODO instead of a rename so no value is silently dropped.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {transformProp} from '../../transform-prop.mjs';
|
|
22
|
+
|
|
23
|
+
export const meta = {
|
|
24
|
+
title: 'Migrate input root styling to container/control parts',
|
|
25
|
+
description:
|
|
26
|
+
'Renames root `xstyle`/`className`/`style` on Field-composed inputs to the `control*` or `container*` part they styled before.',
|
|
27
|
+
fileExtensions: ['.tsx', '.jsx', '.ts', '.js', '.mjs', '.cjs'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Components whose root styling painted the visual control box. */
|
|
31
|
+
const CONTROL_COMPONENTS = [
|
|
32
|
+
'TextInput',
|
|
33
|
+
'TextArea',
|
|
34
|
+
'NumberInput',
|
|
35
|
+
'FileInput',
|
|
36
|
+
'DateInput',
|
|
37
|
+
'DateRangeInput',
|
|
38
|
+
'DateTimeInput',
|
|
39
|
+
'TimeInput',
|
|
40
|
+
'Selector',
|
|
41
|
+
'MultiSelector',
|
|
42
|
+
'ComplexSelector',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** Components whose root styling reached the Field box. */
|
|
46
|
+
const CONTAINER_COMPONENTS = [
|
|
47
|
+
'Typeahead',
|
|
48
|
+
'Tokenizer',
|
|
49
|
+
'CheckboxList',
|
|
50
|
+
'RadioList',
|
|
51
|
+
'Slider',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Field-root members that also render inside InputGroup. There Field is absent
|
|
56
|
+
* and root styling painted the control surface, so it moves to `control*`.
|
|
57
|
+
*/
|
|
58
|
+
const GROUPED_CONTROL_COMPONENTS = new Set(['Typeahead']);
|
|
59
|
+
|
|
60
|
+
/** @type {ReadonlyMap<string, 'control' | 'container'>} */
|
|
61
|
+
const PART_BY_COMPONENT = new Map([
|
|
62
|
+
...CONTROL_COMPONENTS.map(name => /** @type {const} */ ([name, 'control'])),
|
|
63
|
+
...CONTAINER_COMPONENTS.map(
|
|
64
|
+
name => /** @type {const} */ ([name, 'container']),
|
|
65
|
+
),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const ROOT_STYLE_PROPS = /** @type {const} */ ({
|
|
69
|
+
xstyle: 'Xstyle',
|
|
70
|
+
className: 'ClassName',
|
|
71
|
+
style: 'Style',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const PACKAGE_PATTERN = /^@(astryxdesign|xds)\/core(\/[A-Za-z]+)?$/u;
|
|
75
|
+
|
|
76
|
+
const TODO =
|
|
77
|
+
' TODO(astryx upgrade): root styling is no longer accepted here; merge it into ';
|
|
78
|
+
|
|
79
|
+
/** @type {ReadonlyMap<string, ReadonlySet<string>>} */
|
|
80
|
+
const COMPONENT_PROPS = new Map(
|
|
81
|
+
[...PART_BY_COMPONENT.keys()].map(name => [
|
|
82
|
+
name,
|
|
83
|
+
new Set(Object.keys(ROOT_STYLE_PROPS)),
|
|
84
|
+
]),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
89
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
90
|
+
* @returns {string | undefined}
|
|
91
|
+
*/
|
|
92
|
+
export default function migrateFieldInputStyling(file, api) {
|
|
93
|
+
if (!/xstyle|className|style/u.test(file.source)) return undefined;
|
|
94
|
+
if (![...PART_BY_COMPONENT.keys()].some(name => file.source.includes(name))) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const j = api.jscodeshift;
|
|
99
|
+
const root = j(file.source);
|
|
100
|
+
const matchesImport = (/** @type {string} */ source) =>
|
|
101
|
+
PACKAGE_PATTERN.test(source);
|
|
102
|
+
|
|
103
|
+
// Local names that resolve to an Astryx InputGroup (named or namespace).
|
|
104
|
+
/** @type {Set<string>} */
|
|
105
|
+
const inputGroupNames = new Set();
|
|
106
|
+
/** @type {Set<string>} */
|
|
107
|
+
const namespaceNames = new Set();
|
|
108
|
+
root.find(j.ImportDeclaration).forEach((/** @type {any} */ path) => {
|
|
109
|
+
const source = path.node.source.value;
|
|
110
|
+
if (path.node.importKind === 'type') return;
|
|
111
|
+
if (typeof source !== 'string' || !matchesImport(source)) return;
|
|
112
|
+
for (const specifier of path.node.specifiers ?? []) {
|
|
113
|
+
if (specifier.importKind === 'type') continue;
|
|
114
|
+
if (
|
|
115
|
+
specifier.type === 'ImportSpecifier' &&
|
|
116
|
+
specifier.imported?.name === 'InputGroup'
|
|
117
|
+
) {
|
|
118
|
+
inputGroupNames.add(specifier.local?.name ?? 'InputGroup');
|
|
119
|
+
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
120
|
+
namespaceNames.add(specifier.local.name);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/** @param {any} elementPath a JSXElement path */
|
|
126
|
+
const isInputGroup = elementPath => {
|
|
127
|
+
const name = elementPath.node.openingElement.name;
|
|
128
|
+
let localName;
|
|
129
|
+
if (name.type === 'JSXIdentifier' && inputGroupNames.has(name.name)) {
|
|
130
|
+
localName = name.name;
|
|
131
|
+
} else if (
|
|
132
|
+
name.type === 'JSXMemberExpression' &&
|
|
133
|
+
name.object?.type === 'JSXIdentifier' &&
|
|
134
|
+
name.property?.type === 'JSXIdentifier' &&
|
|
135
|
+
name.property.name === 'InputGroup' &&
|
|
136
|
+
namespaceNames.has(name.object.name)
|
|
137
|
+
) {
|
|
138
|
+
localName = name.object.name;
|
|
139
|
+
} else {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const scope = elementPath.scope?.lookup(localName);
|
|
143
|
+
return scope?.path.node.type === 'Program';
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** @param {any} openingPath a JSXOpeningElement path */
|
|
147
|
+
const isInsideInputGroup = openingPath => {
|
|
148
|
+
for (let p = openingPath.parent?.parent; p; p = p.parent) {
|
|
149
|
+
if (p.node.type === 'JSXElement' && isInputGroup(p)) return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
let changed = false;
|
|
155
|
+
transformProp(
|
|
156
|
+
root,
|
|
157
|
+
j,
|
|
158
|
+
{matchesImport, components: COMPONENT_PROPS},
|
|
159
|
+
(propPath, {component}) => {
|
|
160
|
+
const attribute = propPath.node;
|
|
161
|
+
const openingPath = propPath.parent;
|
|
162
|
+
let part = PART_BY_COMPONENT.get(component);
|
|
163
|
+
if (!part) return;
|
|
164
|
+
if (
|
|
165
|
+
part === 'container' &&
|
|
166
|
+
GROUPED_CONTROL_COMPONENTS.has(component) &&
|
|
167
|
+
isInsideInputGroup(openingPath)
|
|
168
|
+
) {
|
|
169
|
+
part = 'control';
|
|
170
|
+
}
|
|
171
|
+
const name = /** @type {keyof typeof ROOT_STYLE_PROPS} */ (
|
|
172
|
+
attribute.name.name
|
|
173
|
+
);
|
|
174
|
+
const next = part + ROOT_STYLE_PROPS[name];
|
|
175
|
+
const present = (openingPath.node.attributes ?? []).some(
|
|
176
|
+
(/** @type {any} */ a) =>
|
|
177
|
+
a.type === 'JSXAttribute' && a.name?.name === next,
|
|
178
|
+
);
|
|
179
|
+
if (present) {
|
|
180
|
+
const comment = `${TODO}\`${next}\`. `;
|
|
181
|
+
attribute.comments ??= [];
|
|
182
|
+
if (
|
|
183
|
+
!attribute.comments.some(
|
|
184
|
+
(/** @type {any} */ c) => c.value === comment,
|
|
185
|
+
)
|
|
186
|
+
) {
|
|
187
|
+
attribute.comments.push(j.commentBlock(comment, true, false));
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
attribute.name = j.jsxIdentifier(next);
|
|
193
|
+
changed = true;
|
|
194
|
+
},
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return changed ? root.toSource({quote: 'single'}) : undefined;
|
|
198
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Report data-token consumers that need an ownership migration.
|
|
5
|
+
*
|
|
6
|
+
* @input Consumer JavaScript/TypeScript source and generated theme CSS
|
|
7
|
+
* @output No rewritten source; actionable upgrade errors for fallback-less
|
|
8
|
+
* `var(--color-data-*)` uses (in JS strings, embedded or whole, and in CSS)
|
|
9
|
+
* and stale generated root-default artifacts
|
|
10
|
+
* @position Next-release upgrade validation for spec:AST-066
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
|
|
15
|
+
export const meta = {
|
|
16
|
+
title: 'Validate data-token ownership',
|
|
17
|
+
description:
|
|
18
|
+
'Reports fallback-less data-token var() uses in source strings and stylesheets for manual CSS/non-CSS migration, and stale generated theme CSS that still owns root defaults.',
|
|
19
|
+
fileExtensions: ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.css'],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// A use without a fallback; `var(--color-data-x, <fallback>)` stays valid.
|
|
23
|
+
const DIRECT_DATA_VAR = /var\(\s*(--color-data-[a-z0-9-]+)\s*\)/u;
|
|
24
|
+
const CSS_COMMENT = /\/\*[\s\S]*?\*\//gu;
|
|
25
|
+
const GENERATED_THEME_HEADER = '@generated by `astryx theme build`';
|
|
26
|
+
const ROOT_DATA_DECLARATION = /:root\s*\{[^}]*--color-data-/su;
|
|
27
|
+
|
|
28
|
+
/** @param {any} node */
|
|
29
|
+
function staticString(node) {
|
|
30
|
+
if (
|
|
31
|
+
(node?.type === 'StringLiteral' || node?.type === 'Literal') &&
|
|
32
|
+
typeof node.value === 'string'
|
|
33
|
+
) {
|
|
34
|
+
return node.value;
|
|
35
|
+
}
|
|
36
|
+
if (node?.type === 'TemplateLiteral') {
|
|
37
|
+
// Each static chunk of the template; a use can sit between expressions.
|
|
38
|
+
return (node.quasis ?? [])
|
|
39
|
+
.map((/** @type {any} */ q) => q?.value?.cooked ?? q?.value?.raw ?? '')
|
|
40
|
+
.join('\u0000');
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
47
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
48
|
+
* @returns {undefined}
|
|
49
|
+
*/
|
|
50
|
+
export default function validateDataTokenOwnership(file, api) {
|
|
51
|
+
if (!file.source.includes('--color-data-')) return undefined;
|
|
52
|
+
|
|
53
|
+
if (path.extname(file.path) === '.css') {
|
|
54
|
+
if (
|
|
55
|
+
file.source.includes(GENERATED_THEME_HEADER) &&
|
|
56
|
+
ROOT_DATA_DECLARATION.test(file.source)
|
|
57
|
+
) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
'This generated theme CSS still emits canonical data defaults at :root. Rebuild it with `astryx theme build`; defaults now come from compiled dataVars consumers.',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const uncommented = file.source.replace(CSS_COMMENT, comment =>
|
|
63
|
+
comment.replace(/[^\n]/gu, ' '),
|
|
64
|
+
);
|
|
65
|
+
const cssMatch = DIRECT_DATA_VAR.exec(uncommented);
|
|
66
|
+
if (cssMatch) {
|
|
67
|
+
const line = uncommented.slice(0, cssMatch.index).split('\n').length;
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Raw var(${cssMatch[1]}) without a fallback at line ${line} needs manual migration: compiled dataVars output is not guaranteed in this stylesheet, so add an explicit fallback or style the element from code that imports dataVars from @astryxdesign/core/theme/dataTokens.stylex.`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const j = api.jscodeshift;
|
|
76
|
+
const root = j(file.source);
|
|
77
|
+
/** @type {{token: string, line: number|null}|null} */
|
|
78
|
+
let found = null;
|
|
79
|
+
const inspect = (/** @type {any} */ node) => {
|
|
80
|
+
if (found) return;
|
|
81
|
+
const value = staticString(node);
|
|
82
|
+
const match =
|
|
83
|
+
typeof value === 'string' ? value.match(DIRECT_DATA_VAR) : null;
|
|
84
|
+
if (match) {
|
|
85
|
+
found = {token: match[1], line: node.loc?.start?.line ?? null};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/** @param {any} nodePath */
|
|
90
|
+
const inspectPath = nodePath => inspect(nodePath.node);
|
|
91
|
+
root.find(j.StringLiteral).forEach(inspectPath);
|
|
92
|
+
root.find(j.Literal).forEach(inspectPath);
|
|
93
|
+
root.find(j.TemplateLiteral).forEach(inspectPath);
|
|
94
|
+
|
|
95
|
+
if (found) {
|
|
96
|
+
const {token, line} = found;
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Direct var(${token})${line == null ? '' : ` at line ${line}`} needs manual migration: CSS-capable code imports dataVars from @astryxdesign/core/theme/dataTokens.stylex; Canvas and other non-CSS APIs use resolveThemeToken() or useTheme().token().`,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
@@ -157,7 +157,7 @@ export const docs = {
|
|
|
157
157
|
{
|
|
158
158
|
title: 'useTheme Hook',
|
|
159
159
|
content: [
|
|
160
|
-
{type: 'prose', text: '`useTheme()` reads the nearest Theme and effective color mode from React context.
|
|
160
|
+
{type: 'prose', text: '`useTheme()` reads the nearest Theme and effective color mode from React context. Prefer `dataVars` for CSS-capable SVG and DOM values. Use this hook for canvas, charts, maps, third-party configuration objects, or an SVG API that requires a concrete JavaScript color instead of a `var(...)` reference.'},
|
|
161
161
|
{type: 'code', lang: 'tsx', label: 'Access resolved token values in React', code: "import {useMemo} from 'react';\nimport {useTheme} from '@astryxdesign/core/theme';\n\nfunction ChartConfig() {\n const {mode, tokens} = useTheme();\n const options = useMemo(() => ({\n mode,\n textColor: tokens['--color-text-primary'],\n gridColor: tokens['--color-border'],\n seriesColor: tokens['--color-data-categorical-blue'],\n }), [mode, tokens]);\n return <Chart options={options} />;\n}"},
|
|
162
162
|
{type: 'prose', text: 'Prefer CSS variables for ordinary styling. See {@link generic:use-a-theme} for the provider setup, and {@link namespace:tokens} for the full token reference.'},
|
|
163
163
|
],
|
|
@@ -17,14 +17,14 @@ export const docs = {
|
|
|
17
17
|
"order": 20
|
|
18
18
|
},
|
|
19
19
|
"category": "foundations",
|
|
20
|
-
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import
|
|
20
|
+
"description": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Retaining any member emits the complete 56-variable group; an unused graph emits none.",
|
|
21
21
|
"sections": [
|
|
22
22
|
{
|
|
23
23
|
"title": "Data Visualization Tokens",
|
|
24
24
|
"content": [
|
|
25
25
|
{
|
|
26
26
|
"type": "prose",
|
|
27
|
-
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import
|
|
27
|
+
"text": "Colors for charts and graphs: one categorical accent per series, a neutral for labels and reference lines, and sequential ramps from 5 (darkest) to 1 (lightest) for ordered scales and heatmaps. Import dataVars from @astryxdesign/core/theme/dataTokens.stylex for CSS-capable code. Retaining any member emits the complete 56-variable group; an unused graph emits none."
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"type": "table",
|
|
@@ -28,7 +28,7 @@ export const docs = {
|
|
|
28
28
|
},
|
|
29
29
|
{
|
|
30
30
|
"type": "prose",
|
|
31
|
-
"text": "See {@link namespace:styling} for
|
|
31
|
+
"text": "Use `dataVars` for StyleX, DOM styles, and SVG presentation attributes. Canvas and other APIs that require concrete mode-resolved values use `resolveThemeToken()` or `useTheme().token()` instead. Raw CSS may use the stable custom-property names only when compiled dataVars output is guaranteed or the declaration carries an explicit fallback. See {@link namespace:styling} for xstyle, className, and compound component patterns, and {@link generic:author-a-theme} for overriding tokens with defineTheme."
|
|
32
32
|
}
|
|
33
33
|
]
|
|
34
34
|
}
|
package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx
CHANGED
|
@@ -47,7 +47,7 @@ export default function ComplexSelectorDeadlinePicker() {
|
|
|
47
47
|
value={value}
|
|
48
48
|
onChange={setValue}
|
|
49
49
|
triggerLabel={formatDeadline(value)}
|
|
50
|
-
|
|
50
|
+
controlStyle={{width: 320}}>
|
|
51
51
|
{(selectedValue, onChange, close) => {
|
|
52
52
|
const set = (patch: Partial<Deadline>) =>
|
|
53
53
|
onChange({...selectedValue, ...patch});
|
|
@@ -184,7 +184,7 @@ export default function ComplexSelectorShowcase() {
|
|
|
184
184
|
value={value}
|
|
185
185
|
onChange={setValue}
|
|
186
186
|
triggerLabel={`${value.fruit} · ${value.ripeness}`}
|
|
187
|
-
|
|
187
|
+
controlStyle={{width: 280}}>
|
|
188
188
|
{(selectedValue, onChange, close) => (
|
|
189
189
|
<FruitRipenessGrid
|
|
190
190
|
value={selectedValue}
|
|
@@ -175,7 +175,7 @@ export default function ComplexSelectorTreeSearch() {
|
|
|
175
175
|
value={value}
|
|
176
176
|
onChange={setValue}
|
|
177
177
|
triggerLabel={value.path}
|
|
178
|
-
|
|
178
|
+
controlStyle={{width: 360}}>
|
|
179
179
|
{(selectedValue, onChange, close) => (
|
|
180
180
|
<DestinationSearch
|
|
181
181
|
value={selectedValue}
|
|
@@ -29,7 +29,7 @@ export default function InternationalizationProviderShippedLocale() {
|
|
|
29
29
|
<SegmentedControlItem value="fr-FR" label="FR" />
|
|
30
30
|
</SegmentedControl>
|
|
31
31
|
<Selector
|
|
32
|
-
|
|
32
|
+
controlStyle={{width: 300}}
|
|
33
33
|
label="Billing region"
|
|
34
34
|
options={[
|
|
35
35
|
{value: 'americas', label: 'Americas'},
|
|
@@ -9,7 +9,7 @@ export default function SelectorClearable() {
|
|
|
9
9
|
const [value, setValue] = useState<string | null>('engineering');
|
|
10
10
|
return (
|
|
11
11
|
<Selector
|
|
12
|
-
|
|
12
|
+
controlStyle={{width: 300}}
|
|
13
13
|
label="Department"
|
|
14
14
|
options={[
|
|
15
15
|
{value: 'engineering', label: 'Engineering'},
|
|
@@ -32,7 +32,7 @@ export default function SelectorOptionDescriptions() {
|
|
|
32
32
|
return (
|
|
33
33
|
<Stack direction="vertical" gap={6}>
|
|
34
34
|
<Selector
|
|
35
|
-
|
|
35
|
+
controlStyle={{width: 320}}
|
|
36
36
|
label="Visibility"
|
|
37
37
|
description="Default trigger: one line at the size token."
|
|
38
38
|
options={VISIBILITY}
|
|
@@ -40,7 +40,7 @@ export default function SelectorOptionDescriptions() {
|
|
|
40
40
|
onChange={setCondensed}
|
|
41
41
|
/>
|
|
42
42
|
<Selector
|
|
43
|
-
|
|
43
|
+
controlStyle={{width: 320}}
|
|
44
44
|
label="Visibility"
|
|
45
45
|
description="A stacked SelectorOption: the description gets its own line, and the trigger grows by exactly one line."
|
|
46
46
|
options={VISIBILITY}
|
|
@@ -9,7 +9,7 @@ export default function SelectorShowcase() {
|
|
|
9
9
|
const [value, setValue] = useState<string | undefined>();
|
|
10
10
|
return (
|
|
11
11
|
<Selector
|
|
12
|
-
|
|
12
|
+
controlStyle={{width: 300}}
|
|
13
13
|
label="Fruit"
|
|
14
14
|
options={['Apple', 'Banana', 'Orange', 'Mango', 'Pineapple']}
|
|
15
15
|
placeholder="Select a fruit..."
|
|
@@ -44,7 +44,7 @@ export default function TokenizerCreatable() {
|
|
|
44
44
|
onChange={items => setTags(items)}
|
|
45
45
|
hasCreate
|
|
46
46
|
placeholder="Type a tag and press Enter..."
|
|
47
|
-
|
|
47
|
+
containerStyle={{width: 400}}
|
|
48
48
|
/>
|
|
49
49
|
</Stack>
|
|
50
50
|
<Stack direction="vertical" gap={1}>
|
|
@@ -59,7 +59,7 @@ export default function TokenizerCreatable() {
|
|
|
59
59
|
hasCreate
|
|
60
60
|
hasEntriesOnFocus
|
|
61
61
|
placeholder="Search or type a new name..."
|
|
62
|
-
|
|
62
|
+
containerStyle={{width: 400}}
|
|
63
63
|
/>
|
|
64
64
|
</Stack>
|
|
65
65
|
</Stack>
|