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

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 (39) hide show
  1. package/dist/lib/browser/{chunk-FS5LRPMY.mjs → chunk-QKMUWO5X.mjs} +79 -100
  2. package/dist/lib/browser/chunk-QKMUWO5X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -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 +128 -78
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/{chunk-E5JUEEB7.mjs → chunk-BYUYHEAX.mjs} +79 -100
  9. package/dist/lib/node-esm/chunk-BYUYHEAX.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +1 -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 +128 -78
  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/testing/Board.d.ts +18 -7
  27. package/dist/types/src/testing/Board.d.ts.map +1 -1
  28. package/dist/types/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +22 -22
  30. package/src/components/Mosaic/Mosaic.stories.tsx +5 -5
  31. package/src/components/Mosaic/Mosaic.tsx +114 -140
  32. package/src/components/Mosaic/styles.ts +5 -3
  33. package/src/components/Stack/Stack.stories.tsx +2 -1
  34. package/src/hooks/index.ts +1 -0
  35. package/src/hooks/useContainerDebug.tsx +46 -0
  36. package/src/hooks/useVisibleItems.ts +3 -0
  37. package/src/testing/Board.tsx +32 -16
  38. package/dist/lib/browser/chunk-FS5LRPMY.mjs.map +0 -7
  39. 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)]",
@@ -623,29 +625,6 @@ import React6, { Fragment, forwardRef as forwardRef5 } from "react";
623
625
  import { invariant } from "@dxos/invariant";
624
626
  import { mx as mx6 } from "@dxos/ui-theme";
625
627
 
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
- };
648
-
649
628
  // src/components/Mosaic/Mosaic.tsx
650
629
  import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
651
630
  import { draggable, dropTargetForElements, monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
@@ -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 React5, { forwardRef as forwardRef4, useCallback as useCallback2, useEffect as useEffect2, useLayoutEffect, useMemo as useMemo2, useRef as useRef4, useState as useState3 } from "react";
663
642
  import { createPortal } from "react-dom";
664
643
  import { log } from "@dxos/log";
665
- import { Json } from "@dxos/react-ui-syntax-highlighter";
666
644
  import { mx as mx5 } 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
  }
@@ -802,7 +780,19 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
802
780
  };
803
781
  });
804
782
  };
805
- return monitorForElements({
783
+ const handleCancel = () => {
784
+ setDragging((dragging2) => {
785
+ requestAnimationFrame(() => {
786
+ dragging2?.target?.handler?.onCancel?.();
787
+ dragging2?.source?.container?.dispatchEvent(new CustomEvent("dnd:cancel", {
788
+ bubbles: true
789
+ }));
790
+ });
791
+ return void 0;
792
+ });
793
+ };
794
+ let noTargetTimeout;
795
+ return combine(monitorForElements({
806
796
  /**
807
797
  * Dragging started within any container.
808
798
  */
@@ -812,7 +802,7 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
812
802
  location: location.current.dropTargets.map((target) => target.data)
813
803
  }, {
814
804
  F: __dxlog_file,
815
- L: 203,
805
+ L: 215,
816
806
  S: void 0,
817
807
  C: (f, a) => f(...a)
818
808
  });
@@ -825,19 +815,24 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
825
815
  * Dragging entered a new container.
826
816
  */
827
817
  onDropTargetChange: ({ source, location }) => {
818
+ clearTimeout(noTargetTimeout);
828
819
  log("Root.onDropTargetChange", {
829
820
  source: source.data,
830
821
  location: location.current.dropTargets.map((target) => target.data)
831
822
  }, {
832
823
  F: __dxlog_file,
833
- L: 215,
824
+ L: 228,
834
825
  S: void 0,
835
826
  C: (f, a) => f(...a)
836
827
  });
837
- handleChange({
838
- source,
839
- location
840
- });
828
+ if (location.current.dropTargets.length === 0) {
829
+ noTargetTimeout = setTimeout(() => setDragging(void 0), 1e3);
830
+ } else {
831
+ handleChange({
832
+ source,
833
+ location
834
+ });
835
+ }
841
836
  },
842
837
  /**
843
838
  * Dragging within any container.
@@ -860,12 +855,12 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
860
855
  * Dragging ended.
861
856
  */
862
857
  onDrop: ({ source, location }) => {
863
- log("Root.onDrop", {
858
+ log.info("Root.onDrop", {
864
859
  source: source.data,
865
860
  location: location.current.dropTargets.map((target) => target.data)
866
861
  }, {
867
862
  F: __dxlog_file,
868
- L: 239,
863
+ L: 257,
869
864
  S: void 0,
870
865
  C: (f, a) => f(...a)
871
866
  });
@@ -876,14 +871,21 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
876
871
  handlers: Object.keys(handlers)
877
872
  }, {
878
873
  F: __dxlog_file,
879
- L: 247,
874
+ L: 265,
880
875
  S: void 0,
881
876
  C: (f, a) => f(...a)
882
877
  });
883
878
  return;
884
879
  }
885
880
  try {
886
- if (location.current.dropTargets.length > 0) {
881
+ if (location.current.dropTargets.length === 0) {
882
+ log.info("cancelled", void 0, {
883
+ F: __dxlog_file,
884
+ L: 280,
885
+ S: void 0,
886
+ C: (f, a) => f(...a)
887
+ });
888
+ } else {
887
889
  const { data: targetData, handler: targetHandler } = getTargetHandler(location);
888
890
  if (!targetHandler) {
889
891
  log.warn("invalid target", {
@@ -892,7 +894,7 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
892
894
  handlers: Object.keys(handlers)
893
895
  }, {
894
896
  F: __dxlog_file,
895
- L: 260,
897
+ L: 285,
896
898
  S: void 0,
897
899
  C: (f, a) => f(...a)
898
900
  });
@@ -909,7 +911,7 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
909
911
  source: sourceData
910
912
  }, {
911
913
  F: __dxlog_file,
912
- L: 276,
914
+ L: 301,
913
915
  S: void 0,
914
916
  C: (f, a) => f(...a)
915
917
  });
@@ -931,18 +933,10 @@ var Root = /* @__PURE__ */ forwardRef4(({ classNames, children, asChild, debug }
931
933
  }
932
934
  }
933
935
  } 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
- });
936
+ handleCancel();
943
937
  }
944
938
  }
945
- });
939
+ }));
946
940
  }, [
947
941
  handlers,
948
942
  getSourceHandler,
@@ -976,7 +970,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
976
970
  const rootRef = useRef4(null);
977
971
  const composedRef = useComposedRefs2(rootRef, forwardedRef);
978
972
  const Root2 = asChild ? Slot3 : Primitive2.div;
979
- const eventHandler = useMemo3(() => eventHandlerProp ?? {
973
+ const eventHandler = useMemo2(() => eventHandlerProp ?? {
980
974
  id: `mosaic-container-${counter++}`
981
975
  }, [
982
976
  eventHandlerProp
@@ -1004,7 +998,7 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1004
998
  }, [
1005
999
  eventHandler
1006
1000
  ]);
1007
- const data = useMemo3(() => ({
1001
+ const data = useMemo2(() => ({
1008
1002
  type: "container",
1009
1003
  id: eventHandler.id
1010
1004
  }), [
@@ -1023,6 +1017,8 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1023
1017
  }, 500);
1024
1018
  };
1025
1019
  return combine(...[
1020
+ // Autoscroll.
1021
+ // TODO(burdon): Autoscroll doesn't work well horizontally.
1026
1022
  autoscrollElement && [
1027
1023
  autoScrollForElements({
1028
1024
  element: autoscrollElement,
@@ -1139,44 +1135,6 @@ var Container = /* @__PURE__ */ forwardRef4(({ className, classNames, children,
1139
1135
  }, children), debug?.());
1140
1136
  });
1141
1137
  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
1138
  var [TileContextProvider, useTileContext] = createContext3("MosaicTile");
1181
1139
  var TILE_STATE_ATTR = "mosaic-tile-state";
1182
1140
  var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChild, dragHandle, allowedEdges: allowedEdgesProp, location, id, data: dataProp, debug: _ }, forwardedRef) => {
@@ -1187,7 +1145,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1187
1145
  const [state, setState] = useState3({
1188
1146
  type: "idle"
1189
1147
  });
1190
- const allowedEdges = useMemo3(() => allowedEdgesProp || (axis === "vertical" ? [
1148
+ const allowedEdges = useMemo2(() => allowedEdgesProp || (axis === "vertical" ? [
1191
1149
  "top",
1192
1150
  "bottom"
1193
1151
  ] : [
@@ -1197,7 +1155,7 @@ var Tile = /* @__PURE__ */ forwardRef4(({ className, classNames, children, asChi
1197
1155
  allowedEdgesProp,
1198
1156
  axis
1199
1157
  ]);
1200
- const data = useMemo3(() => ({
1158
+ const data = useMemo2(() => ({
1201
1159
  type: "tile",
1202
1160
  id,
1203
1161
  containerId,
@@ -1336,7 +1294,7 @@ var Placeholder = ({ classNames, children, asChild, axis = "vertical", location
1336
1294
  const rootRef = useRef4(null);
1337
1295
  const Root2 = asChild ? Slot3 : Primitive2.div;
1338
1296
  const { id: containerId, eventHandler, scrolling, activeLocation, setActiveLocation } = useContainerContext(Placeholder.displayName);
1339
- const data = useMemo3(() => ({
1297
+ const data = useMemo2(() => ({
1340
1298
  type: "placeholder",
1341
1299
  containerId,
1342
1300
  location
@@ -1394,7 +1352,6 @@ DropIndicator.displayName = "MosaicDropIndicator";
1394
1352
  var Mosaic = {
1395
1353
  Root,
1396
1354
  Container,
1397
- ContainerInfo,
1398
1355
  Tile,
1399
1356
  Placeholder,
1400
1357
  DropIndicator,
@@ -1404,6 +1361,29 @@ var Mosaic = {
1404
1361
  VirtualStack
1405
1362
  };
1406
1363
 
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;
1374
+ }
1375
+ const visibleItems2 = items.slice();
1376
+ visibleItems2.splice(idx, 1);
1377
+ return visibleItems2;
1378
+ }, [
1379
+ id,
1380
+ items,
1381
+ dragging,
1382
+ getId
1383
+ ]);
1384
+ return visibleItems;
1385
+ };
1386
+
1407
1387
  // src/components/Stack/Stack.tsx
1408
1388
  var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-mosaic/src/components/Stack/Stack.tsx";
1409
1389
  var StackInner = /* @__PURE__ */ forwardRef5(({ className, classNames, role = "list", axis = "vertical", draggable: draggable2 = true, items, getId, Tile: Tile2, debug, ...props }, forwardedRef) => {
@@ -1540,8 +1520,7 @@ export {
1540
1520
  VirtualStack,
1541
1521
  useRootContext,
1542
1522
  useContainerContext,
1543
- useContainerDebug,
1544
1523
  useTileContext,
1545
1524
  Mosaic
1546
1525
  };
1547
- //# sourceMappingURL=chunk-FS5LRPMY.mjs.map
1526
+ //# sourceMappingURL=chunk-QKMUWO5X.mjs.map