@streamscloud/kit 0.2.30 → 0.2.32

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.
@@ -129,6 +129,7 @@
129
129
 
130
130
  &__option {
131
131
  font-size: var(--_singleselect--text--font-size);
132
+ @include mixins.ellipsis;
132
133
 
133
134
  &--faded {
134
135
  color: var(--_singleselect--placeholder--color);
@@ -7,7 +7,8 @@ import IconReorderDotsVertical from '@fluentui/svg-icons/icons/re_order_dots_ver
7
7
  import Fuse from 'fuse.js';
8
8
  import { dndzone } from 'svelte-dnd-action';
9
9
  import Select from 'svelte-select';
10
- let { value = null, options = [], placeholder = '', disabled = false, loading = false, creatable = null, inlineSelection = false, hideEmptyState = false, showFullItem = false, reorderable = false, on, icon, chevronIcon } = $props();
10
+ let { value = null, options = [], placeholder = '', disabled = false, loading = false, creatable = null, inlineSelection = false, hideEmptyState = false, showFullItem = false, reorderable = false, compareBy, on, icon, chevronIcon } = $props();
11
+ const valuesEqual = (a, b) => (compareBy ? compareBy(a) === compareBy(b) : a === b);
11
12
  const loc = new SelectLocalization();
12
13
  let listOpen = $state(false);
13
14
  let filterText = $state('');
@@ -34,9 +35,9 @@ $effect(() => {
34
35
  }
35
36
  else {
36
37
  selectValue = value
37
- .filter((v) => flatOptions.some((o) => o.value === v))
38
+ .filter((v) => flatOptions.some((o) => valuesEqual(o.value, v)))
38
39
  .map((v) => {
39
- const existent = flatOptions.find((x) => x.value === v);
40
+ const existent = flatOptions.find((x) => valuesEqual(x.value, v));
40
41
  return {
41
42
  id: typeof existent.value === 'string' ? existent.value : JSON.stringify(existent.value),
42
43
  label: existent.label,
@@ -100,7 +101,7 @@ const onSelectFilter = (itemsFiltered) => {
100
101
  label: x.label,
101
102
  value: x.value,
102
103
  $isCreated: false,
103
- group: flatOptions.find((f) => f.value === x.value)?.group
104
+ group: flatOptions.find((f) => valuesEqual(f.value, x.value))?.group
104
105
  }))
105
106
  ];
106
107
  }
@@ -112,11 +113,11 @@ const onSelectFilter = (itemsFiltered) => {
112
113
  };
113
114
  const onClear = (item) => {
114
115
  const items = Array.isArray(item) ? item : [item];
115
- const itemsRemaining = selectValue.filter((x) => !items.some((i) => i.value === x.value));
116
+ const itemsRemaining = selectValue.filter((x) => !items.some((i) => !i.$isCreated && valuesEqual(i.value, x.value)));
116
117
  on?.change?.(itemsRemaining.map((x) => x.value));
117
118
  };
118
119
  const removeItem = (item) => {
119
- const itemsRemaining = selectValue.filter((x) => x.value !== item.value);
120
+ const itemsRemaining = selectValue.filter((x) => !valuesEqual(x.value, item.value));
120
121
  on?.change?.(itemsRemaining.map((x) => x.value));
121
122
  };
122
123
  const flipDurationMs = 200;
@@ -17,6 +17,8 @@ declare function $$render<T>(): {
17
17
  showFullItem?: boolean;
18
18
  /** Enable drag-and-drop reordering of external tags */
19
19
  reorderable?: boolean;
20
+ /** Custom equality comparator for option values. When provided, two values are equal if compareBy(a) === compareBy(b). */
21
+ compareBy?: (value: T) => string | number;
20
22
  on?: {
21
23
  change?: (value: T[]) => void;
22
24
  create?: (label: string) => void;
@@ -9,7 +9,8 @@ import Fuse from 'fuse.js';
9
9
  import { nanoid } from 'nanoid';
10
10
  import { dndzone } from 'svelte-dnd-action';
11
11
  import Select from 'svelte-select';
12
- let { value = null, loadOptions: loadOptionsFn, debounce = 350, placeholder = '', disabled = false, loading = false, creatable = null, inlineSelection = false, hideEmptyState = false, showFullItem = false, showChevron = false, maxVisibleItems = undefined, reorderable = false, on, icon, chevronIcon, optionSnippet } = $props();
12
+ let { value = null, loadOptions: loadOptionsFn, debounce = 350, placeholder = '', disabled = false, loading = false, creatable = null, inlineSelection = false, hideEmptyState = false, showFullItem = false, showChevron = false, maxVisibleItems = undefined, reorderable = false, compareBy, on, icon, chevronIcon, optionSnippet } = $props();
13
+ const valuesEqual = (a, b) => (compareBy ? compareBy(a) === compareBy(b) : a === b);
13
14
  const loc = new SelectLocalization();
14
15
  let listOpen = $state(false);
15
16
  let filterText = $state('');
@@ -44,7 +45,7 @@ let createOption = $state(null);
44
45
  let actualOptions = $state([]);
45
46
  const generateOptions = (selected, actual, created) => {
46
47
  const generated = actual
47
- .filter((x) => !selected.some((v) => v.value === x.value))
48
+ .filter((x) => !selected.some((v) => valuesEqual(v.value, x.value)))
48
49
  .map((x) => ({
49
50
  label: x.label,
50
51
  value: x.value,
@@ -109,11 +110,11 @@ const onSelectFilter = () => {
109
110
  };
110
111
  const onClear = (item) => {
111
112
  const items = Array.isArray(item) ? item : [item];
112
- const itemsRemaining = selectValue.filter((x) => !items.some((i) => i.value === x.value));
113
+ const itemsRemaining = selectValue.filter((x) => !items.some((i) => !i.$isCreated && valuesEqual(i.value, x.value)));
113
114
  on?.change?.(itemsRemaining.map((x) => ({ label: x.label, value: x.value })));
114
115
  };
115
116
  const removeItem = (item) => {
116
- const itemsRemaining = selectValue.filter((x) => x.value !== item.value);
117
+ const itemsRemaining = selectValue.filter((x) => !valuesEqual(x.value, item.value));
117
118
  on?.change?.(itemsRemaining.map((x) => ({ label: x.label, value: x.value })));
118
119
  };
119
120
  const flipDurationMs = 200;
@@ -24,6 +24,8 @@ declare function $$render<T>(): {
24
24
  maxVisibleItems?: number;
25
25
  /** Enable drag-and-drop reordering of external tags */
26
26
  reorderable?: boolean;
27
+ /** Custom equality comparator for option values. When provided, two values are equal if compareBy(a) === compareBy(b). */
28
+ compareBy?: (value: T) => string | number;
27
29
  on?: {
28
30
  change?: (value: SelectOption<T>[]) => void;
29
31
  create?: (label: string) => void;
@@ -4,7 +4,8 @@ import IconAdd from '@fluentui/svg-icons/icons/add_16_filled.svg?raw';
4
4
  import IconChevronDown from '@fluentui/svg-icons/icons/chevron_down_20_regular.svg?raw';
5
5
  import Fuse from 'fuse.js';
6
6
  import Select from 'svelte-select';
7
- let { value = null, options = [], placeholder = '', disabled = false, loading = false, creatable = null, allowReset = false, groupHeaderSelectable = false, on, icon, optionSnippet, selectionSnippet } = $props();
7
+ let { value = null, options = [], placeholder = '', disabled = false, loading = false, creatable = null, allowReset = false, groupHeaderSelectable = false, compareBy, on, icon, optionSnippet, selectionSnippet } = $props();
8
+ const valuesEqual = (a, b) => (compareBy ? compareBy(a) === compareBy(b) : a === b);
8
9
  const loc = new SelectLocalization();
9
10
  let listOpen = $state(false);
10
11
  let filterText = $state('');
@@ -26,7 +27,7 @@ const flattenGroupedOptions = (opts) => {
26
27
  const flatOptions = $derived(flattenGroupedOptions(options));
27
28
  let selectValue = $state.raw(null);
28
29
  $effect(() => {
29
- const existent = flatOptions.find((x) => x.value === value);
30
+ const existent = value !== null ? flatOptions.find((x) => valuesEqual(x.value, value)) : null;
30
31
  if (existent) {
31
32
  selectValue = {
32
33
  label: existent.label,
@@ -124,7 +125,7 @@ const onSelectFilter = (itemsFiltered) => {
124
125
  label: x.label,
125
126
  value: x.value,
126
127
  $isCreated: false,
127
- group: flatOptions.find((f) => f.value === x.value)?.group
128
+ group: flatOptions.find((f) => valuesEqual(f.value, x.value))?.group
128
129
  }))
129
130
  ];
130
131
  }
@@ -336,6 +337,10 @@ Single-value select dropdown built on svelte-select with fuzzy search. Supports
336
337
  }
337
338
  .select__option {
338
339
  font-size: var(--_singleselect--text--font-size);
340
+ text-overflow: ellipsis;
341
+ max-width: 100%;
342
+ white-space: nowrap;
343
+ overflow: hidden;
339
344
  }
340
345
  .select__option--faded {
341
346
  color: var(--_singleselect--placeholder--color);
@@ -13,6 +13,8 @@ declare function $$render<T>(): {
13
13
  allowReset?: boolean;
14
14
  /** Allow clicking group headers to select them */
15
15
  groupHeaderSelectable?: boolean;
16
+ /** Custom equality comparator for option values. When provided, two values are equal if compareBy(a) === compareBy(b). */
17
+ compareBy?: (value: T) => string | number;
16
18
  on?: {
17
19
  change?: (value: T | null) => void;
18
20
  create?: (label: string) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.2.30",
3
+ "version": "0.2.32",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",