@asymmetric-effort/specifyjs 0.2.145 → 0.2.150

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.
@@ -16455,6 +16455,8 @@ function TradingDashboard(props) {
16455
16455
 
16456
16456
  // ../demos/project-manager/src/Toolbar.ts
16457
16457
  var CARD_COLORS = [
16458
+ "transparent",
16459
+ // no background
16458
16460
  "#fef9c3",
16459
16461
  // yellow
16460
16462
  "#fecaca",
@@ -16557,13 +16559,18 @@ function BoardToolbar(props) {
16557
16559
  } else if (isActive) {
16558
16560
  borderStyle = "2px solid #3b82f6";
16559
16561
  }
16562
+ const isTransparent = color === "transparent";
16560
16563
  return createElement("button", {
16561
16564
  key: color,
16565
+ title: isTransparent ? "Transparent" : color,
16562
16566
  style: {
16563
16567
  width: "18px",
16564
16568
  height: "18px",
16565
16569
  borderRadius: "50%",
16566
- backgroundColor: color,
16570
+ backgroundColor: isTransparent ? "#ffffff" : color,
16571
+ backgroundImage: isTransparent ? "linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%), linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%)" : "none",
16572
+ backgroundSize: isTransparent ? "6px 6px" : "auto",
16573
+ backgroundPosition: isTransparent ? "0 0, 3px 3px" : "0 0",
16567
16574
  border: borderStyle,
16568
16575
  cursor: "pointer",
16569
16576
  padding: "0",
@@ -16660,75 +16667,106 @@ function Card2(props) {
16660
16667
  onResize,
16661
16668
  onDelete,
16662
16669
  onDoubleClick,
16670
+ onUpdate,
16663
16671
  onDragStart,
16664
16672
  onDuplicate,
16665
16673
  onChangeColor,
16666
16674
  onChangePriority,
16667
- onAnchorDragStart
16675
+ onAnchorDragStart,
16676
+ onCardContextMenu
16668
16677
  } = props;
16669
16678
  const [hovered, setHovered] = useState(false);
16670
- const [contextMenu, setContextMenu] = useState(null);
16671
- const [colorSubmenuOpen, setColorSubmenuOpen] = useState(false);
16672
- const [prioritySubmenuOpen, setPrioritySubmenuOpen] = useState(false);
16679
+ const [editingTitle, setEditingTitle] = useState(false);
16680
+ const [editingDescription, setEditingDescription] = useState(false);
16681
+ const [titleDraft, setTitleDraft] = useState(card.title || "");
16682
+ const [descDraft, setDescDraft] = useState(card.description || "");
16673
16683
  const dragStartRef = useRef(null);
16674
16684
  const resizeStartRef = useRef(null);
16675
16685
  const cardRef = useRef(null);
16676
- const contextMenuRef = useRef(null);
16686
+ const titleInputRef = useRef(null);
16687
+ const descTextareaRef = useRef(null);
16677
16688
  const priorityColor = card.priority ? PRIORITY_COLORS[card.priority] || "#94a3b8" : "transparent";
16689
+ const { onMouseDown: onDragHandleMouseDown, isDragging: isExportDragging } = useDraggable(
16690
+ "application/project-card",
16691
+ { id: card.id, title: card.title, description: card.description, color: card.color }
16692
+ );
16678
16693
  const handleContextMenu = useCallback((e) => {
16679
16694
  const me = e;
16680
16695
  me.preventDefault();
16681
16696
  me.stopPropagation();
16682
- setContextMenu({ x: me.clientX, y: me.clientY });
16683
- setColorSubmenuOpen(false);
16684
- setPrioritySubmenuOpen(false);
16685
- }, []);
16686
- const closeContextMenu = useCallback(() => {
16687
- setContextMenu(null);
16688
- setColorSubmenuOpen(false);
16689
- setPrioritySubmenuOpen(false);
16690
- }, []);
16697
+ if (onCardContextMenu) {
16698
+ onCardContextMenu(card.id, { x: me.clientX, y: me.clientY });
16699
+ }
16700
+ }, [card.id, onCardContextMenu]);
16691
16701
  useEffect(() => {
16692
- if (!contextMenu) return;
16693
- const handleClick = () => {
16694
- closeContextMenu();
16695
- };
16696
- const timer = setTimeout(() => {
16697
- document.addEventListener("click", handleClick);
16698
- document.addEventListener("contextmenu", handleClick);
16699
- }, 0);
16700
- return () => {
16701
- clearTimeout(timer);
16702
- document.removeEventListener("click", handleClick);
16703
- document.removeEventListener("contextmenu", handleClick);
16704
- };
16705
- }, [contextMenu, closeContextMenu]);
16706
- const handleDuplicateClick = useCallback((e) => {
16707
- e.stopPropagation();
16708
- closeContextMenu();
16709
- if (onDuplicate) onDuplicate(card.id);
16710
- }, [card.id, onDuplicate, closeContextMenu]);
16711
- const handleContextDeleteClick = useCallback((e) => {
16702
+ if (editingTitle && titleInputRef.current) {
16703
+ const input = titleInputRef.current;
16704
+ input.focus();
16705
+ const len = input.value.length;
16706
+ input.setSelectionRange(len, len);
16707
+ }
16708
+ }, [editingTitle]);
16709
+ useEffect(() => {
16710
+ if (editingDescription && descTextareaRef.current) {
16711
+ const textarea = descTextareaRef.current;
16712
+ textarea.focus();
16713
+ const len = textarea.value.length;
16714
+ textarea.setSelectionRange(len, len);
16715
+ }
16716
+ }, [editingDescription]);
16717
+ const handleTitleDoubleClick = useCallback((e) => {
16718
+ e.preventDefault();
16712
16719
  e.stopPropagation();
16713
- closeContextMenu();
16714
- onDelete(card.id);
16715
- }, [card.id, onDelete, closeContextMenu]);
16716
- const handleColorMenuEnter = useCallback(() => {
16717
- setColorSubmenuOpen(true);
16718
- setPrioritySubmenuOpen(false);
16720
+ setTitleDraft(card.title || "");
16721
+ setEditingTitle(true);
16722
+ }, [card.title]);
16723
+ const handleTitleInput = useCallback((e) => {
16724
+ setTitleDraft(e.target.value);
16719
16725
  }, []);
16720
- const handlePriorityMenuEnter = useCallback(() => {
16721
- setPrioritySubmenuOpen(true);
16722
- setColorSubmenuOpen(false);
16726
+ const saveTitleAndClose = useCallback(() => {
16727
+ const newTitle = titleDraft.trim();
16728
+ if (newTitle && newTitle !== card.title && onUpdate) {
16729
+ onUpdate(card.id, { title: newTitle });
16730
+ }
16731
+ setEditingTitle(false);
16732
+ }, [titleDraft, card.id, card.title, onUpdate]);
16733
+ const handleTitleKeyDown = useCallback((e) => {
16734
+ const ke = e;
16735
+ if (ke.key === "Enter") {
16736
+ ke.preventDefault();
16737
+ saveTitleAndClose();
16738
+ } else if (ke.key === "Escape") {
16739
+ ke.preventDefault();
16740
+ setEditingTitle(false);
16741
+ }
16742
+ }, [saveTitleAndClose]);
16743
+ const handleTitleBlur = useCallback(() => {
16744
+ saveTitleAndClose();
16745
+ }, [saveTitleAndClose]);
16746
+ const handleDescriptionClick = useCallback((e) => {
16747
+ e.stopPropagation();
16748
+ setDescDraft(card.description || "");
16749
+ setEditingDescription(true);
16750
+ }, [card.description]);
16751
+ const handleDescInput = useCallback((e) => {
16752
+ setDescDraft(e.target.value);
16723
16753
  }, []);
16724
- const handleColorSelect = useCallback((color) => {
16725
- closeContextMenu();
16726
- if (onChangeColor) onChangeColor(card.id, color);
16727
- }, [card.id, onChangeColor, closeContextMenu]);
16728
- const handlePrioritySelect = useCallback((priority) => {
16729
- closeContextMenu();
16730
- if (onChangePriority) onChangePriority(card.id, priority);
16731
- }, [card.id, onChangePriority, closeContextMenu]);
16754
+ const saveDescAndClose = useCallback(() => {
16755
+ if (descDraft !== card.description && onUpdate) {
16756
+ onUpdate(card.id, { description: descDraft });
16757
+ }
16758
+ setEditingDescription(false);
16759
+ }, [descDraft, card.id, card.description, onUpdate]);
16760
+ const handleDescriptionKeyDown = useCallback((e) => {
16761
+ const ke = e;
16762
+ if (ke.key === "Escape") {
16763
+ ke.preventDefault();
16764
+ saveDescAndClose();
16765
+ }
16766
+ }, [saveDescAndClose]);
16767
+ const handleDescriptionBlur = useCallback(() => {
16768
+ saveDescAndClose();
16769
+ }, [saveDescAndClose]);
16732
16770
  const handleAnchorMouseDown = useCallback((anchor, e) => {
16733
16771
  const me = e;
16734
16772
  me.preventDefault();
@@ -16757,7 +16795,7 @@ function Card2(props) {
16757
16795
  const handleMouseDown = useCallback((e) => {
16758
16796
  const me = e;
16759
16797
  const target = me.target;
16760
- if (target.dataset && (target.dataset.role === "delete" || target.dataset.role === "resize" || target.dataset.role === "anchor")) return;
16798
+ if (target.dataset && (target.dataset.role === "delete" || target.dataset.role === "resize" || target.dataset.role === "anchor" || target.dataset.role === "drag-handle" || target.dataset.role === "inline-edit")) return;
16761
16799
  me.preventDefault();
16762
16800
  me.stopPropagation();
16763
16801
  onSelect(card.id);
@@ -16818,8 +16856,7 @@ function Card2(props) {
16818
16856
  const handleDoubleClick = useCallback((e) => {
16819
16857
  e.preventDefault();
16820
16858
  e.stopPropagation();
16821
- onDoubleClick(card.id);
16822
- }, [card.id, onDoubleClick]);
16859
+ }, []);
16823
16860
  const handleDeleteClick = useCallback((e) => {
16824
16861
  e.preventDefault();
16825
16862
  e.stopPropagation();
@@ -16911,6 +16948,53 @@ function Card2(props) {
16911
16948
  }, tag)
16912
16949
  )
16913
16950
  ) : null;
16951
+ const assigneeEl = card.assignee ? createElement(
16952
+ "div",
16953
+ {
16954
+ style: {
16955
+ display: "flex",
16956
+ alignItems: "center",
16957
+ gap: "4px",
16958
+ marginTop: "4px",
16959
+ fontSize: "10px",
16960
+ color: "#555"
16961
+ },
16962
+ "data-testid": `card-assignee-${card.id}`
16963
+ },
16964
+ createElement("span", {
16965
+ style: {
16966
+ width: "16px",
16967
+ height: "16px",
16968
+ borderRadius: "50%",
16969
+ backgroundColor: "#3b82f6",
16970
+ color: "#fff",
16971
+ fontSize: "9px",
16972
+ fontWeight: "700",
16973
+ display: "inline-flex",
16974
+ alignItems: "center",
16975
+ justifyContent: "center",
16976
+ flexShrink: "0"
16977
+ }
16978
+ }, card.assignee.charAt(0).toUpperCase()),
16979
+ createElement("span", {}, card.assignee)
16980
+ ) : null;
16981
+ const dragHandleStyle = {
16982
+ position: "absolute",
16983
+ top: "4px",
16984
+ right: "24px",
16985
+ width: "18px",
16986
+ height: "18px",
16987
+ borderRadius: "3px",
16988
+ backgroundColor: isExportDragging ? "rgba(59,130,246,0.4)" : "rgba(0,0,0,0.1)",
16989
+ color: "#333",
16990
+ fontSize: "10px",
16991
+ lineHeight: "18px",
16992
+ textAlign: "center",
16993
+ cursor: "grab",
16994
+ display: hovered ? "block" : "none",
16995
+ border: "none",
16996
+ padding: "0"
16997
+ };
16914
16998
  const anchorBaseStyle = {
16915
16999
  position: "absolute",
16916
17000
  width: "10px",
@@ -16927,166 +17011,6 @@ function Card2(props) {
16927
17011
  const anchorRight = { ...anchorBaseStyle, top: "50%", right: "-5px", transform: "translateY(-50%)" };
16928
17012
  const anchorBottom = { ...anchorBaseStyle, bottom: "-5px", left: "50%", transform: "translateX(-50%)" };
16929
17013
  const anchorLeft = { ...anchorBaseStyle, top: "50%", left: "-5px", transform: "translateY(-50%)" };
16930
- const contextMenuStyle = {
16931
- position: "fixed",
16932
- left: contextMenu ? `${contextMenu.x}px` : "0",
16933
- top: contextMenu ? `${contextMenu.y}px` : "0",
16934
- backgroundColor: "#ffffff",
16935
- border: "1px solid #d1d5db",
16936
- borderRadius: "6px",
16937
- boxShadow: "0 4px 16px rgba(0,0,0,0.15)",
16938
- padding: "4px 0",
16939
- zIndex: "10000",
16940
- minWidth: "160px",
16941
- fontSize: "13px",
16942
- color: "#1a1a1a"
16943
- };
16944
- const menuItemStyle = {
16945
- padding: "6px 12px",
16946
- cursor: "pointer",
16947
- display: "flex",
16948
- alignItems: "center",
16949
- justifyContent: "space-between",
16950
- whiteSpace: "nowrap"
16951
- };
16952
- const submenuContainerStyle = {
16953
- position: "absolute",
16954
- left: "100%",
16955
- top: "0",
16956
- backgroundColor: "#ffffff",
16957
- border: "1px solid #d1d5db",
16958
- borderRadius: "6px",
16959
- boxShadow: "0 4px 16px rgba(0,0,0,0.15)",
16960
- padding: "4px 0",
16961
- minWidth: "120px"
16962
- };
16963
- const contextMenuEl = contextMenu ? createElement(
16964
- "div",
16965
- {
16966
- ref: contextMenuRef,
16967
- className: "card-context-menu",
16968
- style: contextMenuStyle,
16969
- "data-testid": `context-menu-${card.id}`,
16970
- role: "menu",
16971
- "aria-label": "Card context menu"
16972
- },
16973
- // Duplicate
16974
- createElement("div", {
16975
- style: menuItemStyle,
16976
- onClick: handleDuplicateClick,
16977
- role: "menuitem",
16978
- "data-testid": `context-menu-duplicate-${card.id}`
16979
- }, "Duplicate"),
16980
- // Delete
16981
- createElement("div", {
16982
- style: menuItemStyle,
16983
- onClick: handleContextDeleteClick,
16984
- role: "menuitem",
16985
- "data-testid": `context-menu-delete-${card.id}`
16986
- }, "Delete"),
16987
- // Change Color submenu
16988
- createElement(
16989
- "div",
16990
- {
16991
- style: { ...menuItemStyle, position: "relative" },
16992
- onMouseEnter: handleColorMenuEnter,
16993
- role: "menuitem",
16994
- "aria-haspopup": "true",
16995
- "data-testid": `context-menu-color-${card.id}`
16996
- },
16997
- "Change Color",
16998
- createElement("span", { style: { marginLeft: "8px" } }, "\u25B6"),
16999
- colorSubmenuOpen ? createElement(
17000
- "div",
17001
- {
17002
- style: submenuContainerStyle,
17003
- role: "menu",
17004
- "data-testid": `context-submenu-color-${card.id}`
17005
- },
17006
- ...CONTEXT_MENU_COLORS.map(
17007
- (color) => createElement(
17008
- "div",
17009
- {
17010
- key: color,
17011
- style: {
17012
- ...menuItemStyle,
17013
- gap: "8px"
17014
- },
17015
- onClick: (e) => {
17016
- e.stopPropagation();
17017
- handleColorSelect(color);
17018
- },
17019
- role: "menuitem",
17020
- "data-testid": `context-color-${color}`
17021
- },
17022
- createElement("span", {
17023
- style: {
17024
- width: "14px",
17025
- height: "14px",
17026
- borderRadius: "50%",
17027
- backgroundColor: color,
17028
- border: "1px solid rgba(0,0,0,0.15)",
17029
- display: "inline-block",
17030
- flexShrink: "0"
17031
- }
17032
- }),
17033
- color === card.color ? "\u2713" : ""
17034
- )
17035
- )
17036
- ) : null
17037
- ),
17038
- // Set Priority submenu
17039
- createElement(
17040
- "div",
17041
- {
17042
- style: { ...menuItemStyle, position: "relative" },
17043
- onMouseEnter: handlePriorityMenuEnter,
17044
- role: "menuitem",
17045
- "aria-haspopup": "true",
17046
- "data-testid": `context-menu-priority-${card.id}`
17047
- },
17048
- "Set Priority",
17049
- createElement("span", { style: { marginLeft: "8px" } }, "\u25B6"),
17050
- prioritySubmenuOpen ? createElement(
17051
- "div",
17052
- {
17053
- style: submenuContainerStyle,
17054
- role: "menu",
17055
- "data-testid": `context-submenu-priority-${card.id}`
17056
- },
17057
- ...PRIORITY_OPTIONS.map(
17058
- (opt) => createElement(
17059
- "div",
17060
- {
17061
- key: opt.value,
17062
- style: {
17063
- ...menuItemStyle,
17064
- gap: "8px"
17065
- },
17066
- onClick: (e) => {
17067
- e.stopPropagation();
17068
- handlePrioritySelect(opt.value);
17069
- },
17070
- role: "menuitem",
17071
- "data-testid": `context-priority-${opt.value}`
17072
- },
17073
- createElement("span", {
17074
- style: {
17075
- width: "8px",
17076
- height: "8px",
17077
- borderRadius: "50%",
17078
- backgroundColor: PRIORITY_COLORS[opt.value] || "#94a3b8",
17079
- display: "inline-block",
17080
- flexShrink: "0"
17081
- }
17082
- }),
17083
- opt.label,
17084
- opt.value === card.priority ? " \u2713" : ""
17085
- )
17086
- )
17087
- ) : null
17088
- )
17089
- ) : null;
17090
17014
  return createElement(
17091
17015
  "div",
17092
17016
  {
@@ -17104,9 +17028,71 @@ function Card2(props) {
17104
17028
  "aria-label": `Card: ${card.title}`,
17105
17029
  tabIndex: 0
17106
17030
  },
17107
- createElement("div", { style: titleStyle }, card.title || "Untitled"),
17108
- createElement("div", { style: descStyle }, card.description || ""),
17031
+ editingTitle ? createElement("input", {
17032
+ ref: titleInputRef,
17033
+ type: "text",
17034
+ value: titleDraft,
17035
+ onInput: handleTitleInput,
17036
+ style: {
17037
+ ...titleStyle,
17038
+ width: "100%",
17039
+ border: "none",
17040
+ outline: "none",
17041
+ backgroundColor: "transparent",
17042
+ padding: "0",
17043
+ margin: "0",
17044
+ fontFamily: "inherit",
17045
+ boxSizing: "border-box"
17046
+ },
17047
+ "data-role": "inline-edit",
17048
+ "data-testid": `card-title-input-${card.id}`,
17049
+ onKeyDown: handleTitleKeyDown,
17050
+ onBlur: handleTitleBlur,
17051
+ onMouseDown: (e) => e.stopPropagation()
17052
+ }) : createElement("div", {
17053
+ style: titleStyle,
17054
+ onDblClick: handleTitleDoubleClick,
17055
+ "data-testid": `card-title-${card.id}`
17056
+ }, card.title || "Untitled"),
17057
+ editingDescription ? createElement("textarea", {
17058
+ ref: descTextareaRef,
17059
+ value: descDraft,
17060
+ onInput: handleDescInput,
17061
+ style: {
17062
+ ...descStyle,
17063
+ width: "100%",
17064
+ border: "none",
17065
+ outline: "none",
17066
+ backgroundColor: "transparent",
17067
+ padding: "0",
17068
+ margin: "0",
17069
+ fontFamily: "inherit",
17070
+ resize: "none",
17071
+ boxSizing: "border-box"
17072
+ },
17073
+ "data-role": "inline-edit",
17074
+ "data-testid": `card-desc-input-${card.id}`,
17075
+ onKeyDown: handleDescriptionKeyDown,
17076
+ onBlur: handleDescriptionBlur,
17077
+ onMouseDown: (e) => e.stopPropagation()
17078
+ }) : createElement("div", {
17079
+ style: descStyle,
17080
+ onClick: handleDescriptionClick,
17081
+ "data-testid": `card-desc-${card.id}`
17082
+ }, card.description || ""),
17109
17083
  tagsEl,
17084
+ assigneeEl,
17085
+ createElement("div", {
17086
+ style: dragHandleStyle,
17087
+ "data-role": "drag-handle",
17088
+ "data-testid": `card-drag-handle-${card.id}`,
17089
+ onMouseDown: (e) => {
17090
+ e.stopPropagation();
17091
+ onDragHandleMouseDown(e);
17092
+ },
17093
+ "aria-label": `Export drag handle for ${card.title}`,
17094
+ title: "Drag to export card"
17095
+ }, "\u2630"),
17110
17096
  createElement("button", {
17111
17097
  style: deleteStyle,
17112
17098
  "data-role": "delete",
@@ -17153,8 +17139,7 @@ function Card2(props) {
17153
17139
  "data-testid": `anchor-left-${card.id}`,
17154
17140
  onMouseDown: (e) => handleAnchorMouseDown("left", e),
17155
17141
  "aria-label": "Connection anchor left"
17156
- }),
17157
- contextMenuEl
17142
+ })
17158
17143
  );
17159
17144
  }
17160
17145
 
@@ -17344,13 +17329,22 @@ function ConnectionsOverlay(props) {
17344
17329
  const isSelected = conn.id === selectedConnectionId;
17345
17330
  const strokeColor = isSelected ? "#3b82f6" : "#94a3b8";
17346
17331
  const dashArray = getStrokeDasharray(conn.style);
17332
+ const dx = to.x - from.x;
17333
+ const dy = to.y - from.y;
17334
+ const dist = Math.sqrt(dx * dx + dy * dy);
17335
+ const curveOffset = Math.min(40, dist * 0.15);
17336
+ const nx = dist > 0 ? -dy / dist : 0;
17337
+ const ny = dist > 0 ? dx / dist : 0;
17338
+ const midX = (from.x + to.x) / 2;
17339
+ const midY = (from.y + to.y) / 2;
17340
+ const cpX = midX + nx * curveOffset;
17341
+ const cpY = midY + ny * curveOffset;
17342
+ const pathD = `M ${from.x} ${from.y} Q ${cpX} ${cpY} ${to.x} ${to.y}`;
17347
17343
  lineElements.push(
17348
- createElement("line", {
17344
+ createElement("path", {
17349
17345
  key: `hit-${conn.id}`,
17350
- x1: String(from.x),
17351
- y1: String(from.y),
17352
- x2: String(to.x),
17353
- y2: String(to.y),
17346
+ d: pathD,
17347
+ fill: "none",
17354
17348
  stroke: "transparent",
17355
17349
  "stroke-width": "12",
17356
17350
  style: { cursor: "pointer" },
@@ -17359,12 +17353,10 @@ function ConnectionsOverlay(props) {
17359
17353
  })
17360
17354
  );
17361
17355
  lineElements.push(
17362
- createElement("line", {
17356
+ createElement("path", {
17363
17357
  key: conn.id,
17364
- x1: String(from.x),
17365
- y1: String(from.y),
17366
- x2: String(to.x),
17367
- y2: String(to.y),
17358
+ d: pathD,
17359
+ fill: "none",
17368
17360
  stroke: strokeColor,
17369
17361
  "stroke-width": isSelected ? "3" : "2",
17370
17362
  "stroke-dasharray": dashArray,
@@ -17373,13 +17365,11 @@ function ConnectionsOverlay(props) {
17373
17365
  })
17374
17366
  );
17375
17367
  if (conn.label) {
17376
- const midX = (from.x + to.x) / 2;
17377
- const midY = (from.y + to.y) / 2;
17378
17368
  lineElements.push(
17379
17369
  createElement("text", {
17380
17370
  key: `label-${conn.id}`,
17381
- x: String(midX),
17382
- y: String(midY - 6),
17371
+ x: String(cpX),
17372
+ y: String(cpY - 6),
17383
17373
  "text-anchor": "middle",
17384
17374
  fill: "#64748b",
17385
17375
  "font-size": "11",
@@ -17454,10 +17444,14 @@ function generateConnectionId() {
17454
17444
  return `conn-${Date.now()}-${connIdCounter}`;
17455
17445
  }
17456
17446
  function Board(props) {
17457
- const { state, dispatch, searchQuery, gridEnabled, selectedCardId, onSelectCard, colorFilter } = props;
17447
+ const { state, dispatch, searchQuery, gridEnabled, selectedCardId, onSelectCard, colorFilter, showConnections } = props;
17448
+ const shouldShowConnections = showConnections !== false;
17458
17449
  const { cards, connections, viewport } = state;
17459
17450
  const [editingCardId, setEditingCardId] = useState(null);
17460
17451
  const [selectedConnectionId, setSelectedConnectionId] = useState(null);
17452
+ const [cardContextMenu, setCardContextMenu] = useState(null);
17453
+ const [colorSubmenuOpen, setColorSubmenuOpen] = useState(false);
17454
+ const [prioritySubmenuOpen, setPrioritySubmenuOpen] = useState(false);
17461
17455
  const containerRef = useRef(null);
17462
17456
  const isPanningRef = useRef(false);
17463
17457
  const panStartRef = useRef(null);
@@ -17514,6 +17508,63 @@ function Board(props) {
17514
17508
  const delta = we.deltaY > 0 ? -0.1 : 0.1;
17515
17509
  dispatch({ type: "ZOOM", zoom: viewport.zoom + delta });
17516
17510
  }, [viewport.zoom, dispatch]);
17511
+ const touchStartRef = useRef(null);
17512
+ useEffect(() => {
17513
+ const container = containerRef.current;
17514
+ if (!container) return;
17515
+ const getTouchPoints = (e) => {
17516
+ const pts = [];
17517
+ for (let i = 0; i < e.touches.length; i++) {
17518
+ pts.push({ x: e.touches[i].clientX, y: e.touches[i].clientY });
17519
+ }
17520
+ return pts;
17521
+ };
17522
+ const getDist = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
17523
+ const handleTouchStart = (e) => {
17524
+ const te = e;
17525
+ if (te.touches.length === 2) {
17526
+ te.preventDefault();
17527
+ const pts = getTouchPoints(te);
17528
+ touchStartRef.current = {
17529
+ touches: pts,
17530
+ panX: viewport.panX,
17531
+ panY: viewport.panY,
17532
+ zoom: viewport.zoom,
17533
+ dist: getDist(pts[0], pts[1])
17534
+ };
17535
+ }
17536
+ };
17537
+ const handleTouchMove = (e) => {
17538
+ const te = e;
17539
+ if (te.touches.length !== 2 || !touchStartRef.current) return;
17540
+ te.preventDefault();
17541
+ const pts = getTouchPoints(te);
17542
+ const start = touchStartRef.current;
17543
+ const startMidX = (start.touches[0].x + start.touches[1].x) / 2;
17544
+ const startMidY = (start.touches[0].y + start.touches[1].y) / 2;
17545
+ const curMidX = (pts[0].x + pts[1].x) / 2;
17546
+ const curMidY = (pts[0].y + pts[1].y) / 2;
17547
+ const dx = curMidX - startMidX;
17548
+ const dy = curMidY - startMidY;
17549
+ dispatch({ type: "PAN", panX: start.panX + dx, panY: start.panY + dy });
17550
+ const curDist = getDist(pts[0], pts[1]);
17551
+ if (start.dist > 0) {
17552
+ const scale = curDist / start.dist;
17553
+ dispatch({ type: "ZOOM", zoom: start.zoom * scale });
17554
+ }
17555
+ };
17556
+ const handleTouchEnd = () => {
17557
+ touchStartRef.current = null;
17558
+ };
17559
+ container.addEventListener("touchstart", handleTouchStart, { passive: false });
17560
+ container.addEventListener("touchmove", handleTouchMove, { passive: false });
17561
+ container.addEventListener("touchend", handleTouchEnd);
17562
+ return () => {
17563
+ container.removeEventListener("touchstart", handleTouchStart);
17564
+ container.removeEventListener("touchmove", handleTouchMove);
17565
+ container.removeEventListener("touchend", handleTouchEnd);
17566
+ };
17567
+ }, [viewport.panX, viewport.panY, viewport.zoom, dispatch]);
17517
17568
  useEffect(() => {
17518
17569
  const handleKeyDown = (e) => {
17519
17570
  const ke = e;
@@ -17551,9 +17602,11 @@ function Board(props) {
17551
17602
  dispatch({ type: "REMOVE_CARD", cardId });
17552
17603
  if (selectedCardId === cardId) onSelectCard(null);
17553
17604
  }, [dispatch, selectedCardId, onSelectCard]);
17554
- const handleDoubleClickCard = useCallback((cardId) => {
17555
- setEditingCardId(cardId);
17605
+ const handleDoubleClickCard = useCallback((_cardId) => {
17556
17606
  }, []);
17607
+ const handleUpdateCard = useCallback((cardId, updates) => {
17608
+ dispatch({ type: "UPDATE_CARD", cardId, updates });
17609
+ }, [dispatch]);
17557
17610
  const handleEditorSave = useCallback((cardId, updates) => {
17558
17611
  dispatch({ type: "UPDATE_CARD", cardId, updates });
17559
17612
  }, [dispatch]);
@@ -17578,6 +17631,67 @@ function Board(props) {
17578
17631
  const handleChangePriority = useCallback((cardId, priority) => {
17579
17632
  dispatch({ type: "UPDATE_CARD", cardId, updates: { priority } });
17580
17633
  }, [dispatch]);
17634
+ const handleCardContextMenu = useCallback((cardId, pos) => {
17635
+ setCardContextMenu({ cardId, x: pos.x, y: pos.y });
17636
+ setColorSubmenuOpen(false);
17637
+ setPrioritySubmenuOpen(false);
17638
+ }, []);
17639
+ const closeCardContextMenu = useCallback(() => {
17640
+ setCardContextMenu(null);
17641
+ setColorSubmenuOpen(false);
17642
+ setPrioritySubmenuOpen(false);
17643
+ }, []);
17644
+ useEffect(() => {
17645
+ if (!cardContextMenu) return;
17646
+ const handleClick = () => {
17647
+ closeCardContextMenu();
17648
+ };
17649
+ const timer = setTimeout(() => {
17650
+ document.addEventListener("click", handleClick);
17651
+ document.addEventListener("contextmenu", handleClick);
17652
+ }, 0);
17653
+ return () => {
17654
+ clearTimeout(timer);
17655
+ document.removeEventListener("click", handleClick);
17656
+ document.removeEventListener("contextmenu", handleClick);
17657
+ };
17658
+ }, [cardContextMenu, closeCardContextMenu]);
17659
+ const handleCtxDuplicateClick = useCallback((e) => {
17660
+ e.stopPropagation();
17661
+ if (cardContextMenu) {
17662
+ const newId = `card-${Date.now()}-dup`;
17663
+ dispatch({ type: "DUPLICATE_CARD", cardId: cardContextMenu.cardId, newId });
17664
+ }
17665
+ closeCardContextMenu();
17666
+ }, [cardContextMenu, dispatch, closeCardContextMenu]);
17667
+ const handleCtxDeleteClick = useCallback((e) => {
17668
+ e.stopPropagation();
17669
+ if (cardContextMenu) {
17670
+ dispatch({ type: "REMOVE_CARD", cardId: cardContextMenu.cardId });
17671
+ if (selectedCardId === cardContextMenu.cardId) onSelectCard(null);
17672
+ }
17673
+ closeCardContextMenu();
17674
+ }, [cardContextMenu, dispatch, selectedCardId, onSelectCard, closeCardContextMenu]);
17675
+ const handleCtxColorMenuEnter = useCallback(() => {
17676
+ setColorSubmenuOpen(true);
17677
+ setPrioritySubmenuOpen(false);
17678
+ }, []);
17679
+ const handleCtxPriorityMenuEnter = useCallback(() => {
17680
+ setPrioritySubmenuOpen(true);
17681
+ setColorSubmenuOpen(false);
17682
+ }, []);
17683
+ const handleCtxColorSelect = useCallback((color) => {
17684
+ if (cardContextMenu) {
17685
+ dispatch({ type: "UPDATE_CARD", cardId: cardContextMenu.cardId, updates: { color } });
17686
+ }
17687
+ closeCardContextMenu();
17688
+ }, [cardContextMenu, dispatch, closeCardContextMenu]);
17689
+ const handleCtxPrioritySelect = useCallback((priority) => {
17690
+ if (cardContextMenu) {
17691
+ dispatch({ type: "UPDATE_CARD", cardId: cardContextMenu.cardId, updates: { priority } });
17692
+ }
17693
+ closeCardContextMenu();
17694
+ }, [cardContextMenu, dispatch, closeCardContextMenu]);
17581
17695
  const handleAnchorDragStart = useCallback((cardId, anchor, ax, ay) => {
17582
17696
  setConnectionDrag({
17583
17697
  fromCardId: cardId,
@@ -17673,10 +17787,12 @@ function Board(props) {
17673
17787
  onResize: handleResizeCard,
17674
17788
  onDelete: handleDeleteCard,
17675
17789
  onDoubleClick: handleDoubleClickCard,
17790
+ onUpdate: handleUpdateCard,
17676
17791
  onDuplicate: handleDuplicateCard,
17677
17792
  onChangeColor: handleChangeColor,
17678
17793
  onChangePriority: handleChangePriority,
17679
- onAnchorDragStart: handleAnchorDragStart
17794
+ onAnchorDragStart: handleAnchorDragStart,
17795
+ onCardContextMenu: handleCardContextMenu
17680
17796
  });
17681
17797
  if (isDimmed) {
17682
17798
  return createElement("div", {
@@ -17709,16 +17825,175 @@ function Board(props) {
17709
17825
  height: String(CANVAS_SIZE),
17710
17826
  "data-testid": "connection-drag-line"
17711
17827
  },
17712
- createElement("line", {
17713
- x1: String(connectionDrag.fromX),
17714
- y1: String(connectionDrag.fromY),
17715
- x2: String(connectionDrag.toX),
17716
- y2: String(connectionDrag.toY),
17717
- stroke: "#3b82f6",
17718
- "stroke-width": "2",
17719
- "stroke-dasharray": "6,4",
17720
- "pointer-events": "none"
17721
- })
17828
+ createElement("line", {
17829
+ x1: String(connectionDrag.fromX),
17830
+ y1: String(connectionDrag.fromY),
17831
+ x2: String(connectionDrag.toX),
17832
+ y2: String(connectionDrag.toY),
17833
+ stroke: "#3b82f6",
17834
+ "stroke-width": "2",
17835
+ "stroke-dasharray": "6,4",
17836
+ "pointer-events": "none"
17837
+ })
17838
+ ) : null;
17839
+ const ctxMenuItemStyle = {
17840
+ padding: "6px 12px",
17841
+ cursor: "pointer",
17842
+ display: "flex",
17843
+ alignItems: "center",
17844
+ justifyContent: "space-between",
17845
+ whiteSpace: "nowrap"
17846
+ };
17847
+ const ctxSubmenuContainerStyle = {
17848
+ position: "absolute",
17849
+ left: "100%",
17850
+ top: "0",
17851
+ backgroundColor: "#ffffff",
17852
+ border: "1px solid #d1d5db",
17853
+ borderRadius: "6px",
17854
+ boxShadow: "0 4px 16px rgba(0,0,0,0.15)",
17855
+ padding: "4px 0",
17856
+ minWidth: "120px"
17857
+ };
17858
+ const contextMenuCard = cardContextMenu ? cards.find((c) => c.id === cardContextMenu.cardId) : null;
17859
+ const contextMenuEl = cardContextMenu ? createElement(
17860
+ "div",
17861
+ {
17862
+ className: "card-context-menu",
17863
+ style: {
17864
+ position: "fixed",
17865
+ left: `${cardContextMenu.x}px`,
17866
+ top: `${cardContextMenu.y}px`,
17867
+ backgroundColor: "#ffffff",
17868
+ border: "1px solid #d1d5db",
17869
+ borderRadius: "6px",
17870
+ boxShadow: "0 4px 16px rgba(0,0,0,0.15)",
17871
+ padding: "4px 0",
17872
+ zIndex: "10000",
17873
+ minWidth: "160px",
17874
+ fontSize: "13px",
17875
+ color: "#1a1a1a"
17876
+ },
17877
+ "data-testid": `context-menu-${cardContextMenu.cardId}`,
17878
+ role: "menu",
17879
+ "aria-label": "Card context menu"
17880
+ },
17881
+ // Duplicate
17882
+ createElement("div", {
17883
+ style: ctxMenuItemStyle,
17884
+ onClick: handleCtxDuplicateClick,
17885
+ role: "menuitem",
17886
+ "data-testid": `context-menu-duplicate-${cardContextMenu.cardId}`
17887
+ }, "Duplicate"),
17888
+ // Delete
17889
+ createElement("div", {
17890
+ style: ctxMenuItemStyle,
17891
+ onClick: handleCtxDeleteClick,
17892
+ role: "menuitem",
17893
+ "data-testid": `context-menu-delete-${cardContextMenu.cardId}`
17894
+ }, "Delete"),
17895
+ // Change Color submenu
17896
+ createElement(
17897
+ "div",
17898
+ {
17899
+ style: { ...ctxMenuItemStyle, position: "relative" },
17900
+ onMouseEnter: handleCtxColorMenuEnter,
17901
+ role: "menuitem",
17902
+ "aria-haspopup": "true",
17903
+ "data-testid": `context-menu-color-${cardContextMenu.cardId}`
17904
+ },
17905
+ "Change Color",
17906
+ createElement("span", { style: { marginLeft: "8px" } }, "\u25B6"),
17907
+ colorSubmenuOpen ? createElement(
17908
+ "div",
17909
+ {
17910
+ style: ctxSubmenuContainerStyle,
17911
+ role: "menu",
17912
+ "data-testid": `context-submenu-color-${cardContextMenu.cardId}`
17913
+ },
17914
+ ...CONTEXT_MENU_COLORS.map(
17915
+ (color) => createElement(
17916
+ "div",
17917
+ {
17918
+ key: color,
17919
+ style: {
17920
+ ...ctxMenuItemStyle,
17921
+ gap: "8px"
17922
+ },
17923
+ onClick: (e) => {
17924
+ e.stopPropagation();
17925
+ handleCtxColorSelect(color);
17926
+ },
17927
+ role: "menuitem",
17928
+ "data-testid": `context-color-${color}`
17929
+ },
17930
+ createElement("span", {
17931
+ style: {
17932
+ width: "14px",
17933
+ height: "14px",
17934
+ borderRadius: "50%",
17935
+ backgroundColor: color,
17936
+ border: "1px solid rgba(0,0,0,0.15)",
17937
+ display: "inline-block",
17938
+ flexShrink: "0"
17939
+ }
17940
+ }),
17941
+ contextMenuCard && color === contextMenuCard.color ? "\u2713" : ""
17942
+ )
17943
+ )
17944
+ ) : null
17945
+ ),
17946
+ // Set Priority submenu
17947
+ createElement(
17948
+ "div",
17949
+ {
17950
+ style: { ...ctxMenuItemStyle, position: "relative" },
17951
+ onMouseEnter: handleCtxPriorityMenuEnter,
17952
+ role: "menuitem",
17953
+ "aria-haspopup": "true",
17954
+ "data-testid": `context-menu-priority-${cardContextMenu.cardId}`
17955
+ },
17956
+ "Set Priority",
17957
+ createElement("span", { style: { marginLeft: "8px" } }, "\u25B6"),
17958
+ prioritySubmenuOpen ? createElement(
17959
+ "div",
17960
+ {
17961
+ style: ctxSubmenuContainerStyle,
17962
+ role: "menu",
17963
+ "data-testid": `context-submenu-priority-${cardContextMenu.cardId}`
17964
+ },
17965
+ ...PRIORITY_OPTIONS.map(
17966
+ (opt) => createElement(
17967
+ "div",
17968
+ {
17969
+ key: opt.value,
17970
+ style: {
17971
+ ...ctxMenuItemStyle,
17972
+ gap: "8px"
17973
+ },
17974
+ onClick: (e) => {
17975
+ e.stopPropagation();
17976
+ handleCtxPrioritySelect(opt.value);
17977
+ },
17978
+ role: "menuitem",
17979
+ "data-testid": `context-priority-${opt.value}`
17980
+ },
17981
+ createElement("span", {
17982
+ style: {
17983
+ width: "8px",
17984
+ height: "8px",
17985
+ borderRadius: "50%",
17986
+ backgroundColor: PRIORITY_COLORS[opt.value] || "#94a3b8",
17987
+ display: "inline-block",
17988
+ flexShrink: "0"
17989
+ }
17990
+ }),
17991
+ opt.label,
17992
+ contextMenuCard && opt.value === contextMenuCard.priority ? " \u2713" : ""
17993
+ )
17994
+ )
17995
+ ) : null
17996
+ )
17722
17997
  ) : null;
17723
17998
  return createElement(
17724
17999
  "div",
@@ -17740,7 +18015,7 @@ function Board(props) {
17740
18015
  style: transformStyle,
17741
18016
  "data-testid": "board-canvas-inner"
17742
18017
  },
17743
- createElement(ConnectionsOverlay, {
18018
+ shouldShowConnections ? createElement(ConnectionsOverlay, {
17744
18019
  connections,
17745
18020
  cards,
17746
18021
  selectedConnectionId,
@@ -17748,17 +18023,20 @@ function Board(props) {
17748
18023
  onDeleteConnection: handleDeleteConnection,
17749
18024
  canvasWidth: CANVAS_SIZE,
17750
18025
  canvasHeight: CANVAS_SIZE
17751
- }),
18026
+ }) : null,
17752
18027
  connectionDragLine,
17753
18028
  ...cardElements
17754
18029
  ),
17755
- editorEl
18030
+ editorEl,
18031
+ contextMenuEl
17756
18032
  );
17757
18033
  }
17758
18034
 
17759
18035
  // ../demos/project-manager/src/BoardState.ts
17760
18036
  var MAX_HISTORY = 50;
17761
18037
  var DEFAULT_BOARD_STATE = {
18038
+ id: crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`,
18039
+ name: "Untitled",
17762
18040
  cards: [],
17763
18041
  connections: [],
17764
18042
  viewport: { panX: 0, panY: 0, zoom: 1 }
@@ -18042,12 +18320,14 @@ function generateCardId() {
18042
18320
  }
18043
18321
  var storage = new LocalBoardStorage();
18044
18322
  var SAMPLE_CARDS = [
18045
- { id: "sample-1", title: "Auth API", description: "Design the auth flow", color: "#3b82f6", position: { x: 50, y: 50 }, size: { width: 180, height: 120 }, priority: "high", createdAt: Date.now(), updatedAt: Date.now() },
18046
- { id: "sample-2", title: "Dashboard", description: "Build the main dashboard", color: "#22c55e", position: { x: 300, y: 80 }, size: { width: 180, height: 120 }, priority: "medium", createdAt: Date.now(), updatedAt: Date.now() },
18323
+ { id: "sample-1", title: "Auth API", description: "Design the auth flow", color: "#3b82f6", position: { x: 50, y: 50 }, size: { width: 180, height: 120 }, priority: "high", assignee: "Alice", createdAt: Date.now(), updatedAt: Date.now() },
18324
+ { id: "sample-2", title: "Dashboard", description: "Build the main dashboard", color: "#22c55e", position: { x: 300, y: 80 }, size: { width: 180, height: 120 }, priority: "medium", assignee: "Bob", createdAt: Date.now(), updatedAt: Date.now() },
18047
18325
  { id: "sample-3", title: "Deploy", description: "Set up CI pipeline", color: "#f59e0b", position: { x: 150, y: 250 }, size: { width: 180, height: 120 }, priority: "low", createdAt: Date.now(), updatedAt: Date.now() },
18048
- { id: "sample-4", title: "Docs", description: "Write API reference", color: "#a855f7", position: { x: 400, y: 280 }, size: { width: 180, height: 120 }, priority: "medium", createdAt: Date.now(), updatedAt: Date.now() }
18326
+ { id: "sample-4", title: "Docs", description: "Write API reference", color: "#a855f7", position: { x: 400, y: 280 }, size: { width: 180, height: 120 }, priority: "medium", assignee: "Carol", createdAt: Date.now(), updatedAt: Date.now() }
18049
18327
  ];
18050
18328
  var SAMPLE_BOARD = {
18329
+ id: "sample-board-001",
18330
+ name: "Sample Project",
18051
18331
  cards: SAMPLE_CARDS,
18052
18332
  connections: [
18053
18333
  { id: "sample-conn-1", fromCardId: "sample-1", toCardId: "sample-2" }
@@ -18065,6 +18345,10 @@ function ProjectManagerApp(props) {
18065
18345
  const [searchQuery, setSearchQuery] = useState("");
18066
18346
  const [selectedCardId, setSelectedCardId] = useState(null);
18067
18347
  const [colorFilter, setColorFilter] = useState(null);
18348
+ const [showConnections, setShowConnections] = useState(true);
18349
+ const [projectName, setProjectName] = useState(state.name || "Untitled");
18350
+ const [showRenameDialog, setShowRenameDialog] = useState(false);
18351
+ const [renameDraft, setRenameDraft] = useState("");
18068
18352
  const sampleLoadedRef = useRef(false);
18069
18353
  useEffect(() => {
18070
18354
  if (!sampleLoadedRef.current && isBoardEmpty(state)) {
@@ -18077,12 +18361,14 @@ function ProjectManagerApp(props) {
18077
18361
  const handleNewCard = useCallback(() => {
18078
18362
  const cx = (-state.viewport.panX + 300) / state.viewport.zoom;
18079
18363
  const cy = (-state.viewport.panY + 200) / state.viewport.zoom;
18364
+ const offsetX = (Math.random() - 0.5) * 300;
18365
+ const offsetY = (Math.random() - 0.5) * 200;
18080
18366
  const newCard = {
18081
18367
  id: generateCardId(),
18082
18368
  title: "New Card",
18083
18369
  description: "",
18084
18370
  color: selectedColor,
18085
- position: { x: Math.round(cx), y: Math.round(cy) },
18371
+ position: { x: Math.round(cx + offsetX), y: Math.round(cy + offsetY) },
18086
18372
  size: { width: 180, height: 120 },
18087
18373
  priority: "medium",
18088
18374
  createdAt: Date.now(),
@@ -18128,6 +18414,41 @@ function ProjectManagerApp(props) {
18128
18414
  document.body.removeChild(a);
18129
18415
  URL.revokeObjectURL(url);
18130
18416
  }, [state, boardId]);
18417
+ const handleImportJSON = useCallback(() => {
18418
+ const input = document.createElement("input");
18419
+ input.type = "file";
18420
+ input.accept = ".json,application/json";
18421
+ input.style.display = "none";
18422
+ input.addEventListener("change", () => {
18423
+ const file = input.files && input.files[0];
18424
+ if (!file) return;
18425
+ const reader = new FileReader();
18426
+ reader.onload = () => {
18427
+ try {
18428
+ const parsed = JSON.parse(reader.result);
18429
+ if (parsed && parsed.cards && parsed.viewport) {
18430
+ dispatch({ type: "SET_BOARD", state: parsed });
18431
+ }
18432
+ } catch (_e) {
18433
+ }
18434
+ };
18435
+ reader.readAsText(file);
18436
+ });
18437
+ document.body.appendChild(input);
18438
+ input.click();
18439
+ document.body.removeChild(input);
18440
+ }, [dispatch]);
18441
+ const handlePrint = useCallback(() => {
18442
+ window.print();
18443
+ }, []);
18444
+ const handleSelectAll = useCallback(() => {
18445
+ if (state.cards.length > 0) {
18446
+ setSelectedCardId(state.cards[0].id);
18447
+ }
18448
+ }, [state.cards]);
18449
+ const handleToggleConnections = useCallback(() => {
18450
+ setShowConnections((prev) => !prev);
18451
+ }, []);
18131
18452
  const handleDeleteSelected = useCallback(() => {
18132
18453
  if (selectedCardId) {
18133
18454
  dispatch({ type: "REMOVE_CARD", cardId: selectedCardId });
@@ -18142,18 +18463,47 @@ function ProjectManagerApp(props) {
18142
18463
  dispatch({ type: "PAN", panX: fit.panX, panY: fit.panY });
18143
18464
  dispatch({ type: "ZOOM", zoom: fit.zoom });
18144
18465
  }, [state.cards, dispatch]);
18466
+ const handleRenameProject = useCallback(() => {
18467
+ setRenameDraft(projectName);
18468
+ setShowRenameDialog(true);
18469
+ }, [projectName]);
18470
+ const handleRenameConfirm = useCallback(() => {
18471
+ const name = renameDraft.trim();
18472
+ if (name) setProjectName(name);
18473
+ setShowRenameDialog(false);
18474
+ }, [renameDraft]);
18475
+ const handleRenameCancel = useCallback(() => {
18476
+ setShowRenameDialog(false);
18477
+ }, []);
18478
+ const handleRenameDraftChange = useCallback((e) => {
18479
+ setRenameDraft(e.target.value);
18480
+ }, []);
18481
+ const handleRenameKeyDown = useCallback((e) => {
18482
+ const ke = e;
18483
+ if (ke.key === "Enter") {
18484
+ ke.preventDefault();
18485
+ handleRenameConfirm();
18486
+ }
18487
+ if (ke.key === "Escape") {
18488
+ ke.preventDefault();
18489
+ handleRenameCancel();
18490
+ }
18491
+ }, [handleRenameConfirm, handleRenameCancel]);
18145
18492
  useEffect(() => {
18146
18493
  const _menuBar = {
18147
18494
  menus: [
18148
18495
  { label: "File", items: [
18149
18496
  { label: "New Board", onClick: handleNewBoard },
18150
18497
  { label: "Export JSON", onClick: handleExportJSON },
18151
- { divider: true }
18498
+ { label: "Import JSON", onClick: handleImportJSON },
18499
+ { divider: true },
18500
+ { label: "Print", onClick: handlePrint }
18152
18501
  ] },
18153
18502
  { label: "Edit", items: [
18154
18503
  { label: "Undo", shortcut: "Ctrl+Z", onClick: undo, disabled: !canUndo },
18155
18504
  { label: "Redo", shortcut: "Ctrl+Y", onClick: redo, disabled: !canRedo },
18156
18505
  { divider: true },
18506
+ { label: "Select All", shortcut: "Ctrl+A", onClick: handleSelectAll },
18157
18507
  { label: "Delete Selected", onClick: handleDeleteSelected }
18158
18508
  ] },
18159
18509
  { label: "View", items: [
@@ -18161,11 +18511,12 @@ function ProjectManagerApp(props) {
18161
18511
  { label: "Zoom Out", onClick: handleZoomOut },
18162
18512
  { label: "Fit All", onClick: handleFitAll },
18163
18513
  { divider: true },
18164
- { label: "Toggle Grid", onClick: handleGridToggle }
18514
+ { label: "Toggle Grid", onClick: handleGridToggle },
18515
+ { label: showConnections ? "Hide Connections" : "Show Connections", onClick: handleToggleConnections }
18165
18516
  ] }
18166
18517
  ]
18167
18518
  };
18168
- }, [handleNewBoard, handleExportJSON, undo, redo, canUndo, canRedo, handleDeleteSelected, handleZoomIn, handleZoomOut, handleFitAll, handleGridToggle]);
18519
+ }, [handleNewBoard, handleExportJSON, handleImportJSON, handlePrint, undo, redo, canUndo, canRedo, handleSelectAll, handleDeleteSelected, handleZoomIn, handleZoomOut, handleFitAll, handleGridToggle, handleToggleConnections, showConnections]);
18169
18520
  useEffect(() => {
18170
18521
  const handleKeyDown = (e) => {
18171
18522
  const ke = e;
@@ -18191,12 +18542,14 @@ function ProjectManagerApp(props) {
18191
18542
  const handleCardDropped = useCallback((title, description) => {
18192
18543
  const cx = (-state.viewport.panX + 300) / state.viewport.zoom;
18193
18544
  const cy = (-state.viewport.panY + 200) / state.viewport.zoom;
18545
+ const offsetX = (Math.random() - 0.5) * 300;
18546
+ const offsetY = (Math.random() - 0.5) * 200;
18194
18547
  const newCard = {
18195
18548
  id: generateCardId(),
18196
18549
  title,
18197
18550
  description,
18198
18551
  color: selectedColor,
18199
- position: { x: Math.round(cx), y: Math.round(cy) },
18552
+ position: { x: Math.round(cx + offsetX), y: Math.round(cy + offsetY) },
18200
18553
  size: { width: 180, height: 120 },
18201
18554
  priority: "medium",
18202
18555
  createdAt: Date.now(),
@@ -18204,6 +18557,133 @@ function ProjectManagerApp(props) {
18204
18557
  };
18205
18558
  dispatch({ type: "ADD_CARD", card: newCard });
18206
18559
  }, [state.viewport, selectedColor, dispatch]);
18560
+ const menuBarStyle = {
18561
+ display: "flex",
18562
+ alignItems: "center",
18563
+ height: "28px",
18564
+ backgroundColor: "#f1f5f9",
18565
+ borderBottom: "1px solid #e2e8f0",
18566
+ padding: "0 8px",
18567
+ fontSize: "13px",
18568
+ flexShrink: "0"
18569
+ };
18570
+ const menuBtnStyle = {
18571
+ padding: "2px 10px",
18572
+ border: "none",
18573
+ backgroundColor: "transparent",
18574
+ cursor: "pointer",
18575
+ fontSize: "13px",
18576
+ color: "#334155",
18577
+ borderRadius: "4px",
18578
+ fontFamily: "inherit"
18579
+ };
18580
+ const appMenuBar = createElement(
18581
+ "div",
18582
+ {
18583
+ style: menuBarStyle,
18584
+ "data-testid": "app-menu-bar"
18585
+ },
18586
+ createElement("button", {
18587
+ style: menuBtnStyle,
18588
+ onClick: handleRenameProject,
18589
+ title: "Project menu"
18590
+ }, "Project"),
18591
+ createElement("button", {
18592
+ style: menuBtnStyle,
18593
+ title: "Settings"
18594
+ }, "Settings"),
18595
+ createElement("button", {
18596
+ style: menuBtnStyle,
18597
+ title: "Help"
18598
+ }, "Help"),
18599
+ createElement("span", {
18600
+ style: { marginLeft: "auto", fontSize: "12px", color: "#94a3b8" }
18601
+ }, `Project Board: ${projectName}`)
18602
+ );
18603
+ const renameDialogEl = showRenameDialog ? createElement(
18604
+ "div",
18605
+ {
18606
+ style: {
18607
+ position: "absolute",
18608
+ inset: "0",
18609
+ backgroundColor: "rgba(0,0,0,0.3)",
18610
+ display: "flex",
18611
+ alignItems: "center",
18612
+ justifyContent: "center",
18613
+ zIndex: "200"
18614
+ },
18615
+ onClick: handleRenameCancel
18616
+ },
18617
+ createElement(
18618
+ "div",
18619
+ {
18620
+ style: {
18621
+ backgroundColor: "#ffffff",
18622
+ borderRadius: "8px",
18623
+ padding: "20px",
18624
+ boxShadow: "0 8px 24px rgba(0,0,0,0.2)",
18625
+ minWidth: "300px"
18626
+ },
18627
+ onClick: (e) => e.stopPropagation(),
18628
+ role: "dialog",
18629
+ "aria-label": "Rename project"
18630
+ },
18631
+ createElement("div", {
18632
+ style: { fontWeight: "600", fontSize: "14px", marginBottom: "12px", color: "#1a1a1a" }
18633
+ }, "Rename Project"),
18634
+ createElement("input", {
18635
+ type: "text",
18636
+ value: renameDraft,
18637
+ onInput: handleRenameDraftChange,
18638
+ onKeyDown: handleRenameKeyDown,
18639
+ autoFocus: true,
18640
+ style: {
18641
+ width: "100%",
18642
+ padding: "8px 10px",
18643
+ border: "1px solid #d1d5db",
18644
+ borderRadius: "6px",
18645
+ fontSize: "14px",
18646
+ boxSizing: "border-box",
18647
+ outline: "none",
18648
+ fontFamily: "inherit"
18649
+ },
18650
+ "data-testid": "rename-input"
18651
+ }),
18652
+ createElement(
18653
+ "div",
18654
+ {
18655
+ style: { display: "flex", justifyContent: "flex-end", gap: "8px", marginTop: "12px" }
18656
+ },
18657
+ createElement("button", {
18658
+ onClick: handleRenameCancel,
18659
+ style: {
18660
+ padding: "6px 14px",
18661
+ border: "1px solid #d1d5db",
18662
+ borderRadius: "6px",
18663
+ backgroundColor: "#ffffff",
18664
+ cursor: "pointer",
18665
+ fontSize: "13px",
18666
+ fontFamily: "inherit"
18667
+ }
18668
+ }, "Cancel"),
18669
+ createElement("button", {
18670
+ onClick: handleRenameConfirm,
18671
+ style: {
18672
+ padding: "6px 14px",
18673
+ border: "none",
18674
+ borderRadius: "6px",
18675
+ backgroundColor: "#3b82f6",
18676
+ color: "#ffffff",
18677
+ cursor: "pointer",
18678
+ fontSize: "13px",
18679
+ fontWeight: "600",
18680
+ fontFamily: "inherit"
18681
+ },
18682
+ "data-testid": "rename-confirm"
18683
+ }, "Rename")
18684
+ )
18685
+ )
18686
+ ) : null;
18207
18687
  return createElement(
18208
18688
  "div",
18209
18689
  {
@@ -18211,6 +18691,7 @@ function ProjectManagerApp(props) {
18211
18691
  style: containerStyle3,
18212
18692
  "data-testid": "project-manager-app"
18213
18693
  },
18694
+ appMenuBar,
18214
18695
  createElement(BoardToolbar, {
18215
18696
  zoom: state.viewport.zoom,
18216
18697
  gridEnabled,
@@ -18238,15 +18719,25 @@ function ProjectManagerApp(props) {
18238
18719
  gridEnabled,
18239
18720
  selectedCardId,
18240
18721
  onSelectCard: handleSelectCard,
18241
- colorFilter
18722
+ colorFilter,
18723
+ showConnections
18242
18724
  })
18243
- )
18725
+ ),
18726
+ renameDialogEl
18244
18727
  );
18245
18728
  }
18246
18729
 
18247
18730
  // ../components/page/unity-desktop/src/UnityDesktop.ts
18248
18731
  var PANEL_HEIGHT = 28;
18249
18732
  var TOAST_TIMEOUT = 5e3;
18733
+ var instanceCounter = 0;
18734
+ function nextInstanceId(appId) {
18735
+ instanceCounter++;
18736
+ return `${appId}-${instanceCounter}`;
18737
+ }
18738
+ function baseLabel(title) {
18739
+ return title.replace(/\s*\(\d+\)$/, "");
18740
+ }
18250
18741
  function ToastContainer2(props) {
18251
18742
  const { toasts, onDismiss } = props;
18252
18743
  if (toasts.length === 0) return null;
@@ -18401,7 +18892,8 @@ function getMockContent(title) {
18401
18892
  height: "100%",
18402
18893
  overflow: "auto"
18403
18894
  };
18404
- switch (title) {
18895
+ const baseName = baseLabel(title);
18896
+ switch (baseName) {
18405
18897
  case "Files":
18406
18898
  return createElement(
18407
18899
  AppContextProvider,
@@ -18460,6 +18952,8 @@ function UnityDesktopInner(props) {
18460
18952
  const wm = useWindowManager();
18461
18953
  const wmActiveMenuBar = wm.activeMenuBar;
18462
18954
  const wmDockSignals = wm.dockSignals;
18955
+ const wmRef = useRef(wm);
18956
+ wmRef.current = wm;
18463
18957
  const [openWindows, setOpenWindows] = useState([]);
18464
18958
  const [toasts, setToasts] = useState([]);
18465
18959
  const [showAppsGrid, setShowAppsGrid] = useState(false);
@@ -18487,20 +18981,20 @@ function UnityDesktopInner(props) {
18487
18981
  appsRef.current = apps;
18488
18982
  const onAppOpenRef = useRef(onAppOpen);
18489
18983
  onAppOpenRef.current = onAppOpen;
18490
- const handleDockItemClick = useCallback((id) => {
18984
+ const openNewInstance = useCallback((appId) => {
18985
+ const currentApps = appsRef.current;
18986
+ const app = currentApps.find((a) => a.id === appId);
18987
+ if (!app) return;
18491
18988
  setOpenWindows((prev) => {
18492
- const existing = prev.find((w) => w.id === id);
18493
- if (existing) {
18494
- const maxZ2 = Math.max(...prev.map((w) => w.zIndex)) + 1;
18495
- return prev.map((w) => w.id === id ? { ...w, focused: true, zIndex: maxZ2, windowState: w.windowState === "minimized" ? "normal" : w.windowState } : { ...w, focused: false });
18496
- }
18497
- const currentApps = appsRef.current;
18498
- const app = currentApps.find((a) => a.id === id);
18499
- if (!app) return prev;
18989
+ const existingCount = prev.filter((w) => w.appId === appId).length;
18990
+ const instanceNum = existingCount + 1;
18991
+ const title = instanceNum === 1 ? app.label : `${app.label} (${instanceNum})`;
18992
+ const winId = nextInstanceId(appId);
18500
18993
  const maxZ = prev.length > 0 ? Math.max(...prev.map((w) => w.zIndex)) + 1 : 1;
18501
18994
  const newWin = {
18502
- id: app.id,
18503
- title: app.label,
18995
+ id: winId,
18996
+ appId: app.id,
18997
+ title,
18504
18998
  icon: app.icon,
18505
18999
  x: 60 + prev.length * 30,
18506
19000
  y: 40 + prev.length * 30,
@@ -18512,8 +19006,8 @@ function UnityDesktopInner(props) {
18512
19006
  };
18513
19007
  return [...prev.map((w) => ({ ...w, focused: false })), newWin];
18514
19008
  });
18515
- if (id === "files") {
18516
- wm.setMenuBar("files", {
19009
+ if (appId === "files") {
19010
+ wmRef.current.setMenuBar("files", {
18517
19011
  menus: [
18518
19012
  {
18519
19013
  label: "File",
@@ -18540,13 +19034,90 @@ function UnityDesktopInner(props) {
18540
19034
  ]
18541
19035
  });
18542
19036
  }
18543
- if (id === "terminal") {
18544
- wm.signalDock("terminal", { badge: 3 });
19037
+ if (appId === "terminal") {
19038
+ wmRef.current.signalDock("terminal", { badge: 3 });
18545
19039
  }
18546
- if (onAppOpenRef.current) onAppOpenRef.current(id);
18547
- }, [wm]);
19040
+ if (onAppOpenRef.current) onAppOpenRef.current(appId);
19041
+ }, []);
19042
+ const focusInstance = useCallback((winId) => {
19043
+ setOpenWindows((prev) => {
19044
+ const target = prev.find((w) => w.id === winId);
19045
+ if (!target) return prev;
19046
+ const maxZ = Math.max(...prev.map((w) => w.zIndex)) + 1;
19047
+ return prev.map((w) => w.id === winId ? { ...w, focused: true, zIndex: maxZ, windowState: w.windowState === "minimized" ? "normal" : w.windowState } : { ...w, focused: false });
19048
+ });
19049
+ }, []);
19050
+ const handleDockItemClick = useCallback((appId) => {
19051
+ setOpenWindows((prev) => {
19052
+ const instances = prev.filter((w) => w.appId === appId);
19053
+ if (instances.length === 0) {
19054
+ return prev;
19055
+ }
19056
+ const sorted = [...instances].sort((a, b) => b.zIndex - a.zIndex);
19057
+ const target = sorted[0];
19058
+ const maxZ = Math.max(...prev.map((w) => w.zIndex)) + 1;
19059
+ return prev.map((w) => w.id === target.id ? { ...w, focused: true, zIndex: maxZ, windowState: w.windowState === "minimized" ? "normal" : w.windowState } : { ...w, focused: false });
19060
+ });
19061
+ setOpenWindows((prev) => {
19062
+ const instances = prev.filter((w) => w.appId === appId);
19063
+ if (instances.length === 0) {
19064
+ const currentApps = appsRef.current;
19065
+ const app = currentApps.find((a) => a.id === appId);
19066
+ if (!app) return prev;
19067
+ const winId = nextInstanceId(appId);
19068
+ const maxZ = prev.length > 0 ? Math.max(...prev.map((w) => w.zIndex)) + 1 : 1;
19069
+ const newWin = {
19070
+ id: winId,
19071
+ appId: app.id,
19072
+ title: app.label,
19073
+ icon: app.icon,
19074
+ x: 60 + prev.length * 30,
19075
+ y: 40 + prev.length * 30,
19076
+ width: 600,
19077
+ height: 400,
19078
+ zIndex: maxZ,
19079
+ focused: true,
19080
+ windowState: "normal"
19081
+ };
19082
+ if (appId === "files") {
19083
+ wmRef.current.setMenuBar("files", {
19084
+ menus: [
19085
+ {
19086
+ label: "File",
19087
+ items: [
19088
+ { label: "New", shortcut: "Ctrl+N", onClick: () => {
19089
+ } },
19090
+ { label: "Open", shortcut: "Ctrl+O", onClick: () => {
19091
+ } },
19092
+ { label: "Save", shortcut: "Ctrl+S", onClick: () => {
19093
+ } }
19094
+ ]
19095
+ },
19096
+ {
19097
+ label: "Edit",
19098
+ items: [
19099
+ { label: "Cut", shortcut: "Ctrl+X", onClick: () => {
19100
+ } },
19101
+ { label: "Copy", shortcut: "Ctrl+C", onClick: () => {
19102
+ } },
19103
+ { label: "Paste", shortcut: "Ctrl+V", onClick: () => {
19104
+ } }
19105
+ ]
19106
+ }
19107
+ ]
19108
+ });
19109
+ }
19110
+ if (appId === "terminal") {
19111
+ wmRef.current.signalDock("terminal", { badge: 3 });
19112
+ }
19113
+ if (onAppOpenRef.current) onAppOpenRef.current(appId);
19114
+ return [...prev.map((w) => ({ ...w, focused: false })), newWin];
19115
+ }
19116
+ return prev;
19117
+ });
19118
+ }, []);
18548
19119
  const dockItems = apps.map((app) => {
18549
- const isRunning = openWindows.some((w) => w.id === app.id);
19120
+ const isRunning = openWindows.some((w) => w.appId === app.id);
18550
19121
  const signal = wmDockSignals.get(app.id);
18551
19122
  const item = {
18552
19123
  id: app.id,
@@ -18754,20 +19325,70 @@ function UnityDesktopInner(props) {
18754
19325
  createElement("div", { style: { fontSize: "24px", fontWeight: "600", marginBottom: "8px" } }, "Locked"),
18755
19326
  createElement("div", { style: { fontSize: "14px", opacity: "0.7" } }, "Click to unlock")
18756
19327
  ) : null;
18757
- const contextMenuEl = contextMenuAppId ? createElement(
18758
- "div",
18759
- {
18760
- className: "unity-desktop__context-menu-backdrop",
18761
- style: {
18762
- position: "absolute",
18763
- inset: "0",
18764
- zIndex: "9000"
19328
+ const contextMenuEl = (() => {
19329
+ if (!contextMenuAppId) return null;
19330
+ const ctxApp = apps.find((a) => a.id === contextMenuAppId);
19331
+ const ctxInstances = openWindows.filter((w) => w.appId === contextMenuAppId);
19332
+ const menuItemStyle = { padding: "6px 14px", cursor: "pointer" };
19333
+ const menuItemHoverHandlers = {
19334
+ onMouseEnter: (e) => {
19335
+ e.currentTarget.style.backgroundColor = "#444";
18765
19336
  },
18766
- onClick: closeContextMenu
18767
- },
18768
- createElement(
19337
+ onMouseLeave: (e) => {
19338
+ e.currentTarget.style.backgroundColor = "transparent";
19339
+ }
19340
+ };
19341
+ const separatorStyle = { borderBottom: "1px solid #444", margin: "4px 0" };
19342
+ const menuChildren = [];
19343
+ menuChildren.push(createElement("div", {
19344
+ key: "new",
19345
+ style: menuItemStyle,
19346
+ ...menuItemHoverHandlers,
19347
+ onClick: () => {
19348
+ openNewInstance(contextMenuAppId);
19349
+ setContextMenuAppId(null);
19350
+ },
19351
+ role: "menuitem"
19352
+ }, "\u25CF New"));
19353
+ if (ctxInstances.length > 0) {
19354
+ menuChildren.push(createElement("div", { key: "sep-1", style: separatorStyle }));
19355
+ ctxInstances.forEach((inst, idx) => {
19356
+ const displayLabel = ctxInstances.length === 1 ? ctxApp?.label || inst.title : `${ctxApp?.label || baseLabel(inst.title)} (${idx + 1})`;
19357
+ menuChildren.push(createElement("div", {
19358
+ key: `inst-${inst.id}`,
19359
+ style: menuItemStyle,
19360
+ ...menuItemHoverHandlers,
19361
+ onClick: () => {
19362
+ focusInstance(inst.id);
19363
+ setContextMenuAppId(null);
19364
+ },
19365
+ role: "menuitem"
19366
+ }, displayLabel));
19367
+ });
19368
+ }
19369
+ menuChildren.push(createElement("div", { key: "sep-2", style: separatorStyle }));
19370
+ menuChildren.push(createElement("div", {
19371
+ key: "about",
19372
+ style: menuItemStyle,
19373
+ ...menuItemHoverHandlers,
19374
+ onClick: () => {
19375
+ setAboutAppId(contextMenuAppId);
19376
+ setContextMenuAppId(null);
19377
+ },
19378
+ role: "menuitem"
19379
+ }, "About"));
19380
+ return createElement(
18769
19381
  "div",
18770
19382
  {
19383
+ className: "unity-desktop__context-menu-backdrop",
19384
+ style: {
19385
+ position: "absolute",
19386
+ inset: "0",
19387
+ zIndex: "9000"
19388
+ },
19389
+ onClick: closeContextMenu
19390
+ },
19391
+ createElement("div", {
18771
19392
  className: "unity-desktop__context-menu",
18772
19393
  style: {
18773
19394
  position: "absolute",
@@ -18784,20 +19405,9 @@ function UnityDesktopInner(props) {
18784
19405
  fontSize: "13px"
18785
19406
  },
18786
19407
  onClick: (e) => e.stopPropagation()
18787
- },
18788
- createElement("div", {
18789
- style: { padding: "6px 14px", fontWeight: "600", borderBottom: "1px solid #444", marginBottom: "4px" }
18790
- }, apps.find((a) => a.id === contextMenuAppId)?.label || contextMenuAppId),
18791
- createElement("div", {
18792
- style: { padding: "6px 14px", cursor: "pointer" },
18793
- onClick: () => {
18794
- setAboutAppId(contextMenuAppId);
18795
- setContextMenuAppId(null);
18796
- },
18797
- role: "menuitem"
18798
- }, "About")
18799
- )
18800
- ) : null;
19408
+ }, ...menuChildren)
19409
+ );
19410
+ })();
18801
19411
  const aboutApp = aboutAppId ? apps.find((a) => a.id === aboutAppId) : null;
18802
19412
  const aboutDialogEl = aboutApp ? createElement(
18803
19413
  "div",