Simplify some utils
This commit is contained in:
parent
d423d530e4
commit
25ff092da2
|
@ -40,12 +40,6 @@
|
||||||
// Sugar for a combination of both min and max
|
// Sugar for a combination of both min and max
|
||||||
const minMax = (value, min, max) => Math.min(max, Math.max(min, value))
|
const minMax = (value, min, max) => Math.min(max, Math.max(min, value))
|
||||||
|
|
||||||
// Util to get the inner DOM node by a component ID
|
|
||||||
const getDOMNode = id => {
|
|
||||||
const component = document.getElementsByClassName(id)[0]
|
|
||||||
return Array.from(component?.children || [])[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
const enrichComponentStyles = styles => {
|
const enrichComponentStyles = styles => {
|
||||||
let clone = { ...styles }
|
let clone = { ...styles }
|
||||||
if (styles) {
|
if (styles) {
|
||||||
|
@ -137,16 +131,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find grid parent and read from DOM
|
// Find grid parent and read from DOM
|
||||||
const domComponent = getDOMNode(id)
|
const domComponent = document.getElementsByClassName(id)[0]
|
||||||
const domGrid = getGridParent(domComponent)
|
const domGrid = domComponent?.closest(".grid")
|
||||||
if (!domGrid) {
|
if (!domGrid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const styles = getComputedStyle(domComponent.parentNode)
|
const styles = getComputedStyle(domComponent)
|
||||||
|
|
||||||
// Show as active
|
// Show as active
|
||||||
builderStore.actions.selectComponent(id)
|
builderStore.actions.selectComponent(id)
|
||||||
domComponent.parentNode.classList.add("dragging")
|
domComponent.classList.add("dragging")
|
||||||
domGrid.classList.add("highlight")
|
domGrid.classList.add("highlight")
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
|
@ -187,7 +181,7 @@
|
||||||
const { id, domTarget, domGrid, domComponent } = dragInfo
|
const { id, domTarget, domGrid, domComponent } = dragInfo
|
||||||
|
|
||||||
// Reset DOM
|
// Reset DOM
|
||||||
domComponent.parentNode.classList.remove("dragging")
|
domComponent.classList.remove("dragging")
|
||||||
domGrid.classList.remove("highlight")
|
domGrid.classList.remove("highlight")
|
||||||
domTarget.removeEventListener("dragend", stopDragging)
|
domTarget.removeEventListener("dragend", stopDragging)
|
||||||
|
|
||||||
|
|
|
@ -70,10 +70,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkInsideGrid = id => {
|
|
||||||
return isGridChild(document.getElementsByClassName(id)[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
const createIntersectionCallback = idx => entries => {
|
const createIntersectionCallback = idx => entries => {
|
||||||
if (callbackCount >= observers.length) {
|
if (callbackCount >= observers.length) {
|
||||||
return
|
return
|
||||||
|
@ -117,7 +113,7 @@
|
||||||
|
|
||||||
// Check if we're inside a grid
|
// Check if we're inside a grid
|
||||||
if (allowResizeAnchors) {
|
if (allowResizeAnchors) {
|
||||||
nextState.insideGrid = checkInsideGrid(componentId)
|
nextState.insideGrid = parents[0]?.dataset.insideGrid === "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get text to display
|
// Get text to display
|
||||||
|
|
|
@ -52,16 +52,6 @@ export const isGridEvent = e => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determines whether a DOM element is an immediate child of a grid
|
|
||||||
export const isGridChild = node => {
|
|
||||||
return node?.parentNode.classList.contains("grid")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the component ID of the closest parent grid
|
|
||||||
export const getGridParent = node => {
|
|
||||||
return node?.parentNode?.closest(".grid")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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, metadata) => {
|
||||||
|
|
Loading…
Reference in New Issue