@sankhyalabs/ezui 1.1.40 → 1.1.41

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.
@@ -2938,14 +2938,7 @@ const NavigationBar = ({ dataUnit: du, buttonProps, enabled }) => {
2938
2938
  buttonProps.removeVisible ? h("ez-button", { key: du.name + '_remove', label: "Remover", enabled: enabled && du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2939
2939
  buttonProps.addVisible ? h("ez-button", { key: du.name + '_add', label: "Adicionar", enabled: enabled, onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2940
2940
  buttonProps.reloadVisible ? h("ez-button", { key: du.name + '_reload', title: "Recarregar", enabled: enabled, mode: "icon", onClick: () => du.load(), image: "/themes/default/images/icons/actions-sprite.svg#rotate", class: "button--secondary margin-right--medium" }) : null,
2941
- buttonProps.cancelVisible ? h("ez-button", { key: du.name + '_cancel', label: "Cancelar", enabled: enabled && du.hasChanges(), onClick: () => {
2942
- Application.confirm("Confirmar cancelamento", "Você perderá a edição atual do registro. Deseja continuar?", /*
2943
- getAssetPath("./assets/trash-can-outline.svg")*/ null, true).then(ok => {
2944
- if (ok) {
2945
- du.cancel();
2946
- }
2947
- });
2948
- }, class: "button--secondary margin-right--medium" }) : null,
2941
+ buttonProps.cancelVisible ? h("ez-button", { key: du.name + '_cancel', label: "Cancelar", enabled: enabled && du.hasChanges(), onClick: () => du.cancel(), class: "button--secondary margin-right--medium" }) : null,
2949
2942
  buttonProps.saveVisible ? h("ez-button", { key: du.name + '_save', label: "Salvar", enabled: enabled && du.hasChanges(), onClick: () => du.save(), class: "button--primary margin-right--medium" }) : null);
2950
2943
  }
2951
2944
  else {
@@ -3342,10 +3335,9 @@ const Field = ({ dataUnit, field, forceScroll, enabled }) => {
3342
3335
  const target = getProp(properties, 'URL');
3343
3336
  const strHeaders = getProp(properties, 'HEADERS');
3344
3337
  const headers = strHeaders ? JSON.parse(strHeaders) : {};
3338
+ const maxfiles = Number(getProp(properties, "maxfiles") || 0);
3345
3339
  return (h("div", { class: "col col--sd-12 padding--small" },
3346
- h("ez-upload", { onEzChange: (event) => {
3347
- changeFieldHandler(event.target['value']);
3348
- }, 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 })));
3349
3341
  case 'DATE':
3350
3342
  return h("div", { class: "col col--sd-12 col--tb-3 padding--small" }, loadingData ? h("place-holder", null) :
3351
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 }));
@@ -5132,144 +5124,217 @@ let EzToast$1 = class extends HTMLElement {
5132
5124
  static get style() { return ezToastCss; }
5133
5125
  };
5134
5126
 
5135
- 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%}}";
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%}}";
5136
5218
 
5137
5219
  let EzUpload$1 = class extends HTMLElement {
5138
5220
  constructor() {
5139
5221
  super();
5140
5222
  this.__registerHost();
5141
5223
  this.__attachShadow();
5142
- this.validatedEvent = createEvent(this, "validatedEvent", 7);
5143
- this.initUploadEvent = createEvent(this, "initUploadEvent", 7);
5144
- this.finishedUploadEvent = createEvent(this, "finishedUploadEvent", 7);
5145
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;
5146
5230
  }
5147
- fileListChange() {
5148
- this.ezChange.emit({ value: this.value });
5231
+ updatePointers(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
+ if (newValue) {
5240
+ newValue.forEach(ezFile => this._filePointers.set(ezFile.name, ezFile));
5241
+ }
5242
+ }
5243
+ this._updatingValue = undefined;
5244
+ }
5245
+ normalizeRequestHeaders() {
5246
+ this._requestHeaders = new Map();
5247
+ if (typeof this.requestheaders == 'string') {
5248
+ try {
5249
+ this.requestheaders = JSON.parse(this.requestheaders);
5250
+ }
5251
+ catch (e) {
5252
+ this.requestheaders = undefined;
5253
+ }
5254
+ }
5255
+ for (var key in this.requestheaders) {
5256
+ this._requestHeaders.set(key, this.requestheaders[key]);
5257
+ }
5149
5258
  }
5150
5259
  async addFiles(files) {
5151
5260
  Array.prototype.forEach.call(files, this.addFile.bind(this));
5152
5261
  }
5153
- addFile(file) {
5154
- this.errorMessage = undefined;
5155
- if (this.validateFile(file)) {
5156
- if (this.target) {
5157
- this._uploadFile(file);
5158
- }
5159
- else {
5160
- this.errorMessage = "Endereço de upload não informado";
5161
- alert(this.errorMessage);
5162
- }
5262
+ async addFile(file) {
5263
+ const oldFile = this._filePointers.get(file.name);
5264
+ if (oldFile) {
5265
+ Application.confirm("Substituir arquivo", `Já existe um arquivo chamado "${file.name}". Deseja substituí-lo?`)
5266
+ .then(ok => {
5267
+ if (ok) {
5268
+ if (this.isRemoteFile(oldFile)) {
5269
+ oldFile.abortUpload();
5270
+ }
5271
+ this.doAddFile(file);
5272
+ }
5273
+ });
5163
5274
  }
5164
5275
  else {
5165
- if (this.errorMessage && this.errorMessage.length > 0) {
5166
- alert(this.errorMessage);
5167
- }
5276
+ this.doAddFile(file);
5168
5277
  }
5169
5278
  }
5170
- validateFile(file) {
5171
- this.errorMessage = '';
5172
- let isValid = true;
5173
- if (this.maxFileSize >= 0 && file.size > this.maxFileSize) {
5174
- this.errorMessage = 'O tamanho máximo dos arquivos é de ' + this.formatBytes(this.maxFileSize);
5175
- isValid = false;
5176
- }
5177
- this.validatedEvent.emit({ isValid: isValid, fileName: file.name });
5178
- return isValid;
5179
- }
5180
- _uploadFile(file) {
5181
- const xhr = (file.xhr = this._createXhr());
5182
- const newValue = this.value ? [...this.value] : [];
5183
- newValue.push({ name: file.name, size: file.size, xhr: file.xhr });
5184
- let stalledId;
5185
- xhr.upload.onprogress = (e) => {
5186
- clearTimeout(stalledId);
5187
- const loaded = e.loaded, total = e.total, progress = ~~((loaded / total) * 100);
5188
- let viewFile = newValue.find(f => f.name === file.name);
5189
- if (viewFile) {
5190
- viewFile.progress = progress;
5279
+ async doAddFile(file) {
5280
+ if (this.validateFile(file)) {
5281
+ const uploadingFile = new RemoteFile(file);
5282
+ this._filePointers.set(file.name, uploadingFile);
5283
+ uploadingFile.upload(this.urlupload, this._requestHeaders, (file) => this.updateFeedback(file))
5284
+ .then((files) => files.forEach(ezFile => this.finishUpload(ezFile)))
5285
+ .catch(msg => this.showError(msg));
5286
+ forceUpdate(this);
5287
+ }
5288
+ }
5289
+ finishUpload(ezFile) {
5290
+ this._filePointers.set(ezFile.name, ezFile);
5291
+ this.updateValue();
5292
+ }
5293
+ updateValue() {
5294
+ this._updatingValue = [];
5295
+ this._filePointers.forEach(f => {
5296
+ if (!this.isRemoteFile(f)) {
5297
+ this._updatingValue.push(f);
5191
5298
  }
5192
- };
5193
- xhr.onreadystatechange = () => {
5194
- this.errorMessage = '';
5195
- if (xhr.readyState == 4) {
5196
- clearTimeout(stalledId);
5197
- file.indeterminate = file.uploading = false;
5198
- if (xhr.status === 0) ;
5199
- else if (xhr.status >= 500) {
5200
- this.errorMessage = "Erro inesperado no servidor";
5201
- }
5202
- else if (xhr.status >= 400) {
5203
- this.errorMessage = "Operação não permitida";
5204
- }
5205
- if (this.errorMessage && this.errorMessage.length > 0) {
5206
- //TODO
5207
- // Conferir com o time de UX um estado de erro ou remoção da lista
5208
- // this.removeFile(file.name);
5209
- alert(this.errorMessage);
5210
- }
5211
- else {
5212
- if (xhr.response) {
5213
- let response = JSON.parse(xhr.response);
5214
- response.forEach(element => {
5215
- let viewFile = newValue.find(f => f.name === this.decode_utf8(element.name));
5216
- if (viewFile) {
5217
- viewFile.progress = undefined;
5218
- //Validar estado de erro com UX
5219
- viewFile.error = false;
5220
- delete viewFile.xhr;
5221
- viewFile.downloadURL = element.downloadURL;
5222
- viewFile.lastModifiedDate = element.lastModifiedDate;
5223
- viewFile.properties = element.properties;
5224
- }
5225
- });
5226
- this.value = newValue;
5227
- this.fileListChange();
5228
- }
5229
- else {
5230
- let viewFile = newValue.find(f => f.name === file.name);
5231
- viewFile.progress = undefined;
5232
- //Validar estado de erro com UX
5233
- viewFile.error = true;
5234
- }
5299
+ });
5300
+ this.value = this._updatingValue;
5301
+ this.ezChange.emit(this.value);
5302
+ }
5303
+ buildProgressId(uploading) {
5304
+ let sanitizedName = uploading.name.replace(/[^a-z0-9_]/gi, '_');
5305
+ return `PROGRESS_${sanitizedName}_${uploading.file.lastModified}`;
5306
+ }
5307
+ updateFeedback(uf) {
5308
+ window.requestAnimationFrame(() => {
5309
+ if (this._host) {
5310
+ const progress = this._host.shadowRoot.querySelector('#' + this.buildProgressId(uf));
5311
+ if (progress) {
5312
+ progress.value = uf.progress;
5235
5313
  }
5236
5314
  }
5237
- };
5238
- xhr.ontimeout = () => {
5239
- if (this.errorMessage && this.errorMessage.length > 0) {
5240
- this.errorMessage.concat(" / Tempo expirado");
5241
- this.removeFile(file.name);
5242
- alert(this.errorMessage);
5243
- }
5244
- };
5245
- const formData = new FormData();
5246
- formData.append(this.formDataName, file, file.name);
5247
- xhr.open("POST", this.target, true);
5248
- this._configureXhr(xhr);
5249
- file.status = "conectando";
5250
- file.uploading = file.indeterminate = true;
5251
- file.complete = file.abort = file.error = file.held = false;
5252
- xhr.send(formData);
5253
- }
5254
- _createXhr() {
5255
- return new XMLHttpRequest();
5256
- }
5257
- _configureXhr(xhr) {
5258
- if (typeof this.headers == 'string') {
5259
- try {
5260
- this.headers = JSON.parse(this.headers);
5261
- }
5262
- catch (e) {
5263
- this.headers = undefined;
5264
- }
5315
+ });
5316
+ }
5317
+ validateFile(file) {
5318
+ if (this.maxfiles > 0 && this._filePointers.size >= this.maxfiles) {
5319
+ this.showError(`A quantidade máxima de arquivos é ${this.maxfiles}.`);
5320
+ return false;
5321
+ }
5322
+ if (file.size === 0) {
5323
+ this.showError(`Erro de permissão: O arquivo "${file.name}" não pode ser enviado.`);
5324
+ return false;
5265
5325
  }
5266
- for (var key in this.headers) {
5267
- xhr.setRequestHeader(key, this.headers[key]);
5326
+ if (!this.urlupload) {
5327
+ this.showError("Endereço de upload não informado");
5328
+ return false;
5268
5329
  }
5269
- if (this.timeout) {
5270
- xhr.timeout = this.timeout;
5330
+ if (this.maxfilesize >= 0 && file.size > this.maxfilesize) {
5331
+ this.showError("O tamanho máximo dos arquivos é de " + this.formatBytes(this.maxfilesize));
5332
+ return false;
5271
5333
  }
5272
- xhr.withCredentials = this.withCredentials;
5334
+ return true;
5335
+ }
5336
+ showError(message) {
5337
+ Application.alert("Enviando arquivo", message);
5273
5338
  }
5274
5339
  formatBytes(bytes, decimals = 1) {
5275
5340
  if (bytes === 0)
@@ -5281,97 +5346,85 @@ let EzUpload$1 = class extends HTMLElement {
5281
5346
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
5282
5347
  }
5283
5348
  onFileInputChange(event) {
5284
- this.addFiles(event.target.files);
5349
+ const input = event.target;
5350
+ this.addFiles(Array.from(input.files));
5285
5351
  this._fileInput.value = '';
5286
5352
  }
5287
- /*componentWillLoad() {
5288
- if (this.fileList?.length > 0) {
5289
- this.fileList.forEach(item => {
5290
- if (item.size) {
5291
- item.strSize = this.formatBytes(item.size);
5292
- }
5293
- })
5294
- this.fileList = [...this.fileList];
5353
+ isRemoteFile(item) {
5354
+ return "file" in item;
5355
+ }
5356
+ removeFromList(name) {
5357
+ this._filePointers.delete(name);
5358
+ this.updateValue();
5359
+ }
5360
+ removeFile(name) {
5361
+ const item = this._filePointers.get(name);
5362
+ if (this.isRemoteFile(item)) {
5363
+ item.abortUpload();
5364
+ this.removeFromList(name);
5365
+ }
5366
+ else {
5367
+ if (this.urldelete) {
5368
+ const uploadingFile = new RemoteFile(null);
5369
+ this._filePointers.set(item.name, uploadingFile);
5370
+ uploadingFile.delete(item, this.urldelete, null)
5371
+ .then(_ok => this.removeFromList(name))
5372
+ .catch(msg => this.showError(msg));
5373
+ }
5374
+ else {
5375
+ this.removeFromList(name);
5376
+ }
5295
5377
  }
5296
- }*/
5297
- decode_utf8(s) {
5298
- return decodeURIComponent(escape(s));
5299
5378
  }
5300
5379
  componentDidLoad() {
5301
- if (this.dropZone && window.FileList && window.File) {
5302
- this.dropZone.addEventListener('dragover', event => {
5380
+ if (this._dropZone && window.FileList && window.File) {
5381
+ this._dropZone.addEventListener('dragover', event => {
5303
5382
  event.stopPropagation();
5304
5383
  event.preventDefault();
5305
5384
  event.dataTransfer.dropEffect = 'copy';
5306
5385
  });
5307
- this.dropZone.addEventListener('drop', event => {
5386
+ this._dropZone.addEventListener('drop', event => {
5308
5387
  event.stopPropagation();
5309
5388
  event.preventDefault();
5310
- this.addFiles(event.dataTransfer.files);
5389
+ this.addFiles(Array.from(event.dataTransfer.files));
5311
5390
  });
5312
5391
  }
5313
5392
  }
5314
- removeFile(name, xhr, downloadURL) {
5315
- if (xhr) {
5316
- xhr.abort();
5393
+ openFilesDialog() {
5394
+ if (this.maxfiles > 0 && this._filePointers.size >= this.maxfiles) {
5395
+ this.showError(`A quantidade máxima de arquivos é ${this.maxfiles}.`);
5317
5396
  }
5318
- if (downloadURL) {
5319
- this.removeFileFromServer(name, downloadURL);
5397
+ else {
5398
+ this._fileInput.click();
5320
5399
  }
5321
- this.value = [...this.value.filter(function (value) { return value.name !== name; })];
5322
- this.fileListChange();
5323
- }
5324
- removeFileFromServer(name, donwloadURL) {
5325
- const xhr = this._createXhr();
5326
- this.errorMessage = '';
5327
- let stalledId;
5328
- xhr.onreadystatechange = () => {
5329
- if (xhr.readyState == 4) {
5330
- clearTimeout(stalledId);
5331
- if (xhr.status === 0) {
5332
- this.errorMessage = "Servidor indisponível";
5333
- }
5334
- else if (xhr.status >= 500) {
5335
- this.errorMessage = "Erro inesperado no servidor";
5336
- }
5337
- else if (xhr.status >= 400) {
5338
- this.errorMessage = "Operação não permitida";
5339
- }
5340
- if (this.errorMessage && this.errorMessage.length > 0) {
5341
- //TODO
5342
- // Conferir com o time de UX um estado de erro ou remoção da lista
5343
- // this.removeFile(file.name);
5344
- alert(this.errorMessage);
5345
- }
5346
- }
5347
- };
5348
- xhr.ontimeout = () => {
5349
- if (this.errorMessage && this.errorMessage.length > 0) {
5350
- alert(this.errorMessage);
5351
- }
5352
- };
5353
- const body = JSON.stringify({
5354
- name: name,
5355
- donwloadURL: donwloadURL,
5356
- });
5357
- xhr.open("DELETE", this.target, true);
5358
- xhr.setRequestHeader('Content-Type', 'application/json');
5359
- this._configureXhr(xhr);
5360
- xhr.send(body);
5361
5400
  }
5362
5401
  render() {
5363
- var _a;
5364
- 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 ?
5365
- h("div", { class: "iu__footer" }, this.value.map(file => {
5366
- return (h("div", { class: "iu__item" }, h("div", { class: "iu__item-label" + (file.progress ? " modificador " : " modificador ") }, file.downloadURL ?
5367
- 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), ")"))
5368
- :
5369
- 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 ?
5370
- h("div", { class: "col col--sd-4 col--stretch align--middle" }, h("progress", { value: file.progress, max: "100" }))
5371
- : undefined, h("div", { class: "col col--stretch align--middle" }, h("button", { class: "btn-cancel ", onClick: () => this.removeFile(file.name, file.xhr) }))));
5372
- }))
5373
- : undefined))), h("input", { ref: (el) => this._fileInput = el, type: "file", id: "fileInput", hidden: true, onChange: (ev) => this.onFileInputChange(ev), multiple: true })));
5402
+ 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 })));
5403
+ }
5404
+ buildFooter() {
5405
+ if (this._filePointers.size === 0) {
5406
+ return null;
5407
+ }
5408
+ const items = [];
5409
+ this._filePointers.forEach(item => items.push(this.buildFileItem(item)));
5410
+ return (h("div", { class: "iu__footer" }, items));
5374
5411
  }
5412
+ buildFileItem(item) {
5413
+ const fileName = item.name;
5414
+ const progress = Number(item['progress']);
5415
+ const downloadURL = item['downloadURL'];
5416
+ const label = `${fileName} (${this.formatBytes(item.size)})`;
5417
+ 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)
5418
+ ?
5419
+ null
5420
+ :
5421
+ 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) }))));
5422
+ }
5423
+ get _host() { return this; }
5424
+ static get watchers() { return {
5425
+ "value": ["updatePointers"],
5426
+ "requestheaders": ["normalizeRequestHeaders"]
5427
+ }; }
5375
5428
  static get style() { return ezUploadCss; }
5376
5429
  };
5377
5430
 
@@ -5399,11 +5452,6 @@ let FormMetadata$1 = class extends HTMLElement {
5399
5452
  properties.push({ name: "options", value: JSON.stringify(objOpts) });
5400
5453
  }
5401
5454
  else if (userInterface === "FILE") {
5402
- /*<URL>http://localhost:8080/2a3skw-graphql/uploadFiles</URL>
5403
- <HEADERS>
5404
- <HEADER NAME="Authorization">dsfs</HEADER>
5405
- </HEADER>
5406
- </field> */
5407
5455
  const urlElement = element.querySelector('URL');
5408
5456
  const headersElement = element.querySelectorAll('HEADERS>HEADER');
5409
5457
  if (urlElement) {
@@ -5416,6 +5464,7 @@ let FormMetadata$1 = class extends HTMLElement {
5416
5464
  });
5417
5465
  properties.push({ name: "HEADERS", value: JSON.stringify(headers) });
5418
5466
  }
5467
+ this.addPropertyIfExists(properties, element, "maxfiles");
5419
5468
  }
5420
5469
  else {
5421
5470
  if (!label) {
@@ -5537,7 +5586,7 @@ const EzTextArea = /*@__PURE__*/proxyCustomElement(EzTextArea$1, [1,"ez-text-are
5537
5586
  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]}]);
5538
5587
  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"]}]);
5539
5588
  const EzToast = /*@__PURE__*/proxyCustomElement(EzToast$1, [1,"ez-toast",{"message":[1025],"fadeTime":[1026,"fade-time"],"useIcon":[1028,"use-icon"]}]);
5540
- 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]}]);
5589
+ 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]}]);
5541
5590
  const FormMetadata = /*@__PURE__*/proxyCustomElement(FormMetadata$1, [1,"form-metadata",{"name":[1],"label":[1],"dataunit":[1025],"many":[4],"autoload":[4],"metadata":[1040]}]);
5542
5591
  const PlaceHolder = /*@__PURE__*/proxyCustomElement(PlaceHolder$1, [1,"place-holder"]);
5543
5592
  const defineCustomElements = (opts) => {