diff --git a/packages/client/src/index.js b/packages/client/src/index.js index 1ce7101466..9c249dd5b3 100644 --- a/packages/client/src/index.js +++ b/packages/client/src/index.js @@ -42,6 +42,7 @@ const loadBudibase = async () => { hiddenComponentIds: window["##BUDIBASE_HIDDEN_COMPONENT_IDS##"], usedPlugins: window["##BUDIBASE_USED_PLUGINS##"], location: window["##BUDIBASE_LOCATION##"], + snippets: window["##BUDIBASE_SNIPPETS##"], }) // Set app ID - this window flag is set by both the preview and the real diff --git a/packages/client/src/stores/builder.js b/packages/client/src/stores/builder.js index 2e745885b5..5440fc3a79 100644 --- a/packages/client/src/stores/builder.js +++ b/packages/client/src/stores/builder.js @@ -18,6 +18,7 @@ const createBuilderStore = () => { usedPlugins: null, eventResolvers: {}, metadata: null, + snippets: null, // Legacy - allow the builder to specify a layout layout: null, diff --git a/packages/client/src/stores/derived/snippets.js b/packages/client/src/stores/derived/snippets.js index 3f11c040bd..806ff85c4a 100644 --- a/packages/client/src/stores/derived/snippets.js +++ b/packages/client/src/stores/derived/snippets.js @@ -1,6 +1,10 @@ import { derived } from "svelte/store" import { appStore } from "../app.js" +import { builderStore } from "../builder.js" -export const snippets = derived(appStore, $appStore => { - return $appStore?.application?.snippets || [] -}) +export const snippets = derived( + [appStore, builderStore], + ([$appStore, $builderStore]) => { + return $builderStore?.snippets || $appStore?.application?.snippets || [] + } +) diff --git a/packages/server/src/api/controllers/static/templates/preview.hbs b/packages/server/src/api/controllers/static/templates/preview.hbs index 63c61baa9f..54b5b1a4e4 100644 --- a/packages/server/src/api/controllers/static/templates/preview.hbs +++ b/packages/server/src/api/controllers/static/templates/preview.hbs @@ -72,7 +72,8 @@ navigation, hiddenComponentIds, usedPlugins, - location + location, + snippets } = parsed // Set some flags so the app knows we're in the builder @@ -89,6 +90,7 @@ window["##BUDIBASE_HIDDEN_COMPONENT_IDS##"] = hiddenComponentIds window["##BUDIBASE_USED_PLUGINS##"] = usedPlugins window["##BUDIBASE_LOCATION##"] = location + window["##BUDIBASE_SNIPPETS##"] = snippets // Initialise app try {