@tooark/web-components 1.4.0 → 1.6.0
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.
- package/README.md +3 -3
- package/README.pt-BR.md +3 -3
- package/dist/index.cjs +198 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +198 -21
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -913,7 +913,10 @@ declare class ArkEmpty extends HTMLElementBase {
|
|
|
913
913
|
* seletor nativo e soltar arquivos na zona alimenta o mesmo input. Toda
|
|
914
914
|
* mudança emite `change` com os arquivos e anuncia os nomes ao leitor de
|
|
915
915
|
* tela. O rótulo aponta para o input (associação nativa) e nomeia o botão
|
|
916
|
-
* junto do próprio texto dele.
|
|
916
|
+
* junto do próprio texto dele. Com `directory` o campo escolhe uma pasta: o
|
|
917
|
+
* seletor abre em modo pasta, uma pasta solta é lida até o fim, a lista vira
|
|
918
|
+
* um resumo e `change` leva também o caminho de cada arquivo. Sem ele, uma
|
|
919
|
+
* pasta solta é recusada com aviso.
|
|
917
920
|
*/
|
|
918
921
|
declare class ArkFileInput extends HTMLElementBase {
|
|
919
922
|
static readonly tagName = "ark-file-input";
|
|
@@ -926,6 +929,12 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
926
929
|
private messageEl;
|
|
927
930
|
/** Profundidade de dragenter/dragleave, porque eles disparam também nos filhos da zona. */
|
|
928
931
|
private dragDepth;
|
|
932
|
+
/** O último drop trouxe uma pasta que o campo não aceita: a lista mostra o aviso até a próxima seleção. */
|
|
933
|
+
private folderRejected;
|
|
934
|
+
/** Caminho de cada arquivo vindo de um drop em modo pasta, na ordem de `files`; nulo quando veio do seletor. */
|
|
935
|
+
private droppedPaths;
|
|
936
|
+
/** Conta as seleções: a leitura assíncrona de uma pasta solta só é publicada se nada veio depois dela. */
|
|
937
|
+
private selectionSeq;
|
|
929
938
|
static get observedAttributes(): string[];
|
|
930
939
|
connectedCallback(): void;
|
|
931
940
|
attributeChangedCallback(): void;
|
|
@@ -933,6 +942,14 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
933
942
|
get inputElement(): HTMLInputElement | null;
|
|
934
943
|
/** Arquivos escolhidos. */
|
|
935
944
|
get files(): File[];
|
|
945
|
+
/**
|
|
946
|
+
* Caminho de cada arquivo de `files`, na mesma ordem, a partir da pasta escolhida ou solta (`pasta/sub/a.txt`);
|
|
947
|
+
* o nome do arquivo quando ele não veio de uma pasta.
|
|
948
|
+
*/
|
|
949
|
+
get paths(): string[];
|
|
950
|
+
/** Escolhe uma pasta inteira: o seletor abre em modo pasta e a zona lê as pastas soltas. Padrão: desligado. */
|
|
951
|
+
get directory(): boolean;
|
|
952
|
+
set directory(value: boolean | string | null | undefined);
|
|
936
953
|
get multiple(): boolean;
|
|
937
954
|
set multiple(value: boolean | string | null | undefined);
|
|
938
955
|
get disabled(): boolean;
|
|
@@ -943,6 +960,12 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
943
960
|
private getLocale;
|
|
944
961
|
private isDisabled;
|
|
945
962
|
private readonly handleChange;
|
|
963
|
+
private resetSelection;
|
|
964
|
+
private publish;
|
|
965
|
+
private summarize;
|
|
966
|
+
private static readDrop;
|
|
967
|
+
private static readFolder;
|
|
968
|
+
private selectDropped;
|
|
946
969
|
private readonly handleDragEnter;
|
|
947
970
|
private readonly handleDragOver;
|
|
948
971
|
private readonly handleDragLeave;
|
package/dist/index.d.ts
CHANGED
|
@@ -913,7 +913,10 @@ declare class ArkEmpty extends HTMLElementBase {
|
|
|
913
913
|
* seletor nativo e soltar arquivos na zona alimenta o mesmo input. Toda
|
|
914
914
|
* mudança emite `change` com os arquivos e anuncia os nomes ao leitor de
|
|
915
915
|
* tela. O rótulo aponta para o input (associação nativa) e nomeia o botão
|
|
916
|
-
* junto do próprio texto dele.
|
|
916
|
+
* junto do próprio texto dele. Com `directory` o campo escolhe uma pasta: o
|
|
917
|
+
* seletor abre em modo pasta, uma pasta solta é lida até o fim, a lista vira
|
|
918
|
+
* um resumo e `change` leva também o caminho de cada arquivo. Sem ele, uma
|
|
919
|
+
* pasta solta é recusada com aviso.
|
|
917
920
|
*/
|
|
918
921
|
declare class ArkFileInput extends HTMLElementBase {
|
|
919
922
|
static readonly tagName = "ark-file-input";
|
|
@@ -926,6 +929,12 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
926
929
|
private messageEl;
|
|
927
930
|
/** Profundidade de dragenter/dragleave, porque eles disparam também nos filhos da zona. */
|
|
928
931
|
private dragDepth;
|
|
932
|
+
/** O último drop trouxe uma pasta que o campo não aceita: a lista mostra o aviso até a próxima seleção. */
|
|
933
|
+
private folderRejected;
|
|
934
|
+
/** Caminho de cada arquivo vindo de um drop em modo pasta, na ordem de `files`; nulo quando veio do seletor. */
|
|
935
|
+
private droppedPaths;
|
|
936
|
+
/** Conta as seleções: a leitura assíncrona de uma pasta solta só é publicada se nada veio depois dela. */
|
|
937
|
+
private selectionSeq;
|
|
929
938
|
static get observedAttributes(): string[];
|
|
930
939
|
connectedCallback(): void;
|
|
931
940
|
attributeChangedCallback(): void;
|
|
@@ -933,6 +942,14 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
933
942
|
get inputElement(): HTMLInputElement | null;
|
|
934
943
|
/** Arquivos escolhidos. */
|
|
935
944
|
get files(): File[];
|
|
945
|
+
/**
|
|
946
|
+
* Caminho de cada arquivo de `files`, na mesma ordem, a partir da pasta escolhida ou solta (`pasta/sub/a.txt`);
|
|
947
|
+
* o nome do arquivo quando ele não veio de uma pasta.
|
|
948
|
+
*/
|
|
949
|
+
get paths(): string[];
|
|
950
|
+
/** Escolhe uma pasta inteira: o seletor abre em modo pasta e a zona lê as pastas soltas. Padrão: desligado. */
|
|
951
|
+
get directory(): boolean;
|
|
952
|
+
set directory(value: boolean | string | null | undefined);
|
|
936
953
|
get multiple(): boolean;
|
|
937
954
|
set multiple(value: boolean | string | null | undefined);
|
|
938
955
|
get disabled(): boolean;
|
|
@@ -943,6 +960,12 @@ declare class ArkFileInput extends HTMLElementBase {
|
|
|
943
960
|
private getLocale;
|
|
944
961
|
private isDisabled;
|
|
945
962
|
private readonly handleChange;
|
|
963
|
+
private resetSelection;
|
|
964
|
+
private publish;
|
|
965
|
+
private summarize;
|
|
966
|
+
private static readDrop;
|
|
967
|
+
private static readFolder;
|
|
968
|
+
private selectDropped;
|
|
946
969
|
private readonly handleDragEnter;
|
|
947
970
|
private readonly handleDragOver;
|
|
948
971
|
private readonly handleDragLeave;
|
package/dist/index.js
CHANGED
|
@@ -2752,7 +2752,8 @@ class ArkCheckbox extends HTMLElementBase {
|
|
|
2752
2752
|
input.tabIndex = -1;
|
|
2753
2753
|
input.setAttribute("aria-hidden", "true");
|
|
2754
2754
|
input.setAttribute("data-ark-chrome", "input");
|
|
2755
|
-
// No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta.
|
|
2755
|
+
// No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta. A caixa vem antes
|
|
2756
|
+
// do input porque um <label> do app em volta do host rotula o primeiro controle rotulável dentro dele.
|
|
2756
2757
|
this.prepend(box, input);
|
|
2757
2758
|
this.boxEl = box;
|
|
2758
2759
|
this.iconEl = icon;
|
|
@@ -5791,7 +5792,10 @@ const UPLOAD_SVG = `
|
|
|
5791
5792
|
* seletor nativo e soltar arquivos na zona alimenta o mesmo input. Toda
|
|
5792
5793
|
* mudança emite `change` com os arquivos e anuncia os nomes ao leitor de
|
|
5793
5794
|
* tela. O rótulo aponta para o input (associação nativa) e nomeia o botão
|
|
5794
|
-
* junto do próprio texto dele.
|
|
5795
|
+
* junto do próprio texto dele. Com `directory` o campo escolhe uma pasta: o
|
|
5796
|
+
* seletor abre em modo pasta, uma pasta solta é lida até o fim, a lista vira
|
|
5797
|
+
* um resumo e `change` leva também o caminho de cada arquivo. Sem ele, uma
|
|
5798
|
+
* pasta solta é recusada com aviso.
|
|
5795
5799
|
*/
|
|
5796
5800
|
class ArkFileInput extends HTMLElementBase {
|
|
5797
5801
|
constructor() {
|
|
@@ -5805,14 +5809,18 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
5805
5809
|
this.messageEl = null;
|
|
5806
5810
|
/** Profundidade de dragenter/dragleave, porque eles disparam também nos filhos da zona. */
|
|
5807
5811
|
this.dragDepth = 0;
|
|
5812
|
+
/** O último drop trouxe uma pasta que o campo não aceita: a lista mostra o aviso até a próxima seleção. */
|
|
5813
|
+
this.folderRejected = false;
|
|
5814
|
+
/** Caminho de cada arquivo vindo de um drop em modo pasta, na ordem de `files`; nulo quando veio do seletor. */
|
|
5815
|
+
this.droppedPaths = null;
|
|
5816
|
+
/** Conta as seleções: a leitura assíncrona de uma pasta solta só é publicada se nada veio depois dela. */
|
|
5817
|
+
this.selectionSeq = 0;
|
|
5808
5818
|
// --- Interação ---
|
|
5809
5819
|
// O change nativo do input oculto não sobe ao host: quem escuta no host recebe só o CustomEvent com detail.
|
|
5810
5820
|
this.handleChange = (event) => {
|
|
5811
|
-
event
|
|
5812
|
-
this.
|
|
5813
|
-
|
|
5814
|
-
announce(files.length ? files.map((file) => file.name).join(", ") : this.getLocale().noFile);
|
|
5815
|
-
this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
|
|
5821
|
+
event.stopPropagation();
|
|
5822
|
+
this.resetSelection();
|
|
5823
|
+
this.publish();
|
|
5816
5824
|
};
|
|
5817
5825
|
this.handleDragEnter = (event) => {
|
|
5818
5826
|
if (this.isDisabled())
|
|
@@ -5835,28 +5843,46 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
5835
5843
|
if (this.dragDepth === 0)
|
|
5836
5844
|
this.setDragover(false);
|
|
5837
5845
|
};
|
|
5838
|
-
// Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`.
|
|
5846
|
+
// Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`. Uma pasta não é um
|
|
5847
|
+
// arquivo (o navegador a entrega como um File vazio, que não dá para ler): sem `directory` fica de fora, com aviso
|
|
5848
|
+
// na lista e anúncio; com ele é lida até o fim.
|
|
5839
5849
|
this.handleDrop = (event) => {
|
|
5840
5850
|
if (this.isDisabled())
|
|
5841
5851
|
return;
|
|
5842
5852
|
event.preventDefault();
|
|
5843
5853
|
this.dragDepth = 0;
|
|
5844
5854
|
this.setDragover(false);
|
|
5845
|
-
|
|
5846
|
-
|
|
5855
|
+
if (!event.dataTransfer || !this.inputEl)
|
|
5856
|
+
return;
|
|
5857
|
+
const { files, folders } = ArkFileInput.readDrop(event.dataTransfer);
|
|
5858
|
+
if (files.length === 0 && folders.length === 0)
|
|
5859
|
+
return;
|
|
5860
|
+
if (this.directory) {
|
|
5861
|
+
void this.selectDropped(files, folders);
|
|
5847
5862
|
return;
|
|
5863
|
+
}
|
|
5864
|
+
if (files.length === 0) {
|
|
5865
|
+
// Só pastas: a seleção fica como estava e não há `change`.
|
|
5866
|
+
this.folderRejected = true;
|
|
5867
|
+
this.syncList();
|
|
5868
|
+
announce(this.getLocale().foldersNotAccepted);
|
|
5869
|
+
return;
|
|
5870
|
+
}
|
|
5871
|
+
this.resetSelection();
|
|
5872
|
+
this.folderRejected = folders.length > 0;
|
|
5848
5873
|
const transfer = new DataTransfer();
|
|
5849
|
-
const count = this.multiple ?
|
|
5874
|
+
const count = this.multiple ? files.length : 1;
|
|
5850
5875
|
for (let index = 0; index < count; index += 1)
|
|
5851
|
-
transfer.items.add(
|
|
5876
|
+
transfer.items.add(files[index]);
|
|
5852
5877
|
this.inputEl.files = transfer.files;
|
|
5853
|
-
this.
|
|
5878
|
+
this.publish();
|
|
5854
5879
|
};
|
|
5855
5880
|
}
|
|
5856
5881
|
static get observedAttributes() {
|
|
5857
5882
|
return [
|
|
5858
5883
|
"accept",
|
|
5859
5884
|
"multiple",
|
|
5885
|
+
"directory",
|
|
5860
5886
|
"label",
|
|
5861
5887
|
"helper",
|
|
5862
5888
|
"error",
|
|
@@ -5892,6 +5918,21 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
5892
5918
|
get files() {
|
|
5893
5919
|
return Array.from(this.inputEl?.files ?? []);
|
|
5894
5920
|
}
|
|
5921
|
+
/**
|
|
5922
|
+
* Caminho de cada arquivo de `files`, na mesma ordem, a partir da pasta escolhida ou solta (`pasta/sub/a.txt`);
|
|
5923
|
+
* o nome do arquivo quando ele não veio de uma pasta.
|
|
5924
|
+
*/
|
|
5925
|
+
get paths() {
|
|
5926
|
+
const dropped = this.droppedPaths;
|
|
5927
|
+
return this.files.map((file, index) => dropped?.[index] ?? (file.webkitRelativePath || file.name));
|
|
5928
|
+
}
|
|
5929
|
+
/** Escolhe uma pasta inteira: o seletor abre em modo pasta e a zona lê as pastas soltas. Padrão: desligado. */
|
|
5930
|
+
get directory() {
|
|
5931
|
+
return this.hasAttribute("directory");
|
|
5932
|
+
}
|
|
5933
|
+
set directory(value) {
|
|
5934
|
+
this.toggleAttribute("directory", coerceBooleanAttr(value));
|
|
5935
|
+
}
|
|
5895
5936
|
get multiple() {
|
|
5896
5937
|
return this.hasAttribute("multiple");
|
|
5897
5938
|
}
|
|
@@ -5909,6 +5950,7 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
5909
5950
|
if (!this.inputEl)
|
|
5910
5951
|
return;
|
|
5911
5952
|
this.inputEl.value = "";
|
|
5953
|
+
this.resetSelection();
|
|
5912
5954
|
this.syncList();
|
|
5913
5955
|
}
|
|
5914
5956
|
focus(options) {
|
|
@@ -5921,6 +5963,106 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
5921
5963
|
isDisabled() {
|
|
5922
5964
|
return this.buttonEl ? this.buttonEl.matches(":disabled") : this.disabled;
|
|
5923
5965
|
}
|
|
5966
|
+
// Uma seleção nova (seletor, drop ou clear) descarta o aviso, os caminhos do drop anterior e a leitura em curso.
|
|
5967
|
+
resetSelection() {
|
|
5968
|
+
this.folderRejected = false;
|
|
5969
|
+
this.droppedPaths = null;
|
|
5970
|
+
this.selectionSeq += 1;
|
|
5971
|
+
}
|
|
5972
|
+
// Lista, anúncio e `change` da seleção atual do input. Em modo pasta o anúncio é o resumo e `detail` leva os
|
|
5973
|
+
// caminhos; fora dele o detail é só `{ files }`, como sempre foi.
|
|
5974
|
+
publish() {
|
|
5975
|
+
this.syncList();
|
|
5976
|
+
const files = this.files;
|
|
5977
|
+
const locale = this.getLocale();
|
|
5978
|
+
if (this.directory) {
|
|
5979
|
+
const summary = this.summarize(locale);
|
|
5980
|
+
announce(files.length ? [summary.folder, summary.count].filter(Boolean).join(", ") : locale.noFolder);
|
|
5981
|
+
const detail = { files, paths: this.paths };
|
|
5982
|
+
this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
|
|
5983
|
+
return;
|
|
5984
|
+
}
|
|
5985
|
+
const selection = files.length ? files.map((file) => file.name).join(", ") : locale.noFile;
|
|
5986
|
+
announce(this.folderRejected ? `${selection}. ${locale.foldersNotAccepted}` : selection);
|
|
5987
|
+
this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
|
|
5988
|
+
}
|
|
5989
|
+
// Resumo da seleção em modo pasta: o nome da pasta, quando todos os caminhos saem da mesma, a contagem e o tamanho.
|
|
5990
|
+
summarize(locale) {
|
|
5991
|
+
const files = this.files;
|
|
5992
|
+
const roots = new Set(this.paths.map((path) => (path.includes("/") ? path.slice(0, path.indexOf("/")) : "")));
|
|
5993
|
+
const [root = ""] = roots;
|
|
5994
|
+
return {
|
|
5995
|
+
folder: roots.size === 1 ? root : "",
|
|
5996
|
+
count: locale.fileCount.replace("{count}", String(files.length)),
|
|
5997
|
+
size: files.reduce((total, file) => total + file.size, 0)
|
|
5998
|
+
};
|
|
5999
|
+
}
|
|
6000
|
+
// Separa arquivos e pastas de um drop. A pasta só se distingue pela entrada (webkitGetAsEntry), que existe só
|
|
6001
|
+
// durante o evento; sem a API, ou num DataTransfer montado por código, tudo é arquivo.
|
|
6002
|
+
static readDrop(transfer) {
|
|
6003
|
+
const files = [];
|
|
6004
|
+
const folders = [];
|
|
6005
|
+
const items = Array.from(transfer.items ?? []);
|
|
6006
|
+
if (items.length === 0)
|
|
6007
|
+
return { files: Array.from(transfer.files ?? []), folders };
|
|
6008
|
+
for (const item of items) {
|
|
6009
|
+
if (item.kind !== "file")
|
|
6010
|
+
continue;
|
|
6011
|
+
const entry = typeof item.webkitGetAsEntry === "function" ? item.webkitGetAsEntry() : null;
|
|
6012
|
+
if (entry?.isDirectory) {
|
|
6013
|
+
folders.push(entry);
|
|
6014
|
+
continue;
|
|
6015
|
+
}
|
|
6016
|
+
const file = item.getAsFile();
|
|
6017
|
+
if (file)
|
|
6018
|
+
files.push(file);
|
|
6019
|
+
}
|
|
6020
|
+
return { files, folders };
|
|
6021
|
+
}
|
|
6022
|
+
// Lê uma pasta solta até o fim, descendo nas subpastas. readEntries devolve lotes (100 no Chromium), então é
|
|
6023
|
+
// chamado até vir vazio; uma entrada que falha ao ler fica de fora sem derrubar o resto.
|
|
6024
|
+
static async readFolder(folder, prefix, found) {
|
|
6025
|
+
const reader = folder.createReader();
|
|
6026
|
+
for (;;) {
|
|
6027
|
+
const batch = await new Promise((resolve) => {
|
|
6028
|
+
reader.readEntries(resolve, () => resolve([]));
|
|
6029
|
+
});
|
|
6030
|
+
if (batch.length === 0)
|
|
6031
|
+
return;
|
|
6032
|
+
for (const entry of batch) {
|
|
6033
|
+
const path = `${prefix}${entry.name}`;
|
|
6034
|
+
if (entry.isDirectory) {
|
|
6035
|
+
await ArkFileInput.readFolder(entry, `${path}/`, found);
|
|
6036
|
+
}
|
|
6037
|
+
else if (entry.isFile) {
|
|
6038
|
+
const file = await new Promise((resolve) => {
|
|
6039
|
+
entry.file(resolve, () => resolve(null));
|
|
6040
|
+
});
|
|
6041
|
+
if (file)
|
|
6042
|
+
found.push({ file, path });
|
|
6043
|
+
}
|
|
6044
|
+
}
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
6047
|
+
// Drop em modo pasta: as pastas são lidas até o fim e tudo vai para o input, cada arquivo de pasta com o caminho a
|
|
6048
|
+
// partir do nome dela (como o webkitRelativePath do seletor) e os arquivos soltos junto com o próprio nome.
|
|
6049
|
+
async selectDropped(files, folders) {
|
|
6050
|
+
this.resetSelection();
|
|
6051
|
+
const seq = this.selectionSeq;
|
|
6052
|
+
const found = files.map((file) => ({ file, path: file.name }));
|
|
6053
|
+
for (const folder of folders)
|
|
6054
|
+
await ArkFileInput.readFolder(folder, `${folder.name}/`, found);
|
|
6055
|
+
// Outra seleção chegou enquanto a pasta era lida: esta não vale mais.
|
|
6056
|
+
if (seq !== this.selectionSeq || !this.inputEl)
|
|
6057
|
+
return;
|
|
6058
|
+
found.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
6059
|
+
const transfer = new DataTransfer();
|
|
6060
|
+
for (const entry of found)
|
|
6061
|
+
transfer.items.add(entry.file);
|
|
6062
|
+
this.inputEl.files = transfer.files;
|
|
6063
|
+
this.droppedPaths = found.map((entry) => entry.path);
|
|
6064
|
+
this.publish();
|
|
6065
|
+
}
|
|
5924
6066
|
setDragover(active) {
|
|
5925
6067
|
if (this.hasAttribute("data-ark-dragover") === active)
|
|
5926
6068
|
return;
|
|
@@ -6051,21 +6193,43 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
6051
6193
|
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
6052
6194
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
6053
6195
|
}
|
|
6054
|
-
// Lista dos nomes (com o tamanho) ou a string noFile.
|
|
6196
|
+
// Lista dos nomes (com o tamanho) ou a string noFile; por último, o aviso da pasta recusada. Em modo pasta a
|
|
6197
|
+
// seleção pode ter centenas de arquivos, então a lista é uma linha só: a pasta, a contagem e o tamanho total.
|
|
6055
6198
|
syncList() {
|
|
6056
6199
|
if (!this.listEl)
|
|
6057
6200
|
return;
|
|
6058
6201
|
const files = this.files;
|
|
6202
|
+
const locale = this.getLocale();
|
|
6203
|
+
const directory = this.directory;
|
|
6059
6204
|
const text = this.getSizing().text;
|
|
6060
6205
|
this.listEl.textContent = "";
|
|
6206
|
+
// max-w-full: centrada na zona, a lista teria a largura do nome mais longo e o truncate dos itens nunca cortaria.
|
|
6061
6207
|
this.listEl.className = [
|
|
6062
|
-
"ark:m-0 ark:flex ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
|
|
6208
|
+
"ark:m-0 ark:flex ark:max-w-full ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
|
|
6063
6209
|
text
|
|
6064
6210
|
].join(" ");
|
|
6065
6211
|
if (files.length === 0) {
|
|
6066
6212
|
const item = document.createElement("li");
|
|
6067
6213
|
item.className = "ark:text-fg-muted";
|
|
6068
|
-
item.textContent =
|
|
6214
|
+
item.textContent = directory ? locale.noFolder : locale.noFile;
|
|
6215
|
+
this.listEl.appendChild(item);
|
|
6216
|
+
}
|
|
6217
|
+
else if (directory) {
|
|
6218
|
+
const summary = this.summarize(locale);
|
|
6219
|
+
const item = document.createElement("li");
|
|
6220
|
+
item.setAttribute("data-ark-chrome", "summary");
|
|
6221
|
+
item.className = "ark:inline-flex ark:max-w-full ark:items-baseline ark:gap-1.5 ark:text-fg";
|
|
6222
|
+
if (summary.folder) {
|
|
6223
|
+
const name = document.createElement("span");
|
|
6224
|
+
name.className = "ark:truncate";
|
|
6225
|
+
name.textContent = summary.folder;
|
|
6226
|
+
item.appendChild(name);
|
|
6227
|
+
}
|
|
6228
|
+
const total = document.createElement("span");
|
|
6229
|
+
total.className = summary.folder ? "ark:shrink-0 ark:text-xs ark:text-fg-muted" : "ark:shrink-0";
|
|
6230
|
+
total.textContent = `${summary.count} · ${ArkFileInput.formatSize(summary.size)}`;
|
|
6231
|
+
item.appendChild(total);
|
|
6232
|
+
applyTestHooks(this, "file-input", item, "summary");
|
|
6069
6233
|
this.listEl.appendChild(item);
|
|
6070
6234
|
return;
|
|
6071
6235
|
}
|
|
@@ -6083,6 +6247,13 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
6083
6247
|
applyTestHooks(this, "file-input", item, "item");
|
|
6084
6248
|
this.listEl.appendChild(item);
|
|
6085
6249
|
}
|
|
6250
|
+
if (this.folderRejected) {
|
|
6251
|
+
const item = document.createElement("li");
|
|
6252
|
+
item.className = "ark:text-danger-soft-fg";
|
|
6253
|
+
item.textContent = locale.foldersNotAccepted;
|
|
6254
|
+
applyTestHooks(this, "file-input", item, "rejected");
|
|
6255
|
+
this.listEl.appendChild(item);
|
|
6256
|
+
}
|
|
6086
6257
|
}
|
|
6087
6258
|
updateAppearance() {
|
|
6088
6259
|
if (!this.inputEl ||
|
|
@@ -6099,10 +6270,14 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
6099
6270
|
const palette = this.getPalette(intent);
|
|
6100
6271
|
const sizing = this.getSizing();
|
|
6101
6272
|
const disabled = this.disabled;
|
|
6273
|
+
const directory = this.directory;
|
|
6102
6274
|
const error = this.hasAttribute("error") || this.hasAttribute("error-message");
|
|
6103
6275
|
const dragover = this.hasAttribute("data-ark-dragover");
|
|
6104
6276
|
this.inputEl.name = this.getAttribute("name") || "";
|
|
6105
|
-
|
|
6277
|
+
// Com `directory` o seletor abre em modo pasta. Onde o navegador não tem esse modo (mobile mais antigo) o atributo
|
|
6278
|
+
// não faz nada e sobra o seletor de arquivos: `multiple` deixa escolher os arquivos da pasta de uma vez.
|
|
6279
|
+
this.inputEl.multiple = this.multiple || directory;
|
|
6280
|
+
this.inputEl.toggleAttribute("webkitdirectory", directory);
|
|
6106
6281
|
this.inputEl.required = this.hasAttribute("required");
|
|
6107
6282
|
this.inputEl.disabled = disabled;
|
|
6108
6283
|
const accept = this.getAttribute("accept");
|
|
@@ -6142,13 +6317,14 @@ class ArkFileInput extends HTMLElementBase {
|
|
|
6142
6317
|
palette.ring
|
|
6143
6318
|
].join(" ");
|
|
6144
6319
|
this.buttonEl.disabled = disabled;
|
|
6145
|
-
|
|
6320
|
+
const choose = directory ? locale.chooseFolder : locale.chooseFile;
|
|
6321
|
+
if (this.buttonEl.getAttribute("data-ark-label") !== choose) {
|
|
6146
6322
|
this.buttonEl.innerHTML = `${UPLOAD_SVG}<span></span>`;
|
|
6147
|
-
this.buttonEl.lastElementChild.textContent =
|
|
6148
|
-
this.buttonEl.setAttribute("data-ark-label",
|
|
6323
|
+
this.buttonEl.lastElementChild.textContent = choose;
|
|
6324
|
+
this.buttonEl.setAttribute("data-ark-label", choose);
|
|
6149
6325
|
}
|
|
6150
6326
|
this.hintEl.className = ["ark:text-fg-muted", sizing.text].join(" ");
|
|
6151
|
-
this.hintEl.textContent = locale.dropHint;
|
|
6327
|
+
this.hintEl.textContent = directory ? locale.dropFolderHint : locale.dropHint;
|
|
6152
6328
|
this.syncList();
|
|
6153
6329
|
// Label: associação nativa com o input; o botão é nomeado pelo rótulo mais o próprio texto.
|
|
6154
6330
|
const labelText = this.getAttribute("label") || "";
|
|
@@ -8608,6 +8784,7 @@ class ArkRadio extends HTMLElementBase {
|
|
|
8608
8784
|
input.tabIndex = -1;
|
|
8609
8785
|
input.setAttribute("aria-hidden", "true");
|
|
8610
8786
|
input.setAttribute("data-ark-chrome", "input");
|
|
8787
|
+
// A opção vem antes do input: um <label> do app em volta do host rotula o primeiro controle rotulável.
|
|
8611
8788
|
this.prepend(box, input);
|
|
8612
8789
|
this.boxEl = box;
|
|
8613
8790
|
this.dotEl = dot;
|