scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
115 lines • 3.5 kB
JavaScript
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_exports = {};
__export(ui_table_exports, {
MockUITable: () => MockUITable
});
module.exports = __toCommonJS(ui_table_exports);
var import_scriptable_abstract = require("scriptable-abstract");
var import_ui_table_row = require("./ui-table-row");
class MockUITable extends import_scriptable_abstract.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 import_ui_table_row.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
});
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockUITable
});
//# sourceMappingURL=ui-table.js.map