jsf.js_next_gen 4.0.1-beta.1 → 4.0.1-beta.3

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 (103) hide show
  1. package/README.md +6 -0
  2. package/dist/docs/assets/search.js +1 -1
  3. package/dist/docs/functions/myfaces.ab.html +1 -1
  4. package/dist/docs/functions/{myfaces.onOnDomReady.html → myfaces.onDomReady.html} +5 -5
  5. package/dist/docs/index.html +9 -0
  6. package/dist/docs/modules/myfaces.html +2 -2
  7. package/dist/docs/variables/myfaces.oam.html +1 -1
  8. package/dist/window/faces-development.js +1285 -1295
  9. package/dist/window/faces-development.js.br +0 -0
  10. package/dist/window/faces-development.js.gz +0 -0
  11. package/dist/window/faces-development.js.map +1 -1
  12. package/dist/window/faces.js +1 -1
  13. package/dist/window/faces.js.br +0 -0
  14. package/dist/window/faces.js.gz +0 -0
  15. package/dist/window/faces.js.map +1 -1
  16. package/dist/window/jsf-development.js +1285 -1295
  17. package/dist/window/jsf-development.js.br +0 -0
  18. package/dist/window/jsf-development.js.gz +0 -0
  19. package/dist/window/jsf-development.js.map +1 -1
  20. package/dist/window/jsf.js +1 -1
  21. package/dist/window/jsf.js.br +0 -0
  22. package/dist/window/jsf.js.gz +0 -0
  23. package/dist/window/jsf.js.map +1 -1
  24. package/package.json +5 -5
  25. package/plans for 4.0.1.txt +8 -0
  26. package/src/main/typescript/api/_api.ts +1 -1
  27. package/src/main/typescript/impl/AjaxImpl.ts +60 -44
  28. package/src/main/typescript/impl/core/Const.ts +5 -2
  29. package/src/main/typescript/impl/util/AsyncRunnable.ts +81 -6
  30. package/src/main/typescript/impl/util/ExtDomQuery.ts +7 -9
  31. package/src/main/typescript/impl/util/FileUtils.ts +26 -22
  32. package/src/main/typescript/impl/util/HiddenInputBuilder.ts +7 -3
  33. package/src/main/typescript/impl/util/Lang.ts +61 -4
  34. package/src/main/typescript/impl/util/XhrQueueController.ts +112 -0
  35. package/src/main/typescript/impl/xhrCore/EventData.ts +3 -3
  36. package/src/main/typescript/impl/xhrCore/ResponseProcessor.ts +12 -10
  37. package/src/main/typescript/impl/xhrCore/XhrFormData.ts +32 -19
  38. package/src/main/typescript/impl/xhrCore/XhrRequest.ts +51 -72
  39. package/src/main/typescript/myfaces/OamSubmit.ts +6 -6
  40. package/src/main/typescript/test/frameworkBase/_ext/monadish/DomQueryTest.spec.ts +179 -40
  41. package/src/main/typescript/test/frameworkBase/_ext/monadish/MonadTest.spec.ts +4 -4
  42. package/src/main/typescript/test/frameworkBase/_ext/monadish/fixtures/blank.css +0 -0
  43. package/src/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-with-header.ts +921 -0
  44. package/src/main/typescript/test/frameworkBase/_ext/monadish/markups/tobago-without-header.ts +108 -0
  45. package/src/main/typescript/test/frameworkBase/_ext/shared/StandardInits.ts +3 -2
  46. package/src/main/typescript/test/frameworkBase/_ext/shared/fixtures/jakarta.faces.resource/faces.js.jsf +0 -0
  47. package/src/main/typescript/test/myfaces/OnLoadSpec.ts +52 -0
  48. package/src/main/typescript/test/queue/AsynchronousProbe.ts +5 -5
  49. package/src/main/typescript/test/queue/AsynchronousQueueTest.spec.ts +4 -3
  50. package/src/main/typescript/test/xhrCore/EventTests.spec.ts +28 -22
  51. package/src/main/typescript/test/xhrCore/NamespacesRequestTest.spec.ts +4 -4
  52. package/src/main/typescript/test/xhrCore/RequestParamsTest.spec.ts +2 -2
  53. package/src/main/typescript/test/xhrCore/RequestTest.spec.ts +80 -6
  54. package/src/main/typescript/test/xhrCore/RequestTest_23.spec.ts +6 -1
  55. package/src/main/typescript/test/xhrCore/ResponseTest.spec.ts +23 -22
  56. package/target/api/_api.js +2 -2
  57. package/target/api/_api.js.map +1 -1
  58. package/target/impl/AjaxImpl.js +48 -38
  59. package/target/impl/AjaxImpl.js.map +1 -1
  60. package/target/impl/core/Const.js +7 -5
  61. package/target/impl/core/Const.js.map +1 -1
  62. package/target/impl/util/AsyncRunnable.js +60 -0
  63. package/target/impl/util/AsyncRunnable.js.map +1 -1
  64. package/target/impl/util/ExtDomQuery.js +8 -8
  65. package/target/impl/util/ExtDomQuery.js.map +1 -1
  66. package/target/impl/util/FileUtils.js +21 -20
  67. package/target/impl/util/FileUtils.js.map +1 -1
  68. package/target/impl/util/HiddenInputBuilder.js +7 -3
  69. package/target/impl/util/HiddenInputBuilder.js.map +1 -1
  70. package/target/impl/util/Lang.js +52 -1
  71. package/target/impl/util/Lang.js.map +1 -1
  72. package/target/impl/xhrCore/EventData.js +2 -2
  73. package/target/impl/xhrCore/EventData.js.map +1 -1
  74. package/target/impl/xhrCore/ResponseProcessor.js +9 -7
  75. package/target/impl/xhrCore/ResponseProcessor.js.map +1 -1
  76. package/target/impl/xhrCore/XhrFormData.js +29 -15
  77. package/target/impl/xhrCore/XhrFormData.js.map +1 -1
  78. package/target/impl/xhrCore/XhrRequest.js +43 -64
  79. package/target/impl/xhrCore/XhrRequest.js.map +1 -1
  80. package/target/myfaces/OamSubmit.js +5 -3
  81. package/target/myfaces/OamSubmit.js.map +1 -1
  82. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js +138 -37
  83. package/target/test/frameworkBase/_ext/monadish/DomQueryTest.spec.js.map +1 -1
  84. package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js +4 -4
  85. package/target/test/frameworkBase/_ext/monadish/MonadTest.spec.js.map +1 -1
  86. package/target/test/frameworkBase/_ext/shared/StandardInits.js +3 -2
  87. package/target/test/frameworkBase/_ext/shared/StandardInits.js.map +1 -1
  88. package/target/test/queue/AsynchronousQueueTest.spec.js +3 -3
  89. package/target/test/queue/AsynchronousQueueTest.spec.js.map +1 -1
  90. package/target/test/xhrCore/EventTests.spec.js +26 -19
  91. package/target/test/xhrCore/EventTests.spec.js.map +1 -1
  92. package/target/test/xhrCore/NamespacesRequestTest.spec.js +3 -3
  93. package/target/test/xhrCore/NamespacesRequestTest.spec.js.map +1 -1
  94. package/target/test/xhrCore/RequestParamsTest.spec.js +1 -1
  95. package/target/test/xhrCore/RequestParamsTest.spec.js.map +1 -1
  96. package/target/test/xhrCore/RequestTest.spec.js +73 -4
  97. package/target/test/xhrCore/RequestTest.spec.js.map +1 -1
  98. package/target/test/xhrCore/RequestTest_23.spec.js +6 -0
  99. package/target/test/xhrCore/RequestTest_23.spec.js.map +1 -1
  100. package/target/test/xhrCore/ResponseTest.spec.js +22 -15
  101. package/target/test/xhrCore/ResponseTest.spec.js.map +1 -1
  102. package/src/main/typescript/impl/util/AsyncQueue.ts +0 -133
  103. package/src/main/typescript/test/frameworkBase/_ext/monadish/StreamTest.spec.ts +0 -231
@@ -14,8 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import {AsyncRunnable} from "../util/AsyncRunnable";
18
- import {Config, DQ, DQ$, Stream} from "mona-dish";
17
+ import {AsyncRunnable, IAsyncRunnable} from "../util/AsyncRunnable";
18
+ import {Config, DQ} from "mona-dish";
19
19
  import {Implementation} from "../AjaxImpl";
20
20
 
21
21
  import {XhrFormData} from "./XhrFormData";
@@ -41,7 +41,7 @@ import {
41
41
  STATE_EVT_TIMEOUT,
42
42
  STD_ACCEPT,
43
43
  URL_ENCODED,
44
- VAL_AJAX, IDENT_NONE
44
+ VAL_AJAX, IDENT_NONE, CTX_PARAM_SRC_FRM_ID, CTX_PARAM_SRC_CTL_ID, CTX_PARAM_PPS
45
45
  } from "../core/Const";
46
46
  import {
47
47
  resolveFinalUrl,
@@ -54,6 +54,10 @@ import {ExtConfig} from "../util/ExtDomQuery";
54
54
  /**
55
55
  * Faces XHR Request Wrapper
56
56
  * as AsyncRunnable for our Asynchronous queue
57
+ * This means from the outside the
58
+ * xhr request is similar to a Promise in a way
59
+ * that you can add then and catch and finally callbacks.
60
+ *
57
61
  *
58
62
  * The idea is that we basically just enqueue
59
63
  * a single ajax request into our queue
@@ -62,60 +66,43 @@ import {ExtConfig} from "../util/ExtDomQuery";
62
66
  *
63
67
  */
64
68
 
65
- export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
69
+ export class XhrRequest extends AsyncRunnable<XMLHttpRequest> {
66
70
 
67
71
  private responseContext: Config;
68
72
 
69
73
  private stopProgress = false;
70
74
 
71
- /**
72
- * helper support so that we do not have to drag in Promise shims
73
- */
74
- private catchFunctions: Array<Function> = [];
75
- private thenFunctions: Array<Function> = [];
76
75
 
76
+ private xhrObject = new XMLHttpRequest();
77
77
  /**
78
78
  * Required Parameters
79
79
  *
80
- * @param source the issuing element
81
- * @param sourceForm the form which is related to the issuing element
82
80
  * @param requestContext the request context with all pass through values
83
- *
84
- * Optional Parameters
85
- *
86
81
  * @param internalContext internal context with internal info which is passed through, not used by the user
87
- * @param partialIdsArray an optional restricting partial ids array for encoding
82
+ * Optional Parameters
88
83
  * @param timeout optional xhr timeout
89
84
  * @param ajaxType optional request type, default "POST"
90
85
  * @param contentType optional content type, default "application/x-www-form-urlencoded"
91
- * @param xhrObject optional xhr object which must fulfill the XMLHTTPRequest api, default XMLHttpRequest
92
86
  */
93
87
  constructor(
94
- private source: DQ,
95
- private sourceForm: DQ,
96
88
  private requestContext: ExtConfig,
97
89
  private internalContext: Config,
98
- private partialIdsArray = [],
99
90
  private timeout = NO_TIMEOUT,
100
91
  private ajaxType = REQ_TYPE_POST,
101
- private contentType = URL_ENCODED,
102
- private xhrObject = new XMLHttpRequest()
92
+ private contentType = URL_ENCODED
103
93
  ) {
104
-
94
+ super();
105
95
  // we omit promises here because we have to deal with cancel functionality,
106
96
  // and promises to not provide that (yet) instead we have our async queue
107
97
  // which uses an api internally, which is very close to promises
108
- this.registerXhrCallbacks((data: any) => {
109
- this.resolve(data)
110
- }, (data: any) => {
111
- this.reject(data)
112
- });
98
+ this.registerXhrCallbacks((data: any) => this.resolve(data), (data: any) => this.reject(data));
113
99
  }
114
100
 
115
- start(): AsyncRunnable<XMLHttpRequest> {
101
+ start(): IAsyncRunnable<XMLHttpRequest> {
116
102
 
117
103
  let ignoreErr = failSaveExecute;
118
104
  let xhrObject = this.xhrObject;
105
+ let sourceForm = DQ.byId(this.internalContext.getIf(CTX_PARAM_SRC_FRM_ID).value)
119
106
 
120
107
  let executesArr = () => {
121
108
  return this.requestContext.getIf(CTX_PARAM_REQ_PASS_THR, P_EXECUTE).get(IDENT_NONE).value.split(/\s+/gi);
@@ -130,15 +117,20 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
130
117
  // whatever the formData object delivers
131
118
  // the partialIdsArray arr is almost deprecated legacy code where we allowed to send a separate list of partial
132
119
  // ids for reduced load and server processing, this will be removed soon, we can handle the same via execute
133
- // anyway TODO reimplement the partial ids array, we still do not have it in jsf the way we need it
134
- let formData: XhrFormData = new XhrFormData(this.sourceForm, resoveNamingContainerMapper(this.internalContext), executesArr(), this.partialIdsArray);
120
+ const executes = executesArr();
121
+ const partialIdsArray = this.internalContext.getIf(CTX_PARAM_PPS).value === true ? executes : [];
122
+ const formData: XhrFormData = new XhrFormData(
123
+ sourceForm,
124
+ resoveNamingContainerMapper(this.internalContext),
125
+ executes, partialIdsArray
126
+ );
135
127
 
136
128
  this.contentType = formData.isMultipartRequest ? "undefined" : this.contentType;
137
129
 
138
130
  // next step the pass through parameters are merged in for post params
139
131
  this.requestContext.$nspEnabled = false;
140
- let requestContext = this.requestContext;
141
- let requestPassThroughParams = requestContext.getIf(CTX_PARAM_REQ_PASS_THR) as ExtConfig;
132
+ const requestContext = this.requestContext;
133
+ const requestPassThroughParams = requestContext.getIf(CTX_PARAM_REQ_PASS_THR) as ExtConfig;
142
134
 
143
135
  // we are turning off here the jsf, faces remapping because we are now dealing with
144
136
  // pass-through parameters
@@ -149,6 +141,9 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
149
141
  try {
150
142
  formData.shallowMerge(requestPassThroughParams, true, true);
151
143
  } finally {
144
+ // unfortunately as long as we support
145
+ // both namespaces we have to keep manual control
146
+ // on the key renaming before doing ops like deep copy
152
147
  this.requestContext.$nspEnabled = true;
153
148
  requestPassThroughParams.$nspEnabled = true;
154
149
  }
@@ -156,15 +151,15 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
156
151
  this.responseContext = requestPassThroughParams.deepCopy;
157
152
 
158
153
  // we have to shift the internal passthroughs around to build up our response context
159
- let responseContext = this.responseContext;
154
+ const responseContext = this.responseContext;
160
155
 
161
156
  responseContext.assign(CTX_PARAM_MF_INTERNAL).value = this.internalContext.value;
162
157
 
163
- // per spec the onevent and onerror handlers must be passed through to the response
158
+ // per spec the onEvent and onError handlers must be passed through to the response
164
159
  responseContext.assign(ON_EVENT).value = requestContext.getIf(ON_EVENT).value;
165
160
  responseContext.assign(ON_ERROR).value = requestContext.getIf(ON_ERROR).value;
166
161
 
167
- xhrObject.open(this.ajaxType, resolveFinalUrl(this.sourceForm, formData, this.ajaxType), true);
162
+ xhrObject.open(this.ajaxType, resolveFinalUrl(sourceForm, formData, this.ajaxType), true);
168
163
 
169
164
  // adding timeout
170
165
  this.timeout ? xhrObject.timeout = this.timeout : null;
@@ -194,40 +189,15 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
194
189
 
195
190
  cancel() {
196
191
  try {
192
+ // this causes onError to be called where the error
193
+ // handling takes over
197
194
  this.xhrObject.abort();
198
195
  } catch (e) {
199
196
  this.handleError(e);
200
197
  }
201
198
  }
202
199
 
203
- resolve(data: any) {
204
- Stream.of(...this.thenFunctions).reduce((inputVal: any, thenFunc: any) => {
205
- return thenFunc(inputVal);
206
- }, data);
207
- }
208
200
 
209
- reject(data: any) {
210
- Stream.of(...this.catchFunctions).reduce((inputVal: any, catchFunc: any) => {
211
- return catchFunc(inputVal);
212
- }, data);
213
- }
214
-
215
- catch(func: (data: any) => any): AsyncRunnable<XMLHttpRequest> {
216
- this.catchFunctions.push(func);
217
- return this;
218
- }
219
-
220
- finally(func: () => void): AsyncRunnable<XMLHttpRequest> {
221
- // no ie11 support we probably are going to revert to shims for that one
222
- this.catchFunctions.push(func);
223
- this.thenFunctions.push(func);
224
- return this;
225
- }
226
-
227
- then(func: (data: any) => any): AsyncRunnable<XMLHttpRequest> {
228
- this.thenFunctions.push(func);
229
- return this;
230
- }
231
201
 
232
202
  /**
233
203
  * attaches the internal event and processing
@@ -237,7 +207,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
237
207
  * @param reject
238
208
  */
239
209
  private registerXhrCallbacks(resolve: Consumer<any>, reject: Consumer<any>) {
240
- let xhrObject = this.xhrObject;
210
+ const xhrObject = this.xhrObject;
241
211
 
242
212
  xhrObject.onabort = () => {
243
213
  this.onAbort(reject);
@@ -253,13 +223,17 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
253
223
  };
254
224
  xhrObject.onerror = (errorData: any) => {
255
225
 
256
- // some browsers trigger an error when cancelling a request internally
226
+ // some browsers trigger an error when cancelling a request internally, or when
227
+ // cancel is called from outside
257
228
  // in this case we simply ignore the request and clear up the queue, because
258
229
  // it is not safe anymore to proceed with the current queue
259
230
  // This bypasses a Safari issue where it keeps requests hanging after page unload
260
231
  // and then triggers a cancel error on then instead of just stopping
261
232
  // and clearing the code
262
233
  if(this.isCancelledResponse(this.xhrObject)) {
234
+ /*
235
+ * this triggers the catch chain and after that finally
236
+ */
263
237
  reject();
264
238
  this.stopProgress = true;
265
239
  return;
@@ -307,14 +281,12 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
307
281
 
308
282
  private handleMalFormedXML(resolve: Function) {
309
283
  this.stopProgress = true;
310
- let errorData = {
284
+ const errorData = {
311
285
  type: ERROR,
312
286
  status: MALFORMEDXML,
313
287
  responseCode: 200,
314
288
  responseText: this.xhrObject?.responseText,
315
- // we remap the element just in case it gets replaced
316
- // it will be unremapped
317
- source: this.source.id.value
289
+ source: this.internalContext.getIf(CTX_PARAM_SRC_CTL_ID).value
318
290
  };
319
291
  try {
320
292
  this.handleError(errorData, true);
@@ -331,16 +303,22 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
331
303
  if (this.stopProgress) {
332
304
  return;
333
305
  }
306
+ /**
307
+ * now call the then chain
308
+ */
334
309
  resolve(data);
335
310
  }
336
311
 
337
312
  private onError(errorData: any, reject: Consumer<any>) {
338
313
  this.handleError(errorData);
314
+ /*
315
+ * this triggers the catch chain and after that finally
316
+ */
339
317
  reject();
340
318
  }
341
319
 
342
320
  private sendRequest(formData: XhrFormData) {
343
- let isPost = this.ajaxType != REQ_TYPE_GET;
321
+ const isPost = this.ajaxType != REQ_TYPE_GET;
344
322
  if (formData.isMultipartRequest) {
345
323
  // in case of a multipart request we send in a formData object as body
346
324
  this.xhrObject.send((isPost) ? formData.toFormData() : null);
@@ -354,7 +332,7 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
354
332
  * other helpers
355
333
  */
356
334
  private sendEvent(evtType: string) {
357
- let eventData = EventData.createFromRequest(this.xhrObject, this.requestContext, evtType);
335
+ const eventData = EventData.createFromRequest(this.xhrObject, this.requestContext, evtType);
358
336
  try {
359
337
  // User code error, we might cover
360
338
  // this in onError, but also we cannot swallow it.
@@ -366,14 +344,15 @@ export class XhrRequest implements AsyncRunnable<XMLHttpRequest> {
366
344
  } catch (e) {
367
345
  e.source = e?.source ?? this.requestContext.getIf(SOURCE).value;
368
346
  this.handleError(e);
347
+
369
348
  throw e;
370
349
  }
371
350
  }
372
351
 
373
352
  private handleError(exception, responseFormatError: boolean = false) {
374
- let errorData = (responseFormatError) ? ErrorData.fromHttpConnection(exception.source, exception.type, exception.status, exception.responseText, exception.responseCode, exception.status) : ErrorData.fromClient(exception);
353
+ const errorData = (responseFormatError) ? ErrorData.fromHttpConnection(exception.source, exception.type, exception.status, exception.responseText, exception.responseCode, exception.status) : ErrorData.fromClient(exception);
354
+ const eventHandler = resolveHandlerFunc(this.requestContext, this.responseContext, ON_ERROR);
375
355
 
376
- let eventHandler = resolveHandlerFunc(this.requestContext, this.responseContext, ON_ERROR);
377
356
  Implementation.sendError(errorData, eventHandler);
378
357
  }
379
358
  }
@@ -14,7 +14,8 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import {DQ, Stream} from "mona-dish";
17
+ import {DQ} from "mona-dish";
18
+ import {ExtLang} from "../impl/util/Lang";
18
19
 
19
20
  /**
20
21
  * legacy code to enable various aspects
@@ -28,6 +29,7 @@ import {DQ, Stream} from "mona-dish";
28
29
  * we might move the code over in the future, but for now a straight 1:1 port suffices
29
30
  */
30
31
  export module oam {
32
+ import ofAssoc = ExtLang.ofAssoc;
31
33
  /**
32
34
  * sets a hidden input field
33
35
  * @param formName the formName
@@ -86,8 +88,8 @@ export module oam {
86
88
  if (window?.myfaces?.core?.config?.autoScroll && (window as any)?.getScrolling) {
87
89
  myfaces.oam.setHiddenInput(formName, 'autoScroll', (window as any)?.getScrolling());
88
90
  }
89
- let paramsStream: Stream<[string, any]> = Array.isArray(params) ? Stream.of(...params) : Stream.ofAssoc(params);
90
- paramsStream.each(([key, data]) => myfaces.oam.setHiddenInput(formName, key, data));
91
+ let paramsStream: Array<[string, any]> = Array.isArray(params) ? [...params] : ofAssoc(params);
92
+ paramsStream.forEach(([key, data]) => myfaces.oam.setHiddenInput(formName, key, data));
91
93
 
92
94
  //we call the namespaced function, to allow decoration, via a direct call we would
93
95
  myfaces.oam.setHiddenInput(formName, `${formName}:_idcl`, linkId ?? '');
@@ -102,8 +104,6 @@ export module oam {
102
104
  (form.getAsElem(0).value as HTMLFormElement).setAttribute("target", target);
103
105
  }
104
106
 
105
-
106
-
107
107
  const result = formElement?.onsubmit?.(null);
108
108
 
109
109
  try {
@@ -120,7 +120,7 @@ export module oam {
120
120
  }
121
121
 
122
122
  // noinspection JSUnusedLocalSymbols
123
- paramsStream.each(([key, data]) => {
123
+ paramsStream.forEach(([key, data]) => {
124
124
  myfaces.oam.clearHiddenInput(formName, key);
125
125
  });
126
126
  myfaces.oam.clearHiddenInput(formName, `${formName}:_idcl`);