@smilodon/core 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 +130 -371
- package/dist/index.cjs +1918 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1918 -21
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +1918 -20
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/types/src/components/enhanced-select.d.ts +70 -7
- package/dist/types/src/components/native-select.d.ts +1 -1
- package/dist/types/src/components/select-option.d.ts +2 -2
- package/dist/types/src/config/global-config.d.ts +5 -3
- package/dist/types/src/data-loading/public-config.d.ts +3 -0
- package/dist/types/src/data-loading/public-types.d.ts +171 -0
- package/dist/types/src/data-loading/request-coordinator.d.ts +236 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/native-types.d.ts +5 -0
- package/dist/types/src/renderers/contracts.d.ts +1 -1
- package/dist/types/src/types/limitation.d.ts +6 -0
- package/dist/types/src/types.d.ts +2 -6
- package/dist/types/src/utils/custom-option-pool.d.ts +1 -1
- package/package.json +7 -4
- package/dist/types/src/themes/importer.d.ts +0 -112
- package/dist/types/tests/accessibility-contract.spec.d.ts +0 -1
- package/dist/types/tests/capabilities-tracking.spec.d.ts +0 -1
- package/dist/types/tests/csp.spec.d.ts +0 -5
- package/dist/types/tests/enhanced-option-renderer.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-accessibility-integration.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-active-authority.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-active-parity.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-authority.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-compatibility-projection.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-selection-parity.spec.d.ts +0 -1
- package/dist/types/tests/enhanced-select-virtualization-integration.spec.d.ts +0 -1
- package/dist/types/tests/interaction.spec.d.ts +0 -1
- package/dist/types/tests/item-adapter.spec.d.ts +0 -1
- package/dist/types/tests/item-registry.spec.d.ts +0 -1
- package/dist/types/tests/lifecycle.spec.d.ts +0 -1
- package/dist/types/tests/memory-lifecycle.spec.d.ts +0 -1
- package/dist/types/tests/select-accessibility.spec.d.ts +0 -1
- package/dist/types/tests/select-selection.spec.d.ts +0 -1
- package/dist/types/tests/setup.d.ts +0 -6
- package/dist/types/tests/shadow-dom.spec.d.ts +0 -5
- package/dist/types/tests/smoke.spec.d.ts +0 -1
- package/dist/types/tests/stress.spec.d.ts +0 -5
- package/dist/types/tests/styling-contract.spec.d.ts +0 -1
- package/dist/types/tests/virtualization-contract.spec.d.ts +0 -1
- package/dist/types/tests/virtualizer.spec.d.ts +0 -1
- package/dist/types/tests/web-accessibility-effects.spec.d.ts +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -2253,6 +2253,96 @@
|
|
|
2253
2253
|
selectConfig.resetConfig();
|
|
2254
2254
|
}
|
|
2255
2255
|
|
|
2256
|
+
const DEFAULT_CONFIG = {
|
|
2257
|
+
protocol: 'legacy',
|
|
2258
|
+
searchMode: 'local',
|
|
2259
|
+
paginationMode: 'page',
|
|
2260
|
+
firstPage: 1,
|
|
2261
|
+
};
|
|
2262
|
+
const ALLOWED_FIELDS = new Set([
|
|
2263
|
+
'protocol',
|
|
2264
|
+
'searchMode',
|
|
2265
|
+
'paginationMode',
|
|
2266
|
+
'firstPage',
|
|
2267
|
+
'fetchLimit',
|
|
2268
|
+
]);
|
|
2269
|
+
function issue(path, code, message) {
|
|
2270
|
+
return { path, code, message };
|
|
2271
|
+
}
|
|
2272
|
+
function isRecord$1(value) {
|
|
2273
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
2274
|
+
return false;
|
|
2275
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2276
|
+
return prototype === Object.prototype || prototype === null;
|
|
2277
|
+
}
|
|
2278
|
+
function validatePositiveSafeInteger(candidate, key, issues) {
|
|
2279
|
+
const value = candidate[key];
|
|
2280
|
+
if (value === undefined)
|
|
2281
|
+
return;
|
|
2282
|
+
if (typeof value !== 'number') {
|
|
2283
|
+
issues.push(issue(key, 'invalid-type', `${key} must be a number.`));
|
|
2284
|
+
return;
|
|
2285
|
+
}
|
|
2286
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
2287
|
+
issues.push(issue(key, 'invalid-positive-integer', `${key} must be a positive safe integer.`));
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
/** Validate a complete effective per-instance data-loading configuration. */
|
|
2291
|
+
function validateDataLoadingConfig(candidate) {
|
|
2292
|
+
if (!isRecord$1(candidate)) {
|
|
2293
|
+
return {
|
|
2294
|
+
valid: false,
|
|
2295
|
+
issues: [issue('dataLoading', 'invalid-type', 'dataLoading must be a plain object.')],
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
const issues = [];
|
|
2299
|
+
for (const key of Object.keys(candidate).filter((candidateKey) => !ALLOWED_FIELDS.has(candidateKey)).sort()) {
|
|
2300
|
+
issues.push(issue(key, 'unknown-field', `Unknown dataLoading field: ${key}.`));
|
|
2301
|
+
}
|
|
2302
|
+
const protocolValue = candidate.protocol;
|
|
2303
|
+
const protocol = protocolValue === undefined ? DEFAULT_CONFIG.protocol : protocolValue;
|
|
2304
|
+
if (typeof protocol !== 'string') {
|
|
2305
|
+
issues.push(issue('protocol', 'invalid-type', 'protocol must be a string.'));
|
|
2306
|
+
}
|
|
2307
|
+
else if (protocol !== 'legacy' && protocol !== 'acknowledged') {
|
|
2308
|
+
issues.push(issue('protocol', 'invalid-value', 'protocol must be legacy or acknowledged.'));
|
|
2309
|
+
}
|
|
2310
|
+
const searchModeValue = candidate.searchMode;
|
|
2311
|
+
const searchMode = searchModeValue === undefined ? DEFAULT_CONFIG.searchMode : searchModeValue;
|
|
2312
|
+
if (typeof searchMode !== 'string') {
|
|
2313
|
+
issues.push(issue('searchMode', 'invalid-type', 'searchMode must be a string.'));
|
|
2314
|
+
}
|
|
2315
|
+
else if (searchMode !== 'local' && searchMode !== 'remote' && searchMode !== 'hybrid') {
|
|
2316
|
+
issues.push(issue('searchMode', 'invalid-value', 'searchMode must be local, remote, or hybrid.'));
|
|
2317
|
+
}
|
|
2318
|
+
const paginationModeValue = candidate.paginationMode;
|
|
2319
|
+
const paginationMode = paginationModeValue === undefined ? DEFAULT_CONFIG.paginationMode : paginationModeValue;
|
|
2320
|
+
if (typeof paginationMode !== 'string') {
|
|
2321
|
+
issues.push(issue('paginationMode', 'invalid-type', 'paginationMode must be a string.'));
|
|
2322
|
+
}
|
|
2323
|
+
else if (paginationMode !== 'page' && paginationMode !== 'cursor') {
|
|
2324
|
+
issues.push(issue('paginationMode', 'invalid-value', 'paginationMode must be page or cursor.'));
|
|
2325
|
+
}
|
|
2326
|
+
validatePositiveSafeInteger(candidate, 'firstPage', issues);
|
|
2327
|
+
validatePositiveSafeInteger(candidate, 'fetchLimit', issues);
|
|
2328
|
+
if (protocol === 'legacy' && (searchMode === 'remote' || searchMode === 'hybrid')) {
|
|
2329
|
+
issues.push(issue('searchMode', 'requires-acknowledged-protocol', 'Remote and hybrid search require the acknowledged protocol.'));
|
|
2330
|
+
}
|
|
2331
|
+
if (protocol === 'legacy' && paginationMode === 'cursor') {
|
|
2332
|
+
issues.push(issue('paginationMode', 'requires-acknowledged-protocol', 'Cursor pagination requires the acknowledged protocol.'));
|
|
2333
|
+
}
|
|
2334
|
+
if (issues.length > 0)
|
|
2335
|
+
return { valid: false, issues };
|
|
2336
|
+
const resolved = {
|
|
2337
|
+
protocol: protocol,
|
|
2338
|
+
searchMode: searchMode,
|
|
2339
|
+
paginationMode: paginationMode,
|
|
2340
|
+
firstPage: candidate.firstPage === undefined ? DEFAULT_CONFIG.firstPage : candidate.firstPage,
|
|
2341
|
+
...(candidate.fetchLimit === undefined ? {} : { fetchLimit: candidate.fetchLimit }),
|
|
2342
|
+
};
|
|
2343
|
+
return { valid: true, value: resolved };
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2256
2346
|
/** Returns whether a selected key remains in the filtered result set. */
|
|
2257
2347
|
/**
|
|
2258
2348
|
* Returns keys in the half-open index range [startIndex, endIndex), clamped to
|
|
@@ -3054,6 +3144,798 @@
|
|
|
3054
3144
|
return true;
|
|
3055
3145
|
}
|
|
3056
3146
|
|
|
3147
|
+
/**
|
|
3148
|
+
* DOM-independent coordinator for the opt-in acknowledged data-loading
|
|
3149
|
+
* protocol. This module is intentionally not re-exported from the package
|
|
3150
|
+
* entry point; public component/adapter integration is a later increment.
|
|
3151
|
+
*/
|
|
3152
|
+
const DEFAULT_MAX_CURSOR_PAGES = 256;
|
|
3153
|
+
const HARD_MAX_CURSOR_PAGES = 4096;
|
|
3154
|
+
const DEFAULT_MAX_CURSOR_TOKEN_BYTES = 1024;
|
|
3155
|
+
const HARD_MAX_CURSOR_TOKEN_BYTES = 4096;
|
|
3156
|
+
let coordinatorInstanceSequence = 0;
|
|
3157
|
+
function isRecord(value) {
|
|
3158
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
3159
|
+
return false;
|
|
3160
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3161
|
+
return prototype === Object.prototype || prototype === null;
|
|
3162
|
+
}
|
|
3163
|
+
function isPositiveSafeInteger(value) {
|
|
3164
|
+
return Number.isSafeInteger(value) && value > 0;
|
|
3165
|
+
}
|
|
3166
|
+
function isNonNegativeSafeInteger(value) {
|
|
3167
|
+
return Number.isSafeInteger(value) && value >= 0;
|
|
3168
|
+
}
|
|
3169
|
+
function isCursor(value) {
|
|
3170
|
+
return typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value));
|
|
3171
|
+
}
|
|
3172
|
+
/** Count UTF-8 bytes without depending on DOM APIs or Node Buffer. */
|
|
3173
|
+
function cursorTokenByteLength(cursor) {
|
|
3174
|
+
const token = String(cursor);
|
|
3175
|
+
let bytes = 0;
|
|
3176
|
+
for (const character of token) {
|
|
3177
|
+
const codePoint = character.codePointAt(0);
|
|
3178
|
+
if (codePoint <= 0x7f)
|
|
3179
|
+
bytes += 1;
|
|
3180
|
+
else if (codePoint <= 0x7ff)
|
|
3181
|
+
bytes += 2;
|
|
3182
|
+
else if (codePoint <= 0xffff)
|
|
3183
|
+
bytes += 3;
|
|
3184
|
+
else
|
|
3185
|
+
bytes += 4;
|
|
3186
|
+
}
|
|
3187
|
+
return bytes;
|
|
3188
|
+
}
|
|
3189
|
+
function parseRequestId(value) {
|
|
3190
|
+
const match = /^data-(\d+)-generation-(\d+)-request-(\d+)-([a-z0-9]+)$/.exec(value);
|
|
3191
|
+
if (!match)
|
|
3192
|
+
return null;
|
|
3193
|
+
const [, instanceText, generationText, sequenceText, check] = match;
|
|
3194
|
+
const instanceId = Number(instanceText);
|
|
3195
|
+
const queryGeneration = Number(generationText);
|
|
3196
|
+
const sequence = Number(sequenceText);
|
|
3197
|
+
if (!Number.isSafeInteger(instanceId) || instanceId < 1 ||
|
|
3198
|
+
!Number.isSafeInteger(queryGeneration) || queryGeneration < 0 ||
|
|
3199
|
+
!Number.isSafeInteger(sequence) || sequence < 1)
|
|
3200
|
+
return null;
|
|
3201
|
+
return Object.freeze({ instanceId, queryGeneration, sequence, check });
|
|
3202
|
+
}
|
|
3203
|
+
function requestIdCheck(secret, instanceId, queryGeneration, sequence) {
|
|
3204
|
+
// A compact keyed check distinguishes IDs actually minted by this instance
|
|
3205
|
+
// from arbitrary strings without retaining a registry of historical IDs.
|
|
3206
|
+
let hash = 14695981039346656037n;
|
|
3207
|
+
const mask = (1n << 64n) - 1n;
|
|
3208
|
+
const input = `${secret}:${instanceId}:${queryGeneration}:${sequence}`;
|
|
3209
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
3210
|
+
hash ^= BigInt(input.charCodeAt(index));
|
|
3211
|
+
hash = (hash * 1099511628211n) & mask;
|
|
3212
|
+
}
|
|
3213
|
+
return hash.toString(36);
|
|
3214
|
+
}
|
|
3215
|
+
function isQueryMode(value) {
|
|
3216
|
+
return value === 'local' || value === 'remote' || value === 'hybrid';
|
|
3217
|
+
}
|
|
3218
|
+
function isPaginationMode(value) {
|
|
3219
|
+
return value === 'page' || value === 'cursor';
|
|
3220
|
+
}
|
|
3221
|
+
function frozenPosition(position) {
|
|
3222
|
+
return Object.freeze({ ...position });
|
|
3223
|
+
}
|
|
3224
|
+
function exactKeys(record, allowed) {
|
|
3225
|
+
return Object.keys(record).every((key) => allowed.includes(key));
|
|
3226
|
+
}
|
|
3227
|
+
function asFrozenItems(items) {
|
|
3228
|
+
return Object.freeze(Array.from(items));
|
|
3229
|
+
}
|
|
3230
|
+
function immutableActions(actions) {
|
|
3231
|
+
return Object.freeze(actions.slice());
|
|
3232
|
+
}
|
|
3233
|
+
function configInput(config = {}) {
|
|
3234
|
+
const root = isRecord(config) ? config : {};
|
|
3235
|
+
const dataLoading = isRecord(root.dataLoading) ? root.dataLoading : {};
|
|
3236
|
+
const infiniteScroll = isRecord(root.infiniteScroll) ? root.infiniteScroll : {};
|
|
3237
|
+
return {
|
|
3238
|
+
protocol: dataLoading.protocol === undefined ? 'legacy' : dataLoading.protocol,
|
|
3239
|
+
searchMode: dataLoading.searchMode === undefined ? 'local' : dataLoading.searchMode,
|
|
3240
|
+
paginationMode: dataLoading.paginationMode === undefined ? 'page' : dataLoading.paginationMode,
|
|
3241
|
+
firstPage: dataLoading.firstPage === undefined ? 1 : dataLoading.firstPage,
|
|
3242
|
+
initialPage: infiniteScroll.initialPage === undefined ? 1 : infiniteScroll.initialPage,
|
|
3243
|
+
fetchLimit: dataLoading.fetchLimit,
|
|
3244
|
+
maxCursorPages: dataLoading.maxCursorPages === undefined
|
|
3245
|
+
? DEFAULT_MAX_CURSOR_PAGES
|
|
3246
|
+
: dataLoading.maxCursorPages,
|
|
3247
|
+
maxCursorTokenBytes: dataLoading.maxCursorTokenBytes === undefined
|
|
3248
|
+
? DEFAULT_MAX_CURSOR_TOKEN_BYTES
|
|
3249
|
+
: dataLoading.maxCursorTokenBytes,
|
|
3250
|
+
pageSize: infiniteScroll.pageSize,
|
|
3251
|
+
};
|
|
3252
|
+
}
|
|
3253
|
+
function validateDataCoordinatorConfig(config = {}) {
|
|
3254
|
+
const input = configInput(config);
|
|
3255
|
+
const errors = [];
|
|
3256
|
+
const add = (field, message) => errors.push(Object.freeze({ field, message }));
|
|
3257
|
+
const rawConfig = config;
|
|
3258
|
+
if (!isRecord(rawConfig))
|
|
3259
|
+
add('config', 'must be a plain object');
|
|
3260
|
+
else {
|
|
3261
|
+
if (rawConfig.dataLoading !== undefined && !isRecord(rawConfig.dataLoading)) {
|
|
3262
|
+
add('dataLoading', 'must be a plain object when supplied');
|
|
3263
|
+
}
|
|
3264
|
+
if (rawConfig.infiniteScroll !== undefined && !isRecord(rawConfig.infiniteScroll)) {
|
|
3265
|
+
add('infiniteScroll', 'must be a plain object when supplied');
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
if (input.protocol !== 'legacy' && input.protocol !== 'acknowledged') {
|
|
3269
|
+
add('dataLoading.protocol', 'must be legacy or acknowledged');
|
|
3270
|
+
}
|
|
3271
|
+
if (!isQueryMode(input.searchMode)) {
|
|
3272
|
+
add('dataLoading.searchMode', 'must be local, remote, or hybrid');
|
|
3273
|
+
}
|
|
3274
|
+
if (!isPaginationMode(input.paginationMode)) {
|
|
3275
|
+
add('dataLoading.paginationMode', 'must be page or cursor');
|
|
3276
|
+
}
|
|
3277
|
+
if (!isPositiveSafeInteger(input.firstPage)) {
|
|
3278
|
+
add('dataLoading.firstPage', 'must be a positive safe integer');
|
|
3279
|
+
}
|
|
3280
|
+
if (!isPositiveSafeInteger(input.initialPage)) {
|
|
3281
|
+
add('infiniteScroll.initialPage', 'must be a positive safe integer');
|
|
3282
|
+
}
|
|
3283
|
+
if (input.protocol === 'acknowledged' &&
|
|
3284
|
+
input.searchMode === 'local' &&
|
|
3285
|
+
input.paginationMode === 'page' &&
|
|
3286
|
+
input.initialPage === Number.MAX_SAFE_INTEGER) {
|
|
3287
|
+
add('infiniteScroll.initialPage', 'must leave room for the next acknowledged page number');
|
|
3288
|
+
}
|
|
3289
|
+
if (input.fetchLimit !== undefined && !isPositiveSafeInteger(input.fetchLimit)) {
|
|
3290
|
+
add('dataLoading.fetchLimit', 'must be a positive safe integer when supplied');
|
|
3291
|
+
}
|
|
3292
|
+
if (!isPositiveSafeInteger(input.maxCursorPages) || input.maxCursorPages > HARD_MAX_CURSOR_PAGES) {
|
|
3293
|
+
add('dataLoading.maxCursorPages', `must be a positive safe integer no greater than ${HARD_MAX_CURSOR_PAGES}`);
|
|
3294
|
+
}
|
|
3295
|
+
if (!isPositiveSafeInteger(input.maxCursorTokenBytes) || input.maxCursorTokenBytes > HARD_MAX_CURSOR_TOKEN_BYTES) {
|
|
3296
|
+
add('dataLoading.maxCursorTokenBytes', `must be a positive safe integer no greater than ${HARD_MAX_CURSOR_TOKEN_BYTES}`);
|
|
3297
|
+
}
|
|
3298
|
+
if (input.pageSize !== undefined && !isPositiveSafeInteger(input.pageSize)) {
|
|
3299
|
+
add('infiniteScroll.pageSize', 'must be a positive safe integer when supplied');
|
|
3300
|
+
}
|
|
3301
|
+
if (input.protocol === 'legacy' &&
|
|
3302
|
+
(input.searchMode === 'remote' || input.searchMode === 'hybrid' || input.paginationMode === 'cursor')) {
|
|
3303
|
+
add('dataLoading.protocol', 'remote/hybrid search and cursor pagination require acknowledged protocol');
|
|
3304
|
+
}
|
|
3305
|
+
const resolvedFetchLimit = typeof input.fetchLimit === 'number' ? input.fetchLimit : typeof input.pageSize === 'number' ? input.pageSize : undefined;
|
|
3306
|
+
if (input.protocol === 'acknowledged' && resolvedFetchLimit === undefined) {
|
|
3307
|
+
add('dataLoading.fetchLimit', 'acknowledged requests require fetchLimit or an effective infiniteScroll.pageSize');
|
|
3308
|
+
}
|
|
3309
|
+
if (errors.length > 0) {
|
|
3310
|
+
return Object.freeze({ valid: false, errors: Object.freeze(errors) });
|
|
3311
|
+
}
|
|
3312
|
+
return Object.freeze({
|
|
3313
|
+
valid: true,
|
|
3314
|
+
value: Object.freeze({
|
|
3315
|
+
protocol: input.protocol,
|
|
3316
|
+
searchMode: input.searchMode,
|
|
3317
|
+
paginationMode: input.paginationMode,
|
|
3318
|
+
firstPage: input.firstPage,
|
|
3319
|
+
initialPage: input.initialPage,
|
|
3320
|
+
fetchLimit: resolvedFetchLimit,
|
|
3321
|
+
maxCursorPages: input.maxCursorPages,
|
|
3322
|
+
maxCursorTokenBytes: input.maxCursorTokenBytes,
|
|
3323
|
+
}),
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
function copyCoordinatorConfig(config = {}) {
|
|
3327
|
+
return {
|
|
3328
|
+
dataLoading: config.dataLoading ? { ...config.dataLoading } : {},
|
|
3329
|
+
infiniteScroll: config.infiniteScroll ? { ...config.infiniteScroll } : {},
|
|
3330
|
+
};
|
|
3331
|
+
}
|
|
3332
|
+
function mergeCoordinatorConfig(current, update) {
|
|
3333
|
+
return {
|
|
3334
|
+
dataLoading: { ...(current.dataLoading ?? {}), ...(update.dataLoading ?? {}) },
|
|
3335
|
+
infiniteScroll: { ...(current.infiniteScroll ?? {}), ...(update.infiniteScroll ?? {}) },
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
/**
|
|
3339
|
+
* Owns request identity and pagination state only. It has no DOM, framework,
|
|
3340
|
+
* observer, timer, or network dependencies. Returned actions are instructions
|
|
3341
|
+
* for a future facade/host boundary; cancellation never performs transport.
|
|
3342
|
+
*/
|
|
3343
|
+
class DataRequestCoordinator {
|
|
3344
|
+
constructor(options = {}) {
|
|
3345
|
+
this.instanceId = ++coordinatorInstanceSequence;
|
|
3346
|
+
this.requestIdSecret = Math.random().toString(36).slice(2) || '0';
|
|
3347
|
+
this.requestSequence = 0;
|
|
3348
|
+
this.connected = false;
|
|
3349
|
+
this.hasConnected = false;
|
|
3350
|
+
this.queryGeneration = 0;
|
|
3351
|
+
this.active = null;
|
|
3352
|
+
this.status = 'idle';
|
|
3353
|
+
/**
|
|
3354
|
+
* Exact cycle detection for the current pagination epoch. One cursor is
|
|
3355
|
+
* retained per accepted advancement; there is intentionally no LRU eviction.
|
|
3356
|
+
*/
|
|
3357
|
+
this.committedCursors = new Set();
|
|
3358
|
+
this.generationHasAcceptedResult = false;
|
|
3359
|
+
this.retryAvailable = false;
|
|
3360
|
+
this.error = null;
|
|
3361
|
+
this.resourceLimit = null;
|
|
3362
|
+
this.sentinelBlocked = false;
|
|
3363
|
+
this.sentinelIntersecting = false;
|
|
3364
|
+
const initialConfig = options.config === undefined ? {} : options.config;
|
|
3365
|
+
const validation = validateDataCoordinatorConfig(initialConfig);
|
|
3366
|
+
if (!validation.valid) {
|
|
3367
|
+
throw new TypeError(validation.errors.map(({ field, message }) => `${field}: ${message}`).join('; '));
|
|
3368
|
+
}
|
|
3369
|
+
this.rawConfig = copyCoordinatorConfig(initialConfig);
|
|
3370
|
+
this.config = validation.value;
|
|
3371
|
+
this.query = options.initialQuery ?? '';
|
|
3372
|
+
this.items = asFrozenItems(options.initialItems ?? []);
|
|
3373
|
+
const remote = this.isRemoteMode();
|
|
3374
|
+
this.hasMore = remote ? false : options.hasMore ?? false;
|
|
3375
|
+
this.nextEligiblePosition = this.initialPosition();
|
|
3376
|
+
this.lastCommittedPage = this.config.paginationMode === 'page' && !remote
|
|
3377
|
+
? this.config.initialPage
|
|
3378
|
+
: undefined;
|
|
3379
|
+
this.needsInitialRemoteSearch = remote;
|
|
3380
|
+
}
|
|
3381
|
+
getSnapshot() {
|
|
3382
|
+
const activeRequest = this.active?.request ?? null;
|
|
3383
|
+
const nextPosition = frozenPosition(this.nextEligiblePosition);
|
|
3384
|
+
return Object.freeze({
|
|
3385
|
+
status: this.status,
|
|
3386
|
+
connected: this.connected,
|
|
3387
|
+
busy: this.active !== null,
|
|
3388
|
+
query: this.query,
|
|
3389
|
+
normalizedQuery: this.query.trim(),
|
|
3390
|
+
queryGeneration: this.queryGeneration,
|
|
3391
|
+
items: asFrozenItems(this.items),
|
|
3392
|
+
hasMore: this.hasMore,
|
|
3393
|
+
activeRequest,
|
|
3394
|
+
lastCommittedPage: this.lastCommittedPage,
|
|
3395
|
+
nextEligiblePosition: nextPosition,
|
|
3396
|
+
error: this.error ? Object.freeze({ ...this.error }) : null,
|
|
3397
|
+
resourceLimit: this.resourceLimit,
|
|
3398
|
+
sentinelBlocked: this.sentinelBlocked,
|
|
3399
|
+
sentinelIntersecting: this.sentinelIntersecting,
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
/** Connect once, dispatching the initial remote/hybrid query when required. */
|
|
3403
|
+
connect(query = this.query) {
|
|
3404
|
+
if (this.connected)
|
|
3405
|
+
return immutableActions([]);
|
|
3406
|
+
const actions = [];
|
|
3407
|
+
if (query !== this.query)
|
|
3408
|
+
actions.push(...this.setQuery(query));
|
|
3409
|
+
if (this.hasConnected)
|
|
3410
|
+
this.queryGeneration += 1;
|
|
3411
|
+
this.connected = true;
|
|
3412
|
+
this.hasConnected = true;
|
|
3413
|
+
if (this.isRemoteMode() && this.needsInitialRemoteSearch) {
|
|
3414
|
+
this.resetPaginationForRemoteQuery(true);
|
|
3415
|
+
const request = this.createSearchRequest();
|
|
3416
|
+
if (request)
|
|
3417
|
+
actions.push(Object.freeze({ type: 'request', request }));
|
|
3418
|
+
}
|
|
3419
|
+
return immutableActions(actions);
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Advance the request transition from synchronous `requested` to `loading`
|
|
3423
|
+
* immediately before a future facade dispatches event/callback notifications.
|
|
3424
|
+
*/
|
|
3425
|
+
markNotificationsDispatched(requestId) {
|
|
3426
|
+
if (!this.active || this.active.request.requestId !== requestId || this.active.phase !== 'requested') {
|
|
3427
|
+
return false;
|
|
3428
|
+
}
|
|
3429
|
+
this.active.phase = 'loading';
|
|
3430
|
+
this.status = 'loading';
|
|
3431
|
+
return true;
|
|
3432
|
+
}
|
|
3433
|
+
setQuery(query) {
|
|
3434
|
+
if (typeof query !== 'string' || query === this.query)
|
|
3435
|
+
return immutableActions([]);
|
|
3436
|
+
const actions = [];
|
|
3437
|
+
const cancellation = this.invalidateActive('query-changed');
|
|
3438
|
+
if (cancellation)
|
|
3439
|
+
actions.push(cancellation);
|
|
3440
|
+
this.query = query;
|
|
3441
|
+
this.queryGeneration += 1;
|
|
3442
|
+
this.error = null;
|
|
3443
|
+
this.status = 'idle';
|
|
3444
|
+
this.generationHasAcceptedResult = false;
|
|
3445
|
+
this.retryAvailable = false;
|
|
3446
|
+
this.retryPosition = undefined;
|
|
3447
|
+
this.retryKind = undefined;
|
|
3448
|
+
this.committedCursors.clear();
|
|
3449
|
+
this.resourceLimit = null;
|
|
3450
|
+
this.sentinelBlocked = false;
|
|
3451
|
+
if (this.isRemoteMode()) {
|
|
3452
|
+
this.resetPaginationForRemoteQuery(true);
|
|
3453
|
+
this.needsInitialRemoteSearch = true;
|
|
3454
|
+
if (this.connected) {
|
|
3455
|
+
const request = this.createSearchRequest();
|
|
3456
|
+
if (request)
|
|
3457
|
+
actions.push(Object.freeze({ type: 'request', request }));
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
else {
|
|
3461
|
+
this.lastCommittedPage = this.config.paginationMode === 'page' ? this.config.initialPage : undefined;
|
|
3462
|
+
this.nextEligiblePosition = this.initialPosition();
|
|
3463
|
+
this.needsInitialRemoteSearch = false;
|
|
3464
|
+
}
|
|
3465
|
+
return immutableActions(actions);
|
|
3466
|
+
}
|
|
3467
|
+
/** Update effective config; non-protocol changes do not rewrite active requests. */
|
|
3468
|
+
updateConfig(update) {
|
|
3469
|
+
const rawUpdate = update;
|
|
3470
|
+
if (!isRecord(rawUpdate) ||
|
|
3471
|
+
(rawUpdate.dataLoading !== undefined && !isRecord(rawUpdate.dataLoading)) ||
|
|
3472
|
+
(rawUpdate.infiniteScroll !== undefined && !isRecord(rawUpdate.infiniteScroll))) {
|
|
3473
|
+
return Object.freeze({
|
|
3474
|
+
status: 'invalid',
|
|
3475
|
+
errors: Object.freeze([
|
|
3476
|
+
Object.freeze({ field: 'config', message: 'update and nested config groups must be plain objects' }),
|
|
3477
|
+
]),
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
const candidate = mergeCoordinatorConfig(this.rawConfig, update);
|
|
3481
|
+
const validation = validateDataCoordinatorConfig(candidate);
|
|
3482
|
+
if (!validation.valid)
|
|
3483
|
+
return Object.freeze({ status: 'invalid', errors: validation.errors });
|
|
3484
|
+
const previous = this.config;
|
|
3485
|
+
const next = validation.value;
|
|
3486
|
+
const protocolChanged = previous.protocol !== next.protocol ||
|
|
3487
|
+
previous.searchMode !== next.searchMode ||
|
|
3488
|
+
previous.paginationMode !== next.paginationMode;
|
|
3489
|
+
this.rawConfig = copyCoordinatorConfig(candidate);
|
|
3490
|
+
this.config = next;
|
|
3491
|
+
if (!protocolChanged) {
|
|
3492
|
+
this.refreshCursorDepthLimit();
|
|
3493
|
+
return Object.freeze({ status: 'accepted', actions: immutableActions([]) });
|
|
3494
|
+
}
|
|
3495
|
+
const actions = [];
|
|
3496
|
+
const cancellation = this.invalidateActive('config-changed');
|
|
3497
|
+
if (cancellation)
|
|
3498
|
+
actions.push(cancellation);
|
|
3499
|
+
this.queryGeneration += 1;
|
|
3500
|
+
this.error = null;
|
|
3501
|
+
this.status = 'idle';
|
|
3502
|
+
this.generationHasAcceptedResult = false;
|
|
3503
|
+
this.retryAvailable = false;
|
|
3504
|
+
this.retryPosition = undefined;
|
|
3505
|
+
this.retryKind = undefined;
|
|
3506
|
+
this.committedCursors.clear();
|
|
3507
|
+
this.resourceLimit = null;
|
|
3508
|
+
this.sentinelBlocked = false;
|
|
3509
|
+
this.hasMore = this.isRemoteMode() ? false : this.hasMore;
|
|
3510
|
+
this.lastCommittedPage = this.config.paginationMode === 'page' && !this.isRemoteMode()
|
|
3511
|
+
? this.config.initialPage
|
|
3512
|
+
: undefined;
|
|
3513
|
+
this.nextEligiblePosition = this.initialPosition();
|
|
3514
|
+
this.needsInitialRemoteSearch = this.isRemoteMode();
|
|
3515
|
+
if (this.connected && this.isRemoteMode()) {
|
|
3516
|
+
const request = this.createSearchRequest();
|
|
3517
|
+
if (request)
|
|
3518
|
+
actions.push(Object.freeze({ type: 'request', request }));
|
|
3519
|
+
}
|
|
3520
|
+
return Object.freeze({ status: 'accepted', actions: immutableActions(actions) });
|
|
3521
|
+
}
|
|
3522
|
+
/** Request another page or explicitly retry the still-eligible position. */
|
|
3523
|
+
requestLoadMore(trigger = 'manual') {
|
|
3524
|
+
if (this.config.protocol !== 'acknowledged' || !this.connected || this.active) {
|
|
3525
|
+
return immutableActions([]);
|
|
3526
|
+
}
|
|
3527
|
+
if (trigger === 'sentinel' && this.sentinelBlocked)
|
|
3528
|
+
return immutableActions([]);
|
|
3529
|
+
if (!this.hasMore && !this.retryAvailable)
|
|
3530
|
+
return immutableActions([]);
|
|
3531
|
+
const position = this.retryAvailable && this.retryPosition
|
|
3532
|
+
? this.retryPosition
|
|
3533
|
+
: this.nextEligiblePosition;
|
|
3534
|
+
if (this.config.paginationMode === 'cursor' &&
|
|
3535
|
+
position.mode === 'cursor' &&
|
|
3536
|
+
position.ordinal > this.config.maxCursorPages) {
|
|
3537
|
+
this.resourceLimit = Object.freeze({
|
|
3538
|
+
reason: 'cursor-depth',
|
|
3539
|
+
maxCursorPages: this.config.maxCursorPages,
|
|
3540
|
+
});
|
|
3541
|
+
this.status = 'resource-limited';
|
|
3542
|
+
this.sentinelBlocked = true;
|
|
3543
|
+
return immutableActions([]);
|
|
3544
|
+
}
|
|
3545
|
+
if (trigger === 'manual')
|
|
3546
|
+
this.sentinelBlocked = false;
|
|
3547
|
+
const retryKind = this.retryAvailable ? this.retryKind : undefined;
|
|
3548
|
+
this.retryAvailable = false;
|
|
3549
|
+
this.retryPosition = undefined;
|
|
3550
|
+
this.retryKind = undefined;
|
|
3551
|
+
const request = retryKind === 'search' && this.isRemoteMode()
|
|
3552
|
+
? this.createSearchRequest(position)
|
|
3553
|
+
: this.createLoadMoreRequest(position);
|
|
3554
|
+
return request ? immutableActions([Object.freeze({ type: 'request', request })]) : immutableActions([]);
|
|
3555
|
+
}
|
|
3556
|
+
/** Feed observer state into the pure sentinel rearm state machine. */
|
|
3557
|
+
setSentinelIntersecting(intersecting) {
|
|
3558
|
+
if (!intersecting) {
|
|
3559
|
+
this.sentinelIntersecting = false;
|
|
3560
|
+
this.sentinelBlocked = false;
|
|
3561
|
+
return immutableActions([]);
|
|
3562
|
+
}
|
|
3563
|
+
if (this.sentinelIntersecting)
|
|
3564
|
+
return immutableActions([]);
|
|
3565
|
+
this.sentinelIntersecting = true;
|
|
3566
|
+
return this.requestLoadMore('sentinel');
|
|
3567
|
+
}
|
|
3568
|
+
/** Invalidate pending work before returning its best-effort host cancellation action. */
|
|
3569
|
+
disconnect() {
|
|
3570
|
+
if (!this.connected)
|
|
3571
|
+
return immutableActions([]);
|
|
3572
|
+
const activeRequest = this.active?.request;
|
|
3573
|
+
const actions = [];
|
|
3574
|
+
if (activeRequest) {
|
|
3575
|
+
if (activeRequest.kind === 'search' && !this.generationHasAcceptedResult) {
|
|
3576
|
+
this.needsInitialRemoteSearch = true;
|
|
3577
|
+
}
|
|
3578
|
+
const cancellation = this.invalidateActive('disconnected');
|
|
3579
|
+
if (cancellation)
|
|
3580
|
+
actions.push(cancellation);
|
|
3581
|
+
this.resourceLimit = null;
|
|
3582
|
+
this.status = 'cancelled';
|
|
3583
|
+
this.sentinelBlocked = true;
|
|
3584
|
+
// Encode invalidation in the generation, so late completions are stale
|
|
3585
|
+
// without retaining one request ID per cancellation.
|
|
3586
|
+
this.queryGeneration += 1;
|
|
3587
|
+
}
|
|
3588
|
+
this.sentinelIntersecting = false;
|
|
3589
|
+
this.connected = false;
|
|
3590
|
+
return immutableActions(actions);
|
|
3591
|
+
}
|
|
3592
|
+
completeDataRequest(completion) {
|
|
3593
|
+
if (!isRecord(completion) || !this.hasValidCompletionEnvelope(completion))
|
|
3594
|
+
return 'invalid';
|
|
3595
|
+
const requestId = completion.requestId;
|
|
3596
|
+
const generation = completion.queryGeneration;
|
|
3597
|
+
if (this.active?.request.requestId !== requestId) {
|
|
3598
|
+
return this.classifyInactiveRequest(requestId, generation);
|
|
3599
|
+
}
|
|
3600
|
+
if (generation !== this.active.request.queryGeneration || this.active.phase !== 'loading')
|
|
3601
|
+
return 'invalid';
|
|
3602
|
+
const validation = this.validateCompletionPayload(completion, this.active.request);
|
|
3603
|
+
if (!validation.valid) {
|
|
3604
|
+
if (validation.resourceLimit === 'cursor-token-size') {
|
|
3605
|
+
const cursor = completion.nextCursor;
|
|
3606
|
+
const actualCursorTokenBytes = cursorTokenByteLength(cursor);
|
|
3607
|
+
this.resourceLimit = Object.freeze({
|
|
3608
|
+
reason: 'cursor-token-size',
|
|
3609
|
+
maxCursorTokenBytes: this.config.maxCursorTokenBytes,
|
|
3610
|
+
actualCursorTokenBytes,
|
|
3611
|
+
requestId,
|
|
3612
|
+
});
|
|
3613
|
+
return 'resource-limit';
|
|
3614
|
+
}
|
|
3615
|
+
return 'invalid';
|
|
3616
|
+
}
|
|
3617
|
+
const request = this.active.request;
|
|
3618
|
+
const status = completion.status;
|
|
3619
|
+
const nextData = status === 'succeeded' || status === 'exhausted'
|
|
3620
|
+
? asFrozenItems(completion.items)
|
|
3621
|
+
: this.items;
|
|
3622
|
+
let nextPosition = this.nextEligiblePosition;
|
|
3623
|
+
let nextLastCommittedPage = this.lastCommittedPage;
|
|
3624
|
+
let nextHasMore = this.hasMore;
|
|
3625
|
+
let nextRetryAvailable = false;
|
|
3626
|
+
let nextRetryPosition;
|
|
3627
|
+
let nextRetryKind;
|
|
3628
|
+
let nextError = null;
|
|
3629
|
+
let nextSentinelBlocked = false;
|
|
3630
|
+
let cursorToCommit;
|
|
3631
|
+
let nextResourceLimit = null;
|
|
3632
|
+
if (status === 'succeeded') {
|
|
3633
|
+
const advances = this.advanceFrom(request, completion);
|
|
3634
|
+
nextPosition = advances.position;
|
|
3635
|
+
nextLastCommittedPage = advances.lastCommittedPage;
|
|
3636
|
+
cursorToCommit = advances.cursorToCommit;
|
|
3637
|
+
nextHasMore = true;
|
|
3638
|
+
}
|
|
3639
|
+
else if (status === 'exhausted') {
|
|
3640
|
+
nextLastCommittedPage = request.position.mode === 'page'
|
|
3641
|
+
? request.position.page
|
|
3642
|
+
: this.lastCommittedPage;
|
|
3643
|
+
nextHasMore = false;
|
|
3644
|
+
}
|
|
3645
|
+
else if (status === 'empty') {
|
|
3646
|
+
nextHasMore = true;
|
|
3647
|
+
nextSentinelBlocked = true;
|
|
3648
|
+
if (completion.advance === 'next') {
|
|
3649
|
+
const advances = this.advanceFrom(request, completion);
|
|
3650
|
+
nextPosition = advances.position;
|
|
3651
|
+
nextLastCommittedPage = advances.lastCommittedPage;
|
|
3652
|
+
cursorToCommit = advances.cursorToCommit;
|
|
3653
|
+
}
|
|
3654
|
+
else {
|
|
3655
|
+
nextRetryAvailable = true;
|
|
3656
|
+
nextRetryPosition = request.position;
|
|
3657
|
+
nextRetryKind = request.kind;
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3660
|
+
else if (status === 'failed') {
|
|
3661
|
+
nextRetryAvailable = true;
|
|
3662
|
+
nextRetryPosition = request.position;
|
|
3663
|
+
nextRetryKind = request.kind;
|
|
3664
|
+
nextError = Object.freeze({ ...completion.error });
|
|
3665
|
+
nextSentinelBlocked = true;
|
|
3666
|
+
}
|
|
3667
|
+
else if (status === 'cancelled') {
|
|
3668
|
+
nextRetryAvailable = true;
|
|
3669
|
+
nextRetryPosition = request.position;
|
|
3670
|
+
nextRetryKind = request.kind;
|
|
3671
|
+
nextSentinelBlocked = true;
|
|
3672
|
+
}
|
|
3673
|
+
if (this.config.paginationMode === 'cursor' &&
|
|
3674
|
+
nextHasMore &&
|
|
3675
|
+
nextPosition.mode === 'cursor' &&
|
|
3676
|
+
nextPosition.ordinal > this.config.maxCursorPages) {
|
|
3677
|
+
nextResourceLimit = Object.freeze({
|
|
3678
|
+
reason: 'cursor-depth',
|
|
3679
|
+
maxCursorPages: this.config.maxCursorPages,
|
|
3680
|
+
requestId,
|
|
3681
|
+
});
|
|
3682
|
+
nextSentinelBlocked = true;
|
|
3683
|
+
}
|
|
3684
|
+
// Commit only after identity, generation, status, and every field validate.
|
|
3685
|
+
this.items = nextData;
|
|
3686
|
+
this.nextEligiblePosition = nextPosition;
|
|
3687
|
+
this.lastCommittedPage = nextLastCommittedPage;
|
|
3688
|
+
this.hasMore = nextHasMore;
|
|
3689
|
+
this.retryAvailable = nextRetryAvailable;
|
|
3690
|
+
this.retryPosition = nextRetryPosition;
|
|
3691
|
+
this.retryKind = nextRetryKind;
|
|
3692
|
+
this.error = nextError;
|
|
3693
|
+
this.resourceLimit = nextResourceLimit;
|
|
3694
|
+
this.sentinelBlocked = nextSentinelBlocked;
|
|
3695
|
+
if (cursorToCommit !== undefined)
|
|
3696
|
+
this.committedCursors.add(cursorToCommit);
|
|
3697
|
+
if (status === 'succeeded' || status === 'exhausted')
|
|
3698
|
+
this.generationHasAcceptedResult = true;
|
|
3699
|
+
this.active = null;
|
|
3700
|
+
this.status = nextResourceLimit ? 'resource-limited' : status;
|
|
3701
|
+
return 'accepted';
|
|
3702
|
+
}
|
|
3703
|
+
isRemoteMode() {
|
|
3704
|
+
return this.config.searchMode === 'remote' || this.config.searchMode === 'hybrid';
|
|
3705
|
+
}
|
|
3706
|
+
initialPosition() {
|
|
3707
|
+
if (this.config.paginationMode === 'cursor') {
|
|
3708
|
+
return Object.freeze({ mode: 'cursor', ordinal: 1 });
|
|
3709
|
+
}
|
|
3710
|
+
const page = this.isRemoteMode() ? this.config.firstPage : this.config.initialPage + 1;
|
|
3711
|
+
return Object.freeze({ mode: 'page', page });
|
|
3712
|
+
}
|
|
3713
|
+
resetPaginationForRemoteQuery(clearItems) {
|
|
3714
|
+
this.hasMore = false;
|
|
3715
|
+
this.lastCommittedPage = undefined;
|
|
3716
|
+
this.nextEligiblePosition = this.initialPosition();
|
|
3717
|
+
this.committedCursors.clear();
|
|
3718
|
+
this.retryAvailable = false;
|
|
3719
|
+
this.retryPosition = undefined;
|
|
3720
|
+
this.retryKind = undefined;
|
|
3721
|
+
this.resourceLimit = null;
|
|
3722
|
+
this.sentinelBlocked = false;
|
|
3723
|
+
this.error = null;
|
|
3724
|
+
if (clearItems)
|
|
3725
|
+
this.items = asFrozenItems([]);
|
|
3726
|
+
}
|
|
3727
|
+
/** Re-evaluate the local cursor cap without resetting accepted history. */
|
|
3728
|
+
refreshCursorDepthLimit() {
|
|
3729
|
+
if (this.config.protocol !== 'acknowledged' || this.config.paginationMode !== 'cursor')
|
|
3730
|
+
return;
|
|
3731
|
+
const position = this.retryAvailable && this.retryPosition
|
|
3732
|
+
? this.retryPosition
|
|
3733
|
+
: this.nextEligiblePosition;
|
|
3734
|
+
const overLimit = (this.hasMore || this.retryAvailable) &&
|
|
3735
|
+
position.mode === 'cursor' && position.ordinal > this.config.maxCursorPages;
|
|
3736
|
+
if (overLimit) {
|
|
3737
|
+
this.resourceLimit = Object.freeze({
|
|
3738
|
+
reason: 'cursor-depth',
|
|
3739
|
+
maxCursorPages: this.config.maxCursorPages,
|
|
3740
|
+
});
|
|
3741
|
+
if (!this.active)
|
|
3742
|
+
this.status = 'resource-limited';
|
|
3743
|
+
this.sentinelBlocked = true;
|
|
3744
|
+
return;
|
|
3745
|
+
}
|
|
3746
|
+
if (this.resourceLimit?.reason === 'cursor-depth') {
|
|
3747
|
+
this.resourceLimit = null;
|
|
3748
|
+
if (!this.active && this.status === 'resource-limited')
|
|
3749
|
+
this.status = 'idle';
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
createSearchRequest(position = this.nextEligiblePosition) {
|
|
3753
|
+
if (!this.connected || !this.isRemoteMode() || this.config.protocol !== 'acknowledged')
|
|
3754
|
+
return null;
|
|
3755
|
+
const request = this.createRequest({ kind: 'search', mode: this.config.searchMode }, position);
|
|
3756
|
+
if (request) {
|
|
3757
|
+
this.needsInitialRemoteSearch = false;
|
|
3758
|
+
this.status = 'requested';
|
|
3759
|
+
}
|
|
3760
|
+
return request;
|
|
3761
|
+
}
|
|
3762
|
+
createLoadMoreRequest(position) {
|
|
3763
|
+
if (!this.connected || this.config.protocol !== 'acknowledged')
|
|
3764
|
+
return null;
|
|
3765
|
+
const request = this.createRequest({ kind: 'loadMore' }, position);
|
|
3766
|
+
if (request)
|
|
3767
|
+
this.status = 'requested';
|
|
3768
|
+
return request;
|
|
3769
|
+
}
|
|
3770
|
+
createRequest(kind, position) {
|
|
3771
|
+
const fetchLimit = this.config.fetchLimit;
|
|
3772
|
+
if (fetchLimit === undefined || this.active)
|
|
3773
|
+
return null;
|
|
3774
|
+
this.requestSequence += 1;
|
|
3775
|
+
const check = requestIdCheck(this.requestIdSecret, this.instanceId, this.queryGeneration, this.requestSequence);
|
|
3776
|
+
const requestId = `data-${this.instanceId}-generation-${this.queryGeneration}-request-${this.requestSequence}-${check}`;
|
|
3777
|
+
const base = Object.freeze({
|
|
3778
|
+
requestId,
|
|
3779
|
+
queryGeneration: this.queryGeneration,
|
|
3780
|
+
query: this.query,
|
|
3781
|
+
normalizedQuery: this.query.trim(),
|
|
3782
|
+
fetchLimit,
|
|
3783
|
+
position: frozenPosition(position),
|
|
3784
|
+
});
|
|
3785
|
+
const request = kind.kind === 'search'
|
|
3786
|
+
? Object.freeze({ ...base, kind: 'search', mode: kind.mode })
|
|
3787
|
+
: Object.freeze({ ...base, kind: 'loadMore' });
|
|
3788
|
+
this.active = { request, phase: 'requested' };
|
|
3789
|
+
this.status = 'requested';
|
|
3790
|
+
this.error = null;
|
|
3791
|
+
return request;
|
|
3792
|
+
}
|
|
3793
|
+
invalidateActive(reason) {
|
|
3794
|
+
if (!this.active)
|
|
3795
|
+
return null;
|
|
3796
|
+
const { request } = this.active;
|
|
3797
|
+
this.active = null;
|
|
3798
|
+
this.status = 'cancelled';
|
|
3799
|
+
const notification = Object.freeze({
|
|
3800
|
+
requestId: request.requestId,
|
|
3801
|
+
queryGeneration: request.queryGeneration,
|
|
3802
|
+
reason,
|
|
3803
|
+
});
|
|
3804
|
+
return Object.freeze({ type: 'cancel', notification });
|
|
3805
|
+
}
|
|
3806
|
+
classifyInactiveRequest(requestId, completionGeneration) {
|
|
3807
|
+
const parsed = parseRequestId(requestId);
|
|
3808
|
+
if (!parsed ||
|
|
3809
|
+
parsed.instanceId !== this.instanceId ||
|
|
3810
|
+
parsed.check !== requestIdCheck(this.requestIdSecret, parsed.instanceId, parsed.queryGeneration, parsed.sequence) ||
|
|
3811
|
+
parsed.sequence > this.requestSequence)
|
|
3812
|
+
return 'unknown-request';
|
|
3813
|
+
if (parsed.queryGeneration !== completionGeneration)
|
|
3814
|
+
return 'invalid';
|
|
3815
|
+
return parsed.queryGeneration < this.queryGeneration ? 'stale' : 'unknown-request';
|
|
3816
|
+
}
|
|
3817
|
+
hasValidCompletionEnvelope(completion) {
|
|
3818
|
+
return (typeof completion.requestId === 'string' &&
|
|
3819
|
+
completion.requestId.length > 0 &&
|
|
3820
|
+
isNonNegativeSafeInteger(completion.queryGeneration) &&
|
|
3821
|
+
typeof completion.status === 'string' &&
|
|
3822
|
+
['succeeded', 'empty', 'exhausted', 'failed', 'cancelled'].includes(completion.status));
|
|
3823
|
+
}
|
|
3824
|
+
validateCompletionPayload(completion, request) {
|
|
3825
|
+
const common = ['requestId', 'queryGeneration', 'status'];
|
|
3826
|
+
switch (completion.status) {
|
|
3827
|
+
case 'succeeded': {
|
|
3828
|
+
const allowed = [...common, 'items', 'hasMore'];
|
|
3829
|
+
if (request.position.mode === 'cursor')
|
|
3830
|
+
allowed.push('nextCursor');
|
|
3831
|
+
if (!exactKeys(completion, allowed) || !Array.isArray(completion.items) || completion.hasMore !== true) {
|
|
3832
|
+
return { valid: false };
|
|
3833
|
+
}
|
|
3834
|
+
if (request.position.mode === 'cursor') {
|
|
3835
|
+
if (request.position.ordinal >= Number.MAX_SAFE_INTEGER || !isCursor(completion.nextCursor)) {
|
|
3836
|
+
return { valid: false };
|
|
3837
|
+
}
|
|
3838
|
+
if (cursorTokenByteLength(completion.nextCursor) > this.config.maxCursorTokenBytes) {
|
|
3839
|
+
return { valid: false, resourceLimit: 'cursor-token-size' };
|
|
3840
|
+
}
|
|
3841
|
+
if (this.hasCommittedCursor(completion.nextCursor))
|
|
3842
|
+
return { valid: false };
|
|
3843
|
+
}
|
|
3844
|
+
else if ('nextCursor' in completion) {
|
|
3845
|
+
return { valid: false };
|
|
3846
|
+
}
|
|
3847
|
+
else if (request.position.page >= Number.MAX_SAFE_INTEGER) {
|
|
3848
|
+
return { valid: false };
|
|
3849
|
+
}
|
|
3850
|
+
return { valid: true };
|
|
3851
|
+
}
|
|
3852
|
+
case 'empty': {
|
|
3853
|
+
const allowed = [...common, 'hasMore', 'advance'];
|
|
3854
|
+
if (request.position.mode === 'cursor' && completion.advance === 'next')
|
|
3855
|
+
allowed.push('nextCursor');
|
|
3856
|
+
if (!exactKeys(completion, allowed) || completion.hasMore !== true)
|
|
3857
|
+
return { valid: false };
|
|
3858
|
+
if (completion.advance !== 'next' && completion.advance !== 'retry')
|
|
3859
|
+
return { valid: false };
|
|
3860
|
+
if (request.position.mode === 'cursor') {
|
|
3861
|
+
if (completion.advance === 'next') {
|
|
3862
|
+
if (request.position.ordinal >= Number.MAX_SAFE_INTEGER || !isCursor(completion.nextCursor)) {
|
|
3863
|
+
return { valid: false };
|
|
3864
|
+
}
|
|
3865
|
+
if (cursorTokenByteLength(completion.nextCursor) > this.config.maxCursorTokenBytes) {
|
|
3866
|
+
return { valid: false, resourceLimit: 'cursor-token-size' };
|
|
3867
|
+
}
|
|
3868
|
+
if (this.hasCommittedCursor(completion.nextCursor))
|
|
3869
|
+
return { valid: false };
|
|
3870
|
+
}
|
|
3871
|
+
else if ('nextCursor' in completion) {
|
|
3872
|
+
return { valid: false };
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
else if ('nextCursor' in completion) {
|
|
3876
|
+
return { valid: false };
|
|
3877
|
+
}
|
|
3878
|
+
else if (completion.advance === 'next' && request.position.page >= Number.MAX_SAFE_INTEGER) {
|
|
3879
|
+
return { valid: false };
|
|
3880
|
+
}
|
|
3881
|
+
return { valid: true };
|
|
3882
|
+
}
|
|
3883
|
+
case 'exhausted': {
|
|
3884
|
+
if (!exactKeys(completion, [...common, 'items', 'hasMore']) ||
|
|
3885
|
+
!Array.isArray(completion.items) ||
|
|
3886
|
+
completion.hasMore !== false) {
|
|
3887
|
+
return { valid: false };
|
|
3888
|
+
}
|
|
3889
|
+
return { valid: true };
|
|
3890
|
+
}
|
|
3891
|
+
case 'failed': {
|
|
3892
|
+
if (!exactKeys(completion, [...common, 'error']) || !isRecord(completion.error))
|
|
3893
|
+
return { valid: false };
|
|
3894
|
+
const error = completion.error;
|
|
3895
|
+
if (!exactKeys(error, ['message', 'code', 'retryable']) ||
|
|
3896
|
+
typeof error.message !== 'string' ||
|
|
3897
|
+
error.message.trim().length === 0 ||
|
|
3898
|
+
(error.code !== undefined && typeof error.code !== 'string') ||
|
|
3899
|
+
(error.retryable !== undefined && typeof error.retryable !== 'boolean')) {
|
|
3900
|
+
return { valid: false };
|
|
3901
|
+
}
|
|
3902
|
+
return { valid: true };
|
|
3903
|
+
}
|
|
3904
|
+
case 'cancelled': {
|
|
3905
|
+
const hasReason = 'reason' in completion;
|
|
3906
|
+
return (exactKeys(completion, hasReason ? [...common, 'reason'] : common) &&
|
|
3907
|
+
(!hasReason || completion.reason === undefined || completion.reason === 'host-cancelled'))
|
|
3908
|
+
? { valid: true }
|
|
3909
|
+
: { valid: false };
|
|
3910
|
+
}
|
|
3911
|
+
default:
|
|
3912
|
+
return { valid: false };
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
hasCommittedCursor(cursor) {
|
|
3916
|
+
return this.committedCursors.has(cursor) || (this.nextEligiblePosition.mode === 'cursor' && this.nextEligiblePosition.cursor === cursor);
|
|
3917
|
+
}
|
|
3918
|
+
advanceFrom(request, completion) {
|
|
3919
|
+
if (request.position.mode === 'page') {
|
|
3920
|
+
const page = request.position.page;
|
|
3921
|
+
return {
|
|
3922
|
+
position: Object.freeze({ mode: 'page', page: page + 1 }),
|
|
3923
|
+
lastCommittedPage: page,
|
|
3924
|
+
};
|
|
3925
|
+
}
|
|
3926
|
+
const nextCursor = completion.nextCursor;
|
|
3927
|
+
return {
|
|
3928
|
+
position: Object.freeze({
|
|
3929
|
+
mode: 'cursor',
|
|
3930
|
+
cursor: nextCursor,
|
|
3931
|
+
ordinal: request.position.ordinal + 1,
|
|
3932
|
+
}),
|
|
3933
|
+
lastCommittedPage: this.lastCommittedPage,
|
|
3934
|
+
cursorToCommit: nextCursor,
|
|
3935
|
+
};
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
|
|
3057
3939
|
/**
|
|
3058
3940
|
* Enhanced Select Component
|
|
3059
3941
|
* Implements all advanced features: infinite scroll, load more, busy state,
|
|
@@ -3061,9 +3943,72 @@
|
|
|
3061
3943
|
*
|
|
3062
3944
|
* Redesigned with formal elegance, refined microinteractions, and polished UX
|
|
3063
3945
|
*/
|
|
3946
|
+
const LEGACY_DATA_LOADING_CONFIG = {
|
|
3947
|
+
protocol: 'legacy',
|
|
3948
|
+
searchMode: 'local',
|
|
3949
|
+
paginationMode: 'page',
|
|
3950
|
+
firstPage: 1,
|
|
3951
|
+
};
|
|
3952
|
+
const DATA_LOADING_CONFIG_FIELDS = ['protocol', 'searchMode', 'paginationMode', 'firstPage', 'fetchLimit'];
|
|
3953
|
+
const INVALID_OBJECT_VALUE = Object.freeze({ kind: 'object' });
|
|
3954
|
+
const INVALID_ARRAY_VALUE = Object.freeze({ kind: 'array' });
|
|
3955
|
+
const INVALID_FUNCTION_VALUE = Object.freeze({ kind: 'function' });
|
|
3956
|
+
function invalidConfigValueSignature(value) {
|
|
3957
|
+
if (value === null || (typeof value !== 'object' && typeof value !== 'function'))
|
|
3958
|
+
return value;
|
|
3959
|
+
if (typeof value === 'function')
|
|
3960
|
+
return INVALID_FUNCTION_VALUE;
|
|
3961
|
+
return Array.isArray(value) ? INVALID_ARRAY_VALUE : INVALID_OBJECT_VALUE;
|
|
3962
|
+
}
|
|
3963
|
+
function createInvalidDataLoadingCandidateSignature(candidate, issues) {
|
|
3964
|
+
const candidatePrototype = candidate !== null && typeof candidate === 'object'
|
|
3965
|
+
? Object.getPrototypeOf(candidate)
|
|
3966
|
+
: undefined;
|
|
3967
|
+
const isRecord = candidate !== null
|
|
3968
|
+
&& typeof candidate === 'object'
|
|
3969
|
+
&& !Array.isArray(candidate)
|
|
3970
|
+
&& (candidatePrototype === Object.prototype || candidatePrototype === null);
|
|
3971
|
+
const recordCandidate = isRecord ? candidate : undefined;
|
|
3972
|
+
const rootKind = isRecord
|
|
3973
|
+
? 'record'
|
|
3974
|
+
: candidate === null
|
|
3975
|
+
? 'null'
|
|
3976
|
+
: Array.isArray(candidate)
|
|
3977
|
+
? 'array'
|
|
3978
|
+
: typeof candidate;
|
|
3979
|
+
return {
|
|
3980
|
+
rootKind,
|
|
3981
|
+
rootValue: candidate === null || typeof candidate !== 'object' ? candidate : undefined,
|
|
3982
|
+
// Compare at most five supported field values. Unknown fields are represented by their
|
|
3983
|
+
// validation issues below; their values are invalid regardless of shape. Signature work is
|
|
3984
|
+
// therefore independent of nested-value depth (and linear only in the already-built issue list).
|
|
3985
|
+
fieldValues: recordCandidate
|
|
3986
|
+
? DATA_LOADING_CONFIG_FIELDS.map((field) => invalidConfigValueSignature(recordCandidate[field]))
|
|
3987
|
+
: [],
|
|
3988
|
+
issues: issues.map(({ path, code, message }) => [path, code, message]),
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3991
|
+
function invalidDataLoadingSignaturesEqual(left, right) {
|
|
3992
|
+
if (left.rootKind !== right.rootKind || !Object.is(left.rootValue, right.rootValue))
|
|
3993
|
+
return false;
|
|
3994
|
+
if (left.fieldValues.length !== right.fieldValues.length || left.issues.length !== right.issues.length)
|
|
3995
|
+
return false;
|
|
3996
|
+
for (let index = 0; index < left.fieldValues.length; index += 1) {
|
|
3997
|
+
if (!Object.is(left.fieldValues[index], right.fieldValues[index]))
|
|
3998
|
+
return false;
|
|
3999
|
+
}
|
|
4000
|
+
for (let index = 0; index < left.issues.length; index += 1) {
|
|
4001
|
+
const leftIssue = left.issues[index];
|
|
4002
|
+
const rightIssue = right.issues[index];
|
|
4003
|
+
if (leftIssue[0] !== rightIssue[0] || leftIssue[1] !== rightIssue[1] || leftIssue[2] !== rightIssue[2]) {
|
|
4004
|
+
return false;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
return true;
|
|
4008
|
+
}
|
|
3064
4009
|
class EnhancedSelect extends HTMLElement {
|
|
3065
4010
|
static get observedAttributes() {
|
|
3066
|
-
return ['aria-label', 'aria-description'];
|
|
4011
|
+
return ['aria-label', 'aria-description', 'aria-busy'];
|
|
3067
4012
|
}
|
|
3068
4013
|
get classMap() {
|
|
3069
4014
|
return this._classMap;
|
|
@@ -3102,6 +4047,8 @@
|
|
|
3102
4047
|
}
|
|
3103
4048
|
constructor() {
|
|
3104
4049
|
super();
|
|
4050
|
+
this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
|
|
4051
|
+
this._hasLastInvalidDataLoadingCandidate = false;
|
|
3105
4052
|
this._engine = new SelectEngineBridge();
|
|
3106
4053
|
this._virtualizationScope = {
|
|
3107
4054
|
dataKeys: [],
|
|
@@ -3145,6 +4092,29 @@
|
|
|
3145
4092
|
this._selectedRecordsByKey = new Map();
|
|
3146
4093
|
this._registryItemsRef = [];
|
|
3147
4094
|
this._pageCache = {};
|
|
4095
|
+
// One coordinator owns both acknowledged and legacy-adjacent lifecycle state;
|
|
4096
|
+
// the public protocol remains explicitly opt-in and legacy remains default.
|
|
4097
|
+
this._dataRequestCoordinator = null;
|
|
4098
|
+
this._acknowledgedSearchMode = null;
|
|
4099
|
+
this._acknowledgedReady = false;
|
|
4100
|
+
this._acknowledgedDeferredStart = false;
|
|
4101
|
+
this._hasEverConnected = false;
|
|
4102
|
+
this._acknowledgedStartTask = null;
|
|
4103
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
4104
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
4105
|
+
this._acknowledgedDeferredModeChange = false;
|
|
4106
|
+
this._acknowledgedProjectionPending = false;
|
|
4107
|
+
this._acknowledgedProjectionSettling = false;
|
|
4108
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
4109
|
+
this._acknowledgedProjectionFailureStageForTest = null;
|
|
4110
|
+
this._acknowledgedProjectionRunning = false;
|
|
4111
|
+
this._acknowledgedProjectionTask = null;
|
|
4112
|
+
this._acknowledgedProjectionScrollTop = 0;
|
|
4113
|
+
this._acknowledgedLastRequest = null;
|
|
4114
|
+
this._acknowledgedProjectionCommitsPosition = false;
|
|
4115
|
+
this._acknowledgedProjectionRequest = null;
|
|
4116
|
+
this._acknowledgedProjectionAttempt = 0;
|
|
4117
|
+
this._acknowledgedProjectionDiagnostic = null;
|
|
3148
4118
|
this._typeBuffer = '';
|
|
3149
4119
|
this._hasError = false;
|
|
3150
4120
|
this._errorMessage = '';
|
|
@@ -3167,6 +4137,9 @@
|
|
|
3167
4137
|
this._tracking = { events: [], styles: [], limitations: [] };
|
|
3168
4138
|
this._suppressBlurClose = false;
|
|
3169
4139
|
this._renderCycleId = 0;
|
|
4140
|
+
this._completedRenderCycleId = 0;
|
|
4141
|
+
this._renderCycleWaiters = new Map();
|
|
4142
|
+
this._renderCycleWaiterTimeouts = new Map();
|
|
3170
4143
|
this._suppressNextOpenClick = false;
|
|
3171
4144
|
this._resolvedDropdownPlacement = 'bottom';
|
|
3172
4145
|
this._multiScrollDrag = {
|
|
@@ -3264,6 +4237,7 @@
|
|
|
3264
4237
|
this._syncListboxAccessibility();
|
|
3265
4238
|
}
|
|
3266
4239
|
connectedCallback() {
|
|
4240
|
+
this._hasEverConnected = true;
|
|
3267
4241
|
// register instance
|
|
3268
4242
|
EnhancedSelect._instances.add(this);
|
|
3269
4243
|
this._runEngineEffects(this._engine.dispatch({ type: 'CONNECT' }));
|
|
@@ -3280,6 +4254,11 @@
|
|
|
3280
4254
|
// Sync direction attribute (must be in connectedCallback, not constructor)
|
|
3281
4255
|
this._syncDirectionConfig();
|
|
3282
4256
|
this._syncComboboxAccessibility();
|
|
4257
|
+
if (this._dataRequestCoordinator || this._dataLoadingConfig.protocol === 'acknowledged') {
|
|
4258
|
+
// Acknowledged dispatch remains behind the explicit readiness
|
|
4259
|
+
// gate; reconnect only restores observer ownership here.
|
|
4260
|
+
this._initializeObservers();
|
|
4261
|
+
}
|
|
3283
4262
|
if (this._optionRenderer || this._classMap || this._groupHeaderRenderer) {
|
|
3284
4263
|
this._setGlobalStylesMirroring(true);
|
|
3285
4264
|
}
|
|
@@ -3297,15 +4276,33 @@
|
|
|
3297
4276
|
if (this._config.callbacks.onOpen) {
|
|
3298
4277
|
this._config.callbacks.onOpen();
|
|
3299
4278
|
}
|
|
4279
|
+
if (this._acknowledgedDeferredStart) {
|
|
4280
|
+
this._acknowledgedDeferredStart = false;
|
|
4281
|
+
this.startDataLoading();
|
|
4282
|
+
}
|
|
3300
4283
|
}
|
|
3301
4284
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
3302
|
-
if (oldValue === newValue
|
|
4285
|
+
if (oldValue === newValue)
|
|
4286
|
+
return;
|
|
4287
|
+
if (name === 'aria-busy') {
|
|
4288
|
+
this._syncListboxAccessibility();
|
|
4289
|
+
return;
|
|
4290
|
+
}
|
|
4291
|
+
if (name !== 'aria-label' && name !== 'aria-description')
|
|
3303
4292
|
return;
|
|
3304
4293
|
this._syncComboboxAccessibility();
|
|
3305
4294
|
if (name === 'aria-label')
|
|
3306
4295
|
this._syncListboxAccessibility();
|
|
3307
4296
|
}
|
|
3308
4297
|
disconnectedCallback() {
|
|
4298
|
+
if (this._dataRequestCoordinator) {
|
|
4299
|
+
const actions = this._dataRequestCoordinator.disconnect();
|
|
4300
|
+
this._acknowledgedReady = false;
|
|
4301
|
+
this._dispatchAcknowledgedActions(actions);
|
|
4302
|
+
this._state.isBusy = false;
|
|
4303
|
+
this._state.isSearching = false;
|
|
4304
|
+
this._state.preserveScrollPosition = false;
|
|
4305
|
+
}
|
|
3309
4306
|
// unregister instance
|
|
3310
4307
|
EnhancedSelect._instances.delete(this);
|
|
3311
4308
|
if (this._state.isOpen) {
|
|
@@ -3340,6 +4337,7 @@
|
|
|
3340
4337
|
this._arrowContainer.removeEventListener('click', this._boundArrowClick);
|
|
3341
4338
|
}
|
|
3342
4339
|
this._renderCycleId += 1;
|
|
4340
|
+
this._resolvePendingRenderCycles(false);
|
|
3343
4341
|
this._teardownGlobalStylesMirroring();
|
|
3344
4342
|
}
|
|
3345
4343
|
_setGlobalStylesMirroring(enabled) {
|
|
@@ -3870,9 +4868,9 @@
|
|
|
3870
4868
|
this._assertActiveProjection('selection config');
|
|
3871
4869
|
}
|
|
3872
4870
|
}
|
|
3873
|
-
_rebuildItemRegistry(items = this._state.loadedItems) {
|
|
4871
|
+
_rebuildItemRegistry(items = this._state.loadedItems, stagedRegistry) {
|
|
3874
4872
|
// Build first so duplicate-key rejection leaves the previous runtime intact.
|
|
3875
|
-
const registry = createItemRegistry(items, this._itemAdapter, {
|
|
4873
|
+
const registry = stagedRegistry ?? createItemRegistry(items, this._itemAdapter, {
|
|
3876
4874
|
duplicateKeyPolicy: this._getDuplicateKeyPolicy(),
|
|
3877
4875
|
});
|
|
3878
4876
|
const activeKey = this._engine.state.activeKey;
|
|
@@ -6167,17 +7165,47 @@
|
|
|
6167
7165
|
this._intersectionObserver.disconnect();
|
|
6168
7166
|
this._intersectionObserver = undefined;
|
|
6169
7167
|
}
|
|
7168
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged'
|
|
7169
|
+
&& (!this._dataRequestCoordinator || !this._acknowledgedReady))
|
|
7170
|
+
return;
|
|
6170
7171
|
// Intersection observer for infinite scroll
|
|
6171
7172
|
if (this._config.infiniteScroll.enabled) {
|
|
6172
|
-
this.
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
7173
|
+
const acknowledged = Boolean(this._dataRequestCoordinator && this._dataLoadingConfig.protocol === 'acknowledged');
|
|
7174
|
+
if (acknowledged && typeof IntersectionObserver === 'undefined')
|
|
7175
|
+
return;
|
|
7176
|
+
let observer;
|
|
7177
|
+
try {
|
|
7178
|
+
observer = new IntersectionObserver((entries) => {
|
|
7179
|
+
if (this._intersectionObserver !== observer)
|
|
7180
|
+
return;
|
|
7181
|
+
entries.forEach((entry) => {
|
|
7182
|
+
if (acknowledged) {
|
|
7183
|
+
if (!this._acknowledgedReady || !this.isConnected || entry.target !== this._loadMoreTrigger)
|
|
7184
|
+
return;
|
|
7185
|
+
if (!entry.isIntersecting) {
|
|
7186
|
+
this._dataRequestCoordinator?.setSentinelIntersecting(false);
|
|
7187
|
+
return;
|
|
7188
|
+
}
|
|
7189
|
+
if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)
|
|
7190
|
+
return;
|
|
7191
|
+
const actions = this._dataRequestCoordinator?.setSentinelIntersecting(true) ?? [];
|
|
7192
|
+
this._dispatchAcknowledgedActions(actions);
|
|
7193
|
+
return;
|
|
7194
|
+
}
|
|
7195
|
+
if (entry.isIntersecting && !this._state.isBusy) {
|
|
6176
7196
|
this._loadMoreItems();
|
|
6177
7197
|
}
|
|
6178
|
-
}
|
|
6179
|
-
}
|
|
6180
|
-
|
|
7198
|
+
});
|
|
7199
|
+
}, acknowledged
|
|
7200
|
+
? { root: this._optionsContainer, threshold: 0.1 }
|
|
7201
|
+
: { threshold: 0.1 });
|
|
7202
|
+
this._intersectionObserver = observer;
|
|
7203
|
+
}
|
|
7204
|
+
catch (error) {
|
|
7205
|
+
this._intersectionObserver = undefined;
|
|
7206
|
+
if (!acknowledged)
|
|
7207
|
+
throw error;
|
|
7208
|
+
}
|
|
6181
7209
|
}
|
|
6182
7210
|
}
|
|
6183
7211
|
async _loadInitialSelectedItems() {
|
|
@@ -6259,7 +7287,10 @@
|
|
|
6259
7287
|
const accessibilityState = {
|
|
6260
7288
|
...derivedState,
|
|
6261
7289
|
// The component's existing busy lifecycle is not yet mirrored to engine dataStatus.
|
|
6262
|
-
busy
|
|
7290
|
+
// Host presentation busy is additive only for the accepted acknowledged
|
|
7291
|
+
// protocol; legacy host attributes remain inert for listbox semantics.
|
|
7292
|
+
busy: this._state.isBusy || (this._dataLoadingConfig.protocol === 'acknowledged'
|
|
7293
|
+
&& this.getAttribute('aria-busy') === 'true'),
|
|
6263
7294
|
};
|
|
6264
7295
|
const effects = computeAccessibilityEffects(accessibilityState, {
|
|
6265
7296
|
controlsId: this._dropdown.id || null,
|
|
@@ -6525,8 +7556,44 @@
|
|
|
6525
7556
|
return results;
|
|
6526
7557
|
}
|
|
6527
7558
|
_handleSearch(query) {
|
|
7559
|
+
if (this._dataRequestCoordinator
|
|
7560
|
+
&& (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)) {
|
|
7561
|
+
// Keep the committed query/generation stable until the accepted snapshot
|
|
7562
|
+
// has been projected. Coalesce input as a latest-wins intent and dispatch
|
|
7563
|
+
// exactly one new generation after recovery/projection succeeds.
|
|
7564
|
+
this._acknowledgedPendingSearchQuery = query;
|
|
7565
|
+
this._input.value = query;
|
|
7566
|
+
this._syncClearControlState();
|
|
7567
|
+
return;
|
|
7568
|
+
}
|
|
7569
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged'
|
|
7570
|
+
&& (this._dataLoadingConfig.searchMode === 'remote' || this._dataLoadingConfig.searchMode === 'hybrid')) {
|
|
7571
|
+
this._state.searchQuery = query;
|
|
7572
|
+
this._syncClearControlState();
|
|
7573
|
+
this._state.lastNotifiedQuery = query;
|
|
7574
|
+
this._state.lastNotifiedResultCount = 0;
|
|
7575
|
+
if (this._dataRequestCoordinator) {
|
|
7576
|
+
const actions = this._dataRequestCoordinator.setQuery(query);
|
|
7577
|
+
if (this._acknowledgedReady)
|
|
7578
|
+
this._dispatchAcknowledgedActions(actions);
|
|
7579
|
+
else
|
|
7580
|
+
this._renderOptions();
|
|
7581
|
+
}
|
|
7582
|
+
else if (!this._state.isOpen) {
|
|
7583
|
+
this._handleOpen();
|
|
7584
|
+
}
|
|
7585
|
+
else {
|
|
7586
|
+
this._renderOptions();
|
|
7587
|
+
}
|
|
7588
|
+
return;
|
|
7589
|
+
}
|
|
6528
7590
|
this._state.searchQuery = query;
|
|
6529
7591
|
this._syncClearControlState();
|
|
7592
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged' && this._dataRequestCoordinator) {
|
|
7593
|
+
// Local acknowledged search has no remote request, but pagination still
|
|
7594
|
+
// belongs to the coordinator's current query generation.
|
|
7595
|
+
this._dispatchAcknowledgedActions(this._dataRequestCoordinator.setQuery(query));
|
|
7596
|
+
}
|
|
6530
7597
|
if (query.length > 0) {
|
|
6531
7598
|
this._perfMark('smilodon-search-input-last');
|
|
6532
7599
|
this._pendingSearchRenderMark = true;
|
|
@@ -7078,6 +8145,12 @@
|
|
|
7078
8145
|
this._inputContent.insertBefore(badge, this._input);
|
|
7079
8146
|
});
|
|
7080
8147
|
}
|
|
8148
|
+
// A query typed during an accepted-snapshot projection is a pending user
|
|
8149
|
+
// intent, not part of the committed projection state. Keep it visible even
|
|
8150
|
+
// when selection/display synchronization runs during that transaction.
|
|
8151
|
+
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
8152
|
+
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
8153
|
+
}
|
|
7081
8154
|
this._syncClearControlState();
|
|
7082
8155
|
}
|
|
7083
8156
|
_renderOptionsWithAnimation() {
|
|
@@ -7145,7 +8218,24 @@
|
|
|
7145
8218
|
this._setActive(targetIndex, 'programmatic');
|
|
7146
8219
|
}
|
|
7147
8220
|
}
|
|
7148
|
-
async _loadMoreItems() {
|
|
8221
|
+
async _loadMoreItems(trigger = 'manual') {
|
|
8222
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged') {
|
|
8223
|
+
if (!this._dataRequestCoordinator
|
|
8224
|
+
|| !this._acknowledgedReady
|
|
8225
|
+
|| this._acknowledgedProjectionPending
|
|
8226
|
+
|| this._acknowledgedProjectionSettling)
|
|
8227
|
+
return;
|
|
8228
|
+
const actions = this._dataRequestCoordinator.requestLoadMore(trigger);
|
|
8229
|
+
this._dispatchAcknowledgedActions(actions);
|
|
8230
|
+
return;
|
|
8231
|
+
}
|
|
8232
|
+
if (this._dataRequestCoordinator) {
|
|
8233
|
+
if (!this._acknowledgedReady || this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)
|
|
8234
|
+
return;
|
|
8235
|
+
const actions = this._dataRequestCoordinator.requestLoadMore(trigger);
|
|
8236
|
+
this._dispatchAcknowledgedActions(actions);
|
|
8237
|
+
return;
|
|
8238
|
+
}
|
|
7149
8239
|
if (this._state.isBusy)
|
|
7150
8240
|
return;
|
|
7151
8241
|
this._setBusy(true);
|
|
@@ -7375,6 +8465,27 @@
|
|
|
7375
8465
|
if (!this._state.searchQuery)
|
|
7376
8466
|
this._updateInputDisplay();
|
|
7377
8467
|
const newLength = this._state.loadedItems.length;
|
|
8468
|
+
if (this._dataRequestCoordinator) {
|
|
8469
|
+
const acknowledgedBusy = this._dataRequestCoordinator.getSnapshot().busy
|
|
8470
|
+
|| this._acknowledgedProjectionPending;
|
|
8471
|
+
this._state.isSearching = false;
|
|
8472
|
+
this._state.isBusy = acknowledgedBusy;
|
|
8473
|
+
if (this._state.preserveScrollPosition && this._dropdown) {
|
|
8474
|
+
const targetScrollTop = this._state.lastScrollPosition;
|
|
8475
|
+
this._renderOptions();
|
|
8476
|
+
this._optionsContainer.scrollTop = targetScrollTop;
|
|
8477
|
+
this._requestLifecycleFrame(() => {
|
|
8478
|
+
if (this._optionsContainer)
|
|
8479
|
+
this._optionsContainer.scrollTop = targetScrollTop;
|
|
8480
|
+
});
|
|
8481
|
+
if (!acknowledgedBusy)
|
|
8482
|
+
this._state.preserveScrollPosition = false;
|
|
8483
|
+
}
|
|
8484
|
+
else {
|
|
8485
|
+
this._renderOptions();
|
|
8486
|
+
}
|
|
8487
|
+
return;
|
|
8488
|
+
}
|
|
7378
8489
|
// When infinite scroll is active (preserveScrollPosition = true),
|
|
7379
8490
|
// we need to maintain scroll position during the update
|
|
7380
8491
|
if (this._state.preserveScrollPosition && this._dropdown) {
|
|
@@ -7550,9 +8661,55 @@
|
|
|
7550
8661
|
this._invalidateGuardedMeasurements();
|
|
7551
8662
|
const previousMode = this._config.selection.mode;
|
|
7552
8663
|
const previousEnabled = this._config.enabled;
|
|
7553
|
-
|
|
8664
|
+
const previousDataLoadingConfig = this._dataLoadingConfig;
|
|
8665
|
+
const { dataLoading, callbacks, ...legacyConfig } = config;
|
|
8666
|
+
const legacyUpdate = { ...legacyConfig };
|
|
8667
|
+
let configErrorDetail;
|
|
8668
|
+
if (callbacks !== undefined && callbacks !== null) {
|
|
8669
|
+
const callbackInput = callbacks;
|
|
8670
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataLoadingConfigError')) {
|
|
8671
|
+
this._dataLoadingConfigErrorCallback = callbackInput.onDataLoadingConfigError;
|
|
8672
|
+
}
|
|
8673
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataRequestCancel')) {
|
|
8674
|
+
this._dataRequestCancelCallback = callbackInput.onDataRequestCancel;
|
|
8675
|
+
}
|
|
8676
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataProjection')) {
|
|
8677
|
+
this._dataProjectionCallback = callbackInput.onDataProjection;
|
|
8678
|
+
}
|
|
8679
|
+
const legacyCallbacks = { ...callbackInput };
|
|
8680
|
+
delete legacyCallbacks.onDataLoadingConfigError;
|
|
8681
|
+
delete legacyCallbacks.onDataRequestCancel;
|
|
8682
|
+
delete legacyCallbacks.onDataProjection;
|
|
8683
|
+
legacyUpdate.callbacks = legacyCallbacks;
|
|
8684
|
+
}
|
|
8685
|
+
this._config = this._mergeConfig(this._config, legacyUpdate);
|
|
8686
|
+
if (dataLoading !== undefined) {
|
|
8687
|
+
const dataLoadingPrototype = dataLoading !== null && typeof dataLoading === 'object'
|
|
8688
|
+
? Object.getPrototypeOf(dataLoading)
|
|
8689
|
+
: undefined;
|
|
8690
|
+
const candidate = dataLoadingPrototype === Object.prototype || dataLoadingPrototype === null
|
|
8691
|
+
? { ...this._dataLoadingConfig, ...dataLoading }
|
|
8692
|
+
: dataLoading;
|
|
8693
|
+
const validation = validateDataLoadingConfig(candidate);
|
|
8694
|
+
if (validation.valid) {
|
|
8695
|
+
this._dataLoadingConfig = validation.value;
|
|
8696
|
+
this._hasLastInvalidDataLoadingCandidate = false;
|
|
8697
|
+
this._lastInvalidDataLoadingCandidate = undefined;
|
|
8698
|
+
}
|
|
8699
|
+
else {
|
|
8700
|
+
const candidateSignature = createInvalidDataLoadingCandidateSignature(candidate, validation.issues);
|
|
8701
|
+
if (!this._hasLastInvalidDataLoadingCandidate ||
|
|
8702
|
+
!this._lastInvalidDataLoadingCandidate ||
|
|
8703
|
+
!invalidDataLoadingSignaturesEqual(this._lastInvalidDataLoadingCandidate, candidateSignature)) {
|
|
8704
|
+
this._hasLastInvalidDataLoadingCandidate = true;
|
|
8705
|
+
this._lastInvalidDataLoadingCandidate = candidateSignature;
|
|
8706
|
+
configErrorDetail = { issues: validation.issues };
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
}
|
|
7554
8710
|
this._rebuildItemRegistry();
|
|
7555
8711
|
if (previousEnabled !== this._config.enabled) {
|
|
8712
|
+
this._input.disabled = !this._config.enabled;
|
|
7556
8713
|
if (!this._config.enabled && this._state.isOpen) {
|
|
7557
8714
|
this._handleClose('disabled');
|
|
7558
8715
|
}
|
|
@@ -7611,6 +8768,291 @@
|
|
|
7611
8768
|
this._syncClearControlState();
|
|
7612
8769
|
this._updateInputDisplay();
|
|
7613
8770
|
}
|
|
8771
|
+
this._acknowledgedSearchMode = this._dataLoadingConfig.searchMode;
|
|
8772
|
+
if (this._dataLoadingConfig.protocol === 'legacy')
|
|
8773
|
+
this._acknowledgedDeferredStart = false;
|
|
8774
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8775
|
+
const switchesToLegacy = previousDataLoadingConfig.protocol === 'acknowledged'
|
|
8776
|
+
&& this._dataLoadingConfig.protocol === 'legacy';
|
|
8777
|
+
const acknowledgedModeChanged = previousDataLoadingConfig.protocol !== this._dataLoadingConfig.protocol
|
|
8778
|
+
|| previousDataLoadingConfig.searchMode !== this._dataLoadingConfig.searchMode
|
|
8779
|
+
|| previousDataLoadingConfig.paginationMode !== this._dataLoadingConfig.paginationMode;
|
|
8780
|
+
if (coordinator && switchesToLegacy) {
|
|
8781
|
+
if (this._acknowledgedReady && !this._acknowledgedProjectionPending && !this._acknowledgedProjectionSettling) {
|
|
8782
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
8783
|
+
if (update.status === 'accepted')
|
|
8784
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
8785
|
+
}
|
|
8786
|
+
this._acknowledgedReady = false;
|
|
8787
|
+
this._dispatchAcknowledgedActions(coordinator.disconnect());
|
|
8788
|
+
if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling) {
|
|
8789
|
+
this._clearAcknowledgedCoordinatorAfterProjection = true;
|
|
8790
|
+
}
|
|
8791
|
+
else {
|
|
8792
|
+
this._dataRequestCoordinator = null;
|
|
8793
|
+
this._acknowledgedSearchMode = null;
|
|
8794
|
+
this._state.isBusy = false;
|
|
8795
|
+
this._state.isSearching = false;
|
|
8796
|
+
this._syncListboxAccessibility();
|
|
8797
|
+
this._renderOptions();
|
|
8798
|
+
}
|
|
8799
|
+
}
|
|
8800
|
+
else if (coordinator && this._dataLoadingConfig.protocol === 'acknowledged') {
|
|
8801
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
8802
|
+
if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling) {
|
|
8803
|
+
this._acknowledgedConfigUpdatePending = true;
|
|
8804
|
+
this._acknowledgedDeferredModeChange || (this._acknowledgedDeferredModeChange = acknowledgedModeChanged);
|
|
8805
|
+
}
|
|
8806
|
+
else if (this._acknowledgedReady) {
|
|
8807
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
8808
|
+
if (update.status === 'accepted') {
|
|
8809
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
8810
|
+
const snapshot = coordinator.getSnapshot();
|
|
8811
|
+
this._state.isBusy = snapshot.busy;
|
|
8812
|
+
this._state.isSearching = snapshot.activeRequest?.kind === 'search';
|
|
8813
|
+
this._syncListboxAccessibility();
|
|
8814
|
+
if (update.actions.every((action) => action.type !== 'request'))
|
|
8815
|
+
this._renderOptions();
|
|
8816
|
+
}
|
|
8817
|
+
}
|
|
8818
|
+
}
|
|
8819
|
+
if (configErrorDetail) {
|
|
8820
|
+
this._emit('dataLoadingConfigError', configErrorDetail);
|
|
8821
|
+
try {
|
|
8822
|
+
this._dataLoadingConfigErrorCallback?.(configErrorDetail);
|
|
8823
|
+
}
|
|
8824
|
+
catch (error) {
|
|
8825
|
+
this._handleError(error);
|
|
8826
|
+
}
|
|
8827
|
+
}
|
|
8828
|
+
}
|
|
8829
|
+
/** Open the acknowledged request lifecycle after the host has installed listeners. */
|
|
8830
|
+
startDataLoading() {
|
|
8831
|
+
const projectionRecoveryOnly = Boolean(this._dataRequestCoordinator && this._acknowledgedProjectionPending);
|
|
8832
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged' && !projectionRecoveryOnly)
|
|
8833
|
+
return;
|
|
8834
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged' && !this._ensureDataRequestCoordinator())
|
|
8835
|
+
return;
|
|
8836
|
+
if (!this.isConnected) {
|
|
8837
|
+
if (!this._hasEverConnected)
|
|
8838
|
+
this._acknowledgedDeferredStart = true;
|
|
8839
|
+
return;
|
|
8840
|
+
}
|
|
8841
|
+
if (this._acknowledgedReady)
|
|
8842
|
+
return;
|
|
8843
|
+
if (this._acknowledgedStartTask) {
|
|
8844
|
+
// A reconnect can arrive while the previous readiness task is still
|
|
8845
|
+
// unwinding an interrupted render. Preserve the restart request so the
|
|
8846
|
+
// accepted projection is recovered as soon as that task settles.
|
|
8847
|
+
this._acknowledgedDeferredStart = true;
|
|
8848
|
+
return;
|
|
8849
|
+
}
|
|
8850
|
+
const task = this._startAcknowledgedDataLoading();
|
|
8851
|
+
this._acknowledgedStartTask = task;
|
|
8852
|
+
void task.finally(() => {
|
|
8853
|
+
if (this._acknowledgedStartTask !== task)
|
|
8854
|
+
return;
|
|
8855
|
+
this._acknowledgedStartTask = null;
|
|
8856
|
+
if (this._acknowledgedDeferredStart && this.isConnected) {
|
|
8857
|
+
this._acknowledgedDeferredStart = false;
|
|
8858
|
+
this.startDataLoading();
|
|
8859
|
+
}
|
|
8860
|
+
}).catch((error) => this._handleError(error));
|
|
8861
|
+
}
|
|
8862
|
+
/** Return detached coordinator state without exposing its canonical item storage. */
|
|
8863
|
+
getDataLoadingState() {
|
|
8864
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8865
|
+
if (!coordinator) {
|
|
8866
|
+
const isRemote = this._dataLoadingConfig.searchMode === 'remote'
|
|
8867
|
+
|| this._dataLoadingConfig.searchMode === 'hybrid';
|
|
8868
|
+
const nextEligiblePosition = this._dataLoadingConfig.paginationMode === 'cursor'
|
|
8869
|
+
? { mode: 'cursor', ordinal: 1 }
|
|
8870
|
+
: {
|
|
8871
|
+
mode: 'page',
|
|
8872
|
+
page: isRemote
|
|
8873
|
+
? this._dataLoadingConfig.firstPage
|
|
8874
|
+
: (this._config.infiniteScroll.initialPage ?? 1) + 1,
|
|
8875
|
+
};
|
|
8876
|
+
return {
|
|
8877
|
+
status: 'idle',
|
|
8878
|
+
connected: this.isConnected,
|
|
8879
|
+
busy: false,
|
|
8880
|
+
projectionPending: false,
|
|
8881
|
+
queryGeneration: 0,
|
|
8882
|
+
activeRequest: null,
|
|
8883
|
+
hasMore: this._dataLoadingConfig.protocol === 'acknowledged'
|
|
8884
|
+
&& !isRemote
|
|
8885
|
+
&& (this._config.infiniteScroll.enabled || this._config.loadMore.enabled),
|
|
8886
|
+
nextEligiblePosition,
|
|
8887
|
+
error: null,
|
|
8888
|
+
resourceLimit: null,
|
|
8889
|
+
};
|
|
8890
|
+
}
|
|
8891
|
+
const snapshot = coordinator.getSnapshot();
|
|
8892
|
+
const activeRequest = snapshot.activeRequest
|
|
8893
|
+
? {
|
|
8894
|
+
...snapshot.activeRequest,
|
|
8895
|
+
position: { ...snapshot.activeRequest.position },
|
|
8896
|
+
}
|
|
8897
|
+
: null;
|
|
8898
|
+
return {
|
|
8899
|
+
status: snapshot.status,
|
|
8900
|
+
connected: snapshot.connected,
|
|
8901
|
+
busy: snapshot.busy || this._acknowledgedProjectionPending,
|
|
8902
|
+
projectionPending: this._acknowledgedProjectionPending,
|
|
8903
|
+
queryGeneration: snapshot.queryGeneration,
|
|
8904
|
+
activeRequest,
|
|
8905
|
+
hasMore: snapshot.hasMore,
|
|
8906
|
+
nextEligiblePosition: { ...snapshot.nextEligiblePosition },
|
|
8907
|
+
error: snapshot.error ? { ...snapshot.error } : null,
|
|
8908
|
+
resourceLimit: snapshot.resourceLimit ? { ...snapshot.resourceLimit } : null,
|
|
8909
|
+
};
|
|
8910
|
+
}
|
|
8911
|
+
/** Synchronously accept/classify a host completion; DOM projection proceeds asynchronously. */
|
|
8912
|
+
completeDataRequest(completion) {
|
|
8913
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8914
|
+
if (!coordinator) {
|
|
8915
|
+
const candidate = completion;
|
|
8916
|
+
if (candidate === null
|
|
8917
|
+
|| typeof candidate !== 'object'
|
|
8918
|
+
|| !('requestId' in candidate)
|
|
8919
|
+
|| typeof candidate.requestId !== 'string'
|
|
8920
|
+
|| candidate.requestId.length === 0
|
|
8921
|
+
|| !('queryGeneration' in candidate)
|
|
8922
|
+
|| !Number.isSafeInteger(candidate.queryGeneration)
|
|
8923
|
+
|| candidate.queryGeneration < 0
|
|
8924
|
+
|| !('status' in candidate)
|
|
8925
|
+
|| typeof candidate.status !== 'string'
|
|
8926
|
+
|| !['succeeded', 'empty', 'exhausted', 'failed', 'cancelled'].includes(candidate.status))
|
|
8927
|
+
return 'invalid';
|
|
8928
|
+
return 'unknown-request';
|
|
8929
|
+
}
|
|
8930
|
+
const snapshotBefore = coordinator.getSnapshot();
|
|
8931
|
+
const completionRecord = completion && typeof completion === 'object'
|
|
8932
|
+
? completion
|
|
8933
|
+
: null;
|
|
8934
|
+
const activeRequest = snapshotBefore.activeRequest;
|
|
8935
|
+
const request = activeRequest
|
|
8936
|
+
&& completionRecord?.requestId === activeRequest.requestId
|
|
8937
|
+
&& completionRecord?.queryGeneration === activeRequest.queryGeneration
|
|
8938
|
+
? activeRequest
|
|
8939
|
+
: null;
|
|
8940
|
+
const status = completionRecord?.status;
|
|
8941
|
+
const advancesPosition = status === 'succeeded'
|
|
8942
|
+
|| status === 'exhausted'
|
|
8943
|
+
|| (status === 'empty' && completionRecord?.advance === 'next');
|
|
8944
|
+
const result = coordinator.completeDataRequest(completion);
|
|
8945
|
+
if (result === 'accepted' && request) {
|
|
8946
|
+
this._acknowledgedLastRequest = request;
|
|
8947
|
+
this._acknowledgedProjectionRequest = request;
|
|
8948
|
+
this._acknowledgedProjectionAttempt = 0;
|
|
8949
|
+
this._acknowledgedProjectionCommitsPosition = advancesPosition;
|
|
8950
|
+
void this._projectAcknowledgedSnapshot(coordinator.getSnapshot(), request, advancesPosition);
|
|
8951
|
+
}
|
|
8952
|
+
else if (result === 'resource-limit') {
|
|
8953
|
+
const resourceLimit = coordinator.getSnapshot().resourceLimit;
|
|
8954
|
+
this._emit('diagnostic', {
|
|
8955
|
+
timestamp: Date.now(),
|
|
8956
|
+
source: 'event',
|
|
8957
|
+
name: 'acknowledgedDataLoadingResourceLimit',
|
|
8958
|
+
detail: resourceLimit,
|
|
8959
|
+
});
|
|
8960
|
+
}
|
|
8961
|
+
return result;
|
|
8962
|
+
}
|
|
8963
|
+
_createCoordinatorConfig() {
|
|
8964
|
+
return {
|
|
8965
|
+
dataLoading: { ...this._dataLoadingConfig },
|
|
8966
|
+
infiniteScroll: {
|
|
8967
|
+
pageSize: this._config.infiniteScroll.pageSize,
|
|
8968
|
+
initialPage: this._config.infiniteScroll.initialPage,
|
|
8969
|
+
},
|
|
8970
|
+
};
|
|
8971
|
+
}
|
|
8972
|
+
_ensureDataRequestCoordinator() {
|
|
8973
|
+
if (!this._dataRequestCoordinator) {
|
|
8974
|
+
const isRemote = this._dataLoadingConfig.searchMode === 'remote'
|
|
8975
|
+
|| this._dataLoadingConfig.searchMode === 'hybrid';
|
|
8976
|
+
try {
|
|
8977
|
+
this._dataRequestCoordinator = new DataRequestCoordinator({
|
|
8978
|
+
config: this._createCoordinatorConfig(),
|
|
8979
|
+
initialQuery: this._state.searchQuery,
|
|
8980
|
+
initialItems: this._state.loadedItems,
|
|
8981
|
+
hasMore: !isRemote && (this._config.infiniteScroll.enabled || this._config.loadMore.enabled),
|
|
8982
|
+
});
|
|
8983
|
+
}
|
|
8984
|
+
catch (error) {
|
|
8985
|
+
const detail = {
|
|
8986
|
+
issues: [{
|
|
8987
|
+
path: 'dataLoading',
|
|
8988
|
+
code: 'invalid-value',
|
|
8989
|
+
message: `Acknowledged data loading could not start: ${error instanceof Error ? error.message : String(error)}`,
|
|
8990
|
+
}],
|
|
8991
|
+
};
|
|
8992
|
+
this._emit('dataLoadingConfigError', detail);
|
|
8993
|
+
try {
|
|
8994
|
+
this._dataLoadingConfigErrorCallback?.(detail);
|
|
8995
|
+
}
|
|
8996
|
+
catch (callbackError) {
|
|
8997
|
+
this._handleError(callbackError);
|
|
8998
|
+
}
|
|
8999
|
+
return null;
|
|
9000
|
+
}
|
|
9001
|
+
}
|
|
9002
|
+
this._acknowledgedSearchMode = this._dataLoadingConfig.searchMode;
|
|
9003
|
+
return this._dataRequestCoordinator;
|
|
9004
|
+
}
|
|
9005
|
+
async _startAcknowledgedDataLoading() {
|
|
9006
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9007
|
+
const projectionRecoveryOnly = Boolean(coordinator && this._acknowledgedProjectionPending);
|
|
9008
|
+
if (!coordinator
|
|
9009
|
+
|| (this._dataLoadingConfig.protocol !== 'acknowledged' && !projectionRecoveryOnly)
|
|
9010
|
+
|| !this.isConnected)
|
|
9011
|
+
return;
|
|
9012
|
+
if (this._acknowledgedReady)
|
|
9013
|
+
return;
|
|
9014
|
+
if (this._acknowledgedProjectionPending) {
|
|
9015
|
+
const interruptedProjection = this._acknowledgedProjectionTask;
|
|
9016
|
+
if (interruptedProjection)
|
|
9017
|
+
await interruptedProjection;
|
|
9018
|
+
if (!this.isConnected)
|
|
9019
|
+
return;
|
|
9020
|
+
if (this._acknowledgedProjectionPending) {
|
|
9021
|
+
await this._retryAcknowledgedProjection();
|
|
9022
|
+
}
|
|
9023
|
+
if (!this.isConnected || this._acknowledgedProjectionPending)
|
|
9024
|
+
return;
|
|
9025
|
+
}
|
|
9026
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged'
|
|
9027
|
+
|| !this._dataRequestCoordinator)
|
|
9028
|
+
return;
|
|
9029
|
+
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
9030
|
+
this._state.searchQuery = this._acknowledgedPendingSearchQuery;
|
|
9031
|
+
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
9032
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9033
|
+
}
|
|
9034
|
+
const configUpdate = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
9035
|
+
if (configUpdate.status !== 'accepted') {
|
|
9036
|
+
this._acknowledgedReady = false;
|
|
9037
|
+
return;
|
|
9038
|
+
}
|
|
9039
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9040
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9041
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
9042
|
+
this._acknowledgedReady = true;
|
|
9043
|
+
this._initializeObservers();
|
|
9044
|
+
const configActions = configUpdate.actions;
|
|
9045
|
+
this._dispatchAcknowledgedActions(configActions);
|
|
9046
|
+
const connectionActions = coordinator.connect(this._state.searchQuery);
|
|
9047
|
+
this._dispatchAcknowledgedActions(connectionActions);
|
|
9048
|
+
if (configActions.length === 0 && connectionActions.length === 0)
|
|
9049
|
+
this._renderOptions();
|
|
9050
|
+
const readyRenderCycleId = this._renderCycleId;
|
|
9051
|
+
const readyRenderCompleted = await this._waitForRenderCycle(readyRenderCycleId);
|
|
9052
|
+
if (!readyRenderCompleted) {
|
|
9053
|
+
this._acknowledgedReady = false;
|
|
9054
|
+
throw new Error('Acknowledged readiness render was superseded before completion');
|
|
9055
|
+
}
|
|
7614
9056
|
}
|
|
7615
9057
|
_mergeConfig(target, source) {
|
|
7616
9058
|
const result = { ...target };
|
|
@@ -7663,7 +9105,8 @@
|
|
|
7663
9105
|
return;
|
|
7664
9106
|
const enabled = this._config.clearControl.enabled === true;
|
|
7665
9107
|
const hasSelection = this._state.selectedIndices.size > 0;
|
|
7666
|
-
const
|
|
9108
|
+
const visibleSearchQuery = this._acknowledgedPendingSearchQuery ?? this._state.searchQuery;
|
|
9109
|
+
const hasSearch = visibleSearchQuery.length > 0;
|
|
7667
9110
|
const clearSelection = this._config.clearControl.clearSelection !== false;
|
|
7668
9111
|
const clearSearch = this._config.clearControl.clearSearch !== false;
|
|
7669
9112
|
const hasSomethingToClear = (clearSelection && hasSelection) || (clearSearch && hasSearch);
|
|
@@ -7934,6 +9377,355 @@
|
|
|
7934
9377
|
this._guardedVirtualOverscan = 0;
|
|
7935
9378
|
return true;
|
|
7936
9379
|
}
|
|
9380
|
+
/** Test-only activation seam; deliberately absent from public config/types. */
|
|
9381
|
+
_enableAcknowledgedDataLoadingForTest(config, options = {}) {
|
|
9382
|
+
if (this._dataRequestCoordinator) {
|
|
9383
|
+
throw new Error('Acknowledged data loading is already enabled for this test instance');
|
|
9384
|
+
}
|
|
9385
|
+
const dataLoading = config.dataLoading;
|
|
9386
|
+
this._dataLoadingConfig = {
|
|
9387
|
+
protocol: dataLoading?.protocol ?? 'acknowledged',
|
|
9388
|
+
searchMode: dataLoading?.searchMode ?? 'local',
|
|
9389
|
+
paginationMode: dataLoading?.paginationMode ?? 'page',
|
|
9390
|
+
firstPage: dataLoading?.firstPage ?? 1,
|
|
9391
|
+
...(dataLoading?.fetchLimit === undefined ? {} : { fetchLimit: dataLoading.fetchLimit }),
|
|
9392
|
+
};
|
|
9393
|
+
this._acknowledgedSearchMode = config.dataLoading?.searchMode ?? 'local';
|
|
9394
|
+
this._dataRequestCoordinator = new DataRequestCoordinator({
|
|
9395
|
+
config,
|
|
9396
|
+
initialQuery: this._state.searchQuery,
|
|
9397
|
+
initialItems: this._state.loadedItems,
|
|
9398
|
+
hasMore: options.hasMore,
|
|
9399
|
+
});
|
|
9400
|
+
this._acknowledgedReady = false;
|
|
9401
|
+
if (this.isConnected)
|
|
9402
|
+
this._initializeObservers();
|
|
9403
|
+
}
|
|
9404
|
+
/** Listener installation must precede this private test-only readiness gate. */
|
|
9405
|
+
async _setAcknowledgedDataLoadingReadyForTest() {
|
|
9406
|
+
if (!this._dataRequestCoordinator)
|
|
9407
|
+
throw new Error('Enable acknowledged data loading before readiness');
|
|
9408
|
+
if (!this.isConnected)
|
|
9409
|
+
throw new Error('Acknowledged readiness requires a connected test element');
|
|
9410
|
+
if (this._acknowledgedReady)
|
|
9411
|
+
return;
|
|
9412
|
+
if (this._acknowledgedProjectionPending) {
|
|
9413
|
+
const interruptedProjection = this._acknowledgedProjectionTask;
|
|
9414
|
+
if (interruptedProjection)
|
|
9415
|
+
await interruptedProjection;
|
|
9416
|
+
if (this._acknowledgedProjectionPending) {
|
|
9417
|
+
await this._retryAcknowledgedProjectionForTest();
|
|
9418
|
+
}
|
|
9419
|
+
if (this._acknowledgedProjectionPending) {
|
|
9420
|
+
throw new Error('Acknowledged readiness cannot open while snapshot projection is pending');
|
|
9421
|
+
}
|
|
9422
|
+
}
|
|
9423
|
+
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
9424
|
+
this._state.searchQuery = this._acknowledgedPendingSearchQuery;
|
|
9425
|
+
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
9426
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9427
|
+
}
|
|
9428
|
+
this._acknowledgedReady = true;
|
|
9429
|
+
this._initializeObservers();
|
|
9430
|
+
const actions = this._dataRequestCoordinator.connect(this._state.searchQuery);
|
|
9431
|
+
this._dispatchAcknowledgedActions(actions);
|
|
9432
|
+
if (actions.length === 0)
|
|
9433
|
+
this._renderOptions();
|
|
9434
|
+
const readyRenderCycleId = this._renderCycleId;
|
|
9435
|
+
const readyRenderCompleted = await this._waitForRenderCycle(readyRenderCycleId);
|
|
9436
|
+
if (!readyRenderCompleted) {
|
|
9437
|
+
this._acknowledgedReady = false;
|
|
9438
|
+
throw new Error('Acknowledged readiness render was superseded before completion');
|
|
9439
|
+
}
|
|
9440
|
+
}
|
|
9441
|
+
_dispatchAcknowledgedActions(actions) {
|
|
9442
|
+
for (const action of actions) {
|
|
9443
|
+
if (action.type === 'cancel') {
|
|
9444
|
+
this._dispatchAcknowledgedEvent('dataRequestCancel', action.notification);
|
|
9445
|
+
try {
|
|
9446
|
+
this._dataRequestCancelCallback?.(action.notification);
|
|
9447
|
+
}
|
|
9448
|
+
catch (error) {
|
|
9449
|
+
this._handleError(error);
|
|
9450
|
+
}
|
|
9451
|
+
continue;
|
|
9452
|
+
}
|
|
9453
|
+
const request = action.request;
|
|
9454
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9455
|
+
if (!coordinator || !this._acknowledgedReady)
|
|
9456
|
+
continue;
|
|
9457
|
+
if (request.kind === 'loadMore') {
|
|
9458
|
+
this._state.lastScrollPosition = this._optionsContainer.scrollTop;
|
|
9459
|
+
this._acknowledgedProjectionScrollTop = this._state.lastScrollPosition;
|
|
9460
|
+
this._state.preserveScrollPosition = true;
|
|
9461
|
+
this._state.isSearching = false;
|
|
9462
|
+
}
|
|
9463
|
+
else {
|
|
9464
|
+
this._acknowledgedProjectionScrollTop = 0;
|
|
9465
|
+
this._state.preserveScrollPosition = false;
|
|
9466
|
+
this._state.isSearching = true;
|
|
9467
|
+
}
|
|
9468
|
+
this._state.isBusy = true;
|
|
9469
|
+
this._acknowledgedLastRequest = request;
|
|
9470
|
+
this._syncListboxAccessibility();
|
|
9471
|
+
this._renderOptions();
|
|
9472
|
+
if (request.kind === 'loadMore') {
|
|
9473
|
+
this._optionsContainer.scrollTop = this._state.lastScrollPosition;
|
|
9474
|
+
}
|
|
9475
|
+
if (!coordinator.markNotificationsDispatched(request.requestId))
|
|
9476
|
+
continue;
|
|
9477
|
+
if (request.kind === 'search') {
|
|
9478
|
+
const detail = { query: request.query, results: [], count: 0, request };
|
|
9479
|
+
this._dispatchAcknowledgedEvent('search', detail);
|
|
9480
|
+
try {
|
|
9481
|
+
const callback = this._config.callbacks.onSearch;
|
|
9482
|
+
callback?.(request.query, request);
|
|
9483
|
+
}
|
|
9484
|
+
catch (error) {
|
|
9485
|
+
this._handleError(error);
|
|
9486
|
+
}
|
|
9487
|
+
}
|
|
9488
|
+
else {
|
|
9489
|
+
const page = request.position.mode === 'page'
|
|
9490
|
+
? request.position.page
|
|
9491
|
+
: request.position.ordinal;
|
|
9492
|
+
const detail = { page, items: [], request };
|
|
9493
|
+
this._dispatchAcknowledgedEvent('loadMore', detail);
|
|
9494
|
+
try {
|
|
9495
|
+
const callback = this._config.callbacks.onLoadMore;
|
|
9496
|
+
callback?.(page, request);
|
|
9497
|
+
}
|
|
9498
|
+
catch (error) {
|
|
9499
|
+
this._handleError(error);
|
|
9500
|
+
}
|
|
9501
|
+
}
|
|
9502
|
+
}
|
|
9503
|
+
}
|
|
9504
|
+
_dispatchAcknowledgedEvent(name, detail) {
|
|
9505
|
+
this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
9506
|
+
this._track('event', name, detail);
|
|
9507
|
+
}
|
|
9508
|
+
/** Test-only completion seam; accepted snapshots are projected from coordinator state. */
|
|
9509
|
+
async _completeDataRequestForTest(completion) {
|
|
9510
|
+
const result = this.completeDataRequest(completion);
|
|
9511
|
+
if (result !== 'accepted')
|
|
9512
|
+
return result;
|
|
9513
|
+
await this._acknowledgedProjectionTask;
|
|
9514
|
+
return result;
|
|
9515
|
+
}
|
|
9516
|
+
_failNextAcknowledgedProjectionForTest(stage = 'before-publish') {
|
|
9517
|
+
this._acknowledgedProjectionFailureStageForTest = stage;
|
|
9518
|
+
}
|
|
9519
|
+
/** Retries only from the canonical accepted coordinator snapshot, never a host payload. */
|
|
9520
|
+
_retryAcknowledgedProjectionForTest() {
|
|
9521
|
+
return this._retryAcknowledgedProjection();
|
|
9522
|
+
}
|
|
9523
|
+
_retryAcknowledgedProjection() {
|
|
9524
|
+
if (!this._dataRequestCoordinator || !this._acknowledgedProjectionPending)
|
|
9525
|
+
return Promise.resolve();
|
|
9526
|
+
return this._projectAcknowledgedSnapshot(this._dataRequestCoordinator.getSnapshot(), this._acknowledgedProjectionRequest ?? this._acknowledgedLastRequest, this._acknowledgedProjectionCommitsPosition);
|
|
9527
|
+
}
|
|
9528
|
+
_projectAcknowledgedSnapshot(snapshot, request, commitPosition) {
|
|
9529
|
+
if (this._acknowledgedProjectionRunning) {
|
|
9530
|
+
return this._acknowledgedProjectionTask ?? Promise.resolve();
|
|
9531
|
+
}
|
|
9532
|
+
this._acknowledgedProjectionRequest = request ?? this._acknowledgedProjectionRequest;
|
|
9533
|
+
this._acknowledgedProjectionAttempt += 1;
|
|
9534
|
+
this._acknowledgedProjectionPending = true;
|
|
9535
|
+
const items = Array.from(snapshot.items);
|
|
9536
|
+
let stagedRegistry;
|
|
9537
|
+
let groupedItems;
|
|
9538
|
+
try {
|
|
9539
|
+
stagedRegistry = createItemRegistry(items, this._itemAdapter, {
|
|
9540
|
+
duplicateKeyPolicy: this._getDuplicateKeyPolicy(),
|
|
9541
|
+
});
|
|
9542
|
+
groupedItems = this._groupItemsByProperty(items);
|
|
9543
|
+
if (this._acknowledgedProjectionFailureStageForTest === 'before-publish') {
|
|
9544
|
+
this._acknowledgedProjectionFailureStageForTest = null;
|
|
9545
|
+
throw new Error('Injected acknowledged projection failure before publication');
|
|
9546
|
+
}
|
|
9547
|
+
}
|
|
9548
|
+
catch (error) {
|
|
9549
|
+
this._syncListboxAccessibility();
|
|
9550
|
+
this._recordAcknowledgedProjectionFailure(snapshot, request, error);
|
|
9551
|
+
return Promise.resolve();
|
|
9552
|
+
}
|
|
9553
|
+
this._acknowledgedProjectionRunning = true;
|
|
9554
|
+
const task = this._applyAcknowledgedSnapshot(snapshot, request, commitPosition, items, stagedRegistry, groupedItems);
|
|
9555
|
+
const trackedTask = task.finally(() => {
|
|
9556
|
+
if (this._acknowledgedProjectionTask === trackedTask) {
|
|
9557
|
+
this._acknowledgedProjectionRunning = false;
|
|
9558
|
+
this._acknowledgedProjectionTask = null;
|
|
9559
|
+
}
|
|
9560
|
+
});
|
|
9561
|
+
this._acknowledgedProjectionTask = trackedTask;
|
|
9562
|
+
return trackedTask;
|
|
9563
|
+
}
|
|
9564
|
+
async _applyAcknowledgedSnapshot(snapshot, request, commitPosition, items, stagedRegistry, groupedItems) {
|
|
9565
|
+
let published = false;
|
|
9566
|
+
try {
|
|
9567
|
+
this._rebuildItemRegistry(items, stagedRegistry);
|
|
9568
|
+
this._state.groupedItems = groupedItems;
|
|
9569
|
+
if (commitPosition && request) {
|
|
9570
|
+
this._state.currentPage = snapshot.lastCommittedPage
|
|
9571
|
+
?? (request.position.mode === 'page' ? request.position.page : request.position.ordinal);
|
|
9572
|
+
}
|
|
9573
|
+
this._state.isSearching = false;
|
|
9574
|
+
this._state.isBusy = true;
|
|
9575
|
+
this._state.lastScrollPosition = this._acknowledgedProjectionScrollTop;
|
|
9576
|
+
this._state.preserveScrollPosition = request?.kind === 'loadMore';
|
|
9577
|
+
published = true;
|
|
9578
|
+
if (this._acknowledgedProjectionFailureStageForTest === 'after-publish') {
|
|
9579
|
+
this._acknowledgedProjectionFailureStageForTest = null;
|
|
9580
|
+
throw new Error('Injected acknowledged projection failure after publication');
|
|
9581
|
+
}
|
|
9582
|
+
if (!this._state.searchQuery && this._acknowledgedPendingSearchQuery === null) {
|
|
9583
|
+
this._updateInputDisplay();
|
|
9584
|
+
}
|
|
9585
|
+
this._syncListboxAccessibility();
|
|
9586
|
+
this._renderOptions();
|
|
9587
|
+
const renderCycleId = this._renderCycleId;
|
|
9588
|
+
const completed = await this._waitForRenderCycle(renderCycleId);
|
|
9589
|
+
if (!completed)
|
|
9590
|
+
throw new Error('Acknowledged snapshot render was superseded before completion');
|
|
9591
|
+
this._state.isBusy = snapshot.busy;
|
|
9592
|
+
if (!snapshot.busy) {
|
|
9593
|
+
this._optionsContainer.querySelector('.busy-bucket')?.remove();
|
|
9594
|
+
if (this._shouldRenderLoadMoreTrigger())
|
|
9595
|
+
this._addLoadMoreTrigger();
|
|
9596
|
+
}
|
|
9597
|
+
this._optionsContainer.scrollTop = this._acknowledgedProjectionScrollTop;
|
|
9598
|
+
this._syncListboxAccessibility();
|
|
9599
|
+
this._syncRenderedOptionAccessibility();
|
|
9600
|
+
this._syncLegacyActiveAria();
|
|
9601
|
+
this._state.preserveScrollPosition = false;
|
|
9602
|
+
this._acknowledgedProjectionPending = false;
|
|
9603
|
+
this._acknowledgedProjectionDiagnostic = null;
|
|
9604
|
+
this._acknowledgedProjectionSettling = true;
|
|
9605
|
+
try {
|
|
9606
|
+
this._dispatchDataProjectionNotification({
|
|
9607
|
+
requestId: this._acknowledgedProjectionRequest?.requestId ?? request?.requestId ?? 'unknown',
|
|
9608
|
+
queryGeneration: this._acknowledgedProjectionRequest?.queryGeneration ?? snapshot.queryGeneration,
|
|
9609
|
+
attempt: this._acknowledgedProjectionAttempt,
|
|
9610
|
+
status: 'complete',
|
|
9611
|
+
});
|
|
9612
|
+
}
|
|
9613
|
+
finally {
|
|
9614
|
+
this._acknowledgedProjectionSettling = false;
|
|
9615
|
+
}
|
|
9616
|
+
if (this._clearAcknowledgedCoordinatorAfterProjection) {
|
|
9617
|
+
this._dataRequestCoordinator = null;
|
|
9618
|
+
this._acknowledgedSearchMode = null;
|
|
9619
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
9620
|
+
this._acknowledgedProjectionRequest = null;
|
|
9621
|
+
}
|
|
9622
|
+
else {
|
|
9623
|
+
this._acknowledgedProjectionRequest = null;
|
|
9624
|
+
}
|
|
9625
|
+
this._finishAcknowledgedProjectionSettlement();
|
|
9626
|
+
}
|
|
9627
|
+
catch (error) {
|
|
9628
|
+
if (published) {
|
|
9629
|
+
if (this.isConnected)
|
|
9630
|
+
this._state.isBusy = true;
|
|
9631
|
+
this._state.isSearching = false;
|
|
9632
|
+
this._syncListboxAccessibility();
|
|
9633
|
+
}
|
|
9634
|
+
this._acknowledgedProjectionPending = true;
|
|
9635
|
+
this._recordAcknowledgedProjectionFailure(snapshot, request, error);
|
|
9636
|
+
}
|
|
9637
|
+
}
|
|
9638
|
+
_recordAcknowledgedProjectionFailure(snapshot, request, error) {
|
|
9639
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9640
|
+
const diagnostic = {
|
|
9641
|
+
requestId: this._acknowledgedProjectionRequest?.requestId ?? request?.requestId ?? 'unknown',
|
|
9642
|
+
queryGeneration: this._acknowledgedProjectionRequest?.queryGeneration ?? snapshot.queryGeneration,
|
|
9643
|
+
message,
|
|
9644
|
+
};
|
|
9645
|
+
this._acknowledgedProjectionDiagnostic = diagnostic;
|
|
9646
|
+
this._emit('diagnostic', {
|
|
9647
|
+
timestamp: Date.now(),
|
|
9648
|
+
source: 'event',
|
|
9649
|
+
name: 'acknowledgedProjectionFailed',
|
|
9650
|
+
detail: diagnostic,
|
|
9651
|
+
});
|
|
9652
|
+
if (diagnostic.requestId !== 'unknown') {
|
|
9653
|
+
this._dispatchDataProjectionNotification({
|
|
9654
|
+
requestId: diagnostic.requestId,
|
|
9655
|
+
queryGeneration: diagnostic.queryGeneration,
|
|
9656
|
+
attempt: this._acknowledgedProjectionAttempt,
|
|
9657
|
+
status: 'failed',
|
|
9658
|
+
error: { message },
|
|
9659
|
+
});
|
|
9660
|
+
}
|
|
9661
|
+
}
|
|
9662
|
+
_dispatchDataProjectionNotification(detail) {
|
|
9663
|
+
this._dispatchAcknowledgedEvent('dataProjection', detail);
|
|
9664
|
+
try {
|
|
9665
|
+
this._dataProjectionCallback?.(detail);
|
|
9666
|
+
}
|
|
9667
|
+
catch (error) {
|
|
9668
|
+
this._handleError(error);
|
|
9669
|
+
}
|
|
9670
|
+
}
|
|
9671
|
+
_dispatchPendingAcknowledgedSearchIntent() {
|
|
9672
|
+
const query = this._acknowledgedPendingSearchQuery;
|
|
9673
|
+
if (query === null || !this._acknowledgedReady || !this.isConnected)
|
|
9674
|
+
return;
|
|
9675
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9676
|
+
this._handleSearch(query);
|
|
9677
|
+
}
|
|
9678
|
+
/** Apply config/query changes coalesced while an accepted snapshot projected. */
|
|
9679
|
+
_finishAcknowledgedProjectionSettlement() {
|
|
9680
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9681
|
+
const query = this._acknowledgedPendingSearchQuery;
|
|
9682
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged' || !coordinator) {
|
|
9683
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9684
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9685
|
+
if (this._dataLoadingConfig.protocol === 'legacy' && query !== null && this.isConnected) {
|
|
9686
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9687
|
+
this._handleSearch(query);
|
|
9688
|
+
}
|
|
9689
|
+
else {
|
|
9690
|
+
this._dispatchPendingAcknowledgedSearchIntent();
|
|
9691
|
+
}
|
|
9692
|
+
return;
|
|
9693
|
+
}
|
|
9694
|
+
if (!this.isConnected || !this._acknowledgedReady)
|
|
9695
|
+
return;
|
|
9696
|
+
if (this._acknowledgedConfigUpdatePending) {
|
|
9697
|
+
const requiresSingleLatestQueryRequest = this._acknowledgedDeferredModeChange && query !== null;
|
|
9698
|
+
if (requiresSingleLatestQueryRequest) {
|
|
9699
|
+
// Apply the mode transition while disconnected, set the latest query,
|
|
9700
|
+
// then reconnect once. This prevents an intermediate request for the
|
|
9701
|
+
// pre-projection query from escaping before the coalesced latest one.
|
|
9702
|
+
this._dispatchAcknowledgedActions(coordinator.disconnect());
|
|
9703
|
+
}
|
|
9704
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
9705
|
+
if (update.status !== 'accepted') {
|
|
9706
|
+
this._acknowledgedReady = false;
|
|
9707
|
+
return;
|
|
9708
|
+
}
|
|
9709
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9710
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9711
|
+
if (requiresSingleLatestQueryRequest && query !== null) {
|
|
9712
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9713
|
+
this._state.searchQuery = query;
|
|
9714
|
+
this._input.value = query;
|
|
9715
|
+
this._dispatchAcknowledgedActions(coordinator.setQuery(query));
|
|
9716
|
+
this._dispatchAcknowledgedActions(coordinator.connect(query));
|
|
9717
|
+
this._syncListboxAccessibility();
|
|
9718
|
+
this._handleSearch(query);
|
|
9719
|
+
return;
|
|
9720
|
+
}
|
|
9721
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
9722
|
+
const state = coordinator.getSnapshot();
|
|
9723
|
+
this._state.isBusy = state.busy;
|
|
9724
|
+
this._state.isSearching = state.activeRequest?.kind === 'search';
|
|
9725
|
+
this._syncListboxAccessibility();
|
|
9726
|
+
}
|
|
9727
|
+
this._dispatchPendingAcknowledgedSearchIntent();
|
|
9728
|
+
}
|
|
7937
9729
|
_updateGuardedVirtualWindow(scrollTop, viewportHeight) {
|
|
7938
9730
|
this._guardedVirtualizationRequested = true;
|
|
7939
9731
|
const virtualizer = this._ensureGuardedVirtualizer(this._renderPlan.filteredKeys);
|
|
@@ -8121,6 +9913,7 @@
|
|
|
8121
9913
|
const scrollTopBeforeRender = this._optionsContainer.scrollTop;
|
|
8122
9914
|
this._renderCycleId += 1;
|
|
8123
9915
|
const renderCycleId = this._renderCycleId;
|
|
9916
|
+
this._resolvePendingRenderCycles(false, renderCycleId);
|
|
8124
9917
|
if (this._guardedVirtualizer) {
|
|
8125
9918
|
this._guardedVirtualScrollTop = this._optionsContainer.scrollTop;
|
|
8126
9919
|
}
|
|
@@ -8128,6 +9921,8 @@
|
|
|
8128
9921
|
if (this._loadMoreTrigger && this._intersectionObserver) {
|
|
8129
9922
|
this._intersectionObserver.unobserve(this._loadMoreTrigger);
|
|
8130
9923
|
}
|
|
9924
|
+
if (this._dataRequestCoordinator)
|
|
9925
|
+
this._loadMoreTrigger = undefined;
|
|
8131
9926
|
this._unobserveGuardedOptionResizeTargets();
|
|
8132
9927
|
// Clear options container
|
|
8133
9928
|
this._optionsContainer.innerHTML = '';
|
|
@@ -8156,12 +9951,15 @@
|
|
|
8156
9951
|
searching.setAttribute('part', 'loading');
|
|
8157
9952
|
searching.textContent = 'Searching...';
|
|
8158
9953
|
this._optionsContainer.appendChild(searching);
|
|
9954
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
8159
9955
|
return;
|
|
8160
9956
|
}
|
|
8161
9957
|
const getValue = this._config.serverSide.getValueFromItem || ((item) => item?.value ?? item);
|
|
8162
9958
|
const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
|
|
8163
9959
|
// Filter items by search query
|
|
8164
|
-
const query = this.
|
|
9960
|
+
const query = this._acknowledgedSearchMode === 'remote'
|
|
9961
|
+
? ''
|
|
9962
|
+
: this._state.searchQuery.toLowerCase();
|
|
8165
9963
|
if (this._guardedMeasurementQuery !== null && this._guardedMeasurementQuery !== query) {
|
|
8166
9964
|
this._invalidateGuardedMeasurements();
|
|
8167
9965
|
}
|
|
@@ -8286,8 +10084,10 @@
|
|
|
8286
10084
|
}
|
|
8287
10085
|
}
|
|
8288
10086
|
const renderChunk = () => {
|
|
8289
|
-
if (renderCycleId !== this._renderCycleId)
|
|
10087
|
+
if (renderCycleId !== this._renderCycleId) {
|
|
10088
|
+
this._resolveRenderCycle(renderCycleId, false);
|
|
8290
10089
|
return;
|
|
10090
|
+
}
|
|
8291
10091
|
const fragment = document.createDocumentFragment();
|
|
8292
10092
|
const chunkEnd = Math.min(Math.max(cursor + chunkSize, maxRenderTarget), filteredIndices.length);
|
|
8293
10093
|
maxRenderTarget = 0; // Reset after fast-forwarding
|
|
@@ -8305,12 +10105,15 @@
|
|
|
8305
10105
|
this._requestLifecycleFrame(renderChunk);
|
|
8306
10106
|
}
|
|
8307
10107
|
else {
|
|
8308
|
-
if (renderCycleId !== this._renderCycleId)
|
|
10108
|
+
if (renderCycleId !== this._renderCycleId) {
|
|
10109
|
+
this._resolveRenderCycle(renderCycleId, false);
|
|
8309
10110
|
return;
|
|
8310
|
-
|
|
10111
|
+
}
|
|
10112
|
+
if (!this._state.isBusy && this._shouldRenderLoadMoreTrigger()) {
|
|
8311
10113
|
this._addLoadMoreTrigger();
|
|
8312
10114
|
}
|
|
8313
10115
|
this._finalizePerfMarks();
|
|
10116
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
8314
10117
|
}
|
|
8315
10118
|
};
|
|
8316
10119
|
renderChunk();
|
|
@@ -8342,7 +10145,7 @@
|
|
|
8342
10145
|
this._optionsContainer.appendChild(busyBucket);
|
|
8343
10146
|
}
|
|
8344
10147
|
// Append Load More Trigger (Button or Sentinel) if enabled and not busy
|
|
8345
|
-
else if ((this.
|
|
10148
|
+
else if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
|
|
8346
10149
|
this._addLoadMoreTrigger();
|
|
8347
10150
|
}
|
|
8348
10151
|
// Rebuilding the list temporarily removes its spacer geometry. Browsers
|
|
@@ -8355,6 +10158,43 @@
|
|
|
8355
10158
|
this._syncLegacyActiveAria();
|
|
8356
10159
|
this._syncGuardedOptionResizeTargets();
|
|
8357
10160
|
this._finalizePerfMarks();
|
|
10161
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
10162
|
+
}
|
|
10163
|
+
_waitForRenderCycle(renderCycleId) {
|
|
10164
|
+
if (renderCycleId < this._renderCycleId)
|
|
10165
|
+
return Promise.resolve(false);
|
|
10166
|
+
if (renderCycleId <= this._completedRenderCycleId)
|
|
10167
|
+
return Promise.resolve(true);
|
|
10168
|
+
return new Promise((resolve) => {
|
|
10169
|
+
this._renderCycleWaiters.set(renderCycleId, resolve);
|
|
10170
|
+
const timeout = window.setTimeout(() => this._resolveRenderCycle(renderCycleId, false), 120000);
|
|
10171
|
+
this._renderCycleWaiterTimeouts.set(renderCycleId, timeout);
|
|
10172
|
+
});
|
|
10173
|
+
}
|
|
10174
|
+
_resolveRenderCycle(renderCycleId, completed) {
|
|
10175
|
+
if (completed)
|
|
10176
|
+
this._completedRenderCycleId = Math.max(this._completedRenderCycleId, renderCycleId);
|
|
10177
|
+
const resolve = this._renderCycleWaiters.get(renderCycleId);
|
|
10178
|
+
const timeout = this._renderCycleWaiterTimeouts.get(renderCycleId);
|
|
10179
|
+
if (timeout !== undefined)
|
|
10180
|
+
window.clearTimeout(timeout);
|
|
10181
|
+
this._renderCycleWaiterTimeouts.delete(renderCycleId);
|
|
10182
|
+
if (!resolve)
|
|
10183
|
+
return;
|
|
10184
|
+
this._renderCycleWaiters.delete(renderCycleId);
|
|
10185
|
+
resolve(completed);
|
|
10186
|
+
}
|
|
10187
|
+
_resolvePendingRenderCycles(completed, beforeCycleId = Number.POSITIVE_INFINITY) {
|
|
10188
|
+
for (const [renderCycleId, resolve] of this._renderCycleWaiters) {
|
|
10189
|
+
if (renderCycleId >= beforeCycleId)
|
|
10190
|
+
continue;
|
|
10191
|
+
const timeout = this._renderCycleWaiterTimeouts.get(renderCycleId);
|
|
10192
|
+
if (timeout !== undefined)
|
|
10193
|
+
window.clearTimeout(timeout);
|
|
10194
|
+
this._renderCycleWaiterTimeouts.delete(renderCycleId);
|
|
10195
|
+
this._renderCycleWaiters.delete(renderCycleId);
|
|
10196
|
+
resolve(completed);
|
|
10197
|
+
}
|
|
8358
10198
|
}
|
|
8359
10199
|
_unobserveGuardedOptionResizeTargets() {
|
|
8360
10200
|
for (const option of this._guardedObservedOptions) {
|
|
@@ -8567,6 +10407,46 @@
|
|
|
8567
10407
|
_addLoadMoreTrigger() {
|
|
8568
10408
|
const container = document.createElement('div');
|
|
8569
10409
|
container.className = 'load-more-container';
|
|
10410
|
+
if (this._dataRequestCoordinator) {
|
|
10411
|
+
const shouldObserve = this._config.infiniteScroll.enabled
|
|
10412
|
+
&& Boolean(this._intersectionObserver)
|
|
10413
|
+
&& this._acknowledgedReady;
|
|
10414
|
+
let sentinel;
|
|
10415
|
+
if (shouldObserve) {
|
|
10416
|
+
sentinel = this._acknowledgedSentinel ?? document.createElement('div');
|
|
10417
|
+
sentinel.className = 'infinite-scroll-sentinel';
|
|
10418
|
+
sentinel.style.height = '10px';
|
|
10419
|
+
sentinel.style.width = '100%';
|
|
10420
|
+
sentinel.style.opacity = '0';
|
|
10421
|
+
this._acknowledgedSentinel = sentinel;
|
|
10422
|
+
this._loadMoreTrigger = sentinel;
|
|
10423
|
+
container.appendChild(sentinel);
|
|
10424
|
+
}
|
|
10425
|
+
// Keep an explicit keyboard-accessible path even when automatic
|
|
10426
|
+
// observation is enabled, and use it as the fallback if IO is absent.
|
|
10427
|
+
if (this._config.loadMore.enabled || this._config.infiniteScroll.enabled) {
|
|
10428
|
+
const button = document.createElement('button');
|
|
10429
|
+
button.className = 'load-more-button';
|
|
10430
|
+
button.textContent = `Load ${this._config.loadMore.itemsPerLoad} more`;
|
|
10431
|
+
button.addEventListener('click', () => this._loadMoreItems('manual'));
|
|
10432
|
+
container.appendChild(button);
|
|
10433
|
+
if (!sentinel)
|
|
10434
|
+
this._loadMoreTrigger = button;
|
|
10435
|
+
}
|
|
10436
|
+
this._optionsContainer.appendChild(container);
|
|
10437
|
+
if (sentinel && this._intersectionObserver) {
|
|
10438
|
+
try {
|
|
10439
|
+
this._intersectionObserver.observe(sentinel);
|
|
10440
|
+
}
|
|
10441
|
+
catch (_error) {
|
|
10442
|
+
this._intersectionObserver.disconnect();
|
|
10443
|
+
this._intersectionObserver = undefined;
|
|
10444
|
+
sentinel.remove();
|
|
10445
|
+
this._loadMoreTrigger = container.querySelector('.load-more-button') ?? undefined;
|
|
10446
|
+
}
|
|
10447
|
+
}
|
|
10448
|
+
return;
|
|
10449
|
+
}
|
|
8570
10450
|
if (this._config.infiniteScroll.enabled) {
|
|
8571
10451
|
// Infinite Scroll: Render an invisible sentinel
|
|
8572
10452
|
// It must have some height to be intersected
|
|
@@ -8593,6 +10473,23 @@
|
|
|
8593
10473
|
this._intersectionObserver.observe(this._loadMoreTrigger);
|
|
8594
10474
|
}
|
|
8595
10475
|
}
|
|
10476
|
+
_shouldRenderLoadMoreTrigger() {
|
|
10477
|
+
if (!this._config.loadMore.enabled && !this._config.infiniteScroll.enabled)
|
|
10478
|
+
return false;
|
|
10479
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged'
|
|
10480
|
+
&& (!this._dataRequestCoordinator || !this._acknowledgedReady))
|
|
10481
|
+
return false;
|
|
10482
|
+
if (!this._dataRequestCoordinator)
|
|
10483
|
+
return this._state.loadedItems.length > 0;
|
|
10484
|
+
const snapshot = this._dataRequestCoordinator.getSnapshot();
|
|
10485
|
+
if (snapshot.status === 'resource-limited')
|
|
10486
|
+
return false;
|
|
10487
|
+
return snapshot.hasMore
|
|
10488
|
+
|| snapshot.error !== null
|
|
10489
|
+
|| snapshot.status === 'empty'
|
|
10490
|
+
|| snapshot.status === 'failed'
|
|
10491
|
+
|| snapshot.status === 'cancelled';
|
|
10492
|
+
}
|
|
8596
10493
|
}
|
|
8597
10494
|
/** live set of all connected instances; used to auto-close siblings */
|
|
8598
10495
|
EnhancedSelect._instances = new Set();
|
|
@@ -9689,6 +11586,7 @@
|
|
|
9689
11586
|
exports.shadowDOMStyles = shadowDOMStyles;
|
|
9690
11587
|
exports.toggleClass = toggleClass;
|
|
9691
11588
|
exports.transition = transition;
|
|
11589
|
+
exports.validateDataLoadingConfig = validateDataLoadingConfig;
|
|
9692
11590
|
exports.validateTemplate = validateTemplate;
|
|
9693
11591
|
exports.valuesEqual = valuesEqual;
|
|
9694
11592
|
exports.warnCSPViolation = warnCSPViolation;
|