@pixerate/editor-react 0.91.1 → 0.93.1

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 (63) hide show
  1. package/dist/animation-editor/AnimationEditor.d.cts +11 -1
  2. package/dist/animation-editor/AnimationEditor.d.ts +11 -1
  3. package/dist/animation-editor/index.cjs +494 -366
  4. package/dist/animation-editor/index.js +48 -4
  5. package/dist/canvas/AgentPresenceLayer.d.cts +3 -0
  6. package/dist/canvas/AgentPresenceLayer.d.ts +3 -0
  7. package/dist/canvas/index.cjs +1033 -893
  8. package/dist/canvas/index.d.cts +2 -0
  9. package/dist/canvas/index.d.ts +2 -0
  10. package/dist/canvas/index.js +125 -74
  11. package/dist/canvas/useCanvasPlaybackSurface.d.cts +28 -0
  12. package/dist/canvas/useCanvasPlaybackSurface.d.ts +28 -0
  13. package/dist/chart/ChartEditor.d.cts +12 -1
  14. package/dist/chart/ChartEditor.d.ts +12 -1
  15. package/dist/chart/index.cjs +187 -29
  16. package/dist/chart/index.js +74 -10
  17. package/dist/{chunk-SMMO7CZB.js → chunk-6YRSQW2V.js} +84 -2
  18. package/dist/chunk-7I73DW4V.js +43 -0
  19. package/dist/{chunk-GML6BYCN.js → chunk-GECXTPSH.js} +53 -3
  20. package/dist/chunk-IPVWWVSF.js +96 -0
  21. package/dist/hooks/useAgentToolProvider.d.cts +6 -2
  22. package/dist/hooks/useAgentToolProvider.d.ts +6 -2
  23. package/dist/image-editor/ImageEditor.d.cts +10 -0
  24. package/dist/image-editor/ImageEditor.d.ts +10 -0
  25. package/dist/image-editor/index.cjs +1028 -864
  26. package/dist/image-editor/index.js +2 -1
  27. package/dist/index.cjs +2070 -1812
  28. package/dist/index.d.cts +1 -0
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +21 -3
  31. package/dist/paint-editor/PaintEditor.d.cts +12 -1
  32. package/dist/paint-editor/PaintEditor.d.ts +12 -1
  33. package/dist/paint-editor/index.cjs +319 -164
  34. package/dist/paint-editor/index.js +84 -11
  35. package/dist/parameters/ParametersPanel.d.cts +11 -1
  36. package/dist/parameters/ParametersPanel.d.ts +11 -1
  37. package/dist/parameters/index.cjs +190 -41
  38. package/dist/parameters/index.js +23 -4
  39. package/dist/playback/AgentPlaybackContext.d.cts +9 -0
  40. package/dist/playback/AgentPlaybackContext.d.ts +9 -0
  41. package/dist/playback/PresenceLayer.d.cts +28 -0
  42. package/dist/playback/PresenceLayer.d.ts +28 -0
  43. package/dist/playback/index.d.cts +4 -0
  44. package/dist/playback/index.d.ts +4 -0
  45. package/dist/playback/useElementPlaybackSurface.d.cts +19 -0
  46. package/dist/playback/useElementPlaybackSurface.d.ts +19 -0
  47. package/dist/playback/usePlaybackSurface.d.cts +11 -0
  48. package/dist/playback/usePlaybackSurface.d.ts +11 -0
  49. package/dist/spreadsheet/SpreadsheetEditor.d.cts +10 -0
  50. package/dist/spreadsheet/SpreadsheetEditor.d.ts +10 -0
  51. package/dist/spreadsheet/index.cjs +443 -313
  52. package/dist/spreadsheet/index.js +2 -1
  53. package/dist/vector/VectorCanvas.d.cts +11 -1
  54. package/dist/vector/VectorCanvas.d.ts +11 -1
  55. package/dist/vector/index.cjs +946 -826
  56. package/dist/vector/index.js +42 -3
  57. package/dist/video-editor/VideoEditor.d.cts +6 -1
  58. package/dist/video-editor/VideoEditor.d.ts +6 -1
  59. package/dist/video-editor/VideoTimeline.d.cts +11 -1
  60. package/dist/video-editor/VideoTimeline.d.ts +11 -1
  61. package/dist/video-editor/index.cjs +463 -332
  62. package/dist/video-editor/index.js +53 -5
  63. package/package.json +3 -3
@@ -1,3 +1,9 @@
1
+ import {
2
+ PresenceLayer,
3
+ useAgentPlayback,
4
+ usePlaybackSurface
5
+ } from "./chunk-IPVWWVSF.js";
6
+
1
7
  // src/spreadsheet/useSpreadsheetEditor.ts
2
8
  import { useState, useRef, useCallback, useMemo } from "react";
3
9
  import {
@@ -248,7 +254,8 @@ import {
248
254
  numberFormatColorToCss,
249
255
  getConditionalFormatCss as getConditionalFormatCss2,
250
256
  getConditionalFormatIcon,
251
- getDataBarCss
257
+ getDataBarCss,
258
+ parseSpreadsheetPlaybackRef
252
259
  } from "@pixerate/editor/spreadsheet";
253
260
 
254
261
  // src/spreadsheet/SpreadsheetContextMenu.tsx
@@ -1209,11 +1216,53 @@ var SpreadsheetEditor = ({
1209
1216
  onColumnHeaderClick,
1210
1217
  onColumnResize,
1211
1218
  showSheetTabs = false,
1212
- virtualize = "auto"
1219
+ virtualize = "auto",
1220
+ playback,
1221
+ playbackId = "spreadsheet",
1222
+ onPlaybackReveal
1213
1223
  }) => {
1214
1224
  const defaultState = useSpreadsheetEditor();
1215
1225
  const state = externalState || defaultState;
1216
1226
  const gridRef = useRef8(null);
1227
+ const ambientPlayback = useAgentPlayback();
1228
+ const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
1229
+ const agentPresence = usePlaybackSurface(playing, playbackId, {
1230
+ defaultKind: "cell",
1231
+ locate: (ref) => {
1232
+ const grid2 = gridRef.current;
1233
+ const range = parseSpreadsheetPlaybackRef(ref);
1234
+ if (!grid2 || !range) return null;
1235
+ const box = grid2.getBoundingClientRect();
1236
+ const inside = (v, a, b) => (a === null || v >= a) && (b === null || v <= b);
1237
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
1238
+ for (const td of grid2.querySelectorAll("td[data-row][data-col]")) {
1239
+ if (!inside(Number(td.dataset.row), range.startRow, range.endRow) || !inside(Number(td.dataset.col), range.startCol, range.endCol)) continue;
1240
+ const r = td.getBoundingClientRect();
1241
+ minX = Math.min(minX, r.left - box.left);
1242
+ minY = Math.min(minY, r.top - box.top);
1243
+ maxX = Math.max(maxX, r.right - box.left);
1244
+ maxY = Math.max(maxY, r.bottom - box.top);
1245
+ }
1246
+ return minX < maxX ? { x: minX, y: minY, width: maxX - minX, height: maxY - minY } : null;
1247
+ },
1248
+ bounds: () => {
1249
+ const r = gridRef.current?.getBoundingClientRect();
1250
+ return r && r.width > 0 ? { x: 0, y: 0, width: r.width, height: r.height } : null;
1251
+ },
1252
+ visible: () => {
1253
+ const r = gridRef.current?.getBoundingClientRect();
1254
+ return !!r && r.width > 0 && r.height > 0 && !(typeof document !== "undefined" && document.visibilityState === "hidden");
1255
+ },
1256
+ toViewport: (p) => {
1257
+ const r = gridRef.current?.getBoundingClientRect();
1258
+ return { x: (r?.left ?? 0) + p.x, y: (r?.top ?? 0) + p.y };
1259
+ },
1260
+ fromViewport: (p) => {
1261
+ const r = gridRef.current?.getBoundingClientRect();
1262
+ return { x: p.x - (r?.left ?? 0), y: p.y - (r?.top ?? 0) };
1263
+ },
1264
+ reveal: () => onPlaybackReveal?.()
1265
+ });
1217
1266
  const scrollRef = useRef8(null);
1218
1267
  const formulaBarRef = useRef8(null);
1219
1268
  const cellInputRef = useRef8(null);
@@ -1607,7 +1656,7 @@ var SpreadsheetEditor = ({
1607
1656
  "div",
1608
1657
  {
1609
1658
  ref: gridRef,
1610
- className: "flex flex-col h-full w-full overflow-hidden border border-border bg-background select-none outline-none text-foreground font-sans text-xs",
1659
+ className: "relative flex flex-col h-full w-full overflow-hidden border border-border bg-background select-none outline-none text-foreground font-sans text-xs",
1611
1660
  tabIndex: 0,
1612
1661
  onKeyDown: handleKeyDown,
1613
1662
  role: "grid",
@@ -1944,6 +1993,7 @@ var SpreadsheetEditor = ({
1944
1993
  }
1945
1994
  ),
1946
1995
  state.validationPrompt && /* @__PURE__ */ jsx7(SpreadsheetValidationDialog, { prompt: state.validationPrompt, onResolve: resolveValidation }),
1996
+ playing && /* @__PURE__ */ jsx7(PresenceLayer, { presence: agentPresence }),
1947
1997
  /* @__PURE__ */ jsx7("style", { children: `
1948
1998
  .col-resize-handle:hover .col-resize-handle-line {
1949
1999
  background-color: var(--primary, #6366f1);
@@ -0,0 +1,96 @@
1
+ // src/playback/PresenceLayer.tsx
2
+ import React, { useSyncExternalStore } from "react";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ function PresenceLayer({ presence, viewport, className = "" }) {
5
+ const { actors } = useSyncExternalStore(presence.subscribe, presence.getState, presence.getState);
6
+ if (!actors.length) return null;
7
+ const map = typeof viewport === "function" ? viewport : viewport ? (p) => ({ x: p.x * viewport.zoom + viewport.x, y: p.y * viewport.zoom + viewport.y }) : (p) => p;
8
+ return /* @__PURE__ */ jsx(
9
+ "div",
10
+ {
11
+ className: `pixerate-presence ${className}`.trim(),
12
+ "aria-hidden": "true",
13
+ "data-testid": "presence-layer",
14
+ style: { position: "absolute", inset: 0, pointerEvents: "none", overflow: "hidden", zIndex: 50 },
15
+ children: actors.map((a) => {
16
+ const at = map(a);
17
+ const ring = a.focus && (() => {
18
+ const tl = map(a.focus);
19
+ const br = map({ x: a.focus.x + a.focus.width, y: a.focus.y + a.focus.height });
20
+ return { left: tl.x - 4, top: tl.y - 4, width: br.x - tl.x + 8, height: br.y - tl.y + 8 };
21
+ })();
22
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
23
+ ring && /* @__PURE__ */ jsx(
24
+ "div",
25
+ {
26
+ "data-actor-focus": a.id,
27
+ style: { position: "absolute", ...ring, borderRadius: 8, border: `2px solid ${a.color}`, background: `${a.color}14`, transition: "all 160ms ease-out" }
28
+ }
29
+ ),
30
+ /* @__PURE__ */ jsxs("div", { "data-actor": a.id, style: { position: "absolute", left: 0, top: 0, transform: `translate(${at.x}px, ${at.y}px)` }, children: [
31
+ /* @__PURE__ */ jsx("svg", { width: "18", height: "20", viewBox: "0 0 12 18", style: { display: "block", transform: a.pressed ? "scale(0.85)" : void 0, transformOrigin: "0 0", filter: "drop-shadow(0 1px 2px rgba(0,0,0,.35))" }, children: /* @__PURE__ */ jsx("path", { d: "M0,0 L0,14 L4,10.5 L7,17 L9.5,16 L6.5,9.5 L11.5,9.5 Z", style: { fill: a.color, stroke: "#ffffff", strokeWidth: 1 } }) }),
32
+ /* @__PURE__ */ jsxs("span", { style: { position: "absolute", left: 14, top: 16, display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 4 }, children: [
33
+ /* @__PURE__ */ jsx("span", { style: { whiteSpace: "nowrap", borderRadius: 999, padding: "1px 7px", fontSize: 11, fontWeight: 600, color: "#ffffff", background: a.color }, children: a.name }),
34
+ a.message && /* @__PURE__ */ jsx("span", { "data-actor-message": a.id, style: { width: "max-content", maxWidth: 240, borderRadius: 8, borderTopLeftRadius: 0, padding: "4px 8px", fontSize: 12, color: "#1e293b", background: "#ffffff", boxShadow: "0 4px 12px rgba(15,23,42,.18)" }, children: a.message })
35
+ ] })
36
+ ] })
37
+ ] }, a.id);
38
+ })
39
+ }
40
+ );
41
+ }
42
+
43
+ // src/playback/AgentPlaybackContext.tsx
44
+ import { createContext, useContext } from "react";
45
+ import { jsx as jsx2 } from "react/jsx-runtime";
46
+ var AgentPlaybackContext = createContext(null);
47
+ function AgentPlaybackProvider({ playback, children }) {
48
+ return /* @__PURE__ */ jsx2(AgentPlaybackContext.Provider, { value: playback ?? null, children });
49
+ }
50
+ function useAgentPlayback() {
51
+ return useContext(AgentPlaybackContext);
52
+ }
53
+
54
+ // src/playback/usePlaybackSurface.ts
55
+ import { useEffect, useRef, useState } from "react";
56
+ import { PresenceStore } from "@pixerate/editor/tools";
57
+ function usePlaybackSurface(playback, id, options = {}, sharedPresence) {
58
+ const ambient = useAgentPlayback();
59
+ const target = playback === void 0 ? ambient : playback;
60
+ const [ownPresence] = useState(() => new PresenceStore());
61
+ const presence = sharedPresence ?? ownPresence;
62
+ const latest = useRef(options);
63
+ latest.current = options;
64
+ useEffect(() => {
65
+ if (!target || !id) return;
66
+ const o = () => latest.current;
67
+ const surface = {
68
+ presence,
69
+ locate: (ref) => o().locate?.(ref) ?? null,
70
+ bounds: () => o().bounds?.() ?? null,
71
+ visible: () => o().visible?.() ?? true,
72
+ toViewport: (p) => o().toViewport?.(p) ?? p,
73
+ fromViewport: (p) => o().fromViewport?.(p) ?? p,
74
+ beginGesture: (key) => o().beginGesture?.(key),
75
+ endGesture: () => o().endGesture?.(),
76
+ reveal: () => o().reveal?.(),
77
+ open: (ref) => o().open?.(ref),
78
+ get defaultKind() {
79
+ return o().defaultKind;
80
+ }
81
+ };
82
+ const detach = target.attach(id, surface);
83
+ return () => {
84
+ detach();
85
+ for (const a of presence.getState().actors) presence.remove(a.id);
86
+ };
87
+ }, [target, id, presence]);
88
+ return presence;
89
+ }
90
+
91
+ export {
92
+ PresenceLayer,
93
+ AgentPlaybackProvider,
94
+ useAgentPlayback,
95
+ usePlaybackSurface
96
+ };
@@ -1,4 +1,8 @@
1
- import type { AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
1
+ import type { AgentPlayback, AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
2
+ export interface UseAgentToolProviderOptions {
3
+ /** Plays the registry's calls with this playback (installed once per registry). */
4
+ playback?: AgentPlayback | null;
5
+ }
2
6
  /**
3
7
  * Registers a tool provider with a `ToolRegistry` while the component is
4
8
  * mounted and unregisters it on unmount (the registry then announces the
@@ -8,4 +12,4 @@ import type { AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
8
12
  * { id }), [editor])`): a new provider object re-registers it. Pass `null`
9
13
  * while it isn't ready.
10
14
  */
11
- export declare function useAgentToolProvider(registry: ToolRegistry | null | undefined, provider: AgentToolProvider | null | undefined): void;
15
+ export declare function useAgentToolProvider(registry: ToolRegistry | null | undefined, provider: AgentToolProvider | null | undefined, options?: UseAgentToolProviderOptions): void;
@@ -1,4 +1,8 @@
1
- import type { AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
1
+ import type { AgentPlayback, AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
2
+ export interface UseAgentToolProviderOptions {
3
+ /** Plays the registry's calls with this playback (installed once per registry). */
4
+ playback?: AgentPlayback | null;
5
+ }
2
6
  /**
3
7
  * Registers a tool provider with a `ToolRegistry` while the component is
4
8
  * mounted and unregisters it on unmount (the registry then announces the
@@ -8,4 +12,4 @@ import type { AgentToolProvider, ToolRegistry } from "@pixerate/editor/tools";
8
12
  * { id }), [editor])`): a new provider object re-registers it. Pass `null`
9
13
  * while it isn't ready.
10
14
  */
11
- export declare function useAgentToolProvider(registry: ToolRegistry | null | undefined, provider: AgentToolProvider | null | undefined): void;
15
+ export declare function useAgentToolProvider(registry: ToolRegistry | null | undefined, provider: AgentToolProvider | null | undefined, options?: UseAgentToolProviderOptions): void;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { AgentPlayback } from '@pixerate/editor/tools';
2
3
  import type { ExportOptions, InpaintHook, RemoveBackgroundHook, ImageEditorAIHooks } from '@pixerate/editor/image-editor';
3
4
  import { type UseImageEditorReturn } from './useImageEditor.cjs';
4
5
  import type { EffectProvider } from '@pixerate/editor/effects';
@@ -18,5 +19,14 @@ export interface ImageEditorProps {
18
19
  * with an Effects section in the Layers tab. Optional: without one the editor is as before.
19
20
  */
20
21
  effects?: EffectProvider | null;
22
+ /**
23
+ * Agent playback: act out the image tools' calls here with the agent's cursor, opening the panel
24
+ * each tool belongs to (default: the nearest `AgentPlaybackProvider`; `null` turns it off).
25
+ */
26
+ playback?: AgentPlayback | null;
27
+ /** The playback surface id (default `image`, where the image tool providers play). */
28
+ playbackId?: string;
29
+ /** Bring the editor on screen (switch to its tab) before the agent acts. */
30
+ onPlaybackReveal?: () => void | Promise<void>;
21
31
  }
22
32
  export declare const ImageEditor: React.FC<ImageEditorProps>;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { AgentPlayback } from '@pixerate/editor/tools';
2
3
  import type { ExportOptions, InpaintHook, RemoveBackgroundHook, ImageEditorAIHooks } from '@pixerate/editor/image-editor';
3
4
  import { type UseImageEditorReturn } from './useImageEditor.js';
4
5
  import type { EffectProvider } from '@pixerate/editor/effects';
@@ -18,5 +19,14 @@ export interface ImageEditorProps {
18
19
  * with an Effects section in the Layers tab. Optional: without one the editor is as before.
19
20
  */
20
21
  effects?: EffectProvider | null;
22
+ /**
23
+ * Agent playback: act out the image tools' calls here with the agent's cursor, opening the panel
24
+ * each tool belongs to (default: the nearest `AgentPlaybackProvider`; `null` turns it off).
25
+ */
26
+ playback?: AgentPlayback | null;
27
+ /** The playback surface id (default `image`, where the image tool providers play). */
28
+ playbackId?: string;
29
+ /** Bring the editor on screen (switch to its tab) before the agent acts. */
30
+ onPlaybackReveal?: () => void | Promise<void>;
21
31
  }
22
32
  export declare const ImageEditor: React.FC<ImageEditorProps>;