UNPKG

scriptable-testlab

Version:

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

149 lines 4.71 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; 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 __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var calendar_exports = {}; __export(calendar_exports, { MockCalendar: () => MockCalendar }); module.exports = __toCommonJS(calendar_exports); var import_scriptable_abstract = require("scriptable-abstract"); var import_color = require("../ui/color"); const DEFAULT_STATE = { identifier: "", title: "", allowsContentModifications: true, isSubscribed: false, color: new import_color.MockColor("#000000") }; const _MockCalendar = class _MockCalendar extends import_scriptable_abstract.AbsCalendar { static get instance() { if (!this._instance) { this._instance = new _MockCalendar(); } return this._instance; } constructor() { super(DEFAULT_STATE); } // Static methods static async forReminders() { return this._calendars.filter((cal) => !cal.isSubscribed); } static async forEvents() { return this._calendars.filter((cal) => !cal.isSubscribed); } static async forRemindersByTitle(title) { const calendar = this._calendars.find((cal) => cal.title === title && !cal.isSubscribed); if (!calendar) { throw new Error(`No calendar found with title: ${title}`); } return calendar; } static async forEventsByTitle(title) { const calendar = this._calendars.find((cal) => cal.title === title && !cal.isSubscribed); if (!calendar) { throw new Error(`No calendar found with title: ${title}`); } return calendar; } static async createForReminders(title) { const calendar = new _MockCalendar(); calendar.title = title; calendar.save(); return calendar; } static async findOrCreateForReminders(title) { try { return await this.forRemindersByTitle(title); } catch { return this.createForReminders(title); } } static async defaultForReminders() { const calendars = await this.forReminders(); if (calendars.length === 0) { return this.createForReminders("Default Reminders"); } return calendars[0]; } static async defaultForEvents() { const calendars = await this.forEvents(); if (calendars.length === 0) { const calendar = new _MockCalendar(); calendar.title = "Default Events"; calendar.save(); return calendar; } return calendars[0]; } static async presentPicker(allowMultiple = false) { return allowMultiple ? this._calendars : [this._calendars[0]]; } // Instance methods get identifier() { return this.state.identifier; } get title() { return this.state.title; } set title(value) { this.setState({ title: value }); } get allowsContentModifications() { return this.state.allowsContentModifications; } set allowsContentModifications(value) { this.setState({ allowsContentModifications: value }); } get isSubscribed() { return this.state.isSubscribed; } get color() { return this.state.color; } set color(value) { this.setState({ color: value }); } supportsAvailability(_availability) { return true; } save() { if (!_MockCalendar._calendars.includes(this)) { _MockCalendar._calendars.push(this); } } remove() { const index = _MockCalendar._calendars.indexOf(this); if (index > -1) { _MockCalendar._calendars.splice(index, 1); } } // Helper method to clear all calendars (for testing) static clearAll() { this._calendars = []; } }; __publicField(_MockCalendar, "_instance", null); __publicField(_MockCalendar, "_calendars", []); let MockCalendar = _MockCalendar; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockCalendar }); //# sourceMappingURL=calendar.js.map