+
+
-
- ${item.preferredFunding ? `
` : ""}
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ ${item.name}
+
+
+ ${item.preferredDesc || ""}
+
+
+
+
+
+
+ ${item.downloads}
+
+
+ ${item.preferredFunding ? `
` : ""}
+
+
+
+
+
+
+
+
+
+
+
+
+
`;
},
@@ -379,11 +388,15 @@ export const bazaar = {
this._genMyHTML("themes");
bazaar.element.firstElementChild.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
+ const dataElement = hasClosestByAttribute(target, "data-obj", null);
+ let dataObj:IObject;
+ if (dataElement) {
+ dataObj = JSON.parse(dataElement.getAttribute("data-obj"));
+ }
while (target && !target.isEqualNode(bazaar.element)) {
const type = target.getAttribute("data-type");
- if (type === "open") {
+ if (type === "open" && dataObj) {
/// #if !BROWSER
- const dataObj = JSON.parse(target.parentElement.parentElement.getAttribute("data-obj"));
const dirName = dataObj.bazaarType;
if (dirName === "icons" || dirName === "themes") {
shell.openPath(path.join(window.siyuan.config.system.confDir, "appearance", dirName, dataObj.name));
@@ -414,7 +427,6 @@ export const bazaar = {
break;
} else if (type === "install") {
if (!target.classList.contains("b3-button--progress")) {
- const dataObj = JSON.parse(target.parentElement.parentElement.getAttribute("data-obj"));
const bazaarType = dataObj.bazaarType as TBazaarType;
let url = "/api/bazaar/installBazaarTemplate";
if (bazaarType === "themes") {
@@ -446,8 +458,7 @@ export const bazaar = {
} else if (type === "install-t") {
if (!target.classList.contains("b3-button--progress")) {
confirmDialog(window.siyuan.languages.update, window.siyuan.languages.exportTplTip, () => {
- const dataObj = JSON.parse(target.parentElement.parentElement.getAttribute("data-obj"));
- const bazaarType: TBazaarType = dataObj.bazaarType;
+ const bazaarType = dataObj.bazaarType as TBazaarType;
let url = "/api/bazaar/installBazaarTemplate";
if (bazaarType === "themes") {
url = "/api/bazaar/installBazaarTheme";
@@ -490,8 +501,7 @@ export const bazaar = {
event.stopPropagation();
break;
} else if (type === "uninstall") {
- const dataObj = JSON.parse(target.parentElement.parentElement.getAttribute("data-obj"));
- const bazaarType: TBazaarType = dataObj.bazaarType;
+ const bazaarType = dataObj.bazaarType as TBazaarType;
let url = "/api/bazaar/uninstallBazaarTemplate";
if (bazaarType === "themes") {
url = "/api/bazaar/uninstallBazaarTheme";
@@ -520,8 +530,7 @@ export const bazaar = {
event.stopPropagation();
break;
} else if (type === "switch") {
- const dataObj = JSON.parse(target.parentElement.parentElement.getAttribute("data-obj"));
- const bazaarType: TBazaarType = dataObj.bazaarType;
+ const bazaarType = dataObj.bazaarType as TBazaarType;
const packageName = dataObj.name;
const mode = dataObj.themeMode === "dark" ? 1 : 0;
if (bazaarType === "icons") {
@@ -561,9 +570,8 @@ export const bazaar = {
event.stopPropagation();
break;
} else if (type === "plugin-enable") {
- const itemElement = hasClosestByClassName(target, "b3-card")
+ const itemElement = hasClosestByClassName(target, "b3-card");
if (itemElement) {
- const dataObj = JSON.parse(itemElement.getAttribute("data-obj"));
fetchPost("/api/petal/setPetalEnabled", {
packageName: dataObj.name,
enabled: (target as HTMLInputElement).checked
@@ -574,7 +582,7 @@ export const bazaar = {
event.stopPropagation();
break;
} else if (target.classList.contains("b3-card")) {
- bazaar._renderReadme(target, (JSON.parse(target.getAttribute("data-obj")).bazaarType) as TBazaarType);
+ bazaar._renderReadme(target, (dataObj.bazaarType) as TBazaarType);
event.preventDefault();
event.stopPropagation();
break;