@dxos/react-ui-mosaic 0.8.4-main.21d9917 → 0.8.4-main.69d29f4

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.
Files changed (42) hide show
  1. package/dist/lib/browser/{chunk-FS5LRPMY.mjs → chunk-4VDZJ3HV.mjs} +351 -259
  2. package/dist/lib/browser/chunk-4VDZJ3HV.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +21 -80
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/{chunk-E5JUEEB7.mjs → chunk-KONKDEUD.mjs} +351 -259
  9. package/dist/lib/node-esm/chunk-KONKDEUD.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +7 -3
  11. package/dist/lib/node-esm/index.mjs.map +1 -1
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +21 -80
  14. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  15. package/dist/types/src/components/Mosaic/Mosaic.d.ts +3 -12
  16. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
  17. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts +1 -1
  18. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -1
  20. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
  21. package/dist/types/src/hooks/index.d.ts +1 -0
  22. package/dist/types/src/hooks/index.d.ts.map +1 -1
  23. package/dist/types/src/hooks/useContainerDebug.d.ts +9 -0
  24. package/dist/types/src/hooks/useContainerDebug.d.ts.map +1 -0
  25. package/dist/types/src/hooks/useVisibleItems.d.ts.map +1 -1
  26. package/dist/types/src/index.d.ts +1 -0
  27. package/dist/types/src/index.d.ts.map +1 -1
  28. package/dist/types/src/testing/Board.d.ts +18 -7
  29. package/dist/types/src/testing/Board.d.ts.map +1 -1
  30. package/dist/types/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +22 -22
  32. package/src/components/Mosaic/Mosaic.stories.tsx +5 -5
  33. package/src/components/Mosaic/Mosaic.tsx +114 -140
  34. package/src/components/Mosaic/styles.ts +5 -3
  35. package/src/components/Stack/Stack.stories.tsx +2 -1
  36. package/src/hooks/index.ts +1 -0
  37. package/src/hooks/useContainerDebug.tsx +46 -0
  38. package/src/hooks/useVisibleItems.ts +3 -0
  39. package/src/index.ts +1 -0
  40. package/src/testing/Board.tsx +32 -16
  41. package/dist/lib/browser/chunk-FS5LRPMY.mjs.map +0 -7
  42. package/dist/lib/node-esm/chunk-E5JUEEB7.mjs.map +0 -7
@@ -471,18 +471,20 @@ var styles3 = {
471
471
  placeholder: {
472
472
  root: [
473
473
  "group opacity-0",
474
- 'group-data-[mosaic-debug="true"]:bg-orange-500',
475
474
  'group-data-[mosaic-debug="true"]:opacity-100',
475
+ 'group-data-[mosaic-debug="true"]:bg-orange-500',
476
476
  "data-[mosaic-placeholder-state=active]:opacity-100",
477
477
  "data-[mosaic-placeholder-axis=vertical]:plb-1",
478
478
  "data-[mosaic-placeholder-axis=vertical]:data-[mosaic-placeholder-state=active]:plb-2.5",
479
479
  "data-[mosaic-placeholder-axis=horizontal]:pli-1",
480
480
  "data-[mosaic-placeholder-axis=horizontal]:data-[mosaic-placeholder-state=active]:pli-2.5"
481
481
  ],
482
- // TODO(burdon): Don't animate open if placeholder is the source.
483
482
  content: [
484
483
  "transition-all duration-0",
485
- "group-data-[mosaic-placeholder-state=active]:duration-200",
484
+ // TODO(burdon): Don't animate open if placeholder is the source.
485
+ // TODO(burdon): Flickers when start to drag since source is removed and then the placeholder shows up.
486
+ // - Use absolute positioning?
487
+ // 'group-data-[mosaic-placeholder-state=active]:duration-200',
486
488
  "group-data-[mosaic-placeholder-axis=vertical]:bs-0",
487
489
  "group-data-[mosaic-placeholder-axis=horizontal]:is-0",
488
490
  "group-data-[mosaic-placeholder-axis=vertical]:group-data-[mosaic-placeholder-state=active]:bs-[var(--mosaic-placeholder-height)]",
@@ -617,34 +619,11 @@ var dropField = StateField.define({
617
619
  provide: (field) => EditorView.decorations.from(field)
618
620
  });
619
621
 
620
- // src/components/Stack/Stack.tsx
621
- import { useVirtualizer } from "@tanstack/react-virtual";
622
- import React6, { Fragment, forwardRef as forwardRef5 } from "react";
623
- import { invariant } from "@dxos/invariant";
624
- import { mx as mx6 } from "@dxos/ui-theme";
625
-
626
- // src/hooks/useVisibleItems.ts
627
- import { useMemo } from "react";
628
- var useVisibleItems = ({ id, items, dragging, getId }) => {
629
- const visibleItems = useMemo(() => {
630
- if (!items || !dragging || id !== dragging.containerId) {
631
- return items ?? [];
632
- }
633
- const idx = items.findIndex((item) => getId(item) === dragging.id);
634
- if (idx === -1) {
635
- return items;
636
- }
637
- const visibleItems2 = items.slice();
638
- visibleItems2.splice(idx, 1);
639
- return visibleItems2;
640
- }, [
641
- id,
642
- items,
643
- dragging,
644
- getId
645
- ]);
646
- return visibleItems;
647
- };
622
+ // src/hooks/useContainerDebug.tsx
623
+ import React7, { forwardRef as forwardRef6, useMemo as useMemo5, useRef as useRef5 } from "react";
624
+ import { createPortal as createPortal2 } from "react-dom";
625
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
626
+ import { mx as mx7 } from "@dxos/ui-theme";
648
627
 
649
628
  // src/components/Mosaic/Mosaic.tsx
650
629
  import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
@@ -659,16 +638,15 @@ import { createContext as createContext3 } from "@radix-ui/react-context";
659
638
  import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
660
639
  import { Slot as Slot3 } from "@radix-ui/react-slot";
661
640
  import { bind } from "bind-event-listener";
662
- import React5, { forwardRef as forwardRef4, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo3, useRef as useRef4, useState as useState3 } from "react";
641
+ import React6, { forwardRef as forwardRef5, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo4, useRef as useRef4, useState as useState3 } from "react";
663
642
  import { createPortal } from "react-dom";
664
- import { log } from "@dxos/log";
665
- import { Json } from "@dxos/react-ui-syntax-highlighter";
666
- import { mx as mx5 } from "@dxos/ui-theme";
643
+ import { log as log2 } from "@dxos/log";
644
+ import { mx as mx6 } from "@dxos/ui-theme";
667
645
  import { isTruthy } from "@dxos/util";
668
646
 
669
647
  // src/components/Scrollable/Scrollable.tsx
670
648
  import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
671
- import React4, { forwardRef as forwardRef3, useEffect, useMemo as useMemo2, useRef as useRef3 } from "react";
649
+ import React4, { forwardRef as forwardRef3, useEffect, useMemo, useRef as useRef3 } from "react";
672
650
  import { mx as mx4 } from "@dxos/ui-theme";
673
651
  import "overlayscrollbars/styles/overlayscrollbars.css";
674
652
  var defaultOptions = {
@@ -680,7 +658,7 @@ var defaultOptions = {
680
658
  };
681
659
  var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", padding, options: optionsProp = defaultOptions, onScroll, viewportRef, ...props }, forwardedRef) => {
682
660
  const osRef = useRef3(null);
683
- const options = useMemo2(() => {
661
+ const options = useMemo(() => {
684
662
  const options2 = {
685
663
  ...optionsProp
686
664
  };
@@ -714,7 +692,7 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
714
692
  osRef,
715
693
  viewportRef
716
694
  ]);
717
- const events = useMemo2(() => {
695
+ const events = useMemo(() => {
718
696
  if (!onScroll) {
719
697
  return null;
720
698
  }
@@ -735,14 +713,230 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
735
713
  });
736
714
  });
737
715
 
716
+ // src/components/Stack/Stack.tsx
717
+ import { useVirtualizer } from "@tanstack/react-virtual";
718
+ import React5, { Fragment, forwardRef as forwardRef4 } from "react";
719
+ import { invariant } from "@dxos/invariant";
720
+ import { mx as mx5 } from "@dxos/ui-theme";
721
+
722
+ // src/hooks/useEventHandlerAdapter.ts
723
+ import { useMemo as useMemo2 } from "react";
724
+ import { log } from "@dxos/log";
725
+ import { arrayMove } from "@dxos/util";
726
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/hooks/useEventHandlerAdapter.ts";
727
+ var useEventHandlerAdapter = ({ items, getId, get, make, onChange, ...props }) => {
728
+ return useMemo2(() => ({
729
+ ...props,
730
+ onTake: ({ source }, cb) => {
731
+ log.info("onTake", {
732
+ source
733
+ }, {
734
+ F: __dxlog_file,
735
+ L: 58,
736
+ S: void 0,
737
+ C: (f, a) => f(...a)
738
+ });
739
+ const mutate = (items2) => {
740
+ const from = items2.findIndex((item) => getId(item) === source.id);
741
+ if (from !== -1) {
742
+ items2.splice(from, 1);
743
+ }
744
+ };
745
+ if (onChange) {
746
+ onChange(mutate);
747
+ } else {
748
+ mutate(items);
749
+ }
750
+ void cb(source.data);
751
+ },
752
+ onDrop: ({ source, target }) => {
753
+ const to = target?.type === "tile" || target?.type === "placeholder" ? target.location : -1;
754
+ log.info("onDrop", {
755
+ source,
756
+ target,
757
+ to
758
+ }, {
759
+ F: __dxlog_file,
760
+ L: 76,
761
+ S: void 0,
762
+ C: (f, a) => f(...a)
763
+ });
764
+ const mutate = (items2) => {
765
+ const from = items2.findIndex((item) => getId(item) === source.id);
766
+ if (to !== -1) {
767
+ if (from !== -1) {
768
+ arrayMove(items2, from, to);
769
+ } else {
770
+ items2.splice(to, 0, make(get(source.data)));
771
+ }
772
+ }
773
+ };
774
+ if (onChange) {
775
+ onChange(mutate);
776
+ } else {
777
+ mutate(items);
778
+ }
779
+ }
780
+ }), [
781
+ items,
782
+ onChange
783
+ ]);
784
+ };
785
+
786
+ // src/hooks/useVisibleItems.ts
787
+ import { useMemo as useMemo3 } from "react";
788
+ var useVisibleItems = ({ id, items, dragging, getId }) => {
789
+ const visibleItems = useMemo3(() => {
790
+ if (!items || !dragging || id !== dragging.containerId) {
791
+ return items ?? [];
792
+ }
793
+ const idx = items.findIndex((item) => getId(item) === dragging.id);
794
+ if (idx === -1) {
795
+ return items;
796
+ }
797
+ const visibleItems2 = items.slice();
798
+ visibleItems2.splice(idx, 1);
799
+ return visibleItems2;
800
+ }, [
801
+ id,
802
+ items,
803
+ dragging,
804
+ getId
805
+ ]);
806
+ return visibleItems;
807
+ };
808
+
809
+ // src/components/Stack/Stack.tsx
810
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
811
+ var StackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
812
+ invariant(Tile2, void 0, {
813
+ F: __dxlog_file2,
814
+ L: 44,
815
+ S: void 0,
816
+ A: [
817
+ "Tile",
818
+ ""
819
+ ]
820
+ });
821
+ const { id, dragging } = useContainerContext(StackInner.displayName);
822
+ const visibleItems = useVisibleItems({
823
+ id,
824
+ items,
825
+ dragging: dragging?.source.data,
826
+ getId
827
+ });
828
+ return /* @__PURE__ */ React5.createElement("div", {
829
+ ...props,
830
+ role,
831
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
832
+ ref: forwardedRef
833
+ }, /* @__PURE__ */ React5.createElement(Placeholder, {
834
+ axis,
835
+ location: 0.5
836
+ }), visibleItems?.map((item, index) => /* @__PURE__ */ React5.createElement(Fragment, {
837
+ key: getId(item)
838
+ }, /* @__PURE__ */ React5.createElement(Tile2, {
839
+ id: getId(item),
840
+ data: item,
841
+ location: index + 1,
842
+ draggable: draggable2,
843
+ debug
844
+ }), /* @__PURE__ */ React5.createElement(Placeholder, {
845
+ axis,
846
+ location: index + 1.5
847
+ }))));
848
+ });
849
+ StackInner.displayName = "Stack";
850
+ var Stack = StackInner;
851
+ var VirtualStackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
852
+ invariant(Tile2, void 0, {
853
+ F: __dxlog_file2,
854
+ L: 106,
855
+ S: void 0,
856
+ A: [
857
+ "Tile",
858
+ ""
859
+ ]
860
+ });
861
+ const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
862
+ const visibleItems = useVisibleItems({
863
+ id,
864
+ items,
865
+ dragging: dragging?.source.data,
866
+ getId
867
+ });
868
+ const virtualizer = useVirtualizer({
869
+ count: visibleItems.length * 2 + 1,
870
+ estimateSize,
871
+ getScrollElement,
872
+ overscan,
873
+ onChange
874
+ });
875
+ const virtualItems = virtualizer.getVirtualItems();
876
+ return /* @__PURE__ */ React5.createElement("div", {
877
+ ...props,
878
+ role,
879
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
880
+ style: {
881
+ position: "relative",
882
+ ...axis === "vertical" ? {
883
+ width: "100%",
884
+ height: virtualizer.getTotalSize()
885
+ } : {
886
+ width: virtualizer.getTotalSize(),
887
+ height: "100%"
888
+ }
889
+ },
890
+ ref: forwardedRef
891
+ }, virtualItems.map((virtualItem) => {
892
+ const data = visibleItems[Math.floor(virtualItem.index / 2)];
893
+ return /* @__PURE__ */ React5.createElement("div", {
894
+ key: virtualItem.key,
895
+ "data-index": virtualItem.index,
896
+ style: {
897
+ position: "absolute",
898
+ top: 0,
899
+ left: 0,
900
+ ...axis === "vertical" ? {
901
+ width: "100%",
902
+ transform: `translateY(${virtualItem.start}px)`
903
+ } : {
904
+ height: "100%",
905
+ transform: `translateX(${virtualItem.start}px)`
906
+ }
907
+ },
908
+ ref: virtualizer.measureElement
909
+ }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React5.createElement(Placeholder, {
910
+ axis,
911
+ location: Math.floor(virtualItem.index / 2) + 0.5
912
+ }) : /* @__PURE__ */ React5.createElement(Tile2, {
913
+ id: getId(data),
914
+ data,
915
+ location: Math.floor(virtualItem.index / 2) + 1,
916
+ debug
917
+ }));
918
+ }));
919
+ });
920
+ VirtualStackInner.displayName = "VirtualStackInner";
921
+ var VirtualStack = VirtualStackInner;
922
+ var Placeholder = (props) => {
923
+ return /* @__PURE__ */ React5.createElement(Mosaic.Placeholder, {
924
+ ...props,
925
+ classNames: styles3.placeholder.root
926
+ }, /* @__PURE__ */ React5.createElement("div", {
927
+ className: mx5("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
928
+ }));
929
+ };
930
+ Placeholder.displayName = "Placeholder";
931
+
738
932
  // src/components/Mosaic/Mosaic.tsx
739
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Mosaic.tsx";
933
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Mosaic.tsx";
740
934
  var getSourceData = (source) => {
741
935
  return source.data.type === "tile" ? source.data : null;
742
936
  };
743
937
  var [RootContextProvider, useRootContext] = createContext3("MosaicRoot");
744
938
  var ROOT_DEBUG_ATTR = "mosaic-debug";
745
- var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }, forwardedRef) => {
939
+ var Root = /* @__PURE__ */ forwardRef5(({ classNames, children, asChild, debug }, forwardedRef) => {
746
940
  const rootRef = useRef4(null);
747
941
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
748
942
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -802,17 +996,29 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
802
996
  };
803
997
  });
804
998
  };
805
- return monitorForElements({
999
+ const handleCancel = () => {
1000
+ setDragging((dragging2) => {
1001
+ requestAnimationFrame(() => {
1002
+ dragging2?.target?.handler?.onCancel?.();
1003
+ dragging2?.source?.container?.dispatchEvent(new CustomEvent("dnd:cancel", {
1004
+ bubbles: true
1005
+ }));
1006
+ });
1007
+ return void 0;
1008
+ });
1009
+ };
1010
+ let noTargetTimeout;
1011
+ return combine(monitorForElements({
806
1012
  /**
807
1013
  * Dragging started within any container.
808
1014
  */
809
1015
  onDragStart: ({ source, location }) => {
810
- log("Root.onDragStart", {
1016
+ log2("Root.onDragStart", {
811
1017
  source: source.data,
812
1018
  location: location.current.dropTargets.map((target) => target.data)
813
1019
  }, {
814
- F: __dxlog_file,
815
- L: 203,
1020
+ F: __dxlog_file3,
1021
+ L: 215,
816
1022
  S: void 0,
817
1023
  C: (f, a) => f(...a)
818
1024
  });
@@ -825,19 +1031,24 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
825
1031
  * Dragging entered a new container.
826
1032
  */
827
1033
  onDropTargetChange: ({ source, location }) => {
828
- log("Root.onDropTargetChange", {
1034
+ clearTimeout(noTargetTimeout);
1035
+ log2("Root.onDropTargetChange", {
829
1036
  source: source.data,
830
1037
  location: location.current.dropTargets.map((target) => target.data)
831
1038
  }, {
832
- F: __dxlog_file,
833
- L: 215,
1039
+ F: __dxlog_file3,
1040
+ L: 228,
834
1041
  S: void 0,
835
1042
  C: (f, a) => f(...a)
836
1043
  });
837
- handleChange({
838
- source,
839
- location
840
- });
1044
+ if (location.current.dropTargets.length === 0) {
1045
+ noTargetTimeout = setTimeout(() => setDragging(void 0), 1e3);
1046
+ } else {
1047
+ handleChange({
1048
+ source,
1049
+ location
1050
+ });
1051
+ }
841
1052
  },
842
1053
  /**
843
1054
  * Dragging within any container.
@@ -860,39 +1071,46 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
860
1071
  * Dragging ended.
861
1072
  */
862
1073
  onDrop: ({ source, location }) => {
863
- log("Root.onDrop", {
1074
+ log2.info("Root.onDrop", {
864
1075
  source: source.data,
865
1076
  location: location.current.dropTargets.map((target) => target.data)
866
1077
  }, {
867
- F: __dxlog_file,
868
- L: 239,
1078
+ F: __dxlog_file3,
1079
+ L: 257,
869
1080
  S: void 0,
870
1081
  C: (f, a) => f(...a)
871
1082
  });
872
1083
  const { data: sourceData, handler: sourceHandler } = getSourceHandler(source);
873
1084
  if (!sourceHandler) {
874
- log.warn("invalid source", {
1085
+ log2.warn("invalid source", {
875
1086
  source: sourceData,
876
1087
  handlers: Object.keys(handlers)
877
1088
  }, {
878
- F: __dxlog_file,
879
- L: 247,
1089
+ F: __dxlog_file3,
1090
+ L: 265,
880
1091
  S: void 0,
881
1092
  C: (f, a) => f(...a)
882
1093
  });
883
1094
  return;
884
1095
  }
885
1096
  try {
886
- if (location.current.dropTargets.length > 0) {
1097
+ if (location.current.dropTargets.length === 0) {
1098
+ log2.info("cancelled", void 0, {
1099
+ F: __dxlog_file3,
1100
+ L: 280,
1101
+ S: void 0,
1102
+ C: (f, a) => f(...a)
1103
+ });
1104
+ } else {
887
1105
  const { data: targetData, handler: targetHandler } = getTargetHandler(location);
888
1106
  if (!targetHandler) {
889
- log.warn("invalid target", {
1107
+ log2.warn("invalid target", {
890
1108
  source: sourceData,
891
1109
  location,
892
1110
  handlers: Object.keys(handlers)
893
1111
  }, {
894
- F: __dxlog_file,
895
- L: 260,
1112
+ F: __dxlog_file3,
1113
+ L: 285,
896
1114
  S: void 0,
897
1115
  C: (f, a) => f(...a)
898
1116
  });
@@ -905,11 +1123,11 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
905
1123
  });
906
1124
  } else {
907
1125
  if (!sourceHandler.onTake) {
908
- log.warn("invalid source", {
1126
+ log2.warn("invalid source", {
909
1127
  source: sourceData
910
1128
  }, {
911
- F: __dxlog_file,
912
- L: 276,
1129
+ F: __dxlog_file3,
1130
+ L: 301,
913
1131
  S: void 0,
914
1132
  C: (f, a) => f(...a)
915
1133
  });
@@ -931,24 +1149,16 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
931
1149
  }
932
1150
  }
933
1151
  } finally {
934
- setDragging((dragging2) => {
935
- requestAnimationFrame(() => {
936
- dragging2?.target?.handler?.onCancel?.();
937
- dragging2?.source?.container?.dispatchEvent(new CustomEvent("dnd:cancel", {
938
- bubbles: true
939
- }));
940
- });
941
- return void 0;
942
- });
1152
+ handleCancel();
943
1153
  }
944
1154
  }
945
- });
1155
+ }));
946
1156
  }, [
947
1157
  handlers,
948
1158
  getSourceHandler,
949
1159
  getTargetHandler
950
1160
  ]);
951
- return /* @__PURE__ */ React5.createElement(RootContextProvider, {
1161
+ return /* @__PURE__ */ React6.createElement(RootContextProvider, {
952
1162
  containers: handlers,
953
1163
  addContainer: (container) => setHandlers((containers) => ({
954
1164
  ...containers,
@@ -961,8 +1171,8 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
961
1171
  };
962
1172
  }),
963
1173
  dragging
964
- }, /* @__PURE__ */ React5.createElement(Root2, {
965
- className: mx5("group overflow-hidden", classNames),
1174
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1175
+ className: mx6("group overflow-hidden", classNames),
966
1176
  [`data-${ROOT_DEBUG_ATTR}`]: debug,
967
1177
  ref: composedRef
968
1178
  }, children));
@@ -972,11 +1182,11 @@ var CONTAINER_STATE_ATTR = "mosaic-container-state";
972
1182
  var CONTAINER_PLACEHOLDER_WIDTH = "--mosaic-placeholder-width";
973
1183
  var CONTAINER_PLACEHOLDER_HEIGHT = "--mosaic-placeholder-height";
974
1184
  var counter = 0;
975
- var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
1185
+ var Container = /* @__PURE__ */ forwardRef5(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
976
1186
  const rootRef = useRef4(null);
977
1187
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
978
1188
  const Root2 = asChild ? Slot3 : Primitive2.div;
979
- const eventHandler = useMemo3(() => eventHandlerProp ?? {
1189
+ const eventHandler = useMemo4(() => eventHandlerProp ?? {
980
1190
  id: `mosaic-container-${counter++}`
981
1191
  }, [
982
1192
  eventHandlerProp
@@ -1004,7 +1214,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1004
1214
  }, [
1005
1215
  eventHandler
1006
1216
  ]);
1007
- const data = useMemo3(() => ({
1217
+ const data = useMemo4(() => ({
1008
1218
  type: "container",
1009
1219
  id: eventHandler.id
1010
1220
  }), [
@@ -1023,6 +1233,8 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1023
1233
  }, 500);
1024
1234
  };
1025
1235
  return combine(...[
1236
+ // Autoscroll.
1237
+ // TODO(burdon): Autoscroll doesn't work well horizontally.
1026
1238
  autoscrollElement && [
1027
1239
  autoScrollForElements({
1028
1240
  element: autoscrollElement,
@@ -1118,7 +1330,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1118
1330
  data,
1119
1331
  autoscrollElement
1120
1332
  ]);
1121
- return /* @__PURE__ */ React5.createElement(ContainerContextProvider, {
1333
+ return /* @__PURE__ */ React6.createElement(ContainerContextProvider, {
1122
1334
  id: eventHandler.id,
1123
1335
  eventHandler,
1124
1336
  axis,
@@ -1127,8 +1339,8 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1127
1339
  scrolling,
1128
1340
  activeLocation,
1129
1341
  setActiveLocation
1130
- }, /* @__PURE__ */ React5.createElement(Root2, {
1131
- className: mx5("bs-full", className, classNames),
1342
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1343
+ className: mx6("bs-full", className, classNames),
1132
1344
  style: {
1133
1345
  [CONTAINER_PLACEHOLDER_WIDTH]: state.type === "active" && state.bounds ? `${state.bounds.width}px` : "0px",
1134
1346
  [CONTAINER_PLACEHOLDER_HEIGHT]: state.type === "active" && state.bounds ? `${state.bounds.height}px` : "0px"
@@ -1139,47 +1351,9 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1139
1351
  }, children), debug?.());
1140
1352
  });
1141
1353
  Container.displayName = "MosaicContainer";
1142
- var useContainerDebug = (debug) => {
1143
- const debugRef = useRef4(null);
1144
- return useMemo3(() => {
1145
- if (!debug) {
1146
- return [
1147
- () => null,
1148
- void 0
1149
- ];
1150
- }
1151
- return [
1152
- ({ classNames }) => /* @__PURE__ */ React5.createElement("div", {
1153
- role: "none",
1154
- className: mx5("overflow-hidden", classNames),
1155
- ref: debugRef
1156
- }),
1157
- () => debugRef.current && /* @__PURE__ */ createPortal(/* @__PURE__ */ React5.createElement(ContainerInfo, null), debugRef.current)
1158
- ];
1159
- }, [
1160
- debug,
1161
- debugRef
1162
- ]);
1163
- };
1164
- var ContainerInfo = /* @__PURE__ */ forwardRef4(({ classNames }, forwardedRef) => {
1165
- const { id, state, activeLocation, scrolling } = useContainerContext(ContainerInfo.displayName);
1166
- const counter2 = useRef4(0);
1167
- return /* @__PURE__ */ React5.createElement(Json, {
1168
- data: {
1169
- id,
1170
- activeLocation,
1171
- scrolling,
1172
- state,
1173
- count: counter2.current++
1174
- },
1175
- classNames: mx5("text-xs", classNames),
1176
- ref: forwardedRef
1177
- });
1178
- });
1179
- ContainerInfo.displayName = "ContainerInfo";
1180
1354
  var [TileContextProvider, useTileContext] = createContext3("MosaicTile");
1181
1355
  var TILE_STATE_ATTR = "mosaic-tile-state";
1182
- var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
1356
+ var Tile = /* @__PURE__ */ forwardRef5(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
1183
1357
  const rootRef = useRef4(null);
1184
1358
  const composedRef = composeRefs(rootRef, forwardedRef);
1185
1359
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -1187,7 +1361,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1187
1361
  const [state, setState] = useState3({
1188
1362
  type: "idle"
1189
1363
  });
1190
- const allowedEdges = useMemo3(() => allowedEdgesProp || (axis === "vertical" ? [
1364
+ const allowedEdges = useMemo4(() => allowedEdgesProp || (axis === "vertical" ? [
1191
1365
  "top",
1192
1366
  "bottom"
1193
1367
  ] : [
@@ -1197,7 +1371,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1197
1371
  allowedEdgesProp,
1198
1372
  axis
1199
1373
  ]);
1200
- const data = useMemo3(() => ({
1374
+ const data = useMemo4(() => ({
1201
1375
  type: "tile",
1202
1376
  id,
1203
1377
  containerId,
@@ -1311,18 +1485,18 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1311
1485
  allowedEdges,
1312
1486
  setActiveLocation
1313
1487
  ]);
1314
- return /* @__PURE__ */ React5.createElement(TileContextProvider, {
1488
+ return /* @__PURE__ */ React6.createElement(TileContextProvider, {
1315
1489
  state
1316
- }, /* @__PURE__ */ React5.createElement(Root2, {
1490
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1317
1491
  [`data-${TILE_STATE_ATTR}`]: state.type,
1318
1492
  role: "listitem",
1319
- className: mx5("relative", className, classNames),
1493
+ className: mx6("relative", className, classNames),
1320
1494
  ref: composedRef
1321
- }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React5.createElement(Root2, {
1495
+ }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(Root2, {
1322
1496
  // NOTE: Use to control appearance while dragging.
1323
1497
  [`data-${TILE_STATE_ATTR}`]: state.type,
1324
1498
  // TODO(burdon): Configure drop animation.
1325
- className: mx5("relative", className, classNames),
1499
+ className: mx6("relative", className, classNames),
1326
1500
  style: {
1327
1501
  width: `${state.rect.width}px`,
1328
1502
  height: `${state.rect.height}px`
@@ -1332,11 +1506,11 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1332
1506
  Tile.displayName = "MosaicTile";
1333
1507
  var PLACEHOLDER_AXIS_ATTR = "mosaic-placeholder-axis";
1334
1508
  var PLACEHOLDER_STATE_ATTR = "mosaic-placeholder-state";
1335
- var Placeholder = ({ classNames, children, asChild, axis = "vertical", location }) => {
1509
+ var Placeholder2 = ({ classNames, children, asChild, axis = "vertical", location }) => {
1336
1510
  const rootRef = useRef4(null);
1337
1511
  const Root2 = asChild ? Slot3 : Primitive2.div;
1338
- const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder.displayName);
1339
- const data = useMemo3(() => ({
1512
+ const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder2.displayName);
1513
+ const data = useMemo4(() => ({
1340
1514
  type: "placeholder",
1341
1515
  containerId,
1342
1516
  location
@@ -1374,18 +1548,18 @@ var Placeholder = ({ classNames, children, asChild, axis = "vertical", location
1374
1548
  scrolling,
1375
1549
  setActiveLocation
1376
1550
  ]);
1377
- return /* @__PURE__ */ React5.createElement(Root2, {
1551
+ return /* @__PURE__ */ React6.createElement(Root2, {
1378
1552
  [`data-${PLACEHOLDER_AXIS_ATTR}`]: axis,
1379
1553
  [`data-${PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? "active" : "idle",
1380
1554
  role: "none",
1381
- className: mx5("relative", classNames),
1555
+ className: mx6("relative", classNames),
1382
1556
  ref: rootRef
1383
1557
  }, children);
1384
1558
  };
1385
- Placeholder.displayName = "MosaicPlaceholder";
1559
+ Placeholder2.displayName = "MosaicPlaceholder";
1386
1560
  var DropIndicator = (props) => {
1387
1561
  const { state } = useTileContext(DropIndicator.displayName);
1388
- return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React5.createElement(NativeDropIndicator, {
1562
+ return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React6.createElement(NativeDropIndicator, {
1389
1563
  ...props,
1390
1564
  edge: state.closestEdge
1391
1565
  }) : null;
@@ -1394,9 +1568,8 @@ DropIndicator.displayName = "MosaicDropIndicator";
1394
1568
  var Mosaic = {
1395
1569
  Root,
1396
1570
  Container,
1397
- ContainerInfo,
1398
1571
  Tile,
1399
- Placeholder,
1572
+ Placeholder: Placeholder2,
1400
1573
  DropIndicator,
1401
1574
  // TODO(burdon): Move out of Mosaic namespace?
1402
1575
  Viewport: Scrollable,
@@ -1404,128 +1577,45 @@ var Mosaic = {
1404
1577
  VirtualStack
1405
1578
  };
1406
1579
 
1407
- // src/components/Stack/Stack.tsx
1408
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
1409
- var StackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
1410
- invariant(Tile2, void 0, {
1411
- F: __dxlog_file2,
1412
- L: 44,
1413
- S: void 0,
1414
- A: [
1415
- "Tile",
1416
- ""
1417
- ]
1418
- });
1419
- const { id, dragging } = useContainerContext(StackInner.displayName);
1420
- const visibleItems = useVisibleItems({
1421
- id,
1422
- items,
1423
- dragging: dragging?.source.data,
1424
- getId
1425
- });
1426
- return /* @__PURE__ */ React6.createElement("div", {
1427
- ...props,
1428
- role,
1429
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1430
- ref: forwardedRef
1431
- }, /* @__PURE__ */ React6.createElement(Placeholder2, {
1432
- axis,
1433
- location: 0.5
1434
- }), visibleItems?.map((item, index) => /* @__PURE__ */ React6.createElement(Fragment, {
1435
- key: getId(item)
1436
- }, /* @__PURE__ */ React6.createElement(Tile2, {
1437
- id: getId(item),
1438
- data: item,
1439
- location: index + 1,
1440
- draggable: draggable2,
1441
- debug
1442
- }), /* @__PURE__ */ React6.createElement(Placeholder2, {
1443
- axis,
1444
- location: index + 1.5
1445
- }))));
1446
- });
1447
- StackInner.displayName = "Stack";
1448
- var Stack = StackInner;
1449
- var VirtualStackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
1450
- invariant(Tile2, void 0, {
1451
- F: __dxlog_file2,
1452
- L: 106,
1453
- S: void 0,
1454
- A: [
1455
- "Tile",
1456
- ""
1457
- ]
1458
- });
1459
- const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
1460
- const visibleItems = useVisibleItems({
1461
- id,
1462
- items,
1463
- dragging: dragging?.source.data,
1464
- getId
1465
- });
1466
- const virtualizer = useVirtualizer({
1467
- count: visibleItems.length * 2 + 1,
1468
- estimateSize,
1469
- getScrollElement,
1470
- overscan,
1471
- onChange
1472
- });
1473
- const virtualItems = virtualizer.getVirtualItems();
1474
- return /* @__PURE__ */ React6.createElement("div", {
1475
- ...props,
1476
- role,
1477
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1478
- style: {
1479
- position: "relative",
1480
- ...axis === "vertical" ? {
1481
- width: "100%",
1482
- height: virtualizer.getTotalSize()
1483
- } : {
1484
- width: virtualizer.getTotalSize(),
1485
- height: "100%"
1486
- }
1580
+ // src/hooks/useContainerDebug.tsx
1581
+ var useContainerDebug = (debug) => {
1582
+ const debugRef = useRef5(null);
1583
+ return useMemo5(() => {
1584
+ if (!debug) {
1585
+ return [
1586
+ () => null,
1587
+ void 0
1588
+ ];
1589
+ }
1590
+ return [
1591
+ ({ classNames }) => /* @__PURE__ */ React7.createElement("div", {
1592
+ role: "none",
1593
+ className: mx7("overflow-hidden", classNames),
1594
+ ref: debugRef
1595
+ }),
1596
+ () => debugRef.current && /* @__PURE__ */ createPortal2(/* @__PURE__ */ React7.createElement(ContainerInfo, null), debugRef.current)
1597
+ ];
1598
+ }, [
1599
+ debug,
1600
+ debugRef
1601
+ ]);
1602
+ };
1603
+ var ContainerInfo = /* @__PURE__ */ forwardRef6(({ classNames }, forwardedRef) => {
1604
+ const { id, state, activeLocation, scrolling } = useContainerContext(ContainerInfo.displayName);
1605
+ const counter2 = useRef5(0);
1606
+ return /* @__PURE__ */ React7.createElement(Json, {
1607
+ data: {
1608
+ id,
1609
+ activeLocation,
1610
+ scrolling,
1611
+ state,
1612
+ count: counter2.current++
1487
1613
  },
1614
+ classNames: mx7("text-xs", classNames),
1488
1615
  ref: forwardedRef
1489
- }, virtualItems.map((virtualItem) => {
1490
- const data = visibleItems[Math.floor(virtualItem.index / 2)];
1491
- return /* @__PURE__ */ React6.createElement("div", {
1492
- key: virtualItem.key,
1493
- "data-index": virtualItem.index,
1494
- style: {
1495
- position: "absolute",
1496
- top: 0,
1497
- left: 0,
1498
- ...axis === "vertical" ? {
1499
- width: "100%",
1500
- transform: `translateY(${virtualItem.start}px)`
1501
- } : {
1502
- height: "100%",
1503
- transform: `translateX(${virtualItem.start}px)`
1504
- }
1505
- },
1506
- ref: virtualizer.measureElement
1507
- }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React6.createElement(Placeholder2, {
1508
- axis,
1509
- location: Math.floor(virtualItem.index / 2) + 0.5
1510
- }) : /* @__PURE__ */ React6.createElement(Tile2, {
1511
- id: getId(data),
1512
- data,
1513
- location: Math.floor(virtualItem.index / 2) + 1,
1514
- debug
1515
- }));
1516
- }));
1616
+ });
1517
1617
  });
1518
- VirtualStackInner.displayName = "VirtualStackInner";
1519
- var VirtualStack = VirtualStackInner;
1520
- var Placeholder2 = (props) => {
1521
- return /* @__PURE__ */ React6.createElement(Mosaic.Placeholder, {
1522
- ...props,
1523
- classNames: styles3.placeholder.root
1524
- }, /* @__PURE__ */ React6.createElement("div", {
1525
- className: mx6("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
1526
- }));
1527
- };
1528
- Placeholder2.displayName = "Placeholder";
1618
+ ContainerInfo.displayName = "ContainerInfo";
1529
1619
 
1530
1620
  export {
1531
1621
  styles,
@@ -1536,12 +1626,14 @@ export {
1536
1626
  Focus,
1537
1627
  styles3,
1538
1628
  dropHandler,
1629
+ useContainerDebug,
1630
+ useEventHandlerAdapter,
1631
+ useVisibleItems,
1539
1632
  Stack,
1540
1633
  VirtualStack,
1541
1634
  useRootContext,
1542
1635
  useContainerContext,
1543
- useContainerDebug,
1544
1636
  useTileContext,
1545
1637
  Mosaic
1546
1638
  };
1547
- //# sourceMappingURL=chunk-FS5LRPMY.mjs.map
1639
+ //# sourceMappingURL=chunk-4VDZJ3HV.mjs.map