UNPKG

scriptable-testlab

Version:

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

132 lines 2.77 kB
import { AbsPasteboard } from "scriptable-abstract"; class MockPasteboard extends AbsPasteboard { /** * @inheritdoc * Inherited from ScriptableVariable, just adding type casting */ static get instance() { return super.instance; } /** * @implements Scriptable.Pasteboard.copy * Copies text to the pasteboard */ copy(text) { this.setText(text); } /** * @implements Scriptable.Pasteboard.paste * Gets text from the pasteboard */ paste() { return this.getText(); } /** * @implements Scriptable.Pasteboard.copyString * Copies string to the pasteboard */ copyString(text) { this.setText(text); } /** * @implements Scriptable.Pasteboard.pasteString * Gets string from the pasteboard */ pasteString() { return this.getText(); } /** * @implements Scriptable.Pasteboard.copyImage * Copies image to the pasteboard */ copyImage(image) { this.setItems([{ image }]); } /** * @implements Scriptable.Pasteboard.pasteImage * Gets image from the pasteboard */ pasteImage() { const images = this.getImages(); if (images.length === 0) { throw new Error("No image on pasteboard"); } return images[0]; } /** * @additional * Additional helper method for getting text */ getText() { return this.state.text; } /** * @additional * Additional helper method for setting text */ setText(text) { this.setState({ text, items: [{ text }] }); } /** * @additional * Additional helper method for getting all items */ getItems() { return [...this.state.items]; } /** * @additional * Additional helper method for setting items */ setItems(items) { this.setState({ text: items[0]?.text ?? this.state.text, items: [...items] }); } /** * @additional * Additional helper method for checking URLs */ hasURLs() { return this.state.items.some((item) => item.url !== void 0); } /** * @additional * Additional helper method for getting URLs */ getURLs() { return this.state.items.map((item) => item.url).filter((url) => url !== void 0); } /** * @additional * Additional helper method for checking images */ hasImages() { return this.state.items.some((item) => item.image !== void 0); } /** * @additional * Additional helper method for getting images */ getImages() { return this.state.items.map((item) => item.image).filter((image) => image !== void 0); } /** * @additional * Additional helper method for clearing pasteboard */ clear() { this.setState({ text: "", items: [] }); } } export { MockPasteboard }; //# sourceMappingURL=pasteboard.js.map