Skip to content

Refactor theme management and disable modal in ThemePanel - #4

Merged
roble merged 2 commits into
mainfrom
dev
Apr 18, 2026
Merged

Refactor theme management and disable modal in ThemePanel#4
roble merged 2 commits into
mainfrom
dev

Conversation

@roble

@roble roble commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

This pull request refactors how theme field definitions are accessed throughout the codebase by replacing the static FIELD_DEFS array with a new themeFields() function. This change ensures that field definitions are generated dynamically when needed, improving maintainability and future extensibility. The update touches multiple files, including the main theme panel component and utility functions, to consistently use the new approach.

Refactoring theme field definitions:

  • Replaced all imports and usages of the static FIELD_DEFS array with the new themeFields() function in ThemePanel.vue and theme.ts, ensuring that field definitions are always retrieved dynamically. [1] [2] [3]
  • Updated fields.ts to export themeFields as a function that returns the field definitions, and removed the static FIELD_DEFS export. [1] [2] [3]

Theme variable management improvements:

  • Refactored the computation of managed CSS variables (MANAGED_VARS_SET, NON_COLOR_FIELD_VARS, FONT_FIELD_VARS) to be dynamically derived from the result of themeFields(), ensuring that any future changes to field definitions are automatically reflected in theme variable logic. [1] [2] [3]

Minor UI adjustment:

  • Adjusted the Sheet component in ThemePanel.vue to use :modal="false" and slightly changed its width class from sm:w-110 to sm:w-105 for improved layout.

Copilot AI review requested due to automatic review settings April 18, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors theme field definition access from a static export (FIELD_DEFS) to a dynamic generator (themeFields()), and updates consumers to use the new API. It also adjusts the ThemePanel sheet behavior/layout (non-modal sheet + width tweak).

Changes:

  • Replaced FIELD_DEFS imports/usages with themeFields() across theme utilities and the ThemePanel.
  • Moved theme field definitions in fields.ts into a themeFields() function (and default export) instead of a static array.
  • Updated ThemePanel’s Sheet to be non-modal and adjusted its responsive width class.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
resources/js/utils/theme.ts Switches allowlist derivation to use themeFields() within applyThemeVars.
resources/js/fields.ts Converts static field definitions into a themeFields() function and removes FIELD_DEFS.
resources/js/components/ThemePanel.vue Updates field initialization/group derivation to use themeFields(); makes the sheet non-modal and tweaks width.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 78 to +83
// Apply only managed vars from the current mode — skip anything not in FIELD_DEFS
Object.entries(modeVars).forEach(([key, value]) => {
if (!MANAGED_VARS_SET.has(key)) return;
const vars = new Set(themeFieldsList.flatMap((f) => f.vars));

if (!vars.has(key)) return;

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vars is rebuilt inside the Object.entries(modeVars).forEach callback, which re-flattens themeFieldsList and allocates a new Set for every theme var. Compute the managed-vars Set once (outside the loop) and reuse it for the allowlist check. Also update the comment to no longer reference FIELD_DEFS since it was removed.

Copilot uses AI. Check for mistakes.
Comment on lines 95 to +101
Object.entries(lightVars).forEach(([key, value]) => {
if (!NON_COLOR_FIELD_VARS.has(key)) return;
const nonColorVars = new Set(
themeFieldsList.filter((f) => f.type !== 'color').flatMap((f) => f.vars),
);

if (!nonColorVars.has(key)) return;

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonColorVars is recomputed inside the Object.entries(lightVars).forEach callback, which repeats the filter(...).flatMap(...) work for every entry. Build this Set once per applyThemeVars call (next to fontFieldVars) and reuse it inside the loop.

Copilot uses AI. Check for mistakes.
Comment on lines 174 to 180
const fields = reactive<FieldState[]>(
FIELD_DEFS.map((f) => ({ ...f, value: '' })),
themeFields().map((f) => ({ ...f, value: '' })),
);

const uniqueGroups = FIELD_DEFS.filter((f) => f.group)
const uniqueGroups = themeFields().filter((f) => f.group)
.map((f) => f.group!)
.filter((g, i, arr) => arr.findIndex((x) => x.name === g.name) === i);

Copilot AI Apr 18, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

themeFields() is invoked twice during setup (for fields and uniqueGroups), which regenerates the full field definition list twice. Consider calling themeFields() once (e.g., const fieldDefs = themeFields()) and reusing it for both to avoid duplicate work and keep any per-call object instances consistent.

Copilot uses AI. Check for mistakes.
@roble
roble merged commit 28dcd7d into main Apr 18, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants