@ohos-ports/slim-select 0.0.0-stage → 4.7.0-beta.1

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +353 -2
  3. package/dist/animations.d.ts +37 -0
  4. package/dist/classes.d.ts +52 -0
  5. package/dist/events.d.ts +26 -0
  6. package/dist/helpers.d.ts +24 -0
  7. package/dist/index.d.ts +62 -0
  8. package/dist/index.umd.d.ts +2 -0
  9. package/dist/lifecycle.d.ts +44 -0
  10. package/dist/mutations.d.ts +33 -0
  11. package/dist/react/index.d.ts +4 -0
  12. package/dist/react/index.js +2153 -0
  13. package/dist/react/index.umd.js +1 -0
  14. package/dist/react/react.d.ts +16 -0
  15. package/dist/react/react.test.d.ts +1 -0
  16. package/dist/react/slim-select/react/index.d.ts +4 -0
  17. package/dist/render.d.ts +207 -0
  18. package/dist/select.d.ts +47 -0
  19. package/dist/settings.d.ts +46 -0
  20. package/dist/slimselect.cjs +2 -0
  21. package/dist/slimselect.cjs.js.map +1 -0
  22. package/dist/slimselect.css +1 -0
  23. package/dist/slimselect.css.map +1 -0
  24. package/dist/slimselect.es.js +2100 -0
  25. package/dist/slimselect.es.js.map +1 -0
  26. package/dist/slimselect.iife.js +2 -0
  27. package/dist/slimselect.iife.js.map +1 -0
  28. package/dist/slimselect.js +2 -0
  29. package/dist/slimselect.js.map +1 -0
  30. package/dist/src/docs/helpers.d.ts +14 -0
  31. package/dist/src/docs/main.d.ts +0 -0
  32. package/dist/src/docs/nav.d.ts +20 -0
  33. package/dist/src/docs/router.d.ts +2 -0
  34. package/dist/src/docs/store.d.ts +12 -0
  35. package/dist/store.d.ts +62 -0
  36. package/dist/sync.d.ts +88 -0
  37. package/dist/vue/helpers.d.ts +2 -0
  38. package/dist/vue/index.d.ts +4 -0
  39. package/dist/vue/index.js +2226 -0
  40. package/dist/vue/index.umd.js +1 -0
  41. package/dist/vue/slim-select/vue/index.d.ts +4 -0
  42. package/package.json +101 -4
  43. package/src/slim-select/slimselect.scss +807 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Brian Voelker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,354 @@
1
- # Temporary Holding Version
1
+ # Slim Select
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **The select dropdown, reimagined.**
4
+
5
+ A lightweight, dependency-free replacement for the native `<select>` — single and multi-select, search, optgroups,
6
+ remote data, modal mode on mobile, and full theming through CSS variables. Drop it into any stack, or use the official
7
+ Vue and React wrappers.
8
+
9
+ ## [slimselectjs.com](https://slimselectjs.com)
10
+
11
+ [![NPM Downloads](https://img.shields.io/npm/dt/slim-select.svg)](https://www.npmjs.com/package/slim-select)
12
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/brianvoe/slim-select/vitest.yml?logo=vitest&label=unit%20tests)
13
+ ![Tests](https://img.shields.io/badge/tests-523%20passing-brightgreen)
14
+
15
+ ![](https://raw.githubusercontent.com/brianvoe/slim-select/master/docs/slimselect.gif)
16
+
17
+ ## Documentation
18
+
19
+ Full docs, live demos, and copy-paste examples: **[slimselectjs.com](https://slimselectjs.com)**
20
+
21
+ - [Get started](https://slimselectjs.com/get-started)
22
+ - [Settings](https://slimselectjs.com/settings)
23
+ - [Methods](https://slimselectjs.com/methods)
24
+ - [Events](https://slimselectjs.com/events)
25
+ - [Styling](https://slimselectjs.com/style)
26
+
27
+ ## Features
28
+
29
+ **Select, upgraded**
30
+
31
+ - Single and multi-select with tags, placeholders, and deselect
32
+ - Search with highlighting, remote/API search, and user-addable options
33
+ - Optgroups with select-all and closable accordion groups
34
+ - HTML options, tooltips, min/max selection limits, and disabled options
35
+ - Modal mode (`off` | `on` | `mobile`) — centered panel with backdrop; mobile-friendly by default
36
+
37
+ **Looks like your product**
38
+
39
+ - Theme entirely with `--ss-*` CSS custom properties — no fighting class specificity
40
+ - Import plain CSS or SCSS; inherit styles, classes, and the `title` tooltip from the native `<select>`
41
+
42
+ **Built to ship**
43
+
44
+ - Zero dependencies
45
+ - ~66KB JS (~16KB gzip) · ~12KB CSS (~2KB gzip)
46
+ - TypeScript types included
47
+ - WCAG 2.1 Level AA accessibility (ARIA, keyboard, screen reader support)
48
+ - Keyboard type-ahead when search is turned off — type a letter to jump to a matching option
49
+ - `prefers-reduced-motion` respected
50
+ - 477 unit tests + 46 Playwright E2E tests
51
+
52
+ **Framework ready**
53
+
54
+ - Vanilla JS
55
+ - [Vue 3](#vue) component with `v-model`
56
+ - [React](#react) component with hooks and ref access
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ npm install slim-select
62
+ ```
63
+
64
+ ### CDN
65
+
66
+ ```html
67
+ <script src="https://unpkg.com/slim-select@latest/dist/slimselect.js"></script>
68
+ <link rel="stylesheet" href="https://unpkg.com/slim-select@latest/dist/slimselect.css" />
69
+ ```
70
+
71
+ ## Quick start
72
+
73
+ ```javascript
74
+ import SlimSelect from 'slim-select'
75
+ import 'slim-select/styles' // or: import 'slim-select/scss'
76
+
77
+ new SlimSelect({
78
+ select: '#selectElement'
79
+ })
80
+ ```
81
+
82
+ ```html
83
+ <select id="selectElement">
84
+ <option value="value1">Value 1</option>
85
+ </select>
86
+ ```
87
+
88
+ ## Styling
89
+
90
+ Slim Select is styled with CSS variables. Set them on a wrapper around your select (or on `:root` for a global theme):
91
+
92
+ ```css
93
+ .my-form {
94
+ --ss-primary-color: #2563eb;
95
+ --ss-bg-color: #ffffff;
96
+ --ss-font-color: #1e293b;
97
+ --ss-border-color: #e2e8f0;
98
+ --ss-border-radius: 8px;
99
+ --ss-main-height: 44px;
100
+ }
101
+ ```
102
+
103
+ See the full token list and live themes on the [Style docs](https://slimselectjs.com/style).
104
+
105
+ ## Data
106
+
107
+ Pass an array of options and optgroups instead of (or in addition to) native `<option>` elements:
108
+
109
+ ```javascript
110
+ new SlimSelect({
111
+ select: '#selectElement',
112
+
113
+ data: [
114
+ { text: 'Value 1', value: 'value1' },
115
+ {
116
+ label: 'Group label',
117
+ options: [
118
+ { text: 'Value 2', value: 'value2' },
119
+ { text: 'Value 3', value: 'value3' }
120
+ ]
121
+ }
122
+ ]
123
+ })
124
+ ```
125
+
126
+ ### Data types
127
+
128
+ ```javascript
129
+ // <optgroup>
130
+ const optgroup = {
131
+ label: 'label', // Required
132
+ selectAll: false, // Optional — default false
133
+ closable: 'off', // Optional — 'off' | 'open' | 'close'
134
+ options: [] // Required — array of options
135
+ }
136
+
137
+ // <option>
138
+ const option = {
139
+ text: 'text', // Required
140
+ value: 'value', // Optional — defaults to text
141
+ html: '<b>Html</b>', // Optional — used for display when set
142
+ selected: false,
143
+ display: true, // Optional — false if native option is hidden or display:none
144
+ disabled: false,
145
+ mandatory: false,
146
+ placeholder: false,
147
+ class: '',
148
+ style: '',
149
+ data: {} // Plain object for data-* attributes
150
+ }
151
+ ```
152
+
153
+ ## Settings
154
+
155
+ All fields are optional. Values shown are defaults.
156
+
157
+ [Full settings documentation](https://slimselectjs.com/settings)
158
+
159
+ ```javascript
160
+ new SlimSelect({
161
+ select: '#selectElement',
162
+
163
+ settings: {
164
+ disabled: false,
165
+ alwaysOpen: false,
166
+ showSearch: true, // false: type letters or digits to jump to a matching option
167
+ focusSearch: true, // false below 768px unless set
168
+ keepSearch: false,
169
+ ariaLabel: 'Combobox',
170
+ searchPlaceholder: 'Search...',
171
+ searchText: 'No Results',
172
+ searchingText: 'Searching...',
173
+ resultsText: '{count} results available',
174
+ deselectText: 'Clear',
175
+ removeText: 'Remove',
176
+ searchHighlight: false,
177
+ closeOnSelect: true,
178
+ contentLocation: document.body,
179
+ contentPosition: 'absolute', // 'absolute' | 'relative' | 'fixed'
180
+ contentWidth: '', // e.g. '500px', '>500px', '<500px'
181
+ openPosition: 'auto', // 'auto' | 'up' | 'down'
182
+ placeholderText: 'Select Value',
183
+ allowDeselect: false,
184
+ hideSelected: false,
185
+ multiString: false,
186
+ keepOrder: false,
187
+ showOptionTooltips: false,
188
+ minSelected: 0,
189
+ maxSelected: 1000,
190
+ timeoutDelay: 200,
191
+ maxValuesShown: 20,
192
+ maxValuesMessage: '{number} selected',
193
+ addableText: 'Press "Enter" to add {value}',
194
+ selectAll: false, // Multi-select: checkbox next to search
195
+ selectAllText: 'Select All',
196
+ unselectAllText: 'Unselect All',
197
+ modal: 'mobile', // 'off' | 'on' | 'mobile'
198
+ modalTitle: '' // Header above the option list in modal view
199
+ }
200
+ })
201
+ ```
202
+
203
+ ## Events
204
+
205
+ [Full events documentation](https://slimselectjs.com/events)
206
+
207
+ ```javascript
208
+ new SlimSelect({
209
+ select: '#selectElement',
210
+
211
+ events: {
212
+ // Remote/API search — return a Promise or data array
213
+ // searchValue: current input text
214
+ // selected: currently selected Option[]
215
+ // catalog: baseline list restored when search clears
216
+ search: (
217
+ searchValue: string,
218
+ selected: Option[],
219
+ catalog?: (Option | Optgroup)[]
220
+ ) =>
221
+ Promise<(Partial<Option> | Partial<Optgroup>)[]> |
222
+ (Partial<Option> | Partial<Optgroup>)[],
223
+
224
+ // Local filter when events.search is not set
225
+ searchFilter: (option: Option, search: string) => boolean,
226
+
227
+ // User-added options — return the new option or an Error
228
+ addable: (value: string) => Promise<Partial<Option> | string> | Partial<Option> | string | Error,
229
+
230
+ beforeChange: (newVal: Option[], oldVal: Option[]) => boolean | void,
231
+ afterChange: (newVal: Option[]) => void,
232
+ beforeOpen: () => void,
233
+ afterOpen: () => void,
234
+ // Return false to cancel close. info.source is why close was requested
235
+ // ('select' | 'deselect' | 'outside' | 'toggle' | 'escape' | 'tab' | 'modal' | 'api').
236
+ // info.selectionChanged is true when the selection is changing in this action.
237
+ // info.option is the clicked option when source is 'select' (undefined otherwise).
238
+ beforeClose: (info: CloseInfo) => boolean | void,
239
+ afterClose: () => void,
240
+ error: (err: Error) => void
241
+ }
242
+ })
243
+ ```
244
+
245
+ ## Methods
246
+
247
+ [Full methods documentation](https://slimselectjs.com/methods)
248
+
249
+ ```javascript
250
+ const slim = new SlimSelect({ select: '#selectElement' })
251
+
252
+ slim.enable()
253
+ slim.disable()
254
+ slim.getData()
255
+ slim.setData(data)
256
+ slim.getSelected() // string[]
257
+ slim.setSelected(['value1', 'value2'])
258
+ slim.addOption(option)
259
+ slim.open()
260
+ slim.close()
261
+ slim.search('searchValue')
262
+ slim.destroy()
263
+ ```
264
+
265
+ ## Vue
266
+
267
+ Official Vue 3 component with `v-model` and full TypeScript support.
268
+
269
+ [Vue documentation](https://slimselectjs.com/vue)
270
+
271
+ ```bash
272
+ npm install slim-select
273
+ ```
274
+
275
+ ```vue
276
+ <script lang="ts">
277
+ import SlimSelect from 'slim-select/vue'
278
+ import 'slim-select/styles'
279
+
280
+ export default {
281
+ components: { SlimSelect },
282
+ data() {
283
+ return {
284
+ selected: 'value2',
285
+ options: [
286
+ { text: 'Value 1', value: 'value1' },
287
+ { text: 'Value 2', value: 'value2' },
288
+ { text: 'Value 3', value: 'value3' }
289
+ ]
290
+ }
291
+ }
292
+ }
293
+ </script>
294
+
295
+ <template>
296
+ <SlimSelect v-model="selected" :data="options" />
297
+ </template>
298
+ ```
299
+
300
+ > **Note:** Pass options via the `:data` prop. Native `<option>` slot children are not supported in the Vue wrapper.
301
+
302
+ ## React
303
+
304
+ Official React component with hooks and ref access to the underlying instance.
305
+
306
+ [React documentation](https://slimselectjs.com/react)
307
+
308
+ ```bash
309
+ npm install slim-select
310
+ ```
311
+
312
+ ```tsx
313
+ import { useState } from 'react'
314
+ import SlimSelect from 'slim-select/react'
315
+ import 'slim-select/styles'
316
+
317
+ function MyComponent() {
318
+ const [selected, setSelected] = useState('value2')
319
+ const options = [
320
+ { text: 'Value 1', value: 'value1' },
321
+ { text: 'Value 2', value: 'value2' },
322
+ { text: 'Value 3', value: 'value3' }
323
+ ]
324
+
325
+ return <SlimSelect data={options} value={selected} onChange={setSelected} />
326
+ }
327
+ ```
328
+
329
+ > **Note:** Pass options via the `data` prop. Native `<option>` children are not supported in the React wrapper.
330
+
331
+ ### Ref access
332
+
333
+ ```tsx
334
+ import { useRef } from 'react'
335
+ import SlimSelect, { SlimSelectRef } from 'slim-select/react'
336
+ import 'slim-select/styles'
337
+
338
+ function MyComponent() {
339
+ const slimRef = useRef<SlimSelectRef>(null)
340
+
341
+ return (
342
+ <>
343
+ <SlimSelect ref={slimRef} data={options} />
344
+ <button onClick={() => slimRef.current?.slimSelect?.open()}>Open</button>
345
+ </>
346
+ )
347
+ }
348
+ ```
349
+
350
+ ## Support
351
+
352
+ [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/brianvoe)
353
+
354
+ <a href="https://www.buymeacoffee.com/brianvoe" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Animation timing helpers.
3
+ *
4
+ * CSS still runs the motion — these keep lifecycle and DOM cleanup aligned with
5
+ * --ss-animation-timing so we are not guessing with hardcoded setTimeout values.
6
+ */
7
+ /** Extra ms added to CSS duration for transitionend/animationend safety-net timeouts. */
8
+ export declare const ANIMATION_TIMEOUT_BUFFER_MS = 50;
9
+ /** .ss-content open/close transitions — wait for both before lifecycle continues. */
10
+ export declare const CONTENT_PANEL_TRANSITION_PROPERTIES: readonly ["transform", "opacity"];
11
+ /** Parse a CSS time value (e.g. "0.2s", "200ms") into milliseconds. */
12
+ export declare function parseAnimationDuration(cssValue: string, fallback?: number): number;
13
+ /** Read --ss-animation-timing from an element's computed styles. */
14
+ export declare function getAnimationDuration(element: HTMLElement, fallback?: number): number;
15
+ /**
16
+ * Safety-net timeout for animation waits.
17
+ * Derived from --ss-animation-timing (+ buffer). An explicit settings.timeoutDelay
18
+ * is treated as a minimum — never shorter than the CSS-driven duration.
19
+ */
20
+ export declare function getAnimationTimeout(element: HTMLElement, userTimeout?: number, fallback?: number): number;
21
+ /** Respect user OS accessibility preference and jsdom (no matchMedia). */
22
+ export declare function prefersReducedMotion(): boolean;
23
+ /**
24
+ * Wait for CSS transition(s) to finish, with a timeout fallback.
25
+ *
26
+ * Pass a single property name to resolve on that transitionend, or an array to
27
+ * wait until every listed property has fired (e.g. transform + opacity on .ss-content).
28
+ * Optional AbortSignal cleans up listeners when lifecycle cancels a rapid toggle.
29
+ */
30
+ export declare function waitForTransitionEnd(element: HTMLElement, propertyNames?: string | readonly string[], timeoutMs?: number, signal?: AbortSignal): Promise<void>;
31
+ /**
32
+ * Wait for a CSS @keyframes animation to finish, with a timeout fallback.
33
+ *
34
+ * Used when removing multi-select value chips (.ss-value-out). jsdom does not
35
+ * fire animationend, so the timeout wins in unit tests.
36
+ */
37
+ export declare function waitForAnimationEnd(element: HTMLElement, animationName?: string, timeoutMs?: number, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,52 @@
1
+ export default class CssClasses {
2
+ main: string;
3
+ placeholder: string;
4
+ values: string;
5
+ single: string;
6
+ multiString: string;
7
+ max: string;
8
+ value: string;
9
+ valueText: string;
10
+ valueDelete: string;
11
+ valueOut: string;
12
+ deselect: string;
13
+ deselectPath: string;
14
+ arrow: string;
15
+ arrowClose: string;
16
+ arrowOpen: string;
17
+ content: string;
18
+ contentOpen: string;
19
+ dirAbove: string;
20
+ dirBelow: string;
21
+ search: string;
22
+ searchHighlighter: string;
23
+ searching: string;
24
+ status: string;
25
+ addable: string;
26
+ addablePath: string;
27
+ list: string;
28
+ optgroup: string;
29
+ optgroupLabel: string;
30
+ optgroupLabelText: string;
31
+ optgroupActions: string;
32
+ optgroupSelectAll: string;
33
+ optgroupSelectAllBox: string;
34
+ optgroupSelectAllCheck: string;
35
+ optgroupClosable: string;
36
+ option: string;
37
+ optionDelete: string;
38
+ highlighted: string;
39
+ modalOverlay: string;
40
+ modalDialog: string;
41
+ modalTitle: string;
42
+ modalClose: string;
43
+ modalContent: string;
44
+ mainOpen: string;
45
+ close: string;
46
+ selected: string;
47
+ error: string;
48
+ disabled: string;
49
+ hide: string;
50
+ constructor(classes?: Partial<CssClasses>);
51
+ getFirst(name: keyof Omit<CssClasses, 'getFirst'>): string;
52
+ }
@@ -0,0 +1,26 @@
1
+ import { hasClassInTree } from './helpers';
2
+ export interface GlobalEventHandlers {
3
+ onDocumentClick: (e: Event) => void;
4
+ onWindowResize: () => void;
5
+ onWindowScroll: () => void;
6
+ onVisibilityChange: () => void;
7
+ }
8
+ export default class GlobalEvents {
9
+ private handlers;
10
+ private attached;
11
+ constructor(handlers: GlobalEventHandlers);
12
+ /** Attach long-lived listeners for the SlimSelect instance lifetime. */
13
+ attach(options: {
14
+ listenScroll: boolean;
15
+ }): void;
16
+ /** Attached after open animation completes — closes on outside click. */
17
+ attachDocumentClick(): void;
18
+ detachDocumentClick(): void;
19
+ detach(options: {
20
+ listenScroll: boolean;
21
+ }): void;
22
+ private resizeHandler;
23
+ private scrollHandler;
24
+ private visibilityHandler;
25
+ }
26
+ export { hasClassInTree };
@@ -0,0 +1,24 @@
1
+ import { Optgroup, Option } from './store';
2
+ import { ModalSetting } from './settings';
3
+ type DataItem = Partial<Option> | Partial<Optgroup>;
4
+ /** Copy option data attributes into a plain object (not a live DOMStringMap). */
5
+ export declare function copyOptionData(data?: {
6
+ [key: string]: string;
7
+ } | DOMStringMap | null): {
8
+ [key: string]: string;
9
+ };
10
+ /** Label text only — excludes nested form controls (e.g. wrapped select options). */
11
+ export declare function getLabelElementText(label: HTMLLabelElement): string;
12
+ /** Associated label text for a select, or its aria-label when no label is linked. */
13
+ export declare function getAssociatedLabelText(select: HTMLSelectElement): string;
14
+ export declare function generateID(): string;
15
+ export declare function hasClassInTree(element: HTMLElement, className: string): HTMLElement | null;
16
+ export declare function debounce<T extends (...args: any[]) => void>(func: T, wait?: number, immediate?: boolean): () => void;
17
+ export declare function isEqual(a: any, b: any): boolean;
18
+ /** Compare selected id sets regardless of order (multi-select). */
19
+ export declare function selectedIdsEqual(a: string[], b: string[]): boolean;
20
+ /** Compare option/optgroup arrays without JSON.stringify. */
21
+ export declare function dataStructureEqual(a: DataItem[], b: DataItem[]): boolean;
22
+ export declare function kebabCase(str: string): string;
23
+ export declare function shouldUseModalView(modal: ModalSetting, viewportWidth?: number): boolean;
24
+ export {};
@@ -0,0 +1,62 @@
1
+ import { default as CssClasses } from './classes';
2
+ import { default as Lifecycle } from './lifecycle';
3
+ import { default as Render, CloseInfo } from './render';
4
+ import { default as Select } from './select';
5
+ import { default as Settings, MODAL_MOBILE_BREAKPOINT } from './settings';
6
+ import { default as Store, Option, Optgroup } from './store';
7
+ import { default as SyncCoordinator } from './sync';
8
+ export { Settings, Option, Optgroup, MODAL_MOBILE_BREAKPOINT };
9
+ export type { ModalSetting } from './settings';
10
+ export type { Main, Content, Search, CloseInfo, CloseSource } from './render';
11
+ export interface Config {
12
+ select: string | Element;
13
+ data?: (Partial<Option> | Partial<Optgroup>)[];
14
+ settings?: Partial<Settings>;
15
+ cssClasses?: Partial<CssClasses>;
16
+ events?: Events;
17
+ }
18
+ export interface Events {
19
+ search?: (searchValue: string, selected: Option[], catalog?: (Option | Optgroup)[]) => Promise<(Partial<Option> | Partial<Optgroup>)[]> | (Partial<Option> | Partial<Optgroup>)[];
20
+ searchFilter?: (option: Option, search: string) => boolean;
21
+ addable?: (value: string) => Promise<Partial<Option> | string> | Partial<Option> | string | false | null | undefined | Error;
22
+ beforeChange?: (newVal: Option[], oldVal: Option[]) => boolean | void;
23
+ afterChange?: (newVal: Option[]) => void;
24
+ beforeOpen?: () => void;
25
+ afterOpen?: () => void;
26
+ beforeClose?: (info: CloseInfo) => boolean | void;
27
+ afterClose?: () => void;
28
+ error?: (err: Error) => void;
29
+ }
30
+ export default class SlimSelect {
31
+ selectEl: HTMLSelectElement;
32
+ settings: Settings;
33
+ cssClasses: CssClasses;
34
+ select: Select;
35
+ store: Store;
36
+ render: Render;
37
+ sync: SyncCoordinator;
38
+ lifecycle: Lifecycle;
39
+ private globalEvents;
40
+ /** Invalidates in-flight API search responses when the query changes or clears. */
41
+ private searchGeneration;
42
+ events: Events;
43
+ constructor(config: Config);
44
+ enable(): void;
45
+ disable(): void;
46
+ getData(): Option[] | Optgroup[];
47
+ setData(data: (Partial<Option> | Partial<Optgroup>)[]): void;
48
+ getSelected(): string[];
49
+ setSelected(values: string | string[], runAfterChange?: boolean): void;
50
+ addOption(option: Partial<Option>): void;
51
+ open(): void;
52
+ close(info?: CloseInfo): void;
53
+ /** Sync close — invoked by lifecycle after beforeClose approves. */
54
+ private applyClose;
55
+ search(value: string): void;
56
+ /** Reset search state without invoking the consumer search event. */
57
+ private clearSearch;
58
+ private runLocalSearch;
59
+ private runApiSearch;
60
+ destroy(): void;
61
+ private documentClick;
62
+ }
@@ -0,0 +1,2 @@
1
+ import { default as SlimSelect } from './index';
2
+ export default SlimSelect;
@@ -0,0 +1,44 @@
1
+ import { CloseInfo } from './render';
2
+ export type LifecycleState = 'closed' | 'opening' | 'open' | 'closing';
3
+ export interface LifecycleHandlers {
4
+ beforeOpen?: () => void;
5
+ afterOpen?: () => void;
6
+ /** Return false to cancel close before any DOM changes. */
7
+ beforeClose?: (info: CloseInfo) => boolean | void;
8
+ /** Sync close work — render, focus, settings. Runs after beforeClose approves. */
9
+ onClose?: (info: CloseInfo) => void;
10
+ afterClose?: () => void;
11
+ /** Fires when fully open — used to attach document click-outside listener. */
12
+ onOpenReady?: () => void;
13
+ /** Fires when fully closed — used to detach document click-outside listener. */
14
+ onCloseReady?: () => void;
15
+ }
16
+ export interface LifecycleOptions {
17
+ /** Fallback when waitForAnimation is not provided (no CSS element yet). */
18
+ timeoutDelay: number;
19
+ waitForAnimation?: (phase: 'open' | 'close', signal?: AbortSignal) => Promise<void>;
20
+ }
21
+ export default class Lifecycle {
22
+ private handlers;
23
+ private options;
24
+ state: LifecycleState;
25
+ private pendingTimer;
26
+ /** Resolvers for in-flight waitForPhase promises — cancelled on rapid toggle. */
27
+ private waitResolvers;
28
+ /** Incremented on cancelPending(); stale async completions check this before firing handlers. */
29
+ private generation;
30
+ private animationAbort;
31
+ constructor(handlers: LifecycleHandlers, options: LifecycleOptions);
32
+ get isOpen(): boolean;
33
+ get isFullOpen(): boolean;
34
+ requestOpen(): Promise<void>;
35
+ requestClose(info?: CloseInfo): Promise<boolean>;
36
+ /** Cancel timers and resolve waiting phases — called when open/close race each other. */
37
+ cancelPending(): void;
38
+ destroy(): void;
39
+ /**
40
+ * Wait for the CSS animation to finish (or timeoutDelay when no waiter exists).
41
+ * cancelPending() resolves the wait early for rapid open/close toggles.
42
+ */
43
+ private waitForPhase;
44
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Pure classification of MutationObserver records on the native <select>.
3
+ *
4
+ * Select.observeCall() uses these flags to decide which sync path to run
5
+ * (class/disabled vs full structure vs selection-only). Keeping this logic
6
+ * separate makes it testable without spinning up a full SlimSelect instance.
7
+ */
8
+ /** What changed in a single observer callback batch (flags can all be true). */
9
+ export interface MutationFlags {
10
+ /** Native select class attribute changed — sync to render styles only. */
11
+ classChanged: boolean;
12
+ /** Native select title attribute changed — sync the tooltip onto the rendered control. */
13
+ titleChanged: boolean;
14
+ /** Native select disabled attribute changed — enable/disable SlimSelect. */
15
+ disabledChanged: boolean;
16
+ /**
17
+ * Options or optgroups were added, removed, or had attributes edited.
18
+ * Triggers a full structure sync (store + native DOM + render).
19
+ */
20
+ optgroupOptionChanged: boolean;
21
+ /**
22
+ * Selection may have changed without a separate `change` event yet.
23
+ * Used when a newly added <option> is already the select's value.
24
+ */
25
+ selectionChanged: boolean;
26
+ }
27
+ /**
28
+ * Scan a MutationObserver batch and return which kinds of updates are needed.
29
+ *
30
+ * The observer watches the <select> with subtree: true, so mutations can
31
+ * target the select itself or any child <option> / <optgroup>.
32
+ */
33
+ export declare function classifyMutations(mutations: MutationRecord[], select: HTMLSelectElement): MutationFlags;
@@ -0,0 +1,4 @@
1
+ import { default as SlimSelect } from './react';
2
+ export default SlimSelect;
3
+ export { Settings, Option, Optgroup } from '../index';
4
+ export type { Config, Events } from '../index';