@astryxdesign/cli 0.7.6-canary.fdabeba → 0.7.6
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 +42 -0
- package/README.md +2 -2
- package/api/component/detail/showcase/showcase.mjs +9 -3
- package/api/search/_adapter.d.mts +3 -1
- package/api/search/_adapter.mjs +19 -19
- package/api/template/copy/copy.mjs +13 -7
- package/api/template/show/show.mjs +12 -8
- package/api/template/skeleton/skeleton.mjs +14 -5
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +2 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/assets/docs/motion.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetShowcase.tsx +12 -12
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +14 -10
- package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.doc.mjs +20 -0
- package/assets/templates/blocks/components/Hooks/useCollatorHookUsage.tsx +55 -0
- package/assets/templates/blocks/components/Hooks/usePressFeedbackHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/usePressFeedbackHookUsage.tsx +41 -0
- package/assets/templates/blocks/components/Hooks/useTranslatorHookUsage.doc.mjs +22 -0
- package/assets/templates/blocks/components/Hooks/useTranslatorHookUsage.tsx +88 -0
- package/assets/templates/blocks/components/Toast/useToastHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Toast/useToastHookUsage.tsx +65 -0
- package/clients/cli/commands/template.mjs +29 -3
- package/foundation/discovery/package-tsconfig.mjs +34 -0
- package/foundation/discovery/template-adapter.d.mts +76 -1
- package/foundation/discovery/template-adapter.mjs +418 -13
- package/foundation/discovery/template-icons.mjs +7 -89
- package/foundation/discovery/template-source-tree.d.mts +48 -0
- package/foundation/discovery/template-source-tree.mjs +159 -0
- package/foundation/fs/read-record.d.mts +4 -1
- package/foundation/fs/read-record.mjs +9 -5
- package/foundation/response/response-types.doc.mjs +2 -2
- package/package.json +10 -9
|
@@ -0,0 +1,20 @@
|
|
|
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: 'useCollator',
|
|
7
|
+
name: 'useCollator — Locale-aware Name Sort',
|
|
8
|
+
displayName: 'useCollator — Locale-aware Name Sort',
|
|
9
|
+
description:
|
|
10
|
+
'A list of names sorted with the compare function from useCollator: accented and lowercase names land where a reader expects, and switching the provider locale to Swedish moves Å and Ö after Z.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: [
|
|
14
|
+
'InternationalizationProvider',
|
|
15
|
+
'Card',
|
|
16
|
+
'SegmentedControl',
|
|
17
|
+
'List',
|
|
18
|
+
'Layout',
|
|
19
|
+
],
|
|
20
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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 {
|
|
8
|
+
InternationalizationProvider,
|
|
9
|
+
useCollator,
|
|
10
|
+
} from '@astryxdesign/core/i18n';
|
|
11
|
+
import {VStack} from '@astryxdesign/core/Layout';
|
|
12
|
+
import {List, ListItem} from '@astryxdesign/core/List';
|
|
13
|
+
import {
|
|
14
|
+
SegmentedControl,
|
|
15
|
+
SegmentedControlItem,
|
|
16
|
+
} from '@astryxdesign/core/SegmentedControl';
|
|
17
|
+
|
|
18
|
+
type Locale = 'en' | 'sv-SE';
|
|
19
|
+
|
|
20
|
+
const PEOPLE = ['Zoë', 'emma', 'Örjan', 'Ana', 'Émile', 'oscar', 'Åsa'];
|
|
21
|
+
|
|
22
|
+
function PeopleList() {
|
|
23
|
+
const collator = useCollator();
|
|
24
|
+
const sorted = [...PEOPLE].sort(collator.compare);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<List density="compact" hasDividers>
|
|
28
|
+
{sorted.map(name => (
|
|
29
|
+
<ListItem key={name} label={name} />
|
|
30
|
+
))}
|
|
31
|
+
</List>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default function UseCollatorHookUsage() {
|
|
36
|
+
const [locale, setLocale] = useState<Locale>('en');
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<InternationalizationProvider locale={locale}>
|
|
40
|
+
<Card width={320} padding={4}>
|
|
41
|
+
<VStack gap={3}>
|
|
42
|
+
<SegmentedControl
|
|
43
|
+
label="Sort order"
|
|
44
|
+
value={locale}
|
|
45
|
+
onChange={nextLocale => setLocale(nextLocale as Locale)}
|
|
46
|
+
size="sm">
|
|
47
|
+
<SegmentedControlItem value="en" label="English" />
|
|
48
|
+
<SegmentedControlItem value="sv-SE" label="Swedish" />
|
|
49
|
+
</SegmentedControl>
|
|
50
|
+
<PeopleList />
|
|
51
|
+
</VStack>
|
|
52
|
+
</Card>
|
|
53
|
+
</InternationalizationProvider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -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: 'usePressFeedback',
|
|
7
|
+
name: 'usePressFeedback — Pressable Card',
|
|
8
|
+
displayName: 'usePressFeedback — Pressable Card',
|
|
9
|
+
description:
|
|
10
|
+
'A Card made pressable with usePressFeedback: its marker and the interactionOverlayStyles backgroundImage overlay go straight on the Card, so a press darkens the card the way every Astryx pressable does; focusOutlineStyles.focusVisible gives it the shared Astryx focus ring for keyboard focus; and a click, Enter or Space flips it.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Card'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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 {usePressFeedback} from '@astryxdesign/core/hooks';
|
|
8
|
+
import {
|
|
9
|
+
focusOutlineStyles,
|
|
10
|
+
interactionOverlayStyles,
|
|
11
|
+
} from '@astryxdesign/core/utils';
|
|
12
|
+
import {PlayingCardContents} from '@astryx-docs/demo-content';
|
|
13
|
+
|
|
14
|
+
export default function UsePressFeedbackHookUsage() {
|
|
15
|
+
const pressable = usePressFeedback();
|
|
16
|
+
const [isFaceUp, setIsFaceUp] = useState(true);
|
|
17
|
+
const flip = () => setIsFaceUp(faceUp => !faceUp);
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<Card
|
|
21
|
+
{...pressable}
|
|
22
|
+
xstyle={[
|
|
23
|
+
interactionOverlayStyles.backgroundImage,
|
|
24
|
+
focusOutlineStyles.focusVisible,
|
|
25
|
+
]}
|
|
26
|
+
width={160}
|
|
27
|
+
role="button"
|
|
28
|
+
tabIndex={0}
|
|
29
|
+
aria-label="Flip card"
|
|
30
|
+
aria-pressed={!isFaceUp}
|
|
31
|
+
onClick={flip}
|
|
32
|
+
onKeyDown={event => {
|
|
33
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
flip();
|
|
36
|
+
}
|
|
37
|
+
}}>
|
|
38
|
+
<PlayingCardContents rank="Q" suit="hearts" faceDown={!isFaceUp} />
|
|
39
|
+
</Card>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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: 'useTranslator',
|
|
7
|
+
name: 'useTranslator — Load More Footer',
|
|
8
|
+
displayName: 'useTranslator — Load More Footer',
|
|
9
|
+
description:
|
|
10
|
+
'A "Load more" footer under a list that gets its button label and its "Showing 3 of 9" count from the function useTranslator returns, with app message keys supplied per locale through InternationalizationProvider, so switching the provider to French changes both strings.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: [
|
|
14
|
+
'InternationalizationProvider',
|
|
15
|
+
'Card',
|
|
16
|
+
'SegmentedControl',
|
|
17
|
+
'List',
|
|
18
|
+
'Text',
|
|
19
|
+
'Button',
|
|
20
|
+
'Layout',
|
|
21
|
+
],
|
|
22
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useState} from 'react';
|
|
6
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
7
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
8
|
+
import {
|
|
9
|
+
InternationalizationProvider,
|
|
10
|
+
useTranslator,
|
|
11
|
+
type MessagesByLocale,
|
|
12
|
+
} from '@astryxdesign/core/i18n';
|
|
13
|
+
import {HStack, VStack} from '@astryxdesign/core/Layout';
|
|
14
|
+
import {List, ListItem} from '@astryxdesign/core/List';
|
|
15
|
+
import {
|
|
16
|
+
SegmentedControl,
|
|
17
|
+
SegmentedControlItem,
|
|
18
|
+
} from '@astryxdesign/core/SegmentedControl';
|
|
19
|
+
import {Text} from '@astryxdesign/core/Text';
|
|
20
|
+
|
|
21
|
+
type Locale = 'en' | 'fr';
|
|
22
|
+
|
|
23
|
+
const MESSAGES: MessagesByLocale = {
|
|
24
|
+
en: {
|
|
25
|
+
'@myapp.invoices.loadMore': {defaultMessage: 'Load more'},
|
|
26
|
+
'@myapp.invoices.showing': {
|
|
27
|
+
defaultMessage: 'Showing {shown, number} of {total, number}',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
fr: {
|
|
31
|
+
'@myapp.invoices.loadMore': {defaultMessage: 'Charger plus'},
|
|
32
|
+
'@myapp.invoices.showing': {
|
|
33
|
+
defaultMessage: '{shown, number} sur {total, number} affichées',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const INVOICES = Array.from({length: 9}, (_, index) => `INV-${1001 + index}`);
|
|
39
|
+
const PAGE_SIZE = 3;
|
|
40
|
+
|
|
41
|
+
function InvoiceList() {
|
|
42
|
+
const translate = useTranslator();
|
|
43
|
+
const [shownCount, setShownCount] = useState(PAGE_SIZE);
|
|
44
|
+
const total = INVOICES.length;
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<VStack gap={3}>
|
|
48
|
+
<List density="compact" hasDividers>
|
|
49
|
+
{INVOICES.slice(0, shownCount).map(invoice => (
|
|
50
|
+
<ListItem key={invoice} label={invoice} />
|
|
51
|
+
))}
|
|
52
|
+
</List>
|
|
53
|
+
<HStack gap={2} hAlign="between" vAlign="center">
|
|
54
|
+
<Text type="supporting">
|
|
55
|
+
{translate('@myapp.invoices.showing', {shown: shownCount, total})}
|
|
56
|
+
</Text>
|
|
57
|
+
<Button
|
|
58
|
+
label={translate('@myapp.invoices.loadMore')}
|
|
59
|
+
size="sm"
|
|
60
|
+
isDisabled={shownCount >= total}
|
|
61
|
+
onClick={() => setShownCount(count => count + PAGE_SIZE)}
|
|
62
|
+
/>
|
|
63
|
+
</HStack>
|
|
64
|
+
</VStack>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function UseTranslatorHookUsage() {
|
|
69
|
+
const [locale, setLocale] = useState<Locale>('en');
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<InternationalizationProvider locale={locale} messages={MESSAGES}>
|
|
73
|
+
<Card width={360} padding={4}>
|
|
74
|
+
<VStack gap={3}>
|
|
75
|
+
<SegmentedControl
|
|
76
|
+
label="Language"
|
|
77
|
+
value={locale}
|
|
78
|
+
onChange={nextLocale => setLocale(nextLocale as Locale)}
|
|
79
|
+
size="sm">
|
|
80
|
+
<SegmentedControlItem value="en" label="English" />
|
|
81
|
+
<SegmentedControlItem value="fr" label="Français" />
|
|
82
|
+
</SegmentedControl>
|
|
83
|
+
<InvoiceList />
|
|
84
|
+
</VStack>
|
|
85
|
+
</Card>
|
|
86
|
+
</InternationalizationProvider>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -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: 'useToast',
|
|
7
|
+
name: 'useToast — Settings Saved',
|
|
8
|
+
displayName: 'useToast — Settings Saved',
|
|
9
|
+
description:
|
|
10
|
+
'Shows a toast from the function useToast returns: a "Settings saved" confirmation with an Undo action, a uniqueID so pressing the button again replaces the toast instead of stacking another, and an error toast when the request fails.',
|
|
11
|
+
isReady: true,
|
|
12
|
+
aspectRatio: 4 / 3,
|
|
13
|
+
componentsUsed: ['Toast', 'Card', 'TextInput', 'Switch', 'Button', 'Layout'],
|
|
14
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
'use client';
|
|
4
|
+
|
|
5
|
+
import {useState} from 'react';
|
|
6
|
+
import {Button} from '@astryxdesign/core/Button';
|
|
7
|
+
import {Card} from '@astryxdesign/core/Card';
|
|
8
|
+
import {VStack} from '@astryxdesign/core/Layout';
|
|
9
|
+
import {Switch} from '@astryxdesign/core/Switch';
|
|
10
|
+
import {TextInput} from '@astryxdesign/core/TextInput';
|
|
11
|
+
import {useToast} from '@astryxdesign/core/Toast';
|
|
12
|
+
|
|
13
|
+
export default function UseToastHookUsage() {
|
|
14
|
+
const toast = useToast();
|
|
15
|
+
const [name, setName] = useState('Ada Lovelace');
|
|
16
|
+
const [savedName, setSavedName] = useState('Ada Lovelace');
|
|
17
|
+
const [undoName, setUndoName] = useState('Ada Lovelace');
|
|
18
|
+
const [isSaveFailing, setIsSaveFailing] = useState(false);
|
|
19
|
+
|
|
20
|
+
const save = () => {
|
|
21
|
+
if (isSaveFailing) {
|
|
22
|
+
toast({
|
|
23
|
+
type: 'error',
|
|
24
|
+
body: 'Could not save settings',
|
|
25
|
+
uniqueID: 'settings-save',
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Saving an unchanged name keeps the earlier undo target.
|
|
30
|
+
const nextUndoName = name === savedName ? undoName : savedName;
|
|
31
|
+
setUndoName(nextUndoName);
|
|
32
|
+
setSavedName(name);
|
|
33
|
+
const dismiss = toast({
|
|
34
|
+
body: 'Settings saved',
|
|
35
|
+
// A repeated Save replaces this toast instead of stacking another.
|
|
36
|
+
uniqueID: 'settings-save',
|
|
37
|
+
endContent: (
|
|
38
|
+
<Button
|
|
39
|
+
label="Undo"
|
|
40
|
+
variant="ghost"
|
|
41
|
+
size="sm"
|
|
42
|
+
onClick={() => {
|
|
43
|
+
setName(nextUndoName);
|
|
44
|
+
setSavedName(nextUndoName);
|
|
45
|
+
dismiss();
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
),
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Card width={360} padding={4}>
|
|
54
|
+
<VStack gap={3}>
|
|
55
|
+
<TextInput label="Display name" value={name} onChange={setName} />
|
|
56
|
+
<Switch
|
|
57
|
+
label="Simulate a failed save"
|
|
58
|
+
value={isSaveFailing}
|
|
59
|
+
onChange={setIsSaveFailing}
|
|
60
|
+
/>
|
|
61
|
+
<Button label="Save" variant="primary" onClick={save} />
|
|
62
|
+
</VStack>
|
|
63
|
+
</Card>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -32,6 +32,20 @@ export {discoverTemplates, listTemplates} from '../../../api/template/template.m
|
|
|
32
32
|
* )} TemplateResponse
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* The line saying how many docs-only demo content elements became a
|
|
37
|
+
* placeholder, in the copied file when one is named.
|
|
38
|
+
* @param {number} count
|
|
39
|
+
* @param {string} [file]
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
function demoContentNote(count, file) {
|
|
43
|
+
return (
|
|
44
|
+
`Replaced ${count} Astryx demo content element${count === 1 ? '' : 's'}${file ? ` in ${file}` : ''} ` +
|
|
45
|
+
'with a <Text>Card content</Text> placeholder. Put your own content there.'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
35
49
|
/**
|
|
36
50
|
* The icon report as text lines (AST-084 FR10): one line per mapped or kept
|
|
37
51
|
* icon, or one line saying why nothing was mapped. Nothing when the project
|
|
@@ -245,7 +259,8 @@ export function registerTemplate(program) {
|
|
|
245
259
|
// from (cli-surface INV28) and the note about replaced demo media go
|
|
246
260
|
// to stderr, the note in the copy receipt's words. (Text mode only:
|
|
247
261
|
// --json returned above with both in the envelope.)
|
|
248
|
-
const {source, demoMediaReplaced, icons} =
|
|
262
|
+
const {source, demoMediaReplaced, demoContentReplaced, icons} =
|
|
263
|
+
result.data;
|
|
249
264
|
console.error(`package: ${result.package}`);
|
|
250
265
|
emit(code(source));
|
|
251
266
|
if (demoMediaReplaced > 0) {
|
|
@@ -254,14 +269,23 @@ export function registerTemplate(program) {
|
|
|
254
269
|
'images now show a neutral placeholder and videos have an empty source. Supply your own media there.',
|
|
255
270
|
);
|
|
256
271
|
}
|
|
272
|
+
if (demoContentReplaced > 0) {
|
|
273
|
+
console.error(demoContentNote(demoContentReplaced));
|
|
274
|
+
}
|
|
257
275
|
// The icon report goes to stderr too, so stdout stays the source.
|
|
258
276
|
for (const line of iconLines(icons)) console.error(line);
|
|
259
277
|
break;
|
|
260
278
|
}
|
|
261
279
|
|
|
262
280
|
case 'template.copy': {
|
|
263
|
-
const {
|
|
264
|
-
|
|
281
|
+
const {
|
|
282
|
+
outputDir,
|
|
283
|
+
fileName,
|
|
284
|
+
demoMediaReplaced,
|
|
285
|
+
demoContentReplaced,
|
|
286
|
+
notes,
|
|
287
|
+
icons,
|
|
288
|
+
} = result.data;
|
|
265
289
|
const file = `${outputDir}/${fileName}`;
|
|
266
290
|
const iconText = iconLines(icons);
|
|
267
291
|
emit(
|
|
@@ -272,6 +296,8 @@ export function registerTemplate(program) {
|
|
|
272
296
|
`Replaced ${demoMediaReplaced} Astryx demo media reference${demoMediaReplaced === 1 ? '' : 's'} in ${file}: ` +
|
|
273
297
|
'images now show a neutral placeholder and videos have an empty source. Supply your own media there.',
|
|
274
298
|
),
|
|
299
|
+
demoContentReplaced > 0 &&
|
|
300
|
+
text(demoContentNote(demoContentReplaced, file)),
|
|
275
301
|
...notes.map(/** @param {string} note */ note => text(note)),
|
|
276
302
|
iconText.length > 0 && text(iconText.join('\n')),
|
|
277
303
|
);
|
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
|
|
27
27
|
import * as fs from 'node:fs';
|
|
28
28
|
import * as path from 'node:path';
|
|
29
|
+
import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What `isAmbient` found for each file, per TypeScript, kept while the
|
|
33
|
+
* file's stamp (`fileStamp`) is the same. A process that compares a package
|
|
34
|
+
* more than once reads the same config each time, and reading a file the way
|
|
35
|
+
* TypeScript does costs far more than a stat.
|
|
36
|
+
* @type {WeakMap<object, Map<string, {stamp: string, ambient: boolean}>>}
|
|
37
|
+
*/
|
|
38
|
+
const ambientByFile = new WeakMap();
|
|
29
39
|
|
|
30
40
|
/**
|
|
31
41
|
* Whether a file the config includes declares types every file sees: a
|
|
@@ -36,6 +46,30 @@ import * as path from 'node:path';
|
|
|
36
46
|
*/
|
|
37
47
|
function isAmbient(ts, file) {
|
|
38
48
|
if (/\.d\.[cm]?ts$/.test(file)) return true;
|
|
49
|
+
// A kept answer still counts as reading the file, so an operation that
|
|
50
|
+
// keeps its own result while what it read is unchanged sees a change to it.
|
|
51
|
+
recordContentRead(file);
|
|
52
|
+
const stamp = fileStamp(file);
|
|
53
|
+
if (stamp === '-') return false;
|
|
54
|
+
let known = ambientByFile.get(ts);
|
|
55
|
+
if (known == null) {
|
|
56
|
+
known = new Map();
|
|
57
|
+
ambientByFile.set(ts, known);
|
|
58
|
+
}
|
|
59
|
+
const key = path.resolve(file);
|
|
60
|
+
const seen = known.get(key);
|
|
61
|
+
if (seen && seen.stamp === stamp) return seen.ambient;
|
|
62
|
+
const ambient = readAmbient(ts, file);
|
|
63
|
+
known.set(key, {stamp, ambient});
|
|
64
|
+
return ambient;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* `isAmbient` for a file that is not a declaration file, read afresh.
|
|
69
|
+
* @param {any} ts
|
|
70
|
+
* @param {string} file
|
|
71
|
+
*/
|
|
72
|
+
function readAmbient(ts, file) {
|
|
39
73
|
let text;
|
|
40
74
|
try {
|
|
41
75
|
text = fs.readFileSync(file, 'utf8');
|
|
@@ -56,12 +56,63 @@ export function stripTemplateAssetRefs(source: string): string;
|
|
|
56
56
|
* third-party URL left as written. That count is what a receipt discloses.
|
|
57
57
|
*
|
|
58
58
|
* @param {string} source - Template source code.
|
|
59
|
+
* @param {{videoPlaceholder?: string}} [options] - `videoPlaceholder` replaces
|
|
60
|
+
* each video reference; the default is an empty source.
|
|
59
61
|
* @returns {{source: string, demoMediaReplaced: number}}
|
|
60
62
|
*/
|
|
61
|
-
export function replaceDemoMedia(source: string
|
|
63
|
+
export function replaceDemoMedia(source: string, { videoPlaceholder }?: {
|
|
64
|
+
videoPlaceholder?: string;
|
|
65
|
+
}): {
|
|
62
66
|
source: string;
|
|
63
67
|
demoMediaReplaced: number;
|
|
64
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Replace each JSX element imported from {@link DEMO_CONTENT_MODULE} with a
|
|
71
|
+
* generic `<Text>` placeholder and remove that import, so emitted source never
|
|
72
|
+
* depends on content only Astryx's previews provide.
|
|
73
|
+
*
|
|
74
|
+
* Every check resolves a name to its binding through the module's scope, so a
|
|
75
|
+
* local declaration or parameter with the same name never counts as the same
|
|
76
|
+
* variable. The placeholder uses an existing Text import from Astryx when that
|
|
77
|
+
* import is the binding its name resolves to at every replaced element. Else
|
|
78
|
+
* the placeholder imports Text, under a unique alias when the file already
|
|
79
|
+
* writes the name `Text`.
|
|
80
|
+
*
|
|
81
|
+
* Only a plain static use is replaced: a named import used only as a JSX tag
|
|
82
|
+
* whose children, if any, are whitespace, and whose props are literal values or
|
|
83
|
+
* read only bindings that code outside the replaced elements still reads. So
|
|
84
|
+
* `faceDown={!isOpen}` is safe when the same `isOpen` is also read elsewhere.
|
|
85
|
+
* Anything else (a namespace or type import, a re-export, a dynamic import, the
|
|
86
|
+
* element used as a value or a type, a spread or computed prop, a prop whose
|
|
87
|
+
* binding nothing else reads, children) throws, naming the element, rather than
|
|
88
|
+
* leaving a reference behind, leaving a binding unused, or dropping code the
|
|
89
|
+
* rest of the file relies on. Source that never names the module is returned
|
|
90
|
+
* as is.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} source - Template source code.
|
|
93
|
+
* @returns {{source: string, demoContentReplaced: number}}
|
|
94
|
+
*/
|
|
95
|
+
export function replaceDemoContent(source: string): {
|
|
96
|
+
source: string;
|
|
97
|
+
demoContentReplaced: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Replace everything in a template that only Astryx's previews provide, in
|
|
101
|
+
* the order a copy applies it: demo-content elements
|
|
102
|
+
* ({@link replaceDemoContent}), then demo media ({@link replaceDemoMedia}).
|
|
103
|
+
* Both counts are what a receipt discloses.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} source - Template source code.
|
|
106
|
+
* @param {{videoPlaceholder?: string}} [options] - As {@link replaceDemoMedia}.
|
|
107
|
+
* @returns {{source: string, demoContentReplaced: number, demoMediaReplaced: number}}
|
|
108
|
+
*/
|
|
109
|
+
export function replaceTemplateDemos(source: string, options?: {
|
|
110
|
+
videoPlaceholder?: string;
|
|
111
|
+
}): {
|
|
112
|
+
source: string;
|
|
113
|
+
demoContentReplaced: number;
|
|
114
|
+
demoMediaReplaced: number;
|
|
115
|
+
};
|
|
65
116
|
/**
|
|
66
117
|
* List the core page-template directory names (sorted). The `template --list`
|
|
67
118
|
* view discovers far more; this is the minimal core-page set `init` scaffolds
|
|
@@ -171,10 +222,34 @@ export function findShowcase(componentName: string, cwd?: string, options?: {
|
|
|
171
222
|
docPath: string;
|
|
172
223
|
} | null>;
|
|
173
224
|
/**
|
|
225
|
+
* The components a template file composes, as written in the catalog.
|
|
174
226
|
* @param {string} pagePath
|
|
175
227
|
* @returns {string[]}
|
|
176
228
|
*/
|
|
177
229
|
export function extractComponents(pagePath: string): string[];
|
|
230
|
+
/**
|
|
231
|
+
* The components a template source composes. A surface that returns rewritten
|
|
232
|
+
* source lists the components of that source, so a component the rewrite
|
|
233
|
+
* removed is not listed.
|
|
234
|
+
* @param {string} src
|
|
235
|
+
* @returns {string[]}
|
|
236
|
+
*/
|
|
237
|
+
export function componentsInSource(src: string): string[];
|
|
238
|
+
/**
|
|
239
|
+
* A video placeholder that names itself in the source, for a copy that has no
|
|
240
|
+
* response to disclose the replacement in, such as the shadcn install. It is a
|
|
241
|
+
* text data URL: it makes no request, it does not play, and it is not image
|
|
242
|
+
* data, so a video element never receives image bytes.
|
|
243
|
+
*/
|
|
244
|
+
export const MARKED_VIDEO_PLACEHOLDER: "data:,placeholder-video-add-your-own";
|
|
245
|
+
/**
|
|
246
|
+
* The one module docs-only demo content is imported from. A template imports
|
|
247
|
+
* an element such as a playing card's face from here so its live preview shows
|
|
248
|
+
* real-looking content; the module exists only where Astryx's own previews
|
|
249
|
+
* build templates, so a copy replaces every element imported from it (see
|
|
250
|
+
* {@link replaceDemoContent}).
|
|
251
|
+
*/
|
|
252
|
+
export const DEMO_CONTENT_MODULE: "@astryx-docs/demo-content";
|
|
178
253
|
/**
|
|
179
254
|
* A discovered template (page or block), normalized across core, external, and
|
|
180
255
|
* integration sources. Not every source populates every field, so
|