2022-04-28 18:30:48 +02:00
|
|
|
import { derived } from "svelte/store"
|
2020-11-17 13:08:24 +01:00
|
|
|
import { routeStore } from "./routes"
|
2020-11-24 10:31:54 +01:00
|
|
|
import { builderStore } from "./builder"
|
2021-06-30 21:35:02 +02:00
|
|
|
import { appStore } from "./app"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-18 20:18:18 +01:00
|
|
|
const createScreenStore = () => {
|
2020-11-24 10:31:54 +01:00
|
|
|
const store = derived(
|
2021-06-30 21:35:02 +02:00
|
|
|
[appStore, routeStore, builderStore],
|
|
|
|
([$appStore, $routeStore, $builderStore]) => {
|
2021-07-07 12:28:53 +02:00
|
|
|
let activeLayout, activeScreen
|
2022-04-27 13:30:35 +02:00
|
|
|
let screens
|
|
|
|
|
2020-11-24 10:31:54 +01:00
|
|
|
if ($builderStore.inBuilder) {
|
|
|
|
// Use builder defined definitions if inside the builder preview
|
|
|
|
activeScreen = $builderStore.screen
|
2021-07-07 12:28:53 +02:00
|
|
|
screens = [activeScreen]
|
2021-05-20 15:47:17 +02:00
|
|
|
|
2022-04-27 13:30:35 +02:00
|
|
|
// Legacy - allow the builder to specify a layout
|
|
|
|
if ($builderStore.layout) {
|
|
|
|
activeLayout = $builderStore.layout
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-20 15:47:17 +02:00
|
|
|
// Find the correct screen by matching the current route
|
2021-07-07 12:48:38 +02:00
|
|
|
screens = $appStore.screens
|
2021-05-20 15:47:17 +02:00
|
|
|
if ($routeStore.activeRoute) {
|
2020-12-04 15:04:07 +01:00
|
|
|
activeScreen = screens.find(
|
2021-05-04 12:32:22 +02:00
|
|
|
screen => screen._id === $routeStore.activeRoute.screenId
|
2020-12-04 15:04:07 +01:00
|
|
|
)
|
|
|
|
}
|
2022-04-27 13:30:35 +02:00
|
|
|
|
|
|
|
// Legacy - find the custom layout for the selected screen
|
2020-12-04 15:04:07 +01:00
|
|
|
if (activeScreen) {
|
2022-04-27 13:30:35 +02:00
|
|
|
const screenLayout = $appStore.layouts?.find(
|
2021-05-04 12:32:22 +02:00
|
|
|
layout => layout._id === activeScreen.layoutId
|
2020-12-04 15:04:07 +01:00
|
|
|
)
|
2022-04-27 13:30:35 +02:00
|
|
|
if (screenLayout) {
|
|
|
|
activeLayout = screenLayout
|
|
|
|
}
|
2020-12-04 15:04:07 +01:00
|
|
|
}
|
2020-11-24 10:31:54 +01:00
|
|
|
}
|
2022-04-27 13:30:35 +02:00
|
|
|
|
|
|
|
// If we don't have a legacy custom layout, build a layout structure
|
|
|
|
// from the screen navigation settings
|
|
|
|
if (!activeLayout) {
|
2022-04-28 18:30:48 +02:00
|
|
|
let navigationSettings = {
|
2022-04-27 13:47:54 +02:00
|
|
|
navigation: "None",
|
2022-05-10 15:54:53 +02:00
|
|
|
pageWidth: activeScreen?.width || "Large",
|
2022-04-27 13:47:54 +02:00
|
|
|
}
|
2022-04-28 13:18:08 +02:00
|
|
|
if (activeScreen?.showNavigation) {
|
2022-05-10 15:54:53 +02:00
|
|
|
navigationSettings = {
|
|
|
|
...navigationSettings,
|
|
|
|
...($builderStore.navigation || $appStore.application?.navigation),
|
|
|
|
}
|
2022-04-27 13:47:54 +02:00
|
|
|
|
2022-05-06 14:51:27 +02:00
|
|
|
// Default navigation to top
|
2022-04-28 18:30:48 +02:00
|
|
|
if (!navigationSettings.navigation) {
|
|
|
|
navigationSettings.navigation = "Top"
|
2022-04-27 14:28:17 +02:00
|
|
|
}
|
2022-05-06 14:51:27 +02:00
|
|
|
|
|
|
|
// Default title to app name
|
|
|
|
if (!navigationSettings.title && !navigationSettings.hideTitle) {
|
|
|
|
navigationSettings.title = $appStore.application?.name
|
|
|
|
}
|
2022-04-27 13:47:54 +02:00
|
|
|
}
|
2022-04-27 13:30:35 +02:00
|
|
|
activeLayout = {
|
|
|
|
_id: "layout",
|
|
|
|
props: {
|
|
|
|
_component: "@budibase/standard-components/layout",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_component: "screenslot",
|
|
|
|
_id: "screenslot",
|
|
|
|
_styles: {
|
|
|
|
normal: {
|
|
|
|
flex: "1 1 auto",
|
|
|
|
display: "flex",
|
|
|
|
"flex-direction": "column",
|
|
|
|
"justify-content": "flex-start",
|
|
|
|
"align-items": "stretch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2022-04-28 18:30:48 +02:00
|
|
|
...navigationSettings,
|
2022-04-27 13:30:35 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { screens, activeLayout, activeScreen }
|
2020-11-17 13:08:24 +01:00
|
|
|
}
|
2020-11-24 10:31:54 +01:00
|
|
|
)
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
return {
|
|
|
|
subscribe: store.subscribe,
|
2020-11-13 16:42:32 +01:00
|
|
|
}
|
2020-11-17 13:08:24 +01:00
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-18 20:18:18 +01:00
|
|
|
export const screenStore = createScreenStore()
|