diff --git a/package.json b/package.json index 148924b6d3..69f7b0f21d 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,5 @@ "format": "prettier --write \"{,!(node_modules)/**/}*.{js,jsx,svelte}\"", "test:e2e": "lerna run cy:test", "test:e2e:ci": "lerna run cy:ci" - }, - "dependencies": { - "@material/icon-button": "4.0.0", - "date-fns": "^2.10.0" } } diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 40ffb0f489..da85abddb3 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -131,9 +131,9 @@ Cypress.Commands.add("navigateToFrontend", () => { Cypress.Commands.add("createScreen", (screenName, route) => { cy.get(".newscreen").click() - cy.get(".uk-input:first").type(screenName) + cy.get("[data-cy=new-screen-dialog] input:first").type(screenName) if (route) { - cy.get(".uk-input:last").type(route) + cy.get("[data-cy=new-screen-dialog] input:last").type(route) } cy.get(".uk-modal-footer").within(() => { cy.contains("Create Screen").click() diff --git a/packages/builder/package.json b/packages/builder/package.json index c9e8cca9be..e223397508 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -60,24 +60,18 @@ "@budibase/bbui": "^1.24.1", "@budibase/client": "^0.1.17", "@budibase/colorpicker": "^1.0.1", - "@nx-js/compiler-util": "^2.0.0", "@sentry/browser": "5.19.1", "@svelteschool/svelte-forms": "^0.7.0", "britecharts": "^2.16.0", - "codemirror": "^5.51.0", "d3-selection": "^1.4.1", - "date-fns": "^1.29.0", "deepmerge": "^4.2.2", "fast-sort": "^2.2.0", "feather-icons": "^4.21.0", "flatpickr": "^4.5.7", "lodash": "^4.17.13", - "lunr": "^2.3.5", "mustache": "^4.0.1", "posthog-js": "1.3.1", - "safe-buffer": "^5.1.2", "shortid": "^2.2.15", - "string_decoder": "^1.2.0", "svelte-portal": "^0.1.0", "svelte-simple-modal": "^0.4.2", "uikit": "^3.1.7", @@ -94,19 +88,15 @@ "@testing-library/jest-dom": "^5.11.0", "@testing-library/svelte": "^3.0.0", "babel-jest": "^24.8.0", - "browser-sync": "^2.26.7", "cypress": "^4.8.0", "cypress-terminal-report": "^1.4.1", "eslint-plugin-cypress": "^2.11.1", - "http-proxy-middleware": "^0.19.1", "identity-obj-proxy": "^3.0.0", "jest": "^24.8.0", "ncp": "^2.0.0", - "npm-run-all": "^4.1.5", "rimraf": "^3.0.2", "rollup": "^1.12.0", "rollup-plugin-alias": "^1.5.2", - "rollup-plugin-browsersync": "^1.0.0", "rollup-plugin-commonjs": "^10.0.0", "rollup-plugin-copy": "^3.0.0", "rollup-plugin-livereload": "^1.0.0", diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index 5b78ea0979..f5849c480a 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -1,4 +1,4 @@ -import { values } from "lodash/fp" +import { values, cloneDeep } from "lodash/fp" import { get_capitalised_name } from "../../helpers" import { backendUiStore } from "builderStore" import * as backendStoreActions from "./backend" @@ -24,8 +24,8 @@ import { saveCurrentPreviewItem as _saveCurrentPreviewItem, saveScreenApi as _saveScreenApi, regenerateCssForCurrentScreen, + generateNewIdsForComponent, } from "../storeUtils" - export const getStore = () => { const initial = { apps: [], @@ -70,6 +70,8 @@ export const getStore = () => { store.addTemplatedComponent = addTemplatedComponent(store) store.setMetadataProp = setMetadataProp(store) store.editPageOrScreen = editPageOrScreen(store) + store.pasteComponent = pasteComponent(store) + store.storeComponentForCopy = storeComponentForCopy(store) return store } @@ -291,9 +293,14 @@ const addChildComponent = store => (componentToAdd, presetProps = {}) => { state ) - state.currentComponentInfo._children = state.currentComponentInfo._children.concat( - newComponent.props - ) + const currentComponent = + state.components[state.currentComponentInfo._component] + + const targetParent = currentComponent.children + ? state.currentComponentInfo + : getParent(state.currentPreviewItem.props, state.currentComponentInfo) + + targetParent._children = targetParent._children.concat(newComponent.props) state.currentFrontEndType === "page" ? _savePage(state) @@ -454,3 +461,50 @@ const setMetadataProp = store => (name, prop) => { return s }) } + +const storeComponentForCopy = store => (component, cut = false) => { + store.update(s => { + const copiedComponent = cloneDeep(component) + s.componentToPaste = copiedComponent + s.componentToPaste.isCut = cut + if (cut) { + const parent = getParent(s.currentPreviewItem.props, component._id) + parent._children = parent._children.filter(c => c._id !== component._id) + selectComponent(s, parent) + } + + return s + }) +} + +const pasteComponent = store => (targetComponent, mode) => { + store.update(s => { + if (!s.componentToPaste) return s + + const componentToPaste = cloneDeep(s.componentToPaste) + // retain the same ids as things may be referencing this component + if (componentToPaste.isCut) { + // in case we paste a second time + s.componentToPaste.isCut = false + } else { + generateNewIdsForComponent(componentToPaste) + } + delete componentToPaste.isCut + + if (mode === "inside") { + targetComponent._children.push(componentToPaste) + return s + } + + const parent = getParent(s.currentPreviewItem.props, targetComponent) + + const targetIndex = parent._children.indexOf(targetComponent) + const index = mode === "above" ? targetIndex : targetIndex + 1 + parent._children.splice(index, 0, cloneDeep(componentToPaste)) + regenerateCssForCurrentScreen(s) + _saveCurrentPreviewItem(s) + selectComponent(s, componentToPaste) + + return s + }) +} diff --git a/packages/builder/src/builderStore/storeUtils.js b/packages/builder/src/builderStore/storeUtils.js index 63fd7ecd00..1630d118e0 100644 --- a/packages/builder/src/builderStore/storeUtils.js +++ b/packages/builder/src/builderStore/storeUtils.js @@ -1,6 +1,7 @@ import { makePropsSafe } from "components/userInterface/pagesParsing/createProps" import api from "./api" import { generate_screen_css } from "./generate_css" +import { uuid } from "./uuid" export const selectComponent = (state, component) => { const componentDef = component._component.startsWith("##") @@ -79,3 +80,8 @@ export const regenerateCssForCurrentScreen = state => { ]) return state } + +export const generateNewIdsForComponent = c => + walkProps(c, p => { + p._id = uuid() + }) diff --git a/packages/builder/src/components/common/Block.svelte b/packages/builder/src/components/common/Block.svelte deleted file mode 100644 index eccf798742..0000000000 --- a/packages/builder/src/components/common/Block.svelte +++ /dev/null @@ -1,59 +0,0 @@ - - -
- - {title} -
- - diff --git a/packages/builder/src/components/common/CodeArea.svelte b/packages/builder/src/components/common/CodeArea.svelte deleted file mode 100644 index afa12dfcca..0000000000 --- a/packages/builder/src/components/common/CodeArea.svelte +++ /dev/null @@ -1,20 +0,0 @@ - - -