diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index d681fda8ad..3c093dd1cf 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -165,7 +165,7 @@ Cypress.Commands.add("getComponent", componentId => { .its("body") .should("not.be.null") .then(cy.wrap) - .find(`[data-component-id=${componentId}]`) + .find(`[data-id=${componentId}]`) }) Cypress.Commands.add("navigateToFrontend", () => { diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index 9b44c138a4..4e51850fe1 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -1,4 +1,5 @@ -{#key propsHash} +{#key renderKey} {#if constructor && componentSettings && (visible || inSelectedPath)} + +
@@ -184,7 +195,7 @@ {#each children as child (child._id)} {/each} - {:else if empty} + {:else if emptyState} {/if} @@ -196,4 +207,10 @@ .component { display: contents; } + .interactive :global(*:hover) { + cursor: pointer; + } + .draggable :global(*:hover) { + cursor: grab; + } diff --git a/packages/client/src/components/Screen.svelte b/packages/client/src/components/Screen.svelte index a759119320..4878df157f 100644 --- a/packages/client/src/components/Screen.svelte +++ b/packages/client/src/components/Screen.svelte @@ -22,6 +22,6 @@ {#key screenDefinition?._id} - + {/key} diff --git a/packages/client/src/components/app/Button.svelte b/packages/client/src/components/app/Button.svelte index ed465e3e66..9900c740d2 100644 --- a/packages/client/src/components/app/Button.svelte +++ b/packages/client/src/components/app/Button.svelte @@ -31,4 +31,7 @@ .spectrum-Button--overBackground:hover { color: #555; } + .spectrum-Button::after { + display: none; + } diff --git a/packages/client/src/components/app/Container.svelte b/packages/client/src/components/app/Container.svelte index 5b2f951c8d..148179c98f 100644 --- a/packages/client/src/components/app/Container.svelte +++ b/packages/client/src/components/app/Container.svelte @@ -34,7 +34,7 @@ display: flex; max-width: 100%; } - .valid-container :global([data-type="component"] > *) { + .valid-container :global(.component > *) { max-width: 100%; } .direction-row { @@ -46,7 +46,7 @@ /* Grow containers inside a row need 0 width 0 so that they ignore content */ /* The nested selector for data-type is the wrapper around all components */ - .direction-row :global(> [data-type="component"] > .size-grow) { + .direction-row :global(> .component > .size-grow) { width: 0; } diff --git a/packages/client/src/components/preview/DNDHandler.svelte b/packages/client/src/components/preview/DNDHandler.svelte new file mode 100644 index 0000000000..8a824f6131 --- /dev/null +++ b/packages/client/src/components/preview/DNDHandler.svelte @@ -0,0 +1,240 @@ + + + + + + + diff --git a/packages/client/src/components/preview/DNDPositionIndicator.svelte b/packages/client/src/components/preview/DNDPositionIndicator.svelte new file mode 100644 index 0000000000..e849ab0313 --- /dev/null +++ b/packages/client/src/components/preview/DNDPositionIndicator.svelte @@ -0,0 +1,54 @@ + + +{#key renderKey} + {#if dimensions && dropInfo?.mode !== "inside"} + + {/if} +{/key} diff --git a/packages/client/src/components/preview/HoverIndicator.svelte b/packages/client/src/components/preview/HoverIndicator.svelte index 9518c6d101..1a9e6477ac 100644 --- a/packages/client/src/components/preview/HoverIndicator.svelte +++ b/packages/client/src/components/preview/HoverIndicator.svelte @@ -7,7 +7,7 @@ $: zIndex = componentId === $builderStore.selectedComponentId ? 900 : 920 const onMouseOver = e => { - const element = e.target.closest("[data-type='component']") + const element = e.target.closest(".interactive.component") const newId = element?.dataset?.id if (newId !== componentId) { componentId = newId @@ -30,7 +30,7 @@
{#if text} -
+
{text}
{/if} @@ -30,6 +35,7 @@ diff --git a/packages/client/src/components/preview/IndicatorSet.svelte b/packages/client/src/components/preview/IndicatorSet.svelte index 957c7d7bef..012aa7e470 100644 --- a/packages/client/src/components/preview/IndicatorSet.svelte +++ b/packages/client/src/components/preview/IndicatorSet.svelte @@ -7,6 +7,7 @@ export let color export let transition export let zIndex + export let prefix = null let indicators = [] let interval @@ -51,6 +52,9 @@ const parents = document.getElementsByClassName(componentId) if (parents.length) { text = parents[0].dataset.name + if (prefix) { + text = `${prefix} ${text}` + } } // Batch reads to minimize reflow diff --git a/packages/client/src/components/preview/SettingsBar.svelte b/packages/client/src/components/preview/SettingsBar.svelte index 3581d4f5f8..43c77ef1e6 100644 --- a/packages/client/src/components/preview/SettingsBar.svelte +++ b/packages/client/src/components/preview/SettingsBar.svelte @@ -16,7 +16,7 @@ let measured = false $: definition = $builderStore.selectedComponentDefinition - $: showBar = definition?.showSettingsBar + $: showBar = definition?.showSettingsBar && !$builderStore.isDragging $: settings = definition?.settings?.filter(setting => setting.showInBar) ?? [] const updatePosition = () => { diff --git a/packages/client/src/stores/builder.js b/packages/client/src/stores/builder.js index 3f36af1d06..0d738e4a11 100644 --- a/packages/client/src/stores/builder.js +++ b/packages/client/src/stores/builder.js @@ -23,6 +23,7 @@ const createBuilderStore = () => { theme: null, customTheme: null, previewDevice: "desktop", + isDragging: false, } const writableStore = writable(initialState) const derivedStore = derived(writableStore, $state => { @@ -64,13 +65,24 @@ const createBuilderStore = () => { dispatchEvent("preview-loaded") }, setSelectedPath: path => { - console.log("set to ") - console.log(path) writableStore.update(state => { state.selectedPath = path return state }) }, + moveComponent: (componentId, destinationComponentId, mode) => { + dispatchEvent("move-component", { + componentId, + destinationComponentId, + mode, + }) + }, + setDragging: dragging => { + writableStore.update(state => { + state.isDragging = dragging + return state + }) + }, } return { ...writableStore, diff --git a/packages/client/src/utils/styleable.js b/packages/client/src/utils/styleable.js index d9925af91a..6a2562fb48 100644 --- a/packages/client/src/utils/styleable.js +++ b/packages/client/src/utils/styleable.js @@ -23,10 +23,14 @@ export const styleable = (node, styles = {}) => { let applyHoverStyles let selectComponent + // Allow dragging if required + const parent = node.closest(".component") + if (parent && parent.classList.contains("draggable")) { + node.setAttribute("draggable", true) + } + // Creates event listeners and applies initial styles const setupStyles = (newStyles = {}) => { - // Use empty state styles as base styles if required, but let them, get - // overridden by any user specified styles let baseStyles = {} if (newStyles.empty) { baseStyles.border = "2px dashed var(--spectrum-global-color-gray-600)" @@ -45,7 +49,6 @@ export const styleable = (node, styles = {}) => { // Applies a style string to a DOM node const applyStyles = styleString => { node.style = styleString - node.dataset.componentId = componentId } // Applies the "normal" style definition