@astryxdesign/cli 0.7.0-canary.2e0dbb5 → 0.7.0-canary.3045eda
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/doctor/doctor.d.mts +30 -2
- package/api/doctor/doctor.doc.mjs +2 -1
- package/api/doctor/doctor.mjs +153 -3
- package/api/doctor/doctor.test.mjs +250 -4
- package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
- package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs +178 -0
- package/assets/codemods/transforms/next/__tests__/rename-empty-search-results-text.test.mjs +202 -0
- package/assets/codemods/transforms/next/index.mjs +24 -0
- package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
- package/assets/codemods/transforms/next/preserve-bottom-sheet-content-padding.mjs +242 -0
- package/assets/codemods/transforms/next/rename-empty-search-results-text.mjs +254 -0
- package/assets/docs/spacing.doc.mjs +2 -2
- package/assets/docs/tree/tokens-spacing.doc.mjs +15 -15
- package/assets/templates/blocks/components/BottomSheet/BottomSheetHeights.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetMobileKeyboard.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetNoScrim.tsx +1 -1
- package/assets/templates/blocks/components/BottomSheet/BottomSheetSnapPoints.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
- package/assets/templates/blocks/components/Dialog/DialogAdaptivePresentation.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
- package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
- package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
- package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
- package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
- package/assets/templates/pages/canvas-editor/page.tsx +1 -1
- package/assets/templates/pages/table-filter/page.tsx +11 -6
- package/assets/templates/pages/table-inbox/page.tsx +3 -1
- package/assets/templates/themes/butter/butterTheme.ts +12 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +12 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +14 -14
- package/assets/templates/themes/neutral/neutralTheme.ts +12 -0
- package/assets/templates/themes/stone/stoneTheme.ts +12 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +10 -10
- package/assets/theme.template.ts +1 -1
- package/clients/cli/commands/doctor.doc.mjs +1 -1
- package/clients/cli/commands/doctor.test.mjs +33 -0
- package/package.json +9 -9
package/assets/codemods/transforms/next/__tests__/preserve-bottom-sheet-content-padding.test.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../preserve-bottom-sheet-content-padding.mjs';
|
|
5
|
+
|
|
6
|
+
async function applyTransform(source) {
|
|
7
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
8
|
+
const j = jscodeshift.withParser('tsx');
|
|
9
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
10
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('preserve-bottom-sheet-content-padding', () => {
|
|
14
|
+
it('adds padding={0} to a sheet with self-padded content', async () => {
|
|
15
|
+
const output =
|
|
16
|
+
await applyTransform(`import {BottomSheet, VStack} from '@astryxdesign/core';
|
|
17
|
+
const a = (
|
|
18
|
+
<BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters">
|
|
19
|
+
<VStack gap={4} padding={4}>x</VStack>
|
|
20
|
+
</BottomSheet>
|
|
21
|
+
);`);
|
|
22
|
+
|
|
23
|
+
expect(output).toContain(
|
|
24
|
+
'<BottomSheet isOpen={isOpen} onOpenChange={setIsOpen} label="Filters" padding={0}>',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('leaves a sheet whose only child is a core Section unchanged', async () => {
|
|
29
|
+
const source = `import {BottomSheet, Section, VStack} from '@astryxdesign/core';
|
|
30
|
+
const a = (
|
|
31
|
+
<BottomSheet isOpen onOpenChange={() => {}} label="Filters">
|
|
32
|
+
{/* filters */}
|
|
33
|
+
<Section padding={4}>
|
|
34
|
+
<VStack gap={4}>x</VStack>
|
|
35
|
+
</Section>
|
|
36
|
+
</BottomSheet>
|
|
37
|
+
);`;
|
|
38
|
+
expect(await applyTransform(source)).toBe(source);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('leaves a sheet whose only child is a core Layout unchanged', async () => {
|
|
42
|
+
const source = `import {BottomSheet, Layout, LayoutContent} from '@astryxdesign/core';
|
|
43
|
+
const a = (
|
|
44
|
+
<BottomSheet isOpen onOpenChange={() => {}} label="Message">
|
|
45
|
+
<Layout content={<LayoutContent>x</LayoutContent>} />
|
|
46
|
+
</BottomSheet>
|
|
47
|
+
);`;
|
|
48
|
+
expect(await applyTransform(source)).toBe(source);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('flags every nested Layout with a TODO, with or without its own padding', async () => {
|
|
52
|
+
const output =
|
|
53
|
+
await applyTransform(`import {BottomSheet, Layout, VStack} from '@astryxdesign/core';
|
|
54
|
+
function A() {
|
|
55
|
+
return (
|
|
56
|
+
<BottomSheet sheetId="a" label="A">
|
|
57
|
+
<VStack>
|
|
58
|
+
<Layout content={x} />
|
|
59
|
+
</VStack>
|
|
60
|
+
</BottomSheet>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function B() {
|
|
64
|
+
return (
|
|
65
|
+
<BottomSheet sheetId="b" label="B">
|
|
66
|
+
<VStack>
|
|
67
|
+
<Layout padding={4} content={x} />
|
|
68
|
+
</VStack>
|
|
69
|
+
</BottomSheet>
|
|
70
|
+
);
|
|
71
|
+
}`);
|
|
72
|
+
|
|
73
|
+
expect(output).toContain('<BottomSheet sheetId="a" label="A" padding={0}>');
|
|
74
|
+
expect(output).toContain('<BottomSheet sheetId="b" label="B" padding={0}>');
|
|
75
|
+
expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(2);
|
|
76
|
+
expect(output.indexOf('TODO(astryx upgrade)')).toBeLessThan(
|
|
77
|
+
output.indexOf('sheetId="a"'),
|
|
78
|
+
);
|
|
79
|
+
expect(output.indexOf('TODO(astryx upgrade)')).toBeGreaterThan(
|
|
80
|
+
output.indexOf('function A'),
|
|
81
|
+
);
|
|
82
|
+
expect(output.lastIndexOf('TODO(astryx upgrade)')).toBeGreaterThan(
|
|
83
|
+
output.indexOf('function B'),
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('does not flag a Layout from another package or a shadowed Layout binding', async () => {
|
|
88
|
+
const output =
|
|
89
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
90
|
+
import {Layout} from './my-layout';
|
|
91
|
+
export function A() {
|
|
92
|
+
return <BottomSheet isOpen><Layout content={<p>b</p>} /></BottomSheet>;
|
|
93
|
+
}
|
|
94
|
+
`);
|
|
95
|
+
expect(output).toContain('padding={0}');
|
|
96
|
+
expect(output).not.toContain('TODO');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('leaves a BottomSheet that a parameter or local binding shadows alone', async () => {
|
|
100
|
+
const source = `import {BottomSheet} from '@astryxdesign/core';
|
|
101
|
+
export function Host({BottomSheet: Sheet}) {
|
|
102
|
+
return <Sheet isOpen><p>own inset</p></Sheet>;
|
|
103
|
+
}
|
|
104
|
+
export function Local() {
|
|
105
|
+
const BottomSheet = (props) => <div {...props} />;
|
|
106
|
+
return <BottomSheet isOpen><p>own inset</p></BottomSheet>;
|
|
107
|
+
}
|
|
108
|
+
`;
|
|
109
|
+
expect(await applyTransform(source)).toBe(source);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('is idempotent: a second run changes nothing', async () => {
|
|
113
|
+
const once =
|
|
114
|
+
await applyTransform(`import {BottomSheet, Layout, VStack} from '@astryxdesign/core';
|
|
115
|
+
export function A() {
|
|
116
|
+
return <BottomSheet isOpen><VStack><p>a</p></VStack></BottomSheet>;
|
|
117
|
+
}
|
|
118
|
+
export function B() {
|
|
119
|
+
return <BottomSheet isOpen><VStack><Layout content={<p>b</p>} /></VStack></BottomSheet>;
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
expect(await applyTransform(once)).toBe(once);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('pads a sheet when the Section has a sibling or is not from core', async () => {
|
|
126
|
+
const output =
|
|
127
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
128
|
+
import {Section} from './local';
|
|
129
|
+
import {Section as CoreSection} from '@astryxdesign/core';
|
|
130
|
+
const a = <BottomSheet sheetId="a" label="A"><Section>x</Section></BottomSheet>;
|
|
131
|
+
const b = (
|
|
132
|
+
<BottomSheet sheetId="b" label="B">
|
|
133
|
+
<CoreSection>x</CoreSection>
|
|
134
|
+
<p>after</p>
|
|
135
|
+
</BottomSheet>
|
|
136
|
+
);`);
|
|
137
|
+
|
|
138
|
+
expect(output).toContain('<BottomSheet sheetId="a" label="A" padding={0}>');
|
|
139
|
+
expect(output).toContain('<BottomSheet sheetId="b" label="B" padding={0}>');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('leaves a sheet that already sets padding unchanged', async () => {
|
|
143
|
+
const source = `import {BottomSheet} from '@astryxdesign/core';
|
|
144
|
+
const a = <BottomSheet sheetId="a" label="A" padding={2}>x</BottomSheet>;
|
|
145
|
+
const b = <BottomSheet sheetId="b" label="B" padding={value}>x</BottomSheet>;`;
|
|
146
|
+
expect(await applyTransform(source)).toBe(source);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('follows aliases, subpath default imports, and namespace imports', async () => {
|
|
150
|
+
const output =
|
|
151
|
+
await applyTransform(`import {BottomSheet as Sheet} from '@astryxdesign/core';
|
|
152
|
+
import Panel from '@astryxdesign/core/BottomSheet';
|
|
153
|
+
import * as Core from '@astryxdesign/core';
|
|
154
|
+
const a = <Sheet sheetId="a" label="A">x</Sheet>;
|
|
155
|
+
const b = <Panel sheetId="b" label="B">x</Panel>;
|
|
156
|
+
const c = <Core.BottomSheet sheetId="c" label="C">x</Core.BottomSheet>;`);
|
|
157
|
+
|
|
158
|
+
expect(output).toContain('<Sheet sheetId="a" label="A" padding={0}>');
|
|
159
|
+
expect(output).toContain('<Panel sheetId="b" label="B" padding={0}>');
|
|
160
|
+
expect(output).toContain(
|
|
161
|
+
'<Core.BottomSheet sheetId="c" label="C" padding={0}>',
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('puts padding={0} before a spread so a spread padding still wins', async () => {
|
|
166
|
+
const output =
|
|
167
|
+
await applyTransform(`import {BottomSheet} from '@astryxdesign/core';
|
|
168
|
+
const a = <BottomSheet label="A" {...args} />;`);
|
|
169
|
+
|
|
170
|
+
expect(output).toContain('<BottomSheet label="A" padding={0} {...args} />');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('ignores BottomSheet from other packages', async () => {
|
|
174
|
+
const source = `import {BottomSheet} from './prototype';
|
|
175
|
+
const a = <BottomSheet title="A">x</BottomSheet>;`;
|
|
176
|
+
expect(await applyTransform(source)).toBe(source);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {describe, expect, it} from 'vitest';
|
|
4
|
+
import transform from '../rename-empty-search-results-text.mjs';
|
|
5
|
+
import manifest from '../index.mjs';
|
|
6
|
+
|
|
7
|
+
async function applyTransform(source) {
|
|
8
|
+
const jscodeshift = (await import('jscodeshift')).default;
|
|
9
|
+
const j = jscodeshift.withParser('tsx');
|
|
10
|
+
const api = {jscodeshift: j, stats: () => {}, report: () => {}};
|
|
11
|
+
return transform({source, path: 'test.tsx'}, api) ?? source;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('rename-empty-search-results-text', () => {
|
|
15
|
+
it('is staged in the next-release manifest', () => {
|
|
16
|
+
expect(manifest.map(entry => entry.name)).toContain(
|
|
17
|
+
'rename-empty-search-results-text',
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('JSX props', () => {
|
|
22
|
+
it('renames the prop on Tokenizer, Typeahead, and BaseTypeahead', async () => {
|
|
23
|
+
const output =
|
|
24
|
+
await applyTransform(`import {BaseTypeahead, Tokenizer, Typeahead} from '@astryxdesign/core';
|
|
25
|
+
const a = <Tokenizer label="People" emptySearchResultsText="Nobody found" />;
|
|
26
|
+
const b = <Typeahead label="Fruit" emptySearchResultsText={copy.empty} />;
|
|
27
|
+
const c = <BaseTypeahead emptySearchResultsText={'None'} />;`);
|
|
28
|
+
|
|
29
|
+
expect(output).toContain(
|
|
30
|
+
'<Tokenizer label="People" emptySearchText="Nobody found" />',
|
|
31
|
+
);
|
|
32
|
+
expect(output).toContain(
|
|
33
|
+
'<Typeahead label="Fruit" emptySearchText={copy.empty} />',
|
|
34
|
+
);
|
|
35
|
+
expect(output).toContain("<BaseTypeahead emptySearchText={'None'} />");
|
|
36
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('follows aliases, namespaces, and subpath default imports', async () => {
|
|
40
|
+
const output =
|
|
41
|
+
await applyTransform(`import {Tokenizer as People} from '@astryxdesign/core';
|
|
42
|
+
import * as Astryx from '@astryxdesign/core';
|
|
43
|
+
import Typeahead from '@astryxdesign/core/Typeahead';
|
|
44
|
+
const a = <People emptySearchResultsText="x" />;
|
|
45
|
+
const b = <Astryx.BaseTypeahead emptySearchResultsText="y" />;
|
|
46
|
+
const c = <Typeahead emptySearchResultsText="z" />;`);
|
|
47
|
+
|
|
48
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
49
|
+
expect(output.match(/emptySearchText=/g)).toHaveLength(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('renames the value as written, whatever shape it has', async () => {
|
|
53
|
+
const output =
|
|
54
|
+
await applyTransform(`import {Tokenizer} from '@astryxdesign/core';
|
|
55
|
+
const a = <Tokenizer emptySearchResultsText={compact ? 'None' : 'No matches'} />;
|
|
56
|
+
const b = <Tokenizer emptySearchResultsText={props.text ?? null} />;
|
|
57
|
+
const c = <Tokenizer {...props} emptySearchResultsText="After a spread" />;`);
|
|
58
|
+
|
|
59
|
+
expect(output).toContain(
|
|
60
|
+
"emptySearchText={compact ? 'None' : 'No matches'}",
|
|
61
|
+
);
|
|
62
|
+
expect(output).toContain('emptySearchText={props.text ?? null}');
|
|
63
|
+
// A spread may carry either name, so the element gets a TODO instead.
|
|
64
|
+
expect(output).toContain('{...props} /* TODO(astryx upgrade)');
|
|
65
|
+
expect(output).toContain('emptySearchResultsText="After a spread"');
|
|
66
|
+
expect(output).toContain('spreads props that may carry either name');
|
|
67
|
+
expect(output.match(/emptySearchResultsText/g)).toHaveLength(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('leaves a TODO instead of choosing when emptySearchText is already set', async () => {
|
|
71
|
+
const output =
|
|
72
|
+
await applyTransform(`import {Typeahead} from '@astryxdesign/core';
|
|
73
|
+
const a = <Typeahead emptySearchResultsText="Old copy" emptySearchText="New copy" />;`);
|
|
74
|
+
|
|
75
|
+
expect(output).toContain('TODO(astryx upgrade)');
|
|
76
|
+
expect(output).toContain('emptySearchResultsText="Old copy"');
|
|
77
|
+
expect(output).toContain('emptySearchText="New copy"');
|
|
78
|
+
expect(await applyTransform(output)).toBe(output);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('leaves other packages, other components, and shadowed names alone', async () => {
|
|
82
|
+
const source = `import {MobileTokenizer} from '@astryxdesign/lab';
|
|
83
|
+
import {Selector} from '@astryxdesign/core';
|
|
84
|
+
import {Tokenizer} from './my-tokenizer';
|
|
85
|
+
const a = <MobileTokenizer emptySearchResultsText="kept" />;
|
|
86
|
+
const b = <Selector emptySearchResultsText="kept" />;
|
|
87
|
+
const c = <Tokenizer emptySearchResultsText="kept" />;`;
|
|
88
|
+
expect(await applyTransform(source)).toBe(source);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('is idempotent', async () => {
|
|
92
|
+
const once =
|
|
93
|
+
await applyTransform(`import {Tokenizer} from '@astryxdesign/core';
|
|
94
|
+
const a = <Tokenizer emptySearchResultsText="Nobody found" />;`);
|
|
95
|
+
expect(await applyTransform(once)).toBe(once);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('ChatComposerInput trigger objects', () => {
|
|
100
|
+
it('renames the key on triggers written inline, in an array or alone', async () => {
|
|
101
|
+
const output =
|
|
102
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
103
|
+
const a = (
|
|
104
|
+
<ChatComposerInput
|
|
105
|
+
triggers={[
|
|
106
|
+
{char: '@', searchSource, onSelect, emptySearchResultsText: 'Nobody found'},
|
|
107
|
+
{char: '#', emptySearchResultsText: 'No tags'} as ChatComposerTrigger,
|
|
108
|
+
]}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
const b = <ChatComposerInput triggers={{char: '/', emptySearchResultsText: 'No commands'}} />;`);
|
|
112
|
+
|
|
113
|
+
expect(output).toContain("emptySearchText: 'Nobody found'");
|
|
114
|
+
expect(output).toContain("emptySearchText: 'No tags'");
|
|
115
|
+
expect(output).toContain("emptySearchText: 'No commands'");
|
|
116
|
+
expect(output).not.toContain('emptySearchResultsText');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('leaves a TODO on a trigger with a spread or computed key, or one that already sets the new name', async () => {
|
|
120
|
+
const output =
|
|
121
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
122
|
+
const a = (
|
|
123
|
+
<ChatComposerInput
|
|
124
|
+
triggers={[
|
|
125
|
+
{...base, emptySearchResultsText: 'Nobody'},
|
|
126
|
+
{[key]: 1, emptySearchResultsText: 'Nobody'},
|
|
127
|
+
{char: '@', emptySearchText: 'New', emptySearchResultsText: 'Old'},
|
|
128
|
+
]}
|
|
129
|
+
/>
|
|
130
|
+
);`);
|
|
131
|
+
|
|
132
|
+
expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(3);
|
|
133
|
+
expect(output.match(/emptySearchResultsText:/g)).toHaveLength(3);
|
|
134
|
+
expect(await applyTransform(output)).toBe(output);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('leaves a TODO on triggers it cannot read instead of following them', async () => {
|
|
138
|
+
const output =
|
|
139
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
140
|
+
import {mentionTrigger} from './triggers';
|
|
141
|
+
const local = {char: '@', emptySearchResultsText: 'Nobody'};
|
|
142
|
+
const a = <ChatComposerInput triggers={[local, mentionTrigger]} />;
|
|
143
|
+
const b = <ChatComposerInput triggers={buildTriggers()} />;
|
|
144
|
+
const c = <ChatComposerInput triggers={useMemo(() => [t], [t])} />;
|
|
145
|
+
const d = <ChatComposerInput {...props} triggers={[{char: '#', emptySearchResultsText: 'No tags'}]} />;`);
|
|
146
|
+
|
|
147
|
+
expect(output.match(/These triggers are built elsewhere/g)).toHaveLength(
|
|
148
|
+
4,
|
|
149
|
+
);
|
|
150
|
+
// The inline object beside a spread is still renamed; the spread is flagged.
|
|
151
|
+
expect(output).toContain("emptySearchText: 'No tags'");
|
|
152
|
+
expect(output).toContain("emptySearchResultsText: 'Nobody'");
|
|
153
|
+
expect(await applyTransform(output)).toBe(output);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('marks every spread onto these elements, even when the element writes neither name', async () => {
|
|
157
|
+
const output =
|
|
158
|
+
await applyTransform(`import {Tokenizer, Typeahead, ChatComposerInput} from '@astryxdesign/core';
|
|
159
|
+
import {Selector} from '@astryxdesign/core';
|
|
160
|
+
const people = {emptySearchResultsText: 'No people match'};
|
|
161
|
+
export function Wrappers(props) {
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
<Tokenizer {...people} />
|
|
165
|
+
<Typeahead {...{emptySearchResultsText: 'Inline'}} />
|
|
166
|
+
<Tokenizer {...props} label="x" />
|
|
167
|
+
<ChatComposerInput {...props} />
|
|
168
|
+
<Selector {...props} />
|
|
169
|
+
<Tokenizer {...props} emptySearchText="already new" />
|
|
170
|
+
</>
|
|
171
|
+
);
|
|
172
|
+
}`);
|
|
173
|
+
|
|
174
|
+
expect(
|
|
175
|
+
output.match(/spreads props that may carry either name/g),
|
|
176
|
+
).toHaveLength(4);
|
|
177
|
+
expect(output.match(/These triggers are built elsewhere/g)).toHaveLength(
|
|
178
|
+
1,
|
|
179
|
+
);
|
|
180
|
+
expect(output).toContain('<Selector {...props} />');
|
|
181
|
+
expect(await applyTransform(output)).toBe(output);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('marks an inline trigger object whose keys come only from a spread, once across runs', async () => {
|
|
185
|
+
const once =
|
|
186
|
+
await applyTransform(`import {ChatComposerInput} from '@astryxdesign/core';
|
|
187
|
+
const a = <ChatComposerInput triggers={[{...baseMention, onSelect}, {[key]: 1, onSelect}]} />;`);
|
|
188
|
+
|
|
189
|
+
expect(once.match(/has a spread or computed key/g)).toHaveLength(2);
|
|
190
|
+
const twice = await applyTransform(once);
|
|
191
|
+
expect(twice).toBe(once);
|
|
192
|
+
expect(twice.match(/TODO\(astryx upgrade\)/g)).toHaveLength(2);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('leaves a file with no runtime core import alone', async () => {
|
|
196
|
+
const source = `import {MobileTokenizer} from '@astryxdesign/lab';
|
|
197
|
+
const copy = {emptySearchResultsText: 'kept'};
|
|
198
|
+
const a = <MobileTokenizer {...copy} />;`;
|
|
199
|
+
expect(await applyTransform(source)).toBe(source);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
import migrateDeprecatedThemeSurface, {
|
|
11
11
|
meta as migrateDeprecatedThemeSurfaceMeta,
|
|
12
12
|
} from './migrate-deprecated-theme-surface.mjs';
|
|
13
|
+
import migrateFieldInputStyling, {
|
|
14
|
+
meta as migrateFieldInputStylingMeta,
|
|
15
|
+
} from './migrate-field-input-styling.mjs';
|
|
16
|
+
import preserveBottomSheetContentPadding, {
|
|
17
|
+
meta as preserveBottomSheetContentPaddingMeta,
|
|
18
|
+
} from './preserve-bottom-sheet-content-padding.mjs';
|
|
19
|
+
import renameEmptySearchResultsText, {
|
|
20
|
+
meta as renameEmptySearchResultsTextMeta,
|
|
21
|
+
} from './rename-empty-search-results-text.mjs';
|
|
13
22
|
import validateDataTokenOwnership, {
|
|
14
23
|
meta as validateDataTokenOwnershipMeta,
|
|
15
24
|
} from './validate-data-token-ownership.mjs';
|
|
@@ -25,4 +34,19 @@ export default [
|
|
|
25
34
|
transform: validateDataTokenOwnership,
|
|
26
35
|
meta: validateDataTokenOwnershipMeta,
|
|
27
36
|
},
|
|
37
|
+
{
|
|
38
|
+
name: 'migrate-field-input-styling',
|
|
39
|
+
transform: migrateFieldInputStyling,
|
|
40
|
+
meta: migrateFieldInputStylingMeta,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'preserve-bottom-sheet-content-padding',
|
|
44
|
+
transform: preserveBottomSheetContentPadding,
|
|
45
|
+
meta: preserveBottomSheetContentPaddingMeta,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'rename-empty-search-results-text',
|
|
49
|
+
transform: renameEmptySearchResultsText,
|
|
50
|
+
meta: renameEmptySearchResultsTextMeta,
|
|
51
|
+
},
|
|
28
52
|
];
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Migrate root styling on Field-composed inputs to their named parts.
|
|
5
|
+
*
|
|
6
|
+
* Field-composed inputs no longer accept root `xstyle`, `className`, or
|
|
7
|
+
* `style` (family:input-fields FR10). Each rename keeps the element the
|
|
8
|
+
* styling reached before: components whose root styling painted the visual
|
|
9
|
+
* control box move to `controlXstyle`/`controlClassName`/`controlStyle`;
|
|
10
|
+
* components whose root styling reached the Field box move to
|
|
11
|
+
* `containerXstyle`/`containerClassName`/`containerStyle`.
|
|
12
|
+
*
|
|
13
|
+
* Only JSX attributes written directly on an element bound to an Astryx import
|
|
14
|
+
* are renamed (named, aliased, or namespace imports). Spread attributes,
|
|
15
|
+
* wrappers that forward their own props, and unrelated components of the same
|
|
16
|
+
* name are left alone; those callsites fail type-checking and are migrated by
|
|
17
|
+
* hand. When the target attribute is already present, the root attribute gets a
|
|
18
|
+
* TODO instead of a rename so no value is silently dropped.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {transformProp} from '../../transform-prop.mjs';
|
|
22
|
+
|
|
23
|
+
export const meta = {
|
|
24
|
+
title: 'Migrate input root styling to container/control parts',
|
|
25
|
+
description:
|
|
26
|
+
'Renames root `xstyle`/`className`/`style` on Field-composed inputs to the `control*` or `container*` part they styled before.',
|
|
27
|
+
fileExtensions: ['.tsx', '.jsx', '.ts', '.js', '.mjs', '.cjs'],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** Components whose root styling painted the visual control box. */
|
|
31
|
+
const CONTROL_COMPONENTS = [
|
|
32
|
+
'TextInput',
|
|
33
|
+
'TextArea',
|
|
34
|
+
'NumberInput',
|
|
35
|
+
'FileInput',
|
|
36
|
+
'DateInput',
|
|
37
|
+
'DateRangeInput',
|
|
38
|
+
'DateTimeInput',
|
|
39
|
+
'TimeInput',
|
|
40
|
+
'Selector',
|
|
41
|
+
'MultiSelector',
|
|
42
|
+
'ComplexSelector',
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** Components whose root styling reached the Field box. */
|
|
46
|
+
const CONTAINER_COMPONENTS = [
|
|
47
|
+
'Typeahead',
|
|
48
|
+
'Tokenizer',
|
|
49
|
+
'CheckboxList',
|
|
50
|
+
'RadioList',
|
|
51
|
+
'Slider',
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Field-root members that also render inside InputGroup. There Field is absent
|
|
56
|
+
* and root styling painted the control surface, so it moves to `control*`.
|
|
57
|
+
*/
|
|
58
|
+
const GROUPED_CONTROL_COMPONENTS = new Set(['Typeahead']);
|
|
59
|
+
|
|
60
|
+
/** @type {ReadonlyMap<string, 'control' | 'container'>} */
|
|
61
|
+
const PART_BY_COMPONENT = new Map([
|
|
62
|
+
...CONTROL_COMPONENTS.map(name => /** @type {const} */ ([name, 'control'])),
|
|
63
|
+
...CONTAINER_COMPONENTS.map(
|
|
64
|
+
name => /** @type {const} */ ([name, 'container']),
|
|
65
|
+
),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const ROOT_STYLE_PROPS = /** @type {const} */ ({
|
|
69
|
+
xstyle: 'Xstyle',
|
|
70
|
+
className: 'ClassName',
|
|
71
|
+
style: 'Style',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const PACKAGE_PATTERN = /^@(astryxdesign|xds)\/core(\/[A-Za-z]+)?$/u;
|
|
75
|
+
|
|
76
|
+
const TODO =
|
|
77
|
+
' TODO(astryx upgrade): root styling is no longer accepted here; merge it into ';
|
|
78
|
+
|
|
79
|
+
/** @type {ReadonlyMap<string, ReadonlySet<string>>} */
|
|
80
|
+
const COMPONENT_PROPS = new Map(
|
|
81
|
+
[...PART_BY_COMPONENT.keys()].map(name => [
|
|
82
|
+
name,
|
|
83
|
+
new Set(Object.keys(ROOT_STYLE_PROPS)),
|
|
84
|
+
]),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {import('../../../../authoring/codemod/type').AstryxCodemodFile} file
|
|
89
|
+
* @param {import('../../../../authoring/codemod/type').CodemodTransformApi} api
|
|
90
|
+
* @returns {string | undefined}
|
|
91
|
+
*/
|
|
92
|
+
export default function migrateFieldInputStyling(file, api) {
|
|
93
|
+
if (!/xstyle|className|style/u.test(file.source)) return undefined;
|
|
94
|
+
if (![...PART_BY_COMPONENT.keys()].some(name => file.source.includes(name))) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const j = api.jscodeshift;
|
|
99
|
+
const root = j(file.source);
|
|
100
|
+
const matchesImport = (/** @type {string} */ source) =>
|
|
101
|
+
PACKAGE_PATTERN.test(source);
|
|
102
|
+
|
|
103
|
+
// Local names that resolve to an Astryx InputGroup (named or namespace).
|
|
104
|
+
/** @type {Set<string>} */
|
|
105
|
+
const inputGroupNames = new Set();
|
|
106
|
+
/** @type {Set<string>} */
|
|
107
|
+
const namespaceNames = new Set();
|
|
108
|
+
root.find(j.ImportDeclaration).forEach((/** @type {any} */ path) => {
|
|
109
|
+
const source = path.node.source.value;
|
|
110
|
+
if (path.node.importKind === 'type') return;
|
|
111
|
+
if (typeof source !== 'string' || !matchesImport(source)) return;
|
|
112
|
+
for (const specifier of path.node.specifiers ?? []) {
|
|
113
|
+
if (specifier.importKind === 'type') continue;
|
|
114
|
+
if (
|
|
115
|
+
specifier.type === 'ImportSpecifier' &&
|
|
116
|
+
specifier.imported?.name === 'InputGroup'
|
|
117
|
+
) {
|
|
118
|
+
inputGroupNames.add(specifier.local?.name ?? 'InputGroup');
|
|
119
|
+
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
120
|
+
namespaceNames.add(specifier.local.name);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
/** @param {any} elementPath a JSXElement path */
|
|
126
|
+
const isInputGroup = elementPath => {
|
|
127
|
+
const name = elementPath.node.openingElement.name;
|
|
128
|
+
let localName;
|
|
129
|
+
if (name.type === 'JSXIdentifier' && inputGroupNames.has(name.name)) {
|
|
130
|
+
localName = name.name;
|
|
131
|
+
} else if (
|
|
132
|
+
name.type === 'JSXMemberExpression' &&
|
|
133
|
+
name.object?.type === 'JSXIdentifier' &&
|
|
134
|
+
name.property?.type === 'JSXIdentifier' &&
|
|
135
|
+
name.property.name === 'InputGroup' &&
|
|
136
|
+
namespaceNames.has(name.object.name)
|
|
137
|
+
) {
|
|
138
|
+
localName = name.object.name;
|
|
139
|
+
} else {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
const scope = elementPath.scope?.lookup(localName);
|
|
143
|
+
return scope?.path.node.type === 'Program';
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
/** @param {any} openingPath a JSXOpeningElement path */
|
|
147
|
+
const isInsideInputGroup = openingPath => {
|
|
148
|
+
for (let p = openingPath.parent?.parent; p; p = p.parent) {
|
|
149
|
+
if (p.node.type === 'JSXElement' && isInputGroup(p)) return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
let changed = false;
|
|
155
|
+
transformProp(
|
|
156
|
+
root,
|
|
157
|
+
j,
|
|
158
|
+
{matchesImport, components: COMPONENT_PROPS},
|
|
159
|
+
(propPath, {component}) => {
|
|
160
|
+
const attribute = propPath.node;
|
|
161
|
+
const openingPath = propPath.parent;
|
|
162
|
+
let part = PART_BY_COMPONENT.get(component);
|
|
163
|
+
if (!part) return;
|
|
164
|
+
if (
|
|
165
|
+
part === 'container' &&
|
|
166
|
+
GROUPED_CONTROL_COMPONENTS.has(component) &&
|
|
167
|
+
isInsideInputGroup(openingPath)
|
|
168
|
+
) {
|
|
169
|
+
part = 'control';
|
|
170
|
+
}
|
|
171
|
+
const name = /** @type {keyof typeof ROOT_STYLE_PROPS} */ (
|
|
172
|
+
attribute.name.name
|
|
173
|
+
);
|
|
174
|
+
const next = part + ROOT_STYLE_PROPS[name];
|
|
175
|
+
const present = (openingPath.node.attributes ?? []).some(
|
|
176
|
+
(/** @type {any} */ a) =>
|
|
177
|
+
a.type === 'JSXAttribute' && a.name?.name === next,
|
|
178
|
+
);
|
|
179
|
+
if (present) {
|
|
180
|
+
const comment = `${TODO}\`${next}\`. `;
|
|
181
|
+
attribute.comments ??= [];
|
|
182
|
+
if (
|
|
183
|
+
!attribute.comments.some(
|
|
184
|
+
(/** @type {any} */ c) => c.value === comment,
|
|
185
|
+
)
|
|
186
|
+
) {
|
|
187
|
+
attribute.comments.push(j.commentBlock(comment, true, false));
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
attribute.name = j.jsxIdentifier(next);
|
|
193
|
+
changed = true;
|
|
194
|
+
},
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
return changed ? root.toSource({quote: 'single'}) : undefined;
|
|
198
|
+
}
|