Skip to content

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

:art: 为主题提供样式基础

Vanessab79bc50b4420
diff --git a/app/src/emoji/index.ts b/app/src/emoji/index.ts
index c1a4d9c2b9..d6ddcb229a 100644
--- a/app/src/emoji/index.ts
+++ b/app/src/emoji/index.ts
@@ -422,13 +422,13 @@ const updateFileEmoji = (unicode: string, id: string) => {
/// #if MOBILE
if (window.siyuan.mobileEditor.protyle.block.rootID === id) {
window.siyuan.mobileEditor.protyle.background.ial.icon = unicode;
- window.siyuan.mobileEditor.protyle.background.render(window.siyuan.mobileEditor.protyle.background.ial);
+ window.siyuan.mobileEditor.protyle.background.render(window.siyuan.mobileEditor.protyle.background.ial, window.siyuan.mobileEditor.protyle.block.rootID);
}
/// #else
getAllModels().editor.find(item => {
if (item.editor.protyle.block.rootID === id) {
item.editor.protyle.background.ial.icon = unicode;
- item.editor.protyle.background.render(item.editor.protyle.background.ial);
+ item.editor.protyle.background.render(item.editor.protyle.background.ial, item.editor.protyle.block.rootID);
item.parent.setDocIcon(unicode);
return true;
}
diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts
index b0716b5217..e288bc7e22 100644
--- a/app/src/mobile/util/MobileBackFoward.ts
+++ b/app/src/mobile/util/MobileBackFoward.ts
@@ -36,7 +36,7 @@ const focusStack = (backStack: IBackStack) => {
id: backStack.id,
}, (response) => {
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === "Untitled" ? "" : response.data.name;
- protyle.background.render(response.data.ial);
+ protyle.background.render(response.data.ial, protyle.block.rootID);
protyle.wysiwyg.renderCustom(response.data.ial);
});
}
diff --git a/app/src/protyle/header/Background.ts b/app/src/protyle/header/Background.ts
index 09840ccc9a..5ad2bfc6f2 100644
--- a/app/src/protyle/header/Background.ts
+++ b/app/src/protyle/header/Background.ts
@@ -82,7 +82,7 @@ export class Background {
const response = JSON.parse(responseText);
const style = `background-image:url("${response.data.succMap[Object.keys(response.data.succMap)[0]]}")`;
this.ial["title-img"] = style;
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"title-img": style}
@@ -118,7 +118,7 @@ export class Background {
attrs: {"title-img": style}
});
} else {
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
}
event.preventDefault();
event.stopPropagation();
@@ -207,7 +207,7 @@ export class Background {
];
const style = bgs[getRandom(0, bgs.length - 1)];
this.ial["title-img"] = style;
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"title-img": this.ial["title-img"]}
@@ -217,7 +217,7 @@ export class Background {
break;
} else if (type === "remove") {
delete this.ial["title-img"];
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"title-img": ""}
@@ -229,7 +229,7 @@ export class Background {
const emoji = getRandomEmoji();
if (emoji) {
this.ial.icon = emoji;
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
updateFileTreeEmoji(emoji, protyle.block.rootID);
updateOutlineEmoji(emoji);
fetchPost("/api/attr/setBlockAttrs", {
@@ -267,7 +267,7 @@ export class Background {
btnsElement[1].addEventListener("click", () => {
const style = `background-image:url(${dialog.element.querySelector("input").value});`;
this.ial["title-img"] = style;
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"title-img": this.ial["title-img"]}
@@ -297,7 +297,7 @@ export class Background {
} else {
this.ial.tags = tags.toString();
}
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
event.preventDefault();
event.stopPropagation();
break;
@@ -307,11 +307,13 @@ export class Background {
});
}
- public render(ial: IObject) {
+ public render(ial: IObject, rootId: string) {
const img = ial["title-img"];
const icon = ial.icon;
const tags = ial.tags;
this.ial = ial;
+ // 为主题提供样式基础
+ this.element.setAttribute("data-node-id", rootId);
if (tags) {
let html = "";
tags.split(",").forEach((item, index) => {
@@ -359,7 +361,7 @@ export class Background {
}
}
- private openTag(protyle:IProtyle) {
+ private openTag(protyle: IProtyle) {
fetchPost("/api/search/searchTag", {
k: "",
}, (response) => {
@@ -434,7 +436,7 @@ export class Background {
return tags;
}
- private addTags(tag: string, protyle:IProtyle) {
+ private addTags(tag: string, protyle: IProtyle) {
window.siyuan.menus.menu.remove();
const tags = this.getTags();
if (tags.includes(tag)) {
@@ -442,10 +444,10 @@ export class Background {
}
tags.push(tag);
fetchPost("/api/attr/setBlockAttrs", {
- id:protyle.block.rootID,
+ id: protyle.block.rootID,
attrs: {"tags": tags.toString()}
});
this.ial.tags = tags.toString();
- this.render(this.ial);
+ this.render(this.ial, protyle.block.rootID);
}
}
diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts
index a2c92e2d19..32ae2104ef 100644
--- a/app/src/protyle/header/Title.ts
+++ b/app/src/protyle/header/Title.ts
@@ -332,7 +332,7 @@ ${window.siyuan.languages.createdAt} ${dayjs(response.data.ial.id.substr(0, 14))
return false;
}
setTitle(response.data.ial.title);
- protyle.background.render(response.data.ial);
+ protyle.background.render(response.data.ial, protyle.block.rootID);
protyle.wysiwyg.renderCustom(response.data.ial);
this.editElement.setAttribute("data-render", "true");
this.setTitle(response.data.ial.title);
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index 36fa17493a..7df5dc7cb0 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -96,7 +96,7 @@ export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[]
// 页签没有打开
protyle.title.render(protyle, response, renderTitle);
} else if (protyle.options.render.background) {
- protyle.background.render(response.data.ial);
+ protyle.background.render(response.data.ial, protyle.block.rootID);
protyle.wysiwyg.renderCustom(response.data.ial);
}