@schukai/monster 3.71.3 → 3.73.0
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/CHANGELOG.md +27 -0
- package/package.json +1 -1
- package/source/components/datatable/dataset.mjs +268 -272
- package/source/components/datatable/datasource/dom.mjs +2 -2
- package/source/components/datatable/datasource/rest.mjs +408 -410
- package/source/components/datatable/filter.mjs +0 -1
- package/source/components/datatable/style/datatable.pcss +7 -5
- package/source/components/datatable/style/embedded-pagination.pcss +1 -1
- package/source/components/datatable/style/pagination.pcss +1 -1
- package/source/components/datatable/stylesheet/change-button.mjs +2 -4
- package/source/components/datatable/stylesheet/column-bar.mjs +2 -4
- package/source/components/datatable/stylesheet/dataset.mjs +2 -4
- package/source/components/datatable/stylesheet/datasource.mjs +1 -3
- package/source/components/datatable/stylesheet/datatable.mjs +2 -4
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/filter-button.mjs +1 -3
- package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +14 -7
- package/source/components/datatable/stylesheet/filter-date-range.mjs +1 -3
- package/source/components/datatable/stylesheet/filter-range.mjs +1 -3
- package/source/components/datatable/stylesheet/filter.mjs +2 -4
- package/source/components/datatable/stylesheet/pagination.mjs +2 -4
- package/source/components/datatable/stylesheet/save-button.mjs +2 -4
- package/source/components/datatable/stylesheet/select-filter.mjs +2 -4
- package/source/components/datatable/stylesheet/status.mjs +2 -4
- package/source/components/form/context-help.mjs +1 -1
- package/source/components/form/field-set.mjs +219 -219
- package/source/components/form/form.mjs +309 -185
- package/source/components/form/reload.mjs +211 -211
- package/source/components/form/select.mjs +12 -13
- package/source/components/form/style/field-set.pcss +2 -2
- package/source/components/form/style/form.pcss +8 -0
- package/source/components/form/stylesheet/action-button.mjs +2 -4
- package/source/components/form/stylesheet/api-button.mjs +1 -3
- package/source/components/form/stylesheet/button-bar.mjs +2 -4
- package/source/components/form/stylesheet/button.mjs +2 -4
- package/source/components/form/stylesheet/confirm-button.mjs +2 -4
- package/source/components/form/stylesheet/context-error.mjs +2 -4
- package/source/components/form/stylesheet/context-help.mjs +2 -4
- package/source/components/form/stylesheet/field-set.mjs +14 -7
- package/source/components/form/stylesheet/form.mjs +14 -7
- package/source/components/form/stylesheet/message-state-button.mjs +1 -3
- package/source/components/form/stylesheet/popper-button.mjs +2 -4
- package/source/components/form/stylesheet/select.mjs +14 -7
- package/source/components/form/stylesheet/state-button.mjs +2 -4
- package/source/components/form/stylesheet/tree-select.mjs +1 -3
- package/source/components/host/stylesheet/call-button.mjs +2 -4
- package/source/components/host/stylesheet/config-manager.mjs +1 -3
- package/source/components/host/stylesheet/host.mjs +2 -4
- package/source/components/host/stylesheet/overlay.mjs +2 -4
- package/source/components/host/stylesheet/toggle-button.mjs +2 -4
- package/source/components/host/stylesheet/viewer.mjs +2 -4
- package/source/components/layout/style/collapse.pcss +2 -2
- package/source/components/layout/style/details.pcss +2 -2
- package/source/components/layout/stylesheet/collapse.mjs +14 -7
- package/source/components/layout/stylesheet/details.mjs +2 -4
- package/source/components/layout/stylesheet/panel.mjs +2 -4
- package/source/components/layout/stylesheet/popper.mjs +2 -4
- package/source/components/layout/stylesheet/split-panel.mjs +1 -3
- package/source/components/layout/stylesheet/tabs.mjs +2 -4
- package/source/components/layout/stylesheet/width-toggle.mjs +1 -3
- package/source/components/layout/tabs.mjs +0 -1
- package/source/components/navigation/stylesheet/table-of-content.mjs +2 -4
- package/source/components/notify/stylesheet/message.mjs +2 -4
- package/source/components/notify/stylesheet/notify.mjs +2 -4
- package/source/components/state/stylesheet/log.mjs +2 -4
- package/source/components/state/stylesheet/state.mjs +2 -4
- package/source/components/style/control.pcss +5 -0
- package/source/components/style/data-grid.pcss +2 -2
- package/source/components/style/mixin/typography.pcss +7 -1
- package/source/components/style/normalize.pcss +1 -1
- package/source/components/stylesheet/badge.mjs +1 -3
- package/source/components/stylesheet/border.mjs +1 -3
- package/source/components/stylesheet/button.mjs +1 -3
- package/source/components/stylesheet/card.mjs +1 -3
- package/source/components/stylesheet/color.mjs +1 -3
- package/source/components/stylesheet/common.mjs +1 -3
- package/source/components/stylesheet/control.mjs +2 -4
- package/source/components/stylesheet/data-grid.mjs +2 -4
- package/source/components/stylesheet/display.mjs +1 -3
- package/source/components/stylesheet/floating-ui.mjs +1 -3
- package/source/components/stylesheet/form.mjs +13 -6
- package/source/components/stylesheet/host.mjs +1 -3
- package/source/components/stylesheet/icons.mjs +1 -3
- package/source/components/stylesheet/mixin/badge.mjs +1 -3
- package/source/components/stylesheet/mixin/button.mjs +1 -3
- package/source/components/stylesheet/mixin/form.mjs +13 -6
- package/source/components/stylesheet/mixin/hover.mjs +1 -3
- package/source/components/stylesheet/mixin/icon.mjs +1 -3
- package/source/components/stylesheet/mixin/media.mjs +1 -3
- package/source/components/stylesheet/mixin/property.mjs +13 -6
- package/source/components/stylesheet/mixin/skeleton.mjs +1 -3
- package/source/components/stylesheet/mixin/spinner.mjs +1 -3
- package/source/components/stylesheet/mixin/typography.mjs +1 -3
- package/source/components/stylesheet/normalize.mjs +1 -3
- package/source/components/stylesheet/popper.mjs +1 -3
- package/source/components/stylesheet/property.mjs +2 -4
- package/source/components/stylesheet/ripple.mjs +1 -3
- package/source/components/stylesheet/skeleton.mjs +1 -3
- package/source/components/stylesheet/space.mjs +1 -3
- package/source/components/stylesheet/spinner.mjs +1 -3
- package/source/components/stylesheet/table.mjs +1 -3
- package/source/components/stylesheet/theme.mjs +1 -3
- package/source/components/stylesheet/typography.mjs +13 -6
- package/source/components/tree-menu/dragable-tree-menu.mjs +693 -0
- package/source/components/tree-menu/style/tree-menu.pcss +69 -42
- package/source/components/tree-menu/stylesheet/tree-menu.mjs +2 -4
- package/source/components/tree-menu/tree-menu.mjs +260 -331
- package/source/data/datasource/server/restapi.mjs +194 -191
- package/source/data/datasource/server.mjs +107 -105
- package/source/data/diff.mjs +1 -1
- package/source/dom/constants.mjs +18 -0
- package/source/dom/customelement.mjs +2 -6
- package/source/dom/slotted.mjs +6 -1
- package/source/dom/updater.mjs +2 -0
- package/test/cases/components/host/details.mjs +1 -1
- package/test/cases/components/host/host.mjs +1 -1
- package/test/cases/components/host/overlay.mjs +1 -1
- package/test/cases/dom/customcontrol.mjs +1 -1
- package/test/cases/dom/customelement.mjs +2 -2
|
@@ -12,206 +12,222 @@
|
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {TokenList} from "../../types/tokenlist.mjs";
|
|
18
|
-
import {DeadMansSwitch} from "../../util/deadmansswitch.mjs";
|
|
19
|
-
import {DataSet} from "../datatable/dataset.mjs";
|
|
20
|
-
//import { Datasource } from "../../data/datasource.mjs";
|
|
21
|
-
import {RestAPI} from "../../data/datasource/server/restapi.mjs";
|
|
22
|
-
import {WebConnect} from "../../data/datasource/server/webconnect.mjs";
|
|
23
|
-
import {WriteError} from "../../data/datasource/server/restapi/writeerror.mjs";
|
|
24
|
-
import {LocalStorage} from "../../data/datasource/storage/localstorage.mjs";
|
|
25
|
-
import {SessionStorage} from "../../data/datasource/storage/sessionstorage.mjs";
|
|
15
|
+
import { internalSymbol } from "../../constants.mjs";
|
|
16
|
+
import { Pathfinder } from "../../data/pathfinder.mjs";
|
|
26
17
|
import {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ATTRIBUTE_UPDATER_ATTRIBUTES,
|
|
31
|
-
ATTRIBUTE_UPDATER_INSERT,
|
|
32
|
-
ATTRIBUTE_UPDATER_REMOVE,
|
|
33
|
-
ATTRIBUTE_UPDATER_REPLACE,
|
|
18
|
+
ATTRIBUTE_FORM_BIND,
|
|
19
|
+
ATTRIBUTE_FORM_BIND_TYPE,
|
|
20
|
+
ATTRIBUTE_UPDATER_BIND,
|
|
34
21
|
} from "../../dom/constants.mjs";
|
|
22
|
+
import { findTargetElementFromEvent } from "../../dom/events.mjs";
|
|
23
|
+
import { clone } from "../../util/clone.mjs";
|
|
24
|
+
import { DeadMansSwitch } from "../../util/deadmansswitch.mjs";
|
|
25
|
+
import { DataSet } from "../datatable/dataset.mjs";
|
|
35
26
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getSlottedElements,
|
|
27
|
+
assembleMethodSymbol,
|
|
28
|
+
registerCustomElement,
|
|
29
|
+
getSlottedElements,
|
|
40
30
|
} from "../../dom/customelement.mjs";
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {Observer} from "../../types/observer.mjs";
|
|
45
|
-
import {ProxyObserver} from "../../types/proxyobserver.mjs";
|
|
46
|
-
import {Processing} from "../../util/processing.mjs";
|
|
47
|
-
import {datasourceLinkedElementSymbol, handleDataSourceChanges} from "../datatable/util.mjs";
|
|
48
|
-
import {MessageStateButton} from "./message-state-button.mjs";
|
|
49
|
-
import {
|
|
50
|
-
ATTRIBUTE_FORM_DATASOURCE,
|
|
51
|
-
ATTRIBUTE_FORM_DATASOURCE_ARGUMENTS,
|
|
52
|
-
} from "./constants.mjs";
|
|
53
|
-
import {StateButton} from "./state-button.mjs";
|
|
54
|
-
import {FormStyleSheet} from "./stylesheet/form.mjs";
|
|
31
|
+
import { FormStyleSheet } from "./stylesheet/form.mjs";
|
|
32
|
+
import { diff } from "../../data/diff.mjs";
|
|
33
|
+
import { isString } from "../../types/is.mjs";
|
|
55
34
|
|
|
56
|
-
export {Form};
|
|
35
|
+
export { Form };
|
|
57
36
|
|
|
37
|
+
/**
|
|
38
|
+
* @private
|
|
39
|
+
* @type {symbol}
|
|
40
|
+
*/
|
|
41
|
+
const debounceWriteBackSymbol = Symbol("debounceWriteBack");
|
|
58
42
|
|
|
59
43
|
/**
|
|
60
44
|
* @private
|
|
61
45
|
* @type {symbol}
|
|
62
46
|
*/
|
|
63
|
-
const
|
|
47
|
+
const debounceBindSymbol = Symbol("debounceBind");
|
|
64
48
|
|
|
65
49
|
class Form extends DataSet {
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @property {Object} templates Template definitions
|
|
53
|
+
* @property {string} templates.main Main template
|
|
54
|
+
* @property {Object} classes Class definitions
|
|
55
|
+
* @property {string} classes.form Form class
|
|
56
|
+
* @property {Object} writeBack Write back definitions
|
|
57
|
+
* @property {string[]} writeBack.events Write back events
|
|
58
|
+
* @property {Object} bind Bind definitions
|
|
59
|
+
* @property {string[]} bind.events Bind events
|
|
60
|
+
* @property {Object} reportValidity Report validity definitions
|
|
61
|
+
* @property {string} reportValidity.selector Report validity selector
|
|
62
|
+
* @property {boolean} features.mutationObserver Mutation observer feature
|
|
63
|
+
* @property {boolean} features.writeBack Write back feature
|
|
64
|
+
* @property {boolean} features.bind Bind feature
|
|
65
|
+
*/
|
|
66
|
+
get defaults() {
|
|
67
|
+
const obj = Object.assign({}, super.defaults, {
|
|
68
|
+
templates: {
|
|
69
|
+
main: getTemplate(),
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
classes: {
|
|
73
|
+
form: "",
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
writeBack: {
|
|
77
|
+
events: ["change", "input", "keyup"],
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
bind: {
|
|
81
|
+
events: ["keyup", "click", "change", "drop", "touchend", "input"],
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
reportValidity: {
|
|
85
|
+
selector: "input,select,textarea",
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
obj["features"]["mutationObserver"] = false;
|
|
90
|
+
obj["features"]["writeBack"] = true;
|
|
91
|
+
obj["features"]["bind"] = true;
|
|
92
|
+
|
|
93
|
+
return obj;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
* @return {string}
|
|
99
|
+
*/
|
|
100
|
+
static getTag() {
|
|
101
|
+
return "monster-form";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @return {CSSStyleSheet[]}
|
|
106
|
+
*/
|
|
107
|
+
static getCSSStyleSheet() {
|
|
108
|
+
return [FormStyleSheet];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
*/
|
|
114
|
+
[assembleMethodSymbol]() {
|
|
115
|
+
super[assembleMethodSymbol]();
|
|
116
|
+
|
|
117
|
+
initControlReferences.call(this);
|
|
118
|
+
initEventHandler.call(this);
|
|
119
|
+
initDataSourceHandler.call(this);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* This method is called when the component is created.
|
|
124
|
+
* @since 3.70.0
|
|
125
|
+
* @returns {DataSet}
|
|
126
|
+
*/
|
|
127
|
+
refresh() {
|
|
128
|
+
this.write();
|
|
129
|
+
super.refresh();
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Run reportValidation on all child html form controls.
|
|
135
|
+
*
|
|
136
|
+
* @since 2.10.0
|
|
137
|
+
* @returns {boolean}
|
|
138
|
+
*/
|
|
139
|
+
reportValidity() {
|
|
140
|
+
let valid = true;
|
|
141
|
+
|
|
142
|
+
const selector = this.getOption("reportValidity.selector");
|
|
143
|
+
const nodes = getSlottedElements.call(this, selector);
|
|
144
|
+
|
|
145
|
+
nodes.forEach((node) => {
|
|
146
|
+
if (typeof node.reportValidity === "function") {
|
|
147
|
+
if (node.reportValidity() === false) {
|
|
148
|
+
valid = false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return valid;
|
|
154
|
+
}
|
|
164
155
|
}
|
|
165
156
|
|
|
166
|
-
function initDataSourceHandler() {
|
|
167
|
-
|
|
168
|
-
}
|
|
157
|
+
function initDataSourceHandler() {}
|
|
169
158
|
|
|
170
159
|
/**
|
|
171
160
|
* @private
|
|
172
161
|
* @returns {initEventHandler}
|
|
173
162
|
*/
|
|
174
163
|
function initEventHandler() {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
164
|
+
this[debounceBindSymbol] = {};
|
|
165
|
+
|
|
166
|
+
if (this.getOption("features.bind") === true) {
|
|
167
|
+
const events = this.getOption("bind.events");
|
|
168
|
+
|
|
169
|
+
for (const event of events) {
|
|
170
|
+
this.addEventListener(event, (e) => {
|
|
171
|
+
const element = findTargetElementFromEvent(e, ATTRIBUTE_FORM_BIND);
|
|
172
|
+
|
|
173
|
+
if (element === undefined) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (this[debounceBindSymbol][element] instanceof DeadMansSwitch) {
|
|
178
|
+
try {
|
|
179
|
+
this[debounceBindSymbol][element].touch();
|
|
180
|
+
return;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
if (e.message !== "has already run") {
|
|
183
|
+
throw e;
|
|
184
|
+
}
|
|
185
|
+
delete this[debounceBindSymbol][element];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this[debounceBindSymbol][element] = new DeadMansSwitch(200, () => {
|
|
190
|
+
retrieveAndSetValue.call(this, element);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (this.getOption("features.writeBack") === true) {
|
|
197
|
+
const events = this.getOption("writeBack.events");
|
|
198
|
+
for (const event of events) {
|
|
199
|
+
this.addEventListener(event, (e) => {
|
|
200
|
+
if (!this.reportValidity()) {
|
|
201
|
+
this.classList.add("invalid");
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
this.classList.remove("invalid");
|
|
204
|
+
}, 1000);
|
|
205
|
+
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (this[debounceWriteBackSymbol] instanceof DeadMansSwitch) {
|
|
210
|
+
try {
|
|
211
|
+
this[debounceWriteBackSymbol].touch();
|
|
212
|
+
return;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
if (e.message !== "has already run") {
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
217
|
+
delete this[debounceWriteBackSymbol];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this[debounceWriteBackSymbol] = new DeadMansSwitch(200, () => {
|
|
222
|
+
setTimeout(() => {
|
|
223
|
+
this.write();
|
|
224
|
+
}, 0);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return this;
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
/**
|
|
@@ -219,10 +235,118 @@ function initEventHandler() {
|
|
|
219
235
|
* @return {FilterButton}
|
|
220
236
|
*/
|
|
221
237
|
function initControlReferences() {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
238
|
+
if (!this.shadowRoot) {
|
|
239
|
+
throw new Error("no shadow-root is defined");
|
|
240
|
+
}
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @throws {Error} the bind argument must start as a value with a path
|
|
246
|
+
* @param {HTMLElement} element
|
|
247
|
+
* @return void
|
|
248
|
+
* @memberOf Monster.DOM
|
|
249
|
+
* @private
|
|
250
|
+
*/
|
|
251
|
+
function retrieveAndSetValue(element) {
|
|
252
|
+
let path = element.getAttribute(ATTRIBUTE_FORM_BIND);
|
|
253
|
+
if (path === null)
|
|
254
|
+
throw new Error("the bind argument must start as a value with a path");
|
|
255
|
+
|
|
256
|
+
if (path.indexOf("path:") !== 0) {
|
|
257
|
+
throw new Error("the bind argument must start as a value with a path");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
path = path.substring(5); // remove path: from the string
|
|
261
|
+
|
|
262
|
+
let value;
|
|
263
|
+
|
|
264
|
+
if (element instanceof HTMLInputElement) {
|
|
265
|
+
switch (element.type) {
|
|
266
|
+
case "checkbox":
|
|
267
|
+
value = element.checked ? element.value : undefined;
|
|
268
|
+
break;
|
|
269
|
+
default:
|
|
270
|
+
value = element.value;
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
274
|
+
value = element.value;
|
|
275
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
276
|
+
switch (element.type) {
|
|
277
|
+
case "select-one":
|
|
278
|
+
value = element.value;
|
|
279
|
+
break;
|
|
280
|
+
case "select-multiple":
|
|
281
|
+
value = element.value;
|
|
282
|
+
|
|
283
|
+
let options = element?.selectedOptions;
|
|
284
|
+
if (options === undefined)
|
|
285
|
+
options = element.querySelectorAll(":scope option:checked");
|
|
286
|
+
value = Array.from(options).map(({ value }) => value);
|
|
287
|
+
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// values from custom elements
|
|
292
|
+
} else if (
|
|
293
|
+
(element?.constructor?.prototype &&
|
|
294
|
+
!!Object.getOwnPropertyDescriptor(
|
|
295
|
+
element.constructor.prototype,
|
|
296
|
+
"value",
|
|
297
|
+
)?.["get"]) ||
|
|
298
|
+
element.hasOwnProperty("value")
|
|
299
|
+
) {
|
|
300
|
+
value = element?.["value"];
|
|
301
|
+
} else {
|
|
302
|
+
throw new Error("unsupported object");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (isString(value)) {
|
|
306
|
+
const type = element.getAttribute(ATTRIBUTE_FORM_BIND_TYPE);
|
|
307
|
+
switch (type) {
|
|
308
|
+
case "number":
|
|
309
|
+
case "int":
|
|
310
|
+
case "float":
|
|
311
|
+
case "integer":
|
|
312
|
+
value = Number(value);
|
|
313
|
+
if (isNaN(value)) {
|
|
314
|
+
value = 0;
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
case "boolean":
|
|
318
|
+
case "bool":
|
|
319
|
+
case "checkbox":
|
|
320
|
+
value = value === "true" || value === "1" || value === "on";
|
|
321
|
+
break;
|
|
322
|
+
case "array":
|
|
323
|
+
case "list":
|
|
324
|
+
value = value.split(",");
|
|
325
|
+
break;
|
|
326
|
+
case "object":
|
|
327
|
+
case "json":
|
|
328
|
+
value = JSON.parse(value);
|
|
329
|
+
break;
|
|
330
|
+
default:
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const copy = clone(this[internalSymbol].getRealSubject()?.options);
|
|
336
|
+
|
|
337
|
+
const pf = new Pathfinder(copy);
|
|
338
|
+
pf.setVia(path, value);
|
|
339
|
+
|
|
340
|
+
const diffResult = diff(copy, this[internalSymbol].getRealSubject()?.options);
|
|
341
|
+
|
|
342
|
+
if (diffResult.length > 0) {
|
|
343
|
+
setTimeout(() => {
|
|
344
|
+
this.setOption(path, value);
|
|
345
|
+
}, 100);
|
|
346
|
+
setTimeout(() => {
|
|
347
|
+
console.log(this[internalSymbol].getRealSubject().options.data);
|
|
348
|
+
}, 1000);
|
|
349
|
+
}
|
|
226
350
|
}
|
|
227
351
|
|
|
228
352
|
/**
|
|
@@ -230,8 +354,8 @@ function initControlReferences() {
|
|
|
230
354
|
* @return {string}
|
|
231
355
|
*/
|
|
232
356
|
function getTemplate() {
|
|
233
|
-
|
|
234
|
-
|
|
357
|
+
// language=HTML
|
|
358
|
+
return `
|
|
235
359
|
<div data-monster-role="control" part="control">
|
|
236
360
|
<form data-monster-attributes="disabled path:disabled | if:true, class path:classes.form"
|
|
237
361
|
data-monster-role="form"
|