@glasshome/widget-sdk 1.0.0 → 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 CHANGED
@@ -7,4 +7,5 @@
7
7
  */
8
8
  export { getForecasts, getStream, getWebRtcClientConfig, sendWebRtcCandidate, startWebRtcSession, state, trackEntityHistory, untrackEntityHistory, } from "@glasshome/sync-layer";
9
9
  export type { AreaView } from "@glasshome/sync-layer";
10
- export { byDomain, useArea, useCamera, useConnection, useCurrency, useEntities, useEntity, useEntityHistory, useEntityStatistics, useForecast, useHassConfig, useLocale, useService, useStore, useTemperatureUnit, useToggle, useTurnOn, useUnitSystem, } from "@glasshome/sync-layer/solid";
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";