@asymmetric-effort/specifyjs 0.2.143 → 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.
@@ -15,6 +15,7 @@ import {
15
15
  useEffect,
16
16
  useId,
17
17
  useMemo,
18
+ useReducer,
18
19
  useRef,
19
20
  useState
20
21
  } from "./chunks/chunk-4V37N6QN.js";
@@ -16452,9 +16453,2291 @@ function TradingDashboard(props) {
16452
16453
  );
16453
16454
  }
16454
16455
 
16456
+ // ../demos/project-manager/src/Toolbar.ts
16457
+ var CARD_COLORS = [
16458
+ "transparent",
16459
+ // no background
16460
+ "#fef9c3",
16461
+ // yellow
16462
+ "#fecaca",
16463
+ // red
16464
+ "#fed7aa",
16465
+ // orange
16466
+ "#bbf7d0",
16467
+ // green
16468
+ "#bfdbfe",
16469
+ // blue
16470
+ "#ddd6fe",
16471
+ // purple
16472
+ "#fbcfe8",
16473
+ // pink
16474
+ "#e5e7eb"
16475
+ // gray
16476
+ ];
16477
+ function BoardToolbar(props) {
16478
+ const {
16479
+ zoom,
16480
+ gridEnabled,
16481
+ selectedColor,
16482
+ colorFilter,
16483
+ onNewCard,
16484
+ onZoomIn,
16485
+ onZoomOut,
16486
+ onZoomReset,
16487
+ onColorSelect,
16488
+ onColorFilter,
16489
+ onGridToggle,
16490
+ onSearch
16491
+ } = props;
16492
+ const [searchText, setSearchText] = useState("");
16493
+ const handleSearchInput = useCallback((e) => {
16494
+ const value = e.target.value;
16495
+ setSearchText(value);
16496
+ onSearch(value);
16497
+ }, [onSearch]);
16498
+ const toolbarStyle = {
16499
+ display: "flex",
16500
+ alignItems: "center",
16501
+ gap: "8px",
16502
+ padding: "6px 12px",
16503
+ backgroundColor: "rgba(255,255,255,0.95)",
16504
+ borderBottom: "1px solid #e2e8f0",
16505
+ fontSize: "12px",
16506
+ flexShrink: "0",
16507
+ flexWrap: "wrap"
16508
+ };
16509
+ const btnStyle = {
16510
+ padding: "4px 10px",
16511
+ border: "1px solid #d1d5db",
16512
+ borderRadius: "4px",
16513
+ backgroundColor: "#ffffff",
16514
+ cursor: "pointer",
16515
+ fontSize: "12px",
16516
+ color: "#374151",
16517
+ lineHeight: "1.4"
16518
+ };
16519
+ const activeBtnStyle = {
16520
+ ...btnStyle,
16521
+ backgroundColor: "#3b82f6",
16522
+ color: "#ffffff",
16523
+ borderColor: "#3b82f6"
16524
+ };
16525
+ const zoomText = {
16526
+ fontSize: "12px",
16527
+ color: "#64748b",
16528
+ minWidth: "40px",
16529
+ textAlign: "center",
16530
+ cursor: "pointer"
16531
+ };
16532
+ const separatorStyle = {
16533
+ width: "1px",
16534
+ height: "20px",
16535
+ backgroundColor: "#e2e8f0",
16536
+ margin: "0 4px"
16537
+ };
16538
+ const inputStyle = {
16539
+ padding: "4px 8px",
16540
+ border: "1px solid #d1d5db",
16541
+ borderRadius: "4px",
16542
+ fontSize: "12px",
16543
+ width: "120px",
16544
+ outline: "none"
16545
+ };
16546
+ const swatches = CARD_COLORS.map((color) => {
16547
+ const isActive = color === selectedColor;
16548
+ const isFiltered = color === colorFilter;
16549
+ const handleSwatchClick = () => {
16550
+ if (isActive && onColorFilter) {
16551
+ onColorFilter(isFiltered ? null : color);
16552
+ } else {
16553
+ onColorSelect(color);
16554
+ }
16555
+ };
16556
+ let borderStyle = "1px solid rgba(0,0,0,0.15)";
16557
+ if (isFiltered) {
16558
+ borderStyle = "3px solid #ef4444";
16559
+ } else if (isActive) {
16560
+ borderStyle = "2px solid #3b82f6";
16561
+ }
16562
+ const isTransparent = color === "transparent";
16563
+ return createElement("button", {
16564
+ key: color,
16565
+ title: isTransparent ? "Transparent" : color,
16566
+ style: {
16567
+ width: "18px",
16568
+ height: "18px",
16569
+ borderRadius: "50%",
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",
16574
+ border: borderStyle,
16575
+ cursor: "pointer",
16576
+ padding: "0",
16577
+ flexShrink: "0",
16578
+ opacity: isFiltered ? "1" : colorFilter ? "0.5" : "1"
16579
+ },
16580
+ onClick: handleSwatchClick,
16581
+ "aria-label": isFiltered ? `Clear color filter ${color}` : `Select color ${color}`,
16582
+ "data-testid": `color-swatch-${color}`
16583
+ });
16584
+ });
16585
+ return createElement(
16586
+ "div",
16587
+ {
16588
+ className: "board-toolbar",
16589
+ style: toolbarStyle,
16590
+ role: "toolbar",
16591
+ "aria-label": "Board toolbar",
16592
+ "data-testid": "board-toolbar"
16593
+ },
16594
+ // New card button
16595
+ createElement("button", {
16596
+ style: btnStyle,
16597
+ onClick: onNewCard,
16598
+ "data-testid": "btn-new-card",
16599
+ "aria-label": "New card"
16600
+ }, "+ New Card"),
16601
+ createElement("div", { style: separatorStyle }),
16602
+ // Zoom controls
16603
+ createElement("button", {
16604
+ style: btnStyle,
16605
+ onClick: onZoomOut,
16606
+ "data-testid": "btn-zoom-out",
16607
+ "aria-label": "Zoom out"
16608
+ }, "-"),
16609
+ createElement("span", {
16610
+ style: zoomText,
16611
+ onClick: onZoomReset,
16612
+ "data-testid": "zoom-level",
16613
+ role: "status",
16614
+ "aria-label": `Zoom ${Math.round(zoom * 100)}%`
16615
+ }, `${Math.round(zoom * 100)}%`),
16616
+ createElement("button", {
16617
+ style: btnStyle,
16618
+ onClick: onZoomIn,
16619
+ "data-testid": "btn-zoom-in",
16620
+ "aria-label": "Zoom in"
16621
+ }, "+"),
16622
+ createElement("div", { style: separatorStyle }),
16623
+ ...swatches,
16624
+ createElement("div", { style: separatorStyle }),
16625
+ // Grid toggle
16626
+ createElement("button", {
16627
+ style: gridEnabled ? activeBtnStyle : btnStyle,
16628
+ onClick: onGridToggle,
16629
+ "data-testid": "btn-grid-toggle",
16630
+ "aria-label": gridEnabled ? "Disable grid snapping" : "Enable grid snapping",
16631
+ "aria-pressed": String(gridEnabled)
16632
+ }, "Grid"),
16633
+ createElement("div", { style: separatorStyle }),
16634
+ // Search
16635
+ createElement("input", {
16636
+ type: "text",
16637
+ placeholder: "Search cards...",
16638
+ value: searchText,
16639
+ onInput: handleSearchInput,
16640
+ style: inputStyle,
16641
+ "data-testid": "search-input",
16642
+ "aria-label": "Search cards"
16643
+ })
16644
+ );
16645
+ }
16646
+
16647
+ // ../demos/project-manager/src/Card.ts
16648
+ var PRIORITY_COLORS = {
16649
+ low: "#22c55e",
16650
+ medium: "#f59e0b",
16651
+ high: "#f97316",
16652
+ critical: "#ef4444"
16653
+ };
16654
+ var CONTEXT_MENU_COLORS = CARD_COLORS;
16655
+ var PRIORITY_OPTIONS = [
16656
+ { label: "Low", value: "low" },
16657
+ { label: "Medium", value: "medium" },
16658
+ { label: "High", value: "high" },
16659
+ { label: "Critical", value: "critical" }
16660
+ ];
16661
+ function Card2(props) {
16662
+ const {
16663
+ card,
16664
+ selected,
16665
+ onSelect,
16666
+ onMove,
16667
+ onResize,
16668
+ onDelete,
16669
+ onDoubleClick,
16670
+ onUpdate,
16671
+ onDragStart,
16672
+ onDuplicate,
16673
+ onChangeColor,
16674
+ onChangePriority,
16675
+ onAnchorDragStart,
16676
+ onCardContextMenu
16677
+ } = props;
16678
+ const [hovered, setHovered] = 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 || "");
16683
+ const dragStartRef = useRef(null);
16684
+ const resizeStartRef = useRef(null);
16685
+ const cardRef = useRef(null);
16686
+ const titleInputRef = useRef(null);
16687
+ const descTextareaRef = useRef(null);
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
+ );
16693
+ const handleContextMenu = useCallback((e) => {
16694
+ const me = e;
16695
+ me.preventDefault();
16696
+ me.stopPropagation();
16697
+ if (onCardContextMenu) {
16698
+ onCardContextMenu(card.id, { x: me.clientX, y: me.clientY });
16699
+ }
16700
+ }, [card.id, onCardContextMenu]);
16701
+ useEffect(() => {
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();
16719
+ e.stopPropagation();
16720
+ setTitleDraft(card.title || "");
16721
+ setEditingTitle(true);
16722
+ }, [card.title]);
16723
+ const handleTitleInput = useCallback((e) => {
16724
+ setTitleDraft(e.target.value);
16725
+ }, []);
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);
16753
+ }, []);
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]);
16770
+ const handleAnchorMouseDown = useCallback((anchor, e) => {
16771
+ const me = e;
16772
+ me.preventDefault();
16773
+ me.stopPropagation();
16774
+ if (onAnchorDragStart) {
16775
+ const cx = card.position.x + card.size.width / 2;
16776
+ const cy = card.position.y + card.size.height / 2;
16777
+ let ax = cx;
16778
+ let ay = cy;
16779
+ if (anchor === "top") {
16780
+ ax = cx;
16781
+ ay = card.position.y;
16782
+ } else if (anchor === "bottom") {
16783
+ ax = cx;
16784
+ ay = card.position.y + card.size.height;
16785
+ } else if (anchor === "left") {
16786
+ ax = card.position.x;
16787
+ ay = cy;
16788
+ } else if (anchor === "right") {
16789
+ ax = card.position.x + card.size.width;
16790
+ ay = cy;
16791
+ }
16792
+ onAnchorDragStart(card.id, anchor, ax, ay);
16793
+ }
16794
+ }, [card.id, card.position, card.size, onAnchorDragStart]);
16795
+ const handleMouseDown = useCallback((e) => {
16796
+ const me = e;
16797
+ const target = me.target;
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;
16799
+ me.preventDefault();
16800
+ me.stopPropagation();
16801
+ onSelect(card.id);
16802
+ dragStartRef.current = {
16803
+ x: me.clientX,
16804
+ y: me.clientY,
16805
+ cardX: card.position.x,
16806
+ cardY: card.position.y
16807
+ };
16808
+ const handleMouseMove = (ev) => {
16809
+ const mev = ev;
16810
+ if (!dragStartRef.current) return;
16811
+ const dx = mev.clientX - dragStartRef.current.x;
16812
+ const dy = mev.clientY - dragStartRef.current.y;
16813
+ onMove(card.id, {
16814
+ x: dragStartRef.current.cardX + dx,
16815
+ y: dragStartRef.current.cardY + dy
16816
+ });
16817
+ };
16818
+ const handleMouseUp = () => {
16819
+ dragStartRef.current = null;
16820
+ document.removeEventListener("mousemove", handleMouseMove);
16821
+ document.removeEventListener("mouseup", handleMouseUp);
16822
+ };
16823
+ document.addEventListener("mousemove", handleMouseMove);
16824
+ document.addEventListener("mouseup", handleMouseUp);
16825
+ if (onDragStart) {
16826
+ onDragStart(card.id, e);
16827
+ }
16828
+ }, [card.id, card.position.x, card.position.y, onSelect, onMove, onDragStart]);
16829
+ const handleResizeMouseDown = useCallback((e) => {
16830
+ const me = e;
16831
+ me.preventDefault();
16832
+ me.stopPropagation();
16833
+ resizeStartRef.current = {
16834
+ x: me.clientX,
16835
+ y: me.clientY,
16836
+ w: card.size.width,
16837
+ h: card.size.height
16838
+ };
16839
+ const handleMouseMove = (ev) => {
16840
+ const mev = ev;
16841
+ if (!resizeStartRef.current) return;
16842
+ const dx = mev.clientX - resizeStartRef.current.x;
16843
+ const dy = mev.clientY - resizeStartRef.current.y;
16844
+ const newW = Math.max(120, resizeStartRef.current.w + dx);
16845
+ const newH = Math.max(80, resizeStartRef.current.h + dy);
16846
+ onResize(card.id, { width: newW, height: newH });
16847
+ };
16848
+ const handleMouseUp = () => {
16849
+ resizeStartRef.current = null;
16850
+ document.removeEventListener("mousemove", handleMouseMove);
16851
+ document.removeEventListener("mouseup", handleMouseUp);
16852
+ };
16853
+ document.addEventListener("mousemove", handleMouseMove);
16854
+ document.addEventListener("mouseup", handleMouseUp);
16855
+ }, [card.id, card.size.width, card.size.height, onResize]);
16856
+ const handleDoubleClick = useCallback((e) => {
16857
+ e.preventDefault();
16858
+ e.stopPropagation();
16859
+ }, []);
16860
+ const handleDeleteClick = useCallback((e) => {
16861
+ e.preventDefault();
16862
+ e.stopPropagation();
16863
+ onDelete(card.id);
16864
+ }, [card.id, onDelete]);
16865
+ const cardStyle = {
16866
+ position: "absolute",
16867
+ left: `${card.position.x}px`,
16868
+ top: `${card.position.y}px`,
16869
+ width: `${card.size.width}px`,
16870
+ height: `${card.size.height}px`,
16871
+ backgroundColor: card.color || "#fef9c3",
16872
+ borderRadius: "6px",
16873
+ borderLeft: `4px solid ${priorityColor}`,
16874
+ boxShadow: selected ? "0 0 0 2px #3b82f6, 0 4px 12px rgba(0,0,0,0.15)" : "0 2px 8px rgba(0,0,0,0.1)",
16875
+ cursor: "grab",
16876
+ userSelect: "none",
16877
+ overflow: "hidden",
16878
+ display: "flex",
16879
+ flexDirection: "column",
16880
+ padding: "8px 10px",
16881
+ boxSizing: "border-box",
16882
+ transition: "box-shadow 150ms ease"
16883
+ };
16884
+ const titleStyle = {
16885
+ fontWeight: "600",
16886
+ fontSize: "14px",
16887
+ color: "#1a1a1a",
16888
+ marginBottom: "4px",
16889
+ lineHeight: "1.3",
16890
+ overflow: "hidden",
16891
+ textOverflow: "ellipsis",
16892
+ whiteSpace: "nowrap"
16893
+ };
16894
+ const descStyle = {
16895
+ fontSize: "12px",
16896
+ color: "#555555",
16897
+ lineHeight: "1.4",
16898
+ overflow: "hidden",
16899
+ flex: "1"
16900
+ };
16901
+ const deleteStyle = {
16902
+ position: "absolute",
16903
+ top: "4px",
16904
+ right: "4px",
16905
+ width: "18px",
16906
+ height: "18px",
16907
+ borderRadius: "50%",
16908
+ backgroundColor: "rgba(0,0,0,0.15)",
16909
+ color: "#333",
16910
+ fontSize: "12px",
16911
+ lineHeight: "18px",
16912
+ textAlign: "center",
16913
+ cursor: "pointer",
16914
+ display: hovered ? "block" : "none",
16915
+ border: "none",
16916
+ padding: "0"
16917
+ };
16918
+ const resizeStyle = {
16919
+ position: "absolute",
16920
+ bottom: "0",
16921
+ right: "0",
16922
+ width: "12px",
16923
+ height: "12px",
16924
+ cursor: "nwse-resize",
16925
+ opacity: "0.4",
16926
+ background: "linear-gradient(135deg, transparent 50%, #666 50%)"
16927
+ };
16928
+ const tagsEl = card.tags && card.tags.length > 0 ? createElement(
16929
+ "div",
16930
+ {
16931
+ style: {
16932
+ display: "flex",
16933
+ gap: "4px",
16934
+ flexWrap: "wrap",
16935
+ marginTop: "4px"
16936
+ }
16937
+ },
16938
+ ...card.tags.map(
16939
+ (tag, i) => createElement("span", {
16940
+ key: String(i),
16941
+ style: {
16942
+ fontSize: "10px",
16943
+ padding: "1px 4px",
16944
+ borderRadius: "3px",
16945
+ backgroundColor: "rgba(0,0,0,0.08)",
16946
+ color: "#444"
16947
+ }
16948
+ }, tag)
16949
+ )
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
+ };
16998
+ const anchorBaseStyle = {
16999
+ position: "absolute",
17000
+ width: "10px",
17001
+ height: "10px",
17002
+ borderRadius: "50%",
17003
+ backgroundColor: "#3b82f6",
17004
+ border: "2px solid #ffffff",
17005
+ cursor: "crosshair",
17006
+ display: hovered ? "block" : "none",
17007
+ zIndex: "10",
17008
+ boxSizing: "border-box"
17009
+ };
17010
+ const anchorTop = { ...anchorBaseStyle, top: "-5px", left: "50%", transform: "translateX(-50%)" };
17011
+ const anchorRight = { ...anchorBaseStyle, top: "50%", right: "-5px", transform: "translateY(-50%)" };
17012
+ const anchorBottom = { ...anchorBaseStyle, bottom: "-5px", left: "50%", transform: "translateX(-50%)" };
17013
+ const anchorLeft = { ...anchorBaseStyle, top: "50%", left: "-5px", transform: "translateY(-50%)" };
17014
+ return createElement(
17015
+ "div",
17016
+ {
17017
+ ref: cardRef,
17018
+ className: "board-card",
17019
+ style: cardStyle,
17020
+ onMouseDown: handleMouseDown,
17021
+ onDblClick: handleDoubleClick,
17022
+ onContextMenu: handleContextMenu,
17023
+ onMouseEnter: () => setHovered(true),
17024
+ onMouseLeave: () => setHovered(false),
17025
+ "data-card-id": card.id,
17026
+ "data-testid": `card-${card.id}`,
17027
+ role: "button",
17028
+ "aria-label": `Card: ${card.title}`,
17029
+ tabIndex: 0
17030
+ },
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 || ""),
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"),
17096
+ createElement("button", {
17097
+ style: deleteStyle,
17098
+ "data-role": "delete",
17099
+ "data-testid": `card-delete-${card.id}`,
17100
+ onClick: handleDeleteClick,
17101
+ "aria-label": `Delete ${card.title}`,
17102
+ tabIndex: -1
17103
+ }, "\xD7"),
17104
+ createElement("div", {
17105
+ style: resizeStyle,
17106
+ "data-role": "resize",
17107
+ onMouseDown: handleResizeMouseDown,
17108
+ "aria-label": "Resize card"
17109
+ }),
17110
+ // Anchor circles for connection creation
17111
+ createElement("div", {
17112
+ style: anchorTop,
17113
+ "data-role": "anchor",
17114
+ "data-anchor": "top",
17115
+ "data-testid": `anchor-top-${card.id}`,
17116
+ onMouseDown: (e) => handleAnchorMouseDown("top", e),
17117
+ "aria-label": "Connection anchor top"
17118
+ }),
17119
+ createElement("div", {
17120
+ style: anchorRight,
17121
+ "data-role": "anchor",
17122
+ "data-anchor": "right",
17123
+ "data-testid": `anchor-right-${card.id}`,
17124
+ onMouseDown: (e) => handleAnchorMouseDown("right", e),
17125
+ "aria-label": "Connection anchor right"
17126
+ }),
17127
+ createElement("div", {
17128
+ style: anchorBottom,
17129
+ "data-role": "anchor",
17130
+ "data-anchor": "bottom",
17131
+ "data-testid": `anchor-bottom-${card.id}`,
17132
+ onMouseDown: (e) => handleAnchorMouseDown("bottom", e),
17133
+ "aria-label": "Connection anchor bottom"
17134
+ }),
17135
+ createElement("div", {
17136
+ style: anchorLeft,
17137
+ "data-role": "anchor",
17138
+ "data-anchor": "left",
17139
+ "data-testid": `anchor-left-${card.id}`,
17140
+ onMouseDown: (e) => handleAnchorMouseDown("left", e),
17141
+ "aria-label": "Connection anchor left"
17142
+ })
17143
+ );
17144
+ }
17145
+
17146
+ // ../demos/project-manager/src/CardEditor.ts
17147
+ function CardEditor(props) {
17148
+ const { card, onSave, onClose } = props;
17149
+ const [title, setTitle] = useState(card.title);
17150
+ const [description, setDescription] = useState(card.description);
17151
+ const titleRef = useRef(null);
17152
+ const overlayRef = useRef(null);
17153
+ useEffect(() => {
17154
+ if (titleRef.current) {
17155
+ titleRef.current.focus();
17156
+ titleRef.current.select();
17157
+ }
17158
+ }, []);
17159
+ const save = useCallback(() => {
17160
+ onSave(card.id, { title, description });
17161
+ onClose();
17162
+ }, [card.id, title, description, onSave, onClose]);
17163
+ const handleKeyDown = useCallback((e) => {
17164
+ const ke = e;
17165
+ if (ke.key === "Escape") {
17166
+ save();
17167
+ }
17168
+ }, [save]);
17169
+ const handleOverlayClick = useCallback((e) => {
17170
+ const me = e;
17171
+ if (me.target === overlayRef.current) {
17172
+ save();
17173
+ }
17174
+ }, [save]);
17175
+ const handleTitleChange = useCallback((e) => {
17176
+ setTitle(e.target.value);
17177
+ }, []);
17178
+ const handleDescChange = useCallback((e) => {
17179
+ setDescription(e.target.value);
17180
+ }, []);
17181
+ const handleTitleKeyDown = useCallback((e) => {
17182
+ const ke = e;
17183
+ if (ke.key === "Tab") {
17184
+ ke.preventDefault();
17185
+ const textarea = ke.target.parentElement?.querySelector("textarea");
17186
+ if (textarea) textarea.focus();
17187
+ }
17188
+ if (ke.key === "Escape") {
17189
+ save();
17190
+ }
17191
+ }, [save]);
17192
+ const overlayStyle = {
17193
+ position: "absolute",
17194
+ inset: "0",
17195
+ backgroundColor: "rgba(0,0,0,0.3)",
17196
+ display: "flex",
17197
+ alignItems: "center",
17198
+ justifyContent: "center",
17199
+ zIndex: "100"
17200
+ };
17201
+ const editorStyle = {
17202
+ backgroundColor: card.color || "#fef9c3",
17203
+ borderRadius: "8px",
17204
+ padding: "16px",
17205
+ width: `${Math.max(card.size.width, 200)}px`,
17206
+ boxShadow: "0 8px 24px rgba(0,0,0,0.2)",
17207
+ display: "flex",
17208
+ flexDirection: "column",
17209
+ gap: "8px"
17210
+ };
17211
+ const inputStyle = {
17212
+ border: "1px solid rgba(0,0,0,0.15)",
17213
+ borderRadius: "4px",
17214
+ padding: "6px 8px",
17215
+ fontSize: "14px",
17216
+ fontWeight: "600",
17217
+ backgroundColor: "rgba(255,255,255,0.7)",
17218
+ color: "#1a1a1a",
17219
+ outline: "none",
17220
+ width: "100%",
17221
+ boxSizing: "border-box"
17222
+ };
17223
+ const textareaStyle = {
17224
+ border: "1px solid rgba(0,0,0,0.15)",
17225
+ borderRadius: "4px",
17226
+ padding: "6px 8px",
17227
+ fontSize: "12px",
17228
+ backgroundColor: "rgba(255,255,255,0.7)",
17229
+ color: "#333",
17230
+ outline: "none",
17231
+ resize: "vertical",
17232
+ minHeight: "60px",
17233
+ width: "100%",
17234
+ boxSizing: "border-box",
17235
+ fontFamily: "inherit"
17236
+ };
17237
+ const btnStyle = {
17238
+ padding: "6px 14px",
17239
+ border: "none",
17240
+ borderRadius: "4px",
17241
+ backgroundColor: "#3b82f6",
17242
+ color: "#ffffff",
17243
+ cursor: "pointer",
17244
+ fontSize: "12px",
17245
+ fontWeight: "600",
17246
+ alignSelf: "flex-end"
17247
+ };
17248
+ return createElement(
17249
+ "div",
17250
+ {
17251
+ ref: overlayRef,
17252
+ className: "card-editor-overlay",
17253
+ style: overlayStyle,
17254
+ onClick: handleOverlayClick,
17255
+ onKeyDown: handleKeyDown,
17256
+ "data-testid": "card-editor-overlay"
17257
+ },
17258
+ createElement(
17259
+ "div",
17260
+ {
17261
+ style: editorStyle,
17262
+ "data-testid": "card-editor",
17263
+ role: "dialog",
17264
+ "aria-label": `Edit card: ${card.title}`
17265
+ },
17266
+ createElement("input", {
17267
+ ref: titleRef,
17268
+ type: "text",
17269
+ value: title,
17270
+ onInput: handleTitleChange,
17271
+ onKeyDown: handleTitleKeyDown,
17272
+ style: inputStyle,
17273
+ placeholder: "Card title",
17274
+ "data-testid": "card-editor-title",
17275
+ "aria-label": "Card title"
17276
+ }),
17277
+ createElement("textarea", {
17278
+ value: description,
17279
+ onInput: handleDescChange,
17280
+ onKeyDown: handleKeyDown,
17281
+ style: textareaStyle,
17282
+ placeholder: "Description...",
17283
+ "data-testid": "card-editor-description",
17284
+ "aria-label": "Card description"
17285
+ }),
17286
+ createElement("button", {
17287
+ style: btnStyle,
17288
+ onClick: save,
17289
+ "data-testid": "card-editor-save"
17290
+ }, "Done")
17291
+ )
17292
+ );
17293
+ }
17294
+
17295
+ // ../demos/project-manager/src/Connection.ts
17296
+ function getCardCenter(card) {
17297
+ return {
17298
+ x: card.position.x + card.size.width / 2,
17299
+ y: card.position.y + card.size.height / 2
17300
+ };
17301
+ }
17302
+ function getStrokeDasharray(style) {
17303
+ switch (style) {
17304
+ case "dashed":
17305
+ return "8,4";
17306
+ case "dotted":
17307
+ return "2,4";
17308
+ default:
17309
+ return "none";
17310
+ }
17311
+ }
17312
+ function ConnectionsOverlay(props) {
17313
+ const { connections, cards, selectedConnectionId, onSelectConnection, canvasWidth, canvasHeight } = props;
17314
+ const cardMap = /* @__PURE__ */ new Map();
17315
+ for (let i = 0; i < cards.length; i++) {
17316
+ cardMap.set(cards[i].id, cards[i]);
17317
+ }
17318
+ const handleLineClick = useCallback((connectionId) => {
17319
+ onSelectConnection(connectionId);
17320
+ }, [onSelectConnection]);
17321
+ const lineElements = [];
17322
+ for (let i = 0; i < connections.length; i++) {
17323
+ const conn = connections[i];
17324
+ const fromCard = cardMap.get(conn.fromCardId);
17325
+ const toCard = cardMap.get(conn.toCardId);
17326
+ if (!fromCard || !toCard) continue;
17327
+ const from = getCardCenter(fromCard);
17328
+ const to = getCardCenter(toCard);
17329
+ const isSelected = conn.id === selectedConnectionId;
17330
+ const strokeColor = isSelected ? "#3b82f6" : "#94a3b8";
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}`;
17343
+ lineElements.push(
17344
+ createElement("path", {
17345
+ key: `hit-${conn.id}`,
17346
+ d: pathD,
17347
+ fill: "none",
17348
+ stroke: "transparent",
17349
+ "stroke-width": "12",
17350
+ style: { cursor: "pointer" },
17351
+ onClick: () => handleLineClick(conn.id),
17352
+ "data-testid": `connection-hit-${conn.id}`
17353
+ })
17354
+ );
17355
+ lineElements.push(
17356
+ createElement("path", {
17357
+ key: conn.id,
17358
+ d: pathD,
17359
+ fill: "none",
17360
+ stroke: strokeColor,
17361
+ "stroke-width": isSelected ? "3" : "2",
17362
+ "stroke-dasharray": dashArray,
17363
+ "pointer-events": "none",
17364
+ "data-testid": `connection-${conn.id}`
17365
+ })
17366
+ );
17367
+ if (conn.label) {
17368
+ lineElements.push(
17369
+ createElement("text", {
17370
+ key: `label-${conn.id}`,
17371
+ x: String(cpX),
17372
+ y: String(cpY - 6),
17373
+ "text-anchor": "middle",
17374
+ fill: "#64748b",
17375
+ "font-size": "11",
17376
+ "pointer-events": "none"
17377
+ }, conn.label)
17378
+ );
17379
+ }
17380
+ }
17381
+ const svgStyle = {
17382
+ position: "absolute",
17383
+ top: "0",
17384
+ left: "0",
17385
+ width: "100%",
17386
+ height: "100%",
17387
+ pointerEvents: "none",
17388
+ overflow: "visible"
17389
+ };
17390
+ return createElement(
17391
+ "svg",
17392
+ {
17393
+ style: svgStyle,
17394
+ width: String(canvasWidth),
17395
+ height: String(canvasHeight),
17396
+ className: "connections-overlay",
17397
+ "data-testid": "connections-overlay",
17398
+ role: "img",
17399
+ "aria-label": "Card connections"
17400
+ },
17401
+ createElement("g", { style: { pointerEvents: "auto" } }, ...lineElements)
17402
+ );
17403
+ }
17404
+
17405
+ // ../demos/project-manager/src/Board.ts
17406
+ var GRID_SIZE = 20;
17407
+ var CANVAS_SIZE = 5e3;
17408
+ function screenToCanvas(screenX, screenY, viewport) {
17409
+ return {
17410
+ x: (screenX - viewport.panX) / viewport.zoom,
17411
+ y: (screenY - viewport.panY) / viewport.zoom
17412
+ };
17413
+ }
17414
+ function computeFitAll(cards, containerWidth, containerHeight, padding) {
17415
+ const pad3 = padding ?? 40;
17416
+ if (cards.length === 0) {
17417
+ return { panX: 0, panY: 0, zoom: 1 };
17418
+ }
17419
+ let minX = Infinity;
17420
+ let minY = Infinity;
17421
+ let maxX = -Infinity;
17422
+ let maxY = -Infinity;
17423
+ for (let i = 0; i < cards.length; i++) {
17424
+ const c = cards[i];
17425
+ if (c.position.x < minX) minX = c.position.x;
17426
+ if (c.position.y < minY) minY = c.position.y;
17427
+ const right = c.position.x + c.size.width;
17428
+ const bottom = c.position.y + c.size.height;
17429
+ if (right > maxX) maxX = right;
17430
+ if (bottom > maxY) maxY = bottom;
17431
+ }
17432
+ const contentW = maxX - minX + pad3 * 2;
17433
+ const contentH = maxY - minY + pad3 * 2;
17434
+ const zoomX = containerWidth / contentW;
17435
+ const zoomY = containerHeight / contentH;
17436
+ const zoom = Math.max(0.25, Math.min(4, Math.min(zoomX, zoomY)));
17437
+ const panX = -minX * zoom + (containerWidth - (maxX - minX) * zoom) / 2;
17438
+ const panY = -minY * zoom + (containerHeight - (maxY - minY) * zoom) / 2;
17439
+ return { panX, panY, zoom };
17440
+ }
17441
+ var connIdCounter = 0;
17442
+ function generateConnectionId() {
17443
+ connIdCounter++;
17444
+ return `conn-${Date.now()}-${connIdCounter}`;
17445
+ }
17446
+ function Board(props) {
17447
+ const { state, dispatch, searchQuery, gridEnabled, selectedCardId, onSelectCard, colorFilter, showConnections } = props;
17448
+ const shouldShowConnections = showConnections !== false;
17449
+ const { cards, connections, viewport } = state;
17450
+ const [editingCardId, setEditingCardId] = useState(null);
17451
+ const [selectedConnectionId, setSelectedConnectionId] = useState(null);
17452
+ const [cardContextMenu, setCardContextMenu] = useState(null);
17453
+ const [colorSubmenuOpen, setColorSubmenuOpen] = useState(false);
17454
+ const [prioritySubmenuOpen, setPrioritySubmenuOpen] = useState(false);
17455
+ const containerRef = useRef(null);
17456
+ const isPanningRef = useRef(false);
17457
+ const panStartRef = useRef(null);
17458
+ const [connectionDrag, setConnectionDrag] = useState(null);
17459
+ const connectionDragRef = useRef(connectionDrag);
17460
+ connectionDragRef.current = connectionDrag;
17461
+ const handleCanvasMouseDown = useCallback((e) => {
17462
+ const me = e;
17463
+ const target = me.target;
17464
+ if (target.closest(".board-card")) return;
17465
+ const isMiddle = me.button === 1;
17466
+ const isShiftLeft = me.button === 0 && me.shiftKey;
17467
+ if (isMiddle || isShiftLeft) {
17468
+ me.preventDefault();
17469
+ isPanningRef.current = true;
17470
+ panStartRef.current = {
17471
+ x: me.clientX,
17472
+ y: me.clientY,
17473
+ panX: viewport.panX,
17474
+ panY: viewport.panY
17475
+ };
17476
+ } else if (me.button === 0) {
17477
+ onSelectCard(null);
17478
+ setSelectedConnectionId(null);
17479
+ }
17480
+ }, [viewport.panX, viewport.panY, onSelectCard]);
17481
+ useEffect(() => {
17482
+ const handleMouseMove = (e) => {
17483
+ if (!isPanningRef.current || !panStartRef.current) return;
17484
+ const me = e;
17485
+ const dx = me.clientX - panStartRef.current.x;
17486
+ const dy = me.clientY - panStartRef.current.y;
17487
+ dispatch({
17488
+ type: "PAN",
17489
+ panX: panStartRef.current.panX + dx,
17490
+ panY: panStartRef.current.panY + dy
17491
+ });
17492
+ };
17493
+ const handleMouseUp = () => {
17494
+ isPanningRef.current = false;
17495
+ panStartRef.current = null;
17496
+ };
17497
+ document.addEventListener("mousemove", handleMouseMove);
17498
+ document.addEventListener("mouseup", handleMouseUp);
17499
+ return () => {
17500
+ document.removeEventListener("mousemove", handleMouseMove);
17501
+ document.removeEventListener("mouseup", handleMouseUp);
17502
+ };
17503
+ }, [dispatch]);
17504
+ const handleWheel = useCallback((e) => {
17505
+ const we = e;
17506
+ if (!we.ctrlKey) return;
17507
+ we.preventDefault();
17508
+ const delta = we.deltaY > 0 ? -0.1 : 0.1;
17509
+ dispatch({ type: "ZOOM", zoom: viewport.zoom + delta });
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]);
17568
+ useEffect(() => {
17569
+ const handleKeyDown = (e) => {
17570
+ const ke = e;
17571
+ if (ke.key === "Delete" || ke.key === "Backspace") {
17572
+ if (selectedConnectionId) {
17573
+ dispatch({ type: "REMOVE_CONNECTION", connectionId: selectedConnectionId });
17574
+ setSelectedConnectionId(null);
17575
+ } else if (selectedCardId) {
17576
+ dispatch({ type: "REMOVE_CARD", cardId: selectedCardId });
17577
+ onSelectCard(null);
17578
+ }
17579
+ }
17580
+ };
17581
+ document.addEventListener("keydown", handleKeyDown);
17582
+ return () => document.removeEventListener("keydown", handleKeyDown);
17583
+ }, [selectedConnectionId, selectedCardId, dispatch, onSelectCard]);
17584
+ const handleSelectCard = useCallback((cardId) => {
17585
+ onSelectCard(cardId);
17586
+ setSelectedConnectionId(null);
17587
+ }, [onSelectCard]);
17588
+ const handleMoveCard = useCallback((cardId, position) => {
17589
+ let pos = position;
17590
+ if (gridEnabled) {
17591
+ pos = {
17592
+ x: Math.round(position.x / GRID_SIZE) * GRID_SIZE,
17593
+ y: Math.round(position.y / GRID_SIZE) * GRID_SIZE
17594
+ };
17595
+ }
17596
+ dispatch({ type: "MOVE_CARD", cardId, position: pos });
17597
+ }, [dispatch, gridEnabled]);
17598
+ const handleResizeCard = useCallback((cardId, size) => {
17599
+ dispatch({ type: "RESIZE_CARD", cardId, size });
17600
+ }, [dispatch]);
17601
+ const handleDeleteCard = useCallback((cardId) => {
17602
+ dispatch({ type: "REMOVE_CARD", cardId });
17603
+ if (selectedCardId === cardId) onSelectCard(null);
17604
+ }, [dispatch, selectedCardId, onSelectCard]);
17605
+ const handleDoubleClickCard = useCallback((_cardId) => {
17606
+ }, []);
17607
+ const handleUpdateCard = useCallback((cardId, updates) => {
17608
+ dispatch({ type: "UPDATE_CARD", cardId, updates });
17609
+ }, [dispatch]);
17610
+ const handleEditorSave = useCallback((cardId, updates) => {
17611
+ dispatch({ type: "UPDATE_CARD", cardId, updates });
17612
+ }, [dispatch]);
17613
+ const handleEditorClose = useCallback(() => {
17614
+ setEditingCardId(null);
17615
+ }, []);
17616
+ const handleSelectConnection = useCallback((connectionId) => {
17617
+ setSelectedConnectionId(connectionId);
17618
+ onSelectCard(null);
17619
+ }, [onSelectCard]);
17620
+ const handleDeleteConnection = useCallback((connectionId) => {
17621
+ dispatch({ type: "REMOVE_CONNECTION", connectionId });
17622
+ setSelectedConnectionId(null);
17623
+ }, [dispatch]);
17624
+ const handleDuplicateCard = useCallback((cardId) => {
17625
+ const newId = `card-${Date.now()}-dup`;
17626
+ dispatch({ type: "DUPLICATE_CARD", cardId, newId });
17627
+ }, [dispatch]);
17628
+ const handleChangeColor = useCallback((cardId, color) => {
17629
+ dispatch({ type: "UPDATE_CARD", cardId, updates: { color } });
17630
+ }, [dispatch]);
17631
+ const handleChangePriority = useCallback((cardId, priority) => {
17632
+ dispatch({ type: "UPDATE_CARD", cardId, updates: { priority } });
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]);
17695
+ const handleAnchorDragStart = useCallback((cardId, anchor, ax, ay) => {
17696
+ setConnectionDrag({
17697
+ fromCardId: cardId,
17698
+ fromAnchor: anchor,
17699
+ fromX: ax,
17700
+ fromY: ay,
17701
+ toX: ax,
17702
+ toY: ay
17703
+ });
17704
+ }, []);
17705
+ useEffect(() => {
17706
+ if (!connectionDragRef.current) return;
17707
+ const handleMouseMove = (e) => {
17708
+ const me = e;
17709
+ if (!connectionDragRef.current) return;
17710
+ const canvasPos = screenToCanvas(me.clientX, me.clientY, viewport);
17711
+ setConnectionDrag((prev) => prev ? {
17712
+ ...prev,
17713
+ toX: canvasPos.x,
17714
+ toY: canvasPos.y
17715
+ } : null);
17716
+ };
17717
+ const handleMouseUp = (e) => {
17718
+ const me = e;
17719
+ if (!connectionDragRef.current) return;
17720
+ const drag = connectionDragRef.current;
17721
+ const target = me.target;
17722
+ const anchorEl = target.closest ? target.closest("[data-anchor]") : null;
17723
+ const cardEl = target.closest ? target.closest("[data-card-id]") : null;
17724
+ if (anchorEl && cardEl) {
17725
+ const targetCardId = cardEl.getAttribute("data-card-id");
17726
+ if (targetCardId && targetCardId !== drag.fromCardId) {
17727
+ dispatch({
17728
+ type: "ADD_CONNECTION",
17729
+ connection: {
17730
+ id: generateConnectionId(),
17731
+ fromCardId: drag.fromCardId,
17732
+ toCardId: targetCardId
17733
+ }
17734
+ });
17735
+ }
17736
+ }
17737
+ setConnectionDrag(null);
17738
+ };
17739
+ document.addEventListener("mousemove", handleMouseMove);
17740
+ document.addEventListener("mouseup", handleMouseUp);
17741
+ return () => {
17742
+ document.removeEventListener("mousemove", handleMouseMove);
17743
+ document.removeEventListener("mouseup", handleMouseUp);
17744
+ };
17745
+ }, [connectionDrag, viewport, dispatch]);
17746
+ const lowerSearch = searchQuery.toLowerCase();
17747
+ const filteredCards = lowerSearch ? cards.filter((c) => c.title.toLowerCase().includes(lowerSearch)) : cards;
17748
+ const dimmedCardIds = /* @__PURE__ */ new Set();
17749
+ if (lowerSearch) {
17750
+ for (let i = 0; i < cards.length; i++) {
17751
+ if (!cards[i].title.toLowerCase().includes(lowerSearch)) {
17752
+ dimmedCardIds.add(cards[i].id);
17753
+ }
17754
+ }
17755
+ }
17756
+ if (colorFilter) {
17757
+ for (let i = 0; i < cards.length; i++) {
17758
+ if (cards[i].color !== colorFilter) {
17759
+ dimmedCardIds.add(cards[i].id);
17760
+ }
17761
+ }
17762
+ }
17763
+ const containerStyle3 = {
17764
+ flex: "1",
17765
+ overflow: "hidden",
17766
+ position: "relative",
17767
+ backgroundColor: "#f8fafc",
17768
+ cursor: isPanningRef.current ? "grabbing" : "default",
17769
+ backgroundImage: "radial-gradient(circle, #d1d5db 1px, transparent 1px)",
17770
+ backgroundSize: `${GRID_SIZE}px ${GRID_SIZE}px`
17771
+ };
17772
+ const transformStyle = {
17773
+ transform: `translate(${viewport.panX}px, ${viewport.panY}px) scale(${viewport.zoom})`,
17774
+ transformOrigin: "0 0",
17775
+ position: "relative",
17776
+ width: `${CANVAS_SIZE}px`,
17777
+ height: `${CANVAS_SIZE}px`
17778
+ };
17779
+ const cardElements = cards.map((card) => {
17780
+ const isDimmed = dimmedCardIds.has(card.id);
17781
+ const cardEl = createElement(Card2, {
17782
+ key: card.id,
17783
+ card,
17784
+ selected: card.id === selectedCardId,
17785
+ onSelect: handleSelectCard,
17786
+ onMove: handleMoveCard,
17787
+ onResize: handleResizeCard,
17788
+ onDelete: handleDeleteCard,
17789
+ onDoubleClick: handleDoubleClickCard,
17790
+ onUpdate: handleUpdateCard,
17791
+ onDuplicate: handleDuplicateCard,
17792
+ onChangeColor: handleChangeColor,
17793
+ onChangePriority: handleChangePriority,
17794
+ onAnchorDragStart: handleAnchorDragStart,
17795
+ onCardContextMenu: handleCardContextMenu
17796
+ });
17797
+ if (isDimmed) {
17798
+ return createElement("div", {
17799
+ key: `dim-${card.id}`,
17800
+ style: { opacity: "0.3" }
17801
+ }, cardEl);
17802
+ }
17803
+ return cardEl;
17804
+ });
17805
+ const editingCard = editingCardId ? cards.find((c) => c.id === editingCardId) : null;
17806
+ const editorEl = editingCard ? createElement(CardEditor, {
17807
+ card: editingCard,
17808
+ onSave: handleEditorSave,
17809
+ onClose: handleEditorClose
17810
+ }) : null;
17811
+ const connectionDragLine = connectionDrag ? createElement(
17812
+ "svg",
17813
+ {
17814
+ style: {
17815
+ position: "absolute",
17816
+ top: "0",
17817
+ left: "0",
17818
+ width: "100%",
17819
+ height: "100%",
17820
+ pointerEvents: "none",
17821
+ overflow: "visible",
17822
+ zIndex: "5"
17823
+ },
17824
+ width: String(CANVAS_SIZE),
17825
+ height: String(CANVAS_SIZE),
17826
+ "data-testid": "connection-drag-line"
17827
+ },
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
+ )
17997
+ ) : null;
17998
+ return createElement(
17999
+ "div",
18000
+ {
18001
+ ref: containerRef,
18002
+ className: "board-canvas",
18003
+ style: containerStyle3,
18004
+ onMouseDown: handleCanvasMouseDown,
18005
+ onWheel: handleWheel,
18006
+ "data-testid": "board-canvas",
18007
+ role: "application",
18008
+ "aria-label": "Project board canvas",
18009
+ tabIndex: 0
18010
+ },
18011
+ createElement(
18012
+ "div",
18013
+ {
18014
+ className: "board-canvas__inner",
18015
+ style: transformStyle,
18016
+ "data-testid": "board-canvas-inner"
18017
+ },
18018
+ shouldShowConnections ? createElement(ConnectionsOverlay, {
18019
+ connections,
18020
+ cards,
18021
+ selectedConnectionId,
18022
+ onSelectConnection: handleSelectConnection,
18023
+ onDeleteConnection: handleDeleteConnection,
18024
+ canvasWidth: CANVAS_SIZE,
18025
+ canvasHeight: CANVAS_SIZE
18026
+ }) : null,
18027
+ connectionDragLine,
18028
+ ...cardElements
18029
+ ),
18030
+ editorEl,
18031
+ contextMenuEl
18032
+ );
18033
+ }
18034
+
18035
+ // ../demos/project-manager/src/BoardState.ts
18036
+ var MAX_HISTORY = 50;
18037
+ var DEFAULT_BOARD_STATE = {
18038
+ id: crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`,
18039
+ name: "Untitled",
18040
+ cards: [],
18041
+ connections: [],
18042
+ viewport: { panX: 0, panY: 0, zoom: 1 }
18043
+ };
18044
+ function boardReducer(state, action) {
18045
+ switch (action.type) {
18046
+ case "ADD_CARD":
18047
+ return {
18048
+ ...state,
18049
+ cards: [...state.cards, action.card]
18050
+ };
18051
+ case "REMOVE_CARD":
18052
+ return {
18053
+ ...state,
18054
+ cards: state.cards.filter((c) => c.id !== action.cardId),
18055
+ connections: state.connections.filter(
18056
+ (conn) => conn.fromCardId !== action.cardId && conn.toCardId !== action.cardId
18057
+ )
18058
+ };
18059
+ case "MOVE_CARD":
18060
+ return {
18061
+ ...state,
18062
+ cards: state.cards.map(
18063
+ (c) => c.id === action.cardId ? { ...c, position: action.position, updatedAt: Date.now() } : c
18064
+ )
18065
+ };
18066
+ case "RESIZE_CARD":
18067
+ return {
18068
+ ...state,
18069
+ cards: state.cards.map(
18070
+ (c) => c.id === action.cardId ? { ...c, size: action.size, updatedAt: Date.now() } : c
18071
+ )
18072
+ };
18073
+ case "UPDATE_CARD":
18074
+ return {
18075
+ ...state,
18076
+ cards: state.cards.map(
18077
+ (c) => c.id === action.cardId ? { ...c, ...action.updates, updatedAt: Date.now() } : c
18078
+ )
18079
+ };
18080
+ case "DUPLICATE_CARD": {
18081
+ const source = state.cards.find((c) => c.id === action.cardId);
18082
+ if (!source) return state;
18083
+ const offset = action.offset || { x: 20, y: 20 };
18084
+ const duplicate = {
18085
+ ...source,
18086
+ id: action.newId,
18087
+ position: {
18088
+ x: source.position.x + offset.x,
18089
+ y: source.position.y + offset.y
18090
+ },
18091
+ createdAt: Date.now(),
18092
+ updatedAt: Date.now()
18093
+ };
18094
+ return {
18095
+ ...state,
18096
+ cards: [...state.cards, duplicate]
18097
+ };
18098
+ }
18099
+ case "ADD_CONNECTION":
18100
+ return {
18101
+ ...state,
18102
+ connections: [...state.connections, action.connection]
18103
+ };
18104
+ case "REMOVE_CONNECTION":
18105
+ return {
18106
+ ...state,
18107
+ connections: state.connections.filter(
18108
+ (conn) => conn.id !== action.connectionId
18109
+ )
18110
+ };
18111
+ case "PAN":
18112
+ return {
18113
+ ...state,
18114
+ viewport: { ...state.viewport, panX: action.panX, panY: action.panY }
18115
+ };
18116
+ case "ZOOM": {
18117
+ const clamped = Math.max(0.25, Math.min(4, action.zoom));
18118
+ return {
18119
+ ...state,
18120
+ viewport: { ...state.viewport, zoom: clamped }
18121
+ };
18122
+ }
18123
+ case "SET_BOARD":
18124
+ return action.state;
18125
+ default:
18126
+ return state;
18127
+ }
18128
+ }
18129
+ function isViewportOnly(action) {
18130
+ return action.type === "PAN" || action.type === "ZOOM";
18131
+ }
18132
+ function historyReducer(state, action) {
18133
+ switch (action.type) {
18134
+ case "UNDO": {
18135
+ if (state.past.length === 0) return state;
18136
+ const previous = state.past[state.past.length - 1];
18137
+ const newPast = state.past.slice(0, state.past.length - 1);
18138
+ return {
18139
+ past: newPast,
18140
+ present: previous,
18141
+ future: [state.present, ...state.future]
18142
+ };
18143
+ }
18144
+ case "REDO": {
18145
+ if (state.future.length === 0) return state;
18146
+ const next = state.future[0];
18147
+ const newFuture = state.future.slice(1);
18148
+ return {
18149
+ past: [...state.past, state.present],
18150
+ present: next,
18151
+ future: newFuture
18152
+ };
18153
+ }
18154
+ case "BOARD_ACTION": {
18155
+ const newPresent = boardReducer(state.present, action.action);
18156
+ if (newPresent === state.present) return state;
18157
+ if (isViewportOnly(action.action)) {
18158
+ return { ...state, present: newPresent };
18159
+ }
18160
+ if (action.action.type === "SET_BOARD") {
18161
+ return { past: [], present: newPresent, future: [] };
18162
+ }
18163
+ const newPast = [...state.past, state.present];
18164
+ if (newPast.length > MAX_HISTORY) {
18165
+ newPast.splice(0, newPast.length - MAX_HISTORY);
18166
+ }
18167
+ return {
18168
+ past: newPast,
18169
+ present: newPresent,
18170
+ future: []
18171
+ };
18172
+ }
18173
+ default:
18174
+ return state;
18175
+ }
18176
+ }
18177
+ function useBoardState(storage2, boardId) {
18178
+ const initialHistory = {
18179
+ past: [],
18180
+ present: DEFAULT_BOARD_STATE,
18181
+ future: []
18182
+ };
18183
+ const [history, historyDispatch] = useReducer(historyReducer, initialHistory);
18184
+ const dispatch = useCallback((action) => {
18185
+ historyDispatch({ type: "BOARD_ACTION", action });
18186
+ }, [historyDispatch]);
18187
+ const undo = useCallback(() => {
18188
+ historyDispatch({ type: "UNDO" });
18189
+ }, [historyDispatch]);
18190
+ const redo = useCallback(() => {
18191
+ historyDispatch({ type: "REDO" });
18192
+ }, [historyDispatch]);
18193
+ const loadedRef = useRef(false);
18194
+ useEffect(() => {
18195
+ if (storage2 && boardId && !loadedRef.current) {
18196
+ loadedRef.current = true;
18197
+ storage2.load(boardId).then((loaded) => {
18198
+ dispatch({ type: "SET_BOARD", state: loaded });
18199
+ }).catch(() => {
18200
+ });
18201
+ }
18202
+ }, [storage2, boardId, dispatch]);
18203
+ const saveTimerRef = useRef(null);
18204
+ const stateRef = useRef(history.present);
18205
+ stateRef.current = history.present;
18206
+ useEffect(() => {
18207
+ if (!storage2 || !boardId) return;
18208
+ if (saveTimerRef.current !== null) {
18209
+ clearTimeout(saveTimerRef.current);
18210
+ }
18211
+ saveTimerRef.current = setTimeout(() => {
18212
+ storage2.save(boardId, stateRef.current).catch(() => {
18213
+ });
18214
+ saveTimerRef.current = null;
18215
+ }, 500);
18216
+ return () => {
18217
+ if (saveTimerRef.current !== null) {
18218
+ clearTimeout(saveTimerRef.current);
18219
+ }
18220
+ };
18221
+ }, [storage2, boardId, history.present]);
18222
+ return {
18223
+ state: history.present,
18224
+ dispatch,
18225
+ undo,
18226
+ redo,
18227
+ canUndo: history.past.length > 0,
18228
+ canRedo: history.future.length > 0
18229
+ };
18230
+ }
18231
+
18232
+ // ../demos/project-manager/src/LocalStorage.ts
18233
+ var DEFAULT_STATE = {
18234
+ cards: [],
18235
+ connections: [],
18236
+ viewport: { panX: 0, panY: 0, zoom: 1 }
18237
+ };
18238
+ var LocalBoardStorage = class {
18239
+ async load(boardId) {
18240
+ try {
18241
+ const raw = localStorage.getItem("board:" + boardId);
18242
+ if (!raw) return DEFAULT_STATE;
18243
+ const parsed = JSON.parse(raw);
18244
+ return parsed;
18245
+ } catch {
18246
+ return DEFAULT_STATE;
18247
+ }
18248
+ }
18249
+ async save(boardId, state) {
18250
+ try {
18251
+ localStorage.setItem("board:" + boardId, JSON.stringify(state));
18252
+ } catch {
18253
+ }
18254
+ }
18255
+ };
18256
+
18257
+ // ../demos/project-manager/src/InterApp.ts
18258
+ function InterAppWrapper(props) {
18259
+ const { cards, onCardDropped, children } = props;
18260
+ const messageBus = useMessageBus();
18261
+ const prevCardsRef = useRef([]);
18262
+ useEffect(() => {
18263
+ const prevCards = prevCardsRef.current;
18264
+ const prevIds = new Set(prevCards.map((c) => c.id));
18265
+ const currIds = new Set(cards.map((c) => c.id));
18266
+ for (const card of cards) {
18267
+ if (!prevIds.has(card.id)) {
18268
+ messageBus.publish("project-board", { event: "card-created", card });
18269
+ }
18270
+ }
18271
+ for (const card of prevCards) {
18272
+ if (!currIds.has(card.id)) {
18273
+ messageBus.publish("project-board", { event: "card-deleted", cardId: card.id });
18274
+ }
18275
+ }
18276
+ for (const card of cards) {
18277
+ if (prevIds.has(card.id)) {
18278
+ const prev = prevCards.find((c) => c.id === card.id);
18279
+ if (prev && prev.updatedAt !== card.updatedAt) {
18280
+ messageBus.publish("project-board", { event: "card-updated", card });
18281
+ }
18282
+ }
18283
+ }
18284
+ prevCardsRef.current = cards;
18285
+ }, [cards, messageBus]);
18286
+ const handleDrop = useCallback(
18287
+ (payload) => {
18288
+ if (payload.type === "text/plain" && typeof payload.data === "string") {
18289
+ onCardDropped(payload.data, "");
18290
+ } else if (payload.type === "application/json") {
18291
+ const data = payload.data;
18292
+ onCardDropped(
18293
+ String(data.title || "Dropped Item"),
18294
+ String(data.description || "")
18295
+ );
18296
+ }
18297
+ },
18298
+ [onCardDropped]
18299
+ );
18300
+ const { isOver } = useDropZone({
18301
+ acceptTypes: ["text/plain", "application/json", "application/project-card"],
18302
+ onDrop: handleDrop
18303
+ });
18304
+ const style = {
18305
+ width: "100%",
18306
+ height: "100%",
18307
+ ...isOver ? { outline: "2px dashed #3b82f6", outlineOffset: "-2px" } : {}
18308
+ };
18309
+ return createElement("div", {
18310
+ style,
18311
+ "data-dropzone-id": "project-board-dropzone"
18312
+ }, children);
18313
+ }
18314
+
18315
+ // ../demos/project-manager/src/index.ts
18316
+ var cardIdCounter = 0;
18317
+ function generateCardId() {
18318
+ cardIdCounter++;
18319
+ return `card-${Date.now()}-${cardIdCounter}`;
18320
+ }
18321
+ var storage = new LocalBoardStorage();
18322
+ var SAMPLE_CARDS = [
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() },
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() },
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() }
18327
+ ];
18328
+ var SAMPLE_BOARD = {
18329
+ id: "sample-board-001",
18330
+ name: "Sample Project",
18331
+ cards: SAMPLE_CARDS,
18332
+ connections: [
18333
+ { id: "sample-conn-1", fromCardId: "sample-1", toCardId: "sample-2" }
18334
+ ],
18335
+ viewport: { panX: 0, panY: 0, zoom: 1 }
18336
+ };
18337
+ function isBoardEmpty(state) {
18338
+ return state.cards.length === 0 && state.connections.length === 0;
18339
+ }
18340
+ function ProjectManagerApp(props) {
18341
+ const boardId = props.boardId || "default";
18342
+ const { state, dispatch, undo, redo, canUndo, canRedo } = useBoardState(storage, boardId);
18343
+ const [selectedColor, setSelectedColor] = useState(CARD_COLORS[0]);
18344
+ const [gridEnabled, setGridEnabled] = useState(false);
18345
+ const [searchQuery, setSearchQuery] = useState("");
18346
+ const [selectedCardId, setSelectedCardId] = useState(null);
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("");
18352
+ const sampleLoadedRef = useRef(false);
18353
+ useEffect(() => {
18354
+ if (!sampleLoadedRef.current && isBoardEmpty(state)) {
18355
+ sampleLoadedRef.current = true;
18356
+ dispatch({ type: "SET_BOARD", state: SAMPLE_BOARD });
18357
+ } else if (state.cards.length > 0) {
18358
+ sampleLoadedRef.current = true;
18359
+ }
18360
+ }, [state, dispatch]);
18361
+ const handleNewCard = useCallback(() => {
18362
+ const cx = (-state.viewport.panX + 300) / state.viewport.zoom;
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;
18366
+ const newCard = {
18367
+ id: generateCardId(),
18368
+ title: "New Card",
18369
+ description: "",
18370
+ color: selectedColor,
18371
+ position: { x: Math.round(cx + offsetX), y: Math.round(cy + offsetY) },
18372
+ size: { width: 180, height: 120 },
18373
+ priority: "medium",
18374
+ createdAt: Date.now(),
18375
+ updatedAt: Date.now()
18376
+ };
18377
+ dispatch({ type: "ADD_CARD", card: newCard });
18378
+ }, [state.viewport, selectedColor, dispatch]);
18379
+ const handleZoomIn = useCallback(() => {
18380
+ dispatch({ type: "ZOOM", zoom: state.viewport.zoom + 0.1 });
18381
+ }, [state.viewport.zoom, dispatch]);
18382
+ const handleZoomOut = useCallback(() => {
18383
+ dispatch({ type: "ZOOM", zoom: state.viewport.zoom - 0.1 });
18384
+ }, [state.viewport.zoom, dispatch]);
18385
+ const handleZoomReset = useCallback(() => {
18386
+ dispatch({ type: "ZOOM", zoom: 1 });
18387
+ }, [dispatch]);
18388
+ const handleGridToggle = useCallback(() => {
18389
+ setGridEnabled((prev) => !prev);
18390
+ }, []);
18391
+ const handleSearch = useCallback((query) => {
18392
+ setSearchQuery(query);
18393
+ }, []);
18394
+ const handleSelectCard = useCallback((cardId) => {
18395
+ setSelectedCardId(cardId);
18396
+ }, []);
18397
+ const handleColorFilter = useCallback((color) => {
18398
+ setColorFilter(color);
18399
+ }, []);
18400
+ const handleNewBoard = useCallback(() => {
18401
+ dispatch({ type: "SET_BOARD", state: DEFAULT_BOARD_STATE });
18402
+ setSelectedCardId(null);
18403
+ }, [dispatch]);
18404
+ const handleExportJSON = useCallback(() => {
18405
+ const json = JSON.stringify(state, null, 2);
18406
+ const blob = new Blob([json], { type: "application/json" });
18407
+ const url = URL.createObjectURL(blob);
18408
+ const a = document.createElement("a");
18409
+ a.href = url;
18410
+ a.download = `board-${boardId}.json`;
18411
+ a.style.display = "none";
18412
+ document.body.appendChild(a);
18413
+ a.click();
18414
+ document.body.removeChild(a);
18415
+ URL.revokeObjectURL(url);
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
+ }, []);
18452
+ const handleDeleteSelected = useCallback(() => {
18453
+ if (selectedCardId) {
18454
+ dispatch({ type: "REMOVE_CARD", cardId: selectedCardId });
18455
+ setSelectedCardId(null);
18456
+ }
18457
+ }, [selectedCardId, dispatch]);
18458
+ const handleFitAll = useCallback(() => {
18459
+ if (state.cards.length === 0) return;
18460
+ const containerWidth = 800;
18461
+ const containerHeight = 600;
18462
+ const fit = computeFitAll(state.cards, containerWidth, containerHeight);
18463
+ dispatch({ type: "PAN", panX: fit.panX, panY: fit.panY });
18464
+ dispatch({ type: "ZOOM", zoom: fit.zoom });
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]);
18492
+ useEffect(() => {
18493
+ const _menuBar = {
18494
+ menus: [
18495
+ { label: "File", items: [
18496
+ { label: "New Board", onClick: handleNewBoard },
18497
+ { label: "Export JSON", onClick: handleExportJSON },
18498
+ { label: "Import JSON", onClick: handleImportJSON },
18499
+ { divider: true },
18500
+ { label: "Print", onClick: handlePrint }
18501
+ ] },
18502
+ { label: "Edit", items: [
18503
+ { label: "Undo", shortcut: "Ctrl+Z", onClick: undo, disabled: !canUndo },
18504
+ { label: "Redo", shortcut: "Ctrl+Y", onClick: redo, disabled: !canRedo },
18505
+ { divider: true },
18506
+ { label: "Select All", shortcut: "Ctrl+A", onClick: handleSelectAll },
18507
+ { label: "Delete Selected", onClick: handleDeleteSelected }
18508
+ ] },
18509
+ { label: "View", items: [
18510
+ { label: "Zoom In", onClick: handleZoomIn },
18511
+ { label: "Zoom Out", onClick: handleZoomOut },
18512
+ { label: "Fit All", onClick: handleFitAll },
18513
+ { divider: true },
18514
+ { label: "Toggle Grid", onClick: handleGridToggle },
18515
+ { label: showConnections ? "Hide Connections" : "Show Connections", onClick: handleToggleConnections }
18516
+ ] }
18517
+ ]
18518
+ };
18519
+ }, [handleNewBoard, handleExportJSON, handleImportJSON, handlePrint, undo, redo, canUndo, canRedo, handleSelectAll, handleDeleteSelected, handleZoomIn, handleZoomOut, handleFitAll, handleGridToggle, handleToggleConnections, showConnections]);
18520
+ useEffect(() => {
18521
+ const handleKeyDown = (e) => {
18522
+ const ke = e;
18523
+ if (ke.ctrlKey && ke.key === "z") {
18524
+ ke.preventDefault();
18525
+ undo();
18526
+ } else if (ke.ctrlKey && ke.key === "y") {
18527
+ ke.preventDefault();
18528
+ redo();
18529
+ }
18530
+ };
18531
+ document.addEventListener("keydown", handleKeyDown);
18532
+ return () => document.removeEventListener("keydown", handleKeyDown);
18533
+ }, [undo, redo]);
18534
+ const containerStyle3 = {
18535
+ display: "flex",
18536
+ flexDirection: "column",
18537
+ width: "100%",
18538
+ height: "100%",
18539
+ backgroundColor: "#f8fafc",
18540
+ overflow: "hidden"
18541
+ };
18542
+ const handleCardDropped = useCallback((title, description) => {
18543
+ const cx = (-state.viewport.panX + 300) / state.viewport.zoom;
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;
18547
+ const newCard = {
18548
+ id: generateCardId(),
18549
+ title,
18550
+ description,
18551
+ color: selectedColor,
18552
+ position: { x: Math.round(cx + offsetX), y: Math.round(cy + offsetY) },
18553
+ size: { width: 180, height: 120 },
18554
+ priority: "medium",
18555
+ createdAt: Date.now(),
18556
+ updatedAt: Date.now()
18557
+ };
18558
+ dispatch({ type: "ADD_CARD", card: newCard });
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;
18687
+ return createElement(
18688
+ "div",
18689
+ {
18690
+ className: "project-manager-app",
18691
+ style: containerStyle3,
18692
+ "data-testid": "project-manager-app"
18693
+ },
18694
+ appMenuBar,
18695
+ createElement(BoardToolbar, {
18696
+ zoom: state.viewport.zoom,
18697
+ gridEnabled,
18698
+ selectedColor,
18699
+ colorFilter,
18700
+ onNewCard: handleNewCard,
18701
+ onZoomIn: handleZoomIn,
18702
+ onZoomOut: handleZoomOut,
18703
+ onZoomReset: handleZoomReset,
18704
+ onColorSelect: setSelectedColor,
18705
+ onColorFilter: handleColorFilter,
18706
+ onGridToggle: handleGridToggle,
18707
+ onSearch: handleSearch
18708
+ }),
18709
+ createElement(
18710
+ InterAppWrapper,
18711
+ {
18712
+ cards: state.cards,
18713
+ onCardDropped: handleCardDropped
18714
+ },
18715
+ createElement(Board, {
18716
+ state,
18717
+ dispatch,
18718
+ searchQuery,
18719
+ gridEnabled,
18720
+ selectedCardId,
18721
+ onSelectCard: handleSelectCard,
18722
+ colorFilter,
18723
+ showConnections
18724
+ })
18725
+ ),
18726
+ renameDialogEl
18727
+ );
18728
+ }
18729
+
16455
18730
  // ../components/page/unity-desktop/src/UnityDesktop.ts
16456
18731
  var PANEL_HEIGHT = 28;
16457
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
+ }
16458
18741
  function ToastContainer2(props) {
16459
18742
  const { toasts, onDismiss } = props;
16460
18743
  if (toasts.length === 0) return null;
@@ -16609,7 +18892,8 @@ function getMockContent(title) {
16609
18892
  height: "100%",
16610
18893
  overflow: "auto"
16611
18894
  };
16612
- switch (title) {
18895
+ const baseName = baseLabel(title);
18896
+ switch (baseName) {
16613
18897
  case "Files":
16614
18898
  return createElement(
16615
18899
  AppContextProvider,
@@ -16653,6 +18937,8 @@ function getMockContent(title) {
16653
18937
  return createElement(IDE, null);
16654
18938
  case "Trading":
16655
18939
  return createElement(TradingDashboard, null);
18940
+ case "Project Board":
18941
+ return createElement(ProjectManagerApp, null);
16656
18942
  default:
16657
18943
  return createElement(
16658
18944
  "div",
@@ -16666,6 +18952,8 @@ function UnityDesktopInner(props) {
16666
18952
  const wm = useWindowManager();
16667
18953
  const wmActiveMenuBar = wm.activeMenuBar;
16668
18954
  const wmDockSignals = wm.dockSignals;
18955
+ const wmRef = useRef(wm);
18956
+ wmRef.current = wm;
16669
18957
  const [openWindows, setOpenWindows] = useState([]);
16670
18958
  const [toasts, setToasts] = useState([]);
16671
18959
  const [showAppsGrid, setShowAppsGrid] = useState(false);
@@ -16693,20 +18981,20 @@ function UnityDesktopInner(props) {
16693
18981
  appsRef.current = apps;
16694
18982
  const onAppOpenRef = useRef(onAppOpen);
16695
18983
  onAppOpenRef.current = onAppOpen;
16696
- 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;
16697
18988
  setOpenWindows((prev) => {
16698
- const existing = prev.find((w) => w.id === id);
16699
- if (existing) {
16700
- const maxZ2 = Math.max(...prev.map((w) => w.zIndex)) + 1;
16701
- return prev.map((w) => w.id === id ? { ...w, focused: true, zIndex: maxZ2, windowState: w.windowState === "minimized" ? "normal" : w.windowState } : { ...w, focused: false });
16702
- }
16703
- const currentApps = appsRef.current;
16704
- const app = currentApps.find((a) => a.id === id);
16705
- 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);
16706
18993
  const maxZ = prev.length > 0 ? Math.max(...prev.map((w) => w.zIndex)) + 1 : 1;
16707
18994
  const newWin = {
16708
- id: app.id,
16709
- title: app.label,
18995
+ id: winId,
18996
+ appId: app.id,
18997
+ title,
16710
18998
  icon: app.icon,
16711
18999
  x: 60 + prev.length * 30,
16712
19000
  y: 40 + prev.length * 30,
@@ -16718,8 +19006,8 @@ function UnityDesktopInner(props) {
16718
19006
  };
16719
19007
  return [...prev.map((w) => ({ ...w, focused: false })), newWin];
16720
19008
  });
16721
- if (id === "files") {
16722
- wm.setMenuBar("files", {
19009
+ if (appId === "files") {
19010
+ wmRef.current.setMenuBar("files", {
16723
19011
  menus: [
16724
19012
  {
16725
19013
  label: "File",
@@ -16746,13 +19034,90 @@ function UnityDesktopInner(props) {
16746
19034
  ]
16747
19035
  });
16748
19036
  }
16749
- if (id === "terminal") {
16750
- wm.signalDock("terminal", { badge: 3 });
19037
+ if (appId === "terminal") {
19038
+ wmRef.current.signalDock("terminal", { badge: 3 });
16751
19039
  }
16752
- if (onAppOpenRef.current) onAppOpenRef.current(id);
16753
- }, [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
+ }, []);
16754
19119
  const dockItems = apps.map((app) => {
16755
- const isRunning = openWindows.some((w) => w.id === app.id);
19120
+ const isRunning = openWindows.some((w) => w.appId === app.id);
16756
19121
  const signal = wmDockSignals.get(app.id);
16757
19122
  const item = {
16758
19123
  id: app.id,
@@ -16960,20 +19325,70 @@ function UnityDesktopInner(props) {
16960
19325
  createElement("div", { style: { fontSize: "24px", fontWeight: "600", marginBottom: "8px" } }, "Locked"),
16961
19326
  createElement("div", { style: { fontSize: "14px", opacity: "0.7" } }, "Click to unlock")
16962
19327
  ) : null;
16963
- const contextMenuEl = contextMenuAppId ? createElement(
16964
- "div",
16965
- {
16966
- className: "unity-desktop__context-menu-backdrop",
16967
- style: {
16968
- position: "absolute",
16969
- inset: "0",
16970
- 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";
16971
19336
  },
16972
- onClick: closeContextMenu
16973
- },
16974
- 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(
16975
19381
  "div",
16976
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", {
16977
19392
  className: "unity-desktop__context-menu",
16978
19393
  style: {
16979
19394
  position: "absolute",
@@ -16990,20 +19405,9 @@ function UnityDesktopInner(props) {
16990
19405
  fontSize: "13px"
16991
19406
  },
16992
19407
  onClick: (e) => e.stopPropagation()
16993
- },
16994
- createElement("div", {
16995
- style: { padding: "6px 14px", fontWeight: "600", borderBottom: "1px solid #444", marginBottom: "4px" }
16996
- }, apps.find((a) => a.id === contextMenuAppId)?.label || contextMenuAppId),
16997
- createElement("div", {
16998
- style: { padding: "6px 14px", cursor: "pointer" },
16999
- onClick: () => {
17000
- setAboutAppId(contextMenuAppId);
17001
- setContextMenuAppId(null);
17002
- },
17003
- role: "menuitem"
17004
- }, "About")
17005
- )
17006
- ) : null;
19408
+ }, ...menuChildren)
19409
+ );
19410
+ })();
17007
19411
  const aboutApp = aboutAppId ? apps.find((a) => a.id === aboutAppId) : null;
17008
19412
  const aboutDialogEl = aboutApp ? createElement(
17009
19413
  "div",