diff --git a/docs/explanations/architecture/dashboard-widgets.md b/docs/explanations/architecture/dashboard-widgets.md index 8abacb3ad47a6a..27d5ca5399d77c 100644 --- a/docs/explanations/architecture/dashboard-widgets.md +++ b/docs/explanations/architecture/dashboard-widgets.md @@ -33,7 +33,7 @@ The split between `widget.json` and `widget.ts` is deliberate. `widget.json` is Unlike the other translatable strings, `help` is an object: `content` plus optional `links`, meant for compact surfaces such as tooltips. -`actions`: declarative verbs (`id`, `label`, optional `icon` and `relevance`, plus exactly one fulfillment key). Today the only key is `href`, a link target, with optional `download` / `openInNewTab`. Hosts mount the primitive and place it; the dashboard uses a "More" menu. A relative `href` that exists under `widgets/{name}/` becomes a plugin URL at registration; missing relative non-admin files are dropped. `data:` and `javascript:` hrefs are rejected. Prefer absolute URLs for assets that must work in the plugin zip (which does not ship `widgets/`). +`actions`: declarative verbs (`id`, `label`, optional `icon` and `relevance`, plus exactly one fulfillment key). Today the only key is `href`, a link target, with optional `download` / `openInNewTab`. Hosts mount the primitive and place it; the dashboard routes by `relevance`: `'high'` and `'medium'` to a persistent footer, the rest to a "More" menu. A relative `href` that exists under `widgets/{name}/` becomes a plugin URL at registration; missing relative non-admin files are dropped. `data:` and `javascript:` hrefs are rejected. Prefer absolute URLs for assets that must work in the plugin zip (which does not ship `widgets/`). `icon`: a registered icon name (`collection/icon-name`), resolved client-side through the site's Icons API. Malformed names are dropped at registration. diff --git a/lib/experimental/dashboard-widgets/class-wp-rest-widget-modules-controller.php b/lib/experimental/dashboard-widgets/class-wp-rest-widget-modules-controller.php index 41c727b6dd14a5..35609948151e8f 100644 --- a/lib/experimental/dashboard-widgets/class-wp-rest-widget-modules-controller.php +++ b/lib/experimental/dashboard-widgets/class-wp-rest-widget-modules-controller.php @@ -337,7 +337,7 @@ public function get_item_schema() { 'icon' => array( 'type' => 'string' ), 'relevance' => array( 'type' => 'string', - 'enum' => array( 'high', 'low' ), + 'enum' => array( 'high', 'medium', 'low' ), ), 'href' => array( 'type' => 'string' ), 'download' => array( 'type' => array( 'string', 'boolean' ) ), diff --git a/lib/experimental/dashboard-widgets/widget-types.php b/lib/experimental/dashboard-widgets/widget-types.php index 503f20cdd597e9..ee3a509570cd7c 100644 --- a/lib/experimental/dashboard-widgets/widget-types.php +++ b/lib/experimental/dashboard-widgets/widget-types.php @@ -242,7 +242,7 @@ function gutenberg_sanitize_widget_actions( $actions, $dir_name = '' ) { } } - if ( isset( $action['relevance'] ) && in_array( $action['relevance'], array( 'high', 'low' ), true ) ) { + if ( isset( $action['relevance'] ) && in_array( $action['relevance'], array( 'high', 'medium', 'low' ), true ) ) { $entry['relevance'] = $action['relevance']; } diff --git a/packages/widget-dashboard/CHANGELOG.md b/packages/widget-dashboard/CHANGELOG.md index ff8f1d446b2a90..c0147f2ab5ce7a 100644 --- a/packages/widget-dashboard/CHANGELOG.md +++ b/packages/widget-dashboard/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +### New Features + +- Widget chrome footer: `relevance: 'high'` actions mount as leading text + links (declared icon as prefix) in a persistent strip under the widget + body, `'medium'` as trailing compact affordances (icon-only with a + declared icon); the "More" menu keeps the rest, and full-bleed widgets + keep every action in the menu + ([#81556](https://github.com/WordPress/gutenberg/pull/81556)). + ### Internal - Point tsconfig references at split dependencies' build projects. ([#81509](https://github.com/WordPress/gutenberg/pull/81509)) diff --git a/packages/widget-dashboard/README.md b/packages/widget-dashboard/README.md index 20f07f5a581a3f..12d456dc800944 100644 --- a/packages/widget-dashboard/README.md +++ b/packages/widget-dashboard/README.md @@ -205,7 +205,7 @@ The tile chrome is a `Card` at the Card's default density. Hosts can tighten or ```css :root { - --wp-widget-dashboard-tile-padding: var(--wpds-dimension-padding-lg); + --wp-widget-dashboard-tile-padding: var( --wpds-dimension-padding-lg ); } ``` @@ -223,7 +223,7 @@ When a widget type declares `help`, the tile chrome surfaces its `content` and o ### Attribute editing -A widget declares importance per attribute through `relevance` (`'high' | 'low'`, absent means `'low'`). The declaration states importance, not placement; this host maps it to two surfaces: +A widget declares importance per attribute through `relevance` (`'high' | 'medium' | 'low'`, absent means `'low'`). The declaration states importance, not placement; this host maps it to two surfaces: - **Prominent surface**: `relevance: 'high'` fields render as bare inline controls in the tile header, for in-context edits. - **Settings surface**: the full schema, opened from the settings trigger. The trigger shows only when some attribute is not promoted; otherwise it would repeat the prominent surface. @@ -232,6 +232,16 @@ The prominent surface holds only while it fits. The header measures the space it Edits on any surface stage through the engine's internal layer and reach `onLayoutChange` on commit. Prominent-surface and dropdown edits publish on a shared auto-save debounce; the settings surface publishes on Save. +### Actions + +Actions carry the same `relevance` scale, mapped to surfaces of decreasing prominence: + +- **Footer, leading**: `relevance: 'high'` actions render as text links in a persistent strip under the widget body, a declared icon riding as prefix. +- **Footer, trailing**: `relevance: 'medium'` actions render as compact affordances: icon-only links when the action declares an icon, text links otherwise. +- **More menu**: the rest collapse into the three-dots menu in the tile header. + +Every affordance is a real anchor. Full-bleed widgets have no footer, so all of their actions stay in the menu. + ## Authoring widgets Widget render modules receive only what they need to render and edit: diff --git a/packages/widget-dashboard/src/components/widget-actions/widget-actions.tsx b/packages/widget-dashboard/src/components/widget-actions/widget-actions.tsx index c240daf159e897..488c37e4eecaad 100644 --- a/packages/widget-dashboard/src/components/widget-actions/widget-actions.tsx +++ b/packages/widget-dashboard/src/components/widget-actions/widget-actions.tsx @@ -3,7 +3,7 @@ import { __ } from '@wordpress/i18n'; import { moreVertical } from '@wordpress/icons'; // eslint-disable-next-line @wordpress/use-recommended-components import { Icon, IconButton, Link } from '@wordpress/ui'; -import type { WidgetType } from '@wordpress/widget-primitives'; +import type { WidgetAction } from '@wordpress/widget-primitives'; import { useReserveHeaderSpace } from '../widget-header/widget-header-fit'; import styles from './widget-actions.module.css'; import { unlock } from '../../lock-unlock'; @@ -12,16 +12,18 @@ const { Menu } = unlock( componentsPrivateApis ); type WidgetActionsProps = { /** - * The widget type whose declared actions render here. + * The actions this menu materializes. The host routes by relevance: + * the footer takes `'high'` and `'medium'`, this menu the rest, and + * every action for full-bleed widgets, which have no footer. */ - widgetType: WidgetType; + actions: WidgetAction[]; }; /** - * Materializes a widget type's declared `actions` as a "more" menu in the - * chrome: a three-dots trigger surfacing each action. This host mounts a real - * anchor for the link fulfillment, so middle-click and copy address survive; - * the menu exposes it as a menu item rather than as a link. + * Materializes widget actions as a "more" menu in the chrome: a three-dots + * trigger surfacing each given action. This host mounts a real anchor for the + * link fulfillment, so middle-click and copy address survive; the menu exposes + * it as a menu item rather than as a link. * * As a trailing header section it reserves its own footprint, so the * collapsible controls beside it never plan for space it occupies. @@ -29,9 +31,8 @@ type WidgetActionsProps = { * @param {WidgetActionsProps} props Component props. */ export function WidgetActions( { - widgetType, + actions, }: WidgetActionsProps ): React.ReactNode { - const actions = widgetType.actions ?? []; const reserveRef = useReserveHeaderSpace< HTMLSpanElement >( 'actions' ); if ( actions.length === 0 ) { diff --git a/packages/widget-dashboard/src/components/widget-footer/index.ts b/packages/widget-dashboard/src/components/widget-footer/index.ts new file mode 100644 index 00000000000000..ea6bd3cfef8ab7 --- /dev/null +++ b/packages/widget-dashboard/src/components/widget-footer/index.ts @@ -0,0 +1 @@ +export { WidgetFooter } from './widget-footer'; diff --git a/packages/widget-dashboard/src/components/widget-footer/widget-footer.module.css b/packages/widget-dashboard/src/components/widget-footer/widget-footer.module.css new file mode 100644 index 00000000000000..0d66b3eec5e78b --- /dev/null +++ b/packages/widget-dashboard/src/components/widget-footer/widget-footer.module.css @@ -0,0 +1,32 @@ +/* + * Full-width divider; content aligns to the card padding. The body above + * has no bottom padding, so scrolled content runs flush to the divider. + */ +.widget-footer { + padding-block: var(--wpds-dimension-padding-md); + padding-inline: var(--wp-ui-card-padding); + border-block-start-style: solid; + border-block-start-width: var(--wpds-border-width-xs); + border-block-start-color: var(--wpds-color-stroke-surface-neutral-weak); +} + +.compact-actions { + margin-inline-start: auto; +} + +/* High action with a declared icon: the icon rides as a prefix. */ +.prefixed-action { + display: inline-flex; + align-items: center; + gap: var(--wpds-dimension-gap-xs); +} + +/* + * Square the icon-only link via the Button override hooks for icon + * buttons; breathing room comes from the size, not from padding. + */ +.icon-action { + --wp-ui-button-aspect-ratio: 1; + --wp-ui-button-padding-inline: 0px; + --wp-ui-button-min-width: unset; +} diff --git a/packages/widget-dashboard/src/components/widget-footer/widget-footer.tsx b/packages/widget-dashboard/src/components/widget-footer/widget-footer.tsx new file mode 100644 index 00000000000000..60815c05ae90fe --- /dev/null +++ b/packages/widget-dashboard/src/components/widget-footer/widget-footer.tsx @@ -0,0 +1,156 @@ +import { __, sprintf } from '@wordpress/i18n'; +// eslint-disable-next-line @wordpress/use-recommended-components +import { Icon, Link, LinkButton, Stack, Tooltip } from '@wordpress/ui'; +import type { WidgetAction, WidgetIcon } from '@wordpress/widget-primitives'; +import styles from './widget-footer.module.css'; + +type IconActionProps = { + /** + * The action to materialize. + */ + action: WidgetAction & { icon: WidgetIcon }; +}; + +/** + * Icon-only link. `openInNewTab` mounts the target on the anchor rather + * than through `Link`, whose external glyph would double the icon; the + * new-tab hint joins the accessible name. + * + * @param {IconActionProps} props Component props. + */ +function IconAction( { action }: IconActionProps ): React.ReactNode { + const label = action.openInNewTab + ? sprintf( + /* translators: %s: action label. */ + __( '%s (opens in a new tab)' ), + action.label + ) + : action.label; + + return ( + + + ) : undefined + } + /> + } + > + + + { action.label } + + ); +} + +type WidgetFooterProps = { + /** + * The promoted actions (`relevance: 'high'` and `'medium'`). + */ + actions: WidgetAction[]; + + /** + * Inert the footer while customizing. + */ + editMode?: boolean; +}; + +/** + * Persistent strip under the widget body. `'high'` actions mount as leading + * text links, a declared icon riding as prefix; `'medium'` actions as + * trailing compact affordances, icon-only when they declare an icon. Every + * affordance is a real anchor. + * + * @param {WidgetFooterProps} props Component props. + */ +export function WidgetFooter( { + actions, + editMode = false, +}: WidgetFooterProps ): React.ReactNode { + if ( actions.length === 0 ) { + return null; + } + + const highActions = actions.filter( + ( action ) => action.relevance === 'high' + ); + const mediumActions = actions.filter( + ( action ) => action.relevance === 'medium' + ); + + return ( + + { highActions.length > 0 && ( + + { highActions.map( ( action ) => ( + + { action.icon && } + { action.label } + + ) ) } + + ) } + + { mediumActions.length > 0 && ( + + + { mediumActions.map( ( action ) => + action.icon ? ( + + ) : ( + + { action.label } + + ) + ) } + + + ) } + + ); +} diff --git a/packages/widget-dashboard/src/components/widget-frame/widget-frame.tsx b/packages/widget-dashboard/src/components/widget-frame/widget-frame.tsx index 34b6e69849ed53..5c80be37250f07 100644 --- a/packages/widget-dashboard/src/components/widget-frame/widget-frame.tsx +++ b/packages/widget-dashboard/src/components/widget-frame/widget-frame.tsx @@ -6,6 +6,8 @@ import { __ } from '@wordpress/i18n'; // eslint-disable-next-line @wordpress/use-recommended-components import { Card, Notice, Stack, VisuallyHidden } from '@wordpress/ui'; import type { WidgetType } from '@wordpress/widget-primitives'; +import { splitWidgetActions } from '../../utils/split-widget-actions'; +import { WidgetFooter } from '../widget-footer'; import { WidgetHeader } from '../widget-header'; import { WidgetRender } from '../widget-render'; import styles from './widget-frame.module.css'; @@ -69,8 +71,9 @@ export interface WidgetFrameProps { } /** - * Shared framing: `presentation` into header + content, with the error/loading - * boundaries. Hosts supply the `Card.Root` and their own concerns. + * Shared framing: `presentation` into header, content, and the actions footer, + * with the error/loading boundaries. Hosts supply the `Card.Root` and their + * own concerns. * * @param {WidgetFrameProps} props Component props. */ @@ -87,6 +90,8 @@ export function WidgetFrame( { const isBodyBleeding = presentation === 'full-bleed' || presentation === 'content-bleed'; + const { footer: footerActions } = splitWidgetActions( widgetType ); + const body = ( }> @@ -122,6 +127,10 @@ export function WidgetFrame( { ) } { body } + + { footerActions.length > 0 && ( + + ) } ); } diff --git a/packages/widget-dashboard/src/components/widgets/widgets.tsx b/packages/widget-dashboard/src/components/widgets/widgets.tsx index 5e65684a006479..1735a336e4310f 100644 --- a/packages/widget-dashboard/src/components/widgets/widgets.tsx +++ b/packages/widget-dashboard/src/components/widgets/widgets.tsx @@ -10,6 +10,7 @@ import type { import type { WidgetName } from '@wordpress/widget-primitives'; import { useDashboardInternalContext } from '../../context/dashboard-context'; import { useDashboardContainerColumnCount } from '../../hooks/use-dashboard-container-column-count'; +import { splitWidgetActions } from '../../utils/split-widget-actions'; import { WidgetActions } from '../widget-actions'; import { WidgetAttributes } from '../widget-attributes'; import { WidgetChrome } from '../widget-chrome'; @@ -124,14 +125,16 @@ export const Widgets = forwardRef< HTMLDivElement, WidgetsProps >( ( type ) => type.name === widget.type ); const hasSettings = !! widgetType?.attributes?.length; - const hasActions = !! widgetType?.actions?.length; const isFullBleed = widgetType?.presentation === 'full-bleed'; + const { menu: menuActions } = splitWidgetActions( widgetType ); + const hasActions = menuActions.length > 0; + // The active mode's controls: layout while customizing, the // attribute controls (high-relevance fields on the prominent // surface, plus a settings entry point when needed) and the - // declared actions otherwise. + // menu actions otherwise. let controls: React.ReactNode; if ( editMode ) { controls = ; @@ -146,7 +149,7 @@ export const Widgets = forwardRef< HTMLDivElement, WidgetsProps >( ) } { hasActions && ( - + ) } ); diff --git a/packages/widget-dashboard/src/stories/assets/footer-anatomy.svg b/packages/widget-dashboard/src/stories/assets/footer-anatomy.svg new file mode 100644 index 00000000000000..eec6a1bfe33547 --- /dev/null +++ b/packages/widget-dashboard/src/stories/assets/footer-anatomy.svg @@ -0,0 +1,31 @@ + + + + the footer strip + + + + + + + + + + + + + View all drafts + + + + + + + + High + text links · leading + + + Medium + compact · trailing + diff --git a/packages/widget-dashboard/src/stories/assets/tile-anatomy.svg b/packages/widget-dashboard/src/stories/assets/tile-anatomy.svg new file mode 100644 index 00000000000000..6cd804445184af --- /dev/null +++ b/packages/widget-dashboard/src/stories/assets/tile-anatomy.svg @@ -0,0 +1,51 @@ + + + + from metadata to tile + + + + + + + Goal Progress + + i + + Metric + + + + + + + + + + + + + + + View goal details + + + + + + + header + icon · title · help + attributes: high inline · full schema in settings + actions: low + + + + content + render module · attribute values + + + + footer + actions: high · medium + diff --git a/packages/widget-dashboard/src/stories/index.story.tsx b/packages/widget-dashboard/src/stories/index.story.tsx index 0522b3082e4011..f8d8fb843af4db 100644 --- a/packages/widget-dashboard/src/stories/index.story.tsx +++ b/packages/widget-dashboard/src/stories/index.story.tsx @@ -6,7 +6,7 @@ import '@wordpress/components/build-style/style.css'; // eslint-disable-next-line @wordpress/no-non-module-stylesheet-imports import '@wordpress/dataviews/build-style/style.css'; import { useState } from '@wordpress/element'; -import { chartBar, trendingUp } from '@wordpress/icons'; +import { chartBar, download, trendingUp } from '@wordpress/icons'; import type { ResolveWidgetModule, WidgetAction, @@ -243,20 +243,32 @@ const GOAL_FIELDS: WidgetAttributeField< GoalAttributes >[] = [ }, ]; -// Two declarative actions: an external link and a client-side download. +// Three declarative actions spanning the relevance scale: a high link and a +// medium download for the chrome footer, one at the default relevance for +// the More menu. const GOAL_ACTIONS: WidgetAction[] = [ { id: 'view-goal', label: 'View goal details', + relevance: 'high', + icon: chartBar, href: 'https://wordpress.org/', openInNewTab: true, }, { id: 'export-progress', label: 'Export progress', + relevance: 'medium', + icon: download, href: new URL( './goal-progress.csv', import.meta.url ).href, download: 'goal-progress.csv', }, + { + id: 'about-goals', + label: 'About goals', + href: 'https://wordpress.org/documentation/', + openInNewTab: true, + }, ]; const goalProgressWidgetType: WidgetType = { @@ -266,7 +278,7 @@ const goalProgressWidgetType: WidgetType = { description: 'Sample goal widget whose attributes are all promoted.', help: { content: - 'One attribute, Goal metric, at high relevance: a single field in the header and no settings button. Two actions in the More menu: a link and a download.', + 'One attribute, Goal metric, at high relevance: a single field in the header and no settings button. Two promoted actions in the footer (a link and a download), plus one in the More menu.', }, icon: trendingUp, renderModule: 'demo/widgets/goal-progress/render', @@ -428,7 +440,7 @@ Their tiles compare the header presentations: The widget only declares relevance; the fit is measured by the chrome, so the same declaration adapts to any tile width. Resize the canvas to watch the headers switch presentations. -Beyond attributes, \`demo/goal-progress\` declares two \`actions\`: a "View goal details" link and an "Export progress" download. The host surfaces them in a "More" menu in the toolbar, so the widget declares each action as data and the host owns where it appears. +Beyond attributes, \`demo/goal-progress\` declares three \`actions\` spanning the relevance scale, and that scale routes them: "View goal details" at \`'high'\` mounts as a leading text link (declared icon as prefix) in a persistent chrome footer, "Export progress" at \`'medium'\` beside it as a trailing icon-only link, and "About goals" at the default \`'low'\` lands in the "More" menu. The widget declares each action as data plus its importance; the host owns the surfaces. Each type also carries a \`help\` note, opened from the info icon in the header, that describes its attributes and what they do. `, diff --git a/packages/widget-dashboard/src/stories/widget-chrome.md b/packages/widget-dashboard/src/stories/widget-chrome.md index 1bef1169453e40..007399c10dfb58 100644 --- a/packages/widget-dashboard/src/stories/widget-chrome.md +++ b/packages/widget-dashboard/src/stories/widget-chrome.md @@ -4,18 +4,26 @@ This package is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes. -The chrome is everything the dashboard wraps around a widget instance: the header, its controls, and the boundaries that catch errors and loading. +The chrome is everything the dashboard wraps around a widget instance: the header, its controls, the footer, and the boundaries that catch errors and loading. The widget declares its identity and how it wants to be framed; the chrome materializes both. The widget never paints its own header or toolbar. +## From metadata to tile + +The chrome reads the widget type and materializes each field in one of three areas. + +![One widget type materialized as a tile of three areas: the header takes the identity, the high-relevance attributes, and the low-relevance actions; the content takes the render module fed with the attribute values; the footer takes the promoted actions.](./assets/tile-anatomy.svg) + +The header takes the identity (`icon`, `title`, `help`), the high-relevance `attributes` inline plus the settings trigger for the full schema, and the low-relevance `actions` in the More menu. The content belongs to the render module, fed the attribute values. The footer takes the promoted `actions`. + ## The frame The dashboard widget interprets `presentation` and determines how much chrome a widget gets. -* `framed` paints a header and pads the content. -* `content-bleed` keeps the header but lets the content fill the available area. -* `full-bleed` hides the header and gives the widget the whole tile, while keeping the identity available to assistive technology. +- `framed` paints a header and pads the content. +- `content-bleed` keeps the header but lets the content fill the available area. +- `full-bleed` hides the header and the footer and gives the widget the whole tile, while keeping the identity available to assistive technology. Whatever the presentation, an error boundary and a loading fallback wrap the content, so a widget that throws or suspends never breaks the tile. @@ -29,7 +37,7 @@ The sections are semantic. A control belongs to a section by its nature, not by - **Identity.** The widget's icon, title, and help. It names the tile, and its title truncates rather than wrapping when the row runs short. - **Attributes.** The widget's high-relevance attributes: quick in-place editing or a dropdown button when there isn't enough space. -- **More.** The widget's declared actions, gathered in a menu on the trailing edge. +- **More.** The widget's low-relevance actions, gathered in a menu on the trailing edge. ### Fitting the row @@ -46,3 +54,21 @@ It measures the identity as it stands, discounts the sections that keep their si Because the decision measures the real row, every section counts on its own. The widget declares its sections; the header measures the fit. + +## The footer + +A persistent strip under the body, for the actions the widget promotes. + +![The footer strip: a full-width divider, high-relevance actions as text links on the leading edge, medium-relevance actions as compact icon affordances on the trailing edge.](./assets/footer-anatomy.svg) + +`relevance` routes every action to its surface. + +- **`high`.** Text links on the leading edge, labels always visible, a declared icon as prefix. +- **`medium`.** Compact affordances on the trailing edge: icon-only with a declared icon, text links otherwise. +- **`low`** (default). The header's More menu. + +Every affordance is a real anchor: middle-click, copy address, and download survive. + +The divider spans the tile, and the body above keeps no bottom padding, so scrolled content runs flush against it. + +The widget declares importance; the footer materializes it. diff --git a/packages/widget-dashboard/src/stories/widget-chrome.mdx b/packages/widget-dashboard/src/stories/widget-chrome.mdx index 1f6cb049a30be7..a76ce70477979b 100644 --- a/packages/widget-dashboard/src/stories/widget-chrome.mdx +++ b/packages/widget-dashboard/src/stories/widget-chrome.mdx @@ -1,11 +1,15 @@ import { Meta, Markdown } from '@storybook/addon-docs/blocks'; import WidgetChromeDoc from './widget-chrome.md?raw'; +import tileAnatomy from './assets/tile-anatomy.svg'; import headerAnatomy from './assets/header-anatomy.svg'; import headerFit from './assets/header-fit.svg'; +import footerAnatomy from './assets/footer-anatomy.svg'; - { WidgetChromeDoc.replace( './assets/header-anatomy.svg', headerAnatomy ) - .replace( './assets/header-fit.svg', headerFit ) } + { WidgetChromeDoc.replace( './assets/tile-anatomy.svg', tileAnatomy ) + .replace( './assets/header-anatomy.svg', headerAnatomy ) + .replace( './assets/header-fit.svg', headerFit ) + .replace( './assets/footer-anatomy.svg', footerAnatomy ) } diff --git a/packages/widget-dashboard/src/utils/split-widget-actions.ts b/packages/widget-dashboard/src/utils/split-widget-actions.ts new file mode 100644 index 00000000000000..b2c08229fd64a7 --- /dev/null +++ b/packages/widget-dashboard/src/utils/split-widget-actions.ts @@ -0,0 +1,27 @@ +import type { WidgetAction, WidgetType } from '@wordpress/widget-primitives'; + +/** + * Splits a widget type's actions across the chrome surfaces: the footer + * takes `relevance: 'high'` and `'medium'`, the More menu the rest. + * Full-bleed widgets have no footer, so every action stays in the menu. + * + * @param widgetType The widget type whose actions are routed. + */ +export function splitWidgetActions( widgetType?: WidgetType ): { + footer: WidgetAction[]; + menu: WidgetAction[]; +} { + const actions = widgetType?.actions ?? []; + + if ( widgetType?.presentation === 'full-bleed' ) { + return { footer: [], menu: actions }; + } + + const isPromoted = ( action: WidgetAction ) => + action.relevance === 'high' || action.relevance === 'medium'; + + return { + footer: actions.filter( isPromoted ), + menu: actions.filter( ( action ) => ! isPromoted( action ) ), + }; +} diff --git a/packages/widget-primitives/CHANGELOG.md b/packages/widget-primitives/CHANGELOG.md index 6e773b13351484..175a0d417bc3ee 100644 --- a/packages/widget-primitives/CHANGELOG.md +++ b/packages/widget-primitives/CHANGELOG.md @@ -2,6 +2,18 @@ ## Unreleased +### New Features + +- `WidgetRelevance` gains a `'medium'` tier between `'high'` and `'low'`, + for persistent but compact visibility + ([#81556](https://github.com/WordPress/gutenberg/pull/81556)). + +### Enhancements + +- `useWidgetTypes` holds the icon slot with the stand-in while an action's + icon reference resolves; an unresolvable reference clears it + ([#81556](https://github.com/WordPress/gutenberg/pull/81556)). + ## 0.5.0 (2026-08-12) ### New Features diff --git a/packages/widget-primitives/README.md b/packages/widget-primitives/README.md index f797f5e9270852..3123dd7cf82e67 100644 --- a/packages/widget-primitives/README.md +++ b/packages/widget-primitives/README.md @@ -60,11 +60,11 @@ It takes host-supplied records (`WidgetModuleRecord[]`, or `null` while loading) ### `WidgetAttributeField< Item >` It's an authoring helper: a DataViews `Field` whose `id` is narrowed to the widget's attribute keys. -Its optional `relevance` hint (`'high' | 'low'`) marks attributes a host may promote to a prominent surface. +Its optional `relevance` hint (`'high' | 'medium' | 'low'`) marks attributes a host may promote to a prominent surface. ### `WidgetAction` -It's a declarative verb a widget type exposes: an envelope (`id`, `label`) plus exactly one fulfillment, named by the key carrying it. +It's a declarative verb a widget type exposes: an envelope (`id`, `label`, optional `icon` and `relevance`) plus exactly one fulfillment, named by the key carrying it. Today the only key is `href`, a link target, with optional `download` / `openInNewTab`. `data:` and `javascript:` hrefs are rejected at registration. Prefer a file next to the widget, an absolute URL, or `downloadBlob` for generated content. diff --git a/packages/widget-primitives/src/components/widget-render/stories/index.story.tsx b/packages/widget-primitives/src/components/widget-render/stories/index.story.tsx index 74d209eee70083..062ddbca04b463 100644 --- a/packages/widget-primitives/src/components/widget-render/stories/index.story.tsx +++ b/packages/widget-primitives/src/components/widget-render/stories/index.story.tsx @@ -527,7 +527,7 @@ export const WithRelevance: StoryObj = { docs: { description: { story: ` -Each attribute may carry a \`relevance\` hint (\`'high' | 'low'\`). The widget declares importance; the host chooses the surface. When absent, treat the hint as \`'low'\`. +Each attribute may carry a \`relevance\` hint (\`'high' | 'medium' | 'low'\`). The widget declares importance; the host chooses the surface. When absent, treat the hint as \`'low'\`. **In this demo** diff --git a/packages/widget-primitives/src/hooks/test/use-widget-types.test.tsx b/packages/widget-primitives/src/hooks/test/use-widget-types.test.tsx index bf2170bb50701a..bb974484965897 100644 --- a/packages/widget-primitives/src/hooks/test/use-widget-types.test.tsx +++ b/packages/widget-primitives/src/hooks/test/use-widget-types.test.tsx @@ -228,7 +228,7 @@ describe( 'useWidgetTypes', () => { ); } ); - it( 'leaves an action without an icon when the reference does not resolve', async () => { + it( 'clears the action stand-in when the reference does not resolve', async () => { const { result } = renderHook( () => useWidgetTypes( actionIconRecords ) ); @@ -241,7 +241,7 @@ describe( 'useWidgetTypes', () => { ); } ); - it( 'emits record actions without their icon while the reference resolves', async () => { + it( 'holds the action icon slot with a stand-in while the reference resolves', async () => { registerIconResolver( () => new Promise< WidgetIcon | null >( () => {} ) ); @@ -256,7 +256,9 @@ describe( 'useWidgetTypes', () => { id: 'report', relevance: 'high', } ); - expect( result.current[ 0 ][ 0 ].actions?.[ 0 ].icon ).toBeUndefined(); + expect( + isValidElement( result.current[ 0 ][ 0 ].actions?.[ 0 ].icon ) + ).toBe( true ); } ); it( "keeps a module action's element icon", async () => { diff --git a/packages/widget-primitives/src/hooks/use-widget-types.ts b/packages/widget-primitives/src/hooks/use-widget-types.ts index 3c33d7a5284305..3f8bb5052ba334 100644 --- a/packages/widget-primitives/src/hooks/use-widget-types.ts +++ b/packages/widget-primitives/src/hooks/use-widget-types.ts @@ -17,25 +17,36 @@ import type { /* * Transparent stand-in for an icon reference that has not resolved yet: - * it holds the icon slot so titles do not shift when the icon lands. + * it holds the icon slot so titles do not shift and actions keep their + * icon shape while the icon lands. */ const pendingIcon: WidgetIcon = createElement( 'svg', { viewBox: '0 0 24 24', } ); /** - * Emitted actions carry only renderable icons: a wire reference resolves - * after the gate and patches in; anything else non-renderable drops. + * Emitted actions carry only renderable icons: a wire reference holds the + * slot with the stand-in while it resolves; anything else non-renderable + * drops. * - * @param actions Declared actions, from the record or the module. + * @param actions Declared actions, from the record or the module. + * @param holdPending Whether wire references resolve later (record actions). */ function withRenderableIcons( - actions: ( WidgetAction | WidgetActionRecord )[] + actions: ( WidgetAction | WidgetActionRecord )[], + holdPending: boolean ): WidgetAction[] { - return actions.map( ( { icon, ...action } ) => ( { - ...action, - ...( isValidElement( icon ) ? { icon: icon as WidgetIcon } : {} ), - } ) ); + return actions.map( ( { icon, ...action } ) => { + if ( isValidElement( icon ) ) { + return { ...action, icon: icon as WidgetIcon }; + } + + if ( holdPending && typeof icon === 'string' ) { + return { ...action, icon: pendingIcon }; + } + + return action; + } ); } /* `true` while records or their metadata imports are still resolving; hosts @@ -141,7 +152,12 @@ export function useWidgetTypes( ? { keywords: record.keywords } : {} ), ...( actions - ? { actions: withRenderableIcons( actions ) } + ? { + actions: withRenderableIcons( + actions, + actions === record.actions + ), + } : {} ), } as WidgetType; } catch { @@ -192,9 +208,8 @@ export function useWidgetTypes( } /* - * Each record action's icon reference resolves off the gate - * and patches into the emitted action; an unresolvable - * reference leaves the action without an icon. + * Record action icon references resolve off the gate and + * patch in; an unresolvable reference clears the stand-in. */ for ( const record of records ) { for ( const action of record.actions ?? [] ) { @@ -203,7 +218,7 @@ export function useWidgetTypes( } void resolveIcon( action.icon ).then( ( resolved ) => { - if ( cancelled || ! resolved ) { + if ( cancelled ) { return; } @@ -215,11 +230,22 @@ export function useWidgetTypes( return { ...type, - actions: type.actions?.map( ( entry ) => - entry.id === action.id - ? { ...entry, icon: resolved } - : entry - ), + actions: type.actions?.map( ( entry ) => { + if ( entry.id !== action.id ) { + return entry; + } + + if ( resolved ) { + return { + ...entry, + icon: resolved, + }; + } + + return entry.icon === pendingIcon + ? { ...entry, icon: undefined } + : entry; + } ), }; } ) ); diff --git a/packages/widget-primitives/src/stories/actions.md b/packages/widget-primitives/src/stories/actions.md index 463da463e6b389..39bc91d28ccafe 100644 --- a/packages/widget-primitives/src/stories/actions.md +++ b/packages/widget-primitives/src/stories/actions.md @@ -60,4 +60,6 @@ Where no link primitive fits, as in a command palette, the host mounts what the The widget lists its actions; it never specifies where they go. The host maps them to its surfaces: a dashboard might gather them in a "More" menu, a footer, or a command palette. -`relevance` carries the widget's side of that decision: `'high'` marks an action worth a prominent surface, `'low'` (the default) the rest. Attributes already use the same vocabulary: the widget declares intent, and the host owns the surface. +`relevance` carries the widget's side of that decision: `'high'` marks an action worth the most prominent surface, `'medium'` one worth persistent but compact visibility, and `'low'` (the default) the rest. Attributes use the same vocabulary: the widget declares intent, and the host owns the surface. + +The dashboard maps it as: `'high'` as text links in a persistent footer, `'medium'` beside them as compact icon affordances, the rest in the "More" menu. Full-bleed widgets keep every action in the menu. diff --git a/packages/widget-primitives/src/stories/anatomy.md b/packages/widget-primitives/src/stories/anatomy.md index 3c00a7f508a768..a02494fc19ceac 100644 --- a/packages/widget-primitives/src/stories/anatomy.md +++ b/packages/widget-primitives/src/stories/anatomy.md @@ -45,9 +45,10 @@ How the widget represents its data and the verbs it exposes: `attributes`, `acti The `attributes` are the contract between host and widget. The widget owns their shape and meaning; the host owns their values. -Each entry in `attributes` is a DataViews `Field` plus an optional `relevance` hint (`'high' | 'low'`). Its `type` may also reference a registered field type by name, resolved to plain `Field` props before any host reads the schema (see **Field Types**). The widget declares how important an attribute is; the host decides where, and whether, to expose it. When the hint is absent, treat it as `'low'`. +Each entry in `attributes` is a DataViews `Field` plus an optional `relevance` hint (`'high' | 'medium' | 'low'`). Its `type` may also reference a registered field type by name, resolved to plain `Field` props before any host reads the schema (see **Field Types**). The widget declares how important an attribute is; the host decides where, and whether, to expose it. When the hint is absent, treat it as `'low'`. - `'high'`: the host _may_ promote the field to a prominent surface near the instance, for quick in-context editing without opening a separate settings UI. +- `'medium'`: worth persistent but compact visibility; a host without such a surface treats it as `'low'`. - `'low'` (default): the field belongs in the host's settings surface, a form built from the full schema. The widget names importance, not a surface. One host might promote `'high'` fields inline; another might fold everything into a single panel. Both honor the same contract. diff --git a/packages/widget-primitives/src/stories/introduction.md b/packages/widget-primitives/src/stories/introduction.md index 8bfbb2e4b0c72b..59d45d9f840ad4 100644 --- a/packages/widget-primitives/src/stories/introduction.md +++ b/packages/widget-primitives/src/stories/introduction.md @@ -14,8 +14,8 @@ A _host_ is any context that renders widgets: a dashboard, a sidebar, a plugin p The shapes a host reads to discover and render a widget: -- `WidgetType`, `WidgetName`, `WidgetIcon` -- `WidgetRenderProps`, `ResolveWidgetModule`, `WidgetModuleRecord` +- `WidgetType`, `WidgetName`, `WidgetIcon` +- `WidgetRenderProps`, `ResolveWidgetModule`, `WidgetModuleRecord` Defined here and re-exported nowhere else. @@ -23,7 +23,7 @@ Defined here and re-exported nowhere else. `WidgetAttributeField< Item >` is for widget authors, not hosts. It narrows a DataViews `Field.id` to the keys of the widget's attribute object, so a typo'd field `id` is caught while authoring. -It also accepts an optional `relevance` hint (`'high' | 'low'`). The widget declares importance, not a surface. See **Anatomy** for how hosts may use it. +It also accepts an optional `relevance` hint (`'high' | 'medium' | 'low'`). The widget declares importance, not a surface. See **Anatomy** for how hosts may use it. How a widget is authored (its folder, `widget.json`, `widget.ts`, `render.tsx`) is covered in **System Architecture**. @@ -31,8 +31,8 @@ How a widget is authored (its folder, `widget.json`, `widget.ts`, `render.tsx`) `useWidgetTypes( records )` takes host-supplied widget-module records, imports each record's metadata module, and returns: -- `WidgetType[]` -- `isResolvingWidgetTypes`, which stays `true` before records are supplied (`null` or `undefined`) and while their metadata modules are still importing +- `WidgetType[]` +- `isResolvingWidgetTypes`, which stays `true` before records are supplied (`null` or `undefined`) and while their metadata modules are still importing The hook reaches for no store or endpoint. The host fetches the records however it wants and passes them in. diff --git a/packages/widget-primitives/src/types.ts b/packages/widget-primitives/src/types.ts index 733042e9925dc1..b76dcb8037aac6 100644 --- a/packages/widget-primitives/src/types.ts +++ b/packages/widget-primitives/src/types.ts @@ -62,11 +62,11 @@ export interface WidgetHelp { } /** - * How relevant a declaration is. Hosts may promote `'high'` to a prominent - * surface; `'low'` (the default) is not. The widget declares importance, - * not a surface. + * How relevant a declaration is. The widget declares importance, not a + * surface; hosts map the scale to surfaces of decreasing prominence. + * `'low'` is the default. */ -export type WidgetRelevance = 'high' | 'low'; +export type WidgetRelevance = 'high' | 'medium' | 'low'; /** * A user-triggerable verb a widget type declares. The declaration is @@ -99,9 +99,7 @@ export interface WidgetAction { icon?: WidgetIcon; /** - * How relevant the action is among the widget's actions. Hosts may - * surface `'high'` prominently; `'low'` (the default) belongs in a - * secondary surface such as a menu. + * How relevant the action is among the widget's actions. */ relevance?: WidgetRelevance; diff --git a/packages/wp-build/CHANGELOG.md b/packages/wp-build/CHANGELOG.md index bd5c9e5eb77b44..2af027045e0955 100644 --- a/packages/wp-build/CHANGELOG.md +++ b/packages/wp-build/CHANGELOG.md @@ -6,6 +6,11 @@ - Register the content module for routes that only export a `canvas`, so a route without a stage or inspector can render a custom canvas ([#81578](https://github.com/WordPress/gutenberg/pull/81578)). +### Documentation + +- Widget attributes: the `relevance` hint documents the `'medium'` tier + ([#81556](https://github.com/WordPress/gutenberg/pull/81556)). + ## 0.21.0 (2026-08-12) ### Enhancements diff --git a/packages/wp-build/README.md b/packages/wp-build/README.md index f549ec0e8b0145..3b272dca9cd973 100644 --- a/packages/wp-build/README.md +++ b/packages/wp-build/README.md @@ -6,11 +6,11 @@ Build tool for WordPress plugins. `@wordpress/build` is an opinionated build system designed for WordPress plugins. It provides: -- **Transpilation**: Converts TypeScript/JSX source code to both CommonJS (`build/`) and ESM (`build-module/`) formats using esbuild -- **Style Compilation**: Processes SCSS files and CSS modules, generating LTR and RTL versions -- **Bundling**: Creates browser-ready bundles for WordPress scripts and modules -- **PHP Generation**: Automatically generates PHP registration files for scripts, modules, and styles -- **Watch Mode**: Incremental rebuilds during development +- **Transpilation**: Converts TypeScript/JSX source code to both CommonJS (`build/`) and ESM (`build-module/`) formats using esbuild +- **Style Compilation**: Processes SCSS files and CSS modules, generating LTR and RTL versions +- **Bundling**: Creates browser-ready bundles for WordPress scripts and modules +- **PHP Generation**: Automatically generates PHP registration files for scripts, modules, and styles +- **Watch Mode**: Incremental rebuilds during development ## Installation @@ -67,9 +67,9 @@ Configure your `package.json` with the following optional fields: Controls whether the package is exposed as a bundled WordPress script/module and accessible via the configured global variable. -- **`true`**: The package will be bundled and exposed as a WordPress script. It will be available in WordPress as part of the configured global (e.g., `wp.blockEditor`, `wp.data`, or a custom global name if configured differently). +- **`true`**: The package will be bundled and exposed as a WordPress script. It will be available in WordPress as part of the configured global (e.g., `wp.blockEditor`, `wp.data`, or a custom global name if configured differently). -- **Omitted or `false` (default)**: The package will not be exposed as a WordPress script. Use this for packages designed solely as dependencies for other packages. The package can still be used as a dependency via npm imports by other packages. +- **Omitted or `false` (default)**: The package will not be exposed as a WordPress script. Use this for packages designed solely as dependencies for other packages. The package can still be used as a dependency via npm imports by other packages. ```json { @@ -107,7 +107,7 @@ Additional script dependencies: ```json { - "wpScriptExtraDependencies": ["wp-polyfill"] + "wpScriptExtraDependencies": [ "wp-polyfill" ] } ``` @@ -232,8 +232,8 @@ The prefix used for WordPress script handles in `.asset.php` files (e.g., `wp-da With this configuration: -- `@my-plugin/editor` → `window.myPlugin.editor` with handle `mp-editor` -- `@my-plugin/data` → `window.myPlugin.data` with handle `mp-data` +- `@my-plugin/editor` → `window.myPlugin.editor` with handle `mp-editor` +- `@my-plugin/data` → `window.myPlugin.data` with handle `mp-data` ### `wpPlugin.externalNamespaces` @@ -258,9 +258,9 @@ Additional package namespaces to externalize (consume as externals, not expose). This allows your packages to consume third-party dependencies as externals: -- `import { Cart } from '@woo/cart'` → `window.woo.cart` with handle `woocommerce-cart` -- `import { Button } from '@acme/ui'` → `window.acme.ui` with handle `acme-plugin-ui` -- Dependencies are tracked in `.asset.php` files +- `import { Cart } from '@woo/cart'` → `window.woo.cart` with handle `woocommerce-cart` +- `import { Button } from '@acme/ui'` → `window.acme.ui` with handle `acme-plugin-ui` +- Dependencies are tracked in `.asset.php` files If `handlePrefix` is omitted, it defaults to the namespace key (e.g., `"woo"` → `woo-cart`). @@ -277,7 +277,7 @@ Pages can be defined as simple strings or as objects with initialization modules "my-admin-page", { "id": "my-other-page", - "init": ["@my-plugin/my-page-init"] + "init": [ "@my-plugin/my-page-init" ] } ] } @@ -286,19 +286,19 @@ Pages can be defined as simple strings or as objects with initialization modules **Page Configuration:** -- **String format**: `"my-admin-page"` - Simple page with no init modules -- **Object format**: `{ "id": "page-slug", "init": ["@scope/package"], "experimental": true }` - Page with optional init modules - - **`id`** (required): The page slug used in WordPress admin URLs - - **`init`** (optional): Array of script module IDs to execute during page initialization - - **`experimental`** (optional, default `false`): When `true`, the page is excluded from WordPress Core builds (`IS_WORDPRESS_CORE=true`), along with any route that belongs only to experimental pages. +- **String format**: `"my-admin-page"` - Simple page with no init modules +- **Object format**: `{ "id": "page-slug", "init": ["@scope/package"], "experimental": true }` - Page with optional init modules + - **`id`** (required): The page slug used in WordPress admin URLs + - **`init`** (optional): Array of script module IDs to execute during page initialization + - **`experimental`** (optional, default `false`): When `true`, the page is excluded from WordPress Core builds (`IS_WORDPRESS_CORE=true`), along with any route that belongs only to experimental pages. **Generated Files:** This generates two page modes: -- `build/pages/my-admin-page/page.php` - Full-page mode (takes over entire admin screen with custom sidebar) -- `build/pages/my-admin-page/page-wp-admin.php` - WP-Admin mode (integrates within standard wp-admin interface) -- `build/pages.php` - Loader for all pages +- `build/pages/my-admin-page/page.php` - Full-page mode (takes over entire admin screen with custom sidebar) +- `build/pages/my-admin-page/page-wp-admin.php` - WP-Admin mode (integrates within standard wp-admin interface) +- `build/pages.php` - Loader for all pages Each mode provides route/menu registration functions and a render callback. Routes are automatically registered for both modes. @@ -343,8 +343,8 @@ add_menu_page( 'Title', 'Menu', 'capability', 'my-admin-page', 'my_plugin_my_adm **Init Modules:** Init modules are JavaScript packages that execute during page initialization, after menu items and routes are registered and before the app renders. They're ideal for: -- Adding icons to menu items (icons can't be passed from PHP) -- Registering command palette entries +- Adding icons to menu items (icons can't be passed from PHP) +- Registering command palette entries **Creating an Init Module:** @@ -395,9 +395,9 @@ The `init()` function is **mandatory** - all init modules must export this named This configuration: -- Packages like `@wordpress/data` expose `window.wp.data` -- Packages like `@wordpress/block-editor` expose `window.wp.blockEditor` -- All packages can consume `@wordpress/*` as externals +- Packages like `@wordpress/data` expose `window.wp.data` +- Packages like `@wordpress/block-editor` expose `window.wp.blockEditor` +- All packages can consume `@wordpress/*` as externals ### Example: Third-Party Plugin @@ -413,18 +413,18 @@ This configuration: This configuration: -- Packages like `@acme/editor` expose `window.acme.editor` -- Packages like `@acme/data` expose `window.acme.data` -- All packages can still consume `@wordpress/*` → `window.wp.*` -- All packages can still consume vendors (react, lodash) → `window.React`, `window.lodash` +- Packages like `@acme/editor` expose `window.acme.editor` +- Packages like `@acme/data` expose `window.acme.data` +- All packages can still consume `@wordpress/*` → `window.wp.*` +- All packages can still consume vendors (react, lodash) → `window.React`, `window.lodash` ### Behavior -- **Packages with `wpScript: true` matching the namespace**: Bundled with global exposure -- **Packages with `wpScript: true` not matching the namespace**: Bundled without global exposure -- **Dependencies**: `@wordpress/*` packages are always externalized to `wp.*` globals -- **Vendors**: React, lodash, jQuery, moment are always externalized to their standard globals -- **Asset files**: `.asset.php` files are always generated for WordPress dependency management +- **Packages with `wpScript: true` matching the namespace**: Bundled with global exposure +- **Packages with `wpScript: true` not matching the namespace**: Bundled without global exposure +- **Dependencies**: `@wordpress/*` packages are always externalized to `wp.*` globals +- **Vendors**: React, lodash, jQuery, moment are always externalized to their standard globals +- **Asset files**: `.asset.php` files are always generated for WordPress dependency management ## Output Structure @@ -471,15 +471,15 @@ For routes that should appear on multiple pages: { "route": { "path": "/settings", - "page": ["my-admin-page", "other-page"] + "page": [ "my-admin-page", "other-page" ] } } ``` The `page` field can be either: -- **String**: Route belongs to a single page -- **Array**: Route appears on multiple pages (the build system will register the route for each page) +- **String**: Route belongs to a single page +- **Array**: Route appears on multiple pages (the build system will register the route for each page) Each page ID must match one of the pages defined in `wpPlugin.pages` in your root `package.json`. This tells the build system which page(s) this route belongs to. It can also map to existing pages registered by other plugins. @@ -513,22 +513,22 @@ The canvas is a full-screen area typically used for editor previews. To use a cu Export a `route` object with optional hooks. Each hook receives `{ params, search }` — path parameters and query string values from the URL. -- **`beforeLoad`** — Runs before navigation completes. Use for auth checks, validation, or redirects. Throw `redirect()` or `notFound()` from `@wordpress/route` to abort navigation. -- **`loader`** — Runs while the route is loading. Use to preload data (for example, `resolveSelect` from `@wordpress/data`) so `stage` components can read from the store without a loading state. May return an object whose properties are merged into the route's loader data. For data that must be available before the JavaScript application loads, use [`rest_preload_api_request()`](https://developer.wordpress.org/reference/functions/rest_preload_api_request/) in your page's PHP render callback instead. -- **`canvas`** — Runs in parallel with `loader`. Controls which canvas is rendered depending on return values: - - `CanvasData` (`{ postType, postId, isPreview?, editLink? }`) → default WordPress editor canvas - - `null` → custom `canvas.tsx` component (if provided) - - `undefined` or omitted → no canvas +- **`beforeLoad`** — Runs before navigation completes. Use for auth checks, validation, or redirects. Throw `redirect()` or `notFound()` from `@wordpress/route` to abort navigation. +- **`loader`** — Runs while the route is loading. Use to preload data (for example, `resolveSelect` from `@wordpress/data`) so `stage` components can read from the store without a loading state. May return an object whose properties are merged into the route's loader data. For data that must be available before the JavaScript application loads, use [`rest_preload_api_request()`](https://developer.wordpress.org/reference/functions/rest_preload_api_request/) in your page's PHP render callback instead. +- **`canvas`** — Runs in parallel with `loader`. Controls which canvas is rendered depending on return values: + - `CanvasData` (`{ postType, postId, isPreview?, editLink? }`) → default WordPress editor canvas + - `null` → custom `canvas.tsx` component (if provided) + - `undefined` or omitted → no canvas ```tsx export const route = { - beforeLoad: ({ params, search }) => { + beforeLoad: ( { params, search } ) => { // Pre-navigation validation, auth checks }, - loader: ({ params, search }) => { + loader: ( { params, search } ) => { // Data preloading }, - canvas: ({ params, search }) => { + canvas: ( { params, search } ) => { // Return CanvasData to use default canvas (editor) return { postType: params.type, @@ -542,7 +542,7 @@ export const route = { // Return undefined to show no canvas // return undefined; - } + }, }; ``` @@ -550,10 +550,10 @@ export const route = { The build system generates: -- `build/routes/{route-name}/content.js` - Bundled stage/inspector/canvas components -- `build/routes/{route-name}/route.js` - Bundled lifecycle hooks (if present) -- `build/routes/registry.php` - Route registry data -- `build/routes.php` - Route registration logic +- `build/routes/{route-name}/content.js` - Bundled stage/inspector/canvas components +- `build/routes/{route-name}/route.js` - Bundled lifecycle hooks (if present) +- `build/routes/registry.php` - Route registry data +- `build/routes.php` - Route registration logic The boot package in Gutenberg will automatically use these routes and make them available. @@ -580,13 +580,13 @@ widgets/ Widgets use a dual-entry pattern, similar in spirit to how blocks split metadata between `block.json` and `edit.js`: -| Concern | Lives in | Reason | -| --- | --- | --- | -| Identity (`name`) | both (must match) | server needs it to register; client uses it to resolve the runtime entry | -| Translatable metadata (`title`, `description`, `help`, `keywords`) | `widget.json` | translated server-side via `textdomain`, so the host receives localized strings without a JS runtime | -| Framing (`category`, `presentation`) | `widget.json` | plain JSON the host reads without a JS runtime | -| Attribute schema (types, options, labels, `relevance`) | `widget.ts` | needs TypeScript coupling with `render` props; labels are translated with `__()` | -| Icon and `example` | `widget.ts` | runtime values co-located with the attribute schema | +| Concern | Lives in | Reason | +| ------------------------------------------------------------------ | ----------------- | ---------------------------------------------------------------------------------------------------- | +| Identity (`name`) | both (must match) | server needs it to register; client uses it to resolve the runtime entry | +| Translatable metadata (`title`, `description`, `help`, `keywords`) | `widget.json` | translated server-side via `textdomain`, so the host receives localized strings without a JS runtime | +| Framing (`category`, `presentation`) | `widget.json` | plain JSON the host reads without a JS runtime | +| Attribute schema (types, options, labels, `relevance`) | `widget.ts` | needs TypeScript coupling with `render` props; labels are translated with `__()` | +| Icon and `example` | `widget.ts` | runtime values co-located with the attribute schema | Rule of thumb: anything the host needs before loading a widget's module — identity, translatable copy, framing — goes in `widget.json`, which the build forwards to `build/widgets/registry.php` and exposes through the REST API. Anything that needs TypeScript or runtime values (attribute schema, icon, `example`) goes in `widget.ts`. @@ -607,14 +607,14 @@ Rule of thumb: anything the host needs before loading a widget's module — iden **Fields:** -- **`name`** (required): Namespaced identifier (e.g., `"my-plugin/hello-world"`) -- **`title`** (optional): Human-readable title. Translated server-side using `textdomain`. -- **`description`** (optional): Short description. Translated server-side using `textdomain`. -- **`help`** (optional): Contextual help note for compact surfaces. An object with `content` (may carry ``/``) and optional `links` (`label`, `href`). Translated server-side using `textdomain`. -- **`keywords`** (optional): Search aliases. Translated server-side using `textdomain`. -- **`category`** (optional): Grouping category for filtering -- **`presentation`** (optional): Rendering intent (`framed`, `content-bleed`, `full-bleed`) -- **`textdomain`** (optional): Gettext text domain for translating `title`, `description`, `help`, and `keywords` +- **`name`** (required): Namespaced identifier (e.g., `"my-plugin/hello-world"`) +- **`title`** (optional): Human-readable title. Translated server-side using `textdomain`. +- **`description`** (optional): Short description. Translated server-side using `textdomain`. +- **`help`** (optional): Contextual help note for compact surfaces. An object with `content` (may carry ``/``) and optional `links` (`label`, `href`). Translated server-side using `textdomain`. +- **`keywords`** (optional): Search aliases. Translated server-side using `textdomain`. +- **`category`** (optional): Grouping category for filtering +- **`presentation`** (optional): Rendering intent (`framed`, `content-bleed`, `full-bleed`) +- **`textdomain`** (optional): Gettext text domain for translating `title`, `description`, `help`, and `keywords` ### `widget.ts` — runtime schema @@ -657,7 +657,7 @@ const widget = { export default widget; ``` -Each attribute entry is a DataViews `Field` plus an optional `relevance` hint (`'high' | 'low'`). The widget declares importance; the host decides where to expose each field. When absent, `relevance` defaults to `'low'`. +Each attribute entry is a DataViews `Field` plus an optional `relevance` hint (`'high' | 'medium' | 'low'`). The widget declares importance; the host decides where to expose each field. When absent, `relevance` defaults to `'low'`. The same `HelloWorldAttributes` type is consumed by `render.tsx`, giving the author a single source of truth for the data contract. @@ -677,7 +677,9 @@ export default function HelloWorld( { attributes }: HelloWorldRenderProps ) { return (
Hello, { attributes.greeting ?? 'World' }! - { attributes.showDate && } + { attributes.showDate && ( + + ) }
); } @@ -689,12 +691,12 @@ All non-JSON entries are optional. The build system checks for files with extens The build system generates: -- `build/widgets/{widget-name}/render.min.js` + `render.js` — Bundled UI component (ESM) -- `build/widgets/{widget-name}/render.min.asset.php` — Asset metadata for render module -- `build/widgets/{widget-name}/widget.min.js` + `widget.js` — Bundled metadata (ESM) -- `build/widgets/{widget-name}/widget.min.asset.php` — Asset metadata for widget module -- `build/widgets/registry.php` — Widget registry data -- `build/widgets.php` — Script module registration logic +- `build/widgets/{widget-name}/render.min.js` + `render.js` — Bundled UI component (ESM) +- `build/widgets/{widget-name}/render.min.asset.php` — Asset metadata for render module +- `build/widgets/{widget-name}/widget.min.js` + `widget.js` — Bundled metadata (ESM) +- `build/widgets/{widget-name}/widget.min.asset.php` — Asset metadata for widget module +- `build/widgets/registry.php` — Widget registry data +- `build/widgets.php` — Script module registration logic ### PHP Registration diff --git a/packages/wp-build/lib/widget-utils.mjs b/packages/wp-build/lib/widget-utils.mjs index bc2a7a7f18b770..7c042a6548ea0e 100644 --- a/packages/wp-build/lib/widget-utils.mjs +++ b/packages/wp-build/lib/widget-utils.mjs @@ -34,13 +34,13 @@ export function getAllWidgets( rootDir ) { /** * @typedef {Object} WidgetActionMetadata - * @property {string} id Stable identifier, local to the widget type. - * @property {string} label Human-readable label. Translatable. - * @property {string} [icon] Registered icon name (`collection/icon-name`). - * @property {'high'|'low'} [relevance] How relevant the action is among the widget's actions. - * @property {string} href Destination the action points at. - * @property {string|boolean} [download] Download the destination; a string sets the filename. - * @property {boolean} [openInNewTab] Open the destination in a new browser tab. + * @property {string} id Stable identifier, local to the widget type. + * @property {string} label Human-readable label. Translatable. + * @property {string} [icon] Registered icon name (`collection/icon-name`). + * @property {'high'|'medium'|'low'} [relevance] How relevant the action is among the widget's actions. + * @property {string} href Destination the action points at. + * @property {string|boolean} [download] Download the destination; a string sets the filename. + * @property {boolean} [openInNewTab] Open the destination in a new browser tab. */ /** diff --git a/phpunit/experimental/class-wp-rest-widget-modules-controller-test.php b/phpunit/experimental/class-wp-rest-widget-modules-controller-test.php index 26e9ff72c3bbb2..76ff35129a918d 100644 --- a/phpunit/experimental/class-wp-rest-widget-modules-controller-test.php +++ b/phpunit/experimental/class-wp-rest-widget-modules-controller-test.php @@ -243,7 +243,7 @@ public function test_schema_exposes_expected_properties() { $this->assertArrayHasKey( 'icon', $action_properties ); $this->assertArrayHasKey( 'relevance', $action_properties ); $this->assertSame( - array( 'high', 'low' ), + array( 'high', 'medium', 'low' ), $action_properties['relevance']['enum'] ); } diff --git a/phpunit/experimental/widget-types-test.php b/phpunit/experimental/widget-types-test.php index 1e6954f117a456..24e0b1c951416e 100644 --- a/phpunit/experimental/widget-types-test.php +++ b/phpunit/experimental/widget-types-test.php @@ -354,6 +354,12 @@ public function test_sanitize_widget_actions_envelope_extras() { 'icon' => 'core/chart-bar', 'relevance' => 'high', ), + array( + 'id' => 'export', + 'label' => 'Export', + 'href' => 'https://example.com/export', + 'relevance' => 'medium', + ), array( 'id' => 'about', 'label' => 'About', @@ -373,6 +379,12 @@ public function test_sanitize_widget_actions_envelope_extras() { 'icon' => 'core/chart-bar', 'relevance' => 'high', ), + array( + 'id' => 'export', + 'label' => 'Export', + 'href' => 'https://example.com/export', + 'relevance' => 'medium', + ), array( 'id' => 'about', 'label' => 'About', diff --git a/widgets/events/render.tsx b/widgets/events/render.tsx index 5a8b603ee62702..b1ce49d9991058 100644 --- a/widgets/events/render.tsx +++ b/widgets/events/render.tsx @@ -4,7 +4,7 @@ import { store as coreStore } from '@wordpress/core-data'; import { Spinner } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { mapMarker } from '@wordpress/icons'; -import { Icon, Link, Stack, EmptyState } from '@wordpress/ui'; +import { Icon, Stack, EmptyState } from '@wordpress/ui'; import { EventsList, type WPEvent } from './components'; import type { EventsWidgetAttributes } from './types'; import styles from './style.module.css'; @@ -117,11 +117,7 @@ export default function WordPressEvents( { }, [ activeLocation, hasSelectedLocation, userLocale ] ); return ( - + { ! hasSelectedLocation && ( ) } -
- - - { __( 'Meetups' ) } - - - { __( 'WordCamps' ) } - - -
); } diff --git a/widgets/events/style.module.css b/widgets/events/style.module.css index c82736ee23df1d..42a0879bb5a122 100644 --- a/widgets/events/style.module.css +++ b/widgets/events/style.module.css @@ -8,12 +8,6 @@ padding: var(--wpds-dimension-padding-2xl); } -.footer { - border-block-start: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak); - padding-block: var(--wpds-dimension-padding-lg); - padding-inline: var(--wpds-dimension-padding-2xl); -} - .statusText { padding-inline: var(--wpds-dimension-padding-2xl); color: var(--wpds-color-foreground-content-neutral-weak); diff --git a/widgets/events/widget.json b/widgets/events/widget.json index c7fbd176484850..2a1a850460669d 100644 --- a/widgets/events/widget.json +++ b/widgets/events/widget.json @@ -5,5 +5,21 @@ "icon": "core/calendar", "category": "dashboard", "presentation": "content-bleed", + "actions": [ + { + "id": "meetups", + "label": "Meetups", + "relevance": "high", + "href": "https://make.wordpress.org/community/meetups-landing-page", + "openInNewTab": true + }, + { + "id": "wordcamps", + "label": "WordCamps", + "relevance": "high", + "href": "https://central.wordcamp.org/schedule/", + "openInNewTab": true + } + ], "textdomain": "default" } diff --git a/widgets/quick-draft/widget.json b/widgets/quick-draft/widget.json index 4b112453f9a753..eec88af4b719d8 100644 --- a/widgets/quick-draft/widget.json +++ b/widgets/quick-draft/widget.json @@ -8,5 +8,13 @@ "icon": "dashboard-widgets/drafts", "category": "dashboard", "presentation": "content-bleed", + "actions": [ + { + "id": "view-drafts", + "label": "View all drafts", + "relevance": "high", + "href": "edit.php?post_status=draft" + } + ], "textdomain": "default" }