PRC Block Library
The center piece of the PRC Platform. This library includes 85+ custom Gutenberg blocks and opinionated modifications of core blocks, providing a comprehensive set of tools to streamline content creation and ensure consistency across PRC projects. Use this library to create beautiful, responsive content that engages and informs your audience
by Seth Rubenstein, Ben Wormald · github.com/pewresearch/prc-block-library · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/pewresearch/prc-block-library/archive/refs/heads/trunk.zipReadme
PRC Block Library
The core Gutenberg block library for the PRC Platform — provides all custom blocks and core block enhancements used across pewresearch.org.
Overview
PRC Block Library registers ~90 blocks across two namespaces: prc-block/* for custom PRC blocks and modifications to core/* blocks. It is the display layer of the platform and the first plugin loaded when rendering any content. Beyond blocks, it also ships a set of cross-cutting support systems (Interactivity API helpers, a Print Engine, block visibility controls, custom rich text formats, sticky/legacy-max-width layout supports, and a form data store) that apply globally to all registered blocks.
In the block editor, the plugin registers the Pew Research Center Block Library block collection (namespace prc-block) in includes/supports/src/index.jsx, which is enqueued with the Supports subsystem.
Dependencies
- Upstream:
prc-platform-core(required plugin),prc-schema-seo(optional, for PDF contact resolution),prc-staff-bylines(optional, for PDF bylines), Report Package plugin (optional, for multi-chapter PDF rendering), WordPress AI plugin (optional, for tabular data AI experiment) - Downstream: Every plugin or theme that renders blocks on the front end depends on this library. Form input blocks (
prc-block/form-input-*) live here; the form container and related blocks live in@prc/block-forms. Theprc-block-library/forms@wordpress/datastore (registered by@prc/block-forms) is a direct integration point for any plugin registering custom form types.
Local Development Setup
Prerequisites
- Node.js 22+ / npm 10.9+
- PHP 8.2+
- WordPress Playground (via `
npm run vip:startfrom repo root)
Running Locally
# Build the entire library (run from repo root)
npm run build:library -w @prc/block-library
# Build a single deprecated block only
npm run build deprecated:grid-controller -w @prc/block-library
# Watch mode for a single deprecated block during development
npm run start deprecated:grid-controller -w @prc/block-library
# Watch mode for the full library
npm run start:library -w @prc/block-library
Running Tests
# Run Playwright e2e tests (from monorepo root; VIP dev-env + Playwright are centralized)
npm run vip:start
npm test -- tests/prc-block-library/e2e/
Architecture
Blocks are discovered and loaded automatically at runtime. Plugin::load_blocks() globs all subdirectories of src/ (in local/dev) or build/ (in production) and calls include_block() for each. Any directory prefixed with _ or . is skipped. Each block is expected to have a class-{block-name}.php file which self-registers with WordPress using register_block_type_from_metadata(). Block metadata is pre-indexed at build time via build/blocks-manifest.php and registered with wp_register_block_metadata_collection() for performance.
Blocks are split into two groups initialized by Plugin:
- Core blocks (
define_core_blocks): extensions and modifications to existingcore/*blocks — adding attributes, context, controls, or custom rendering. - PRC blocks (
define_prc_blocks): net-new blocks in theprc-blocknamespace.
In addition to block classes, Plugin boots several support subsystems via define_library_dependencies(). These run independently of individual blocks and hook into WordPress globally.
Block scaffolding uses @wordpress/create-block with templates located at the repository root (/block-templates). There are four variants:
| Variant | When to use |
|---|---|
default |
Standard block with InnerBlocks and server-side rendering via render.php |
syncedEntity |
Block that wraps a custom post type or synced entity with create/search UI |
contextProvider |
Block that provides context to children and uses Interactivity API routing |
coreBlock |
Extension of an existing core/* block via filters |
To scaffold a new block, run npm run create-block from the repository root. See /block-templates/README.md for detailed documentation.
Key Files
| Path | Purpose |
|---|---|
prc-block-library.php |
Plugin entry point; defines constants, runs Plugin |
includes/class-plugin.php |
Boots all blocks and support subsystems; registers block categories and HTML allowlist |
includes/class-loader.php |
Maintains and runs all WordPress action/filter hooks |
includes/utils.php |
convert_number_to_words(), prc_log_error(), prc_block_library_manifest() helpers |
src/story-item/class-ai.php |
Story Item AI title/blurb generation via the WordPress AI plugin |
includes/block-visibility/class-block-visibility.php |
Adds editor UI for per-block visibility control |
includes/custom-text-formats/class-custom-text-formats.php |
Registers custom rich text format buttons in the editor toolbar |
includes/interactivity-api/class-interactivity-api.php |
Injects interactiveNamespace and interactiveSubsumption attributes and context on every block that declares supports.interactivity |
includes/pagination/class-pagination.php |
Registers shared pagination styles/scripts consumed by listing blocks |
includes/supports/class-supports.php |
Adds sticky-state color/shadow attributes; keeps legacy maxWidth attribute registration/render (editor UI removed) |
build/blocks-manifest.php |
Auto-generated block metadata index; do not edit manually |
src/README.md |
Instructions for scaffolding a new block |
bin/build-block.js |
CLI helper for building a single named block |
bin/start-block.js |
CLI helper for watching a single named block |
webpack.config.js |
Inherits from root webpack.config.js |
tests/prc-block-library/e2e/ |
Playwright e2e specs (monorepo root) |
Blocks
This section doubles as the documentation index. Each block links to its detailed doc in docs/plugins/prc-block-library/blocks/.
Core Block Modifications (core/*)
Adds attributes, context, rendering changes, or new editor controls to existing WordPress core blocks.
| Block | Notes |
|---|---|
core/button |
PRC platform customizations |
core/categories |
PRC platform customizations |
core/carousel |
WIP, no functional implementation yet |
core/code |
PRC platform customizations |
core/cover |
PRC platform customizations |
core/details |
Interactivity API integration |
core/dialog |
PRC dialog pattern utilities |
core/embed |
PRC platform customizations |
core/file |
PRC platform customizations |
core/group |
PRC platform customizations |
core/heading |
PRC platform customizations |
core/image |
PRC platform customizations |
core/list |
PRC platform customizations |
core/list-item |
PRC platform customizations |
core/media-text |
PRC platform customizations |
core/navigation |
PRC platform customizations |
core/paragraph |
PRC platform customizations |
core/post-content |
PRC platform customizations |
core/post-title |
Custom render callback for PRC title patterns |
core/pullquote |
PRC platform customizations |
core/query-pagination-numbers |
PRC platform customizations |
core/search |
PRC platform customizations |
core/separator |
PRC platform customizations |
core/social-links |
Interactivity API integration |
core/table |
PRC platform customizations |
core/tabs |
PRC platform customizations; registered as Remote Data Blocks template |