An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve bazaar list dynamic loading https://github.com/siyuan-note/siyuan/issues/19573
Daniel683873cacc15
diff --git a/app/src/assets/scss/business/_config.scss b/app/src/assets/scss/business/_config.scssindex f33f2dc5d2..bc36e25aca 100644--- a/app/src/assets/scss/business/_config.scss+++ b/app/src/assets/scss/business/_config.scss@@ -718,6 +718,14 @@}}+ &__cards {+ grid-auto-rows: 160px;++ > [data-bazaar-index] {+ cursor: default;+ }+ }+&__rating-star {--b3-icon-star-fill: currentColor;display: block;diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.tsindex ee86f318a7..ec56dc7aef 100644--- a/app/src/config/bazaar.ts+++ b/app/src/config/bazaar.ts@@ -1719,7 +1719,7 @@ type="checkbox">state.frameID = window.requestAnimationFrame(() => {state.frameID = undefined;if (state.active && this._isBazaarCardRenderCurrent(state)) {- this._appendBazaarCardBatch(state);+ this._fillVisibleBazaarCards(state);}});},@@ -1730,49 +1730,56 @@ type="checkbox">if (typeof window.IntersectionObserver === "function") {if (!state.observer) {state.observer = new IntersectionObserver((entries) => {- if (entries.some((entry) => entry.isIntersecting)) {- state.observer?.disconnect();- this._scheduleBazaarCardBatch(state);+ if (!state.active || !this._isBazaarCardRenderCurrent(state)) {+ return;}+ entries.filter((entry) => entry.isIntersecting).forEach((entry) => {+ this._fillBazaarCard(state, entry.target as HTMLElement);+ });}, {root: state.panel,rootMargin: "640px 0px",});}state.observer.disconnect();- const lastCard = state.cardsElement.lastElementChild;- if (lastCard) {- state.observer.observe(lastCard);- }+ state.cardsElement.querySelectorAll("[data-bazaar-index]").forEach((card) => state.observer.observe(card));return;}if (!state.scrollHandler) {state.scrollHandler = () => {- if (state.panel.scrollTop + state.panel.clientHeight + 640 >= state.panel.scrollHeight) {- this._scheduleBazaarCardBatch(state);- }+ this._scheduleBazaarCardBatch(state);};state.panel.addEventListener("scroll", state.scrollHandler, {passive: true});}- if (state.panel.clientHeight > 0 &&- state.panel.scrollTop + state.panel.clientHeight + 640 >= state.panel.scrollHeight) {+ if (state.panel.clientHeight > 0) {this._scheduleBazaarCardBatch(state);}},- _appendBazaarCardBatch(state: IBazaarCardRenderState) {- if (!this._isBazaarCardRenderCurrent(state)) {+ _fillBazaarCard(state: IBazaarCardRenderState, card: HTMLElement) {+ const index = card.getAttribute("data-bazaar-index");+ if (index === null) {return;}- const batch = getNextBazaarCardBatch(state.packages, state.cursor);- state.cursor = batch.nextCursor;- state.cardsElement.insertAdjacentHTML("beforeend", batch.packages.map((item) =>- this._genCardHTML(item, state.bazaarType)).join(""));- if (batch.complete) {+ state.observer?.unobserve(card);+ card.removeAttribute("data-bazaar-index");+ card.outerHTML = this._genCardHTML(state.packages[Number(index)], state.bazaarType);+ state.cursor++;+ if (state.cursor >= state.packages.length) {this._stopBazaarCardWatcher(state);- } else {- this._watchBazaarCardBatch(state);}},+ _fillVisibleBazaarCards(state: IBazaarCardRenderState) {+ if (!this._isBazaarCardRenderCurrent(state)) {+ return;+ }+ const bounds = state.panel.getBoundingClientRect();+ state.cardsElement.querySelectorAll<HTMLElement>("[data-bazaar-index]").forEach((card) => {+ const cardBounds = card.getBoundingClientRect();+ if (cardBounds.bottom >= bounds.top - 640 && cardBounds.top <= bounds.bottom + 640) {+ this._fillBazaarCard(state, card);+ }+ });+ },_setBazaarPanelActive(panel: Element, active: boolean) {this._bazaarCardRenderStates.forEach((state: IBazaarCardRenderState) => {if (state.panel !== panel) {@@ -1794,7 +1801,10 @@ type="checkbox">container.innerHTML = `<div class="b3-cards b3-cards--nowrap"><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul></div>`;return;}- container.innerHTML = '<div class="b3-cards"></div>';+ const batch = getNextBazaarCardBatch(visiblePackages, 0);+ container.innerHTML = `<div class="b3-cards config-bazaar__cards">${visiblePackages.map((item, index) =>+ index < batch.nextCursor ? this._genCardHTML(item, bazaarType) :+ `<div class="b3-card" data-bazaar-index="${index}" aria-hidden="true"></div>`).join("")}</div>`;const panel = container.closest(".config-bazaar__panel") as HTMLElement;const state: IBazaarCardRenderState = {container,@@ -1802,12 +1812,12 @@ type="checkbox">cardsElement: container.firstElementChild as HTMLElement,packages: visiblePackages,bazaarType,- cursor: 0,+ cursor: batch.nextCursor,active: !panel.classList.contains("fn__none"),mount: this._captureMount(),};this._bazaarCardRenderStates.set(container, state);- this._appendBazaarCardBatch(state);+ this._watchBazaarCardBatch(state);},_onBazaar(response: IWebSocketData, bazaarType: TBazaarType, mount: IBazaarMountSnapshot) {if (!bazaar._isBazaarRequestCurrent(bazaarType, mount)) {