@smilodon/react 1.10.0 → 1.10.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.
- package/README.md +139 -0
- package/dist/index.cjs +516 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +517 -145
- package/dist/index.js.map +1 -1
- package/dist/types/Select.d.ts +17 -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 +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import React, { forwardRef, useRef, useMemo,
|
|
3
|
+
import React, { forwardRef, useState, useRef, useMemo, useCallback, useEffect, useImperativeHandle } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { configureSelect, resetSelectConfig, selectConfig } from "@smilodon/core";
|
|
6
|
+
const DEFAULT_DATA_LOADING_CONFIG = {
|
|
7
|
+
protocol: "legacy",
|
|
8
|
+
searchMode: "local",
|
|
9
|
+
paginationMode: "page",
|
|
10
|
+
firstPage: 1
|
|
11
|
+
};
|
|
12
|
+
function isPlainRecord(value) {
|
|
13
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const prototype = Object.getPrototypeOf(value);
|
|
17
|
+
return prototype === Object.prototype || prototype === null;
|
|
18
|
+
}
|
|
19
|
+
function isBusyToken(value) {
|
|
20
|
+
return value === true || value === "true";
|
|
21
|
+
}
|
|
22
|
+
function composeBusyToken(consumerValue, externalBusy) {
|
|
23
|
+
if (externalBusy || isBusyToken(consumerValue)) return "true";
|
|
24
|
+
if (consumerValue === false || consumerValue === "false") return consumerValue;
|
|
25
|
+
return consumerValue;
|
|
26
|
+
}
|
|
6
27
|
const Select = forwardRef((props, ref) => {
|
|
28
|
+
var _a, _b;
|
|
7
29
|
const {
|
|
8
30
|
items = [],
|
|
9
31
|
groupedItems,
|
|
@@ -51,6 +73,9 @@ const Select = forwardRef((props, ref) => {
|
|
|
51
73
|
onLoadMore,
|
|
52
74
|
onClear,
|
|
53
75
|
onDiagnostic,
|
|
76
|
+
onDataRequestCancel,
|
|
77
|
+
onDataProjection,
|
|
78
|
+
onDataLoadingConfigError,
|
|
54
79
|
trackingEnabled = false,
|
|
55
80
|
trackEvents = true,
|
|
56
81
|
trackStyling = true,
|
|
@@ -64,16 +89,65 @@ const Select = forwardRef((props, ref) => {
|
|
|
64
89
|
onCreate,
|
|
65
90
|
classMap,
|
|
66
91
|
groupHeaderRenderer,
|
|
92
|
+
"aria-busy": consumerAriaBusy,
|
|
67
93
|
...hostProps
|
|
68
94
|
} = props;
|
|
95
|
+
const [isControlled] = useState(value !== void 0);
|
|
96
|
+
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
97
|
+
const hasAppliedInitialValueRef = useRef(false);
|
|
69
98
|
const elementRef = useRef(null);
|
|
99
|
+
const coreModuleRef = useRef(null);
|
|
100
|
+
const acceptedDataLoadingConfigRef = useRef({
|
|
101
|
+
...DEFAULT_DATA_LOADING_CONFIG
|
|
102
|
+
});
|
|
103
|
+
const configUpdateStackRef = useRef([]);
|
|
104
|
+
const configUpdateInProgressRef = useRef(false);
|
|
105
|
+
const queuedConfigUpdatesRef = useRef([]);
|
|
106
|
+
const queuedImperativeConfigsRef = useRef([]);
|
|
107
|
+
const activeListenersRef = useRef(null);
|
|
108
|
+
const callbackStateRef = useRef({
|
|
109
|
+
onSelect,
|
|
110
|
+
onChange,
|
|
111
|
+
onOpen,
|
|
112
|
+
onClose,
|
|
113
|
+
onSearch,
|
|
114
|
+
onLoadMore,
|
|
115
|
+
onClear,
|
|
116
|
+
onDiagnostic,
|
|
117
|
+
onDataRequestCancel,
|
|
118
|
+
onDataProjection,
|
|
119
|
+
onDataLoadingConfigError,
|
|
120
|
+
isControlled,
|
|
121
|
+
multiple
|
|
122
|
+
});
|
|
123
|
+
callbackStateRef.current = {
|
|
124
|
+
onSelect,
|
|
125
|
+
onChange,
|
|
126
|
+
onOpen,
|
|
127
|
+
onClose,
|
|
128
|
+
onSearch,
|
|
129
|
+
onLoadMore,
|
|
130
|
+
onClear,
|
|
131
|
+
onDiagnostic,
|
|
132
|
+
onDataRequestCancel,
|
|
133
|
+
onDataProjection,
|
|
134
|
+
onDataLoadingConfigError,
|
|
135
|
+
isControlled,
|
|
136
|
+
multiple
|
|
137
|
+
};
|
|
138
|
+
const ariaBusyInputsRef = useRef({ consumerAriaBusy, loading });
|
|
139
|
+
ariaBusyInputsRef.current = { consumerAriaBusy, loading };
|
|
140
|
+
const initializingRef = useRef(true);
|
|
141
|
+
const compatibilityFailureReportedRef = useRef(false);
|
|
142
|
+
const unusableRef = useRef(false);
|
|
143
|
+
const [acceptedProtocol, setAcceptedProtocol] = useState("legacy");
|
|
144
|
+
const [isCoreModuleLoaded, setIsCoreModuleLoaded] = useState(false);
|
|
145
|
+
const [isAcknowledgedQualified, setIsAcknowledgedQualified] = useState(false);
|
|
146
|
+
const [isUnusable, setIsUnusable] = useState(false);
|
|
70
147
|
const resolvedDropdownPlacement = useMemo(() => {
|
|
71
148
|
if (placement == null ? void 0 : placement.startsWith("top")) return "top";
|
|
72
149
|
return "bottom";
|
|
73
150
|
}, [placement]);
|
|
74
|
-
const [isControlled] = useState(value !== void 0);
|
|
75
|
-
const [internalValue, setInternalValue] = useState(defaultValue);
|
|
76
|
-
const hasAppliedInitialValueRef = useRef(false);
|
|
77
151
|
const reactRendererCache = useRef(
|
|
78
152
|
/* @__PURE__ */ new Map()
|
|
79
153
|
);
|
|
@@ -124,8 +198,8 @@ const Select = forwardRef((props, ref) => {
|
|
|
124
198
|
const resolvedOptionRenderer = useMemo(() => {
|
|
125
199
|
if (optionRenderer) {
|
|
126
200
|
return (item, index, helpers) => {
|
|
127
|
-
var
|
|
128
|
-
return ((
|
|
201
|
+
var _a2;
|
|
202
|
+
return ((_a2 = optionRendererRef.current) == null ? void 0 : _a2.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
|
|
129
203
|
};
|
|
130
204
|
}
|
|
131
205
|
const hasReactRenderer = !!(customRenderer ?? renderItem);
|
|
@@ -204,6 +278,240 @@ const Select = forwardRef((props, ref) => {
|
|
|
204
278
|
reactRendererCache.current.clear();
|
|
205
279
|
}, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
|
|
206
280
|
const [isElementReady, setIsElementReady] = useState(false);
|
|
281
|
+
const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_a = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _a.protocol) === "acknowledged";
|
|
282
|
+
const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
|
|
283
|
+
const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
|
|
284
|
+
const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
|
|
285
|
+
const markUnusable = useCallback(
|
|
286
|
+
(message) => {
|
|
287
|
+
if (unusableRef.current) return;
|
|
288
|
+
unusableRef.current = true;
|
|
289
|
+
setIsUnusable(true);
|
|
290
|
+
const element = elementRef.current;
|
|
291
|
+
const { consumerAriaBusy: currentConsumerBusy } = ariaBusyInputsRef.current;
|
|
292
|
+
if (element) {
|
|
293
|
+
if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
|
|
294
|
+
else element.setAttribute("aria-busy", String(currentConsumerBusy));
|
|
295
|
+
}
|
|
296
|
+
if (!compatibilityFailureReportedRef.current) {
|
|
297
|
+
compatibilityFailureReportedRef.current = true;
|
|
298
|
+
console.error(`[Smilodon React] ${message}`);
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
[]
|
|
302
|
+
);
|
|
303
|
+
const syncHostBusy = useCallback((element) => {
|
|
304
|
+
const { consumerAriaBusy: currentConsumerBusy, loading: externalBusy } = ariaBusyInputsRef.current;
|
|
305
|
+
if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged" && !unusableRef.current) {
|
|
306
|
+
const composed = composeBusyToken(currentConsumerBusy, externalBusy);
|
|
307
|
+
if (composed === void 0) element.removeAttribute("aria-busy");
|
|
308
|
+
else element.setAttribute("aria-busy", String(composed));
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
|
|
312
|
+
else element.setAttribute("aria-busy", String(currentConsumerBusy));
|
|
313
|
+
}, []);
|
|
314
|
+
const applyInstanceConfig = useCallback(
|
|
315
|
+
(element, config) => {
|
|
316
|
+
if (!(element == null ? void 0 : element.updateConfig) || unusableRef.current) return;
|
|
317
|
+
if (configUpdateInProgressRef.current) {
|
|
318
|
+
queuedConfigUpdatesRef.current.push({ ...config });
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
configUpdateInProgressRef.current = true;
|
|
322
|
+
const queue = [{ ...config }];
|
|
323
|
+
let processed = 0;
|
|
324
|
+
try {
|
|
325
|
+
while (queue.length > 0 && !unusableRef.current) {
|
|
326
|
+
if (processed++ >= 100) {
|
|
327
|
+
queuedConfigUpdatesRef.current = [];
|
|
328
|
+
markUnusable(
|
|
329
|
+
"Too many reentrant configuration updates were queued; the wrapper has been stopped to avoid an unbounded update loop."
|
|
330
|
+
);
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
const currentConfig = queue.shift();
|
|
334
|
+
const module = coreModuleRef.current;
|
|
335
|
+
let validation;
|
|
336
|
+
if (currentConfig.dataLoading !== void 0) {
|
|
337
|
+
const candidate = isPlainRecord(currentConfig.dataLoading) ? { ...acceptedDataLoadingConfigRef.current, ...currentConfig.dataLoading } : currentConfig.dataLoading;
|
|
338
|
+
if (!module) {
|
|
339
|
+
markUnusable(
|
|
340
|
+
"The core validator is unavailable; acknowledged configuration cannot be reconciled safely."
|
|
341
|
+
);
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
validation = module.validateDataLoadingConfig(candidate);
|
|
346
|
+
} catch (error2) {
|
|
347
|
+
markUnusable(
|
|
348
|
+
`Core data-loading preflight failed unexpectedly: ${String(error2)}`
|
|
349
|
+
);
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const update = { sawConfigError: false };
|
|
354
|
+
configUpdateStackRef.current.push(update);
|
|
355
|
+
let threw = false;
|
|
356
|
+
try {
|
|
357
|
+
element.updateConfig(currentConfig);
|
|
358
|
+
} catch (error2) {
|
|
359
|
+
threw = true;
|
|
360
|
+
markUnusable(
|
|
361
|
+
`Core configuration acceptance is uncertain after updateConfig() threw: ${String(error2)}`
|
|
362
|
+
);
|
|
363
|
+
} finally {
|
|
364
|
+
configUpdateStackRef.current.pop();
|
|
365
|
+
}
|
|
366
|
+
if ((validation == null ? void 0 : validation.valid) && !threw) {
|
|
367
|
+
if (update.sawConfigError) {
|
|
368
|
+
markUnusable(
|
|
369
|
+
"Core reported a data-loading configuration error for a preflight-valid candidate; the accepted protocol is uncertain."
|
|
370
|
+
);
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
acceptedDataLoadingConfigRef.current = { ...validation.value };
|
|
374
|
+
setAcceptedProtocol(validation.value.protocol);
|
|
375
|
+
syncHostBusy(element);
|
|
376
|
+
}
|
|
377
|
+
if (queuedConfigUpdatesRef.current.length > 0) {
|
|
378
|
+
queue.push(...queuedConfigUpdatesRef.current);
|
|
379
|
+
queuedConfigUpdatesRef.current = [];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
} finally {
|
|
383
|
+
configUpdateInProgressRef.current = false;
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
[markUnusable, syncHostBusy]
|
|
387
|
+
);
|
|
388
|
+
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
|
|
389
|
+
const qualifyAcknowledgedElement = useCallback(() => {
|
|
390
|
+
const element = elementRef.current;
|
|
391
|
+
const module = coreModuleRef.current;
|
|
392
|
+
if (!element || !module || typeof customElements === "undefined") return false;
|
|
393
|
+
const registered = customElements.get("enhanced-select");
|
|
394
|
+
const observed = registered == null ? void 0 : registered.observedAttributes;
|
|
395
|
+
const compatible = registered === module.EnhancedSelect && element.constructor === module.EnhancedSelect && Array.isArray(observed) && observed.includes("aria-busy") && typeof element.updateConfig === "function" && typeof element.startDataLoading === "function" && typeof element.getDataLoadingState === "function" && typeof element.completeDataRequest === "function";
|
|
396
|
+
if (!compatible) {
|
|
397
|
+
markUnusable(
|
|
398
|
+
"Acknowledged data loading requires the exact peer-resolved EnhancedSelect constructor with the Phase 2F facade and aria-busy observation support."
|
|
399
|
+
);
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
setIsAcknowledgedQualified(true);
|
|
403
|
+
return true;
|
|
404
|
+
}, [markUnusable]);
|
|
405
|
+
const subscribeToCoreEvents = useCallback((element) => {
|
|
406
|
+
const currentSubscription = activeListenersRef.current;
|
|
407
|
+
if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
|
|
408
|
+
currentSubscription == null ? void 0 : currentSubscription.dispose();
|
|
409
|
+
const handleSelect = (event) => {
|
|
410
|
+
var _a2, _b2;
|
|
411
|
+
const detail = event.detail;
|
|
412
|
+
(_b2 = (_a2 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a2, detail.item, detail.index);
|
|
413
|
+
};
|
|
414
|
+
const handleChange = (event) => {
|
|
415
|
+
var _a2;
|
|
416
|
+
const { selectedItems, selectedValues } = event.detail;
|
|
417
|
+
const callbacks = callbackStateRef.current;
|
|
418
|
+
const values = selectedValues;
|
|
419
|
+
const nextSingleValue = values.length > 0 ? values[0] : "";
|
|
420
|
+
if (initializingRef.current) return;
|
|
421
|
+
if (!callbacks.isControlled) {
|
|
422
|
+
setInternalValue(callbacks.multiple ? values : nextSingleValue);
|
|
423
|
+
}
|
|
424
|
+
(_a2 = callbacks.onChange) == null ? void 0 : _a2.call(
|
|
425
|
+
callbacks,
|
|
426
|
+
callbacks.multiple ? values : nextSingleValue,
|
|
427
|
+
selectedItems
|
|
428
|
+
);
|
|
429
|
+
};
|
|
430
|
+
const handleOpen = () => {
|
|
431
|
+
var _a2, _b2;
|
|
432
|
+
return (_b2 = (_a2 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a2);
|
|
433
|
+
};
|
|
434
|
+
const handleClose = () => {
|
|
435
|
+
var _a2, _b2;
|
|
436
|
+
return (_b2 = (_a2 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a2);
|
|
437
|
+
};
|
|
438
|
+
const handleSearch = (event) => {
|
|
439
|
+
const { query, results, count, request } = event.detail;
|
|
440
|
+
const callback = callbackStateRef.current.onSearch;
|
|
441
|
+
if (!callback) return;
|
|
442
|
+
if (request) callback(query, results, count, request);
|
|
443
|
+
else callback(query, results, count);
|
|
444
|
+
};
|
|
445
|
+
const handleLoadMore = (event) => {
|
|
446
|
+
const { page, request } = event.detail;
|
|
447
|
+
const callback = callbackStateRef.current.onLoadMore;
|
|
448
|
+
if (!callback) return;
|
|
449
|
+
if (request) callback(page, request);
|
|
450
|
+
else callback(page);
|
|
451
|
+
};
|
|
452
|
+
const handleClear = (event) => {
|
|
453
|
+
var _a2, _b2;
|
|
454
|
+
const { clearedSelection, clearedSearch } = event.detail;
|
|
455
|
+
(_b2 = (_a2 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a2, { clearedSelection, clearedSearch });
|
|
456
|
+
};
|
|
457
|
+
const handleDiagnostic = (event) => {
|
|
458
|
+
var _a2, _b2;
|
|
459
|
+
(_b2 = (_a2 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
|
|
460
|
+
_a2,
|
|
461
|
+
event.detail
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
const handleDataRequestCancel = (event) => {
|
|
465
|
+
var _a2, _b2;
|
|
466
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
|
|
467
|
+
_a2,
|
|
468
|
+
event.detail
|
|
469
|
+
);
|
|
470
|
+
};
|
|
471
|
+
const handleDataProjection = (event) => {
|
|
472
|
+
var _a2, _b2;
|
|
473
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
|
|
474
|
+
_a2,
|
|
475
|
+
event.detail
|
|
476
|
+
);
|
|
477
|
+
};
|
|
478
|
+
const handleDataLoadingConfigError = (event) => {
|
|
479
|
+
var _a2, _b2;
|
|
480
|
+
const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
|
|
481
|
+
if (activeUpdate) activeUpdate.sawConfigError = true;
|
|
482
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
|
|
483
|
+
_a2,
|
|
484
|
+
event.detail
|
|
485
|
+
);
|
|
486
|
+
};
|
|
487
|
+
const listeners = [
|
|
488
|
+
["select", handleSelect],
|
|
489
|
+
["change", handleChange],
|
|
490
|
+
["open", handleOpen],
|
|
491
|
+
["close", handleClose],
|
|
492
|
+
["search", handleSearch],
|
|
493
|
+
["loadMore", handleLoadMore],
|
|
494
|
+
["clear", handleClear],
|
|
495
|
+
["diagnostic", handleDiagnostic],
|
|
496
|
+
["dataRequestCancel", handleDataRequestCancel],
|
|
497
|
+
["dataProjection", handleDataProjection],
|
|
498
|
+
["dataLoadingConfigError", handleDataLoadingConfigError]
|
|
499
|
+
];
|
|
500
|
+
for (const [name, listener] of listeners) {
|
|
501
|
+
element.addEventListener(name, listener);
|
|
502
|
+
}
|
|
503
|
+
const dispose = () => {
|
|
504
|
+
var _a2;
|
|
505
|
+
if (((_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose) === dispose) {
|
|
506
|
+
activeListenersRef.current = null;
|
|
507
|
+
}
|
|
508
|
+
for (const [name, listener] of listeners) {
|
|
509
|
+
element.removeEventListener(name, listener);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
activeListenersRef.current = { element, dispose };
|
|
513
|
+
return dispose;
|
|
514
|
+
}, []);
|
|
207
515
|
useEffect(() => {
|
|
208
516
|
const element = elementRef.current;
|
|
209
517
|
if (!element || !isElementReady) return;
|
|
@@ -234,23 +542,61 @@ const Select = forwardRef((props, ref) => {
|
|
|
234
542
|
}
|
|
235
543
|
}, [isElementReady, classMap, areClassMapsEqual]);
|
|
236
544
|
useEffect(() => {
|
|
237
|
-
if (typeof window
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
545
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") return;
|
|
546
|
+
let active = true;
|
|
547
|
+
const existingConstructor = customElements.get("enhanced-select");
|
|
548
|
+
if (existingConstructor) setIsElementReady(true);
|
|
549
|
+
import("@smilodon/core").then((module) => {
|
|
550
|
+
if (!active) return;
|
|
551
|
+
coreModuleRef.current = module;
|
|
552
|
+
setIsCoreModuleLoaded(true);
|
|
553
|
+
const currentConstructor = customElements.get("enhanced-select");
|
|
554
|
+
if (!currentConstructor) {
|
|
555
|
+
customElements.define("enhanced-select", module.EnhancedSelect);
|
|
247
556
|
}
|
|
248
|
-
|
|
557
|
+
setIsElementReady(true);
|
|
558
|
+
}).catch((error2) => {
|
|
559
|
+
if (!active) return;
|
|
560
|
+
if (requiresAcknowledgedQualification) {
|
|
561
|
+
markUnusable(`Unable to load the compatible core runtime: ${String(error2)}`);
|
|
562
|
+
} else if (!customElements.get("enhanced-select")) {
|
|
563
|
+
console.error(`[Smilodon React] Unable to register enhanced-select: ${String(error2)}`);
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
return () => {
|
|
567
|
+
active = false;
|
|
568
|
+
};
|
|
569
|
+
}, [markUnusable]);
|
|
570
|
+
useEffect(() => {
|
|
571
|
+
if (!isElementReady || !isCoreModuleLoaded || !requiresAcknowledgedQualification || isUnusable) return;
|
|
572
|
+
qualifyAcknowledgedElement();
|
|
573
|
+
}, [
|
|
574
|
+
isElementReady,
|
|
575
|
+
isCoreModuleLoaded,
|
|
576
|
+
requiresAcknowledgedQualification,
|
|
577
|
+
isUnusable,
|
|
578
|
+
qualifyAcknowledgedElement
|
|
579
|
+
]);
|
|
580
|
+
useEffect(() => {
|
|
581
|
+
const element = elementRef.current;
|
|
582
|
+
if (!(acknowledgedRequested || dataLoadingConfigured) || !isElementUsable || !element) return;
|
|
583
|
+
return subscribeToCoreEvents(element);
|
|
584
|
+
}, [
|
|
585
|
+
acknowledgedRequested,
|
|
586
|
+
dataLoadingConfigured,
|
|
587
|
+
isElementUsable,
|
|
588
|
+
subscribeToCoreEvents
|
|
589
|
+
]);
|
|
590
|
+
useEffect(() => {
|
|
591
|
+
return () => {
|
|
592
|
+
var _a2;
|
|
593
|
+
return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
|
|
594
|
+
};
|
|
249
595
|
}, []);
|
|
250
596
|
useEffect(() => {
|
|
251
|
-
var
|
|
597
|
+
var _a2;
|
|
252
598
|
const element = elementRef.current;
|
|
253
|
-
if (!element || !
|
|
599
|
+
if (!element || !isElementUsable) return;
|
|
254
600
|
if (!element.setItems) {
|
|
255
601
|
console.warn("Enhanced select element not fully initialized yet");
|
|
256
602
|
return;
|
|
@@ -310,13 +656,13 @@ const Select = forwardRef((props, ref) => {
|
|
|
310
656
|
autoMitigateRuntimeModeSwitch
|
|
311
657
|
}
|
|
312
658
|
};
|
|
313
|
-
element
|
|
659
|
+
applyInstanceConfig(element, config);
|
|
314
660
|
if (coreConfig) {
|
|
315
|
-
element
|
|
661
|
+
applyInstanceConfig(element, coreConfig);
|
|
316
662
|
}
|
|
317
663
|
if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
|
|
318
664
|
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
319
|
-
const currentValues = ((
|
|
665
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
320
666
|
if (!areValuesEqual(values, currentValues)) {
|
|
321
667
|
element.setSelectedValues(values);
|
|
322
668
|
}
|
|
@@ -331,7 +677,7 @@ const Select = forwardRef((props, ref) => {
|
|
|
331
677
|
element.setRequired(true);
|
|
332
678
|
}
|
|
333
679
|
}, [
|
|
334
|
-
|
|
680
|
+
isElementUsable,
|
|
335
681
|
items,
|
|
336
682
|
groupedItems,
|
|
337
683
|
searchable,
|
|
@@ -373,11 +719,12 @@ const Select = forwardRef((props, ref) => {
|
|
|
373
719
|
required,
|
|
374
720
|
internalValue,
|
|
375
721
|
isControlled,
|
|
376
|
-
areValuesEqual
|
|
722
|
+
areValuesEqual,
|
|
723
|
+
applyInstanceConfig
|
|
377
724
|
]);
|
|
378
725
|
useEffect(() => {
|
|
379
726
|
const element = elementRef.current;
|
|
380
|
-
if (!element || !
|
|
727
|
+
if (!element || !isElementUsable || !element.setItems) return;
|
|
381
728
|
if (groupedItems) {
|
|
382
729
|
element.setGroupedItems(groupedItems);
|
|
383
730
|
} else if (items && items.length && items[0] && items[0].group !== void 0) {
|
|
@@ -395,23 +742,23 @@ const Select = forwardRef((props, ref) => {
|
|
|
395
742
|
} else {
|
|
396
743
|
element.setItems(items);
|
|
397
744
|
}
|
|
398
|
-
}, [items, groupedItems,
|
|
745
|
+
}, [items, groupedItems, isElementUsable]);
|
|
399
746
|
useEffect(() => {
|
|
400
|
-
var
|
|
747
|
+
var _a2;
|
|
401
748
|
const element = elementRef.current;
|
|
402
|
-
if (!element || !isControlled || !
|
|
749
|
+
if (!element || !isControlled || !isElementUsable || !element.setSelectedValues)
|
|
403
750
|
return;
|
|
404
751
|
if (value !== void 0) {
|
|
405
752
|
const values = Array.isArray(value) ? value : [value];
|
|
406
|
-
const currentValues = ((
|
|
753
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
407
754
|
if (!areValuesEqual(values, currentValues)) {
|
|
408
755
|
element.setSelectedValues(values);
|
|
409
756
|
}
|
|
410
757
|
}
|
|
411
|
-
}, [value, isControlled,
|
|
758
|
+
}, [value, isControlled, isElementUsable, areValuesEqual]);
|
|
412
759
|
useEffect(() => {
|
|
413
760
|
const element = elementRef.current;
|
|
414
|
-
if (!element || !
|
|
761
|
+
if (!element || !isElementUsable || !element.updateConfig) return;
|
|
415
762
|
const config = {
|
|
416
763
|
searchable,
|
|
417
764
|
placeholder,
|
|
@@ -461,9 +808,9 @@ const Select = forwardRef((props, ref) => {
|
|
|
461
808
|
autoMitigateRuntimeModeSwitch
|
|
462
809
|
}
|
|
463
810
|
};
|
|
464
|
-
element
|
|
811
|
+
applyInstanceConfig(element, config);
|
|
465
812
|
if (coreConfig) {
|
|
466
|
-
element
|
|
813
|
+
applyInstanceConfig(element, coreConfig);
|
|
467
814
|
}
|
|
468
815
|
}, [
|
|
469
816
|
searchable,
|
|
@@ -499,185 +846,210 @@ const Select = forwardRef((props, ref) => {
|
|
|
499
846
|
autoMitigateRuntimeModeSwitch,
|
|
500
847
|
direction,
|
|
501
848
|
resolvedDropdownPlacement,
|
|
502
|
-
|
|
849
|
+
isElementUsable,
|
|
850
|
+
applyInstanceConfig
|
|
503
851
|
]);
|
|
504
852
|
useEffect(() => {
|
|
505
853
|
const element = elementRef.current;
|
|
506
|
-
if (!element || !
|
|
854
|
+
if (!element || !isElementUsable) return;
|
|
507
855
|
if (error) {
|
|
508
856
|
if (element.setError)
|
|
509
857
|
element.setError(errorMessage || "Invalid selection");
|
|
510
858
|
} else {
|
|
511
859
|
if (element.clearError) element.clearError();
|
|
512
860
|
}
|
|
513
|
-
}, [error, errorMessage,
|
|
861
|
+
}, [error, errorMessage, isElementUsable]);
|
|
514
862
|
useEffect(() => {
|
|
515
863
|
const element = elementRef.current;
|
|
516
|
-
if (!element || !
|
|
864
|
+
if (!element || !isElementUsable || !element.setRequired) return;
|
|
517
865
|
element.setRequired(required);
|
|
518
|
-
}, [required,
|
|
866
|
+
}, [required, isElementUsable]);
|
|
519
867
|
useEffect(() => {
|
|
868
|
+
var _a2, _b2;
|
|
520
869
|
const element = elementRef.current;
|
|
521
|
-
if (!element) return;
|
|
522
|
-
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
870
|
+
if (!element || !isElementUsable) return;
|
|
871
|
+
if (isCoreModuleLoaded && queuedImperativeConfigsRef.current.length > 0) {
|
|
872
|
+
const queued = queuedImperativeConfigsRef.current;
|
|
873
|
+
queuedImperativeConfigsRef.current = [];
|
|
874
|
+
for (const config of queued) {
|
|
875
|
+
const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
|
|
876
|
+
if (requestsAcknowledged && !qualifyAcknowledgedElement()) break;
|
|
877
|
+
if (config.dataLoading !== void 0 || requestsAcknowledged) {
|
|
878
|
+
subscribeToCoreEvents(element);
|
|
879
|
+
}
|
|
880
|
+
applyInstanceConfig(element, config);
|
|
881
|
+
if (unusableRef.current) break;
|
|
532
882
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
onOpen == null ? void 0 : onOpen();
|
|
540
|
-
};
|
|
541
|
-
const handleClose = (e) => {
|
|
542
|
-
onClose == null ? void 0 : onClose();
|
|
543
|
-
};
|
|
544
|
-
const handleSearch = (e) => {
|
|
545
|
-
const { query, results, count } = e.detail;
|
|
546
|
-
onSearch == null ? void 0 : onSearch(query, results, count);
|
|
547
|
-
};
|
|
548
|
-
const handleLoadMore = (e) => {
|
|
549
|
-
const { page } = e.detail;
|
|
550
|
-
onLoadMore == null ? void 0 : onLoadMore(page);
|
|
551
|
-
};
|
|
552
|
-
const handleClear = (e) => {
|
|
553
|
-
onClear == null ? void 0 : onClear({
|
|
554
|
-
clearedSelection: e.detail.clearedSelection,
|
|
555
|
-
clearedSearch: e.detail.clearedSearch
|
|
556
|
-
});
|
|
557
|
-
};
|
|
558
|
-
const handleDiagnostic = (e) => {
|
|
559
|
-
onDiagnostic == null ? void 0 : onDiagnostic(e.detail);
|
|
560
|
-
};
|
|
561
|
-
element.addEventListener("select", handleSelect);
|
|
562
|
-
element.addEventListener("change", handleChange);
|
|
563
|
-
element.addEventListener("open", handleOpen);
|
|
564
|
-
element.addEventListener("close", handleClose);
|
|
565
|
-
element.addEventListener("search", handleSearch);
|
|
566
|
-
element.addEventListener("loadMore", handleLoadMore);
|
|
567
|
-
element.addEventListener("clear", handleClear);
|
|
568
|
-
element.addEventListener("diagnostic", handleDiagnostic);
|
|
569
|
-
return () => {
|
|
570
|
-
element.removeEventListener("select", handleSelect);
|
|
571
|
-
element.removeEventListener("change", handleChange);
|
|
572
|
-
element.removeEventListener("open", handleOpen);
|
|
573
|
-
element.removeEventListener("close", handleClose);
|
|
574
|
-
element.removeEventListener("search", handleSearch);
|
|
575
|
-
element.removeEventListener("loadMore", handleLoadMore);
|
|
576
|
-
element.removeEventListener("clear", handleClear);
|
|
577
|
-
element.removeEventListener("diagnostic", handleDiagnostic);
|
|
578
|
-
};
|
|
883
|
+
}
|
|
884
|
+
initializingRef.current = false;
|
|
885
|
+
syncHostBusy(element);
|
|
886
|
+
if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged") {
|
|
887
|
+
(_b2 = element.startDataLoading) == null ? void 0 : _b2.call(element);
|
|
888
|
+
}
|
|
579
889
|
}, [
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
890
|
+
isElementUsable,
|
|
891
|
+
acceptedProtocol,
|
|
892
|
+
acknowledgedRequested,
|
|
893
|
+
coreConfig,
|
|
894
|
+
items,
|
|
895
|
+
groupedItems,
|
|
896
|
+
value,
|
|
897
|
+
defaultValue,
|
|
898
|
+
loading,
|
|
899
|
+
consumerAriaBusy,
|
|
900
|
+
syncHostBusy,
|
|
901
|
+
isCoreModuleLoaded,
|
|
902
|
+
qualifyAcknowledgedElement,
|
|
903
|
+
subscribeToCoreEvents,
|
|
904
|
+
applyInstanceConfig
|
|
905
|
+
]);
|
|
906
|
+
useEffect(() => {
|
|
907
|
+
const element = elementRef.current;
|
|
908
|
+
if (!element || acknowledgedRequested || dataLoadingConfigured || !isElementReady) return;
|
|
909
|
+
return subscribeToCoreEvents(element);
|
|
910
|
+
}, [
|
|
911
|
+
acknowledgedRequested,
|
|
912
|
+
dataLoadingConfigured,
|
|
913
|
+
isElementReady,
|
|
914
|
+
subscribeToCoreEvents
|
|
590
915
|
]);
|
|
591
916
|
useImperativeHandle(ref, () => ({
|
|
592
917
|
focus: () => {
|
|
593
|
-
var
|
|
594
|
-
(
|
|
918
|
+
var _a2;
|
|
919
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.focus();
|
|
595
920
|
},
|
|
596
921
|
open: () => {
|
|
597
|
-
var
|
|
598
|
-
(
|
|
922
|
+
var _a2;
|
|
923
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.open();
|
|
599
924
|
},
|
|
600
925
|
close: () => {
|
|
601
|
-
var
|
|
602
|
-
(
|
|
926
|
+
var _a2;
|
|
927
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.close();
|
|
603
928
|
},
|
|
604
929
|
getSelectedItems: () => {
|
|
605
|
-
var
|
|
606
|
-
return ((
|
|
930
|
+
var _a2;
|
|
931
|
+
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedItems()) || [];
|
|
607
932
|
},
|
|
608
933
|
getSelectedValues: () => {
|
|
609
|
-
var
|
|
610
|
-
return ((
|
|
934
|
+
var _a2;
|
|
935
|
+
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
|
|
611
936
|
},
|
|
612
937
|
setItems: (items2) => {
|
|
613
|
-
var
|
|
614
|
-
(
|
|
938
|
+
var _a2;
|
|
939
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
|
|
615
940
|
},
|
|
616
941
|
setGroupedItems: (groups) => {
|
|
617
|
-
var
|
|
618
|
-
(
|
|
942
|
+
var _a2;
|
|
943
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setGroupedItems(groups);
|
|
619
944
|
},
|
|
620
945
|
clear: () => {
|
|
621
|
-
var
|
|
622
|
-
(
|
|
946
|
+
var _a2;
|
|
947
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setSelectedValues([]);
|
|
623
948
|
if (!isControlled) {
|
|
624
949
|
setInternalValue(multiple ? [] : void 0);
|
|
625
950
|
}
|
|
626
951
|
onChange == null ? void 0 : onChange(multiple ? [] : "", []);
|
|
627
952
|
},
|
|
628
953
|
clearSearch: () => {
|
|
629
|
-
var
|
|
630
|
-
(
|
|
954
|
+
var _a2, _b2;
|
|
955
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearSearch) == null ? void 0 : _b2.call(_a2);
|
|
631
956
|
},
|
|
632
957
|
updateConfig: (config) => {
|
|
633
|
-
var
|
|
634
|
-
|
|
958
|
+
var _a2;
|
|
959
|
+
const element = elementRef.current;
|
|
960
|
+
if (!element || unusableRef.current) return;
|
|
961
|
+
const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
|
|
962
|
+
if (!isElementReady || !isCoreModuleLoaded) {
|
|
963
|
+
queuedImperativeConfigsRef.current.push({ ...config });
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
if (requestsAcknowledged && !qualifyAcknowledgedElement()) return;
|
|
967
|
+
if (config.dataLoading !== void 0 || requestsAcknowledged) {
|
|
968
|
+
subscribeToCoreEvents(element);
|
|
969
|
+
}
|
|
970
|
+
applyInstanceConfig(element, config);
|
|
971
|
+
},
|
|
972
|
+
getDataLoadingState: () => {
|
|
973
|
+
var _a2, _b2, _c;
|
|
974
|
+
const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
|
|
975
|
+
if (snapshot) return snapshot;
|
|
976
|
+
return {
|
|
977
|
+
status: "idle",
|
|
978
|
+
connected: Boolean((_c = elementRef.current) == null ? void 0 : _c.isConnected),
|
|
979
|
+
busy: false,
|
|
980
|
+
projectionPending: false,
|
|
981
|
+
queryGeneration: 0,
|
|
982
|
+
activeRequest: null,
|
|
983
|
+
hasMore: false,
|
|
984
|
+
nextEligiblePosition: {
|
|
985
|
+
mode: "page",
|
|
986
|
+
page: DEFAULT_DATA_LOADING_CONFIG.firstPage
|
|
987
|
+
},
|
|
988
|
+
error: null,
|
|
989
|
+
resourceLimit: null
|
|
990
|
+
};
|
|
991
|
+
},
|
|
992
|
+
completeDataRequest: (completion) => {
|
|
993
|
+
var _a2, _b2;
|
|
994
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.completeDataRequest) == null ? void 0 : _b2.call(_a2, completion)) ?? "unknown-request";
|
|
635
995
|
},
|
|
636
996
|
setError: (message) => {
|
|
637
|
-
var
|
|
638
|
-
(
|
|
997
|
+
var _a2, _b2;
|
|
998
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setError) == null ? void 0 : _b2.call(_a2, message);
|
|
639
999
|
},
|
|
640
1000
|
clearError: () => {
|
|
641
|
-
var
|
|
642
|
-
(
|
|
1001
|
+
var _a2, _b2;
|
|
1002
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearError) == null ? void 0 : _b2.call(_a2);
|
|
643
1003
|
},
|
|
644
1004
|
setRequired: (isRequired) => {
|
|
645
|
-
var
|
|
646
|
-
(
|
|
1005
|
+
var _a2, _b2;
|
|
1006
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setRequired) == null ? void 0 : _b2.call(_a2, isRequired);
|
|
647
1007
|
},
|
|
648
1008
|
validate: () => {
|
|
649
|
-
var
|
|
650
|
-
return ((
|
|
1009
|
+
var _a2, _b2;
|
|
1010
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.validate) == null ? void 0 : _b2.call(_a2)) ?? true;
|
|
651
1011
|
},
|
|
652
1012
|
getCapabilities: () => {
|
|
653
|
-
var
|
|
654
|
-
return (
|
|
1013
|
+
var _a2, _b2;
|
|
1014
|
+
return (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getCapabilities) == null ? void 0 : _b2.call(_a2);
|
|
655
1015
|
},
|
|
656
1016
|
getKnownLimitations: () => {
|
|
657
|
-
var
|
|
658
|
-
return ((
|
|
1017
|
+
var _a2, _b2;
|
|
1018
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getKnownLimitations) == null ? void 0 : _b2.call(_a2)) || [];
|
|
659
1019
|
},
|
|
660
1020
|
getTrackingSnapshot: () => {
|
|
661
|
-
var
|
|
662
|
-
return ((
|
|
1021
|
+
var _a2, _b2;
|
|
1022
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getTrackingSnapshot) == null ? void 0 : _b2.call(_a2)) || {
|
|
663
1023
|
events: [],
|
|
664
1024
|
styles: [],
|
|
665
1025
|
limitations: []
|
|
666
1026
|
};
|
|
667
1027
|
},
|
|
668
1028
|
clearTracking: (source) => {
|
|
669
|
-
var
|
|
670
|
-
(
|
|
1029
|
+
var _a2, _b2;
|
|
1030
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearTracking) == null ? void 0 : _b2.call(_a2, source);
|
|
671
1031
|
},
|
|
672
1032
|
setLimitationPolicies: (policies) => {
|
|
673
|
-
var
|
|
674
|
-
(
|
|
1033
|
+
var _a2, _b2;
|
|
1034
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setLimitationPolicies) == null ? void 0 : _b2.call(_a2, policies);
|
|
675
1035
|
}
|
|
676
|
-
})
|
|
1036
|
+
}), [
|
|
1037
|
+
applyInstanceConfig,
|
|
1038
|
+
isElementReady,
|
|
1039
|
+
isCoreModuleLoaded,
|
|
1040
|
+
qualifyAcknowledgedElement,
|
|
1041
|
+
subscribeToCoreEvents,
|
|
1042
|
+
isElementUsable,
|
|
1043
|
+
isControlled,
|
|
1044
|
+
multiple,
|
|
1045
|
+
onChange
|
|
1046
|
+
]);
|
|
1047
|
+
const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
|
|
677
1048
|
return React.createElement("enhanced-select", {
|
|
678
1049
|
ref: elementRef,
|
|
679
1050
|
...hostProps,
|
|
680
|
-
|
|
1051
|
+
"aria-busy": renderedAriaBusy,
|
|
1052
|
+
class: className,
|
|
681
1053
|
dir: direction,
|
|
682
1054
|
style
|
|
683
1055
|
});
|