@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.
Files changed (120) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +143 -2
  4. package/package.json +67 -4
  5. package/src/Announcer.d.ts +2 -0
  6. package/src/Announcer.js +8 -0
  7. package/src/FindBar.d.ts +31 -0
  8. package/src/FindBar.js +37 -0
  9. package/src/FoldToolbar.d.ts +58 -0
  10. package/src/FoldToolbar.js +438 -0
  11. package/src/PanelEdge.d.ts +20 -0
  12. package/src/PanelEdge.js +74 -0
  13. package/src/VideoShrinkNotice.d.ts +10 -0
  14. package/src/VideoShrinkNotice.js +81 -0
  15. package/src/WheelZoomItem.d.ts +12 -0
  16. package/src/WheelZoomItem.js +18 -0
  17. package/src/agent.d.ts +68 -0
  18. package/src/agent.js +113 -0
  19. package/src/announce.d.ts +21 -0
  20. package/src/announce.js +31 -0
  21. package/src/chrome.d.ts +208 -0
  22. package/src/chrome.js +148 -0
  23. package/src/clipboard.d.ts +19 -0
  24. package/src/clipboard.js +48 -0
  25. package/src/collab/CommentList.d.ts +32 -0
  26. package/src/collab/CommentList.js +165 -0
  27. package/src/collab/CommentViews.d.ts +131 -0
  28. package/src/collab/CommentViews.js +619 -0
  29. package/src/collab/HistoryViews.d.ts +38 -0
  30. package/src/collab/HistoryViews.js +103 -0
  31. package/src/collab/PresenceViews.d.ts +53 -0
  32. package/src/collab/PresenceViews.js +48 -0
  33. package/src/collab/cds/cds.d.ts +151 -0
  34. package/src/collab/cds/cds.js +231 -0
  35. package/src/collab/cds/comment-card.d.ts +113 -0
  36. package/src/collab/cds/comment-card.js +230 -0
  37. package/src/collab/cds/comment-composer.d.ts +35 -0
  38. package/src/collab/cds/comment-composer.js +125 -0
  39. package/src/collab/cds/comments-css.d.ts +2 -0
  40. package/src/collab/cds/comments-css.js +3 -0
  41. package/src/collab/cds/comments.css +504 -0
  42. package/src/collab/cds/edge-piles.d.ts +69 -0
  43. package/src/collab/cds/edge-piles.js +178 -0
  44. package/src/collab/cds/layer.d.ts +41 -0
  45. package/src/collab/cds/layer.js +144 -0
  46. package/src/collab/cds/markdown.d.ts +20 -0
  47. package/src/collab/cds/markdown.js +534 -0
  48. package/src/collab/cds/shield.d.ts +28 -0
  49. package/src/collab/cds/shield.js +114 -0
  50. package/src/collab/cds/time.d.ts +2 -0
  51. package/src/collab/cds/time.js +41 -0
  52. package/src/collab/collab.d.ts +102 -0
  53. package/src/collab/collab.js +121 -0
  54. package/src/collab/comments.d.ts +272 -0
  55. package/src/collab/comments.js +596 -0
  56. package/src/collab/history-wiring.d.ts +32 -0
  57. package/src/collab/history-wiring.js +53 -0
  58. package/src/collab/history.d.ts +59 -0
  59. package/src/collab/history.js +96 -0
  60. package/src/collab/mentions/mention-list.d.ts +63 -0
  61. package/src/collab/mentions/mention-list.js +257 -0
  62. package/src/collab/mentions.d.ts +112 -0
  63. package/src/collab/mentions.js +164 -0
  64. package/src/collab/peer-colors.d.ts +123 -0
  65. package/src/collab/peer-colors.js +273 -0
  66. package/src/collab/pins.d.ts +70 -0
  67. package/src/collab/pins.js +44 -0
  68. package/src/collab/presence.d.ts +92 -0
  69. package/src/collab/presence.js +158 -0
  70. package/src/design-systems.d.ts +46 -0
  71. package/src/design-systems.js +61 -0
  72. package/src/downloads.d.ts +31 -0
  73. package/src/downloads.js +46 -0
  74. package/src/file-drop.d.ts +33 -0
  75. package/src/file-drop.js +36 -0
  76. package/src/find.d.ts +64 -0
  77. package/src/find.js +147 -0
  78. package/src/follow.d.ts +141 -0
  79. package/src/follow.js +389 -0
  80. package/src/index.d.ts +32 -0
  81. package/src/index.js +32 -0
  82. package/src/keys.d.ts +18 -0
  83. package/src/keys.js +42 -0
  84. package/src/menu-fit.d.ts +12 -0
  85. package/src/menu-fit.js +9 -0
  86. package/src/merge.d.ts +23 -0
  87. package/src/merge.js +116 -0
  88. package/src/page-link.d.ts +33 -0
  89. package/src/page-link.js +75 -0
  90. package/src/project-sync.d.ts +161 -0
  91. package/src/project-sync.js +319 -0
  92. package/src/react.d.ts +20 -0
  93. package/src/react.js +20 -0
  94. package/src/read-retries.d.ts +55 -0
  95. package/src/read-retries.js +125 -0
  96. package/src/right-drag-pan.d.ts +128 -0
  97. package/src/right-drag-pan.js +253 -0
  98. package/src/roles.d.ts +39 -0
  99. package/src/roles.js +27 -0
  100. package/src/session.d.ts +56 -0
  101. package/src/session.js +57 -0
  102. package/src/shell.d.ts +60 -0
  103. package/src/shell.js +111 -0
  104. package/src/stash.d.ts +26 -0
  105. package/src/stash.js +69 -0
  106. package/src/styles.css +17 -0
  107. package/src/toolbar-fold.d.ts +106 -0
  108. package/src/toolbar-fold.js +130 -0
  109. package/src/video-shrink/index.d.ts +8 -0
  110. package/src/video-shrink/index.js +7 -0
  111. package/src/video-shrink/plan.d.ts +92 -0
  112. package/src/video-shrink/plan.js +133 -0
  113. package/src/video-shrink/protocol.d.ts +29 -0
  114. package/src/video-shrink/protocol.js +2 -0
  115. package/src/video-shrink/queue.d.ts +69 -0
  116. package/src/video-shrink/queue.js +287 -0
  117. package/src/video-shrink/worker.d.ts +8 -0
  118. package/src/video-shrink/worker.js +223 -0
  119. package/src/wheel-zoom.d.ts +14 -0
  120. package/src/wheel-zoom.js +48 -0
package/src/agent.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * The agent's side of every editor: following its status, and telling the
3
+ * person how the host took a request ("Send to agent", "Ask agent to fix").
4
+ * Pure; the editor shows the message (a toast).
5
+ */
6
+ import type { AgentCapability, AgentSendResult, AgentStatus, SelectionSnapshot } from '@openartifactsai/runtime';
7
+ /** What {@link selectionSnapshotOf} takes: the selection as the request's `text` names it, taken when Send is pressed. */
8
+ export interface SelectionSnapshotInput {
9
+ /** What is selected, e.g. `elements`, `slides`, `area` ({@link SelectionSnapshot}`.kind`). */
10
+ kind: string;
11
+ /** How many are selected; at least `items.length`. */
12
+ count?: number;
13
+ /** The selected things, first ones first; more than the limit are left out (`count` still says how many). */
14
+ items?: ReadonlyArray<{
15
+ id: string;
16
+ kind?: string;
17
+ label?: string;
18
+ }>;
19
+ /** The noun for `label` (`element` → `3 selected elements`); ignored when `label` is given. */
20
+ noun?: string;
21
+ /** The one-line chip text, when the noun form does not fit (a cell range, a data pick). */
22
+ label?: string;
23
+ where?: string;
24
+ text?: string;
25
+ }
26
+ /**
27
+ * A request's `selectionSnapshot`: what was selected when the person pressed Send, for the app that shows the request
28
+ * to put beside their words (`3 selected elements`, opened to list them). `null` when nothing is selected. The type
29
+ * server and the daemon check it again; this only shapes it.
30
+ */
31
+ export declare function selectionSnapshotOf(input: SelectionSnapshotInput): SelectionSnapshot | null;
32
+ /** A message for the person. */
33
+ export interface AgentResultMessage {
34
+ title: string;
35
+ description?: string;
36
+ }
37
+ /**
38
+ * How the host took a request, for a toast. `subject` names what the agent
39
+ * checks next ("this design", "this deck", "this board"). `agent` is its
40
+ * status: one that is not woken while it idles (`wakesIdle: false`) gets a
41
+ * queued request on its next turn, which the person starts.
42
+ */
43
+ export declare function agentResultMessage(result: Pick<AgentSendResult, 'status' | 'reason' | 'drafted'>, subject: string, agent?: Pick<AgentStatus, 'name' | 'wakesIdle'>): AgentResultMessage;
44
+ /**
45
+ * The words for a request put in the agent's conversation for the person to send there (`drafted`), as the Shell
46
+ * says them: `sent` after sending, `via` for a thread or request that went that way (`label`: the same, as a label
47
+ * of its own). English, or Simplified Chinese when the page's language is Chinese.
48
+ */
49
+ export declare function draftedText(agentName?: string | null, zh?: boolean): {
50
+ sent: string;
51
+ via: string;
52
+ label: string;
53
+ };
54
+ /**
55
+ * Longest Ask a person can send from an editor, in UTF-8 bytes of the trimmed words: what the Shell's Ask and
56
+ * claude.ai's take (`MAX_ASK_BYTES` of `@openartifactsai/protocol`). Longer words are refused when sent, with
57
+ * {@link ASK_TOO_LONG} and the draft kept, never cut. What the editor adds after them (the selection, the slide) does
58
+ * not count: the type server keeps room for it.
59
+ */
60
+ export declare const ASK_TEXT_BYTES = 8000;
61
+ /** What an editor says when an Ask is over {@link ASK_TEXT_BYTES} (as the Shell's Ask says it). */
62
+ export declare const ASK_TOO_LONG = "That\u2019s too long to send.";
63
+ /** Whether the person's words are over {@link ASK_TEXT_BYTES} once trimmed. */
64
+ export declare function askTooLong(words: string): boolean;
65
+ /** A failed send result for an error thrown while sending. */
66
+ export declare function sendFailure(error: unknown): AgentSendResult;
67
+ /** Follows the agent's status (none without an agent); returns a function that stops. */
68
+ export declare function watchAgentStatus(agent: AgentCapability | null | undefined, onStatus: (status: AgentStatus) => void, onUnavailable?: () => void): () => void;
package/src/agent.js ADDED
@@ -0,0 +1,113 @@
1
+ /**
2
+ * The agent's side of every editor: following its status, and telling the
3
+ * person how the host took a request ("Send to agent", "Ask agent to fix").
4
+ * Pure; the editor shows the message (a toast).
5
+ */
6
+ /** Most items a snapshot lists (as `SELECTION_SNAPSHOT_LIMITS.items` of `@openartifactsai/protocol`). */
7
+ const SNAPSHOT_ITEMS = 20;
8
+ /**
9
+ * A request's `selectionSnapshot`: what was selected when the person pressed Send, for the app that shows the request
10
+ * to put beside their words (`3 selected elements`, opened to list them). `null` when nothing is selected. The type
11
+ * server and the daemon check it again; this only shapes it.
12
+ */
13
+ export function selectionSnapshotOf(input) {
14
+ const items = (input.items ?? [])
15
+ .filter((item) => typeof item.id === 'string' && item.id !== '')
16
+ .slice(0, SNAPSHOT_ITEMS)
17
+ .map((item) => ({ id: item.id, ...(item.kind ? { kind: item.kind } : {}), ...(item.label ? { label: item.label } : {}) }));
18
+ const count = Math.max(Math.floor(input.count ?? 0), items.length);
19
+ if (count < 1)
20
+ return null;
21
+ const noun = input.noun ?? 'item';
22
+ const label = input.label?.trim() || `${count} selected ${count === 1 ? noun : `${noun}s`}`;
23
+ return {
24
+ kind: input.kind,
25
+ label,
26
+ count,
27
+ ...(items.length ? { items } : {}),
28
+ ...(input.where ? { where: input.where } : {}),
29
+ ...(input.text ? { text: input.text } : {}),
30
+ };
31
+ }
32
+ /**
33
+ * How the host took a request, for a toast. `subject` names what the agent
34
+ * checks next ("this design", "this deck", "this board"). `agent` is its
35
+ * status: one that is not woken while it idles (`wakesIdle: false`) gets a
36
+ * queued request on its next turn, which the person starts.
37
+ */
38
+ export function agentResultMessage(result, subject, agent) {
39
+ switch (result.status) {
40
+ case 'delivered':
41
+ return result.drafted ? { title: draftedText(agent?.name).sent } : { title: 'Sent to the agent' };
42
+ case 'queued':
43
+ if (agent?.wakesIdle === false) {
44
+ const name = agent.name || 'The agent';
45
+ return { title: `Queued for ${name}`, description: `${name} gets it on its next turn. If it is idle, send it a message there to start one.` };
46
+ }
47
+ return { title: 'Queued for the agent', description: `It will see the request the next time it checks ${subject}.` };
48
+ case 'staged':
49
+ return { title: 'Request prepared', description: 'Your agent will ask before acting on it.' };
50
+ default:
51
+ return { title: 'Could not reach the agent', description: result.reason ?? 'Try again, or copy your request into the conversation.' };
52
+ }
53
+ }
54
+ /** Whether the page's language is Chinese (the Shell's rule: `zh*` → Simplified Chinese). */
55
+ function chinese() {
56
+ try {
57
+ return /^zh\b/i.test(globalThis.navigator?.language ?? '');
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /**
64
+ * The words for a request put in the agent's conversation for the person to send there (`drafted`), as the Shell
65
+ * says them: `sent` after sending, `via` for a thread or request that went that way (`label`: the same, as a label
66
+ * of its own). English, or Simplified Chinese when the page's language is Chinese.
67
+ */
68
+ export function draftedText(agentName, zh = chinese()) {
69
+ const name = String(agentName ?? '').trim();
70
+ return zh
71
+ ? { sent: `已放进 ${name || '智能体'} 的对话:到那里发出去。`, via: '在对话里,等你发出', label: '在对话里,等你发出' }
72
+ : { sent: `It is in the ${name || 'agent'} conversation now: send it there.`, via: 'in the conversation, for you to send', label: 'In the conversation, for you to send' };
73
+ }
74
+ /**
75
+ * Longest Ask a person can send from an editor, in UTF-8 bytes of the trimmed words: what the Shell's Ask and
76
+ * claude.ai's take (`MAX_ASK_BYTES` of `@openartifactsai/protocol`). Longer words are refused when sent, with
77
+ * {@link ASK_TOO_LONG} and the draft kept, never cut. What the editor adds after them (the selection, the slide) does
78
+ * not count: the type server keeps room for it.
79
+ */
80
+ export const ASK_TEXT_BYTES = 8000;
81
+ /** What an editor says when an Ask is over {@link ASK_TEXT_BYTES} (as the Shell's Ask says it). */
82
+ export const ASK_TOO_LONG = 'That’s too long to send.';
83
+ const utf8 = new TextEncoder();
84
+ /** Whether the person's words are over {@link ASK_TEXT_BYTES} once trimmed. */
85
+ export function askTooLong(words) {
86
+ return utf8.encode(words.trim()).length > ASK_TEXT_BYTES;
87
+ }
88
+ /** A failed send result for an error thrown while sending. */
89
+ export function sendFailure(error) {
90
+ return { status: 'failed', reason: error instanceof Error ? error.message : String(error) };
91
+ }
92
+ /** Follows the agent's status (none without an agent); returns a function that stops. */
93
+ export function watchAgentStatus(agent, onStatus, onUnavailable) {
94
+ if (!agent)
95
+ return () => { };
96
+ let stopped = false;
97
+ let received = false;
98
+ agent.status().then((status) => {
99
+ if (!stopped && !received)
100
+ onStatus(status);
101
+ }, () => { if (!stopped && !received)
102
+ onUnavailable?.(); });
103
+ const off = agent.onStatus(status => {
104
+ if (!stopped) {
105
+ received = true;
106
+ onStatus(status);
107
+ }
108
+ });
109
+ return () => {
110
+ stopped = true;
111
+ off();
112
+ };
113
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The screen-reader announcer core, free of any editor store: a polite live
3
+ * region's message and a serial. {@link announce} queues a message; a
4
+ * component renders `useAnnouncer` in a `role="status"` region (see
5
+ * `Announcer.tsx`). Repeating the same message re-announces it.
6
+ */
7
+ /** Longest message read out (longer ones are cut, at a word where they can be). */
8
+ export declare const ANNOUNCE_LIMIT = 200;
9
+ export interface AnnouncerState {
10
+ message: string;
11
+ /** Bumped per announcement, so the same text is read again. */
12
+ serial: number;
13
+ }
14
+ export declare const useAnnouncer: import("zustand").UseBoundStore<import("zustand").StoreApi<AnnouncerState>>;
15
+ /**
16
+ * The text read out for a message, whitespace collapsed; empty: nothing. Past {@link ANNOUNCE_LIMIT} it is cut at the
17
+ * last word break within that many characters, or mid-word when that break comes early, and ends with an ellipsis.
18
+ */
19
+ export declare function announcementText(message: string): string;
20
+ /** Reads a message out to screen readers. */
21
+ export declare function announce(message: string): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The screen-reader announcer core, free of any editor store: a polite live
3
+ * region's message and a serial. {@link announce} queues a message; a
4
+ * component renders `useAnnouncer` in a `role="status"` region (see
5
+ * `Announcer.tsx`). Repeating the same message re-announces it.
6
+ */
7
+ import { create } from 'zustand';
8
+ /** Longest message read out (longer ones are cut, at a word where they can be). */
9
+ export const ANNOUNCE_LIMIT = 200;
10
+ /** A cut at a word keeps at least this many characters; one that would keep fewer cuts at the limit instead. */
11
+ const SHORTEST_WORD_CUT = 119;
12
+ export const useAnnouncer = create()(() => ({ message: '', serial: 0 }));
13
+ /**
14
+ * The text read out for a message, whitespace collapsed; empty: nothing. Past {@link ANNOUNCE_LIMIT} it is cut at the
15
+ * last word break within that many characters, or mid-word when that break comes early, and ends with an ellipsis.
16
+ */
17
+ export function announcementText(message) {
18
+ const text = message.replace(/\s+/g, ' ').trim();
19
+ if (text.length <= ANNOUNCE_LIMIT)
20
+ return text;
21
+ const wordBreak = text.slice(0, ANNOUNCE_LIMIT).search(/\s+\S*$/);
22
+ // A cut mid-word leaves room for the ellipsis and no half of a surrogate pair.
23
+ const kept = wordBreak >= SHORTEST_WORD_CUT ? text.slice(0, wordBreak) : text.slice(0, ANNOUNCE_LIMIT - 1).replace(/[\uD800-\uDBFF]$/, '');
24
+ return `${kept}…`;
25
+ }
26
+ /** Reads a message out to screen readers. */
27
+ export function announce(message) {
28
+ const text = announcementText(message);
29
+ if (text)
30
+ useAnnouncer.setState((s) => ({ message: text, serial: s.serial + 1 }));
31
+ }
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Primitives of the editor chrome (Design, Slides and Whiteboard): floating
3
+ * cards (12px radius, hairline ring, soft shadow), 28px / 32px / 36px ghost
4
+ * controls (pressed = blue-soft), icon-only tool buttons, dark tooltips with
5
+ * key chips, menus (14px radius, 28px rows, submenus included), popovers
6
+ * and color swatch rows.
7
+ *
8
+ * Menus and popovers take a `mark` (a `data-*` attribute their popup
9
+ * carries, e.g. so a board surface starts no gesture on it) and a
10
+ * `popupBase` (classes in place of {@link POPUP}) for editors whose popups
11
+ * look different.
12
+ *
13
+ * Styled with the editor's chrome tokens (`bg-chrome`, `text-chrome-fg`,
14
+ * `bg-chrome-hover`, `bg-chrome-pressed`, `text-chrome-accent`,
15
+ * `shadow-chrome`, `bg-tip`…); the focus ring is `outline-chrome-focus`, so
16
+ * each editor picks its own focus color.
17
+ */
18
+ import { Popover as BasePopover } from '@base-ui/react/popover';
19
+ import { type ButtonHTMLAttributes, type CSSProperties, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
20
+ import type { ChromeDraw, ShellConnection } from '@openartifactsai/runtime';
21
+ import { type KeyChord } from '@openartifactsai/ui';
22
+ /** A floating chrome card. */
23
+ export declare const Card: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
24
+ /** The 1 × 18px divider between groups of controls (`vertical: false`: a full-width 1px rule between rows). */
25
+ export declare function ChromeDivider({ className, vertical }: {
26
+ className?: string;
27
+ vertical?: boolean;
28
+ }): ReactNode;
29
+ /** Where a tooltip or popup opens. */
30
+ export type ChromeSide = 'top' | 'bottom' | 'left' | 'right';
31
+ /** A `data-*` attribute a popup carries (see the module comment). */
32
+ export type ChromeMark = `data-${string}`;
33
+ /** A dark tooltip; the shortcut shows as a key chip. */
34
+ export declare function Tip({ label, shortcut, side, children, disabled, }: {
35
+ label: ReactNode;
36
+ shortcut?: string;
37
+ side?: ChromeSide;
38
+ /** Never open (e.g. while a popup of the trigger is open). */
39
+ disabled?: boolean;
40
+ children: ReactElement<Record<string, unknown>>;
41
+ }): ReactNode;
42
+ /** Shares hover delays between neighbouring tooltips. */
43
+ export declare function TipGroup({ children }: {
44
+ children: ReactNode;
45
+ }): ReactNode;
46
+ /** Props of {@link ChromeButton}. */
47
+ export interface ChromeButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
48
+ /** Pressed state (tools, toggles). */
49
+ pressed?: boolean;
50
+ /** Icon-only: a square control. */
51
+ square?: boolean;
52
+ /** Control height: 28px (cards), 32px (bottom toolbars) or 36px (a board's tool bar). */
53
+ size?: 'md' | 'lg' | 'xl';
54
+ }
55
+ /** A ghost control: 8px radius, 14px text, blue-soft when pressed. */
56
+ export declare const ChromeButton: import("react").ForwardRefExoticComponent<ChromeButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
57
+ /** A {@link ChromeButton} with a tooltip that still shows while it is disabled. */
58
+ export declare const TipButton: import("react").ForwardRefExoticComponent<ChromeButtonProps & {
59
+ tip: ReactNode;
60
+ shortcut?: string;
61
+ side?: ChromeSide;
62
+ } & import("react").RefAttributes<HTMLButtonElement>>;
63
+ /** Props of {@link ToolButton}. */
64
+ export interface ToolButtonProps extends Omit<ChromeButtonProps, 'children' | 'square'> {
65
+ /** Accessible name and tooltip text. */
66
+ label: string;
67
+ /** Longer tooltip text, when it differs from the name. */
68
+ tip?: ReactNode;
69
+ icon: ReactNode;
70
+ shortcut?: string;
71
+ tipSide?: ChromeSide;
72
+ }
73
+ /** A square, icon-only control with a tooltip (36px by default; its icon drawn at 18px). */
74
+ export declare const ToolButton: import("react").ForwardRefExoticComponent<ToolButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
75
+ /** Classes of a chrome menu's popup. */
76
+ export declare const POPUP = "min-w-[128px] max-w-[320px] rounded-[14px] bg-chrome p-1.5 text-[14px] leading-5 font-control text-chrome-fg shadow-chrome-popup outline-none origin-[var(--transform-origin)] transition-[opacity,transform] duration-100 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0";
77
+ /** A chrome menu. `trigger` is rendered as the menu's trigger. */
78
+ export declare function ChromeMenu({ trigger, children, side, align, className, tip, open, onOpenChange, sideOffset, mark, popupBase, }: {
79
+ trigger: ReactElement<Record<string, unknown>>;
80
+ children: ReactNode;
81
+ side?: ChromeSide;
82
+ align?: 'start' | 'center' | 'end';
83
+ className?: string;
84
+ /** Tooltip of the trigger. */
85
+ tip?: {
86
+ label: ReactNode;
87
+ shortcut?: string;
88
+ side?: ChromeSide;
89
+ };
90
+ open?: boolean;
91
+ onOpenChange?: (open: boolean) => void;
92
+ /** Gap between the trigger and the popup (default 6px). */
93
+ sideOffset?: number;
94
+ /** A `data-*` attribute the popup carries. */
95
+ mark?: ChromeMark;
96
+ /** Popup classes in place of {@link POPUP}. */
97
+ popupBase?: string;
98
+ }): ReactNode;
99
+ /** Props of {@link ChromeMenuItem}. */
100
+ export interface ChromeMenuItemProps {
101
+ children: ReactNode;
102
+ /** A second, muted line under the label. */
103
+ description?: ReactNode;
104
+ /** Keep the menu open after a click (default: close). */
105
+ closeOnClick?: boolean;
106
+ onSelect?: () => void;
107
+ /** Text shown at the end of the row (display only). */
108
+ shortcut?: string;
109
+ /** The row's key chord: shown at the end of the row, announced, and pressed while the menu is open. */
110
+ keys?: KeyChord;
111
+ /** Shows a check column; `true` draws the mark. */
112
+ checked?: boolean;
113
+ disabled?: boolean;
114
+ danger?: boolean;
115
+ icon?: ReactNode;
116
+ title?: string;
117
+ }
118
+ /** One menu row. A row that closes the menu keeps the rest of a double click from reaching what the menu uncovers. */
119
+ export declare function ChromeMenuItem({ children, onSelect, shortcut, keys, checked, disabled, danger, icon, title, description, closeOnClick }: ChromeMenuItemProps): ReactNode;
120
+ /** Props of {@link ChromeMenuCheckboxItem}. */
121
+ export interface ChromeMenuCheckboxItemProps {
122
+ children: ReactNode;
123
+ checked: boolean;
124
+ onCheckedChange: (checked: boolean) => void;
125
+ disabled?: boolean;
126
+ title?: string;
127
+ }
128
+ /** A menu row that turns a setting on or off; announced as a checkbox and keeps the menu open. */
129
+ export declare function ChromeMenuCheckboxItem({ children, checked, onCheckedChange, disabled, title }: ChromeMenuCheckboxItemProps): ReactNode;
130
+ /** A submenu row and its popup. */
131
+ export declare function ChromeSubmenu({ label, icon, children, disabled, className, mark, popupBase, }: {
132
+ label: ReactNode;
133
+ icon?: ReactNode;
134
+ children: ReactNode;
135
+ disabled?: boolean;
136
+ /** Extra classes of the popup. */
137
+ className?: string;
138
+ /** A `data-*` attribute the popup carries. */
139
+ mark?: ChromeMark;
140
+ /** Popup classes in place of {@link POPUP}. */
141
+ popupBase?: string;
142
+ }): ReactNode;
143
+ /** A menu separator. */
144
+ export declare function ChromeMenuSeparator(): ReactNode;
145
+ /** A muted group label inside a menu. */
146
+ export declare function ChromeMenuLabel({ children }: {
147
+ children: ReactNode;
148
+ }): ReactNode;
149
+ /** Props of {@link ChromePopover}. */
150
+ export interface ChromePopoverProps {
151
+ trigger: ReactElement<Record<string, unknown>>;
152
+ children: ReactNode;
153
+ side?: ChromeSide;
154
+ align?: 'start' | 'center' | 'end';
155
+ open?: boolean;
156
+ onOpenChange?: (open: boolean, details: ChromePopoverChange) => void;
157
+ className?: string;
158
+ /** Accessible name of the popup. */
159
+ label?: string;
160
+ /** Element the popup is positioned against instead of the trigger. */
161
+ anchor?: Element | null | (() => Element | null);
162
+ /** Gap between the anchor and the popup (default 8px). */
163
+ gap?: number;
164
+ /**
165
+ * Move focus into the popup when it opens (default: true). A function is
166
+ * told how it was opened (`''` when not by a press) and names the element
167
+ * to focus, `false` to leave focus where it is, or `null` for the first one.
168
+ */
169
+ initialFocus?: boolean | ((openedBy: 'mouse' | 'touch' | 'pen' | 'keyboard' | '') => HTMLElement | false | null);
170
+ /** A `data-*` attribute the popup carries. */
171
+ mark?: ChromeMark;
172
+ /** Popup classes in place of {@link POPUP}. */
173
+ popupBase?: string;
174
+ style?: CSSProperties;
175
+ /**
176
+ * Once something has been typed into a field of the popup (other than a
177
+ * search field), a press outside no longer closes it: Escape, or the
178
+ * popup's own buttons, do.
179
+ */
180
+ holdWhileTyped?: boolean;
181
+ }
182
+ /** Why a {@link ChromePopover} opens or closes; `cancel()` keeps it as it is. */
183
+ export type ChromePopoverChange = BasePopover.Root.ChangeEventDetails;
184
+ /** A floating chrome panel anchored to a trigger (or to `anchor`). A press outside that closes it does not double-click what is under it. */
185
+ export declare function ChromePopover({ trigger, children, side, align, open, onOpenChange, className, label, anchor, gap, initialFocus, mark, popupBase, style, holdWhileTyped, }: ChromePopoverProps): ReactNode;
186
+ /** One color choice of a {@link SwatchRow}. */
187
+ export interface Swatch {
188
+ /** The value stored (a palette name or `#rrggbb`). */
189
+ name: string;
190
+ /** CSS color drawn. */
191
+ value: string;
192
+ label: string;
193
+ }
194
+ /** A row of round color swatches (radio semantics); the current one is ringed in the chrome accent. */
195
+ export declare function SwatchRow({ label, swatches, current, onPick, size, className, }: {
196
+ label: string;
197
+ swatches: readonly Swatch[];
198
+ current: string | undefined;
199
+ onPick: (name: string) => void;
200
+ /** Diameter of a swatch, px (its hit area is 8px larger). */
201
+ size?: number;
202
+ className?: string;
203
+ }): ReactNode;
204
+ /**
205
+ * Whether the Shell framing the page draws `draw` (its save state, its export formats): the page then hides its own
206
+ * copy, so there is one of each. False outside a Shell and for Shells older than `draws`.
207
+ */
208
+ export declare function useShellDraw(shell: ShellConnection | null | undefined, draw: ChromeDraw): boolean;
package/src/chrome.js ADDED
@@ -0,0 +1,148 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Primitives of the editor chrome (Design, Slides and Whiteboard): floating
4
+ * cards (12px radius, hairline ring, soft shadow), 28px / 32px / 36px ghost
5
+ * controls (pressed = blue-soft), icon-only tool buttons, dark tooltips with
6
+ * key chips, menus (14px radius, 28px rows, submenus included), popovers
7
+ * and color swatch rows.
8
+ *
9
+ * Menus and popovers take a `mark` (a `data-*` attribute their popup
10
+ * carries, e.g. so a board surface starts no gesture on it) and a
11
+ * `popupBase` (classes in place of {@link POPUP}) for editors whose popups
12
+ * look different.
13
+ *
14
+ * Styled with the editor's chrome tokens (`bg-chrome`, `text-chrome-fg`,
15
+ * `bg-chrome-hover`, `bg-chrome-pressed`, `text-chrome-accent`,
16
+ * `shadow-chrome`, `bg-tip`…); the focus ring is `outline-chrome-focus`, so
17
+ * each editor picks its own focus color.
18
+ */
19
+ import { Menu as BaseMenu } from '@base-ui/react/menu';
20
+ import { Popover as BasePopover } from '@base-ui/react/popover';
21
+ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
22
+ import { Check, ChevronRight } from 'lucide-react';
23
+ import { forwardRef, useEffect, useRef, useState } from 'react';
24
+ import { ariaPressed, cn, keepFocusOnTipPress, menuChordParts, MenuTreeProvider, onApplePlatform, spokenShortcut, swallowFollowUpClicks, useMenuShortcutPopup, } from '@openartifactsai/ui';
25
+ import { menuFit } from "./menu-fit.js";
26
+ /** A floating chrome card. */
27
+ export const Card = forwardRef(function Card({ className, ...rest }, ref) {
28
+ return _jsx("div", { ref: ref, className: cn('pointer-events-auto flex items-center gap-1 rounded-[12px] bg-chrome text-chrome-fg shadow-chrome', className), ...rest });
29
+ });
30
+ /** The 1 × 18px divider between groups of controls (`vertical: false`: a full-width 1px rule between rows). */
31
+ export function ChromeDivider({ className, vertical = true }) {
32
+ return _jsx("div", { "aria-hidden": "true", className: cn(vertical ? 'mx-0.5 h-[18px] w-px' : 'my-1 h-px w-full', 'shrink-0 bg-chrome-line', className) });
33
+ }
34
+ /** The props that put `mark` on an element. */
35
+ const marked = (mark) => (mark ? { [mark]: '' } : {});
36
+ /** A dark tooltip; the shortcut shows as a key chip. */
37
+ export function Tip({ label, shortcut, side = 'bottom', children, disabled, }) {
38
+ return (_jsxs(BaseTooltip.Root, { disabled: disabled, children: [_jsx(BaseTooltip.Trigger, { render: children }), _jsx(BaseTooltip.Portal, { children: _jsx(BaseTooltip.Positioner, { side: side, sideOffset: 8, className: "z-[1000]", children: _jsxs(BaseTooltip.Popup, { onMouseDown: keepFocusOnTipPress, className: "flex max-w-80 items-center gap-1.5 rounded-[6px] bg-tip px-2 py-[5px] text-[13px] leading-[18px] text-tip-fg shadow-[0_1px_2px_rgb(11_11_11/0.06),0_2px_8px_rgb(11_11_11/0.08)] transition-opacity data-[ending-style]:opacity-0 data-[starting-style]:opacity-0", children: [_jsx("span", { children: label }), shortcut ? (_jsxs(_Fragment, { children: [_jsx("kbd", { "aria-hidden": "true", className: "rounded-[4px] bg-white/15 px-1 font-sans text-[12px] leading-4 text-tip-fg/80", children: shortcut }), _jsx("span", { className: "sr-only", children: spokenShortcut(shortcut, onApplePlatform()) })] })) : null] }) }) })] }));
39
+ }
40
+ /** Shares hover delays between neighbouring tooltips. */
41
+ export function TipGroup({ children }) {
42
+ return (_jsx(BaseTooltip.Provider, { delay: 400, closeDelay: 0, children: children }));
43
+ }
44
+ const HEIGHTS = { md: 'h-7', lg: 'h-8', xl: 'h-9' };
45
+ const WIDTHS = { md: 'w-7', lg: 'w-8', xl: 'w-9' };
46
+ /** A ghost control: 8px radius, 14px text, blue-soft when pressed. */
47
+ export const ChromeButton = forwardRef(function ChromeButton({ pressed, square, size = 'md', className, type = 'button', ...rest }, ref) {
48
+ return (_jsx("button", { ref: ref, type: type, "aria-pressed": ariaPressed(pressed, rest['aria-haspopup']), className: cn('inline-flex shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap rounded-[8px] text-[14px] font-control leading-5 text-chrome-fg outline-none transition-colors duration-100 ease-out', 'hover:bg-chrome-hover focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-chrome-focus', 'disabled:pointer-events-none disabled:opacity-40', HEIGHTS[size], square ? WIDTHS[size] : 'px-[9px]', pressed && 'bg-chrome-pressed text-chrome-pressed-fg hover:bg-chrome-pressed', className), ...rest }));
49
+ });
50
+ /** A {@link ChromeButton} with a tooltip that still shows while it is disabled. */
51
+ export const TipButton = forwardRef(function TipButton({ tip, shortcut, side, disabled, ...rest }, ref) {
52
+ const button = _jsx(ChromeButton, { ref: ref, disabled: disabled, ...rest });
53
+ // A disabled button gets no pointer events, so the tooltip hangs on a wrapper.
54
+ return (_jsx(Tip, { label: tip, shortcut: shortcut, side: side, children: disabled ? _jsx("span", { className: "inline-flex", children: button }) : button }));
55
+ });
56
+ /** A square, icon-only control with a tooltip (36px by default; its icon drawn at 18px). */
57
+ export const ToolButton = forwardRef(function ToolButton({ label, tip, icon, shortcut, tipSide = 'top', size = 'xl', className, ...rest }, ref) {
58
+ return (_jsx(Tip, { label: tip ?? label, shortcut: shortcut, side: tipSide, children: _jsx(ChromeButton, { ref: ref, square: true, size: size, "aria-label": label, className: cn('[&_svg]:size-[18px] [&_svg]:shrink-0', className), ...rest, children: icon }) }));
59
+ });
60
+ /* ---------------------------------- menus --------------------------------- */
61
+ /** Classes of a chrome menu's popup. */
62
+ export const POPUP = 'min-w-[128px] max-w-[320px] rounded-[14px] bg-chrome p-1.5 text-[14px] leading-5 font-control text-chrome-fg shadow-chrome-popup outline-none origin-[var(--transform-origin)] transition-[opacity,transform] duration-100 data-[starting-style]:scale-95 data-[starting-style]:opacity-0 data-[ending-style]:opacity-0';
63
+ const ITEM = 'flex h-7 cursor-default select-none items-center gap-2 rounded-[8px] px-2.5 outline-none data-[highlighted]:bg-chrome-hover data-[popup-open]:bg-chrome-hover data-[disabled]:opacity-40';
64
+ /** A chrome menu. `trigger` is rendered as the menu's trigger. */
65
+ export function ChromeMenu({ trigger, children, side = 'bottom', align = 'start', className, tip, open, onOpenChange, sideOffset = 6, mark, popupBase = POPUP, }) {
66
+ const triggerElement = _jsx(BaseMenu.Trigger, { render: trigger });
67
+ const { tree, popupProps } = useMenuShortcutPopup();
68
+ return (_jsxs(BaseMenu.Root, { open: open, onOpenChange: onOpenChange ? (next) => onOpenChange(next) : undefined, children: [tip ? (_jsx(Tip, { label: tip.label, shortcut: tip.shortcut, side: tip.side ?? (side === 'top' ? 'top' : 'bottom'), children: triggerElement })) : (triggerElement), _jsx(BaseMenu.Portal, { children: _jsx(BaseMenu.Positioner, { side: side, align: align, sideOffset: sideOffset, className: "z-[1000]", children: _jsx(BaseMenu.Popup, { ...marked(mark), ...popupProps, className: cn(popupBase, className), style: menuFit(className), children: _jsx(MenuTreeProvider, { value: tree, children: children }) }) }) })] }));
69
+ }
70
+ /** One menu row. A row that closes the menu keeps the rest of a double click from reaching what the menu uncovers. */
71
+ export function ChromeMenuItem({ children, onSelect, shortcut, keys, checked, disabled, danger, icon, title, description, closeOnClick }) {
72
+ const chord = menuChordParts(keys);
73
+ const wraps = checked !== undefined && description === undefined;
74
+ const cell = wraps ? 'flex h-5 w-4 shrink-0 items-center justify-center' : 'flex size-4 shrink-0 items-center justify-center';
75
+ return (_jsxs(BaseMenu.Item, { className: cn(ITEM, description !== undefined && 'h-auto min-h-7 items-start py-1.5', wraps && 'h-auto min-h-7 items-start py-1', danger && 'text-danger data-[highlighted]:bg-danger data-[highlighted]:text-white'), disabled: disabled, onClick: (event) => {
76
+ if (closeOnClick !== false)
77
+ swallowFollowUpClicks(event.nativeEvent);
78
+ onSelect?.();
79
+ }, closeOnClick: closeOnClick, title: title, ...chord?.rowProps, children: [checked !== undefined ? _jsx("span", { className: cell, children: checked ? _jsx(Check, { className: "size-4 text-chrome-accent", strokeWidth: 2.25 }) : null }) : null, icon ? (_jsx("span", { "data-chrome-icon": "", className: cn(cell, 'text-chrome-muted'), children: icon })) : null, description !== undefined ? (_jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [_jsx("span", { className: "truncate", children: children }), _jsx("span", { className: "truncate text-[12px] leading-4 text-chrome-muted", children: description })] })) : (_jsx("span", { className: cn('min-w-0 flex-1', wraps ? 'line-clamp-2 break-words' : 'truncate'), children: children })), chord ? (_jsxs("span", { className: "ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted", children: [_jsx("span", { "aria-hidden": "true", children: chord.label }), _jsx("span", { className: "sr-only", children: chord.spoken })] })) : shortcut ? (_jsx("span", { className: "ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted", children: shortcut })) : null] }));
80
+ }
81
+ /** A menu row that turns a setting on or off; announced as a checkbox and keeps the menu open. */
82
+ export function ChromeMenuCheckboxItem({ children, checked, onCheckedChange, disabled, title }) {
83
+ return (_jsxs(BaseMenu.CheckboxItem, { className: cn(ITEM, 'h-auto min-h-7 items-start py-1'), checked: checked, onCheckedChange: (next) => onCheckedChange(next), closeOnClick: false, disabled: disabled, title: title, children: [_jsx("span", { className: "flex h-5 w-4 shrink-0 items-center justify-center", children: checked ? _jsx(Check, { className: "size-4 text-chrome-accent", strokeWidth: 2.25 }) : null }), _jsx("span", { className: "line-clamp-2 min-w-0 flex-1 break-words", children: children })] }));
84
+ }
85
+ /** A submenu row and its popup. */
86
+ export function ChromeSubmenu({ label, icon, children, disabled, className, mark, popupBase = POPUP, }) {
87
+ const { popupProps } = useMenuShortcutPopup();
88
+ return (_jsxs(BaseMenu.SubmenuRoot, { children: [_jsxs(BaseMenu.SubmenuTrigger, { className: ITEM, disabled: disabled, children: [icon ? _jsx("span", { "data-chrome-icon": "", className: "flex size-4 shrink-0 items-center justify-center text-chrome-muted", children: icon }) : null, _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), _jsx(ChevronRight, { className: "size-4 shrink-0 text-chrome-muted", strokeWidth: 1.5 })] }), _jsx(BaseMenu.Portal, { children: _jsx(BaseMenu.Positioner, { sideOffset: 4, className: "z-[1000]", children: _jsx(BaseMenu.Popup, { ...marked(mark), ...popupProps, className: cn(popupBase, className), style: menuFit(className), children: children }) }) })] }));
89
+ }
90
+ /** A menu separator. */
91
+ export function ChromeMenuSeparator() {
92
+ return _jsx(BaseMenu.Separator, { className: "mx-2.5 my-1 h-px bg-chrome-line" });
93
+ }
94
+ /** A muted group label inside a menu. */
95
+ export function ChromeMenuLabel({ children }) {
96
+ return _jsx("div", { className: "px-2.5 py-1 text-[13px] font-medium text-chrome-muted", children: children });
97
+ }
98
+ /** True for a field whose typing is a search (a filter, not an edit worth keeping). */
99
+ function isSearchField(target) {
100
+ if (!(target instanceof HTMLElement))
101
+ return true;
102
+ if (!target.matches('input, textarea, [contenteditable="true"]'))
103
+ return true;
104
+ return target.matches('[type="search"], [role="searchbox"], [role="combobox"]');
105
+ }
106
+ /** A floating chrome panel anchored to a trigger (or to `anchor`). A press outside that closes it does not double-click what is under it. */
107
+ export function ChromePopover({ trigger, children, side = 'top', align = 'center', open, onOpenChange, className, label, anchor, gap = 8, initialFocus = true, mark, popupBase = POPUP, style, holdWhileTyped = false, }) {
108
+ const typed = useRef(false);
109
+ const change = (next, details) => {
110
+ if (!next && details.reason === 'outside-press') {
111
+ if (holdWhileTyped && typed.current) {
112
+ details.cancel();
113
+ return;
114
+ }
115
+ if (details.event instanceof MouseEvent)
116
+ swallowFollowUpClicks(details.event);
117
+ }
118
+ onOpenChange?.(next, details);
119
+ };
120
+ return (_jsxs(BasePopover.Root, { open: open, onOpenChange: change, onOpenChangeComplete: (done) => {
121
+ if (!done)
122
+ typed.current = false;
123
+ }, children: [_jsx(BasePopover.Trigger, { render: trigger }), _jsx(BasePopover.Portal, { children: _jsx(BasePopover.Positioner, { side: side, align: align, sideOffset: gap, anchor: anchor ?? undefined, className: "z-[1000]", children: _jsx(BasePopover.Popup, { ...marked(mark), "aria-label": label, initialFocus: typeof initialFocus === 'function' ? (openedBy) => initialFocus(openedBy) ?? true : initialFocus ? undefined : false, className: cn(popupBase, className), style: style, onInput: (event) => {
124
+ if (!isSearchField(event.target))
125
+ typed.current = true;
126
+ }, children: children }) }) })] }));
127
+ }
128
+ /** A row of round color swatches (radio semantics); the current one is ringed in the chrome accent. */
129
+ export function SwatchRow({ label, swatches, current, onPick, size = 20, className, }) {
130
+ return (_jsx("div", { role: "radiogroup", "aria-label": label, className: cn('flex items-center gap-1', className), children: swatches.map((swatch) => {
131
+ const on = swatch.name === current;
132
+ return (_jsx(Tip, { label: swatch.label, side: "top", children: _jsx("button", { type: "button", role: "radio", "aria-checked": on, "aria-label": swatch.label, onClick: () => onPick(swatch.name), className: "grid shrink-0 place-items-center rounded-full outline-none transition-shadow focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-chrome-focus", style: { width: size + 8, height: size + 8 }, children: _jsx("span", { className: cn('block rounded-full ring-1 ring-inset ring-black/10 dark:ring-white/15', on && 'ring-2 ring-chrome-accent ring-offset-2 ring-offset-chrome'), style: { width: size, height: size, background: swatch.value } }) }) }, swatch.name));
133
+ }) }));
134
+ }
135
+ /**
136
+ * Whether the Shell framing the page draws `draw` (its save state, its export formats): the page then hides its own
137
+ * copy, so there is one of each. False outside a Shell and for Shells older than `draws`.
138
+ */
139
+ export function useShellDraw(shell, draw) {
140
+ const [draws, setDraws] = useState(() => shell?.draws.has(draw) ?? false);
141
+ useEffect(() => {
142
+ if (!shell)
143
+ return undefined;
144
+ setDraws(shell.draws.has(draw));
145
+ return shell.onHello((next) => setDraws(next.has(draw)));
146
+ }, [shell, draw]);
147
+ return draws;
148
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Writing the system clipboard from an editor. Some browsers keep the
3
+ * clipboard from framed pages whatever the frame's `allow` says; there the
4
+ * Open Artifacts Shell framing the editor writes instead (it may, right after
5
+ * a press in the frame). Pure (no DOM until called).
6
+ */
7
+ import type { ShellConnection } from '@openartifactsai/runtime';
8
+ /** The browser refused the clipboard (rather than failing on the content). */
9
+ export declare function clipboardRefused(error: unknown): boolean;
10
+ /** Formats can be copied: by the browser, or by the Shell framing the page. */
11
+ export declare function canWriteClipboard(shell?: ShellConnection | null): boolean;
12
+ /**
13
+ * Writes one clipboard item. Call it on the person's press without awaiting
14
+ * anything first (a format may still be a promise, such as an image being
15
+ * drawn). Where the browser refuses this page, the Shell writes it.
16
+ */
17
+ export declare function writeClipboard(items: Record<string, Blob | PromiseLike<Blob>>, shell?: ShellConnection | null): Promise<void>;
18
+ /** Writes text to the clipboard, through the Shell where the browser refuses this page. */
19
+ export declare function writeClipboardText(text: string, shell?: ShellConnection | null): Promise<void>;