2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
2020-11-25 10:50:51 +01:00
|
|
|
import { writable } from "svelte/store"
|
2020-11-19 19:39:22 +01:00
|
|
|
import { setContext, onMount } from "svelte"
|
2021-09-01 12:41:48 +02:00
|
|
|
import { Layout, Heading, Body } from "@budibase/bbui"
|
2020-11-13 16:42:32 +01:00
|
|
|
import Component from "./Component.svelte"
|
2021-09-01 12:41:48 +02:00
|
|
|
import SDK from "sdk"
|
2021-02-01 19:51:22 +01:00
|
|
|
import {
|
|
|
|
createContextStore,
|
|
|
|
initialise,
|
|
|
|
screenStore,
|
|
|
|
authStore,
|
2021-05-20 15:47:17 +02:00
|
|
|
routeStore,
|
|
|
|
builderStore,
|
2021-09-02 12:38:41 +02:00
|
|
|
themeStore,
|
2021-09-01 12:41:48 +02:00
|
|
|
} from "stores"
|
|
|
|
import NotificationDisplay from "components/overlay/NotificationDisplay.svelte"
|
|
|
|
import ConfirmationDisplay from "components/overlay/ConfirmationDisplay.svelte"
|
|
|
|
import PeekScreenDisplay from "components/overlay/PeekScreenDisplay.svelte"
|
|
|
|
import UserBindingsProvider from "components/context/UserBindingsProvider.svelte"
|
|
|
|
import DeviceBindingsProvider from "components/context/DeviceBindingsProvider.svelte"
|
2021-09-01 17:10:36 +02:00
|
|
|
import StateBindingsProvider from "components/context/StateBindingsProvider.svelte"
|
2021-09-01 12:41:48 +02:00
|
|
|
import SettingsBar from "components/preview/SettingsBar.svelte"
|
|
|
|
import SelectionIndicator from "components/preview/SelectionIndicator.svelte"
|
|
|
|
import HoverIndicator from "components/preview/HoverIndicator.svelte"
|
2021-09-03 12:50:09 +02:00
|
|
|
import CustomThemeWrapper from "./CustomThemeWrapper.svelte"
|
2021-07-07 12:29:35 +02:00
|
|
|
import ErrorSVG from "../../../builder/assets/error.svg"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-20 10:50:10 +01:00
|
|
|
// Provide contexts
|
|
|
|
setContext("sdk", SDK)
|
2020-11-25 10:50:51 +01:00
|
|
|
setContext("component", writable({}))
|
2021-02-01 19:51:22 +01:00
|
|
|
setContext("context", createContextStore())
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2021-05-20 15:47:17 +02:00
|
|
|
let dataLoaded = false
|
2021-07-07 12:29:35 +02:00
|
|
|
let permissionError = false
|
2020-11-19 19:39:22 +01:00
|
|
|
|
|
|
|
// Load app config
|
|
|
|
onMount(async () => {
|
2020-12-11 15:24:19 +01:00
|
|
|
await initialise()
|
2021-01-28 15:29:35 +01:00
|
|
|
await authStore.actions.fetchUser()
|
2021-05-20 15:47:17 +02:00
|
|
|
dataLoaded = true
|
2021-06-30 20:37:03 +02:00
|
|
|
if ($builderStore.inBuilder) {
|
|
|
|
builderStore.actions.notifyLoaded()
|
|
|
|
}
|
2020-11-19 19:39:22 +01:00
|
|
|
})
|
2021-02-26 15:04:31 +01:00
|
|
|
|
2021-07-07 12:29:35 +02:00
|
|
|
// Handle no matching route - this is likely a permission error
|
2021-05-20 15:47:17 +02:00
|
|
|
$: {
|
|
|
|
if (dataLoaded && $routeStore.routerLoaded && !$routeStore.activeRoute) {
|
|
|
|
if ($authStore) {
|
2021-07-07 12:29:35 +02:00
|
|
|
// There is a logged in user, so handle them
|
|
|
|
if ($screenStore.screens.length) {
|
|
|
|
// Screens exist so navigate back to the home screen
|
|
|
|
const firstRoute = $screenStore.screens[0].routing?.route ?? "/"
|
|
|
|
routeStore.actions.navigate(firstRoute)
|
|
|
|
} else {
|
|
|
|
// No screens likely means the user has no permissions to view this app
|
|
|
|
permissionError = true
|
|
|
|
}
|
2021-05-20 15:47:17 +02:00
|
|
|
} else {
|
2021-07-07 12:29:35 +02:00
|
|
|
// The user is not logged in, redirect them to login
|
2021-05-20 15:47:17 +02:00
|
|
|
const returnUrl = `${window.location.pathname}${window.location.hash}`
|
|
|
|
const encodedUrl = encodeURIComponent(returnUrl)
|
|
|
|
window.location = `/builder/auth/login?returnUrl=${encodedUrl}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 16:42:32 +01:00
|
|
|
</script>
|
|
|
|
|
2021-07-07 12:29:35 +02:00
|
|
|
{#if dataLoaded}
|
2021-06-08 09:00:54 +02:00
|
|
|
<div
|
|
|
|
id="spectrum-root"
|
|
|
|
lang="en"
|
|
|
|
dir="ltr"
|
2021-09-02 12:38:41 +02:00
|
|
|
class="spectrum spectrum--medium {$themeStore.theme}"
|
2021-06-08 09:00:54 +02:00
|
|
|
>
|
2021-07-07 12:29:35 +02:00
|
|
|
{#if permissionError}
|
|
|
|
<div class="error">
|
|
|
|
<Layout justifyItems="center" gap="S">
|
|
|
|
{@html ErrorSVG}
|
|
|
|
<Heading size="L">You don't have permission to use this app</Heading>
|
|
|
|
<Body size="S">Ask your administrator to grant you access</Body>
|
|
|
|
</Layout>
|
2021-06-08 16:16:37 +02:00
|
|
|
</div>
|
2021-07-07 12:29:35 +02:00
|
|
|
{:else if $screenStore.activeLayout}
|
2021-08-13 12:24:47 +02:00
|
|
|
<UserBindingsProvider>
|
|
|
|
<DeviceBindingsProvider>
|
2021-08-26 12:28:44 +02:00
|
|
|
<StateBindingsProvider>
|
2021-09-08 10:40:25 +02:00
|
|
|
<!-- Settings bar can be rendered outside of device preview -->
|
2021-08-26 12:28:44 +02:00
|
|
|
<!-- Key block needs to be outside the if statement or it breaks -->
|
|
|
|
{#key $builderStore.selectedComponentId}
|
|
|
|
{#if $builderStore.inBuilder}
|
|
|
|
<SettingsBar />
|
|
|
|
{/if}
|
2021-08-13 12:24:47 +02:00
|
|
|
{/key}
|
2021-09-08 10:40:25 +02:00
|
|
|
|
2021-09-08 11:28:19 +02:00
|
|
|
<!-- Clip boundary for selection indicators -->
|
2021-09-08 10:40:25 +02:00
|
|
|
<div
|
2021-09-08 11:28:19 +02:00
|
|
|
id="clip-root"
|
2021-09-08 10:40:25 +02:00
|
|
|
class:preview={$builderStore.inBuilder}
|
|
|
|
class:tablet-preview={$builderStore.previewDevice === "tablet"}
|
|
|
|
class:mobile-preview={$builderStore.previewDevice === "mobile"}
|
|
|
|
>
|
|
|
|
<!-- Actual app -->
|
|
|
|
<div id="app-root">
|
|
|
|
<CustomThemeWrapper>
|
|
|
|
{#key $screenStore.activeLayout._id}
|
|
|
|
<Component instance={$screenStore.activeLayout.props} />
|
|
|
|
{/key}
|
|
|
|
|
|
|
|
<!-- Layers on top of app -->
|
|
|
|
<NotificationDisplay />
|
|
|
|
<ConfirmationDisplay />
|
|
|
|
<PeekScreenDisplay />
|
|
|
|
</CustomThemeWrapper>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Selection indicators should be bounded by device -->
|
|
|
|
<!--
|
2021-08-26 12:28:44 +02:00
|
|
|
We don't want to key these by componentID as they control their own
|
|
|
|
re-mounting to avoid flashes.
|
|
|
|
-->
|
2021-09-08 10:40:25 +02:00
|
|
|
{#if $builderStore.inBuilder}
|
|
|
|
<SelectionIndicator />
|
|
|
|
<HoverIndicator />
|
|
|
|
{/if}
|
|
|
|
</div>
|
2021-08-26 12:28:44 +02:00
|
|
|
</StateBindingsProvider>
|
2021-08-13 12:24:47 +02:00
|
|
|
</DeviceBindingsProvider>
|
|
|
|
</UserBindingsProvider>
|
2021-07-07 12:29:35 +02:00
|
|
|
{/if}
|
2021-05-13 17:32:52 +02:00
|
|
|
</div>
|
2021-01-22 12:31:56 +01:00
|
|
|
{/if}
|
2021-05-13 17:32:52 +02:00
|
|
|
|
|
|
|
<style>
|
2021-09-08 10:40:25 +02:00
|
|
|
#spectrum-root {
|
2021-06-24 13:14:19 +02:00
|
|
|
padding: 0;
|
|
|
|
margin: 0;
|
2021-06-08 16:16:37 +02:00
|
|
|
overflow: hidden;
|
2021-09-08 10:40:25 +02:00
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
background: transparent;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2021-06-08 16:16:37 +02:00
|
|
|
}
|
2021-09-08 11:28:19 +02:00
|
|
|
#clip-root {
|
2021-09-08 10:40:25 +02:00
|
|
|
max-width: 100%;
|
|
|
|
max-height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
2021-05-13 17:32:52 +02:00
|
|
|
position: relative;
|
2021-09-08 10:40:25 +02:00
|
|
|
overflow: hidden;
|
|
|
|
background-color: transparent;
|
2021-05-13 17:32:52 +02:00
|
|
|
}
|
2021-09-08 10:40:25 +02:00
|
|
|
#app-root {
|
|
|
|
overflow: hidden;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
2021-07-30 11:06:16 +02:00
|
|
|
}
|
2021-09-08 10:40:25 +02:00
|
|
|
|
2021-07-07 12:29:35 +02:00
|
|
|
.error {
|
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
display: grid;
|
|
|
|
place-items: center;
|
|
|
|
z-index: 1;
|
|
|
|
text-align: center;
|
|
|
|
padding: 20px;
|
|
|
|
}
|
|
|
|
.error :global(svg) {
|
|
|
|
fill: var(--spectrum-global-color-gray-500);
|
|
|
|
width: 80px;
|
|
|
|
height: 80px;
|
|
|
|
}
|
|
|
|
.error :global(h1),
|
|
|
|
.error :global(p) {
|
|
|
|
color: var(--spectrum-global-color-gray-800);
|
|
|
|
}
|
|
|
|
.error :global(p) {
|
|
|
|
font-style: italic;
|
|
|
|
margin-top: -0.5em;
|
|
|
|
}
|
|
|
|
.error :global(h1) {
|
|
|
|
font-weight: 400;
|
|
|
|
}
|
2021-09-08 10:40:25 +02:00
|
|
|
|
|
|
|
/* Preview styles */
|
2021-09-08 10:51:08 +02:00
|
|
|
/* The additional 6px of size is to account for 4px padding and 2px border */
|
2021-09-08 11:28:19 +02:00
|
|
|
#clip-root.preview {
|
2021-09-08 10:40:25 +02:00
|
|
|
padding: 2px;
|
|
|
|
}
|
2021-09-08 11:28:19 +02:00
|
|
|
#clip-root.tablet-preview {
|
2021-09-08 10:51:08 +02:00
|
|
|
width: calc(1024px + 6px);
|
|
|
|
height: calc(768px + 6px);
|
2021-09-08 10:40:25 +02:00
|
|
|
}
|
2021-09-08 11:28:19 +02:00
|
|
|
#clip-root.mobile-preview {
|
2021-09-08 10:51:08 +02:00
|
|
|
width: calc(390px + 6px);
|
|
|
|
height: calc(844px + 6px);
|
2021-09-08 10:40:25 +02:00
|
|
|
}
|
|
|
|
.preview #app-root {
|
2021-09-08 10:51:08 +02:00
|
|
|
border: 1px solid var(--spectrum-global-color-gray-300);
|
2021-09-08 10:40:25 +02:00
|
|
|
border-radius: 4px;
|
|
|
|
}
|
2021-05-13 17:32:52 +02:00
|
|
|
</style>
|