@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,611 @@
|
|
|
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 { P, PCSS, CustomElementUtils, Utils, Components, PropertyConverters, CustomElement, Watch, stopPropagationHandler, DefaultComparer, PropertyChangeEventName, Debounce } from '@pacem/pacem-core';
|
|
8
|
+
import { FieldChangeEvent } from './types';
|
|
9
|
+
import { PacemFormRelevantElement } from './form';
|
|
10
|
+
const ORIGINAL_VALUE_FIELD = 'pacem:model:original-value';
|
|
11
|
+
export class PacemModelElement extends PacemFormRelevantElement {
|
|
12
|
+
viewActivatedCallback() {
|
|
13
|
+
super.viewActivatedCallback();
|
|
14
|
+
this._registerFieldConditionally();
|
|
15
|
+
this._setAsOriginalValue(this.value);
|
|
16
|
+
}
|
|
17
|
+
_registerFieldConditionally() {
|
|
18
|
+
const name = this.name, form = this.form;
|
|
19
|
+
if (!Utils.isNullOrEmpty(name) && !Utils.isNull(form)
|
|
20
|
+
&& (!this.hasAttribute('autobind')
|
|
21
|
+
|| (this.getAttribute('autobind') !== 'off' && this.getAttribute('autobind') !== 'false'))) {
|
|
22
|
+
form.registerField(name, this);
|
|
23
|
+
// automatic bind value given the field name
|
|
24
|
+
if (!this.hasAttribute('value')) {
|
|
25
|
+
const formId = form.id = form.id || 'frm_' + Utils.uniqueCode();
|
|
26
|
+
this.setAttribute('value', `{{ #${formId}.entity.${name}, twoway }}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
propertyChangedCallback(name, old, val, first) {
|
|
31
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
32
|
+
switch (name) {
|
|
33
|
+
case 'value':
|
|
34
|
+
this.viewValue = this.getViewValue(val);
|
|
35
|
+
break;
|
|
36
|
+
case 'valid':
|
|
37
|
+
if (!val) {
|
|
38
|
+
Utils.addClass(this, PCSS + '-invalid');
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
Utils.removeClass(this, PCSS + '-invalid');
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case 'dirty':
|
|
45
|
+
if (val) {
|
|
46
|
+
Utils.addClass(this, PCSS + '-dirty');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
Utils.removeClass(this, PCSS + '-dirty');
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'name':
|
|
53
|
+
let form = this.form;
|
|
54
|
+
if (form != null) {
|
|
55
|
+
if (old)
|
|
56
|
+
form.unregisterField(old);
|
|
57
|
+
}
|
|
58
|
+
this._registerFieldConditionally();
|
|
59
|
+
break;
|
|
60
|
+
case 'form':
|
|
61
|
+
let n = this.name;
|
|
62
|
+
if (!Utils.isNullOrEmpty(n)) {
|
|
63
|
+
if (old != null)
|
|
64
|
+
old.unregisterField(n);
|
|
65
|
+
}
|
|
66
|
+
this._registerFieldConditionally();
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
let name = this.name, form = this.form;
|
|
72
|
+
if (!Utils.isNullOrEmpty(name) && !Utils.isNull(form))
|
|
73
|
+
form.unregisterField(name);
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
}
|
|
76
|
+
get originalValue() {
|
|
77
|
+
return CustomElementUtils.getAttachedPropertyValue(this, ORIGINAL_VALUE_FIELD);
|
|
78
|
+
}
|
|
79
|
+
_setAsOriginalValue(v) {
|
|
80
|
+
CustomElementUtils.setAttachedPropertyValue(this, ORIGINAL_VALUE_FIELD, v);
|
|
81
|
+
}
|
|
82
|
+
reset() {
|
|
83
|
+
this.value = this.originalValue;
|
|
84
|
+
// then
|
|
85
|
+
this.dirty = false;
|
|
86
|
+
}
|
|
87
|
+
setPristine() {
|
|
88
|
+
this._setAsOriginalValue(this.value);
|
|
89
|
+
//
|
|
90
|
+
this.dirty = false;
|
|
91
|
+
}
|
|
92
|
+
setDirty() {
|
|
93
|
+
this.dirty = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
__decorate([
|
|
97
|
+
Watch({ converter: PropertyConverters.String })
|
|
98
|
+
], PacemModelElement.prototype, "viewValue", void 0);
|
|
99
|
+
__decorate([
|
|
100
|
+
Watch({
|
|
101
|
+
converter: {
|
|
102
|
+
convert: (attr, element) => {
|
|
103
|
+
if (!(element instanceof PacemModelElement)) {
|
|
104
|
+
return attr;
|
|
105
|
+
}
|
|
106
|
+
return element.convertValueAttributeToProperty(attr);
|
|
107
|
+
},
|
|
108
|
+
convertBack: (prop) => prop.toString()
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
], PacemModelElement.prototype, "value", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
114
|
+
], PacemModelElement.prototype, "dirty", void 0);
|
|
115
|
+
__decorate([
|
|
116
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
117
|
+
], PacemModelElement.prototype, "valid", void 0);
|
|
118
|
+
__decorate([
|
|
119
|
+
Watch({ converter: PropertyConverters.String })
|
|
120
|
+
], PacemModelElement.prototype, "name", void 0);
|
|
121
|
+
export class PacemBaseElement extends PacemModelElement {
|
|
122
|
+
constructor() {
|
|
123
|
+
super(...arguments);
|
|
124
|
+
this.focusHandler = (evt) => {
|
|
125
|
+
const focusFieldgroup = (add = true) => {
|
|
126
|
+
// TODO: re-think, since this is an ugly workaround just to properly set the outline and borders of the fieldgroup
|
|
127
|
+
if (Utils.hasClass(this.parentElement, '.' + PCSS + '-fieldgroup')) {
|
|
128
|
+
(add ? Utils.addClass : Utils.removeClass).apply(this, [this.parentElement, PCSS + '-focus']);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const blurFieldgroup = () => focusFieldgroup(false);
|
|
132
|
+
switch (evt.type) {
|
|
133
|
+
case 'focus':
|
|
134
|
+
Utils.addClass(this, PCSS + '-focus');
|
|
135
|
+
focusFieldgroup();
|
|
136
|
+
this._preFocusValue = this.value;
|
|
137
|
+
break;
|
|
138
|
+
case 'blur':
|
|
139
|
+
Utils.removeClass(this, PCSS + '-focus');
|
|
140
|
+
blurFieldgroup();
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (evt.bubbles)
|
|
144
|
+
this.emit(evt);
|
|
145
|
+
else
|
|
146
|
+
this.dispatchEvent(new FocusEvent(evt.type));
|
|
147
|
+
};
|
|
148
|
+
this.changeHandler = (evt) => {
|
|
149
|
+
const val = this.value;
|
|
150
|
+
this.onChange(evt).then(v => {
|
|
151
|
+
if (!this.compareValuePropertyValues(val, v)) {
|
|
152
|
+
this.dispatchEvent(new FieldChangeEvent({
|
|
153
|
+
fieldName: this.name,
|
|
154
|
+
oldValue: val,
|
|
155
|
+
currentValue: v,
|
|
156
|
+
firstChange: !this.dirty
|
|
157
|
+
}));
|
|
158
|
+
this.dirty = true;
|
|
159
|
+
}
|
|
160
|
+
}, _ => {
|
|
161
|
+
// do nothing
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
this.keydownHandler = (evt) => {
|
|
165
|
+
stopPropagationHandler(evt);
|
|
166
|
+
};
|
|
167
|
+
this.keyupHandler = (evt) => {
|
|
168
|
+
switch (evt.keyCode) {
|
|
169
|
+
case /* Esc */ 27:
|
|
170
|
+
stopPropagationHandler(evt);
|
|
171
|
+
// choose between reset and set
|
|
172
|
+
if (this.compareValuePropertyValues(this.originalValue, this._preFocusValue)) {
|
|
173
|
+
this.reset();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.value = this._preFocusValue;
|
|
177
|
+
}
|
|
178
|
+
this.blur();
|
|
179
|
+
break;
|
|
180
|
+
case /* Enter */ 13:
|
|
181
|
+
if (this.preventKeyboardSubmit) {
|
|
182
|
+
stopPropagationHandler(evt);
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
compareValuePropertyValues(old, val) {
|
|
189
|
+
return DefaultComparer(old, val);
|
|
190
|
+
}
|
|
191
|
+
get preventKeyboardSubmit() {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
propertyChangedCallback(name, old, val, first) {
|
|
195
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
196
|
+
switch (name) {
|
|
197
|
+
case 'required':
|
|
198
|
+
case 'disabled':
|
|
199
|
+
case 'autofocus':
|
|
200
|
+
case 'placeholder':
|
|
201
|
+
case 'readonly':
|
|
202
|
+
for (let inputField of this.inputFields) {
|
|
203
|
+
val ? inputField.setAttribute(name, val) : inputField.removeAttribute(name);
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
//case 'name':
|
|
207
|
+
case 'tabOrder':
|
|
208
|
+
for (let inputField of this.inputFields) {
|
|
209
|
+
inputField.setAttribute('tabindex', val);
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case 'value':
|
|
213
|
+
this.acceptValue(val);
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
if (name === 'required'
|
|
217
|
+
|| name === 'disabled'
|
|
218
|
+
|| name === 'readonly') {
|
|
219
|
+
let className = `${PCSS}-${name}`;
|
|
220
|
+
val ? Utils.addClass(this, className) : Utils.removeClass(this, className);
|
|
221
|
+
}
|
|
222
|
+
if (name === 'readonly') {
|
|
223
|
+
this.toggleReadonlyView(val);
|
|
224
|
+
}
|
|
225
|
+
// aria-... attributes
|
|
226
|
+
else if (name === 'required') {
|
|
227
|
+
this.aria.attributes.set('required', !!val + '');
|
|
228
|
+
}
|
|
229
|
+
else if (name === 'valid') {
|
|
230
|
+
// Specs say that 'aria-invalid' on required attributes SHOULD NOT be set before submission,
|
|
231
|
+
// think about a 'submitted state'(?) to check against...
|
|
232
|
+
this.aria.attributes.set('invalid', (!val && !!this.dirty) + '');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
registerInputFields(inputFields = this.inputFields) {
|
|
236
|
+
if (!Utils.isNull(inputFields) && !Utils.isArray(inputFields)) {
|
|
237
|
+
inputFields = [inputFields];
|
|
238
|
+
}
|
|
239
|
+
for (let inputField of inputFields) {
|
|
240
|
+
inputField.addEventListener('focus', this.focusHandler, false);
|
|
241
|
+
inputField.addEventListener('blur', this.focusHandler, false);
|
|
242
|
+
inputField.addEventListener('change', this.changeHandler, false);
|
|
243
|
+
// avoid interference with other handlers (e.g. cref UI.PacemAdapterElement)
|
|
244
|
+
inputField.addEventListener('keydown', this.keydownHandler, false);
|
|
245
|
+
inputField.addEventListener('keyup', this.keyupHandler, false);
|
|
246
|
+
inputField.addEventListener('mousedown', stopPropagationHandler, false);
|
|
247
|
+
inputField.addEventListener('touchstart', stopPropagationHandler, { passive: false, capture: false });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
unregisterInputFields(inputFields = this.inputFields) {
|
|
251
|
+
if (!Utils.isNull(inputFields) && !Utils.isArray(inputFields)) {
|
|
252
|
+
inputFields = [inputFields];
|
|
253
|
+
}
|
|
254
|
+
for (let inputField of inputFields) {
|
|
255
|
+
if (Utils.isNull(inputField))
|
|
256
|
+
continue;
|
|
257
|
+
inputField.removeEventListener('touchstart', stopPropagationHandler, { capture: false });
|
|
258
|
+
inputField.removeEventListener('keydown', this.keydownHandler, false);
|
|
259
|
+
inputField.removeEventListener('keyup', this.keyupHandler, false);
|
|
260
|
+
inputField.removeEventListener('mousedown', stopPropagationHandler, false);
|
|
261
|
+
//
|
|
262
|
+
inputField.removeEventListener('change', this.changeHandler, false);
|
|
263
|
+
inputField.removeEventListener('focus', this.focusHandler, false);
|
|
264
|
+
inputField.removeEventListener('blur', this.focusHandler, false);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
viewActivatedCallback() {
|
|
268
|
+
super.viewActivatedCallback();
|
|
269
|
+
this.toggleReadonlyView(this.readonly || false);
|
|
270
|
+
// aria-attribute
|
|
271
|
+
if (!Utils.isNullOrEmpty(this.id)) {
|
|
272
|
+
const label = document.querySelector(`label[for=${this.id}]`);
|
|
273
|
+
if (label) {
|
|
274
|
+
if (label.id) {
|
|
275
|
+
this.aria.attributes.set('labelledby', label.id);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
this.aria.attributes.set('label', label.textContent);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
this.aria.attributes.remove('labelledby');
|
|
283
|
+
this.aria.attributes.remove('label');
|
|
284
|
+
}
|
|
285
|
+
;
|
|
286
|
+
}
|
|
287
|
+
// add handlers
|
|
288
|
+
this.registerInputFields();
|
|
289
|
+
}
|
|
290
|
+
disconnectedCallback() {
|
|
291
|
+
// remove handlers
|
|
292
|
+
this.unregisterInputFields();
|
|
293
|
+
super.disconnectedCallback();
|
|
294
|
+
}
|
|
295
|
+
focus() {
|
|
296
|
+
const fields = this.inputFields;
|
|
297
|
+
if (fields && fields.length) {
|
|
298
|
+
fields[0].focus();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
blur() {
|
|
302
|
+
const fields = this.inputFields;
|
|
303
|
+
if (!Utils.isNullOrEmpty(fields)) {
|
|
304
|
+
for (let field of fields) {
|
|
305
|
+
field.blur();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
__decorate([
|
|
311
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
312
|
+
], PacemBaseElement.prototype, "required", void 0);
|
|
313
|
+
__decorate([
|
|
314
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
315
|
+
], PacemBaseElement.prototype, "autofocus", void 0);
|
|
316
|
+
__decorate([
|
|
317
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
318
|
+
], PacemBaseElement.prototype, "readonly", void 0);
|
|
319
|
+
__decorate([
|
|
320
|
+
Watch({ converter: PropertyConverters.String })
|
|
321
|
+
], PacemBaseElement.prototype, "name", void 0);
|
|
322
|
+
__decorate([
|
|
323
|
+
Watch({ converter: PropertyConverters.String })
|
|
324
|
+
], PacemBaseElement.prototype, "placeholder", void 0);
|
|
325
|
+
export class PacemItemElement extends Components.PacemElement {
|
|
326
|
+
#container;
|
|
327
|
+
/** @overridable */
|
|
328
|
+
findContainer() {
|
|
329
|
+
return CustomElementUtils.findAncestor(this, n => n instanceof PacemItemsContainerBaseElement);
|
|
330
|
+
}
|
|
331
|
+
get container() {
|
|
332
|
+
return this.#container;
|
|
333
|
+
}
|
|
334
|
+
viewActivatedCallback() {
|
|
335
|
+
super.viewActivatedCallback();
|
|
336
|
+
const container = this.#container = this.findContainer();
|
|
337
|
+
if (!Utils.isNull(container)) {
|
|
338
|
+
container.register(this);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
disconnectedCallback() {
|
|
342
|
+
if (!Utils.isNull(this.#container)) {
|
|
343
|
+
this.#container.unregister(this);
|
|
344
|
+
}
|
|
345
|
+
super.disconnectedCallback();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
export class PacemItemsContainerBaseElement extends PacemBaseElement {
|
|
349
|
+
/**
|
|
350
|
+
* Registers a new item among the items.
|
|
351
|
+
* @param item {PacemDataItemElement} Item to be enrolled
|
|
352
|
+
*/
|
|
353
|
+
register(item) {
|
|
354
|
+
let flag = true;
|
|
355
|
+
if (Utils.isNull(this.items)) {
|
|
356
|
+
this.items = [item];
|
|
357
|
+
}
|
|
358
|
+
else if (this.items.indexOf(item) === -1) {
|
|
359
|
+
this.items.push(item);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
flag = false;
|
|
363
|
+
}
|
|
364
|
+
return flag;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Removes an existing element from the items.
|
|
368
|
+
* @param item {PacemDataItemElement} Item to be removed
|
|
369
|
+
*/
|
|
370
|
+
unregister(item) {
|
|
371
|
+
const ndx = !Utils.isNull(this.items) && this.items.indexOf(item);
|
|
372
|
+
if (ndx >= 0) {
|
|
373
|
+
this.items.splice(ndx, 1)[0];
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
__decorate([
|
|
380
|
+
Watch( /* can only be databound or assigned at runtime */)
|
|
381
|
+
], PacemItemsContainerBaseElement.prototype, "items", void 0);
|
|
382
|
+
let PacemDataItemElement = class PacemDataItemElement extends PacemItemElement {
|
|
383
|
+
};
|
|
384
|
+
__decorate([
|
|
385
|
+
Watch({
|
|
386
|
+
converter: {
|
|
387
|
+
convert: (attr, element) => {
|
|
388
|
+
// boolean?
|
|
389
|
+
if (attr === 'true')
|
|
390
|
+
return true;
|
|
391
|
+
if (attr === 'false')
|
|
392
|
+
return false;
|
|
393
|
+
// number?
|
|
394
|
+
let num = parseFloat(attr);
|
|
395
|
+
if (!isNaN(num))
|
|
396
|
+
return num;
|
|
397
|
+
// date?
|
|
398
|
+
let date = Utils.Dates.parse(attr);
|
|
399
|
+
if (Utils.Dates.isDate(date))
|
|
400
|
+
return date;
|
|
401
|
+
return attr;
|
|
402
|
+
},
|
|
403
|
+
convertBack: (prop) => prop.toString()
|
|
404
|
+
}
|
|
405
|
+
})
|
|
406
|
+
], PacemDataItemElement.prototype, "value", void 0);
|
|
407
|
+
__decorate([
|
|
408
|
+
Watch({ converter: PropertyConverters.String })
|
|
409
|
+
], PacemDataItemElement.prototype, "label", void 0);
|
|
410
|
+
__decorate([
|
|
411
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
412
|
+
], PacemDataItemElement.prototype, "disabled", void 0);
|
|
413
|
+
PacemDataItemElement = __decorate([
|
|
414
|
+
CustomElement({ tagName: P + '-data-item' })
|
|
415
|
+
], PacemDataItemElement);
|
|
416
|
+
export { PacemDataItemElement };
|
|
417
|
+
export class PacemDataSourceElement extends PacemItemsContainerBaseElement {
|
|
418
|
+
constructor(multipleChoice = false) {
|
|
419
|
+
super();
|
|
420
|
+
this.multipleChoice = multipleChoice;
|
|
421
|
+
this._itemPropertyChangedHandler = (evt) => {
|
|
422
|
+
this.databind();
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Registers a new item among the items.
|
|
427
|
+
* @param item {PacemDataItemElement} Item to be enrolled
|
|
428
|
+
*/
|
|
429
|
+
register(item) {
|
|
430
|
+
const flag = super.register(item);
|
|
431
|
+
if (flag) {
|
|
432
|
+
item.addEventListener(PropertyChangeEventName, this._itemPropertyChangedHandler, false);
|
|
433
|
+
}
|
|
434
|
+
return flag;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Removes an existing element from the items.
|
|
438
|
+
* @param item {PacemDataItemElement} Item to be removed
|
|
439
|
+
*/
|
|
440
|
+
unregister(item) {
|
|
441
|
+
const flag = super.register(item);
|
|
442
|
+
if (flag) {
|
|
443
|
+
item.removeEventListener(PropertyChangeEventName, this._itemPropertyChangedHandler, false);
|
|
444
|
+
}
|
|
445
|
+
return flag;
|
|
446
|
+
}
|
|
447
|
+
buildAdaptedDatasource(ds = this.datasource) {
|
|
448
|
+
return ds && ds.map(i => this.mapEntityToItem(i));
|
|
449
|
+
}
|
|
450
|
+
databind(datasource = this.buildAdaptedDatasource(this.datasource)) {
|
|
451
|
+
if (Utils.isNull(datasource) && Utils.isNull(this.adaptedDatasource))
|
|
452
|
+
return;
|
|
453
|
+
const ds = this.adaptedDatasource = datasource || []; /*
|
|
454
|
+
.map(i => this.mapEntityToItem(i))*/
|
|
455
|
+
;
|
|
456
|
+
if (Utils.isNullOrEmpty(ds.filter(i => this.isDataSourceItemSelected(i))))
|
|
457
|
+
this.handleDatasourceMismatch(ds);
|
|
458
|
+
}
|
|
459
|
+
handleDatasourceMismatch(datasource) {
|
|
460
|
+
this.value = undefined;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Checks wether the provided `item` matches the control's criteria for a selected option against a provided value (which defaults to control's value).
|
|
464
|
+
* @param item {any} item to check against
|
|
465
|
+
* @param value {any} value to match
|
|
466
|
+
*/
|
|
467
|
+
isItemSelected(item, value = this.value) {
|
|
468
|
+
if (Utils.isNullOrEmpty(value)) {
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
const v = this.mapEntityToValue(item), c = this.compareBy;
|
|
472
|
+
if (this.multipleChoice && Utils.isArray(value))
|
|
473
|
+
return !Utils.isNull(value.find(j =>
|
|
474
|
+
// caution: numbers and strings might be compared, ease the comparison by loosing equality constraints: `===` to `==`.
|
|
475
|
+
j /* value item */ == /*=*/ v /* datasource item */ || (typeof j === 'object' && !Utils.isNullOrEmpty(c) && c in v && c in j && v[c] == /*=*/ j[c])));
|
|
476
|
+
else if (!this.multipleChoice) {
|
|
477
|
+
return value == /*=*/ v || (typeof value === 'object' && !Utils.isNullOrEmpty(c) && c in v && c in value && v[c] == /*=*/ value[c]);
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Checks wether the provided `item` matches the control's criteria for a selected option against a provided value (which defaults to control's value).
|
|
485
|
+
* @param item {DataSourceItem} item to check against
|
|
486
|
+
* @param value {any} value to match
|
|
487
|
+
*/
|
|
488
|
+
isDataSourceItemSelected(item, value = this.value) {
|
|
489
|
+
if (Utils.isNullOrEmpty(value)) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
if (item.disabled) {
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
const c = this.compareBy;
|
|
496
|
+
if (this.multipleChoice && Utils.isArray(value)) {
|
|
497
|
+
// caution: numbers and strings might be compared, ease the comparison by loosing equality constraints: `===` to `==`.
|
|
498
|
+
let found = value.find(j => j == /*=*/ item.value || (typeof j === 'object' && !Utils.isNullOrEmpty(c) && c in j && !Utils.isNullOrEmpty(item.value) && c in item.value && j[c] == /*=*/ item.value[c]));
|
|
499
|
+
return !Utils.isNull(found);
|
|
500
|
+
}
|
|
501
|
+
else if (!this.multipleChoice && !Utils.isNullOrEmpty(item.value)) {
|
|
502
|
+
return value == /*=*/ item.value || (typeof value === 'object' && !Utils.isNullOrEmpty(c) && c in value && !Utils.isNullOrEmpty(item.value) && c in item.value && value[c] == /*=*/ item.value[c]);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
mapEntityToValue(entity) {
|
|
509
|
+
if (entity == null) {
|
|
510
|
+
throw 'entity cannot be null';
|
|
511
|
+
}
|
|
512
|
+
// declared
|
|
513
|
+
if (entity instanceof PacemDataItemElement) {
|
|
514
|
+
return entity.value;
|
|
515
|
+
}
|
|
516
|
+
// databound
|
|
517
|
+
let value = entity, prop;
|
|
518
|
+
if (prop = this.valueProperty) {
|
|
519
|
+
value = entity[prop];
|
|
520
|
+
}
|
|
521
|
+
return value;
|
|
522
|
+
}
|
|
523
|
+
mapEntityToViewValue(entity) {
|
|
524
|
+
if (entity == null)
|
|
525
|
+
throw 'entity cannot be null';
|
|
526
|
+
// declared
|
|
527
|
+
if (entity instanceof PacemDataItemElement) {
|
|
528
|
+
return entity.label || entity.value;
|
|
529
|
+
}
|
|
530
|
+
// databound
|
|
531
|
+
let viewValue = entity.toString(), prop;
|
|
532
|
+
if (prop = this.textProperty) {
|
|
533
|
+
viewValue = entity[prop];
|
|
534
|
+
}
|
|
535
|
+
return viewValue;
|
|
536
|
+
}
|
|
537
|
+
mapEntityToItem(entity) {
|
|
538
|
+
if (entity == null) {
|
|
539
|
+
throw 'entity cannot be null';
|
|
540
|
+
}
|
|
541
|
+
// declared
|
|
542
|
+
if (entity instanceof PacemDataItemElement) {
|
|
543
|
+
return { value: entity.value, viewValue: entity.label || entity.value, disabled: entity.disabled, data: entity };
|
|
544
|
+
}
|
|
545
|
+
// databound
|
|
546
|
+
let disabled = false;
|
|
547
|
+
const disabledProp = this.disabledProperty;
|
|
548
|
+
if (!Utils.isNullOrEmpty(disabledProp)) {
|
|
549
|
+
disabled = entity[disabledProp] || false;
|
|
550
|
+
}
|
|
551
|
+
return { value: this.mapEntityToValue(entity), viewValue: this.mapEntityToViewValue(entity), disabled: disabled, data: entity };
|
|
552
|
+
}
|
|
553
|
+
propertyChangedCallback(name, old, val, first) {
|
|
554
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
555
|
+
switch (name) {
|
|
556
|
+
case 'datasource':
|
|
557
|
+
case 'textProperty':
|
|
558
|
+
case 'disabledProperty':
|
|
559
|
+
case 'valueProperty':
|
|
560
|
+
cancelAnimationFrame(this._handle);
|
|
561
|
+
this._handle = requestAnimationFrame(() => {
|
|
562
|
+
this.databind();
|
|
563
|
+
// refresh view value, since it depends on selected items.
|
|
564
|
+
this.viewValue = this.getViewValue(this.value);
|
|
565
|
+
});
|
|
566
|
+
break;
|
|
567
|
+
case 'items':
|
|
568
|
+
cancelAnimationFrame(this._handleItems);
|
|
569
|
+
this._handleItems = requestAnimationFrame(() => {
|
|
570
|
+
this.datasource = this.items;
|
|
571
|
+
});
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
getViewValue(val) {
|
|
576
|
+
if (Utils.isNullOrEmpty(this.datasource)) {
|
|
577
|
+
return undefined;
|
|
578
|
+
}
|
|
579
|
+
return this.datasource.filter(i => this.isItemSelected(i)).map(i => this.mapEntityToViewValue(i)).join(', ');
|
|
580
|
+
}
|
|
581
|
+
convertValueAttributeToProperty(attr) {
|
|
582
|
+
if (this.multipleChoice) {
|
|
583
|
+
return attr.split(',').map(i => i.trim());
|
|
584
|
+
}
|
|
585
|
+
return attr;
|
|
586
|
+
}
|
|
587
|
+
compareValuePropertyValues(old, val) {
|
|
588
|
+
return DefaultComparer(old, val);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
__decorate([
|
|
592
|
+
Watch({ emit: false, converter: PropertyConverters.Json })
|
|
593
|
+
], PacemDataSourceElement.prototype, "datasource", void 0);
|
|
594
|
+
__decorate([
|
|
595
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
596
|
+
], PacemDataSourceElement.prototype, "valueProperty", void 0);
|
|
597
|
+
__decorate([
|
|
598
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
599
|
+
], PacemDataSourceElement.prototype, "textProperty", void 0);
|
|
600
|
+
__decorate([
|
|
601
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
602
|
+
], PacemDataSourceElement.prototype, "disabledProperty", void 0);
|
|
603
|
+
__decorate([
|
|
604
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
605
|
+
], PacemDataSourceElement.prototype, "compareBy", void 0);
|
|
606
|
+
__decorate([
|
|
607
|
+
Watch({ converter: PropertyConverters.Json })
|
|
608
|
+
], PacemDataSourceElement.prototype, "adaptedDatasource", void 0);
|
|
609
|
+
__decorate([
|
|
610
|
+
Debounce(true)
|
|
611
|
+
], PacemDataSourceElement.prototype, "databind", null);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CustomTypedEvent } from '@pacem/pacem-core';
|
|
2
|
+
export const FieldChangeEventName = 'change';
|
|
3
|
+
export class FieldChangeEvent extends CustomTypedEvent {
|
|
4
|
+
constructor(args) {
|
|
5
|
+
super(FieldChangeEventName, args, { bubbles: true, cancelable: false });
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//}
|