@wordpress/editor
Version:
Enhanced block editor for WordPress posts.
100 lines (97 loc) • 6.67 kB
JavaScript
// packages/editor/src/components/collaborators-presence/list.tsx
import { __ } from "@wordpress/i18n";
import { Popover, Button } from "@wordpress/components";
import { closeSmall } from "@wordpress/icons";
import { speak } from "@wordpress/a11y";
import Avatar from "./avatar/index.mjs";
import { getAvatarUrl } from "../collaborators-overlay/get-avatar-url.mjs";
import { getAvatarBorderColor } from "../collab-sidebar/utils.mjs";
// packages/editor/src/components/collaborators-presence/styles/collaborators-list.scss
if (typeof document !== "undefined" && process.env.NODE_ENV !== "test" && !document.head.querySelector("style[data-wp-hash='0f8400f482']")) {
const style = document.createElement("style");
style.setAttribute("data-wp-hash", "0f8400f482");
style.appendChild(document.createTextNode(".editor-collaborators-presence__list.components-popover .components-popover__content{background:#fff;border:1px solid #ddd;border-radius:8px;border-width:1px 0 0 1px;box-shadow:0 1px 2px #0000000d,0 2px 3px #0000000a,0 6px 6px #00000008,0 8px 8px #00000005}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-content{min-width:280px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-header{align-items:center;display:flex;justify-content:space-between;padding:8px 16px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-header-title{display:flex;font-size:13px;font-weight:499;gap:4px;line-height:20px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-header-title span{color:#757575}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-header-action{padding:0}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-header-action button{color:#1e1e1e;height:32px;padding:0;width:32px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-items{display:flex;flex-direction:column;padding-bottom:16px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item{all:unset;align-items:center;box-sizing:border-box;cursor:pointer;display:flex;gap:8px;padding:12px 16px;transition:background-color .2s ease;width:100%}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item:hover:not(:disabled){background-color:rgba(var(--wp-admin-theme-color--rgb),.04)}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item:active:not(:disabled){background-color:rgba(var(--wp-admin-theme-color--rgb),.08)}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item:focus-visible{outline:2px solid var(--wp-admin-theme-color,#3858e9);outline-offset:-2px}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item:disabled{cursor:default}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item-info{display:flex;flex:1;flex-direction:column;min-width:0}.editor-collaborators-presence__list.components-popover .editor-collaborators-presence__list-item-name{color:#1e1e1e;font-size:13px;font-weight:499;line-height:20px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}"));
document.head.appendChild(style);
}
// packages/editor/src/components/collaborators-presence/list.tsx
import { jsx, jsxs } from "react/jsx-runtime";
function CollaboratorsList({
activeCollaborators,
popoverAnchor,
setIsPopoverVisible,
cursorRegistry
}) {
const handleCollaboratorClick = (clientId) => {
const success = cursorRegistry.scrollToCursor(clientId, {
behavior: "smooth",
block: "center",
highlightDuration: 2e3
});
if (success) {
speak(__("Scrolled to cursor"), "polite");
setIsPopoverVisible(false);
}
};
return /* @__PURE__ */ jsx(
Popover,
{
anchor: popoverAnchor,
placement: "bottom",
offset: 8,
className: "editor-collaborators-presence__list",
onClose: () => setIsPopoverVisible(false),
children: /* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-content", children: [
/* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-header", children: [
/* @__PURE__ */ jsxs("div", { className: "editor-collaborators-presence__list-header-title", children: [
__("Collaborators"),
/* @__PURE__ */ jsx("span", { children: activeCollaborators.length })
] }),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-header-action", children: /* @__PURE__ */ jsx(
Button,
{
__next40pxDefaultSize: true,
icon: closeSmall,
iconSize: 24,
label: __("Close Collaborators List"),
onClick: () => setIsPopoverVisible(false)
}
) })
] }),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-items", children: activeCollaborators.map((collaboratorState) => {
const isCurrentUser = collaboratorState.isMe;
return /* @__PURE__ */ jsxs(
"button",
{
className: "editor-collaborators-presence__list-item",
disabled: isCurrentUser,
onClick: () => handleCollaboratorClick(
collaboratorState.clientId
),
children: [
/* @__PURE__ */ jsx(
Avatar,
{
src: getAvatarUrl(
collaboratorState.collaboratorInfo.avatar_urls
),
name: collaboratorState.collaboratorInfo.name,
borderColor: isCurrentUser ? "var(--wp-admin-theme-color)" : getAvatarBorderColor(
collaboratorState.collaboratorInfo.id
),
dimmed: !collaboratorState.isConnected
}
),
/* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-item-info", children: /* @__PURE__ */ jsx("div", { className: "editor-collaborators-presence__list-item-name", children: isCurrentUser ? __("You") : collaboratorState.collaboratorInfo.name }) })
]
},
collaboratorState.clientId
);
}) })
] })
}
);
}
export {
CollaboratorsList
};
//# sourceMappingURL=list.mjs.map