feat: migration to Svelte 5
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy';
|
||||
|
||||
import { createEventDispatcher, onMount, tick } from 'svelte';
|
||||
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
@@ -7,52 +9,50 @@
|
||||
import { check_hosted_file_obj_w_hash } from '$lib/ae_core/core__check_hosted_file_obj_w_hash';
|
||||
import { ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/stores/ae_stores';
|
||||
|
||||
export let element_id = 'svelte_input_file_element';
|
||||
export let input_name = 'file_list';
|
||||
export let container_class_li: string[] = [];
|
||||
export let input_class_li: string[] = ['file_drop_area'];
|
||||
export let table_class_li: string[] = ['table', 'table-sm', 'table-striped', '', 'text-sm'];
|
||||
|
||||
export let multiple: boolean = true;
|
||||
export let required: boolean = true;
|
||||
export let accept: string =
|
||||
'audio/*, image/*, video/*, .bak, .cfg, .css, .csv, .doc, .docx, .gz, .htm, .html, .ini, .iso, .j2, .json, .key, .keynote, .md, .pdf, .ppt, .pptx, .rar, .rtf, .sql, .svelte, ttf, .txt, .xls, .xlsx, .xz, .zip, .bin, .dmg, .exe, .js, .msi, .php, .py, .sh';
|
||||
export let untrusted_extension_list = ['bin', 'dmg', 'exe', 'js', 'msi', 'php', 'py', 'sh'];
|
||||
export let legacy_extension_list = ['avi', 'doc', 'ppt', 'xls', 'wmv'];
|
||||
export let use_selected_file_table = true;
|
||||
|
||||
export let file_list_status: null | string = null;
|
||||
export let processed_file_list: any[] = [];
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let input_file_list: any = null;
|
||||
let input_file_list_processed: any[] = [];
|
||||
interface Props {
|
||||
element_id?: string;
|
||||
input_name?: string;
|
||||
container_class_li?: string[];
|
||||
input_class_li?: string[];
|
||||
table_class_li?: string[];
|
||||
multiple?: boolean;
|
||||
required?: boolean;
|
||||
accept?: string;
|
||||
untrusted_extension_list?: any;
|
||||
legacy_extension_list?: any;
|
||||
use_selected_file_table?: boolean;
|
||||
file_list_status?: null | string;
|
||||
processed_file_list?: any[];
|
||||
input_file_list?: any;
|
||||
}
|
||||
|
||||
let {
|
||||
element_id = 'svelte_input_file_element',
|
||||
input_name = 'file_list',
|
||||
container_class_li = [],
|
||||
input_class_li = ['file_drop_area'],
|
||||
table_class_li = ['table', 'table-sm', 'table-striped', '', 'text-sm'],
|
||||
multiple = true,
|
||||
required = true,
|
||||
accept = 'audio/*, image/*, video/*, .bak, .cfg, .css, .csv, .doc, .docx, .gz, .htm, .html, .ini, .iso, .j2, .json, .key, .keynote, .md, .pdf, .ppt, .pptx, .rar, .rtf, .sql, .svelte, ttf, .txt, .xls, .xlsx, .xz, .zip, .bin, .dmg, .exe, .js, .msi, .php, .py, .sh',
|
||||
untrusted_extension_list = ['bin', 'dmg', 'exe', 'js', 'msi', 'php', 'py', 'sh'],
|
||||
legacy_extension_list = ['avi', 'doc', 'ppt', 'xls', 'wmv'],
|
||||
use_selected_file_table = true,
|
||||
file_list_status = $bindable(null),
|
||||
processed_file_list = $bindable([]),
|
||||
input_file_list = $bindable(null)
|
||||
}: Props = $props();
|
||||
let input_file_list_processed: any[] = $state([]);
|
||||
|
||||
onMount(() => {
|
||||
console.log('** Element Mounted: ** Element Input File');
|
||||
});
|
||||
|
||||
$: if (input_file_list) {
|
||||
console.log(input_file_list);
|
||||
|
||||
process_file_list(input_file_list).then(function (result) {
|
||||
// console.log(result);
|
||||
|
||||
if (!result || !result.length) {
|
||||
file_list_status = 'none';
|
||||
}
|
||||
|
||||
// Save the results to the file upload list to be displayed as a table.
|
||||
input_file_list_processed = result; // Includes file hash
|
||||
|
||||
dispatch('input_file_list_updated', {
|
||||
element_id: element_id,
|
||||
input_file_list: input_file_list,
|
||||
input_file_list_processed: result // Includes file hash
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function process_file_list(file_list) {
|
||||
console.log('*** process_file_list() ***');
|
||||
@@ -309,6 +309,28 @@
|
||||
|
||||
return true;
|
||||
}
|
||||
run(() => {
|
||||
if (input_file_list) {
|
||||
console.log(input_file_list);
|
||||
|
||||
process_file_list(input_file_list).then(function (result) {
|
||||
// console.log(result);
|
||||
|
||||
if (!result || !result.length) {
|
||||
file_list_status = 'none';
|
||||
}
|
||||
|
||||
// Save the results to the file upload list to be displayed as a table.
|
||||
input_file_list_processed = result; // Includes file hash
|
||||
|
||||
dispatch('input_file_list_updated', {
|
||||
element_id: element_id,
|
||||
input_file_list: input_file_list,
|
||||
input_file_list_processed: result // Includes file hash
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -370,9 +392,9 @@
|
||||
<tr>
|
||||
<td class="file_remove">
|
||||
<button
|
||||
on:click|preventDefault={() => {
|
||||
onclick={preventDefault(() => {
|
||||
remove_file_from_filelist(file_index);
|
||||
}}
|
||||
})}
|
||||
class="btn btn-md preset-tonal-warning hover:preset-filled-secondary-500 m-1"
|
||||
title="Remove file from upload list"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user