ywana-core8 0.2.17 → 0.2.18

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.
package/dist/index.umd.js CHANGED
@@ -32421,7 +32421,7 @@ const rows = [
32421
32421
  isResizing && "window--resizing",
32422
32422
  className
32423
32423
  ].filter(Boolean).join(" ");
32424
- return /* @__PURE__ */ React.createElement(
32424
+ return /* @__PURE__ */ React.createElement(WindowInstanceProvider, { windowId: id }, /* @__PURE__ */ React.createElement(
32425
32425
  "div",
32426
32426
  {
32427
32427
  ref: windowRef,
@@ -32517,8 +32517,224 @@ const rows = [
32517
32517
  className: "window__resize-handle window__resize-handle--sw",
32518
32518
  onMouseDown: (e) => handleResizeStart(e, "sw")
32519
32519
  }
32520
+ )),
32521
+ /* @__PURE__ */ React.createElement(FloatingElementsRenderer, null)
32522
+ ));
32523
+ };
32524
+ const WindowInstanceContext = React.createContext(null);
32525
+ const WindowInstanceProvider = ({ windowId, children }) => {
32526
+ const [dialogs, setDialogs] = React.useState([]);
32527
+ const [notifications, setNotifications] = React.useState([]);
32528
+ const [tooltips, setTooltips] = React.useState([]);
32529
+ const [contextMenus, setContextMenus] = React.useState([]);
32530
+ const [overlays, setOverlays] = React.useState([]);
32531
+ const idCounterRef = React.useRef(0);
32532
+ const generateId = React.useCallback(() => {
32533
+ return `${windowId}-element-${++idCounterRef.current}`;
32534
+ }, [windowId]);
32535
+ const showDialog = React.useCallback((config) => {
32536
+ const id = generateId();
32537
+ const dialog = {
32538
+ id,
32539
+ type: "dialog",
32540
+ ...config,
32541
+ createdAt: Date.now(),
32542
+ onClose: () => hideDialog(id)
32543
+ };
32544
+ setDialogs((prev) => [...prev, dialog]);
32545
+ return id;
32546
+ }, [generateId]);
32547
+ const hideDialog = React.useCallback((id) => {
32548
+ setDialogs((prev) => prev.filter((dialog) => dialog.id !== id));
32549
+ }, []);
32550
+ const hideAllDialogs = React.useCallback(() => {
32551
+ setDialogs([]);
32552
+ }, []);
32553
+ const showNotification = React.useCallback((config) => {
32554
+ const id = generateId();
32555
+ const notification = {
32556
+ id,
32557
+ type: "notification",
32558
+ duration: 5e3,
32559
+ ...config,
32560
+ createdAt: Date.now(),
32561
+ onClose: () => hideNotification(id)
32562
+ };
32563
+ setNotifications((prev) => [...prev, notification]);
32564
+ if (notification.duration > 0) {
32565
+ setTimeout(() => hideNotification(id), notification.duration);
32566
+ }
32567
+ return id;
32568
+ }, [generateId]);
32569
+ const hideNotification = React.useCallback((id) => {
32570
+ setNotifications((prev) => prev.filter((notification) => notification.id !== id));
32571
+ }, []);
32572
+ const hideAllNotifications = React.useCallback(() => {
32573
+ setNotifications([]);
32574
+ }, []);
32575
+ const showTooltip = React.useCallback((config) => {
32576
+ const id = generateId();
32577
+ const tooltip = { id, type: "tooltip", ...config, createdAt: Date.now() };
32578
+ setTooltips((prev) => [...prev, tooltip]);
32579
+ return id;
32580
+ }, [generateId]);
32581
+ const hideTooltip = React.useCallback((id) => {
32582
+ setTooltips((prev) => prev.filter((tooltip) => tooltip.id !== id));
32583
+ }, []);
32584
+ const hideAllTooltips = React.useCallback(() => {
32585
+ setTooltips([]);
32586
+ }, []);
32587
+ const showContextMenu = React.useCallback((config) => {
32588
+ setContextMenus([]);
32589
+ const id = generateId();
32590
+ const contextMenu = {
32591
+ id,
32592
+ type: "contextMenu",
32593
+ ...config,
32594
+ createdAt: Date.now(),
32595
+ onClose: () => hideContextMenu(id)
32596
+ };
32597
+ setContextMenus([contextMenu]);
32598
+ return id;
32599
+ }, [generateId]);
32600
+ const hideContextMenu = React.useCallback((id) => {
32601
+ setContextMenus((prev) => prev.filter((menu) => menu.id !== id));
32602
+ }, []);
32603
+ const hideAllContextMenus = React.useCallback(() => {
32604
+ setContextMenus([]);
32605
+ }, []);
32606
+ const showOverlay = React.useCallback((config) => {
32607
+ const id = generateId();
32608
+ const overlay = {
32609
+ id,
32610
+ type: "overlay",
32611
+ ...config,
32612
+ createdAt: Date.now(),
32613
+ onClose: () => hideOverlay(id)
32614
+ };
32615
+ setOverlays((prev) => [...prev, overlay]);
32616
+ return id;
32617
+ }, [generateId]);
32618
+ const hideOverlay = React.useCallback((id) => {
32619
+ setOverlays((prev) => prev.filter((overlay) => overlay.id !== id));
32620
+ }, []);
32621
+ const hideAllOverlays = React.useCallback(() => {
32622
+ setOverlays([]);
32623
+ }, []);
32624
+ const clearAll = React.useCallback(() => {
32625
+ setDialogs([]);
32626
+ setNotifications([]);
32627
+ setTooltips([]);
32628
+ setContextMenus([]);
32629
+ setOverlays([]);
32630
+ }, []);
32631
+ const value = {
32632
+ windowId,
32633
+ dialogs,
32634
+ notifications,
32635
+ tooltips,
32636
+ contextMenus,
32637
+ overlays,
32638
+ showDialog,
32639
+ hideDialog,
32640
+ hideAllDialogs,
32641
+ showNotification,
32642
+ hideNotification,
32643
+ hideAllNotifications,
32644
+ showTooltip,
32645
+ hideTooltip,
32646
+ hideAllTooltips,
32647
+ showContextMenu,
32648
+ hideContextMenu,
32649
+ hideAllContextMenus,
32650
+ showOverlay,
32651
+ hideOverlay,
32652
+ hideAllOverlays,
32653
+ clearAll,
32654
+ generateId
32655
+ };
32656
+ return /* @__PURE__ */ React.createElement(WindowInstanceContext.Provider, { value }, children);
32657
+ };
32658
+ const useWindowInstance = () => {
32659
+ const context = React.useContext(WindowInstanceContext);
32660
+ if (!context) {
32661
+ throw new Error("useWindowInstance must be used within a WindowInstanceProvider");
32662
+ }
32663
+ return context;
32664
+ };
32665
+ const FloatingElementsRenderer = () => {
32666
+ const { dialogs, notifications, tooltips, contextMenus, overlays } = useWindowInstance();
32667
+ return /* @__PURE__ */ React.createElement("div", { className: "window-floating-elements" }, overlays.map((overlay) => /* @__PURE__ */ React.createElement("div", { key: overlay.id, className: "window-overlay" }, /* @__PURE__ */ React.createElement("div", { className: "window-overlay__content" }, overlay.content, overlay.showCloseButton !== false && /* @__PURE__ */ React.createElement(
32668
+ "button",
32669
+ {
32670
+ className: "window-dialog__close",
32671
+ onClick: () => overlay.onClose && overlay.onClose(),
32672
+ style: { position: "absolute", top: "8px", right: "8px" }
32673
+ },
32674
+ "×"
32675
+ )))), dialogs.map((dialog) => /* @__PURE__ */ React.createElement("div", { key: dialog.id, className: "window-dialog" }, /* @__PURE__ */ React.createElement("div", { className: "window-dialog__content" }, dialog.title && /* @__PURE__ */ React.createElement("div", { className: "window-dialog__header" }, /* @__PURE__ */ React.createElement("h3", { className: "window-dialog__title" }, dialog.title), /* @__PURE__ */ React.createElement(
32676
+ "button",
32677
+ {
32678
+ className: "window-dialog__close",
32679
+ onClick: () => dialog.onClose && dialog.onClose()
32680
+ },
32681
+ "×"
32682
+ )), /* @__PURE__ */ React.createElement("div", { className: "window-dialog__body" }, dialog.content), dialog.actions && /* @__PURE__ */ React.createElement("div", { className: "window-dialog__footer" }, dialog.actions)))), notifications.map((notification) => /* @__PURE__ */ React.createElement(
32683
+ "div",
32684
+ {
32685
+ key: notification.id,
32686
+ className: `window-notification window-notification--${notification.type || "info"}`,
32687
+ style: {
32688
+ top: `${16 + notifications.indexOf(notification) * 80}px`
32689
+ }
32690
+ },
32691
+ notification.icon && /* @__PURE__ */ React.createElement("div", { style: { fontSize: "18px", flexShrink: 0 } }, notification.icon),
32692
+ /* @__PURE__ */ React.createElement("div", { className: "window-notification__content" }, notification.title && /* @__PURE__ */ React.createElement("div", { className: "window-notification__title" }, notification.title), /* @__PURE__ */ React.createElement("div", { className: "window-notification__message" }, notification.message)),
32693
+ /* @__PURE__ */ React.createElement(
32694
+ "button",
32695
+ {
32696
+ className: "window-notification__close",
32697
+ onClick: () => notification.onClose && notification.onClose()
32698
+ },
32699
+ "×"
32700
+ )
32701
+ )), tooltips.map((tooltip) => /* @__PURE__ */ React.createElement(
32702
+ "div",
32703
+ {
32704
+ key: tooltip.id,
32705
+ className: "window-tooltip",
32706
+ style: {
32707
+ left: tooltip.x,
32708
+ top: tooltip.y,
32709
+ transform: tooltip.position === "top" ? "translateX(-50%) translateY(-100%)" : "translateX(-50%)"
32710
+ }
32711
+ },
32712
+ tooltip.text
32713
+ )), contextMenus.map((menu) => /* @__PURE__ */ React.createElement(
32714
+ "div",
32715
+ {
32716
+ key: menu.id,
32717
+ className: "window-context-menu",
32718
+ style: {
32719
+ left: menu.x,
32720
+ top: menu.y
32721
+ }
32722
+ },
32723
+ menu.items && menu.items.map((item, index) => /* @__PURE__ */ React.createElement(
32724
+ "div",
32725
+ {
32726
+ key: index,
32727
+ className: "window-context-menu__item",
32728
+ onClick: () => {
32729
+ item.onClick && item.onClick();
32730
+ menu.onClose && menu.onClose();
32731
+ }
32732
+ },
32733
+ item.icon && /* @__PURE__ */ React.createElement("span", null, item.icon),
32734
+ /* @__PURE__ */ React.createElement("span", null, item.label),
32735
+ item.shortcut && /* @__PURE__ */ React.createElement("span", { style: { marginLeft: "auto", fontSize: "11px", color: "#999" } }, item.shortcut)
32520
32736
  ))
32521
- );
32737
+ )));
32522
32738
  };
32523
32739
  const ApplicationMenu = ({ isOpen, onClose }) => {
32524
32740
  console.log("ApplicationMenu render - isOpen:", isOpen, "onClose:", onClose);