Allow moving grid components using the label
This commit is contained in:
parent
f99ae6b96e
commit
b62371d1be
|
@ -3040,7 +3040,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 32
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3071,7 +3071,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 32
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3207,7 +3207,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3309,7 +3309,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3395,7 +3395,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3481,7 +3481,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3695,7 +3695,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -3901,8 +3901,8 @@
|
|||
"editable": true,
|
||||
"requiredAncestors": ["form"],
|
||||
"size": {
|
||||
"width": 20,
|
||||
"height": 20
|
||||
"width": 400,
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -4028,7 +4028,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 150
|
||||
"height": 100
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -4152,7 +4152,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -4270,7 +4270,7 @@
|
|||
"styles": ["size"],
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -4430,7 +4430,7 @@
|
|||
"styles": ["size"],
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
@ -4785,7 +4785,7 @@
|
|||
"editable": true,
|
||||
"size": {
|
||||
"width": 400,
|
||||
"height": 50
|
||||
"height": 60
|
||||
},
|
||||
"settings": [
|
||||
{
|
||||
|
|
|
@ -3,7 +3,13 @@
|
|||
import { builderStore, componentStore } from "stores"
|
||||
import { Utils, memo } from "@budibase/frontend-core"
|
||||
import { GridRowHeight } from "constants"
|
||||
import { isGridEvent, GridParams, getGridVar, Devices } from "utils/grid"
|
||||
import {
|
||||
isGridEvent,
|
||||
GridParams,
|
||||
getGridVar,
|
||||
Devices,
|
||||
GridDragModes,
|
||||
} from "utils/grid"
|
||||
|
||||
const context = getContext("context")
|
||||
|
||||
|
@ -49,7 +55,7 @@
|
|||
let deltaX = Math.round(diffX / colSize)
|
||||
const diffY = mouseY - startY
|
||||
let deltaY = Math.round(diffY / GridRowHeight)
|
||||
if (mode === "move") {
|
||||
if (mode === GridDragModes.Move) {
|
||||
deltaX = minMax(deltaX, 1 - colStart, cols + 1 - colEnd)
|
||||
deltaY = Math.max(deltaY, 1 - rowStart)
|
||||
const newStyles = {
|
||||
|
@ -59,7 +65,7 @@
|
|||
[vars.rowEnd]: rowEnd + deltaY,
|
||||
}
|
||||
styles.set(newStyles)
|
||||
} else if (mode === "resize") {
|
||||
} else if (mode === GridDragModes.Resize) {
|
||||
let newStyles = {}
|
||||
if (side === "right") {
|
||||
newStyles[vars.colEnd] = Math.max(colEnd + deltaX, colStart + 1)
|
||||
|
@ -103,14 +109,13 @@
|
|||
|
||||
// Extract state
|
||||
let mode, id, side
|
||||
if (e.target.classList.contains("anchor")) {
|
||||
// Handle resize
|
||||
mode = "resize"
|
||||
if (e.target.dataset.indicator === "true") {
|
||||
mode = e.target.dataset.dragMode
|
||||
id = e.target.dataset.id
|
||||
side = e.target.dataset.side
|
||||
} else {
|
||||
// Handle move
|
||||
mode = "move"
|
||||
mode = GridDragModes.Move
|
||||
const component = e.target.closest(".component")
|
||||
id = component.dataset.id
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<script>
|
||||
import { Icon } from "@budibase/bbui"
|
||||
import { GridDragModes } from "utils/grid"
|
||||
|
||||
export let top
|
||||
export let left
|
||||
|
@ -38,7 +39,16 @@
|
|||
class:hCompact={width < 40}
|
||||
>
|
||||
{#if text || icon}
|
||||
<div class="label" class:flipped class:line class:right={alignRight}>
|
||||
<div
|
||||
class="label"
|
||||
class:flipped
|
||||
class:line
|
||||
class:right={alignRight}
|
||||
draggable="true"
|
||||
data-indicator="true"
|
||||
data-drag-mode={GridDragModes.Move}
|
||||
data-id={componentId}
|
||||
>
|
||||
{#if icon}
|
||||
<Icon name={icon} size="S" color="white" />
|
||||
{/if}
|
||||
|
@ -52,8 +62,10 @@
|
|||
{#if showResizeAnchors}
|
||||
{#each AnchorSides as side}
|
||||
<div
|
||||
draggable="true"
|
||||
class="anchor {side}"
|
||||
draggable="true"
|
||||
data-indicator="true"
|
||||
data-drag-mode={GridDragModes.Resize}
|
||||
data-side={side}
|
||||
data-id={componentId}
|
||||
>
|
||||
|
@ -101,6 +113,7 @@
|
|||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
pointer-events: all;
|
||||
}
|
||||
.label.line {
|
||||
transform: translateY(-50%);
|
||||
|
|
|
@ -38,17 +38,22 @@ export const Devices = {
|
|||
Mobile: "mobile",
|
||||
}
|
||||
|
||||
export const GridDragModes = {
|
||||
Resize: "resize",
|
||||
Move: "move",
|
||||
}
|
||||
|
||||
// Builds a CSS variable name for a certain piece of grid metadata
|
||||
export const getGridVar = (device, param) => `--grid-${device}-${param}`
|
||||
|
||||
// Determines whether a JS event originated from immediately within a grid
|
||||
export const isGridEvent = e => {
|
||||
return (
|
||||
e.target.dataset.indicator === "true" ||
|
||||
e.target
|
||||
.closest?.(".component")
|
||||
?.parentNode.closest(".component")
|
||||
?.childNodes[0]?.classList?.contains("grid") ||
|
||||
e.target.classList.contains("anchor")
|
||||
?.childNodes[0]?.classList?.contains("grid")
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue