@astryxdesign/cli 0.7.9-canary.dd5ca29 → 0.7.9-canary.ddb8b34

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.
@@ -249,7 +249,7 @@ useBackdropPress useBackdropPress Layer/Layer.doc.mjs Layer/useBackdropPress.ts
249
249
  useBaseTablePlugins useBaseTablePlugins Table/Table.doc.mjs Table/useBaseTablePlugins.ts
250
250
  useBusyAnnouncement useBusyAnnouncement hooks/useAnimatedLayout.doc.mjs hooks/useBusyAnnouncement.ts
251
251
  useCalendarConstraints useCalendarConstraints Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarConstraints.ts
252
- useCalendarDays useCalendarDays Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarDays.ts
252
+ useCalendarDays useCalendarDays Calendar/useCalendarDays.doc.mjs Calendar/hooks/useCalendarDays.ts
253
253
  useCalendarNavigation useCalendarNavigation Calendar/Calendar.doc.mjs Calendar/hooks/useCalendarNavigation.ts
254
254
  useChatComposerTokens useChatComposerTokens Chat/Chat.doc.mjs Chat/useChatComposerTokens.ts
255
255
  useChatDictation useChatDictation Chat/Chat.doc.mjs Chat/useChatDictation.ts
@@ -300,7 +300,7 @@ useSwipeAction useSwipeAction Item/Item.doc.mjs Item/useSwipeAction.ts
300
300
  useSwitchTouch useSwitchTouch Switch/Switch.doc.mjs Switch/useSwitchTouch.ts
301
301
  useTableCellStyles useTableCellStyles Table/Table.doc.mjs Table/useTableCellStyles.ts
302
302
  useTableColumnSettingsState useTableColumnSettingsState Table/Table.doc.mjs Table/plugins/columnSettings/useTableColumnSettingsState.tsx
303
- useTableSortableState useTableSortableState Table/Table.doc.mjs Table/plugins/sortable/useTableSortableState.tsx
303
+ useTableSortableState useTableSortableState Table/plugins/sortable/useTableSortableState.doc.mjs Table/plugins/sortable/useTableSortableState.tsx
304
304
  useToastGesture useToastGesture Toast/Toast.doc.mjs Toast/useToastGesture.ts
305
305
  useTouchTrigger useTouchTrigger Layer/Layer.doc.mjs Layer/useTouchTrigger.ts
306
306
  useTriggerMenu useTriggerMenu Chat/Chat.doc.mjs Chat/useTriggerMenu.tsx
@@ -1973,7 +1973,6 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
1973
1973
  // A frozen require(esm) namespace cannot be patched, so retain that gap and
1974
1974
  // let the selected lineage decide whether it matters.
1975
1975
  const commonJsPatch = interception.patchCommonJs(filePath);
1976
- degraded.commonJs = !commonJsPatch.covered;
1977
1976
  try {
1978
1977
  try {
1979
1978
  mod = jiti(filePath);
@@ -1995,6 +1994,8 @@ async function importThemeModule(filePath, interception, /** @type {any} */ load
1995
1994
  });
1996
1995
  }
1997
1996
  } finally {
1997
+ // Read after the load: the root is wrapped when the load requires it.
1998
+ degraded.commonJs = !commonJsPatch.covered;
1998
1999
  commonJsPatch.undo();
1999
2000
  }
2000
2001
  } else {
@@ -67,7 +67,7 @@
67
67
  * SYNC: packages/cli/api/theme/build/build.mjs (importThemeModule)
68
68
  */
69
69
 
70
- import {createRequire} from 'node:module';
70
+ import Module, {createRequire} from 'node:module';
71
71
  import * as path from 'node:path';
72
72
 
73
73
  import {findInstalledPackage} from '../../../foundation/fs/paths.mjs';
@@ -293,20 +293,24 @@ export function interceptCore(coreThemeModule, coreRootModule) {
293
293
  };
294
294
  /** @type {any} */
295
295
  let wrappedRoot;
296
+ let rootRead = false;
296
297
  // jiti reads a virtual module only when a theme imports its specifier. So
297
298
  // the root, which loads all of Core, loads only for a theme that asks.
298
299
  Object.defineProperty(modules, '@astryxdesign/core', {
299
300
  enumerable: true,
300
301
  configurable: true,
301
302
  get() {
302
- const root =
303
- typeof coreRootModule === 'function'
304
- ? coreRootModule()
305
- : coreRootModule;
306
- // Falls back to the theme namespace only when the root could not be
307
- // imported at all; a partial root is better than none, and a core
308
- // missing its own root entry is already broken.
309
- wrappedRoot ??= wrapNamespace(root ?? coreThemeModule);
303
+ if (!rootRead) {
304
+ const root =
305
+ typeof coreRootModule === 'function'
306
+ ? coreRootModule()
307
+ : coreRootModule;
308
+ // Falls back to the theme namespace only when the root could not be
309
+ // imported at all; a partial root is better than none, and a core
310
+ // missing its own root entry is already broken.
311
+ wrappedRoot = wrapNamespace(root ?? coreThemeModule);
312
+ rootRead = true;
313
+ }
310
314
  return wrappedRoot;
311
315
  },
312
316
  });
@@ -469,28 +473,19 @@ export function interceptCore(coreThemeModule, coreRootModule) {
469
473
  return {covered, undo: () => {}};
470
474
  }
471
475
 
472
- for (const specifier of [
473
- '@astryxdesign/core/theme',
474
- '@astryxdesign/core',
475
- ]) {
476
- /** @type {any} */
477
- let cjs;
478
- try {
479
- cjs = createRequire(fromFile)(specifier);
480
- } catch {
481
- // A specifier that CommonJS cannot resolve cannot be used by a `.cjs`
482
- // source dependency either, so it creates no unobserved path.
483
- continue;
484
- }
485
-
476
+ const requireFromTheme = createRequire(fromFile);
477
+ /**
478
+ * Wraps `defineTheme` on a CommonJS exports object in place, so a call
479
+ * from a `.cjs` dependency is recorded. False when it cannot be wrapped.
480
+ * @param {any} cjs
481
+ */
482
+ const wrap = cjs => {
486
483
  const real = cjs?.defineTheme;
487
- if (typeof real !== 'function') continue;
484
+ if (typeof real !== 'function') return true;
488
485
  const descriptor = Object.getOwnPropertyDescriptor(cjs, 'defineTheme');
489
486
  if (!descriptor || !(descriptor.writable || descriptor.configurable)) {
490
- covered = false;
491
- continue;
487
+ return false;
492
488
  }
493
-
494
489
  try {
495
490
  Object.defineProperty(cjs, 'defineTheme', {
496
491
  ...descriptor,
@@ -503,16 +498,84 @@ export function interceptCore(coreThemeModule, coreRootModule) {
503
498
  undo.push(() =>
504
499
  Object.defineProperty(cjs, 'defineTheme', descriptor),
505
500
  );
501
+ return true;
506
502
  } catch {
507
503
  // ESM namespace exotic objects may report a writable descriptor but
508
504
  // still reject redefinition. This is a real coverage failure, not an
509
505
  // absent CommonJS entry: a `.cjs` dependency can call the function
510
506
  // while the recorder cannot wrap it.
511
- covered = false;
507
+ return false;
508
+ }
509
+ };
510
+
511
+ // An entry that CommonJS cannot resolve or load cannot be used by a
512
+ // `.cjs` source dependency either, so it creates no unobserved path. It
513
+ // is skipped, as are the entries of a package config CommonJS cannot
514
+ // read. Throwing instead would fail every theme beside such an install.
515
+ /** @param {string} specifier @returns {string | null} */
516
+ const resolveEntry = specifier => {
517
+ try {
518
+ return requireFromTheme.resolve(specifier);
519
+ } catch {
520
+ return null;
521
+ }
522
+ };
523
+ const themeFile = resolveEntry('@astryxdesign/core/theme');
524
+ const rootFile = resolveEntry('@astryxdesign/core');
525
+
526
+ // The theme subpath is small, so it is wrapped now.
527
+ if (themeFile) {
528
+ /** @type {any} */
529
+ let themeExports = null;
530
+ try {
531
+ themeExports = requireFromTheme(themeFile);
532
+ } catch {
533
+ // A dependency that requires it fails the same way.
534
+ }
535
+ if (themeExports && !wrap(themeExports)) covered = false;
536
+ }
537
+
538
+ // The root loads all of Core, so it is wrapped only once this load
539
+ // requires it. Every CommonJS require goes through `Module._load`,
540
+ // which is watched for the load's duration. The watch reads the require
541
+ // cache, where the root's file is keyed by its real path. So any
542
+ // request that loads that file counts, however it is spelled. A load
543
+ // that never requires the root leaves no path through it to observe.
544
+ if (rootFile) {
545
+ /** @type {any} */
546
+ const loader = Module;
547
+ /** Wraps the root once its file has run; false until then. */
548
+ const wrapLoadedRoot = () => {
549
+ const loaded = loader._cache[rootFile];
550
+ // A CommonJS module is cached before its body runs, so a require
551
+ // inside the root's own body sees it partly built.
552
+ if (!loaded?.loaded) return false;
553
+ if (!wrap(loaded.exports)) covered = false;
554
+ return true;
555
+ };
556
+ if (!wrapLoadedRoot()) {
557
+ const load = loader._load;
558
+ /** @this {any} @param {...any} args */
559
+ const watch = function (...args) {
560
+ const exports = load.apply(this, args);
561
+ if (loader._load === watch && wrapLoadedRoot()) {
562
+ loader._load = load;
563
+ }
564
+ return exports;
565
+ };
566
+ loader._load = watch;
567
+ // Theme loads never overlap: each caller awaits one at a time. The
568
+ // watch is still removed only while it is the one installed.
569
+ undo.push(() => {
570
+ if (loader._load === watch) loader._load = load;
571
+ });
512
572
  }
513
573
  }
514
574
  return {
515
- covered,
575
+ /** Read after the load: a root required during it counts. */
576
+ get covered() {
577
+ return covered;
578
+ },
516
579
  undo() {
517
580
  for (const restore of undo.reverse()) {
518
581
  try {
@@ -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
+ }
@@ -0,0 +1,15 @@
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: 'useInputContainer',
7
+ name: 'useInputContainer — Search Field Wrapper',
8
+ displayName: 'useInputContainer — Search Field Wrapper',
9
+ description:
10
+ 'A custom search field wrapper with a leading search icon, padding and a trailing Clear button. useInputContainer puts focus in the input when the icon or the padding is clicked, while a click on Clear empties the field without the wrapper taking it over.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Icon', 'InputClearButton'],
14
+ icons: {MagnifyingGlassIcon: 'search'},
15
+ };
@@ -0,0 +1,93 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {useRef, useState} from 'react';
6
+ import * as stylex from '@stylexjs/stylex';
7
+ import {InputClearButton} from '@astryxdesign/core/Field';
8
+ import {useInputContainer} from '@astryxdesign/core/hooks';
9
+ import {Icon} from '@astryxdesign/core/Icon';
10
+ import {
11
+ colorVars,
12
+ focusVars,
13
+ radiusVars,
14
+ spacingVars,
15
+ } from '@astryxdesign/core/theme/tokens.stylex';
16
+ import {MagnifyingGlassIcon} from '@heroicons/react/24/outline';
17
+
18
+ const styles = stylex.create({
19
+ field: {
20
+ display: 'flex',
21
+ alignItems: 'center',
22
+ gap: spacingVars['--spacing-2'],
23
+ width: 320,
24
+ minHeight: 40,
25
+ paddingInline: spacingVars['--spacing-3'],
26
+ borderWidth: 1,
27
+ borderStyle: 'solid',
28
+ borderColor: colorVars['--color-border-emphasized'],
29
+ borderRadius: radiusVars['--radius-element'],
30
+ cursor: 'text',
31
+ outlineWidth: {
32
+ default: 0,
33
+ ':has(> input:focus-visible)': focusVars['--focus-outline-width'],
34
+ },
35
+ outlineStyle: {
36
+ default: 'none',
37
+ ':has(> input:focus-visible)': focusVars['--focus-outline-style'],
38
+ },
39
+ outlineColor: {
40
+ default: null,
41
+ ':has(> input:focus-visible)': focusVars['--focus-outline-color'],
42
+ },
43
+ outlineOffset: {
44
+ default: 0,
45
+ ':has(> input:focus-visible)': focusVars['--focus-outline-offset'],
46
+ },
47
+ },
48
+ input: {
49
+ flexGrow: 1,
50
+ minWidth: 0,
51
+ borderStyle: 'none',
52
+ outlineStyle: 'none',
53
+ backgroundColor: 'transparent',
54
+ color: 'inherit',
55
+ fontFamily: 'inherit',
56
+ fontSize: 'inherit',
57
+ },
58
+ });
59
+
60
+ export default function UseInputContainerHookUsage() {
61
+ const containerRef = useRef<HTMLDivElement>(null);
62
+ const inputRef = useRef<HTMLInputElement>(null);
63
+ const [query, setQuery] = useState('');
64
+ const {onClick, onMouseUp} = useInputContainer({containerRef, inputRef});
65
+
66
+ return (
67
+ <div
68
+ ref={containerRef}
69
+ onClick={onClick}
70
+ onMouseUp={onMouseUp}
71
+ {...stylex.props(styles.field)}>
72
+ <Icon icon={MagnifyingGlassIcon} color="secondary" />
73
+ <input
74
+ ref={inputRef}
75
+ type="text"
76
+ aria-label="Search"
77
+ placeholder="Search"
78
+ value={query}
79
+ onChange={event => setQuery(event.target.value)}
80
+ {...stylex.props(styles.input)}
81
+ />
82
+ {query !== '' && (
83
+ <InputClearButton
84
+ label="Clear search"
85
+ onClick={() => {
86
+ setQuery('');
87
+ inputRef.current?.focus();
88
+ }}
89
+ />
90
+ )}
91
+ </div>
92
+ );
93
+ }
@@ -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: 'useTableSortableState',
7
+ name: 'useTableSortableState — Multi-Sort Orders',
8
+ displayName: 'useTableSortableState — Multi-Sort Orders',
9
+ description:
10
+ 'Orders with no sort code of their own: useTableSortableState owns the sort state, returns the sorted orders, and hands useTableSortable a ready config. Click Customer, then Shift-click Total, to sort by customer and then by total within each customer. A line above the orders reads the current sort state from the hook.',
11
+ isReady: true,
12
+ aspectRatio: 4 / 3,
13
+ componentsUsed: ['Table', 'Layout', 'Text'],
14
+ };
@@ -0,0 +1,61 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ import {VStack} from '@astryxdesign/core/Layout';
6
+ import {
7
+ Table,
8
+ useTableSortable,
9
+ useTableSortableState,
10
+ } from '@astryxdesign/core/Table';
11
+ import type {TableColumn} from '@astryxdesign/core/Table';
12
+ import {Text} from '@astryxdesign/core/Text';
13
+
14
+ interface Order extends Record<string, unknown> {
15
+ id: string;
16
+ customer: string;
17
+ total: number;
18
+ }
19
+
20
+ const orders: Order[] = [
21
+ {id: '1042', customer: 'Chen', total: 85},
22
+ {id: '1043', customer: 'Ana', total: 120},
23
+ {id: '1044', customer: 'Ben', total: 40},
24
+ {id: '1045', customer: 'Ana', total: 35},
25
+ {id: '1046', customer: 'Chen', total: 15},
26
+ {id: '1047', customer: 'Ben', total: 210},
27
+ {id: '1048', customer: 'Ana', total: 60},
28
+ ];
29
+
30
+ const columns: TableColumn<Order>[] = [
31
+ {key: 'id', header: 'Order'},
32
+ {key: 'customer', header: 'Customer', sortable: true},
33
+ {key: 'total', header: 'Total ($)', sortable: true, align: 'end'},
34
+ ];
35
+
36
+ export default function UseTableSortableStateHookUsage() {
37
+ const {sortedData, sort, sortConfig} = useTableSortableState<Order>({
38
+ data: orders,
39
+ isMultiSortEnabled: true,
40
+ });
41
+ const sortablePlugin = useTableSortable<Order>(sortConfig);
42
+
43
+ return (
44
+ <VStack gap={3}>
45
+ <Text type="supporting" color="secondary">
46
+ Sorted by:{' '}
47
+ {sort.length === 0
48
+ ? 'none'
49
+ : sort
50
+ .map(({sortKey, direction}) => `${sortKey} ${direction}`)
51
+ .join(', then ')}
52
+ </Text>
53
+ <Table
54
+ data={sortedData}
55
+ columns={columns}
56
+ idKey="id"
57
+ plugins={{sortable: sortablePlugin}}
58
+ />
59
+ </VStack>
60
+ );
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.9-canary.dd5ca29",
3
+ "version": "0.7.9-canary.ddb8b34",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -124,10 +124,10 @@
124
124
  "zod": "^4.4.3"
125
125
  },
126
126
  "peerDependencies": {
127
- "@astryxdesign/charts": "0.7.9-canary.dd5ca29",
128
- "@astryxdesign/core": "0.7.9-canary.dd5ca29",
129
- "@astryxdesign/lab": "0.7.9-canary.dd5ca29",
130
- "@astryxdesign/theme-neutral": "0.7.9-canary.dd5ca29"
127
+ "@astryxdesign/charts": "0.7.9-canary.ddb8b34",
128
+ "@astryxdesign/core": "0.7.9-canary.ddb8b34",
129
+ "@astryxdesign/lab": "0.7.9-canary.ddb8b34",
130
+ "@astryxdesign/theme-neutral": "0.7.9-canary.ddb8b34"
131
131
  },
132
132
  "peerDependenciesMeta": {
133
133
  "@astryxdesign/charts": {
@@ -144,10 +144,10 @@
144
144
  }
145
145
  },
146
146
  "devDependencies": {
147
- "@astryxdesign/charts": "0.7.9-canary.dd5ca29",
148
- "@astryxdesign/core": "0.7.9-canary.dd5ca29",
149
- "@astryxdesign/lab": "0.7.9-canary.dd5ca29",
150
- "@astryxdesign/theme-neutral": "0.7.9-canary.dd5ca29",
147
+ "@astryxdesign/charts": "0.7.9-canary.ddb8b34",
148
+ "@astryxdesign/core": "0.7.9-canary.ddb8b34",
149
+ "@astryxdesign/lab": "0.7.9-canary.ddb8b34",
150
+ "@astryxdesign/theme-neutral": "0.7.9-canary.ddb8b34",
151
151
  "@heroicons/react": "^2.2.0",
152
152
  "@stylexjs/stylex": "^0.19.0",
153
153
  "@types/babel__core": "^7.20.5",