-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathln0.ts
93 lines (85 loc) · 2.3 KB
/
ln0.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { html, TemplateResult } from 'lit-element';
import { get } from 'lit-translate';
import '@openscd/open-scd/src/wizard-textfield.js';
import {
getValue,
Wizard,
WizardActor,
WizardInputElement,
} from '@openscd/open-scd/src/foundation.js';
import { cloneElement } from '@openscd/xml';
import { SimpleAction } from '@openscd/core/foundation/deprecated/editor.js';
import { patterns } from './foundation/limits.js';
export function renderLN0Wizard(
lnType: string | null,
desc: string | null,
lnClass: string | null,
inst: string | null
): TemplateResult[] {
return [
html`<wizard-textfield
label="lnType"
.maybeValue=${lnType}
readonly
required
helper="${get('ln0.wizard.lnTypeHelper')}"
></wizard-textfield>`,
html`<wizard-textfield
label="desc"
.maybeValue=${desc}
nullable
helper="${get('ln0.wizard.descHelper')}"
></wizard-textfield>`,
html`<wizard-textfield
label="lnClass"
readonly
required
.maybeValue=${lnClass}
helper="${get('ln0.wizard.lnClassHelper')}"
></wizard-textfield>`,
html`<wizard-textfield
label="inst"
.maybeValue=${inst}
readonly
helper="${get('ln0.wizard.instHelper')}"
></wizard-textfield>`,
];
}
function updateAction(element: Element): WizardActor {
return (inputs: WizardInputElement[]): SimpleAction[] => {
const ldAttrs: Record<string, string | null> = {};
const ldKeys = ['lnType', 'desc', 'lnClass', 'inst'];
ldKeys.forEach(key => {
ldAttrs[key] = getValue(inputs.find(i => i.label === key)!);
});
if (ldKeys.some(key => ldAttrs[key] !== element.getAttribute(key))) {
const newElement = cloneElement(element, ldAttrs);
return [
{
old: { element },
new: { element: newElement },
},
];
}
return [];
};
}
export function editLN0Wizard(element: Element): Wizard {
return [
{
title: get('ln0.wizard.title.edit'),
element,
primary: {
icon: 'edit',
label: get('save'),
action: updateAction(element),
},
content: renderLN0Wizard(
element.getAttribute('lnType'),
element.getAttribute('desc'),
element.getAttribute('lnClass'),
element.getAttribute('inst')
),
},
];
}