From 2aae2bab3128306591bab8191163050f7ca24ab2 Mon Sep 17 00:00:00 2001 From: poirazis Date: Sun, 30 Jun 2024 17:43:47 +0300 Subject: [PATCH 1/2] wip --- package.json | 10 +- schema.json | 25 +++- src/Component.svelte | 248 ++++++++++++++++++++----------------- src/RepeaterPreview.svelte | 8 +- src/TabControl.svelte | 22 ++-- 5 files changed, 175 insertions(+), 138 deletions(-) diff --git a/package.json b/package.json index 831678d..768566a 100644 --- a/package.json +++ b/package.json @@ -14,23 +14,23 @@ "@crownframework/svelte-error-boundary": "^1.0.3", "@spectrum-css/opacitycheckerboard": "^1.1.5", "@spectrum-css/splitview": "4.0.3", - "svelte": "^4.2.17", + "svelte": "^4.2.18", "svelte-fsm": "^1.2.0" }, "devDependencies": { - "@budibase/backend-core": "^2.28.1", - "@budibase/shared-core": "^2.28.1", + "@budibase/backend-core": "^2.29.4", + "@budibase/shared-core": "^2.29.4", "@rollup/plugin-commonjs": "^25.0.8", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-terser": "^0.4.4", "npm-run-all": "^4.1.5", - "postcss": "^8.4.38", + "postcss": "^8.4.39", "rollup": "^2.79.1", "rollup-plugin-copy2": "^0.3.1", "rollup-plugin-polyfill-node": "^0.8.0", "rollup-plugin-postcss": "^4.0.2", - "rollup-plugin-svelte": "^7.2.1", + "rollup-plugin-svelte": "^7.2.2", "rollup-plugin-svg": "^2.0.0", "tar": "^6.2.1" } diff --git a/schema.json b/schema.json index e3f562d..c84f11a 100644 --- a/schema.json +++ b/schema.json @@ -164,6 +164,20 @@ "label": "Source Array", "resetOn": "bound", "dependsOn": { "setting": "bound", "value": "array" } + }, + { + "type": "boolean", + "key": "autorefresh", + "label": "Auto Refresh", + "resetOn": "bound", + "dependsOn": { "setting": "bound", "value": "dataprovider" } + }, + { + "type": "number", + "key": "autorefreshRate", + "label": "Refresh Every", + "resetOn": "bound", + "dependsOn": "autorefresh" } ] }, @@ -401,12 +415,6 @@ "key": "activeTab", "label": "Active Tab" }, - { - "type": "boolean", - "key": "tabsQuiet", - "label": "Quiet", - "defaultValue": false - }, { "type": "boolean", "key": "tabsEmphasized", @@ -530,6 +538,11 @@ "type": "color", "key": "color", "label": "Color" + }, + { + "type": "event", + "key": "onShow", + "label": "On Show" } ] }, diff --git a/src/Component.svelte b/src/Component.svelte index 6c46538..32754f3 100644 --- a/src/Component.svelte +++ b/src/Component.svelte @@ -14,6 +14,7 @@ Provider, ContextScopes, componentStore, + screenStore, memo, } = getContext("sdk"); @@ -66,9 +67,12 @@ export let skeleton = false; - // Events + // Events as Parent export let onTabChange; + // Events as Child + export let onShow; + let containers = []; let container; @@ -85,11 +89,9 @@ let id = Math.random() * 10; let childCssVariables = {}; let cssVariables = {}; - let scope = ContextScopes.Local; + let builderCssVariables = {}; - const props = memo($$props); - - $: props.set($$props); + let scope = ContextScopes.Local; // The array of slots to be rendered in array repeater mode let slots; @@ -177,6 +179,7 @@ childState.deactivate(); }, show() { + onShow?.(); childState.activate(); }, synchProperties() { @@ -186,8 +189,6 @@ ...$component.styles, normal: { ...$component.styles.normal, - ...cssVariables, - ...childCssVariables, "border-top-width": borderTop ? $component.styles.normal["border-width"] ?? 0 : 0, @@ -390,7 +391,7 @@ }, refresh() { childCssVariables = { - flex: flex == "grow" ? flexFactor + " 1 auto" : "0 1 auto", + flex: flex == "grow" ? flexFactor + " 1 auto" : "0 0 auto", }; }, }, @@ -477,9 +478,9 @@ "plugin/bb-component-SuperContainer" : false; - $: state.synchProperties($$props); - $: if (bound == "array") slots = safeParse(sourceArray); + + // If a Child , keep in sync with parent $: childState.synch($parentState); $: parentState?.updateContainer( id, @@ -490,6 +491,7 @@ Math.min(rowSpan, $parentGridStore?.gridRows) ); + // Inside Builder specigic code $: { if ( $builderStore.inBuilder && @@ -509,13 +511,32 @@ } } - $: if (mode == "grid") setContext("superContainerParams", gridStore); + // Update on property changes + $: state.synchProperties( + mode, + childMode, + hAlign, + vAlign, + flex, + flexFactor, + bound, + direction, + gap, + activeTab, + gridColumns, + gridRows + ); - $: if (mode == "fieldgroup") { - setContext("field-group", labelPos); - setContext("field-group-label-width", labelWidth); - setContext("field-group-disabled", disabled); - } + // Append Compnent Styles + $: $component.styles = { + ...$component.styles, + normal: { + ...$component.styles.normal, + ...cssVariables, + ...childCssVariables, + ...builderCssVariables, + }, + }; function safeParse(str) { let parsed = []; @@ -553,9 +574,15 @@ } }); - $: state.synchProperties($props); - + // Expose State to Children setContext("superContainer", state); + $: if (mode == "grid") setContext("superContainerParams", gridStore); + + $: if (mode == "fieldgroup") { + setContext("field-group", labelPos); + setContext("field-group-label-width", labelWidth); + setContext("field-group-disabled", disabled); + } (resizing ? state.resize(e) : null)} /> -{#key disabled} - {#key mode} - {#if $childState != "hidden" && $childState != "tabItem"} -
- {#if skeleton} - Loading ... - {:else} - {#if mode == "grid" && $builderStore.inBuilder} -
- {#each coords as _, idx} -
- {idx} -
- {/each} +{#if $childState != "hidden" && $childState != "tabItem"} +
+ {#if skeleton} + Loading ... + {:else} + {#if mode == "grid" && $builderStore.inBuilder} +
+ {#each coords as _, idx} +
+ {idx}
- {/if} - - {#if mode == "tabs" && containers?.length > 0} - - {/if} - - - {#if bound == "dataprovider" && dataprovider} - - {#if dataprovider?.rows?.length} - {#each dataprovider.rows as row} - - - - {/each} - {:else if $builderStore.inBuilder} - - - - {/if} - - {:else if bound == "array"} - {#if slots?.length} - {#each slots as row, idx} - - - - {/each} - {:else if $builderStore.inBuilder} - - - - {/if} - - {:else if mode == "grid"} + {/each} +
+ {/if} + + {#if mode == "tabs" && containers?.length > 0} + + {/if} + + + {#if bound == "dataprovider" && dataprovider} + + {#if dataprovider?.rows?.length} + {#each dataprovider.rows as row} + + + + {/each} + {:else if $builderStore.inBuilder} + - {:else} - {#key labelPos + labelWidth} + + {/if} + + {:else if bound == "array"} + {#if slots?.length} + {#each slots as row, idx} + - {/key} - {/if} - - {#if grabberPosition} - - {/if} + + {/each} + {:else if $builderStore.inBuilder} + + + {/if} -
+ + {:else if mode == "grid"} + + {:else} + {#key labelPos + labelWidth} + + {/key} + {/if} + + {#if grabberPosition} + + {/if} {/if} - {/key} -{/key} +
+{/if} diff --git a/src/TabControl.svelte b/src/TabControl.svelte index ba64e9f..d3a7973 100644 --- a/src/TabControl.svelte +++ b/src/TabControl.svelte @@ -6,20 +6,20 @@ export let vAlign; export let state; export let theme; - export let tabsQuiet; export let tabsSize; export let tabsAlignment; export let tabsIconsOnly; export let tabsEmphasized; let tabs = []; + let innerWidth; let indicatorLeft, indicatorWidth, indicatorTop, indicatorHeight; const tabHeights = { - S: "2.25rem", - M: "2.5rem", - L: "3rem", + S: "2rem", + M: "2.25rem", + L: "2.5rem", }; const tabWidths = { S: "7.5rem", @@ -46,11 +46,13 @@ } }; + $: getIndicatorPosition(innerWidth); $: setTimeout(() => getIndicatorPosition($$props, tabs), 10); + {#if containers?.length}
{#each containers as container, idx} + +
Date: Tue, 29 Oct 2024 16:24:36 +0200 Subject: [PATCH 2/2] v1.10.0 --- package.json | 14 +- schema.json | 58 ++------- src/Component.svelte | 288 +++++++++++++++--------------------------- src/TabControl.svelte | 10 +- 4 files changed, 124 insertions(+), 246 deletions(-) diff --git a/package.json b/package.json index 768566a..3706654 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bb-component-SuperContainer", - "version": "1.9.0", + "version": "1.10.0", "description": "A Multi Layout Data Aware Container Component for Budibase", "author": "Michael Poirazi", "license": "MIT", @@ -14,19 +14,19 @@ "@crownframework/svelte-error-boundary": "^1.0.3", "@spectrum-css/opacitycheckerboard": "^1.1.5", "@spectrum-css/splitview": "4.0.3", - "svelte": "^4.2.18", + "svelte": "^4.2.19", "svelte-fsm": "^1.2.0" }, "devDependencies": { - "@budibase/backend-core": "^2.29.4", - "@budibase/shared-core": "^2.29.4", + "@budibase/backend-core": "^2.33.5", + "@budibase/shared-core": "^2.33.5", "@rollup/plugin-commonjs": "^25.0.8", "@rollup/plugin-json": "^6.1.0", - "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-node-resolve": "^15.3.0", "@rollup/plugin-terser": "^0.4.4", "npm-run-all": "^4.1.5", - "postcss": "^8.4.39", - "rollup": "^2.79.1", + "postcss": "^8.4.47", + "rollup": "^2.79.2", "rollup-plugin-copy2": "^0.3.1", "rollup-plugin-polyfill-node": "^0.8.0", "rollup-plugin-postcss": "^4.0.2", diff --git a/schema.json b/schema.json index c84f11a..fae62b9 100644 --- a/schema.json +++ b/schema.json @@ -10,14 +10,18 @@ "showEmptyState": true, "icon": "SelectIntersect", "styles": ["padding", "size", "border", "background"], + "grid": { + "hAlign": "stretch", + "vAlign": "stretch" + }, "context": [ { "type": "schema", - "scope": "local" + "scope": "global" }, { "type": "static", - "scope": "local", + "scope": "global", "values": [ { "key": "value", "label": "value", "type": "object" }, { "key": "index", "label": "index", "type": "number" } @@ -156,6 +160,7 @@ "type": "dataProvider", "key": "dataprovider", "label": "Data Provider", + "resetOn": "bound", "dependsOn": { "setting": "bound", "value": "dataprovider" } }, { @@ -164,20 +169,6 @@ "label": "Source Array", "resetOn": "bound", "dependsOn": { "setting": "bound", "value": "array" } - }, - { - "type": "boolean", - "key": "autorefresh", - "label": "Auto Refresh", - "resetOn": "bound", - "dependsOn": { "setting": "bound", "value": "dataprovider" } - }, - { - "type": "number", - "key": "autorefreshRate", - "label": "Refresh Every", - "resetOn": "bound", - "dependsOn": "autorefresh" } ] }, @@ -196,7 +187,7 @@ { "section": true, "name": "Container Options", - "dependsOn": { "setting": "mode", "value": "container" }, + "settings": [ { "type": "select", @@ -264,7 +255,7 @@ "barTitle": "Align stretched horizontally" } ], - "defaultValue": "flex-start" + "defaultValue": "stretch" }, { "type": "select", @@ -545,37 +536,6 @@ "label": "On Show" } ] - }, - { - "section": true, - "tag": "style", - "name": "Borders", - "settings": [ - { - "type": "boolean", - "key": "borderTop", - "label": "Top", - "defaultValue": true - }, - { - "type": "boolean", - "key": "borderRight", - "label": "Right", - "defaultValue": true - }, - { - "type": "boolean", - "key": "borderBottom", - "label": "Bottom", - "defaultValue": true - }, - { - "type": "boolean", - "key": "borderLeft", - "label": "Left", - "defaultValue": true - } - ] } ] } diff --git a/src/Component.svelte b/src/Component.svelte index 32754f3..515747e 100644 --- a/src/Component.svelte +++ b/src/Component.svelte @@ -1,22 +1,13 @@ (resizing ? state.resize(e) : null)} /> - -{#if $childState != "hidden" && $childState != "tabItem"} +{#if $childState != "tabsItem"}
Loading ... {:else} - {#if mode == "grid" && $builderStore.inBuilder} + {#if mode == "grid" && inBuilder}
{#each coords as _, idx} -
- {idx} -
+
{/each}
{/if} @@ -639,42 +577,24 @@ /> {/if} - - {#if bound == "dataprovider" && dataprovider} - - {#if dataprovider?.rows?.length} - {#each dataprovider.rows as row} - - - - {/each} - {:else if $builderStore.inBuilder} - + {#if bound} + {#each slots as row, idx (idx)} + - {/if} - - {:else if bound == "array"} - {#if slots?.length} - {#each slots as row, idx} - - - - {/each} - {:else if $builderStore.inBuilder} - - - - {/if} - - {:else if mode == "grid"} - + {/each} {:else} - {#key labelPos + labelWidth} - + {#key labelWidth} + {#key labelPos} + {#key disabled} + + {/key} + {/key} {/key} {/if} @@ -722,7 +642,7 @@ grid-template-rows: repeat(var(--grid-rows), 1fr); column-gap: var(--grid-column-gap); row-gap: var(--grid-row-gap); - background-color: var(--spectrum-global-color-gray-200); + background-color: var(--spectrum-global-color-gray-75); } .placeholder { @@ -730,7 +650,7 @@ align-items: center; justify-content: center; color: var(--spectrum-global-color-gray-500); - border: 1px solid var(--spectrum-global-color-gray-400); + border: 1px dotted var(--spectrum-global-color-gray-400); } .super-fieldgroup { diff --git a/src/TabControl.svelte b/src/TabControl.svelte index d3a7973..71307b1 100644 --- a/src/TabControl.svelte +++ b/src/TabControl.svelte @@ -52,10 +52,10 @@ - {#if containers?.length}
- {#each containers as container, idx} + {#each containers as container, idx (idx)}