@luxalgo/vela-ui 0.2.0 → 0.4.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/CHANGELOG.md +153 -91
- package/LICENSE +201 -201
- package/NOTICE +28 -28
- package/README.md +86 -86
- package/cli/engine.mjs +282 -282
- package/cli/index.mjs +154 -154
- package/dist/badge.js +1 -1
- package/dist/bar-chart.d.ts +1 -1
- package/dist/bar-chart.js +1 -1
- package/dist/button.d.ts +1 -1
- package/dist/button.js +4 -4
- package/dist/callout-bubble.d.ts +1 -1
- package/dist/callout-bubble.js +4 -4
- package/dist/card.d.ts +52 -0
- package/dist/card.js +179 -0
- package/dist/checkbox.js +5 -5
- package/dist/{chunk-B5ZSRUDQ.js → chunk-BWSOMG3G.js} +2 -2
- package/dist/{chunk-G7IQLY3A.js → chunk-C3PXY2SW.js} +5 -0
- package/dist/{chunk-CC3DDNFC.js → chunk-DXDCKZ2M.js} +4 -4
- package/dist/chunk-GUIYFQ27.js +30 -0
- package/dist/{chunk-WGULXRWD.js → chunk-KUWTI2PE.js} +4 -4
- package/dist/{chunk-Z5PINFQO.js → chunk-QGWAN3EP.js} +5 -5
- package/dist/{chunk-V2Q4MRMS.js → chunk-RH53NQGE.js} +30 -4
- package/dist/{chunk-WBGSYCV2.js → chunk-SKFAYTDK.js} +4 -4
- package/dist/{chunk-MJ4RUGX7.js → chunk-TGJNHUYV.js} +3 -3
- package/dist/{chunk-WXH3EFV5.js → chunk-VC7SVSDK.js} +4 -4
- package/dist/{chunk-7VMN7NKJ.js → chunk-YT2BSP7O.js} +3 -3
- package/dist/collapsible.d.ts +1 -1
- package/dist/collapsible.js +3 -3
- package/dist/color-picker.js +5 -5
- package/dist/context-menu.js +5 -5
- package/dist/data-table.d.ts +1 -1
- package/dist/data-table.js +1 -1
- package/dist/date-picker.d.ts +1 -1
- package/dist/date-picker.js +2 -2
- package/dist/dialog.d.ts +9 -1
- package/dist/dialog.js +15 -5
- package/dist/donut.d.ts +1 -1
- package/dist/donut.js +1 -1
- package/dist/drawer.d.ts +1 -1
- package/dist/drawer.js +2 -2
- package/dist/dropdown-menu.d.ts +1 -1
- package/dist/dropdown-menu.js +5 -5
- package/dist/empty.d.ts +1 -1
- package/dist/empty.js +2 -2
- package/dist/field.js +13 -13
- package/dist/{stat.d.ts → figure.d.ts} +9 -9
- package/dist/figure.js +41 -0
- package/dist/glyph-select.js +5 -5
- package/dist/hover-card.d.ts +1 -1
- package/dist/hover-card.js +3 -3
- package/dist/icons.js +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -3
- package/dist/input-group.d.ts +1 -1
- package/dist/input-group.js +4 -4
- package/dist/input.js +2 -2
- package/dist/item.d.ts +1 -1
- package/dist/item.js +2 -2
- package/dist/kbd.d.ts +1 -1
- package/dist/kbd.js +2 -2
- package/dist/line-chart.d.ts +1 -1
- package/dist/line-chart.js +1 -1
- package/dist/manifest.json +691 -74
- package/dist/month-grid.js +1 -1
- package/dist/number-input.d.ts +1 -1
- package/dist/number-input.js +5 -5
- package/dist/popover.js +3 -3
- package/dist/scatter-chart.d.ts +1 -1
- package/dist/scatter-chart.js +1 -1
- package/dist/select.d.ts +1 -1
- package/dist/select.js +7 -7
- package/dist/slider.d.ts +1 -1
- package/dist/slider.js +2 -2
- package/dist/sort-button.js +4 -4
- package/dist/sparkline.d.ts +1 -1
- package/dist/sparkline.js +1 -1
- package/dist/switch.d.ts +1 -1
- package/dist/switch.js +3 -3
- package/dist/tabs.d.ts +1 -1
- package/dist/tabs.js +4 -4
- package/dist/text-area.d.ts +1 -1
- package/dist/text-area.js +2 -2
- package/dist/theme-TefB8vtl.d.ts +341 -0
- package/dist/theme.d.ts +42 -192
- package/dist/theme.js +1 -1
- package/dist/theme.schema.json +321 -30
- package/dist/toast.d.ts +49 -0
- package/dist/toast.js +463 -0
- package/dist/toggle-group.d.ts +1 -1
- package/dist/toggle-group.js +4 -4
- package/dist/tooltip.js +2 -2
- package/dist/treemap.d.ts +80 -0
- package/dist/treemap.js +470 -0
- package/dist/zag.d.ts +11 -2
- package/dist/zag.js +1 -1
- package/docs/theming.md +217 -217
- package/docs/what-to-change.md +20 -20
- package/docs/writing-a-component.md +250 -250
- package/llms.txt +6 -3
- package/package.json +90 -90
- package/registry/badge.ts +119 -119
- package/registry/bar-chart.ts +215 -215
- package/registry/button.ts +387 -379
- package/registry/callout-bubble.ts +347 -347
- package/registry/card.ts +379 -0
- package/registry/checkbox.ts +234 -234
- package/registry/collapsible.ts +271 -271
- package/registry/color-picker.ts +582 -582
- package/registry/context-menu.ts +208 -208
- package/registry/data-table.ts +215 -215
- package/registry/date-picker.ts +483 -483
- package/registry/dialog.ts +551 -535
- package/registry/donut.ts +145 -145
- package/registry/drawer.ts +636 -636
- package/registry/dropdown-menu.ts +762 -762
- package/registry/empty.ts +91 -91
- package/registry/field.ts +584 -584
- package/registry/{stat.ts → figure.ts} +96 -96
- package/registry/glyph-select.ts +268 -268
- package/registry/hover-card.ts +222 -222
- package/registry/input-group.ts +229 -229
- package/registry/input.ts +181 -181
- package/registry/item.ts +376 -376
- package/registry/kbd.ts +64 -64
- package/registry/line-chart.ts +218 -218
- package/registry/month-grid.ts +328 -328
- package/registry/number-input.ts +443 -443
- package/registry/popover.ts +368 -368
- package/registry/scatter-chart.ts +221 -221
- package/registry/select.ts +620 -620
- package/registry/slider.ts +259 -259
- package/registry/sort-button.ts +189 -189
- package/registry/sparkline.ts +114 -114
- package/registry/switch.ts +205 -205
- package/registry/tabs.ts +426 -426
- package/registry/text-area.ts +186 -186
- package/registry/toast.ts +965 -0
- package/registry/toggle-group.ts +295 -295
- package/registry/tooltip.ts +156 -156
- package/registry/treemap.ts +847 -0
- package/skills/theming-vela-ui/SKILL.md +137 -137
- package/skills/using-vela-ui-components/SKILL.md +139 -137
- package/skills/writing-vela-ui-components/SKILL.md +163 -163
- package/src/components/badge.ts +119 -119
- package/src/components/bar-chart.ts +215 -215
- package/src/components/button.ts +387 -379
- package/src/components/callout-bubble.ts +347 -347
- package/src/components/card.ts +379 -0
- package/src/components/checkbox.ts +234 -234
- package/src/components/collapsible.ts +271 -271
- package/src/components/color-picker.ts +582 -582
- package/src/components/context-menu.ts +208 -208
- package/src/components/data-table.ts +215 -215
- package/src/components/date-picker.ts +483 -483
- package/src/components/dialog.ts +551 -535
- package/src/components/donut.ts +145 -145
- package/src/components/drawer.ts +636 -636
- package/src/components/dropdown-menu.ts +762 -762
- package/src/components/empty.ts +91 -91
- package/src/components/field.ts +584 -584
- package/src/components/{stat.ts → figure.ts} +96 -96
- package/src/components/glyph-select.ts +268 -268
- package/src/components/hover-card.ts +222 -222
- package/src/components/input-group.ts +229 -229
- package/src/components/input.ts +181 -181
- package/src/components/item.ts +376 -376
- package/src/components/kbd.ts +64 -64
- package/src/components/line-chart.ts +218 -218
- package/src/components/month-grid.ts +328 -328
- package/src/components/number-input.ts +443 -443
- package/src/components/popover.ts +368 -368
- package/src/components/scatter-chart.ts +221 -221
- package/src/components/select.ts +620 -620
- package/src/components/slider.ts +259 -259
- package/src/components/sort-button.ts +189 -189
- package/src/components/sparkline.ts +114 -114
- package/src/components/switch.ts +205 -205
- package/src/components/tabs.ts +426 -426
- package/src/components/text-area.ts +186 -186
- package/src/components/toast.ts +965 -0
- package/src/components/toggle-group.ts +295 -295
- package/src/components/tooltip.ts +156 -156
- package/src/components/treemap.ts +847 -0
- package/src/index.ts +24 -24
- package/src/lib/calendar.ts +117 -117
- package/src/lib/chart.ts +72 -72
- package/src/lib/color.ts +89 -89
- package/src/lib/component-index.ts +163 -151
- package/src/lib/css.ts +48 -48
- package/src/lib/define.ts +45 -45
- package/src/lib/dispose.ts +36 -36
- package/src/lib/h.ts +55 -55
- package/src/lib/headless.ts +16 -16
- package/src/lib/i18n.ts +30 -30
- package/src/lib/icons.ts +244 -237
- package/src/lib/kit-text.ts +26 -26
- package/src/lib/page.ts +24 -24
- package/src/lib/palette.ts +81 -81
- package/src/lib/placement.ts +188 -188
- package/src/lib/scope.ts +135 -135
- package/src/lib/styles.ts +53 -53
- package/src/lib/surface-events.ts +31 -31
- package/src/lib/surface-exit.ts +87 -87
- package/src/lib/t.ts +68 -68
- package/src/lib/theme.ts +684 -664
- package/src/lib/tokens.ts +110 -110
- package/src/lib/variants.ts +32 -32
- package/src/lib/zag.ts +61 -46
- package/stylelint/index.mjs +60 -60
- package/stylelint/lint.mjs +81 -81
- package/stylelint/plugin.mjs +115 -115
- package/dist/chunk-P4MTEMT7.js +0 -23
- package/dist/stat.js +0 -41
- package/dist/{chunk-U3EH42YY.js → chunk-5BJV5FY5.js} +1 -1
- package/dist/{chunk-E2FE6V2N.js → chunk-ALAHGSLC.js} +1 -1
- package/dist/{chunk-C3ICYMI3.js → chunk-FYVQO5TN.js} +1 -1
package/cli/index.mjs
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// vela-ui: add a component to a project, copy its source for a variant of your own, see what
|
|
3
|
-
// changed upstream since, and check the project.
|
|
4
|
-
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { join, relative, resolve } from 'node:path';
|
|
6
|
-
import { createInterface } from 'node:readline/promises';
|
|
7
|
-
import { pathToFileURL } from 'node:url';
|
|
8
|
-
import { parseArgs } from 'node:util';
|
|
9
|
-
import * as engine from './engine.mjs';
|
|
10
|
-
|
|
11
|
-
const USAGE = `Usage: vela-ui <command> [options]
|
|
12
|
-
|
|
13
|
-
list the components
|
|
14
|
-
add <component> make ${engine.PACKAGE} a direct dependency and print the import
|
|
15
|
-
add <component> --source copy the component's source, for a variant of your own
|
|
16
|
-
--as <name> the copy's component name (default: app-<component>)
|
|
17
|
-
--force overwrite an existing copy
|
|
18
|
-
diff <copy> what changed upstream since the copy was made
|
|
19
|
-
--accept record that the copy has taken those changes in
|
|
20
|
-
check one copy of the package, no copy behind it, the theme file valid
|
|
21
|
-
|
|
22
|
-
--cwd <path> the project (default: the current folder)
|
|
23
|
-
--from <path> read the catalog from a checkout instead of this package
|
|
24
|
-
--agents add the note for coding agents to AGENTS.md without asking
|
|
25
|
-
--no-install print the install command instead of running it`;
|
|
26
|
-
|
|
27
|
-
const say = (text = '') => process.stdout.write(`${text}\n`);
|
|
28
|
-
const fail = (text) => {
|
|
29
|
-
process.stderr.write(`vela-ui: ${text}\n`);
|
|
30
|
-
process.exit(1);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
let parsed;
|
|
34
|
-
try {
|
|
35
|
-
parsed = parseArgs({
|
|
36
|
-
allowPositionals: true,
|
|
37
|
-
options: {
|
|
38
|
-
source: { type: 'boolean' },
|
|
39
|
-
as: { type: 'string' },
|
|
40
|
-
force: { type: 'boolean' },
|
|
41
|
-
accept: { type: 'boolean' },
|
|
42
|
-
from: { type: 'string' },
|
|
43
|
-
cwd: { type: 'string' },
|
|
44
|
-
agents: { type: 'boolean' },
|
|
45
|
-
'no-install': { type: 'boolean' },
|
|
46
|
-
help: { type: 'boolean', short: 'h' },
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
} catch (e) {
|
|
50
|
-
fail(`${e.message}\n\n${USAGE}`);
|
|
51
|
-
}
|
|
52
|
-
const { values, positionals } = parsed;
|
|
53
|
-
const [command, name] = positionals;
|
|
54
|
-
if (!command || values.help) {
|
|
55
|
-
say(USAGE);
|
|
56
|
-
process.exit(command || values.help ? 0 : 1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const cwd = resolve(values.cwd ?? process.cwd());
|
|
60
|
-
let catalog;
|
|
61
|
-
try {
|
|
62
|
-
catalog = engine.readCatalog(values.from);
|
|
63
|
-
} catch (e) {
|
|
64
|
-
fail(e.message);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function offerAgentsNote() {
|
|
68
|
-
if (engine.hasAgentsBlock(cwd)) return;
|
|
69
|
-
let yes = values.agents === true;
|
|
70
|
-
if (!yes && process.stdin.isTTY) {
|
|
71
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
72
|
-
const answer = await rl.question('Add a note to AGENTS.md pointing coding agents at the kit\'s reference? [Y/n] ');
|
|
73
|
-
rl.close();
|
|
74
|
-
yes = !/^n/i.test(answer.trim());
|
|
75
|
-
}
|
|
76
|
-
if (yes) {
|
|
77
|
-
engine.writeAgentsBlock(cwd);
|
|
78
|
-
say('Added the note to AGENTS.md.');
|
|
79
|
-
} else if (!process.stdin.isTTY) say('Tip: `vela-ui add <component> --agents` adds a note to AGENTS.md pointing coding agents at the kit\'s reference.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function ensureDependency() {
|
|
83
|
-
if (engine.isDirectDependency(cwd)) return;
|
|
84
|
-
const cmd = engine.installCommand(engine.detectPackageManager(cwd), `${engine.PACKAGE}@^${catalog.version}`);
|
|
85
|
-
if (values['no-install']) {
|
|
86
|
-
say(`${engine.PACKAGE} is not a dependency of this project yet: ${cmd}`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
say(`$ ${cmd}`);
|
|
90
|
-
const run = spawnSync(cmd, { cwd, stdio: 'inherit', shell: true });
|
|
91
|
-
if (run.status !== 0) fail(`the install failed (${cmd}).`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
switch (command) {
|
|
95
|
-
case 'list': {
|
|
96
|
-
for (const c of catalog.manifest.components) say(`${c.name.padEnd(16)} ${c.factory ?? ''}`.trimEnd());
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
case 'add': {
|
|
100
|
-
if (!name) fail('add needs a component: `vela-ui list` shows them.');
|
|
101
|
-
const item = engine.findItem(catalog, name);
|
|
102
|
-
if (!item) fail(`no component "${name}" in ${engine.PACKAGE} ${catalog.version}: \`vela-ui list\` shows them.`);
|
|
103
|
-
ensureDependency();
|
|
104
|
-
const factory = item.factory ?? item.exports[0];
|
|
105
|
-
if (values.source) {
|
|
106
|
-
const as = values.as ?? `app-${item.component ?? item.name}`;
|
|
107
|
-
if (!/^[a-z][a-z0-9-]*$/.test(as)) fail(`--as takes a lowercase name with dashes ("${as}").`);
|
|
108
|
-
let file;
|
|
109
|
-
try {
|
|
110
|
-
({ file } = engine.copyItem({ cwd, catalog, item, as, force: values.force }));
|
|
111
|
-
} catch (e) {
|
|
112
|
-
fail(e.message);
|
|
113
|
-
}
|
|
114
|
-
const alias = engine.readConfig(cwd).aliases?.ui;
|
|
115
|
-
const from = alias?.startsWith('#') ? `${alias}/${as}` : `./${relative(cwd, file).split('\\').join('/').replace(/\.ts$/, '')}`;
|
|
116
|
-
say(`Copied ${item.name} to ${relative(cwd, file)}, as the component "${as}" (its parts are data-slot="${as}…").`);
|
|
117
|
-
say(`Vela and the plugins keep rendering the package's ${item.name}.`);
|
|
118
|
-
say();
|
|
119
|
-
say(`import { ${factory} } from '${from}';`);
|
|
120
|
-
} else {
|
|
121
|
-
say(item.example ?? `import { ${factory} } from '${item.import}';`);
|
|
122
|
-
}
|
|
123
|
-
await offerAgentsNote();
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
case 'diff': {
|
|
127
|
-
if (!name) fail('diff needs a copy: the names are in vela-ui.lock.json.');
|
|
128
|
-
try {
|
|
129
|
-
const { entry, diff } = engine.upstreamDiff({ cwd, catalog, as: name });
|
|
130
|
-
if (!diff) say(`${name}: no change upstream since ${entry.version}.`);
|
|
131
|
-
else {
|
|
132
|
-
say(`${name}: ${entry.item}, ${entry.version} -> ${catalog.version} (- upstream when copied, + upstream now)\n`);
|
|
133
|
-
say(diff);
|
|
134
|
-
}
|
|
135
|
-
if (values.accept) {
|
|
136
|
-
engine.acceptUpstream({ cwd, catalog, as: name });
|
|
137
|
-
say(`\nRecorded ${name} as up to date with ${catalog.version}.`);
|
|
138
|
-
}
|
|
139
|
-
} catch (e) {
|
|
140
|
-
fail(e.message);
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case 'check': {
|
|
145
|
-
const { checkTheme } = await import(pathToFileURL(join(catalog.root, 'dist/theme.js')).href);
|
|
146
|
-
const findings = engine.checkProject({ cwd, catalog, checkTheme });
|
|
147
|
-
if (!findings.length) say('vela-ui check: all good.');
|
|
148
|
-
for (const f of findings) say(`${f.level === 'error' ? 'error' : 'warn '} ${f.text}`);
|
|
149
|
-
process.exit(findings.some((f) => f.level === 'error') ? 1 : 0);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
default:
|
|
153
|
-
fail(`unknown command "${command}".\n\n${USAGE}`);
|
|
154
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// vela-ui: add a component to a project, copy its source for a variant of your own, see what
|
|
3
|
+
// changed upstream since, and check the project.
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { join, relative, resolve } from 'node:path';
|
|
6
|
+
import { createInterface } from 'node:readline/promises';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { parseArgs } from 'node:util';
|
|
9
|
+
import * as engine from './engine.mjs';
|
|
10
|
+
|
|
11
|
+
const USAGE = `Usage: vela-ui <command> [options]
|
|
12
|
+
|
|
13
|
+
list the components
|
|
14
|
+
add <component> make ${engine.PACKAGE} a direct dependency and print the import
|
|
15
|
+
add <component> --source copy the component's source, for a variant of your own
|
|
16
|
+
--as <name> the copy's component name (default: app-<component>)
|
|
17
|
+
--force overwrite an existing copy
|
|
18
|
+
diff <copy> what changed upstream since the copy was made
|
|
19
|
+
--accept record that the copy has taken those changes in
|
|
20
|
+
check one copy of the package, no copy behind it, the theme file valid
|
|
21
|
+
|
|
22
|
+
--cwd <path> the project (default: the current folder)
|
|
23
|
+
--from <path> read the catalog from a checkout instead of this package
|
|
24
|
+
--agents add the note for coding agents to AGENTS.md without asking
|
|
25
|
+
--no-install print the install command instead of running it`;
|
|
26
|
+
|
|
27
|
+
const say = (text = '') => process.stdout.write(`${text}\n`);
|
|
28
|
+
const fail = (text) => {
|
|
29
|
+
process.stderr.write(`vela-ui: ${text}\n`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = parseArgs({
|
|
36
|
+
allowPositionals: true,
|
|
37
|
+
options: {
|
|
38
|
+
source: { type: 'boolean' },
|
|
39
|
+
as: { type: 'string' },
|
|
40
|
+
force: { type: 'boolean' },
|
|
41
|
+
accept: { type: 'boolean' },
|
|
42
|
+
from: { type: 'string' },
|
|
43
|
+
cwd: { type: 'string' },
|
|
44
|
+
agents: { type: 'boolean' },
|
|
45
|
+
'no-install': { type: 'boolean' },
|
|
46
|
+
help: { type: 'boolean', short: 'h' },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
} catch (e) {
|
|
50
|
+
fail(`${e.message}\n\n${USAGE}`);
|
|
51
|
+
}
|
|
52
|
+
const { values, positionals } = parsed;
|
|
53
|
+
const [command, name] = positionals;
|
|
54
|
+
if (!command || values.help) {
|
|
55
|
+
say(USAGE);
|
|
56
|
+
process.exit(command || values.help ? 0 : 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const cwd = resolve(values.cwd ?? process.cwd());
|
|
60
|
+
let catalog;
|
|
61
|
+
try {
|
|
62
|
+
catalog = engine.readCatalog(values.from);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
fail(e.message);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function offerAgentsNote() {
|
|
68
|
+
if (engine.hasAgentsBlock(cwd)) return;
|
|
69
|
+
let yes = values.agents === true;
|
|
70
|
+
if (!yes && process.stdin.isTTY) {
|
|
71
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
72
|
+
const answer = await rl.question('Add a note to AGENTS.md pointing coding agents at the kit\'s reference? [Y/n] ');
|
|
73
|
+
rl.close();
|
|
74
|
+
yes = !/^n/i.test(answer.trim());
|
|
75
|
+
}
|
|
76
|
+
if (yes) {
|
|
77
|
+
engine.writeAgentsBlock(cwd);
|
|
78
|
+
say('Added the note to AGENTS.md.');
|
|
79
|
+
} else if (!process.stdin.isTTY) say('Tip: `vela-ui add <component> --agents` adds a note to AGENTS.md pointing coding agents at the kit\'s reference.');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function ensureDependency() {
|
|
83
|
+
if (engine.isDirectDependency(cwd)) return;
|
|
84
|
+
const cmd = engine.installCommand(engine.detectPackageManager(cwd), `${engine.PACKAGE}@^${catalog.version}`);
|
|
85
|
+
if (values['no-install']) {
|
|
86
|
+
say(`${engine.PACKAGE} is not a dependency of this project yet: ${cmd}`);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
say(`$ ${cmd}`);
|
|
90
|
+
const run = spawnSync(cmd, { cwd, stdio: 'inherit', shell: true });
|
|
91
|
+
if (run.status !== 0) fail(`the install failed (${cmd}).`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
switch (command) {
|
|
95
|
+
case 'list': {
|
|
96
|
+
for (const c of catalog.manifest.components) say(`${c.name.padEnd(16)} ${c.factory ?? ''}`.trimEnd());
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case 'add': {
|
|
100
|
+
if (!name) fail('add needs a component: `vela-ui list` shows them.');
|
|
101
|
+
const item = engine.findItem(catalog, name);
|
|
102
|
+
if (!item) fail(`no component "${name}" in ${engine.PACKAGE} ${catalog.version}: \`vela-ui list\` shows them.`);
|
|
103
|
+
ensureDependency();
|
|
104
|
+
const factory = item.factory ?? item.exports[0];
|
|
105
|
+
if (values.source) {
|
|
106
|
+
const as = values.as ?? `app-${item.component ?? item.name}`;
|
|
107
|
+
if (!/^[a-z][a-z0-9-]*$/.test(as)) fail(`--as takes a lowercase name with dashes ("${as}").`);
|
|
108
|
+
let file;
|
|
109
|
+
try {
|
|
110
|
+
({ file } = engine.copyItem({ cwd, catalog, item, as, force: values.force }));
|
|
111
|
+
} catch (e) {
|
|
112
|
+
fail(e.message);
|
|
113
|
+
}
|
|
114
|
+
const alias = engine.readConfig(cwd).aliases?.ui;
|
|
115
|
+
const from = alias?.startsWith('#') ? `${alias}/${as}` : `./${relative(cwd, file).split('\\').join('/').replace(/\.ts$/, '')}`;
|
|
116
|
+
say(`Copied ${item.name} to ${relative(cwd, file)}, as the component "${as}" (its parts are data-slot="${as}…").`);
|
|
117
|
+
say(`Vela and the plugins keep rendering the package's ${item.name}.`);
|
|
118
|
+
say();
|
|
119
|
+
say(`import { ${factory} } from '${from}';`);
|
|
120
|
+
} else {
|
|
121
|
+
say(item.example ?? `import { ${factory} } from '${item.import}';`);
|
|
122
|
+
}
|
|
123
|
+
await offerAgentsNote();
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case 'diff': {
|
|
127
|
+
if (!name) fail('diff needs a copy: the names are in vela-ui.lock.json.');
|
|
128
|
+
try {
|
|
129
|
+
const { entry, diff } = engine.upstreamDiff({ cwd, catalog, as: name });
|
|
130
|
+
if (!diff) say(`${name}: no change upstream since ${entry.version}.`);
|
|
131
|
+
else {
|
|
132
|
+
say(`${name}: ${entry.item}, ${entry.version} -> ${catalog.version} (- upstream when copied, + upstream now)\n`);
|
|
133
|
+
say(diff);
|
|
134
|
+
}
|
|
135
|
+
if (values.accept) {
|
|
136
|
+
engine.acceptUpstream({ cwd, catalog, as: name });
|
|
137
|
+
say(`\nRecorded ${name} as up to date with ${catalog.version}.`);
|
|
138
|
+
}
|
|
139
|
+
} catch (e) {
|
|
140
|
+
fail(e.message);
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'check': {
|
|
145
|
+
const { checkTheme } = await import(pathToFileURL(join(catalog.root, 'dist/theme.js')).href);
|
|
146
|
+
const findings = engine.checkProject({ cwd, catalog, checkTheme });
|
|
147
|
+
if (!findings.length) say('vela-ui check: all good.');
|
|
148
|
+
for (const f of findings) say(`${f.level === 'error' ? 'error' : 'warn '} ${f.text}`);
|
|
149
|
+
process.exit(findings.some((f) => f.level === 'error') ? 1 : 0);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
default:
|
|
153
|
+
fail(`unknown command "${command}".\n\n${USAGE}`);
|
|
154
|
+
}
|
package/dist/badge.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
2
|
import { h } from './chunk-Q6WTDVH6.js';
|
|
3
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
3
4
|
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
4
5
|
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
5
6
|
import './chunk-2GQIZM5Z.js';
|
|
6
7
|
import './chunk-BXMWQIBO.js';
|
|
7
8
|
import './chunk-X66RJAIS.js';
|
|
8
|
-
import { t } from './chunk-6QCILIT2.js';
|
|
9
9
|
|
|
10
10
|
// src/components/badge.ts
|
|
11
11
|
var badgeDef = defineComponent({
|
package/dist/bar-chart.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
2
|
import './t.js';
|
|
3
3
|
|
|
4
|
-
declare const barChartDef: ComponentDef<"bar-chart", "
|
|
4
|
+
declare const barChartDef: ComponentDef<"bar-chart", "label" | "marker" | "root" | "grid" | "bar" | "tip", "tip-radius" | "tip-shadow" | "tip-z" | "tip-bg">;
|
|
5
5
|
interface BarDatum {
|
|
6
6
|
label: string;
|
|
7
7
|
value: number;
|
package/dist/bar-chart.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { chartFrame, showTip, valueAxis, compactNumber, escapeXml } from './chunk-A2FJ7Y7D.js';
|
|
2
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
2
3
|
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
3
4
|
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
4
5
|
import './chunk-2GQIZM5Z.js';
|
|
5
6
|
import './chunk-BXMWQIBO.js';
|
|
6
7
|
import './chunk-X66RJAIS.js';
|
|
7
|
-
import { t } from './chunk-6QCILIT2.js';
|
|
8
8
|
|
|
9
9
|
// src/components/bar-chart.ts
|
|
10
10
|
var barChartDef = defineComponent({
|
package/dist/button.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { a as VariantProps, V as VariantFn } from './variants-B4stUBnY.js';
|
|
|
2
2
|
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
3
3
|
import './t.js';
|
|
4
4
|
|
|
5
|
-
declare const buttonDef: ComponentDef<"button", "
|
|
5
|
+
declare const buttonDef: ComponentDef<"button", "keys" | "root" | "icon", "height" | "font-size-sm" | "radius" | "height-xs" | "height-sm" | "height-lg" | "font-size" | "font-size-xs">;
|
|
6
6
|
declare const buttonVariants: VariantFn<{
|
|
7
7
|
readonly variant: readonly ["default", "outline", "secondary", "ghost", "destructive", "link", "up", "down", "favorite"];
|
|
8
8
|
readonly size: readonly ["default", "xs", "sm", "lg", "icon", "icon-xs", "icon-sm", "icon-lg"];
|
package/dist/button.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { BUTTON_CSS, BUTTON_STYLE_ID, buttonDef, buttonVariants, createButton } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { BUTTON_CSS, BUTTON_STYLE_ID, buttonDef, buttonVariants, createButton } from './chunk-DXDCKZ2M.js';
|
|
2
|
+
import './chunk-FYVQO5TN.js';
|
|
3
|
+
import './chunk-C3PXY2SW.js';
|
|
3
4
|
import './chunk-LZWZV2ZS.js';
|
|
4
|
-
import './chunk-G7IQLY3A.js';
|
|
5
5
|
import './chunk-Q6WTDVH6.js';
|
|
6
|
+
import './chunk-6QCILIT2.js';
|
|
6
7
|
import './chunk-VMCR3S2A.js';
|
|
7
8
|
import './chunk-XBEL4K33.js';
|
|
8
9
|
import './chunk-2GQIZM5Z.js';
|
|
9
10
|
import './chunk-BXMWQIBO.js';
|
|
10
11
|
import './chunk-X66RJAIS.js';
|
|
11
|
-
import './chunk-6QCILIT2.js';
|
package/dist/callout-bubble.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ type CalloutPanelRow = {
|
|
|
55
55
|
* stand alone. Pure — unit-tested apart from the DOM.
|
|
56
56
|
*/
|
|
57
57
|
declare function calloutPanelRows(items: CalloutPanelItem[]): CalloutPanelRow[];
|
|
58
|
-
declare const calloutBubbleDef: ComponentDef<"callout-bubble", "
|
|
58
|
+
declare const calloutBubbleDef: ComponentDef<"callout-bubble", "button" | "title" | "text" | "root" | "panel" | "actions", "panel-radius" | "button-radius">;
|
|
59
59
|
/** The panel opens where the placement props say (default below and start-aligned, 6px away,
|
|
60
60
|
* flipping above near the bottom edge). */
|
|
61
61
|
interface CalloutBubbleOptions extends CalloutBubbleSpec, PlacementProps {
|
package/dist/callout-bubble.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Popover } from './chunk-B5ZSRUDQ.js';
|
|
1
|
+
import { Popover } from './chunk-BWSOMG3G.js';
|
|
3
2
|
import './chunk-J2QJATCD.js';
|
|
4
3
|
import './chunk-S7USVSYP.js';
|
|
5
|
-
import './chunk-
|
|
4
|
+
import './chunk-RH53NQGE.js';
|
|
6
5
|
import './chunk-TAKSIV57.js';
|
|
7
6
|
import './chunk-MMTMOV6R.js';
|
|
8
7
|
import './chunk-3Q32K4PE.js';
|
|
9
8
|
import './chunk-A72NWYNP.js';
|
|
9
|
+
import { iconAt } from './chunk-C3PXY2SW.js';
|
|
10
10
|
import { addSlot } from './chunk-Q6WTDVH6.js';
|
|
11
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
11
12
|
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
12
13
|
import { css, defineStyles } from './chunk-XBEL4K33.js';
|
|
13
14
|
import './chunk-2GQIZM5Z.js';
|
|
14
15
|
import './chunk-BXMWQIBO.js';
|
|
15
16
|
import './chunk-X66RJAIS.js';
|
|
16
|
-
import { t } from './chunk-6QCILIT2.js';
|
|
17
17
|
|
|
18
18
|
// src/components/callout-bubble.ts
|
|
19
19
|
function closesPanel(item) {
|
package/dist/card.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { C as Child } from './h-Bl37qUis.js';
|
|
2
|
+
import { a as VariantProps, V as VariantFn } from './variants-B4stUBnY.js';
|
|
3
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
4
|
+
import './t.js';
|
|
5
|
+
|
|
6
|
+
declare const cardDef: ComponentDef<"card", "footer" | "header" | "title" | "root" | "trigger" | "content" | "heading" | "eyebrow" | "description" | "action", "border" | "radius" | "gap" | "background" | "padding" | "padding-sm" | "gap-sm" | "inset-background">;
|
|
7
|
+
declare const cardVariants: VariantFn<{
|
|
8
|
+
readonly variant: readonly ["default", "inset"];
|
|
9
|
+
readonly size: readonly ["default", "sm"];
|
|
10
|
+
}>;
|
|
11
|
+
type CardVariant = (typeof cardVariants.spec.variant)[number];
|
|
12
|
+
type CardSize = (typeof cardVariants.spec.size)[number];
|
|
13
|
+
interface CardProps extends VariantProps<typeof cardVariants> {
|
|
14
|
+
/** Small capitals over the title: what kind of card it is ("Market pulse"). */
|
|
15
|
+
eyebrow?: string | Node;
|
|
16
|
+
/** The heading: text, or an element (a name with a badge after it). */
|
|
17
|
+
title?: string | Node;
|
|
18
|
+
/** The muted line under the title. */
|
|
19
|
+
description?: string | Node;
|
|
20
|
+
/** At the header's end: its buttons, a toggle group. */
|
|
21
|
+
action?: Child;
|
|
22
|
+
/** The body. More can be appended to the handle's `content` later. */
|
|
23
|
+
content?: Child;
|
|
24
|
+
/** Under the body, past a line: notes, a source, a time. */
|
|
25
|
+
footer?: Child;
|
|
26
|
+
/** The title's heading level (default 3). */
|
|
27
|
+
headingLevel?: 2 | 3 | 4 | 5 | 6;
|
|
28
|
+
/** The current card (the one a detail view shows). */
|
|
29
|
+
selected?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Makes the card clickable: a click on it, or Enter or Space on its title, runs it. */
|
|
32
|
+
onSelect?: (e: MouseEvent | KeyboardEvent) => void;
|
|
33
|
+
/** Extra class names (layout hooks). */
|
|
34
|
+
className?: string;
|
|
35
|
+
}
|
|
36
|
+
interface CardHandle {
|
|
37
|
+
readonly el: HTMLElement;
|
|
38
|
+
/** The body: append the card's content here. */
|
|
39
|
+
readonly content: HTMLElement;
|
|
40
|
+
/** A new title; null removes it. */
|
|
41
|
+
setTitle(title: string | Node | null): void;
|
|
42
|
+
/** A new description; null removes it. */
|
|
43
|
+
setDescription(description: string | Node | null): void;
|
|
44
|
+
/** A new footer; null removes it. */
|
|
45
|
+
setFooter(footer: Child | null): void;
|
|
46
|
+
setSelected(selected: boolean): void;
|
|
47
|
+
setDisabled(disabled: boolean): void;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|
|
50
|
+
declare function createCard(props?: CardProps): CardHandle;
|
|
51
|
+
|
|
52
|
+
export { type CardHandle, type CardProps, type CardSize, type CardVariant, cardDef, cardVariants, createCard };
|
package/dist/card.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { variants } from './chunk-LZWZV2ZS.js';
|
|
2
|
+
import { h, append } from './chunk-Q6WTDVH6.js';
|
|
3
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
4
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
5
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
6
|
+
import './chunk-2GQIZM5Z.js';
|
|
7
|
+
import './chunk-BXMWQIBO.js';
|
|
8
|
+
import './chunk-X66RJAIS.js';
|
|
9
|
+
|
|
10
|
+
// src/components/card.ts
|
|
11
|
+
var cardDef = defineComponent({
|
|
12
|
+
name: "card",
|
|
13
|
+
parts: ["root", "header", "heading", "eyebrow", "title", "trigger", "description", "action", "content", "footer"],
|
|
14
|
+
settings: {
|
|
15
|
+
radius: t.radius.lg,
|
|
16
|
+
padding: "16px",
|
|
17
|
+
"padding-sm": "10px 12px",
|
|
18
|
+
gap: "12px",
|
|
19
|
+
"gap-sm": "8px",
|
|
20
|
+
background: t.surface,
|
|
21
|
+
border: t.border,
|
|
22
|
+
"inset-background": `color-mix(in srgb, ${t.fg.bright} 2.5%, ${t.surface})`
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var cardVariants = variants({ variant: ["default", "inset"], size: ["default", "sm"] });
|
|
26
|
+
var CONTROL = 'button, a[href], input, select, textarea, label, summary, [role="button"], [role="checkbox"], [role="switch"], [role="menuitem"], [role="option"], [role="link"], [role="tab"], [role="radio"], [contenteditable]:not([contenteditable="false"])';
|
|
27
|
+
var injectStyles = defineStyles(
|
|
28
|
+
"vela-ui-card",
|
|
29
|
+
css`@layer vela.ui{[data-slot=card]{box-sizing:border-box;min-width:0;padding:${cardDef.vars.padding};border:1px solid ${cardDef.vars.border};border-radius:${cardDef.vars.radius};background:${cardDef.vars.background};color:${t.fg};text-align:start;transition:background ${t.dur.fast} ease, border-color ${t.dur.fast} ease;font-size:13px;position:relative}[data-slot=card]:where(:not([hidden])){gap:${cardDef.vars.gap};flex-direction:column;display:flex}[data-slot=card][data-size=sm]{gap:${cardDef.vars["gap-sm"]};padding:${cardDef.vars["padding-sm"]};font-size:12px}[data-slot=card][data-variant=inset]{background:${cardDef.vars["inset-background"]}}[data-slot=card][data-clickable]{cursor:pointer;-webkit-tap-highlight-color:transparent}[data-slot=card][data-clickable]:not([data-disabled]):hover{border-color:${t.border.strong}}[data-slot=card][data-selected],[data-slot=card][data-selected][data-clickable]:hover{border-color:${t.fg.bright}}[data-slot=card]:focus-visible{outline:2px solid ${t.focus};outline-offset:2px}[data-slot=card][data-disabled]{cursor:default;opacity:.5}[data-slot=card-header]{gap:12px;min-width:0}[data-slot=card-header]:where(:not([hidden])){align-items:flex-start;display:flex}[data-slot=card-heading]{flex:auto;min-width:0}[data-slot=card-heading]:where(:not([hidden])){flex-direction:column;gap:2px;display:flex}[data-slot=card-eyebrow]{color:${t.fg.muted};letter-spacing:.08em;text-transform:uppercase;font-size:10px;font-weight:500;line-height:14px}[data-slot=card-title]{color:${t.fg.bright};overflow-wrap:anywhere;margin:0;font-size:15px;font-weight:600;line-height:1.3}[data-slot=card-title]:is([data-size=sm] *){font-size:13px}[data-slot=card-trigger]{all:unset;border-radius:${t.radius.sm};cursor:pointer}[data-slot=card-trigger]:focus-visible{outline:2px solid ${t.focus};outline-offset:2px}[data-slot=card-trigger]:disabled{cursor:default}[data-slot=card-description]{color:${t.fg.muted};margin:0;font-size:12px;line-height:1.45}[data-slot=card-action]{flex:none;gap:6px;margin-inline-start:auto}[data-slot=card-action]:where(:not([hidden])){align-items:center;display:inline-flex}[data-slot=card-content]{flex:auto;min-width:0}[data-slot=card-footer]{border-top:1px solid ${cardDef.vars.border};color:${t.fg.muted};flex-wrap:wrap;gap:8px 16px;padding-top:10px;font-size:11px;line-height:1.5}[data-slot=card-footer]:where(:not([hidden])){justify-content:space-between;align-items:center;display:flex}}`
|
|
30
|
+
);
|
|
31
|
+
var CardImpl = class {
|
|
32
|
+
constructor(props) {
|
|
33
|
+
this.props = props;
|
|
34
|
+
this.header = null;
|
|
35
|
+
this.heading = null;
|
|
36
|
+
this.titleEl = null;
|
|
37
|
+
this.trigger = null;
|
|
38
|
+
this.descriptionEl = null;
|
|
39
|
+
this.footerEl = null;
|
|
40
|
+
this.disabled = false;
|
|
41
|
+
this.selected = false;
|
|
42
|
+
this.onClick = (e) => {
|
|
43
|
+
if (this.disabled) return;
|
|
44
|
+
const control = e.target instanceof Element ? e.target.closest(CONTROL) : null;
|
|
45
|
+
if (control && control !== this.trigger && control !== this.el && this.el.contains(control)) return;
|
|
46
|
+
this.props.onSelect?.(e);
|
|
47
|
+
};
|
|
48
|
+
this.onKey = (e) => {
|
|
49
|
+
if (this.disabled || e.target !== this.el || e.key !== "Enter" && e.key !== " ") return;
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
this.props.onSelect?.(e);
|
|
52
|
+
};
|
|
53
|
+
injectStyles(document);
|
|
54
|
+
this.content = h("div", { slot: cardDef.slot("content") });
|
|
55
|
+
append(this.content, [props.content]);
|
|
56
|
+
this.el = h(
|
|
57
|
+
"div",
|
|
58
|
+
{ className: props.className, slot: cardDef.slot("root"), attrs: cardVariants(props), data: { clickable: props.onSelect ? true : null } },
|
|
59
|
+
this.content
|
|
60
|
+
);
|
|
61
|
+
if (props.eyebrow !== void 0) this.ensureHeading().prepend(h("div", { slot: cardDef.slot("eyebrow") }, props.eyebrow));
|
|
62
|
+
if (props.title !== void 0) this.setTitle(props.title);
|
|
63
|
+
if (props.description !== void 0) this.setDescription(props.description);
|
|
64
|
+
if (props.action !== void 0 && props.action !== null) {
|
|
65
|
+
const action = h("div", { slot: cardDef.slot("action") });
|
|
66
|
+
append(action, [props.action]);
|
|
67
|
+
this.ensureHeader().append(action);
|
|
68
|
+
}
|
|
69
|
+
if (props.footer !== void 0) this.setFooter(props.footer);
|
|
70
|
+
if (props.onSelect) this.el.addEventListener("click", this.onClick);
|
|
71
|
+
this.disabled = props.disabled ?? false;
|
|
72
|
+
this.selected = props.selected ?? false;
|
|
73
|
+
this.syncControl();
|
|
74
|
+
this.setDisabled(this.disabled);
|
|
75
|
+
this.setSelected(this.selected);
|
|
76
|
+
}
|
|
77
|
+
setTitle(title) {
|
|
78
|
+
if (title === null) {
|
|
79
|
+
this.titleEl?.remove();
|
|
80
|
+
this.titleEl = null;
|
|
81
|
+
this.trigger = null;
|
|
82
|
+
this.syncControl();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!this.titleEl) {
|
|
86
|
+
this.titleEl = h(`h${this.props.headingLevel ?? 3}`, { slot: cardDef.slot("title") });
|
|
87
|
+
const heading = this.ensureHeading();
|
|
88
|
+
const eyebrow = heading.querySelector(`:scope > [data-slot="${cardDef.slot("eyebrow")}"]`);
|
|
89
|
+
if (eyebrow) eyebrow.after(this.titleEl);
|
|
90
|
+
else heading.prepend(this.titleEl);
|
|
91
|
+
if (this.props.onSelect) {
|
|
92
|
+
this.trigger = h("button", { slot: cardDef.slot("trigger"), attrs: { type: "button" } });
|
|
93
|
+
this.titleEl.append(this.trigger);
|
|
94
|
+
}
|
|
95
|
+
this.syncControl();
|
|
96
|
+
}
|
|
97
|
+
(this.trigger ?? this.titleEl).replaceChildren(title);
|
|
98
|
+
}
|
|
99
|
+
setDescription(description) {
|
|
100
|
+
if (description === null) {
|
|
101
|
+
this.descriptionEl?.remove();
|
|
102
|
+
this.descriptionEl = null;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this.descriptionEl ?? (this.descriptionEl = this.ensureHeading().appendChild(h("p", { slot: cardDef.slot("description") })));
|
|
106
|
+
this.descriptionEl.replaceChildren(description);
|
|
107
|
+
}
|
|
108
|
+
setFooter(footer) {
|
|
109
|
+
if (footer === null) {
|
|
110
|
+
this.footerEl?.remove();
|
|
111
|
+
this.footerEl = null;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.footerEl ?? (this.footerEl = this.el.appendChild(h("div", { slot: cardDef.slot("footer") })));
|
|
115
|
+
this.footerEl.replaceChildren();
|
|
116
|
+
append(this.footerEl, [footer]);
|
|
117
|
+
}
|
|
118
|
+
setSelected(selected) {
|
|
119
|
+
this.selected = selected;
|
|
120
|
+
this.el.toggleAttribute("data-selected", selected);
|
|
121
|
+
this.el.removeAttribute("aria-current");
|
|
122
|
+
this.trigger?.removeAttribute("aria-current");
|
|
123
|
+
if (selected) this.control()?.setAttribute("aria-current", "true");
|
|
124
|
+
}
|
|
125
|
+
setDisabled(disabled) {
|
|
126
|
+
this.disabled = disabled;
|
|
127
|
+
this.el.toggleAttribute("data-disabled", disabled);
|
|
128
|
+
if (this.trigger) this.trigger.disabled = disabled;
|
|
129
|
+
else if (this.props.onSelect) {
|
|
130
|
+
this.el.tabIndex = disabled ? -1 : 0;
|
|
131
|
+
if (disabled) this.el.setAttribute("aria-disabled", "true");
|
|
132
|
+
else this.el.removeAttribute("aria-disabled");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
destroy() {
|
|
136
|
+
this.el.removeEventListener("click", this.onClick);
|
|
137
|
+
this.el.removeEventListener("keydown", this.onKey);
|
|
138
|
+
this.el.remove();
|
|
139
|
+
}
|
|
140
|
+
/** What the keyboard and screen readers press: the title's button, or the card itself without a title. */
|
|
141
|
+
control() {
|
|
142
|
+
if (!this.props.onSelect) return null;
|
|
143
|
+
return this.trigger ?? this.el;
|
|
144
|
+
}
|
|
145
|
+
/** Give the card the button's role while it has no title to carry it, and take it back once it has one. */
|
|
146
|
+
syncControl() {
|
|
147
|
+
if (!this.props.onSelect) return;
|
|
148
|
+
if (this.trigger === null) {
|
|
149
|
+
this.el.setAttribute("role", "button");
|
|
150
|
+
this.el.addEventListener("keydown", this.onKey);
|
|
151
|
+
} else {
|
|
152
|
+
this.el.removeAttribute("role");
|
|
153
|
+
this.el.removeAttribute("tabindex");
|
|
154
|
+
this.el.removeAttribute("aria-disabled");
|
|
155
|
+
this.el.removeEventListener("keydown", this.onKey);
|
|
156
|
+
}
|
|
157
|
+
this.setDisabled(this.disabled);
|
|
158
|
+
this.setSelected(this.selected);
|
|
159
|
+
}
|
|
160
|
+
ensureHeader() {
|
|
161
|
+
if (!this.header) {
|
|
162
|
+
this.header = h("div", { slot: cardDef.slot("header") });
|
|
163
|
+
this.el.prepend(this.header);
|
|
164
|
+
}
|
|
165
|
+
return this.header;
|
|
166
|
+
}
|
|
167
|
+
ensureHeading() {
|
|
168
|
+
if (!this.heading) {
|
|
169
|
+
this.heading = h("div", { slot: cardDef.slot("heading") });
|
|
170
|
+
this.ensureHeader().prepend(this.heading);
|
|
171
|
+
}
|
|
172
|
+
return this.heading;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
function createCard(props = {}) {
|
|
176
|
+
return new CardImpl(props);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export { cardDef, cardVariants, createCard };
|