@webjskit/ui 0.1.0 → 0.2.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/README.md +10 -5
- package/package.json +2 -5
- package/src/commands/add.js +31 -2
package/README.md
CHANGED
|
@@ -20,9 +20,9 @@ function calls, not for a layered React abstraction over every primitive:
|
|
|
20
20
|
`<ui-sonner>`, …). Reserved for the behavior the browser still doesn't
|
|
21
21
|
give you for free: hover-with-delay tooltips, roving-focus keyboard nav
|
|
22
22
|
for menus and tabs, toast queue with stack and dismiss. Dialog and
|
|
23
|
-
alert-dialog
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
alert-dialog wrap the native `<dialog>.showModal()`, so focus trap,
|
|
24
|
+
Escape, and backdrop overlay all come from the platform. Light DOM
|
|
25
|
+
throughout (no shadow DOM); authored children project through `<slot>`.
|
|
26
26
|
|
|
27
27
|
Works with any project that uses Tailwind CSS v4 and supports custom elements:
|
|
28
28
|
webjs, Next, Astro, Vite, SvelteKit, Lit, vanilla HTML, as long as Tailwind
|
|
@@ -30,8 +30,13 @@ is configured, the components render correctly. Variant names, sizes, and
|
|
|
30
30
|
data-attribute conventions mirror shadcn's so an AI agent's existing
|
|
31
31
|
knowledge of shadcn maps directly.
|
|
32
32
|
|
|
33
|
-
Tier-2 elements extend `
|
|
34
|
-
|
|
33
|
+
Tier-2 elements extend `WebComponent` from `@webjskit/core`, a tiny
|
|
34
|
+
Lit-shaped base class with `static properties` for reactive attributes,
|
|
35
|
+
`render()` returning an `` html`...` `` template, and declarative
|
|
36
|
+
bindings (`@click`, `?attr`, `attr=`). Light DOM throughout, so Tailwind
|
|
37
|
+
utility classes on authored children apply directly. The `webjsui add`
|
|
38
|
+
CLI installs `@webjskit/core` automatically when you add a Tier-2
|
|
39
|
+
component.
|
|
35
40
|
|
|
36
41
|
## Install
|
|
37
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webjskit/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "An AI-first component library - class-helper functions for visuals, custom elements only where state matters. Source-copied into your repo, you own it. Works with any Tailwind v4 project.",
|
|
6
6
|
"bin": {
|
|
@@ -44,8 +44,5 @@
|
|
|
44
44
|
"tailwind",
|
|
45
45
|
"components",
|
|
46
46
|
"webjs"
|
|
47
|
-
]
|
|
48
|
-
"engines": {
|
|
49
|
-
"node": ">=24.0.0"
|
|
50
|
-
}
|
|
47
|
+
]
|
|
51
48
|
}
|
package/src/commands/add.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { dirname, join, basename } from 'node:path';
|
|
3
|
+
import { dirname, join, basename, relative as relPath } from 'node:path';
|
|
4
4
|
import prompts from 'prompts';
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { getConfig } from '../utils/get-config.js';
|
|
@@ -70,10 +70,39 @@ async function writeRegistryFile(cwd, config, item, file, opts) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
const content = rewriteUtilsImport(file.content || '', target, config);
|
|
74
|
+
writeFileSync(target, content, 'utf8');
|
|
74
75
|
logger.success(`Wrote ${relative(cwd, target)}`);
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Rewrite the registry-relative `'../lib/utils.ts'` import to the path
|
|
80
|
+
* that resolves correctly from the file's target location to the user's
|
|
81
|
+
* cn() helper.
|
|
82
|
+
*
|
|
83
|
+
* The registry source assumes its own layout (`<registry>/components/<x>.ts`
|
|
84
|
+
* imports `'../lib/utils.ts'`). When that file lands in the user's
|
|
85
|
+
* components/ui/<x>.ts, the literal `'../lib/utils.ts'` resolves to
|
|
86
|
+
* `components/lib/utils.ts`, which doesn't exist. We compute the actual
|
|
87
|
+
* relative path from the target directory to `config.resolvedPaths.utils`
|
|
88
|
+
* (an absolute path the user has already configured via components.json's
|
|
89
|
+
* aliases.utils) and substitute it in.
|
|
90
|
+
*
|
|
91
|
+
* @param {string} content raw file content from the registry
|
|
92
|
+
* @param {string} target absolute path where the file will be written
|
|
93
|
+
* @param {{ resolvedPaths: { utils: string } }} config parsed components.json
|
|
94
|
+
*/
|
|
95
|
+
export function rewriteUtilsImport(content, target, config) {
|
|
96
|
+
if (!content.includes('../lib/utils.ts')) return content;
|
|
97
|
+
const utilsAbs = config?.resolvedPaths?.utils;
|
|
98
|
+
if (!utilsAbs) return content;
|
|
99
|
+
let rel = relPath(dirname(target), utilsAbs).split(/[\\/]/).join('/');
|
|
100
|
+
if (!rel.startsWith('.')) rel = './' + rel;
|
|
101
|
+
return content
|
|
102
|
+
.replaceAll("'../lib/utils.ts'", `'${rel}'`)
|
|
103
|
+
.replaceAll('"../lib/utils.ts"', `"${rel}"`);
|
|
104
|
+
}
|
|
105
|
+
|
|
77
106
|
function resolveTarget(cwd, config, item, file) {
|
|
78
107
|
// explicit `target` wins
|
|
79
108
|
if (file.target) return join(cwd, file.target);
|