-
🌐 async-utils.jsWeb, 3.69 kB⬇
-
🌐 auth-storage.jsWeb, 735 B⬇
-
🌐 chat-helpers.jsWeb, 8.85 kB⬇
-
🌐 chat-renderer.jsWeb, 70.00 kB⬇
-
🌐 code-overlay.jsWeb, 21.77 kB⬇
-
🌐 confirm-dialog.jsWeb, 3.17 kB⬇
-
🌐 conversation-format-utils.jsWeb, 21.51 kB⬇
-
🌐 diagram-overlay.jsWeb, 7.93 kB⬇
-
🌐 dialog.jsWeb, 2.50 kB⬇
-
🌐 dom-utils.jsWeb, 8.33 kB⬇
-
🌐 drag-reorder.jsWeb, 4.82 kB⬇
-
🌐 elements.jsWeb, 11.06 kB⬇
-
🌐 export-utils.jsWeb, 1.53 kB⬇
-
🌐 format-utils.jsWeb, 29.60 kB⬇
-
🌐 history-navigation.jsWeb, 1.95 kB⬇
-
🌐 hljs-yaml.jsWeb, 5.07 kB⬇
-
🌐 inline-format.jsWeb, 7.35 kB⬇
-
🌐 instant-answer.jsWeb, 19.82 kB⬇
-
🌐 interactive-tools.jsWeb, 38.77 kB⬇
-
🌐 mermaid-fixes.jsWeb, 4.60 kB⬇
-
🌐 mermaid-render.jsWeb, 5.10 kB⬇
-
🌐 mermaid.jsWeb, 195 B⬇
-
🌐 migrations.jsWeb, 12.11 kB⬇
-
🌐 multi-choice-dialog.jsWeb, 1.33 kB⬇
-
🌐 notification-stack.jsWeb, 2.50 kB⬇
-
🌐 options-manager.jsWeb, 45.56 kB⬇
-
🌐 overlay-utils.jsWeb, 4.14 kB⬇
-
🌐 pdf-export.jsWeb, 23.59 kB⬇
-
🌐 pinch-zoom.jsWeb, 3.21 kB⬇
-
🌐 plugin-dialog.jsWeb, 2.17 kB⬇
-
🌐 read-aloud.jsWeb, 33.84 kB⬇
-
🌐 response-pipeline.jsWeb, 55.19 kB⬇
-
🌐 scratchpad-editor.jsWeb, 8.64 kB⬇
-
🌐 scratchpad-export.jsWeb, 3.56 kB⬇
-
🌐 scrollbars.jsWeb, 3.12 kB⬇
-
🌐 selection-manager.jsWeb, 3.76 kB⬇
-
🌐 settings-utils.jsWeb, 31.08 kB⬇
-
🌐 share.jsWeb, 10.75 kB⬇
-
🌐 side-drawer.jsWeb, 9.37 kB⬇
-
🌐 speech-text.jsWeb, 6.60 kB⬇
-
🌐 swipe-navigation.jsWeb, 6.16 kB⬇
-
🌐 table-overlay.jsWeb, 8.10 kB⬇
-
🌐 theme-utils.jsWeb, 8.34 kB⬇
-
🌐 thinking-panel-base.jsWeb, 14.88 kB⬇
-
🌐 ui-sets.jsWeb, 1.00 kB⬇
-
🌐 version-overlay.jsWeb, 4.63 kB⬇
/**
* Selection manager for handling multi-select state, item toggles, and button updates.
*/
export class SelectionManager {
#isSelectionMode = false;
#selectedItems = [];
#onSelectionChange;
/**
* @param {Function} [onSelectionChange] - Callback invoked whenever selection state changes.
*/
constructor(onSelectionChange = null) {
this.#onSelectionChange = onSelectionChange;
}
/**
* Gets whether multi-selection mode is active.
* @returns {boolean}
*/
get isSelectionMode() {
return this.#isSelectionMode;
}
/**
* Sets multi-selection mode and notifies listeners.
* @param {boolean} val
*/
set isSelectionMode(val) {
this.#isSelectionMode = !!val;
this._notify();
}
/**
* Returns a copy of the selected items array.
* @returns {Array<string|number>}
*/
get selectedItems() {
return [...this.#selectedItems];
}
/**
* Sets the selected items and notifies listeners.
* @param {Array<string|number>} items
*/
set selectedItems(items) {
this.#selectedItems = Array.isArray(items) ? [...items] : [];
this._notify();
}
/**
* Returns the count of selected items.
* @returns {number}
*/
get count() {
return this.#selectedItems.length;
}
/**
* Toggles selection mode on or off. Clears selected items when disabled.
* @param {boolean|null} [force=null] - Optional boolean to force state.
* @returns {boolean} New selection mode state.
*/
toggleMode(force = null) {
this.#isSelectionMode = force !== null ? !!force : !this.#isSelectionMode;
if (!this.#isSelectionMode) {
this.#selectedItems = [];
}
this._notify();
return this.#isSelectionMode;
}
/**
* Checks if an item is currently selected.
* @param {string|number} id - Item identifier or index.
* @returns {boolean}
*/
isSelected(id) {
return this.#selectedItems.includes(id);
}
/**
* Selects an item.
* @param {string|number} id - Item identifier or index.
*/
select(id) {
if (!this.#selectedItems.includes(id)) {
this.#selectedItems.push(id);
this._notify();
}
}
/**
* Deselects an item.
* @param {string|number} id - Item identifier or index.
*/
deselect(id) {
const idx = this.#selectedItems.indexOf(id);
if (idx !== -1) {
this.#selectedItems.splice(idx, 1);
this._notify();
}
}
/**
* Toggles the selection state of a specific item.
* @param {string|number} id - Item identifier or index.
* @param {boolean|null} [force=null] - Optional force state.
* @returns {boolean} Whether the item is now selected.
*/
toggleItem(id, force = null) {
const shouldSelect = force !== null ? !!force : !this.isSelected(id);
if (shouldSelect) {
this.select(id);
} else {
this.deselect(id);
}
return shouldSelect;
}
/**
* Resets selection state and exits selection mode.
*/
clear() {
this.#selectedItems = [];
this.#isSelectionMode = false;
this._notify();
}
/**
* Updates the select button label and enables/disables associated action buttons.
* @param {HTMLElement|null} selectBtn - Button indicating selection count.
* @param {HTMLElement[]} [actionBtns=[]] - Action buttons to enable/disable.
* @param {string} [defaultLabel='Select'] - Default text when no items selected.
*/
updateControls(selectBtn, actionBtns = [], defaultLabel = 'Select') {
if (selectBtn) {
selectBtn.textContent = this.count > 0 ? String(this.count) : defaultLabel;
}
const hasSelection = this.count > 0;
(actionBtns || []).forEach(btn => {
if (btn) {
btn.disabled = !hasSelection;
}
});
}
/**
* Notifies the selection change listener of updated state.
* @private
*/
_notify() {
if (typeof this.#onSelectionChange === 'function') {
this.#onSelectionChange({
isSelectionMode: this.#isSelectionMode,
selectedItems: this.selectedItems,
count: this.count
});
}
}
}
selection-manager.js
×
Type: Web, text/plain
3.76 Kilobytes
Last Modified 2026-11-04 09:48:28
⬇ Download File
Type: Web, text/plain
3.76 Kilobytes
Last Modified 2026-11-04 09:48:28
⬇ Download File