1
0
Fork 0
mirror of synced 2024-07-02 21:10:43 +12:00
budibase/packages/builder/src/builderStore/index.js

72 lines
2 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 { getHostingStore } from "./store/hosting"
import { getThemeStore } from "./store/theme"
import { derived, writable } from "svelte/store"
import analytics from "analytics"
import { FrontendTypes, LAYOUT_NAMES } from "../constants"
import { findComponent } from "./storeUtils"
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()
export const hostingStore = getHostingStore()
2019-07-13 21:35:57 +12:00
2021-05-03 19:31:09 +12:00
export const currentAsset = derived(store, ($store) => {
const type = $store.currentFrontEndType
if (type === FrontendTypes.SCREEN) {
2021-05-03 19:31:09 +12:00
return $store.screens.find(
(screen) => screen._id === $store.selectedScreenId
)
} else if (type === FrontendTypes.LAYOUT) {
2021-05-03 19:31:09 +12:00
return $store.layouts.find(
(layout) => layout._id === $store.selectedLayoutId
)
}
2020-11-25 07:11:34 +13:00
return null
})
export const selectedComponent = derived(
[store, currentAsset],
([$store, $currentAsset]) => {
if (!$currentAsset || !$store.selectedComponentId) {
return null
}
return findComponent($currentAsset.props, $store.selectedComponentId)
}
)
2021-05-03 19:31:09 +12:00
export const currentAssetId = derived(store, ($store) => {
return $store.currentFrontEndType === FrontendTypes.SCREEN
? $store.selectedScreenId
: $store.selectedLayoutId
})
2021-05-03 19:31:09 +12:00
export const currentAssetName = derived(currentAsset, ($currentAsset) => {
return $currentAsset?.name
2020-11-25 07:11:34 +13:00
})
// leave this as before for consistency
2021-05-03 19:31:09 +12:00
export const allScreens = derived(store, ($store) => {
2020-11-25 07:11:34 +13:00
return $store.screens
})
2021-05-03 19:31:09 +12:00
export const mainLayout = derived(store, ($store) => {
return $store.layouts?.find(
2021-05-03 19:31:09 +12:00
(layout) => layout._id === LAYOUT_NAMES.MASTER.PRIVATE
)
})
export const selectedAccessRole = writable("BASIC")
2019-07-13 21:35:57 +12:00
export const initialise = async () => {
try {
await analytics.activate()
analytics.captureEvent("Builder Started")
} catch (err) {
console.log(err)
}
2020-05-07 21:53:34 +12:00
}
export const screenSearchString = writable(null)