UNPKG

@serenity-is/corelib

Version:
1,418 lines (1,406 loc) 925 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; // src/base/symbols.ts var isAssignableFromSymbol = Symbol.for("Serenity.isAssignableFrom"); var isInstanceOfTypeSymbol = Symbol.for("Serenity.isInstanceOfType"); var implementedInterfacesSymbol = Symbol.for("Serenity.implementedInterfaces"); var localTextTableSymbol = Symbol.for("Serenity.localTextTable"); var scriptDataHashSymbol = Symbol.for("Serenity.scriptDataHash"); var scriptDataSymbol = Symbol.for("Serenity.scriptData"); var typeRegistrySymbol = Symbol.for("Serenity.typeRegistry"); // src/base/system-internal.ts var _a; (_a = Symbol.typeInfo) != null ? _a : Symbol.typeInfo = Symbol.for("Serenity.typeInfo"); var globalObject = typeof globalThis !== "undefined" && globalThis || typeof window !== "undefined" && window || typeof self !== "undefined" && self || // @ts-ignore check for global typeof global !== "undefined" && global || {}; function merge(arr1, arr2) { if (!arr1 || !arr2) return (arr1 || arr2 || []).slice(); function distinct(arr) { return arr.filter((item, pos) => arr.indexOf(item) === pos); } __name(distinct, "distinct"); return distinct(arr1.concat(arr2)); } __name(merge, "merge"); function getTypeRegistry() { let typeRegistry = globalObject[typeRegistrySymbol]; if (!typeRegistry) typeRegistry = globalObject[typeRegistrySymbol] = {}; return typeRegistry; } __name(getTypeRegistry, "getTypeRegistry"); function interfaceIsAssignableFrom(from) { return from != null && Array.isArray(from[implementedInterfacesSymbol]) && from[implementedInterfacesSymbol].some((x) => { var _a105; return x === this || getTypeNameProp(this) && ((_a105 = peekTypeInfo(x)) == null ? void 0 : _a105.typeKind) === "interface" && getTypeNameProp(x) === getTypeNameProp(this); }); } __name(interfaceIsAssignableFrom, "interfaceIsAssignableFrom"); function autoRegisterViaTypeInfo(type) { var _a105; if (!Object.prototype.hasOwnProperty.call(type, Symbol.typeInfo)) return; const typeInfo = type[Symbol.typeInfo]; if (!typeInfo || typeInfo.registered || !typeInfo.typeName) return; if (typeInfo.typeName.endsWith(".")) typeInfo.typeName += type.name; if (!getTypeRegistry()[typeInfo.typeName]) getTypeRegistry()[typeInfo.typeName] = type; if (((_a105 = typeInfo.interfaces) == null ? void 0 : _a105.length) && !Object.prototype.hasOwnProperty.call(implementedInterfacesSymbol)) { Object.defineProperty(type, implementedInterfacesSymbol, { value: merge(type[implementedInterfacesSymbol], typeInfo.interfaces), configurable: true }); } if (typeInfo.typeKind === "interface" && !Object.prototype.hasOwnProperty.call(type, isAssignableFromSymbol)) { Object.defineProperty(type, isAssignableFromSymbol, { value: interfaceIsAssignableFrom, configurable: true }); } typeInfo.registered = true; return; } __name(autoRegisterViaTypeInfo, "autoRegisterViaTypeInfo"); function internalRegisterType(type, typeName, interfaces, kind) { const typeInfo = ensureTypeInfo(type); if (kind) typeInfo.typeKind = kind; if (typeName && typeName !== typeInfo.typeName) typeInfo.typeName = typeName; if (typeInfo.typeName) { if (typeInfo.typeName.endsWith(".")) typeInfo.typeName += type.name; getTypeRegistry()[typeInfo.typeName] = type; } if ((interfaces == null ? void 0 : interfaces.length) && typeInfo.interfaces !== interfaces) { interfaces = typeInfo.interfaces = merge(typeInfo.interfaces, interfaces); Object.defineProperty(type, implementedInterfacesSymbol, { value: merge(type[implementedInterfacesSymbol], interfaces), configurable: true }); } typeInfo.registered = true; return typeInfo; } __name(internalRegisterType, "internalRegisterType"); function ensureTypeInfo(type) { let typeInfo; if (!Object.prototype.hasOwnProperty.call(type, Symbol.typeInfo) || !(typeInfo = type[Symbol.typeInfo])) { typeInfo = { typeKind: void 0 }; Object.defineProperty(type, Symbol.typeInfo, { value: typeInfo, configurable: true, writable: true }); return typeInfo; } if (!typeInfo.registered) autoRegisterViaTypeInfo(type); return typeInfo; } __name(ensureTypeInfo, "ensureTypeInfo"); function peekTypeInfo(type) { if (!type || !Object.prototype.hasOwnProperty.call(type, Symbol.typeInfo)) return void 0; const typeInfo = type[Symbol.typeInfo]; if (typeInfo && !typeInfo.registered) autoRegisterViaTypeInfo(type); return typeInfo; } __name(peekTypeInfo, "peekTypeInfo"); function getTypeNameProp(type) { var _a105; return ((_a105 = peekTypeInfo(type)) == null ? void 0 : _a105.typeName) || void 0; } __name(getTypeNameProp, "getTypeNameProp"); function setTypeNameProp(type, value) { ensureTypeInfo(type).typeName = value; autoRegisterViaTypeInfo(type); } __name(setTypeNameProp, "setTypeNameProp"); // src/base/system.ts var nsSerenity = "Serenity."; var SerenityNS = "Serenity"; function getGlobalObject() { return globalObject; } __name(getGlobalObject, "getGlobalObject"); function omitUndefined(x) { if (x == null) return x; let obj = /* @__PURE__ */ Object.create(null); Object.entries(x).forEach(([key, value]) => value !== void 0 && (obj[key] = value)); return obj; } __name(omitUndefined, "omitUndefined"); function getNested(from, name) { var a = name.split("."); for (var i = 0; i < a.length; i++) { from = from[a[i]]; if (from == null) return null; } return from; } __name(getNested, "getNested"); function getType(name, target) { var type; if (target == null) { type = getTypeRegistry()[name]; if (type != null || globalObject == void 0 || name === "Object") return type; target = globalObject; } type = getNested(target, name); if (typeof type !== "function") return null; return type; } __name(getType, "getType"); function getTypeFullName(type) { return getTypeNameProp(type) || type.name || (type.toString().match(/^\s*function\s*([^\s(]+)/) || [])[1] || "Object"; } __name(getTypeFullName, "getTypeFullName"); function getTypeShortName(type) { var fullName = getTypeFullName(type); var bIndex = fullName == null ? void 0 : fullName.indexOf("["); var nsIndex = fullName == null ? void 0 : fullName.lastIndexOf(".", bIndex >= 0 ? bIndex : fullName.length); return nsIndex > 0 ? fullName.substring(nsIndex + 1) : fullName; } __name(getTypeShortName, "getTypeShortName"); function getInstanceType(instance) { if (instance == null) throw "Can't get instance type of null or undefined!"; try { return instance.constructor; } catch (ex) { return Object; } } __name(getInstanceType, "getInstanceType"); function isAssignableFrom(target, fromType) { if (target === fromType || fromType.prototype instanceof target) return true; if (typeof target[isAssignableFromSymbol] === "function") return target[isAssignableFromSymbol](fromType); return false; } __name(isAssignableFrom, "isAssignableFrom"); function isInstanceOfType(instance, type) { if (instance == null) return false; if (typeof type[isInstanceOfTypeSymbol] === "function") return type[isInstanceOfTypeSymbol](instance); return isAssignableFrom(type, getInstanceType(instance)); } __name(isInstanceOfType, "isInstanceOfType"); function getBaseType(type) { var _a105; if (type == null || type === Object || !type.prototype || ((_a105 = type[Symbol.typeInfo]) == null ? void 0 : _a105.typeKind) === "interface") return null; return Object.getPrototypeOf(type.prototype).constructor; } __name(getBaseType, "getBaseType"); function registerClass(type, name, intf) { internalRegisterType(type, name, intf, "class"); } __name(registerClass, "registerClass"); function registerEnum(enumType, name, enumKey) { if (typeof enumType !== "object" || enumType == null) throw "Enum type is required in registerEnum!"; if (name && name.endsWith(".")) throw "Enum name cannot end with a dot in registerEnum!"; internalRegisterType(enumType, name, void 0, "enum"); if (enumKey && enumKey != name) { const typeStore = getTypeRegistry(); if (!typeStore[enumKey]) typeStore[enumKey] = enumType; } } __name(registerEnum, "registerEnum"); function registerInterface(type, name, intf) { internalRegisterType(type, name, intf, "interface"); Object.defineProperty(type, isAssignableFromSymbol, { value: interfaceIsAssignableFrom, configurable: true }); } __name(registerInterface, "registerInterface"); var Enum; ((Enum2) => { Enum2.toString = /* @__PURE__ */ __name((enumType, value) => { var _a105; if (value == null) return ""; if (typeof value !== "number") return "" + value; var values = enumType; if (value === 0 || !((_a105 = peekTypeInfo(enumType)) == null ? void 0 : _a105.enumFlags)) { for (var i in values) { if (values[i] === value) { return i; } } return value == null ? "" : value.toString(); } else { var parts = []; for (var i in values) { if (typeof values[i] !== "number") continue; if (values[i] & value) { parts.push(i); value -= values[i]; } } if (value != 0) parts.push(value.toString()); return parts.join(" | "); } }, "toString"); Enum2.getValues = /* @__PURE__ */ __name((enumType) => { var parts = []; var values = enumType; for (var i in values) { if (Object.prototype.hasOwnProperty.call(values, i) && typeof values[i] === "number") parts.push(values[i]); } return parts; }, "getValues"); })(Enum || (Enum = {})); var isEnum = /* @__PURE__ */ __name((type) => { var _a105; return typeof type === "object" && ((_a105 = type[Symbol.typeInfo]) == null ? void 0 : _a105.typeKind) == "enum"; }, "isEnum"); function initFormType(typ, nameWidgetPairs) { for (var i = 0; i < nameWidgetPairs.length - 1; i += 2) { (function(name, widget) { Object.defineProperty(typ.prototype, name, { get: /* @__PURE__ */ __name(function() { return this.w(name, widget); }, "get"), enumerable: true, configurable: true }); })(nameWidgetPairs[i], nameWidgetPairs[i + 1]); } } __name(initFormType, "initFormType"); var _fieldsProxy = new Proxy({}, { get: /* @__PURE__ */ __name((_, p) => p, "get") }); function fieldsProxy() { return _fieldsProxy; } __name(fieldsProxy, "fieldsProxy"); function isArrayLike(obj) { return typeof obj === "object" && obj != null && typeof obj.length === "number" && typeof obj.nodeType !== "number"; } __name(isArrayLike, "isArrayLike"); function isPromiseLike(obj) { return obj instanceof Promise || typeof obj === "object" && obj != null && typeof obj.then === "function" && typeof obj.catch === "function"; } __name(isPromiseLike, "isPromiseLike"); var _EditorAttribute = class _EditorAttribute { }; __name(_EditorAttribute, "EditorAttribute"); var EditorAttribute = _EditorAttribute; registerClass(EditorAttribute, "Serenity.EditorAttribute"); var _ISlickFormatter = class _ISlickFormatter { }; __name(_ISlickFormatter, "ISlickFormatter"); var ISlickFormatter = _ISlickFormatter; registerInterface(ISlickFormatter, "Serenity.ISlickFormatter"); function registerFormatter(type, name, intf) { registerClass(type, name, merge([ISlickFormatter], intf)); } __name(registerFormatter, "registerFormatter"); function registerEditor(type, name, intf) { var _a105; registerClass(type, name, intf); const typeInfo = peekTypeInfo(type); typeInfo.typeKind = "editor"; if (!((_a105 = typeInfo.customAttributes) == null ? void 0 : _a105.some((x) => getInstanceType(x) === x))) addCustomAttribute(type, new EditorAttribute()); } __name(registerEditor, "registerEditor"); function addCustomAttribute(type, attr2) { let typeInfo = ensureTypeInfo(type); if (!typeInfo.customAttributes) typeInfo.customAttributes = [attr2]; else typeInfo.customAttributes.push(attr2); } __name(addCustomAttribute, "addCustomAttribute"); function getCustomAttribute(type, attrType, inherit = true) { var _a105; if (!type || attrType == null) return null; do { let attrs = (_a105 = peekTypeInfo(type)) == null ? void 0 : _a105.customAttributes; if (attrs) { for (var i = attrs.length - 1; i >= 0; i--) { let attr2 = attrs[i]; if (attr2 != null && isInstanceOfType(attr2, attrType)) return attr2; } } } while (inherit && (type = getBaseType(type))); } __name(getCustomAttribute, "getCustomAttribute"); function hasCustomAttribute(type, attrType, inherit = true) { return getCustomAttribute(type, attrType, inherit) != null; } __name(hasCustomAttribute, "hasCustomAttribute"); function getCustomAttributes(type, attrType, inherit = true) { var _a105; if (!type) return []; const allTypes = attrType === void 0; var result = []; do { let attrs = (_a105 = peekTypeInfo(type)) == null ? void 0 : _a105.customAttributes; if (attrs) { for (var i = attrs.length - 1; i >= 0; i--) { let attr2 = attrs[i]; if (attr2 && (allTypes || attrType && isInstanceOfType(attr2, attrType))) { result.push(attr2); } } } } while (inherit && (type = getBaseType(type))); return result; } __name(getCustomAttributes, "getCustomAttributes"); function classTypeInfo(typeName, intfAndAttr) { const typeInfo = { typeKind: "class", typeName }; const interfaces = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x === "function"); if (interfaces == null ? void 0 : interfaces.length) typeInfo.interfaces = interfaces; const attrs = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x !== "function"); if (attrs == null ? void 0 : attrs.length) typeInfo.customAttributes = attrs; return typeInfo; } __name(classTypeInfo, "classTypeInfo"); function editorTypeInfo(typeName, intfAndAttr) { const typeInfo = { typeKind: "editor", typeName }; const interfaces = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x === "function"); if (interfaces == null ? void 0 : interfaces.length) typeInfo.interfaces = interfaces; typeInfo.customAttributes = merge([new EditorAttribute()], intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x !== "function" && x.prototype !== EditorAttribute.prototype)); return typeInfo; } __name(editorTypeInfo, "editorTypeInfo"); function formatterTypeInfo(typeName, intfAndAttr) { const typeInfo = { typeKind: "formatter", typeName, interfaces: merge([ISlickFormatter], intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x === "function")) }; const attrs = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x !== "function"); if (attrs == null ? void 0 : attrs.length) typeInfo.customAttributes = attrs; return typeInfo; } __name(formatterTypeInfo, "formatterTypeInfo"); function interfaceTypeInfo(typeName, intfAndAttr) { const typeInfo = { typeKind: "interface", typeName }; const interfaces = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x === "function"); if (interfaces == null ? void 0 : interfaces.length) typeInfo.interfaces = interfaces; const attrs = intfAndAttr == null ? void 0 : intfAndAttr.filter((x) => typeof x !== "function"); if (attrs == null ? void 0 : attrs.length) typeInfo.customAttributes = attrs; return typeInfo; } __name(interfaceTypeInfo, "interfaceTypeInfo"); function registerType(type) { if (!type) throw "registerType is called with null target!"; let typeInfo = peekTypeInfo(type); if (!typeInfo) throw `registerType is called on type "${type.name}" that does not have a static [Symbol.typeInfo] property!`; if (!typeInfo.typeName) throw `registerType is called on type "${type.name}", but it's typeInfo property does not have a typeName!`; } __name(registerType, "registerType"); // src/base/localtext.ts function getTable() { let localTextTable = getGlobalObject()[localTextTableSymbol]; if (!localTextTable) getGlobalObject()[localTextTableSymbol] = localTextTable = {}; return localTextTable; } __name(getTable, "getTable"); function addLocalText(obj, pre) { if (!obj) return; let table = getTable(); if (typeof obj === "string") { table[obj] = pre; return; } pre != null ? pre : pre = ""; for (let k of Object.keys(obj)) { let actual = pre + k; let o = obj[k]; if (typeof o === "object") { addLocalText(o, actual + "."); } else { table[actual] = o; } } } __name(addLocalText, "addLocalText"); function localText(key, defaultText) { var _a105, _b67, _c; return (_c = (_b67 = (_a105 = getTable()[key]) != null ? _a105 : defaultText) != null ? _b67 : key) != null ? _c : ""; } __name(localText, "localText"); function tryGetText(key) { return getTable()[key]; } __name(tryGetText, "tryGetText"); function proxyTexts(o, p, t) { return new Proxy(o, { get: /* @__PURE__ */ __name((_, y) => { if (typeof y === "symbol") return; var tv = t[y]; if (tv == null) return localText(p + y); else { var z = o[y]; if (z != null) return z; o[y] = z = proxyTexts({}, p + y + ".", tv); return z; } }, "get"), ownKeys: /* @__PURE__ */ __name((_) => Object.keys(t), "ownKeys") }); } __name(proxyTexts, "proxyTexts"); var TranslationConfig = { /** Retrieves the list of available languages */ getLanguageList: null, /** A function to translate texts based on provided options */ translateTexts: null }; var text = localText; var LT; ((LT2) => { LT2.add = addLocalText; LT2.getDefault = localText; })(LT || (LT = {})); var global2 = getGlobalObject(); var serenity = global2.Serenity || (global2.Serenity = {}); serenity.LT = serenity.LT || {}; serenity.LT.add = serenity.addLocalText = addLocalText; // src/base/config.ts var Config = { /** * This is the root path of your application. If your application resides under http://localhost/mysite/, * your root path is "/mysite/". This variable is automatically initialized by reading from a <link> element * with ID "ApplicationPath" from current page, which is usually located in your _LayoutHead.cshtml file */ applicationPath: "/", /** * Gets a default return URL for the application. This is used when a return URL is not specified * @param purpose Optional purpose for the return URL, for example "login" or "logout" */ defaultReturnUrl: /* @__PURE__ */ __name((purpose) => Config.applicationPath, "defaultReturnUrl"), /** * Email validation by default only allows ASCII characters. Set this to true if you want to allow unicode. */ emailAllowOnlyAscii: true, /** * This is an optional callback that is used to load types lazily when they are not found in the * type registry. This is useful when a type is not available in currently loaded scripts * (e.g. chunks / entry modules) but is available via some other means (e.g. a separate script file). * The method may return a type or a promise that resolves to a type. If either returns null, * the type is considered to be not found. * The method is called with the type key and an optional kind parameter, which is used to distinguish * between different kinds of types (e.g. "editor" or "dialog" or "enum"). */ lazyTypeLoader: null, /** * This is the list of root namespaces that may be searched for types. For example, if you specify an editor type * of "MyEditor", first a class with name "MyEditor" will be searched, if not found, search will be followed by * "Serenity.MyEditor" and "MyApp.MyEditor" if you added "MyApp" to the list of root namespaces. * * You should usually add your application root namespace to this list in ScriptInit(ialization).ts file. */ rootNamespaces: ["Serenity"], /** * This is an optional method for handling when user is not logged in. If a users session is expired * and when a NotAuthorized response is received from a service call, Serenity will call this handler, so * you may intercept it and notify user about this situation and ask if she wants to login again... */ notLoggedInHandler: null }; function resetApplicationPath() { Config.applicationPath = "/"; if (typeof document !== "undefined") { var pathLink = document.querySelector("link#ApplicationPath"); if (pathLink != null) { Config.applicationPath = pathLink.getAttribute("href"); } } } __name(resetApplicationPath, "resetApplicationPath"); resetApplicationPath(); // src/base/html.ts var esc = { "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;", "&": "&amp;" }; function escFunc(a) { return esc[a]; } __name(escFunc, "escFunc"); function htmlEncode(s) { if (s == null) return ""; if (typeof s !== "string") s = "" + s; return s.replace(/[<>"'&]/g, escFunc); } __name(htmlEncode, "htmlEncode"); function toggleClass(el, cls, add) { if (!el || cls == null || !cls.length) return; if (cls.indexOf(" ") < 0) { el.classList.toggle(cls, add); return; } var k = cls.split(" ").map((x) => x.trim()).filter((x) => x.length); for (var a of k) el.classList.toggle(a, add); } __name(toggleClass, "toggleClass"); function addClass(el, cls) { return toggleClass(el, cls, true); } __name(addClass, "addClass"); function removeClass(el, cls) { return toggleClass(el, cls, false); } __name(removeClass, "removeClass"); function appendToNode(parent2, child) { if (child == null || child === false) return; if (isArrayLike(child)) { for (var i = 0; i < child.length; i++) { appendToNode(parent2, child[i]); } } else if (typeof child === "string") { parent2.appendChild(document.createTextNode(child)); } else if (child instanceof Node) { parent2.appendChild(child); } else if (isPromiseLike(child)) { const placeholder = parent2.appendChild(document.createComment("Loading content...")); child.then((result) => { var _a105; const fragment = document.createDocumentFragment(); appendToNode(fragment, result); (_a105 = placeholder.parentElement) == null ? void 0 : _a105.replaceChild(fragment, placeholder); }, (error) => { placeholder.textContent = "Error loading content: " + error; throw error; }); } else { parent2.append(child); } } __name(appendToNode, "appendToNode"); var SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^&:/?#]*(?:[/?#]|$))/gi; var DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[a-z0-9+\/]+=*$/i; function sanitizeUrl(url) { url = String(url).trim(); if (url === "null" || url.length === 0 || url === "about:blank") return "about:blank"; if (url.match(SAFE_URL_PATTERN) || url.match(DATA_URL_PATTERN)) return url; if (url === "javascript:void(0)" || url === "javascript:;") return url; return `unsafe:${url}`; } __name(sanitizeUrl, "sanitizeUrl"); function getElementReadOnly(el) { if (el == null) return null; if (el.classList.contains("readonly")) return true; const type = el.getAttribute("type"); if (el.tagName == "SELECT" || type === "radio" || type === "checkbox") return el.hasAttribute("disabled"); return el.hasAttribute("readonly"); } __name(getElementReadOnly, "getElementReadOnly"); function setElementReadOnly(elements, value) { if (!elements) return; elements = isArrayLike(elements) ? elements : [elements]; for (var i = 0; i < elements.length; i++) { let el = elements[i]; if (!el) continue; var type = el.getAttribute("type"); el.classList.toggle("readonly", !!value); const attr2 = el.tagName == "SELECT" || type === "radio" || type === "checkbox" ? "disabled" : "readonly"; value ? el.setAttribute(attr2, attr2) : el.removeAttribute(attr2); } } __name(setElementReadOnly, "setElementReadOnly"); function parseQueryString(s) { let qs; if (s === void 0) qs = location.search.substring(1, location.search.length); else qs = s || ""; let result = {}; let parts = qs.split("&"); for (let i = 0; i < parts.length; i++) { let part = parts[i]; if (!part.length) continue; let pair = parts[i].split("="); let name = decodeURIComponent(pair[0]); result[name] = pair.length >= 2 ? decodeURIComponent(pair[1]) : name; } return result; } __name(parseQueryString, "parseQueryString"); function getReturnUrl(opt) { var q = parseQueryString(); var returnUrl = q["returnUrl"] || q["ReturnUrl"] || q["ReturnURL"] || q["returnURL"]; if (returnUrl && (!(opt == null ? void 0 : opt.ignoreUnsafe) && !/^\//.test(returnUrl))) return null; if (!returnUrl && !(opt == null ? void 0 : opt.queryOnly)) returnUrl = Config.defaultReturnUrl(opt == null ? void 0 : opt.purpose); return returnUrl; } __name(getReturnUrl, "getReturnUrl"); function cssEscape(selector) { if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(selector); var string = String(selector); var length = string.length; var index = -1; var codeUnit; var result = ""; var firstCodeUnit = string.charCodeAt(0); if (length == 1 && firstCodeUnit == 45) return "\\" + string; while (++index < length) { codeUnit = string.charCodeAt(index); if (codeUnit == 0) { result += "\uFFFD"; continue; } if (codeUnit >= 1 && codeUnit <= 31 || codeUnit == 127 || index == 0 && codeUnit >= 48 && codeUnit <= 57 || index == 1 && codeUnit >= 48 && codeUnit <= 57 && firstCodeUnit == 45) { result += "\\" + codeUnit.toString(16) + " "; continue; } if (codeUnit >= 128 || codeUnit == 45 || codeUnit == 95 || codeUnit >= 48 && codeUnit <= 57 || codeUnit >= 65 && codeUnit <= 90 || codeUnit >= 97 && codeUnit <= 122) { result += string.charAt(index); continue; } result += "\\" + string.charAt(index); } return result; } __name(cssEscape, "cssEscape"); // src/base/toastr2.ts var initialOptions = { tapToDismiss: true, toastClass: "toast", containerId: "toast-container", onShown: /* @__PURE__ */ __name(() => { }, "onShown"), onHidden: /* @__PURE__ */ __name(() => { }, "onHidden"), closeOnHover: true, extendedTimeOut: 1e3, iconClass: "toast-info", positionClass: "toast-top-right", timeOut: 5e3, // Set timeOut to 0 to make it sticky titleClass: "toast-title", messageClass: "toast-message", escapeHtml: true, target: "body", closeHtml: '<button type="button">&times;</button>', closeClass: "toast-close-button", newestOnTop: true, preventDuplicates: false, rtl: false, onCloseClick: /* @__PURE__ */ __name(() => { }, "onCloseClick"), closeButton: false, onclick: /* @__PURE__ */ __name(() => { }, "onclick") }; var initialInstance = null; var _Toastr = class _Toastr { constructor(options) { var _a105; this.toastId = 0; this.previousToast = null; this.options = Object.assign(Object.assign({}, (_a105 = initialInstance == null ? void 0 : initialInstance.options) != null ? _a105 : initialOptions), options); } getContainer(options, create = false) { var _a105, _b67, _c; let container = document.getElementById((_a105 = options == null ? void 0 : options.containerId) != null ? _a105 : this.options.containerId); if (container || !create) return container; container = document.createElement("div"); container.setAttribute("id", this.options.containerId); let positionClass = (_b67 = options == null ? void 0 : options.positionClass) != null ? _b67 : this.options.positionClass; if (positionClass) addClass(container, positionClass); let targetSelector = (_c = options == null ? void 0 : options.target) != null ? _c : this.options.target; const target = document.querySelector(targetSelector); if (target) target.appendChild(container); return container; } error(message, title, opt) { return this.notify({ type: "error", iconClass: "toast-error", message, title }, opt); } warning(message, title, opt) { return this.notify({ type: "warning", iconClass: "toast-warning", message, title }, opt); } success(message, title, opt) { return this.notify({ type: "success", iconClass: "toast-success", message, title }, opt); } info(message, title, opt) { return this.notify({ type: "info", iconClass: "toast-info", message, title }, opt); } subscribe(callback) { this.listener = callback; } publish(args) { if (!this.listener) { return; } this.listener(args); } removeContainerIfEmpty(options) { var _a105; let container = this.getContainer(options); if (!container) return; if (!((_a105 = container.hasChildNodes) == null ? void 0 : _a105.call(container)) && container.parentNode) container.parentNode.removeChild(container); } removeToast(toastElement, options) { var _a105; if (!toastElement) return; if (toastElement !== document.activeElement) { (_a105 = toastElement.parentNode) == null ? void 0 : _a105.removeChild(toastElement); this.previousToast = null; this.removeContainerIfEmpty(options); } } clear(options) { let container = this.getContainer(options); if (!container) return; const toastsToClear = Array.from(container.childNodes); for (let i = toastsToClear.length - 1; i >= 0; i -= 1) this.removeToast(toastsToClear[i], options); this.removeContainerIfEmpty(); } notify(map, opt) { opt = Object.assign(Object.assign(Object.assign({}, this.options), map), opt); const shouldExit = /* @__PURE__ */ __name((opts, exitMap) => { if (opts.preventDuplicates) { if (exitMap.message === this.previousToast) { return true; } this.previousToast = exitMap.message || ""; } return false; }, "shouldExit"); if (shouldExit(opt, map)) { return null; } this.toastId += 1; var container = this.getContainer(opt, true); let intervalId = null; const toastElement = document.createElement("div"); const $titleElement = document.createElement("div"); const $messageElement = document.createElement("div"); const closeContainer = document.createElement("div"); closeContainer.innerHTML = opt.closeHtml.trim(); const closeElement = closeContainer.firstChild; const response = { toastId: this.toastId, state: "visible", startTime: /* @__PURE__ */ new Date(), endTime: void 0, opt, map }; const hideToast = /* @__PURE__ */ __name((override = null) => { if (toastElement === document.activeElement && !override) { return; } this.removeToast(toastElement); if (intervalId) { clearTimeout(intervalId); } if (opt.onHidden && response.state !== "hidden") { opt.onHidden(); } response.state = "hidden"; response.endTime = /* @__PURE__ */ new Date(); this.publish(response); }, "hideToast"); const setAria = /* @__PURE__ */ __name(() => { let ariaValue = ""; switch (opt.iconClass) { case "toast-success": case "toast-info": ariaValue = "polite"; break; default: ariaValue = "assertive"; } toastElement.setAttribute("aria-live", ariaValue); }, "setAria"); const handleEvents = /* @__PURE__ */ __name(() => { if (opt.closeOnHover) { toastElement.addEventListener("mouseover", () => { if (intervalId) { clearTimeout(intervalId); } }); toastElement.addEventListener("mouseout", () => { if (opt.timeOut >= 0 && (opt.timeOut > 0 || opt.extendedTimeOut > 0)) { intervalId = setTimeout(hideToast, opt.extendedTimeOut); } }); } if (!opt.onclick && opt.tapToDismiss) { toastElement.addEventListener("click", hideToast); } if (opt.closeButton && closeElement) { closeElement.addEventListener("click", (event) => { event.stopPropagation(); if (opt.onCloseClick) { opt.onCloseClick(event); } hideToast(true); }); } if (opt.onclick) { toastElement.addEventListener("click", (event) => { if (opt.onclick) { opt.onclick(event); } if (opt.tapToDismiss) hideToast(); }); } }, "handleEvents"); const setTitle = /* @__PURE__ */ __name(() => { if (map.title) { let suffix = map.title; if (opt.escapeHtml) { suffix = htmlEncode(map.title); } $titleElement.innerHTML = suffix; addClass($titleElement, opt.titleClass); toastElement.appendChild($titleElement); } }, "setTitle"); const setMessage = /* @__PURE__ */ __name(() => { if (map.message) { let suffix = map.message; if (opt.escapeHtml) { suffix = htmlEncode(map.message); } $messageElement.innerHTML = suffix; addClass($messageElement, opt.messageClass); toastElement.appendChild($messageElement); } }, "setMessage"); const setCloseButton = /* @__PURE__ */ __name(() => { if (opt.closeButton && closeElement) { addClass(closeElement, opt.closeClass); closeElement.setAttribute("role", "button"); toastElement.insertBefore(closeElement, toastElement.firstChild); } }, "setCloseButton"); const setSequence = /* @__PURE__ */ __name(() => { if (opt.newestOnTop) { container.insertBefore(toastElement, container.firstChild); } else { container.appendChild(toastElement); } }, "setSequence"); const displayToast = /* @__PURE__ */ __name(() => { if (opt.onShown) { opt.onShown(); } if (opt.timeOut > 0) { intervalId = setTimeout(hideToast, opt.timeOut); } }, "displayToast"); const personalizeToast = /* @__PURE__ */ __name(() => { toastElement.classList.add("show"); opt.rtl && toastElement.classList.add("rtl"); opt.toastClass && addClass(toastElement, opt.toastClass); opt.iconClass && addClass(toastElement, opt.iconClass); setTitle(); setMessage(); setCloseButton(); setSequence(); setAria(); }, "personalizeToast"); personalizeToast(); displayToast(); handleEvents(); this.publish(response); return toastElement; } }; __name(_Toastr, "Toastr"); var Toastr = _Toastr; initialInstance = new Toastr(); var toastr2_default = initialInstance; // src/base/notify.ts var defaultNotifyOptions = { timeOut: 5e3, escapeHtml: true, positionClass: "position-toast toast-top-full-width" }; function positionToastContainer(options, create = true) { let container = toastr2_default.getContainer(options, create); if (!container || !container.classList.contains("position-toast") || typeof document === "undefined" || !document.body) return; let dialogs = Array.from(document.body.children); let dialogIndex = dialogs.findIndex((x) => x.matches(".ui-dialog, .modal.in, .modal.show") && !x.matches('[style*="display:none"], [style*="display: none"], .hidden')); let dialog = dialogs[dialogIndex]; if (dialog) { const { top, left, right } = dialog.getBoundingClientRect(); container.classList.add("positioned-toast"); container.style.position = "absolute"; container.style.top = top + 28 + "px"; container.style.left = left + 6 + "px"; container.style.width = Math.max(right - left - 12, 150) + "px"; } else if (container.classList.contains("positioned-toast")) { container.classList.remove("positioned-toast"); container.style.position = ""; container.style.top = ""; container.style.left = ""; container.style.width = ""; } } __name(positionToastContainer, "positionToastContainer"); function getToastrOptions(options) { options = Object.assign(Object.assign({}, defaultNotifyOptions), options); positionToastContainer(options); return options; } __name(getToastrOptions, "getToastrOptions"); function showToast(type, message, title, options) { return toastr2_default[type](message, title, getToastrOptions(options)); } __name(showToast, "showToast"); function notifyError(message, title, options) { showToast("error", message, title, options); } __name(notifyError, "notifyError"); function notifyInfo(message, title, options) { showToast("info", message, title, options); } __name(notifyInfo, "notifyInfo"); function notifySuccess(message, title, options) { showToast("success", message, title, options); } __name(notifySuccess, "notifySuccess"); function notifyWarning(message, title, options) { showToast("warning", message, title, options); } __name(notifyWarning, "notifyWarning"); // src/base/blockui.ts var blockUICount = 0; function blockUI(options) { function block() { var _a105; if (blockUICount++ > 0 || typeof document === "undefined") return; var div = document.createElement("div"); div.className = "blockUI blockOverlay"; div.setAttribute("style", `z-index: ${(_a105 = options == null ? void 0 : options.zIndex) != null ? _a105 : 2e3}; border: none; margin: 0px; padding: 0px; width: 100%; height: 100%; top: 0px; left: 0px; opacity: 0; cursor: wait; position: fixed;`); document.body.appendChild(div); } __name(block, "block"); (options == null ? void 0 : options.useTimeout) && window.setTimeout(block, 0) || block(); } __name(blockUI, "blockUI"); function blockUndo() { var _a105; if (blockUICount < 1) return; if (--blockUICount === 0 && typeof document !== "undefined") (_a105 = document.body.querySelector(":scope > .blockUI.blockOverlay")) == null ? void 0 : _a105.remove(); } __name(blockUndo, "blockUndo"); // src/base/lookup.ts var _Lookup = class _Lookup { constructor(options, items) { this.items = []; this.itemById = {}; options = options || {}; this.idField = options.idField; this.parentIdField = options.parentIdField; this.textField = options.textField; if (items != null) this.update(items); } update(value) { this.items = []; this.itemById = {}; if (value) { for (var k of value) { if (k == null || typeof k !== "object") this.items.push({ [this.idField]: k, [this.textField]: k }); else this.items.push(k); } } var idField = this.idField; if (idField) { for (var r of this.items) { var v = r[idField]; if (v != null) { this.itemById[v] = r; } } } } }; __name(_Lookup, "Lookup"); var Lookup = _Lookup; // src/base/environment.ts function getjQuery() { return typeof jQuery === "function" ? jQuery : typeof $ === "function" && $.fn ? $ : void 0; } __name(getjQuery, "getjQuery"); function isBS3() { var _a105, _b67, _c, _d; return (((_d = (_c = (_b67 = (_a105 = getjQuery()) == null ? void 0 : _a105.fn) == null ? void 0 : _b67.modal) == null ? void 0 : _c.Constructor) == null ? void 0 : _d.VERSION) + "").charAt(0) == "3"; } __name(isBS3, "isBS3"); function isBS5Plus() { return typeof bootstrap !== "undefined" && !!bootstrap.Modal && (bootstrap.Modal.VERSION + "").charAt(0) != "4"; } __name(isBS5Plus, "isBS5Plus"); // src/base/fluent-events.ts var stripNameRegex = /\..*/; var stripUidRegex = /::\d+$/; var uidEvent = 1; var customEvents = { mouseenter: "mouseover", mouseleave: "mouseout" }; function makeEventUid(prefix) { return `${prefix}::${uidEvent++}`; } __name(makeEventUid, "makeEventUid"); var eventRegistry = /* @__PURE__ */ new WeakMap(); function disposeDescendants(element) { element.querySelectorAll("*").forEach((node) => disposeElement(node)); } __name(disposeDescendants, "disposeDescendants"); function disposeElement(element) { let events = eventRegistry.get(element); if (!events) return; eventRegistry.delete(element); var disposeHandlers = events["disposing"]; if (disposeHandlers) { for (const [_, handler] of Object.entries(disposeHandlers)) { if (typeof handler.callable === "function") { try { handler.callable.call(element, { target: element }); } catch (e) { } } } } for (const [typeEvent, handlers] of Object.entries(events)) { for (const [handlerKey, handler] of Object.entries(handlers)) { element.removeEventListener(typeEvent, handler, Boolean(handler.delegationSelector)); delete handlers[handlerKey]; } } } __name(disposeElement, "disposeElement"); function getElementEvents(element) { var events = eventRegistry.get(element); if (!events) eventRegistry.set(element, events = {}); return events; } __name(getElementEvents, "getElementEvents"); function hydrateEvent(obj, meta = {}) { for (const [key, value] of Object.entries(meta)) { if (key === "bubbles" || key === "cancelable") { continue; } try { obj[key] = value; } catch (e) { Object.defineProperty(obj, key, { configurable: true, get() { return value; } }); } } return obj; } __name(hydrateEvent, "hydrateEvent"); function baseHandler(element, fn) { return /* @__PURE__ */ __name(function handler(event) { hydrateEvent(event, { delegateTarget: element }); if (handler.oneOff) { removeListener(element, event.type, fn); } return fn.apply(element, [event]); }, "handler"); } __name(baseHandler, "baseHandler"); function delegationHandler(element, selector, fn) { return /* @__PURE__ */ __name(function handler(event) { const domElements = element.querySelectorAll(selector); for (let { target } = event; target && target !== this; target = target.parentNode) { for (const domElement of domElements) { if (domElement !== target) { continue; } hydrateEvent(event, { delegateTarget: target }); if (handler.oneOff) { removeListener(element, event.type, selector, fn); } return fn.apply(target, [event]); } } }, "handler"); } __name(delegationHandler, "delegationHandler"); function findHandler(handlers, callable, delegationSelector = null) { return Object.values(handlers).find((event) => event.callable === callable && event.delegationSelector === delegationSelector); } __name(findHandler, "findHandler"); function normalizeParameters(originalTypeEvent, handler, delegationFunction) { const isDelegated = typeof handler === "string"; const callable = isDelegated ? delegationFunction : handler || delegationFunction; let typeEvent = getTypeEvent(originalTypeEvent); if (originalTypeEvent.indexOf(".bs.") >= 0) typeEvent = originalTypeEvent; return [isDelegated, callable, typeEvent]; } __name(normalizeParameters, "normalizeParameters"); function addListener(element, originalTypeEvent, handler, delegationFunction, oneOff) { if (typeof originalTypeEvent !== "string" || !element) { return; } const $2 = getjQuery(); if ($2) { let $element = $2(element); if (oneOff) $element.one(originalTypeEvent, handler, delegationFunction); else $element.on(originalTypeEvent, handler, delegationFunction); return; } let [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationFunction); if (!callable) return; if (originalTypeEvent in customEvents) { const wrapFunction = /* @__PURE__ */ __name((fn2) => { return function(event) { if (!event.relatedTarget || event.relatedTarget !== event.delegateTarget && !event.delegateTarget.contains(event.relatedTarget)) { return fn2.call(this, event); } }; }, "wrapFunction"); callable = wrapFunction(callable); } const events = getElementEvents(element); const handlers = events[typeEvent] || (events[typeEvent] = /* @__PURE__ */ Object.create(null)); const previousFunction = findHandler(handlers, callable, isDelegated ? handler : null); if (previousFunction) { previousFunction.oneOff = previousFunction.oneOff && oneOff; return; } const dotIdx = originalTypeEvent.indexOf("."); const ns = dotIdx > -1 ? originalTypeEvent.substring(dotIdx + 1) : ""; const uid = makeEventUid(ns); const fn = isDelegated ? delegationHandler(element, handler, callable) : baseHandler(element, callable); fn.delegationSelector = isDelegated ? handler : null; fn.callable = callable; fn.oneOff = oneOff; fn.uidEvent = uid; if (uid !== "__proto__") handlers[uid] = fn; element.addEventListener(typeEvent, fn, isDelegated); } __name(addListener, "addListener"); function removeHandler(element, events, typeEvent, handler, delegationSelector) { const fn = findHandler(events[typeEvent], handler, delegationSelector); if (!fn) { return; } element.removeEventListener(typeEvent, fn, Boolean(delegationSelector)); delete events[typeEvent][fn.uidEvent]; } __name(removeHandler, "removeHandler"); function removeNamespacedHandlers(element, events, typeEvent, namespace) { const handlers = events[typeEvent] || {}; for (const [handlerKey, handler] of Object.entries(handlers)) { if (handlerKey.includes(namespace)) { removeHandler(element, events, typeEvent, handler.callable, handler.delegationSelector); } } } __name(removeNamespacedHandlers, "removeNamespacedHandlers"); function getTypeEvent(event) { event = event.replace(stripNameRegex, ""); return customEvents[event] || event; } __name(getTypeEvent, "getTypeEvent"); function removeListener(element, originalTypeEvent, handler, delegationHandler2) { if (typeof originalTypeEvent !== "string" || !element) { return; } const $2 = getjQuery(); if ($2) { $2(element).off(originalTypeEvent, handler, delegationHandler2); return; } const [isDelegated, callable, typeEvent] = normalizeParameters(originalTypeEvent, handler, delegationHandler2); const inNamespace = typeEvent !== originalTypeEvent; const events = getElementEvents(element); const handlers = events[typeEvent] || {}; const isNamespace = originalTypeEvent.startsWith("."); if (typeof callable !== "undefined") { if (!Object.keys(handlers).length) { return; } removeHandler(element, events, typeEvent, callable, isDelegated ? handler : null); return; } if (isNamespace) { for (const elementEvent of Object.keys(events)) { removeNamespacedHandlers(element, events, elementEvent, originalTypeEvent.slice(1)); } } for (const [keyHandlers, handler2] of Object.entries(handlers)) { const handlerKey = keyHandlers.replace(stripUidRegex, ""); if (!inNamespace || originalTypeEvent.includes(handlerKey)) { removeHandler(element, events, typeEvent, handler2.callable, handler2.delegationSelector); } } } __name(removeListener, "removeListener"); function triggerEvent(element, type, args) { var _a105, _b67; if (typeof type !== "string" || !element) { return null; } const $2 = getjQuery(); const typeEvent = getTypeEvent(type); const inNamespace = type !== typeEvent; let jQueryEvent = null; let bubbles = (_a105 = args == null ? void 0 : args.bubbles) != null ? _a105 : true; let nativeDispatch = true; let defaultPrevented = false; if (inNamespace && $2) { jQueryEvent = $2.Event(type, args); $2(element).trigger(jQueryEvent); bubbles = bubbles && !jQueryEvent.isPropagationStopped(); nativeDispatch = !jQueryEvent.isImmediatePropagationStopped(); defaultPrevented = jQueryEvent.isDefaultPrevented(); } const evt = hydrateEvent(new Event(type, { bubbles, cancelable: (_b67 = args == null ? void 0 : args.cancelable) != null ? _b67 : true }), args); if