scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
175 lines • 4.11 kB
JavaScript
import { AbsUITableRow } from "scriptable-abstract";
import { MockUITableCell } from "./ui-table-cell";
class MockUITableRow extends 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 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 = 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 = 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 = 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 = MockUITableCell.button(title);
this.addCell(cell);
return cell;
}
}
export {
MockUITableRow
};
//# sourceMappingURL=ui-table-row.js.map