budibase/packages/builder/src/builderStore/index.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-04 18:09:45 +01:00
import { getFrontendStore } from "./store/frontend"
import { getBackendUiStore } from "./store/backend"
import { getAutomationStore } from "./store/automation/"
import { getThemeStore } from "./store/theme"
import { derived } from "svelte/store"
import analytics from "analytics"
2020-12-03 18:31:38 +01:00
import { LAYOUT_NAMES } from "../constants"
2019-07-13 11:35:57 +02:00
2020-11-04 18:09:45 +01:00
export const store = getFrontendStore()
export const backendUiStore = getBackendUiStore()
export const automationStore = getAutomationStore()
export const themeStore = getThemeStore()
2019-07-13 11:35:57 +02:00
2020-11-24 19:11:34 +01:00
export const currentAsset = derived(store, $store => {
const layout = $store.layouts
? $store.layouts.find(layout => layout._id === $store.currentAssetId)
: null
2020-11-24 19:11:34 +01:00
if (layout) {
return layout
}
const screen = $store.screens
? $store.screens.find(screen => screen._id === $store.currentAssetId)
: null
2020-11-24 19:11:34 +01:00
if (screen) {
return screen
}
2020-11-24 19:11:34 +01:00
return null
})
export const currentAssetName = derived(store, () => {
return currentAsset.name
})
// leave this as before for consistency
export const allScreens = derived(store, $store => {
return $store.screens
})
export const mainLayout = derived(store, $store => {
return $store.layouts?.find(
2020-12-03 18:31:38 +01:00
layout => layout.props?._id === LAYOUT_NAMES.MASTER.PRIVATE
)
})
2019-07-13 11:35:57 +02:00
export const initialise = async () => {
try {
await analytics.activate()
analytics.captureEvent("Builder Started")
} catch (err) {
console.log(err)
}
2020-05-07 11:53:34 +02:00
}