@shival99/z-ui-svelte 0.1.14 → 0.1.16
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/dist/components/z-gallery/ZGalleryPreview.svelte +1 -4
- package/dist/components/z-gallery/ZGalleryPreview.svelte.d.ts +0 -2
- package/dist/components/z-gallery/ZGalleryPreviewStage.svelte +12 -14
- package/dist/components/z-gallery/ZGalleryPreviewStage.svelte.d.ts +0 -2
- package/dist/components/z-gallery/ZGalleryTextPreview.svelte +120 -11
- package/dist/components/z-gallery/z-gallery.utils.d.ts +3 -0
- package/dist/components/z-gallery/z-gallery.utils.js +10 -1
- package/dist/components/z-tabs/z-tabs.util.js +3 -3
- package/package.json +10 -10
- package/dist/components/z-gallery/ZGalleryOfficeHtml.svelte +0 -44
- package/dist/components/z-gallery/ZGalleryOfficeHtml.svelte.d.ts +0 -10
|
@@ -23,8 +23,6 @@
|
|
|
23
23
|
zPdfViewerConfig?: ZGalleryPdfViewerConfig;
|
|
24
24
|
/** Extra origins (besides the page's own) PDFs may be loaded from. */
|
|
25
25
|
zTrustedResourceOrigins?: string[];
|
|
26
|
-
/** Renders a Word, Excel or PowerPoint file as HTML, shown in a sandboxed frame instead of the built-in renderers. */
|
|
27
|
-
zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
|
|
28
26
|
onClose?: () => void;
|
|
29
27
|
onDownload?: (file: ZGalleryFile) => void;
|
|
30
28
|
onNavigate?: (file: ZGalleryFile) => void;
|
|
@@ -38,7 +36,6 @@
|
|
|
38
36
|
zShowToolbar = true,
|
|
39
37
|
zPdfViewerConfig = {},
|
|
40
38
|
zTrustedResourceOrigins = [],
|
|
41
|
-
zOfficeHtml,
|
|
42
39
|
onClose,
|
|
43
40
|
onDownload,
|
|
44
41
|
onNavigate,
|
|
@@ -260,7 +257,7 @@
|
|
|
260
257
|
data-dismiss
|
|
261
258
|
>
|
|
262
259
|
{#key shown.id}
|
|
263
|
-
<ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins}
|
|
260
|
+
<ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins} />
|
|
264
261
|
{/key}
|
|
265
262
|
</div>
|
|
266
263
|
</div>
|
|
@@ -13,8 +13,6 @@ interface Props {
|
|
|
13
13
|
zPdfViewerConfig?: ZGalleryPdfViewerConfig;
|
|
14
14
|
/** Extra origins (besides the page's own) PDFs may be loaded from. */
|
|
15
15
|
zTrustedResourceOrigins?: string[];
|
|
16
|
-
/** Renders a Word, Excel or PowerPoint file as HTML, shown in a sandboxed frame instead of the built-in renderers. */
|
|
17
|
-
zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
|
|
18
16
|
onClose?: () => void;
|
|
19
17
|
onDownload?: (file: ZGalleryFile) => void;
|
|
20
18
|
onNavigate?: (file: ZGalleryFile) => void;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import ZIcon from '../z-icon/ZIcon.svelte';
|
|
5
5
|
import type { ZIcon as ZIconName } from '../z-icon/z-icon.types';
|
|
6
6
|
import ZSkeleton from '../z-skeleton/ZSkeleton.svelte';
|
|
7
|
-
import ZGalleryOfficeHtml from './ZGalleryOfficeHtml.svelte';
|
|
8
7
|
import ZGalleryOfficePreview from './ZGalleryOfficePreview.svelte';
|
|
9
8
|
import ZGalleryPdfViewer from './ZGalleryPdfViewer.svelte';
|
|
10
9
|
import ZGalleryTextPreview from './ZGalleryTextPreview.svelte';
|
|
@@ -17,6 +16,7 @@
|
|
|
17
16
|
zGalleryFileCategory,
|
|
18
17
|
zGalleryFormatSize,
|
|
19
18
|
zGalleryIsAllowedResourceUrl,
|
|
19
|
+
zGalleryIsMarkdown,
|
|
20
20
|
zGalleryOfficeKind,
|
|
21
21
|
} from './z-gallery.utils';
|
|
22
22
|
|
|
@@ -26,8 +26,6 @@
|
|
|
26
26
|
zoomed?: boolean;
|
|
27
27
|
zPdfViewerConfig?: ZGalleryPdfViewerConfig;
|
|
28
28
|
zTrustedResourceOrigins?: string[];
|
|
29
|
-
/** Renders an Office file as HTML (see ZGalleryOfficeHtml). Without it the built-in renderers are used. */
|
|
30
|
-
zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
let {
|
|
@@ -36,7 +34,6 @@
|
|
|
36
34
|
zoomed = $bindable(false),
|
|
37
35
|
zPdfViewerConfig = {},
|
|
38
36
|
zTrustedResourceOrigins = [],
|
|
39
|
-
zOfficeHtml,
|
|
40
37
|
}: Props = $props();
|
|
41
38
|
|
|
42
39
|
// The lightbox keys this component by file id, so state starts fresh for every file.
|
|
@@ -48,6 +45,15 @@
|
|
|
48
45
|
const category = $derived(zGalleryFileCategory(file));
|
|
49
46
|
const mediaUrl = $derived(file.url || file.downloadUrl || null);
|
|
50
47
|
const isTextual = $derived(category === 'text' || category === 'code');
|
|
48
|
+
const textLanguage = $derived.by(() => {
|
|
49
|
+
if (category === 'code') {
|
|
50
|
+
return zGalleryCodeLanguage(file.name);
|
|
51
|
+
}
|
|
52
|
+
if (zGalleryIsMarkdown(file)) {
|
|
53
|
+
return 'markdown';
|
|
54
|
+
}
|
|
55
|
+
return zGalleryExtension(file.name) || 'txt';
|
|
56
|
+
});
|
|
51
57
|
const officeKind = $derived(zGalleryOfficeKind(file));
|
|
52
58
|
// PDFs and Office files are loaded into an iframe / fetched, so only same-origin and trusted origins are allowed.
|
|
53
59
|
const resourceAllowed = $derived(
|
|
@@ -218,11 +224,7 @@
|
|
|
218
224
|
{#if loading}
|
|
219
225
|
{@render loadingState()}
|
|
220
226
|
{/if}
|
|
221
|
-
{
|
|
222
|
-
<ZGalleryOfficeHtml {file} {zOfficeHtml} onLoaded={done} onError={officeFailed} />
|
|
223
|
-
{:else}
|
|
224
|
-
<ZGalleryOfficePreview kind={officeKind} url={mediaUrl} name={file.name} onLoaded={done} onError={officeFailed} />
|
|
225
|
-
{/if}
|
|
227
|
+
<ZGalleryOfficePreview kind={officeKind} url={mediaUrl} name={file.name} onLoaded={done} onError={officeFailed} />
|
|
226
228
|
{/if}
|
|
227
229
|
</div>
|
|
228
230
|
{:else if isTextual}
|
|
@@ -234,11 +236,7 @@
|
|
|
234
236
|
{:else if textError}
|
|
235
237
|
{@render errorState(textError)}
|
|
236
238
|
{:else}
|
|
237
|
-
<ZGalleryTextPreview
|
|
238
|
-
class="absolute inset-0 shadow-2xl"
|
|
239
|
-
content={text}
|
|
240
|
-
language={category === 'code' ? zGalleryCodeLanguage(file.name) : zGalleryExtension(file.name) || 'txt'}
|
|
241
|
-
/>
|
|
239
|
+
<ZGalleryTextPreview class="absolute inset-0 shadow-2xl" content={text} language={textLanguage} />
|
|
242
240
|
{/if}
|
|
243
241
|
</div>
|
|
244
242
|
{:else}
|
|
@@ -5,8 +5,6 @@ interface Props {
|
|
|
5
5
|
zoomed?: boolean;
|
|
6
6
|
zPdfViewerConfig?: ZGalleryPdfViewerConfig;
|
|
7
7
|
zTrustedResourceOrigins?: string[];
|
|
8
|
-
/** Renders an Office file as HTML (see ZGalleryOfficeHtml). Without it the built-in renderers are used. */
|
|
9
|
-
zOfficeHtml?: (file: ZGalleryFile) => Promise<string>;
|
|
10
8
|
}
|
|
11
9
|
declare const ZGalleryPreviewStage: import("svelte").Component<Props, {}, "zoomed">;
|
|
12
10
|
type ZGalleryPreviewStage = ReturnType<typeof ZGalleryPreviewStage>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ClassValue } from 'clsx';
|
|
3
3
|
import { zMergeClasses } from '../../utils/merge-classes';
|
|
4
|
+
import { zGalleryMarkdownHtml } from './z-gallery.utils';
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
6
7
|
class?: ClassValue;
|
|
@@ -11,6 +12,8 @@
|
|
|
11
12
|
|
|
12
13
|
let { class: className, content, language = 'text' }: Props = $props();
|
|
13
14
|
|
|
15
|
+
const isMarkdown = $derived(language.toLowerCase() === 'markdown');
|
|
16
|
+
const markdownHtml = $derived(isMarkdown ? zGalleryMarkdownHtml(content) : '');
|
|
14
17
|
const lines = $derived(content.split(/\r?\n/));
|
|
15
18
|
</script>
|
|
16
19
|
|
|
@@ -26,15 +29,121 @@
|
|
|
26
29
|
{language}
|
|
27
30
|
</div>
|
|
28
31
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex (scrollable region must be keyboard focusable) -->
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
{#if isMarkdown}
|
|
33
|
+
<div
|
|
34
|
+
class="z-gallery-markdown min-h-0 flex-1 overflow-auto p-5 text-sm leading-6"
|
|
35
|
+
tabindex="0"
|
|
36
|
+
role="region"
|
|
37
|
+
aria-label="Markdown preview"
|
|
38
|
+
>
|
|
39
|
+
{@html markdownHtml}
|
|
40
|
+
</div>
|
|
41
|
+
{:else}
|
|
42
|
+
<div
|
|
43
|
+
class="grid min-h-0 flex-1 auto-rows-min grid-cols-[auto_1fr] gap-x-4 overflow-auto p-4 font-mono text-xs leading-5"
|
|
44
|
+
tabindex="0"
|
|
45
|
+
role="region"
|
|
46
|
+
aria-label={language}
|
|
47
|
+
>
|
|
48
|
+
{#each lines as line, index (index)}
|
|
49
|
+
<span class="text-muted-foreground text-right select-none">{index + 1}</span>
|
|
50
|
+
<span class="break-words whitespace-pre-wrap">{line}</span>
|
|
51
|
+
{/each}
|
|
52
|
+
</div>
|
|
53
|
+
{/if}
|
|
40
54
|
</div>
|
|
55
|
+
|
|
56
|
+
<style>
|
|
57
|
+
.z-gallery-markdown :global(:first-child) {
|
|
58
|
+
margin-top: 0;
|
|
59
|
+
}
|
|
60
|
+
.z-gallery-markdown :global(:last-child) {
|
|
61
|
+
margin-bottom: 0;
|
|
62
|
+
}
|
|
63
|
+
.z-gallery-markdown :global(h1),
|
|
64
|
+
.z-gallery-markdown :global(h2),
|
|
65
|
+
.z-gallery-markdown :global(h3),
|
|
66
|
+
.z-gallery-markdown :global(h4),
|
|
67
|
+
.z-gallery-markdown :global(h5),
|
|
68
|
+
.z-gallery-markdown :global(h6) {
|
|
69
|
+
margin: 1.25em 0 0.5em;
|
|
70
|
+
color: var(--foreground);
|
|
71
|
+
font-weight: 650;
|
|
72
|
+
line-height: 1.3;
|
|
73
|
+
}
|
|
74
|
+
.z-gallery-markdown :global(h1) {
|
|
75
|
+
font-size: 1.65em;
|
|
76
|
+
}
|
|
77
|
+
.z-gallery-markdown :global(h2) {
|
|
78
|
+
font-size: 1.4em;
|
|
79
|
+
}
|
|
80
|
+
.z-gallery-markdown :global(h3) {
|
|
81
|
+
font-size: 1.2em;
|
|
82
|
+
}
|
|
83
|
+
.z-gallery-markdown :global(p) {
|
|
84
|
+
margin: 0 0 0.85em;
|
|
85
|
+
}
|
|
86
|
+
.z-gallery-markdown :global(ul),
|
|
87
|
+
.z-gallery-markdown :global(ol) {
|
|
88
|
+
margin: 0 0 0.85em;
|
|
89
|
+
padding-left: 1.5em;
|
|
90
|
+
}
|
|
91
|
+
.z-gallery-markdown :global(ul) {
|
|
92
|
+
list-style: disc;
|
|
93
|
+
}
|
|
94
|
+
.z-gallery-markdown :global(ol) {
|
|
95
|
+
list-style: decimal;
|
|
96
|
+
}
|
|
97
|
+
.z-gallery-markdown :global(li + li) {
|
|
98
|
+
margin-top: 0.25em;
|
|
99
|
+
}
|
|
100
|
+
.z-gallery-markdown :global(blockquote) {
|
|
101
|
+
margin: 0 0 0.85em;
|
|
102
|
+
border-left: 3px solid var(--border);
|
|
103
|
+
padding-left: 0.9em;
|
|
104
|
+
color: var(--muted-foreground);
|
|
105
|
+
}
|
|
106
|
+
.z-gallery-markdown :global(pre) {
|
|
107
|
+
overflow: auto;
|
|
108
|
+
margin: 0 0 0.85em;
|
|
109
|
+
border: 1px solid var(--border);
|
|
110
|
+
border-radius: 0.5rem;
|
|
111
|
+
background: color-mix(in oklab, var(--muted) 45%, transparent);
|
|
112
|
+
padding: 0.8em 1em;
|
|
113
|
+
}
|
|
114
|
+
.z-gallery-markdown :global(code) {
|
|
115
|
+
border-radius: 0.25rem;
|
|
116
|
+
background: color-mix(in oklab, var(--muted) 55%, transparent);
|
|
117
|
+
padding: 0.1em 0.3em;
|
|
118
|
+
font-family: var(--font-mono);
|
|
119
|
+
font-size: 0.9em;
|
|
120
|
+
}
|
|
121
|
+
.z-gallery-markdown :global(pre code) {
|
|
122
|
+
background: transparent;
|
|
123
|
+
padding: 0;
|
|
124
|
+
}
|
|
125
|
+
.z-gallery-markdown :global(a) {
|
|
126
|
+
color: var(--primary);
|
|
127
|
+
text-decoration: underline;
|
|
128
|
+
text-underline-offset: 2px;
|
|
129
|
+
}
|
|
130
|
+
.z-gallery-markdown :global(hr) {
|
|
131
|
+
margin: 1.25em 0;
|
|
132
|
+
border-color: var(--border);
|
|
133
|
+
}
|
|
134
|
+
.z-gallery-markdown :global(table) {
|
|
135
|
+
width: 100%;
|
|
136
|
+
border-collapse: collapse;
|
|
137
|
+
margin-bottom: 0.85em;
|
|
138
|
+
}
|
|
139
|
+
.z-gallery-markdown :global(th),
|
|
140
|
+
.z-gallery-markdown :global(td) {
|
|
141
|
+
border: 1px solid var(--border);
|
|
142
|
+
padding: 0.4em 0.65em;
|
|
143
|
+
text-align: left;
|
|
144
|
+
}
|
|
145
|
+
.z-gallery-markdown :global(th) {
|
|
146
|
+
background: color-mix(in oklab, var(--muted) 45%, transparent);
|
|
147
|
+
font-weight: 600;
|
|
148
|
+
}
|
|
149
|
+
</style>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ZFileCategory, ZFileCategoryStyle, ZGalleryFile, ZGalleryOfficeKind } from './z-gallery.types';
|
|
2
2
|
/** Lower-case extension without the dot, or `''` when the name has none. */
|
|
3
3
|
export declare function zGalleryExtension(name: string): string;
|
|
4
|
+
export declare function zGalleryIsMarkdown(file: Pick<ZGalleryFile, 'name' | 'type'>): boolean;
|
|
5
|
+
/** Render Markdown files for the read-only Gallery preview and sanitize any embedded HTML. */
|
|
6
|
+
export declare function zGalleryMarkdownHtml(content: string): string;
|
|
4
7
|
export declare function zGalleryFileCategory(file: Pick<ZGalleryFile, 'name' | 'type'>): ZFileCategory;
|
|
5
8
|
export declare function zGalleryCategoryStyle(file: Pick<ZGalleryFile, 'name' | 'type'>): ZFileCategoryStyle;
|
|
6
9
|
export declare function zGalleryFormatSize(bytes: number): string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { marked } from 'marked';
|
|
1
2
|
import { Z_GALLERY_FILE_CATEGORY_STYLES } from './z-gallery.define';
|
|
3
|
+
import { zSafeHtml } from '../../utils/z-safe-html';
|
|
2
4
|
const IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'bmp', 'ico', 'avif'];
|
|
3
5
|
const VIDEO_EXTENSIONS = ['mp4', 'avi', 'mov', 'wmv', 'flv', 'webm', 'mkv'];
|
|
4
6
|
const AUDIO_EXTENSIONS = ['mp3', 'wav', 'ogg', 'flac', 'aac', 'm4a'];
|
|
@@ -28,7 +30,7 @@ const CODE_EXTENSIONS = [
|
|
|
28
30
|
'sh',
|
|
29
31
|
'svelte',
|
|
30
32
|
];
|
|
31
|
-
const TEXT_EXTENSIONS = ['txt', 'md', 'log'];
|
|
33
|
+
const TEXT_EXTENSIONS = ['txt', 'md', 'markdown', 'mdx', 'log'];
|
|
32
34
|
const WORD_EXTENSIONS = ['doc', 'docx', 'odt', 'rtf'];
|
|
33
35
|
const EXCEL_EXTENSIONS = ['xls', 'xlsx', 'csv', 'ods'];
|
|
34
36
|
const POWERPOINT_EXTENSIONS = ['ppt', 'pptx', 'odp'];
|
|
@@ -51,6 +53,13 @@ export function zGalleryExtension(name) {
|
|
|
51
53
|
const index = name.lastIndexOf('.');
|
|
52
54
|
return index < 0 ? '' : name.slice(index + 1).toLowerCase();
|
|
53
55
|
}
|
|
56
|
+
export function zGalleryIsMarkdown(file) {
|
|
57
|
+
return (file.type?.toLowerCase() === 'text/markdown' || ['md', 'markdown', 'mdx'].includes(zGalleryExtension(file.name)));
|
|
58
|
+
}
|
|
59
|
+
/** Render Markdown files for the read-only Gallery preview and sanitize any embedded HTML. */
|
|
60
|
+
export function zGalleryMarkdownHtml(content) {
|
|
61
|
+
return zSafeHtml(marked.parse(content, { async: false, gfm: true }));
|
|
62
|
+
}
|
|
54
63
|
export function zGalleryFileCategory(file) {
|
|
55
64
|
const type = file.type?.toLowerCase() || '';
|
|
56
65
|
const ext = zGalleryExtension(file.name?.toLowerCase() || '');
|
|
@@ -42,9 +42,9 @@ export function zTabsMeasure(button) {
|
|
|
42
42
|
if (!container) {
|
|
43
43
|
return { x: button.offsetLeft, y: button.offsetTop, w: button.offsetWidth, h: button.offsetHeight };
|
|
44
44
|
}
|
|
45
|
-
// Screen rects follow transforms: a strip inside a panel that is still scaling in measured smaller, and the
|
|
46
|
-
// stayed off until a later resize. Dividing by the container's own scale (its drawn width over its layout
|
|
47
|
-
// the layout geometry back, with the fractional part kept.
|
|
45
|
+
// Screen rects follow transforms: a strip inside a panel that is still scaling in measured smaller, and the
|
|
46
|
+
// indicator stayed off until a later resize. Dividing by the container's own scale (its drawn width over its layout
|
|
47
|
+
// width) gives the layout geometry back, with the fractional part kept.
|
|
48
48
|
const buttonRect = button.getBoundingClientRect();
|
|
49
49
|
const containerRect = container.getBoundingClientRect();
|
|
50
50
|
const scaleX = container.offsetWidth ? containerRect.width / container.offsetWidth : 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shival99/z-ui-svelte",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "Z-UI component library for Svelte 5 (runes, no CDK).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -55,14 +55,6 @@
|
|
|
55
55
|
"vite": "7.3.1",
|
|
56
56
|
"vitest": "4.1.10"
|
|
57
57
|
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"package": "svelte-package && node scripts/bundle-core-styles.mjs",
|
|
60
|
-
"prepublishOnly": "pnpm package",
|
|
61
|
-
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
62
|
-
"test": "vitest run",
|
|
63
|
-
"generate:animated-icons": "node scripts/generate-animated-icons.mjs",
|
|
64
|
-
"lint": "eslint src"
|
|
65
|
-
},
|
|
66
58
|
"dependencies": {
|
|
67
59
|
"@dayflow/blossom-color-picker-svelte": "1.3.0",
|
|
68
60
|
"@floating-ui/dom": "1.8.0",
|
|
@@ -91,6 +83,7 @@
|
|
|
91
83
|
"exceljs": "^4.4.0",
|
|
92
84
|
"file-saver": "^2.0.5",
|
|
93
85
|
"isomorphic-dompurify": "^2.36.0",
|
|
86
|
+
"marked": "17.0.6",
|
|
94
87
|
"overlayscrollbars": "2.16.0",
|
|
95
88
|
"qrcode": "^1.5.4",
|
|
96
89
|
"shiki": "^4.4.3",
|
|
@@ -118,5 +111,12 @@
|
|
|
118
111
|
"@aiden0z/pptx-renderer": {
|
|
119
112
|
"optional": true
|
|
120
113
|
}
|
|
114
|
+
},
|
|
115
|
+
"scripts": {
|
|
116
|
+
"package": "svelte-package && node scripts/bundle-core-styles.mjs",
|
|
117
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
118
|
+
"test": "vitest run",
|
|
119
|
+
"generate:animated-icons": "node scripts/generate-animated-icons.mjs",
|
|
120
|
+
"lint": "eslint src"
|
|
121
121
|
}
|
|
122
|
-
}
|
|
122
|
+
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { zTranslate } from '../../i18n/translate.svelte';
|
|
3
|
-
import type { ZGalleryFile } from './z-gallery.types';
|
|
4
|
-
|
|
5
|
-
// A Word, Excel or PowerPoint file shown as the HTML the app renders for it (`zOfficeHtml`). The HTML runs in a sandboxed
|
|
6
|
-
// frame without the page's origin: its own scripts (sheet tabs, slide arrows) work, and it cannot reach the app.
|
|
7
|
-
interface Props {
|
|
8
|
-
file: ZGalleryFile;
|
|
9
|
-
zOfficeHtml: (file: ZGalleryFile) => Promise<string>;
|
|
10
|
-
onLoaded?: () => void;
|
|
11
|
-
onError?: (message: string) => void;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let { file, zOfficeHtml, onLoaded, onError }: Props = $props();
|
|
15
|
-
|
|
16
|
-
let srcdoc = $state<string | null>(null);
|
|
17
|
-
|
|
18
|
-
$effect(() => {
|
|
19
|
-
const target = file;
|
|
20
|
-
let stale = false;
|
|
21
|
-
srcdoc = null;
|
|
22
|
-
zOfficeHtml(target)
|
|
23
|
-
.then((html) => {
|
|
24
|
-
if (stale) return;
|
|
25
|
-
srcdoc = html;
|
|
26
|
-
})
|
|
27
|
-
.catch((error: unknown) => {
|
|
28
|
-
if (!stale) onError?.(error instanceof Error ? error.message : zTranslate('i18n_z_ui_gallery_preview_load_error'));
|
|
29
|
-
});
|
|
30
|
-
return () => {
|
|
31
|
-
stale = true;
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
</script>
|
|
35
|
-
|
|
36
|
-
{#if srcdoc !== null}
|
|
37
|
-
<iframe
|
|
38
|
-
title={file.name}
|
|
39
|
-
class="bg-card size-full border-0 transition-opacity duration-300 motion-reduce:transition-none"
|
|
40
|
-
sandbox="allow-scripts"
|
|
41
|
-
srcdoc={srcdoc}
|
|
42
|
-
onload={() => onLoaded?.()}
|
|
43
|
-
></iframe>
|
|
44
|
-
{/if}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ZGalleryFile } from './z-gallery.types';
|
|
2
|
-
interface Props {
|
|
3
|
-
file: ZGalleryFile;
|
|
4
|
-
zOfficeHtml: (file: ZGalleryFile) => Promise<string>;
|
|
5
|
-
onLoaded?: () => void;
|
|
6
|
-
onError?: (message: string) => void;
|
|
7
|
-
}
|
|
8
|
-
declare const ZGalleryOfficeHtml: import("svelte").Component<Props, {}, "">;
|
|
9
|
-
type ZGalleryOfficeHtml = ReturnType<typeof ZGalleryOfficeHtml>;
|
|
10
|
-
export default ZGalleryOfficeHtml;
|