Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/10065

Vanessaee7547649693
diff --git a/app/src/card/newCardTab.ts b/app/src/card/newCardTab.ts
index f5971f80bf..8a87dd0b82 100644
--- a/app/src/card/newCardTab.ts
+++ b/app/src/card/newCardTab.ts
@@ -13,12 +13,7 @@ export const newCardModel = (options: {
cardType: TCardType,
id: string,
title?: string
- cardsData?: {
- cards: ICard[],
- unreviewedCount: number
- unreviewedNewCardCount: number
- unreviewedOldCardCount: number
- },
+ cardsData?: ICardData,
index?: number,
}
}) => {
@@ -28,7 +23,7 @@ export const newCardModel = (options: {
type: "siyuan-card",
tab: options.tab,
data: options.data,
- init() {
+ async init() {
if (options.data.cardsData) {
this.element.innerHTML = genCardHTML({
id: this.data.id,
@@ -37,7 +32,7 @@ export const newCardModel = (options: {
isTab: true,
});
- editor = bindCardEvent({
+ editor = await bindCardEvent({
app: options.app,
element: this.element,
id: this.data.id,
@@ -56,7 +51,7 @@ export const newCardModel = (options: {
rootID: this.data.id,
deckID: this.data.id,
notebook: this.data.id,
- }, (response) => {
+ }, async (response) => {
this.element.innerHTML = genCardHTML({
id: this.data.id,
cardType: this.data.cardType,
@@ -64,7 +59,7 @@ export const newCardModel = (options: {
isTab: true,
});
- editor = bindCardEvent({
+ editor = await bindCardEvent({
app: options.app,
element: this.element,
id: this.data.id,
diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts
index 3edc44e68c..bbbedbafd0 100644
--- a/app/src/card/openCard.ts
+++ b/app/src/card/openCard.ts
@@ -30,12 +30,7 @@ const genCardCount = (unreviewedNewCardCount: number, unreviewedOldCardCount: nu
export const genCardHTML = (options: {
id: string,
cardType: TCardType,
- cardsData: {
- cards: ICard[],
- unreviewedCount: number
- unreviewedNewCardCount: number
- unreviewedOldCardCount: number
- },
+ cardsData: ICardData,
isTab: boolean
}) => {
let iconsHTML: string;
@@ -129,24 +124,19 @@ ${window.siyuan.config.flashcard.list ? "card__block--hideli" : ""}" data-type="
</div>`;
};
-export const bindCardEvent = (options: {
+export const bindCardEvent = async (options: {
app: App,
element: Element,
title?: string,
- cardsData: {
- cards: ICard[],
- unreviewedCount: number
- unreviewedNewCardCount: number
- unreviewedOldCardCount: number
- }
+ cardsData: ICardData
cardType: TCardType,
id?: string,
dialog?: Dialog,
index?: number
}) => {
- options.app.plugins.forEach(item => {
- item.eventBus.emit("update-cards", options);
- });
+ for (let i = 0; i < options.app.plugins.length; i++) {
+ options.cardsData = await options.app.plugins[i].updateCards(options.cardsData);
+ }
if (window.siyuan.storage[Constants.LOCAL_FLASHCARD].fullscreen) {
fullscreen(options.element.querySelector(".card__main"),
options.element.querySelector('[data-type="fullscreen"]'));
@@ -199,12 +189,12 @@ export const bindCardEvent = (options: {
rootID: filterElement.getAttribute("data-id"),
deckID: filterElement.getAttribute("data-id"),
notebook: filterElement.getAttribute("data-id"),
- }, (treeCards) => {
+ }, async (treeCards) => {
index = 0;
options.cardsData = treeCards.data;
- options.app.plugins.forEach(item => {
- item.eventBus.emit("update-cards", options);
- });
+ for (let i = 0; i < options.app.plugins.length; i++) {
+ options.cardsData = await options.app.plugins[i].updateCards(options.cardsData);
+ }
if (options.cardsData.cards.length > 0) {
nextCard({
countElement,
@@ -416,12 +406,12 @@ export const bindCardEvent = (options: {
deckID: filterElement.getAttribute("data-id"),
notebook: filterElement.getAttribute("data-id"),
reviewedCards: options.cardsData.cards
- }, (result) => {
+ }, async (result) => {
index = 0;
options.cardsData = result.data;
- options.app.plugins.forEach(item => {
- item.eventBus.emit("update-cards", options);
- });
+ for (let i = 0; i < options.app.plugins.length; i++) {
+ options.cardsData = await options.app.plugins[i].updateCards(options.cardsData);
+ }
if (options.cardsData.cards.length === 0) {
if (options.cardsData.unreviewedCount > 0) {
newRound(countElement, editor, actionElements, result.data.unreviewedCount);
@@ -459,12 +449,7 @@ export const openCard = (app: App) => {
});
};
-export const openCardByData = (app: App, cardsData: {
- cards: ICard[],
- unreviewedCount: number
- unreviewedNewCardCount: number
- unreviewedOldCardCount: number
-}, cardType: TCardType, id?: string, title?: string) => {
+export const openCardByData = async (app: App, cardsData: ICardData, cardType: TCardType, id?: string, title?: string) => {
const exit = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === Constants.DIALOG_OPENCARD) {
item.destroy();
@@ -490,7 +475,7 @@ export const openCardByData = (app: App, cardsData: {
});
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
- const editor = bindCardEvent({
+ const editor = await bindCardEvent({
app,
element: dialog.element,
cardsData,
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index 5dd3d337d8..d508e6dd10 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -88,6 +88,10 @@ export class Plugin {
// 卸载
}
+ public async updateCards(options: ICardData) {
+ return options;
+ }
+
public onLayoutReady() {
// 布局加载完成
}
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 32bd53b99d..3105c2b6f0 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -64,7 +64,6 @@ type TEventBus = "ws-main" | "sync-start" | "sync-end" | "sync-fail" |
"loaded-protyle" | "loaded-protyle-dynamic" | "loaded-protyle-static" |
"switch-protyle" |
"destroy-protyle" |
- "update-cards"|
"lock-screen" |
"mobile-keyboard-show" | "mobile-keyboard-hide"
type TAVCol =
@@ -218,6 +217,13 @@ interface ICard {
nextDues: IObject
}
+interface ICardData {
+ cards: ICard[],
+ unreviewedCount: number
+ unreviewedNewCardCount: number
+ unreviewedOldCardCount: number
+}
+
interface IPluginSettingOption {
title: string
description?: string