@astryxdesign/cli 0.7.9-canary.f9281ef → 0.7.9
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/CHANGELOG.md +80 -0
- package/README.md +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -5
- package/api/swizzle/copy/copy.d.mts +17 -1
- package/api/swizzle/copy/copy.mjs +240 -5
- package/api/swizzle/swizzle.doc.mjs +1 -1
- package/api/swizzle/swizzle.type.mjs +1 -1
- package/api/theme/build/build.mjs +342 -72
- package/api/theme/build/core-interception.mjs +92 -29
- package/api/theme/build/icon-imports.d.mts +35 -4
- package/api/theme/build/icon-imports.mjs +299 -38
- package/assets/discover/official-packages.json +8 -0
- package/assets/docs/author-a-theme.doc.mjs +3 -1
- package/assets/docs/icons.doc.mjs +29 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarDaysHookUsage.tsx +71 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.doc.mjs +15 -0
- package/assets/templates/blocks/components/Hooks/useInputContainerHookUsage.tsx +93 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useMergedRefsHookUsage.tsx +78 -0
- package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollLockHookUsage.tsx +80 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useScrollOverflowHookUsage.tsx +94 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.doc.mjs +19 -0
- package/assets/templates/blocks/components/Icon/useIconHookUsage.tsx +68 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkComponentHookUsage.tsx +89 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.doc.mjs +21 -0
- package/assets/templates/blocks/components/Overlay/useOverlayHookUsage.tsx +49 -0
- package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableSortableStateHookUsage.tsx +61 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.doc.mjs +15 -0
- package/assets/templates/blocks/components/usePanGesture/PanDraggableBox.tsx +98 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.doc.mjs +14 -0
- package/assets/templates/blocks/components/usePanGesture/PanPlayingCard.tsx +147 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +30 -4
- package/assets/theme.template.ts +14 -2
- package/authoring/doctypes/base/type.ts +41 -0
- package/authoring/doctypes/component/component.doc.mjs +7 -1
- package/authoring/doctypes/component/type.ts +5 -0
- package/authoring/index.d.ts +2 -0
- package/clients/cli/commands/swizzle.mjs +10 -0
- package/clients/cli/lib/component-format.mjs +49 -0
- package/foundation/discovery/component-discovery.mjs +17 -6
- package/foundation/response/response-types.doc.mjs +1 -1
- package/package.json +9 -9
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Resolve importable icon registries
|
|
4
|
+
* Resolve importable icon registries, or component icon slot maps, for the
|
|
5
|
+
* selected theme export.
|
|
5
6
|
*
|
|
6
|
-
* @input Loaded theme export identity,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* @input Loaded theme export identity, the theme field to carry (`icons` or
|
|
8
|
+
* `componentIcons`), plus the caller's source reader and the theme loader's
|
|
9
|
+
* resolver (this module performs no environment access).
|
|
10
|
+
* @output Import bindings and an expression preserving inherited values.
|
|
9
11
|
* @position Private theme-build packaging helper; never evaluates authored source.
|
|
10
12
|
*/
|
|
11
13
|
|
|
@@ -21,15 +23,25 @@ import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
|
|
|
21
23
|
* @property {string} exportName
|
|
22
24
|
* @property {string} [iconsSpecifierImportPath]
|
|
23
25
|
* @property {string} [iconsSpecifierLocalName]
|
|
26
|
+
* @property {string} [mergeName] - Set when `expression` calls the slot merge
|
|
27
|
+
* function, which the module must declare under this name.
|
|
24
28
|
*/
|
|
25
29
|
|
|
26
30
|
/** @typedef {{kind: 'reference', module: any, binding: any, members: string[]}} RegistryReference */
|
|
27
31
|
/**
|
|
28
|
-
* `entries` marks a package theme read for its
|
|
29
|
-
* `icons
|
|
30
|
-
*
|
|
32
|
+
* `entries` marks a package theme read for its entries: its public field
|
|
33
|
+
* (node-valued `icons`, or the static `componentIcons` view) merged with the
|
|
34
|
+
* `__` field that holds its functions, if any. `object` is an inline
|
|
35
|
+
* `componentIcons` object: each slot is a static value or an imported one.
|
|
36
|
+
* @typedef {{json: unknown} | {ref: RegistryReference} | {object: Array<[string, SlotData]>}} SlotData
|
|
37
|
+
* A `merge` with `theme` set merges a theme's own values over its base's;
|
|
38
|
+
* any other merge is a spread inside one object.
|
|
39
|
+
* @typedef {{kind: 'registry', ref: RegistryReference, preferredName: string, override?: boolean, entries?: boolean} | {kind: 'merge', base: RegistryPlan, own: RegistryPlan, theme?: boolean} | {kind: 'object', entries: Array<[string, SlotData]>}} RegistryPlan
|
|
31
40
|
*/
|
|
32
41
|
|
|
42
|
+
/** Marks a node that is not a static JSON value. */
|
|
43
|
+
const NOT_STATIC = Symbol('not static');
|
|
44
|
+
|
|
33
45
|
/** @param {any} node */
|
|
34
46
|
function unwrap(node) {
|
|
35
47
|
while (
|
|
@@ -83,8 +95,19 @@ function bindingNames(pattern) {
|
|
|
83
95
|
return [];
|
|
84
96
|
}
|
|
85
97
|
|
|
86
|
-
/** @param {string} [name] @param {string} [reason] @returns {never} */
|
|
87
|
-
function
|
|
98
|
+
/** @param {string} [name] @param {string} [reason] @param {string} [field] @returns {never} */
|
|
99
|
+
function registryError(name, reason = '', field = 'icons') {
|
|
100
|
+
if (field === 'componentIcons') {
|
|
101
|
+
const value = name ? `\`componentIcons: ${name}\`` : 'componentIcons';
|
|
102
|
+
throw new AstryxError(
|
|
103
|
+
`Theme sets ${value} but the build cannot carry it. ` +
|
|
104
|
+
(reason ? `${reason} ` : '') +
|
|
105
|
+
'A built theme carries names, null, and requests made of static values, ' +
|
|
106
|
+
'constants, or imported bindings, and slot functions imported from their own module.',
|
|
107
|
+
undefined,
|
|
108
|
+
ERROR_CODES.ERR_THEME_INVALID,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
88
111
|
const registry = name ? `\`icons: ${name}\`` : 'an icon registry';
|
|
89
112
|
throw new AstryxError(
|
|
90
113
|
`Theme sets ${registry} but no import for the registry was found. ` +
|
|
@@ -106,9 +129,16 @@ function invalidRegistry(name, reason = '') {
|
|
|
106
129
|
* base is read for its entries (`__icons`) as well as its node-valued `icons`,
|
|
107
130
|
* and a built base module's `__icons` field is followed instead of `icons`.
|
|
108
131
|
*
|
|
132
|
+
* With `field: 'componentIcons'`, the same tracing carries a theme's slot
|
|
133
|
+
* values: a slot function must come from an import, and an inline object may
|
|
134
|
+
* also hold static values (names, `null`, requests), written as JSON. A built
|
|
135
|
+
* base module is read through its export, like a package theme. A theme's own
|
|
136
|
+
* slots merge over its base's through `mergeName`, which skips an
|
|
137
|
+
* `undefined` slot as `defineTheme` does.
|
|
138
|
+
*
|
|
109
139
|
* @param {string} filePath
|
|
110
140
|
* @param {string | undefined} exportName
|
|
111
|
-
* @param {{hasIcons: boolean, functionEntries?: boolean, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
141
|
+
* @param {{hasIcons: boolean, functionEntries?: boolean, field?: 'icons' | 'componentIcons', mergeName?: string, readSource: (filename: string) => string, resolveModule: (specifier: string, fromFile: string) => string | Promise<string>, reservedNames?: string[], rawInput?: boolean}} options
|
|
112
142
|
* @returns {Promise<IconImports | null>}
|
|
113
143
|
*/
|
|
114
144
|
export async function resolveIconImports(
|
|
@@ -117,12 +147,20 @@ export async function resolveIconImports(
|
|
|
117
147
|
{
|
|
118
148
|
hasIcons,
|
|
119
149
|
functionEntries = false,
|
|
150
|
+
field = 'icons',
|
|
151
|
+
mergeName = 'mergeComponentIcons',
|
|
120
152
|
readSource,
|
|
121
153
|
resolveModule,
|
|
122
154
|
reservedNames = [],
|
|
123
155
|
rawInput = false,
|
|
124
156
|
},
|
|
125
157
|
) {
|
|
158
|
+
const entriesField = `__${field}`;
|
|
159
|
+
const staticSlots = field === 'componentIcons';
|
|
160
|
+
const defaultName = staticSlots ? 'themeComponentIcons' : 'themeIcons';
|
|
161
|
+
/** @param {string} [name] @param {string} [reason] @returns {never} */
|
|
162
|
+
const invalidRegistry = (name, reason) => registryError(name, reason, field);
|
|
163
|
+
|
|
126
164
|
if (exportName === undefined) {
|
|
127
165
|
if (!hasIcons) return null;
|
|
128
166
|
invalidRegistry(
|
|
@@ -410,11 +448,11 @@ export async function resolveIconImports(
|
|
|
410
448
|
// `__icons`. Read both only when the built theme needs its functions, so
|
|
411
449
|
// a theme without them keeps its existing output.
|
|
412
450
|
return functionEntries
|
|
413
|
-
? {kind: 'registry', ref, preferredName:
|
|
451
|
+
? {kind: 'registry', ref, preferredName: defaultName, entries: true}
|
|
414
452
|
: {
|
|
415
453
|
kind: 'registry',
|
|
416
|
-
ref: {...ref, members: [...ref.members,
|
|
417
|
-
preferredName:
|
|
454
|
+
ref: {...ref, members: [...ref.members, field]},
|
|
455
|
+
preferredName: defaultName,
|
|
418
456
|
};
|
|
419
457
|
}
|
|
420
458
|
|
|
@@ -431,9 +469,42 @@ export async function resolveIconImports(
|
|
|
431
469
|
});
|
|
432
470
|
}
|
|
433
471
|
|
|
472
|
+
/**
|
|
473
|
+
* Whether a node is a built theme module's theme object (`__built: true`).
|
|
474
|
+
* @param {any} module @param {any} node @param {Set<string>} [seen]
|
|
475
|
+
* @returns {boolean}
|
|
476
|
+
*/
|
|
477
|
+
function isBuiltTheme(module, node, seen = new Set()) {
|
|
478
|
+
node = unwrap(node);
|
|
479
|
+
if (node?.type === 'Identifier') {
|
|
480
|
+
if (seen.has(node.name)) return false;
|
|
481
|
+
seen.add(node.name);
|
|
482
|
+
const binding = module.bindings.get(node.name);
|
|
483
|
+
return (
|
|
484
|
+
binding?.kind === 'const' && isBuiltTheme(module, binding.node, seen)
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
return (
|
|
488
|
+
node?.type === 'ObjectExpression' &&
|
|
489
|
+
node.properties.some(
|
|
490
|
+
(/** @type {any} */ item) =>
|
|
491
|
+
['ObjectProperty', 'Property'].includes(item.type) &&
|
|
492
|
+
propertyName(item.key) === '__built' &&
|
|
493
|
+
unwrap(item.value)?.value === true,
|
|
494
|
+
)
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
434
498
|
/** @param {RegistryReference} ref @param {boolean} [rejectOpaque] @returns {Promise<RegistryPlan | null>} */
|
|
435
499
|
async function themeReference(ref, rejectOpaque = false) {
|
|
436
500
|
const target = await importedExport(ref);
|
|
501
|
+
if (target && staticSlots) {
|
|
502
|
+
// A built module's generated code is not traced: the module is imported
|
|
503
|
+
// and read through its export, like a package theme.
|
|
504
|
+
const selected = await selectedExport(target.module, target.name);
|
|
505
|
+
if (!selected.binding && isBuiltTheme(target.module, selected.node))
|
|
506
|
+
return packageTheme(ref);
|
|
507
|
+
}
|
|
437
508
|
if (target) return exportedTheme(target.module, target.name, rejectOpaque);
|
|
438
509
|
if (rejectOpaque)
|
|
439
510
|
invalidRegistry(
|
|
@@ -474,13 +545,15 @@ export async function resolveIconImports(
|
|
|
474
545
|
return {
|
|
475
546
|
kind: 'registry',
|
|
476
547
|
ref,
|
|
477
|
-
preferredName: preferredName ??
|
|
548
|
+
preferredName: preferredName ?? defaultName,
|
|
478
549
|
// A namespace's exported registry can be redirected to an icon module;
|
|
479
550
|
// a named theme's .icons cannot be imported from that sidecar.
|
|
480
551
|
override:
|
|
481
552
|
ref.binding.importedName === '*' && ref.members.length === 1,
|
|
482
553
|
};
|
|
483
554
|
}
|
|
555
|
+
if (staticSlots && node?.type === 'ObjectExpression')
|
|
556
|
+
return slotObject(module, node);
|
|
484
557
|
// Spreads merge in order. An object adding no entries, such as `{}`, is no
|
|
485
558
|
// local registry: a child keeps its inherited icons and a root emits none.
|
|
486
559
|
if (
|
|
@@ -501,6 +574,150 @@ export async function resolveIconImports(
|
|
|
501
574
|
invalidRegistry(preferredName ?? rootIdentifier(node) ?? undefined);
|
|
502
575
|
}
|
|
503
576
|
|
|
577
|
+
/** @param {any} item @returns {string | null} A plain property's static key. */
|
|
578
|
+
function plainKey(item) {
|
|
579
|
+
if (
|
|
580
|
+
!['ObjectProperty', 'Property'].includes(item.type) ||
|
|
581
|
+
item.method ||
|
|
582
|
+
(item.kind && item.kind !== 'init')
|
|
583
|
+
)
|
|
584
|
+
return null;
|
|
585
|
+
if (!item.computed) return propertyName(item.key);
|
|
586
|
+
return typeof item.key?.value === 'string' ? item.key.value : null;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* A slot value as data the module can write: a JSON value, an imported
|
|
591
|
+
* binding (with any member reads), or an object of those. Unmutated `const`
|
|
592
|
+
* bindings and member reads on them are followed. Anything else, a function
|
|
593
|
+
* defined in the theme file included, is NOT_STATIC.
|
|
594
|
+
* @param {any} module @param {any} node @param {Set<string>} [path] - The
|
|
595
|
+
* `const` names on the current path, which a cycle would revisit.
|
|
596
|
+
* @returns {Promise<SlotData | typeof NOT_STATIC>}
|
|
597
|
+
*/
|
|
598
|
+
async function slotData(module, node, path = new Set()) {
|
|
599
|
+
node = unwrap(node);
|
|
600
|
+
if (node?.type === 'NullLiteral') return {json: null};
|
|
601
|
+
if (
|
|
602
|
+
['StringLiteral', 'NumericLiteral', 'BooleanLiteral', 'Literal'].includes(
|
|
603
|
+
node?.type,
|
|
604
|
+
) &&
|
|
605
|
+
(node.value === null || typeof node.value !== 'object')
|
|
606
|
+
)
|
|
607
|
+
return {json: node.value};
|
|
608
|
+
if (node?.type === 'TemplateLiteral' && node.expressions.length === 0)
|
|
609
|
+
return {json: node.quasis[0].value.cooked};
|
|
610
|
+
if (
|
|
611
|
+
(node?.type === 'Identifier' &&
|
|
612
|
+
node.name === 'undefined' &&
|
|
613
|
+
!module.bindings.has(node.name)) ||
|
|
614
|
+
(node?.type === 'UnaryExpression' && node.operator === 'void')
|
|
615
|
+
)
|
|
616
|
+
return {json: undefined};
|
|
617
|
+
if (node?.type === 'Identifier') {
|
|
618
|
+
const binding = module.bindings.get(node.name);
|
|
619
|
+
if (!binding || module.mutated.has(node.name) || path.has(node.name))
|
|
620
|
+
return NOT_STATIC;
|
|
621
|
+
if (binding.kind === 'import')
|
|
622
|
+
return {ref: importedReference(module, binding)};
|
|
623
|
+
if (binding.kind !== 'const') return NOT_STATIC;
|
|
624
|
+
return slotData(module, binding.node, new Set([...path, node.name]));
|
|
625
|
+
}
|
|
626
|
+
if (node?.type === 'MemberExpression' && !node.optional) {
|
|
627
|
+
const name = node.computed
|
|
628
|
+
? typeof node.property.value === 'string'
|
|
629
|
+
? node.property.value
|
|
630
|
+
: null
|
|
631
|
+
: propertyName(node.property);
|
|
632
|
+
if (name === null) return NOT_STATIC;
|
|
633
|
+
const object = await slotData(module, node.object, path);
|
|
634
|
+
if (object === NOT_STATIC) return NOT_STATIC;
|
|
635
|
+
if ('ref' in object)
|
|
636
|
+
return {ref: {...object.ref, members: [...object.ref.members, name]}};
|
|
637
|
+
if ('object' in object) {
|
|
638
|
+
// The last property with a name wins, as in the object literal.
|
|
639
|
+
const entry = [...object.object]
|
|
640
|
+
.reverse()
|
|
641
|
+
.find(([key]) => key === name);
|
|
642
|
+
return entry ? entry[1] : {json: undefined};
|
|
643
|
+
}
|
|
644
|
+
return NOT_STATIC;
|
|
645
|
+
}
|
|
646
|
+
if (node?.type !== 'ObjectExpression') return NOT_STATIC;
|
|
647
|
+
/** @type {Array<[string, SlotData]>} */
|
|
648
|
+
const entries = [];
|
|
649
|
+
for (const item of node.properties) {
|
|
650
|
+
const key = plainKey(item);
|
|
651
|
+
if (key === null) return NOT_STATIC;
|
|
652
|
+
const value = await slotData(module, item.value, path);
|
|
653
|
+
if (value === NOT_STATIC) return NOT_STATIC;
|
|
654
|
+
entries.push([key, value]);
|
|
655
|
+
}
|
|
656
|
+
return {object: entries};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/** @param {any} module @param {any} node @param {Set<string>} [seen] @returns {boolean} */
|
|
660
|
+
function isLocalFunction(module, node, seen = new Set()) {
|
|
661
|
+
node = unwrap(node);
|
|
662
|
+
if (node?.type === 'Identifier' && !seen.has(node.name)) {
|
|
663
|
+
seen.add(node.name);
|
|
664
|
+
const binding = module.bindings.get(node.name);
|
|
665
|
+
return (
|
|
666
|
+
binding?.kind === 'const' && isLocalFunction(module, binding.node, seen)
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
return ['ArrowFunctionExpression', 'FunctionExpression'].includes(
|
|
670
|
+
node?.type,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/** @param {any} module @param {any} node @param {string} slot @returns {Promise<SlotData>} */
|
|
675
|
+
async function slotValue(module, node, slot) {
|
|
676
|
+
const data = await slotData(module, node);
|
|
677
|
+
if (data !== NOT_STATIC) return data;
|
|
678
|
+
invalidRegistry(
|
|
679
|
+
undefined,
|
|
680
|
+
isLocalFunction(module, node)
|
|
681
|
+
? `The slot function for "${slot}" is defined in the theme file.`
|
|
682
|
+
: `The value for "${slot}" is neither a static value nor an imported binding.`,
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* An inline `componentIcons` object. Spreads and own slots apply in source
|
|
688
|
+
* order, as in the object itself.
|
|
689
|
+
* @param {any} module @param {any} node @returns {Promise<RegistryPlan | null>}
|
|
690
|
+
*/
|
|
691
|
+
async function slotObject(module, node) {
|
|
692
|
+
/** @type {RegistryPlan | null} */
|
|
693
|
+
let result = null;
|
|
694
|
+
/** @type {Array<[string, SlotData]> | null} */
|
|
695
|
+
let entries = null;
|
|
696
|
+
/** @param {RegistryPlan | null} next */
|
|
697
|
+
const add = next => {
|
|
698
|
+
if (next)
|
|
699
|
+
result = result ? {kind: 'merge', base: result, own: next} : next;
|
|
700
|
+
};
|
|
701
|
+
for (const item of node.properties) {
|
|
702
|
+
if (item.type === 'SpreadElement' || item.type === 'SpreadProperty') {
|
|
703
|
+
if (entries) add({kind: 'object', entries});
|
|
704
|
+
entries = null;
|
|
705
|
+
add(await registry(module, item.argument));
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
708
|
+
const key = plainKey(item);
|
|
709
|
+
if (key === null)
|
|
710
|
+
invalidRegistry(
|
|
711
|
+
undefined,
|
|
712
|
+
'A slot must be a plain property with a static name.',
|
|
713
|
+
);
|
|
714
|
+
entries ??= [];
|
|
715
|
+
entries.push([key, await slotValue(module, item.value, key)]);
|
|
716
|
+
}
|
|
717
|
+
if (entries) add({kind: 'object', entries});
|
|
718
|
+
return result;
|
|
719
|
+
}
|
|
720
|
+
|
|
504
721
|
/** @param {any} module @param {any} node @returns {Promise<Map<string, any>>} */
|
|
505
722
|
async function fields(module, node) {
|
|
506
723
|
node = unwrap(node);
|
|
@@ -516,7 +733,7 @@ export async function resolveIconImports(
|
|
|
516
733
|
if (ref) return referenceFields(ref);
|
|
517
734
|
}
|
|
518
735
|
if (node?.type === 'CallExpression' && isDefineTheme(module, node.callee)) {
|
|
519
|
-
return new Map([[
|
|
736
|
+
return new Map([[field, {plan: await theme(module, node)}]]);
|
|
520
737
|
}
|
|
521
738
|
if (node?.type !== 'ObjectExpression') invalidRegistry();
|
|
522
739
|
const result = new Map();
|
|
@@ -533,7 +750,7 @@ export async function resolveIconImports(
|
|
|
533
750
|
: propertyName(item.key);
|
|
534
751
|
if (key === null)
|
|
535
752
|
invalidRegistry(undefined, 'Computed theme keys cannot be resolved.');
|
|
536
|
-
if (![
|
|
753
|
+
if (![field, entriesField, 'extends'].includes(key)) continue;
|
|
537
754
|
if (
|
|
538
755
|
!['ObjectProperty', 'Property'].includes(item.type) ||
|
|
539
756
|
item.method ||
|
|
@@ -586,9 +803,9 @@ export async function resolveIconImports(
|
|
|
586
803
|
}
|
|
587
804
|
const config = await fields(module, node);
|
|
588
805
|
const baseField = config.get('extends');
|
|
589
|
-
// A built module keeps its
|
|
590
|
-
//
|
|
591
|
-
const iconField = config.get(
|
|
806
|
+
// A built module keeps its functions in `__icons` (or `__componentIcons`)
|
|
807
|
+
// beside the public view; those entries are the values to carry.
|
|
808
|
+
const iconField = config.get(entriesField) ?? config.get(field);
|
|
592
809
|
const base = baseField
|
|
593
810
|
? await theme(baseField.module, baseField.node)
|
|
594
811
|
: null;
|
|
@@ -597,7 +814,18 @@ export async function resolveIconImports(
|
|
|
597
814
|
? iconField.plan
|
|
598
815
|
: await registry(iconField.module, iconField.node)
|
|
599
816
|
: null;
|
|
600
|
-
|
|
817
|
+
// A root's own slot values pass through the theme merge too, so an
|
|
818
|
+
// `undefined` slot is dropped as `defineTheme` drops it.
|
|
819
|
+
if (staticSlots && own && !base)
|
|
820
|
+
return {
|
|
821
|
+
kind: 'merge',
|
|
822
|
+
base: {kind: 'object', entries: []},
|
|
823
|
+
own,
|
|
824
|
+
theme: true,
|
|
825
|
+
};
|
|
826
|
+
return base && own
|
|
827
|
+
? {kind: 'merge', base, own, theme: true}
|
|
828
|
+
: (own ?? base);
|
|
601
829
|
}
|
|
602
830
|
|
|
603
831
|
let plan;
|
|
@@ -626,7 +854,7 @@ export async function resolveIconImports(
|
|
|
626
854
|
/^[A-Za-z_$][\w$]*$/u.test(preferred) &&
|
|
627
855
|
!['default', 'await', 'yield'].includes(preferred)
|
|
628
856
|
? preferred
|
|
629
|
-
:
|
|
857
|
+
: defaultName;
|
|
630
858
|
let name = stem;
|
|
631
859
|
let counter = 1;
|
|
632
860
|
while (used.has(name)) name = `${stem}${counter++}`;
|
|
@@ -652,19 +880,8 @@ export async function resolveIconImports(
|
|
|
652
880
|
return relative.startsWith('.') ? relative : `./${relative}`;
|
|
653
881
|
}
|
|
654
882
|
|
|
655
|
-
/** @param {
|
|
656
|
-
function
|
|
657
|
-
if (value.kind === 'merge') {
|
|
658
|
-
const base = render(value.base);
|
|
659
|
-
const own = render(value.own);
|
|
660
|
-
return {
|
|
661
|
-
expression: `{...${base.expression}, ...${own.expression}}`,
|
|
662
|
-
preferredName: 'themeIcons',
|
|
663
|
-
overridePath: own.overridePath,
|
|
664
|
-
overrideLocalName: own.overrideLocalName,
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
const {ref} = value;
|
|
883
|
+
/** @param {RegistryReference} ref */
|
|
884
|
+
function importedTarget(ref) {
|
|
668
885
|
const source = importPath(ref);
|
|
669
886
|
const identity = `${source}\0${ref.binding.importedName}\0${JSON.stringify(ref.members)}`;
|
|
670
887
|
let localName = emitted.get(identity);
|
|
@@ -677,12 +894,54 @@ export async function resolveIconImports(
|
|
|
677
894
|
localName,
|
|
678
895
|
});
|
|
679
896
|
}
|
|
680
|
-
|
|
681
|
-
|
|
897
|
+
return {
|
|
898
|
+
source,
|
|
682
899
|
localName,
|
|
683
|
-
|
|
900
|
+
target: ref.members.reduce(
|
|
901
|
+
(result, member) => `${result}[${JSON.stringify(member)}]`,
|
|
902
|
+
localName,
|
|
903
|
+
),
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/** @param {SlotData} data @returns {string} */
|
|
908
|
+
function renderData(data) {
|
|
909
|
+
if ('ref' in data) return importedTarget(data.ref).target;
|
|
910
|
+
if ('object' in data)
|
|
911
|
+
return `{${data.object
|
|
912
|
+
.map(([key, entry]) => `${JSON.stringify(key)}: ${renderData(entry)}`)
|
|
913
|
+
.join(', ')}}`;
|
|
914
|
+
return data.json === undefined ? 'void 0' : JSON.stringify(data.json);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/** @param {RegistryPlan} value @returns {{expression: string, preferredName: string, overridePath?: string, overrideLocalName?: string}} */
|
|
918
|
+
function render(value) {
|
|
919
|
+
if (value.kind === 'merge') {
|
|
920
|
+
const base = render(value.base);
|
|
921
|
+
const own = render(value.own);
|
|
922
|
+
const themeMerge = staticSlots && value.theme === true;
|
|
923
|
+
if (themeMerge) usesMerge = true;
|
|
924
|
+
return {
|
|
925
|
+
expression: themeMerge
|
|
926
|
+
? `${mergeName}(${base.expression}, ${own.expression})`
|
|
927
|
+
: `{...${base.expression}, ...${own.expression}}`,
|
|
928
|
+
preferredName: defaultName,
|
|
929
|
+
overridePath: own.overridePath,
|
|
930
|
+
overrideLocalName: own.overrideLocalName,
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
if (value.kind === 'object') {
|
|
934
|
+
// An `undefined` slot stays in the object, as in the source, so the
|
|
935
|
+
// theme merge leaves the inherited slot in place.
|
|
936
|
+
return {
|
|
937
|
+
expression: renderData({object: value.entries}),
|
|
938
|
+
preferredName: defaultName,
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
const {ref} = value;
|
|
942
|
+
const {source, localName, target} = importedTarget(ref);
|
|
684
943
|
const expression = value.entries
|
|
685
|
-
? `{...${target}[
|
|
944
|
+
? `{...${target}[${JSON.stringify(field)}], ...${target}[${JSON.stringify(entriesField)}]}`
|
|
686
945
|
: target;
|
|
687
946
|
return {
|
|
688
947
|
expression,
|
|
@@ -696,6 +955,7 @@ export async function resolveIconImports(
|
|
|
696
955
|
};
|
|
697
956
|
}
|
|
698
957
|
|
|
958
|
+
let usesMerge = false;
|
|
699
959
|
const rendered = render(plan);
|
|
700
960
|
const name =
|
|
701
961
|
rendered.preferredName === rendered.expression &&
|
|
@@ -706,6 +966,7 @@ export async function resolveIconImports(
|
|
|
706
966
|
imports,
|
|
707
967
|
expression: rendered.expression,
|
|
708
968
|
exportName: name,
|
|
969
|
+
...(usesMerge ? {mergeName} : {}),
|
|
709
970
|
...(rendered.overridePath
|
|
710
971
|
? {
|
|
711
972
|
iconsSpecifierImportPath: rendered.overridePath,
|
|
@@ -144,6 +144,14 @@
|
|
|
144
144
|
"kind": "component",
|
|
145
145
|
"name": "LogStream"
|
|
146
146
|
},
|
|
147
|
+
{
|
|
148
|
+
"kind": "component",
|
|
149
|
+
"name": "NavigationScreen"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"kind": "component",
|
|
153
|
+
"name": "NavigationStack"
|
|
154
|
+
},
|
|
147
155
|
{
|
|
148
156
|
"kind": "component",
|
|
149
157
|
"name": "RadialChart"
|
|
@@ -41,7 +41,7 @@ export const docs = {
|
|
|
41
41
|
['typography.scale', '--text-heading-*-size/weight/leading, --text-body-size/weight/leading', 'base (px), ratio'],
|
|
42
42
|
['typography.body/heading/code', '--font-family-body, --font-family-heading, --font-family-code', 'family, fallbacks?, url?, weight?'],
|
|
43
43
|
['radius', '--radius-inner, --radius-element, --radius-container, --radius-page, --radius-chat', 'base (px), multiplier (0–2)'],
|
|
44
|
-
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (
|
|
44
|
+
['motion', 'Every --duration-* token, --ease-entrance and --ease-move (tempo also times the touch springs)', 'tempo? (0.75–1.5), character? (crisp|standard|expressive); and/or a duration scale: fast (ms), medium (ms), ratio, slow?, easing?. The scale wins over tempo for the durations it sets, and explicit tokens win over both. Fixed whatever the knobs say: drags and momentum, rubber band, keyboard, press onset/cancel/flash, hover intent, gesture thresholds, Spinner/Skeleton loops, the 200 ms Reduce Motion cap. See {@link generic:motion}.'],
|
|
45
45
|
]},
|
|
46
46
|
{type: 'prose', text: 'For dark mode tuples in token values, see the Dark mode section of {@link generic:use-a-theme}.'},
|
|
47
47
|
],
|
|
@@ -56,6 +56,7 @@ export const docs = {
|
|
|
56
56
|
['components', 'Deep-merged: child component rules override matching keys from the base.'],
|
|
57
57
|
['icons', 'Shallow-merged: child icons override matching names from the base.'],
|
|
58
58
|
['iconVariants', 'Replaced, never merged: a child that sets iconVariants replaces the base list; a child that omits it inherits the list.'],
|
|
59
|
+
['componentIcons', 'Merged by slot: a child entry replaces the base entry for that slot whole; an omitted or undefined entry keeps the inherited one.'],
|
|
59
60
|
['indicators', 'Shallow-merged: child indicators override matching names from the base.'],
|
|
60
61
|
['onDark, onLight', "Deep-merged per surface: the base's resolved surface first, then the child's overrides."],
|
|
61
62
|
['motion', "Field by field: the child's `fast`, `medium` and `ratio` regenerate the fast and medium duration tokens; `slow` and `easing` left unset keep the base theme's tokens, so an inherited slow band stays at the base's ratio. Each knob (`tempo`, `character`) the child leaves unset keeps the base's."],
|
|
@@ -138,6 +139,7 @@ export const docs = {
|
|
|
138
139
|
{type: 'prose', text: 'Keep `react` and the icon library external so the registry does not bundle its own copies of those dependencies.'},
|
|
139
140
|
{type: 'prose', text: "A registry entry can be a function of `{size, variant}`. The built theme keeps the function, so `Icon` asks it for the size and variant it renders, as the runtime theme does, including for entries inherited from a built or package theme. The built theme's `icons` field and the registry its module re-exports are React nodes, with each function read at size `md`. A function written in the theme file itself cannot be carried, so the build fails; move it into the registry module."},
|
|
140
141
|
{type: 'prose', text: "A theme that lists `iconVariants` also writes an `IconVariantMap` augmentation into `<theme>.variants.d.ts`, so `Icon`'s `variant` accepts those names wherever the theme's types load. Its declaration carries the list too, so a theme that extends the built theme types `variant` in its icon entries by that list."},
|
|
142
|
+
{type: 'prose', text: "A built theme keeps its `componentIcons`. Names, `null` values, and static requests are written into the module. A slot function stays a function: the module imports it from the module the theme source imports it from, so component slots resolve the same for the built theme as for the runtime theme. The built theme's `componentIcons` field leaves out slot functions, as the runtime theme's does. A slot function defined in the theme file fails the build: move it to its own module and import it. In `--family` output, a member supplies its own slot functions through a named import of its whole `componentIcons` map. The module keeps each slot import as the theme source spells it, and `--icons-specifier` does not change it, so with `--out` in another directory, make a module answer to that specifier from the output directory, as for the icon registry."},
|
|
141
143
|
],
|
|
142
144
|
},
|
|
143
145
|
{
|
|
@@ -214,5 +214,34 @@ export const brandTheme = defineTheme({
|
|
|
214
214
|
},
|
|
215
215
|
],
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
title: 'Component Icon Slots',
|
|
219
|
+
category: 'foundations',
|
|
220
|
+
content: [
|
|
221
|
+
{
|
|
222
|
+
type: 'prose',
|
|
223
|
+
text: "A component icon slot names why an icon appears in one component, such as `code-block-copy` for CodeBlock's copy button. `defineTheme({componentIcons})` maps a slot to one of the shared icon names. A theme can then change the icon one component uses without changing that name's artwork everywhere; `icons` still chooses the artwork for each name. Each component's docs list its slots, their state, and their fallbacks (`astryx component CodeBlock`).",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
type: 'code',
|
|
227
|
+
lang: 'tsx',
|
|
228
|
+
label: 'Mapping a slot, with its state',
|
|
229
|
+
code: `export const brandTheme = defineTheme({
|
|
230
|
+
name: 'brand',
|
|
231
|
+
componentIcons: {
|
|
232
|
+
'code-block-copy': ({copied}) => ({icon: copied ? 'checkDouble' : 'copy'}),
|
|
233
|
+
},
|
|
234
|
+
});`,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: 'prose',
|
|
238
|
+
text: "A slot value is a shared icon name, `null` to hide the icon, or a partial request of `icon`, `variant`, and `size`. A field the request leaves out keeps the component's own value. A slot with state also accepts a pure, synchronous function of that state that returns a request: returning `null` hides the icon, and returning `undefined` changes nothing. A request `size` changes only the icon, never the control around it. Icon content a component's caller passes wins over the slot.",
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
type: 'prose',
|
|
242
|
+
text: "An unknown icon name, a variant the theme does not list, or a size other than `xsm`, `sm`, `md`, or `lg` is ignored for that field, with one development warning. A theme that extends another merges `componentIcons` by slot ({@link generic:author-a-theme}). `theme.componentIcons` reads back names, `null` values, and static requests, and leaves out the slots a function resolves.",
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
},
|
|
217
246
|
],
|
|
218
247
|
};
|
|
@@ -150,7 +150,7 @@ const styles = stylex.create({
|
|
|
150
150
|
content: [
|
|
151
151
|
{
|
|
152
152
|
type: 'prose',
|
|
153
|
-
text: "A theme sets how motion feels with two knobs in `defineTheme`'s `motion`. They drive the CSS motion tokens
|
|
153
|
+
text: "A theme sets how motion feels with two knobs in `defineTheme`'s `motion`. They drive the CSS motion tokens, and `tempo` also times the springs of touch motion; those springs don't follow `character` yet. Every theme follows each person's Reduce Motion setting; no theme loosens it.",
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
type: 'list',
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
|
|
4
|
+
export const doc = {
|
|
5
|
+
type: 'block',
|
|
6
|
+
exampleFor: 'useCalendarDays',
|
|
7
|
+
name: 'useCalendarDays — Month Grid',
|
|
8
|
+
displayName: 'useCalendarDays — Month Grid',
|
|
9
|
+
description:
|
|
10
|
+
'A compact custom month view: a seven-column table built from the weeks and dayNames that useCalendarDays returns, with only as many rows as the month needs. Days from the previous and next months are dimmed, and a Week starts on control (Sunday or Monday) reorders both the header and the grid.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['SegmentedControl', 'Layout', 'Text'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useState} from 'react';
|
|
6
|
+
import {useCalendarDays} from '@astryxdesign/core/Calendar';
|
|
7
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
8
|
+
import {
|
|
9
|
+
SegmentedControl,
|
|
10
|
+
SegmentedControlItem,
|
|
11
|
+
} from '@astryxdesign/core/SegmentedControl';
|
|
12
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
13
|
+
|
|
14
|
+
export default function UseCalendarDaysHookUsage() {
|
|
15
|
+
const [weekStartsOn, setWeekStartsOn] = useState<0 | 1>(0);
|
|
16
|
+
const {weeks, dayNames} = useCalendarDays({
|
|
17
|
+
year: 2026,
|
|
18
|
+
month: 12,
|
|
19
|
+
weekStartsOn,
|
|
20
|
+
hasVariableRowCount: true,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<VStack gap={3}>
|
|
25
|
+
<HStack gap={2} vAlign="center">
|
|
26
|
+
<Text type="body">Week starts on</Text>
|
|
27
|
+
<SegmentedControl
|
|
28
|
+
label="Week starts on"
|
|
29
|
+
value={String(weekStartsOn)}
|
|
30
|
+
onChange={value => setWeekStartsOn(value === '1' ? 1 : 0)}
|
|
31
|
+
size="sm">
|
|
32
|
+
<SegmentedControlItem value="0" label="Sunday" />
|
|
33
|
+
<SegmentedControlItem value="1" label="Monday" />
|
|
34
|
+
</SegmentedControl>
|
|
35
|
+
</HStack>
|
|
36
|
+
<table style={{tableLayout: 'fixed', width: 280}}>
|
|
37
|
+
<caption>
|
|
38
|
+
<Text type="body" weight="bold">
|
|
39
|
+
December 2026
|
|
40
|
+
</Text>
|
|
41
|
+
</caption>
|
|
42
|
+
<thead>
|
|
43
|
+
<tr>
|
|
44
|
+
{dayNames.map((name, column) => (
|
|
45
|
+
<th key={(weekStartsOn + column) % 7} scope="col">
|
|
46
|
+
<Text type="supporting" color="secondary">
|
|
47
|
+
{name}
|
|
48
|
+
</Text>
|
|
49
|
+
</th>
|
|
50
|
+
))}
|
|
51
|
+
</tr>
|
|
52
|
+
</thead>
|
|
53
|
+
<tbody>
|
|
54
|
+
{weeks.map(week => (
|
|
55
|
+
<tr key={week[0].iso}>
|
|
56
|
+
{week.map(day => (
|
|
57
|
+
<td key={day.iso} align="center">
|
|
58
|
+
<Text
|
|
59
|
+
type="body"
|
|
60
|
+
color={day.isOutside ? 'secondary' : 'primary'}>
|
|
61
|
+
{day.dayNumber}
|
|
62
|
+
</Text>
|
|
63
|
+
</td>
|
|
64
|
+
))}
|
|
65
|
+
</tr>
|
|
66
|
+
))}
|
|
67
|
+
</tbody>
|
|
68
|
+
</table>
|
|
69
|
+
</VStack>
|
|
70
|
+
);
|
|
71
|
+
}
|