@smilodon/core 1.10.0 → 1.10.2
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 +1931 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1931 -25
- 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 +1931 -24
- 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 +71 -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,8 +8145,19 @@
|
|
|
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
|
}
|
|
8156
|
+
_isActivelyEditingSearchInput() {
|
|
8157
|
+
return this._config.searchable === true
|
|
8158
|
+
&& this._state.isOpen
|
|
8159
|
+
&& this._shadow.activeElement === this._input;
|
|
8160
|
+
}
|
|
7083
8161
|
_renderOptionsWithAnimation() {
|
|
7084
8162
|
// Add fade-out animation
|
|
7085
8163
|
this._optionsContainer.style.opacity = '0';
|
|
@@ -7145,7 +8223,24 @@
|
|
|
7145
8223
|
this._setActive(targetIndex, 'programmatic');
|
|
7146
8224
|
}
|
|
7147
8225
|
}
|
|
7148
|
-
async _loadMoreItems() {
|
|
8226
|
+
async _loadMoreItems(trigger = 'manual') {
|
|
8227
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged') {
|
|
8228
|
+
if (!this._dataRequestCoordinator
|
|
8229
|
+
|| !this._acknowledgedReady
|
|
8230
|
+
|| this._acknowledgedProjectionPending
|
|
8231
|
+
|| this._acknowledgedProjectionSettling)
|
|
8232
|
+
return;
|
|
8233
|
+
const actions = this._dataRequestCoordinator.requestLoadMore(trigger);
|
|
8234
|
+
this._dispatchAcknowledgedActions(actions);
|
|
8235
|
+
return;
|
|
8236
|
+
}
|
|
8237
|
+
if (this._dataRequestCoordinator) {
|
|
8238
|
+
if (!this._acknowledgedReady || this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)
|
|
8239
|
+
return;
|
|
8240
|
+
const actions = this._dataRequestCoordinator.requestLoadMore(trigger);
|
|
8241
|
+
this._dispatchAcknowledgedActions(actions);
|
|
8242
|
+
return;
|
|
8243
|
+
}
|
|
7149
8244
|
if (this._state.isBusy)
|
|
7150
8245
|
return;
|
|
7151
8246
|
this._setBusy(true);
|
|
@@ -7372,9 +8467,30 @@
|
|
|
7372
8467
|
const previousLength = this._state.loadedItems.length;
|
|
7373
8468
|
this._rebuildItemRegistry(items);
|
|
7374
8469
|
this._state.groupedItems = this._groupItemsByProperty(items);
|
|
7375
|
-
if (!this._state.searchQuery)
|
|
8470
|
+
if (!this._state.searchQuery && !this._isActivelyEditingSearchInput())
|
|
7376
8471
|
this._updateInputDisplay();
|
|
7377
8472
|
const newLength = this._state.loadedItems.length;
|
|
8473
|
+
if (this._dataRequestCoordinator) {
|
|
8474
|
+
const acknowledgedBusy = this._dataRequestCoordinator.getSnapshot().busy
|
|
8475
|
+
|| this._acknowledgedProjectionPending;
|
|
8476
|
+
this._state.isSearching = false;
|
|
8477
|
+
this._state.isBusy = acknowledgedBusy;
|
|
8478
|
+
if (this._state.preserveScrollPosition && this._dropdown) {
|
|
8479
|
+
const targetScrollTop = this._state.lastScrollPosition;
|
|
8480
|
+
this._renderOptions();
|
|
8481
|
+
this._optionsContainer.scrollTop = targetScrollTop;
|
|
8482
|
+
this._requestLifecycleFrame(() => {
|
|
8483
|
+
if (this._optionsContainer)
|
|
8484
|
+
this._optionsContainer.scrollTop = targetScrollTop;
|
|
8485
|
+
});
|
|
8486
|
+
if (!acknowledgedBusy)
|
|
8487
|
+
this._state.preserveScrollPosition = false;
|
|
8488
|
+
}
|
|
8489
|
+
else {
|
|
8490
|
+
this._renderOptions();
|
|
8491
|
+
}
|
|
8492
|
+
return;
|
|
8493
|
+
}
|
|
7378
8494
|
// When infinite scroll is active (preserveScrollPosition = true),
|
|
7379
8495
|
// we need to maintain scroll position during the update
|
|
7380
8496
|
if (this._state.preserveScrollPosition && this._dropdown) {
|
|
@@ -7432,7 +8548,7 @@
|
|
|
7432
8548
|
this._rebuildItemRegistry(groupedItems.flatMap(group => group.options));
|
|
7433
8549
|
this._state.groupedItems = groupedItems;
|
|
7434
8550
|
this._renderOptions();
|
|
7435
|
-
if (!this._state.searchQuery)
|
|
8551
|
+
if (!this._state.searchQuery && !this._isActivelyEditingSearchInput())
|
|
7436
8552
|
this._updateInputDisplay();
|
|
7437
8553
|
}
|
|
7438
8554
|
/**
|
|
@@ -7550,9 +8666,55 @@
|
|
|
7550
8666
|
this._invalidateGuardedMeasurements();
|
|
7551
8667
|
const previousMode = this._config.selection.mode;
|
|
7552
8668
|
const previousEnabled = this._config.enabled;
|
|
7553
|
-
|
|
8669
|
+
const previousDataLoadingConfig = this._dataLoadingConfig;
|
|
8670
|
+
const { dataLoading, callbacks, ...legacyConfig } = config;
|
|
8671
|
+
const legacyUpdate = { ...legacyConfig };
|
|
8672
|
+
let configErrorDetail;
|
|
8673
|
+
if (callbacks !== undefined && callbacks !== null) {
|
|
8674
|
+
const callbackInput = callbacks;
|
|
8675
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataLoadingConfigError')) {
|
|
8676
|
+
this._dataLoadingConfigErrorCallback = callbackInput.onDataLoadingConfigError;
|
|
8677
|
+
}
|
|
8678
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataRequestCancel')) {
|
|
8679
|
+
this._dataRequestCancelCallback = callbackInput.onDataRequestCancel;
|
|
8680
|
+
}
|
|
8681
|
+
if (Object.prototype.hasOwnProperty.call(callbackInput, 'onDataProjection')) {
|
|
8682
|
+
this._dataProjectionCallback = callbackInput.onDataProjection;
|
|
8683
|
+
}
|
|
8684
|
+
const legacyCallbacks = { ...callbackInput };
|
|
8685
|
+
delete legacyCallbacks.onDataLoadingConfigError;
|
|
8686
|
+
delete legacyCallbacks.onDataRequestCancel;
|
|
8687
|
+
delete legacyCallbacks.onDataProjection;
|
|
8688
|
+
legacyUpdate.callbacks = legacyCallbacks;
|
|
8689
|
+
}
|
|
8690
|
+
this._config = this._mergeConfig(this._config, legacyUpdate);
|
|
8691
|
+
if (dataLoading !== undefined) {
|
|
8692
|
+
const dataLoadingPrototype = dataLoading !== null && typeof dataLoading === 'object'
|
|
8693
|
+
? Object.getPrototypeOf(dataLoading)
|
|
8694
|
+
: undefined;
|
|
8695
|
+
const candidate = dataLoadingPrototype === Object.prototype || dataLoadingPrototype === null
|
|
8696
|
+
? { ...this._dataLoadingConfig, ...dataLoading }
|
|
8697
|
+
: dataLoading;
|
|
8698
|
+
const validation = validateDataLoadingConfig(candidate);
|
|
8699
|
+
if (validation.valid) {
|
|
8700
|
+
this._dataLoadingConfig = validation.value;
|
|
8701
|
+
this._hasLastInvalidDataLoadingCandidate = false;
|
|
8702
|
+
this._lastInvalidDataLoadingCandidate = undefined;
|
|
8703
|
+
}
|
|
8704
|
+
else {
|
|
8705
|
+
const candidateSignature = createInvalidDataLoadingCandidateSignature(candidate, validation.issues);
|
|
8706
|
+
if (!this._hasLastInvalidDataLoadingCandidate ||
|
|
8707
|
+
!this._lastInvalidDataLoadingCandidate ||
|
|
8708
|
+
!invalidDataLoadingSignaturesEqual(this._lastInvalidDataLoadingCandidate, candidateSignature)) {
|
|
8709
|
+
this._hasLastInvalidDataLoadingCandidate = true;
|
|
8710
|
+
this._lastInvalidDataLoadingCandidate = candidateSignature;
|
|
8711
|
+
configErrorDetail = { issues: validation.issues };
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8714
|
+
}
|
|
7554
8715
|
this._rebuildItemRegistry();
|
|
7555
8716
|
if (previousEnabled !== this._config.enabled) {
|
|
8717
|
+
this._input.disabled = !this._config.enabled;
|
|
7556
8718
|
if (!this._config.enabled && this._state.isOpen) {
|
|
7557
8719
|
this._handleClose('disabled');
|
|
7558
8720
|
}
|
|
@@ -7602,14 +8764,301 @@
|
|
|
7602
8764
|
// Re-initialize observers in case infinite scroll was enabled/disabled
|
|
7603
8765
|
this._initializeObservers();
|
|
7604
8766
|
this._syncClearControlState();
|
|
7605
|
-
this.
|
|
8767
|
+
if (!this._isActivelyEditingSearchInput())
|
|
8768
|
+
this._updateInputDisplay();
|
|
7606
8769
|
this._renderOptions();
|
|
7607
8770
|
}
|
|
7608
8771
|
else {
|
|
7609
8772
|
this._syncInputContainerMode();
|
|
7610
8773
|
this._syncMultiSelectDisplayConfig();
|
|
7611
8774
|
this._syncClearControlState();
|
|
7612
|
-
this.
|
|
8775
|
+
if (!this._isActivelyEditingSearchInput())
|
|
8776
|
+
this._updateInputDisplay();
|
|
8777
|
+
}
|
|
8778
|
+
this._acknowledgedSearchMode = this._dataLoadingConfig.searchMode;
|
|
8779
|
+
if (this._dataLoadingConfig.protocol === 'legacy')
|
|
8780
|
+
this._acknowledgedDeferredStart = false;
|
|
8781
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8782
|
+
const switchesToLegacy = previousDataLoadingConfig.protocol === 'acknowledged'
|
|
8783
|
+
&& this._dataLoadingConfig.protocol === 'legacy';
|
|
8784
|
+
const acknowledgedModeChanged = previousDataLoadingConfig.protocol !== this._dataLoadingConfig.protocol
|
|
8785
|
+
|| previousDataLoadingConfig.searchMode !== this._dataLoadingConfig.searchMode
|
|
8786
|
+
|| previousDataLoadingConfig.paginationMode !== this._dataLoadingConfig.paginationMode;
|
|
8787
|
+
if (coordinator && switchesToLegacy) {
|
|
8788
|
+
if (this._acknowledgedReady && !this._acknowledgedProjectionPending && !this._acknowledgedProjectionSettling) {
|
|
8789
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
8790
|
+
if (update.status === 'accepted')
|
|
8791
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
8792
|
+
}
|
|
8793
|
+
this._acknowledgedReady = false;
|
|
8794
|
+
this._dispatchAcknowledgedActions(coordinator.disconnect());
|
|
8795
|
+
if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling) {
|
|
8796
|
+
this._clearAcknowledgedCoordinatorAfterProjection = true;
|
|
8797
|
+
}
|
|
8798
|
+
else {
|
|
8799
|
+
this._dataRequestCoordinator = null;
|
|
8800
|
+
this._acknowledgedSearchMode = null;
|
|
8801
|
+
this._state.isBusy = false;
|
|
8802
|
+
this._state.isSearching = false;
|
|
8803
|
+
this._syncListboxAccessibility();
|
|
8804
|
+
this._renderOptions();
|
|
8805
|
+
}
|
|
8806
|
+
}
|
|
8807
|
+
else if (coordinator && this._dataLoadingConfig.protocol === 'acknowledged') {
|
|
8808
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
8809
|
+
if (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling) {
|
|
8810
|
+
this._acknowledgedConfigUpdatePending = true;
|
|
8811
|
+
this._acknowledgedDeferredModeChange || (this._acknowledgedDeferredModeChange = acknowledgedModeChanged);
|
|
8812
|
+
}
|
|
8813
|
+
else if (this._acknowledgedReady) {
|
|
8814
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
8815
|
+
if (update.status === 'accepted') {
|
|
8816
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
8817
|
+
const snapshot = coordinator.getSnapshot();
|
|
8818
|
+
this._state.isBusy = snapshot.busy;
|
|
8819
|
+
this._state.isSearching = snapshot.activeRequest?.kind === 'search';
|
|
8820
|
+
this._syncListboxAccessibility();
|
|
8821
|
+
if (update.actions.every((action) => action.type !== 'request'))
|
|
8822
|
+
this._renderOptions();
|
|
8823
|
+
}
|
|
8824
|
+
}
|
|
8825
|
+
}
|
|
8826
|
+
if (configErrorDetail) {
|
|
8827
|
+
this._emit('dataLoadingConfigError', configErrorDetail);
|
|
8828
|
+
try {
|
|
8829
|
+
this._dataLoadingConfigErrorCallback?.(configErrorDetail);
|
|
8830
|
+
}
|
|
8831
|
+
catch (error) {
|
|
8832
|
+
this._handleError(error);
|
|
8833
|
+
}
|
|
8834
|
+
}
|
|
8835
|
+
}
|
|
8836
|
+
/** Open the acknowledged request lifecycle after the host has installed listeners. */
|
|
8837
|
+
startDataLoading() {
|
|
8838
|
+
const projectionRecoveryOnly = Boolean(this._dataRequestCoordinator && this._acknowledgedProjectionPending);
|
|
8839
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged' && !projectionRecoveryOnly)
|
|
8840
|
+
return;
|
|
8841
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged' && !this._ensureDataRequestCoordinator())
|
|
8842
|
+
return;
|
|
8843
|
+
if (!this.isConnected) {
|
|
8844
|
+
if (!this._hasEverConnected)
|
|
8845
|
+
this._acknowledgedDeferredStart = true;
|
|
8846
|
+
return;
|
|
8847
|
+
}
|
|
8848
|
+
if (this._acknowledgedReady)
|
|
8849
|
+
return;
|
|
8850
|
+
if (this._acknowledgedStartTask) {
|
|
8851
|
+
// A reconnect can arrive while the previous readiness task is still
|
|
8852
|
+
// unwinding an interrupted render. Preserve the restart request so the
|
|
8853
|
+
// accepted projection is recovered as soon as that task settles.
|
|
8854
|
+
this._acknowledgedDeferredStart = true;
|
|
8855
|
+
return;
|
|
8856
|
+
}
|
|
8857
|
+
const task = this._startAcknowledgedDataLoading();
|
|
8858
|
+
this._acknowledgedStartTask = task;
|
|
8859
|
+
void task.finally(() => {
|
|
8860
|
+
if (this._acknowledgedStartTask !== task)
|
|
8861
|
+
return;
|
|
8862
|
+
this._acknowledgedStartTask = null;
|
|
8863
|
+
if (this._acknowledgedDeferredStart && this.isConnected) {
|
|
8864
|
+
this._acknowledgedDeferredStart = false;
|
|
8865
|
+
this.startDataLoading();
|
|
8866
|
+
}
|
|
8867
|
+
}).catch((error) => this._handleError(error));
|
|
8868
|
+
}
|
|
8869
|
+
/** Return detached coordinator state without exposing its canonical item storage. */
|
|
8870
|
+
getDataLoadingState() {
|
|
8871
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8872
|
+
if (!coordinator) {
|
|
8873
|
+
const isRemote = this._dataLoadingConfig.searchMode === 'remote'
|
|
8874
|
+
|| this._dataLoadingConfig.searchMode === 'hybrid';
|
|
8875
|
+
const nextEligiblePosition = this._dataLoadingConfig.paginationMode === 'cursor'
|
|
8876
|
+
? { mode: 'cursor', ordinal: 1 }
|
|
8877
|
+
: {
|
|
8878
|
+
mode: 'page',
|
|
8879
|
+
page: isRemote
|
|
8880
|
+
? this._dataLoadingConfig.firstPage
|
|
8881
|
+
: (this._config.infiniteScroll.initialPage ?? 1) + 1,
|
|
8882
|
+
};
|
|
8883
|
+
return {
|
|
8884
|
+
status: 'idle',
|
|
8885
|
+
connected: this.isConnected,
|
|
8886
|
+
busy: false,
|
|
8887
|
+
projectionPending: false,
|
|
8888
|
+
queryGeneration: 0,
|
|
8889
|
+
activeRequest: null,
|
|
8890
|
+
hasMore: this._dataLoadingConfig.protocol === 'acknowledged'
|
|
8891
|
+
&& !isRemote
|
|
8892
|
+
&& (this._config.infiniteScroll.enabled || this._config.loadMore.enabled),
|
|
8893
|
+
nextEligiblePosition,
|
|
8894
|
+
error: null,
|
|
8895
|
+
resourceLimit: null,
|
|
8896
|
+
};
|
|
8897
|
+
}
|
|
8898
|
+
const snapshot = coordinator.getSnapshot();
|
|
8899
|
+
const activeRequest = snapshot.activeRequest
|
|
8900
|
+
? {
|
|
8901
|
+
...snapshot.activeRequest,
|
|
8902
|
+
position: { ...snapshot.activeRequest.position },
|
|
8903
|
+
}
|
|
8904
|
+
: null;
|
|
8905
|
+
return {
|
|
8906
|
+
status: snapshot.status,
|
|
8907
|
+
connected: snapshot.connected,
|
|
8908
|
+
busy: snapshot.busy || this._acknowledgedProjectionPending,
|
|
8909
|
+
projectionPending: this._acknowledgedProjectionPending,
|
|
8910
|
+
queryGeneration: snapshot.queryGeneration,
|
|
8911
|
+
activeRequest,
|
|
8912
|
+
hasMore: snapshot.hasMore,
|
|
8913
|
+
nextEligiblePosition: { ...snapshot.nextEligiblePosition },
|
|
8914
|
+
error: snapshot.error ? { ...snapshot.error } : null,
|
|
8915
|
+
resourceLimit: snapshot.resourceLimit ? { ...snapshot.resourceLimit } : null,
|
|
8916
|
+
};
|
|
8917
|
+
}
|
|
8918
|
+
/** Synchronously accept/classify a host completion; DOM projection proceeds asynchronously. */
|
|
8919
|
+
completeDataRequest(completion) {
|
|
8920
|
+
const coordinator = this._dataRequestCoordinator;
|
|
8921
|
+
if (!coordinator) {
|
|
8922
|
+
const candidate = completion;
|
|
8923
|
+
if (candidate === null
|
|
8924
|
+
|| typeof candidate !== 'object'
|
|
8925
|
+
|| !('requestId' in candidate)
|
|
8926
|
+
|| typeof candidate.requestId !== 'string'
|
|
8927
|
+
|| candidate.requestId.length === 0
|
|
8928
|
+
|| !('queryGeneration' in candidate)
|
|
8929
|
+
|| !Number.isSafeInteger(candidate.queryGeneration)
|
|
8930
|
+
|| candidate.queryGeneration < 0
|
|
8931
|
+
|| !('status' in candidate)
|
|
8932
|
+
|| typeof candidate.status !== 'string'
|
|
8933
|
+
|| !['succeeded', 'empty', 'exhausted', 'failed', 'cancelled'].includes(candidate.status))
|
|
8934
|
+
return 'invalid';
|
|
8935
|
+
return 'unknown-request';
|
|
8936
|
+
}
|
|
8937
|
+
const snapshotBefore = coordinator.getSnapshot();
|
|
8938
|
+
const completionRecord = completion && typeof completion === 'object'
|
|
8939
|
+
? completion
|
|
8940
|
+
: null;
|
|
8941
|
+
const activeRequest = snapshotBefore.activeRequest;
|
|
8942
|
+
const request = activeRequest
|
|
8943
|
+
&& completionRecord?.requestId === activeRequest.requestId
|
|
8944
|
+
&& completionRecord?.queryGeneration === activeRequest.queryGeneration
|
|
8945
|
+
? activeRequest
|
|
8946
|
+
: null;
|
|
8947
|
+
const status = completionRecord?.status;
|
|
8948
|
+
const advancesPosition = status === 'succeeded'
|
|
8949
|
+
|| status === 'exhausted'
|
|
8950
|
+
|| (status === 'empty' && completionRecord?.advance === 'next');
|
|
8951
|
+
const result = coordinator.completeDataRequest(completion);
|
|
8952
|
+
if (result === 'accepted' && request) {
|
|
8953
|
+
this._acknowledgedLastRequest = request;
|
|
8954
|
+
this._acknowledgedProjectionRequest = request;
|
|
8955
|
+
this._acknowledgedProjectionAttempt = 0;
|
|
8956
|
+
this._acknowledgedProjectionCommitsPosition = advancesPosition;
|
|
8957
|
+
void this._projectAcknowledgedSnapshot(coordinator.getSnapshot(), request, advancesPosition);
|
|
8958
|
+
}
|
|
8959
|
+
else if (result === 'resource-limit') {
|
|
8960
|
+
const resourceLimit = coordinator.getSnapshot().resourceLimit;
|
|
8961
|
+
this._emit('diagnostic', {
|
|
8962
|
+
timestamp: Date.now(),
|
|
8963
|
+
source: 'event',
|
|
8964
|
+
name: 'acknowledgedDataLoadingResourceLimit',
|
|
8965
|
+
detail: resourceLimit,
|
|
8966
|
+
});
|
|
8967
|
+
}
|
|
8968
|
+
return result;
|
|
8969
|
+
}
|
|
8970
|
+
_createCoordinatorConfig() {
|
|
8971
|
+
return {
|
|
8972
|
+
dataLoading: { ...this._dataLoadingConfig },
|
|
8973
|
+
infiniteScroll: {
|
|
8974
|
+
pageSize: this._config.infiniteScroll.pageSize,
|
|
8975
|
+
initialPage: this._config.infiniteScroll.initialPage,
|
|
8976
|
+
},
|
|
8977
|
+
};
|
|
8978
|
+
}
|
|
8979
|
+
_ensureDataRequestCoordinator() {
|
|
8980
|
+
if (!this._dataRequestCoordinator) {
|
|
8981
|
+
const isRemote = this._dataLoadingConfig.searchMode === 'remote'
|
|
8982
|
+
|| this._dataLoadingConfig.searchMode === 'hybrid';
|
|
8983
|
+
try {
|
|
8984
|
+
this._dataRequestCoordinator = new DataRequestCoordinator({
|
|
8985
|
+
config: this._createCoordinatorConfig(),
|
|
8986
|
+
initialQuery: this._state.searchQuery,
|
|
8987
|
+
initialItems: this._state.loadedItems,
|
|
8988
|
+
hasMore: !isRemote && (this._config.infiniteScroll.enabled || this._config.loadMore.enabled),
|
|
8989
|
+
});
|
|
8990
|
+
}
|
|
8991
|
+
catch (error) {
|
|
8992
|
+
const detail = {
|
|
8993
|
+
issues: [{
|
|
8994
|
+
path: 'dataLoading',
|
|
8995
|
+
code: 'invalid-value',
|
|
8996
|
+
message: `Acknowledged data loading could not start: ${error instanceof Error ? error.message : String(error)}`,
|
|
8997
|
+
}],
|
|
8998
|
+
};
|
|
8999
|
+
this._emit('dataLoadingConfigError', detail);
|
|
9000
|
+
try {
|
|
9001
|
+
this._dataLoadingConfigErrorCallback?.(detail);
|
|
9002
|
+
}
|
|
9003
|
+
catch (callbackError) {
|
|
9004
|
+
this._handleError(callbackError);
|
|
9005
|
+
}
|
|
9006
|
+
return null;
|
|
9007
|
+
}
|
|
9008
|
+
}
|
|
9009
|
+
this._acknowledgedSearchMode = this._dataLoadingConfig.searchMode;
|
|
9010
|
+
return this._dataRequestCoordinator;
|
|
9011
|
+
}
|
|
9012
|
+
async _startAcknowledgedDataLoading() {
|
|
9013
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9014
|
+
const projectionRecoveryOnly = Boolean(coordinator && this._acknowledgedProjectionPending);
|
|
9015
|
+
if (!coordinator
|
|
9016
|
+
|| (this._dataLoadingConfig.protocol !== 'acknowledged' && !projectionRecoveryOnly)
|
|
9017
|
+
|| !this.isConnected)
|
|
9018
|
+
return;
|
|
9019
|
+
if (this._acknowledgedReady)
|
|
9020
|
+
return;
|
|
9021
|
+
if (this._acknowledgedProjectionPending) {
|
|
9022
|
+
const interruptedProjection = this._acknowledgedProjectionTask;
|
|
9023
|
+
if (interruptedProjection)
|
|
9024
|
+
await interruptedProjection;
|
|
9025
|
+
if (!this.isConnected)
|
|
9026
|
+
return;
|
|
9027
|
+
if (this._acknowledgedProjectionPending) {
|
|
9028
|
+
await this._retryAcknowledgedProjection();
|
|
9029
|
+
}
|
|
9030
|
+
if (!this.isConnected || this._acknowledgedProjectionPending)
|
|
9031
|
+
return;
|
|
9032
|
+
}
|
|
9033
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged'
|
|
9034
|
+
|| !this._dataRequestCoordinator)
|
|
9035
|
+
return;
|
|
9036
|
+
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
9037
|
+
this._state.searchQuery = this._acknowledgedPendingSearchQuery;
|
|
9038
|
+
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
9039
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9040
|
+
}
|
|
9041
|
+
const configUpdate = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
9042
|
+
if (configUpdate.status !== 'accepted') {
|
|
9043
|
+
this._acknowledgedReady = false;
|
|
9044
|
+
return;
|
|
9045
|
+
}
|
|
9046
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9047
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9048
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
9049
|
+
this._acknowledgedReady = true;
|
|
9050
|
+
this._initializeObservers();
|
|
9051
|
+
const configActions = configUpdate.actions;
|
|
9052
|
+
this._dispatchAcknowledgedActions(configActions);
|
|
9053
|
+
const connectionActions = coordinator.connect(this._state.searchQuery);
|
|
9054
|
+
this._dispatchAcknowledgedActions(connectionActions);
|
|
9055
|
+
if (configActions.length === 0 && connectionActions.length === 0)
|
|
9056
|
+
this._renderOptions();
|
|
9057
|
+
const readyRenderCycleId = this._renderCycleId;
|
|
9058
|
+
const readyRenderCompleted = await this._waitForRenderCycle(readyRenderCycleId);
|
|
9059
|
+
if (!readyRenderCompleted) {
|
|
9060
|
+
this._acknowledgedReady = false;
|
|
9061
|
+
throw new Error('Acknowledged readiness render was superseded before completion');
|
|
7613
9062
|
}
|
|
7614
9063
|
}
|
|
7615
9064
|
_mergeConfig(target, source) {
|
|
@@ -7663,7 +9112,8 @@
|
|
|
7663
9112
|
return;
|
|
7664
9113
|
const enabled = this._config.clearControl.enabled === true;
|
|
7665
9114
|
const hasSelection = this._state.selectedIndices.size > 0;
|
|
7666
|
-
const
|
|
9115
|
+
const visibleSearchQuery = this._acknowledgedPendingSearchQuery ?? this._state.searchQuery;
|
|
9116
|
+
const hasSearch = visibleSearchQuery.length > 0;
|
|
7667
9117
|
const clearSelection = this._config.clearControl.clearSelection !== false;
|
|
7668
9118
|
const clearSearch = this._config.clearControl.clearSearch !== false;
|
|
7669
9119
|
const hasSomethingToClear = (clearSelection && hasSelection) || (clearSearch && hasSearch);
|
|
@@ -7934,6 +9384,357 @@
|
|
|
7934
9384
|
this._guardedVirtualOverscan = 0;
|
|
7935
9385
|
return true;
|
|
7936
9386
|
}
|
|
9387
|
+
/** Test-only activation seam; deliberately absent from public config/types. */
|
|
9388
|
+
_enableAcknowledgedDataLoadingForTest(config, options = {}) {
|
|
9389
|
+
if (this._dataRequestCoordinator) {
|
|
9390
|
+
throw new Error('Acknowledged data loading is already enabled for this test instance');
|
|
9391
|
+
}
|
|
9392
|
+
const dataLoading = config.dataLoading;
|
|
9393
|
+
this._dataLoadingConfig = {
|
|
9394
|
+
protocol: dataLoading?.protocol ?? 'acknowledged',
|
|
9395
|
+
searchMode: dataLoading?.searchMode ?? 'local',
|
|
9396
|
+
paginationMode: dataLoading?.paginationMode ?? 'page',
|
|
9397
|
+
firstPage: dataLoading?.firstPage ?? 1,
|
|
9398
|
+
...(dataLoading?.fetchLimit === undefined ? {} : { fetchLimit: dataLoading.fetchLimit }),
|
|
9399
|
+
};
|
|
9400
|
+
this._acknowledgedSearchMode = config.dataLoading?.searchMode ?? 'local';
|
|
9401
|
+
this._dataRequestCoordinator = new DataRequestCoordinator({
|
|
9402
|
+
config,
|
|
9403
|
+
initialQuery: this._state.searchQuery,
|
|
9404
|
+
initialItems: this._state.loadedItems,
|
|
9405
|
+
hasMore: options.hasMore,
|
|
9406
|
+
});
|
|
9407
|
+
this._acknowledgedReady = false;
|
|
9408
|
+
if (this.isConnected)
|
|
9409
|
+
this._initializeObservers();
|
|
9410
|
+
}
|
|
9411
|
+
/** Listener installation must precede this private test-only readiness gate. */
|
|
9412
|
+
async _setAcknowledgedDataLoadingReadyForTest() {
|
|
9413
|
+
if (!this._dataRequestCoordinator)
|
|
9414
|
+
throw new Error('Enable acknowledged data loading before readiness');
|
|
9415
|
+
if (!this.isConnected)
|
|
9416
|
+
throw new Error('Acknowledged readiness requires a connected test element');
|
|
9417
|
+
if (this._acknowledgedReady)
|
|
9418
|
+
return;
|
|
9419
|
+
if (this._acknowledgedProjectionPending) {
|
|
9420
|
+
const interruptedProjection = this._acknowledgedProjectionTask;
|
|
9421
|
+
if (interruptedProjection)
|
|
9422
|
+
await interruptedProjection;
|
|
9423
|
+
if (this._acknowledgedProjectionPending) {
|
|
9424
|
+
await this._retryAcknowledgedProjectionForTest();
|
|
9425
|
+
}
|
|
9426
|
+
if (this._acknowledgedProjectionPending) {
|
|
9427
|
+
throw new Error('Acknowledged readiness cannot open while snapshot projection is pending');
|
|
9428
|
+
}
|
|
9429
|
+
}
|
|
9430
|
+
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
9431
|
+
this._state.searchQuery = this._acknowledgedPendingSearchQuery;
|
|
9432
|
+
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
9433
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9434
|
+
}
|
|
9435
|
+
this._acknowledgedReady = true;
|
|
9436
|
+
this._initializeObservers();
|
|
9437
|
+
const actions = this._dataRequestCoordinator.connect(this._state.searchQuery);
|
|
9438
|
+
this._dispatchAcknowledgedActions(actions);
|
|
9439
|
+
if (actions.length === 0)
|
|
9440
|
+
this._renderOptions();
|
|
9441
|
+
const readyRenderCycleId = this._renderCycleId;
|
|
9442
|
+
const readyRenderCompleted = await this._waitForRenderCycle(readyRenderCycleId);
|
|
9443
|
+
if (!readyRenderCompleted) {
|
|
9444
|
+
this._acknowledgedReady = false;
|
|
9445
|
+
throw new Error('Acknowledged readiness render was superseded before completion');
|
|
9446
|
+
}
|
|
9447
|
+
}
|
|
9448
|
+
_dispatchAcknowledgedActions(actions) {
|
|
9449
|
+
for (const action of actions) {
|
|
9450
|
+
if (action.type === 'cancel') {
|
|
9451
|
+
this._dispatchAcknowledgedEvent('dataRequestCancel', action.notification);
|
|
9452
|
+
try {
|
|
9453
|
+
this._dataRequestCancelCallback?.(action.notification);
|
|
9454
|
+
}
|
|
9455
|
+
catch (error) {
|
|
9456
|
+
this._handleError(error);
|
|
9457
|
+
}
|
|
9458
|
+
continue;
|
|
9459
|
+
}
|
|
9460
|
+
const request = action.request;
|
|
9461
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9462
|
+
if (!coordinator || !this._acknowledgedReady)
|
|
9463
|
+
continue;
|
|
9464
|
+
if (request.kind === 'loadMore') {
|
|
9465
|
+
this._state.lastScrollPosition = this._optionsContainer.scrollTop;
|
|
9466
|
+
this._acknowledgedProjectionScrollTop = this._state.lastScrollPosition;
|
|
9467
|
+
this._state.preserveScrollPosition = true;
|
|
9468
|
+
this._state.isSearching = false;
|
|
9469
|
+
}
|
|
9470
|
+
else {
|
|
9471
|
+
this._acknowledgedProjectionScrollTop = 0;
|
|
9472
|
+
this._state.preserveScrollPosition = false;
|
|
9473
|
+
this._state.isSearching = true;
|
|
9474
|
+
}
|
|
9475
|
+
this._state.isBusy = true;
|
|
9476
|
+
this._acknowledgedLastRequest = request;
|
|
9477
|
+
this._syncListboxAccessibility();
|
|
9478
|
+
this._renderOptions();
|
|
9479
|
+
if (request.kind === 'loadMore') {
|
|
9480
|
+
this._optionsContainer.scrollTop = this._state.lastScrollPosition;
|
|
9481
|
+
}
|
|
9482
|
+
if (!coordinator.markNotificationsDispatched(request.requestId))
|
|
9483
|
+
continue;
|
|
9484
|
+
if (request.kind === 'search') {
|
|
9485
|
+
const detail = { query: request.query, results: [], count: 0, request };
|
|
9486
|
+
this._dispatchAcknowledgedEvent('search', detail);
|
|
9487
|
+
try {
|
|
9488
|
+
const callback = this._config.callbacks.onSearch;
|
|
9489
|
+
callback?.(request.query, request);
|
|
9490
|
+
}
|
|
9491
|
+
catch (error) {
|
|
9492
|
+
this._handleError(error);
|
|
9493
|
+
}
|
|
9494
|
+
}
|
|
9495
|
+
else {
|
|
9496
|
+
const page = request.position.mode === 'page'
|
|
9497
|
+
? request.position.page
|
|
9498
|
+
: request.position.ordinal;
|
|
9499
|
+
const detail = { page, items: [], request };
|
|
9500
|
+
this._dispatchAcknowledgedEvent('loadMore', detail);
|
|
9501
|
+
try {
|
|
9502
|
+
const callback = this._config.callbacks.onLoadMore;
|
|
9503
|
+
callback?.(page, request);
|
|
9504
|
+
}
|
|
9505
|
+
catch (error) {
|
|
9506
|
+
this._handleError(error);
|
|
9507
|
+
}
|
|
9508
|
+
}
|
|
9509
|
+
}
|
|
9510
|
+
}
|
|
9511
|
+
_dispatchAcknowledgedEvent(name, detail) {
|
|
9512
|
+
this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
9513
|
+
this._track('event', name, detail);
|
|
9514
|
+
}
|
|
9515
|
+
/** Test-only completion seam; accepted snapshots are projected from coordinator state. */
|
|
9516
|
+
async _completeDataRequestForTest(completion) {
|
|
9517
|
+
const result = this.completeDataRequest(completion);
|
|
9518
|
+
if (result !== 'accepted')
|
|
9519
|
+
return result;
|
|
9520
|
+
await this._acknowledgedProjectionTask;
|
|
9521
|
+
return result;
|
|
9522
|
+
}
|
|
9523
|
+
_failNextAcknowledgedProjectionForTest(stage = 'before-publish') {
|
|
9524
|
+
this._acknowledgedProjectionFailureStageForTest = stage;
|
|
9525
|
+
}
|
|
9526
|
+
/** Retries only from the canonical accepted coordinator snapshot, never a host payload. */
|
|
9527
|
+
_retryAcknowledgedProjectionForTest() {
|
|
9528
|
+
return this._retryAcknowledgedProjection();
|
|
9529
|
+
}
|
|
9530
|
+
_retryAcknowledgedProjection() {
|
|
9531
|
+
if (!this._dataRequestCoordinator || !this._acknowledgedProjectionPending)
|
|
9532
|
+
return Promise.resolve();
|
|
9533
|
+
return this._projectAcknowledgedSnapshot(this._dataRequestCoordinator.getSnapshot(), this._acknowledgedProjectionRequest ?? this._acknowledgedLastRequest, this._acknowledgedProjectionCommitsPosition);
|
|
9534
|
+
}
|
|
9535
|
+
_projectAcknowledgedSnapshot(snapshot, request, commitPosition) {
|
|
9536
|
+
if (this._acknowledgedProjectionRunning) {
|
|
9537
|
+
return this._acknowledgedProjectionTask ?? Promise.resolve();
|
|
9538
|
+
}
|
|
9539
|
+
this._acknowledgedProjectionRequest = request ?? this._acknowledgedProjectionRequest;
|
|
9540
|
+
this._acknowledgedProjectionAttempt += 1;
|
|
9541
|
+
this._acknowledgedProjectionPending = true;
|
|
9542
|
+
const items = Array.from(snapshot.items);
|
|
9543
|
+
let stagedRegistry;
|
|
9544
|
+
let groupedItems;
|
|
9545
|
+
try {
|
|
9546
|
+
stagedRegistry = createItemRegistry(items, this._itemAdapter, {
|
|
9547
|
+
duplicateKeyPolicy: this._getDuplicateKeyPolicy(),
|
|
9548
|
+
});
|
|
9549
|
+
groupedItems = this._groupItemsByProperty(items);
|
|
9550
|
+
if (this._acknowledgedProjectionFailureStageForTest === 'before-publish') {
|
|
9551
|
+
this._acknowledgedProjectionFailureStageForTest = null;
|
|
9552
|
+
throw new Error('Injected acknowledged projection failure before publication');
|
|
9553
|
+
}
|
|
9554
|
+
}
|
|
9555
|
+
catch (error) {
|
|
9556
|
+
this._syncListboxAccessibility();
|
|
9557
|
+
this._recordAcknowledgedProjectionFailure(snapshot, request, error);
|
|
9558
|
+
return Promise.resolve();
|
|
9559
|
+
}
|
|
9560
|
+
this._acknowledgedProjectionRunning = true;
|
|
9561
|
+
const task = this._applyAcknowledgedSnapshot(snapshot, request, commitPosition, items, stagedRegistry, groupedItems);
|
|
9562
|
+
const trackedTask = task.finally(() => {
|
|
9563
|
+
if (this._acknowledgedProjectionTask === trackedTask) {
|
|
9564
|
+
this._acknowledgedProjectionRunning = false;
|
|
9565
|
+
this._acknowledgedProjectionTask = null;
|
|
9566
|
+
}
|
|
9567
|
+
});
|
|
9568
|
+
this._acknowledgedProjectionTask = trackedTask;
|
|
9569
|
+
return trackedTask;
|
|
9570
|
+
}
|
|
9571
|
+
async _applyAcknowledgedSnapshot(snapshot, request, commitPosition, items, stagedRegistry, groupedItems) {
|
|
9572
|
+
let published = false;
|
|
9573
|
+
try {
|
|
9574
|
+
this._rebuildItemRegistry(items, stagedRegistry);
|
|
9575
|
+
this._state.groupedItems = groupedItems;
|
|
9576
|
+
if (commitPosition && request) {
|
|
9577
|
+
this._state.currentPage = snapshot.lastCommittedPage
|
|
9578
|
+
?? (request.position.mode === 'page' ? request.position.page : request.position.ordinal);
|
|
9579
|
+
}
|
|
9580
|
+
this._state.isSearching = false;
|
|
9581
|
+
this._state.isBusy = true;
|
|
9582
|
+
this._state.lastScrollPosition = this._acknowledgedProjectionScrollTop;
|
|
9583
|
+
this._state.preserveScrollPosition = request?.kind === 'loadMore';
|
|
9584
|
+
published = true;
|
|
9585
|
+
if (this._acknowledgedProjectionFailureStageForTest === 'after-publish') {
|
|
9586
|
+
this._acknowledgedProjectionFailureStageForTest = null;
|
|
9587
|
+
throw new Error('Injected acknowledged projection failure after publication');
|
|
9588
|
+
}
|
|
9589
|
+
if (!this._state.searchQuery
|
|
9590
|
+
&& this._acknowledgedPendingSearchQuery === null
|
|
9591
|
+
&& !this._isActivelyEditingSearchInput()) {
|
|
9592
|
+
this._updateInputDisplay();
|
|
9593
|
+
}
|
|
9594
|
+
this._syncListboxAccessibility();
|
|
9595
|
+
this._renderOptions();
|
|
9596
|
+
const renderCycleId = this._renderCycleId;
|
|
9597
|
+
const completed = await this._waitForRenderCycle(renderCycleId);
|
|
9598
|
+
if (!completed)
|
|
9599
|
+
throw new Error('Acknowledged snapshot render was superseded before completion');
|
|
9600
|
+
this._state.isBusy = snapshot.busy;
|
|
9601
|
+
if (!snapshot.busy) {
|
|
9602
|
+
this._optionsContainer.querySelector('.busy-bucket')?.remove();
|
|
9603
|
+
if (this._shouldRenderLoadMoreTrigger())
|
|
9604
|
+
this._addLoadMoreTrigger();
|
|
9605
|
+
}
|
|
9606
|
+
this._optionsContainer.scrollTop = this._acknowledgedProjectionScrollTop;
|
|
9607
|
+
this._syncListboxAccessibility();
|
|
9608
|
+
this._syncRenderedOptionAccessibility();
|
|
9609
|
+
this._syncLegacyActiveAria();
|
|
9610
|
+
this._state.preserveScrollPosition = false;
|
|
9611
|
+
this._acknowledgedProjectionPending = false;
|
|
9612
|
+
this._acknowledgedProjectionDiagnostic = null;
|
|
9613
|
+
this._acknowledgedProjectionSettling = true;
|
|
9614
|
+
try {
|
|
9615
|
+
this._dispatchDataProjectionNotification({
|
|
9616
|
+
requestId: this._acknowledgedProjectionRequest?.requestId ?? request?.requestId ?? 'unknown',
|
|
9617
|
+
queryGeneration: this._acknowledgedProjectionRequest?.queryGeneration ?? snapshot.queryGeneration,
|
|
9618
|
+
attempt: this._acknowledgedProjectionAttempt,
|
|
9619
|
+
status: 'complete',
|
|
9620
|
+
});
|
|
9621
|
+
}
|
|
9622
|
+
finally {
|
|
9623
|
+
this._acknowledgedProjectionSettling = false;
|
|
9624
|
+
}
|
|
9625
|
+
if (this._clearAcknowledgedCoordinatorAfterProjection) {
|
|
9626
|
+
this._dataRequestCoordinator = null;
|
|
9627
|
+
this._acknowledgedSearchMode = null;
|
|
9628
|
+
this._clearAcknowledgedCoordinatorAfterProjection = false;
|
|
9629
|
+
this._acknowledgedProjectionRequest = null;
|
|
9630
|
+
}
|
|
9631
|
+
else {
|
|
9632
|
+
this._acknowledgedProjectionRequest = null;
|
|
9633
|
+
}
|
|
9634
|
+
this._finishAcknowledgedProjectionSettlement();
|
|
9635
|
+
}
|
|
9636
|
+
catch (error) {
|
|
9637
|
+
if (published) {
|
|
9638
|
+
if (this.isConnected)
|
|
9639
|
+
this._state.isBusy = true;
|
|
9640
|
+
this._state.isSearching = false;
|
|
9641
|
+
this._syncListboxAccessibility();
|
|
9642
|
+
}
|
|
9643
|
+
this._acknowledgedProjectionPending = true;
|
|
9644
|
+
this._recordAcknowledgedProjectionFailure(snapshot, request, error);
|
|
9645
|
+
}
|
|
9646
|
+
}
|
|
9647
|
+
_recordAcknowledgedProjectionFailure(snapshot, request, error) {
|
|
9648
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9649
|
+
const diagnostic = {
|
|
9650
|
+
requestId: this._acknowledgedProjectionRequest?.requestId ?? request?.requestId ?? 'unknown',
|
|
9651
|
+
queryGeneration: this._acknowledgedProjectionRequest?.queryGeneration ?? snapshot.queryGeneration,
|
|
9652
|
+
message,
|
|
9653
|
+
};
|
|
9654
|
+
this._acknowledgedProjectionDiagnostic = diagnostic;
|
|
9655
|
+
this._emit('diagnostic', {
|
|
9656
|
+
timestamp: Date.now(),
|
|
9657
|
+
source: 'event',
|
|
9658
|
+
name: 'acknowledgedProjectionFailed',
|
|
9659
|
+
detail: diagnostic,
|
|
9660
|
+
});
|
|
9661
|
+
if (diagnostic.requestId !== 'unknown') {
|
|
9662
|
+
this._dispatchDataProjectionNotification({
|
|
9663
|
+
requestId: diagnostic.requestId,
|
|
9664
|
+
queryGeneration: diagnostic.queryGeneration,
|
|
9665
|
+
attempt: this._acknowledgedProjectionAttempt,
|
|
9666
|
+
status: 'failed',
|
|
9667
|
+
error: { message },
|
|
9668
|
+
});
|
|
9669
|
+
}
|
|
9670
|
+
}
|
|
9671
|
+
_dispatchDataProjectionNotification(detail) {
|
|
9672
|
+
this._dispatchAcknowledgedEvent('dataProjection', detail);
|
|
9673
|
+
try {
|
|
9674
|
+
this._dataProjectionCallback?.(detail);
|
|
9675
|
+
}
|
|
9676
|
+
catch (error) {
|
|
9677
|
+
this._handleError(error);
|
|
9678
|
+
}
|
|
9679
|
+
}
|
|
9680
|
+
_dispatchPendingAcknowledgedSearchIntent() {
|
|
9681
|
+
const query = this._acknowledgedPendingSearchQuery;
|
|
9682
|
+
if (query === null || !this._acknowledgedReady || !this.isConnected)
|
|
9683
|
+
return;
|
|
9684
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9685
|
+
this._handleSearch(query);
|
|
9686
|
+
}
|
|
9687
|
+
/** Apply config/query changes coalesced while an accepted snapshot projected. */
|
|
9688
|
+
_finishAcknowledgedProjectionSettlement() {
|
|
9689
|
+
const coordinator = this._dataRequestCoordinator;
|
|
9690
|
+
const query = this._acknowledgedPendingSearchQuery;
|
|
9691
|
+
if (this._dataLoadingConfig.protocol !== 'acknowledged' || !coordinator) {
|
|
9692
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9693
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9694
|
+
if (this._dataLoadingConfig.protocol === 'legacy' && query !== null && this.isConnected) {
|
|
9695
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9696
|
+
this._handleSearch(query);
|
|
9697
|
+
}
|
|
9698
|
+
else {
|
|
9699
|
+
this._dispatchPendingAcknowledgedSearchIntent();
|
|
9700
|
+
}
|
|
9701
|
+
return;
|
|
9702
|
+
}
|
|
9703
|
+
if (!this.isConnected || !this._acknowledgedReady)
|
|
9704
|
+
return;
|
|
9705
|
+
if (this._acknowledgedConfigUpdatePending) {
|
|
9706
|
+
const requiresSingleLatestQueryRequest = this._acknowledgedDeferredModeChange && query !== null;
|
|
9707
|
+
if (requiresSingleLatestQueryRequest) {
|
|
9708
|
+
// Apply the mode transition while disconnected, set the latest query,
|
|
9709
|
+
// then reconnect once. This prevents an intermediate request for the
|
|
9710
|
+
// pre-projection query from escaping before the coalesced latest one.
|
|
9711
|
+
this._dispatchAcknowledgedActions(coordinator.disconnect());
|
|
9712
|
+
}
|
|
9713
|
+
const update = coordinator.updateConfig(this._createCoordinatorConfig());
|
|
9714
|
+
if (update.status !== 'accepted') {
|
|
9715
|
+
this._acknowledgedReady = false;
|
|
9716
|
+
return;
|
|
9717
|
+
}
|
|
9718
|
+
this._acknowledgedConfigUpdatePending = false;
|
|
9719
|
+
this._acknowledgedDeferredModeChange = false;
|
|
9720
|
+
if (requiresSingleLatestQueryRequest && query !== null) {
|
|
9721
|
+
this._acknowledgedPendingSearchQuery = null;
|
|
9722
|
+
this._state.searchQuery = query;
|
|
9723
|
+
this._input.value = query;
|
|
9724
|
+
this._dispatchAcknowledgedActions(coordinator.setQuery(query));
|
|
9725
|
+
this._dispatchAcknowledgedActions(coordinator.connect(query));
|
|
9726
|
+
this._syncListboxAccessibility();
|
|
9727
|
+
this._handleSearch(query);
|
|
9728
|
+
return;
|
|
9729
|
+
}
|
|
9730
|
+
this._dispatchAcknowledgedActions(update.actions);
|
|
9731
|
+
const state = coordinator.getSnapshot();
|
|
9732
|
+
this._state.isBusy = state.busy;
|
|
9733
|
+
this._state.isSearching = state.activeRequest?.kind === 'search';
|
|
9734
|
+
this._syncListboxAccessibility();
|
|
9735
|
+
}
|
|
9736
|
+
this._dispatchPendingAcknowledgedSearchIntent();
|
|
9737
|
+
}
|
|
7937
9738
|
_updateGuardedVirtualWindow(scrollTop, viewportHeight) {
|
|
7938
9739
|
this._guardedVirtualizationRequested = true;
|
|
7939
9740
|
const virtualizer = this._ensureGuardedVirtualizer(this._renderPlan.filteredKeys);
|
|
@@ -8121,6 +9922,7 @@
|
|
|
8121
9922
|
const scrollTopBeforeRender = this._optionsContainer.scrollTop;
|
|
8122
9923
|
this._renderCycleId += 1;
|
|
8123
9924
|
const renderCycleId = this._renderCycleId;
|
|
9925
|
+
this._resolvePendingRenderCycles(false, renderCycleId);
|
|
8124
9926
|
if (this._guardedVirtualizer) {
|
|
8125
9927
|
this._guardedVirtualScrollTop = this._optionsContainer.scrollTop;
|
|
8126
9928
|
}
|
|
@@ -8128,6 +9930,8 @@
|
|
|
8128
9930
|
if (this._loadMoreTrigger && this._intersectionObserver) {
|
|
8129
9931
|
this._intersectionObserver.unobserve(this._loadMoreTrigger);
|
|
8130
9932
|
}
|
|
9933
|
+
if (this._dataRequestCoordinator)
|
|
9934
|
+
this._loadMoreTrigger = undefined;
|
|
8131
9935
|
this._unobserveGuardedOptionResizeTargets();
|
|
8132
9936
|
// Clear options container
|
|
8133
9937
|
this._optionsContainer.innerHTML = '';
|
|
@@ -8156,12 +9960,15 @@
|
|
|
8156
9960
|
searching.setAttribute('part', 'loading');
|
|
8157
9961
|
searching.textContent = 'Searching...';
|
|
8158
9962
|
this._optionsContainer.appendChild(searching);
|
|
9963
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
8159
9964
|
return;
|
|
8160
9965
|
}
|
|
8161
9966
|
const getValue = this._config.serverSide.getValueFromItem || ((item) => item?.value ?? item);
|
|
8162
9967
|
const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
|
|
8163
9968
|
// Filter items by search query
|
|
8164
|
-
const query = this.
|
|
9969
|
+
const query = this._acknowledgedSearchMode === 'remote'
|
|
9970
|
+
? ''
|
|
9971
|
+
: this._state.searchQuery.toLowerCase();
|
|
8165
9972
|
if (this._guardedMeasurementQuery !== null && this._guardedMeasurementQuery !== query) {
|
|
8166
9973
|
this._invalidateGuardedMeasurements();
|
|
8167
9974
|
}
|
|
@@ -8286,8 +10093,10 @@
|
|
|
8286
10093
|
}
|
|
8287
10094
|
}
|
|
8288
10095
|
const renderChunk = () => {
|
|
8289
|
-
if (renderCycleId !== this._renderCycleId)
|
|
10096
|
+
if (renderCycleId !== this._renderCycleId) {
|
|
10097
|
+
this._resolveRenderCycle(renderCycleId, false);
|
|
8290
10098
|
return;
|
|
10099
|
+
}
|
|
8291
10100
|
const fragment = document.createDocumentFragment();
|
|
8292
10101
|
const chunkEnd = Math.min(Math.max(cursor + chunkSize, maxRenderTarget), filteredIndices.length);
|
|
8293
10102
|
maxRenderTarget = 0; // Reset after fast-forwarding
|
|
@@ -8305,12 +10114,15 @@
|
|
|
8305
10114
|
this._requestLifecycleFrame(renderChunk);
|
|
8306
10115
|
}
|
|
8307
10116
|
else {
|
|
8308
|
-
if (renderCycleId !== this._renderCycleId)
|
|
10117
|
+
if (renderCycleId !== this._renderCycleId) {
|
|
10118
|
+
this._resolveRenderCycle(renderCycleId, false);
|
|
8309
10119
|
return;
|
|
8310
|
-
|
|
10120
|
+
}
|
|
10121
|
+
if (!this._state.isBusy && this._shouldRenderLoadMoreTrigger()) {
|
|
8311
10122
|
this._addLoadMoreTrigger();
|
|
8312
10123
|
}
|
|
8313
10124
|
this._finalizePerfMarks();
|
|
10125
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
8314
10126
|
}
|
|
8315
10127
|
};
|
|
8316
10128
|
renderChunk();
|
|
@@ -8342,7 +10154,7 @@
|
|
|
8342
10154
|
this._optionsContainer.appendChild(busyBucket);
|
|
8343
10155
|
}
|
|
8344
10156
|
// Append Load More Trigger (Button or Sentinel) if enabled and not busy
|
|
8345
|
-
else if ((this.
|
|
10157
|
+
else if ((!this._dataRequestCoordinator || !this._state.isBusy) && this._shouldRenderLoadMoreTrigger()) {
|
|
8346
10158
|
this._addLoadMoreTrigger();
|
|
8347
10159
|
}
|
|
8348
10160
|
// Rebuilding the list temporarily removes its spacer geometry. Browsers
|
|
@@ -8355,6 +10167,43 @@
|
|
|
8355
10167
|
this._syncLegacyActiveAria();
|
|
8356
10168
|
this._syncGuardedOptionResizeTargets();
|
|
8357
10169
|
this._finalizePerfMarks();
|
|
10170
|
+
this._resolveRenderCycle(renderCycleId, true);
|
|
10171
|
+
}
|
|
10172
|
+
_waitForRenderCycle(renderCycleId) {
|
|
10173
|
+
if (renderCycleId < this._renderCycleId)
|
|
10174
|
+
return Promise.resolve(false);
|
|
10175
|
+
if (renderCycleId <= this._completedRenderCycleId)
|
|
10176
|
+
return Promise.resolve(true);
|
|
10177
|
+
return new Promise((resolve) => {
|
|
10178
|
+
this._renderCycleWaiters.set(renderCycleId, resolve);
|
|
10179
|
+
const timeout = window.setTimeout(() => this._resolveRenderCycle(renderCycleId, false), 120000);
|
|
10180
|
+
this._renderCycleWaiterTimeouts.set(renderCycleId, timeout);
|
|
10181
|
+
});
|
|
10182
|
+
}
|
|
10183
|
+
_resolveRenderCycle(renderCycleId, completed) {
|
|
10184
|
+
if (completed)
|
|
10185
|
+
this._completedRenderCycleId = Math.max(this._completedRenderCycleId, renderCycleId);
|
|
10186
|
+
const resolve = this._renderCycleWaiters.get(renderCycleId);
|
|
10187
|
+
const timeout = this._renderCycleWaiterTimeouts.get(renderCycleId);
|
|
10188
|
+
if (timeout !== undefined)
|
|
10189
|
+
window.clearTimeout(timeout);
|
|
10190
|
+
this._renderCycleWaiterTimeouts.delete(renderCycleId);
|
|
10191
|
+
if (!resolve)
|
|
10192
|
+
return;
|
|
10193
|
+
this._renderCycleWaiters.delete(renderCycleId);
|
|
10194
|
+
resolve(completed);
|
|
10195
|
+
}
|
|
10196
|
+
_resolvePendingRenderCycles(completed, beforeCycleId = Number.POSITIVE_INFINITY) {
|
|
10197
|
+
for (const [renderCycleId, resolve] of this._renderCycleWaiters) {
|
|
10198
|
+
if (renderCycleId >= beforeCycleId)
|
|
10199
|
+
continue;
|
|
10200
|
+
const timeout = this._renderCycleWaiterTimeouts.get(renderCycleId);
|
|
10201
|
+
if (timeout !== undefined)
|
|
10202
|
+
window.clearTimeout(timeout);
|
|
10203
|
+
this._renderCycleWaiterTimeouts.delete(renderCycleId);
|
|
10204
|
+
this._renderCycleWaiters.delete(renderCycleId);
|
|
10205
|
+
resolve(completed);
|
|
10206
|
+
}
|
|
8358
10207
|
}
|
|
8359
10208
|
_unobserveGuardedOptionResizeTargets() {
|
|
8360
10209
|
for (const option of this._guardedObservedOptions) {
|
|
@@ -8567,6 +10416,46 @@
|
|
|
8567
10416
|
_addLoadMoreTrigger() {
|
|
8568
10417
|
const container = document.createElement('div');
|
|
8569
10418
|
container.className = 'load-more-container';
|
|
10419
|
+
if (this._dataRequestCoordinator) {
|
|
10420
|
+
const shouldObserve = this._config.infiniteScroll.enabled
|
|
10421
|
+
&& Boolean(this._intersectionObserver)
|
|
10422
|
+
&& this._acknowledgedReady;
|
|
10423
|
+
let sentinel;
|
|
10424
|
+
if (shouldObserve) {
|
|
10425
|
+
sentinel = this._acknowledgedSentinel ?? document.createElement('div');
|
|
10426
|
+
sentinel.className = 'infinite-scroll-sentinel';
|
|
10427
|
+
sentinel.style.height = '10px';
|
|
10428
|
+
sentinel.style.width = '100%';
|
|
10429
|
+
sentinel.style.opacity = '0';
|
|
10430
|
+
this._acknowledgedSentinel = sentinel;
|
|
10431
|
+
this._loadMoreTrigger = sentinel;
|
|
10432
|
+
container.appendChild(sentinel);
|
|
10433
|
+
}
|
|
10434
|
+
// Keep an explicit keyboard-accessible path even when automatic
|
|
10435
|
+
// observation is enabled, and use it as the fallback if IO is absent.
|
|
10436
|
+
if (this._config.loadMore.enabled || this._config.infiniteScroll.enabled) {
|
|
10437
|
+
const button = document.createElement('button');
|
|
10438
|
+
button.className = 'load-more-button';
|
|
10439
|
+
button.textContent = `Load ${this._config.loadMore.itemsPerLoad} more`;
|
|
10440
|
+
button.addEventListener('click', () => this._loadMoreItems('manual'));
|
|
10441
|
+
container.appendChild(button);
|
|
10442
|
+
if (!sentinel)
|
|
10443
|
+
this._loadMoreTrigger = button;
|
|
10444
|
+
}
|
|
10445
|
+
this._optionsContainer.appendChild(container);
|
|
10446
|
+
if (sentinel && this._intersectionObserver) {
|
|
10447
|
+
try {
|
|
10448
|
+
this._intersectionObserver.observe(sentinel);
|
|
10449
|
+
}
|
|
10450
|
+
catch (_error) {
|
|
10451
|
+
this._intersectionObserver.disconnect();
|
|
10452
|
+
this._intersectionObserver = undefined;
|
|
10453
|
+
sentinel.remove();
|
|
10454
|
+
this._loadMoreTrigger = container.querySelector('.load-more-button') ?? undefined;
|
|
10455
|
+
}
|
|
10456
|
+
}
|
|
10457
|
+
return;
|
|
10458
|
+
}
|
|
8570
10459
|
if (this._config.infiniteScroll.enabled) {
|
|
8571
10460
|
// Infinite Scroll: Render an invisible sentinel
|
|
8572
10461
|
// It must have some height to be intersected
|
|
@@ -8593,6 +10482,23 @@
|
|
|
8593
10482
|
this._intersectionObserver.observe(this._loadMoreTrigger);
|
|
8594
10483
|
}
|
|
8595
10484
|
}
|
|
10485
|
+
_shouldRenderLoadMoreTrigger() {
|
|
10486
|
+
if (!this._config.loadMore.enabled && !this._config.infiniteScroll.enabled)
|
|
10487
|
+
return false;
|
|
10488
|
+
if (this._dataLoadingConfig.protocol === 'acknowledged'
|
|
10489
|
+
&& (!this._dataRequestCoordinator || !this._acknowledgedReady))
|
|
10490
|
+
return false;
|
|
10491
|
+
if (!this._dataRequestCoordinator)
|
|
10492
|
+
return this._state.loadedItems.length > 0;
|
|
10493
|
+
const snapshot = this._dataRequestCoordinator.getSnapshot();
|
|
10494
|
+
if (snapshot.status === 'resource-limited')
|
|
10495
|
+
return false;
|
|
10496
|
+
return snapshot.hasMore
|
|
10497
|
+
|| snapshot.error !== null
|
|
10498
|
+
|| snapshot.status === 'empty'
|
|
10499
|
+
|| snapshot.status === 'failed'
|
|
10500
|
+
|| snapshot.status === 'cancelled';
|
|
10501
|
+
}
|
|
8596
10502
|
}
|
|
8597
10503
|
/** live set of all connected instances; used to auto-close siblings */
|
|
8598
10504
|
EnhancedSelect._instances = new Set();
|
|
@@ -9689,6 +11595,7 @@
|
|
|
9689
11595
|
exports.shadowDOMStyles = shadowDOMStyles;
|
|
9690
11596
|
exports.toggleClass = toggleClass;
|
|
9691
11597
|
exports.transition = transition;
|
|
11598
|
+
exports.validateDataLoadingConfig = validateDataLoadingConfig;
|
|
9692
11599
|
exports.validateTemplate = validateTemplate;
|
|
9693
11600
|
exports.valuesEqual = valuesEqual;
|
|
9694
11601
|
exports.warnCSPViolation = warnCSPViolation;
|