@jinntec/fore 1.9.0 → 1.10.1

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.
@@ -341,7 +341,18 @@ function functionNameResolver({prefix, localName}, _arity) {
341
341
  case 'instance':
342
342
  case 'log':
343
343
  case 'parse':
344
+ case 'local-date':
345
+ case 'local-dateTime':
344
346
  case 'logtree':
347
+ case 'uri':
348
+ case 'uri-fragment':
349
+ case 'uri-host':
350
+ case 'uri-param':
351
+ case 'uri-path':
352
+ case 'uri-port':
353
+ case 'uri-query':
354
+ case 'uri-scheme':
355
+ case 'uri-scheme-specific-part':
345
356
  return {namespaceURI: XFORMS_NAMESPACE_URI, localName};
346
357
  default:
347
358
  if (prefix === '' && globallyDeclaredFunctionLocalNames.includes(localName)) {
@@ -407,14 +418,15 @@ function getVariablesInScope(formElement) {
407
418
  * @param {Node} contextNode The start of the XPath
408
419
  * @param {{parentNode}|ForeElementMixin} formElement The form element associated to the XPath
409
420
  */
410
- export function evaluateXPath(xpath, contextNode, formElement, variables = {}, options={}) {
421
+ /*
422
+ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, options={}, domFacade = null) {
411
423
  const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
412
424
  const variablesInScope = getVariablesInScope(formElement);
413
425
 
414
426
  return fxEvaluateXPath(
415
427
  xpath,
416
428
  contextNode,
417
- null,
429
+ domFacade,
418
430
  {...variablesInScope, ...variables},
419
431
  fxEvaluateXPath.ALL_RESULTS_TYPE,
420
432
  {
@@ -429,7 +441,59 @@ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, o
429
441
  },
430
442
  );
431
443
  }
444
+ */
445
+ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, options={}) {
446
+ try{
447
+ console.log('evaluateXPath',xpath);
448
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
449
+ const variablesInScope = getVariablesInScope(formElement);
450
+
451
+ return fxEvaluateXPath(
452
+ xpath,
453
+ contextNode,
454
+ null,
455
+ {...variablesInScope, ...variables},
456
+ fxEvaluateXPath.ALL_RESULTS_TYPE,
457
+ {
458
+ debug: true,
459
+ currentContext: {formElement, variables},
460
+ moduleImports: {
461
+ xf: XFORMS_NAMESPACE_URI,
462
+ },
463
+ functionNameResolver,
464
+ namespaceResolver,
465
+ language: options.language || evaluateXPath.XPATH_3_1
466
+ },
467
+ );
468
+ }catch (e){
469
+ formElement.dispatchEvent(new CustomEvent('error', {
470
+ composed: false,
471
+ bubbles: true,
472
+ detail: {
473
+ origin: formElement,
474
+ message: `Expression '${xpath}' failed`,
475
+ expr:xpath,
476
+ level:'Error'
477
+ },
478
+ }));
432
479
 
480
+ /*
481
+ formElement.dispatchEvent(
482
+ new CustomEvent('error', {
483
+ composed: false,
484
+ bubbles: true,
485
+ cancelable:true,
486
+ detail: {
487
+ origin: formElement,
488
+ message: `Expression '${xpath}' failed`,
489
+ expr:xpath,
490
+ level:'Error'},
491
+ }),
492
+ );
493
+ */
494
+ return false;
495
+ }
496
+ }
433
497
  /**
434
498
  * Evaluate an XPath to the first Node
435
499
  *
@@ -439,17 +503,30 @@ export function evaluateXPath(xpath, contextNode, formElement, variables = {}, o
439
503
  * @return {Node} The first node found by the XPath
440
504
  */
441
505
  export function evaluateXPathToFirstNode(xpath, contextNode, formElement) {
442
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
443
- const variablesInScope = getVariablesInScope(formElement);
444
- return fxEvaluateXPathToFirstNode(xpath, contextNode, null, variablesInScope, {
445
- defaultFunctionNamespaceURI: XFORMS_NAMESPACE_URI,
446
- moduleImports: {
447
- xf: XFORMS_NAMESPACE_URI,
448
- },
449
- currentContext: {formElement},
450
- functionNameResolver,
451
- namespaceResolver,
452
- });
506
+ try{
507
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
508
+ const variablesInScope = getVariablesInScope(formElement);
509
+ return fxEvaluateXPathToFirstNode(xpath, contextNode, null, variablesInScope, {
510
+ defaultFunctionNamespaceURI: XFORMS_NAMESPACE_URI,
511
+ moduleImports: {
512
+ xf: XFORMS_NAMESPACE_URI,
513
+ },
514
+ currentContext: {formElement},
515
+ functionNameResolver,
516
+ namespaceResolver,
517
+ });
518
+ } catch (e){
519
+ formElement.dispatchEvent(new CustomEvent('error', {
520
+ composed: false,
521
+ bubbles: true,
522
+ detail: {
523
+ origin: formElement,
524
+ message: `Expression '${xpath}' failed`,
525
+ expr:xpath,
526
+ level:'Error'
527
+ },
528
+ }));
529
+ }
453
530
  }
454
531
 
455
532
  /**
@@ -461,17 +538,30 @@ export function evaluateXPathToFirstNode(xpath, contextNode, formElement) {
461
538
  * @return {Node[]} All nodes
462
539
  */
463
540
  export function evaluateXPathToNodes(xpath, contextNode, formElement) {
464
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
465
- const variablesInScope = getVariablesInScope(formElement);
541
+ try{
542
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
543
+ const variablesInScope = getVariablesInScope(formElement);
466
544
 
467
- return fxEvaluateXPathToNodes(xpath, contextNode, null, variablesInScope, {
468
- currentContext: {formElement},
469
- functionNameResolver,
470
- moduleImports: {
471
- xf: XFORMS_NAMESPACE_URI,
472
- },
473
- namespaceResolver,
474
- });
545
+ return fxEvaluateXPathToNodes(xpath, contextNode, null, variablesInScope, {
546
+ currentContext: {formElement},
547
+ functionNameResolver,
548
+ moduleImports: {
549
+ xf: XFORMS_NAMESPACE_URI,
550
+ },
551
+ namespaceResolver,
552
+ });
553
+ }catch (e){
554
+ formElement.dispatchEvent(new CustomEvent('error', {
555
+ composed: false,
556
+ bubbles: true,
557
+ detail: {
558
+ origin: formElement,
559
+ message: `Expression '${xpath}' failed`,
560
+ expr:xpath,
561
+ level:'Error'
562
+ },
563
+ }));
564
+ }
475
565
  }
476
566
 
477
567
  /**
@@ -483,17 +573,30 @@ export function evaluateXPathToNodes(xpath, contextNode, formElement) {
483
573
  * @return {boolean}
484
574
  */
485
575
  export function evaluateXPathToBoolean(xpath, contextNode, formElement) {
486
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
487
- const variablesInScope = getVariablesInScope(formElement);
576
+ try{
577
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
578
+ const variablesInScope = getVariablesInScope(formElement);
488
579
 
489
- return fxEvaluateXPathToBoolean(xpath, contextNode, null, variablesInScope, {
490
- currentContext: {formElement},
491
- functionNameResolver,
492
- moduleImports: {
493
- xf: XFORMS_NAMESPACE_URI,
494
- },
495
- namespaceResolver,
496
- });
580
+ return fxEvaluateXPathToBoolean(xpath, contextNode, null, variablesInScope, {
581
+ currentContext: {formElement},
582
+ functionNameResolver,
583
+ moduleImports: {
584
+ xf: XFORMS_NAMESPACE_URI,
585
+ },
586
+ namespaceResolver,
587
+ });
588
+ }catch (e){
589
+ formElement.dispatchEvent(new CustomEvent('error', {
590
+ composed: false,
591
+ bubbles: true,
592
+ detail: {
593
+ origin: formElement,
594
+ message: `Expression '${xpath}' failed`,
595
+ expr:xpath,
596
+ level:'Error'
597
+ },
598
+ }));
599
+ }
497
600
  }
498
601
 
499
602
  /**
@@ -514,17 +617,30 @@ export function evaluateXPathToString(
514
617
  domFacade = null,
515
618
  namespaceReferenceNode = formElement,
516
619
  ) {
517
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
518
- const variablesInScope = getVariablesInScope(formElement);
620
+ try{
621
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
622
+ const variablesInScope = getVariablesInScope(formElement);
519
623
 
520
- return fxEvaluateXPathToString(xpath, contextNode, domFacade, variablesInScope, {
521
- currentContext: {formElement},
522
- functionNameResolver,
523
- moduleImports: {
524
- xf: XFORMS_NAMESPACE_URI,
525
- },
526
- namespaceResolver,
527
- });
624
+ return fxEvaluateXPathToString(xpath, contextNode, domFacade, variablesInScope, {
625
+ currentContext: {formElement},
626
+ functionNameResolver,
627
+ moduleImports: {
628
+ xf: XFORMS_NAMESPACE_URI,
629
+ },
630
+ namespaceResolver,
631
+ });
632
+ }catch (e) {
633
+ formElement.dispatchEvent(new CustomEvent('error', {
634
+ composed: false,
635
+ bubbles: true,
636
+ detail: {
637
+ origin: formElement,
638
+ message: `Expression '${xpath}' failed`,
639
+ expr:xpath,
640
+ level:'Error'
641
+ },
642
+ }));
643
+ }
528
644
  }
529
645
 
530
646
  /**
@@ -545,22 +661,31 @@ export function evaluateXPathToStrings(
545
661
  domFacade = null,
546
662
  namespaceReferenceNode = formElement,
547
663
  ) {
548
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
549
- return fxEvaluateXPathToStrings(
550
- xpath,
551
- contextNode,
552
- domFacade,
553
- {},
554
-
555
- {
556
- currentContext: {formElement},
557
- functionNameResolver,
558
- moduleImports: {
559
- xf: XFORMS_NAMESPACE_URI,
664
+ try{
665
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
666
+ return fxEvaluateXPathToStrings( xpath, contextNode, domFacade,
667
+ {},
668
+ {
669
+ currentContext: {formElement},
670
+ functionNameResolver,
671
+ moduleImports: {
672
+ xf: XFORMS_NAMESPACE_URI,
673
+ },
674
+ namespaceResolver,
560
675
  },
561
- namespaceResolver,
562
- },
563
- );
676
+ );
677
+ } catch (e){
678
+ formElement.dispatchEvent(new CustomEvent('error', {
679
+ composed: false,
680
+ bubbles: true,
681
+ detail: {
682
+ origin: formElement,
683
+ message: `Expression '${xpath}' failed`,
684
+ expr:xpath,
685
+ level:'Error'
686
+ },
687
+ }));
688
+ }
564
689
  }
565
690
 
566
691
  /**
@@ -581,17 +706,30 @@ export function evaluateXPathToNumber(
581
706
  domFacade = null,
582
707
  namespaceReferenceNode = formElement,
583
708
  ) {
584
- const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
585
- const variablesInScope = getVariablesInScope(formElement);
709
+ try{
710
+ const namespaceResolver = createNamespaceResolverForNode(xpath, contextNode, formElement);
711
+ const variablesInScope = getVariablesInScope(formElement);
586
712
 
587
- return fxEvaluateXPathToNumber(xpath, contextNode, domFacade, variablesInScope, {
588
- currentContext: {formElement},
589
- functionNameResolver,
590
- moduleImports: {
591
- xf: XFORMS_NAMESPACE_URI,
592
- },
593
- namespaceResolver,
594
- });
713
+ return fxEvaluateXPathToNumber(xpath, contextNode, domFacade, variablesInScope, {
714
+ currentContext: {formElement},
715
+ functionNameResolver,
716
+ moduleImports: {
717
+ xf: XFORMS_NAMESPACE_URI,
718
+ },
719
+ namespaceResolver,
720
+ });
721
+ }catch (e) {
722
+ formElement.dispatchEvent(new CustomEvent('error', {
723
+ composed: false,
724
+ bubbles: true,
725
+ detail: {
726
+ origin: formElement,
727
+ message: `Expression '${xpath}' failed`,
728
+ expr:xpath,
729
+ level:'Error'
730
+ },
731
+ }));
732
+ }
595
733
  }
596
734
 
597
735
  const contextFunction = (dynamicContext, string) => {
@@ -833,18 +971,44 @@ const instance = (dynamicContext, string) => {
833
971
  {namespaceResolver: xhtmlNamespaceResolver},
834
972
  );
835
973
 
974
+ let lookup = null;
975
+ if(string === null || string === 'default'){
976
+ lookup = formElement.getModel().getDefaultInstance();
977
+ }else{
978
+ lookup = formElement.getModel().getInstance(string);
979
+ if(!lookup){
980
+ document.querySelector('fx-fore').dispatchEvent(new CustomEvent('error', {
981
+ composed: true,
982
+ bubbles: true,
983
+ detail: {
984
+ origin: 'functions',
985
+ message: `Function not found '${localName}'`,
986
+ level:'Error'
987
+ },
988
+ }));
989
+ }
990
+ }
991
+
992
+ const context = lookup.getDefaultContext();
993
+ if (!context) {
994
+ debugger;
995
+ return null;
996
+ }
997
+ return context;
998
+
999
+ /*
836
1000
  const inst = string
837
- ? formElement.querySelector(`#${string}`)
838
- : formElement.querySelector(`fx-instance`);
1001
+ ? formElement.getModel().getInstance(string)
1002
+ : formElement.getModel().getDefaultInstance();
1003
+ */
839
1004
 
840
1005
  /*
841
1006
  const inst = string
842
1007
  ? resolveId(string, formElement, 'fx-instance')
843
1008
  : formElement.querySelector(`fx-instance`);
844
- */
845
1009
 
846
- if (inst) {
847
- const context = inst.getDefaultContext();
1010
+ if (lookup) {
1011
+ const context = lookup.getDefaultContext();
848
1012
  if (!context) {
849
1013
  debugger;
850
1014
  return null;
@@ -852,6 +1016,7 @@ const instance = (dynamicContext, string) => {
852
1016
  return context;
853
1017
  }
854
1018
  return null;
1019
+ */
855
1020
  };
856
1021
 
857
1022
  registerCustomXPathFunction(
@@ -980,3 +1145,89 @@ registerCustomXPathFunction(
980
1145
  'xs:string?',
981
1146
  (dynamicContext, string) => btoa(string),
982
1147
  );
1148
+
1149
+ registerCustomXPathFunction(
1150
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'local-date'},
1151
+ [],
1152
+ 'xs:string?',
1153
+ (dynamicContext, string) => new Date().toLocaleDateString(),
1154
+ );
1155
+ registerCustomXPathFunction(
1156
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'local-dateTime'},
1157
+ [],
1158
+ 'xs:string?',
1159
+ (dynamicContext, string) => {
1160
+ return new Date().toLocaleString();
1161
+ },
1162
+ );
1163
+ registerCustomXPathFunction(
1164
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri'},
1165
+ [],
1166
+ 'xs:string?',
1167
+ (dynamicContext, string) => window.location.href,
1168
+ );
1169
+ registerCustomXPathFunction(
1170
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-fragment'},
1171
+ [],
1172
+ 'xs:string?',
1173
+ (dynamicContext, arg) => window.location.hash,
1174
+ );
1175
+ registerCustomXPathFunction(
1176
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-host'},
1177
+ [],
1178
+ 'xs:string?',
1179
+ (dynamicContext, arg) => window.location.host,
1180
+ );
1181
+ registerCustomXPathFunction(
1182
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-query'},
1183
+ [],
1184
+ 'xs:string?',
1185
+ (dynamicContext, arg) => window.location.search,
1186
+ );
1187
+ registerCustomXPathFunction(
1188
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-path'},
1189
+ [],
1190
+ 'xs:string?',
1191
+ (dynamicContext, arg) => {
1192
+ return new URL(window.location.href).pathname;
1193
+ },
1194
+ );
1195
+ registerCustomXPathFunction(
1196
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-port'},
1197
+ [],
1198
+ 'xs:string?',
1199
+ (dynamicContext, arg) => {
1200
+ return window.location.port;
1201
+ },
1202
+ );
1203
+ registerCustomXPathFunction(
1204
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-param'},
1205
+ ['xs:string?'],
1206
+ 'xs:string?',
1207
+ (dynamicContext, arg) => {
1208
+ if (!arg) return null;
1209
+
1210
+ const search = window.location.search;
1211
+ const urlparams = new URLSearchParams(search);
1212
+ const param = urlparams.get(arg);
1213
+ return param ? param : '';
1214
+
1215
+ },
1216
+ );
1217
+ registerCustomXPathFunction(
1218
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-scheme'},
1219
+ [],
1220
+ 'xs:string?',
1221
+ (dynamicContext, arg) => {
1222
+ return new URL(window.location.href).protocol;
1223
+ },
1224
+ );
1225
+ registerCustomXPathFunction(
1226
+ {namespaceURI: XFORMS_NAMESPACE_URI, localName: 'uri-scheme-specific-part'},
1227
+ [],
1228
+ 'xs:string?',
1229
+ (dynamicContext, arg) => {
1230
+ const uri = window.location.href;
1231
+ return uri.substring(uri.indexOf(':') + 1, uri.length);
1232
+ },
1233
+ );