jsf.js_next_gen 4.0.0-beta-20 → 4.0.0-beta-22

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 (43) hide show
  1. package/dist/window/faces-development.js +147 -79
  2. package/dist/window/faces-development.js.br +0 -0
  3. package/dist/window/faces-development.js.gz +0 -0
  4. package/dist/window/faces-development.js.map +1 -1
  5. package/dist/window/faces.js +1 -1
  6. package/dist/window/faces.js.br +0 -0
  7. package/dist/window/faces.js.gz +0 -0
  8. package/dist/window/faces.js.map +1 -1
  9. package/dist/window/jsf-development.js +147 -79
  10. package/dist/window/jsf-development.js.br +0 -0
  11. package/dist/window/jsf-development.js.gz +0 -0
  12. package/dist/window/jsf-development.js.map +1 -1
  13. package/dist/window/jsf.js +1 -1
  14. package/dist/window/jsf.js.br +0 -0
  15. package/dist/window/jsf.js.gz +0 -0
  16. package/dist/window/jsf.js.map +1 -1
  17. package/package.json +3 -3
  18. package/src/main/typescript/impl/util/ExtDomQuery.ts +51 -4
  19. package/src/main/typescript/impl/xhrCore/ResponseProcessor.ts +1 -23
  20. package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +283 -68
  21. package/src/main/typescript/test/frameworkBase/_ext/monadish/fixtures/test.js +1 -0
  22. package/src/main/typescript/test/frameworkBase/_ext/monadish/fixtures/test2.js +1 -0
  23. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +11 -3
  24. package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +14 -6
  25. package/src/main/typescript/test/xhrCore/ResponseTest.spec.ts +36 -11
  26. package/src/main/typescript/test/xhrCore/fixtures/addedViewHead1.js +16 -0
  27. package/src/main/typescript/test/xhrCore/fixtures/addedViewHead2.css +18 -0
  28. package/src/main/typescript/test/xhrCore/fixtures/addedViewHead2.js +16 -0
  29. package/src/main/typescript/test/xhrCore/fixtures/addedViewHead3.js +16 -0
  30. package/src/main/typescript/test/xhrCore/fixtures/nonce_script.js +16 -0
  31. package/src/tmp/test.html +92 -0
  32. package/target/impl/util/ExtDomQuery.js +47 -2
  33. package/target/impl/util/ExtDomQuery.js.map +1 -1
  34. package/target/impl/xhrCore/ResponseProcessor.js +1 -23
  35. package/target/impl/xhrCore/ResponseProcessor.js.map +1 -1
  36. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +243 -83
  37. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js.map +1 -1
  38. package/target/test/frameworkBase/_ext/shared/StandardInits.js +11 -3
  39. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  40. package/target/test/frameworkBase/_ext/shared/XmlResponses.js +13 -6
  41. package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
  42. package/target/test/xhrCore/ResponseTest.spec.js +25 -10
  43. package/target/test/xhrCore/ResponseTest.spec.js.map +1 -1
@@ -69,7 +69,13 @@ var Submittables;
69
69
  * @param condition the condition lambda to be fulfilled
70
70
  * @param options options for the search
71
71
  */
72
- function waitUntilDom(root, condition, options = { attributes: true, childList: true, subtree: true, timeout: 500, interval: 100 }) {
72
+ function waitUntilDom(root, condition, options = {
73
+ attributes: true,
74
+ childList: true,
75
+ subtree: true,
76
+ timeout: 500,
77
+ interval: 100
78
+ }) {
73
79
  return new Promise((success, error) => {
74
80
  let observer = null;
75
81
  const MUT_ERROR = new Error("Mutation observer timeout");
@@ -1029,33 +1035,8 @@ class DomQuery {
1029
1035
  * @param defer in miliseconds execution default (0 == no defer)
1030
1036
  * @param charSet
1031
1037
  */
1032
- loadScriptEval(src, defer = 0, charSet = "utf-8", nonce) {
1033
- let xhr = new XMLHttpRequest();
1034
- xhr.open("GET", src, false);
1035
- if (charSet) {
1036
- xhr.setRequestHeader("Content-Type", "application/x-javascript; charset:" + charSet);
1037
- }
1038
- xhr.onload = () => {
1039
- //defer also means we have to process after the ajax response
1040
- //has been processed
1041
- //we can achieve that with a small timeout, the timeout
1042
- //triggers after the processing is done!
1043
- if (!defer) {
1044
- this.globalEval(xhr.responseText.replace(/\n/g, "\r\n") + "\r\n//@ sourceURL=" + src, nonce);
1045
- }
1046
- else {
1047
- //TODO not ideal we maybe ought to move to something else here
1048
- //but since it is not in use yet, it is ok
1049
- setTimeout(() => {
1050
- this.globalEval(xhr.responseText + "\r\n//@ sourceURL=" + src, nonce);
1051
- }, defer);
1052
- }
1053
- };
1054
- xhr.onerror = (data) => {
1055
- throw Error(data);
1056
- };
1057
- //since we are synchronous we do it after not with onReadyStateChange
1058
- xhr.send(null);
1038
+ loadScriptEval(src, defer = 0, nonce) {
1039
+ this._loadScriptEval(false, src, defer, nonce);
1059
1040
  return this;
1060
1041
  }
1061
1042
  /**
@@ -1065,33 +1046,46 @@ class DomQuery {
1065
1046
  * @param defer in miliseconds execution default (0 == no defer)
1066
1047
  * @param charSet
1067
1048
  */
1068
- loadScriptEvalSticky(src, defer = 0, charSet = "utf-8", nonce) {
1069
- let xhr = new XMLHttpRequest();
1070
- xhr.open("GET", src, false);
1071
- if (charSet) {
1072
- xhr.setRequestHeader("Content-Type", "application/x-javascript; charset:" + charSet);
1073
- }
1074
- xhr.onload = () => {
1075
- //defer also means we have to process after the ajax response
1076
- //has been processed
1077
- //we can achieve that with a small timeout, the timeout
1078
- //triggers after the processing is done!
1049
+ loadScriptEvalSticky(src, defer = 0, nonce) {
1050
+ this._loadScriptEval(true, src, defer, nonce);
1051
+ return this;
1052
+ }
1053
+ _loadScriptEval(sticky, src, defer = 0, nonce) {
1054
+ let srcNode = this.createSourceNode(src, nonce);
1055
+ let nonceCheck = this.createSourceNode(null, nonce);
1056
+ let marker = `nonce_${Date.now()}_${Math.random()}`;
1057
+ nonceCheck.innerHTML = `document.head["${marker}"] = true`; //noop
1058
+ let head = document.head;
1059
+ // upfront nonce check, needed mostly for testing
1060
+ // but cannot hurt to block src calls which have invalid nonce on localhost
1061
+ // the reason for doing this up until now we have a similar construct automatically
1062
+ // by loading the scripts via xhr and then embedding them.
1063
+ // this is not needed anymore but the nonce is more relaxed with script src
1064
+ // we now enforce it the old way
1065
+ head.appendChild(nonceCheck);
1066
+ head.removeChild(nonceCheck);
1067
+ if (!head[marker]) {
1068
+ return;
1069
+ }
1070
+ try {
1079
1071
  if (!defer) {
1080
- this.globalEvalSticky(xhr.responseText.replace(/\n/g, "\r\n") + "\r\n//@ sourceURL=" + src, nonce);
1072
+ head.appendChild(srcNode);
1073
+ if (!sticky) {
1074
+ head.removeChild(srcNode);
1075
+ }
1081
1076
  }
1082
1077
  else {
1083
- //TODO not ideal we maybe ought to move to something else here
1084
- //but since it is not in use yet, it is ok
1085
1078
  setTimeout(() => {
1086
- this.globalEvalSticky(xhr.responseText + "\r\n//@ sourceURL=" + src, nonce);
1079
+ head.appendChild(srcNode);
1080
+ if (!sticky) {
1081
+ head.removeChild(srcNode);
1082
+ }
1087
1083
  }, defer);
1088
1084
  }
1089
- };
1090
- xhr.onerror = (data) => {
1091
- throw Error(data);
1092
- };
1093
- //since we are synchronous we do it after not with onReadyStateChange
1094
- xhr.send(null);
1085
+ }
1086
+ finally {
1087
+ delete head[marker];
1088
+ }
1095
1089
  return this;
1096
1090
  }
1097
1091
  insertAfter(...toInsertParams) {
@@ -1309,14 +1303,14 @@ class DomQuery {
1309
1303
  //we run the collected scripts before running, the include
1310
1304
  finalScripts = evalCollectedScripts(finalScripts);
1311
1305
  if (!sticky) {
1312
- (!!nonce) ? this.loadScriptEval(src, 0, "UTF-8", nonce) :
1306
+ (!!nonce) ? this.loadScriptEval(src, 0, nonce) :
1313
1307
  //if no nonce is set we do not pass any once
1314
- this.loadScriptEval(src, 0, "UTF-8");
1308
+ this.loadScriptEval(src, 0);
1315
1309
  }
1316
1310
  else {
1317
- (!!nonce) ? this.loadScriptEvalSticky(src, 0, "UTF-8", nonce) :
1311
+ (!!nonce) ? this.loadScriptEvalSticky(src, 0, nonce) :
1318
1312
  //if no nonce is set we do not pass any once
1319
- this.loadScriptEvalSticky(src, 0, "UTF-8");
1313
+ this.loadScriptEvalSticky(src, 0);
1320
1314
  }
1321
1315
  }
1322
1316
  }
@@ -1665,7 +1659,13 @@ class DomQuery {
1665
1659
  * @param condition
1666
1660
  * @param options
1667
1661
  */
1668
- waitUntilDom(condition, options = { attributes: true, childList: true, subtree: true, timeout: 500, interval: 100 }) {
1662
+ waitUntilDom(condition, options = {
1663
+ attributes: true,
1664
+ childList: true,
1665
+ subtree: true,
1666
+ timeout: 500,
1667
+ interval: 100
1668
+ }) {
1669
1669
  return __awaiter(this, void 0, void 0, function* () {
1670
1670
  return waitUntilDom(this, condition, options);
1671
1671
  });
@@ -1781,6 +1781,51 @@ class DomQuery {
1781
1781
  });
1782
1782
  return this;
1783
1783
  }
1784
+ /*[observable](): Observable<DomQuery> {
1785
+ return this.observable;
1786
+ }
1787
+
1788
+ get observable(): Observable<DomQuery> {
1789
+ let observerFunc = (observer:Subscriber<DomQuery>) => {
1790
+ try {
1791
+ this.each(dqNode => {
1792
+ observer.next(dqNode);
1793
+ });
1794
+ } catch (e) {
1795
+ observer.error(e);
1796
+ }
1797
+ };
1798
+ return new Observable(observerFunc);
1799
+ }
1800
+
1801
+ get observableElem(): Observable<Element> {
1802
+ let observerFunc = (observer:Subscriber<Element>) => {
1803
+ try {
1804
+ this.eachElem(node => {
1805
+ observer.next(node);
1806
+ });
1807
+ } catch (e) {
1808
+ observer.error(e);
1809
+ }
1810
+ };
1811
+ return new Observable(observerFunc);
1812
+ }*/
1813
+ createSourceNode(src, nonce) {
1814
+ let srcNode = document.createElement("script");
1815
+ srcNode.type = "text/javascript";
1816
+ if (!!nonce) {
1817
+ if ('undefined' != typeof (srcNode === null || srcNode === void 0 ? void 0 : srcNode.nonce)) {
1818
+ srcNode.nonce = nonce;
1819
+ }
1820
+ else {
1821
+ srcNode.setAttribute("nonce", nonce);
1822
+ }
1823
+ }
1824
+ if (!!src) {
1825
+ srcNode.src = src;
1826
+ }
1827
+ return srcNode;
1828
+ }
1784
1829
  }
1785
1830
  exports.DomQuery = DomQuery;
1786
1831
  DomQuery.absent = new DomQuery();
@@ -5380,7 +5425,7 @@ const IS_FACES_SOURCE = (source) => {
5380
5425
  };
5381
5426
  /**
5382
5427
  * namespace myfaces.testscripts can be used as extension point for internal
5383
- * tests, those will be handled similarly to faces.js regarding
5428
+ * tests, those will be handled similarly to faces.js - regarding
5384
5429
  * reload blocking on ajax requests
5385
5430
  *
5386
5431
  * @param source the source to check
@@ -5490,6 +5535,7 @@ class ExtDomquery extends mona_dish_1.DQ {
5490
5535
  /**
5491
5536
  * decorated run scripts which takes our jsf extensions into consideration
5492
5537
  * (standard DomQuery will let you pass anything)
5538
+ * @param sticky if set to true the internally generated element for the script is left in the dom
5493
5539
  * @param whilteListed
5494
5540
  */
5495
5541
  runScripts(sticky = false, whilteListed) {
@@ -5497,7 +5543,51 @@ class ExtDomquery extends mona_dish_1.DQ {
5497
5543
  var _a;
5498
5544
  return ((_a = whilteListed === null || whilteListed === void 0 ? void 0 : whilteListed(src)) !== null && _a !== void 0 ? _a : true) && !IS_FACES_SOURCE(src) && !IS_INTERNAL_SOURCE(src);
5499
5545
  };
5500
- return super.runScripts(false, whitelistFunc);
5546
+ return super.runScripts(sticky, whitelistFunc);
5547
+ }
5548
+ /**
5549
+ * adds the elements in this ExtDomQuery to the head
5550
+ *
5551
+ * @param suppressDoubleIncludes checks for existing elements in the head before running the insert
5552
+ */
5553
+ runHeadInserts(suppressDoubleIncludes = true) {
5554
+ let head = ExtDomquery.byId(document.head);
5555
+ //automated nonce handling
5556
+ let processedScripts = [];
5557
+ // the idea is only to run head inserts on resources
5558
+ // which do not exist already, that way
5559
+ // we can avoid double includes on subsequent resource
5560
+ // requests.
5561
+ function resourceIsNew(element) {
5562
+ if (!suppressDoubleIncludes) {
5563
+ return true;
5564
+ }
5565
+ const tagName = element.tagName.value;
5566
+ if (!tagName) {
5567
+ // textnode
5568
+ return true;
5569
+ }
5570
+ let href = element.attr("href").orElse(element.attr("src").value);
5571
+ if (!href.isPresent()) {
5572
+ return true;
5573
+ }
5574
+ return !head.querySelectorAll(`${tagName}[href='${href.value}']`).length &&
5575
+ !head.querySelectorAll(`${tagName}[src='${href.value}']`).length;
5576
+ }
5577
+ this
5578
+ .filter(resourceIsNew)
5579
+ .each(element => {
5580
+ if (element.tagName.value != "SCRIPT") {
5581
+ //we need to run runScripts properly to deal with the rest
5582
+ new ExtDomquery(...processedScripts).runScripts(true);
5583
+ processedScripts = [];
5584
+ head.append(element);
5585
+ }
5586
+ else {
5587
+ processedScripts.push(element);
5588
+ }
5589
+ });
5590
+ new ExtDomquery(...processedScripts).runScripts(true);
5501
5591
  }
5502
5592
  /**
5503
5593
  * byId producer
@@ -6633,7 +6723,7 @@ class ResponseProcessor {
6633
6723
  globalEval() {
6634
6724
  // phase one, if we have head inserts, we build up those before going into the script eval phase
6635
6725
  let insertHeadElems = new ExtDomQuery_1.ExtDomquery(...this.internalContext.getIf(Const_1.DEFERRED_HEAD_INSERTS).value);
6636
- this.runHeadInserts(insertHeadElems);
6726
+ insertHeadElems.runHeadInserts(true);
6637
6727
  // phase 2 we run a script eval on all updated elements in the body
6638
6728
  let updateElems = new ExtDomQuery_1.ExtDomquery(...this.internalContext.getIf(Const_1.UPDATE_ELEMS).value);
6639
6729
  updateElems.runCss();
@@ -6783,28 +6873,6 @@ class ResponseProcessor {
6783
6873
  triggerOnError(errorData) {
6784
6874
  this.externalContext.getIf(Const_1.ON_ERROR).orElse(this.internalContext.getIf(Const_1.ON_ERROR).value).orElse(Const_1.EMPTY_FUNC).value(errorData);
6785
6875
  }
6786
- /**
6787
- * adds new elements to the head as per spec, we use it in a deferred way
6788
- * to have the html buildup first then the head inserts which run the head evals
6789
- * and then the body and css evals from the markup
6790
- *
6791
- * This is only performed upon a head replacement or resource insert
6792
- *
6793
- * @param newElements the elements which need addition
6794
- */
6795
- runHeadInserts(newElements) {
6796
- let head = ExtDomQuery_1.ExtDomquery.byId(document.head);
6797
- //automated nonce handling
6798
- newElements.each(element => {
6799
- if (element.tagName.value != "SCRIPT" || element.attr("src").isPresent()) {
6800
- head.append(element);
6801
- return;
6802
- }
6803
- // special corner case
6804
- // embedded script code,
6805
- element.globalEvalSticky(element.innerHTML);
6806
- });
6807
- }
6808
6876
  }
6809
6877
  exports.ResponseProcessor = ResponseProcessor;
6810
6878
 
Binary file
Binary file