@open-artifact/editor-kit 0.10.0 → 0.11.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.10.0",
3
+ "version": "0.11.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.10.0",
26
- "@open-artifact/runtime": "0.10.0",
27
- "@open-artifact/ui": "0.10.0",
25
+ "@open-artifact/design-system-core": "0.11.0",
26
+ "@open-artifact/runtime": "0.11.0",
27
+ "@open-artifact/ui": "0.11.0",
28
28
  "clsx": "^2.1.1",
29
29
  "lucide-react": "^1.65.0",
30
30
  "zustand": "^5.0.10",
package/src/chrome.d.ts CHANGED
@@ -15,6 +15,7 @@
15
15
  * `shadow-chrome`, `bg-tip`…); the focus ring is `outline-chrome-focus`, so
16
16
  * each editor picks its own focus color.
17
17
  */
18
+ import { Popover as BasePopover } from '@base-ui/react/popover';
18
19
  import { type ButtonHTMLAttributes, type CSSProperties, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
19
20
  import type { ChromeDraw, ShellConnection } from '@open-artifact/runtime';
20
21
  /** A floating chrome card. */
@@ -110,7 +111,7 @@ export interface ChromeMenuItemProps {
110
111
  icon?: ReactNode;
111
112
  title?: string;
112
113
  }
113
- /** One menu row. */
114
+ /** One menu row. A row that closes the menu keeps the rest of a double click from reaching what the menu uncovers. */
114
115
  export declare function ChromeMenuItem({ children, onSelect, shortcut, checked, disabled, danger, icon, title, description, closeOnClick }: ChromeMenuItemProps): ReactNode;
115
116
  /** A submenu row and its popup. */
116
117
  export declare function ChromeSubmenu({ label, icon, children, disabled, className, mark, popupBase, }: {
@@ -138,7 +139,7 @@ export interface ChromePopoverProps {
138
139
  side?: ChromeSide;
139
140
  align?: 'start' | 'center' | 'end';
140
141
  open?: boolean;
141
- onOpenChange?: (open: boolean) => void;
142
+ onOpenChange?: (open: boolean, details: ChromePopoverChange) => void;
142
143
  className?: string;
143
144
  /** Accessible name of the popup. */
144
145
  label?: string;
@@ -153,9 +154,17 @@ export interface ChromePopoverProps {
153
154
  /** Popup classes in place of {@link POPUP}. */
154
155
  popupBase?: string;
155
156
  style?: CSSProperties;
157
+ /**
158
+ * Once something has been typed into a field of the popup (other than a
159
+ * search field), a press outside no longer closes it: Escape, or the
160
+ * popup's own buttons, do.
161
+ */
162
+ holdWhileTyped?: boolean;
156
163
  }
157
- /** A floating chrome panel anchored to a trigger (or to `anchor`). */
158
- export declare function ChromePopover({ trigger, children, side, align, open, onOpenChange, className, label, anchor, gap, initialFocus, mark, popupBase, style, }: ChromePopoverProps): ReactNode;
164
+ /** Why a {@link ChromePopover} opens or closes; `cancel()` keeps it as it is. */
165
+ export type ChromePopoverChange = BasePopover.Root.ChangeEventDetails;
166
+ /** 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. */
167
+ export declare function ChromePopover({ trigger, children, side, align, open, onOpenChange, className, label, anchor, gap, initialFocus, mark, popupBase, style, holdWhileTyped, }: ChromePopoverProps): ReactNode;
159
168
  /** One color choice of a {@link SwatchRow}. */
160
169
  export interface Swatch {
161
170
  /** The value stored (a palette name or `#rrggbb`). */
package/src/chrome.js CHANGED
@@ -20,8 +20,8 @@ import { Menu as BaseMenu } from '@base-ui/react/menu';
20
20
  import { Popover as BasePopover } from '@base-ui/react/popover';
21
21
  import { Tooltip as BaseTooltip } from '@base-ui/react/tooltip';
22
22
  import { Check, ChevronRight } from 'lucide-react';
23
- import { forwardRef, useEffect, useState } from 'react';
24
- import { cn } from '@open-artifact/ui';
23
+ import { forwardRef, useEffect, useRef, useState } from 'react';
24
+ import { cn, swallowFollowUpClicks } from '@open-artifact/ui';
25
25
  import { menuFit } from "./menu-fit.js";
26
26
  /** A floating chrome card. */
27
27
  export const Card = forwardRef(function Card({ className, ...rest }, ref) {
@@ -66,9 +66,13 @@ export function ChromeMenu({ trigger, children, side = 'bottom', align = 'start'
66
66
  const triggerElement = _jsx(BaseMenu.Trigger, { render: trigger });
67
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 }) }) })] }));
68
68
  }
69
- /** One menu row. */
69
+ /** One menu row. A row that closes the menu keeps the rest of a double click from reaching what the menu uncovers. */
70
70
  export function ChromeMenuItem({ children, onSelect, shortcut, checked, disabled, danger, icon, title, description, closeOnClick }) {
71
- return (_jsxs(BaseMenu.Item, { className: cn(ITEM, description !== undefined && 'h-auto min-h-7 items-start py-1.5', danger && 'text-danger data-[highlighted]:bg-danger data-[highlighted]:text-white'), disabled: disabled, onClick: onSelect, closeOnClick: closeOnClick, title: title, children: [checked !== undefined ? (_jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: checked ? _jsx(Check, { className: "size-4 text-chrome-accent", strokeWidth: 2.25 }) : null })) : null, icon ? _jsx("span", { "data-chrome-icon": "", className: "flex size-4 shrink-0 items-center justify-center 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: "min-w-0 flex-1 truncate", children: children })), shortcut ? _jsx("span", { className: "ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted", children: shortcut }) : null] }));
71
+ return (_jsxs(BaseMenu.Item, { className: cn(ITEM, description !== undefined && 'h-auto min-h-7 items-start py-1.5', danger && 'text-danger data-[highlighted]:bg-danger data-[highlighted]:text-white'), disabled: disabled, onClick: (event) => {
72
+ if (closeOnClick !== false)
73
+ swallowFollowUpClicks(event.nativeEvent);
74
+ onSelect?.();
75
+ }, closeOnClick: closeOnClick, title: title, children: [checked !== undefined ? (_jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: checked ? _jsx(Check, { className: "size-4 text-chrome-accent", strokeWidth: 2.25 }) : null })) : null, icon ? _jsx("span", { "data-chrome-icon": "", className: "flex size-4 shrink-0 items-center justify-center 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: "min-w-0 flex-1 truncate", children: children })), shortcut ? _jsx("span", { className: "ml-6 max-w-40 shrink-0 truncate text-[13px] text-chrome-muted", children: shortcut }) : null] }));
72
76
  }
73
77
  /** A submenu row and its popup. */
74
78
  export function ChromeSubmenu({ label, icon, children, disabled, className, mark, popupBase = POPUP, }) {
@@ -82,9 +86,35 @@ export function ChromeMenuSeparator() {
82
86
  export function ChromeMenuLabel({ children }) {
83
87
  return _jsx("div", { className: "px-2.5 py-1 text-[13px] font-medium text-chrome-muted", children: children });
84
88
  }
85
- /** A floating chrome panel anchored to a trigger (or to `anchor`). */
86
- export function ChromePopover({ trigger, children, side = 'top', align = 'center', open, onOpenChange, className, label, anchor, gap = 8, initialFocus = true, mark, popupBase = POPUP, style, }) {
87
- return (_jsxs(BasePopover.Root, { open: open, onOpenChange: onOpenChange ? (next) => onOpenChange(next) : undefined, 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: initialFocus ? undefined : false, className: cn(popupBase, className), style: style, children: children }) }) })] }));
89
+ /** True for a field whose typing is a search (a filter, not an edit worth keeping). */
90
+ function isSearchField(target) {
91
+ if (!(target instanceof HTMLElement))
92
+ return true;
93
+ if (!target.matches('input, textarea, [contenteditable="true"]'))
94
+ return true;
95
+ return target.matches('[type="search"], [role="searchbox"], [role="combobox"]');
96
+ }
97
+ /** 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. */
98
+ export function ChromePopover({ trigger, children, side = 'top', align = 'center', open, onOpenChange, className, label, anchor, gap = 8, initialFocus = true, mark, popupBase = POPUP, style, holdWhileTyped = false, }) {
99
+ const typed = useRef(false);
100
+ const change = (next, details) => {
101
+ if (!next && details.reason === 'outside-press') {
102
+ if (holdWhileTyped && typed.current) {
103
+ details.cancel();
104
+ return;
105
+ }
106
+ if (details.event instanceof MouseEvent)
107
+ swallowFollowUpClicks(details.event);
108
+ }
109
+ onOpenChange?.(next, details);
110
+ };
111
+ return (_jsxs(BasePopover.Root, { open: open, onOpenChange: change, onOpenChangeComplete: (done) => {
112
+ if (!done)
113
+ typed.current = false;
114
+ }, 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: initialFocus ? undefined : false, className: cn(popupBase, className), style: style, onInput: (event) => {
115
+ if (!isSearchField(event.target))
116
+ typed.current = true;
117
+ }, children: children }) }) })] }));
88
118
  }
89
119
  /** A row of round color swatches (radio semantics); the current one is ringed in the chrome accent. */
90
120
  export function SwatchRow({ label, swatches, current, onPick, size = 20, className, }) {