@sankhyalabs/ezui 1.1.141 → 1.1.142

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 (54) hide show
  1. package/dist/cjs/ez-date-input.cjs.entry.js +16 -5
  2. package/dist/cjs/ez-date-time-input.cjs.entry.js +7 -1
  3. package/dist/cjs/ez-form.cjs.entry.js +53 -8
  4. package/dist/cjs/ez-number-input.cjs.entry.js +8 -1
  5. package/dist/cjs/ez-text-area.cjs.entry.js +35 -22
  6. package/dist/cjs/ez-text-input.cjs.entry.js +11 -9
  7. package/dist/cjs/ez-time-input.cjs.entry.js +5 -0
  8. package/dist/cjs/ez-upload.cjs.entry.js +28 -9
  9. package/dist/collection/components/ez-date-input/ez-date-input.js +49 -5
  10. package/dist/collection/components/ez-date-time-input/ez-date-time-input.js +40 -1
  11. package/dist/collection/components/ez-form/DataBinder.js +54 -8
  12. package/dist/collection/components/ez-form/ez-form.js +0 -1
  13. package/dist/collection/components/ez-number-input/ez-number-input.js +41 -1
  14. package/dist/collection/components/ez-text-area/ez-text-area.js +35 -22
  15. package/dist/collection/components/ez-text-input/ez-text-input.js +11 -9
  16. package/dist/collection/components/ez-time-input/ez-time-input.js +38 -0
  17. package/dist/collection/components/ez-upload/RemoteFile.js +6 -1
  18. package/dist/collection/components/ez-upload/ez-upload.js +36 -8
  19. package/dist/custom-elements/index.js +164 -56
  20. package/dist/esm/ez-date-input.entry.js +16 -5
  21. package/dist/esm/ez-date-time-input.entry.js +7 -1
  22. package/dist/esm/ez-form.entry.js +54 -9
  23. package/dist/esm/ez-number-input.entry.js +8 -1
  24. package/dist/esm/ez-text-area.entry.js +35 -22
  25. package/dist/esm/ez-text-input.entry.js +11 -9
  26. package/dist/esm/ez-time-input.entry.js +5 -0
  27. package/dist/esm/ez-upload.entry.js +28 -9
  28. package/dist/ezui/ezui.esm.js +1 -1
  29. package/dist/ezui/p-140f7085.entry.js +1 -0
  30. package/dist/ezui/p-24e98dc1.entry.js +1 -0
  31. package/dist/ezui/p-49fdfa4b.entry.js +1 -0
  32. package/dist/ezui/p-4fdceb7d.entry.js +1 -0
  33. package/dist/ezui/p-7746460e.entry.js +1 -0
  34. package/dist/ezui/p-87808290.entry.js +1 -0
  35. package/dist/ezui/p-b524dfca.entry.js +1 -0
  36. package/dist/ezui/p-ec21ecce.entry.js +1 -0
  37. package/dist/types/components/ez-date-input/ez-date-input.d.ts +12 -1
  38. package/dist/types/components/ez-date-time-input/ez-date-time-input.d.ts +11 -0
  39. package/dist/types/components/ez-form/DataBinder.d.ts +1 -0
  40. package/dist/types/components/ez-number-input/ez-number-input.d.ts +11 -0
  41. package/dist/types/components/ez-text-area/ez-text-area.d.ts +4 -3
  42. package/dist/types/components/ez-text-input/ez-text-input.d.ts +1 -1
  43. package/dist/types/components/ez-time-input/ez-time-input.d.ts +10 -0
  44. package/dist/types/components/ez-upload/ez-upload.d.ts +5 -0
  45. package/dist/types/components.d.ts +36 -0
  46. package/package.json +1 -1
  47. package/dist/ezui/p-248361f5.entry.js +0 -1
  48. package/dist/ezui/p-347b145b.entry.js +0 -1
  49. package/dist/ezui/p-9b82c2fe.entry.js +0 -1
  50. package/dist/ezui/p-b8d64970.entry.js +0 -1
  51. package/dist/ezui/p-c620258b.entry.js +0 -1
  52. package/dist/ezui/p-cb73bee7.entry.js +0 -1
  53. package/dist/ezui/p-db0981c1.entry.js +0 -1
  54. package/dist/ezui/p-ec8419f1.entry.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import { HTMLElement as HTMLElement$1, createEvent, h, forceUpdate, Host, proxyCustomElement } from '@stencil/core/internal/client';
2
2
  export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';
3
- import { FloatingManager, DateUtils, TimeFormatter, UserInterface, Action, ApplicationContext, DataUnitAction, DataUnit, NumberUtils, DataType, StringUtils, MaskFormatter } from '@sankhyalabs/core';
3
+ import { FloatingManager, DateUtils, TimeFormatter, UserInterface, Action, WaitingChangeException, ApplicationContext, DataUnitAction, DataUnit, NumberUtils, DataType, StringUtils, MaskFormatter } from '@sankhyalabs/core';
4
4
  import { UserInterface as UserInterface$1, SortMode } from '@sankhyalabs/core/dist/dataunit/metadata/UnitMetadata';
5
5
 
6
6
  const ezApplicationCss = "";
@@ -844,6 +844,8 @@ let EzDateInput$1 = class extends HTMLElement$1 {
844
844
  this.__registerHost();
845
845
  this.__attachShadow();
846
846
  this.ezChange = createEvent(this, "ezChange", 7);
847
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
848
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
847
849
  /**
848
850
  * Deixa o campo disponível ou não para uso.
849
851
  */
@@ -857,11 +859,16 @@ let EzDateInput$1 = class extends HTMLElement$1 {
857
859
  this._textInput.label = this.label;
858
860
  }
859
861
  observeErrorMessage() {
860
- this._textInput.errorMessage = this.errorMessage;
861
- }
862
- observeValue() {
863
862
  if (this._textInput) {
864
- this._textInput.value = this.getTextValue(this.value);
863
+ this._textInput.errorMessage = this.errorMessage;
864
+ }
865
+ }
866
+ observeValue(newValue, oldValue) {
867
+ if (newValue != oldValue) {
868
+ if (this._textInput) {
869
+ this.errorMessage = "";
870
+ this._textInput.value = this.getTextValue(this.value);
871
+ }
865
872
  }
866
873
  }
867
874
  /**
@@ -911,12 +918,16 @@ let EzDateInput$1 = class extends HTMLElement$1 {
911
918
  }
912
919
  }
913
920
  else {
921
+ this.ezCancelWaitingChange.emit();
914
922
  this._textInput.errorMessage = "O valor digitado não é uma data válida";
915
923
  }
916
924
  }
917
925
  getTextValue(d) {
918
926
  return d ? new Intl.DateTimeFormat("pt-BR").format(d) : undefined;
919
927
  }
928
+ startChange() {
929
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
930
+ }
920
931
  componentDidLoad() {
921
932
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
922
933
  }
@@ -924,7 +935,7 @@ let EzDateInput$1 = class extends HTMLElement$1 {
924
935
  return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => {
925
936
  if (event.key === "H" || event.key === "h")
926
937
  this.changeValue(new Date());
927
- }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem })));
938
+ }, label: this.label, value: this.getTextValue(this.value), onInput: () => this.startChange(), restrict: "0123456789/", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem })));
928
939
  }
929
940
  get _elem() { return this; }
930
941
  static get watchers() { return {
@@ -943,6 +954,8 @@ let EzDateTimeInput$1 = class extends HTMLElement$1 {
943
954
  this.__registerHost();
944
955
  this.__attachShadow();
945
956
  this.ezChange = createEvent(this, "ezChange", 7);
957
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
958
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
946
959
  /**
947
960
  * Deixa o campo disponível ou não para uso.
948
961
  */
@@ -1048,6 +1061,7 @@ let EzDateTimeInput$1 = class extends HTMLElement$1 {
1048
1061
  }
1049
1062
  }
1050
1063
  else {
1064
+ this.ezCancelWaitingChange.emit();
1051
1065
  this._textInput.errorMessage = "O valor digitado não é uma data válida";
1052
1066
  }
1053
1067
  }
@@ -1062,11 +1076,14 @@ let EzDateTimeInput$1 = class extends HTMLElement$1 {
1062
1076
  };
1063
1077
  return d ? (new Intl.DateTimeFormat('pt-BR', this.showSeconds ? optionsSecond : options).format(d)) : undefined;
1064
1078
  }
1079
+ startChange() {
1080
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
1081
+ }
1065
1082
  componentDidLoad() {
1066
1083
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
1067
1084
  }
1068
1085
  render() {
1069
- return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => { this.onChangeKeyDown(event); }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onFocus: () => this.onFocused(), onClick: () => this.onClicked(), slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.changeValue(this._calendar.value); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem, time: true, showSeconds: this.showSeconds })));
1086
+ return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => { this.onChangeKeyDown(event); }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onInput: () => this.startChange(), onFocus: () => this.onFocused(), onClick: () => this.onClicked(), slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.changeValue(this._calendar.value); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem, time: true, showSeconds: this.showSeconds })));
1070
1087
  }
1071
1088
  get _elem() { return this; }
1072
1089
  static get watchers() { return {
@@ -1880,11 +1897,7 @@ class DataBinder {
1880
1897
  this._dataUnit.unsubscribe(this.onDataUnitEvent);
1881
1898
  }
1882
1899
  updateValue(fieldName, field) {
1883
- const oldValue = field["value"];
1884
- const newValue = this._dataUnit.getFieldValue(fieldName);
1885
- if (oldValue != newValue) {
1886
- field["value"] = newValue;
1887
- }
1900
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
1888
1901
  }
1889
1902
  updateBind(fieldName, field) {
1890
1903
  const oldBind = this._fields.get(fieldName);
@@ -1892,21 +1905,53 @@ class DataBinder {
1892
1905
  oldBind.destroy();
1893
1906
  }
1894
1907
  field["value"] = this._dataUnit.getFieldValue(fieldName);
1895
- this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
1908
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName) => this.cancelWaitingChange(fieldName), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
1896
1909
  this.bindSearchOptionsLoader(fieldName, field);
1897
1910
  this.applyEzUploadContext(fieldName, field);
1898
1911
  }
1899
1912
  changeStarted(fieldName, waitingChange) {
1913
+ /**
1914
+ * se o waitingChange não é blocante, add um event listener pra
1915
+ * fazer o accept da promise
1916
+ *
1917
+ * se não tiver promise no waitingChange, eu crio uma e resolvo no bind
1918
+ *
1919
+ *
1920
+ */
1900
1921
  if (this._dataUnit.records.length === 0) {
1901
1922
  this._dataUnit.addRecord();
1902
1923
  }
1924
+ if (!waitingChange.blocking && waitingChange.promise == undefined) {
1925
+ const bind = this._fields.get(fieldName);
1926
+ if (bind) {
1927
+ waitingChange.promise = new Promise((resolve, reject) => {
1928
+ bind.waitingChangePromiseResolve = resolve;
1929
+ bind.waitingChangePromiseReject = reject;
1930
+ });
1931
+ }
1932
+ }
1903
1933
  this._dataUnit.startChange(fieldName, waitingChange);
1904
1934
  }
1935
+ cancelWaitingChange(fieldName) {
1936
+ if (this._dataUnit.waitingForChange(fieldName)) {
1937
+ this._dataUnit.cancelWaitingChange(fieldName);
1938
+ const bind = this._fields.get(fieldName);
1939
+ if (bind) {
1940
+ bind.rejectWaitingChange(new WaitingChangeException("Change canceled", fieldName));
1941
+ }
1942
+ }
1943
+ }
1905
1944
  setFieldValue(fieldName, newValue) {
1906
1945
  if (this._dataUnit.records.length === 0) {
1907
1946
  this._dataUnit.addRecord();
1908
1947
  }
1909
1948
  this._dataUnit.setFieldValue(fieldName, newValue);
1949
+ if (this._dataUnit.waitingForChange(fieldName)) {
1950
+ const bind = this._fields.get(fieldName);
1951
+ if (bind) {
1952
+ bind.acceptWaitingChange();
1953
+ }
1954
+ }
1910
1955
  }
1911
1956
  bindSearchOptionsLoader(fieldName, field) {
1912
1957
  if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] == undefined) {
@@ -1935,18 +1980,36 @@ class DataBinder {
1935
1980
  class Bind {
1936
1981
  constructor() {
1937
1982
  this.startChangeEventName = "ezStartChange";
1983
+ this.cancelWaitingChangeEventName = "ezCancelWaitingChange";
1938
1984
  this.changeEventName = "ezChange";
1939
1985
  }
1940
1986
  destroy() {
1941
1987
  this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
1988
+ this.field.removeEventListener(this.cancelWaitingChangeEventName, this.cancelWaitingChangeListener);
1942
1989
  this.field.removeEventListener(this.changeEventName, this.changeListener);
1943
1990
  }
1944
- static create(fieldName, field, startChangeCallback, changeCallback) {
1991
+ acceptWaitingChange() {
1992
+ if (this.waitingChangePromiseResolve) {
1993
+ this.waitingChangePromiseResolve();
1994
+ this.waitingChangePromiseReject = undefined;
1995
+ this.waitingChangePromiseResolve = undefined;
1996
+ }
1997
+ }
1998
+ rejectWaitingChange(reason) {
1999
+ if (this.waitingChangePromiseReject) {
2000
+ this.waitingChangePromiseReject(reason);
2001
+ this.waitingChangePromiseReject = undefined;
2002
+ this.waitingChangePromiseResolve = undefined;
2003
+ }
2004
+ }
2005
+ static create(fieldName, field, startChangeCallback, cancelWaitingChangeCallback, changeCallback) {
1945
2006
  const b = new Bind();
1946
2007
  b.field = field;
1947
2008
  b.fieldName = fieldName;
1948
2009
  b.startChangeListener = (evt) => { startChangeCallback(fieldName, evt.detail); };
1949
2010
  b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
2011
+ b.cancelWaitingChangeListener = () => { cancelWaitingChangeCallback(fieldName); };
2012
+ b.field.addEventListener(b.cancelWaitingChangeEventName, b.cancelWaitingChangeListener);
1950
2013
  b.changeListener = (evt) => { changeCallback(fieldName, evt.detail); };
1951
2014
  b.field.addEventListener(b.changeEventName, b.changeListener);
1952
2015
  return b;
@@ -2091,7 +2154,6 @@ let EzForm$1 = class extends HTMLElement$1 {
2091
2154
  }
2092
2155
  }
2093
2156
  if (action.type === Action.RECORDS_ADDED) {
2094
- debugger;
2095
2157
  const metadata = selectFormMetadata(this._store.getState());
2096
2158
  const defaultValues = metadata.getDefaultValues();
2097
2159
  if (defaultValues) {
@@ -113638,6 +113700,8 @@ let EzNumberInput$1 = class extends HTMLElement$1 {
113638
113700
  this.__registerHost();
113639
113701
  this.__attachShadow();
113640
113702
  this.ezChange = createEvent(this, "ezChange", 7);
113703
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
113704
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
113641
113705
  /**
113642
113706
  * Deixa o campo disponível ou não para uso.
113643
113707
  */
@@ -113687,6 +113751,7 @@ let EzNumberInput$1 = class extends HTMLElement$1 {
113687
113751
  parseNumber() {
113688
113752
  const parsedNumber = this._textInput.value ? NumberUtils.stringToNumber(this._textInput.value) : undefined;
113689
113753
  if (parsedNumber !== undefined && isNaN(parsedNumber)) {
113754
+ this.ezCancelWaitingChange.emit();
113690
113755
  this.errorMessage = "O valor digitado não é um número válido";
113691
113756
  }
113692
113757
  else {
@@ -113694,6 +113759,7 @@ let EzNumberInput$1 = class extends HTMLElement$1 {
113694
113759
  this.changeValue(parsedNumber);
113695
113760
  }
113696
113761
  catch (e) {
113762
+ this.ezCancelWaitingChange.emit();
113697
113763
  this.errorMessage = e.message;
113698
113764
  return;
113699
113765
  }
@@ -113705,11 +113771,14 @@ let EzNumberInput$1 = class extends HTMLElement$1 {
113705
113771
  }
113706
113772
  return undefined;
113707
113773
  }
113774
+ startChange() {
113775
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
113776
+ }
113708
113777
  componentDidLoad() {
113709
113778
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
113710
113779
  }
113711
113780
  render() {
113712
- return (h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseNumber(), label: this.label, value: this.getTextValue(this.value), restrict: this.precision > 0 ? "0123456789-,." : "0123456789-", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }));
113781
+ return (h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseNumber(), label: this.label, onInput: () => this.startChange(), value: this.getTextValue(this.value), restrict: this.precision > 0 ? "0123456789-,." : "0123456789-", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }));
113713
113782
  }
113714
113783
  get _elem() { return this; }
113715
113784
  static get watchers() { return {
@@ -114192,11 +114261,17 @@ let EzTextArea$1 = class extends HTMLElement$1 {
114192
114261
  (_b = this._messageBoxElem) === null || _b === void 0 ? void 0 : _b.classList.remove('hasError');
114193
114262
  }
114194
114263
  }
114195
- observeValue() {
114196
- this._inputElem.value = this.value == undefined ? "" : this.value;
114197
- this.handleChange();
114198
- this.adjustFloatingLabel();
114199
- this.ezChange.emit(this.value);
114264
+ observeValue(newValue, oldValue) {
114265
+ if (this._inputElem) {
114266
+ if (newValue != oldValue) {
114267
+ if (this.canChangeValue()) {
114268
+ this._inputElem.value = this.value || "";
114269
+ }
114270
+ this.adjustFloatingLabel();
114271
+ this.errorMessage = "";
114272
+ this.ezChange.emit(this.value);
114273
+ }
114274
+ }
114200
114275
  }
114201
114276
  observeMode() {
114202
114277
  if (this._initialRows == undefined) {
@@ -114214,6 +114289,27 @@ let EzTextArea$1 = class extends HTMLElement$1 {
114214
114289
  this._initialRows = rows;
114215
114290
  }
114216
114291
  }
114292
+ //---------------------------------------------
114293
+ // Public methods
114294
+ //---------------------------------------------
114295
+ /**
114296
+ * Faz o foco no componente de input
114297
+ */
114298
+ async setFocus() {
114299
+ this._inputElem.focus();
114300
+ }
114301
+ /**
114302
+ * Remove o foco no componente de input
114303
+ */
114304
+ async setBlur() {
114305
+ this._inputElem.blur();
114306
+ }
114307
+ //---------------------------------------------
114308
+ // Private methods
114309
+ //---------------------------------------------
114310
+ canChangeValue() {
114311
+ return this._inputElem && (this.value || "") !== this._inputElem.value;
114312
+ }
114217
114313
  adjustFloatingLabel() {
114218
114314
  if (this.label && this._labelElem) {
114219
114315
  const hasValue = this.value && this.value.toString().length > 0;
@@ -114234,21 +114330,6 @@ let EzTextArea$1 = class extends HTMLElement$1 {
114234
114330
  return this._hostElement.shadowRoot.activeElement !== null;
114235
114331
  }
114236
114332
  //---------------------------------------------
114237
- // Public methods
114238
- //---------------------------------------------
114239
- /**
114240
- * Faz o foco no componente de input
114241
- */
114242
- async setFocus() {
114243
- this._inputElem.focus();
114244
- }
114245
- /**
114246
- * Remove o foco no componente de input
114247
- */
114248
- async setBlur() {
114249
- this._inputElem.blur();
114250
- }
114251
- //---------------------------------------------
114252
114333
  // Event handlers
114253
114334
  //---------------------------------------------
114254
114335
  handleFocusout() {
@@ -114258,8 +114339,9 @@ let EzTextArea$1 = class extends HTMLElement$1 {
114258
114339
  }
114259
114340
  }
114260
114341
  handleChange() {
114261
- this.errorMessage = "";
114262
- this.value = this._inputElem.value;
114342
+ if (this.canChangeValue()) {
114343
+ this.value = this._inputElem.value;
114344
+ }
114263
114345
  }
114264
114346
  handleFocus() {
114265
114347
  if (this.label && this._labelElem && !this._labelElem.classList.contains("textarea__label--floated")) {
@@ -114342,17 +114424,19 @@ let EzTextInput$1 = class extends HTMLElement$1 {
114342
114424
  }
114343
114425
  }
114344
114426
  }
114345
- observeValue() {
114427
+ observeValue(newValue, oldValue) {
114346
114428
  if (this._inputElem) {
114347
- this._inputElem.value = this.value || "";
114348
- }
114349
- this.handleChange();
114350
- this.adjustFloatingLabel();
114351
- if (this.slaveMode) {
114352
- return;
114429
+ if (newValue != oldValue) {
114430
+ this._inputElem.value = this.value || "";
114431
+ this.handleChange();
114432
+ this.adjustFloatingLabel();
114433
+ if (this.slaveMode) {
114434
+ return;
114435
+ }
114436
+ this.errorMessage = "";
114437
+ this.ezChange.emit(this.value);
114438
+ }
114353
114439
  }
114354
- this.errorMessage = "";
114355
- this.ezChange.emit(this.value);
114356
114440
  }
114357
114441
  adjustFloatingLabel() {
114358
114442
  if (this.label && this._labelElem) {
@@ -114515,6 +114599,8 @@ let EzTimeInput$1 = class extends HTMLElement$1 {
114515
114599
  this.__registerHost();
114516
114600
  this.__attachShadow();
114517
114601
  this.ezChange = createEvent(this, "ezChange", 7);
114602
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
114603
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
114518
114604
  /**
114519
114605
  * Deixa o campo disponível ou não para digitação.
114520
114606
  */
@@ -114575,10 +114661,12 @@ let EzTimeInput$1 = class extends HTMLElement$1 {
114575
114661
  this.prepareValue(this.viewValue);
114576
114662
  if (this.viewValue && !TimeFormatter.validateTime(this.viewValue, this.showSeconds)) {
114577
114663
  this._oldViewValue = this.viewValue;
114664
+ this.ezCancelWaitingChange.emit();
114578
114665
  this.errorMessage = "Favor inserir um horário válido.";
114579
114666
  }
114580
114667
  else {
114581
114668
  if (this.viewValue === this._oldViewValue) {
114669
+ this.ezCancelWaitingChange.emit();
114582
114670
  return;
114583
114671
  }
114584
114672
  this._oldViewValue = this.viewValue;
@@ -114597,6 +114685,7 @@ let EzTimeInput$1 = class extends HTMLElement$1 {
114597
114685
  }
114598
114686
  }
114599
114687
  handleChange() {
114688
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
114600
114689
  this.viewValue = this._inputElem.value;
114601
114690
  this.value = NumberUtils.stringToNumber(this.viewValue.replace(/\D/g, ""));
114602
114691
  }
@@ -114756,7 +114845,12 @@ class RemoteFile {
114756
114845
  }
114757
114846
  const response = xhr.response;
114758
114847
  if (response) {
114759
- resolve(JSON.parse(response));
114848
+ try {
114849
+ resolve(JSON.parse(response));
114850
+ }
114851
+ catch (error) {
114852
+ reject(`Servidor não retornou um objeto válido: ${response}.\n${error}`);
114853
+ }
114760
114854
  }
114761
114855
  }
114762
114856
  };
@@ -114810,6 +114904,7 @@ let EzUpload$1 = class extends HTMLElement$1 {
114810
114904
  this.__attachShadow();
114811
114905
  this.ezChange = createEvent(this, "ezChange", 7);
114812
114906
  this.ezStartChange = createEvent(this, "ezStartChange", 7);
114907
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
114813
114908
  this._filePointers = new Map();
114814
114909
  /**
114815
114910
  * Deixa o campo disponível ou não para digitação.
@@ -114898,14 +114993,27 @@ let EzUpload$1 = class extends HTMLElement$1 {
114898
114993
  }
114899
114994
  }
114900
114995
  async doAddFile(file) {
114901
- if (this.validateFile(file)) {
114902
- this.ezStartChange.emit({ waitmessage: "Há arquivos sendo enviados. Por favor aguarde a conclusão ou cancele o envio." });
114903
- const uploadingFile = new RemoteFile(file);
114904
- this._filePointers.set(file.name, uploadingFile);
114905
- uploadingFile.upload(this.urlUpload, this._requestHeaders, (file) => this.updateFeedback(file))
114906
- .then((files) => files.forEach(ezFile => this.finishUpload(ezFile)))
114907
- .catch(msg => this.showError(msg));
114908
- forceUpdate(this);
114996
+ try {
114997
+ if (this.validateFile(file)) {
114998
+ this.ezStartChange.emit({ waitmessage: "Há arquivos sendo enviados. Por favor aguarde a conclusão ou cancele o envio.", blocking: true });
114999
+ const uploadingFile = new RemoteFile(file);
115000
+ const oldPointer = this._filePointers.get(file.name);
115001
+ if (oldPointer && this.isRemoteFile(oldPointer)) {
115002
+ oldPointer.abortUpload();
115003
+ }
115004
+ this._filePointers.set(file.name, uploadingFile);
115005
+ uploadingFile.upload(this.urlUpload, this._requestHeaders, (file) => this.updateFeedback(file))
115006
+ .then((files) => files.forEach(ezFile => this.finishUpload(ezFile)))
115007
+ .catch(msg => {
115008
+ this.ezCancelWaitingChange.emit();
115009
+ this.showError(msg);
115010
+ });
115011
+ forceUpdate(this);
115012
+ }
115013
+ }
115014
+ catch (error) {
115015
+ this.ezCancelWaitingChange.emit();
115016
+ throw error;
114909
115017
  }
114910
115018
  }
114911
115019
  finishUpload(ezFile) {
@@ -8,6 +8,8 @@ let EzDateInput = class {
8
8
  constructor(hostRef) {
9
9
  registerInstance(this, hostRef);
10
10
  this.ezChange = createEvent(this, "ezChange", 7);
11
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
12
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
11
13
  /**
12
14
  * Deixa o campo disponível ou não para uso.
13
15
  */
@@ -21,11 +23,16 @@ let EzDateInput = class {
21
23
  this._textInput.label = this.label;
22
24
  }
23
25
  observeErrorMessage() {
24
- this._textInput.errorMessage = this.errorMessage;
25
- }
26
- observeValue() {
27
26
  if (this._textInput) {
28
- this._textInput.value = this.getTextValue(this.value);
27
+ this._textInput.errorMessage = this.errorMessage;
28
+ }
29
+ }
30
+ observeValue(newValue, oldValue) {
31
+ if (newValue != oldValue) {
32
+ if (this._textInput) {
33
+ this.errorMessage = "";
34
+ this._textInput.value = this.getTextValue(this.value);
35
+ }
29
36
  }
30
37
  }
31
38
  /**
@@ -75,12 +82,16 @@ let EzDateInput = class {
75
82
  }
76
83
  }
77
84
  else {
85
+ this.ezCancelWaitingChange.emit();
78
86
  this._textInput.errorMessage = "O valor digitado não é uma data válida";
79
87
  }
80
88
  }
81
89
  getTextValue(d) {
82
90
  return d ? new Intl.DateTimeFormat("pt-BR").format(d) : undefined;
83
91
  }
92
+ startChange() {
93
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
94
+ }
84
95
  componentDidLoad() {
85
96
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
86
97
  }
@@ -88,7 +99,7 @@ let EzDateInput = class {
88
99
  return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => {
89
100
  if (event.key === "H" || event.key === "h")
90
101
  this.changeValue(new Date());
91
- }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem })));
102
+ }, label: this.label, value: this.getTextValue(this.value), onInput: () => this.startChange(), restrict: "0123456789/", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.hideCalendar(); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem })));
92
103
  }
93
104
  get _elem() { return getElement(this); }
94
105
  static get watchers() { return {
@@ -8,6 +8,8 @@ let EzDateTimeInput = class {
8
8
  constructor(hostRef) {
9
9
  registerInstance(this, hostRef);
10
10
  this.ezChange = createEvent(this, "ezChange", 7);
11
+ this.ezStartChange = createEvent(this, "ezStartChange", 7);
12
+ this.ezCancelWaitingChange = createEvent(this, "ezCancelWaitingChange", 7);
11
13
  /**
12
14
  * Deixa o campo disponível ou não para uso.
13
15
  */
@@ -113,6 +115,7 @@ let EzDateTimeInput = class {
113
115
  }
114
116
  }
115
117
  else {
118
+ this.ezCancelWaitingChange.emit();
116
119
  this._textInput.errorMessage = "O valor digitado não é uma data válida";
117
120
  }
118
121
  }
@@ -127,11 +130,14 @@ let EzDateTimeInput = class {
127
130
  };
128
131
  return d ? (new Intl.DateTimeFormat('pt-BR', this.showSeconds ? optionsSecond : options).format(d)) : undefined;
129
132
  }
133
+ startChange() {
134
+ this.ezStartChange.emit({ waitmessage: "", blocking: false });
135
+ }
130
136
  componentDidLoad() {
131
137
  CSSVarsUtils.applyVarsTextInput(this._elem, this._textInput);
132
138
  }
133
139
  render() {
134
- return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => { this.onChangeKeyDown(event); }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onFocus: () => this.onFocused(), onClick: () => this.onClicked(), slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.changeValue(this._calendar.value); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem, time: true, showSeconds: this.showSeconds })));
140
+ return (h(Host, null, h("ez-text-input", { ref: elem => this._textInput = elem, onBlur: () => this.parseDate(), onKeyDown: event => { this.onChangeKeyDown(event); }, label: this.label, value: this.getTextValue(this.value), restrict: "0123456789/: ", enabled: this.enabled, errorMessage: this.errorMessage, mode: this.mode, onInput: () => this.startChange(), onFocus: () => this.onFocused(), onClick: () => this.onClicked(), slaveMode: true }, h("button", { disabled: !this.enabled, tabindex: -1, class: "btn-open-cal", onClick: () => this.showCalendar(), slot: "leftIcon" })), h("ez-calendar", { onEzChange: (event) => { this.changeValue(this._calendar.value); event.stopPropagation(); }, floating: true, ref: elem => this._calendar = elem, time: true, showSeconds: this.showSeconds })));
135
141
  }
136
142
  get _elem() { return getElement(this); }
137
143
  static get watchers() { return {
@@ -1,5 +1,5 @@
1
1
  import { h, r as registerInstance, c as createEvent, f as forceUpdate, H as Host, g as getElement } from './index-b21f0a10.js';
2
- import { UserInterface, Action, ApplicationContext, DataUnitAction, DataUnit } from '@sankhyalabs/core';
2
+ import { UserInterface, Action, WaitingChangeException, ApplicationContext, DataUnitAction, DataUnit } from '@sankhyalabs/core';
3
3
  import { A as ApplicationUtils } from './ApplicationUtils-35350d20.js';
4
4
 
5
5
  const buildTextArea = ({ name, label, readOnly }) => {
@@ -650,11 +650,7 @@ class DataBinder {
650
650
  this._dataUnit.unsubscribe(this.onDataUnitEvent);
651
651
  }
652
652
  updateValue(fieldName, field) {
653
- const oldValue = field["value"];
654
- const newValue = this._dataUnit.getFieldValue(fieldName);
655
- if (oldValue != newValue) {
656
- field["value"] = newValue;
657
- }
653
+ field["value"] = this._dataUnit.getFieldValue(fieldName);
658
654
  }
659
655
  updateBind(fieldName, field) {
660
656
  const oldBind = this._fields.get(fieldName);
@@ -662,21 +658,53 @@ class DataBinder {
662
658
  oldBind.destroy();
663
659
  }
664
660
  field["value"] = this._dataUnit.getFieldValue(fieldName);
665
- this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
661
+ this._fields.set(fieldName, Bind.create(fieldName, field, (fieldName, waitingChange) => this.changeStarted(fieldName, waitingChange), (fieldName) => this.cancelWaitingChange(fieldName), (fieldName, newValue) => this.setFieldValue(fieldName, newValue)));
666
662
  this.bindSearchOptionsLoader(fieldName, field);
667
663
  this.applyEzUploadContext(fieldName, field);
668
664
  }
669
665
  changeStarted(fieldName, waitingChange) {
666
+ /**
667
+ * se o waitingChange não é blocante, add um event listener pra
668
+ * fazer o accept da promise
669
+ *
670
+ * se não tiver promise no waitingChange, eu crio uma e resolvo no bind
671
+ *
672
+ *
673
+ */
670
674
  if (this._dataUnit.records.length === 0) {
671
675
  this._dataUnit.addRecord();
672
676
  }
677
+ if (!waitingChange.blocking && waitingChange.promise == undefined) {
678
+ const bind = this._fields.get(fieldName);
679
+ if (bind) {
680
+ waitingChange.promise = new Promise((resolve, reject) => {
681
+ bind.waitingChangePromiseResolve = resolve;
682
+ bind.waitingChangePromiseReject = reject;
683
+ });
684
+ }
685
+ }
673
686
  this._dataUnit.startChange(fieldName, waitingChange);
674
687
  }
688
+ cancelWaitingChange(fieldName) {
689
+ if (this._dataUnit.waitingForChange(fieldName)) {
690
+ this._dataUnit.cancelWaitingChange(fieldName);
691
+ const bind = this._fields.get(fieldName);
692
+ if (bind) {
693
+ bind.rejectWaitingChange(new WaitingChangeException("Change canceled", fieldName));
694
+ }
695
+ }
696
+ }
675
697
  setFieldValue(fieldName, newValue) {
676
698
  if (this._dataUnit.records.length === 0) {
677
699
  this._dataUnit.addRecord();
678
700
  }
679
701
  this._dataUnit.setFieldValue(fieldName, newValue);
702
+ if (this._dataUnit.waitingForChange(fieldName)) {
703
+ const bind = this._fields.get(fieldName);
704
+ if (bind) {
705
+ bind.acceptWaitingChange();
706
+ }
707
+ }
680
708
  }
681
709
  bindSearchOptionsLoader(fieldName, field) {
682
710
  if (field.nodeName === "EZ-SEARCH" && field["optionLoader"] == undefined) {
@@ -705,18 +733,36 @@ class DataBinder {
705
733
  class Bind {
706
734
  constructor() {
707
735
  this.startChangeEventName = "ezStartChange";
736
+ this.cancelWaitingChangeEventName = "ezCancelWaitingChange";
708
737
  this.changeEventName = "ezChange";
709
738
  }
710
739
  destroy() {
711
740
  this.field.removeEventListener(this.startChangeEventName, this.startChangeListener);
741
+ this.field.removeEventListener(this.cancelWaitingChangeEventName, this.cancelWaitingChangeListener);
712
742
  this.field.removeEventListener(this.changeEventName, this.changeListener);
713
743
  }
714
- static create(fieldName, field, startChangeCallback, changeCallback) {
744
+ acceptWaitingChange() {
745
+ if (this.waitingChangePromiseResolve) {
746
+ this.waitingChangePromiseResolve();
747
+ this.waitingChangePromiseReject = undefined;
748
+ this.waitingChangePromiseResolve = undefined;
749
+ }
750
+ }
751
+ rejectWaitingChange(reason) {
752
+ if (this.waitingChangePromiseReject) {
753
+ this.waitingChangePromiseReject(reason);
754
+ this.waitingChangePromiseReject = undefined;
755
+ this.waitingChangePromiseResolve = undefined;
756
+ }
757
+ }
758
+ static create(fieldName, field, startChangeCallback, cancelWaitingChangeCallback, changeCallback) {
715
759
  const b = new Bind();
716
760
  b.field = field;
717
761
  b.fieldName = fieldName;
718
762
  b.startChangeListener = (evt) => { startChangeCallback(fieldName, evt.detail); };
719
763
  b.field.addEventListener(b.startChangeEventName, b.startChangeListener);
764
+ b.cancelWaitingChangeListener = () => { cancelWaitingChangeCallback(fieldName); };
765
+ b.field.addEventListener(b.cancelWaitingChangeEventName, b.cancelWaitingChangeListener);
720
766
  b.changeListener = (evt) => { changeCallback(fieldName, evt.detail); };
721
767
  b.field.addEventListener(b.changeEventName, b.changeListener);
722
768
  return b;
@@ -821,7 +867,6 @@ let EzForm = class {
821
867
  }
822
868
  }
823
869
  if (action.type === Action.RECORDS_ADDED) {
824
- debugger;
825
870
  const metadata = selectFormMetadata(this._store.getState());
826
871
  const defaultValues = metadata.getDefaultValues();
827
872
  if (defaultValues) {