canvu-react 0.4.63 → 0.4.65

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.
@@ -118,6 +118,36 @@ type VectorToolDefinition = {
118
118
  ariaLabel?: string;
119
119
  };
120
120
 
121
+ type ReadOnlyItemClickCandidateDetail = {
122
+ /** The item Canvu hit-tested under the read-only click. */
123
+ item: VectorSceneItem;
124
+ /** World-space pointer location at press time. */
125
+ worldX: number;
126
+ worldY: number;
127
+ /** Viewport/client pointer location at press time. */
128
+ clientX: number;
129
+ clientY: number;
130
+ pointerType: string;
131
+ shiftKey: boolean;
132
+ altKey: boolean;
133
+ metaKey: boolean;
134
+ ctrlKey: boolean;
135
+ /** Current viewport items. */
136
+ items: readonly VectorSceneItem[];
137
+ /** Selection snapshot before read-only activation handles the click. */
138
+ selectedIds: readonly string[];
139
+ };
140
+ /**
141
+ * Controls which items may receive select-mode click activation while
142
+ * `VectorViewport` is read-only (`interactive={false}`).
143
+ *
144
+ * `"custom"` keeps the default high-level behavior: custom placement/tool
145
+ * items with `onSelectModeItemClick` remain clickable, while regular items do
146
+ * not become selectable unless the app opts in. Use `"all"` or a predicate for
147
+ * read-only viewers that still need item selection or item-specific side effects.
148
+ */
149
+ type ReadOnlyItemClickScope = "custom" | "all" | ((detail: ReadOnlyItemClickCandidateDetail) => boolean);
150
+
121
151
  type ActiveToolStyle = StrokeStyle & {
122
152
  toolKind: "draw" | "marker" | "text" | "rect" | "ellipse" | "architectural-cloud" | "line" | "arrow";
123
153
  label?: string;
@@ -179,6 +209,47 @@ type SelectModeItemClickDetail = {
179
209
  /** Set the viewport selection when activation should also select or clear. */
180
210
  setSelectedIds: (ids: readonly string[]) => void;
181
211
  };
212
+
213
+ /**
214
+ * Read-only interaction exceptions for viewers that should stay immutable while
215
+ * still allowing explicit activation/selection clicks.
216
+ *
217
+ * Canvu-owned editing remains disabled: no placement, draw, move, resize,
218
+ * rotate, eraser, paste/drop mutation, text editing, handles, or inspector.
219
+ * Explicit user callbacks may still call `updateItem` when that is the desired
220
+ * app-level exception.
221
+ *
222
+ * @example
223
+ * ```tsx
224
+ * <VectorViewport
225
+ * interactive={false}
226
+ * readOnlyInteraction={{
227
+ * itemClicks: "all",
228
+ * onItemClick: ({ item, setSelectedIds }) => {
229
+ * setSelectedIds([item.id]);
230
+ * return "handled";
231
+ * },
232
+ * }}
233
+ * />
234
+ * ```
235
+ */
236
+ type ReadOnlyInteractionOptions = {
237
+ /**
238
+ * Which read-only item clicks Canvu should capture.
239
+ *
240
+ * Defaults to `"custom"`, which only activates custom placement/tool items
241
+ * that provide `onSelectModeItemClick`.
242
+ */
243
+ itemClicks?: ReadOnlyItemClickScope;
244
+ /**
245
+ * Optional handler for read-only item clicks enabled by `itemClicks`.
246
+ *
247
+ * Custom placement `onSelectModeItemClick` handlers run first for their own
248
+ * items. For non-custom opt-in clicks, returning `undefined` lets Canvu apply
249
+ * default read-only selection semantics.
250
+ */
251
+ onItemClick?: (detail: SelectModeItemClickDetail) => SelectModeItemClickResult;
252
+ };
182
253
  /**
183
254
  * Best-effort reason attached to a React viewport item change.
184
255
  *
@@ -202,6 +273,101 @@ type VectorItemsChangeInfo = {
202
273
  itemIds?: readonly string[];
203
274
  toolId?: string;
204
275
  };
276
+ /**
277
+ * Interaction categories emitted by the React viewport lifecycle hooks.
278
+ *
279
+ * These describe pointer gestures owned by `VectorViewport`, not every possible
280
+ * input event. Camera pan/zoom, keyboard shortcuts, paste/drop, toolbar clicks,
281
+ * and custom UI events are intentionally outside this lifecycle.
282
+ */
283
+ type CanvuInteractionKind = "move" | "resize" | "rotate" | "marquee" | "stroke" | "erase" | "tap" | "place" | "select-mode-item-click";
284
+ /**
285
+ * World and client coordinates for a viewport interaction sample.
286
+ *
287
+ * `start` stays fixed for the accepted gesture. `current` is updated for the
288
+ * after hook so integrations can compare where the gesture began and ended.
289
+ */
290
+ type CanvuInteractionPoint = {
291
+ readonly worldX: number;
292
+ readonly worldY: number;
293
+ readonly clientX: number;
294
+ readonly clientY: number;
295
+ };
296
+ /**
297
+ * Stable interaction metadata passed to before/after interaction hooks.
298
+ *
299
+ * Use this for custom tool behavior that needs to observe or claim a viewport
300
+ * gesture before Canvu mutates selection, previews, or items. Do not use it to
301
+ * intercept item-list writes; use `wrapOnItemsChange` when you need exact
302
+ * document mutation middleware.
303
+ *
304
+ * @example
305
+ * ```tsx
306
+ * <VectorViewport
307
+ * onBeforeInteraction={(detail) =>
308
+ * detail.toolId === "review-pin" ? "handled" : undefined
309
+ * }
310
+ * />
311
+ * ```
312
+ */
313
+ type CanvuInteractionDetail = {
314
+ /** Stable id for this accepted pointer gesture. */
315
+ readonly interactionId: string;
316
+ /** Canvu interaction category resolved before built-in state changes. */
317
+ readonly kind: CanvuInteractionKind;
318
+ /** Active viewport tool when the gesture started. */
319
+ readonly toolId: string;
320
+ /** Browser pointer type such as `"mouse"`, `"pen"`, or `"touch"`. */
321
+ readonly pointerType: string;
322
+ /** Pointer button reported by the start event. Touch fallbacks use `0`. */
323
+ readonly button: number;
324
+ readonly shiftKey: boolean;
325
+ readonly altKey: boolean;
326
+ readonly metaKey: boolean;
327
+ readonly ctrlKey: boolean;
328
+ /** Pointer position when the interaction started. */
329
+ readonly start: CanvuInteractionPoint;
330
+ /** Latest pointer position known to Canvu for this interaction. */
331
+ readonly current: CanvuInteractionPoint;
332
+ /** Selection snapshot before Canvu applies this interaction. */
333
+ readonly selectedIds: readonly string[];
334
+ /** Primary target item ids when the interaction has known targets. */
335
+ readonly itemIds: readonly string[];
336
+ /** Current viewport items when the interaction was accepted. */
337
+ readonly items: readonly VectorSceneItem[];
338
+ };
339
+ /** Return value that lets a before hook claim a gesture. */
340
+ type CanvuBeforeInteractionResult = "handled" | undefined;
341
+ /**
342
+ * Runs after Canvu resolves an interaction kind and before built-in mutation.
343
+ *
344
+ * Return `"handled"` to claim the gesture. Canvu will prevent the pointer event,
345
+ * skip later before hooks, skip built-in behavior, and will not emit an after
346
+ * hook for that gesture.
347
+ */
348
+ type CanvuBeforeInteractionHook = (detail: CanvuInteractionDetail) => CanvuBeforeInteractionResult;
349
+ /** Final state reported when an accepted interaction leaves Canvu's active state. */
350
+ type CanvuInteractionOutcome = "completed" | "cancelled";
351
+ /**
352
+ * Metadata passed to after interaction hooks.
353
+ *
354
+ * `info` mirrors the best-effort `VectorItemsChangeInfo` used by
355
+ * `onItemsChange`; it is intentionally advisory and may be omitted when the
356
+ * gesture did not write items.
357
+ */
358
+ type CanvuAfterInteractionDetail = CanvuInteractionDetail & {
359
+ readonly outcome: CanvuInteractionOutcome;
360
+ readonly info?: VectorItemsChangeInfo;
361
+ };
362
+ /**
363
+ * Runs once when an accepted Canvu interaction completes or is cancelled.
364
+ *
365
+ * Use this for analytics, custom UI cleanup, or tool-specific side effects that
366
+ * should happen after Canvu's gesture lifecycle finishes. Use
367
+ * `wrapOnItemsChange` instead when you need to transform or persist item
368
+ * mutations.
369
+ */
370
+ type CanvuAfterInteractionHook = (detail: CanvuAfterInteractionDetail) => void;
205
371
  /**
206
372
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
207
373
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -243,8 +409,10 @@ type CustomShapePlacementOptions = {
243
409
  * Optional select-mode click handler for items created by this placement.
244
410
  *
245
411
  * If provided, a plain click on the item in select mode calls this handler instead
246
- * of selecting or moving the item. Resize and rotate handles still win first, and
247
- * dragging past the tap threshold falls back to normal move behavior.
412
+ * of selecting or moving the item. Resize and rotate handles still win first in
413
+ * interactive viewports, and dragging past the tap threshold falls back to normal
414
+ * move behavior. In read-only viewports, the same click still activates the item
415
+ * by default, while dragging past the tap threshold cancels activation.
248
416
  */
249
417
  onSelectModeItemClick?: (detail: SelectModeItemClickDetail) => SelectModeItemClickResult;
250
418
  };
@@ -266,6 +434,15 @@ type VectorViewportProps = {
266
434
  * Requires `onItemsChange` to persist mutations.
267
435
  */
268
436
  interactive?: boolean;
437
+ /**
438
+ * Read-only click exceptions used when `interactive` is false.
439
+ *
440
+ * By default, read-only viewports still allow custom placement/tool items
441
+ * with `onSelectModeItemClick` to activate. Opt into `"all"` or a predicate
442
+ * when a read-only viewer should also allow regular item selection/clicks.
443
+ * Canvu-owned editing stays disabled; only explicit callbacks may mutate.
444
+ */
445
+ readOnlyInteraction?: ReadOnlyInteractionOptions;
269
446
  /** Selected item ids (order preserved). Empty = none. */
270
447
  selectedIds?: readonly string[];
271
448
  onSelectionChange?: (ids: string[]) => void;
@@ -278,6 +455,24 @@ type VectorViewportProps = {
278
455
  * omit `info`.
279
456
  */
280
457
  onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
458
+ /**
459
+ * Runs before a Canvu-owned pointer interaction mutates viewport state.
460
+ *
461
+ * Return `"handled"` to claim the gesture and prevent Canvu's built-in
462
+ * selection, drawing, placement, or resize behavior for that pointerdown.
463
+ * Prefer this for custom tool behavior. Prefer `wrapOnItemsChange` when your
464
+ * integration needs document mutation middleware instead.
465
+ */
466
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
467
+ /**
468
+ * Runs once after an accepted Canvu-owned pointer interaction completes or is
469
+ * cancelled.
470
+ *
471
+ * This is useful for analytics, custom tool cleanup, and UI side effects.
472
+ * The optional `info` payload is best-effort mutation metadata; continue to use
473
+ * `wrapOnItemsChange` for exact item-list interception.
474
+ */
475
+ onAfterInteraction?: CanvuAfterInteractionHook;
281
476
  /**
282
477
  * Fires when a link/bookmark item is activated (double-click / double-tap).
283
478
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -417,6 +612,19 @@ type CanvasPluginContribution = {
417
612
  viewportProps?: Partial<Pick<VectorViewportProps, "remotePresence" | "presenceOverlay">>;
418
613
  /** Event callbacks chained into the viewport without manual wiring in app code. */
419
614
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
615
+ /**
616
+ * Hooks around Canvu-owned pointer interactions.
617
+ *
618
+ * Use these for custom tool behavior that needs to observe or claim a gesture
619
+ * before the viewport mutates state. Use `wrapOnItemsChange` for exact item
620
+ * mutation middleware.
621
+ */
622
+ interactionHooks?: {
623
+ /** Return `"handled"` to claim the gesture and skip Canvu's built-in behavior. */
624
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
625
+ /** Runs once when an accepted gesture completes or is cancelled. */
626
+ onAfterInteraction?: CanvuAfterInteractionHook;
627
+ };
420
628
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
421
629
  wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
422
630
  };
@@ -498,4 +706,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
498
706
  */
499
707
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
500
708
 
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 };
709
+ export { type VectorItemsChangeMotive as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type VectorSelectionInspectorProps as D, VectorViewport as E, type VectorViewportHandle as F, type VectorViewportProps as G, createCanvuPlugin as H, getBoardPositionStyle as I, useCanvuChromeContext as J, useCanvuDocumentContext as K, useCanvuPluginContext as L, useCanvuPluginContribution as M, useCanvuResolvedTools as N, useCanvuViewportContext as O, type PlacementPreview as P, type ReadOnlyInteractionOptions as R, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvuBeforeInteractionHook as a, type CanvuAfterInteractionHook as b, type CanvasPlugin as c, VectorSelectionInspector as d, type CanvasPluginComponentProps as e, type CanvasPluginContribution as f, type CanvasPluginItemsChangeMiddlewareContext as g, type CanvasPluginRenderContext as h, type CanvuAfterInteractionDetail as i, type CanvuBeforeInteractionResult as j, type CanvuChromeActiveToolStyle as k, CanvuChromeContext as l, type CanvuChromeContextValue as m, type CanvuChromeSelectionStyleChange as n, type CanvuInteractionDetail as o, type CanvuInteractionKind as p, type CanvuInteractionOutcome as q, type CanvuInteractionPoint as r, CanvuPluginContext as s, type CanvuPluginContextValue as t, type CanvuPluginViewportSnapshot as u, type ReadOnlyItemClickCandidateDetail as v, type ReadOnlyItemClickScope as w, type SelectModeItemClickResult as x, type VectorCanvasSpacePosition as y, type VectorItemsChangeInfo as z };
@@ -118,6 +118,36 @@ type VectorToolDefinition = {
118
118
  ariaLabel?: string;
119
119
  };
120
120
 
121
+ type ReadOnlyItemClickCandidateDetail = {
122
+ /** The item Canvu hit-tested under the read-only click. */
123
+ item: VectorSceneItem;
124
+ /** World-space pointer location at press time. */
125
+ worldX: number;
126
+ worldY: number;
127
+ /** Viewport/client pointer location at press time. */
128
+ clientX: number;
129
+ clientY: number;
130
+ pointerType: string;
131
+ shiftKey: boolean;
132
+ altKey: boolean;
133
+ metaKey: boolean;
134
+ ctrlKey: boolean;
135
+ /** Current viewport items. */
136
+ items: readonly VectorSceneItem[];
137
+ /** Selection snapshot before read-only activation handles the click. */
138
+ selectedIds: readonly string[];
139
+ };
140
+ /**
141
+ * Controls which items may receive select-mode click activation while
142
+ * `VectorViewport` is read-only (`interactive={false}`).
143
+ *
144
+ * `"custom"` keeps the default high-level behavior: custom placement/tool
145
+ * items with `onSelectModeItemClick` remain clickable, while regular items do
146
+ * not become selectable unless the app opts in. Use `"all"` or a predicate for
147
+ * read-only viewers that still need item selection or item-specific side effects.
148
+ */
149
+ type ReadOnlyItemClickScope = "custom" | "all" | ((detail: ReadOnlyItemClickCandidateDetail) => boolean);
150
+
121
151
  type ActiveToolStyle = StrokeStyle & {
122
152
  toolKind: "draw" | "marker" | "text" | "rect" | "ellipse" | "architectural-cloud" | "line" | "arrow";
123
153
  label?: string;
@@ -179,6 +209,47 @@ type SelectModeItemClickDetail = {
179
209
  /** Set the viewport selection when activation should also select or clear. */
180
210
  setSelectedIds: (ids: readonly string[]) => void;
181
211
  };
212
+
213
+ /**
214
+ * Read-only interaction exceptions for viewers that should stay immutable while
215
+ * still allowing explicit activation/selection clicks.
216
+ *
217
+ * Canvu-owned editing remains disabled: no placement, draw, move, resize,
218
+ * rotate, eraser, paste/drop mutation, text editing, handles, or inspector.
219
+ * Explicit user callbacks may still call `updateItem` when that is the desired
220
+ * app-level exception.
221
+ *
222
+ * @example
223
+ * ```tsx
224
+ * <VectorViewport
225
+ * interactive={false}
226
+ * readOnlyInteraction={{
227
+ * itemClicks: "all",
228
+ * onItemClick: ({ item, setSelectedIds }) => {
229
+ * setSelectedIds([item.id]);
230
+ * return "handled";
231
+ * },
232
+ * }}
233
+ * />
234
+ * ```
235
+ */
236
+ type ReadOnlyInteractionOptions = {
237
+ /**
238
+ * Which read-only item clicks Canvu should capture.
239
+ *
240
+ * Defaults to `"custom"`, which only activates custom placement/tool items
241
+ * that provide `onSelectModeItemClick`.
242
+ */
243
+ itemClicks?: ReadOnlyItemClickScope;
244
+ /**
245
+ * Optional handler for read-only item clicks enabled by `itemClicks`.
246
+ *
247
+ * Custom placement `onSelectModeItemClick` handlers run first for their own
248
+ * items. For non-custom opt-in clicks, returning `undefined` lets Canvu apply
249
+ * default read-only selection semantics.
250
+ */
251
+ onItemClick?: (detail: SelectModeItemClickDetail) => SelectModeItemClickResult;
252
+ };
182
253
  /**
183
254
  * Best-effort reason attached to a React viewport item change.
184
255
  *
@@ -202,6 +273,101 @@ type VectorItemsChangeInfo = {
202
273
  itemIds?: readonly string[];
203
274
  toolId?: string;
204
275
  };
276
+ /**
277
+ * Interaction categories emitted by the React viewport lifecycle hooks.
278
+ *
279
+ * These describe pointer gestures owned by `VectorViewport`, not every possible
280
+ * input event. Camera pan/zoom, keyboard shortcuts, paste/drop, toolbar clicks,
281
+ * and custom UI events are intentionally outside this lifecycle.
282
+ */
283
+ type CanvuInteractionKind = "move" | "resize" | "rotate" | "marquee" | "stroke" | "erase" | "tap" | "place" | "select-mode-item-click";
284
+ /**
285
+ * World and client coordinates for a viewport interaction sample.
286
+ *
287
+ * `start` stays fixed for the accepted gesture. `current` is updated for the
288
+ * after hook so integrations can compare where the gesture began and ended.
289
+ */
290
+ type CanvuInteractionPoint = {
291
+ readonly worldX: number;
292
+ readonly worldY: number;
293
+ readonly clientX: number;
294
+ readonly clientY: number;
295
+ };
296
+ /**
297
+ * Stable interaction metadata passed to before/after interaction hooks.
298
+ *
299
+ * Use this for custom tool behavior that needs to observe or claim a viewport
300
+ * gesture before Canvu mutates selection, previews, or items. Do not use it to
301
+ * intercept item-list writes; use `wrapOnItemsChange` when you need exact
302
+ * document mutation middleware.
303
+ *
304
+ * @example
305
+ * ```tsx
306
+ * <VectorViewport
307
+ * onBeforeInteraction={(detail) =>
308
+ * detail.toolId === "review-pin" ? "handled" : undefined
309
+ * }
310
+ * />
311
+ * ```
312
+ */
313
+ type CanvuInteractionDetail = {
314
+ /** Stable id for this accepted pointer gesture. */
315
+ readonly interactionId: string;
316
+ /** Canvu interaction category resolved before built-in state changes. */
317
+ readonly kind: CanvuInteractionKind;
318
+ /** Active viewport tool when the gesture started. */
319
+ readonly toolId: string;
320
+ /** Browser pointer type such as `"mouse"`, `"pen"`, or `"touch"`. */
321
+ readonly pointerType: string;
322
+ /** Pointer button reported by the start event. Touch fallbacks use `0`. */
323
+ readonly button: number;
324
+ readonly shiftKey: boolean;
325
+ readonly altKey: boolean;
326
+ readonly metaKey: boolean;
327
+ readonly ctrlKey: boolean;
328
+ /** Pointer position when the interaction started. */
329
+ readonly start: CanvuInteractionPoint;
330
+ /** Latest pointer position known to Canvu for this interaction. */
331
+ readonly current: CanvuInteractionPoint;
332
+ /** Selection snapshot before Canvu applies this interaction. */
333
+ readonly selectedIds: readonly string[];
334
+ /** Primary target item ids when the interaction has known targets. */
335
+ readonly itemIds: readonly string[];
336
+ /** Current viewport items when the interaction was accepted. */
337
+ readonly items: readonly VectorSceneItem[];
338
+ };
339
+ /** Return value that lets a before hook claim a gesture. */
340
+ type CanvuBeforeInteractionResult = "handled" | undefined;
341
+ /**
342
+ * Runs after Canvu resolves an interaction kind and before built-in mutation.
343
+ *
344
+ * Return `"handled"` to claim the gesture. Canvu will prevent the pointer event,
345
+ * skip later before hooks, skip built-in behavior, and will not emit an after
346
+ * hook for that gesture.
347
+ */
348
+ type CanvuBeforeInteractionHook = (detail: CanvuInteractionDetail) => CanvuBeforeInteractionResult;
349
+ /** Final state reported when an accepted interaction leaves Canvu's active state. */
350
+ type CanvuInteractionOutcome = "completed" | "cancelled";
351
+ /**
352
+ * Metadata passed to after interaction hooks.
353
+ *
354
+ * `info` mirrors the best-effort `VectorItemsChangeInfo` used by
355
+ * `onItemsChange`; it is intentionally advisory and may be omitted when the
356
+ * gesture did not write items.
357
+ */
358
+ type CanvuAfterInteractionDetail = CanvuInteractionDetail & {
359
+ readonly outcome: CanvuInteractionOutcome;
360
+ readonly info?: VectorItemsChangeInfo;
361
+ };
362
+ /**
363
+ * Runs once when an accepted Canvu interaction completes or is cancelled.
364
+ *
365
+ * Use this for analytics, custom UI cleanup, or tool-specific side effects that
366
+ * should happen after Canvu's gesture lifecycle finishes. Use
367
+ * `wrapOnItemsChange` instead when you need to transform or persist item
368
+ * mutations.
369
+ */
370
+ type CanvuAfterInteractionHook = (detail: CanvuAfterInteractionDetail) => void;
205
371
  /**
206
372
  * Imperative API for pan/zoom and integrations (e.g. AI agents following a region).
207
373
  * Call {@link requestRender} after mutating the {@link Camera2D} from {@link getCamera}.
@@ -243,8 +409,10 @@ type CustomShapePlacementOptions = {
243
409
  * Optional select-mode click handler for items created by this placement.
244
410
  *
245
411
  * If provided, a plain click on the item in select mode calls this handler instead
246
- * of selecting or moving the item. Resize and rotate handles still win first, and
247
- * dragging past the tap threshold falls back to normal move behavior.
412
+ * of selecting or moving the item. Resize and rotate handles still win first in
413
+ * interactive viewports, and dragging past the tap threshold falls back to normal
414
+ * move behavior. In read-only viewports, the same click still activates the item
415
+ * by default, while dragging past the tap threshold cancels activation.
248
416
  */
249
417
  onSelectModeItemClick?: (detail: SelectModeItemClickDetail) => SelectModeItemClickResult;
250
418
  };
@@ -266,6 +434,15 @@ type VectorViewportProps = {
266
434
  * Requires `onItemsChange` to persist mutations.
267
435
  */
268
436
  interactive?: boolean;
437
+ /**
438
+ * Read-only click exceptions used when `interactive` is false.
439
+ *
440
+ * By default, read-only viewports still allow custom placement/tool items
441
+ * with `onSelectModeItemClick` to activate. Opt into `"all"` or a predicate
442
+ * when a read-only viewer should also allow regular item selection/clicks.
443
+ * Canvu-owned editing stays disabled; only explicit callbacks may mutate.
444
+ */
445
+ readOnlyInteraction?: ReadOnlyInteractionOptions;
269
446
  /** Selected item ids (order preserved). Empty = none. */
270
447
  selectedIds?: readonly string[];
271
448
  onSelectionChange?: (ids: string[]) => void;
@@ -278,6 +455,24 @@ type VectorViewportProps = {
278
455
  * omit `info`.
279
456
  */
280
457
  onItemsChange?: (items: VectorSceneItem[], info?: VectorItemsChangeInfo) => void;
458
+ /**
459
+ * Runs before a Canvu-owned pointer interaction mutates viewport state.
460
+ *
461
+ * Return `"handled"` to claim the gesture and prevent Canvu's built-in
462
+ * selection, drawing, placement, or resize behavior for that pointerdown.
463
+ * Prefer this for custom tool behavior. Prefer `wrapOnItemsChange` when your
464
+ * integration needs document mutation middleware instead.
465
+ */
466
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
467
+ /**
468
+ * Runs once after an accepted Canvu-owned pointer interaction completes or is
469
+ * cancelled.
470
+ *
471
+ * This is useful for analytics, custom tool cleanup, and UI side effects.
472
+ * The optional `info` payload is best-effort mutation metadata; continue to use
473
+ * `wrapOnItemsChange` for exact item-list interception.
474
+ */
475
+ onAfterInteraction?: CanvuAfterInteractionHook;
281
476
  /**
282
477
  * Fires when a link/bookmark item is activated (double-click / double-tap).
283
478
  * When omitted, the link opens in a new browser tab by default (web only).
@@ -417,6 +612,19 @@ type CanvasPluginContribution = {
417
612
  viewportProps?: Partial<Pick<VectorViewportProps, "remotePresence" | "presenceOverlay">>;
418
613
  /** Event callbacks chained into the viewport without manual wiring in app code. */
419
614
  callbacks?: Partial<Pick<VectorViewportProps, "onWorldPointerDown" | "onWorldPointerMove" | "onWorldPointerLeave" | "onPlacementPreviewChange" | "onCameraChange">>;
615
+ /**
616
+ * Hooks around Canvu-owned pointer interactions.
617
+ *
618
+ * Use these for custom tool behavior that needs to observe or claim a gesture
619
+ * before the viewport mutates state. Use `wrapOnItemsChange` for exact item
620
+ * mutation middleware.
621
+ */
622
+ interactionHooks?: {
623
+ /** Return `"handled"` to claim the gesture and skip Canvu's built-in behavior. */
624
+ onBeforeInteraction?: CanvuBeforeInteractionHook;
625
+ /** Runs once when an accepted gesture completes or is cancelled. */
626
+ onAfterInteraction?: CanvuAfterInteractionHook;
627
+ };
420
628
  /** Middleware around `onItemsChange` for collaboration, comments, persistence, etc. */
421
629
  wrapOnItemsChange?: (nextItems: VectorSceneItem[], ctx: CanvasPluginItemsChangeMiddlewareContext, info?: VectorItemsChangeInfo) => void;
422
630
  };
@@ -498,4 +706,4 @@ declare function useCanvuResolvedTools(): VectorToolDefinition[];
498
706
  */
499
707
  declare function useCanvuPluginContribution(pluginId: string, contribution: CanvasPluginContribution): void;
500
708
 
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 };
709
+ export { type VectorItemsChangeMotive as A, type BoardComponentPosition as B, type CustomShapePlacementOptions as C, type VectorSelectionInspectorProps as D, VectorViewport as E, type VectorViewportHandle as F, type VectorViewportProps as G, createCanvuPlugin as H, getBoardPositionStyle as I, useCanvuChromeContext as J, useCanvuDocumentContext as K, useCanvuPluginContext as L, useCanvuPluginContribution as M, useCanvuResolvedTools as N, useCanvuViewportContext as O, type PlacementPreview as P, type ReadOnlyInteractionOptions as R, type SelectModeItemClickDetail as S, type VectorToolDefinition as V, type WorldPointerDownDetail as W, type CanvuBeforeInteractionHook as a, type CanvuAfterInteractionHook as b, type CanvasPlugin as c, VectorSelectionInspector as d, type CanvasPluginComponentProps as e, type CanvasPluginContribution as f, type CanvasPluginItemsChangeMiddlewareContext as g, type CanvasPluginRenderContext as h, type CanvuAfterInteractionDetail as i, type CanvuBeforeInteractionResult as j, type CanvuChromeActiveToolStyle as k, CanvuChromeContext as l, type CanvuChromeContextValue as m, type CanvuChromeSelectionStyleChange as n, type CanvuInteractionDetail as o, type CanvuInteractionKind as p, type CanvuInteractionOutcome as q, type CanvuInteractionPoint as r, CanvuPluginContext as s, type CanvuPluginContextValue as t, type CanvuPluginViewportSnapshot as u, type ReadOnlyItemClickCandidateDetail as v, type ReadOnlyItemClickScope as w, type SelectModeItemClickResult as x, type VectorCanvasSpacePosition as y, type VectorItemsChangeInfo as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvu-react",
3
- "version": "0.4.63",
3
+ "version": "0.4.65",
4
4
  "description": "Vector-first infinite canvas (SVG) with pan, zoom, React bindings, and optional plugins",
5
5
  "license": "MIT",
6
6
  "type": "module",