This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-17 01:13:22 +09:00
1 parent de68d0ce47
commit b4cc5b0afe
9 files changed
+108 -171

No files matched your search

@@ -1,7 +1,6 @@
<script lang="ts">
import { getContext, onDestroy, onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import DOMPurify from 'dompurify';
import { isCodeFile } from '$lib/utils/codeHighlight';
import {
FileContentError,
@@ -39,9 +38,7 @@
let controller: AbortController;
let indexedController: AbortController;
let objectUrl = '';
let workbook: any = null;
let selectedExcelSheet = '';
let excelSheetNames: string[] = [];
let indexedEditor: FileCodeEditor;
let mounted = false;
$: name = fileName(file);
@@ -89,14 +86,6 @@
if (!signal.aborted) indexedLoading = false;
}
};
const selectSheet = async (sheet: string) => {
const key = request;
const { excelToTable } = await import('$lib/utils/excelToTable');
const result = await excelToTable(workbook.Sheets[sheet]);
if (key !== request) return;
selectedExcelSheet = sheet;
previewData = { fileOfficeHtml: DOMPurify.sanitize(result.html, { ADD_ATTR: ['target'] }) };
};
const loadOriginal = async () => {
controller?.abort();
controller = new AbortController();
@@ -137,11 +126,10 @@
const { readExcelWorkbook } = await import('$lib/utils/excelToTable');
const bytes = await blob.arrayBuffer();
if (signal.aborted || key !== request) return;
workbook = await readExcelWorkbook(bytes);
excelSheetNames = workbook.SheetNames;
if (!excelSheetNames.length) throw new Error('This workbook has no sheets.');
await selectSheet(excelSheetNames[0]);
data = previewData;
const workbook = await readExcelWorkbook(bytes);
if (!workbook.SheetNames.length) throw new Error('This workbook has no sheets.');
selectedExcelSheet = workbook.SheetNames[0];
data = { excelWorkbook: workbook };
} else if (ext === 'pptx' || mime.includes('presentationml')) {
const { pptxToImages } = await import('$lib/utils/pptxToHtml');
const result = await pptxToImages(await blob.arrayBuffer());
@@ -300,9 +288,7 @@
readOnly
allowScripts={false}
bind:showRaw
{excelSheetNames}
{selectedExcelSheet}
onSheetChange={selectSheet}
bind:selectedExcelSheet
/>{/if}
{:else if indexedLoading}<div class="p-4"><Spinner className="size-4" /></div>
{:else if indexedError}<div class="p-4 text-xs">