@glasshome/widget-sdk 0.2.5 → 0.3.3
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/define-widget.d.ts +2 -2
- package/dist/framework/dialogs/WidgetDialog.d.ts +5 -0
- package/dist/framework/fields.d.ts +16 -0
- package/dist/framework/index.d.ts +2 -0
- package/dist/framework/to-form-schema.d.ts +16 -0
- package/dist/index.js +819 -759
- package/dist/schemas.d.ts +17 -1
- package/dist/schemas.js +33 -17
- package/dist/version.d.ts +1 -5
- package/package.json +1 -1
package/dist/define-widget.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { WidgetDefinition } from "./types";
|
|
|
2
2
|
/**
|
|
3
3
|
* Define a widget and return its definition for registration with the dashboard.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* When `configSchema` (Zod) is provided, auto-populates `manifest.schema` (JSON Schema)
|
|
6
|
+
* and `manifest.defaultConfig` for backward compatibility with existing consumers.
|
|
7
7
|
*
|
|
8
8
|
* @template C - Widget configuration type
|
|
9
9
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Component, type JSX } from "solid-js";
|
|
2
|
+
import type { ZodType } from "zod";
|
|
2
3
|
export interface WidgetDialogTab {
|
|
3
4
|
id: string;
|
|
4
5
|
label: string;
|
|
@@ -21,11 +22,15 @@ export interface WidgetDialogProps {
|
|
|
21
22
|
maxWidth?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl";
|
|
22
23
|
defaultTab?: string;
|
|
23
24
|
headerActions?: JSX.Element;
|
|
25
|
+
configSchema?: ZodType;
|
|
26
|
+
config?: Record<string, unknown>;
|
|
27
|
+
onConfigSave?: (config: Record<string, unknown>) => void;
|
|
24
28
|
ResponsiveDialog: Component<any>;
|
|
25
29
|
ResponsiveDialogContent: Component<any>;
|
|
26
30
|
ResponsiveDialogHeader: Component<any>;
|
|
27
31
|
ResponsiveDialogTitle: Component<any>;
|
|
28
32
|
ResponsiveDialogDescription: Component<any>;
|
|
29
33
|
Button: Component<any>;
|
|
34
|
+
SchemaForm?: Component<any>;
|
|
30
35
|
}
|
|
31
36
|
export declare function WidgetDialog(props: WidgetDialogProps): JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Pre-built Zod field helpers for common widget config patterns.
|
|
4
|
+
* Each helper returns a Zod schema with `.meta()` annotations that
|
|
5
|
+
* SchemaForm uses to render the appropriate UI (entity picker, area picker, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export declare const widgetFields: {
|
|
8
|
+
/** Optional display name override (renders as text input) */
|
|
9
|
+
title: () => z.ZodOptional<z.ZodString>;
|
|
10
|
+
/** Multi-select entity picker for a HA domain */
|
|
11
|
+
entityIds: (domain: string) => z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
/** Single-select entity picker for a HA domain */
|
|
13
|
+
singleEntity: (domain: string) => z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
14
|
+
/** Area picker dropdown */
|
|
15
|
+
areaId: () => z.ZodOptional<z.ZodString>;
|
|
16
|
+
};
|
|
@@ -51,5 +51,7 @@ export { typography } from "./design-system/typography";
|
|
|
51
51
|
export { WIDGET_Z, type WidgetZIndex } from "./design-system/z-index";
|
|
52
52
|
export { type AdaptiveIconColors, deriveAdaptiveIconColors, GRADIENT_NAMES, GRADIENT_PRESET_KEYS, GRADIENT_PRESETS, type GradientPreset, getGradient, getGradientFromString, gradientColorPresets, stateColors, type WidgetColorPreset, } from "./theming";
|
|
53
53
|
export { applyCssVars, applyLayout, builtInVariants, classicGlass, compactHorizontal, composeVariants, createFlexLayout, extendVariant, getBuiltInVariant, getBuiltInVariantIds, isBuiltInVariant, mergeVariants, minimal, } from "./variants";
|
|
54
|
+
export { widgetFields } from "./fields";
|
|
55
|
+
export { extractDefaults, toFormSchema } from "./to-form-schema";
|
|
54
56
|
export { allEntitiesInState, anyEntityInState, calculateLightGroup, calculateSensorGroup, cn, countActiveEntities, countAvailableEntities, countEntitiesByState, createEmptyStateConfig, type EmptyStateConfigOptions, formatValue, getEntityAttribute, getEntityState, interpretValue, isEntityActive, isEntityAvailable, type LightGroupResult, type SensorGroupResult, type SensorGroupType, type WidgetEmptyStateConfig, } from "./utils";
|
|
55
57
|
export type { AbsoluteLayoutStrategy, BaseComponentProps, ColorVariant, CustomLayoutStrategy, ElementConfig, EntityView, FlexLayoutStrategy, GestureConfig, GradientConfig, GridLayoutStrategy, HoldGestureConfig, ImageOverlay, InteractionConfig, LayoutStrategy, PositionConfig, SlideGestureConfig, SpacingScale, VariantPlugins, VariantRegistry, WidgetContextValue, WidgetDimensions, WidgetElement, WidgetOrientation, WidgetSize, WidgetStyles, WidgetVariant, WidgetVariantConfig, } from "./types";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ZodType } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Convert a Zod config schema to JSON Schema with custom metadata injected.
|
|
4
|
+
*
|
|
5
|
+
* Widget field helpers attach metadata via `.meta()` (e.g. `{ domain: "light" }`,
|
|
6
|
+
* `{ formType: "area-picker" }`). The `override` callback reads these from
|
|
7
|
+
* `z.globalRegistry` and merges them into the JSON Schema output so the
|
|
8
|
+
* form renderer can detect custom field types.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toFormSchema(schema: ZodType): object;
|
|
11
|
+
/**
|
|
12
|
+
* Extract default config values from a Zod schema.
|
|
13
|
+
* Fields with `.default()` get their default value; optional fields without
|
|
14
|
+
* defaults are omitted. Returns empty object on parse failure.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractDefaults(schema: ZodType): Record<string, unknown>;
|