{"version":3,"file":"PageState.js","sources":["../../Framework/PageState/index.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\nimport { State } from \"./state\";\r\nimport { shallowReadonly, reactive } from \"vue\";\r\nimport { PageConfig } from \"@Obsidian/Utility/page\";\r\nimport { RockDateTime } from \"@Obsidian/Utility/rockDateTime\";\r\n\r\n// This needs to move elsewhere probably.\r\nexport type PageDebugTiming = {\r\n title: string;\r\n subtitle: string;\r\n startTimeMs: number;\r\n finishTimeMs: number;\r\n};\r\n\r\n// This is the private state that we can modify.\r\nconst state: State = reactive({\r\n areSecondaryBlocksShown: true,\r\n currentPerson: null,\r\n isAnonymousVisitor: false,\r\n pageParameters: {},\r\n contextEntities: {},\r\n pageId: 0,\r\n pageGuid: \"\",\r\n executionStartTime: RockDateTime.now().toMilliseconds(),\r\n debugTimings: [],\r\n loginUrlWithReturnUrl: \"\"\r\n});\r\n\r\nexport class Store {\r\n public state: Readonly;\r\n\r\n constructor() {\r\n this.state = shallowReadonly(state);\r\n }\r\n\r\n setAreSecondaryBlocksShown(areSecondaryBlocksShown: boolean): void {\r\n state.areSecondaryBlocksShown = areSecondaryBlocksShown;\r\n }\r\n\r\n initialize(pageConfig: PageConfig): void {\r\n state.currentPerson = pageConfig.currentPerson || null;\r\n state.isAnonymousVisitor = pageConfig.isAnonymousVisitor;\r\n state.pageParameters = pageConfig.pageParameters || {};\r\n state.pageId = pageConfig.pageId || 0;\r\n state.pageGuid = pageConfig.pageGuid || \"\";\r\n state.executionStartTime = pageConfig.executionStartTime;\r\n state.loginUrlWithReturnUrl = pageConfig.loginUrlWithReturnUrl;\r\n }\r\n\r\n addPageDebugTiming(timing: PageDebugTiming): void {\r\n const pageStartTime = state.executionStartTime;\r\n const timestampMs = timing.startTimeMs - pageStartTime;\r\n const durationMs = timing.finishTimeMs - timing.startTimeMs;\r\n\r\n state.debugTimings.push({\r\n timestampMs: timestampMs,\r\n durationMs: durationMs,\r\n indentLevel: 1,\r\n isTitleBold: false,\r\n subTitle: timing.subtitle,\r\n title: timing.title\r\n });\r\n }\r\n\r\n // This should be replaced with something else, doesn't really fit as a store action.\r\n redirectToLogin(): void {\r\n if (state.loginUrlWithReturnUrl) {\r\n window.location.href = state.loginUrlWithReturnUrl;\r\n }\r\n }\r\n\r\n get isAuthenticated(): boolean {\r\n return !!state.currentPerson;\r\n }\r\n\r\n getPageParameter(key: string): unknown {\r\n return state.pageParameters[key];\r\n }\r\n}\r\n\r\nconst store = new Store();\r\n\r\nexport function useStore(): Store {\r\n return store;\r\n}\r\n"],"names":["state","reactive","areSecondaryBlocksShown","currentPerson","isAnonymousVisitor","pageParameters","contextEntities","pageId","pageGuid","executionStartTime","RockDateTime","now","toMilliseconds","debugTimings","loginUrlWithReturnUrl","Store","constructor","shallowReadonly","setAreSecondaryBlocksShown","initialize","pageConfig","addPageDebugTiming","timing","pageStartTime","timestampMs","startTimeMs","durationMs","finishTimeMs","push","indentLevel","isTitleBold","subTitle","subtitle","title","redirectToLogin","window","location","href","isAuthenticated","getPageParameter","key","store","useStore"],"mappings":";;;;;;;;;;;;;;YA8BA,IAAMA,KAAY,GAAGC,QAAQ,CAAC;YAC1BC,EAAAA,uBAAuB,EAAE,IAAI;YAC7BC,EAAAA,aAAa,EAAE,IAAI;YACnBC,EAAAA,kBAAkB,EAAE,KAAK;cACzBC,cAAc,EAAE,EAAE;cAClBC,eAAe,EAAE,EAAE;YACnBC,EAAAA,MAAM,EAAE,CAAC;YACTC,EAAAA,QAAQ,EAAE,EAAE;YACZC,EAAAA,kBAAkB,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