@asymmetric-effort/specifyjs 0.2.142 → 0.2.143

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.
@@ -12367,6 +12367,336 @@ function useWindowManager() {
12367
12367
  return useContext(WindowManagerContext);
12368
12368
  }
12369
12369
 
12370
+ // ../components/layout/app-message-bus/src/MessageBus.ts
12371
+ var AppContext = createContext({
12372
+ appId: ""
12373
+ });
12374
+ function AppContextProvider(props) {
12375
+ const value = useMemo(() => ({ appId: props.appId }), [props.appId]);
12376
+ return createElement(AppContext.Provider, { value }, props.children);
12377
+ }
12378
+ function useAppId() {
12379
+ const ctx = useContext(AppContext);
12380
+ return ctx.appId;
12381
+ }
12382
+ var MessageBusContext = createContext({
12383
+ publish: () => {
12384
+ },
12385
+ subscribe: () => () => {
12386
+ },
12387
+ subscribeAll: () => () => {
12388
+ }
12389
+ });
12390
+ function MessageBusProvider(props) {
12391
+ const channelSubsRef = useRef([]);
12392
+ const globalSubsRef = useRef([]);
12393
+ const publish = useCallback(
12394
+ ((...args) => {
12395
+ const channel = args[0];
12396
+ const payload = args[1];
12397
+ const to = args[2];
12398
+ const from = args[3] || "";
12399
+ const message = {
12400
+ channel,
12401
+ from,
12402
+ to: to || null,
12403
+ payload,
12404
+ timestamp: Date.now()
12405
+ };
12406
+ const channelSubs = channelSubsRef.current;
12407
+ for (let i = 0; i < channelSubs.length; i++) {
12408
+ const sub = channelSubs[i];
12409
+ if (sub.channel !== channel) continue;
12410
+ if (message.to && sub.appId !== message.to) continue;
12411
+ if (!message.to && sub.appId === from) continue;
12412
+ sub.handler(message);
12413
+ }
12414
+ const globalSubs = globalSubsRef.current;
12415
+ for (let i = 0; i < globalSubs.length; i++) {
12416
+ globalSubs[i].handler(message);
12417
+ }
12418
+ }),
12419
+ []
12420
+ );
12421
+ const subscribe = useCallback(
12422
+ ((...args) => {
12423
+ const channel = args[0];
12424
+ const handler = args[1];
12425
+ const appId = args[2] || "";
12426
+ const sub = { channel, handler, appId };
12427
+ channelSubsRef.current = [...channelSubsRef.current, sub];
12428
+ return () => {
12429
+ channelSubsRef.current = channelSubsRef.current.filter(
12430
+ (s) => s !== sub
12431
+ );
12432
+ };
12433
+ }),
12434
+ []
12435
+ );
12436
+ const subscribeAll = useCallback(
12437
+ ((...args) => {
12438
+ const handler = args[0];
12439
+ const sub = { handler };
12440
+ globalSubsRef.current = [...globalSubsRef.current, sub];
12441
+ return () => {
12442
+ globalSubsRef.current = globalSubsRef.current.filter(
12443
+ (s) => s !== sub
12444
+ );
12445
+ };
12446
+ }),
12447
+ []
12448
+ );
12449
+ const value = useMemo(
12450
+ () => ({ publish, subscribe, subscribeAll }),
12451
+ [publish, subscribe, subscribeAll]
12452
+ );
12453
+ return createElement(MessageBusContext.Provider, { value }, props.children);
12454
+ }
12455
+ function useMessageBus() {
12456
+ const ctx = useContext(MessageBusContext);
12457
+ const appId = useAppId();
12458
+ const publish = useCallback(
12459
+ ((...args) => {
12460
+ const channel = args[0];
12461
+ const payload = args[1];
12462
+ const to = args[2];
12463
+ ctx.publish(channel, payload, to, appId);
12464
+ }),
12465
+ [ctx.publish, appId]
12466
+ );
12467
+ const subscribe = useCallback(
12468
+ ((...args) => {
12469
+ const channel = args[0];
12470
+ const handler = args[1];
12471
+ return ctx.subscribe(channel, handler, appId);
12472
+ }),
12473
+ [ctx.subscribe, appId]
12474
+ );
12475
+ return useMemo(
12476
+ () => ({ publish, subscribe, subscribeAll: ctx.subscribeAll }),
12477
+ [publish, subscribe, ctx.subscribeAll]
12478
+ );
12479
+ }
12480
+ function useChannel(channel, handler) {
12481
+ const bus = useMessageBus();
12482
+ const handlerRef = useRef(handler);
12483
+ handlerRef.current = handler;
12484
+ useEffect(() => {
12485
+ const unsubscribe = bus.subscribe(channel, (msg) => {
12486
+ handlerRef.current(msg);
12487
+ });
12488
+ return unsubscribe;
12489
+ }, [bus, channel]);
12490
+ }
12491
+
12492
+ // ../components/layout/app-drag-drop/src/DragDrop.ts
12493
+ var DragDropContext = createContext({
12494
+ startDrag: () => {
12495
+ },
12496
+ cancelDrag: () => {
12497
+ },
12498
+ registerDropZone: () => () => {
12499
+ },
12500
+ currentDrag: null,
12501
+ isDragging: false
12502
+ });
12503
+ function DragDropProvider(props) {
12504
+ const [currentDrag, setCurrentDrag] = useState(null);
12505
+ const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
12506
+ const dropZonesRef = useRef(/* @__PURE__ */ new Map());
12507
+ const activeZoneRef = useRef(null);
12508
+ const isDragging = currentDrag !== null;
12509
+ const startDrag = useCallback(
12510
+ ((...args) => {
12511
+ const payload = args[0];
12512
+ setCurrentDrag(payload);
12513
+ }),
12514
+ []
12515
+ );
12516
+ const cancelDrag = useCallback(
12517
+ ((..._args) => {
12518
+ if (activeZoneRef.current) {
12519
+ const zone = dropZonesRef.current.get(activeZoneRef.current);
12520
+ if (zone && zone.onDragLeave) {
12521
+ zone.onDragLeave();
12522
+ }
12523
+ activeZoneRef.current = null;
12524
+ }
12525
+ setCurrentDrag(null);
12526
+ }),
12527
+ []
12528
+ );
12529
+ const registerDropZone = useCallback(
12530
+ ((...args) => {
12531
+ const zoneId = args[0];
12532
+ const zone = args[1];
12533
+ dropZonesRef.current = new Map(dropZonesRef.current);
12534
+ dropZonesRef.current.set(zoneId, zone);
12535
+ return () => {
12536
+ dropZonesRef.current = new Map(dropZonesRef.current);
12537
+ dropZonesRef.current.delete(zoneId);
12538
+ if (activeZoneRef.current === zoneId) {
12539
+ activeZoneRef.current = null;
12540
+ }
12541
+ };
12542
+ }),
12543
+ []
12544
+ );
12545
+ useEffect(() => {
12546
+ if (!isDragging) return;
12547
+ const handleMouseMove = (e) => {
12548
+ const me = e;
12549
+ setMousePos({ x: me.clientX, y: me.clientY });
12550
+ const elementAtPoint = document.elementFromPoint(me.clientX, me.clientY);
12551
+ if (!elementAtPoint) return;
12552
+ let foundZoneId = null;
12553
+ const zones = dropZonesRef.current;
12554
+ zones.forEach((_zone, zoneId) => {
12555
+ const zoneEl = document.querySelector(`[data-dropzone-id="${zoneId}"]`);
12556
+ if (zoneEl && zoneEl.contains(elementAtPoint)) {
12557
+ foundZoneId = zoneId;
12558
+ }
12559
+ });
12560
+ const prevZoneId = activeZoneRef.current;
12561
+ if (foundZoneId !== prevZoneId) {
12562
+ if (prevZoneId) {
12563
+ const prevZone = zones.get(prevZoneId);
12564
+ if (prevZone && prevZone.onDragLeave) {
12565
+ prevZone.onDragLeave();
12566
+ }
12567
+ }
12568
+ if (foundZoneId) {
12569
+ const newZone = zones.get(foundZoneId);
12570
+ if (newZone && newZone.onDragEnter && currentDrag) {
12571
+ if (newZone.acceptTypes.indexOf(currentDrag.type) !== -1) {
12572
+ newZone.onDragEnter(currentDrag);
12573
+ }
12574
+ }
12575
+ }
12576
+ activeZoneRef.current = foundZoneId;
12577
+ }
12578
+ };
12579
+ const handleMouseUp = (_e) => {
12580
+ const activeId = activeZoneRef.current;
12581
+ if (activeId && currentDrag) {
12582
+ const zone = dropZonesRef.current.get(activeId);
12583
+ if (zone && zone.acceptTypes.indexOf(currentDrag.type) !== -1) {
12584
+ zone.onDrop(currentDrag);
12585
+ }
12586
+ }
12587
+ activeZoneRef.current = null;
12588
+ setCurrentDrag(null);
12589
+ };
12590
+ const handleKeyDown = (e) => {
12591
+ const ke = e;
12592
+ if (ke.key === "Escape") {
12593
+ cancelDrag();
12594
+ }
12595
+ };
12596
+ document.addEventListener("mousemove", handleMouseMove);
12597
+ document.addEventListener("mouseup", handleMouseUp);
12598
+ document.addEventListener("keydown", handleKeyDown);
12599
+ return () => {
12600
+ document.removeEventListener("mousemove", handleMouseMove);
12601
+ document.removeEventListener("mouseup", handleMouseUp);
12602
+ document.removeEventListener("keydown", handleKeyDown);
12603
+ };
12604
+ }, [isDragging, currentDrag, cancelDrag]);
12605
+ const value = useMemo(
12606
+ () => ({
12607
+ startDrag,
12608
+ cancelDrag,
12609
+ registerDropZone,
12610
+ currentDrag,
12611
+ isDragging
12612
+ }),
12613
+ [startDrag, cancelDrag, registerDropZone, currentDrag, isDragging]
12614
+ );
12615
+ const previewEl = isDragging ? createElement(
12616
+ "div",
12617
+ {
12618
+ className: "drag-drop-preview",
12619
+ style: {
12620
+ position: "fixed",
12621
+ left: `${mousePos.x + 12}px`,
12622
+ top: `${mousePos.y + 12}px`,
12623
+ pointerEvents: "none",
12624
+ zIndex: "10000",
12625
+ opacity: "0.8",
12626
+ padding: "6px 10px",
12627
+ backgroundColor: "rgba(50, 50, 50, 0.9)",
12628
+ color: "#ffffff",
12629
+ borderRadius: "4px",
12630
+ fontSize: "12px",
12631
+ boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
12632
+ whiteSpace: "nowrap"
12633
+ }
12634
+ },
12635
+ currentDrag && currentDrag.preview ? String(currentDrag.preview) : `Dragging ${currentDrag ? currentDrag.type : ""}`
12636
+ ) : null;
12637
+ return createElement(
12638
+ DragDropContext.Provider,
12639
+ { value },
12640
+ props.children,
12641
+ previewEl
12642
+ );
12643
+ }
12644
+ function useDragDrop() {
12645
+ return useContext(DragDropContext);
12646
+ }
12647
+ function useDraggable(type, data) {
12648
+ const ctx = useDragDrop();
12649
+ const appId = useAppId();
12650
+ const dataRef = useRef(data);
12651
+ dataRef.current = data;
12652
+ const onMouseDown = useCallback(
12653
+ (e) => {
12654
+ e.preventDefault();
12655
+ ctx.startDrag({
12656
+ type,
12657
+ data: dataRef.current,
12658
+ sourceAppId: appId || ""
12659
+ });
12660
+ },
12661
+ [ctx, type, appId]
12662
+ );
12663
+ const isDragging = ctx.isDragging && ctx.currentDrag !== null && ctx.currentDrag.type === type;
12664
+ return useMemo(
12665
+ () => ({ onMouseDown, isDragging }),
12666
+ [onMouseDown, isDragging]
12667
+ );
12668
+ }
12669
+ function useDropZone(config) {
12670
+ const ctx = useDragDrop();
12671
+ const [isOver, setIsOver] = useState(false);
12672
+ const zoneIdRef = useRef(config.zoneId || `zone-${Math.random().toString(36).slice(2, 10)}`);
12673
+ const configRef = useRef(config);
12674
+ configRef.current = config;
12675
+ useEffect(() => {
12676
+ const cleanup = ctx.registerDropZone(zoneIdRef.current, {
12677
+ acceptTypes: configRef.current.acceptTypes,
12678
+ onDragEnter: (payload) => {
12679
+ setIsOver(true);
12680
+ if (configRef.current.onDragEnter) configRef.current.onDragEnter(payload);
12681
+ },
12682
+ onDragLeave: () => {
12683
+ setIsOver(false);
12684
+ if (configRef.current.onDragLeave) configRef.current.onDragLeave();
12685
+ },
12686
+ onDrop: (payload) => {
12687
+ setIsOver(false);
12688
+ configRef.current.onDrop(payload);
12689
+ }
12690
+ });
12691
+ return cleanup;
12692
+ }, [ctx]);
12693
+ const canDrop = ctx.isDragging && ctx.currentDrag !== null && config.acceptTypes.indexOf(ctx.currentDrag.type) !== -1;
12694
+ return useMemo(
12695
+ () => ({ isOver, canDrop, zoneId: zoneIdRef.current }),
12696
+ [isOver, canDrop]
12697
+ );
12698
+ }
12699
+
12370
12700
  // ../components/nav/system-tray/src/SystemTray.ts
12371
12701
  var DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
12372
12702
  var MONTHS = [
@@ -16175,6 +16505,102 @@ function ToastContainer2(props) {
16175
16505
  "aria-label": "Notifications"
16176
16506
  }, ...toastEls);
16177
16507
  }
16508
+ function TerminalContent() {
16509
+ const bus = useMessageBus();
16510
+ const publishedRef = useRef(false);
16511
+ useEffect(() => {
16512
+ if (!publishedRef.current) {
16513
+ publishedRef.current = true;
16514
+ bus.publish("terminal-output", { text: "Terminal session started", pid: 1 });
16515
+ }
16516
+ }, [bus]);
16517
+ const contentStyle = {
16518
+ padding: "16px",
16519
+ fontSize: "12px",
16520
+ color: "#00ff41",
16521
+ height: "100%",
16522
+ overflow: "auto",
16523
+ backgroundColor: "#1a1a2e",
16524
+ fontFamily: "monospace"
16525
+ };
16526
+ return createElement(
16527
+ "div",
16528
+ { style: contentStyle },
16529
+ createElement("div", null, "$ whoami"),
16530
+ createElement("div", null, "operator"),
16531
+ createElement("div", null, "$ uname -a"),
16532
+ createElement("div", null, "Linux specifyjs 6.1.0 #1 SMP x86_64 GNU/Linux"),
16533
+ createElement(
16534
+ "div",
16535
+ { style: { opacity: "0.6", marginTop: "8px", fontSize: "10px" } },
16536
+ "[Published terminal-output message]"
16537
+ ),
16538
+ createElement("div", null, "$ _")
16539
+ );
16540
+ }
16541
+ function FilesContent() {
16542
+ const [messages, setMessages] = useState([]);
16543
+ const dragDrop = useDragDrop();
16544
+ useChannel("terminal-output", (msg) => {
16545
+ setMessages((prev) => [...prev, `[terminal] ${msg.payload.text}`]);
16546
+ });
16547
+ const handleDragFile = useCallback((e) => {
16548
+ e.preventDefault();
16549
+ dragDrop.startDrag({
16550
+ type: "application/file",
16551
+ data: { name: "readme.txt", size: 1024 },
16552
+ sourceAppId: "files",
16553
+ preview: "readme.txt"
16554
+ });
16555
+ }, [dragDrop]);
16556
+ const contentStyle = {
16557
+ padding: "16px",
16558
+ fontSize: "13px",
16559
+ color: "var(--color-text, #333)",
16560
+ height: "100%",
16561
+ overflow: "auto"
16562
+ };
16563
+ return createElement(
16564
+ "div",
16565
+ { style: contentStyle },
16566
+ createElement("div", { style: { fontWeight: "600", marginBottom: "12px" } }, "Home"),
16567
+ createElement(
16568
+ "div",
16569
+ { style: { display: "flex", flexDirection: "column", gap: "6px" } },
16570
+ ...["\u{1F4C1} Documents", "\u{1F4C1} Downloads", "\u{1F4C1} Music", "\u{1F4C1} Pictures", "\u{1F4C1} Videos"].map(
16571
+ (f) => createElement("span", { style: { cursor: "pointer" } }, f)
16572
+ ),
16573
+ createElement("span", {
16574
+ style: {
16575
+ cursor: "grab",
16576
+ padding: "4px 8px",
16577
+ border: "1px dashed #94a3b8",
16578
+ borderRadius: "4px",
16579
+ backgroundColor: "rgba(148, 163, 184, 0.1)"
16580
+ },
16581
+ onMouseDown: handleDragFile,
16582
+ "aria-label": "Drag readme.txt"
16583
+ }, "\u{1F4C4} readme.txt (drag me)")
16584
+ ),
16585
+ messages.length > 0 ? createElement(
16586
+ "div",
16587
+ {
16588
+ style: {
16589
+ marginTop: "12px",
16590
+ padding: "8px",
16591
+ backgroundColor: "rgba(0,0,0,0.05)",
16592
+ borderRadius: "4px",
16593
+ fontSize: "11px",
16594
+ fontFamily: "monospace"
16595
+ }
16596
+ },
16597
+ createElement("div", { style: { fontWeight: "600", marginBottom: "4px" } }, "Messages received:"),
16598
+ ...messages.map(
16599
+ (m, i) => createElement("div", { key: String(i), style: { color: "#64748b" } }, m)
16600
+ )
16601
+ ) : null
16602
+ );
16603
+ }
16178
16604
  function getMockContent(title) {
16179
16605
  const contentStyle = {
16180
16606
  padding: "16px",
@@ -16186,24 +16612,15 @@ function getMockContent(title) {
16186
16612
  switch (title) {
16187
16613
  case "Files":
16188
16614
  return createElement(
16189
- "div",
16190
- { style: contentStyle },
16191
- createElement("div", { style: { fontWeight: "600", marginBottom: "12px" } }, "Home"),
16192
- createElement(
16193
- "div",
16194
- { style: { display: "flex", flexDirection: "column", gap: "6px" } },
16195
- ...["\u{1F4C1} Documents", "\u{1F4C1} Downloads", "\u{1F4C1} Music", "\u{1F4C1} Pictures", "\u{1F4C1} Videos", "\u{1F4C4} readme.txt"].map((f) => createElement("span", { style: { cursor: "pointer" } }, f))
16196
- )
16615
+ AppContextProvider,
16616
+ { appId: "files" },
16617
+ createElement(FilesContent, null)
16197
16618
  );
16198
16619
  case "Terminal":
16199
16620
  return createElement(
16200
- "div",
16201
- { style: { ...contentStyle, backgroundColor: "#1a1a2e", color: "#00ff41", fontFamily: "monospace", fontSize: "12px" } },
16202
- createElement("div", null, "$ whoami"),
16203
- createElement("div", null, "operator"),
16204
- createElement("div", null, "$ uname -a"),
16205
- createElement("div", null, "Linux specifyjs 6.1.0 #1 SMP x86_64 GNU/Linux"),
16206
- createElement("div", null, "$ _")
16621
+ AppContextProvider,
16622
+ { appId: "terminal" },
16623
+ createElement(TerminalContent, null)
16207
16624
  );
16208
16625
  case "Browser":
16209
16626
  return createElement(
@@ -16665,14 +17082,22 @@ function UnityDesktop(props) {
16665
17082
  {
16666
17083
  onWindowOpen: onAppOpen
16667
17084
  },
16668
- createElement(UnityDesktopInner, {
16669
- apps,
16670
- user,
16671
- onAppOpen,
16672
- onLogout,
16673
- theme,
16674
- children
16675
- })
17085
+ createElement(
17086
+ MessageBusProvider,
17087
+ null,
17088
+ createElement(
17089
+ DragDropProvider,
17090
+ null,
17091
+ createElement(UnityDesktopInner, {
17092
+ apps,
17093
+ user,
17094
+ onAppOpen,
17095
+ onLogout,
17096
+ theme,
17097
+ children
17098
+ })
17099
+ )
17100
+ )
16676
17101
  );
16677
17102
  }
16678
17103
 
@@ -16750,25 +17175,29 @@ function UnityApp(props) {
16750
17175
  });
16751
17176
  return null;
16752
17177
  }
16753
- return createElement(DraggableWindow, {
16754
- id,
16755
- title,
16756
- icon,
16757
- defaultPosition: windowState.position,
16758
- defaultSize: windowState.size,
16759
- minSize,
16760
- resizable,
16761
- windowState: windowState.windowState,
16762
- focused: windowState.focused,
16763
- zIndex: windowState.zIndex,
16764
- onClose: handleClose,
16765
- onFocus: handleFocus,
16766
- onMove: handleMove,
16767
- onResize: handleResize,
16768
- onMinimize: handleMinimize,
16769
- onMaximize: handleMaximize,
16770
- children
16771
- });
17178
+ return createElement(
17179
+ AppContextProvider,
17180
+ { appId: id },
17181
+ createElement(DraggableWindow, {
17182
+ id,
17183
+ title,
17184
+ icon,
17185
+ defaultPosition: windowState.position,
17186
+ defaultSize: windowState.size,
17187
+ minSize,
17188
+ resizable,
17189
+ windowState: windowState.windowState,
17190
+ focused: windowState.focused,
17191
+ zIndex: windowState.zIndex,
17192
+ onClose: handleClose,
17193
+ onFocus: handleFocus,
17194
+ onMove: handleMove,
17195
+ onResize: handleResize,
17196
+ onMinimize: handleMinimize,
17197
+ onMaximize: handleMaximize,
17198
+ children
17199
+ })
17200
+ );
16772
17201
  }
16773
17202
 
16774
17203
  // ../components/form/button/src/Button.ts
@@ -25893,6 +26322,7 @@ export {
25893
26322
  Accordion,
25894
26323
  Alert,
25895
26324
  AnalogClock,
26325
+ AppContextProvider,
25896
26326
  Avatar,
25897
26327
  Badge,
25898
26328
  BarGraph,
@@ -25917,6 +26347,7 @@ export {
25917
26347
  DecompositionTree,
25918
26348
  DigitalClock,
25919
26349
  DiscreteCartesian2D,
26350
+ DragDropProvider,
25920
26351
  Drawer,
25921
26352
  Dropdown,
25922
26353
  EmptyState,
@@ -25942,6 +26373,7 @@ export {
25942
26373
  LollipopChart,
25943
26374
  Matrix,
25944
26375
  Menubar,
26376
+ MessageBusProvider,
25945
26377
  Modal,
25946
26378
  MultilineField,
25947
26379
  NavWrapper,
@@ -26009,9 +26441,15 @@ export {
26009
26441
  numRotationAngles,
26010
26442
  projectTo2D,
26011
26443
  transformVec,
26444
+ useAppId,
26012
26445
  useBarGraphScales,
26446
+ useChannel,
26447
+ useDragDrop,
26448
+ useDraggable,
26449
+ useDropZone,
26013
26450
  useHover,
26014
26451
  useHypercube,
26015
26452
  useLineGraphScales,
26453
+ useMessageBus,
26016
26454
  useToast
26017
26455
  };