scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
92 lines • 2.42 kB
JavaScript
import { AbsUITable } from "scriptable-abstract";
import { MockUITableRow } from "./ui-table-row";
class MockUITable extends AbsUITable {
constructor() {
super({
showSeparators: true,
// Default iOS behavior: show separators
rows: [],
isPresented: false,
isFullscreen: false
});
}
/**
* Whether to show separators between rows
*/
get showSeparators() {
return this.state.showSeparators;
}
/**
* Sets whether to show separators between rows
*/
set showSeparators(value) {
if (typeof value !== "boolean") {
throw new Error("ShowSeparators must be a boolean");
}
this.setState({ showSeparators: value });
}
/**
* Adds a row to the table
* @param row Row to add to the table. If not provided, a new row will be created.
* @returns The added row
*/
addRow(row) {
const newRow = row || new MockUITableRow();
this.setState({ rows: [...this.state.rows, newRow] });
return newRow;
}
/**
* Removes a specific row from the table
* @param row Row to remove from the table
*/
removeRow(row) {
if (this.state.isPresented) {
throw new Error("Cannot remove rows while table is being presented");
}
const index = this.state.rows.indexOf(row);
if (index === -1) {
throw new Error("Row not found in table");
}
const rows = [...this.state.rows];
rows.splice(index, 1);
this.setState({ rows });
}
/**
* Removes all rows from the table
*/
removeAllRows() {
if (this.state.isPresented) {
throw new Error("Cannot remove rows while table is being presented");
}
this.setState({ rows: [] });
}
/**
* Reloads the table view
* Must be called after modifying rows while the table is being presented
*/
reload() {
this.setState({ ...this.state });
}
/**
* Presents the table modally
* @param fullscreen Whether to present in fullscreen mode. Only has effect when used within the app.
*/
async present(fullscreen = false) {
if (this.state.isPresented) {
throw new Error("Table is already being presented");
}
this.setState({
isPresented: true,
isFullscreen: fullscreen
});
await new Promise((resolve) => setTimeout(resolve, 0));
this.setState({
isPresented: false,
isFullscreen: false
});
}
}
export {
MockUITable
};
//# sourceMappingURL=ui-table.js.map