@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.
Files changed (57) hide show
  1. package/LICENSE +191 -0
  2. package/NOTICE +4 -0
  3. package/dist/browser/pacem-scaffolding.js +10430 -0
  4. package/dist/browser/pacem-scaffolding.js.map +1 -0
  5. package/dist/browser/pacem-scaffolding.min.js +2 -0
  6. package/dist/browser/pacem-scaffolding.min.js.map +1 -0
  7. package/dist/bundle/pacem-scaffolding.min.mjs +380 -0
  8. package/dist/bundle/pacem-scaffolding.mjs +10046 -0
  9. package/dist/bundle/pacem-scaffolding.mjs.map +7 -0
  10. package/dist/esm/calendar-picker.js +478 -0
  11. package/dist/esm/char-counter.js +43 -0
  12. package/dist/esm/checkbox-list.js +75 -0
  13. package/dist/esm/checkbox.js +112 -0
  14. package/dist/esm/childform.js +237 -0
  15. package/dist/esm/contenteditable.js +326 -0
  16. package/dist/esm/datetime-picker.js +310 -0
  17. package/dist/esm/form.js +630 -0
  18. package/dist/esm/formfield.js +1065 -0
  19. package/dist/esm/geolocate.js +197 -0
  20. package/dist/esm/hierarchy.js +509 -0
  21. package/dist/esm/index-components-scaffolding.js +39 -0
  22. package/dist/esm/index-components.js +1 -0
  23. package/dist/esm/index-iife.js +3 -0
  24. package/dist/esm/index-root.js +2 -0
  25. package/dist/esm/index-scaffolding.js +3 -0
  26. package/dist/esm/index.js +2 -0
  27. package/dist/esm/input-chars.js +185 -0
  28. package/dist/esm/input-color.js +80 -0
  29. package/dist/esm/input-email.js +32 -0
  30. package/dist/esm/input-file.js +691 -0
  31. package/dist/esm/input-hidden.js +25 -0
  32. package/dist/esm/input-image.js +391 -0
  33. package/dist/esm/input-number.js +58 -0
  34. package/dist/esm/input-password.js +71 -0
  35. package/dist/esm/input-search.js +27 -0
  36. package/dist/esm/input-tel.js +31 -0
  37. package/dist/esm/input-text.js +36 -0
  38. package/dist/esm/input-url.js +32 -0
  39. package/dist/esm/input.js +215 -0
  40. package/dist/esm/l10n.js +66 -0
  41. package/dist/esm/latlng.js +178 -0
  42. package/dist/esm/namevalue-list.js +139 -0
  43. package/dist/esm/property-picker.js +84 -0
  44. package/dist/esm/radio-list.js +70 -0
  45. package/dist/esm/radio.js +79 -0
  46. package/dist/esm/select.js +126 -0
  47. package/dist/esm/slider.js +284 -0
  48. package/dist/esm/snapshot.js +325 -0
  49. package/dist/esm/suggest.js +545 -0
  50. package/dist/esm/tags.js +174 -0
  51. package/dist/esm/textarea-markdown.js +75 -0
  52. package/dist/esm/textarea.js +51 -0
  53. package/dist/esm/types-components.js +611 -0
  54. package/dist/esm/types.js +8 -0
  55. package/dist/esm/validators.js +409 -0
  56. package/package.json +38 -0
  57. package/typings/index.d.ts +2283 -0
@@ -0,0 +1,32 @@
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, CustomElement, Defaults, ViewChild } from '@pacem/pacem-core';
8
+ import { PacemTextualInputElement } from './input';
9
+ import { CHAR_COUNTER_CHILD } from './char-counter';
10
+ //namespace Pacem.Components.Scaffolding {
11
+ let PacemUrlInputElement = class PacemUrlInputElement extends PacemTextualInputElement {
12
+ constructor() {
13
+ super();
14
+ }
15
+ toggleReadonlyView(readonly) {
16
+ this.input.hidden = readonly;
17
+ this.anchor.hidden = !readonly;
18
+ }
19
+ get inputFields() {
20
+ return [this.input];
21
+ }
22
+ };
23
+ __decorate([
24
+ ViewChild('input[type=url]')
25
+ ], PacemUrlInputElement.prototype, "input", void 0);
26
+ __decorate([
27
+ ViewChild(P + '-a')
28
+ ], PacemUrlInputElement.prototype, "anchor", void 0);
29
+ PacemUrlInputElement = __decorate([
30
+ CustomElement({ tagName: P + '-input-url', template: `<input type="url" class="${PCSS}-input" />${CHAR_COUNTER_CHILD}<${P}-a class="${PCSS}-readonly" disabled="{{ $pacem.isNullOrEmpty(:host.value) }}" href="{{ :host.value }}" target="_blank"><${P}-text text="{{ :host.viewValue }}"></${P}-text></${P}-a>`, shadow: Defaults.USE_SHADOW_ROOT })
31
+ ], PacemUrlInputElement);
32
+ export { PacemUrlInputElement };
@@ -0,0 +1,215 @@
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 { PropertyConverters, Utils, Watch, CustomElementUtils } from '@pacem/pacem-core';
8
+ import { PacemBaseElement } from './types-components';
9
+ //namespace Pacem.Components.Scaffolding {
10
+ export var ChangePolicy;
11
+ (function (ChangePolicy) {
12
+ ChangePolicy["Input"] = "input";
13
+ ChangePolicy["Blur"] = "blur";
14
+ })(ChangePolicy || (ChangePolicy = {}));
15
+ const INPUT_FIELD_ACTIVATED_PROP = 'pacem:scaffolding:input_field';
16
+ export class PacemBaseInputElement extends PacemBaseElement {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.debounce = false;
20
+ this.changePolicy = ChangePolicy.Input;
21
+ this._focusHandler = (evt) => {
22
+ if (!this.autoselect) {
23
+ return;
24
+ }
25
+ let field = /* first field (usually the only one) */ this.inputField;
26
+ for (let f of this.inputFields ?? []) {
27
+ if (f === document.activeElement) {
28
+ field = f;
29
+ break;
30
+ }
31
+ }
32
+ field?.select();
33
+ };
34
+ }
35
+ propertyChangedCallback(name, old, val, first) {
36
+ super.propertyChangedCallback(name, old, val, first);
37
+ switch (name) {
38
+ case 'placeholder':
39
+ for (let inputField of this.inputFields ?? []) {
40
+ inputField.setAttribute(name, val);
41
+ }
42
+ break;
43
+ }
44
+ }
45
+ acceptValue(val) {
46
+ if (this.inputField && val !== this.inputField.value) {
47
+ this.inputField.value = Utils.isNullOrEmpty(val) ? '' : val;
48
+ }
49
+ }
50
+ get inputField() {
51
+ return this.inputFields[0];
52
+ }
53
+ onChange(evt) {
54
+ return new Promise((resolve) => {
55
+ if (this.readonly) {
56
+ resolve(this.value);
57
+ }
58
+ else if (evt.type === 'input' && this.changePolicy === ChangePolicy.Blur) {
59
+ resolve(this.value);
60
+ }
61
+ else {
62
+ //
63
+ const fn = () => {
64
+ const val = this.getValue(this.inputField.value);
65
+ if (val !== this.value) {
66
+ this.value = val;
67
+ // /* DO NOT MESS THE change EVENT DISPATCH */ this.dispatchEvent(new Event('change'));
68
+ }
69
+ resolve(val);
70
+ };
71
+ const d = this.debounce;
72
+ if (typeof d === 'number' && d > 0) {
73
+ clearTimeout(this._handle);
74
+ this._handle = setTimeout(fn, d);
75
+ }
76
+ else if (d === true) {
77
+ cancelAnimationFrame(this._handle);
78
+ this._handle = requestAnimationFrame(fn);
79
+ }
80
+ else
81
+ requestAnimationFrame(fn);
82
+ }
83
+ });
84
+ }
85
+ ;
86
+ registerInputFields(inputFields = this.inputFields) {
87
+ super.registerInputFields(inputFields);
88
+ if (!Utils.isNull(inputFields) && !Utils.isArray(inputFields)) {
89
+ inputFields = [inputFields];
90
+ }
91
+ for (let field of inputFields ?? []) {
92
+ if (!(field instanceof HTMLInputElement) && !(field instanceof HTMLTextAreaElement)) {
93
+ continue;
94
+ }
95
+ if (CustomElementUtils.getAttachedPropertyValue(field, INPUT_FIELD_ACTIVATED_PROP, 'off') === 'on') {
96
+ continue;
97
+ }
98
+ CustomElementUtils.setAttachedPropertyValue(field, INPUT_FIELD_ACTIVATED_PROP, 'on');
99
+ if ('size' in field) {
100
+ // HTMLInputElement only
101
+ field.size = 1;
102
+ }
103
+ field.autocomplete = 'off';
104
+ field.addEventListener('input', this.changeHandler, false);
105
+ field.addEventListener('focus', this._focusHandler, false);
106
+ }
107
+ }
108
+ unregisterInputFields(inputFields = this.inputFields) {
109
+ super.unregisterInputFields(inputFields);
110
+ if (!Utils.isNull(inputFields) && !Utils.isArray(inputFields)) {
111
+ inputFields = [inputFields];
112
+ }
113
+ for (let field of inputFields ?? []) {
114
+ if (CustomElementUtils.getAttachedPropertyValue(field, INPUT_FIELD_ACTIVATED_PROP) !== 'on') {
115
+ continue;
116
+ }
117
+ CustomElementUtils.deleteAttachedPropertyValue(field, INPUT_FIELD_ACTIVATED_PROP);
118
+ field.removeEventListener('input', this.changeHandler, false);
119
+ field.removeEventListener('focus', this._focusHandler, false);
120
+ }
121
+ }
122
+ viewActivatedCallback() {
123
+ super.viewActivatedCallback();
124
+ this.registerInputFields();
125
+ }
126
+ disconnectedCallback() {
127
+ this.unregisterInputFields();
128
+ super.disconnectedCallback();
129
+ }
130
+ }
131
+ __decorate([
132
+ Watch({
133
+ emit: false, converter: {
134
+ convert: (attr) => {
135
+ switch (attr) {
136
+ case 'true':
137
+ return true;
138
+ case 'false':
139
+ return false;
140
+ default:
141
+ return parseFloat(attr);
142
+ }
143
+ },
144
+ convertBack: (prop) => prop.toString()
145
+ }
146
+ })
147
+ ], PacemBaseInputElement.prototype, "debounce", void 0);
148
+ __decorate([
149
+ Watch({ emit: false, converter: PropertyConverters.String })
150
+ ], PacemBaseInputElement.prototype, "changePolicy", void 0);
151
+ __decorate([
152
+ Watch({ emit: false, converter: PropertyConverters.Boolean })
153
+ ], PacemBaseInputElement.prototype, "autoselect", void 0);
154
+ export class PacemOrdinalInputElement extends PacemBaseInputElement {
155
+ convertValueAttributeToProperty(attr) {
156
+ return parseFloat(attr);
157
+ }
158
+ propertyChangedCallback(name, old, val, first) {
159
+ super.propertyChangedCallback(name, old, val, first);
160
+ switch (name) {
161
+ case 'min':
162
+ case 'max':
163
+ case 'step':
164
+ val != null ? this.inputField.setAttribute(name, val) : this.inputField.removeAttribute(name);
165
+ break;
166
+ }
167
+ }
168
+ }
169
+ __decorate([
170
+ Watch({ converter: PropertyConverters.Number })
171
+ ], PacemOrdinalInputElement.prototype, "min", void 0);
172
+ __decorate([
173
+ Watch({ converter: PropertyConverters.Number })
174
+ ], PacemOrdinalInputElement.prototype, "max", void 0);
175
+ __decorate([
176
+ Watch({
177
+ converter: {
178
+ convert: (attr) => {
179
+ const num = parseFloat(attr);
180
+ return isNaN(num) ? 'any' : num;
181
+ },
182
+ convertBack: (val) => val.toString()
183
+ }
184
+ })
185
+ ], PacemOrdinalInputElement.prototype, "step", void 0);
186
+ export class PacemTextualInputElement extends PacemBaseInputElement {
187
+ convertValueAttributeToProperty(attr) {
188
+ return attr;
189
+ }
190
+ propertyChangedCallback(name, old, val, first) {
191
+ super.propertyChangedCallback(name, old, val, first);
192
+ switch (name) {
193
+ case 'pattern':
194
+ case 'maxlength':
195
+ case 'minlength':
196
+ val != null ? this.inputField.setAttribute(name, val) : this.inputField.removeAttribute(name);
197
+ break;
198
+ }
199
+ }
200
+ getValue(val) {
201
+ return Utils.isNullOrEmpty(val) ? null : val;
202
+ }
203
+ getViewValue(val) {
204
+ return val;
205
+ }
206
+ }
207
+ __decorate([
208
+ Watch({ converter: PropertyConverters.String })
209
+ ], PacemTextualInputElement.prototype, "pattern", void 0);
210
+ __decorate([
211
+ Watch({ converter: PropertyConverters.Number })
212
+ ], PacemTextualInputElement.prototype, "minlength", void 0);
213
+ __decorate([
214
+ Watch({ converter: PropertyConverters.Number })
215
+ ], PacemTextualInputElement.prototype, "maxlength", void 0);
@@ -0,0 +1,66 @@
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 { Utils, Transformer } from '@pacem/pacem-core';
8
+ const DefaultFormLocalizationOptions = {
9
+ display: (displayProp, prop, dictionary) => dictionary[`${displayProp}_${prop}`],
10
+ validator: (validatorType, validatorTypeIndex, prop, dictionary) => dictionary['validator_' + validatorType + '_' + prop] ?? dictionary['validator_' + validatorType + validatorTypeIndex + '_' + prop],
11
+ commandTooltip: (commandName, dictionary) => dictionary['command_tooltip_' + commandName]
12
+ };
13
+ export class Forms {
14
+ /**
15
+ * Localizes the metadata of a form **in place** using a translation dictionary.
16
+ *
17
+ * @param metadata The default metadata.
18
+ * @param dictionary The translation dictionary.
19
+ * @param options Custom replacement strategy, just in case.
20
+ * @returns The localized metadata.
21
+ */
22
+ static localizeMetadata(metadata, dictionary, options) {
23
+ return Forms._localizeMetadata(metadata, dictionary, options);
24
+ }
25
+ static _localizeMetadata(metadata, dictionary, options, prefix = '') {
26
+ options = Utils.extend({}, DefaultFormLocalizationOptions, options);
27
+ for (let prop of metadata.props) {
28
+ // child form
29
+ if ('props' in prop && typeof prop.props === 'object' && !Utils.isArray(prop.props)) {
30
+ const pre = prefix + prop.prop + '.';
31
+ prop.props = Forms._localizeMetadata(prop.props, dictionary, options, pre);
32
+ }
33
+ const display = prop.display = prop.display ?? {};
34
+ const property = prefix + prop.prop;
35
+ display.name = options.display('name', property, dictionary) ?? display.name;
36
+ display.watermark = options.display('watermark', property, dictionary) ?? display.watermark;
37
+ display.description = options.display('description', property, dictionary) ?? display.description;
38
+ if (!Utils.isNullOrEmpty(prop.commands)) {
39
+ for (let command of prop.commands) {
40
+ const tooltip = options.commandTooltip(command.name, dictionary);
41
+ if (!Utils.isNullOrEmpty(tooltip)) {
42
+ command.tooltip = tooltip;
43
+ }
44
+ }
45
+ }
46
+ if (!Utils.isNullOrEmpty(prop.validators)) {
47
+ const memoizer = {};
48
+ for (let validator of prop.validators) {
49
+ const type = validator.type;
50
+ if (typeof type === 'string') {
51
+ const index = memoizer[type] = (memoizer[type] ?? -1) + 1;
52
+ const errorMessage = options.validator(type, index, property, dictionary);
53
+ if (!Utils.isNullOrEmpty(errorMessage)) {
54
+ validator['errorMessage'] = errorMessage;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ return metadata;
61
+ }
62
+ }
63
+ __decorate([
64
+ Transformer('forms.localizeMetadata')
65
+ ], Forms, "localizeMetadata", null);
66
+ //}
@@ -0,0 +1,178 @@
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 { Components as ComponentsMaps } from '@pacem/pacem-maps';
9
+ import { PacemBaseElement } from './types-components';
10
+ //namespace Pacem.Components.Scaffolding {
11
+ export const DEFAULT_TILES = "";
12
+ export const DEFAULT_ATTRIBUTION = "";
13
+ //const TILES = `//api.mapbox.com/styles/v1/cmerighi/ciwz1gib7002l2prvgpi724nk/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiY21lcmlnaGkiLCJhIjoiY2lsZHIxdGJmMDAxOHc4bHowamxpZ2Z2OCJ9.7I7ndF-rAkx_1Sqi0bw3Ew`;
14
+ //const ATTRIBUTION = `Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>`
15
+ const REVERSE_GEOCODE_URL = 'https://nominatim.openstreetmap.org/reverse';
16
+ let PacemLatLngElement = class PacemLatLngElement extends PacemBaseElement {
17
+ convertValueAttributeToProperty(attr) {
18
+ const regexArray = /^\s*([+-]?\d+\.?\d+)[,\s]\s*([+-]?\d+\.?\d+)\s*$/.exec(attr);
19
+ if (regexArray && regexArray.length === 3) {
20
+ return { lat: parseFloat(regexArray[1]), lng: parseFloat(regexArray[2]) };
21
+ }
22
+ throw `Invalid coordinates format for "${attr}"`;
23
+ }
24
+ compareValuePropertyValues(old, val) {
25
+ if (old && typeof old.lat === 'number' && typeof old.lng === 'number'
26
+ && val && typeof val.lat === 'number' && typeof val.lng === 'number') {
27
+ return old.lat === val.lat && old.lng === val.lng;
28
+ }
29
+ return false;
30
+ }
31
+ getViewValue(value) {
32
+ return this._getViewValue(value);
33
+ }
34
+ _getViewValue(value, precision = 8) {
35
+ return value && typeof value.lat === 'number' && typeof value.lng === 'number' && value.lat.toFixed(precision) + ',' + value.lng.toFixed(precision) || '';
36
+ }
37
+ get inputFields() {
38
+ return [this._latInput, this._lngInput];
39
+ }
40
+ toggleReadonlyView(readonly) {
41
+ this._inputContainer.hidden = /*
42
+ this._lngInput.hide = this._latInput.hide =*/
43
+ readonly;
44
+ }
45
+ // regex:
46
+ acceptValue(val) {
47
+ let e_val = this._ensureValue(val);
48
+ this._lat = e_val.lat;
49
+ this._lng = e_val.lng;
50
+ }
51
+ _ensureValue(val) {
52
+ return (val && typeof val.lat === 'number' && typeof val.lng === 'number') ? val : ComponentsMaps.Maps.MapConsts.DEFAULT_COORDS;
53
+ }
54
+ onChange(evt) {
55
+ if (evt && evt.type === 'dragend') {
56
+ var mevt = evt;
57
+ // geocoordinate change due to map drag
58
+ this._lat = mevt.detail.position.lat;
59
+ this._lng = mevt.detail.position.lng;
60
+ } // else: geocoordinate change due to text-input
61
+ const lat = this._lat;
62
+ const lng = this._lng;
63
+ if (Utils.isNull(lat) || Utils.isNull(lng))
64
+ return Utils.fromResult(this.value);
65
+ return Utils.fromResult(this.value = { lat: lat, lng: lng });
66
+ }
67
+ propertyChangedCallback(name, old, val, first) {
68
+ super.propertyChangedCallback(name, old, val, first);
69
+ if (name === 'options' && !first) {
70
+ const opts = Utils.clone((val || { provider: 'osm' }));
71
+ this._synchronizeOptions(opts);
72
+ }
73
+ }
74
+ viewActivatedCallback() {
75
+ super.viewActivatedCallback();
76
+ this._synchronizeOptions();
77
+ }
78
+ _synchronizeOptions(opts = this.options || { provider: 'osm' }) {
79
+ const marker = this._marker, map = this._map;
80
+ marker.icon = opts.icon;
81
+ switch (opts && opts.provider) {
82
+ case 'azure':
83
+ this._azureAdapter.subscriptionKey = opts.apiKey;
84
+ map.adapter = this._azureAdapter;
85
+ break;
86
+ case 'google':
87
+ case 'gmaps':
88
+ this._googleAdapter.apiKey = opts.apiKey;
89
+ map.adapter = this._googleAdapter;
90
+ break;
91
+ default:
92
+ if (!Utils.isNullOrEmpty(opts.attribution)) {
93
+ this._leafletAdapter.attribution = opts.attribution;
94
+ }
95
+ if (!Utils.isNullOrEmpty(opts.tiles)) {
96
+ this._leafletAdapter.tiles = opts.tiles;
97
+ }
98
+ map.adapter = this._leafletAdapter;
99
+ break;
100
+ }
101
+ delete opts['provider'];
102
+ delete opts['icon'];
103
+ delete opts['apiKey'];
104
+ delete opts['attribution'];
105
+ delete opts['tiles'];
106
+ for (let prop in opts) {
107
+ if (prop in map) {
108
+ map[prop] = opts[prop];
109
+ }
110
+ }
111
+ }
112
+ };
113
+ __decorate([
114
+ ViewChild(P + '-map-adapter-leaflet')
115
+ ], PacemLatLngElement.prototype, "_leafletAdapter", void 0);
116
+ __decorate([
117
+ ViewChild(P + '-map-adapter-azure')
118
+ ], PacemLatLngElement.prototype, "_azureAdapter", void 0);
119
+ __decorate([
120
+ ViewChild(P + '-map-adapter-google')
121
+ ], PacemLatLngElement.prototype, "_googleAdapter", void 0);
122
+ __decorate([
123
+ ViewChild(P + '-map')
124
+ ], PacemLatLngElement.prototype, "_map", void 0);
125
+ __decorate([
126
+ ViewChild(P + '-map-marker')
127
+ ], PacemLatLngElement.prototype, "_marker", void 0);
128
+ __decorate([
129
+ ViewChild(P + '-input-number:nth-child(1)')
130
+ ], PacemLatLngElement.prototype, "_latInput", void 0);
131
+ __decorate([
132
+ ViewChild(P + '-input-number:nth-child(2)')
133
+ ], PacemLatLngElement.prototype, "_lngInput", void 0);
134
+ __decorate([
135
+ ViewChild(`.${PCSS}-latlng-fields`)
136
+ ], PacemLatLngElement.prototype, "_inputContainer", void 0);
137
+ __decorate([
138
+ ViewChild(P + '-fetch')
139
+ ], PacemLatLngElement.prototype, "_fetcher", void 0);
140
+ __decorate([
141
+ Watch({ converter: PropertyConverters.Json, emit: false })
142
+ ], PacemLatLngElement.prototype, "options", void 0);
143
+ __decorate([
144
+ Watch()
145
+ ], PacemLatLngElement.prototype, "_lat", void 0);
146
+ __decorate([
147
+ Watch()
148
+ ], PacemLatLngElement.prototype, "_lng", void 0);
149
+ PacemLatLngElement = __decorate([
150
+ CustomElement({
151
+ tagName: P + '-latlng', shadow: Defaults.USE_SHADOW_ROOT,
152
+ template: `<div class="${PCSS}-latlng">
153
+ <div class="${PCSS}-latlng-fields ${PCSS}-viewfinder">
154
+ <${P}-input-number class="${PCSS}-lat" value="{{ :host._lat, twoway }}" min="-90" max="90" step="{{ 'any' }}"></${P}-input-number>
155
+ <${P}-input-number class="${PCSS}-lng" value="{{ :host._lng, twoway }}" min="-180" max="180" step="{{ 'any' }}"></${P}-input-number>
156
+ </div>
157
+ <${P}-panel hide="{{ Pacem.Utils.isNull(:host.value) || :host.readonly }}">
158
+ <dl class="${PCSS}-latlng-preview">
159
+ <dt>decimals:</dt><dd><${P}-text text="{{ :host._getViewValue(:host.value, 12) }}"></${P}-text></dd>
160
+ <dt>address:</dt><dd><${P}-text text="{{ ::_fetcher.result.display_name || '?' }}"></${P}-text></dd>
161
+ <dt>degrees:</dt><dd><${P}-span css-class="{{ {'${PCSS}-lat-north': :host._lat > 0, '${PCSS}-lat-south': :host._lat < 0} }}" content="{{ $pacem.decToDeg(Math.abs(:host._lat)) }}"></${P}-span>,
162
+ <${P}-span css-class="{{ {'${PCSS}-lng-east': :host._lng > 0, '${PCSS}-lng-west': :host._lng < 0} }}" content="{{ $pacem.decToDeg(Math.abs(:host._lng)) }}"></${P}-span></dd>
163
+ </dl>
164
+ </${P}-panel>
165
+ <${P}-span class="${PCSS}-readonly" hide="{{ !:host.readonly }}" content="{{ :host.viewValue + ($pacem.isNullOrEmpty(::_fetcher.result.display_name) ? '' : (' <small>'+ ::_fetcher.result.display_name +'</small>')) }}"></${P}-span>
166
+
167
+ <${P}-map-adapter-leaflet></${P}-map-adapter-leaflet>
168
+ <${P}-map-adapter-azure></${P}-map-adapter-azure>
169
+ <${P}-map-adapter-google></${P}-map-adapter-google>
170
+
171
+ <${P}-map adapter="{{ ::_adapter }}">
172
+ <${P}-map-marker position="{{ :host._ensureValue(:host.value) }}" on-dragend=":host.changeHandler($event)" draggable="{{ !:host.readonly }}"></${P}-map-marker>
173
+ </${P}-map>
174
+ <${P}-fetch disabled="{{ $pacem.isNull(:host.value) }}" parameters="{{ { format: 'json', lat: :host._lat, lon: :host._lng } }}" url="${REVERSE_GEOCODE_URL}"></${P}-fetch>
175
+ </div>`
176
+ })
177
+ ], PacemLatLngElement);
178
+ export { PacemLatLngElement };
@@ -0,0 +1,139 @@
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, CustomElement, Watch, Utils, PropertyConverters, Defaults } from '@pacem/pacem-core';
8
+ import { PacemBaseElement } from './types-components';
9
+ import { ChangePolicy } from './input';
10
+ //namespace Pacem.Components.Scaffolding {
11
+ const ITEM_TXT_CORE = `change-policy="${ChangePolicy.Blur}" readonly="{{ :host.readonly }}"`;
12
+ function isEmpty(nvp) {
13
+ return Utils.isNullOrEmpty(nvp && nvp.name);
14
+ }
15
+ function pullEmpty() {
16
+ return { name: '', value: '' };
17
+ }
18
+ let PacemNameValueListElement = class PacemNameValueListElement extends PacemBaseElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ this.inputFields = [];
22
+ this._bag = [];
23
+ }
24
+ toggleReadonlyView(readonly) {
25
+ // let the bindings do their job...
26
+ }
27
+ onChange(evt) {
28
+ return new Promise((resolve, reject) => {
29
+ let val = this._bagToValue(this._bag);
30
+ if (!this.compareValuePropertyValues(val, this.value)) {
31
+ resolve(this.value = val);
32
+ }
33
+ else {
34
+ reject();
35
+ }
36
+ });
37
+ }
38
+ acceptValue(val) {
39
+ this._bag = this._valueToBag(val);
40
+ }
41
+ getViewValue(value) {
42
+ return ''; // unneeded
43
+ }
44
+ compareValuePropertyValues(old, val) {
45
+ return Utils.Json.stringify(old) === Utils.Json.stringify(val);
46
+ }
47
+ convertValueAttributeToProperty(attr) {
48
+ return PropertyConverters.Json.convert(attr);
49
+ }
50
+ propertyChangedCallback(name, old, val, first) {
51
+ super.propertyChangedCallback(name, old, val, first);
52
+ if (name === 'dictionary' && !first) {
53
+ this.value = this._bagToValue();
54
+ }
55
+ }
56
+ _bagToValue(bag = this._bag) {
57
+ if (!this.dictionary) {
58
+ // not a dictionary
59
+ // return an array
60
+ let b = [];
61
+ for (let item of bag || []) {
62
+ if (isEmpty(item)) {
63
+ continue;
64
+ }
65
+ if (b.find(i => i.name === item.name && i.value === item.value)) {
66
+ continue;
67
+ }
68
+ b.push(item);
69
+ }
70
+ return b;
71
+ }
72
+ // dictionary
73
+ // return an object
74
+ let v = {};
75
+ for (let kvp of bag || []) {
76
+ if (kvp.name in v) {
77
+ // skip existing names...
78
+ continue;
79
+ }
80
+ v[kvp.name] = kvp.value;
81
+ }
82
+ return v;
83
+ }
84
+ _valueToBag(val = this.value) {
85
+ const bag = [];
86
+ if (!Utils.isNullOrEmpty(val) && typeof val === 'object') {
87
+ if (this.dictionary && !Utils.isArray(val)) {
88
+ for (let prop in val) {
89
+ bag.push({ name: prop, value: val[prop] });
90
+ }
91
+ }
92
+ else if (!this.dictionary && Utils.isArray(val)) {
93
+ Array.prototype.splice.apply(bag, [0, 0].concat(val.map(i => Utils.clone(i))));
94
+ }
95
+ }
96
+ return !Utils.isNullOrEmpty(bag) ? bag : [pullEmpty()];
97
+ }
98
+ _deleteAt(evt) {
99
+ this._bag.splice(evt.detail, 1);
100
+ this.changeHandler(evt);
101
+ }
102
+ _addItem(evt) {
103
+ const bag = this._bag, lastItem = this._bag[this._bag.length - 1];
104
+ if (Utils.isEmpty(bag) || !isEmpty(lastItem)) {
105
+ bag.push(pullEmpty());
106
+ }
107
+ }
108
+ };
109
+ __decorate([
110
+ Watch({ emit: false, converter: PropertyConverters.Boolean })
111
+ ], PacemNameValueListElement.prototype, "dictionary", void 0);
112
+ __decorate([
113
+ Watch({ converter: PropertyConverters.Json })
114
+ ], PacemNameValueListElement.prototype, "_bag", void 0);
115
+ PacemNameValueListElement = __decorate([
116
+ CustomElement({
117
+ tagName: P + '-namevalue-list', shadow: Defaults.USE_SHADOW_ROOT,
118
+ template: `<${P}-repeater datasource="{{ :host._bag }}" on-itemdelete=":host._deleteAt($event)">
119
+ <template>
120
+ <div class="${PCSS}-fieldset ${PCSS}-margin margin-bottom-1">
121
+ <div class="fieldset-auto">
122
+ <div class="${PCSS}-fieldgroup">
123
+ <${P}-input-text ${ITEM_TXT_CORE} value="{{ ^item.name, twoway }}" on-change=":host.changeHandler($event)"></${P}-input-text>
124
+ <div class="fieldgroup-prepend"></div>
125
+ </div>
126
+ <div class="${PCSS}-fieldgroup">
127
+ <${P}-input-text ${ITEM_TXT_CORE} value="{{ ^item.value, twoway }}" on-change=":host.changeHandler($event)"></${P}-input-text>
128
+ <div class="fieldgroup-append">
129
+ <${P}-button class="${PCSS}-cell cols-2 flat delete" hide="{{ :host.readonly }}" command-name="delete" command-argument="{{ ^index }}"></${P}-button>
130
+ </div>
131
+ </div>
132
+ </div>
133
+ </div>
134
+ </template>
135
+ <${P}-button class="flat add" hide="{{ :host.readonly }}" on-click=":host._addItem($event)"></${P}-button>
136
+ </${P}-repeater>`
137
+ })
138
+ ], PacemNameValueListElement);
139
+ export { PacemNameValueListElement };