@jinntec/fore 1.10.3 → 2.0.0
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/dist/fore-dev.js +2 -2
- package/dist/fore-dev.js.map +1 -1
- package/dist/fore.js +2 -2
- package/dist/fore.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/abstract-action.js +1 -1
- package/src/actions/fx-load.js +3 -35
- package/src/actions/fx-refresh.js +3 -0
- package/src/actions/fx-toggle.js +1 -1
- package/src/fore.js +77 -2
- package/src/fx-fore.js +68 -65
- package/src/fx-instance.js +1 -0
- package/src/fx-model.js +32 -10
- package/src/fx-submission.js +1 -1
- package/src/getInScopeContext.js +0 -4
- package/src/ui/fx-case.js +5 -2
- package/src/ui/fx-container.js +22 -0
- package/src/ui/fx-control.js +25 -31
- package/src/ui/fx-inspector.js +16 -12
- package/src/ui/fx-repeat.js +2 -1
- package/src/ui/fx-switch.js +7 -2
package/src/ui/fx-container.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import '../fx-model.js';
|
|
2
2
|
import { foreElementMixin } from '../ForeElementMixin.js';
|
|
3
|
+
import {Fore} from "../fore.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* `fx-container` -
|
|
@@ -7,12 +8,23 @@ import { foreElementMixin } from '../ForeElementMixin.js';
|
|
|
7
8
|
*
|
|
8
9
|
*/
|
|
9
10
|
export class FxContainer extends foreElementMixin(HTMLElement) {
|
|
11
|
+
static get properties() {
|
|
12
|
+
return {
|
|
13
|
+
...super.properties,
|
|
14
|
+
/*
|
|
15
|
+
src: {
|
|
16
|
+
type: String,
|
|
17
|
+
},
|
|
18
|
+
*/
|
|
19
|
+
};
|
|
20
|
+
}
|
|
10
21
|
constructor() {
|
|
11
22
|
super();
|
|
12
23
|
this.attachShadow({ mode: 'open' });
|
|
13
24
|
}
|
|
14
25
|
|
|
15
26
|
connectedCallback() {
|
|
27
|
+
this.src = this.hasAttribute('src') ? this.getAttribute('src'):null;
|
|
16
28
|
const style = `
|
|
17
29
|
:host {
|
|
18
30
|
display: block;
|
|
@@ -51,6 +63,16 @@ export class FxContainer extends foreElementMixin(HTMLElement) {
|
|
|
51
63
|
if (!force && this.hasAttribute('refresh-on-view')) return;
|
|
52
64
|
// console.log('### FxContainer.refresh on : ', this);
|
|
53
65
|
|
|
66
|
+
// if loading from 'src' needs to be done do it now
|
|
67
|
+
/*
|
|
68
|
+
if(this.src){
|
|
69
|
+
await Fore.loadForeFromSrc(this,this.src,'fx-group')
|
|
70
|
+
.then(foreElement =>{
|
|
71
|
+
this.getOwnerForm().registerLazyElement(foreElement);
|
|
72
|
+
foreElement.refresh();
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
*/
|
|
54
76
|
if (this.isBound()) {
|
|
55
77
|
this.evalInContext();
|
|
56
78
|
this.modelItem = this.getModelItem();
|
package/src/ui/fx-control.js
CHANGED
|
@@ -48,6 +48,9 @@ export default class FxControl extends XfAbstractControl {
|
|
|
48
48
|
},
|
|
49
49
|
initial: {
|
|
50
50
|
type: Boolean
|
|
51
|
+
},
|
|
52
|
+
src:{
|
|
53
|
+
type: String
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
}
|
|
@@ -62,7 +65,7 @@ export default class FxControl extends XfAbstractControl {
|
|
|
62
65
|
|
|
63
66
|
connectedCallback() {
|
|
64
67
|
this.initial = this.hasAttribute('initial') ? this.getAttribute('initial') : null;
|
|
65
|
-
this.
|
|
68
|
+
this.src = this.hasAttribute('src') ? this.getAttribute('src') : null;
|
|
66
69
|
this.loaded = false;
|
|
67
70
|
this.initialNode = null;
|
|
68
71
|
this.debounceDelay = this.hasAttribute('debounce') ? this.getAttribute('debounce') : null;
|
|
@@ -263,7 +266,7 @@ export default class FxControl extends XfAbstractControl {
|
|
|
263
266
|
} else (
|
|
264
267
|
Fore.dispatch(this, "warn", {'message': 'trying to replace a node that is neither an Attribute, Elemment or Text node'})
|
|
265
268
|
)
|
|
266
|
-
this.getOwnerForm().refresh();
|
|
269
|
+
// this.getOwnerForm().refresh();
|
|
267
270
|
}
|
|
268
271
|
|
|
269
272
|
renderHTML(ref) {
|
|
@@ -374,8 +377,8 @@ export default class FxControl extends XfAbstractControl {
|
|
|
374
377
|
return;
|
|
375
378
|
}
|
|
376
379
|
|
|
377
|
-
// ### when there's a
|
|
378
|
-
if (this.
|
|
380
|
+
// ### when there's a src Fore is used as widget and will be loaded from external file
|
|
381
|
+
if (this.src && !this.loaded && this.modelItem.relevant) {
|
|
379
382
|
// ### evaluate initial data if necessary
|
|
380
383
|
|
|
381
384
|
if (this.initial) {
|
|
@@ -383,8 +386,8 @@ export default class FxControl extends XfAbstractControl {
|
|
|
383
386
|
// console.log('initialNodes', this.initialNode);
|
|
384
387
|
}
|
|
385
388
|
|
|
386
|
-
// ### load the markup from
|
|
387
|
-
await this.
|
|
389
|
+
// ### load the markup from src
|
|
390
|
+
await this._loadForeFromSrc();
|
|
388
391
|
this.loaded = true;
|
|
389
392
|
|
|
390
393
|
// ### replace default instance of embedded Fore with initial nodes
|
|
@@ -393,20 +396,13 @@ export default class FxControl extends XfAbstractControl {
|
|
|
393
396
|
return;
|
|
394
397
|
}
|
|
395
398
|
|
|
396
|
-
/*
|
|
397
|
-
if(this.url && !this.loaded){
|
|
398
|
-
this._loadForeFromUrl();
|
|
399
|
-
this.loaded=true;
|
|
400
|
-
return;
|
|
401
|
-
}
|
|
402
|
-
*/
|
|
403
399
|
if (widget.value !== this.value) {
|
|
404
400
|
widget.value = this.value;
|
|
405
401
|
}
|
|
406
402
|
}
|
|
407
403
|
|
|
408
404
|
/**
|
|
409
|
-
* loads an external Fore from an HTML file given by `
|
|
405
|
+
* loads an external Fore from an HTML file given by `src` attribute and embed it as child of this control.
|
|
410
406
|
*
|
|
411
407
|
* Will look for the `<fx-fore>` element within the returned HTML file and return that element.
|
|
412
408
|
*
|
|
@@ -415,13 +411,13 @@ export default class FxControl extends XfAbstractControl {
|
|
|
415
411
|
* todo: dispatch link error
|
|
416
412
|
* @private
|
|
417
413
|
*/
|
|
418
|
-
async
|
|
414
|
+
async _loadForeFromSrc() {
|
|
419
415
|
console.info(
|
|
420
|
-
`%
|
|
416
|
+
`%cControl ref="${this.ref}" is loading ${this.src}`,
|
|
421
417
|
"background:#64b5f6; color:white; padding:0.5rem; display:inline-block; white-space: nowrap; border-radius:0.3rem;width:100%;",
|
|
422
418
|
);
|
|
423
419
|
try {
|
|
424
|
-
const response = await fetch(this.
|
|
420
|
+
const response = await fetch(this.src, {
|
|
425
421
|
method: 'GET',
|
|
426
422
|
credentials: this.credentials,
|
|
427
423
|
mode: 'cors',
|
|
@@ -457,10 +453,12 @@ export default class FxControl extends XfAbstractControl {
|
|
|
457
453
|
this.initialNode = evaluateXPathToFirstNode(this.initial, this.nodeset, this);
|
|
458
454
|
|
|
459
455
|
doc.firstElementChild.appendChild(this.initialNode.cloneNode(true));
|
|
460
|
-
|
|
456
|
+
defaultInst.instanceData = doc;
|
|
461
457
|
}
|
|
462
|
-
|
|
463
|
-
|
|
458
|
+
imported.model = imported.querySelector('fx-model');
|
|
459
|
+
imported.model.updateModel();
|
|
460
|
+
|
|
461
|
+
imported.refresh(true);
|
|
464
462
|
},
|
|
465
463
|
{once: true},
|
|
466
464
|
);
|
|
@@ -477,23 +475,19 @@ export default class FxControl extends XfAbstractControl {
|
|
|
477
475
|
dummy.replaceWith(imported);
|
|
478
476
|
}
|
|
479
477
|
|
|
480
|
-
|
|
481
478
|
if (!theFore) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}),
|
|
488
|
-
);
|
|
479
|
+
Fore.dispatch('error', {
|
|
480
|
+
detail: {
|
|
481
|
+
message: `Fore element not found in '${this.src}'. Maybe wrapped within 'template' element?`,
|
|
482
|
+
}
|
|
483
|
+
});
|
|
489
484
|
}
|
|
490
|
-
|
|
485
|
+
Fore.dispatch('loaded', {detail: {fore: theFore}});
|
|
491
486
|
} catch (error) {
|
|
492
487
|
// console.log('error', error);
|
|
493
488
|
Fore.dispatch(this, 'error', {
|
|
494
489
|
origin: this,
|
|
495
|
-
message: `control couldn't be loaded from
|
|
496
|
-
expr:xpath,
|
|
490
|
+
message: `control couldn't be loaded from src '${this.src}'`,
|
|
497
491
|
level:'Error'
|
|
498
492
|
});
|
|
499
493
|
|
package/src/ui/fx-inspector.js
CHANGED
|
@@ -86,19 +86,23 @@ export class FxInspector extends HTMLElement {
|
|
|
86
86
|
|
|
87
87
|
update() {
|
|
88
88
|
// console.log('update');
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
try{
|
|
90
|
+
const pre = this.shadowRoot.querySelectorAll('pre');
|
|
91
|
+
// console.log('pre', pre);
|
|
92
|
+
const fore = this.closest('fx-fore');
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
Array.from(pre).forEach(element => {
|
|
95
|
+
const inst = fore.getModel().getInstance(element.getAttribute('id'));
|
|
96
|
+
if (inst.getAttribute('type') === 'xml') {
|
|
97
|
+
element.innerText = this.serializeDOM(inst.instanceData);
|
|
98
|
+
}
|
|
99
|
+
if (inst.getAttribute('type') === 'json') {
|
|
100
|
+
element.innerText = JSON.stringify(inst.instanceData, undefined, 2);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}catch (e){
|
|
104
|
+
console.warn('caught problem in inspector', e.message);
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
render(style) {
|
package/src/ui/fx-repeat.js
CHANGED
|
@@ -279,7 +279,8 @@ export class FxRepeat extends foreElementMixin(HTMLElement) {
|
|
|
279
279
|
|
|
280
280
|
newItem.nodeset = this.nodeset[position - 1];
|
|
281
281
|
newItem.index = position;
|
|
282
|
-
|
|
282
|
+
// Tell the owner form we might have new template expressions here
|
|
283
|
+
this.getOwnerForm().scanForNewTemplateExpressionsNextRefresh();
|
|
283
284
|
}
|
|
284
285
|
}
|
|
285
286
|
|
package/src/ui/fx-switch.js
CHANGED
|
@@ -42,10 +42,12 @@ class FxSwitch extends FxContainer {
|
|
|
42
42
|
`;
|
|
43
43
|
this.cases = [];
|
|
44
44
|
this.formerCase=null;
|
|
45
|
+
this.selectedCase = null;
|
|
46
|
+
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
async refresh(force) {
|
|
48
|
-
super.refresh();
|
|
50
|
+
super.refresh(force);
|
|
49
51
|
// console.log('refresh on switch ');
|
|
50
52
|
if(this.cases.length === 0){
|
|
51
53
|
this.cases = Array.from(this.querySelectorAll(':scope > fx-case'));
|
|
@@ -98,7 +100,6 @@ class FxSwitch extends FxContainer {
|
|
|
98
100
|
* @param caseElement the fx-case element to activate
|
|
99
101
|
*/
|
|
100
102
|
toggle(caseElement) {
|
|
101
|
-
this.formerCase = this.selectedCase;
|
|
102
103
|
this.selectedCase = caseElement;
|
|
103
104
|
Array.from(this.cases).forEach(c => {
|
|
104
105
|
if (c === this.selectedCase) {
|
|
@@ -117,6 +118,10 @@ class FxSwitch extends FxContainer {
|
|
|
117
118
|
this.selectedCase = caseElement;
|
|
118
119
|
}
|
|
119
120
|
this._dispatchEvents();
|
|
121
|
+
this.formerCase = this.selectedCase;
|
|
122
|
+
|
|
123
|
+
// Tell the owner form we might have new template expressions here
|
|
124
|
+
this.getOwnerForm().scanForNewTemplateExpressionsNextRefresh();
|
|
120
125
|
}
|
|
121
126
|
}
|
|
122
127
|
|