@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,112 @@
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, PropertyConverters, Utils, ViewChild, Watch } from '@pacem/pacem-core';
8
+ import { PacemBaseElement } from './types-components';
9
+ //namespace Pacem.Components.Scaffolding {
10
+ const StringOrBooleanPropertyConverter = {
11
+ convert: (attr) => attr === 'true' ? true : (attr === 'false' ? false : attr),
12
+ convertBack: (prop) => prop.toString()
13
+ };
14
+ let PacemCheckboxElement = class PacemCheckboxElement extends PacemBaseElement {
15
+ constructor() {
16
+ super('checkbox');
17
+ this.caption = '';
18
+ this._key = '_' + Utils.uniqueCode();
19
+ }
20
+ convertValueAttributeToProperty(attr) {
21
+ StringOrBooleanPropertyConverter.convert(attr) === this.trueValue ? this.trueValue : this.falseValue;
22
+ }
23
+ toggleReadonlyView(readonly) {
24
+ this.span.hidden = !readonly;
25
+ this._checkbox.hidden = this._label.hidden = readonly;
26
+ }
27
+ get inputFields() {
28
+ return [this._checkbox];
29
+ }
30
+ onChange(evt) {
31
+ this.selected = this._checkbox.checked;
32
+ const value = this.value = this.selected ? this.trueValue : this.falseValue;
33
+ return Utils.fromResult(value);
34
+ }
35
+ viewActivatedCallback() {
36
+ super.viewActivatedCallback();
37
+ this._checkbox.id = this._label.htmlFor = this._key;
38
+ this._synchronizeUi();
39
+ if (this.value /* weak equality to deal with declarative values and conversions */ == this.trueValue)
40
+ this.selected = true;
41
+ else if (this.value /* weak equality to deal with declarative values and conversions */ == this.falseValue)
42
+ this.selected = false;
43
+ }
44
+ propertyChangedCallback(name, old, val, first) {
45
+ super.propertyChangedCallback(name, old, val, first);
46
+ if (!this.isReady) {
47
+ // the following are only UI-relevant modifications
48
+ return;
49
+ }
50
+ switch (name) {
51
+ case 'caption':
52
+ this._label.hidden = Utils.isNullOrEmpty(val);
53
+ break;
54
+ case 'name':
55
+ this._checkbox.name = val;
56
+ break;
57
+ case 'selected':
58
+ this._synchronizeUi();
59
+ break;
60
+ }
61
+ }
62
+ _synchronizeUi(val = this.selected) {
63
+ if (this._checkbox.checked = val) {
64
+ this.value = this.trueValue;
65
+ Utils.addClass(this, PCSS + '-selected');
66
+ this.aria.attributes.set('checked', 'true');
67
+ }
68
+ else {
69
+ this.value = this.falseValue;
70
+ Utils.removeClass(this, PCSS + '-selected');
71
+ this.aria.attributes.set('checked', 'false');
72
+ }
73
+ }
74
+ acceptValue(val) {
75
+ this.selected = val /* weak equality to deal with declarative values and conversions */ == this.trueValue;
76
+ }
77
+ getViewValue(val) {
78
+ if (!Utils.isNull(val))
79
+ return this.caption;
80
+ return '';
81
+ }
82
+ };
83
+ __decorate([
84
+ ViewChild("input[type=checkbox]")
85
+ ], PacemCheckboxElement.prototype, "_checkbox", void 0);
86
+ __decorate([
87
+ ViewChild("label")
88
+ ], PacemCheckboxElement.prototype, "_label", void 0);
89
+ __decorate([
90
+ ViewChild(`.${PCSS}-readonly`)
91
+ ], PacemCheckboxElement.prototype, "span", void 0);
92
+ __decorate([
93
+ Watch({ converter: PropertyConverters.String })
94
+ ], PacemCheckboxElement.prototype, "caption", void 0);
95
+ __decorate([
96
+ Watch({ emit: false, converter: StringOrBooleanPropertyConverter })
97
+ ], PacemCheckboxElement.prototype, "trueValue", void 0);
98
+ __decorate([
99
+ Watch({ emit: false, converter: StringOrBooleanPropertyConverter })
100
+ ], PacemCheckboxElement.prototype, "falseValue", void 0);
101
+ __decorate([
102
+ Watch({ converter: PropertyConverters.Boolean })
103
+ ], PacemCheckboxElement.prototype, "selected", void 0);
104
+ PacemCheckboxElement = __decorate([
105
+ CustomElement({
106
+ tagName: P + '-checkbox',
107
+ template: `<${P}-span class="${PCSS}-readonly ${PCSS}-checkbox" text="{{ :host.caption }}"></${P}-span>
108
+ <input type="checkbox" class="${PCSS}-input" /><label class="${PCSS}-label ${PCSS}-checkbox ${PCSS}-viewfinder" pacem><${P}-span content="{{ :host.caption }}"></${P}-span></label>`,
109
+ shadow: Defaults.USE_SHADOW_ROOT
110
+ })
111
+ ], PacemCheckboxElement);
112
+ export { PacemCheckboxElement };
@@ -0,0 +1,237 @@
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, PacemEventTarget, PropertyChangeEventName, Components, PropertyConverters, Utils, ViewChild, Watch, UI, avoidHandler } from '@pacem/pacem-core';
8
+ import { PacemBaseElement } from './types-components';
9
+ /** For internal use ONLY! */
10
+ let PacemChildFormPropagatorElement = class PacemChildFormPropagatorElement extends PacemEventTarget {
11
+ propertyChangedCallback(name, old, val, first) {
12
+ super.propertyChangedCallback(name, old, val, first);
13
+ if (!first) {
14
+ const prop = this.property, value = this.watch, hasPropDefined = !Utils.isNullOrEmpty(prop), hasModelDefined = !Utils.isNull(this.model);
15
+ if (name === 'watch'
16
+ || name === 'property'
17
+ || (name === 'model' && hasPropDefined && hasModelDefined && Utils.isArray(val) && val.some(i => !(prop in i) || i[prop] !== value))
18
+ || (name === 'model' && hasPropDefined && hasModelDefined && !Utils.isArray(val) && (!(prop in val) || val[prop] !== value))) {
19
+ this._synchronize();
20
+ }
21
+ }
22
+ }
23
+ viewActivatedCallback() {
24
+ super.viewActivatedCallback();
25
+ this._synchronize();
26
+ }
27
+ _synchronize() {
28
+ const model = this.model, propagate = this.property, value = this.watch;
29
+ if (Utils.isNullOrEmpty(model) || Utils.isNullOrEmpty(propagate)) {
30
+ return;
31
+ }
32
+ if (Utils.isArray(model)) {
33
+ for (let item of model) {
34
+ item[propagate] = value;
35
+ }
36
+ // trigger change
37
+ this.model = model.slice(0);
38
+ }
39
+ else {
40
+ model[propagate] = value;
41
+ // trigger change
42
+ this.model = Utils.extend({}, model);
43
+ }
44
+ }
45
+ };
46
+ __decorate([
47
+ Watch({ emit: true /* mandatory twoway binding */ })
48
+ ], PacemChildFormPropagatorElement.prototype, "model", void 0);
49
+ __decorate([
50
+ Watch({ emit: false, converter: PropertyConverters.String, reflectBack: true })
51
+ ], PacemChildFormPropagatorElement.prototype, "property", void 0);
52
+ __decorate([
53
+ Watch({ emit: false })
54
+ ], PacemChildFormPropagatorElement.prototype, "watch", void 0);
55
+ PacemChildFormPropagatorElement = __decorate([
56
+ CustomElement({ tagName: P + '-childform-propagator' })
57
+ ], PacemChildFormPropagatorElement);
58
+ export { PacemChildFormPropagatorElement };
59
+ /** Represents a sub-form for automatic generation of editing fields for sub-entities. */
60
+ let PacemChildFormElement = class PacemChildFormElement extends PacemBaseElement {
61
+ constructor() {
62
+ super(...arguments);
63
+ /** Internal representation of the entity. */
64
+ this._model = [];
65
+ this._subForms = [];
66
+ }
67
+ get inputFields() {
68
+ return [];
69
+ }
70
+ toggleReadonlyView(readonly) {
71
+ // automatic
72
+ }
73
+ onChange(evt) {
74
+ return new Promise((resolve, _) => {
75
+ var val = this._modelToEntity();
76
+ resolve(this.value = val);
77
+ });
78
+ }
79
+ acceptValue(val) {
80
+ this._entityToModel(val);
81
+ }
82
+ getViewValue(value) {
83
+ return '';
84
+ }
85
+ convertValueAttributeToProperty(attr) {
86
+ return PropertyConverters.Json.convert(attr, this);
87
+ }
88
+ propertyChangedCallback(name, old, val, first) {
89
+ super.propertyChangedCallback(name, old, val, first);
90
+ switch (name) {
91
+ case 'mode':
92
+ this._entityToModel();
93
+ break;
94
+ }
95
+ }
96
+ _dragStart(evt) {
97
+ var args = evt.detail;
98
+ const size = Utils.offset(args.element), floater = args.floater;
99
+ floater.style.width = size.width + 'px';
100
+ floater.style.height = size.height + 'px';
101
+ }
102
+ _dragEnd(evt) {
103
+ if (this.mode === 'array' /*&& !Utils.isNull(evt.detail.target)*/) {
104
+ this._triggerChange();
105
+ }
106
+ }
107
+ reset() {
108
+ super.reset();
109
+ // once the value/entity with this component is reset
110
+ // it is not necessary to process the subForms
111
+ this._subForms.forEach(f => {
112
+ f.setPristine();
113
+ });
114
+ }
115
+ _itemCreate(evt) {
116
+ const ndx = evt.detail.index, subForms = this._subForms;
117
+ evt.detail.dom[0].childNodes.forEach(e => {
118
+ if (e instanceof Element && e.localName === (P + '-form')) {
119
+ subForms.splice(ndx, subForms.length - ndx, e);
120
+ }
121
+ });
122
+ }
123
+ _itemChange(ndx, evt) {
124
+ if (evt.detail.propertyName === 'entity'
125
+ && Utils.Json.stringify(this._model[ndx]) !== Utils.Json.stringify(evt.detail.currentValue)) {
126
+ this._model.splice(ndx, 1, evt.detail.currentValue);
127
+ this._triggerChange();
128
+ }
129
+ }
130
+ _deleteAt(evt) {
131
+ // prevent the event to bubble (nested scenarios).
132
+ avoidHandler(evt.srcEvent);
133
+ const model = this._model;
134
+ if (this.mode === 'array') {
135
+ model.splice(evt.detail, 1);
136
+ }
137
+ else {
138
+ model.splice(0, model.length);
139
+ }
140
+ this._triggerChange();
141
+ }
142
+ _addItem(evt) {
143
+ const mode = this.mode, model = this._model;
144
+ if (mode === 'array') {
145
+ model.push({});
146
+ }
147
+ else {
148
+ model.splice(0, model.length, {});
149
+ }
150
+ this._triggerChange();
151
+ }
152
+ _triggerChange() {
153
+ this.changeHandler(new Event('change'));
154
+ }
155
+ _entityToModel(entity = this.value) {
156
+ switch (this.mode) {
157
+ case 'array':
158
+ let arr = entity || [];
159
+ if (Utils.isArray(arr)) {
160
+ this._model.cloneFrom(arr);
161
+ }
162
+ break;
163
+ default:
164
+ const model = this._model, length = model.length;
165
+ if (length !== 1 || model[0] !== entity) {
166
+ if (!Utils.isNull(entity)) {
167
+ model.splice(0, length, entity);
168
+ }
169
+ else {
170
+ model.splice(0, length);
171
+ }
172
+ }
173
+ break;
174
+ }
175
+ }
176
+ _modelToEntity(model = this._model) {
177
+ switch (this.mode) {
178
+ case 'array':
179
+ return Utils.clone(model);
180
+ default:
181
+ return model && model.length && model[0] || null;
182
+ }
183
+ }
184
+ };
185
+ __decorate([
186
+ Watch({ emit: false, converter: PropertyConverters.String })
187
+ ], PacemChildFormElement.prototype, "fetchCredentials", void 0);
188
+ __decorate([
189
+ Watch({ emit: false, converter: PropertyConverters.Json })
190
+ ], PacemChildFormElement.prototype, "fetchHeaders", void 0);
191
+ __decorate([
192
+ ViewChild('.' + PCSS + '-childform')
193
+ ], PacemChildFormElement.prototype, "_container", void 0);
194
+ __decorate([
195
+ ViewChild(P + '-drag-drop')
196
+ ], PacemChildFormElement.prototype, "_dragger", void 0);
197
+ __decorate([
198
+ ViewChild('.' + PCSS + '-childform-item-floater')
199
+ ], PacemChildFormElement.prototype, "_floater", void 0);
200
+ __decorate([
201
+ Watch({ converter: PropertyConverters.String })
202
+ ], PacemChildFormElement.prototype, "mode", void 0);
203
+ __decorate([
204
+ Watch({ converter: PropertyConverters.Boolean })
205
+ ], PacemChildFormElement.prototype, "lockItems", void 0);
206
+ __decorate([
207
+ Watch({ converter: PropertyConverters.Json })
208
+ ], PacemChildFormElement.prototype, "metadata", void 0);
209
+ __decorate([
210
+ Watch({ converter: PropertyConverters.Json })
211
+ ], PacemChildFormElement.prototype, "_model", void 0);
212
+ PacemChildFormElement = __decorate([
213
+ CustomElement({
214
+ tagName: P + '-childform', shadow: Defaults.USE_SHADOW_ROOT,
215
+ template: `<${P}-repeater datasource="{{ :host._model }}" on-itemdelete=":host._deleteAt($event)" on-${Components.RepeaterItemCreateEventName}=":host._itemCreate($event)">
216
+ <div class="${PCSS}-childform">
217
+ <template>
218
+ <${P}-panel class="${PCSS}-childform-item" behaviors="{{ [::_dragger] }}">
219
+ <${P}-panel class="childform-item-handle ${PCSS}-margin margin-right-1" hide="{{ :host.lockItems || :host.readonly || :host.mode !== 'array' || !(:host._model && :host._model.length > 1) }}"><i class="${PCSS}-icon drag-handle">drag_handle</i></${P}-panel>
220
+ <${P}-panel class="childform-item-index text-small"><${P}-span hide="{{ !:host.readonly || :host.mode !== 'array' }}" class="${PCSS}-margin margin-right-1" text="{{ ^index+1 }}"></${P}-span></${P}-panel>
221
+ <${P}-form entity="{{ ^item }}" fetch-headers="{{ :host.fetchHeaders }}" fetch-credentials="{{ :host.fetchCredentials }}" on-${PropertyChangeEventName}=":host._itemChange(^index, $event)" readonly="{{ :host.readonly }}" metadata="{{ :host.metadata }}" autogenerate="true" logger="{{ :host.logger }}"></${P}-form>
222
+ <${P}-button tab-order="-1" class="flat circular circle-small clear ${PCSS}-margin margin-left-1" hide="{{ :host.lockItems || :host.readonly }}" command-name="delete" command-argument="{{ ^index }}"></${P}-button>
223
+ </${P}-panel>
224
+ </template>
225
+ </div>
226
+ <${P}-button tab-order="-1" class="flat circular circle-small add" hide="{{ :host.lockItems || :host.readonly || !(:host.mode === 'array' || $pacem.isNullOrEmpty(:host._model)) }}" on-click=":host._addItem($event)"></${P}-button>
227
+ </${P}-repeater>
228
+ <div class="${PCSS}-childform-item-floater ${PCSS}-panel panel-border">
229
+ <div class="corner top-left"></div><div class="corner top-right"></div><div class="corner bottom-left"></div><div class="corner bottom-right"></div>
230
+ </div>
231
+ <${P}-drag-drop floater="{{ ::_floater }}" disabled="{{ :host.lockItems }}"
232
+ on-${UI.DragDropEventType.Start}=":host._dragStart($event)"
233
+ on-${UI.DragDropEventType.End}=":host._dragEnd($event)"
234
+ drop-behavior="${UI.DropBehavior.InsertChild}" mode="${UI.DragDataMode.Alias}" handle-selector=".drag-handle" drop-targets="{{ [::_container] }}"></${P}-drag-drop>`
235
+ })
236
+ ], PacemChildFormElement);
237
+ export { PacemChildFormElement };
@@ -0,0 +1,326 @@
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 { CustomTypedEvent, CustomEventUtils, Debounce, Utils, P, PCSS, CustomElement, Watch, Defaults, ViewChild, PropertyChangeEvent, PropertyChangeEventName } from '@pacem/pacem-core';
8
+ import { HistoryService } from '@pacem/pacem-foundation';
9
+ import { PacemItemElement, PacemItemsContainerBaseElement } from './types-components';
10
+ import { CHAR_COUNTER_CHILD } from './char-counter';
11
+ //namespace Pacem.Components.Scaffolding {
12
+ const EXECUTECOMMAND_NAME = 'execute';
13
+ const EMPTY_CONTENT = '<p><br></p>';
14
+ class ContenteditableChangeEvent extends CustomTypedEvent {
15
+ constructor(html) {
16
+ super('contenteditablechange', { html: html });
17
+ }
18
+ }
19
+ export class PacemContenteditableCommandElement extends PacemItemElement {
20
+ constructor() {
21
+ super(...arguments);
22
+ this._containerPropChangeHandler = (evt) => {
23
+ const p = evt.detail;
24
+ this.containerPropertyChangedCallback(p.propertyName, p.oldValue, p.currentValue, p.firstChange);
25
+ };
26
+ }
27
+ execCommand(...args) {
28
+ const me = this;
29
+ if (me.disabled) {
30
+ return;
31
+ }
32
+ me.exec.apply(me, args).then(_ => {
33
+ me.dispatchEvent(new Event(EXECUTECOMMAND_NAME));
34
+ }, e => {
35
+ console.error(e);
36
+ });
37
+ }
38
+ connectedCallback() {
39
+ super.connectedCallback();
40
+ Utils.addClass(this, PCSS + '-contenteditable-command');
41
+ }
42
+ viewActivatedCallback() {
43
+ super.viewActivatedCallback();
44
+ const cnt = this.container;
45
+ if (!Utils.isNull(cnt)) {
46
+ this.contentElement = cnt.contentElement;
47
+ cnt.addEventListener(PropertyChangeEventName, this._containerPropChangeHandler, false);
48
+ }
49
+ }
50
+ disconnectedCallback() {
51
+ const cnt = this.container;
52
+ if (!Utils.isNull(cnt)) {
53
+ cnt.removeEventListener(PropertyChangeEventName, this._containerPropChangeHandler, false);
54
+ }
55
+ super.disconnectedCallback();
56
+ }
57
+ containerPropertyChangedCallback(name, old, val, first) {
58
+ if (name === 'range') {
59
+ this.range = val;
60
+ }
61
+ }
62
+ }
63
+ __decorate([
64
+ Watch()
65
+ ], PacemContenteditableCommandElement.prototype, "range", void 0);
66
+ __decorate([
67
+ Watch()
68
+ ], PacemContenteditableCommandElement.prototype, "contentElement", void 0);
69
+ function isFileCommand(obj) {
70
+ return obj instanceof PacemContenteditableCommandElement && 'pasteCallback' in obj && typeof obj['pasteCallback'] === 'function';
71
+ }
72
+ function isElement(node) {
73
+ return node?.nodeType == Node.ELEMENT_NODE;
74
+ }
75
+ let PacemContenteditableElement = class PacemContenteditableElement extends PacemItemsContainerBaseElement {
76
+ constructor() {
77
+ super('rich text editor');
78
+ this._focusHandler = (evt) => {
79
+ this._ensureInteractiveMarkup();
80
+ };
81
+ this._blurHandler = (evt) => {
82
+ // clean up the output
83
+ const container = this._container;
84
+ for (let command of this.items) {
85
+ command.cleanUp(container);
86
+ }
87
+ this._checkChangedHandler(evt);
88
+ };
89
+ this._pasteHandler = (evt) => {
90
+ // I'll manage it myself!
91
+ evt.preventDefault();
92
+ const range = this.range, files = evt.clipboardData.files;
93
+ if (!Utils.isNull(range) && files.length === 0) {
94
+ const text = evt.clipboardData.getData('text/plain');
95
+ const plainText = text.replace(/</gi, '&lt;').replace(/\n/gi, '<br />');
96
+ const frag = range.createContextualFragment(plainText);
97
+ range.deleteContents();
98
+ range.insertNode(frag);
99
+ this._checkChangedHandler(evt);
100
+ }
101
+ else {
102
+ for (let j = 0; j < files.length; j++) {
103
+ const f = files.item(j);
104
+ for (let cmd of this.items) {
105
+ if (isFileCommand(cmd)) {
106
+ cmd.pasteCallback(f).then(_ => this._checkChangedHandler(evt), _ => { });
107
+ }
108
+ }
109
+ }
110
+ // this._checkAndSynchronizeHandler(evt);
111
+ }
112
+ };
113
+ this._shortcutHandler = (evt) => {
114
+ // prevent any default shortcut combo apart from 'copy', 'cut' and 'paste' (mainly due to the clipboard access limitations)
115
+ if (evt.ctrlKey && ['C', 'V', 'X'].indexOf(evt.key?.toUpperCase()) === -1) {
116
+ // Let it manage it only if the relevant command is available
117
+ evt.preventDefault();
118
+ }
119
+ };
120
+ this._inputHandler = (evt) => {
121
+ this._fixRangeMarkup();
122
+ this._checkChangedHandler(evt);
123
+ };
124
+ this._checkChangedHandler = (evt) => {
125
+ const container = this._container, inputHtml = container.innerHTML;
126
+ var html = inputHtml;
127
+ if (Utils.isNullOrEmpty(inputHtml)
128
+ || inputHtml === '<br>'
129
+ || inputHtml === EMPTY_CONTENT) {
130
+ container.innerHTML = EMPTY_CONTENT;
131
+ html = '';
132
+ }
133
+ if (html != this.value) {
134
+ this.changeHandler(new ContenteditableChangeEvent(html));
135
+ if (this.value != this.#history.current) {
136
+ this._updateHistory();
137
+ }
138
+ }
139
+ // fire history change in any case
140
+ this._fireHistoryChange();
141
+ };
142
+ this._selectionChangeHandler = (evt) => {
143
+ const selection = document.getSelection();
144
+ if (selection && selection.anchorNode && this._container.contains(selection.anchorNode)) {
145
+ const range = selection.getRangeAt(0);
146
+ this.range = range.cloneRange();
147
+ }
148
+ else {
149
+ this.range = null;
150
+ }
151
+ };
152
+ //this._workspace = document.createElement('div');
153
+ }
154
+ #history;
155
+ get history() {
156
+ return this.#history;
157
+ }
158
+ reset() {
159
+ super.reset();
160
+ this.#history.reset();
161
+ this._fireHistoryChange();
162
+ }
163
+ _fireHistoryChange() {
164
+ const h = this.#history;
165
+ this.dispatchEvent(new PropertyChangeEvent({ propertyName: 'history', oldValue: h, currentValue: h }));
166
+ }
167
+ convertValueAttributeToProperty(attr) {
168
+ return attr;
169
+ }
170
+ toggleReadonlyView(readonly) {
171
+ this._dashboard.hidden = readonly;
172
+ if (readonly) {
173
+ this._container.removeAttribute('contenteditable');
174
+ }
175
+ else {
176
+ this._container.setAttribute('contenteditable', 'true');
177
+ document.execCommand("defaultParagraphSeparator", false, "p");
178
+ }
179
+ }
180
+ register(item) {
181
+ if (super.register(item)) {
182
+ item.addEventListener(EXECUTECOMMAND_NAME, this._checkChangedHandler, false);
183
+ return true;
184
+ }
185
+ return false;
186
+ }
187
+ unregister(item) {
188
+ if (super.unregister(item)) {
189
+ item.removeEventListener(EXECUTECOMMAND_NAME, this._checkChangedHandler, false);
190
+ return true;
191
+ }
192
+ return false;
193
+ }
194
+ /** @override */
195
+ get preventKeyboardSubmit() {
196
+ return true;
197
+ }
198
+ get inputFields() {
199
+ return [this._container];
200
+ }
201
+ get contentElement() {
202
+ return this._container;
203
+ }
204
+ onChange(evt) {
205
+ return new Promise((resolve, reject) => {
206
+ if (CustomEventUtils.isInstanceOf(evt, ContenteditableChangeEvent)) {
207
+ const html = this.value = evt.detail.html;
208
+ resolve(html);
209
+ // find a less-instrusive way to call this...
210
+ this._selectionChangeHandler(evt);
211
+ }
212
+ else
213
+ resolve(this.value);
214
+ });
215
+ }
216
+ _fixRangeMarkup() {
217
+ const range = this.range, fnDownwards = (node) => {
218
+ node.childNodes.forEach(i => fnDownwards(i));
219
+ if (isElement(node) && node.tagName === 'SPAN') {
220
+ Element.prototype.replaceWith.apply(node, Array.from(node.childNodes));
221
+ }
222
+ else if (node instanceof HTMLElement) {
223
+ node.removeAttribute('style');
224
+ }
225
+ }, fn = (node) => {
226
+ let element = node;
227
+ if (!isElement(element)) {
228
+ element = node.parentElement;
229
+ }
230
+ fnDownwards(element);
231
+ };
232
+ if (!Utils.isNull(range)) {
233
+ fn(range.commonAncestorContainer);
234
+ }
235
+ }
236
+ _ensureInteractiveMarkup() {
237
+ const workspace = this._container, nodes = workspace.childNodes, childCount = nodes.length;
238
+ if (childCount == 0 || workspace.innerHTML === EMPTY_CONTENT) {
239
+ workspace.innerHTML = EMPTY_CONTENT;
240
+ }
241
+ else {
242
+ let node, range;
243
+ const closeRange = (n) => {
244
+ range.setEndAfter(n);
245
+ const p = document.createElement('p');
246
+ range.surroundContents(p);
247
+ };
248
+ for (let j = 0; j < childCount; j++) {
249
+ node = nodes.item(j);
250
+ if (!(node instanceof Element)) {
251
+ if (Utils.isNull(range)) {
252
+ range = document.createRange();
253
+ range.setStartBefore(node);
254
+ }
255
+ }
256
+ else if (range) {
257
+ closeRange(node.previousSibling);
258
+ range = null;
259
+ }
260
+ }
261
+ // open range?
262
+ if (!Utils.isNull(range)) {
263
+ closeRange(node);
264
+ }
265
+ }
266
+ }
267
+ _updateHistory() {
268
+ this.#history.push(this.value);
269
+ this._fireHistoryChange();
270
+ }
271
+ acceptValue(val) {
272
+ if (!Utils.isNull(this._container) && /*the following `if` statement prevents from flashing the content and writing backwards!*/ val != this._container.innerHTML) {
273
+ this._container.innerHTML = val;
274
+ }
275
+ }
276
+ viewActivatedCallback() {
277
+ super.viewActivatedCallback();
278
+ const container = this._container;
279
+ this.#history = new HistoryService(this.value);
280
+ container.addEventListener('blur', this._blurHandler, false);
281
+ container.addEventListener('keydown', this._shortcutHandler, false);
282
+ container.addEventListener('focus', this._focusHandler, false);
283
+ container.addEventListener('input', this._inputHandler, false);
284
+ container.addEventListener('paste', this._pasteHandler, false);
285
+ document.addEventListener('selectionchange', this._selectionChangeHandler, false);
286
+ }
287
+ disconnectedCallback() {
288
+ document.removeEventListener('selectionchange', this._selectionChangeHandler, false);
289
+ const container = this._container;
290
+ if (!Utils.isNull(container)) {
291
+ container.removeEventListener('keydown', this._shortcutHandler, false);
292
+ container.removeEventListener('blur', this._blurHandler, false);
293
+ container.removeEventListener('focus', this._focusHandler, false);
294
+ container.removeEventListener('input', this._inputHandler, false);
295
+ container.removeEventListener('paste', this._pasteHandler, false);
296
+ }
297
+ super.disconnectedCallback();
298
+ }
299
+ getViewValue(val) {
300
+ return val;
301
+ }
302
+ };
303
+ __decorate([
304
+ ViewChild("div[pacem]")
305
+ ], PacemContenteditableElement.prototype, "_container", void 0);
306
+ __decorate([
307
+ ViewChild("div[dashboard]")
308
+ ], PacemContenteditableElement.prototype, "_dashboard", void 0);
309
+ __decorate([
310
+ Watch()
311
+ ], PacemContenteditableElement.prototype, "range", void 0);
312
+ __decorate([
313
+ Debounce(500)
314
+ ], PacemContenteditableElement.prototype, "_updateHistory", null);
315
+ PacemContenteditableElement = __decorate([
316
+ CustomElement({
317
+ tagName: P + '-contenteditable', shadow: Defaults.USE_SHADOW_ROOT,
318
+ template: `<div class="${PCSS}-contenteditable ${PCSS}-viewfinder">
319
+ <div contenteditable="true" role="presenter" pacem></div>
320
+ </div>${CHAR_COUNTER_CHILD}
321
+ <div dashboard>
322
+ <${P}-content></${P}-content>
323
+ </div>`
324
+ })
325
+ ], PacemContenteditableElement);
326
+ export { PacemContenteditableElement };