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"
|
|
|
|
import { getHostingStore } from "./store/hosting"
|
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"
|
2020-09-29 16:26:56 +02:00
|
|
|
import analytics from "analytics"
|
2020-12-14 12:14:16 +01:00
|
|
|
import { FrontendTypes, LAYOUT_NAMES } from "../constants"
|
2021-01-12 21:00:35 +01:00
|
|
|
import { findComponent } from "./storeUtils"
|
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()
|
2020-12-15 17:41:55 +01:00
|
|
|
export const hostingStore = getHostingStore()
|
2019-07-13 11:35:57 +02:00
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
export const currentAsset = derived(store, ($store) => {
|
2020-12-14 12:14:16 +01:00
|
|
|
const type = $store.currentFrontEndType
|
|
|
|
if (type === FrontendTypes.SCREEN) {
|
2021-05-03 09:31:09 +02:00
|
|
|
return $store.screens.find(
|
|
|
|
(screen) => screen._id === $store.selectedScreenId
|
|
|
|
)
|
2020-12-14 12:14:16 +01:00
|
|
|
} else if (type === FrontendTypes.LAYOUT) {
|
2021-05-03 09:31:09 +02:00
|
|
|
return $store.layouts.find(
|
|
|
|
(layout) => layout._id === $store.selectedLayoutId
|
|
|
|
)
|
2020-12-14 12:14:16 +01:00
|
|
|
}
|
2020-11-24 19:11:34 +01:00
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
2020-12-07 16:27:46 +01:00
|
|
|
export const selectedComponent = derived(
|
|
|
|
[store, currentAsset],
|
|
|
|
([$store, $currentAsset]) => {
|
2021-01-12 21:00:35 +01:00
|
|
|
if (!$currentAsset || !$store.selectedComponentId) {
|
|
|
|
return null
|
2020-12-07 16:27:46 +01:00
|
|
|
}
|
2021-01-12 21:00:35 +01:00
|
|
|
return findComponent($currentAsset.props, $store.selectedComponentId)
|
2020-12-07 16:27:46 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
export const currentAssetId = derived(store, ($store) => {
|
2020-12-14 12:14:16 +01:00
|
|
|
return $store.currentFrontEndType === FrontendTypes.SCREEN
|
|
|
|
? $store.selectedScreenId
|
|
|
|
: $store.selectedLayoutId
|
|
|
|
})
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
export const currentAssetName = derived(currentAsset, ($currentAsset) => {
|
2020-12-14 12:14:16 +01:00
|
|
|
return $currentAsset?.name
|
2020-11-24 19:11:34 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// leave this as before for consistency
|
2021-05-03 09:31:09 +02:00
|
|
|
export const allScreens = derived(store, ($store) => {
|
2020-11-24 19:11:34 +01:00
|
|
|
return $store.screens
|
2020-11-05 18:47:27 +01:00
|
|
|
})
|
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
export const mainLayout = derived(store, ($store) => {
|
2020-12-01 17:22:06 +01:00
|
|
|
return $store.layouts?.find(
|
2021-05-03 09:31:09 +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")
|
|
|
|
|
2019-07-13 11:35:57 +02:00
|
|
|
export const initialise = async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
try {
|
2020-10-12 22:35:10 +02:00
|
|
|
await analytics.activate()
|
2020-09-29 16:26:56 +02:00
|
|
|
analytics.captureEvent("Builder Started")
|
2020-02-03 10:24:25 +01:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
2020-05-07 11:53:34 +02:00
|
|
|
}
|
2021-03-09 20:06:25 +01:00
|
|
|
|
|
|
|
export const screenSearchString = writable(null)
|