@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.cjs
CHANGED
|
@@ -27,7 +27,29 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
27
27
|
const React = require("react");
|
|
28
28
|
const client = require("react-dom/client");
|
|
29
29
|
const core = require("@smilodon/core");
|
|
30
|
+
const DEFAULT_DATA_LOADING_CONFIG = {
|
|
31
|
+
protocol: "legacy",
|
|
32
|
+
searchMode: "local",
|
|
33
|
+
paginationMode: "page",
|
|
34
|
+
firstPage: 1
|
|
35
|
+
};
|
|
36
|
+
function isPlainRecord(value) {
|
|
37
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const prototype = Object.getPrototypeOf(value);
|
|
41
|
+
return prototype === Object.prototype || prototype === null;
|
|
42
|
+
}
|
|
43
|
+
function isBusyToken(value) {
|
|
44
|
+
return value === true || value === "true";
|
|
45
|
+
}
|
|
46
|
+
function composeBusyToken(consumerValue, externalBusy) {
|
|
47
|
+
if (externalBusy || isBusyToken(consumerValue)) return "true";
|
|
48
|
+
if (consumerValue === false || consumerValue === "false") return consumerValue;
|
|
49
|
+
return consumerValue;
|
|
50
|
+
}
|
|
30
51
|
const Select = React.forwardRef((props, ref) => {
|
|
52
|
+
var _a, _b;
|
|
31
53
|
const {
|
|
32
54
|
items = [],
|
|
33
55
|
groupedItems,
|
|
@@ -75,6 +97,9 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
75
97
|
onLoadMore,
|
|
76
98
|
onClear,
|
|
77
99
|
onDiagnostic,
|
|
100
|
+
onDataRequestCancel,
|
|
101
|
+
onDataProjection,
|
|
102
|
+
onDataLoadingConfigError,
|
|
78
103
|
trackingEnabled = false,
|
|
79
104
|
trackEvents = true,
|
|
80
105
|
trackStyling = true,
|
|
@@ -88,16 +113,65 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
88
113
|
onCreate,
|
|
89
114
|
classMap,
|
|
90
115
|
groupHeaderRenderer,
|
|
116
|
+
"aria-busy": consumerAriaBusy,
|
|
91
117
|
...hostProps
|
|
92
118
|
} = props;
|
|
119
|
+
const [isControlled] = React.useState(value !== void 0);
|
|
120
|
+
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
121
|
+
const hasAppliedInitialValueRef = React.useRef(false);
|
|
93
122
|
const elementRef = React.useRef(null);
|
|
123
|
+
const coreModuleRef = React.useRef(null);
|
|
124
|
+
const acceptedDataLoadingConfigRef = React.useRef({
|
|
125
|
+
...DEFAULT_DATA_LOADING_CONFIG
|
|
126
|
+
});
|
|
127
|
+
const configUpdateStackRef = React.useRef([]);
|
|
128
|
+
const configUpdateInProgressRef = React.useRef(false);
|
|
129
|
+
const queuedConfigUpdatesRef = React.useRef([]);
|
|
130
|
+
const queuedImperativeConfigsRef = React.useRef([]);
|
|
131
|
+
const activeListenersRef = React.useRef(null);
|
|
132
|
+
const callbackStateRef = React.useRef({
|
|
133
|
+
onSelect,
|
|
134
|
+
onChange,
|
|
135
|
+
onOpen,
|
|
136
|
+
onClose,
|
|
137
|
+
onSearch,
|
|
138
|
+
onLoadMore,
|
|
139
|
+
onClear,
|
|
140
|
+
onDiagnostic,
|
|
141
|
+
onDataRequestCancel,
|
|
142
|
+
onDataProjection,
|
|
143
|
+
onDataLoadingConfigError,
|
|
144
|
+
isControlled,
|
|
145
|
+
multiple
|
|
146
|
+
});
|
|
147
|
+
callbackStateRef.current = {
|
|
148
|
+
onSelect,
|
|
149
|
+
onChange,
|
|
150
|
+
onOpen,
|
|
151
|
+
onClose,
|
|
152
|
+
onSearch,
|
|
153
|
+
onLoadMore,
|
|
154
|
+
onClear,
|
|
155
|
+
onDiagnostic,
|
|
156
|
+
onDataRequestCancel,
|
|
157
|
+
onDataProjection,
|
|
158
|
+
onDataLoadingConfigError,
|
|
159
|
+
isControlled,
|
|
160
|
+
multiple
|
|
161
|
+
};
|
|
162
|
+
const ariaBusyInputsRef = React.useRef({ consumerAriaBusy, loading });
|
|
163
|
+
ariaBusyInputsRef.current = { consumerAriaBusy, loading };
|
|
164
|
+
const initializingRef = React.useRef(true);
|
|
165
|
+
const compatibilityFailureReportedRef = React.useRef(false);
|
|
166
|
+
const unusableRef = React.useRef(false);
|
|
167
|
+
const [acceptedProtocol, setAcceptedProtocol] = React.useState("legacy");
|
|
168
|
+
const [isCoreModuleLoaded, setIsCoreModuleLoaded] = React.useState(false);
|
|
169
|
+
const [isAcknowledgedQualified, setIsAcknowledgedQualified] = React.useState(false);
|
|
170
|
+
const [isUnusable, setIsUnusable] = React.useState(false);
|
|
94
171
|
const resolvedDropdownPlacement = React.useMemo(() => {
|
|
95
172
|
if (placement == null ? void 0 : placement.startsWith("top")) return "top";
|
|
96
173
|
return "bottom";
|
|
97
174
|
}, [placement]);
|
|
98
|
-
const [isControlled] = React.useState(value !== void 0);
|
|
99
|
-
const [internalValue, setInternalValue] = React.useState(defaultValue);
|
|
100
|
-
const hasAppliedInitialValueRef = React.useRef(false);
|
|
101
175
|
const reactRendererCache = React.useRef(
|
|
102
176
|
/* @__PURE__ */ new Map()
|
|
103
177
|
);
|
|
@@ -148,8 +222,8 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
148
222
|
const resolvedOptionRenderer = React.useMemo(() => {
|
|
149
223
|
if (optionRenderer) {
|
|
150
224
|
return (item, index, helpers) => {
|
|
151
|
-
var
|
|
152
|
-
return ((
|
|
225
|
+
var _a2;
|
|
226
|
+
return ((_a2 = optionRendererRef.current) == null ? void 0 : _a2.call(optionRendererRef, item, index, helpers)) || document.createElement("div");
|
|
153
227
|
};
|
|
154
228
|
}
|
|
155
229
|
const hasReactRenderer = !!(customRenderer ?? renderItem);
|
|
@@ -228,6 +302,240 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
228
302
|
reactRendererCache.current.clear();
|
|
229
303
|
}, [!!optionRenderer, !!(customRenderer ?? renderItem), scheduleRootUnmount]);
|
|
230
304
|
const [isElementReady, setIsElementReady] = React.useState(false);
|
|
305
|
+
const acknowledgedRequested = acceptedProtocol === "acknowledged" || ((_a = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _a.protocol) === "acknowledged";
|
|
306
|
+
const dataLoadingConfigured = (coreConfig == null ? void 0 : coreConfig.dataLoading) !== void 0;
|
|
307
|
+
const coreFacadeRequired = acknowledgedRequested || dataLoadingConfigured;
|
|
308
|
+
const isElementUsable = isElementReady && (!acknowledgedRequested || isAcknowledgedQualified) && (!coreFacadeRequired || isCoreModuleLoaded) && !isUnusable;
|
|
309
|
+
const markUnusable = React.useCallback(
|
|
310
|
+
(message) => {
|
|
311
|
+
if (unusableRef.current) return;
|
|
312
|
+
unusableRef.current = true;
|
|
313
|
+
setIsUnusable(true);
|
|
314
|
+
const element = elementRef.current;
|
|
315
|
+
const { consumerAriaBusy: currentConsumerBusy } = ariaBusyInputsRef.current;
|
|
316
|
+
if (element) {
|
|
317
|
+
if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
|
|
318
|
+
else element.setAttribute("aria-busy", String(currentConsumerBusy));
|
|
319
|
+
}
|
|
320
|
+
if (!compatibilityFailureReportedRef.current) {
|
|
321
|
+
compatibilityFailureReportedRef.current = true;
|
|
322
|
+
console.error(`[Smilodon React] ${message}`);
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
[]
|
|
326
|
+
);
|
|
327
|
+
const syncHostBusy = React.useCallback((element) => {
|
|
328
|
+
const { consumerAriaBusy: currentConsumerBusy, loading: externalBusy } = ariaBusyInputsRef.current;
|
|
329
|
+
if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged" && !unusableRef.current) {
|
|
330
|
+
const composed = composeBusyToken(currentConsumerBusy, externalBusy);
|
|
331
|
+
if (composed === void 0) element.removeAttribute("aria-busy");
|
|
332
|
+
else element.setAttribute("aria-busy", String(composed));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (currentConsumerBusy === void 0) element.removeAttribute("aria-busy");
|
|
336
|
+
else element.setAttribute("aria-busy", String(currentConsumerBusy));
|
|
337
|
+
}, []);
|
|
338
|
+
const applyInstanceConfig = React.useCallback(
|
|
339
|
+
(element, config) => {
|
|
340
|
+
if (!(element == null ? void 0 : element.updateConfig) || unusableRef.current) return;
|
|
341
|
+
if (configUpdateInProgressRef.current) {
|
|
342
|
+
queuedConfigUpdatesRef.current.push({ ...config });
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
configUpdateInProgressRef.current = true;
|
|
346
|
+
const queue = [{ ...config }];
|
|
347
|
+
let processed = 0;
|
|
348
|
+
try {
|
|
349
|
+
while (queue.length > 0 && !unusableRef.current) {
|
|
350
|
+
if (processed++ >= 100) {
|
|
351
|
+
queuedConfigUpdatesRef.current = [];
|
|
352
|
+
markUnusable(
|
|
353
|
+
"Too many reentrant configuration updates were queued; the wrapper has been stopped to avoid an unbounded update loop."
|
|
354
|
+
);
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
const currentConfig = queue.shift();
|
|
358
|
+
const module2 = coreModuleRef.current;
|
|
359
|
+
let validation;
|
|
360
|
+
if (currentConfig.dataLoading !== void 0) {
|
|
361
|
+
const candidate = isPlainRecord(currentConfig.dataLoading) ? { ...acceptedDataLoadingConfigRef.current, ...currentConfig.dataLoading } : currentConfig.dataLoading;
|
|
362
|
+
if (!module2) {
|
|
363
|
+
markUnusable(
|
|
364
|
+
"The core validator is unavailable; acknowledged configuration cannot be reconciled safely."
|
|
365
|
+
);
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
validation = module2.validateDataLoadingConfig(candidate);
|
|
370
|
+
} catch (error2) {
|
|
371
|
+
markUnusable(
|
|
372
|
+
`Core data-loading preflight failed unexpectedly: ${String(error2)}`
|
|
373
|
+
);
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
const update = { sawConfigError: false };
|
|
378
|
+
configUpdateStackRef.current.push(update);
|
|
379
|
+
let threw = false;
|
|
380
|
+
try {
|
|
381
|
+
element.updateConfig(currentConfig);
|
|
382
|
+
} catch (error2) {
|
|
383
|
+
threw = true;
|
|
384
|
+
markUnusable(
|
|
385
|
+
`Core configuration acceptance is uncertain after updateConfig() threw: ${String(error2)}`
|
|
386
|
+
);
|
|
387
|
+
} finally {
|
|
388
|
+
configUpdateStackRef.current.pop();
|
|
389
|
+
}
|
|
390
|
+
if ((validation == null ? void 0 : validation.valid) && !threw) {
|
|
391
|
+
if (update.sawConfigError) {
|
|
392
|
+
markUnusable(
|
|
393
|
+
"Core reported a data-loading configuration error for a preflight-valid candidate; the accepted protocol is uncertain."
|
|
394
|
+
);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
acceptedDataLoadingConfigRef.current = { ...validation.value };
|
|
398
|
+
setAcceptedProtocol(validation.value.protocol);
|
|
399
|
+
syncHostBusy(element);
|
|
400
|
+
}
|
|
401
|
+
if (queuedConfigUpdatesRef.current.length > 0) {
|
|
402
|
+
queue.push(...queuedConfigUpdatesRef.current);
|
|
403
|
+
queuedConfigUpdatesRef.current = [];
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
} finally {
|
|
407
|
+
configUpdateInProgressRef.current = false;
|
|
408
|
+
}
|
|
409
|
+
},
|
|
410
|
+
[markUnusable, syncHostBusy]
|
|
411
|
+
);
|
|
412
|
+
const requiresAcknowledgedQualification = acceptedProtocol === "acknowledged" || ((_b = coreConfig == null ? void 0 : coreConfig.dataLoading) == null ? void 0 : _b.protocol) === "acknowledged";
|
|
413
|
+
const qualifyAcknowledgedElement = React.useCallback(() => {
|
|
414
|
+
const element = elementRef.current;
|
|
415
|
+
const module2 = coreModuleRef.current;
|
|
416
|
+
if (!element || !module2 || typeof customElements === "undefined") return false;
|
|
417
|
+
const registered = customElements.get("enhanced-select");
|
|
418
|
+
const observed = registered == null ? void 0 : registered.observedAttributes;
|
|
419
|
+
const compatible = registered === module2.EnhancedSelect && element.constructor === module2.EnhancedSelect && Array.isArray(observed) && observed.includes("aria-busy") && typeof element.updateConfig === "function" && typeof element.startDataLoading === "function" && typeof element.getDataLoadingState === "function" && typeof element.completeDataRequest === "function";
|
|
420
|
+
if (!compatible) {
|
|
421
|
+
markUnusable(
|
|
422
|
+
"Acknowledged data loading requires the exact peer-resolved EnhancedSelect constructor with the Phase 2F facade and aria-busy observation support."
|
|
423
|
+
);
|
|
424
|
+
return false;
|
|
425
|
+
}
|
|
426
|
+
setIsAcknowledgedQualified(true);
|
|
427
|
+
return true;
|
|
428
|
+
}, [markUnusable]);
|
|
429
|
+
const subscribeToCoreEvents = React.useCallback((element) => {
|
|
430
|
+
const currentSubscription = activeListenersRef.current;
|
|
431
|
+
if ((currentSubscription == null ? void 0 : currentSubscription.element) === element) return currentSubscription.dispose;
|
|
432
|
+
currentSubscription == null ? void 0 : currentSubscription.dispose();
|
|
433
|
+
const handleSelect = (event) => {
|
|
434
|
+
var _a2, _b2;
|
|
435
|
+
const detail = event.detail;
|
|
436
|
+
(_b2 = (_a2 = callbackStateRef.current).onSelect) == null ? void 0 : _b2.call(_a2, detail.item, detail.index);
|
|
437
|
+
};
|
|
438
|
+
const handleChange = (event) => {
|
|
439
|
+
var _a2;
|
|
440
|
+
const { selectedItems, selectedValues } = event.detail;
|
|
441
|
+
const callbacks = callbackStateRef.current;
|
|
442
|
+
const values = selectedValues;
|
|
443
|
+
const nextSingleValue = values.length > 0 ? values[0] : "";
|
|
444
|
+
if (initializingRef.current) return;
|
|
445
|
+
if (!callbacks.isControlled) {
|
|
446
|
+
setInternalValue(callbacks.multiple ? values : nextSingleValue);
|
|
447
|
+
}
|
|
448
|
+
(_a2 = callbacks.onChange) == null ? void 0 : _a2.call(
|
|
449
|
+
callbacks,
|
|
450
|
+
callbacks.multiple ? values : nextSingleValue,
|
|
451
|
+
selectedItems
|
|
452
|
+
);
|
|
453
|
+
};
|
|
454
|
+
const handleOpen = () => {
|
|
455
|
+
var _a2, _b2;
|
|
456
|
+
return (_b2 = (_a2 = callbackStateRef.current).onOpen) == null ? void 0 : _b2.call(_a2);
|
|
457
|
+
};
|
|
458
|
+
const handleClose = () => {
|
|
459
|
+
var _a2, _b2;
|
|
460
|
+
return (_b2 = (_a2 = callbackStateRef.current).onClose) == null ? void 0 : _b2.call(_a2);
|
|
461
|
+
};
|
|
462
|
+
const handleSearch = (event) => {
|
|
463
|
+
const { query, results, count, request } = event.detail;
|
|
464
|
+
const callback = callbackStateRef.current.onSearch;
|
|
465
|
+
if (!callback) return;
|
|
466
|
+
if (request) callback(query, results, count, request);
|
|
467
|
+
else callback(query, results, count);
|
|
468
|
+
};
|
|
469
|
+
const handleLoadMore = (event) => {
|
|
470
|
+
const { page, request } = event.detail;
|
|
471
|
+
const callback = callbackStateRef.current.onLoadMore;
|
|
472
|
+
if (!callback) return;
|
|
473
|
+
if (request) callback(page, request);
|
|
474
|
+
else callback(page);
|
|
475
|
+
};
|
|
476
|
+
const handleClear = (event) => {
|
|
477
|
+
var _a2, _b2;
|
|
478
|
+
const { clearedSelection, clearedSearch } = event.detail;
|
|
479
|
+
(_b2 = (_a2 = callbackStateRef.current).onClear) == null ? void 0 : _b2.call(_a2, { clearedSelection, clearedSearch });
|
|
480
|
+
};
|
|
481
|
+
const handleDiagnostic = (event) => {
|
|
482
|
+
var _a2, _b2;
|
|
483
|
+
(_b2 = (_a2 = callbackStateRef.current).onDiagnostic) == null ? void 0 : _b2.call(
|
|
484
|
+
_a2,
|
|
485
|
+
event.detail
|
|
486
|
+
);
|
|
487
|
+
};
|
|
488
|
+
const handleDataRequestCancel = (event) => {
|
|
489
|
+
var _a2, _b2;
|
|
490
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataRequestCancel) == null ? void 0 : _b2.call(
|
|
491
|
+
_a2,
|
|
492
|
+
event.detail
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
const handleDataProjection = (event) => {
|
|
496
|
+
var _a2, _b2;
|
|
497
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataProjection) == null ? void 0 : _b2.call(
|
|
498
|
+
_a2,
|
|
499
|
+
event.detail
|
|
500
|
+
);
|
|
501
|
+
};
|
|
502
|
+
const handleDataLoadingConfigError = (event) => {
|
|
503
|
+
var _a2, _b2;
|
|
504
|
+
const activeUpdate = configUpdateStackRef.current[configUpdateStackRef.current.length - 1];
|
|
505
|
+
if (activeUpdate) activeUpdate.sawConfigError = true;
|
|
506
|
+
(_b2 = (_a2 = callbackStateRef.current).onDataLoadingConfigError) == null ? void 0 : _b2.call(
|
|
507
|
+
_a2,
|
|
508
|
+
event.detail
|
|
509
|
+
);
|
|
510
|
+
};
|
|
511
|
+
const listeners = [
|
|
512
|
+
["select", handleSelect],
|
|
513
|
+
["change", handleChange],
|
|
514
|
+
["open", handleOpen],
|
|
515
|
+
["close", handleClose],
|
|
516
|
+
["search", handleSearch],
|
|
517
|
+
["loadMore", handleLoadMore],
|
|
518
|
+
["clear", handleClear],
|
|
519
|
+
["diagnostic", handleDiagnostic],
|
|
520
|
+
["dataRequestCancel", handleDataRequestCancel],
|
|
521
|
+
["dataProjection", handleDataProjection],
|
|
522
|
+
["dataLoadingConfigError", handleDataLoadingConfigError]
|
|
523
|
+
];
|
|
524
|
+
for (const [name, listener] of listeners) {
|
|
525
|
+
element.addEventListener(name, listener);
|
|
526
|
+
}
|
|
527
|
+
const dispose = () => {
|
|
528
|
+
var _a2;
|
|
529
|
+
if (((_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose) === dispose) {
|
|
530
|
+
activeListenersRef.current = null;
|
|
531
|
+
}
|
|
532
|
+
for (const [name, listener] of listeners) {
|
|
533
|
+
element.removeEventListener(name, listener);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
activeListenersRef.current = { element, dispose };
|
|
537
|
+
return dispose;
|
|
538
|
+
}, []);
|
|
231
539
|
React.useEffect(() => {
|
|
232
540
|
const element = elementRef.current;
|
|
233
541
|
if (!element || !isElementReady) return;
|
|
@@ -258,23 +566,61 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
258
566
|
}
|
|
259
567
|
}, [isElementReady, classMap, areClassMapsEqual]);
|
|
260
568
|
React.useEffect(() => {
|
|
261
|
-
if (typeof window
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
569
|
+
if (typeof window === "undefined" || typeof customElements === "undefined") return;
|
|
570
|
+
let active = true;
|
|
571
|
+
const existingConstructor = customElements.get("enhanced-select");
|
|
572
|
+
if (existingConstructor) setIsElementReady(true);
|
|
573
|
+
import("@smilodon/core").then((module2) => {
|
|
574
|
+
if (!active) return;
|
|
575
|
+
coreModuleRef.current = module2;
|
|
576
|
+
setIsCoreModuleLoaded(true);
|
|
577
|
+
const currentConstructor = customElements.get("enhanced-select");
|
|
578
|
+
if (!currentConstructor) {
|
|
579
|
+
customElements.define("enhanced-select", module2.EnhancedSelect);
|
|
271
580
|
}
|
|
272
|
-
|
|
581
|
+
setIsElementReady(true);
|
|
582
|
+
}).catch((error2) => {
|
|
583
|
+
if (!active) return;
|
|
584
|
+
if (requiresAcknowledgedQualification) {
|
|
585
|
+
markUnusable(`Unable to load the compatible core runtime: ${String(error2)}`);
|
|
586
|
+
} else if (!customElements.get("enhanced-select")) {
|
|
587
|
+
console.error(`[Smilodon React] Unable to register enhanced-select: ${String(error2)}`);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
return () => {
|
|
591
|
+
active = false;
|
|
592
|
+
};
|
|
593
|
+
}, [markUnusable]);
|
|
594
|
+
React.useEffect(() => {
|
|
595
|
+
if (!isElementReady || !isCoreModuleLoaded || !requiresAcknowledgedQualification || isUnusable) return;
|
|
596
|
+
qualifyAcknowledgedElement();
|
|
597
|
+
}, [
|
|
598
|
+
isElementReady,
|
|
599
|
+
isCoreModuleLoaded,
|
|
600
|
+
requiresAcknowledgedQualification,
|
|
601
|
+
isUnusable,
|
|
602
|
+
qualifyAcknowledgedElement
|
|
603
|
+
]);
|
|
604
|
+
React.useEffect(() => {
|
|
605
|
+
const element = elementRef.current;
|
|
606
|
+
if (!(acknowledgedRequested || dataLoadingConfigured) || !isElementUsable || !element) return;
|
|
607
|
+
return subscribeToCoreEvents(element);
|
|
608
|
+
}, [
|
|
609
|
+
acknowledgedRequested,
|
|
610
|
+
dataLoadingConfigured,
|
|
611
|
+
isElementUsable,
|
|
612
|
+
subscribeToCoreEvents
|
|
613
|
+
]);
|
|
614
|
+
React.useEffect(() => {
|
|
615
|
+
return () => {
|
|
616
|
+
var _a2;
|
|
617
|
+
return (_a2 = activeListenersRef.current) == null ? void 0 : _a2.dispose();
|
|
618
|
+
};
|
|
273
619
|
}, []);
|
|
274
620
|
React.useEffect(() => {
|
|
275
|
-
var
|
|
621
|
+
var _a2;
|
|
276
622
|
const element = elementRef.current;
|
|
277
|
-
if (!element || !
|
|
623
|
+
if (!element || !isElementUsable) return;
|
|
278
624
|
if (!element.setItems) {
|
|
279
625
|
console.warn("Enhanced select element not fully initialized yet");
|
|
280
626
|
return;
|
|
@@ -334,13 +680,13 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
334
680
|
autoMitigateRuntimeModeSwitch
|
|
335
681
|
}
|
|
336
682
|
};
|
|
337
|
-
element
|
|
683
|
+
applyInstanceConfig(element, config);
|
|
338
684
|
if (coreConfig) {
|
|
339
|
-
element
|
|
685
|
+
applyInstanceConfig(element, coreConfig);
|
|
340
686
|
}
|
|
341
687
|
if (!isControlled && !hasAppliedInitialValueRef.current && internalValue !== void 0) {
|
|
342
688
|
const values = Array.isArray(internalValue) ? internalValue : [internalValue];
|
|
343
|
-
const currentValues = ((
|
|
689
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
344
690
|
if (!areValuesEqual(values, currentValues)) {
|
|
345
691
|
element.setSelectedValues(values);
|
|
346
692
|
}
|
|
@@ -355,7 +701,7 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
355
701
|
element.setRequired(true);
|
|
356
702
|
}
|
|
357
703
|
}, [
|
|
358
|
-
|
|
704
|
+
isElementUsable,
|
|
359
705
|
items,
|
|
360
706
|
groupedItems,
|
|
361
707
|
searchable,
|
|
@@ -397,11 +743,12 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
397
743
|
required,
|
|
398
744
|
internalValue,
|
|
399
745
|
isControlled,
|
|
400
|
-
areValuesEqual
|
|
746
|
+
areValuesEqual,
|
|
747
|
+
applyInstanceConfig
|
|
401
748
|
]);
|
|
402
749
|
React.useEffect(() => {
|
|
403
750
|
const element = elementRef.current;
|
|
404
|
-
if (!element || !
|
|
751
|
+
if (!element || !isElementUsable || !element.setItems) return;
|
|
405
752
|
if (groupedItems) {
|
|
406
753
|
element.setGroupedItems(groupedItems);
|
|
407
754
|
} else if (items && items.length && items[0] && items[0].group !== void 0) {
|
|
@@ -419,23 +766,23 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
419
766
|
} else {
|
|
420
767
|
element.setItems(items);
|
|
421
768
|
}
|
|
422
|
-
}, [items, groupedItems,
|
|
769
|
+
}, [items, groupedItems, isElementUsable]);
|
|
423
770
|
React.useEffect(() => {
|
|
424
|
-
var
|
|
771
|
+
var _a2;
|
|
425
772
|
const element = elementRef.current;
|
|
426
|
-
if (!element || !isControlled || !
|
|
773
|
+
if (!element || !isControlled || !isElementUsable || !element.setSelectedValues)
|
|
427
774
|
return;
|
|
428
775
|
if (value !== void 0) {
|
|
429
776
|
const values = Array.isArray(value) ? value : [value];
|
|
430
|
-
const currentValues = ((
|
|
777
|
+
const currentValues = ((_a2 = element.getSelectedValues) == null ? void 0 : _a2.call(element)) || [];
|
|
431
778
|
if (!areValuesEqual(values, currentValues)) {
|
|
432
779
|
element.setSelectedValues(values);
|
|
433
780
|
}
|
|
434
781
|
}
|
|
435
|
-
}, [value, isControlled,
|
|
782
|
+
}, [value, isControlled, isElementUsable, areValuesEqual]);
|
|
436
783
|
React.useEffect(() => {
|
|
437
784
|
const element = elementRef.current;
|
|
438
|
-
if (!element || !
|
|
785
|
+
if (!element || !isElementUsable || !element.updateConfig) return;
|
|
439
786
|
const config = {
|
|
440
787
|
searchable,
|
|
441
788
|
placeholder,
|
|
@@ -485,9 +832,9 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
485
832
|
autoMitigateRuntimeModeSwitch
|
|
486
833
|
}
|
|
487
834
|
};
|
|
488
|
-
element
|
|
835
|
+
applyInstanceConfig(element, config);
|
|
489
836
|
if (coreConfig) {
|
|
490
|
-
element
|
|
837
|
+
applyInstanceConfig(element, coreConfig);
|
|
491
838
|
}
|
|
492
839
|
}, [
|
|
493
840
|
searchable,
|
|
@@ -523,185 +870,210 @@ const Select = React.forwardRef((props, ref) => {
|
|
|
523
870
|
autoMitigateRuntimeModeSwitch,
|
|
524
871
|
direction,
|
|
525
872
|
resolvedDropdownPlacement,
|
|
526
|
-
|
|
873
|
+
isElementUsable,
|
|
874
|
+
applyInstanceConfig
|
|
527
875
|
]);
|
|
528
876
|
React.useEffect(() => {
|
|
529
877
|
const element = elementRef.current;
|
|
530
|
-
if (!element || !
|
|
878
|
+
if (!element || !isElementUsable) return;
|
|
531
879
|
if (error) {
|
|
532
880
|
if (element.setError)
|
|
533
881
|
element.setError(errorMessage || "Invalid selection");
|
|
534
882
|
} else {
|
|
535
883
|
if (element.clearError) element.clearError();
|
|
536
884
|
}
|
|
537
|
-
}, [error, errorMessage,
|
|
885
|
+
}, [error, errorMessage, isElementUsable]);
|
|
538
886
|
React.useEffect(() => {
|
|
539
887
|
const element = elementRef.current;
|
|
540
|
-
if (!element || !
|
|
888
|
+
if (!element || !isElementUsable || !element.setRequired) return;
|
|
541
889
|
element.setRequired(required);
|
|
542
|
-
}, [required,
|
|
890
|
+
}, [required, isElementUsable]);
|
|
543
891
|
React.useEffect(() => {
|
|
892
|
+
var _a2, _b2;
|
|
544
893
|
const element = elementRef.current;
|
|
545
|
-
if (!element) return;
|
|
546
|
-
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
894
|
+
if (!element || !isElementUsable) return;
|
|
895
|
+
if (isCoreModuleLoaded && queuedImperativeConfigsRef.current.length > 0) {
|
|
896
|
+
const queued = queuedImperativeConfigsRef.current;
|
|
897
|
+
queuedImperativeConfigsRef.current = [];
|
|
898
|
+
for (const config of queued) {
|
|
899
|
+
const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
|
|
900
|
+
if (requestsAcknowledged && !qualifyAcknowledgedElement()) break;
|
|
901
|
+
if (config.dataLoading !== void 0 || requestsAcknowledged) {
|
|
902
|
+
subscribeToCoreEvents(element);
|
|
903
|
+
}
|
|
904
|
+
applyInstanceConfig(element, config);
|
|
905
|
+
if (unusableRef.current) break;
|
|
556
906
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
onOpen == null ? void 0 : onOpen();
|
|
564
|
-
};
|
|
565
|
-
const handleClose = (e) => {
|
|
566
|
-
onClose == null ? void 0 : onClose();
|
|
567
|
-
};
|
|
568
|
-
const handleSearch = (e) => {
|
|
569
|
-
const { query, results, count } = e.detail;
|
|
570
|
-
onSearch == null ? void 0 : onSearch(query, results, count);
|
|
571
|
-
};
|
|
572
|
-
const handleLoadMore = (e) => {
|
|
573
|
-
const { page } = e.detail;
|
|
574
|
-
onLoadMore == null ? void 0 : onLoadMore(page);
|
|
575
|
-
};
|
|
576
|
-
const handleClear = (e) => {
|
|
577
|
-
onClear == null ? void 0 : onClear({
|
|
578
|
-
clearedSelection: e.detail.clearedSelection,
|
|
579
|
-
clearedSearch: e.detail.clearedSearch
|
|
580
|
-
});
|
|
581
|
-
};
|
|
582
|
-
const handleDiagnostic = (e) => {
|
|
583
|
-
onDiagnostic == null ? void 0 : onDiagnostic(e.detail);
|
|
584
|
-
};
|
|
585
|
-
element.addEventListener("select", handleSelect);
|
|
586
|
-
element.addEventListener("change", handleChange);
|
|
587
|
-
element.addEventListener("open", handleOpen);
|
|
588
|
-
element.addEventListener("close", handleClose);
|
|
589
|
-
element.addEventListener("search", handleSearch);
|
|
590
|
-
element.addEventListener("loadMore", handleLoadMore);
|
|
591
|
-
element.addEventListener("clear", handleClear);
|
|
592
|
-
element.addEventListener("diagnostic", handleDiagnostic);
|
|
593
|
-
return () => {
|
|
594
|
-
element.removeEventListener("select", handleSelect);
|
|
595
|
-
element.removeEventListener("change", handleChange);
|
|
596
|
-
element.removeEventListener("open", handleOpen);
|
|
597
|
-
element.removeEventListener("close", handleClose);
|
|
598
|
-
element.removeEventListener("search", handleSearch);
|
|
599
|
-
element.removeEventListener("loadMore", handleLoadMore);
|
|
600
|
-
element.removeEventListener("clear", handleClear);
|
|
601
|
-
element.removeEventListener("diagnostic", handleDiagnostic);
|
|
602
|
-
};
|
|
907
|
+
}
|
|
908
|
+
initializingRef.current = false;
|
|
909
|
+
syncHostBusy(element);
|
|
910
|
+
if (acceptedDataLoadingConfigRef.current.protocol === "acknowledged") {
|
|
911
|
+
(_b2 = element.startDataLoading) == null ? void 0 : _b2.call(element);
|
|
912
|
+
}
|
|
603
913
|
}, [
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
914
|
+
isElementUsable,
|
|
915
|
+
acceptedProtocol,
|
|
916
|
+
acknowledgedRequested,
|
|
917
|
+
coreConfig,
|
|
918
|
+
items,
|
|
919
|
+
groupedItems,
|
|
920
|
+
value,
|
|
921
|
+
defaultValue,
|
|
922
|
+
loading,
|
|
923
|
+
consumerAriaBusy,
|
|
924
|
+
syncHostBusy,
|
|
925
|
+
isCoreModuleLoaded,
|
|
926
|
+
qualifyAcknowledgedElement,
|
|
927
|
+
subscribeToCoreEvents,
|
|
928
|
+
applyInstanceConfig
|
|
929
|
+
]);
|
|
930
|
+
React.useEffect(() => {
|
|
931
|
+
const element = elementRef.current;
|
|
932
|
+
if (!element || acknowledgedRequested || dataLoadingConfigured || !isElementReady) return;
|
|
933
|
+
return subscribeToCoreEvents(element);
|
|
934
|
+
}, [
|
|
935
|
+
acknowledgedRequested,
|
|
936
|
+
dataLoadingConfigured,
|
|
937
|
+
isElementReady,
|
|
938
|
+
subscribeToCoreEvents
|
|
614
939
|
]);
|
|
615
940
|
React.useImperativeHandle(ref, () => ({
|
|
616
941
|
focus: () => {
|
|
617
|
-
var
|
|
618
|
-
(
|
|
942
|
+
var _a2;
|
|
943
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.focus();
|
|
619
944
|
},
|
|
620
945
|
open: () => {
|
|
621
|
-
var
|
|
622
|
-
(
|
|
946
|
+
var _a2;
|
|
947
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.open();
|
|
623
948
|
},
|
|
624
949
|
close: () => {
|
|
625
|
-
var
|
|
626
|
-
(
|
|
950
|
+
var _a2;
|
|
951
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.close();
|
|
627
952
|
},
|
|
628
953
|
getSelectedItems: () => {
|
|
629
|
-
var
|
|
630
|
-
return ((
|
|
954
|
+
var _a2;
|
|
955
|
+
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedItems()) || [];
|
|
631
956
|
},
|
|
632
957
|
getSelectedValues: () => {
|
|
633
|
-
var
|
|
634
|
-
return ((
|
|
958
|
+
var _a2;
|
|
959
|
+
return ((_a2 = elementRef.current) == null ? void 0 : _a2.getSelectedValues()) || [];
|
|
635
960
|
},
|
|
636
961
|
setItems: (items2) => {
|
|
637
|
-
var
|
|
638
|
-
(
|
|
962
|
+
var _a2;
|
|
963
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setItems(items2);
|
|
639
964
|
},
|
|
640
965
|
setGroupedItems: (groups) => {
|
|
641
|
-
var
|
|
642
|
-
(
|
|
966
|
+
var _a2;
|
|
967
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setGroupedItems(groups);
|
|
643
968
|
},
|
|
644
969
|
clear: () => {
|
|
645
|
-
var
|
|
646
|
-
(
|
|
970
|
+
var _a2;
|
|
971
|
+
(_a2 = elementRef.current) == null ? void 0 : _a2.setSelectedValues([]);
|
|
647
972
|
if (!isControlled) {
|
|
648
973
|
setInternalValue(multiple ? [] : void 0);
|
|
649
974
|
}
|
|
650
975
|
onChange == null ? void 0 : onChange(multiple ? [] : "", []);
|
|
651
976
|
},
|
|
652
977
|
clearSearch: () => {
|
|
653
|
-
var
|
|
654
|
-
(
|
|
978
|
+
var _a2, _b2;
|
|
979
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearSearch) == null ? void 0 : _b2.call(_a2);
|
|
655
980
|
},
|
|
656
981
|
updateConfig: (config) => {
|
|
657
|
-
var
|
|
658
|
-
|
|
982
|
+
var _a2;
|
|
983
|
+
const element = elementRef.current;
|
|
984
|
+
if (!element || unusableRef.current) return;
|
|
985
|
+
const requestsAcknowledged = acceptedDataLoadingConfigRef.current.protocol === "acknowledged" || ((_a2 = config.dataLoading) == null ? void 0 : _a2.protocol) === "acknowledged";
|
|
986
|
+
if (!isElementReady || !isCoreModuleLoaded) {
|
|
987
|
+
queuedImperativeConfigsRef.current.push({ ...config });
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (requestsAcknowledged && !qualifyAcknowledgedElement()) return;
|
|
991
|
+
if (config.dataLoading !== void 0 || requestsAcknowledged) {
|
|
992
|
+
subscribeToCoreEvents(element);
|
|
993
|
+
}
|
|
994
|
+
applyInstanceConfig(element, config);
|
|
995
|
+
},
|
|
996
|
+
getDataLoadingState: () => {
|
|
997
|
+
var _a2, _b2, _c;
|
|
998
|
+
const snapshot = (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getDataLoadingState) == null ? void 0 : _b2.call(_a2);
|
|
999
|
+
if (snapshot) return snapshot;
|
|
1000
|
+
return {
|
|
1001
|
+
status: "idle",
|
|
1002
|
+
connected: Boolean((_c = elementRef.current) == null ? void 0 : _c.isConnected),
|
|
1003
|
+
busy: false,
|
|
1004
|
+
projectionPending: false,
|
|
1005
|
+
queryGeneration: 0,
|
|
1006
|
+
activeRequest: null,
|
|
1007
|
+
hasMore: false,
|
|
1008
|
+
nextEligiblePosition: {
|
|
1009
|
+
mode: "page",
|
|
1010
|
+
page: DEFAULT_DATA_LOADING_CONFIG.firstPage
|
|
1011
|
+
},
|
|
1012
|
+
error: null,
|
|
1013
|
+
resourceLimit: null
|
|
1014
|
+
};
|
|
1015
|
+
},
|
|
1016
|
+
completeDataRequest: (completion) => {
|
|
1017
|
+
var _a2, _b2;
|
|
1018
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.completeDataRequest) == null ? void 0 : _b2.call(_a2, completion)) ?? "unknown-request";
|
|
659
1019
|
},
|
|
660
1020
|
setError: (message) => {
|
|
661
|
-
var
|
|
662
|
-
(
|
|
1021
|
+
var _a2, _b2;
|
|
1022
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setError) == null ? void 0 : _b2.call(_a2, message);
|
|
663
1023
|
},
|
|
664
1024
|
clearError: () => {
|
|
665
|
-
var
|
|
666
|
-
(
|
|
1025
|
+
var _a2, _b2;
|
|
1026
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearError) == null ? void 0 : _b2.call(_a2);
|
|
667
1027
|
},
|
|
668
1028
|
setRequired: (isRequired) => {
|
|
669
|
-
var
|
|
670
|
-
(
|
|
1029
|
+
var _a2, _b2;
|
|
1030
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setRequired) == null ? void 0 : _b2.call(_a2, isRequired);
|
|
671
1031
|
},
|
|
672
1032
|
validate: () => {
|
|
673
|
-
var
|
|
674
|
-
return ((
|
|
1033
|
+
var _a2, _b2;
|
|
1034
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.validate) == null ? void 0 : _b2.call(_a2)) ?? true;
|
|
675
1035
|
},
|
|
676
1036
|
getCapabilities: () => {
|
|
677
|
-
var
|
|
678
|
-
return (
|
|
1037
|
+
var _a2, _b2;
|
|
1038
|
+
return (_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getCapabilities) == null ? void 0 : _b2.call(_a2);
|
|
679
1039
|
},
|
|
680
1040
|
getKnownLimitations: () => {
|
|
681
|
-
var
|
|
682
|
-
return ((
|
|
1041
|
+
var _a2, _b2;
|
|
1042
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getKnownLimitations) == null ? void 0 : _b2.call(_a2)) || [];
|
|
683
1043
|
},
|
|
684
1044
|
getTrackingSnapshot: () => {
|
|
685
|
-
var
|
|
686
|
-
return ((
|
|
1045
|
+
var _a2, _b2;
|
|
1046
|
+
return ((_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.getTrackingSnapshot) == null ? void 0 : _b2.call(_a2)) || {
|
|
687
1047
|
events: [],
|
|
688
1048
|
styles: [],
|
|
689
1049
|
limitations: []
|
|
690
1050
|
};
|
|
691
1051
|
},
|
|
692
1052
|
clearTracking: (source) => {
|
|
693
|
-
var
|
|
694
|
-
(
|
|
1053
|
+
var _a2, _b2;
|
|
1054
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.clearTracking) == null ? void 0 : _b2.call(_a2, source);
|
|
695
1055
|
},
|
|
696
1056
|
setLimitationPolicies: (policies) => {
|
|
697
|
-
var
|
|
698
|
-
(
|
|
1057
|
+
var _a2, _b2;
|
|
1058
|
+
(_b2 = (_a2 = elementRef.current) == null ? void 0 : _a2.setLimitationPolicies) == null ? void 0 : _b2.call(_a2, policies);
|
|
699
1059
|
}
|
|
700
|
-
})
|
|
1060
|
+
}), [
|
|
1061
|
+
applyInstanceConfig,
|
|
1062
|
+
isElementReady,
|
|
1063
|
+
isCoreModuleLoaded,
|
|
1064
|
+
qualifyAcknowledgedElement,
|
|
1065
|
+
subscribeToCoreEvents,
|
|
1066
|
+
isElementUsable,
|
|
1067
|
+
isControlled,
|
|
1068
|
+
multiple,
|
|
1069
|
+
onChange
|
|
1070
|
+
]);
|
|
1071
|
+
const renderedAriaBusy = acceptedProtocol === "acknowledged" && !isUnusable ? composeBusyToken(consumerAriaBusy, loading) : consumerAriaBusy;
|
|
701
1072
|
return React.createElement("enhanced-select", {
|
|
702
1073
|
ref: elementRef,
|
|
703
1074
|
...hostProps,
|
|
704
|
-
|
|
1075
|
+
"aria-busy": renderedAriaBusy,
|
|
1076
|
+
class: className,
|
|
705
1077
|
dir: direction,
|
|
706
1078
|
style
|
|
707
1079
|
});
|