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

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
@@ -376,11 +376,15 @@ var CardLink = ({ label, href }) => {
376
376
  icon: "ph--arrow-square-out--regular"
377
377
  })));
378
378
  };
379
- var CardIcon = ({ toolbar, ...props }) => {
379
+ var CardIconBlock = ({ classNames, children, role = "none", ...props }) => {
380
380
  return /* @__PURE__ */ React2.createElement("div", {
381
- role: "none",
382
- className: "grid bs-[var(--rail-item)] is-[var(--rail-item)] place-items-center"
383
- }, /* @__PURE__ */ React2.createElement(Icon, {
381
+ ...props,
382
+ role,
383
+ className: mx2("grid bs-[var(--rail-item)] is-[var(--rail-item)] place-items-center", classNames)
384
+ }, children);
385
+ };
386
+ var CardIcon = ({ toolbar, ...props }) => {
387
+ return /* @__PURE__ */ React2.createElement(CardIconBlock, null, /* @__PURE__ */ React2.createElement(Icon, {
384
388
  ...props,
385
389
  size: toolbar ? 5 : 4
386
390
  }));
@@ -397,6 +401,7 @@ var Card = {
397
401
  Close: CardClose,
398
402
  Menu: CardMenu,
399
403
  Icon: CardIcon,
404
+ IconBlock: CardIconBlock,
400
405
  // Content
401
406
  Content: CardContent,
402
407
  Row: CardRow,
@@ -621,11 +626,11 @@ var dropField = StateField.define({
621
626
  provide: (field) => EditorView.decorations.from(field)
622
627
  });
623
628
 
624
- // src/components/Stack/Stack.tsx
625
- import { useVirtualizer } from "@tanstack/react-virtual";
626
- import React6, { Fragment, forwardRef as forwardRef5 } from "react";
627
- import { invariant } from "@dxos/invariant";
628
- import { mx as mx6 } from "@dxos/ui-theme";
629
+ // src/hooks/useContainerDebug.tsx
630
+ import React7, { forwardRef as forwardRef6, useMemo as useMemo5, useRef as useRef5 } from "react";
631
+ import { createPortal as createPortal2 } from "react-dom";
632
+ import { Json } from "@dxos/react-ui-syntax-highlighter";
633
+ import { mx as mx7 } from "@dxos/ui-theme";
629
634
 
630
635
  // src/components/Mosaic/Mosaic.tsx
631
636
  import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
@@ -640,15 +645,15 @@ import { createContext as createContext3 } from "@radix-ui/react-context";
640
645
  import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
641
646
  import { Slot as Slot3 } from "@radix-ui/react-slot";
642
647
  import { bind } from "bind-event-listener";
643
- import React5, { forwardRef as forwardRef4, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo2, useRef as useRef4, useState as useState3 } from "react";
648
+ import React6, { forwardRef as forwardRef5, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo4, useRef as useRef4, useState as useState3 } from "react";
644
649
  import { createPortal } from "react-dom";
645
- import { log } from "@dxos/log";
646
- import { mx as mx5 } from "@dxos/ui-theme";
650
+ import { log as log2 } from "@dxos/log";
651
+ import { mx as mx6 } from "@dxos/ui-theme";
647
652
  import { isTruthy } from "@dxos/util";
648
653
 
649
654
  // src/components/Scrollable/Scrollable.tsx
650
655
  import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
651
- import React4, { forwardRef as forwardRef3, useEffect, useMemo, useRef as useRef3 } from "react";
656
+ import React4, { forwardRef as forwardRef3, useEffect, useImperativeHandle, useMemo, useRef as useRef3 } from "react";
652
657
  import { mx as mx4 } from "@dxos/ui-theme";
653
658
  import "overlayscrollbars/styles/overlayscrollbars.css";
654
659
  var defaultOptions = {
@@ -675,20 +680,13 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
675
680
  axis,
676
681
  optionsProp
677
682
  ]);
678
- useEffect(() => {
679
- const hostElement = osRef.current?.getElement();
680
- if (forwardedRef) {
681
- if (typeof forwardedRef === "function") {
682
- forwardedRef(hostElement ?? null);
683
- } else {
684
- forwardedRef.current = hostElement ?? null;
685
- }
686
- }
687
- });
683
+ useImperativeHandle(forwardedRef, () => osRef.current?.getElement(), [
684
+ osRef
685
+ ]);
688
686
  useEffect(() => {
689
687
  const instance = osRef.current?.osInstance();
690
688
  if (viewportRef) {
691
- viewportRef.current = instance?.elements().viewport ?? null;
689
+ viewportRef(instance?.elements().viewport ?? null);
692
690
  }
693
691
  }, [
694
692
  osRef,
@@ -708,21 +706,237 @@ var Scrollable = /* @__PURE__ */ forwardRef3(({ classNames, axis = "vertical", p
708
706
  ]);
709
707
  return /* @__PURE__ */ React4.createElement(OverlayScrollbarsComponent, {
710
708
  ...props,
711
- className: mx4(padding && axis === "vertical" ? "pli-3" : "pbe-3", classNames),
709
+ className: mx4(padding && (axis === "vertical" ? "pli-3" : "pbe-3"), classNames),
712
710
  options,
713
711
  events,
714
712
  ref: osRef
715
713
  });
716
714
  });
717
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
+
718
932
  // src/components/Mosaic/Mosaic.tsx
719
- 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";
720
934
  var getSourceData = (source) => {
721
935
  return source.data.type === "tile" ? source.data : null;
722
936
  };
723
937
  var [RootContextProvider, useRootContext] = createContext3("MosaicRoot");
724
938
  var ROOT_DEBUG_ATTR = "mosaic-debug";
725
- var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }, forwardedRef) => {
939
+ var Root = /* @__PURE__ */ forwardRef5(({ classNames, children, asChild, debug }, forwardedRef) => {
726
940
  const rootRef = useRef4(null);
727
941
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
728
942
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -799,11 +1013,11 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
799
1013
  * Dragging started within any container.
800
1014
  */
801
1015
  onDragStart: ({ source, location }) => {
802
- log("Root.onDragStart", {
1016
+ log2("Root.onDragStart", {
803
1017
  source: source.data,
804
1018
  location: location.current.dropTargets.map((target) => target.data)
805
1019
  }, {
806
- F: __dxlog_file,
1020
+ F: __dxlog_file3,
807
1021
  L: 215,
808
1022
  S: void 0,
809
1023
  C: (f, a) => f(...a)
@@ -818,11 +1032,11 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
818
1032
  */
819
1033
  onDropTargetChange: ({ source, location }) => {
820
1034
  clearTimeout(noTargetTimeout);
821
- log("Root.onDropTargetChange", {
1035
+ log2("Root.onDropTargetChange", {
822
1036
  source: source.data,
823
1037
  location: location.current.dropTargets.map((target) => target.data)
824
1038
  }, {
825
- F: __dxlog_file,
1039
+ F: __dxlog_file3,
826
1040
  L: 228,
827
1041
  S: void 0,
828
1042
  C: (f, a) => f(...a)
@@ -857,22 +1071,22 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
857
1071
  * Dragging ended.
858
1072
  */
859
1073
  onDrop: ({ source, location }) => {
860
- log.info("Root.onDrop", {
1074
+ log2.info("Root.onDrop", {
861
1075
  source: source.data,
862
1076
  location: location.current.dropTargets.map((target) => target.data)
863
1077
  }, {
864
- F: __dxlog_file,
1078
+ F: __dxlog_file3,
865
1079
  L: 257,
866
1080
  S: void 0,
867
1081
  C: (f, a) => f(...a)
868
1082
  });
869
1083
  const { data: sourceData, handler: sourceHandler } = getSourceHandler(source);
870
1084
  if (!sourceHandler) {
871
- log.warn("invalid source", {
1085
+ log2.warn("invalid source", {
872
1086
  source: sourceData,
873
1087
  handlers: Object.keys(handlers)
874
1088
  }, {
875
- F: __dxlog_file,
1089
+ F: __dxlog_file3,
876
1090
  L: 265,
877
1091
  S: void 0,
878
1092
  C: (f, a) => f(...a)
@@ -881,8 +1095,8 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
881
1095
  }
882
1096
  try {
883
1097
  if (location.current.dropTargets.length === 0) {
884
- log.info("cancelled", void 0, {
885
- F: __dxlog_file,
1098
+ log2.info("cancelled", void 0, {
1099
+ F: __dxlog_file3,
886
1100
  L: 280,
887
1101
  S: void 0,
888
1102
  C: (f, a) => f(...a)
@@ -890,12 +1104,12 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
890
1104
  } else {
891
1105
  const { data: targetData, handler: targetHandler } = getTargetHandler(location);
892
1106
  if (!targetHandler) {
893
- log.warn("invalid target", {
1107
+ log2.warn("invalid target", {
894
1108
  source: sourceData,
895
1109
  location,
896
1110
  handlers: Object.keys(handlers)
897
1111
  }, {
898
- F: __dxlog_file,
1112
+ F: __dxlog_file3,
899
1113
  L: 285,
900
1114
  S: void 0,
901
1115
  C: (f, a) => f(...a)
@@ -909,10 +1123,10 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
909
1123
  });
910
1124
  } else {
911
1125
  if (!sourceHandler.onTake) {
912
- log.warn("invalid source", {
1126
+ log2.warn("invalid source", {
913
1127
  source: sourceData
914
1128
  }, {
915
- F: __dxlog_file,
1129
+ F: __dxlog_file3,
916
1130
  L: 301,
917
1131
  S: void 0,
918
1132
  C: (f, a) => f(...a)
@@ -923,7 +1137,6 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
923
1137
  source: sourceData
924
1138
  }, async (object) => {
925
1139
  targetHandler.onDrop?.({
926
- // TODO(burdon): Change source!!!
927
1140
  source: {
928
1141
  ...sourceData,
929
1142
  data: object
@@ -944,7 +1157,7 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
944
1157
  getSourceHandler,
945
1158
  getTargetHandler
946
1159
  ]);
947
- return /* @__PURE__ */ React5.createElement(RootContextProvider, {
1160
+ return /* @__PURE__ */ React6.createElement(RootContextProvider, {
948
1161
  containers: handlers,
949
1162
  addContainer: (container) => setHandlers((containers) => ({
950
1163
  ...containers,
@@ -957,8 +1170,8 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
957
1170
  };
958
1171
  }),
959
1172
  dragging
960
- }, /* @__PURE__ */ React5.createElement(Root2, {
961
- className: mx5("group overflow-hidden", classNames),
1173
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1174
+ className: mx6("group overflow-hidden", classNames),
962
1175
  [`data-${ROOT_DEBUG_ATTR}`]: debug,
963
1176
  ref: composedRef
964
1177
  }, children));
@@ -968,11 +1181,11 @@ var CONTAINER_STATE_ATTR = "mosaic-container-state";
968
1181
  var CONTAINER_PLACEHOLDER_WIDTH = "--mosaic-placeholder-width";
969
1182
  var CONTAINER_PLACEHOLDER_HEIGHT = "--mosaic-placeholder-height";
970
1183
  var counter = 0;
971
- var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
1184
+ var Container = /* @__PURE__ */ forwardRef5(({ className, classNames, children, eventHandler: eventHandlerProp, axis = "vertical", asChild, autoScroll: autoscrollElement, withFocus, debug, ...props }, forwardedRef) => {
972
1185
  const rootRef = useRef4(null);
973
1186
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
974
1187
  const Root2 = asChild ? Slot3 : Primitive2.div;
975
- const eventHandler = useMemo2(() => eventHandlerProp ?? {
1188
+ const eventHandler = useMemo4(() => eventHandlerProp ?? {
976
1189
  id: `mosaic-container-${counter++}`
977
1190
  }, [
978
1191
  eventHandlerProp
@@ -1000,7 +1213,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1000
1213
  }, [
1001
1214
  eventHandler
1002
1215
  ]);
1003
- const data = useMemo2(() => ({
1216
+ const data = useMemo4(() => ({
1004
1217
  type: "container",
1005
1218
  id: eventHandler.id
1006
1219
  }), [
@@ -1019,25 +1232,17 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1019
1232
  }, 500);
1020
1233
  };
1021
1234
  return combine(...[
1022
- // Autoscroll.
1023
- // TODO(burdon): Autoscroll doesn't work well horizontally.
1024
- autoscrollElement && [
1025
- autoScrollForElements({
1026
- element: autoscrollElement,
1027
- canScroll: ({ element: _ }) => {
1028
- return true;
1029
- },
1030
- getAllowedAxis: () => axis,
1031
- getConfiguration: () => ({
1032
- maxScrollSpeed: "fast"
1033
- })
1034
- }),
1035
- bind(autoscrollElement, {
1036
- type: "scroll",
1037
- listener: handleScroll
1038
- }),
1039
- () => setScrolling(false)
1040
- ],
1235
+ /**
1236
+ * Custom event for dragging cancellation.
1237
+ */
1238
+ bind(rootRef.current, {
1239
+ type: "dnd:cancel",
1240
+ listener: () => {
1241
+ setState({
1242
+ type: "idle"
1243
+ });
1244
+ }
1245
+ }),
1041
1246
  // Target.
1042
1247
  dropTargetForElements({
1043
1248
  element: rootRef.current,
@@ -1098,17 +1303,26 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1098
1303
  });
1099
1304
  }
1100
1305
  }),
1101
- /**
1102
- * Custom event for dragging cancellation.
1103
- */
1104
- bind(rootRef.current, {
1105
- type: "dnd:cancel",
1106
- listener: () => {
1107
- setState({
1108
- type: "idle"
1109
- });
1110
- }
1111
- })
1306
+ // Autoscroll.
1307
+ // NOTE: When used with Scrollable we get a spurious warning (in dev mode).
1308
+ // "Auto scrolling has been attached to an element that appears not to be scrollable."
1309
+ autoscrollElement && [
1310
+ autoScrollForElements({
1311
+ element: autoscrollElement,
1312
+ // canScroll: ({ element: _ }) => {
1313
+ // return true;
1314
+ // },
1315
+ getAllowedAxis: () => axis,
1316
+ getConfiguration: () => ({
1317
+ maxScrollSpeed: "fast"
1318
+ })
1319
+ }),
1320
+ bind(autoscrollElement, {
1321
+ type: "scroll",
1322
+ listener: handleScroll
1323
+ }),
1324
+ () => setScrolling(false)
1325
+ ]
1112
1326
  ].filter(isTruthy).flatMap((x) => x));
1113
1327
  }, [
1114
1328
  rootRef,
@@ -1116,7 +1330,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1116
1330
  data,
1117
1331
  autoscrollElement
1118
1332
  ]);
1119
- return /* @__PURE__ */ React5.createElement(ContainerContextProvider, {
1333
+ return /* @__PURE__ */ React6.createElement(ContainerContextProvider, {
1120
1334
  id: eventHandler.id,
1121
1335
  eventHandler,
1122
1336
  axis,
@@ -1125,8 +1339,8 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1125
1339
  scrolling,
1126
1340
  activeLocation,
1127
1341
  setActiveLocation
1128
- }, /* @__PURE__ */ React5.createElement(Root2, {
1129
- className: mx5("bs-full", className, classNames),
1342
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1343
+ className: mx6("bs-full", className, classNames),
1130
1344
  style: {
1131
1345
  [CONTAINER_PLACEHOLDER_WIDTH]: state.type === "active" && state.bounds ? `${state.bounds.width}px` : "0px",
1132
1346
  [CONTAINER_PLACEHOLDER_HEIGHT]: state.type === "active" && state.bounds ? `${state.bounds.height}px` : "0px"
@@ -1139,7 +1353,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1139
1353
  Container.displayName = "MosaicContainer";
1140
1354
  var [TileContextProvider, useTileContext] = createContext3("MosaicTile");
1141
1355
  var TILE_STATE_ATTR = "mosaic-tile-state";
1142
- 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) => {
1143
1357
  const rootRef = useRef4(null);
1144
1358
  const composedRef = composeRefs(rootRef, forwardedRef);
1145
1359
  const Root2 = asChild ? Slot3 : Primitive2.div;
@@ -1147,7 +1361,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1147
1361
  const [state, setState] = useState3({
1148
1362
  type: "idle"
1149
1363
  });
1150
- const allowedEdges = useMemo2(() => allowedEdgesProp || (axis === "vertical" ? [
1364
+ const allowedEdges = useMemo4(() => allowedEdgesProp || (axis === "vertical" ? [
1151
1365
  "top",
1152
1366
  "bottom"
1153
1367
  ] : [
@@ -1157,7 +1371,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1157
1371
  allowedEdgesProp,
1158
1372
  axis
1159
1373
  ]);
1160
- const data = useMemo2(() => ({
1374
+ const data = useMemo4(() => ({
1161
1375
  type: "tile",
1162
1376
  id,
1163
1377
  containerId,
@@ -1271,18 +1485,18 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1271
1485
  allowedEdges,
1272
1486
  setActiveLocation
1273
1487
  ]);
1274
- return /* @__PURE__ */ React5.createElement(TileContextProvider, {
1488
+ return /* @__PURE__ */ React6.createElement(TileContextProvider, {
1275
1489
  state
1276
- }, /* @__PURE__ */ React5.createElement(Root2, {
1490
+ }, /* @__PURE__ */ React6.createElement(Root2, {
1277
1491
  [`data-${TILE_STATE_ATTR}`]: state.type,
1278
1492
  role: "listitem",
1279
- className: mx5("relative", className, classNames),
1493
+ className: mx6("relative", className, classNames),
1280
1494
  ref: composedRef
1281
- }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React5.createElement(Root2, {
1495
+ }, children), state.type === "preview" && /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(Root2, {
1282
1496
  // NOTE: Use to control appearance while dragging.
1283
1497
  [`data-${TILE_STATE_ATTR}`]: state.type,
1284
1498
  // TODO(burdon): Configure drop animation.
1285
- className: mx5("relative", className, classNames),
1499
+ className: mx6("relative", className, classNames),
1286
1500
  style: {
1287
1501
  width: `${state.rect.width}px`,
1288
1502
  height: `${state.rect.height}px`
@@ -1292,11 +1506,11 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1292
1506
  Tile.displayName = "MosaicTile";
1293
1507
  var PLACEHOLDER_AXIS_ATTR = "mosaic-placeholder-axis";
1294
1508
  var PLACEHOLDER_STATE_ATTR = "mosaic-placeholder-state";
1295
- var Placeholder = ({ classNames, children, asChild, axis = "vertical", location }) => {
1509
+ var Placeholder2 = ({ classNames, children, asChild, axis = "vertical", location }) => {
1296
1510
  const rootRef = useRef4(null);
1297
1511
  const Root2 = asChild ? Slot3 : Primitive2.div;
1298
- const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder.displayName);
1299
- const data = useMemo2(() => ({
1512
+ const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder2.displayName);
1513
+ const data = useMemo4(() => ({
1300
1514
  type: "placeholder",
1301
1515
  containerId,
1302
1516
  location
@@ -1334,18 +1548,18 @@ var Placeholder = ({ classNames, children, asChild, axis = "vertical", location
1334
1548
  scrolling,
1335
1549
  setActiveLocation
1336
1550
  ]);
1337
- return /* @__PURE__ */ React5.createElement(Root2, {
1551
+ return /* @__PURE__ */ React6.createElement(Root2, {
1338
1552
  [`data-${PLACEHOLDER_AXIS_ATTR}`]: axis,
1339
1553
  [`data-${PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? "active" : "idle",
1340
1554
  role: "none",
1341
- className: mx5("relative", classNames),
1555
+ className: mx6("relative", classNames),
1342
1556
  ref: rootRef
1343
1557
  }, children);
1344
1558
  };
1345
- Placeholder.displayName = "MosaicPlaceholder";
1559
+ Placeholder2.displayName = "MosaicPlaceholder";
1346
1560
  var DropIndicator = (props) => {
1347
1561
  const { state } = useTileContext(DropIndicator.displayName);
1348
- return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React5.createElement(NativeDropIndicator, {
1562
+ return state.type === "target" && state.closestEdge ? /* @__PURE__ */ React6.createElement(NativeDropIndicator, {
1349
1563
  ...props,
1350
1564
  edge: state.closestEdge
1351
1565
  }) : null;
@@ -1355,7 +1569,7 @@ var Mosaic = {
1355
1569
  Root,
1356
1570
  Container,
1357
1571
  Tile,
1358
- Placeholder,
1572
+ Placeholder: Placeholder2,
1359
1573
  DropIndicator,
1360
1574
  // TODO(burdon): Move out of Mosaic namespace?
1361
1575
  Viewport: Scrollable,
@@ -1363,151 +1577,45 @@ var Mosaic = {
1363
1577
  VirtualStack
1364
1578
  };
1365
1579
 
1366
- // src/hooks/useVisibleItems.ts
1367
- import { useMemo as useMemo3 } from "react";
1368
- var useVisibleItems = ({ id, items, dragging, getId }) => {
1369
- const visibleItems = useMemo3(() => {
1370
- if (!items || !dragging || id !== dragging.containerId) {
1371
- return items ?? [];
1372
- }
1373
- const idx = items.findIndex((item) => getId(item) === dragging.id);
1374
- if (idx === -1) {
1375
- return items;
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
+ ];
1376
1589
  }
1377
- const visibleItems2 = items.slice();
1378
- visibleItems2.splice(idx, 1);
1379
- return visibleItems2;
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
+ ];
1380
1598
  }, [
1381
- id,
1382
- items,
1383
- dragging,
1384
- getId
1599
+ debug,
1600
+ debugRef
1385
1601
  ]);
1386
- return visibleItems;
1387
1602
  };
1388
-
1389
- // src/components/Stack/Stack.tsx
1390
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
1391
- var StackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
1392
- invariant(Tile2, void 0, {
1393
- F: __dxlog_file2,
1394
- L: 44,
1395
- S: void 0,
1396
- A: [
1397
- "Tile",
1398
- ""
1399
- ]
1400
- });
1401
- const { id, dragging } = useContainerContext(StackInner.displayName);
1402
- const visibleItems = useVisibleItems({
1403
- id,
1404
- items,
1405
- dragging: dragging?.source.data,
1406
- getId
1407
- });
1408
- return /* @__PURE__ */ React6.createElement("div", {
1409
- ...props,
1410
- role,
1411
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1412
- ref: forwardedRef
1413
- }, /* @__PURE__ */ React6.createElement(Placeholder2, {
1414
- axis,
1415
- location: 0.5
1416
- }), visibleItems?.map((item, index) => /* @__PURE__ */ React6.createElement(Fragment, {
1417
- key: getId(item)
1418
- }, /* @__PURE__ */ React6.createElement(Tile2, {
1419
- id: getId(item),
1420
- data: item,
1421
- location: index + 1,
1422
- draggable: draggable2,
1423
- debug
1424
- }), /* @__PURE__ */ React6.createElement(Placeholder2, {
1425
- axis,
1426
- location: index + 1.5
1427
- }))));
1428
- });
1429
- StackInner.displayName = "Stack";
1430
- var Stack = StackInner;
1431
- var VirtualStackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", items, getId, Tile: Tile2, estimateSize, getScrollElement, overscan = 8, onChange, debug, ...props }, forwardedRef) => {
1432
- invariant(Tile2, void 0, {
1433
- F: __dxlog_file2,
1434
- L: 106,
1435
- S: void 0,
1436
- A: [
1437
- "Tile",
1438
- ""
1439
- ]
1440
- });
1441
- const { id, dragging } = useContainerContext(VirtualStackInner.displayName);
1442
- const visibleItems = useVisibleItems({
1443
- id,
1444
- items,
1445
- dragging: dragging?.source.data,
1446
- getId
1447
- });
1448
- const virtualizer = useVirtualizer({
1449
- count: visibleItems.length * 2 + 1,
1450
- estimateSize,
1451
- getScrollElement,
1452
- overscan,
1453
- onChange
1454
- });
1455
- const virtualItems = virtualizer.getVirtualItems();
1456
- return /* @__PURE__ */ React6.createElement("div", {
1457
- ...props,
1458
- role,
1459
- className: mx6("flex", axis === "horizontal" && "bs-full [&>*]:shrink-0", axis === "vertical" && "flex-col", classNames, className),
1460
- style: {
1461
- position: "relative",
1462
- ...axis === "vertical" ? {
1463
- width: "100%",
1464
- height: virtualizer.getTotalSize()
1465
- } : {
1466
- width: virtualizer.getTotalSize(),
1467
- height: "100%"
1468
- }
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++
1469
1613
  },
1614
+ classNames: mx7("text-xs", classNames),
1470
1615
  ref: forwardedRef
1471
- }, virtualItems.map((virtualItem) => {
1472
- const data = visibleItems[Math.floor(virtualItem.index / 2)];
1473
- return /* @__PURE__ */ React6.createElement("div", {
1474
- key: virtualItem.key,
1475
- "data-index": virtualItem.index,
1476
- style: {
1477
- position: "absolute",
1478
- top: 0,
1479
- left: 0,
1480
- ...axis === "vertical" ? {
1481
- width: "100%",
1482
- transform: `translateY(${virtualItem.start}px)`
1483
- } : {
1484
- height: "100%",
1485
- transform: `translateX(${virtualItem.start}px)`
1486
- }
1487
- },
1488
- ref: virtualizer.measureElement
1489
- }, virtualItem.index % 2 === 0 ? /* @__PURE__ */ React6.createElement(Placeholder2, {
1490
- axis,
1491
- location: Math.floor(virtualItem.index / 2) + 0.5
1492
- }) : /* @__PURE__ */ React6.createElement(Tile2, {
1493
- id: getId(data),
1494
- data,
1495
- location: Math.floor(virtualItem.index / 2) + 1,
1496
- debug
1497
- }));
1498
- }));
1616
+ });
1499
1617
  });
1500
- VirtualStackInner.displayName = "VirtualStackInner";
1501
- var VirtualStack = VirtualStackInner;
1502
- var Placeholder2 = (props) => {
1503
- return /* @__PURE__ */ React6.createElement(Mosaic.Placeholder, {
1504
- ...props,
1505
- classNames: styles3.placeholder.root
1506
- }, /* @__PURE__ */ React6.createElement("div", {
1507
- className: mx6("flex bs-full bg-baseSurface border border-dashed border-separator rounded-sm", styles3.placeholder.content)
1508
- }));
1509
- };
1510
- Placeholder2.displayName = "Placeholder";
1618
+ ContainerInfo.displayName = "ContainerInfo";
1511
1619
 
1512
1620
  export {
1513
1621
  styles,
@@ -1518,6 +1626,9 @@ export {
1518
1626
  Focus,
1519
1627
  styles3,
1520
1628
  dropHandler,
1629
+ useContainerDebug,
1630
+ useEventHandlerAdapter,
1631
+ useVisibleItems,
1521
1632
  Stack,
1522
1633
  VirtualStack,
1523
1634
  useRootContext,
@@ -1525,4 +1636,4 @@ export {
1525
1636
  useTileContext,
1526
1637
  Mosaic
1527
1638
  };
1528
- //# sourceMappingURL=chunk-BYUYHEAX.mjs.map
1639
+ //# sourceMappingURL=chunk-X6GV7SMK.mjs.map