@files-preview-app/preview-file 1.3.1 → 1.3.3

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/README.md CHANGED
@@ -490,9 +490,34 @@ Use directly with any build tool (Vite, Webpack, Rollup) or via `<script type="m
490
490
  |---|---|---|---|
491
491
  | `preview()` | `container: HTMLElement`, `source: FileSource`, `options?: PreviewViewerOptions` | `Promise<PreviewInstance>` | Renders any supported file into the target DOM element. Cleans up previous renders automatically. |
492
492
  | `getInstance()` | None | `PreviewInstance \| null` | Returns the active preview instance, exposing zoom, navigation, export, and rotation methods. |
493
- | `on()` | `event: string`, `handler: (data: any) => void` | `Unsubscribe: () => void` | Subscribes to lifecycle events. Returns an unsubscribe cleanup function. |
494
- | `registerPlugin()` | `plugin: PreviewPlugin` | `this` | Registers a custom renderer plugin. |
495
- | `registerPlugins()` | `plugins: PreviewPlugin[]` | `this` | Registers multiple renderer plugins at once. |
493
+ | `openInSeparateWindow()` | None | `Window \| null` | Clones current file buffer and opens it in a full-screen isolated browser tab. |
494
+ | `setShowFileName(show)` | `show: boolean` | `void` | Dynamically toggles the file name and format badge title bar above the toolbar. |
495
+ | `setFileName(name)` | `name: string` | `void` | Dynamically updates the displayed file title in the preview panel. |
496
+ | `setToolbarConfig(config)` | `config: ToolbarConfig` | `void` | Dynamically reconfigures which toolbar buttons/actions are shown. |
497
+ | `getToolbarConfig()` | None | `ToolbarConfig` | Returns the active toolbar configuration. |
498
+ | `hideToolbarAction(id)` | `actionId: string` | `void` | Hides a specific toolbar action by ID or alias (e.g. `'zoomIn'`, `'print'`, `'download'`). |
499
+ | `showToolbarAction(id)` | `actionId: string` | `void` | Shows a previously hidden toolbar action. |
500
+ | `enableToolbarAction(id)` | `actionId: string` | `void` | Enables a disabled toolbar action button. |
501
+ | `disableToolbarAction(id)` | `actionId: string` | `void` | Disables a toolbar action button. |
502
+ | `toggleThumbnails()` | None | `void` | Toggles the page/sheet thumbnail sidebar panel. |
503
+ | `toggleFullscreen()` | None | `void` | Toggles browser fullscreen on the viewer container. |
504
+ | `fitToPage()` | None | `void` | Scales document page or table so it fits the frame width with minimal margins. |
505
+ | `zoomIn()` | None | `void` | Programmatically zooms in. |
506
+ | `zoomOut()` | None | `void` | Programmatically zooms out. |
507
+ | `setZoom(level)` | `level: number` | `void` | Programmatically sets exact zoom scale (e.g. `1.5` = 150%). |
508
+ | `getZoom()` | None | `number` | Returns current zoom level. |
509
+ | `rotateCW()` | None | `void` | Rotates document or image 90° clockwise. |
510
+ | `rotateCCW()` | None | `void` | Rotates document or image 90° counter-clockwise. |
511
+ | `goToPage(page)` | `page: number` | `void` | Navigates to a specific page or sheet (1-based index). |
512
+ | `nextPage()` | None | `void` | Navigates to next page or sheet. |
513
+ | `prevPage()` | None | `void` | Navigates to previous page or sheet. |
514
+ | `getPageCount()` | None | `number` | Returns total page/sheet count. |
515
+ | `getCurrentPage()` | None | `number` | Returns current active page number (1-based). |
516
+ | `download()` | None | `void` | Downloads current file with original name and detected MIME type. |
517
+ | `print()` | None | `void` | Triggers browser print dialog for document. |
518
+ | `on(event, handler)` | `event: string`, `handler: (data: any) => void` | `Unsubscribe: () => void` | Subscribes to lifecycle events. Returns an unsubscribe cleanup function. |
519
+ | `registerPlugin(plugin)` | `plugin: PreviewPlugin` | `this` | Registers a custom renderer plugin. |
520
+ | `registerPlugins(list)` | `plugins: PreviewPlugin[]` | `this` | Registers multiple renderer plugins at once. |
496
521
  | `destroy()` | None | `void` | Destroys the active instance, removes toolbar DOM, cancels network abort controllers, and clears listeners. |
497
522
 
498
523
  ---
@@ -522,6 +547,68 @@ Retrieved via `viewer.getInstance()` or `previewRef.current.getInstance()`.
522
547
  | **Export** | `download()` | `void` | Downloads original file with proper name & MIME | `instance.download()` |
523
548
  | **Export** | `print()` | `void` | Opens browser print dialog formatted for clean output | `instance.print()` |
524
549
  | **Lifecycle** | `destroy()` | `void` | Releases memory, cancels rendering, revokes blob URLs | `instance.destroy()` |
550
+ ---
551
+
552
+ ## 🛠️ Toolbar Configuration & Feature Toggles
553
+
554
+ All toolbar features and buttons are completely configurable through options and instance methods.
555
+ If an action is set to `false`, its button will not appear in the toolbar.
556
+
557
+ ### Via Initialization Options:
558
+ ```typescript
559
+ // Flat options:
560
+ await viewer.preview(container, file, {
561
+ zoomIn: false, // Hide zoom in button
562
+ print: false, // Hide print button
563
+ openWindow: false, // Hide "Open in Separate Full Window" button
564
+ download: true // Keep download enabled
565
+ });
566
+
567
+ // Or nested toolbar object:
568
+ await viewer.preview(container, file, {
569
+ toolbar: {
570
+ zoomIn: false,
571
+ print: false,
572
+ copy: false
573
+ }
574
+ });
575
+ ```
576
+
577
+ ### Via Runtime Instance Methods:
578
+ ```typescript
579
+ // Hide an action dynamically
580
+ viewer.hideToolbarAction('zoomIn');
581
+ viewer.hideToolbarAction('print');
582
+
583
+ // Show a hidden action
584
+ viewer.showToolbarAction('zoomIn');
585
+
586
+ // Disable/enable an action button without removing it
587
+ viewer.disableToolbarAction('fitPage');
588
+ viewer.enableToolbarAction('fitPage');
589
+
590
+ // Reconfigure the entire toolbar at runtime
591
+ viewer.setToolbarConfig({
592
+ zoomIn: false,
593
+ zoomOut: false,
594
+ download: true
595
+ });
596
+ ```
597
+
598
+ ### Available Toolbar Toggle Keys:
599
+ | Option Key | Corresponding Action | Description |
600
+ |---|---|---|
601
+ | `zoomIn` | Zoom In | Zoom in button |
602
+ | `zoomOut` | Zoom Out | Zoom out button |
603
+ | `fitPage` / `fitToPage` | Fit to Page | Scales document to fill frame width with minimal side margins |
604
+ | `rotate` / `rotateCW` | Rotate | 90° Clockwise rotation |
605
+ | `fullscreen` | Fullscreen | Fullscreen frame toggle |
606
+ | `thumbnails` | Thumbnails | Sidebar thumbnail toggle |
607
+ | `download` | Download | File download button |
608
+ | `print` | Print | Browser clean print button |
609
+ | `openWindow` / `openSeparateWindow` | Open in Separate Window | Opens preview in a standalone window |
610
+ | `copy` | Copy Text | Copy document text to clipboard |
611
+ | `pageNav` / `pagination` | Pagination | Previous, next, and jump-to-page input |
525
612
 
526
613
  ---
527
614
 
@@ -592,14 +679,23 @@ Passed to `options` prop in React/Angular/Vue or third argument to `viewer.previ
592
679
  |---|---|---|---|
593
680
  | `theme` | `'light' \| 'dark' \| 'auto'` | `'light'` | UI theme. `'auto'` adapts to system dark mode preferences. |
594
681
  | `showToolbar` | `boolean` | `true` | Set `false` to hide built-in toolbar (e.g. when using your own custom buttons). |
682
+ | `toolbar` | `boolean \| ToolbarConfig` | `true` | Fine-grained button visibility flags (`zoomIn`, `print`, `download`, `pageNav`, etc.). |
595
683
  | `toolbarPosition` | `'top' \| 'bottom'` | `'top'` | Positions toolbar at the top or bottom of the viewer container. |
684
+ | `showFileName` | `boolean` | `true` | When `true`, displays file name and format badge in title bar above toolbar. |
685
+ | `fileName` | `string` | `undefined` | Custom file title override displayed in title bar. |
686
+ | `fitMode` | `'page' \| 'width'` | `'page'` | Preferred fit calculation strategy. |
596
687
  | `showThumbnails` | `boolean` | `false` | Opens page thumbnails sidebar panel automatically on load. |
597
688
  | `className` | `string` | `''` | Custom CSS class attached to the root viewer container element. |
598
689
  | `zoom` | `number` | `1.0` | Initial zoom multiplier (`1.0` = 100%, `1.5` = 150%). |
599
690
  | `page` | `number` | `1` | Initial page, slide, or sheet number to display on load (1-based). |
600
691
  | `locale` | `string` | `'en'` | UI label language localization. |
692
+ | `metadata` | `FileMetadata` | `undefined` | Manual override object for file attributes (`name`, `extension`, `mimeType`, `size`). |
693
+ | `standaloneViewerUrl` | `string` | `undefined` | Custom URL opened when user clicks "Open in Separate Full Window". |
694
+ | `onOpenSeparateWindow` | `function` | `undefined` | Custom callback hook to handle opening preview in separate window. |
601
695
  | `pluginOptions` | `Record<string, unknown>` | `{}` | Custom options passed directly to underlying format renderer plugins. |
602
696
 
697
+ > 📖 **For exhaustive details and TypeScript interfaces, see the full [API Reference Documentation](../../docs/API_REFERENCE.md).**
698
+
603
699
  ---
604
700
 
605
701
  ## 🎨 CSS Variables (Theming & Custom Styling)