@jinntec/fore 1.3.0 → 1.4.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.
Files changed (41) hide show
  1. package/dist/fore-dev.js +4 -4
  2. package/dist/fore-dev.js.map +1 -1
  3. package/dist/fore.js +3 -3
  4. package/dist/fore.js.map +1 -1
  5. package/package.json +1 -1
  6. package/resources/fore.css +6 -1
  7. package/src/ForeElementMixin.js +4 -0
  8. package/src/actions/abstract-action.js +77 -35
  9. package/src/actions/fx-action.js +9 -9
  10. package/src/actions/fx-append.js +1 -1
  11. package/src/actions/fx-confirm.js +1 -1
  12. package/src/actions/fx-copy.js +68 -0
  13. package/src/actions/fx-delete.js +1 -1
  14. package/src/actions/fx-dispatch.js +1 -1
  15. package/src/actions/fx-hide.js +1 -1
  16. package/src/actions/fx-insert.js +1 -1
  17. package/src/actions/fx-message.js +1 -1
  18. package/src/actions/fx-refresh.js +2 -2
  19. package/src/actions/fx-reload.js +1 -1
  20. package/src/actions/fx-replace.js +1 -1
  21. package/src/actions/fx-return.js +1 -1
  22. package/src/actions/fx-send.js +2 -2
  23. package/src/actions/fx-setfocus.js +1 -1
  24. package/src/actions/fx-setvalue.js +1 -1
  25. package/src/actions/fx-show.js +1 -1
  26. package/src/actions/fx-toggle.js +1 -1
  27. package/src/actions/fx-update.js +1 -1
  28. package/src/fore.js +58 -10
  29. package/src/fx-bind.js +5 -0
  30. package/src/fx-fore.js +36 -35
  31. package/src/fx-instance.js +70 -70
  32. package/src/fx-model.js +12 -17
  33. package/src/fx-submission.js +420 -416
  34. package/src/getInScopeContext.js +2 -4
  35. package/src/modelitem.js +3 -1
  36. package/src/ui/abstract-control.js +1 -1
  37. package/src/ui/fx-control.js +2 -2
  38. package/src/ui/fx-switch.js +9 -1
  39. package/src/ui/fx-trigger.js +19 -18
  40. package/src/xpath-evaluation.js +21 -9
  41. package/src/xpath-util.js +13 -28
@@ -52,10 +52,8 @@ function _getInitialContext(node, ref) {
52
52
  }
53
53
  return model.getDefaultInstance().getDefaultContext();
54
54
  }
55
- if (model.getDefaultInstance() !== null && model.inited) {
56
- return model.getDefaultInstance().getDefaultContext();
57
- }
58
- return [];
55
+ // should always return default context if all other fails
56
+ return model.getDefaultInstance().getDefaultContext();
59
57
  }
60
58
 
61
59
  export default function getInScopeContext(node, ref) {
package/src/modelitem.js CHANGED
@@ -67,7 +67,9 @@ export class ModelItem {
67
67
  }
68
68
 
69
69
  addAlert(alert) {
70
- this.alerts.push(alert);
70
+ if(!this.alerts.includes(alert)){
71
+ this.alerts.push(alert);
72
+ }
71
73
  }
72
74
 
73
75
  cleanAlerts() {
@@ -257,7 +257,7 @@ export default class AbstractControl extends foreElementMixin(HTMLElement) {
257
257
  const alert = this.querySelector('fx-alert');
258
258
 
259
259
  const mi = this.getModelItem();
260
- console.log('late modelItem', mi);
260
+ // console.log('late modelItem', mi);
261
261
  if (this.isValid() !== this.modelItem.constraint) {
262
262
  if (this.modelItem.constraint) {
263
263
  // if (alert) alert.style.display = 'none';
@@ -482,7 +482,7 @@ export default class FxControl extends XfAbstractControl {
482
482
  if (nodeset.length) {
483
483
  // console.log('nodeset', nodeset);
484
484
  const fragment = document.createDocumentFragment();
485
- console.time('offscreen');
485
+ // console.time('offscreen');
486
486
  /*
487
487
  Array.from(nodeset).forEach(node => {
488
488
  // console.log('#### node', node);
@@ -504,7 +504,7 @@ export default class FxControl extends XfAbstractControl {
504
504
  this.updateEntry(newEntry, node);
505
505
  });
506
506
  this.template.parentNode.appendChild(fragment);
507
- console.timeEnd('offscreen');
507
+ // console.timeEnd('offscreen');
508
508
  } else {
509
509
  const newEntry = this.createEntry();
510
510
  this.template.parentNode.appendChild(newEntry);
@@ -5,7 +5,6 @@ import { FxContainer } from './fx-container.js';
5
5
  * `fx-switch`
6
6
  * a container allowing to switch between fx-case elements
7
7
  *
8
- * * todo: implement
9
8
  * @customElement
10
9
  */
11
10
  class FxSwitch extends FxContainer {
@@ -45,9 +44,13 @@ class FxSwitch extends FxContainer {
45
44
  Array.from(cases).forEach(caseElem => {
46
45
  const name = caseElem.getAttribute('name');
47
46
  if (name === this.modelItem.value) {
47
+ Fore.dispatch(caseElem,'select',{});
48
48
  caseElem.classList.add('selected-case');
49
49
  selectedCase = caseElem;
50
50
  } else {
51
+ if(caseElem.classList.contains('selected-case')){
52
+ Fore.dispatch(caseElem,'deselect',{});
53
+ }
51
54
  caseElem.classList.remove('selected-case');
52
55
  }
53
56
  });
@@ -56,6 +59,7 @@ class FxSwitch extends FxContainer {
56
59
  // if none is selected select the first as default
57
60
  if (!selectedCase) {
58
61
  selectedCase = cases[0];
62
+ Fore.dispatch(selectedCase,'select',{});
59
63
  selectedCase.classList.add('selected-case');
60
64
  }
61
65
  }
@@ -69,9 +73,13 @@ class FxSwitch extends FxContainer {
69
73
  if (caseElement === c) {
70
74
  // eslint-disable-next-line no-param-reassign
71
75
  c.classList.add('selected-case');
76
+ Fore.dispatch(c,'select',{});
72
77
  this.refresh();
73
78
  } else {
74
79
  // eslint-disable-next-line no-param-reassign
80
+ if(c.classList.contains('selected-case')){
81
+ Fore.dispatch(c,'deselect',{});
82
+ }
75
83
  c.classList.remove('selected-case');
76
84
  }
77
85
  });
@@ -1,5 +1,5 @@
1
1
  import XfAbstractControl from './abstract-control.js';
2
- import {leadingDebounce} from "../events.js";
2
+ import { leadingDebounce } from '../events.js';
3
3
 
4
4
  export class FxTrigger extends XfAbstractControl {
5
5
  connectedCallback() {
@@ -28,14 +28,18 @@ export class FxTrigger extends XfAbstractControl {
28
28
 
29
29
  const element = elements[0];
30
30
 
31
- if(this.debounceDelay){
31
+ if (this.debounceDelay) {
32
32
  this.addEventListener(
33
- 'click',
34
- leadingDebounce(this,(e) => {
35
- this.performActions(e)
36
- }, this.debounceDelay),
33
+ 'click',
34
+ leadingDebounce(
35
+ this,
36
+ e => {
37
+ this.performActions(e);
38
+ },
39
+ this.debounceDelay,
40
+ ),
37
41
  );
38
- }else{
42
+ } else {
39
43
  element.addEventListener('click', e => this.performActions(e));
40
44
  }
41
45
  this.widget = element;
@@ -63,7 +67,7 @@ export class FxTrigger extends XfAbstractControl {
63
67
  }
64
68
 
65
69
  async updateWidgetValue() {
66
- console.log('trigger update', this);
70
+ // console.log('trigger update', this);
67
71
  return null;
68
72
  }
69
73
 
@@ -88,17 +92,14 @@ export class FxTrigger extends XfAbstractControl {
88
92
  // Update all child variables, but only once
89
93
  this.querySelectorAll('fx-var').forEach(variableElement => variableElement.refresh());
90
94
 
91
- const forLoop = async () => {
92
- for (let i = 0; i < this.children.length; i += 1) {
93
- const child = this.children[i];
94
- if (typeof child.execute === 'function') {
95
- // eslint-disable-next-line no-await-in-loop
96
- await child.execute(e);
97
- // child.execute(e);
98
- }
95
+ for (let i = 0; i < this.children.length; i += 1) {
96
+ const child = this.children[i];
97
+ if (typeof child.execute === 'function') {
98
+ // eslint-disable-next-line no-await-in-loop
99
+ await child.execute(e);
100
+ // child.execute(e);
99
101
  }
100
- };
101
- forLoop();
102
+ }
102
103
  }
103
104
 
104
105
  /*
@@ -47,8 +47,21 @@ const xhtmlNamespaceResolver = prefix => {
47
47
  * Resolve an id in scope. Behaves like the algorithm defined on https://www.w3.org/community/xformsusers/wiki/XForms_2.0#idref-resolve
48
48
  */
49
49
  export function resolveId(id, sourceObject, nodeName = null) {
50
- const allMatchingTargetObjects = fxEvaluateXPathToNodes(
51
- 'outermost(ancestor-or-self::fx-fore[1]/(descendant::fx-fore|descendant::*[@id = $id]))[not(self::fx-fore)]',
50
+ let query = 'outermost(ancestor-or-self::fx-fore[1]/(descendant::fx-fore|descendant::*[@id = $id]))[not(self::fx-fore)]';
51
+ /*
52
+ if (nodeName === 'fx-instance') {
53
+ // Instance elements can only be in the `model` element
54
+ // query = 'ancestor-or-self::fx-fore[1]/fx-model/fx-instance[@id = $id]';
55
+
56
+ const fore = Fore.getFore(sourceObject);
57
+ const instances = fore.getModel().instances;
58
+ const targetInstance = instances.find(i => i.id === id);
59
+ return targetInstance;
60
+ return document.getElementById(id);
61
+ }
62
+ */
63
+
64
+ const allMatchingTargetObjects = fxEvaluateXPathToNodes(query,
52
65
  sourceObject,
53
66
  null,
54
67
  {id},
@@ -749,19 +762,18 @@ const instance = (dynamicContext, string) => {
749
762
  {namespaceResolver: xhtmlNamespaceResolver},
750
763
  );
751
764
 
752
- // console.log('fnInstance dynamicContext: ', dynamicContext);
753
- // console.log('fnInstance string: ', string);
765
+ const inst = string
766
+ ? formElement.querySelector(`#${string}`)
767
+ : formElement.querySelector(`fx-instance`);
754
768
 
769
+ /*
755
770
  const inst = string
756
771
  ? resolveId(string, formElement, 'fx-instance')
757
772
  : formElement.querySelector(`fx-instance`);
773
+ */
758
774
 
759
- // const def = instance.getInstanceData();
760
775
  if (inst) {
761
- const def = inst.getDefaultContext();
762
- // console.log('target instance root node: ', def);
763
-
764
- return def;
776
+ return inst.getDefaultContext();
765
777
  }
766
778
  return null;
767
779
  };
package/src/xpath-util.js CHANGED
@@ -1,14 +1,12 @@
1
1
  import * as fx from 'fontoxpath';
2
2
 
3
- /**
4
- * Checks wether the specified path expression is an absolute path.
5
- *
6
- * @param path the path expression.
7
- * @return <code>true</code> if specified path expression is an absolute
8
- * path, otherwise <code>false</code>.
9
- */
10
-
11
3
  export class XPathUtil {
4
+
5
+ /**
6
+ * returns next bound element upwards in tree
7
+ * @param start where to start the search
8
+ * @returns {*|null}
9
+ */
12
10
  static getParentBindingElement(start) {
13
11
  /* if (start.parentNode.host) {
14
12
  const { host } = start.parentNode;
@@ -25,6 +23,13 @@ export class XPathUtil {
25
23
  return null;
26
24
  }
27
25
 
26
+ /**
27
+ * Checks whether the specified path expression is an absolute path.
28
+ *
29
+ * @param path the path expression.
30
+ * @return <code>true</code> if specified path expression is an absolute
31
+ * path, otherwise <code>false</code>.
32
+ */
28
33
  static isAbsolutePath(path) {
29
34
  return path != null && (path.startsWith('/') || path.startsWith('instance('));
30
35
  }
@@ -33,26 +38,6 @@ export class XPathUtil {
33
38
  return ref === '.' || ref === './text()' || ref === 'text()' || ref === '' || ref === null;
34
39
  }
35
40
 
36
- static getDefaultInstance(boundElement) {
37
- // const fore = boundElement.closest('fx-fore');
38
- const fore = XPathUtil.getForeElement(boundElement);
39
- const defaultInstance = fore.querySelector('fx-instance');
40
- if (!defaultInstance) {
41
- throw new Error('no default instance present');
42
- }
43
- return defaultInstance;
44
- }
45
-
46
- static getForeElement(start) {
47
- if (start.nodeName === 'FX-FORE') {
48
- return start;
49
- }
50
- if (start.parentNode) {
51
- return XPathUtil.getForeElement(start.parentNode);
52
- }
53
- throw new Error('no Fore element present');
54
- }
55
-
56
41
  /**
57
42
  * returns the instance id from a complete XPath using `instance()` function.
58
43
  *