From 5d6967cee890fc473057c5ab1b36ebafad2f1289 Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:17:08 +0000 Subject: [PATCH 1/3] fix dropdown width issue & improve ux --- package-lock.json | 107 ++++++++ package.json | 3 + .../elements/forms/inputSelectSearch.svelte | 252 ++++++++---------- .../settings/displayName.svelte | 5 +- svelte.config.js | 8 +- 5 files changed, 234 insertions(+), 141 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e11b21dca..0385a05099 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,8 @@ "web-vitals": "^3.4.0" }, "devDependencies": { + "@melt-ui/pp": "^0.1.4", + "@melt-ui/svelte": "^0.65.1", "@playwright/test": "^1.37.1", "@sveltejs/adapter-static": "^2.0.3", "@sveltejs/kit": "^1.24.0", @@ -53,6 +55,7 @@ "svelte-check": "^3.5.1", "svelte-jester": "^2.3.2", "svelte-preprocess": "^5.0.4", + "svelte-sequential-preprocessor": "^2.0.1", "tslib": "^2.6.2", "typescript": "^5.2.2", "vite": "^4.4.9", @@ -1292,6 +1295,31 @@ "node": ">=14" } }, + "node_modules/@floating-ui/core": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.5.2.tgz", + "integrity": "sha512-Ii3MrfY/GAIN3OhXNzpCKaLxHQfJF9qvwq/kEJYdqDxeIHa01K8sldugal6TmeeXl+WMvhv9cnVzUTaFFJF09A==", + "dev": true, + "dependencies": { + "@floating-ui/utils": "^0.1.3" + } + }, + "node_modules/@floating-ui/dom": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.5.3.tgz", + "integrity": "sha512-ClAbQnEqJAKCJOEbbLo5IUlZHkNszqhuxS4fHAVxRPXPya6Ysf2G8KypnYcOTpx6I8xcgF9bbHb6g/2KpbV8qA==", + "dev": true, + "dependencies": { + "@floating-ui/core": "^1.4.2", + "@floating-ui/utils": "^0.1.3" + } + }, + "node_modules/@floating-ui/utils": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.1.6.tgz", + "integrity": "sha512-OfX7E2oUDYxtBvsuS4e/jSn4Q9Qb6DzgeYtsAdkPZ47znpoNsMgZw0+tVijiv3uGNR6dgNlty6r9rzIzHjtd/A==", + "dev": true + }, "node_modules/@humanwhocodes/config-array": { "version": "0.11.13", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", @@ -1325,6 +1353,15 @@ "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", "dev": true }, + "node_modules/@internationalized/date": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/@internationalized/date/-/date-3.5.0.tgz", + "integrity": "sha512-nw0Q+oRkizBWMioseI8+2TeUPEyopJVz5YxoYVzR0W1v+2YytiYah7s/ot35F149q/xAg4F1gT/6eTd+tsUpFQ==", + "dev": true, + "dependencies": { + "@swc/helpers": "^0.5.0" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -1809,6 +1846,39 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@melt-ui/pp": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@melt-ui/pp/-/pp-0.1.4.tgz", + "integrity": "sha512-zR+Kl3CZJPJBHW8V7YcdQCMI/dVcnW9Ct3yGbVaIywYVStVRS7F9uEDOea3xLLT2WTGodQePzPlUn53yKFu87g==", + "dev": true, + "dependencies": { + "estree-walker": "^3.0.3" + }, + "engines": { + "pnpm": ">=8.6.3" + }, + "peerDependencies": { + "@melt-ui/svelte": ">= 0.29.0", + "svelte": "^3.55.0 || ^4.0.0 || ^5.0.0-next.1" + } + }, + "node_modules/@melt-ui/svelte": { + "version": "0.65.1", + "resolved": "https://registry.npmjs.org/@melt-ui/svelte/-/svelte-0.65.1.tgz", + "integrity": "sha512-EFLLcfT7i3ICsGmdK4i83V5+08jl6ZKFKxguvOr2zNV08cIXWwp4lIwoYLOpP6ydORrbJjiRBd9sfNJcrm5YWg==", + "dev": true, + "dependencies": { + "@floating-ui/core": "^1.3.1", + "@floating-ui/dom": "^1.4.5", + "@internationalized/date": "^3.5.0", + "dequal": "^2.0.3", + "focus-trap": "^7.5.2", + "nanoid": "^4.0.2" + }, + "peerDependencies": { + "svelte": ">=3 <5" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -2081,6 +2151,15 @@ "vite": "^4.0.0" } }, + "node_modules/@swc/helpers": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.3.tgz", + "integrity": "sha512-FaruWX6KdudYloq1AHD/4nU+UsMTdNE8CKyrseXWEcgjDAbvkwJg2QGPAnfIJLIWsjZOSPLOAykK6fuYp4vp4A==", + "dev": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@testing-library/dom": { "version": "9.3.3", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.3.tgz", @@ -4546,6 +4625,15 @@ "integrity": "sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==", "dev": true }, + "node_modules/focus-trap": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/focus-trap/-/focus-trap-7.5.4.tgz", + "integrity": "sha512-N7kHdlgsO/v+iD/dMoJKtsSqs5Dz/dXZVebRgJw23LDk+jMi/974zyiOYDziY2JPp8xivq9BmUGwIJMiuSBi7w==", + "dev": true, + "dependencies": { + "tabbable": "^6.2.0" + } + }, "node_modules/for-each": { "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", @@ -8479,6 +8567,19 @@ "node": ">=12" } }, + "node_modules/svelte-sequential-preprocessor": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/svelte-sequential-preprocessor/-/svelte-sequential-preprocessor-2.0.1.tgz", + "integrity": "sha512-N5JqlBni6BzElxmuFrOPxOJnjsxh1cFDACLEVKs8OHBcx8ZNRO1p5SxuQex1m3qbLzAC8G99EHeWcxGkjyKjLQ==", + "dev": true, + "dependencies": { + "svelte": "^4.0.1", + "tslib": "~2.6.0" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/svelte/node_modules/aria-query": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", @@ -8528,6 +8629,12 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, + "node_modules/tabbable": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.2.0.tgz", + "integrity": "sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==", + "dev": true + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", diff --git a/package.json b/package.json index 633d192740..e0118c8205 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "web-vitals": "^3.4.0" }, "devDependencies": { + "@melt-ui/pp": "^0.1.4", + "@melt-ui/svelte": "^0.65.1", "@playwright/test": "^1.37.1", "@sveltejs/adapter-static": "^2.0.3", "@sveltejs/kit": "^1.24.0", @@ -65,6 +67,7 @@ "svelte-check": "^3.5.1", "svelte-jester": "^2.3.2", "svelte-preprocess": "^5.0.4", + "svelte-sequential-preprocessor": "^2.0.1", "tslib": "^2.6.2", "typescript": "^5.2.2", "vite": "^4.4.9", diff --git a/src/lib/elements/forms/inputSelectSearch.svelte b/src/lib/elements/forms/inputSelectSearch.svelte index 929b528e4e..28ab237acc 100644 --- a/src/lib/elements/forms/inputSelectSearch.svelte +++ b/src/lib/elements/forms/inputSelectSearch.svelte @@ -1,6 +1,6 @@ -
  • - - - -
    -
    - {#if $$slots.output && selectedOption} -
    { - if (interactiveOutput) hasFocus = !hasFocus; - }}> - -
    - {:else} - (hasFocus = true)} - on:click={() => (hasFocus = true)} - on:input={handleInput} - on:keydown={handleKeydown} /> - {/if} - -
    - {#if showClearBtn} - - {/if} + + +
    +
    + {#if $$slots.output && selectedOption} +
    { + if (interactiveOutput) hasFocus = !hasFocus; + }}> + +
    + {:else} + + {/if} + +
    + {#if showClearBtn} -
    + {/if} +
    - - {#each options as option, i} -
  • - -
  • - {:else} -
  • - There are no {name} that match your search -
  • - {/each} - - - + +
    +
    +
    +
      + {#each options as o} +
    • + +
    • + {:else} +
    • + There are no {name} that match your search +
    • + {/each} +
    +
    +
    +
    + + diff --git a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte index ed2e408a5c..6047e84abf 100644 --- a/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte +++ b/src/routes/console/project-[project]/databases/database-[database]/collection-[collection]/settings/displayName.svelte @@ -37,7 +37,10 @@ $: options = ($attributes as Models.AttributeString[]) .filter( (attr) => - attr.type === 'string' && !attr?.array && !names?.some((name) => name === attr.key) + attr.type === 'string' && + !attr?.array && + !names?.some((name) => name === attr.key) && + attr.key.toLowerCase().includes(search?.toLowerCase()) ) .map((attr) => { return { diff --git a/svelte.config.js b/svelte.config.js index ca8f1dd0ba..3b2327858b 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,11 +1,12 @@ +import { preprocessMeltUI } from '@melt-ui/pp'; +import sequence from 'svelte-sequential-preprocessor'; import adapter from '@sveltejs/adapter-static'; import preprocess from 'svelte-preprocess'; - -/** @type {import('@sveltejs/kit').Config} */ +/** @type {import('@sveltejs/kit').Config}*/ const config = { // Consult https://github.com/sveltejs/svelte-preprocess // for more information about preprocessors - preprocess: preprocess(), + preprocess: sequence([preprocess(), preprocessMeltUI()]), compilerOptions: { accessors: process.env.VITEST }, @@ -26,5 +27,4 @@ const config = { } } }; - export default config; From befed8e636e365259d145c4ca18a9b6c67be9c4b Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Wed, 13 Dec 2023 12:36:01 +0000 Subject: [PATCH 2/3] better click outside --- .../elements/forms/inputSelectSearch.svelte | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/lib/elements/forms/inputSelectSearch.svelte b/src/lib/elements/forms/inputSelectSearch.svelte index 28ab237acc..15eb33b741 100644 --- a/src/lib/elements/forms/inputSelectSearch.svelte +++ b/src/lib/elements/forms/inputSelectSearch.svelte @@ -1,6 +1,7 @@ + +
    + class:u-stretch={stretch} + bind:this={wrapperEl}> @@ -112,7 +133,7 @@ {placeholder} {required} on:input={handleInput} - bind:this={element} + bind:this={inputEl} use:melt={$input} /> {/if} @@ -133,14 +154,14 @@ disabled={!interactiveOutput} on:click={() => { hasFocus = !hasFocus; - open.set(true); + $open = !$open; }}>
    -
    +
      From 6a6a3ec67c863b7fabf046b4b00e9fcc681855cf Mon Sep 17 00:00:00 2001 From: tglide <26071571+TGlide@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:54:56 +0000 Subject: [PATCH 3/3] fix dropdown --- .../elements/forms/inputSelectSearch.svelte | 70 +++++++++++++------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/src/lib/elements/forms/inputSelectSearch.svelte b/src/lib/elements/forms/inputSelectSearch.svelte index 15eb33b741..f4f1c1de68 100644 --- a/src/lib/elements/forms/inputSelectSearch.svelte +++ b/src/lib/elements/forms/inputSelectSearch.svelte @@ -41,14 +41,24 @@ options: comboOptions } = createCombobox({ onSelectedChange({ next }) { - if (next) { - value = next.value; - dispatch('select', next); - } + value = next ? next.value : null; + dispatch('select', next); + return next; }, preventScroll: false, - closeOnOutsideClick: false + closeOnOutsideClick: false, + positioning: { + strategy: 'fixed', + sameWidth: true, + placement: 'bottom' + }, + portal: null, + ids: id + ? { + trigger: id + } + : undefined }); $: { @@ -85,8 +95,7 @@ } $: showClearBtn = (hasFocus && search) || value; - - $: console.log(disabled); + $: showOutput = $$slots.output && selectedOption;
      - {#if $$slots.output && selectedOption} -
      { - if (interactiveOutput) hasFocus = !hasFocus; - }}> - -
      - {:else} +
      + {#if showOutput} +
      { + if (interactiveOutput) { + hasFocus = !hasFocus; + open.set(true); + } + }}> + +
      + {/if} - {/if} +
      {#if showClearBtn} @@ -189,7 +202,7 @@
      -