@openremote/or-json-forms 1.8.0-snapshot.20250725120000 → 1.8.0-snapshot.20250725123024
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/README.md +113 -113
- package/custom-elements.json +2 -2
- package/dist/umd/index.js +1105 -1105
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +1163 -1163
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/base-element.js +1 -57
- package/lib/controls/control-array-element.js +83 -277
- package/lib/controls/control-base-element.js +1 -48
- package/lib/controls/control-input-element.js +20 -157
- package/lib/index.js +7 -141
- package/lib/layouts/layout-base-element.js +1 -29
- package/lib/layouts/layout-vertical-element.js +128 -340
- package/lib/standard-renderers.js +12 -188
- package/lib/styles.js +148 -156
- package/lib/util.js +23 -291
- package/package.json +4 -4
package/lib/base-element.js
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
var __decorate = (
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { LitElement } from "lit";
|
|
8
|
-
import { property } from "lit/decorators.js";
|
|
9
|
-
export class BaseElement extends LitElement {
|
|
10
|
-
set props(props) {
|
|
11
|
-
delete props.id;
|
|
12
|
-
Object.assign(this, props);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
__decorate([
|
|
16
|
-
property({ type: Object })
|
|
17
|
-
], BaseElement.prototype, "state", void 0);
|
|
18
|
-
__decorate([
|
|
19
|
-
property({ type: Object })
|
|
20
|
-
], BaseElement.prototype, "uischema", void 0);
|
|
21
|
-
__decorate([
|
|
22
|
-
property({ type: Object })
|
|
23
|
-
], BaseElement.prototype, "schema", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
property({ type: String, attribute: false })
|
|
26
|
-
], BaseElement.prototype, "data", void 0);
|
|
27
|
-
__decorate([
|
|
28
|
-
property({ type: Array })
|
|
29
|
-
], BaseElement.prototype, "renderers", void 0);
|
|
30
|
-
__decorate([
|
|
31
|
-
property({ type: Array })
|
|
32
|
-
], BaseElement.prototype, "cells", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
property({ type: String, attribute: false })
|
|
35
|
-
], BaseElement.prototype, "config", void 0);
|
|
36
|
-
__decorate([
|
|
37
|
-
property({ type: Array })
|
|
38
|
-
], BaseElement.prototype, "uischemas", void 0);
|
|
39
|
-
__decorate([
|
|
40
|
-
property({ type: Boolean })
|
|
41
|
-
], BaseElement.prototype, "enabled", void 0);
|
|
42
|
-
__decorate([
|
|
43
|
-
property({ type: Boolean })
|
|
44
|
-
], BaseElement.prototype, "visible", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
property({ type: String })
|
|
47
|
-
], BaseElement.prototype, "path", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
property({ type: String })
|
|
50
|
-
], BaseElement.prototype, "label", void 0);
|
|
51
|
-
__decorate([
|
|
52
|
-
property({ type: Boolean })
|
|
53
|
-
], BaseElement.prototype, "required", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
property()
|
|
56
|
-
], BaseElement.prototype, "errors", void 0);
|
|
57
|
-
//# sourceMappingURL=base-element.js.map
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,r){var a,p=arguments.length,d=p<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)d=Reflect.decorate(e,t,o,r);else for(var i=e.length-1;i>=0;i--)(a=e[i])&&(d=(p<3?a(d):p>3?a(t,o,d):a(t,o))||d);return p>3&&d&&Object.defineProperty(t,o,d),d};import{LitElement as e}from"lit";import{property as t}from"lit/decorators.js";export class BaseElement extends e{set props(e){delete e.id,Object.assign(this,e)}}__decorate([t({type:Object})],BaseElement.prototype,"state",void 0),__decorate([t({type:Object})],BaseElement.prototype,"uischema",void 0),__decorate([t({type:Object})],BaseElement.prototype,"schema",void 0),__decorate([t({type:String,attribute:!1})],BaseElement.prototype,"data",void 0),__decorate([t({type:Array})],BaseElement.prototype,"renderers",void 0),__decorate([t({type:Array})],BaseElement.prototype,"cells",void 0),__decorate([t({type:String,attribute:!1})],BaseElement.prototype,"config",void 0),__decorate([t({type:Array})],BaseElement.prototype,"uischemas",void 0),__decorate([t({type:Boolean})],BaseElement.prototype,"enabled",void 0),__decorate([t({type:Boolean})],BaseElement.prototype,"visible",void 0),__decorate([t({type:String})],BaseElement.prototype,"path",void 0),__decorate([t({type:String})],BaseElement.prototype,"label",void 0),__decorate([t({type:Boolean})],BaseElement.prototype,"required",void 0),__decorate([t()],BaseElement.prototype,"errors",void 0);
|
|
@@ -1,287 +1,93 @@
|
|
|
1
|
-
var __decorate =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, Paths, Resolve, update } from "@jsonforms/core";
|
|
8
|
-
import { css, html, unsafeCSS } from "lit";
|
|
9
|
-
import { customElement, property } from "lit/decorators.js";
|
|
10
|
-
import { controlWithoutLabel, getCombinatorInfos, getTemplateFromProps, showJsonEditor } from "../util";
|
|
11
|
-
import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
|
|
12
|
-
import { i18next } from "@openremote/or-translate";
|
|
13
|
-
import { OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
|
|
14
|
-
import "@openremote/or-mwc-components/or-mwc-list";
|
|
15
|
-
import { addItemOrParameterDialogStyle, baseStyle, panelStyle } from "../styles";
|
|
16
|
-
import { DefaultColor4, DefaultColor5 } from "@openremote/core";
|
|
17
|
-
import { ControlBaseElement } from "./control-base-element";
|
|
18
|
-
import { getTemplateWrapper } from "../index";
|
|
19
|
-
// language=CSS
|
|
20
|
-
const style = css `
|
|
21
|
-
.item-border, .drag-handle {
|
|
22
|
-
border-color: var(--or-app-color5, ${unsafeCSS(DefaultColor5)});
|
|
23
|
-
border-radius: 4px;
|
|
24
|
-
border-width: 1px;
|
|
25
|
-
border-style: solid;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.item-wrapper {
|
|
29
|
-
display: flex;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.item-wrapper > .item-container {
|
|
33
|
-
flex: 1;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.item-wrapper + .item-wrapper {
|
|
37
|
-
padding-top: 10px;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.item-wrapper > .item-container > .item-container {
|
|
41
|
-
margin: 0;
|
|
42
|
-
flex: 1;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
.item-wrapper > .item-container > .item-container > .delete-container {
|
|
46
|
-
display: none;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
.item-wrapper > .item-container > .item-container :first-child {
|
|
50
|
-
padding: 0;
|
|
51
|
-
margin: 0;
|
|
52
|
-
flex: 1;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
.item-wrapper.dragging > .item-container {
|
|
56
|
-
opacity: 0.5;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.item-wrapper.indicator-after {
|
|
60
|
-
border-bottom-width: 3px;
|
|
61
|
-
border-bottom-style: solid;
|
|
62
|
-
border-bottom-color: var(--or-app-color4, ${unsafeCSS(DefaultColor4)});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.item-wrapper.indicator-before {
|
|
66
|
-
border-top-width: 3px;
|
|
67
|
-
border-top-style: solid;
|
|
68
|
-
border-top-color: var(--or-app-color4, ${unsafeCSS(DefaultColor4)});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
.drag-container > button {
|
|
72
|
-
cursor: grab;
|
|
73
|
-
}
|
|
74
|
-
`;
|
|
75
|
-
let ControlArrayElement = class ControlArrayElement extends ControlBaseElement {
|
|
76
|
-
static get styles() {
|
|
77
|
-
return [
|
|
78
|
-
baseStyle,
|
|
79
|
-
panelStyle,
|
|
80
|
-
style
|
|
81
|
-
];
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,r,i){var o,a=arguments.length,s=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(o=e[n])&&(s=(a<3?o(s):a>3?o(t,r,s):o(t,r))||s);return a>3&&s&&Object.defineProperty(t,r,s),s};import{computeLabel as e,createDefaultValue as t,mapDispatchToArrayControlProps as r,Paths as i,Resolve as o,update as a}from"@jsonforms/core";import{css as s,html as n,unsafeCSS as d}from"lit";import{customElement as l,property as m}from"lit/decorators.js";import{controlWithoutLabel as c,getCombinatorInfos as p,getTemplateFromProps as h,showJsonEditor as g}from"../util";import{InputType as f}from"@openremote/or-mwc-components/or-mwc-input";import{i18next as u}from"@openremote/or-translate";import{OrMwcDialog as v,showDialog as b}from"@openremote/or-mwc-components/or-mwc-dialog";import"@openremote/or-mwc-components/or-mwc-list";import{addItemOrParameterDialogStyle as w,baseStyle as y,panelStyle as A}from"../styles";import{DefaultColor4 as I,DefaultColor5 as x}from"@openremote/core";import{ControlBaseElement as $}from"./control-base-element";import{getTemplateWrapper as E}from"../index";let style=s`
|
|
2
|
+
.item-border, .drag-handle {
|
|
3
|
+
border-color: var(--or-app-color5, ${d(x)});
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
border-width: 1px;
|
|
6
|
+
border-style: solid;
|
|
82
7
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.resolvedSchema = Resolve.schema(this.schema, 'items', this.rootSchema);
|
|
87
|
-
if (Array.isArray(this.resolvedSchema.anyOf)) {
|
|
88
|
-
this.itemInfos = getCombinatorInfos(this.resolvedSchema.anyOf, this.rootSchema);
|
|
89
|
-
}
|
|
90
|
-
else if (Array.isArray(this.resolvedSchema.oneOf)) {
|
|
91
|
-
this.itemInfos = getCombinatorInfos(this.resolvedSchema.oneOf, this.rootSchema);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (_changedProperties.has("state")) {
|
|
95
|
-
const dispatchMethods = mapDispatchToArrayControlProps(this.state.dispatch);
|
|
96
|
-
this.addItem = (value) => dispatchMethods.addItem(this.path, value)();
|
|
97
|
-
this.removeItem = (index) => {
|
|
98
|
-
dispatchMethods.removeItems(this.path, [index])();
|
|
99
|
-
};
|
|
100
|
-
this.moveItem = (fromIndex, toIndex) => {
|
|
101
|
-
const move = (input, from, to) => {
|
|
102
|
-
let numberOfDeletedElm = 1;
|
|
103
|
-
const elm = input.splice(from, numberOfDeletedElm)[0];
|
|
104
|
-
numberOfDeletedElm = 0;
|
|
105
|
-
input.splice(to, numberOfDeletedElm, elm);
|
|
106
|
-
};
|
|
107
|
-
this.state.dispatch(update(this.path, array => {
|
|
108
|
-
move(array, fromIndex, toIndex);
|
|
109
|
-
return array;
|
|
110
|
-
}));
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return super.shouldUpdate(_changedProperties);
|
|
8
|
+
|
|
9
|
+
.item-wrapper {
|
|
10
|
+
display: flex;
|
|
114
11
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const itemCount = Array.isArray(this.data) ? this.data.length : 0;
|
|
119
|
-
const header = this.minimal ? `` : html `
|
|
120
|
-
<span slot="header">${this.label ? computeLabel(this.label, this.required, false) : ""}</span>
|
|
121
|
-
<div id="header-description" slot="header-description">
|
|
122
|
-
<div id="errors">
|
|
123
|
-
${!this.errors ? `` : html `<or-icon icon="alert"></or-icon><span>${this.errors}</span>`}
|
|
124
|
-
</div>
|
|
125
|
-
<div id="header-buttons"><or-mwc-input .type="${InputType.BUTTON}" outlined label="json" icon="pencil" @or-mwc-input-changed="${(ev) => this._showJson(ev)}"></or-mwc-input></div>
|
|
126
|
-
</div>
|
|
127
|
-
`;
|
|
128
|
-
const content = html `
|
|
129
|
-
${header}
|
|
130
|
-
<div id="content-wrapper" slot="content">
|
|
131
|
-
<div id="content" @dragover="${(ev) => this._onDragOver(ev)}">
|
|
132
|
-
|
|
133
|
-
${!Array.isArray(this.data) ? `` : this.data.map((item, index) => {
|
|
134
|
-
const childPath = Paths.compose(this.path, "" + index);
|
|
135
|
-
const props = {
|
|
136
|
-
renderers: this.renderers,
|
|
137
|
-
uischema: controlWithoutLabel("#"),
|
|
138
|
-
schema: this.resolvedSchema,
|
|
139
|
-
path: childPath
|
|
140
|
-
};
|
|
141
|
-
return this.getArrayItemWrapper(getTemplateFromProps(this.state, props) || html ``, index);
|
|
142
|
-
})}
|
|
143
|
-
|
|
144
|
-
</div>
|
|
145
|
-
${this.errors ? `` : html `
|
|
146
|
-
<div id="footer">
|
|
147
|
-
<or-mwc-input .disabled="${itemCount && itemCount >= maxItems}" .type="${InputType.BUTTON}" label="addItem" icon="plus" @or-mwc-input-changed="${() => this.doAddItem()}"></or-mwc-input>
|
|
148
|
-
</div>
|
|
149
|
-
`}
|
|
150
|
-
</div>
|
|
151
|
-
`;
|
|
152
|
-
return this.minimal ? html `<div>${content}</div>` : html `<or-collapsible-panel>${content}</or-collapsible-panel>`;
|
|
12
|
+
|
|
13
|
+
.item-wrapper > .item-container {
|
|
14
|
+
flex: 1;
|
|
153
15
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
<div class="drag-container">
|
|
158
|
-
<button draggable="true" @dragstart="${(ev) => this._onDragStart(ev)}" @dragend="${(ev) => this._onDragEnd(ev)}" class="draggable button-clear"><or-icon icon="menu"></or-icon></input>
|
|
159
|
-
</div>
|
|
160
|
-
${getTemplateWrapper(elementTemplate, () => this.removeItem(index))}
|
|
161
|
-
</div>
|
|
162
|
-
`;
|
|
16
|
+
|
|
17
|
+
.item-wrapper + .item-wrapper {
|
|
18
|
+
padding-top: 10px;
|
|
163
19
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const itemContainerElem = itemWrapperElem.lastElementChild;
|
|
169
|
-
ev.dataTransfer.setDragImage(itemContainerElem, (itemContainerElem.getBoundingClientRect().width / 2) - 50, 0);
|
|
20
|
+
|
|
21
|
+
.item-wrapper > .item-container > .item-container {
|
|
22
|
+
margin: 0;
|
|
23
|
+
flex: 1;
|
|
170
24
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const itemWrapperElem = buttonElem.parentElement.parentElement;
|
|
175
|
-
itemWrapperElem.classList.remove("dragging");
|
|
176
|
-
const index = Number(itemWrapperElem.getAttribute("data-index"));
|
|
177
|
-
const afterIndex = Math.max(0, (itemWrapperElem.getAttribute("data-after-index") !== null ? Number(itemWrapperElem.getAttribute("data-after-index")) : draggables.length) - 1);
|
|
178
|
-
draggables.forEach(draggable => draggable.classList.remove("indicator-before", "indicator-after"));
|
|
179
|
-
if (index === afterIndex) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
this.moveItem(index, afterIndex);
|
|
25
|
+
|
|
26
|
+
.item-wrapper > .item-container > .item-container > .delete-container {
|
|
27
|
+
display: none;
|
|
183
28
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
ev.preventDefault();
|
|
190
|
-
const draggables = [...this.shadowRoot.querySelectorAll(".item-wrapper:not(.dragging)")];
|
|
191
|
-
const initial = { offset: Number.NEGATIVE_INFINITY, element: null };
|
|
192
|
-
const afterItem = draggables.reduce((closest, child) => {
|
|
193
|
-
const box = child.getBoundingClientRect();
|
|
194
|
-
const offset = ev.clientY - box.top - box.height / 2;
|
|
195
|
-
if (offset < 0 && offset > closest.offset) {
|
|
196
|
-
return { offset: offset, element: child };
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
return closest;
|
|
200
|
-
}
|
|
201
|
-
}, initial).element;
|
|
202
|
-
draggables.forEach(draggable => draggable.classList.remove("indicator-before", "indicator-after"));
|
|
203
|
-
if (afterItem === null) {
|
|
204
|
-
draggables[draggables.length - 1].classList.add("indicator-after");
|
|
205
|
-
dragging.removeAttribute("data-after-index");
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
afterItem.classList.add("indicator-before");
|
|
209
|
-
const afterIndex = afterItem.getAttribute("data-index");
|
|
210
|
-
dragging.setAttribute("data-after-index", afterIndex);
|
|
211
|
-
}
|
|
29
|
+
|
|
30
|
+
.item-wrapper > .item-container > .item-container :first-child {
|
|
31
|
+
padding: 0;
|
|
32
|
+
margin: 0;
|
|
33
|
+
flex: 1;
|
|
212
34
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
this.handleChange(this.path || "", newValue);
|
|
217
|
-
}));
|
|
35
|
+
|
|
36
|
+
.item-wrapper.dragging > .item-container {
|
|
37
|
+
opacity: 0.5;
|
|
218
38
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this.showAddDialog();
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
this.addItem(createDefaultValue(this.resolvedSchema, this.rootSchema));
|
|
228
|
-
}
|
|
39
|
+
|
|
40
|
+
.item-wrapper.indicator-after {
|
|
41
|
+
border-bottom-width: 3px;
|
|
42
|
+
border-bottom-style: solid;
|
|
43
|
+
border-bottom-color: var(--or-app-color4, ${d(I)});
|
|
229
44
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
text: labelStr,
|
|
236
|
-
value: labelStr,
|
|
237
|
-
data: itemInfo
|
|
238
|
-
};
|
|
239
|
-
});
|
|
240
|
-
const onParamChanged = (itemInfo) => {
|
|
241
|
-
selectedItemInfo = itemInfo;
|
|
242
|
-
const descElem = dialog.shadowRoot.getElementById("parameter-desc");
|
|
243
|
-
descElem.innerHTML = itemInfo.description || "";
|
|
244
|
-
dialog.shadowRoot.getElementById("add-btn").disabled = false;
|
|
245
|
-
};
|
|
246
|
-
const dialog = showDialog(new OrMwcDialog()
|
|
247
|
-
.setContent(html `
|
|
248
|
-
<div class="col">
|
|
249
|
-
<form id="mdc-dialog-form-add" class="row">
|
|
250
|
-
<div id="type-list" class="col">
|
|
251
|
-
<or-mwc-list @or-mwc-list-changed="${(evt) => { if (evt.detail.length === 1)
|
|
252
|
-
onParamChanged(evt.detail[0].data); }}" .listItems="${listItems.sort((a, b) => a.text.localeCompare(b.text))}" id="parameter-list"></or-mwc-list>
|
|
253
|
-
</div>
|
|
254
|
-
<div id="parameter-desc" class="col"></div>
|
|
255
|
-
</form>
|
|
256
|
-
</div>
|
|
257
|
-
`)
|
|
258
|
-
.setStyles(addItemOrParameterDialogStyle)
|
|
259
|
-
.setHeading((this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addItem"))
|
|
260
|
-
.setActions([
|
|
261
|
-
{
|
|
262
|
-
actionName: "cancel",
|
|
263
|
-
content: "cancel"
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
default: true,
|
|
267
|
-
actionName: "add",
|
|
268
|
-
action: () => {
|
|
269
|
-
if (selectedItemInfo) {
|
|
270
|
-
const value = selectedItemInfo.defaultValueCreator();
|
|
271
|
-
this.addItem(value);
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
content: html `<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" disabled label="add"></or-mwc-input>`
|
|
275
|
-
}
|
|
276
|
-
])
|
|
277
|
-
.setDismissAction(null));
|
|
45
|
+
|
|
46
|
+
.item-wrapper.indicator-before {
|
|
47
|
+
border-top-width: 3px;
|
|
48
|
+
border-top-style: solid;
|
|
49
|
+
border-top-color: var(--or-app-color4, ${d(I)});
|
|
278
50
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
ControlArrayElement =
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
51
|
+
|
|
52
|
+
.drag-container > button {
|
|
53
|
+
cursor: grab;
|
|
54
|
+
}
|
|
55
|
+
`,ControlArrayElement=class extends ${static get styles(){return[y,A,style]}shouldUpdate(e){if(e.has("schema")&&(this.itemInfos=void 0,this.resolvedSchema=o.schema(this.schema,"items",this.rootSchema),Array.isArray(this.resolvedSchema.anyOf)?this.itemInfos=p(this.resolvedSchema.anyOf,this.rootSchema):Array.isArray(this.resolvedSchema.oneOf)&&(this.itemInfos=p(this.resolvedSchema.oneOf,this.rootSchema))),e.has("state")){let e=r(this.state.dispatch);this.addItem=t=>e.addItem(this.path,t)(),this.removeItem=t=>{e.removeItems(this.path,[t])()},this.moveItem=(e,t)=>{this.state.dispatch(a(this.path,r=>{let i=1,o=r.splice(e,i)[0];return i=0,r.splice(t,i,o),r}))}}return super.shouldUpdate(e)}render(){var t;let r=null!=(t=this.schema.maxItems)?t:Number.MAX_SAFE_INTEGER,o=Array.isArray(this.data)?this.data.length:0,a=this.minimal?"":n`
|
|
56
|
+
<span slot="header">${this.label?e(this.label,this.required,!1):""}</span>
|
|
57
|
+
<div id="header-description" slot="header-description">
|
|
58
|
+
<div id="errors">
|
|
59
|
+
${!this.errors?"":n`<or-icon icon="alert"></or-icon><span>${this.errors}</span>`}
|
|
60
|
+
</div>
|
|
61
|
+
<div id="header-buttons"><or-mwc-input .type="${f.BUTTON}" outlined label="json" icon="pencil" @or-mwc-input-changed="${e=>this._showJson(e)}"></or-mwc-input></div>
|
|
62
|
+
</div>
|
|
63
|
+
`,s=n`
|
|
64
|
+
${a}
|
|
65
|
+
<div id="content-wrapper" slot="content">
|
|
66
|
+
<div id="content" @dragover="${e=>this._onDragOver(e)}">
|
|
67
|
+
|
|
68
|
+
${!Array.isArray(this.data)?"":this.data.map((e,t)=>{let r=i.compose(this.path,""+t),o={renderers:this.renderers,uischema:c("#"),schema:this.resolvedSchema,path:r};return this.getArrayItemWrapper(h(this.state,o)||n``,t)})}
|
|
69
|
+
|
|
70
|
+
</div>
|
|
71
|
+
${this.errors?"":n`
|
|
72
|
+
<div id="footer">
|
|
73
|
+
<or-mwc-input .disabled="${o&&o>=r}" .type="${f.BUTTON}" label="addItem" icon="plus" @or-mwc-input-changed="${()=>this.doAddItem()}"></or-mwc-input>
|
|
74
|
+
</div>
|
|
75
|
+
`}
|
|
76
|
+
</div>
|
|
77
|
+
`;return this.minimal?n`<div>${s}</div>`:n`<or-collapsible-panel>${s}</or-collapsible-panel>`}getArrayItemWrapper(e,t){return n`
|
|
78
|
+
<div class="item-wrapper" data-index="${t}">
|
|
79
|
+
<div class="drag-container">
|
|
80
|
+
<button draggable="true" @dragstart="${e=>this._onDragStart(e)}" @dragend="${e=>this._onDragEnd(e)}" class="draggable button-clear"><or-icon icon="menu"></or-icon></input>
|
|
81
|
+
</div>
|
|
82
|
+
${E(e,()=>this.removeItem(t))}
|
|
83
|
+
</div>
|
|
84
|
+
`}_onDragStart(e){let t=e.currentTarget.parentElement.parentElement;t.classList.add("dragging");let r=t.lastElementChild;e.dataTransfer.setDragImage(r,r.getBoundingClientRect().width/2-50,0)}_onDragEnd(e){let t=[...this.shadowRoot.querySelectorAll(".item-wrapper")],r=e.currentTarget.parentElement.parentElement;r.classList.remove("dragging");let i=Number(r.getAttribute("data-index")),o=Math.max(0,(null!==r.getAttribute("data-after-index")?Number(r.getAttribute("data-after-index")):t.length)-1);t.forEach(e=>e.classList.remove("indicator-before","indicator-after")),i!==o&&this.moveItem(i,o)}_onDragOver(e){let t=this.shadowRoot.querySelector(".dragging");if(!t)return;e.preventDefault();let r=[...this.shadowRoot.querySelectorAll(".item-wrapper:not(.dragging)")],i=r.reduce((t,r)=>{let i=r.getBoundingClientRect(),o=e.clientY-i.top-i.height/2;return o<0&&o>t.offset?{offset:o,element:r}:t},{offset:-1/0,element:null}).element;if(r.forEach(e=>e.classList.remove("indicator-before","indicator-after")),null===i)r[r.length-1].classList.add("indicator-after"),t.removeAttribute("data-after-index");else{i.classList.add("indicator-before");let e=i.getAttribute("data-index");t.setAttribute("data-after-index",e)}}_showJson(e){e.stopPropagation(),g(this.title||this.schema.title||"",this.data,e=>{this.handleChange(this.path||"",e)})}doAddItem(){this.resolvedSchema&&(this.itemInfos?this.showAddDialog():this.addItem(t(this.resolvedSchema,this.rootSchema)))}showAddDialog(){let t,r=this.itemInfos.map((t,r)=>{let i=t.title?e(t.title,!1,!0):"";return{text:i,value:i,data:t}}),i=b(new v().setContent(n`
|
|
85
|
+
<div class="col">
|
|
86
|
+
<form id="mdc-dialog-form-add" class="row">
|
|
87
|
+
<div id="type-list" class="col">
|
|
88
|
+
<or-mwc-list @or-mwc-list-changed="${e=>{var r;1===e.detail.length&&(t=r=e.detail[0].data,i.shadowRoot.getElementById("parameter-desc").innerHTML=r.description||"",i.shadowRoot.getElementById("add-btn").disabled=!1)}}" .listItems="${r.sort((e,t)=>e.text.localeCompare(t.text))}" id="parameter-list"></or-mwc-list>
|
|
89
|
+
</div>
|
|
90
|
+
<div id="parameter-desc" class="col"></div>
|
|
91
|
+
</form>
|
|
92
|
+
</div>
|
|
93
|
+
`).setStyles(w).setHeading((this.label?e(this.label,this.required,!1)+" - ":"")+u.t("addItem")).setActions([{actionName:"cancel",content:"cancel"},{default:!0,actionName:"add",action:()=>{if(t){let e=t.defaultValueCreator();this.addItem(e)}},content:n`<or-mwc-input id="add-btn" .type="${f.BUTTON}" disabled label="add"></or-mwc-input>`}]).setDismissAction(null))}};__decorate([m()],ControlArrayElement.prototype,"minimal",void 0),ControlArrayElement=__decorate([l("or-json-forms-array-control")],ControlArrayElement);export{ControlArrayElement};
|
|
@@ -1,48 +1 @@
|
|
|
1
|
-
var __decorate
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { createId, isControl, mapDispatchToControlProps, removeId } from "@jsonforms/core";
|
|
8
|
-
import { property } from "lit/decorators.js";
|
|
9
|
-
import { BaseElement } from "../base-element";
|
|
10
|
-
export class ControlBaseElement extends BaseElement {
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
updated(_changedProperties) {
|
|
15
|
-
super.updated(_changedProperties);
|
|
16
|
-
if (_changedProperties.has("state")) {
|
|
17
|
-
const { handleChange } = mapDispatchToControlProps(this.state.dispatch);
|
|
18
|
-
this.handleChange = handleChange;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
shouldUpdate(changedProperties) {
|
|
22
|
-
var _a;
|
|
23
|
-
if (changedProperties.has("uischema")) {
|
|
24
|
-
if (isControl(this.uischema)) {
|
|
25
|
-
const oldSchemaValue = changedProperties.get("uischema");
|
|
26
|
-
if ((oldSchemaValue === null || oldSchemaValue === void 0 ? void 0 : oldSchemaValue.scope) !== ((_a = this.uischema) === null || _a === void 0 ? void 0 : _a.scope)) {
|
|
27
|
-
if (this.id) {
|
|
28
|
-
removeId(this.id);
|
|
29
|
-
}
|
|
30
|
-
this.id = createId(this.uischema.scope);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
disconnectedCallback() {
|
|
37
|
-
if (isControl(this.uischema)) {
|
|
38
|
-
removeId(this.id);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
__decorate([
|
|
43
|
-
property()
|
|
44
|
-
], ControlBaseElement.prototype, "description", void 0);
|
|
45
|
-
__decorate([
|
|
46
|
-
property()
|
|
47
|
-
], ControlBaseElement.prototype, "rootSchema", void 0);
|
|
48
|
-
//# sourceMappingURL=control-base-element.js.map
|
|
1
|
+
var __decorate=this&&this.__decorate||function(e,t,o,s){var r,i=arguments.length,a=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,s);else for(var c=e.length-1;c>=0;c--)(r=e[c])&&(a=(i<3?r(a):i>3?r(t,o,a):r(t,o))||a);return i>3&&a&&Object.defineProperty(t,o,a),a};import{createId as e,isControl as t,mapDispatchToControlProps as o,removeId as s}from"@jsonforms/core";import{property as r}from"lit/decorators.js";import{BaseElement as i}from"../base-element";export class ControlBaseElement extends i{constructor(){super()}updated(e){if(super.updated(e),e.has("state")){let{handleChange:e}=o(this.state.dispatch);this.handleChange=e}}shouldUpdate(o){var r;if(o.has("uischema")&&t(this.uischema)){let t=o.get("uischema");(null==t?void 0:t.scope)!==(null==(r=this.uischema)?void 0:r.scope)&&(this.id&&s(this.id),this.id=e(this.uischema.scope))}return!0}disconnectedCallback(){t(this.uischema)&&s(this.id)}}__decorate([r()],ControlBaseElement.prototype,"description",void 0),__decorate([r()],ControlBaseElement.prototype,"rootSchema",void 0);
|