@dxos/react-ui-mosaic 0.8.4-main.937b3ca → 0.8.4-main.9735255

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-QKMUWO5X.mjs → chunk-UMBPEG4F.mjs} +347 -236
  2. package/dist/lib/browser/chunk-UMBPEG4F.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -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 +78 -185
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/{chunk-BYUYHEAX.mjs → chunk-X6GV7SMK.mjs} +347 -236
  9. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +9 -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 +78 -185
  14. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  15. package/dist/types/src/components/Card/Card.d.ts +2 -1
  16. package/dist/types/src/components/Card/Card.d.ts.map +1 -1
  17. package/dist/types/src/components/Focus/Focus.d.ts.map +1 -1
  18. package/dist/types/src/components/Mosaic/Mosaic.d.ts +8 -1
  19. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
  20. package/dist/types/src/components/Scrollable/Scrollable.d.ts +11 -4
  21. package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +1 -1
  22. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +6 -4
  23. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +1 -1
  24. package/dist/types/src/components/Stack/Stack.d.ts +4 -6
  25. package/dist/types/src/components/Stack/Stack.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.map +1 -1
  29. package/dist/types/tsconfig.tsbuildinfo +1 -1
  30. package/package.json +22 -22
  31. package/src/components/Card/Card.tsx +25 -2
  32. package/src/components/Focus/Focus.tsx +2 -0
  33. package/src/components/Mosaic/Mosaic.tsx +32 -33
  34. package/src/components/Scrollable/Scrollable.stories.tsx +34 -8
  35. package/src/components/Scrollable/Scrollable.tsx +7 -18
  36. package/src/components/Stack/Stack.stories.tsx +8 -8
  37. package/src/components/Stack/Stack.tsx +10 -10
  38. package/src/index.ts +1 -0
  39. package/src/testing/Board.tsx +11 -11
  40. package/src/testing/Virtualizer.stories.tsx +3 -3
  41. package/dist/lib/browser/chunk-QKMUWO5X.mjs.map +0 -7
  42. package/dist/lib/node-esm/chunk-BYUYHEAX.mjs.map +0 -7
@@ -374,11 +374,15 @@ var CardLink = ({ label, href }) => {
374
374
  icon: "ph--arrow-square-out--regular"
375
375
  })));
376
376
  };
377
- var CardIcon = ({ toolbar, ...props }) => {
377
+ var CardIconBlock = ({ classNames, children, role = "none", ...props }) => {
378
378
  return /* @__PURE__ */ React2.createElement("div", {
379
- role: "none",
380
- className: "grid bs-[var(--rail-item)] is-[var(--rail-item)] place-items-center"
381
- }, /* @__PURE__ */ React2.createElement(Icon, {
379
+ ...props,
380
+ role,
381
+ className: mx2("grid bs-[var(--rail-item)] is-[var(--rail-item)] place-items-center", classNames)
382
+ }, children);
383
+ };
384
+ var CardIcon = ({ toolbar, ...props }) => {
385
+ return /* @__PURE__ */ React2.createElement(CardIconBlock, null, /* @__PURE__ */ React2.createElement(Icon, {
382
386
  ...props,
383
387
  size: toolbar ? 5 : 4
384
388
  }));
@@ -395,6 +399,7 @@ var Card = {
395
399
  Close: CardClose,
396
400
  Menu: CardMenu,
397
401
  Icon: CardIcon,
402
+ IconBlock: CardIconBlock,
398
403
  // Content
399
404
  Content: CardContent,
400
405
  Row: CardRow,
@@ -619,11 +624,11 @@ var dropField = StateField.define({
619
624
  provide: (field) => EditorView.decorations.from(field)
620
625
  });
621
626
 
622
- // src/components/Stack/Stack.tsx
623
- import { useVirtualizer } from "@tanstack/react-virtual";
624
- import React6, { Fragment, forwardRef as forwardRef5 } from "react";
625
- import { invariant } from "@dxos/invariant";
626
- import { mx as mx6 } from "@dxos/ui-theme";
627
+ // src/hooks/useContainerDebug.tsx
628
+ import React7, { forwardRef as forwardRef6, useMemo as useMemo5, useRef as useRef5 } from "react";
629
+ import { createPortal as createPortal2 } from "react-dom";
630
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
631
+ import { mx as mx7 } from "@dxos/ui-theme";
627
632
 
628
633
  // src/components/Mosaic/Mosaic.tsx
629
634
  import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
@@ -638,15 +643,15 @@ import { createContext as createContext3 } from "@radix-ui/react-context";
638
643
  import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
639
644
  import { Slot as Slot3 } from "@radix-ui/react-slot";
640
645
  import { bind } from "bind-event-listener";
641
- import React5, { forwardRef as forwardRef4, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo2, useRef as useRef4, useState as useState3 } from "react";
646
+ import React6, { forwardRef as forwardRef5, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo4, useRef as useRef4, useState as useState3 } from "react";
642
647
  import { createPortal } from "react-dom";
643
- import { log } from "@dxos/log";
644
- import { mx as mx5 } from "@dxos/ui-theme";
648
+ import { log as log2 } from "@dxos/log";
649
+ import { mx as mx6 } from "@dxos/ui-theme";
645
650
  import { isTruthy } from "@dxos/util";
646
651
 
647
652
  // src/components/Scrollable/Scrollable.tsx
648
653
  import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
649
- import React4, { forwardRef as forwardRef3, useEffect, useMemo, useRef as useRef3 } from "react";
654
+ import React4, { forwardRef as forwardRef3, useEffect, useImperativeHandle, useMemo, useRef as useRef3 } from "react";
650
655
  import { mx as mx4 } from "@dxos/ui-theme";
651
656
  import "overlayscrollbars/styles/overlayscrollbars.css";
652
657
  var defaultOptions = {
@@ -673,20 +678,13 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
673
678
  axis,
674
679
  optionsProp
675
680
  ]);
676
- useEffect(() => {
677
- const hostElement = osRef.current?.getElement();
678
- if (forwardedRef) {
679
- if (typeof forwardedRef === "function") {
680
- forwardedRef(hostElement ?? null);
681
- } else {
682
- forwardedRef.current = hostElement ?? null;
683
- }
684
- }
685
- });
681
+ useImperativeHandle(forwardedRef, () => osRef.current?.getElement(), [
682
+ osRef
683
+ ]);
686
684
  useEffect(() => {
687
685
  const instance = osRef.current?.osInstance();
688
686
  if (viewportRef) {
689
- viewportRef.current = instance?.elements().viewport ?? null;
687
+ viewportRef(instance?.elements().viewport ?? null);
690
688
  }
691
689
  }, [
692
690
  osRef,
@@ -706,21 +704,237 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
706
704
  ]);
707
705
  return /* @__PURE__ */ React4.createElement(OverlayScrollbarsComponent, {
708
706
  ...props,
709
- className: mx4(padding && axis === "vertical" ? "pli-3" : "pbe-3", classNames),
707
+ className: mx4(padding && (axis === "vertical" ? "pli-3" : "pbe-3"), classNames),
710
708
  options,
711
709
  events,
712
710
  ref: osRef
713
711
  });
714
712
  });
715
713
 
714
+ // src/components/Stack/Stack.tsx
715
+ import { useVirtualizer } from "@tanstack/react-virtual";
716
+ import React5, { Fragment, forwardRef as forwardRef4 } from "react";
717
+ import { invariant } from "@dxos/invariant";
718
+ import { mx as mx5 } from "@dxos/ui-theme";
719
+
720
+ // src/hooks/useEventHandlerAdapter.ts
721
+ import { useMemo as useMemo2 } from "react";
722
+ import { log } from "@dxos/log";
723
+ import { arrayMove } from "@dxos/util";
724
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/hooks/useEventHandlerAdapter.ts";
725
+ var useEventHandlerAdapter = ({ items, getId, get, make, onChange, ...props }) => {
726
+ return useMemo2(() => ({
727
+ ...props,
728
+ onTake: ({ source }, cb) => {
729
+ log.info("onTake", {
730
+ source
731
+ }, {
732
+ F: __dxlog_file,
733
+ L: 58,
734
+ S: void 0,
735
+ C: (f, a) => f(...a)
736
+ });
737
+ const mutate = (items2) => {
738
+ const from = items2.findIndex((item) => getId(item) === source.id);
739
+ if (from !== -1) {
740
+ items2.splice(from, 1);
741
+ }
742
+ };
743
+ if (onChange) {
744
+ onChange(mutate);
745
+ } else {
746
+ mutate(items);
747
+ }
748
+ void cb(source.data);
749
+ },
750
+ onDrop: ({ source, target }) => {
751
+ const to = target?.type === "tile" || target?.type === "placeholder" ? target.location : -1;
752
+ log.info("onDrop", {
753
+ source,
754
+ target,
755
+ to
756
+ }, {
757
+ F: __dxlog_file,
758
+ L: 76,
759
+ S: void 0,
760
+ C: (f, a) => f(...a)
761
+ });
762
+ const mutate = (items2) => {
763
+ const from = items2.findIndex((item) => getId(item) === source.id);
764
+ if (to !== -1) {
765
+ if (from !== -1) {
766
+ arrayMove(items2, from, to);
767
+ } else {
768
+ items2.splice(to, 0, make(get(source.data)));
769
+ }
770
+ }
771
+ };
772
+ if (onChange) {
773
+ onChange(mutate);
774
+ } else {
775
+ mutate(items);
776
+ }
777
+ }
778
+ }), [
779
+ items,
780
+ onChange
781
+ ]);
782
+ };
783
+
784
+ // src/hooks/useVisibleItems.ts
785
+ import { useMemo as useMemo3 } from "react";
786
+ var useVisibleItems = ({ id, items, dragging, getId }) => {
787
+ const visibleItems = useMemo3(() => {
788
+ if (!items || !dragging || id !== dragging.containerId) {
789
+ return items ?? [];
790
+ }
791
+ const idx = items.findIndex((item) => getId(item) === dragging.id);
792
+ if (idx === -1) {
793
+ return items;
794
+ }
795
+ const visibleItems2 = items.slice();
796
+ visibleItems2.splice(idx, 1);
797
+ return visibleItems2;
798
+ }, [
799
+ id,
800
+ items,
801
+ dragging,
802
+ getId
803
+ ]);
804
+ return visibleItems;
805
+ };
806
+
807
+ // src/components/Stack/Stack.tsx
808
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
809
+ var StackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
810
+ invariant(Tile2, void 0, {
811
+ F: __dxlog_file2,
812
+ L: 44,
813
+ S: void 0,
814
+ A: [
815
+ "Tile",
816
+ ""
817
+ ]
818
+ });
819
+ const { id, dragging } = useContainerContext(StackInner.displayName);
820
+ const visibleItems = useVisibleItems({
821
+ id,
822
+ items,
823
+ dragging: dragging?.source.data,
824
+ getId
825
+ });
826
+ return /* @__PURE__ */ React5.createElement("div", {
827
+ ...props,
828
+ role,
829
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
830
+ ref: forwardedRef
831
+ }, /* @__PURE__ */ React5.createElement(Placeholder, {
832
+ axis,
833
+ location: 0.5
834
+ }), visibleItems?.map((item, index) => /* @__PURE__ */ React5.createElement(Fragment, {
835
+ key: getId(item)
836
+ }, /* @__PURE__ */ React5.createElement(Tile2, {
837
+ id: getId(item),
838
+ data: item,
839
+ location: index + 1,
840
+ draggable: draggable2,
841
+ debug
842
+ }), /* @__PURE__ */ React5.createElement(Placeholder, {
843
+ axis,
844
+ location: index + 1.5
845
+ }))));
846
+ });
847
+ StackInner.displayName = "Stack";
848
+ var Stack = StackInner;
849
+ var VirtualStackInner = /* @__PURE__ */ forwardRef4(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
850
+ invariant(Tile2, void 0, {
851
+ F: __dxlog_file2,
852
+ L: 106,
853
+ S: void 0,
854
+ A: [
855
+ "Tile",
856
+ ""
857
+ ]
858
+ });
859
+ const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
860
+ const visibleItems = useVisibleItems({
861
+ id,
862
+ items,
863
+ dragging: dragging?.source.data,
864
+ getId
865
+ });
866
+ const virtualizer = useVirtualizer({
867
+ count: visibleItems.length * 2 + 1,
868
+ estimateSize,
869
+ getScrollElement,
870
+ overscan,
871
+ onChange
872
+ });
873
+ const virtualItems = virtualizer.getVirtualItems();
874
+ return /* @__PURE__ */ React5.createElement("div", {
875
+ ...props,
876
+ role,
877
+ className: mx5("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
878
+ style: {
879
+ position: "relative",
880
+ ...axis === "vertical" ? {
881
+ width: "100%",
882
+ height: virtualizer.getTotalSize()
883
+ } : {
884
+ width: virtualizer.getTotalSize(),
885
+ height: "100%"
886
+ }
887
+ },
888
+ ref: forwardedRef
889
+ }, virtualItems.map((virtualItem) => {
890
+ const data = visibleItems[Math.floor(virtualItem.index / 2)];
891
+ return /* @__PURE__ */ React5.createElement("div", {
892
+ key: virtualItem.key,
893
+ "data-index": virtualItem.index,
894
+ style: {
895
+ position: "absolute",
896
+ top: 0,
897
+ left: 0,
898
+ ...axis === "vertical" ? {
899
+ width: "100%",
900
+ transform: `translateY(${virtualItem.start}px)`
901
+ } : {
902
+ height: "100%",
903
+ transform: `translateX(${virtualItem.start}px)`
904
+ }
905
+ },
906
+ ref: virtualizer.measureElement
907
+ }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React5.createElement(Placeholder, {
908
+ axis,
909
+ location: Math.floor(virtualItem.index / 2) + 0.5
910
+ }) : /* @__PURE__ */ React5.createElement(Tile2, {
911
+ id: getId(data),
912
+ data,
913
+ location: Math.floor(virtualItem.index / 2) + 1,
914
+ debug
915
+ }));
916
+ }));
917
+ });
918
+ VirtualStackInner.displayName = "VirtualStackInner";
919
+ var VirtualStack = VirtualStackInner;
920
+ var Placeholder = (props) => {
921
+ return /* @__PURE__ */ React5.createElement(Mosaic.Placeholder, {
922
+ ...props,
923
+ classNames: styles3.placeholder.root
924
+ }, /* @__PURE__ */ React5.createElement("div", {
925
+ className: mx5("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
926
+ }));
927
+ };
928
+ Placeholder.displayName = "Placeholder";
929
+
716
930
  // src/components/Mosaic/Mosaic.tsx
717
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Mosaic.tsx";
931
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Mosaic/Mosaic.tsx";
718
932
  var getSourceData = (source) => {
719
933
  return source.data.type === "tile" ? source.data : null;
720
934
  };
721
935
  var [RootContextProvider, useRootContext] = createContext3("MosaicRoot");
722
936
  var ROOT_DEBUG_ATTR = "mosaic-debug";
723
- var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }, forwardedRef) => {
937
+ var Root = /* @__PURE__ */ forwardRef5(({ classNames, children, asChild, debug }, forwardedRef) => {
724
938
  const rootRef = useRef4(null);
725
939
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
726
940
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -797,11 +1011,11 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
797
1011
  * Dragging started within any container.
798
1012
  */
799
1013
  onDragStart: ({ source, location }) => {
800
- log("Root.onDragStart", {
1014
+ log2("Root.onDragStart", {
801
1015
  source: source.data,
802
1016
  location: location.current.dropTargets.map((target) => target.data)
803
1017
  }, {
804
- F: __dxlog_file,
1018
+ F: __dxlog_file3,
805
1019
  L: 215,
806
1020
  S: void 0,
807
1021
  C: (f, a) => f(...a)
@@ -816,11 +1030,11 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
816
1030
  */
817
1031
  onDropTargetChange: ({ source, location }) => {
818
1032
  clearTimeout(noTargetTimeout);
819
- log("Root.onDropTargetChange", {
1033
+ log2("Root.onDropTargetChange", {
820
1034
  source: source.data,
821
1035
  location: location.current.dropTargets.map((target) => target.data)
822
1036
  }, {
823
- F: __dxlog_file,
1037
+ F: __dxlog_file3,
824
1038
  L: 228,
825
1039
  S: void 0,
826
1040
  C: (f, a) => f(...a)
@@ -855,22 +1069,22 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
855
1069
  * Dragging ended.
856
1070
  */
857
1071
  onDrop: ({ source, location }) => {
858
- log.info("Root.onDrop", {
1072
+ log2.info("Root.onDrop", {
859
1073
  source: source.data,
860
1074
  location: location.current.dropTargets.map((target) => target.data)
861
1075
  }, {
862
- F: __dxlog_file,
1076
+ F: __dxlog_file3,
863
1077
  L: 257,
864
1078
  S: void 0,
865
1079
  C: (f, a) => f(...a)
866
1080
  });
867
1081
  const { data: sourceData, handler: sourceHandler } = getSourceHandler(source);
868
1082
  if (!sourceHandler) {
869
- log.warn("invalid source", {
1083
+ log2.warn("invalid source", {
870
1084
  source: sourceData,
871
1085
  handlers: Object.keys(handlers)
872
1086
  }, {
873
- F: __dxlog_file,
1087
+ F: __dxlog_file3,
874
1088
  L: 265,
875
1089
  S: void 0,
876
1090
  C: (f, a) => f(...a)
@@ -879,8 +1093,8 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
879
1093
  }
880
1094
  try {
881
1095
  if (location.current.dropTargets.length === 0) {
882
- log.info("cancelled", void 0, {
883
- F: __dxlog_file,
1096
+ log2.info("cancelled", void 0, {
1097
+ F: __dxlog_file3,
884
1098
  L: 280,
885
1099
  S: void 0,
886
1100
  C: (f, a) => f(...a)
@@ -888,12 +1102,12 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
888
1102
  } else {
889
1103
  const { data: targetData, handler: targetHandler } = getTargetHandler(location);
890
1104
  if (!targetHandler) {
891
- log.warn("invalid target", {
1105
+ log2.warn("invalid target", {
892
1106
  source: sourceData,
893
1107
  location,
894
1108
  handlers: Object.keys(handlers)
895
1109
  }, {
896
- F: __dxlog_file,
1110
+ F: __dxlog_file3,
897
1111
  L: 285,
898
1112
  S: void 0,
899
1113
  C: (f, a) => f(...a)
@@ -907,10 +1121,10 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
907
1121
  });
908
1122
  } else {
909
1123
  if (!sourceHandler.onTake) {
910
- log.warn("invalid source", {
1124
+ log2.warn("invalid source", {
911
1125
  source: sourceData
912
1126
  }, {
913
- F: __dxlog_file,
1127
+ F: __dxlog_file3,
914
1128
  L: 301,
915
1129
  S: void 0,
916
1130
  C: (f, a) => f(...a)
@@ -921,7 +1135,6 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
921
1135
  source: sourceData
922
1136
  }, async (object) => {
923
1137
  targetHandler.onDrop?.({
924
- // TODO(burdon): Change source!!!
925
1138
  source: {
926
1139
  ...sourceData,
927
1140
  data: object
@@ -942,7 +1155,7 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
942
1155
  getSourceHandler,
943
1156
  getTargetHandler
944
1157
  ]);
945
- return /* @__PURE__ */ React5.createElement(RootContextProvider, {
1158
+ return /* @__PURE__ */ React6.createElement(RootContextProvider, {
946
1159
  containers: handlers,
947
1160
  addContainer: (container) => setHandlers((containers) => ({
948
1161
  ...containers,
@@ -955,8 +1168,8 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
955
1168
  };
956
1169
  }),
957
1170
  dragging
958
- }, /* @__PURE__ */ React5.createElement(Root2, {
959
- className: mx5("group overflow-hidden", classNames),
1171
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1172
+ className: mx6("group overflow-hidden", classNames),
960
1173
  [`data-${ROOT_DEBUG_ATTR}`]: debug,
961
1174
  ref: composedRef
962
1175
  }, children));
@@ -966,11 +1179,11 @@ var CONTAINER_STATE_ATTR = "mosaic-container-state";
966
1179
  var CONTAINER_PLACEHOLDER_WIDTH = "--mosaic-placeholder-width";
967
1180
  var CONTAINER_PLACEHOLDER_HEIGHT = "--mosaic-placeholder-height";
968
1181
  var counter = 0;
969
- var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
1182
+ var Container = /* @__PURE__ */ forwardRef5(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
970
1183
  const rootRef = useRef4(null);
971
1184
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
972
1185
  const Root2 = asChild ? Slot3 : Primitive2.div;
973
- const eventHandler = useMemo2(() => eventHandlerProp ?? {
1186
+ const eventHandler = useMemo4(() => eventHandlerProp ?? {
974
1187
  id: `mosaic-container-${counter++}`
975
1188
  }, [
976
1189
  eventHandlerProp
@@ -998,7 +1211,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
998
1211
  }, [
999
1212
  eventHandler
1000
1213
  ]);
1001
- const data = useMemo2(() => ({
1214
+ const data = useMemo4(() => ({
1002
1215
  type: "container",
1003
1216
  id: eventHandler.id
1004
1217
  }), [
@@ -1017,25 +1230,17 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1017
1230
  }, 500);
1018
1231
  };
1019
1232
  return combine(...[
1020
- // Autoscroll.
1021
- // TODO(burdon): Autoscroll doesn't work well horizontally.
1022
- autoscrollElement && [
1023
- autoScrollForElements({
1024
- element: autoscrollElement,
1025
- canScroll: ({ element: _ }) => {
1026
- return true;
1027
- },
1028
- getAllowedAxis: () => axis,
1029
- getConfiguration: () => ({
1030
- maxScrollSpeed: "fast"
1031
- })
1032
- }),
1033
- bind(autoscrollElement, {
1034
- type: "scroll",
1035
- listener: handleScroll
1036
- }),
1037
- () => setScrolling(false)
1038
- ],
1233
+ /**
1234
+ * Custom event for dragging cancellation.
1235
+ */
1236
+ bind(rootRef.current, {
1237
+ type: "dnd:cancel",
1238
+ listener: () => {
1239
+ setState({
1240
+ type: "idle"
1241
+ });
1242
+ }
1243
+ }),
1039
1244
  // Target.
1040
1245
  dropTargetForElements({
1041
1246
  element: rootRef.current,
@@ -1096,17 +1301,26 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1096
1301
  });
1097
1302
  }
1098
1303
  }),
1099
- /**
1100
- * Custom event for dragging cancellation.
1101
- */
1102
- bind(rootRef.current, {
1103
- type: "dnd:cancel",
1104
- listener: () => {
1105
- setState({
1106
- type: "idle"
1107
- });
1108
- }
1109
- })
1304
+ // Autoscroll.
1305
+ // NOTE: When used with Scrollable we get a spurious warning (in dev mode).
1306
+ // "Auto scrolling has been attached to an element that appears not to be scrollable."
1307
+ autoscrollElement && [
1308
+ autoScrollForElements({
1309
+ element: autoscrollElement,
1310
+ // canScroll: ({ element: _ }) => {
1311
+ // return true;
1312
+ // },
1313
+ getAllowedAxis: () => axis,
1314
+ getConfiguration: () => ({
1315
+ maxScrollSpeed: "fast"
1316
+ })
1317
+ }),
1318
+ bind(autoscrollElement, {
1319
+ type: "scroll",
1320
+ listener: handleScroll
1321
+ }),
1322
+ () => setScrolling(false)
1323
+ ]
1110
1324
  ].filter(isTruthy).flatMap((x) => x));
1111
1325
  }, [
1112
1326
  rootRef,
@@ -1114,7 +1328,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1114
1328
  data,
1115
1329
  autoscrollElement
1116
1330
  ]);
1117
- return /* @__PURE__ */ React5.createElement(ContainerContextProvider, {
1331
+ return /* @__PURE__ */ React6.createElement(ContainerContextProvider, {
1118
1332
  id: eventHandler.id,
1119
1333
  eventHandler,
1120
1334
  axis,
@@ -1123,8 +1337,8 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1123
1337
  scrolling,
1124
1338
  activeLocation,
1125
1339
  setActiveLocation
1126
- }, /* @__PURE__ */ React5.createElement(Root2, {
1127
- className: mx5("bs-full", className, classNames),
1340
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1341
+ className: mx6("bs-full", className, classNames),
1128
1342
  style: {
1129
1343
  [CONTAINER_PLACEHOLDER_WIDTH]: state.type === "active" && state.bounds ? `${state.bounds.width}px` : "0px",
1130
1344
  [CONTAINER_PLACEHOLDER_HEIGHT]: state.type === "active" && state.bounds ? `${state.bounds.height}px` : "0px"
@@ -1137,7 +1351,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1137
1351
  Container.displayName = "MosaicContainer";
1138
1352
  var [TileContextProvider, useTileContext] = createContext3("MosaicTile");
1139
1353
  var TILE_STATE_ATTR = "mosaic-tile-state";
1140
- var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
1354
+ var Tile = /* @__PURE__ */ forwardRef5(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
1141
1355
  const rootRef = useRef4(null);
1142
1356
  const composedRef = composeRefs(rootRef, forwardedRef);
1143
1357
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -1145,7 +1359,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1145
1359
  const [state, setState] = useState3({
1146
1360
  type: "idle"
1147
1361
  });
1148
- const allowedEdges = useMemo2(() => allowedEdgesProp || (axis === "vertical" ? [
1362
+ const allowedEdges = useMemo4(() => allowedEdgesProp || (axis === "vertical" ? [
1149
1363
  "top",
1150
1364
  "bottom"
1151
1365
  ] : [
@@ -1155,7 +1369,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1155
1369
  allowedEdgesProp,
1156
1370
  axis
1157
1371
  ]);
1158
- const data = useMemo2(() => ({
1372
+ const data = useMemo4(() => ({
1159
1373
  type: "tile",
1160
1374
  id,
1161
1375
  containerId,
@@ -1269,18 +1483,18 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1269
1483
  allowedEdges,
1270
1484
  setActiveLocation
1271
1485
  ]);
1272
- return /* @__PURE__ */ React5.createElement(TileContextProvider, {
1486
+ return /* @__PURE__ */ React6.createElement(TileContextProvider, {
1273
1487
  state
1274
- }, /* @__PURE__ */ React5.createElement(Root2, {
1488
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1275
1489
  [`data-${TILE_STATE_ATTR}`]: state.type,
1276
1490
  role: "listitem",
1277
- className: mx5("relative", className, classNames),
1491
+ className: mx6("relative", className, classNames),
1278
1492
  ref: composedRef
1279
- }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React5.createElement(Root2, {
1493
+ }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(Root2, {
1280
1494
  // NOTE: Use to control appearance while dragging.
1281
1495
  [`data-${TILE_STATE_ATTR}`]: state.type,
1282
1496
  // TODO(burdon): Configure drop animation.
1283
- className: mx5("relative", className, classNames),
1497
+ className: mx6("relative", className, classNames),
1284
1498
  style: {
1285
1499
  width: `${state.rect.width}px`,
1286
1500
  height: `${state.rect.height}px`
@@ -1290,11 +1504,11 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1290
1504
  Tile.displayName = "MosaicTile";
1291
1505
  var PLACEHOLDER_AXIS_ATTR = "mosaic-placeholder-axis";
1292
1506
  var PLACEHOLDER_STATE_ATTR = "mosaic-placeholder-state";
1293
- var Placeholder = ({ classNames, children, asChild, axis = "vertical", location }) => {
1507
+ var Placeholder2 = ({ classNames, children, asChild, axis = "vertical", location }) => {
1294
1508
  const rootRef = useRef4(null);
1295
1509
  const Root2 = asChild ? Slot3 : Primitive2.div;
1296
- const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder.displayName);
1297
- const data = useMemo2(() => ({
1510
+ const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder2.displayName);
1511
+ const data = useMemo4(() => ({
1298
1512
  type: "placeholder",
1299
1513
  containerId,
1300
1514
  location
@@ -1332,18 +1546,18 @@ var Placeholder = ({ classNames, children, asChild, axis = "vertical", location
1332
1546
  scrolling,
1333
1547
  setActiveLocation
1334
1548
  ]);
1335
- return /* @__PURE__ */ React5.createElement(Root2, {
1549
+ return /* @__PURE__ */ React6.createElement(Root2, {
1336
1550
  [`data-${PLACEHOLDER_AXIS_ATTR}`]: axis,
1337
1551
  [`data-${PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? "active" : "idle",
1338
1552
  role: "none",
1339
- className: mx5("relative", classNames),
1553
+ className: mx6("relative", classNames),
1340
1554
  ref: rootRef
1341
1555
  }, children);
1342
1556
  };
1343
- Placeholder.displayName = "MosaicPlaceholder";
1557
+ Placeholder2.displayName = "MosaicPlaceholder";
1344
1558
  var DropIndicator = (props) => {
1345
1559
  const { state } = useTileContext(DropIndicator.displayName);
1346
- return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React5.createElement(NativeDropIndicator, {
1560
+ return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React6.createElement(NativeDropIndicator, {
1347
1561
  ...props,
1348
1562
  edge: state.closestEdge
1349
1563
  }) : null;
@@ -1353,7 +1567,7 @@ var Mosaic = {
1353
1567
  Root,
1354
1568
  Container,
1355
1569
  Tile,
1356
- Placeholder,
1570
+ Placeholder: Placeholder2,
1357
1571
  DropIndicator,
1358
1572
  // TODO(burdon): Move out of Mosaic namespace?
1359
1573
  Viewport: Scrollable,
@@ -1361,151 +1575,45 @@ var Mosaic = {
1361
1575
  VirtualStack
1362
1576
  };
1363
1577
 
1364
- // src/hooks/useVisibleItems.ts
1365
- import { useMemo as useMemo3 } from "react";
1366
- var useVisibleItems = ({ id, items, dragging, getId }) => {
1367
- const visibleItems = useMemo3(() => {
1368
- if (!items || !dragging || id !== dragging.containerId) {
1369
- return items ?? [];
1370
- }
1371
- const idx = items.findIndex((item) => getId(item) === dragging.id);
1372
- if (idx === -1) {
1373
- return items;
1578
+ // src/hooks/useContainerDebug.tsx
1579
+ var useContainerDebug = (debug) => {
1580
+ const debugRef = useRef5(null);
1581
+ return useMemo5(() => {
1582
+ if (!debug) {
1583
+ return [
1584
+ () => null,
1585
+ void 0
1586
+ ];
1374
1587
  }
1375
- const visibleItems2 = items.slice();
1376
- visibleItems2.splice(idx, 1);
1377
- return visibleItems2;
1588
+ return [
1589
+ ({ classNames }) => /* @__PURE__ */ React7.createElement("div", {
1590
+ role: "none",
1591
+ className: mx7("overflow-hidden", classNames),
1592
+ ref: debugRef
1593
+ }),
1594
+ () => debugRef.current && /* @__PURE__ */ createPortal2(/* @__PURE__ */ React7.createElement(ContainerInfo, null), debugRef.current)
1595
+ ];
1378
1596
  }, [
1379
- id,
1380
- items,
1381
- dragging,
1382
- getId
1597
+ debug,
1598
+ debugRef
1383
1599
  ]);
1384
- return visibleItems;
1385
1600
  };
1386
-
1387
- // src/components/Stack/Stack.tsx
1388
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
1389
- var StackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
1390
- invariant(Tile2, void 0, {
1391
- F: __dxlog_file2,
1392
- L: 44,
1393
- S: void 0,
1394
- A: [
1395
- "Tile",
1396
- ""
1397
- ]
1398
- });
1399
- const { id, dragging } = useContainerContext(StackInner.displayName);
1400
- const visibleItems = useVisibleItems({
1401
- id,
1402
- items,
1403
- dragging: dragging?.source.data,
1404
- getId
1405
- });
1406
- return /* @__PURE__ */ React6.createElement("div", {
1407
- ...props,
1408
- role,
1409
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1410
- ref: forwardedRef
1411
- }, /* @__PURE__ */ React6.createElement(Placeholder2, {
1412
- axis,
1413
- location: 0.5
1414
- }), visibleItems?.map((item, index) => /* @__PURE__ */ React6.createElement(Fragment, {
1415
- key: getId(item)
1416
- }, /* @__PURE__ */ React6.createElement(Tile2, {
1417
- id: getId(item),
1418
- data: item,
1419
- location: index + 1,
1420
- draggable: draggable2,
1421
- debug
1422
- }), /* @__PURE__ */ React6.createElement(Placeholder2, {
1423
- axis,
1424
- location: index + 1.5
1425
- }))));
1426
- });
1427
- StackInner.displayName = "Stack";
1428
- var Stack = StackInner;
1429
- var VirtualStackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
1430
- invariant(Tile2, void 0, {
1431
- F: __dxlog_file2,
1432
- L: 106,
1433
- S: void 0,
1434
- A: [
1435
- "Tile",
1436
- ""
1437
- ]
1438
- });
1439
- const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
1440
- const visibleItems = useVisibleItems({
1441
- id,
1442
- items,
1443
- dragging: dragging?.source.data,
1444
- getId
1445
- });
1446
- const virtualizer = useVirtualizer({
1447
- count: visibleItems.length * 2 + 1,
1448
- estimateSize,
1449
- getScrollElement,
1450
- overscan,
1451
- onChange
1452
- });
1453
- const virtualItems = virtualizer.getVirtualItems();
1454
- return /* @__PURE__ */ React6.createElement("div", {
1455
- ...props,
1456
- role,
1457
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1458
- style: {
1459
- position: "relative",
1460
- ...axis === "vertical" ? {
1461
- width: "100%",
1462
- height: virtualizer.getTotalSize()
1463
- } : {
1464
- width: virtualizer.getTotalSize(),
1465
- height: "100%"
1466
- }
1601
+ var ContainerInfo = /* @__PURE__ */ forwardRef6(({ classNames }, forwardedRef) => {
1602
+ const { id, state, activeLocation, scrolling } = useContainerContext(ContainerInfo.displayName);
1603
+ const counter2 = useRef5(0);
1604
+ return /* @__PURE__ */ React7.createElement(Json, {
1605
+ data: {
1606
+ id,
1607
+ activeLocation,
1608
+ scrolling,
1609
+ state,
1610
+ count: counter2.current++
1467
1611
  },
1612
+ classNames: mx7("text-xs", classNames),
1468
1613
  ref: forwardedRef
1469
- }, virtualItems.map((virtualItem) => {
1470
- const data = visibleItems[Math.floor(virtualItem.index / 2)];
1471
- return /* @__PURE__ */ React6.createElement("div", {
1472
- key: virtualItem.key,
1473
- "data-index": virtualItem.index,
1474
- style: {
1475
- position: "absolute",
1476
- top: 0,
1477
- left: 0,
1478
- ...axis === "vertical" ? {
1479
- width: "100%",
1480
- transform: `translateY(${virtualItem.start}px)`
1481
- } : {
1482
- height: "100%",
1483
- transform: `translateX(${virtualItem.start}px)`
1484
- }
1485
- },
1486
- ref: virtualizer.measureElement
1487
- }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React6.createElement(Placeholder2, {
1488
- axis,
1489
- location: Math.floor(virtualItem.index / 2) + 0.5
1490
- }) : /* @__PURE__ */ React6.createElement(Tile2, {
1491
- id: getId(data),
1492
- data,
1493
- location: Math.floor(virtualItem.index / 2) + 1,
1494
- debug
1495
- }));
1496
- }));
1614
+ });
1497
1615
  });
1498
- VirtualStackInner.displayName = "VirtualStackInner";
1499
- var VirtualStack = VirtualStackInner;
1500
- var Placeholder2 = (props) => {
1501
- return /* @__PURE__ */ React6.createElement(Mosaic.Placeholder, {
1502
- ...props,
1503
- classNames: styles3.placeholder.root
1504
- }, /* @__PURE__ */ React6.createElement("div", {
1505
- className: mx6("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
1506
- }));
1507
- };
1508
- Placeholder2.displayName = "Placeholder";
1616
+ ContainerInfo.displayName = "ContainerInfo";
1509
1617
 
1510
1618
  export {
1511
1619
  styles,
@@ -1516,6 +1624,9 @@ export {
1516
1624
  Focus,
1517
1625
  styles3,
1518
1626
  dropHandler,
1627
+ useContainerDebug,
1628
+ useEventHandlerAdapter,
1629
+ useVisibleItems,
1519
1630
  Stack,
1520
1631
  VirtualStack,
1521
1632
  useRootContext,
@@ -1523,4 +1634,4 @@ export {
1523
1634
  useTileContext,
1524
1635
  Mosaic
1525
1636
  };
1526
- //# sourceMappingURL=chunk-QKMUWO5X.mjs.map
1637
+ //# sourceMappingURL=chunk-UMBPEG4F.mjs.map