scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
236 lines • 7.49 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
import { AbsTextField } from "scriptable-abstract";
import { MockColor } from "./color";
import { MockFont } from "./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 MockColor("#000000"),
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 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);
export {
MockTextField,
TextFieldAlignment,
TextFieldAutocapitalizationType,
TextFieldKeyboardType,
TextFieldReturnKeyType
};
//# sourceMappingURL=text-field.js.map