@glasshome/widget-sdk 1.27.1 → 1.29.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 +2 -0
- package/dist/export-history.json +290 -0
- package/dist/framework/hooks/index.d.ts +3 -1
- package/dist/framework/hooks/use-widget-context.d.ts +11 -0
- package/dist/framework/hooks/use-widget-state.d.ts +10 -0
- package/dist/framework/index.d.ts +1 -1
- package/dist/framework/panel/panel-entity.d.ts +1 -0
- package/dist/framework/panel/panel.d.ts +1 -1
- package/dist/index.js +1018 -788
- package/guide/widgets.md +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ export default defineWidget({
|
|
|
38
38
|
});
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
Small values a widget keeps across reloads (recent picks, the last tab) go through `useWidgetState(key, schema, fallback)`, kept by the host for this widget and this person. `localStorage` is in memory and empty after a reload.
|
|
42
|
+
|
|
41
43
|
### `@glasshome/widget-sdk/vite` — Vite Plugin
|
|
42
44
|
|
|
43
45
|
Vite plugin for widget development. Handles widget bundling, preview server, and registry generation.
|
package/dist/export-history.json
CHANGED
|
@@ -5710,5 +5710,295 @@
|
|
|
5710
5710
|
"useWidgetViewer",
|
|
5711
5711
|
"widgetFields",
|
|
5712
5712
|
"z"
|
|
5713
|
+
],
|
|
5714
|
+
"1.28.0": [
|
|
5715
|
+
"Badge",
|
|
5716
|
+
"Button",
|
|
5717
|
+
"ButtonGroup",
|
|
5718
|
+
"Carousel",
|
|
5719
|
+
"CarouselContent",
|
|
5720
|
+
"CarouselDots",
|
|
5721
|
+
"CarouselItem",
|
|
5722
|
+
"CarouselNext",
|
|
5723
|
+
"CarouselPrevious",
|
|
5724
|
+
"ColorDisc",
|
|
5725
|
+
"ColorSlider",
|
|
5726
|
+
"ColorWheel",
|
|
5727
|
+
"CountPill",
|
|
5728
|
+
"Icon",
|
|
5729
|
+
"Input",
|
|
5730
|
+
"Label",
|
|
5731
|
+
"PanelEntityRow",
|
|
5732
|
+
"PanelFacts",
|
|
5733
|
+
"PanelRow",
|
|
5734
|
+
"PanelRows",
|
|
5735
|
+
"PanelSection",
|
|
5736
|
+
"Progress",
|
|
5737
|
+
"ResponsiveDialog",
|
|
5738
|
+
"ResponsiveDialogBody",
|
|
5739
|
+
"ResponsiveDialogClose",
|
|
5740
|
+
"ResponsiveDialogContent",
|
|
5741
|
+
"ResponsiveDialogDescription",
|
|
5742
|
+
"ResponsiveDialogFooter",
|
|
5743
|
+
"ResponsiveDialogHeader",
|
|
5744
|
+
"ResponsiveDialogTitle",
|
|
5745
|
+
"SDK_VERSION",
|
|
5746
|
+
"SchemaForm",
|
|
5747
|
+
"SectionIcon",
|
|
5748
|
+
"SectionTitle",
|
|
5749
|
+
"Select",
|
|
5750
|
+
"SelectContent",
|
|
5751
|
+
"SelectItem",
|
|
5752
|
+
"SelectTrigger",
|
|
5753
|
+
"SelectValue",
|
|
5754
|
+
"Slider",
|
|
5755
|
+
"SwatchPicker",
|
|
5756
|
+
"Switch",
|
|
5757
|
+
"Tabs",
|
|
5758
|
+
"TabsContent",
|
|
5759
|
+
"TabsList",
|
|
5760
|
+
"TabsTrigger",
|
|
5761
|
+
"TemperatureBar",
|
|
5762
|
+
"Toggle",
|
|
5763
|
+
"ToggleGroup",
|
|
5764
|
+
"ToggleGroupItem",
|
|
5765
|
+
"ToneSchema",
|
|
5766
|
+
"Widget",
|
|
5767
|
+
"WidgetAction",
|
|
5768
|
+
"WidgetBackdrop",
|
|
5769
|
+
"WidgetChip",
|
|
5770
|
+
"WidgetChoice",
|
|
5771
|
+
"WidgetContent",
|
|
5772
|
+
"WidgetControls",
|
|
5773
|
+
"WidgetCtx",
|
|
5774
|
+
"WidgetDebugTab",
|
|
5775
|
+
"WidgetDebugView",
|
|
5776
|
+
"WidgetDialog",
|
|
5777
|
+
"WidgetGlyph",
|
|
5778
|
+
"WidgetHead",
|
|
5779
|
+
"WidgetHero",
|
|
5780
|
+
"WidgetIcon",
|
|
5781
|
+
"WidgetLayer",
|
|
5782
|
+
"WidgetManifestSchema",
|
|
5783
|
+
"WidgetSizeCtx",
|
|
5784
|
+
"WidgetSliderFill",
|
|
5785
|
+
"WidgetStatus",
|
|
5786
|
+
"WidgetStepper",
|
|
5787
|
+
"WidgetTitle",
|
|
5788
|
+
"WidgetValue",
|
|
5789
|
+
"buildDebugData",
|
|
5790
|
+
"byDomain",
|
|
5791
|
+
"calculateLightGroup",
|
|
5792
|
+
"calculateSensorGroup",
|
|
5793
|
+
"copyText",
|
|
5794
|
+
"countActiveEntities",
|
|
5795
|
+
"defineConfig",
|
|
5796
|
+
"defineWidget",
|
|
5797
|
+
"deprecations",
|
|
5798
|
+
"field",
|
|
5799
|
+
"formatDeprecation",
|
|
5800
|
+
"formatSchemaError",
|
|
5801
|
+
"getEntityAttribute",
|
|
5802
|
+
"getForecasts",
|
|
5803
|
+
"getStream",
|
|
5804
|
+
"getWebRtcClientConfig",
|
|
5805
|
+
"hassMediaUrl",
|
|
5806
|
+
"imagePreset",
|
|
5807
|
+
"imageSrc",
|
|
5808
|
+
"imageUrl",
|
|
5809
|
+
"injectTokens",
|
|
5810
|
+
"isDark",
|
|
5811
|
+
"isEntityActive",
|
|
5812
|
+
"isPanelControllable",
|
|
5813
|
+
"mediaUrl",
|
|
5814
|
+
"monotoneCubicPath",
|
|
5815
|
+
"parseColor",
|
|
5816
|
+
"presetValue",
|
|
5817
|
+
"sendWebRtcCandidate",
|
|
5818
|
+
"startWebRtcSession",
|
|
5819
|
+
"state",
|
|
5820
|
+
"svgColors",
|
|
5821
|
+
"trackEntityHistory",
|
|
5822
|
+
"untrackEntityHistory",
|
|
5823
|
+
"useArea",
|
|
5824
|
+
"useCalendarEvents",
|
|
5825
|
+
"useCamera",
|
|
5826
|
+
"useConfirm",
|
|
5827
|
+
"useConnection",
|
|
5828
|
+
"useCopyText",
|
|
5829
|
+
"useCurrency",
|
|
5830
|
+
"useDaylight",
|
|
5831
|
+
"useEntities",
|
|
5832
|
+
"useEntity",
|
|
5833
|
+
"useEntityHistory",
|
|
5834
|
+
"useEntityStatistics",
|
|
5835
|
+
"useForecast",
|
|
5836
|
+
"useHassConfig",
|
|
5837
|
+
"useIntersectionPause",
|
|
5838
|
+
"useLocale",
|
|
5839
|
+
"useMaterial",
|
|
5840
|
+
"useReducedMotion",
|
|
5841
|
+
"useService",
|
|
5842
|
+
"useStore",
|
|
5843
|
+
"useTemperatureUnit",
|
|
5844
|
+
"useToggle",
|
|
5845
|
+
"useTurnOff",
|
|
5846
|
+
"useTurnOn",
|
|
5847
|
+
"useUnitSystem",
|
|
5848
|
+
"useWidgetContext",
|
|
5849
|
+
"useWidgetDashboard",
|
|
5850
|
+
"useWidgetDialog",
|
|
5851
|
+
"useWidgetDimensions",
|
|
5852
|
+
"useWidgetEntityGroup",
|
|
5853
|
+
"useWidgetGestures",
|
|
5854
|
+
"useWidgetState",
|
|
5855
|
+
"useWidgetViewer",
|
|
5856
|
+
"widgetFields",
|
|
5857
|
+
"z"
|
|
5858
|
+
],
|
|
5859
|
+
"1.29.0": [
|
|
5860
|
+
"Badge",
|
|
5861
|
+
"Button",
|
|
5862
|
+
"ButtonGroup",
|
|
5863
|
+
"Carousel",
|
|
5864
|
+
"CarouselContent",
|
|
5865
|
+
"CarouselDots",
|
|
5866
|
+
"CarouselItem",
|
|
5867
|
+
"CarouselNext",
|
|
5868
|
+
"CarouselPrevious",
|
|
5869
|
+
"ColorDisc",
|
|
5870
|
+
"ColorSlider",
|
|
5871
|
+
"ColorWheel",
|
|
5872
|
+
"CountPill",
|
|
5873
|
+
"Icon",
|
|
5874
|
+
"Input",
|
|
5875
|
+
"Label",
|
|
5876
|
+
"PanelEntityRow",
|
|
5877
|
+
"PanelFacts",
|
|
5878
|
+
"PanelRow",
|
|
5879
|
+
"PanelRows",
|
|
5880
|
+
"PanelSection",
|
|
5881
|
+
"Progress",
|
|
5882
|
+
"ResponsiveDialog",
|
|
5883
|
+
"ResponsiveDialogBody",
|
|
5884
|
+
"ResponsiveDialogClose",
|
|
5885
|
+
"ResponsiveDialogContent",
|
|
5886
|
+
"ResponsiveDialogDescription",
|
|
5887
|
+
"ResponsiveDialogFooter",
|
|
5888
|
+
"ResponsiveDialogHeader",
|
|
5889
|
+
"ResponsiveDialogTitle",
|
|
5890
|
+
"SDK_VERSION",
|
|
5891
|
+
"SchemaForm",
|
|
5892
|
+
"SectionIcon",
|
|
5893
|
+
"SectionTitle",
|
|
5894
|
+
"Select",
|
|
5895
|
+
"SelectContent",
|
|
5896
|
+
"SelectItem",
|
|
5897
|
+
"SelectTrigger",
|
|
5898
|
+
"SelectValue",
|
|
5899
|
+
"Slider",
|
|
5900
|
+
"SwatchPicker",
|
|
5901
|
+
"Switch",
|
|
5902
|
+
"Tabs",
|
|
5903
|
+
"TabsContent",
|
|
5904
|
+
"TabsList",
|
|
5905
|
+
"TabsTrigger",
|
|
5906
|
+
"TemperatureBar",
|
|
5907
|
+
"Toggle",
|
|
5908
|
+
"ToggleGroup",
|
|
5909
|
+
"ToggleGroupItem",
|
|
5910
|
+
"ToneSchema",
|
|
5911
|
+
"Widget",
|
|
5912
|
+
"WidgetAction",
|
|
5913
|
+
"WidgetBackdrop",
|
|
5914
|
+
"WidgetChip",
|
|
5915
|
+
"WidgetChoice",
|
|
5916
|
+
"WidgetContent",
|
|
5917
|
+
"WidgetControls",
|
|
5918
|
+
"WidgetCtx",
|
|
5919
|
+
"WidgetDebugTab",
|
|
5920
|
+
"WidgetDebugView",
|
|
5921
|
+
"WidgetDialog",
|
|
5922
|
+
"WidgetGlyph",
|
|
5923
|
+
"WidgetHead",
|
|
5924
|
+
"WidgetHero",
|
|
5925
|
+
"WidgetIcon",
|
|
5926
|
+
"WidgetLayer",
|
|
5927
|
+
"WidgetManifestSchema",
|
|
5928
|
+
"WidgetSizeCtx",
|
|
5929
|
+
"WidgetSliderFill",
|
|
5930
|
+
"WidgetStatus",
|
|
5931
|
+
"WidgetStepper",
|
|
5932
|
+
"WidgetTitle",
|
|
5933
|
+
"WidgetValue",
|
|
5934
|
+
"buildDebugData",
|
|
5935
|
+
"byDomain",
|
|
5936
|
+
"calculateLightGroup",
|
|
5937
|
+
"calculateSensorGroup",
|
|
5938
|
+
"copyText",
|
|
5939
|
+
"countActiveEntities",
|
|
5940
|
+
"defineConfig",
|
|
5941
|
+
"defineWidget",
|
|
5942
|
+
"deprecations",
|
|
5943
|
+
"field",
|
|
5944
|
+
"formatDeprecation",
|
|
5945
|
+
"formatSchemaError",
|
|
5946
|
+
"getEntityAttribute",
|
|
5947
|
+
"getForecasts",
|
|
5948
|
+
"getStream",
|
|
5949
|
+
"getWebRtcClientConfig",
|
|
5950
|
+
"hassMediaUrl",
|
|
5951
|
+
"imagePreset",
|
|
5952
|
+
"imageSrc",
|
|
5953
|
+
"imageUrl",
|
|
5954
|
+
"injectTokens",
|
|
5955
|
+
"isDark",
|
|
5956
|
+
"isEntityActive",
|
|
5957
|
+
"isPanelControllable",
|
|
5958
|
+
"mediaUrl",
|
|
5959
|
+
"monotoneCubicPath",
|
|
5960
|
+
"parseColor",
|
|
5961
|
+
"presetValue",
|
|
5962
|
+
"sendWebRtcCandidate",
|
|
5963
|
+
"startWebRtcSession",
|
|
5964
|
+
"state",
|
|
5965
|
+
"svgColors",
|
|
5966
|
+
"trackEntityHistory",
|
|
5967
|
+
"untrackEntityHistory",
|
|
5968
|
+
"useArea",
|
|
5969
|
+
"useCalendarEvents",
|
|
5970
|
+
"useCamera",
|
|
5971
|
+
"useConfirm",
|
|
5972
|
+
"useConnection",
|
|
5973
|
+
"useCopyText",
|
|
5974
|
+
"useCurrency",
|
|
5975
|
+
"useDaylight",
|
|
5976
|
+
"useEntities",
|
|
5977
|
+
"useEntity",
|
|
5978
|
+
"useEntityHistory",
|
|
5979
|
+
"useEntityStatistics",
|
|
5980
|
+
"useForecast",
|
|
5981
|
+
"useHassConfig",
|
|
5982
|
+
"useIntersectionPause",
|
|
5983
|
+
"useLocale",
|
|
5984
|
+
"useMaterial",
|
|
5985
|
+
"useReducedMotion",
|
|
5986
|
+
"useService",
|
|
5987
|
+
"useStore",
|
|
5988
|
+
"useTemperatureUnit",
|
|
5989
|
+
"useToggle",
|
|
5990
|
+
"useTurnOff",
|
|
5991
|
+
"useTurnOn",
|
|
5992
|
+
"useUnitSystem",
|
|
5993
|
+
"useWidgetContext",
|
|
5994
|
+
"useWidgetDashboard",
|
|
5995
|
+
"useWidgetDialog",
|
|
5996
|
+
"useWidgetDimensions",
|
|
5997
|
+
"useWidgetEntityGroup",
|
|
5998
|
+
"useWidgetGestures",
|
|
5999
|
+
"useWidgetState",
|
|
6000
|
+
"useWidgetViewer",
|
|
6001
|
+
"widgetFields",
|
|
6002
|
+
"z"
|
|
5713
6003
|
]
|
|
5714
6004
|
}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Hooks for widget development: context, dialog, entity group.
|
|
5
5
|
*/
|
|
6
|
-
export { type ReactiveWidgetContext, type ServiceCallFn, useWidgetContext, WidgetCtx, type WidgetDashboard, type WidgetMaterial, type WidgetViewer, type WidgetDimensions, } from "./use-widget-context";
|
|
6
|
+
export { type ReactiveWidgetContext, type ServiceCallFn, useWidgetContext, WidgetCtx, type WidgetDashboard, type WidgetMaterial, type WidgetViewer, type WidgetDimensions, type WidgetStateStore, } from "./use-widget-context";
|
|
7
|
+
export { useWidgetState } from "./use-widget-state";
|
|
8
|
+
export type { WidgetStateVerdict } from "@glasshome/widget-contract/state";
|
|
7
9
|
export { useWidgetDashboard } from "./use-widget-dashboard";
|
|
8
10
|
export { useWidgetViewer } from "./use-widget-viewer";
|
|
9
11
|
export { useMaterial } from "./use-material";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MaterialTerms } from "@glasshome/ui/tokens";
|
|
2
|
+
import type { WidgetStateVerdict } from "@glasshome/widget-contract/state";
|
|
2
3
|
/**
|
|
3
4
|
* Reactive widget context.
|
|
4
5
|
*
|
|
@@ -34,6 +35,11 @@ export interface WidgetMaterial {
|
|
|
34
35
|
id: string;
|
|
35
36
|
terms: MaterialTerms;
|
|
36
37
|
}
|
|
38
|
+
/** Values a widget keeps across reloads. `read` is reactive; `write(key, undefined)` deletes; a refused write changes nothing. */
|
|
39
|
+
export interface WidgetStateStore {
|
|
40
|
+
read(key: string): unknown;
|
|
41
|
+
write(key: string, value: unknown): WidgetStateVerdict;
|
|
42
|
+
}
|
|
37
43
|
export interface ReactiveWidgetContext {
|
|
38
44
|
updateConfig: (config: Record<string, unknown>) => void;
|
|
39
45
|
/**
|
|
@@ -48,6 +54,9 @@ export interface ReactiveWidgetContext {
|
|
|
48
54
|
/** Present when the host mounts the widget; the service hooks route
|
|
49
55
|
through it. Absent in previews/tests (direct sync-layer fallback). */
|
|
50
56
|
callService?: ServiceCallFn;
|
|
57
|
+
/** Whether the widget's own grant lets it make this call, so a control it cannot run is never drawn.
|
|
58
|
+
Absent on hosts that predate this field: draw the control and let the call answer. */
|
|
59
|
+
canCall?: (domain: string, service: string, entityIds: string[]) => boolean;
|
|
51
60
|
/** The dashboard this instance sits on. Absent on hosts that predate this field. */
|
|
52
61
|
dashboard?: () => WidgetDashboard;
|
|
53
62
|
/** Who is looking. Absent on hosts that predate this field. */
|
|
@@ -67,6 +76,8 @@ export interface ReactiveWidgetContext {
|
|
|
67
76
|
tone: string | null;
|
|
68
77
|
lift: number | null;
|
|
69
78
|
} | null) => void;
|
|
79
|
+
/** Kept by the host across reloads, for this widget and this person. Absent on hosts that predate this field. */
|
|
80
|
+
state?: WidgetStateStore;
|
|
70
81
|
}
|
|
71
82
|
export declare const WidgetCtx: import("solid-js").Context<ReactiveWidgetContext | undefined>;
|
|
72
83
|
export declare function useWidgetContext(): ReactiveWidgetContext;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type WidgetStateVerdict } from "@glasshome/widget-contract/state";
|
|
2
|
+
import { type Accessor } from "solid-js";
|
|
3
|
+
import type { z } from "zod";
|
|
4
|
+
/**
|
|
5
|
+
* A small value this widget keeps across reloads, for this widget on this board and this person.
|
|
6
|
+
* The stored value is read through `schema`; anything it refuses reads as `fallback`.
|
|
7
|
+
* The setter returns the host's verdict: anything but "ok" changed nothing. A value that would not read back
|
|
8
|
+
* through `schema` after a JSON round trip (a Date, NaN) is refused as "value".
|
|
9
|
+
*/
|
|
10
|
+
export declare function useWidgetState<T>(key: string, schema: z.ZodType<T>, fallback: T): [Accessor<T>, (next: T | ((prev: T) => T)) => WidgetStateVerdict];
|
|
@@ -36,7 +36,7 @@ export { WidgetSliderFill } from "./backgrounds/WidgetSliderFill";
|
|
|
36
36
|
export { type PanelFact, PanelFacts, PanelRow, type PanelRowProps, PanelRows, PanelSection, type PanelSlide, } from "./panel/panel";
|
|
37
37
|
export { isPanelControllable, PanelEntityRow } from "./panel/panel-entity";
|
|
38
38
|
export { buildDebugData, WidgetDebugTab, type WidgetDebugData, type WidgetDebugEntity, WidgetDebugView, WidgetDialog, type SheetTile, type WidgetDialogProps, type WidgetDialogTab, } from "./dialogs";
|
|
39
|
-
export { type AggregationPreset, type ReactiveWidgetContext, type ServiceCallFn, type UseWidgetEntityGroupOptions, type UseWidgetEntityGroupResult, type Daylight, type DaylightPhase, useDaylight, useIntersectionPause, useReducedMotion, useWidgetContext, useWidgetDashboard, useMaterial, useWidgetViewer, useWidgetDialog, useWidgetDimensions, useWidgetEntityGroup, WidgetCtx, type WidgetDashboard, type WidgetMaterial, type WidgetViewer, type WidgetDialogReturn, type WidgetDimensions, type WidgetDimensionsAccessor, WidgetSizeCtx, } from "./hooks";
|
|
39
|
+
export { type AggregationPreset, type ReactiveWidgetContext, type ServiceCallFn, type UseWidgetEntityGroupOptions, type UseWidgetEntityGroupResult, type Daylight, type DaylightPhase, useDaylight, useIntersectionPause, useReducedMotion, useWidgetContext, useWidgetDashboard, useMaterial, useWidgetViewer, useWidgetState, useWidgetDialog, useWidgetDimensions, useWidgetEntityGroup, WidgetCtx, type WidgetDashboard, type WidgetMaterial, type WidgetViewer, type WidgetStateStore, type WidgetStateVerdict, type WidgetDialogReturn, type WidgetDimensions, type WidgetDimensionsAccessor, WidgetSizeCtx, } from "./hooks";
|
|
40
40
|
export { type GestureHandlers, useWidgetGestures } from "./gestures/use-widget-gestures";
|
|
41
41
|
export { injectTokens, type SvgColorKey, svgColors, type Tone, ToneSchema } from "./theming";
|
|
42
42
|
export { widgetFields } from "./fields";
|
|
@@ -4,6 +4,7 @@ export declare function isPanelControllable(domain: string): boolean;
|
|
|
4
4
|
/**
|
|
5
5
|
* A row for any entity, drawn and wired from its domain: a light dims, a cover
|
|
6
6
|
* opens, a lock locks. The same row the area panel and every group panel use.
|
|
7
|
+
* A call the widget's grant refuses draws no control; the row still reads.
|
|
7
8
|
*/
|
|
8
9
|
export declare function PanelEntityRow(props: {
|
|
9
10
|
entityId: string;
|
|
@@ -9,7 +9,7 @@ export interface PanelSlide {
|
|
|
9
9
|
onCommit?: (value: number) => void;
|
|
10
10
|
/** Names the value for screen readers and the keyboard handle ("Brightness"). */
|
|
11
11
|
label?: string;
|
|
12
|
-
/**
|
|
12
|
+
/** The value moves in steps of this size, by drag and by keyboard. Unset: the drag reports whole numbers and a key moves 5. */
|
|
13
13
|
step?: number;
|
|
14
14
|
}
|
|
15
15
|
/** A labelled group in the panel's aside ("Lights", "Playing on"). */
|