@astryxdesign/cli 0.7.9 → 0.7.10-canary.010db3f
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/api/component/__fixtures__/resolutions/modules.txt +0 -1
- package/api/search/_gather-components.mjs +2 -1
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/getting-started.doc.mjs +20 -0
- package/assets/templates/blocks/components/Carousel/CarouselSnapPaging.doc.mjs +14 -0
- package/assets/templates/blocks/components/Carousel/CarouselSnapPaging.tsx +49 -0
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.doc.mjs +23 -0
- package/assets/templates/blocks/components/MultiSelector/useMultiComboboxHookUsage.tsx +164 -0
- package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.doc.mjs +14 -0
- package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.tsx +110 -0
- package/assets/templates/blocks/components/useDragToSnapPoints/DragToSnapPointsCard.doc.mjs +21 -0
- package/assets/templates/blocks/components/useDragToSnapPoints/DragToSnapPointsCard.tsx +74 -0
- package/assets/templates/pages/ai-chat-landing/page.tsx +0 -9
- package/foundation/discovery/authoring-self-docs.mjs +2 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -1
- package/foundation/discovery/docs-discovery.mjs +6 -4
- package/foundation/discovery/icon-definition-discovery.mjs +3 -3
- package/foundation/discovery/template-adapter.mjs +5 -7
- package/foundation/discovery/theme-discovery.mjs +8 -10
- package/foundation/doc-compiler/tree.mjs +2 -2
- package/foundation/fs/listing-cache.d.mts +3 -1
- package/foundation/fs/listing-cache.mjs +63 -11
- package/foundation/fs/paths.mjs +2 -1
- package/package.json +6 -18
|
@@ -168,7 +168,6 @@ menuPressGesture menuPressGesture hooks/useAnimatedLayout.doc.mjs hooks/menuPres
|
|
|
168
168
|
menuPressMarker menuPressMarker hooks/useAnimatedLayout.doc.mjs hooks/menuPressMarker.ts
|
|
169
169
|
menuPressOnItems menuPressOnItems hooks/useAnimatedLayout.doc.mjs hooks/menuPressOnItems.ts
|
|
170
170
|
menuRegionStops menuRegionStops DropdownMenu/DropdownMenu.doc.mjs DropdownMenu/menuRegionStops.ts
|
|
171
|
-
menuRegionsContext menuRegionsContext DropdownMenu/DropdownMenu.doc.mjs DropdownMenu/menuRegionsContext.ts
|
|
172
171
|
menuWidth menuWidth DropdownMenu/DropdownMenu.doc.mjs DropdownMenu/menuWidth.ts
|
|
173
172
|
mergeComponents mergeComponents theme/MediaTheme.doc.mjs theme/mergeComponents.ts
|
|
174
173
|
modalAnnounce modalAnnounce hooks/useAnimatedLayout.doc.mjs hooks/modalAnnounce.ts
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import {discoverExternalPackages} from '../../foundation/fs/paths.mjs';
|
|
11
|
+
import {listDir} from '../../foundation/fs/listing-cache.mjs';
|
|
11
12
|
import {
|
|
12
13
|
discoverComponents,
|
|
13
14
|
discoverValidIntegrationComponents,
|
|
@@ -103,7 +104,7 @@ async function gatherCoreComponents(coreDir) {
|
|
|
103
104
|
// A family doc with no component of its own name (Chat) names members too.
|
|
104
105
|
const srcDir = path.join(coreDir, 'src');
|
|
105
106
|
const listed = new Set(names);
|
|
106
|
-
for (const dir of fs.existsSync(srcDir) ?
|
|
107
|
+
for (const dir of fs.existsSync(srcDir) ? listDir(srcDir) : []) {
|
|
107
108
|
const doc = path.join(srcDir, dir, `${dir}.doc.mjs`);
|
|
108
109
|
if (listed.has(dir) || !fs.existsSync(doc)) continue;
|
|
109
110
|
for (const [n, place] of familyPlaces(await loadModuleDoc(doc)))
|
|
@@ -64,6 +64,26 @@ export const docs = {
|
|
|
64
64
|
},
|
|
65
65
|
],
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
id: 'upgrade',
|
|
69
|
+
title: 'Upgrade',
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: 'prose',
|
|
73
|
+
text: 'Upgrade every Astryx package your app lists in one command, to the same release. Each theme names the exact Core release it works with, so a theme left on an older release no longer matches the new Core.',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'code',
|
|
77
|
+
lang: 'bash',
|
|
78
|
+
label: 'Terminal',
|
|
79
|
+
code: `{@pm install @astryxdesign/core@latest @astryxdesign/theme-neutral@latest @astryxdesign/cli@latest}\n{@command upgrade --from <old Core version> --apply}`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'prose',
|
|
83
|
+
text: "Add every other Astryx package your app lists to the same command, and pass the Core version you had before to `--from`. If your package manager holds new releases back, exempt the whole `@astryxdesign/*` scope; in pnpm, `minimumReleaseAgeExclude: ['@astryxdesign/*']`. Exempting only some of its packages installs packages from different releases side by side.",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
67
87
|
{
|
|
68
88
|
id: 'install-once',
|
|
69
89
|
title: 'Install once, use everywhere',
|
|
@@ -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: 'useSnapPaging',
|
|
7
|
+
name: 'useSnapPaging — Onboarding Pages',
|
|
8
|
+
displayName: 'useSnapPaging — Onboarding Pages',
|
|
9
|
+
description:
|
|
10
|
+
"Onboarding cards in a Carousel with hasSnap={useSnapPaging()}: under a finger or a trackpad swipe, each flick moves one view and rests on a card's start edge. A switch picks one view or one card per flick through the hook's pages option.",
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Carousel', 'Card', 'Layout', 'Switch', 'Text'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useState} from 'react';
|
|
6
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
7
|
+
import {Carousel} from '@astryxdesign/core/Carousel';
|
|
8
|
+
import {Stack} from '@astryxdesign/core/Layout';
|
|
9
|
+
import {useSnapPaging} from '@astryxdesign/core/SnapPaging';
|
|
10
|
+
import {Switch} from '@astryxdesign/core/Switch';
|
|
11
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
12
|
+
|
|
13
|
+
const SCREENS = [
|
|
14
|
+
{title: 'Welcome', body: 'Swipe to see what is new.'},
|
|
15
|
+
{title: 'Shared albums', body: 'Invite friends to add their photos.'},
|
|
16
|
+
{title: 'Memories', body: 'See a day from years ago.'},
|
|
17
|
+
{title: 'Search', body: 'Find a photo by what is in it.'},
|
|
18
|
+
{title: 'All set', body: 'Your library is ready.'},
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export default function CarouselSnapPaging() {
|
|
22
|
+
const [isOneCard, setIsOneCard] = useState(false);
|
|
23
|
+
// A flick moves one view, or one card with {pages: 'item'}.
|
|
24
|
+
const paging = useSnapPaging({pages: isOneCard ? 'item' : 'view'});
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Stack direction="vertical" gap={3} style={{maxWidth: 520, padding: 8}}>
|
|
28
|
+
<Switch
|
|
29
|
+
label="One card per flick"
|
|
30
|
+
value={isOneCard}
|
|
31
|
+
onChange={setIsOneCard}
|
|
32
|
+
/>
|
|
33
|
+
<Carousel gap={2} hasSnap={paging} aria-label="Onboarding">
|
|
34
|
+
{SCREENS.map(screen => (
|
|
35
|
+
<Card key={screen.title} width={220} minHeight={160}>
|
|
36
|
+
<Stack direction="vertical" gap={1}>
|
|
37
|
+
<Text type="body" weight="bold">
|
|
38
|
+
{screen.title}
|
|
39
|
+
</Text>
|
|
40
|
+
<Text type="body" color="secondary">
|
|
41
|
+
{screen.body}
|
|
42
|
+
</Text>
|
|
43
|
+
</Stack>
|
|
44
|
+
</Card>
|
|
45
|
+
))}
|
|
46
|
+
</Carousel>
|
|
47
|
+
</Stack>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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: 'useMultiCombobox',
|
|
7
|
+
name: 'useMultiCombobox — Issue Labels',
|
|
8
|
+
displayName: 'useMultiCombobox — Issue Labels',
|
|
9
|
+
description:
|
|
10
|
+
'A Labels field built on useMultiCombobox: typing filters the labels, the arrow keys move the active option while focus stays in the field, Enter or a click toggles a label and the list stays open, and selected labels show as removable tokens above the field.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
icons: {CheckIcon: 'check'},
|
|
14
|
+
componentsUsed: [
|
|
15
|
+
'MultiSelector',
|
|
16
|
+
'Card',
|
|
17
|
+
'TextInput',
|
|
18
|
+
'Item',
|
|
19
|
+
'Icon',
|
|
20
|
+
'Token',
|
|
21
|
+
'Layout',
|
|
22
|
+
],
|
|
23
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useId, useRef, useState} from 'react';
|
|
6
|
+
import {CheckIcon} from '@heroicons/react/24/outline';
|
|
7
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
8
|
+
import {useAnnounce} from '@astryxdesign/core/hooks';
|
|
9
|
+
import {Icon} from '@astryxdesign/core/Icon';
|
|
10
|
+
import {Item} from '@astryxdesign/core/Item';
|
|
11
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
12
|
+
import {useMultiCombobox} from '@astryxdesign/core/MultiSelector';
|
|
13
|
+
import {TextInput} from '@astryxdesign/core/TextInput';
|
|
14
|
+
import {Token} from '@astryxdesign/core/Token';
|
|
15
|
+
import {isImeKeyEvent} from '@astryxdesign/core/utils';
|
|
16
|
+
|
|
17
|
+
const LABELS = [
|
|
18
|
+
{value: 'bug', label: 'Bug'},
|
|
19
|
+
{value: 'docs', label: 'Documentation'},
|
|
20
|
+
{value: 'a11y', label: 'Accessibility'},
|
|
21
|
+
{value: 'perf', label: 'Performance'},
|
|
22
|
+
{value: 'good-first-issue', label: 'Good first issue'},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function filterLabels(query: string) {
|
|
26
|
+
const needle = query.trim().toLowerCase();
|
|
27
|
+
return LABELS.filter(item => item.label.toLowerCase().includes(needle));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function UseMultiComboboxHookUsage() {
|
|
31
|
+
const listboxId = useId();
|
|
32
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
33
|
+
const [query, setQuery] = useState('');
|
|
34
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
35
|
+
const [selected, setSelected] = useState<string[]>(['bug']);
|
|
36
|
+
const matches = filterLabels(query);
|
|
37
|
+
const announce = useAnnounce({hasReplace: true});
|
|
38
|
+
|
|
39
|
+
const toggle = (value: string) =>
|
|
40
|
+
setSelected(current =>
|
|
41
|
+
current.includes(value)
|
|
42
|
+
? current.filter(item => item !== value)
|
|
43
|
+
: [...current, value],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const combobox = useMultiCombobox({
|
|
47
|
+
selectableItems: matches,
|
|
48
|
+
isOpen,
|
|
49
|
+
hasSearch: true,
|
|
50
|
+
// With no match there is no option to point at, so the list stays shut.
|
|
51
|
+
onOpen: () => {
|
|
52
|
+
if (matches.length === 0) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
setIsOpen(true);
|
|
56
|
+
},
|
|
57
|
+
onClose: () => setIsOpen(false),
|
|
58
|
+
onToggle: toggle,
|
|
59
|
+
listboxId,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Card width={360} padding={4}>
|
|
64
|
+
<VStack gap={2}>
|
|
65
|
+
<HStack gap={1} wrap="wrap">
|
|
66
|
+
{LABELS.filter(item => selected.includes(item.value)).map(item => (
|
|
67
|
+
<Token
|
|
68
|
+
key={item.value}
|
|
69
|
+
label={item.label}
|
|
70
|
+
// The removed token's button unmounts, so focus goes back to
|
|
71
|
+
// the field instead of the page.
|
|
72
|
+
onRemove={() => {
|
|
73
|
+
toggle(item.value);
|
|
74
|
+
inputRef.current?.focus();
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
))}
|
|
78
|
+
</HStack>
|
|
79
|
+
<TextInput
|
|
80
|
+
ref={inputRef}
|
|
81
|
+
label="Labels"
|
|
82
|
+
placeholder="Filter labels"
|
|
83
|
+
role="combobox"
|
|
84
|
+
aria-autocomplete="list"
|
|
85
|
+
aria-expanded={isOpen}
|
|
86
|
+
aria-controls={isOpen ? listboxId : undefined}
|
|
87
|
+
aria-activedescendant={combobox.activeDescendantId}
|
|
88
|
+
value={query}
|
|
89
|
+
onChange={nextQuery => {
|
|
90
|
+
const nextMatches = filterLabels(nextQuery);
|
|
91
|
+
setQuery(nextQuery);
|
|
92
|
+
setIsOpen(true);
|
|
93
|
+
combobox.setHighlightedIndex(nextMatches.length > 0 ? 0 : -1);
|
|
94
|
+
if (nextQuery.trim() !== query.trim()) {
|
|
95
|
+
announce(
|
|
96
|
+
nextMatches.length === 0
|
|
97
|
+
? 'No labels match'
|
|
98
|
+
: nextMatches.length === 1
|
|
99
|
+
? '1 label'
|
|
100
|
+
: `${nextMatches.length} labels`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}}
|
|
104
|
+
onClick={combobox.onTriggerClick}
|
|
105
|
+
onKeyDown={event => {
|
|
106
|
+
// Keys that compose a Korean, Japanese or Chinese syllable belong
|
|
107
|
+
// to the input method. Home, End, PageUp and PageDown keep their
|
|
108
|
+
// text-field meaning.
|
|
109
|
+
if (
|
|
110
|
+
isImeKeyEvent(event.nativeEvent) ||
|
|
111
|
+
['Home', 'End', 'PageUp', 'PageDown'].includes(event.key)
|
|
112
|
+
) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// With no active option, Enter submits a surrounding form.
|
|
116
|
+
if (event.key === 'Enter' && combobox.activeDescendantId == null) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
combobox.onKeyDown(event);
|
|
120
|
+
}}
|
|
121
|
+
onBlur={() => {
|
|
122
|
+
setIsOpen(false);
|
|
123
|
+
combobox.setHighlightedIndex(-1);
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
{isOpen && (
|
|
127
|
+
<VStack
|
|
128
|
+
as="ul"
|
|
129
|
+
gap={0}
|
|
130
|
+
id={listboxId}
|
|
131
|
+
role="listbox"
|
|
132
|
+
aria-label="Labels"
|
|
133
|
+
aria-multiselectable
|
|
134
|
+
// Focus stays on the field when an option is pressed.
|
|
135
|
+
onMouseDown={event => event.preventDefault()}>
|
|
136
|
+
{matches.map((item, index) => (
|
|
137
|
+
<Item
|
|
138
|
+
key={item.value}
|
|
139
|
+
as="li"
|
|
140
|
+
id={combobox.getItemId(index)}
|
|
141
|
+
role="option"
|
|
142
|
+
// Selection is a check mark, so the highlight below stays the
|
|
143
|
+
// only fill on the row and the active option is always visible.
|
|
144
|
+
aria-checked={selected.includes(item.value)}
|
|
145
|
+
density="compact"
|
|
146
|
+
label={item.label}
|
|
147
|
+
endContent={
|
|
148
|
+
selected.includes(item.value) && (
|
|
149
|
+
<Icon icon={CheckIcon} size="sm" />
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
isHighlighted={index === combobox.highlightedIndex}
|
|
153
|
+
onClick={() => toggle(item.value)}
|
|
154
|
+
// Highlight follows pointer movement: a list that opens under
|
|
155
|
+
// a resting pointer keeps the active option the keys set.
|
|
156
|
+
onMouseMove={() => combobox.onItemMouseEnter(item, index)}
|
|
157
|
+
/>
|
|
158
|
+
))}
|
|
159
|
+
</VStack>
|
|
160
|
+
)}
|
|
161
|
+
</VStack>
|
|
162
|
+
</Card>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -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: 'createDragToSnapPoints',
|
|
7
|
+
name: 'createDragToSnapPoints — Playing card in plain JavaScript',
|
|
8
|
+
displayName: 'createDragToSnapPoints — Playing card in plain JavaScript',
|
|
9
|
+
description:
|
|
10
|
+
'The three-place playing card from the useDragToSnapPoints example, built in plain JavaScript with createDragToSnapPoints: a sideways drag settles it on the nearest place or the next after a flick, buttons settle it from the keyboard, and a live region announces the place. React only mounts it.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: [],
|
|
14
|
+
};
|
package/assets/templates/blocks/components/createDragToSnapPoints/DragToSnapPointsCardVanilla.tsx
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {createDragToSnapPoints} from '@astryxdesign/core';
|
|
6
|
+
|
|
7
|
+
const PLACES = ['Hand', 'Table', 'Discard pile'];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A card that snaps between three places, in plain JavaScript: no React
|
|
11
|
+
* below this line. It returns a function that takes it down again.
|
|
12
|
+
*/
|
|
13
|
+
function mountCard(table: HTMLElement, buttons: HTMLElement) {
|
|
14
|
+
const card = document.createElement('div');
|
|
15
|
+
card.textContent = 'Q\u2665';
|
|
16
|
+
Object.assign(card.style, {
|
|
17
|
+
width: '96px',
|
|
18
|
+
height: '136px',
|
|
19
|
+
display: 'grid',
|
|
20
|
+
placeItems: 'center',
|
|
21
|
+
font: 'bold 36px system-ui, sans-serif',
|
|
22
|
+
// The theme's surface and text, so the card reads in light and dark.
|
|
23
|
+
borderRadius: 'var(--radius-container)',
|
|
24
|
+
backgroundColor: 'var(--color-background-surface)',
|
|
25
|
+
color: 'var(--color-text-primary)',
|
|
26
|
+
boxShadow: '0 2px 8px var(--color-shadow)',
|
|
27
|
+
touchAction: 'none',
|
|
28
|
+
cursor: 'grab',
|
|
29
|
+
userSelect: 'none',
|
|
30
|
+
});
|
|
31
|
+
table.append(card);
|
|
32
|
+
const status = document.createElement('div');
|
|
33
|
+
status.setAttribute('aria-live', 'polite');
|
|
34
|
+
Object.assign(status.style, {position: 'absolute', clip: 'rect(0 0 0 0)'});
|
|
35
|
+
table.append(status);
|
|
36
|
+
|
|
37
|
+
// The places run in reading order, so leftward in a right-to-left layout.
|
|
38
|
+
// There the snap points are negative, so they sort the other way round.
|
|
39
|
+
const steps = [0, 110, 220];
|
|
40
|
+
const isRtl = getComputedStyle(table).direction === 'rtl';
|
|
41
|
+
const placeAt = (index: number) => (isRtl ? steps.length - 1 - index : index);
|
|
42
|
+
const snap = createDragToSnapPoints(card, {
|
|
43
|
+
axis: 'x',
|
|
44
|
+
snapPoints: isRtl ? steps.map(step => -step) : steps,
|
|
45
|
+
onSettle: index => {
|
|
46
|
+
status.textContent = `The card is on the ${PLACES[placeAt(index)].toLowerCase()}.`;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const controls = PLACES.map((name, index) => {
|
|
50
|
+
const button = document.createElement('button');
|
|
51
|
+
button.type = 'button';
|
|
52
|
+
button.textContent = name;
|
|
53
|
+
// The Astryx reset removes a native button's own look, so these take the
|
|
54
|
+
// theme's secondary button look.
|
|
55
|
+
Object.assign(button.style, {
|
|
56
|
+
height: 'var(--size-element-md)',
|
|
57
|
+
paddingInline: 'var(--spacing-3)',
|
|
58
|
+
border: 'none',
|
|
59
|
+
borderRadius: 'var(--radius-element)',
|
|
60
|
+
backgroundColor: 'var(--color-neutral)',
|
|
61
|
+
color: 'var(--color-text-primary)',
|
|
62
|
+
font: 'inherit',
|
|
63
|
+
fontSize: 'var(--text-label-size)',
|
|
64
|
+
fontWeight: 'var(--font-weight-medium)',
|
|
65
|
+
cursor: 'pointer',
|
|
66
|
+
});
|
|
67
|
+
button.addEventListener('click', () => snap.settleTo(placeAt(index)));
|
|
68
|
+
buttons.append(button);
|
|
69
|
+
return button;
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
snap.destroy();
|
|
73
|
+
for (const button of controls) {
|
|
74
|
+
button.remove();
|
|
75
|
+
}
|
|
76
|
+
card.remove();
|
|
77
|
+
status.remove();
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Mounts the card when the wrapper attaches, and takes it down when it
|
|
83
|
+
* detaches: its cleanup is the callback ref's.
|
|
84
|
+
*/
|
|
85
|
+
function mountTable(wrapper: HTMLDivElement | null) {
|
|
86
|
+
if (wrapper == null) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const table = wrapper.firstElementChild as HTMLElement;
|
|
90
|
+
const buttons = wrapper.lastElementChild as HTMLElement;
|
|
91
|
+
return mountCard(table, buttons);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default function DragToSnapPointsCardVanilla() {
|
|
95
|
+
return (
|
|
96
|
+
<div
|
|
97
|
+
ref={mountTable}
|
|
98
|
+
style={{display: 'grid', gap: 16, padding: 16, maxWidth: 380}}>
|
|
99
|
+
<div
|
|
100
|
+
style={{
|
|
101
|
+
position: 'relative',
|
|
102
|
+
height: 150,
|
|
103
|
+
display: 'flex',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
<div style={{display: 'flex', gap: 8}} />
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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: 'useDragToSnapPoints',
|
|
7
|
+
name: 'useDragToSnapPoints — Playing card on three places',
|
|
8
|
+
displayName: 'useDragToSnapPoints — Playing card on three places',
|
|
9
|
+
description:
|
|
10
|
+
'A playing card that a sideways drag moves between three places: a slow release settles on the nearest, a quick flick carries to the next, and a release moving back returns where it started. Buttons settle it from the keyboard, and the new place is announced. Built only on the public useDragToSnapPoints hook.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: [
|
|
14
|
+
'Card',
|
|
15
|
+
'Button',
|
|
16
|
+
'Layout',
|
|
17
|
+
'Text',
|
|
18
|
+
'VisuallyHidden',
|
|
19
|
+
'useDragToSnapPoints',
|
|
20
|
+
],
|
|
21
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useLayoutEffect, useRef, useState} from 'react';
|
|
6
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
7
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
8
|
+
import {useDragToSnapPoints} from '@astryxdesign/core/hooks';
|
|
9
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
10
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
11
|
+
import {VisuallyHidden} from '@astryxdesign/core/VisuallyHidden';
|
|
12
|
+
|
|
13
|
+
const PLACES = ['Hand', 'Table', 'Discard pile'];
|
|
14
|
+
/** How far along the row each place sits, in px from where the card rests. */
|
|
15
|
+
const STEPS = [0, 110, 220];
|
|
16
|
+
|
|
17
|
+
export default function DragToSnapPointsCard() {
|
|
18
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
19
|
+
const [place, setPlace] = useState(0);
|
|
20
|
+
// The places run in reading order, so leftward in a right-to-left layout.
|
|
21
|
+
// There the snap points are negative, so they sort the other way round.
|
|
22
|
+
// The direction is the one the card renders in.
|
|
23
|
+
const [isRtl, setIsRtl] = useState(false);
|
|
24
|
+
// Reads the direction the browser computed for the card once it is laid
|
|
25
|
+
// out.
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
if (ref.current != null) {
|
|
28
|
+
setIsRtl(getComputedStyle(ref.current).direction === 'rtl');
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
const placeAt = (index: number) => (isRtl ? STEPS.length - 1 - index : index);
|
|
32
|
+
const {settleTo} = useDragToSnapPoints(ref, {
|
|
33
|
+
axis: 'x',
|
|
34
|
+
snapPoints: isRtl ? STEPS.map(step => -step) : STEPS,
|
|
35
|
+
onSettle: index => setPlace(placeAt(index)),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<VStack gap={4} style={{maxWidth: 380, padding: 16}}>
|
|
40
|
+
<Text type="body">
|
|
41
|
+
Drag the card sideways and let go: it settles on the nearest place, or
|
|
42
|
+
the next one after a quick flick.
|
|
43
|
+
</Text>
|
|
44
|
+
<HStack gap={2} style={{height: 150, alignItems: 'center'}}>
|
|
45
|
+
<Card
|
|
46
|
+
ref={ref}
|
|
47
|
+
width={96}
|
|
48
|
+
minHeight={136}
|
|
49
|
+
style={{touchAction: 'none', cursor: 'grab', userSelect: 'none'}}
|
|
50
|
+
aria-label={`Queen of hearts, on the ${PLACES[place].toLowerCase()}`}>
|
|
51
|
+
<VStack gap={1} hAlign="center" style={{paddingBlock: 32}}>
|
|
52
|
+
<Text type="display-2" weight="bold">
|
|
53
|
+
Q
|
|
54
|
+
</Text>
|
|
55
|
+
<Text type="display-3">{'\u2665'}</Text>
|
|
56
|
+
</VStack>
|
|
57
|
+
</Card>
|
|
58
|
+
</HStack>
|
|
59
|
+
<HStack gap={2}>
|
|
60
|
+
{PLACES.map((name, index) => (
|
|
61
|
+
<Button
|
|
62
|
+
key={name}
|
|
63
|
+
label={name}
|
|
64
|
+
variant={index === place ? 'primary' : 'secondary'}
|
|
65
|
+
onClick={() => settleTo(placeAt(index))}
|
|
66
|
+
/>
|
|
67
|
+
))}
|
|
68
|
+
</HStack>
|
|
69
|
+
<VisuallyHidden as="div" aria-live="polite">
|
|
70
|
+
{`The card is on the ${PLACES[place].toLowerCase()}.`}
|
|
71
|
+
</VisuallyHidden>
|
|
72
|
+
</VStack>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -252,12 +252,6 @@ export default function AIChatTemplate() {
|
|
|
252
252
|
const activeMode = MODE_OPTIONS.find(m => m.key === mode) ?? MODE_OPTIONS[0];
|
|
253
253
|
const suggestions = category ? CATEGORY_SUGGESTIONS[category] : null;
|
|
254
254
|
|
|
255
|
-
// The composer's imperative insert methods mutate the DOM without emitting a
|
|
256
|
-
// change, so dispatch an input event to sync its value and clear the placeholder.
|
|
257
|
-
const syncComposerValue = () => {
|
|
258
|
-
document.activeElement?.dispatchEvent(new Event('input', {bubbles: true}));
|
|
259
|
-
};
|
|
260
|
-
|
|
261
255
|
const applySuggestion = (prompt: string) => {
|
|
262
256
|
const input = composerInputRef.current;
|
|
263
257
|
if (!input) {
|
|
@@ -268,7 +262,6 @@ export default function AIChatTemplate() {
|
|
|
268
262
|
window.getSelection()?.selectAllChildren(document.activeElement);
|
|
269
263
|
}
|
|
270
264
|
input.insertText(prompt);
|
|
271
|
-
syncComposerValue();
|
|
272
265
|
};
|
|
273
266
|
|
|
274
267
|
const insertMention = (item: (typeof MENTION_ITEMS)[number]) => {
|
|
@@ -287,7 +280,6 @@ export default function AIChatTemplate() {
|
|
|
287
280
|
label: item.label,
|
|
288
281
|
variant: 'blue',
|
|
289
282
|
});
|
|
290
|
-
syncComposerValue();
|
|
291
283
|
};
|
|
292
284
|
|
|
293
285
|
const insertModeToken = (label: string) => {
|
|
@@ -297,7 +289,6 @@ export default function AIChatTemplate() {
|
|
|
297
289
|
label,
|
|
298
290
|
variant: 'orange',
|
|
299
291
|
});
|
|
300
|
-
syncComposerValue();
|
|
301
292
|
};
|
|
302
293
|
|
|
303
294
|
return (
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* the self-doc tests fail.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
18
|
import * as path from 'node:path';
|
|
20
19
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
20
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
21
21
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
22
22
|
import {
|
|
23
23
|
DOC_OUTPUT_BUDGET_BYTES,
|
|
@@ -75,7 +75,7 @@ export function discoverAuthoringSelfDocSources(root = AUTHORING_ROOT) {
|
|
|
75
75
|
const found = [];
|
|
76
76
|
/** @param {string} dir */
|
|
77
77
|
const walk = dir => {
|
|
78
|
-
for (const entry of
|
|
78
|
+
for (const entry of listDirEntries(dir)) {
|
|
79
79
|
if (entry.name === 'node_modules' || entry.name.startsWith('__'))
|
|
80
80
|
continue;
|
|
81
81
|
const full = path.join(dir, entry.name);
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import * as fs from 'node:fs';
|
|
19
19
|
import * as path from 'node:path';
|
|
20
20
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
21
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
21
22
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
22
23
|
import {AUTHORING_SELF_DOCS, selfDocSection} from './authoring-self-docs.mjs';
|
|
23
24
|
import {
|
|
@@ -66,7 +67,7 @@ export function discoverCliSelfDocSources(root = CLI_ROOT) {
|
|
|
66
67
|
/** @param {string} dir */
|
|
67
68
|
const walk = dir => {
|
|
68
69
|
if (!fs.existsSync(dir)) return;
|
|
69
|
-
for (const entry of
|
|
70
|
+
for (const entry of listDirEntries(dir)) {
|
|
70
71
|
if (
|
|
71
72
|
entry.name === 'node_modules' ||
|
|
72
73
|
entry.name.startsWith('__') ||
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
import * as fs from 'node:fs';
|
|
33
33
|
import * as path from 'node:path';
|
|
34
34
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
35
|
+
import {listDir, listDirEntries} from '../fs/listing-cache.mjs';
|
|
35
36
|
import {importDocModule} from '../doc-compiler/import.mjs';
|
|
36
37
|
import {CLI_PROVIDER_ID} from '../identity/providers.mjs';
|
|
37
38
|
import {parseReadableDoc} from '../doc-compiler/parse-readable.mjs';
|
|
@@ -135,7 +136,7 @@ export function discoverBuiltinTopics() {
|
|
|
135
136
|
/** @type {Record<string, string>} */
|
|
136
137
|
const topics = Object.create(null);
|
|
137
138
|
if (!fs.existsSync(BUILTIN_DOCS_DIR)) return topics;
|
|
138
|
-
for (const file of
|
|
139
|
+
for (const file of listDir(BUILTIN_DOCS_DIR)) {
|
|
139
140
|
const match = file.match(BUILTIN_TOPIC_FILE_RE);
|
|
140
141
|
if (match) topics[match[1]] = path.join(BUILTIN_DOCS_DIR, file);
|
|
141
142
|
}
|
|
@@ -152,7 +153,7 @@ export function builtinGuideFiles() {
|
|
|
152
153
|
const files = Object.values(discoverBuiltinTopics());
|
|
153
154
|
const tree = path.join(BUILTIN_DOCS_DIR, 'tree');
|
|
154
155
|
if (fs.existsSync(tree)) {
|
|
155
|
-
for (const file of
|
|
156
|
+
for (const file of listDir(tree).sort()) {
|
|
156
157
|
if (BUILTIN_TOPIC_FILE_RE.test(file)) files.push(path.join(tree, file));
|
|
157
158
|
}
|
|
158
159
|
}
|
|
@@ -524,7 +525,7 @@ export async function discoverIntegrationDocs(integration) {
|
|
|
524
525
|
const files = [];
|
|
525
526
|
/** @param {string} dirPath */
|
|
526
527
|
function scanDir(dirPath) {
|
|
527
|
-
for (const entry of
|
|
528
|
+
for (const entry of listDirEntries(dirPath)) {
|
|
528
529
|
if (entry.name === 'node_modules' || entry.name === '__tests__') continue;
|
|
529
530
|
const full = path.join(dirPath, entry.name);
|
|
530
531
|
if (entry.isDirectory()) {
|
|
@@ -737,7 +738,8 @@ export function mergeTopicReport(base, overlay) {
|
|
|
737
738
|
// It also keeps the place an earlier `after` gave the one it replaces,
|
|
738
739
|
// so sections placed after that key later still follow it.
|
|
739
740
|
if (replaced[PLACED_AFTER] != null) {
|
|
740
|
-
const placed =
|
|
741
|
+
const placed =
|
|
742
|
+
replacing === section ? withoutPosition({...section}) : replacing;
|
|
741
743
|
for (const symbol of Object.getOwnPropertySymbols(section)) {
|
|
742
744
|
if (!(symbol in placed)) {
|
|
743
745
|
Object.defineProperty(
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
* surface reads
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
18
|
import * as path from 'node:path';
|
|
20
19
|
import {parseIconDefinition} from '../../authoring/doctypes/icon-definition/parse.mjs';
|
|
21
20
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
21
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
22
22
|
import {readStaticDescriptorValue} from './theme-discovery.mjs';
|
|
23
23
|
|
|
24
24
|
/** @typedef {import('../../authoring/doctypes/icon-definition/type').IconDefinitionDoc} IconDefinitionDoc */
|
|
@@ -53,10 +53,10 @@ export function readDefinitionsDir(dir, owner) {
|
|
|
53
53
|
const definitions = [];
|
|
54
54
|
/** @type {Array<{file: string, message: string}>} */
|
|
55
55
|
const errors = [];
|
|
56
|
-
/** @type {fs.Dirent[]} */
|
|
56
|
+
/** @type {import('node:fs').Dirent[]} */
|
|
57
57
|
let entries;
|
|
58
58
|
try {
|
|
59
|
-
entries =
|
|
59
|
+
entries = listDirEntries(dir);
|
|
60
60
|
} catch {
|
|
61
61
|
return {definitions, errors};
|
|
62
62
|
}
|
|
@@ -28,6 +28,7 @@ import {createRequire} from 'node:module';
|
|
|
28
28
|
import {readDocView} from '../doc-compiler/read.mjs';
|
|
29
29
|
import {importDocModule} from '../doc-compiler/import.mjs';
|
|
30
30
|
import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
|
|
31
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
31
32
|
import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
|
|
32
33
|
import {Project} from '../config/project.mjs';
|
|
33
34
|
import {
|
|
@@ -1115,8 +1116,7 @@ export function listTemplates() {
|
|
|
1115
1116
|
const all = [];
|
|
1116
1117
|
if (fs.existsSync(PAGES_DIR)) {
|
|
1117
1118
|
all.push(
|
|
1118
|
-
...
|
|
1119
|
-
.readdirSync(PAGES_DIR, {withFileTypes: true})
|
|
1119
|
+
...listDirEntries(PAGES_DIR)
|
|
1120
1120
|
.filter(e => e.isDirectory())
|
|
1121
1121
|
.map(e => e.name),
|
|
1122
1122
|
);
|
|
@@ -1133,7 +1133,7 @@ function findDocFiles(dir, pattern) {
|
|
|
1133
1133
|
/** @type {string[]} */
|
|
1134
1134
|
const results = [];
|
|
1135
1135
|
if (!fs.existsSync(dir)) return results;
|
|
1136
|
-
for (const entry of
|
|
1136
|
+
for (const entry of listDirEntries(dir)) {
|
|
1137
1137
|
const full = path.join(dir, entry.name);
|
|
1138
1138
|
if (entry.isDirectory()) {
|
|
1139
1139
|
results.push(...findDocFiles(full, pattern));
|
|
@@ -1160,9 +1160,7 @@ export function findPageDocFile(dirPath) {
|
|
|
1160
1160
|
|
|
1161
1161
|
async function discoverPages() {
|
|
1162
1162
|
if (!fs.existsSync(PAGES_DIR)) return [];
|
|
1163
|
-
const dirs =
|
|
1164
|
-
.readdirSync(PAGES_DIR, {withFileTypes: true})
|
|
1165
|
-
.filter(e => e.isDirectory());
|
|
1163
|
+
const dirs = listDirEntries(PAGES_DIR).filter(e => e.isDirectory());
|
|
1166
1164
|
|
|
1167
1165
|
/** @type {DiscoveredTemplate[]} */
|
|
1168
1166
|
const templates = [];
|
|
@@ -1602,7 +1600,7 @@ function findIntegrationDocFiles(root) {
|
|
|
1602
1600
|
if (!fs.existsSync(root)) return results;
|
|
1603
1601
|
/** @param {string} dir */
|
|
1604
1602
|
const walk = dir => {
|
|
1605
|
-
for (const entry of
|
|
1603
|
+
for (const entry of listDirEntries(dir)) {
|
|
1606
1604
|
const full = path.join(dir, entry.name);
|
|
1607
1605
|
if (entry.isDirectory()) {
|
|
1608
1606
|
walk(full);
|
|
@@ -22,6 +22,7 @@ import * as path from 'node:path';
|
|
|
22
22
|
import {lowerDoc} from '../doc-compiler/compile.mjs';
|
|
23
23
|
import {packageSource} from '../doc-compiler/source.mjs';
|
|
24
24
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
25
|
+
import {listDirEntries} from '../fs/listing-cache.mjs';
|
|
25
26
|
import {formatCliCommand} from '../env/package-manager.mjs';
|
|
26
27
|
import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
|
|
27
28
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
@@ -1187,7 +1188,7 @@ function listThemeFolder(folder) {
|
|
|
1187
1188
|
const symlinks = [];
|
|
1188
1189
|
/** @param {string} directory */
|
|
1189
1190
|
function walk(directory) {
|
|
1190
|
-
for (const entry of
|
|
1191
|
+
for (const entry of listDirEntries(directory)) {
|
|
1191
1192
|
if (isIgnoredThemeEntry(entry.name)) continue;
|
|
1192
1193
|
const full = path.join(directory, entry.name);
|
|
1193
1194
|
const relative = path.relative(folder, full).split(path.sep).join('/');
|
|
@@ -1291,8 +1292,7 @@ export function discoverUnmigratedThemeCopies(
|
|
|
1291
1292
|
) {
|
|
1292
1293
|
const root = path.resolve(projectDir, owner);
|
|
1293
1294
|
if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) return [];
|
|
1294
|
-
return
|
|
1295
|
-
.readdirSync(root, {withFileTypes: true})
|
|
1295
|
+
return listDirEntries(root)
|
|
1296
1296
|
.filter(entry => entry.isDirectory() && !isIgnoredThemeEntry(entry.name))
|
|
1297
1297
|
.map(entry => unmigratedThemeCopy(path.join(root, entry.name)))
|
|
1298
1298
|
.filter(copy => copy !== null)
|
|
@@ -1369,9 +1369,9 @@ export function discoverThemeDirectory(
|
|
|
1369
1369
|
/** @type {DiscoveredTheme[]} */
|
|
1370
1370
|
const themes = [];
|
|
1371
1371
|
const slugs = new Set();
|
|
1372
|
-
const rootEntries =
|
|
1373
|
-
|
|
1374
|
-
|
|
1372
|
+
const rootEntries = listDirEntries(themeRoot).filter(
|
|
1373
|
+
entry => !isIgnoredThemeEntry(entry.name),
|
|
1374
|
+
);
|
|
1375
1375
|
const rootDescriptor = rootEntries.find(
|
|
1376
1376
|
entry => entry.isFile() && entry.name.endsWith(THEME_DOC_SUFFIX),
|
|
1377
1377
|
);
|
|
@@ -1614,8 +1614,7 @@ export function unreadThemeFolders(themeRoot, {packageDir, packageName} = {}) {
|
|
|
1614
1614
|
if (!fs.existsSync(themeRoot) || !fs.statSync(themeRoot).isDirectory()) {
|
|
1615
1615
|
return [];
|
|
1616
1616
|
}
|
|
1617
|
-
const folders =
|
|
1618
|
-
.readdirSync(themeRoot, {withFileTypes: true})
|
|
1617
|
+
const folders = listDirEntries(themeRoot)
|
|
1619
1618
|
.filter(entry => entry.isDirectory() && !isIgnoredThemeEntry(entry.name))
|
|
1620
1619
|
.map(entry => path.join(themeRoot, entry.name))
|
|
1621
1620
|
.sort();
|
|
@@ -1630,8 +1629,7 @@ export function unreadThemeFolders(themeRoot, {packageDir, packageName} = {}) {
|
|
|
1630
1629
|
if (unread.length === 0) return [];
|
|
1631
1630
|
|
|
1632
1631
|
const modules = [
|
|
1633
|
-
...
|
|
1634
|
-
.readdirSync(themeRoot, {withFileTypes: true})
|
|
1632
|
+
...listDirEntries(themeRoot)
|
|
1635
1633
|
.filter(
|
|
1636
1634
|
entry =>
|
|
1637
1635
|
entry.isFile() &&
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import * as fs from 'node:fs';
|
|
21
21
|
import * as path from 'node:path';
|
|
22
22
|
import {CLI_ROOT} from '../fs/paths.mjs';
|
|
23
|
+
import {listDir} from '../fs/listing-cache.mjs';
|
|
23
24
|
import {loadCliSelfDocs} from '../discovery/cli-self-docs.mjs';
|
|
24
25
|
import {astryxIconDefinitions} from '../discovery/icon-definition-discovery.mjs';
|
|
25
26
|
import {routeSegment} from '../discovery/docs-section-key.mjs';
|
|
@@ -812,8 +813,7 @@ function adoptionsFor(doc, declared, routeOf) {
|
|
|
812
813
|
*/
|
|
813
814
|
export function treeDocFiles(dir = TREE_DOCS_DIR) {
|
|
814
815
|
if (!fs.existsSync(dir)) return [];
|
|
815
|
-
return
|
|
816
|
-
.readdirSync(dir)
|
|
816
|
+
return listDir(dir)
|
|
817
817
|
.filter(file => /^[\w-]+\.doc\.mjs$/u.test(file))
|
|
818
818
|
.sort(byText)
|
|
819
819
|
.map(file => path.join(dir, file));
|
|
@@ -25,7 +25,9 @@ export function oncePerListing<T>(key: string, compute: () => T): T;
|
|
|
25
25
|
export function listingCacheActive(): boolean;
|
|
26
26
|
/**
|
|
27
27
|
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
28
|
-
* caller that sorts it cannot reorder another caller's listing.
|
|
28
|
+
* caller that sorts it cannot reorder another caller's listing. The names come
|
|
29
|
+
* from the same read as {@link listDirEntries}, so a folder listed both ways
|
|
30
|
+
* is read once.
|
|
29
31
|
* @param {string} dir
|
|
30
32
|
* @returns {string[]}
|
|
31
33
|
*/
|
|
@@ -2,23 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file One directory listing per path for the duration of one read-only
|
|
5
|
-
* operation.
|
|
5
|
+
* operation, kept for later operations while the folder is unchanged.
|
|
6
6
|
*
|
|
7
7
|
* @input A read-only operation (`withListingCache(fn)`), and directory paths
|
|
8
8
|
* its discovery helpers list or probe.
|
|
9
9
|
* @output The same answers `fs.readdirSync` / `fs.existsSync` give, read from
|
|
10
10
|
* disk once per path while the operation runs, and `oncePerListing`, a
|
|
11
|
-
* value computed once per operation.
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
11
|
+
* value computed once per operation. A later operation in the same process
|
|
12
|
+
* reuses a listing while its folder's stamp is unchanged.
|
|
13
|
+
* @position Used by the name resolvers and doc walkers in
|
|
14
|
+
* foundation/discovery and by `existsCaseExact`. A search or build resolves
|
|
15
|
+
* ~160 components and their hooks, and each resolution walks the same
|
|
16
|
+
* source tree again. Inside one operation the tree does not change, so each
|
|
17
|
+
* directory is read once. Outside `withListingCache` every helper reads the
|
|
18
|
+
* disk directly, exactly as before.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
21
22
|
import * as fs from 'node:fs';
|
|
23
|
+
import * as path from 'node:path';
|
|
24
|
+
import {performance} from 'node:perf_hooks';
|
|
25
|
+
import {fileStamp, recordContentRead} from './read-record.mjs';
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* @typedef {{
|
|
@@ -33,6 +37,24 @@ import * as fs from 'node:fs';
|
|
|
33
37
|
/** @type {AsyncLocalStorage<ListingCache>} */
|
|
34
38
|
const scope = new AsyncLocalStorage();
|
|
35
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Listings kept for later operations in this process, by folder. Each holds
|
|
42
|
+
* the folder's stamp (`fileStamp`: size, times and inode) and when this
|
|
43
|
+
* process first saw it. Once the stamp has held for {@link SETTLE_MS}, it
|
|
44
|
+
* holds the entries too. Adding, removing or renaming an entry changes the
|
|
45
|
+
* stamp.
|
|
46
|
+
* @type {Map<string, {stamp: string, since: number, entries: fs.Dirent[] | null}>}
|
|
47
|
+
*/
|
|
48
|
+
const kept = new Map();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* How long a folder's stamp must hold, by this process's clock, before its
|
|
52
|
+
* listing is kept. A file system can store times as coarsely as 2 s. So a
|
|
53
|
+
* change within one tick of the last can leave the stamp as it was. After the
|
|
54
|
+
* stamp has held this long, a new change falls in a later tick.
|
|
55
|
+
*/
|
|
56
|
+
const SETTLE_MS = 2000;
|
|
57
|
+
|
|
36
58
|
/**
|
|
37
59
|
* Run `fn` with a listing cache. A nested call shares the outer cache. Only
|
|
38
60
|
* wrap operations that do not change the files they list.
|
|
@@ -79,7 +101,9 @@ export function listingCacheActive() {
|
|
|
79
101
|
|
|
80
102
|
/**
|
|
81
103
|
* `fs.readdirSync(dir)`, read once per operation. Returns a fresh array, so a
|
|
82
|
-
* caller that sorts it cannot reorder another caller's listing.
|
|
104
|
+
* caller that sorts it cannot reorder another caller's listing. The names come
|
|
105
|
+
* from the same read as {@link listDirEntries}, so a folder listed both ways
|
|
106
|
+
* is read once.
|
|
83
107
|
* @param {string} dir
|
|
84
108
|
* @returns {string[]}
|
|
85
109
|
*/
|
|
@@ -88,7 +112,7 @@ export function listDir(dir) {
|
|
|
88
112
|
if (!cache) return fs.readdirSync(dir);
|
|
89
113
|
let names = cache.names.get(dir);
|
|
90
114
|
if (!names) {
|
|
91
|
-
names =
|
|
115
|
+
names = listDirEntries(dir).map(entry => entry.name);
|
|
92
116
|
cache.names.set(dir, names);
|
|
93
117
|
}
|
|
94
118
|
return names.slice();
|
|
@@ -104,12 +128,40 @@ export function listDirEntries(dir) {
|
|
|
104
128
|
if (!cache) return fs.readdirSync(dir, {withFileTypes: true});
|
|
105
129
|
let entries = cache.entries.get(dir);
|
|
106
130
|
if (!entries) {
|
|
107
|
-
entries =
|
|
131
|
+
entries = keptOrRead(dir);
|
|
108
132
|
cache.entries.set(dir, entries);
|
|
109
133
|
}
|
|
110
134
|
return entries.slice();
|
|
111
135
|
}
|
|
112
136
|
|
|
137
|
+
/**
|
|
138
|
+
* `dir`'s entries for an operation. They are the kept listing while the
|
|
139
|
+
* folder's stamp is the one it was kept with. Otherwise they are a new read,
|
|
140
|
+
* kept once the stamp has held for {@link SETTLE_MS}.
|
|
141
|
+
* @param {string} dir
|
|
142
|
+
* @returns {fs.Dirent[]}
|
|
143
|
+
*/
|
|
144
|
+
function keptOrRead(dir) {
|
|
145
|
+
const folder = path.resolve(dir);
|
|
146
|
+
// A reuse check (read-record.mjs) records the folder's state before the
|
|
147
|
+
// stamp below is taken. So a change between the two shows as a change.
|
|
148
|
+
recordContentRead(folder);
|
|
149
|
+
const before = performance.now();
|
|
150
|
+
const stamp = fileStamp(folder);
|
|
151
|
+
const held = kept.get(folder);
|
|
152
|
+
if (held?.entries && held.stamp === stamp) return held.entries;
|
|
153
|
+
const entries = fs.readdirSync(dir, {withFileTypes: true});
|
|
154
|
+
if (held?.stamp !== stamp) {
|
|
155
|
+
// Taken after the stamp, so the stamp's times are no later than this.
|
|
156
|
+
kept.set(folder, {stamp, since: performance.now(), entries: null});
|
|
157
|
+
} else if (before - held.since >= SETTLE_MS) {
|
|
158
|
+
// Read after the stamp held for the settle time: a later change gets a
|
|
159
|
+
// new stamp.
|
|
160
|
+
kept.set(folder, {stamp, since: held.since, entries});
|
|
161
|
+
}
|
|
162
|
+
return entries;
|
|
163
|
+
}
|
|
164
|
+
|
|
113
165
|
/**
|
|
114
166
|
* The entry named exactly `name` in `dir`'s listing, or null when the folder
|
|
115
167
|
* holds no such name or cannot be read. Inside an operation, a name the
|
package/foundation/fs/paths.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
16
16
|
import {
|
|
17
17
|
findEntry,
|
|
18
18
|
listDir,
|
|
19
|
+
listDirEntries,
|
|
19
20
|
listingCacheActive,
|
|
20
21
|
pathExists,
|
|
21
22
|
} from './listing-cache.mjs';
|
|
@@ -811,7 +812,7 @@ export function discoverExternalPackages(startDir = process.cwd()) {
|
|
|
811
812
|
/** @param {string} searchDir */
|
|
812
813
|
const scanDir = searchDir => {
|
|
813
814
|
if (!fs.existsSync(searchDir)) return;
|
|
814
|
-
const entries =
|
|
815
|
+
const entries = listDirEntries(searchDir);
|
|
815
816
|
|
|
816
817
|
for (const entry of entries) {
|
|
817
818
|
if (!entry.isDirectory()) continue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/cli",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.10-canary.010db3f",
|
|
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,30 +124,18 @@
|
|
|
124
124
|
"zod": "^4.4.3"
|
|
125
125
|
},
|
|
126
126
|
"peerDependencies": {
|
|
127
|
-
"@astryxdesign/
|
|
128
|
-
"@astryxdesign/core": "*",
|
|
129
|
-
"@astryxdesign/lab": "*",
|
|
130
|
-
"@astryxdesign/theme-neutral": "*"
|
|
127
|
+
"@astryxdesign/core": "0.7.10-canary.010db3f"
|
|
131
128
|
},
|
|
132
129
|
"peerDependenciesMeta": {
|
|
133
|
-
"@astryxdesign/charts": {
|
|
134
|
-
"optional": true
|
|
135
|
-
},
|
|
136
130
|
"@astryxdesign/core": {
|
|
137
131
|
"optional": true
|
|
138
|
-
},
|
|
139
|
-
"@astryxdesign/lab": {
|
|
140
|
-
"optional": true
|
|
141
|
-
},
|
|
142
|
-
"@astryxdesign/theme-neutral": {
|
|
143
|
-
"optional": true
|
|
144
132
|
}
|
|
145
133
|
},
|
|
146
134
|
"devDependencies": {
|
|
147
|
-
"@astryxdesign/charts": "
|
|
148
|
-
"@astryxdesign/core": "
|
|
149
|
-
"@astryxdesign/lab": "
|
|
150
|
-
"@astryxdesign/theme-neutral": "
|
|
135
|
+
"@astryxdesign/charts": "0.7.10-canary.010db3f",
|
|
136
|
+
"@astryxdesign/core": "0.7.10-canary.010db3f",
|
|
137
|
+
"@astryxdesign/lab": "0.7.10-canary.010db3f",
|
|
138
|
+
"@astryxdesign/theme-neutral": "0.7.10-canary.010db3f",
|
|
151
139
|
"@heroicons/react": "^2.2.0",
|
|
152
140
|
"@stylexjs/stylex": "^0.19.0",
|
|
153
141
|
"@types/babel__core": "^7.20.5",
|