@pacem/pacem 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-2d.js +2755 -0
- package/dist/browser/pacem-2d.js.map +6 -0
- package/dist/browser/pacem-2d.min.js +7 -0
- package/dist/browser/pacem-2d.min.js.map +6 -0
- package/dist/browser/pacem-3d.js +7723 -0
- package/dist/browser/pacem-3d.js.map +6 -0
- package/dist/browser/pacem-3d.min.js +7 -0
- package/dist/browser/pacem-3d.min.js.map +6 -0
- package/dist/browser/pacem-charts.js +1628 -0
- package/dist/browser/pacem-charts.js.map +6 -0
- package/dist/browser/pacem-charts.min.js +7 -0
- package/dist/browser/pacem-charts.min.js.map +6 -0
- package/dist/browser/pacem-cms.js +2220 -0
- package/dist/browser/pacem-cms.js.map +6 -0
- package/dist/browser/pacem-cms.min.js +7 -0
- package/dist/browser/pacem-cms.min.js.map +6 -0
- package/dist/browser/pacem-core.js +9104 -0
- package/dist/browser/pacem-core.js.map +6 -0
- package/dist/browser/pacem-core.min.js +7 -0
- package/dist/browser/pacem-core.min.js.map +6 -0
- package/dist/browser/pacem-foundation.js +2138 -0
- package/dist/browser/pacem-foundation.js.map +6 -0
- package/dist/browser/pacem-foundation.min.js +7 -0
- package/dist/browser/pacem-foundation.min.js.map +6 -0
- package/dist/browser/pacem-fx.js +870 -0
- package/dist/browser/pacem-fx.js.map +6 -0
- package/dist/browser/pacem-fx.min.js +7 -0
- package/dist/browser/pacem-fx.min.js.map +6 -0
- package/dist/browser/pacem-logging.js +175 -0
- package/dist/browser/pacem-logging.js.map +6 -0
- package/dist/browser/pacem-logging.min.js +7 -0
- package/dist/browser/pacem-logging.min.js.map +6 -0
- package/dist/browser/pacem-maps.js +3642 -0
- package/dist/browser/pacem-maps.js.map +6 -0
- package/dist/browser/pacem-maps.min.js +7 -0
- package/dist/browser/pacem-maps.min.js.map +6 -0
- package/dist/browser/pacem-media.js +284 -0
- package/dist/browser/pacem-media.js.map +6 -0
- package/dist/browser/pacem-media.min.js +7 -0
- package/dist/browser/pacem-media.min.js.map +6 -0
- package/dist/browser/pacem-networking.js +434 -0
- package/dist/browser/pacem-networking.js.map +6 -0
- package/dist/browser/pacem-networking.min.js +7 -0
- package/dist/browser/pacem-networking.min.js.map +6 -0
- package/dist/browser/pacem-numerical.js +2627 -0
- package/dist/browser/pacem-numerical.js.map +6 -0
- package/dist/browser/pacem-numerical.min.js +7 -0
- package/dist/browser/pacem-numerical.min.js.map +6 -0
- package/dist/browser/pacem-plus.js +2373 -0
- package/dist/browser/pacem-plus.js.map +6 -0
- package/dist/browser/pacem-plus.min.js +7 -0
- package/dist/browser/pacem-plus.min.js.map +6 -0
- package/dist/browser/pacem-scaffolding.js +10435 -0
- package/dist/browser/pacem-scaffolding.js.map +6 -0
- package/dist/browser/pacem-scaffolding.min.js +7 -0
- package/dist/browser/pacem-scaffolding.min.js.map +6 -0
- package/dist/browser/pacem-ui.js +6348 -0
- package/dist/browser/pacem-ui.js.map +6 -0
- package/dist/browser/pacem-ui.min.js +7 -0
- package/dist/browser/pacem-ui.min.js.map +6 -0
- package/dist/bundle/pacem.min.mjs +997 -0
- package/dist/bundle/pacem.mjs +47067 -0
- package/dist/bundle/pacem.mjs.map +12 -0
- package/dist/typings/index.d.ts +9757 -0
- package/package.json +130 -0
|
@@ -0,0 +1,2220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pacem/pacem v1.0.0-abel (https://js.pacem.it)
|
|
3
|
+
* Copyright 2026 Pacem (https://pacem.it)
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
(function (pacemFoundation, pacemCore, pacemScaffolding, pacemUi) {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
//namespace Pacem.Components.Cms {
|
|
10
|
+
/** Function container proxy (used in metadata) */
|
|
11
|
+
const Functions = {
|
|
12
|
+
'dismiss': (...args) => {
|
|
13
|
+
for (let name of args || []) {
|
|
14
|
+
delete Functions[name];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
'handleExpressionValueChange': (evt, prop, entity) => {
|
|
18
|
+
if (evt.detail.propertyName === 'value' && !pacemCore.Utils.isNull(entity)) {
|
|
19
|
+
const value = evt.detail.currentValue;
|
|
20
|
+
if (entity instanceof HTMLElement) {
|
|
21
|
+
// handle the entity as an element and modify the attribute
|
|
22
|
+
let attr = pacemCore.CustomElementUtils.camelToKebab(prop);
|
|
23
|
+
if (pacemCore.Utils.isNullOrEmpty(value)) {
|
|
24
|
+
entity.removeAttribute(attr);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
entity.setAttribute(attr, value.toString());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
entity[prop] = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** Default metadata ('expression' field) 'type' factory. */
|
|
37
|
+
const EXPRESSION_METADATA_TYPE = (host, hostRef = ':host', hostEntityRef = ':host.entity') => {
|
|
38
|
+
const attrs = {}, meta = host.metadata, fns = Functions, fnKeys = [];
|
|
39
|
+
attrs['value'] = `{{ ${hostEntityRef} instanceof HTMLElement && ${hostEntityRef}.getAttribute('${pacemCore.CustomElementUtils.camelToKebab(meta.prop)}') }}`;
|
|
40
|
+
attrs['on-' + pacemCore.PropertyChangeEventName] = `Pacem.Components.Cms.Functions.handleExpressionValueChange($event, '${meta.prop}', ${hostEntityRef})`;
|
|
41
|
+
attrs['converter'] = `{{ Pacem.CustomElementUtils.getWatchedProperty(${hostEntityRef}, '${meta.prop}').config.converter }}`;
|
|
42
|
+
const tagName = pacemCore.P + '-expression';
|
|
43
|
+
let extra = (meta.extra || {});
|
|
44
|
+
// selector
|
|
45
|
+
if (!pacemCore.Utils.isNullOrEmpty(extra.selector)) {
|
|
46
|
+
attrs['selector'] = extra.selector;
|
|
47
|
+
}
|
|
48
|
+
// filters to the selector
|
|
49
|
+
if (!pacemCore.Utils.isNullOrEmpty(extra.filter)) {
|
|
50
|
+
switch (typeof extra.filter) {
|
|
51
|
+
case 'string':
|
|
52
|
+
attrs['filter'] = `{{ (e) => e.constructor.name === "${extra.filter}" || e.localName === "${extra.filter.toLowerCase()}" }}`;
|
|
53
|
+
break;
|
|
54
|
+
case 'function':
|
|
55
|
+
const fnKey = 'fn' + pacemCore.Utils.uniqueCode();
|
|
56
|
+
fns[fnKey] = extra.filter;
|
|
57
|
+
attrs['filter'] = `{{ Pacem.Components.Cms.Functions.${fnKey}, once }}`;
|
|
58
|
+
// tidy-up memento
|
|
59
|
+
fnKeys.push(fnKey);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// labeler
|
|
64
|
+
if (typeof extra.labeler === 'function') {
|
|
65
|
+
const fnKey = 'fn' + pacemCore.Utils.uniqueCode();
|
|
66
|
+
fns[fnKey] = extra.labeler;
|
|
67
|
+
attrs['labeler'] = `{{ Pacem.Components.Cms.Functions.${fnKey}, once }}`;
|
|
68
|
+
// tidy-up memento
|
|
69
|
+
fnKeys.push(fnKey);
|
|
70
|
+
}
|
|
71
|
+
if (fnKeys.length > 0) {
|
|
72
|
+
// tidy-up
|
|
73
|
+
attrs['on-unload'] = `{{ Pacem.Components.Cms.Functions.dismiss('${fnKeys.join('\',\'')}') }}`;
|
|
74
|
+
}
|
|
75
|
+
return { tagName: tagName, attrs: attrs };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var __decorate$e = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
79
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
80
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
81
|
+
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;
|
|
82
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
83
|
+
};
|
|
84
|
+
//namespace Pacem.Components.Cms {
|
|
85
|
+
class PacemElementPickerElementBase extends pacemScaffolding.Components.Scaffolding.PacemBaseElement {
|
|
86
|
+
}
|
|
87
|
+
__decorate$e([
|
|
88
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
89
|
+
], PacemElementPickerElementBase.prototype, "selector", void 0);
|
|
90
|
+
__decorate$e([
|
|
91
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Eval })
|
|
92
|
+
], PacemElementPickerElementBase.prototype, "filter", void 0);
|
|
93
|
+
__decorate$e([
|
|
94
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Eval })
|
|
95
|
+
], PacemElementPickerElementBase.prototype, "labeler", void 0);
|
|
96
|
+
let PacemElementPickerElement = class PacemElementPickerElement extends PacemElementPickerElementBase {
|
|
97
|
+
get inputFields() {
|
|
98
|
+
return [this._select];
|
|
99
|
+
}
|
|
100
|
+
toggleReadonlyView(readonly) {
|
|
101
|
+
this._select.readonly = readonly;
|
|
102
|
+
}
|
|
103
|
+
onChange(_) {
|
|
104
|
+
return pacemCore.Utils.fromResult(this.value = this._select.value);
|
|
105
|
+
}
|
|
106
|
+
acceptValue(val) {
|
|
107
|
+
this._select.value = val;
|
|
108
|
+
}
|
|
109
|
+
getViewValue(value) {
|
|
110
|
+
return this._select.viewValue;
|
|
111
|
+
}
|
|
112
|
+
convertValueAttributeToProperty(attr) {
|
|
113
|
+
return pacemCore.PropertyConverters.Element.convert(attr);
|
|
114
|
+
}
|
|
115
|
+
viewActivatedCallback() {
|
|
116
|
+
super.viewActivatedCallback();
|
|
117
|
+
this._databind();
|
|
118
|
+
}
|
|
119
|
+
propertyChangedCallback(name, old, val, first) {
|
|
120
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
121
|
+
if (!first) {
|
|
122
|
+
switch (name) {
|
|
123
|
+
case 'selector':
|
|
124
|
+
case 'filter':
|
|
125
|
+
case 'labeler':
|
|
126
|
+
this._databind();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
_databind() {
|
|
132
|
+
const project = this.labeler || (e => {
|
|
133
|
+
let label = e.constructor.name;
|
|
134
|
+
if (e.id) {
|
|
135
|
+
label += '#' + e.id;
|
|
136
|
+
}
|
|
137
|
+
return label;
|
|
138
|
+
});
|
|
139
|
+
const retval = [];
|
|
140
|
+
document.querySelectorAll(this.selector || '[pacem]').forEach((e, i, arr) => {
|
|
141
|
+
if ((pacemCore.Utils.isNull(this.filter) || this.filter(e) === true)
|
|
142
|
+
// let' say 'id' is a must-have...
|
|
143
|
+
&& !pacemCore.Utils.isNullOrEmpty(e.id)) {
|
|
144
|
+
retval.push({ element: e, label: project(e) });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
this._select.valueProperty = 'element';
|
|
148
|
+
this._select.textProperty = 'label';
|
|
149
|
+
this._select.datasource = retval;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
__decorate$e([
|
|
153
|
+
pacemCore.ViewChild(pacemCore.P + '-select')
|
|
154
|
+
], PacemElementPickerElement.prototype, "_select", void 0);
|
|
155
|
+
__decorate$e([
|
|
156
|
+
pacemCore.Debounce(50)
|
|
157
|
+
], PacemElementPickerElement.prototype, "_databind", null);
|
|
158
|
+
PacemElementPickerElement = __decorate$e([
|
|
159
|
+
pacemCore.CustomElement({
|
|
160
|
+
tagName: pacemCore.P + '-element-picker', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
161
|
+
template: `<${pacemCore.P}-select></${pacemCore.P}-select>`
|
|
162
|
+
})
|
|
163
|
+
], PacemElementPickerElement);
|
|
164
|
+
|
|
165
|
+
var __decorate$d = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
166
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
167
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
168
|
+
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;
|
|
169
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
170
|
+
};
|
|
171
|
+
//namespace Pacem.Components.Cms {
|
|
172
|
+
var ExpressionSource;
|
|
173
|
+
(function (ExpressionSource) {
|
|
174
|
+
ExpressionSource["Constant"] = "const";
|
|
175
|
+
ExpressionSource["PropertyReference"] = "property";
|
|
176
|
+
ExpressionSource["Expression"] = "expr";
|
|
177
|
+
})(ExpressionSource || (ExpressionSource = {}));
|
|
178
|
+
let PacemExpressionElement = class PacemExpressionElement extends PacemElementPickerElementBase {
|
|
179
|
+
propertyChangedCallback(name, old, val, first) {
|
|
180
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
181
|
+
if (name === 'converter') {
|
|
182
|
+
this._setFeedbackText(this.value);
|
|
183
|
+
}
|
|
184
|
+
else if (!first) {
|
|
185
|
+
if (this._editing) {
|
|
186
|
+
switch (name) {
|
|
187
|
+
case '_source':
|
|
188
|
+
switch (val) {
|
|
189
|
+
case ExpressionSource.PropertyReference:
|
|
190
|
+
this._picker.focus();
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
this._editor.focus();
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
case '_propRef':
|
|
198
|
+
if (!pacemCore.Utils.isNullOrEmpty(val)) {
|
|
199
|
+
this._editor.focus();
|
|
200
|
+
this._editor.value = '{{ #' + this._sourceRef.id + '.' + val + ' }}';
|
|
201
|
+
}
|
|
202
|
+
this.changeHandler(new Event('change'));
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
get inputFields() {
|
|
209
|
+
return [this._editor];
|
|
210
|
+
}
|
|
211
|
+
toggleReadonlyView(readonly) {
|
|
212
|
+
if (readonly) {
|
|
213
|
+
// ensure not editing
|
|
214
|
+
this._editing = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
setPristine() {
|
|
218
|
+
super.setPristine();
|
|
219
|
+
this._editing = false;
|
|
220
|
+
}
|
|
221
|
+
onChange(_) {
|
|
222
|
+
return pacemCore.Utils.fromResult(this.value = this._editor.value);
|
|
223
|
+
}
|
|
224
|
+
acceptValue(val) {
|
|
225
|
+
this._view.textContent = val || '...';
|
|
226
|
+
this._setFeedbackText(val);
|
|
227
|
+
this._reverseStructure();
|
|
228
|
+
if (val !== this._editor.value) {
|
|
229
|
+
this._editor.value = val;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
_setFeedbackText(val = this.value) {
|
|
233
|
+
const converter = this.converter;
|
|
234
|
+
if (pacemCore.CustomElementUtils.isBindingAttribute(val) || typeof (converter && converter.convert) !== 'function') {
|
|
235
|
+
this._eval.setAttribute('text', val);
|
|
236
|
+
}
|
|
237
|
+
else if (val === undefined) {
|
|
238
|
+
this._eval.text = '<undefined>';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
this._eval.text = converter.convert(val);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
getViewValue(value) {
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
convertValueAttributeToProperty(attr) {
|
|
248
|
+
return attr;
|
|
249
|
+
}
|
|
250
|
+
_reverseStructure() {
|
|
251
|
+
let cleanup = () => {
|
|
252
|
+
this._source = this._sourceRef = this._propRef = /*this.value =*/ undefined;
|
|
253
|
+
};
|
|
254
|
+
// dependencies?
|
|
255
|
+
let expr = this.value;
|
|
256
|
+
if (!pacemCore.Utils.isNullOrEmpty(expr)) {
|
|
257
|
+
// setup the most likely form fields
|
|
258
|
+
if (pacemCore.CustomElementUtils.isBindingAttribute(expr)) {
|
|
259
|
+
const expression = pacemCore.CustomElementUtils.parseBindingAttribute(expr, this), deps = expression.dependencies;
|
|
260
|
+
// complex or simple (one dependency) expression
|
|
261
|
+
if (pacemCore.Utils.isNullOrEmpty(deps) || deps.length > 1 || pacemCore.RepeaterItem.isRepeaterItem(deps[0].element)) {
|
|
262
|
+
this._source = ExpressionSource.Expression;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const dep = deps[0];
|
|
266
|
+
this._source = ExpressionSource.PropertyReference;
|
|
267
|
+
this._sourceRef = document.querySelector('#' + dep.element.id);
|
|
268
|
+
this._propRef = dep.path;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this._source = ExpressionSource.Constant;
|
|
273
|
+
}
|
|
274
|
+
//
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
cleanup();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
__decorate$d([
|
|
282
|
+
pacemCore.Watch({ emit: false })
|
|
283
|
+
], PacemExpressionElement.prototype, "converter", void 0);
|
|
284
|
+
__decorate$d([
|
|
285
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Boolean })
|
|
286
|
+
], PacemExpressionElement.prototype, "_editing", void 0);
|
|
287
|
+
__decorate$d([
|
|
288
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
289
|
+
], PacemExpressionElement.prototype, "_source", void 0);
|
|
290
|
+
__decorate$d([
|
|
291
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Element })
|
|
292
|
+
], PacemExpressionElement.prototype, "_sourceRef", void 0);
|
|
293
|
+
__decorate$d([
|
|
294
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
295
|
+
], PacemExpressionElement.prototype, "_propRef", void 0);
|
|
296
|
+
__decorate$d([
|
|
297
|
+
pacemCore.ViewChild(pacemCore.P + '-element-picker')
|
|
298
|
+
], PacemExpressionElement.prototype, "_picker", void 0);
|
|
299
|
+
__decorate$d([
|
|
300
|
+
pacemCore.ViewChild(pacemCore.P + '-textarea')
|
|
301
|
+
], PacemExpressionElement.prototype, "_editor", void 0);
|
|
302
|
+
__decorate$d([
|
|
303
|
+
pacemCore.ViewChild('span.' + pacemCore.PCSS + '-viewfinder')
|
|
304
|
+
], PacemExpressionElement.prototype, "_view", void 0);
|
|
305
|
+
__decorate$d([
|
|
306
|
+
pacemCore.ViewChild(pacemCore.P + '-text')
|
|
307
|
+
], PacemExpressionElement.prototype, "_eval", void 0);
|
|
308
|
+
__decorate$d([
|
|
309
|
+
pacemCore.Debounce(50)
|
|
310
|
+
], PacemExpressionElement.prototype, "_reverseStructure", null);
|
|
311
|
+
PacemExpressionElement = __decorate$d([
|
|
312
|
+
pacemCore.CustomElement({
|
|
313
|
+
tagName: pacemCore.P + '-expression', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
314
|
+
template: `<${pacemCore.P}-collapse class="${pacemCore.PCSS}-expression" collapse="{{ !:host._editing }}">
|
|
315
|
+
<div class="expression-builder ${pacemCore.PCSS}-grid grid-tiny-rowgap grid-tiny-colgap ${pacemCore.PCSS}-pad pad-bottom-2">
|
|
316
|
+
<div class="${pacemCore.PCSS}-cell">
|
|
317
|
+
<${pacemCore.P}-select value="{{ :host._source, twoway }}" class="display-block">
|
|
318
|
+
<${pacemCore.P}-data-item value="${ExpressionSource.Constant}" label="constant value"></${pacemCore.P}-data-item>
|
|
319
|
+
<${pacemCore.P}-data-item value="${ExpressionSource.PropertyReference}" label="property reference"></${pacemCore.P}-data-item>
|
|
320
|
+
<${pacemCore.P}-data-item value="${ExpressionSource.Expression}" label="complex expression"></${pacemCore.P}-data-item>
|
|
321
|
+
</${pacemCore.P}-select>
|
|
322
|
+
</div>
|
|
323
|
+
|
|
324
|
+
<${pacemCore.P}-panel class="${pacemCore.PCSS}-cell cols-hd-6" hide="{{ :host._source !== '${ExpressionSource.PropertyReference}' }}">
|
|
325
|
+
<${pacemCore.P}-element-picker value="{{ :host._sourceRef, twoway }}" selector="{{ :host.selector }}" filter="{{ :host.filter }}" labeler="{{ :host.labeler }}" class="display-block"></${pacemCore.P}-element-picker>
|
|
326
|
+
</${pacemCore.P}-panel>
|
|
327
|
+
<${pacemCore.P}-panel class="${pacemCore.PCSS}-cell cols-hd-6" hide="{{ :host._source !== '${ExpressionSource.PropertyReference}' }}">
|
|
328
|
+
<${pacemCore.P}-property-picker value="{{ :host._propRef, twoway }}" disabled="{{ !:host._sourceRef }}" target="{{ :host._sourceRef }}" on-change="::_editor.focus()" class="display-block"></${pacemCore.P}-property-picker>
|
|
329
|
+
</${pacemCore.P}-panel>
|
|
330
|
+
|
|
331
|
+
<${pacemCore.P}-panel class="${pacemCore.PCSS}-cell">
|
|
332
|
+
<${pacemCore.P}-textarea class="display-block" placeholder="{{ '{{ '+ (:host._source || '') +'... }}' }}" change-policy="${pacemScaffolding.Components.Scaffolding.ChangePolicy.Blur}"></${pacemCore.P}-textarea>
|
|
333
|
+
</${pacemCore.P}-panel>
|
|
334
|
+
</div>
|
|
335
|
+
</${pacemCore.P}-collapse>
|
|
336
|
+
<div class="${pacemCore.PCSS}-fieldset">
|
|
337
|
+
<div class="fieldset-left">
|
|
338
|
+
<div class="${pacemCore.PCSS}-fieldgroup ${pacemCore.PCSS}-viewfinder">
|
|
339
|
+
<div class="text-truncate ${pacemCore.PCSS}-pad pad-x-1"><span class="${pacemCore.PCSS}-viewfinder text-tech">{{ :host.value || '...' }}</span></div>
|
|
340
|
+
<${pacemCore.P}-panel class="fieldgroup-prepend">
|
|
341
|
+
<${pacemCore.P}-button class="flat edit ${pacemCore.PCSS}-pad pad-left-1" on-click=":host._editing = !:host._editing" hide="{{ :host.readonly }}"></${pacemCore.P}-button>
|
|
342
|
+
</${pacemCore.P}-panel>
|
|
343
|
+
<${pacemCore.P}-panel class="fieldgroup-append text-tech display-flex flex-middle flex-nowrap" hide="{{ $pacem.isNullOrEmpty(:host.value) }}">
|
|
344
|
+
<i class="${pacemCore.PCSS}-icon text-primary">keyboard_arrow_right</i>
|
|
345
|
+
<${pacemCore.P}-text text="?" class="bg-primary ${pacemCore.PCSS}-pad pad-left-1 pad-right-1 ${pacemCore.PCSS}-margin margin-right-1 text-truncate" eval></${pacemCore.P}-text>
|
|
346
|
+
</${pacemCore.P}-panel>
|
|
347
|
+
</div>
|
|
348
|
+
</div>
|
|
349
|
+
</div>`
|
|
350
|
+
})
|
|
351
|
+
], PacemExpressionElement);
|
|
352
|
+
|
|
353
|
+
var __decorate$c = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
354
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
355
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
356
|
+
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;
|
|
357
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
358
|
+
};
|
|
359
|
+
const UI = pacemUi.Components.UI;
|
|
360
|
+
//namespace Pacem.Components.Cms {
|
|
361
|
+
const DEFAULT_PERMISSION_METADATA = {
|
|
362
|
+
props: [
|
|
363
|
+
{
|
|
364
|
+
prop: 'permissions',
|
|
365
|
+
// child form-fields
|
|
366
|
+
type: 'array',
|
|
367
|
+
display: { name: 'Permissions' },
|
|
368
|
+
props: {
|
|
369
|
+
display: { cssClass: [pacemCore.PCSS + '-cell', pacemCore.PCSS + '-grid', 'grid-novgap', 'grid-tiny-colgap', 'grid-nospace'], name: 'Permission' },
|
|
370
|
+
props: Array.prototype.concat.apply([
|
|
371
|
+
{
|
|
372
|
+
prop: 'claimType', type: 'string',
|
|
373
|
+
display: { cssClass: [pacemCore.PCSS + '-cell', 'cols-hd-4', 'cols-lg-6', 'field-stretch', 'field-minimal'], name: 'Claim type' },
|
|
374
|
+
validators: [{ type: 'required', errorMessage: '!' }]
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
prop: 'claimValue', type: 'string',
|
|
378
|
+
display: { cssClass: [pacemCore.PCSS + '-cell', 'cols-hd-4', 'cols-lg-6', 'field-stretch', 'field-minimal'], name: 'Claim value' },
|
|
379
|
+
validators: [{ type: 'required', errorMessage: '!' }]
|
|
380
|
+
},
|
|
381
|
+
], ['read', 'update', 'create', 'delete'].map((p, j) => {
|
|
382
|
+
return {
|
|
383
|
+
prop: p,
|
|
384
|
+
type: 'boolean',
|
|
385
|
+
display: { cssClass: [pacemCore.PCSS + '-cell', 'cols-hd-1', 'cols-3', 'field-minimal', pacemCore.PCSS + '-pad pad-left-2'], name: p.charAt(0).toUpperCase() + p.substr(1) }
|
|
386
|
+
};
|
|
387
|
+
}))
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
]
|
|
391
|
+
};
|
|
392
|
+
const DEFAULT_METADATA = {
|
|
393
|
+
display: { name: 'Widget', cssClass: [pacemCore.PCSS + '-grid', 'grid-novgap', 'grid-tiny-colgap', 'grid-nospace'] },
|
|
394
|
+
props: [
|
|
395
|
+
{ prop: 'tag', type: 'string', display: { name: 'Tag', cssClass: [pacemCore.PCSS + '-cell'] } }
|
|
396
|
+
]
|
|
397
|
+
};
|
|
398
|
+
function cellifyMetadata(p) {
|
|
399
|
+
// ensure pacem-cell cssClass
|
|
400
|
+
p.display = p.display || { name: p.prop, cssClass: [] };
|
|
401
|
+
const css = p.display.cssClass = pacemCore.Utils.isArray(p.display.cssClass) && p.display.cssClass || [];
|
|
402
|
+
css.push(pacemCore.PCSS + '-cell');
|
|
403
|
+
}
|
|
404
|
+
function gridifyMetadata(metadata) {
|
|
405
|
+
var props = metadata && metadata.props || [];
|
|
406
|
+
var display = metadata && metadata.display || { name: 'Element' };
|
|
407
|
+
if (!pacemCore.Utils.isNull(display)) {
|
|
408
|
+
const css = display.cssClass = display.cssClass || [];
|
|
409
|
+
Array.prototype.push.apply(css, DEFAULT_METADATA.display.cssClass);
|
|
410
|
+
}
|
|
411
|
+
props.forEach(cellifyMetadata);
|
|
412
|
+
return { display: display, props: props };
|
|
413
|
+
}
|
|
414
|
+
function buildWidgetMetadata(metadata) {
|
|
415
|
+
var display = pacemCore.Utils.extend({}, DEFAULT_METADATA.display, metadata && metadata.display || {});
|
|
416
|
+
var props = pacemCore.Utils.clone(DEFAULT_METADATA.props);
|
|
417
|
+
Array.prototype.push.apply(props, (metadata && metadata.props || []).filter(p => {
|
|
418
|
+
if (p.prop === 'tag') {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
cellifyMetadata(p);
|
|
422
|
+
return true;
|
|
423
|
+
}));
|
|
424
|
+
return { display: display, props: props };
|
|
425
|
+
}
|
|
426
|
+
const WIDGET_CSS_CLASS = pacemCore.PCSS + '-widget';
|
|
427
|
+
/** Default metadata ('expression' field) 'extra' object. */
|
|
428
|
+
const EXPRESSION_WIDGET_METADATA_EXTRA = {
|
|
429
|
+
selector: '.' + WIDGET_CSS_CLASS,
|
|
430
|
+
labeler: (e) => {
|
|
431
|
+
if (!pacemCore.Utils.isNullOrEmpty(e.tag)) {
|
|
432
|
+
return e.tag;
|
|
433
|
+
}
|
|
434
|
+
return (e.metadata && e.metadata.display && e.metadata.display.name || '') + '#' + e.id;
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
class Widget {
|
|
438
|
+
/**
|
|
439
|
+
* Utility method for widget gathering.
|
|
440
|
+
* @param predicate Predicate for filtering
|
|
441
|
+
*/
|
|
442
|
+
static findAll(predicate) {
|
|
443
|
+
return pacemCore.CustomElementUtils.findAll('.' + WIDGET_CSS_CLASS, (widget) => widget instanceof PacemWidgetElement && !pacemCore.Utils.isNullOrEmpty(widget.id) && (pacemCore.Utils.isNull(predicate) || predicate(widget)));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
let PacemWidgetToolbarElement = class PacemWidgetToolbarElement extends pacemCore.Components.PacemElement {
|
|
447
|
+
/** Gets the toolbar's edit button. */
|
|
448
|
+
get editButton() {
|
|
449
|
+
return this._btnEdit;
|
|
450
|
+
}
|
|
451
|
+
/** Gets the toolbar's permimssions button. */
|
|
452
|
+
get permissionsButton() {
|
|
453
|
+
return this._btnPerms;
|
|
454
|
+
}
|
|
455
|
+
/** Gets the toolbar's remove button. */
|
|
456
|
+
get removeButton() {
|
|
457
|
+
return this._btnRemove;
|
|
458
|
+
}
|
|
459
|
+
_edit(evt) {
|
|
460
|
+
const form = this._proxy.dom.find(e => 'core' in e.attributes);
|
|
461
|
+
form.open(this.target, true);
|
|
462
|
+
form.metadata = this.target.metadata;
|
|
463
|
+
// popout
|
|
464
|
+
this._popoutJustInCase();
|
|
465
|
+
}
|
|
466
|
+
_editPermissions(evt) {
|
|
467
|
+
const form = this._proxy.dom.find(e => 'permissions' in e.attributes);
|
|
468
|
+
form.open(this.target);
|
|
469
|
+
form.metadata = this.target.permissionMetadata;
|
|
470
|
+
// popout
|
|
471
|
+
this._popoutJustInCase();
|
|
472
|
+
}
|
|
473
|
+
_popoutJustInCase() {
|
|
474
|
+
const balloon = pacemCore.CustomElementUtils.findAncestorOfType(this, UI.PacemBalloonElement);
|
|
475
|
+
if (!pacemCore.Utils.isNullOrEmpty(balloon)) {
|
|
476
|
+
balloon.popout();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
__decorate$c([
|
|
481
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Element })
|
|
482
|
+
], PacemWidgetToolbarElement.prototype, "target", void 0);
|
|
483
|
+
__decorate$c([
|
|
484
|
+
pacemCore.ViewChild('.buttons > div')
|
|
485
|
+
], PacemWidgetToolbarElement.prototype, "_toolbar", void 0);
|
|
486
|
+
__decorate$c([
|
|
487
|
+
pacemCore.ViewChild(pacemCore.P + '-button[edit]')
|
|
488
|
+
], PacemWidgetToolbarElement.prototype, "_btnEdit", void 0);
|
|
489
|
+
__decorate$c([
|
|
490
|
+
pacemCore.ViewChild(pacemCore.P + '-button[permissions]')
|
|
491
|
+
], PacemWidgetToolbarElement.prototype, "_btnPerms", void 0);
|
|
492
|
+
__decorate$c([
|
|
493
|
+
pacemCore.ViewChild(pacemCore.P + '-button[remove]')
|
|
494
|
+
], PacemWidgetToolbarElement.prototype, "_btnRemove", void 0);
|
|
495
|
+
__decorate$c([
|
|
496
|
+
pacemCore.ViewChild(pacemCore.P + '-shell-proxy')
|
|
497
|
+
], PacemWidgetToolbarElement.prototype, "_proxy", void 0);
|
|
498
|
+
PacemWidgetToolbarElement = __decorate$c([
|
|
499
|
+
pacemCore.CustomElement({
|
|
500
|
+
tagName: pacemCore.P + '-widget-toolbar', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
501
|
+
template: `<${pacemCore.P}-span class="toolbar-text" content="{{ '<i class="${pacemCore.PCSS}-icon">'+ (::target.metadata && ::target.metadata.display && ::target.metadata.display.icon || 'widgets') +'</i> '+ (::target.tag || (::target.metadata && ::target.metadata.display && ::target.metadata.display.name || ::target.localName) +'#'+ ::target.id) }}"></${pacemCore.P}-span>
|
|
502
|
+
<div class="buttons ${pacemCore.PCSS}-buttonset ${pacemCore.PCSS}-pad ${pacemCore.PCSS}-margin pad-0 margin-left-2">
|
|
503
|
+
<div class="buttonset-left">
|
|
504
|
+
<${pacemCore.P}-button edit class="button edit" on-click=":host._edit($event)"></${pacemCore.P}-button>
|
|
505
|
+
<${pacemCore.P}-button permissions class="button" on-click=":host._editPermissions($event)" css-class="{{ {'button-success': ::target.permissions.length > 0} }}" icon-glyph="verified_user"></${pacemCore.P}-button>
|
|
506
|
+
<${pacemCore.P}-button remove class="button button-danger delete"></${pacemCore.P}-button>
|
|
507
|
+
</div>
|
|
508
|
+
<div>
|
|
509
|
+
<${pacemCore.P}-shell-proxy>
|
|
510
|
+
<${pacemCore.P}-modal-form core></${pacemCore.P}-modal-form>
|
|
511
|
+
<${pacemCore.P}-modal-form permissions></${pacemCore.P}-modal-form>
|
|
512
|
+
</${pacemCore.P}-shell-proxy>`
|
|
513
|
+
})
|
|
514
|
+
], PacemWidgetToolbarElement);
|
|
515
|
+
class PacemWidgetElement extends pacemCore.Components.PacemElement {
|
|
516
|
+
constructor(metadata, role = 'widget') {
|
|
517
|
+
super(role);
|
|
518
|
+
this.permissionMetadata = DEFAULT_PERMISSION_METADATA;
|
|
519
|
+
this.metadata = metadata;
|
|
520
|
+
}
|
|
521
|
+
connectedCallback() {
|
|
522
|
+
super.connectedCallback();
|
|
523
|
+
// ensure an explicit id for each widget
|
|
524
|
+
if (pacemCore.Utils.isNullOrEmpty(this.id)) {
|
|
525
|
+
this.id = 'wdg' + pacemCore.Utils.uniqueCode();
|
|
526
|
+
}
|
|
527
|
+
pacemCore.Utils.addClass(this, WIDGET_CSS_CLASS);
|
|
528
|
+
}
|
|
529
|
+
propertyChangedCallback(name, old, val, first) {
|
|
530
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
531
|
+
switch (name) {
|
|
532
|
+
case 'editable':
|
|
533
|
+
if (!val) {
|
|
534
|
+
this._disposeBalloon();
|
|
535
|
+
}
|
|
536
|
+
else if (this.isReady) {
|
|
537
|
+
this._ensureBalloon();
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
case 'editing':
|
|
541
|
+
if (!pacemCore.Utils.isNull(this._balloon)) {
|
|
542
|
+
this._balloon.disabled = !val;
|
|
543
|
+
}
|
|
544
|
+
(val ? pacemCore.Utils.addClass : pacemCore.Utils.removeClass).apply(this, [this, 'widget-' + name]);
|
|
545
|
+
break;
|
|
546
|
+
case 'metadata':
|
|
547
|
+
this._assignIcon(val);
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
viewActivatedCallback() {
|
|
552
|
+
super.viewActivatedCallback();
|
|
553
|
+
this._assignIcon();
|
|
554
|
+
this._ensureBalloon();
|
|
555
|
+
}
|
|
556
|
+
disconnectedCallback() {
|
|
557
|
+
super.disconnectedCallback();
|
|
558
|
+
}
|
|
559
|
+
_assignIcon(val = this.metadata) {
|
|
560
|
+
this.dataset['icon'] = (val && val.display && val.display.icon) || 'widgets';
|
|
561
|
+
}
|
|
562
|
+
_ensureBalloon() {
|
|
563
|
+
if (pacemCore.Utils.isNull(this._balloon)) {
|
|
564
|
+
const balloon = this._balloon = document.createElement(pacemCore.P + '-balloon');
|
|
565
|
+
balloon.target = this;
|
|
566
|
+
balloon.disabled = !this.editing;
|
|
567
|
+
balloon.options = {
|
|
568
|
+
behavior: UI.BalloonBehavior.Menu,
|
|
569
|
+
trigger: UI.BalloonTrigger.Hover
|
|
570
|
+
};
|
|
571
|
+
// innerHTML before appending the balloon to the DOM.
|
|
572
|
+
balloon.innerHTML = `<${pacemCore.P}-widget-toolbar target="{{ #${this.id} }}"><${pacemCore.P}-widget-toolbar>`;
|
|
573
|
+
// append to trigger connected/viewActivated callbacks
|
|
574
|
+
pacemCore.CustomElementUtils.findAncestorShell(this).appendChild(balloon);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
_disposeBalloon() {
|
|
578
|
+
if (!pacemCore.Utils.isNull(this._balloon)) {
|
|
579
|
+
this._balloon.remove();
|
|
580
|
+
this._balloon = null;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
__decorate$c([
|
|
585
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Boolean })
|
|
586
|
+
], PacemWidgetElement.prototype, "editing", void 0);
|
|
587
|
+
__decorate$c([
|
|
588
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Boolean })
|
|
589
|
+
], PacemWidgetElement.prototype, "editable", void 0);
|
|
590
|
+
__decorate$c([
|
|
591
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
592
|
+
], PacemWidgetElement.prototype, "tag", void 0);
|
|
593
|
+
__decorate$c([
|
|
594
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Json })
|
|
595
|
+
], PacemWidgetElement.prototype, "permissions", void 0);
|
|
596
|
+
__decorate$c([
|
|
597
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Json })
|
|
598
|
+
], PacemWidgetElement.prototype, "metadata", void 0);
|
|
599
|
+
__decorate$c([
|
|
600
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Json })
|
|
601
|
+
], PacemWidgetElement.prototype, "permissionMetadata", void 0);
|
|
602
|
+
|
|
603
|
+
var __decorate$b = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
604
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
605
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
606
|
+
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;
|
|
607
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
608
|
+
};
|
|
609
|
+
//namespace Pacem.Components.Cms {
|
|
610
|
+
const DATA_METADATA$1 = {
|
|
611
|
+
display: { icon: 'storage', name: 'Data', description: 'Data object widget.' },
|
|
612
|
+
props: [
|
|
613
|
+
{
|
|
614
|
+
prop: 'model', type: EXPRESSION_METADATA_TYPE, display: {
|
|
615
|
+
name: 'Model'
|
|
616
|
+
}, extra: {
|
|
617
|
+
selector: '.' + pacemCore.PCSS + '-widget'
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
]
|
|
621
|
+
};
|
|
622
|
+
let PacemWidgetDataElement = class PacemWidgetDataElement extends PacemWidgetElement {
|
|
623
|
+
constructor() {
|
|
624
|
+
super(buildWidgetMetadata(DATA_METADATA$1));
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
__decorate$b([
|
|
628
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.Json })
|
|
629
|
+
], PacemWidgetDataElement.prototype, "model", void 0);
|
|
630
|
+
PacemWidgetDataElement = __decorate$b([
|
|
631
|
+
pacemCore.CustomElement({
|
|
632
|
+
tagName: pacemCore.P + '-widget-data'
|
|
633
|
+
})
|
|
634
|
+
], PacemWidgetDataElement);
|
|
635
|
+
|
|
636
|
+
var __decorate$a = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
637
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
638
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
639
|
+
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;
|
|
640
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
641
|
+
};
|
|
642
|
+
//namespace Pacem.Components.Cms {
|
|
643
|
+
const FETCH_PARAMETER_METADATA = {
|
|
644
|
+
props: [
|
|
645
|
+
{ prop: 'name', type: 'string', isReadOnly: true, display: { name: 'Name', cssClass: ['cols-md-4', 'cols-lg-3', 'cols-hd-2'] } },
|
|
646
|
+
{ prop: 'value', type: EXPRESSION_METADATA_TYPE, display: { name: 'Value', cssClass: ['cols-md-8', 'cols-lg-9', 'cols-hd-10'] } }
|
|
647
|
+
]
|
|
648
|
+
};
|
|
649
|
+
const FETCH_METADATA = {
|
|
650
|
+
display: {
|
|
651
|
+
icon: 'wifi', name: 'Api Fetcher', description: 'Fetching widget that retrieves data from a REST endpoint.'
|
|
652
|
+
}, props: [
|
|
653
|
+
{
|
|
654
|
+
prop: 'manifest', type: EXPRESSION_METADATA_TYPE, isComplexType: true, display: {
|
|
655
|
+
name: 'Api Manifest'
|
|
656
|
+
}, extra: {
|
|
657
|
+
selector: pacemCore.P + '-widget-apimanifest'
|
|
658
|
+
}, validators: [{ type: 'required', errorMessage: 'Api Manifest is a required field.' }]
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
prop: 'endpoint', type: 'object', isComplexType: true, display: {
|
|
662
|
+
name: 'Endpoint', ui: 'oneToMany'
|
|
663
|
+
}, validators: [{ type: 'required', errorMessage: 'Api Manifest is a required field.' }],
|
|
664
|
+
extra: {
|
|
665
|
+
source: (manifest) => manifest.endpoints.map(e => pacemCore.Utils.extend(e, { 'fullPath': `[${e.method.toUpperCase()}] ${e.path}` })).sort(),
|
|
666
|
+
textProperty: 'fullPath', valueProperty: 'fullPath',
|
|
667
|
+
dependsOn: [{ prop: 'manifest', hide: true }]
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
{
|
|
671
|
+
prop: 'parameters', type: 'array', display: {
|
|
672
|
+
name: 'Parameters'
|
|
673
|
+
},
|
|
674
|
+
props: gridifyMetadata(FETCH_PARAMETER_METADATA),
|
|
675
|
+
extra: {
|
|
676
|
+
lockItems: true,
|
|
677
|
+
dependsOn: [{ prop: 'endpoint', hide: true }]
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
ACCESS_TOKEN_METADATA
|
|
681
|
+
]
|
|
682
|
+
};
|
|
683
|
+
const PARAMETER_TAGNAME = pacemCore.P + '-widget-fetch-parameter';
|
|
684
|
+
let PacemWidgetFetchParameterElement = class PacemWidgetFetchParameterElement extends pacemCore.PacemEventTarget {
|
|
685
|
+
propertyChangedCallback(name, old, val, first) {
|
|
686
|
+
super.propertyChangedCallback(name, old, val.first);
|
|
687
|
+
if (name === 'value' && !pacemCore.Utils.isNull(this._fetcher)) {
|
|
688
|
+
this._fetcher.fetch();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
viewActivatedCallback() {
|
|
692
|
+
super.viewActivatedCallback();
|
|
693
|
+
this._fetcher = pacemCore.CustomElementUtils.findAncestorOfType(this, PacemWidgetFetchElement);
|
|
694
|
+
if (!pacemCore.Utils.isNull(this._fetcher) && !pacemCore.Utils.isNull(this.value)) {
|
|
695
|
+
this._fetcher.fetch();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
__decorate$a([
|
|
700
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.Boolean })
|
|
701
|
+
], PacemWidgetFetchParameterElement.prototype, "required", void 0);
|
|
702
|
+
__decorate$a([
|
|
703
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
704
|
+
], PacemWidgetFetchParameterElement.prototype, "name", void 0);
|
|
705
|
+
__decorate$a([
|
|
706
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
707
|
+
], PacemWidgetFetchParameterElement.prototype, "value", void 0);
|
|
708
|
+
PacemWidgetFetchParameterElement = __decorate$a([
|
|
709
|
+
pacemCore.CustomElement({ tagName: PARAMETER_TAGNAME })
|
|
710
|
+
], PacemWidgetFetchParameterElement);
|
|
711
|
+
let PacemWidgetFetchElement = class PacemWidgetFetchElement extends PacemBearerWidgetElement {
|
|
712
|
+
constructor() {
|
|
713
|
+
super(buildWidgetMetadata(FETCH_METADATA));
|
|
714
|
+
this._onerror = (e) => {
|
|
715
|
+
this.failure = !(this.success = false);
|
|
716
|
+
};
|
|
717
|
+
this._onsuccess = (e) => {
|
|
718
|
+
this.failure = !(this.success = true);
|
|
719
|
+
};
|
|
720
|
+
this._onresult = (e) => {
|
|
721
|
+
this.result = e.detail;
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
get _parameters() {
|
|
725
|
+
return Array.from(this._itemsElement.children).filter(e => e.localName === PARAMETER_TAGNAME);
|
|
726
|
+
}
|
|
727
|
+
fetch() {
|
|
728
|
+
const fetcher = this._fetcher, parameters = this._parameters || [], endpoint = this.endpoint;
|
|
729
|
+
if (!pacemCore.Utils.isNull(endpoint)) {
|
|
730
|
+
for (let param of endpoint.parameters) {
|
|
731
|
+
if (param.required && pacemCore.Utils.isNull(parameters.find(p => p.name === param.name))) {
|
|
732
|
+
// parameters not yet aligned with the ref endpoint:
|
|
733
|
+
// not all the required parameters are attached => exit
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
// build-up fetch params
|
|
739
|
+
const params = {};
|
|
740
|
+
for (let parameter of parameters) {
|
|
741
|
+
if (!pacemCore.Utils.isNullOrEmpty(parameter.value)) {
|
|
742
|
+
params[parameter.name] = parameter.value;
|
|
743
|
+
}
|
|
744
|
+
else if (parameter.required) {
|
|
745
|
+
// found an empty (required) parameter => exit
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
fetcher.url = this.url;
|
|
750
|
+
fetcher.method = this.method;
|
|
751
|
+
fetcher.credentials = this.fetchCredentials;
|
|
752
|
+
fetcher.headers = this.fetchHeaders;
|
|
753
|
+
fetcher.parameters = params;
|
|
754
|
+
return fetcher.fetch();
|
|
755
|
+
}
|
|
756
|
+
viewActivatedCallback() {
|
|
757
|
+
super.viewActivatedCallback();
|
|
758
|
+
this.fetch();
|
|
759
|
+
}
|
|
760
|
+
propertyChangedCallback(name, old, val, first) {
|
|
761
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
762
|
+
if (name === 'endpoint' && !pacemCore.Utils.isNullOrEmpty(val)) {
|
|
763
|
+
this._mergeEndpoint(val);
|
|
764
|
+
}
|
|
765
|
+
else
|
|
766
|
+
switch (name) {
|
|
767
|
+
case 'parameters':
|
|
768
|
+
case 'fetchHeaders':
|
|
769
|
+
case 'fetchCredentials':
|
|
770
|
+
case 'url':
|
|
771
|
+
case 'method':
|
|
772
|
+
this.fetch();
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
_mergeEndpoint(endpoint = this.endpoint) {
|
|
777
|
+
this.url = this.manifest.baseUrl + endpoint.path;
|
|
778
|
+
this.method = endpoint.method;
|
|
779
|
+
this.fields = endpoint.response.fields;
|
|
780
|
+
const itemsElement = this._itemsElement, parameters = this._parameters;
|
|
781
|
+
// remove exceeding
|
|
782
|
+
for (let j = parameters.length - 1; j >= 0; j--) {
|
|
783
|
+
let item = parameters[j];
|
|
784
|
+
let matching = endpoint.parameters.find(p => p.name === item.name);
|
|
785
|
+
if (pacemCore.Utils.isNull(matching)) {
|
|
786
|
+
item.remove();
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
// add missing
|
|
790
|
+
for (let param of endpoint.parameters) {
|
|
791
|
+
let existing = parameters.find(p => p.name === param.name);
|
|
792
|
+
if (pacemCore.Utils.isNull(existing)) {
|
|
793
|
+
let item = existing = document.createElement(PARAMETER_TAGNAME);
|
|
794
|
+
item.name = param.name;
|
|
795
|
+
itemsElement.appendChild(item);
|
|
796
|
+
}
|
|
797
|
+
existing.required = param.required;
|
|
798
|
+
}
|
|
799
|
+
// for editing sake
|
|
800
|
+
this.parameters = parameters;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
__decorate$a([
|
|
804
|
+
pacemCore.Watch({ reflectBack: true, emit: true /* < due to metadata 'dependsOn' */, converter: pacemCore.PropertyConverters.Json })
|
|
805
|
+
], PacemWidgetFetchElement.prototype, "manifest", void 0);
|
|
806
|
+
__decorate$a([
|
|
807
|
+
pacemCore.Watch({ reflectBack: true, emit: true /* < due to metadata 'dependsOn' */, converter: pacemCore.PropertyConverters.Json })
|
|
808
|
+
], PacemWidgetFetchElement.prototype, "endpoint", void 0);
|
|
809
|
+
__decorate$a([
|
|
810
|
+
pacemCore.Watch({ reflectBack: true, emit: false, converter: pacemCore.PropertyConverters.String })
|
|
811
|
+
], PacemWidgetFetchElement.prototype, "url", void 0);
|
|
812
|
+
__decorate$a([
|
|
813
|
+
pacemCore.Watch({ reflectBack: true, emit: false, converter: pacemCore.PropertyConverters.String })
|
|
814
|
+
], PacemWidgetFetchElement.prototype, "method", void 0);
|
|
815
|
+
__decorate$a([
|
|
816
|
+
pacemCore.Watch({ reflectBack: true, emit: false, converter: pacemCore.PropertyConverters.Json })
|
|
817
|
+
], PacemWidgetFetchElement.prototype, "fields", void 0);
|
|
818
|
+
__decorate$a([
|
|
819
|
+
pacemCore.Watch( /* just for editing sake */)
|
|
820
|
+
], PacemWidgetFetchElement.prototype, "parameters", void 0);
|
|
821
|
+
__decorate$a([
|
|
822
|
+
pacemCore.Watch( /* can only be databound or assigned at runtime */)
|
|
823
|
+
], PacemWidgetFetchElement.prototype, "result", void 0);
|
|
824
|
+
__decorate$a([
|
|
825
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Boolean })
|
|
826
|
+
], PacemWidgetFetchElement.prototype, "fetching", void 0);
|
|
827
|
+
__decorate$a([
|
|
828
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Boolean })
|
|
829
|
+
], PacemWidgetFetchElement.prototype, "success", void 0);
|
|
830
|
+
__decorate$a([
|
|
831
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Boolean })
|
|
832
|
+
], PacemWidgetFetchElement.prototype, "failure", void 0);
|
|
833
|
+
__decorate$a([
|
|
834
|
+
pacemCore.ViewChild(pacemCore.P + '-fetch')
|
|
835
|
+
], PacemWidgetFetchElement.prototype, "_fetcher", void 0);
|
|
836
|
+
__decorate$a([
|
|
837
|
+
pacemCore.ViewChild('div[hidden]')
|
|
838
|
+
], PacemWidgetFetchElement.prototype, "_itemsElement", void 0);
|
|
839
|
+
PacemWidgetFetchElement = __decorate$a([
|
|
840
|
+
pacemCore.CustomElement({
|
|
841
|
+
tagName: pacemCore.P + '-widget-fetch', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
842
|
+
template: `<${pacemCore.P}-fetch autofetch="false" fetching="{{ :host.fetching, twoway }}" debounce="100"
|
|
843
|
+
on-${pacemCore.Net.FetchResultEventName}=":host._onresult($event)" on-${pacemCore.Net.FetchErrorEventName}=":host._onerror($event)" on-${pacemCore.Net.FetchSuccessEventName}=":host._onsuccess($event)"></${pacemCore.P}-fetch><div hidden><${pacemCore.P}-content></${pacemCore.P}-content></div>`
|
|
844
|
+
})
|
|
845
|
+
], PacemWidgetFetchElement);
|
|
846
|
+
|
|
847
|
+
var __decorate$9 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
848
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
849
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
850
|
+
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;
|
|
851
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
852
|
+
};
|
|
853
|
+
//namespace Pacem.Components.Cms {
|
|
854
|
+
const FETCH_CREDENTIALS_METADATA = {
|
|
855
|
+
prop: 'fetchCredentials', type: 'string', dataType: 'enumeration', display: { name: 'Fetch Credentials' }, extra: {
|
|
856
|
+
enum: ['same-origin', 'omit', 'include']
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
const ACCESS_TOKEN_METADATA = {
|
|
860
|
+
prop: 'accessToken', type: EXPRESSION_METADATA_TYPE, display: { name: 'Access Token' },
|
|
861
|
+
extra: pacemCore.Utils.extend({}, EXPRESSION_WIDGET_METADATA_EXTRA, { filter: (e) => e instanceof PacemWidgetDataElement || e instanceof PacemWidgetFetchElement })
|
|
862
|
+
};
|
|
863
|
+
class PacemBearerWidgetElement extends PacemWidgetElement {
|
|
864
|
+
constructor() {
|
|
865
|
+
super(...arguments);
|
|
866
|
+
this.fetchCredentials = 'same-origin';
|
|
867
|
+
}
|
|
868
|
+
propertyChangedCallback(name, old, val, first) {
|
|
869
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
870
|
+
if (name === 'accessToken') {
|
|
871
|
+
if (!pacemCore.Utils.isNullOrEmpty(val)) {
|
|
872
|
+
this.fetchHeaders = { 'Authorization': 'Bearer ' + val };
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
this.fetchHeaders = {};
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
__decorate$9([
|
|
881
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
882
|
+
], PacemBearerWidgetElement.prototype, "fetchCredentials", void 0);
|
|
883
|
+
__decorate$9([
|
|
884
|
+
pacemCore.Watch({ emit: false, converter: pacemCore.PropertyConverters.Json })
|
|
885
|
+
], PacemBearerWidgetElement.prototype, "fetchHeaders", void 0);
|
|
886
|
+
__decorate$9([
|
|
887
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
888
|
+
], PacemBearerWidgetElement.prototype, "accessToken", void 0);
|
|
889
|
+
__decorate$9([
|
|
890
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Boolean })
|
|
891
|
+
], PacemBearerWidgetElement.prototype, "fetching", void 0);
|
|
892
|
+
|
|
893
|
+
var __decorate$8 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
894
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
895
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
896
|
+
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;
|
|
897
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
898
|
+
};
|
|
899
|
+
//namespace Pacem.Components.Cms {
|
|
900
|
+
let PacemWidgetTranslatorElement = class PacemWidgetTranslatorElement extends PacemWidgetElement {
|
|
901
|
+
};
|
|
902
|
+
PacemWidgetTranslatorElement = __decorate$8([
|
|
903
|
+
pacemCore.CustomElement({
|
|
904
|
+
tagName: pacemCore.P + '-widget-translator'
|
|
905
|
+
})
|
|
906
|
+
], PacemWidgetTranslatorElement);
|
|
907
|
+
|
|
908
|
+
var __decorate$7 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
909
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
910
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
911
|
+
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;
|
|
912
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
913
|
+
};
|
|
914
|
+
//namespace Pacem.Components.Cms {
|
|
915
|
+
const DATA_METADATA = {
|
|
916
|
+
display: { icon: 'timer', name: 'Clock', description: 'Timer widget.' },
|
|
917
|
+
props: [
|
|
918
|
+
{
|
|
919
|
+
prop: 'interval', type: EXPRESSION_METADATA_TYPE, display: {
|
|
920
|
+
name: 'Interval (msec)'
|
|
921
|
+
}, extra: {
|
|
922
|
+
selector: '.' + pacemCore.PCSS + '-widget', step: 1000
|
|
923
|
+
},
|
|
924
|
+
validators: [{
|
|
925
|
+
type: 'range', errorMessage: 'Negative numbers not allowed', params: { min: 0 }
|
|
926
|
+
}]
|
|
927
|
+
}
|
|
928
|
+
]
|
|
929
|
+
};
|
|
930
|
+
let PacemWidgetClockElement = class PacemWidgetClockElement extends PacemWidgetElement {
|
|
931
|
+
constructor() {
|
|
932
|
+
super(buildWidgetMetadata(DATA_METADATA));
|
|
933
|
+
this.interval = 0;
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
__decorate$7([
|
|
937
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
938
|
+
], PacemWidgetClockElement.prototype, "interval", void 0);
|
|
939
|
+
__decorate$7([
|
|
940
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Number })
|
|
941
|
+
], PacemWidgetClockElement.prototype, "time", void 0);
|
|
942
|
+
PacemWidgetClockElement = __decorate$7([
|
|
943
|
+
pacemCore.CustomElement({
|
|
944
|
+
tagName: pacemCore.P + '-widget-clock', template: `<${pacemCore.P}-timer interval="{{ :host.interval }}" on-tick="{{ :host.time = Date.now() }}"></${pacemCore.P}-timer>`
|
|
945
|
+
})
|
|
946
|
+
], PacemWidgetClockElement);
|
|
947
|
+
|
|
948
|
+
/// <reference path="./swagger-types.d.ts" />
|
|
949
|
+
//namespace Pacem.Cms.OpenApi {
|
|
950
|
+
const BAG = 'pacem:metadatabag';
|
|
951
|
+
class SwaggerCmsParser {
|
|
952
|
+
constructor(_openApi = new pacemScaffolding.Scaffolding.OpenApi.OpenApiParser()) {
|
|
953
|
+
this._openApi = _openApi;
|
|
954
|
+
this._cachedMetadataUrls = [];
|
|
955
|
+
}
|
|
956
|
+
async load(url, headers) {
|
|
957
|
+
let api = await this._openApi.load(url, headers);
|
|
958
|
+
if (api != null) {
|
|
959
|
+
api[BAG] = {};
|
|
960
|
+
// greedy load of datafields
|
|
961
|
+
for (let endpoint of api.endpoints) {
|
|
962
|
+
await this._enrichSchemas(api, endpoint, headers);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return api;
|
|
966
|
+
}
|
|
967
|
+
async _enrichSchemas(api, endpoint, headers) {
|
|
968
|
+
const response = endpoint.response;
|
|
969
|
+
if (response && response.meta) {
|
|
970
|
+
response.fields = await this._fetchMetadata(api, { name: response.fullType, schema: response.meta }, headers);
|
|
971
|
+
}
|
|
972
|
+
// parameters?
|
|
973
|
+
const parameters = endpoint.parameters;
|
|
974
|
+
for (let parameter of (parameters || [])) {
|
|
975
|
+
if (parameter.meta && parameter.fullType) {
|
|
976
|
+
let fields = await this._fetchMetadata(api, { name: parameter.fullType, schema: parameter.meta }, headers);
|
|
977
|
+
parameter.fields = fields;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
clearCache() {
|
|
982
|
+
const cache = this.cache, keys = this._cachedMetadataUrls;
|
|
983
|
+
if (cache) {
|
|
984
|
+
for (let key of keys) {
|
|
985
|
+
cache.removeProperty(key);
|
|
986
|
+
}
|
|
987
|
+
// clear keys
|
|
988
|
+
keys.splice(0);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
*
|
|
993
|
+
* @param def1
|
|
994
|
+
* @param headers HTTP headers for API fetching
|
|
995
|
+
*/
|
|
996
|
+
async _fetchMetadata(api, def0, headers) {
|
|
997
|
+
let _fetch = async (def1) => {
|
|
998
|
+
let cols = [];
|
|
999
|
+
if (def1 && def1.name) {
|
|
1000
|
+
// short-circuit if already in the bag
|
|
1001
|
+
if (api[BAG][def1.name]) {
|
|
1002
|
+
return api[BAG][def1.name];
|
|
1003
|
+
}
|
|
1004
|
+
/* reserve a place for this type so that it gets not fetched again if aggressive recursion occurs */ api[BAG][def1.name] = cols;
|
|
1005
|
+
let meta = { props: [] }, metadataUrl;
|
|
1006
|
+
if (/^https?:\/\//.test(def1.name)) {
|
|
1007
|
+
// name is url? then it's the endpoint for type metadata, fetch it!
|
|
1008
|
+
metadataUrl = def1.name;
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
console.warn(`Swagger entity definition keys must appear in form of absolute url. Their response to a GET request needs to be the entity metadata itself.\nNo other options are currently supported.`);
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (metadataUrl) {
|
|
1015
|
+
let retrieveFn = async () => {
|
|
1016
|
+
let response = await fetch(metadataUrl, { credentials: 'omit', mode: 'cors', headers: headers });
|
|
1017
|
+
if (response.ok) {
|
|
1018
|
+
return await response.json();
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
if (this.cache) {
|
|
1022
|
+
// check for session cache
|
|
1023
|
+
meta = this.cache.getPropertyValue(metadataUrl);
|
|
1024
|
+
if (!meta) {
|
|
1025
|
+
// no cache available? then fetch...
|
|
1026
|
+
meta = await retrieveFn();
|
|
1027
|
+
this._cachedMetadataUrls.push(metadataUrl);
|
|
1028
|
+
this.cache.setPropertyValue(metadataUrl, meta, /* persist in session not on location */ false);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
// do fetch
|
|
1033
|
+
meta = await retrieveFn();
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
let schema = def1.schema;
|
|
1037
|
+
for (let col in schema.properties) {
|
|
1038
|
+
let column = schema.properties[col], field = meta && meta.props.find(p => p.prop === col);
|
|
1039
|
+
let datafield = Object.assign({
|
|
1040
|
+
prop: col, type: column.type || 'text', props: undefined
|
|
1041
|
+
}, field || /* if there's no match, then read-only */ { isReadOnly: true });
|
|
1042
|
+
if (field) {
|
|
1043
|
+
let $ref = (column.items && column.items.$ref) || column.$ref;
|
|
1044
|
+
if ($ref) {
|
|
1045
|
+
let ref = pacemScaffolding.Scaffolding.OpenApi.getOpenApiDefinition(api, $ref), key = ref.name;
|
|
1046
|
+
if (api[BAG][key]) {
|
|
1047
|
+
datafield.props = api[BAG][key];
|
|
1048
|
+
}
|
|
1049
|
+
else {
|
|
1050
|
+
// recursion here
|
|
1051
|
+
datafield.props = await _fetch(ref);
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
cols.push(datafield);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return cols;
|
|
1059
|
+
};
|
|
1060
|
+
return await _fetch(def0);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
var swaggerCms = /*#__PURE__*/Object.freeze({
|
|
1065
|
+
__proto__: null,
|
|
1066
|
+
SwaggerCmsParser: SwaggerCmsParser
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
var __decorate$6 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1070
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1071
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1072
|
+
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;
|
|
1073
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1074
|
+
};
|
|
1075
|
+
//namespace Pacem.Components.Cms {
|
|
1076
|
+
const APIMANIFEST_METADATA = {
|
|
1077
|
+
display: { icon: 'cloud_circle', name: 'Api Manifest', description: 'OpenApi parser for WebApi scaffolding.' },
|
|
1078
|
+
props: [
|
|
1079
|
+
{
|
|
1080
|
+
prop: 'url', type: 'text', display: {
|
|
1081
|
+
name: 'Url', description: 'Insert the url of the OpenApi json configuration.', cssClass: ['cols-lg-8'],
|
|
1082
|
+
watermark: 'https://domain.com/swagger/v1/swagger.json'
|
|
1083
|
+
},
|
|
1084
|
+
extra: { tooltip: true },
|
|
1085
|
+
validators: [{
|
|
1086
|
+
type: 'required', errorMessage: 'Url field is required.'
|
|
1087
|
+
}]
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
prop: 'usecache', type: 'boolean', display: {
|
|
1091
|
+
name: 'Cache results', description: 'Whether to cache the manifest per-url.', cssClass: ['cols-lg-4'],
|
|
1092
|
+
ui: 'switcher'
|
|
1093
|
+
},
|
|
1094
|
+
extra: { tooltip: true }
|
|
1095
|
+
},
|
|
1096
|
+
ACCESS_TOKEN_METADATA
|
|
1097
|
+
]
|
|
1098
|
+
};
|
|
1099
|
+
let PacemWidgetApiManifestElement = class PacemWidgetApiManifestElement extends PacemBearerWidgetElement {
|
|
1100
|
+
constructor(_openapi = new SwaggerCmsParser(), _cache = new pacemCore.Storage()) {
|
|
1101
|
+
super(buildWidgetMetadata(APIMANIFEST_METADATA));
|
|
1102
|
+
this._openapi = _openapi;
|
|
1103
|
+
this._cache = _cache;
|
|
1104
|
+
}
|
|
1105
|
+
propertyChangedCallback(name, old, val, first) {
|
|
1106
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
1107
|
+
switch (name) {
|
|
1108
|
+
case 'url':
|
|
1109
|
+
case 'editing':
|
|
1110
|
+
case 'editable':
|
|
1111
|
+
this._scaffold();
|
|
1112
|
+
break;
|
|
1113
|
+
case 'usecache':
|
|
1114
|
+
this._openapi.cache = val ? this._cache : null;
|
|
1115
|
+
break;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
viewActivatedCallback() {
|
|
1119
|
+
super.viewActivatedCallback();
|
|
1120
|
+
if (this.usecache) {
|
|
1121
|
+
this._openapi.cache = this._cache;
|
|
1122
|
+
}
|
|
1123
|
+
this._scaffold();
|
|
1124
|
+
}
|
|
1125
|
+
_scaffold() {
|
|
1126
|
+
if (this.editing && this.editable && !pacemCore.Utils.isNullOrEmpty(this.url)) {
|
|
1127
|
+
this.fetching = true;
|
|
1128
|
+
this._openapi.load(this.url).then(s => {
|
|
1129
|
+
this.manifest = s;
|
|
1130
|
+
this.fetching = false;
|
|
1131
|
+
}, _ => {
|
|
1132
|
+
this.fetching = false;
|
|
1133
|
+
});
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
__decorate$6([
|
|
1138
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
1139
|
+
], PacemWidgetApiManifestElement.prototype, "url", void 0);
|
|
1140
|
+
__decorate$6([
|
|
1141
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Boolean })
|
|
1142
|
+
], PacemWidgetApiManifestElement.prototype, "usecache", void 0);
|
|
1143
|
+
__decorate$6([
|
|
1144
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Json })
|
|
1145
|
+
], PacemWidgetApiManifestElement.prototype, "manifest", void 0);
|
|
1146
|
+
PacemWidgetApiManifestElement = __decorate$6([
|
|
1147
|
+
pacemCore.CustomElement({ tagName: pacemCore.P + '-widget-apimanifest' })
|
|
1148
|
+
], PacemWidgetApiManifestElement);
|
|
1149
|
+
|
|
1150
|
+
var __decorate$5 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1151
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1152
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1153
|
+
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;
|
|
1154
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1155
|
+
};
|
|
1156
|
+
//namespace Pacem.Components.Cms {
|
|
1157
|
+
class PacemUiWidgetElement extends PacemWidgetElement {
|
|
1158
|
+
constructor(metadata, colspan = 1, role) {
|
|
1159
|
+
super(metadata, role);
|
|
1160
|
+
this.colspan = colspan;
|
|
1161
|
+
this.rowspan = 1;
|
|
1162
|
+
}
|
|
1163
|
+
// just a flag class
|
|
1164
|
+
connectedCallback() {
|
|
1165
|
+
super.connectedCallback();
|
|
1166
|
+
pacemCore.Utils.addClass(this, 'ui-widget ' + pacemCore.PCSS + '-cell cols-xs-start-1 cols-xs-12 rows-xs-start-auto');
|
|
1167
|
+
}
|
|
1168
|
+
propertyChangedCallback(name, old, val, first) {
|
|
1169
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
1170
|
+
switch (name) {
|
|
1171
|
+
case 'row':
|
|
1172
|
+
pacemCore.Utils.removeClass(this, `rows-start-${old + 1}`);
|
|
1173
|
+
pacemCore.Utils.addClass(this, `rows-start-${val + 1}`);
|
|
1174
|
+
break;
|
|
1175
|
+
case 'rowspan':
|
|
1176
|
+
pacemCore.Utils.removeClass(this, `rows-${old}`);
|
|
1177
|
+
pacemCore.Utils.addClass(this, `rows-${val}`);
|
|
1178
|
+
break;
|
|
1179
|
+
case 'column':
|
|
1180
|
+
pacemCore.Utils.removeClass(this, `cols-start-${old + 1}`);
|
|
1181
|
+
pacemCore.Utils.addClass(this, `cols-start-${val + 1}`);
|
|
1182
|
+
break;
|
|
1183
|
+
case 'colspan':
|
|
1184
|
+
pacemCore.Utils.removeClass(this, `cols-${old}`);
|
|
1185
|
+
pacemCore.Utils.addClass(this, `cols-${val}`);
|
|
1186
|
+
break;
|
|
1187
|
+
case 'borders':
|
|
1188
|
+
(this.borders ? pacemCore.Utils.addClass : pacemCore.Utils.removeClass).apply(this, [this, pacemCore.PCSS + '-border']);
|
|
1189
|
+
break;
|
|
1190
|
+
case 'corners':
|
|
1191
|
+
(this.borders ? pacemCore.Utils.addClass : pacemCore.Utils.removeClass).apply(this, [this, pacemCore.PCSS + '-corners']);
|
|
1192
|
+
break;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
get container() {
|
|
1196
|
+
return this._container;
|
|
1197
|
+
}
|
|
1198
|
+
/** @overridable */
|
|
1199
|
+
findContainer() {
|
|
1200
|
+
return pacemCore.CustomElementUtils.findAncestor(this, n => n instanceof PacemCompositeWidgetElement);
|
|
1201
|
+
}
|
|
1202
|
+
viewActivatedCallback() {
|
|
1203
|
+
super.viewActivatedCallback();
|
|
1204
|
+
let iter = this._container = this.findContainer();
|
|
1205
|
+
if (!pacemCore.Utils.isNull(iter)) {
|
|
1206
|
+
iter.register(this);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
disconnectedCallback() {
|
|
1210
|
+
if (!pacemCore.Utils.isNull(this._container)) {
|
|
1211
|
+
this._container.unregister(this);
|
|
1212
|
+
}
|
|
1213
|
+
super.disconnectedCallback();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
__decorate$5([
|
|
1217
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1218
|
+
], PacemUiWidgetElement.prototype, "column", void 0);
|
|
1219
|
+
__decorate$5([
|
|
1220
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1221
|
+
], PacemUiWidgetElement.prototype, "row", void 0);
|
|
1222
|
+
__decorate$5([
|
|
1223
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1224
|
+
], PacemUiWidgetElement.prototype, "colspan", void 0);
|
|
1225
|
+
__decorate$5([
|
|
1226
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1227
|
+
], PacemUiWidgetElement.prototype, "rowspan", void 0);
|
|
1228
|
+
__decorate$5([
|
|
1229
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Boolean })
|
|
1230
|
+
], PacemUiWidgetElement.prototype, "borders", void 0);
|
|
1231
|
+
__decorate$5([
|
|
1232
|
+
pacemCore.Watch({ emit: true, reflectBack: true, converter: pacemCore.PropertyConverters.Boolean })
|
|
1233
|
+
], PacemUiWidgetElement.prototype, "corners", void 0);
|
|
1234
|
+
const WidgetRegisterEventName = "widgetregister";
|
|
1235
|
+
const WidgetUnregisterEventName = "widgetunregister";
|
|
1236
|
+
const LayoutChangeEventName = "layoutchange";
|
|
1237
|
+
class WidgetRegisterEvent extends CustomEvent {
|
|
1238
|
+
constructor(item, eventInit) {
|
|
1239
|
+
super(WidgetRegisterEventName, pacemCore.Utils.extend(eventInit || {}, { detail: item }));
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
class WidgetUnregisterEvent extends CustomEvent {
|
|
1243
|
+
constructor(item, eventInit) {
|
|
1244
|
+
super(WidgetUnregisterEventName, pacemCore.Utils.extend(eventInit || {}, { detail: item }));
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
class PacemCompositeWidgetElement extends PacemUiWidgetElement {
|
|
1248
|
+
get itemsElement() {
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
validate(item) {
|
|
1252
|
+
return item instanceof PacemUiWidgetElement;
|
|
1253
|
+
}
|
|
1254
|
+
viewActivatedCallback() {
|
|
1255
|
+
super.viewActivatedCallback();
|
|
1256
|
+
pacemCore.Utils.addClass(this.itemsElement, pacemCore.PCSS + '-items-element');
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Appends a child Element to this CompositeWidget's itemsElement.
|
|
1260
|
+
* @param item New child element
|
|
1261
|
+
*/
|
|
1262
|
+
appendItem(item) {
|
|
1263
|
+
this.itemsElement.appendChild(item);
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Registers a new item among the items.
|
|
1267
|
+
* @param item {PacemUiWidgetElement} Item to be enrolled
|
|
1268
|
+
*/
|
|
1269
|
+
register(item) {
|
|
1270
|
+
if (!this.validate(item)) {
|
|
1271
|
+
this.log(pacemCore.Logging.LogLevel.Debug, `${(item && item.localName)} element couldn't be registered in a ${this.localName} element.`);
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
let retval = false;
|
|
1275
|
+
const items = this.items = this.items || [];
|
|
1276
|
+
if (pacemCore.Utils.isNullOrEmpty(items)) {
|
|
1277
|
+
this.items = [item];
|
|
1278
|
+
retval = true;
|
|
1279
|
+
}
|
|
1280
|
+
else if (items.indexOf(item) === -1) {
|
|
1281
|
+
items.push(item);
|
|
1282
|
+
retval = true;
|
|
1283
|
+
}
|
|
1284
|
+
//
|
|
1285
|
+
if (retval) {
|
|
1286
|
+
this.dispatchEvent(new WidgetRegisterEvent(item));
|
|
1287
|
+
}
|
|
1288
|
+
return retval;
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Removes an existing element from the items.
|
|
1292
|
+
* @param item {PacemUiWidgetElement} Item to be removed
|
|
1293
|
+
*/
|
|
1294
|
+
unregister(item) {
|
|
1295
|
+
const items = this.items, ndx = !pacemCore.Utils.isNullOrEmpty(items) && items.indexOf(item);
|
|
1296
|
+
if (ndx >= 0) {
|
|
1297
|
+
let item = items.splice(ndx, 1);
|
|
1298
|
+
this.dispatchEvent(new WidgetUnregisterEvent(item[0]));
|
|
1299
|
+
return true;
|
|
1300
|
+
}
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
__decorate$5([
|
|
1305
|
+
pacemCore.Watch( /* can only be databound or assigned at runtime */)
|
|
1306
|
+
], PacemCompositeWidgetElement.prototype, "items", void 0);
|
|
1307
|
+
// #endregion COMPOSITE
|
|
1308
|
+
|
|
1309
|
+
var __decorate$4 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1310
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1311
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1312
|
+
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;
|
|
1313
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1314
|
+
};
|
|
1315
|
+
//namespace Pacem.Components.Cms {
|
|
1316
|
+
const TEXT_METADATA = buildWidgetMetadata({
|
|
1317
|
+
display: { icon: 'font_download', name: 'Text', description: 'Plain text widget.' },
|
|
1318
|
+
props: [{
|
|
1319
|
+
prop: 'text', type: EXPRESSION_METADATA_TYPE, display: { name: 'Text' }, extra: EXPRESSION_WIDGET_METADATA_EXTRA
|
|
1320
|
+
}]
|
|
1321
|
+
});
|
|
1322
|
+
let PacemWidgetTextElement = class PacemWidgetTextElement extends PacemUiWidgetElement {
|
|
1323
|
+
constructor() {
|
|
1324
|
+
super(TEXT_METADATA);
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
__decorate$4([
|
|
1328
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
1329
|
+
], PacemWidgetTextElement.prototype, "text", void 0);
|
|
1330
|
+
PacemWidgetTextElement = __decorate$4([
|
|
1331
|
+
pacemCore.CustomElement({
|
|
1332
|
+
tagName: pacemCore.P + '-widget-text', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
1333
|
+
template: `<${pacemCore.P}-text text="{{ :host.text }}"></${pacemCore.P}-text>`
|
|
1334
|
+
})
|
|
1335
|
+
], PacemWidgetTextElement);
|
|
1336
|
+
|
|
1337
|
+
var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1338
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1339
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1340
|
+
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;
|
|
1341
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1342
|
+
};
|
|
1343
|
+
//namespace Pacem.Components.Cms {
|
|
1344
|
+
/**
|
|
1345
|
+
* UI widget container that eases dragdrop-based enrollment into composite widgets.
|
|
1346
|
+
*/
|
|
1347
|
+
let PacemWidgetPickerElement = class PacemWidgetPickerElement extends PacemCompositeWidgetElement {
|
|
1348
|
+
register(item) {
|
|
1349
|
+
const retval = super.register(item);
|
|
1350
|
+
if (retval) {
|
|
1351
|
+
item.hide = true;
|
|
1352
|
+
}
|
|
1353
|
+
return retval;
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
__decorate$3([
|
|
1357
|
+
pacemCore.ViewChild(pacemCore.P + '-drag-drop')
|
|
1358
|
+
], PacemWidgetPickerElement.prototype, "_dragDrop", void 0);
|
|
1359
|
+
PacemWidgetPickerElement = __decorate$3([
|
|
1360
|
+
pacemCore.CustomElement({
|
|
1361
|
+
tagName: pacemCore.P + '-widget-picker', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
1362
|
+
template: `<${pacemCore.P}-repeater datasource="{{ :host.items }}">
|
|
1363
|
+
<template>
|
|
1364
|
+
<${pacemCore.P}-panel behaviors="{{ [::_dragDrop] }}" class="${pacemCore.PCSS}-widget-itempicker display-flex flex-fill flex-middle flex-nowrap">
|
|
1365
|
+
<i class="${pacemCore.PCSS}-icon flex-auto" dragger>drag_indicator</i>
|
|
1366
|
+
<${pacemCore.P}-icon icon="{{ ^item.metadata.display.icon }}" class="flex-auto ${pacemCore.PCSS}-margin margin-x-1"></${pacemCore.P}-icon>
|
|
1367
|
+
<${pacemCore.P}-text text="{{ ^item.metadata.display.name }}"></${pacemCore.P}-text>
|
|
1368
|
+
</${pacemCore.P}-panel>
|
|
1369
|
+
</template>
|
|
1370
|
+
</${pacemCore.P}-repeater>
|
|
1371
|
+
<${pacemCore.P}-drag-drop handle-selector="i.${pacemCore.PCSS}-icon[dragger]"></${pacemCore.P}-drag-drop>
|
|
1372
|
+
<${pacemCore.P}-content></${pacemCore.P}-content>`
|
|
1373
|
+
})
|
|
1374
|
+
], PacemWidgetPickerElement);
|
|
1375
|
+
|
|
1376
|
+
var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1377
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1378
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1379
|
+
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;
|
|
1380
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1381
|
+
};
|
|
1382
|
+
//namespace Pacem.Components.Cms {
|
|
1383
|
+
function createSvgGridBox() {
|
|
1384
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
1385
|
+
svg.style.pointerEvents = 'none';
|
|
1386
|
+
svg.style.zIndex = '1000';
|
|
1387
|
+
svg.setAttribute('height', '100%');
|
|
1388
|
+
svg.setAttribute('width', '100%');
|
|
1389
|
+
svg.setAttribute('preserveAspectRatio', 'none');
|
|
1390
|
+
svg.setAttribute('class', 'grid-cell-wrapper');
|
|
1391
|
+
//svg.style.padding = '2px';
|
|
1392
|
+
//svg.style.boxSizing = 'border-box';
|
|
1393
|
+
svg.innerHTML = `<rect class="grid-cell" width="100%" height="100%"></rect>`;
|
|
1394
|
+
return svg;
|
|
1395
|
+
}
|
|
1396
|
+
const GRID_COLUMNS = 12;
|
|
1397
|
+
const FALLBACK_COLUMNS = GRID_COLUMNS;
|
|
1398
|
+
const FALLBACK_ROWS = 1;
|
|
1399
|
+
const GRID_METADATA = {
|
|
1400
|
+
display: {
|
|
1401
|
+
icon: 'grid_on',
|
|
1402
|
+
name: 'Grid',
|
|
1403
|
+
description: 'Composition Widget that lays out child-widgets in a grid container.'
|
|
1404
|
+
},
|
|
1405
|
+
props: [
|
|
1406
|
+
{
|
|
1407
|
+
prop: 'rows', type: 'int', display: {
|
|
1408
|
+
name: 'Rows', cssClass: ['cols-lg-4']
|
|
1409
|
+
}, validators: [
|
|
1410
|
+
{ type: 'required', errorMessage: '' },
|
|
1411
|
+
{
|
|
1412
|
+
type: 'range', errorMessage: '', params: {
|
|
1413
|
+
min: 1, max: 24
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
]
|
|
1417
|
+
}, {
|
|
1418
|
+
prop: 'rowGap', type: 'int', display: {
|
|
1419
|
+
//ui: 'slider',
|
|
1420
|
+
name: 'Row gap', cssClass: ['cols-lg-4']
|
|
1421
|
+
}, validators: [
|
|
1422
|
+
// { type: 'required', errorMessage: '' },
|
|
1423
|
+
{
|
|
1424
|
+
type: 'range', errorMessage: '', params: {
|
|
1425
|
+
min: 0, max: 3, step: .25
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
]
|
|
1429
|
+
}, {
|
|
1430
|
+
prop: 'columnGap', type: 'int', display: {
|
|
1431
|
+
//ui: 'slider',
|
|
1432
|
+
name: 'Column gap', cssClass: ['cols-lg-4']
|
|
1433
|
+
}, validators: [
|
|
1434
|
+
// { type: 'required', errorMessage: '' },
|
|
1435
|
+
{
|
|
1436
|
+
type: 'range', errorMessage: '', params: {
|
|
1437
|
+
min: 0, max: 3, step: .25
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
]
|
|
1441
|
+
}
|
|
1442
|
+
]
|
|
1443
|
+
};
|
|
1444
|
+
let PacemGridWidgetElement = class PacemGridWidgetElement extends PacemCompositeWidgetElement {
|
|
1445
|
+
constructor() {
|
|
1446
|
+
super(buildWidgetMetadata(GRID_METADATA), FALLBACK_COLUMNS, "grid");
|
|
1447
|
+
this._widgetPropertyChange = (evt) => {
|
|
1448
|
+
if (evt.detail.propertyName === 'row' || evt.detail.propertyName === 'rowspan') {
|
|
1449
|
+
const widget = evt.target;
|
|
1450
|
+
this.rows = Math.max(this.rows, widget.row + widget.rowspan);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
this._dragDropHandler = (evt) => {
|
|
1454
|
+
const args = evt.detail, el = args.element;
|
|
1455
|
+
switch (evt.type) {
|
|
1456
|
+
case pacemCore.UI.DragDropEventType.Start:
|
|
1457
|
+
this._gridBoxes.forEach(svg => { svg.style.pointerEvents = 'auto'; });
|
|
1458
|
+
this._initState = {
|
|
1459
|
+
colspan: el.colspan,
|
|
1460
|
+
rowspan: el.rowspan,
|
|
1461
|
+
col: el.column,
|
|
1462
|
+
row: el.row
|
|
1463
|
+
};
|
|
1464
|
+
break;
|
|
1465
|
+
case pacemCore.UI.DragDropEventType.End:
|
|
1466
|
+
this._gridBoxes.forEach(svg => { svg.style.pointerEvents = 'none'; });
|
|
1467
|
+
break;
|
|
1468
|
+
case pacemCore.UI.DragDropEventType.Over:
|
|
1469
|
+
var dropTarget = args.target;
|
|
1470
|
+
var col = +dropTarget.style.gridColumnStart - 1;
|
|
1471
|
+
var row = +dropTarget.style.gridRowStart - 1;
|
|
1472
|
+
const farRight = col + this._initState.colspan, farBottom = row + this._initState.rowspan;
|
|
1473
|
+
// check overlap
|
|
1474
|
+
if (!this._intersects(el, col, row, el.colspan, el.rowspan)) {
|
|
1475
|
+
let fireLayoutChange = false;
|
|
1476
|
+
//
|
|
1477
|
+
if (farRight <= (this.columns || FALLBACK_COLUMNS)) {
|
|
1478
|
+
fireLayoutChange = el.column !== col;
|
|
1479
|
+
el.column = col; // + '/' + (col + this._initState.colspan);
|
|
1480
|
+
}
|
|
1481
|
+
if (farBottom <= (this.rows || FALLBACK_ROWS)) {
|
|
1482
|
+
fireLayoutChange = fireLayoutChange || (el.row !== row);
|
|
1483
|
+
el.row = row; // + '/' + (row + this._initState.rowspan);
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
break;
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
this._resizeHandler = (evt) => {
|
|
1490
|
+
switch (evt.type) {
|
|
1491
|
+
case pacemCore.UI.RescaleEventType.Start:
|
|
1492
|
+
pacemCore.Utils.addClass(evt.detail.element, pacemCore.PCSS + '-rescaling');
|
|
1493
|
+
this._gridBoxes.forEach(svg => { svg.style.pointerEvents = 'auto'; });
|
|
1494
|
+
break;
|
|
1495
|
+
case pacemCore.UI.RescaleEventType.End:
|
|
1496
|
+
this._gridBoxes.forEach(svg => { svg.style.pointerEvents = 'none'; });
|
|
1497
|
+
pacemCore.Utils.removeClass(evt.detail.element, pacemCore.PCSS + '-rescaling');
|
|
1498
|
+
break;
|
|
1499
|
+
case pacemCore.UI.RescaleEventType.Rescale:
|
|
1500
|
+
evt.preventDefault();
|
|
1501
|
+
// check pos
|
|
1502
|
+
const pos = { x: evt.clientX, y: evt.clientY }, handle = evt.detail.handle;
|
|
1503
|
+
const dropTarget = document.elementsFromPoint(pos.x, pos.y).find(e => this._dragDrop.dropTargets.indexOf(e) >= 0);
|
|
1504
|
+
if (dropTarget) {
|
|
1505
|
+
var col = +dropTarget.style.gridColumnStart;
|
|
1506
|
+
var row = +dropTarget.style.gridRowStart;
|
|
1507
|
+
const widget = evt.detail.element, startcol = widget.column + 1, startrow = widget.row + 1;
|
|
1508
|
+
const colspan = 1 + col - startcol, rowspan = 1 + row - startrow;
|
|
1509
|
+
if (!this._intersects(widget, widget.column, widget.row, colspan, rowspan)) {
|
|
1510
|
+
let fireLayoutChange = false;
|
|
1511
|
+
//
|
|
1512
|
+
if (col >= startcol && handle.endsWith('right')) {
|
|
1513
|
+
fireLayoutChange = widget.colspan !== colspan;
|
|
1514
|
+
widget.colspan = colspan;
|
|
1515
|
+
}
|
|
1516
|
+
if (row >= startrow && handle.startsWith('bottom')) {
|
|
1517
|
+
fireLayoutChange = fireLayoutChange || widget.rowspan !== rowspan;
|
|
1518
|
+
widget.rowspan = rowspan;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
break;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
this._gridBoxes = [];
|
|
1526
|
+
}
|
|
1527
|
+
register(item) {
|
|
1528
|
+
let retval = super.register(item);
|
|
1529
|
+
if (retval) {
|
|
1530
|
+
const row = item.row || 0, column = item.column || 0, colspan = item.colspan || 2, rowspan = item.rowspan || 1;
|
|
1531
|
+
let foundspot = !this._intersects(item, column, row, colspan, rowspan);
|
|
1532
|
+
if (foundspot) {
|
|
1533
|
+
item.row = row;
|
|
1534
|
+
item.column = column;
|
|
1535
|
+
item.colspan = colspan;
|
|
1536
|
+
item.rowspan = rowspan;
|
|
1537
|
+
}
|
|
1538
|
+
else {
|
|
1539
|
+
if (!foundspot) {
|
|
1540
|
+
// select a spot or create a new row
|
|
1541
|
+
let check = (elasticOnColspan = false) => {
|
|
1542
|
+
let maxColIndex = this.columns - 1;
|
|
1543
|
+
if (!elasticOnColspan) {
|
|
1544
|
+
maxColIndex = maxColIndex - colspan + 1;
|
|
1545
|
+
}
|
|
1546
|
+
for (let j = 0; j < this.rows; j++) {
|
|
1547
|
+
for (let i = 0; i <= maxColIndex; i++) {
|
|
1548
|
+
if (!this._intersects(item, i, j, colspan, rowspan)) {
|
|
1549
|
+
item.column = i;
|
|
1550
|
+
item.row = j;
|
|
1551
|
+
item.colspan = Math.min(maxColIndex + 1 - i, colspan);
|
|
1552
|
+
item.rowspan = rowspan;
|
|
1553
|
+
foundspot = true;
|
|
1554
|
+
break;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
if (foundspot)
|
|
1558
|
+
break;
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
check();
|
|
1562
|
+
if (!foundspot && colspan > 1) {
|
|
1563
|
+
// find first avail slot conceding less colspan
|
|
1564
|
+
check(true);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
// okay, surrender and create a new row
|
|
1568
|
+
if (!foundspot) {
|
|
1569
|
+
this.rows++;
|
|
1570
|
+
item.row = this.rows - 1;
|
|
1571
|
+
item.column = 0;
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
//
|
|
1575
|
+
// item.behaviors.push(this._dragDrop, this._rescaler);
|
|
1576
|
+
item.behaviors = [this._dragDrop, this._rescaler];
|
|
1577
|
+
item.addEventListener(pacemCore.PropertyChangeEventName, this._widgetPropertyChange, false);
|
|
1578
|
+
}
|
|
1579
|
+
//
|
|
1580
|
+
return retval;
|
|
1581
|
+
}
|
|
1582
|
+
unregister(item) {
|
|
1583
|
+
let retval = super.unregister(item);
|
|
1584
|
+
if (retval) {
|
|
1585
|
+
item.removeEventListener(pacemCore.PropertyChangeEventName, this._widgetPropertyChange, false);
|
|
1586
|
+
const ndx = item.behaviors.indexOf(this._dragDrop);
|
|
1587
|
+
if (ndx >= 0)
|
|
1588
|
+
item.behaviors.splice(ndx, 1);
|
|
1589
|
+
const ndx1 = item.behaviors.indexOf(this._rescaler);
|
|
1590
|
+
if (ndx1 >= 0)
|
|
1591
|
+
item.behaviors.splice(ndx1, 1);
|
|
1592
|
+
}
|
|
1593
|
+
return retval;
|
|
1594
|
+
}
|
|
1595
|
+
_intersects(who, col, row, colspan, rowspan) {
|
|
1596
|
+
for (let item of this.items) {
|
|
1597
|
+
let widget = item;
|
|
1598
|
+
if (widget === who) {
|
|
1599
|
+
continue;
|
|
1600
|
+
}
|
|
1601
|
+
if ((widget.column < (col + colspan) && (widget.column + widget.colspan) > col)
|
|
1602
|
+
&& (widget.row < (row + rowspan) && (widget.row + widget.rowspan) > row)) {
|
|
1603
|
+
return true;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
connectedCallback() {
|
|
1609
|
+
super.connectedCallback();
|
|
1610
|
+
pacemCore.Utils.addClass(this, pacemCore.PCSS + '-grid');
|
|
1611
|
+
// drag-drop
|
|
1612
|
+
let dragDrop = this._dragDrop = document.createElement(pacemCore.P + '-drag-drop');
|
|
1613
|
+
let floater = document.createElement('div');
|
|
1614
|
+
document.body.appendChild(floater);
|
|
1615
|
+
dragDrop.floater = floater;
|
|
1616
|
+
dragDrop.mode = pacemCore.UI.DragDataMode.Alias;
|
|
1617
|
+
dragDrop.dropBehavior = pacemCore.UI.DropBehavior.None;
|
|
1618
|
+
dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Start, this._dragDropHandler, false);
|
|
1619
|
+
dragDrop.addEventListener(pacemCore.UI.DragDropEventType.Over, this._dragDropHandler, false);
|
|
1620
|
+
dragDrop.addEventListener(pacemCore.UI.DragDropEventType.End, this._dragDropHandler, false);
|
|
1621
|
+
document.body.appendChild(dragDrop);
|
|
1622
|
+
// rescale
|
|
1623
|
+
let rescale = this._rescaler = document.createElement(pacemCore.P + '-rescale');
|
|
1624
|
+
rescale.handles = [pacemCore.UI.RescaleHandle.Right, pacemCore.UI.RescaleHandle.Bottom];
|
|
1625
|
+
rescale.addEventListener(pacemCore.UI.RescaleEventType.Start, this._resizeHandler, false);
|
|
1626
|
+
rescale.addEventListener(pacemCore.UI.RescaleEventType.Rescale, this._resizeHandler, false);
|
|
1627
|
+
rescale.addEventListener(pacemCore.UI.RescaleEventType.End, this._resizeHandler, false);
|
|
1628
|
+
document.body.appendChild(rescale);
|
|
1629
|
+
// editor
|
|
1630
|
+
// default configuration
|
|
1631
|
+
if (pacemCore.Utils.isNullOrEmpty(this.columns)) {
|
|
1632
|
+
this.columns = GRID_COLUMNS;
|
|
1633
|
+
}
|
|
1634
|
+
if (pacemCore.Utils.isNullOrEmpty(this.rows)) {
|
|
1635
|
+
this.rows = 1;
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
viewActivatedCallback() {
|
|
1639
|
+
super.viewActivatedCallback();
|
|
1640
|
+
this.adapt();
|
|
1641
|
+
}
|
|
1642
|
+
propertyChangedCallback(name, old, val, first) {
|
|
1643
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
1644
|
+
this.adapt();
|
|
1645
|
+
}
|
|
1646
|
+
disconnectedCallback() {
|
|
1647
|
+
var dragDrop = this._dragDrop, rescale = this._rescaler;
|
|
1648
|
+
if (!pacemCore.Utils.isNull(dragDrop)) {
|
|
1649
|
+
dragDrop.floater.remove();
|
|
1650
|
+
dragDrop.removeEventListener(pacemCore.UI.DragDropEventType.Start, this._dragDropHandler, false);
|
|
1651
|
+
dragDrop.removeEventListener(pacemCore.UI.DragDropEventType.Over, this._dragDropHandler, false);
|
|
1652
|
+
dragDrop.removeEventListener(pacemCore.UI.DragDropEventType.End, this._dragDropHandler, false);
|
|
1653
|
+
dragDrop.remove();
|
|
1654
|
+
this._dragDrop = null;
|
|
1655
|
+
}
|
|
1656
|
+
if (!pacemCore.Utils.isNull(rescale)) {
|
|
1657
|
+
rescale.removeEventListener(pacemCore.UI.RescaleEventType.Start, this._resizeHandler, false);
|
|
1658
|
+
rescale.removeEventListener(pacemCore.UI.RescaleEventType.Rescale, this._resizeHandler, false);
|
|
1659
|
+
rescale.removeEventListener(pacemCore.UI.RescaleEventType.End, this._resizeHandler, false);
|
|
1660
|
+
rescale.remove();
|
|
1661
|
+
this._rescaler = null;
|
|
1662
|
+
}
|
|
1663
|
+
super.disconnectedCallback();
|
|
1664
|
+
}
|
|
1665
|
+
_normalize(measure, defaultValue = 1) {
|
|
1666
|
+
if (typeof measure === 'string') {
|
|
1667
|
+
return measure;
|
|
1668
|
+
}
|
|
1669
|
+
else if (measure == null) {
|
|
1670
|
+
measure = defaultValue;
|
|
1671
|
+
}
|
|
1672
|
+
return this.unitPixels(measure) + 'px';
|
|
1673
|
+
}
|
|
1674
|
+
unitPixels(qty) {
|
|
1675
|
+
return qty * (this.unit || 8);
|
|
1676
|
+
}
|
|
1677
|
+
adapt() {
|
|
1678
|
+
this.style.marginTop = this.unitPixels(this.marginTop || 0) + 'px';
|
|
1679
|
+
this.style.marginBottom = this.unitPixels(this.marginBottom || 0) + 'px';
|
|
1680
|
+
//
|
|
1681
|
+
this.style.gridTemplateColumns = `repeat(${(this.columns || FALLBACK_COLUMNS)}, 1fr)`;
|
|
1682
|
+
//this.style.gridAutoRows = `minmax(${(this.minRowheight || 24)}, ${(this.rowheight || 'auto')})`;
|
|
1683
|
+
let minrowheight = this._normalize(this.minRowheight, 3), rowheight = this._normalize(this.rowheight || 'auto');
|
|
1684
|
+
this.style.gridTemplateRows = `repeat(${(this.rows || FALLBACK_ROWS)}, minmax(${minrowheight}, ${rowheight}))`;
|
|
1685
|
+
this.style.gridRowGap = this._normalize(this.rowGap, 1);
|
|
1686
|
+
this.style.gridColumnGap = this._normalize(this.columnGap, 1);
|
|
1687
|
+
//
|
|
1688
|
+
this._setGridLines();
|
|
1689
|
+
}
|
|
1690
|
+
_setGridLines() {
|
|
1691
|
+
var splice = 0;
|
|
1692
|
+
const editing = this.editing;
|
|
1693
|
+
if (editing) {
|
|
1694
|
+
const cols = this.columns || FALLBACK_COLUMNS, rows = this.rows || FALLBACK_ROWS, total = cols * rows;
|
|
1695
|
+
splice = total;
|
|
1696
|
+
for (let k = 0; k < total; k++) {
|
|
1697
|
+
while (this._gridBoxes.length <= k) {
|
|
1698
|
+
let s = createSvgGridBox();
|
|
1699
|
+
this.appendChild(s);
|
|
1700
|
+
this._gridBoxes.push(s);
|
|
1701
|
+
}
|
|
1702
|
+
let svg = this._gridBoxes[k];
|
|
1703
|
+
const i = k % cols, j = Math.floor(k / cols);
|
|
1704
|
+
svg.style.gridColumn = (i + 1).toString();
|
|
1705
|
+
svg.style.gridRow = (j + 1).toString();
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
for (let svg of this._gridBoxes.splice(splice)) {
|
|
1709
|
+
svg.remove();
|
|
1710
|
+
}
|
|
1711
|
+
// behaviors to be synchronized
|
|
1712
|
+
if (!pacemCore.Utils.isNull(this._dragDrop) && !pacemCore.Utils.isNull(this._rescaler)) {
|
|
1713
|
+
this._dragDrop.disabled = this._rescaler.disabled
|
|
1714
|
+
= !editing;
|
|
1715
|
+
this._dragDrop.dropTargets = this._gridBoxes;
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
__decorate$2([
|
|
1720
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1721
|
+
], PacemGridWidgetElement.prototype, "unit", void 0);
|
|
1722
|
+
__decorate$2([
|
|
1723
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1724
|
+
], PacemGridWidgetElement.prototype, "marginTop", void 0);
|
|
1725
|
+
__decorate$2([
|
|
1726
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1727
|
+
], PacemGridWidgetElement.prototype, "marginBottom", void 0);
|
|
1728
|
+
__decorate$2([
|
|
1729
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1730
|
+
], PacemGridWidgetElement.prototype, "columns", void 0);
|
|
1731
|
+
__decorate$2([
|
|
1732
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1733
|
+
], PacemGridWidgetElement.prototype, "rows", void 0);
|
|
1734
|
+
__decorate$2([
|
|
1735
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
1736
|
+
], PacemGridWidgetElement.prototype, "minRowheight", void 0);
|
|
1737
|
+
__decorate$2([
|
|
1738
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.String })
|
|
1739
|
+
], PacemGridWidgetElement.prototype, "rowheight", void 0);
|
|
1740
|
+
__decorate$2([
|
|
1741
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1742
|
+
], PacemGridWidgetElement.prototype, "rowGap", void 0);
|
|
1743
|
+
__decorate$2([
|
|
1744
|
+
pacemCore.Watch({ emit: false, reflectBack: true, converter: pacemCore.PropertyConverters.Number })
|
|
1745
|
+
], PacemGridWidgetElement.prototype, "columnGap", void 0);
|
|
1746
|
+
__decorate$2([
|
|
1747
|
+
pacemCore.Debounce(100)
|
|
1748
|
+
], PacemGridWidgetElement.prototype, "adapt", null);
|
|
1749
|
+
PacemGridWidgetElement = __decorate$2([
|
|
1750
|
+
pacemCore.CustomElement({ tagName: pacemCore.P + '-widget-grid' })
|
|
1751
|
+
], PacemGridWidgetElement);
|
|
1752
|
+
|
|
1753
|
+
var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1754
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1755
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1756
|
+
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;
|
|
1757
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1758
|
+
};
|
|
1759
|
+
//namespace Pacem.Components.Cms {
|
|
1760
|
+
/** Default metadata ('expression' field) 'type' factory. */
|
|
1761
|
+
const DATACOLUMNS_METADATA_TYPE = (host, hostRef = ':host', hostEntityRef = ':host.entity') => {
|
|
1762
|
+
const attrs = {}, meta = host.metadata, fns = Functions, fnKeys = [];
|
|
1763
|
+
attrs['properties'] = `{{ Pacem.CustomElementUtils.getWatchedProperty(${hostEntityRef}, '${meta.prop}').config.converter }}`;
|
|
1764
|
+
const tagName = pacemCore.P + '-datacolumns';
|
|
1765
|
+
let extra = (meta.extra || {});
|
|
1766
|
+
// properties
|
|
1767
|
+
if (!pacemCore.Utils.isNullOrEmpty(extra.properties)) {
|
|
1768
|
+
switch (typeof extra.properties) {
|
|
1769
|
+
case 'string':
|
|
1770
|
+
attrs['properties'] = `{{ ${hostEntityRef}.${extra.properties} }}`;
|
|
1771
|
+
break;
|
|
1772
|
+
case 'function':
|
|
1773
|
+
const fnKey = 'fn' + pacemCore.Utils.uniqueCode();
|
|
1774
|
+
fns[fnKey] = extra.properties;
|
|
1775
|
+
attrs['properties'] = `{{ Pacem.Components.Cms.Functions.${fnKey}(${hostRef}), once }}`;
|
|
1776
|
+
// tidy-up memento
|
|
1777
|
+
fnKeys.push(fnKey);
|
|
1778
|
+
break;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (fnKeys.length > 0) {
|
|
1782
|
+
// tidy-up
|
|
1783
|
+
attrs['on-unload'] = `{{ Pacem.Components.Cms.Functions.dismiss('${fnKeys.join('\',\'')}') }}`;
|
|
1784
|
+
}
|
|
1785
|
+
return { tagName: tagName, attrs: attrs };
|
|
1786
|
+
};
|
|
1787
|
+
const DATACOLUMN_METADATA$1 = {
|
|
1788
|
+
display: { name: 'Columns' },
|
|
1789
|
+
props: [
|
|
1790
|
+
{ prop: 'header', type: 'string', display: { cssClass: ['form-minimal'], name: 'Header' } },
|
|
1791
|
+
{
|
|
1792
|
+
prop: 'content', type: EXPRESSION_METADATA_TYPE, display: { name: 'Content' },
|
|
1793
|
+
extra: EXPRESSION_WIDGET_METADATA_EXTRA
|
|
1794
|
+
}
|
|
1795
|
+
]
|
|
1796
|
+
};
|
|
1797
|
+
let PacemDataColumnElement = class PacemDataColumnElement extends pacemCore.Components.PacemElement {
|
|
1798
|
+
propertyChangedCallback(name, old, val, first) {
|
|
1799
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
1800
|
+
switch (name) {
|
|
1801
|
+
case 'content':
|
|
1802
|
+
this.contentExpression = val;
|
|
1803
|
+
break;
|
|
1804
|
+
case 'contentExpression':
|
|
1805
|
+
this.setAttribute('content', val || '');
|
|
1806
|
+
break;
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
viewActivatedCallback() {
|
|
1810
|
+
super.viewActivatedCallback();
|
|
1811
|
+
this._form.entity = this;
|
|
1812
|
+
this._form.metadata = gridifyMetadata(DATACOLUMN_METADATA$1);
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
__decorate$1([
|
|
1816
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
1817
|
+
], PacemDataColumnElement.prototype, "header", void 0);
|
|
1818
|
+
__decorate$1([
|
|
1819
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
1820
|
+
], PacemDataColumnElement.prototype, "content", void 0);
|
|
1821
|
+
__decorate$1([
|
|
1822
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.String })
|
|
1823
|
+
], PacemDataColumnElement.prototype, "contentExpression", void 0);
|
|
1824
|
+
__decorate$1([
|
|
1825
|
+
pacemCore.ViewChild(pacemCore.P + '-form')
|
|
1826
|
+
], PacemDataColumnElement.prototype, "_form", void 0);
|
|
1827
|
+
PacemDataColumnElement = __decorate$1([
|
|
1828
|
+
pacemCore.CustomElement({
|
|
1829
|
+
tagName: pacemCore.P + '-widget-datacolumn', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
1830
|
+
template: `<${pacemCore.P}-form class="panel-body" autogenerate="true"></${pacemCore.P}-form>`
|
|
1831
|
+
})
|
|
1832
|
+
], PacemDataColumnElement);
|
|
1833
|
+
let PacemDataColumnsElement = class PacemDataColumnsElement extends pacemScaffolding.Components.Scaffolding.PacemBaseElement {
|
|
1834
|
+
constructor() {
|
|
1835
|
+
super(...arguments);
|
|
1836
|
+
this._dropHandler = (e) => {
|
|
1837
|
+
this.changeHandler(e);
|
|
1838
|
+
};
|
|
1839
|
+
this._columnifyMetadata = (props = this.properties) => {
|
|
1840
|
+
return (props || []).map(p => {
|
|
1841
|
+
const header = typeof p.display?.name === 'function' ? /* NOT supported */ p.prop : (p.display?.name || p.prop);
|
|
1842
|
+
const c = {
|
|
1843
|
+
header,
|
|
1844
|
+
content: `{{ ^item.${p.prop} }}`
|
|
1845
|
+
};
|
|
1846
|
+
return c;
|
|
1847
|
+
}).sort((a, b) => a.header > b.header ? 1 : -1);
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
get inputFields() {
|
|
1851
|
+
return [];
|
|
1852
|
+
}
|
|
1853
|
+
toggleReadonlyView(readonly) {
|
|
1854
|
+
// leave it all to the template bindings
|
|
1855
|
+
}
|
|
1856
|
+
onChange(evt) {
|
|
1857
|
+
return pacemCore.Utils.fromResult(this.value = this._repeater.datasource);
|
|
1858
|
+
}
|
|
1859
|
+
acceptValue(val) {
|
|
1860
|
+
if (!pacemCore.Utils.isNull(this._repeater)) {
|
|
1861
|
+
this._repeater.datasource = pacemCore.Utils.clone(val || []);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
getViewValue(value) {
|
|
1865
|
+
return /* dummy */ '[DataColumns]';
|
|
1866
|
+
}
|
|
1867
|
+
convertValueAttributeToProperty(attr) {
|
|
1868
|
+
return pacemCore.PropertyConverters.Json.convert(attr, this);
|
|
1869
|
+
}
|
|
1870
|
+
viewActivatedCallback() {
|
|
1871
|
+
super.viewActivatedCallback();
|
|
1872
|
+
this._propDragger.addEventListener(pacemCore.UI.DragDropEventType.End, this._dropHandler, false);
|
|
1873
|
+
this._colDragger.addEventListener(pacemCore.UI.DragDropEventType.End, this._dropHandler, false);
|
|
1874
|
+
}
|
|
1875
|
+
disconnectedCallback() {
|
|
1876
|
+
if (!pacemCore.Utils.isNull(this._propDragger)) {
|
|
1877
|
+
this._propDragger.removeEventListener(pacemCore.UI.DragDropEventType.End, this._dropHandler, false);
|
|
1878
|
+
}
|
|
1879
|
+
if (!pacemCore.Utils.isNull(this._colDragger)) {
|
|
1880
|
+
this._colDragger.removeEventListener(pacemCore.UI.DragDropEventType.End, this._dropHandler, false);
|
|
1881
|
+
}
|
|
1882
|
+
super.disconnectedCallback();
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
1885
|
+
__decorate$1([
|
|
1886
|
+
pacemCore.ViewChild(`${pacemCore.P}-repeater[columns]`)
|
|
1887
|
+
], PacemDataColumnsElement.prototype, "_repeater", void 0);
|
|
1888
|
+
__decorate$1([
|
|
1889
|
+
pacemCore.ViewChild(`${pacemCore.P}-drag-drop[properties]`)
|
|
1890
|
+
], PacemDataColumnsElement.prototype, "_propDragger", void 0);
|
|
1891
|
+
__decorate$1([
|
|
1892
|
+
pacemCore.ViewChild(`${pacemCore.P}-drag-drop[columns]`)
|
|
1893
|
+
], PacemDataColumnsElement.prototype, "_colDragger", void 0);
|
|
1894
|
+
__decorate$1([
|
|
1895
|
+
pacemCore.ViewChild('div[drop-target]')
|
|
1896
|
+
], PacemDataColumnsElement.prototype, "_dropTarget", void 0);
|
|
1897
|
+
__decorate$1([
|
|
1898
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Json })
|
|
1899
|
+
], PacemDataColumnsElement.prototype, "properties", void 0);
|
|
1900
|
+
PacemDataColumnsElement = __decorate$1([
|
|
1901
|
+
pacemCore.CustomElement({
|
|
1902
|
+
tagName: pacemCore.P + '-widget-datacolumns', shadow: pacemCore.Defaults.USE_SHADOW_ROOT,
|
|
1903
|
+
template: `<div class="${pacemCore.PCSS}-datacolumns">
|
|
1904
|
+
<div class="datacolumns-main display-flex flex-fill">
|
|
1905
|
+
|
|
1906
|
+
<${pacemCore.P}-drag-drop mode="${pacemCore.UI.DragDataMode.Alias}" disabled="{{ :host.readonly }}" handle-selector="*[handle]"
|
|
1907
|
+
drop-behavior="${pacemCore.UI.DropBehavior.InsertChild}" drop-targets="{{ [::_dropTarget] }}" columns></${pacemCore.P}-drag-drop>
|
|
1908
|
+
<${pacemCore.P}-repeater class="display-flex flex-fill" columns>
|
|
1909
|
+
<!-- columns -->
|
|
1910
|
+
<div class="display-flex flex-nowrap" drop-target>
|
|
1911
|
+
<template>
|
|
1912
|
+
<${pacemCore.P}-panel behaviors="{{ [::_colDragger] }}">
|
|
1913
|
+
<div class="${pacemCore.PCSS}-panel panel-side-left side-auto">
|
|
1914
|
+
<div class="panel-side">
|
|
1915
|
+
<${pacemCore.P}-button class="display-block button-flat icon-glyph-small" icon-glyph="drag_indicator" handle></${pacemCore.P}-button>
|
|
1916
|
+
<${pacemCore.P}-button class="display-block button-flat icon-glyph-small" on-click=":host.value.splice(^index, 1)" icon-glyph="clear"></${pacemCore.P}-button>
|
|
1917
|
+
</div>
|
|
1918
|
+
<div class="panel-heading">
|
|
1919
|
+
<${pacemCore.P}-text text="{{ ^item.header }}"></${pacemCore.P}-text>
|
|
1920
|
+
</div>
|
|
1921
|
+
<${pacemCore.P}-widget-datacolumn class="panel-body" header="{{ ^item.header, twoway }}" content-expression="{{ ^item.content, twoway }}"></${pacemCore.P}-widget-datacolumn>
|
|
1922
|
+
</div>
|
|
1923
|
+
</${pacemCore.P}-panel>
|
|
1924
|
+
</template>
|
|
1925
|
+
</div>
|
|
1926
|
+
</${pacemCore.P}-repeater>
|
|
1927
|
+
|
|
1928
|
+
</div>
|
|
1929
|
+
<${pacemCore.P}-panel class="datacolumns-props" hide="{{ :host.readonly }}">
|
|
1930
|
+
<${pacemCore.P}-drag-drop mode="${pacemCore.UI.DragDataMode.Copy}" disabled="{{ :host.readonly }}" handle-selector="*[handle]"
|
|
1931
|
+
drop-behavior="${pacemCore.UI.DropBehavior.InsertChild}" drop-targets="{{ [::_dropTarget] }}" properties></${pacemCore.P}-drag-drop>
|
|
1932
|
+
<${pacemCore.P}-repeater datasource="{{ :host._columnifyMetadata(:host.properties) }}">
|
|
1933
|
+
<!-- properties -->
|
|
1934
|
+
<template>
|
|
1935
|
+
<${pacemCore.P}-panel behaviors="{{ [::_propDragger] }}" class="${pacemCore.PCSS}-panel panel-side-left side-auto panel-primary panel-filled ${pacemCore.PCSS}-margin margin-bottom-1">
|
|
1936
|
+
<div class="panel-side">
|
|
1937
|
+
<${pacemCore.P}-button class="display-block button-flat icon-glyph-small" icon-glyph="drag_indicator" handle></${pacemCore.P}-button>
|
|
1938
|
+
</div>
|
|
1939
|
+
<div class="text-truncate panel-body">
|
|
1940
|
+
<${pacemCore.P}-span text="{{ ^item.header }}"></${pacemCore.P}-span>
|
|
1941
|
+
</div>
|
|
1942
|
+
</${pacemCore.P}-panel>
|
|
1943
|
+
</template>
|
|
1944
|
+
</${pacemCore.P}-repeater>
|
|
1945
|
+
</${pacemCore.P}-panel>
|
|
1946
|
+
</div>`
|
|
1947
|
+
})
|
|
1948
|
+
], PacemDataColumnsElement);
|
|
1949
|
+
|
|
1950
|
+
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1951
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1952
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1953
|
+
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;
|
|
1954
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1955
|
+
};
|
|
1956
|
+
//namespace Pacem.Components.Cms {
|
|
1957
|
+
const DATACOLUMN_METADATA = {
|
|
1958
|
+
display: { name: 'DataColumn' },
|
|
1959
|
+
props: [
|
|
1960
|
+
{ prop: "header", type: "string", display: { name: "Header" } },
|
|
1961
|
+
{ prop: "content", type: EXPRESSION_METADATA_TYPE, display: { name: "Content" }, extra: EXPRESSION_WIDGET_METADATA_EXTRA },
|
|
1962
|
+
]
|
|
1963
|
+
};
|
|
1964
|
+
const DATAGRID_METADATA = buildWidgetMetadata({
|
|
1965
|
+
display: { icon: 'table_chart', name: 'DataGrid', description: 'DataGrid widget.' },
|
|
1966
|
+
props: [{
|
|
1967
|
+
prop: 'datasource', type: EXPRESSION_METADATA_TYPE, display: { name: 'Datasource' },
|
|
1968
|
+
extra: pacemCore.Utils.extend({}, EXPRESSION_WIDGET_METADATA_EXTRA, { filter: (e) => e instanceof PacemWidgetDataElement || e instanceof PacemWidgetFetchElement })
|
|
1969
|
+
},
|
|
1970
|
+
{
|
|
1971
|
+
prop: 'columns', type: DATACOLUMNS_METADATA_TYPE, display: { name: 'Columns' },
|
|
1972
|
+
// this will include 'datasource' as argument in the oneToMany source fn
|
|
1973
|
+
extra: { properties: 'datarowMetadata' },
|
|
1974
|
+
props: gridifyMetadata(DATACOLUMN_METADATA)
|
|
1975
|
+
}]
|
|
1976
|
+
});
|
|
1977
|
+
function gridify(columns = []) {
|
|
1978
|
+
var output = '';
|
|
1979
|
+
for (let column of columns || []) {
|
|
1980
|
+
// if empty then 1fr
|
|
1981
|
+
const col = column.width || 1;
|
|
1982
|
+
if (typeof col === 'number') {
|
|
1983
|
+
output += col + 'fr ';
|
|
1984
|
+
}
|
|
1985
|
+
else {
|
|
1986
|
+
output += 'auto ';
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
return output;
|
|
1990
|
+
}
|
|
1991
|
+
function datagridFragments(columns = []) {
|
|
1992
|
+
const fragHeading = document.createDocumentFragment(), fragBody = document.createDocumentFragment();
|
|
1993
|
+
let j = 1;
|
|
1994
|
+
for (let col of columns) {
|
|
1995
|
+
// heading
|
|
1996
|
+
const headcell = document.createElement('div');
|
|
1997
|
+
headcell.classList.add(pacemCore.PCSS + '-headcell');
|
|
1998
|
+
headcell.textContent = col.header;
|
|
1999
|
+
fragHeading.appendChild(headcell);
|
|
2000
|
+
// body
|
|
2001
|
+
const datacell = new pacemCore.Components.PacemSpanElement();
|
|
2002
|
+
datacell.classList.add(pacemCore.PCSS + '-datacell', 'datacell-corners');
|
|
2003
|
+
datacell.style.gridColumn = j.toString();
|
|
2004
|
+
datacell.setAttribute('css', "{{ {'grid-row': ^index+2} }}");
|
|
2005
|
+
datacell.setAttribute('content', col.content);
|
|
2006
|
+
fragBody.appendChild(datacell);
|
|
2007
|
+
j++;
|
|
2008
|
+
}
|
|
2009
|
+
const datarow = new pacemCore.Components.PacemPanelElement();
|
|
2010
|
+
datarow.classList.add(pacemCore.PCSS + '-datarow');
|
|
2011
|
+
datarow.setAttribute('css', "{{ {'grid-row': ^index+2} }}");
|
|
2012
|
+
datarow.setAttribute('css-class', "{{ {'datarow-alt': ^index % 2 === 1} }}");
|
|
2013
|
+
datarow.style.gridColumn = "1/" + (columns.length + 1);
|
|
2014
|
+
fragBody.appendChild(datarow);
|
|
2015
|
+
return { head: fragHeading, body: fragBody };
|
|
2016
|
+
}
|
|
2017
|
+
function datagridInnerHTML(id, columns = []) {
|
|
2018
|
+
const { head, body } = datagridFragments(columns);
|
|
2019
|
+
const head0 = document.createElement('div');
|
|
2020
|
+
head0.appendChild(head);
|
|
2021
|
+
const body0 = document.createElement('div');
|
|
2022
|
+
body0.appendChild(body);
|
|
2023
|
+
return `<${pacemCore.P}-repeater datasource="{{ #${id}.datasource }}">
|
|
2024
|
+
<div class="${pacemCore.PCSS}-datatable" style="grid-template-columns: ${gridify(columns)}">
|
|
2025
|
+
${head0.innerHTML}
|
|
2026
|
+
<template>${body0.innerHTML}</template>
|
|
2027
|
+
</div></${pacemCore.P}-repeater>`;
|
|
2028
|
+
}
|
|
2029
|
+
let PacemWidgetDataGridElement = class PacemWidgetDataGridElement extends PacemUiWidgetElement {
|
|
2030
|
+
constructor() {
|
|
2031
|
+
super(DATAGRID_METADATA);
|
|
2032
|
+
this.columns = [];
|
|
2033
|
+
this.datasource = [];
|
|
2034
|
+
this.datarowMetadata = [];
|
|
2035
|
+
this._builtUponDatasource = false;
|
|
2036
|
+
}
|
|
2037
|
+
_gridify(columns = this.columns) {
|
|
2038
|
+
var output = '';
|
|
2039
|
+
for (let column of columns || []) {
|
|
2040
|
+
// if empty then 1fr
|
|
2041
|
+
const col = column.width || 1;
|
|
2042
|
+
if (typeof col === 'number') {
|
|
2043
|
+
output += col + 'fr ';
|
|
2044
|
+
}
|
|
2045
|
+
else {
|
|
2046
|
+
output += 'auto ';
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
return output;
|
|
2050
|
+
}
|
|
2051
|
+
propertyChangedCallback(name, old, val, first) {
|
|
2052
|
+
super.propertyChangedCallback(name, old, val, first);
|
|
2053
|
+
if (!first) {
|
|
2054
|
+
switch (name) {
|
|
2055
|
+
case 'columns':
|
|
2056
|
+
/*
|
|
2057
|
+
*
|
|
2058
|
+
* TODO: manage columns separately!
|
|
2059
|
+
* Create an ad-hoc editor/formfield and a dedicated form
|
|
2060
|
+
*
|
|
2061
|
+
* */
|
|
2062
|
+
this.innerHTML = datagridInnerHTML(this.id, val);
|
|
2063
|
+
break;
|
|
2064
|
+
case 'datasource':
|
|
2065
|
+
this._extractMetadataJustInCase(val);
|
|
2066
|
+
break;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
viewActivatedCallback() {
|
|
2071
|
+
super.viewActivatedCallback();
|
|
2072
|
+
this.innerHTML = datagridInnerHTML(this.id, this.columns);
|
|
2073
|
+
}
|
|
2074
|
+
_seekArray(ds) {
|
|
2075
|
+
if (pacemCore.Utils.isArray(ds)) {
|
|
2076
|
+
return ds;
|
|
2077
|
+
}
|
|
2078
|
+
if (typeof ds === 'object') {
|
|
2079
|
+
for (let prop in ds) {
|
|
2080
|
+
const arr = this._seekArray(ds[prop]);
|
|
2081
|
+
if (!pacemCore.Utils.isNull(arr)) {
|
|
2082
|
+
return arr;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
return null;
|
|
2087
|
+
}
|
|
2088
|
+
_extractMetadataJustInCase(ds = this.datasource) {
|
|
2089
|
+
if ((pacemCore.Utils.isNullOrEmpty(this.datarowMetadata) || this._builtUponDatasource) && !pacemCore.Utils.isNullOrEmpty(ds)) {
|
|
2090
|
+
const arr = this._seekArray(ds);
|
|
2091
|
+
if (!pacemCore.Utils.isNullOrEmpty(arr)) {
|
|
2092
|
+
const props = [];
|
|
2093
|
+
const item = arr[0];
|
|
2094
|
+
for (let prop in item) {
|
|
2095
|
+
props.push({ prop, type: typeof item[prop] });
|
|
2096
|
+
}
|
|
2097
|
+
this.datarowMetadata = props;
|
|
2098
|
+
this._builtUponDatasource = true;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
}
|
|
2102
|
+
};
|
|
2103
|
+
__decorate([
|
|
2104
|
+
pacemCore.Watch({ reflectBack: true, converter: pacemCore.PropertyConverters.Json })
|
|
2105
|
+
], PacemWidgetDataGridElement.prototype, "columns", void 0);
|
|
2106
|
+
__decorate([
|
|
2107
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Json })
|
|
2108
|
+
], PacemWidgetDataGridElement.prototype, "datasource", void 0);
|
|
2109
|
+
__decorate([
|
|
2110
|
+
pacemCore.Watch({ converter: pacemCore.PropertyConverters.Json })
|
|
2111
|
+
], PacemWidgetDataGridElement.prototype, "datarowMetadata", void 0);
|
|
2112
|
+
__decorate([
|
|
2113
|
+
pacemCore.ViewChild(`.${pacemCore.PCSS}-datatable`)
|
|
2114
|
+
], PacemWidgetDataGridElement.prototype, "_datatable", void 0);
|
|
2115
|
+
__decorate([
|
|
2116
|
+
pacemCore.ViewChild('template')
|
|
2117
|
+
], PacemWidgetDataGridElement.prototype, "_template", void 0);
|
|
2118
|
+
__decorate([
|
|
2119
|
+
pacemCore.ViewChild(pacemCore.P + '-repeater')
|
|
2120
|
+
], PacemWidgetDataGridElement.prototype, "_repeater", void 0);
|
|
2121
|
+
PacemWidgetDataGridElement = __decorate([
|
|
2122
|
+
pacemCore.CustomElement({
|
|
2123
|
+
tagName: pacemCore.P + '-widget-datagrid'
|
|
2124
|
+
})
|
|
2125
|
+
], PacemWidgetDataGridElement);
|
|
2126
|
+
|
|
2127
|
+
var index_components = /*#__PURE__*/Object.freeze({
|
|
2128
|
+
__proto__: null,
|
|
2129
|
+
ACCESS_TOKEN_METADATA: ACCESS_TOKEN_METADATA,
|
|
2130
|
+
DATACOLUMNS_METADATA_TYPE: DATACOLUMNS_METADATA_TYPE,
|
|
2131
|
+
DEFAULT_METADATA: DEFAULT_METADATA,
|
|
2132
|
+
EXPRESSION_METADATA_TYPE: EXPRESSION_METADATA_TYPE,
|
|
2133
|
+
EXPRESSION_WIDGET_METADATA_EXTRA: EXPRESSION_WIDGET_METADATA_EXTRA,
|
|
2134
|
+
get ExpressionSource () { return ExpressionSource; },
|
|
2135
|
+
FETCH_CREDENTIALS_METADATA: FETCH_CREDENTIALS_METADATA,
|
|
2136
|
+
Functions: Functions,
|
|
2137
|
+
GRID_COLUMNS: GRID_COLUMNS,
|
|
2138
|
+
LayoutChangeEventName: LayoutChangeEventName,
|
|
2139
|
+
PacemBearerWidgetElement: PacemBearerWidgetElement,
|
|
2140
|
+
PacemCompositeWidgetElement: PacemCompositeWidgetElement,
|
|
2141
|
+
get PacemDataColumnElement () { return PacemDataColumnElement; },
|
|
2142
|
+
get PacemDataColumnsElement () { return PacemDataColumnsElement; },
|
|
2143
|
+
get PacemElementPickerElement () { return PacemElementPickerElement; },
|
|
2144
|
+
PacemElementPickerElementBase: PacemElementPickerElementBase,
|
|
2145
|
+
get PacemExpressionElement () { return PacemExpressionElement; },
|
|
2146
|
+
get PacemGridWidgetElement () { return PacemGridWidgetElement; },
|
|
2147
|
+
PacemUiWidgetElement: PacemUiWidgetElement,
|
|
2148
|
+
get PacemWidgetApiManifestElement () { return PacemWidgetApiManifestElement; },
|
|
2149
|
+
get PacemWidgetClockElement () { return PacemWidgetClockElement; },
|
|
2150
|
+
get PacemWidgetDataElement () { return PacemWidgetDataElement; },
|
|
2151
|
+
get PacemWidgetDataGridElement () { return PacemWidgetDataGridElement; },
|
|
2152
|
+
PacemWidgetElement: PacemWidgetElement,
|
|
2153
|
+
get PacemWidgetFetchElement () { return PacemWidgetFetchElement; },
|
|
2154
|
+
get PacemWidgetFetchParameterElement () { return PacemWidgetFetchParameterElement; },
|
|
2155
|
+
get PacemWidgetPickerElement () { return PacemWidgetPickerElement; },
|
|
2156
|
+
get PacemWidgetTextElement () { return PacemWidgetTextElement; },
|
|
2157
|
+
get PacemWidgetToolbarElement () { return PacemWidgetToolbarElement; },
|
|
2158
|
+
get PacemWidgetTranslatorElement () { return PacemWidgetTranslatorElement; },
|
|
2159
|
+
Widget: Widget,
|
|
2160
|
+
WidgetRegisterEvent: WidgetRegisterEvent,
|
|
2161
|
+
WidgetRegisterEventName: WidgetRegisterEventName,
|
|
2162
|
+
WidgetUnregisterEvent: WidgetUnregisterEvent,
|
|
2163
|
+
WidgetUnregisterEventName: WidgetUnregisterEventName,
|
|
2164
|
+
buildWidgetMetadata: buildWidgetMetadata,
|
|
2165
|
+
gridifyMetadata: gridifyMetadata
|
|
2166
|
+
});
|
|
2167
|
+
|
|
2168
|
+
const PermissionEditEventName = 'permissionedit';
|
|
2169
|
+
class PermissionEditEvent extends CustomEvent {
|
|
2170
|
+
constructor(permissible) {
|
|
2171
|
+
super(PermissionEditEventName, { detail: permissible, cancelable: false, bubbles: true });
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
class Permissible {
|
|
2175
|
+
static canEdit(claims, resource) { return this._canDoSomethingToResource(claims, resource, p => p.update); }
|
|
2176
|
+
static canRead(claims, resource) { return this._canDoSomethingToResource(claims, resource, p => p.read); }
|
|
2177
|
+
static canAdd(claims, resource) { return this._canDoSomethingToResource(claims, resource, p => p.create); }
|
|
2178
|
+
static canDelete(claims, resource) { return this._canDoSomethingToResource(claims, resource, p => p.delete); }
|
|
2179
|
+
static canTranslate(claims, resource) { return this._canDoSomethingToResource(claims, resource, p => p.translate); }
|
|
2180
|
+
static _canDoSomethingToResource(claims, resource, predicate) {
|
|
2181
|
+
if (pacemCore.Utils.isNullOrEmpty(claims) || pacemCore.Utils.isNull(resource)) {
|
|
2182
|
+
return false;
|
|
2183
|
+
}
|
|
2184
|
+
// if no permissions are set, then you're free to go!
|
|
2185
|
+
var editable = true;
|
|
2186
|
+
if (resource.permissions && resource.permissions.length > 0) {
|
|
2187
|
+
// check correspondence otherwise
|
|
2188
|
+
editable = false;
|
|
2189
|
+
for (let permission of resource.permissions) {
|
|
2190
|
+
if (predicate(permission) && claims[permission.claimType] && claims[permission.claimType].indexOf(permission.claimValue) >= 0) {
|
|
2191
|
+
return true;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
// return
|
|
2196
|
+
return editable;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
var index_cms = /*#__PURE__*/Object.freeze({
|
|
2201
|
+
__proto__: null,
|
|
2202
|
+
DATACOLUMNS_METADATA_TYPE: DATACOLUMNS_METADATA_TYPE,
|
|
2203
|
+
OpenApi: swaggerCms,
|
|
2204
|
+
get PacemDataColumnElement () { return PacemDataColumnElement; },
|
|
2205
|
+
get PacemDataColumnsElement () { return PacemDataColumnsElement; },
|
|
2206
|
+
Permissible: Permissible,
|
|
2207
|
+
PermissionEditEvent: PermissionEditEvent,
|
|
2208
|
+
PermissionEditEventName: PermissionEditEventName
|
|
2209
|
+
});
|
|
2210
|
+
|
|
2211
|
+
var Output = /*#__PURE__*/Object.freeze({
|
|
2212
|
+
__proto__: null,
|
|
2213
|
+
Cms: index_cms,
|
|
2214
|
+
Components: index_components
|
|
2215
|
+
});
|
|
2216
|
+
|
|
2217
|
+
pacemFoundation.DeepMerger.merge(Output);
|
|
2218
|
+
|
|
2219
|
+
})(Pacem, Pacem, Pacem, Pacem);
|
|
2220
|
+
//# sourceMappingURL=pacem-cms.js.map
|