Basic grid conversion
This commit is contained in:
parent
c4ba33cf5b
commit
558b7c88a7
|
@ -1,4 +1,4 @@
|
||||||
import { GridSpacing, GridRowHeight } from "constants"
|
import { GridSpacing, GridRowHeight } from "@/constants"
|
||||||
import { builderStore } from "stores"
|
import { builderStore } from "stores"
|
||||||
import { buildStyleString } from "utils/styleable.js"
|
import { buildStyleString } from "utils/styleable.js"
|
||||||
|
|
||||||
|
@ -44,10 +44,11 @@ export const GridDragModes = {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builds a CSS variable name for a certain piece of grid metadata
|
// Builds a CSS variable name for a certain piece of grid metadata
|
||||||
export const getGridVar = (device, param) => `--grid-${device}-${param}`
|
export const getGridVar = (device: string, param: string) =>
|
||||||
|
`--grid-${device}-${param}`
|
||||||
|
|
||||||
// Determines whether a JS event originated from immediately within a grid
|
// Determines whether a JS event originated from immediately within a grid
|
||||||
export const isGridEvent = e => {
|
export const isGridEvent = (e: any) => {
|
||||||
return (
|
return (
|
||||||
e.target.dataset?.indicator === "true" ||
|
e.target.dataset?.indicator === "true" ||
|
||||||
e.target
|
e.target
|
||||||
|
@ -59,11 +60,11 @@ export const isGridEvent = e => {
|
||||||
|
|
||||||
// Svelte action to apply required class names and styles to our component
|
// Svelte action to apply required class names and styles to our component
|
||||||
// wrappers
|
// wrappers
|
||||||
export const gridLayout = (node, metadata) => {
|
export const gridLayout = (node: HTMLDivElement, metadata: any) => {
|
||||||
let selectComponent
|
let selectComponent: any
|
||||||
|
|
||||||
// Applies the required listeners, CSS and classes to a component DOM node
|
// Applies the required listeners, CSS and classes to a component DOM node
|
||||||
const applyMetadata = metadata => {
|
const applyMetadata = (metadata: any) => {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
styles,
|
styles,
|
||||||
|
@ -86,7 +87,7 @@ export const gridLayout = (node, metadata) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback to select the component when clicking on the wrapper
|
// Callback to select the component when clicking on the wrapper
|
||||||
selectComponent = e => {
|
selectComponent = (e: Event) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
builderStore.actions.selectComponent(id)
|
builderStore.actions.selectComponent(id)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +101,7 @@ export const gridLayout = (node, metadata) => {
|
||||||
}
|
}
|
||||||
width += 2 * GridSpacing
|
width += 2 * GridSpacing
|
||||||
height += 2 * GridSpacing
|
height += 2 * GridSpacing
|
||||||
let vars = {
|
let vars: any = {
|
||||||
"--default-width": width,
|
"--default-width": width,
|
||||||
"--default-height": height,
|
"--default-height": height,
|
||||||
}
|
}
|
||||||
|
@ -135,7 +136,7 @@ export const gridLayout = (node, metadata) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply some metadata to data attributes to speed up lookups
|
// Apply some metadata to data attributes to speed up lookups
|
||||||
const addDataTag = (tagName, device, param) => {
|
const addDataTag = (tagName: string, device: string, param: string) => {
|
||||||
const val = `${vars[getGridVar(device, param)]}`
|
const val = `${vars[getGridVar(device, param)]}`
|
||||||
if (node.dataset[tagName] !== val) {
|
if (node.dataset[tagName] !== val) {
|
||||||
node.dataset[tagName] = val
|
node.dataset[tagName] = val
|
||||||
|
@ -147,11 +148,12 @@ export const gridLayout = (node, metadata) => {
|
||||||
addDataTag("gridMobileHAlign", Devices.Mobile, GridParams.HAlign)
|
addDataTag("gridMobileHAlign", Devices.Mobile, GridParams.HAlign)
|
||||||
addDataTag("gridDesktopVAlign", Devices.Desktop, GridParams.VAlign)
|
addDataTag("gridDesktopVAlign", Devices.Desktop, GridParams.VAlign)
|
||||||
addDataTag("gridMobileVAlign", Devices.Mobile, GridParams.VAlign)
|
addDataTag("gridMobileVAlign", Devices.Mobile, GridParams.VAlign)
|
||||||
if (node.dataset.insideGrid !== true) {
|
if (node.dataset.insideGrid !== "true") {
|
||||||
node.dataset.insideGrid = true
|
node.dataset.insideGrid = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply all CSS variables to the wrapper
|
// Apply all CSS variables to the wrapper
|
||||||
|
// @ts-expect-error TODO
|
||||||
node.style = buildStyleString(vars)
|
node.style = buildStyleString(vars)
|
||||||
|
|
||||||
// Add a listener to select this node on click
|
// Add a listener to select this node on click
|
||||||
|
@ -160,7 +162,7 @@ export const gridLayout = (node, metadata) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add draggable attribute
|
// Add draggable attribute
|
||||||
node.setAttribute("draggable", !!draggable)
|
node.setAttribute("draggable", (!!draggable).toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the previously set up listeners
|
// Removes the previously set up listeners
|
||||||
|
@ -176,7 +178,7 @@ export const gridLayout = (node, metadata) => {
|
||||||
applyMetadata(metadata)
|
applyMetadata(metadata)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
update(newMetadata) {
|
update(newMetadata: any) {
|
||||||
removeListeners()
|
removeListeners()
|
||||||
applyMetadata(newMetadata)
|
applyMetadata(newMetadata)
|
||||||
},
|
},
|
|
@ -14,6 +14,7 @@
|
||||||
"../*",
|
"../*",
|
||||||
"../../node_modules/@budibase/*"
|
"../../node_modules/@budibase/*"
|
||||||
],
|
],
|
||||||
|
"@/*": ["./src/*"],
|
||||||
"*": ["./src/*"]
|
"*": ["./src/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue