1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00
budibase/packages/builder/src/builderStore/index.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-11-05 06:09:45 +13:00
import { getFrontendStore } from "./store/frontend"
import { getAutomationStore } from "./store/automation"
import { getThemeStore } from "./store/theme"
import { derived, writable } from "svelte/store"
import { FrontendTypes, LAYOUT_NAMES } from "../constants"
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()
export const automationStore = getAutomationStore()
export const themeStore = getThemeStore()
2019-07-13 21:35:57 +12:00
export const selectedScreen = derived(store, $store => {
return $store.screens.find(screen => screen._id === $store.selectedScreenId)
})
2022-04-26 06:59:30 +12:00
export const currentAsset = selectedScreen
2020-11-25 07:11:34 +13:00
export const selectedComponent = derived(
[store, currentAsset],
([$store, $currentAsset]) => {
if (!$currentAsset || !$store.selectedComponentId) {
return null
}
return findComponent($currentAsset?.props, $store.selectedComponentId)
}
)
export const selectedComponentPath = derived(
[store, currentAsset],
([$store, $currentAsset]) => {
return findComponentPath(
$currentAsset?.props,
$store.selectedComponentId
).map(component => component._id)
}
)
2021-05-04 22:32:22 +12:00
export const currentAssetName = derived(currentAsset, $currentAsset => {
return $currentAsset?.name
2020-11-25 07:11:34 +13:00
})
2021-05-04 22:32:22 +12:00
export const mainLayout = derived(store, $store => {
return $store.layouts?.find(
2021-05-04 22:32:22 +12:00
layout => layout._id === LAYOUT_NAMES.MASTER.PRIVATE
)
})
export const selectedAccessRole = writable("BASIC")
export const screenSearchString = writable(null)