@jinntec/fore 1.10.2 → 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/src/ui/fx-case.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // import { foreElementMixin } from '../ForeElementMixin';
2
2
 
3
+ import {FxContainer} from "./fx-container.js";
4
+
3
5
  /**
4
6
  * `fx-case`
5
7
  * a container allowing to switch between fx-case elements
@@ -7,11 +9,12 @@
7
9
  * * todo: implement
8
10
  * @customElement
9
11
  */
10
- class FxCase extends HTMLElement {
12
+ class FxCase extends FxContainer {
13
+ /*
11
14
  constructor() {
12
15
  super();
13
- this.attachShadow({ mode: 'open' });
14
16
  }
17
+ */
15
18
 
16
19
  connectedCallback() {
17
20
  if (this.hasAttribute('label')) {
@@ -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;
@@ -42,7 +54,6 @@ export class FxContainer extends foreElementMixin(HTMLElement) {
42
54
  } );
43
55
  */
44
56
 
45
- this.setAttribute('tabindex','0');
46
57
  }
47
58
 
48
59
  /**
@@ -52,6 +63,16 @@ export class FxContainer extends foreElementMixin(HTMLElement) {
52
63
  if (!force && this.hasAttribute('refresh-on-view')) return;
53
64
  // console.log('### FxContainer.refresh on : ', this);
54
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
+ */
55
76
  if (this.isBound()) {
56
77
  this.evalInContext();
57
78
  this.modelItem = this.getModelItem();
@@ -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.url = this.hasAttribute('url') ? this.getAttribute('url') : null;
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 url Fore is used as widget and will be loaded from external file
378
- if (this.url && !this.loaded && this.modelItem.relevant) {
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 Url
387
- await this._loadForeFromUrl();
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 `url` attribute and embed it as child of this control.
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 _loadForeFromUrl() {
414
+ async _loadForeFromSrc() {
419
415
  console.info(
420
- `%cFore is processing URL ${this.url}`,
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.url, {
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
- defaultInst.setInstanceData(doc);
456
+ defaultInst.instanceData = doc;
461
457
  }
462
- imported.getModel().updateModel();
463
- imported.refresh();
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
- this.dispatchEvent(
483
- new CustomEvent('error', {
484
- detail: {
485
- message: `Fore element not found in '${this.src}'. Maybe wrapped within 'template' element?`,
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
- this.dispatchEvent(new CustomEvent('loaded', {detail: {fore: theFore}}));
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 url '${this.url}'`,
496
- expr:xpath,
490
+ message: `control couldn't be loaded from src '${this.src}'`,
497
491
  level:'Error'
498
492
  });
499
493
 
@@ -86,19 +86,23 @@ export class FxInspector extends HTMLElement {
86
86
 
87
87
  update() {
88
88
  // console.log('update');
89
- const pre = this.shadowRoot.querySelectorAll('pre');
90
- // console.log('pre', pre);
91
- const fore = this.closest('fx-fore');
89
+ try{
90
+ const pre = this.shadowRoot.querySelectorAll('pre');
91
+ // console.log('pre', pre);
92
+ const fore = this.closest('fx-fore');
92
93
 
93
- Array.from(pre).forEach(element => {
94
- const inst = fore.getModel().getInstance(element.getAttribute('id'));
95
- if (inst.getAttribute('type') === 'xml') {
96
- element.innerText = this.serializeDOM(inst.instanceData);
97
- }
98
- if (inst.getAttribute('type') === 'json') {
99
- element.innerText = JSON.stringify(inst.instanceData, undefined, 2);
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) {
@@ -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
- this.getOwnerForm().someInstanceDataStructureChanged = true;
282
+ // Tell the owner form we might have new template expressions here
283
+ this.getOwnerForm().scanForNewTemplateExpressionsNextRefresh();
283
284
  }
284
285
  }
285
286
 
@@ -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
 
@@ -444,11 +444,10 @@ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, o
444
444
  */
445
445
  export function evaluateXPath(xpath, contextNode, formElement, variables = {}, options={}) {
446
446
  try{
447
- console.log('evaluateXPath',xpath);
448
447
  const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
449
448
  const variablesInScope = getVariablesInScope(formElement);
450
449
 
451
- return fxEvaluateXPath(
450
+ const result = fxEvaluateXPath(
452
451
  xpath,
453
452
  contextNode,
454
453
  null,
@@ -465,6 +464,8 @@ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, o
465
464
  language: options.language || evaluateXPath.XPATH_3_1
466
465
  },
467
466
  );
467
+ // console.log('evaluateXPath',xpath, result);
468
+ return result;
468
469
  }catch (e){
469
470
  formElement.dispatchEvent(new CustomEvent('error', {
470
471
  composed: false,
@@ -506,7 +507,7 @@ export function evaluateXPathToFirstNode(xpath, contextNode, formElement) {
506
507
  try{
507
508
  const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
508
509
  const variablesInScope = getVariablesInScope(formElement);
509
- return fxEvaluateXPathToFirstNode(xpath, contextNode, null, variablesInScope, {
510
+ const result = fxEvaluateXPathToFirstNode(xpath, contextNode, null, variablesInScope, {
510
511
  defaultFunctionNamespaceURI: XFORMS_NAMESPACE_URI,
511
512
  moduleImports: {
512
513
  xf: XFORMS_NAMESPACE_URI,
@@ -515,6 +516,8 @@ export function evaluateXPathToFirstNode(xpath, contextNode, formElement) {
515
516
  functionNameResolver,
516
517
  namespaceResolver,
517
518
  });
519
+ // console.log('evaluateXPathToFirstNode',xpath, result);
520
+ return result;
518
521
  } catch (e){
519
522
  formElement.dispatchEvent(new CustomEvent('error', {
520
523
  composed: false,
@@ -542,7 +545,7 @@ export function evaluateXPathToNodes(xpath, contextNode, formElement) {
542
545
  const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
543
546
  const variablesInScope = getVariablesInScope(formElement);
544
547
 
545
- return fxEvaluateXPathToNodes(xpath, contextNode, null, variablesInScope, {
548
+ const result = fxEvaluateXPathToNodes(xpath, contextNode, null, variablesInScope, {
546
549
  currentContext: {formElement},
547
550
  functionNameResolver,
548
551
  moduleImports: {
@@ -550,6 +553,8 @@ export function evaluateXPathToNodes(xpath, contextNode, formElement) {
550
553
  },
551
554
  namespaceResolver,
552
555
  });
556
+ // console.log('evaluateXPathToNodes',xpath, result);
557
+ return result;
553
558
  }catch (e){
554
559
  formElement.dispatchEvent(new CustomEvent('error', {
555
560
  composed: false,