/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { html, ifDefined } from "chrome://global/content/vendor/lit.all.mjs"; import { SidebarTabList, SidebarTabRow, } from "chrome://browser/content/sidebar/sidebar-tab-list.mjs"; export class SidebarBookmarkList extends SidebarTabList { static properties = { ...SidebarTabList.properties, expandedFolderGuids: { type: Object }, }; constructor() { super(); this.bookmarksContext = true; this.expandedFolderGuids = new Set(); this.getItemHeight = (item, h) => this.#itemHeightGetter(item, h); } willUpdate(changes) { super.willUpdate(changes); if (changes.has("expandedFolderGuids")) { // Reassign to a new function reference so Lit detects the change and // propagates it to sublists, causing them to reset their cached heights. this.getItemHeight = (item, h) => this.#itemHeightGetter(item, h); } } #itemHeightGetter = (item, defaultHeight) => { if (!item.children || !this.expandedFolderGuids.has(item.guid)) { return defaultHeight; } return item.children.reduce( (sum, child) => sum + this.#itemHeightGetter(child, defaultHeight), defaultHeight ); }; static queries = { ...SidebarTabList.queries, rowEls: { all: "sidebar-bookmark-row" }, folderEls: { all: "details" }, folderLabelEl: ".bookmark-folder-label", }; itemTemplate = (tabItem, i) => { let tabIndex = -1; if ((this.searchQuery || this.sortOption == "lastvisited") && i == 0) { tabIndex = 0; } else if (!this.searchQuery) { tabIndex = 0; } if (!tabItem.url && !tabItem.children) { return html`
`; } if (tabItem.children !== undefined) { if (!tabItem.children.length) { return html`