{"version":3,"file":"Utility.js","sources":["../../Framework/Utility/http.ts","../../Framework/Utility/address.ts","../../Framework/Utility/arrayUtils.ts","../../Framework/Utility/linq.ts","../../Framework/Utility/guid.ts","../../Framework/Utility/stringUtils.ts","../../Framework/Utility/aspDateFormat.ts","../../Framework/Utility/rockDateTime.ts","../../Framework/Utility/block.ts","../../Framework/Utility/booleanUtils.ts","../../Framework/Utility/bus.ts","../../Framework/Utility/cache.ts","../../Framework/Utility/cancellation.ts","../../Framework/Utility/util.ts","../../Framework/Utility/suspense.ts","../../Framework/Utility/numberUtils.ts","../../Framework/Utility/component.ts","../../Framework/Utility/dateKey.ts","../../Framework/Utility/page.ts","../../Framework/Utility/dialogs.ts","../../Framework/Utility/email.ts","../../Framework/Utility/enumUtils.ts","../../Framework/Utility/fieldTypes.ts","../../Framework/Utility/form.ts","../../Framework/Utility/fullscreen.ts","../../Framework/Utility/geo.ts","../../Framework/Utility/internetCalendar.ts","../../Framework/Utility/lava.ts","../../Framework/Utility/listItemBag.ts","../../Framework/Utility/mergeField.ts","../../Framework/Utility/objectUtils.ts","../../Framework/Utility/phone.ts","../../Framework/Utility/popover.ts","../../Framework/Utility/promiseUtils.ts","../../Framework/Utility/realTime.ts","../../Framework/Utility/slidingDateRange.ts","../../Framework/Utility/structuredContentEditor.ts","../../Framework/Utility/tooltip.ts","../../Framework/Utility/treeItemProviders.ts","../../Framework/Utility/url.ts","../../Framework/Utility/validationRules.ts"],"sourcesContent":["// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport axios, { AxiosResponse } from \"axios\";\r\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\nimport { HttpBodyData, HttpMethod, HttpFunctions, HttpResult, HttpUrlParams } from \"@Obsidian/Types/Utility/http\";\r\nimport { inject, provide, getCurrentInstance } from \"vue\";\r\n\r\n\r\n// #region HTTP Requests\r\n\r\n/**\r\n * Make an API call. This is only place Axios (or AJAX library) should be referenced to allow tools like performance metrics to provide\r\n * better insights.\r\n * @param method\r\n * @param url\r\n * @param params\r\n * @param data\r\n */\r\nasync function doApiCallRaw(method: HttpMethod, url: string, params: HttpUrlParams, data: HttpBodyData): Promise> {\r\n return await axios({\r\n method,\r\n url,\r\n params,\r\n data\r\n });\r\n}\r\n\r\n/**\r\n * Make an API call. This is a special use function that should not\r\n * normally be used. Instead call useHttp() to get the HTTP functions that\r\n * can be used.\r\n *\r\n * @param {string} method The HTTP method, such as GET\r\n * @param {string} url The endpoint to access, such as /api/campuses/\r\n * @param {object} params Query parameter object. Will be converted to ?key1=value1&key2=value2 as part of the URL.\r\n * @param {any} data This will be the body of the request\r\n */\r\nexport async function doApiCall(method: HttpMethod, url: string, params: HttpUrlParams = undefined, data: HttpBodyData = undefined): Promise> {\r\n try {\r\n const result = await doApiCallRaw(method, url, params, data);\r\n\r\n return {\r\n data: result.data as T,\r\n isError: false,\r\n isSuccess: true,\r\n statusCode: result.status,\r\n errorMessage: null\r\n } as HttpResult;\r\n }\r\n catch (e) {\r\n if (axios.isAxiosError(e)) {\r\n if (e.response?.data?.Message || e?.response?.data?.message) {\r\n return {\r\n data: null,\r\n isError: true,\r\n isSuccess: false,\r\n statusCode: e.response.status,\r\n errorMessage: e?.response?.data?.Message ?? e.response.data.message\r\n } as HttpResult;\r\n }\r\n\r\n return {\r\n data: null,\r\n isError: true,\r\n isSuccess: false,\r\n statusCode: e.response?.status ?? 0,\r\n errorMessage: null\r\n } as HttpResult;\r\n }\r\n else {\r\n return {\r\n data: null,\r\n isError: true,\r\n isSuccess: false,\r\n statusCode: 0,\r\n errorMessage: null\r\n } as HttpResult;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Make a GET HTTP request. This is a special use function that should not\r\n * normally be used. Instead call useHttp() to get the HTTP functions that\r\n * can be used.\r\n *\r\n * @param {string} url The endpoint to access, such as /api/campuses/\r\n * @param {object} params Query parameter object. Will be converted to ?key1=value1&key2=value2 as part of the URL.\r\n */\r\nexport async function get(url: string, params: HttpUrlParams = undefined): Promise> {\r\n return await doApiCall(\"GET\", url, params, undefined);\r\n}\r\n\r\n/**\r\n * Make a POST HTTP request. This is a special use function that should not\r\n * normally be used. Instead call useHttp() to get the HTTP functions that\r\n * can be used.\r\n *\r\n * @param {string} url The endpoint to access, such as /api/campuses/\r\n * @param {object} params Query parameter object. Will be converted to ?key1=value1&key2=value2 as part of the URL.\r\n * @param {any} data This will be the body of the request\r\n */\r\nexport async function post(url: string, params: HttpUrlParams = undefined, data: HttpBodyData = undefined): Promise> {\r\n return await doApiCall(\"POST\", url, params, data);\r\n}\r\n\r\nconst httpFunctionsSymbol = Symbol(\"http-functions\");\r\n\r\n/**\r\n * Provides the HTTP functions that child components will use. This is an\r\n * internal API and should not be used by third party components.\r\n *\r\n * @param functions The functions that will be made available to child components.\r\n */\r\nexport function provideHttp(functions: HttpFunctions): void {\r\n provide(httpFunctionsSymbol, functions);\r\n}\r\n\r\n/**\r\n * Gets the HTTP functions that can be used by the component. This is the\r\n * standard way to make HTTP requests.\r\n *\r\n * @returns An object that contains the functions which can be called.\r\n */\r\nexport function useHttp(): HttpFunctions {\r\n let http: HttpFunctions | undefined;\r\n\r\n // Check if we are inside a setup instance. This prevents warnings\r\n // from being displayed if being called outside a setup() function.\r\n if (getCurrentInstance()) {\r\n http = inject(httpFunctionsSymbol);\r\n }\r\n\r\n return http || {\r\n doApiCall: doApiCall,\r\n get: get,\r\n post: post\r\n };\r\n}\r\n\r\n// #endregion\r\n\r\n// #region File Upload\r\n\r\ntype FileUploadResponse = {\r\n /* eslint-disable @typescript-eslint/naming-convention */\r\n Guid: Guid;\r\n FileName: string;\r\n /* eslint-enable */\r\n};\r\n\r\n/**\r\n * Progress reporting callback used when uploading a file into Rock.\r\n */\r\nexport type UploadProgressCallback = (progress: number, total: number, percent: number) => void;\r\n\r\n/**\r\n * Options used when uploading a file into Rock to change the default behavior.\r\n */\r\nexport type UploadOptions = {\r\n /**\r\n * The base URL to use when uploading the file, must accept the same parameters\r\n * and as the standard FileUploader.ashx handler.\r\n */\r\n baseUrl?: string;\r\n\r\n /** True if the file should be uploaded as temporary, only applies to binary files. */\r\n isTemporary?: boolean;\r\n\r\n /** A function to call to report the ongoing progress of the upload. */\r\n progress: UploadProgressCallback;\r\n};\r\n\r\n/**\r\n * Uploads a file in the form data into Rock. This is an internal function and\r\n * should not be exported.\r\n *\r\n * @param url The URL to use for the POST request.\r\n * @param data The form data to send in the request body.\r\n * @param progress The optional callback to use to report progress.\r\n *\r\n * @returns The response from the upload handler.\r\n */\r\nasync function uploadFile(url: string, data: FormData, progress: UploadProgressCallback | undefined): Promise {\r\n const result = await axios.post(url, data, {\r\n headers: {\r\n \"Content-Type\": \"multipart/form-data\"\r\n },\r\n onUploadProgress: (event: ProgressEvent) => {\r\n if (progress) {\r\n progress(event.loaded, event.total, Math.floor(event.loaded * 100 / event.total));\r\n }\r\n }\r\n });\r\n\r\n // Check for a \"everything went perfectly fine\" response.\r\n if (result.status === 200 && typeof result.data === \"object\") {\r\n return result.data;\r\n }\r\n\r\n if (result.status === 406) {\r\n throw \"File type is not allowed.\";\r\n }\r\n\r\n if (typeof result.data === \"string\") {\r\n throw result.data;\r\n }\r\n\r\n throw \"Upload failed.\";\r\n}\r\n\r\n/**\r\n * Uploads a file to the Rock file system, usually inside the ~/Content directory.\r\n *\r\n * @param file The file to be uploaded to the server.\r\n * @param encryptedRootFolder The encrypted root folder specified by the server,\r\n * this specifies the jail the upload operation is limited to.\r\n * @param folderPath The additional sub-folder path to use inside the root folder.\r\n * @param options The options to use when uploading the file.\r\n *\r\n * @returns A ListItemBag that contains the scrubbed filename that was uploaded.\r\n */\r\nexport async function uploadContentFile(file: File, encryptedRootFolder: string, folderPath: string, options?: UploadOptions): Promise {\r\n const url = `${options?.baseUrl ?? \"/FileUploader.ashx\"}?rootFolder=${encryptedRootFolder}`;\r\n const formData = new FormData();\r\n\r\n formData.append(\"file\", file);\r\n\r\n if (folderPath) {\r\n formData.append(\"folderPath\", folderPath);\r\n }\r\n\r\n const result = await uploadFile(url, formData, options?.progress);\r\n\r\n return {\r\n value: \"\",\r\n text: result.FileName\r\n };\r\n}\r\n\r\n/**\r\n * Uploads a BinaryFile into Rock. The specific storage location is defined by\r\n * the file type.\r\n *\r\n * @param file The file to be uploaded into Rock.\r\n * @param binaryFileTypeGuid The unique identifier of the BinaryFileType to handle the upload.\r\n * @param options The options ot use when uploading the file.\r\n *\r\n * @returns A ListItemBag whose value contains the new file Guid and text specifies the filename.\r\n */\r\nexport async function uploadBinaryFile(file: File, binaryFileTypeGuid: Guid, options?: UploadOptions): Promise {\r\n let url = `${options?.baseUrl ?? \"/FileUploader.ashx\"}?isBinaryFile=True&fileTypeGuid=${binaryFileTypeGuid}`;\r\n\r\n // Assume file is temporary unless specified otherwise so that files\r\n // that don't end up getting used will get cleaned up.\r\n if (options?.isTemporary === false) {\r\n url += \"&isTemporary=False\";\r\n }\r\n else {\r\n url += \"&isTemporary=True\";\r\n }\r\n\r\n const formData = new FormData();\r\n formData.append(\"file\", file);\r\n\r\n const result = await uploadFile(url, formData, options?.progress);\r\n\r\n return {\r\n value: result.Guid,\r\n text: result.FileName\r\n };\r\n}\r\n\r\n// #endregion\r\n\r\nexport default {\r\n doApiCall,\r\n post,\r\n get\r\n};\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { HttpResult } from \"@Obsidian/Types/Utility/http\";\r\nimport { AddressControlBag } from \"@Obsidian/ViewModels/Controls/addressControlBag\";\r\nimport { AddressControlValidateAddressOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/AddressControlValidateAddressOptionsBag\";\r\nimport { AddressControlValidateAddressResultsBag } from \"@Obsidian/ViewModels/Rest/Controls/AddressControlValidateAddressResultsBag\";\r\nimport { post } from \"./http\";\r\n\r\nexport function getDefaultAddressControlModel(): AddressControlBag {\r\n return {\r\n state: \"AZ\",\r\n country: \"US\"\r\n };\r\n}\r\n\r\nexport function validateAddress(address: AddressControlValidateAddressOptionsBag): Promise> {\r\n return post(\"/api/v2/Controls/AddressControlValidateAddress\", undefined, address);\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/**\r\n * Flatten a nested array down by the given number of levels.\r\n * Meant to be a replacement for the official Array.prototype.flat, which isn't supported by all browsers we support.\r\n * Adapted from Polyfill: https://github.com/behnammodi/polyfill/blob/master/array.polyfill.js#L591\r\n *\r\n * @param arr (potentially) nested array to be flattened\r\n * @param depth The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.\r\n *\r\n * @returns A new array with the sub-array elements concatenated into it.\r\n */\r\nexport const flatten = (arr: T[][], depth: number = 1): T[] => {\r\n const result: T[] = [];\r\n const forEach = result.forEach;\r\n\r\n const flatDeep = function (arr, depth): void {\r\n forEach.call(arr, function (val) {\r\n if (depth > 0 && Array.isArray(val)) {\r\n flatDeep(val, depth - 1);\r\n }\r\n else {\r\n result.push(val);\r\n }\r\n });\r\n };\r\n\r\n flatDeep(arr, depth);\r\n return result;\r\n};","/**\r\n * A function that will select a value from the object.\r\n */\r\ntype ValueSelector = (value: T) => string | number | boolean | null | undefined;\r\n\r\n/**\r\n * A function that will perform testing on a value to see if it meets\r\n * a certain condition and return true or false.\r\n */\r\ntype PredicateFn = (value: T, index: number) => boolean;\r\n\r\n/**\r\n * A function that will compare two values to see which one should\r\n * be ordered first.\r\n */\r\ntype ValueComparer = (a: T, b: T) => number;\r\n\r\nconst moreThanOneElement = \"More than one element was found in collection.\";\r\n\r\nconst noElementsFound = \"No element was found in collection.\";\r\n\r\n/**\r\n * Compares the values of two objects given the selector function.\r\n *\r\n * For the purposes of a compare, null and undefined are always a lower\r\n * value - unless both values are null or undefined in which case they\r\n * are considered equal.\r\n * \r\n * @param keySelector The function that will select the value.\r\n * @param descending True if this comparison should be in descending order.\r\n */\r\nfunction valueComparer(keySelector: ValueSelector, descending: boolean): ValueComparer {\r\n return (a: T, b: T): number => {\r\n const valueA = keySelector(a);\r\n const valueB = keySelector(b);\r\n\r\n // If valueA is null or undefined then it will either be considered\r\n // lower than or equal to valueB.\r\n if (valueA === undefined || valueA === null) {\r\n // If valueB is also null or undefined then they are considered equal.\r\n if (valueB === undefined || valueB === null) {\r\n return 0;\r\n }\r\n\r\n return !descending ? -1 : 1;\r\n }\r\n\r\n // If valueB is undefined or null (but valueA is not) then it is considered\r\n // a lower value than valueA.\r\n if (valueB === undefined || valueB === null) {\r\n return !descending ? 1 : -1;\r\n }\r\n\r\n // Perform a normal comparison.\r\n if (valueA > valueB) {\r\n return !descending ? 1 : -1;\r\n }\r\n else if (valueA < valueB) {\r\n return !descending ? -1 : 1;\r\n }\r\n else {\r\n return 0;\r\n }\r\n };\r\n}\r\n\r\n\r\n/**\r\n * Provides LINQ style access to an array of elements.\r\n */\r\nexport class List {\r\n /** The elements being tracked by this list. */\r\n protected elements: T[];\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new list with the given elements.\r\n * \r\n * @param elements The elements to be made available to LINQ queries.\r\n */\r\n constructor(elements?: T[]) {\r\n if (elements === undefined) {\r\n this.elements = [];\r\n }\r\n else {\r\n // Copy the array so if the caller makes changes it won't be reflected by us.\r\n this.elements = [...elements];\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new List from the elements without copying to a new array.\r\n * \r\n * @param elements The elements to initialize the list with.\r\n * @returns A new list of elements.\r\n */\r\n public static fromArrayNoCopy(elements: T[]): List {\r\n const list = new List();\r\n\r\n list.elements = elements;\r\n\r\n return list;\r\n }\r\n\r\n // #endregion\r\n\r\n /**\r\n * Returns a boolean that determines if the collection contains any elements.\r\n *\r\n * @returns true if the collection contains any elements; otherwise false.\r\n */\r\n public any(): boolean;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns a boolean that determines\r\n * if the filtered collection contains any elements.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns true if the collection contains any elements; otherwise false.\r\n */\r\n public any(predicate: PredicateFn): boolean;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns a boolean that determines\r\n * if the filtered collection contains any elements.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns true if the collection contains any elements; otherwise false.\r\n */\r\n public any(predicate?: PredicateFn): boolean {\r\n let elements = this.elements;\r\n\r\n if (predicate !== undefined) {\r\n elements = elements.filter(predicate);\r\n }\r\n\r\n return elements.length > 0;\r\n }\r\n\r\n /**\r\n * Returns the first element from the collection if there are any elements.\r\n * Otherwise will throw an exception.\r\n *\r\n * @returns The first element in the collection.\r\n */\r\n public first(): T;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the first element\r\n * in the collection if any remain. Otherwise throws an exception.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns The first element in the collection.\r\n */\r\n public first(predicate: PredicateFn): T;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the first element\r\n * in the collection if any remain. Otherwise throws an exception.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns The first element in the collection.\r\n */\r\n public first(predicate?: PredicateFn): T {\r\n let elements = this.elements;\r\n\r\n if (predicate !== undefined) {\r\n elements = elements.filter(predicate);\r\n }\r\n\r\n if (elements.length >= 1) {\r\n return elements[0];\r\n }\r\n else {\r\n throw noElementsFound;\r\n }\r\n }\r\n\r\n /**\r\n * Returns the first element found in the collection or undefined if the\r\n * collection contains no elements.\r\n *\r\n * @returns The first element in the collection or undefined.\r\n */\r\n public firstOrUndefined(): T | undefined;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the first element\r\n * found in the collection. If no elements remain then undefined is\r\n * returned instead.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns The first element in the filtered collection or undefined.\r\n */\r\n public firstOrUndefined(predicate: PredicateFn): T | undefined;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the first element\r\n * found in the collection. If no elements remain then undefined is\r\n * returned instead.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns The first element in the filtered collection or undefined.\r\n */\r\n public firstOrUndefined(predicate?: PredicateFn): T | undefined {\r\n let elements = this.elements;\r\n\r\n if (predicate !== undefined) {\r\n elements = elements.filter(predicate);\r\n }\r\n\r\n if (elements.length === 1) {\r\n return elements[0];\r\n }\r\n else {\r\n return undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a single element from the collection if there is a single\r\n * element. Otherwise will throw an exception.\r\n *\r\n * @returns An element.\r\n */\r\n public single(): T;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the single remaining\r\n * element from the collection. If more than one element remains then an\r\n * exception will be thrown.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns An element.\r\n */\r\n public single(predicate: PredicateFn): T;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the single remaining\r\n * element from the collection. If more than one element remains then an\r\n * exception will be thrown.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns An element.\r\n */\r\n public single(predicate?: PredicateFn): T {\r\n let elements = this.elements;\r\n\r\n if (predicate !== undefined) {\r\n elements = elements.filter(predicate);\r\n }\r\n\r\n if (elements.length === 1) {\r\n return elements[0];\r\n }\r\n else {\r\n throw moreThanOneElement;\r\n }\r\n }\r\n\r\n /**\r\n * Returns a single element from the collection if there is a single\r\n * element. If no elements are found then undefined is returned. More\r\n * than a single element will throw an exception.\r\n *\r\n * @returns An element or undefined.\r\n */\r\n public singleOrUndefined(): T | undefined;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the single element\r\n * from the collection if there is only one remaining. If no elements\r\n * remain then undefined is returned. More than a single element will throw\r\n * an exception.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns An element or undefined.\r\n */\r\n public singleOrUndefined(predicate: PredicateFn): T | undefined;\r\n\r\n /**\r\n * Filters the list by the predicate and then returns the single element\r\n * from the collection if there is only one remaining. If no elements\r\n * remain then undefined is returned. More than a single element will throw\r\n * an exception.\r\n *\r\n * @param predicate The predicate to filter the elements by.\r\n *\r\n * @returns An element or undefined.\r\n */\r\n public singleOrUndefined(predicate?: PredicateFn): T | undefined {\r\n let elements = this.elements;\r\n\r\n if (predicate !== undefined) {\r\n elements = elements.filter(predicate);\r\n }\r\n\r\n if (elements.length === 0) {\r\n return undefined;\r\n }\r\n else if (elements.length === 1) {\r\n return elements[0];\r\n }\r\n else {\r\n throw moreThanOneElement;\r\n }\r\n }\r\n\r\n /**\r\n * Orders the elements of the array and returns a new list of items\r\n * in that order.\r\n * \r\n * @param keySelector The selector for the key to be ordered by.\r\n * @returns A new ordered list of elements.\r\n */\r\n public orderBy(keySelector: ValueSelector): OrderedList {\r\n const comparer = valueComparer(keySelector, false);\r\n\r\n return new OrderedList(this.elements, comparer);\r\n }\r\n\r\n /**\r\n * Orders the elements of the array in descending order and returns a\r\n * new list of items in that order.\r\n *\r\n * @param keySelector The selector for the key to be ordered by.\r\n * @returns A new ordered list of elements.\r\n */\r\n public orderByDescending(keySelector: ValueSelector): OrderedList {\r\n const comparer = valueComparer(keySelector, true);\r\n\r\n return new OrderedList(this.elements, comparer);\r\n }\r\n\r\n /**\r\n * Filters the results and returns a new list containing only the elements\r\n * that match the predicate.\r\n * \r\n * @param predicate The predicate to filter elements with.\r\n * \r\n * @returns A new collection of elements that match the predicate.\r\n */\r\n public where(predicate: PredicateFn): List {\r\n return new List(this.elements.filter(predicate));\r\n }\r\n\r\n /**\r\n * Get the elements of this list as a native array of items.\r\n *\r\n * @returns An array of items with all filters applied.\r\n */\r\n public toArray(): T[] {\r\n return [...this.elements];\r\n }\r\n}\r\n\r\n/**\r\n * A list of items that has ordering already applied.\r\n */\r\nclass OrderedList extends List {\r\n /** The base comparer to use when ordering. */\r\n private baseComparer!: ValueComparer;\r\n\r\n // #region Constructors\r\n\r\n constructor(elements: T[], baseComparer: ValueComparer) {\r\n super(elements);\r\n\r\n this.baseComparer = baseComparer;\r\n this.elements.sort(this.baseComparer);\r\n }\r\n\r\n // #endregion\r\n\r\n /**\r\n * Orders the elements of the array and returns a new list of items\r\n * in that order.\r\n * \r\n * @param keySelector The selector for the key to be ordered by.\r\n * @returns A new ordered list of elements.\r\n */\r\n public thenBy(keySelector: ValueSelector): OrderedList {\r\n const comparer = valueComparer(keySelector, false);\r\n\r\n return new OrderedList(this.elements, (a: T, b: T) => this.baseComparer(a, b) || comparer(a, b));\r\n }\r\n\r\n /**\r\n * Orders the elements of the array in descending order and returns a\r\n * new list of items in that order.\r\n *\r\n * @param keySelector The selector for the key to be ordered by.\r\n * @returns A new ordered list of elements.\r\n */\r\n public thenByDescending(keySelector: ValueSelector): OrderedList {\r\n const comparer = valueComparer(keySelector, true);\r\n\r\n return new OrderedList(this.elements, (a: T, b: T) => this.baseComparer(a, b) || comparer(a, b));\r\n }\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\n\r\n/** An empty unique identifier. */\r\nexport const emptyGuid = \"00000000-0000-0000-0000-000000000000\";\r\n\r\n/**\r\n* Generates a new Guid\r\n*/\r\nexport function newGuid (): Guid {\r\n return \"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\".replace(/[xy]/g, (c) => {\r\n const r = Math.random() * 16 | 0;\r\n const v = c === \"x\" ? r : r & 0x3 | 0x8;\r\n return v.toString(16);\r\n });\r\n}\r\n\r\n/**\r\n * Returns a normalized Guid that can be compared with string equality (===)\r\n * @param a\r\n */\r\nexport function normalize (a: Guid | null | undefined): Guid | null {\r\n if (!a) {\r\n return null;\r\n }\r\n\r\n return a.toLowerCase();\r\n}\r\n\r\n/**\r\n * Checks if the given string is a valid Guid. To be considered valid it must\r\n * be a bare guid with hyphens. Bare means not enclosed in '{' and '}'.\r\n * \r\n * @param guid The Guid to be checked.\r\n * @returns True if the guid is valid, otherwise false.\r\n */\r\nexport function isValidGuid(guid: Guid | string): boolean {\r\n return /^[0-9A-Fa-f]{8}-(?:[0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}$/.test(guid);\r\n}\r\n\r\n/**\r\n * Converts the string value to a Guid.\r\n * \r\n * @param value The value to be converted.\r\n * @returns A Guid value or null is the string could not be parsed as a Guid.\r\n */\r\nexport function toGuidOrNull(value: string | null | undefined): Guid | null {\r\n if (value === null || value === undefined) {\r\n return null;\r\n }\r\n\r\n if (!isValidGuid(value)) {\r\n return null;\r\n }\r\n\r\n return value as Guid;\r\n}\r\n\r\n/**\r\n * Are the guids equal?\r\n * @param a\r\n * @param b\r\n */\r\nexport function areEqual (a: Guid | null | undefined, b: Guid | null | undefined): boolean {\r\n return normalize(a) === normalize(b);\r\n}\r\n\r\nexport default {\r\n newGuid,\r\n normalize,\r\n areEqual\r\n};\r\n\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { areEqual, toGuidOrNull } from \"./guid\";\r\nimport { Pluralize } from \"@Obsidian/Libs/pluralize\";\r\n\r\n/**\r\n * Is the value an empty string?\r\n * @param val\r\n */\r\nexport function isEmpty(val: unknown): boolean {\r\n if (typeof val === \"string\") {\r\n return val.length === 0;\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/**\r\n * Is the value an empty string?\r\n * @param val\r\n */\r\nexport function isWhiteSpace(val: unknown): boolean {\r\n if (typeof val === \"string\") {\r\n return val.trim().length === 0;\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/**\r\n * Is the value null, undefined or whitespace?\r\n * @param val\r\n */\r\nexport function isNullOrWhiteSpace(val: unknown): boolean {\r\n return isWhiteSpace(val) || val === undefined || val === null;\r\n}\r\n\r\n/**\r\n * Turns \"MyCamelCaseString\" into \"My Camel Case String\"\r\n * @param val\r\n */\r\nexport function splitCamelCase(val: string): string {\r\n return val.replace(/([a-z])([A-Z])/g, \"$1 $2\");\r\n}\r\n\r\n/**\r\n * Returns an English comma-and fragment.\r\n * Ex: ['a', 'b', 'c'] => 'a, b, and c'\r\n * @param strs\r\n */\r\nexport function asCommaAnd(strs: string[]): string {\r\n if (strs.length === 0) {\r\n return \"\";\r\n }\r\n\r\n if (strs.length === 1) {\r\n return strs[0];\r\n }\r\n\r\n if (strs.length === 2) {\r\n return `${strs[0]} and ${strs[1]}`;\r\n }\r\n\r\n const last = strs.pop();\r\n return `${strs.join(\", \")}, and ${last}`;\r\n}\r\n\r\n/**\r\n * Convert the string to the title case.\r\n * hellO worlD => Hello World\r\n * @param str\r\n */\r\nexport function toTitleCase(str: string | null): string {\r\n if (!str) {\r\n return \"\";\r\n }\r\n\r\n return str.replace(/\\w\\S*/g, (word) => {\r\n return word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();\r\n });\r\n}\r\n\r\n/**\r\n * Capitalize the first character\r\n */\r\nexport function upperCaseFirstCharacter(str: string | null): string {\r\n if (!str) {\r\n return \"\";\r\n }\r\n\r\n return str.charAt(0).toUpperCase() + str.substring(1);\r\n}\r\n\r\n/**\r\n * Pluralizes the given word. If count is specified and is equal to 1 then\r\n * the singular form of the word is returned. This will also de-pluralize a\r\n * word if required.\r\n *\r\n * @param word The word to be pluralized or singularized.\r\n * @param count An optional count to indicate when the word should be singularized.\r\n *\r\n * @returns The word in plural or singular form depending on the options.\r\n */\r\nexport function pluralize(word: string, count?: number): string {\r\n return Pluralize(word, count);\r\n}\r\n\r\n/**\r\n * Returns a singular or plural phrase depending on if the number is 1.\r\n * (0, Cat, Cats) => Cats\r\n * (1, Cat, Cats) => Cat\r\n * (2, Cat, Cats) => Cats\r\n * @param num\r\n * @param singular\r\n * @param plural\r\n */\r\nexport function pluralConditional(num: number, singular: string, plural: string): string {\r\n return num === 1 ? singular : plural;\r\n}\r\n\r\n/**\r\n * Pad the left side of a string so it is at least length characters long.\r\n *\r\n * @param str The string to be padded.\r\n * @param length The minimum length to make the string.\r\n * @param padCharacter The character to use to pad the string.\r\n */\r\nexport function padLeft(str: string | undefined | null, length: number, padCharacter: string = \" \"): string {\r\n if (padCharacter == \"\") {\r\n padCharacter = \" \";\r\n }\r\n else if (padCharacter.length > 1) {\r\n padCharacter = padCharacter.substring(0, 1);\r\n }\r\n\r\n if (!str) {\r\n return Array(length + 1).join(padCharacter);\r\n }\r\n\r\n if (str.length >= length) {\r\n return str;\r\n }\r\n\r\n return Array(length - str.length + 1).join(padCharacter) + str;\r\n}\r\n\r\n/**\r\n * Pad the right side of a string so it is at least length characters long.\r\n *\r\n * @param str The string to be padded.\r\n * @param length The minimum length to make the string.\r\n * @param padCharacter The character to use to pad the string.\r\n */\r\nexport function padRight(str: string | undefined | null, length: number, padCharacter: string = \" \"): string {\r\n if (padCharacter == \"\") {\r\n padCharacter = \" \";\r\n }\r\n else if (padCharacter.length > 1) {\r\n padCharacter = padCharacter.substring(0, 1);\r\n }\r\n\r\n if (!str) {\r\n return Array(length).join(padCharacter);\r\n }\r\n\r\n if (str.length >= length) {\r\n return str;\r\n }\r\n\r\n return str + Array(length - str.length + 1).join(padCharacter);\r\n}\r\n\r\nexport type TruncateOptions = {\r\n ellipsis?: boolean;\r\n};\r\n\r\n/**\r\n * Ensure a string does not go over the character limit. Truncation happens\r\n * on word boundaries.\r\n *\r\n * @param str The string to be truncated.\r\n * @param limit The maximum length of the resulting string.\r\n * @param options Additional options that control how truncation will happen.\r\n *\r\n * @returns The truncated string.\r\n */\r\nexport function truncate(str: string, limit: number, options?: TruncateOptions): string {\r\n // Early out if the string is already under the limit.\r\n if (str.length <= limit) {\r\n return str;\r\n }\r\n\r\n // All the whitespace characters that we can split on.\r\n const trimmable = \"\\u0009\\u000A\\u000B\\u000C\\u000D\\u0020\\u00A0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u2028\\u2029\\u3000\\uFEFF\";\r\n const reg = new RegExp(`(?=[${trimmable}])`);\r\n const words = str.split(reg);\r\n let count = 0;\r\n\r\n // If we are appending ellipsis, then shorten the limit size.\r\n if (options && options.ellipsis === true) {\r\n limit -= 3;\r\n }\r\n\r\n // Get a list of words that will fit within our length requirements.\r\n const visibleWords = words.filter(function (word) {\r\n count += word.length;\r\n return count <= limit;\r\n });\r\n\r\n return `${visibleWords.join(\"\")}...`;\r\n}\r\n\r\n/** The regular expression that contains the characters to be escaped. */\r\nconst escapeHtmlRegExp = /[\"'&<>]/g;\r\n\r\n/** The character map of the characters to be replaced and the strings to replace them with. */\r\nconst escapeHtmlMap: Record = {\r\n '\"': \""\",\r\n \"&\": \"&\",\r\n \"'\": \"'\",\r\n \"<\": \"<\",\r\n \">\": \">\"\r\n};\r\n\r\n/**\r\n * Escapes a string so it can be used in HTML. This turns things like the <\r\n * character into the < sequence so it will still render as \"<\".\r\n *\r\n * @param str The string to be escaped.\r\n * @returns A string that has all HTML entities escaped.\r\n */\r\nexport function escapeHtml(str: string): string {\r\n return str.replace(escapeHtmlRegExp, (ch) => {\r\n return escapeHtmlMap[ch];\r\n });\r\n}\r\n\r\n/**\r\n * The default compare value function for UI controls. This checks if both values\r\n * are GUIDs and if so does a case-insensitive compare, otherwise it does a\r\n * case-sensitive compare of the two values.\r\n *\r\n * @param value The value selected in the UI.\r\n * @param itemValue The item value to be compared against.\r\n *\r\n * @returns true if the two values are considered equal; otherwise false.\r\n */\r\nexport function defaultControlCompareValue(value: string, itemValue: string): boolean {\r\n const guidValue = toGuidOrNull(value);\r\n const guidItemValue = toGuidOrNull(itemValue);\r\n\r\n if (guidValue !== null && guidItemValue !== null) {\r\n return areEqual(guidValue, guidItemValue);\r\n }\r\n\r\n return value === itemValue;\r\n}\r\n\r\n/**\r\n * Determins whether or not a given string contains any HTML tags in.\r\n *\r\n * @param value The string potentially containing HTML\r\n *\r\n * @returns true if it contains HTML, otherwise false\r\n */\r\nexport function containsHtmlTag(value: string): boolean {\r\n return /<[/0-9a-zA-Z]/.test(value);\r\n}\r\n\r\nexport default {\r\n asCommaAnd,\r\n containsHtmlTag,\r\n escapeHtml,\r\n splitCamelCase,\r\n isNullOrWhiteSpace,\r\n isWhiteSpace,\r\n isEmpty,\r\n toTitleCase,\r\n pluralConditional,\r\n padLeft,\r\n padRight,\r\n truncate\r\n};\r\n","import { List } from \"./linq\";\r\nimport { padLeft, padRight } from \"./stringUtils\";\r\nimport { RockDateTime } from \"./rockDateTime\";\r\n\r\n/**\r\n * Returns a blank string if the string value is 0.\r\n *\r\n * @param value The value to check and return.\r\n * @returns The value passed in or an empty string if it equates to zero.\r\n */\r\nfunction blankIfZero(value: string): string {\r\n return parseInt(value) === 0 ? \"\" : value;\r\n}\r\n\r\n/**\r\n * Gets the 12 hour value of the given 24-hour number.\r\n *\r\n * @param hour The hour in a 24-hour format.\r\n * @returns The hour in a 12-hour format.\r\n */\r\nfunction get12HourValue(hour: number): number {\r\n if (hour == 0) {\r\n return 12;\r\n }\r\n else if (hour < 13) {\r\n return hour;\r\n }\r\n else {\r\n return hour - 12;\r\n }\r\n}\r\ntype DateFormatterCommand = (date: RockDateTime) => string;\r\n\r\nconst englishDayNames = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\r\nconst englishMonthNames = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"];\r\n\r\nconst dateFormatters: Record = {\r\n \"yyyyy\": date => padLeft(date.year.toString(), 5, \"0\"),\r\n \"yyyy\": date => padLeft(date.year.toString(), 4, \"0\"),\r\n \"yyy\": date => padLeft(date.year.toString(), 3, \"0\"),\r\n \"yy\": date => padLeft((date.year % 100).toString(), 2, \"0\"),\r\n \"y\": date => (date.year % 100).toString(),\r\n\r\n \"MMMM\": date => englishMonthNames[date.month - 1],\r\n \"MMM\": date => englishMonthNames[date.month - 1].substr(0, 3),\r\n \"MM\": date => padLeft(date.month.toString(), 2, \"0\"),\r\n \"M\": date => date.month.toString(),\r\n\r\n \"dddd\": date => englishDayNames[date.dayOfWeek],\r\n \"ddd\": date => englishDayNames[date.dayOfWeek].substr(0, 3),\r\n \"dd\": date => padLeft(date.day.toString(), 2, \"0\"),\r\n \"d\": date => date.day.toString(),\r\n\r\n \"fffffff\": date => padRight((date.millisecond * 10000).toString(), 7, \"0\"),\r\n \"ffffff\": date => padRight((date.millisecond * 1000).toString(), 6, \"0\"),\r\n \"fffff\": date => padRight((date.millisecond * 100).toString(), 5, \"0\"),\r\n \"ffff\": date => padRight((date.millisecond * 10).toString(), 4, \"0\"),\r\n \"fff\": date => padRight(date.millisecond.toString(), 3, \"0\"),\r\n \"ff\": date => padRight(Math.floor(date.millisecond / 10).toString(), 2, \"0\"),\r\n \"f\": date => padRight(Math.floor(date.millisecond / 100).toString(), 1, \"0\"),\r\n\r\n \"FFFFFFF\": date => blankIfZero(padRight((date.millisecond * 10000).toString(), 7, \"0\")),\r\n \"FFFFFF\": date => blankIfZero(padRight((date.millisecond * 1000).toString(), 6, \"0\")),\r\n \"FFFFF\": date => blankIfZero(padRight((date.millisecond * 100).toString(), 5, \"0\")),\r\n \"FFFF\": date => blankIfZero(padRight((date.millisecond * 10).toString(), 4, \"0\")),\r\n \"FFF\": date => blankIfZero(padRight(date.millisecond.toString(), 3, \"0\")),\r\n \"FF\": date => blankIfZero(padRight(Math.floor(date.millisecond / 10).toString(), 2, \"0\")),\r\n \"F\": date => blankIfZero(padRight(Math.floor(date.millisecond / 100).toString(), 1, \"0\")),\r\n\r\n \"g\": date => date.year < 0 ? \"B.C.\" : \"A.D.\",\r\n \"gg\": date => date.year < 0 ? \"B.C.\" : \"A.D.\",\r\n\r\n \"hh\": date => padLeft(get12HourValue(date.hour).toString(), 2, \"0\"),\r\n \"h\": date => get12HourValue(date.hour).toString(),\r\n\r\n \"HH\": date => padLeft(date.hour.toString(), 2, \"0\"),\r\n \"H\": date => date.hour.toString(),\r\n\r\n \"mm\": date => padLeft(date.minute.toString(), 2, \"0\"),\r\n \"m\": date => date.minute.toString(),\r\n\r\n \"ss\": date => padLeft(date.second.toString(), 2, \"0\"),\r\n \"s\": date => date.second.toString(),\r\n\r\n \"K\": date => {\r\n const offset = date.offset;\r\n const offsetHour = Math.abs(Math.floor(offset / 60));\r\n const offsetMinute = Math.abs(offset % 60);\r\n return `${offset >= 0 ? \"+\" : \"-\"}${padLeft(offsetHour.toString(), 2, \"0\")}:${padLeft(offsetMinute.toString(), 2, \"0\")}`;\r\n },\r\n\r\n \"tt\": date => date.hour >= 12 ? \"PM\" : \"AM\",\r\n \"t\": date => date.hour >= 12 ? \"P\" : \"A\",\r\n\r\n \"zzz\": date => {\r\n const offset = date.offset;\r\n const offsetHour = Math.abs(Math.floor(offset / 60));\r\n const offsetMinute = Math.abs(offset % 60);\r\n return `${offset >= 0 ? \"+\" : \"-\"}${padLeft(offsetHour.toString(), 2, \"0\")}:${padLeft(offsetMinute.toString(), 2, \"0\")}`;\r\n },\r\n \"zz\": date => {\r\n const offset = date.offset;\r\n const offsetHour = Math.abs(Math.floor(offset / 60));\r\n return `${offset >= 0 ? \"+\" : \"-\"}${padLeft(offsetHour.toString(), 2, \"0\")}`;\r\n },\r\n \"z\": date => {\r\n const offset = date.offset;\r\n const offsetHour = Math.abs(Math.floor(offset / 60));\r\n return `${offset >= 0 ? \"+\" : \"-\"}${offsetHour}`;\r\n },\r\n\r\n \":\": () => \":\",\r\n \"/\": () => \"/\"\r\n};\r\n\r\nconst dateFormatterKeys = new List(Object.keys(dateFormatters))\r\n .orderByDescending(k => k.length)\r\n .toArray();\r\n\r\nconst standardDateFormats: Record = {\r\n \"d\": date => formatAspDate(date, \"M/d/yyyy\"),\r\n \"D\": date => formatAspDate(date, \"dddd, MMMM dd, yyyy\"),\r\n \"t\": date => formatAspDate(date, \"h:mm tt\"),\r\n \"T\": date => formatAspDate(date, \"h:mm:ss tt\"),\r\n \"M\": date => formatAspDate(date, \"MMMM dd\"),\r\n \"m\": date => formatAspDate(date, \"MMMM dd\"),\r\n \"Y\": date => formatAspDate(date, \"yyyy MMMM\"),\r\n \"y\": date => formatAspDate(date, \"yyyy MMMM\"),\r\n \"f\": date => `${formatAspDate(date, \"D\")} ${formatAspDate(date, \"t\")}`,\r\n \"F\": date => `${formatAspDate(date, \"D\")} ${formatAspDate(date, \"T\")}`,\r\n \"g\": date => `${formatAspDate(date, \"d\")} ${formatAspDate(date, \"t\")}`,\r\n \"G\": date => `${formatAspDate(date, \"d\")} ${formatAspDate(date, \"T\")}`,\r\n \"o\": date => formatAspDate(date, `yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffzzz`),\r\n \"O\": date => formatAspDate(date, `yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffzzz`),\r\n \"r\": date => formatAspDate(date, `ddd, dd MMM yyyy HH':'mm':'ss 'GMT'`),\r\n \"R\": date => formatAspDate(date, `ddd, dd MMM yyyy HH':'mm':'ss 'GMT'`),\r\n \"s\": date => formatAspDate(date, `yyyy'-'MM'-'dd'T'HH':'mm':'ss`),\r\n \"u\": date => formatAspDate(date, `yyyy'-'MM'-'dd HH':'mm':'ss'Z'`),\r\n \"U\": date => {\r\n return formatAspDate(date.universalDateTime, `F`);\r\n },\r\n};\r\n\r\n/**\r\n * Formats the Date object using custom format specifiers.\r\n *\r\n * @param date The date object to be formatted.\r\n * @param format The custom format string.\r\n * @returns A string that represents the date in the specified format.\r\n */\r\nfunction formatAspCustomDate(date: RockDateTime, format: string): string {\r\n let result = \"\";\r\n\r\n for (let i = 0; i < format.length;) {\r\n let matchFound = false;\r\n\r\n for (const k of dateFormatterKeys) {\r\n if (format.substr(i, k.length) === k) {\r\n result += dateFormatters[k](date);\r\n matchFound = true;\r\n i += k.length;\r\n break;\r\n }\r\n }\r\n\r\n if (matchFound) {\r\n continue;\r\n }\r\n\r\n if (format[i] === \"\\\\\") {\r\n i++;\r\n if (i < format.length) {\r\n result += format[i++];\r\n }\r\n }\r\n else if (format[i] === \"'\") {\r\n i++;\r\n for (; i < format.length && format[i] !== \"'\"; i++) {\r\n result += format[i];\r\n }\r\n i++;\r\n }\r\n else if (format[i] === '\"') {\r\n i++;\r\n for (; i < format.length && format[i] !== '\"'; i++) {\r\n result += format[i];\r\n }\r\n i++;\r\n }\r\n else {\r\n result += format[i++];\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Formats the Date object using a standard format string.\r\n *\r\n * @param date The date object to be formatted.\r\n * @param format The standard format specifier.\r\n * @returns A string that represents the date in the specified format.\r\n */\r\nfunction formatAspStandardDate(date: RockDateTime, format: string): string {\r\n if (standardDateFormats[format] !== undefined) {\r\n return standardDateFormats[format](date);\r\n }\r\n\r\n return format;\r\n}\r\n\r\n/**\r\n * Formats the given Date object using nearly the same rules as the ASP C#\r\n * format methods.\r\n *\r\n * @param date The date object to be formatted.\r\n * @param format The format string to use.\r\n */\r\nexport function formatAspDate(date: RockDateTime, format: string): string {\r\n if (format.length === 1) {\r\n return formatAspStandardDate(date, format);\r\n }\r\n else if (format.length === 2 && format[0] === \"%\") {\r\n return formatAspCustomDate(date, format[1]);\r\n }\r\n else {\r\n return formatAspCustomDate(date, format);\r\n }\r\n}\r\n","import { DateTime, FixedOffsetZone, Zone } from \"luxon\";\r\nimport { formatAspDate } from \"./aspDateFormat\";\r\nimport { DayOfWeek } from \"@Obsidian/Enums/Controls/dayOfWeek\";\r\n\r\n/**\r\n * The days of the week that are used by RockDateTime.\r\n */\r\nexport { DayOfWeek } from \"@Obsidian/Enums/Controls/dayOfWeek\";\r\n\r\n/**\r\n * The various date and time formats supported by the formatting methods.\r\n */\r\nexport const DateTimeFormat: Record = {\r\n DateFull: {\r\n year: \"numeric\",\r\n month: \"long\",\r\n day: \"numeric\"\r\n },\r\n\r\n DateMedium: {\r\n year: \"numeric\",\r\n month: \"short\",\r\n day: \"numeric\"\r\n },\r\n\r\n DateShort: {\r\n year: \"numeric\",\r\n month: \"numeric\",\r\n day: \"numeric\"\r\n },\r\n\r\n TimeShort: {\r\n hour: \"numeric\",\r\n minute: \"numeric\",\r\n },\r\n\r\n TimeWithSeconds: {\r\n hour: \"numeric\",\r\n minute: \"numeric\",\r\n second: \"numeric\"\r\n },\r\n\r\n DateTimeShort: {\r\n year: \"numeric\",\r\n month: \"numeric\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\"\r\n },\r\n\r\n DateTimeShortWithSeconds: {\r\n year: \"numeric\",\r\n month: \"numeric\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\",\r\n second: \"numeric\"\r\n },\r\n\r\n DateTimeMedium: {\r\n year: \"numeric\",\r\n month: \"short\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\"\r\n },\r\n\r\n DateTimeMediumWithSeconds: {\r\n year: \"numeric\",\r\n month: \"short\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\",\r\n second: \"numeric\"\r\n },\r\n\r\n DateTimeFull: {\r\n year: \"numeric\",\r\n month: \"long\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\"\r\n },\r\n\r\n DateTimeFullWithSeconds: {\r\n year: \"numeric\",\r\n month: \"long\",\r\n day: \"numeric\",\r\n hour: \"numeric\",\r\n minute: \"numeric\",\r\n second: \"numeric\"\r\n }\r\n};\r\n\r\n/**\r\n * A date and time object that handles time zones and formatting. This class is\r\n * immutable and cannot be modified. All modifications are performed by returning\r\n * a new RockDateTime instance.\r\n */\r\nexport class RockDateTime {\r\n /** The internal DateTime object that holds our date information. */\r\n private dateTime: DateTime;\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new instance of RockDateTime.\r\n *\r\n * @param dateTime The Luxon DateTime object that is used to track the internal state.\r\n */\r\n private constructor(dateTime: DateTime) {\r\n this.dateTime = dateTime;\r\n }\r\n\r\n /**\r\n * Creates a new instance of RockDateTime from the given date and time parts.\r\n *\r\n * @param year The year of the new date.\r\n * @param month The month of the new date (1-12).\r\n * @param day The day of month of the new date.\r\n * @param hour The hour of the day.\r\n * @param minute The minute of the hour.\r\n * @param second The second of the minute.\r\n * @param millisecond The millisecond of the second.\r\n * @param zone The time zone offset to construct the date in.\r\n *\r\n * @returns A RockDateTime instance or null if the requested date was not valid.\r\n */\r\n public static fromParts(year: number, month: number, day: number, hour?: number, minute?: number, second?: number, millisecond?: number, zone?: number | string): RockDateTime | null {\r\n let luxonZone: Zone | string | undefined;\r\n\r\n if (zone !== undefined) {\r\n if (typeof zone === \"number\") {\r\n luxonZone = FixedOffsetZone.instance(zone);\r\n }\r\n else {\r\n luxonZone = zone;\r\n }\r\n }\r\n\r\n const dateTime = DateTime.fromObject({\r\n year,\r\n month,\r\n day,\r\n hour,\r\n minute,\r\n second,\r\n millisecond\r\n }, {\r\n zone: luxonZone\r\n });\r\n\r\n if (!dateTime.isValid) {\r\n return null;\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new instance of RockDateTime that represents the time specified\r\n * as the Javascript milliseconds value. The time zone is set to the browser\r\n * time zone.\r\n *\r\n * @param milliseconds The time in milliseconds since the epoch.\r\n *\r\n * @returns A new RockDateTime instance or null if the specified date was not valid.\r\n */\r\n public static fromMilliseconds(milliseconds: number): RockDateTime | null {\r\n const dateTime = DateTime.fromMillis(milliseconds);\r\n\r\n if (!dateTime.isValid) {\r\n return null;\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Construct a new RockDateTime instance from a Javascript Date object.\r\n *\r\n * @param date The Javascript date object that contains the date information.\r\n *\r\n * @returns A RockDateTime instance or null if the date was not valid.\r\n */\r\n public static fromJSDate(date: Date): RockDateTime | null {\r\n const dateTime = DateTime.fromJSDate(date);\r\n\r\n if (!dateTime.isValid) {\r\n return null;\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Constructs a new RockDateTime instance by parsing the given string from\r\n * ISO 8601 format.\r\n *\r\n * @param dateString The string that contains the ISO 8601 formatted text.\r\n *\r\n * @returns A new RockDateTime instance or null if the date was not valid.\r\n */\r\n public static parseISO(dateString: string): RockDateTime | null {\r\n const dateTime = DateTime.fromISO(dateString, { setZone: true });\r\n\r\n if (!dateTime.isValid) {\r\n return null;\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Constructs a new RockDateTime instance by parsing the given string from\r\n * RFC 1123 format. This is common in HTTP headers.\r\n *\r\n * @param dateString The string that contains the RFC 1123 formatted text.\r\n *\r\n * @returns A new RockDateTime instance or null if the date was not valid.\r\n */\r\n public static parseHTTP(dateString: string): RockDateTime | null {\r\n const dateTime = DateTime.fromHTTP(dateString, { setZone: true });\r\n\r\n if (!dateTime.isValid) {\r\n return null;\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the current date and time.\r\n *\r\n * @returns A RockDateTime instance.\r\n */\r\n public static now(): RockDateTime {\r\n return new RockDateTime(DateTime.now());\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the current time in UTC.\r\n *\r\n * @returns A new RockDateTime instance in the UTC time zone.\r\n */\r\n public static utcNow(): RockDateTime {\r\n return new RockDateTime(DateTime.now().toUTC());\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Properties\r\n\r\n /**\r\n * The Date portion of this RockDateTime instance. All time properties of\r\n * the returned instance will be set to 0.\r\n */\r\n public get date(): RockDateTime {\r\n const date = RockDateTime.fromParts(this.year, this.month, this.day, 0, 0, 0, 0, this.offset);\r\n\r\n if (date === null) {\r\n throw \"Could not convert to date instance.\";\r\n }\r\n\r\n return date;\r\n }\r\n\r\n /**\r\n * The day of the month represented by this instance.\r\n */\r\n public get day(): number {\r\n return this.dateTime.day;\r\n }\r\n\r\n /**\r\n * The day of the week represented by this instance.\r\n */\r\n public get dayOfWeek(): DayOfWeek {\r\n switch (this.dateTime.weekday) {\r\n case 1:\r\n return DayOfWeek.Monday;\r\n\r\n case 2:\r\n return DayOfWeek.Tuesday;\r\n\r\n case 3:\r\n return DayOfWeek.Wednesday;\r\n\r\n case 4:\r\n return DayOfWeek.Thursday;\r\n\r\n case 5:\r\n return DayOfWeek.Friday;\r\n\r\n case 6:\r\n return DayOfWeek.Saturday;\r\n\r\n case 7:\r\n return DayOfWeek.Sunday;\r\n }\r\n\r\n throw \"Could not determine day of week.\";\r\n }\r\n\r\n /**\r\n * The day of the year represented by this instance.\r\n */\r\n public get dayOfYear(): number {\r\n return this.dateTime.ordinal;\r\n }\r\n\r\n /**\r\n * The hour of the day represented by this instance.\r\n */\r\n public get hour(): number {\r\n return this.dateTime.hour;\r\n }\r\n\r\n /**\r\n * The millisecond of the second represented by this instance.\r\n */\r\n public get millisecond(): number {\r\n return this.dateTime.millisecond;\r\n }\r\n\r\n /**\r\n * The minute of the hour represented by this instance.\r\n */\r\n public get minute(): number {\r\n return this.dateTime.minute;\r\n }\r\n\r\n /**\r\n * The month of the year represented by this instance (1-12).\r\n */\r\n public get month(): number {\r\n return this.dateTime.month;\r\n }\r\n\r\n /**\r\n * The offset from UTC represented by this instance. If the timezone of this\r\n * instance is UTC-7 then the value returned is -420.\r\n */\r\n public get offset(): number {\r\n return this.dateTime.offset;\r\n }\r\n\r\n /**\r\n * The second of the minute represented by this instance.\r\n */\r\n public get second(): number {\r\n return this.dateTime.second;\r\n }\r\n\r\n /**\r\n * The year represented by this instance.\r\n */\r\n public get year(): number {\r\n return this.dateTime.year;\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the same point in\r\n * time represented in the local browser time zone.\r\n */\r\n public get localDateTime(): RockDateTime {\r\n return new RockDateTime(this.dateTime.toLocal());\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the same point in\r\n * time represented in the organization time zone.\r\n */\r\n public get organizationDateTime(): RockDateTime {\r\n throw \"Not Implemented\";\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the same point in\r\n * time represented in UTC.\r\n */\r\n public get universalDateTime(): RockDateTime {\r\n return new RockDateTime(this.dateTime.toUTC());\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Methods\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of days to this instance.\r\n *\r\n * @param days The number of days to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addDays(days: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ days: days });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of hours to this instance.\r\n *\r\n * @param days The number of hours to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addHours(hours: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ hours: hours });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of milliseconds to this instance.\r\n *\r\n * @param days The number of milliseconds to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addMilliseconds(milliseconds: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ milliseconds: milliseconds });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of minutes to this instance.\r\n *\r\n * @param days The number of minutes to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addMinutes(minutes: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ minutes: minutes });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of months to this instance.\r\n *\r\n * @param days The number of months to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addMonths(months: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ months: months });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of seconds to this instance.\r\n *\r\n * @param days The number of seconds to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addSeconds(seconds: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ seconds: seconds });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Creates a new RockDateTime instance that represents the date and time\r\n * after adding the number of years to this instance.\r\n *\r\n * @param days The number of years to add.\r\n *\r\n * @returns A new instance of RockDateTime that represents the new date and time.\r\n */\r\n public addYears(years: number): RockDateTime {\r\n const dateTime = this.dateTime.plus({ years: years });\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Operation produced an invalid date.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Converts the date time representation into the number of milliseconds\r\n * that have elapsed since the epoch (1970-01-01T00:00:00Z).\r\n *\r\n * @returns The number of milliseconds since the epoch.\r\n */\r\n public toMilliseconds(): number {\r\n return this.dateTime.toMillis();\r\n }\r\n\r\n /**\r\n * Creates a new instance of RockDateTime that represents the same point\r\n * in time as represented by the specified time zone offset.\r\n *\r\n * @param zone The time zone offset as a number or string such as \"UTC+4\".\r\n *\r\n * @returns A new RockDateTime instance that represents the specified time zone.\r\n */\r\n public toOffset(zone: number | string): RockDateTime {\r\n let dateTime: DateTime;\r\n\r\n if (typeof zone === \"number\") {\r\n dateTime = this.dateTime.setZone(FixedOffsetZone.instance(zone));\r\n }\r\n else {\r\n dateTime = this.dateTime.setZone(zone);\r\n }\r\n\r\n if (!dateTime.isValid) {\r\n throw \"Invalid time zone specified.\";\r\n }\r\n\r\n return new RockDateTime(dateTime);\r\n }\r\n\r\n /**\r\n * Formats this instance according to C# formatting rules.\r\n *\r\n * @param format The string that specifies the format to use.\r\n *\r\n * @returns A string representing this instance in the given format.\r\n */\r\n public toASPString(format: string): string {\r\n return formatAspDate(this, format);\r\n }\r\n\r\n /**\r\n * Creates a string representation of this instance in ISO8601 format.\r\n *\r\n * @returns An ISO8601 formatted string.\r\n */\r\n public toISOString(): string {\r\n return this.dateTime.toISO();\r\n }\r\n\r\n /**\r\n * Formats this instance using standard locale formatting rules to display\r\n * a date and time in the browsers specified locale.\r\n *\r\n * @param format The format to use when generating the string.\r\n *\r\n * @returns A string that represents the date and time in then specified format.\r\n */\r\n public toLocaleString(format: Intl.DateTimeFormatOptions): string {\r\n return this.dateTime.toLocaleString(format);\r\n }\r\n\r\n /**\r\n * Transforms the date into a human friendly elapsed time string.\r\n *\r\n * @example\r\n * // Returns \"21yrs\"\r\n * RockDateTime.fromParts(2000, 3, 4).toElapsedString();\r\n *\r\n * @returns A string that represents the amount of time that has elapsed.\r\n */\r\n public toElapsedString(): string {\r\n const now = RockDateTime.now();\r\n const msPerHour = 1000 * 60 * 60;\r\n const hoursPerDay = 24;\r\n const daysPerMonth = 30.4167;\r\n const daysPerYear = 365.25;\r\n\r\n const totalMs = Math.abs(now.toMilliseconds() - this.toMilliseconds());\r\n const totalHours = totalMs / msPerHour;\r\n const totalDays = totalHours / hoursPerDay;\r\n\r\n if (totalDays < 2) {\r\n return \"1day\";\r\n }\r\n\r\n if (totalDays < 31) {\r\n return `${Math.floor(totalDays)}days`;\r\n }\r\n\r\n const totalMonths = totalDays / daysPerMonth;\r\n\r\n if (totalMonths <= 1) {\r\n return \"1mon\";\r\n }\r\n\r\n if (totalMonths <= 18) {\r\n return `${Math.round(totalMonths)}mon`;\r\n }\r\n\r\n const totalYears = totalDays / daysPerYear;\r\n\r\n if (totalYears <= 1) {\r\n return \"1yr\";\r\n }\r\n\r\n return `${Math.round(totalYears)}yrs`;\r\n }\r\n\r\n /**\r\n * Formats this instance as a string that can be used in HTTP headers and\r\n * cookies.\r\n *\r\n * @returns A new string that conforms to RFC 1123\r\n */\r\n public toHTTPString(): string {\r\n return this.dateTime.toHTTP();\r\n }\r\n\r\n /**\r\n * Get the value of the date and time in a format that can be used in\r\n * comparisons.\r\n *\r\n * @returns A number that represents the date and time.\r\n */\r\n public valueOf(): number {\r\n return this.dateTime.valueOf();\r\n }\r\n\r\n /**\r\n * Creates a standard string representation of the date and time.\r\n *\r\n * @returns A string representation of the date and time.\r\n */\r\n public toString(): string {\r\n return this.toLocaleString(DateTimeFormat.DateTimeFull);\r\n }\r\n\r\n /**\r\n * Checks if this instance is equal to another RockDateTime instance. This\r\n * will return true if the two instances represent the same point in time,\r\n * even if they have been associated with different time zones. In other\r\n * words \"2021-09-08 12:00:00 Z\" == \"2021-09-08 14:00:00 UTC+2\".\r\n *\r\n * @param otherDateTime The other RockDateTime to be compared against.\r\n *\r\n * @returns True if the two instances represent the same point in time.\r\n */\r\n public isEqualTo(otherDateTime: RockDateTime): boolean {\r\n return this.dateTime.toMillis() === otherDateTime.dateTime.toMillis();\r\n }\r\n\r\n /**\r\n * Checks if this instance is later than another RockDateTime instance.\r\n *\r\n * @param otherDateTime The other RockDateTime to be compared against.\r\n *\r\n * @returns True if this instance represents a point in time that occurred after another point in time, regardless of time zone.\r\n */\r\n public isLaterThan(otherDateTime: RockDateTime): boolean {\r\n return this.dateTime.toMillis() > otherDateTime.dateTime.toMillis();\r\n }\r\n\r\n /**\r\n * Checks if this instance is earlier than another RockDateTime instance.\r\n *\r\n * @param otherDateTime The other RockDateTime to be compared against.\r\n *\r\n * @returns True if this instance represents a point in time that occurred before another point in time, regardless of time zone.\r\n */\r\n public isEarlierThan(otherDateTime: RockDateTime): boolean {\r\n return this.dateTime.toMillis() < otherDateTime.dateTime.toMillis();\r\n }\r\n\r\n /**\r\n * Calculates the elapsed time between this date and the reference date and\r\n * returns that difference in a human friendly way.\r\n *\r\n * @param otherDateTime The reference date and time. If not specified then 'now' is used.\r\n *\r\n * @returns A string that represents the elapsed time.\r\n */\r\n public humanizeElapsed(otherDateTime?: RockDateTime): string {\r\n otherDateTime = otherDateTime ?? RockDateTime.now();\r\n\r\n const totalSeconds = Math.floor((otherDateTime.dateTime.toMillis() - this.dateTime.toMillis()) / 1000);\r\n\r\n if (totalSeconds <= 1) {\r\n return \"right now\";\r\n }\r\n else if (totalSeconds < 60) { // 1 minute\r\n return `${totalSeconds} seconds ago`;\r\n }\r\n else if (totalSeconds < 3600) { // 1 hour\r\n return `${Math.floor(totalSeconds / 60)} minutes ago`;\r\n }\r\n else if (totalSeconds < 86400) { // 1 day\r\n return `${Math.floor(totalSeconds / 3600)} hours ago`;\r\n }\r\n else if (totalSeconds < 31536000) { // 1 year\r\n return `${Math.floor(totalSeconds / 86400)} days ago`;\r\n }\r\n else {\r\n return `${Math.floor(totalSeconds / 31536000)} years ago`;\r\n }\r\n }\r\n\r\n // #endregion\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { BlockEvent, InvokeBlockActionFunc, SecurityGrant } from \"@Obsidian/Types/Utility/block\";\r\nimport { IBlockPersonPreferencesProvider, IPersonPreferenceCollection } from \"@Obsidian/Types/Core/personPreferences\";\r\nimport { ExtendedRef } from \"@Obsidian/Types/Utility/component\";\r\nimport { DetailBlockBox } from \"@Obsidian/ViewModels/Blocks/detailBlockBox\";\r\nimport { inject, provide, Ref, ref, watch } from \"vue\";\r\nimport { RockDateTime } from \"./rockDateTime\";\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { HttpBodyData, HttpPostFunc, HttpResult } from \"@Obsidian/Types/Utility/http\";\r\nimport { BlockActionContextBag } from \"@Obsidian/ViewModels/Blocks/blockActionContextBag\";\r\n\r\nconst blockReloadSymbol = Symbol();\r\nconst configurationValuesChangedSymbol = Symbol();\r\nconst staticContentSymbol = Symbol();\r\n\r\n// TODO: Change these to use symbols\r\n\r\n/**\r\n * Maps the block configuration values to the expected type.\r\n *\r\n * @returns The configuration values for the block.\r\n */\r\nexport function useConfigurationValues(): T {\r\n const result = inject[>(\"configurationValues\");\r\n\r\n if (result === undefined) {\r\n throw \"Attempted to access block configuration outside of a RockBlock.\";\r\n }\r\n\r\n return result.value;\r\n}\r\n\r\n/**\r\n * Gets the function that will be used to invoke block actions.\r\n *\r\n * @returns An instance of @see {@link InvokeBlockActionFunc}.\r\n */\r\nexport function useInvokeBlockAction(): InvokeBlockActionFunc {\r\n const result = inject(\"invokeBlockAction\");\r\n\r\n if (result === undefined) {\r\n throw \"Attempted to access block action invocation outside of a RockBlock.\";\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Creates a function that can be provided to the block that allows calling\r\n * block actions.\r\n *\r\n * @private This should not be used by plugins.\r\n *\r\n * @param post The function to handle the post operation.\r\n * @param pageGuid The unique identifier of the page.\r\n * @param blockGuid The unique identifier of the block.\r\n * @param pageParameters The parameters to include with the block action calls.\r\n *\r\n * @returns A function that can be used to provide the invoke block action.\r\n */\r\nexport function createInvokeBlockAction(post: HttpPostFunc, pageGuid: Guid, blockGuid: Guid, pageParameters: Record): InvokeBlockActionFunc {\r\n async function invokeBlockAction(actionName: string, data: HttpBodyData | undefined = undefined, actionContext: BlockActionContextBag | undefined = undefined): Promise> {\r\n let context: BlockActionContextBag = {};\r\n\r\n if (actionContext) {\r\n context = {...actionContext};\r\n }\r\n\r\n context.pageParameters = pageParameters;\r\n\r\n return await post(`/api/v2/BlockActions/${pageGuid}/${blockGuid}/${actionName}`, undefined, {\r\n __context: context,\r\n ...data\r\n });\r\n }\r\n\r\n return invokeBlockAction;\r\n}\r\n\r\n/**\r\n * Provides the reload block callback function for a block. This is an internal\r\n * method and should not be used by plugins.\r\n *\r\n * @param callback The callback that will be called when a block wants to reload itself.\r\n */\r\nexport function provideReloadBlock(callback: () => void): void {\r\n provide(blockReloadSymbol, callback);\r\n}\r\n\r\n/**\r\n * Gets a function that can be called when a block wants to reload itself.\r\n *\r\n * @returns A function that will cause the block component to be reloaded.\r\n */\r\nexport function useReloadBlock(): () => void {\r\n return inject<() => void>(blockReloadSymbol, () => {\r\n // Intentionally blank, do nothing by default.\r\n });\r\n}\r\n\r\n/**\r\n * Provides the data for a block to be notified when its configuration values\r\n * have changed. This is an internal method and should not be used by plugins.\r\n *\r\n * @returns An object with an invoke and reset function.\r\n */\r\nexport function provideConfigurationValuesChanged(): { invoke: () => void, reset: () => void } {\r\n const callbacks: (() => void)[] = [];\r\n\r\n provide(configurationValuesChangedSymbol, callbacks);\r\n\r\n return {\r\n invoke: (): void => {\r\n for (const c of callbacks) {\r\n c();\r\n }\r\n },\r\n\r\n reset: (): void => {\r\n callbacks.splice(0, callbacks.length);\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Registered a function to be called when the block configuration values have\r\n * changed.\r\n *\r\n * @param callback The function to be called when the configuration values have changed.\r\n */\r\nexport function onConfigurationValuesChanged(callback: () => void): void {\r\n const callbacks = inject<(() => void)[]>(configurationValuesChangedSymbol);\r\n\r\n if (callbacks !== undefined) {\r\n callbacks.push(callback);\r\n }\r\n}\r\n\r\n/**\r\n * Provides the static content that the block provided on the server.\r\n *\r\n * @param content The static content from the server.\r\n */\r\nexport function provideStaticContent(content: string | undefined): void {\r\n provide(staticContentSymbol, content);\r\n}\r\n\r\n/**\r\n * Gets the static content that was provided by the block on the server.\r\n *\r\n * @returns A string of HTML content or undefined.\r\n */\r\nexport function useStaticContent(): string | undefined {\r\n return inject(staticContentSymbol);\r\n}\r\n\r\n\r\n/**\r\n * A type that returns the keys of a child property.\r\n */\r\ntype ChildKeys, PropertyName extends string> = keyof NonNullable & string;\r\n\r\n/**\r\n * A valid properties box that uses the specified name for the content bag.\r\n */\r\ntype ValidPropertiesBox = {\r\n validProperties?: string[] | null;\r\n} & {\r\n [P in PropertyName]?: Record | null;\r\n };\r\n\r\n/**\r\n * Sets the a value for a custom settings box. This will set the value and then\r\n * add the property name to the list of valid properties.\r\n *\r\n * @param box The box whose custom setting value will be set.\r\n * @param propertyName The name of the custom setting property to set.\r\n * @param value The new value of the custom setting.\r\n */\r\nexport function setCustomSettingsBoxValue, S extends NonNullable, K extends ChildKeys>(box: T, propertyName: K, value: S[K]): void {\r\n if (!box.settings) {\r\n box.settings = {} as Record;\r\n }\r\n\r\n box.settings[propertyName] = value;\r\n\r\n if (!box.validProperties) {\r\n box.validProperties = [];\r\n }\r\n\r\n if (!box.validProperties.includes(propertyName)) {\r\n box.validProperties.push(propertyName);\r\n }\r\n}\r\n\r\n/**\r\n * Sets the a value for a property box. This will set the value and then\r\n * add the property name to the list of valid properties.\r\n *\r\n * @param box The box whose property value will be set.\r\n * @param propertyName The name of the property on the bag to set.\r\n * @param value The new value of the property.\r\n */\r\nexport function setPropertiesBoxValue, S extends NonNullable, K extends ChildKeys>(box: T, propertyName: K, value: S[K]): void {\r\n if (!box.bag) {\r\n box.bag = {} as Record;\r\n }\r\n\r\n box.bag[propertyName] = value;\r\n\r\n if (!box.validProperties) {\r\n box.validProperties = [];\r\n }\r\n\r\n if (!box.validProperties.includes(propertyName)) {\r\n box.validProperties.push(propertyName);\r\n }\r\n}\r\n\r\n/**\r\n * Dispatches a block event to the document.\r\n *\r\n * @param eventName The name of the event to be dispatched.\r\n * @param eventData The custom data to be attached to the event.\r\n *\r\n * @returns true if preventDefault() was called on the event, otherwise false.\r\n */\r\nexport function dispatchBlockEvent(eventName: string, blockGuid: Guid, eventData?: unknown): boolean {\r\n const ev = new CustomEvent(eventName, {\r\n cancelable: true,\r\n detail: {\r\n guid: blockGuid,\r\n data: eventData\r\n }\r\n });\r\n\r\n return document.dispatchEvent(ev);\r\n}\r\n\r\n/**\r\n * Tests if the given event is a custom block event. This does not ensure\r\n * that the event data is the correct type, only the event itself.\r\n *\r\n * @param event The event to be tested.\r\n *\r\n * @returns true if the event is a block event.\r\n */\r\nexport function isBlockEvent(event: Event): event is CustomEvent> {\r\n return \"guid\" in event && \"data\" in event;\r\n}\r\n\r\n\r\n// #region Security Grants\r\n\r\nconst securityGrantSymbol = Symbol();\r\n\r\n/**\r\n * Use a security grant token value provided by the server. This returns a reference\r\n * to the actual value and will automatically handle renewing the token and updating\r\n * the value. This function is meant to be used by blocks. Controls should use the\r\n * useSecurityGrant() function instead.\r\n *\r\n * @param token The token provided by the server.\r\n *\r\n * @returns A reference to the security grant that will be updated automatically when it has been renewed.\r\n */\r\nexport function getSecurityGrant(token: string | null | undefined): SecurityGrant {\r\n // Use || so that an empty string gets converted to null.\r\n const tokenRef = ref(token || null);\r\n const invokeBlockAction = useInvokeBlockAction();\r\n let renewalTimeout: NodeJS.Timeout | null = null;\r\n\r\n // Internal function to renew the token and re-schedule renewal.\r\n const renewToken = async (): Promise => {\r\n const result = await invokeBlockAction(\"RenewSecurityGrantToken\");\r\n\r\n if (result.isSuccess && result.data) {\r\n tokenRef.value = result.data;\r\n\r\n scheduleRenewal();\r\n }\r\n };\r\n\r\n // Internal function to schedule renewal based on the expiration date in\r\n // the existing token. Renewal happens 15 minutes before expiration.\r\n const scheduleRenewal = (): void => {\r\n // Cancel any existing renewal timer.\r\n if (renewalTimeout !== null) {\r\n clearTimeout(renewalTimeout);\r\n renewalTimeout = null;\r\n }\r\n\r\n // No token, nothing to do.\r\n if (tokenRef.value === null) {\r\n return;\r\n }\r\n\r\n const segments = tokenRef.value?.split(\";\");\r\n\r\n // Token not in expected format.\r\n if (segments.length !== 3 || segments[0] !== \"1\") {\r\n return;\r\n }\r\n\r\n const expiresDateTime = RockDateTime.parseISO(segments[1]);\r\n\r\n // Could not parse expiration date and time.\r\n if (expiresDateTime === null) {\r\n return;\r\n }\r\n\r\n const renewTimeout = expiresDateTime.addMinutes(-15).toMilliseconds() - RockDateTime.now().toMilliseconds();\r\n\r\n // Renewal request would be in the past, ignore.\r\n if (renewTimeout < 0) {\r\n return;\r\n }\r\n\r\n // Schedule the renewal task to happen 15 minutes before expiration.\r\n renewalTimeout = setTimeout(renewToken, renewTimeout);\r\n };\r\n\r\n scheduleRenewal();\r\n\r\n return {\r\n token: tokenRef,\r\n updateToken(newToken) {\r\n tokenRef.value = newToken || null;\r\n scheduleRenewal();\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Provides the security grant to child components to use in their API calls.\r\n *\r\n * @param grant The grant ot provide to child components.\r\n */\r\nexport function provideSecurityGrant(grant: SecurityGrant): void {\r\n provide(securityGrantSymbol, grant);\r\n}\r\n\r\n/**\r\n * Uses a previously provided security grant token by a parent component.\r\n * This function is meant to be used by controls that need to obtain a security\r\n * grant from a parent component.\r\n *\r\n * @returns A string reference that contains the security grant token.\r\n */\r\nexport function useSecurityGrantToken(): Ref {\r\n const grant = inject(securityGrantSymbol);\r\n\r\n return grant ? grant.token : ref(null);\r\n}\r\n\r\n// #endregion\r\n\r\n// #region Extended References\r\n\r\n/** An emit object that conforms to having a propertyChanged event. */\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\nexport type PropertyChangedEmitFn = E extends Array ? (event: EE, ...args: any[]) => void : (event: E, ...args: any[]) => void;\r\n\r\n/**\r\n * Watches for changes to the given Ref objects and emits a special event to\r\n * indicate that a given property has changed.\r\n *\r\n * @param propertyRefs The ExtendedRef objects to watch for changes.\r\n * @param emit The emit function for the component.\r\n */\r\nexport function watchPropertyChanges(propertyRefs: ExtendedRef[], emit: PropertyChangedEmitFn): void {\r\n for (const propRef of propertyRefs) {\r\n watch(propRef, () => {\r\n if (propRef.context.propertyName) {\r\n emit(\"propertyChanged\", propRef.context.propertyName);\r\n }\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * Requests an updated attribute list from the server based on the\r\n * current UI selections made.\r\n *\r\n * @param bag The entity bag that will be used to determine current property values\r\n * and then updated with the new attributes and values.\r\n * @param validProperties The properties that are considered valid on the bag when\r\n * the server will read the bag.\r\n * @param invokeBlockAction The function to use when calling the block action.\r\n */\r\nexport async function refreshDetailAttributes(bag: Ref, validProperties: string[], invokeBlockAction: InvokeBlockActionFunc): Promise {\r\n const data: DetailBlockBox = {\r\n entity: bag.value,\r\n isEditable: true,\r\n validProperties: validProperties\r\n };\r\n\r\n const result = await invokeBlockAction, unknown>>(\"RefreshAttributes\", {\r\n box: data\r\n });\r\n\r\n if (result.isSuccess) {\r\n if (result.statusCode === 200 && result.data && bag.value) {\r\n const newBag: TEntityBag = {\r\n ...bag.value,\r\n attributes: result.data.entity?.attributes,\r\n attributeValues: result.data.entity?.attributeValues\r\n };\r\n\r\n bag.value = newBag;\r\n }\r\n }\r\n}\r\n\r\n// #endregion Extended Refs\r\n\r\n// #region Block Guid\r\n\r\nconst blockGuidSymbol = Symbol(\"block-guid\");\r\n\r\n/**\r\n * Provides the block unique identifier to all child components.\r\n * This is an internal method and should not be used by plugins.\r\n *\r\n * @param blockGuid The unique identifier of the block.\r\n */\r\nexport function provideBlockGuid(blockGuid: string): void {\r\n provide(blockGuidSymbol, blockGuid);\r\n}\r\n\r\n/**\r\n * Gets the unique identifier of the current block in this component chain.\r\n *\r\n * @returns The unique identifier of the block.\r\n */\r\nexport function useBlockGuid(): Guid | undefined {\r\n return inject(blockGuidSymbol);\r\n}\r\n\r\n// #endregion\r\n\r\n// #region Person Preferences\r\n\r\nconst blockPreferenceProviderSymbol = Symbol();\r\n\r\n/** An no-op implementation of {@link IPersonPreferenceCollection}. */\r\nconst emptyPreferences: IPersonPreferenceCollection = {\r\n getValue(): string {\r\n return \"\";\r\n },\r\n setValue(): void {\r\n // Intentionally empty.\r\n },\r\n getKeys(): string[] {\r\n return [];\r\n },\r\n containsKey(): boolean {\r\n return false;\r\n },\r\n save(): Promise {\r\n return Promise.resolve();\r\n },\r\n withPrefix(): IPersonPreferenceCollection {\r\n return emptyPreferences;\r\n }\r\n};\r\n\r\nconst emptyPreferenceProvider: IBlockPersonPreferencesProvider = {\r\n blockPreferences: emptyPreferences,\r\n getGlobalPreferences() {\r\n return Promise.resolve(emptyPreferences);\r\n },\r\n getEntityPreferences() {\r\n return Promise.resolve(emptyPreferences);\r\n }\r\n};\r\n\r\n/**\r\n * Provides the person preferences provider that will be used by components\r\n * to access the person preferences associated with their block.\r\n *\r\n * @private This is an internal method and should not be used by plugins.\r\n *\r\n * @param blockGuid The unique identifier of the block.\r\n */\r\nexport function providePersonPreferences(provider: IBlockPersonPreferencesProvider): void {\r\n provide(blockPreferenceProviderSymbol, provider);\r\n}\r\n\r\n/**\r\n * Gets the person preference provider that can be used to access block\r\n * preferences as well as other preferences.\r\n *\r\n * @returns An object that implements {@link IBlockPersonPreferencesProvider}.\r\n */\r\nexport function usePersonPreferences(): IBlockPersonPreferencesProvider {\r\n return inject(blockPreferenceProviderSymbol)\r\n ?? emptyPreferenceProvider;\r\n}\r\n\r\n// #endregion\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/**\r\n * Transform the value into true, false, or null\r\n * @param val\r\n */\r\nexport function asBooleanOrNull(val: unknown): boolean | null {\r\n if (val === undefined || val === null) {\r\n return null;\r\n }\r\n\r\n if (typeof val === \"boolean\") {\r\n return val;\r\n }\r\n\r\n if (typeof val === \"string\") {\r\n const asString = (val || \"\").trim().toLowerCase();\r\n\r\n if (!asString) {\r\n return null;\r\n }\r\n\r\n return [\"true\", \"yes\", \"t\", \"y\", \"1\"].indexOf(asString) !== -1;\r\n }\r\n\r\n if (typeof val === \"number\") {\r\n return !!val;\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * Transform the value into true or false\r\n * @param val\r\n */\r\nexport function asBoolean(val: unknown): boolean {\r\n return !!asBooleanOrNull(val);\r\n}\r\n\r\n/** Transform the value into the strings \"Yes\", \"No\", or null */\r\nexport function asYesNoOrNull(val: unknown): \"Yes\" | \"No\" | null {\r\n const boolOrNull = asBooleanOrNull(val);\r\n\r\n if (boolOrNull === null) {\r\n return null;\r\n }\r\n\r\n return boolOrNull ? \"Yes\" : \"No\";\r\n}\r\n\r\n/** Transform the value into the strings \"True\", \"False\", or null */\r\nexport function asTrueFalseOrNull(val: unknown): \"True\" | \"False\" | null {\r\n const boolOrNull = asBooleanOrNull(val);\r\n\r\n if (boolOrNull === null) {\r\n return null;\r\n }\r\n\r\n return boolOrNull ? \"True\" : \"False\";\r\n}\r\n\r\n/** Transform the value into the strings \"True\" if truthy or \"False\" if falsey */\r\nexport function asTrueOrFalseString(val: unknown): \"True\" | \"False\" {\r\n const boolOrNull = asBooleanOrNull(val);\r\n\r\n return boolOrNull ? \"True\" : \"False\";\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\nimport mitt from \"mitt\";\r\nimport { RockDateTime } from \"./rockDateTime\";\r\n\r\n/**\r\n * The bus allows page components to send and receive arbitrary data from other page components.\r\n */\r\ntype LogItem = {\r\n date: RockDateTime;\r\n message: string;\r\n};\r\n\r\nconst bus = mitt();\r\nconst log: LogItem[] = [];\r\n\r\n/**\r\n* Write a log entry that a payload was sent or received.\r\n*/\r\nconst writeLog = (msg: string): void => {\r\n log.push({\r\n date: RockDateTime.now(),\r\n message: msg\r\n });\r\n};\r\n\r\n/**\r\n* Send the payload to subscribers listening for the event name\r\n*/\r\nfunction publish(eventName: string, payload: T): void {\r\n writeLog(`Published ${eventName}`);\r\n bus.emit(eventName, payload);\r\n}\r\n\r\n/**\r\n* Whenever an event is received of eventName, the callback is executed with the message\r\n* payload as a parameter.\r\n*/\r\nfunction subscribe(eventName: string, callback: (payload: T) => void): void {\r\n writeLog(`Subscribed to ${eventName}`);\r\n bus.on(eventName, payload => {\r\n if (payload) {\r\n callback(payload as T);\r\n }\r\n });\r\n}\r\n\r\nexport default {\r\n publish,\r\n subscribe,\r\n log\r\n};\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport { RockDateTime } from \"./rockDateTime\";\r\n\r\n//\r\ntype CacheEntry = {\r\n value: T;\r\n expiration: number;\r\n};\r\n\r\n/**\r\n* Stores the value using the given key. The cache will expire at the expiration or in\r\n* 1 minute if none is provided\r\n* @param key\r\n* @param value\r\n* @param expiration\r\n*/\r\nfunction set(key: string, value: T, expirationDT: RockDateTime | null = null): void {\r\n let expiration: number;\r\n\r\n if (expirationDT) {\r\n expiration = expirationDT.toMilliseconds();\r\n }\r\n else {\r\n // Default to one minute\r\n expiration = RockDateTime.now().addMinutes(1).toMilliseconds();\r\n }\r\n\r\n const cache: CacheEntry = { expiration, value };\r\n const cacheJson = JSON.stringify(cache);\r\n sessionStorage.setItem(key, cacheJson);\r\n}\r\n\r\n/**\r\n * Gets a stored cache value if there is one that has not yet expired.\r\n * @param key\r\n */\r\nfunction get(key: string): T | null {\r\n const cacheJson = sessionStorage.getItem(key);\r\n\r\n if (!cacheJson) {\r\n return null;\r\n }\r\n\r\n const cache = JSON.parse(cacheJson) as CacheEntry;\r\n\r\n if (!cache || !cache.expiration) {\r\n return null;\r\n }\r\n\r\n if (cache.expiration < RockDateTime.now().toMilliseconds()) {\r\n return null;\r\n }\r\n\r\n return cache.value;\r\n}\r\n\r\nconst promiseCache: Record | undefined> = {};\r\n\r\n/**\r\n * Since Promises can't be cached, we need to store them in memory until we get the result back. This wraps\r\n * a function in another function that returns a promise and...\r\n * - If there's a cached result, return it\r\n * - Otherwise if there's a cached Promise, return it\r\n * - Otherwise call the given function and cache it's promise and return it. Once the the Promise resolves, cache its result\r\n *\r\n * @param key Key for identifying the cached values\r\n * @param fn Function that returns a Promise that we want to cache the value of\r\n *\r\n */\r\nfunction cachePromiseFactory(key: string, fn: () => Promise, expiration: RockDateTime | null = null): () => Promise {\r\n return async function (): Promise {\r\n // If it's cached, grab it\r\n const cachedResult = get(key);\r\n if (cachedResult) {\r\n return cachedResult;\r\n }\r\n\r\n // If it's not cached yet but we've already started fetching it\r\n // (it's not cached until we receive the results), return the existing Promise\r\n if (promiseCache[key]) {\r\n return promiseCache[key] as Promise;\r\n }\r\n\r\n // Not stored anywhere, so fetch it and save it on the stored Promise for the next call\r\n promiseCache[key] = fn();\r\n\r\n // Once it's resolved, cache the result\r\n promiseCache[key]?.then((result) => {\r\n set(key, result, expiration);\r\n delete promiseCache[key];\r\n return result;\r\n }).catch((e: Error) => {\r\n // Something's wrong, let's get rid of the stored promise, so we can try again.\r\n delete promiseCache[key];\r\n throw e;\r\n });\r\n\r\n return promiseCache[key] as Promise;\r\n };\r\n}\r\n\r\n\r\nexport default {\r\n set,\r\n get,\r\n cachePromiseFactory: cachePromiseFactory\r\n};\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport mitt, { Emitter } from \"mitt\";\r\n\r\n// NOTE: Much of the logic for this was taken from VSCode's MIT licensed version:\r\n// https://github.com/microsoft/vscode/blob/342394d1e7d43d3324dc2ede1d634cffd52ba159/src/vs/base/common/cancellation.ts\r\n\r\n/**\r\n * A cancellation token can be used to instruct some operation to run but abort\r\n * if a certain condition is met.\r\n */\r\nexport interface ICancellationToken {\r\n /**\r\n * A flag signalling is cancellation has been requested.\r\n */\r\n readonly isCancellationRequested: boolean;\r\n\r\n /**\r\n * Registers a listener for when cancellation has been requested. This event\r\n * only ever fires `once` as cancellation can only happen once. Listeners\r\n * that are registered after cancellation will be called (next event loop run),\r\n * but also only once.\r\n *\r\n * @param listener The function to be called when the token has been cancelled.\r\n */\r\n onCancellationRequested(listener: () => void): void;\r\n}\r\n\r\nfunction shortcutCancelledEvent(listener: () => void): void {\r\n window.setTimeout(listener, 0);\r\n}\r\n\r\n/**\r\n * Determines if something is a cancellation token.\r\n *\r\n * @param thing The thing to be checked to see if it is a cancellation token.\r\n *\r\n * @returns true if the @{link thing} is a cancellation token, otherwise false.\r\n */\r\nexport function isCancellationToken(thing: unknown): thing is ICancellationToken {\r\n if (thing === CancellationTokenNone || thing === CancellationTokenCancelled) {\r\n return true;\r\n }\r\n if (thing instanceof MutableToken) {\r\n return true;\r\n }\r\n if (!thing || typeof thing !== \"object\") {\r\n return false;\r\n }\r\n return typeof (thing as ICancellationToken).isCancellationRequested === \"boolean\"\r\n && typeof (thing as ICancellationToken).onCancellationRequested === \"function\";\r\n}\r\n\r\n/**\r\n * A cancellation token that will never be in a cancelled state.\r\n */\r\nexport const CancellationTokenNone = Object.freeze({\r\n isCancellationRequested: false,\r\n onCancellationRequested() {\r\n // Intentionally blank.\r\n }\r\n});\r\n\r\n/**\r\n * A cancellation token that is already in a cancelled state.\r\n */\r\nexport const CancellationTokenCancelled = Object.freeze({\r\n isCancellationRequested: true,\r\n onCancellationRequested: shortcutCancelledEvent\r\n});\r\n\r\n/**\r\n * Internal implementation of a cancellation token that starts initially as\r\n * active but can later be switched to a cancelled state.\r\n */\r\nclass MutableToken implements ICancellationToken {\r\n private isCancelled: boolean = false;\r\n private emitter: Emitter> | null = null;\r\n\r\n /**\r\n * Cancels the token and fires any registered event listeners.\r\n */\r\n public cancel(): void {\r\n if (!this.isCancelled) {\r\n this.isCancelled = true;\r\n if (this.emitter) {\r\n this.emitter.emit(\"cancel\", undefined);\r\n this.emitter = null;\r\n }\r\n }\r\n }\r\n\r\n // #region ICancellationToken implementation\r\n\r\n get isCancellationRequested(): boolean {\r\n return this.isCancelled;\r\n }\r\n\r\n onCancellationRequested(listener: () => void): void {\r\n if (this.isCancelled) {\r\n return shortcutCancelledEvent(listener);\r\n }\r\n\r\n if (!this.emitter) {\r\n this.emitter = mitt();\r\n }\r\n\r\n this.emitter.on(\"cancel\", listener);\r\n }\r\n\r\n // #endregion\r\n}\r\n\r\n/**\r\n * Creates a source instance that can be used to trigger a cancellation\r\n * token into the cancelled state.\r\n */\r\nexport class CancellationTokenSource {\r\n /** The token that can be passed to functions. */\r\n private internalToken?: ICancellationToken = undefined;\r\n\r\n /**\r\n * Creates a new instance of {@link CancellationTokenSource}.\r\n *\r\n * @param parent The parent cancellation token that will also cancel this source.\r\n */\r\n constructor(parent?: ICancellationToken) {\r\n if (parent) {\r\n parent.onCancellationRequested(() => this.cancel());\r\n }\r\n }\r\n\r\n /**\r\n * The cancellation token that can be used to determine when the task\r\n * should be cancelled.\r\n */\r\n get token(): ICancellationToken {\r\n if (!this.internalToken) {\r\n // be lazy and create the token only when\r\n // actually needed\r\n this.internalToken = new MutableToken();\r\n }\r\n\r\n return this.internalToken;\r\n }\r\n\r\n /**\r\n * Moves the token into a cancelled state.\r\n */\r\n cancel(): void {\r\n if (!this.internalToken) {\r\n // Save an object creation by returning the default cancelled\r\n // token when cancellation happens before someone asks for the\r\n // token.\r\n this.internalToken = CancellationTokenCancelled;\r\n\r\n }\r\n else if (this.internalToken instanceof MutableToken) {\r\n // Actually cancel the existing token.\r\n this.internalToken.cancel();\r\n }\r\n }\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/**\r\n * Compares two values for equality by performing deep nested comparisons\r\n * if the values are objects or arrays.\r\n * \r\n * @param a The first value to compare.\r\n * @param b The second value to compare.\r\n * @param strict True if strict comparision is required (meaning 1 would not equal \"1\").\r\n *\r\n * @returns True if the two values are equal to each other.\r\n */\r\nexport function deepEqual(a: unknown, b: unknown, strict: boolean): boolean {\r\n // Catches everything but objects.\r\n if (strict && a === b) {\r\n return true;\r\n }\r\n else if (!strict && a == b) {\r\n return true;\r\n }\r\n\r\n // NaN never equals another NaN, but functionally they are the same.\r\n if (typeof a === \"number\" && typeof b === \"number\" && isNaN(a) && isNaN(b)) {\r\n return true;\r\n }\r\n\r\n // Remaining value types must both be of type object\r\n if (a && b && typeof a === \"object\" && typeof b === \"object\") {\r\n // Array status must match.\r\n if (Array.isArray(a) !== Array.isArray(b)) {\r\n return false;\r\n }\r\n\r\n if (Array.isArray(a) && Array.isArray(b)) {\r\n // Array lengths must match.\r\n if (a.length !== b.length) {\r\n return false;\r\n }\r\n\r\n // Each element in the array must match.\r\n for (let i = 0; i < a.length; i++) {\r\n if (!deepEqual(a[i], b[i], strict)) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n else {\r\n // NOTE: There are a few edge cases not accounted for here, but they\r\n // are rare and unusual:\r\n // Map, Set, ArrayBuffer, RegExp\r\n\r\n // The objects must be of the same \"object type\".\r\n if (a.constructor !== b.constructor) {\r\n return false;\r\n }\r\n\r\n // Get all the key/value pairs of each object and sort them so they\r\n // are in the same order as each other.\r\n const aEntries = Object.entries(a).sort((a, b) => a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0));\r\n const bEntries = Object.entries(b).sort((a, b) => a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0));\r\n\r\n // Key/value count must be identical.\r\n if (aEntries.length !== bEntries.length) {\r\n return false;\r\n }\r\n\r\n for (let i = 0; i < aEntries.length; i++) {\r\n const aEntry = aEntries[i];\r\n const bEntry = bEntries[i];\r\n\r\n // Ensure the keys are equal, must always be strict.\r\n if (!deepEqual(aEntry[0], bEntry[0], true)) {\r\n return false;\r\n }\r\n\r\n // Ensure the values are equal.\r\n if (!deepEqual(aEntry[1], bEntry[1], strict)) {\r\n return false;\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n}\r\n\r\n\r\n/**\r\n * Debounces the function so it will only be called once during the specified\r\n * delay period. The returned function should be called to trigger the original\r\n * function that is to be debounced.\r\n * \r\n * @param fn The function to be called once per delay period.\r\n * @param delay The period in milliseconds. If the returned function is called\r\n * more than once during this period then fn will only be executed once for\r\n * the period. If not specified then it defaults to 250ms.\r\n * @param eager If true then the fn function will be called immediately and\r\n * then any subsequent calls will be debounced.\r\n *\r\n * @returns A function to be called when fn should be executed.\r\n */\r\nexport function debounce(fn: (() => void), delay: number = 250, eager: boolean = false): (() => void) {\r\n let timeout: NodeJS.Timeout | null = null;\r\n\r\n return (): void => {\r\n if (timeout) {\r\n clearTimeout(timeout);\r\n }\r\n else if (eager) {\r\n // If there was no previous timeout and we are configured for\r\n // eager calls, then execute now.\r\n fn();\r\n\r\n // An eager call should not result in a final debounce call.\r\n timeout = setTimeout(() => timeout = null, delay);\r\n\r\n return;\r\n }\r\n\r\n // If we had a previous timeout or we are not set for eager calls\r\n // then set a timeout to initiate the function after the delay.\r\n timeout = setTimeout(() => {\r\n timeout = null;\r\n fn();\r\n }, delay);\r\n };\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { newGuid } from \"./guid\";\r\nimport { inject, nextTick, provide } from \"vue\";\r\n\r\nconst suspenseSymbol = Symbol(\"RockSuspense\");\r\n\r\n/**\r\n * Defines the interface for a provider of suspense monitoring. These are used\r\n * to track asynchronous operations that components may be performing so the\r\n * watching component can perform an operation once all pending operations\r\n * have completed.\r\n */\r\nexport interface ISuspenseProvider {\r\n /**\r\n * Adds a new operation identified by the promise. When the promise\r\n * either resolves or fails the operation is considered completed.\r\n *\r\n * @param operation The promise that represents the operation.\r\n */\r\n addOperation(operation: Promise): void;\r\n\r\n /**\r\n * Notes that an asynchronous operation has started on a child component.\r\n *\r\n * @param key The key that identifies the operation.\r\n */\r\n startAsyncOperation(key: Guid): void;\r\n\r\n /**\r\n * Notes that an asynchrounous operation has completed on a child component.\r\n *\r\n * @param key The key that was previously passed to startAsyncOperation.\r\n */\r\n completeAsyncOperation(key: Guid): void;\r\n}\r\n\r\n/**\r\n * A basic provider that handles the guts of a suspense provider. This can be\r\n * used by components that need to know when child components have completed\r\n * their work.\r\n */\r\nexport class BasicSuspenseProvider implements ISuspenseProvider {\r\n private readonly operationKey: Guid;\r\n\r\n private readonly parentProvider: ISuspenseProvider | undefined;\r\n\r\n private readonly pendingOperations: Guid[];\r\n\r\n private finishedHandlers: (() => void)[];\r\n\r\n /**\r\n * Creates a new suspense provider.\r\n *\r\n * @param parentProvider The parent suspense provider that will be notified of pending operations.\r\n */\r\n constructor(parentProvider: ISuspenseProvider | undefined) {\r\n this.operationKey = newGuid();\r\n this.parentProvider = parentProvider;\r\n this.pendingOperations = [];\r\n this.finishedHandlers = [];\r\n }\r\n\r\n /**\r\n * Called when all pending operations are complete. Notifies all handlers\r\n * that the pending operations have completed as well as the parent provider.\r\n */\r\n private allOperationsComplete(): void {\r\n // Wait until the next Vue tick in case a new async operation started.\r\n // This can happen, for example, with defineAsyncComponent(). It will\r\n // complete its async operation (loading the JS file) and then the\r\n // component defined in the file might start an async operation. This\r\n // prevents us from completing too soon.\r\n nextTick(() => {\r\n // Verify nothing started a new asynchronous operation while we\r\n // we waiting for the next tick.\r\n if (this.pendingOperations.length !== 0) {\r\n return;\r\n }\r\n\r\n // Notify all pending handlers that all operations completed.\r\n for (const handler of this.finishedHandlers) {\r\n handler();\r\n }\r\n this.finishedHandlers = [];\r\n\r\n // Notify the parent that our own pending operation has completed.\r\n if (this.parentProvider) {\r\n this.parentProvider.completeAsyncOperation(this.operationKey);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Adds a new operation identified by the promise. When the promise\r\n * either resolves or fails the operation is considered completed.\r\n *\r\n * @param operation The promise that represents the operation.\r\n */\r\n public addOperation(operation: Promise): void {\r\n const operationKey = newGuid();\r\n\r\n this.startAsyncOperation(operationKey);\r\n\r\n operation.then(() => this.completeAsyncOperation(operationKey))\r\n .catch(() => this.completeAsyncOperation(operationKey));\r\n }\r\n\r\n /**\r\n * Notes that an asynchronous operation has started on a child component.\r\n *\r\n * @param key The key that identifies the operation.\r\n */\r\n public startAsyncOperation(key: Guid): void {\r\n this.pendingOperations.push(key);\r\n\r\n // If this is the first operation we started, notify the parent provider.\r\n if (this.pendingOperations.length === 1 && this.parentProvider) {\r\n this.parentProvider.startAsyncOperation(this.operationKey);\r\n }\r\n }\r\n\r\n /**\r\n * Notes that an asynchrounous operation has completed on a child component.\r\n *\r\n * @param key The key that was previously passed to startAsyncOperation.\r\n */\r\n public completeAsyncOperation(key: Guid): void {\r\n const index = this.pendingOperations.indexOf(key);\r\n\r\n if (index !== -1) {\r\n this.pendingOperations.splice(index, 1);\r\n }\r\n\r\n // If this was the last operation then send notifications.\r\n if (this.pendingOperations.length === 0) {\r\n this.allOperationsComplete();\r\n }\r\n }\r\n\r\n /**\r\n * Checks if this provider has any asynchronous operations that are still\r\n * pending completion.\r\n *\r\n * @returns true if there are pending operations; otherwise false.\r\n */\r\n public hasPendingOperations(): boolean {\r\n return this.pendingOperations.length > 0;\r\n }\r\n\r\n /**\r\n * Adds a new handler that is called when all pending operations have been\r\n * completed. This is a fire-once, meaning the callback will only be called\r\n * when the current pending operations have completed. If new operations\r\n * begin after the callback is executed it will not be called again unless\r\n * it is added with this method again.\r\n *\r\n * @param callback The function to call when all pending operations have completed.\r\n */\r\n public addFinishedHandler(callback: () => void): void {\r\n this.finishedHandlers.push(callback);\r\n }\r\n}\r\n\r\n/**\r\n * Provides a new suspense provider to any child components.\r\n *\r\n * @param provider The provider to make available to child components.\r\n */\r\nexport function provideSuspense(provider: ISuspenseProvider): void {\r\n provide(suspenseSymbol, provider);\r\n}\r\n\r\n/**\r\n * Uses the current suspense provider that was defined by any parent component.\r\n *\r\n * @returns The suspense provider if one was defined; otherwise undefined.\r\n */\r\nexport function useSuspense(): ISuspenseProvider | undefined {\r\n return inject(suspenseSymbol);\r\n}\r\n\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport { CurrencyInfoBag } from \"../ViewModels/Rest/Utilities/currencyInfoBag\";\r\n\r\n// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat\r\n// Number.toLocaleString takes the same options as Intl.NumberFormat\r\n// Most of the options probably won't get used, so just add the ones you need to use to this when needed\r\ntype NumberFormatOptions = {\r\n useGrouping?: boolean // MDN gives other possible values, but TS is complaining that it should only be boolean\r\n};\r\n\r\n/**\r\n * Get a formatted string.\r\n * Ex: 10001.2 => 10,001.2\r\n * @param num\r\n */\r\nexport function asFormattedString(num: number | null, digits?: number, options: NumberFormatOptions = {}): string {\r\n if (num === null) {\r\n return \"\";\r\n }\r\n\r\n return num.toLocaleString(\r\n \"en-US\",\r\n {\r\n minimumFractionDigits: digits,\r\n maximumFractionDigits: digits ?? 9,\r\n ...options\r\n }\r\n );\r\n}\r\n\r\n/**\r\n * Get a number value from a formatted string. If the number cannot be parsed, then zero is returned by default.\r\n * Ex: $1,000.20 => 1000.2\r\n * @param str\r\n */\r\nexport function toNumber(str?: string | number | null): number {\r\n return toNumberOrNull(str) || 0;\r\n}\r\n\r\n/**\r\n * Get a number value from a formatted string. If the number cannot be parsed, then null is returned by default.\r\n * Ex: $1,000.20 => 1000.2\r\n * @param str\r\n */\r\nexport function toNumberOrNull(str?: string | number | null): number | null {\r\n if (str === null || str === undefined || str === \"\") {\r\n return null;\r\n }\r\n\r\n if (typeof str === \"number\") {\r\n return str;\r\n }\r\n\r\n const replaced = str.replace(/[$,]/g, \"\");\r\n const num = Number(replaced);\r\n\r\n return !isNaN(num) ? num : null;\r\n}\r\n\r\n/**\r\n * Get a currency value from a string or number. If the number cannot be parsed, then null is returned by default.\r\n * Ex: 1000.20 => $1,000.20\r\n * @param value The value to be converted to a currency.\r\n */\r\nexport function toCurrencyOrNull(value?: string | number | null, currencyInfo: CurrencyInfoBag | null = null): string | null {\r\n if (typeof value === \"string\") {\r\n value = toNumberOrNull(value);\r\n }\r\n\r\n if (value === null || value === undefined) {\r\n return null;\r\n }\r\n const currencySymbol = currencyInfo?.symbol ?? \"$\";\r\n const currencyDecimalPlaces = currencyInfo?.decimalPlaces ?? 2;\r\n return `${currencySymbol}${asFormattedString(value, currencyDecimalPlaces)}`;\r\n}\r\n\r\n/**\r\n * Adds an ordinal suffix.\r\n * Ex: 1 => 1st\r\n * @param num\r\n */\r\nexport function toOrdinalSuffix(num?: number | null): string {\r\n if (!num) {\r\n return \"\";\r\n }\r\n\r\n const j = num % 10;\r\n const k = num % 100;\r\n\r\n if (j == 1 && k != 11) {\r\n return num + \"st\";\r\n }\r\n if (j == 2 && k != 12) {\r\n return num + \"nd\";\r\n }\r\n if (j == 3 && k != 13) {\r\n return num + \"rd\";\r\n }\r\n return num + \"th\";\r\n}\r\n\r\n/**\r\n * Convert a number to an ordinal.\r\n * Ex: 1 => first\r\n * @param num\r\n */\r\nexport function toOrdinal(num?: number | null): string {\r\n if (!num) {\r\n return \"\";\r\n }\r\n\r\n switch (num) {\r\n case 1: return \"first\";\r\n case 2: return \"second\";\r\n case 3: return \"third\";\r\n case 4: return \"fourth\";\r\n case 5: return \"fifth\";\r\n case 6: return \"sixth\";\r\n case 7: return \"seventh\";\r\n case 8: return \"eighth\";\r\n case 9: return \"ninth\";\r\n case 10: return \"tenth\";\r\n default: return toOrdinalSuffix(num);\r\n }\r\n}\r\n\r\n/**\r\n * Convert a number to a word.\r\n * Ex: 1 => one\r\n * @param num\r\n */\r\nexport function toWord(num?: number | null): string {\r\n if (num === null || num === undefined) {\r\n return \"\";\r\n }\r\n\r\n switch (num) {\r\n case 1: return \"one\";\r\n case 2: return \"two\";\r\n case 3: return \"three\";\r\n case 4: return \"four\";\r\n case 5: return \"five\";\r\n case 6: return \"six\";\r\n case 7: return \"seven\";\r\n case 8: return \"eight\";\r\n case 9: return \"nine\";\r\n case 10: return \"ten\";\r\n default: return `${num}`;\r\n }\r\n}\r\n\r\nexport function zeroPad(num: number, length: number): string {\r\n let str = num.toString();\r\n\r\n while (str.length < length) {\r\n str = \"0\" + str;\r\n }\r\n\r\n return str;\r\n}\r\n\r\nexport function toDecimalPlaces(num: number, decimalPlaces: number): number {\r\n decimalPlaces = Math.floor(decimalPlaces); // ensure it's an integer\r\n\r\n return Math.round(num * 10 ** decimalPlaces) / 10 ** decimalPlaces;\r\n}\r\n\r\nexport default {\r\n toOrdinal,\r\n toOrdinalSuffix,\r\n toNumberOrNull,\r\n asFormattedString\r\n};\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport { AsyncComponentLoader, Component, ComponentPublicInstance, defineAsyncComponent as vueDefineAsyncComponent, ExtractPropTypes, PropType, reactive, ref, Ref, VNode, watch, WatchOptions, render, isVNode, createVNode } from \"vue\";\r\nimport { deepEqual } from \"./util\";\r\nimport { useSuspense } from \"./suspense\";\r\nimport { newGuid } from \"./guid\";\r\nimport { ControlLazyMode } from \"@Obsidian/Enums/Controls/controlLazyMode\";\r\nimport { PickerDisplayStyle } from \"@Obsidian/Enums/Controls/pickerDisplayStyle\";\r\nimport { ExtendedRef, ExtendedRefContext } from \"@Obsidian/Types/Utility/component\";\r\nimport type { RulesPropType, ValidationRule } from \"@Obsidian/Types/validationRules\";\r\nimport { toNumberOrNull } from \"./numberUtils\";\r\n\r\ntype Prop = { [key: string]: unknown };\r\ntype PropKey = Extract;\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ntype EmitFn = E extends Array ? (event: EE, ...args: any[]) => void : (event: E, ...args: any[]) => void;\r\n\r\n/**\r\n * Utility function for when you are using a component that takes a v-model\r\n * and uses that model as a v-model in that component's template. It creates\r\n * a new ref that keeps itself up-to-date with the given model and fires an\r\n * 'update:MODELNAME' event when it gets changed.\r\n *\r\n * Ensure the related `props` and `emits` are specified to ensure there are\r\n * no type issues.\r\n */\r\nexport function useVModelPassthrough, E extends `update:${K}`>(props: T, modelName: K, emit: EmitFn, options?: WatchOptions): Ref {\r\n const internalValue = ref(props[modelName]) as Ref;\r\n\r\n watch(() => props[modelName], val => updateRefValue(internalValue, val), options);\r\n watch(internalValue, val => {\r\n if (val !== props[modelName]) {\r\n emit(`update:${modelName}`, val);\r\n }\r\n }, options);\r\n\r\n return internalValue;\r\n}\r\n\r\n/**\r\n * Utility function for when you are using a component that takes a v-model\r\n * and uses that model as a v-model in that component's template. It creates\r\n * a new ref that keeps itself up-to-date with the given model and fires an\r\n * 'update:MODELNAME' event when it gets changed. It also gives a means of watching\r\n * the model prop for any changes (verifies that the prop change is different than\r\n * the current value first)\r\n *\r\n * Ensure the related `props` and `emits` are specified to ensure there are\r\n * no type issues.\r\n */\r\nexport function useVModelPassthroughWithPropUpdateCheck, E extends `update:${K}`>(props: T, modelName: K, emit: EmitFn, options?: WatchOptions): [Ref, (fn: () => unknown) => void] {\r\n const internalValue = ref(props[modelName]) as Ref;\r\n const listeners: (() => void)[] = [];\r\n\r\n watch(() => props[modelName], val => {\r\n if (updateRefValue(internalValue, val)) {\r\n onPropUpdate();\r\n }\r\n }, options);\r\n watch(internalValue, val => emit(`update:${modelName}`, val), options);\r\n\r\n function onPropUpdate(): void {\r\n listeners.forEach(fn => fn());\r\n }\r\n\r\n function addPropUpdateListener(fn: () => unknown): void {\r\n listeners.push(fn);\r\n }\r\n\r\n return [internalValue, addPropUpdateListener];\r\n}\r\n\r\n/**\r\n * Updates the Ref value, but only if the new value is actually different than\r\n * the current value. A deep comparison is performed.\r\n *\r\n * @param target The target Ref object to be updated.\r\n * @param value The new value to be assigned to the target.\r\n *\r\n * @returns True if the target was updated, otherwise false.\r\n */\r\nexport function updateRefValue(target: Ref, value: TV): boolean {\r\n if (deepEqual(target.value, value, true)) {\r\n return false;\r\n }\r\n\r\n target.value = value;\r\n\r\n return true;\r\n}\r\n\r\n/**\r\n * Defines a component that will be loaded asynchronously. This contains logic\r\n * to properly work with the RockSuspense control.\r\n *\r\n * @param source The function to call to load the component.\r\n *\r\n * @returns The component that was loaded.\r\n */\r\nexport function defineAsyncComponent(source: AsyncComponentLoader): T {\r\n return vueDefineAsyncComponent(async () => {\r\n const suspense = useSuspense();\r\n const operationKey = newGuid();\r\n\r\n suspense?.startAsyncOperation(operationKey);\r\n const component = await source();\r\n suspense?.completeAsyncOperation(operationKey);\r\n\r\n return component;\r\n });\r\n}\r\n\r\n// #region Standard Form Field\r\n\r\ntype StandardRockFormFieldProps = {\r\n label: {\r\n type: PropType,\r\n default: \"\"\r\n },\r\n\r\n help: {\r\n type: PropType,\r\n default: \"\"\r\n },\r\n\r\n rules: RulesPropType,\r\n\r\n formGroupClasses: {\r\n type: PropType,\r\n default: \"\"\r\n },\r\n\r\n validationTitle: {\r\n type: PropType,\r\n default: \"\"\r\n },\r\n\r\n isRequiredIndicatorHidden: {\r\n type: PropType,\r\n default: false\r\n }\r\n};\r\n\r\n/** The standard component props that should be included when using RockFormField. */\r\nexport const standardRockFormFieldProps: StandardRockFormFieldProps = {\r\n label: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n\r\n help: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n\r\n rules: {\r\n type: [Array, Object, String] as PropType,\r\n default: \"\"\r\n },\r\n\r\n formGroupClasses: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n\r\n validationTitle: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n\r\n isRequiredIndicatorHidden: {\r\n type: Boolean as PropType,\r\n default: false\r\n }\r\n};\r\n\r\n/**\r\n * Copies the known properties for the standard rock form field props from\r\n * the source object to the destination object.\r\n *\r\n * @param source The source object to copy the values from.\r\n * @param destination The destination object to copy the values to.\r\n */\r\nfunction copyStandardRockFormFieldProps(source: ExtractPropTypes, destination: ExtractPropTypes): void {\r\n destination.formGroupClasses = source.formGroupClasses;\r\n destination.help = source.help;\r\n destination.label = source.label;\r\n destination.rules = source.rules;\r\n destination.validationTitle = source.validationTitle;\r\n}\r\n\r\n/**\r\n * Configures the basic properties that should be passed to the RockFormField\r\n * component. The value returned by this function should be used with v-bind on\r\n * the RockFormField in order to pass all the defined prop values to it.\r\n *\r\n * @param props The props of the component that will be using the RockFormField.\r\n *\r\n * @returns An object of prop values that can be used with v-bind.\r\n */\r\nexport function useStandardRockFormFieldProps(props: ExtractPropTypes): ExtractPropTypes {\r\n const propValues = reactive>({\r\n label: props.label,\r\n help: props.help,\r\n rules: props.rules,\r\n formGroupClasses: props.formGroupClasses,\r\n validationTitle: props.validationTitle,\r\n isRequiredIndicatorHidden: props.isRequiredIndicatorHidden\r\n });\r\n\r\n watch([() => props.formGroupClasses, () => props.help, () => props.label, () => props.rules, () => props.validationTitle], () => {\r\n copyStandardRockFormFieldProps(props, propValues);\r\n });\r\n\r\n return propValues;\r\n}\r\n\r\n// #endregion\r\n\r\n// #region Standard Async Pickers\r\n\r\ntype StandardAsyncPickerProps = StandardRockFormFieldProps & {\r\n /** Enhance the picker for dealing with long lists by providing a search mechanism. */\r\n enhanceForLongLists: {\r\n type: PropType,\r\n default: false\r\n },\r\n\r\n /** The method the picker should use to load data. */\r\n lazyMode: {\r\n type: PropType,\r\n default: \"onDemand\"\r\n },\r\n\r\n /** True if the picker should allow multiple items to be selected. */\r\n multiple: {\r\n type: PropType,\r\n default: false\r\n },\r\n\r\n /** True if the picker should allow empty selections. */\r\n showBlankItem: {\r\n type: PropType,\r\n default: false\r\n },\r\n\r\n /** The optional value to show when `showBlankItem` is `true`. */\r\n blankValue: {\r\n type: PropType,\r\n default: \"\"\r\n },\r\n\r\n /** The visual style to use when displaying the picker. */\r\n displayStyle: {\r\n type: PropType,\r\n default: \"auto\"\r\n },\r\n\r\n /** The number of columns to use when displaying the items in a list. */\r\n columnCount: {\r\n type: PropType,\r\n default: 0\r\n }\r\n};\r\n\r\n/** The standard component props that should be included when using BaseAsyncPicker. */\r\nexport const standardAsyncPickerProps: StandardAsyncPickerProps = {\r\n ...standardRockFormFieldProps,\r\n\r\n enhanceForLongLists: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n lazyMode: {\r\n type: String as PropType,\r\n default: ControlLazyMode.OnDemand\r\n },\r\n\r\n multiple: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n showBlankItem: {\r\n type: Boolean as PropType,\r\n default: false\r\n },\r\n\r\n blankValue: {\r\n type: String as PropType,\r\n default: \"\"\r\n },\r\n\r\n displayStyle: {\r\n type: String as PropType,\r\n default: PickerDisplayStyle.Auto\r\n },\r\n\r\n columnCount: {\r\n type: Number as PropType,\r\n default: 0\r\n }\r\n};\r\n\r\n/**\r\n * Copies the known properties for the standard async picker props from\r\n * the source object to the destination object.\r\n *\r\n * @param source The source object to copy the values from.\r\n * @param destination The destination object to copy the values to.\r\n */\r\nfunction copyStandardAsyncPickerProps(source: ExtractPropTypes, destination: ExtractPropTypes): void {\r\n copyStandardRockFormFieldProps(source, destination);\r\n\r\n destination.enhanceForLongLists = source.enhanceForLongLists;\r\n destination.lazyMode = source.lazyMode;\r\n destination.multiple = source.multiple;\r\n destination.showBlankItem = source.showBlankItem;\r\n destination.blankValue = source.blankValue;\r\n destination.displayStyle = source.displayStyle;\r\n destination.columnCount = source.columnCount;\r\n}\r\n\r\n/**\r\n * Configures the basic properties that should be passed to the BaseAsyncPicker\r\n * component. The value returned by this function should be used with v-bind on\r\n * the BaseAsyncPicker in order to pass all the defined prop values to it.\r\n *\r\n * @param props The props of the component that will be using the BaseAsyncPicker.\r\n *\r\n * @returns An object of prop values that can be used with v-bind.\r\n */\r\nexport function useStandardAsyncPickerProps(props: ExtractPropTypes): ExtractPropTypes {\r\n const standardFieldProps = useStandardRockFormFieldProps(props);\r\n\r\n const propValues = reactive>({\r\n ...standardFieldProps,\r\n enhanceForLongLists: props.enhanceForLongLists,\r\n lazyMode: props.lazyMode,\r\n multiple: props.multiple,\r\n showBlankItem: props.showBlankItem,\r\n blankValue: props.blankValue,\r\n displayStyle: props.displayStyle,\r\n columnCount: props.columnCount\r\n });\r\n\r\n // Watch for changes in any of the standard props. Use deep for this so we\r\n // don't need to know which prop keys it actually contains.\r\n watch(() => standardFieldProps, () => {\r\n copyStandardRockFormFieldProps(props, propValues);\r\n }, {\r\n deep: true\r\n });\r\n\r\n // Watch for changes in our known list of props that might change.\r\n watch([() => props.enhanceForLongLists, () => props.lazyMode, () => props.multiple, () => props.showBlankItem, () => props.displayStyle, () => props.columnCount], () => {\r\n copyStandardAsyncPickerProps(props, propValues);\r\n });\r\n\r\n return propValues;\r\n}\r\n\r\n// #endregion\r\n\r\n// #region Extended References\r\n\r\n/**\r\n * Creates a Ref that contains extended data to better identify this ref\r\n * when you have multiple refs to work with.\r\n *\r\n * @param value The initial value of the Ref.\r\n * @param extendedData The additional context data to put on the Ref.\r\n *\r\n * @returns An ExtendedRef object that can be used like a regular Ref object.\r\n */\r\nexport function extendedRef(value: T, context: ExtendedRefContext): ExtendedRef {\r\n const refValue = ref(value) as ExtendedRef;\r\n\r\n refValue.context = context;\r\n\r\n return refValue;\r\n}\r\n\r\n/**\r\n * Creates an extended Ref with the specified property name in the context.\r\n *\r\n * @param value The initial value of the Ref.\r\n * @param propertyName The property name to use for the context.\r\n *\r\n * @returns An ExtendedRef object that can be used like a regular Ref object.\r\n */\r\nexport function propertyRef(value: T, propertyName: string): ExtendedRef {\r\n return extendedRef(value, {\r\n propertyName\r\n });\r\n}\r\n\r\n// #endregion Extended Refs\r\n\r\n// #region VNode Helpers\r\n\r\n/**\r\n * Retrieves a single prop value from a VNode object. If the prop is explicitely\r\n * specified in the DOM then it will be returned. Otherwise the component's\r\n * prop default values are checked. If there is a default value it will be\r\n * returned.\r\n *\r\n * @param node The node whose property value is being requested.\r\n * @param propName The name of the property whose value is being requested.\r\n *\r\n * @returns The value of the property or `undefined` if it was not set.\r\n */\r\nexport function getVNodeProp(node: VNode, propName: string): T | undefined {\r\n // Check if the prop was specified in the DOM declaration.\r\n if (node.props && node.props[propName] !== undefined) {\r\n return node.props[propName] as T;\r\n }\r\n\r\n // Now look to see if the backing component has defined a prop with that\r\n // name and provided a default value.\r\n if (typeof node.type === \"object\" && typeof node.type[\"props\"] === \"object\") {\r\n const defaultProps = node.type[\"props\"] as Record;\r\n const defaultProp = defaultProps[propName];\r\n\r\n if (defaultProp && typeof defaultProp === \"object\" && defaultProp[\"default\"] !== undefined) {\r\n return defaultProp[\"default\"] as T;\r\n }\r\n }\r\n\r\n return undefined;\r\n}\r\n\r\n/**\r\n * Retrieves all prop values from a VNode object. First all default values\r\n * from the component are retrieved. Then any specified on the DOM will be used\r\n * to override those default values.\r\n *\r\n * @param node The node whose property values are being requested.\r\n *\r\n * @returns An object that contains all props and values for the node.\r\n */\r\nexport function getVNodeProps(node: VNode): Record {\r\n const props: Record = {};\r\n\r\n // Get all default values from the backing component's defined props.\r\n if (typeof node.type === \"object\" && typeof node.type[\"props\"] === \"object\") {\r\n const defaultProps = node.type[\"props\"] as Record;\r\n\r\n for (const p in defaultProps) {\r\n const defaultProp = defaultProps[p];\r\n\r\n if (defaultProp && typeof defaultProp === \"object\" && defaultProp[\"default\"] !== undefined) {\r\n props[p] = defaultProp[\"default\"];\r\n }\r\n }\r\n }\r\n\r\n // Override with any values specified on the DOM declaration.\r\n if (node.props) {\r\n for (const p in node.props) {\r\n if (typeof node.type === \"object\" && typeof node.type[\"props\"] === \"object\") {\r\n const propType = node.type[\"props\"][p]?.type;\r\n\r\n if (propType === Boolean) {\r\n props[p] = node.props[p] === true || node.props[p] === \"\";\r\n }\r\n else if (propType === Number) {\r\n props[p] = toNumberOrNull(node.props[p]) ?? undefined;\r\n }\r\n else {\r\n props[p] = node.props[p];\r\n }\r\n }\r\n else {\r\n props[p] = node.props[p];\r\n }\r\n }\r\n }\r\n\r\n return props;\r\n}\r\n\r\n/**\r\n * Renders the node into an off-screen div and then extracts the text content\r\n * by way of the innerText property of the div.\r\n *\r\n * @param node The node or component to be rendered.\r\n * @param props The properties to be passed to the component when it is mounted.\r\n *\r\n * @returns The text content of the node after it has rendered.\r\n */\r\nexport function extractText(node: VNode | Component, props?: Record): string {\r\n const el = document.createElement(\"div\");\r\n\r\n // Create a new virtual node with the specified properties.\r\n const vnode = createVNode(node, props);\r\n\r\n // Mount the node in our off-screen container.\r\n render(vnode, el);\r\n\r\n const text = el.innerText;\r\n\r\n // Unmount it.\r\n render(null, el);\r\n\r\n return text.trim();\r\n}\r\n\r\n/**\r\n * Renders the node into an off-screen div and then extracts the HTML content\r\n * by way of the innerHTML property of the div.\r\n *\r\n * @param node The node or component to be rendered.\r\n * @param props The properties to be passed to the component when it is mounted.\r\n *\r\n * @returns The HTML content of the node after it has rendered.\r\n */\r\nexport function extractHtml(node: VNode | Component, props?: Record): string {\r\n const el = document.createElement(\"div\");\r\n\r\n // Create a new virtual node with the specified properties.\r\n const vnode = createVNode(node, props);\r\n\r\n // Mount the node in our off-screen container.\r\n render(vnode, el);\r\n\r\n const html = el.innerHTML;\r\n\r\n // Unmount it.\r\n render(null, el);\r\n\r\n return html;\r\n}\r\n\r\n// #endregion\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { toNumberOrNull, zeroPad } from \"./numberUtils\";\r\nconst dateKeyLength = \"YYYYMMDD\".length;\r\nconst dateKeyNoYearLength = \"MMDD\".length;\r\n\r\n/**\r\n * Gets the year value from the date key.\r\n * Ex: 20210228 => 2021\r\n * @param dateKey\r\n */\r\nexport function getYear(dateKey: string | null): number {\r\n const defaultValue = 0;\r\n\r\n if (!dateKey || dateKey.length !== dateKeyLength) {\r\n return defaultValue;\r\n }\r\n\r\n const asString = dateKey.substring(0, 4);\r\n const year = toNumberOrNull(asString) || defaultValue;\r\n return year;\r\n}\r\n\r\n/**\r\n * Gets the month value from the date key.\r\n * Ex: 20210228 => 2\r\n * @param dateKey\r\n */\r\nexport function getMonth(dateKey: string | null): number {\r\n const defaultValue = 0;\r\n\r\n if (!dateKey) {\r\n return defaultValue;\r\n }\r\n\r\n if (dateKey.length === dateKeyLength) {\r\n const asString = dateKey.substring(4, 6);\r\n return toNumberOrNull(asString) || defaultValue;\r\n }\r\n\r\n if (dateKey.length === dateKeyNoYearLength) {\r\n const asString = dateKey.substring(0, 2);\r\n return toNumberOrNull(asString) || defaultValue;\r\n }\r\n\r\n return defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the day value from the date key.\r\n * Ex: 20210228 => 28\r\n * @param dateKey\r\n */\r\nexport function getDay(dateKey: string | null): number {\r\n const defaultValue = 0;\r\n\r\n if (!dateKey) {\r\n return defaultValue;\r\n }\r\n\r\n if (dateKey.length === dateKeyLength) {\r\n const asString = dateKey.substring(6, 8);\r\n return toNumberOrNull(asString) || defaultValue;\r\n }\r\n\r\n if (dateKey.length === dateKeyNoYearLength) {\r\n const asString = dateKey.substring(2, 4);\r\n return toNumberOrNull(asString) || defaultValue;\r\n }\r\n\r\n return defaultValue;\r\n}\r\n\r\n/**\r\n * Gets the datekey constructed from the parts.\r\n * Ex: (2021, 2, 28) => '20210228'\r\n * @param year\r\n * @param month\r\n * @param day\r\n */\r\nexport function toDateKey(year: number | null, month: number | null, day: number | null): string {\r\n if (!year || year > 9999 || year < 0) {\r\n year = 0;\r\n }\r\n\r\n if (!month || month > 12 || month < 0) {\r\n month = 0;\r\n }\r\n\r\n if (!day || day > 31 || day < 0) {\r\n day = 0;\r\n }\r\n\r\n const yearStr = zeroPad(year, 4);\r\n const monthStr = zeroPad(month, 2);\r\n const dayStr = zeroPad(day, 2);\r\n\r\n return `${yearStr}${monthStr}${dayStr}`;\r\n}\r\n\r\n/**\r\n * Gets the datekey constructed from the parts.\r\n * Ex: (2, 28) => '0228'\r\n * @param month\r\n * @param day\r\n */\r\nexport function toNoYearDateKey(month: number | null, day: number | null): string {\r\n if (!month || month > 12 || month < 0) {\r\n month = 0;\r\n }\r\n\r\n if (!day || day > 31 || day < 0) {\r\n day = 0;\r\n }\r\n\r\n const monthStr = zeroPad(month, 2);\r\n const dayStr = zeroPad(day, 2);\r\n\r\n return `${monthStr}${dayStr}`;\r\n}\r\n\r\nexport default {\r\n getYear,\r\n getMonth,\r\n getDay,\r\n toDateKey,\r\n toNoYearDateKey\r\n};\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { CurrentPersonBag } from \"@Obsidian/ViewModels/Crm/currentPersonBag\";\r\n\r\nexport type PageConfig = {\r\n executionStartTime: number;\r\n pageId: number;\r\n pageGuid: Guid;\r\n pageParameters: Record;\r\n currentPerson: CurrentPersonBag | null;\r\n isAnonymousVisitor: boolean;\r\n loginUrlWithReturnUrl: string;\r\n};\r\n\r\nexport function smoothScrollToTop(): void {\r\n window.scrollTo({ top: 0, behavior: \"smooth\" });\r\n}\r\n\r\nexport default {\r\n smoothScrollToTop\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-explicit-any\r\ndeclare const Obsidian: any;\r\n\r\n\r\n/*\r\n * Code to handle working with modals.\r\n */\r\nlet currentModalCount = 0;\r\n\r\n/**\r\n * Track a modal being opened or closed. This is used to adjust the page in response\r\n * to any modals being visible.\r\n *\r\n * @param state true if the modal is now open, false if it is now closed.\r\n */\r\nexport function trackModalState(state: boolean): void {\r\n const body = document.body;\r\n const cssClasses = [\"modal-open\"];\r\n\r\n if (state) {\r\n currentModalCount++;\r\n }\r\n else {\r\n currentModalCount = currentModalCount > 0 ? currentModalCount - 1 : 0;\r\n }\r\n\r\n if (currentModalCount > 0) {\r\n for (const cssClass of cssClasses) {\r\n body.classList.add(cssClass);\r\n }\r\n }\r\n else {\r\n for (const cssClass of cssClasses) {\r\n body.classList.remove(cssClass);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Loads a JavaScript file asynchronously into the document and returns a\r\n * Promise that can be used to determine when the script has loaded. The\r\n * promise will return true if the script loaded successfully or false if it\r\n * failed to load.\r\n *\r\n * The function passed in isScriptLoaded will be called before the script is\r\n * inserted into the DOM as well as after to make sure it actually loaded.\r\n *\r\n * @param source The source URL of the script to be loaded.\r\n * @param isScriptLoaded An optional function to call to determine if the script is loaded.\r\n * @param attributes An optional set of attributes to apply to the script tag.\r\n * @param fingerprint If set to false, then a fingerprint will not be added to the source URL. Default is true.\r\n *\r\n * @returns A Promise that indicates if the script was loaded or not.\r\n */\r\nexport async function loadJavaScriptAsync(source: string, isScriptLoaded?: () => boolean, attributes?: Record, fingerprint?: boolean): Promise {\r\n let src = source;\r\n\r\n // Add the cache busting fingerprint if we have one.\r\n if (fingerprint !== false && typeof Obsidian !== \"undefined\" && Obsidian?.options?.fingerprint) {\r\n if (src.indexOf(\"?\") === -1) {\r\n src += `?${Obsidian.options.fingerprint}`;\r\n }\r\n else {\r\n src += `&${Obsidian.options.fingerprint}`;\r\n }\r\n }\r\n\r\n // Check if the script is already loaded. First see if we have a custom\r\n // function that will do the check. Otherwise fall back to looking for any\r\n // script tags that have the same source.\r\n if (isScriptLoaded) {\r\n if (isScriptLoaded()) {\r\n return true;\r\n }\r\n }\r\n\r\n // Make sure the script wasn't already added in some other way.\r\n const scripts = Array.from(document.getElementsByTagName(\"script\"));\r\n const thisScript = scripts.filter(s => s.src === src);\r\n\r\n if (thisScript.length > 0) {\r\n const promise = scriptLoadedPromise(thisScript[0]);\r\n return promise;\r\n }\r\n\r\n // Build the script tag that will be dynamically loaded.\r\n const script = document.createElement(\"script\");\r\n script.type = \"text/javascript\";\r\n script.src = src;\r\n if (attributes) {\r\n for (const key in attributes) {\r\n script.setAttribute(key, attributes[key]);\r\n }\r\n }\r\n\r\n // Load the script.\r\n const promise = scriptLoadedPromise(script);\r\n document.getElementsByTagName(\"head\")[0].appendChild(script);\r\n\r\n return promise;\r\n\r\n async function scriptLoadedPromise(scriptElement: HTMLScriptElement): Promise {\r\n try {\r\n await new Promise((resolve, reject) => {\r\n scriptElement.addEventListener(\"load\", () => resolve());\r\n scriptElement.addEventListener(\"error\", () => {\r\n reject();\r\n });\r\n });\r\n\r\n // If we have a custom function, call it to see if the script loaded correctly.\r\n if (isScriptLoaded) {\r\n return isScriptLoaded();\r\n }\r\n\r\n return true;\r\n }\r\n catch {\r\n return false;\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * Adds a new link to the quick return action menu. The URL in the address bar\r\n * will be used as the destination.\r\n *\r\n * @param title The title of the quick link that identifies the current page.\r\n * @param section The section title to place this link into.\r\n * @param sectionOrder The priority order to give the section if it doesn't already exist.\r\n */\r\nexport function addQuickReturn(title: string, section: string, sectionOrder?: number): void {\r\n interface IRock {\r\n personalLinks: {\r\n addQuickReturn: (type: string, typeOrder: number, itemName: string) => void\r\n }\r\n }\r\n\r\n (window[\"Rock\"] as IRock).personalLinks.addQuickReturn(section, sectionOrder ?? 0, title);\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { trackModalState } from \"./page\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/naming-convention\r\ndeclare const Rock: any;\r\n\r\ntype DialogOptions = {\r\n message: string;\r\n buttons: ButtonOptions[];\r\n container?: string | Element;\r\n};\r\n\r\ntype ButtonOptions = {\r\n key: string;\r\n label: string;\r\n className: string;\r\n};\r\n\r\n/**\r\n * Creates a dialog to display a message.\r\n *\r\n * @param body The body content to put in the dialog.\r\n * @param footer The footer content to put in the dialog.\r\n *\r\n * @returns An element that should be added to the body.\r\n */\r\nfunction createDialog(body: HTMLElement | HTMLElement[], footer: HTMLElement | HTMLElement[] | undefined): HTMLElement {\r\n // Create the scrollable container that will act as a backdrop for the dialog.\r\n const scrollable = document.createElement(\"div\");\r\n scrollable.classList.add(\"modal-scrollable\");\r\n scrollable.style.zIndex = \"1060\";\r\n\r\n // Create the modal that will act as a container for the outer content.\r\n const modal = document.createElement(\"div\");\r\n scrollable.appendChild(modal);\r\n modal.classList.add(\"modal\", \"fade\");\r\n modal.tabIndex = -1;\r\n modal.setAttribute(\"role\", \"dialog\");\r\n modal.setAttribute(\"aria-hidden\", \"false\");\r\n modal.style.display = \"block\";\r\n\r\n // Create the inner dialog of the modal.\r\n const modalDialog = document.createElement(\"div\");\r\n modal.appendChild(modalDialog);\r\n modalDialog.classList.add(\"modal-dialog\");\r\n\r\n // Create the container for the inner content.\r\n const modalContent = document.createElement(\"div\");\r\n modalDialog.appendChild(modalContent);\r\n modalContent.classList.add(\"modal-content\");\r\n\r\n // Create the container for the body content.\r\n const modalBody = document.createElement(\"div\");\r\n modalContent.appendChild(modalBody);\r\n modalBody.classList.add(\"modal-body\");\r\n\r\n // Add all the body elements to the body.\r\n if (Array.isArray(body)) {\r\n for (const el of body) {\r\n modalBody.appendChild(el);\r\n }\r\n }\r\n else {\r\n modalBody.appendChild(body);\r\n }\r\n\r\n // If we have any footer content then create a footer.\r\n if (footer && (!Array.isArray(footer) || footer.length > 0)) {\r\n const modalFooter = document.createElement(\"div\");\r\n modalContent.appendChild(modalFooter);\r\n modalFooter.classList.add(\"modal-footer\");\r\n\r\n // Add all the footer elements to the footer.\r\n if (Array.isArray(footer)) {\r\n for (const el of footer) {\r\n modalFooter.appendChild(el);\r\n }\r\n }\r\n else {\r\n modalFooter.appendChild(footer);\r\n }\r\n }\r\n\r\n // Add a click handler to the background so the user gets feedback\r\n // that they can't just click away from the dialog.\r\n scrollable.addEventListener(\"click\", () => {\r\n modal.classList.remove(\"animated\", \"shake\");\r\n setTimeout(() => {\r\n modal.classList.add(\"animated\", \"shake\");\r\n }, 0);\r\n });\r\n\r\n return scrollable;\r\n}\r\n\r\n/**\r\n * Construct a standard close button to be placed in the dialog.\r\n *\r\n * @returns A button element.\r\n */\r\nfunction createCloseButton(): HTMLButtonElement {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.classList.add(\"close\");\r\n closeButton.type = \"button\";\r\n closeButton.style.marginTop = \"-10px\";\r\n closeButton.innerHTML = \"×\";\r\n\r\n return closeButton;\r\n}\r\n\r\n/**\r\n * Creates a standard backdrop element to be placed in the window.\r\n *\r\n * @returns An element to show that the background is not active.\r\n */\r\nfunction createBackdrop(): HTMLElement {\r\n const backdrop = document.createElement(\"div\");\r\n backdrop.classList.add(\"modal-backdrop\");\r\n backdrop.style.zIndex = \"1050\";\r\n\r\n return backdrop;\r\n}\r\n\r\n/**\r\n * Shows a dialog modal. This is meant to look and behave like the standard\r\n * Rock.dialog.* functions, but this handles fullscreen mode whereas the old\r\n * methods do not.\r\n *\r\n * @param options The options that describe the dialog to be shown.\r\n *\r\n * @returns The key of the button that was clicked, or \"cancel\" if the cancel button was clicked.\r\n */\r\nfunction showDialog(options: DialogOptions): Promise {\r\n return new Promise(resolve => {\r\n let timer: NodeJS.Timeout | null = null;\r\n const container = document.fullscreenElement || document.body;\r\n const body = document.createElement(\"div\");\r\n body.innerText = options.message;\r\n\r\n const buttons: HTMLElement[] = [];\r\n\r\n /**\r\n * Internal function to handle clearing the dialog and resolving the\r\n * promise.\r\n *\r\n * @param result The result to return in the promise.\r\n */\r\n function clearDialog(result: string): void {\r\n // This acts as a way to ensure only a single clear request happens.\r\n if (timer !== null) {\r\n return;\r\n }\r\n\r\n // The timout is used as a fallback in case we don't get the\r\n // transition end event.\r\n timer = setTimeout(() => {\r\n backdrop.remove();\r\n dialog.remove();\r\n trackModalState(false);\r\n\r\n resolve(result);\r\n }, 1000);\r\n\r\n modal.addEventListener(\"transitionend\", () => {\r\n if (timer) {\r\n clearTimeout(timer);\r\n }\r\n\r\n backdrop.remove();\r\n dialog.remove();\r\n trackModalState(false);\r\n\r\n resolve(result);\r\n });\r\n\r\n modal.classList.remove(\"in\");\r\n backdrop.classList.remove(\"in\");\r\n }\r\n\r\n // Add in all the buttons specified.\r\n for (const button of options.buttons) {\r\n const btn = document.createElement(\"button\");\r\n btn.classList.value = button.className;\r\n btn.type = \"button\";\r\n btn.innerText = button.label;\r\n btn.addEventListener(\"click\", () => {\r\n clearDialog(button.key);\r\n });\r\n buttons.push(btn);\r\n }\r\n\r\n // Construct the close (cancel) button.\r\n const closeButton = createCloseButton();\r\n closeButton.addEventListener(\"click\", () => {\r\n clearDialog(\"cancel\");\r\n });\r\n\r\n const dialog = createDialog([closeButton, body], buttons);\r\n const backdrop = createBackdrop();\r\n\r\n const modal = dialog.querySelector(\".modal\") as HTMLElement;\r\n\r\n // Do final adjustments to the elements and add to the body.\r\n trackModalState(true);\r\n container.appendChild(dialog);\r\n container.appendChild(backdrop);\r\n modal.style.marginTop = `-${modal.offsetHeight / 2.0}px`;\r\n\r\n // Show the backdrop and the modal.\r\n backdrop.classList.add(\"in\");\r\n modal.classList.add(\"in\");\r\n });\r\n}\r\n\r\n/**\r\n * Shows an alert message that requires the user to acknowledge.\r\n *\r\n * @param message The message text to be displayed.\r\n *\r\n * @returns A promise that indicates when the dialog has been dismissed.\r\n */\r\nexport async function alert(message: string): Promise {\r\n await showDialog({\r\n message,\r\n buttons: [\r\n {\r\n key: \"ok\",\r\n label: \"OK\",\r\n className: \"btn btn-primary\"\r\n }\r\n ]\r\n });\r\n}\r\n\r\n/**\r\n * Shows a confirmation dialog that consists of OK and Cancel buttons. The\r\n * user will be required to click one of these two buttons.\r\n *\r\n * @param message The message to be displayed inside the dialog.\r\n *\r\n * @returns A promise that indicates when the dialog has been dismissed. The\r\n * value will be true if the OK button was clicked or false otherwise.\r\n */\r\nexport async function confirm(message: string): Promise {\r\n const result = await showDialog({\r\n message,\r\n buttons: [\r\n {\r\n key: \"ok\",\r\n label: \"OK\",\r\n className: \"btn btn-primary\"\r\n },\r\n {\r\n key: \"cancel\",\r\n label: \"Cancel\",\r\n className: \"btn btn-default\"\r\n }\r\n ]\r\n });\r\n\r\n return result === \"ok\";\r\n}\r\n\r\n/**\r\n * Shows a delete confirmation dialog that consists of OK and Cancel buttons.\r\n * The user will be required to click one of these two buttons. The message\r\n * is standardized.\r\n *\r\n * @param nameText The name of type that will be deleted.\r\n *\r\n * @returns A promise that indicates when the dialog has been dismissed. The\r\n * value will be true if the OK button was clicked or false otherwise.\r\n */\r\nexport function confirmDelete(typeName: string, additionalMessage?: string): Promise {\r\n let message = `Are you sure you want to delete this ${typeName}?`;\r\n\r\n if (additionalMessage) {\r\n message += ` ${additionalMessage}`;\r\n }\r\n\r\n return confirm(message);\r\n}\r\n\r\n/**\r\n * Shows the security dialog for the given entity.\r\n *\r\n * @param entityTypeIdKey The identifier of the entity's type.\r\n * @param entityIdKey The identifier of the entity to secure.\r\n * @param entityTitle The title of the entity. This is used to construct the modal title.\r\n */\r\nexport function showSecurity(entityTypeIdKey: Guid | string | number, entityIdKey: Guid | string | number, entityTitle: string = \"Item\"): void {\r\n Rock.controls.modal.show(undefined, `/Secure/${entityTypeIdKey}/${entityIdKey}?t=Secure ${entityTitle}&pb=&sb=Done`);\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/**\r\n * Is the value a valid email address?\r\n * @param val\r\n */\r\nexport function isEmail(val: unknown): boolean {\r\n if (typeof val === \"string\") {\r\n const re = /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\r\n return re.test(val.toLowerCase());\r\n }\r\n\r\n return false;\r\n}\r\n","import { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\n\r\n/**\r\n * A function to convert the enums to array of ListItemBag in the frontend.\r\n *\r\n * @param description The enum to be converted to an array of listItemBag as a dictionary of value to enum description\r\n *\r\n * @returns An array of ListItemBag.\r\n */\r\nexport function enumToListItemBag (description: Record): ListItemBag[] {\r\n const listItemBagList: ListItemBag[] = [];\r\n for(const property in description) {\r\n listItemBagList.push({\r\n text: description[property].toString(),\r\n value: property.toString()\r\n });\r\n }\r\n return listItemBagList;\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { isValidGuid, normalize } from \"./guid\";\r\nimport { IFieldType } from \"@Obsidian/Types/fieldType\";\r\n\r\nconst fieldTypeTable: Record = {};\r\n\r\n/** Determines how the field type component is being used so it can adapt to different */\r\nexport type DataEntryMode = \"defaultValue\" | undefined;\r\n\r\n/**\r\n * Register a new field type in the system. This must be called for all field\r\n * types a plugin registers.\r\n *\r\n * @param fieldTypeGuid The unique identifier of the field type.\r\n * @param fieldType The class instance that will handle the field type.\r\n */\r\nexport function registerFieldType(fieldTypeGuid: Guid, fieldType: IFieldType): void {\r\n const normalizedGuid = normalize(fieldTypeGuid);\r\n\r\n if (!isValidGuid(fieldTypeGuid) || normalizedGuid === null) {\r\n throw \"Invalid guid specified when registering field type.\";\r\n }\r\n\r\n if (fieldTypeTable[normalizedGuid] !== undefined) {\r\n throw \"Invalid attempt to replace existing field type.\";\r\n }\r\n\r\n fieldTypeTable[normalizedGuid] = fieldType;\r\n}\r\n\r\n/**\r\n * Get the field type handler for a given unique identifier.\r\n *\r\n * @param fieldTypeGuid The unique identifier of the field type.\r\n *\r\n * @returns The field type instance or null if not found.\r\n */\r\nexport function getFieldType(fieldTypeGuid: Guid): IFieldType | null {\r\n const normalizedGuid = normalize(fieldTypeGuid);\r\n\r\n if (normalizedGuid !== null) {\r\n const field = fieldTypeTable[normalizedGuid];\r\n\r\n if (field) {\r\n return field;\r\n }\r\n }\r\n\r\n console.warn(`Field type \"${fieldTypeGuid}\" was not found`);\r\n return null;\r\n}\r\n\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { inject, provide } from \"vue\";\r\n\r\n/** The unique symbol used when injecting the form state. */\r\nconst formStateSymbol = Symbol();\r\n\r\n/**\r\n * Holds the state of a single form on the page along with any callback methods\r\n * that can be used to interact with the form.\r\n */\r\nexport type FormState = {\r\n /** The number of submissions the form has had. */\r\n submitCount: number;\r\n\r\n /** Sets the current error for the given field name. A blank error means no error. */\r\n setError: (id: string, name: string, error: string) => void;\r\n};\r\n\r\n/**\r\n * Contains the internal form error passed between RockForm and RockValidation.\r\n *\r\n * This is an internal type and subject to change at any time.\r\n */\r\nexport type FormError = {\r\n /** The name of the field. */\r\n name: string;\r\n\r\n /** The current error text. */\r\n text: string;\r\n};\r\n\r\n/**\r\n * Provides the form state for any child components that need access to it.\r\n * \r\n * @param state The state that will be provided to child components.\r\n */\r\nexport function provideFormState(state: FormState): void {\r\n provide(formStateSymbol, state);\r\n}\r\n\r\n/**\r\n * Makes use of the FormState that was previously provided by a parent component.\r\n *\r\n * @returns The form state or undefined if it was not available.\r\n */\r\nexport function useFormState(): FormState | undefined {\r\n return inject(formStateSymbol, undefined);\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n// Define the browser-specific versions of these functions that older browsers\r\n// implemented before using the standard API.\r\ndeclare global {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface Document {\r\n mozCancelFullScreen?: () => Promise;\r\n webkitExitFullscreen?: () => Promise;\r\n mozFullScreenElement?: Element;\r\n webkitFullscreenElement?: Element;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n interface HTMLElement {\r\n mozRequestFullscreen?: () => Promise;\r\n webkitRequestFullscreen?: () => Promise;\r\n }\r\n}\r\n\r\n/**\r\n * Request that the window enter true fullscreen mode for the given element.\r\n * \r\n * @param element The element that will be the root of the fullscreen view.\r\n * @param exitCallback The function to call when leaving fullscreen mode.\r\n *\r\n * @returns A promise that indicates when the operation has completed.\r\n */\r\nexport async function enterFullscreen(element: HTMLElement, exitCallback?: (() => void)): Promise {\r\n try {\r\n if (element.requestFullscreen) {\r\n await element.requestFullscreen();\r\n }\r\n else if (element.mozRequestFullscreen) {\r\n await element.mozRequestFullscreen();\r\n }\r\n else if (element.webkitRequestFullscreen) {\r\n await element.webkitRequestFullscreen();\r\n }\r\n else {\r\n return false;\r\n }\r\n\r\n element.classList.add(\"is-fullscreen\");\r\n\r\n const onFullscreenChange = (): void => {\r\n element.classList.remove(\"is-fullscreen\");\r\n\r\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\r\n document.removeEventListener(\"mozfullscreenchange\", onFullscreenChange);\r\n document.removeEventListener(\"webkitfullscreenchange\", onFullscreenChange);\r\n\r\n if (exitCallback) {\r\n exitCallback();\r\n }\r\n };\r\n\r\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\r\n document.addEventListener(\"mozfullscreenchange\", onFullscreenChange);\r\n document.addEventListener(\"webkitfullscreenchange\", onFullscreenChange);\r\n\r\n return true;\r\n }\r\n catch (ex) {\r\n console.error(ex);\r\n return false;\r\n }\r\n}\r\n\r\n/**\r\n * Checks if any element is currently in fullscreen mode.\r\n * \r\n * @returns True if an element is currently in fullscreen mode in the window; otherwise false.\r\n */\r\nexport function isFullscreen(): boolean {\r\n return !!document.fullscreenElement || !!document.mozFullScreenElement || !!document.webkitFullscreenElement;\r\n}\r\n\r\n/**\r\n * Manually exits fullscreen mode.\r\n * \r\n * @returns True if fullscreen mode was exited; otherwise false.\r\n */\r\nexport async function exitFullscreen(): Promise {\r\n try {\r\n if (document.exitFullscreen) {\r\n await document.exitFullscreen();\r\n }\r\n else if (document.mozCancelFullScreen) {\r\n await document.mozCancelFullScreen();\r\n }\r\n else if (document.webkitExitFullscreen) {\r\n document.webkitExitFullscreen();\r\n }\r\n else {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n catch (ex) {\r\n console.error(ex);\r\n return false;\r\n }\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/* global google */\r\n\r\nimport { DrawingMode, Coordinate, ILatLng, ILatLngLiteral } from \"@Obsidian/Types/Controls/geo\";\r\nimport { GeoPickerSettingsBag } from \"@Obsidian/ViewModels/Rest/Controls/geoPickerSettingsBag\";\r\nimport { GeoPickerGetSettingsOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/geoPickerGetSettingsOptionsBag\";\r\nimport { GeoPickerGoogleMapSettingsBag } from \"@Obsidian/ViewModels/Rest/Controls/geoPickerGoogleMapSettingsBag\";\r\nimport { loadJavaScriptAsync } from \"./page\";\r\nimport { post } from \"./http\";\r\n\r\n/**\r\n * Converts a LatLng object, \"lat,lng\" coordinate string, or WellKnown \"lng lat\" coordinate string to a Coordinate array\r\n * @param coord Either a string in \"lat,lng\" format or a LatLng object from Google Maps\r\n * @param isWellKnown True if is \"lng lat\" format, false if it is \"lat, lng\"\r\n *\r\n * @returns Coordinate: Tuple with a Latitude number and Longitude number as the elements\r\n */\r\nexport function toCoordinate(coord: string | ILatLng, isWellKnown: boolean = false): Coordinate {\r\n if (typeof coord == \"string\") {\r\n // WellKnown string format\r\n if (isWellKnown) {\r\n return coord.split(\" \").reverse().map(val => parseFloat(val)) as Coordinate;\r\n }\r\n // Google Maps URL string format\r\n else {\r\n return coord.split(\",\").map(val => parseFloat(val)) as Coordinate;\r\n }\r\n }\r\n else {\r\n return [coord.lat(), coord.lng()];\r\n }\r\n}\r\n\r\n/**\r\n * Takes a Well Known Text value and converts it into a Coordinate array\r\n */\r\nexport function wellKnownToCoordinates(wellKnownText: string, type: DrawingMode): Coordinate[] {\r\n if (wellKnownText == \"\") {\r\n return [];\r\n }\r\n if (type == \"Point\") {\r\n // From this format: POINT (-112.130946 33.600114)\r\n return [toCoordinate(wellKnownText.replace(/(POINT *\\( *)|( *\\) *)/ig, \"\"), true)];\r\n }\r\n else {\r\n // From this format: POLYGON ((-112.157058 33.598563, -112.092341 33.595132, -112.117061 33.608715, -112.124957 33.609286, -112.157058 33.598563))\r\n return wellKnownText.replace(/(POLYGON *\\(+ *)|( *\\)+ *)/ig, \"\").split(/ *, */).map((coord) => toCoordinate(coord, true));\r\n }\r\n}\r\n\r\n/**\r\n * Takes a Well Known Text value and converts it into a Coordinate array\r\n */\r\nexport function coordinatesToWellKnown(coordinates: Coordinate[], type: DrawingMode): string {\r\n if (coordinates.length == 0) {\r\n return \"\";\r\n }\r\n else if (type == \"Point\") {\r\n return `POINT(${coordinates[0].reverse().join(\" \")})`;\r\n }\r\n else {\r\n // DB doesn't work well with the points of a polygon specified in clockwise order for some reason\r\n if (isClockwisePolygon(coordinates)) {\r\n coordinates.reverse();\r\n }\r\n\r\n const coordinateString = coordinates.map(coords => coords.reverse().join(\" \")).join(\", \");\r\n return `POLYGON((${coordinateString}))`;\r\n }\r\n}\r\n\r\n/**\r\n * Takes a Coordinate and uses Geocoding to get nearest address\r\n */\r\nexport function nearAddressForCoordinate(coordinate: Coordinate): Promise {\r\n return new Promise(resolve => {\r\n // only try if google is loaded\r\n if (window.google) {\r\n const geocoder = new google.maps.Geocoder();\r\n geocoder.geocode({ location: new google.maps.LatLng(...coordinate) }, function (results, status) {\r\n if (status == google.maps.GeocoderStatus.OK && results?.[0]) {\r\n resolve(\"near \" + results[0].formatted_address);\r\n }\r\n else {\r\n console.log(\"Geocoder failed due to: \" + status);\r\n resolve(\"\");\r\n }\r\n });\r\n }\r\n else {\r\n resolve(\"\");\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Takes a Coordinate array and uses Geocoding to get nearest address for the first point\r\n */\r\nexport function nearAddressForCoordinates(coordinates: Coordinate[]): Promise {\r\n if (!coordinates || coordinates.length == 0) {\r\n return Promise.resolve(\"\");\r\n }\r\n return nearAddressForCoordinate(coordinates[0]);\r\n}\r\n\r\n/**\r\n * Determine whether the polygon's coordinates are drawn in clockwise order\r\n * Thank you dominoc!\r\n * http://dominoc925.blogspot.com/2012/03/c-code-to-determine-if-polygon-vertices.html\r\n */\r\nexport function isClockwisePolygon(polygon: number[][]): boolean {\r\n let sum = 0;\r\n\r\n for (let i = 0; i < polygon.length - 1; i++) {\r\n sum += (Math.abs(polygon[i + 1][0]) - Math.abs(polygon[i][0])) * (Math.abs(polygon[i + 1][1]) + Math.abs(polygon[i][1]));\r\n }\r\n\r\n return sum > 0;\r\n}\r\n\r\n/**\r\n * Download the necessary resources to run the maps and return the map settings from the API\r\n *\r\n * @param options Options for which data to get from the API\r\n *\r\n * @return Promise with the map settings retrieved from the API\r\n */\r\nexport async function loadMapResources(options: GeoPickerGetSettingsOptionsBag = {}): Promise {\r\n const response = await post(\"/api/v2/Controls/GeoPickerGetGoogleMapSettings\", undefined, options);\r\n const googleMapSettings = response.data ?? {};\r\n\r\n let keyParam = \"\";\r\n\r\n if (googleMapSettings.googleApiKey) {\r\n keyParam = `key=${googleMapSettings.googleApiKey}&`;\r\n }\r\n\r\n await loadJavaScriptAsync(`https://maps.googleapis.com/maps/api/js?${keyParam}libraries=drawing,visualization,geometry`, () => typeof (google) != \"undefined\" && typeof (google.maps) != \"undefined\", {}, false);\r\n\r\n return googleMapSettings;\r\n}\r\n\r\n/**\r\n * Creates a ILatLng object\r\n */\r\nexport function createLatLng(latOrLatLngOrLatLngLiteral: number | ILatLngLiteral | ILatLng, lngOrNoClampNoWrap?: number | boolean | null, noClampNoWrap?: boolean): ILatLng {\r\n return new google.maps.LatLng(latOrLatLngOrLatLngLiteral as number, lngOrNoClampNoWrap, noClampNoWrap);\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { DayOfWeek, RockDateTime } from \"./rockDateTime\";\r\nimport { newGuid } from \"./guid\";\r\nimport { toNumberOrNull } from \"./numberUtils\";\r\nimport { pluralConditional } from \"./stringUtils\";\r\n\r\ntype Frequency = \"DAILY\" | \"WEEKLY\" | \"MONTHLY\";\r\n\r\n/**\r\n * The day of the week and an interval number for that particular day.\r\n */\r\nexport type WeekdayNumber = {\r\n /** The interval number for this day. */\r\n value: number;\r\n\r\n /** The day of the week. */\r\n day: DayOfWeek;\r\n};\r\n\r\n// Abbreviate nth lookup table.\r\nconst nthNamesAbbreviated: [number, string][] = [\r\n [1, \"1st\"],\r\n [2, \"2nd\"],\r\n [3, \"3rd\"],\r\n [4, \"4th\"],\r\n [-1, \"last\"]\r\n];\r\n\r\n// #region Internal Functions\r\n\r\n/**\r\n * Converts the number to a string and pads the left with zeros to make up\r\n * the minimum required length.\r\n *\r\n * @param value The value to be converted to a string.\r\n * @param length The minimum required length of the final string.\r\n *\r\n * @returns A string that represents the value.\r\n */\r\nfunction padZeroLeft(value: number, length: number): string {\r\n const str = value.toString();\r\n\r\n return \"0\".repeat(length - str.length) + str;\r\n}\r\n\r\n/**\r\n * Get a date-only string that can be used in the iCal format.\r\n *\r\n * @param date The date object to be converted to a string.\r\n *\r\n * @returns A string that represents only the date portion of the parameter.\r\n */\r\nfunction getDateString(date: RockDateTime): string {\r\n const year = date.year;\r\n const month = date.month;\r\n const day = date.day;\r\n\r\n return `${year}${padZeroLeft(month, 2)}${padZeroLeft(day, 2)}`;\r\n}\r\n\r\n/**\r\n * Gets a time-only string that can be used in the iCal format.\r\n *\r\n * @param date The date object to be converted to a string.\r\n *\r\n * @returns A string that represents only the time portion of the parameter.\r\n */\r\nfunction getTimeString(date: RockDateTime): string {\r\n const hour = date.hour;\r\n const minute = date.minute;\r\n const second = date.second;\r\n\r\n return `${padZeroLeft(hour, 2)}${padZeroLeft(minute, 2)}${padZeroLeft(second, 2)}`;\r\n}\r\n\r\n/**\r\n * Gets a date and time string that can be used in the iCal format.\r\n *\r\n * @param date The date object to be converted to a string.\r\n *\r\n * @returns A string that represents only the date and time of the parameter.\r\n */\r\nfunction getDateTimeString(date: RockDateTime): string {\r\n return `${getDateString(date)}T${getTimeString(date)}`;\r\n}\r\n\r\n/**\r\n * Gets all the date objects from a range or period string value. This converts\r\n * from an iCal format into a set of date objects.\r\n *\r\n * @param value The string value in iCal format.\r\n *\r\n * @returns An array of date objects that represents the range or period value.\r\n */\r\nfunction getDatesFromRangeOrPeriod(value: string): RockDateTime[] {\r\n const segments = value.split(\"/\");\r\n\r\n if (segments.length === 0) {\r\n return [];\r\n }\r\n\r\n const startDate = getDateFromString(segments[0]);\r\n if (!startDate) {\r\n return [];\r\n }\r\n\r\n if (segments.length !== 2) {\r\n return [startDate];\r\n }\r\n\r\n const dates: RockDateTime[] = [];\r\n\r\n if (segments[1].startsWith(\"P\")) {\r\n // Value is a period so we have a start date and then a period marker\r\n // to tell us how long that date extends.\r\n const days = getPeriodDurationInDays(segments[1]);\r\n\r\n for (let day = 0; day < days; day++) {\r\n const date = startDate.addDays(day);\r\n if (date) {\r\n dates.push(date);\r\n }\r\n }\r\n }\r\n else {\r\n // Value is a date range so we have a start date and then an end date\r\n // and we need to fill in the dates in between.\r\n const endDate = getDateFromString(segments[1]);\r\n\r\n if (endDate !== null) {\r\n let date = startDate;\r\n\r\n while (date <= endDate) {\r\n dates.push(date);\r\n date = date.addDays(1);\r\n }\r\n }\r\n }\r\n\r\n return dates;\r\n}\r\n\r\n/**\r\n * Get a date object that only has the date portion filled in from the iCal\r\n * date string. The time will be set to midnight.\r\n *\r\n * @param value An iCal date value.\r\n *\r\n * @returns A date object that represents the iCal date value.\r\n */\r\nfunction getDateFromString(value: string): RockDateTime | null {\r\n if (value.length < 8) {\r\n return null;\r\n }\r\n\r\n const year = parseInt(value.substring(0, 4));\r\n const month = parseInt(value.substring(4, 6));\r\n const day = parseInt(value.substring(6, 8));\r\n\r\n return RockDateTime.fromParts(year, month, day);\r\n}\r\n\r\n/**\r\n * Get a date object that has both the date and time filled in from the iCal\r\n * date string.\r\n *\r\n * @param value An iCal date value.\r\n *\r\n * @returns A date object that represents the iCal date value.\r\n */\r\nfunction getDateTimeFromString(value: string): RockDateTime | null {\r\n if (value.length < 15 || value[8] !== \"T\") {\r\n return null;\r\n }\r\n\r\n const year = parseInt(value.substring(0, 4));\r\n const month = parseInt(value.substring(4, 6));\r\n const day = parseInt(value.substring(6, 8));\r\n const hour = parseInt(value.substring(9, 11));\r\n const minute = parseInt(value.substring(11, 13));\r\n const second = parseInt(value.substring(13, 15));\r\n\r\n return RockDateTime.fromParts(year, month, day, hour, minute, second);\r\n}\r\n\r\n/**\r\n * Gets an iCal period duration in the number of days.\r\n *\r\n * @param period The iCal period definition.\r\n *\r\n * @returns The number of days found in the definition.\r\n */\r\nfunction getPeriodDurationInDays(period: string): number {\r\n // These are in a format like P1D, P2W, etc.\r\n if (!period.startsWith(\"P\")) {\r\n return 0;\r\n }\r\n\r\n if (period.endsWith(\"D\")) {\r\n return parseInt(period.substring(1, period.length - 1));\r\n }\r\n else if (period.endsWith(\"W\")) {\r\n return parseInt(period.substring(1, period.length - 1)) * 7;\r\n }\r\n\r\n return 0;\r\n}\r\n\r\n/**\r\n * Gets the specific recurrence dates from a RDATE iCal value string.\r\n *\r\n * @param attributes The attributes that were defined on the RDATE property.\r\n * @param value The value of the RDATE property.\r\n *\r\n * @returns An array of date objects found in the RDATE value.\r\n */\r\nfunction getRecurrenceDates(attributes: Record, value: string): RockDateTime[] {\r\n const recurrenceDates: RockDateTime[] = [];\r\n const valueParts = value.split(\",\");\r\n let valueType = attributes[\"VALUE\"];\r\n\r\n for (const valuePart of valueParts) {\r\n if(!valueType) {\r\n // The value type is unspecified and it could be a PERIOD, DATE-TIME or a DATE.\r\n // Determine it based on the length and the contents of the valuePart string.\r\n\r\n const length = valuePart.length;\r\n\r\n if (length === 8) { // Eg: 20240117\r\n valueType = \"DATE\";\r\n }\r\n else if ((length === 15 || length === 16) && valuePart[8] === \"T\") { // Eg: 19980119T020000, 19970714T173000Z\r\n valueType = \"DATE-TIME\";\r\n }\r\n else { // Eg: 20240201/20240202, 20240118/P1D\r\n valueType = \"PERIOD\";\r\n }\r\n }\r\n\r\n\r\n if (valueType === \"PERIOD\") {\r\n // Values are stored in period format, such as \"20221005/P1D\".\r\n recurrenceDates.push(...getDatesFromRangeOrPeriod(valuePart));\r\n }\r\n else if (valueType === \"DATE\") {\r\n // Values are date-only values.\r\n const date = getDateFromString(valuePart);\r\n if (date) {\r\n recurrenceDates.push(date);\r\n }\r\n }\r\n else if (valueType === \"DATE-TIME\") {\r\n // Values are date and time values.\r\n const date = getDateTimeFromString(valuePart);\r\n if (date) {\r\n recurrenceDates.push(date);\r\n }\r\n }\r\n }\r\n\r\n return recurrenceDates;\r\n}\r\n\r\n/**\r\n * Gets the name of the weekday from the iCal abbreviation.\r\n *\r\n * @param day The iCal day abbreviation.\r\n *\r\n * @returns A string that represents the day name.\r\n */\r\nfunction getWeekdayName(day: DayOfWeek): \"Sunday\" | \"Monday\" | \"Tuesday\" | \"Wednesday\" | \"Thursday\" | \"Friday\" | \"Saturday\" | \"Unknown\" {\r\n if (day === DayOfWeek.Sunday) {\r\n return \"Sunday\";\r\n }\r\n else if (day === DayOfWeek.Monday) {\r\n return \"Monday\";\r\n }\r\n else if (day === DayOfWeek.Tuesday) {\r\n return \"Tuesday\";\r\n }\r\n else if (day === DayOfWeek.Wednesday) {\r\n return \"Wednesday\";\r\n }\r\n else if (day === DayOfWeek.Thursday) {\r\n return \"Thursday\";\r\n }\r\n else if (day === DayOfWeek.Friday) {\r\n return \"Friday\";\r\n }\r\n else if (day === DayOfWeek.Saturday) {\r\n return \"Saturday\";\r\n }\r\n else {\r\n return \"Unknown\";\r\n }\r\n}\r\n\r\n/**\r\n * Checks if the date matches one of the weekday options.\r\n *\r\n * @param rockDate The date that must match one of the weekday options.\r\n * @param days The array of weekdays that the date must match.\r\n *\r\n * @returns True if the date matches; otherwise false.\r\n */\r\nfunction dateMatchesDays(rockDate: RockDateTime, days: DayOfWeek[]): boolean {\r\n for (const day of days) {\r\n if (rockDate.dayOfWeek === day) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/**\r\n * Checks if the date matches the specifie day of week and also the offset into\r\n * the month for that day.\r\n *\r\n * @param rockDate The date object to be checked.\r\n * @param dayOfWeek The day of week the date must be on.\r\n * @param offsets The offset in week, such as 2 meaning the second 'dayOfWeek' or -1 meaning the last 'dayOfWeek'.\r\n *\r\n * @returns True if the date matches the options; otherwise false.\r\n */\r\nfunction dateMatchesOffsetDayOfWeeks(rockDate: RockDateTime, dayOfWeek: DayOfWeek, offsets: number[]): boolean {\r\n if (!dateMatchesDays(rockDate, [dayOfWeek])) {\r\n return false;\r\n }\r\n\r\n const dayOfMonth = rockDate.day;\r\n\r\n for (const offset of offsets) {\r\n if (offset === 1 && dayOfMonth >= 1 && dayOfMonth <= 7) {\r\n return true;\r\n }\r\n else if (offset === 2 && dayOfMonth >= 8 && dayOfMonth <= 14) {\r\n return true;\r\n }\r\n else if (offset === 3 && dayOfMonth >= 15 && dayOfMonth <= 21) {\r\n return true;\r\n }\r\n else if (offset === 4 && dayOfMonth >= 22 && dayOfMonth <= 28) {\r\n return true;\r\n }\r\n else if (offset === -1) {\r\n const lastDayOfMonth = rockDate.addDays(-(rockDate.day - 1)).addMonths(1).addDays(-1).day;\r\n\r\n if (dayOfMonth >= (lastDayOfMonth - 7) && dayOfMonth <= lastDayOfMonth) {\r\n return true;\r\n }\r\n }\r\n }\r\n\r\n return false;\r\n}\r\n\r\n/**\r\n * Gets the DayOfWeek value that corresponds to the iCal formatted weekday.\r\n *\r\n * @param day The day of the week to be parsed.\r\n *\r\n * @returns A DayOfWeek value that represents the day.\r\n */\r\nfunction getDayOfWeekFromIcalDay(day: \"SU\" | \"MO\" | \"TU\" | \"WE\" | \"TH\" | \"FR\" | \"SA\"): DayOfWeek {\r\n switch (day) {\r\n case \"SU\":\r\n return DayOfWeek.Sunday;\r\n\r\n case \"MO\":\r\n return DayOfWeek.Monday;\r\n case \"TU\":\r\n return DayOfWeek.Tuesday;\r\n\r\n case \"WE\":\r\n return DayOfWeek.Wednesday;\r\n\r\n case \"TH\":\r\n return DayOfWeek.Thursday;\r\n\r\n case \"FR\":\r\n return DayOfWeek.Friday;\r\n\r\n case \"SA\":\r\n return DayOfWeek.Saturday;\r\n }\r\n}\r\n\r\n/**\r\n * Gets the iCal abbreviation for the day of the week.\r\n *\r\n * @param day The day of the week to be converted to iCal format.\r\n *\r\n * @returns An iCal representation of the day of week.\r\n */\r\nfunction getiCalDay(day: DayOfWeek): \"SU\" | \"MO\" | \"TU\" | \"WE\" | \"TH\" | \"FR\" | \"SA\" {\r\n switch (day) {\r\n case DayOfWeek.Sunday:\r\n return \"SU\";\r\n\r\n case DayOfWeek.Monday:\r\n return \"MO\";\r\n\r\n case DayOfWeek.Tuesday:\r\n return \"TU\";\r\n\r\n case DayOfWeek.Wednesday:\r\n return \"WE\";\r\n\r\n case DayOfWeek.Thursday:\r\n return \"TH\";\r\n\r\n case DayOfWeek.Friday:\r\n return \"FR\";\r\n\r\n case DayOfWeek.Saturday:\r\n return \"SA\";\r\n }\r\n}\r\n\r\n/**\r\n * Normalizes line length so that none of the individual lines exceed the\r\n * maximum length of 75 charactes from the RFC.\r\n *\r\n * @param lines The array of lines to be normalized.\r\n *\r\n * @returns A new array with the lines normalized for length.\r\n */\r\nfunction normalizeLineLength(lines: string[]): string[] {\r\n const newLines: string[] = [...lines];\r\n\r\n for (let lineNumber = 0; lineNumber < newLines.length; lineNumber++) {\r\n // Spec does not allow lines longer than 75 characters.\r\n if (newLines[lineNumber].length > 75) {\r\n const currentLine = newLines[lineNumber].substring(0, 75);\r\n const newLine = \" \" + newLines[lineNumber].substring(75);\r\n\r\n newLines.splice(lineNumber, 1, currentLine, newLine);\r\n }\r\n }\r\n\r\n return newLines;\r\n}\r\n\r\n/**\r\n * Denormalizes line length so that any continuation lines are appending\r\n * to the previous line for proper parsing.\r\n *\r\n * @param lines The array of lines to be denormalized.\r\n *\r\n * @returns A new array with the lines denormalized.\r\n */\r\nfunction denormalizeLineLength(lines: string[]): string[] {\r\n const newLines: string[] = [...lines];\r\n\r\n for (let lineNumber = 1; lineNumber < newLines.length;) {\r\n if (newLines[lineNumber][0] === \" \") {\r\n newLines[lineNumber - 1] += newLines[lineNumber].substring(1);\r\n newLines.splice(lineNumber, 1);\r\n }\r\n else {\r\n lineNumber++;\r\n }\r\n }\r\n\r\n return newLines;\r\n}\r\n\r\n// #endregion\r\n\r\n/**\r\n * Helper utility to feed lines into ICS parsers.\r\n */\r\nclass LineFeeder {\r\n // #region Properties\r\n\r\n /**\r\n * The denormalzied lines that represent the ICS data.\r\n */\r\n private lines: string[];\r\n\r\n // #endregion\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new LineFeeder with the given content.\r\n *\r\n * @param content A string that represents raw ICS data.\r\n */\r\n constructor(content: string) {\r\n const lines = content.split(/\\r\\n|\\n|\\r/);\r\n\r\n this.lines = denormalizeLineLength(lines);\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Functions\r\n\r\n /**\r\n * Peek at the next line to be read from the feeder.\r\n *\r\n * @returns The next line to be read or null if no more lines remain.\r\n */\r\n public peek(): string | null {\r\n if (this.lines.length === 0) {\r\n return null;\r\n }\r\n\r\n return this.lines[0];\r\n }\r\n\r\n /**\r\n * Pops the next line from the feeder, removing it.\r\n *\r\n * @returns The line that was removed from the feeder or null if no lines remain.\r\n */\r\n public pop(): string | null {\r\n if (this.lines.length === 0) {\r\n return null;\r\n }\r\n\r\n return this.lines.splice(0, 1)[0];\r\n }\r\n\r\n // #endregion\r\n}\r\n\r\n/**\r\n * Logic and structure for a rule that defines when an even recurs on\r\n * different dates.\r\n */\r\nexport class RecurrenceRule {\r\n // #region Properties\r\n\r\n /**\r\n * The frequency of this recurrence. Only Daily, Weekly and Monthly\r\n * are supported.\r\n */\r\n public frequency?: Frequency;\r\n\r\n /**\r\n * The date at which no more event dates will be generated. This is\r\n * an exclusive date, meaning if an event date lands on this date\r\n * then it will not be included in the list of dates.\r\n */\r\n public endDate?: RockDateTime;\r\n\r\n /**\r\n * The maximum number of dates, including the original date, that\r\n * should be generated.\r\n */\r\n public count?: number;\r\n\r\n /**\r\n * The interval between dates based on the frequency. If this value is\r\n * 2 and frequency is Weekly, then you are asking for \"every other week\".\r\n */\r\n public interval: number = 1;\r\n\r\n /**\r\n * The days of the month the event should recur on. Only a single value\r\n * is supported currently.\r\n */\r\n public byMonthDay: number[] = [];\r\n\r\n /**\r\n * The days of the week the event shoudl recur on.\r\n */\r\n public byDay: WeekdayNumber[] = [];\r\n\r\n // #endregion\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new recurrence rule that can be used to define or adjust the\r\n * recurrence pattern of an event.\r\n *\r\n * @param rule An existing RRULE string from an iCal file.\r\n *\r\n * @returns A new instance that can be used to adjust or define the rule.\r\n */\r\n public constructor(rule: string | undefined = undefined) {\r\n if (!rule) {\r\n return;\r\n }\r\n\r\n // Rule has a format like \"FREQ=DAILY;COUNT=5\" so we split by semicolon\r\n // first and then sub-split by equals character and then stuff everything\r\n // into this values object.\r\n const values: Record = {};\r\n\r\n for (const attr of rule.split(\";\")) {\r\n const attrParts = attr.split(\"=\");\r\n if (attrParts.length === 2) {\r\n values[attrParts[0]] = attrParts[1];\r\n }\r\n }\r\n\r\n // Make sure the values we have are valid.\r\n if (values[\"UNTIL\"] !== undefined && values[\"COUNT\"] !== undefined) {\r\n throw new Error(`Recurrence rule '${rule}' cannot specify both UNTIL and COUNT.`);\r\n }\r\n\r\n if (values[\"FREQ\"] !== \"DAILY\" && values[\"FREQ\"] !== \"WEEKLY\" && values[\"FREQ\"] !== \"MONTHLY\") {\r\n throw new Error(`Invalid frequence for recurrence rule '${rule}'.`);\r\n }\r\n\r\n this.frequency = values[\"FREQ\"];\r\n\r\n if (values[\"UNTIL\"]?.length === 8) {\r\n this.endDate = getDateFromString(values[\"UNTIL\"]) ?? undefined;\r\n }\r\n else if (values[\"UNTIL\"]?.length >= 15) {\r\n this.endDate = getDateTimeFromString(values[\"UNTIL\"]) ?? undefined;\r\n }\r\n\r\n if (values[\"COUNT\"] !== undefined) {\r\n this.count = toNumberOrNull(values[\"COUNT\"]) ?? undefined;\r\n }\r\n\r\n if (values[\"INTERVAL\"] !== undefined) {\r\n this.interval = toNumberOrNull(values[\"INTERVAL\"]) ?? 1;\r\n }\r\n\r\n if (values[\"BYMONTHDAY\"] !== undefined && values[\"BYMONTHDAY\"].length > 0) {\r\n this.byMonthDay = [];\r\n\r\n for (const v of values[\"BYMONTHDAY\"].split(\",\")) {\r\n const num = toNumberOrNull(v);\r\n if (num !== null) {\r\n this.byMonthDay.push(num);\r\n }\r\n }\r\n }\r\n\r\n if (values[\"BYDAY\"] !== undefined && values[\"BYDAY\"].length > 0) {\r\n this.byDay = [];\r\n\r\n for (const v of values[\"BYDAY\"].split(\",\")) {\r\n if (v.length < 2) {\r\n continue;\r\n }\r\n\r\n const num = v.length > 2 ? toNumberOrNull(v.substring(0, v.length - 2)) : 1;\r\n const day = v.substring(v.length - 2);\r\n\r\n if (num === null) {\r\n continue;\r\n }\r\n\r\n if (day === \"SU\" || day === \"MO\" || day === \"TU\" || day == \"WE\" || day == \"TH\" || day == \"FR\" || day == \"SA\") {\r\n this.byDay.push({\r\n value: num,\r\n day: getDayOfWeekFromIcalDay(day)\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Functions\r\n\r\n /**\r\n * Builds and returns the RRULE value for an iCal file export.\r\n *\r\n * @returns A RRULE value that represents the recurrence rule.\r\n */\r\n public build(): string {\r\n const attributes: string[] = [];\r\n\r\n attributes.push(`FREQ=${this.frequency}`);\r\n\r\n if (this.count !== undefined) {\r\n attributes.push(`COUNT=${this.count}`);\r\n }\r\n else if (this.endDate) {\r\n attributes.push(`UNTIL=${getDateTimeString(this.endDate)}`);\r\n }\r\n\r\n if (this.interval > 1) {\r\n attributes.push(`INTERVAL=${this.interval}`);\r\n }\r\n\r\n if (this.byMonthDay.length > 0) {\r\n const monthDayValues = this.byMonthDay.map(md => md.toString()).join(\",\");\r\n attributes.push(`BYMONTHDAY=${monthDayValues}`);\r\n }\r\n\r\n if (this.byDay.length > 0) {\r\n const dayValues = this.byDay.map(d => d.value !== 1 ? `${d.value}${getiCalDay(d.day)}` : getiCalDay(d.day));\r\n attributes.push(`BYDAY=${dayValues}`);\r\n }\r\n\r\n return attributes.join(\";\");\r\n }\r\n\r\n /**\r\n * Gets all the dates within the range that match the recurrence rule. A\r\n * maximum of 100,000 dates will be returned by this function.\r\n *\r\n * @param eventStartDateTime The start date and time of the primary event this rule is for.\r\n * @param startDateTime The inclusive starting date and time that events should be returned for.\r\n * @param endDateTime The exclusive ending date and time that events should be returned for.\r\n *\r\n * @returns An array of date objects that represent the additional dates and times for the event.\r\n */\r\n public getDates(eventStartDateTime: RockDateTime, startDateTime: RockDateTime, endDateTime: RockDateTime): RockDateTime[] {\r\n const dates: RockDateTime[] = [];\r\n let rockDate = eventStartDateTime;\r\n let dateCount = 0;\r\n\r\n if (!rockDate) {\r\n return [];\r\n }\r\n\r\n if (this.endDate && this.endDate < endDateTime) {\r\n endDateTime = this.endDate;\r\n }\r\n\r\n while (rockDate < endDateTime && dateCount < 100_000) {\r\n if (this.count && dateCount >= this.count) {\r\n break;\r\n }\r\n\r\n dateCount++;\r\n\r\n if (rockDate >= startDateTime) {\r\n dates.push(rockDate);\r\n }\r\n\r\n const nextDate = this.nextDateAfter(rockDate);\r\n\r\n if (nextDate === null) {\r\n break;\r\n }\r\n else {\r\n rockDate = nextDate;\r\n }\r\n }\r\n\r\n return dates;\r\n }\r\n\r\n /**\r\n * Gets the next valid date after the specified date based on our recurrence\r\n * rules.\r\n *\r\n * @param rockDate The reference date that should be used when calculation the next date.\r\n *\r\n * @returns The next date after the reference date or null if one cannot be determined.\r\n */\r\n private nextDateAfter(rockDate: RockDateTime): RockDateTime | null {\r\n if (this.frequency === \"DAILY\") {\r\n return rockDate.addDays(this.interval);\r\n }\r\n else if (this.frequency === \"WEEKLY\" && this.byDay.length > 0) {\r\n let nextDate = rockDate;\r\n\r\n if (nextDate.dayOfWeek === DayOfWeek.Saturday) {\r\n // On saturday process any skip intervals to move past the next n weeks.\r\n nextDate = nextDate.addDays(1 + ((this.interval - 1) * 7));\r\n }\r\n else {\r\n nextDate = nextDate.addDays(1);\r\n }\r\n\r\n while (!dateMatchesDays(nextDate, this.byDay.map(d => d.day))) {\r\n if (nextDate.dayOfWeek === DayOfWeek.Saturday) {\r\n // On saturday process any skip intervals to move past the next n weeks.\r\n nextDate = nextDate.addDays(1 + ((this.interval - 1) * 7));\r\n }\r\n else {\r\n nextDate = nextDate.addDays(1);\r\n }\r\n }\r\n\r\n return nextDate;\r\n }\r\n else if (this.frequency === \"MONTHLY\") {\r\n if (this.byMonthDay.length > 0) {\r\n let nextDate = rockDate.addDays(-(rockDate.day - 1));\r\n\r\n if (rockDate.day >= this.byMonthDay[0]) {\r\n nextDate = nextDate.addMonths(this.interval);\r\n }\r\n\r\n let lastDayOfMonth = nextDate.addMonths(1).addDays(-1).day;\r\n let loopCount = 0;\r\n\r\n // Skip any months that don't have this day number.\r\n while (lastDayOfMonth < this.byMonthDay[0]) {\r\n nextDate = nextDate.addMonths(this.interval);\r\n\r\n lastDayOfMonth = nextDate.addMonths(1).addDays(-1).day;\r\n\r\n // Fail-safe check so we don't get stuck looping forever\r\n // if the rule is one that can't be determined. Such as a\r\n // rule for the 30th day of the month every 12 months\r\n // starting in February.\r\n if (loopCount++ >= 100) {\r\n return null;\r\n }\r\n }\r\n\r\n nextDate = nextDate.addDays(this.byMonthDay[0] - 1);\r\n\r\n return nextDate;\r\n }\r\n else if (this.byDay.length > 0) {\r\n const dayOfWeek = this.byDay[0].day;\r\n const offsets = this.byDay.map(d => d.value);\r\n\r\n let nextDate = rockDate.addDays(1);\r\n\r\n while (!dateMatchesOffsetDayOfWeeks(nextDate, dayOfWeek, offsets)) {\r\n nextDate = nextDate.addDays(1);\r\n }\r\n\r\n return nextDate;\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n // #endregion\r\n}\r\n\r\n/**\r\n * A single event inside a calendar.\r\n */\r\nexport class Event {\r\n // #region Properties\r\n\r\n /**\r\n * The unique identifier for this schedule used in the scheduled event.\r\n */\r\n public uid?: string;\r\n\r\n /**\r\n * The first date and time that the event occurs on. This must be provided\r\n * before the schedule can be built.\r\n */\r\n public startDateTime?: RockDateTime;\r\n\r\n /**\r\n * The end date and time for the event. This must be provided before\r\n * this schedule can be built.\r\n */\r\n public endDateTime?: RockDateTime;\r\n\r\n /**\r\n * An array of dates to be excluded from the recurrence rules.\r\n */\r\n public excludedDates: RockDateTime[] = [];\r\n\r\n /**\r\n * An array of specific dates that this schedule will recur on. This is\r\n * only valid if recurrenceRules contains no rules.\r\n */\r\n public recurrenceDates: RockDateTime[] = [];\r\n\r\n /**\r\n * The rules that define when this schedule recurs on for additional dates.\r\n * Only the first rule is currently supported.\r\n */\r\n public recurrenceRules: RecurrenceRule[] = [];\r\n\r\n // #endregion\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new internet calendar event.\r\n *\r\n * @param icsContent The content from the ICS file that represents this single event.\r\n *\r\n * @returns A new Event instance.\r\n */\r\n public constructor(icsContent: string | LineFeeder | undefined = undefined) {\r\n if (icsContent === undefined) {\r\n this.uid = newGuid();\r\n return;\r\n }\r\n\r\n let feeder: LineFeeder;\r\n\r\n if (typeof icsContent === \"string\") {\r\n feeder = new LineFeeder(icsContent);\r\n }\r\n else {\r\n feeder = icsContent;\r\n }\r\n\r\n this.parse(feeder);\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Functions\r\n\r\n /**\r\n * Build the event as a list of individual lines that make up the event in\r\n * the ICS file format.\r\n *\r\n * @returns An array of lines to be inserted into an ICS file.\r\n */\r\n public buildLines(): string[] {\r\n if (!this.startDateTime || !this.endDateTime) {\r\n return [];\r\n }\r\n\r\n const lines: string[] = [];\r\n\r\n lines.push(\"BEGIN:VEVENT\");\r\n lines.push(`DTEND:${getDateTimeString(this.endDateTime)}`);\r\n lines.push(`DTSTAMP:${getDateTimeString(RockDateTime.now())}`);\r\n lines.push(`DTSTART:${getDateTimeString(this.startDateTime)}`);\r\n\r\n if (this.excludedDates.length > 0) {\r\n lines.push(`EXDATE:${this.excludedDates.map(d => getDateString(d) + \"/P1D\").join(\",\")}`);\r\n }\r\n\r\n if (this.recurrenceDates.length > 0) {\r\n const recurrenceDates: string[] = [];\r\n for (const date of this.recurrenceDates) {\r\n const rDate = RockDateTime.fromParts(date.year, date.month, date.day, this.startDateTime.hour, this.startDateTime.minute, this.startDateTime.second);\r\n if (rDate) {\r\n recurrenceDates.push(getDateTimeString(rDate));\r\n }\r\n }\r\n\r\n lines.push(`RDATE:${recurrenceDates.join(\",\")}`);\r\n }\r\n else if (this.recurrenceRules.length > 0) {\r\n for (const rrule of this.recurrenceRules) {\r\n lines.push(`RRULE:${rrule.build()}`);\r\n }\r\n }\r\n\r\n lines.push(\"SEQUENCE:0\");\r\n lines.push(`UID:${this.uid}`);\r\n lines.push(\"END:VEVENT\");\r\n\r\n return lines;\r\n }\r\n\r\n /**\r\n * Builds the event into a string that conforms to ICS format.\r\n *\r\n * @returns An ICS formatted string that represents the event data.\r\n */\r\n public build(): string | null {\r\n const lines = this.buildLines();\r\n\r\n if (lines.length === 0) {\r\n return null;\r\n }\r\n\r\n return normalizeLineLength(lines).join(\"\\r\\n\");\r\n }\r\n\r\n /**\r\n * Parse data from an existing event and store it on this instance.\r\n *\r\n * @param feeder The feeder that will provide the line data for parsing.\r\n */\r\n private parse(feeder: LineFeeder): void {\r\n let duration: string | null = null;\r\n let line: string | null;\r\n\r\n // Verify this is an event.\r\n if (feeder.peek() !== \"BEGIN:VEVENT\") {\r\n throw new Error(\"Invalid event.\");\r\n }\r\n\r\n feeder.pop();\r\n\r\n // Parse the line until we run out of lines or see an END line.\r\n while ((line = feeder.pop()) !== null) {\r\n if (line === \"END:VEVENT\") {\r\n break;\r\n }\r\n\r\n const splitAt = line.indexOf(\":\");\r\n if (splitAt < 0) {\r\n continue;\r\n }\r\n\r\n let key = line.substring(0, splitAt);\r\n const value = line.substring(splitAt + 1);\r\n\r\n const keyAttributes: Record = {};\r\n const keySegments = key.split(\";\");\r\n if (keySegments.length > 1) {\r\n key = keySegments[0];\r\n keySegments.splice(0, 1);\r\n\r\n for (const attr of keySegments) {\r\n const attrSegments = attr.split(\"=\");\r\n if (attr.length === 2) {\r\n keyAttributes[attrSegments[0]] = attrSegments[1];\r\n }\r\n }\r\n }\r\n\r\n if (key === \"DTSTART\") {\r\n this.startDateTime = getDateTimeFromString(value) ?? undefined;\r\n }\r\n else if (key === \"DTEND\") {\r\n this.endDateTime = getDateTimeFromString(value) ?? undefined;\r\n }\r\n else if (key === \"RRULE\") {\r\n this.recurrenceRules.push(new RecurrenceRule(value));\r\n }\r\n else if (key === \"RDATE\") {\r\n this.recurrenceDates = getRecurrenceDates(keyAttributes, value);\r\n }\r\n else if (key === \"UID\") {\r\n this.uid = value;\r\n }\r\n else if (key === \"DURATION\") {\r\n duration = value;\r\n }\r\n else if (key === \"EXDATE\") {\r\n const dateValues = value.split(\",\");\r\n for (const dateValue of dateValues) {\r\n const dates = getDatesFromRangeOrPeriod(dateValue);\r\n this.excludedDates.push(...dates);\r\n }\r\n }\r\n }\r\n\r\n if (duration !== null) {\r\n // TODO: Calculate number of seconds and add to startDate.\r\n }\r\n }\r\n\r\n /**\r\n * Determines if the date is listed in one of the excluded dates. This\r\n * currently only checks the excludedDates but in the future might also\r\n * check the excluded rules.\r\n *\r\n * @param rockDate The date to be checked to see if it is excluded.\r\n *\r\n * @returns True if the date is excluded; otherwise false.\r\n */\r\n private isDateExcluded(rockDate: RockDateTime): boolean {\r\n const rockDateOnly = rockDate.date;\r\n\r\n for (const excludedDate of this.excludedDates) {\r\n if (excludedDate.date.isEqualTo(rockDateOnly)) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * Get all the dates for this event that fall within the specified date range.\r\n *\r\n * @param startDateTime The inclusive starting date to use when filtering event dates.\r\n * @param endDateTime The exclusive endign date to use when filtering event dates.\r\n *\r\n * @returns An array of dates that fall between startDateTime and endDateTime.\r\n */\r\n public getDates(startDateTime: RockDateTime, endDateTime: RockDateTime): RockDateTime[] {\r\n if (!this.startDateTime) {\r\n return [];\r\n }\r\n\r\n // If the schedule has a startDateTime that is later than the requested\r\n // startDateTime then use ours instead.\r\n if (this.startDateTime > startDateTime) {\r\n startDateTime = this.startDateTime;\r\n }\r\n\r\n if (this.recurrenceDates.length > 0) {\r\n const dates: RockDateTime[] = [];\r\n const recurrenceDates: RockDateTime[] = [this.startDateTime, ...this.recurrenceDates];\r\n\r\n for (const date of recurrenceDates) {\r\n if (date >= startDateTime && date < endDateTime) {\r\n dates.push(date);\r\n }\r\n }\r\n\r\n return dates;\r\n }\r\n else if (this.recurrenceRules.length > 0) {\r\n const rrule = this.recurrenceRules[0];\r\n\r\n return rrule.getDates(this.startDateTime, startDateTime, endDateTime)\r\n .filter(d => !this.isDateExcluded(d));\r\n }\r\n else {\r\n if (this.startDateTime >= startDateTime && this.startDateTime < endDateTime) {\r\n return [this.startDateTime];\r\n }\r\n\r\n return [];\r\n }\r\n }\r\n\r\n /**\r\n * Get the friendly text string that represents this event. This will be a\r\n * plain text string with no formatting applied.\r\n *\r\n * @returns A string that represents the event in a human friendly manner.\r\n */\r\n public toFriendlyText(): string {\r\n return this.toFriendlyString(false);\r\n }\r\n\r\n /**\r\n * Get the friendly HTML string that represents this event. This will be\r\n * formatted with HTML to make the information easier to read.\r\n *\r\n * @returns A string that represents the event in a human friendly manner.\r\n */\r\n public toFriendlyHtml(): string {\r\n return this.toFriendlyString(true);\r\n }\r\n\r\n /**\r\n * Get the friendly string that can be easily understood by a human.\r\n *\r\n * @param html If true then the string can contain HTML content to make things easier to read.\r\n *\r\n * @returns A string that represents the event in a human friendly manner.\r\n */\r\n private toFriendlyString(html: boolean): string {\r\n if (!this.startDateTime) {\r\n return \"\";\r\n }\r\n\r\n const startTimeText = this.startDateTime.toLocaleString({ hour: \"numeric\", minute: \"2-digit\", hour12: true });\r\n\r\n if (this.recurrenceRules.length > 0) {\r\n const rrule = this.recurrenceRules[0];\r\n\r\n if (rrule.frequency === \"DAILY\") {\r\n let result = \"Daily\";\r\n\r\n if (rrule.interval > 1) {\r\n result += ` every ${rrule.interval} ${pluralConditional(rrule.interval, \"day\", \"days\")}`;\r\n }\r\n\r\n result += ` at ${startTimeText}`;\r\n\r\n return result;\r\n }\r\n else if (rrule.frequency === \"WEEKLY\") {\r\n if (rrule.byDay.length === 0) {\r\n return \"No Scheduled Days\";\r\n }\r\n\r\n let result = rrule.byDay.map(d => getWeekdayName(d.day) + \"s\").join(\",\");\r\n\r\n if (rrule.interval > 1) {\r\n result = `Every ${rrule.interval} weeks: ${result}`;\r\n }\r\n else {\r\n result = `Weekly: ${result}`;\r\n }\r\n\r\n return `${result} at ${startTimeText}`;\r\n }\r\n else if (rrule.frequency === \"MONTHLY\") {\r\n if (rrule.byMonthDay.length > 0) {\r\n let result = `Day ${rrule.byMonthDay[0]} of every `;\r\n\r\n if (rrule.interval > 1) {\r\n result += `${rrule.interval} months`;\r\n }\r\n else {\r\n result += \"month\";\r\n }\r\n\r\n return `${result} at ${startTimeText}`;\r\n }\r\n else if (rrule.byDay.length > 0) {\r\n const byDay = rrule.byDay[0];\r\n const offsetNames = nthNamesAbbreviated.filter(n => rrule.byDay.some(d => d.value == n[0])).map(n => n[1]);\r\n let result = \"\";\r\n\r\n if (offsetNames.length > 0) {\r\n let nameText: string;\r\n\r\n if (offsetNames.length > 2) {\r\n nameText = `${offsetNames.slice(0, offsetNames.length - 1).join(\", \")} and ${offsetNames[offsetNames.length - 1]}`;\r\n }\r\n else {\r\n nameText = offsetNames.join(\" and \");\r\n }\r\n result = `The ${nameText} ${getWeekdayName(byDay.day)} of every month`;\r\n }\r\n else {\r\n return \"\";\r\n }\r\n\r\n return `${result} at ${startTimeText}`;\r\n }\r\n else {\r\n return \"\";\r\n }\r\n }\r\n else {\r\n return \"\";\r\n }\r\n }\r\n else {\r\n const dates: RockDateTime[] = [this.startDateTime, ...this.recurrenceDates];\r\n\r\n if (dates.length === 1) {\r\n return `Once at ${this.startDateTime.toASPString(\"g\")}`;\r\n }\r\n else if (!html || dates.length > 99) {\r\n const firstDate = dates[0];\r\n const lastDate = dates[dates.length - 1];\r\n\r\n if (firstDate && lastDate) {\r\n return `Multiple dates between ${firstDate.toASPString(\"g\")} and ${lastDate.toASPString(\"g\")}`;\r\n }\r\n else {\r\n return \"\";\r\n }\r\n }\r\n else if (dates.length > 1) {\r\n let listHtml = `]`;\r\n\r\n for (const date of dates) {\r\n listHtml += `- ${date.toASPString(\"g\")}
`;\r\n }\r\n\r\n listHtml += \"\";\r\n\r\n return listHtml;\r\n }\r\n else {\r\n return \"No Schedule\";\r\n }\r\n }\r\n }\r\n\r\n // #endregion\r\n}\r\n\r\n/**\r\n * A recurring schedule allows schedules to be built and customized from the iCal\r\n * format used in ics files.\r\n */\r\nexport class Calendar {\r\n // #region Properties\r\n\r\n /**\r\n * The events that exist for this calendar.\r\n */\r\n public events: Event[] = [];\r\n\r\n // #endregion\r\n\r\n // #region Constructors\r\n\r\n /**\r\n * Creates a new Calendar instance.\r\n *\r\n * @param icsContent The content from an ICS file to initialize the calendar with.\r\n *\r\n * @returns A new Calendar instance.\r\n */\r\n public constructor(icsContent: string | undefined = undefined) {\r\n if (icsContent === undefined) {\r\n return;\r\n }\r\n\r\n const feeder = new LineFeeder(icsContent);\r\n\r\n this.parse(feeder);\r\n }\r\n\r\n // #endregion\r\n\r\n // #region Functions\r\n\r\n /**\r\n * Builds the calendar into a string that conforms to ICS format.\r\n *\r\n * @returns An ICS formatted string that represents the calendar data.\r\n */\r\n public build(): string | null {\r\n const lines: string[] = [];\r\n\r\n lines.push(\"BEGIN:VCALENDAR\");\r\n lines.push(\"PRODID:-//github.com/SparkDevNetwork/Rock//NONSGML Rock//EN\");\r\n lines.push(\"VERSION:2.0\");\r\n\r\n for (const event of this.events) {\r\n lines.push(...event.buildLines());\r\n }\r\n\r\n lines.push(\"END:VCALENDAR\");\r\n\r\n return denormalizeLineLength(lines).join(\"\\r\\n\");\r\n }\r\n\r\n /**\r\n * Parses the ICS data from a line feeder and constructs the calendar\r\n * from that data.\r\n *\r\n * @param feeder The feeder that provides the individual lines.\r\n */\r\n private parse(feeder: LineFeeder): void {\r\n let line: string | null;\r\n\r\n // Parse the line data.\r\n while ((line = feeder.peek()) !== null) {\r\n if (line === \"BEGIN:VEVENT\") {\r\n const event = new Event(feeder);\r\n\r\n this.events.push(event);\r\n }\r\n else {\r\n feeder.pop();\r\n }\r\n }\r\n }\r\n\r\n // #endregion\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Liquid } from \"@Obsidian/Libs/liquidjs\";\r\n\r\nconst engine = new Liquid({\r\n cache: true\r\n});\r\n\r\nexport function resolveMergeFields(template: string, mergeFields: Record): string {\r\n const tpl = engine.parse(template);\r\n\r\n return engine.renderSync(tpl, mergeFields);\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\n\r\nexport function asListItemBagOrNull(bagJson: string): ListItemBag | null {\r\n try {\r\n const val = JSON.parse(bagJson);\r\n\r\n if (\"value\" in val || \"text\" in val) {\r\n return val;\r\n }\r\n\r\n return null;\r\n }\r\n catch (e) {\r\n return null;\r\n }\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { MergeFieldPickerFormatSelectedValueOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/mergeFieldPickerFormatSelectedValueOptionsBag\";\r\nimport { useHttp } from \"./http\";\r\n\r\n/**\r\n * Take a given mergeFieldPicker value and format it for Lava\r\n *\r\n * @param value The merge field to be formatted\r\n *\r\n * @returns The formatted string in a Promise\r\n */\r\nexport async function formatValue(value: string): Promise {\r\n const http = useHttp();\r\n\r\n const options: MergeFieldPickerFormatSelectedValueOptionsBag = {\r\n selectedValue: value\r\n };\r\n\r\n const response = await http.post(\"/api/v2/Controls/MergeFieldPickerFormatSelectedValue\", {}, options);\r\n\r\n if (response.isSuccess && response.data) {\r\n return response.data;\r\n }\r\n else {\r\n console.error(\"Error\", response.errorMessage || `Error formatting '${value}'.`);\r\n return \"\";\r\n }\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nexport function fromEntries(entries: Iterable<[PropertyKey, string]>): Record {\r\n const res = {};\r\n for (const entry of entries) {\r\n res[entry[0]] = entry[1];\r\n }\r\n return res;\r\n}","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport Cache from \"./cache\";\r\nimport { useHttp } from \"./http\";\r\nimport { PhoneNumberBoxGetConfigurationResultsBag } from \"@Obsidian/ViewModels/Rest/Controls/phoneNumberBoxGetConfigurationResultsBag\";\r\nimport { PhoneNumberCountryCodeRulesConfigurationBag } from \"@Obsidian/ViewModels/Rest/Controls/phoneNumberCountryCodeRulesConfigurationBag\";\r\nimport { PhoneNumberBoxGetConfigurationOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/phoneNumberBoxGetConfigurationOptionsBag\";\r\n\r\nconst http = useHttp();\r\n\r\n/**\r\n * Fetch the configuration for phone numbers and their possible formats for different countries\r\n */\r\nasync function fetchPhoneNumberConfiguration(): Promise {\r\n const result = await http.post(\"/api/v2/Controls/PhoneNumberBoxGetConfiguration\", undefined, null);\r\n\r\n if (result.isSuccess && result.data) {\r\n return result.data;\r\n }\r\n\r\n throw new Error(result.errorMessage ?? \"Error fetching phone number configuration\");\r\n}\r\n\r\n/**\r\n * Fetch the configuration for phone numbers, SMS option, and possible phone number formats for different countries\r\n */\r\nasync function fetchPhoneNumberAndSmsConfiguration(): Promise {\r\n const options: Partial = {\r\n showSmsOptIn: true\r\n };\r\n const result = await http.post(\"/api/v2/Controls/PhoneNumberBoxGetConfiguration\", undefined, options);\r\n\r\n if (result.isSuccess && result.data) {\r\n return result.data;\r\n }\r\n\r\n throw new Error(result.errorMessage ?? \"Error fetching phone number configuration\");\r\n}\r\n\r\n/**\r\n * Fetch the configuration for phone numbers and their possible formats for different countries.\r\n * Cacheable version of fetchPhoneNumberConfiguration cacheable\r\n */\r\nexport const getPhoneNumberConfiguration = Cache.cachePromiseFactory(\"phoneNumberConfiguration\", fetchPhoneNumberConfiguration);\r\n\r\nexport const getPhoneNumberAndSmsConfiguration = Cache.cachePromiseFactory(\"phoneNumberAndSmsConfiguration\", fetchPhoneNumberAndSmsConfiguration);\r\n\r\nconst defaultRulesConfig = [\r\n {\r\n \"match\": \"^(\\\\d{3})(\\\\d{4})$\",\r\n \"format\": \"$1-$2\"\r\n },\r\n {\r\n \"match\": \"^(\\\\d{3})(\\\\d{3})(\\\\d{4})$\",\r\n \"format\": \"($1) $2-$3\"\r\n },\r\n {\r\n \"match\": \"^1(\\\\d{3})(\\\\d{3})(\\\\d{4})$\",\r\n \"format\": \"($1) $2-$3\"\r\n }\r\n];\r\n\r\n/**\r\n * Format a phone number according to a given configuration\r\n *\r\n * e.g. from the default configuration:\r\n * 3214567 => 321-4567\r\n * 3214567890 => (321) 456-7890\r\n */\r\nexport function formatPhoneNumber(value: string, rules: PhoneNumberCountryCodeRulesConfigurationBag[] = defaultRulesConfig): string {\r\n value = stripPhoneNumber(value);\r\n\r\n if (!value || rules.length == 0) {\r\n return value;\r\n }\r\n\r\n for (const rule of rules) {\r\n const regex = new RegExp(rule.match ?? \"\");\r\n\r\n if (regex.test(value)) {\r\n return value.replace(regex, rule.format ?? \"\") || value;\r\n }\r\n }\r\n\r\n return value;\r\n}\r\n\r\n/**\r\n * Strips special characters from the phone number.\r\n * (321) 456-7890 => 3214567890\r\n * @param str\r\n */\r\nexport function stripPhoneNumber(str: string): string {\r\n if (!str) {\r\n return \"\";\r\n }\r\n\r\n return str.replace(/\\D/g, \"\");\r\n}\r\n\r\nexport default {\r\n getPhoneNumberConfiguration,\r\n formatPhoneNumber,\r\n stripPhoneNumber\r\n};\r\n\r\n/* eslint-disable */\r\n// @ts-ignore\r\nwindow.formatPhoneNumber = formatPhoneNumber;","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n\r\n// NOTE: Do not make this public yet. This is essentially temporary and\r\n// will likely move to a different place and be merged with the tooltip\r\n// concept code as well.\r\ntype PopoverOptions = {\r\n /** Allow HTML content in the popover. */\r\n html?: boolean;\r\n\r\n /** Enables santization of HTML content. */\r\n sanitize?: boolean;\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ndeclare const $: any;\r\n\r\n/**\r\n * Configure a popover for the specified node or nodes to show on hover. This\r\n * currently uses Bootstrap popovers but may be changed to use a different\r\n * method later.\r\n * \r\n * @param node The node or nodes to have popovers configured on.\r\n * @param options The options that describe how the popovers should behave.\r\n */\r\nexport function popover(node: Element | Element[], options?: PopoverOptions): void {\r\n // If we got an array of elements then activate each one.\r\n if (Array.isArray(node)) {\r\n for (const n of node) {\r\n popover(n, options);\r\n }\r\n\r\n return;\r\n }\r\n\r\n $(node).popover({\r\n html: options?.html,\r\n sanitize: options?.sanitize ?? true\r\n });\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n/**\r\n * Returns a promise that completes after the specified number of milliseconds\r\n * have ellapsed.\r\n * \r\n * @param ms The number of milliseconds to wait.\r\n * \r\n * @returns A promise that completes after the interval has ellapsed.\r\n */\r\nexport function sleep(ms: number): Promise {\r\n return new Promise(resolve => {\r\n setTimeout(resolve, ms);\r\n });\r\n}\r\n\r\n/**\r\n * Checks if the value is a promise to return a value. This is used to check\r\n * if a function that could have returned either a value or a promise for a\r\n * value returned a promise.\r\n * \r\n * @param obj The object to be tested if it is a promise.\r\n *\r\n * @returns True if the object is a promise.\r\n */\r\nexport function isPromise(obj: PromiseLike | T): obj is PromiseLike {\r\n return !!obj && (typeof obj === \"object\" || typeof obj === \"function\") && typeof (obj as Record).then === \"function\";\r\n}\r\n\r\n/**\r\n * A class that provides a way to defer execution via await until some\r\n * external trigger happens.\r\n */\r\nexport class PromiseCompletionSource {\r\n private internalPromise: Promise;\r\n\r\n private internalResolve: (T) => void = () => { /* Intentionally blank. */ };\r\n\r\n private internalReject: (reason?: unknown) => void = () => { /* Intentionally blank. */ };\r\n\r\n constructor() {\r\n this.internalPromise = new Promise((resolve, reject) => {\r\n this.internalResolve = resolve;\r\n this.internalReject = reject;\r\n });\r\n }\r\n\r\n /** The promise that can be awaited. */\r\n public get promise(): Promise {\r\n return this.internalPromise;\r\n }\r\n\r\n /**\r\n * Resolves the promise with the given value.\r\n * \r\n * @param value The value to be returned by the await call.\r\n */\r\n public resolve(value: T): void {\r\n this.internalResolve(value);\r\n }\r\n\r\n /**\r\n * Rejects the promise and throws the reason as an error.\r\n * \r\n * @param reason The reason to be thrown by the await call.\r\n */\r\n public reject(reason?: unknown): void {\r\n this.internalReject(reason);\r\n }\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { loadJavaScriptAsync } from \"./page\";\r\n\r\n// Disable certain checks as they are needed to interface with existing JS file.\r\n/* eslint-disable @typescript-eslint/ban-types */\r\n/* eslint-disable @typescript-eslint/no-explicit-any */\r\n\r\n/** A generic set a server functions with no type checking. */\r\nexport type GenericServerFunctions = {\r\n [name: string]: (...args: unknown[]) => unknown;\r\n};\r\n\r\n/** A set of specific server functions that conform to an interface. */\r\nexport type ServerFunctions = {\r\n [K in keyof T]: T[K] extends Function ? T[K] : never;\r\n};\r\n\r\n/**\r\n * An object that allows RealTime communication between the browser and the Rock\r\n * server over a specific topic.\r\n */\r\nexport interface ITopic = GenericServerFunctions> {\r\n /**\r\n * Allows messages to be sent to the server. Any property access is treated\r\n * like a message function whose property name is the message name.\r\n */\r\n server: TServer;\r\n\r\n /**\r\n * Gets the connection identifier for this topic. This will be the same for\r\n * all topics, but that should not be relied on staying that way in the future.\r\n */\r\n get connectionId(): string | null;\r\n\r\n /**\r\n * Gets a value that indicates if the topic is currently reconnecting.\r\n */\r\n get isReconnecting(): boolean;\r\n\r\n /**\r\n * Gets a value that indicates if the topic is disconnected and will no\r\n * longer try to connect to the server.\r\n */\r\n get isDisconnected(): boolean;\r\n\r\n /**\r\n * Registers a handler to be called when a message with the given name\r\n * is received.\r\n *\r\n * @param messageName The message name that will trigger the handler.\r\n * @param handler The handler to be called when a message is received.\r\n */\r\n on(messageName: string, handler: ((...args: any[]) => void)): void;\r\n\r\n /**\r\n * Registers a handler to be called when any message is received.\r\n *\r\n * @param handler The handler to be called when a message is received.\r\n */\r\n onMessage(handler: ((messageName: string, args: unknown[]) => void)): void;\r\n\r\n /**\r\n * Registers a callback to be called when the connection has been\r\n * temporarily lost. An automatic reconnection is in progress. The topic\r\n * is now in a state where it can not send any messages.\r\n *\r\n * @param callback The callback to be called.\r\n */\r\n onReconnecting(callback: (() => void)): void;\r\n\r\n /**\r\n * Registers a callback to be called when the connection has been\r\n * reconnected. The topic can now send messages again.\r\n *\r\n * @param callback The callback to be called.\r\n */\r\n onReconnected(callback: (() => void)): void;\r\n\r\n /**\r\n * Registers a callback to be called when the connection has been lost\r\n * and will no longer try to reconnect.\r\n *\r\n * @param callback The callback to be called.\r\n */\r\n onDisconnected(callback: (() => void)): void;\r\n}\r\n\r\ninterface IRockRealTimeStatic {\r\n getTopic>(identifier: string): Promise>;\r\n}\r\n\r\nlet libraryObject: IRockRealTimeStatic | null = null;\r\nlet libraryPromise: Promise | null = null;\r\n\r\n/**\r\n * Gets the real time object from window.Rock.RealTime. If it is not available\r\n * then an exception will be thrown.\r\n *\r\n * @returns An instance of IRockRealTimeStatic.\r\n */\r\nasync function getRealTimeObject(): Promise {\r\n if (libraryObject) {\r\n return libraryObject;\r\n }\r\n\r\n if (!libraryPromise) {\r\n libraryPromise = loadJavaScriptAsync(\"/Scripts/Rock/realtime.js\", () => !!window[\"Rock\"]?.[\"RealTime\"]);\r\n }\r\n\r\n if (!await libraryPromise) {\r\n throw new Error(\"Unable to load RealTime library.\");\r\n }\r\n\r\n libraryObject = window[\"Rock\"]?.[\"RealTime\"] as IRockRealTimeStatic;\r\n\r\n return libraryObject;\r\n}\r\n\r\n/**\r\n * Connects to a specific topic in the Rock RealTime system and returns an\r\n * instance to a proxy that handles sending to and receiving messages from\r\n * that specific topic.\r\n *\r\n * @param identifier The identifier of the topic to be connected to.\r\n *\r\n * @returns A proxy to handle communication with the topic.\r\n */\r\nexport async function getTopic>(identifier: string): Promise> {\r\n const realTime = await getRealTimeObject();\r\n\r\n return realTime.getTopic(identifier);\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { ListItemBag } from \"@Obsidian/ViewModels/Utility/listItemBag\";\r\nimport { toNumber, toNumberOrNull } from \"./numberUtils\";\r\nimport { SlidingDateRangeType as RangeType, SlidingDateRangeType } from \"@Obsidian/Enums/Controls/slidingDateRangeType\";\r\nimport { TimeUnitType as TimeUnit } from \"@Obsidian/Enums/Controls/timeUnitType\";\r\nimport { DayOfWeek, RockDateTime } from \"./rockDateTime\";\r\n\r\n// This file contains helper functions and tooling required to work with sliding\r\n// date ranges. A sliding date range is one that, generally, is anchored to whatever\r\n// the current date and time is when the check is made. For example, \"within the next\r\n// 5 days\" would be the english equivalent of a sliding date range.\r\n\r\n/**\r\n * The enums have been moved to separate files in order to share with the back end. We import them\r\n * above (with the names used by the definitions that used to exist in this file) so they can be\r\n * used below and we export them here so that any files previously importing them from here\r\n * do not break.\r\n */\r\nexport { SlidingDateRangeType as RangeType } from \"@Obsidian/Enums/Controls/slidingDateRangeType\";\r\nexport { TimeUnitType as TimeUnit } from \"@Obsidian/Enums/Controls/timeUnitType\";\r\n\r\n/**\r\n * Specifies the information required to track a sliding date range.\r\n */\r\nexport type SlidingDateRange = {\r\n /** The type of sliding date range represented by this instance. */\r\n rangeType: RangeType;\r\n\r\n /** The unit of time represented by the timeValue property. */\r\n timeUnit?: TimeUnit;\r\n\r\n /** The number of time units used when calculating the date range. */\r\n timeValue?: number;\r\n\r\n /** The lower value of a specific date range. */\r\n lowerDate?: string;\r\n\r\n /** The upper value of a specific date range. */\r\n upperDate?: string;\r\n};\r\n\r\n/**\r\n * The sliding date range types represented as an array of ListItemBag objects.\r\n * These are ordered correctly and can be used in pickers.\r\n */\r\nexport const rangeTypeOptions: ListItemBag[] = [\r\n {\r\n value: RangeType.Current.toString(),\r\n text: \"Current\"\r\n },\r\n {\r\n value: RangeType.Previous.toString(),\r\n text: \"Previous\"\r\n },\r\n {\r\n value: RangeType.Last.toString(),\r\n text: \"Last\"\r\n },\r\n {\r\n value: RangeType.Next.toString(),\r\n text: \"Next\"\r\n },\r\n {\r\n value: RangeType.Upcoming.toString(),\r\n text: \"Upcoming\"\r\n },\r\n {\r\n value: RangeType.DateRange.toString(),\r\n text: \"Date Range\"\r\n }\r\n];\r\n\r\n/**\r\n * The sliding date range time units represented as an array of ListItemBag objects.\r\n * These are ordered correctly and can be used in pickers.\r\n */\r\nexport const timeUnitOptions: ListItemBag[] = [\r\n {\r\n value: TimeUnit.Hour.toString(),\r\n text: \"Hour\"\r\n },\r\n {\r\n value: TimeUnit.Day.toString(),\r\n text: \"Day\"\r\n },\r\n {\r\n value: TimeUnit.Week.toString(),\r\n text: \"Week\"\r\n },\r\n {\r\n value: TimeUnit.Month.toString(),\r\n text: \"Month\"\r\n },\r\n {\r\n value: TimeUnit.Year.toString(),\r\n text: \"Year\"\r\n },\r\n];\r\n\r\n/**\r\n * Helper function to get the text from a ListItemBag that matches the value.\r\n *\r\n * @param value The value to be searched for.\r\n * @param options The ListItemBag options to be searched.\r\n *\r\n * @returns The text value of the ListItemBag or an empty string if not found.\r\n */\r\nfunction getTextForValue(value: string, options: ListItemBag[]): string {\r\n const matches = options.filter(v => v.value === value);\r\n\r\n return matches.length > 0 ? matches[0].text ?? \"\" : \"\";\r\n}\r\n\r\n/**\r\n * Gets the user friendly text that represents the RangeType value.\r\n *\r\n * @param rangeType The RangeType value to be represented.\r\n *\r\n * @returns A human readable string that represents the RangeType value.\r\n */\r\nexport function getRangeTypeText(rangeType: RangeType): string {\r\n const rangeTypes = rangeTypeOptions.filter(o => o.value === rangeType.toString());\r\n\r\n return rangeTypes.length > 0 ? rangeTypes[0].text ?? \"\" : \"\";\r\n}\r\n\r\n/**\r\n * Gets the user friendly text that represents the TimeUnit value.\r\n *\r\n * @param timeUnit The TimeUnit value to be represented.\r\n *\r\n * @returns A human readable string that represents the TimeUnit value.\r\n */\r\nexport function getTimeUnitText(timeUnit: TimeUnit): string {\r\n const timeUnits = timeUnitOptions.filter(o => o.value === timeUnit.toString());\r\n\r\n return timeUnits.length > 0 ? timeUnits[0].text ?? \"\" : \"\";\r\n}\r\n\r\n/**\r\n * Parses a pipe delimited string into a SlidingDateRange native object. The\r\n * delimited string is a format used by attribute values and other places.\r\n *\r\n * @param value The pipe delimited string that should be parsed.\r\n *\r\n * @returns A SlidingDaterange object or null if the string could not be parsed.\r\n */\r\nexport function parseSlidingDateRangeString(value: string): SlidingDateRange | null {\r\n const segments = value.split(\"|\");\r\n\r\n if (segments.length < 3) {\r\n return null;\r\n }\r\n\r\n // Find the matching range types and time units (should be 0 or 1) that\r\n // match the values in the string.\r\n const rangeTypes = rangeTypeOptions.filter(o => (o.text ?? \"\").replace(\" \", \"\").toLowerCase() === segments[0].toLowerCase() || o.value === segments[0]);\r\n const timeUnits = timeUnitOptions.filter(o => (o.text ?? \"\").toLowerCase() === segments[2].toLowerCase() || o.value === segments[2]);\r\n\r\n if (rangeTypes.length === 0) {\r\n return null;\r\n }\r\n\r\n const range: SlidingDateRange = {\r\n rangeType: toNumber(rangeTypes[0].value)\r\n };\r\n\r\n // If the range type is one that has time units then parse the time units.\r\n if (([RangeType.Current, RangeType.Last, RangeType.Next, RangeType.Previous, RangeType.Upcoming] as number[]).includes(range.rangeType)) {\r\n range.timeUnit = timeUnits.length > 0 ? toNumber(timeUnits[0].value) as TimeUnit : TimeUnit.Hour;\r\n\r\n // If the range type is one that has time values then parse the time value.\r\n if (([RangeType.Last, RangeType.Next, RangeType.Previous, RangeType.Upcoming] as number[]).includes(range.rangeType)) {\r\n range.timeValue = toNumberOrNull(segments[1]) ?? 1;\r\n }\r\n }\r\n\r\n // Parse the lower and upper dates if our range type is a DateRange.\r\n if (range.rangeType === RangeType.DateRange) {\r\n if (segments.length > 3) {\r\n range.lowerDate = segments[3];\r\n }\r\n\r\n if (segments.length > 4) {\r\n range.upperDate = segments[4];\r\n }\r\n }\r\n\r\n return range;\r\n}\r\n\r\n/**\r\n * Formats the pipe delimited string.\r\n *\r\n * @param value The pipe delimited string that should be formatted.\r\n *\r\n * @returns A string that formats the sliding date range.\r\n */\r\nexport function slidingDateRangeToString(value: SlidingDateRange): string {\r\n\r\n switch (value.rangeType) {\r\n case RangeType.Current:\r\n return `Current||${getTextForValue(value.timeUnit?.toString() ?? \"\", timeUnitOptions)}||`;\r\n\r\n case RangeType.DateRange:\r\n return `DateRange|||${value.lowerDate ?? \"\"}|${value.upperDate ?? \"\"}`;\r\n\r\n default:\r\n return `${getTextForValue(value.rangeType.toString(), rangeTypeOptions)}|${value.timeValue ?? \"\"}|${getTextForValue(value.timeUnit?.toString() ?? \"\", timeUnitOptions)}||`;\r\n }\r\n}\r\n\r\n/**\r\n * Calculates the start and end dates in a sliding date range.\r\n *\r\n * @param value The sliding date range to use when calculating dates.\r\n * @param currentDateTime The date and time to use in any \"now\" calculations.\r\n *\r\n * @returns An object that contains the start and end dates and times.\r\n */\r\nexport function calculateSlidingDateRange(value: SlidingDateRange, currentDateTime: RockDateTime | null | undefined = undefined): { start: RockDateTime | null, end: RockDateTime | null } {\r\n const result: { start: RockDateTime | null, end: RockDateTime | null } = {\r\n start: null,\r\n end: null\r\n };\r\n\r\n if (!currentDateTime) {\r\n currentDateTime = RockDateTime.now();\r\n }\r\n\r\n if (value.rangeType === RangeType.Current) {\r\n if (value.timeUnit === TimeUnit.Hour) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, currentDateTime.day, currentDateTime.hour, 0, 0);\r\n result.end = result.start?.addHours(1) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Day) {\r\n result.start = currentDateTime.date;\r\n result.end = result.start.addDays(1);\r\n }\r\n else if (value.timeUnit === TimeUnit.Week) {\r\n // TODO: This needs to be updated to get the FirstDayOfWeek from server.\r\n let diff = currentDateTime.dayOfWeek - DayOfWeek.Monday;\r\n\r\n if (diff < 0) {\r\n diff += 7;\r\n }\r\n\r\n result.start = currentDateTime.addDays(-1 * diff).date;\r\n result.end = result.start.addDays(7);\r\n }\r\n else if (value.timeUnit === TimeUnit.Month) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, 1);\r\n result.end = result.start?.addMonths(1) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Year) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, 1, 1);\r\n result.end = RockDateTime.fromParts(currentDateTime.year + 1, 1, 1);\r\n }\r\n }\r\n else if (value.rangeType === RangeType.Last || value.rangeType === RangeType.Previous) {\r\n // The number of time units to adjust by.\r\n const count = value.timeValue ?? 1;\r\n\r\n // If we are getting \"Last\" then round up to include the\r\n // current day/week/month/year.\r\n const roundUpCount = value.rangeType === RangeType.Last ? 1 : 0;\r\n\r\n if (value.timeUnit === TimeUnit.Hour) {\r\n result.end = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, currentDateTime.day, currentDateTime.hour, 0, 0)\r\n ?.addHours(roundUpCount) ?? null;\r\n result.start = result.end?.addHours(-count) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Day) {\r\n result.end = currentDateTime.date.addDays(roundUpCount);\r\n result.start = result.end?.addDays(-count) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Week) {\r\n // TODO: This needs to be updated to get the FirstDayOfWeek from server.\r\n let diff = currentDateTime.dayOfWeek - DayOfWeek.Monday;\r\n\r\n if (diff < 0) {\r\n diff += 7;\r\n }\r\n\r\n result.end = currentDateTime.addDays(-1 * diff).date.addDays(7 * roundUpCount);\r\n result.start = result.end.addDays(-count * 7);\r\n }\r\n else if (value.timeUnit === TimeUnit.Month) {\r\n result.end = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, 1)?.addMonths(roundUpCount) ?? null;\r\n result.start = result.end?.addMonths(-count) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Year) {\r\n result.end = RockDateTime.fromParts(currentDateTime.year, 1, 1)?.addYears(roundUpCount) ?? null;\r\n result.start = result.end?.addYears(-count) ?? null;\r\n }\r\n\r\n // don't let Last,Previous have any future dates\r\n const cutoffDate = currentDateTime.date.addDays(1);\r\n if (result.end && result.end.date > cutoffDate) {\r\n result.end = cutoffDate;\r\n }\r\n }\r\n else if (value.rangeType === RangeType.Next || value.rangeType === RangeType.Upcoming) {\r\n // The number of time units to adjust by.\r\n const count = value.timeValue ?? 1;\r\n\r\n // If we are getting \"Upcoming\" then round up to include the\r\n // current day/week/month/year.\r\n const roundUpCount = value.rangeType === RangeType.Upcoming ? 1 : 0;\r\n\r\n if (value.timeUnit === TimeUnit.Hour) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, currentDateTime.day, currentDateTime.hour, 0, 0)\r\n ?.addHours(roundUpCount) ?? null;\r\n result.end = result.start?.addHours(count) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Day) {\r\n result.start = currentDateTime.date.addDays(roundUpCount);\r\n result.end = result.start.addDays(count);\r\n }\r\n else if (value.timeUnit === TimeUnit.Week) {\r\n // TODO: This needs to be updated to get the FirstDayOfWeek from server.\r\n let diff = currentDateTime.dayOfWeek - DayOfWeek.Monday;\r\n\r\n if (diff < 0) {\r\n diff += 7;\r\n }\r\n\r\n result.start = currentDateTime.addDays(-1 * diff)\r\n .date.addDays(7 * roundUpCount);\r\n result.end = result.start.addDays(count * 7);\r\n }\r\n else if (value.timeUnit === TimeUnit.Month) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, currentDateTime.month, 1)\r\n ?.addMonths(roundUpCount) ?? null;\r\n result.end = result.start?.addMonths(count) ?? null;\r\n }\r\n else if (value.timeUnit === TimeUnit.Year) {\r\n result.start = RockDateTime.fromParts(currentDateTime.year, 1, 1)\r\n ?.addYears(roundUpCount) ?? null;\r\n result.end = result.start?.addYears(count) ?? null;\r\n }\r\n\r\n // don't let Next,Upcoming have any past dates\r\n if (result.start && result.start.date < currentDateTime.date) {\r\n result.start = currentDateTime.date;\r\n }\r\n }\r\n else if (value.rangeType === RangeType.DateRange) {\r\n result.start = RockDateTime.parseISO(value.lowerDate ?? \"\");\r\n result.end = RockDateTime.parseISO(value.upperDate ?? \"\");\r\n\r\n // Sliding date range does not use ISO dates (though might be changed\r\n // in the future). So if we can't parse as an ISO date then try a\r\n // natural parse.\r\n if (!result.start && value.lowerDate) {\r\n result.start = RockDateTime.fromJSDate(new Date(value.lowerDate));\r\n }\r\n\r\n if (!result.end && value.upperDate) {\r\n result.end = RockDateTime.fromJSDate(new Date(value.upperDate));\r\n }\r\n\r\n if (result.end) {\r\n // Add a day to the end so that we get the entire day when comparing.\r\n result.end = result.end.addDays(1);\r\n }\r\n }\r\n\r\n // To avoid confusion about the day or hour of the end of the date range,\r\n // subtract a millisecond off our 'less than' end date. For example, if our\r\n // end date is 2019-11-7, we actually want all the data less than 2019-11-8,\r\n // but if a developer does EndDate.DayOfWeek, they would want 2019-11-7 and\r\n // not 2019-11-8 So, to make sure we include all the data for 2019-11-7, but\r\n // avoid the confusion about what DayOfWeek of the end, we'll compromise by\r\n // subtracting a millisecond from the end date\r\n if (result.end && value.timeUnit != TimeUnit.Hour) {\r\n result.end = result.end.addMilliseconds(-1);\r\n }\r\n\r\n return result;\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n\r\nimport { useHttp } from \"./http\";\r\nimport { StructuredContentEditorConfigurationBag } from \"@Obsidian/ViewModels/Rest/Controls/structuredContentEditorConfigurationBag\";\r\nimport { StructuredContentEditorGetConfigurationOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/structuredContentEditorGetConfigurationOptionsBag\";\r\n\r\nconst http = useHttp();\r\n\r\n/** Fetches the configuration for the structured content editor. */\r\nexport async function getStructuredContentEditorConfiguration(options: StructuredContentEditorGetConfigurationOptionsBag): Promise {\r\n const result = await http.post(\"/api/v2/Controls/StructuredContentEditorGetConfiguration\", undefined, options);\r\n\r\n if (result.isSuccess && result.data) {\r\n return result.data;\r\n }\r\n\r\n throw new Error(result.errorMessage || \"Error fetching structured content editor configuration\");\r\n}\r\n\r\nexport default {\r\n getStructuredContentEditorConfiguration\r\n};","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\n\r\n// NOTE: Do not make this public yet. This is essentially temporary and\r\n// will likely move to a different place and be merged with the popover\r\n// concept code as well.\r\ntype TooltipOptions = {\r\n /** Allow HTML content in the tooltip. */\r\n html?: boolean;\r\n\r\n /** Enables santization of HTML content. */\r\n sanitize?: boolean;\r\n};\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\r\ndeclare const $: any;\r\n\r\n/**\r\n * Configure a tooltip for the specified node or nodes to show on hover. This\r\n * currently uses Bootstrap tooltips but may be changed to use a different\r\n * method later.\r\n * \r\n * @param node The node or nodes to have tooltips configured on.\r\n * @param options The options that describe how the tooltips should behave.\r\n */\r\nexport function tooltip(node: Element | Element[], options?: TooltipOptions): void {\r\n // If we got an array of elements then activate each one.\r\n if (Array.isArray(node)) {\r\n for (const n of node) {\r\n tooltip(n, options);\r\n }\r\n\r\n return;\r\n }\r\n\r\n $(node).tooltip({\r\n html: options?.html,\r\n sanitize: options?.sanitize ?? true\r\n });\r\n}\r\n\r\n/**\r\n * Manually show a previously-configured tooltip for the specified node.\r\n *\r\n * @param node The node for which to show a tooltip\r\n */\r\nexport function showTooltip(node: Element): void {\r\n $(node).tooltip(\"show\");\r\n}\r\n","// \r\n// Copyright by the Spark Development Network\r\n//\r\n// Licensed under the Rock Community License (the \"License\");\r\n// you may not use this file except in compliance with the License.\r\n// You may obtain a copy of the License at\r\n//\r\n// http://www.rockrms.com/license\r\n//\r\n// Unless required by applicable law or agreed to in writing, software\r\n// distributed under the License is distributed on an \"AS IS\" BASIS,\r\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n// See the License for the specific language governing permissions and\r\n// limitations under the License.\r\n// \r\n//\r\n\r\nimport { Guid } from \"@Obsidian/Types\";\r\nimport { emptyGuid } from \"./guid\";\r\nimport { post } from \"./http\";\r\nimport { TreeItemBag } from \"@Obsidian/ViewModels/Utility/treeItemBag\";\r\nimport { CategoryPickerChildTreeItemsOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/categoryPickerChildTreeItemsOptionsBag\";\r\nimport { LocationItemPickerGetActiveChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/locationItemPickerGetActiveChildrenOptionsBag\";\r\nimport { DataViewPickerGetDataViewsOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/dataViewPickerGetDataViewsOptionsBag\";\r\nimport { WorkflowTypePickerGetWorkflowTypesOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/workflowTypePickerGetWorkflowTypesOptionsBag\";\r\nimport { PagePickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/pagePickerGetChildrenOptionsBag\";\r\nimport { PagePickerGetSelectedPageHierarchyOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/pagePickerGetSelectedPageHierarchyOptionsBag\";\r\nimport { ConnectionRequestPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/connectionRequestPickerGetChildrenOptionsBag\";\r\nimport { GroupPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/groupPickerGetChildrenOptionsBag\";\r\nimport { MergeTemplatePickerGetMergeTemplatesOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/mergeTemplatePickerGetMergeTemplatesOptionsBag\";\r\nimport { MergeTemplateOwnership } from \"@Obsidian/Enums/Controls/mergeTemplateOwnership\";\r\nimport { MetricCategoryPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/metricCategoryPickerGetChildrenOptionsBag\";\r\nimport { MetricItemPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/metricItemPickerGetChildrenOptionsBag\";\r\nimport { RegistrationTemplatePickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/registrationTemplatePickerGetChildrenOptionsBag\";\r\nimport { ReportPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/reportPickerGetChildrenOptionsBag\";\r\nimport { SchedulePickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/schedulePickerGetChildrenOptionsBag\";\r\nimport { WorkflowActionTypePickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/workflowActionTypePickerGetChildrenOptionsBag\";\r\nimport { MergeFieldPickerGetChildrenOptionsBag } from \"@Obsidian/ViewModels/Rest/Controls/mergeFieldPickerGetChildrenOptionsBag\";\r\nimport { flatten } from \"./arrayUtils\";\r\nimport { toNumberOrNull } from \"./numberUtils\";\r\n\r\n/**\r\n * The methods that must be implemented by tree item providers. These methods\r\n * provide the TreeItem objects to be displayed when lazy loading is being used.\r\n */\r\nexport interface ITreeItemProvider {\r\n /**\r\n * Get the root items to be displayed in the tree list.\r\n *\r\n * @param expandToValues The values that should be auto-expanded to. This will contain\r\n * the nodes that should be visible when the data is returned, they should not be\r\n * expanded themselves, only any ancestor nodes.\r\n *\r\n * @returns A collection of TreeItem objects, optionally wrapped in a Promise\r\n * if the loading is being performed asynchronously.\r\n */\r\n getRootItems(expandToValues: string[]): Promise | TreeItemBag[];\r\n\r\n /**\r\n * Get the child items of the given tree item.\r\n *\r\n * @param item The parent item whose children should be loaded.\r\n *\r\n * @returns A collection of TreeItem objects, optionally wrapped in a Promise\r\n * if the loading is being performed asynchronously.\r\n */\r\n getChildItems(item: TreeItemBag): Promise | TreeItemBag[];\r\n\r\n /**\r\n * Checks if the item can be selected by the individual. This function\r\n * is optional.\r\n *\r\n * @param item The item that is about to be selected.\r\n * @param isSelectable True if the tree view considers the item selectable.\r\n *\r\n * @returns A boolean that determines the final selectable state of the item.\r\n */\r\n canSelectItem?(item: TreeItemBag, isSelectable: boolean): boolean;\r\n}\r\n\r\n/**\r\n * Tree Item Provider for retrieving categories from the server and displaying\r\n * them inside a tree list.\r\n */\r\nexport class CategoryTreeItemProvider implements ITreeItemProvider {\r\n /**\r\n * The root category to start pulling categories from. Set to undefined to\r\n * begin with any category that does not have a parent.\r\n */\r\n public rootCategoryGuid?: Guid;\r\n\r\n /**\r\n * The entity type unique identifier to restrict results to. Set to undefined\r\n * to include all categories, regardless of entity type.\r\n */\r\n public entityTypeGuid?: Guid;\r\n\r\n /**\r\n * The value that must match in the category EntityTypeQualifierColumn\r\n * property. Set to undefined or an empty string to ignore.\r\n */\r\n public entityTypeQualifierColumn?: string;\r\n\r\n /**\r\n * The value that must match in the category EntityTypeQualifierValue\r\n * property.\r\n */\r\n public entityTypeQualifierValue?: string;\r\n\r\n /**\r\n * The security grant token that will be used to request additional access\r\n * to the category list.\r\n */\r\n public securityGrantToken?: string | null;\r\n\r\n /**\r\n * Gets the child items from the server.\r\n *\r\n * @param parentGuid The parent item whose children are retrieved.\r\n *\r\n * @returns A collection of TreeItem objects as an asynchronous operation.\r\n */\r\n private async getItems(parentGuid?: Guid | null): Promise {\r\n const options: Partial = {\r\n parentGuid: parentGuid,\r\n entityTypeGuid: this.entityTypeGuid,\r\n entityTypeQualifierColumn: this.entityTypeQualifierColumn,\r\n entityTypeQualifierValue: this.entityTypeQualifierValue,\r\n lazyLoad: false,\r\n securityGrantToken: this.securityGrantToken\r\n };\r\n\r\n const response = await post(\"/api/v2/Controls/CategoryPickerChildTreeItems\", {}, options);\r\n\r\n if (response.isSuccess && response.data) {\r\n return response.data;\r\n }\r\n else {\r\n console.log(\"Error\", response.errorMessage);\r\n return [];\r\n }\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n */\r\n async getRootItems(): Promise {\r\n return await this.getItems(this.rootCategoryGuid);\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n */\r\n async getChildItems(item: TreeItemBag): Promise {\r\n return this.getItems(item.value);\r\n }\r\n}\r\n\r\n/**\r\n * Tree Item Provider for retrieving locations from the server and displaying\r\n * them inside a tree list.\r\n */\r\nexport class LocationTreeItemProvider implements ITreeItemProvider {\r\n /**\r\n * The security grant token that will be used to request additional access\r\n * to the category list.\r\n */\r\n public securityGrantToken?: string | null;\r\n\r\n /**\r\n * Gets the child items from the server.\r\n *\r\n * @param parentGuid The parent item whose children are retrieved.\r\n *\r\n * @returns A collection of TreeItem objects as an asynchronous operation.\r\n */\r\n private async getItems(parentGuid?: Guid | null): Promise {\r\n const options: Partial = {\r\n guid: parentGuid ?? emptyGuid,\r\n rootLocationGuid: emptyGuid,\r\n securityGrantToken: this.securityGrantToken\r\n };\r\n const url = \"/api/v2/Controls/LocationItemPickerGetActiveChildren\";\r\n const response = await post(url, undefined, options);\r\n\r\n if (response.isSuccess && response.data) {\r\n return response.data;\r\n }\r\n else {\r\n console.log(\"Error\", response.errorMessage);\r\n return [];\r\n }\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n */\r\n async getRootItems(): Promise {\r\n return await this.getItems(null);\r\n }\r\n\r\n /**\r\n * @inheritdoc\r\n */\r\n async getChildItems(item: TreeItemBag): Promise {\r\n return this.getItems(item.value);\r\n }\r\n}\r\n\r\n/**\r\n * Tree Item Provider for retrieving data views from the server and displaying\r\n * them inside a tree list.\r\n */\r\nexport class DataViewTreeItemProvider implements ITreeItemProvider {\r\n /**\r\n * The entity type unique identifier to restrict results to. Set to undefined\r\n * to include all categories, regardless of entity type.\r\n */\r\n public entityTypeGuid?: Guid;\r\n\r\n /**\r\n * The security grant token that will be used to request additional access\r\n * to the category list.\r\n */\r\n public securityGrantToken?: string | null;\r\n\r\n /**\r\n * The flag sets whether only persisted data view should be shown by the picker\r\n */\r\n public displayPersistedOnly: boolean = false;\r\n\r\n /**\r\n * Gets the child items from the server.\r\n *\r\n * @param parentGuid The parent item whose children are retrieved.\r\n *\r\n * @returns A collection of TreeItem objects as an asynchronous operation.\r\n */\r\n private async getItems(parentGuid?: Guid | null): Promise {\r\n const options: Partial = {\r\n parentGuid,\r\n getCategorizedItems: true,\r\n includeCategoriesWithoutChildren: false,\r\n entityTypeGuidFilter: this.entityTypeGuid,\r\n lazyLoad: false,\r\n securityGrantToken: this.securityGrantToken,\r\n displayPersistedOnly: this.displayPersistedOnly\r\n };\r\n\r\n const response = await post