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