canvu-react 0.4.58 → 0.4.60

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.
@@ -179,6 +179,29 @@ type SelectModeItemClickDetail = {
179
179
  /** Set the viewport selection when activation should also select or clear. */
180
180
  setSelectedIds: (ids: readonly string[]) => void;
181
181
  };
182
+ /**
183
+ * Best-effort reason attached to a React viewport item change.
184
+ *
185
+ * Middleware and `onItemsChange` consumers can use this to distinguish user
186
+ * actions such as deletion, erasing, placement, or text editing without
187
+ * diffing item snapshots themselves. Metadata may be omitted by legacy callers
188
+ * or by integrations that update items outside canvu's built-in interactions.
189
+ */
190
+ type VectorItemsChangeMotive = "draw" | "place" | "text-create" | "text-edit" | "asset-add" | "asset-hydrate" | "move" | "resize" | "rotate" | "style" | "delete" | "erase" | "cut" | "paste" | "duplicate" | "lock" | "unlock" | "reorder" | "undo" | "redo" | "custom" | "remote-sync" | "plugin" | "unknown";
191
+ /**
192
+ * Optional metadata passed alongside a React viewport item change.
193
+ *
194
+ * The payload is intentionally small and stable: `motive` describes the action
195
+ * class, `itemIds` identifies the primary affected items when known, and
196
+ * `toolId` records the active tool for placement or drawing flows. Treat this
197
+ * as advisory metadata; absence means the change came from legacy code or an
198
+ * external source that did not provide a motive.
199
+ */
200
+ type VectorItemsChangeInfo = {
201
+ motive: VectorItemsChangeMotive;
202
+ itemIds?: readonly string[];
203
+ toolId?: string;
204
+ };
182
205
  /**
183
206
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
184
207
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -246,7 +269,15 @@ type VectorViewportProps = {
246
269
  /** Selected item ids (order preserved). Empty = none. */
247
270
  selectedIds?: readonly string[];
248
271
  onSelectionChange?: (ids: string[]) => void;
249
- onItemsChange?: (items: VectorSceneItem[]) => void;
272
+ /**
273
+ * Called when the React viewport requests a replacement item list.
274
+ *
275
+ * `info` is best-effort action metadata for middleware and app code that
276
+ * needs to know whether the change was a deletion, placement, move, etc.
277
+ * Existing one-argument handlers remain valid, and callers outside canvu may
278
+ * omit `info`.
279
+ */
280
+ onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
250
281
  /**
251
282
  * Fires when a link/bookmark item is activated (double-click / double-tap).
252
283
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -368,7 +399,7 @@ type CanvasPluginRenderContext = {
368
399
  type CanvasPluginItemsChangeMiddlewareContext = {
369
400
  /** Current board items before the pending change is applied. */
370
401
  currentItems: readonly VectorSceneItem[];
371
- /** Continue the item change pipeline. */
402
+ /** Continue the item change pipeline. Forward `info` when preserving motive metadata. */
372
403
  next: NonNullable<VectorViewportProps["onItemsChange"]>;
373
404
  /** Original consumer callback passed to `VectorViewport`. */
374
405
  consumerOnItemsChange?: VectorViewportProps["onItemsChange"];
@@ -387,7 +418,7 @@ type CanvasPluginContribution = {
387
418
  /** Event callbacks chained into the viewport without manual wiring in app code. */
388
419
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
389
420
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
390
- wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext) => void;
421
+ wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
391
422
  };
392
423
  type CanvasPluginComponentProps = {
393
424
  /** Stable plugin id so the component can register contributions. */
@@ -467,4 +498,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
467
498
  */
468
499
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
469
500
 
470
- export { useCanvuViewportContext as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorSelectionInspectorProps as p, VectorViewport as q, type VectorViewportHandle as r, type VectorViewportProps as s, createCanvuPlugin as t, getBoardPositionStyle as u, useCanvuChromeContext as v, useCanvuDocumentContext as w, useCanvuPluginContext as x, useCanvuPluginContribution as y, useCanvuResolvedTools as z };
501
+ export { useCanvuPluginContribution as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, useCanvuResolvedTools as D, useCanvuViewportContext as E, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorItemsChangeInfo as p, type VectorItemsChangeMotive as q, type VectorSelectionInspectorProps as r, VectorViewport as s, type VectorViewportHandle as t, type VectorViewportProps as u, createCanvuPlugin as v, getBoardPositionStyle as w, useCanvuChromeContext as x, useCanvuDocumentContext as y, useCanvuPluginContext as z };
@@ -179,6 +179,29 @@ type SelectModeItemClickDetail = {
179
179
  /** Set the viewport selection when activation should also select or clear. */
180
180
  setSelectedIds: (ids: readonly string[]) => void;
181
181
  };
182
+ /**
183
+ * Best-effort reason attached to a React viewport item change.
184
+ *
185
+ * Middleware and `onItemsChange` consumers can use this to distinguish user
186
+ * actions such as deletion, erasing, placement, or text editing without
187
+ * diffing item snapshots themselves. Metadata may be omitted by legacy callers
188
+ * or by integrations that update items outside canvu's built-in interactions.
189
+ */
190
+ type VectorItemsChangeMotive = "draw" | "place" | "text-create" | "text-edit" | "asset-add" | "asset-hydrate" | "move" | "resize" | "rotate" | "style" | "delete" | "erase" | "cut" | "paste" | "duplicate" | "lock" | "unlock" | "reorder" | "undo" | "redo" | "custom" | "remote-sync" | "plugin" | "unknown";
191
+ /**
192
+ * Optional metadata passed alongside a React viewport item change.
193
+ *
194
+ * The payload is intentionally small and stable: `motive` describes the action
195
+ * class, `itemIds` identifies the primary affected items when known, and
196
+ * `toolId` records the active tool for placement or drawing flows. Treat this
197
+ * as advisory metadata; absence means the change came from legacy code or an
198
+ * external source that did not provide a motive.
199
+ */
200
+ type VectorItemsChangeInfo = {
201
+ motive: VectorItemsChangeMotive;
202
+ itemIds?: readonly string[];
203
+ toolId?: string;
204
+ };
182
205
  /**
183
206
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
184
207
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -246,7 +269,15 @@ type VectorViewportProps = {
246
269
  /** Selected item ids (order preserved). Empty = none. */
247
270
  selectedIds?: readonly string[];
248
271
  onSelectionChange?: (ids: string[]) => void;
249
- onItemsChange?: (items: VectorSceneItem[]) => void;
272
+ /**
273
+ * Called when the React viewport requests a replacement item list.
274
+ *
275
+ * `info` is best-effort action metadata for middleware and app code that
276
+ * needs to know whether the change was a deletion, placement, move, etc.
277
+ * Existing one-argument handlers remain valid, and callers outside canvu may
278
+ * omit `info`.
279
+ */
280
+ onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
250
281
  /**
251
282
  * Fires when a link/bookmark item is activated (double-click / double-tap).
252
283
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -368,7 +399,7 @@ type CanvasPluginRenderContext = {
368
399
  type CanvasPluginItemsChangeMiddlewareContext = {
369
400
  /** Current board items before the pending change is applied. */
370
401
  currentItems: readonly VectorSceneItem[];
371
- /** Continue the item change pipeline. */
402
+ /** Continue the item change pipeline. Forward `info` when preserving motive metadata. */
372
403
  next: NonNullable<VectorViewportProps["onItemsChange"]>;
373
404
  /** Original consumer callback passed to `VectorViewport`. */
374
405
  consumerOnItemsChange?: VectorViewportProps["onItemsChange"];
@@ -387,7 +418,7 @@ type CanvasPluginContribution = {
387
418
  /** Event callbacks chained into the viewport without manual wiring in app code. */
388
419
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
389
420
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
390
- wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext) => void;
421
+ wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
391
422
  };
392
423
  type CanvasPluginComponentProps = {
393
424
  /** Stable plugin id so the component can register contributions. */
@@ -467,4 +498,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
467
498
  */
468
499
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
469
500
 
470
- export { useCanvuViewportContext as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorSelectionInspectorProps as p, VectorViewport as q, type VectorViewportHandle as r, type VectorViewportProps as s, createCanvuPlugin as t, getBoardPositionStyle as u, useCanvuChromeContext as v, useCanvuDocumentContext as w, useCanvuPluginContext as x, useCanvuPluginContribution as y, useCanvuResolvedTools as z };
501
+ export { useCanvuPluginContribution as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, useCanvuResolvedTools as D, useCanvuViewportContext as E, type PlacementPreview as P, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvasPlugin as a, VectorSelectionInspector as b, type CanvasPluginComponentProps as c, type CanvasPluginContribution as d, type CanvasPluginItemsChangeMiddlewareContext as e, type CanvasPluginRenderContext as f, type CanvuChromeActiveToolStyle as g, CanvuChromeContext as h, type CanvuChromeContextValue as i, type CanvuChromeSelectionStyleChange as j, CanvuPluginContext as k, type CanvuPluginContextValue as l, type CanvuPluginViewportSnapshot as m, type SelectModeItemClickResult as n, type VectorCanvasSpacePosition as o, type VectorItemsChangeInfo as p, type VectorItemsChangeMotive as q, type VectorSelectionInspectorProps as r, VectorViewport as s, type VectorViewportHandle as t, type VectorViewportProps as u, createCanvuPlugin as v, getBoardPositionStyle as w, useCanvuChromeContext as x, useCanvuDocumentContext as y, useCanvuPluginContext as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvu-react",
3
- "version": "0.4.58",
3
+ "version": "0.4.60",
4
4
  "description": "Vector-first infinite canvas (SVG) with pan, zoom, React bindings, and optional plugins",
5
5
  "license": "MIT",
6
6
  "type": "module",