${previousCount
? html`
${repeat(
range(1, previousCount),
(i) => i,
(i) => html`
`,
)}
`
: nothing}
${repeat(
files,
(file) => file.id,
(file) => {
const fileSize = !file.provider || file.size > 0 ? fileSizeAsString(file.size) : nothing;
const fileChangedAt = file.updated_at || file.created_at;
const fileDate = new Intl.DateTimeFormat(this.weavy?.locale, {
dateStyle: "full",
timeStyle: "short",
}).format(new Date(fileChangedAt));
const isRenaming = Boolean(
this.componentFeatures?.allowsFeature(Feature.FileRename) &&
this.isRenamingId &&
this.isRenamingId === file.id,
);
const isSelected = this.selectedId === file.id;
const { icon } = getIcon(file.name);
const ext = getExtension(file.name);
const provider = getProvider(file.provider);
const handleRename = (e: Event) => {
e.stopImmediatePropagation();
const renameTarget = e.target as HTMLInputElement;
if (
this.componentFeatures?.allowsFeature(Feature.FileRename) &&
renameTarget.value &&
renameTarget.value !== file.name
) {
this.dispatchAction({ action: ActionType.Rename, file: { ...file, name: renameTarget.value } });
} else {
this.dispatchAction({ action: ActionType.EditName, file: null });
}
};
const handleRenameKey = (e: KeyboardEvent & Event) => {
const target = e.target as HTMLInputElement;
if (e.key === "Escape") {
e.preventDefault();
target.value = file.name;
target.blur();
} else if (e.key === "Enter") {
e.preventDefault();
target.blur();
}
};
const highlight = Boolean(this.highlightId && this.highlightId === file.id);
return html`
{
if (file.is_trashed) {
return;
}
if (isModifiedClick(e)) {
if (!e.defaultPrevented && this.dispatchAction({ action: ActionType.Open, file })) {
e.stopPropagation();
e.preventDefault();
openUrl(file.download_url ?? file.external_url, "_blank");
}
} else {
!e.defaultPrevented && this.dispatchAction({ action: ActionType.Select, file });
}
}}
@keydown=${clickOnEnterAndConsumeOnSpace}
@keyup=${clickOnSpace}
${highlight ? ref(autoScrollRef({ block: "center", behavior: "instant" })) : nothing}
>
this.dispatchAction({ action: ActionType.Edit, file: e.detail.file })}
@edit-name=${(e: FileEditNameEventType) =>
this.dispatchAction({
action: ActionType.EditName,
file: e.detail.editName ? e.detail.file : null,
})}
@trash=${(e: FileTrashEventType) =>
this.dispatchAction({ action: ActionType.Trash, file: e.detail.file })}
@restore=${(e: FileRestoreEventType) =>
this.dispatchAction({ action: ActionType.Restore, file: e.detail.file })}
@delete-forever=${(e: FileDeleteForeverEventType) =>
this.dispatchAction({ action: ActionType.DeleteForever, file: e.detail.file })}
@subscribe=${(e: FileSubscribeEventType) =>
this.dispatchAction({
action: e.detail.subscribe ? ActionType.Subscribe : ActionType.Unsubscribe,
file: e.detail.file,
})}
>
${!file.is_trashed && file.thumbnail_url
? html`

`
: html`
`}
${isRenaming
? html`
{
inputConsume(e);
handleRenameKey(e);
}}
@click=${(e: Event) => e.preventDefault()}
@focus=${handleSelectFilename}
${ref(autoFocusRef())}
/>
`
: html`
${file.name}
${this.componentFeatures?.allowsFeature(
Feature.Comments,
) && file.comments?.count
? html`
{
if (!e.defaultPrevented && !file.is_trashed) {
(e.target as HTMLElement).blur();
this.dispatchAction({ action: ActionType.Comment, file });
e.stopPropagation();
}
}}
title=${msg(str`${file.comments.count} comments`)}
>
${file.comments.count}
`
: nothing}
`}
`;
},
)}
`;
}
return nothing;
}
}