@pixerate/editor-react 0.206.0 → 0.208.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 DiagramScene } from '@pixerate/editor/canvas';
2
+ import { type DiagramDrag, type DiagramScene } from '@pixerate/editor/canvas';
3
3
  export interface MermaidFamilySceneProps {
4
4
  /** The family's picture (`useMermaidDiagram().scene`, or `mermaidToScene`). */
5
5
  scene: DiagramScene;
@@ -11,6 +11,12 @@ export interface MermaidFamilySceneProps {
11
11
  onSelect?: (target: string | null, event: React.MouseEvent) => void;
12
12
  /** A mark was double-clicked (rename it with `diagramRenameOp`). */
13
13
  onOpen?: (target: string, event: React.MouseEvent) => void;
14
+ /**
15
+ * Makes marks with a `drag` kind draggable (pass a scene from `withDiagramDragHandles`, as
16
+ * `useMermaidDiagram().scene` is when editable): the node follows the pointer, and the
17
+ * finished drag is reported for `useMermaidDiagram().drop` (or `planDiagramDrag`).
18
+ */
19
+ onDragEnd?: (drag: DiagramDrag) => void;
14
20
  /** Colour of selected marks' outline (default `var(--primary, #2563eb)`). */
15
21
  selectionColor?: string;
16
22
  /** Arrow head colour (default `var(--muted-foreground, #64748b)`). */
@@ -26,4 +32,4 @@ export interface MermaidFamilySceneProps {
26
32
  * one SVG of the scene's marks, sized to the drawing. Clicking a mark selects its node,
27
33
  * edge or group; double-clicking opens it for renaming.
28
34
  */
29
- export declare function MermaidFamilyScene({ scene, padding, interactive, onSelect, onOpen, selectionColor, markerColor, className, style, title }: MermaidFamilySceneProps): React.JSX.Element;
35
+ export declare function MermaidFamilyScene({ scene, padding, interactive, onSelect, onOpen, onDragEnd, selectionColor, markerColor, className, style, title }: MermaidFamilySceneProps): React.JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type DiagramScene } from '@pixerate/editor/canvas';
2
+ import { type DiagramDrag, type DiagramScene } from '@pixerate/editor/canvas';
3
3
  export interface MermaidFamilySceneProps {
4
4
  /** The family's picture (`useMermaidDiagram().scene`, or `mermaidToScene`). */
5
5
  scene: DiagramScene;
@@ -11,6 +11,12 @@ export interface MermaidFamilySceneProps {
11
11
  onSelect?: (target: string | null, event: React.MouseEvent) => void;
12
12
  /** A mark was double-clicked (rename it with `diagramRenameOp`). */
13
13
  onOpen?: (target: string, event: React.MouseEvent) => void;
14
+ /**
15
+ * Makes marks with a `drag` kind draggable (pass a scene from `withDiagramDragHandles`, as
16
+ * `useMermaidDiagram().scene` is when editable): the node follows the pointer, and the
17
+ * finished drag is reported for `useMermaidDiagram().drop` (or `planDiagramDrag`).
18
+ */
19
+ onDragEnd?: (drag: DiagramDrag) => void;
14
20
  /** Colour of selected marks' outline (default `var(--primary, #2563eb)`). */
15
21
  selectionColor?: string;
16
22
  /** Arrow head colour (default `var(--muted-foreground, #64748b)`). */
@@ -26,4 +32,4 @@ export interface MermaidFamilySceneProps {
26
32
  * one SVG of the scene's marks, sized to the drawing. Clicking a mark selects its node,
27
33
  * edge or group; double-clicking opens it for renaming.
28
34
  */
29
- export declare function MermaidFamilyScene({ scene, padding, interactive, onSelect, onOpen, selectionColor, markerColor, className, style, title }: MermaidFamilySceneProps): React.JSX.Element;
35
+ export declare function MermaidFamilyScene({ scene, padding, interactive, onSelect, onOpen, onDragEnd, selectionColor, markerColor, className, style, title }: MermaidFamilySceneProps): React.JSX.Element;
@@ -4998,6 +4998,7 @@ function MermaidFamilyScene({
4998
4998
  interactive = true,
4999
4999
  onSelect,
5000
5000
  onOpen,
5001
+ onDragEnd,
5001
5002
  selectionColor = "var(--primary, #2563eb)",
5002
5003
  markerColor = "var(--muted-foreground, #64748b)",
5003
5004
  className = "",
@@ -5005,6 +5006,41 @@ function MermaidFamilyScene({
5005
5006
  title
5006
5007
  }) {
5007
5008
  const uid = (0, import_react38.useId)().replace(/:/g, "");
5009
+ const svgRef = (0, import_react38.useRef)(null);
5010
+ const [drag, setDrag] = (0, import_react38.useState)(null);
5011
+ const dragged = (0, import_react38.useRef)(false);
5012
+ const toScene = (event) => {
5013
+ const ctm = svgRef.current?.getScreenCTM?.();
5014
+ if (!ctm) return [event.clientX, event.clientY];
5015
+ const p = new DOMPoint(event.clientX, event.clientY).matrixTransform(ctm.inverse());
5016
+ return [p.x, p.y];
5017
+ };
5018
+ const overAt = (event, self) => {
5019
+ const hit = document.elementFromPoint?.(event.clientX, event.clientY)?.closest?.("[data-target]")?.getAttribute("data-target") ?? null;
5020
+ return hit && hit !== self ? hit : null;
5021
+ };
5022
+ const startDrag = (mark, event) => {
5023
+ if (!interactive || !onDragEnd || !mark.drag || !mark.target || event.button !== 0) return;
5024
+ event.stopPropagation();
5025
+ const start = toScene(event);
5026
+ let current = { kind: mark.drag, target: mark.target, start, pointer: start };
5027
+ dragged.current = false;
5028
+ const move = (ev) => {
5029
+ current = { ...current, pointer: toScene(ev), over: mark.drag === "connect" ? overAt(ev, mark.target) : null };
5030
+ if ((0, import_canvas26.isDiagramDrag)(current)) dragged.current = true;
5031
+ setDrag(current);
5032
+ };
5033
+ const up = (ev) => {
5034
+ window.removeEventListener("pointermove", move);
5035
+ window.removeEventListener("pointerup", up);
5036
+ current = { ...current, pointer: toScene(ev), over: mark.drag === "connect" ? overAt(ev, mark.target) : null };
5037
+ setDrag(null);
5038
+ if ((0, import_canvas26.isDiagramDrag)(current)) onDragEnd(current);
5039
+ };
5040
+ window.addEventListener("pointermove", move);
5041
+ window.addEventListener("pointerup", up);
5042
+ };
5043
+ const shown = drag ? (0, import_canvas26.previewDiagramDrag)(scene, drag, { theme: { selection: selectionColor } }) : scene;
5008
5044
  const marker = (kind) => kind ? `url(#${uid}-${kind})` : void 0;
5009
5045
  const x = scene.x - padding;
5010
5046
  const y = scene.y - padding;
@@ -5013,18 +5049,25 @@ function MermaidFamilyScene({
5013
5049
  const handlers = (mark) => interactive && mark.target ? {
5014
5050
  onClick: (event) => {
5015
5051
  event.stopPropagation();
5052
+ if (dragged.current) {
5053
+ dragged.current = false;
5054
+ return;
5055
+ }
5016
5056
  onSelect?.(mark.target, event);
5017
5057
  },
5058
+ onPointerDown: (event) => startDrag(mark, event),
5018
5059
  onDoubleClick: (event) => {
5019
5060
  event.stopPropagation();
5020
5061
  onOpen?.(mark.target, event);
5021
5062
  },
5022
- cursor: "pointer"
5063
+ cursor: onDragEnd && mark.drag ? mark.drag === "move-x" ? "ew-resize" : mark.drag === "resize" ? "col-resize" : mark.drag === "score" || mark.drag === "order" || mark.drag === "move-y" ? "ns-resize" : mark.drag === "connect" ? "crosshair" : "move" : "pointer"
5023
5064
  } : { pointerEvents: "none" };
5065
+ const shift = (mark) => mark.offset && (mark.offset[0] || mark.offset[1]) ? `translate(${mark.offset[0]} ${mark.offset[1]})` : void 0;
5024
5066
  const stroke = (mark) => mark.selected ? { stroke: selectionColor, strokeWidth: Math.max(2, mark.strokeWidth ?? 0) } : { stroke: mark.stroke, strokeWidth: mark.strokeWidth };
5025
5067
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
5026
5068
  "svg",
5027
5069
  {
5070
+ ref: svgRef,
5028
5071
  className: `pixerate-diagram-scene ${className}`.trim(),
5029
5072
  "data-family": scene.family,
5030
5073
  role: "img",
@@ -5033,14 +5076,22 @@ function MermaidFamilyScene({
5033
5076
  width,
5034
5077
  height,
5035
5078
  style: { display: "block", maxWidth: "100%", height: "auto", overflow: "visible", ...style },
5036
- onClick: interactive ? (event) => onSelect?.(null, event) : void 0,
5079
+ onClick: interactive ? (event) => dragged.current ? dragged.current = false : onSelect?.(null, event) : void 0,
5037
5080
  children: [
5038
5081
  /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("defs", { children: [
5039
5082
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("marker", { id: `${uid}-arrowclosed`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("path", { d: "M0,0 L10,5 L0,10 Z", style: { fill: markerColor } }) }),
5040
5083
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("marker", { id: `${uid}-arrow`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("path", { d: "M0,0 L10,5 L0,10", style: { fill: "none", stroke: markerColor, strokeWidth: 1.5 } }) })
5041
5084
  ] }),
5042
- scene.marks.map((mark) => {
5043
- const common = { "data-role": mark.role, "data-target": mark.target, "data-selected": mark.selected ? "" : void 0, opacity: mark.opacity, ...handlers(mark) };
5085
+ shown.marks.map((mark) => {
5086
+ const common = {
5087
+ "data-role": mark.role,
5088
+ "data-target": mark.target,
5089
+ "data-drag": onDragEnd ? mark.drag : void 0,
5090
+ "data-selected": mark.selected ? "" : void 0,
5091
+ opacity: mark.opacity,
5092
+ transform: mark.kind === "text" ? void 0 : shift(mark),
5093
+ ...handlers(mark)
5094
+ };
5044
5095
  switch (mark.kind) {
5045
5096
  case "rect":
5046
5097
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
@@ -5098,7 +5149,7 @@ function MermaidFamilyScene({
5098
5149
  y: mark.y,
5099
5150
  textAnchor: mark.anchor,
5100
5151
  dominantBaseline: (0, import_canvas26.diagramTextBaseline)(mark.baseline),
5101
- transform: mark.rotate ? `rotate(${mark.rotate} ${mark.x} ${mark.y})` : void 0,
5152
+ transform: [shift(mark), mark.rotate ? `rotate(${mark.rotate} ${mark.x} ${mark.y})` : ""].filter(Boolean).join(" ") || void 0,
5102
5153
  style: {
5103
5154
  fill: mark.selected ? selectionColor : mark.fill,
5104
5155
  fontSize: mark.size,
@@ -5143,9 +5194,14 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
5143
5194
  [state.document, state.editable]
5144
5195
  );
5145
5196
  const scene = (0, import_react39.useMemo)(
5146
- () => state.document.tier === "editable" ? (0, import_canvas27.familySceneFromLayout)(state.document.family, state.document.graph, canvas.layout, { theme: { ...import_canvas27.CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
5197
+ () => {
5198
+ if (state.document.tier !== "editable") return null;
5199
+ const theme = { ...import_canvas27.CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme };
5200
+ const drawn = (0, import_canvas27.familySceneFromLayout)(state.document.family, state.document.graph, canvas.layout, { theme, selection: state.selection });
5201
+ return drawn && state.editable ? (0, import_canvas27.withDiagramDragHandles)(drawn, { theme, selection: state.selection }) : drawn;
5202
+ },
5147
5203
  // eslint-disable-next-line react-hooks/exhaustive-deps
5148
- [state.document, canvas.layout, state.selection]
5204
+ [state.document, canvas.layout, state.selection, state.editable]
5149
5205
  );
5150
5206
  const layoutRef = (0, import_react39.useRef)(canvas.layout);
5151
5207
  layoutRef.current = canvas.layout;
@@ -5176,6 +5232,11 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
5176
5232
  const op = (0, import_canvas27.diagramRenameOp)(controller.getDocument(), target, label);
5177
5233
  return op ? controller.apply(op, "Rename") : null;
5178
5234
  },
5235
+ drop: (drag) => {
5236
+ if (!controller.getState().editable) return null;
5237
+ const ops = (0, import_canvas27.planDiagramDrag)(controller.getDocument(), layoutRef.current, drag);
5238
+ return ops.length ? controller.apply(ops, (0, import_canvas27.diagramDragLabel)(drag.kind)) : null;
5239
+ },
5179
5240
  select: (ids) => controller.select(ids),
5180
5241
  undo: () => void controller.undo(),
5181
5242
  redo: () => void controller.redo()
@@ -3153,8 +3153,8 @@ import {
3153
3153
  } from "@pixerate/editor/canvas";
3154
3154
 
3155
3155
  // src/canvas/MermaidFamilyScene.tsx
3156
- import { useId } from "react";
3157
- import { diagramTextBaseline } from "@pixerate/editor/canvas";
3156
+ import { useId, useRef as useRef20, useState as useState12 } from "react";
3157
+ import { diagramTextBaseline, isDiagramDrag, previewDiagramDrag } from "@pixerate/editor/canvas";
3158
3158
  import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
3159
3159
  function MermaidFamilyScene({
3160
3160
  scene,
@@ -3162,6 +3162,7 @@ function MermaidFamilyScene({
3162
3162
  interactive = true,
3163
3163
  onSelect,
3164
3164
  onOpen,
3165
+ onDragEnd,
3165
3166
  selectionColor = "var(--primary, #2563eb)",
3166
3167
  markerColor = "var(--muted-foreground, #64748b)",
3167
3168
  className = "",
@@ -3169,6 +3170,41 @@ function MermaidFamilyScene({
3169
3170
  title
3170
3171
  }) {
3171
3172
  const uid = useId().replace(/:/g, "");
3173
+ const svgRef = useRef20(null);
3174
+ const [drag, setDrag] = useState12(null);
3175
+ const dragged = useRef20(false);
3176
+ const toScene = (event) => {
3177
+ const ctm = svgRef.current?.getScreenCTM?.();
3178
+ if (!ctm) return [event.clientX, event.clientY];
3179
+ const p = new DOMPoint(event.clientX, event.clientY).matrixTransform(ctm.inverse());
3180
+ return [p.x, p.y];
3181
+ };
3182
+ const overAt = (event, self) => {
3183
+ const hit = document.elementFromPoint?.(event.clientX, event.clientY)?.closest?.("[data-target]")?.getAttribute("data-target") ?? null;
3184
+ return hit && hit !== self ? hit : null;
3185
+ };
3186
+ const startDrag = (mark, event) => {
3187
+ if (!interactive || !onDragEnd || !mark.drag || !mark.target || event.button !== 0) return;
3188
+ event.stopPropagation();
3189
+ const start = toScene(event);
3190
+ let current = { kind: mark.drag, target: mark.target, start, pointer: start };
3191
+ dragged.current = false;
3192
+ const move = (ev) => {
3193
+ current = { ...current, pointer: toScene(ev), over: mark.drag === "connect" ? overAt(ev, mark.target) : null };
3194
+ if (isDiagramDrag(current)) dragged.current = true;
3195
+ setDrag(current);
3196
+ };
3197
+ const up = (ev) => {
3198
+ window.removeEventListener("pointermove", move);
3199
+ window.removeEventListener("pointerup", up);
3200
+ current = { ...current, pointer: toScene(ev), over: mark.drag === "connect" ? overAt(ev, mark.target) : null };
3201
+ setDrag(null);
3202
+ if (isDiagramDrag(current)) onDragEnd(current);
3203
+ };
3204
+ window.addEventListener("pointermove", move);
3205
+ window.addEventListener("pointerup", up);
3206
+ };
3207
+ const shown = drag ? previewDiagramDrag(scene, drag, { theme: { selection: selectionColor } }) : scene;
3172
3208
  const marker = (kind) => kind ? `url(#${uid}-${kind})` : void 0;
3173
3209
  const x = scene.x - padding;
3174
3210
  const y = scene.y - padding;
@@ -3177,18 +3213,25 @@ function MermaidFamilyScene({
3177
3213
  const handlers = (mark) => interactive && mark.target ? {
3178
3214
  onClick: (event) => {
3179
3215
  event.stopPropagation();
3216
+ if (dragged.current) {
3217
+ dragged.current = false;
3218
+ return;
3219
+ }
3180
3220
  onSelect?.(mark.target, event);
3181
3221
  },
3222
+ onPointerDown: (event) => startDrag(mark, event),
3182
3223
  onDoubleClick: (event) => {
3183
3224
  event.stopPropagation();
3184
3225
  onOpen?.(mark.target, event);
3185
3226
  },
3186
- cursor: "pointer"
3227
+ cursor: onDragEnd && mark.drag ? mark.drag === "move-x" ? "ew-resize" : mark.drag === "resize" ? "col-resize" : mark.drag === "score" || mark.drag === "order" || mark.drag === "move-y" ? "ns-resize" : mark.drag === "connect" ? "crosshair" : "move" : "pointer"
3187
3228
  } : { pointerEvents: "none" };
3229
+ const shift = (mark) => mark.offset && (mark.offset[0] || mark.offset[1]) ? `translate(${mark.offset[0]} ${mark.offset[1]})` : void 0;
3188
3230
  const stroke = (mark) => mark.selected ? { stroke: selectionColor, strokeWidth: Math.max(2, mark.strokeWidth ?? 0) } : { stroke: mark.stroke, strokeWidth: mark.strokeWidth };
3189
3231
  return /* @__PURE__ */ jsxs10(
3190
3232
  "svg",
3191
3233
  {
3234
+ ref: svgRef,
3192
3235
  className: `pixerate-diagram-scene ${className}`.trim(),
3193
3236
  "data-family": scene.family,
3194
3237
  role: "img",
@@ -3197,14 +3240,22 @@ function MermaidFamilyScene({
3197
3240
  width,
3198
3241
  height,
3199
3242
  style: { display: "block", maxWidth: "100%", height: "auto", overflow: "visible", ...style },
3200
- onClick: interactive ? (event) => onSelect?.(null, event) : void 0,
3243
+ onClick: interactive ? (event) => dragged.current ? dragged.current = false : onSelect?.(null, event) : void 0,
3201
3244
  children: [
3202
3245
  /* @__PURE__ */ jsxs10("defs", { children: [
3203
3246
  /* @__PURE__ */ jsx11("marker", { id: `${uid}-arrowclosed`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ jsx11("path", { d: "M0,0 L10,5 L0,10 Z", style: { fill: markerColor } }) }),
3204
3247
  /* @__PURE__ */ jsx11("marker", { id: `${uid}-arrow`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "8", markerHeight: "8", orient: "auto-start-reverse", children: /* @__PURE__ */ jsx11("path", { d: "M0,0 L10,5 L0,10", style: { fill: "none", stroke: markerColor, strokeWidth: 1.5 } }) })
3205
3248
  ] }),
3206
- scene.marks.map((mark) => {
3207
- const common = { "data-role": mark.role, "data-target": mark.target, "data-selected": mark.selected ? "" : void 0, opacity: mark.opacity, ...handlers(mark) };
3249
+ shown.marks.map((mark) => {
3250
+ const common = {
3251
+ "data-role": mark.role,
3252
+ "data-target": mark.target,
3253
+ "data-drag": onDragEnd ? mark.drag : void 0,
3254
+ "data-selected": mark.selected ? "" : void 0,
3255
+ opacity: mark.opacity,
3256
+ transform: mark.kind === "text" ? void 0 : shift(mark),
3257
+ ...handlers(mark)
3258
+ };
3208
3259
  switch (mark.kind) {
3209
3260
  case "rect":
3210
3261
  return /* @__PURE__ */ jsx11(
@@ -3262,7 +3313,7 @@ function MermaidFamilyScene({
3262
3313
  y: mark.y,
3263
3314
  textAnchor: mark.anchor,
3264
3315
  dominantBaseline: diagramTextBaseline(mark.baseline),
3265
- transform: mark.rotate ? `rotate(${mark.rotate} ${mark.x} ${mark.y})` : void 0,
3316
+ transform: [shift(mark), mark.rotate ? `rotate(${mark.rotate} ${mark.x} ${mark.y})` : ""].filter(Boolean).join(" ") || void 0,
3266
3317
  style: {
3267
3318
  fill: mark.selected ? selectionColor : mark.fill,
3268
3319
  fontSize: mark.size,
@@ -3282,7 +3333,7 @@ function MermaidFamilyScene({
3282
3333
  }
3283
3334
 
3284
3335
  // src/canvas/useMermaidDiagram.ts
3285
- import { useEffect as useEffect16, useMemo as useMemo15, useRef as useRef20, useState as useState12, useSyncExternalStore as useSyncExternalStore5 } from "react";
3336
+ import { useEffect as useEffect16, useMemo as useMemo15, useRef as useRef21, useState as useState13, useSyncExternalStore as useSyncExternalStore5 } from "react";
3286
3337
  import {
3287
3338
  DiagramController,
3288
3339
  createDiagramEditorDocument
@@ -3291,8 +3342,11 @@ import {
3291
3342
  CSS_VARIABLE_DIAGRAM_SCENE_THEME,
3292
3343
  DiagramStream,
3293
3344
  blendDiagramLayout,
3345
+ diagramDragLabel,
3294
3346
  diagramRenameOp,
3295
3347
  familySceneFromLayout,
3348
+ planDiagramDrag,
3349
+ withDiagramDragHandles,
3296
3350
  easeDiagramTween,
3297
3351
  mermaidMovesFromCanvas,
3298
3352
  mermaidToCanvas
@@ -3301,7 +3355,7 @@ function useDiagramState(controller) {
3301
3355
  return useSyncExternalStore5(controller.subscribe, controller.getState, controller.getState);
3302
3356
  }
3303
3357
  function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3304
- const own = useRef20(null);
3358
+ const own = useRef21(null);
3305
3359
  let controller;
3306
3360
  if (controllerOrOptions instanceof DiagramController) controller = controllerOrOptions;
3307
3361
  else {
@@ -3319,11 +3373,16 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3319
3373
  [state.document, state.editable]
3320
3374
  );
3321
3375
  const scene = useMemo15(
3322
- () => state.document.tier === "editable" ? familySceneFromLayout(state.document.family, state.document.graph, canvas.layout, { theme: { ...CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme }, selection: state.selection }) : null,
3376
+ () => {
3377
+ if (state.document.tier !== "editable") return null;
3378
+ const theme = { ...CSS_VARIABLE_DIAGRAM_SCENE_THEME, ...sceneTheme };
3379
+ const drawn = familySceneFromLayout(state.document.family, state.document.graph, canvas.layout, { theme, selection: state.selection });
3380
+ return drawn && state.editable ? withDiagramDragHandles(drawn, { theme, selection: state.selection }) : drawn;
3381
+ },
3323
3382
  // eslint-disable-next-line react-hooks/exhaustive-deps
3324
- [state.document, canvas.layout, state.selection]
3383
+ [state.document, canvas.layout, state.selection, state.editable]
3325
3384
  );
3326
- const layoutRef = useRef20(canvas.layout);
3385
+ const layoutRef = useRef21(canvas.layout);
3327
3386
  layoutRef.current = canvas.layout;
3328
3387
  const actions = useMemo15(
3329
3388
  () => ({
@@ -3352,6 +3411,11 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3352
3411
  const op = diagramRenameOp(controller.getDocument(), target, label);
3353
3412
  return op ? controller.apply(op, "Rename") : null;
3354
3413
  },
3414
+ drop: (drag) => {
3415
+ if (!controller.getState().editable) return null;
3416
+ const ops = planDiagramDrag(controller.getDocument(), layoutRef.current, drag);
3417
+ return ops.length ? controller.apply(ops, diagramDragLabel(drag.kind)) : null;
3418
+ },
3355
3419
  select: (ids) => controller.select(ids),
3356
3420
  undo: () => void controller.undo(),
3357
3421
  redo: () => void controller.redo()
@@ -3362,11 +3426,11 @@ function useMermaidDiagram(controllerOrOptions = {}, view = {}) {
3362
3426
  }
3363
3427
  function useMermaidStream(source, options = {}) {
3364
3428
  const { complete = false, duration = 300, ...layoutOptions } = options;
3365
- const stream = useRef20(null);
3429
+ const stream = useRef21(null);
3366
3430
  if (!stream.current) stream.current = new DiagramStream(layoutOptions);
3367
3431
  const result = useMemo15(() => stream.current.update(source, complete), [source, complete]);
3368
- const [shown, setShown] = useState12({ layout: result.layout, settled: true });
3369
- const shownRef = useRef20(shown.layout);
3432
+ const [shown, setShown] = useState13({ layout: result.layout, settled: true });
3433
+ const shownRef = useRef21(shown.layout);
3370
3434
  shownRef.current = shown.layout;
3371
3435
  useEffect16(() => {
3372
3436
  const target = result.layout;
@@ -3478,12 +3542,12 @@ function MermaidThumbnail({ source, className = "", fallback = null, ...options
3478
3542
  }
3479
3543
 
3480
3544
  // src/canvas/useDiagramDirector.ts
3481
- import { useRef as useRef21, useSyncExternalStore as useSyncExternalStore6 } from "react";
3545
+ import { useRef as useRef22, useSyncExternalStore as useSyncExternalStore6 } from "react";
3482
3546
  import { DiagramDirector, PresenceStore } from "@pixerate/editor/diagram";
3483
3547
  function useDiagramDirector(controller, options) {
3484
- const placement = useRef21(options.placement);
3548
+ const placement = useRef22(options.placement);
3485
3549
  placement.current = options.placement;
3486
- const ref = useRef21(null);
3550
+ const ref = useRef22(null);
3487
3551
  if (!ref.current) {
3488
3552
  const presence = new PresenceStore();
3489
3553
  ref.current = {
@@ -3509,17 +3573,17 @@ function DiagramPresenceLayer({ presence, viewport, className = "" }) {
3509
3573
  }
3510
3574
 
3511
3575
  // src/canvas/useCanvasProposals.ts
3512
- import { useEffect as useEffect17, useMemo as useMemo17, useRef as useRef22, useState as useState13, useSyncExternalStore as useSyncExternalStore7 } from "react";
3576
+ import { useEffect as useEffect17, useMemo as useMemo17, useRef as useRef23, useState as useState14, useSyncExternalStore as useSyncExternalStore7 } from "react";
3513
3577
  import {
3514
3578
  createCanvasChangeFeed,
3515
3579
  createCanvasProposals
3516
3580
  } from "@pixerate/editor/canvas";
3517
3581
  function useCanvasProposals(options) {
3518
- const latest = useRef22(options);
3582
+ const latest = useRef23(options);
3519
3583
  latest.current = options;
3520
- const live = useRef22({ nodes: options.nodes, edges: options.edges });
3584
+ const live = useRef23({ nodes: options.nodes, edges: options.edges });
3521
3585
  live.current = { nodes: options.nodes, edges: options.edges };
3522
- const storeRef = useRef22(null);
3586
+ const storeRef = useRef23(null);
3523
3587
  if (storeRef.current === null) {
3524
3588
  storeRef.current = createCanvasProposals({
3525
3589
  getNodes: () => live.current.nodes,
@@ -3558,9 +3622,9 @@ function useCanvasProposals(options) {
3558
3622
  );
3559
3623
  }
3560
3624
  function useCanvasChangeFeed(options) {
3561
- const latest = useRef22(options);
3625
+ const latest = useRef23(options);
3562
3626
  latest.current = options;
3563
- const [last, setLast] = useState13(null);
3627
+ const [last, setLast] = useState14(null);
3564
3628
  const feed = useMemo17(
3565
3629
  () => createCanvasChangeFeed({
3566
3630
  getNodes: () => latest.current.nodes,
@@ -1,6 +1,6 @@
1
1
  import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type DiagramEditorDocument, type MermaidDocument } from '@pixerate/editor/diagram';
2
2
  import type { EditorDocument } from '@pixerate/editor/persistence';
3
- import { type DiagramLayout, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
3
+ import { type DiagramLayout, type DiagramDrag, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
4
4
  export interface UseMermaidDiagramOptions extends DiagramControllerOptions {
5
5
  /** Layout spacing and node measuring for new nodes (stored positions always win). */
6
6
  layoutOptions?: DiagramLayoutOptions;
@@ -33,7 +33,8 @@ export interface UseMermaidDiagramResult {
33
33
  /**
34
34
  * The family's own picture (pie, Gantt, sequence, XY, radar…) with the selection marked;
35
35
  * null for families drawn as nodes and edges (flowchart, state, class, ER) and text-only
36
- * ones. Render it with `MermaidFamilyScene`.
36
+ * ones. Render it with `MermaidFamilyScene`. When editable, its draggable marks carry
37
+ * `drag` (and a selected Gantt task its grips): pass `drop` as `onDragEnd`.
37
38
  */
38
39
  scene: DiagramScene | null;
39
40
  apply: (ops: EditOp | EditOp[], label?: string) => DiagramActionResult;
@@ -49,6 +50,8 @@ export interface UseMermaidDiagramResult {
49
50
  rename: (id: string, label: string) => DiagramActionResult;
50
51
  /** Renames what a scene mark targets: the title (`::title`), a group, an edge or a node. */
51
52
  renameTarget: (target: string, label: string) => DiagramActionResult | null;
53
+ /** Applies a finished drag on the scene (`planDiagramDrag`) as one undo step; null when it changes nothing. */
54
+ drop: (drag: DiagramDrag) => DiagramActionResult | null;
52
55
  select: (ids: readonly string[]) => void;
53
56
  undo: () => void;
54
57
  redo: () => void;
@@ -1,6 +1,6 @@
1
1
  import { DiagramController, type DiagramActionResult, type DiagramControllerOptions, type DiagramState, type EditOp, type DiagramEditorDocument, type MermaidDocument } from '@pixerate/editor/diagram';
2
2
  import type { EditorDocument } from '@pixerate/editor/persistence';
3
- import { type DiagramLayout, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
3
+ import { type DiagramLayout, type DiagramDrag, type DiagramLayoutOptions, type DiagramScene, type DiagramSceneTheme, type MermaidFlowEdge, type MermaidFlowNode } from '@pixerate/editor/canvas';
4
4
  export interface UseMermaidDiagramOptions extends DiagramControllerOptions {
5
5
  /** Layout spacing and node measuring for new nodes (stored positions always win). */
6
6
  layoutOptions?: DiagramLayoutOptions;
@@ -33,7 +33,8 @@ export interface UseMermaidDiagramResult {
33
33
  /**
34
34
  * The family's own picture (pie, Gantt, sequence, XY, radar…) with the selection marked;
35
35
  * null for families drawn as nodes and edges (flowchart, state, class, ER) and text-only
36
- * ones. Render it with `MermaidFamilyScene`.
36
+ * ones. Render it with `MermaidFamilyScene`. When editable, its draggable marks carry
37
+ * `drag` (and a selected Gantt task its grips): pass `drop` as `onDragEnd`.
37
38
  */
38
39
  scene: DiagramScene | null;
39
40
  apply: (ops: EditOp | EditOp[], label?: string) => DiagramActionResult;
@@ -49,6 +50,8 @@ export interface UseMermaidDiagramResult {
49
50
  rename: (id: string, label: string) => DiagramActionResult;
50
51
  /** Renames what a scene mark targets: the title (`::title`), a group, an edge or a node. */
51
52
  renameTarget: (target: string, label: string) => DiagramActionResult | null;
53
+ /** Applies a finished drag on the scene (`planDiagramDrag`) as one undo step; null when it changes nothing. */
54
+ drop: (drag: DiagramDrag) => DiagramActionResult | null;
52
55
  select: (ids: readonly string[]) => void;
53
56
  undo: () => void;
54
57
  redo: () => void;