mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
4817bc0812
commit
893f645a82
1 changed files with 45 additions and 23 deletions
|
|
@ -293,49 +293,64 @@ export const bazaar = {
|
|||
</div>
|
||||
</div>`;
|
||||
},
|
||||
_genUpdateItemHTML (item: IBazaarItem) {
|
||||
return `<div class="b3-card">
|
||||
_genUpdateItemHTML(item: IBazaarItem, bazaarType: TBazaarType) {
|
||||
const dataObj = {
|
||||
bazaarType,
|
||||
themeMode: item.modes?.toString(),
|
||||
updated: item.updated,
|
||||
name: item.name,
|
||||
repoURL: item.repoURL,
|
||||
repoHash: item.repoHash,
|
||||
downloaded: true
|
||||
};
|
||||
return `<div class="b3-card" data-obj='${JSON.stringify(dataObj)}'>
|
||||
<div class="b3-card__img"><img src="${item.iconURL}" onerror="this.src='/stage/images/icon.png'"/></div>
|
||||
<div class="fn__flex-1 fn__flex-column">
|
||||
<div class="b3-card__info b3-card__info--left fn__flex-1">
|
||||
${item.preferredName} <span class="ft__on-surface ft__smaller">${item.name}</span>
|
||||
<div class="b3-card__desc" title="${escapeAttr(item.preferredDesc) || ""}">${item.preferredDesc || ""}</div>
|
||||
</div>
|
||||
<div class="fn__flex-1 fn__flex-column">
|
||||
<div class="b3-card__info b3-card__info--left fn__flex-1">
|
||||
${item.preferredName} <span class="ft__on-surface ft__smaller">${item.name}</span>
|
||||
<div class="b3-card__desc" title="${escapeAttr(item.preferredDesc) || ""}">${item.preferredDesc || ""}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="b3-card__actions b3-card__actions--right">
|
||||
${item.incompatible ? `<span class="fn__flex-center b3-tooltips b3-tooltips__nw b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""}
|
||||
${item.preferredFunding ? `<span class="fn__space"></span><a target="_blank" href="${item.preferredFunding}" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.sponsor} ${item.preferredFunding}"><svg class="ft__pink"><use xlink:href="#iconHeart"></use></svg></a>` : ""}
|
||||
${item.incompatible ? `<span class="fn__space"></span><span class="fn__flex-center b3-tooltips b3-tooltips__nw b3-chip b3-chip--error b3-chip--small" aria-label="${window.siyuan.languages.incompatiblePluginTip}">${window.siyuan.languages.incompatible}</span>` : ""}
|
||||
${item.preferredFunding ? `<a target="_blank" href="${item.preferredFunding}" class="block__icon block__icon--show ariaLabel" aria-label="${window.siyuan.languages.sponsor} ${item.preferredFunding}"><svg class="ft__pink"><use xlink:href="#iconHeart"></use></svg></a>` : ""}
|
||||
<span class="b3-tooltips b3-tooltips__nw block__icon block__icon--show${isBrowser() ? " fn__none" : ""}" data-type="open" aria-label="${window.siyuan.languages.showInFolder}">
|
||||
<svg><use xlink:href="#iconFolder"></use></svg>
|
||||
</span>
|
||||
<span data-type="install-t" aria-label="${window.siyuan.languages.update}" class="b3-tooltips b3-tooltips__nw block__icon block__icon--show">
|
||||
<svg class="ft__primary"><use xlink:href="#iconRefresh"></use></svg>
|
||||
</span>
|
||||
</div>
|
||||
</div>`
|
||||
</div>`;
|
||||
},
|
||||
_getUpdate() {
|
||||
fetchPost("/api/bazaar/getUpdatedPackage", {frontend: getFrontend()}, (response) => {
|
||||
let html = "";
|
||||
response.data.plugins.forEach((item: IBazaarItem) => {
|
||||
html += this._genUpdateItemHTML(item);
|
||||
html += this._genUpdateItemHTML(item, "plugins");
|
||||
});
|
||||
response.data.themes.forEach((item: IBazaarItem) => {
|
||||
html += this._genUpdateItemHTML(item);
|
||||
html += this._genUpdateItemHTML(item, "themes");
|
||||
});
|
||||
response.data.icons.forEach((item: IBazaarItem) => {
|
||||
html += this._genUpdateItemHTML(item);
|
||||
html += this._genUpdateItemHTML(item, "icons");
|
||||
});
|
||||
response.data.templates.forEach((item: IBazaarItem) => {
|
||||
html += this._genUpdateItemHTML(item);
|
||||
html += this._genUpdateItemHTML(item, "templates");
|
||||
});
|
||||
response.data.widgets.forEach((item: IBazaarItem) => {
|
||||
html += this._genUpdateItemHTML(item);
|
||||
html += this._genUpdateItemHTML(item, "widgets");
|
||||
});
|
||||
this.element.querySelector('[data-type="downloaded-update"]').innerHTML = `<div class="fn__flex config-bazaar__title">
|
||||
<div class="fn__flex-1"></div>
|
||||
<button class="b3-button">${window.siyuan.languages.update}</button>
|
||||
<button class="b3-button" data-type="install-all">${window.siyuan.languages.update}</button>
|
||||
<span class="fn__space"></span>
|
||||
<div class="counter counter--bg fn__flex-center">${response.data.themes.length + response.data.icons.length + response.data.widgets.length + response.data.plugins.length + response.data.templates.length}</div>
|
||||
</div>
|
||||
<div class="config-bazaar__content">${html}</div>`;
|
||||
})
|
||||
},
|
||||
_genMyHTML(bazaarType: TBazaarType, app: App) {
|
||||
_genMyHTML(bazaarType: TBazaarType, app: App, updateUpdate = true) {
|
||||
const contentElement = bazaar.element.querySelector("#configBazaarDownloaded");
|
||||
if (contentElement.getAttribute("data-loading") === "true" ||
|
||||
contentElement.previousElementSibling.querySelector(`[data-type="my${bazaarType.replace(bazaarType[0], bazaarType[0].toUpperCase()).substring(0, bazaarType.length - 1)}"]`).classList.contains("b3-button--outline")) {
|
||||
|
|
@ -430,6 +445,9 @@ export const bazaar = {
|
|||
}
|
||||
contentElement.innerHTML = html ? html : `<div class="fn__hr"></div><ul class="b3-list b3-list--background"><li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li></ul>`;
|
||||
});
|
||||
if (updateUpdate) {
|
||||
this._getUpdate();
|
||||
}
|
||||
},
|
||||
_data: {
|
||||
themes: [] as IBazaarItem[],
|
||||
|
|
@ -578,7 +596,6 @@ export const bazaar = {
|
|||
return;
|
||||
}
|
||||
this._genMyHTML("plugins", app);
|
||||
this._getUpdate();
|
||||
bazaar.element.firstElementChild.addEventListener("click", (event) => {
|
||||
let target = event.target as HTMLElement;
|
||||
const dataElement = hasClosestByAttribute(target, "data-obj", null);
|
||||
|
|
@ -611,7 +628,7 @@ export const bazaar = {
|
|||
}
|
||||
});
|
||||
target.classList.remove("b3-button--outline");
|
||||
this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType, app);
|
||||
this._genMyHTML(type.replace("my", "").toLowerCase() + "s" as TBazaarType, app, false);
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
|
@ -662,7 +679,7 @@ export const bazaar = {
|
|||
}
|
||||
}
|
||||
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
||||
bazaar._genMyHTML(bazaarType, app);
|
||||
bazaar._genMyHTML(bazaarType, app, false);
|
||||
if (bazaarType === "plugins") {
|
||||
if (window.siyuan.config.bazaar.petalDisabled) {
|
||||
confirmDialog(window.siyuan.languages.confirm, window.siyuan.languages.enablePluginTip2);
|
||||
|
|
@ -674,7 +691,7 @@ export const bazaar = {
|
|||
frontend: getFrontend()
|
||||
}, (response) => {
|
||||
loadPlugin(app, response.data);
|
||||
bazaar._genMyHTML(bazaarType, app);
|
||||
bazaar._genMyHTML(bazaarType, app, false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -684,6 +701,11 @@ export const bazaar = {
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (type === "install-all") {
|
||||
fetchPost("/api/bazaar/batchUpdatePackage", {frontend: getFrontend()});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
break;
|
||||
} else if (type === "install-t") {
|
||||
if (!target.classList.contains("b3-button--progress")) {
|
||||
confirmDialog(window.siyuan.languages.update, window.siyuan.languages.exportTplTip, () => {
|
||||
|
|
@ -790,7 +812,7 @@ export const bazaar = {
|
|||
fetchPost("/api/setting/setAppearance", Object.assign({}, window.siyuan.config.appearance, {
|
||||
icon: packageName,
|
||||
}), (appearanceResponse) => {
|
||||
this._genMyHTML(bazaarType, app);
|
||||
this._genMyHTML(bazaarType, app, false);
|
||||
fetchPost("/api/bazaar/getBazaarIcon", {}, response => {
|
||||
response.data.appearance = appearanceResponse.data;
|
||||
bazaar._onBazaar(response, "icons", true);
|
||||
|
|
@ -827,7 +849,7 @@ export const bazaar = {
|
|||
return;
|
||||
}
|
||||
}
|
||||
this._genMyHTML("themes", app);
|
||||
this._genMyHTML("themes", app, false);
|
||||
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
|
||||
response.data.appearance = appearanceResponse.data;
|
||||
bazaar._onBazaar(response, "themes", true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue