-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from flixlix/feat-add-ui-editor
feat: add ui editor
- Loading branch information
Showing
9 changed files
with
435 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import type { LitElement } from "lit"; | ||
|
||
|
||
|
||
export type HaFormSchema = | ||
| HaFormConstantSchema | ||
| HaFormStringSchema | ||
| HaFormIntegerSchema | ||
| HaFormFloatSchema | ||
| HaFormBooleanSchema | ||
| HaFormSelectSchema | ||
| HaFormMultiSelectSchema | ||
| HaFormTimeSchema | ||
| HaFormSelector | ||
| HaFormGridSchema | ||
| HaFormExpandableSchema; | ||
|
||
export interface HaFormBaseSchema { | ||
name: string; | ||
// This value is applied if no data is submitted for this field | ||
default?: HaFormData; | ||
required?: boolean; | ||
disabled?: boolean; | ||
description?: { | ||
suffix?: string; | ||
// This value will be set initially when form is loaded | ||
suggested_value?: HaFormData; | ||
}; | ||
context?: Record<string, string>; | ||
} | ||
|
||
export interface HaFormGridSchema extends HaFormBaseSchema { | ||
type: "grid"; | ||
name: string; | ||
column_min_width?: string; | ||
schema: readonly HaFormSchema[]; | ||
} | ||
|
||
export interface HaFormExpandableSchema extends HaFormBaseSchema { | ||
type: "expandable"; | ||
name: ""; | ||
title: string; | ||
icon?: string; | ||
iconPath?: string; | ||
expanded?: boolean; | ||
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6; | ||
schema: readonly HaFormSchema[]; | ||
} | ||
|
||
export interface HaFormSelector extends HaFormBaseSchema { | ||
type?: never; | ||
selector: any; | ||
} | ||
|
||
export interface HaFormConstantSchema extends HaFormBaseSchema { | ||
type: "constant"; | ||
value?: string; | ||
} | ||
|
||
export interface HaFormIntegerSchema extends HaFormBaseSchema { | ||
type: "integer"; | ||
default?: HaFormIntegerData; | ||
valueMin?: number; | ||
valueMax?: number; | ||
} | ||
|
||
export interface HaFormSelectSchema extends HaFormBaseSchema { | ||
type: "select"; | ||
options: ReadonlyArray<readonly [string, string]>; | ||
} | ||
|
||
export interface HaFormMultiSelectSchema extends HaFormBaseSchema { | ||
type: "multi_select"; | ||
options: | ||
| Record<string, string> | ||
| readonly string[] | ||
| ReadonlyArray<readonly [string, string]>; | ||
} | ||
|
||
export interface HaFormFloatSchema extends HaFormBaseSchema { | ||
type: "float"; | ||
} | ||
|
||
export interface HaFormStringSchema extends HaFormBaseSchema { | ||
type: "string"; | ||
format?: string; | ||
autocomplete?: string; | ||
} | ||
|
||
export interface HaFormBooleanSchema extends HaFormBaseSchema { | ||
type: "boolean"; | ||
} | ||
|
||
export interface HaFormTimeSchema extends HaFormBaseSchema { | ||
type: "positive_time_period_dict"; | ||
} | ||
|
||
// Type utility to unionize a schema array by flattening any grid schemas | ||
export type SchemaUnion< | ||
SchemaArray extends readonly HaFormSchema[], | ||
Schema = SchemaArray[number] | ||
> = Schema extends HaFormGridSchema | HaFormExpandableSchema | ||
? SchemaUnion<Schema["schema"]> | ||
: Schema; | ||
|
||
export interface HaFormDataContainer { | ||
[key: string]: HaFormData; | ||
} | ||
|
||
export type HaFormData = | ||
| HaFormStringData | ||
| HaFormIntegerData | ||
| HaFormFloatData | ||
| HaFormBooleanData | ||
| HaFormSelectData | ||
| HaFormMultiSelectData | ||
| HaFormTimeData; | ||
|
||
export type HaFormStringData = string; | ||
export type HaFormIntegerData = number; | ||
export type HaFormFloatData = number; | ||
export type HaFormBooleanData = boolean; | ||
export type HaFormSelectData = string; | ||
export type HaFormMultiSelectData = string[]; | ||
export type HaFormTimeData = any; | ||
|
||
export interface HaFormElement extends LitElement { | ||
schema: HaFormSchema | readonly HaFormSchema[]; | ||
data?: HaFormDataContainer | HaFormData; | ||
label?: string; | ||
} |
Oops, something went wrong.