jsf.js_next_gen 4.0.0-RC-1 → 4.0.0-RC.2

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 (33) hide show
  1. package/dist/docs/functions/faces.push.init.html +5 -1
  2. package/dist/window/faces-development.js +65 -23
  3. package/dist/window/faces-development.js.br +0 -0
  4. package/dist/window/faces-development.js.gz +0 -0
  5. package/dist/window/faces-development.js.map +1 -1
  6. package/dist/window/faces.js +1 -1
  7. package/dist/window/faces.js.br +0 -0
  8. package/dist/window/faces.js.gz +0 -0
  9. package/dist/window/faces.js.map +1 -1
  10. package/dist/window/jsf-development.js +76 -23
  11. package/dist/window/jsf-development.js.br +0 -0
  12. package/dist/window/jsf-development.js.gz +0 -0
  13. package/dist/window/jsf-development.js.map +1 -1
  14. package/dist/window/jsf.js +1 -1
  15. package/dist/window/jsf.js.br +0 -0
  16. package/dist/window/jsf.js.gz +0 -0
  17. package/dist/window/jsf.js.map +1 -1
  18. package/package.json +1 -1
  19. package/src/main/typescript/api/_api.ts +3 -1
  20. package/src/main/typescript/api/jsf.ts +18 -0
  21. package/src/main/typescript/impl/PushImpl.ts +38 -12
  22. package/src/main/typescript/impl/xhrCore/XhrFormData.ts +24 -12
  23. package/src/main/typescript/test/xhrCore/RequestTest.spec.ts +6 -0
  24. package/target/api/_api.js +3 -2
  25. package/target/api/_api.js.map +1 -1
  26. package/target/api/jsf.js +11 -0
  27. package/target/api/jsf.js.map +1 -1
  28. package/target/impl/PushImpl.js +44 -14
  29. package/target/impl/PushImpl.js.map +1 -1
  30. package/target/impl/xhrCore/XhrFormData.js +18 -7
  31. package/target/impl/xhrCore/XhrFormData.js.map +1 -1
  32. package/target/test/xhrCore/RequestTest.spec.js +5 -0
  33. package/target/test/xhrCore/RequestTest.spec.js.map +1 -1
@@ -19,7 +19,7 @@
19
19
  <h1>Function init</h1></div>
20
20
  <section class="tsd-panel">
21
21
  <ul class="tsd-signatures tsd-kind-function tsd-parent-kind-namespace">
22
- <li class="tsd-signature tsd-anchor-link" id="init">init<span class="tsd-signature-symbol">(</span>socketClientId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, url<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, channel<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, onopen<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, onmessage<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, onclose<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, behaviors<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, autoConnect<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span><a href="#init" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none" id="icon-anchor-a"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" id="icon-anchor-b"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" id="icon-anchor-c"></path></svg></a></li>
22
+ <li class="tsd-signature tsd-anchor-link" id="init">init<span class="tsd-signature-symbol">(</span>socketClientId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, url<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, channel<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, onopen<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, onmessage<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, onerror<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, onclose<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Function</span>, behaviors<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span>, autoConnect<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span><a href="#init" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none" id="icon-anchor-a"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" id="icon-anchor-b"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" id="icon-anchor-c"></path></svg></a></li>
23
23
  <li class="tsd-description">
24
24
  <div class="tsd-parameters">
25
25
  <h4 class="tsd-parameters-title">Parameters</h4>
@@ -45,6 +45,10 @@
45
45
  <div class="tsd-comment tsd-typography"><p>The function to be invoked when a message is received.</p>
46
46
  </div></li>
47
47
  <li>
48
+ <h5>onerror: <span class="tsd-signature-type">Function</span></h5>
49
+ <div class="tsd-comment tsd-typography"><p>The function to be invoked when an error occurs.</p>
50
+ </div></li>
51
+ <li>
48
52
  <h5>onclose: <span class="tsd-signature-type">Function</span></h5>
49
53
  <div class="tsd-comment tsd-typography"><p>The function to be invoked when the web socket is closed.</p>
50
54
  </div></li>
@@ -3907,12 +3907,13 @@ var faces;
3907
3907
  * @param channel the channel name/id
3908
3908
  * @param onopen The function to be invoked when the web socket is opened.
3909
3909
  * @param onmessage The function to be invoked when a message is received.
3910
+ * @param onerror The function to be invoked when an error occurs.
3910
3911
  * @param onclose The function to be invoked when the web socket is closed.
3911
3912
  * @param behaviors functions which are invoked whenever a message is received
3912
3913
  * @param autoConnect Whether or not to automatically open the socket. Defaults to <code>false</code>.
3913
3914
  */
3914
- function init(socketClientId, url, channel, onopen, onmessage, onclose, behaviors, autoConnect) {
3915
- PushImpl_1.PushImpl.init(socketClientId, url, channel, onopen, onmessage, onclose, behaviors, autoConnect);
3915
+ function init(socketClientId, url, channel, onopen, onmessage, onerror, onclose, behaviors, autoConnect) {
3916
+ PushImpl_1.PushImpl.init(socketClientId, url, channel, onopen, onmessage, onerror, onclose, behaviors, autoConnect);
3916
3917
  }
3917
3918
  push.init = init;
3918
3919
  /**
@@ -4622,12 +4623,13 @@ exports.PushImpl = void 0;
4622
4623
  * Typescript port of the faces\.push part in the myfaces implementation
4623
4624
  */
4624
4625
  const Const_1 = __webpack_require__(/*! ./core/Const */ "./src/main/typescript/impl/core/Const.ts");
4626
+ const mona_dish_1 = __webpack_require__(/*! mona-dish */ "./node_modules/mona-dish/src/main/typescript/index_core.ts");
4625
4627
  /**
4626
4628
  * Implementation class for the push functionality
4627
4629
  */
4628
4630
  var PushImpl;
4629
4631
  (function (PushImpl) {
4630
- const URL_PROTOCOL = window.location.protocol.replace("http", "ws") + "//";
4632
+ const URL_PROTOCOL = mona_dish_1.DQ.global().location.protocol.replace("http", "ws") + "//";
4631
4633
  // we expose the member variables for testing purposes
4632
4634
  // they are not directly touched outside of tests
4633
4635
  /* socket map by token */
@@ -4652,14 +4654,15 @@ var PushImpl;
4652
4654
  * @param channel the channel name/id
4653
4655
  * @param onopen The function to be invoked when the web socket is opened.
4654
4656
  * @param onmessage The function to be invoked when a message is received.
4657
+ * @param onerror The function to be invoked when an error occurs.
4655
4658
  * @param onclose The function to be invoked when the web socket is closed.
4656
4659
  * @param behaviors functions which are invoked whenever a message is received
4657
4660
  * @param autoConnect Whether or not to automatically open the socket. Defaults to <code>false</code>.
4658
4661
  */
4659
- function init(socketClientId, url, channel, onopen, onmessage, onclose, behaviors, autoConnect) {
4660
- var _a;
4662
+ function init(socketClientId, url, channel, onopen, onmessage, onerror, onclose, behaviors, autoConnect) {
4663
+ var _a, _b, _c;
4661
4664
  onclose = resolveFunction(onclose);
4662
- if (!window.WebSocket) { // IE6-9.
4665
+ if (!mona_dish_1.DQ.global().WebSocket) { // IE6-9.
4663
4666
  onclose(-1, channel);
4664
4667
  return;
4665
4668
  }
@@ -4669,6 +4672,7 @@ var PushImpl;
4669
4672
  'channelToken': channelToken,
4670
4673
  'onopen': resolveFunction(onopen),
4671
4674
  'onmessage': resolveFunction(onmessage),
4675
+ 'onerror': resolveFunction(onerror),
4672
4676
  'onclose': onclose,
4673
4677
  'behaviors': behaviors,
4674
4678
  'autoconnect': autoConnect
@@ -4682,17 +4686,17 @@ var PushImpl;
4682
4686
  }
4683
4687
  }
4684
4688
  if (autoConnect) {
4685
- ((_a = window === null || window === void 0 ? void 0 : window.faces) !== null && _a !== void 0 ? _a : window === null || window === void 0 ? void 0 : window.jsf).push.open(socketClientId);
4689
+ ((_b = (_a = mona_dish_1.DQ.global()) === null || _a === void 0 ? void 0 : _a.faces) !== null && _b !== void 0 ? _b : (_c = mona_dish_1.DQ.global()) === null || _c === void 0 ? void 0 : _c.jsf).push.open(socketClientId);
4686
4690
  }
4687
4691
  }
4688
4692
  PushImpl.init = init;
4689
4693
  function open(socketClientId) {
4690
4694
  var _a;
4691
- getSocket((_a = PushImpl.components === null || PushImpl.components === void 0 ? void 0 : PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a.channelToken).open();
4695
+ getSocket((_a = PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a.channelToken).open();
4692
4696
  }
4693
4697
  PushImpl.open = open;
4694
4698
  function close(socketClientId) {
4695
- getSocket(PushImpl.components === null || PushImpl.components === void 0 ? void 0 : PushImpl.components[socketClientId].channelToken).close();
4699
+ getSocket(PushImpl.components[socketClientId].channelToken).close();
4696
4700
  }
4697
4701
  PushImpl.close = close;
4698
4702
  // Private helper classes
@@ -4722,28 +4726,53 @@ var PushImpl;
4722
4726
  }
4723
4727
  // noinspection JSUnusedLocalSymbols
4724
4728
  onopen(event) {
4729
+ var _a, _b;
4725
4730
  if (!this.reconnectAttempts) {
4726
4731
  let clientIds = PushImpl.clientIdsByTokens[this.channelToken];
4727
4732
  for (let i = clientIds.length - 1; i >= 0; i--) {
4728
4733
  let socketClientId = clientIds[i];
4729
- PushImpl.components[socketClientId]['onopen'](this.channel);
4734
+ (_b = (_a = PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a['onopen']) === null || _b === void 0 ? void 0 : _b.call(_a, this.channel);
4730
4735
  }
4731
4736
  }
4732
4737
  this.reconnectAttempts = 0;
4733
4738
  }
4739
+ onerror(event) {
4740
+ var _a, _b;
4741
+ let message = JSON.parse(event.data);
4742
+ //TODO replace this with a more readable Stream code
4743
+ for (let i = PushImpl.clientIdsByTokens[this.channelToken].length - 1; i >= 0; i--) {
4744
+ let socketClientId = PushImpl.clientIdsByTokens[this.channelToken][i];
4745
+ if (document.getElementById(socketClientId)) {
4746
+ try {
4747
+ (_b = (_a = PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a['onerror']) === null || _b === void 0 ? void 0 : _b.call(_a, message, this.channel, event);
4748
+ }
4749
+ catch (e) {
4750
+ //Ignore
4751
+ }
4752
+ }
4753
+ else {
4754
+ PushImpl.clientIdsByTokens[this.channelToken].splice(i, 1);
4755
+ }
4756
+ }
4757
+ if (PushImpl.clientIdsByTokens[this.channelToken].length == 0) {
4758
+ // tag disappeared
4759
+ this.close();
4760
+ }
4761
+ }
4734
4762
  onmmessage(event) {
4763
+ var _a, _b, _c;
4735
4764
  let message = JSON.parse(event.data);
4736
4765
  for (let i = PushImpl.clientIdsByTokens[this.channelToken].length - 1; i >= 0; i--) {
4737
4766
  let socketClientId = PushImpl.clientIdsByTokens[this.channelToken][i];
4738
4767
  if (document.getElementById(socketClientId)) {
4739
4768
  try {
4740
- PushImpl.components[socketClientId]['onmessage'](message, this.channel, event);
4769
+ (_b = (_a = PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a['onmessage']) === null || _b === void 0 ? void 0 : _b.call(_a, message, this.channel, event);
4741
4770
  }
4742
4771
  catch (e) {
4743
4772
  //Ignore
4744
4773
  }
4745
- let behaviors = PushImpl.components[socketClientId]['behaviors'];
4746
- let functions = behaviors[message];
4774
+ let behaviors = (_c = PushImpl.components === null || PushImpl.components === void 0 ? void 0 : PushImpl.components[socketClientId]) === null || _c === void 0 ? void 0 : _c['behaviors'];
4775
+ let functions = behaviors === null || behaviors === void 0 ? void 0 : behaviors[message];
4747
4776
  if (functions && functions.length) {
4748
4777
  for (let j = 0; j < functions.length; j++) {
4749
4778
  try {
@@ -4765,6 +4794,7 @@ var PushImpl;
4765
4794
  }
4766
4795
  }
4767
4796
  onclose(event) {
4797
+ var _a, _b;
4768
4798
  if (!this.socket
4769
4799
  || (event.code == 1000 && event.reason == Const_1.REASON_EXPIRED)
4770
4800
  || (event.code == 1008)
@@ -4773,7 +4803,7 @@ var PushImpl;
4773
4803
  let clientIds = PushImpl.clientIdsByTokens[this.channelToken];
4774
4804
  for (let i = clientIds.length - 1; i >= 0; i--) {
4775
4805
  let socketClientId = clientIds[i];
4776
- PushImpl.components[socketClientId]['onclose'](event === null || event === void 0 ? void 0 : event.code, this === null || this === void 0 ? void 0 : this.channel, event);
4806
+ (_b = (_a = PushImpl.components === null || PushImpl.components === void 0 ? void 0 : PushImpl.components[socketClientId]) === null || _a === void 0 ? void 0 : _a['onclose']) === null || _b === void 0 ? void 0 : _b.call(_a, event === null || event === void 0 ? void 0 : event.code, this === null || this === void 0 ? void 0 : this.channel, event);
4777
4807
  }
4778
4808
  }
4779
4809
  else {
@@ -4795,12 +4825,13 @@ var PushImpl;
4795
4825
  this.socket.onopen = (event) => this.onopen(event);
4796
4826
  this.socket.onmessage = (event) => this.onmmessage(event);
4797
4827
  this.socket.onclose = (event) => this.onclose(event);
4828
+ this.socket.onerror = (event) => this.onerror(event);
4798
4829
  }
4799
4830
  }
4800
4831
  // Private static functions ---------------------------------------------------------------------------------------
4801
4832
  function getBaseURL(url) {
4802
4833
  if (url.indexOf("://") < 0) {
4803
- let base = window.location.hostname + ":" + window.location.port;
4834
+ let base = mona_dish_1.DQ.global().location.hostname + ":" + mona_dish_1.DQ.global().location.port;
4804
4835
  return URL_PROTOCOL + base + url;
4805
4836
  }
4806
4837
  else {
@@ -4825,7 +4856,7 @@ var PushImpl;
4825
4856
  }
4826
4857
  function resolveFunction(fn = () => {
4827
4858
  }) {
4828
- return ((typeof fn !== "function") && (fn = window[fn]), fn);
4859
+ return ((typeof fn !== "function") && (fn = mona_dish_1.DQ.global()[fn]), fn);
4829
4860
  }
4830
4861
  })(PushImpl = exports.PushImpl || (exports.PushImpl = {}));
4831
4862
 
@@ -6965,12 +6996,17 @@ class XhrFormData extends mona_dish_1.Config {
6965
6996
  //a call to getViewState before must pass the encoded line
6966
6997
  //a call from getViewState passes the form element as datasource,
6967
6998
  //so we have two call points
6999
+ // atm we basically encode twice, to keep the code leaner
7000
+ // this will be later optmized, practically elements
7001
+ // which are already covered by an external viewstate do not need
7002
+ // the encoding a second time, because they are overwritten by the viewstate again
6968
7003
  if (isString(dataSource)) {
6969
7004
  this.assignEncodedString(this.dataSource);
6970
7005
  }
6971
7006
  else {
6972
7007
  this.applyFormDataToConfig();
6973
7008
  }
7009
+ //now assign the external viewstate overrides
6974
7010
  if ('undefined' != typeof viewState) {
6975
7011
  this.assignEncodedString(viewState);
6976
7012
  }
@@ -6984,23 +7020,26 @@ class XhrFormData extends mona_dish_1.Config {
6984
7020
  * in our ajax request
6985
7021
  */
6986
7022
  postInit(...executes) {
6987
- let fetchInput = (id) => {
7023
+ let fetchFileInputs = (id) => {
7024
+ const INPUT_FILE = "input[type='file']";
6988
7025
  if (id == Const_1.IDENT_ALL) {
6989
- return mona_dish_1.DQ.querySelectorAllDeep("input[type='file']");
7026
+ return mona_dish_1.DQ.querySelectorAllDeep(INPUT_FILE);
6990
7027
  }
6991
7028
  else if (id == Const_1.IDENT_FORM) {
6992
- return this.dataSource.querySelectorAllDeep("input[type='file']");
7029
+ return this.dataSource.matchesSelector(INPUT_FILE) ?
7030
+ this.dataSource :
7031
+ this.dataSource.querySelectorAllDeep(INPUT_FILE);
6993
7032
  }
6994
7033
  else {
6995
7034
  let element = mona_dish_1.DQ.byId(id, true);
6996
- return this.getFileInputs(element);
7035
+ return element.matchesSelector(INPUT_FILE) ? element : this.getFileInputs(element);
6997
7036
  }
6998
7037
  };
6999
7038
  let inputExists = (item) => {
7000
7039
  return item.isPresent();
7001
7040
  };
7002
7041
  this.isMultipartRequest = mona_dish_1.LazyStream.of(...executes)
7003
- .map(fetchInput)
7042
+ .map(fetchFileInputs)
7004
7043
  .filter(inputExists)
7005
7044
  .first().isPresent();
7006
7045
  }
@@ -7038,8 +7077,8 @@ class XhrFormData extends mona_dish_1.Config {
7038
7077
  var _a, _b;
7039
7078
  return keyVal.length < 3 ? [(_a = keyVal === null || keyVal === void 0 ? void 0 : keyVal[0]) !== null && _a !== void 0 ? _a : [], (_b = keyVal === null || keyVal === void 0 ? void 0 : keyVal[1]) !== null && _b !== void 0 ? _b : []] : keyVal;
7040
7079
  }
7080
+ //TODO fix files...
7041
7081
  mona_dish_1.Stream.of(...keyValueEntries)
7042
- //split only the first =
7043
7082
  .map(line => splitToKeyVal(line))
7044
7083
  //special case of having keys without values
7045
7084
  .map(keyVal => fixKeyWithoutVal(keyVal))
@@ -7075,7 +7114,10 @@ class XhrFormData extends mona_dish_1.Config {
7075
7114
  }
7076
7115
  let entries = mona_dish_1.LazyStream.of(...Object.keys(this.value))
7077
7116
  .filter(key => this.value.hasOwnProperty(key))
7078
- .flatMap(key => mona_dish_1.Stream.of(...this.value[key]).map(val => [key, val]).collect(new mona_dish_1.ArrayCollector()))
7117
+ .flatMap(key => mona_dish_1.Stream.of(...this.value[key]).map(val => [key, val])
7118
+ //we cannot encode file elements that is handled by multipart requests anyway
7119
+ .filter(([, value]) => !(value instanceof ExtDomQuery_1.ExtDomQuery.global().File))
7120
+ .collect(new mona_dish_1.ArrayCollector()))
7079
7121
  .map(keyVal => {
7080
7122
  return `${encodeURIComponent(keyVal[0])}=${encodeURIComponent(keyVal[1])}`;
7081
7123
  })
Binary file
Binary file