Skip to content

Commit 5f3a7a7

Browse files
feat(wizard-dialog): wizard-dialog content definition through WizardInput objects
1 parent 7bbf1c1 commit 5f3a7a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+741
-198
lines changed

src/editors/singlelinediagram/wizards/foundation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
EditorAction,
77
getValue,
88
WizardActor,
9-
WizardInput,
9+
WizardInputElement,
1010
} from '../../../foundation.js';
1111
import { SCL_COORDINATES_NAMESPACE } from "../foundation.js";
1212

@@ -48,7 +48,7 @@ function updateXYAttribute(element: Element, attributeName: string, value: strin
4848
}
4949

5050
export function updateNamingAndCoordinatesAction(element: Element): WizardActor {
51-
return (inputs: WizardInput[]): EditorAction[] => {
51+
return (inputs: WizardInputElement[]): EditorAction[] => {
5252
const name = getValue(inputs.find(i => i.label === 'name')!)!;
5353
const desc = getValue(inputs.find(i => i.label === 'desc')!);
5454
const xCoordinate = getValue(inputs.find(i => i.label === 'xCoordinate')!);

src/editors/substation/guess-wizard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
EditorAction,
1414
Wizard,
1515
WizardActor,
16-
WizardInput,
16+
WizardInputElement,
1717
} from '../../foundation.js';
1818

1919
let bayNum = 1;
@@ -169,7 +169,7 @@ function createBayElement(
169169

170170
function guessBasedOnCSWI(doc: XMLDocument): WizardActor {
171171
return (
172-
inputs: WizardInput[],
172+
inputs: WizardInputElement[],
173173
wizard: Element,
174174
list?: List | null
175175
): EditorAction[] => {

src/editors/templates/datype-wizards.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Wizard,
2626
WizardAction,
2727
WizardActor,
28-
WizardInput,
28+
WizardInputElement,
2929
WizardMenuActor,
3030
} from '../../foundation.js';
3131
import { createBDAWizard, editBDAWizard } from '../../wizards/bda.js';
@@ -48,7 +48,7 @@ function openAddBda(parent: Element): WizardMenuActor {
4848
}
4949

5050
function updateDATpyeAction(element: Element): WizardActor {
51-
return (inputs: WizardInput[]): EditorAction[] => {
51+
return (inputs: WizardInputElement[]): EditorAction[] => {
5252
const id = getValue(inputs.find(i => i.label === 'id')!)!;
5353
const desc = getValue(inputs.find(i => i.label === 'desc')!);
5454

@@ -162,7 +162,7 @@ function addPredefinedDAType(
162162
parent: Element,
163163
templates: XMLDocument
164164
): WizardActor {
165-
return (inputs: WizardInput[]): EditorAction[] => {
165+
return (inputs: WizardInputElement[]): EditorAction[] => {
166166
const id = getValue(inputs.find(i => i.label === 'id')!);
167167

168168
if (!id) return [];

src/editors/templates/dotype-wizards.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Wizard,
2626
WizardAction,
2727
WizardActor,
28-
WizardInput,
28+
WizardInputElement,
2929
WizardMenuActor,
3030
} from '../../foundation.js';
3131
import { createDaWizard, editDAWizard } from '../../wizards/da.js';
@@ -46,7 +46,7 @@ function remove(element: Element): WizardMenuActor {
4646
}
4747

4848
function updateSDoAction(element: Element): WizardActor {
49-
return (inputs: WizardInput[]): EditorAction[] => {
49+
return (inputs: WizardInputElement[]): EditorAction[] => {
5050
const name = getValue(inputs.find(i => i.label === 'name')!)!;
5151
const desc = getValue(inputs.find(i => i.label === 'desc')!);
5252
const type = getValue(inputs.find(i => i.label === 'type')!)!;
@@ -68,7 +68,7 @@ function updateSDoAction(element: Element): WizardActor {
6868
}
6969

7070
function createSDoAction(parent: Element): WizardActor {
71-
return (inputs: WizardInput[]): EditorAction[] => {
71+
return (inputs: WizardInputElement[]): EditorAction[] => {
7272
const name = getValue(inputs.find(i => i.label === 'name')!)!;
7373
const desc = getValue(inputs.find(i => i.label === 'desc')!);
7474
const type = getValue(inputs.find(i => i.label === 'type')!);
@@ -171,7 +171,7 @@ function addPredefinedDOType(
171171
parent: Element,
172172
templates: XMLDocument
173173
): WizardActor {
174-
return (inputs: WizardInput[]): EditorAction[] => {
174+
return (inputs: WizardInputElement[]): EditorAction[] => {
175175
const id = getValue(inputs.find(i => i.label === 'id')!);
176176

177177
if (!id) return [];
@@ -308,7 +308,7 @@ function openAddDa(parent: Element): WizardMenuActor {
308308
}
309309

310310
function updateDOTypeAction(element: Element): WizardActor {
311-
return (inputs: WizardInput[]): EditorAction[] => {
311+
return (inputs: WizardInputElement[]): EditorAction[] => {
312312
const id = getValue(inputs.find(i => i.label === 'id')!)!;
313313
const desc = getValue(inputs.find(i => i.label === 'desc')!);
314314
const cdc = getValue(inputs.find(i => i.label === 'CDC')!)!;

src/editors/templates/enumtype-wizard.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
Wizard,
2626
WizardAction,
2727
WizardActor,
28-
WizardInput,
28+
WizardInputElement,
2929
WizardMenuActor,
3030
} from '../../foundation.js';
3131
import { CreateOptions, UpdateOptions, WizardOptions } from './foundation.js';
@@ -46,7 +46,7 @@ function nextOrd(parent: Element): string {
4646
}
4747

4848
function createEnumValAction(parent: Element): WizardActor {
49-
return (inputs: WizardInput[]): EditorAction[] => {
49+
return (inputs: WizardInputElement[]): EditorAction[] => {
5050
const value = getValue(inputs.find(i => i.label === 'value')!);
5151
const desc = getValue(inputs.find(i => i.label === 'desc')!);
5252
const ord =
@@ -71,7 +71,7 @@ function createEnumValAction(parent: Element): WizardActor {
7171
}
7272

7373
function updateEnumValAction(element: Element): WizardActor {
74-
return (inputs: WizardInput[]): EditorAction[] => {
74+
return (inputs: WizardInputElement[]): EditorAction[] => {
7575
const value = getValue(inputs.find(i => i.label === 'value')!) ?? '';
7676
const desc = getValue(inputs.find(i => i.label === 'desc')!);
7777
const ord =
@@ -167,7 +167,7 @@ function eNumValWizard(options: WizardOptions): Wizard {
167167
}
168168

169169
function createAction(parent: Element, templates: XMLDocument): WizardActor {
170-
return (inputs: WizardInput[]): EditorAction[] => {
170+
return (inputs: WizardInputElement[]): EditorAction[] => {
171171
const id = getValue(inputs.find(i => i.label === 'id')!);
172172

173173
if (!id) return [];
@@ -256,7 +256,7 @@ function openAddEnumVal(parent: Element): WizardMenuActor {
256256
}
257257

258258
function updateEnumTpyeAction(element: Element): WizardActor {
259-
return (inputs: WizardInput[]): EditorAction[] => {
259+
return (inputs: WizardInputElement[]): EditorAction[] => {
260260
const id = getValue(inputs.find(i => i.label === 'id')!)!;
261261
const desc = getValue(inputs.find(i => i.label === 'desc')!);
262262

src/editors/templates/foundation.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
import { css, html, TemplateResult } from 'lit-element';
2-
import { ifDefined } from 'lit-html/directives/if-defined';
1+
import { css } from 'lit-element';
32

43
import '@material/mwc-list/mwc-list-item';
54

6-
import {
7-
cloneElement,
8-
Create,
9-
EditorAction,
10-
getValue,
11-
isPublic,
12-
WizardActor,
13-
WizardInput,
14-
} from '../../foundation.js';
5+
import { Create, isPublic } from '../../foundation.js';
156

167
export interface UpdateOptions {
178
identity: string | null;

src/editors/templates/lnodetype-wizard.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
Wizard,
3131
WizardAction,
3232
WizardActor,
33-
WizardInput,
33+
WizardInputElement,
3434
WizardMenuActor,
3535
} from '../../foundation.js';
3636
import { WizardSelect } from '../../wizard-select.js';
@@ -56,7 +56,7 @@ function openAddDo(parent: Element): WizardMenuActor {
5656
}
5757

5858
function updateDoAction(element: Element): WizardActor {
59-
return (inputs: WizardInput[]): EditorAction[] => {
59+
return (inputs: WizardInputElement[]): EditorAction[] => {
6060
const name = getValue(inputs.find(i => i.label === 'name')!)!;
6161
const desc = getValue(inputs.find(i => i.label === 'desc')!);
6262
const type = getValue(inputs.find(i => i.label === 'type')!)!;
@@ -91,7 +91,7 @@ function updateDoAction(element: Element): WizardActor {
9191
}
9292

9393
function createDoAction(parent: Element): WizardActor {
94-
return (inputs: WizardInput[]): EditorAction[] => {
94+
return (inputs: WizardInputElement[]): EditorAction[] => {
9595
const name = getValue(inputs.find(i => i.label === 'name')!)!;
9696
const desc = getValue(inputs.find(i => i.label === 'desc')!);
9797
const type = getValue(inputs.find(i => i.label === 'type')!);
@@ -281,7 +281,7 @@ function getAllDataObjects(
281281
}
282282

283283
function createNewLNodeType(parent: Element, element: Element): WizardActor {
284-
return (_: WizardInput[], wizard: Element): EditorAction[] => {
284+
return (_: WizardInputElement[], wizard: Element): EditorAction[] => {
285285
const selected = Array.from(
286286
wizard.shadowRoot!.querySelectorAll<WizardSelect>('wizard-select')
287287
).filter(select => select.maybeValue);
@@ -395,7 +395,7 @@ function startLNodeTypeCreate(
395395
nsd74: XMLDocument,
396396
nsd7420: XMLDocument
397397
): WizardActor {
398-
return (inputs: WizardInput[], wizard: Element): EditorAction[] => {
398+
return (inputs: WizardInputElement[], wizard: Element): EditorAction[] => {
399399
const id = getValue(inputs.find(i => i.label === 'id')!);
400400
if (!id) return [];
401401

@@ -564,7 +564,7 @@ export function createLNodeTypeWizard(
564564
}
565565

566566
function updateLNodeTypeAction(element: Element): WizardActor {
567-
return (inputs: WizardInput[]): EditorAction[] => {
567+
return (inputs: WizardInputElement[]): EditorAction[] => {
568568
const id = getValue(inputs.find(i => i.label === 'id')!)!;
569569
const desc = getValue(inputs.find(i => i.label === 'desc')!);
570570
const lnClass = getValue(inputs.find(i => i.label === 'lnClass')!)!;

src/foundation.ts

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function newActionEvent<T extends EditorAction>(
171171

172172
export const wizardInputSelector =
173173
'wizard-textfield, mwc-textfield, ace-editor, mwc-select,wizard-select, wizard-checkbox';
174-
export type WizardInput =
174+
export type WizardInputElement =
175175
| WizardTextField
176176
| TextField
177177
| (AceEditor & { checkValidity: () => boolean; label: string })
@@ -183,7 +183,7 @@ export type WizardAction = EditorAction | WizardFactory;
183183

184184
/** @returns [[`EditorAction`]]s to dispatch on [[`WizardDialog`]] commit. */
185185
export type WizardActor = (
186-
inputs: WizardInput[],
186+
inputs: WizardInputElement[],
187187
wizard: Element,
188188
list?: List | null
189189
) => WizardAction[];
@@ -195,21 +195,21 @@ export function isWizardFactory(
195195
}
196196

197197
/** @returns the validity of `input` depending on type. */
198-
export function checkValidity(input: WizardInput): boolean {
198+
export function checkValidity(input: WizardInputElement): boolean {
199199
if (input instanceof WizardTextField || input instanceof Select)
200200
return input.checkValidity();
201201
else return true;
202202
}
203203

204204
/** reports the validity of `input` depending on type. */
205-
export function reportValidity(input: WizardInput): boolean {
205+
export function reportValidity(input: WizardInputElement): boolean {
206206
if (input instanceof WizardTextField || input instanceof Select)
207207
return input.reportValidity();
208208
else return true;
209209
}
210210

211211
/** @returns the `value` or `maybeValue` of `input` depending on type. */
212-
export function getValue(input: WizardInput): string | null {
212+
export function getValue(input: WizardInputElement): string | null {
213213
if (
214214
input instanceof WizardTextField ||
215215
input instanceof WizardSelect ||
@@ -220,11 +220,78 @@ export function getValue(input: WizardInput): string | null {
220220
}
221221

222222
/** @returns the `multiplier` of `input` if available. */
223-
export function getMultiplier(input: WizardInput): string | null {
223+
export function getMultiplier(input: WizardInputElement): string | null {
224224
if (input instanceof WizardTextField) return input.multiplier;
225225
else return null;
226226
}
227227

228+
/** Inputs as `TextField`, `Select` or `Checkbox `used in`wizard-dialog` */
229+
export type WizardInput =
230+
| WizardInputTextField
231+
| WizardInputSelect
232+
| WizardInputCheckbox;
233+
234+
interface WizardInputBase {
235+
/** maps attribute key */
236+
label: string;
237+
/** maps attribute value */
238+
maybeValue: string | null;
239+
/** whether attribute is optional */
240+
nullable?: boolean;
241+
/** whether the input shall be disabled */
242+
disabled?: boolean;
243+
/** helper text */
244+
helper?: string;
245+
/** initial focused element in `wizard-dialog` (once per dialog) */
246+
dialogInitialFocus?: boolean;
247+
}
248+
249+
interface WizardInputTextField extends WizardInputBase {
250+
kind: 'TextField';
251+
/** wether the input might be empty string */
252+
required?: boolean;
253+
/** pattern definition from schema */
254+
pattern?: string;
255+
/** minimal characters allowed */
256+
minLength?: number;
257+
/** maximal characters allowed */
258+
maxLength?: number;
259+
/** message text explaining invalid inputs */
260+
validationMessage?: string;
261+
/** suffix definition - overwrites unit multiplier definition */
262+
suffix?: string;
263+
/** SI unit for specific suffix definition */
264+
unit?: string;
265+
/** in comibination with unit defines specific suffix */
266+
multiplier?: string | null;
267+
/** array of multipliers allowed for the input */
268+
multipliers?: (string | null)[];
269+
/** used for specific input type e.g. number */
270+
type?: string;
271+
/** minimal valid number in combination with type number */
272+
min?: number;
273+
/** maximal valid number in combination with type number */
274+
max?: number;
275+
/** value displaxed when input is nulled */
276+
default?: string;
277+
}
278+
279+
interface WizardInputSelect extends WizardInputBase {
280+
kind: 'Select';
281+
/** selectabled values */
282+
values: string[];
283+
/** value displayed with input is nulled */
284+
default?: string;
285+
/** message explaining invalid inputs */
286+
valadationMessage?: string;
287+
}
288+
289+
interface WizardInputCheckbox extends WizardInputBase {
290+
kind: 'Checkbox';
291+
/** wether checkbox is checked with nulled input */
292+
default?: boolean;
293+
}
294+
228295
/** @returns [[`WizardAction`]]s to dispatch on [[`WizardDialog`]] menu action. */
229296
export type WizardMenuActor = () => WizardAction[];
230297

@@ -238,7 +305,7 @@ export interface MenuAction {
238305
/** Represents a page of a wizard dialog */
239306
export interface WizardPage {
240307
title: string;
241-
content?: TemplateResult[];
308+
content?: (TemplateResult | WizardInput)[];
242309
primary?: {
243310
icon: string;
244311
label: string;

src/menu/NewProject.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
newOpenDocEvent,
1313
newWizardEvent,
1414
Wizard,
15-
WizardInput,
15+
WizardInputElement,
1616
} from '../foundation.js';
1717
import { newEmptySCD, SupportedVersion } from '../schemas.js';
1818

1919
export default class NewProjectPlugin extends LitElement {
2020
private createNewProject(
21-
inputs: WizardInput[],
21+
inputs: WizardInputElement[],
2222
wizard: Element
2323
): EditorAction[] {
2424
const docName = inputs[0].value?.match(/\.s[sc]d$/i)

src/menu/UpdateDescriptionABB.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Wizard,
1717
WizardAction,
1818
WizardActor,
19-
WizardInput,
19+
WizardInputElement,
2020
} from '../foundation.js';
2121

2222
interface addDescItem {
@@ -27,7 +27,7 @@ interface addDescItem {
2727

2828
function addDescriptionAction(doc: XMLDocument): WizardActor {
2929
return (
30-
_: WizardInput[],
30+
_: WizardInputElement[],
3131
wizard: Element,
3232
list: List | null | undefined
3333
): WizardAction[] => {

0 commit comments

Comments
 (0)