{"version":3,"file":"PageState.js","sources":["../../Framework/PageState/index.ts"],"sourcesContent":["// \n// Copyright by the Spark Development Network\n//\n// Licensed under the Rock Community License (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.rockrms.com/license\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// \n//\nimport { State } from \"./state\";\nimport { shallowReadonly, reactive } from \"vue\";\nimport { PageConfig } from \"@Obsidian/Utility/page\";\nimport { RockDateTime } from \"@Obsidian/Utility/rockDateTime\";\n\n// This needs to move elsewhere probably.\nexport type PageDebugTiming = {\n title: string;\n subtitle: string;\n startTimeMs: number;\n finishTimeMs: number;\n};\n\n// This is the private state that we can modify.\nconst state: State = reactive({\n areSecondaryBlocksShown: true,\n currentPerson: null,\n isAnonymousVisitor: false,\n pageParameters: {},\n contextEntities: {},\n pageId: 0,\n pageGuid: \"\",\n interactionGuid: \"\",\n executionStartTime: RockDateTime.now().toMilliseconds(),\n debugTimings: [],\n loginUrlWithReturnUrl: \"\"\n});\n\nexport class Store {\n public state: Readonly;\n\n constructor() {\n this.state = shallowReadonly(state);\n }\n\n setAreSecondaryBlocksShown(areSecondaryBlocksShown: boolean): void {\n state.areSecondaryBlocksShown = areSecondaryBlocksShown;\n }\n\n initialize(pageConfig: PageConfig): void {\n state.currentPerson = pageConfig.currentPerson || null;\n state.isAnonymousVisitor = pageConfig.isAnonymousVisitor;\n state.pageParameters = pageConfig.pageParameters || {};\n state.pageId = pageConfig.pageId;\n state.pageGuid = pageConfig.pageGuid;\n state.interactionGuid = pageConfig.interactionGuid;\n state.executionStartTime = pageConfig.executionStartTime;\n state.loginUrlWithReturnUrl = pageConfig.loginUrlWithReturnUrl;\n }\n\n addPageDebugTiming(timing: PageDebugTiming): void {\n const pageStartTime = state.executionStartTime;\n const timestampMs = timing.startTimeMs - pageStartTime;\n const durationMs = timing.finishTimeMs - timing.startTimeMs;\n\n state.debugTimings.push({\n timestampMs: timestampMs,\n durationMs: durationMs,\n indentLevel: 1,\n isTitleBold: false,\n subTitle: timing.subtitle,\n title: timing.title\n });\n }\n\n // This should be replaced with something else, doesn't really fit as a store action.\n redirectToLogin(): void {\n if (state.loginUrlWithReturnUrl) {\n window.location.href = state.loginUrlWithReturnUrl;\n }\n }\n\n get isAuthenticated(): boolean {\n return !!state.currentPerson;\n }\n\n getPageParameter(key: string): unknown {\n return state.pageParameters[key];\n }\n}\n\nconst store = new Store();\n\nexport function useStore(): Store {\n return store;\n}\n"],"names":["state","reactive","areSecondaryBlocksShown","currentPerson","isAnonymousVisitor","pageParameters","contextEntities","pageId","pageGuid","interactionGuid","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,eAAe,EAAE,EAAE;YACnBC,EAAAA,kBAAkB,EAAEC,YAAY,CAACC,GAAG,EAAE,CAACC,cAAc,EAAE;YACvDC,EAAAA,YAAY,EAAE,EAAE;YAChBC,EAAAA,qBAAqB,EAAE,EAAA;YAC3B,CAAC,CAAC,CAAA;YAEK,MAAMC,KAAK,CA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