@sankhyalabs/ezui 1.1.40 → 1.1.44

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) : {};
3345
- 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 })));
3338
+ const maxfiles = Number(getProp(properties, "maxfiles") || 0);
3339
+ return (h("div", { class: "col col--sd-12 padding--small" }, loadingData ? h("place-holder", null) :
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,220 @@ 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);--iu__btn-cancel-image:url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"8x\" width=\"8px\"><path d=\"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\"/></svg>');--iu__file-icon-image:url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" height=\"11x\" width=\"9px\"><path d=\"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\"/></svg>');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;-webkit-mask-image:var(--iu__btn-cancel-image);mask-image:var(--iu__btn-cancel-image)}.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:disabled{cursor:unset}.iu__file-icon::after{content:'';display:flex;background-color:var(--text--primary, #626e82);width:9px;height:11px;-webkit-mask-image:var(--iu__file-icon-image);mask-image:var(--iu__file-icon-image)}.iu__file-icon:disabled::after{background-color:var(--text--disable, #AFB6C0)}.iu__icon-label{justify-content:center;display:flex;cursor:pointer;padding:var(--iu--padding--large) 0px;box-sizing:border-box}.background--disabled{background-color:var(--color--disable-secondary, #F2F5F8)}.text--disabled{color:var(--text--disable, #AFB6C0)}.mouse-pointer--disabled{cursor:none}.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
+ 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;
5149
5242
  }
5150
- async addFiles(files) {
5151
- 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
+ }
5152
5247
  }
5153
- addFile(file) {
5154
- this.errorMessage = undefined;
5155
- if (this.validateFile(file)) {
5156
- if (this.target) {
5157
- 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);
5158
5253
  }
5159
- else {
5160
- this.errorMessage = "Endereço de upload não informado";
5161
- alert(this.errorMessage);
5254
+ catch (e) {
5255
+ this.requestheaders = undefined;
5162
5256
  }
5163
5257
  }
5164
- else {
5165
- if (this.errorMessage && this.errorMessage.length > 0) {
5166
- alert(this.errorMessage);
5167
- }
5258
+ for (var key in this.requestheaders) {
5259
+ this._requestHeaders.set(key, this.requestheaders[key]);
5168
5260
  }
5169
5261
  }
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;
5191
- }
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;
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();
5234
5273
  }
5274
+ this.doAddFile(file);
5235
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);
5236
5301
  }
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;
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
+ }
5264
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;
5324
+ }
5325
+ if (file.size === 0) {
5326
+ this.showError(`Erro de permissão: O arquivo "${file.name}" não pode ser enviado.`);
5327
+ return false;
5265
5328
  }
5266
- for (var key in this.headers) {
5267
- xhr.setRequestHeader(key, this.headers[key]);
5329
+ if (!this.urlupload) {
5330
+ this.showError("Endereço de upload não informado");
5331
+ return false;
5268
5332
  }
5269
- if (this.timeout) {
5270
- xhr.timeout = this.timeout;
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;
5271
5336
  }
5272
- xhr.withCredentials = this.withCredentials;
5337
+ return true;
5338
+ }
5339
+ showError(message) {
5340
+ Application.alert("Enviando arquivo", message);
5273
5341
  }
5274
5342
  formatBytes(bytes, decimals = 1) {
5275
5343
  if (bytes === 0)
@@ -5281,97 +5349,107 @@ let EzUpload$1 = class extends HTMLElement {
5281
5349
  return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
5282
5350
  }
5283
5351
  onFileInputChange(event) {
5284
- this.addFiles(event.target.files);
5352
+ const input = event.target;
5353
+ this.addFiles(Array.from(input.files));
5285
5354
  this._fileInput.value = '';
5286
5355
  }
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];
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.enabled) {
5384
+ if (this.maxfiles > 0 && this._filePointers.size >= this.maxfiles) {
5385
+ this.showError(`A quantidade máxima de arquivos é ${this.maxfiles}.`);
5386
+ }
5387
+ else {
5388
+ this._fileInput.click();
5389
+ }
5295
5390
  }
5296
- }*/
5297
- decode_utf8(s) {
5298
- return decodeURIComponent(escape(s));
5299
5391
  }
5300
5392
  componentDidLoad() {
5301
- if (this.dropZone && window.FileList && window.File) {
5302
- this.dropZone.addEventListener('dragover', event => {
5393
+ if (this.enabled && this._dropZone && window.FileList && window.File) {
5394
+ this._dropZone.addEventListener('dragover', event => {
5303
5395
  event.stopPropagation();
5304
5396
  event.preventDefault();
5305
5397
  event.dataTransfer.dropEffect = 'copy';
5306
5398
  });
5307
- this.dropZone.addEventListener('drop', event => {
5399
+ this._dropZone.addEventListener('drop', event => {
5308
5400
  event.stopPropagation();
5309
5401
  event.preventDefault();
5310
- this.addFiles(event.dataTransfer.files);
5402
+ this.addFiles(Array.from(event.dataTransfer.files));
5311
5403
  });
5312
5404
  }
5313
5405
  }
5314
- removeFile(name, xhr, downloadURL) {
5315
- if (xhr) {
5316
- xhr.abort();
5406
+ componentWillRender() {
5407
+ if (this.value) {
5408
+ if (this._filePointers.size < this.value.length) {
5409
+ this.updateFilePointers();
5410
+ }
5317
5411
  }
5318
- if (downloadURL) {
5319
- this.removeFileFromServer(name, downloadURL);
5412
+ }
5413
+ /*
5414
+ background--disabled
5415
+ text--disabled
5416
+ fill--disabled
5417
+ mouse-poiter--disabled
5418
+ */
5419
+ render() {
5420
+ return (h("div", { ref: (el) => this._dropZone = el, class: this.evalDisabledClass('iu', 'background--disabled') }, this.label ? h("label", { class: this.evalDisabledClass('iu__label', 'text--disabled'), title: this.label }, this.label) : null, h("div", { class: "iu__container", onClick: () => this.openFilesDialog() }, h("div", { class: this.evalDisabledClass('iu__icon-label', 'mouse-pointer--disabled') }, h("button", { class: "iu__file-icon", disabled: !this.enabled }), h("div", { class: this.evalDisabledClass('text text--center text--medium text--primary', 'text--disabled') }, this.enabled ? 'Arraste e solte ou clique para adicionar arquivos' : 'Somente leitura')), this.buildFooter()), h("input", { ref: (el) => this._fileInput = el, onChange: (ev) => this.onFileInputChange(ev), type: "file", multiple: true, hidden: true })));
5421
+ }
5422
+ buildFooter() {
5423
+ if (this._filePointers.size === 0) {
5424
+ return null;
5320
5425
  }
5321
- this.value = [...this.value.filter(function (value) { return value.name !== name; })];
5322
- this.fileListChange();
5426
+ const items = [];
5427
+ this._filePointers.forEach(item => items.push(this.buildFileItem(item)));
5428
+ return (h("div", { class: "iu__footer" }, items));
5323
5429
  }
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);
5430
+ buildFileItem(item) {
5431
+ const fileName = item.name;
5432
+ const progress = Number(item['progress']);
5433
+ const downloadURL = item['downloadURL'];
5434
+ const label = `${fileName} (${this.formatBytes(item.size)})`;
5435
+ 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)
5436
+ ?
5437
+ null
5438
+ :
5439
+ h("div", { class: "col col--sd-4 col--stretch align--middle" }, h("progress", { id: this.buildProgressId(item), value: progress, max: "100" })), this.enabled
5440
+ ?
5441
+ h("div", { class: "col col--stretch align--middle" }, h("button", { class: "btn-cancel ", onClick: () => this.removeFile(fileName) }))
5442
+ :
5443
+ null));
5361
5444
  }
5362
- 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 })));
5445
+ evalDisabledClass(regularClasses, disabledClass) {
5446
+ return this.enabled ? regularClasses : `${regularClasses} ${disabledClass}`;
5374
5447
  }
5448
+ get _host() { return this; }
5449
+ static get watchers() { return {
5450
+ "value": ["changeValue"],
5451
+ "requestheaders": ["normalizeRequestHeaders"]
5452
+ }; }
5375
5453
  static get style() { return ezUploadCss; }
5376
5454
  };
5377
5455
 
@@ -5399,11 +5477,6 @@ let FormMetadata$1 = class extends HTMLElement {
5399
5477
  properties.push({ name: "options", value: JSON.stringify(objOpts) });
5400
5478
  }
5401
5479
  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
5480
  const urlElement = element.querySelector('URL');
5408
5481
  const headersElement = element.querySelectorAll('HEADERS>HEADER');
5409
5482
  if (urlElement) {
@@ -5416,6 +5489,7 @@ let FormMetadata$1 = class extends HTMLElement {
5416
5489
  });
5417
5490
  properties.push({ name: "HEADERS", value: JSON.stringify(headers) });
5418
5491
  }
5492
+ this.addPropertyIfExists(properties, element, "maxfiles");
5419
5493
  }
5420
5494
  else {
5421
5495
  if (!label) {
@@ -5537,7 +5611,7 @@ const EzTextArea = /*@__PURE__*/proxyCustomElement(EzTextArea$1, [1,"ez-text-are
5537
5611
  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
5612
  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
5613
  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]}]);
5614
+ 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
5615
  const FormMetadata = /*@__PURE__*/proxyCustomElement(FormMetadata$1, [1,"form-metadata",{"name":[1],"label":[1],"dataunit":[1025],"many":[4],"autoload":[4],"metadata":[1040]}]);
5542
5616
  const PlaceHolder = /*@__PURE__*/proxyCustomElement(PlaceHolder$1, [1,"place-holder"]);
5543
5617
  const defineCustomElements = (opts) => {