first commit

This commit is contained in:
Stefan Hacker
2026-04-03 09:38:48 +02:00
commit 37ad745546
47450 changed files with 3120798 additions and 0 deletions
@@ -0,0 +1,35 @@
import type { IDropdownOption } from '../Dropdown.types';
/**
* A utility class to cache size and position in cache.
*
* Dropdown options has non-selectable display types. It is therefore not cheap to determine
* the total number of actual selectable options as well as the position an option is in the
* list of options - O(n) cost for each lookup.
*
* Given that we potentially have to make this determination on every single render pass, this
* cache should provide a little bit of relief.
*/
export declare class DropdownSizePosCache {
private _cachedOptions;
private _displayOnlyOptionsCache;
private _notSelectableOptionsCache;
private _size;
/**
* Invalidates the cache and recalculate the size of selectable options.
*/
updateOptions(options: IDropdownOption[]): void;
/**
* The size of all the selectable options.
*/
get optionSetSize(): number;
/**
* The chached options array.
*/
get cachedOptions(): IDropdownOption[];
/**
* Returns the position of this option element relative to the full set of selectable option elements.
* Note: the first selectable element is position 1 in the set.
* @param index The raw index of the option element.
*/
positionInSet(index: number | undefined): number | undefined;
}
@@ -0,0 +1,91 @@
define(["require", "exports", "tslib", "../Dropdown.types"], function (require, exports, tslib_1, Dropdown_types_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DropdownSizePosCache = void 0;
/**
* A utility class to cache size and position in cache.
*
* Dropdown options has non-selectable display types. It is therefore not cheap to determine
* the total number of actual selectable options as well as the position an option is in the
* list of options - O(n) cost for each lookup.
*
* Given that we potentially have to make this determination on every single render pass, this
* cache should provide a little bit of relief.
*/
var DropdownSizePosCache = /** @class */ (function () {
function DropdownSizePosCache() {
this._size = 0;
}
/**
* Invalidates the cache and recalculate the size of selectable options.
*/
DropdownSizePosCache.prototype.updateOptions = function (options) {
var displayOnlyOptionsCache = [];
var notSelectableOptionsCache = [];
var size = 0;
for (var i = 0; i < options.length; i++) {
var _a = options[i], itemType = _a.itemType, hidden = _a.hidden;
if (itemType === Dropdown_types_1.DropdownMenuItemType.Divider || itemType === Dropdown_types_1.DropdownMenuItemType.Header) {
displayOnlyOptionsCache.push(i);
notSelectableOptionsCache.push(i);
}
else if (hidden) {
notSelectableOptionsCache.push(i);
}
else {
size++;
}
}
this._size = size;
this._displayOnlyOptionsCache = displayOnlyOptionsCache;
this._notSelectableOptionsCache = notSelectableOptionsCache;
this._cachedOptions = tslib_1.__spreadArray([], options, true);
};
Object.defineProperty(DropdownSizePosCache.prototype, "optionSetSize", {
/**
* The size of all the selectable options.
*/
get: function () {
return this._size;
},
enumerable: false,
configurable: true
});
Object.defineProperty(DropdownSizePosCache.prototype, "cachedOptions", {
/**
* The chached options array.
*/
get: function () {
return this._cachedOptions;
},
enumerable: false,
configurable: true
});
/**
* Returns the position of this option element relative to the full set of selectable option elements.
* Note: the first selectable element is position 1 in the set.
* @param index The raw index of the option element.
*/
DropdownSizePosCache.prototype.positionInSet = function (index) {
if (index === undefined) {
return undefined;
}
// we could possibly memoize this too but this should be good enough, most of the time (the expectation is that
// when you have a lot of options, the selectable options will heavily dominate over the non-selectable options.
var offset = 0;
while (index > this._notSelectableOptionsCache[offset]) {
offset++;
}
if (this._displayOnlyOptionsCache[offset] === index) {
throw new Error("Unexpected: Option at index ".concat(index, " is not a selectable element."));
}
if (this._notSelectableOptionsCache[offset] === index) {
return undefined;
}
return index - offset + 1;
};
return DropdownSizePosCache;
}());
exports.DropdownSizePosCache = DropdownSizePosCache;
});
//# sourceMappingURL=DropdownSizePosCache.js.map
@@ -0,0 +1 @@
{"version":3,"file":"DropdownSizePosCache.js","sourceRoot":"../src/","sources":["components/Dropdown/utilities/DropdownSizePosCache.ts"],"names":[],"mappings":";;;;IAGA;;;;;;;;;OASG;IACH;QAAA;YAIU,UAAK,GAAG,CAAC,CAAC;QAqEpB,CAAC;QAnEC;;WAEG;QACI,4CAAa,GAApB,UAAqB,OAA0B;YAC7C,IAAM,uBAAuB,GAAG,EAAE,CAAC;YACnC,IAAM,yBAAyB,GAAG,EAAE,CAAC;YACrC,IAAI,IAAI,GAAG,CAAC,CAAC;YACb,KAAK,IAAI,CAAC,GAAG,CAAC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AI,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;gBACpD,MAAM,IAAI,KAAK,CAAC,sCAA+B,KAAK,kCAA+B,CAAC,CAAC;YACvF,CAAC;YAED,IAAI,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;gBACtD,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,OAAO,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;QAC5B,CAAC;QACH,2BAAC;IAAD,CAAC,AAzED,IAyEC;IAzEY,oDAAoB","sourcesContent":["import { DropdownMenuItemType } from '../Dropdown.types';\nimport type { IDropdownOption } from '../Dropdown.types';\n\n/**\n * A utility class to cache size and position in cache.\n *\n * Dropdown options has non-selectable display types. It is therefore not cheap to determine\n * the total number of actual selectable options as well as the position an option is in the\n * list of options - O(n) cost for each lookup.\n *\n * Given that we potentially have to make this determination on every single render pass, this\n * cache should provide a little bit of relief.\n */\nexport class DropdownSizePosCache {\n private _cachedOptions: IDropdownOption[];\n private _displayOnlyOptionsCache: number[];\n private _notSelectableOptionsCache: number[];\n private _size = 0;\n\n /**\n * Invalidates the cache and recalculate the size of selectable options.\n */\n public updateOptions(options: IDropdownOption[]): void {\n const displayOnlyOptionsCache = [];\n const notSelectableOptionsCache = [];\n let size = 0;\n for (let i = 0; i < options.length; i++) {\n const { itemType, hidden } = options[i];\n\n if (itemType === DropdownMenuItemType.Divider || itemType === DropdownMenuItemType.Header) {\n displayOnlyOptionsCache.push(i);\n notSelectableOptionsCache.push(i);\n } else if (hidden) {\n notSelectableOptionsCache.push(i);\n } else {\n size++;\n }\n }\n\n this._size = size;\n this._displayOnlyOptionsCache = displayOnlyOptionsCache;\n this._notSelectableOptionsCache = notSelectableOptionsCache;\n this._cachedOptions = [...options];\n }\n\n /**\n * The size of all the selectable options.\n */\n public get optionSetSize(): number {\n return this._size;\n }\n\n /**\n * The chached options array.\n */\n public get cachedOptions(): IDropdownOption[] {\n return this._cachedOptions;\n }\n\n /**\n * Returns the position of this option element relative to the full set of selectable option elements.\n * Note: the first selectable element is position 1 in the set.\n * @param index The raw index of the option element.\n */\n public positionInSet(index: number | undefined): number | undefined {\n if (index === undefined) {\n return undefined;\n }\n\n // we could possibly memoize this too but this should be good enough, most of the time (the expectation is that\n // when you have a lot of options, the selectable options will heavily dominate over the non-selectable options.\n let offset = 0;\n while (index > this._notSelectableOptionsCache[offset]) {\n offset++;\n }\n\n if (this._displayOnlyOptionsCache[offset] === index) {\n throw new Error(`Unexpected: Option at index ${index} is not a selectable element.`);\n }\n\n if (this._notSelectableOptionsCache[offset] === index) {\n return undefined;\n }\n\n return index - offset + 1;\n }\n}\n"]}