Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,12 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
* @type {Array<string>}
* @default
*/
@property({
type: Array,
attribute: 'allowed-file-extensions',
converter(value) {
if (typeof value === 'string') {
return value.split(',').map((ext) => ext.trim());
}
return value;
},
})
@property({ type: Array, attribute: 'allowed-file-extensions' })
allowedFileExtensions?: Array<string>;

@state()
public temporaryFile?: UmbTemporaryFileModel;

@state()
private _extensions?: string[];

@state()
private _previewAlias?: string;

Expand Down Expand Up @@ -87,7 +75,14 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
}

async #setPreviewAlias(): Promise<void> {
this._previewAlias = await this.#getPreviewElementAlias();
// Store current src to detect changes during async operation
const currentSrc = this.#src;
const alias = await this.#getPreviewElementAlias();

// Only update if src hasn't changed in the meantime (prevents race conditions)
if (this.#src === currentSrc) {
this._previewAlias = alias;
}
}

async #getPreviewElementAlias() {
Expand All @@ -107,9 +102,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
if (!mimeType) return fallbackAlias;

// Check for an exact match
const exactMatch = manifests.find((manifest) => {
return stringOrStringArrayContains(manifest.forMimeTypes, mimeType);
});
const exactMatch = manifests.find((manifest) => stringOrStringArrayContains(manifest.forMimeTypes, mimeType));
if (exactMatch) return exactMatch.alias;

// Check for wildcard match (e.g. image/*)
Expand Down Expand Up @@ -151,6 +144,11 @@ export class UmbInputUploadFieldElement extends UmbLitElement {

this.temporaryFile = (file as UmbUploadableFile).temporaryFile;

if (!this.temporaryFile?.file) {
console.error('No file available for upload');
return;
}

this.#clearObjectUrl();

const blobUrl = URL.createObjectURL(this.temporaryFile.file);
Expand All @@ -176,7 +174,7 @@ export class UmbInputUploadFieldElement extends UmbLitElement {
<umb-input-dropzone
standalone
disable-folder-upload
accept=${ifDefined(this._extensions?.join(','))}
accept=${ifDefined(this.allowedFileExtensions ? this.allowedFileExtensions.join(',') : undefined)}
@change=${this.#onUpload}></umb-input-dropzone>
`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const manifest: ManifestPropertyEditorSchema = {
{
alias: 'fileExtensions',
label: 'Accepted file extensions',
description:
'Insert one extension per line, for example `.jpg`.\n\nYou can also use mime types, for example `image/*` or `application/pdf`.',
propertyEditorUiAlias: 'Umb.PropertyEditorUi.AcceptedUploadTypes',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class UmbPropertyEditorUIUploadFieldElement extends UmbLitElement impleme
public set config(config: UmbPropertyEditorConfigCollection | undefined) {
if (!config) return;
this._fileExtensions = config.getValueByAlias<Array<string>>('fileExtensions');
if (this._fileExtensions?.length) {
this._fileExtensions = this._fileExtensions.map((ext) =>
ext.startsWith('.') ? ext : ext.includes('/') ? ext : `.${ext}`,
);
}
}

#onChange(event: CustomEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class UmbUfmRenderElement extends UmbLitElement {
overflow: auto;
}

code {
font-family: var(--uui-font-monospace);
white-space: pre-wrap;
background-color: var(--uui-color-background);
border-radius: var(--uui-border-radius);
padding: 0.2em 0.4em;
}

:host > :first-child {
margin-block-start: 0;
}
Expand Down
Loading