2020-11-04 18:09:45 +01:00
|
|
|
import { getFrontendStore } from "./store/frontend"
|
2020-12-15 17:41:55 +01:00
|
|
|
import { getAutomationStore } from "./store/automation"
|
2020-10-30 14:23:49 +01:00
|
|
|
import { getThemeStore } from "./store/theme"
|
2020-12-09 19:18:47 +01:00
|
|
|
import { derived, writable } from "svelte/store"
|
2022-04-26 14:44:21 +02:00
|
|
|
import { LAYOUT_NAMES } from "../constants"
|
2022-03-21 16:17:51 +01:00
|
|
|
import { findComponent, findComponentPath } from "./componentUtils"
|
2019-07-13 11:35:57 +02:00
|
|
|
|
2020-11-04 18:09:45 +01:00
|
|
|
export const store = getFrontendStore()
|
2020-09-21 14:49:34 +02:00
|
|
|
export const automationStore = getAutomationStore()
|
2020-10-30 14:23:49 +01:00
|
|
|
export const themeStore = getThemeStore()
|
2019-07-13 11:35:57 +02:00
|
|
|
|
2022-04-25 20:33:43 +02:00
|
|
|
export const selectedScreen = derived(store, $store => {
|
|
|
|
return $store.screens.find(screen => screen._id === $store.selectedScreenId)
|
|
|
|
})
|
|
|
|
|
2020-12-07 16:27:46 +01:00
|
|
|
export const selectedComponent = derived(
|
2022-04-26 14:44:21 +02:00
|
|
|
[store, selectedScreen],
|
|
|
|
([$store, $selectedScreen]) => {
|
|
|
|
if (!$selectedScreen || !$store.selectedComponentId) {
|
2021-01-12 21:00:35 +01:00
|
|
|
return null
|
2020-12-07 16:27:46 +01:00
|
|
|
}
|
2022-04-26 14:44:21 +02:00
|
|
|
return findComponent($selectedScreen?.props, $store.selectedComponentId)
|
2020-12-07 16:27:46 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-03-21 16:17:51 +01:00
|
|
|
export const selectedComponentPath = derived(
|
2022-04-26 14:44:21 +02:00
|
|
|
[store, selectedScreen],
|
|
|
|
([$store, $selectedScreen]) => {
|
2022-03-21 16:17:51 +01:00
|
|
|
return findComponentPath(
|
2022-04-26 14:44:21 +02:00
|
|
|
$selectedScreen?.props,
|
2022-03-21 16:17:51 +01:00
|
|
|
$store.selectedComponentId
|
|
|
|
).map(component => component._id)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
export const mainLayout = derived(store, $store => {
|
2020-12-01 17:22:06 +01:00
|
|
|
return $store.layouts?.find(
|
2021-05-04 12:32:22 +02:00
|
|
|
layout => layout._id === LAYOUT_NAMES.MASTER.PRIVATE
|
2020-12-01 17:22:06 +01:00
|
|
|
)
|
2020-11-05 18:47:27 +01:00
|
|
|
})
|
|
|
|
|
2020-12-09 19:18:47 +01:00
|
|
|
export const selectedAccessRole = writable("BASIC")
|
|
|
|
|
2022-04-26 14:44:21 +02:00
|
|
|
// For compatibility
|
|
|
|
export const currentAsset = selectedScreen
|