scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
144 lines • 4.99 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 date_picker_exports = {};
__export(date_picker_exports, {
MockDatePicker: () => MockDatePicker
});
module.exports = __toCommonJS(date_picker_exports);
var import_scriptable_abstract = require("scriptable-abstract");
const DEFAULT_STATE = {
minimumDate: null,
maximumDate: null,
countdownDuration: 0,
minuteInterval: 1,
initialDate: /* @__PURE__ */ new Date()
};
class MockDatePicker extends import_scriptable_abstract.AbsDatePicker {
constructor() {
super(DEFAULT_STATE);
}
validateDateRange(date) {
if (this.state.minimumDate && date.getTime() < this.state.minimumDate.getTime()) {
throw new Error("Initial date cannot be earlier than minimum date");
}
if (this.state.maximumDate && date.getTime() > this.state.maximumDate.getTime()) {
throw new Error("Initial date cannot be later than maximum date");
}
}
validateMinMaxDates(min, max) {
if (min && max && min.getTime() > max.getTime()) {
throw new Error("Minimum date cannot be later than maximum date");
}
}
get minimumDate() {
return this.state.minimumDate ? new Date(this.state.minimumDate) : null;
}
set minimumDate(value) {
if (value) {
const newMin = new Date(value);
this.validateMinMaxDates(newMin, this.state.maximumDate);
}
this.setState({ minimumDate: value ? new Date(value) : null });
}
get maximumDate() {
return this.state.maximumDate ? new Date(this.state.maximumDate) : null;
}
set maximumDate(value) {
if (value) {
const newMax = new Date(value);
this.validateMinMaxDates(this.state.minimumDate, newMax);
}
this.setState({ maximumDate: value ? new Date(value) : null });
}
get countdownDuration() {
return this.state.countdownDuration;
}
set countdownDuration(value) {
const numValue = Number(value);
if (isNaN(numValue) || numValue < 0) {
throw new Error("Countdown duration must be a non-negative number");
}
this.setState({ countdownDuration: numValue });
}
get minuteInterval() {
return this.state.minuteInterval;
}
set minuteInterval(value) {
const numValue = Number(value);
if (isNaN(numValue) || numValue <= 0) {
throw new Error("Minute interval must be a positive number");
}
if (numValue > 30) {
throw new Error("Minute interval must not exceed 30");
}
if (60 % numValue !== 0) {
throw new Error("Minute interval must be a factor of 60");
}
this.setState({ minuteInterval: numValue });
}
get initialDate() {
return new Date(this.state.initialDate);
}
set initialDate(value) {
this.setState({ initialDate: new Date(value) });
}
/**
* Presents the date picker to the user.
* @returns A promise that resolves with the selected date.
*/
async pickDate() {
this.validateDateRange(this.state.initialDate);
return new Date(this.state.initialDate);
}
/**
* Presents the time picker to the user.
* @returns A promise that resolves with the selected date.
*/
async pickTime() {
this.validateDateRange(this.state.initialDate);
const date = new Date(this.state.initialDate);
const minutes = date.getMinutes();
const intervalMinutes = Math.round(minutes / this.state.minuteInterval) * this.state.minuteInterval;
date.setMinutes(intervalMinutes);
return new Date(date);
}
/**
* Presents the countdown duration picker to the user.
* @returns A promise that resolves with the selected duration in seconds.
*/
async pickCountdownDuration() {
return this.state.countdownDuration;
}
/**
* Presents the date picker displaying date and time.
* @returns A promise that resolves with the selected date.
*/
async pickDateAndTime() {
this.validateDateRange(this.state.initialDate);
const date = new Date(this.state.initialDate);
const minutes = date.getMinutes();
const intervalMinutes = Math.round(minutes / this.state.minuteInterval) * this.state.minuteInterval;
date.setMinutes(intervalMinutes);
return new Date(date);
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MockDatePicker
});
//# sourceMappingURL=date-picker.js.map