@streamscloud/kit 0.16.0 → 0.16.2

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.
@@ -2,6 +2,7 @@ import type { WithId } from './types';
2
2
  export declare class MapContainer<T extends WithId> {
3
3
  private _container;
4
4
  get items(): T[];
5
+ has(id: T['id']): boolean;
5
6
  add(item: T): void;
6
7
  remove(item: T): void;
7
8
  set(items: T[]): void;
@@ -4,6 +4,9 @@ export class MapContainer {
4
4
  get items() {
5
5
  return Array.from(this._container.values());
6
6
  }
7
+ has(id) {
8
+ return this._container.has(id);
9
+ }
7
10
  add(item) {
8
11
  this._container.set(item.id, item);
9
12
  }
@@ -16,6 +16,9 @@ class RepositoryInstance {
16
16
  get limit() {
17
17
  return this._limit;
18
18
  }
19
+ has(id) {
20
+ return this._container.has(id);
21
+ }
19
22
  add(...items) {
20
23
  const itemsToNotify = [];
21
24
  for (const item of items) {
@@ -4,6 +4,8 @@ export type WithId = {
4
4
  export interface Repository<T extends WithId> {
5
5
  items: T[];
6
6
  limit?: number;
7
+ /** O(1) membership check by id, backed by the keyed container. */
8
+ has(id: T['id']): boolean;
7
9
  add(...item: T[]): void;
8
10
  remove(...item: T[]): void;
9
11
  set(...item: T[]): void;
@@ -2,10 +2,10 @@
2
2
  import { CONTROL_ICON_SIZE, scaleUp } from '../icon';
3
3
  import { Input } from '../input';
4
4
  import IconSearch from '@fluentui/svg-icons/icons/search_20_regular.svg?raw';
5
- const { value, collapsedIconColor, collapsedIconSize, placeholder = '', size = 'sm', debounce = 0, shortcut = false, clearOnEscape = false, on } = $props();
5
+ const { value, collapsedIconColor, collapsedIconSize, placeholder = '', size = 'sm', debounce = 0, collapsible = true, shortcut = false, clearOnEscape = false, on } = $props();
6
6
  let inputRef = $state.raw(undefined);
7
7
  let focused = $state(false);
8
- const expanded = $derived(focused || !!value);
8
+ const expanded = $derived(!collapsible || focused || !!value);
9
9
  const collapsedSize = $derived(collapsedIconSize ?? scaleUp(CONTROL_ICON_SIZE[size]));
10
10
  const onInput = (v) => {
11
11
  on?.input?.(v);
@@ -47,10 +47,11 @@ const handleKeydown = (event) => {
47
47
 
48
48
  <!--
49
49
  @component
50
- A collapsible search input for toolbars. Collapsed to an icon-only square at the chosen field height
51
- when empty + unfocused; expands to the full input width when focused or when a value is present.
52
- Shares Input's size preset so it lines up with other field-shaped controls. Opt into `shortcut`
53
- for a document-wide Cmd/Ctrl+K focus-and-select, and `clearOnEscape` to clear on Escape.
50
+ A search input for toolbars. By default collapses to an icon-only square at the chosen field height
51
+ when empty + unfocused, and expands to the full input width when focused or when a value is present;
52
+ set `collapsible={false}` to keep it always expanded. Shares Input's size preset so it lines up with
53
+ other field-shaped controls. Opt into `shortcut` for a document-wide Cmd/Ctrl+K focus-and-select,
54
+ and `clearOnEscape` to clear on Escape.
54
55
 
55
56
  ### CSS Custom Properties
56
57
  | Property | Description | Default |
@@ -7,6 +7,8 @@ type Props = {
7
7
  placeholder?: string;
8
8
  /** Size preset (shared with Input / DatePicker / Select). @default 'sm' */
9
9
  size?: 'sm' | 'md' | 'lg';
10
+ /** Collapse to an icon-only square when empty + unfocused. Set false to keep the input always expanded. @default true */
11
+ collapsible?: boolean;
10
12
  /** Debounce delay in ms @default 0 */
11
13
  debounce?: number;
12
14
  /** Bind Cmd/Ctrl+K document-wide to focus the input and select its text. Enable on a single instance per view. @default false */
@@ -18,10 +20,11 @@ type Props = {
18
20
  };
19
21
  };
20
22
  /**
21
- * A collapsible search input for toolbars. Collapsed to an icon-only square at the chosen field height
22
- * when empty + unfocused; expands to the full input width when focused or when a value is present.
23
- * Shares Input's size preset so it lines up with other field-shaped controls. Opt into `shortcut`
24
- * for a document-wide Cmd/Ctrl+K focus-and-select, and `clearOnEscape` to clear on Escape.
23
+ * A search input for toolbars. By default collapses to an icon-only square at the chosen field height
24
+ * when empty + unfocused, and expands to the full input width when focused or when a value is present;
25
+ * set `collapsible={false}` to keep it always expanded. Shares Input's size preset so it lines up with
26
+ * other field-shaped controls. Opt into `shortcut` for a document-wide Cmd/Ctrl+K focus-and-select,
27
+ * and `clearOnEscape` to clear on Escape.
25
28
  *
26
29
  * ### CSS Custom Properties
27
30
  * | Property | Description | Default |
@@ -238,7 +238,7 @@ const getEditorColumnOrDefault = (column, editMode) => {
238
238
  {/snippet}
239
239
  {#each model.items as item, itemIndex (item)}
240
240
  {@const editMode = model.editingItem?.id === item.id}
241
- {@const isSelected = !!model.selection.items.find((x) => x.id === item.id)}
241
+ {@const isSelected = model.selection.has(item.id)}
242
242
  {@const isHighlighted = model.highlightedItemIds.includes(item.id)}
243
243
  {@const flushBottom = model.styles?.variant === 'card' && itemIndex === model.items.length - 1}
244
244
  {@const zebra = model.styles?.zebra === true && itemIndex % 2 === 1 && !isSelected && !isHighlighted}
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" generics="T extends {id: string}">import { Checkbox } from '../../checkbox';
2
2
  let { item, selection } = $props();
3
- const selected = $derived(!!selection.items.find((x) => x.id === item.id));
3
+ const selected = $derived(selection.has(item.id));
4
4
  const disabled = $derived(!selected && !!selection.limit && selection.items.length >= selection.limit);
5
5
  const toggle = () => {
6
6
  if (selected) {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" generics="T extends {id: string}">import { Checkbox } from '../../checkbox';
2
2
  import TableHeader from './table-header.svelte';
3
3
  let { column } = $props();
4
- const allSelected = $derived(!!column.data.items.length && column.data.items.every((x) => !!column.selection.items.find((i) => i.id === x.id)));
4
+ const allSelected = $derived(!!column.data.items.length && column.data.items.every((x) => column.selection.has(x.id)));
5
5
  const canSelectAll = $derived(column.data.items.length > 0 && (!column.selection.limit || column.data.items.length <= column.selection.limit));
6
6
  const toggleSelectedAll = () => {
7
7
  if (allSelected) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.16.0",
3
+ "version": "0.16.2",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",