Skip to content

DataViews: Vendor DateCalendar and DateRangeCalendar from components - #81324

Closed
oandregal wants to merge 1 commit into
trunkfrom
try/dataviews-vendor-date-calendar
Closed

DataViews: Vendor DateCalendar and DateRangeCalendar from components#81324
oandregal wants to merge 1 commit into
trunkfrom
try/dataviews-vendor-date-calendar

Conversation

@oandregal

Copy link
Copy Markdown
Member

Part of #81230

What?

Moves the private DateCalendar and DateRangeCalendar components out of @wordpress/components and into @wordpress/dataviews as internal components, removing them from the components package entirely. The date and datetime DataForm controls now import them directly instead of unlocking them through @wordpress/private-apis.

Why?

DataViews is a bundled package: plugins may import it from npm rather than using the WordPress script. When two copies of @wordpress/private-apis exist in one runtime, one copy cannot unlock objects locked by the other, which crashes at module initialization ("Cannot unlock an object that was not locked before"). #81230 tracks removing every private cross-package API usage from DataViews.

The calendar components were blocked on "still stabilizing in @wordpress/components" — but they are consumed nowhere else: the two DataViews controls were their only usage sites in Gutenberg. I also checked some typical external repositories and there's no import either. Vendoring them into DataViews as internal components unblocks the private-APIs removal without forcing a public-API stabilization decision, and the components package can always reintroduce a public calendar later.

How?

  • Move packages/components/src/calendar/ to packages/dataviews/src/components/calendar/.
  • Rename the CSS class prefix from components-calendar to dataviews-calendar, so a bundled newer DataViews can never be double-styled by an older wp-components stylesheet that still ships the calendar rules.
  • Replace the components-internal theme variables in the stylesheet with the design-system tokens they resolve to (--wpds-*, and var(--wp-admin-theme-color, #3858e9) for the accent), following the stylelint policy that disallows --wp-components-color-* outside the components package. Computed values are unchanged.
  • Move the react-day-picker dependency from @wordpress/components (no remaining usage there) to @wordpress/dataviews.
  • Update the two consumers: date.tsx needs no private-API unlock at all anymore; datetime.tsx keeps a single unlock for ValidatedInputControl (a separate DataViews: remove all private API usage #81230 item).
  • Remove the components-side exports: the private-apis.ts entries and the stylesheet registration.

Testing Instructions

  1. Run the moved unit tests: npm run test:unit packages/dataviews/src/components/calendar (115 tests) and the full suite npm run test:unit packages/dataviews (556 tests).
  2. Run npm run build and confirm it passes, including type generation.
  3. In the editor, open a DataViews screen with a date filter (e.g. Site Editor → Pages, add a "Date" filter with the between operator): the calendar and range calendar should render and behave exactly as on trunk — presets, month navigation, range hover preview, timezone handling.
  4. Edit a page's date field through DataForms (or the DataViews Storybook DataForm validation story) and verify the single-date calendar works, including selected-day and today indicators.
  5. Inspect the rendered calendar in devtools: class names now use the dataviews-calendar prefix, and the styles come from the DataViews stylesheet. wp-components CSS no longer contains components-calendar rules.
  6. Verify packages/components no longer references the calendar: grep -r "DateCalendar" packages/components/src returns nothing.

Use of AI Tools

This PR, including this description, was written by Claude Code (Claude Fable 5), based on issue #81230's analysis, and human-reviewed before submission.

Move the private DateCalendar / DateRangeCalendar components (and their
TZDate re-export) from @wordpress/components into @wordpress/dataviews as
internal components, and delete them from the components package. DataViews
was their only consumer, and unlocking them via cross-package private APIs
breaks npm-bundled copies of the package (see #81230).

- Move packages/components/src/calendar to
  packages/dataviews/src/components/calendar, including tests; drop the
  Storybook stories, READMEs, and their docs manifest entries.
- Copy the internal useControlledValue hook, the only dependency on
  components internals.
- Rename the CSS class prefix from components-calendar to
  dataviews-calendar so stale wp-components stylesheets cannot
  double-style the calendar.
- Replace the components-internal theme variables with the design-system
  tokens they resolve to, per the stylelint policy banning
  --wp-components-color-* outside the components package.
- Move the react-day-picker dependency from components to dataviews.
- Import the calendar directly in the date and datetime dataform
  controls; date.tsx no longer needs the private APIs unlock at all.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions github-actions Bot added [Package] Components /packages/components [Package] DataViews /packages/dataviews labels Aug 7, 2026
@oandregal

Copy link
Copy Markdown
Member Author

I'm not fully convinced vendoring components in DataViews is the way forward, but DateCalendar/DateRangeCalendar have a more compact API surface and less usage than the Validated* components (#81306 (comment)), so it's a better place for experimenting and understanding the boundaries.

If we go this route, a hard rule is that DataViews should never export these components. If a second consumer wants to use them in the future, it should vendor them itself (until there's a canonical version from wp/ui or wp/components). This is unfortunate, but I don't see any other way forward.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Components, [Package] DataViews.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

1 similar comment
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Components, [Package] DataViews.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@oandregal
oandregal requested review from ntsekouras and a balanced review from Copilot August 7, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Moves private calendar components into DataViews, eliminating their cross-package private API usage.

Changes:

  • Vendors calendar implementation, styles, and tests into DataViews.
  • Updates DataForm consumers and CSS class prefixes.
  • Moves react-day-picker and removes Components exports/docs.

Reviewed changes

Copilot reviewed 21 out of 29 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/manifest.json Removes obsolete calendar docs.
package-lock.json Moves dependency ownership.
packages/components/CHANGELOG.md Records calendar removal.
packages/components/package.json Removes react-day-picker.
packages/components/src/calendar/date-calendar/README.md Removes private API docs.
packages/components/src/calendar/date-range-calendar/README.md Removes range API docs.
packages/components/src/calendar/stories/date-calendar.story.tsx Removes obsolete story.
packages/components/src/calendar/stories/date-range-calendar.story.tsx Removes obsolete range story.
packages/components/src/calendar/utils/constants.ts Removes old class constants.
packages/components/src/private-apis.ts Removes calendar private exports.
packages/components/src/style.scss Removes calendar styles.
packages/dataviews/CHANGELOG.md Records vendored calendars.
packages/dataviews/package.json Adds react-day-picker.
packages/dataviews/src/components/calendar/date-calendar/index.tsx Moves single-date calendar.
packages/dataviews/src/components/calendar/date-range-calendar/index.tsx Moves range calendar.
packages/dataviews/src/components/calendar/index.tsx Provides internal exports.
packages/dataviews/src/components/calendar/style.scss Renames and retokens styles.
packages/dataviews/src/components/calendar/test/__utils__/index.ts Moves test helpers.
packages/dataviews/src/components/calendar/test/date-calendar.tsx Moves single-date tests.
packages/dataviews/src/components/calendar/test/date-range-calendar.tsx Moves range tests.
packages/dataviews/src/components/calendar/types.ts Moves and updates types.
packages/dataviews/src/components/calendar/utils/constants.ts Defines DataViews class names.
packages/dataviews/src/components/calendar/utils/day-cell.tsx Moves custom day cells.
packages/dataviews/src/components/calendar/utils/misc.ts Moves month clamping utility.
packages/dataviews/src/components/calendar/utils/use-controlled-value.ts Vendors controlled-state utility.
packages/dataviews/src/components/calendar/utils/use-localization-props.ts Moves localization behavior.
packages/dataviews/src/components/dataform-controls/date.tsx Uses internal calendars directly.
packages/dataviews/src/components/dataform-controls/datetime.tsx Uses internal date calendar.
packages/dataviews/src/style.scss Includes calendar styles.

@oandregal

Copy link
Copy Markdown
Member Author

Closing in favor of #81337

@oandregal oandregal closed this Aug 7, 2026
@oandregal
oandregal deleted the try/dataviews-vendor-date-calendar branch August 7, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Package] DataViews /packages/dataviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants