diff --git a/src/ui/src/components/core/root/CoreRoot.vue b/src/ui/src/components/core/root/CoreRoot.vue index 8e3573694..d6c2b762a 100644 --- a/src/ui/src/components/core/root/CoreRoot.vue +++ b/src/ui/src/components/core/root/CoreRoot.vue @@ -17,15 +17,14 @@ import { useEvaluator } from "@/renderer/useEvaluator"; const ssHashChangeStub = ` def handle_hashchange(state, payload): # The payload is a dictionary with the page key and all the route variables in the URL hash. - # For example, if the current URL is - # http://localhost:3000/#main/animal=duck&colour=yellow + # For example, if the current URL is http://localhost:3000/#main/animal=duck&colour=yellow # you will get the following dictionary # { - # "page_key": "main", - # "route_vars": { - # "animal": "duck", - # "colour": "yellow" - # } + # "page_key": "main", + # "route_vars": { + # "animal": "duck", + # "colour": "yellow" + # } # } page_key = payload.get("page_key") @@ -39,6 +38,23 @@ def handle_hashchange(state, payload): else: state["message"] = "You're not in the Duck zone.`.trim(); +const wfAppOpenStub = ` +def handle_app_open(state): + # The payload is a dictionary with the page key and all the route variables in the URL hash. + # For example, if the current URL is http://localhost:3000/#/animal=duck&colour=yellow + # you will get the following dictionary + # { + # "page_key": "main", + # "route_vars": { + # "animal": "duck", + # "colour": "yellow" + # } + # } + + page_key = payload.get("page_key") + route_vars = payload.get("route_vars") +`.trim(); + const description = "The root component of the application, which serves as the starting point of the component hierarchy."; @@ -57,6 +73,10 @@ export default { ...sharedStyleFields, }, events: { + "wf-app-open": { + desc: "Captures the first application load, including page key and route vars.", + stub: wfAppOpenStub, + }, "wf-hashchange": { desc: "Capture changes to the URL hash, including page key and route vars.", stub: ssHashChangeStub, @@ -74,6 +94,7 @@ import { watch, nextTick, onBeforeMount, + onMounted, } from "vue"; import injectionKeys from "@/injectionKeys"; import { changePageInHash, getParsedHash } from "@/core/navigation"; @@ -126,12 +147,26 @@ watch(displayedPageId, (newPageId) => { changePageInHash(pageKey); }); +function handleAppOpenChange() { + const parsedHash = getParsedHash(); + const event = new CustomEvent("wf-app-open", { + detail: { + payload: parsedHash, + }, + }); + rootEl.value?.dispatchEvent(event); +} + onBeforeMount(() => { window.addEventListener("hashchange", () => { handleHashChange(); }); handleHashChange(); }); + +onMounted(() => { + handleAppOpenChange(); +});