@jinntec/fore 1.0.0-3 → 1.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.
Files changed (62) hide show
  1. package/README.md +25 -34
  2. package/dist/fore-dev.js +43 -0
  3. package/dist/fore-dev.js.map +1 -0
  4. package/dist/fore.js +36 -1
  5. package/dist/fore.js.map +1 -0
  6. package/index.js +3 -0
  7. package/package.json +34 -38
  8. package/resources/fore.css +35 -50
  9. package/src/DependencyNotifyingDomFacade.js +10 -16
  10. package/src/ForeElementMixin.js +25 -18
  11. package/src/actions/abstract-action.js +17 -9
  12. package/src/actions/fx-action.js +6 -4
  13. package/src/actions/fx-append.js +8 -17
  14. package/src/actions/fx-confirm.js +3 -1
  15. package/src/actions/fx-delete.js +6 -3
  16. package/src/actions/fx-dispatch.js +9 -8
  17. package/src/actions/fx-hide.js +10 -6
  18. package/src/actions/fx-insert.js +49 -39
  19. package/src/actions/fx-message.js +3 -1
  20. package/src/actions/fx-refresh.js +11 -1
  21. package/src/actions/fx-replace.js +68 -0
  22. package/src/actions/fx-return.js +42 -0
  23. package/src/actions/fx-send.js +3 -1
  24. package/src/actions/fx-setvalue.js +58 -51
  25. package/src/actions/fx-show.js +8 -4
  26. package/src/actions/fx-toggle.js +15 -10
  27. package/src/actions/fx-update.js +3 -1
  28. package/src/dep_graph.js +4 -2
  29. package/src/drawdown.js +67 -82
  30. package/src/fore.js +158 -11
  31. package/src/functions/fx-function.js +11 -3
  32. package/src/fx-bind.js +42 -202
  33. package/src/fx-fore.js +105 -70
  34. package/src/fx-header.js +3 -1
  35. package/src/fx-instance.js +9 -1
  36. package/src/fx-model.js +31 -23
  37. package/src/fx-submission.js +73 -47
  38. package/src/fx-var.js +7 -4
  39. package/src/getInScopeContext.js +37 -11
  40. package/src/modelitem.js +4 -4
  41. package/src/relevance.js +65 -0
  42. package/src/ui/abstract-control.js +55 -35
  43. package/src/ui/fx-alert.js +7 -1
  44. package/src/ui/fx-case.js +3 -1
  45. package/src/ui/fx-container.js +7 -1
  46. package/src/ui/fx-control.js +283 -33
  47. package/src/ui/fx-dialog.js +54 -40
  48. package/src/ui/fx-group.js +3 -1
  49. package/src/ui/fx-hint.js +4 -1
  50. package/src/ui/fx-inspector.js +117 -17
  51. package/src/ui/fx-items.js +8 -8
  52. package/src/ui/fx-output.js +14 -5
  53. package/src/ui/fx-repeat.js +33 -41
  54. package/src/ui/fx-repeatitem.js +10 -4
  55. package/src/ui/fx-switch.js +3 -1
  56. package/src/ui/fx-trigger.js +3 -1
  57. package/src/xpath-evaluation.js +121 -131
  58. package/src/xpath-util.js +14 -7
  59. package/dist/fore-all.js +0 -140
  60. package/src/.DS_Store +0 -0
  61. package/src/actions/.DS_Store +0 -0
  62. package/src/ui/.DS_Store +0 -0
package/src/fx-bind.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { DependencyNotifyingDomFacade } from './DependencyNotifyingDomFacade.js';
2
2
  import { foreElementMixin } from './ForeElementMixin.js';
3
+ import { Fore } from './fore.js';
3
4
  import { ModelItem } from './modelitem.js';
4
5
  import {
5
6
  evaluateXPathToBoolean,
@@ -32,98 +33,8 @@ export class FxBind extends foreElementMixin(HTMLElement) {
32
33
 
33
34
  static TYPE_DEFAULT = 'xs:string';
34
35
 
35
- /*
36
- static get styles() {
37
- return css`
38
- :host {
39
- display: none;
40
- }
41
- `;
42
- }
43
- */
44
-
45
- /*
46
- static get properties() {
47
- return {
48
- ...super.properties,
49
-
50
- /!**
51
- * allows to calculate a value. This value will become readonly.
52
- *!/
53
- calculate: {
54
- type: String
55
- },
56
- contextNode:{
57
- type:Object
58
- },
59
- /!**
60
- * arbitrary XPath resolving to xs:boolean - defaults to 'true()'
61
- *!/
62
- constraint: {
63
- type: String
64
- },
65
- /!**
66
- * id of this bind
67
- *!/
68
- id:{
69
- type:String
70
- },
71
- /!**
72
- * the nodeset the bind is referring to by it's binding expression (ref attribute)
73
- *!/
74
- nodeset: {
75
- type: Array
76
- },
77
- /!**
78
- * the owning model of this bind
79
- *!/
80
- model:{
81
- type:Object
82
- },
83
- /!**
84
- * XPath statement resolving to xs:boolean to switch between readonly and readwrite mode - defaults to 'false()'
85
- *!/
86
- readonly: {
87
- type: String
88
- },
89
- /!**
90
- * the XPath binding expression of this bind
91
- *!/
92
- ref: {
93
- type: String
94
- },
95
- /!**
96
- * XPath statement resolving to xs:boolean to switch between relevant and non-relevant mode - defaults to 'true()'
97
- *!/
98
- relevant: {
99
- type: String
100
- },
101
- /!**
102
- * XPath statement resolving to xs:boolean to switch between required and optional - defaults to 'false'.
103
- *!/
104
- required: {
105
- type: String
106
- },
107
- /!**
108
- * XPath statement
109
- *!/
110
- type: {
111
- type: String
112
- }
113
- };
114
- }
115
- */
116
-
117
36
  constructor() {
118
37
  super();
119
- // this.id='';
120
- // this.ref = '';
121
- // this.readonly = 'false()';
122
- // this.required = 'false()';
123
- // this.relevant = 'true()';
124
- // this.constraint = 'true()';
125
- // this.type = 'xs:string';
126
- // this.calculate = '';
127
38
  this.nodeset = [];
128
39
  this.model = {};
129
40
  this.contextNode = {};
@@ -165,26 +76,23 @@ export class FxBind extends foreElementMixin(HTMLElement) {
165
76
  this._processChildren(model);
166
77
  }
167
78
 
168
- /*
169
- //todo: certainly not ideal to rely on duplicating instance id on instance document - better way later ;)
170
- static getPath(node){
171
- let path = fx.evaluateXPath('path()',node);
172
- const instanceId = node.ownerDocument.firstElementChild.getAttribute('id');
173
- if(instanceId !== 'default'){
174
- return '#' + instanceId + FxBind.shortenPath(path);
175
- }else {
176
- return FxBind.shortenPath(path);
177
- }
178
-
179
- }
180
- */
181
-
182
79
  _buildBindGraph() {
183
80
  if (this.bindType === 'xml') {
184
81
  this.nodeset.forEach(node => {
185
82
  const path = XPathUtil.getPath(node);
186
83
  this.model.mainGraph.addNode(path, node);
187
84
 
85
+ /* ### catching references in the 'ref' itself...
86
+ todo: investigate cases where 'ref' attributes use predicates pointing to other nodes. These would not be handled
87
+ in current implementation.
88
+
89
+ General question: are there valid use-cases for using a 'filter' expression to narrow the nodeset
90
+ where to apply constraints? Guess yes and if it's 'just' for reducing the amount of necessary modelItem objects.
91
+
92
+
93
+ */
94
+ // const foreignRefs = this.getReferences(this.ref);
95
+
188
96
  if (this.calculate) {
189
97
  this.model.mainGraph.addNode(`${path}:calculate`, node);
190
98
  // Calculated values are a dependency of the model item.
@@ -251,7 +159,7 @@ export class FxBind extends foreElementMixin(HTMLElement) {
251
159
  // console.log('otherPath', otherPath)
252
160
 
253
161
  // todo: nasty hack to prevent duplicate pathes like 'a[1]' and 'a[1]/text()[1]' to end up as separate nodes in the graph
254
- if(!otherPath.endsWith('text()[1]')){
162
+ if (!otherPath.endsWith('text()[1]')) {
255
163
  if (!this.model.mainGraph.hasNode(otherPath)) {
256
164
  this.model.mainGraph.addNode(otherPath, ref);
257
165
  }
@@ -271,14 +179,6 @@ export class FxBind extends foreElementMixin(HTMLElement) {
271
179
  });
272
180
  }
273
181
 
274
- /*
275
- render() {
276
- return html`
277
- <slot></slot>
278
- `;
279
- }
280
- */
281
-
282
182
  getAlert() {
283
183
  if (this.hasAttribute('alert')) {
284
184
  return this.getAttribute('alert');
@@ -290,33 +190,6 @@ export class FxBind extends foreElementMixin(HTMLElement) {
290
190
  return null;
291
191
  }
292
192
 
293
- /*
294
- firstUpdated(_changedProperties) {
295
- super.firstUpdated(_changedProperties);
296
- }
297
- */
298
-
299
- /*
300
- namespaceResolver(prefix) {
301
- // TODO: Do proper namespace resolving. Look at the ancestry / namespacesInScope of the declaration
302
-
303
- /!**
304
- * for (let ancestor = this; ancestor; ancestor = ancestor.parentNode) {
305
- * if (ancestor.getAttribute(`xmlns:${prefix}`)) {
306
- * // Return value
307
- * }
308
- * }
309
- *!/
310
-
311
- // console.log('namespaceResolver prefix', prefix);
312
- const ns = {
313
- xhtml: 'http://www.w3.org/1999/xhtml',
314
- // '' : Fore.XFORMS_NAMESPACE_URI
315
- };
316
- return ns[prefix] || null;
317
- }
318
- */
319
-
320
193
  /**
321
194
  * overwrites
322
195
  */
@@ -335,7 +208,7 @@ export class FxBind extends foreElementMixin(HTMLElement) {
335
208
  } else {
336
209
  // eslint-disable-next-line no-lonely-if
337
210
  if (this.ref) {
338
- const localResult = evaluateXPathToNodes(this.ref, n, this.getOwnerForm());
211
+ const localResult = evaluateXPathToNodes(this.ref, n, this);
339
212
  localResult.forEach(item => {
340
213
  this.nodeset.push(item);
341
214
  });
@@ -351,7 +224,7 @@ export class FxBind extends foreElementMixin(HTMLElement) {
351
224
  } else {
352
225
  const inst = this.getModel().getInstance(this.instanceId);
353
226
  if (inst.type === 'xml') {
354
- this.nodeset = evaluateXPathToNodes(this.ref, inscopeContext, this.getOwnerForm());
227
+ this.nodeset = evaluateXPathToNodes(this.ref, inscopeContext, this);
355
228
  } else {
356
229
  this.nodeset = this.ref;
357
230
  }
@@ -361,11 +234,6 @@ export class FxBind extends foreElementMixin(HTMLElement) {
361
234
  _createModelItems() {
362
235
  // console.log('#### ', thi+s.nodeset);
363
236
 
364
- /*
365
- if(XPathUtil.isSelfReference(this.ref)){
366
- return;
367
- }
368
- */
369
237
  if (Array.isArray(this.nodeset)) {
370
238
  // todo - iterate and create
371
239
  // console.log('################################################ ', this.nodeset);
@@ -380,54 +248,6 @@ export class FxBind extends foreElementMixin(HTMLElement) {
380
248
  }
381
249
  }
382
250
 
383
- static lazyCreateModelitems(model, ref, nodeset) {
384
- if (Array.isArray(nodeset)) {
385
- Array.from(nodeset).forEach(n => {
386
- FxBind.lazyCreateModelItem(model, ref, n);
387
- });
388
- } else {
389
- FxBind.lazyCreateModelItem(model, ref, nodeset);
390
- }
391
- }
392
-
393
- /*
394
- static lazyCreateModelItem(model,ref,node){
395
- console.log('lazyCreateModelItem ', node);
396
-
397
- let mItem = {};
398
- let targetNode = {};
399
- if(node === null) return null;
400
- if(node.nodeType === node.TEXT_NODE){
401
- // const parent = node.parentNode;
402
- // console.log('PARENT ', parent);
403
- targetNode = node.parentNode;
404
- }else {
405
- targetNode = node;
406
- }
407
-
408
- // const path = fx.evaluateXPath('path()',node);
409
- const path = FxBind.getPath(node);
410
-
411
- // const path = Fore.evaluateXPath ('path()', node, this, Fore.namespaceResolver) ;
412
-
413
- // ### intializing ModelItem with default values (as there is no <fx-bind> matching for given ref)
414
- const mi = new ModelItem(path,
415
- ref,
416
- FxBind.READONLY_DEFAULT,
417
- FxBind.RELEVANT_DEFAULT,
418
- FxBind.REQUIRED_DEFAULT,
419
- FxBind.CONSTRAINT_DEFAULT,
420
- FxBind.TYPE_DEFAULT,
421
- targetNode,
422
- this);
423
-
424
-
425
- // console.log('new ModelItem is instanceof ModelItem ', mi instanceof ModelItem);
426
- model.registerModelItem(mi);
427
- return mi;
428
- }
429
- */
430
-
431
251
  /**
432
252
  * creates a ModelItem for given instance node.
433
253
  *
@@ -452,7 +272,7 @@ export class FxBind extends foreElementMixin(HTMLElement) {
452
272
  if bind is the dot expression we use the modelitem of the parent
453
273
  */
454
274
  if (XPathUtil.isSelfReference(this.ref)) {
455
- const parentBoundElement = this.parentElement.closest('fx-bind[ref]');
275
+ const parentBoundElement = Fore.getClosest('fx-bind[ref]', this.parentElement);
456
276
  console.log('parent bound element ', parentBoundElement);
457
277
 
458
278
  if (parentBoundElement) {
@@ -514,16 +334,34 @@ export class FxBind extends foreElementMixin(HTMLElement) {
514
334
  */
515
335
  _getReferencesForProperty(propertyExpr) {
516
336
  if (propertyExpr) {
517
- const touchedNodes = new Set();
518
- const domFacade = new DependencyNotifyingDomFacade(otherNode => touchedNodes.add(otherNode));
519
- this.nodeset.forEach(node => {
520
- evaluateXPathToString(propertyExpr, node, this.getOwnerForm(), domFacade);
521
- });
337
+ return this.getReferences(propertyExpr);
338
+ }
339
+ return [];
340
+ }
341
+
342
+ getReferences(propertyExpr) {
343
+ const touchedNodes = new Set();
344
+ const domFacade = new DependencyNotifyingDomFacade(otherNode => touchedNodes.add(otherNode));
345
+ this.nodeset.forEach(node => {
346
+ evaluateXPathToString(propertyExpr, node, this, domFacade);
347
+ });
348
+ return Array.from(touchedNodes.values());
349
+ }
350
+
351
+ /*
352
+ static getReferencesForRef(ref,nodeset){
353
+ if (ref && nodeset) {
354
+ const touchedNodes = new Set();
355
+ const domFacade = new DependencyNotifyingDomFacade(otherNode => touchedNodes.add(otherNode));
356
+ nodeset.forEach(node => {
357
+ evaluateXPathToString(ref, node, this, domFacade);
358
+ });
522
359
 
523
360
  return Array.from(touchedNodes.values());
524
361
  }
525
362
  return [];
526
363
  }
364
+ */
527
365
 
528
366
  _initBooleanModelItemProperty(property, node) {
529
367
  // evaluate expression to boolean
@@ -562,4 +400,6 @@ export class FxBind extends foreElementMixin(HTMLElement) {
562
400
  return 'default';
563
401
  }
564
402
  }
565
- customElements.define('fx-bind', FxBind);
403
+ if (!customElements.get('fx-bind')) {
404
+ customElements.define('fx-bind', FxBind);
405
+ }