From bd481adbfc5dedce0db9ee5ac7bb2097048a767a Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Mon, 3 Jul 2023 09:33:24 +0200 Subject: [PATCH] =?UTF-8?q?fix(frontend):=20Forked=20svelte-select=20to=20?= =?UTF-8?q?fix=20overflow=20issues=20using=20a=20po=E2=80=A6=20(#1778)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(frontend): Forked svelte-select to fix overflow issues using a portal * fix(frontend): fix event bubble * fix(frontend): fix build * fix(frontend): Remove uncessary support for multiple values * fix(frontend): conditional portal * fix(frontend): conditional portal * fix(frontend): fix resourcepicker * fix(frontend): AppMultiSelect fix * fix(frontend): fix build * fix(frontend): AppMultiSelect fix --- frontend/package-lock.json | 75 +- frontend/package.json | 3 +- .../src/lib/components/ResourcePicker.svelte | 2 +- .../src/lib/components/ScriptPicker.svelte | 3 +- .../components/inputs/AppMultiSelect.svelte | 81 +- .../apps/components/inputs/AppSelect.svelte | 2 +- .../apps/svelte-select/lib/ChevronIcon.svelte | 18 + .../apps/svelte-select/lib/ClearIcon.svelte | 22 + .../lib/ConditionalPortal.svelte | 11 + .../apps/svelte-select/lib/LoadingIcon.svelte | 34 + .../apps/svelte-select/lib/Select.svelte | 1112 +++++++++++++++++ .../apps/svelte-select/lib/filter.js | 32 + .../apps/svelte-select/lib/get-items.js | 30 + .../apps/svelte-select/lib/index.js | 1 + .../apps/svelte-select/lib/tailwind.css | 130 ++ 15 files changed, 1491 insertions(+), 65 deletions(-) create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/ChevronIcon.svelte create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/ClearIcon.svelte create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/ConditionalPortal.svelte create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/LoadingIcon.svelte create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/Select.svelte create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/filter.js create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/get-items.js create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/index.js create mode 100644 frontend/src/lib/components/apps/svelte-select/lib/tailwind.css diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4775af3b3d..347949a550 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -34,7 +34,6 @@ "svelte-chartjs": "^3.1.0", "svelte-dnd-action": "^0.9.22", "svelte-portal": "^2.2.0", - "svelte-select": "^5.6.1", "svelte-timezone-picker": "^2.0.3", "tailwind-merge": "^1.12.0", "vscode-ws-jsonrpc": "3.0.0", @@ -44,6 +43,7 @@ "yjs": "^13.6.4" }, "devDependencies": { + "@floating-ui/core": "^1.3.1", "@playwright/test": "^1.34.3", "@rgossiaux/svelte-headlessui": "^1.0.2", "@sveltejs/adapter-static": "^2.0.2", @@ -81,6 +81,7 @@ "svelte-awesome": "^3.2.0", "svelte-awesome-color-picker": "^2.4.5", "svelte-check": "^3.4.3", + "svelte-floating-ui": "^1.5.3", "svelte-highlight": "^7.3.0", "svelte-multiselect": "^8.6.2", "svelte-overlay": "^1.4.1", @@ -452,16 +453,18 @@ } }, "node_modules/@floating-ui/core": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.2.5.tgz", - "integrity": "sha512-qrcbyfnRVziRlB6IYwjCopYhO7Vud750JlJyuljruIXcPxr22y8zdckcJGsuOdnQ639uVD1tTXddrcH3t3QYIQ==" + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.3.1.tgz", + "integrity": "sha512-Bu+AMaXNjrpjh41znzHqaz3r2Nr8hHuHZT6V2LBKMhyMl0FgKA62PNYbqnfgmzOhoWZj70Zecisbo4H1rotP5g==", + "dev": true }, "node_modules/@floating-ui/dom": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.2.5.tgz", - "integrity": "sha512-+sAUfpQ3Frz+VCbPCqj+cZzvEESy3fjSeT/pDWkYCWOBXYNNKZfuVsHuv8/JO2zze8+Eb/Q7a6hZVgzS81fLbQ==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.4.3.tgz", + "integrity": "sha512-nB/68NyaQlcdY22L+Fgd1HERQ7UGv7XFN+tPxwrEfQL4nKtAP/jIZnZtpUlXbtV+VEGHh6W/63Gy2C5biWI3sA==", + "dev": true, "dependencies": { - "@floating-ui/core": "^1.2.4" + "@floating-ui/core": "^1.3.1" } }, "node_modules/@fortawesome/fontawesome-common-types": { @@ -7143,12 +7146,13 @@ } }, "node_modules/svelte-floating-ui": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/svelte-floating-ui/-/svelte-floating-ui-1.2.8.tgz", - "integrity": "sha512-8Ifi5CD2Ui7FX7NjJRmutFtXjrB8T/FMNoS2H8P81t5LHK4I9G4NIs007rLWG/nRl7y+zJUXa3tWuTjYXw/O5A==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/svelte-floating-ui/-/svelte-floating-ui-1.5.3.tgz", + "integrity": "sha512-yjLeRQ4SNcICbMabp5S2cXc5ubBd2eua+swfTqqGBeg8ZrUvotZYK8jsRWETl/3RgLQsaZbEYKx8OmLA3wL/yw==", + "dev": true, "dependencies": { - "@floating-ui/core": "^1.1.0", - "@floating-ui/dom": "^1.1.0" + "@floating-ui/core": "^1.2.4", + "@floating-ui/dom": "^1.2.4" } }, "node_modules/svelte-highlight": { @@ -7282,15 +7286,6 @@ "integrity": "sha512-fLkhfnyEc4uMOCZCl8IPyC0e9lujrjqdSyrKw28Y8j99YUPZR+pHnSxde7PqhM0ST6eyO4ugh2nFnLZTIoG9aQ==", "dev": true }, - "node_modules/svelte-select": { - "version": "5.6.1", - "resolved": "https://registry.npmjs.org/svelte-select/-/svelte-select-5.6.1.tgz", - "integrity": "sha512-Powj91VAWyaNMSSOQ0E29UMTw/ExWsHEsA83H7yQgfji2S2DhG6Rs5qZHslZ+ihbCPxXel5uEzwLsSqDABkQDw==", - "dependencies": { - "@floating-ui/dom": "^1.2.1", - "svelte-floating-ui": "1.2.8" - } - }, "node_modules/svelte-splitpanes": { "version": "0.7.14", "resolved": "https://registry.npmjs.org/svelte-splitpanes/-/svelte-splitpanes-0.7.14.tgz", @@ -8394,16 +8389,18 @@ "dev": true }, "@floating-ui/core": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.2.5.tgz", - "integrity": "sha512-qrcbyfnRVziRlB6IYwjCopYhO7Vud750JlJyuljruIXcPxr22y8zdckcJGsuOdnQ639uVD1tTXddrcH3t3QYIQ==" + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.3.1.tgz", + "integrity": "sha512-Bu+AMaXNjrpjh41znzHqaz3r2Nr8hHuHZT6V2LBKMhyMl0FgKA62PNYbqnfgmzOhoWZj70Zecisbo4H1rotP5g==", + "dev": true }, "@floating-ui/dom": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.2.5.tgz", - "integrity": "sha512-+sAUfpQ3Frz+VCbPCqj+cZzvEESy3fjSeT/pDWkYCWOBXYNNKZfuVsHuv8/JO2zze8+Eb/Q7a6hZVgzS81fLbQ==", + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.4.3.tgz", + "integrity": "sha512-nB/68NyaQlcdY22L+Fgd1HERQ7UGv7XFN+tPxwrEfQL4nKtAP/jIZnZtpUlXbtV+VEGHh6W/63Gy2C5biWI3sA==", + "dev": true, "requires": { - "@floating-ui/core": "^1.2.4" + "@floating-ui/core": "^1.3.1" } }, "@fortawesome/fontawesome-common-types": { @@ -13253,12 +13250,13 @@ "requires": {} }, "svelte-floating-ui": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/svelte-floating-ui/-/svelte-floating-ui-1.2.8.tgz", - "integrity": "sha512-8Ifi5CD2Ui7FX7NjJRmutFtXjrB8T/FMNoS2H8P81t5LHK4I9G4NIs007rLWG/nRl7y+zJUXa3tWuTjYXw/O5A==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/svelte-floating-ui/-/svelte-floating-ui-1.5.3.tgz", + "integrity": "sha512-yjLeRQ4SNcICbMabp5S2cXc5ubBd2eua+swfTqqGBeg8ZrUvotZYK8jsRWETl/3RgLQsaZbEYKx8OmLA3wL/yw==", + "dev": true, "requires": { - "@floating-ui/core": "^1.1.0", - "@floating-ui/dom": "^1.1.0" + "@floating-ui/core": "^1.2.4", + "@floating-ui/dom": "^1.2.4" } }, "svelte-highlight": { @@ -13334,15 +13332,6 @@ "integrity": "sha512-fLkhfnyEc4uMOCZCl8IPyC0e9lujrjqdSyrKw28Y8j99YUPZR+pHnSxde7PqhM0ST6eyO4ugh2nFnLZTIoG9aQ==", "dev": true }, - "svelte-select": { - "version": "5.6.1", - "resolved": "https://registry.npmjs.org/svelte-select/-/svelte-select-5.6.1.tgz", - "integrity": "sha512-Powj91VAWyaNMSSOQ0E29UMTw/ExWsHEsA83H7yQgfji2S2DhG6Rs5qZHslZ+ihbCPxXel5uEzwLsSqDABkQDw==", - "requires": { - "@floating-ui/dom": "^1.2.1", - "svelte-floating-ui": "1.2.8" - } - }, "svelte-splitpanes": { "version": "0.7.14", "resolved": "https://registry.npmjs.org/svelte-splitpanes/-/svelte-splitpanes-0.7.14.tgz", diff --git a/frontend/package.json b/frontend/package.json index e0146803ed..2e68ad3f7b 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,6 +16,7 @@ "test": "playwright test --config=tests-out/playwright.config.js" }, "devDependencies": { + "@floating-ui/core": "^1.3.1", "@playwright/test": "^1.34.3", "@rgossiaux/svelte-headlessui": "^1.0.2", "@sveltejs/adapter-static": "^2.0.2", @@ -53,6 +54,7 @@ "svelte-awesome": "^3.2.0", "svelte-awesome-color-picker": "^2.4.5", "svelte-check": "^3.4.3", + "svelte-floating-ui": "^1.5.3", "svelte-highlight": "^7.3.0", "svelte-multiselect": "^8.6.2", "svelte-overlay": "^1.4.1", @@ -94,7 +96,6 @@ "svelte-chartjs": "^3.1.0", "svelte-dnd-action": "^0.9.22", "svelte-portal": "^2.2.0", - "svelte-select": "^5.6.1", "svelte-timezone-picker": "^2.0.3", "tailwind-merge": "^1.12.0", "vscode-ws-jsonrpc": "3.0.0", diff --git a/frontend/src/lib/components/ResourcePicker.svelte b/frontend/src/lib/components/ResourcePicker.svelte index 9208179b63..138dd80955 100644 --- a/frontend/src/lib/components/ResourcePicker.svelte +++ b/frontend/src/lib/components/ResourcePicker.svelte @@ -4,7 +4,7 @@ import { faPen, faPlus, faRotateRight } from '@fortawesome/free-solid-svg-icons' import { createEventDispatcher } from 'svelte' import Icon from 'svelte-awesome' - import Select from 'svelte-select' + import Select from './apps/svelte-select/lib/index' import { SELECT_INPUT_DEFAULT_STYLE } from '../defaults' import AppConnect from './AppConnect.svelte' import { Button } from './common' diff --git a/frontend/src/lib/components/ScriptPicker.svelte b/frontend/src/lib/components/ScriptPicker.svelte index 7aba40b42e..18f8cae332 100644 --- a/frontend/src/lib/components/ScriptPicker.svelte +++ b/frontend/src/lib/components/ScriptPicker.svelte @@ -4,7 +4,7 @@ import { hubScripts, workspaceStore } from '$lib/stores' import { createEventDispatcher } from 'svelte' - import Select from 'svelte-select' + import Select from './apps/svelte-select/lib/index' import { getScriptByPath } from '$lib/scripts' import { Button, Drawer, DrawerContent } from './common' @@ -97,6 +97,7 @@ placeholder="Pick a {itemKind}" inputStyles={SELECT_INPUT_DEFAULT_STYLE.inputStyles} containerStyles={SELECT_INPUT_DEFAULT_STYLE.containerStyles} + portal={false} /> {/if} diff --git a/frontend/src/lib/components/apps/components/inputs/AppMultiSelect.svelte b/frontend/src/lib/components/apps/components/inputs/AppMultiSelect.svelte index 7e12578a24..94dd89b80e 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppMultiSelect.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppMultiSelect.svelte @@ -1,6 +1,5 @@ {#each Object.keys(components['multiselectcomponent'].initialData.configuration) as key (key)} @@ -84,23 +105,46 @@ e.stopPropagation() } }} + use:floatingRef + bind:clientWidth={w} + bind:clientHeight={h} > {#if !value || Array.isArray(value)} - { - outputs?.result.set([...(value ?? [])]) - }} - options={Array.isArray(items) ? items : []} - placeholder={resolvedConfig.placeholder} - allowUserOptions={resolvedConfig.create} - on:open={() => { - $selectedComponent = [id] - }} - /> +
+ { + outputs?.result.set([...(value ?? [])]) + }} + options={Array.isArray(items) ? items : []} + placeholder={resolvedConfig.placeholder} + allowUserOptions={resolvedConfig.create} + on:open={() => { + $selectedComponent = [id] + open = true + }} + on:close={() => { + open = false + }} + > +
+ {option} +
+
+ + {:else} Value {value} is not an array {/if} @@ -112,7 +156,8 @@ padding: 0 !important; overflow: auto; } - .svelte-select-list { + + .z1000 { z-index: 1000 !important; } diff --git a/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte b/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte index dd6a187ed8..4cc3efca43 100644 --- a/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte +++ b/frontend/src/lib/components/apps/components/inputs/AppSelect.svelte @@ -1,6 +1,6 @@ + +{#if condition} + +{:else} + +{/if} diff --git a/frontend/src/lib/components/apps/svelte-select/lib/LoadingIcon.svelte b/frontend/src/lib/components/apps/svelte-select/lib/LoadingIcon.svelte new file mode 100644 index 0000000000..2feebbb525 --- /dev/null +++ b/frontend/src/lib/components/apps/svelte-select/lib/LoadingIcon.svelte @@ -0,0 +1,34 @@ + + + + + diff --git a/frontend/src/lib/components/apps/svelte-select/lib/Select.svelte b/frontend/src/lib/components/apps/svelte-select/lib/Select.svelte new file mode 100644 index 0000000000..408c288362 --- /dev/null +++ b/frontend/src/lib/components/apps/svelte-select/lib/Select.svelte @@ -0,0 +1,1112 @@ + + + + +
+ {#if listOpen} + +
+ {#if $$slots['list-prepend']}{/if} + {#if $$slots.list} + {:else if filteredItems.length > 0} + {#each filteredItems as item, i} +
handleHover(i)} + on:focus={() => handleHover(i)} + on:click|stopPropagation={() => handleItemClick({ item, i })} + on:keydown|preventDefault|stopPropagation + class="list-item" + tabindex="-1" + > +
+ + {item?.[label]} + +
+
+ {/each} + {:else if !hideEmptyState} + +
No options
+
+ {/if} + {#if $$slots['list-append']}{/if} +
+
+ {/if} + + + {#if focused} + {ariaSelection} + + {ariaContext} + + {/if} + + +
+ +
+ +
+ {#if hasValue} +
+ + {value[label]} + +
+ {/if} + + +
+ +
+ {#if loading} + + {/if} + + {#if showClear} + + {/if} + + {#if showChevron} + + {/if} +
+ + + + + + {#if required && (!value || value.length === 0)} + +