{"version":3,"file":"Serenity.CoreLib.js","sources":["../corelib/q/arrays.ts","../corelib/q/system.ts","../corelib/q/strings.ts","../corelib/q/localtext.ts","../corelib/globals/jquery-module.ts","../corelib/q/html.ts","../corelib/q/toastr2.ts","../corelib/q/notify.ts","../corelib/q/config.ts","../corelib/globals/bootstrap-module.ts","../corelib/q/dialogs.ts","../corelib/q/errorhandling.ts","../corelib/q/blockui.ts","../corelib/q/services.ts","../corelib/q/formatting.ts","../corelib/q/scriptdata.ts","../corelib/q/authorization.ts","../corelib/q/debounce.ts","../corelib/q/layouttimer.ts","../corelib/q/router.ts","../corelib/q/layout.ts","../corelib/q/lookup.ts","../corelib/q/propertyitem.ts","../corelib/q/servicetypes.ts","../corelib/globals/jquery.validation-module.ts","../corelib/q/validation.ts","../corelib/q/validateoptions.ts","../corelib/q/criteria.ts","../corelib/q/index.ts","../corelib/decorators/index.ts","../corelib/interfaces/ibooleanvalue.ts","../corelib/interfaces/idoublevalue.ts","../corelib/interfaces/idialog.ts","../corelib/interfaces/ieditdialog.ts","../corelib/interfaces/igeteditvalue.ts","../corelib/interfaces/ireadonly.ts","../corelib/interfaces/iseteditvalue.ts","../corelib/interfaces/istringvalue.ts","../corelib/interfaces/ivalidaterequired.ts","../corelib/types/captureoperationtype.ts","../corelib/types/reflectionutils.ts","../corelib/types/commontyperegistry.ts","../corelib/types/dialogtyperegistry.ts","../corelib/patch/jquerypatch.ts","../corelib/ui/widgets/widget.ts","../corelib/types/editortyperegistry.ts","../corelib/types/enumtyperegistry.ts","../corelib/ui/helpers/lazyloadhelper.ts","../corelib/ui/widgets/prefixedcontext.ts","../corelib/ui/widgets/toolbar.ts","../corelib/ui/widgets/templatedwidget.ts","../corelib/ui/widgets/flexify.ts","../corelib/ui/dialogs/dialogextensions.ts","../corelib/ui/dialogs/templateddialog.ts","../corelib/ui/widgets/templatedpanel.ts","../corelib/ui/helpers/validationhelper.ts","../corelib/ui/editors/cascadedwidgetlink.ts","../corelib/ui/helpers/tabsextensions.ts","../corelib/ui/widgets/reflectionoptionssetter.ts","../corelib/ui/editors/editorutils.ts","../corelib/ui/widgets/propertygrid.ts","../corelib/ui/widgets/propertypanel.ts","../corelib/ui/helpers/subdialoghelper.ts","../corelib/ui/dialogs/propertydialog.ts","../corelib/ui/editors/stringeditor.ts","../corelib/ui/editors/passwordeditor.ts","../corelib/ui/editors/textareaeditor.ts","../corelib/ui/editors/booleaneditor.ts","../corelib/ui/editors/decimaleditor.ts","../corelib/ui/editors/integereditor.ts","../corelib/ui/editors/dateeditor.ts","../corelib/ui/editors/datetimeeditor.ts","../corelib/ui/editors/timeeditor.ts","../corelib/ui/editors/emaileditor.ts","../corelib/ui/editors/emailaddresseditor.ts","../corelib/ui/editors/urleditor.ts","../corelib/ui/editors/radiobuttoneditor.ts","../corelib/globals/select2-module.ts","../corelib/ui/editors/select2editor.ts","../corelib/ui/editors/selecteditor.ts","../corelib/ui/editors/dateyeareditor.ts","../corelib/ui/editors/enumeditor.ts","../corelib/ui/editors/lookupeditor.ts","../corelib/ui/editors/servicelookupeditor.ts","../corelib/ui/editors/htmlcontenteditor.ts","../corelib/ui/editors/maskededitor.ts","../corelib/ui/editors/recaptcha.ts","../corelib/ui/helpers/uploadhelper.ts","../corelib/ui/editors/uploadeditors.ts","../corelib/ui/datagrid/quickfilterbar.ts","../corelib/ui/datagrid/quicksearchinput.ts","../corelib/ui/filtering/filteroperator.ts","../corelib/ui/filtering/filterstore.ts","../corelib/ui/filtering/filtering.ts","../corelib/ui/filtering/filterwidgetbase.ts","../corelib/ui/filtering/filterpanel.ts","../corelib/ui/filtering/filterdialog.ts","../corelib/ui/filtering/filterdisplaybar.ts","../corelib/ui/datagrid/slickpager.ts","../corelib/ui/formatters/formatters.ts","../corelib/types/formattertyperegistry.ts","../corelib/ui/helpers/slickhelpers.ts","../corelib/slick/aggregators.ts","../corelib/slick/remoteview.ts","../corelib/slick/index.ts","../corelib/ui/datagrid/datagrid.ts","../corelib/ui/datagrid/columnpickerdialog.ts","../corelib/ui/datagrid/treegridmixin.ts","../corelib/ui/editors/checktreeeditor.ts","../corelib/ui/datagrid/entitygrid.ts","../corelib/ui/dialogs/entitydialog.ts","../corelib/ui/widgets/jsx.ts","../corelib/ui/widgets/reporting.ts","../corelib/ui/widgets/scriptcontext.ts","../corelib/interfaces/iasyncinit.ts","../corelib/ui/widgets/wx.ts","../corelib/ui/widgets/googlemap.ts","../corelib/ui/editors/select2ajaxeditor.ts","../corelib/index.ts"],"sourcesContent":["/**\n * Tests if any of array elements matches given predicate. Prefer Array.some() over this function (e.g. `[1, 2, 3].some(predicate)`).\n * @param array Array to test.\n * @param predicate Predicate to test elements.\n * @returns True if any element matches.\n */\nexport function any(array: TItem[], predicate: (x: TItem) => boolean): boolean {\n return array.some(predicate);\n}\n\n/**\n * Counts number of array elements that matches a given predicate.\n * @param array Array to test.\n * @param predicate Predicate to test elements.\n */\nexport function count(array: TItem[], predicate: (x: TItem) => boolean): number {\n let count = 0;\n for (let x of array)\n if (predicate(x))\n count++;\n\n return count;\n}\n\n/**\n * Gets first element in an array that matches given predicate similar to LINQ's First.\n * Throws an error if no match is found.\n * @param array Array to test.\n * @param predicate Predicate to test elements.\n * @returns First element that matches.\n */\nexport function first(array: TItem[], predicate: (x: TItem) => boolean): TItem {\n for (let x of array)\n if (predicate(x))\n return x;\n\n throw new Error(\"first:No element satisfies the condition.!\");\n}\n\n/**\n * A group item returned by `groupBy()`.\n */\nexport type GroupByElement = {\n /** index of the item in `inOrder` array */\n order: number;\n /** key of the group */\n key: string;\n /** the items in the group */\n items: TItem[];\n /** index of the first item of this group in the original array */\n start: number;\n}\n\n/**\n * Return type of the `groupBy` function.\n */\nexport type GroupByResult = {\n byKey: { [key: string]: GroupByElement };\n inOrder: GroupByElement[];\n};\n\n/**\n * Groups an array with keys determined by specified getKey() callback.\n * Resulting object contains group objects in order and a dictionary to access by key.\n * This is similar to LINQ's ToLookup function with some additional details like start index.\n * @param items Array to group.\n * @param getKey Function that returns key for each item.\n * @returns GroupByResult object.\n */\nexport function groupBy(items: TItem[], getKey: (x: TItem) => any): GroupByResult {\n let result: GroupByResult = {\n byKey: Object.create(null),\n inOrder: []\n };\n\n for (var index = 0; index < items.length; index++) {\n var item = items[index];\n let key = getKey(item) ?? \"\";\n var group = result.byKey[key];\n if (group === undefined) {\n group = {\n order: result.inOrder.length,\n key: key,\n items: [item],\n start: index\n }\n result.byKey[key] = group;\n result.inOrder.push(group);\n }\n else {\n group.items.push(item);\n }\n }\n\n return result;\n}\n\n/**\n * Gets index of first element in an array that matches given predicate.\n * @param array Array to test.\n * @param predicate Predicate to test elements.\n */\nexport function indexOf(array: TItem[], predicate: (x: TItem) => boolean): number {\n for (var i = 0; i < array.length; i++)\n if (predicate(array[i]))\n return i;\n\n return -1;\n}\n\n/**\n * Inserts an item to the array at specified index. Prefer Array.splice unless\n * you need to support IE.\n * @param obj Array or array like object to insert to.\n * @param index Index to insert at.\n * @param item Item to insert.\n * @throws Error if object does not support insert.\n * @example\n * insert([1, 2, 3], 1, 4); // [1, 4, 2, 3]\n * insert({ insert: (index, item) => { this.splice(index, 0, item); } }\n */\nexport function insert(obj: any, index: number, item: any): void {\n if (obj.insert)\n obj.insert(index, item);\n else if (Array.isArray(obj))\n obj.splice(index, 0, item);\n else\n throw new Error(\"Object does not support insert!\");\n}\n\n/**\n * Determines if the object is an array. Prefer Array.isArray over this function (e.g. `Array.isArray(obj)`).\n * @param obj Object to test.\n * @returns True if the object is an array.\n * @example\n * isArray([1, 2, 3]); // true\n * isArray({}); // false\n */\nexport const isArray = Array.isArray;\n\n/**\n* Gets first element in an array that matches given predicate.\n* Throws an error if no matches is found, or there are multiple matches.\n* @param array Array to test.\n* @param predicate Predicate to test elements.\n* @returns First element that matches.\n* @example\n* first([1, 2, 3], x => x == 2); // 2\n* first([1, 2, 3], x => x == 4); // throws error.\n*/\nexport function single(array: TItem[], predicate: (x: TItem) => boolean): TItem {\n let match: any;\n let found = false;\n for (let x of array)\n if (predicate(x)) {\n if (found)\n throw new Error(\"single:sequence contains more than one element.\");\n\n found = true;\n match = x;\n }\n\n if (!found)\n throw new Error(\"single:No element satisfies the condition.\");\n\n return match;\n}\n\nexport type Grouping = { [key: string]: TItem[] };\n\n/**\n * Maps an array into a dictionary with keys determined by specified getKey() callback,\n * and values that are arrays containing elements for a particular key.\n * @param items Array to map.\n * @param getKey Function that returns key for each item.\n * @returns Grouping object.\n * @example\n * toGrouping([1, 2, 3], x => x % 2 == 0 ? \"even\" : \"odd\"); // { odd: [1, 3], even: [2] }\n */\nexport function toGrouping(items: TItem[], getKey: (x: TItem) => any): Grouping {\n let lookup: Grouping = {};\n for (let x of items) {\n let key = getKey(x) ?? \"\";\n let d = lookup[key];\n if (!d) {\n d = lookup[key] = [];\n }\n\n d.push(x);\n }\n return lookup;\n}\n\n/**\n * Gets first element in an array that matches given predicate (similar to LINQ's FirstOrDefault).\n * Returns null if no match is found.\n * @param array Array to test.\n * @param predicate Predicate to test elements.\n * @returns First element that matches.\n * @example\n * tryFirst([1, 2, 3], x => x == 2); // 2\n * tryFirst([1, 2, 3], x => x == 4); // null\n */\nexport function tryFirst(array: TItem[], predicate: (x: TItem) => boolean): TItem {\n for (let x of array)\n if (predicate(x))\n return x;\n}","export type Dictionary = { [key: string]: TItem };\n\nexport function coalesce(a: any, b: any): any {\n return a != null ? a : b;\n}\n\nexport function isValue(a: any): boolean {\n return a != null;\n}\n\nexport let today = (): Date => {\n var d = new Date();\n return new Date(d.getFullYear(), d.getMonth(), d.getDate());\n}\n\nexport function extend(a: T, b: T): T {\n for (var key in b)\n if (Object.prototype.hasOwnProperty.call(b, key))\n a[key] = b[key];\n return a;\n}\n\nexport function deepClone(a: T, a2?: any, a3?: any): T {\n // for backward compatibility\n if (a2 != null || a3 != null) {\n return extend(extend(deepClone(a || {}), deepClone(a2 || {})), deepClone(a3 || {}));\n }\n\n // https://github.com/angus-c/just/blob/master/packages/collection-clone/index.js\n var result = a;\n var type = {}.toString.call(a).slice(8, -1);\n if (type == 'Set') {\n return new Set([...(a as any)].map(value => deepClone(value))) as any;\n }\n if (type == 'Map') {\n return new Map([...(a as any)].map(kv => [deepClone(kv[0]), deepClone(kv[1])])) as any;\n }\n if (type == 'Date') {\n return new Date((a as any).getTime()) as any;\n }\n if (type == 'RegExp') {\n return RegExp((a as any).source, getRegExpFlags(a as any)) as any;\n }\n if (type == 'Array' || type == 'Object') {\n result = (Array.isArray(a) ? [] : {}) as any;\n for (var key in a) {\n // include prototype properties\n result[key] = deepClone(a[key]);\n }\n }\n // primitives and non-supported objects (e.g. functions) land here\n return result;\n}\n\nfunction getRegExpFlags(regExp: RegExp) {\n if (typeof (regExp.source as any).flags == 'string') {\n return (regExp.source as any).flags;\n } else {\n var flags = [];\n regExp.global && flags.push('g');\n regExp.ignoreCase && flags.push('i');\n regExp.multiline && flags.push('m');\n regExp.sticky && flags.push('y');\n regExp.unicode && flags.push('u');\n return flags.join('');\n }\n}\n\ninterface TypeExt {\n __interface?: boolean;\n __interfaces?: any[];\n __isAssignableFrom?: (from: any) => boolean;\n __isInstanceOfType?: (instance: any) => boolean;\n __metadata?: TypeMetadata;\n __typeName?: string;\n}\n\ninterface TypeMetadata {\n enumFlags?: boolean;\n attr?: any[];\n members?: TypeMember[];\n}\n\nexport type Type = Function | Object;\n\nexport interface TypeMember {\n name: string;\n type: MemberType;\n attr?: any[];\n getter?: string;\n setter?: string;\n}\n\nfunction getTypeStore() {\n return getStateStore(\"__types\");\n}\n\nexport function getNested(from: any, name: string) {\n var a = name.split('.');\n for (var i = 0; i < a.length; i++) {\n from = from[a[i]];\n if (from == null)\n return null;\n }\n return from;\n}\n\nconst globalObj: any = \n (typeof globalThis !== \"undefined\" && globalThis) || \n (typeof window !== \"undefined\" && window) || \n (typeof self !== \"undefined\" && self) ||\n // @ts-ignore check for global\n (typeof global !== \"undefined\" && global) ||\n (function () { return this; })() || Function('return this')();\n\nexport function getGlobalThis(): any {\n return globalObj;\n}\n\nexport function getType(name: string, target?: any): Type {\n var type: any;\n const types = getTypeStore();\n if (target == null) {\n type = types[name];\n if (type != null || globalObj == void 0 || name === \"Object\")\n return type;\n\n target = globalObj;\n }\n\n type = getNested(target, name)\n if (typeof type !== 'function')\n return null;\n\n return type;\n}\n\nexport function getTypeNameProp(type: Type): string {\n return (Object.prototype.hasOwnProperty.call(type, \"__typeName\") && (type as TypeExt).__typeName) || void 0;\n}\n\nexport function setTypeNameProp(type: Type, value: string) {\n Object.defineProperty(type, \"__typeName\", { value, configurable: true });\n}\n\nexport function getTypeFullName(type: Type): string {\n return getTypeNameProp(type) || (type as any).name ||\n (type.toString().match(/^\\s*function\\s*([^\\s(]+)/) || [])[1] || 'Object';\n};\n\nexport function getTypeShortName(type: Type): string {\n var fullName = getTypeFullName(type);\n var bIndex = fullName.indexOf('[');\n var nsIndex = fullName.lastIndexOf('.', bIndex >= 0 ? bIndex : fullName.length);\n return nsIndex > 0 ? fullName.substr(nsIndex + 1) : fullName;\n};\n\nexport function getInstanceType(instance: any): any {\n if (instance == null)\n throw new ArgumentNullException(\"instance\", \"Can't get instance type of null or undefined!\");\n\n // Have to catch as constructor cannot be looked up on native COM objects\n try {\n return instance.constructor;\n }\n catch (ex) {\n return Object;\n }\n};\n\nexport function isAssignableFrom(target: any, type: Type) {\n if (target === type || (type as any).prototype instanceof target)\n return true;\n\n if (typeof (target as TypeExt).__isAssignableFrom === 'function')\n return (target as TypeExt).__isAssignableFrom(type);\n\n return false;\n};\n\nexport function isInstanceOfType(instance: any, type: Type) {\n if (instance == null)\n return false;\n\n if (typeof (type as TypeExt).__isInstanceOfType === 'function')\n return (type as TypeExt).__isInstanceOfType(instance);\n\n return isAssignableFrom(type, getInstanceType(instance));\n};\n\nexport function safeCast(instance: any, type: Type) {\n return isInstanceOfType(instance, type) ? instance : null;\n};\n\nexport function cast(instance: any, type: Type) {\n if (instance == null)\n return instance;\n else if (isInstanceOfType(instance, type))\n return instance;\n throw new InvalidCastException('Cannot cast object to type ' + getTypeFullName(type));\n}\n\nexport function getBaseType(type: any) {\n if (type === Object ||\n !type.prototype ||\n (type as TypeExt).__interface === true) {\n return null;\n }\n else if (Object.getPrototypeOf) {\n return Object.getPrototypeOf(type.prototype).constructor;\n }\n else {\n var p = type.prototype;\n if (Object.prototype.hasOwnProperty.call(p, 'constructor')) {\n try {\n var ownValue = p.constructor;\n delete p.constructor;\n return p.constructor;\n }\n finally {\n p.constructor = ownValue;\n }\n }\n return p.constructor;\n }\n};\n\nexport function getAttributes(type: any, attrType: any, inherit?: boolean) {\n var result = [];\n if (inherit) {\n var b = getBaseType(type);\n if (b) {\n var a: any = getAttributes(b, attrType, true);\n for (var i = 0; i < a.length; i++) {\n var t = getInstanceType(a[i]);\n result.push(a[i]);\n }\n }\n }\n var attr = (type as TypeExt).__metadata?.attr;\n if (attr != null) {\n for (var i = 0; i < attr.length; i++) {\n var a: any = attr[i];\n if (attrType == null || isInstanceOfType(a, attrType)) {\n var t = getInstanceType(a);\n for (var j = result.length - 1; j >= 0; j--) {\n if (isInstanceOfType(result[j], t))\n result.splice(j, 1);\n }\n result.push(a);\n }\n }\n }\n return result;\n};\n\nexport enum MemberType {\n field = 4,\n property = 16\n}\n\nexport function getMembers(type: any, memberTypes: MemberType): TypeMember[] {\n var result: TypeMember[] = [];\n var b = getBaseType(type);\n if (b)\n result = getMembers(b, memberTypes & ~1);\n\n var members = (type as TypeExt).__metadata?.members;\n if (members != null) {\n for (var m of members) {\n if (memberTypes & m.type)\n result.push(m);\n }\n }\n\n return result;\n};\n\nexport function addTypeMember(type: any, member: TypeMember): TypeMember {\n\n var name = member.name;\n var md = ensureMetadata(type);\n md.members = md.members || [];\n\n let existing: TypeMember;\n for (var m of md.members) {\n if (m.name == name) {\n existing = m;\n break;\n }\n }\n\n if (existing) {\n if (member.type != null)\n existing.type = member.type;\n if (member.attr != null)\n existing.attr = merge(existing.attr, member.attr);\n if (member.getter != null)\n existing.getter = member.getter;\n if (member.setter != null)\n existing.setter = member.setter;\n return existing;\n }\n else {\n md.members.push(member);\n return member;\n }\n}\n\nexport function getTypes(from?: any): any[] {\n const types = getTypeStore();\n var result = [];\n if (!from) {\n for (var t in types) {\n if (Object.prototype.hasOwnProperty.call(types, t))\n result.push(types[t]);\n }\n }\n else {\n var traverse = function (s: any, n: string) {\n for (var c in s) {\n if (Object.prototype.hasOwnProperty.call(s, c))\n traverse(s[c], c);\n }\n if (typeof (s) === 'function' &&\n n.charAt(0).toUpperCase() === n.charAt(0) &&\n n.charAt(0).toLowerCase() !== n.charAt(0))\n result.push(s);\n };\n traverse(from, '');\n }\n return result;\n};\n\nexport function clearKeys(d: any) {\n for (var n in d) {\n if (Object.prototype.hasOwnProperty.call(d, n))\n delete d[n];\n }\n}\n\nexport function delegateCombine(delegate1: any, delegate2: any) {\n if (!delegate1) {\n if (!delegate2._targets) {\n return delegate2;\n }\n return delegate2;\n }\n if (!delegate2) {\n if (!delegate1._targets) {\n return delegate1;\n }\n return delegate1;\n }\n\n var targets1 = delegate1._targets ? delegate1._targets : [null, delegate1];\n var targets2 = delegate2._targets ? delegate2._targets : [null, delegate2];\n\n return _mkdel(targets1.concat(targets2));\n};\n\nconst fallbackStore: any = {};\n\n\nexport function getStateStore(key?: string): any {\n\n let store: any;\n if (globalObj) {\n if (!globalObj.Q)\n globalObj.Q = {};\n\n store = globalObj.Q.__stateStore;\n if (!store)\n globalObj.Q.__stateStore = store = Object.create(null);\n }\n else\n store = fallbackStore;\n\n if (key == null)\n return store;\n\n var s = store[key];\n if (s == null)\n store[key] = s = Object.create(null);\n return s;\n}\n\nexport namespace Enum {\n export let toString = (enumType: any, value: number): string => {\n var values = enumType;\n if (value === 0 || !((enumType as TypeExt).__metadata?.enumFlags)) {\n for (var i in values) {\n if (values[i] === value) {\n return i;\n }\n }\n return value == null ? \"\" : value.toString();\n }\n else {\n var parts: string[] = [];\n for (var i in values) {\n if (values[i] & value) {\n parts.push(i);\n }\n else\n parts.push(value == null ? \"\" : value.toString());\n }\n return parts.join(' | ');\n }\n };\n\n export let getValues = (enumType: any) => {\n var parts = [];\n var values = enumType;\n for (var i in values) {\n if (Object.prototype.hasOwnProperty.call(values, i) &&\n typeof values[i] === \"number\")\n parts.push(values[i]);\n }\n return parts;\n };\n}\n\nfunction delegateContains(targets: any[], object: any, method: any) {\n for (var i = 0; i < targets.length; i += 2) {\n if (targets[i] === object && targets[i + 1] === method) {\n return true;\n }\n }\n return false;\n};\n\n\nlet _mkdel = (targets: any[]): any => {\n var delegate: any = function () {\n if (targets.length === 2) {\n return targets[1].apply(targets[0], arguments);\n }\n else {\n var clone = targets.slice();\n for (var i = 0; i < clone.length; i += 2) {\n if (delegateContains(targets, clone[i], clone[i + 1])) {\n clone[i + 1].apply(clone[i], arguments);\n }\n }\n return null;\n }\n };\n delegate._targets = targets;\n\n return delegate;\n};\n\nexport let delegateRemove = (delegate1: any, delegate2: any) => {\n if (!delegate1 || (delegate1 === delegate2)) {\n return null;\n }\n if (!delegate2) {\n return delegate1;\n }\n\n var targets = delegate1._targets;\n var object = null;\n var method;\n if (delegate2._targets) {\n object = delegate2._targets[0];\n method = delegate2._targets[1];\n }\n else {\n method = delegate2;\n }\n\n for (var i = 0; i < targets.length; i += 2) {\n if ((targets[i] === object) && (targets[i + 1] === method)) {\n if (targets.length === 2) {\n return null;\n }\n var t = targets.slice();\n t.splice(i, 2);\n return _mkdel(t);\n }\n }\n\n return delegate1;\n};\n\nexport let isEnum = (type: any) => {\n return typeof type !== \"function\" &&\n (type as TypeExt).__interface === null;\n};\n\nexport function initFormType(typ: Function, nameWidgetPairs: any[]) {\n for (var i = 0; i < nameWidgetPairs.length - 1; i += 2) {\n (function (name: string, widget: any) {\n Object.defineProperty(typ.prototype, name, {\n get: function () {\n return this.w(name, widget);\n },\n enumerable: true,\n configurable: true\n });\n })(nameWidgetPairs[i], nameWidgetPairs[i + 1]);\n }\n}\n\nexport function prop(type: any, name: string, getter?: string, setter?: string) {\n getter = getter || \"get_\" + name;\n setter = setter || \"set_\" + name;\n\n Object.defineProperty(type.prototype, name, {\n get: function () {\n return this[getter]();\n },\n set: function (value) {\n return this[setter](value);\n },\n configurable: true,\n enumerable: true\n });\n}\n\nfunction ensureMetadata(target: Type): TypeMetadata {\n\n if (!Object.prototype.hasOwnProperty.call(target, '__metadata') ||\n !(target as TypeExt).__metadata) {\n (target as TypeExt).__metadata = Object.create(null);\n }\n\n return (target as TypeExt).__metadata;\n}\n\nfunction distinct(arr: any[]) {\n return arr.filter((item, pos) => arr.indexOf(item) === pos);\n}\n\nconst _fieldsProxy = new Proxy({}, { get: (_, p) => p }) as any;\n\nexport function fieldsProxy(): Readonly> {\n return _fieldsProxy\n}\n\nexport function keyOf(prop: keyof T) {\n return prop;\n}\n\nfunction merge(arr1: any[], arr2: any[]) {\n if (!arr1 || !arr2)\n return (arr1 || arr2 || []).slice();\n\n return distinct(arr1.concat(arr2));\n}\n\nfunction interfaceIsAssignableFrom(from: any) {\n return from != null && \n Array.isArray((from as TypeExt).__interfaces) && \n (from as TypeExt).__interfaces.some(x => \n x === this ||\n (getTypeNameProp(this)?.length && \n x.__interface &&\n getTypeNameProp(x) === this.__typeName));\n}\n\nfunction registerType(type: any, name: string, intf: any[]) {\n const types = getTypeStore();\n if (name && name.length) {\n setTypeNameProp(type, name);\n types[name] = type;\n }\n else if (getTypeNameProp(type as TypeExt)?.length)\n types[(type as TypeExt).__typeName] = type;\n\n if (intf != null && intf.length)\n Object.defineProperty(type, \"__interfaces\", {\n value: merge((type as TypeExt).__interfaces, intf),\n configurable: true\n });\n}\n\nexport function registerClass(type: any, name: string, intf?: any[]) {\n registerType(type, name, intf);\n Object.defineProperty(type, \"__interface\", { value: false, configurable: true });\n}\n\nexport function registerEditor(type: any, name: string, intf?: any[]) {\n registerClass(type, name, intf);\n addAttribute(type, new EditorAttribute());\n}\n\nexport function registerEnum(type: any, name: string, enumKey?: string) {\n registerType(type, name, undefined);\n if (enumKey && enumKey != name) {\n const types = getTypeStore();\n if (!types[enumKey])\n types[enumKey] = type;\n }\n Object.defineProperty(type, \"__interface\", { value: null, configurable: true });\n}\n\nexport function registerInterface(type: any, name: string, intf?: any[]) {\n registerType(type, name, intf);\n Object.defineProperty(type, \"__interface\", { value: true, configurable: true });\n Object.defineProperty(type, \"__isAssignableFrom\", { value: interfaceIsAssignableFrom, configurable: true });\n}\n\nexport function addAttribute(type: any, attr: any) {\n var md = ensureMetadata(type);\n md.attr = md.attr || [];\n md.attr.push(attr);\n}\n\nexport class ISlickFormatter {\n}\n\nregisterInterface(ISlickFormatter, 'Serenity.ISlickFormatter');\n\nexport class EditorAttribute {\n}\n\nregisterClass(EditorAttribute, 'Serenity.EditorAttribute');\n\nexport function initializeTypes(root: any, pre: string, limit: number) {\n\n if (!root)\n return;\n\n const types = getTypeStore();\n\n for (var k of Object.keys(root)) {\n if (k.charAt(0) < 'A' || \n k.charAt(0) > 'Z' || \n k.indexOf('$') >= 0 || \n !Object.prototype.hasOwnProperty.call(root, k))\n continue;\n\n var obj = root[k];\n\n if (obj == void 0 ||\n Array.isArray(obj) ||\n obj instanceof Date ||\n (typeof obj != \"function\" &&\n typeof obj != \"object\"))\n continue;\n\n // no explict __typeName, e.g. not registered with a name,\n // a function but not an html element, or registered without name\n if (!getTypeNameProp(obj) && \n ((typeof obj === \"function\" && typeof obj.nodeType !== \"number\") || \n (Object.prototype.hasOwnProperty.call(obj, \"__interface\") &&\n (obj as TypeExt).__interface !== undefined))) {\n \n // legacy formatter with registerClass\n if (typeof obj == \"function\" && \n !obj.__interfaces && \n obj.prototype?.format &&\n k.substr(-9) === \"Formatter\") {\n if ((obj as TypeExt).__interface === undefined)\n Object.defineProperty(obj, \"__interface\", { value: false, configurable: true });\n (obj as TypeExt).__interfaces = [ISlickFormatter]\n }\n\n // only register types that should\n if ((obj as TypeExt).__interface !== undefined) {\n setTypeNameProp(obj, pre + k);\n types[pre + k] = obj;\n }\n }\n \n if (limit > 0) \n initializeTypes(obj, pre + k + \".\", limit - 1);\n }\n}\n\nexport class Exception extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"Exception\";\n }\n}\n\nexport class ArgumentNullException extends Exception {\n constructor(paramName: string, message?: string) {\n super((message || 'Value cannot be null.') + '\\nParameter name: ' + paramName);\n this.name = \"ArgumentNullException\";\n }\n}\n\nexport class InvalidCastException extends Exception {\n constructor(message: string) {\n super(message);\n this.name = \"InvalidCastException\";\n }\n}\n\nexport {}","/**\n * Checks if the string ends with the specified substring.\n * @param s String to check.\n * @param suffix Suffix to check.\n * @returns True if the string ends with the specified substring.\n */\nexport function endsWith(s: string, suffix: string): boolean {\n return s.endsWith(suffix);\n}\n\n/**\n * Checks if the string is empty or null.\n * @param s String to check.\n * @returns True if the string is empty or null.\n */\nexport function isEmptyOrNull(s: string) {\n return s == null || s.length === 0;\n}\n\n/**\n * Checks if the string is empty or null or whitespace.\n * @param s String to check.\n * @returns True if the string is empty or null or whitespace.\n */\nexport function isTrimmedEmpty(s: string) {\n return trimToNull(s) == null;\n}\n\n/**\n * Pads the string to the left with the specified character.\n * @param s String to pad.\n * @param len Target length of the string.\n * @param ch Character to pad with.\n * @returns Padded string.\n */\nexport function padLeft(s: string | number, len: number, ch: string = ' ') {\n s = s == null ? '' : s.toString();\n if ((s as any).padStart)\n return (s as any).padStart(len, ch);\n while (s.length < len)\n s = ch + s;\n return s;\n}\n\n/**\n * Checks if the string starts with the prefix\n * @param s String to check.\n * @param prefix Prefix to check.\n * @returns True if the string starts with the prefix.\n */\nexport function startsWith(s: string, prefix: string): boolean {\n return s.startsWith(prefix);\n}\n\n/**\n * Converts the string to single line by removing line end characters\n * @param str String to convert.\n */\nexport function toSingleLine(str: string) {\n return replaceAll(replaceAll(trimToEmpty(str), '\\r\\n', ' '), '\\n', ' ').trim();\n}\n\n/**\n * Trims the whitespace characters from the end of the string\n */\nexport var trimEnd = function(s: string) {\n return (s ?? \"\" as any).trimEnd?.() ?? s.replace(/\\s*$/, '');\n};\n\n/**\n * Trims the whitespace characters from the start of the string\n */\nexport var trimStart = function(s: string) {\n return (s ?? \"\" as any).trimStart?.() ?? s.replace(/^\\s*/, '');\n};\n\n/**\n * Trims the whitespace characters from the start and end of the string\n * This returns empty string even when the string is null or undefined.\n */\nexport function trim(s: string) {\n return s?.trim() ?? '';\n}\n\n/**\n * Trims the whitespace characters from the start and end of the string\n * Returns empty string if the string is null or undefined.\n */\nexport function trimToEmpty(s: string) {\n return (s ?? \"\").trim();\n}\n\n/**\n * Trims the whitespace characters from the start and end of the string\n * Returns null if the string is null, undefined or whitespace.\n */\nexport function trimToNull(s: string) {\n if (s == null)\n return null;\n s = trim(s);\n return s.length === 0 ? null : s;\n}\n\n/**\n * Replaces all occurrences of the search string with the replacement string.\n * @param str String to replace.\n * @param find String to find.\n * @param replace String to replace with.\n * @returns Replaced string.\n */\nexport function replaceAll(str: string, find: string, replace: string): string {\n str = str || '';\n return (str as any).replaceAll?.(find, replace) ?? str.split(find).join(replace);\n}\n\n/**\n * Pads the start of string to make it the specified length.\n * @param s String to pad.\n * @param len Target length of the string.\n */\nexport function zeroPad(n: number, len: number): string {\n if (n == null)\n return \"\";\n let s = n.toString();\n while (s.length < len)\n s = \"0\" + s;\n return s;\n}","import { getStateStore } from \"./system\";\nimport { isEmptyOrNull, startsWith } from \"./strings\";\n\nexport function localText(key: string): string {\n let t: string = getTable()[key];\n if (t == null) {\n t = key ?? '';\n }\n return t;\n}\n\n/** @obsolete prefer localText for better discoverability */\nexport const text = localText;\n\nexport function dbText(prefix: string): ((key: string) => string) {\n return function (key: string) {\n return localText(\"Db.\" + prefix + \".\" + key);\n }\n}\n\nfunction getTable(): { [key: string]: string } {\n return getStateStore(\"__localText\");\n}\n\nexport function prefixedText(prefix: string) {\n\n return function (text: string, key: string | ((p?: string) => string)) {\n\n if (text != null && !startsWith(text, '`')) {\n var local = tryGetText(text);\n if (local != null) {\n return local;\n }\n }\n\n if (text != null && startsWith(text, '`')) {\n text = text.substr(1);\n }\n\n if (!isEmptyOrNull(prefix)) {\n var textKey = typeof (key) == \"function\" ? key(prefix) : (prefix + key);\n var localText = tryGetText(textKey);\n if (localText != null) {\n return localText;\n }\n }\n\n return text;\n }\n}\n\nexport function tryGetText(key: string): string {\n var value = getTable()[key];\n return value;\n}\n\nexport function dbTryText(prefix: string): ((key: string) => string) {\n return function (key: string) {\n return localText(\"Db.\" + prefix + \".\" + key);\n }\n}\n\nexport function proxyTexts(o: Record, p: string, t: Record): Object {\n if (typeof window != 'undefined' && window['Proxy']) {\n return new window['Proxy'](o, {\n get: (x: Object, y: string) => {\n var tv = t[y];\n if (tv == null)\n return;\n if (typeof tv == 'number')\n return localText(p + y);\n else {\n var z = o[y];\n if (z != null)\n return z;\n o[y] = z = proxyTexts({}, p + y + '.', tv);\n return z;\n }\n },\n ownKeys: (x: Object) => Object.keys(t)\n });\n }\n else {\n for (var k of Object.keys(t)) {\n if (typeof t[k] == 'number')\n Object.defineProperty(o, k, {\n get: () => localText(p + k)\n });\n else\n o[k] = proxyTexts({}, p + k + '.', t[k]);\n }\n return o;\n }\n}\n\nexport class LT {\n static empty: LT = new LT('');\n\n constructor(private key: string) {\n }\n\n static add(key: string, value: string): void;\n static add(obj: any, pre?: string) {\n if (!obj) {\n return;\n }\n \n let table = getTable();\n\n if (typeof obj === \"string\") {\n table[obj] = pre;\n return;\n }\n\n pre = pre || '';\n for (let k of Object.keys(obj)) {\n let actual = pre + k;\n let o = obj[k];\n if (typeof (o) === 'object') {\n LT.add(o, actual + '.');\n }\n else {\n table[actual] = o;\n }\n }\n }\n\n get() {\n var t = getTable()[this.key];\n if (t == null) {\n t = this.key || '';\n }\n return t;\n }\n\n toString() {\n var t = getTable()[this.key];\n if (t == null) {\n t = this.key || '';\n }\n return t;\n }\n\n static initializeTextClass = function (type: any, prefix: string) {\n var $t1 = Object.keys(type).slice();\n var table = getTable();\n for (var $t2 = 0; $t2 < $t1.length; $t2++) {\n var member = $t1[$t2];\n var value = type[member];\n if (value instanceof LT) {\n var lt = value;\n var key = prefix + member;\n table[key] = lt.key;\n type[member] = new LT(key);\n }\n }\n }\n\n static getDefault = function (key: string, defaultText: string) {\n var t = getTable()[key];\n if (t == null) {\n t = defaultText;\n if (t == null) {\n t = key || '';\n }\n }\n return t;\n }\n}\n\nif (typeof globalThis !== \"undefined\") {\n const Q = (globalThis as any).Q || ((globalThis as any).Q = {});\n if (Q.LT == null)\n Q.LT = LT;\n}","/// \nconst $: JQueryStatic = typeof jQuery === \"function\" ? jQuery : typeof globalThis.$ === \"function\" ? globalThis.$ :\n typeof window !== \"undefined\" ? (window.jQuery ?? window.$) : undefined;\n\nexport default $;","import { localText } from \"./localtext\";\nimport $ from \"@optionaldeps/jquery\";\n\n/**\n * Adds an empty option to the select.\n * @param select the select element\n */\nexport function addEmptyOption(select: JQuery | HTMLSelectElement) {\n addOption(select, '', localText(\"Controls.SelectEditor.EmptyItemText\"));\n}\n\n/**\n * Adds an option to the select.\n */\nexport function addOption(select: JQuery | HTMLSelectElement, key: string, text: string) {\n $('