From 40652bb51bfd01ee96c6300c5167af673368dc1b Mon Sep 17 00:00:00 2001 From: jatmn Date: Thu, 3 Dec 2026 23:26:18 -0800 Subject: [PATCH 1/2] refactor(webui): rebuild modal-box dialog interiors on Mantine Modal --- frontend/app.js | 875 +++++++++++++++-------------- frontend/style.css | 54 +- scripts/frontend-contrast-test.mjs | 53 ++ scripts/frontend-state-test.mjs | 152 ++++- scripts/package-webui-test.mjs | 6 +- 5 files changed, 678 insertions(+), 462 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index 85d8e9b4..247f3a15 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -3262,11 +3262,11 @@ function Workspace({ appearance }) { opened: !!display.editor, onClose: dismissOverlay, centered: true, - size: "56rem", + radius: "md", + size: modalSizeFor(display.editor), yOffset: "var(--dialog-gutter)", xOffset: "var(--dialog-gutter)", transitionProps: { duration: 0 }, - classNames: { content: "modal-overlay" }, }, h(Modal.Overlay, { color: "var(--overlay)", backgroundOpacity: 1 }), h(Modal.Content, { @@ -3275,6 +3275,57 @@ function Workspace({ appearance }) { ), ); } +function modalSizeFor(editor) { + if (editor?.type === CaseView) return "60rem"; + if (editor?.type === BanDialog) return "34rem"; + return "56rem"; +} +function ModalDialogShell({ + className = "", + headerClassName = "", + eyebrow = null, + title, + titleProps = null, + titleExtra = null, + headerActions = null, + headerSub = null, + closeLabel = "Close", + bodyClassName = "", + footer = null, + footerClassName = "", + children, + ...rest +}) { + const working = useContext(BusyContext); + return h( + "div", + { className: `sf-modal-shell ${className}`.trim(), ...rest }, + h( + Modal.Header, + { className: headerClassName || undefined }, + h( + "div", + { className: "sf-modal-header-main" }, + h( + "div", + { className: "sf-modal-title-group" }, + eyebrow ? h("span", { className: "eyebrow" }, eyebrow) : null, + h( + "div", + { className: "sf-modal-title-row" }, + h(Modal.Title, titleProps, title), + titleExtra, + ), + ), + headerActions ? h("div", { className: "sf-modal-header-actions" }, headerActions) : null, + h(Modal.CloseButton, { "aria-label": closeLabel, title: closeLabel, disabled: working }), + ), + headerSub, + ), + h(Modal.Body, { className: bodyClassName || undefined }, children), + footer ? h("footer", { className: `sf-modal-footer ${footerClassName}`.trim() }, footer) : null, + ); +} function ModalToastStatus() { const { message, seq } = useStore(ui, snapshot => snapshot.modalToast); return h("div", { @@ -6374,29 +6425,33 @@ function EditorSection({ title, hint, className = "", children }) { // Enabled and Dry-run sit in the header as toggles; their labels stay the // exact control names. -function RuleEditorHeader({ title, enabled, dryRun, dryRunDisabled, enabledDisabled, disabled, requireChannels, hasChannels, onEnabled, onDryRun, dryRunRef }) { +function RuleToggles({ enabled, dryRun, dryRunDisabled, enabledDisabled, disabled, requireChannels, hasChannels, onEnabled, onDryRun, dryRunRef }) { + return h( + "div", + { className: "rule-toggles" }, + h(FieldSwitch, { + className: "toggle-label", + label: "Enabled", + ...(requireChannels ? { checked: enabled, disabled: !hasChannels } : { defaultChecked: enabled, disabled: disabled || enabledDisabled }), + onChange: (e) => onEnabled(e.target.checked), + }), + h(FieldSwitch, { + ref: dryRunRef, + className: "toggle-label", + label: "Dry-run (log only)", + defaultChecked: dryRun, + disabled: disabled || dryRunDisabled, + onChange: (e) => onDryRun(e.target.checked), + }), + ); +} + +function RuleEditorHeader({ title, ...toggleProps }) { return h( "div", { className: "editor-heading rule-editor-header" }, h("div", { className: "rule-editor-title" }, h("span", { className: "eyebrow" }, "AUTOMOD RULE"), h("h3", { className: "sf-card-title" }, title)), - h( - "div", - { className: "rule-toggles" }, - h(FieldSwitch, { - className: "toggle-label", - label: "Enabled", - ...(requireChannels ? { checked: enabled, disabled: !hasChannels } : { defaultChecked: enabled, disabled: disabled || enabledDisabled }), - onChange: (e) => onEnabled(e.target.checked), - }), - h(FieldSwitch, { - ref: dryRunRef, - className: "toggle-label", - label: "Dry-run (log only)", - defaultChecked: dryRun, - disabled: disabled || dryRunDisabled, - onChange: (e) => onDryRun(e.target.checked), - }), - ), + h(RuleToggles, toggleProps), ); } @@ -6839,24 +6894,72 @@ function CustomRuleEditor({ record: r, creating }) { rule.dry_run, ); return h( - "div", - { className: "modal-box rule-editor", onInput: trackDraft }, - h(RuleEditorHeader, { + ModalDialogShell, + { + className: "rule-editor", + onInput: trackDraft, + eyebrow: "AUTOMOD RULE", title: creating ? (preset ? r.name : "Add custom rule") : `Edit custom rule: ${r.name || r.rule_id}`, - enabled: rule.enabled, - requireChannels: preset, - hasChannels: rule.include_channels.length > 0, - dryRun: rule.dry_run, - dryRunDisabled: creating, - onEnabled: (on) => { - rule.enabled = on; - refresh(); - }, - onDryRun: (on) => { - rule.dry_run = on; - refresh(); - }, - }), + headerActions: h(RuleToggles, { + enabled: rule.enabled, + requireChannels: preset, + hasChannels: rule.include_channels.length > 0, + dryRun: rule.dry_run, + dryRunDisabled: creating, + onEnabled: (on) => { + rule.enabled = on; + refresh(); + }, + onDryRun: (on) => { + rule.dry_run = on; + refresh(); + }, + }), + footer: h( + React.Fragment, + null, + h( + ActionButton, + { + variant: "filled", + onClick: async () => { + if (!flushPendingIds(pending)) return; + const data = buildCustomRuleSaveBody(rule, creating); + const saved = await api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "PUT", { scope: "guild", data }); + if (!applyConfigPatch(saved) && !(await loadConfig())) return; + const persisted = state.config.rules.find((record) => record.rule_id === r.rule_id)?.effective; + const removed = preset && persisted ? data.include_channels.length - persisted.include_channels.length : 0; + if (removed > 0) { + const channels = removed === 1 ? "1 unavailable channel" : `${removed} unavailable channels`; + const disabled = data.enabled && !persisted.enabled ? " The rule is now off." : ""; + toast(`Rule saved. Removed ${channels}.${disabled}`); + } else { + toast("Rule saved", "success"); + } + closeOverlay(); + renderTab(); + }, + }, + "Save", + ), + !creating + ? h( + ActionButton, + { + variant: "filled", color: "red", + onClick: async () => { + await reloadAfter(() => api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "DELETE", { scope: "guild" }), () => { + toast("Rule deleted", "success"); + closeOverlay(); + }); + }, + }, + "Delete", + ) + : null, + h(ActionButton, { variant: "outline", onClick: () => canLeave() && closeOverlay() }, "Cancel"), + ), + }, h(RuleSummary, { text: summary }), h( EditorSection, @@ -7086,50 +7189,6 @@ function CustomRuleEditor({ record: r, creating }) { kind === "honeypot_role" ? h("p", { className: "field-help" }, "For a hidden case, turn on Open a case and turn off Post to automod log.") : null, ), ), - h( - "div", - { className: "modal-action" }, - h( - ActionButton, - { - variant: "filled", - onClick: async () => { - if (!flushPendingIds(pending)) return; - const data = buildCustomRuleSaveBody(rule, creating); - const saved = await api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "PUT", { scope: "guild", data }); - if (!applyConfigPatch(saved) && !(await loadConfig())) return; - const persisted = state.config.rules.find((record) => record.rule_id === r.rule_id)?.effective; - const removed = preset && persisted ? data.include_channels.length - persisted.include_channels.length : 0; - if (removed > 0) { - const channels = removed === 1 ? "1 unavailable channel" : `${removed} unavailable channels`; - const disabled = data.enabled && !persisted.enabled ? " The rule is now off." : ""; - toast(`Rule saved. Removed ${channels}.${disabled}`); - } else { - toast("Rule saved", "success"); - } - closeOverlay(); - renderTab(); - }, - }, - "Save", - ), - !creating - ? h( - ActionButton, - { - variant: "filled", color: "red", - onClick: async () => { - await reloadAfter(() => api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "DELETE", { scope: "guild" }), () => { - toast("Rule deleted", "success"); - closeOverlay(); - }); - }, - }, - "Delete", - ) - : null, - h(ActionButton, { variant: "outline", onClick: () => canLeave() && closeOverlay() }, "Cancel"), - ), ); } @@ -7175,19 +7234,56 @@ function OnboardingTrapEditor({ record }) { && Number(windowMinutes) === (expected.params?.join_window_minutes ?? 30); const lockLiveRemoval = managedRemoval && !matchesSavedLiveRemoval; return h( - "div", - { className: "modal-box rule-editor", onInput: trackDraft }, - h(RuleEditorHeader, { - key: hasRole, + ModalDialogShell, + { + className: "rule-editor", + onInput: trackDraft, + eyebrow: "AUTOMOD RULE", title: record.name, - enabled: rule.enabled && hasRole, - dryRun: rule.dry_run, - disabled: !hasRole, - enabledDisabled: lockLiveRemoval && !rule.enabled && !rule.dry_run, - dryRunDisabled: lockLiveRemoval && rule.enabled && rule.dry_run, - onEnabled: (on) => { rule.enabled = on; refresh(); }, - onDryRun: (on) => { rule.dry_run = on; refresh(); }, - }), + headerActions: h(RuleToggles, { + key: hasRole, + enabled: rule.enabled && hasRole, + dryRun: rule.dry_run, + disabled: !hasRole, + enabledDisabled: lockLiveRemoval && !rule.enabled && !rule.dry_run, + dryRunDisabled: lockLiveRemoval && rule.enabled && rule.dry_run, + onEnabled: (on) => { rule.enabled = on; refresh(); }, + onDryRun: (on) => { rule.dry_run = on; refresh(); }, + }), + footer: h( + React.Fragment, + null, + h(ActionButton, { + variant: "filled", + onClick: async () => { + if (!flushPendingIds(pending)) return; + const roleId = roleIds[0] || null; + if (roleId === state.guildId) throw new Error("Choose a role other than @everyone"); + if (canManageRemoval && (removalRoleIds.length > 5 || removalRoleIds.some((id) => id === state.guildId || id === roleId))) { + throw new Error("Choose up to five roles other than @everyone and the trap role to remove"); + } + if (!/^\d+$/.test(windowMinutes) || Number(windowMinutes) > 1440) throw new Error("Enter a join window from 0 to 1440 minutes"); + if (!/^\d+$/.test(cleanupMinutes) || Number(cleanupMinutes) > 60) throw new Error("Enter a cleanup window from 0 to 60 minutes"); + const data = { + ...rule, + enabled: rule.enabled && roleId !== null, + params: { + ...rule.params, + role_id: roleId, + join_window_minutes: Number(windowMinutes), + cleanup_window_minutes: Number(cleanupMinutes), + ...(canManageRemoval ? { remove_role_ids: [...removalRoleIds] } : {}), + }, + }; + await reloadAfter(() => api(`/api/guilds/${state.guildId}/rules/${record.rule_id}`, "PUT", { scope: "guild", data, expected }), () => { + toast("Rule saved", "success"); + closeOverlay(); + }); + }, + }, "Save"), + h(ActionButton, { variant: "outline", onClick: () => canLeave() && closeOverlay() }, "Cancel"), + ), + }, h( EditorSection, { title: "Trigger" }, @@ -7244,39 +7340,6 @@ function OnboardingTrapEditor({ record }) { h("p", { className: "field-help" }, "After a successful kick, delete tracked messages the member sent since joining within this window. Use 0 to leave their messages in place."), ), h("p", {}, h("a", { href: ONBOARDING_TRAP_GUIDE, className: "link" }, "Onboarding bot trap setup guide")), - h( - "div", - { className: "modal-action" }, - h(ActionButton, { - variant: "filled", - onClick: async () => { - if (!flushPendingIds(pending)) return; - const roleId = roleIds[0] || null; - if (roleId === state.guildId) throw new Error("Choose a role other than @everyone"); - if (canManageRemoval && (removalRoleIds.length > 5 || removalRoleIds.some((id) => id === state.guildId || id === roleId))) { - throw new Error("Choose up to five roles other than @everyone and the trap role to remove"); - } - if (!/^\d+$/.test(windowMinutes) || Number(windowMinutes) > 1440) throw new Error("Enter a join window from 0 to 1440 minutes"); - if (!/^\d+$/.test(cleanupMinutes) || Number(cleanupMinutes) > 60) throw new Error("Enter a cleanup window from 0 to 60 minutes"); - const data = { - ...rule, - enabled: rule.enabled && roleId !== null, - params: { - ...rule.params, - role_id: roleId, - join_window_minutes: Number(windowMinutes), - cleanup_window_minutes: Number(cleanupMinutes), - ...(canManageRemoval ? { remove_role_ids: [...removalRoleIds] } : {}), - }, - }; - await reloadAfter(() => api(`/api/guilds/${state.guildId}/rules/${record.rule_id}`, "PUT", { scope: "guild", data, expected }), () => { - toast("Rule saved", "success"); - closeOverlay(); - }); - }, - }, "Save"), - h(ActionButton, { variant: "outline", onClick: () => canLeave() && closeOverlay() }, "Cancel"), - ), ); } @@ -7367,22 +7430,130 @@ function RuleEditor({ record: r }) { ); return h( - "div", - { className: "modal-box rule-editor", onInput: trackDraft }, - h(RuleEditorHeader, { + ModalDialogShell, + { + className: "rule-editor", + onInput: trackDraft, + eyebrow: "AUTOMOD RULE", title: `Edit rule: ${r.name}`, - enabled: rule.enabled, - dryRun, - dryRunRef, - onEnabled: (on) => { - rule.enabled = on; - refresh(); - }, - onDryRun: (on) => { - rule.dry_run = on; - setDryRun(on); - }, - }), + headerActions: h(RuleToggles, { + enabled: rule.enabled, + dryRun, + dryRunRef, + onEnabled: (on) => { + rule.enabled = on; + refresh(); + }, + onDryRun: (on) => { + rule.dry_run = on; + setDryRun(on); + }, + }), + footer: h( + React.Fragment, + null, + h( + ActionButton, + { + variant: "filled", + onClick: async () => { + let replaceVelocityLimit = false; + try { + if (spam) { + // The header toggle is the source of truth, including scripted checks. + const punish = !(dryRunRef.current?.checked ?? dryRun); + setSpamRuleMode(rule, r.rule_id, punish, (key) => Number(values[key]), spamBan); + if (!spamConfigured(r.rule_id, rule)) + throw new Error( + "Channels must be 2–10 and window 1–600 seconds, all whole numbers. Images 1–10. Text length 1–2000.", + ); + } else if (r.rule_id !== "badword" && !knownSpam) { + const params = {}; + // `rule` is the draft; compare limits with what the target scope stores. + const persisted = + (scopeSelRef.current?.value === "global" && state.guildId !== "0" ? r.global : r.effective) + ?.params ?? {}; + const shown = r.effective?.params ?? {}; + for (const { key, label, max } of fields) { + const raw = String(values[key] ?? ""); + const value = Number(raw); + const validInteger = raw.trim() !== "" && Number.isSafeInteger(value) && value >= 0; + if (max !== undefined) { + // Keep an untouched limit or a restored legacy value outside the + // accepted range. A valid input edit can replace a legacy value + // even when both are displayed as the same number. + if (raw === initialValues[key] && (!velocityLimitEdited.current || !validInteger || value > max)) { + if (Object.hasOwn(shown, key)) params[key] = shown[key]; + continue; + } + replaceVelocityLimit = true; + } + const unchanged = max === undefined && value === persisted[key]; + if (raw.trim() === "" || Number.isNaN(value) || (!unchanged && !validInteger)) + throw new Error(`${label} must be a non-negative whole number.`); + if (key === "window_secs" && (value < 1 || value > 600)) + throw new Error("Window must be 1–600 seconds."); + if (max !== undefined && value > max) + throw new Error(`${label} must be 0–${max}.`); + params[key] = value; + } + if (r.rule_id === "invite") { + params.allowlist_codes = String(values.allowlist_codes || "") + .split(",") + .map((code) => code.trim()) + .filter(Boolean); + } + rule.params = params; + } + } catch (e) { + toast("Invalid detection settings: " + e.message, "error"); + return; + } + if (!flushPendingIds(pending)) return; + const scope = scopeSelRef.current.value; + const saved = await api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "PUT", { + scope, + data: rule, + clear_guild_override: scope === "global" && state.guildId !== "0", + ...(replaceVelocityLimit ? { replace_velocity_limit: true } : {}), + }); + const savedLocally = applyConfigPatch(saved); + if (!savedLocally && !(await loadConfig())) return; + toast("Rule saved", "success"); + closeOverlay(); + renderTab(); + }, + }, + "Save", + ), + h( + ActionButton, + { + variant: "filled", color: "red", + onClick: async () => { + await reloadAfter( + () => api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "DELETE", { scope: "guild" }), + () => { + toast("Rule reset", "success"); + closeOverlay(); + }, + ); + }, + }, + "Reset to global", + ), + h( + ActionButton, + { + variant: "outline", + onClick: () => { + if (canLeave()) closeOverlay(); + }, + }, + "Cancel", + ), + ), + }, h(RuleSummary, { text: summary }), h( EditorSection, @@ -7411,110 +7582,6 @@ function RuleEditor({ record: r }) { field("Applies to", scopeSel), h(RuleAdvanced, { rule, names, onChange: refresh, pending }), ), - h( - "div", - { className: "modal-action" }, - h( - ActionButton, - { - variant: "filled", - onClick: async () => { - let replaceVelocityLimit = false; - try { - if (spam) { - // The header toggle is the source of truth, including scripted checks. - const punish = !(dryRunRef.current?.checked ?? dryRun); - setSpamRuleMode(rule, r.rule_id, punish, (key) => Number(values[key]), spamBan); - if (!spamConfigured(r.rule_id, rule)) - throw new Error( - "Channels must be 2–10 and window 1–600 seconds, all whole numbers. Images 1–10. Text length 1–2000.", - ); - } else if (r.rule_id !== "badword" && !knownSpam) { - const params = {}; - // `rule` is the draft; compare limits with what the target scope stores. - const persisted = - (scopeSelRef.current?.value === "global" && state.guildId !== "0" ? r.global : r.effective) - ?.params ?? {}; - const shown = r.effective?.params ?? {}; - for (const { key, label, max } of fields) { - const raw = String(values[key] ?? ""); - const value = Number(raw); - const validInteger = raw.trim() !== "" && Number.isSafeInteger(value) && value >= 0; - if (max !== undefined) { - // Keep an untouched limit or a restored legacy value outside the - // accepted range. A valid input edit can replace a legacy value - // even when both are displayed as the same number. - if (raw === initialValues[key] && (!velocityLimitEdited.current || !validInteger || value > max)) { - if (Object.hasOwn(shown, key)) params[key] = shown[key]; - continue; - } - replaceVelocityLimit = true; - } - const unchanged = max === undefined && value === persisted[key]; - if (raw.trim() === "" || Number.isNaN(value) || (!unchanged && !validInteger)) - throw new Error(`${label} must be a non-negative whole number.`); - if (key === "window_secs" && (value < 1 || value > 600)) - throw new Error("Window must be 1–600 seconds."); - if (max !== undefined && value > max) - throw new Error(`${label} must be 0–${max}.`); - params[key] = value; - } - if (r.rule_id === "invite") { - params.allowlist_codes = String(values.allowlist_codes || "") - .split(",") - .map((code) => code.trim()) - .filter(Boolean); - } - rule.params = params; - } - } catch (e) { - toast("Invalid detection settings: " + e.message, "error"); - return; - } - if (!flushPendingIds(pending)) return; - const scope = scopeSelRef.current.value; - const saved = await api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "PUT", { - scope, - data: rule, - clear_guild_override: scope === "global" && state.guildId !== "0", - ...(replaceVelocityLimit ? { replace_velocity_limit: true } : {}), - }); - const savedLocally = applyConfigPatch(saved); - if (!savedLocally && !(await loadConfig())) return; - toast("Rule saved", "success"); - closeOverlay(); - renderTab(); - }, - }, - "Save", - ), - h( - ActionButton, - { - variant: "filled", color: "red", - onClick: async () => { - await reloadAfter( - () => api(`/api/guilds/${state.guildId}/rules/${r.rule_id}`, "DELETE", { scope: "guild" }), - () => { - toast("Rule reset", "success"); - closeOverlay(); - }, - ); - }, - }, - "Reset to global", - ), - h( - ActionButton, - { - variant: "outline", - onClick: () => { - if (canLeave()) closeOverlay(); - }, - }, - "Cancel", - ), - ), ); } @@ -8696,18 +8763,13 @@ function CommandEditor({ record: c }) { : h("p", { className: "field-help" }, spec ? "This built-in has no settings." : "This behavior has no form fields. Its saved settings are kept."); return h( - "div", - { className: "modal-box rule-editor command-editor", onInput: trackDraft }, - h( - "div", - { className: "editor-heading rule-editor-header" }, - h( - "div", - { className: "rule-editor-title" }, - h("span", { className: "eyebrow" }, builtin ? "BUILT-IN COMMAND" : isPlan ? "CUSTOM COMMAND" : "COMMAND"), - h("h3", { className: "sf-card-title" }, isNew ? "New custom command" : `Edit command: ${c.name}`), - ), - h( + ModalDialogShell, + { + className: "rule-editor command-editor", + onInput: trackDraft, + eyebrow: builtin ? "BUILT-IN COMMAND" : isPlan ? "CUSTOM COMMAND" : "COMMAND", + title: isNew ? "New custom command" : `Edit command: ${c.name}`, + headerActions: h( "div", { className: "rule-toggles" }, h(FieldSwitch, { @@ -8720,7 +8782,90 @@ function CommandEditor({ record: c }) { }, }), ), - ), + footer: h( + React.Fragment, + null, + field("Applies to", scopeSel), + h( + ActionButton, + { + variant: "filled", + hidden: fixed, + onClick: async () => { + data.name = String(data.name || "").trim().toLowerCase(); + if (!data.name) return toast("Name required", "error"); + // Typed role and channel IDs land in the data before it is checked. + if (!flushPendingIds(pending)) return; + const problem = commandFormError(data); + if (problem) return toast(problem, "error"); + data.aliases = aliasText.value + .split(",") + .map((s) => s.trim()) + .filter(Boolean); + // The server omits empty allowed roles; an untouched save sends the same shape. + const { grant_roles: grants, ...ungranted } = data; + const saved = grants.length && scopeSelRef.current.value !== "global" && state.guildId !== "0" ? data : ungranted; + await reloadAfter( + () => + isNew + ? api(`/api/guilds/${state.guildId}/commands`, "POST", { + scope: scopeSelRef.current.value, + data: saved, + }) + : api(`/api/guilds/${state.guildId}/commands/${encodeURIComponent(c.name)}`, "PUT", { + scope: scopeSelRef.current.value, + data: saved, + }), + () => { + toast("Command saved", "success"); + closeOverlay(); + }, + ); + }, + }, + "Save", + ), + h( + ActionButton, + { + variant: "filled", color: "red", + // A built-in has nothing to delete until this server overrides it. + hidden: isNew || (builtin && (fixed || !c.guild_override)), + onClick: async () => { + if (!confirm(builtin ? `Reset ${c.name} to its default?` : `Delete command ${c.name}?`)) return; + // Prefer clearing a guild override (reset to global). Only delete the + // global row when there is no override and the caller is the bot owner. + const delScope = c.guild_override + ? "guild" + : c.scope === "global" && isBotOwner() + ? "global" + : "guild"; + await reloadAfter( + () => + api(`/api/guilds/${state.guildId}/commands/${encodeURIComponent(c.name)}`, "DELETE", { + scope: delScope, + }), + () => { + toast(builtin ? "Reset to default" : c.guild_override ? "Override cleared" : "Deleted", "success"); + closeOverlay(); + }, + ); + }, + }, + builtin ? "Reset to default" : "Delete", + ), + h( + ActionButton, + { + variant: "outline", + onClick: () => { + if (canLeave()) closeOverlay(); + }, + }, + "Cancel", + ), + ), + }, h(RuleSummary, { text: commandSummaryText(globalTarget ? { ...data, grant_roles: [] } : data, names) }), fixed ? h("p", { className: "field-help" }, "Built-ins are changed one server at a time. Pick a server to edit this one.") : null, h( @@ -8857,89 +9002,6 @@ function CommandEditor({ record: c }) { ) : null, ), - h( - "div", - { className: "modal-action" }, - field("Applies to", scopeSel), - h( - ActionButton, - { - variant: "filled", - hidden: fixed, - onClick: async () => { - data.name = String(data.name || "").trim().toLowerCase(); - if (!data.name) return toast("Name required", "error"); - // Typed role and channel IDs land in the data before it is checked. - if (!flushPendingIds(pending)) return; - const problem = commandFormError(data); - if (problem) return toast(problem, "error"); - data.aliases = aliasText.value - .split(",") - .map((s) => s.trim()) - .filter(Boolean); - // The server omits empty allowed roles; an untouched save sends the same shape. - const { grant_roles: grants, ...ungranted } = data; - const saved = grants.length && scopeSelRef.current.value !== "global" && state.guildId !== "0" ? data : ungranted; - await reloadAfter( - () => - isNew - ? api(`/api/guilds/${state.guildId}/commands`, "POST", { - scope: scopeSelRef.current.value, - data: saved, - }) - : api(`/api/guilds/${state.guildId}/commands/${encodeURIComponent(c.name)}`, "PUT", { - scope: scopeSelRef.current.value, - data: saved, - }), - () => { - toast("Command saved", "success"); - closeOverlay(); - }, - ); - }, - }, - "Save", - ), - h( - ActionButton, - { - variant: "filled", color: "red", - // A built-in has nothing to delete until this server overrides it. - hidden: isNew || (builtin && (fixed || !c.guild_override)), - onClick: async () => { - if (!confirm(builtin ? `Reset ${c.name} to its default?` : `Delete command ${c.name}?`)) return; - // Prefer clearing a guild override (reset to global). Only delete the - // global row when there is no override and the caller is the bot owner. - const delScope = c.guild_override - ? "guild" - : c.scope === "global" && isBotOwner() - ? "global" - : "guild"; - await reloadAfter( - () => - api(`/api/guilds/${state.guildId}/commands/${encodeURIComponent(c.name)}`, "DELETE", { - scope: delScope, - }), - () => { - toast(builtin ? "Reset to default" : c.guild_override ? "Override cleared" : "Deleted", "success"); - closeOverlay(); - }, - ); - }, - }, - builtin ? "Reset to default" : "Delete", - ), - h( - ActionButton, - { - variant: "outline", - onClick: () => { - if (canLeave()) closeOverlay(); - }, - }, - "Cancel", - ), - ), ); } @@ -11234,17 +11296,15 @@ function CaseView({ guildId, caseId, onRemoved, onFilter }) { }; }, [base, attempt]); const short = caseId.slice(0, 8); - const header = h( - "header", - { className: "case-header" }, - h( - "div", - { className: "case-title" }, - h("h2", { title: caseId }, `Case ${short}`), - h(IconButton, { action: "copy", label: `Copy case ID ${caseId}`, onClick: () => navigator.clipboard.writeText(caseId) }), - h(IconButton, { action: "cancel", label: "Close case", variant: "subtle", className: "case-close", onClick: dismissOverlay }), - ), - view.status === "ready" + const shellProps = { + className: "case-view", + headerClassName: "case-header", + title: `Case ${short}`, + titleProps: { title: caseId }, + titleExtra: h(IconButton, { action: "copy", label: `Copy case ID ${caseId}`, onClick: () => navigator.clipboard.writeText(caseId) }), + closeLabel: "Close case", + bodyClassName: "case-view-body", + headerSub: view.status === "ready" ? h( "div", { className: "case-tags" }, @@ -11254,12 +11314,11 @@ function CaseView({ guildId, caseId, onRemoved, onFilter }) { h(Badge, { component: "span", className: "badge badge-soft badge-sm" }, state.guilds.find((g) => g.id === guildId)?.name || "This server"), ) : null, - ); + }; if (view.status !== "ready") { return h( - "div", - { className: "modal-box case-view", "aria-busy": view.status === "loading" }, - header, + ModalDialogShell, + { ...shellProps, "aria-busy": view.status === "loading" }, view.status === "loading" ? h("p", { className: "case-loading", role: "status", "aria-live": "polite" }, "Loading case…") : h( @@ -11312,10 +11371,41 @@ function CaseView({ guildId, caseId, onRemoved, onFilter }) { ); onRemoved?.(); }; + const footer = !isPreview() && (canManageServer() || view.canDelete) + ? h( + React.Fragment, + null, + canManageServer() + ? h( + "div", + { className: "case-note-form" }, + h(FieldTextarea, { + ref: noteRef, + rows: "2", + "aria-label": "Note", + placeholder: "Add a note for other moderators. Discord isn't changed.", + }), + h(ActionButton, { variant: "filled", size: "sm", type: "button", onClick: addNote }, "Add note"), + ) + : null, + view.canDelete + ? h( + ActionButton, + { + type: "button", + size: "sm", className: "case-remove", + title: "Deletes jModGuard's private record only. Discord isn't changed.", + onClick: remove, + }, + h(Icon, { name: ACTION_ICONS.remove.icon, intent: ACTION_ICONS.remove.intent }), + "Remove case record", + ) + : null, + ) + : null; return h( - "div", - { className: "modal-box case-view", onInput: trackDraft }, - header, + ModalDialogShell, + { ...shellProps, onInput: trackDraft, footerClassName: "case-actions", footer }, h( "section", { className: "case-section", "aria-label": "Who" }, @@ -11344,38 +11434,6 @@ function CaseView({ guildId, caseId, onRemoved, onFilter }) { h("h3", {}, "Evidence"), h(CaseEvidence, { guildId, caseId, texts, files: view.files, names, channels: view.channels }), ), - !isPreview() && (canManageServer() || view.canDelete) - ? h( - "div", - { className: "case-actions" }, - canManageServer() - ? h( - "div", - { className: "case-note-form" }, - h(FieldTextarea, { - ref: noteRef, - rows: "2", - "aria-label": "Note", - placeholder: "Add a note for other moderators. Discord isn't changed.", - }), - h(ActionButton, { variant: "filled", size: "sm", type: "button", onClick: addNote }, "Add note"), - ) - : null, - view.canDelete - ? h( - ActionButton, - { - type: "button", - size: "sm", className: "case-remove", - title: "Deletes jModGuard's private record only. Discord isn't changed.", - onClick: remove, - }, - h(Icon, { name: ACTION_ICONS.remove.icon, intent: ACTION_ICONS.remove.intent }), - "Remove case record", - ) - : null, - ) - : null, ); } @@ -13748,18 +13806,20 @@ function BanDialog({ guildId, onDone }) { else onDone(); }; return h( - "div", - { className: "modal-box ban-dialog" }, - h( - "header", - { className: "case-header" }, - h( - "div", - { className: "case-title" }, - h("h2", null, "Ban a user"), - h(IconButton, { action: "cancel", label: "Close", variant: "subtle", className: "case-close", onClick: close }), - ), - ), + ModalDialogShell, + { + className: "ban-dialog", + title: "Ban a user", + closeLabel: "Close", + footer: receipt + ? h(ActionButton, { type: "button", size: "sm", onClick: closeOverlay }, "Close") + : h( + React.Fragment, + null, + h(ActionButton, { type: "button", variant: "filled", color: "red", disabled: !durationValid, onClick: submit }, h(Icon, { name: "hammer" }), "Ban user"), + h(ActionButton, { type: "button", variant: "default", onClick: close }, "Cancel"), + ), + }, receipt ? h( "div", @@ -13771,7 +13831,6 @@ function BanDialog({ guildId, onDone }) { banReceiptText(receipt), ), h("p", { className: "field-help" }, "Bot actions keeps this result."), - h("div", { className: "row" }, h(ActionButton, { type: "button", size: "sm", onClick: closeOverlay }, "Close")), ) : h( "div", @@ -13826,12 +13885,6 @@ function BanDialog({ guildId, onDone }) { }, }), ), - h( - "div", - { className: "row" }, - h(ActionButton, { type: "button", variant: "filled", color: "red", disabled: !durationValid, onClick: submit }, h(Icon, { name: "hammer" }), "Ban user"), - h(ActionButton, { type: "button", variant: "default", onClick: close }, "Cancel"), - ), ), ); } diff --git a/frontend/style.css b/frontend/style.css index 5b810e53..e65f5433 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -40,7 +40,7 @@ body { background: var(--bg); } /* WCAG 2.2 target size: compact controls (xs/sm/square buttons, fields, tooltip triggers) never render below 24px. */ .mantine-ActionIcon-root, .tooltip-trigger { min-width: var(--target-min); } /* One visible focus ring for every control; --accent keeps 3:1 on all shell surfaces in both themes. */ -:is(.mantine-Button-root, .mantine-ActionIcon-root, .mantine-Input-input, .mantine-Checkbox-input, .server-picker-trigger, .menu button, .tooltip-trigger, .mantine-Notification-closeButton, .table-scroll, a, summary, .sf-hub-pill, .sf-srv-btn, .sf-rail-toggle, .sf-ribbon-link, .sf-tri button, .sf-log-nav-btn, .sf-wb-select-btn):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +:is(.mantine-Button-root, .mantine-ActionIcon-root, .mantine-CloseButton-root, .mantine-Input-input, .mantine-Checkbox-input, .server-picker-trigger, .menu button, .tooltip-trigger, .mantine-Notification-closeButton, .table-scroll, a, summary, .sf-hub-pill, .sf-srv-btn, .sf-rail-toggle, .sf-ribbon-link, .sf-tri button, .sf-log-nav-btn, .sf-wb-select-btn):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .mantine-Switch-input:focus-visible + .mantine-Switch-track { outline: 2px solid var(--accent); outline-offset: 2px; } .hidden, [hidden] { display: none !important; } .w-full { width: 100%; } @@ -269,19 +269,30 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .dashboard-note strong { flex-shrink: 0; } .dashboard-note p { color: var(--muted); } -.modal-overlay { border: 1px solid var(--shell-border); overflow: hidden; } -.modal-overlay:has(.case-view) { flex-basis: min(60rem, 100%); } -.modal-overlay:has(.ban-dialog) { flex-basis: min(34rem, 100%); } -.modal-box { padding: 1.5rem; min-width: 0; max-height: calc(100dvh - 2 * var(--dialog-gutter) - 2px); overflow: auto; } -.modal-action { display: flex; justify-content: flex-end; margin-top: 1rem; } +.mantine-Modal-content { display: flex; flex-direction: column; border: 1px solid var(--shell-border); background: var(--panel); color: var(--text); overflow: hidden; } +.sf-modal-shell { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; min-height: 0; max-height: calc(100dvh - 2 * var(--dialog-gutter) - 2px); overflow: hidden; } +.mantine-Modal-header { position: static; flex: 0 0 auto; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: .5rem; min-height: 0; padding: 1rem 1.5rem; border-bottom: 1px solid var(--shell-border); background: var(--panel); z-index: auto; } +.sf-modal-header-main { display: flex; align-items: flex-start; gap: .5rem .75rem; width: 100%; min-width: 0; flex-wrap: wrap; } +.sf-modal-title-group { display: flex; flex-direction: column; gap: .125rem; flex: 1 1 0; min-width: 0; } +.sf-modal-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; min-width: 0; } +.mantine-Modal-title { margin: 0; font-size: 1.125rem; line-height: 1.3; font-weight: 750; letter-spacing: -.01em; color: var(--text); min-width: 0; overflow-wrap: anywhere; } +.sf-modal-header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; flex: 0 1 auto; min-width: 0; } +.mantine-Modal-close { flex: 0 0 auto; margin-inline-start: 0; min-width: var(--target-min); min-height: var(--target-min); color: var(--text); background-color: var(--btn-subtle-bg); border: 1px solid var(--shell-border); border-radius: var(--radius-field); } +.mantine-Modal-close:hover:not(:disabled) { background-color: var(--btn-hover); border-color: var(--input-border); } +.mantine-Modal-body { flex: 1 1 auto; min-width: 0; min-height: 0; padding: 1rem 1.5rem; overflow: auto; } +.mantine-Modal-body:where(:not(:only-child)) { padding-top: 1rem; } +.mantine-Modal-body :where(h3) { font-size: .9375rem; line-height: 1.35; font-weight: 700; color: var(--text); } +.mantine-Modal-body p { line-height: 1.5; } +.sf-modal-footer { flex: 0 0 auto; display: flex; justify-content: flex-end; flex-wrap: wrap; align-items: flex-end; gap: .5rem; padding: .75rem 1.5rem 1rem; border-top: 1px solid var(--shell-border); background: var(--panel); } +.sf-modal-footer > .field { margin: 0 auto 0 0; flex: 1 1 13.75rem; } +.sf-modal-footer > .field > .mantine-NativeSelect-root, .sf-modal-footer > .field > select { width: 100%; } .editor-heading { margin-bottom: 1rem; } .editor-heading h3 { margin: .25rem 0 .375rem; } .rule-editor .mantine-Textarea-input { min-height: 10rem; line-height: 1.65; } /* Automod rule editor (#621): header toggles, live summary, then compact sections. */ -.rule-editor { padding-bottom: 0; } .rule-editor-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .625rem; } .rule-editor-header h3 { margin: .125rem 0 0; } -.rule-toggles { display: flex; gap: 1rem; flex-wrap: wrap; padding-top: .25rem; } +.rule-toggles { display: flex; gap: .5rem 1rem; flex-wrap: wrap; align-items: center; padding-top: .125rem; } .toggle-label { display: inline-flex; align-items: center; gap: .5rem; font-size: .75rem; font-weight: 650; color: var(--text); } .rule-summary { margin: 0 0 .75rem; padding: .5rem .75rem; border: 1px solid var(--hero-border); border-left: 3px solid var(--accent); border-radius: .5rem; background: var(--hero); font-weight: 600; line-height: 1.45; } .editor-section { padding: .625rem .75rem; margin-block: .5rem; display: flex; flex-direction: column; gap: .5rem; } @@ -346,16 +357,11 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .editor-advanced > summary { cursor: pointer; font-weight: 650; font-size: var(--ui-font-size-sm); } .editor-advanced[open] > summary { margin-bottom: .5rem; } .editor-advanced > * + * { margin-top: .5rem; } -.modal-action { flex-wrap: wrap; align-items: flex-end; gap: .5rem; padding-top: .75rem; border-top: 1px solid var(--shell-border); } -/* The rule editor keeps Save, Reset and Cancel in view while its sections scroll. */ /* Command editor (#623): the #621 layout with compact step rows. */ .command-editor .mantine-Textarea-input { min-height: 3.5rem; } .command-step .id-picker { margin: 0; } .emoji-select { width: auto; } .raw-behavior { margin: 0; max-height: 14rem; overflow: auto; padding: .5rem .625rem; border: 1px solid var(--shell-border); border-radius: .5rem; background: var(--panel2); font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; } -.rule-editor > .modal-action { position: sticky; bottom: 0; z-index: 1; margin-top: .25rem; padding-bottom: 1rem; background: var(--panel); } -.modal-action > .field { margin: 0 auto 0 0; flex: 1 1 13.75rem; } -.modal-action > .field > .mantine-NativeSelect-root, .modal-action > .field > select { width: 100%; } .commands-table { width: 100%; } .commands-table th { background: var(--panel2); padding-block: .5rem; color: var(--muted); font-size: .75rem; } @@ -420,9 +426,12 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor } @media (max-width: 720px) { .dashboard-note { flex-direction: column; gap: .375rem; } - .modal-box { padding: min(1.25rem, 12px); } - .modal-action .mantine-Button-root { max-width: 100%; height: auto; } - .modal-action .mantine-Button-label { white-space: normal; overflow: visible; } + .mantine-Modal-header { padding: min(.875rem, 10px) min(1.25rem, 12px); } + .sf-modal-header-actions { order: 3; flex: 1 0 100%; } + .mantine-Modal-body { padding: min(1rem, 12px) min(1.25rem, 12px); } + .sf-modal-footer { padding: min(.75rem, 10px) min(1.25rem, 12px); } + .sf-modal-footer .mantine-Button-root { max-width: 100%; height: auto; } + .sf-modal-footer .mantine-Button-label { white-space: normal; overflow: visible; } .editor-columns { grid-template-columns: minmax(0, 1fr); } .template-workspace, .ignore-fields, .routing-fields { grid-template-columns: minmax(0, 1fr); } .editor-footer { align-items: stretch; } @@ -685,14 +694,9 @@ svg.icon-neutral { color: var(--icon-neutral); } .case-avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 1.5rem; height: 1.5rem; border-radius: 999px; background: var(--selected); color: var(--selected-text); font-size: .75rem; font-weight: 700; } .case-avatar-lg { width: 2.5rem; height: 2.5rem; font-size: 1rem; } .case-avatar .icon { width: 1.25rem; height: 1.25rem; } -.modal-box.case-view { display: flex; flex-direction: column; gap: 1rem; padding-bottom: 0; } -.case-header { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; padding-bottom: .75rem; border-bottom: 1px solid var(--shell-border); } -.case-title { display: flex; flex: 1 1 100%; align-items: center; gap: .5rem; min-width: 0; } -.case-header h2 { margin: 0; font-size: 1.125rem; } -.case-header .case-tags { flex: 1 1 100%; } +.case-view-body { display: flex; flex-direction: column; gap: 1rem; } .case-tags { display: flex; flex-wrap: wrap; align-items: center; gap: .375rem; } -.case-close { margin-inline-start: auto; } -.case-loading, .case-error { margin: 0 0 1rem; } +.case-loading, .case-error { margin: 0; } .case-error { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem; } .case-error .err { margin: 0; } .case-section > h3 { margin: 0 0 .5rem; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; } @@ -728,7 +732,7 @@ svg.icon-neutral { color: var(--icon-neutral); } .case-file img, .case-file-placeholder { display: flex; align-items: center; justify-content: center; width: 100%; height: 7.5rem; border-radius: .375rem; background: var(--panel2); object-fit: cover; } .case-file-placeholder .icon { width: 2rem; height: 2rem; } .case-file-meta { display: flex; align-items: center; justify-content: space-between; gap: .375rem; font-size: var(--ui-font-size-sm); } -.case-actions { position: sticky; bottom: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem 1rem; padding: .75rem 0 1rem; border-top: 1px solid var(--shell-border); background: var(--panel); } +.case-actions { gap: .5rem 1rem; } .case-note-form { display: flex; flex: 1 1 20rem; align-items: flex-end; gap: .5rem; min-width: 0; } .case-note-form .mantine-Textarea-root { flex: 1 1 auto; min-width: 0; } .case-note-form .mantine-Textarea-input { min-height: 2.5rem; } @@ -763,10 +767,10 @@ svg.icon-neutral { color: var(--icon-neutral); } .ban-reason-editor { display: flex; flex-direction: column; gap: .375rem; min-width: 14rem; } .ban-reason-editor .mantine-Textarea-root { width: 100%; } .ban-reason-editor .field-help { margin: 0; } -.modal-box.ban-dialog { display: flex; flex-direction: column; gap: 1rem; } .ban-form { display: flex; flex-direction: column; gap: .25rem; } .ban-form .mantine-InputWrapper-root { width: 100%; } .ban-receipt p { margin: 0 0 .5rem; } +.ban-receipt p:last-child { margin-bottom: 0; } /* ==== end Bans (#625) ==== */ /* ==== Bot Resources (#652): process cards and time lines with gaps for missing samples ==== */ diff --git a/scripts/frontend-contrast-test.mjs b/scripts/frontend-contrast-test.mjs index 936c0aea..61064e6f 100644 --- a/scripts/frontend-contrast-test.mjs +++ b/scripts/frontend-contrast-test.mjs @@ -337,6 +337,59 @@ test("daisy-era card, hero, bg-base, rounded-box and text-warning classes are re } }); +test("daisy-era .modal-box, .modal-action, and .modal-overlay classes are removed from frontend sources", () => { + for (const file of [ + "app.js", "administration.js", "appearance.js", "charts.js", "list-controls.js", + "controls.css", "style.css", "index.html", "administration/index.html", + ]) { + const source = readFileSync(new URL(`../frontend/${file}`, import.meta.url), "utf8"); + assert.doesNotMatch(source, /\bmodal-(?:box|action|overlay)\b/, file); + } +}); + +test("Mantine Modal shell, typography, close button, and footer keep Sentinel tokens, targets, and contrast", () => { + assert.equal(declaration(rule(".mantine-Modal-content"), "border"), "1px solid var(--shell-border)"); + assert.equal(declaration(rule(".mantine-Modal-content"), "background"), "var(--panel)"); + assert.equal(declaration(rule(".mantine-Modal-header"), "border-bottom"), "1px solid var(--shell-border)"); + assert.equal(declaration(rule(".mantine-Modal-header"), "background"), "var(--panel)"); + assert.equal(declaration(rule(".sf-modal-footer"), "border-top"), "1px solid var(--shell-border)"); + assert.equal(declaration(rule(".sf-modal-footer"), "background"), "var(--panel)"); + + const titleRule = rule(".mantine-Modal-title"); + assert.match(declaration(titleRule, "font-size"), /^[\d.]+rem$/); + assert.ok(px(declaration(titleRule, "font-size")) <= 20, "modal title stays within page heading scale"); + assert.equal(declaration(titleRule, "color"), "var(--text)"); + + const bodyHeadingRule = rule(".mantine-Modal-body :where(h3)"); + assert.match(declaration(bodyHeadingRule, "font-size"), /^[\d.]+rem$/); + assert.equal(declaration(bodyHeadingRule, "color"), "var(--text)"); + + const closeRule = rule(".mantine-Modal-close"); + assert.equal(declaration(closeRule, "min-width"), "var(--target-min)"); + assert.equal(declaration(closeRule, "min-height"), "var(--target-min)"); + const focus = css.match(/^:is\(([^)]*)\):focus-visible\s*\{([^}]*)\}/m); + assert.ok(focus[1].split(/,\s*/).includes(".mantine-CloseButton-root"), "shared :focus-visible ring covers .mantine-CloseButton-root"); + + const narrow = mediaBlock("(max-width: 720px)", css.slice(css.indexOf("@media (max-width: 1100px)"))); + assert.match(narrow, /\.sf-modal-footer \.mantine-Button-root\s*\{[^}]*max-width:\s*100%;[^}]*height:\s*auto;/); + assert.match(narrow, /\.sf-modal-footer \.mantine-Button-label\s*\{[^}]*white-space:\s*normal;[^}]*overflow:\s*visible;/); + + for (const [theme, selector] of [["light", ":root"], ["dark", ':root[data-theme="dark"]']]) { + const colors = tokens(selector); + for (const [label, fg, bg, floor] of [ + ["modal title on panel", colors["--text"], colors["--panel"], 4.5], + ["modal close icon on rest", colors["--text"], colors["--btn-subtle-bg"], 4.5], + ["modal close icon on hover", colors["--text"], colors["--btn-hover"], 4.5], + ["modal close border on panel", colors["--shell-border"], colors["--panel"], 3], + ["modal close hover border on hover", colors["--input-border"], colors["--btn-hover"], 3], + ["modal border on panel", colors["--shell-border"], colors["--panel"], 3], + ]) { + const ratio = contrast(fg, bg); + assert.ok(ratio >= floor, `${theme} ${label}: ${ratio.toFixed(2)}:1 (need >= ${floor}:1)`); + } + } +}); + test("Mantine Table maps stripe, hover, border and header tokens to Sentinel palette", () => { const appearance = readFileSync(new URL("../frontend/appearance.js", import.meta.url), "utf8"); assert.match(appearance, /"--table-border-color":\s*"var\(--shell-border\)"/); diff --git a/scripts/frontend-state-test.mjs b/scripts/frontend-state-test.mjs index dda702f9..277fa7ce 100644 --- a/scripts/frontend-state-test.mjs +++ b/scripts/frontend-state-test.mjs @@ -185,19 +185,19 @@ function harness(fetchImpl = async () => {}, storage = new Map(), session = new const fn = app[name]; app[name] = (...args) => { fixtureContent.remove(); flushSync(() => { vm.runInContext('ui.set({ view: "main-view" });', context); fn(...args); }); - return document.querySelector('.modal-overlay'); + return document.querySelector('.mantine-Modal-content'); }; } for (const name of ['editRule', 'editCommand']) { const fn = app[name]; app[name] = async (...args) => { fixtureContent.remove(); flushSync(() => { vm.runInContext('ui.set({ view: "main-view" });', context); fn(...args); }); await settle(); - return document.querySelector('.modal-overlay'); + return document.querySelector('.mantine-Modal-content'); }; } const nodes = { get: selector => document.querySelector(selector) }; const toastNode = () => [...document.querySelectorAll('.mantine-Notification-root')].at(-1) ?? null; - const collect = () => Array.from(document.querySelectorAll('#content *, .modal-overlay *, #owner-tools *, .test-panel *')); + const collect = () => Array.from(document.querySelectorAll('#content *, .mantine-Modal-content *, #owner-tools *, .test-panel *')); const elements = { find: predicate => collect().find(predicate), filter: predicate => collect().filter(predicate), some: predicate => collect().some(predicate), [Symbol.iterator]: function* () { yield* collect(); } }; function measureDraftRenders() { const counts = new Map(); @@ -288,7 +288,7 @@ test('Commands fields tell password managers to ignore them', async () => { const panel = h.document.querySelector('#content'); assertPasswordManagerHints(panel, 'input[type="checkbox"]'); await fire(findNode(panel, n => n.localName === 'button' && n.textContent === '+ New custom command'), 'click'); - assertPasswordManagerHints(h.document.querySelector('.modal-overlay'), 'input[placeholder="command name"]', 'textarea'); + assertPasswordManagerHints(h.document.querySelector('.mantine-Modal-content'), 'input[placeholder="command name"]', 'textarea'); }); test('Settings fields tell password managers to ignore them', async () => { @@ -4022,8 +4022,8 @@ for (const kind of ['rule', 'command']) { if (kind === 'rule') await app.editRule({ name: 'Flood', rule_id: 'flood', effective: { params: {}, actions: [{ at: 1, action: 'warn' }] } }); else await app.editCommand(null); assert.equal(app.isDirty(), false, 'opening the editor does not modify it'); - const panel = elements.find(n => n.classList.contains('modal-box')); - assert.equal(Boolean(panel?.closest('.modal-overlay[role=dialog]')), true, + const panel = elements.find(n => n.classList.contains('sf-modal-shell')); + assert.equal(Boolean(panel?.closest('.mantine-Modal-content[role=dialog]')), true, 'the editor is placed inside the accessible dialog'); const button = action === 'add' ? elements.find(n => n.localName === 'button' && (n.textContent === '+ add step' || n.textContent === '+ add action')) @@ -4035,6 +4035,112 @@ for (const kind of ['rule', 'command']) { } } +test('all six modal dialogs use Mantine Modal parts, sizes, and close/dirty-leave semantics', async () => { + const confirms = []; + let allowLeave = false; + const caseId = 'a'.repeat(32); + const h = harness(async (url) => { + const pathname = new URL(url, 'https://ui.example.test').pathname; + if (pathname.endsWith('/server-names')) return response({ roles: [{ id: '22', name: 'Trap' }], channels: [] }); + if (pathname.endsWith('/cases')) return response({ cases: [caseId], names: {}, summaries: { [caseId]: { action: 'ban', outcome: 'succeeded', subject_id: '10', actor_id: '20', occurred_at_ms: 1790000000000 } } }); + if (pathname.endsWith(`/cases/${caseId}/history`)) return response({ history: [], names: {} }); + if (pathname.endsWith(`/cases/${caseId}/evidence`)) return response({ evidence: [] }); + if (pathname.endsWith(`/cases/${caseId}`)) return response({ id: caseId, case: { action: 'ban', outcome: 'succeeded', subject_id: '10', actor_id: '20', occurred_at_ms: 1790000000000, reason: 'Test' }, can_delete: true, names: {} }); + if (pathname.endsWith('/bans')) return response({ bans: [], names: {} }); + return response({ settings: {}, rules: [], commands: [], log_channels: [], badwords: [] }); + }, new Map(), new Map(), (message) => { + confirms.push(message); + return allowLeave; + }); + h.app.state.config = { + enrollment_id: 'membership', + rules: [], + commands: [], + badwords: [], + templates: [], + log_channels: [], + }; + + const verifyModal = (expectedTitle, expectedSize, closeLabel = 'Close') => { + const dialog = h.document.querySelector('.mantine-Modal-content'); + assert.ok(dialog, `${expectedTitle}: dialog mounted`); + assert.equal(dialog.getAttribute('role'), 'dialog'); + assert.equal(dialog.getAttribute('aria-modal'), 'true'); + assert.equal(dialog.closest('.mantine-Modal-root').style.getPropertyValue('--modal-size'), expectedSize, `${expectedTitle}: size`); + const header = dialog.querySelector('.mantine-Modal-header'); + const title = dialog.querySelector('.mantine-Modal-title'); + const closeBtn = dialog.querySelector('.mantine-Modal-close'); + const body = dialog.querySelector('.mantine-Modal-body'); + const footer = dialog.querySelector('.sf-modal-footer'); + assert.ok(header && title && closeBtn && body && footer, `${expectedTitle}: renders Mantine Header/Title/CloseButton/Body and shared footer`); + assert.equal(title.localName, 'h2'); + assert.equal(title.textContent, expectedTitle); + assert.equal(dialog.getAttribute('aria-labelledby'), title.id, `${expectedTitle}: aria-labelledby links Modal.Title`); + assert.equal(dialog.getAttribute('aria-describedby'), body.id, `${expectedTitle}: aria-describedby links Modal.Body`); + assert.equal(closeBtn.getAttribute('aria-label'), closeLabel); + assert.equal(dialog.querySelector('.modal-box, .modal-action, .modal-overlay'), null, `${expectedTitle}: no retired daisy modal classes`); + assert.equal(dialog.classList.contains('modal-overlay'), false); + return { dialog, closeBtn }; + }; + + // 1. RuleEditor: clean close via Modal.CloseButton and dirty close prompt. + await h.app.editRule({ name: 'Flood', rule_id: 'flood', effective: { enabled: true, dry_run: false, params: {}, actions: [{ at: 1, action: 'warn' }] } }); + let { closeBtn } = verifyModal('Edit rule: Flood', '56rem'); + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null, 'clean RuleEditor closes on CloseButton'); + + await h.app.editRule({ name: 'Flood', rule_id: 'flood', effective: { enabled: true, dry_run: false, params: {}, actions: [{ at: 1, action: 'warn' }] } }); + ({ closeBtn } = verifyModal('Edit rule: Flood', '56rem')); + h.app.markDirty(); + allowLeave = false; + await fire(closeBtn, 'click'); + assert.ok(h.document.querySelector('.mantine-Modal-content'), 'dirty RuleEditor stays open when leave is declined'); + assert.equal(confirms.length, 1); + allowLeave = true; + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null, 'dirty RuleEditor closes when leave is confirmed'); + + // 2. CustomRuleEditor: Escape respects dirty-leave and closes clean dialog. + await h.app.editRule({ name: 'Custom spam', rule_id: 'custom:0123456789abcdef', effective: { name: 'Custom spam', enabled: true, dry_run: true, params: { kind: 'pattern', pattern: 'x' }, actions: [{ at: 1, action: 'delete' }] } }); + const { dialog: customDialog } = verifyModal('Edit custom rule: Custom spam', '56rem'); + assert.ok(customDialog.querySelector('[data-autofocus="true"]'), 'FocusTrap.InitialFocus is mounted inside Modal.Content'); + h.app.markDirty(); + allowLeave = false; + await fire(customDialog, 'keydown', { key: 'Escape' }); + assert.ok(h.document.querySelector('.mantine-Modal-content'), 'dirty CustomRuleEditor stays open on Escape when leave is declined'); + allowLeave = true; + await fire(customDialog, 'keydown', { key: 'Escape' }); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null, 'dirty CustomRuleEditor closes on Escape when leave is confirmed'); + + // 3. OnboardingTrapEditor. + await h.app.editRule({ name: 'Onboarding bot trap', rule_id: 'onboarding_bot_trap', effective: { enabled: false, dry_run: true, params: { role_id: null, join_window_minutes: 30, cleanup_window_minutes: 0 }, actions: [{ at: 1, action: 'kick', reason: 'Trap' }] } }); + ({ closeBtn } = verifyModal('Onboarding bot trap', '56rem')); + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); + + // 4. CommandEditor. + await h.app.editCommand(null); + ({ closeBtn } = verifyModal('New custom command', '56rem')); + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); + + // 5. CaseView (60rem, Close case label). + const casesRoot = await casesView(h); + await settle(); + await fire(findNode(casesRoot, n => n.getAttribute?.('aria-label') === `Open case ${caseId}`), 'click'); + await settle(); + ({ closeBtn } = verifyModal(`Case ${caseId.slice(0, 8)}`, '60rem', 'Close case')); + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); + + // 6. BanDialog (34rem). + const bansRoot = await bansView(h); + await fire(findNode(bansRoot, n => n.localName === 'button' && n.textContent === 'Ban user'), 'click'); + ({ closeBtn } = verifyModal('Ban a user', '34rem')); + await fire(closeBtn, 'click'); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); +}); + async function ruleSaveHarness({ scope = 'global', override = false, legacyAck = false } = {}) { const calls = []; const failures = { put: false, lost: false, refresh: false }; @@ -4071,7 +4177,7 @@ async function ruleSaveHarness({ scope = 'global', override = false, legacyAck = h.app.navigate('rules'); await h.app.editRule(h.app.state.config.rules[0]); const content = h.nodes.get('#content'); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); const scopeInput = findNode(modal, (n) => n.localName === 'select' && Array.from(n.children).some((c) => c.getAttribute("value") === 'global')); scopeInput.value = scope; const enabled = findNode(modal, (n) => n.getAttribute("type") === 'checkbox'); @@ -4181,7 +4287,7 @@ test('a refused command save retains its checkbox value for the next save', asyn h.app.navigate('commands'); await h.app.editCommand(null); const content = h.nodes.get('#content'); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); const name = findNode(modal, (n) => n.getAttribute("placeholder") === 'command name'); name.value = 'hello'; await fire(name, 'input'); @@ -5760,10 +5866,10 @@ test('wrapped navigation leaves content and picker options reachable at enlarged hub.click(); const add = await find('.automod-rules .page-header-actions button'); add.click(); - const modal = await find('.modal-box'); + const modal = await find('.mantine-Modal-content'); await frame(); const modalRect = modal.getBoundingClientRect(); - const actions = [...modal.querySelectorAll('.modal-action button')].filter(b => !b.hidden && b.offsetParent).map(button => { + const actions = [...modal.querySelectorAll('.sf-modal-footer button')].filter(b => !b.hidden && b.offsetParent).map(button => { const rect = button.getBoundingClientRect(); const label = button.querySelector('.mantine-Button-label') ?? button; return { @@ -8899,7 +9005,7 @@ test('custom rule rename updates the card heading after save without reloading', const heading = () => h.document.querySelector('#content .rule-heading h3').textContent; assert.equal(heading(), 'Original name'); await fire(findNode(h.nodes.get('#content'), n => n.localName === 'button' && n.getAttribute('aria-label') === 'Edit'), 'click'); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); const nameField = [...modal.querySelectorAll('.field')].find(n => n.querySelector('label')?.textContent === 'Name'); const name = nameField.querySelector('input'); name.value = 'Renamed rule'; @@ -8910,11 +9016,11 @@ test('custom rule rename updates the card heading after save without reloading', assert.equal(heading(), 'Original name'); acknowledge(response({ ok: true, config_patch: { kind: 'rule', id, scope: 'guild', value: calls[0].body.data } })); await settle(); - assert.equal(h.document.querySelector('.modal-overlay'), null); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); assert.equal(heading(), 'Renamed rule'); assert.equal(calls.length, 1, 'the acknowledged patch must not need a configuration reload'); await fire(findNode(h.nodes.get('#content'), n => n.localName === 'button' && n.getAttribute('aria-label') === 'Edit'), 'click'); - assert.equal(h.document.querySelector('.modal-overlay h3').textContent, 'Edit custom rule: Renamed rule'); + assert.equal(h.document.querySelector('.mantine-Modal-content .mantine-Modal-title').textContent, 'Edit custom rule: Renamed rule'); }); test('honeypot switch shows the kick action that save submits', async () => { @@ -8993,7 +9099,7 @@ test('built-in onboarding trap starts off, warns on unsafe setup, and saves a gu const edit = async () => { await fire(findNode(card, n => n.localName === 'button' && n.getAttribute('aria-label') === 'Edit'), 'click'); await settle(); - return h.document.querySelector('.modal-overlay'); + return h.document.querySelector('.mantine-Modal-content'); }; const save = (modal) => fire(findNode(modal, n => n.localName === 'button' && textOf(n) === 'Save'), 'click'); let modal = await edit(); @@ -9067,7 +9173,7 @@ test('delegated settings can edit cleanup while onboarding role removal stays lo const card = h.nodes.get('#content'); await fire(findNode(card, n => n.localName === 'button' && n.getAttribute('aria-label') === 'Edit'), 'click'); await settle(); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); assert.match(textOf(modal), /Manage Server to change or activate role removal/); assert.ok(![...modal.querySelectorAll('label')].some(label => textOf(label) === 'Roles to remove before kicking')); assert.equal(pickerLabelled(modal, 'Enabled').disabled, !enabled && !dryRun); @@ -9179,7 +9285,7 @@ test('No links or media preset requires channels and saves ordered actions and r h.app.navigate('rules'); const button = (root, text) => findNode(root, n => n.localName === 'button' && textOf(n) === text); await fire(button(h.nodes.get('#content'), 'No links or media'), 'click'); - const modal = h.nodes.get('.modal-overlay'); + const modal = h.nodes.get('.mantine-Modal-content'); const control = (text) => findNode(modal, n => n.localName === 'label' && textOf(n) === text).control; const enabled = control('Enabled'); assert.equal(enabled.checked, false); @@ -9263,7 +9369,7 @@ test('No links or media reports removed channels and uses the saved disabled sta h.app.state.config = { enrollment_id: 'membership', rules: [record] }; const modal = await h.app.editRule(record); await fire(findNode(modal, n => n.localName === 'button' && textOf(n) === 'Save'), 'click'); - assert.equal(h.nodes.get('.modal-overlay'), null); + assert.equal(h.nodes.get('.mantine-Modal-content'), null); assert.equal(h.app.state.config.rules[0].effective.enabled, false); assert.deepEqual(Array.from(h.app.state.config.rules[0].effective.include_channels), []); assert.equal(h.toast().textContent, 'Rule saved. Removed 1 unavailable channel. The rule is now off.'); @@ -9720,7 +9826,7 @@ test('untouched rule reload recovers reordered nested parameters', async () => { await fire(first.elements.find(n=>n.localName==='button' && n.textContent==='Cancel'),'click'); await first.app.editRule(initial); first.failures.lost = true; - const params = findNode(first.document.querySelector('.modal-overlay'), n => n.localName === 'label' && textOf(n) === 'Window (seconds)').control; + const params = findNode(first.document.querySelector('.mantine-Modal-content'), n => n.localName === 'label' && textOf(n) === 'Window (seconds)').control; params.value = '12'; await fire(params,'input'); await fire(first.elements.find(n=>n.localName==='button' && n.textContent==='Save'),'click'); const original = first.calls.find(c=>c.method==='PUT'); @@ -9771,7 +9877,7 @@ test('global rule retry after detection edits preserves a newer guild override', const h = await ruleSaveHarness({scope:'global', override:true}); h.app.state.config.enrollment_id = 'abcdef0123456789abcdef0123456789'; h.failures.lost = true; - const params = findNode(h.document.querySelector('.modal-overlay'), n => n.localName === 'label' && textOf(n) === 'Window (seconds)').control; + const params = findNode(h.document.querySelector('.mantine-Modal-content'), n => n.localName === 'label' && textOf(n) === 'Window (seconds)').control; params.value = '12'; await fire(params,'input'); await fire(h.save,'click'); const first = h.calls.find(c=>c.method==='PUT'); assert.equal(first.body.scope,'global'); @@ -10656,7 +10762,7 @@ test('Badwords setup reaches existing rule enable escalation exemptions without h.app.state.config = {badwords: [], rules: [rule]}; h.app.state.tab = 'badwords'; h.app.renderTab(); const settings = [...h.document.querySelectorAll('button')].find(n => n.textContent === 'Edit actions & exemptions'); assert.ok(settings); await fire(settings, 'click'); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); for (const text of ['Enabled', 'Dry-run', 'Actions', 'Skip roles', 'Skip moderators']) assert.ok(modal.textContent.includes(text)); assert.doesNotMatch(modal.textContent, /Parameters \(JSON\)/); const other = await h.app.editRule({...rule, rule_id: 'mention_spam'}); @@ -10820,7 +10926,7 @@ test('Badwords rule saves enable actions and exemptions through the setup path', h.app.state.config = {enrollment_id: 'membership', badwords: [], rules: [rule]}; h.app.state.tab = 'badwords'; h.app.renderTab(); await fire([...h.document.querySelectorAll('button')].find(n => n.textContent === 'Edit actions & exemptions'), 'click'); - const modal = h.document.querySelector('.modal-overlay'); + const modal = h.document.querySelector('.mantine-Modal-content'); await fire(modal.querySelector('input[type="checkbox"]'), 'change', {target: {checked: true}}); await chooseOption(modal.querySelector('.escalation-step select'), 'Timeout'); const roles = findNode(modal, n => n.localName === 'label' && textOf(n).startsWith('Skip roles')).control; @@ -10832,7 +10938,7 @@ test('Badwords rule saves enable actions and exemptions through the setup path', assert.deepEqual(submitted.data.whitelist_roles, ['9007199254740993']); assert.deepEqual(submitted.data.params, {}); assert.equal(h.app.state.tab, 'badwords'); - assert.equal(h.document.querySelector('.modal-overlay'), null); + assert.equal(h.document.querySelector('.mantine-Modal-content'), null); }); // #622: Badwords, Known spam and Known-bad images share one page pattern. @@ -12275,7 +12381,7 @@ test('Case view opens the last row of a full page and renders required reads bef await fire(findNode(root, n => n.getAttribute?.('aria-label') === `Open case ${last}`), 'click', {}); const dialog = caseDialog(h); assert.ok(dialog, 'the dialog opens at once'); - assert.equal(h.document.querySelector('.modal-overlay').getAttribute('aria-label'), `Case ${last.slice(0, 8)}`); + assert.equal(h.document.querySelector('.mantine-Modal-content').getAttribute('aria-label'), `Case ${last.slice(0, 8)}`); assert.match(dialog.querySelector('[role="status"]').textContent, /Loading case/); assert.equal(h.app.isBusy(), false, 'opening a case does not grey out the page'); // The three required reads start before any answers. diff --git a/scripts/package-webui-test.mjs b/scripts/package-webui-test.mjs index 98b04331..eb2064fb 100644 --- a/scripts/package-webui-test.mjs +++ b/scripts/package-webui-test.mjs @@ -105,10 +105,10 @@ test("WebUI ships Mantine components without the retired UI libraries", () => { test("WebUI CSS retains used widgets and excludes unused component families", () => { const css = fs.readFileSync(path.join(repo, "dist/frontend/style.css"), "utf8"); - for (const name of ["alert", "badge", "menu", "modal-overlay", "sf-card", "sf-card-body", "sf-empty-panel", "stat"]) { + for (const name of ["alert", "badge", "menu", "sf-card", "sf-card-body", "sf-empty-panel", "sf-modal-footer", "stat"]) { assert.ok(new RegExp("\\." + name + "(?=[^a-zA-Z0-9_-])").test(css), "missing " + name); } - for (const name of ["btn", "card", "card-actions", "card-body", "card-border", "card-title", "checkbox", "hero", "hero-content", "hero-copy", "input", "select", "table", "table-zebra", "textarea", "toggle"]) { + for (const name of ["btn", "card", "card-actions", "card-body", "card-border", "card-title", "checkbox", "hero", "hero-content", "hero-copy", "input", "modal-action", "modal-box", "modal-overlay", "select", "table", "table-zebra", "textarea", "toggle"]) { assert.ok(!new RegExp("\\." + name + "(?=[^a-zA-Z0-9_-])").test(css), `retired daisy .${name} must not be emitted`); } assert.ok(css.includes(".table-scroll{"), "horizontal table scroll wrapper must stay emitted"); @@ -118,7 +118,7 @@ test("WebUI CSS retains used widgets and excludes unused component families", () // Selective imports keep unused Mantine component styles out of the release. const { css: metadata } = JSON.parse(fs.readFileSync(path.join(repo, "dist/webui-metafile.json"), "utf8")); assert.ok(!Object.keys(metadata.inputs).some((name) => /@mantine\/core\/styles(?:\.layer)?\.css$/.test(name))); - for (const name of ["ActionIcon", "Button", "Checkbox", "Combobox", "InlineInput", "Input", "Paper", "Switch", "Table"]) { + for (const name of ["ActionIcon", "Button", "Checkbox", "CloseButton", "Combobox", "InlineInput", "Input", "Modal", "ModalBase", "Overlay", "Paper", "Switch", "Table"]) { assert.ok(Object.keys(metadata.inputs).some((file) => file.endsWith(`/@mantine/core/styles/${name}.layer.css`)), "missing Mantine CSS " + name); } for (const name of ["bg-base-100", "bg-base-200", "bg-base-300", "rounded-box", "rounded-t-box", "rounded-selector", "text-secondary", "text-warning"]) { From 204d5f96d965f17e3b35516a70dcc9ff44494cef Mon Sep 17 00:00:00 2001 From: jatmn Date: Thu, 3 Dec 2026 23:47:35 -0800 Subject: [PATCH 2/2] fix(webui): unify modal scroll on short/enlarged viewports and omit aria-describedby on rich bodies --- frontend/app.js | 2 +- frontend/style.css | 13 ++++--- scripts/frontend-contrast-test.mjs | 6 +++- scripts/frontend-state-test.mjs | 55 ++++++++++++++++++++++++++++-- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/frontend/app.js b/frontend/app.js index 247f3a15..a516b562 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -3322,7 +3322,7 @@ function ModalDialogShell({ ), headerSub, ), - h(Modal.Body, { className: bodyClassName || undefined }, children), + h("div", { className: `sf-modal-body ${bodyClassName}`.trim() }, children), footer ? h("footer", { className: `sf-modal-footer ${footerClassName}`.trim() }, footer) : null, ); } diff --git a/frontend/style.css b/frontend/style.css index e65f5433..2456d790 100644 --- a/frontend/style.css +++ b/frontend/style.css @@ -279,10 +279,9 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .sf-modal-header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; flex: 0 1 auto; min-width: 0; } .mantine-Modal-close { flex: 0 0 auto; margin-inline-start: 0; min-width: var(--target-min); min-height: var(--target-min); color: var(--text); background-color: var(--btn-subtle-bg); border: 1px solid var(--shell-border); border-radius: var(--radius-field); } .mantine-Modal-close:hover:not(:disabled) { background-color: var(--btn-hover); border-color: var(--input-border); } -.mantine-Modal-body { flex: 1 1 auto; min-width: 0; min-height: 0; padding: 1rem 1.5rem; overflow: auto; } -.mantine-Modal-body:where(:not(:only-child)) { padding-top: 1rem; } -.mantine-Modal-body :where(h3) { font-size: .9375rem; line-height: 1.35; font-weight: 700; color: var(--text); } -.mantine-Modal-body p { line-height: 1.5; } +.sf-modal-body { flex: 1 1 auto; min-width: 0; min-height: 0; padding: 1rem 1.5rem; overflow: auto; } +.sf-modal-body :where(h3) { font-size: .9375rem; line-height: 1.35; font-weight: 700; color: var(--text); } +.sf-modal-body p { line-height: 1.5; } .sf-modal-footer { flex: 0 0 auto; display: flex; justify-content: flex-end; flex-wrap: wrap; align-items: flex-end; gap: .5rem; padding: .75rem 1.5rem 1rem; border-top: 1px solid var(--shell-border); background: var(--panel); } .sf-modal-footer > .field { margin: 0 auto 0 0; flex: 1 1 13.75rem; } .sf-modal-footer > .field > .mantine-NativeSelect-root, .sf-modal-footer > .field > select { width: 100%; } @@ -428,7 +427,7 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .dashboard-note { flex-direction: column; gap: .375rem; } .mantine-Modal-header { padding: min(.875rem, 10px) min(1.25rem, 12px); } .sf-modal-header-actions { order: 3; flex: 1 0 100%; } - .mantine-Modal-body { padding: min(1rem, 12px) min(1.25rem, 12px); } + .sf-modal-body { padding: min(1rem, 12px) min(1.25rem, 12px); } .sf-modal-footer { padding: min(.75rem, 10px) min(1.25rem, 12px); } .sf-modal-footer .mantine-Button-root { max-width: 100%; height: auto; } .sf-modal-footer .mantine-Button-label { white-space: normal; overflow: visible; } @@ -437,6 +436,10 @@ pre.code { background: var(--panel2); border: 1px solid var(--shell-border); bor .editor-footer { align-items: stretch; } .editor-footer .row { flex-wrap: wrap; } } +@media (max-height: 36rem) { + .sf-modal-shell { overflow: auto; } + .sf-modal-body { flex: 0 0 auto; overflow: visible; } +} /* Owner Updates shares the workspace palette and Mantine components. */ .administration-page #content { padding: 1.25rem 1.5rem; gap: 1rem; } diff --git a/scripts/frontend-contrast-test.mjs b/scripts/frontend-contrast-test.mjs index 61064e6f..beaf0267 100644 --- a/scripts/frontend-contrast-test.mjs +++ b/scripts/frontend-contrast-test.mjs @@ -360,10 +360,14 @@ test("Mantine Modal shell, typography, close button, and footer keep Sentinel to assert.ok(px(declaration(titleRule, "font-size")) <= 20, "modal title stays within page heading scale"); assert.equal(declaration(titleRule, "color"), "var(--text)"); - const bodyHeadingRule = rule(".mantine-Modal-body :where(h3)"); + const bodyHeadingRule = rule(".sf-modal-body :where(h3)"); assert.match(declaration(bodyHeadingRule, "font-size"), /^[\d.]+rem$/); assert.equal(declaration(bodyHeadingRule, "color"), "var(--text)"); + const shortViewport = mediaBlock("(max-height: 36rem)", css); + assert.match(shortViewport, /\.sf-modal-shell\s*\{[^}]*overflow:\s*auto;/); + assert.match(shortViewport, /\.sf-modal-body\s*\{[^}]*flex:\s*0 0 auto;[^}]*overflow:\s*visible;/); + const closeRule = rule(".mantine-Modal-close"); assert.equal(declaration(closeRule, "min-width"), "var(--target-min)"); assert.equal(declaration(closeRule, "min-height"), "var(--target-min)"); diff --git a/scripts/frontend-state-test.mjs b/scripts/frontend-state-test.mjs index 277fa7ce..cdd1a9f8 100644 --- a/scripts/frontend-state-test.mjs +++ b/scripts/frontend-state-test.mjs @@ -4070,13 +4070,13 @@ test('all six modal dialogs use Mantine Modal parts, sizes, and close/dirty-leav const header = dialog.querySelector('.mantine-Modal-header'); const title = dialog.querySelector('.mantine-Modal-title'); const closeBtn = dialog.querySelector('.mantine-Modal-close'); - const body = dialog.querySelector('.mantine-Modal-body'); + const body = dialog.querySelector('.sf-modal-body'); const footer = dialog.querySelector('.sf-modal-footer'); - assert.ok(header && title && closeBtn && body && footer, `${expectedTitle}: renders Mantine Header/Title/CloseButton/Body and shared footer`); + assert.ok(header && title && closeBtn && body && footer, `${expectedTitle}: renders Mantine Header/Title/CloseButton with shared body and footer`); assert.equal(title.localName, 'h2'); assert.equal(title.textContent, expectedTitle); assert.equal(dialog.getAttribute('aria-labelledby'), title.id, `${expectedTitle}: aria-labelledby links Modal.Title`); - assert.equal(dialog.getAttribute('aria-describedby'), body.id, `${expectedTitle}: aria-describedby links Modal.Body`); + assert.equal(dialog.getAttribute('aria-describedby'), null, `${expectedTitle}: structured body is not wired as aria-describedby`); assert.equal(closeBtn.getAttribute('aria-label'), closeLabel); assert.equal(dialog.querySelector('.modal-box, .modal-action, .modal-overlay'), null, `${expectedTitle}: no retired daisy modal classes`); assert.equal(dialog.classList.contains('modal-overlay'), false); @@ -6725,6 +6725,55 @@ test('the last case of a full page opens on screen and its file stacks on narrow if (width < 720) assert.ok(moderator.top >= subject.bottom, `${width}px: Who cards stack`); else assert.equal(Math.round(moderator.top), Math.round(subject.top), `${width}px: Who cards sit side by side`); } + + // Enlarged text on short/narrow viewports: unified dialog scrolling keeps case content and footer actions reachable. + const enlargedBrowser = await launchFirefox(32); + try { + for (const [width, height] of [[360, 640], [667, 375]]) { + await enlargedBrowser.send('browsingContext.setViewport', { context: enlargedBrowser.context, viewport: { width, height } }); + await enlargedBrowser.send('browsingContext.navigate', { context: enlargedBrowser.context, url, wait: 'complete' }); + const { type, result, exceptionDetails } = await enlargedBrowser.send('script.evaluate', { + target: { context: enlargedBrowser.context }, + awaitPromise: true, + expression: `(async () => { + const wait = () => new Promise(resolve => setTimeout(resolve, 50)); + const frame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); + for (let i = 0; i < 200 && !document.querySelector('#hub-nav [data-hub="records"]'); i++) await wait(); + document.querySelector('#hub-nav [data-hub="records"]').click(); + for (let i = 0; i < 200 && !document.querySelector('#tabs [data-tab="cases"]'); i++) await wait(); + document.querySelector('#tabs [data-tab="cases"]').click(); + for (let i = 0; i < 200 && document.querySelectorAll('tbody tr').length < 50; i++) await wait(); + [...document.querySelectorAll('button[aria-label^="Open case"]')].at(-1).click(); + for (let i = 0; i < 200 && !document.querySelector('.case-view .case-who'); i++) await wait(); + await frame(); + const shell = document.querySelector('.sf-modal-shell'); + const body = shell.querySelector('.sf-modal-body'); + const removeBtn = [...shell.querySelectorAll('.sf-modal-footer button')].find(b => b.textContent.includes('Remove case record')); + const shellRect = shell.getBoundingClientRect(); + const bodyHeight = body.getBoundingClientRect().height; + shell.scrollTop = shell.scrollHeight; + await frame(); + const removeRect = removeBtn.getBoundingClientRect(); + return JSON.stringify({ + viewport: { width: innerWidth, height: innerHeight }, + shellRect: shellRect.toJSON(), + shellScrollHeight: shell.scrollHeight, + shellClientHeight: shell.clientHeight, + bodyHeight, + removeRect: removeRect.toJSON(), + }); + })()`, + }); + assert.equal(type, 'success', exceptionDetails?.text); + const m = JSON.parse(result.value); + assert.ok(m.bodyHeight >= 100, `${width}×${height} @32px: case body must remain readable (${JSON.stringify(m)})`); + assert.ok(m.shellScrollHeight > m.shellClientHeight, `${width}×${height} @32px: shell scrolls when dialog exceeds viewport`); + assert.ok(m.removeRect.bottom <= m.shellRect.bottom + 1 && m.removeRect.bottom <= m.viewport.height + 1, + `${width}×${height} @32px: Remove case record is reachable after scrolling (${JSON.stringify(m)})`); + } + } finally { + await enlargedBrowser.close(); + } }); test('text rule UI can save independent thresholds without generic escalation', async () => {