@glasshome/widget-sdk 0.5.2 → 1.1.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/dist/data.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Home Assistant data and service hooks, re-exported from
3
+ * @glasshome/sync-layer. Widgets must import these from the SDK instead of
4
+ * sync-layer directly: the single store instance lives in the host (via the
5
+ * import map), and a direct import would bundle a second, disconnected
6
+ * store. Phase 4 routes these through capability checks.
7
+ */
8
+ export { getForecasts, getStream, getWebRtcClientConfig, sendWebRtcCandidate, startWebRtcSession, state, trackEntityHistory, untrackEntityHistory, } from "@glasshome/sync-layer";
9
+ export type { AreaView } from "@glasshome/sync-layer";
10
+ export { byDomain, useArea, useCamera, useConnection, useCurrency, useEntities, useEntity, useEntityHistory, useEntityStatistics, useForecast, useHassConfig, useLocale, useStore, useTemperatureUnit, useUnitSystem, } from "@glasshome/sync-layer/solid";
11
+ export { useService, useToggle, useTurnOff, useTurnOn } from "./framework/hooks/use-service";
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Hooks for widget development: context, dialog, entity group.
5
5
  */
6
- export { type ReactiveWidgetContext, useWidgetContext, WidgetCtx, } from "./use-widget-context";
6
+ export { type ReactiveWidgetContext, type ServiceCallFn, useWidgetContext, WidgetCtx, } from "./use-widget-context";
7
7
  export { useIntersectionPause } from "./use-intersection-pause";
8
8
  export { useReducedMotion } from "./use-reduced-motion";
9
9
  export { useWidgetDialog, type WidgetDialogReturn } from "./use-widget-dialog";
@@ -0,0 +1,11 @@
1
+ import { useToggle as useDirectToggle, useTurnOff as useDirectTurnOff, useTurnOn as useDirectTurnOn } from "@glasshome/sync-layer/solid";
2
+ import { type ServiceCallFn } from "./use-widget-context";
3
+ export declare function useService(): {
4
+ callService: ServiceCallFn;
5
+ turnOn: ReturnType<typeof useDirectTurnOn>;
6
+ turnOff: ReturnType<typeof useDirectTurnOff>;
7
+ toggle: ReturnType<typeof useDirectToggle>;
8
+ };
9
+ export declare function useTurnOn(): ReturnType<typeof useDirectTurnOn>;
10
+ export declare function useTurnOff(): ReturnType<typeof useDirectTurnOff>;
11
+ export declare function useToggle(): ReturnType<typeof useDirectToggle>;
@@ -15,6 +15,9 @@ export interface WidgetDimensions {
15
15
  width: number;
16
16
  height: number;
17
17
  }
18
+ /** Capability-routed service call: an RPC into the host's HA bridge worker,
19
+ validated there against the widget's granted capabilities. */
20
+ export type ServiceCallFn = (domain: string, service: string, serviceData?: Record<string, unknown>, target?: Record<string, unknown>) => Promise<void>;
18
21
  export interface ReactiveWidgetContext {
19
22
  isEditMode: () => boolean;
20
23
  updateConfig: (config: Record<string, unknown>) => void;
@@ -23,6 +26,9 @@ export interface ReactiveWidgetContext {
23
26
  /** Host RPC: `useWidgetDialog` registers its opener here so the host can
24
27
  open the widget's dialog on a chosen tab. Called with `null` on cleanup. */
25
28
  registerDialogOpener?: (open: ((tab?: string) => void) | null) => void;
29
+ /** Present when the host mounts the widget; the service hooks route
30
+ through it. Absent in previews/tests (direct sync-layer fallback). */
31
+ callService?: ServiceCallFn;
26
32
  }
27
33
  export declare const WidgetCtx: import("solid-js").Context<ReactiveWidgetContext | undefined>;
28
34
  export declare function useWidgetContext(): ReactiveWidgetContext;
@@ -37,7 +37,7 @@ export { WidgetTitle } from "./components/WidgetTitle";
37
37
  export { WidgetValue } from "./components/WidgetValue";
38
38
  export { WidgetSliderFill } from "./backgrounds/WidgetSliderFill";
39
39
  export { WidgetDialog, type WidgetDialogProps, type WidgetDialogTab } from "./dialogs";
40
- export { type AggregationPreset, type ReactiveWidgetContext, type UseWidgetEntityGroupOptions, type UseWidgetEntityGroupResult, useIntersectionPause, useReducedMotion, useWidgetContext, useWidgetDialog, useWidgetEntityGroup, WidgetCtx, type WidgetDialogReturn, } from "./hooks";
40
+ export { type AggregationPreset, type ReactiveWidgetContext, type ServiceCallFn, type UseWidgetEntityGroupOptions, type UseWidgetEntityGroupResult, useIntersectionPause, useReducedMotion, useWidgetContext, useWidgetDialog, useWidgetEntityGroup, WidgetCtx, type WidgetDialogReturn, } from "./hooks";
41
41
  export { type GestureHandlers, useWidgetGestures } from "./gestures/use-widget-gestures";
42
42
  export { injectTokens, type SvgColorKey, svgColors, type Tone, ToneSchema, } from "./theming";
43
43
  export { widgetFields } from "./fields";
@@ -2,7 +2,7 @@
2
2
  * Minimal document-shape needed for token injection. Allows tests to pass
3
3
  * a stub without a full DOM implementation.
4
4
  */
5
- interface InjectTokensRoot {
5
+ export interface InjectTokensRoot {
6
6
  head: {
7
7
  appendChild: (node: unknown) => void;
8
8
  querySelector?: (sel: string) => unknown;
@@ -13,12 +13,17 @@ interface InjectTokensRoot {
13
13
  };
14
14
  }
15
15
  /**
16
- * Inject the SDK tokens stylesheet into <head>. Idempotent across:
16
+ * Inject the SDK tokens stylesheet into the widget's root.
17
+ *
18
+ * ShadowRoot: adopts a shared constructed CSSStyleSheet (one instance for
19
+ * all widget shadow roots), idempotent per root via WeakSet.
20
+ *
21
+ * Document (or no argument, legacy): appends a <style> to <head>.
22
+ * Idempotent across:
17
23
  * - Repeated calls within the same module instance (boolean sentinel).
18
24
  * - Multiple SDK module instances (DOM sentinel data-glasshome-tokens).
19
25
  * - SSR / non-browser environments (no-op when document is undefined).
20
26
  */
21
- export declare function injectTokens(doc?: InjectTokensRoot): void;
27
+ export declare function injectTokens(root?: Document | ShadowRoot): void;
22
28
  /** Test-only: reset the module-level sentinel. Not exported from the package root. */
23
29
  export declare function __resetInjectedForTests(): void;
24
- export {};
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { defineWidget } from "./define-widget";
2
+ export * from "./data";
2
3
  export * from "./framework";
3
4
  export { monotoneCubicPath } from "./shared/spline";
4
5
  export { formatSchemaError, WidgetManifestSchema } from "./schemas";