UNPKG

scriptable-testlab

Version:

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

262 lines 8.77 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 text_field_exports = {}; __export(text_field_exports, { MockTextField: () => MockTextField, TextFieldAlignment: () => TextFieldAlignment, TextFieldAutocapitalizationType: () => TextFieldAutocapitalizationType, TextFieldKeyboardType: () => TextFieldKeyboardType, TextFieldReturnKeyType: () => TextFieldReturnKeyType }); module.exports = __toCommonJS(text_field_exports); var import_scriptable_abstract = require("scriptable-abstract"); var import_color = require("./color"); var import_font = require("./font"); var TextFieldAlignment = /* @__PURE__ */ ((TextFieldAlignment2) => { TextFieldAlignment2["left"] = "left"; TextFieldAlignment2["center"] = "center"; TextFieldAlignment2["right"] = "right"; return TextFieldAlignment2; })(TextFieldAlignment || {}); var TextFieldKeyboardType = /* @__PURE__ */ ((TextFieldKeyboardType2) => { TextFieldKeyboardType2["default"] = "default"; TextFieldKeyboardType2["number"] = "number"; TextFieldKeyboardType2["decimal"] = "decimal"; TextFieldKeyboardType2["email"] = "email"; TextFieldKeyboardType2["phone"] = "phone"; TextFieldKeyboardType2["url"] = "url"; return TextFieldKeyboardType2; })(TextFieldKeyboardType || {}); var TextFieldAutocapitalizationType = /* @__PURE__ */ ((TextFieldAutocapitalizationType2) => { TextFieldAutocapitalizationType2["none"] = "none"; TextFieldAutocapitalizationType2["words"] = "words"; TextFieldAutocapitalizationType2["sentences"] = "sentences"; TextFieldAutocapitalizationType2["all"] = "all"; return TextFieldAutocapitalizationType2; })(TextFieldAutocapitalizationType || {}); var TextFieldReturnKeyType = /* @__PURE__ */ ((TextFieldReturnKeyType2) => { TextFieldReturnKeyType2["default"] = "default"; TextFieldReturnKeyType2["go"] = "go"; TextFieldReturnKeyType2["next"] = "next"; TextFieldReturnKeyType2["done"] = "done"; TextFieldReturnKeyType2["search"] = "search"; TextFieldReturnKeyType2["send"] = "send"; return TextFieldReturnKeyType2; })(TextFieldReturnKeyType || {}); const DEFAULT_STATE = { text: "", isSecure: false, placeholder: "", textColor: new import_color.MockColor("#000000"), font: import_font.MockFont.systemFont(12), _keyboardType: "default" /* default */, _textAlignment: "left" /* left */, _autocapitalizationType: "none" /* none */, _returnKeyType: "default" /* default */, _keyboardAppearance: "light", _spellCheckingType: "default", _autocorrectionType: "default", minimumContentHeight: 0 }; class MockTextField extends import_scriptable_abstract.AbsTextField { constructor(config = {}) { super({ ...DEFAULT_STATE, ...config }); } get text() { return this.state.text; } set text(value) { let processedValue = value; switch (this.state._keyboardType) { case "number" /* number */: processedValue = value.replace(/[^\d]/g, ""); break; case "decimal" /* decimal */: processedValue = value.replace(/[^\d.]/g, ""); break; case "email" /* email */: processedValue = value.toLowerCase(); break; case "phone" /* phone */: processedValue = value.replace(/[^\d+\-()]/g, ""); break; case "url" /* url */: processedValue = value.toLowerCase(); break; } switch (this.state._autocapitalizationType) { case "words" /* words */: processedValue = processedValue.replace(/\b\w/g, (c) => c.toUpperCase()); break; case "sentences" /* sentences */: processedValue = processedValue.replace(/(^\w|\.\s+\w)/g, (c) => c.toUpperCase()); break; case "all" /* all */: processedValue = processedValue.toUpperCase(); break; } this.setState({ text: processedValue }); this.state.onTextChange?.(processedValue); } get placeholder() { return this.state.placeholder; } set placeholder(value) { this.setState({ placeholder: value }); } get isSecure() { return this.state.isSecure; } set isSecure(value) { this.setState({ isSecure: value }); } get textColor() { return this.state.textColor; } set textColor(value) { this.setState({ textColor: value }); } get font() { return this.state.font; } set font(value) { this.setState({ font: value }); } get minimumContentHeight() { return this.state.minimumContentHeight; } set minimumContentHeight(value) { this.setState({ minimumContentHeight: value }); } // Public properties for API compatibility get keyboardType() { return this.state._keyboardType; } set keyboardType(value) { this.setState({ _keyboardType: value }); } get alignment() { return this.state._textAlignment; } set alignment(value) { this.setState({ _textAlignment: value }); } get autocapitalizationType() { return this.state._autocapitalizationType; } set autocapitalizationType(value) { this.setState({ _autocapitalizationType: value }); } get returnKeyType() { return this.state._returnKeyType; } set returnKeyType(value) { this.setState({ _returnKeyType: value }); } // Event handlers onReturn(callback) { this.setState({ onReturn: callback }); } onTextChange(callback) { this.setState({ onTextChange: callback }); } onBeginEditing(callback) { this.setState({ onBeginEditing: callback }); } onEndEditing(callback) { this.setState({ onEndEditing: callback }); } // Keyboard type methods with validation setDefaultKeyboard() { this.keyboardType = "default" /* default */; } setNumberPadKeyboard() { this.keyboardType = "number" /* number */; this.text = this.state.text; } setDecimalPadKeyboard() { this.keyboardType = "decimal" /* decimal */; this.text = this.state.text; } setEmailAddressKeyboard() { this.keyboardType = "email" /* email */; this.text = this.state.text.toLowerCase(); } setPhonePadKeyboard() { this.keyboardType = "phone" /* phone */; this.text = this.state.text; } setURLKeyboard() { this.keyboardType = "url" /* url */; this.text = this.state.text.toLowerCase(); } setNumbersAndPunctuationKeyboard() { this.keyboardType = "number" /* number */; } setWebSearchKeyboard() { this.keyboardType = "default" /* default */; } setTwitterKeyboard() { this.keyboardType = "default" /* default */; } // Text alignment methods leftAlignText() { this.alignment = "left" /* left */; } centerAlignText() { this.alignment = "center" /* center */; } rightAlignText() { this.alignment = "right" /* right */; } // Additional properties get keyboardAppearance() { return this.state._keyboardAppearance; } set keyboardAppearance(value) { this.setState({ _keyboardAppearance: value }); } get spellCheckingType() { return this.state._spellCheckingType; } set spellCheckingType(value) { this.setState({ _spellCheckingType: value }); } get autocorrectionType() { return this.state._autocorrectionType; } set autocorrectionType(value) { this.setState({ _autocorrectionType: value }); } } // Static properties for API compatibility __publicField(MockTextField, "Alignment", TextFieldAlignment); __publicField(MockTextField, "KeyboardType", TextFieldKeyboardType); __publicField(MockTextField, "AutocapitalizationType", TextFieldAutocapitalizationType); __publicField(MockTextField, "ReturnKeyType", TextFieldReturnKeyType); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { MockTextField, TextFieldAlignment, TextFieldAutocapitalizationType, TextFieldKeyboardType, TextFieldReturnKeyType }); //# sourceMappingURL=text-field.js.map