@glasshome/widget-sdk 1.5.0 → 1.6.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/dist/index.d.ts +1 -1
- package/dist/index.js +273 -257
- package/dist/types.d.ts +15 -2
- package/dist/vite/index.d.ts +7 -1
- package/dist/vite/index.js +109 -109
- package/package.json +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -7,11 +7,23 @@ export interface GridSize {
|
|
|
7
7
|
w: number;
|
|
8
8
|
h: number;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* A curated showcase state for preview-image generation. Config references
|
|
12
|
+
* demo-fixture entity ids; the preview harness renders it at `size` and
|
|
13
|
+
* screenshots light + dark. `examples[0]` is the thumbnail.
|
|
14
|
+
*
|
|
15
|
+
* @template C - Widget configuration type
|
|
16
|
+
*/
|
|
17
|
+
export interface WidgetExample<C = Record<string, unknown>> {
|
|
18
|
+
config: C;
|
|
19
|
+
size: GridSize;
|
|
20
|
+
label?: string;
|
|
21
|
+
}
|
|
10
22
|
/**
|
|
11
23
|
* Widget manifest — declarative metadata about a widget.
|
|
12
24
|
* Framework-agnostic: no SolidJS imports.
|
|
13
25
|
*/
|
|
14
|
-
export interface WidgetManifest {
|
|
26
|
+
export interface WidgetManifest<C = Record<string, unknown>> {
|
|
15
27
|
name: string;
|
|
16
28
|
description?: string;
|
|
17
29
|
minSize: GridSize;
|
|
@@ -24,6 +36,7 @@ export interface WidgetManifest {
|
|
|
24
36
|
configVersion?: number;
|
|
25
37
|
capabilities?: CapabilityGrant[];
|
|
26
38
|
cssUrl?: string;
|
|
39
|
+
examples?: WidgetExample<C>[];
|
|
27
40
|
}
|
|
28
41
|
/**
|
|
29
42
|
* Runtime context provided to widgets by the host.
|
|
@@ -49,7 +62,7 @@ export interface WidgetContext {
|
|
|
49
62
|
* @template C - Widget configuration type
|
|
50
63
|
*/
|
|
51
64
|
export interface WidgetDefinition<C = Record<string, unknown>> {
|
|
52
|
-
manifest: WidgetManifest
|
|
65
|
+
manifest: WidgetManifest<C>;
|
|
53
66
|
configSchema?: ZodType<C, unknown>;
|
|
54
67
|
migrate?: (config: Record<string, unknown>, fromConfigVersion: number) => Record<string, unknown>;
|
|
55
68
|
component: (props: {
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -3,7 +3,13 @@ export interface GlasshomeWidgetOptions {
|
|
|
3
3
|
/** Entry file for the widget (default: "src/index.tsx") */
|
|
4
4
|
entry?: string;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Packages provided by the host import map — widgets must not bundle these.
|
|
8
|
+
* Delegates to the shared list in @glasshome/widget-contract so the host's
|
|
9
|
+
* import map and the widget build can never disagree again. Exact match only:
|
|
10
|
+
* a specifier the import map does not serve (e.g. "@glasshome/ui/tokens")
|
|
11
|
+
* must be bundled, because leaving it external is a runtime 404.
|
|
12
|
+
*/
|
|
7
13
|
export declare function isWidgetExternal(id: string): boolean;
|
|
8
14
|
interface DiscoveredWidget {
|
|
9
15
|
name: string;
|
package/dist/vite/index.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { formatSchemaError as e,
|
|
2
|
-
import { createHash as
|
|
3
|
-
import { existsSync as
|
|
4
|
-
import { createRequire as
|
|
5
|
-
import { dirname as
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import
|
|
1
|
+
import { formatSchemaError as e, isHostProvidedModule as t, widgetManifestSchema as n } from "@glasshome/widget-contract";
|
|
2
|
+
import { createHash as r } from "node:crypto";
|
|
3
|
+
import { existsSync as i, mkdirSync as a, readFileSync as o, readdirSync as s, rmSync as c, statSync as l, writeFileSync as u } from "node:fs";
|
|
4
|
+
import { createRequire as d } from "node:module";
|
|
5
|
+
import { dirname as f, join as p, resolve as m, sep as h } from "node:path";
|
|
6
|
+
import { fileURLToPath as g } from "node:url";
|
|
7
|
+
import _ from "@tailwindcss/vite";
|
|
8
8
|
//#region src/vite/index.ts
|
|
9
|
-
function
|
|
9
|
+
function v(e) {
|
|
10
10
|
let t = JSON.stringify(e, Object.keys(e).sort());
|
|
11
|
-
return
|
|
11
|
+
return r("sha256").update(t).digest("hex").slice(0, 16);
|
|
12
12
|
}
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
return
|
|
13
|
+
var y = "virtual:glasshome-widget", b = "\0virtual:glasshome-widget", x = "/@glasshome/preview";
|
|
14
|
+
function S(e) {
|
|
15
|
+
return h === "\\" ? e.split(h).join("/") : e;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return
|
|
17
|
+
function C() {
|
|
18
|
+
return m(f(g(import.meta.url)), "../../preview");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
return
|
|
20
|
+
function w(e) {
|
|
21
|
+
return t(e);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function T() {
|
|
24
24
|
return {
|
|
25
25
|
name: "glasshome-widget:sync-layer-guard",
|
|
26
26
|
apply: "build",
|
|
@@ -30,15 +30,15 @@ function w() {
|
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
|
-
var
|
|
34
|
-
function
|
|
33
|
+
var E = "node_modules/.cache/glasshome-widgets";
|
|
34
|
+
function D(e) {
|
|
35
35
|
try {
|
|
36
|
-
return
|
|
36
|
+
return d(p(process.cwd(), "package.json")).resolve(e);
|
|
37
37
|
} catch {
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
var
|
|
41
|
+
var O = [
|
|
42
42
|
"--radius",
|
|
43
43
|
"--background",
|
|
44
44
|
"--foreground",
|
|
@@ -48,124 +48,124 @@ var D = [
|
|
|
48
48
|
"--muted",
|
|
49
49
|
"--accent"
|
|
50
50
|
];
|
|
51
|
-
function
|
|
52
|
-
let n =
|
|
53
|
-
if (!
|
|
54
|
-
let
|
|
55
|
-
for (let e of
|
|
56
|
-
let n = e[1] ?? "", r =
|
|
51
|
+
function k(e, t) {
|
|
52
|
+
let n = p(e, `${t}.css`);
|
|
53
|
+
if (!i(n)) return;
|
|
54
|
+
let r = o(n, "utf-8");
|
|
55
|
+
for (let e of r.matchAll(/:host[^{]*\{([^}]*)\}/g)) {
|
|
56
|
+
let n = e[1] ?? "", r = O.find((e) => n.includes(`${e}:`));
|
|
57
57
|
if (r) throw Error(`[glasshome-widget] "${t}.css" defines theme variable "${r}" on :host. Theme variables must inherit from the document so widgets follow the household theme — never re-scope them into the widget's shadow root.`);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
function
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
let o =
|
|
60
|
+
function A(e, t, n) {
|
|
61
|
+
let r = m(e, E);
|
|
62
|
+
a(r, { recursive: !0 });
|
|
63
|
+
let o = D("@glasshome/ui/styles");
|
|
64
64
|
if (!o) throw Error("[widget-sdk] @glasshome/ui is required to build widgets (it provides the theme every GlassHome widget ships with). Add it to your widget's dependencies.");
|
|
65
|
-
let s =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
...
|
|
69
|
-
|
|
70
|
-
].filter((e) =>
|
|
71
|
-
|
|
65
|
+
let s = m(f(o), "../.."), c = D("@glasshome/widget-sdk/tailwind-sources"), l = c ? f(c) : null, d = [
|
|
66
|
+
p(s, "src"),
|
|
67
|
+
p(s, "dist"),
|
|
68
|
+
...l ? [p(l, "src"), p(l, "dist")] : [],
|
|
69
|
+
f(n)
|
|
70
|
+
].filter((e) => i(e)), h = m(r, `${t}.tailwind.css`);
|
|
71
|
+
u(h, [
|
|
72
72
|
"@import \"tailwindcss\" source(none);",
|
|
73
73
|
"@import \"tw-animate-css\";",
|
|
74
74
|
"@import \"@glasshome/ui/styles/theme\";",
|
|
75
|
-
...
|
|
75
|
+
...d.map((e) => `@source "${S(e)}";`),
|
|
76
76
|
"@custom-variant dark {",
|
|
77
77
|
" &:is(.dark *) { @slot }",
|
|
78
78
|
" :host(.dark) & { @slot }",
|
|
79
79
|
"}",
|
|
80
80
|
""
|
|
81
81
|
].join("\n"));
|
|
82
|
-
let g =
|
|
83
|
-
return
|
|
84
|
-
`import "${
|
|
85
|
-
`export { default } from "${
|
|
82
|
+
let g = m(r, `${t}.entry.ts`);
|
|
83
|
+
return u(g, [
|
|
84
|
+
`import "${S(h)}";`,
|
|
85
|
+
`export { default } from "${S(n)}";`,
|
|
86
86
|
""
|
|
87
87
|
].join("\n")), g;
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
let e =
|
|
89
|
+
function j() {
|
|
90
|
+
let e = _();
|
|
91
91
|
for (let t of e) t.apply ??= "build";
|
|
92
92
|
return e;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function M(e) {
|
|
95
95
|
let t = [];
|
|
96
|
-
if (!
|
|
97
|
-
for (let n of
|
|
98
|
-
let
|
|
99
|
-
if (!
|
|
100
|
-
let a =
|
|
101
|
-
|
|
96
|
+
if (!i(e)) return t;
|
|
97
|
+
for (let n of s(e)) {
|
|
98
|
+
let r = m(e, n);
|
|
99
|
+
if (!l(r).isDirectory()) continue;
|
|
100
|
+
let a = m(r, "index.tsx"), o = m(r, "manifest.json");
|
|
101
|
+
i(a) && i(o) && t.push({
|
|
102
102
|
name: n,
|
|
103
103
|
entry: a
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
return t;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
111
|
-
if (!
|
|
112
|
-
let
|
|
113
|
-
if (!
|
|
114
|
-
let
|
|
115
|
-
if (!
|
|
116
|
-
let d =
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
bundleUrl: `./${
|
|
120
|
-
...d ? { cssUrl: `./${
|
|
108
|
+
function N(t, r) {
|
|
109
|
+
let c = [];
|
|
110
|
+
if (i(t)) for (let a of s(t)) {
|
|
111
|
+
if (!l(p(t, a)).isDirectory()) continue;
|
|
112
|
+
let s = p(t, a, "manifest.json");
|
|
113
|
+
if (!i(s)) continue;
|
|
114
|
+
let u = n.safeParse(JSON.parse(o(s, "utf-8")));
|
|
115
|
+
if (!u.success) throw Error(`[registry] Invalid manifest for "${a}": ${e(u.error)}`);
|
|
116
|
+
let d = i(p(r, `${a}.css`));
|
|
117
|
+
c.push({
|
|
118
|
+
...u.data,
|
|
119
|
+
bundleUrl: `./${a}.js`,
|
|
120
|
+
...d ? { cssUrl: `./${a}.css` } : {}
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
let d = {
|
|
124
124
|
version: 1,
|
|
125
125
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
126
126
|
baseUrl: "./",
|
|
127
|
-
widgets:
|
|
127
|
+
widgets: c
|
|
128
128
|
};
|
|
129
|
-
r
|
|
129
|
+
i(r) || a(r, { recursive: !0 }), u(p(r, "registry.json"), JSON.stringify(d, null, 2)), console.log(`[registry] Generated registry.json with ${c.length} widget(s)`);
|
|
130
130
|
}
|
|
131
|
-
async function
|
|
132
|
-
let { build: t } = await import("vite"), n = process.cwd(),
|
|
133
|
-
if (
|
|
134
|
-
console.warn("[glasshome-widgets] No widgets found in",
|
|
131
|
+
async function P(e) {
|
|
132
|
+
let { build: t } = await import("vite"), n = process.cwd(), r = m(n, e?.srcDir ?? "src"), o = m(n, e?.outDir ?? "dist"), s = M(r);
|
|
133
|
+
if (s.length === 0) {
|
|
134
|
+
console.warn("[glasshome-widgets] No widgets found in", r);
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
137
|
if (e?.only) {
|
|
138
138
|
let t = new Set(e.only);
|
|
139
|
-
|
|
139
|
+
s = s.filter((e) => t.has(e.name));
|
|
140
140
|
}
|
|
141
|
-
e?.only ||
|
|
142
|
-
for (let r of
|
|
141
|
+
e?.only || i(o) && c(o, { recursive: !0 }), i(o) || a(o, { recursive: !0 });
|
|
142
|
+
for (let r of s) await t({
|
|
143
143
|
configFile: !1,
|
|
144
144
|
root: n,
|
|
145
145
|
plugins: [
|
|
146
|
-
...
|
|
146
|
+
...j(),
|
|
147
147
|
...e?.plugins ?? [],
|
|
148
|
-
|
|
148
|
+
T()
|
|
149
149
|
],
|
|
150
150
|
...e?.viteConfig,
|
|
151
151
|
build: {
|
|
152
152
|
lib: {
|
|
153
|
-
entry:
|
|
153
|
+
entry: A(n, r.name, r.entry),
|
|
154
154
|
formats: ["es"],
|
|
155
155
|
fileName: r.name,
|
|
156
156
|
cssFileName: r.name
|
|
157
157
|
},
|
|
158
|
-
rollupOptions: { external:
|
|
158
|
+
rollupOptions: { external: w },
|
|
159
159
|
outDir: o,
|
|
160
160
|
emptyOutDir: !1,
|
|
161
161
|
copyPublicDir: !1,
|
|
162
162
|
...e?.viteConfig?.build
|
|
163
163
|
},
|
|
164
164
|
logLevel: "warn"
|
|
165
|
-
}),
|
|
166
|
-
|
|
165
|
+
}), k(o, r.name);
|
|
166
|
+
N(r, o);
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function F(e) {
|
|
169
169
|
let t = e?.entry ?? "src/index.tsx", n = {
|
|
170
170
|
name: "glasshome-widget:build",
|
|
171
171
|
apply: "build",
|
|
@@ -173,31 +173,31 @@ function P(e) {
|
|
|
173
173
|
let e = process.cwd();
|
|
174
174
|
return { build: {
|
|
175
175
|
lib: {
|
|
176
|
-
entry:
|
|
176
|
+
entry: A(e, "index", m(e, t)),
|
|
177
177
|
formats: ["es"],
|
|
178
178
|
fileName: "index",
|
|
179
179
|
cssFileName: "index"
|
|
180
180
|
},
|
|
181
|
-
rollupOptions: { external:
|
|
181
|
+
rollupOptions: { external: w }
|
|
182
182
|
} };
|
|
183
183
|
}
|
|
184
|
-
},
|
|
184
|
+
}, r = {
|
|
185
185
|
name: "glasshome-widget:dev",
|
|
186
186
|
apply: "serve",
|
|
187
187
|
enforce: "pre",
|
|
188
188
|
config() {
|
|
189
|
-
let e =
|
|
189
|
+
let e = C(), t = process.cwd();
|
|
190
190
|
return { server: { fs: { allow: [
|
|
191
191
|
e,
|
|
192
192
|
t,
|
|
193
|
-
|
|
193
|
+
m(t, "..", "..")
|
|
194
194
|
] } } };
|
|
195
195
|
},
|
|
196
196
|
configureServer(e) {
|
|
197
|
-
let t =
|
|
197
|
+
let t = p(C(), "preview.html");
|
|
198
198
|
e.middlewares.use(async (n, r, i) => {
|
|
199
199
|
if (n.url === "/" || n.url === "/index.html") try {
|
|
200
|
-
let i =
|
|
200
|
+
let i = o(t, "utf-8");
|
|
201
201
|
i = await e.transformIndexHtml(n.url, i), r.setHeader("Content-Type", "text/html"), r.statusCode = 200, r.end(i);
|
|
202
202
|
} catch (e) {
|
|
203
203
|
i(e);
|
|
@@ -206,44 +206,44 @@ function P(e) {
|
|
|
206
206
|
});
|
|
207
207
|
},
|
|
208
208
|
resolveId(e) {
|
|
209
|
-
if (e ===
|
|
210
|
-
if (e ===
|
|
209
|
+
if (e === x) return S(p(C(), "host.tsx"));
|
|
210
|
+
if (e === y) return b;
|
|
211
211
|
},
|
|
212
212
|
load(e) {
|
|
213
|
-
if (e ===
|
|
213
|
+
if (e === b) return `export { default } from "${S(m(process.cwd(), t))}";`;
|
|
214
214
|
}
|
|
215
|
-
},
|
|
215
|
+
}, a = {
|
|
216
216
|
name: "glasshome-widget:schema",
|
|
217
217
|
apply: "build",
|
|
218
218
|
async closeBundle() {
|
|
219
|
-
|
|
220
|
-
let e =
|
|
221
|
-
if (
|
|
219
|
+
k(m(process.cwd(), "dist"), "index");
|
|
220
|
+
let e = m(process.cwd(), "dist", "index.js");
|
|
221
|
+
if (i(e)) try {
|
|
222
222
|
let t = (await import(`${e}?t=${Date.now()}`)).default;
|
|
223
223
|
if (!t?.configSchema) return;
|
|
224
|
-
let { z: n } = await import("zod"),
|
|
225
|
-
if (
|
|
226
|
-
let e = JSON.parse(a
|
|
227
|
-
e.schema =
|
|
224
|
+
let { z: n } = await import("zod"), r = n.toJSONSchema(t.configSchema, { unrepresentable: "any" }), a = m(process.cwd(), "manifest.json");
|
|
225
|
+
if (i(a)) {
|
|
226
|
+
let e = JSON.parse(o(a, "utf-8"));
|
|
227
|
+
e.schema = r, u(a, JSON.stringify(e, null, 2));
|
|
228
228
|
}
|
|
229
|
-
let s =
|
|
230
|
-
if (
|
|
229
|
+
let s = v(r), c = m(process.cwd(), ".schema-hash");
|
|
230
|
+
if (i(c) && o(c, "utf-8").trim() !== s) {
|
|
231
231
|
let e = t.manifest?.name ?? "unknown";
|
|
232
232
|
console.warn(`[widget-sdk] Schema shape changed for "${e}" — verify configVersion was bumped`);
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
u(c, s);
|
|
235
235
|
} catch {}
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
return [
|
|
239
|
-
...
|
|
239
|
+
...j(),
|
|
240
240
|
n,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
T(),
|
|
242
|
+
a,
|
|
243
|
+
r
|
|
244
244
|
];
|
|
245
245
|
}
|
|
246
|
-
function
|
|
246
|
+
function I(e) {
|
|
247
247
|
let t = e?.srcDir ?? "src", n = e?.outDir ?? "dist", r = [];
|
|
248
248
|
return [{
|
|
249
249
|
name: "glasshome-widgets:build",
|
|
@@ -262,7 +262,7 @@ function F(e) {
|
|
|
262
262
|
if (e === "\0glasshome-noop") return "export {}";
|
|
263
263
|
},
|
|
264
264
|
async closeBundle() {
|
|
265
|
-
await
|
|
265
|
+
await P({
|
|
266
266
|
srcDir: t,
|
|
267
267
|
outDir: n,
|
|
268
268
|
plugins: r
|
|
@@ -271,4 +271,4 @@ function F(e) {
|
|
|
271
271
|
}];
|
|
272
272
|
}
|
|
273
273
|
//#endregion
|
|
274
|
-
export {
|
|
274
|
+
export { P as buildWidgets, M as discoverWidgets, N as generateRegistry, F as glasshomeWidget, I as glasshomeWidgets, w as isWidgetExternal };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glasshome/widget-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "SDK for building GlassHome dashboard widgets with SolidJS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"glasshome",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"typecheck:test": "tsc --noEmit -p tsconfig.test.json"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@glasshome/sync-layer": "0.
|
|
55
|
+
"@glasshome/sync-layer": "0.4.0",
|
|
56
56
|
"solid-js": "^1.9.11"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@glasshome/widget-contract": "0.
|
|
59
|
+
"@glasshome/widget-contract": "0.2.0",
|
|
60
60
|
"@modular-forms/solid": "^0.25.1",
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
62
|
"tailwind-merge": "^3.5.0",
|