@sankhyalabs/ezui 1.1.38 → 1.1.42

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-button_16.cjs.entry.js +328 -206
  2. package/dist/cjs/ez-dialog.cjs.entry.js +4 -4
  3. package/dist/cjs/ez-popup.cjs.entry.js +3 -3
  4. package/dist/cjs/ez-toast.cjs.entry.js +37 -0
  5. package/dist/cjs/ezui.cjs.js +1 -1
  6. package/dist/cjs/loader.cjs.js +1 -1
  7. package/dist/collection/collection-manifest.json +2 -1
  8. package/dist/collection/components/ez-combo-box/ez-combo-box.js +18 -8
  9. package/dist/collection/components/ez-dialog/ez-dialog.js +16 -12
  10. package/dist/collection/components/ez-form/assets/trash-can-outline.svg +3 -0
  11. package/dist/collection/components/ez-form/ez-form.js +9 -0
  12. package/dist/collection/components/ez-form/subcomponents/DataUnit.js +2 -1
  13. package/dist/collection/components/ez-form/subcomponents/form-metadata.js +1 -5
  14. package/dist/collection/components/ez-form/subcomponents/structure/Field.js +2 -3
  15. package/dist/collection/components/ez-form/subcomponents/structure/NavigationBar.js +6 -3
  16. package/dist/collection/components/ez-popup/ez-popup.js +5 -5
  17. package/dist/collection/components/ez-search/ez-search.js +9 -7
  18. package/dist/collection/components/ez-toast/ez-toast.css +108 -0
  19. package/dist/collection/components/ez-toast/ez-toast.js +113 -0
  20. package/dist/collection/components/ez-upload/RemoteFile.js +89 -0
  21. package/dist/collection/components/ez-upload/ez-upload.css +16 -1
  22. package/dist/collection/components/ez-upload/ez-upload.js +257 -296
  23. package/dist/collection/utils/Application.js +34 -0
  24. package/dist/custom-elements/index.d.ts +6 -0
  25. package/dist/custom-elements/index.js +375 -219
  26. package/dist/esm/ez-button_16.entry.js +328 -206
  27. package/dist/esm/ez-dialog.entry.js +4 -4
  28. package/dist/esm/ez-popup.entry.js +3 -3
  29. package/dist/esm/ez-toast.entry.js +33 -0
  30. package/dist/esm/ezui.js +1 -1
  31. package/dist/esm/loader.js +1 -1
  32. package/dist/ezui/assets/trash-can-outline.svg +3 -0
  33. package/dist/ezui/ezui.esm.js +1 -1
  34. package/dist/ezui/p-1ff02df6.entry.js +1 -0
  35. package/dist/ezui/p-243c6972.entry.js +1 -0
  36. package/dist/ezui/p-4a87d740.entry.js +1 -0
  37. package/dist/ezui/p-c3b18332.entry.js +1 -0
  38. package/dist/types/components/ez-combo-box/ez-combo-box.d.ts +2 -1
  39. package/dist/types/components/ez-dialog/ez-dialog.d.ts +3 -3
  40. package/dist/types/components/ez-form/ez-form.d.ts +2 -0
  41. package/dist/types/components/ez-popup/ez-popup.d.ts +1 -1
  42. package/dist/types/components/ez-search/ez-search.d.ts +1 -1
  43. package/dist/types/components/ez-toast/ez-toast.d.ts +17 -0
  44. package/dist/types/components/ez-upload/RemoteFile.d.ts +14 -0
  45. package/dist/types/components/ez-upload/ez-upload.d.ts +51 -57
  46. package/dist/types/components.d.ts +95 -61
  47. package/dist/types/utils/Application.d.ts +6 -0
  48. package/package.json +2 -2
  49. package/react/components.d.ts +1 -0
  50. package/react/components.js +1 -0
  51. package/react/components.js.map +1 -1
  52. package/dist/ezui/p-40fe4f51.entry.js +0 -1
  53. package/dist/ezui/p-caa50ec5.entry.js +0 -1
  54. package/dist/ezui/p-e8a91edd.entry.js +0 -1
@@ -1020,12 +1020,18 @@ let EzComboBox$1 = class extends HTMLElement {
1020
1020
  }
1021
1021
  getText() {
1022
1022
  let text = '';
1023
- const selected = this.value;
1023
+ const selected = this.getSelectedOption();
1024
1024
  if (selected) {
1025
1025
  text = this.showselectedvalue ? `${selected.value} - ${selected.label}` : selected.label;
1026
1026
  }
1027
1027
  return text;
1028
1028
  }
1029
+ getSelectedOption() {
1030
+ if (typeof this.value === 'string' || this.value instanceof String) {
1031
+ return this._visibleOptions.find(o => o.value === this.value);
1032
+ }
1033
+ return this.value;
1034
+ }
1029
1035
  updateVisibleOptions() {
1030
1036
  let opts = this._source || [];
1031
1037
  if (!this.searchmode && this._criteria) {
@@ -1094,9 +1100,11 @@ let EzComboBox$1 = class extends HTMLElement {
1094
1100
  }
1095
1101
  }
1096
1102
  selectOption(opt) {
1097
- if (this.value !== opt) {
1098
- this.value = !(opt === null || opt === void 0 ? void 0 : opt.value) ? null : opt;
1099
- this.ezChange.emit(this.value);
1103
+ const currentOpt = this.getSelectedOption();
1104
+ if (currentOpt !== opt) {
1105
+ const adjustedOpt = !(opt === null || opt === void 0 ? void 0 : opt.value) ? null : opt;
1106
+ this.value = adjustedOpt;
1107
+ this.ezChange.emit(adjustedOpt);
1100
1108
  }
1101
1109
  else {
1102
1110
  this.internalUpdate();
@@ -1319,7 +1327,7 @@ let EzDialog$1 = class extends HTMLElement {
1319
1327
  */
1320
1328
  this.oppened = false;
1321
1329
  }
1322
- handleButtonClick(selectedOption) {
1330
+ async handleButtonClick(selectedOption) {
1323
1331
  this.oppened = false;
1324
1332
  this.ezChange.emit(selectedOption);
1325
1333
  }
@@ -1328,10 +1336,10 @@ let EzDialog$1 = class extends HTMLElement {
1328
1336
  return (h("div", { class: "overlay" }, h("div", { class: "dialog" }, h("div", { class: this.critical === true ? "dialog__critical--indicator" : "dialog__warning--indicator" }), h("div", { class: "dialog__container" }, h("div", { class: "title__container" }, h("div", { class: "title__box" }, this.personalizedIconPath ?
1329
1337
  h("svg", { class: "iconePersonalizado", role: "img" }, h("use", { xlinkHref: this.personalizedIconPath }))
1330
1338
  :
1331
- h("div", { class: this.critical ? "title-icon title-icon--critical" : "title-icon" }), h("div", { class: "title title--label" }, h("h2", null, this.title))), h("button", { class: "btn-close", onClick: () => { this.oppened = false; this.ezChange.emit("CANCEL"); } })), h("div", { class: "text text--primary text--medium message" }, this.message), this.confirm ?
1332
- h("div", { class: "button-yes-no__container" }, h("ez-button", { class: "button__no", mode: "link", label: "N\u00E3o", onClick: () => this.handleButtonClick("N") }), h("ez-button", { label: "Ok", onClick: () => this.handleButtonClick("S") }))
1339
+ h("div", { class: this.critical ? "title-icon title-icon--critical" : "title-icon" }), h("div", { class: "title title--label" }, h("h2", null, this.ezTitle))), h("button", { class: "btn-close", onClick: () => { this.oppened = false; this.ezChange.emit(false); } })), h("div", { class: "text text--primary text--medium message" }, this.message), this.confirm ?
1340
+ h("div", { class: "button-yes-no__container" }, h("ez-button", { class: "button__no", mode: "link", label: "N\u00E3o", onClick: () => this.handleButtonClick(false) }), h("ez-button", { label: "Ok", onClick: () => this.handleButtonClick(true) }))
1333
1341
  : undefined, !this.confirm ?
1334
- h("div", { class: "button__ok--container" }, h("ez-button", { label: "Ok", onClick: () => this.handleButtonClick("S") }))
1342
+ h("div", { class: "button__ok--container" }, h("ez-button", { label: "Ok", onClick: () => this.handleButtonClick(true) }))
1335
1343
  : undefined))));
1336
1344
  }
1337
1345
  return null;
@@ -2874,11 +2882,48 @@ function showHideNavBtn(state, { buttonName, status }) {
2874
2882
  return Object.assign(Object.assign({}, state), { visibleButtons });
2875
2883
  }
2876
2884
 
2877
- function removeHandler(dataUnit) {
2878
- if (confirm("Tem certeza que deseja Remover?")) {
2879
- dataUnit.remove();
2885
+ class Application {
2886
+ static async showDialog(title, message, icon = null, confirm, critical = false) {
2887
+ return new Promise(resolve => {
2888
+ let dialog = document.querySelector("ez-dialog");
2889
+ if (!dialog) {
2890
+ dialog = document.createElement("ez-dialog");
2891
+ window.document.body.appendChild(dialog);
2892
+ }
2893
+ dialog.ezTitle = title;
2894
+ dialog.message = message;
2895
+ dialog.critical = critical;
2896
+ dialog.confirm = confirm;
2897
+ dialog.personalizedIconPath = icon;
2898
+ dialog.oppened = true;
2899
+ dialog.addEventListener("ezChange", (evt) => resolve(evt.detail));
2900
+ });
2901
+ }
2902
+ static async alert(title, message, icon = null) {
2903
+ return Application.showDialog(title, message, icon, false, false);
2904
+ }
2905
+ static async confirm(title, message, icon = null, critical = false) {
2906
+ return Application.showDialog(title, message, icon, true, critical);
2907
+ }
2908
+ static async info(message) {
2909
+ let toast = document.querySelector("ez-toast");
2910
+ if (!toast) {
2911
+ toast = document.createElement("ez-toast");
2912
+ window.document.body.appendChild(toast);
2913
+ }
2914
+ toast.message = message;
2915
+ toast.fadeTime = 4000;
2916
+ toast.show();
2880
2917
  }
2881
2918
  }
2919
+
2920
+ function removeHandler(dataUnit) {
2921
+ Application.confirm("Exclusão de registro", "Tem certeza que deseja Remover?", null, true).then(ok => {
2922
+ if (ok) {
2923
+ dataUnit.remove();
2924
+ }
2925
+ });
2926
+ }
2882
2927
  const NavigationBar = ({ dataUnit: du, buttonProps, enabled }) => {
2883
2928
  if (buttonProps.previousVisible
2884
2929
  || buttonProps.nextVisible
@@ -3212,7 +3257,7 @@ class DataUnit {
3212
3257
  });
3213
3258
  const result = this.recordsValidator.validateRecords(this, recordsToValidate, triggedBy);
3214
3259
  if (result.message) {
3215
- alert(result.message);
3260
+ Application.info(result.message);
3216
3261
  }
3217
3262
  return result.isValid;
3218
3263
  }
@@ -3290,10 +3335,9 @@ const Field = ({ dataUnit, field, forceScroll, enabled }) => {
3290
3335
  const target = getProp(properties, 'URL');
3291
3336
  const strHeaders = getProp(properties, 'HEADERS');
3292
3337
  const headers = strHeaders ? JSON.parse(strHeaders) : {};
3338
+ const maxfiles = Number(getProp(properties, "maxfiles") || 0);
3293
3339
  return (h("div", { class: "col col--sd-12 padding--small" },
3294
- h("ez-upload", { onEzChange: (event) => {
3295
- changeFieldHandler(event.target['value']);
3296
- }, target: target, headers: headers, value: value })));
3340
+ h("ez-upload", { value: value, label: formattedLabel, enabled: isEnabled, onEzChange: (event) => changeFieldHandler(event.detail), urlupload: target, requestheaders: headers, maxfiles: maxfiles })));
3297
3341
  case 'DATE':
3298
3342
  return h("div", { class: "col col--sd-12 col--tb-3 padding--small" }, loadingData ? h("place-holder", null) :
3299
3343
  h("ez-date-input", { value: !value ? null : DateUtils.clearTime(value), label: formattedLabel, enabled: isEnabled, onEzChange: (event) => changeFieldHandler(event.target['value']), errormessage: errorMessage, ref: elem => scrollToView(forceScroll, elem), key: key }));
@@ -3388,6 +3432,7 @@ let EzForm$1 = class extends HTMLElement {
3388
3432
  this._dataUnits = new Map();
3389
3433
  this._duSources = new Map();
3390
3434
  this._tabPositionByField = new Map();
3435
+ this._duToLoad = [];
3391
3436
  }
3392
3437
  cleanPreparedMetadata() {
3393
3438
  this._preparedMetadata = undefined;
@@ -3527,6 +3572,9 @@ let EzForm$1 = class extends HTMLElement {
3527
3572
  };
3528
3573
  this._preparedMetadata = metadata.map((form, index) => {
3529
3574
  const du = form.dataUnit;
3575
+ if (form.autoLoad) {
3576
+ this._duToLoad.push(du);
3577
+ }
3530
3578
  this.decorateDU(du);
3531
3579
  const duName = du.name;
3532
3580
  this._duSources.set(duName, du);
@@ -3568,6 +3616,10 @@ let EzForm$1 = class extends HTMLElement {
3568
3616
  }
3569
3617
  }
3570
3618
  }
3619
+ componentDidRender() {
3620
+ this._duToLoad.forEach(du => du.load());
3621
+ this._duToLoad = [];
3622
+ }
3571
3623
  loadSearch(argument, context) {
3572
3624
  const fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
3573
3625
  if (fieldSearchExecutor) {
@@ -3609,6 +3661,7 @@ let EzForm$1 = class extends HTMLElement {
3609
3661
  render() {
3610
3662
  return this._preparedMetadata ? h(FormSheet, { enabled: this.enabled, store: this._store, source: this._preparedMetadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
3611
3663
  }
3664
+ static get assetsDirs() { return ["assets"]; }
3612
3665
  get _host() { return this; }
3613
3666
  static get watchers() { return {
3614
3667
  "metadata": ["cleanPreparedMetadata"]
@@ -4304,9 +4357,9 @@ let EzPopup$1 = class extends HTMLElement {
4304
4357
  }
4305
4358
  render() {
4306
4359
  if (this.opened) {
4307
- return (h(Host, null, h("div", { class: "overlay" }, h("div", { class: "popup col " + this.size }, h("div", { class: "popup__container" }, h("div", { class: "popup__content" }, h("div", { class: "popup__header" }, this.title ?
4308
- h("div", { class: "title popup__title" }, this.title)
4309
- : undefined, h("button", { class: this.title ? "btn-close" : "btn-close btn-close--solo", onClick: () => { this.opened = false; this.ezChange.emit("CANCEL"); } })), h("div", { class: "popup__expandable-content" }, h("slot", null))))))));
4360
+ return (h(Host, null, h("div", { class: "overlay" }, h("div", { class: "popup col " + this.size }, h("div", { class: "popup__container" }, h("div", { class: "popup__content" }, h("div", { class: "popup__header" }, this.ezTitle ?
4361
+ h("div", { class: "title popup__title" }, this.ezTitle)
4362
+ : undefined, h("button", { class: this.ezTitle ? "btn-close" : "btn-close btn-close--solo", onClick: () => { this.opened = false; this.ezChange.emit("CANCEL"); } })), h("div", { class: "popup__expandable-content" }, h("slot", null))))))));
4310
4363
  }
4311
4364
  return null;
4312
4365
  }
@@ -4341,8 +4394,9 @@ let EzSearch$1 = class extends HTMLElement {
4341
4394
  }
4342
4395
  }
4343
4396
  onComboChange(evt) {
4344
- this.value = this._comboElement.value;
4345
- this.ezChange.emit(this.value);
4397
+ evt.stopPropagation();
4398
+ this.value = evt.detail;
4399
+ this.ezChange.emit(evt.detail);
4346
4400
  }
4347
4401
  render() {
4348
4402
  return (h("ez-combo-box", { ref: elem => this._comboElement = elem, value: this.value, label: this.label, enabled: this.enabled, errormessage: this.errormessage, optionloader: this.optionloader, searchmode: true, onEzChange: evt => this.onComboChange(evt), showselectedvalue: this.showselectedvalue, showoptionvalue: this.showoptionvalue }));
@@ -5038,144 +5092,252 @@ let EzTimeInput$1 = class extends HTMLElement {
5038
5092
  static get style() { return ezTimeInputCss; }
5039
5093
  };
5040
5094
 
5041
- const ezUploadCss = ":host{--iu--height:42px;--iu--width:100%;--iu__icon--width:48px;--iu__container--background-color:var(--background--medium, #d2dce9);--iu__color--primary:var(--color--primary, #008561);--iu--padding--extra-small:var(--space--extra-small, 3px);--iu--padding--small:var(--space--small, 6px);--iu--padding--medium:var(--space--medium, 12px);--iu--padding--large:var(--space--large, 24px);--iu--border-radius:var(--border--radius-medium, 12px);--iu__border--color:var(--color-strokes, #DCE0E8);--iu__input--border:var(--border--medium, 2px solid);--iu--text-shadow:var(--text-shadow, 0 0 0 #353535, 0 0 1px transparent);--iu--text--primary:var(--text-primary, #626e82);--iu--font-size:var(--text--medium, 14px);--iu--font-family:var(--font-pattern, Arial);--iu--font-weight:var(--text-weight--large, 500);display:flex;flex-wrap:wrap;position:relative;font-family:var(--iu--font-family);font-size:var(--iu--font-size);width:var(--iu--width);font-weight:var(--iu--font-weight)}.iu{display:flex;flex-wrap:wrap;background-color:var(--iu__container--background-color);padding:var(--iu--padding--small);width:100%;border-radius:12px;box-sizing:border-box}.iu__container{width:100%;height:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;border:2px dashed var(--iu__border--color);border-radius:6px;box-sizing:border-box}.iu__footer{display:flex;flex-wrap:wrap;justify-content:flex-start;width:100%;padding:0 var(--iu--padding--medium) var(--iu--padding--medium) var(--iu--padding--medium);box-sizing:border-box}.iu__item{display:flex;width:100%;justify-content:flex-start;align-items:center;align-self:center;padding-bottom:var(--iu--padding--extra-small);box-sizing:border-box;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.iu__item-label{display:flex;max-width:80%;align-self:stretch;align-items:center}.file__name{font-weight:200}.box__content{width:100%;justify-content:center;align-items:center;height:100%;border:1px dashed var(--iu__border--color);border-radius:6px;box-sizing:border-box}.box__container{display:flex;flex-wrap:wrap;background-color:var(--iu__container--background-color);padding:6px;width:100%;border-radius:12px}a:-webkit-any-link{color:#008561;fill:#008561;cursor:pointer;text-decoration:none}progress[value]{display:flex;width:100%;appearance:none;border:1px solid var(--iu__border--color);height:12px;justify-content:flex-start;align-items:center;border-radius:3px;position:relative}progress[value]::-webkit-progress-bar{display:flex;-webkit-appearance:none;width:100%;background-color:rgb(255, 255, 255);border-radius:2px;padding:2px}progress[value]::-webkit-progress-value{display:flex;width:100%;background-color:var(--iu__color--primary)}.text--center{text-align:center}.align--middle{align-self:center;align-items:center}.text{font-family:\"Sora\", \"Algerian\";text-shadow:0 0 0 #353535, 0 0 1px transparent}.text--primary{color:var(--iu--text--primary);text-shadow:var(--iu--text-shadow)}.text--ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.text--medium{font-size:14px}.text--small{font-size:12px}.btn-cancel{outline:none;border:none;background-color:unset;cursor:pointer}.btn-cancel::after{content:'';display:flex;background-color:var(--text--primary, #008561);width:8px;height:8px;clip-path:path(\"M 8,0.8 7.2,0 4,3.2 0.8,0 0,0.8 3.2,4 0,7.2 0.8,8 4,4.8 7.2,8 8,7.2 4.8,4 Z\")}.iu__file-icon{outline:none;border:none;background-color:unset;cursor:pointer}.iu__file-icon::after{content:'';display:flex;background-color:var(--text--primary, #626e82);width:9px;height:11px;clip-path:path(\"M 1.2272719,8.4999999 V 2.75 c 0,-1.1045695 1.4652499,-2 3.2727273,-2 1.8074777,0 3.2727281,0.8954305 3.2727281,2 V 8.9999999 C 7.7727273,9.690356 6.8569456,10.25 5.7272719,10.25 4.5975985,10.25 3.6818174,9.690356 3.6818174,8.9999999 V 3.75 c 0,-0.2761425 0.3663125,-0.5 0.8181818,-0.5 0.4518694,0 0.8181818,0.2238575 0.8181818,0.5 V 8.4999999 H 6.5454537 V 3.75 C 6.5454537,3.059644 5.6296725,2.5 4.4999992,2.5 3.3703258,2.5 2.4545446,3.059644 2.4545446,3.75 V 8.9999999 C 2.4545446,10.10457 3.9197945,11 5.7272719,11 7.5347496,11 9,10.10457 9,8.9999999 V 2.75 C 9,1.231217 6.9852809,0 4.4999992,0 2.0147181,5e-7 0,1.231217 0,2.75 v 5.7499999 z\")}.iu__icon-label{justify-content:center;display:flex;cursor:pointer;padding:var(--iu--padding--large) 0px;box-sizing:border-box}.row{width:100%;display:flex;flex-wrap:wrap}.col{display:flex;flex-wrap:wrap;align-self:flex-start;box-sizing:border-box}.col--stretch{align-self:stretch}.col--undefined{width:unset}.col--nowrap{flex-wrap:nowrap}@media screen and (min-width: 320px){.col--sd-1{width:8.33333%}.col--sd-2{width:16.66667%}.col--sd-3{width:25%}.col--sd-4{width:33.33333%}.col--sd-5{width:41.66667%}.col--sd-6{width:50%}.col--sd-7{width:58.33333%}.col--sd-8{width:66.66667%}.col--sd-9{width:75%}.col--sd-10{width:83.33333%}.col--sd-11{width:91.66667%}.col--sd-12{width:100%}}@media screen and (min-width: 480px){.col--pn-1{width:8.33333%}.col--pn-2{width:16.66667%}.col--pn-3{width:25%}.col--pn-4{width:33.33333%}.col--pn-5{width:41.66667%}.col--pn-6{width:50%}.col--pn-7{width:58.33333%}.col--pn-8{width:66.66667%}.col--pn-9{width:75%}.col--pn-10{width:83.33333%}.col--pn-11{width:91.66667%}.col--pn-12{width:100%}}@media screen and (min-width: 768px){.col--tb-1{width:8.33333%}.col--tb-2{width:16.66667%}.col--tb-3{width:25%}.col--tb-4{width:33.33333%}.col--tb-5{width:41.66667%}.col--tb-6{width:50%}.col--tb-7{width:58.33333%}.col--tb-8{width:66.66667%}.col--tb-9{width:75%}.col--tb-10{width:83.33333%}.col--tb-11{width:91.66667%}.col--tb-12{width:100%}}@media screen and (min-width: 992px){.col--md-1{width:8.33333%}.col--md-2{width:16.66667%}.col--md-3{width:25%}.col--md-4{width:33.33333%}.col--md-5{width:41.66667%}.col--md-6{width:50%}.col--md-7{width:58.33333%}.col--md-8{width:66.66667%}.col--md-9{width:75%}.col--md-10{width:83.33333%}.col--md-11{width:91.66667%}.col--md-12{width:100%}}@media screen and (min-width: 1200px){.col--ld-1{width:8.33333%}.col--ld-2{width:16.66667%}.col--ld-3{width:25%}.col--ld-4{width:33.33333%}.col--ld-5{width:41.66667%}.col--ld-6{width:50%}.col--ld-7{width:58.33333%}.col--ld-8{width:66.66667%}.col--ld-9{width:75%}.col--ld-10{width:83.33333%}.col--ld-11{width:91.66667%}.col--ld-12{width:100%}}";
5095
+ const ezToastCss = ":host{--toast-z-index:var(--more-visible, 2);--toast-color--secondary:var(--color--secondary, #383c45);--toast-title--primary:var(--title--primary, #2b3a54);--toast-space--small:var(--space--small, 6px);--toast--close__image:url('data:image/svg+xml;utf8,<svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" xmlns=\"http://www.w3.org/2000/svg%22%3E<path d=\"M 7.0060773,5.995511 11.461972,1.5397722 c 0.132856,-0.1328413 0.207547,-0.3130253 0.207547,-0.5009046 0,-0.18786999 -0.07469,-0.3680541 -0.207547,-0.5009048 -0.132857,-0.13284126 -0.31302,-0.20748126 -0.500927,-0.20748126 -0.187812,0 -0.36807,0.07464 -0.500926,0.20748126 L 6.0042244,4.9937015 1.5482921,0.5379628 C 1.4154357,0.40512154 1.2352533,0.33048154 1.0473657,0.33048154 c -0.18787813,0 -0.36807,0.07464 -0.50092647,0.20748126 -0.13285646,0.1328507 -0.20749026,0.31303481 -0.20749026,0.5009048 0,0.1878793 0.0746338,0.3680633 0.20749026,0.5009046 L 5.0023715,5.995511 0.54643923,10.452213 c -0.0676086,0.06534 -0.12151598,0.14352 -0.15859681,0.229916 -0.0370714,0.08639 -0.0565645,0.1794 -0.0573369,0.27335 -7.724e-4,0.09404 0.0171873,0.187331 0.0528423,0.274293 0.0356455,0.08705 0.0882688,0.166087 0.15479148,0.23256 0.0665321,0.06648 0.14562277,0.11897 0.2326735,0.154567 0.0870507,0.0356 0.18031463,0.05344 0.2743433,0.05259 0.094029,-8.5e-4 0.1869528,-0.02049 0.2733331,-0.0576 0.08639,-0.0372 0.1645078,-0.09121 0.2298029,-0.158817 L 6.0042244,6.9973204 10.460119,11.453078 c 0.132856,0.132851 0.313114,0.207444 0.500926,0.207444 0.187907,0 0.36807,-0.07459 0.500927,-0.207444 0.132856,-0.13285 0.207547,-0.313006 0.207547,-0.500904 0,-0.187898 -0.07469,-0.368054 -0.207547,-0.500905 z\"/></svg>')}.toast__container{position:fixed;display:flex;bottom:100px;z-index:var(--toast-z-index);left:100px;width:30%;box-sizing:border-box;background-color:var(--toast-color--secondary);border-radius:6px;align-items:center;padding:12px;visibility:hidden}.message__container{font-family:\"Sora\", \"Algerian\";text-shadow:0 0 0 #353535, 0 0 1px transparent;color:#FFFFFF;font-size:14px;width:90%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.message__conteiner--icon{padding-left:var(--toast-space--small);width:80%}.btn-close{display:flex;justify-content:flex-end;padding:0;outline:none;width:10%;border:none;background-color:unset;cursor:pointer}.btn-close::after{content:'';display:flex;background-color:#FFFFFF;width:12px;height:12px;-webkit-mask-image:var(--toast--close__image);mask-image:var(--toast--close__image)}.toast__container--oppened{animation:fadein 0.5s, fadeout 0.5s 3s;visibility:visible}@-webkit-keyframes fadein{from{left:-100px;opacity:0}to{left:100px;opacity:1}}@keyframes fadein{from{left:-100px;opacity:0}to{left:100px;opacity:1}}@-webkit-keyframes fadeout{from{left:100px;opacity:1}to{bottom:0;opacity:0}}@keyframes fadeout{from{left:100px;opacity:1}to{bottom:0;opacity:0}}";
5096
+
5097
+ let EzToast$1 = class extends HTMLElement {
5098
+ constructor() {
5099
+ super();
5100
+ this.__registerHost();
5101
+ this.__attachShadow();
5102
+ /**
5103
+ * Controla o tempo de exibição do componente em milissegundos.
5104
+ */
5105
+ this.fadeTime = 5000;
5106
+ /**
5107
+ * Adiciona ícone de check no componente.
5108
+ */
5109
+ this.useIcon = false;
5110
+ }
5111
+ async show() {
5112
+ this.container.classList.add("toast__container--oppened");
5113
+ this.container.style.animation = `fadein 0.5s, fadeout 0.5s ${this.fadeTime / 1000}s`;
5114
+ setTimeout(() => {
5115
+ this.container.classList.remove("toast__container--oppened");
5116
+ this.container.style.animation = `none`;
5117
+ }, this.fadeTime + 400);
5118
+ }
5119
+ render() {
5120
+ return (h("div", { ref: (el) => this.container = el, class: "toast__container" }, this.useIcon ?
5121
+ h("slot", { name: "icon" })
5122
+ : undefined, h("div", { class: this.useIcon ? "message__container message__conteiner--icon" : "message__container", title: this.message }, " ", this.message, " "), h("button", { class: "btn-close", onClick: () => { this.container.classList.remove("toast__container--oppened"); this.container.style.animation = `none`; } })));
5123
+ }
5124
+ static get style() { return ezToastCss; }
5125
+ };
5126
+
5127
+ class RemoteFile {
5128
+ constructor(file) {
5129
+ this.file = file;
5130
+ this.size = file.size;
5131
+ this.name = file.name;
5132
+ }
5133
+ abortUpload() {
5134
+ if (this._uploadingXhr) {
5135
+ this._aborted = true;
5136
+ this._uploadingXhr.abort();
5137
+ this._uploadingXhr = undefined;
5138
+ }
5139
+ }
5140
+ isUploading() {
5141
+ return this._uploadingXhr !== undefined;
5142
+ }
5143
+ async upload(server, headers, updateCallBack) {
5144
+ return new Promise((resolve, reject) => {
5145
+ const xhr = new XMLHttpRequest();
5146
+ this._uploadingXhr = xhr;
5147
+ this._aborted = false;
5148
+ this.progress = 0;
5149
+ xhr.upload.onprogress = (e) => {
5150
+ const loaded = e.loaded;
5151
+ const total = e.total;
5152
+ this.progress = ~~((loaded / total) * 100);
5153
+ updateCallBack(this, loaded, total);
5154
+ };
5155
+ xhr.onreadystatechange = () => {
5156
+ if (xhr.readyState == 4) {
5157
+ this._uploadingXhr = undefined;
5158
+ const status = xhr.status;
5159
+ if (!this._aborted) {
5160
+ if (status === 0) {
5161
+ reject("Servidor indisponível");
5162
+ }
5163
+ else if (status >= 500) {
5164
+ reject("Erro inesperado no servidor");
5165
+ }
5166
+ else if (status >= 400) {
5167
+ reject("Operação não permitida");
5168
+ }
5169
+ }
5170
+ const response = xhr.response;
5171
+ if (response) {
5172
+ resolve(JSON.parse(response));
5173
+ }
5174
+ }
5175
+ };
5176
+ xhr.ontimeout = () => {
5177
+ reject("Tempo limite de transferência atingido.");
5178
+ };
5179
+ const formData = new FormData();
5180
+ formData.append("ARQUIVO", this.file, this.file.name);
5181
+ xhr.open("POST", server, true);
5182
+ if (headers) {
5183
+ headers.forEach((value, key) => xhr.setRequestHeader(key, value));
5184
+ }
5185
+ xhr.send(formData);
5186
+ });
5187
+ }
5188
+ async delete(item, server, headers) {
5189
+ return new Promise((resolve, reject) => {
5190
+ const xhr = new XMLHttpRequest();
5191
+ xhr.onreadystatechange = () => {
5192
+ if (xhr.readyState == 4) {
5193
+ if (xhr.status === 0) {
5194
+ reject("Servidor indisponível");
5195
+ }
5196
+ else if (xhr.status >= 500) {
5197
+ reject("Erro inesperado no servidor");
5198
+ }
5199
+ else if (xhr.status >= 400) {
5200
+ reject("Operação não permitida");
5201
+ }
5202
+ resolve(true);
5203
+ }
5204
+ };
5205
+ xhr.ontimeout = () => {
5206
+ reject("Tempo limite de remoção atingido.");
5207
+ };
5208
+ xhr.open("DELETE", server, true);
5209
+ if (headers) {
5210
+ headers.forEach((value, key) => xhr.setRequestHeader(key, value));
5211
+ }
5212
+ xhr.send(JSON.stringify(item));
5213
+ });
5214
+ }
5215
+ }
5216
+
5217
+ const ezUploadCss = ":host{--iu--height:42px;--iu--width:100%;--iu__icon--width:48px;--iu__container--background-color:var(--background--medium, #d2dce9);--iu__color--primary:var(--color--primary, #008561);--iu--padding--extra-small:var(--space--extra-small, 3px);--iu--padding--small:var(--space--small, 6px);--iu--padding--medium:var(--space--medium, 12px);--iu--padding--large:var(--space--large, 24px);--iu--border-radius:var(--border--radius-medium, 12px);--iu__border--color:var(--color-strokes, #DCE0E8);--iu__input--border:var(--border--medium, 2px solid);--iu--text-shadow:var(--text-shadow, 0 0 0 #353535, 0 0 1px transparent);--iu--text--primary:var(--text-primary, #626e82);--iu--font-size:var(--text--medium, 14px);--iu--font-family:var(--font-pattern, Arial);--iu--font-weight:var(--text-weight--large, 500);display:flex;flex-wrap:wrap;position:relative;font-family:var(--iu--font-family);font-size:var(--iu--font-size);width:var(--iu--width);font-weight:var(--iu--font-weight)}.iu{display:flex;flex-wrap:wrap;background-color:var(--iu__container--background-color);padding:var(--iu--padding--small);width:100%;border-radius:12px;box-sizing:border-box}.iu__container{width:100%;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;border:2px dashed var(--iu__border--color);border-radius:6px;box-sizing:border-box}.iu__footer{display:flex;flex-wrap:wrap;justify-content:flex-start;width:100%;padding:0 var(--iu--padding--medium) var(--iu--padding--medium) var(--iu--padding--medium);box-sizing:border-box}.iu__item{display:flex;width:100%;justify-content:flex-start;align-items:center;align-self:center;padding-bottom:var(--iu--padding--extra-small);box-sizing:border-box;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.iu__item-label{display:flex;max-width:80%;align-self:stretch;align-items:center}.file__name{font-weight:200}.box__content{width:100%;justify-content:center;align-items:center;height:100%;border:1px dashed var(--iu__border--color);border-radius:6px;box-sizing:border-box}.box__container{display:flex;flex-wrap:wrap;background-color:var(--iu__container--background-color);padding:6px;width:100%;border-radius:12px}a:-webkit-any-link{color:#008561;fill:#008561;cursor:pointer;text-decoration:none}progress[value]{display:flex;width:100%;appearance:none;border:1px solid var(--iu__border--color);height:12px;justify-content:flex-start;align-items:center;border-radius:3px;position:relative}progress[value]::-webkit-progress-bar{display:flex;-webkit-appearance:none;width:100%;background-color:rgb(255, 255, 255);border-radius:2px;padding:2px}progress[value]::-webkit-progress-value{display:flex;width:100%;background-color:var(--iu__color--primary)}.text--center{text-align:center}.align--middle{align-self:center;align-items:center}.text{font-family:\"Sora\", \"Algerian\";text-shadow:0 0 0 #353535, 0 0 1px transparent}.text--primary{color:var(--iu--text--primary);text-shadow:var(--iu--text-shadow)}.text--ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.text--medium{font-size:14px}.text--small{font-size:12px}.btn-cancel{outline:none;border:none;background-color:unset;cursor:pointer}.btn-cancel::after{content:'';display:flex;background-color:var(--text--primary, #008561);width:8px;height:8px;clip-path:path(\"M 8,0.8 7.2,0 4,3.2 0.8,0 0,0.8 3.2,4 0,7.2 0.8,8 4,4.8 7.2,8 8,7.2 4.8,4 Z\")}.iu__label{padding:var(--space--small);padding-top:0;box-sizing:border-box;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:var(--iu--font-family);font-size:var(--text--extra-small);font-weight:var( --iu--font-weight);color:var(--iu--text--primary);text-shadow:var(--iu--text-shadow)}.iu__file-icon{outline:none;border:none;background-color:unset;cursor:pointer}.iu__file-icon::after{content:'';display:flex;background-color:var(--text--primary, #626e82);width:9px;height:11px;clip-path:path(\"M 1.2272719,8.4999999 V 2.75 c 0,-1.1045695 1.4652499,-2 3.2727273,-2 1.8074777,0 3.2727281,0.8954305 3.2727281,2 V 8.9999999 C 7.7727273,9.690356 6.8569456,10.25 5.7272719,10.25 4.5975985,10.25 3.6818174,9.690356 3.6818174,8.9999999 V 3.75 c 0,-0.2761425 0.3663125,-0.5 0.8181818,-0.5 0.4518694,0 0.8181818,0.2238575 0.8181818,0.5 V 8.4999999 H 6.5454537 V 3.75 C 6.5454537,3.059644 5.6296725,2.5 4.4999992,2.5 3.3703258,2.5 2.4545446,3.059644 2.4545446,3.75 V 8.9999999 C 2.4545446,10.10457 3.9197945,11 5.7272719,11 7.5347496,11 9,10.10457 9,8.9999999 V 2.75 C 9,1.231217 6.9852809,0 4.4999992,0 2.0147181,5e-7 0,1.231217 0,2.75 v 5.7499999 z\")}.iu__icon-label{justify-content:center;display:flex;cursor:pointer;padding:var(--iu--padding--large) 0px;box-sizing:border-box}.row{width:100%;display:flex;flex-wrap:wrap}.col{display:flex;flex-wrap:wrap;align-self:flex-start;box-sizing:border-box}.col--stretch{align-self:stretch}.col--undefined{width:unset}.col--nowrap{flex-wrap:nowrap}@media screen and (min-width: 320px){.col--sd-1{width:8.33333%}.col--sd-2{width:16.66667%}.col--sd-3{width:25%}.col--sd-4{width:33.33333%}.col--sd-5{width:41.66667%}.col--sd-6{width:50%}.col--sd-7{width:58.33333%}.col--sd-8{width:66.66667%}.col--sd-9{width:75%}.col--sd-10{width:83.33333%}.col--sd-11{width:91.66667%}.col--sd-12{width:100%}}@media screen and (min-width: 480px){.col--pn-1{width:8.33333%}.col--pn-2{width:16.66667%}.col--pn-3{width:25%}.col--pn-4{width:33.33333%}.col--pn-5{width:41.66667%}.col--pn-6{width:50%}.col--pn-7{width:58.33333%}.col--pn-8{width:66.66667%}.col--pn-9{width:75%}.col--pn-10{width:83.33333%}.col--pn-11{width:91.66667%}.col--pn-12{width:100%}}@media screen and (min-width: 768px){.col--tb-1{width:8.33333%}.col--tb-2{width:16.66667%}.col--tb-3{width:25%}.col--tb-4{width:33.33333%}.col--tb-5{width:41.66667%}.col--tb-6{width:50%}.col--tb-7{width:58.33333%}.col--tb-8{width:66.66667%}.col--tb-9{width:75%}.col--tb-10{width:83.33333%}.col--tb-11{width:91.66667%}.col--tb-12{width:100%}}@media screen and (min-width: 992px){.col--md-1{width:8.33333%}.col--md-2{width:16.66667%}.col--md-3{width:25%}.col--md-4{width:33.33333%}.col--md-5{width:41.66667%}.col--md-6{width:50%}.col--md-7{width:58.33333%}.col--md-8{width:66.66667%}.col--md-9{width:75%}.col--md-10{width:83.33333%}.col--md-11{width:91.66667%}.col--md-12{width:100%}}@media screen and (min-width: 1200px){.col--ld-1{width:8.33333%}.col--ld-2{width:16.66667%}.col--ld-3{width:25%}.col--ld-4{width:33.33333%}.col--ld-5{width:41.66667%}.col--ld-6{width:50%}.col--ld-7{width:58.33333%}.col--ld-8{width:66.66667%}.col--ld-9{width:75%}.col--ld-10{width:83.33333%}.col--ld-11{width:91.66667%}.col--ld-12{width:100%}}";
5042
5218
 
5043
5219
  let EzUpload$1 = class extends HTMLElement {
5044
5220
  constructor() {
5045
5221
  super();
5046
5222
  this.__registerHost();
5047
5223
  this.__attachShadow();
5048
- this.validatedEvent = createEvent(this, "validatedEvent", 7);
5049
- this.initUploadEvent = createEvent(this, "initUploadEvent", 7);
5050
- this.finishedUploadEvent = createEvent(this, "finishedUploadEvent", 7);
5051
5224
  this.ezChange = createEvent(this, "ezChange", 7);
5225
+ this._filePointers = new Map();
5226
+ /**
5227
+ * Deixa o campo disponível ou não para digitação.
5228
+ */
5229
+ this.enabled = true;
5052
5230
  }
5053
- fileListChange() {
5054
- this.ezChange.emit({ value: this.value });
5231
+ changeValue(newValue) {
5232
+ if (newValue !== this._updatingValue) {
5233
+ this._filePointers.forEach(f => {
5234
+ if (this.isRemoteFile(f)) {
5235
+ f.abortUpload();
5236
+ }
5237
+ });
5238
+ this._filePointers = new Map();
5239
+ this.updateFilePointers();
5240
+ }
5241
+ this._updatingValue = undefined;
5055
5242
  }
5056
- addFiles(files) {
5057
- Array.prototype.forEach.call(files, this.addFile.bind(this));
5243
+ updateFilePointers() {
5244
+ if (this.value) {
5245
+ this.value.forEach(ezFile => this._filePointers.set(ezFile.name, ezFile));
5246
+ }
5058
5247
  }
5059
- addFile(file) {
5060
- this.errorMessage = undefined;
5061
- if (this.validateFile(file)) {
5062
- if (this.target) {
5063
- this._uploadFile(file);
5248
+ normalizeRequestHeaders() {
5249
+ this._requestHeaders = new Map();
5250
+ if (typeof this.requestheaders == 'string') {
5251
+ try {
5252
+ this.requestheaders = JSON.parse(this.requestheaders);
5064
5253
  }
5065
- else {
5066
- this.errorMessage = "Endereço de upload não informado";
5067
- alert(this.errorMessage);
5254
+ catch (e) {
5255
+ this.requestheaders = undefined;
5068
5256
  }
5069
5257
  }
5070
- else {
5071
- if (this.errorMessage && this.errorMessage.length > 0) {
5072
- alert(this.errorMessage);
5073
- }
5258
+ for (var key in this.requestheaders) {
5259
+ this._requestHeaders.set(key, this.requestheaders[key]);
5074
5260
  }
5075
5261
  }
5076
- validateFile(file) {
5077
- this.errorMessage = '';
5078
- let isValid = true;
5079
- if (this.maxFileSize >= 0 && file.size > this.maxFileSize) {
5080
- this.errorMessage = 'O tamanho máximo dos arquivos é de ' + this.formatBytes(this.maxFileSize);
5081
- isValid = false;
5082
- }
5083
- this.validatedEvent.emit({ isValid: isValid, fileName: file.name });
5084
- return isValid;
5085
- }
5086
- _uploadFile(file) {
5087
- const xhr = (file.xhr = this._createXhr());
5088
- const newValue = this.value ? [...this.value] : [];
5089
- newValue.push({ name: file.name, size: file.size, xhr: file.xhr });
5090
- let stalledId;
5091
- xhr.upload.onprogress = (e) => {
5092
- clearTimeout(stalledId);
5093
- const loaded = e.loaded, total = e.total, progress = ~~((loaded / total) * 100);
5094
- let viewFile = newValue.find(f => f.name === file.name);
5095
- if (viewFile) {
5096
- viewFile.progress = progress;
5097
- }
5098
- };
5099
- xhr.onreadystatechange = () => {
5100
- this.errorMessage = '';
5101
- if (xhr.readyState == 4) {
5102
- clearTimeout(stalledId);
5103
- file.indeterminate = file.uploading = false;
5104
- if (xhr.status === 0) ;
5105
- else if (xhr.status >= 500) {
5106
- this.errorMessage = "Erro inesperado no servidor";
5107
- }
5108
- else if (xhr.status >= 400) {
5109
- this.errorMessage = "Operação não permitida";
5110
- }
5111
- if (this.errorMessage && this.errorMessage.length > 0) {
5112
- //TODO
5113
- // Conferir com o time de UX um estado de erro ou remoção da lista
5114
- // this.removeFile(file.name);
5115
- alert(this.errorMessage);
5116
- }
5117
- else {
5118
- if (xhr.response) {
5119
- let response = JSON.parse(xhr.response);
5120
- response.forEach(element => {
5121
- let viewFile = newValue.find(f => f.name === this.decode_utf8(element.name));
5122
- if (viewFile) {
5123
- viewFile.progress = undefined;
5124
- //Validar estado de erro com UX
5125
- viewFile.error = false;
5126
- delete viewFile.xhr;
5127
- viewFile.downloadURL = element.downloadURL;
5128
- viewFile.lastModifiedDate = element.lastModifiedDate;
5129
- viewFile.properties = element.properties;
5130
- }
5131
- });
5132
- this.value = newValue;
5133
- this.fileListChange();
5134
- }
5135
- else {
5136
- let viewFile = newValue.find(f => f.name === file.name);
5137
- viewFile.progress = undefined;
5138
- //Validar estado de erro com UX
5139
- viewFile.error = true;
5262
+ async addFiles(files) {
5263
+ Array.prototype.forEach.call(files, this.addFile.bind(this));
5264
+ }
5265
+ async addFile(file) {
5266
+ const oldFile = this._filePointers.get(file.name);
5267
+ if (oldFile) {
5268
+ Application.confirm("Substituir arquivo", `Já existe um arquivo chamado "${file.name}". Deseja substituí-lo?`)
5269
+ .then(ok => {
5270
+ if (ok) {
5271
+ if (this.isRemoteFile(oldFile)) {
5272
+ oldFile.abortUpload();
5140
5273
  }
5274
+ this.doAddFile(file);
5141
5275
  }
5276
+ });
5277
+ }
5278
+ else {
5279
+ this.doAddFile(file);
5280
+ }
5281
+ }
5282
+ async doAddFile(file) {
5283
+ if (this.validateFile(file)) {
5284
+ const uploadingFile = new RemoteFile(file);
5285
+ this._filePointers.set(file.name, uploadingFile);
5286
+ uploadingFile.upload(this.urlupload, this._requestHeaders, (file) => this.updateFeedback(file))
5287
+ .then((files) => files.forEach(ezFile => this.finishUpload(ezFile)))
5288
+ .catch(msg => this.showError(msg));
5289
+ forceUpdate(this);
5290
+ }
5291
+ }
5292
+ finishUpload(ezFile) {
5293
+ this._filePointers.set(ezFile.name, ezFile);
5294
+ this.updateValue();
5295
+ }
5296
+ updateValue() {
5297
+ this._updatingValue = [];
5298
+ this._filePointers.forEach(f => {
5299
+ if (!this.isRemoteFile(f)) {
5300
+ this._updatingValue.push(f);
5142
5301
  }
5143
- };
5144
- xhr.ontimeout = () => {
5145
- if (this.errorMessage && this.errorMessage.length > 0) {
5146
- this.errorMessage.concat(" / Tempo expirado");
5147
- this.removeFile(file.name);
5148
- alert(this.errorMessage);
5149
- }
5150
- };
5151
- const formData = new FormData();
5152
- formData.append(this.formDataName, file, file.name);
5153
- xhr.open("POST", this.target, true);
5154
- this._configureXhr(xhr);
5155
- file.status = "conectando";
5156
- file.uploading = file.indeterminate = true;
5157
- file.complete = file.abort = file.error = file.held = false;
5158
- xhr.send(formData);
5159
- }
5160
- _createXhr() {
5161
- return new XMLHttpRequest();
5162
- }
5163
- _configureXhr(xhr) {
5164
- if (typeof this.headers == 'string') {
5165
- try {
5166
- this.headers = JSON.parse(this.headers);
5167
- }
5168
- catch (e) {
5169
- this.headers = undefined;
5302
+ });
5303
+ this.value = this._updatingValue;
5304
+ this.ezChange.emit(this.value);
5305
+ }
5306
+ buildProgressId(uploading) {
5307
+ let sanitizedName = uploading.name.replace(/[^a-z0-9_]/gi, '_');
5308
+ return `PROGRESS_${sanitizedName}_${uploading.file.lastModified}`;
5309
+ }
5310
+ updateFeedback(uf) {
5311
+ window.requestAnimationFrame(() => {
5312
+ if (this._host) {
5313
+ const progress = this._host.shadowRoot.querySelector('#' + this.buildProgressId(uf));
5314
+ if (progress) {
5315
+ progress.value = uf.progress;
5316
+ }
5170
5317
  }
5318
+ });
5319
+ }
5320
+ validateFile(file) {
5321
+ if (this.maxfiles > 0 && this._filePointers.size >= this.maxfiles) {
5322
+ this.showError(`A quantidade máxima de arquivos é ${this.maxfiles}.`);
5323
+ return false;
5171
5324
  }
5172
- for (var key in this.headers) {
5173
- xhr.setRequestHeader(key, this.headers[key]);
5325
+ if (file.size === 0) {
5326
+ this.showError(`Erro de permissão: O arquivo "${file.name}" não pode ser enviado.`);
5327
+ return false;
5174
5328
  }
5175
- if (this.timeout) {
5176
- xhr.timeout = this.timeout;
5329
+ if (!this.urlupload) {
5330
+ this.showError("Endereço de upload não informado");
5331
+ return false;
5177
5332
  }
5178
- xhr.withCredentials = this.withCredentials;
5333
+ if (this.maxfilesize >= 0 && file.size > this.maxfilesize) {
5334
+ this.showError("O tamanho máximo dos arquivos é de " + this.formatBytes(this.maxfilesize));
5335
+ return false;
5336
+ }
5337
+ return true;
5338
+ }
5339
+ showError(message) {
5340
+ Application.alert("Enviando arquivo", message);
5179
5341
  }
5180
5342
  formatBytes(bytes, decimals = 1) {
5181
5343
  if (bytes === 0)
@@ -5187,96 +5349,92 @@ let EzUpload$1 = class extends HTMLElement {
5187
5349
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
5188
5350
  }
5189
5351
  onFileInputChange(event) {
5190
- this.addFiles(event.target.files);
5352
+ const input = event.target;
5353
+ this.addFiles(Array.from(input.files));
5191
5354
  this._fileInput.value = '';
5192
5355
  }
5193
- /*componentWillLoad() {
5194
- if (this.fileList?.length > 0) {
5195
- this.fileList.forEach(item => {
5196
- if (item.size) {
5197
- item.strSize = this.formatBytes(item.size);
5198
- }
5199
- })
5200
- this.fileList = [...this.fileList];
5356
+ isRemoteFile(item) {
5357
+ return "file" in item;
5358
+ }
5359
+ removeFromList(name) {
5360
+ this._filePointers.delete(name);
5361
+ this.updateValue();
5362
+ }
5363
+ removeFile(name) {
5364
+ const item = this._filePointers.get(name);
5365
+ if (this.isRemoteFile(item)) {
5366
+ item.abortUpload();
5367
+ this.removeFromList(name);
5368
+ }
5369
+ else {
5370
+ if (this.urldelete) {
5371
+ const uploadingFile = new RemoteFile(null);
5372
+ this._filePointers.set(item.name, uploadingFile);
5373
+ uploadingFile.delete(item, this.urldelete, null)
5374
+ .then(_ok => this.removeFromList(name))
5375
+ .catch(msg => this.showError(msg));
5376
+ }
5377
+ else {
5378
+ this.removeFromList(name);
5379
+ }
5380
+ }
5381
+ }
5382
+ openFilesDialog() {
5383
+ if (this.maxfiles > 0 && this._filePointers.size >= this.maxfiles) {
5384
+ this.showError(`A quantidade máxima de arquivos é ${this.maxfiles}.`);
5385
+ }
5386
+ else {
5387
+ this._fileInput.click();
5201
5388
  }
5202
- }*/
5203
- decode_utf8(s) {
5204
- return decodeURIComponent(escape(s));
5205
5389
  }
5206
5390
  componentDidLoad() {
5207
- if (this.dropZone && window.FileList && window.File) {
5208
- this.dropZone.addEventListener('dragover', event => {
5391
+ if (this._dropZone && window.FileList && window.File) {
5392
+ this._dropZone.addEventListener('dragover', event => {
5209
5393
  event.stopPropagation();
5210
5394
  event.preventDefault();
5211
5395
  event.dataTransfer.dropEffect = 'copy';
5212
5396
  });
5213
- this.dropZone.addEventListener('drop', event => {
5397
+ this._dropZone.addEventListener('drop', event => {
5214
5398
  event.stopPropagation();
5215
5399
  event.preventDefault();
5216
- this.addFiles(event.dataTransfer.files);
5400
+ this.addFiles(Array.from(event.dataTransfer.files));
5217
5401
  });
5218
5402
  }
5219
5403
  }
5220
- removeFile(name, xhr, downloadURL) {
5221
- if (xhr) {
5222
- xhr.abort();
5223
- }
5224
- if (downloadURL) {
5225
- this.removeFileFromServer(name, downloadURL);
5226
- }
5227
- this.value = [...this.value.filter(function (value) { return value.name !== name; })];
5228
- }
5229
- removeFileFromServer(name, donwloadURL) {
5230
- const xhr = this._createXhr();
5231
- this.errorMessage = '';
5232
- let stalledId;
5233
- xhr.onreadystatechange = () => {
5234
- if (xhr.readyState == 4) {
5235
- clearTimeout(stalledId);
5236
- if (xhr.status === 0) {
5237
- this.errorMessage = "Servidor indisponível";
5238
- }
5239
- else if (xhr.status >= 500) {
5240
- this.errorMessage = "Erro inesperado no servidor";
5241
- }
5242
- else if (xhr.status >= 400) {
5243
- this.errorMessage = "Operação não permitida";
5244
- }
5245
- if (this.errorMessage && this.errorMessage.length > 0) {
5246
- //TODO
5247
- // Conferir com o time de UX um estado de erro ou remoção da lista
5248
- // this.removeFile(file.name);
5249
- alert(this.errorMessage);
5250
- }
5251
- }
5252
- };
5253
- xhr.ontimeout = () => {
5254
- if (this.errorMessage && this.errorMessage.length > 0) {
5255
- alert(this.errorMessage);
5404
+ componentWillRender() {
5405
+ if (this.value) {
5406
+ if (this._filePointers.size < this.value.length) {
5407
+ this.updateFilePointers();
5256
5408
  }
5257
- };
5258
- const body = JSON.stringify({
5259
- name: name,
5260
- donwloadURL: donwloadURL,
5261
- });
5262
- xhr.open("DELETE", this.target, true);
5263
- xhr.setRequestHeader('Content-Type', 'application/json');
5264
- this._configureXhr(xhr);
5265
- xhr.send(body);
5409
+ }
5266
5410
  }
5267
5411
  render() {
5268
- var _a;
5269
- return (h(Host, null, h("slot", null, h("div", { ref: (el) => this.dropZone = el, class: "iu" }, h("div", { class: "iu__container" }, h("div", { onClick: () => this._fileInput.click(), class: "iu__icon-label" }, h("button", { class: "iu__file-icon" }), h("div", { class: "text text--center text--medium text--primary" }, "Arraste e solte ou clique para anexar arquivo")), ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) > 0 ?
5270
- h("div", { class: "iu__footer" }, this.value.map(file => {
5271
- return (h("div", { class: "iu__item" }, h("div", { class: "iu__item-label" + (file.progress ? " modificador " : " modificador ") }, file.downloadURL ?
5272
- h("div", { title: file.name + "(" + this.formatBytes(file.size) + ")", class: "file__name text text--primary text--small text--ellipsis align--middle" }, h("a", { href: file.downloadURL, download: true }, file.name, " (", this.formatBytes(file.size), ")"))
5273
- :
5274
- h("div", { title: file.name + "(" + this.formatBytes(file.size) + ")", class: "col--stretch align--middle file__name text text--primary text--small text--ellipsis align--middle " }, file.name, " (", this.formatBytes(file.size), ")")), file.progress ?
5275
- h("div", { class: "col col--sd-4 col--stretch align--middle" }, h("progress", { value: file.progress, max: "100" }))
5276
- : undefined, h("div", { class: "col col--stretch align--middle" }, h("button", { class: "btn-cancel ", onClick: () => this.removeFile(file.name, file.xhr) }))));
5277
- }))
5278
- : undefined))), h("input", { ref: (el) => this._fileInput = el, type: "file", id: "fileInput", hidden: true, onChange: (ev) => this.onFileInputChange(ev), multiple: true })));
5412
+ return (h("div", { ref: (el) => this._dropZone = el, class: "iu" }, this.label ? h("label", { class: "iu__label", title: this.label }, this.label) : null, h("div", { class: "iu__container", onClick: () => this.openFilesDialog() }, h("div", { class: "iu__icon-label" }, h("button", { class: "iu__file-icon" }), h("div", { class: "text text--center text--medium text--primary" }, "Arraste e solte ou clique para adicionar arquivos")), this.buildFooter()), h("input", { ref: (el) => this._fileInput = el, onChange: (ev) => this.onFileInputChange(ev), type: "file", multiple: true, hidden: true })));
5279
5413
  }
5414
+ buildFooter() {
5415
+ if (this._filePointers.size === 0) {
5416
+ return null;
5417
+ }
5418
+ const items = [];
5419
+ this._filePointers.forEach(item => items.push(this.buildFileItem(item)));
5420
+ return (h("div", { class: "iu__footer" }, items));
5421
+ }
5422
+ buildFileItem(item) {
5423
+ const fileName = item.name;
5424
+ const progress = Number(item['progress']);
5425
+ const downloadURL = item['downloadURL'];
5426
+ const label = `${fileName} (${this.formatBytes(item.size)})`;
5427
+ return (h("div", { class: "iu__item", key: fileName, onClick: evt => evt.stopPropagation() }, h("div", { class: "iu__item-label modificador" }, h("div", { title: label, class: "col--stretch align--middle file__name text text--primary text--small text--ellipsis align--middle" }, downloadURL ? h("a", { href: downloadURL, download: true }, label) : label)), isNaN(progress)
5428
+ ?
5429
+ null
5430
+ :
5431
+ h("div", { class: "col col--sd-4 col--stretch align--middle" }, h("progress", { id: this.buildProgressId(item), value: progress, max: "100" })), h("div", { class: "col col--stretch align--middle" }, h("button", { class: "btn-cancel ", onClick: () => this.removeFile(fileName) }))));
5432
+ }
5433
+ get _host() { return this; }
5434
+ static get watchers() { return {
5435
+ "value": ["changeValue"],
5436
+ "requestheaders": ["normalizeRequestHeaders"]
5437
+ }; }
5280
5438
  static get style() { return ezUploadCss; }
5281
5439
  };
5282
5440
 
@@ -5304,11 +5462,6 @@ let FormMetadata$1 = class extends HTMLElement {
5304
5462
  properties.push({ name: "options", value: JSON.stringify(objOpts) });
5305
5463
  }
5306
5464
  else if (userInterface === "FILE") {
5307
- /*<URL>http://localhost:8080/2a3skw-graphql/uploadFiles</URL>
5308
- <HEADERS>
5309
- <HEADER NAME="Authorization">dsfs</HEADER>
5310
- </HEADER>
5311
- </field> */
5312
5465
  const urlElement = element.querySelector('URL');
5313
5466
  const headersElement = element.querySelectorAll('HEADERS>HEADER');
5314
5467
  if (urlElement) {
@@ -5321,6 +5474,7 @@ let FormMetadata$1 = class extends HTMLElement {
5321
5474
  });
5322
5475
  properties.push({ name: "HEADERS", value: JSON.stringify(headers) });
5323
5476
  }
5477
+ this.addPropertyIfExists(properties, element, "maxfiles");
5324
5478
  }
5325
5479
  else {
5326
5480
  if (!label) {
@@ -5425,9 +5579,9 @@ const EzButton = /*@__PURE__*/proxyCustomElement(EzButton$1, [1,"ez-button",{"la
5425
5579
  const EzCalendar = /*@__PURE__*/proxyCustomElement(EzCalendar$1, [1,"ez-calendar",{"value":[1040],"floating":[516]}]);
5426
5580
  const EzCheck = /*@__PURE__*/proxyCustomElement(EzCheck$1, [1,"ez-check",{"label":[513],"value":[1540],"enabled":[516],"mode":[513]}]);
5427
5581
  const EzCollapsableBox = /*@__PURE__*/proxyCustomElement(EzCollapsableBox$1, [1,"ez-collapsable-box",{"value":[1540],"label":[513]}]);
5428
- const EzComboBox = /*@__PURE__*/proxyCustomElement(EzComboBox$1, [1,"ez-combo-box",{"value":[1040],"label":[513],"enabled":[516],"options":[1040],"errormessage":[1537],"searchmode":[4],"showselectedvalue":[4],"showoptionvalue":[4],"optionloader":[16],"_preSelection":[32],"_visibleOptions":[32]}]);
5582
+ const EzComboBox = /*@__PURE__*/proxyCustomElement(EzComboBox$1, [1,"ez-combo-box",{"value":[1537],"label":[513],"enabled":[516],"options":[1040],"errormessage":[1537],"searchmode":[4],"showselectedvalue":[4],"showoptionvalue":[4],"optionloader":[16],"_preSelection":[32],"_visibleOptions":[32]}]);
5429
5583
  const EzDateInput = /*@__PURE__*/proxyCustomElement(EzDateInput$1, [1,"ez-date-input",{"label":[513],"value":[1040],"enabled":[516],"errormessage":[1537]}]);
5430
- const EzDialog = /*@__PURE__*/proxyCustomElement(EzDialog$1, [1,"ez-dialog",{"confirm":[1028],"critical":[1028],"message":[1025],"oppened":[1540],"personalizedIconPath":[1025,"personalized-icon-path"],"title":[1025]}]);
5584
+ const EzDialog = /*@__PURE__*/proxyCustomElement(EzDialog$1, [1,"ez-dialog",{"confirm":[1028],"critical":[1028],"message":[1025],"oppened":[1540],"personalizedIconPath":[1025,"personalized-icon-path"],"ezTitle":[1025,"ez-title"]}]);
5431
5585
  const EzForm = /*@__PURE__*/proxyCustomElement(EzForm$1, [0,"ez-form",{"metadataexecutor":[1],"loadexecutor":[1],"saveexecutor":[1],"removeexecutor":[1],"fieldsearchexecutor":[1],"ignoresavevalidation":[4],"metadata":[16],"slavemode":[4],"enabled":[4]}]);
5432
5586
  const EzIcon = /*@__PURE__*/proxyCustomElement(EzIcon$1, [1,"ez-icon",{"size":[513],"href":[513]}]);
5433
5587
  const EzLabelChip = /*@__PURE__*/proxyCustomElement(EzLabelChip$1, [1,"ez-label-chip",{"label":[513],"enabled":[516],"removable":[516],"value":[1540]}]);
@@ -5435,13 +5589,14 @@ const EzModal = /*@__PURE__*/proxyCustomElement(EzModal$1, [1,"ez-modal",{"modal
5435
5589
  const EzNumberInput = /*@__PURE__*/proxyCustomElement(NumberInput, [1,"ez-number-input",{"strvalue":[1025],"value":[1026],"label":[513],"enabled":[516],"errormessage":[1537],"precision":[1538],"prettyprecision":[1538],"textleft":[516],"formatnumber":[513]}]);
5436
5590
  const EzNumericInput = /*@__PURE__*/proxyCustomElement(EzNumericInput$1, [1,"ez-numeric-input",{"label":[513],"value":[1538],"enabled":[516],"errormessage":[1537],"precision":[8],"prettyprecision":[8]}]);
5437
5591
  const EzPopover = /*@__PURE__*/proxyCustomElement(EzPopover$1, [1,"ez-popover",{"autoclose":[516],"top":[1537],"left":[1537],"bottom":[1537],"right":[1537],"boxwidth":[513],"isOpened":[1540,"is-opened"]}]);
5438
- const EzPopup = /*@__PURE__*/proxyCustomElement(EzPopup$1, [1,"ez-popup",{"size":[1],"opened":[1540],"useHeader":[1540,"use-header"],"title":[1]}]);
5439
- const EzSearch = /*@__PURE__*/proxyCustomElement(EzSearch$1, [1,"ez-search",{"value":[1040],"label":[1537],"enabled":[1540],"errormessage":[1537],"optionloader":[16],"showselectedvalue":[4],"showoptionvalue":[4]}]);
5592
+ const EzPopup = /*@__PURE__*/proxyCustomElement(EzPopup$1, [1,"ez-popup",{"size":[1],"opened":[1540],"useHeader":[1540,"use-header"],"ezTitle":[1,"ez-title"]}]);
5593
+ const EzSearch = /*@__PURE__*/proxyCustomElement(EzSearch$1, [1,"ez-search",{"value":[1537],"label":[1537],"enabled":[1540],"errormessage":[1537],"optionloader":[16],"showselectedvalue":[4],"showoptionvalue":[4]}]);
5440
5594
  const EzTabselector = /*@__PURE__*/proxyCustomElement(EzTabselector$1, [1,"ez-tabselector",{"selectedindex":[1537],"selectedtab":[1537],"tabs":[1]}]);
5441
5595
  const EzTextArea = /*@__PURE__*/proxyCustomElement(EzTextArea$1, [1,"ez-text-area",{"label":[513],"value":[1537],"enabled":[516],"loading":[516],"errormessage":[1537],"rows":[1538]}]);
5442
5596
  const EzTextInput = /*@__PURE__*/proxyCustomElement(EzTextInput$1, [1,"ez-text-input",{"label":[513],"value":[1537],"enabled":[516],"loading":[516],"errormessage":[1537],"onlynumber":[516],"mask":[1],"restrict":[1]}]);
5443
5597
  const EzTimeInput = /*@__PURE__*/proxyCustomElement(EzTimeInput$1, [1,"ez-time-input",{"label":[513],"viewValue":[1537,"view-value"],"value":[1026],"enabled":[516],"errormessage":[1537],"showSeconds":[516,"show-seconds"]}]);
5444
- const EzUpload = /*@__PURE__*/proxyCustomElement(EzUpload$1, [1,"ez-upload",{"maxFileSize":[514,"max-file-size"],"headers":[520],"timeout":[514],"withCredentials":[516,"with-credentials"],"formDataName":[513,"form-data-name"],"target":[513],"value":[16]}]);
5598
+ const EzToast = /*@__PURE__*/proxyCustomElement(EzToast$1, [1,"ez-toast",{"message":[1025],"fadeTime":[1026,"fade-time"],"useIcon":[1028,"use-icon"]}]);
5599
+ const EzUpload = /*@__PURE__*/proxyCustomElement(EzUpload$1, [1,"ez-upload",{"label":[1],"enabled":[4],"maxfilesize":[2],"maxfiles":[2],"requestheaders":[8],"urlupload":[1],"urldelete":[1],"value":[1040]}]);
5445
5600
  const FormMetadata = /*@__PURE__*/proxyCustomElement(FormMetadata$1, [1,"form-metadata",{"name":[1],"label":[1],"dataunit":[1025],"many":[4],"autoload":[4],"metadata":[1040]}]);
5446
5601
  const PlaceHolder = /*@__PURE__*/proxyCustomElement(PlaceHolder$1, [1,"place-holder"]);
5447
5602
  const defineCustomElements = (opts) => {
@@ -5468,6 +5623,7 @@ const defineCustomElements = (opts) => {
5468
5623
  EzTextArea,
5469
5624
  EzTextInput,
5470
5625
  EzTimeInput,
5626
+ EzToast,
5471
5627
  EzUpload,
5472
5628
  FormMetadata,
5473
5629
  PlaceHolder
@@ -5479,4 +5635,4 @@ const defineCustomElements = (opts) => {
5479
5635
  }
5480
5636
  };
5481
5637
 
5482
- export { EzActionChip, EzButton, EzCalendar, EzCheck, EzCollapsableBox, EzComboBox, EzDateInput, EzDialog, EzForm, EzIcon, EzLabelChip, EzModal, EzNumberInput, EzNumericInput, EzPopover, EzPopup, EzSearch, EzTabselector, EzTextArea, EzTextInput, EzTimeInput, EzUpload, FormMetadata, PlaceHolder, defineCustomElements };
5638
+ export { EzActionChip, EzButton, EzCalendar, EzCheck, EzCollapsableBox, EzComboBox, EzDateInput, EzDialog, EzForm, EzIcon, EzLabelChip, EzModal, EzNumberInput, EzNumericInput, EzPopover, EzPopup, EzSearch, EzTabselector, EzTextArea, EzTextInput, EzTimeInput, EzToast, EzUpload, FormMetadata, PlaceHolder, defineCustomElements };