Extensions Authoring Guide
This guide explains how to create custom extensions for VistaView. Extensions allow you to add additional functionality to the lightbox without modifying the core library.
What Are Extensions?
Section titled “What Are Extensions?”Extensions are modular plugins that hook into VistaView’s lifecycle to add features like:
- UI Controls - Custom buttons and interface elements
- Behaviors - Logging, analytics, keyboard shortcuts
- Content Types - Videos, maps, custom media
- Enhanced Features - Image stories, annotations, sharing
Extension Interface
Section titled “Extension Interface”All extensions must implement the VistaExtension interface:
interface VistaExtension { name: string; description?: string; control?: () => HTMLElement | null; onInitializeImage?: (par: VistaImageParams) => VistaBox | void | null | undefined; onImageView?: (data: VistaData, vistaView: VistaView) => void; onContentChange?: (content: VistaImageClone, vistaView: VistaView) => void; onDeactivateUi?: (names: string[], vistaView: VistaView) => void; onReactivateUi?: (names: string[], vistaView: VistaView) => void; onOpen?: (vistaView: VistaView) => void; onClose?: (vistaView: VistaView) => void;}Properties
Section titled “Properties”name(required): Unique identifier for your extensiondescription(optional): Human-readable descriptioncontrol(optional): Returns an HTML element to be added to the UIonInitializeImage(optional): Called when each image is initialized. Can return a customVistaBoxonImageView(optional): Called when navigating to an imageonContentChange(optional): Called when image content changesonDeactivateUi(optional): Called when UI should be disabledonReactivateUi(optional): Called when UI should be enabledonOpen(optional): Called when lightbox opensonClose(optional): Called when lightbox closes
Extension Types
Section titled “Extension Types”1. UI Extensions
Section titled “1. UI Extensions”Add visible controls to the lightbox interface.
Examples: Download button, share button, fullscreen toggle
2. Behavior Extensions
Section titled “2. Behavior Extensions”Add functionality without visible UI.
Examples: Logging, analytics, keyboard shortcuts
3. Content Extensions
Section titled “3. Content Extensions”Support custom content types by providing custom VistaBox implementations.
Examples: YouTube videos, maps, 360° images
4. Complex Extensions
Section titled “4. Complex Extensions”Combine UI, state management, and async operations.
Examples: Image stories, annotations, slideshows
Quick Start
Section titled “Quick Start”The simplest extension:
import type { VistaExtension } from 'vistaview';
export function myExtension(): VistaExtension { return { name: 'myExtension', onOpen: (vistaView) => { console.log('Lightbox opened!'); }, };}Usage:
import { vistaView } from 'vistaview';import { myExtension } from './my-extension';
vistaView({ elements: '#gallery a', extensions: [myExtension()],});Lifecycle Event Order
Section titled “Lifecycle Event Order”Understanding when hooks are called:
On Open
Section titled “On Open”initFunctionExtension.onOpenonOpencallbacksetupFunctionExtension.onImageViewonImageViewcallback
On Navigate
Section titled “On Navigate”setupFunctionExtension.onImageViewonImageViewcallback
On Close
Section titled “On Close”closeFunctionExtension.onCloseonClosecallback
Next Steps
Section titled “Next Steps”- UI Extensions - Add custom controls
- Behavior Extensions - Add functionality without UI
- Content Extensions - Support custom content types
- Best Practices - Memory management, accessibility, TypeScript
- Publishing - Share your extension