@pixerate/editor-react 0.175.0 → 0.177.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.
@@ -1673,6 +1673,7 @@ function useCanvasDraw(options) {
1673
1673
  drawOptions: options.drawOptions,
1674
1674
  generateNodeId: options.generateNodeId,
1675
1675
  brushLibrary: options.brushLibrary,
1676
+ colorScheme: options.colorScheme,
1676
1677
  onToolChange: setToolState,
1677
1678
  onStyleChange: (s) => setStyleState(s),
1678
1679
  onActiveStrokeChange: setActiveStroke,
@@ -1687,6 +1688,9 @@ function useCanvasDraw(options) {
1687
1688
  controller.setTool(options.initialTool);
1688
1689
  }
1689
1690
  }, [options.initialTool, controller]);
1691
+ (0, import_react17.useEffect)(() => {
1692
+ controller.setColorScheme(options.colorScheme ?? "light");
1693
+ }, [options.colorScheme, controller]);
1690
1694
  return (0, import_react17.useMemo)(
1691
1695
  () => ({
1692
1696
  tool,
@@ -1702,7 +1706,8 @@ function useCanvasDraw(options) {
1702
1706
  eraseAt: controller.eraseAt,
1703
1707
  drawStroke: controller.drawStroke,
1704
1708
  nodeBounds: controller.nodeBounds,
1705
- listBrushes: controller.listBrushes
1709
+ listBrushes: controller.listBrushes,
1710
+ selectBrush: controller.selectBrush
1706
1711
  }),
1707
1712
  [tool, style, activeStroke, controller]
1708
1713
  );
@@ -1214,6 +1214,7 @@ function useCanvasDraw(options) {
1214
1214
  drawOptions: options.drawOptions,
1215
1215
  generateNodeId: options.generateNodeId,
1216
1216
  brushLibrary: options.brushLibrary,
1217
+ colorScheme: options.colorScheme,
1217
1218
  onToolChange: setToolState,
1218
1219
  onStyleChange: (s) => setStyleState(s),
1219
1220
  onActiveStrokeChange: setActiveStroke,
@@ -1228,6 +1229,9 @@ function useCanvasDraw(options) {
1228
1229
  controller.setTool(options.initialTool);
1229
1230
  }
1230
1231
  }, [options.initialTool, controller]);
1232
+ useEffect7(() => {
1233
+ controller.setColorScheme(options.colorScheme ?? "light");
1234
+ }, [options.colorScheme, controller]);
1231
1235
  return useMemo7(
1232
1236
  () => ({
1233
1237
  tool,
@@ -1243,7 +1247,8 @@ function useCanvasDraw(options) {
1243
1247
  eraseAt: controller.eraseAt,
1244
1248
  drawStroke: controller.drawStroke,
1245
1249
  nodeBounds: controller.nodeBounds,
1246
- listBrushes: controller.listBrushes
1250
+ listBrushes: controller.listBrushes,
1251
+ selectBrush: controller.selectBrush
1247
1252
  }),
1248
1253
  [tool, style, activeStroke, controller]
1249
1254
  );
@@ -9,6 +9,8 @@ export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
9
9
  generateNodeId?: () => string;
10
10
  /** The brush library whose saved brushes strokes may use besides the presets (the canvas profile decides which); read once, on mount. */
11
11
  brushLibrary?: CanvasDrawControllerOptions<TNode>['brushLibrary'];
12
+ /** The app's colour scheme, which picks the side of a brush's light / dark default colour (default light). */
13
+ colorScheme?: 'light' | 'dark';
12
14
  onStrokeComplete?: (node: TNode) => void;
13
15
  onNodesErase?: (erasedNodes: TNode[]) => void;
14
16
  }
@@ -38,6 +40,13 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
38
40
  } | undefined;
39
41
  /** The presets and saved brushes `style.brush` accepts (loads the paint engine). */
40
42
  listBrushes: () => Promise<CanvasBrushPreset[]>;
43
+ /**
44
+ * Picks a brush (`null`: plain pen) with its size, and its default colour unless `keepColour`.
45
+ * Resolves to the preset; rejects for a brush the canvas can't paint.
46
+ */
47
+ selectBrush: (id: string | null, choice?: {
48
+ keepColour?: boolean;
49
+ }) => Promise<CanvasBrushPreset | null>;
41
50
  }
42
51
  export type CanvasDraw<TNode extends CanvasNode = CanvasNode> = CanvasDrawState & CanvasDrawActions<TNode>;
43
52
  /**
@@ -9,6 +9,8 @@ export interface UseCanvasDrawOptions<TNode extends CanvasNode = CanvasNode> {
9
9
  generateNodeId?: () => string;
10
10
  /** The brush library whose saved brushes strokes may use besides the presets (the canvas profile decides which); read once, on mount. */
11
11
  brushLibrary?: CanvasDrawControllerOptions<TNode>['brushLibrary'];
12
+ /** The app's colour scheme, which picks the side of a brush's light / dark default colour (default light). */
13
+ colorScheme?: 'light' | 'dark';
12
14
  onStrokeComplete?: (node: TNode) => void;
13
15
  onNodesErase?: (erasedNodes: TNode[]) => void;
14
16
  }
@@ -38,6 +40,13 @@ export interface CanvasDrawActions<TNode extends CanvasNode = CanvasNode> {
38
40
  } | undefined;
39
41
  /** The presets and saved brushes `style.brush` accepts (loads the paint engine). */
40
42
  listBrushes: () => Promise<CanvasBrushPreset[]>;
43
+ /**
44
+ * Picks a brush (`null`: plain pen) with its size, and its default colour unless `keepColour`.
45
+ * Resolves to the preset; rejects for a brush the canvas can't paint.
46
+ */
47
+ selectBrush: (id: string | null, choice?: {
48
+ keepColour?: boolean;
49
+ }) => Promise<CanvasBrushPreset | null>;
41
50
  }
42
51
  export type CanvasDraw<TNode extends CanvasNode = CanvasNode> = CanvasDrawState & CanvasDrawActions<TNode>;
43
52
  /**
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintAgentStrokes, 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). */
@@ -14,6 +14,8 @@ export interface PaintCanvasProps {
14
14
  presence?: PaintPresence;
15
15
  /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
16
  proposals?: PaintProposals;
17
+ /** Strokes an agent is painting live alongside the user's, drawn as soft lines (see `createPaintAgentStrokes`). */
18
+ agentStrokes?: PaintAgentStrokes;
17
19
  className?: string;
18
20
  }
19
21
  /**
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type PaintEditorController, type PaintPresence, type PaintProposals, type PaintTool, type PaintView } from '@pixerate/editor/paint-editor';
2
+ import { type PaintEditorController, type PaintAgentStrokes, 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). */
@@ -14,6 +14,8 @@ export interface PaintCanvasProps {
14
14
  presence?: PaintPresence;
15
15
  /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
16
16
  proposals?: PaintProposals;
17
+ /** Strokes an agent is painting live alongside the user's, drawn as soft lines (see `createPaintAgentStrokes`). */
18
+ agentStrokes?: PaintAgentStrokes;
17
19
  className?: string;
18
20
  }
19
21
  /**
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { PaintPresence, type PaintEditorController, type PaintProposals } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals, type PaintAgentStrokes } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -11,6 +11,8 @@ export interface PaintEditorProps {
11
11
  presence?: PaintPresence;
12
12
  /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
13
  proposals?: PaintProposals;
14
+ /** Strokes an agent is painting live alongside the user's (see `createPaintAgentStrokes`). */
15
+ agentStrokes?: PaintAgentStrokes;
14
16
  className?: string;
15
17
  /**
16
18
  * 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, type PaintProposals } from '@pixerate/editor/paint-editor';
2
+ import { PaintPresence, type PaintEditorController, type PaintProposals, type PaintAgentStrokes } from '@pixerate/editor/paint-editor';
3
3
  import type { AgentPlayback } from '@pixerate/editor/tools';
4
4
  export interface PaintEditorProps {
5
5
  controller: PaintEditorController;
@@ -11,6 +11,8 @@ export interface PaintEditorProps {
11
11
  presence?: PaintPresence;
12
12
  /** Paint an agent suggests, drawn over the canvas as ghosts (see `usePaintProposals`). */
13
13
  proposals?: PaintProposals;
14
+ /** Strokes an agent is painting live alongside the user's (see `createPaintAgentStrokes`). */
15
+ agentStrokes?: PaintAgentStrokes;
14
16
  className?: string;
15
17
  /**
16
18
  * Agent playback: act out the paint tools' calls here with the agent's cursor, opening the panel
@@ -109,7 +109,7 @@ function usePaintChangeFeed(controller, options = {}) {
109
109
  var import_react2 = require("react");
110
110
  var import_paint_editor2 = require("@pixerate/editor/paint-editor");
111
111
  var import_jsx_runtime = require("react/jsx-runtime");
112
- var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
112
+ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, agentStrokes, className }) => {
113
113
  const state = usePaintEditorState(controller);
114
114
  const viewport = (0, import_react2.useRef)(null);
115
115
  const canvas = (0, import_react2.useRef)(null);
@@ -247,6 +247,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
247
247
  },
248
248
  i
249
249
  )),
250
+ agentStrokes && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PaintAgentStrokeLines, { strokes: agentStrokes }),
250
251
  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" })
251
252
  ] }),
252
253
  state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferencePanel, { controller, id: r.id }, r.id)),
@@ -353,6 +354,10 @@ var PaintProposalGhost = ({ proposal, transform, zoom }) => {
353
354
  }
354
355
  );
355
356
  };
357
+ var PaintAgentStrokeLines = ({ strokes }) => {
358
+ const { strokes: list } = (0, import_react2.useSyncExternalStore)(strokes.subscribe, strokes.getState, strokes.getState);
359
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: list.map((s) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { "data-agent-stroke": s.id, points: (0, import_paint_editor2.paintAgentStrokePoints)(s), fill: "none", stroke: s.color, strokeOpacity: s.opacity ?? 0.6, strokeWidth: s.size, strokeLinecap: "round", strokeLinejoin: "round" }, s.id)) });
360
+ };
356
361
 
357
362
  // src/paint-editor/PaintToolbar.tsx
358
363
  var import_react4 = require("react");
@@ -3996,7 +4001,7 @@ var PAINT_CONTROLS = {
3996
4001
  lighting: '[data-testid="light-panel"]',
3997
4002
  symmetry: '[aria-label="Symmetry"]'
3998
4003
  };
3999
- var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
4004
+ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, agentStrokes, className, playback, playbackId = "paint", onPlaybackReveal }) => {
4000
4005
  const [tool, setTool] = (0, import_react29.useState)("brush");
4001
4006
  const [tab, setTab] = (0, import_react29.useState)("color");
4002
4007
  const tabRef = (0, import_react29.useRef)(tab);
@@ -4067,7 +4072,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, cl
4067
4072
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-h-0 flex-1 gap-2", children: [
4068
4073
  /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
4069
4074
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex min-w-0 flex-1 flex-col", children: [
4070
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
4075
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, agentStrokes, className: "flex-1 rounded-lg" }),
4071
4076
  error && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
4072
4077
  ] }),
4073
4078
  /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
@@ -87,10 +87,11 @@ import {
87
87
  guideOverlay,
88
88
  handlePaintShortcut,
89
89
  viewCssTransform,
90
+ paintAgentStrokePoints,
90
91
  paintProposalGhost
91
92
  } from "@pixerate/editor/paint-editor";
92
93
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
93
- var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, className }) => {
94
+ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount = true, onError, presence, proposals, agentStrokes, className }) => {
94
95
  const state = usePaintEditorState(controller);
95
96
  const viewport = useRef2(null);
96
97
  const canvas = useRef2(null);
@@ -228,6 +229,7 @@ var PaintCanvas = ({ controller, tool = "brush", showGuides = true, fitOnMount =
228
229
  },
229
230
  i
230
231
  )),
232
+ agentStrokes && /* @__PURE__ */ jsx(PaintAgentStrokeLines, { strokes: agentStrokes }),
231
233
  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" })
232
234
  ] }),
233
235
  state.guides.references.filter((r) => r.visible).map((r) => /* @__PURE__ */ jsx(ReferencePanel, { controller, id: r.id }, r.id)),
@@ -334,6 +336,10 @@ var PaintProposalGhost = ({ proposal, transform, zoom }) => {
334
336
  }
335
337
  );
336
338
  };
339
+ var PaintAgentStrokeLines = ({ strokes }) => {
340
+ const { strokes: list } = useSyncExternalStore2(strokes.subscribe, strokes.getState, strokes.getState);
341
+ return /* @__PURE__ */ jsx(Fragment, { children: list.map((s) => /* @__PURE__ */ jsx("polyline", { "data-agent-stroke": s.id, points: paintAgentStrokePoints(s), fill: "none", stroke: s.color, strokeOpacity: s.opacity ?? 0.6, strokeWidth: s.size, strokeLinecap: "round", strokeLinejoin: "round" }, s.id)) });
342
+ };
337
343
 
338
344
  // src/paint-editor/PaintToolbar.tsx
339
345
  import { useRef as useRef4, useState as useState4 } from "react";
@@ -1675,7 +1681,7 @@ var PAINT_CONTROLS = {
1675
1681
  lighting: '[data-testid="light-panel"]',
1676
1682
  symmetry: '[aria-label="Symmetry"]'
1677
1683
  };
1678
- var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, className, playback, playbackId = "paint", onPlaybackReveal }) => {
1684
+ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, agentStrokes, className, playback, playbackId = "paint", onPlaybackReveal }) => {
1679
1685
  const [tool, setTool] = useState10("brush");
1680
1686
  const [tab, setTab] = useState10("color");
1681
1687
  const tabRef = useRef8(tab);
@@ -1746,7 +1752,7 @@ var PaintEditor = ({ controller, fileName, height = 720, presence, proposals, cl
1746
1752
  /* @__PURE__ */ jsxs14("div", { className: "flex min-h-0 flex-1 gap-2", children: [
1747
1753
  /* @__PURE__ */ jsx15(BrushPanel, { controller, className: "w-60 shrink-0 overflow-y-auto pr-1" }),
1748
1754
  /* @__PURE__ */ jsxs14("div", { className: "flex min-w-0 flex-1 flex-col", children: [
1749
- /* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, className: "flex-1 rounded-lg" }),
1755
+ /* @__PURE__ */ jsx15(PaintCanvas, { controller, tool, onError: setError, presence: playing ? void 0 : presence, proposals, agentStrokes, className: "flex-1 rounded-lg" }),
1750
1756
  error && /* @__PURE__ */ jsx15("p", { role: "alert", className: "mt-1 text-[11px] text-rose-400", children: error })
1751
1757
  ] }),
1752
1758
  /* @__PURE__ */ jsxs14("div", { className: "flex w-64 shrink-0 flex-col gap-2 overflow-y-auto pr-1", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.175.0",
3
+ "version": "0.177.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.257.0 <1.0.0-0",
280
+ "@pixerate/editor": ">=0.260.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.257.0"
331
+ "@pixerate/editor": "0.260.0"
332
332
  },
333
333
  "scripts": {
334
334
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",