diff --git a/packages/builder/src/builderStore/store.js b/packages/builder/src/builderStore/store.js index 9245e2c9b5..3cb400c4de 100644 --- a/packages/builder/src/builderStore/store.js +++ b/packages/builder/src/builderStore/store.js @@ -111,6 +111,7 @@ export const getStore = () => { store.moveUpComponent = moveUpComponent(store) store.moveDownComponent = moveDownComponent(store) store.copyComponent = copyComponent(store) + store.addTemplatedComponent = addTemplatedComponent(store) return store } @@ -161,6 +162,7 @@ const initialise = (store, initial) => async () => { initial.components = values(pkg.components.components).map( expandComponentDefinition ) + initial.templates = pkg.components.templates initial.builtins = [getBuiltin("##builtin/screenslot")] initial.actions = values(pkg.appDefinition.actions) initial.triggers = pkg.appDefinition.triggers @@ -735,6 +737,24 @@ const addChildComponent = store => (componentToAdd, presetName) => { }) } +/** + * @param {string} props - props to add, as child of current component + */ +const addTemplatedComponent = store => props => { + store.update(state => { + walkProps(props, p => { + p._id = uuid() + }) + state.currentComponentInfo._children = state.currentComponentInfo._children.concat( + props + ) + + _savePage(state) + + return state + }) +} + const selectComponent = store => component => { store.update(s => { const componentDef = component._component.startsWith("##") diff --git a/packages/builder/src/common/ConfirmDialog.svelte b/packages/builder/src/common/ConfirmDialog.svelte index 592b73a395..b54f971d7c 100644 --- a/packages/builder/src/common/ConfirmDialog.svelte +++ b/packages/builder/src/common/ConfirmDialog.svelte @@ -39,7 +39,9 @@ const ok = () => {