Guide

Scripts architecture

PHP namespaces stay PRC\Platform\Scripts and PRC\Platform\Script_Modules so existing REST endpoint classes keep working after the move out of prc-platform-core.

Layout

PathContents
includes/scripts/First-party @prc/* and third-party JS/CSS source plus build output
includes/script-modules/@prc/d3 and @prc/topojson script modules
includes/scripts/src/third-party/d3/ and d3-v7/UMD bundles exposed as window.d3 and window.d3v7
includes/class-bootstrap.phpWires classes into the plugin Loader

Third-party D3 globals

Legacy chart and interactive bundles externalize D3 to script handles built from the UMD d3/dist/d3.js entry (not d3/src). Each webpack build must export the populated UMD global as the library default:

Build outputGlobalTypical consumer
build/third-party/d3/window.d3Older interactives
build/third-party/d3-v7/window.d3v7import * as d3 from 'd3v7'

Rebuild vendors after D3 version changes:

Build scripts workspace bash
npx turbo build --filter=@prc/scripts

Load order

client-mu-plugins/plugin-loader.php loads prc-scripts after prc-icon-library / prc-post-publish-pipeline and immediately before prc-block-library, so handles exist before consumers that list Requires Plugins: prc-scripts.

Internal REST helpers

Some @prc/components packages register editor helper routes under prc-api/v3 (for example /utils/postid-by-url and /components/wp-entity-search). Those support shared UI controls and are not a public product API.

Shared UI components

ComponentPathConsumers
CalendarHeatmap, AnalyticsPeriodControls, monthKeyFromIndex@prc/components/calendar-heatmapDataset stats panel, quiz analytics — month grid with optional onCellClick drill-down to daily cells
AudienceBuildPanel@prc/components/audience-build-panelDatasets, quiz-builder, email-builder — DataForm audience cards with rebuild/delete/draft actions

See the plugin README for import examples and prop shapes.

Storybook

Root Storybook (.storybook/) discovers stories under plugins/prc-scripts/includes/scripts/src/@prc/ and chart stories under plugins/prc-charting-library/src/.

CommandPurpose
npm run storybookDev server at http://localhost:6006
npm run build-storybookStatic build

Production builds externalize @prc/* to window.* via dependency-extraction.js. Storybook aliases those packages to source instead. See the plugin README for mocks, decorators, and how to add a story.

Was this helpful?