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 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DropdownSizePosCache = void 0;
var tslib_1 = require("tslib");
var Dropdown_types_1 = require("../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.
*/
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":";;;;AAAA,oDAAyD;AAGzD;;;;;;;;;GASG;AACH;IAAA;QAIU,UAAK,GAAG,CAAC,CAAC;IAqEpB,CAAC;IAnEC;;OAEG;IACI,4CAAa,GAApB,UAAqB,OAA0B;QAC7C,IAAM,uBAAuB,GAAG,EAAE,CAAC;QACnC,IAAM,yBAAyB,GAAG,EAAE,CAAC;QACrC,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC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C,wBAAwB,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;YACpD,MAAM,IAAI,KAAK,CAAC,sCAA+B,KAAK,kCAA+B,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,IAAI,CAAC,0BAA0B,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;YACtD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;IAC5B,CAAC;IACH,2BAAC;AAAD,CAAC,AAzED,IAyEC;AAzEY,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"]}