@shival99/z-ui-svelte 0.1.12 → 0.1.14

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.
@@ -1084,10 +1084,16 @@
1084
1084
  {#snippet fades(edges: ZScrollEdges)}
1085
1085
  <!-- Soft edges while a list is scrolled: the top once it left the start, the bottom while there is more below. -->
1086
1086
  {#if !edges.atTop}
1087
- <div class="pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b from-popover to-transparent" aria-hidden="true"></div>
1087
+ <div
1088
+ class="from-popover pointer-events-none absolute inset-x-0 top-0 h-6 bg-gradient-to-b to-transparent"
1089
+ aria-hidden="true"
1090
+ ></div>
1088
1091
  {/if}
1089
1092
  {#if !edges.atTop && !edges.atEnd}
1090
- <div class="pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t from-popover to-transparent" aria-hidden="true"></div>
1093
+ <div
1094
+ class="from-popover pointer-events-none absolute inset-x-0 bottom-0 h-6 bg-gradient-to-t to-transparent"
1095
+ aria-hidden="true"
1096
+ ></div>
1091
1097
  {/if}
1092
1098
  {/snippet}
1093
1099
 
@@ -1235,77 +1241,77 @@
1235
1241
  </div>
1236
1242
  {:else if useVirtual}
1237
1243
  <div class="relative">
1238
- <div
1239
- bind:this={optionsEl}
1240
- {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1241
- {@attach zScrollEdges(edges => (listEdges = edges))}
1242
- class="z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1243
- style:height={`${heightExpand}px`}
1244
- onscroll={onOptionsScroll}
1245
- >
1246
- <div class="z-autocomplete-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1247
- {#each $virtualizer.getVirtualItems() as item (item.key)}
1248
- {@const option = filteredOptions[item.index]}
1249
- {#if option}
1250
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1251
- <div
1252
- data-glide-item
1253
- data-index={item.index}
1254
- role="option"
1255
- tabindex="-1"
1256
- aria-selected={activeIndex === item.index}
1257
- aria-disabled={option.disabled || undefined}
1258
- class={['z-autocomplete-option absolute right-0 left-0 min-w-0', optionClass(option, item.index)]}
1259
- style:display={hasTemplate ? 'block' : null}
1260
- style:height={zDynamicSize ? null : `${optionHeight}px`}
1261
- style:min-height={zDynamicSize ? `${optionHeight}px` : null}
1262
- style:overflow={hasTemplate ? 'visible' : null}
1263
- style:transform={`translateY(${item.start}px) translateZ(0)`}
1264
- onmouseenter={() => (activeIndex = item.index)}
1265
- onclick={() => selectOption(option)}
1266
- {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1267
- >
1268
- {@render optionBody(option, item.index)}
1269
- </div>
1270
- {/if}
1271
- {/each}
1244
+ <div
1245
+ bind:this={optionsEl}
1246
+ {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1247
+ {@attach zScrollEdges(edges => (listEdges = edges))}
1248
+ class="z-autocomplete-content-state z-autocomplete-options z-autocomplete-virtual-scroll relative overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1249
+ style:height={`${heightExpand}px`}
1250
+ onscroll={onOptionsScroll}
1251
+ >
1252
+ <div class="z-autocomplete-virtual-inner relative" style:height={`${$virtualizer.getTotalSize()}px`}>
1253
+ {#each $virtualizer.getVirtualItems() as item (item.key)}
1254
+ {@const option = filteredOptions[item.index]}
1255
+ {#if option}
1256
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1257
+ <div
1258
+ data-glide-item
1259
+ data-index={item.index}
1260
+ role="option"
1261
+ tabindex="-1"
1262
+ aria-selected={activeIndex === item.index}
1263
+ aria-disabled={option.disabled || undefined}
1264
+ class={['z-autocomplete-option absolute right-0 left-0 min-w-0', optionClass(option, item.index)]}
1265
+ style:display={hasTemplate ? 'block' : null}
1266
+ style:height={zDynamicSize ? null : `${optionHeight}px`}
1267
+ style:min-height={zDynamicSize ? `${optionHeight}px` : null}
1268
+ style:overflow={hasTemplate ? 'visible' : null}
1269
+ style:transform={`translateY(${item.start}px) translateZ(0)`}
1270
+ onmouseenter={() => (activeIndex = item.index)}
1271
+ onclick={() => selectOption(option)}
1272
+ {@attach zDynamicSize ? (node: HTMLDivElement) => $virtualizer.measureElement(node) : null}
1273
+ >
1274
+ {@render optionBody(option, item.index)}
1275
+ </div>
1276
+ {/if}
1277
+ {/each}
1278
+ </div>
1279
+ {#if isLoadingMore}{@render loadingMore()}{/if}
1272
1280
  </div>
1273
- {#if isLoadingMore}{@render loadingMore()}{/if}
1274
- </div>
1275
- {@render fades(listEdges)}
1281
+ {@render fades(listEdges)}
1276
1282
  </div>
1277
1283
  {:else}
1278
1284
  <div class="relative">
1279
- <div
1280
- bind:this={optionsEl}
1281
- {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1282
- {@attach zScrollEdges(edges => (listEdges = edges))}
1283
- class="z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1284
- style:min-height={`${heightExpand}px`}
1285
- style:max-height={`${heightExpand}px`}
1286
- >
1287
- {#each filteredOptions as option, index (trackKey(option, index))}
1288
- <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1289
- <div
1290
- data-glide-item
1291
- role="option"
1292
- tabindex="-1"
1293
- aria-selected={activeIndex === index}
1294
- aria-disabled={option.disabled || undefined}
1295
- class={['z-autocomplete-option relative min-w-0', optionClass(option, index)]}
1296
- style:display={hasTemplate ? 'block' : null}
1297
- style:min-height={hasTemplate ? null : `${optionHeight}px`}
1298
- style:overflow={hasTemplate ? 'visible' : null}
1299
- onmouseenter={() => (activeIndex = index)}
1300
- onclick={() => selectOption(option)}
1301
- >
1302
- {@render optionBody(option, index)}
1303
- </div>
1304
- {/each}
1305
- {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1306
- {#if isLoadingMore}{@render loadingMore()}{/if}
1307
- </div>
1308
- {@render fades(listEdges)}
1285
+ <div
1286
+ bind:this={optionsEl}
1287
+ {@attach zHoverGlide({ class: 'bg-primary/15 rounded-(--radius-sm)' })}
1288
+ {@attach zScrollEdges(edges => (listEdges = edges))}
1289
+ class="z-autocomplete-content-state z-autocomplete-options flex flex-col gap-0.75 overflow-x-hidden overflow-y-auto overscroll-y-contain p-1"
1290
+ style:min-height={`${heightExpand}px`}
1291
+ style:max-height={`${heightExpand}px`}
1292
+ >
1293
+ {#each filteredOptions as option, index (trackKey(option, index))}
1294
+ <!-- svelte-ignore a11y_click_events_have_key_events (keyboard is handled by the input) -->
1295
+ <div
1296
+ data-glide-item
1297
+ role="option"
1298
+ tabindex="-1"
1299
+ aria-selected={activeIndex === index}
1300
+ aria-disabled={option.disabled || undefined}
1301
+ class={['z-autocomplete-option relative min-w-0', optionClass(option, index)]}
1302
+ style:display={hasTemplate ? 'block' : null}
1303
+ style:min-height={hasTemplate ? null : `${optionHeight}px`}
1304
+ style:overflow={hasTemplate ? 'visible' : null}
1305
+ onmouseenter={() => (activeIndex = index)}
1306
+ onclick={() => selectOption(option)}
1307
+ >
1308
+ {@render optionBody(option, index)}
1309
+ </div>
1310
+ {/each}
1311
+ {#if canLoadMore}<div bind:this={sentinel} class="h-px w-full shrink-0"></div>{/if}
1312
+ {#if isLoadingMore}{@render loadingMore()}{/if}
1313
+ </div>
1314
+ {@render fades(listEdges)}
1309
1315
  </div>
1310
1316
  {/if}
1311
1317
  </div>
@@ -0,0 +1,44 @@
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}
@@ -0,0 +1,10 @@
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;
@@ -23,6 +23,8 @@
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>;
26
28
  onClose?: () => void;
27
29
  onDownload?: (file: ZGalleryFile) => void;
28
30
  onNavigate?: (file: ZGalleryFile) => void;
@@ -36,6 +38,7 @@
36
38
  zShowToolbar = true,
37
39
  zPdfViewerConfig = {},
38
40
  zTrustedResourceOrigins = [],
41
+ zOfficeHtml,
39
42
  onClose,
40
43
  onDownload,
41
44
  onNavigate,
@@ -257,7 +260,7 @@
257
260
  data-dismiss
258
261
  >
259
262
  {#key shown.id}
260
- <ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins} />
263
+ <ZGalleryPreviewStage file={shown} {rotation} bind:zoomed {zPdfViewerConfig} {zTrustedResourceOrigins} {zOfficeHtml} />
261
264
  {/key}
262
265
  </div>
263
266
  </div>
@@ -13,6 +13,8 @@ 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>;
16
18
  onClose?: () => void;
17
19
  onDownload?: (file: ZGalleryFile) => void;
18
20
  onNavigate?: (file: ZGalleryFile) => void;
@@ -4,6 +4,7 @@
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';
7
8
  import ZGalleryOfficePreview from './ZGalleryOfficePreview.svelte';
8
9
  import ZGalleryPdfViewer from './ZGalleryPdfViewer.svelte';
9
10
  import ZGalleryTextPreview from './ZGalleryTextPreview.svelte';
@@ -25,6 +26,8 @@
25
26
  zoomed?: boolean;
26
27
  zPdfViewerConfig?: ZGalleryPdfViewerConfig;
27
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>;
28
31
  }
29
32
 
30
33
  let {
@@ -33,6 +36,7 @@
33
36
  zoomed = $bindable(false),
34
37
  zPdfViewerConfig = {},
35
38
  zTrustedResourceOrigins = [],
39
+ zOfficeHtml,
36
40
  }: Props = $props();
37
41
 
38
42
  // The lightbox keys this component by file id, so state starts fresh for every file.
@@ -214,7 +218,11 @@
214
218
  {#if loading}
215
219
  {@render loadingState()}
216
220
  {/if}
217
- <ZGalleryOfficePreview kind={officeKind} url={mediaUrl} name={file.name} onLoaded={done} onError={officeFailed} />
221
+ {#if zOfficeHtml}
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}
218
226
  {/if}
219
227
  </div>
220
228
  {:else if isTextual}
@@ -5,6 +5,8 @@ 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>;
8
10
  }
9
11
  declare const ZGalleryPreviewStage: import("svelte").Component<Props, {}, "zoomed">;
10
12
  type ZGalleryPreviewStage = ReturnType<typeof ZGalleryPreviewStage>;