@open-artifact/editor-kit 0.9.1 → 0.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-artifact/editor-kit",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "What every artifact editor shares: collaboration (comments, presence, history), roles and host session, Shell chrome reports, find, recovery stashes, line merge, announcements, chrome primitives and design-system loading.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -22,9 +22,9 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@base-ui/react": "^1.8.0",
25
- "@open-artifact/design-system-core": "0.9.1",
26
- "@open-artifact/runtime": "0.9.1",
27
- "@open-artifact/ui": "0.9.1",
25
+ "@open-artifact/design-system-core": "0.10.0",
26
+ "@open-artifact/runtime": "0.10.0",
27
+ "@open-artifact/ui": "0.10.0",
28
28
  "clsx": "^2.1.1",
29
29
  "lucide-react": "^1.65.0",
30
30
  "zustand": "^5.0.10",
package/src/chrome.js CHANGED
@@ -22,6 +22,7 @@ import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
22
22
  import { Check, ChevronRight } from 'lucide-react';
23
23
  import { forwardRef, useEffect, useState } from 'react';
24
24
  import { cn } from '@open-artifact/ui';
25
+ import { menuFit } from "./menu-fit.js";
25
26
  /** A floating chrome card. */
26
27
  export const Card = forwardRef(function Card({ className, ...rest }, ref) {
27
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 });
@@ -63,7 +64,7 @@ const ITEM = 'flex h-7 cursor-default select-none items-center gap-2 rounded-[8p
63
64
  /** A chrome menu. `trigger` is rendered as the menu's trigger. */
64
65
  export function ChromeMenu({ trigger, children, side = 'bottom', align = 'start', className, tip, open, onOpenChange, sideOffset = 6, mark, popupBase = POPUP, }) {
65
66
  const triggerElement = _jsx(BaseMenu.Trigger, { render: trigger });
66
- 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), className: cn(popupBase, className), children: children }) }) })] }));
67
+ 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), className: cn(popupBase, className), style: menuFit(className), children: children }) }) })] }));
67
68
  }
68
69
  /** One menu row. */
69
70
  export function ChromeMenuItem({ children, onSelect, shortcut, checked, disabled, danger, icon, title, description, closeOnClick }) {
@@ -71,7 +72,7 @@ export function ChromeMenuItem({ children, onSelect, shortcut, checked, disabled
71
72
  }
72
73
  /** A submenu row and its popup. */
73
74
  export function ChromeSubmenu({ label, icon, children, disabled, className, mark, popupBase = POPUP, }) {
74
- 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), className: cn(popupBase, className), children: children }) }) })] }));
75
+ 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), className: cn(popupBase, className), style: menuFit(className), children: children }) }) })] }));
75
76
  }
76
77
  /** A menu separator. */
77
78
  export function ChromeMenuSeparator() {
@@ -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 Artifact 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 '@open-artifact/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>;
@@ -0,0 +1,48 @@
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 Artifact Shell framing the editor writes instead (it may, right after
5
+ * a press in the frame). Pure (no DOM until called).
6
+ */
7
+ /** The browser itself writes clipboard formats (images, HTML) here. */
8
+ const browserWrites = () => typeof ClipboardItem !== 'undefined' && Boolean(globalThis.navigator?.clipboard?.write);
9
+ /** The browser refused the clipboard (rather than failing on the content). */
10
+ export function clipboardRefused(error) {
11
+ return typeof error === 'object' && error !== null && error.name === 'NotAllowedError';
12
+ }
13
+ /** Formats can be copied: by the browser, or by the Shell framing the page. */
14
+ export function canWriteClipboard(shell) {
15
+ return browserWrites() || Boolean(shell?.writesClipboard);
16
+ }
17
+ /**
18
+ * Writes one clipboard item. Call it on the person's press without awaiting
19
+ * anything first (a format may still be a promise, such as an image being
20
+ * drawn). Where the browser refuses this page, the Shell writes it.
21
+ */
22
+ export async function writeClipboard(items, shell) {
23
+ if (browserWrites()) {
24
+ try {
25
+ await navigator.clipboard.write([new ClipboardItem(items)]);
26
+ return;
27
+ }
28
+ catch (error) {
29
+ if (!shell?.writesClipboard || !clipboardRefused(error))
30
+ throw error;
31
+ }
32
+ }
33
+ else if (!shell?.writesClipboard) {
34
+ throw new Error('This browser cannot copy to the clipboard.');
35
+ }
36
+ await shell.writeClipboard(items);
37
+ }
38
+ /** Writes text to the clipboard, through the Shell where the browser refuses this page. */
39
+ export async function writeClipboardText(text, shell) {
40
+ try {
41
+ await navigator.clipboard.writeText(text);
42
+ }
43
+ catch (error) {
44
+ if (!shell?.writesClipboard || !clipboardRefused(error))
45
+ throw error;
46
+ await shell.writeClipboard({ 'text/plain': new Blob([text], { type: 'text/plain' }) });
47
+ }
48
+ }
@@ -267,9 +267,31 @@ export function createComments(adapter) {
267
267
  }
268
268
  },
269
269
  async sendAllToAgent() {
270
+ if (!capability || !canSendToAgent())
271
+ return;
270
272
  const open = store.getState().threads.filter((t) => controller.canSendThread(t));
271
- for (const thread of open)
272
- await controller.sendToAgent(thread.id);
273
+ if (!open.length)
274
+ return;
275
+ // All at once: the host merges what reaches it within a short window into one message, so the agent gets
276
+ // every thread in one turn. One after another, each would wait out the window and arrive (or queue) alone.
277
+ if (adapter.sendToAgent) {
278
+ await Promise.all(open.map((thread) => adapter.sendToAgent(thread, anchorOf(thread))));
279
+ return;
280
+ }
281
+ const cap = capability;
282
+ const results = await Promise.allSettled(open.map((thread) => cap.sendToAgent(thread.id)));
283
+ let sent = 0;
284
+ for (const result of results) {
285
+ if (result.status === 'fulfilled') {
286
+ put(result.value);
287
+ sent++;
288
+ }
289
+ }
290
+ if (sent)
291
+ notify(sentNotice(adapter.agentName?.() || 'the agent', adapter.agentWakesIdle?.()));
292
+ const failure = results.find((result) => result.status === 'rejected');
293
+ if (failure)
294
+ failed(failure.reason);
273
295
  },
274
296
  canSendThread(thread) {
275
297
  if (thread.status !== 'open')
package/src/index.d.ts CHANGED
@@ -21,5 +21,6 @@ export * from './session.ts';
21
21
  export * from './shell.ts';
22
22
  export * from './agent.ts';
23
23
  export * from './downloads.ts';
24
+ export * from './clipboard.ts';
24
25
  export * from './find.ts';
25
26
  export * from './design-systems.ts';
package/src/index.js CHANGED
@@ -21,5 +21,6 @@ export * from "./session.js";
21
21
  export * from "./shell.js";
22
22
  export * from "./agent.js";
23
23
  export * from "./downloads.js";
24
+ export * from "./clipboard.js";
24
25
  export * from "./find.js";
25
26
  export * from "./design-systems.js";
@@ -0,0 +1,12 @@
1
+ /** The inline style {@link menuFit} gives a popup. */
2
+ export interface MenuFitStyle {
3
+ maxHeight: string;
4
+ overflowY: 'auto';
5
+ }
6
+ /**
7
+ * Keeps a menu inside a short window: a popup with no height limit of its
8
+ * own scrolls, headings and all, within the height Base UI measured free
9
+ * next to its trigger (`--available-height`). A popup whose classes set a
10
+ * `max-h-*` keeps that limit.
11
+ */
12
+ export declare function menuFit(className?: string): MenuFitStyle | undefined;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Keeps a menu inside a short window: a popup with no height limit of its
3
+ * own scrolls, headings and all, within the height Base UI measured free
4
+ * next to its trigger (`--available-height`). A popup whose classes set a
5
+ * `max-h-*` keeps that limit.
6
+ */
7
+ export function menuFit(className) {
8
+ return className && /(^|\s)max-h-/.test(className) ? undefined : { maxHeight: 'var(--available-height)', overflowY: 'auto' };
9
+ }
package/src/react.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './collab/HistoryViews.tsx';
11
11
  export * from './collab/PresenceViews.tsx';
12
12
  export * from './Announcer.tsx';
13
13
  export * from './chrome.tsx';
14
+ export { menuFit } from './menu-fit.ts';
14
15
  export * from './FindBar.tsx';
15
16
  export * from './PanelEdge.tsx';
16
17
  /** Key labels for the chrome's shortcut chips (also in the pure entry). */
package/src/react.js CHANGED
@@ -11,6 +11,7 @@ export * from "./collab/HistoryViews.js";
11
11
  export * from "./collab/PresenceViews.js";
12
12
  export * from "./Announcer.js";
13
13
  export * from "./chrome.js";
14
+ export { menuFit } from "./menu-fit.js";
14
15
  export * from "./FindBar.js";
15
16
  export * from "./PanelEdge.js";
16
17
  /** Key labels for the chrome's shortcut chips (also in the pure entry). */
package/src/shell.d.ts CHANGED
@@ -32,7 +32,11 @@ export interface ShellDrawsState {
32
32
  /** A Shell frames this page. */
33
33
  framed: boolean;
34
34
  }
35
- /** A handler of Shell commands; may answer an `exports` request with items. */
35
+ /**
36
+ * A handler of Shell commands; may answer an `exports` request with items.
37
+ * Every command reaches every handler, `follow` too (sent where the report
38
+ * has `following`, with a key from its `peers` or `null` to stop).
39
+ */
36
40
  export type ShellCommandHandler = (command: ChromeCommand) => ChromeExportItem[] | void;
37
41
  /** A bridge made by {@link createShellBridge}. */
38
42
  export interface ShellBridge {