@openartifactsai/editor-kit 0.0.0-stage → 0.23.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +143 -2
- package/package.json +67 -4
- package/src/Announcer.d.ts +2 -0
- package/src/Announcer.js +8 -0
- package/src/FindBar.d.ts +31 -0
- package/src/FindBar.js +37 -0
- package/src/FoldToolbar.d.ts +58 -0
- package/src/FoldToolbar.js +438 -0
- package/src/PanelEdge.d.ts +20 -0
- package/src/PanelEdge.js +74 -0
- package/src/VideoShrinkNotice.d.ts +10 -0
- package/src/VideoShrinkNotice.js +81 -0
- package/src/WheelZoomItem.d.ts +12 -0
- package/src/WheelZoomItem.js +18 -0
- package/src/agent.d.ts +68 -0
- package/src/agent.js +113 -0
- package/src/announce.d.ts +21 -0
- package/src/announce.js +31 -0
- package/src/chrome.d.ts +208 -0
- package/src/chrome.js +148 -0
- package/src/clipboard.d.ts +19 -0
- package/src/clipboard.js +48 -0
- package/src/collab/CommentList.d.ts +32 -0
- package/src/collab/CommentList.js +165 -0
- package/src/collab/CommentViews.d.ts +131 -0
- package/src/collab/CommentViews.js +619 -0
- package/src/collab/HistoryViews.d.ts +38 -0
- package/src/collab/HistoryViews.js +103 -0
- package/src/collab/PresenceViews.d.ts +53 -0
- package/src/collab/PresenceViews.js +48 -0
- package/src/collab/cds/cds.d.ts +151 -0
- package/src/collab/cds/cds.js +231 -0
- package/src/collab/cds/comment-card.d.ts +113 -0
- package/src/collab/cds/comment-card.js +230 -0
- package/src/collab/cds/comment-composer.d.ts +35 -0
- package/src/collab/cds/comment-composer.js +125 -0
- package/src/collab/cds/comments-css.d.ts +2 -0
- package/src/collab/cds/comments-css.js +3 -0
- package/src/collab/cds/comments.css +504 -0
- package/src/collab/cds/edge-piles.d.ts +69 -0
- package/src/collab/cds/edge-piles.js +178 -0
- package/src/collab/cds/layer.d.ts +41 -0
- package/src/collab/cds/layer.js +144 -0
- package/src/collab/cds/markdown.d.ts +20 -0
- package/src/collab/cds/markdown.js +534 -0
- package/src/collab/cds/shield.d.ts +28 -0
- package/src/collab/cds/shield.js +114 -0
- package/src/collab/cds/time.d.ts +2 -0
- package/src/collab/cds/time.js +41 -0
- package/src/collab/collab.d.ts +102 -0
- package/src/collab/collab.js +121 -0
- package/src/collab/comments.d.ts +272 -0
- package/src/collab/comments.js +596 -0
- package/src/collab/history-wiring.d.ts +32 -0
- package/src/collab/history-wiring.js +53 -0
- package/src/collab/history.d.ts +59 -0
- package/src/collab/history.js +96 -0
- package/src/collab/mentions/mention-list.d.ts +63 -0
- package/src/collab/mentions/mention-list.js +257 -0
- package/src/collab/mentions.d.ts +112 -0
- package/src/collab/mentions.js +164 -0
- package/src/collab/peer-colors.d.ts +123 -0
- package/src/collab/peer-colors.js +273 -0
- package/src/collab/pins.d.ts +70 -0
- package/src/collab/pins.js +44 -0
- package/src/collab/presence.d.ts +92 -0
- package/src/collab/presence.js +158 -0
- package/src/design-systems.d.ts +46 -0
- package/src/design-systems.js +61 -0
- package/src/downloads.d.ts +31 -0
- package/src/downloads.js +46 -0
- package/src/file-drop.d.ts +33 -0
- package/src/file-drop.js +36 -0
- package/src/find.d.ts +64 -0
- package/src/find.js +147 -0
- package/src/follow.d.ts +141 -0
- package/src/follow.js +389 -0
- package/src/index.d.ts +32 -0
- package/src/index.js +32 -0
- package/src/keys.d.ts +18 -0
- package/src/keys.js +42 -0
- package/src/menu-fit.d.ts +12 -0
- package/src/menu-fit.js +9 -0
- package/src/merge.d.ts +23 -0
- package/src/merge.js +116 -0
- package/src/page-link.d.ts +33 -0
- package/src/page-link.js +75 -0
- package/src/project-sync.d.ts +161 -0
- package/src/project-sync.js +319 -0
- package/src/react.d.ts +20 -0
- package/src/react.js +20 -0
- package/src/read-retries.d.ts +55 -0
- package/src/read-retries.js +125 -0
- package/src/right-drag-pan.d.ts +128 -0
- package/src/right-drag-pan.js +253 -0
- package/src/roles.d.ts +39 -0
- package/src/roles.js +27 -0
- package/src/session.d.ts +56 -0
- package/src/session.js +57 -0
- package/src/shell.d.ts +60 -0
- package/src/shell.js +111 -0
- package/src/stash.d.ts +26 -0
- package/src/stash.js +69 -0
- package/src/styles.css +17 -0
- package/src/toolbar-fold.d.ts +106 -0
- package/src/toolbar-fold.js +130 -0
- package/src/video-shrink/index.d.ts +8 -0
- package/src/video-shrink/index.js +7 -0
- package/src/video-shrink/plan.d.ts +92 -0
- package/src/video-shrink/plan.js +133 -0
- package/src/video-shrink/protocol.d.ts +29 -0
- package/src/video-shrink/protocol.js +2 -0
- package/src/video-shrink/queue.d.ts +69 -0
- package/src/video-shrink/queue.js +287 -0
- package/src/video-shrink/worker.d.ts +8 -0
- package/src/video-shrink/worker.js +223 -0
- package/src/wheel-zoom.d.ts +14 -0
- package/src/wheel-zoom.js +48 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CommentCard and its parts: same DOM, data attributes and class
|
|
3
|
+
* strings, the raised card and the flat one (a row in a list, `onExpand` on a click away from its controls). Left out:
|
|
4
|
+
* reactions, "show more" clamping, the toolbar's arrow-key roving, touch sizing at runtime.
|
|
5
|
+
*/
|
|
6
|
+
import { type HTMLAttributes, type ReactNode, type RefObject } from 'react';
|
|
7
|
+
import { type MenuItemSpec } from './cds.js';
|
|
8
|
+
import { type MentionsSpec } from '../mentions/mention-list.js';
|
|
9
|
+
/** Set inside a ReplyField: the composer there is the card's reply box. */
|
|
10
|
+
export declare const ReplyFieldContext: import("react").Context<boolean>;
|
|
11
|
+
/** The "Send to Agent" checkbox under a composer or an edit field. */
|
|
12
|
+
export interface SendBoxSpec {
|
|
13
|
+
label: string;
|
|
14
|
+
checked: boolean;
|
|
15
|
+
onCheckedChange: (checked: boolean) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `lockedBy`: the text mentions the agent by this name, so the comment goes to it whatever the box says. The box shows
|
|
19
|
+
* ticked and cannot be cleared (it says why); what the viewer had ticked comes back when the mention goes.
|
|
20
|
+
*/
|
|
21
|
+
export declare function SendBox({ box, disabled, lockedBy }: {
|
|
22
|
+
box: SendBoxSpec;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
lockedBy?: string;
|
|
25
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export declare function CommentCard({ variant, expanded, active, onExpand, onClose, labelledBy, reply, maxHeight, scrollRegionLabel, scrollRef, scrollProps, className, children, }: {
|
|
27
|
+
/** `flat` is a row in a list of threads (no panel of its own). */
|
|
28
|
+
variant?: 'raised' | 'flat';
|
|
29
|
+
expanded?: boolean;
|
|
30
|
+
active?: boolean;
|
|
31
|
+
/** A click or Enter on a collapsed card, away from its controls. */
|
|
32
|
+
onExpand?: () => void;
|
|
33
|
+
onClose?: () => void;
|
|
34
|
+
labelledBy?: string;
|
|
35
|
+
/** The ReplyField, drawn under the comments while the card is expanded. */
|
|
36
|
+
reply?: ReactNode;
|
|
37
|
+
/** The comments go in a region that scrolls past this height (px or a CSS length); the reply box stays under it. */
|
|
38
|
+
maxHeight?: number | string;
|
|
39
|
+
scrollRegionLabel?: string;
|
|
40
|
+
/** That scroll region, and handlers for it. */
|
|
41
|
+
scrollRef?: RefObject<HTMLDivElement | null>;
|
|
42
|
+
scrollProps?: Pick<HTMLAttributes<HTMLDivElement>, 'onPointerDownCapture' | 'onWheelCapture' | 'onScroll'>;
|
|
43
|
+
className?: string;
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export type WorkingState = 'queued' | 'working';
|
|
47
|
+
export declare function Comment({ authorName, agent, working, timestamp, actions, editor, confirm, footnote, nameId, children, }: {
|
|
48
|
+
authorName: string;
|
|
49
|
+
/** Written by the agent: the robot avatar. */
|
|
50
|
+
agent?: boolean;
|
|
51
|
+
/** The agent has it (working) or it is waiting for one (queued): a dot instead of the avatar. */
|
|
52
|
+
working?: WorkingState;
|
|
53
|
+
timestamp?: ReactNode;
|
|
54
|
+
actions?: ReactNode;
|
|
55
|
+
/** An EditField: replaces the body. */
|
|
56
|
+
editor?: ReactNode;
|
|
57
|
+
/** A DeleteConfirm: drawn under the body. */
|
|
58
|
+
confirm?: ReactNode;
|
|
59
|
+
footnote?: ReactNode;
|
|
60
|
+
nameId?: string;
|
|
61
|
+
children?: ReactNode;
|
|
62
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
/** `placement` overrides the comment's: `pinned` keeps the actions showing (the selected row of a list). */
|
|
64
|
+
export declare function Actions({ placement: forced, children }: {
|
|
65
|
+
placement?: 'pinned' | 'float';
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
/** Closes every open menu; true if one was open. */
|
|
69
|
+
export declare function closeMenus(): boolean;
|
|
70
|
+
/** A menu's open state, closed by `closeMenus` (a press elsewhere in the layer or on the page, Escape). */
|
|
71
|
+
export declare function useLayerMenu(): [boolean, (open: boolean) => void];
|
|
72
|
+
export declare function MoreMenu({ items, label, disabled, waitReason, }: {
|
|
73
|
+
items: readonly MenuItemSpec[];
|
|
74
|
+
label?: string;
|
|
75
|
+
/** The menu does not open. */
|
|
76
|
+
disabled?: boolean;
|
|
77
|
+
/** The menu opens, but every item is disabled for this reason. */
|
|
78
|
+
waitReason?: string;
|
|
79
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
80
|
+
export declare function ResolveAction({ resolved, busy, disabled, onResolve, }: {
|
|
81
|
+
resolved?: boolean;
|
|
82
|
+
busy?: boolean;
|
|
83
|
+
/** Shown but not pressable (another change is on its way). */
|
|
84
|
+
disabled?: boolean;
|
|
85
|
+
onResolve?: () => void;
|
|
86
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
87
|
+
export declare function EditField({ savedValue, onSave, onCancel, busy, sendBox, mentions, onChanged, }: {
|
|
88
|
+
savedValue: string;
|
|
89
|
+
/** `send`: hand the thread to the agent (the box, or a mention of it); `to`: whom the message names now. */
|
|
90
|
+
onSave: (text: string, how: {
|
|
91
|
+
send: boolean;
|
|
92
|
+
to: string[];
|
|
93
|
+
}) => void;
|
|
94
|
+
onCancel: () => void;
|
|
95
|
+
/** Whether the words now differ from the saved ones, each time that turns. */
|
|
96
|
+
onChanged?: (changed: boolean) => void;
|
|
97
|
+
busy?: boolean;
|
|
98
|
+
sendBox?: SendBoxSpec;
|
|
99
|
+
/** Who `@` can name (with `picked`: whom the saved text already names). */
|
|
100
|
+
mentions?: MentionsSpec;
|
|
101
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
102
|
+
export declare function DeleteConfirm({ onDelete, onCancel, busy, label }: {
|
|
103
|
+
onDelete: () => void;
|
|
104
|
+
onCancel: () => void;
|
|
105
|
+
busy?: boolean;
|
|
106
|
+
label?: string;
|
|
107
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
108
|
+
export declare function Replies({ children }: {
|
|
109
|
+
children: ReactNode;
|
|
110
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
111
|
+
export declare function ReplyField({ children }: {
|
|
112
|
+
children: ReactNode;
|
|
113
|
+
}): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* CommentCard and its parts: same DOM, data attributes and class
|
|
4
|
+
* strings, the raised card and the flat one (a row in a list, `onExpand` on a click away from its controls). Left out:
|
|
5
|
+
* reactions, "show more" clamping, the toolbar's arrow-key roving, touch sizing at runtime.
|
|
6
|
+
*/
|
|
7
|
+
import { createContext, useContext, useEffect, useId, useLayoutEffect, useRef, useState, } from 'react';
|
|
8
|
+
import { Avatar, Button, Checkbox, cn, FIELD_CLASS, focusedIn, Icon, Menu, MenuItems, MenuPopup, panelClass, panelVars, PlainEditor, returnFocus, Tooltip, useCdsRoot, } from "./cds.js";
|
|
9
|
+
import { isComposingKey } from '@openartifactsai/ui';
|
|
10
|
+
import { COMMENT_TEXT_BYTES } from "../comments.js";
|
|
11
|
+
import { AGENT_KEY } from "../mentions.js";
|
|
12
|
+
import { MentionMarks, useMentions } from "../mentions/mention-list.js";
|
|
13
|
+
const CardContext = createContext({ expanded: false });
|
|
14
|
+
const InRepliesContext = createContext(false);
|
|
15
|
+
const CloseContext = createContext(null);
|
|
16
|
+
const PlacementContext = createContext('float');
|
|
17
|
+
/** Set inside a ReplyField: the composer there is the card's reply box. */
|
|
18
|
+
export const ReplyFieldContext = createContext(false);
|
|
19
|
+
/**
|
|
20
|
+
* `lockedBy`: the text mentions the agent by this name, so the comment goes to it whatever the box says. The box shows
|
|
21
|
+
* ticked and cannot be cleared (it says why); what the viewer had ticked comes back when the mention goes.
|
|
22
|
+
*/
|
|
23
|
+
export function SendBox({ box, disabled = false, lockedBy }) {
|
|
24
|
+
if (lockedBy === undefined)
|
|
25
|
+
return _jsx(Checkbox, { label: box.label, checked: box.checked, disabled: disabled, onCheckedChange: box.onCheckedChange });
|
|
26
|
+
const reason = `Your comment mentions @${lockedBy}. Remove the mention to uncheck.`;
|
|
27
|
+
return (_jsx(Tooltip, { content: reason, children: _jsxs("span", { "data-send-locked": "", className: "inline-flex min-w-0", children: [_jsx(Checkbox, { label: box.label, checked: true, disabled: true, onCheckedChange: () => { } }), _jsx("span", { className: "sr-only", children: reason })] }) }));
|
|
28
|
+
}
|
|
29
|
+
/** Hover-revealed action group of a comment that is not pinned. */
|
|
30
|
+
const FLOAT = `pointer-events-none absolute inset-y-0 end-full ps-8 opacity-0 empty:hidden [&:not(:has(button,a[href],[role=button]))]:bg-none [&:not(:has(button,a[href],[role=button]))]:ps-0 bg-[linear-gradient(to_right,transparent,var(--cds-comment-card-row-tint,transparent)_30%),linear-gradient(to_right,transparent,var(--cds-comment-card-bg,var(--cds-page-bg))_30%)] rtl:bg-[linear-gradient(to_left,transparent,var(--cds-comment-card-row-tint,transparent)_30%),linear-gradient(to_left,transparent,var(--cds-comment-card-bg,var(--cds-page-bg))_30%)] group-hover/comment:pointer-events-auto group-hover/comment:opacity-100 has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100 has-[[data-popup-open]]:pointer-events-auto has-[[data-popup-open]]:opacity-100 has-[[aria-expanded=true]]:pointer-events-auto has-[[aria-expanded=true]]:opacity-100 has-[[data-resolving]]:pointer-events-auto has-[[data-resolving]]:opacity-100 touch:pointer-events-auto touch:static touch:bg-none touch:ps-0 touch:opacity-100`;
|
|
31
|
+
/** Touch sizing of an action button. */
|
|
32
|
+
const ACTION = `touch:mx-[calc((2.75rem*var(--cds-rem-scale,1)_-_var(--cds-h-control))/2)] touch:[&:not(:has(~_:is(button,a[href],[role=button],input,[data-cds-part=resolved-mark]),~_*_:is(button,a[href],[role=button],input)))]:me-0 touch:before:absolute touch:before:top-1/2 touch:before:left-1/2 touch:before:size-[calc(2.75rem*var(--cds-rem-scale,1))] touch:before:-translate-x-1/2 touch:before:-translate-y-1/2 touch:before:content-['']`;
|
|
33
|
+
/** Touch sizing of the actions toolbar. */
|
|
34
|
+
const TOOLBAR = `touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:[--cds-h-control:calc(2rem*var(--cds-rem-scale,1))] touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:[--cds-radius:calc(0.5rem*var(--cds-rem-scale,1))] touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:mx-[calc((2.75rem*var(--cds-rem-scale,1)_-_var(--cds-h-control))/2)] touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step]):not(:has(~_:is(button,a[href],[role=button],input,[data-cds-part=resolved-mark]),~_*_:is(button,a[href],[role=button],input)))]:me-0 touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:absolute touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:top-1/2 touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:left-1/2 touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:size-[calc(2.75rem*var(--cds-rem-scale,1))] touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:-translate-x-1/2 touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:-translate-y-1/2 touch:[&_[data-cds=Button][data-cds-icon-only][data-cds-ghost]:not([data-cds-part],[data-size],[data-step])]:before:content-['']`;
|
|
35
|
+
const CARD = "group/comment-card relative flex flex-col font-sans text-body font-normal text-primary outline-none after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:content-[''] focus-visible:outline-hidden focus-visible:after:shadow-focus";
|
|
36
|
+
/** A flat card (a row in a list of threads): tinted while hovered or active. */
|
|
37
|
+
const FLAT = 'bg-[var(--cds-comment-card-row-tint,transparent)] hover:[--cds-comment-card-row-tint:var(--cds-comment-card-hover-tint,var(--cds-alpha-1))] data-[active]:[--cds-comment-card-row-tint:var(--cds-comment-card-hover-tint,var(--cds-alpha-1))] after:inset-px';
|
|
38
|
+
/** With a `maxHeight`: the box around the comments' scroll region (it draws the region's focus ring)… */
|
|
39
|
+
const SCROLL_BOX = 'relative flex min-h-0 flex-col mt-[calc(var(--cds-pad-lg)-8px)] mb-pad-xs has-[>:focus-visible]:after:pointer-events-none has-[>:focus-visible]:after:absolute has-[>:focus-visible]:after:inset-0 has-[>:focus-visible]:after:shadow-focus has-[>:focus-visible]:after:outline-hidden';
|
|
40
|
+
/** …and the region: the comments scroll in it, the reply box stays under it. */
|
|
41
|
+
const SCROLL_REGION = 'flex min-h-0 flex-col gap-sm overflow-y-auto overscroll-contain px-lg pt-[8px] pb-[max(8px,var(--cds-pad-md))] outline-none scroll-fade-y scroll-fade-hide-top scroll-fade-size-4';
|
|
42
|
+
/** What a click on a collapsed card may land on without expanding it (the replies toggle expands it). */
|
|
43
|
+
const CARD_CONTROLS = 'a[href], button, input, select, textarea, summary, label, [role="button"], [role="link"], [role="checkbox"], [role="switch"], [contenteditable]:not([contenteditable="false"]), [data-cds-part="edit-field"], [data-cds-part="delete-confirm"], [data-cds-part="reply-field"]';
|
|
44
|
+
function expandsCard(target, card) {
|
|
45
|
+
if (!(target instanceof Element) || !card.contains(target))
|
|
46
|
+
return false;
|
|
47
|
+
const selection = card.ownerDocument.getSelection();
|
|
48
|
+
if (selection !== null && !selection.isCollapsed && card.contains(selection.anchorNode))
|
|
49
|
+
return false;
|
|
50
|
+
const control = target.closest(CARD_CONTROLS);
|
|
51
|
+
return control === null || !card.contains(control) || control.matches('[data-cds-part="replies-toggle"]');
|
|
52
|
+
}
|
|
53
|
+
export function CommentCard({ variant = 'raised', expanded = true, active = false, onExpand, onClose, labelledBy, reply, maxHeight, scrollRegionLabel = 'Comment thread', scrollRef, scrollProps, className, children, }) {
|
|
54
|
+
const { dark } = useCdsRoot();
|
|
55
|
+
const raised = variant === 'raised';
|
|
56
|
+
const expandable = Boolean(onExpand) && !expanded;
|
|
57
|
+
return (_jsx(CardContext.Provider, { value: { expanded }, children: _jsx(CloseContext.Provider, { value: onClose ? { onClose } : null, children: _jsxs("article", { "data-cds": "CommentCard", "data-variant": variant, "data-expanded": expanded || undefined, "data-active": active || undefined, "aria-labelledby": labelledBy, tabIndex: expandable ? 0 : -1, className: cn(CARD, expandable && 'cursor-interactive', raised ? cn(panelClass(true), 'transition-shadow duration-fast [--cds-comment-card-bg:var(--cds-surface-2)]') : FLAT, className), style: raised ? panelVars(dark) : undefined, onClick: expandable ? event => !event.defaultPrevented && expandsCard(event.target, event.currentTarget) && onExpand?.() : undefined, onKeyDown: expandable
|
|
58
|
+
? event => {
|
|
59
|
+
if (event.defaultPrevented || event.target !== event.currentTarget || (event.key !== 'Enter' && event.key !== ' '))
|
|
60
|
+
return;
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (!event.repeat)
|
|
63
|
+
onExpand?.();
|
|
64
|
+
}
|
|
65
|
+
: undefined, children: [maxHeight === undefined ? (_jsx("div", { className: "flex min-h-0 flex-col gap-sm p-lg", children: children })) : (_jsx("div", { className: SCROLL_BOX, children: _jsx("div", { ...scrollProps, ref: scrollRef, role: "group", tabIndex: 0, "aria-label": scrollRegionLabel, className: SCROLL_REGION, style: { maxHeight }, children: children }) })), expanded && reply] }) }) }));
|
|
66
|
+
}
|
|
67
|
+
export function Comment({ authorName, agent = false, working, timestamp, actions, editor, confirm, footnote, nameId, children, }) {
|
|
68
|
+
const { expanded } = useContext(CardContext);
|
|
69
|
+
const inReplies = useContext(InRepliesContext);
|
|
70
|
+
const close = useContext(CloseContext);
|
|
71
|
+
const id = useId();
|
|
72
|
+
const ids = { name: nameId ?? `${id}-name`, time: `${id}-time`, body: `${id}-body` };
|
|
73
|
+
const placement = expanded && !inReplies ? 'pinned' : 'float';
|
|
74
|
+
const actionsEl = actions ?? (close && !inReplies ? _jsx(Actions, {}) : undefined);
|
|
75
|
+
const avatar = working ? (_jsx("span", { className: "flex size-[var(--cds-avatar-sm)] shrink-0 items-center justify-center", children: _jsx(WorkingDot, { queued: working === 'queued' }) })) : (_jsx(Avatar, { name: authorName, variant: agent ? 'agent' : 'default', size: "sm", className: "shrink-0" }));
|
|
76
|
+
const Tag = inReplies ? 'article' : 'div';
|
|
77
|
+
return (_jsxs(Tag, { "data-cds-part": "comment", "data-by-agent": agent || undefined, "data-working": working || undefined, "aria-labelledby": inReplies ? `${ids.name} ${ids.time}` : undefined, tabIndex: inReplies ? -1 : undefined, className: "group/comment relative flex flex-col gap-xs rounded outline-none focus-visible:shadow-focus focus-visible:outline-hidden touch:isolate", children: [_jsxs("div", { className: cn('relative flex flex-wrap items-center gap-x-sm text-footnote font-normal touch:z-[1]', !editor && '-mb-[calc(var(--cds-gap-xs)/2)]'), children: [_jsx("span", { "aria-hidden": "true", className: "-me-[calc(var(--cds-gap-sm)-var(--cds-gap-xs))] inline-flex shrink-0", children: avatar }), _jsxs("span", { className: "flex min-h-control flex-1 flex-wrap content-center items-baseline gap-x-xs before:h-0 before:w-16 before:basis-full before:content-['']", children: [_jsx("span", { className: "grid max-w-full grid-cols-[minmax(0,max-content)]", children: _jsx("span", { id: ids.name, className: "min-w-0 overflow-x-clip text-ellipsis whitespace-nowrap font-semibold", children: authorName }) }), timestamp != null && (_jsx("span", { id: ids.time, className: "shrink-0 text-caption font-normal whitespace-nowrap text-muted", "data-cds-part": "timestamp", children: timestamp }))] }), _jsx(PlacementContext.Provider, { value: placement, children: actionsEl })] }), editor ?? (_jsxs("div", { className: "flex flex-col text-body font-normal text-primary", "data-cds-part": "body", id: ids.body, children: [children != null && children !== '' && (_jsx("div", { className: "text-pretty wrap-anywhere [&_code]:break-all [&_pre]:max-w-full [&_pre]:overflow-x-auto", children: _jsx("div", { className: "whitespace-pre-wrap", children: children }) })), footnote != null && footnote !== false && (_jsx("span", { className: "text-caption font-normal text-[color:var(--cds-text-stays-secondary,var(--cds-text-muted))]", "data-cds-part": "footnote", children: footnote }))] })), confirm] }));
|
|
78
|
+
}
|
|
79
|
+
function WorkingDot({ queued }) {
|
|
80
|
+
return (_jsxs("span", { "aria-hidden": "true", "data-cds-part": "working-dot", className: "relative block rounded-full p-[calc(0.125rem*var(--cds-rem-scale,1))] motion-safe:animate-[cds-fade-in_var(--cds-dur-base)_var(--cds-ease-out)]", children: [!queued && (_jsx("span", { style: { animationDelay: `${-(Date.now() % 2500)}ms` }, className: "cds-working-dot-halo absolute inset-[calc(0.125rem*var(--cds-rem-scale,1))] rounded-full bg-fill-brand" })), _jsx("span", { className: cn('relative block size-[calc(0.5rem*var(--cds-rem-scale,1))] rounded-full', queued
|
|
81
|
+
? 'border-[length:calc(0.125rem*var(--cds-rem-scale,1))] border-current text-[color:var(--cds-text-stays-secondary,var(--cds-text-muted))]'
|
|
82
|
+
: 'bg-fill-brand forced-colors:border-[length:calc(0.25rem*var(--cds-rem-scale,1))]') })] }));
|
|
83
|
+
}
|
|
84
|
+
/** `placement` overrides the comment's: `pinned` keeps the actions showing (the selected row of a list). */
|
|
85
|
+
export function Actions({ placement: forced, children }) {
|
|
86
|
+
const inherited = useContext(PlacementContext);
|
|
87
|
+
const placement = forced ?? inherited;
|
|
88
|
+
const inReplies = useContext(InRepliesContext);
|
|
89
|
+
const close = useContext(CloseContext);
|
|
90
|
+
const closeButton = close && !inReplies ? (_jsx(Button, { variant: "ghost", iconOnly: true, "aria-label": close.closeLabel ?? 'Close', icon: _jsx(Icon, { name: "X", size: "sm" }), onClick: close.onClose, className: ACTION, "data-cds-part": "close" })) : null;
|
|
91
|
+
return (_jsx("span", { role: "toolbar", "aria-label": "Comment actions", tabIndex: -1, "data-cds-part": "actions", "data-placement": placement, className: cn('relative ms-auto flex shrink-0 items-center self-stretch', TOOLBAR), children: placement === 'float' ? (_jsxs(_Fragment, { children: [_jsx("span", { className: cn('flex items-center', FLOAT), children: children }), closeButton] })) : (_jsxs(_Fragment, { children: [children, closeButton] })) }));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Open menus. Base UI closes a menu on a press outside it by listening on the document, which never hears presses
|
|
95
|
+
* inside the comments layer (shield.ts stops them at the window), so the layer closes them itself.
|
|
96
|
+
*/
|
|
97
|
+
const openMenus = new Set();
|
|
98
|
+
/** Closes every open menu; true if one was open. */
|
|
99
|
+
export function closeMenus() {
|
|
100
|
+
const any = openMenus.size > 0;
|
|
101
|
+
for (const close of [...openMenus])
|
|
102
|
+
close();
|
|
103
|
+
return any;
|
|
104
|
+
}
|
|
105
|
+
/** A menu's open state, closed by `closeMenus` (a press elsewhere in the layer or on the page, Escape). */
|
|
106
|
+
export function useLayerMenu() {
|
|
107
|
+
const [open, setOpen] = useState(false);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!open)
|
|
110
|
+
return;
|
|
111
|
+
const close = () => setOpen(false);
|
|
112
|
+
openMenus.add(close);
|
|
113
|
+
return () => {
|
|
114
|
+
openMenus.delete(close);
|
|
115
|
+
};
|
|
116
|
+
}, [open]);
|
|
117
|
+
return [open, setOpen];
|
|
118
|
+
}
|
|
119
|
+
export function MoreMenu({ items, label = 'More options', disabled = false, waitReason, }) {
|
|
120
|
+
const [open, setOpen] = useLayerMenu();
|
|
121
|
+
if (items.length === 0)
|
|
122
|
+
return null;
|
|
123
|
+
return (_jsxs(Menu.Root, { open: open, onOpenChange: setOpen, modal: false, disabled: disabled, children: [_jsx(Tooltip, { content: label, disabled: open, children: _jsx(Menu.Trigger, { render: _jsx(Button, { variant: "ghost", iconOnly: true, tooltip: false, "aria-label": label, icon: _jsx(Icon, { name: "DotsHorizontal", size: "sm" }), className: ACTION, "data-cds-part": "more" }) }) }), _jsx(MenuPopup, { align: "end", children: _jsx(MenuItems, { items: items.map(item => ({
|
|
124
|
+
...item,
|
|
125
|
+
...(waitReason === undefined ? {} : { disabled: true, disabledReason: waitReason }),
|
|
126
|
+
onSelect: () => {
|
|
127
|
+
setOpen(false);
|
|
128
|
+
item.onSelect();
|
|
129
|
+
},
|
|
130
|
+
})) }) })] }));
|
|
131
|
+
}
|
|
132
|
+
export function ResolveAction({ resolved = false, busy = false, disabled = false, onResolve, }) {
|
|
133
|
+
if (resolved) {
|
|
134
|
+
return (_jsx(Tooltip, { content: "Resolved", side: "top", children: _jsx("span", { role: "img", "aria-label": "Resolved", "data-cds-part": "resolved-mark", className: "inline-flex size-control items-center justify-center", children: _jsx(Icon, { name: "CheckCircleFilled", size: "sm", className: "text-accent" }) }) }));
|
|
135
|
+
}
|
|
136
|
+
if (!onResolve)
|
|
137
|
+
return null;
|
|
138
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", iconOnly: true, "aria-label": "Resolve", ...(busy ? { 'aria-busy': true, 'aria-disabled': true } : disabled ? { 'aria-disabled': true } : {}), "data-cds-part": "resolve", "data-resolving": busy ? 'true' : undefined, icon: busy ? (_jsxs("span", { className: "cds-resolve-check relative inline-flex", children: [_jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": true, className: "pointer-events-none absolute inset-0 size-full overflow-visible", children: _jsx("rect", { className: "cds-resolve-square", x: "0.75", y: "0.75", width: "14.5", height: "14.5", rx: "4" }) }), _jsx(Icon, { name: "Check", size: "sm", className: "relative" })] })) : (_jsx(Icon, { name: "Check", size: "sm" })), onClick: busy || disabled ? undefined : onResolve, className: ACTION }), _jsx("span", { role: "status", className: "sr-only" })] }));
|
|
139
|
+
}
|
|
140
|
+
const TEXT_ENTRY = 'textarea, [contenteditable="true"], [role="textbox"]';
|
|
141
|
+
/**
|
|
142
|
+
* A part that takes focus while it is shown (an edit box, a delete confirmation): focuses `target` when it appears,
|
|
143
|
+
* and when it goes away with focus inside, gives focus back to what had it, else the comment's ⋯ button, else the card.
|
|
144
|
+
*/
|
|
145
|
+
function useFocusPart(part, target) {
|
|
146
|
+
useLayoutEffect(() => {
|
|
147
|
+
const node = part.current;
|
|
148
|
+
if (!node)
|
|
149
|
+
return;
|
|
150
|
+
const root = node.getRootNode();
|
|
151
|
+
const before = focusedIn(node);
|
|
152
|
+
const restore = before && !node.contains(before) ? before : null;
|
|
153
|
+
const el = target.current;
|
|
154
|
+
if (el) {
|
|
155
|
+
el.focus({ preventScroll: true });
|
|
156
|
+
if (el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement)
|
|
157
|
+
el.setSelectionRange(el.value.length, el.value.length);
|
|
158
|
+
}
|
|
159
|
+
return () => {
|
|
160
|
+
const active = focusedIn(node);
|
|
161
|
+
if (!active || !node.contains(active))
|
|
162
|
+
return;
|
|
163
|
+
returnFocus(root, [restore, node.closest('[data-cds-part="comment"]')?.querySelector('[data-cds-part="more"]'), node.closest('[data-cds="CommentCard"]')]);
|
|
164
|
+
};
|
|
165
|
+
}, [part, target]);
|
|
166
|
+
}
|
|
167
|
+
/** Clicks on the bare parts of a field focus its text box. */
|
|
168
|
+
function focusOnBareClick(event, box) {
|
|
169
|
+
const target = event.target;
|
|
170
|
+
if (event.defaultPrevented || target.closest(`${TEXT_ENTRY}, button, input, [role="checkbox"]`))
|
|
171
|
+
return;
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
box?.querySelector(TEXT_ENTRY)?.focus();
|
|
174
|
+
}
|
|
175
|
+
export function EditField({ savedValue, onSave, onCancel, busy = false, sendBox, mentions, onChanged, }) {
|
|
176
|
+
const [value, setValue] = useState(savedValue);
|
|
177
|
+
const [initialChecked] = useState(sendBox?.checked);
|
|
178
|
+
const part = useRef(null);
|
|
179
|
+
const box = useRef(null);
|
|
180
|
+
const editor = useRef(null);
|
|
181
|
+
const field = useMentions(mentions, value, setValue, editor);
|
|
182
|
+
const mentionsAgent = sendBox !== undefined && field.mentionsAgent;
|
|
183
|
+
useFocusPart(part, editor);
|
|
184
|
+
const changed = value.trim() !== savedValue.trim();
|
|
185
|
+
useEffect(() => onChanged?.(changed), [changed]);
|
|
186
|
+
const save = () => {
|
|
187
|
+
if (busy)
|
|
188
|
+
return;
|
|
189
|
+
const text = value.trim();
|
|
190
|
+
const send = mentionsAgent || Boolean(sendBox?.checked);
|
|
191
|
+
const unchanged = text === savedValue.trim() && sendBox?.checked === initialChecked;
|
|
192
|
+
if (text === '' || unchanged)
|
|
193
|
+
return onCancel();
|
|
194
|
+
const named = field.targets(text);
|
|
195
|
+
onSave(text, { send, to: send && !named.includes(AGENT_KEY) ? [AGENT_KEY, ...named] : named });
|
|
196
|
+
};
|
|
197
|
+
return (_jsxs("div", { ref: part, "data-cds-part": "edit-field", className: "flex flex-col gap-xs", onMouseDown: event => focusOnBareClick(event, box.current), children: [_jsxs("div", { ref: box, className: FIELD_CLASS, children: [_jsxs("div", { className: "relative min-w-0", children: [_jsx(PlainEditor, { ref: editor, "aria-label": "Edit comment", maxLength: COMMENT_TEXT_BYTES, value: value, onChange: setValue, onSubmit: save, readOnly: busy, className: "scroll-thin max-h-[8lh]", onKeyDown: event => {
|
|
198
|
+
if (field.onKeyDown(event))
|
|
199
|
+
return;
|
|
200
|
+
if (event.key === 'Escape' && !isComposingKey(event.nativeEvent)) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
event.stopPropagation();
|
|
203
|
+
if (!busy)
|
|
204
|
+
onCancel();
|
|
205
|
+
}
|
|
206
|
+
}, onKeyUp: field.onKeyUp, onClick: field.onCaret, onFocus: field.onCaret, onBlur: field.onBlur, ...(mentions ? field.aria : {}) }), _jsx(MentionMarks, { value: value, names: field.names, field: editor })] }), field.parts] }), _jsxs("div", { className: "flex flex-wrap items-center gap-sm", children: [sendBox && _jsx(SendBox, { box: sendBox, disabled: busy, lockedBy: mentionsAgent ? mentions?.agentName : undefined }), _jsxs("div", { className: "ms-auto flex items-center gap-sm", children: [_jsx(Button, { variant: "secondary", "aria-disabled": busy || undefined, onClick: busy ? undefined : onCancel, children: "Cancel" }), _jsx(Button, { variant: "primary", busy: busy, onClick: save, children: "Save" })] })] })] }));
|
|
207
|
+
}
|
|
208
|
+
export function DeleteConfirm({ onDelete, onCancel, busy = false, label }) {
|
|
209
|
+
const id = useId();
|
|
210
|
+
const part = useRef(null);
|
|
211
|
+
const cancel = useRef(null);
|
|
212
|
+
useFocusPart(part, cancel);
|
|
213
|
+
return (_jsxs("div", { ref: part, role: "group", "aria-labelledby": id, "data-cds-part": "delete-confirm", className: "flex flex-col gap-sm border-t pt-sm", children: [_jsx("span", { id: id, className: "text-body font-normal text-primary", children: label ?? 'Delete this comment?' }), _jsxs("div", { className: "flex justify-end gap-sm", children: [_jsx(Button, { ref: cancel, variant: "secondary", "aria-disabled": busy || undefined, onClick: busy ? undefined : onCancel, children: "Cancel" }), _jsx(Button, { variant: "danger", busy: busy, onClick: onDelete, children: "Delete" })] })] }));
|
|
214
|
+
}
|
|
215
|
+
export function Replies({ children }) {
|
|
216
|
+
return (_jsx(InRepliesContext.Provider, { value: true, children: _jsx("div", { "data-cds-part": "replies", className: "flex flex-col gap-sm", children: children }) }));
|
|
217
|
+
}
|
|
218
|
+
export function ReplyField({ children }) {
|
|
219
|
+
const { expanded } = useContext(CardContext);
|
|
220
|
+
const box = useRef(null);
|
|
221
|
+
if (!expanded)
|
|
222
|
+
return null;
|
|
223
|
+
const onMouseDown = (event) => {
|
|
224
|
+
if (event.target !== event.currentTarget)
|
|
225
|
+
return;
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
box.current?.querySelector(TEXT_ENTRY)?.focus();
|
|
228
|
+
};
|
|
229
|
+
return (_jsx("div", { "data-cds-part": "reply-field", className: "px-lg pb-lg group-has-[:is([data-cds-part=edit-field],[data-cds-part=delete-confirm])]/comment-card:hidden", onMouseDown: onMouseDown, children: _jsx("div", { ref: box, className: FIELD_CLASS, onMouseDown: onMouseDown, children: _jsx(ReplyFieldContext.Provider, { value: true, children: children }) }) }));
|
|
230
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CommentComposer: the standalone composer (a raised panel) and the reply box
|
|
3
|
+
* inside a card's ReplyField, with the "Send to Agent" checkbox and the @agent
|
|
4
|
+
* mention it puts in front of the text. Same DOM, data attributes and class strings.
|
|
5
|
+
*
|
|
6
|
+
* Added here: `context`, the line above a new comment that says what it is about (the anchor's label).
|
|
7
|
+
*
|
|
8
|
+
* With `mentions`, `@` opens a list of whom the comment can name (see ../mentions/mention-list.tsx). A comment that mentions the
|
|
9
|
+
* agent goes to it: the checkbox shows ticked and cannot be cleared while the mention is in the text.
|
|
10
|
+
*/
|
|
11
|
+
import { type Ref } from 'react';
|
|
12
|
+
import { type SendBoxSpec } from './comment-card.js';
|
|
13
|
+
import { type MentionsSpec } from '../mentions/mention-list.js';
|
|
14
|
+
export interface CommentComposerProps {
|
|
15
|
+
value: string;
|
|
16
|
+
onChange: (value: string) => void;
|
|
17
|
+
/** Enter or the send button; `send`: it goes to the agent (the checkbox, or a mention); `to`: whom it names. */
|
|
18
|
+
onSubmit: (text: string, how: {
|
|
19
|
+
send: boolean;
|
|
20
|
+
to: string[];
|
|
21
|
+
}) => void;
|
|
22
|
+
/** Escape. */
|
|
23
|
+
onCancel?: () => void;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
/** Omitted when no agent can take comments: no checkbox, just save. */
|
|
26
|
+
sendBox?: SendBoxSpec;
|
|
27
|
+
busy?: boolean;
|
|
28
|
+
form?: 'reply';
|
|
29
|
+
context?: string;
|
|
30
|
+
label?: string;
|
|
31
|
+
textareaRef?: Ref<HTMLTextAreaElement>;
|
|
32
|
+
/** Who `@` can name; without it `@` is plain text. */
|
|
33
|
+
mentions?: MentionsSpec;
|
|
34
|
+
}
|
|
35
|
+
export declare function CommentComposer({ value, onChange, onSubmit: submitWith, onCancel, placeholder, sendBox, busy, form, context, label, textareaRef, mentions, }: CommentComposerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* CommentComposer: the standalone composer (a raised panel) and the reply box
|
|
4
|
+
* inside a card's ReplyField, with the "Send to Agent" checkbox and the @agent
|
|
5
|
+
* mention it puts in front of the text. Same DOM, data attributes and class strings.
|
|
6
|
+
*
|
|
7
|
+
* Added here: `context`, the line above a new comment that says what it is about (the anchor's label).
|
|
8
|
+
*
|
|
9
|
+
* With `mentions`, `@` opens a list of whom the comment can name (see ../mentions/mention-list.tsx). A comment that mentions the
|
|
10
|
+
* agent goes to it: the checkbox shows ticked and cannot be cleared while the mention is in the text.
|
|
11
|
+
*/
|
|
12
|
+
import { useContext, useLayoutEffect, useRef } from 'react';
|
|
13
|
+
import { Badge, Button, cn, mergeRefs, panelClass, panelVars, PlainEditor, useCdsRoot } from "./cds.js";
|
|
14
|
+
import { COMMENT_TEXT_BYTES } from "../comments.js";
|
|
15
|
+
import { AGENT_KEY } from "../mentions.js";
|
|
16
|
+
import { ReplyFieldContext, SendBox } from "./comment-card.js";
|
|
17
|
+
import { MentionMarks, useMentions } from "../mentions/mention-list.js";
|
|
18
|
+
/** The footer shown. */
|
|
19
|
+
const FOOTER_SHOWN = 'grid-rows-[1fr] pt-md opacity-100';
|
|
20
|
+
/** The checkbox row tucks into the panel's padding. */
|
|
21
|
+
const FOOTER_TUCK = '[--cc-tuck:calc((var(--cds-h-control)_-_var(--cds-checkbox--sm))/2)] -me-[var(--cc-tuck)] -mb-[var(--cc-tuck)]';
|
|
22
|
+
const FOOTER_TUCK_REPLY = '-mb-[calc(var(--cc-tuck)_-_var(--cds-pad-md)_+_var(--cds-pad-sm))]';
|
|
23
|
+
/** An empty reply box hides its footer until it has focus. */
|
|
24
|
+
const FOOTER_IDLE = 'invisible grid-rows-[0fr] opacity-0 group-focus-within/cc:visible group-focus-within/cc:grid-rows-[1fr] group-focus-within/cc:pt-md group-focus-within/cc:opacity-100';
|
|
25
|
+
const HIDDEN = 'invisible opacity-0';
|
|
26
|
+
const ENTRY = 'text-body cds-text-entry-floored py-[calc((var(--cds-h-control)_-_1lh)_/_2)]';
|
|
27
|
+
const TEXT_ENTRY = 'textarea, [contenteditable="true"], [role="textbox"]';
|
|
28
|
+
/**
|
|
29
|
+
* Past these heights the text scrolls inside its box. `--comment-card-room` is the height the card around it may take
|
|
30
|
+
* (set by the popover it opens in), so the box shrinks before the card's own buttons are pushed out of view.
|
|
31
|
+
*/
|
|
32
|
+
const REPLY_HEIGHT = 'scroll-thin max-h-[min(5lh,var(--comment-card-room,100vh)_-_12rem)]';
|
|
33
|
+
const DRAFT_HEIGHT = 'scroll-thin max-h-[min(8lh,max(2lh,var(--comment-card-room,100vh)_-_8rem))]';
|
|
34
|
+
export function CommentComposer({ value, onChange, onSubmit: submitWith, onCancel, placeholder = 'Add your comment', sendBox, busy = false, form, context, label = 'Comment', textareaRef, mentions, }) {
|
|
35
|
+
const { dark } = useCdsRoot();
|
|
36
|
+
const inReplyField = useContext(ReplyFieldContext);
|
|
37
|
+
const reply = inReplyField || form === 'reply';
|
|
38
|
+
const standalone = !inReplyField;
|
|
39
|
+
const editor = useRef(null);
|
|
40
|
+
const field = useMentions(mentions, value, onChange, editor);
|
|
41
|
+
const agentName = mentions?.agentName ?? 'agent';
|
|
42
|
+
const mentionsAgent = sendBox !== undefined && field.mentionsAgent;
|
|
43
|
+
const sends = mentionsAgent || Boolean(sendBox?.checked);
|
|
44
|
+
const mentionable = !reply && sendBox !== undefined;
|
|
45
|
+
// The tag stands for a mention the text does not have yet.
|
|
46
|
+
const tagged = mentionable && sends && !mentionsAgent;
|
|
47
|
+
const hasSendBox = sendBox !== undefined;
|
|
48
|
+
/** Sends `text`: to the agent when the box is ticked or the text mentions it (and then it names the agent), with whom it names. */
|
|
49
|
+
const onSubmit = (text, _box) => {
|
|
50
|
+
const named = field.targets(text);
|
|
51
|
+
submitWith(text, { send: sends, to: sends && !named.includes(AGENT_KEY) ? [AGENT_KEY, ...named] : named });
|
|
52
|
+
};
|
|
53
|
+
/** The send button says where the comment goes. */
|
|
54
|
+
const namedFor = sends && sendBox ? { 'aria-label': sendBox.label } : {};
|
|
55
|
+
const empty = value.trim() === '';
|
|
56
|
+
const idle = inReplyField && !busy && empty;
|
|
57
|
+
const footerIdle = idle && hasSendBox;
|
|
58
|
+
const root = useRef(null);
|
|
59
|
+
const grid = useRef(null);
|
|
60
|
+
const mention = useRef(null);
|
|
61
|
+
// The text starts after the @agent tag: --cc-tag-w is its width.
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
const tag = mention.current;
|
|
64
|
+
const box = grid.current;
|
|
65
|
+
if (!box)
|
|
66
|
+
return;
|
|
67
|
+
if (!tag) {
|
|
68
|
+
box.style.removeProperty('--cc-tag-w');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const measure = () => box.style.setProperty('--cc-tag-w', `${tag.getBoundingClientRect().width}px`);
|
|
72
|
+
measure();
|
|
73
|
+
const observer = new ResizeObserver(measure);
|
|
74
|
+
observer.observe(tag);
|
|
75
|
+
return () => observer.disconnect();
|
|
76
|
+
}, [tagged]);
|
|
77
|
+
const submit = () => {
|
|
78
|
+
if (busy || empty)
|
|
79
|
+
return;
|
|
80
|
+
onSubmit(value.trim(), { send: Boolean(sendBox?.checked) });
|
|
81
|
+
};
|
|
82
|
+
const onKeyDown = (event) => {
|
|
83
|
+
const native = event.nativeEvent;
|
|
84
|
+
if (native.isComposing || native.keyCode === 229)
|
|
85
|
+
return;
|
|
86
|
+
if (event.key === 'Escape' && onCancel) {
|
|
87
|
+
if (value !== '') {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
}
|
|
91
|
+
onCancel();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const el = event.currentTarget;
|
|
95
|
+
if (event.key === 'Backspace' && !event.repeat && tagged && el.selectionStart === 0 && el.selectionEnd === 0) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
sendBox.onCheckedChange(false);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const onMouseDown = (event) => {
|
|
101
|
+
const target = event.target;
|
|
102
|
+
const box = root.current;
|
|
103
|
+
if (!box?.contains(target))
|
|
104
|
+
return;
|
|
105
|
+
const checkbox = target.closest('[role="checkbox"]');
|
|
106
|
+
if (checkbox && checkbox.getAttribute('aria-disabled') !== 'true') {
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const control = target.closest(`${TEXT_ENTRY}, button, input, [tabindex="0"]`);
|
|
111
|
+
const wrapsSend = Boolean(control?.querySelector('[data-cds-part="send"]'));
|
|
112
|
+
if (control && !wrapsSend && control !== box && box.contains(control))
|
|
113
|
+
return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
box.querySelector(TEXT_ENTRY)?.focus();
|
|
116
|
+
};
|
|
117
|
+
const sendButton = (_jsx(Button, { variant: "ghost", iconOnly: true, icon: "ArrowUp", "aria-label": "Send", shortcut: "enter", disabled: empty && !busy, busy: busy, onMouseDown: event => event.preventDefault(), onClick: () => {
|
|
118
|
+
submit();
|
|
119
|
+
editor.current?.focus({ preventScroll: true });
|
|
120
|
+
}, className: "shrink-0", "data-cds-part": "send", ...namedFor }));
|
|
121
|
+
const entry = (_jsxs("div", { ref: grid, className: cn('relative grid min-w-0', mentionable && 'text-body font-normal'), children: [tagged && (_jsx("span", { ref: mention, "aria-hidden": true, "data-cds-part": "mention", className: "flex h-[1lh] items-center justify-self-start [grid-area:1/1]", children: _jsxs(Badge, { children: ["@", agentName] }) })), _jsx("div", { className: "min-w-0 [grid-area:1/1]", children: _jsx(PlainEditor, { ref: mergeRefs(editor, textareaRef), value: value, onChange: onChange, onSubmit: submit, onKeyDown: (event) => field.onKeyDown(event) || onKeyDown(event), onKeyUp: field.onKeyUp, onClick: field.onCaret, onFocus: field.onCaret, onBlur: field.onBlur, ...(mentions ? field.aria : {}), placeholder: tagged ? undefined : placeholder, "aria-label": label, maxLength: COMMENT_TEXT_BYTES, readOnly: busy, "aria-disabled": busy || undefined, className: cn('min-h-[1lh] placeholder:overflow-hidden placeholder:text-ellipsis placeholder:whitespace-nowrap', inReplyField ? REPLY_HEIGHT : DRAFT_HEIGHT, tagged && 'indent-[calc(var(--cc-tag-w,0px)+var(--cds-gap-xs))]') }) }), _jsx(MentionMarks, { value: value, names: field.names, field: editor }), field.parts] }));
|
|
122
|
+
const restingSend = inReplyField && !hasSendBox ? (_jsx("span", { "data-cds-part": "send-rest", "data-idle": idle || undefined, className: cn('flex shrink-0 transition-[opacity,visibility] duration-fast ease-out motion-reduce:transition-none', idle && HIDDEN), children: sendButton })) : (sendButton);
|
|
123
|
+
const body = (_jsxs(_Fragment, { children: [standalone && context && _jsx("div", { className: "mb-md truncate text-muted", children: context }), _jsxs("div", { className: cn(hasSendBox ? 'flex min-h-control min-w-0 flex-col justify-center' : 'flex min-w-0 items-end gap-sm', !hasSendBox && inReplyField && '-me-[calc(var(--cds-pad-md)-var(--cds-pad-sm))]'), children: [_jsx("div", { className: cn('min-w-0', ENTRY, !hasSendBox && 'flex-1 self-center'), children: entry }), hasSendBox ? null : restingSend] }), hasSendBox && (_jsx("div", { "data-cds-part": "footer", "data-idle": footerIdle || undefined, className: cn('grid transition-[grid-template-rows,padding,opacity,visibility] duration-fast ease-out motion-reduce:transition-none', footerIdle ? FOOTER_IDLE : FOOTER_SHOWN), children: _jsxs("div", { className: cn('flex min-h-0 min-w-0 items-center justify-between gap-sm', FOOTER_TUCK, inReplyField && FOOTER_TUCK_REPLY, footerIdle && 'overflow-hidden group-focus-within/cc:overflow-visible'), children: [_jsx("div", { className: "flex min-w-0", children: _jsx(SendBox, { box: sendBox, disabled: busy, lockedBy: mentionsAgent ? agentName : undefined }) }), sendButton] }) }))] }));
|
|
124
|
+
return standalone ? (_jsxs("div", { ref: root, "data-cds": "CommentComposer", "data-form": reply ? 'reply' : undefined, onMouseDown: onMouseDown, className: cn(panelClass(true), 'group/cc relative flex min-w-0 flex-col p-lg font-sans text-body font-normal text-primary'), style: panelVars(dark), children: [_jsx("div", { className: "peer contents", children: body }), _jsx("div", { "aria-hidden": true, "data-draft-ring": "", className: "pointer-events-none absolute inset-px rounded-[inherit] peer-focus-within:shadow-focus" })] })) : (_jsx("div", { ref: root, "data-cds": "CommentComposer", "data-form": reply ? 'reply' : undefined, onMouseDown: onMouseDown, className: "group/cc flex min-w-0 flex-col", children: body }));
|
|
125
|
+
}
|