@jinntec/fore 1.0.0-4 → 1.1.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 (66) hide show
  1. package/README.md +26 -38
  2. package/dist/fore-dev.js +43 -0
  3. package/dist/fore-dev.js.map +1 -0
  4. package/dist/fore.js +37 -0
  5. package/dist/fore.js.map +1 -0
  6. package/index.js +4 -0
  7. package/package.json +42 -42
  8. package/resources/fore.css +186 -0
  9. package/resources/toastify.css +87 -0
  10. package/resources/{fore-styles.css → vars.css} +0 -292
  11. package/src/DependencyNotifyingDomFacade.js +10 -16
  12. package/src/ForeElementMixin.js +26 -19
  13. package/src/actions/abstract-action.js +30 -9
  14. package/src/actions/fx-action.js +6 -4
  15. package/src/actions/fx-append.js +8 -17
  16. package/src/actions/fx-confirm.js +5 -3
  17. package/src/actions/fx-delete.js +6 -3
  18. package/src/actions/fx-dispatch.js +9 -8
  19. package/src/actions/fx-hide.js +10 -6
  20. package/src/actions/fx-insert.js +49 -39
  21. package/src/actions/fx-message.js +3 -1
  22. package/src/actions/fx-refresh.js +15 -1
  23. package/src/actions/fx-replace.js +73 -0
  24. package/src/actions/fx-return.js +42 -0
  25. package/src/actions/fx-send.js +3 -1
  26. package/src/actions/fx-setfocus.js +37 -0
  27. package/src/actions/fx-setvalue.js +58 -51
  28. package/src/actions/fx-show.js +12 -4
  29. package/src/actions/fx-toggle.js +15 -10
  30. package/src/actions/fx-update.js +3 -1
  31. package/src/dep_graph.js +4 -2
  32. package/src/drawdown.js +67 -82
  33. package/src/fore.js +158 -12
  34. package/src/functions/fx-function.js +17 -3
  35. package/src/fx-bind.js +42 -202
  36. package/src/fx-fore.js +599 -567
  37. package/src/fx-header.js +3 -1
  38. package/src/fx-instance.js +9 -1
  39. package/src/fx-model.js +59 -23
  40. package/src/fx-submission.js +106 -48
  41. package/src/fx-var.js +7 -4
  42. package/src/getInScopeContext.js +37 -11
  43. package/src/modelitem.js +4 -4
  44. package/src/relevance.js +64 -0
  45. package/src/ui/abstract-control.js +64 -37
  46. package/src/ui/fx-alert.js +7 -1
  47. package/src/ui/fx-case.js +4 -3
  48. package/src/ui/fx-container.js +7 -1
  49. package/src/ui/fx-control.js +309 -34
  50. package/src/ui/fx-dialog.js +54 -40
  51. package/src/ui/fx-group.js +3 -1
  52. package/src/ui/fx-hint.js +4 -1
  53. package/src/ui/fx-inspector.js +120 -17
  54. package/src/ui/fx-items.js +8 -8
  55. package/src/ui/fx-output.js +16 -5
  56. package/src/ui/fx-repeat.js +33 -41
  57. package/src/ui/fx-repeatitem.js +10 -4
  58. package/src/ui/fx-switch.js +5 -3
  59. package/src/ui/fx-trigger.js +3 -1
  60. package/src/xpath-evaluation.js +621 -576
  61. package/src/xpath-util.js +15 -8
  62. package/dist/fore-all.js +0 -140
  63. package/dist/fore-debug.js +0 -140
  64. package/src/.DS_Store +0 -0
  65. package/src/actions/.DS_Store +0 -0
  66. package/src/ui/.DS_Store +0 -0
@@ -45,21 +45,14 @@ export class DependencyNotifyingDomFacade {
45
45
  * @param bucket - The bucket that matches the attribute that will be used.
46
46
  */
47
47
  // eslint-disable-next-line class-methods-use-this
48
- /*
49
48
  getChildNodes(node, bucket) {
50
49
  const matchingNodes = Array.from(node.childNodes).filter(
51
50
  childNode => !bucket || getBucketsForNode(childNode).includes(bucket),
52
51
  );
53
- return matchingNodes;
54
- }
55
- */
56
-
57
- getChildNodes(node, bucket) {
58
- const matchingNodes = Array.from(node.childNodes).filter(
59
- childNode => !bucket || getBucketsForNode(childNode).includes(bucket));
60
52
  matchingNodes.forEach(matchingNode => this._onNodeTouched(matchingNode));
61
53
  return matchingNodes;
62
54
  }
55
+
63
56
  /**
64
57
  * Get the data of this node.
65
58
  *
@@ -83,11 +76,11 @@ export class DependencyNotifyingDomFacade {
83
76
  * @param bucket - The bucket that matches the attribute that will be used.
84
77
  */
85
78
  getFirstChild(node, bucket) {
86
- const matchingNode = Array.from(this.getChildNodes()).filter(
87
- childNode => !bucket || getBucketsForNode(childNode).includes(bucket),
88
- )[0];
89
- if (matchingNode) {
90
- return matchingNode;
79
+ for (const child of node.childNodes) {
80
+ if (!bucket || getBucketsForNode(child).includes(bucket)) {
81
+ this._onNodeTouched(child);
82
+ return child;
83
+ }
91
84
  }
92
85
  return null;
93
86
  }
@@ -120,12 +113,13 @@ export class DependencyNotifyingDomFacade {
120
113
  */
121
114
  // eslint-disable-next-line class-methods-use-this
122
115
  getNextSibling(node, bucket) {
123
- for (let { nextSibling } = node; nextSibling; nextSibling = nextSibling.nextSibling) {
124
- if (!getBucketsForNode(nextSibling).includes(bucket)) {
116
+ for (let sibling = node.nextSibling; sibling; sibling = sibling.nextSibling) {
117
+ if (!getBucketsForNode(sibling).includes(bucket)) {
125
118
  // eslint-disable-next-line no-continue
126
119
  continue;
127
120
  }
128
- return nextSibling;
121
+ this._onNodeTouched(sibling);
122
+ return sibling;
129
123
  }
130
124
  return null;
131
125
  }
@@ -1,5 +1,6 @@
1
1
  import { XPathUtil } from './xpath-util.js';
2
2
  import { FxModel } from './fx-model.js';
3
+ import { Fore } from './fore.js';
3
4
  import {
4
5
  evaluateXPath,
5
6
  evaluateXPathToFirstNode,
@@ -7,6 +8,11 @@ import {
7
8
  } from './xpath-evaluation.js';
8
9
  import getInScopeContext from './getInScopeContext.js';
9
10
 
11
+ /**
12
+ * Mixin containing all general functions that are shared by all Fore element classes.
13
+ * @param superclass
14
+ * @returns {{readonly properties: {ref: {type: StringConstructor}, context: {type: ObjectConstructor}, nodeset: {type: ObjectConstructor}, model: {type: ObjectConstructor}, inScopeVariables: {type: MapConstructor}, modelItem: {type: ObjectConstructor}}, new(): ForeElementMixin, context: null, model: null, modelItem: {}, ref: *|string, inScopeVariables: null, nodeset: *, prototype: ForeElementMixin}}
15
+ */
10
16
  export const foreElementMixin = superclass =>
11
17
  class ForeElementMixin extends superclass {
12
18
  static get properties() {
@@ -94,10 +100,21 @@ export const foreElementMixin = superclass =>
94
100
  */
95
101
  evalInContext() {
96
102
  // const inscopeContext = this.getInScopeContext();
97
- const inscopeContext = getInScopeContext(this.getAttributeNode('ref') || this, this.ref);
98
- if (!inscopeContext) {
99
- console.warn('no in scopeContext for ', this);
100
- return;
103
+ let inscopeContext;
104
+ if (this.hasAttribute('context')) {
105
+ inscopeContext = getInScopeContext(this.getAttributeNode('context') || this, this.context);
106
+ }
107
+ if (this.hasAttribute('ref')) {
108
+ inscopeContext = getInScopeContext(this.getAttributeNode('ref') || this, this.ref);
109
+ }
110
+ if (!inscopeContext && this.getModel().instances.length !== 0) {
111
+ // ### always fall back to default context with there's neither a 'context' or 'ref' present
112
+ inscopeContext = this.getModel()
113
+ .getDefaultInstance()
114
+ .getDefaultContext();
115
+ // console.warn('no in scopeContext for ', this);
116
+ // console.warn('using default context ', this);
117
+ // return;
101
118
  }
102
119
  if (this.ref === '') {
103
120
  this.nodeset = inscopeContext;
@@ -120,7 +137,7 @@ export const foreElementMixin = superclass =>
120
137
  if (nodeType) {
121
138
  this.nodeset = evaluateXPathToFirstNode(this.ref, inscopeContext, this);
122
139
  } else {
123
- this.nodeset = evaluateXPath(this.ref, inscopeContext, this);
140
+ [this.nodeset] = evaluateXPath(this.ref, inscopeContext, this);
124
141
  }
125
142
  }
126
143
  // console.log('UiElement evaluated to nodeset: ', this.nodeset);
@@ -139,7 +156,7 @@ export const foreElementMixin = superclass =>
139
156
  return this.getAttribute('ref');
140
157
  }
141
158
  // try to get closest parent bind
142
- const parent = this.parentNode.closest('[ref]');
159
+ const parent = Fore.getClosest('[ref]', this.parentNode);
143
160
  if (!parent) {
144
161
  return 'instance()'; // the default instance
145
162
  }
@@ -178,10 +195,10 @@ export const foreElementMixin = superclass =>
178
195
  this.modelItem = mi;
179
196
  }
180
197
 
181
- const repeated = this.closest('fx-repeatitem');
198
+ const repeated = Fore.getClosest('fx-repeatitem', this);
182
199
  let existed;
183
200
  if (repeated) {
184
- const { index } = this.closest('fx-repeatitem');
201
+ const { index } = repeated;
185
202
  if (Array.isArray(this.nodeset)) {
186
203
  existed = this.getModel().getModelItem(this.nodeset[index - 1]);
187
204
  } else {
@@ -211,7 +228,7 @@ export const foreElementMixin = superclass =>
211
228
  return evaluateXPathToString(valAttr, inscopeContext, this.getOwnerForm());
212
229
  } catch (error) {
213
230
  console.error(error);
214
- this.dispatch('error', { message: error });
231
+ Fore.dispatch(this, 'error', { message: error });
215
232
  }
216
233
  }
217
234
  if (this.textContent) {
@@ -227,14 +244,4 @@ export const foreElementMixin = superclass =>
227
244
  setInScopeVariables(inScopeVariables) {
228
245
  this.inScopeVariables = inScopeVariables;
229
246
  }
230
-
231
- dispatch(eventName, detail) {
232
- const event = new CustomEvent(eventName, {
233
- composed: true,
234
- bubbles: true,
235
- detail,
236
- });
237
- // console.log('firing', event);
238
- this.dispatchEvent(event);
239
- }
240
247
  };
@@ -1,5 +1,7 @@
1
1
  import { foreElementMixin } from '../ForeElementMixin.js';
2
- import { evaluateXPathToBoolean } from '../xpath-evaluation.js';
2
+ import { evaluateXPathToBoolean, resolveId } from '../xpath-evaluation.js';
3
+ import getInScopeContext from '../getInScopeContext.js';
4
+ import { Fore } from '../fore.js';
3
5
 
4
6
  async function wait(howLong) {
5
7
  return new Promise(resolve => setTimeout(() => resolve(), howLong));
@@ -86,7 +88,7 @@ export class AbstractAction extends foreElementMixin(HTMLElement) {
86
88
  } else if (this.target === '#document') {
87
89
  document.addEventListener(this.event, e => this.execute(e));
88
90
  } else {
89
- this.targetElement = document.getElementById(this.target);
91
+ this.targetElement = resolveId(this.target, this);
90
92
  this.targetElement.addEventListener(this.event, e => this.execute(e));
91
93
  }
92
94
  } else {
@@ -112,9 +114,25 @@ export class AbstractAction extends foreElementMixin(HTMLElement) {
112
114
  * @param e
113
115
  */
114
116
  async execute(e) {
115
- console.log('executing', this);
117
+ // console.log('executing', this);
118
+ // console.log('executing e', e);
119
+ // console.log('executing e phase', e.eventPhase);
120
+ if(e && e.code){
121
+ const vars = new Map();
122
+ vars.set('code',e.code);
123
+ this.setInScopeVariables(vars);
124
+ }
125
+
116
126
  if (e && e.detail) {
117
127
  this.detail = e.detail;
128
+ const vars = new Map();
129
+ Object.keys(e.detail).forEach(function(key,index) {
130
+ // key: the name of the object key
131
+ // index: the ordinal position of the key within the object
132
+ vars.set(key,e.detail[key]);
133
+ });
134
+ console.log("event detail vars", vars);
135
+ this.setInScopeVariables(vars);
118
136
  }
119
137
  this.needsUpdate = false;
120
138
 
@@ -124,7 +142,7 @@ export class AbstractAction extends foreElementMixin(HTMLElement) {
124
142
  }
125
143
 
126
144
  // First check if 'if' condition is true - otherwise exist right away
127
- if (this.ifExpr && !evaluateXPathToBoolean(this.ifExpr, this.nodeset, this)) {
145
+ if (this.ifExpr && !evaluateXPathToBoolean(this.ifExpr, getInScopeContext(this), this)) {
128
146
  return;
129
147
  }
130
148
 
@@ -139,7 +157,7 @@ export class AbstractAction extends foreElementMixin(HTMLElement) {
139
157
  return;
140
158
  }
141
159
 
142
- if (!evaluateXPathToBoolean(this.whileExpr, this.nodeset, this)) {
160
+ if (!evaluateXPathToBoolean(this.whileExpr, getInScopeContext(this), this)) {
143
161
  // Done with iterating
144
162
  return;
145
163
  }
@@ -198,13 +216,16 @@ export class AbstractAction extends foreElementMixin(HTMLElement) {
198
216
  }
199
217
 
200
218
  /**
219
+ * dispathes action-performed event
220
+ *
221
+ * @event action-performed - whenever an action has been run
201
222
  */
202
223
  dispatchActionPerformed() {
203
224
  console.log('action-performed ', this);
204
- this.dispatchEvent(
205
- new CustomEvent('action-performed', { composed: true, bubbles: true, detail: {} }),
206
- );
225
+ Fore.dispatch(this, 'action-performed', {});
207
226
  }
208
227
  }
209
228
 
210
- window.customElements.define('abstract-action', AbstractAction);
229
+ if (!customElements.get('abstract-action')) {
230
+ window.customElements.define('abstract-action', AbstractAction);
231
+ }
@@ -47,13 +47,15 @@ export class FxAction extends AbstractAction {
47
47
  }
48
48
  const action = actionOrVar;
49
49
  action.detail = this.detail;
50
- // action.perform();
51
- action.execute();
50
+ action.perform();
51
+ // action.execute();
52
52
  });
53
53
  this.dispatchActionPerformed();
54
- // this.needsUpdate = false;
54
+ this.needsUpdate = true;
55
55
  }
56
56
  }
57
57
  }
58
58
 
59
- window.customElements.define('fx-action', FxAction);
59
+ if (!customElements.get('fx-action')) {
60
+ window.customElements.define('fx-action', FxAction);
61
+ }
@@ -1,5 +1,6 @@
1
1
  import { AbstractAction } from './abstract-action.js';
2
2
  import { Fore } from '../fore.js';
3
+ import { resolveId } from '../xpath-evaluation.js';
3
4
 
4
5
  /**
5
6
  * `fx-append` appends an entry to a repeat.
@@ -77,7 +78,7 @@ class FxAppend extends AbstractAction {
77
78
  super.actionPerformed();
78
79
  // const repeat = document.getElementById(this.repeat);
79
80
  // repeat.setIndex(repeat.nodeset.length);
80
- this.dispatch();
81
+ this._dispatch();
81
82
  }
82
83
 
83
84
  /**
@@ -117,22 +118,10 @@ class FxAppend extends AbstractAction {
117
118
  *
118
119
  * The target repeat is a child of the same repeat-item as the append action.
119
120
  */
120
- dispatch() {
121
- let targetRepeat;
122
- if (Fore.isRepeated(this)) {
123
- console.log('append repeated ', this.repeatContext);
124
- targetRepeat = Fore.getRepeatTarget(this, this.repeat);
125
- } else {
126
- targetRepeat = document.getElementById(this.repeat);
127
- }
121
+ _dispatch() {
122
+ const targetRepeat = resolveId(this.repeat, this);
128
123
  console.log('dispatching index change ', targetRepeat.nodeset.length);
129
- targetRepeat.dispatchEvent(
130
- new CustomEvent('index-changed', {
131
- composed: true,
132
- bubbles: true,
133
- detail: { index: targetRepeat.nodeset.length },
134
- }),
135
- );
124
+ Fore.dispatch(targetRepeat, 'index-changed', { index: targetRepeat.nodeset.length });
136
125
  }
137
126
 
138
127
  /**
@@ -213,4 +202,6 @@ class FxAppend extends AbstractAction {
213
202
  */
214
203
  }
215
204
 
216
- window.customElements.define('fx-append', FxAppend);
205
+ if (!customElements.get('fx-append')) {
206
+ window.customElements.define('fx-append', FxAppend);
207
+ }
@@ -1,4 +1,4 @@
1
- import { FxAction } from './fx-action.js';
1
+ import {AbstractAction} from "./abstract-action";
2
2
 
3
3
  /**
4
4
  * `fx-confirm`
@@ -7,7 +7,7 @@ import { FxAction } from './fx-action.js';
7
7
  * @customElement
8
8
  * @demo demo/project.html
9
9
  */
10
- export class FxConfirm extends FxAction {
10
+ export class FxConfirm extends AbstractAction {
11
11
  connectedCallback() {
12
12
  this.message = this.hasAttribute('message') ? this.getAttribute('message') : null;
13
13
  }
@@ -19,4 +19,6 @@ export class FxConfirm extends FxAction {
19
19
  }
20
20
  }
21
21
 
22
- window.customElements.define('fx-confirm', FxConfirm);
22
+ if (!customElements.get('fx-confirm')) {
23
+ window.customElements.define('fx-confirm', FxConfirm);
24
+ }
@@ -1,4 +1,5 @@
1
1
  import { AbstractAction } from './abstract-action.js';
2
+ import { Fore } from '../fore.js';
2
3
 
3
4
  /**
4
5
  * `fx-delete`
@@ -29,13 +30,13 @@ class FxDelete extends AbstractAction {
29
30
  // ### if there's no repeat the delete action is inside of a repeat template
30
31
  if (this.repeatId === '') {
31
32
  // find the index to delete
32
- const rItem = this.parentNode.closest('fx-repeatitem');
33
+ const rItem = Fore.getClosest('fx-repeatitem', this.parentNode);
33
34
  const idx = Array.from(rItem.parentNode.children).indexOf(rItem) + 1;
34
35
  // console.log('>>> idx to delete ', idx);
35
36
 
36
37
  // ### get the model now as it'll be hard once we've deleted ourselves ;)
37
38
  this.model = this.getModel();
38
- const repeat = this.parentNode.closest('fx-repeat');
39
+ const repeat = Fore.getClosest('fx-repeat', this.parentNode);
39
40
 
40
41
  // ### update the nodeset
41
42
  let nodeToDelete;
@@ -77,4 +78,6 @@ class FxDelete extends AbstractAction {
77
78
  }
78
79
  }
79
80
 
80
- window.customElements.define('fx-delete', FxDelete);
81
+ if (!customElements.get('fx-delete')) {
82
+ window.customElements.define('fx-delete', FxDelete);
83
+ }
@@ -1,6 +1,5 @@
1
1
  import { AbstractAction } from './abstract-action.js';
2
2
  import { evaluateXPath, resolveId } from '../xpath-evaluation.js';
3
- import { XPathUtil } from '../xpath-util.js';
4
3
 
5
4
  /**
6
5
  * `fx-dispatch`
@@ -68,7 +67,8 @@ export class FxDispatch extends AbstractAction {
68
67
  if (value) {
69
68
  throw new Error('if "expr" is given there must not be a "value" attribute');
70
69
  }
71
- const result = evaluateXPath(expr, this.getInScopeContext(), this.getOwnerForm());
70
+ const [result] = evaluateXPath(expr, this.getInScopeContext(), this.getOwnerForm());
71
+
72
72
  let serialized = null;
73
73
  if (result.nodeName) {
74
74
  const serializer = new XMLSerializer();
@@ -90,11 +90,10 @@ export class FxDispatch extends AbstractAction {
90
90
 
91
91
  // ### when targetid is given dispatch to that if present (throw an error if not) - otherwise dispatch to document
92
92
  if (this.targetid) {
93
- // const target = document.getElementById(this.targetid);
94
- let target;
95
- if (XPathUtil.isRepeated(this)) {
96
- target = resolveId(this.targetid, this.parentNode, null);
97
- } else {
93
+ let target = resolveId(this.targetid, this.parentNode, null);
94
+ if (!target) {
95
+ // TODO: essentially, we want to highly prefer the closest target. in the same subcontrol.
96
+ // However, it may be that our target is elsewhere. Do a global search for that case
98
97
  target = document.getElementById(this.targetid);
99
98
  }
100
99
  console.log('target', target);
@@ -120,4 +119,6 @@ export class FxDispatch extends AbstractAction {
120
119
  }
121
120
  }
122
121
 
123
- window.customElements.define('fx-dispatch', FxDispatch);
122
+ if (!customElements.get('fx-dispatch')) {
123
+ window.customElements.define('fx-dispatch', FxDispatch);
124
+ }
@@ -1,4 +1,6 @@
1
- import { FxAction } from './fx-action.js';
1
+ import { Fore } from '../fore.js';
2
+ import { AbstractAction } from './abstract-action.js';
3
+ import { resolveId } from '../xpath-evaluation.js';
2
4
 
3
5
  /**
4
6
  * `fx-hide`
@@ -7,17 +9,19 @@ import { FxAction } from './fx-action.js';
7
9
  * @customElement
8
10
  * @demo demo/project.html
9
11
  */
10
- export class FxHide extends FxAction {
12
+ export class FxHide extends AbstractAction {
11
13
  connectedCallback() {
12
14
  this.dialog = this.getAttribute('dialog');
13
- if(!this.dialog){
14
- this.dispatch('error',{message:'dialog does not exist'})
15
+ if (!this.dialog) {
16
+ Fore.dispatch(this, 'error', { message: 'dialog does not exist' });
15
17
  }
16
18
  }
17
19
 
18
20
  perform() {
19
- document.getElementById(this.dialog).hide();
21
+ resolveId(this.dialog, this).hide();
20
22
  }
21
23
  }
22
24
 
23
- window.customElements.define('fx-hide', FxHide);
25
+ if (!customElements.get('fx-hide')) {
26
+ window.customElements.define('fx-hide', FxHide);
27
+ }
@@ -1,7 +1,6 @@
1
1
  import { AbstractAction } from './abstract-action.js';
2
2
  import getInScopeContext from '../getInScopeContext.js';
3
3
  import {
4
- evaluateXPath,
5
4
  evaluateXPathToNodes,
6
5
  evaluateXPathToFirstNode,
7
6
  evaluateXPathToNumber,
@@ -47,6 +46,12 @@ export class FxInsert extends AbstractAction {
47
46
  // ### if there's an origin attribute use it
48
47
  let originTarget;
49
48
  try {
49
+ /*
50
+ todo: discuss where to pass vars from event.detail into function context
51
+ */
52
+ // this.setInScopeVariables(this.detail);
53
+
54
+ // originTarget = evaluateXPathToFirstNode(this.origin, inscope, this);
50
55
  originTarget = evaluateXPathToFirstNode(this.origin, inscope, this.getOwnerForm());
51
56
  if (Array.isArray(originTarget) && originTarget.length === 0) {
52
57
  console.warn('invalid origin for this insert action - ignoring...', this);
@@ -85,32 +90,26 @@ export class FxInsert extends AbstractAction {
85
90
  console.log('this.nodeset', this.nodeset);
86
91
  */
87
92
 
88
- // ### obtaining targetSequence
89
- const inscope = getInScopeContext(this.getAttributeNode('ref'), this.ref);
90
-
91
- // @ts-ignore
92
- const targetSequence = evaluateXPathToNodes(this.ref, inscope, this.getOwnerForm());
93
- // console.log('insert nodeset ', targetSequence);
93
+ let inscope;
94
+ // ### 'context' attribute takes precedence over 'ref'
95
+ let targetSequence;
96
+ if (this.hasAttribute('context')) {
97
+ inscope = getInScopeContext(this.getAttributeNode('context'), this.getAttribute('context'));
98
+ targetSequence = evaluateXPathToNodes(
99
+ this.getAttribute('context'),
100
+ inscope,
101
+ this.getOwnerForm(),
102
+ );
103
+ }
94
104
 
95
- // ### obtaining originSequence
96
- /*
97
- let originSequence;
98
- if (this.origin) {
99
- // ### if there's an origin attribute use it
100
- const originTarget = evaluateXPathToFirstNode(this.origin, inscope, this.getOwnerForm());
101
- if(Array.isArray(originTarget) && originTarget.length === 0){
102
- console.warn('invalid origin for this insert action - ignoring...', this);
103
- return;
104
- }
105
- originSequence = originTarget.cloneNode(true);
106
- } else if (targetSequence) {
107
- // ### use last item of targetSequence
108
- originSequence = this._cloneTargetSequence(targetSequence);
109
- if(originSequence && !this.keepValues){
110
- this._clear(originSequence);
111
- }
112
- }
113
- */
105
+ if (this.hasAttribute('ref')) {
106
+ if (inscope) {
107
+ targetSequence = evaluateXPathToNodes(this.ref, inscope, this.getOwnerForm());
108
+ } else {
109
+ inscope = getInScopeContext(this.getAttributeNode('ref'), this.ref);
110
+ targetSequence = evaluateXPathToNodes(this.ref, inscope, this.getOwnerForm());
111
+ }
112
+ }
114
113
  const originSequenceClone = this._cloneOriginSequence(inscope, targetSequence);
115
114
  if (!originSequenceClone) return; // if no origin back out without effect
116
115
 
@@ -127,13 +126,9 @@ export class FxInsert extends AbstractAction {
127
126
  index = 1;
128
127
  console.log('appended', inscope);
129
128
  } else {
130
- // todo: eval 'at'
131
-
132
- /*
133
- insert at position given by 'at' or use the last item in the targetSequence
134
- */
135
- // if (this.at) {
129
+ /* ### insert at position given by 'at' or use the last item in the targetSequence ### */
136
130
  if (this.hasAttribute('at')) {
131
+ // todo: eval 'at'
137
132
  // index = this.at;
138
133
  // insertLocationNode = targetSequence[this.at - 1];
139
134
 
@@ -150,7 +145,11 @@ export class FxInsert extends AbstractAction {
150
145
  index = 1;
151
146
 
152
147
  insertLocationNode = targetSequence;
153
- const context = evaluateXPath('count(preceding::*)', targetSequence, this.getOwnerForm());
148
+ const context = evaluateXPathToNumber(
149
+ 'count(preceding::*)',
150
+ targetSequence,
151
+ this.getOwnerForm(),
152
+ );
154
153
  // console.log('context', context);
155
154
  index = context + 1;
156
155
  // index = targetSequence.findIndex(insertLocationNode);
@@ -165,7 +164,15 @@ export class FxInsert extends AbstractAction {
165
164
  // insertLocationNode.parentNode.append(originSequence);
166
165
  // const nextSibl = insertLocationNode.nextSibling;
167
166
  index += 1;
168
- insertLocationNode.insertAdjacentElement('afterend', originSequenceClone);
167
+ if (this.hasAttribute('context') && this.hasAttribute('ref')) {
168
+ // index=1;
169
+ inscope.append(originSequenceClone);
170
+ } else if (this.hasAttribute('context')) {
171
+ index = 1;
172
+ insertLocationNode.prepend(originSequenceClone);
173
+ } else {
174
+ insertLocationNode.insertAdjacentElement('afterend', originSequenceClone);
175
+ }
169
176
  }
170
177
  }
171
178
 
@@ -173,16 +180,17 @@ export class FxInsert extends AbstractAction {
173
180
  // console.log('parent ', insertLocationNode.parentNode);
174
181
  // console.log('instance ', this.getModel().getDefaultContext());
175
182
 
176
- // console.log('<<<<<<< at', this.at);
177
- // console.log('<<<<<<< index', index);
183
+ console.log('<<<<<<< at', this.at);
184
+ console.log('<<<<<<< index', index);
178
185
  // todo: this actually should dispatch to respective instance
179
186
  document.dispatchEvent(
180
- new CustomEvent('insert', {
187
+ // new CustomEvent('insert', {
188
+ new CustomEvent('index-changed', {
181
189
  composed: true,
182
190
  bubbles: true,
183
191
  detail: {
184
192
  insertedNodes: originSequenceClone,
185
- position: index,
193
+ index,
186
194
  },
187
195
  }),
188
196
  );
@@ -235,4 +243,6 @@ export class FxInsert extends AbstractAction {
235
243
  }
236
244
  }
237
245
 
238
- window.customElements.define('fx-insert', FxInsert);
246
+ if (!customElements.get('fx-insert')) {
247
+ window.customElements.define('fx-insert', FxInsert);
248
+ }
@@ -61,4 +61,6 @@ class FxMessage extends AbstractAction {
61
61
  }
62
62
  }
63
63
 
64
- window.customElements.define('fx-message', FxMessage);
64
+ if (!customElements.get('fx-message')) {
65
+ window.customElements.define('fx-message', FxMessage);
66
+ }
@@ -1,4 +1,5 @@
1
1
  import { AbstractAction } from './abstract-action.js';
2
+ import { Fore } from '../fore.js';
2
3
 
3
4
  /**
4
5
  * `fx-refresh`
@@ -8,8 +9,21 @@ import { AbstractAction } from './abstract-action.js';
8
9
  */
9
10
  class FxRefresh extends AbstractAction {
10
11
  perform() {
12
+ if (this.hasAttribute('self')) {
13
+ const control = Fore.getClosest('fx-control', this);
14
+ if (control) {
15
+ control.refresh();
16
+ return;
17
+ }
18
+ }
19
+ if(this.hasAttribute('force')){
20
+ this.getOwnerForm().forceRefresh();
21
+ return;
22
+ }
11
23
  this.getOwnerForm().refresh();
12
24
  }
13
25
  }
14
26
 
15
- window.customElements.define('fx-refresh', FxRefresh);
27
+ if (!customElements.get('fx-refresh')) {
28
+ window.customElements.define('fx-refresh', FxRefresh);
29
+ }