UNPKG

scriptable-testlab

Version:

A lightweight, efficient tool designed to manage and update scripts for Scriptable.

55 lines (47 loc) 1.25 kB
import {AbsQuickLook} from 'scriptable-abstract'; import {MockData} from '../data'; import {MockImage} from '../media/image'; interface QuickLookState { lastPreviewedItem: string | Image | Data | null; } /** * Mock implementation of Scriptable's QuickLook global variable * Provides functionality for previewing various types of content * * @implements QuickLook */ export class MockQuickLook extends AbsQuickLook<QuickLookState> { static get instance(): MockQuickLook { return super.instance as MockQuickLook; } constructor() { super({ lastPreviewedItem: null, }); } /** * @inheritdoc */ async present(item: string | Image | Data): Promise<void> { // Validate input if (item instanceof MockImage || item instanceof MockData || typeof item === 'string') { this.setState({lastPreviewedItem: item}); } else { throw new Error('Invalid item type for QuickLook preview'); } } /** * @additional * Get the last previewed item */ getLastPreviewedItem(): string | Image | Data | null { return this.state.lastPreviewedItem; } /** * @additional * Clear the preview history */ clear(): void { this.setState({lastPreviewedItem: null}); } }