From 760de588a8b65639737a5e2bdfdac5543a0227e0 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 2 Jun 2026 01:55:11 -0400 Subject: [PATCH 1/5] feat: add Codex-token-mapped AG Grid theme module --- extension.json | 3 +- modules/ext.aggrid/theme.js | 36 +++++++++++++++++++++++ tests/vitest/ext.aggrid/theme.test.js | 41 +++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 modules/ext.aggrid/theme.js create mode 100644 tests/vitest/ext.aggrid/theme.test.js diff --git a/extension.json b/extension.json index 7d87360..6b771ab 100644 --- a/extension.json +++ b/extension.json @@ -34,7 +34,8 @@ "ext.aggrid": { "packageFiles": [ "ext.aggrid/init.js", - "ext.aggrid/mountGrid.js" + "ext.aggrid/mountGrid.js", + "ext.aggrid/theme.js" ], "styles": [ "ext.aggrid/ext.aggrid.less" diff --git a/modules/ext.aggrid/theme.js b/modules/ext.aggrid/theme.js new file mode 100644 index 0000000..22544ff --- /dev/null +++ b/modules/ext.aggrid/theme.js @@ -0,0 +1,36 @@ +/* global agGrid */ + +// AG Grid theme colour params mapped to Codex design tokens (CSS variables). +// The grid follows the wiki light/dark/OS scheme and skin colour +// customisations through the cascade — no JS theme-syncing. Fallbacks are the +// REL1_43 light token values, so skins without Codex tokens still render a +// usable light grid. Typography inherits the page font; AG Grid's concrete +// fontSize/spacing defaults are kept (it needs them for row-height layout). +const THEME_PARAMS = { + backgroundColor: 'var(--background-color-base, #fff)', + foregroundColor: 'var(--color-base, #202122)', + borderColor: 'var(--border-color-base, #a2a9b1)', + chromeBackgroundColor: 'var(--background-color-neutral-subtle, #f8f9fa)', + headerBackgroundColor: 'var(--background-color-neutral-subtle, #f8f9fa)', + headerTextColor: 'var(--color-base, #202122)', + accentColor: 'var(--color-progressive, #36c)', + rowHoverColor: 'var(--background-color-interactive-subtle, #f8f9fa)', + selectedRowBackgroundColor: 'var(--background-color-progressive-subtle, #f1f4fd)', + fontFamily: 'inherit' +}; + +let cachedTheme = null; + +/** + * The shared AG Grid theme, built once from themeQuartz. + * + * @return {Object} An AG Grid Theme object. + */ +function getWikiTheme() { + if ( !cachedTheme ) { + cachedTheme = agGrid.themeQuartz.withParams( THEME_PARAMS ); + } + return cachedTheme; +} + +module.exports = { THEME_PARAMS: THEME_PARAMS, getWikiTheme: getWikiTheme }; diff --git a/tests/vitest/ext.aggrid/theme.test.js b/tests/vitest/ext.aggrid/theme.test.js new file mode 100644 index 0000000..1bcb08a --- /dev/null +++ b/tests/vitest/ext.aggrid/theme.test.js @@ -0,0 +1,41 @@ +const { THEME_PARAMS, getWikiTheme } = require( '../../../modules/ext.aggrid/theme.js' ); + +describe( 'THEME_PARAMS', () => { + const expected = { + backgroundColor: 'var(--background-color-base, #fff)', + foregroundColor: 'var(--color-base, #202122)', + borderColor: 'var(--border-color-base, #a2a9b1)', + chromeBackgroundColor: 'var(--background-color-neutral-subtle, #f8f9fa)', + headerBackgroundColor: 'var(--background-color-neutral-subtle, #f8f9fa)', + headerTextColor: 'var(--color-base, #202122)', + accentColor: 'var(--color-progressive, #36c)', + rowHoverColor: 'var(--background-color-interactive-subtle, #f8f9fa)', + selectedRowBackgroundColor: 'var(--background-color-progressive-subtle, #f1f4fd)' + }; + + it( 'maps every colour param to a Codex token with a fallback', () => { + Object.keys( expected ).forEach( ( key ) => { + expect( THEME_PARAMS[ key ] ).toBe( expected[ key ] ); + } ); + } ); + + it( 'inherits typography rather than setting a font', () => { + expect( THEME_PARAMS.fontFamily ).toBe( 'inherit' ); + expect( THEME_PARAMS.fontSize ).toBeUndefined(); + } ); +} ); + +describe( 'getWikiTheme', () => { + it( 'builds the theme from themeQuartz.withParams and memoises it', () => { + const built = { id: 'wiki-theme' }; + const withParams = vi.fn( () => built ); + global.agGrid = { themeQuartz: { withParams } }; + + expect( getWikiTheme() ).toBe( built ); + expect( getWikiTheme() ).toBe( built ); + expect( withParams ).toHaveBeenCalledTimes( 1 ); + expect( withParams ).toHaveBeenCalledWith( THEME_PARAMS ); + + delete global.agGrid; + } ); +} ); From 07d52cf60b5b0eb8c74951deb9b9cfa08467a33c Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 2 Jun 2026 01:56:56 -0400 Subject: [PATCH 2/5] feat: apply Codex-themed grid and follow wiki light/dark mode Co-Authored-By: Claude Sonnet 4.6 --- modules/ext.aggrid/ext.aggrid.less | 3 +++ modules/ext.aggrid/mountGrid.js | 6 ++++++ tests/vitest/ext.aggrid/mountGrid.test.js | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/modules/ext.aggrid/ext.aggrid.less b/modules/ext.aggrid/ext.aggrid.less index 1481057..8cf59ba 100644 --- a/modules/ext.aggrid/ext.aggrid.less +++ b/modules/ext.aggrid/ext.aggrid.less @@ -1,4 +1,7 @@ .ext-aggrid { width: 100%; height: 400px; + /* Inherit the page color-scheme so Citizen's light-dark() tokens resolve + to the wiki's current mode. */ + color-scheme: inherit; } diff --git a/modules/ext.aggrid/mountGrid.js b/modules/ext.aggrid/mountGrid.js index 85d3be4..0f26047 100644 --- a/modules/ext.aggrid/mountGrid.js +++ b/modules/ext.aggrid/mountGrid.js @@ -1,5 +1,7 @@ /* global agGrid */ +const { getWikiTheme } = require( './theme.js' ); + const PLACEHOLDER_SELECTOR = '.ext-aggrid'; const CONFIG_ATTR = 'data-mw-aggrid-options'; // Marks a placeholder as already mounted so re-runs (e.g. wikipage.content @@ -38,6 +40,10 @@ function mountGrid( el ) { if ( !gridOptions ) { return; } + // Apply the wiki theme unless the author already chose one. + if ( !gridOptions.theme ) { + gridOptions.theme = getWikiTheme(); + } // Mark before mounting so a concurrent/re-entrant pass can't double-mount. el.classList.add( INIT_CLASS ); // agGrid is the global exposed by the vendored AG Grid bundle. diff --git a/tests/vitest/ext.aggrid/mountGrid.test.js b/tests/vitest/ext.aggrid/mountGrid.test.js index 06979bb..0c8f753 100644 --- a/tests/vitest/ext.aggrid/mountGrid.test.js +++ b/tests/vitest/ext.aggrid/mountGrid.test.js @@ -30,7 +30,10 @@ describe( 'parseConfig', () => { describe( 'mountGrid', () => { beforeEach( () => { - global.agGrid = { createGrid: vi.fn() }; + global.agGrid = { + createGrid: vi.fn(), + themeQuartz: { withParams: () => ( { __wiki: true } ) } + }; } ); afterEach( () => { @@ -57,4 +60,18 @@ describe( 'mountGrid', () => { expect( global.agGrid.createGrid ).not.toHaveBeenCalled(); expect( el.classList.contains( 'ext-aggrid--init' ) ).toBe( false ); } ); + + it( 'applies the wiki theme when the config has none', () => { + const el = makeEl( '{"columnDefs":[],"rowData":[]}' ); + mountGrid( el ); + const opts = global.agGrid.createGrid.mock.calls[ 0 ][ 1 ]; + expect( opts.theme ).toEqual( { __wiki: true } ); + } ); + + it( 'preserves a theme already set in the config', () => { + const el = makeEl( '{"columnDefs":[],"rowData":[],"theme":"legacy"}' ); + mountGrid( el ); + const opts = global.agGrid.createGrid.mock.calls[ 0 ][ 1 ]; + expect( opts.theme ).toBe( 'legacy' ); + } ); } ); From 206d2273d614880c96070bccc8c2b30d83e6c278 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 2 Jun 2026 02:00:17 -0400 Subject: [PATCH 3/5] fix: inherit browser color-scheme so grid follows wiki dark mode AG Grid's themeQuartz defaults browserColorScheme to "light", emitting color-scheme: light on .ag-root-wrapper, which pinned Citizen's light-dark() Codex tokens to their light values inside the grid. Set browserColorScheme: 'inherit' so the wrapper inherits the page scheme. Verified: the grid background flips dark (night) / light (day) with the wiki theme toggle. Co-Authored-By: Claude Opus 4.8 (1M context) --- modules/ext.aggrid/theme.js | 6 +++++- tests/vitest/ext.aggrid/theme.test.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/ext.aggrid/theme.js b/modules/ext.aggrid/theme.js index 22544ff..352dcf9 100644 --- a/modules/ext.aggrid/theme.js +++ b/modules/ext.aggrid/theme.js @@ -16,7 +16,11 @@ const THEME_PARAMS = { accentColor: 'var(--color-progressive, #36c)', rowHoverColor: 'var(--background-color-interactive-subtle, #f8f9fa)', selectedRowBackgroundColor: 'var(--background-color-progressive-subtle, #f1f4fd)', - fontFamily: 'inherit' + fontFamily: 'inherit', + // Inherit the page color-scheme rather than AG Grid's default of "light", so + // the wrapper doesn't pin itself to light and Citizen's light-dark() Codex + // tokens resolve to the wiki's current mode inside the grid. + browserColorScheme: 'inherit' }; let cachedTheme = null; diff --git a/tests/vitest/ext.aggrid/theme.test.js b/tests/vitest/ext.aggrid/theme.test.js index 1bcb08a..ccc8a86 100644 --- a/tests/vitest/ext.aggrid/theme.test.js +++ b/tests/vitest/ext.aggrid/theme.test.js @@ -23,6 +23,10 @@ describe( 'THEME_PARAMS', () => { expect( THEME_PARAMS.fontFamily ).toBe( 'inherit' ); expect( THEME_PARAMS.fontSize ).toBeUndefined(); } ); + + it( 'inherits the browser color-scheme so light-dark() tokens resolve', () => { + expect( THEME_PARAMS.browserColorScheme ).toBe( 'inherit' ); + } ); } ); describe( 'getWikiTheme', () => { From d5ac33903aa4137d282e15112d987d20180ca783 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 2 Jun 2026 02:02:57 -0400 Subject: [PATCH 4/5] chore: make color-scheme comments skin-agnostic Refer to light-dark() color tokens / the page's mode rather than naming a specific skin. Co-Authored-By: Claude Opus 4.8 (1M context) --- modules/ext.aggrid/ext.aggrid.less | 4 ++-- modules/ext.aggrid/theme.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/ext.aggrid/ext.aggrid.less b/modules/ext.aggrid/ext.aggrid.less index 8cf59ba..b546725 100644 --- a/modules/ext.aggrid/ext.aggrid.less +++ b/modules/ext.aggrid/ext.aggrid.less @@ -1,7 +1,7 @@ .ext-aggrid { width: 100%; height: 400px; - /* Inherit the page color-scheme so Citizen's light-dark() tokens resolve - to the wiki's current mode. */ + /* Inherit the page color-scheme so light-dark() color tokens resolve to + the page's current mode. */ color-scheme: inherit; } diff --git a/modules/ext.aggrid/theme.js b/modules/ext.aggrid/theme.js index 352dcf9..550288c 100644 --- a/modules/ext.aggrid/theme.js +++ b/modules/ext.aggrid/theme.js @@ -18,8 +18,8 @@ const THEME_PARAMS = { selectedRowBackgroundColor: 'var(--background-color-progressive-subtle, #f1f4fd)', fontFamily: 'inherit', // Inherit the page color-scheme rather than AG Grid's default of "light", so - // the wrapper doesn't pin itself to light and Citizen's light-dark() Codex - // tokens resolve to the wiki's current mode inside the grid. + // the wrapper doesn't pin itself to light and light-dark() color tokens + // resolve to the page's current mode inside the grid. browserColorScheme: 'inherit' }; From 4848b084119fe25e297594d917100004b726531b Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Tue, 2 Jun 2026 02:07:17 -0400 Subject: [PATCH 5/5] refactor: drop redundant color-scheme on .ext-aggrid color-scheme is an inherited property, so .ext-aggrid already takes the page scheme from its ancestors. The grid's scheme is governed by the theme's browserColorScheme: 'inherit' (which controls .ag-root-wrapper). Verified the grid still flips dark/light with the rule removed. Co-Authored-By: Claude Opus 4.8 (1M context) --- modules/ext.aggrid/ext.aggrid.less | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/ext.aggrid/ext.aggrid.less b/modules/ext.aggrid/ext.aggrid.less index b546725..1481057 100644 --- a/modules/ext.aggrid/ext.aggrid.less +++ b/modules/ext.aggrid/ext.aggrid.less @@ -1,7 +1,4 @@ .ext-aggrid { width: 100%; height: 400px; - /* Inherit the page color-scheme so light-dark() color tokens resolve to - the page's current mode. */ - color-scheme: inherit; }