@smilodon/react 1.11.0 → 1.12.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.
- package/COMPLETE-GUIDE.md +67 -0
- package/README.md +134 -0
- package/dist/index.cjs +129 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +129 -32
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +13 -3
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/COMPLETE-GUIDE.md
CHANGED
|
@@ -679,6 +679,41 @@ function EventHandling() {
|
|
|
679
679
|
|
|
680
680
|
## Styling & Theming
|
|
681
681
|
|
|
682
|
+
### Active class mapping for custom-rendered options (Core #82)
|
|
683
|
+
|
|
684
|
+
Use `classMap.active` to supply application-specific active styles when using `customRenderer`. Core removes stale built-in aliases and old mapped classes when active focus changes:
|
|
685
|
+
|
|
686
|
+
```tsx
|
|
687
|
+
<Select
|
|
688
|
+
items={items}
|
|
689
|
+
customRenderer={(item) => <span>{item.label}</span>}
|
|
690
|
+
classMap={{ active: "my-active-option", selected: "my-selected-option" }}
|
|
691
|
+
/>
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
Active and selected are distinct states; use `data-sm-state` or the mapped classes when styling. The correction is in Core. See the [Core rendering contract](../core/README.md#active-state-on-custom-option-roots).
|
|
695
|
+
|
|
696
|
+
### Dropdown enter and exit animations (Core 1.12.0)
|
|
697
|
+
|
|
698
|
+
The shared Core supports independent animations controlled through inherited CSS variables:
|
|
699
|
+
|
|
700
|
+
```css
|
|
701
|
+
enhanced-select {
|
|
702
|
+
--select-dropdown-animation: dropdownEnter 220ms ease-out forwards;
|
|
703
|
+
--select-dropdown-exit-animation: dropdownExit 160ms ease-in forwards;
|
|
704
|
+
--select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
|
|
705
|
+
--select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
|
|
706
|
+
}
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
Exit updates `aria-expanded` and `close` synchronously while an inert visual panel finishes animating. Set `--select-dropdown-exit-animation: none` to disable exit. Reduced-motion preferences are honored. Core `1.12.0` is available from npm.
|
|
710
|
+
|
|
711
|
+
### Acknowledged pagination and rerender ownership (#85 — pending React release)
|
|
712
|
+
|
|
713
|
+
The locally prepared React fix synchronizes `items`/`groupedItems` only for actual input identity changes; presentation config changes must not overwrite accepted cumulative pages. Keep initial item references stable and use `completeDataRequest()` for acknowledged page results with the request ID and query generation. That fix is **not merged or released**; the public React 1.11.0 package cannot be assumed to contain it.
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
682
717
|
### Inline Styles with CSS Variables
|
|
683
718
|
|
|
684
719
|
```tsx
|
|
@@ -1242,6 +1277,38 @@ function AsyncSelect() {
|
|
|
1242
1277
|
}
|
|
1243
1278
|
```
|
|
1244
1279
|
|
|
1280
|
+
### Customizing the Core busy bucket
|
|
1281
|
+
|
|
1282
|
+
`loadingIcon` and `loadingContent` provide React nodes to Core's native `loading-icon` and `loading-content` slots. The adapter keeps these nodes in the custom element's light DOM and React owns their lifecycle; Core controls when the slot projection is visible.
|
|
1283
|
+
|
|
1284
|
+
```tsx
|
|
1285
|
+
<Select
|
|
1286
|
+
items={items}
|
|
1287
|
+
infiniteScroll
|
|
1288
|
+
config={{
|
|
1289
|
+
busyBucket: {
|
|
1290
|
+
enabled: true,
|
|
1291
|
+
showSpinner: false,
|
|
1292
|
+
showMessage: true,
|
|
1293
|
+
message: 'Loading…',
|
|
1294
|
+
minDisplayTime: 200,
|
|
1295
|
+
contentMode: 'replace',
|
|
1296
|
+
},
|
|
1297
|
+
}}
|
|
1298
|
+
loadingIcon={<MyLoadingIcon />}
|
|
1299
|
+
loadingContent={(
|
|
1300
|
+
<div>
|
|
1301
|
+
<strong>Loading more options…</strong>
|
|
1302
|
+
<span>Additional results will appear shortly.</span>
|
|
1303
|
+
</div>
|
|
1304
|
+
)}
|
|
1305
|
+
/>
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
`append` is the default `contentMode` and shows the built-in UI alongside custom content. `replace` shows only accessible custom content and hides the icon and message regions; otherwise Core retains its “Loading…” fallback. Keep meaningful text in replacement content so assistive technology has a status to announce. In append mode, the icon is decorative and separate from `arrowIcon`.
|
|
1309
|
+
|
|
1310
|
+
The busy bucket is presentation only. `minDisplayTime` may keep it visible briefly after completion, but never delays the data coordinator, page advancement, or `aria-busy`. Custom nodes remain mounted while the bucket is hidden; gate animation or expensive work through application state. The existing `Searching...` state has its own rendering path.
|
|
1311
|
+
|
|
1245
1312
|
### With React Hook Form
|
|
1246
1313
|
|
|
1247
1314
|
```tsx
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Select component for React applications. The shared core has scoped automated Phase 4 browser coverage; complete React integration parity and manual assistive-technology certification remain unverified.
|
|
4
4
|
|
|
5
|
+
> **Upcoming web release:** React `1.12.0` and Core `1.17.0` are release candidates, not yet available from npm. Their cumulative changes and qualification limits are tracked in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md).
|
|
6
|
+
|
|
5
7
|
> Large-list status: the public `virtualized` prop enables legacy chunked rendering for large flat lists; it does not window rows to the viewport, and all results may eventually be mounted. True viewport virtualization remains guarded by a private test seam and is not a supported production mode. The shared core passed its scoped Phase 4 automated browser matrix in Chromium, Firefox, and WebKit; this does not certify every React integration, minimum browser versions, or WCAG conformance. Manual assistive-technology assessment remains pending. See the [current limitation record](../../docs/KNOWN-LIMITATIONS.md#viewport-virtualization-status).
|
|
6
8
|
|
|
7
9
|
## 📖 Documentation
|
|
@@ -176,6 +178,7 @@ The coordinator rejects stale responses by request ID and query generation; the
|
|
|
176
178
|
|
|
177
179
|
### Other useful scenarios
|
|
178
180
|
|
|
181
|
+
- **Terminal empty remote search (#92):** When the host completes the matching acknowledged request with `status: 'exhausted'`, `items: []`, and `hasMore: false`, Core displays the query-specific no-results message after successful projection. React consumers do not need a manual rerender, popup toggle, or `setItems([])` workaround. Wait for `onDataProjection` with `status: 'complete'` before relying on the projected DOM; `completeDataRequest()` returning `accepted` reports response acceptance, not DOM settlement. An empty page with `status: 'empty'` and `hasMore: true` is nonterminal. This guidance does not include the separate React #85 fix.
|
|
179
182
|
- **Empty query:** clearing search still invokes `onSearch` with `request.query === ''`. `URLSearchParams` serializes it as an explicit empty `q` parameter; do not omit it if the endpoint treats an empty query specially.
|
|
180
183
|
- **Page-based pagination:** change `paginationMode` to `'page'`; the request's `position.page` is the page to request. Keep the API's page numbering consistent with `firstPage`.
|
|
181
184
|
- **Hybrid search:** use `searchMode: 'hybrid'` only when the host intends the runtime's hybrid search behavior; the host still answers the remote request with its identity and generation.
|
|
@@ -184,6 +187,75 @@ The coordinator rejects stale responses by request ID and query generation; the
|
|
|
184
187
|
- **Legacy compatibility:** omit `config.dataLoading` to retain the legacy protocol. Existing `onSearch(query, results, count)` and `onLoadMore(page)` calls remain usable; the new request argument is optional in those callback signatures.
|
|
185
188
|
- **Controlled selection:** keep `value` in application state and update it through `onChange`. Replacing remote result pages does not transfer ownership of the selected value from the application to the transport layer.
|
|
186
189
|
|
|
190
|
+
### Custom busy bucket (React 1.12.0; requires Core 1.13.0)
|
|
191
|
+
|
|
192
|
+
Introduced in `@smilodon/react@1.12.0`, `loadingIcon` and `loadingContent` expose Core's native loading slots. Use `@smilodon/core@^1.13.0`. These are React-owned light-DOM children; Core projects them into its Shadow DOM busy bucket without creating another React root.
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
<Select
|
|
196
|
+
items={items}
|
|
197
|
+
infiniteScroll
|
|
198
|
+
config={{
|
|
199
|
+
busyBucket: {
|
|
200
|
+
enabled: true,
|
|
201
|
+
showSpinner: false,
|
|
202
|
+
showMessage: true,
|
|
203
|
+
message: 'Loading…',
|
|
204
|
+
minDisplayTime: 200,
|
|
205
|
+
contentMode: 'append',
|
|
206
|
+
},
|
|
207
|
+
}}
|
|
208
|
+
loadingIcon={<MyLoadingIcon />}
|
|
209
|
+
loadingContent={(
|
|
210
|
+
<div>
|
|
211
|
+
<strong>Loading more products…</strong>
|
|
212
|
+
<span>Please wait.</span>
|
|
213
|
+
</div>
|
|
214
|
+
)}
|
|
215
|
+
/>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Use `contentMode: 'replace'` when accessible `loadingContent` should be the only visible bucket content; Core hides the icon and message regions. If no accessible replacement is supplied, Core retains a “Loading…” fallback. In append mode, `loadingIcon` is decorative and does not affect `arrowIcon`; `loadingContent` is independent of `items`. React keeps both custom nodes mounted in the light DOM while busy UI is hidden, so start expensive work only from the request callback or explicit application state.
|
|
219
|
+
|
|
220
|
+
`minDisplayTime` is a presentation policy for the busy bucket, not a request delay. Request acceptance, pagination state, and `aria-busy` update as soon as the request completes. The dedicated `Searching...` view remains unchanged and is not replaced by these props.
|
|
221
|
+
|
|
222
|
+
### Latest-chip auto-scroll (React 1.12.0 candidate; Issue #100)
|
|
223
|
+
|
|
224
|
+
In horizontal multi-select mode, `multiSelectDisplay.scrollToLatestChip` reveals a newly selected chip. It is opt-in and respects reduced-motion preferences. This behavior requires the pending Core `1.17.0` release; the adapter versions listed in the [web release checklist](../../docs/releases/WEB-1.17.0-RELEASE.md) are not yet on npm.
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
<Select
|
|
228
|
+
items={items}
|
|
229
|
+
multiple
|
|
230
|
+
multiSelectDisplay={{
|
|
231
|
+
mode: 'horizontal',
|
|
232
|
+
overflowX: 'auto',
|
|
233
|
+
scrollToLatestChip: true,
|
|
234
|
+
scrollToLatestChipBehavior: 'smooth',
|
|
235
|
+
}}
|
|
236
|
+
/>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Custom empty-state renderer (React 1.12.0 candidate; Issue #93)
|
|
240
|
+
|
|
241
|
+
`emptyStateRenderer` receives Core's readonly `{ query, reason }` context only while a terminal empty state is active. React renders its result in Core's native `empty-state` slot; omit the prop to keep the built-in fallback. `onEmptyStateChange` receives the new context and receives `null` when the empty state clears. The imperative handle also exposes `getEmptyStateContext()`.
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<Select
|
|
245
|
+
items={items}
|
|
246
|
+
searchable
|
|
247
|
+
emptyStateRenderer={({ query, reason }) => (
|
|
248
|
+
<div role="status">
|
|
249
|
+
<EmptyResultsIcon aria-hidden="true" />
|
|
250
|
+
<span>{reason === 'no-options' ? 'No options yet' : `No results for “${query}”`}</span>
|
|
251
|
+
</div>
|
|
252
|
+
)}
|
|
253
|
+
onEmptyStateChange={(context) => console.log('Empty state:', context)}
|
|
254
|
+
/>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
This is a presentation API; it does not change the behavior of `items`, acknowledged request completion, or selection.
|
|
258
|
+
|
|
187
259
|
## Infinite Render Loop: Root-Cause Review (No External Dependencies)
|
|
188
260
|
|
|
189
261
|
If you see `Maximum update depth exceeded`, follow this checklist before shipping:
|
|
@@ -1537,6 +1609,28 @@ You can replace the default chip remove icon with the `removeButtonIcon` prop:
|
|
|
1537
1609
|
|
|
1538
1610
|
Markup strings are supported too, so inline SVG icons work.
|
|
1539
1611
|
|
|
1612
|
+
React components are also supported, including generated icon components:
|
|
1613
|
+
|
|
1614
|
+
```tsx
|
|
1615
|
+
import TrashIcon from '@/generated/icons/Trash.icon';
|
|
1616
|
+
|
|
1617
|
+
<Select
|
|
1618
|
+
items={items}
|
|
1619
|
+
multiple
|
|
1620
|
+
defaultValue={['one']}
|
|
1621
|
+
removeButtonIcon={<TrashIcon />}
|
|
1622
|
+
/>
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
The React node is displayed inside Core's existing remove buttons in selected
|
|
1626
|
+
chips and selected dropdown options. Remove behavior, accessibility labels, and
|
|
1627
|
+
`chip-remove` / `chip-remove-icon` parts remain Core-owned. Strings still
|
|
1628
|
+
render as the legacy text or inline SVG markup. The prop supports React nodes,
|
|
1629
|
+
**not** a component function passed directly: use `<TrashIcon />`, not
|
|
1630
|
+
`TrashIcon`. When `config.selection.removeButtonIcon` is explicitly
|
|
1631
|
+
supplied, that Core string configuration takes precedence. React nodes are
|
|
1632
|
+
supported by the React adapter only, not Core or other framework adapters.
|
|
1633
|
+
|
|
1540
1634
|
To style the icon separately from the round remove button, use the host `style` prop with these tokens:
|
|
1541
1635
|
|
|
1542
1636
|
- `--select-badge-remove-icon-size`
|
|
@@ -1753,6 +1847,46 @@ interface SelectHandle {
|
|
|
1753
1847
|
}
|
|
1754
1848
|
```
|
|
1755
1849
|
|
|
1850
|
+
## Dropdown animation controls (Core 1.12.0)
|
|
1851
|
+
|
|
1852
|
+
React consumers can customize entry and exit animations through inherited Core CSS variables, without a new React prop:
|
|
1853
|
+
|
|
1854
|
+
```tsx
|
|
1855
|
+
<Select items={items} className="animated-select" />
|
|
1856
|
+
```
|
|
1857
|
+
|
|
1858
|
+
```css
|
|
1859
|
+
enhanced-select.animated-select {
|
|
1860
|
+
--select-dropdown-animation: dropdownEnter 250ms ease-out forwards;
|
|
1861
|
+
--select-dropdown-exit-animation: dropdownExit 180ms ease-in forwards;
|
|
1862
|
+
--select-dropdown-exit-to-opacity: 0;
|
|
1863
|
+
--select-dropdown-exit-to-transform: translateY(-8px) scale(0.98);
|
|
1864
|
+
--select-dropdown-top-exit-to-transform: translateY(8px) scale(0.98);
|
|
1865
|
+
}
|
|
1866
|
+
```
|
|
1867
|
+
|
|
1868
|
+
Set either animation to `none` to disable it. The close event and ARIA close immediately, while the visual dropdown becomes inert and exits. Reopening cancels an unfinished exit; reduced-motion preferences are respected. Core `1.12.0` is available on npm, and React `1.11.0` declares `@smilodon/core: ^1.11.0`, which accepts it. See [engineering notes](../../docs/architecture/DROPDOWN-EXIT-ANIMATION.md).
|
|
1869
|
+
|
|
1870
|
+
### Custom active classes — Issue #82 (Core)
|
|
1871
|
+
|
|
1872
|
+
When rendering custom option content, set `classMap.active` to the class names used by your application's active-state styles. Core now removes both legacy `active`/`sm-active` aliases and previously configured active classes as focus moves; an inactive option no longer matches `.option.active` accidentally.
|
|
1873
|
+
|
|
1874
|
+
```tsx
|
|
1875
|
+
<Select
|
|
1876
|
+
items={items}
|
|
1877
|
+
customRenderer={(item) => <span>{item.label}</span>}
|
|
1878
|
+
classMap={{ active: "my-option-active", selected: "my-option-selected" }}
|
|
1879
|
+
/>
|
|
1880
|
+
```
|
|
1881
|
+
|
|
1882
|
+
The option's `data-sm-state`, `aria-selected`, and classes reflect independent active/selected semantics. The fix is in Core, not in React's renderer. See [Issue #82](https://github.com/navidrezadoost/Smilodon/issues/82) and the [Core rendering guide](../core/README.md#active-state-on-custom-option-roots).
|
|
1883
|
+
|
|
1884
|
+
### Acknowledged pagination on React rerenders — Issue #85 (unreleased)
|
|
1885
|
+
|
|
1886
|
+
The reported local fix for [Issue #85](https://github.com/navidrezadoost/Smilodon/issues/85) is qualified **but not yet pushed, merged, or published**. In acknowledged loading, React's `items` prop can supply the initial page while Core accepts cumulative pages using `completeDataRequest()`. Equivalent or newly allocated `config`, `multiSelectDisplay`, and `disabledOptionBehavior` objects must not force Core to revert its accepted cumulative snapshot to the initial `items`.
|
|
1887
|
+
|
|
1888
|
+
The pending fix moves `items`/`groupedItems` synchronization into one identity-guarded effect, independent of presentation configuration, and applies uncontrolled `defaultValue` after item registration. New `items` or `groupedItems` identities still represent deliberate updates; `setItems()` alone is not an acknowledged coordinator reset. Keep input references stable where the input is unchanged, complete requests with their exact request IDs and generations, and consult the final release notes before expecting this fix in published packages.
|
|
1889
|
+
|
|
1756
1890
|
## Styling
|
|
1757
1891
|
|
|
1758
1892
|
The component uses Shadow DOM for style encapsulation. You can customize it using CSS custom properties:
|
package/dist/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
26
26
|
const jsxRuntime = require("react/jsx-runtime");
|
|
27
27
|
const React = require("react");
|
|
28
28
|
const client = require("react-dom/client");
|
|
29
|
+
const reactDom = require("react-dom");
|
|
29
30
|
const core = require("@smilodon/core");
|
|
30
31
|
const DEFAULT_DATA_LOADING_CONFIG = {
|
|
31
32
|
protocol: "legacy",
|
|
@@ -49,7 +50,7 @@ function composeBusyToken(consumerValue, externalBusy) {
|
|
|
49
50
|
return consumerValue;
|
|
50
51
|
}
|
|
51
52
|
const Select = React.forwardRef((props, ref) => {
|
|
52
|
-
var _a, _b;
|
|
53
|
+
var _a, _b, _c;
|
|
53
54
|
const {
|
|
54
55
|
items = [],
|
|
55
56
|
groupedItems,
|
|
@@ -74,6 +75,9 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
74
75
|
config: coreConfig,
|
|
75
76
|
removeButtonIcon,
|
|
76
77
|
arrowIcon,
|
|
78
|
+
loadingIcon,
|
|
79
|
+
loadingContent,
|
|
80
|
+
emptyStateRenderer,
|
|
77
81
|
disabledOptionBehavior,
|
|
78
82
|
showSelectedIndicator = true,
|
|
79
83
|
toggleOnTriggerClick = true,
|
|
@@ -101,6 +105,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
101
105
|
onDataRequestCancel,
|
|
102
106
|
onDataProjection,
|
|
103
107
|
onDataLoadingConfigError,
|
|
108
|
+
onEmptyStateChange,
|
|
104
109
|
trackingEnabled = false,
|
|
105
110
|
trackEvents = true,
|
|
106
111
|
trackStyling = true,
|
|
@@ -142,6 +147,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
142
147
|
onDataRequestCancel,
|
|
143
148
|
onDataProjection,
|
|
144
149
|
onDataLoadingConfigError,
|
|
150
|
+
onEmptyStateChange,
|
|
145
151
|
isControlled,
|
|
146
152
|
multiple
|
|
147
153
|
});
|
|
@@ -157,6 +163,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
157
163
|
onDataRequestCancel,
|
|
158
164
|
onDataProjection,
|
|
159
165
|
onDataLoadingConfigError,
|
|
166
|
+
onEmptyStateChange,
|
|
160
167
|
isControlled,
|
|
161
168
|
multiple
|
|
162
169
|
};
|
|
@@ -303,7 +310,10 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
303
310
|
reactRendererCache.current.clear();
|
|
304
311
|
}, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
|
|
305
312
|
const [isElementReady, setIsElementReady] = React.useState(false);
|
|
306
|
-
const
|
|
313
|
+
const [emptyStateContext, setEmptyStateContext] = React.useState(null);
|
|
314
|
+
const [removeIconTargets, setRemoveIconTargets] = React.useState([]);
|
|
315
|
+
const shouldPortalRemoveIcon = multiple && removeButtonIcon != null && typeof removeButtonIcon !== "string" && typeof removeButtonIcon !== "boolean" && ((_a = coreConfig == null ? void 0 : coreConfig.selection) == null ? void 0 : _a.removeButtonIcon) === void 0;
|
|
316
|
+
const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
|
|
307
317
|
const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
|
|
308
318
|
const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
|
|
309
319
|
const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
|
|
@@ -410,7 +420,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
410
420
|
},
|
|
411
421
|
[markUnusable, syncHostBusy]
|
|
412
422
|
);
|
|
413
|
-
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((
|
|
423
|
+
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_c = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _c.protocol) === "acknowledged";
|
|
414
424
|
const qualifyAcknowledgedElement = React.useCallback(() => {
|
|
415
425
|
const element = elementRef.current;
|
|
416
426
|
const module2 = coreModuleRef.current;
|
|
@@ -428,16 +438,17 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
428
438
|
return true;
|
|
429
439
|
}, [markUnusable]);
|
|
430
440
|
const subscribeToCoreEvents = React.useCallback((element) => {
|
|
441
|
+
var _a2;
|
|
431
442
|
const currentSubscription = activeListenersRef.current;
|
|
432
443
|
if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
|
|
433
444
|
currentSubscription == null ? void 0 : currentSubscription.dispose();
|
|
434
445
|
const handleSelect = (event) => {
|
|
435
|
-
var
|
|
446
|
+
var _a3, _b2;
|
|
436
447
|
const detail = event.detail;
|
|
437
|
-
(_b2 = (
|
|
448
|
+
(_b2 = (_a3 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a3, detail.item, detail.index);
|
|
438
449
|
};
|
|
439
450
|
const handleChange = (event) => {
|
|
440
|
-
var
|
|
451
|
+
var _a3;
|
|
441
452
|
const { selectedItems, selectedValues } = event.detail;
|
|
442
453
|
const callbacks = callbackStateRef.current;
|
|
443
454
|
const values = selectedValues;
|
|
@@ -446,19 +457,19 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
446
457
|
if (!callbacks.isControlled) {
|
|
447
458
|
setInternalValue(callbacks.multiple ? values : nextSingleValue);
|
|
448
459
|
}
|
|
449
|
-
(
|
|
460
|
+
(_a3 = callbacks.onChange) == null ? void 0 : _a3.call(
|
|
450
461
|
callbacks,
|
|
451
462
|
callbacks.multiple ? values : nextSingleValue,
|
|
452
463
|
selectedItems
|
|
453
464
|
);
|
|
454
465
|
};
|
|
455
466
|
const handleOpen = () => {
|
|
456
|
-
var
|
|
457
|
-
return (_b2 = (
|
|
467
|
+
var _a3, _b2;
|
|
468
|
+
return (_b2 = (_a3 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a3);
|
|
458
469
|
};
|
|
459
470
|
const handleClose = () => {
|
|
460
|
-
var
|
|
461
|
-
return (_b2 = (
|
|
471
|
+
var _a3, _b2;
|
|
472
|
+
return (_b2 = (_a3 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a3);
|
|
462
473
|
};
|
|
463
474
|
const handleSearch = (event) => {
|
|
464
475
|
const { query, results, count, request } = event.detail;
|
|
@@ -475,40 +486,46 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
475
486
|
else callback(page);
|
|
476
487
|
};
|
|
477
488
|
const handleClear = (event) => {
|
|
478
|
-
var
|
|
489
|
+
var _a3, _b2;
|
|
479
490
|
const { clearedSelection, clearedSearch } = event.detail;
|
|
480
|
-
(_b2 = (
|
|
491
|
+
(_b2 = (_a3 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a3, { clearedSelection, clearedSearch });
|
|
481
492
|
};
|
|
482
493
|
const handleDiagnostic = (event) => {
|
|
483
|
-
var
|
|
484
|
-
(_b2 = (
|
|
485
|
-
|
|
494
|
+
var _a3, _b2;
|
|
495
|
+
(_b2 = (_a3 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
|
|
496
|
+
_a3,
|
|
486
497
|
event.detail
|
|
487
498
|
);
|
|
488
499
|
};
|
|
489
500
|
const handleDataRequestCancel = (event) => {
|
|
490
|
-
var
|
|
491
|
-
(_b2 = (
|
|
492
|
-
|
|
501
|
+
var _a3, _b2;
|
|
502
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
|
|
503
|
+
_a3,
|
|
493
504
|
event.detail
|
|
494
505
|
);
|
|
495
506
|
};
|
|
496
507
|
const handleDataProjection = (event) => {
|
|
497
|
-
var
|
|
498
|
-
(_b2 = (
|
|
499
|
-
|
|
508
|
+
var _a3, _b2;
|
|
509
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
|
|
510
|
+
_a3,
|
|
500
511
|
event.detail
|
|
501
512
|
);
|
|
502
513
|
};
|
|
503
514
|
const handleDataLoadingConfigError = (event) => {
|
|
504
|
-
var
|
|
515
|
+
var _a3, _b2;
|
|
505
516
|
const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
|
|
506
517
|
if (activeUpdate) activeUpdate.sawConfigError = true;
|
|
507
|
-
(_b2 = (
|
|
508
|
-
|
|
518
|
+
(_b2 = (_a3 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
|
|
519
|
+
_a3,
|
|
509
520
|
event.detail
|
|
510
521
|
);
|
|
511
522
|
};
|
|
523
|
+
const handleEmptyStateChange = (event) => {
|
|
524
|
+
var _a3, _b2;
|
|
525
|
+
const context = event.detail.context;
|
|
526
|
+
setEmptyStateContext(context);
|
|
527
|
+
(_b2 = (_a3 = callbackStateRef.current).onEmptyStateChange) == null ? void 0 : _b2.call(_a3, context);
|
|
528
|
+
};
|
|
512
529
|
const listeners = [
|
|
513
530
|
["select", handleSelect],
|
|
514
531
|
["change", handleChange],
|
|
@@ -520,14 +537,18 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
520
537
|
["diagnostic", handleDiagnostic],
|
|
521
538
|
["dataRequestCancel", handleDataRequestCancel],
|
|
522
539
|
["dataProjection", handleDataProjection],
|
|
523
|
-
["dataLoadingConfigError", handleDataLoadingConfigError]
|
|
540
|
+
["dataLoadingConfigError", handleDataLoadingConfigError],
|
|
541
|
+
["emptyStateChange", handleEmptyStateChange]
|
|
524
542
|
];
|
|
525
543
|
for (const [name, listener] of listeners) {
|
|
526
544
|
element.addEventListener(name, listener);
|
|
527
545
|
}
|
|
546
|
+
setEmptyStateContext(
|
|
547
|
+
((_a2 = element.getEmptyStateContext) == null ? void 0 : _a2.call(element)) ?? null
|
|
548
|
+
);
|
|
528
549
|
const dispose = () => {
|
|
529
|
-
var
|
|
530
|
-
if (((
|
|
550
|
+
var _a3;
|
|
551
|
+
if (((_a3 = activeListenersRef.current) == null ? void 0 : _a3.dispose) === dispose) {
|
|
531
552
|
activeListenersRef.current = null;
|
|
532
553
|
}
|
|
533
554
|
for (const [name, listener] of listeners) {
|
|
@@ -644,7 +665,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
644
665
|
...selectionConfig,
|
|
645
666
|
mode: multiple ? "multi" : "single",
|
|
646
667
|
maxSelections,
|
|
647
|
-
removeButtonIcon,
|
|
668
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
648
669
|
disabledOptionBehavior,
|
|
649
670
|
showSelectedIndicator,
|
|
650
671
|
toggleOnTriggerClick
|
|
@@ -797,7 +818,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
797
818
|
...selectionConfig,
|
|
798
819
|
mode: multiple ? "multi" : "single",
|
|
799
820
|
maxSelections,
|
|
800
|
-
removeButtonIcon,
|
|
821
|
+
removeButtonIcon: typeof removeButtonIcon === "string" ? removeButtonIcon : void 0,
|
|
801
822
|
disabledOptionBehavior,
|
|
802
823
|
showSelectedIndicator,
|
|
803
824
|
toggleOnTriggerClick
|
|
@@ -874,6 +895,48 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
874
895
|
isElementUsable,
|
|
875
896
|
applyInstanceConfig
|
|
876
897
|
]);
|
|
898
|
+
React.useEffect(() => {
|
|
899
|
+
const element = elementRef.current;
|
|
900
|
+
const shadow = element == null ? void 0 : element.shadowRoot;
|
|
901
|
+
if (!isElementUsable || !shouldPortalRemoveIcon || !shadow) {
|
|
902
|
+
setRemoveIconTargets((previous) => previous.length ? [] : previous);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
const observed = /* @__PURE__ */ new Set();
|
|
906
|
+
let currentTargets = [];
|
|
907
|
+
let disposed = false;
|
|
908
|
+
const observer = new MutationObserver(() => refresh());
|
|
909
|
+
const refresh = () => {
|
|
910
|
+
if (disposed) return;
|
|
911
|
+
const optionRoots = Array.from(shadow.querySelectorAll("select-option")).map((option) => option.shadowRoot).filter((root) => root !== null);
|
|
912
|
+
const roots = [shadow, ...optionRoots];
|
|
913
|
+
if (roots.length !== observed.size || roots.some((root) => !observed.has(root))) {
|
|
914
|
+
observer.disconnect();
|
|
915
|
+
observed.clear();
|
|
916
|
+
for (const root of roots) {
|
|
917
|
+
observer.observe(root, { childList: true, subtree: true });
|
|
918
|
+
observed.add(root);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const targets = [
|
|
922
|
+
...Array.from(shadow.querySelectorAll('[part="chip-remove-icon"]')),
|
|
923
|
+
...optionRoots.flatMap(
|
|
924
|
+
(root) => Array.from(root.querySelectorAll('[part="chip-remove-icon"]'))
|
|
925
|
+
)
|
|
926
|
+
];
|
|
927
|
+
if (targets.length === currentTargets.length && targets.every((target, index) => target === currentTargets[index])) return;
|
|
928
|
+
for (const target of targets) {
|
|
929
|
+
if (!currentTargets.includes(target)) target.replaceChildren();
|
|
930
|
+
}
|
|
931
|
+
currentTargets = targets;
|
|
932
|
+
setRemoveIconTargets(targets);
|
|
933
|
+
};
|
|
934
|
+
refresh();
|
|
935
|
+
return () => {
|
|
936
|
+
disposed = true;
|
|
937
|
+
observer.disconnect();
|
|
938
|
+
};
|
|
939
|
+
}, [isElementUsable, shouldPortalRemoveIcon]);
|
|
877
940
|
React.useEffect(() => {
|
|
878
941
|
const element = elementRef.current;
|
|
879
942
|
if (!element || !isElementUsable) return;
|
|
@@ -965,6 +1028,10 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
965
1028
|
var _a2;
|
|
966
1029
|
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
|
|
967
1030
|
},
|
|
1031
|
+
getEmptyStateContext: () => {
|
|
1032
|
+
var _a2, _b2;
|
|
1033
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getEmptyStateContext) == null ? void 0 : _b2.call(_a2)) ?? null;
|
|
1034
|
+
},
|
|
968
1035
|
setItems: (items2) => {
|
|
969
1036
|
var _a2;
|
|
970
1037
|
(_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
|
|
@@ -1001,12 +1068,12 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
1001
1068
|
applyInstanceConfig(element, config);
|
|
1002
1069
|
},
|
|
1003
1070
|
getDataLoadingState: () => {
|
|
1004
|
-
var _a2, _b2,
|
|
1071
|
+
var _a2, _b2, _c2;
|
|
1005
1072
|
const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
|
|
1006
1073
|
if (snapshot) return snapshot;
|
|
1007
1074
|
return {
|
|
1008
1075
|
status: "idle",
|
|
1009
|
-
connected: Boolean((
|
|
1076
|
+
connected: Boolean((_c2 = elementRef.current) == null ? void 0 : _c2.isConnected),
|
|
1010
1077
|
busy: false,
|
|
1011
1078
|
projectionPending: false,
|
|
1012
1079
|
queryGeneration: 0,
|
|
@@ -1076,6 +1143,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
1076
1143
|
onChange
|
|
1077
1144
|
]);
|
|
1078
1145
|
const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
|
|
1146
|
+
const renderedEmptyState = emptyStateContext && emptyStateRenderer ? emptyStateRenderer(emptyStateContext) : null;
|
|
1079
1147
|
return React.createElement(
|
|
1080
1148
|
"enhanced-select",
|
|
1081
1149
|
{
|
|
@@ -1095,6 +1163,35 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
1095
1163
|
"aria-hidden": "true"
|
|
1096
1164
|
},
|
|
1097
1165
|
arrowIcon
|
|
1166
|
+
) : null,
|
|
1167
|
+
loadingIcon != null ? React.createElement(
|
|
1168
|
+
"span",
|
|
1169
|
+
{
|
|
1170
|
+
slot: "loading-icon",
|
|
1171
|
+
className: "smilodon-loading-icon",
|
|
1172
|
+
"aria-hidden": "true"
|
|
1173
|
+
},
|
|
1174
|
+
loadingIcon
|
|
1175
|
+
) : null,
|
|
1176
|
+
loadingContent != null ? React.createElement(
|
|
1177
|
+
"div",
|
|
1178
|
+
{
|
|
1179
|
+
slot: "loading-content",
|
|
1180
|
+
className: "smilodon-loading-content"
|
|
1181
|
+
},
|
|
1182
|
+
loadingContent
|
|
1183
|
+
) : null,
|
|
1184
|
+
renderedEmptyState != null && typeof renderedEmptyState !== "boolean" ? React.createElement(
|
|
1185
|
+
"div",
|
|
1186
|
+
{ slot: "empty-state", className: "smilodon-empty-state" },
|
|
1187
|
+
renderedEmptyState
|
|
1188
|
+
) : null,
|
|
1189
|
+
shouldPortalRemoveIcon ? removeIconTargets.map(
|
|
1190
|
+
(target, index) => reactDom.createPortal(
|
|
1191
|
+
React.createElement("span", { "aria-hidden": "true" }, removeButtonIcon),
|
|
1192
|
+
target,
|
|
1193
|
+
index
|
|
1194
|
+
)
|
|
1098
1195
|
) : null
|
|
1099
1196
|
);
|
|
1100
1197
|
});
|