@hirobius/design-system 0.17.0 → 0.19.0
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/CONSUMING.md +150 -0
- package/DESIGN.md +220 -0
- package/README.md +30 -2
- package/codemods/patterns-subpath.mjs +254 -0
- package/codemods/patterns-subpath.names.json +26 -0
- package/dist/chunks/{activity-feed-C8_e-Btq.js → activity-feed-DIMeUJpW.js} +4907 -2912
- package/dist/chunks/{form-DnGRy27o.js → form-BvNNnJ0t.js} +2 -2
- package/dist/form.js +5 -5
- package/dist/hirobius-ui.js +1986 -2529
- package/dist/icons.js +53 -0
- package/dist/manifest.js +15 -14
- package/dist/patterns.js +292 -101
- package/dist/static.css +3 -3
- package/dist/styles.css +1 -1
- package/dist/tokens.css +1 -1
- package/dist/types/src/app/components/alert-dialog.d.ts +9 -1
- package/dist/types/src/app/components/alert.d.ts +4 -0
- package/dist/types/src/app/components/avatar.d.ts +4 -0
- package/dist/types/src/app/components/badge.d.ts +4 -0
- package/dist/types/src/app/components/box.d.ts +5 -0
- package/dist/types/src/app/components/breadcrumb.d.ts +4 -0
- package/dist/types/src/app/components/button-group.d.ts +4 -0
- package/dist/types/src/app/components/button.d.ts +3 -0
- package/dist/types/src/app/components/card.d.ts +9 -0
- package/dist/types/src/app/components/checkbox.d.ts +4 -0
- package/dist/types/src/app/components/combobox.d.ts +10 -0
- package/dist/types/src/app/components/command-palette.d.ts +3 -1
- package/dist/types/src/app/components/container.d.ts +5 -0
- package/dist/types/src/app/components/context-menu.d.ts +25 -2
- package/dist/types/src/app/components/data-table-section.d.ts +45 -0
- package/dist/types/src/app/components/destructive-section.d.ts +32 -0
- package/dist/types/src/app/components/dialog.d.ts +20 -2
- package/dist/types/src/app/components/disclosure.d.ts +3 -0
- package/dist/types/src/app/components/divider.d.ts +4 -0
- package/dist/types/src/app/components/empty-state.d.ts +4 -0
- package/dist/types/src/app/components/field.d.ts +4 -0
- package/dist/types/src/app/components/form-actions.d.ts +26 -0
- package/dist/types/src/app/components/grid.d.ts +4 -0
- package/dist/types/src/app/components/hds-tooltip.d.ts +14 -2
- package/dist/types/src/app/components/hover-card.d.ts +16 -1
- package/dist/types/src/app/components/icon.d.ts +4 -0
- package/dist/types/src/app/components/inline-link.d.ts +4 -0
- package/dist/types/src/app/components/input.d.ts +5 -0
- package/dist/types/src/app/components/kbd.d.ts +3 -0
- package/dist/types/src/app/components/menu.d.ts +26 -2
- package/dist/types/src/app/components/metric-tiles.d.ts +40 -0
- package/dist/types/src/app/components/page-header.d.ts +34 -0
- package/dist/types/src/app/components/pagination.d.ts +3 -0
- package/dist/types/src/app/components/popover.d.ts +14 -2
- package/dist/types/src/app/components/progress.d.ts +4 -0
- package/dist/types/src/app/components/radio.d.ts +5 -0
- package/dist/types/src/app/components/select.d.ts +16 -0
- package/dist/types/src/app/components/skeleton.d.ts +4 -0
- package/dist/types/src/app/components/slider.d.ts +3 -0
- package/dist/types/src/app/components/spinner.d.ts +4 -0
- package/dist/types/src/app/components/stack.d.ts +4 -0
- package/dist/types/src/app/components/stat.d.ts +4 -0
- package/dist/types/src/app/components/status-tile.d.ts +4 -0
- package/dist/types/src/app/components/table.d.ts +36 -4
- package/dist/types/src/app/components/tabs.d.ts +4 -0
- package/dist/types/src/app/components/tag.d.ts +3 -0
- package/dist/types/src/app/components/text.d.ts +4 -0
- package/dist/types/src/app/components/textarea.d.ts +3 -0
- package/dist/types/src/app/components/toast.d.ts +4 -0
- package/dist/types/src/app/components/toggle.d.ts +4 -0
- package/dist/types/src/app/components/tooltip.d.ts +1 -1
- package/dist/types/src/app/components/visually-hidden.d.ts +3 -0
- package/dist/types/src/app/context/hds-portal.d.ts +52 -0
- package/dist/types/src/app/context/hds-theme.d.ts +10 -0
- package/dist/types/src/app/data/manifest-types.d.ts +27 -0
- package/dist/types/src/app/design-system/generated-token-refs.d.ts +2 -0
- package/dist/types/src/icons.d.ts +13 -0
- package/dist/types/src/index.d.ts +20 -1
- package/dist/types/src/patterns.d.ts +5 -0
- package/dist/variables.css +4 -0
- package/docs/CONSUMING.md +758 -0
- package/hirobius.tokens.json +17 -0
- package/llms.txt +261 -0
- package/package.json +30 -6
- package/public/hds-manifest.json +1545 -89
- package/public/llms/components.txt +1090 -0
- package/public/llms/layout.txt +54 -0
- package/public/llms/scroll.txt +22 -0
- package/public/llms/tokens.txt +32 -0
- package/public/llms-full.txt +1561 -0
- package/public/llms.txt +261 -0
- package/src/app/data/component-api.json +6156 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* patterns-subpath codemod (hds#316, follows hds#254)
|
|
4
|
+
*
|
|
5
|
+
* Rewrites `import { Page } from '@hirobius/design-system'` to
|
|
6
|
+
* `import { Page } from '@hirobius/design-system/patterns'` for every
|
|
7
|
+
* pattern-tier component whose root re-export is deprecated. Other named
|
|
8
|
+
* imports stay on the root. Aliases, `type` modifiers and multi-line layout
|
|
9
|
+
* are preserved; an existing `/patterns` import of the same kind is extended
|
|
10
|
+
* instead of duplicated.
|
|
11
|
+
*
|
|
12
|
+
* node codemods/patterns-subpath.mjs [--root <dir>] [--check] [--dry-run]
|
|
13
|
+
*
|
|
14
|
+
* --root <dir> directory to scan (default: current directory)
|
|
15
|
+
* --check write nothing; exit 1 when a rewrite is needed or a root namespace
|
|
16
|
+
* import (`import * as X`, `export *`) needs a manual look
|
|
17
|
+
* --dry-run write nothing; print each import line before (-) and after (+), exit 0
|
|
18
|
+
*
|
|
19
|
+
* The name list is codemods/patterns-subpath.names.json, generated from
|
|
20
|
+
* src/index.ts by `pnpm codemod:names`.
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from 'node:fs';
|
|
23
|
+
import { dirname, join, relative, resolve } from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
const ROOT_PKG = '@hirobius/design-system';
|
|
27
|
+
const SUBPATH = `${ROOT_PKG}/patterns`;
|
|
28
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
29
|
+
const EXTS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs', '.mts', '.cts']);
|
|
30
|
+
const SKIP_DIRS = new Set([
|
|
31
|
+
'node_modules',
|
|
32
|
+
'dist',
|
|
33
|
+
'build',
|
|
34
|
+
'.git',
|
|
35
|
+
'.next',
|
|
36
|
+
'.vercel',
|
|
37
|
+
'coverage',
|
|
38
|
+
'storybook-static',
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export function loadPatternNames() {
|
|
42
|
+
const { names } = JSON.parse(readFileSync(join(HERE, 'patterns-subpath.names.json'), 'utf8'));
|
|
43
|
+
return new Set(names);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const esc = (pkg) => pkg.replace(/[/@]/g, '\\$&');
|
|
47
|
+
// indent, import|export, type?, default?, { body }, quote, semicolon
|
|
48
|
+
const namedRe = (pkg) =>
|
|
49
|
+
new RegExp(
|
|
50
|
+
`^([ \\t]*)(import|export)(\\s+type)?\\s*(?:([\\w$]+)\\s*,\\s*)?\\{([^}]*)\\}\\s*from\\s*(['"])${esc(pkg)}\\6(;?)`,
|
|
51
|
+
'gm',
|
|
52
|
+
);
|
|
53
|
+
// `import * as X`, `import D, * as X`, `export * from`, `export * as X from` on the root
|
|
54
|
+
const namespaceRe = new RegExp(
|
|
55
|
+
`^[ \\t]*(?:import\\s+(?:[\\w$]+\\s*,\\s*)?\\*\\s*as\\s+[\\w$]+|export\\s+\\*(?:\\s*as\\s+[\\w$]+)?)\\s*from\\s*['"]${esc(ROOT_PKG)}['"]`,
|
|
56
|
+
'gm',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const specName = (spec) =>
|
|
60
|
+
spec
|
|
61
|
+
.replace(/^type\s+/, '')
|
|
62
|
+
.split(/\s+as\s+/)[0]
|
|
63
|
+
.trim();
|
|
64
|
+
const splitSpecs = (body) =>
|
|
65
|
+
body
|
|
66
|
+
.split(',')
|
|
67
|
+
.map((s) => s.trim())
|
|
68
|
+
.filter(Boolean);
|
|
69
|
+
|
|
70
|
+
/** Namespace imports and star re-exports of the root: names are not visible, so no rewrite. */
|
|
71
|
+
export function findUnrewritable(source) {
|
|
72
|
+
return [...source.matchAll(namespaceRe)].map((m) => m[0].trim());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Renders one import/export statement. */
|
|
76
|
+
function render({ indent, kw, typeKw, def, list, pkg, multiline, quote, semi }) {
|
|
77
|
+
const head = `${indent}${kw}${typeKw ? ' type' : ''} `;
|
|
78
|
+
const tail = ` from ${quote}${pkg}${quote}${semi}`;
|
|
79
|
+
if (list.length === 0) return `${head}${def}${tail}`;
|
|
80
|
+
const d = def ? `${def}, ` : '';
|
|
81
|
+
if (multiline)
|
|
82
|
+
return `${head}${d}{\n${list.map((s) => `${indent} ${s},`).join('\n')}\n${indent}}${tail}`;
|
|
83
|
+
return `${head}${d}{ ${list.join(', ')} }${tail}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Pure transform of one file's source.
|
|
88
|
+
* @returns {{ source: string, changed: boolean, sites: number, moved: string[],
|
|
89
|
+
* edits: {before: string, after: string}[] }}
|
|
90
|
+
*/
|
|
91
|
+
export function transformSource(source, names) {
|
|
92
|
+
const moved = [];
|
|
93
|
+
const edits = [];
|
|
94
|
+
const isType = (m) => !!m[3];
|
|
95
|
+
const parse = (m) => ({
|
|
96
|
+
indent: m[1],
|
|
97
|
+
kw: m[2],
|
|
98
|
+
typeKw: m[3],
|
|
99
|
+
def: m[4],
|
|
100
|
+
body: m[5],
|
|
101
|
+
quote: m[6],
|
|
102
|
+
semi: m[7],
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// An existing `import { … } from '/patterns'` of each kind absorbs moved names.
|
|
106
|
+
const targets = {};
|
|
107
|
+
for (const m of source.matchAll(namedRe(SUBPATH))) {
|
|
108
|
+
if (m[2] !== 'import' || m[4]) continue;
|
|
109
|
+
targets[isType(m) ? 'type' : 'value'] ??= { m, add: [] };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const replacements = [];
|
|
113
|
+
for (const m of source.matchAll(namedRe(ROOT_PKG))) {
|
|
114
|
+
const p = parse(m);
|
|
115
|
+
const specs = splitSpecs(p.body);
|
|
116
|
+
const go = specs.filter((s) => names.has(specName(s)));
|
|
117
|
+
if (go.length === 0) continue;
|
|
118
|
+
moved.push(...go.map(specName));
|
|
119
|
+
const keep = specs.filter((s) => !go.includes(s));
|
|
120
|
+
const multiline = p.body.includes('\n');
|
|
121
|
+
const lines = [];
|
|
122
|
+
if (keep.length > 0 || p.def)
|
|
123
|
+
lines.push(render({ ...p, list: keep, pkg: ROOT_PKG, multiline }));
|
|
124
|
+
const target = p.kw === 'import' && targets[p.typeKw ? 'type' : 'value'];
|
|
125
|
+
if (target) target.add.push(...go);
|
|
126
|
+
else lines.push(render({ ...p, def: undefined, list: go, pkg: SUBPATH, multiline }));
|
|
127
|
+
replacements.push({ start: m.index, end: m.index + m[0].length, before: m[0], lines });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (replacements.length === 0) return { source, changed: false, sites: 0, moved: [], edits: [] };
|
|
131
|
+
|
|
132
|
+
const sites = replacements.length;
|
|
133
|
+
for (const { m, add } of Object.values(targets)) {
|
|
134
|
+
if (add.length === 0) continue;
|
|
135
|
+
const p = parse(m);
|
|
136
|
+
const have = splitSpecs(p.body);
|
|
137
|
+
const merged = [...have, ...add.filter((n) => !have.includes(n))];
|
|
138
|
+
replacements.push({
|
|
139
|
+
start: m.index,
|
|
140
|
+
end: m.index + m[0].length,
|
|
141
|
+
before: m[0],
|
|
142
|
+
lines: [
|
|
143
|
+
render({
|
|
144
|
+
...p,
|
|
145
|
+
def: undefined,
|
|
146
|
+
list: merged,
|
|
147
|
+
pkg: SUBPATH,
|
|
148
|
+
multiline: p.body.includes('\n'),
|
|
149
|
+
}),
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let out = source;
|
|
155
|
+
for (const r of replacements.sort((x, y) => y.start - x.start)) {
|
|
156
|
+
const after = r.lines.join('\n');
|
|
157
|
+
// A statement folded entirely into an existing import leaves nothing behind, not a blank line.
|
|
158
|
+
const end = after === '' && out[r.end] === '\n' ? r.end + 1 : r.end;
|
|
159
|
+
out = out.slice(0, r.start) + after + out.slice(end);
|
|
160
|
+
edits.unshift({ before: r.before, after });
|
|
161
|
+
}
|
|
162
|
+
return { source: out, changed: out !== source, sites, moved, edits };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function* walk(dir) {
|
|
166
|
+
for (const entry of readdirSync(dir)) {
|
|
167
|
+
if (SKIP_DIRS.has(entry)) continue;
|
|
168
|
+
const full = join(dir, entry);
|
|
169
|
+
const st = statSync(full);
|
|
170
|
+
if (st.isDirectory()) yield* walk(full);
|
|
171
|
+
else if (EXTS.has(full.slice(full.lastIndexOf('.')))) yield full;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Scan a directory. Writes only when `write` is true. */
|
|
176
|
+
export function runCodemod({ root, write = false, names = loadPatternNames() }) {
|
|
177
|
+
const files = [];
|
|
178
|
+
const manual = [];
|
|
179
|
+
const moved = new Set();
|
|
180
|
+
let sites = 0;
|
|
181
|
+
for (const file of walk(root)) {
|
|
182
|
+
const src = readFileSync(file, 'utf8');
|
|
183
|
+
if (!src.includes(ROOT_PKG)) continue;
|
|
184
|
+
for (const stmt of findUnrewritable(src)) manual.push({ file: relative(root, file), stmt });
|
|
185
|
+
const r = transformSource(src, names);
|
|
186
|
+
if (!r.changed) continue;
|
|
187
|
+
files.push({ file: relative(root, file), sites: r.sites, moved: r.moved, edits: r.edits });
|
|
188
|
+
r.moved.forEach((n) => moved.add(n));
|
|
189
|
+
sites += r.sites;
|
|
190
|
+
if (write) writeFileSync(file, r.source);
|
|
191
|
+
}
|
|
192
|
+
return { files, sites, manual, names: [...moved].sort() };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function main(argv) {
|
|
196
|
+
const args = { root: process.cwd(), check: false, dryRun: false };
|
|
197
|
+
for (let i = 0; i < argv.length; i++) {
|
|
198
|
+
if (argv[i] === '--root') args.root = resolve(argv[++i] ?? '');
|
|
199
|
+
else if (argv[i] === '--check') args.check = true;
|
|
200
|
+
else if (argv[i] === '--dry-run') args.dryRun = true;
|
|
201
|
+
else {
|
|
202
|
+
console.error(
|
|
203
|
+
`unknown argument: ${argv[i]}\nusage: patterns-subpath [--root <dir>] [--check] [--dry-run]`,
|
|
204
|
+
);
|
|
205
|
+
return 2;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const write = !args.check && !args.dryRun;
|
|
209
|
+
const res = runCodemod({ root: args.root, write });
|
|
210
|
+
const summary = `${res.files.length} files, ${res.sites} import sites, ${res.names.length} names (${res.names.join(', ') || 'none'})`;
|
|
211
|
+
const manualLines = res.manual.map(
|
|
212
|
+
(m) => ` ${m.file}: ${m.stmt} (namespace import: move pattern names to '${SUBPATH}' by hand)`,
|
|
213
|
+
);
|
|
214
|
+
if (args.check) {
|
|
215
|
+
if (res.sites > 0 || res.manual.length > 0) {
|
|
216
|
+
console.error(`patterns-subpath: rewrite needed: ${summary}`);
|
|
217
|
+
for (const f of res.files) console.error(` ${f.file}: ${f.moved.join(', ')}`);
|
|
218
|
+
for (const l of manualLines) console.error(l);
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
console.log('patterns-subpath: nothing to rewrite');
|
|
222
|
+
return 0;
|
|
223
|
+
}
|
|
224
|
+
console.log(`patterns-subpath: ${write ? 'rewrote' : 'would rewrite'} ${summary}`);
|
|
225
|
+
for (const f of res.files) {
|
|
226
|
+
console.log(` ${f.file}: ${f.moved.join(', ')}`);
|
|
227
|
+
if (args.dryRun)
|
|
228
|
+
for (const e of f.edits) {
|
|
229
|
+
for (const l of e.before.split('\n')) console.log(`- ${l}`);
|
|
230
|
+
for (const l of e.after.split('\n')) console.log(`+ ${l}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (res.manual.length > 0) {
|
|
234
|
+
console.warn('patterns-subpath: cannot rewrite these, do them by hand:');
|
|
235
|
+
for (const l of manualLines) console.warn(l);
|
|
236
|
+
}
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Compare real paths: npm/yarn link the bin and pnpm links the package directory, so
|
|
241
|
+
// argv[1] is a symlink while import.meta.url is already resolved.
|
|
242
|
+
const isEntry = (() => {
|
|
243
|
+
try {
|
|
244
|
+
return (
|
|
245
|
+
!!process.argv[1] &&
|
|
246
|
+
realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))
|
|
247
|
+
);
|
|
248
|
+
} catch {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
})();
|
|
252
|
+
if (isEntry) {
|
|
253
|
+
process.exit(main(process.argv.slice(2)));
|
|
254
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"subpath": "@hirobius/design-system/patterns",
|
|
3
|
+
"names": [
|
|
4
|
+
"ActivityFeed",
|
|
5
|
+
"AppShell",
|
|
6
|
+
"AssetImg",
|
|
7
|
+
"Calendar",
|
|
8
|
+
"Carousel",
|
|
9
|
+
"CodeBlock",
|
|
10
|
+
"CommandPalette",
|
|
11
|
+
"DocLinkCard",
|
|
12
|
+
"ErrorPattern",
|
|
13
|
+
"FileInput",
|
|
14
|
+
"Form",
|
|
15
|
+
"Lightbox",
|
|
16
|
+
"NavItem",
|
|
17
|
+
"OverflowList",
|
|
18
|
+
"Page",
|
|
19
|
+
"Reveal",
|
|
20
|
+
"SideNav",
|
|
21
|
+
"Stepper",
|
|
22
|
+
"Toolbar",
|
|
23
|
+
"TopNav",
|
|
24
|
+
"TreeList"
|
|
25
|
+
]
|
|
26
|
+
}
|