@smilodon/react 1.10.0 → 1.11.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 +2 -0
- package/README.md +165 -0
- package/dist/index.cjs +542 -150
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +543 -151
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +19 -7
- package/dist/types/Select.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/COMPLETE-GUIDE.md
CHANGED
|
@@ -141,6 +141,7 @@ interface SelectProps {
|
|
|
141
141
|
// Styling
|
|
142
142
|
className?: string;
|
|
143
143
|
style?: React.CSSProperties;
|
|
144
|
+
arrowIcon?: React.ReactNode;
|
|
144
145
|
|
|
145
146
|
// Advanced
|
|
146
147
|
virtualized?: boolean;
|
|
@@ -168,6 +169,7 @@ interface SelectProps {
|
|
|
168
169
|
| `estimatedItemHeight` | `number` | `48` | Passed to core config for the guarded viewport-windowing test path; it does not affect public chunk rendering |
|
|
169
170
|
| `className` | `string` | `undefined` | CSS class name |
|
|
170
171
|
| `style` | `React.CSSProperties` | `undefined` | Inline styles (CSS variables) |
|
|
172
|
+
| `arrowIcon` | `React.ReactNode` | `undefined` | Decorative content for the native arrow slot; custom content does not rotate automatically |
|
|
171
173
|
| `virtualized` | `boolean` | `false` | Enable incremental chunk rendering for large flat lists; not viewport windowing |
|
|
172
174
|
| `customRenderer` | `function` | `undefined` | Custom option renderer |
|
|
173
175
|
| `onOpen` | `() => void` | `undefined` | Called when dropdown opens |
|
package/README.md
CHANGED
|
@@ -45,6 +45,145 @@ The Quick Start examples are self-contained. Longer feature snippets below are f
|
|
|
45
45
|
|
|
46
46
|
In focused JSX examples, `items`, `groups`, `bigItems`, and similar values are component-local application data unless the snippet declares them; imports and hook state should be added in the containing component as needed.
|
|
47
47
|
|
|
48
|
+
## Acknowledged data loading (Phase 2F-D development candidate)
|
|
49
|
+
|
|
50
|
+
The current local Phase 2F-D candidate integrates the core acknowledged-loading facade with the React adapter. It is not part of the published `1.10.0` package, and Firefox/WebKit certification, independent review, and remaining contract coverage are pending. Treat the following as implementation guidance for this candidate, not a release-readiness or cross-browser compatibility claim.
|
|
51
|
+
|
|
52
|
+
Acknowledged loading is opt-in through per-instance `config.dataLoading`; there is no global acknowledged-loading default. If the config is omitted, the adapter keeps the legacy protocol and existing callback behavior. The host owns fetch, cancellation, and retry policy; the core owns request identity, stale-completion rejection, canonical acceptance, and subsequent DOM projection.
|
|
53
|
+
|
|
54
|
+
### Remote cursor search with cancellation and failures
|
|
55
|
+
|
|
56
|
+
This illustrative component handles remote search and load-more requests through one host function. It sends the exact query (including an empty string), passes page/cursor position and fetch limit to the server, echoes request identity on completion, aborts cancelled requests, and reports failures without an automatic retry.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
import { useEffect, useRef } from 'react'
|
|
60
|
+
import {
|
|
61
|
+
Select,
|
|
62
|
+
type DataRequest,
|
|
63
|
+
type DataRequestCompletion,
|
|
64
|
+
type SelectHandle,
|
|
65
|
+
type SelectItem,
|
|
66
|
+
} from '@smilodon/react'
|
|
67
|
+
|
|
68
|
+
type SearchPage = {
|
|
69
|
+
items: SelectItem[]
|
|
70
|
+
hasMore: boolean
|
|
71
|
+
nextCursor?: string | number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function RemoteSelect() {
|
|
75
|
+
const selectRef = useRef<SelectHandle>(null)
|
|
76
|
+
const controllers = useRef(new Map<string, AbortController>())
|
|
77
|
+
|
|
78
|
+
useEffect(() => () => {
|
|
79
|
+
for (const controller of controllers.current.values()) controller.abort()
|
|
80
|
+
controllers.current.clear()
|
|
81
|
+
}, [])
|
|
82
|
+
|
|
83
|
+
async function load(request: DataRequest) {
|
|
84
|
+
const controller = new AbortController()
|
|
85
|
+
controllers.current.set(request.requestId, controller)
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
const params = new URLSearchParams({ q: request.query, limit: String(request.fetchLimit) })
|
|
89
|
+
if (request.position.mode === 'page') {
|
|
90
|
+
params.set('page', String(request.position.page))
|
|
91
|
+
} else if (request.position.cursor !== undefined) {
|
|
92
|
+
params.set('cursor', String(request.position.cursor))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const response = await fetch(`/api/options?${params}`, { signal: controller.signal })
|
|
96
|
+
if (!response.ok) throw new Error(`Search failed: ${response.status}`)
|
|
97
|
+
|
|
98
|
+
const page = await response.json() as SearchPage
|
|
99
|
+
if (!Array.isArray(page.items) || typeof page.hasMore !== 'boolean') {
|
|
100
|
+
throw new Error('The options endpoint returned an invalid page.')
|
|
101
|
+
}
|
|
102
|
+
if (request.position.mode === 'cursor' && page.hasMore && page.nextCursor === undefined) {
|
|
103
|
+
throw new Error('A non-terminal cursor page must include nextCursor.')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const completion: DataRequestCompletion = page.hasMore
|
|
107
|
+
? {
|
|
108
|
+
requestId: request.requestId,
|
|
109
|
+
queryGeneration: request.queryGeneration,
|
|
110
|
+
status: 'succeeded',
|
|
111
|
+
items: page.items,
|
|
112
|
+
hasMore: true,
|
|
113
|
+
...(page.nextCursor === undefined ? {} : { nextCursor: page.nextCursor }),
|
|
114
|
+
}
|
|
115
|
+
: {
|
|
116
|
+
requestId: request.requestId,
|
|
117
|
+
queryGeneration: request.queryGeneration,
|
|
118
|
+
status: 'exhausted',
|
|
119
|
+
items: page.items,
|
|
120
|
+
hasMore: false,
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const result = selectRef.current?.completeDataRequest(completion)
|
|
124
|
+
if (result !== 'accepted') {
|
|
125
|
+
// Stale, unknown, invalid, or resource-limited completions are not projected.
|
|
126
|
+
console.info('Response not accepted:', result)
|
|
127
|
+
}
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (!controller.signal.aborted) {
|
|
130
|
+
selectRef.current?.completeDataRequest({
|
|
131
|
+
requestId: request.requestId,
|
|
132
|
+
queryGeneration: request.queryGeneration,
|
|
133
|
+
status: 'failed',
|
|
134
|
+
error: { message: error instanceof Error ? error.message : String(error), retryable: true },
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
} finally {
|
|
138
|
+
controllers.current.delete(request.requestId)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Select
|
|
144
|
+
ref={selectRef}
|
|
145
|
+
searchable
|
|
146
|
+
config={{
|
|
147
|
+
dataLoading: {
|
|
148
|
+
protocol: 'acknowledged',
|
|
149
|
+
searchMode: 'remote',
|
|
150
|
+
paginationMode: 'cursor',
|
|
151
|
+
fetchLimit: 25,
|
|
152
|
+
},
|
|
153
|
+
}}
|
|
154
|
+
onSearch={(_query, _results, _count, request) => {
|
|
155
|
+
if (request) void load(request)
|
|
156
|
+
}}
|
|
157
|
+
onLoadMore={(_page, request) => {
|
|
158
|
+
if (request) void load(request)
|
|
159
|
+
}}
|
|
160
|
+
onDataRequestCancel={({ requestId }) => {
|
|
161
|
+
controllers.current.get(requestId)?.abort()
|
|
162
|
+
controllers.current.delete(requestId)
|
|
163
|
+
}}
|
|
164
|
+
onDataProjection={(detail) => {
|
|
165
|
+
if (detail.status === 'failed') console.error(detail.error.message)
|
|
166
|
+
}}
|
|
167
|
+
onDataLoadingConfigError={({ issues }) => {
|
|
168
|
+
console.error('Rejected data-loading config:', issues)
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The coordinator rejects stale responses by request ID and query generation; the host should still abort cancelled network work to save resources. An accepted response does not mean projection is finished: observe `onDataProjection` for the projection result. A failed request remains failed until a new explicit request is made; the sample deliberately does not retry automatically.
|
|
176
|
+
|
|
177
|
+
### Other useful scenarios
|
|
178
|
+
|
|
179
|
+
- **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
|
+
- **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
|
+
- **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.
|
|
182
|
+
- **React Strict Mode:** the adapter owns readiness and initial request setup. Do not call a second manual request from an effect; keep each host response keyed by the request ID supplied in the callback. Browser certification for this scenario remains pending outside the reported Chromium run.
|
|
183
|
+
- **External busy state:** the React `loading` prop and consumer `aria-busy` remain presentation inputs. The adapter composes them with core busy state; the acknowledged request snapshot's `busy` does not include external presentation loading.
|
|
184
|
+
- **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
|
+
- **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
|
+
|
|
48
187
|
## Infinite Render Loop: Root-Cause Review (No External Dependencies)
|
|
49
188
|
|
|
50
189
|
If you see `Maximum update depth exceeded`, follow this checklist before shipping:
|
|
@@ -1264,6 +1403,7 @@ function OptimizedExample() {
|
|
|
1264
1403
|
| `estimatedItemHeight` | `number` | `48` | Exposed estimate used only by the guarded viewport-windowing test path; not a production tuning control |
|
|
1265
1404
|
| `maxSelections` | `number` | - | Max selections (multi-select) |
|
|
1266
1405
|
| `toggleOnTriggerClick` | `boolean` | `true` | Allow repeated trigger clicks to toggle the dropdown |
|
|
1406
|
+
| `arrowIcon` | `React.ReactNode` | - | Decorative custom arrow content; defaults to the built-in chevron and does not rotate automatically |
|
|
1267
1407
|
| `placement` | `string` | `"bottom-start"` | Dropdown placement |
|
|
1268
1408
|
| `className` | `string` | - | Custom CSS class |
|
|
1269
1409
|
| `style` | `CSSProperties` | - | Inline styles |
|
|
@@ -1284,6 +1424,31 @@ function OptimizedExample() {
|
|
|
1284
1424
|
| `creatable` | `boolean` | `false` | Allow creating new options |
|
|
1285
1425
|
| `onCreate` | `(label) => void` | - | Create option callback |
|
|
1286
1426
|
|
|
1427
|
+
### Custom arrow icon
|
|
1428
|
+
|
|
1429
|
+
Available in `@smilodon/react@1.11.0` with `@smilodon/core@1.11.0`, pass any React node as `arrowIcon`. It is rendered in the native `arrow` slot and marked decorative; Core continues to own pointer and open/close behavior. The built-in SVG remains the fallback when the prop is omitted or `null`. Custom content is not automatically rotated; use the host's `data-open` attribute if it should rotate:
|
|
1430
|
+
|
|
1431
|
+
```tsx
|
|
1432
|
+
<Select
|
|
1433
|
+
className="custom-arrow-select"
|
|
1434
|
+
items={items}
|
|
1435
|
+
arrowIcon={<MyChevron />}
|
|
1436
|
+
/>
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
```css
|
|
1440
|
+
.custom-arrow-select > .smilodon-custom-arrow {
|
|
1441
|
+
display: inline-flex;
|
|
1442
|
+
transition: transform 180ms ease;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
.custom-arrow-select[data-open="true"] > .smilodon-custom-arrow {
|
|
1446
|
+
transform: rotate(180deg);
|
|
1447
|
+
}
|
|
1448
|
+
```
|
|
1449
|
+
|
|
1450
|
+
The default arrow hover background is suppressed while custom arrow content is assigned. Custom icon color and transform are not set by Core.
|
|
1451
|
+
|
|
1287
1452
|
### Multi-select chip styling
|
|
1288
1453
|
|
|
1289
1454
|
Selected chips in multi-select mode use softer default pill styles and remain fully customizable. Target them with `::part(chip)`, `::part(chip-label)`, `::part(chip-remove)`, and `::part(chip-remove-icon)`, or override CSS variables such as `--select-badge-bg`, `--select-badge-border`, `--select-badge-color`, `--select-badge-shadow`, `--select-badge-width`, `--select-badge-height`, `--select-badge-remove-size`, `--select-badge-remove-icon-size`, and `--select-multi-input-min-width`.
|