@blankways/ui 0.1.0-alpha.1 → 0.2.0-alpha.1
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/README.md +157 -139
- package/dist/cli/cli.options.js +21 -1
- package/dist/cli/cli.types.d.ts +1 -0
- package/dist/cli.js +2 -1
- package/dist/commands/add.command.d.ts +2 -0
- package/dist/commands/add.command.js +30 -82
- package/dist/commands/dev.command.d.ts +3 -0
- package/dist/commands/dev.command.js +76 -0
- package/dist/commands/doctor.command.js +12 -1
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.command.js +15 -10
- package/dist/commands/install.command.d.ts +2 -0
- package/dist/commands/install.command.js +36 -0
- package/dist/commands/list.command.js +10 -5
- package/dist/commands/registry.command.d.ts +2 -0
- package/dist/commands/registry.command.js +69 -0
- package/dist/commands/styles.command.d.ts +1 -2
- package/dist/commands/styles.command.js +15 -39
- package/dist/config/config.helpers.d.ts +4 -1
- package/dist/config/config.helpers.js +61 -8
- package/dist/constants/cli.constants.d.ts +14 -3
- package/dist/constants/cli.constants.js +14 -9
- package/dist/doctor/checks/barrels.check.d.ts +1 -0
- package/dist/doctor/checks/barrels.check.js +60 -0
- package/dist/doctor/checks/contracts.check.d.ts +1 -0
- package/dist/doctor/checks/contracts.check.js +45 -0
- package/dist/doctor/checks/icons.check.js +8 -3
- package/dist/doctor/checks/index.d.ts +3 -0
- package/dist/doctor/checks/index.js +3 -0
- package/dist/doctor/checks/motion.check.js +2 -2
- package/dist/doctor/checks/namespaces.check.d.ts +1 -0
- package/dist/doctor/checks/namespaces.check.js +76 -0
- package/dist/doctor/checks/themes.check.js +18 -40
- package/dist/doctor/doctor.helpers.js +5 -1
- package/dist/doctor/doctor.types.d.ts +4 -0
- package/dist/helpers/args.helpers.d.ts +2 -0
- package/dist/helpers/args.helpers.js +9 -0
- package/dist/helpers/barrels.helpers.d.ts +15 -0
- package/dist/helpers/barrels.helpers.js +157 -0
- package/dist/index.d.ts +12 -9
- package/dist/index.js +11 -9
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/lockfile.d.ts +18 -0
- package/dist/registry/lockfile.js +32 -0
- package/dist/registry/registry.helpers.d.ts +3 -13
- package/dist/registry/registry.helpers.js +30 -116
- package/dist/registry/registry.providers.d.ts +13 -0
- package/dist/registry/registry.providers.js +159 -0
- package/dist/registry/registry.service.d.ts +14 -0
- package/dist/registry/registry.service.js +126 -0
- package/dist/types/config.types.d.ts +29 -0
- package/dist/types/registry.types.d.ts +31 -0
- package/dist/types/registry.types.js +2 -0
- package/dist/ui-api/index.d.ts +16 -0
- package/dist/ui-api/index.js +30 -0
- package/dist/ui-api/ui-api.d.ts +18 -0
- package/dist/ui-api/ui-api.js +194 -0
- package/package.json +7 -5
- package/styles.css +16 -0
- package/dist/registry-data/README.md +0 -71
- package/dist/registry-data/avatar/Avatar.tsx +0 -64
- package/dist/registry-data/avatar/component.json +0 -30
- package/dist/registry-data/avatar/index.ts +0 -1
- package/dist/registry-data/badge/Badge.tsx +0 -76
- package/dist/registry-data/badge/component.json +0 -30
- package/dist/registry-data/badge/index.ts +0 -1
- package/dist/registry-data/brand-logo/BrandLogo.tsx +0 -24
- package/dist/registry-data/brand-logo/component.json +0 -26
- package/dist/registry-data/brand-logo/index.ts +0 -1
- package/dist/registry-data/button/Button.tsx +0 -76
- package/dist/registry-data/button/component.json +0 -33
- package/dist/registry-data/button/index.ts +0 -1
- package/dist/registry-data/button-link/ButtonLink.tsx +0 -83
- package/dist/registry-data/button-link/component.json +0 -33
- package/dist/registry-data/button-link/index.ts +0 -5
- package/dist/registry-data/button-styles/component.json +0 -19
- package/dist/registry-data/button-styles/index.ts +0 -45
- package/dist/registry-data/cn/cn.ts +0 -6
- package/dist/registry-data/cn/component.json +0 -16
- package/dist/registry-data/confirm-dialog/ConfirmDialog.tsx +0 -134
- package/dist/registry-data/confirm-dialog/component.json +0 -34
- package/dist/registry-data/confirm-dialog/index.ts +0 -1
- package/dist/registry-data/container/Container.tsx +0 -22
- package/dist/registry-data/container/component.json +0 -28
- package/dist/registry-data/container/index.ts +0 -1
- package/dist/registry-data/cursor-glow/CursorGlow.tsx +0 -29
- package/dist/registry-data/cursor-glow/component.json +0 -28
- package/dist/registry-data/cursor-glow/index.ts +0 -1
- package/dist/registry-data/dropdown-menu/DropdownMenu.tsx +0 -157
- package/dist/registry-data/dropdown-menu/component.json +0 -34
- package/dist/registry-data/dropdown-menu/index.ts +0 -5
- package/dist/registry-data/empty-state/EmptyState.tsx +0 -92
- package/dist/registry-data/empty-state/component.json +0 -30
- package/dist/registry-data/empty-state/index.ts +0 -5
- package/dist/registry-data/eyebrow/Eyebrow.tsx +0 -68
- package/dist/registry-data/eyebrow/component.json +0 -30
- package/dist/registry-data/eyebrow/index.ts +0 -1
- package/dist/registry-data/field-styles/component.json +0 -19
- package/dist/registry-data/field-styles/index.ts +0 -42
- package/dist/registry-data/form-dialog/FormDialog.tsx +0 -128
- package/dist/registry-data/form-dialog/component.json +0 -34
- package/dist/registry-data/form-dialog/index.ts +0 -1
- package/dist/registry-data/icons/component.json +0 -22
- package/dist/registry-data/icons/index.ts +0 -21
- package/dist/registry-data/icons-form/component.json +0 -17
- package/dist/registry-data/icons-form/index.ts +0 -1
- package/dist/registry-data/icons-sidebar/component.json +0 -17
- package/dist/registry-data/icons-sidebar/index.ts +0 -1
- package/dist/registry-data/icons-theme/component.json +0 -17
- package/dist/registry-data/icons-theme/index.ts +0 -1
- package/dist/registry-data/icons-toast/component.json +0 -17
- package/dist/registry-data/icons-toast/index.ts +0 -1
- package/dist/registry-data/info-dialog/InfoDialog.tsx +0 -119
- package/dist/registry-data/info-dialog/component.json +0 -36
- package/dist/registry-data/info-dialog/index.ts +0 -1
- package/dist/registry-data/input/Input.tsx +0 -96
- package/dist/registry-data/input/component.json +0 -33
- package/dist/registry-data/input/index.ts +0 -1
- package/dist/registry-data/multi-combobox/MultiCombobox.tsx +0 -205
- package/dist/registry-data/multi-combobox/component.json +0 -35
- package/dist/registry-data/multi-combobox/index.ts +0 -5
- package/dist/registry-data/remote-provider/RemoteProvider.tsx +0 -8
- package/dist/registry-data/remote-provider/component.json +0 -25
- package/dist/registry-data/remote-provider/index.ts +0 -3
- package/dist/registry-data/reveal/Reveal.tsx +0 -22
- package/dist/registry-data/reveal/component.json +0 -30
- package/dist/registry-data/reveal/index.ts +0 -1
- package/dist/registry-data/section/Section.tsx +0 -80
- package/dist/registry-data/section/component.json +0 -30
- package/dist/registry-data/section/index.ts +0 -1
- package/dist/registry-data/section-heading/SectionHeading.tsx +0 -105
- package/dist/registry-data/section-heading/component.json +0 -32
- package/dist/registry-data/section-heading/index.ts +0 -1
- package/dist/registry-data/select/Select.tsx +0 -197
- package/dist/registry-data/select/component.json +0 -34
- package/dist/registry-data/select/index.ts +0 -1
- package/dist/registry-data/sidebar/Sidebar.tsx +0 -432
- package/dist/registry-data/sidebar/SidebarCollapsible.tsx +0 -77
- package/dist/registry-data/sidebar/SidebarParts.tsx +0 -373
- package/dist/registry-data/sidebar/component.json +0 -47
- package/dist/registry-data/sidebar/index.ts +0 -4
- package/dist/registry-data/sidebar/useSidebar.ts +0 -29
- package/dist/registry-data/styles-base/component.json +0 -19
- package/dist/registry-data/styles-base/index.css +0 -67
- package/dist/registry-data/styles-components/component.json +0 -19
- package/dist/registry-data/styles-components/index.css +0 -30
- package/dist/registry-data/styles-motion/component.json +0 -20
- package/dist/registry-data/styles-motion/index.css +0 -381
- package/dist/registry-data/styles-tokens/component.json +0 -17
- package/dist/registry-data/styles-tokens/index.css +0 -77
- package/dist/registry-data/styles-utilities/component.json +0 -19
- package/dist/registry-data/styles-utilities/index.css +0 -29
- package/dist/registry-data/switch/Switch.tsx +0 -91
- package/dist/registry-data/switch/component.json +0 -34
- package/dist/registry-data/switch/index.ts +0 -1
- package/dist/registry-data/tabs/Tabs.tsx +0 -226
- package/dist/registry-data/tabs/component.json +0 -32
- package/dist/registry-data/tabs/index.ts +0 -1
- package/dist/registry-data/textarea/Textarea.tsx +0 -94
- package/dist/registry-data/textarea/component.json +0 -33
- package/dist/registry-data/textarea/index.ts +0 -1
- package/dist/registry-data/theme-core/component.json +0 -17
- package/dist/registry-data/theme-core/theme.ts +0 -84
- package/dist/registry-data/theme-dark/component.json +0 -19
- package/dist/registry-data/theme-dark/index.ts +0 -7
- package/dist/registry-data/theme-light/component.json +0 -19
- package/dist/registry-data/theme-light/index.ts +0 -7
- package/dist/registry-data/theme-provider/ThemeContext.tsx +0 -177
- package/dist/registry-data/theme-provider/component.json +0 -30
- package/dist/registry-data/theme-provider/index.ts +0 -2
- package/dist/registry-data/theme-selector/ThemeSelector.tsx +0 -269
- package/dist/registry-data/theme-selector/component.json +0 -35
- package/dist/registry-data/theme-selector/selector.ts +0 -1
- package/dist/registry-data/theme-system/component.json +0 -19
- package/dist/registry-data/theme-system/index.ts +0 -7
- package/dist/registry-data/theme-toggle/ThemeToggle.tsx +0 -71
- package/dist/registry-data/theme-toggle/component.json +0 -31
- package/dist/registry-data/theme-toggle/toggle.ts +0 -1
- package/dist/registry-data/toast/Toast.tsx +0 -260
- package/dist/registry-data/toast/ToastTypeIcon.tsx +0 -83
- package/dist/registry-data/toast/component.json +0 -43
- package/dist/registry-data/toast/index.ts +0 -3
- package/dist/registry-data/toast/useToast.ts +0 -47
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { SupportedFramework } from '../constants/index.js';
|
|
2
2
|
export declare const REGISTRY_KINDS: readonly ['component', 'icon', 'theme', 'style', 'utility'];
|
|
3
3
|
export type RegistryKind = (typeof REGISTRY_KINDS)[number];
|
|
4
|
+
/** Destination roots owned by the new namespaced layout. */
|
|
5
|
+
export declare const REGISTRY_ROOTS: readonly ['components', 'themes', 'runtimes'];
|
|
6
|
+
export type RegistryRoot = (typeof REGISTRY_ROOTS)[number];
|
|
7
|
+
export type ExposureMode = 'full' | 'incremental';
|
|
4
8
|
export type RegistryFile = {
|
|
5
9
|
source: string;
|
|
6
10
|
target: string;
|
|
@@ -11,18 +15,32 @@ export type RegistryManifest = {
|
|
|
11
15
|
framework?: SupportedFramework;
|
|
12
16
|
description?: string;
|
|
13
17
|
hidden?: boolean;
|
|
18
|
+
/** Same-registry entries, kept for backwards compatibility. */
|
|
14
19
|
dependencies?: string[];
|
|
20
|
+
/** Qualified `registry:entry` requests; the safe inter-package contract. */
|
|
21
|
+
requires?: string[];
|
|
22
|
+
/** Arbitrary theme names declared by this peer. No special light/dark. */
|
|
23
|
+
themes?: string[];
|
|
24
|
+
/** Revision of this entry, used to tell local drift from registry updates. */
|
|
25
|
+
revision?: number;
|
|
15
26
|
peers?: string[];
|
|
16
27
|
suggestions?: string[];
|
|
17
28
|
files?: RegistryFile[];
|
|
18
29
|
};
|
|
19
30
|
export type RegistryItem = {
|
|
31
|
+
/** Specifier of the package that provides this entry, as written in components.json. */
|
|
32
|
+
registry: string;
|
|
33
|
+
/** Namespace slug declared by `uiRegistryId`; used for qualified names. */
|
|
34
|
+
id: string;
|
|
20
35
|
name: string;
|
|
21
36
|
kind: RegistryKind;
|
|
22
37
|
framework: SupportedFramework;
|
|
23
38
|
description: string;
|
|
24
39
|
hidden: boolean;
|
|
25
40
|
dependencies: string[];
|
|
41
|
+
requires: string[];
|
|
42
|
+
themes: string[];
|
|
43
|
+
revision: number;
|
|
26
44
|
peers: string[];
|
|
27
45
|
suggestions: string[];
|
|
28
46
|
files: RegistryFile[];
|
|
@@ -30,6 +48,19 @@ export type RegistryItem = {
|
|
|
30
48
|
export type ResolvedRegistryItem = RegistryItem & {
|
|
31
49
|
requested: boolean;
|
|
32
50
|
};
|
|
51
|
+
/** A loaded external registry package and the root directory of its entries. */
|
|
52
|
+
export type RegistryProvider = {
|
|
53
|
+
specifier: string;
|
|
54
|
+
packageRoot: string;
|
|
55
|
+
root: string;
|
|
56
|
+
/** Stable namespace declared via `uiRegistryId` in package.json. */
|
|
57
|
+
id: string;
|
|
58
|
+
version: string;
|
|
59
|
+
uiRequires: string[];
|
|
60
|
+
/** Dev-only peers; never written to the consumer's components.json. */
|
|
61
|
+
devRegistries: string[];
|
|
62
|
+
items: RegistryItem[];
|
|
63
|
+
};
|
|
33
64
|
export type CopyResult = {
|
|
34
65
|
copied: string[];
|
|
35
66
|
skipped: string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { install, status, validate } from './ui-api.js';
|
|
2
|
+
export type { InstallResult } from './ui-api.js';
|
|
3
|
+
export type { Lockfile, LockEntry } from '../registry/lockfile.js';
|
|
4
|
+
export type { InstallOptions } from '../types/config.types.js';
|
|
5
|
+
export type { ExposureMode } from '../types/registry.types.js';
|
|
6
|
+
export { install, status, validate };
|
|
7
|
+
/** Materializes specific entries plus their `requires` closure. Build-time only. */
|
|
8
|
+
export declare function ensure(selectors: string[], options?: Parameters<typeof install>[0]): Promise<import("./ui-api.js").InstallResult>;
|
|
9
|
+
/** Materializes every visible entry of every configured registry. Build-time only. */
|
|
10
|
+
export declare function ensureAll(options?: Parameters<typeof install>[0]): Promise<import("./ui-api.js").InstallResult>;
|
|
11
|
+
/** Regenerates the generated barrels without copying any registry files. */
|
|
12
|
+
export declare function sync(options?: {
|
|
13
|
+
cwd?: string;
|
|
14
|
+
dryRun?: boolean;
|
|
15
|
+
globalCss?: string;
|
|
16
|
+
}): Promise<import("../helpers/barrels.helpers.js").BarrelsSyncResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { readConfig, resolveComponentsDir } from '../config/index.js';
|
|
3
|
+
import { CLI_NAME } from '../constants/index.js';
|
|
4
|
+
import { CliError } from '../errors/index.js';
|
|
5
|
+
import { syncBarrels } from '../helpers/barrels.helpers.js';
|
|
6
|
+
import { install, status, validate } from './ui-api.js';
|
|
7
|
+
export { install, status, validate };
|
|
8
|
+
/** Materializes specific entries plus their `requires` closure. Build-time only. */
|
|
9
|
+
export async function ensure(selectors, options = {}) {
|
|
10
|
+
return install({ ...options, selectors, exposure: options.exposure ?? 'incremental' });
|
|
11
|
+
}
|
|
12
|
+
/** Materializes every visible entry of every configured registry. Build-time only. */
|
|
13
|
+
export async function ensureAll(options = {}) {
|
|
14
|
+
return install({ ...options, exposure: options.exposure ?? 'full' });
|
|
15
|
+
}
|
|
16
|
+
/** Regenerates the generated barrels without copying any registry files. */
|
|
17
|
+
export async function sync(options = {}) {
|
|
18
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
19
|
+
const config = await readConfig(cwd);
|
|
20
|
+
if (!config) {
|
|
21
|
+
throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
|
|
22
|
+
}
|
|
23
|
+
return syncBarrels({
|
|
24
|
+
cwd,
|
|
25
|
+
componentsDir: resolveComponentsDir(cwd, config),
|
|
26
|
+
globalCss: options.globalCss,
|
|
27
|
+
themeOrder: config.themeOrder,
|
|
28
|
+
dryRun: options.dryRun
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Lockfile } from '../registry/lockfile.js';
|
|
2
|
+
import type { InstallOptions } from '../types/config.types.js';
|
|
3
|
+
export type InstallResult = {
|
|
4
|
+
added: string[];
|
|
5
|
+
updated: string[];
|
|
6
|
+
kept: string[];
|
|
7
|
+
planned: string[];
|
|
8
|
+
barrels: string[];
|
|
9
|
+
entries: string[];
|
|
10
|
+
};
|
|
11
|
+
/** Single write path: resolve, validate, plan, apply, sync, lock. */
|
|
12
|
+
export declare function install(options?: InstallOptions): Promise<InstallResult>;
|
|
13
|
+
export declare function status(options?: {
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}): Promise<Lockfile>;
|
|
16
|
+
export declare function validate(options?: {
|
|
17
|
+
cwd?: string;
|
|
18
|
+
}): Promise<string[]>;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { copyFile, mkdir, stat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { readConfig, resolveComponentsDir } from '../config/index.js';
|
|
4
|
+
import { CLI_NAME, DEFAULT_EXPOSURE } from '../constants/index.js';
|
|
5
|
+
import { CliError } from '../errors/index.js';
|
|
6
|
+
import { syncBarrels } from '../helpers/barrels.helpers.js';
|
|
7
|
+
import { toDisplayPath } from '../helpers/path.helpers.js';
|
|
8
|
+
import { hashFile, readLockfile, writeLockfile } from '../registry/lockfile.js';
|
|
9
|
+
import { loadRegistryProviders } from '../registry/registry.providers.js';
|
|
10
|
+
import { resolveSelectedComponents } from '../registry/registry.service.js';
|
|
11
|
+
const ALLOWED_ROOTS = ['components', 'themes', 'runtimes'];
|
|
12
|
+
function qualifiedName(item) {
|
|
13
|
+
return `${item.id}:${item.name}`;
|
|
14
|
+
}
|
|
15
|
+
function validateLayout(items) {
|
|
16
|
+
const problems = [];
|
|
17
|
+
for (const item of items) {
|
|
18
|
+
const allowed = ALLOWED_ROOTS.map(root => `${root}/${item.id}/`);
|
|
19
|
+
for (const file of item.files) {
|
|
20
|
+
if (!allowed.some(prefix => file.target.startsWith(prefix))) {
|
|
21
|
+
problems.push(`${qualifiedName(item)} → ${file.target} must start with ${allowed.join(', ')}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return problems;
|
|
26
|
+
}
|
|
27
|
+
async function pathExists(path) {
|
|
28
|
+
try {
|
|
29
|
+
await stat(path);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function planActions(items, componentsDir, lock, force) {
|
|
37
|
+
const actions = [];
|
|
38
|
+
for (const item of items) {
|
|
39
|
+
const key = qualifiedName(item);
|
|
40
|
+
const locked = lock.entries[key];
|
|
41
|
+
for (const file of item.files) {
|
|
42
|
+
const target = join(componentsDir, file.target);
|
|
43
|
+
const sourceHash = await hashFile(file.source);
|
|
44
|
+
const lockedHash = locked?.files[file.target];
|
|
45
|
+
if (!(await pathExists(target))) {
|
|
46
|
+
actions.push({ target, source: file.source, status: 'add' });
|
|
47
|
+
}
|
|
48
|
+
else if (lockedHash === sourceHash) {
|
|
49
|
+
actions.push({ target, source: file.source, status: 'unchanged' });
|
|
50
|
+
}
|
|
51
|
+
else if (force || (lockedHash && (await hashFile(target)) === lockedHash)) {
|
|
52
|
+
actions.push({ target, source: file.source, status: 'update' });
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
actions.push({ target, source: file.source, status: 'keep' });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return actions;
|
|
60
|
+
}
|
|
61
|
+
function buildLock(items, exposure, registries, providers) {
|
|
62
|
+
const entries = {};
|
|
63
|
+
for (const item of items) {
|
|
64
|
+
entries[qualifiedName(item)] = {
|
|
65
|
+
revision: item.revision,
|
|
66
|
+
files: {}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
version: 1,
|
|
71
|
+
exposure,
|
|
72
|
+
registries: Object.fromEntries(providers
|
|
73
|
+
.filter(provider => registries.includes(provider.specifier))
|
|
74
|
+
.map(provider => [provider.specifier, { id: provider.id, version: provider.version }])),
|
|
75
|
+
entries
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function assertFrozen(lock, desired) {
|
|
79
|
+
if (lock.exposure !== desired.exposure) {
|
|
80
|
+
throw new CliError('ui.lock.json is out of date (exposure changed). Run "ui install".');
|
|
81
|
+
}
|
|
82
|
+
const keys = Object.keys(desired.entries).sort().join(',');
|
|
83
|
+
if (Object.keys(lock.entries).sort().join(',') !== keys) {
|
|
84
|
+
throw new CliError('ui.lock.json is out of date (entries changed). Run "ui install".');
|
|
85
|
+
}
|
|
86
|
+
for (const [key, entry] of Object.entries(desired.entries)) {
|
|
87
|
+
const locked = lock.entries[key];
|
|
88
|
+
if (locked?.revision !== entry.revision) {
|
|
89
|
+
throw new CliError(`ui.lock.json is out of date (${key}). Run "ui install".`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Single write path: resolve, validate, plan, apply, sync, lock. */
|
|
94
|
+
export async function install(options = {}) {
|
|
95
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
96
|
+
const config = await readConfig(cwd);
|
|
97
|
+
if (!config) {
|
|
98
|
+
throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
|
|
99
|
+
}
|
|
100
|
+
const componentsDir = resolveComponentsDir(cwd, config, options.componentsDir);
|
|
101
|
+
const registries = options.registries ?? config.registries;
|
|
102
|
+
const exposure = options.exposure ?? config.exposure ?? DEFAULT_EXPOSURE;
|
|
103
|
+
const providers = await loadRegistryProviders(cwd, registries, config.framework);
|
|
104
|
+
const items = providers.flatMap(provider => provider.items);
|
|
105
|
+
const selectors = options.selectors?.length
|
|
106
|
+
? options.selectors
|
|
107
|
+
: exposure === 'full'
|
|
108
|
+
? items.filter(item => !item.hidden).map(qualifiedName)
|
|
109
|
+
: (config.entries ?? []);
|
|
110
|
+
if (selectors.length === 0) {
|
|
111
|
+
throw new CliError(exposure === 'incremental'
|
|
112
|
+
? 'No entries requested. Add "entries" to components.json, use "ui add <entry>", or switch exposure to "full".'
|
|
113
|
+
: 'No entries available in the configured registries.');
|
|
114
|
+
}
|
|
115
|
+
const ordered = await resolveSelectedComponents(selectors, false, {
|
|
116
|
+
cwd,
|
|
117
|
+
registries,
|
|
118
|
+
framework: config.framework
|
|
119
|
+
});
|
|
120
|
+
const problems = validateLayout(ordered);
|
|
121
|
+
if (problems.length > 0) {
|
|
122
|
+
throw new CliError(`Registry layout is invalid:\n - ${problems.join('\n - ')}`);
|
|
123
|
+
}
|
|
124
|
+
const lock = await readLockfile(cwd);
|
|
125
|
+
const desired = buildLock(ordered, exposure, registries, providers);
|
|
126
|
+
for (const item of ordered) {
|
|
127
|
+
desired.entries[qualifiedName(item)].files = Object.fromEntries(await Promise.all(item.files.map(async (file) => [file.target, await hashFile(file.source)])));
|
|
128
|
+
}
|
|
129
|
+
if (options.frozen)
|
|
130
|
+
assertFrozen(lock, desired);
|
|
131
|
+
const actions = await planActions(ordered, componentsDir, lock, Boolean(options.force));
|
|
132
|
+
const result = {
|
|
133
|
+
added: [],
|
|
134
|
+
updated: [],
|
|
135
|
+
kept: [],
|
|
136
|
+
planned: [],
|
|
137
|
+
barrels: [],
|
|
138
|
+
entries: ordered.map(qualifiedName)
|
|
139
|
+
};
|
|
140
|
+
for (const action of actions) {
|
|
141
|
+
const display = toDisplayPath(cwd, action.target);
|
|
142
|
+
if (action.status === 'unchanged')
|
|
143
|
+
continue;
|
|
144
|
+
if (action.status === 'keep') {
|
|
145
|
+
result.kept.push(display);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (options.dryRun) {
|
|
149
|
+
result.planned.push(display);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
await mkdir(dirname(action.target), { recursive: true });
|
|
153
|
+
await copyFile(action.source, action.target);
|
|
154
|
+
if (action.status === 'add')
|
|
155
|
+
result.added.push(display);
|
|
156
|
+
else
|
|
157
|
+
result.updated.push(display);
|
|
158
|
+
}
|
|
159
|
+
if (!options.dryRun) {
|
|
160
|
+
const barrels = await syncBarrels({
|
|
161
|
+
cwd,
|
|
162
|
+
componentsDir,
|
|
163
|
+
globalCss: options.globalCss,
|
|
164
|
+
themeOrder: config.themeOrder
|
|
165
|
+
});
|
|
166
|
+
result.barrels = barrels.barrels.map(path => toDisplayPath(cwd, path));
|
|
167
|
+
await writeLockfile(cwd, desired);
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
export async function status(options = {}) {
|
|
172
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
173
|
+
const lock = await readLockfile(cwd);
|
|
174
|
+
return lock;
|
|
175
|
+
}
|
|
176
|
+
export async function validate(options = {}) {
|
|
177
|
+
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
178
|
+
const config = await readConfig(cwd);
|
|
179
|
+
if (!config) {
|
|
180
|
+
throw new CliError(`components.json not found. Run "${CLI_NAME} init" first.`);
|
|
181
|
+
}
|
|
182
|
+
const providers = await loadRegistryProviders(cwd, config.registries, config.framework);
|
|
183
|
+
const items = providers.flatMap(provider => provider.items);
|
|
184
|
+
const problems = [];
|
|
185
|
+
for (const item of items) {
|
|
186
|
+
const allowed = ALLOWED_ROOTS.map(root => `${root}/${item.id}/`);
|
|
187
|
+
for (const file of item.files) {
|
|
188
|
+
if (!allowed.some(prefix => file.target.startsWith(prefix))) {
|
|
189
|
+
problems.push(`${qualifiedName(item)} → ${file.target}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return problems;
|
|
194
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blankways/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "CLI for
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
|
+
"description": "Build-time API and CLI for composing external UI registries into a project.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"import": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
-
"./cli": "./dist/cli.js"
|
|
15
|
+
"./cli": "./dist/cli.js",
|
|
16
|
+
"./styles.css": "./styles.css"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"styles.css"
|
|
19
21
|
],
|
|
20
22
|
"author": "",
|
|
21
23
|
"license": "ISC",
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
"vitest": "^5.0.5"
|
|
32
34
|
},
|
|
33
35
|
"scripts": {
|
|
34
|
-
"build": "node scripts/clean-dist.mjs && tsc && tsc-alias
|
|
36
|
+
"build": "node scripts/clean-dist.mjs && tsc && tsc-alias",
|
|
35
37
|
"typecheck": "tsc --noEmit && node scripts/validate-registry.mjs",
|
|
36
38
|
"test": "vitest run --passWithNoTests"
|
|
37
39
|
}
|
package/styles.css
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* @blankways/ui base stylesheet. Immutable: import it, never copy it into ui/. */
|
|
2
|
+
:where(*, *::before, *::after) {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
:where(html) {
|
|
7
|
+
-webkit-text-size-adjust: 100%;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
:where(body) {
|
|
11
|
+
margin: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
:where(button, input, textarea, select) {
|
|
15
|
+
font: inherit;
|
|
16
|
+
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# Component registry
|
|
2
|
-
|
|
3
|
-
Cada entrada es una carpeta con un `component.json`. El CLI la copia a `ui/` respetando los `target` del manifiesto.
|
|
4
|
-
|
|
5
|
-
```json
|
|
6
|
-
{
|
|
7
|
-
"name": "button",
|
|
8
|
-
"kind": "component",
|
|
9
|
-
"framework": "react",
|
|
10
|
-
"description": "Native button with shared variants.",
|
|
11
|
-
"hidden": false,
|
|
12
|
-
"dependencies": ["cn", "button-styles"],
|
|
13
|
-
"peers": ["@blankways/state", "@blankways/state-react@0.1.0-alpha.1", "react"],
|
|
14
|
-
"suggestions": ["styles-tokens", "styles-base"],
|
|
15
|
-
"files": [
|
|
16
|
-
{ "source": "Button.tsx", "target": "components/button/Button.tsx" },
|
|
17
|
-
{ "source": "index.ts", "target": "components/button/index.ts" }
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
`source` es relativo a la carpeta de la entrada. `target` es relativo a `componentsDir`, que por defecto es `ui`. `framework` declara la alternativa de UI a la que pertenece la entrada; `init` guarda esa misma alternativa en `components.json` y el CLI filtra el registro por ella. Por ahora solo existe `react`.
|
|
23
|
-
|
|
24
|
-
## Tipos
|
|
25
|
-
|
|
26
|
-
- `component`: componentes React.
|
|
27
|
-
- `icon`: re-exports públicos de `lucide-react`.
|
|
28
|
-
- `theme`: core, provider, toggle, selector y constantes de tema.
|
|
29
|
-
- `style`: archivos CSS con tokens y utilidades de Tailwind v4.
|
|
30
|
-
- `utility`: helpers como `buttonStyles` y `fieldStyles`.
|
|
31
|
-
|
|
32
|
-
Las entradas con `"hidden": true` son internas: no se listan ni se seleccionan directamente con `add`, pero se resuelven como dependencias cuando otra entrada las necesita. `cn` es la entrada interna actual y se copia a `internals/cn.ts`. Los helpers `button-styles` y `field-styles` se copian a `styles/`.
|
|
33
|
-
|
|
34
|
-
## Peers versionados
|
|
35
|
-
|
|
36
|
-
`peers` admite specs con versión, por ejemplo `@blankways/state-react@0.1.0-alpha.1`. `doctor` compara la versión declarada en el `package.json` del proyecto y avisa si falta o no coincide.
|
|
37
|
-
|
|
38
|
-
## Entradas remotas
|
|
39
|
-
|
|
40
|
-
`remote-provider` envuelve `RemoteProvider` y re-exporta `useCall` desde `@blankways/remote-react@0.1.0-alpha.1`.
|
|
41
|
-
|
|
42
|
-
## Themes
|
|
43
|
-
|
|
44
|
-
Los themes son strings abiertos. `theme-core` registra automáticamente `light` y `dark`, pero cualquier entrada puede añadir otro:
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
export const sepiaTheme = 'sepia'
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
El usuario puede pasarlos a `ThemeProvider`:
|
|
51
|
-
|
|
52
|
-
```tsx
|
|
53
|
-
<ThemeProvider themes={['light', 'dark', 'sepia']}>
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
`system` es una preferencia que se resuelve a uno de los themes registrados mediante `systemThemes`.
|
|
57
|
-
|
|
58
|
-
Dependencias entre themes:
|
|
59
|
-
|
|
60
|
-
```text
|
|
61
|
-
theme-light/dark/system → theme-core
|
|
62
|
-
theme-provider → theme-core
|
|
63
|
-
theme-toggle → theme-provider + icons-theme + cn
|
|
64
|
-
theme-selector → theme-provider + icons-form + cn
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Validación
|
|
68
|
-
|
|
69
|
-
`pnpm typecheck` valida el registro con `node scripts/validate-registry.mjs`: comprueba manifiestos, archivos fuente, rutas `target`, dependencias, ciclos e imports relativos como `../icons/form.js` en la disposición que tendrá el usuario. La validación no compila las plantillas, por lo que no requiere React ni sus tipos.
|
|
70
|
-
|
|
71
|
-
Tras cambiar `source/`, ejecuta `pnpm build`.
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
2
|
-
import { State, type StateId } from '@blankways/state'
|
|
3
|
-
import { Show, Text, useCompute, useState } from '@blankways/state-react'
|
|
4
|
-
import { cn } from '../../internals/cn.js'
|
|
5
|
-
|
|
6
|
-
export type AvatarProps = {
|
|
7
|
-
src?: string
|
|
8
|
-
alt?: string
|
|
9
|
-
/** Full name used for the initials when there is no photo. */
|
|
10
|
-
name?: string
|
|
11
|
-
/** Custom text shown instead of calculated initials. */
|
|
12
|
-
fallback?: string
|
|
13
|
-
className?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function initialsOf(label: string) {
|
|
17
|
-
return label
|
|
18
|
-
.split(' ')
|
|
19
|
-
.filter(Boolean)
|
|
20
|
-
.slice(0, 2)
|
|
21
|
-
.map((part) => part[0]?.toUpperCase())
|
|
22
|
-
.join('')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function useSyncedState<Type>(value: Type): StateId<Type> {
|
|
26
|
-
const state = useState(value)
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!Object.is(State.get(state), value)) State.set(state, value)
|
|
29
|
-
}, [state, value])
|
|
30
|
-
return state
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Round avatar: the photo, or the initials on a neutral gradient. */
|
|
34
|
-
export function Avatar({ src, alt, name, fallback, className }: AvatarProps) {
|
|
35
|
-
const label = name ?? fallback ?? alt ?? ''
|
|
36
|
-
const labelState = useSyncedState(label)
|
|
37
|
-
const hasImage = useSyncedState(Boolean(src))
|
|
38
|
-
const hasInitials = useCompute([hasImage] as const, ([present]) => !present)
|
|
39
|
-
const initials = useCompute(
|
|
40
|
-
[labelState] as const,
|
|
41
|
-
([value]) => initialsOf(value) || fallback || '·',
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<span
|
|
46
|
-
className={cn(
|
|
47
|
-
'relative inline-flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-full bg-gradient-to-br from-brand-500 to-brand-300 text-xs font-bold text-[#111111]',
|
|
48
|
-
className,
|
|
49
|
-
)}
|
|
50
|
-
>
|
|
51
|
-
<Show when={hasImage}>
|
|
52
|
-
<img src={src} alt={alt ?? name ?? ''} className="size-full object-cover" />
|
|
53
|
-
</Show>
|
|
54
|
-
<Show when={hasInitials}>
|
|
55
|
-
<span
|
|
56
|
-
aria-hidden="true"
|
|
57
|
-
className="inline-flex size-full items-center justify-center"
|
|
58
|
-
>
|
|
59
|
-
<Text as="span" value={initials} />
|
|
60
|
-
</span>
|
|
61
|
-
</Show>
|
|
62
|
-
</span>
|
|
63
|
-
)
|
|
64
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "avatar",
|
|
3
|
-
"kind": "component",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "Round avatar that falls back to initials on a neutral gradient.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"cn"
|
|
8
|
-
],
|
|
9
|
-
"peers": [
|
|
10
|
-
"@blankways/state",
|
|
11
|
-
"@blankways/state-react@0.1.0-alpha.1",
|
|
12
|
-
"react"
|
|
13
|
-
],
|
|
14
|
-
"suggestions": [
|
|
15
|
-
"styles-tokens",
|
|
16
|
-
"styles-base",
|
|
17
|
-
"styles-components",
|
|
18
|
-
"styles-utilities"
|
|
19
|
-
],
|
|
20
|
-
"files": [
|
|
21
|
-
{
|
|
22
|
-
"source": "Avatar.tsx",
|
|
23
|
-
"target": "components/avatar/Avatar.tsx"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"source": "index.ts",
|
|
27
|
-
"target": "components/avatar/index.ts"
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Avatar, type AvatarProps } from './Avatar.js'
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from 'react'
|
|
2
|
-
import type { ReactNode } from 'react'
|
|
3
|
-
import { State, type StateId } from '@blankways/state'
|
|
4
|
-
import {
|
|
5
|
-
Text,
|
|
6
|
-
useAttributes,
|
|
7
|
-
useMatch,
|
|
8
|
-
useState,
|
|
9
|
-
type ReactiveAttributes,
|
|
10
|
-
} from '@blankways/state-react'
|
|
11
|
-
import { cn } from '../../internals/cn.js'
|
|
12
|
-
|
|
13
|
-
const TONE_CASES = ['default', 'brand', 'success', 'warning', 'danger'] as const
|
|
14
|
-
|
|
15
|
-
export type BadgeTone = (typeof TONE_CASES)[number]
|
|
16
|
-
|
|
17
|
-
export type BadgeProps = {
|
|
18
|
-
children: ReactNode | StateId<string>
|
|
19
|
-
tone?: BadgeTone
|
|
20
|
-
className?: string
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const toneClasses: Record<BadgeTone, string> = {
|
|
24
|
-
default: 'bg-surface-2 text-ink-soft',
|
|
25
|
-
brand: 'bg-accent-soft text-accent-soft-fg',
|
|
26
|
-
success: 'bg-surface-2 text-ink',
|
|
27
|
-
warning: 'bg-ink/10 text-ink',
|
|
28
|
-
danger: 'bg-ink/20 text-ink',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function useSyncedState<Type>(value: Type): StateId<Type> {
|
|
32
|
-
const state = useState(value)
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (!Object.is(State.get(state), value)) State.set(state, value)
|
|
35
|
-
}, [state, value])
|
|
36
|
-
return state
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Small pill for statuses and labels; children may be a reactive text state. */
|
|
40
|
-
export function Badge({ children, tone = 'default', className }: BadgeProps) {
|
|
41
|
-
const toneState = useSyncedState(tone)
|
|
42
|
-
const [isDefault, isBrand, isSuccess, isWarning, isDanger] = useMatch(
|
|
43
|
-
toneState,
|
|
44
|
-
TONE_CASES,
|
|
45
|
-
)
|
|
46
|
-
const ref = useRef<HTMLSpanElement | null>(null)
|
|
47
|
-
const attributes = useMemo<ReactiveAttributes<HTMLSpanElement>>(
|
|
48
|
-
() => ({
|
|
49
|
-
'data-tone': toneState,
|
|
50
|
-
'data-tone-default': isDefault,
|
|
51
|
-
'data-tone-brand': isBrand,
|
|
52
|
-
'data-tone-success': isSuccess,
|
|
53
|
-
'data-tone-warning': isWarning,
|
|
54
|
-
'data-tone-danger': isDanger,
|
|
55
|
-
}),
|
|
56
|
-
[toneState, isDefault, isBrand, isSuccess, isWarning, isDanger],
|
|
57
|
-
)
|
|
58
|
-
useAttributes(ref, attributes)
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<span
|
|
62
|
-
ref={ref}
|
|
63
|
-
className={cn(
|
|
64
|
-
'motion-lift inline-flex items-center rounded-2xl px-[0.469rem] py-[0.188rem] text-[11px] leading-none font-semibold tracking-wide',
|
|
65
|
-
toneClasses[tone],
|
|
66
|
-
className,
|
|
67
|
-
)}
|
|
68
|
-
>
|
|
69
|
-
{typeof children === 'number' ? (
|
|
70
|
-
<Text as="span" value={children as StateId<string>} />
|
|
71
|
-
) : (
|
|
72
|
-
children
|
|
73
|
-
)}
|
|
74
|
-
</span>
|
|
75
|
-
)
|
|
76
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "badge",
|
|
3
|
-
"kind": "component",
|
|
4
|
-
"framework": "react",
|
|
5
|
-
"description": "Compact status pill with reactive tones and optional reactive text.",
|
|
6
|
-
"dependencies": [
|
|
7
|
-
"cn"
|
|
8
|
-
],
|
|
9
|
-
"peers": [
|
|
10
|
-
"@blankways/state",
|
|
11
|
-
"@blankways/state-react@0.1.0-alpha.1",
|
|
12
|
-
"react"
|
|
13
|
-
],
|
|
14
|
-
"suggestions": [
|
|
15
|
-
"styles-tokens",
|
|
16
|
-
"styles-base",
|
|
17
|
-
"styles-components",
|
|
18
|
-
"styles-utilities"
|
|
19
|
-
],
|
|
20
|
-
"files": [
|
|
21
|
-
{
|
|
22
|
-
"source": "Badge.tsx",
|
|
23
|
-
"target": "components/badge/Badge.tsx"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"source": "index.ts",
|
|
27
|
-
"target": "components/badge/index.ts"
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Badge, type BadgeProps, type BadgeTone } from './Badge.js'
|