Skip to content

Commit 8e5e9de

Browse files
chriszaratedabowmandabowmanciampojameskoster
authored
Editor: Polish real-time collaboration presence UI and move Avatar to editor package (#75652) (#76365)
* Components: Add stories and tests for Avatar and AvatarGroup * Components: Avatar: Replace `status` string prop with `dimmed` boolean The free-form `status` string generated `is-{status}` CSS modifier classes intended for ad-hoc external styling — a pattern incompatible with CSS modules. Replace with a `dimmed` boolean that bakes the visual dimming behavior directly into the component. * Editor: Use Avatar `dimmed` prop for disconnected collaborators Replace inline `opacity: 0.5` on the list item button with the Avatar component's `dimmed` prop, which provides proper desaturation and luminosity blending instead of a blunt container opacity. * Editor: Copy avatar color palette into collaborators-overlay Add `avatar-colors.ts` with an independent color palette for the overlay and presence components, decoupled from collab-sidebar/utils. Update all four consumers to import from the new module. * Components: Avatar: Auto-detect badge text color from borderColor contrast Use colord's WCAG AA readability check to set the badge name color to black or white based on the borderColor luminance. Also update the overlay's compiled Avatar styles to read the new custom property. * Components: Avatar: Add usage guidance to size prop JSDoc Describe when each size should be used rather than raw pixel values, following the same pattern as Button's size prop. * Components: Avatar: Replace `badge` boolean with `variant` enum prop Aligns with the pattern used by Button, Popover, and other components in the library. The CSS class changes from `has-badge` to `is-badge` to match the `is-{variant}` convention. * Components: Avatar: Refine dimmed state and move background to badge variant Move status indicator outside __image so it stays at full opacity when dimmed. Simplify dimmed CSS to opacity: 0.5 with $gray-700 background and border. Move outer background-color to badge variant only so it doesn't bleed through the dimmed 50% opacity. * Editor: Polish collaborators-presence button states and max avatars Update hover and pressed backgrounds to both use $gray-200 and increase the visible avatar count from 3 to 4. * Editor: Update collaborators list popover to match design Restyle the collaborators presence list to match the Figma specs: - Remove uppercase header, use flex layout with gap for title + count - Switch close icon from `close` to `closeSmall` at 24px - Replace hardcoded values with design tokens ($border-width, $sidebar-width, $border-width-focus-fallback) - Full-width list items with 12px/16px padding, no border-radius - Name text: 13px medium weight with ellipsis truncation - Theme-tinted hover state (rgba #3858e9 4%) * Editor: Move Avatar and AvatarGroup from components to collaborators-presence The components team wants more time to review before adding new components to the package. Since Avatar and AvatarGroup are only consumed by the real-time collaboration UI, move them into the editor's collaborators-presence folder where they can iterate independently. They can be promoted back to @wordpress/components when the team is ready. * Editor: Add avatar label above collaborator block highlights Renders a small Avatar badge at the top-left of each highlighted block, positioned $grid-unit-10 above the outline, so users can see who selected a block at a glance and hover to reveal the collaborator's name. * Editor: Clean up collaborators overlay and presence code for PR - Remove unused avatar background color exports and arrays - Fix JSDoc on getAvatarBorderColor to match actual return - Refactor useBlockHighlighting: useMemo → useCallback, type userStates as PostEditorAwarenessState[] to eliminate any casts, use Set for O(1) lookups in unhighlight loop - Update inline style comment to reference correct SCSS source path and note intentionally omitted dimmed/status-indicator styles - Remove whitespace in collaborator count span - Remove stories and tests (moved to add/avatar-component branch) * Editor: Unify collaborator avatar colors across collab-sidebar and overlay Replaces the separate avatar-colors.ts palette with the existing getAvatarBorderColor in collab-sidebar/utils.js, updated to use the WordPress.org Design Library colors agreed on with the design team. * Editor: Rename Avatar CSS prefix from components- to editor- Renames class names and custom properties to follow the editor package convention now that Avatar lives in the editor package. * Editor: Clarify overlay block label comment The Avatar isn't restyled — it's positioned as a label for block highlights. * Update package-lock.json for colord dependency in editor * Editor: Address PR review feedback on avatar styles - Replace hardcoded #000 with #1e1e1e ($gray-900) in badge text contrast check to match the design system's text color - Replace --wp-components-color-accent with --wp-admin-theme-color in overlay inline styles (components package variable not available in iframe) - Add token comments (e.g. /* $font-size-medium */) to hardcoded values in the overlay inline styles for maintainability - Update top-level comment to reference editor package instead of wp-components * Editor: Split overlay iframe styles into dedicated modules Extract the monolithic CSS string from overlay.tsx into three focused files with clear responsibilities: - collaborator-styles.ts: compiled design tokens from @wordpress/base-styles, used as the single source of truth for values that can't be imported as Sass inside the editor canvas iframe. - avatar-iframe-styles.ts: Avatar component CSS (mirrors avatar/styles.scss) using token constants instead of hardcoded values with comments. - overlay-iframe-styles.ts: overlay layout, cursors, block highlights, and animations. Adds z-index layering so cursor lines always render below avatar labels across users. * Editor: Add overflow: hidden fallback for Safari avatar rendering Safari < 17 does not support `overflow: clip`. Add `overflow: hidden` before `overflow: clip` as a fallback, matching the established pattern used by the Cover block. * Editor: Memoize colord() contrast check and guard role=img in Avatar Wrap the colord().isReadable() call in useMemo so it only recomputes when borderColor changes instead of on every render. Also guard role="img" and aria-label to only be set when name is provided, avoiding an unlabeled image role. * Editor: Refactor useBlockHighlighting to invalidation-token pattern Move all DOM mutations into useEffect, replacing the previous useCallback + useMemo approach. Add a recomputeToken state variable that rerenderHighlightsAfterDelay bumps via setTimeout, keeping the delayed rerender pure and stable across renders. Add cleanup effect that removes is-collaborator-selected classes and --collaborator-outline-color properties from block elements on unmount. * Editor: Use theme color variables for collaborators list hover/active Replace hardcoded #3858e9 with rgba(var(--wp-admin-theme-color--rgb)) for hover and active states, matching the established pattern in edit-site and dataviews. Make active slightly darker (0.08) than hover (0.04). Fix focus-visible fallback to use #3858e9. * Editor: Add color name comments to avatar border color palette Add inline comments identifying each hex color in the AVATAR_BORDER_COLORS array for easier reference. * Editor: Internationalize AvatarGroup overflow label Use sprintf and _n from @wordpress/i18n for the overflow count aria-label so it is translatable and properly pluralized. * Editor: Use useCallback instead of useMemo for rerenderAfterDelay Replace useMemo wrapping a function factory with useCallback, which is the idiomatic React pattern for memoizing callback functions. * Editor: Replace hardcoded colors with named constants in Avatar * Editor: Clarify avatar border color palette comment * Editor: Deduplicate block highlights by blockId When multiple collaborators select the same block, only the first one in the array gets the outline and avatar label. * Editor: Hoist overlay rect computation out of highlight loop * Components: Add CHANGELOG entry for Avatar removal * Editor: Refactor useRenderCursors to invalidation-token pattern Replace useMemo(() => () => {}) with useEffect + recomputeToken state, matching the pattern already used in useBlockHighlighting. This makes rerenderCursorsAfterDelay a stable useCallback with empty dependencies, reducing unnecessary effect re-runs from useResizeObserver. Also fix getComputedStyle to use the iframe's defaultView instead of the parent window, which is correct for cross-frame style resolution. * Editor: Capture ref value in useBlockHighlighting effect cleanup Copies `highlightedBlockIds.current` into a local variable at the top of the effect so the cleanup closure always references the same Set instance, fixing the react-hooks/exhaustive-deps warning. * Editor: Guard resolveSelection calls against stale Yjs positions Wrap resolveSelection() calls in try/catch blocks in both useBlockHighlighting and useRenderCursors hooks. The underlying createAbsolutePositionFromRelativePosition can throw when Yjs document positions become stale after edits. * Editor: Fix Safari avatar rendering with inline backgroundImage Safari does not resolve url() values inside CSS custom properties, causing avatar gravatar images to silently fail and show only the blue background-color fallback. Set backgroundImage as an inline style directly on the .editor-avatar__image span, bypassing the custom property. The --editor-avatar-url custom property is kept for the dimmed state's ::before pseudo-element. Skip the inline style when dimmed to avoid conflicting with the dimmed state's background-image: none rule. * Editor: Re-add Avatar and AvatarGroup component tests Re-implement tests for Avatar (34 tests) and AvatarGroup (11 tests) that were previously moved to the add/avatar-component branch. Updated for the editor package: class prefix (editor-avatar), custom property names (--editor-avatar-*), i18n overflow labels, and new inline backgroundImage Safari fix coverage. * Editor: Replace background-image with <img> element and load detection in Avatar Switches the Avatar component from CSS background-image to a real <img> element with a useImageLoadingStatus preloader hook. This eliminates the Safari bug where url() in CSS custom properties silently fails (including the unfixable dimmed state which used a ::before pseudo-element), and adds proper image load/error detection so broken URLs gracefully fall back to initials instead of showing empty colored circles. * Editor: Use native img events instead of Image() preloader for Avatar The side-channel `new Image()` preloader is blocked by Safari's Intelligent Tracking Prevention for third-party domains like Gravatar, causing avatars to silently fall back to initials. Replaces the preloader with native `<img onLoad/onError>` events — the `<img>` is always in the DOM (when src is truthy) at opacity 0, becoming visible via CSS when the load event fires. * Editor: Clean up Avatar review findings Use $gray-900 instead of $black for status indicator color, keep useImageLoadingStatus as a private import, and add a test for the src-change reset path. * Editor: Simplify overlay rerender logic Remove the intermediate `rerenderAfterDelay` useCallback wrapper and inline the logic directly into useResizeObserver and useEffect. This eliminates the unusual pattern of a function being both the effect callback and its own dependency. * Components: Move changelog entry to Unreleased section Move the Avatar/AvatarGroup removal changelog entry from the 32.2.0 versioned section to the Unreleased section to fix the changelog CI check. https://claude.ai/code/session_019NSHrF2BYtbLUikSpAwUPU * Editor: Fix overlay avatar falling back to initials for cached images Replace useEffect-based status reset in useImageLoadingStatus with synchronous derived state to fix a race condition when images load from browser cache. The useEffect (passive effect) runs after the DOM commit. When the overlay avatar renders inside the editor iframe, the Gravatar image is already cached (loaded earlier by the toolbar avatar), so the img element's load event fires between the commit and useEffect. The useEffect then resets status back to 'loading', but onLoad won't fire again, leaving the avatar stuck showing initials. The fix uses React's standard "store previous props in state" pattern so the reset happens synchronously during render, before the commit, eliminating the race window. https://claude.ai/code/session_019NSHrF2BYtbLUikSpAwUPU * Editor: Add crossOrigin to avatar img for Safari iframe CORP compliance Safari enforces Cross-Origin-Resource-Policy headers strictly for images loaded inside iframes. The overlay avatars render inside the editor iframe via createPortal, so Gravatar images are blocked by CORP and fall back to initials. Adding crossOrigin="anonymous" makes the browser issue a CORS request instead of an opaque one. Gravatar supports CORS (Access-Control-Allow-Origin: *), and CORS requests are exempt from CORP enforcement, fixing the issue in Safari. https://claude.ai/code/session_019NSHrF2BYtbLUikSpAwUPU * Editor: Pass rerender delay into overlay hooks instead of hardcoding * Editor: Stabilize resize observer callback with useCallback * Editor: Extract useDebouncedRecompute to debounce overlay rerenders --------- Unlinked contributors: claude. Co-authored-by: David Bowman <[email protected]> Co-authored-by: dabowman <[email protected]> Co-authored-by: ciampo <[email protected]> Co-authored-by: jameskoster <[email protected]> Co-authored-by: maxschmeling <[email protected]> Co-authored-by: chriszarate <[email protected]> Co-authored-by: jasmussen <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: tyxla <[email protected]>
1 parent 74a4f25 commit 8e5e9de

30 files changed

Lines changed: 1457 additions & 552 deletions

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
### Bug Fixes
66

7+
- Revert `word-break: break-word` addition ([#76230](https://github.com/WordPress/gutenberg/pull/76230)).
8+
- `VisuallyHidden`: Add `word-break: normal` to prevent text wrapping issues in screen reader content ([#75539](https://github.com/WordPress/gutenberg/pull/75539)).
9+
10+
### Enhancements
11+
12+
- `DateCalendar`, `DateRangeCalendar`: Add `showOutsideDays` and `fixedWeeks` props and style outside-month days ([#76199](https://github.com/WordPress/gutenberg/pull/76199)).
13+
14+
### Internal
15+
16+
- Remove `Avatar` and `AvatarGroup` from private APIs, moved to `@wordpress/editor` ([#75652](https://github.com/WordPress/gutenberg/pull/75652)).
17+
718
- `SnackbarList`: Fix scaling distortion when a snackbar's content is updated in place via a shared notice ID ([#75709](https://github.com/WordPress/gutenberg/pull/75709)).
819
- `ToggleGroupControl`: Fix hover styles on disabled items ([#75737](https://github.com/WordPress/gutenberg/pull/75737)).
920
- `FormTokenField`: Fixed incorrect height of input field when rendered on pages using WordPress 7.0 form styles ([#75880](https://github.com/WordPress/gutenberg/pull/75880)).

packages/components/src/avatar/component.tsx

Lines changed: 0 additions & 82 deletions
This file was deleted.

packages/components/src/private-apis.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import { Tabs } from './tabs';
1414
import { kebabCase, normalizeTextString } from './utils/strings';
1515
import { withIgnoreIMEEvents } from './utils/with-ignore-ime-events';
1616
import { lock } from './lock-unlock';
17-
import Avatar from './avatar';
18-
import AvatarGroup from './avatar-group';
1917
import Badge from './badge';
2018

2119
import { DateCalendar, DateRangeCalendar, TZDate } from './calendar';
@@ -36,8 +34,6 @@ import { ValidatedFormTokenField } from './validated-form-controls/components/fo
3634
export const privateApis = {};
3735
lock( privateApis, {
3836
__experimentalPopoverLegacyPositionToPlacement,
39-
Avatar,
40-
AvatarGroup,
4137
ComponentsContext,
4238
Tabs,
4339
Theme,

packages/components/src/style.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@use "@wordpress/base-styles/mixins" as *;
22
@use "./animate/style.scss" as *;
33
@use "./autocomplete/style.scss" as *;
4-
@use "./avatar/styles.scss" as *;
5-
@use "./avatar-group/styles.scss" as *;
64
@use "./badge/styles.scss" as *;
75
@use "./button-group/style.scss" as *;
86
@use "./button/style.scss" as *;

packages/editor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"change-case": "^4.1.2",
107107
"client-zip": "^2.4.5",
108108
"clsx": "^2.1.1",
109+
"colord": "^2.7.0",
109110
"date-fns": "^3.6.0",
110111
"diff": "^4.0.2",
111112
"fast-deep-equal": "^3.1.3",

packages/editor/src/components/collab-sidebar/utils.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ export function sanitizeCommentString( str ) {
1919
export function noop() {}
2020

2121
/**
22-
* These colors are picked from the WordPress.org design library.
23-
* @see https://www.figma.com/design/HOJTpCFfa3tR0EccUlu0CM/WordPress.org-Design-Library?node-id=1-2193&t=M6WdRvTpt0mh8n6T-1
22+
* Avatar border colors chosen to be visually distinct from each other and from
23+
* the editor's semantic UI colors (Delta E > 10 between all pairs).
2424
*/
2525
const AVATAR_BORDER_COLORS = [
26-
'#3858E9', // Blueberry
27-
'#9fB1FF', // Blueberry 2
28-
'#1D35B4', // Dark Blueberry
29-
'#1A1919', // Charcoal 0
30-
'#E26F56', // Pomegranate
31-
'#33F078', // Acid Green
32-
'#FFF972', // Lemon
33-
'#7A00DF', // Purple
26+
'#C36EFF', // Purple
27+
'#FF51A8', // Pink
28+
'#E4780A', // Orange
29+
'#FF35EE', // Magenta
30+
'#879F11', // Olive
31+
'#46A494', // Teal
32+
'#00A2C3', // Cyan
3433
];
3534

3635
/**
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Compiled CSS for the Avatar component, for injection into the editor canvas
3+
* iframe where the editor package's SCSS is not available.
4+
*
5+
* Source: ../collaborators-presence/avatar/styles.scss
6+
*
7+
* Dimmed and status-indicator styles are intentionally omitted — they are not
8+
* used in the overlay. Keep in sync when editing the SCSS source.
9+
*/
10+
11+
import {
12+
BUTTON_SIZE_COMPACT,
13+
BUTTON_SIZE_SMALL,
14+
ELEVATION_X_SMALL,
15+
FONT_LINE_HEIGHT_SMALL,
16+
FONT_SIZE_MEDIUM,
17+
FONT_SIZE_X_SMALL,
18+
FONT_WEIGHT_MEDIUM,
19+
GRID_UNIT_05,
20+
GRID_UNIT_10,
21+
RADIUS_FULL,
22+
WHITE,
23+
} from './collaborator-styles';
24+
25+
export const AVATAR_IFRAME_STYLES = `
26+
.editor-avatar {
27+
position: relative;
28+
display: inline-flex;
29+
align-items: center;
30+
border-radius: ${ RADIUS_FULL };
31+
overflow: hidden;
32+
overflow: clip;
33+
flex-shrink: 0;
34+
box-shadow: 0 0 0 var(--wp-admin-border-width-focus, 2px) ${ WHITE }, ${ ELEVATION_X_SMALL };
35+
}
36+
.editor-avatar__image {
37+
box-sizing: border-box;
38+
position: relative;
39+
width: ${ BUTTON_SIZE_COMPACT };
40+
height: ${ BUTTON_SIZE_COMPACT };
41+
border-radius: ${ RADIUS_FULL };
42+
border: 0;
43+
background-color: var(--wp-admin-theme-color, #3858e9);
44+
overflow: hidden;
45+
overflow: clip;
46+
flex-shrink: 0;
47+
font-size: 0;
48+
color: ${ WHITE };
49+
}
50+
.is-small > .editor-avatar__image {
51+
width: ${ BUTTON_SIZE_SMALL };
52+
height: ${ BUTTON_SIZE_SMALL };
53+
}
54+
.has-avatar-border-color > .editor-avatar__image {
55+
border: var(--wp-admin-border-width-focus, 2px) solid var(--editor-avatar-outline-color);
56+
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus, 2px) ${ WHITE };
57+
background-clip: padding-box;
58+
}
59+
.editor-avatar__img {
60+
position: absolute;
61+
inset: 0;
62+
width: 100%;
63+
height: 100%;
64+
object-fit: cover;
65+
border-radius: inherit;
66+
opacity: 0;
67+
}
68+
.has-src > .editor-avatar__image > .editor-avatar__img {
69+
opacity: 1;
70+
}
71+
.editor-avatar:not(.has-src) > .editor-avatar__image {
72+
display: flex;
73+
align-items: center;
74+
justify-content: center;
75+
font-size: ${ FONT_SIZE_X_SMALL };
76+
font-weight: ${ FONT_WEIGHT_MEDIUM };
77+
border: 0;
78+
box-shadow: none;
79+
background-clip: border-box;
80+
}
81+
.editor-avatar:not(.has-src).has-avatar-border-color > .editor-avatar__image {
82+
background-color: var(--editor-avatar-outline-color);
83+
}
84+
.editor-avatar__name {
85+
font-size: ${ FONT_SIZE_MEDIUM };
86+
font-weight: ${ FONT_WEIGHT_MEDIUM };
87+
line-height: ${ FONT_LINE_HEIGHT_SMALL };
88+
color: var(--editor-avatar-name-color, ${ WHITE });
89+
min-width: 0;
90+
padding-bottom: 2px; /* $grid-unit-05 / 2 */
91+
overflow: hidden;
92+
opacity: 0;
93+
white-space: nowrap;
94+
transition: opacity 0.15s cubic-bezier(0.15, 0, 0.15, 1);
95+
}
96+
.editor-avatar.is-badge {
97+
display: inline-grid;
98+
grid-template-columns: min-content 0fr;
99+
column-gap: 0;
100+
padding-inline-end: 0;
101+
background-color: var(--wp-admin-theme-color, #3858e9);
102+
transition:
103+
grid-template-columns 0.3s cubic-bezier(0.15, 0, 0.15, 1),
104+
column-gap 0.3s cubic-bezier(0.15, 0, 0.15, 1),
105+
padding-inline-end 0.3s cubic-bezier(0.15, 0, 0.15, 1);
106+
}
107+
.editor-avatar.is-badge:hover {
108+
grid-template-columns: min-content 1fr;
109+
column-gap: ${ GRID_UNIT_05 };
110+
padding-inline-end: ${ GRID_UNIT_10 };
111+
transition-timing-function: cubic-bezier(0.85, 0, 0.85, 1);
112+
}
113+
.editor-avatar.is-badge:hover .editor-avatar__name {
114+
opacity: 1;
115+
transition-timing-function: cubic-bezier(0.85, 0, 0.85, 1);
116+
}
117+
.editor-avatar.is-badge.has-avatar-border-color {
118+
background-color: var(--editor-avatar-outline-color);
119+
}
120+
@media (prefers-reduced-motion: reduce) {
121+
.editor-avatar.is-badge,
122+
.editor-avatar__name {
123+
transition: none;
124+
}
125+
}
126+
`;
Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
/**
2-
* Compiled CSS value of $elevation-x-small.
3-
* Keep in sync with @wordpress/base-styles/_variables.scss.
2+
* Compiled values of `@wordpress/base-styles` design tokens, for use in
3+
* CSS strings injected into the editor canvas iframe where Sass is not
4+
* available.
5+
*
6+
* Keep in sync with `@wordpress/base-styles`.
47
*/
8+
9+
// _variables.scss — $elevation-x-small
510
export const ELEVATION_X_SMALL =
611
'0 1px 1px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.02), 0 3px 3px rgba(0, 0, 0, 0.02), 0 4px 4px rgba(0, 0, 0, 0.01)';
12+
13+
// _variables.scss — $radius-full
14+
export const RADIUS_FULL = '9999px';
15+
16+
// _variables.scss — $button-size-compact
17+
export const BUTTON_SIZE_COMPACT = '32px';
18+
19+
// _variables.scss — $button-size-small
20+
export const BUTTON_SIZE_SMALL = '24px';
21+
22+
// _variables.scss — $grid-unit-05
23+
export const GRID_UNIT_05 = '4px';
24+
25+
// _variables.scss — $grid-unit-10
26+
export const GRID_UNIT_10 = '8px';
27+
28+
// _variables.scss — $border-width
29+
export const BORDER_WIDTH = '1px';
30+
31+
// _variables.scss — $border-width-focus-fallback
32+
export const BORDER_WIDTH_FOCUS_FALLBACK = '2px';
33+
34+
// _colors.scss — $white
35+
export const WHITE = '#fff';
36+
37+
// _font.scss — $font-size-x-small
38+
export const FONT_SIZE_X_SMALL = '11px';
39+
40+
// _font.scss — $font-size-medium
41+
export const FONT_SIZE_MEDIUM = '13px';
42+
43+
// _font.scss — $font-weight-medium
44+
export const FONT_WEIGHT_MEDIUM = '499';
45+
46+
// _font.scss — $font-line-height-small
47+
export const FONT_LINE_HEIGHT_SMALL = '20px';

0 commit comments

Comments
 (0)