@pacem/pacem-scaffolding 1.0.0-abel
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/LICENSE +191 -0
- package/NOTICE +4 -0
- package/dist/browser/pacem-scaffolding.js +10430 -0
- package/dist/browser/pacem-scaffolding.js.map +1 -0
- package/dist/browser/pacem-scaffolding.min.js +2 -0
- package/dist/browser/pacem-scaffolding.min.js.map +1 -0
- package/dist/bundle/pacem-scaffolding.min.mjs +380 -0
- package/dist/bundle/pacem-scaffolding.mjs +10046 -0
- package/dist/bundle/pacem-scaffolding.mjs.map +7 -0
- package/dist/esm/calendar-picker.js +478 -0
- package/dist/esm/char-counter.js +43 -0
- package/dist/esm/checkbox-list.js +75 -0
- package/dist/esm/checkbox.js +112 -0
- package/dist/esm/childform.js +237 -0
- package/dist/esm/contenteditable.js +326 -0
- package/dist/esm/datetime-picker.js +310 -0
- package/dist/esm/form.js +630 -0
- package/dist/esm/formfield.js +1065 -0
- package/dist/esm/geolocate.js +197 -0
- package/dist/esm/hierarchy.js +509 -0
- package/dist/esm/index-components-scaffolding.js +39 -0
- package/dist/esm/index-components.js +1 -0
- package/dist/esm/index-iife.js +3 -0
- package/dist/esm/index-root.js +2 -0
- package/dist/esm/index-scaffolding.js +3 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/input-chars.js +185 -0
- package/dist/esm/input-color.js +80 -0
- package/dist/esm/input-email.js +32 -0
- package/dist/esm/input-file.js +691 -0
- package/dist/esm/input-hidden.js +25 -0
- package/dist/esm/input-image.js +391 -0
- package/dist/esm/input-number.js +58 -0
- package/dist/esm/input-password.js +71 -0
- package/dist/esm/input-search.js +27 -0
- package/dist/esm/input-tel.js +31 -0
- package/dist/esm/input-text.js +36 -0
- package/dist/esm/input-url.js +32 -0
- package/dist/esm/input.js +215 -0
- package/dist/esm/l10n.js +66 -0
- package/dist/esm/latlng.js +178 -0
- package/dist/esm/namevalue-list.js +139 -0
- package/dist/esm/property-picker.js +84 -0
- package/dist/esm/radio-list.js +70 -0
- package/dist/esm/radio.js +79 -0
- package/dist/esm/select.js +126 -0
- package/dist/esm/slider.js +284 -0
- package/dist/esm/snapshot.js +325 -0
- package/dist/esm/suggest.js +545 -0
- package/dist/esm/tags.js +174 -0
- package/dist/esm/textarea-markdown.js +75 -0
- package/dist/esm/textarea.js +51 -0
- package/dist/esm/types-components.js +611 -0
- package/dist/esm/types.js +8 -0
- package/dist/esm/validators.js +409 -0
- package/package.json +38 -0
- package/typings/index.d.ts +2283 -0
|
@@ -0,0 +1,1065 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
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 { Logging, PropertyConverters, Net, Utils, P, PCSS, CustomElement, Watch, PropertyChangeEvent, PropertyChangeEventName, ViewChild, CustomElementUtils, JsonFunctionConversion } from '@pacem/pacem-core';
|
|
8
|
+
import { Components as ComponentsUI } from '@pacem/pacem-ui';
|
|
9
|
+
import { PacemFormRelevantElement } from './form';
|
|
10
|
+
import { ContenteditableUtils } from './contenteditable/utils';
|
|
11
|
+
import { PacemBaseValidatorElement, PacemLengthValidatorElement, PacemAsyncValidatorElement, PacemBinaryValidatorElement, PacemCompareValidatorElement, PacemCustomValidatorElement, PacemRangeValidatorElement, PacemRegexValidatorElement, PacemRequiredValidatorElement } from './validators';
|
|
12
|
+
//namespace Components.Scaffolding {
|
|
13
|
+
function getFormId(key) {
|
|
14
|
+
return 'form' + key;
|
|
15
|
+
}
|
|
16
|
+
function patternToString(pattern) {
|
|
17
|
+
return new RegExp(pattern /*.split('\\').join('\\\\')*/).source;
|
|
18
|
+
}
|
|
19
|
+
function isKnownValidator(v) {
|
|
20
|
+
return 'errorMessage' in v;
|
|
21
|
+
}
|
|
22
|
+
function isValidatorFactory(v) {
|
|
23
|
+
return 'attributes' in v && typeof v.attributes === 'function';
|
|
24
|
+
}
|
|
25
|
+
let PacemFormFieldElement = class PacemFormFieldElement extends PacemFormRelevantElement {
|
|
26
|
+
constructor(_md = new ComponentsUI.UI.MarkdownService()) {
|
|
27
|
+
super();
|
|
28
|
+
this._md = _md;
|
|
29
|
+
this._entityPropertyChangeHandler = (e) => {
|
|
30
|
+
// nudge entity propertychange notification
|
|
31
|
+
this.dispatchEvent(new PropertyChangeEvent({ propertyName: 'entity', currentValue: this.entity }));
|
|
32
|
+
};
|
|
33
|
+
this._labelClickHandler = (_) => {
|
|
34
|
+
document.getElementById(this._label.htmlFor).focus();
|
|
35
|
+
};
|
|
36
|
+
this._key = '_' + Utils.uniqueCode();
|
|
37
|
+
}
|
|
38
|
+
get key() {
|
|
39
|
+
return this._key;
|
|
40
|
+
}
|
|
41
|
+
get fetcher() {
|
|
42
|
+
return this._fetcher;
|
|
43
|
+
}
|
|
44
|
+
get field() {
|
|
45
|
+
return this._field;
|
|
46
|
+
}
|
|
47
|
+
viewActivatedCallback() {
|
|
48
|
+
super.viewActivatedCallback();
|
|
49
|
+
this._buildUpForm();
|
|
50
|
+
this._buildUpFetcher();
|
|
51
|
+
}
|
|
52
|
+
propertyChangedCallback(name, old, val, first) {
|
|
53
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
54
|
+
switch (name) {
|
|
55
|
+
case 'readonly':
|
|
56
|
+
this._ensureBalloon();
|
|
57
|
+
break;
|
|
58
|
+
case 'metadata':
|
|
59
|
+
this._ensureBalloon();
|
|
60
|
+
this._buildUpCss();
|
|
61
|
+
this._buildUpLabel();
|
|
62
|
+
this._buildUpField();
|
|
63
|
+
break;
|
|
64
|
+
case 'entity':
|
|
65
|
+
// In the case that the entity is a HTMLElement,
|
|
66
|
+
// its changes might not propagate correctly.
|
|
67
|
+
// This is a nudgy solution. Explore how to improve
|
|
68
|
+
// `CustomElementUtils.set` as an alternative...
|
|
69
|
+
if (old instanceof HTMLElement) {
|
|
70
|
+
old.removeEventListener(PropertyChangeEventName, this._entityPropertyChangeHandler, false);
|
|
71
|
+
}
|
|
72
|
+
if (val instanceof HTMLElement) {
|
|
73
|
+
val.addEventListener(PropertyChangeEventName, this._entityPropertyChangeHandler, false);
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
disconnectedCallback() {
|
|
79
|
+
if (this.entity instanceof HTMLElement) {
|
|
80
|
+
this.entity.removeEventListener(PropertyChangeEventName, this._entityPropertyChangeHandler, false);
|
|
81
|
+
}
|
|
82
|
+
if (!Utils.isNull(this._label)) {
|
|
83
|
+
this._label.removeEventListener('click', this._labelClickHandler, false);
|
|
84
|
+
}
|
|
85
|
+
if (!Utils.isNull(this._balloon)) {
|
|
86
|
+
this._balloon.remove();
|
|
87
|
+
}
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
}
|
|
90
|
+
_normalizeTooltip() {
|
|
91
|
+
const metadata = this.metadata && this.metadata.extra && this.metadata.extra.tooltip || false;
|
|
92
|
+
if (typeof metadata === 'object') {
|
|
93
|
+
return metadata;
|
|
94
|
+
}
|
|
95
|
+
return { type: metadata };
|
|
96
|
+
}
|
|
97
|
+
_ensureBalloon() {
|
|
98
|
+
var innerText, tooltip;
|
|
99
|
+
const noBalloon = this.readonly
|
|
100
|
+
|| ((tooltip = this._normalizeTooltip()).type === false)
|
|
101
|
+
|| Utils.isNullOrEmpty(innerText = this.metadata && this.metadata.display && this.metadata.display.description);
|
|
102
|
+
// balloon
|
|
103
|
+
if (Utils.isNull(this._balloon) && !noBalloon) {
|
|
104
|
+
let balloon = document.createElement(P + '-balloon');
|
|
105
|
+
balloon.options = {
|
|
106
|
+
behavior: ComponentsUI.UI.BalloonBehavior.Tooltip,
|
|
107
|
+
trigger: tooltip.trigger || ComponentsUI.UI.BalloonTrigger.Hover,
|
|
108
|
+
position: tooltip.position || ComponentsUI.UI.BalloonPosition.Top,
|
|
109
|
+
hoverDelay: 200, hoverTimeout: 50,
|
|
110
|
+
align: tooltip.align || ComponentsUI.UI.BalloonAlignment.Auto
|
|
111
|
+
};
|
|
112
|
+
Utils.addClass(balloon, PCSS + '-field-tooltip');
|
|
113
|
+
var shell = CustomElementUtils.findAncestorShell(this);
|
|
114
|
+
shell.appendChild(this._balloon = balloon);
|
|
115
|
+
}
|
|
116
|
+
const balloon = this._balloon;
|
|
117
|
+
if (!Utils.isNull(balloon)) {
|
|
118
|
+
balloon.target = this._label;
|
|
119
|
+
if (!(balloon.disabled = noBalloon)) {
|
|
120
|
+
const content = innerText || '';
|
|
121
|
+
switch (tooltip.type) {
|
|
122
|
+
case 'md':
|
|
123
|
+
case 'markdown':
|
|
124
|
+
balloon.innerHTML = this._md.toHtml(content);
|
|
125
|
+
break;
|
|
126
|
+
case 'html':
|
|
127
|
+
balloon.innerHTML = content;
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
balloon.innerText = content;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
_buildUpCss() {
|
|
137
|
+
const display = this.metadata?.display;
|
|
138
|
+
if (Utils.isNull(display)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (typeof display.cssClass === 'function') {
|
|
142
|
+
const { cssClassAttr } = display.cssClass(this, '$this', '$this.entity');
|
|
143
|
+
this.setAttribute('css-class', cssClassAttr);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
this.cssClass = display.cssClass;
|
|
147
|
+
}
|
|
148
|
+
if (typeof display.css === 'function') {
|
|
149
|
+
const { cssAttr } = display.css(this, '$this', '$this.entity');
|
|
150
|
+
this.setAttribute('css', cssAttr);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
this.css = display.css;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
_buildUpLabel() {
|
|
157
|
+
// label
|
|
158
|
+
const label = this._label, span = label.firstElementChild;
|
|
159
|
+
const meta = this.metadata;
|
|
160
|
+
label.htmlFor = this._key;
|
|
161
|
+
Utils.addClass(label, PCSS + '-label');
|
|
162
|
+
const vals = this.metadata.validators;
|
|
163
|
+
if (vals && vals.find(v => v.type === 'required')) {
|
|
164
|
+
Utils.addClass(label, PCSS + '-required');
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
Utils.removeClass(label, PCSS + '-required');
|
|
168
|
+
}
|
|
169
|
+
//
|
|
170
|
+
if (!Utils.isNull(this._balloon) && !this._balloon.disabled) {
|
|
171
|
+
Utils.addClass(label, PCSS + '-tooltip');
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
Utils.removeClass(label, PCSS + '-tooltip');
|
|
175
|
+
}
|
|
176
|
+
// exploit a pacem-span so that it cleans the htm content up
|
|
177
|
+
if (typeof meta.display?.name === 'function') {
|
|
178
|
+
const { contentAttr } = meta.display.name(this, ':host', ':host.entity', '::_form');
|
|
179
|
+
span.setAttribute('content', contentAttr);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
span.removeAttribute('content');
|
|
183
|
+
span.content = (meta.display && meta.display.name) || meta.prop;
|
|
184
|
+
}
|
|
185
|
+
label.setAttribute('id', 'label' + this._key);
|
|
186
|
+
label.addEventListener('click', this._labelClickHandler, false);
|
|
187
|
+
}
|
|
188
|
+
// #region Template-called
|
|
189
|
+
_isValueNullOrEmpty(entity = this.entity, metadata = this.metadata) {
|
|
190
|
+
if (Utils.isNull(metadata)) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
const props = metadata.prop.split('.');
|
|
194
|
+
let obj = entity;
|
|
195
|
+
for (let j = 0; j < props.length; j++) {
|
|
196
|
+
const prop = props[j];
|
|
197
|
+
if (Utils.isNullOrEmpty(obj && obj[prop])) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
// next
|
|
201
|
+
obj = obj[prop];
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Reflects the value onto the entity attribute, if the 'entity' is an instance of HTMLElement.
|
|
207
|
+
*/
|
|
208
|
+
_handleValueChange(evt) {
|
|
209
|
+
if (evt.detail.propertyName === 'value') {
|
|
210
|
+
const value = evt.detail.currentValue, prop = this.metadata.prop;
|
|
211
|
+
if (this.entity instanceof HTMLElement) {
|
|
212
|
+
// handle the entity as an element and modify the attribute
|
|
213
|
+
let attr = CustomElementUtils.camelToKebab(prop);
|
|
214
|
+
if (Utils.isNullOrEmpty(value)) {
|
|
215
|
+
this.entity.removeAttribute(attr);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.entity.setAttribute(attr, value.toString());
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
this.entity[prop] = value;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 'Prettifies' the input value (for some specific cases) to be included in an URL segment or query string.
|
|
228
|
+
* @param v Input value
|
|
229
|
+
*/
|
|
230
|
+
_adjustDependencyValue(v) {
|
|
231
|
+
if (Utils.Dates.isDate(v)) {
|
|
232
|
+
return Utils.Dates.parse(v).toISOString();
|
|
233
|
+
}
|
|
234
|
+
return v;
|
|
235
|
+
}
|
|
236
|
+
_broadcastFetchResult(v) {
|
|
237
|
+
const field = this;
|
|
238
|
+
this.dispatchEvent(new CustomEvent("fetch", { detail: v, bubbles: true, cancelable: false }));
|
|
239
|
+
}
|
|
240
|
+
// #endregion
|
|
241
|
+
_buildUpFetcher() {
|
|
242
|
+
// fetcher
|
|
243
|
+
var fetcher = this._fetcher;
|
|
244
|
+
fetcher.setAttribute('id', 'fetch' + this._key);
|
|
245
|
+
fetcher.setAttribute('on-fetchresult', ':host._broadcastFetchResult($event.detail)');
|
|
246
|
+
}
|
|
247
|
+
_buildUpForm() {
|
|
248
|
+
// form
|
|
249
|
+
var form = this._form;
|
|
250
|
+
form.setAttribute('id', getFormId(this._key));
|
|
251
|
+
form.setAttribute('sudden-validation', '{{ ::form.suddenValidation }}');
|
|
252
|
+
}
|
|
253
|
+
_buildUpField() {
|
|
254
|
+
if (this._field)
|
|
255
|
+
this._field.remove();
|
|
256
|
+
this._fetcher.removeAttribute('parameters');
|
|
257
|
+
this._fetcher.result =
|
|
258
|
+
this._fetcher.url = null;
|
|
259
|
+
for (var j = this._validators.children.length - 1; j >= 0; j--)
|
|
260
|
+
this._validators.children[j].remove();
|
|
261
|
+
var meta = this.metadata;
|
|
262
|
+
// field
|
|
263
|
+
let tagName = /* setting the default/fallback input element */ P + '-input-text';
|
|
264
|
+
let numericTagName = P + (meta.display && meta.display.ui === 'slider' ? '-slider' : '-input-number');
|
|
265
|
+
let attrs = {
|
|
266
|
+
'id': this._key, 'name': meta.prop,
|
|
267
|
+
// readonly if property `readonly` set to true OR metadata property is not editable OR parent form's `readonly` property is set to true
|
|
268
|
+
'readonly': "{{ :host.readonly || :host.metadata.isReadOnly || ::_form.readonly }}",
|
|
269
|
+
'value': `{{ :host.entity.${meta.prop}, twoway }}`,
|
|
270
|
+
'placeholder': `${((meta.display && meta.display.watermark) || "")}`
|
|
271
|
+
};
|
|
272
|
+
// autofocus
|
|
273
|
+
if (meta.extra?.autofocus == true) {
|
|
274
|
+
attrs['on-load'] = 'requestAnimationFrame(() => $this.focus())';
|
|
275
|
+
}
|
|
276
|
+
// fetch data
|
|
277
|
+
let fetchData = meta.extra || {};
|
|
278
|
+
let fetchAttrs = {};
|
|
279
|
+
let disabledAttr = "false";
|
|
280
|
+
let dependingClause = '';
|
|
281
|
+
let dependingDisabling = '';
|
|
282
|
+
let dependingParameters = '';
|
|
283
|
+
let dependsOn = [];
|
|
284
|
+
// #region dependency from other props
|
|
285
|
+
if (!Utils.isNullOrEmpty(fetchData.dependsOn)) {
|
|
286
|
+
if (typeof fetchData.dependsOn === 'function') {
|
|
287
|
+
const depAttrs = fetchData.dependsOn(this, ':host', ':host.entity', '$this.entity'), hideAttr = depAttrs.hideAttr;
|
|
288
|
+
if (!Utils.isNullOrEmpty(hideAttr)) {
|
|
289
|
+
this.setAttribute('hide', hideAttr);
|
|
290
|
+
}
|
|
291
|
+
if (!Utils.isNullOrEmpty(depAttrs.disabledAttr)) {
|
|
292
|
+
disabledAttr = depAttrs.disabledAttr;
|
|
293
|
+
if (CustomElementUtils.isBindingAttribute(disabledAttr)) {
|
|
294
|
+
dependingDisabling = CustomElementUtils.extractBindingAttributeExpression(disabledAttr);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!Utils.isNullOrEmpty(depAttrs.parameterAttrs)) {
|
|
298
|
+
const pAttrs = depAttrs.parameterAttrs, parameterPairs = [];
|
|
299
|
+
for (let alias in pAttrs) {
|
|
300
|
+
const propName = pAttrs[alias];
|
|
301
|
+
parameterPairs.push(`${alias}: ${propName}`);
|
|
302
|
+
// exploit this sneaky way...
|
|
303
|
+
dependsOn.push({ prop: propName });
|
|
304
|
+
}
|
|
305
|
+
dependingParameters = parameterPairs.join(', ');
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
dependsOn = fetchData.dependsOn;
|
|
310
|
+
// there should be a better way...
|
|
311
|
+
let disablingClauses = { empty: [], notEqual: {} };
|
|
312
|
+
let hidingClauses = { empty: [], notEqual: {} };
|
|
313
|
+
// fetch
|
|
314
|
+
let namesAndPaths = [];
|
|
315
|
+
let paths = [];
|
|
316
|
+
for (var depends of dependsOn) {
|
|
317
|
+
let path = ':host.entity.' + depends.prop, path2 = '$this.entity.' + depends.prop;
|
|
318
|
+
if (!Utils.isNullOrEmpty(depends.value)) {
|
|
319
|
+
let clause = (p) => p + ' !== ' + JSON.stringify(depends.value);
|
|
320
|
+
(disablingClauses.notEqual[path] = disablingClauses.notEqual[path] || []).push(clause(path));
|
|
321
|
+
if (depends.hide) {
|
|
322
|
+
(hidingClauses.notEqual[path2] = hidingClauses.notEqual[path2] || []).push(clause(path2));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (!depends.optional) {
|
|
326
|
+
let clause = (p) => '$pacem.isNullOrEmpty(' + p + ')';
|
|
327
|
+
disablingClauses.empty.push(clause(path));
|
|
328
|
+
if (depends.hide) {
|
|
329
|
+
hidingClauses.empty.push(clause(path2));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// fetch
|
|
333
|
+
paths.push(path);
|
|
334
|
+
namesAndPaths.push(`${(depends.alias || depends.prop)}: :host._adjustDependencyValue(${path})`);
|
|
335
|
+
if (!depends.optional) {
|
|
336
|
+
dependingClause += `!$pacem.isNullOrEmpty(${path}) && `;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
dependingParameters = namesAndPaths.join(', ');
|
|
340
|
+
let joinClauses = (d) => {
|
|
341
|
+
let ne = 'false', emp = 'false';
|
|
342
|
+
if (!Utils.isNullOrEmpty(d.notEqual)) {
|
|
343
|
+
// when a value is provided then pick the logical operator when provided.
|
|
344
|
+
// consider to switch semantic (i.e. 'or' -> '&&', 'and' -> '||') due to the 'notEqual' operator.
|
|
345
|
+
// 'and' is assumed to be the default
|
|
346
|
+
const neByProp = [];
|
|
347
|
+
for (let dp in d.notEqual) {
|
|
348
|
+
// same property conditions always concatenated with '&&' (logical and)
|
|
349
|
+
neByProp.push('(' + d.notEqual[dp].join(' && ') + ')');
|
|
350
|
+
}
|
|
351
|
+
// different property clauses should be concatenated with '||' (logical or)
|
|
352
|
+
ne = '(' + neByProp.join(' || ') + ')';
|
|
353
|
+
}
|
|
354
|
+
if (!Utils.isNullOrEmpty(d.empty)) {
|
|
355
|
+
// logical operator doe not affect 'empty' (no 'value' explicitated) deps:
|
|
356
|
+
// empty always means 'BAD', then ANY empty entry would automatically trigger a negative outcome ('||').
|
|
357
|
+
emp = '(' + d.empty.join(' || ') + ')';
|
|
358
|
+
}
|
|
359
|
+
return ne + ' || ' + emp;
|
|
360
|
+
};
|
|
361
|
+
dependingDisabling = joinClauses(disablingClauses);
|
|
362
|
+
disabledAttr = `{{ ${dependingDisabling} }}`;
|
|
363
|
+
// never disable the form-field, NEVER!
|
|
364
|
+
// attrs['disabled'] = disabledAttr; // * BUG
|
|
365
|
+
this.setAttribute('hide', `{{ ${joinClauses(hidingClauses)} }}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// #endregion
|
|
369
|
+
const fn = 'fn';
|
|
370
|
+
const fns = this[fn] = this[fn] || {};
|
|
371
|
+
const spinStaticDatasourceAttr = (source = []) => {
|
|
372
|
+
let args = (dependsOn || []).map(p => ':host.entity.' + p.prop).join(', ');
|
|
373
|
+
const fnKey = 'fn' + Utils.uniqueCode();
|
|
374
|
+
switch (typeof source) {
|
|
375
|
+
case 'function':
|
|
376
|
+
fns[fnKey] = source;
|
|
377
|
+
break;
|
|
378
|
+
default:
|
|
379
|
+
if (Utils.isArray(source)) {
|
|
380
|
+
fns[fnKey] = () => source;
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
throw 'Unsupported source format.';
|
|
384
|
+
}
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
return `{{ :host.${fn}.${fnKey}(${args}) }}`;
|
|
388
|
+
};
|
|
389
|
+
const children = new DocumentFragment();
|
|
390
|
+
let uiHint;
|
|
391
|
+
// metadata
|
|
392
|
+
if (typeof meta.type === 'function' /* < factory */) {
|
|
393
|
+
// build-up meta-structure
|
|
394
|
+
var retval = meta.type(this, ':host', ':host.entity');
|
|
395
|
+
// element must be a registered custom-element (hyphen!)
|
|
396
|
+
if (retval.tagName.indexOf('-') === -1) {
|
|
397
|
+
this.log(Logging.LogLevel.Error, `${tagName} is not an allowed form-field`);
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// set tagName
|
|
401
|
+
tagName = retval.tagName;
|
|
402
|
+
// set/override attributes
|
|
403
|
+
Utils.extend(attrs, retval.attrs || {});
|
|
404
|
+
// prepare recursive seeding function
|
|
405
|
+
function seedChildren(parent, children) {
|
|
406
|
+
if (!Utils.isNullOrEmpty(children)) {
|
|
407
|
+
for (let child of children) {
|
|
408
|
+
// element must be a registered custom-element (hyphen!)
|
|
409
|
+
if (child.tagName.indexOf('-') === -1) {
|
|
410
|
+
this.log(Logging.LogLevel.Error, `${child.tagName} is not an allowed child element for form-field ${tagName}`);
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
const el = document.createElement(child.tagName);
|
|
414
|
+
if (!Utils.isNullOrEmpty(child.attrs)) {
|
|
415
|
+
for (let attr in child.attrs) {
|
|
416
|
+
const attrVal = child.attrs[attr];
|
|
417
|
+
el.setAttribute(attr, attrVal);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (!Utils.isNullOrEmpty(child.children)) {
|
|
421
|
+
// recursion here
|
|
422
|
+
seedChildren(el, child.children);
|
|
423
|
+
}
|
|
424
|
+
parent.appendChild(el);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
// seed
|
|
429
|
+
seedChildren(children, retval.children);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
else
|
|
433
|
+
switch (uiHint = (meta.display && meta.display.ui)) {
|
|
434
|
+
// remove this (use dataType = 'HTML' instead).
|
|
435
|
+
case 'contentEditable':
|
|
436
|
+
console.warn('`contentEditable` ui hint is deprecated. Lean on `dataType` equal to \'HTML\' instead.');
|
|
437
|
+
tagName = P + '-contenteditable';
|
|
438
|
+
children.append(ContenteditableUtils.getDefaultDashboard());
|
|
439
|
+
break;
|
|
440
|
+
case 'snapshot':
|
|
441
|
+
tagName = P + '-snapshot';
|
|
442
|
+
if (fetchData.width > 0) {
|
|
443
|
+
attrs['width'] = '' + fetchData.width;
|
|
444
|
+
}
|
|
445
|
+
if (fetchData.height > 0) {
|
|
446
|
+
attrs['height'] = '' + fetchData.height;
|
|
447
|
+
}
|
|
448
|
+
if (fetchData.quality >= 0) {
|
|
449
|
+
attrs['quality'] = '' + fetchData.quality;
|
|
450
|
+
}
|
|
451
|
+
break;
|
|
452
|
+
case 'chars':
|
|
453
|
+
case 'digits':
|
|
454
|
+
case 'otp':
|
|
455
|
+
tagName = P + '-input-chars';
|
|
456
|
+
if (fetchData.charCount > 0) {
|
|
457
|
+
attrs['charCount'] = '' + fetchData.charCount;
|
|
458
|
+
}
|
|
459
|
+
if (!Utils.isNullOrEmpty(fetchData.inputTransform)) {
|
|
460
|
+
attrs['input-transform'] = fetchData.inputTransform;
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
case 'oneToMany':
|
|
464
|
+
case 'dropdown':
|
|
465
|
+
case 'radioList':
|
|
466
|
+
case 'checkboxList':
|
|
467
|
+
case 'manyToMany':
|
|
468
|
+
if (uiHint === 'oneToMany' || uiHint === 'dropdown') {
|
|
469
|
+
// select
|
|
470
|
+
tagName = P + '-select';
|
|
471
|
+
if (fetchData.preventWheel !== false /* must explicit a 'false': default/empty is true for <select> */) {
|
|
472
|
+
attrs['on-wheel'] = '$event.preventDefault()';
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
// checkboxlist
|
|
477
|
+
delete attrs['placeholder'];
|
|
478
|
+
tagName = P + (uiHint === 'radioList' ? '-radio-list' : '-checkbox-list');
|
|
479
|
+
}
|
|
480
|
+
if (!Utils.isNullOrEmpty(fetchData.textProperty)) {
|
|
481
|
+
attrs['text-property'] = fetchData.textProperty;
|
|
482
|
+
}
|
|
483
|
+
if (!Utils.isNullOrEmpty(fetchData.disabledProperty)) {
|
|
484
|
+
attrs['disabled-property'] = fetchData.disabledProperty;
|
|
485
|
+
}
|
|
486
|
+
if (!Utils.isNullOrEmpty(fetchData.valueProperty)) {
|
|
487
|
+
if (!meta.isComplexType)
|
|
488
|
+
attrs['value-property'] = fetchData.valueProperty;
|
|
489
|
+
else
|
|
490
|
+
attrs['compare-by'] = fetchData.valueProperty;
|
|
491
|
+
}
|
|
492
|
+
if (Utils.isNullOrEmpty(fetchData.source)) {
|
|
493
|
+
// datasource has to be fetched
|
|
494
|
+
this._fetcher.id = `fetch${this._key}`;
|
|
495
|
+
this._fetcher.url = fetchData.sourceUrl;
|
|
496
|
+
this._fetcher.method = fetchData.verb;
|
|
497
|
+
//
|
|
498
|
+
fetchAttrs['parameters'] = `{{ { ${dependingParameters} } }}`;
|
|
499
|
+
fetchAttrs['disabled'] = disabledAttr;
|
|
500
|
+
attrs['datasource'] = `{{ ${dependingClause}Utils.getApiResult(#fetch${this._key}.result) || null }}`;
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
// static datasource provided
|
|
504
|
+
attrs['datasource'] = spinStaticDatasourceAttr(fetchData.source);
|
|
505
|
+
}
|
|
506
|
+
break;
|
|
507
|
+
// experimental (do not include in metadata)
|
|
508
|
+
//case 'hierarchy':
|
|
509
|
+
// // select
|
|
510
|
+
// delete attrs['placeholder'];
|
|
511
|
+
// tagName = P + '-hierarchy';
|
|
512
|
+
// if (!Utils.isNullOrEmpty(fetchData.textProperty)) {
|
|
513
|
+
// attrs['text-property'] = fetchData.textProperty;
|
|
514
|
+
// }
|
|
515
|
+
// if (!Utils.isNullOrEmpty(fetchData.disabledProperty)) {
|
|
516
|
+
// attrs['disabled-property'] = fetchData.disabledProperty;
|
|
517
|
+
// }
|
|
518
|
+
// if (!Utils.isNullOrEmpty(fetchData.parentsProperty)) {
|
|
519
|
+
// attrs['parents-property'] = fetchData.parentsProperty;
|
|
520
|
+
// }
|
|
521
|
+
// if (!Utils.isNullOrEmpty(fetchData.valueProperty)) {
|
|
522
|
+
// attrs['value-property'] = fetchData.valueProperty;
|
|
523
|
+
// }
|
|
524
|
+
// if (!Utils.isNullOrEmpty(fetchData.unlinkCaption)) {
|
|
525
|
+
// attrs['unlink-caption'] = fetchData.unlinkCaption;
|
|
526
|
+
// }
|
|
527
|
+
// if (Utils.isNullOrEmpty(fetchData.source)) {
|
|
528
|
+
// // datasource has to be fetched
|
|
529
|
+
// this._fetcher.id = `fetch${this._key}`;
|
|
530
|
+
// this._fetcher.url = fetchData.sourceUrl;
|
|
531
|
+
// this._fetcher.method = fetchData.verb;
|
|
532
|
+
// //
|
|
533
|
+
// fetchAttrs['parameters'] = `{{ { ${dependingParameters} } }}`;
|
|
534
|
+
// fetchAttrs['disabled'] = disabledAttr;
|
|
535
|
+
// attrs['datasource'] = `{{ ${dependingClause}Utils.getApiResult(#fetch${this._key}.result) || null }}`;
|
|
536
|
+
// } else {
|
|
537
|
+
// // static datasource provided
|
|
538
|
+
// attrs['datasource'] = spinStaticDatasourceAttr(fetchData.source);
|
|
539
|
+
// }
|
|
540
|
+
// break;
|
|
541
|
+
case 'suggest':
|
|
542
|
+
case 'tags':
|
|
543
|
+
case 'autocomplete':
|
|
544
|
+
// autocomplete
|
|
545
|
+
const tags = meta.display.ui === 'tags';
|
|
546
|
+
tagName = P + (tags ? '-tags' : '-suggest');
|
|
547
|
+
this._fetcher.id = `fetch${this._key}`;
|
|
548
|
+
if (!Utils.isNullOrEmpty(fetchData.textProperty)) {
|
|
549
|
+
attrs['text-property'] = fetchData.textProperty;
|
|
550
|
+
}
|
|
551
|
+
let itemValue = `#${this._key}.value`;
|
|
552
|
+
if (!Utils.isNullOrEmpty(fetchData.valueProperty)) {
|
|
553
|
+
attrs['compare-by'] = fetchData.valueProperty;
|
|
554
|
+
if (tags) {
|
|
555
|
+
itemValue = `(${itemValue} && ${itemValue}.${fetchData.valueProperty}) || ''`;
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
if (!meta.isComplexType) {
|
|
559
|
+
attrs['value-property'] = fetchData.valueProperty;
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
itemValue += ` && ${itemValue}.${fetchData.valueProperty}`;
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (!Utils.isNullOrEmpty(fetchData.sourceUrl)) {
|
|
567
|
+
fetchAttrs['url'] = `${fetchData.sourceUrl}`;
|
|
568
|
+
this._fetcher.method = fetchData.verb;
|
|
569
|
+
//
|
|
570
|
+
if (!Utils.isNullOrEmpty(fetchData.dependsOn)) {
|
|
571
|
+
// deps
|
|
572
|
+
fetchAttrs['parameters'] = `{{ { ${dependingParameters}, q: #${this._key}.hint || '', ${(fetchData.valueProperty || 'value')}: ${itemValue} || '' } }}`;
|
|
573
|
+
fetchAttrs['disabled'] = disabledAttr;
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
// no deps
|
|
577
|
+
fetchAttrs['parameters'] = `{{ {q: #${this._key}.hint || '', ${(fetchData.valueProperty || 'value')}: ${itemValue} || '' } }}`;
|
|
578
|
+
}
|
|
579
|
+
attrs['datasource'] = `{{ ${dependingClause}Utils.getApiResult(#fetch${this._key}.result) || null }}`;
|
|
580
|
+
}
|
|
581
|
+
else {
|
|
582
|
+
// static datasource
|
|
583
|
+
attrs['datasource'] = spinStaticDatasourceAttr(fetchData.source);
|
|
584
|
+
}
|
|
585
|
+
if (tags) {
|
|
586
|
+
// tags
|
|
587
|
+
attrs['allow-new'] = (meta.extra.allowNew === true).toString();
|
|
588
|
+
attrs['allow-duplicates'] = (meta.extra.allowDuplicates === true).toString();
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
// suggest
|
|
592
|
+
if (!Utils.isNullOrEmpty(fetchData.disabledProperty)) {
|
|
593
|
+
attrs['disabled-property'] = fetchData.disabledProperty;
|
|
594
|
+
}
|
|
595
|
+
if (!Utils.isNullOrEmpty(fetchData.itemtemplate)) {
|
|
596
|
+
const itmpl = fetchData.itemtemplate;
|
|
597
|
+
if (itmpl instanceof HTMLElement) {
|
|
598
|
+
attrs['itemtemplate'] = '{{ #' + (itmpl.id = itmpl.id || this._key + '_itemtmpl') + ' }}';
|
|
599
|
+
if (!itmpl.isConnected) {
|
|
600
|
+
this.append(itmpl);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
attrs['itemtemplate'] = itmpl;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (!Utils.isNullOrEmpty(fetchData.filterFields)) {
|
|
608
|
+
const ffields = fetchData.filterFields;
|
|
609
|
+
attrs['filter-fields'] = (Utils.isArray(ffields)) ? ffields.join(' ') : ffields;
|
|
610
|
+
}
|
|
611
|
+
if (!Utils.isNullOrEmpty(fetchData.maxSuggestions)) {
|
|
612
|
+
attrs['max-suggestions'] = fetchData.maxSuggestions.toString();
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
break;
|
|
616
|
+
case "calendar":
|
|
617
|
+
tagName = P + '-calendar-picker';
|
|
618
|
+
const calendarFormat = meta.display?.format ?? meta.extra?.format;
|
|
619
|
+
if (!Utils.isNullOrEmpty(calendarFormat)) {
|
|
620
|
+
attrs['format'] = '{{ ' + JSON.stringify(calendarFormat) + ' }}';
|
|
621
|
+
}
|
|
622
|
+
if (!Utils.isNullOrEmpty(fetchData.disabledRanges)) {
|
|
623
|
+
attrs['disabled-ranges'] = '{{ ' + JSON.stringify(fetchData.disabledRanges) + ' }}';
|
|
624
|
+
}
|
|
625
|
+
break;
|
|
626
|
+
case "dictionary":
|
|
627
|
+
tagName = P + '-namevalue-list';
|
|
628
|
+
attrs['dictionary'] = 'true';
|
|
629
|
+
break;
|
|
630
|
+
case 'switcher':
|
|
631
|
+
if ((meta.type || '').toLowerCase() === 'boolean') {
|
|
632
|
+
attrs['class'] = "checkbox-switch";
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
default:
|
|
638
|
+
let dataType = (meta.dataType || meta.type || '').toLowerCase();
|
|
639
|
+
switch (dataType) {
|
|
640
|
+
// should replace this one:
|
|
641
|
+
//case 'imageurl':
|
|
642
|
+
// tagName = P + '-input-image';
|
|
643
|
+
// const f_id = this._fetcher.id = `fetch${this._key}`;
|
|
644
|
+
// attrs['image-set'] = `{{ Utils.getApiResult(#${f_id}.result) }}`;
|
|
645
|
+
// attrs['on-imagefetchrequest'] = `#${f_id}.url = '${meta.extra.fetchUrl}'; #${f_id}.parameters = { q: $event.detail.hint, skip: $event.detail.skip, take: $event.detail.take }`;
|
|
646
|
+
// attrs['max-width'] = '' + meta.extra.width;
|
|
647
|
+
// attrs['max-height'] = '' + meta.extra.height;
|
|
648
|
+
// attrs['max-thumbnail-height'] = '' + meta.extra.thumbHeight;
|
|
649
|
+
// attrs['max-thumbnail-width'] = '' + meta.extra.thumbWidth;
|
|
650
|
+
// attrs['upload-url'] = meta.extra.uploadUrl;
|
|
651
|
+
// attrs['allow-snapshot'] = '' + meta.extra.snapshot;
|
|
652
|
+
// break;
|
|
653
|
+
case 'upload':
|
|
654
|
+
// upload
|
|
655
|
+
tagName = P + '-upload';
|
|
656
|
+
let uploadExtra = meta.extra || {};
|
|
657
|
+
attrs['url'] = uploadExtra.uploadUrl;
|
|
658
|
+
attrs['parallelism'] = '' + uploadExtra.parallelism;
|
|
659
|
+
attrs['chunk-size'] = '' + uploadExtra.chunkSize;
|
|
660
|
+
attrs['max-image-width'] = '' + uploadExtra.maxImageWidth;
|
|
661
|
+
attrs['max-image-height'] = '' + uploadExtra.maxImageHeight;
|
|
662
|
+
attrs['select-mode'] = uploadExtra.mode ?? 'file';
|
|
663
|
+
break;
|
|
664
|
+
case 'html':
|
|
665
|
+
// contenteditable
|
|
666
|
+
tagName = P + '-contenteditable';
|
|
667
|
+
children.append(ContenteditableUtils.getDefaultDashboard());
|
|
668
|
+
break;
|
|
669
|
+
case 'enumeration':
|
|
670
|
+
// radiobutton list
|
|
671
|
+
tagName = P + '-radio-list';
|
|
672
|
+
attrs['class'] = PCSS + '-radio-list';
|
|
673
|
+
attrs['value-property'] = "value";
|
|
674
|
+
attrs['text-property'] = "caption";
|
|
675
|
+
attrs['datasource'] = '{{ ' + JSON.stringify(meta.extra.enum) + ' }}';
|
|
676
|
+
delete attrs['placeholder'];
|
|
677
|
+
break;
|
|
678
|
+
case 'password':
|
|
679
|
+
tagName = P + '-input-password';
|
|
680
|
+
break;
|
|
681
|
+
case 'emailaddress':
|
|
682
|
+
tagName = P + '-input-email';
|
|
683
|
+
break;
|
|
684
|
+
case "color":
|
|
685
|
+
tagName = P + '-input-color';
|
|
686
|
+
break;
|
|
687
|
+
case "time":
|
|
688
|
+
case "date":
|
|
689
|
+
case "datetime":
|
|
690
|
+
tagName = P + '-datetime-picker';
|
|
691
|
+
delete attrs['placeholder'];
|
|
692
|
+
if (dataType === 'datetime') {
|
|
693
|
+
attrs['precision'] = "minute";
|
|
694
|
+
}
|
|
695
|
+
const dateFormat = meta.display?.format ?? meta.extra?.format;
|
|
696
|
+
if (!Utils.isNullOrEmpty(dateFormat)) {
|
|
697
|
+
attrs['format'] = '{{ ' + JSON.stringify(dateFormat) + ' }}';
|
|
698
|
+
}
|
|
699
|
+
if (!Utils.isNullOrEmpty(fetchData.disabledRanges)) {
|
|
700
|
+
attrs['disabled-ranges'] = '{{ ' + JSON.stringify(fetchData.disabledRanges) + ' }}';
|
|
701
|
+
}
|
|
702
|
+
break;
|
|
703
|
+
case "url":
|
|
704
|
+
tagName = P + '-input-url';
|
|
705
|
+
break;
|
|
706
|
+
case "phonenumber":
|
|
707
|
+
tagName = P + '-input-tel';
|
|
708
|
+
break;
|
|
709
|
+
case "multilinetext":
|
|
710
|
+
tagName = P + '-textarea';
|
|
711
|
+
break;
|
|
712
|
+
case "markdown":
|
|
713
|
+
tagName = P + '-textarea-markdown';
|
|
714
|
+
break;
|
|
715
|
+
case 'latlng':
|
|
716
|
+
tagName = P + '-latlng';
|
|
717
|
+
if (!Utils.isNullOrEmpty(meta.extra) && typeof meta.extra === 'object' && !Utils.isArray(meta.extra)) {
|
|
718
|
+
attrs['options'] = JSON.stringify(meta.extra);
|
|
719
|
+
}
|
|
720
|
+
break;
|
|
721
|
+
case 'percent':
|
|
722
|
+
case 'percentage':
|
|
723
|
+
case 'currency':
|
|
724
|
+
let defaultFormatOptions = dataType === 'currency' ? { style: 'currency', currency: 'EUR' } : { style: 'percent', maximumFractionDigits: 2 };
|
|
725
|
+
let intl = meta.display?.format ?? defaultFormatOptions;
|
|
726
|
+
attrs['format'] = JSON.stringify(intl);
|
|
727
|
+
default:
|
|
728
|
+
switch ((meta.type || '').toLowerCase()) {
|
|
729
|
+
case "boolean":
|
|
730
|
+
tagName = P + '-checkbox';
|
|
731
|
+
//attrs['selected'] = `{{ :host.entity.${meta.prop}, twoway }}`;
|
|
732
|
+
attrs['true-value'] = "{{ true }}";
|
|
733
|
+
attrs['false-value'] = "{{ false }}";
|
|
734
|
+
attrs['caption'] = attrs['placeholder'];
|
|
735
|
+
//delete attrs['value'];
|
|
736
|
+
delete attrs['placeholder'];
|
|
737
|
+
break;
|
|
738
|
+
case "byte":
|
|
739
|
+
attrs['min'] = '0';
|
|
740
|
+
attrs['max'] = '255';
|
|
741
|
+
case "int16":
|
|
742
|
+
case "int32":
|
|
743
|
+
case "int64":
|
|
744
|
+
case "short":
|
|
745
|
+
case "integer":
|
|
746
|
+
case "int":
|
|
747
|
+
case "long":
|
|
748
|
+
attrs['step'] = '' + (meta.extra?.step ?? '1');
|
|
749
|
+
tagName = numericTagName;
|
|
750
|
+
const intFormat = meta.display?.format;
|
|
751
|
+
if (!Utils.isNullOrEmpty(intFormat)) {
|
|
752
|
+
attrs['format'] = JSON.stringify(intFormat);
|
|
753
|
+
}
|
|
754
|
+
if (fetchData.preventWheel !== false /* must explicit a 'false': default/empty is true for <input[type=number]> */ && tagName === (P + '-input-number')) {
|
|
755
|
+
attrs['on-wheel'] = '$event.preventDefault()';
|
|
756
|
+
}
|
|
757
|
+
break;
|
|
758
|
+
case "double":
|
|
759
|
+
case "decimal":
|
|
760
|
+
case "float":
|
|
761
|
+
case "single":
|
|
762
|
+
case "number":
|
|
763
|
+
tagName = numericTagName;
|
|
764
|
+
attrs['step'] = '' + (meta.extra?.step ?? 'any');
|
|
765
|
+
const decimalFormat = meta.display?.format;
|
|
766
|
+
if (!Utils.isNullOrEmpty(decimalFormat)) {
|
|
767
|
+
attrs['format'] = JSON.stringify(decimalFormat);
|
|
768
|
+
}
|
|
769
|
+
if (fetchData.preventWheel !== false /* must explicit a 'false': default/empty is true for <input[type=number]> */ && tagName === (P + '-input-number')) {
|
|
770
|
+
attrs['on-wheel'] = '$event.preventDefault()';
|
|
771
|
+
}
|
|
772
|
+
break;
|
|
773
|
+
default:
|
|
774
|
+
if ((meta.type === 'array' || meta.type === 'object') && !Utils.isNullOrEmpty(meta.props)) {
|
|
775
|
+
tagName = P + '-childform';
|
|
776
|
+
delete attrs['placeholder'];
|
|
777
|
+
attrs['metadata'] = Utils.Json.stringify(meta.props, { functions: JsonFunctionConversion.Reference });
|
|
778
|
+
attrs['mode'] = meta.type;
|
|
779
|
+
attrs['lock-items'] = '' + (meta.extra && meta.extra.lockItems || false);
|
|
780
|
+
attrs['logger'] = '{{ :host.logger }}';
|
|
781
|
+
if (!Utils.isNullOrEmpty(dependsOn)) {
|
|
782
|
+
var extraDom = '';
|
|
783
|
+
for (let d of dependsOn) {
|
|
784
|
+
extraDom += `<${P}-childform-propagator model="${attrs["value"]}" watch="{{ :host.entity.${d.prop} }}" property="${(d.alias || d.prop)}"></${P}-childform-propagator>\n`;
|
|
785
|
+
}
|
|
786
|
+
this._container.innerHTML = extraDom;
|
|
787
|
+
}
|
|
788
|
+
attrs['fetch-credentials'] = '{{ :host.fetchCredentials }}';
|
|
789
|
+
attrs['fetch-headers'] = '{{ :host.fetchHeaders }}';
|
|
790
|
+
}
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
// #region commands
|
|
798
|
+
if (!Utils.isNullOrEmpty(meta.commands)) {
|
|
799
|
+
Utils.addClass(this._container, PCSS + '-fieldgroup');
|
|
800
|
+
const prepend = this._container.appendChild(document.createElement('div')), append = this._container.appendChild(document.createElement('div'));
|
|
801
|
+
Utils.addClass(prepend, `fieldgroup-prepend ${PCSS}-buttonset buttons`);
|
|
802
|
+
Utils.addClass(append, `fieldgroup-append ${PCSS}-buttonset buttons`);
|
|
803
|
+
const disable = dependingDisabling || 'false';
|
|
804
|
+
meta.commands.forEach(cmd => {
|
|
805
|
+
const btn = document.createElement(P + '-button');
|
|
806
|
+
btn.setAttribute('icon-glyph', cmd.icon);
|
|
807
|
+
btn.setAttribute('command-name', cmd.name);
|
|
808
|
+
if (cmd.dependsOnValue) {
|
|
809
|
+
btn.setAttribute('disabled', `{{ (${disable}) || !::_form.valid || $pacem.isNullOrEmpty(:host.entity.${meta.prop}) }}`);
|
|
810
|
+
btn.setAttribute('command-argument', `{{ :host.entity.${meta.prop} }}`);
|
|
811
|
+
}
|
|
812
|
+
else {
|
|
813
|
+
btn.setAttribute('disabled', disabledAttr);
|
|
814
|
+
}
|
|
815
|
+
btn.setAttribute('tooltip', cmd.tooltip);
|
|
816
|
+
if (!Utils.isNullOrEmpty(cmd.cssClass)) {
|
|
817
|
+
Utils.addClass(btn, cmd.cssClass.join(' '));
|
|
818
|
+
}
|
|
819
|
+
(cmd.prepend ? prepend : append).appendChild(btn);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
// #endregion
|
|
823
|
+
// #region validators
|
|
824
|
+
if (!Utils.isNullOrEmpty(meta.validators)) {
|
|
825
|
+
meta.validators.forEach((v) => {
|
|
826
|
+
var validatorElement;
|
|
827
|
+
var params = {};
|
|
828
|
+
var attributes = {};
|
|
829
|
+
if (isKnownValidator(v)) {
|
|
830
|
+
params = v['params'] || {};
|
|
831
|
+
attributes['error-message'] = v.errorMessage;
|
|
832
|
+
}
|
|
833
|
+
if (isValidatorFactory(v)) {
|
|
834
|
+
// preserve static attributes, just in case
|
|
835
|
+
Utils.extend(attributes, v.attributes(this, ':host', ':host.entity'));
|
|
836
|
+
}
|
|
837
|
+
switch (v.type) {
|
|
838
|
+
case 'required':
|
|
839
|
+
attrs['required'] = 'true';
|
|
840
|
+
validatorElement = new PacemRequiredValidatorElement();
|
|
841
|
+
break;
|
|
842
|
+
case 'length':
|
|
843
|
+
let lengthValidator = new PacemLengthValidatorElement();
|
|
844
|
+
validatorElement = lengthValidator;
|
|
845
|
+
let max = params && params['max'];
|
|
846
|
+
let min = params && params['min'];
|
|
847
|
+
if (max != null) {
|
|
848
|
+
attrs['maxlength'] = '' + (lengthValidator.max = max);
|
|
849
|
+
if (tagName === P + '-input-chars') {
|
|
850
|
+
attrs['count'] ??= '' + max;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
else if ('max' in attributes) {
|
|
854
|
+
attrs['max'] = attributes['max'];
|
|
855
|
+
}
|
|
856
|
+
if (min != null) {
|
|
857
|
+
attrs['minlength'] = '' + (lengthValidator.min = min);
|
|
858
|
+
}
|
|
859
|
+
else if ('min' in attributes) {
|
|
860
|
+
attrs['minlength'] = attributes['min'];
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
case 'range':
|
|
864
|
+
let rangeValidator = new PacemRangeValidatorElement();
|
|
865
|
+
validatorElement = rangeValidator;
|
|
866
|
+
let maxNum = params && params['max'];
|
|
867
|
+
let minNum = params && params['min'];
|
|
868
|
+
let isDateTime = tagName === P + '-datetime-picker';
|
|
869
|
+
// TODO: handle calendar-picker
|
|
870
|
+
if (maxNum != null) {
|
|
871
|
+
rangeValidator.max = maxNum;
|
|
872
|
+
attrs['max'] = "{{ " + (isDateTime ? "'" + maxNum + "'" : maxNum) + " }}";
|
|
873
|
+
}
|
|
874
|
+
else if ('max' in attributes) {
|
|
875
|
+
attrs['max'] = attributes['max'];
|
|
876
|
+
}
|
|
877
|
+
if (minNum != null) {
|
|
878
|
+
rangeValidator.min = minNum;
|
|
879
|
+
attrs['min'] = "{{ " + (isDateTime ? "'" + minNum + "'" : minNum) + " }}";
|
|
880
|
+
}
|
|
881
|
+
else if ('min' in attributes) {
|
|
882
|
+
attrs['min'] = attributes['min'];
|
|
883
|
+
}
|
|
884
|
+
break;
|
|
885
|
+
case 'email':
|
|
886
|
+
let emailValidator = new PacemRegexValidatorElement();
|
|
887
|
+
validatorElement = emailValidator;
|
|
888
|
+
attrs['pattern'] = patternToString(emailValidator.pattern = /^[\w\-\.]+@[\w\-\.]+\.[a-zA-Z0-9]{2,6}$/);
|
|
889
|
+
break;
|
|
890
|
+
case 'regex':
|
|
891
|
+
let regexValidator = new PacemRegexValidatorElement();
|
|
892
|
+
validatorElement = regexValidator;
|
|
893
|
+
let pattern = params['pattern'];
|
|
894
|
+
pattern ||= attributes['pattern'];
|
|
895
|
+
attrs['pattern'] = patternToString(pattern);
|
|
896
|
+
regexValidator.pattern = pattern;
|
|
897
|
+
break;
|
|
898
|
+
case 'binary':
|
|
899
|
+
let binaryValidator = new PacemBinaryValidatorElement();
|
|
900
|
+
validatorElement = binaryValidator;
|
|
901
|
+
let filePattern = params['pattern'];
|
|
902
|
+
if (filePattern != null) {
|
|
903
|
+
attrs['pattern'] = patternToString(filePattern);
|
|
904
|
+
binaryValidator.pattern = filePattern;
|
|
905
|
+
}
|
|
906
|
+
else if ('pattern' in attributes) {
|
|
907
|
+
attrs['pattern'] = attributes['pattern'];
|
|
908
|
+
}
|
|
909
|
+
let maxSize = params && params['maxSize'];
|
|
910
|
+
if (maxSize != null) {
|
|
911
|
+
binaryValidator.maxSize = maxSize;
|
|
912
|
+
attrs['max-size'] = '' + maxSize;
|
|
913
|
+
}
|
|
914
|
+
else if ('max-size' in attributes) {
|
|
915
|
+
attrs['max-size'] = attributes['max-size'];
|
|
916
|
+
}
|
|
917
|
+
break;
|
|
918
|
+
case 'compare':
|
|
919
|
+
let compareValidator = new PacemCompareValidatorElement();
|
|
920
|
+
validatorElement = compareValidator;
|
|
921
|
+
let comparedToCore = '';
|
|
922
|
+
if ('value' in params) {
|
|
923
|
+
comparedToCore = JSON.stringify(params.value);
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
const toProp = 'to' in params ? params.to : params.toProperty;
|
|
927
|
+
comparedToCore = `:host.entity.${toProp}`;
|
|
928
|
+
}
|
|
929
|
+
const compareToAttr = `{{ ${comparedToCore} }}`;
|
|
930
|
+
compareValidator.setAttribute('to', compareToAttr);
|
|
931
|
+
let operator = compareValidator.operator = params['operator'] || attributes['operator'] || 'equal';
|
|
932
|
+
// In case of `date(time)` try to add some interaction with `datetime-picker`'s min/max props.
|
|
933
|
+
if (tagName === P + '-datetime-picker') {
|
|
934
|
+
switch (operator) {
|
|
935
|
+
case 'lessOrEqual':
|
|
936
|
+
case 'less': // approximation: edge value won't be allowed but will result enabled on the `datetime-picker`
|
|
937
|
+
attrs['max'] = compareToAttr;
|
|
938
|
+
break;
|
|
939
|
+
case 'greaterOrEqual':
|
|
940
|
+
case 'greater': // approximation: edge value won't be allowed but will result enabled on the `datetime-picker`
|
|
941
|
+
attrs['min'] = compareToAttr;
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
} /* // TODO: should accumulate disabled ranges (possible multiple validators)
|
|
945
|
+
else if (tagName === P + '-calendar-picker') {
|
|
946
|
+
//
|
|
947
|
+
switch (operator) {
|
|
948
|
+
case 'lessOrEqual':
|
|
949
|
+
case 'less': // approximation: edge value won't be allowed but will result enabled on the `calendar-picker`
|
|
950
|
+
attrs['disabled-ranges'] = `{{ [{ to: ${comparedToCore} }] }}`;
|
|
951
|
+
break;
|
|
952
|
+
case 'greaterOrEqual':
|
|
953
|
+
case 'greater': // approximation: edge value won't be allowed but will result enabled on the `calendar-picker`
|
|
954
|
+
attrs['disabled-ranges'] = `{{ [{ from: ${comparedToCore} }] }}`;
|
|
955
|
+
break;
|
|
956
|
+
}
|
|
957
|
+
}*/
|
|
958
|
+
break;
|
|
959
|
+
case 'async':
|
|
960
|
+
let asyncValidator = new PacemAsyncValidatorElement();
|
|
961
|
+
validatorElement = asyncValidator;
|
|
962
|
+
asyncValidator.url = params['url'];
|
|
963
|
+
let parameters = [], depOn = params['dependsOn'] || dependsOn;
|
|
964
|
+
parameters.push(`${meta.prop}: :host._adjustDependencyValue(:host.entity.${meta.prop})`);
|
|
965
|
+
for (let depend of depOn || []) {
|
|
966
|
+
parameters.push(`${(depend.alias || depend.prop)}: :host._adjustDependencyValue(:host.entity.${depend.prop})`);
|
|
967
|
+
}
|
|
968
|
+
asyncValidator.setAttribute('parameters', `{{ { ${(parameters.join(', '))} } }}`);
|
|
969
|
+
asyncValidator.method = params['verb'] || Net.HttpMethod.Get;
|
|
970
|
+
asyncValidator.setAttribute('fetch-credentials', '{{ :host.fetchCredentials }}');
|
|
971
|
+
asyncValidator.setAttribute('fetch-headers', '{{ :host.fetchHeaders }}');
|
|
972
|
+
break;
|
|
973
|
+
case 'custom':
|
|
974
|
+
validatorElement = new PacemCustomValidatorElement();
|
|
975
|
+
break;
|
|
976
|
+
default:
|
|
977
|
+
// custom (extra-lib) validator
|
|
978
|
+
if (!Utils.isNullOrEmpty(v.type) && /* must be a custom element */ v.type.indexOf('-') > 0) {
|
|
979
|
+
const tagName = v.type;
|
|
980
|
+
const extern = document.createElement(tagName);
|
|
981
|
+
if (extern instanceof PacemBaseValidatorElement) {
|
|
982
|
+
validatorElement = extern;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
break;
|
|
986
|
+
}
|
|
987
|
+
//
|
|
988
|
+
if (Utils.isNull(validatorElement)) {
|
|
989
|
+
throw `Cannot generate a formfield validator based on type: ${v.type}.`;
|
|
990
|
+
}
|
|
991
|
+
else {
|
|
992
|
+
validatorElement.watch = meta.prop;
|
|
993
|
+
validatorElement.setAttribute('hide', '{{ !this.invalid }}');
|
|
994
|
+
validatorElement.setAttribute('disabled', disabledAttr);
|
|
995
|
+
for (let attrName in attributes) {
|
|
996
|
+
validatorElement.setAttribute(attrName, attributes[attrName]);
|
|
997
|
+
}
|
|
998
|
+
this._validators.appendChild(validatorElement);
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
// #endregion
|
|
1003
|
+
// #region build-up
|
|
1004
|
+
let field = document.createElement(tagName);
|
|
1005
|
+
for (var name in attrs) {
|
|
1006
|
+
let attr;
|
|
1007
|
+
if (!Utils.isNullOrEmpty(attr = attrs[name]))
|
|
1008
|
+
field.setAttribute(name, attr);
|
|
1009
|
+
}
|
|
1010
|
+
field.append(children);
|
|
1011
|
+
// #endregion
|
|
1012
|
+
this._field = field;
|
|
1013
|
+
this._container.insertBefore(field, this._container.firstElementChild);
|
|
1014
|
+
for (var name in fetchAttrs) {
|
|
1015
|
+
let attr;
|
|
1016
|
+
if (!Utils.isNullOrEmpty(attr = fetchAttrs[name]))
|
|
1017
|
+
this._fetcher.setAttribute(name, attr);
|
|
1018
|
+
}
|
|
1019
|
+
// fire propertychange event for bindings' sake...
|
|
1020
|
+
this.dispatchEvent(new PropertyChangeEvent({ propertyName: 'field', currentValue: field }));
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
__decorate([
|
|
1024
|
+
ViewChild('label')
|
|
1025
|
+
], PacemFormFieldElement.prototype, "_label", void 0);
|
|
1026
|
+
__decorate([
|
|
1027
|
+
ViewChild(`div.${PCSS}-input-container`)
|
|
1028
|
+
], PacemFormFieldElement.prototype, "_container", void 0);
|
|
1029
|
+
__decorate([
|
|
1030
|
+
ViewChild(P + '-fetch')
|
|
1031
|
+
], PacemFormFieldElement.prototype, "_fetcher", void 0);
|
|
1032
|
+
__decorate([
|
|
1033
|
+
ViewChild(P + '-form')
|
|
1034
|
+
], PacemFormFieldElement.prototype, "_form", void 0);
|
|
1035
|
+
__decorate([
|
|
1036
|
+
ViewChild(P + '-panel.' + PCSS + '-validators')
|
|
1037
|
+
], PacemFormFieldElement.prototype, "_validators", void 0);
|
|
1038
|
+
__decorate([
|
|
1039
|
+
Watch({ converter: PropertyConverters.Json })
|
|
1040
|
+
], PacemFormFieldElement.prototype, "metadata", void 0);
|
|
1041
|
+
__decorate([
|
|
1042
|
+
Watch({ converter: PropertyConverters.Json })
|
|
1043
|
+
], PacemFormFieldElement.prototype, "fetchHeaders", void 0);
|
|
1044
|
+
__decorate([
|
|
1045
|
+
Watch({ converter: PropertyConverters.String })
|
|
1046
|
+
], PacemFormFieldElement.prototype, "fetchCredentials", void 0);
|
|
1047
|
+
__decorate([
|
|
1048
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
1049
|
+
], PacemFormFieldElement.prototype, "readonly", void 0);
|
|
1050
|
+
__decorate([
|
|
1051
|
+
Watch()
|
|
1052
|
+
], PacemFormFieldElement.prototype, "entity", void 0);
|
|
1053
|
+
PacemFormFieldElement = __decorate([
|
|
1054
|
+
CustomElement({
|
|
1055
|
+
tagName: P + '-form-field', template: `<${P}-form class="${PCSS}-field" logger="{{ :host.logger }}"
|
|
1056
|
+
css-class="{{ {'${PCSS}-fetching': ::_fetcher.fetching, '${PCSS}-dirty': this.dirty, '${PCSS}-invalid': !this.valid, '${PCSS}-editable': !:host.readonly, '${PCSS}-readonly': :host.readonly, '${PCSS}-pristine': !this.dirty, '${PCSS}-valid': this.valid, '${PCSS}-has-value': !:host._isValueNullOrEmpty(:host.entity, :host.metadata) } }}">
|
|
1057
|
+
<label class="${PCSS}-label"><${P}-span></${P}-span></label>
|
|
1058
|
+
<div class="${PCSS}-input-container"></div>
|
|
1059
|
+
<${P}-fetch debounce="300" logger="{{ :host.logger }}" credentials="{{ :host.fetchCredentials }}" headers="{{ :host.fetchHeaders }}" diff-by-values="true"
|
|
1060
|
+
on-fetchresult=":host._broadcastFetchResult($event.detail)"></${P}-fetch>
|
|
1061
|
+
<${P}-panel class="${PCSS}-validators" hide="{{ ::_form.valid || !::_form.dirty || :host.readonly }}"></${P}-panel>
|
|
1062
|
+
</${P}-form>`
|
|
1063
|
+
})
|
|
1064
|
+
], PacemFormFieldElement);
|
|
1065
|
+
export { PacemFormFieldElement };
|