@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,84 @@
|
|
|
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, ViewChild, CustomElement, Watch, Utils, PropertyConverters, Defaults, CustomElementUtils } from '@pacem/pacem-core';
|
|
8
|
+
import { PacemBaseElement } from './types-components';
|
|
9
|
+
//namespace Pacem.Components.Scaffolding {
|
|
10
|
+
let PacemPropertyPickerElement = class PacemPropertyPickerElement extends PacemBaseElement {
|
|
11
|
+
get inputFields() {
|
|
12
|
+
return [this._select];
|
|
13
|
+
}
|
|
14
|
+
toggleReadonlyView(readonly) {
|
|
15
|
+
this._select.readonly = readonly;
|
|
16
|
+
}
|
|
17
|
+
onChange(evt) {
|
|
18
|
+
return Utils.fromResult(this.value = this._select.value);
|
|
19
|
+
}
|
|
20
|
+
acceptValue(val) {
|
|
21
|
+
this._select.value = val;
|
|
22
|
+
}
|
|
23
|
+
getViewValue(value) {
|
|
24
|
+
return this._select.viewValue;
|
|
25
|
+
}
|
|
26
|
+
convertValueAttributeToProperty(attr) {
|
|
27
|
+
return PropertyConverters.Element.convert(attr);
|
|
28
|
+
}
|
|
29
|
+
viewActivatedCallback() {
|
|
30
|
+
super.viewActivatedCallback();
|
|
31
|
+
this._databind();
|
|
32
|
+
}
|
|
33
|
+
propertyChangedCallback(name, old, val, first) {
|
|
34
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
35
|
+
if (!first) {
|
|
36
|
+
switch (name) {
|
|
37
|
+
case 'target':
|
|
38
|
+
this._databind();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
_databind() {
|
|
44
|
+
const props = [],
|
|
45
|
+
// recursive fn
|
|
46
|
+
fnRec = (container, prop, name) => {
|
|
47
|
+
const val = container[prop];
|
|
48
|
+
if (typeof val === 'object' && val != null && !Utils.isArray(val)) {
|
|
49
|
+
for (let key of Object.keys(val)) {
|
|
50
|
+
const fullName = name + '.' + key;
|
|
51
|
+
// add nested
|
|
52
|
+
props.push(fullName);
|
|
53
|
+
// try again (recursively)
|
|
54
|
+
fnRec(val, key, fullName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
let src = this.target;
|
|
59
|
+
if (!Utils.isNull(src)) {
|
|
60
|
+
let observed = CustomElementUtils.getWatchedProperties(src);
|
|
61
|
+
for (let obs of observed) {
|
|
62
|
+
let name = obs.name;
|
|
63
|
+
// add straight
|
|
64
|
+
props.push(name);
|
|
65
|
+
// dig nested stuff
|
|
66
|
+
fnRec(src, name, name);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this._select.datasource = props.sort();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__decorate([
|
|
73
|
+
ViewChild(P + '-select')
|
|
74
|
+
], PacemPropertyPickerElement.prototype, "_select", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
Watch({ converter: PropertyConverters.Element })
|
|
77
|
+
], PacemPropertyPickerElement.prototype, "target", void 0);
|
|
78
|
+
PacemPropertyPickerElement = __decorate([
|
|
79
|
+
CustomElement({
|
|
80
|
+
tagName: P + '-property-picker', shadow: Defaults.USE_SHADOW_ROOT,
|
|
81
|
+
template: `<${P}-select></${P}-select>`
|
|
82
|
+
})
|
|
83
|
+
], PacemPropertyPickerElement);
|
|
84
|
+
export { PacemPropertyPickerElement };
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { CustomElement, Defaults, P, PCSS, PropertyChangeEventName, Utils, ViewChild } from '@pacem/pacem-core';
|
|
8
|
+
import { PacemDataSourceElement } from './types-components';
|
|
9
|
+
//namespace Pacem.Components.Scaffolding {
|
|
10
|
+
let PacemRadioListElement = class PacemRadioListElement extends PacemDataSourceElement {
|
|
11
|
+
acceptValue(val) {
|
|
12
|
+
// no need to implement
|
|
13
|
+
}
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this['key'] = '_' + Utils.uniqueCode();
|
|
17
|
+
}
|
|
18
|
+
get inputFields() {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
propertyChangedCallback(name, old, val, first) {
|
|
22
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
23
|
+
if (name === 'disabled') {
|
|
24
|
+
this._disable.model = val;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
viewActivatedCallback() {
|
|
28
|
+
super.viewActivatedCallback();
|
|
29
|
+
this._disable.model = this.disabled;
|
|
30
|
+
}
|
|
31
|
+
toggleReadonlyView(readonly) {
|
|
32
|
+
this._repeater.hidden = readonly;
|
|
33
|
+
this._span.hidden = !readonly;
|
|
34
|
+
}
|
|
35
|
+
_selectionChanged(evt, index, item) {
|
|
36
|
+
if (evt.detail.propertyName === 'selected' && evt.detail.currentValue === true) {
|
|
37
|
+
this._selectedValue = this.mapEntityToValue(this.datasource[index]);
|
|
38
|
+
this.changeHandler(evt);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
onChange(evt) {
|
|
42
|
+
this.value = this._selectedValue;
|
|
43
|
+
this.databind();
|
|
44
|
+
return Utils.fromResult(this._selectedValue);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
__decorate([
|
|
48
|
+
ViewChild(P + '-repeater')
|
|
49
|
+
], PacemRadioListElement.prototype, "_repeater", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
ViewChild(P + '-data')
|
|
52
|
+
], PacemRadioListElement.prototype, "_disable", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
ViewChild(`span.${PCSS}-readonly`)
|
|
55
|
+
], PacemRadioListElement.prototype, "_span", void 0);
|
|
56
|
+
PacemRadioListElement = __decorate([
|
|
57
|
+
CustomElement({
|
|
58
|
+
tagName: P + '-radio-list', template: `<${P}-repeater datasource="{{ :host.adaptedDatasource }}">
|
|
59
|
+
<ol class="${PCSS}-radio-list ${PCSS}-viewfinder" pacem>
|
|
60
|
+
<template>
|
|
61
|
+
<li><${P}-radio disabled="{{ ::_disable.model || ^item.disabled }}" name="{{ :host.key, once }}" autobind="off" caption="{{ ^item.viewValue }}" value="{{ ^item.value }}" selected="{{ :host.isDataSourceItemSelected(^item, :host.value) }}"
|
|
62
|
+
on-focus=":host.focusHandler($event)" on-blur=":host.focusHandler($event)"
|
|
63
|
+
on-${PropertyChangeEventName}=":host._selectionChanged($event, ^index, ^item)"></${P}-radio></li>
|
|
64
|
+
</template>
|
|
65
|
+
</ol>
|
|
66
|
+
</${P}-repeater><span class="${PCSS}-readonly ${PCSS}-radio"><${P}-text text="{{ :host.viewValue }}"></${P}-text></span><${P}-data></${P}-data><${P}-content></${P}-content>`,
|
|
67
|
+
shadow: Defaults.USE_SHADOW_ROOT
|
|
68
|
+
})
|
|
69
|
+
], PacemRadioListElement);
|
|
70
|
+
export { PacemRadioListElement };
|
|
@@ -0,0 +1,79 @@
|
|
|
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, ViewChild, CustomElement, Watch, Utils, PropertyConverters, Defaults } from '@pacem/pacem-core';
|
|
8
|
+
import { PacemBaseElement } from './types-components';
|
|
9
|
+
//namespace Pacem.Components.Scaffolding {
|
|
10
|
+
let PacemRadioElement = class PacemRadioElement extends PacemBaseElement {
|
|
11
|
+
convertValueAttributeToProperty(attr) {
|
|
12
|
+
return attr;
|
|
13
|
+
}
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this._key = '_' + Utils.uniqueCode();
|
|
17
|
+
}
|
|
18
|
+
toggleReadonlyView(readonly) {
|
|
19
|
+
this.span.hidden = !readonly;
|
|
20
|
+
this._radio.hidden = /*this.label.hidden =*/ readonly;
|
|
21
|
+
}
|
|
22
|
+
get inputFields() {
|
|
23
|
+
return [this._radio];
|
|
24
|
+
}
|
|
25
|
+
onChange(evt) {
|
|
26
|
+
this.selected = this._radio.checked;
|
|
27
|
+
const value = this.selected ? this._radio.value : undefined;
|
|
28
|
+
return Utils.fromResult(value);
|
|
29
|
+
}
|
|
30
|
+
viewActivatedCallback() {
|
|
31
|
+
super.viewActivatedCallback();
|
|
32
|
+
this._radio.id = this._label.htmlFor = this._key;
|
|
33
|
+
}
|
|
34
|
+
propertyChangedCallback(name, old, val, first) {
|
|
35
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
36
|
+
switch (name) {
|
|
37
|
+
case 'name':
|
|
38
|
+
this._radio.name = val;
|
|
39
|
+
break;
|
|
40
|
+
case 'selected':
|
|
41
|
+
(this._radio.checked = val) ?
|
|
42
|
+
Utils.addClass(this, PCSS + '-selected')
|
|
43
|
+
:
|
|
44
|
+
Utils.removeClass(this, PCSS + '-selected');
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
acceptValue(val) {
|
|
49
|
+
this._radio.value = Utils.isNullOrEmpty(val) ? '' : val;
|
|
50
|
+
}
|
|
51
|
+
getViewValue(val) {
|
|
52
|
+
if (!Utils.isNull(val))
|
|
53
|
+
return this.caption;
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorate([
|
|
58
|
+
ViewChild("input[type=radio]")
|
|
59
|
+
], PacemRadioElement.prototype, "_radio", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
ViewChild("label")
|
|
62
|
+
], PacemRadioElement.prototype, "_label", void 0);
|
|
63
|
+
__decorate([
|
|
64
|
+
ViewChild(`.${PCSS}-readonly`)
|
|
65
|
+
], PacemRadioElement.prototype, "span", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
Watch({ converter: PropertyConverters.String })
|
|
68
|
+
], PacemRadioElement.prototype, "caption", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
Watch({ converter: PropertyConverters.Boolean })
|
|
71
|
+
], PacemRadioElement.prototype, "selected", void 0);
|
|
72
|
+
PacemRadioElement = __decorate([
|
|
73
|
+
CustomElement({
|
|
74
|
+
tagName: P + '-radio',
|
|
75
|
+
template: `<${P}-span class="${PCSS}-readonly ${PCSS}-radio" text="{{ :host.caption }}"></${P}-span><input type="radio" class="${PCSS}-input" /><label class="${PCSS}-label ${PCSS}-radio ${PCSS}-viewfinder"><${P}-text text="{{ :host.caption }}"></${P}-text></label>`,
|
|
76
|
+
shadow: Defaults.USE_SHADOW_ROOT
|
|
77
|
+
})
|
|
78
|
+
], PacemRadioElement);
|
|
79
|
+
export { PacemRadioElement };
|
|
@@ -0,0 +1,126 @@
|
|
|
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 { Components, PropertyConverters, Utils, P, PCSS, CustomElement, Watch, Defaults, ViewChild } from '@pacem/pacem-core';
|
|
8
|
+
import { PacemDataSourceElement } from './types-components';
|
|
9
|
+
//namespace Pacem.Components.Scaffolding {
|
|
10
|
+
let PacemSelectElement = class PacemSelectElement extends PacemDataSourceElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.emptyOption = true;
|
|
14
|
+
}
|
|
15
|
+
toggleReadonlyView(readonly) {
|
|
16
|
+
this._repeater.hidden = readonly;
|
|
17
|
+
this._span.hidden = !readonly;
|
|
18
|
+
}
|
|
19
|
+
// no actual need to be idem-potent...
|
|
20
|
+
// (take care in future)
|
|
21
|
+
get inputFields() {
|
|
22
|
+
return [this._select];
|
|
23
|
+
}
|
|
24
|
+
_manageDom(evt) {
|
|
25
|
+
const args = evt.detail, item = args.item;
|
|
26
|
+
let option = args.dom.find(o => o instanceof HTMLOptionElement);
|
|
27
|
+
option.value = item.value;
|
|
28
|
+
option.textContent = item.viewValue;
|
|
29
|
+
option.disabled = item.disabled;
|
|
30
|
+
option.selected = this.isDataSourceItemSelected(item);
|
|
31
|
+
(Utils.isNullOrEmpty(option.value) ? Utils.addClass : Utils.removeClass).apply(this, [option, PCSS + '-watermark']);
|
|
32
|
+
}
|
|
33
|
+
onChange(evt) {
|
|
34
|
+
let select = this._select, selectedIndex = select.selectedIndex, datasource = this.adaptedDatasource, item = selectedIndex >= 0 && datasource[selectedIndex], value;
|
|
35
|
+
if (item != null) {
|
|
36
|
+
value = item.value;
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
value = undefined;
|
|
40
|
+
return Utils.fromResult(this.value = value);
|
|
41
|
+
}
|
|
42
|
+
propertyChangedCallback(name, old, val, first) {
|
|
43
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
44
|
+
switch (name) {
|
|
45
|
+
// case 'required':
|
|
46
|
+
case 'placeholder':
|
|
47
|
+
case 'emptyOption':
|
|
48
|
+
this.databind();
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
buildAdaptedDatasource(ds = this.datasource) {
|
|
53
|
+
let adapted = super.buildAdaptedDatasource(ds);
|
|
54
|
+
if (adapted && this.emptyOption) {
|
|
55
|
+
adapted.splice(0, 0, { viewValue: this.placeholder || '', value: undefined, data: undefined });
|
|
56
|
+
}
|
|
57
|
+
return adapted;
|
|
58
|
+
}
|
|
59
|
+
handleDatasourceMismatch(ds) {
|
|
60
|
+
if (this.emptyOption) {
|
|
61
|
+
super.handleDatasourceMismatch(ds);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// change value, since it does not exist in database and there's not null/empty fallback...
|
|
65
|
+
if (Utils.isNullOrEmpty(ds)) {
|
|
66
|
+
this.value = void 0;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.value = ds[0].value;
|
|
70
|
+
// ...you'll re-enter the acceptValue procedure with hopefully more luck.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
;
|
|
75
|
+
acceptValue(val) {
|
|
76
|
+
const ds = this.adaptedDatasource, item = ds && ds.filter(i => this.isDataSourceItemSelected(i, val));
|
|
77
|
+
//let item = this.datasource && this.datasource.filter(i => this.isItemSelected(i));
|
|
78
|
+
if (item && item.length == 1)
|
|
79
|
+
this._select.selectedIndex = ds.indexOf(item[0]);
|
|
80
|
+
else {
|
|
81
|
+
this._select.value = undefined;
|
|
82
|
+
let opts = this._select.options;
|
|
83
|
+
if (opts.length > 0 && Utils.isNullOrEmpty(opts[0].value)) {
|
|
84
|
+
this._select.selectedIndex = 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
viewActivatedCallback() {
|
|
89
|
+
super.viewActivatedCallback();
|
|
90
|
+
//select.addEventListener("change", this.changeHandler, false);
|
|
91
|
+
var options = { capture: false, passive: false };
|
|
92
|
+
this._select.addEventListener("wheel", this.emitHandler, options);
|
|
93
|
+
}
|
|
94
|
+
disconnectedCallback() {
|
|
95
|
+
if (!Utils.isNull(this._select)) {
|
|
96
|
+
//select.removeEventListener("change", this.changeHandler, false);
|
|
97
|
+
var options = { capture: false, passive: false };
|
|
98
|
+
this._select.removeEventListener("wheel", this.emitHandler, options);
|
|
99
|
+
}
|
|
100
|
+
super.disconnectedCallback();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__decorate([
|
|
104
|
+
ViewChild('select')
|
|
105
|
+
], PacemSelectElement.prototype, "_select", void 0);
|
|
106
|
+
__decorate([
|
|
107
|
+
ViewChild(P + '-repeater')
|
|
108
|
+
], PacemSelectElement.prototype, "_repeater", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
ViewChild(`span.${PCSS}-readonly`)
|
|
111
|
+
], PacemSelectElement.prototype, "_span", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
114
|
+
], PacemSelectElement.prototype, "emptyOption", void 0);
|
|
115
|
+
PacemSelectElement = __decorate([
|
|
116
|
+
CustomElement({
|
|
117
|
+
tagName: P + '-select', template: `<${P}-repeater datasource="{{ :host.adaptedDatasource }}" on-${Components.RepeaterItemCreateEventName}=":host._manageDom($event)">
|
|
118
|
+
<select class="${PCSS}-select ${PCSS}-viewfinder">
|
|
119
|
+
<template>
|
|
120
|
+
<option></option>
|
|
121
|
+
</template>
|
|
122
|
+
</select>
|
|
123
|
+
</${P}-repeater><span class="${PCSS}-readonly"><${P}-text text="{{ :host.viewValue }}"></${P}-text></span><${P}-content></${P}-content>`, shadow: Defaults.USE_SHADOW_ROOT
|
|
124
|
+
})
|
|
125
|
+
], PacemSelectElement);
|
|
126
|
+
export { PacemSelectElement };
|
|
@@ -0,0 +1,284 @@
|
|
|
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 { Components as ComponentsUI } from '@pacem/pacem-ui';
|
|
8
|
+
import { P, PCSS, ViewChild, CustomElement, Watch, Utils, PropertyConverters, Defaults, avoidHandler, Components, UI } from '@pacem/pacem-core';
|
|
9
|
+
import { PacemBaseElement } from './types-components';
|
|
10
|
+
//namespace Pacem.Components.Scaffolding {
|
|
11
|
+
// TODO: exploit 202x features like https://developer.mozilla.org/en-US/docs/Web/CSS/offset-path or https://developer.chrome.com/blog/anchor-positioning-api
|
|
12
|
+
let PacemSliderElement = class PacemSliderElement extends PacemBaseElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.inputFields = [];
|
|
16
|
+
this._dragHandler = (evt) => {
|
|
17
|
+
evt.preventDefault();
|
|
18
|
+
this._computeAndAssignValue(evt.detail.currentPosition.x, this.changePolicy !== 'end');
|
|
19
|
+
};
|
|
20
|
+
this._endHandler = (evt) => {
|
|
21
|
+
evt.preventDefault();
|
|
22
|
+
this._computeAndAssignValue(evt.detail.currentPosition.x, this.changePolicy === 'end');
|
|
23
|
+
};
|
|
24
|
+
this._startHandler = (evt) => {
|
|
25
|
+
this._thumb.focus();
|
|
26
|
+
};
|
|
27
|
+
this._downHandler = (evt) => {
|
|
28
|
+
const x = evt instanceof MouseEvent ? evt.clientX : evt.touches && evt.touches.length && evt.touches[0].clientX, trackSize = this._trackSize;
|
|
29
|
+
if (!Utils.isNullOrEmpty(trackSize)) {
|
|
30
|
+
this._computeAndAssignValue(x, true);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
this._keydownHandler = (evt) => {
|
|
34
|
+
switch (evt.keyCode) {
|
|
35
|
+
case 39: // right
|
|
36
|
+
case 37: // left
|
|
37
|
+
avoidHandler(evt);
|
|
38
|
+
let forward = evt.keyCode === 39; // TODO: include rtl!
|
|
39
|
+
let step = (typeof this.step !== 'number' ? 1.0 : this.step) * (forward ? 1 : -1);
|
|
40
|
+
let cease = false;
|
|
41
|
+
let ceaseFn = (evt) => {
|
|
42
|
+
cease = true;
|
|
43
|
+
window.removeEventListener('keyup', ceaseFn, false);
|
|
44
|
+
Utils.removeClass(this, 'slider-keydown');
|
|
45
|
+
};
|
|
46
|
+
window.addEventListener('keyup', ceaseFn, false);
|
|
47
|
+
Utils.addClass(this, 'slider-keydown');
|
|
48
|
+
Utils.accelerateCallback(token => {
|
|
49
|
+
if (!(token.cancel = cease)) {
|
|
50
|
+
this._setValue(this.value + step);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
onChange(evt) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
if (evt.type === 'slide') {
|
|
60
|
+
resolve(this.value = evt.detail);
|
|
61
|
+
}
|
|
62
|
+
resolve(this.value);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
_draw(val = this.value) {
|
|
66
|
+
const trackSize = this._trackSize;
|
|
67
|
+
if (Utils.isNull(trackSize)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const v = Utils.isNullOrEmpty(val) ? this.min : parseFloat(val);
|
|
71
|
+
const percentage = Math.min(1, Math.max(0, (v - this.min) / (this.max - this.min)));
|
|
72
|
+
this._progress.style.transform = `scale(${(percentage)}, 1)`;
|
|
73
|
+
this._thumb.style.transform = `translateX(${Math.round(percentage * trackSize.width)}px)`;
|
|
74
|
+
}
|
|
75
|
+
_format(v) {
|
|
76
|
+
const intl = this.format;
|
|
77
|
+
if (!Utils.isNullOrEmpty(intl)) {
|
|
78
|
+
return new Intl.NumberFormat(Utils.lang(this), intl).format(v);
|
|
79
|
+
}
|
|
80
|
+
// fallback
|
|
81
|
+
let sv = '-';
|
|
82
|
+
if (!Utils.isNull(v)) {
|
|
83
|
+
sv = v.toLocaleString();
|
|
84
|
+
}
|
|
85
|
+
let evt = new CustomEvent("formatvalue", { detail: { value: v } });
|
|
86
|
+
this.dispatchEvent(evt);
|
|
87
|
+
return Utils.isNull(evt.detail.output) ? sv : evt.detail.output;
|
|
88
|
+
}
|
|
89
|
+
acceptValue(val) {
|
|
90
|
+
this._draw(val);
|
|
91
|
+
}
|
|
92
|
+
getViewValue(value) {
|
|
93
|
+
return this._format(value);
|
|
94
|
+
}
|
|
95
|
+
convertValueAttributeToProperty(attr) {
|
|
96
|
+
return parseFloat(attr);
|
|
97
|
+
}
|
|
98
|
+
toggleReadonlyView(readonly) {
|
|
99
|
+
this._thumb.hidden = readonly;
|
|
100
|
+
const css = 'cursor-pointer';
|
|
101
|
+
if (readonly) {
|
|
102
|
+
Utils.removeClass(this._max, css);
|
|
103
|
+
Utils.removeClass(this._min, css);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
Utils.addClass(this._max, css);
|
|
107
|
+
Utils.addClass(this._min, css);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
_setTrackSize(evt) {
|
|
111
|
+
const size = evt.detail;
|
|
112
|
+
this._trackSize = { x: size.left, y: size.top, width: size.width, height: size.height };
|
|
113
|
+
this._draw(this.value);
|
|
114
|
+
}
|
|
115
|
+
_computeAndAssignValue(x, triggerChange) {
|
|
116
|
+
if (this.readonly || this.disabled) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// constraint to track size to compute the slider value
|
|
120
|
+
const constraint = this._trackSize, step = this.step;
|
|
121
|
+
let perc = (x - constraint.x) / constraint.width;
|
|
122
|
+
let v = (this.max - this.min) * perc + this.min;
|
|
123
|
+
if (typeof step === 'number') {
|
|
124
|
+
v = Math.round(v / step) * step;
|
|
125
|
+
}
|
|
126
|
+
if (triggerChange) {
|
|
127
|
+
this._setValue(v);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this._draw(v);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_setValue(v) {
|
|
134
|
+
if (isNaN(v) || Utils.isNull(v)) {
|
|
135
|
+
// keep in sync with pacem-input-number logic (TODO: centralize code, this is a fix)
|
|
136
|
+
// cast NaN to undefined
|
|
137
|
+
v = undefined;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (!isNaN(this.min) && v < this.min) {
|
|
141
|
+
v = this.min;
|
|
142
|
+
}
|
|
143
|
+
if (!isNaN(this.max) && v > this.max) {
|
|
144
|
+
v = this.max;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.changeHandler(new CustomEvent('slide', { detail: v }));
|
|
148
|
+
}
|
|
149
|
+
connectedCallback() {
|
|
150
|
+
super.connectedCallback();
|
|
151
|
+
this.addEventListener('mousedown', this._downHandler, false);
|
|
152
|
+
this.addEventListener('touchstart', this._downHandler, { passive: false, capture: false });
|
|
153
|
+
}
|
|
154
|
+
viewActivatedCallback() {
|
|
155
|
+
super.viewActivatedCallback();
|
|
156
|
+
this._dragger.addEventListener(UI.DragDropEventType.Init, this._startHandler, false);
|
|
157
|
+
this._dragger.addEventListener(UI.DragDropEventType.Drag, this._dragHandler, false);
|
|
158
|
+
this._dragger.addEventListener(UI.DragDropEventType.End, this._endHandler, false);
|
|
159
|
+
this._thumb.addEventListener('keydown', this._keydownHandler, false);
|
|
160
|
+
this._min.text = this._format(this.min);
|
|
161
|
+
this._max.text = this._format(this.max);
|
|
162
|
+
// balloon
|
|
163
|
+
const balloon = this._shellProxy.dom[0];
|
|
164
|
+
if (!Utils.isNull(balloon)) {
|
|
165
|
+
balloon.target = this._thumb;
|
|
166
|
+
balloon.options = {
|
|
167
|
+
trigger: ComponentsUI.UI.BalloonTrigger.Focus,
|
|
168
|
+
trackPosition: true,
|
|
169
|
+
position: ComponentsUI.UI.BalloonPosition.Top,
|
|
170
|
+
align: ComponentsUI.UI.BalloonAlignment.Center,
|
|
171
|
+
behavior: ComponentsUI.UI.BalloonBehavior.Tooltip,
|
|
172
|
+
hoverDelay: 0, hoverTimeout: 0
|
|
173
|
+
};
|
|
174
|
+
this._syncThumbLabel();
|
|
175
|
+
}
|
|
176
|
+
//
|
|
177
|
+
this._thumb.tabIndex = 0;
|
|
178
|
+
}
|
|
179
|
+
_syncThumbLabel(thumbLabel = this.thumbLabel) {
|
|
180
|
+
const balloon = this._shellProxy.dom[0];
|
|
181
|
+
(thumbLabel ? Utils.addClass : Utils.removeClass).apply(this, [this, 'slider-thumblabel']);
|
|
182
|
+
balloon.disabled = !thumbLabel;
|
|
183
|
+
}
|
|
184
|
+
disconnectedCallback() {
|
|
185
|
+
this.removeEventListener('mousedown', this._downHandler, false);
|
|
186
|
+
this.removeEventListener('touchstart', this._downHandler, { capture: false });
|
|
187
|
+
if (!Utils.isNull(this._dragger)) {
|
|
188
|
+
this._dragger.removeEventListener(UI.DragDropEventType.End, this._endHandler, false);
|
|
189
|
+
this._dragger.removeEventListener(UI.DragDropEventType.Drag, this._dragHandler, false);
|
|
190
|
+
this._dragger.removeEventListener(UI.DragDropEventType.Init, this._startHandler, false);
|
|
191
|
+
}
|
|
192
|
+
if (!Utils.isNull(this._thumb)) {
|
|
193
|
+
this._thumb.removeEventListener('keydown', this._keydownHandler, false);
|
|
194
|
+
}
|
|
195
|
+
super.disconnectedCallback();
|
|
196
|
+
}
|
|
197
|
+
propertyChangedCallback(name, old, val, first) {
|
|
198
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
199
|
+
if (first) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
switch (name) {
|
|
203
|
+
case 'thumbLabel':
|
|
204
|
+
this._syncThumbLabel(val);
|
|
205
|
+
break;
|
|
206
|
+
case 'min':
|
|
207
|
+
case 'max':
|
|
208
|
+
if (!Utils.isNull(this._max) && !Utils.isNull(this._min)) {
|
|
209
|
+
this._min.text = this._format(this.min);
|
|
210
|
+
this._max.text = this._format(this.max);
|
|
211
|
+
}
|
|
212
|
+
this._setValue(this.value);
|
|
213
|
+
this._draw();
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
__decorate([
|
|
219
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
220
|
+
], PacemSliderElement.prototype, "min", void 0);
|
|
221
|
+
__decorate([
|
|
222
|
+
Watch({ emit: false, converter: PropertyConverters.Number })
|
|
223
|
+
], PacemSliderElement.prototype, "max", void 0);
|
|
224
|
+
__decorate([
|
|
225
|
+
Watch({ emit: false, converter: PropertyConverters.Boolean })
|
|
226
|
+
], PacemSliderElement.prototype, "thumbLabel", void 0);
|
|
227
|
+
__decorate([
|
|
228
|
+
Watch({
|
|
229
|
+
emit: false, converter: {
|
|
230
|
+
convert: (attr) => {
|
|
231
|
+
let v = parseFloat(attr);
|
|
232
|
+
if (isNaN(v)) {
|
|
233
|
+
return 'any';
|
|
234
|
+
}
|
|
235
|
+
return v;
|
|
236
|
+
}, convertBack: (v) => (v || '').toString()
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
], PacemSliderElement.prototype, "step", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
Watch({ emit: false, converter: PropertyConverters.String })
|
|
242
|
+
], PacemSliderElement.prototype, "changePolicy", void 0);
|
|
243
|
+
__decorate([
|
|
244
|
+
Watch({ emit: false, converter: PropertyConverters.Json })
|
|
245
|
+
], PacemSliderElement.prototype, "format", void 0);
|
|
246
|
+
__decorate([
|
|
247
|
+
ViewChild(`.slider-track`)
|
|
248
|
+
], PacemSliderElement.prototype, "_track", void 0);
|
|
249
|
+
__decorate([
|
|
250
|
+
ViewChild(`.slider-progress`)
|
|
251
|
+
], PacemSliderElement.prototype, "_progress", void 0);
|
|
252
|
+
__decorate([
|
|
253
|
+
ViewChild(`.slider-thumb`)
|
|
254
|
+
], PacemSliderElement.prototype, "_thumb", void 0);
|
|
255
|
+
__decorate([
|
|
256
|
+
ViewChild(`${P}-text[min]`)
|
|
257
|
+
], PacemSliderElement.prototype, "_min", void 0);
|
|
258
|
+
__decorate([
|
|
259
|
+
ViewChild(`${P}-text[max]`)
|
|
260
|
+
], PacemSliderElement.prototype, "_max", void 0);
|
|
261
|
+
__decorate([
|
|
262
|
+
ViewChild(`${P}-drag-drop`)
|
|
263
|
+
], PacemSliderElement.prototype, "_dragger", void 0);
|
|
264
|
+
__decorate([
|
|
265
|
+
ViewChild(`${P}-shell-proxy`)
|
|
266
|
+
], PacemSliderElement.prototype, "_shellProxy", void 0);
|
|
267
|
+
PacemSliderElement = __decorate([
|
|
268
|
+
CustomElement({
|
|
269
|
+
tagName: P + '-slider',
|
|
270
|
+
template: `<div class="${PCSS}-viewfinder ${PCSS}-slider"><${P}-text text="{{ :host._format(:host.min) }}" min></${P}-text>
|
|
271
|
+
<div class="slider-track"><div class="slider-progress"></div></div>
|
|
272
|
+
<${P}-panel class="${PCSS}-clickable slider-thumb" behaviors="{{ [::_dragger] }}">
|
|
273
|
+
<div class="thumb-label"></div>
|
|
274
|
+
</${P}-panel>
|
|
275
|
+
<${P}-text text="{{ :host._format(:host.max) }}" max></${P}-text>
|
|
276
|
+
<div class="slider-footer"><${P}-text text="{{ :host.viewValue }}"></${P}-text></div>
|
|
277
|
+
</div>
|
|
278
|
+
<${P}-drag-drop lock-timeout="0"></${P}-drag-drop><${P}-resize watch-position="true" on-${Components.ResizeEventName}=":host._setTrackSize($event)" target="{{ ::_track }}"></${P}-resize>
|
|
279
|
+
<${P}-shell-proxy><${P}-balloon class="text-center"><${P}-text text="{{ :host.viewValue }}"></${P}-text></${P}-balloon></${P}-shell-proxy>
|
|
280
|
+
`,
|
|
281
|
+
shadow: Defaults.USE_SHADOW_ROOT
|
|
282
|
+
})
|
|
283
|
+
], PacemSliderElement);
|
|
284
|
+
export { PacemSliderElement };
|