@pixerate/editor-react 0.173.0 → 0.174.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
3
3
  export interface PaintCanvasProps {
4
4
  controller: PaintEditorController;
5
5
  /** The active tool (default brush). */
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
12
12
  onError?: (message: string | null) => void;
13
13
  /** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
14
14
  presence?: PaintPresence;
15
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
+ proposals?: PaintProposals;
15
17
  className?: string;
16
18
  }
17
19
  /**
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
38
40
  height: number;
39
41
  };
40
42
  }>;
43
+ /** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
44
+ export declare const PaintProposalGhosts: React.FC<{
45
+ proposals: PaintProposals;
46
+ transform: string;
47
+ zoom: number;
48
+ }>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
3
3
  export interface PaintCanvasProps {
4
4
  controller: PaintEditorController;
5
5
  /** The active tool (default brush). */
@@ -12,6 +12,8 @@ export interface PaintCanvasProps {
12
12
  onError?: (message: string | null) => void;
13
13
  /** Agent cursors to draw over the canvas (see `PaintDirector` and `usePaintDirector`). */
14
14
  presence?: PaintPresence;
15
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
+ proposals?: PaintProposals;
15
17
  className?: string;
16
18
  }
17
19
  /**
@@ -38,3 +40,9 @@ export declare const PaintPresenceLayer: React.FC<{
38
40
  height: number;
39
41
  };
40
42
  }>;
43
+ /** Pending paint proposals drawn over the canvas: each ghost where its paint would go, translucent with a dashed edge. */
44
+ export declare const PaintProposalGhosts: React.FC<{
45
+ proposals: PaintProposals;
46
+ transform: string;
47
+ zoom: number;
48
+ }>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
9
9
  height?: number | string;
10
10
  /** Agent cursors to draw over the canvas (see `usePaintDirector`). */
11
11
  presence?: PaintPresence;
12
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
+ proposals?: PaintProposals;
12
14
  className?: string;
13
15
  /**
14
16
  * Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PaintPresence, type PaintEditorController } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -9,6 +9,8 @@ export interface PaintEditorProps {
9
9
  height?: number | string;
10
10
  /** Agent cursors to draw over the canvas (see `usePaintDirector`). */
11
11
  presence?: PaintPresence;
12
+ /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
+ proposals?: PaintProposals;
12
14
  className?: string;
13
15
  /**
14
16
  * Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
@@ -41,6 +41,7 @@ __export(paint_editor_exports, {
41
41
  PaintGradientEditor: () => PaintGradientEditor,
42
42
  PaintLayersPanel: () => PaintLayersPanel,
43
43
  PaintPresenceLayer: () => PaintPresenceLayer,
44
+ PaintProposalGhosts: () => PaintProposalGhosts,
44
45
  PaintSlider: () => PaintSlider,
45
46
  PaintToolbar: () => PaintToolbar,
46
47
  PaperPanel: () => PaperPanel,
@@ -48,11 +49,13 @@ __export(paint_editor_exports, {
48
49
  StickerPicker: () => StickerPicker,
49
50
  StrokePanel: () => StrokePanel,
50
51
  WetPanel: () => WetPanel,
52
+ usePaintChangeFeed: () => usePaintChangeFeed,
51
53
  usePaintDirector: () => usePaintDirector,
52
54
  usePaintEditor: () => usePaintEditor,
53
55
  usePaintEditorState: () => usePaintEditorState,
54
56
  usePaintEffectsProvider: () => usePaintEffectsProvider,
55
- usePaintEffectsTools: () => usePaintEffectsTools
57
+ usePaintEffectsTools: () => usePaintEffectsTools,
58
+ usePaintProposals: () => usePaintProposals
56
59
  });
57
60
  module.exports = __toCommonJS(paint_editor_exports);
58
61
 
@@ -80,12 +83,33 @@ function usePaintDirector(controller, options = {}) {
80
83
  });
81
84
  return value;
82
85
  }
86
+ function usePaintProposals(controller, options = {}) {
87
+ const [store] = (0, import_react.useState)(() => (0, import_paint_editor.createPaintProposals)({ ...options, controller }));
88
+ const state = (0, import_react.useSyncExternalStore)(store.subscribe, store.getState, store.getState);
89
+ return (0, import_react.useMemo)(() => ({ store, proposals: state.proposals, propose: store.propose, accept: store.accept, reject: store.reject, clear: store.clear }), [store, state]);
90
+ }
91
+ function usePaintChangeFeed(controller, options = {}) {
92
+ const onChange = (0, import_react.useRef)(options.onChange);
93
+ onChange.current = options.onChange;
94
+ const [last, setLast] = (0, import_react.useState)(null);
95
+ const [feed, setFeed] = (0, import_react.useState)(null);
96
+ (0, import_react.useEffect)(() => {
97
+ const next = (0, import_paint_editor.createPaintChangeFeed)(controller);
98
+ next.subscribe((change) => {
99
+ setLast(change);
100
+ onChange.current?.(change);
101
+ });
102
+ setFeed(next);
103
+ return () => next.dispose();
104
+ }, [controller]);
105
+ return { feed, last };
106
+ }
83
107
 
84
108
  // src/paint-editor/PaintCanvas.tsx
85
109
  var import_react2 = require("react");
86
110
  var import_paint_editor2 = require("@pixerate/editor/paint-editor");
87
111
  var import_jsx_runtime = require("react/jsx-runtime");
88
- var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, className }) => {
112
+ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
89
113
  const state = usePaintEditorState(controller);
90
114
  const viewport = (0, import_react2.useRef)(null);
91
115
  const canvas = (0, import_react2.useRef)(null);
@@ -226,6 +250,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
226
250
  predicted.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: predicted.map((p) => `${p.x},${p.y}`).join(" "), fill: "none", stroke: state.color, strokeOpacity: 0.5, strokeWidth: Math.max(1, state.brush.tip.size / 2), strokeLinecap: "round" })
227
251
  ] }),
228
252
  state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferencePanel, { controller, id: r.id }, r.id)),
253
+ proposals && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhosts, { proposals, transform, zoom: state.view.zoom }),
229
254
  presence && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintPresenceLayer, { presence, view: state.view, canvas: doc, viewport: size }),
230
255
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "absolute bottom-1 right-2 text-[10px] text-slate-500 pointer-events-none", "data-testid": "paint-view-status", children: [
231
256
  Math.round(state.view.zoom * 100),
@@ -301,6 +326,33 @@ var ReferencePanel = ({ controller, id }) => {
301
326
  }
302
327
  );
303
328
  };
329
+ var PaintProposalGhosts = ({ proposals, transform, zoom }) => {
330
+ const { proposals: pending } = (0, import_react2.useSyncExternalStore)(proposals.subscribe, proposals.getState, proposals.getState);
331
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: pending.map((p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintProposalGhost, { proposal: p, transform, zoom }, p.id)) });
332
+ };
333
+ var PaintProposalGhost = ({ proposal, transform, zoom }) => {
334
+ const ref = (0, import_react2.useRef)(null);
335
+ const ghost = (0, import_paint_editor2.paintProposalGhost)(proposal);
336
+ (0, import_react2.useEffect)(() => {
337
+ const ctx = ref.current?.getContext("2d");
338
+ if (!ctx || !ghost || typeof ImageData === "undefined") return;
339
+ ctx.putImageData(new ImageData(new Uint8ClampedArray(ghost.data), ghost.width, ghost.height), 0, 0);
340
+ }, [ghost?.data]);
341
+ if (!ghost) return null;
342
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
343
+ "canvas",
344
+ {
345
+ ref,
346
+ width: ghost.width,
347
+ height: ghost.height,
348
+ "data-paint-proposal": proposal.id,
349
+ title: proposal.rationale ? `${proposal.title}: ${proposal.rationale}` : proposal.title,
350
+ "aria-label": `Suggested: ${proposal.title}`,
351
+ className: "absolute left-0 top-0 pointer-events-none",
352
+ style: { transform: `${transform} translate(${ghost.x}px, ${ghost.y}px)`, transformOrigin: "0 0", opacity: 0.7, outline: `${1.5 / zoom}px dashed #a78bfa`, outlineOffset: `${2 / zoom}px` }
353
+ }
354
+ );
355
+ };
304
356
 
305
357
  // src/paint-editor/PaintToolbar.tsx
306
358
  var import_react4 = require("react");
@@ -3913,7 +3965,7 @@ var PAINT_CONTROLS = {
3913
3965
  lighting: '[data-testid="light-panel"]',
3914
3966
  symmetry: '[aria-label="Symmetry"]'
3915
3967
  };
3916
- var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
3968
+ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
3917
3969
  const [tool, setTool] = (0, import_react29.useState)("brush");
3918
3970
  const [tab, setTab] = (0, import_react29.useState)("color");
3919
3971
  const tabRef = (0, import_react29.useRef)(tab);
@@ -3984,7 +4036,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
3984
4036
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-h-0 flex-1 gap-2", children: [
3985
4037
  /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
3986
4038
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col", children: [
3987
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
4039
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
3988
4040
  error && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
3989
4041
  ] }),
3990
4042
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
@@ -4014,6 +4066,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
4014
4066
  PaintGradientEditor,
4015
4067
  PaintLayersPanel,
4016
4068
  PaintPresenceLayer,
4069
+ PaintProposalGhosts,
4017
4070
  PaintSlider,
4018
4071
  PaintToolbar,
4019
4072
  PaperPanel,
@@ -4021,9 +4074,11 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
4021
4074
  StickerPicker,
4022
4075
  StrokePanel,
4023
4076
  WetPanel,
4077
+ usePaintChangeFeed,
4024
4078
  usePaintDirector,
4025
4079
  usePaintEditor,
4026
4080
  usePaintEditorState,
4027
4081
  usePaintEffectsProvider,
4028
- usePaintEffectsTools
4082
+ usePaintEffectsTools,
4083
+ usePaintProposals
4029
4084
  });
@@ -23,8 +23,15 @@ import {
23
23
  } from "../chunk-62FMEDGG.js";
24
24
 
25
25
  // src/paint-editor/usePaintEditor.ts
26
- import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
27
- import { PaintDirector, PaintEditorController, PaintPresence, createPaintEditorDocument } from "@pixerate/editor/paint-editor";
26
+ import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
27
+ import {
28
+ PaintDirector,
29
+ PaintEditorController,
30
+ PaintPresence,
31
+ createPaintChangeFeed,
32
+ createPaintEditorDocument,
33
+ createPaintProposals
34
+ } from "@pixerate/editor/paint-editor";
28
35
  function usePaintEditor(options = {}) {
29
36
  const [controller] = useState(() => options instanceof PaintEditorController ? options : new PaintEditorController(options));
30
37
  const state = usePaintEditorState(controller);
@@ -46,9 +53,30 @@ function usePaintDirector(controller, options = {}) {
46
53
  });
47
54
  return value;
48
55
  }
56
+ function usePaintProposals(controller, options = {}) {
57
+ const [store] = useState(() => createPaintProposals({ ...options, controller }));
58
+ const state = useSyncExternalStore(store.subscribe, store.getState, store.getState);
59
+ return useMemo(() => ({ store, proposals: state.proposals, propose: store.propose, accept: store.accept, reject: store.reject, clear: store.clear }), [store, state]);
60
+ }
61
+ function usePaintChangeFeed(controller, options = {}) {
62
+ const onChange = useRef(options.onChange);
63
+ onChange.current = options.onChange;
64
+ const [last, setLast] = useState(null);
65
+ const [feed, setFeed] = useState(null);
66
+ useEffect(() => {
67
+ const next = createPaintChangeFeed(controller);
68
+ next.subscribe((change) => {
69
+ setLast(change);
70
+ onChange.current?.(change);
71
+ });
72
+ setFeed(next);
73
+ return () => next.dispose();
74
+ }, [controller]);
75
+ return { feed, last };
76
+ }
49
77
 
50
78
  // src/paint-editor/PaintCanvas.tsx
51
- import { useEffect as useEffect2, useMemo as useMemo2, useRef, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
79
+ import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2, useSyncExternalStore as useSyncExternalStore2 } from "react";
52
80
  import {
53
81
  PaintCanvasPresenter,
54
82
  PaintGesture,
@@ -58,16 +86,17 @@ import {
58
86
  fitZoom,
59
87
  guideOverlay,
60
88
  handlePaintShortcut,
61
- viewCssTransform
89
+ viewCssTransform,
90
+ paintProposalGhost
62
91
  } from "@pixerate/editor/paint-editor";
63
- import { jsx, jsxs } from "react/jsx-runtime";
64
- var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, className }) => {
92
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
93
+ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
65
94
  const state = usePaintEditorState(controller);
66
- const viewport = useRef(null);
67
- const canvas = useRef(null);
68
- const water = useRef(null);
95
+ const viewport = useRef2(null);
96
+ const canvas = useRef2(null);
97
+ const water = useRef2(null);
69
98
  const [size, setSize] = useState2({ width: 800, height: 600 });
70
- const measured = useRef(false);
99
+ const measured = useRef2(false);
71
100
  const [predicted, setPredicted] = useState2([]);
72
101
  const [strokeDrag, setStrokeDrag] = useState2(null);
73
102
  const presenter = useMemo2(() => new PaintCanvasPresenter(controller), [controller]);
@@ -93,7 +122,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
93
122
  ro.observe(el);
94
123
  return () => ro.disconnect();
95
124
  }, []);
96
- const fitted = useRef(null);
125
+ const fitted = useRef2(null);
97
126
  useEffect2(() => {
98
127
  const key = `${doc.width}x${doc.height}`;
99
128
  if (!fitOnMount || fitted.current === key) return;
@@ -202,6 +231,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
202
231
  predicted.length > 0 && /* @__PURE__ */ jsx("polyline", { points: predicted.map((p) => `${p.x},${p.y}`).join(" "), fill: "none", stroke: state.color, strokeOpacity: 0.5, strokeWidth: Math.max(1, state.brush.tip.size / 2), strokeLinecap: "round" })
203
232
  ] }),
204
233
  state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ jsx(ReferencePanel, { controller, id: r.id }, r.id)),
234
+ proposals && /* @__PURE__ */ jsx(PaintProposalGhosts, { proposals, transform, zoom: state.view.zoom }),
205
235
  presence && /* @__PURE__ */ jsx(PaintPresenceLayer, { presence, view: state.view, canvas: doc, viewport: size }),
206
236
  /* @__PURE__ */ jsxs("div", { className: "absolute bottom-1 right-2 text-[10px] text-slate-500 pointer-events-none", "data-testid": "paint-view-status", children: [
207
237
  Math.round(state.view.zoom * 100),
@@ -227,7 +257,7 @@ var PaintPresenceLayer = ({ presence, view, canvas, viewport }) => {
227
257
  var ReferencePanel = ({ controller, id }) => {
228
258
  const state = usePaintEditorState(controller);
229
259
  const ref = state.guides.references.find((r) => r.id === id);
230
- const drag = useRef(null);
260
+ const drag = useRef2(null);
231
261
  if (!ref) return null;
232
262
  const h = ref.height / ref.width * ref.displayWidth;
233
263
  return /* @__PURE__ */ jsxs(
@@ -277,19 +307,46 @@ var ReferencePanel = ({ controller, id }) => {
277
307
  }
278
308
  );
279
309
  };
310
+ var PaintProposalGhosts = ({ proposals, transform, zoom }) => {
311
+ const { proposals: pending } = useSyncExternalStore2(proposals.subscribe, proposals.getState, proposals.getState);
312
+ return /* @__PURE__ */ jsx(Fragment, { children: pending.map((p) => /* @__PURE__ */ jsx(PaintProposalGhost, { proposal: p, transform, zoom }, p.id)) });
313
+ };
314
+ var PaintProposalGhost = ({ proposal, transform, zoom }) => {
315
+ const ref = useRef2(null);
316
+ const ghost = paintProposalGhost(proposal);
317
+ useEffect2(() => {
318
+ const ctx = ref.current?.getContext("2d");
319
+ if (!ctx || !ghost || typeof ImageData === "undefined") return;
320
+ ctx.putImageData(new ImageData(new Uint8ClampedArray(ghost.data), ghost.width, ghost.height), 0, 0);
321
+ }, [ghost?.data]);
322
+ if (!ghost) return null;
323
+ return /* @__PURE__ */ jsx(
324
+ "canvas",
325
+ {
326
+ ref,
327
+ width: ghost.width,
328
+ height: ghost.height,
329
+ "data-paint-proposal": proposal.id,
330
+ title: proposal.rationale ? `${proposal.title}: ${proposal.rationale}` : proposal.title,
331
+ "aria-label": `Suggested: ${proposal.title}`,
332
+ className: "absolute left-0 top-0 pointer-events-none",
333
+ style: { transform: `${transform} translate(${ghost.x}px, ${ghost.y}px)`, transformOrigin: "0 0", opacity: 0.7, outline: `${1.5 / zoom}px dashed #a78bfa`, outlineOffset: `${2 / zoom}px` }
334
+ }
335
+ );
336
+ };
280
337
 
281
338
  // src/paint-editor/PaintToolbar.tsx
282
- import { useRef as useRef3, useState as useState4 } from "react";
339
+ import { useRef as useRef4, useState as useState4 } from "react";
283
340
  import { PAINT_TOOLS, SYMMETRY_MODES, decodeImageBlob, downloadBytes, quickStencil, timeLapseZip } from "@pixerate/editor/paint-editor";
284
341
 
285
342
  // src/paint-editor/shared.tsx
286
- import { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
343
+ import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
287
344
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
288
345
  var chip = (on) => `px-2 py-1 rounded text-[11px] ${on ? "bg-indigo-600 text-white" : "bg-slate-800 text-slate-300 hover:text-white"}`;
289
346
  var button = "px-2 py-1 rounded text-[11px] bg-slate-800 text-slate-200 hover:bg-slate-700 disabled:opacity-40";
290
347
  var panel = "flex flex-col gap-2 text-xs text-slate-200";
291
348
  var PixelCanvas = ({ pixels, label, className, style }) => {
292
- const ref = useRef2(null);
349
+ const ref = useRef3(null);
293
350
  useEffect3(() => {
294
351
  const canvas = ref.current;
295
352
  const ctx = canvas?.getContext("2d");
@@ -305,8 +362,8 @@ var PixelCanvas = ({ pixels, label, className, style }) => {
305
362
  var fmt = (c, v) => c.step >= 1 ? String(Math.round(v)) : v.toFixed(2);
306
363
  var PaintSlider = ({ control, value, onChange, onCommit }) => {
307
364
  const [draft, setDraft] = useState3(null);
308
- const ref = useRef2(null);
309
- const commit = useRef2(onCommit);
365
+ const ref = useRef3(null);
366
+ const commit = useRef3(onCommit);
310
367
  commit.current = onCommit;
311
368
  useEffect3(() => {
312
369
  const el = ref.current;
@@ -359,8 +416,8 @@ function useAttempt() {
359
416
  }
360
417
  var ErrorLine = ({ error }) => error ? /* @__PURE__ */ jsx2("p", { role: "alert", className: "text-[11px] text-rose-400", children: error }) : null;
361
418
  var CommitColorInput = ({ value, label, onCommit, className }) => {
362
- const ref = useRef2(null);
363
- const commit = useRef2(onCommit);
419
+ const ref = useRef3(null);
420
+ const commit = useRef3(onCommit);
364
421
  commit.current = onCommit;
365
422
  useEffect3(() => {
366
423
  const el = ref.current;
@@ -373,15 +430,15 @@ var CommitColorInput = ({ value, label, onCommit, className }) => {
373
430
  };
374
431
 
375
432
  // src/paint-editor/PaintToolbar.tsx
376
- import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
433
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
377
434
  var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", className }) => {
378
435
  const state = usePaintEditorState(controller);
379
436
  const [error, attempt] = useAttempt();
380
437
  const [busy, setBusy] = useState4(null);
381
438
  const [note, setNote] = useState4(null);
382
- const openRef = useRef3(null);
383
- const tracingRef = useRef3(null);
384
- const refRef = useRef3(null);
439
+ const openRef = useRef4(null);
440
+ const tracingRef = useRef4(null);
441
+ const refRef = useRef4(null);
385
442
  const { symmetry, perspective, tracing } = state.guides;
386
443
  const { canvas } = state.document;
387
444
  const exportImage = (format) => attempt(async () => downloadBytes(await controller.exportImage({ format }), `${fileName}.${format === "image/png" ? "png" : "jpg"}`, format));
@@ -456,7 +513,7 @@ var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", cla
456
513
  ),
457
514
  /* @__PURE__ */ jsx3("span", { className: "mx-1 h-4 w-px bg-slate-700" }),
458
515
  /* @__PURE__ */ jsx3("button", { type: "button", className: button, onClick: () => tracingRef.current?.click(), children: "Tracing image\u2026" }),
459
- tracing && /* @__PURE__ */ jsxs3(Fragment, { children: [
516
+ tracing && /* @__PURE__ */ jsxs3(Fragment2, { children: [
460
517
  /* @__PURE__ */ jsx3(
461
518
  "input",
462
519
  {
@@ -577,7 +634,7 @@ var PaintToolbar = ({ controller, tool, onToolChange, fileName = "painting", cla
577
634
  };
578
635
 
579
636
  // src/paint-editor/BrushPanel.tsx
580
- import { useMemo as useMemo4, useRef as useRef4 } from "react";
637
+ import { useMemo as useMemo4, useRef as useRef5 } from "react";
581
638
  import { brushLoadColor, brushTakesPaint, downloadBytes as downloadBytes2, toggleStickerRef, DEFAULT_PAINT_GRADIENT } from "@pixerate/editor/paint-editor";
582
639
  import { PAINT_PROFILE as PAINT_PROFILE2 } from "@pixerate/editor/brushes";
583
640
 
@@ -704,7 +761,7 @@ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
704
761
  var BrushPanel = ({ controller, thumbnailWidth = 112, thumbnailHeight = 32, className }) => {
705
762
  const state = usePaintEditorState(controller);
706
763
  const [error, attempt] = useAttempt();
707
- const fileRef = useRef4(null);
764
+ const fileRef = useRef5(null);
708
765
  const { brush, brushes } = state;
709
766
  const paper = state.document.paper;
710
767
  const thumbs = useMemo4(
@@ -827,7 +884,7 @@ var PaperPanel = ({ controller, className }) => {
827
884
  };
828
885
 
829
886
  // src/paint-editor/ColorPanel.tsx
830
- import { useMemo as useMemo6, useRef as useRef5, useState as useState7 } from "react";
887
+ import { useMemo as useMemo6, useRef as useRef6, useState as useState7 } from "react";
831
888
  import {
832
889
  HARMONY_KINDS,
833
890
  MIXING_PAD_HEIGHT,
@@ -854,7 +911,7 @@ var ColorPanel = ({ controller, wheelSize = 168, mixingPad = true, className })
854
911
  const [sample, setSample] = useState7(3);
855
912
  const [parts, setParts] = useState7([1, 1]);
856
913
  const [padName, setPadName] = useState7("");
857
- const padPoints = useRef5(null);
914
+ const padPoints = useRef6(null);
858
915
  const ring = useMemo6(() => renderColorWheel(wheelSize, wheel), [wheelSize, wheel]);
859
916
  const color = state.color;
860
917
  const harmony = useMemo6(() => controller.harmony(kind, { color, wheel }), [controller, kind, color, wheel]);
@@ -1368,11 +1425,11 @@ var StrokePanel = ({ controller, className }) => {
1368
1425
  };
1369
1426
 
1370
1427
  // src/paint-editor/PaintEditor.tsx
1371
- import { useRef as useRef7, useState as useState10 } from "react";
1428
+ import { useRef as useRef8, useState as useState10 } from "react";
1372
1429
  import { PaintPresence as PaintPresence2, documentToScreen as documentToScreen2, screenToDocument } from "@pixerate/editor/paint-editor";
1373
1430
 
1374
1431
  // src/paint-editor/PaintEffectsPanel.tsx
1375
- import { useEffect as useEffect5, useMemo as useMemo7, useRef as useRef6, useState as useState9 } from "react";
1432
+ import { useEffect as useEffect5, useMemo as useMemo7, useRef as useRef7, useState as useState9 } from "react";
1376
1433
  import { createPaintEffectsToolProvider, PAPER_EFFECT_BLENDS } from "@pixerate/editor/paint-editor";
1377
1434
  import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
1378
1435
  function usePaintEffectsProvider(controller) {
@@ -1392,7 +1449,7 @@ function usePaintEffectsTools(registry, controller, options = {}) {
1392
1449
  }
1393
1450
  function Controls({ provider, effect, name, values, apply }) {
1394
1451
  const { description, error } = useEffectDescription(provider, effect);
1395
- const drags = useRef6(/* @__PURE__ */ new Set());
1452
+ const drags = useRef7(/* @__PURE__ */ new Set());
1396
1453
  if (!provider) return /* @__PURE__ */ jsxs13("p", { className: "text-[11px] text-slate-400", children: [
1397
1454
  'No effects provider: "',
1398
1455
  name ?? effect,
@@ -1587,12 +1644,12 @@ var PAINT_CONTROLS = {
1587
1644
  lighting: '[data-testid="light-panel"]',
1588
1645
  symmetry: '[aria-label="Symmetry"]'
1589
1646
  };
1590
- var PaintEditor = ({ controller, fileName, height = 720, presence, className, playback, playbackId = "paint", onPlaybackReveal }) => {
1647
+ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
1591
1648
  const [tool, setTool] = useState10("brush");
1592
1649
  const [tab, setTab] = useState10("color");
1593
- const tabRef = useRef7(tab);
1650
+ const tabRef = useRef8(tab);
1594
1651
  tabRef.current = tab;
1595
- const rootRef = useRef7(null);
1652
+ const rootRef = useRef8(null);
1596
1653
  const [ownPresence] = useState10(() => new PaintPresence2());
1597
1654
  const ambientPlayback = useAgentPlayback();
1598
1655
  const playing = (playback === void 0 ? ambientPlayback : playback) ?? null;
@@ -1658,7 +1715,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, className, pl
1658
1715
  /* @__PURE__ */ jsxs14("div", { className: "flex min-h-0 flex-1 gap-2", children: [
1659
1716
  /* @__PURE__ */ jsx15(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
1660
1717
  /* @__PURE__ */ jsxs14("div", { className: "flex min-w-0 flex-1 flex-col", children: [
1661
- /* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, className: "flex-1 rounded-lg" }),
1718
+ /* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
1662
1719
  error && /* @__PURE__ */ jsx15("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
1663
1720
  ] }),
1664
1721
  /* @__PURE__ */ jsxs14("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
@@ -1687,6 +1744,7 @@ export {
1687
1744
  PaintGradientEditor,
1688
1745
  PaintLayersPanel,
1689
1746
  PaintPresenceLayer,
1747
+ PaintProposalGhosts,
1690
1748
  PaintSlider,
1691
1749
  PaintToolbar,
1692
1750
  PaperPanel,
@@ -1694,9 +1752,11 @@ export {
1694
1752
  StickerPicker,
1695
1753
  StrokePanel,
1696
1754
  WetPanel,
1755
+ usePaintChangeFeed,
1697
1756
  usePaintDirector,
1698
1757
  usePaintEditor,
1699
1758
  usePaintEditorState,
1700
1759
  usePaintEffectsProvider,
1701
- usePaintEffectsTools
1760
+ usePaintEffectsTools,
1761
+ usePaintProposals
1702
1762
  };
@@ -1,4 +1,4 @@
1
- import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
1
+ import { PaintDirector, PaintEditorController, PaintPresence, type PaintChange, type PaintChangeFeed, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type PaintProposal, type PaintProposals, type PaintProposalsOptions, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
2
2
  import type { EditorDocument } from '@pixerate/editor/persistence';
3
3
  export interface UsePaintEditorReturn {
4
4
  controller: PaintEditorController;
@@ -23,3 +23,32 @@ export declare function usePaintDirector(controller: PaintEditorController, opti
23
23
  presence: PaintPresence;
24
24
  director: PaintDirector;
25
25
  };
26
+ export interface PaintProposalsHandle {
27
+ /** The framework-free store (for `createPaintProposalToolProvider` and agents). */
28
+ readonly store: PaintProposals;
29
+ /** Pending proposals; pass `store` to `PaintCanvas` (`proposals`) to draw them as ghosts. */
30
+ proposals: readonly PaintProposal[];
31
+ propose: PaintProposals['propose'];
32
+ accept: PaintProposals['accept'];
33
+ reject: PaintProposals['reject'];
34
+ clear: PaintProposals['clear'];
35
+ }
36
+ /**
37
+ * Paint an agent suggests without painting it: ghosts the user accepts (painted on a layer of
38
+ * their own as one undo step, made by the proposer) or dismisses. Pass `store` to `PaintCanvas`
39
+ * as `proposals` to draw the ghosts, and to `createPaintProposalToolProvider` for agents. Options
40
+ * are read on the first render. The same API as the Svelte `createPaintProposalState`.
41
+ */
42
+ export declare function usePaintProposals(controller: PaintEditorController, options?: Omit<PaintProposalsOptions, 'controller'>): PaintProposalsHandle;
43
+ /**
44
+ * What changed in the painting, after each change: strokes, fills and layers added, removed or
45
+ * changed, and the start and end of each stroke, with who made it. For agents that paint
46
+ * alongside the user. Returns the feed (`null` until mounted) and the latest change. The same API
47
+ * as the Svelte `createPaintChangeWatcher`.
48
+ */
49
+ export declare function usePaintChangeFeed(controller: PaintEditorController, options?: {
50
+ onChange?: (change: PaintChange) => void;
51
+ }): {
52
+ feed: PaintChangeFeed | null;
53
+ last: PaintChange | null;
54
+ };
@@ -1,4 +1,4 @@
1
- import { PaintDirector, PaintEditorController, PaintPresence, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
1
+ import { PaintDirector, PaintEditorController, PaintPresence, type PaintChange, type PaintChangeFeed, type PaintDirectorOptions, type PaintEditorOptions, type PaintEditorState, type PaintProposal, type PaintProposals, type PaintProposalsOptions, type SerializedPaintDocument } from '@pixerate/editor/paint-editor';
2
2
  import type { EditorDocument } from '@pixerate/editor/persistence';
3
3
  export interface UsePaintEditorReturn {
4
4
  controller: PaintEditorController;
@@ -23,3 +23,32 @@ export declare function usePaintDirector(controller: PaintEditorController, opti
23
23
  presence: PaintPresence;
24
24
  director: PaintDirector;
25
25
  };
26
+ export interface PaintProposalsHandle {
27
+ /** The framework-free store (for `createPaintProposalToolProvider` and agents). */
28
+ readonly store: PaintProposals;
29
+ /** Pending proposals; pass `store` to `PaintCanvas` (`proposals`) to draw them as ghosts. */
30
+ proposals: readonly PaintProposal[];
31
+ propose: PaintProposals['propose'];
32
+ accept: PaintProposals['accept'];
33
+ reject: PaintProposals['reject'];
34
+ clear: PaintProposals['clear'];
35
+ }
36
+ /**
37
+ * Paint an agent suggests without painting it: ghosts the user accepts (painted on a layer of
38
+ * their own as one undo step, made by the proposer) or dismisses. Pass `store` to `PaintCanvas`
39
+ * as `proposals` to draw the ghosts, and to `createPaintProposalToolProvider` for agents. Options
40
+ * are read on the first render. The same API as the Svelte `createPaintProposalState`.
41
+ */
42
+ export declare function usePaintProposals(controller: PaintEditorController, options?: Omit<PaintProposalsOptions, 'controller'>): PaintProposalsHandle;
43
+ /**
44
+ * What changed in the painting, after each change: strokes, fills and layers added, removed or
45
+ * changed, and the start and end of each stroke, with who made it. For agents that paint
46
+ * alongside the user. Returns the feed (`null` until mounted) and the latest change. The same API
47
+ * as the Svelte `createPaintChangeWatcher`.
48
+ */
49
+ export declare function usePaintChangeFeed(controller: PaintEditorController, options?: {
50
+ onChange?: (change: PaintChange) => void;
51
+ }): {
52
+ feed: PaintChangeFeed | null;
53
+ last: PaintChange | null;
54
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.173.0",
3
+ "version": "0.174.0",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -277,7 +277,7 @@
277
277
  "dependencies": {},
278
278
  "peerDependencies": {
279
279
  "@dagrejs/dagre": "^1.1.8",
280
- "@pixerate/editor": ">=0.255.0 <1.0.0-0",
280
+ "@pixerate/editor": ">=0.256.0 <1.0.0-0",
281
281
  "@tiptap/core": "^2.27.3",
282
282
  "@tiptap/extension-bubble-menu": "^2.27.3",
283
283
  "@tiptap/extension-placeholder": "^2.27.3",
@@ -328,7 +328,7 @@
328
328
  "tsup": "^9.0.0",
329
329
  "typescript": "^5.7.3",
330
330
  "vitest": "^5.0.5",
331
- "@pixerate/editor": "0.255.0"
331
+ "@pixerate/editor": "0.256.0"
332
332
  },
333
333
  "scripts": {
334
334
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",