487 lines
29 KiB
HTML
487 lines
29 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<style>
|
|
/* the catalog's grid, in the app's look (the kit's tokens) — the public
|
|
site (site/ in this repo) draws the same cards read-only */
|
|
.pc{max-width:1180px;margin:0 auto;padding:16px;display:flex;gap:22px;align-items:flex-start}
|
|
.pc-side{width:196px;flex:none;position:sticky;top:12px}
|
|
.pc-side h4{font:500 11px/1 var(--aia-font);color:hsl(var(--muted-foreground));margin:0 0 8px 10px}
|
|
.pc-side button{display:flex;width:100%;align-items:center;gap:8px;padding:7px 10px;border:0;border-radius:8px;background:none;color:hsl(var(--muted-foreground));font:13px/1.2 var(--aia-font);text-align:left;cursor:pointer}
|
|
.pc-side button:hover{background:hsl(var(--accent)/.5);color:hsl(var(--foreground))}
|
|
.pc-side button[aria-current=true]{background:hsl(var(--accent));color:hsl(var(--foreground));font-weight:600}
|
|
.pc-side .n{margin-left:auto;font-size:11.5px;opacity:.7;font-variant-numeric:tabular-nums}
|
|
.pc-main{flex:1;min-width:0}
|
|
.pc-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:12px}
|
|
.pc-search{position:relative;flex:1;min-width:12rem}
|
|
.pc-search input{width:100%;height:34px;padding-left:30px}
|
|
.pc-search svg{position:absolute;left:9px;top:50%;transform:translateY(-50%);width:14px;height:14px;color:hsl(var(--muted-foreground))}
|
|
.pc-chips{display:none;gap:6px;overflow-x:auto;margin:0 -16px 12px;padding:0 16px;scrollbar-width:none}
|
|
.pc-chips button{flex:none;display:flex;gap:6px;align-items:center;height:28px;padding:0 12px;border:1px solid hsl(var(--border));border-radius:999px;background:none;color:hsl(var(--muted-foreground));font:12px/1 var(--aia-font);cursor:pointer;white-space:nowrap}
|
|
.pc-chips button[aria-pressed=true]{border-color:hsl(var(--primary)/.5);background:hsl(var(--primary)/.1);color:hsl(var(--primary))}
|
|
.pc-count{font-size:12px;color:hsl(var(--muted-foreground));border-top:1px solid hsl(var(--border));padding:10px 2px 0;margin:0 0 10px}
|
|
.pc-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(15rem,1fr));gap:12px}
|
|
.pc-card{display:flex;flex-direction:column;border:1px solid hsl(var(--border));border-radius:12px;background:hsl(var(--card));overflow:hidden;cursor:pointer;transition:border-color .15s,box-shadow .15s;min-width:0}
|
|
.pc-card:hover{border-color:hsl(var(--primary)/.5);box-shadow:0 4px 14px hsl(var(--foreground)/.06)}
|
|
.pc-banner{aspect-ratio:16/8;background:linear-gradient(135deg,var(--c,#64748b) 0%,color-mix(in srgb,var(--c,#64748b) 55%,#fff) 100%);background-size:cover;background-position:center;opacity:.95}
|
|
.pc-banner.has{background-image:var(--img)}
|
|
.pc-body{position:relative;padding:30px 12px 12px;display:flex;flex-direction:column;gap:4px;flex:1}
|
|
.pc-tile{position:absolute;top:-20px;left:12px;width:40px;height:40px;border-radius:10px;background:var(--c,#64748b);box-shadow:0 0 0 4px hsl(var(--card));display:grid;place-items:center}
|
|
.pc-tile i{width:22px;height:22px;background:#fff;-webkit-mask:var(--m) center/contain no-repeat;mask:var(--m) center/contain no-repeat}
|
|
.pc-tile b{color:#fff;font:600 16px/1 var(--aia-font)}
|
|
.pc-pills{position:absolute;top:8px;right:12px;display:flex;gap:4px;flex-wrap:wrap;justify-content:flex-end}
|
|
.pill{border-radius:999px;padding:2px 8px;font:500 10.5px/1.4 var(--aia-font);white-space:nowrap}
|
|
.pill.live{background:rgba(16,185,129,.15);color:#059669}
|
|
.pill.warn{background:rgba(245,158,11,.15);color:#b45309}
|
|
.pill.info{background:rgba(14,165,233,.15);color:#0284c7}
|
|
.pill.off{background:hsl(var(--muted));color:hsl(var(--muted-foreground))}
|
|
.dark .pill.live{color:#34d399}.dark .pill.warn{color:#fbbf24}.dark .pill.info{color:#38bdf8}
|
|
.pc-name{font-weight:600;font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
.pc-meta{font-size:11px;color:hsl(var(--muted-foreground));overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
.pc-desc{font-size:12px;color:hsl(var(--muted-foreground));display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;margin:0}
|
|
.pc-foot{display:flex;gap:6px;align-items:center;margin-top:auto;padding-top:8px;flex-wrap:wrap}
|
|
.pc-foot .note{font-size:11px;color:hsl(var(--muted-foreground));flex:1;min-width:0}
|
|
.pc-note{display:flex;gap:10px;align-items:center;border:1px solid hsl(var(--border));border-radius:10px;padding:10px 12px;margin-bottom:12px;font-size:12.5px}
|
|
.pc-note.warn{border-color:rgba(245,158,11,.45);background:rgba(245,158,11,.07)}
|
|
.pc-note.err{border-color:hsl(var(--destructive)/.45);background:hsl(var(--destructive)/.06)}
|
|
.pc-note p{margin:0;flex:1}
|
|
.pc-skel{border:1px solid hsl(var(--border));border-radius:12px;height:230px;background:linear-gradient(90deg,hsl(var(--muted)/.5),hsl(var(--muted)),hsl(var(--muted)/.5));background-size:200% 100%;animation:sk 1.4s infinite}
|
|
@keyframes sk{to{background-position:-200% 0}}
|
|
/* detail */
|
|
.pd{max-width:860px;margin:0 auto;padding:16px}
|
|
.pd-back{margin-bottom:12px}
|
|
.pd-hero{border-radius:14px;overflow:hidden;border:1px solid hsl(var(--border));background:hsl(var(--card))}
|
|
.pd-hero .pc-banner{aspect-ratio:16/6}
|
|
.pd-head{position:relative;padding:34px 16px 16px;display:flex;gap:12px;align-items:flex-end;flex-wrap:wrap}
|
|
.pd-head .pc-tile{top:-28px;left:16px;width:56px;height:56px;border-radius:14px}
|
|
.pd-head .pc-tile i{width:30px;height:30px}
|
|
.pd-title{flex:1;min-width:12rem}
|
|
.pd-title h1{font-size:20px;margin:0 0 2px}
|
|
.pd-sec{margin-top:18px}
|
|
.pd-sec h3{font-size:11px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:hsl(var(--muted-foreground));margin:0 0 8px}
|
|
.pd-list{margin:0;padding-left:18px;font-size:13px;line-height:1.6}
|
|
.pd-src{display:flex;gap:8px;align-items:center;font-family:var(--aia-mono);font-size:11.5px;word-break:break-all;background:hsl(var(--muted)/.5);border-radius:8px;padding:8px 10px}
|
|
.pd-src span{flex:1}
|
|
.md{font-size:13.5px;line-height:1.6}
|
|
.md h1,.md h2,.md h3{font-size:15px;margin:16px 0 6px}
|
|
.md p{margin:0 0 10px}.md ul,.md ol{margin:0 0 10px;padding-left:20px}
|
|
.md code{font-family:var(--aia-mono);font-size:12px;background:hsl(var(--muted));border-radius:4px;padding:1px 4px}
|
|
.md pre{background:hsl(var(--muted));border-radius:8px;padding:10px;overflow:auto}.md pre code{background:none;padding:0}
|
|
.md a{color:hsl(var(--primary))}
|
|
.tags{display:flex;gap:6px;flex-wrap:wrap}
|
|
.tag{font:500 11px/1 var(--aia-mono);border:1px solid hsl(var(--border));border-radius:6px;padding:4px 7px}
|
|
a.req{color:hsl(var(--primary));cursor:pointer;text-decoration:underline;text-underline-offset:2px}
|
|
@media (max-width:899px){.pc-side{display:none}.pc-chips{display:flex}}
|
|
@media (max-width:520px){.pc-bar .aia-seg{width:100%}.pc-bar .aia-seg>button{flex:1}.pc{padding:12px}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="root"></div>
|
|
<script>
|
|
(function () {
|
|
"use strict";
|
|
var A = window.aiAgentPlugin;
|
|
var init = (A && A.init) || {};
|
|
var FR = init.lang === "fr";
|
|
function L(en, fr) { return FR ? fr : en; }
|
|
var CATS = [
|
|
["dev", "Dev and code", "Dev et code"], ["data", "Data and costs", "Données et coûts"],
|
|
["agents", "Agents and context", "Agents et contexte"], ["chat", "Chat and mail", "Messagerie et mail"],
|
|
["scheduling", "Scheduling", "Planification"], ["media", "Media and fun", "Médias et loisirs"],
|
|
["other", "Other", "Autre"], ["providers", "Providers", "Fournisseurs"],
|
|
["harnesses", "Harnesses", "Harness"], ["translations", "Translations", "Traductions"]
|
|
];
|
|
var CAT_LABEL = {}; CATS.forEach(function (c) { CAT_LABEL[c[0]] = L(c[1], c[2]); });
|
|
var SELF = (A && A.id) || "plugin-catalog";
|
|
|
|
var q0 = init.query || {};
|
|
var S = {
|
|
cat: CAT_LABEL[q0.cat] ? q0.cat : "all",
|
|
show: q0.show === "installed" || q0.show === "available" ? q0.show : "all",
|
|
search: typeof q0.q === "string" ? q0.q : "",
|
|
detail: typeof q0.plugin === "string" ? q0.plugin : null,
|
|
data: null, meta: null,
|
|
installed: null, listError: "", busy: {}
|
|
};
|
|
var art = {}; // path → data URL | "pending" | "failed"
|
|
var root = document.getElementById("root");
|
|
|
|
function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return "&#" + c.charCodeAt(0) + ";"; }); }
|
|
|
|
// ── markdown (README) — a small subset, escaped first; keep in step with site/app.js
|
|
function inline(s) {
|
|
return s
|
|
.replace(/`([^`]+)`/g, "<code>$1</code>")
|
|
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
.replace(/(^|[\s(])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>")
|
|
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
}
|
|
function md(text) {
|
|
var lines = esc(text || "").split("\n"), out = [], list = null, para = [], code = null;
|
|
function flush() { if (para.length) { out.push("<p>" + inline(para.join(" ")) + "</p>"); para = []; } }
|
|
function endList() { if (list) { out.push("</" + list + ">"); list = null; } }
|
|
lines.forEach(function (ln) {
|
|
if (code !== null) {
|
|
if (/^```/.test(ln)) { out.push("<pre><code>" + code.join("\n") + "</code></pre>"); code = null; }
|
|
else code.push(ln);
|
|
return;
|
|
}
|
|
if (/^```/.test(ln)) { flush(); endList(); code = []; return; }
|
|
var h = /^(#{1,4})\s+(.*)$/.exec(ln);
|
|
if (h) { flush(); endList(); out.push("<h3>" + inline(h[2]) + "</h3>"); return; }
|
|
var li = /^\s*(?:[-*]|(\d+)\.)\s+(.*)$/.exec(ln);
|
|
if (li) {
|
|
flush();
|
|
var tag = li[1] ? "ol" : "ul";
|
|
if (list !== tag) { endList(); out.push("<" + tag + ">"); list = tag; }
|
|
out.push("<li>" + inline(li[2]) + "</li>");
|
|
return;
|
|
}
|
|
if (!ln.trim()) { flush(); endList(); return; }
|
|
if (list && /^\s+\S/.test(ln)) { out[out.length - 1] = out[out.length - 1].replace(/<\/li>$/, " " + inline(ln.trim()) + "</li>"); return; }
|
|
endList();
|
|
para.push(ln.trim());
|
|
});
|
|
if (code !== null) out.push("<pre><code>" + code.join("\n") + "</code></pre>");
|
|
flush(); endList();
|
|
return out.join("");
|
|
}
|
|
|
|
function cmpVer(a, b) {
|
|
var x = String(a || "").split(/[.-]/), y = String(b || "").split(/[.-]/);
|
|
for (var i = 0; i < Math.max(x.length, y.length); i++) {
|
|
var m = parseInt(x[i] || "0", 10), n = parseInt(y[i] || "0", 10);
|
|
if (isNaN(m) || isNaN(n)) { if ((x[i] || "") !== (y[i] || "")) return (x[i] || "") < (y[i] || "") ? -1 : 1; continue; }
|
|
if (m !== n) return m < n ? -1 : 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// ── what is installed (the host's bridge; owner + plugins.manage only)
|
|
function refreshInstalled() {
|
|
if (!A || !A.plugins) { S.listError = L("This hub is too old to install plugins from here — update the ai-agent.", "Ce hub est trop ancien pour installer des plugins d'ici — mets l'ai-agent à jour."); render(); return Promise.resolve(); }
|
|
return A.plugins.list().then(function (r) {
|
|
var m = {};
|
|
(r && r.installed || []).forEach(function (p) { m[p.id] = p; });
|
|
S.installed = m; S.repo = r && r.catalogRepo; S.listError = "";
|
|
render();
|
|
}, function (e) { S.listError = String(e && e.message || e); S.installed = {}; render(); });
|
|
}
|
|
|
|
// ── pictures: fetched through the plugin's own action, as they scroll in
|
|
function loadArt(path) {
|
|
if (!path || art[path]) return;
|
|
art[path] = "pending";
|
|
A.action("art", { path: path }).then(function (r) {
|
|
art[path] = r && r.dataUrl || "failed";
|
|
paintArt(path);
|
|
}, function () { art[path] = "failed"; });
|
|
}
|
|
function paintArt(path) {
|
|
var url = art[path];
|
|
if (!url || url === "pending" || url === "failed") return;
|
|
document.querySelectorAll('[data-art="' + path + '"]').forEach(function (el) {
|
|
if (el.dataset.mask) { el.style.setProperty("--m", 'url("' + url + '")'); }
|
|
else { el.style.setProperty("--img", 'url("' + url + '")'); el.classList.add("has"); }
|
|
});
|
|
}
|
|
var io = "IntersectionObserver" in window ? new IntersectionObserver(function (es) {
|
|
es.forEach(function (e) { if (e.isIntersecting) { io.unobserve(e.target); loadArt(e.target.dataset.art); } });
|
|
}, { rootMargin: "300px" }) : null;
|
|
function wireArt() {
|
|
document.querySelectorAll("[data-art]").forEach(function (el) {
|
|
var p = el.dataset.art;
|
|
if (art[p] && art[p] !== "pending") paintArt(p);
|
|
else if (io) io.observe(el); else loadArt(p);
|
|
});
|
|
}
|
|
|
|
// ── a plugin's state against what is installed here
|
|
function stateOf(p) {
|
|
var mine = S.installed && S.installed[p.id];
|
|
if (!mine) return { installed: false };
|
|
var diff = cmpVer(mine.version, p.version);
|
|
return { installed: true, mine: mine, newer: diff < 0, older: diff > 0, local: !mine.fromCatalog };
|
|
}
|
|
function missingReqs(p) {
|
|
if (!S.installed) return [];
|
|
return (p.requires || []).filter(function (r) { return !S.installed[r] || !S.installed[r].enabled; });
|
|
}
|
|
function nameOf(id) {
|
|
var p = (S.data && S.data.catalog && S.data.catalog.plugins || []).filter(function (x) { return x.id === id; })[0];
|
|
return p ? p.name : id;
|
|
}
|
|
|
|
function pills(p, st) {
|
|
var out = [];
|
|
if (st.installed) {
|
|
if (st.mine.needsApproval) out.push(["warn", L("Needs re-approval", "À réapprouver")]);
|
|
else if (!st.mine.enabled) out.push(["off", L("Disabled", "Désactivé")]);
|
|
else out.push(["live", L("Installed", "Installé")]);
|
|
if (st.newer) out.push(["info", L("Update", "Mise à jour")]);
|
|
} else if (p.seed) out.push(["off", L("Comes with the app", "Fourni avec l'appli")]);
|
|
return out.map(function (x) { return '<span class="pill ' + x[0] + '">' + esc(x[1]) + "</span>"; }).join("");
|
|
}
|
|
function tile(p) {
|
|
var c = p.color || "#64748b";
|
|
var inner = p.iconSvg ? '<i data-mask="1" data-art="' + esc(p.iconSvg) + '"></i>' : "<b>" + esc((p.name || p.id).charAt(0).toUpperCase()) + "</b>";
|
|
return '<span class="pc-tile" style="--c:' + esc(c) + '">' + inner + "</span>";
|
|
}
|
|
function banner(p) {
|
|
return '<div class="pc-banner"' + (p.illustration ? ' data-art="' + esc(p.illustration) + '"' : "") +
|
|
' style="--c:' + esc(p.color || "#64748b") + '"></div>';
|
|
}
|
|
function metaLine(p) {
|
|
return [p.author, CAT_LABEL[p.category] || ""].filter(Boolean).map(esc).join(" · ");
|
|
}
|
|
|
|
// the buttons of a card / the detail page
|
|
function actions(p, big) {
|
|
var st = stateOf(p), busy = S.busy[p.id], sm = big ? "" : " aia-btn-sm";
|
|
if (S.listError || !S.installed) return "";
|
|
var miss = missingReqs(p);
|
|
if (busy) return '<button class="aia-btn' + sm + '" disabled>' + esc(busy) + "…</button>";
|
|
if (!st.installed) {
|
|
var dis = miss.length ? ' disabled title="' + esc(L("Install first: ", "À installer d'abord : ") + miss.map(nameOf).join(", ")) + '"' : "";
|
|
return '<button class="aia-btn aia-btn-primary' + sm + '" data-do="install" data-id="' + esc(p.id) + '"' + dis + ">" + esc(L("Install", "Installer")) + "</button>";
|
|
}
|
|
var h = "";
|
|
if (st.newer) {
|
|
// a newer catalog version (or one replacing a local checkout's older copy)
|
|
h += '<button class="aia-btn aia-btn-primary' + sm + '" data-do="install" data-id="' + esc(p.id) + '" title="' +
|
|
esc(L("Install the catalog's v", "Installer la v") + p.version + L("", " du catalogue")) + '">' + esc(L("Update", "Mettre à jour")) + "</button>";
|
|
} else if (big && st.local) {
|
|
// the detail page only: swap a local checkout's copy for the catalog's
|
|
h += '<button class="aia-btn" data-do="install" data-id="' + esc(p.id) + '">' + esc(L("Install the catalog's copy", "Installer la copie du catalogue")) + "</button>";
|
|
}
|
|
if (p.id !== SELF) {
|
|
h += '<button class="aia-btn aia-btn-danger' + sm + '" data-do="uninstall" data-id="' + esc(p.id) + '">' + esc(L("Uninstall", "Désinstaller")) + "</button>";
|
|
}
|
|
return h;
|
|
}
|
|
function footNote(p) {
|
|
var st = stateOf(p), bits = [];
|
|
if (st.installed && st.newer) bits.push("v" + st.mine.version + " → v" + p.version);
|
|
else if (st.installed && st.older) bits.push("v" + st.mine.version + L(" (newer than the catalog)", " (plus récente que le catalogue)"));
|
|
if (st.installed && st.local) bits.push(L("local copy", "copie locale"));
|
|
var miss = !st.installed ? missingReqs(p) : [];
|
|
if (miss.length) bits.push(L("needs ", "il faut ") + miss.map(nameOf).join(", "));
|
|
return bits.length ? '<span class="note">' + esc(bits.join(" · ")) + "</span>" : '<span class="note"></span>';
|
|
}
|
|
|
|
// ── filters
|
|
function filtered() {
|
|
var all = S.data && S.data.catalog ? S.data.catalog.plugins : [];
|
|
var n = S.search.trim().toLowerCase();
|
|
var searched = all.filter(function (p) {
|
|
return !n || [p.name, p.description, p.id, p.author].some(function (f) { return String(f || "").toLowerCase().indexOf(n) >= 0; });
|
|
});
|
|
function inShow(p, show) { var i = stateOf(p).installed; return show === "all" || (show === "installed") === i; }
|
|
function inCat(p, cat) { return cat === "all" || p.category === cat; }
|
|
var counts = {
|
|
all: searched.filter(function (p) { return inCat(p, S.cat); }).length,
|
|
installed: searched.filter(function (p) { return inCat(p, S.cat) && inShow(p, "installed"); }).length,
|
|
available: searched.filter(function (p) { return inCat(p, S.cat) && inShow(p, "available"); }).length
|
|
};
|
|
var forCats = searched.filter(function (p) { return inShow(p, S.show); });
|
|
var cats = [{ id: "all", label: L("All", "Tout"), n: forCats.length }].concat(CATS.map(function (c) {
|
|
return { id: c[0], label: CAT_LABEL[c[0]], n: forCats.filter(function (p) { return p.category === c[0]; }).length };
|
|
}).filter(function (c) { return c.n > 0 || c.id === S.cat; }));
|
|
var shown = forCats.filter(function (p) { return inCat(p, S.cat); }).sort(function (a, b) {
|
|
var x = stateOf(a).installed, y = stateOf(b).installed;
|
|
return (S.show === "all" && x !== y) ? (x ? -1 : 1) : a.name.localeCompare(b.name);
|
|
});
|
|
return { shown: shown, counts: counts, cats: cats };
|
|
}
|
|
|
|
function route(replace) {
|
|
var query = {};
|
|
if (S.cat !== "all") query.cat = S.cat;
|
|
if (S.show !== "all") query.show = S.show;
|
|
if (S.search.trim()) query.q = S.search.trim();
|
|
if (S.detail) query.plugin = S.detail;
|
|
if (A && A.setRoute) A.setRoute({ query: query }, { replace: !!replace });
|
|
}
|
|
|
|
var SEARCH_SVG = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></svg>';
|
|
|
|
function notes() {
|
|
var d = S.data, h = "";
|
|
if (d && d.error && d.catalog) {
|
|
h += '<div class="pc-note warn"><p>' + esc(L("The catalog site can't be reached — showing the copy from ", "Le site du catalogue est injoignable — copie du ") +
|
|
(d.fetchedAt ? new Date(d.fetchedAt * 1000).toLocaleString(FR ? "fr-FR" : undefined) : "?") + ". " + d.error) +
|
|
'</p><button class="aia-btn aia-btn-sm" data-do="retry">' + esc(L("Retry", "Réessayer")) + "</button></div>";
|
|
}
|
|
if (S.listError) h += '<div class="pc-note err"><p>' + esc(S.listError) + "</p></div>";
|
|
return h;
|
|
}
|
|
|
|
function renderGrid() {
|
|
var d = S.data;
|
|
if (!d) {
|
|
return '<div class="pc"><div class="pc-main"><div class="pc-grid">' + new Array(7).join('<div class="pc-skel"></div>') + "</div></div></div>";
|
|
}
|
|
if (!d.catalog) {
|
|
return '<div class="pc"><div class="pc-main"><div class="pc-note err"><p><strong>' + esc(L("The catalog can't be reached.", "Le catalogue est injoignable.")) +
|
|
"</strong> " + esc(d.error || "") + " (" + esc(d.url || "") + ')</p><button class="aia-btn aia-btn-sm" data-do="retry">' +
|
|
esc(L("Retry", "Réessayer")) + "</button></div></div></div>";
|
|
}
|
|
var f = filtered();
|
|
var side = '<nav class="pc-side" aria-label="' + esc(L("Category", "Catégorie")) + '"><h4>' + esc(L("Category", "Catégorie")) + "</h4>" +
|
|
f.cats.map(function (c) {
|
|
return '<button data-cat="' + c.id + '" aria-current="' + (c.id === S.cat) + '"><span>' + esc(c.label) + '</span><span class="n">' + c.n + "</span></button>";
|
|
}).join("") + "</nav>";
|
|
var chips = '<div class="pc-chips">' + f.cats.map(function (c) {
|
|
return '<button data-cat="' + c.id + '" aria-pressed="' + (c.id === S.cat) + '">' + esc(c.label) + ' <span style="opacity:.7">' + c.n + "</span></button>";
|
|
}).join("") + "</div>";
|
|
var seg = '<div class="aia-seg" role="group">' + [["all", L("All", "Tout")], ["installed", L("Installed", "Installés")], ["available", L("Available", "Disponibles")]].map(function (s) {
|
|
return '<button data-show="' + s[0] + '" aria-pressed="' + (S.show === s[0]) + '">' + esc(s[1]) + ' <span style="opacity:.6">' + f.counts[s[0]] + "</span></button>";
|
|
}).join("") + "</div>";
|
|
var bar = '<div class="pc-bar"><label class="pc-search">' + SEARCH_SVG +
|
|
'<input class="aia-input" type="search" id="q" placeholder="' + esc(L("Search plugins", "Chercher un plugin")) + '" value="' + esc(S.search) + '"></label>' + seg + "</div>";
|
|
var cards = f.shown.length ? '<div class="pc-grid">' + f.shown.map(function (p) {
|
|
return '<div class="pc-card" data-open="' + esc(p.id) + '" tabindex="0" role="link" aria-label="' + esc(p.name) + '">' + banner(p) +
|
|
'<div class="pc-body">' + tile(p) + '<div class="pc-pills">' + pills(p, stateOf(p)) + "</div>" +
|
|
'<span class="pc-name">' + esc(p.name) + '</span><span class="pc-meta">' + metaLine(p) + "</span>" +
|
|
'<p class="pc-desc">' + esc(p.description) + '</p><div class="pc-foot">' + footNote(p) + actions(p, false) + "</div></div></div>";
|
|
}).join("") + "</div>" : '<div class="aia-empty">' + esc(S.search ? L("No plugin matches.", "Aucun plugin ne correspond.") :
|
|
S.show === "available" ? L("Everything here is installed.", "Tout est déjà installé ici.") : L("Nothing in this category yet.", "Rien dans cette catégorie pour l'instant.")) + "</div>";
|
|
return '<div class="pc">' + side + '<div class="pc-main">' + notes() + bar + chips +
|
|
'<p class="pc-count">' + f.shown.length + " " + esc(f.shown.length === 1 ? "plugin" : "plugins") + "</p>" + cards + "</div></div>";
|
|
}
|
|
|
|
function renderDetail(p) {
|
|
var st = stateOf(p);
|
|
var sec = function (title, body) { return body ? '<div class="pd-sec"><h3>' + esc(title) + "</h3>" + body + "</div>" : ""; };
|
|
var reqs = (p.requires || []).map(function (r) {
|
|
var ok = S.installed && S.installed[r] && S.installed[r].enabled;
|
|
return '<a class="req" data-open="' + esc(r) + '">' + esc(nameOf(r)) + "</a>" + (ok ? " ✓" : "");
|
|
}).join(", ");
|
|
var site = S.data && S.data.siteUrl;
|
|
return '<div class="pd">' +
|
|
'<button class="aia-btn aia-btn-sm aia-btn-ghost pd-back" data-do="back">← ' + esc(L("All plugins", "Tous les plugins")) + "</button>" +
|
|
notes() +
|
|
'<div class="pd-hero">' + banner(p) + '<div class="pd-head">' + tile(p) +
|
|
'<div class="pd-title"><h1>' + esc(p.name) + '</h1><div class="pc-meta">' + metaLine(p) + " · v" + esc(p.version) + "</div>" +
|
|
'<div class="pc-foot" style="padding-top:2px">' + footNote(p) + "</div></div>" +
|
|
'<div class="pc-pills" style="position:static">' + pills(p, st) + "</div>" +
|
|
'<div class="aia-row">' + actions(p, true) + "</div></div></div>" +
|
|
'<p style="font-size:14px;margin:12px 0 0">' + esc(p.description) + "</p>" +
|
|
sec(L("About", "À propos"), p.readme ? '<div class="md">' + md(p.readme) + "</div>" : "") +
|
|
sec(L("What it declares", "Ce qu'il déclare"), (p.declares || []).length ? '<ul class="pd-list">' + p.declares.map(function (x) { return "<li>" + inline(esc(x)) + "</li>"; }).join("") + "</ul>" : "") +
|
|
sec(L("Hub capabilities it asks for", "Accès au hub demandés"), (p.capabilities || []).length ? '<div class="tags">' + p.capabilities.map(function (c) { return '<span class="tag">' + esc(c) + "</span>"; }).join("") + '</div><p class="aia-small aia-muted" style="margin:6px 0 0">' +
|
|
esc(L("The app lists exactly what each one allows before you install.", "L'appli détaille ce que chacun permet avant l'installation.")) + "</p>" : "") +
|
|
sec(L("Needs", "Nécessite"), reqs ? '<p style="margin:0">' + reqs + "</p>" : "") +
|
|
sec(L("Runs on its own", "Tourne tout seul"), (p.schedules || []).length ? '<ul class="pd-list">' + p.schedules.map(function (s) { return "<li><code>" + esc(s.cron) + "</code> " + esc(s.description || s.id) + "</li>"; }).join("") + "</ul>" : "") +
|
|
sec(L("Source", "Source"), '<div class="pd-src"><span>' + esc(p.source) + '</span><button class="aia-btn aia-btn-sm" data-do="copy" data-text="' + esc(p.source) + '">' + esc(L("Copy", "Copier")) + "</button></div>" +
|
|
(site ? '<p class="aia-small" style="margin:8px 0 0"><a class="req" href="' + esc(site + "?plugin=" + encodeURIComponent(p.id)) + '" target="_blank" rel="noopener noreferrer">' + esc(L("On the public site ↗", "Sur le site public ↗")) + "</a></p>" : "")) +
|
|
"</div>";
|
|
}
|
|
|
|
var lastFocus = null;
|
|
function render() {
|
|
var active = document.activeElement && document.activeElement.id === "q";
|
|
var pos = active ? document.activeElement.selectionStart : null;
|
|
var p = S.detail && S.data && S.data.catalog && S.data.catalog.plugins.filter(function (x) { return x.id === S.detail; })[0];
|
|
root.innerHTML = '<div class="aia-page" style="max-width:none;padding:0">' + (p ? renderDetail(p) : renderGrid()) + "</div>";
|
|
if (active) { var el = document.getElementById("q"); if (el) { el.focus(); try { el.setSelectionRange(pos, pos); } catch (e) {} } }
|
|
wireArt();
|
|
header();
|
|
resize();
|
|
}
|
|
function resize() { if (A && A.resize) A.resize(Math.ceil(document.documentElement.scrollHeight)); }
|
|
if ("ResizeObserver" in window) new ResizeObserver(resize).observe(root);
|
|
|
|
function header() {
|
|
if (!A || !A.setHeader) return;
|
|
var n = S.data && S.data.catalog ? S.data.catalog.plugins.length : null;
|
|
var mine = S.installed ? Object.keys(S.installed).length : null;
|
|
A.setHeader({
|
|
subtitle: n == null ? "" : n + " " + L("plugins in the catalog", "plugins au catalogue") + (mine == null ? "" : " · " + mine + " " + L("installed here", "installés ici")),
|
|
actions: S.data && S.data.siteUrl ? [{ id: "site", label: L("Public site", "Site public"), icon: "external-link" }] : [],
|
|
refresh: true
|
|
});
|
|
}
|
|
|
|
// ── doing things: the host confirms, then we re-read what is installed
|
|
function doInstall(id) {
|
|
var p = S.data.catalog.plugins.filter(function (x) { return x.id === id; })[0];
|
|
if (!p) return;
|
|
S.busy[id] = L("Waiting for you", "En attente"); render();
|
|
A.plugins.install({ source: p.source }).then(function (r) {
|
|
delete S.busy[id];
|
|
if (r && r.ok) A.toast && A.toast(L("Installed ", "Installé : ") + p.name + " v" + (r.version || p.version), "success");
|
|
return refreshInstalled();
|
|
}, function (e) {
|
|
delete S.busy[id]; render();
|
|
A.toast && A.toast(String(e && e.message || e), "error");
|
|
});
|
|
}
|
|
function doUninstall(id) {
|
|
S.busy[id] = L("Waiting for you", "En attente"); render();
|
|
A.plugins.uninstall({ id: id }).then(function (r) {
|
|
delete S.busy[id];
|
|
if (r && r.ok) A.toast && A.toast(L("Uninstalled ", "Désinstallé : ") + nameOf(id) + (r.purged ? L(", its data deleted", ", données supprimées") : ""), "success");
|
|
return refreshInstalled();
|
|
}, function (e) {
|
|
delete S.busy[id]; render();
|
|
A.toast && A.toast(String(e && e.message || e), "error");
|
|
});
|
|
}
|
|
|
|
var handle = null;
|
|
root.addEventListener("click", function (e) {
|
|
var t = e.target.closest ? e.target.closest("[data-do],[data-cat],[data-show],[data-open]") : null;
|
|
if (!t) return;
|
|
if (t.dataset.do) {
|
|
e.stopPropagation();
|
|
var d = t.dataset.do;
|
|
if (d === "install") doInstall(t.dataset.id);
|
|
else if (d === "uninstall") doUninstall(t.dataset.id);
|
|
else if (d === "retry") { if (handle) handle.refresh(); refreshInstalled(); }
|
|
else if (d === "back") { S.detail = null; route(false); render(); window.scrollTo(0, 0); }
|
|
else if (d === "copy") { A.copy(t.dataset.text).then(function () { A.toast(L("Copied", "Copié"), "success"); }); }
|
|
return;
|
|
}
|
|
if (t.dataset.cat) { S.cat = t.dataset.cat; route(true); render(); return; }
|
|
if (t.dataset.show) { S.show = t.dataset.show; route(true); render(); return; }
|
|
if (t.dataset.open) { S.detail = t.dataset.open; route(false); render(); window.scrollTo(0, 0); }
|
|
});
|
|
root.addEventListener("keydown", function (e) {
|
|
if (e.key === "Enter" && e.target.dataset && e.target.dataset.open) { S.detail = e.target.dataset.open; route(false); render(); }
|
|
});
|
|
var typing = null;
|
|
root.addEventListener("input", function (e) {
|
|
if (e.target.id !== "q") return;
|
|
S.search = e.target.value; render();
|
|
clearTimeout(typing); typing = setTimeout(function () { route(true); }, 400);
|
|
});
|
|
|
|
if (!A) { root.textContent = "aiAgentPlugin missing"; return; }
|
|
A.onRoute && A.onRoute(function (r) {
|
|
var q = (r && r.query) || {};
|
|
S.cat = CAT_LABEL[q.cat] ? q.cat : "all";
|
|
S.show = q.show === "installed" || q.show === "available" ? q.show : "all";
|
|
S.search = typeof q.q === "string" ? q.q : "";
|
|
S.detail = typeof q.plugin === "string" ? q.plugin : null;
|
|
render();
|
|
});
|
|
A.onHeaderAction && A.onHeaderAction(function (id) {
|
|
if (id === "site" && S.data && S.data.siteUrl) window.open(S.data.siteUrl, "_blank", "noopener");
|
|
});
|
|
A.onRefresh && A.onRefresh(function () { refreshInstalled(); });
|
|
A.onTheme && A.onTheme(function () { render(); });
|
|
handle = A.query("catalog", {}, function (data, meta) {
|
|
if (data) S.data = data;
|
|
else if (meta && meta.error) S.data = { catalog: null, error: meta.error, url: "" };
|
|
render();
|
|
});
|
|
refreshInstalled();
|
|
render();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|