jsf.js_next_gen 4.0.0-beta-23 → 4.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 (200) hide show
  1. package/.nyc_output/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +1 -0
  2. package/.nyc_output/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +1 -0
  3. package/.nyc_output/processinfo/09ca9ebc-2305-4357-8db9-48ddfc7dfde2.json +1 -0
  4. package/.nyc_output/processinfo/7c496a14-166e-4aa5-85b9-47b22b055ad8.json +1 -0
  5. package/.nyc_output/processinfo/index.json +1 -1
  6. package/README.md +7 -22
  7. package/dist/docs/assets/main.js +56 -52
  8. package/dist/docs/assets/search.js +1 -1
  9. package/dist/docs/assets/style.css +23 -0
  10. package/dist/docs/functions/faces.ajax.addOnError.html +6 -4
  11. package/dist/docs/functions/faces.ajax.addOnEvent.html +2 -0
  12. package/dist/docs/functions/faces.ajax.request.html +7 -7
  13. package/dist/docs/functions/faces.ajax.response.html +0 -1
  14. package/dist/docs/functions/faces.push.close.html +4 -2
  15. package/dist/docs/functions/faces.push.init.html +19 -7
  16. package/dist/docs/functions/faces.push.open.html +4 -2
  17. package/dist/docs/functions/faces.util.chain.html +3 -3
  18. package/dist/docs/functions/myfaces.ab.html +9 -4
  19. package/dist/docs/functions/myfaces.onOnDomReady.html +72 -0
  20. package/dist/docs/index.html +7 -18
  21. package/dist/docs/modules/myfaces.html +3 -1
  22. package/dist/docs/variables/myfaces.oam.html +2 -1
  23. package/dist/window/faces-development.js +2147 -1779
  24. package/dist/window/faces-development.js.br +0 -0
  25. package/dist/window/faces-development.js.gz +0 -0
  26. package/dist/window/faces-development.js.map +1 -1
  27. package/dist/window/faces.js +1 -1
  28. package/dist/window/faces.js.LICENSE.txt +17 -2
  29. package/dist/window/faces.js.br +0 -0
  30. package/dist/window/faces.js.gz +0 -0
  31. package/dist/window/faces.js.map +1 -1
  32. package/dist/window/jsf-development.js +2156 -1777
  33. package/dist/window/jsf-development.js.br +0 -0
  34. package/dist/window/jsf-development.js.gz +0 -0
  35. package/dist/window/jsf-development.js.map +1 -1
  36. package/dist/window/jsf.js +1 -1
  37. package/dist/window/jsf.js.LICENSE.txt +17 -2
  38. package/dist/window/jsf.js.br +0 -0
  39. package/dist/window/jsf.js.gz +0 -0
  40. package/dist/window/jsf.js.map +1 -1
  41. package/package.json +19 -18
  42. package/pom.xml +1 -1
  43. package/src/main/test.xml +23 -0
  44. package/src/main/typescript/@types/definitions/index.d.ts +24 -7
  45. package/src/main/typescript/api/_api.ts +79 -37
  46. package/src/main/typescript/api/jsf.ts +18 -0
  47. package/src/main/typescript/impl/AjaxImpl.ts +168 -78
  48. package/src/main/typescript/impl/PushImpl.ts +63 -38
  49. package/src/main/typescript/impl/core/Const.ts +52 -39
  50. package/src/main/typescript/impl/util/Assertions.ts +16 -8
  51. package/src/main/typescript/impl/util/AsyncQueue.ts +1 -1
  52. package/src/main/typescript/impl/util/AsyncRunnable.ts +4 -4
  53. package/src/main/typescript/impl/util/ExtDomQuery.ts +58 -45
  54. package/src/main/typescript/impl/util/FileUtils.ts +104 -0
  55. package/src/main/typescript/impl/util/HiddenInputBuilder.ts +89 -0
  56. package/src/main/typescript/impl/util/Lang.ts +30 -31
  57. package/src/main/typescript/impl/xhrCore/ErrorData.ts +15 -10
  58. package/src/main/typescript/impl/xhrCore/EventData.ts +2 -2
  59. package/src/main/typescript/impl/xhrCore/IResponseProcessor.ts +25 -11
  60. package/src/main/typescript/impl/xhrCore/RequestDataResolver.ts +78 -32
  61. package/src/main/typescript/impl/xhrCore/ResonseDataResolver.ts +10 -10
  62. package/src/main/typescript/impl/xhrCore/Response.ts +66 -49
  63. package/src/main/typescript/impl/xhrCore/ResponseProcessor.ts +202 -131
  64. package/src/main/typescript/impl/xhrCore/XhrFormData.ts +79 -166
  65. package/src/main/typescript/impl/xhrCore/XhrRequest.ts +80 -68
  66. package/src/main/typescript/myfaces/OamSubmit.ts +29 -13
  67. package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +19 -22
  68. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +108 -1
  69. package/src/main/typescript/test/frameworkBase/_ext/shared/XmlResponses.ts +40 -1
  70. package/src/main/typescript/test/impl/ImplTest.spec.ts +3 -3
  71. package/src/main/typescript/test/impl/ImplTest_23.spec.ts +3 -7
  72. package/src/main/typescript/test/xhrCore/EventTests.spec.ts +1 -1
  73. package/src/main/typescript/test/xhrCore/FileUploadTest.spec.ts +5 -2
  74. package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +203 -0
  75. package/src/main/typescript/test/xhrCore/OamSubmitTest.spec.ts +177 -0
  76. package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +158 -17
  77. package/src/main/typescript/test/xhrCore/RequestTest.spec.ts +242 -11
  78. package/src/main/typescript/test/xhrCore/RequestTest_23.spec.ts +39 -3
  79. package/src/main/typescript/test/xhrCore/ResponseTest.spec.ts +373 -35
  80. package/src/main/typescript/test/xhrCore/ResponseTest23.spec.ts +43 -9
  81. package/src/main/typescript/test/xhrCore/TobagoFileUploadTest.spec.ts +109 -0
  82. package/src/main/typescript/test/xhrCore/XhrFormDataTest.spec.ts +67 -49
  83. package/src/main/typescript/test.xml +6 -0
  84. package/src/main/typescript/tsconfig.json +1 -1
  85. package/src/test/resources/jsf-development.js +1 -1
  86. package/src/tmp/test.html +12 -88
  87. package/target/api/_api.js +72 -31
  88. package/target/api/_api.js.map +1 -1
  89. package/target/api/jsf.js +11 -0
  90. package/target/api/jsf.js.map +1 -1
  91. package/target/classes/com/example/jsfs_js_ts/DecoratedFacesJS.class +0 -0
  92. package/target/classes/com/example/jsfs_js_ts/DecoratingResourceHandlerWrapper.class +0 -0
  93. package/target/classes/com/example/jsfs_js_ts/FacesJSMapFileResourceWrapper.class +0 -0
  94. package/target/classes/com/example/jsfs_js_ts/FacesJSMappingDecorator.class +0 -0
  95. package/target/impl/AjaxImpl.js +144 -59
  96. package/target/impl/AjaxImpl.js.map +1 -1
  97. package/target/impl/PushImpl.js +66 -35
  98. package/target/impl/PushImpl.js.map +1 -1
  99. package/target/impl/core/Const.js +51 -38
  100. package/target/impl/core/Const.js.map +1 -1
  101. package/target/impl/core/Context.js +10 -0
  102. package/target/impl/core/Context.js.map +1 -0
  103. package/target/impl/util/Assertions.js +12 -7
  104. package/target/impl/util/Assertions.js.map +1 -1
  105. package/target/impl/util/AsyncQueue.js.map +1 -1
  106. package/target/impl/util/ExtDomQuery.js +58 -40
  107. package/target/impl/util/ExtDomQuery.js.map +1 -1
  108. package/target/impl/util/FileUtils.js +96 -0
  109. package/target/impl/util/FileUtils.js.map +1 -0
  110. package/target/impl/util/HiddenElementBuilder.js +7 -0
  111. package/target/impl/util/HiddenElementBuilder.js.map +1 -0
  112. package/target/impl/util/HiddenInputBuilder.js +79 -0
  113. package/target/impl/util/HiddenInputBuilder.js.map +1 -0
  114. package/target/impl/util/Lang.js +29 -30
  115. package/target/impl/util/Lang.js.map +1 -1
  116. package/target/impl/util/URLCodec.js +77 -0
  117. package/target/impl/util/URLCodec.js.map +1 -0
  118. package/target/impl/util/XhrQueueController.js +82 -0
  119. package/target/impl/util/XhrQueueController.js.map +1 -0
  120. package/target/impl/xhrCore/ErrorData.js +10 -8
  121. package/target/impl/xhrCore/ErrorData.js.map +1 -1
  122. package/target/impl/xhrCore/EventData.js +1 -1
  123. package/target/impl/xhrCore/EventData.js.map +1 -1
  124. package/target/impl/xhrCore/RequestContext.js +11 -0
  125. package/target/impl/xhrCore/RequestContext.js.map +1 -0
  126. package/target/impl/xhrCore/RequestDataResolver.js +70 -23
  127. package/target/impl/xhrCore/RequestDataResolver.js.map +1 -1
  128. package/target/impl/xhrCore/ResonseDataResolver.js +9 -9
  129. package/target/impl/xhrCore/ResonseDataResolver.js.map +1 -1
  130. package/target/impl/xhrCore/Response.js +44 -29
  131. package/target/impl/xhrCore/Response.js.map +1 -1
  132. package/target/impl/xhrCore/ResponseProcessor.js +182 -116
  133. package/target/impl/xhrCore/ResponseProcessor.js.map +1 -1
  134. package/target/impl/xhrCore/XhrFormData.js +68 -156
  135. package/target/impl/xhrCore/XhrFormData.js.map +1 -1
  136. package/target/impl/xhrCore/XhrQueHandler.js +11 -0
  137. package/target/impl/xhrCore/XhrQueHandler.js.map +1 -0
  138. package/target/impl/xhrCore/XhrQueueController.js +62 -0
  139. package/target/impl/xhrCore/XhrQueueController.js.map +1 -0
  140. package/target/impl/xhrCore/XhrRequest.js +68 -59
  141. package/target/impl/xhrCore/XhrRequest.js.map +1 -1
  142. package/target/myfaces/OamSubmit.js +23 -14
  143. package/target/myfaces/OamSubmit.js.map +1 -1
  144. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +16 -16
  145. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js.map +1 -1
  146. package/target/test/frameworkBase/_ext/monadish/ExtendedArrayTest.spec.js +76 -0
  147. package/target/test/frameworkBase/_ext/monadish/ExtendedArrayTest.spec.js.map +1 -0
  148. package/target/test/frameworkBase/_ext/monadish/markups/tobago-with-header.js +925 -0
  149. package/target/test/frameworkBase/_ext/monadish/markups/tobago-with-header.js.map +1 -0
  150. package/target/test/frameworkBase/_ext/monadish/markups/tobago-without-header.js +112 -0
  151. package/target/test/frameworkBase/_ext/monadish/markups/tobago-without-header.js.map +1 -0
  152. package/target/test/frameworkBase/_ext/shared/StandardInits.js +100 -1
  153. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  154. package/target/test/frameworkBase/_ext/shared/XmlResponses.js +37 -1
  155. package/target/test/frameworkBase/_ext/shared/XmlResponses.js.map +1 -1
  156. package/target/test/impl/ImplTest.spec.js +2 -2
  157. package/target/test/impl/ImplTest.spec.js.map +1 -1
  158. package/target/test/impl/ImplTest_23.spec.js +2 -2
  159. package/target/test/impl/ImplTest_23.spec.js.map +1 -1
  160. package/target/test/myfaces/OnLoadSpec.js +57 -0
  161. package/target/test/myfaces/OnLoadSpec.js.map +1 -0
  162. package/target/test/xhrCore/EventTests.spec.js +1 -1
  163. package/target/test/xhrCore/EventTests.spec.js.map +1 -1
  164. package/target/test/xhrCore/FileUploadTest.spec.js +2 -1
  165. package/target/test/xhrCore/FileUploadTest.spec.js.map +1 -1
  166. package/target/test/xhrCore/NamespacesRequestTest.spec.js +204 -0
  167. package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -0
  168. package/target/test/xhrCore/OamSubmitTest.spec.js +180 -0
  169. package/target/test/xhrCore/OamSubmitTest.spec.js.map +1 -0
  170. package/target/test/xhrCore/RequestParamsTest.spec.js +142 -10
  171. package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
  172. package/target/test/xhrCore/RequestTest.spec.js +217 -9
  173. package/target/test/xhrCore/RequestTest.spec.js.map +1 -1
  174. package/target/test/xhrCore/RequestTest_23.spec.js +34 -2
  175. package/target/test/xhrCore/RequestTest_23.spec.js.map +1 -1
  176. package/target/test/xhrCore/ResponseTest.spec.js +308 -24
  177. package/target/test/xhrCore/ResponseTest.spec.js.map +1 -1
  178. package/target/test/xhrCore/ResponseTest23.spec.js +38 -8
  179. package/target/test/xhrCore/ResponseTest23.spec.js.map +1 -1
  180. package/target/test/xhrCore/TobagoFileUploadTest.spec.js +128 -0
  181. package/target/test/xhrCore/TobagoFileUploadTest.spec.js.map +1 -0
  182. package/target/test/xhrCore/XhrFormDataTest.spec.js +57 -34
  183. package/target/test/xhrCore/XhrFormDataTest.spec.js.map +1 -1
  184. package/target/test-classes/.gz +0 -0
  185. package/target/test-classes/com/example/jsfs_js_ts/JsfsJsTsApplicationTests.class +0 -0
  186. package/target/test-classes/fileuploadtest.html +24 -0
  187. package/target/test-classes/jsf-development.js +3559 -0
  188. package/target/test-classes/jsf-development.js.br +0 -0
  189. package/target/test-classes/jsf-development.js.gz +0 -0
  190. package/target/test-classes/jsf-development.js.map +1 -0
  191. package/target/test-classes/jsf.js +3 -0
  192. package/target/test-classes/jsf.js.br +0 -0
  193. package/target/test-classes/jsf.js.gz +0 -0
  194. package/tmp.xml +36 -0
  195. package/.nyc_output/2303b649-59d9-485c-9228-73b0ec8787a7.json +0 -1
  196. package/.nyc_output/756f2f03-c85b-4cdb-9b92-5799eb45ef1e.json +0 -1
  197. package/.nyc_output/processinfo/2303b649-59d9-485c-9228-73b0ec8787a7.json +0 -1
  198. package/.nyc_output/processinfo/756f2f03-c85b-4cdb-9b92-5799eb45ef1e.json +0 -1
  199. package/target/types/index.js +0 -18
  200. package/target/types/index.js.map +0 -1
@@ -39,9 +39,12 @@ const IS_FACES_SOURCE = (source?: string): boolean => {
39
39
  }
40
40
 
41
41
  /**
42
- * namespace myfaces.testscripts can be used as extension point for internal
43
- * tests, those will be handled similarly to faces.js - regarding
44
- * reload blocking on ajax requests
42
+ * namespace myfaces\.testscripts can be used as extension point for internal
43
+ * tests, those will be handled similarly to faces.js, in regard
44
+ * to reload blocking on ajax requests
45
+ *
46
+ * Note: atm not used, used to be used in the old implementation
47
+ * but still is reserved for now
45
48
  *
46
49
  * @param source the source to check
47
50
  * @constructor
@@ -55,21 +58,21 @@ const ATTR_SRC = 'src';
55
58
 
56
59
  /**
57
60
  * Extension which adds implementation specific
58
- * meta data to our dom query
61
+ * meta-data to our dom query
59
62
  *
60
63
  * Usage
61
64
  * el = new ExtDQ(oldReference)
62
65
  * nonce = el.nonce
63
66
  * windowId = el.getWindowId
64
67
  */
65
- export class ExtDomquery extends DQ {
68
+ export class ExtDomQuery extends DQ {
66
69
 
67
70
  static get windowId() {
68
- return new ExtDomquery(document.body).windowId;
71
+ return new ExtDomQuery(document.body).windowId;
69
72
  }
70
73
 
71
74
  static get nonce(): string {
72
- return new ExtDomquery(document.body).nonce;
75
+ return new ExtDomQuery(document.body).nonce;
73
76
  }
74
77
 
75
78
  get windowId(): string | null {
@@ -112,7 +115,7 @@ export class ExtDomquery extends DQ {
112
115
  let curScript = new DQ(document.currentScript);
113
116
  //since our baseline atm is ie11 we cannot use document.currentScript globally
114
117
  if (!!this.extractNonce(curScript)) {
115
- // fastpath for modern browsers
118
+ // fast-path for modern browsers
116
119
  return this.extractNonce(curScript);
117
120
  }
118
121
  // fallback if the currentScript method fails, we just search the jsf tags for nonce, this is
@@ -130,26 +133,20 @@ export class ExtDomquery extends DQ {
130
133
  return null;
131
134
  }
132
135
 
133
-
134
-
135
- private extractNonce(curScript: DomQuery) {
136
- return (curScript.getAsElem(0).value as HTMLElement)?.nonce ?? curScript.attr("nonce").value;
137
- }
138
-
139
136
  static searchJsfJsFor(item: RegExp): Optional<String> {
140
- return new ExtDomquery(document).searchJsfJsFor(item);
137
+ return new ExtDomQuery(document).searchJsfJsFor(item);
141
138
  }
142
139
 
143
140
  /**
144
- * searches the embedded faces.js for items like separator char etc..
141
+ * searches the embedded faces.js for items like separator char etc.
145
142
  * expects a match as variable under position 1 in the result match
146
- * @param rexp
143
+ * @param regExp
147
144
  */
148
- searchJsfJsFor(rexp: RegExp): Optional<string> {
145
+ searchJsfJsFor(regExp: RegExp): Optional<string> {
149
146
  //perfect application for lazy stream
150
147
  return DQ.querySelectorAll("script[src], link[src]").lazyStream
151
148
  .filter(item => IS_FACES_SOURCE(item.attr(ATTR_SRC).value))
152
- .map(item => item.attr(ATTR_SRC).value.match(rexp))
149
+ .map(item => item.attr(ATTR_SRC).value.match(regExp))
153
150
  .filter(item => item != null && item.length > 1)
154
151
  .map((result: string[]) => {
155
152
  return decodeURIComponent(result[1]);
@@ -157,22 +154,24 @@ export class ExtDomquery extends DQ {
157
154
  }
158
155
 
159
156
  globalEval(code: string, nonce ?: string): DQ {
160
- return new ExtDomquery(super.globalEval(code, nonce ?? this.nonce));
157
+ return new ExtDomQuery(super.globalEval(code, nonce ?? this.nonce));
161
158
  }
162
159
 
160
+ // called from base class runScripts, do not delete
161
+ // noinspection JSUnusedGlobalSymbols
163
162
  globalEvalSticky(code: string, nonce ?: string): DQ {
164
- return new ExtDomquery(super.globalEvalSticky(code, nonce ?? this.nonce));
163
+ return new ExtDomQuery(super.globalEvalSticky(code, nonce ?? this.nonce));
165
164
  }
166
165
 
167
166
  /**
168
167
  * decorated run scripts which takes our jsf extensions into consideration
169
168
  * (standard DomQuery will let you pass anything)
170
169
  * @param sticky if set to true the internally generated element for the script is left in the dom
171
- * @param whilteListed
170
+ * @param whiteListed
172
171
  */
173
- runScripts(sticky = false, whilteListed?: (src: string) => boolean): DomQuery {
172
+ runScripts(sticky = false, whiteListed?: (src: string) => boolean): DomQuery {
174
173
  const whitelistFunc = (src: string): boolean => {
175
- return (whilteListed?.(src) ?? true) && !IS_FACES_SOURCE(src) && !IS_INTERNAL_SOURCE(src);
174
+ return (whiteListed?.(src) ?? true) && !IS_FACES_SOURCE(src) && !IS_INTERNAL_SOURCE(src);
176
175
  };
177
176
  return super.runScripts(sticky, whitelistFunc);
178
177
  }
@@ -183,7 +182,7 @@ export class ExtDomquery extends DQ {
183
182
  * @param suppressDoubleIncludes checks for existing elements in the head before running the insert
184
183
  */
185
184
  runHeadInserts(suppressDoubleIncludes = true): void {
186
- let head = ExtDomquery.byId(document.head);
185
+ let head = ExtDomQuery.byId(document.head);
187
186
  //automated nonce handling
188
187
  let processedScripts = [];
189
188
 
@@ -197,12 +196,13 @@ export class ExtDomquery extends DQ {
197
196
  }
198
197
  const tagName = element.tagName.value;
199
198
  if(!tagName) {
200
- // textnode
199
+ // text node they do not have tag names, so we can process them as they are without
200
+ // any further ado
201
201
  return true;
202
202
  }
203
203
  let reference = element.attr("href")
204
- .orElse(element.attr("src").value)
205
- .orElse(element.attr("rel").value);
204
+ .orElseLazy(() => element.attr("src").value)
205
+ .orElseLazy(() => element.attr("rel").value);
206
206
 
207
207
  if (!reference.isPresent()) {
208
208
  return true;
@@ -217,14 +217,14 @@ export class ExtDomquery extends DQ {
217
217
  .each(element => {
218
218
  if(element.tagName.value != "SCRIPT") {
219
219
  //we need to run runScripts properly to deal with the rest
220
- new ExtDomquery(...processedScripts).runScripts(true);
220
+ new ExtDomQuery(...processedScripts).runScripts(true);
221
221
  processedScripts = [];
222
222
  head.append(element);
223
223
  } else {
224
224
  processedScripts.push(element);
225
225
  }
226
226
  });
227
- new ExtDomquery(...processedScripts).runScripts(true);
227
+ new ExtDomQuery(...processedScripts).runScripts(true);
228
228
  }
229
229
 
230
230
 
@@ -235,15 +235,21 @@ export class ExtDomquery extends DQ {
235
235
  * @param deep whether the search should go into embedded shadow dom elements
236
236
  * @return a DomQuery containing the found elements
237
237
  */
238
- static byId(selector: string | DomQuery | Element, deep = false): DomQuery {
238
+ static byId(selector: string | DomQuery | Element, deep = false): ExtDomQuery {
239
239
  const ret = DomQuery.byId(selector, deep);
240
- return new ExtDomquery(ret);
240
+ return new ExtDomQuery(ret);
241
241
  }
242
242
 
243
+ private extractNonce(curScript: DomQuery) {
244
+ return (curScript.getAsElem(0).value as HTMLElement)?.nonce ?? curScript.attr("nonce").value;
245
+ }
243
246
 
247
+ filter(func: (item: DomQuery) => boolean): ExtDomQuery {
248
+ return new ExtDomQuery(super.filter(func));
249
+ }
244
250
  }
245
251
 
246
- export const ExtDQ = ExtDomquery;
252
+ export const ExtDQ = ExtDomQuery;
247
253
 
248
254
  /**
249
255
  * in order to reduce the number of interception points for the fallbacks we add
@@ -251,18 +257,20 @@ export const ExtDQ = ExtDomquery;
251
257
  */
252
258
  export class ExtConfig extends Config {
253
259
 
260
+ $nspEnabled = true;
261
+
254
262
  constructor(root: any) {
255
263
  super(root);
256
264
  }
257
265
 
258
266
  assignIf(condition: boolean, ...accessPath): IValueHolder<any> {
259
- const acessPathMapped = this.remap(accessPath);
260
- return super.assignIf(condition, ...acessPathMapped);
267
+ const accessPathMapped = this.remap(accessPath);
268
+ return super.assignIf(condition, ...accessPathMapped);
261
269
  }
262
270
 
263
271
  assign(...accessPath): IValueHolder<any> {
264
- const acessPathMapped = this.remap(accessPath);
265
- return super.assign(...acessPathMapped);
272
+ const accessPathMapped = this.remap(accessPath);
273
+ return super.assign(...accessPathMapped);
266
274
  }
267
275
 
268
276
  append(...accessPath): IValueHolder<any> {
@@ -270,13 +278,13 @@ export class ExtConfig extends Config {
270
278
  }
271
279
 
272
280
  appendIf(condition: boolean, ...accessPath): IValueHolder<any> {
273
- const acessPathMapped = this.remap(accessPath);
274
- return super.appendIf(condition, ...acessPathMapped);
281
+ const accessPathMapped = this.remap(accessPath);
282
+ return super.appendIf(condition, ...accessPathMapped);
275
283
  }
276
284
 
277
285
  getIf(...accessPath): Config {
278
- const acessPathMapped = this.remap(accessPath);
279
- return super.getIf(...acessPathMapped);
286
+ const accessPathMapped = this.remap(accessPath);
287
+ return super.getIf(...accessPathMapped);
280
288
  }
281
289
 
282
290
  get(defaultVal: any): Config {
@@ -315,10 +323,15 @@ export class ExtConfig extends Config {
315
323
  return new ExtConfig(super.deepCopy$());
316
324
  }
317
325
 
318
-
319
- private remap(accessPath: any[]) {
326
+ /**
327
+ * helper to remap the namespaces of an array of access paths
328
+ * @param accessPath the access paths to be remapped
329
+ * @private returns an array of access paths with version remapped namespaces
330
+ */
331
+ private remap(accessPath: string[]): string[] {
332
+ if(!this.$nspEnabled) {
333
+ return accessPath;
334
+ }
320
335
  return Stream.of(...accessPath).map(key => $nsp(key)).collect(new ArrayCollector());
321
336
  }
322
-
323
-
324
337
  }
@@ -0,0 +1,104 @@
1
+ import {ArrayCollector, Config, DomQuery, DQ, LazyStream, Stream} from "mona-dish";
2
+ import {ExtDomQuery} from "./ExtDomQuery";
3
+ import {$faces, EMPTY_STR} from "../core/Const";
4
+
5
+ /*
6
+ * various routines for encoding and decoding url parameters
7
+ * into configs and vice versa
8
+ */
9
+
10
+
11
+ /**
12
+ * encodes a given form data into a url encoded string
13
+ * @param formData the form data config object
14
+ * @param paramsMapper the params mapper
15
+ * @param defaultStr a default string if nothing comes out of it
16
+ */
17
+ export function encodeFormData(formData: Config,
18
+ paramsMapper = (inStr, inVal) => [inStr, inVal],
19
+ defaultStr = EMPTY_STR): string {
20
+ if (formData.isAbsent()) {
21
+ return defaultStr;
22
+ }
23
+ const assocValues = formData.value;
24
+
25
+ const expandValueArrAndRename = key => Stream.of(...assocValues[key]).map(val => paramsMapper(key, val));
26
+ const isPropertyKey = key => assocValues.hasOwnProperty(key);
27
+ const isNotFile = ([, value]) => !(value instanceof ExtDomQuery.global().File);
28
+ const mapIntoUrlParam = keyVal => `${encodeURIComponent(keyVal[0])}=${encodeURIComponent(keyVal[1])}`;
29
+
30
+ const entries = LazyStream.of(...Object.keys(assocValues))
31
+ .filter(isPropertyKey)
32
+ .flatMap(expandValueArrAndRename)
33
+ //we cannot encode file elements that is handled by multipart requests anyway
34
+ .filter(isNotFile)
35
+ .map(mapIntoUrlParam)
36
+ .collect(new ArrayCollector());
37
+
38
+ return entries.join("&")
39
+ }
40
+
41
+ /**
42
+ * splits and decodes encoded values into strings containing of key=value
43
+ * @param encoded encoded string
44
+ */
45
+ export function decodeEncodedValues(encoded: string): Stream<string[]> {
46
+ const filterBlanks = item => !!(item || '').replace(/\s+/g, '');
47
+ const splitKeyValuePair = line => {
48
+ let index = line.indexOf("=");
49
+ if (index == -1) {
50
+ return [line];
51
+ }
52
+ return [line.substring(0, index), line.substring(index + 1)];
53
+ };
54
+
55
+ let requestParamEntries = decodeURIComponent(encoded).split(/&/gi);
56
+ return Stream.of(...requestParamEntries)
57
+ .filter(filterBlanks)
58
+ .map(splitKeyValuePair)
59
+ }
60
+
61
+
62
+ /**
63
+ * gets all the input files and their corresponding file objects
64
+ * @param dataSource
65
+ */
66
+ export function resolveFiles(dataSource: DQ): Stream<[string, File]> {
67
+
68
+ const expandFilesArr = ([key, files]) => Stream.of(...files).map(file => [key, file]);
69
+ const remapFileInput = fileInput => [fileInput.name.value || fileInput.id.value, fileInput.filesFromElem(0)];
70
+ return dataSource
71
+ .querySelectorAllDeep("input[type='file']")
72
+ .stream
73
+ .map(remapFileInput)
74
+ .flatMap(expandFilesArr);
75
+ }
76
+
77
+
78
+ export function fixEmmptyParameters(keyVal: any[]): [string, any] {
79
+ return (keyVal.length < 3 ? [keyVal?.[0] ?? [], keyVal?.[1] ?? []] : keyVal) as [string, any];
80
+ }
81
+
82
+ /**
83
+ * returns the decoded viewState from parentItem
84
+ * @param parentItem
85
+ */
86
+ function resolveViewState(parentItem: DomQuery): Stream<string[] | [string, File]> {
87
+ const viewStateStr = $faces().getViewState(parentItem.getAsElem(0).value);
88
+
89
+ // we now need to decode it and then merge it into the target buf
90
+ // which hosts already our overrides (aka do not override what is already there(
91
+ // after that we need to deal with form elements on a separate level
92
+ return decodeEncodedValues(viewStateStr);
93
+ }
94
+
95
+ /**
96
+ * gets all the inputs under the form parentItem
97
+ * as stream
98
+ * @param parentItem
99
+ */
100
+ export function getFormInputsAsStream(parentItem: DomQuery): Stream<string[] | [string, File]> {
101
+ const standardInputs = resolveViewState(parentItem);
102
+ const fileInputs = resolveFiles(parentItem);
103
+ return standardInputs.concat(fileInputs as any)
104
+ }
@@ -0,0 +1,89 @@
1
+ /*! Licensed to the Apache Software Foundation (ASF) under one or more
2
+ * contributor license agreements. See the NOTICE file distributed with
3
+ * this work for additional information regarding copyright ownership.
4
+ * The ASF licenses this file to you under the Apache License, Version 2.0
5
+ * (the "License"); you may not use this file except in compliance with
6
+ * the License. You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import {DomQuery, DQ, DQ$} from "mona-dish";
19
+ import {$faces, $nsp, HTML_CLIENT_WINDOW, HTML_VIEWSTATE, P_CLIENT_WINDOW, P_VIEWSTATE} from "../core/Const";
20
+
21
+ /**
22
+ * Builder for hidden inputs.
23
+ * ATM only ViewState and Client window
24
+ * are supported (per spec)
25
+ *
26
+ * Improves readability in the response processor!
27
+ */
28
+ export class HiddenInputBuilder {
29
+ private namingContainerId?: string;
30
+ private parent?: DomQuery;
31
+ private namedViewRoot: boolean = false;
32
+ private readonly name: string;
33
+ private readonly template: string;
34
+
35
+ constructor(private selector: string) {
36
+ const isViewState = selector.indexOf($nsp(P_VIEWSTATE)) != -1;
37
+ this.name = isViewState ? P_VIEWSTATE : P_CLIENT_WINDOW
38
+ this.template = isViewState ? HTML_VIEWSTATE : HTML_CLIENT_WINDOW
39
+ }
40
+
41
+ withNamingContainerId(namingContainer: string): HiddenInputBuilder {
42
+ this.namingContainerId = namingContainer;
43
+ return this;
44
+ }
45
+
46
+ withParent(parent: DomQuery): HiddenInputBuilder {
47
+ this.parent = parent;
48
+ return this;
49
+ }
50
+
51
+ withNamedViewRoot(namedViewRoot: boolean): HiddenInputBuilder {
52
+ this.namedViewRoot = namedViewRoot;
53
+ return this;
54
+ }
55
+
56
+
57
+ build(): DomQuery {
58
+ const SEP = $faces().separatorchar;
59
+
60
+ let existingStates = DQ$(`[name*='${$nsp(this.name)}']`);
61
+ let cnt = existingStates.stream.map(state => {
62
+ let ident: string = state.id.orElse("-1").value;
63
+ ident = ident.substring(ident.lastIndexOf(SEP)+1);
64
+ return parseInt(ident);
65
+ })
66
+ .filter(item => !isNaN(item))
67
+ .reduce((item1, item2) => Math.max(item1, item2), -1).value;
68
+ //the maximum new ident is the current max + 1
69
+ cnt++;
70
+
71
+
72
+ const newElement = DQ.fromMarkup($nsp(this.template));
73
+ newElement.id.value = ((this.namingContainerId?.length) ?
74
+ [this.namingContainerId, $nsp(this.name), cnt]:
75
+ [$nsp(this.name), cnt]).join(SEP);
76
+
77
+ //name must be prefixed with the naming container id as well according to the jsdocs
78
+ if(this.namedViewRoot) {
79
+ newElement.name.value = (this.namingContainerId?.length) ?
80
+ [this.namingContainerId, $nsp(this.name)].join(SEP): $nsp(this.name);
81
+ } else {
82
+ newElement.name.value = $nsp(this.name);
83
+ }
84
+
85
+
86
+ this?.parent?.append(newElement);
87
+ return newElement;
88
+ }
89
+ }
@@ -13,13 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  *
16
- * todo replace singleton with module definition
17
- *
18
16
  */
19
17
 
20
18
  import {Lang as LangBase, Config, Optional, DomQuery, DQ, Stream} from "mona-dish";
21
19
  import {Messages} from "../i18n/Messages";
22
- import {EMPTY_STR, TAG_FORM} from "../core/Const";
20
+ import {EMPTY_STR, HTML_TAG_FORM} from "../core/Const";
23
21
  import {getEventTarget} from "../xhrCore/RequestDataResolver";
24
22
 
25
23
 
@@ -38,11 +36,11 @@ export module ExtLang {
38
36
 
39
37
  //should be in lang, but for now here to avoid recursive imports, not sure if typescript still has a problem with those
40
38
  /**
41
- * helper function to savely resolve anything
39
+ * helper function to safely resolve anything
42
40
  * this is not an elvis operator, it resolves
43
41
  * a value without exception in a tree and if
44
42
  * it is not resolvable then an optional of
45
- * a default value is restored or Optional.empty
43
+ * a default value is restored or Optional\.empty
46
44
  * if none is given
47
45
  *
48
46
  * usage
@@ -51,7 +49,7 @@ export module ExtLang {
51
49
  * </code>
52
50
  *
53
51
  * @param resolverProducer a lambda which can produce the value
54
- * @param defaultValue an optional default value if the producer failes to produce anything
52
+ * @param defaultValue an optional default value if the producer fails to produce anything
55
53
  * @returns an Optional of the produced value
56
54
  */
57
55
  export function failSaveResolve<T>(resolverProducer: () => T, defaultValue: T = null): Optional<T> {
@@ -75,10 +73,10 @@ export module ExtLang {
75
73
  * returns a given localized message upon a given key
76
74
  * basic java log like templating functionality is included
77
75
  *
78
- * @param {String} key the key for the message
79
- * @param {String} defaultMessage optional default message if none was found
76
+ * @param key the key for the message
77
+ * @param defaultMessage optional default message if none was found
80
78
  *
81
- * Additionally you can pass additional arguments, which are used
79
+ * Additionally, you can pass additional arguments, which are used
82
80
  * in the same way java log templates use the params
83
81
  *
84
82
  * @param templateParams the param list to be filled in
@@ -106,15 +104,15 @@ export module ExtLang {
106
104
  }
107
105
 
108
106
  /**
109
- * creates an exeption with additional internal parameters
107
+ * creates an exception with additional internal parameters
110
108
  * for extra information
111
109
  *
112
110
  * @param error
113
- * @param {String} title the exception title
114
- * @param {String} name the exception name
115
- * @param {String} callerCls the caller class
116
- * @param {String} callFunc the caller function
117
- * @param {String} message the message for the exception
111
+ * @param title the exception title
112
+ * @param name the exception name
113
+ * @param callerCls the caller class
114
+ * @param callFunc the caller function
115
+ * @param message the message for the exception
118
116
  */
119
117
  export function makeException(error: Error, title: string, name: string, callerCls: string, callFunc: string, message: string): Error {
120
118
 
@@ -124,14 +122,14 @@ export module ExtLang {
124
122
 
125
123
  /**
126
124
  * fetches a global config entry
127
- * @param {String} configName the name of the configuration entry
128
- * @param {Object} defaultValue
125
+ * @param configName the name of the configuration entry
126
+ * @param defaultValue
129
127
  *
130
128
  * @return either the config entry or if none is given the default value
131
129
  */
132
130
  export function getGlobalConfig(configName: string, defaultValue: any): any {
133
131
  /**
134
- * note we could use exists but this is an heavy operation, since the config name usually
132
+ * note we could use exists but this is a heavy operation, since the config name usually
135
133
  * given this function here is called very often
136
134
  * is a single entry without . in between we can do the lighter shortcut
137
135
  */
@@ -139,7 +137,7 @@ export module ExtLang {
139
137
  }
140
138
 
141
139
  /**
142
- * fetches the form in an fuzzy manner depending
140
+ * fetches the form in a fuzzy manner depending
143
141
  * on an element or event target.
144
142
  *
145
143
  * The idea is that according to the jsf spec
@@ -148,7 +146,7 @@ export module ExtLang {
148
146
  * This is fine, but since then html5 came into the picture with the form attribute the element
149
147
  * can be anywhere referencing its parent form.
150
148
  *
151
- * Also theoretically you can have the case of an issuing element enclosing a set of forms
149
+ * Also, theoretically you can have the case of an issuing element enclosing a set of forms
152
150
  * (not really often used, but theoretically it could be input button allows to embed html for instance)
153
151
  *
154
152
  * So the idea is not to limit the issuing form determination to the spec case
@@ -160,25 +158,25 @@ export module ExtLang {
160
158
  export function getForm(elem: Element, event ?: Event): DQ | never {
161
159
 
162
160
  let queryElem = new DQ(elem);
163
- let eventTarget = new DQ(getEventTarget(event));
161
+ let eventTarget = (event) ? new DQ(getEventTarget(event)) : DomQuery.absent;
164
162
 
165
- if (queryElem.isTag(TAG_FORM)) {
163
+ if (queryElem.isTag(HTML_TAG_FORM)) {
166
164
  return queryElem;
167
165
  }
168
166
 
169
167
  //html 5 for handling
170
- if (queryElem.attr(TAG_FORM).isPresent()) {
171
- let formId = queryElem.attr(TAG_FORM).value;
168
+ if (queryElem.attr(HTML_TAG_FORM).isPresent()) {
169
+ let formId = queryElem.attr(HTML_TAG_FORM).value;
172
170
  let foundForm = DQ.byId(formId, true);
173
171
  if (foundForm.isPresent()) {
174
172
  return foundForm;
175
173
  }
176
174
  }
177
175
 
178
- let form = queryElem.parents(TAG_FORM)
179
- .orElseLazy(() => queryElem.byTagName(TAG_FORM, true))
180
- .orElseLazy(() => eventTarget.parents(TAG_FORM))
181
- .orElseLazy(() => eventTarget.byTagName(TAG_FORM))
176
+ let form = queryElem.firstParent(HTML_TAG_FORM)
177
+ .orElseLazy(() => queryElem.byTagName(HTML_TAG_FORM, true))
178
+ .orElseLazy(() => eventTarget.firstParent(HTML_TAG_FORM))
179
+ .orElseLazy(() => eventTarget.byTagName(HTML_TAG_FORM))
182
180
  .first();
183
181
 
184
182
  assertFormExists(form);
@@ -190,10 +188,11 @@ export module ExtLang {
190
188
  * gets the local or global options with local ones having higher priority
191
189
  * if no local or global one was found then the default value is given back
192
190
  *
193
- * @param {String} configName the name of the configuration entry
194
- * @param {String} localOptions the local options root for the configuration myfaces as default marker is added implicitely
191
+ * @param configName the name of the configuration entry
192
+ * @param localOptions the local options root for the configuration myfaces as default marker is added
193
+ * implicitly
195
194
  *
196
- * @param {Object} defaultValue
195
+ * @param defaultValue
197
196
  *
198
197
  * @return either the config entry or if none is given the default value
199
198
  */
@@ -14,11 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import {
17
- EMPTY_STR,
17
+ EMPTY_STR, ERROR,
18
18
  ERROR_MESSAGE,
19
19
  ERROR_NAME,
20
20
  RESPONSE_TEXT,
21
- RESPONSE_XML,
21
+ RESPONSE_XML, SERVER_ERROR,
22
22
  SOURCE,
23
23
  STATUS,
24
24
  UNKNOWN
@@ -49,7 +49,8 @@ export enum ErrorType {
49
49
  export class ErrorData extends EventData implements IErrorData {
50
50
 
51
51
  type: string = "error";
52
- source: string;
52
+ source: HTMLElement;
53
+ sourceId: string;
53
54
  errorName: string;
54
55
  errorMessage: string;
55
56
 
@@ -63,12 +64,14 @@ export class ErrorData extends EventData implements IErrorData {
63
64
  serverErrorMessage: string;
64
65
  message: string;
65
66
 
66
- constructor(source: string, errorName: string, errorMessage: string, responseText: string = null, responseXML: any = null, responseCode: string = "200", status: string = "UNKNOWN", type = ErrorType.CLIENT_ERROR) {
67
+ constructor(source: string, errorName: string, errorMessage: string, responseText: string = null, responseXML: any = null, responseCode: string = "200", status: string = "", type = ErrorType.CLIENT_ERROR) {
67
68
  super();
68
- this.source = source;
69
- this.type = "error";
69
+ this.source = document.getElementById(source);
70
+ this.sourceId = source;
71
+ this.type = ERROR;
70
72
  this.errorName = errorName;
71
- this.message = this.errorMessage = errorMessage;
73
+ //tck requires that the type is prefixed to the message itself (jsdoc also) in case of a server error
74
+ this.message = this.errorMessage = (type == SERVER_ERROR) ? type + ": " + errorMessage : errorMessage;
72
75
  this.responseCode = responseCode;
73
76
  this.responseText = responseText;
74
77
  this.status = status;
@@ -81,10 +84,10 @@ export class ErrorData extends EventData implements IErrorData {
81
84
  }
82
85
 
83
86
  static fromClient(e: Error): ErrorData {
84
- return new ErrorData("client", e?.name ?? '', e?.message ?? '', e?.stack ?? '');
87
+ return new ErrorData((e as any)?.source ?? "client", e?.name ?? EMPTY_STR, e?.message ?? EMPTY_STR, e?.stack ?? EMPTY_STR);
85
88
  }
86
89
 
87
- static fromHttpConnection(source: any, name: string, message: string, responseText, responseCode: number, status: string = 'UNKNOWN'): ErrorData {
90
+ static fromHttpConnection(source: any, name: string, message: string, responseText, responseCode: number, status: string = EMPTY_STR): ErrorData {
88
91
  return new ErrorData(source, name, message, responseText, responseCode, `${responseCode}`, status, ErrorType.HTTP_ERROR);
89
92
  }
90
93
 
@@ -98,11 +101,13 @@ export class ErrorData extends EventData implements IErrorData {
98
101
  let status = getMsg(context, STATUS);
99
102
  let responseText = getMsg(context, RESPONSE_TEXT);
100
103
  let responseXML = getMsg(context, RESPONSE_XML);
104
+
105
+
101
106
  return new ErrorData(source, errorName, errorMessage, responseText, responseXML, errorCode + EMPTY_STR, status, errorType);
102
107
  }
103
108
 
104
109
  private static getMsg(context, param) {
105
- return getMessage(context.getIf(param).orElse(UNKNOWN).value);
110
+ return getMessage(context.getIf(param).orElse(EMPTY_STR).value);
106
111
  }
107
112
 
108
113
  static fromServerError(context: Config): ErrorData {
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import {Config, DQ} from "mona-dish";
17
- import {BEGIN, CTX_PARAM_PASS_THR, EVENT, P_PARTIAL_SOURCE, SOURCE} from "../core/Const";
17
+ import {BEGIN, CTX_PARAM_REQ_PASS_THR, EVENT, P_PARTIAL_SOURCE, SOURCE} from "../core/Const";
18
18
 
19
19
  export class EventData implements IEventData{
20
20
  type: string;
@@ -33,7 +33,7 @@ export class EventData implements IEventData{
33
33
 
34
34
  let sourceId: string = context.getIf(SOURCE)
35
35
  .orElseLazy(() => context.getIf(P_PARTIAL_SOURCE).value)
36
- .orElseLazy(() => context.getIf(CTX_PARAM_PASS_THR, P_PARTIAL_SOURCE).value)
36
+ .orElseLazy(() => context.getIf(CTX_PARAM_REQ_PASS_THR, P_PARTIAL_SOURCE).value)
37
37
  .value;
38
38
  if (sourceId) {
39
39
  eventData.source = DQ.byId(sourceId, true).first().value.value;