More conversions

This commit is contained in:
Adria Navarro 2025-02-13 11:24:41 +01:00
parent 0d096132b8
commit a3d6048336
1 changed files with 15 additions and 10 deletions

View File

@ -2,7 +2,12 @@ import { writable, get } from "svelte/store"
import { API } from "api" import { API } from "api"
import { devToolsStore } from "./devTools.js" import { devToolsStore } from "./devTools.js"
import { eventStore } from "./events.js" import { eventStore } from "./events.js"
import { DropPosition, PingSource, PreviewDevice } from "@budibase/types" import {
ComponentDefinition,
DropPosition,
PingSource,
PreviewDevice,
} from "@budibase/types"
interface BuilderStore { interface BuilderStore {
inBuilder: boolean inBuilder: boolean
@ -15,9 +20,9 @@ interface BuilderStore {
previewDevice: PreviewDevice previewDevice: PreviewDevice
navigation: string | null navigation: string | null
hiddenComponentIds: [] hiddenComponentIds: []
usedPlugins: string | null usedPlugins: { name: string; hash: string }[] | null
eventResolvers: {} eventResolvers: {}
metadata: string | null metadata: { componentId: string; step: number } | null
snippets: string | null snippets: string | null
componentErrors: {} componentErrors: {}
layout: null layout: null
@ -121,18 +126,18 @@ const createBuilderStore = () => {
requestAddComponent: () => { requestAddComponent: () => {
eventStore.actions.dispatchEvent("request-add-component") eventStore.actions.dispatchEvent("request-add-component")
}, },
highlightSetting: setting => { highlightSetting: (setting: string) => {
eventStore.actions.dispatchEvent("highlight-setting", { setting }) eventStore.actions.dispatchEvent("highlight-setting", { setting })
}, },
ejectBlock: (id, definition) => { ejectBlock: (id: string, definition: ComponentDefinition) => {
eventStore.actions.dispatchEvent("eject-block", { id, definition }) eventStore.actions.dispatchEvent("eject-block", { id, definition })
}, },
updateUsedPlugin: (name, hash) => { updateUsedPlugin: (name: string, hash: string) => {
// Check if we used this plugin // Check if we used this plugin
const used = get(store)?.usedPlugins?.find(x => x.name === name) const used = get(store)?.usedPlugins?.find(x => x.name === name)
if (used) { if (used) {
store.update(state => { store.update(state => {
state.usedPlugins = state.usedPlugins.filter(x => x.name !== name) state.usedPlugins = state.usedPlugins!.filter(x => x.name !== name)
state.usedPlugins.push({ state.usedPlugins.push({
...used, ...used,
hash, hash,
@ -144,13 +149,13 @@ const createBuilderStore = () => {
// Notify the builder so we can reload component definitions // Notify the builder so we can reload component definitions
eventStore.actions.dispatchEvent("reload-plugin") eventStore.actions.dispatchEvent("reload-plugin")
}, },
addParentComponent: (componentId: any, parentType: any) => { addParentComponent: (componentId: string, parentType: string) => {
eventStore.actions.dispatchEvent("add-parent-component", { eventStore.actions.dispatchEvent("add-parent-component", {
componentId, componentId,
parentType, parentType,
}) })
}, },
setMetadata: metadata => { setMetadata: (metadata: { componentId: string; step: number }) => {
store.update(state => ({ store.update(state => ({
...state, ...state,
metadata, metadata,
@ -159,7 +164,7 @@ const createBuilderStore = () => {
} }
return { return {
...store, ...store,
set: state => store.set({ ...initialState, ...state }), set: (state: BuilderStore) => store.set({ ...initialState, ...state }),
actions, actions,
} }
} }