UNPKG

scriptable-testlab

Version:

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

198 lines 5.28 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var ui_table_row_exports = {}; __export(ui_table_row_exports, { MockUITableRow: () => MockUITableRow }); module.exports = __toCommonJS(ui_table_row_exports); var import_scriptable_abstract = require("scriptable-abstract"); var import_ui_table_cell = require("./ui-table-cell"); class MockUITableRow extends import_scriptable_abstract.AbsUITableRow { constructor() { super({ isHeader: false, height: 44, // iOS 默认行高 backgroundColor: null, cellSpacing: 10, // iOS 默认间距 cells: [], dismissOnSelect: true, onSelect: null }); } /** * Whether the row is a header row */ get isHeader() { return this.state.isHeader; } /** * Sets whether the row is a header row */ set isHeader(value) { if (typeof value !== "boolean") { throw new Error("IsHeader must be a boolean"); } this.setState({ isHeader: value }); } /** * Height of the row */ get height() { return this.state.height; } /** * Sets the height of the row */ set height(value) { if (typeof value !== "number" || value <= 0) { throw new Error("Height must be a positive number"); } this.setState({ height: value }); } /** * Background color of the row */ get backgroundColor() { return this.state.backgroundColor; } /** * Sets the background color of the row */ set backgroundColor(value) { this.setState({ backgroundColor: value }); } /** * Spacing between cells */ get cellSpacing() { return this.state.cellSpacing; } /** * Sets the spacing between cells */ set cellSpacing(value) { if (typeof value !== "number" || value < 0) { throw new Error("Cell spacing must be a non-negative number"); } this.setState({ cellSpacing: value }); } /** * Whether to dismiss the table when the row is selected */ get dismissOnSelect() { return this.state.dismissOnSelect; } /** * Sets whether to dismiss the table when the row is selected */ set dismissOnSelect(value) { if (typeof value !== "boolean") { throw new Error("DismissOnSelect must be a boolean"); } this.setState({ dismissOnSelect: value }); } /** * Function to call when the row is selected */ get onSelect() { return this.state.onSelect; } /** * Sets the function to call when the row is selected */ set onSelect(value) { if (value !== null && typeof value !== "function") { throw new Error("OnSelect must be a function or null"); } this.setState({ onSelect: value }); } /** * Cells in the row */ get cells() { return this.state.cells; } /** * Adds a cell to the row * @param cell Cell to add to the row */ addCell(cell) { if (!(cell instanceof import_ui_table_cell.MockUITableCell)) { throw new Error("Cell must be an instance of UITableCell"); } const cells = [...this.state.cells, cell]; this.setState({ cells }); } /** * Adds a text cell to the row * @param title Optional title to show in the cell * @param subtitle Optional subtitle shown below the title in the cell * @returns The created cell */ addText(title, subtitle) { const cell = import_ui_table_cell.MockUITableCell.text(title, subtitle); this.addCell(cell); return cell; } /** * Adds an image cell to the row * @param image Image to show in the cell * @returns The created cell */ addImage(image) { if (!image) { throw new Error("Image cannot be null"); } const cell = import_ui_table_cell.MockUITableCell.image(image); this.addCell(cell); return cell; } /** * Adds an image cell that loads from URL * @param url URL to image * @returns The created cell */ addImageAtURL(url) { if (!url) { throw new Error("URL cannot be empty"); } const cell = import_ui_table_cell.MockUITableCell.imageAtURL(url); this.addCell(cell); return cell; } /** * Adds a button cell to the row * @param title Title of the button * @returns The created cell */ addButton(title) { if (!title) { throw new Error("Button title cannot be empty"); } const cell = import_ui_table_cell.MockUITableCell.button(title); this.addCell(cell); return cell; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockUITableRow }); //# sourceMappingURL=ui-table-row.js.map