@glasshome/widget-sdk 1.9.1 → 1.9.2

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.js CHANGED
@@ -1449,7 +1449,7 @@ function Hn() {
1449
1449
  //#region src/version.ts
1450
1450
  var Un = {
1451
1451
  name: "@glasshome/widget-sdk",
1452
- version: "1.9.1",
1452
+ version: "1.9.2",
1453
1453
  description: "SDK for building GlassHome dashboard widgets with SolidJS",
1454
1454
  keywords: [
1455
1455
  "glasshome",
@@ -1510,6 +1510,7 @@ var Un = {
1510
1510
  "@glasshome/ui": "1.3.0",
1511
1511
  "solid-js": "^1.9.11"
1512
1512
  },
1513
+ peerDependenciesMeta: { "@glasshome/ui": { optional: !0 } },
1513
1514
  dependencies: {
1514
1515
  "@glasshome/widget-contract": "0.2.0",
1515
1516
  "@modular-forms/solid": "^0.25.1",
@@ -1521,6 +1522,7 @@ var Un = {
1521
1522
  zod: "^4.1.13"
1522
1523
  },
1523
1524
  devDependencies: {
1525
+ "@glasshome/ui": "1.3.0",
1524
1526
  "@types/bun": "latest",
1525
1527
  "@types/node": "^25.2.2",
1526
1528
  typescript: "^5",
@@ -25,6 +25,12 @@ export declare function runSchemaGuard(args: {
25
25
  * must be bundled, because leaving it external is a runtime 404.
26
26
  */
27
27
  export declare function isWidgetExternal(id: string): boolean;
28
+ /**
29
+ * True when a widget source file imports `@glasshome/sync-layer` directly.
30
+ * Same file filters as `isDirectUiImportSource`: node_modules is the SDK's own
31
+ * business, and non-script assets are not scanned.
32
+ */
33
+ export declare function isDirectSyncLayerImportSource(id: string, code: string): boolean;
28
34
  /**
29
35
  * True when a widget source file imports `@glasshome/ui` directly. The regex is
30
36
  * the registry's `sourcePattern` for `direct-ui-import`, so the build warning and
@@ -129,28 +129,33 @@ function P() {
129
129
  function F(e) {
130
130
  return r(e);
131
131
  }
132
- function I() {
132
+ var I = /\.(ts|tsx|js|jsx)$/, L = /from\s+["']@glasshome\/sync-layer(\/[^"']*)?["']/;
133
+ function R(e, t) {
134
+ let n = N(e).split("?")[0] ?? "";
135
+ return n.includes("/node_modules/") || !I.test(n) ? !1 : L.test(t);
136
+ }
137
+ function z() {
133
138
  return {
134
139
  name: "glasshome-widget:sync-layer-guard",
135
140
  apply: "build",
136
141
  enforce: "pre",
137
- resolveId(e, t) {
138
- if (e === "@glasshome/sync-layer" || e.startsWith("@glasshome/sync-layer/")) throw Error(`Widgets must not import "${e}" directly` + (t ? ` (imported by ${t})` : "") + ". Import the equivalent hook from \"@glasshome/widget-sdk\" instead (e.g. useEntity, useEntities, useService).");
142
+ transform(e, t) {
143
+ if (R(t, e)) throw Error(`Widgets must not import "@glasshome/sync-layer" directly (imported by ${N(_(process.cwd(), t.split("?")[0] ?? t))}). Import the equivalent hook from "@glasshome/widget-sdk" instead (e.g. useEntity, useEntities, useService).`);
144
+ return null;
139
145
  }
140
146
  };
141
147
  }
142
- var L = /\.(ts|tsx|js|jsx)$/;
143
- function R(t, n) {
148
+ function B(t, n) {
144
149
  let r = N(t).split("?")[0] ?? "";
145
- if (r.includes("/node_modules/") || !L.test(r)) return !1;
150
+ if (r.includes("/node_modules/") || !I.test(r)) return !1;
146
151
  let i = e.find((e) => e.id === "direct-ui-import");
147
152
  return i?.sourcePattern ? new RegExp(i.sourcePattern).test(n) : !1;
148
153
  }
149
- function z(e = /* @__PURE__ */ new Set()) {
154
+ function V(e = /* @__PURE__ */ new Set()) {
150
155
  let t = /* @__PURE__ */ new Set();
151
156
  return {
152
157
  scan(e, n) {
153
- R(e, n) && t.add(N(_(process.cwd(), e.split("?")[0] ?? e)));
158
+ B(e, n) && t.add(N(_(process.cwd(), e.split("?")[0] ?? e)));
154
159
  },
155
160
  take() {
156
161
  let n = [...t].filter((t) => !e.has(t));
@@ -159,8 +164,8 @@ function z(e = /* @__PURE__ */ new Set()) {
159
164
  }
160
165
  };
161
166
  }
162
- function B(n) {
163
- let r = z(n);
167
+ function H(n) {
168
+ let r = V(n);
164
169
  return {
165
170
  name: "glasshome-widget:ui-import-guard",
166
171
  apply: "build",
@@ -176,15 +181,15 @@ function B(n) {
176
181
  }
177
182
  };
178
183
  }
179
- var V = "node_modules/.cache/glasshome-widgets";
180
- function H(e) {
184
+ var U = "node_modules/.cache/glasshome-widgets";
185
+ function W(e) {
181
186
  try {
182
187
  return m(g(process.cwd(), "package.json")).resolve(e);
183
188
  } catch {
184
189
  return null;
185
190
  }
186
191
  }
187
- var U = [
192
+ var G = [
188
193
  "--radius",
189
194
  "--background",
190
195
  "--foreground",
@@ -194,21 +199,21 @@ var U = [
194
199
  "--muted",
195
200
  "--accent"
196
201
  ];
197
- function W(e, t) {
202
+ function K(e, t) {
198
203
  let n = g(e, `${t}.css`);
199
204
  if (!s(n)) return;
200
205
  let r = l(n, "utf-8");
201
206
  for (let e of r.matchAll(/:host[^{]*\{([^}]*)\}/g)) {
202
- let n = e[1] ?? "", r = U.find((e) => n.includes(`${e}:`));
207
+ let n = e[1] ?? "", r = G.find((e) => n.includes(`${e}:`));
203
208
  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.`);
204
209
  }
205
210
  }
206
- function G(e, t, n) {
207
- let r = v(e, V);
211
+ function q(e, t, n) {
212
+ let r = v(e, U);
208
213
  c(r, { recursive: !0 });
209
- let i = H("@glasshome/ui/styles");
214
+ let i = W("@glasshome/ui/styles");
210
215
  if (!i) 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.");
211
- let a = v(h(i), "../.."), o = H("@glasshome/widget-sdk/tailwind-sources"), l = o ? h(o) : null, u = [
216
+ let a = v(h(i), "../.."), o = W("@glasshome/widget-sdk/tailwind-sources"), l = o ? h(o) : null, u = [
212
217
  g(a, "src"),
213
218
  g(a, "dist"),
214
219
  ...l ? [g(l, "src"), g(l, "dist")] : [],
@@ -232,12 +237,12 @@ function G(e, t, n) {
232
237
  ""
233
238
  ].join("\n")), f;
234
239
  }
235
- function K() {
240
+ function J() {
236
241
  let e = x();
237
242
  for (let t of e) t.apply ??= "build";
238
243
  return e;
239
244
  }
240
- function q(e) {
245
+ function Y(e) {
241
246
  let t = [];
242
247
  if (!s(e)) return t;
243
248
  for (let n of u(e)) {
@@ -251,7 +256,7 @@ function q(e) {
251
256
  }
252
257
  return t;
253
258
  }
254
- function J(e, t) {
259
+ function X(e, t) {
255
260
  let r = [];
256
261
  if (s(e)) for (let a of u(e)) {
257
262
  if (!f(g(e, a)).isDirectory()) continue;
@@ -274,8 +279,8 @@ function J(e, t) {
274
279
  };
275
280
  s(t) || c(t, { recursive: !0 }), p(g(t, "registry.json"), JSON.stringify(a, null, 2)), console.log(`[registry] Generated registry.json with ${r.length} widget(s)`);
276
281
  }
277
- async function Y(e) {
278
- let { build: t } = await import("vite"), n = process.cwd(), r = v(n, e?.srcDir ?? "src"), i = v(n, e?.outDir ?? "dist"), a = q(r);
282
+ async function Z(e) {
283
+ let { build: t } = await import("vite"), n = process.cwd(), r = v(n, e?.srcDir ?? "src"), i = v(n, e?.outDir ?? "dist"), a = Y(r);
279
284
  if (a.length === 0) {
280
285
  console.warn("[glasshome-widgets] No widgets found in", r);
281
286
  return;
@@ -290,15 +295,15 @@ async function Y(e) {
290
295
  configFile: !1,
291
296
  root: n,
292
297
  plugins: [
293
- ...K(),
298
+ ...J(),
294
299
  ...e?.plugins ?? [],
295
- I(),
296
- B(o)
300
+ z(),
301
+ H(o)
297
302
  ],
298
303
  ...e?.viteConfig,
299
304
  build: {
300
305
  lib: {
301
- entry: G(n, r.name, r.entry),
306
+ entry: q(n, r.name, r.entry),
302
307
  formats: ["es"],
303
308
  fileName: r.name,
304
309
  cssFileName: r.name
@@ -310,15 +315,15 @@ async function Y(e) {
310
315
  ...e?.viteConfig?.build
311
316
  },
312
317
  logLevel: "warn"
313
- }), W(i, r.name), await k({
318
+ }), K(i, r.name), await k({
314
319
  outFile: g(i, `${r.name}.js`),
315
320
  hashFile: g(h(r.entry), ".schema-hash"),
316
321
  widgetName: r.name,
317
322
  manifestPath: g(h(r.entry), "manifest.json")
318
323
  });
319
- J(r, i);
324
+ X(r, i);
320
325
  }
321
- function X(e) {
326
+ function Q(e) {
322
327
  let t = e?.entry ?? "src/index.tsx", n = {
323
328
  name: "glasshome-widget:build",
324
329
  apply: "build",
@@ -326,7 +331,7 @@ function X(e) {
326
331
  let e = process.cwd();
327
332
  return { build: {
328
333
  lib: {
329
- entry: G(e, "index", v(e, t)),
334
+ entry: q(e, "index", v(e, t)),
330
335
  formats: ["es"],
331
336
  fileName: "index",
332
337
  cssFileName: "index"
@@ -372,7 +377,7 @@ function X(e) {
372
377
  name: "glasshome-widget:schema",
373
378
  apply: "build",
374
379
  async closeBundle() {
375
- W(v(process.cwd(), "dist"), "index"), await k({
380
+ K(v(process.cwd(), "dist"), "index"), await k({
376
381
  outFile: v(process.cwd(), "dist", "index.js"),
377
382
  hashFile: v(process.cwd(), ".schema-hash"),
378
383
  widgetName: "index",
@@ -381,15 +386,15 @@ function X(e) {
381
386
  }
382
387
  };
383
388
  return [
384
- ...K(),
389
+ ...J(),
385
390
  n,
386
- I(),
387
- B(),
391
+ z(),
392
+ H(),
388
393
  i,
389
394
  r
390
395
  ];
391
396
  }
392
- function Z(e) {
397
+ function $(e) {
393
398
  let t = e?.srcDir ?? "src", n = e?.outDir ?? "dist", r = [];
394
399
  return [{
395
400
  name: "glasshome-widgets:build",
@@ -408,7 +413,7 @@ function Z(e) {
408
413
  if (e === "\0glasshome-noop") return "export {}";
409
414
  },
410
415
  async closeBundle() {
411
- await Y({
416
+ await Z({
412
417
  srcDir: t,
413
418
  outDir: n,
414
419
  plugins: r
@@ -417,4 +422,4 @@ function Z(e) {
417
422
  }];
418
423
  }
419
424
  //#endregion
420
- export { C as MAX_EXAMPLES, Y as buildWidgets, z as createUiImportTracker, q as discoverWidgets, J as generateRegistry, X as glasshomeWidget, Z as glasshomeWidgets, R as isDirectUiImportSource, F as isWidgetExternal, k as runSchemaGuard };
425
+ export { C as MAX_EXAMPLES, Z as buildWidgets, V as createUiImportTracker, Y as discoverWidgets, X as generateRegistry, Q as glasshomeWidget, $ as glasshomeWidgets, R as isDirectSyncLayerImportSource, B as isDirectUiImportSource, F as isWidgetExternal, k as runSchemaGuard };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/widget-sdk",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "SDK for building GlassHome dashboard widgets with SolidJS",
5
5
  "keywords": [
6
6
  "glasshome",
@@ -61,6 +61,11 @@
61
61
  "@glasshome/ui": "1.3.0",
62
62
  "solid-js": "^1.9.11"
63
63
  },
64
+ "peerDependenciesMeta": {
65
+ "@glasshome/ui": {
66
+ "optional": true
67
+ }
68
+ },
64
69
  "dependencies": {
65
70
  "@glasshome/widget-contract": "0.2.0",
66
71
  "@modular-forms/solid": "^0.25.1",
@@ -72,6 +77,7 @@
72
77
  "zod": "^4.1.13"
73
78
  },
74
79
  "devDependencies": {
80
+ "@glasshome/ui": "1.3.0",
75
81
  "@types/bun": "latest",
76
82
  "@types/node": "^25.2.2",
77
83
  "typescript": "^5",