@speles7172/controls 0.1.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/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/SearchableMultiSelect.d.ts +48 -0
- package/dist/SearchableMultiSelect.d.ts.map +1 -0
- package/dist/SearchableMultiSelect.js +183 -0
- package/dist/SearchableMultiSelect.js.map +1 -0
- package/dist/SearchableSelect.d.ts +19 -0
- package/dist/SearchableSelect.d.ts.map +1 -0
- package/dist/SearchableSelect.js +17 -0
- package/dist/SearchableSelect.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +369 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/useOptionSelect.d.ts +126 -0
- package/dist/useOptionSelect.d.ts.map +1 -0
- package/dist/useOptionSelect.js +299 -0
- package/dist/useOptionSelect.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { DEFAULT_LIMIT, matchOptions } from '@speles7172/controls-client/core';
|
|
3
|
+
/**
|
|
4
|
+
* A stable key for a list of values, for effect dependencies.
|
|
5
|
+
*
|
|
6
|
+
* `JSON.stringify` rather than a join, because a join needs a separator that no
|
|
7
|
+
* value can contain and there is no such character — join on a comma and
|
|
8
|
+
* `['a,b']` keys the same as `['a', 'b']`, so a change of selection goes
|
|
9
|
+
* unnoticed. Stringifying escapes the ambiguity away instead of betting against
|
|
10
|
+
* it.
|
|
11
|
+
*/
|
|
12
|
+
function keyOf(values) {
|
|
13
|
+
return JSON.stringify(values);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A searchable selection, without any markup.
|
|
17
|
+
*
|
|
18
|
+
* Split out for the same reason `useAuditConsole` is: an application with its
|
|
19
|
+
* own design system wants this state machine and none of the HTML below it.
|
|
20
|
+
* Everything hard lives here — the debounce, discarding stale responses,
|
|
21
|
+
* paging, and turning selected values back into labels — and none of it is
|
|
22
|
+
* specific to how the thing looks.
|
|
23
|
+
*/
|
|
24
|
+
export function useOptionSelect(settings) {
|
|
25
|
+
const { transport, value, onChange, single = false, pageSize = DEFAULT_LIMIT, debounceMs = 200, minSearchLength = 0, maxSelected, allowCustomValue = false, clearable = true, disabled = false, } = settings;
|
|
26
|
+
const staticOptions = settings.options;
|
|
27
|
+
const isAsync = transport !== undefined;
|
|
28
|
+
const [open, setOpenState] = useState(false);
|
|
29
|
+
const [term, setTermState] = useState('');
|
|
30
|
+
const [appliedTerm, setAppliedTerm] = useState('');
|
|
31
|
+
const [loaded, setLoaded] = useState([]);
|
|
32
|
+
const [loadedMore, setLoadedMore] = useState(false);
|
|
33
|
+
const [status, setStatus] = useState('idle');
|
|
34
|
+
const [error, setError] = useState(null);
|
|
35
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
36
|
+
/** Labels learned from a `resolve` call, keyed by value. */
|
|
37
|
+
const [resolved, setResolved] = useState({});
|
|
38
|
+
/** How many of a *static* list to show — the local equivalent of paging. */
|
|
39
|
+
const [shownCount, setShownCount] = useState(pageSize);
|
|
40
|
+
// Every run gets a number. A response whose number is stale is discarded
|
|
41
|
+
// rather than rendered: without this, a slow search started at "a" lands
|
|
42
|
+
// after a fast one started at "acme" and silently replaces newer results.
|
|
43
|
+
const runId = useRef(0);
|
|
44
|
+
const mounted = useRef(true);
|
|
45
|
+
/** Values already sent to `resolve`, so a miss is not retried forever. */
|
|
46
|
+
const asked = useRef(new Set());
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
mounted.current = true;
|
|
49
|
+
return () => {
|
|
50
|
+
mounted.current = false;
|
|
51
|
+
runId.current += 1;
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
const valueKey = keyOf(value);
|
|
55
|
+
/** Everything whose label is known, from any source. */
|
|
56
|
+
const known = useMemo(() => {
|
|
57
|
+
const map = new Map();
|
|
58
|
+
for (const option of staticOptions ?? [])
|
|
59
|
+
map.set(option.value, option);
|
|
60
|
+
for (const option of loaded)
|
|
61
|
+
map.set(option.value, option);
|
|
62
|
+
for (const option of Object.values(resolved))
|
|
63
|
+
map.set(option.value, option);
|
|
64
|
+
return map;
|
|
65
|
+
}, [staticOptions, loaded, resolved]);
|
|
66
|
+
const run = useCallback(async (searchTerm, offset) => {
|
|
67
|
+
if (transport === undefined)
|
|
68
|
+
return;
|
|
69
|
+
const id = (runId.current += 1);
|
|
70
|
+
setStatus('loading');
|
|
71
|
+
setError(null);
|
|
72
|
+
try {
|
|
73
|
+
const page = await transport.search({ term: searchTerm, limit: pageSize, offset });
|
|
74
|
+
if (runId.current !== id || !mounted.current)
|
|
75
|
+
return;
|
|
76
|
+
// Appended for a "show more", replaced for a new search — the offset is
|
|
77
|
+
// what distinguishes them, so the caller cannot get it wrong.
|
|
78
|
+
setLoaded((current) => (offset === 0 ? page.options : [...current, ...page.options]));
|
|
79
|
+
setLoadedMore(page.hasMore);
|
|
80
|
+
setStatus('ready');
|
|
81
|
+
}
|
|
82
|
+
catch (thrown) {
|
|
83
|
+
if (runId.current !== id || !mounted.current)
|
|
84
|
+
return;
|
|
85
|
+
setError(thrown instanceof Error ? thrown.message : String(thrown));
|
|
86
|
+
setStatus('error');
|
|
87
|
+
}
|
|
88
|
+
}, [transport, pageSize]);
|
|
89
|
+
/**
|
|
90
|
+
* The debounce.
|
|
91
|
+
*
|
|
92
|
+
* Only for a transport. A static list has nothing to wait for, and delaying
|
|
93
|
+
* it by 200ms would make the cheap case feel worse than the expensive one.
|
|
94
|
+
*/
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!isAsync) {
|
|
97
|
+
setAppliedTerm(term);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!open)
|
|
101
|
+
return;
|
|
102
|
+
if (debounceMs <= 0) {
|
|
103
|
+
setAppliedTerm(term);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const timer = setTimeout(() => setAppliedTerm(term), debounceMs);
|
|
107
|
+
return () => clearTimeout(timer);
|
|
108
|
+
}, [term, open, isAsync, debounceMs]);
|
|
109
|
+
/** Search whenever the applied term changes, and when the control opens. */
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (!isAsync || !open)
|
|
112
|
+
return;
|
|
113
|
+
if (appliedTerm.trim().length < minSearchLength) {
|
|
114
|
+
setLoaded([]);
|
|
115
|
+
setLoadedMore(false);
|
|
116
|
+
setStatus('idle');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
void run(appliedTerm, 0);
|
|
120
|
+
}, [isAsync, open, appliedTerm, minSearchLength, run]);
|
|
121
|
+
/**
|
|
122
|
+
* Labels for values that are selected but not loaded.
|
|
123
|
+
*
|
|
124
|
+
* The half of a searchable control that is usually missing. A form reopened
|
|
125
|
+
* three months later holds ids and no labels, and none of them are in the
|
|
126
|
+
* first page of options.
|
|
127
|
+
*/
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const resolveValues = transport?.resolve;
|
|
130
|
+
if (resolveValues === undefined)
|
|
131
|
+
return;
|
|
132
|
+
const missing = value.filter((entry) => !known.has(entry) && !asked.current.has(entry));
|
|
133
|
+
if (missing.length === 0)
|
|
134
|
+
return;
|
|
135
|
+
for (const entry of missing)
|
|
136
|
+
asked.current.add(entry);
|
|
137
|
+
let cancelled = false;
|
|
138
|
+
void resolveValues(missing)
|
|
139
|
+
.then((options) => {
|
|
140
|
+
if (cancelled || !mounted.current)
|
|
141
|
+
return;
|
|
142
|
+
setResolved((current) => {
|
|
143
|
+
const next = { ...current };
|
|
144
|
+
for (const option of options)
|
|
145
|
+
next[option.value] = option;
|
|
146
|
+
return next;
|
|
147
|
+
});
|
|
148
|
+
})
|
|
149
|
+
// A label that will not load is not a reason to break the form: the
|
|
150
|
+
// control falls back to showing the value itself.
|
|
151
|
+
.catch(() => undefined);
|
|
152
|
+
return () => {
|
|
153
|
+
cancelled = true;
|
|
154
|
+
};
|
|
155
|
+
// `valueKey` rather than `value`: the prop is an array, so its identity
|
|
156
|
+
// changes on every render of the parent and the effect would re-run for
|
|
157
|
+
// nothing.
|
|
158
|
+
}, [transport, valueKey, known, value]);
|
|
159
|
+
/** The options to render. */
|
|
160
|
+
const options = useMemo(() => {
|
|
161
|
+
const listed = isAsync
|
|
162
|
+
? loaded
|
|
163
|
+
: // A static list is matched and ranked here by the same rules the SQL
|
|
164
|
+
// side uses, and paged locally so a list of five thousand does not
|
|
165
|
+
// become five thousand DOM nodes.
|
|
166
|
+
matchOptions(staticOptions ?? [], appliedTerm, { keep: value }).slice(0, shownCount);
|
|
167
|
+
if (!allowCustomValue)
|
|
168
|
+
return listed;
|
|
169
|
+
const custom = appliedTerm.trim();
|
|
170
|
+
// Nothing to offer when the term is empty, and nothing to *add* when it is
|
|
171
|
+
// already one of the options — a duplicate row that selects the same value
|
|
172
|
+
// reads as a rendering fault.
|
|
173
|
+
if (custom === '' || listed.some((option) => option.value === custom))
|
|
174
|
+
return listed;
|
|
175
|
+
// Last, not first: the term is a fallback for when none of the real
|
|
176
|
+
// options are what was meant, so it must not displace the best match from
|
|
177
|
+
// the position the keyboard lands on.
|
|
178
|
+
return [...listed, { value: custom, label: custom }];
|
|
179
|
+
}, [isAsync, loaded, staticOptions, appliedTerm, value, shownCount, allowCustomValue]);
|
|
180
|
+
const staticMatchCount = useMemo(() => (isAsync ? 0 : matchOptions(staticOptions ?? [], appliedTerm, { keep: value }).length), [isAsync, staticOptions, appliedTerm, value]);
|
|
181
|
+
const hasMore = isAsync ? loadedMore : staticMatchCount > shownCount;
|
|
182
|
+
const selected = useMemo(() => value.map((entry) => known.get(entry) ?? { value: entry, label: entry }), [value, known]);
|
|
183
|
+
const atLimit = !single && maxSelected !== undefined && value.length >= maxSelected;
|
|
184
|
+
const setOpen = useCallback((next) => {
|
|
185
|
+
if (disabled)
|
|
186
|
+
return;
|
|
187
|
+
setOpenState(next);
|
|
188
|
+
if (!next) {
|
|
189
|
+
// Reopening starts from the full list rather than a stale narrowing.
|
|
190
|
+
setTermState('');
|
|
191
|
+
setActiveIndex(-1);
|
|
192
|
+
setShownCount(pageSize);
|
|
193
|
+
if (!isAsync)
|
|
194
|
+
setAppliedTerm('');
|
|
195
|
+
}
|
|
196
|
+
}, [disabled, pageSize, isAsync]);
|
|
197
|
+
const setTerm = useCallback((next) => {
|
|
198
|
+
setTermState(next);
|
|
199
|
+
// A new search invalidates where the keyboard was: index 3 of the old list
|
|
200
|
+
// is a different option in the new one.
|
|
201
|
+
setActiveIndex(-1);
|
|
202
|
+
}, []);
|
|
203
|
+
const toggle = useCallback((entry) => {
|
|
204
|
+
if (disabled)
|
|
205
|
+
return;
|
|
206
|
+
if (single) {
|
|
207
|
+
const alreadyChosen = value[0] === entry;
|
|
208
|
+
// Choosing the current value again is how a single select is emptied.
|
|
209
|
+
// When it may not be emptied, that is a no-op rather than a silent
|
|
210
|
+
// clear the caller then has to ignore.
|
|
211
|
+
if (alreadyChosen && !clearable) {
|
|
212
|
+
setOpen(false);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
onChange(alreadyChosen ? [] : [entry]);
|
|
216
|
+
// A single choice is the whole interaction, so making it ends it. Here
|
|
217
|
+
// rather than in the component, so a click and an Enter cannot disagree
|
|
218
|
+
// about whether the popover stays open — which is exactly how they
|
|
219
|
+
// drifted apart the first time.
|
|
220
|
+
setOpen(false);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
if (value.includes(entry)) {
|
|
224
|
+
// The last one cannot be taken away from a selection that must not be
|
|
225
|
+
// empty; the others still can.
|
|
226
|
+
if (!clearable && value.length === 1)
|
|
227
|
+
return;
|
|
228
|
+
onChange(value.filter((current) => current !== entry));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
// The cap is enforced here rather than only in the markup: a control that
|
|
232
|
+
// merely *looks* disabled is one a keyboard walks straight past.
|
|
233
|
+
if (maxSelected !== undefined && value.length >= maxSelected)
|
|
234
|
+
return;
|
|
235
|
+
onChange([...value, entry]);
|
|
236
|
+
}, [disabled, single, value, onChange, maxSelected, setOpen, clearable]);
|
|
237
|
+
const selectListed = useCallback(() => {
|
|
238
|
+
if (disabled || single)
|
|
239
|
+
return;
|
|
240
|
+
const selectable = options.filter((option) => option.disabled !== true).map((option) => option.value);
|
|
241
|
+
const next = [...new Set([...value, ...selectable])];
|
|
242
|
+
onChange(maxSelected === undefined ? next : next.slice(0, maxSelected));
|
|
243
|
+
}, [disabled, single, options, value, onChange, maxSelected]);
|
|
244
|
+
const moveActive = useCallback((to) => {
|
|
245
|
+
const count = options.length;
|
|
246
|
+
if (count === 0) {
|
|
247
|
+
setActiveIndex(-1);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
setActiveIndex((current) => {
|
|
251
|
+
if (to === 'first')
|
|
252
|
+
return 0;
|
|
253
|
+
if (to === 'last')
|
|
254
|
+
return count - 1;
|
|
255
|
+
// Wraps, and treats "no active option" as "just before the first", so
|
|
256
|
+
// the first Down press lands on index 0 rather than on 1.
|
|
257
|
+
const from = current < 0 ? (to > 0 ? -1 : 0) : current;
|
|
258
|
+
return ((from + to) % count + count) % count;
|
|
259
|
+
});
|
|
260
|
+
}, [options.length]);
|
|
261
|
+
return {
|
|
262
|
+
open,
|
|
263
|
+
setOpen,
|
|
264
|
+
term,
|
|
265
|
+
setTerm,
|
|
266
|
+
appliedTerm,
|
|
267
|
+
options,
|
|
268
|
+
status: isAsync ? status : 'ready',
|
|
269
|
+
error,
|
|
270
|
+
hasMore,
|
|
271
|
+
showMore: () => {
|
|
272
|
+
if (isAsync)
|
|
273
|
+
void run(appliedTerm, loaded.length);
|
|
274
|
+
else
|
|
275
|
+
setShownCount((current) => current + pageSize);
|
|
276
|
+
},
|
|
277
|
+
refresh: () => {
|
|
278
|
+
if (isAsync)
|
|
279
|
+
void run(appliedTerm, 0);
|
|
280
|
+
},
|
|
281
|
+
needsMoreInput: appliedTerm.trim().length < minSearchLength,
|
|
282
|
+
minSearchLength,
|
|
283
|
+
selected,
|
|
284
|
+
isSelected: (entry) => value.includes(entry),
|
|
285
|
+
toggle,
|
|
286
|
+
clear: () => {
|
|
287
|
+
if (!disabled && clearable)
|
|
288
|
+
onChange([]);
|
|
289
|
+
},
|
|
290
|
+
clearable,
|
|
291
|
+
selectListed,
|
|
292
|
+
atLimit,
|
|
293
|
+
activeIndex,
|
|
294
|
+
setActiveIndex,
|
|
295
|
+
moveActive,
|
|
296
|
+
disabled,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
//# sourceMappingURL=useOptionSelect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOptionSelect.js","sourceRoot":"","sources":["../src/useOptionSelect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AA4H/E;;;;;;;;GAQG;AACH,SAAS,KAAK,CAAC,MAAyB;IACtC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgC;IAC9D,MAAM,EACJ,SAAS,EACT,KAAK,EACL,QAAQ,EACR,MAAM,GAAG,KAAK,EACd,QAAQ,GAAG,aAAa,EACxB,UAAU,GAAG,GAAG,EAChB,eAAe,GAAG,CAAC,EACnB,WAAW,EACX,gBAAgB,GAAG,KAAK,EACxB,SAAS,GAAG,IAAI,EAChB,QAAQ,GAAG,KAAK,GACjB,GAAG,QAAQ,CAAC;IAEb,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO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;KACT,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@speles7172/controls",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reusable React form controls — starting with a searchable multi-select — over static options or a transport you supply.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./styles.css": "./dist/styles.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"registry": "https://registry.npmjs.org",
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/speles7172/utils.git",
|
|
26
|
+
"directory": "packages/controls"
|
|
27
|
+
},
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=22.0.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc --build && node ../../scripts/copy-assets.mjs src/styles.css dist/styles.css",
|
|
33
|
+
"prepublishOnly": "npm run build"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@speles7172/controls-client": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@testing-library/react": "^16.1.0",
|
|
43
|
+
"@testing-library/user-event": "^14.5.2",
|
|
44
|
+
"@types/react": "^19.0.2",
|
|
45
|
+
"@types/react-dom": "^19.0.2",
|
|
46
|
+
"jsdom": "^25.0.1",
|
|
47
|
+
"react": "^19.0.0",
|
|
48
|
+
"react-dom": "^19.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|