svelte-multiselect 11.0.0-rc.1 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
- <script>export let color = `cornflowerblue`;
2
- export let duration = `1.5s`;
3
- export let size = `1em`;
1
+ <script lang="ts">"use strict";
2
+ let { color = `cornflowerblue`, duration = `1.5s`, size = `1em` } = $props();
4
3
  </script>
5
4
 
6
5
  <div
@@ -9,7 +8,7 @@ export let size = `1em`;
9
8
  {color}"
10
9
  style:width={size}
11
10
  style:height={size}
12
- />
11
+ ></div>
13
12
 
14
13
  <style>
15
14
  div {
@@ -1,20 +1,8 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- color?: string;
5
- duration?: string;
6
- size?: string;
7
- };
8
- events: {
9
- [evt: string]: CustomEvent<any>;
10
- };
11
- slots: {};
12
- exports?: {} | undefined;
13
- bindings?: string | undefined;
14
- };
15
- export type CircleSpinnerProps = typeof __propDef.props;
16
- export type CircleSpinnerEvents = typeof __propDef.events;
17
- export type CircleSpinnerSlots = typeof __propDef.slots;
18
- export default class CircleSpinner extends SvelteComponent<CircleSpinnerProps, CircleSpinnerEvents, CircleSpinnerSlots> {
1
+ interface Props {
2
+ color?: string;
3
+ duration?: string;
4
+ size?: string;
19
5
  }
20
- export {};
6
+ declare const CircleSpinner: import("svelte").Component<Props, {}, "">;
7
+ type CircleSpinner = ReturnType<typeof CircleSpinner>;
8
+ export default CircleSpinner;
@@ -1,23 +1,13 @@
1
- <script>import { tick } from 'svelte';
2
- import { fade } from 'svelte/transition';
1
+ <script lang="ts">import { fade } from 'svelte/transition';
3
2
  import Select from './MultiSelect.svelte';
4
- export let actions;
5
- export let triggers = [`k`];
6
- export let close_keys = [`Escape`];
7
- export let fade_duration = 200; // in ms
8
- export let style = ``; // for dialog
9
- // for span in option slot, has no effect when passing a slot
10
- export let span_style = ``;
11
- export let open = false;
12
- export let dialog = null;
13
- export let input = null;
14
- export let placeholder = `Filter actions...`;
3
+ let { actions, triggers = [`k`], close_keys = [`Escape`], fade_duration = 200, style = ``, open = $bindable(false), dialog = $bindable(null), input = $bindable(null), placeholder = `Filter actions...`, ...rest } = $props();
4
+ $effect(() => {
5
+ if (open && input)
6
+ input?.focus(); // focus input when palette is opened
7
+ });
15
8
  async function toggle(event) {
16
9
  if (triggers.includes(event.key) && event.metaKey && !open) {
17
- // open on cmd+trigger
18
10
  open = true;
19
- await tick(); // wait for dialog to open and input to be mounted
20
- input?.focus();
21
11
  }
22
12
  else if (close_keys.includes(event.key) && open) {
23
13
  open = false;
@@ -28,13 +18,13 @@ function close_if_outside(event) {
28
18
  open = false;
29
19
  }
30
20
  }
31
- function trigger_action_and_close(event) {
32
- event.detail.option.action(event.detail.option.label);
21
+ function trigger_action_and_close({ option }) {
22
+ option.action(option.label);
33
23
  open = false;
34
24
  }
35
25
  </script>
36
26
 
37
- <svelte:window on:keydown={toggle} on:click={close_if_outside} />
27
+ <svelte:window onkeydown={toggle} onclick={close_if_outside} />
38
28
 
39
29
  {#if open}
40
30
  <dialog open bind:this={dialog} transition:fade={{ duration: fade_duration }} {style}>
@@ -42,16 +32,16 @@ function trigger_action_and_close(event) {
42
32
  options={actions}
43
33
  bind:input
44
34
  {placeholder}
45
- on:add={trigger_action_and_close}
46
- on:keydown={toggle}
47
- {...$$restProps}
48
- let:option
49
- >
50
- <!-- wait for https://github.com/sveltejs/svelte/pull/8304 -->
51
- <slot>
52
- <span style={span_style}>{option.label}</span>
53
- </slot>
54
- </Select>
35
+ onadd={trigger_action_and_close}
36
+ onkeydown={toggle}
37
+ {...rest}
38
+ --sms-bg="var(--sms-options-bg)"
39
+ --sms-width="min(20em, 90vw)"
40
+ --sms-max-width="none"
41
+ --sms-placeholder-color="lightgray"
42
+ --sms-options-margin="1px 0"
43
+ --sms-options-border-radius="0 0 1ex 1ex"
44
+ />
55
45
  </dialog>
56
46
  {/if}
57
47
 
@@ -67,12 +57,4 @@ function trigger_action_and_close(event) {
67
57
  z-index: 10;
68
58
  font-size: 2.4ex;
69
59
  }
70
- dialog :global(div.multiselect) {
71
- --sms-bg: var(--sms-options-bg);
72
- --sms-width: min(20em, 90vw);
73
- --sms-max-width: none;
74
- --sms-placeholder-color: lightgray;
75
- --sms-options-margin: 1px 0;
76
- --sms-options-border-radius: 0 0 1ex 1ex;
77
- }
78
60
  </style>
@@ -1,33 +1,20 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- [x: string]: any;
5
- actions: {
6
- label: string;
7
- action: () => void;
8
- }[];
9
- triggers?: string[] | undefined;
10
- close_keys?: string[] | undefined;
11
- fade_duration?: number | undefined;
12
- style?: string | undefined;
13
- span_style?: string | undefined;
14
- open?: boolean | undefined;
15
- dialog?: (HTMLDialogElement | null) | undefined;
16
- input?: (HTMLInputElement | null) | undefined;
17
- placeholder?: string | undefined;
18
- };
19
- events: {
20
- [evt: string]: CustomEvent<any>;
21
- };
22
- slots: {
23
- default: {};
24
- };
25
- exports?: undefined;
26
- bindings?: undefined;
27
- };
28
- export type CmdPaletteProps = typeof __propDef.props;
29
- export type CmdPaletteEvents = typeof __propDef.events;
30
- export type CmdPaletteSlots = typeof __propDef.slots;
31
- export default class CmdPalette extends SvelteComponent<CmdPaletteProps, CmdPaletteEvents, CmdPaletteSlots> {
1
+ import type { MultiSelectProps } from './props';
2
+ import type { ObjectOption } from './types';
3
+ interface Action extends ObjectOption {
4
+ label: string;
5
+ action: (label: string) => void;
32
6
  }
33
- export {};
7
+ interface Props extends Omit<MultiSelectProps<Action>, `options` | `onadd` | `onkeydown` | `placeholder`> {
8
+ actions: Action[];
9
+ triggers?: string[];
10
+ close_keys?: string[];
11
+ fade_duration?: number;
12
+ style?: string;
13
+ open?: boolean;
14
+ dialog?: HTMLDialogElement | null;
15
+ input?: HTMLInputElement | null;
16
+ placeholder?: string;
17
+ }
18
+ declare const CmdPalette: import("svelte").Component<Props, {}, "open" | "input" | "dialog">;
19
+ type CmdPalette = ReturnType<typeof CmdPalette>;
20
+ export default CmdPalette;