From 9906ea96a9f8597bf9207a929870bf0d4b5a49d7 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 1 Aug 2024 16:23:53 +0100 Subject: [PATCH] Update some component manifest styles and fix issue with default grid vars --- packages/client/manifest.json | 72 ++++++++++++++----- .../client/src/components/Component.svelte | 2 + .../app/container/GridContainer.svelte | 25 +++++-- .../components/preview/GridDNDHandler.svelte | 23 ++---- .../preview/GridStylesButton.svelte | 1 + .../src/components/preview/SettingsBar.svelte | 5 +- packages/client/src/utils/grid.js | 18 ++--- 7 files changed, 94 insertions(+), 52 deletions(-) diff --git a/packages/client/manifest.json b/packages/client/manifest.json index 39c1213510..9b3939854c 100644 --- a/packages/client/manifest.json +++ b/packages/client/manifest.json @@ -114,13 +114,12 @@ "icon": "Selection", "hasChildren": true, "size": { - "width": 400, + "width": 500, "height": 200 }, "grid": { "hAlign": "stretch", - "vAlign": "stretch", - "showControls": false + "vAlign": "stretch" }, "styles": ["padding", "size", "background", "border", "shadow"], "settings": [ @@ -363,8 +362,12 @@ "illegalChildren": ["section"], "showEmptyState": false, "size": { - "width": 400, - "height": 100 + "width": 600, + "height": 200 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" }, "settings": [ { @@ -735,8 +738,12 @@ "illegalChildren": ["section"], "hasChildren": true, "size": { - "width": 400, - "height": 100 + "width": 500, + "height": 200 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" }, "settings": [ { @@ -4963,8 +4970,12 @@ "hasChildren": true, "actions": ["RefreshDatasource"], "size": { - "width": 400, - "height": 100 + "width": 500, + "height": 200 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" }, "settings": [ { @@ -5281,6 +5292,10 @@ "width": 100, "height": 35 }, + "grid": { + "hAlign": "center", + "vAlign": "center" + }, "settings": [ { "type": "dataProvider", @@ -5327,6 +5342,14 @@ "name": "Chart Block", "icon": "GraphPie", "hasChildren": false, + "size": { + "width": 600, + "height": 400 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" + }, "settings": [ { "type": "select", @@ -6250,6 +6273,10 @@ "width": 600, "height": 400 }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" + }, "settings": [ { "type": "text", @@ -6459,8 +6486,12 @@ "illegalChildren": ["section", "rowexplorer"], "hasChildren": true, "size": { - "width": 400, - "height": 100 + "width": 500, + "height": 200 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" }, "settings": [ { @@ -6731,9 +6762,13 @@ "hasChildren": false, "ejectable": false, "size": { - "width": 400, + "width": 600, "height": 400 }, + "grid": { + "hAlign": "stretch", + "vAlign": "start" + }, "styles": ["size"], "settings": [ { @@ -6922,7 +6957,7 @@ "block": true, "info": "Form blocks are only compatible with internal or SQL tables", "size": { - "width": 400, + "width": 600, "height": 400 }, "grid": { @@ -7147,8 +7182,12 @@ "name": "Row Explorer Block", "icon": "PersonalizationField", "size": { - "width": 600, - "height": 400 + "width": 800, + "height": 426 + }, + "grid": { + "hAlign": "stretch", + "vAlign": "start" }, "settings": [ { @@ -7272,8 +7311,7 @@ }, "grid": { "hAlign": "stretch", - "vAlign": "stretch", - "showControls": false + "vAlign": "stretch" }, "settings": [ { diff --git a/packages/client/src/components/Component.svelte b/packages/client/src/components/Component.svelte index 6088fb2e9c..d45b320b35 100644 --- a/packages/client/src/components/Component.svelte +++ b/packages/client/src/components/Component.svelte @@ -634,6 +634,8 @@ // Generates any required base styles based on the component definition const getBaseStyles = definition => { return { + "--default-width": definition.size?.width || 100, + "--default-height": definition.size?.height || 100, ...getBaseGridVars(definition), } } diff --git a/packages/client/src/components/app/container/GridContainer.svelte b/packages/client/src/components/app/container/GridContainer.svelte index 3ed99c1963..0df7b46f43 100644 --- a/packages/client/src/components/app/container/GridContainer.svelte +++ b/packages/client/src/components/app/container/GridContainer.svelte @@ -41,8 +41,8 @@ ...$component.styles?.normal, "--cols": cols, "--rows": rows, - "--col-size": `${colSize}px`, - "--row-size": `${rowSize}px`, + "--col-size": colSize, + "--row-size": rowSize, }, empty: false, }} @@ -70,14 +70,14 @@ gap: 0; /* Prevent cross-grid variable inheritance */ - --grid-desktop-col-start: initial; + /* --grid-desktop-col-start: initial; --grid-desktop-col-end: initial; --grid-desktop-row-start: initial; --grid-desktop-row-end: initial; --grid-mobile-col-start: initial; --grid-mobile-col-end: initial; --grid-mobile-row-start: initial; - --grid-mobile-row-end: initial; + --grid-mobile-row-end: initial;*/ } .grid, .underlay { @@ -111,9 +111,22 @@ /* On desktop, use desktop metadata and fall back to mobile */ /* Position vars */ --col-start: var(--grid-desktop-col-start, var(--grid-mobile-col-start, 1)); - --col-end: var(--grid-desktop-col-end, var(--grid-mobile-col-end, 2)); + --col-end: var( + --grid-desktop-col-end, + var( + --grid-mobile-col-end, + /* Our final*/ + round(up, calc(var(--default-width) / var(--col-size) + 1)) + ) + ); --row-start: var(--grid-desktop-row-start, var(--grid-mobile-row-start, 1)); - --row-end: var(--grid-desktop-row-end, var(--grid-mobile-row-end, 2)); + --row-end: var( + --grid-desktop-row-end, + var( + --grid-mobile-row-end, + round(up, calc(var(--default-height) / var(--row-size) + 1)) + ) + ); /* Flex vars */ --h-align: var(--grid-desktop-h-align, var(--grid-mobile-h-align, stretch)); diff --git a/packages/client/src/components/preview/GridDNDHandler.svelte b/packages/client/src/components/preview/GridDNDHandler.svelte index 374defe138..7e2cbd50c8 100644 --- a/packages/client/src/components/preview/GridDNDHandler.svelte +++ b/packages/client/src/components/preview/GridDNDHandler.svelte @@ -1,14 +1,8 @@ diff --git a/packages/client/src/components/preview/SettingsBar.svelte b/packages/client/src/components/preview/SettingsBar.svelte index c8535899af..6b00221f9e 100644 --- a/packages/client/src/components/preview/SettingsBar.svelte +++ b/packages/client/src/components/preview/SettingsBar.svelte @@ -40,7 +40,10 @@ $: isRoot = componentId === $builderStore.screen?.props?._id $: insideGrid = parent?._component.endsWith("/container") && parent.layout === "grid" - $: showGridStyles = insideGrid && definition?.grid?.showControls !== false + $: showGridStyles = + insideGrid && + (definition?.grid?.hAlign !== "stretch" || + definition?.grid?.vAlign !== "stretch") $: gridHAlignVar = $getGridVar("h-align") $: gridVAlignVar = $getGridVar("v-align") $: gridStyles = $state?.styles diff --git a/packages/client/src/utils/grid.js b/packages/client/src/utils/grid.js index d5be908edb..4fa8a3e49b 100644 --- a/packages/client/src/utils/grid.js +++ b/packages/client/src/utils/grid.js @@ -70,23 +70,17 @@ export const getGridParentID = node => { } // Generates the base set of grid CSS vars from a component definition -const alignmentToStyleMap = { - start: "flex-start", - center: "center", - end: "flex-end", - stretch: "stretch", -} export const getBaseGridVars = definition => { const gridHAlign = definition?.grid?.hAlign || "stretch" const gridVAlign = definition?.grid?.vAlign || "center" const flexStyles = gridVAlign === "stretch" ? "1 1 0" : "0 0 auto" return { - ["--grid-desktop-h-align"]: alignmentToStyleMap[gridHAlign], - ["--grid-mobile-h-align"]: alignmentToStyleMap[gridHAlign], - ["--grid-desktop-v-align"]: alignmentToStyleMap[gridVAlign], - ["--grid-mobile-v-align"]: alignmentToStyleMap[gridVAlign], - ["--grid-desktop-child-flex"]: flexStyles, - ["--grid-mobile-child-flex"]: flexStyles, + "--grid-desktop-h-align": gridHAlign, + "--grid-mobile-h-align": gridHAlign, + "--grid-desktop-v-align": gridVAlign, + "--grid-mobile-v-align": gridVAlign, + "--grid-desktop-child-flex": flexStyles, + "--grid-mobile-child-flex": flexStyles, } }