Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
exclude: changelog\.md

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.26.0
rev: v9.27.0
hooks:
- id: eslint
types: [file]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"package": "svelte-package",
"serve": "vite build && vite preview",
"check": "svelte-check src",
"test": "vitest --run --coverage tests/unit/*.ts && npm run test:e2e",
"test": "vitest run && playwright test",
"test:unit": "vitest tests/unit/*.ts",
"test:e2e": "playwright test tests/*.test.ts",
"changelog": "npx auto-changelog --package --output changelog.md --hide-empty-releases --hide-credit --commit-limit false",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Tests](https://github.com/janosh/svelte-multiselect/actions/workflows/test.yml/badge.svg)](https://github.com/janosh/svelte-multiselect/actions/workflows/test.yml)
[![GitHub Pages](https://github.com/janosh/svelte-multiselect/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/janosh/svelte-multiselect/actions/workflows/gh-pages.yml)
[![NPM version](https://img.shields.io/npm/v/svelte-multiselect?logo=NPM&color=purple)](https://npmjs.com/package/svelte-multiselect)
[![Needs Svelte version](https://img.shields.io/npm/dependency-version/svelte-multiselect/svelte?color=teal&logo=Svelte&label=Svelte)](https://github.com/sveltejs/svelte/blob/master/packages/svelte/CHANGELOG.md)
[![Needs Svelte version](https://img.shields.io/npm/dependency-version/svelte-multiselect/peer/svelte?color=teal&logo=Svelte&label=Svelte)](https://github.com/sveltejs/svelte/blob/master/packages/svelte/CHANGELOG.md)
[![REPL](https://img.shields.io/badge/Svelte-REPL-blue?label=Try%20it!)](https://svelte.dev/repl/a5a14b8f15d64cb083b567292480db05)
[![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-darkblue?logo=stackblitz)](https://stackblitz.com/github/janosh/svelte-multiselect)

Expand Down
5 changes: 3 additions & 2 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--night: #0b0b1b;
--blue: cornflowerblue;
--text-color: #ccc;
--main-max-width: 50em;

--sms-active-color: rgba(255, 255, 255, 0.1);
--sms-focus-border: 1pt solid cornflowerblue;
Expand All @@ -28,7 +29,7 @@ main {
margin: auto;
margin-bottom: 3em;
width: 100%;
max-width: 50em;
max-width: var(--main-max-width);
}
button,
a.btn {
Expand Down Expand Up @@ -139,7 +140,7 @@ div.multiselect.invalid {
aside.toc.desktop {
position: fixed;
top: 3em;
left: calc(50vw + 50em / 2);
left: calc(50vw + var(--main-max-width) / 2);
max-width: 16em;
}

Expand Down
43 changes: 12 additions & 31 deletions src/lib/CmdPalette.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script lang="ts">
import { tick, type Snippet } from 'svelte'
import { fade } from 'svelte/transition'

import Select from './MultiSelect.svelte'
import type { MultiSelectProps } from './props'
import type { ObjectOption } from './types'
Expand All @@ -22,34 +20,31 @@
fade_duration?: number // in ms
style?: string // for dialog
// for span in option snippet, has no effect when specifying a custom option snippet
span_style?: string
open?: boolean
dialog?: HTMLDialogElement | null
input?: HTMLInputElement | null
placeholder?: string
children?: Snippet
}
let {
actions,
triggers = [`k`],
close_keys = [`Escape`],
fade_duration = 200,
style = ``,
span_style = ``,
open = $bindable(false),
dialog = $bindable(null),
input = $bindable(null),
placeholder = `Filter actions...`,
children,
...rest
}: Props = $props()

$effect(() => {
if (open && input) input?.focus() // focus input when palette is opened
})

async function toggle(event: KeyboardEvent) {
if (triggers.includes(event.key) && event.metaKey && !open) {
// open on cmd+trigger
open = true
await tick() // wait for dialog to open and input to be mounted
input?.focus()
} else if (close_keys.includes(event.key) && open) {
open = false
}
Expand All @@ -65,8 +60,6 @@
option.action(option.label)
open = false
}

const children_render = $derived(children)
</script>

<svelte:window onkeydown={toggle} onclick={close_if_outside} />
Expand All @@ -80,22 +73,18 @@
onadd={trigger_action_and_close}
onkeydown={toggle}
{...rest}
>
{#snippet children({ option })}
<!-- wait for https://github.com/sveltejs/svelte/pull/8304 -->
{#if children_render}
{@render children_render()}
{:else}
<span style={span_style}>{option.label}</span>
{/if}
{/snippet}
</Select>
--sms-bg="var(--sms-options-bg)"
--sms-width="min(20em, 90vw)"
--sms-max-width="none"
--sms-placeholder-color="lightgray"
--sms-options-margin="1px 0"
--sms-options-border-radius="0 0 1ex 1ex"
/>
</dialog>
{/if}

<style>
/* TODO maybe remove global */
:where(:global(dialog)) {
:where(dialog) {
position: fixed;
top: 30%;
border: none;
Expand All @@ -106,12 +95,4 @@
z-index: 10;
font-size: 2.4ex;
}
dialog :global(div.multiselect) {
--sms-bg: var(--sms-options-bg);
--sms-width: min(20em, 90vw);
--sms-max-width: none;
--sms-placeholder-color: lightgray;
--sms-options-margin: 1px 0;
--sms-options-border-radius: 0 0 1ex 1ex;
}
</style>
Loading