feat(custom-widgets): complete Custom JSX v2 (#6390)

This commit is contained in:
Thomas authored and ajnart committed 2026-08-13 19:48:57 +02:00
1 parent 3a1245cbc5
commit acdfcbb18e
416 files changed
+37853 -18066

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>New Comment on Homarr Workshop</title>
</head>
<body style="margin: 0; padding: 0; background-color: #f4f4f4; font-family: Helvetica, Arial, sans-serif">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f4">
<tr>
<td align="center" style="padding: 50px 20px">
<table
role="presentation"
width="600"
cellpadding="0"
cellspacing="0"
style="width: 600px; max-width: 100%; background-color: #ffffff; border: 1px solid #000000"
>
<!-- Header -->
<tr>
<td align="center" style="background-color: #000000; padding: 36px 20px">
<a href="https://homarr.dev" target="_blank" style="text-decoration: none">
<img
src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/homarr-wordmark-light.png"
alt="Homarr"
width="170"
style="display: block; width: 170px; height: auto; border: 0; margin: 0 auto"
/>
</a>
</td>
</tr>
<!-- Body -->
<tr>
<td style="padding: 45px 40px; color: #000000; font-size: 15px; line-height: 1.7">
<p style="margin: 0 0 18px 0">Hi there,</p>
<p style="margin: 0 0 18px 0">
<strong>{{commenterName}}</strong> left a comment on your submission
<strong>{{submissionTitle}}</strong>:
</p>
<blockquote
style="
margin: 0 0 24px 0;
padding: 16px 20px;
border-left: 3px solid #000000;
background-color: #f9f9f9;
color: #555555;
"
>
{{commentExcerpt}}
</blockquote>
<!-- CTA button -->
<table role="presentation" cellpadding="0" cellspacing="0">
<tr>
<td align="center" style="background-color: #000000">
<a
href="{{submissionUrl}}"
target="_blank"
style="
display: inline-block;
padding: 12px 28px;
color: #ffffff;
font-size: 14px;
font-weight: bold;
text-decoration: none;
letter-spacing: 0.5px;
"
>
VIEW THE COMMENT
</a>
</td>
</tr>
</table>
</td>
</tr>
<!-- Divider -->
<tr>
<td style="border-top: 1px solid #000000"></td>
</tr>
<!-- Footer -->
<tr>
<td align="center" style="padding: 24px 20px; color: #000000; font-size: 12px">
<a href="https://homarr.dev" target="_blank" style="color: #000000; text-decoration: underline"
>homarr.dev</a
>
&nbsp;&middot;&nbsp; Homarr &mdash; 2026
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
+53
View File
@@ -0,0 +1,53 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Workshop report</title>
</head>
<body style="margin: 0; padding: 0; background: #f4f4f4; font-family: Helvetica, Arial, sans-serif">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background: #f4f4f4">
<tr>
<td align="center" style="padding: 50px 20px">
<table
role="presentation"
width="600"
cellpadding="0"
cellspacing="0"
style="width: 600px; max-width: 100%; background: #ffffff; border: 1px solid #dc2626"
>
<tr>
<td style="background: #991b1b; padding: 28px 36px; color: #ffffff">
<div style="font-size: 12px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase">
Moderation alert
</div>
<div style="margin-top: 8px; font-size: 22px; font-weight: bold">A Workshop submission was reported</div>
</td>
</tr>
<tr>
<td style="padding: 36px; color: #18181b; font-size: 15px; line-height: 1.65">
<p style="margin: 0 0 18px">
<strong>{{reporterName}}</strong> reported <a href="{{submissionUrl}}">{{submissionTitle}}</a>.
</p>
<p style="margin: 0 0 8px; font-size: 12px; font-weight: bold; text-transform: uppercase; color: #991b1b">
{{category}}
</p>
<blockquote
style="margin: 0 0 26px; padding: 16px 18px; border-left: 3px solid #dc2626; background: #fef2f2"
>
{{explanation}}
</blockquote>
<a
href="{{adminUrl}}"
style="display: inline-block; padding: 12px 20px; background: #991b1b; color: #ffffff; font-weight: bold; text-decoration: none"
>
REVIEW REPORT
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
@@ -0,0 +1,44 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Workshop submission removed</title>
</head>
<body style="margin: 0; padding: 0; background: #f4f4f4; font-family: Helvetica, Arial, sans-serif">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background: #f4f4f4">
<tr>
<td align="center" style="padding: 50px 20px">
<table
role="presentation"
width="600"
cellpadding="0"
cellspacing="0"
style="width: 600px; max-width: 100%; background: #ffffff; border: 1px solid #27272a"
>
<tr>
<td style="background: #18181b; padding: 28px 36px; color: #ffffff">
<div style="font-size: 12px; font-weight: bold; letter-spacing: 1px; text-transform: uppercase">
Homarr Workshop
</div>
<div style="margin-top: 8px; font-size: 22px; font-weight: bold">Your submission was removed</div>
</td>
</tr>
<tr>
<td style="padding: 36px; color: #18181b; font-size: 15px; line-height: 1.65">
<p style="margin: 0 0 18px">A Workshop administrator removed your submission:</p>
<div style="margin: 0 0 24px; padding: 16px 18px; border-left: 3px solid #dc2626; background: #fef2f2">
<strong>{{submissionTitle}}</strong>
</div>
<p style="margin: 0">
The submission is no longer available in Workshop. Widgets or CSS already installed by users are not
removed from their Homarr instances.
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
+138 -59
View File
@@ -1,75 +1,154 @@
/// <reference path="../pb_data/types.d.ts" />
// --- Submissions ---
onRecordCreateRequest((e) => {
e.record.set("author", e.auth?.id);
e.record.set("upvotes", 0);
e.record.set("downvotes", 0);
e.record.set("version", 1);
e.next();
}, "submissions");
onRecordAfterCreateSuccess((e) => {
onRecordAfterCreateSuccess((event) => {
try {
var votes = e.app.findCollectionByNameOrId("votes");
var vote = new Record(votes);
vote.set("submission", e.record.id);
vote.set("user", e.record.get("author"));
const votes = event.app.findCollectionByNameOrId("votes");
const vote = new Record(votes);
vote.set("submission", event.record.id);
vote.set("user", event.record.get("author"));
vote.set("value", 1);
e.app.save(vote);
} catch (err) {
console.log("auto-upvote failed for submission " + e.record.id + ": " + err);
event.app.save(vote);
} catch (error) {
console.log(`Workshop initial upvote failed for ${event.record.id}: ${error}`);
}
e.next();
event.next();
}, "submissions");
onRecordUpdateRequest((e) => {
var original = e.app.findRecordById("submissions", e.record.id);
e.record.set("author", original.get("author"));
e.record.set("upvotes", original.get("upvotes"));
e.record.set("downvotes", original.get("downvotes"));
e.record.set("type", original.get("type"));
e.record.set("schemaVersion", original.get("schemaVersion"));
e.record.set("version", original.get("version"));
e.next();
}, "submissions");
const escapeHtml = (value) =>
String(value)
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#039;");
// --- Votes ---
const emailTemplate = (filename) => {
const hooksPath = $os.getenv("WORKSHOP_PB_HOOKS_DIR") || $filepath.dirname(__filepath);
return $os.readFile($filepath.join(hooksPath, filename));
};
onRecordCreateRequest((e) => {
var v = +e.record.get("value");
if (v !== 1 && v !== -1) throw new BadRequestError("value must be 1 or -1");
e.record.set("user", e.auth?.id);
e.next();
}, "votes");
const sendEmail = (app, recipientEmail, subject, text, html) => {
const sender = app.settings().meta;
app.newMailClient().send(
new MailerMessage({
from: { address: sender.senderAddress, name: sender.senderName },
to: [{ address: recipientEmail }],
subject,
text,
html,
}),
);
};
onRecordUpdateRequest((e) => {
var v = +e.record.get("value");
if (v !== 1 && v !== -1) throw new BadRequestError("value must be 1 or -1");
var original = e.app.findRecordById("votes", e.record.id);
e.record.set("user", original.get("user"));
e.record.set("submission", original.get("submission"));
e.next();
}, "votes");
onRecordAfterCreateSuccess((event) => {
try {
const submission = event.app.findRecordById("submissions", event.record.get("submission"));
const recipient = event.app.findRecordById("users", submission.get("author"));
const commenter = event.app.findRecordById("users", event.record.get("author"));
const recipientEmail = recipient.email();
const publicOrigin = $os.getenv("WORKSHOP_PUBLIC_ORIGIN").replace(/\/$/, "");
// Vote count hooks removed — the `marketplace` view computes upvotes/downvotes via SQL
if (!recipientEmail || recipient.id === commenter.id || !publicOrigin) {
event.next();
return;
}
// --- Reports & Comments ---
const commenterName = commenter.getString("displayName") || "A community member";
const submissionTitle = submission.getString("title");
const rawExcerpt = event.record.getString("content").slice(0, 280);
const submissionUrl = `${publicOrigin}/workshop/${submission.id}/`;
const template = emailTemplate("comment-email.html")
.replaceAll("{{commenterName}}", escapeHtml(commenterName))
.replaceAll("{{submissionTitle}}", escapeHtml(submissionTitle))
.replaceAll("{{commentExcerpt}}", escapeHtml(rawExcerpt))
.replaceAll("{{submissionUrl}}", escapeHtml(submissionUrl));
onRecordCreateRequest((e) => {
e.record.set("user", e.auth?.id);
e.next();
sendEmail(
event.app,
recipientEmail,
`${commenterName} commented on ${submissionTitle}`,
`${commenterName} commented on “${submissionTitle}”:\n\n${rawExcerpt}\n\n${submissionUrl}`,
template,
);
} catch (error) {
console.log(`Workshop comment email failed for ${event.record.id}: ${error}`);
}
event.next();
}, "comments");
onRecordAfterCreateSuccess((event) => {
try {
const submission = event.app.findRecordById("submissions", event.record.get("submission"));
const reporter = event.app.findRecordById("users", event.record.get("reporter"));
const publicOrigin = $os.getenv("WORKSHOP_PUBLIC_ORIGIN").replace(/\/$/, "");
const admins = event.app.findAllRecords("users").filter((user) => user.getBool("isAdmin") && Boolean(user.email()));
if (!publicOrigin || admins.length === 0) {
event.next();
return;
}
const reporterName = reporter.getString("displayName") || "A community member";
const submissionTitle = submission.getString("title");
const category = event.record.getString("category");
const explanation = event.record.getString("explanation");
const adminUrl = `${publicOrigin}/workshop/admin`;
const submissionUrl = `${publicOrigin}/workshop/${submission.id}/`;
const template = emailTemplate("report-email.html")
.replaceAll("{{reporterName}}", escapeHtml(reporterName))
.replaceAll("{{submissionTitle}}", escapeHtml(submissionTitle))
.replaceAll("{{category}}", escapeHtml(category))
.replaceAll("{{explanation}}", escapeHtml(explanation))
.replaceAll("{{adminUrl}}", escapeHtml(adminUrl))
.replaceAll("{{submissionUrl}}", escapeHtml(submissionUrl));
for (const admin of admins) {
try {
sendEmail(
event.app,
admin.email(),
`Workshop report: ${submissionTitle}`,
`${reporterName} reported “${submissionTitle}” for ${category}.\n\n${explanation}\n\nReview: ${adminUrl}`,
template,
);
} catch (error) {
console.log(`Workshop report email failed for admin ${admin.id}: ${error}`);
}
}
} catch (error) {
console.log(`Workshop report email failed for ${event.record.id}: ${error}`);
}
event.next();
}, "reports");
onRecordCreateRequest((e) => {
e.record.set("author", e.auth?.id);
e.next();
}, "comments");
onRecordDeleteRequest((event) => {
const submissionId = event.record.id;
const submissionTitle = event.record.getString("title");
const authorId = event.record.get("author");
const actor = event.requestInfo().auth;
const notifyAuthor = actor && actor.getBool("isAdmin") && actor.id !== authorId;
onRecordUpdateRequest((e) => {
var original = e.app.findRecordById("comments", e.record.id);
e.record.set("author", original.get("author"));
e.record.set("submission", original.get("submission"));
e.next();
}, "comments");
event.next();
if (!notifyAuthor) return;
try {
const author = event.app.findRecordById("users", authorId);
const recipientEmail = author.email();
if (!recipientEmail) return;
const publicOrigin = $os.getenv("WORKSHOP_PUBLIC_ORIGIN").replace(/\/$/, "");
const workshopUrl = publicOrigin ? `${publicOrigin}/workshop/` : "";
const template = emailTemplate("submission-deleted-email.html").replaceAll(
"{{submissionTitle}}",
escapeHtml(submissionTitle),
);
const text = `A Workshop administrator removed your submission “${submissionTitle}”.${
workshopUrl ? `\n\nReturn to Workshop: ${workshopUrl}` : ""
}`;
sendEmail(event.app, recipientEmail, `Your Workshop submission was removed`, text, template);
} catch (error) {
console.log(`Workshop deletion email failed for ${submissionId}: ${error}`);
}
}, "submissions");