@jinntec/fore 1.0.0-5 → 1.2.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 (64) hide show
  1. package/README.md +7 -28
  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 +3 -1
  7. package/package.json +39 -41
  8. package/resources/fore.css +27 -54
  9. package/src/DependencyNotifyingDomFacade.js +5 -13
  10. package/src/ForeElementMixin.js +15 -22
  11. package/src/actions/abstract-action.js +34 -10
  12. package/src/actions/fx-action.js +7 -5
  13. package/src/actions/fx-append.js +8 -17
  14. package/src/actions/fx-confirm.js +5 -3
  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 +9 -6
  18. package/src/actions/fx-insert.js +27 -14
  19. package/src/actions/fx-message.js +3 -1
  20. package/src/actions/fx-refresh.js +24 -1
  21. package/src/actions/fx-replace.js +74 -0
  22. package/src/actions/fx-return.js +42 -0
  23. package/src/actions/fx-send.js +3 -1
  24. package/src/actions/fx-setfocus.js +37 -0
  25. package/src/actions/fx-setvalue.js +58 -51
  26. package/src/actions/fx-show.js +12 -4
  27. package/src/actions/fx-toggle.js +13 -9
  28. package/src/actions/fx-update.js +3 -1
  29. package/src/dep_graph.js +1 -1
  30. package/src/drawdown.js +67 -82
  31. package/src/fore.js +143 -26
  32. package/src/functions/fx-function.js +17 -3
  33. package/src/fx-bind.js +40 -200
  34. package/src/fx-fore.js +598 -568
  35. package/src/fx-header.js +3 -1
  36. package/src/fx-instance.js +9 -1
  37. package/src/fx-model.js +60 -27
  38. package/src/fx-submission.js +108 -51
  39. package/src/fx-var.js +7 -4
  40. package/src/getInScopeContext.js +23 -16
  41. package/src/modelitem.js +4 -4
  42. package/src/relevance.js +64 -0
  43. package/src/ui/abstract-control.js +65 -37
  44. package/src/ui/fx-alert.js +7 -1
  45. package/src/ui/fx-case.js +4 -3
  46. package/src/ui/fx-container.js +4 -2
  47. package/src/ui/fx-control.js +315 -34
  48. package/src/ui/fx-dialog.js +50 -45
  49. package/src/ui/fx-group.js +3 -1
  50. package/src/ui/fx-hint.js +4 -1
  51. package/src/ui/fx-inspector.js +118 -17
  52. package/src/ui/fx-items.js +7 -5
  53. package/src/ui/fx-output.js +19 -6
  54. package/src/ui/fx-repeat.js +13 -26
  55. package/src/ui/fx-repeatitem.js +10 -4
  56. package/src/ui/fx-switch.js +5 -3
  57. package/src/ui/fx-trigger.js +3 -1
  58. package/src/xpath-evaluation.js +622 -553
  59. package/src/xpath-util.js +2 -6
  60. package/dist/fore-all.js +0 -140
  61. package/dist/fore-debug.js +0 -140
  62. package/src/.DS_Store +0 -0
  63. package/src/actions/.DS_Store +0 -0
  64. 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.
@@ -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
  */
@@ -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,8 +272,8 @@ 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]');
456
- console.log('parent bound element ', parentBoundElement);
275
+ const parentBoundElement = Fore.getClosest('fx-bind[ref]', this.parentElement);
276
+ // console.log('parent bound element ', parentBoundElement);
457
277
 
458
278
  if (parentBoundElement) {
459
279
  // todo: Could be fancier by combining them
@@ -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, 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
+ }