UNPKG

uicore-ts

Version:

UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha

87 lines (86 loc) 3.08 kB
"use strict"; 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 UIAutocompleteRowView_exports = {}; __export(UIAutocompleteRowView_exports, { UIAutocompleteRowView: () => UIAutocompleteRowView }); module.exports = __toCommonJS(UIAutocompleteRowView_exports); var import_UIButton = require("./UIButton"); var import_UIColor = require("./UIColor"); var import_UIObject = require("./UIObject"); var import_UITextView = require("./UITextView"); class UIAutocompleteRowView extends import_UIButton.UIButton { constructor(elementID) { super(elementID); this._filterWords = []; this.titleLabel.textAlignment = import_UITextView.UITextView.textAlignment.left; this.userInteractionEnabled = import_UIObject.YES; this.style.outline = "none"; this.viewHTMLElement.setAttribute("tabindex", "-1"); this.colors = { titleLabel: { normal: import_UIColor.UIColor.blackColor, highlighted: import_UIColor.UIColor.blackColor, selected: import_UIColor.UIColor.whiteColor }, background: { normal: import_UIColor.UIColor.whiteColor, hovered: import_UIColor.UIColor.lightGreyColor, highlighted: import_UIColor.UIColor.lightGreyColor, selected: import_UIColor.UIColor.greyColor } }; } set item(item) { this._item = item; this._updateLabelContent(); } get item() { return this._item; } set filterWords(words) { this._filterWords = words; this._updateLabelContent(); } get filterWords() { return this._filterWords; } _updateLabelContent() { if (!this._item) { return; } const label = this._item.label; if (this._filterWords.length === 0) { this.titleLabel.text = label; return; } const escapedWords = this._filterWords.map( (word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") ); const pattern = new RegExp(`(${escapedWords.join("|")})`, "gi"); const escaped = label.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"); const highlighted = escaped.replace(pattern, "<strong>$1</strong>"); this.titleLabel.innerHTML = highlighted; } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { UIAutocompleteRowView }); //# sourceMappingURL=UIAutocompleteRowView.js.map