Skip to content

Commit bfda55f

Browse files
committed
Added typescript definitions for widget definitions
Signed-off-by: Jeff James <[email protected]>
1 parent 2746eb7 commit bfda55f

File tree

9 files changed

+287
-2
lines changed

9 files changed

+287
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhHomePageDefinition(): WidgetDefinition
4+
export declare function OhLocationsTabParameters(): WidgetDefinition
5+
export declare function OhEquipmentTabParameters(): WidgetDefinition
6+
export declare function OhPropertiesTabParameters(): WidgetDefinition
7+
export declare function OhLocationCardParameters(): WidgetDefinition
8+
export declare function OhEquipmentCardParameters(): WidgetDefinition
9+
export declare function OhPropertyCardParameters(): WidgetDefinition
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import * as api from '@/api'
2+
3+
/**
4+
* Parameter types supported by widget definitions
5+
*/
6+
export type ParameterType = (typeof api.ConfigDescriptionParameter)['type']
7+
8+
/**
9+
* Visibility function type
10+
* @param value - The current value of the parameter
11+
* @param configuration - The full configuration object
12+
* @param configDescription - The configuration description
13+
* @param parameters - The parameters object
14+
* @returns Whether the parameter should be visible
15+
*/
16+
export type VisibilityFunction = (value: any, configuration: Record<string, any>, configDescription: any, parameters: any) => boolean
17+
18+
/**
19+
* Parameter class for building widget configuration parameters
20+
*/
21+
export declare class Parameter implements api.ConfigDescriptionParameter {
22+
type: ParameterType
23+
name: string
24+
label: string
25+
description: string
26+
advanced?: boolean
27+
context?: string
28+
groupName?: string
29+
multiple?: boolean
30+
options?: Array<api.ParameterOption>
31+
limitToOptions?: boolean
32+
default?: any
33+
required?: boolean
34+
visible?: VisibilityFunction
35+
36+
constructor(type: ParameterType, name: string, label: string, description: string)
37+
38+
/**
39+
* Sets the parameter as advanced
40+
*/
41+
a(): this
42+
43+
/**
44+
* Sets the context of the parameter
45+
*/
46+
c(context: string): this
47+
48+
/**
49+
* Sets the groupName of the parameter
50+
*/
51+
g(groupName: string): this
52+
53+
/**
54+
* Sets the parameter as holding multiple values
55+
*/
56+
m(): this
57+
58+
/**
59+
* Sets the options of the parameter
60+
* @param opts - The array of options
61+
* @param limitToOptions - Whether valid values should be restricted to options
62+
* @param multiple - Whether multiple options may be selected
63+
*/
64+
o(opts: api.ParameterOption[], limitToOptions?: boolean, multiple?: boolean): this
65+
66+
/**
67+
* Sets the default value of the parameter
68+
* @param value - The default value
69+
*/
70+
d(value: any): this
71+
72+
/**
73+
* Sets the parameter as required
74+
*/
75+
r(): this
76+
77+
/**
78+
* The visibility function
79+
* @param vfn - The visibility function
80+
*/
81+
v(vfn: VisibilityFunction): this
82+
}
83+
84+
/**
85+
* Widget definition interface
86+
*/
87+
export interface _WidgetDefinition {
88+
name: string
89+
label: string
90+
description: string
91+
icon?: string
92+
hidden: boolean
93+
props: api.ConfigDescription
94+
}
95+
96+
/**
97+
* The widget definition class, describing the widget and its props (config parameters)
98+
*/
99+
export declare class WidgetDefinition implements _WidgetDefinition {
100+
name: string
101+
label: string
102+
description: string
103+
icon?: string
104+
hidden: boolean
105+
docLink?: string
106+
props: api.ConfigDescription
107+
108+
constructor(name: string, label: string, description: string, icon?: string, hidden?: boolean)
109+
110+
/**
111+
* Add a parameter group with optional parameters
112+
* @param group - The parameter group
113+
* @param params - Optional array of parameters
114+
* @param advanced - Whether to mark all parameters as advanced
115+
*/
116+
paramGroup(group: api.ConfigDescriptionParameterGroup, params?: Parameter[], advanced?: boolean): this
117+
118+
/**
119+
* Add parameters to the widget
120+
* @param p - Array of parameters
121+
*/
122+
params(p: Parameter[]): this
123+
}
124+
125+
// Helper functions
126+
127+
/**
128+
* Builds a parameter
129+
* @param type - The type of the parameter
130+
* @param name - The name of the parameter
131+
* @param label - The untranslated (English) label of the parameter
132+
* @param description - The untranslated (English) description of the parameter
133+
*/
134+
export declare function p(type: ParameterType, name: string, label: string, description: string): Parameter
135+
136+
/**
137+
* Builds a boolean parameter
138+
* @param name - The name of the parameter
139+
* @param label - The untranslated (English) label of the parameter
140+
* @param description - The untranslated (English) description of the parameter
141+
*/
142+
export declare function pb(name: string, label: string, description: string): Parameter
143+
144+
/**
145+
* Builds a decimal parameter
146+
* @param name - The name of the parameter
147+
* @param label - The untranslated (English) label of the parameter
148+
* @param description - The untranslated (English) description of the parameter
149+
*/
150+
export declare function pd(name: string, label: string, description: string): Parameter
151+
152+
/**
153+
* Builds a parameter group
154+
* @param name - The name of the group
155+
* @param label - The untranslated (English) label of the group
156+
* @param description - The untranslated (English) description of the group
157+
*/
158+
export declare function pg(name: string, label: string, description?: string): api.ConfigDescriptionParameterGroup
159+
160+
/**
161+
* Builds an item parameter
162+
* @param name - The name of the parameter
163+
* @param label - The untranslated (English) label of the parameter
164+
* @param description - The untranslated (English) description of the parameter
165+
*/
166+
export declare function pi(name: string, label: string, description: string): Parameter
167+
168+
/**
169+
* Builds a text parameter with options
170+
* @param name - The name of the parameter
171+
* @param label - The untranslated (English) label of the parameter
172+
* @param description - The untranslated (English) description of the parameter
173+
* @param options - An array of options with untranslated (English) labels
174+
*/
175+
export declare function po(name: string, label: string, description: string, options: api.ParameterOption[]): Parameter
176+
177+
/**
178+
* Builds a numerical (integer) parameter
179+
* @param name - The name of the parameter
180+
* @param label - The untranslated (English) label of the parameter
181+
* @param description - The untranslated (English) description of the parameter
182+
*/
183+
export declare function pn(name: string, label: string, description: string): Parameter
184+
185+
/**
186+
* Builds a text parameter
187+
* @param name - The name of the parameter
188+
* @param label - The untranslated (English) label of the parameter
189+
* @param description - The untranslated (English) description of the parameter
190+
*/
191+
export declare function pt(name: string, label: string, description: string): Parameter
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhBlockDescription(): WidgetDefinition
4+
export declare function OhGridRowDefinition(): WidgetDefinition
5+
export declare function OhGridColDefinition(): WidgetDefinition
6+
export declare function OhMasonryDefinition(): WidgetDefinition
7+
export declare function OhGridLayoutDefinition(): WidgetDefinition
8+
export declare function OhCanvasItemDefinition(): WidgetDefinition
9+
export declare function OhCanvasLayoutDefinition(): WidgetDefinition
10+
export declare function OhCanvasLayerDefinition(): WidgetDefinition
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhMapPageDefinition(): WidgetDefinition
4+
export declare function OhMapMarkerDefinition(): WidgetDefinition
5+
export declare function OhMapCircleMarkerDefinition(): WidgetDefinition
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhPlanPageDefinition(): WidgetDefinition
4+
export declare function OhPlanMarkerDefinition(): WidgetDefinition
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
// cells
4+
export declare function OhCellDefinition(): WidgetDefinition
5+
export declare function OhLabelCellDefinition(): WidgetDefinition
6+
export declare function OhSliderCellDefinition(): WidgetDefinition
7+
export declare function OhKnobCellDefinition(): WidgetDefinition
8+
export declare function OhColorpickerCellDefinition(): WidgetDefinition
9+
export declare function OhRollershutterCellDefinition(): WidgetDefinition
10+
11+
// cards
12+
export declare function OhCardDefinition(): WidgetDefinition
13+
export declare function OhLabelCardDefinition(): WidgetDefinition
14+
export declare function OhListCardDefinition(): WidgetDefinition
15+
export declare function OhInputCardDefinition(): WidgetDefinition
16+
export declare function OhColorpickerCardDefinition(): WidgetDefinition
17+
export declare function OhPlayerCardDefinition(): WidgetDefinition
18+
export declare function OhRollershutterCardDefinition(): WidgetDefinition
19+
export declare function OhSliderCardDefinition(): WidgetDefinition
20+
export declare function OhGaugeCardDefinition(): WidgetDefinition
21+
export declare function OhKnobCardDefinition(): WidgetDefinition
22+
export declare function OhStepperCardDefinition(): WidgetDefinition
23+
export declare function OhSwiperCardDefinition(): WidgetDefinition
24+
export declare function OhToggleCardDefinition(): WidgetDefinition
25+
export declare function OhImageCardDefinition(): WidgetDefinition
26+
export declare function OhVideoCardDefinition(): WidgetDefinition
27+
export declare function OhWebFrameCardDefinition(): WidgetDefinition
28+
export declare function OhClockCardDefinition(): WidgetDefinition
29+
export declare function OhSIPClientCardDefinition(): WidgetDefinition
30+
31+
// list items
32+
export declare function OhListItemDefinition(): WidgetDefinition
33+
export declare function OhLabelItemDefinition(): WidgetDefinition
34+
export declare function OhInputItemDefinition(): WidgetDefinition
35+
export declare function OhColorpickerItemDefinition(): WidgetDefinition
36+
export declare function OhPlayerItemDefinition(): WidgetDefinition
37+
export declare function OhRollershutterItemDefinition(): WidgetDefinition
38+
export declare function OhSliderItemDefinition(): WidgetDefinition
39+
export declare function OhStepperItemDefinition(): WidgetDefinition
40+
export declare function OhToggleItemDefinition(): WidgetDefinition
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhButtonDefinition(): WidgetDefinition
4+
export declare function OhChartDefinition(): WidgetDefinition
5+
export declare function OhColorpickerDefinition(): WidgetDefinition
6+
export declare function OhContextDefinition(): WidgetDefinition
7+
export declare function OhGaugeDefinition(): WidgetDefinition
8+
export declare function OhIconDefinition(): WidgetDefinition
9+
export declare function OhImageDefinition(): WidgetDefinition
10+
export declare function OhVideoDefinition(): WidgetDefinition
11+
export declare function OhInputDefinition(): WidgetDefinition
12+
export declare function OhKnobDefinition(): WidgetDefinition
13+
export declare function OhLinkDefinition(): WidgetDefinition
14+
export declare function OhListDefinition(): WidgetDefinition
15+
export declare function OhPlayerDefinition(): WidgetDefinition
16+
export declare function OhRollershutterDefinition(): WidgetDefinition
17+
export declare function OhSliderDefinition(): WidgetDefinition
18+
export declare function OhStepperDefinition(): WidgetDefinition
19+
export declare function OhSwiperDefinition(): WidgetDefinition
20+
export declare function OhToggleDefinition(): WidgetDefinition
21+
export declare function OhTrendDefinition(): WidgetDefinition
22+
export declare function OhWebFrameDefinition(): WidgetDefinition
23+
export declare function OhRepeaterDefinition(): WidgetDefinition
24+
export declare function OhClockDefinition(): WidgetDefinition
25+
export declare function OhSIPClientDefinition(): WidgetDefinition
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { WidgetDefinition } from '../index'
2+
3+
export declare function OhTabDefinition(): WidgetDefinition

bundles/org.openhab.ui/web/src/components/widgets/layout/oh-block.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
<script setup lang="ts">
5151
import { useWidgetContext } from '@/components/widgets/useWidgetContext'
5252
import type { WidgetContext } from '@/components/widgets/types'
53-
54-
// @ts-expect-error - assets are not typee
5553
import { OhBlockDescription } from '@/assets/definitions/widgets/layout'
5654
5755
defineOptions({

0 commit comments

Comments
 (0)