diff --git a/app/src/assets/scss/component/_card.scss b/app/src/assets/scss/component/_card.scss index f94e13585..749be8849 100644 --- a/app/src/assets/scss/component/_card.scss +++ b/app/src/assets/scss/component/_card.scss @@ -10,6 +10,12 @@ border: 1px solid var(--b3-theme-surface-lighter); display: flex; + &--wrap { + width: calc(50% - 18px); + margin: 16px 0 0 16px; + min-width: 342px; + } + &:hover { background-color: var(--b3-theme-surface-lighter); transform: translate(0px, -4px); @@ -19,7 +25,7 @@ &s { display: flex; flex-wrap: wrap; - margin: 8px; + margin: 0 16px 16px 0; } &--current .b3-card__info, diff --git a/app/src/config/bazaar.ts b/app/src/config/bazaar.ts index d99fbd3d8..3e60758ac 100644 --- a/app/src/config/bazaar.ts +++ b/app/src/config/bazaar.ts @@ -11,7 +11,7 @@ import * as path from "path"; /// #endif import {isBrowser} from "../util/functions"; import {setStorageVal} from "../protyle/util/compatibility"; -import {hasClosestByClassName} from "../protyle/util/hasClosest"; +import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest"; export const bazaar = { element: undefined as Element, @@ -173,30 +173,39 @@ export const bazaar = { repoHash: item.repoHash, downloaded: false, }; - return `
-
-
- ${item.name} - - - - - ${item.downloads} + return `
+
+
-
- ${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;