@open-artifact/editor-kit 0.2.1 → 0.9.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 +4 -4
- package/src/PanelEdge.d.ts +20 -0
- package/src/PanelEdge.js +74 -0
- package/src/chrome.d.ts +3 -2
- package/src/chrome.js +2 -2
- package/src/collab/CommentViews.d.ts +3 -1
- package/src/collab/CommentViews.js +2 -2
- package/src/collab/cds/layer.d.ts +1 -1
- package/src/collab/cds/layer.js +3 -3
- package/src/collab/collab.d.ts +2 -0
- package/src/collab/collab.js +2 -0
- package/src/collab/comments.d.ts +2 -0
- package/src/collab/comments.js +3 -2
- package/src/react.d.ts +1 -0
- package/src/react.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-artifact/editor-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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.
|
|
26
|
-
"@open-artifact/runtime": "0.
|
|
27
|
-
"@open-artifact/ui": "0.
|
|
25
|
+
"@open-artifact/design-system-core": "0.9.0",
|
|
26
|
+
"@open-artifact/runtime": "0.9.0",
|
|
27
|
+
"@open-artifact/ui": "0.9.0",
|
|
28
28
|
"clsx": "^2.1.1",
|
|
29
29
|
"lucide-react": "^1.65.0",
|
|
30
30
|
"zustand": "^5.0.10",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface PanelEdgeProps {
|
|
3
|
+
label: string;
|
|
4
|
+
width: number;
|
|
5
|
+
min: number;
|
|
6
|
+
max: number;
|
|
7
|
+
/** Which of the panel's sides the edge is on. */
|
|
8
|
+
side: 'left' | 'right';
|
|
9
|
+
onResize(width: number): void;
|
|
10
|
+
onReset?(): void;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function PanelEdge({ label, width, min, max, side, onResize, onReset, className }: PanelEdgeProps): ReactNode;
|
|
14
|
+
export interface PanelWidth {
|
|
15
|
+
width: number;
|
|
16
|
+
resize(width: number): void;
|
|
17
|
+
reset(): void;
|
|
18
|
+
}
|
|
19
|
+
/** A panel's width between `min` and `max` (and never wider than `cap`, when given), kept in this browser under `key`. */
|
|
20
|
+
export declare function usePanelWidth(key: string, initial: number, min: number, max: number, cap?: number): PanelWidth;
|
package/src/PanelEdge.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A panel's edge that resizes it: drag it, or with it focused press the arrow keys (Shift for bigger steps); a double
|
|
4
|
+
* click puts the panel back to its first width. `usePanelWidth` keeps the width per panel in this browser.
|
|
5
|
+
*/
|
|
6
|
+
import { cn } from '@open-artifact/ui';
|
|
7
|
+
import { useCallback, useRef, useState } from 'react';
|
|
8
|
+
const STEP = 8;
|
|
9
|
+
const BIG_STEP = 32;
|
|
10
|
+
export function PanelEdge({ label, width, min, max, side, onResize, onReset, className }) {
|
|
11
|
+
const start = useRef(null);
|
|
12
|
+
const grow = side === 'left' ? -1 : 1;
|
|
13
|
+
const down = (event) => {
|
|
14
|
+
if (event.button !== 0)
|
|
15
|
+
return;
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
18
|
+
start.current = { x: event.clientX, width };
|
|
19
|
+
};
|
|
20
|
+
const move = (event) => {
|
|
21
|
+
if (!start.current)
|
|
22
|
+
return;
|
|
23
|
+
onResize(start.current.width + (event.clientX - start.current.x) * grow);
|
|
24
|
+
};
|
|
25
|
+
const up = () => {
|
|
26
|
+
start.current = null;
|
|
27
|
+
};
|
|
28
|
+
const key = (event) => {
|
|
29
|
+
if (start.current || event.metaKey || event.ctrlKey || event.altKey)
|
|
30
|
+
return;
|
|
31
|
+
const toward = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
|
|
32
|
+
if (!toward)
|
|
33
|
+
return;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
onResize(width + toward * grow * (event.shiftKey ? BIG_STEP : STEP));
|
|
37
|
+
};
|
|
38
|
+
return (_jsx("div", { role: "separator", "aria-orientation": "vertical", "aria-label": label, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": Math.round(width), tabIndex: 0, className: cn('absolute inset-y-0 z-10 w-2 cursor-col-resize outline-none pointer-coarse:hidden', 'hover:bg-[linear-gradient(to_right,transparent_3px,var(--color-chrome-accent)_3px,var(--color-chrome-accent)_5px,transparent_5px)]', 'focus-visible:bg-[linear-gradient(to_right,transparent_3px,var(--color-chrome-accent)_3px,var(--color-chrome-accent)_5px,transparent_5px)]', side === 'left' ? '-left-1' : '-right-1', className), onPointerDown: down, onPointerMove: move, onPointerUp: up, onPointerCancel: up, onKeyDown: key, onDoubleClick: onReset }));
|
|
39
|
+
}
|
|
40
|
+
function readWidth(key) {
|
|
41
|
+
try {
|
|
42
|
+
const value = Number(localStorage.getItem(key));
|
|
43
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function writeWidth(key, width) {
|
|
50
|
+
try {
|
|
51
|
+
if (width === null)
|
|
52
|
+
localStorage.removeItem(key);
|
|
53
|
+
else
|
|
54
|
+
localStorage.setItem(key, String(Math.round(width)));
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// A browser that keeps nothing still resizes for the visit.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** A panel's width between `min` and `max` (and never wider than `cap`, when given), kept in this browser under `key`. */
|
|
61
|
+
export function usePanelWidth(key, initial, min, max, cap = Infinity) {
|
|
62
|
+
const clamp = useCallback((value) => Math.round(Math.max(min, Math.min(max, cap, value))), [min, max, cap]);
|
|
63
|
+
const [stored, setStored] = useState(() => readWidth(key) ?? initial);
|
|
64
|
+
const resize = useCallback((value) => {
|
|
65
|
+
const next = clamp(value);
|
|
66
|
+
setStored(next);
|
|
67
|
+
writeWidth(key, next);
|
|
68
|
+
}, [clamp, key]);
|
|
69
|
+
const reset = useCallback(() => {
|
|
70
|
+
setStored(initial);
|
|
71
|
+
writeWidth(key, null);
|
|
72
|
+
}, [initial, key]);
|
|
73
|
+
return { width: clamp(stored), resize, reset };
|
|
74
|
+
}
|
package/src/chrome.d.ts
CHANGED
|
@@ -15,7 +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 { type ButtonHTMLAttributes, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
|
|
18
|
+
import { type ButtonHTMLAttributes, type CSSProperties, type HTMLAttributes, type ReactElement, type ReactNode } from 'react';
|
|
19
19
|
import type { ChromeDraw, ShellConnection } from '@open-artifact/runtime';
|
|
20
20
|
/** A floating chrome card. */
|
|
21
21
|
export declare const Card: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLDivElement> & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -152,9 +152,10 @@ export interface ChromePopoverProps {
|
|
|
152
152
|
mark?: ChromeMark;
|
|
153
153
|
/** Popup classes in place of {@link POPUP}. */
|
|
154
154
|
popupBase?: string;
|
|
155
|
+
style?: CSSProperties;
|
|
155
156
|
}
|
|
156
157
|
/** A floating chrome panel anchored to a trigger (or to `anchor`). */
|
|
157
|
-
export declare function ChromePopover({ trigger, children, side, align, open, onOpenChange, className, label, anchor, gap, initialFocus, mark, popupBase, }: ChromePopoverProps): ReactNode;
|
|
158
|
+
export declare function ChromePopover({ trigger, children, side, align, open, onOpenChange, className, label, anchor, gap, initialFocus, mark, popupBase, style, }: ChromePopoverProps): ReactNode;
|
|
158
159
|
/** One color choice of a {@link SwatchRow}. */
|
|
159
160
|
export interface Swatch {
|
|
160
161
|
/** The value stored (a palette name or `#rrggbb`). */
|
package/src/chrome.js
CHANGED
|
@@ -82,8 +82,8 @@ export function ChromeMenuLabel({ children }) {
|
|
|
82
82
|
return _jsx("div", { className: "px-2.5 py-1 text-[13px] font-medium text-chrome-muted", children: children });
|
|
83
83
|
}
|
|
84
84
|
/** A floating chrome panel anchored to a trigger (or to `anchor`). */
|
|
85
|
-
export function ChromePopover({ trigger, children, side = 'top', align = 'center', open, onOpenChange, className, label, anchor, gap = 8, initialFocus = true, mark, popupBase = POPUP, }) {
|
|
86
|
-
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), children: children }) }) })] }));
|
|
85
|
+
export function ChromePopover({ trigger, children, side = 'top', align = 'center', open, onOpenChange, className, label, anchor, gap = 8, initialFocus = true, mark, popupBase = POPUP, style, }) {
|
|
86
|
+
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 }) }) })] }));
|
|
87
87
|
}
|
|
88
88
|
/** A row of round color swatches (radio semantics); the current one is ringed in the chrome accent. */
|
|
89
89
|
export function SwatchRow({ label, swatches, current, onPick, size = 20, className, }) {
|
|
@@ -53,11 +53,13 @@ export interface CommentPopoverProps {
|
|
|
53
53
|
corner?: Point;
|
|
54
54
|
/** The surface it is kept inside (px, from the layer's top-left corner). */
|
|
55
55
|
viewport: Size;
|
|
56
|
+
/** Its width (px; default 330). */
|
|
57
|
+
width?: number;
|
|
56
58
|
onEscape(): void;
|
|
57
59
|
/** A function gets the height the card may take, and the popover keeps to it. */
|
|
58
60
|
children: ReactNode | ((maxHeight: number) => ReactNode);
|
|
59
61
|
}
|
|
60
|
-
export declare function CommentPopover({ pin, corner, viewport, onEscape, children }: CommentPopoverProps): ReactNode;
|
|
62
|
+
export declare function CommentPopover({ pin, corner, viewport, width: wanted, onEscape, children }: CommentPopoverProps): ReactNode;
|
|
61
63
|
export interface CommentPinsProps<A> {
|
|
62
64
|
comments: CommentsController<A>;
|
|
63
65
|
/** The surface's camera (pins re-place when it changes). */
|
|
@@ -202,7 +202,7 @@ function cardMaxHeight(pin, viewport) {
|
|
|
202
202
|
: bottom - clamp(pin.top - 2, top, Math.max(top, bottom - CARD_MIN_ROOM));
|
|
203
203
|
return Math.min(cardCap(viewport.height), Math.max(0, room));
|
|
204
204
|
}
|
|
205
|
-
export function CommentPopover({ pin, corner, viewport, onEscape, children }) {
|
|
205
|
+
export function CommentPopover({ pin, corner, viewport, width: wanted = CARD_WIDTH, onEscape, children }) {
|
|
206
206
|
const ref = useRef(null);
|
|
207
207
|
const [height, setHeight] = useState(0);
|
|
208
208
|
useLayoutEffect(() => {
|
|
@@ -214,7 +214,7 @@ export function CommentPopover({ pin, corner, viewport, onEscape, children }) {
|
|
|
214
214
|
observer.observe(el);
|
|
215
215
|
return () => observer.disconnect();
|
|
216
216
|
}, []);
|
|
217
|
-
const width = Math.max(0, Math.min(
|
|
217
|
+
const width = Math.max(0, Math.min(wanted, viewport.width - 2 * EDGE));
|
|
218
218
|
let left;
|
|
219
219
|
let top;
|
|
220
220
|
let maxHeight;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
16
16
|
export declare const useInLayer: () => boolean;
|
|
17
|
-
/** Dark when the page says so (data-theme, a dark/light class), else when the system is; and the root font scale. */
|
|
17
|
+
/** Dark when the page says so (data-mode, data-theme, a dark/light class), else when the system is; and the root font scale. */
|
|
18
18
|
export declare function usePageTheme(win?: Window): {
|
|
19
19
|
dark: boolean;
|
|
20
20
|
remScale: number;
|
package/src/collab/cds/layer.js
CHANGED
|
@@ -63,12 +63,12 @@ function adoptSheet(shadow) {
|
|
|
63
63
|
style.textContent = COMMENTS_CSS;
|
|
64
64
|
shadow.append(style);
|
|
65
65
|
}
|
|
66
|
-
/** Dark when the page says so (data-theme, a dark/light class), else when the system is; and the root font scale. */
|
|
66
|
+
/** Dark when the page says so (data-mode, data-theme, a dark/light class), else when the system is; and the root font scale. */
|
|
67
67
|
export function usePageTheme(win = window) {
|
|
68
68
|
const read = () => {
|
|
69
69
|
const doc = win.document;
|
|
70
70
|
const html = doc.documentElement;
|
|
71
|
-
const attr = html.getAttribute('data-theme') ?? doc.body?.getAttribute('data-theme');
|
|
71
|
+
const attr = html.getAttribute('data-mode') ?? html.getAttribute('data-theme') ?? doc.body?.getAttribute('data-theme');
|
|
72
72
|
const system = win.matchMedia?.('(prefers-color-scheme: dark)').matches ?? false;
|
|
73
73
|
const dark = attr === 'dark' || html.classList.contains('dark') || (attr !== 'light' && !html.classList.contains('light') && system);
|
|
74
74
|
const rootSize = Number.parseFloat(win.getComputedStyle(html).fontSize) || 16;
|
|
@@ -83,7 +83,7 @@ export function usePageTheme(win = window) {
|
|
|
83
83
|
const media = win.matchMedia?.('(prefers-color-scheme: dark)');
|
|
84
84
|
media?.addEventListener?.('change', update);
|
|
85
85
|
const observer = new MutationObserver(update);
|
|
86
|
-
observer.observe(win.document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'class', 'style'] });
|
|
86
|
+
observer.observe(win.document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-mode', 'class', 'style'] });
|
|
87
87
|
if (win.document.body)
|
|
88
88
|
observer.observe(win.document.body, { attributes: true, attributeFilter: ['data-theme'] });
|
|
89
89
|
return () => {
|
package/src/collab/collab.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface CollabAdapter {
|
|
|
17
17
|
showSurface?(): void;
|
|
18
18
|
/** Starts a thread on what is selected (the Shell's `comment_selection` action). */
|
|
19
19
|
commentOnSelection?(): void;
|
|
20
|
+
/** Route the comment shortcut through the host when it owns the entry point. */
|
|
21
|
+
requestCommentMode?(on: boolean): boolean;
|
|
20
22
|
/** The viewer cannot edit (comment mode then leaves Delete alone). */
|
|
21
23
|
readOnly(): boolean;
|
|
22
24
|
/** The Shell's page button for comments (default `false`: the page draws its own). */
|
package/src/collab/collab.js
CHANGED
|
@@ -107,6 +107,8 @@ export function createCollab({ comments, history, adapter }) {
|
|
|
107
107
|
if (letter === 'c' && !press.meta && !press.alt && !press.shift) {
|
|
108
108
|
if (!comments.canComment() || !adapter.onSurface())
|
|
109
109
|
return false;
|
|
110
|
+
if (adapter.requestCommentMode)
|
|
111
|
+
return adapter.requestCommentMode(!state.on);
|
|
110
112
|
state.setOn(!state.on);
|
|
111
113
|
return true;
|
|
112
114
|
}
|
package/src/collab/comments.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface CommentsAdapter<A> {
|
|
|
67
67
|
sendToAgent?(thread: CommentThread, anchor: A): Promise<boolean>;
|
|
68
68
|
/** Told of threads as the host hands them over: the list, every change and every write. */
|
|
69
69
|
heard?(threads: readonly CommentThread[]): void;
|
|
70
|
+
/** A new thread's card opens once it is saved (default: always); `sent`: it went to the agent too. */
|
|
71
|
+
opensCreated?(sent: boolean): boolean;
|
|
70
72
|
}
|
|
71
73
|
/** The comments store. */
|
|
72
74
|
export interface CommentsState<A> {
|
package/src/collab/comments.js
CHANGED
|
@@ -172,15 +172,16 @@ export function createComments(adapter) {
|
|
|
172
172
|
location: adapter.location?.(anchor) ?? {},
|
|
173
173
|
text: body,
|
|
174
174
|
});
|
|
175
|
+
const sends = Boolean(options?.send) && canSendToAgent();
|
|
175
176
|
store.setState((state) => ({
|
|
176
177
|
threads: state.threads.some((t) => t.id === thread.id) ? state.threads : [...state.threads, thread],
|
|
177
178
|
draft: null,
|
|
178
179
|
draftText: '',
|
|
179
180
|
sendNew: false,
|
|
180
|
-
active: thread.id,
|
|
181
|
+
active: adapter.opensCreated?.(sends) === false ? null : thread.id,
|
|
181
182
|
}));
|
|
182
183
|
adapter.heard?.([thread]);
|
|
183
|
-
if (
|
|
184
|
+
if (sends)
|
|
184
185
|
await controller.sendToAgent(thread.id);
|
|
185
186
|
return true;
|
|
186
187
|
}
|
package/src/react.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export * from './collab/PresenceViews.tsx';
|
|
|
12
12
|
export * from './Announcer.tsx';
|
|
13
13
|
export * from './chrome.tsx';
|
|
14
14
|
export * from './FindBar.tsx';
|
|
15
|
+
export * from './PanelEdge.tsx';
|
|
15
16
|
/** Key labels for the chrome's shortcut chips (also in the pure entry). */
|
|
16
17
|
export { ALT, MOD, SHIFT } from './keys.ts';
|
package/src/react.js
CHANGED
|
@@ -12,5 +12,6 @@ export * from "./collab/PresenceViews.js";
|
|
|
12
12
|
export * from "./Announcer.js";
|
|
13
13
|
export * from "./chrome.js";
|
|
14
14
|
export * from "./FindBar.js";
|
|
15
|
+
export * from "./PanelEdge.js";
|
|
15
16
|
/** Key labels for the chrome's shortcut chips (also in the pure entry). */
|
|
16
17
|
export { ALT, MOD, SHIFT } from "./keys.js";
|