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

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 (109) hide show
  1. package/dist/lib/browser/{chunk-UMBPEG4F.mjs → chunk-Y6GU2CCU.mjs} +833 -992
  2. package/dist/lib/browser/chunk-Y6GU2CCU.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +407 -45
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +28 -218
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/{chunk-X6GV7SMK.mjs → chunk-KTLFCRVA.mjs} +833 -992
  9. package/dist/lib/node-esm/chunk-KTLFCRVA.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +407 -45
  11. package/dist/lib/node-esm/index.mjs.map +4 -4
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +28 -218
  14. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  15. package/dist/types/src/components/Board/Board.d.ts +65 -0
  16. package/dist/types/src/components/Board/Board.d.ts.map +1 -0
  17. package/dist/types/src/components/{Mosaic/Mosaic.stories.d.ts → Board/Board.stories.d.ts} +9 -1
  18. package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -0
  19. package/dist/types/src/components/Board/Column.d.ts +29 -0
  20. package/dist/types/src/components/Board/Column.d.ts.map +1 -0
  21. package/dist/types/src/components/Board/Item.d.ts +9 -0
  22. package/dist/types/src/components/Board/Item.d.ts.map +1 -0
  23. package/dist/types/src/components/Board/index.d.ts +2 -0
  24. package/dist/types/src/components/Board/index.d.ts.map +1 -0
  25. package/dist/types/src/components/Card/Card.d.ts +5 -3
  26. package/dist/types/src/components/Card/Card.d.ts.map +1 -1
  27. package/dist/types/src/components/Focus/Focus.d.ts +5 -4
  28. package/dist/types/src/components/Focus/Focus.d.ts.map +1 -1
  29. package/dist/types/src/components/Focus/styles.d.ts.map +1 -1
  30. package/dist/types/src/components/Mosaic/Mosaic.d.ts +8 -17
  31. package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
  32. package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -1
  33. package/dist/types/src/components/Mosaic/types.d.ts +0 -2
  34. package/dist/types/src/components/Mosaic/types.d.ts.map +1 -1
  35. package/dist/types/src/components/Stack/Stack.d.ts +3 -3
  36. package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
  37. package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
  38. package/dist/types/src/{testing/Virtualizer.stories.d.ts → components/Stack/virtualizer.stories.d.ts} +2 -2
  39. package/dist/types/src/components/Stack/virtualizer.stories.d.ts.map +1 -0
  40. package/dist/types/src/components/index.d.ts +1 -1
  41. package/dist/types/src/components/index.d.ts.map +1 -1
  42. package/dist/types/src/testing/CardContainer.d.ts +1 -1
  43. package/dist/types/src/testing/CardContainer.d.ts.map +1 -1
  44. package/dist/types/src/testing/index.d.ts +1 -1
  45. package/dist/types/src/testing/index.d.ts.map +1 -1
  46. package/dist/types/src/testing/types.d.ts +21 -0
  47. package/dist/types/src/testing/types.d.ts.map +1 -0
  48. package/dist/types/src/translations.d.ts +4 -1
  49. package/dist/types/src/translations.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +24 -26
  52. package/src/components/{Mosaic/Mosaic.stories.tsx → Board/Board.stories.tsx} +52 -8
  53. package/src/components/Board/Board.tsx +166 -0
  54. package/src/components/Board/Column.tsx +253 -0
  55. package/src/components/Board/Item.tsx +80 -0
  56. package/src/components/{Layout → Board}/index.ts +1 -1
  57. package/src/components/Card/Card.stories.tsx +1 -1
  58. package/src/components/Card/styles.ts +1 -1
  59. package/src/components/Focus/Focus.tsx +7 -9
  60. package/src/components/Focus/styles.ts +3 -6
  61. package/src/components/Image/Image.stories.tsx +1 -1
  62. package/src/components/Mosaic/Mosaic.tsx +40 -39
  63. package/src/components/Mosaic/styles.ts +9 -8
  64. package/src/components/Mosaic/types.ts +0 -4
  65. package/src/components/Stack/Stack.stories.tsx +23 -19
  66. package/src/components/Stack/Stack.tsx +34 -25
  67. package/src/{testing/Virtualizer.stories.tsx → components/Stack/virtualizer.stories.tsx} +47 -37
  68. package/src/components/index.ts +1 -1
  69. package/src/hooks/useContainerDebug.tsx +4 -2
  70. package/src/testing/CardContainer.tsx +12 -7
  71. package/src/testing/index.ts +1 -1
  72. package/src/testing/types.ts +38 -0
  73. package/src/translations.ts +4 -1
  74. package/dist/lib/browser/chunk-UMBPEG4F.mjs.map +0 -7
  75. package/dist/lib/browser/index.css +0 -13
  76. package/dist/lib/browser/index.css.map +0 -7
  77. package/dist/lib/browser/testing/index.css +0 -13
  78. package/dist/lib/browser/testing/index.css.map +0 -7
  79. package/dist/lib/node-esm/chunk-X6GV7SMK.mjs.map +0 -7
  80. package/dist/lib/node-esm/index.css +0 -13
  81. package/dist/lib/node-esm/index.css.map +0 -7
  82. package/dist/lib/node-esm/testing/index.css +0 -13
  83. package/dist/lib/node-esm/testing/index.css.map +0 -7
  84. package/dist/types/src/components/Layout/Layout.d.ts +0 -33
  85. package/dist/types/src/components/Layout/Layout.d.ts.map +0 -1
  86. package/dist/types/src/components/Layout/Layout.stories.d.ts +0 -10
  87. package/dist/types/src/components/Layout/Layout.stories.d.ts.map +0 -1
  88. package/dist/types/src/components/Layout/index.d.ts +0 -2
  89. package/dist/types/src/components/Layout/index.d.ts.map +0 -1
  90. package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +0 -1
  91. package/dist/types/src/components/Scrollable/Scrollable.d.ts +0 -24
  92. package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +0 -1
  93. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +0 -10
  94. package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +0 -1
  95. package/dist/types/src/components/Scrollable/index.d.ts +0 -2
  96. package/dist/types/src/components/Scrollable/index.d.ts.map +0 -1
  97. package/dist/types/src/testing/Board.d.ts +0 -45
  98. package/dist/types/src/testing/Board.d.ts.map +0 -1
  99. package/dist/types/src/testing/Slot.stories.d.ts +0 -14
  100. package/dist/types/src/testing/Slot.stories.d.ts.map +0 -1
  101. package/dist/types/src/testing/Virtualizer.stories.d.ts.map +0 -1
  102. package/src/components/Layout/Layout.stories.tsx +0 -59
  103. package/src/components/Layout/Layout.tsx +0 -108
  104. package/src/components/Scrollable/Scrollable.stories.tsx +0 -59
  105. package/src/components/Scrollable/Scrollable.tsx +0 -88
  106. package/src/components/Scrollable/index.ts +0 -5
  107. package/src/components/Scrollable/scrollable.css +0 -20
  108. package/src/testing/Board.tsx +0 -278
  109. package/src/testing/Slot.stories.tsx +0 -101
@@ -2,4 +2,4 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
- export * from './Layout';
5
+ export * from './Board';
@@ -57,7 +57,7 @@ const DefaultStory = ({ title, description, image, fullWidth }: CardStoryProps)
57
57
  const meta = {
58
58
  title: 'ui/react-ui-mosaic/Card',
59
59
  render: DefaultStory,
60
- decorators: [withTheme, withLayout({ layout: 'column', classNames: 'grid is-[30rem] place-items-center' })],
60
+ decorators: [withTheme(), withLayout({ layout: 'column', classNames: 'grid is-[30rem] place-items-center' })],
61
61
  } satisfies Meta<typeof DefaultStory>;
62
62
 
63
63
  export default meta;
@@ -5,7 +5,7 @@
5
5
  import { type ClassNameValue } from '@dxos/react-ui';
6
6
 
7
7
  export const styles = {
8
- root: 'group/card relative min-bs-[--rail-item] overflow-hidden is-full card-min-width __card-max-width',
8
+ root: 'group/card relative min-bs-[--rail-item] is-full card-min-width overflow-hidden',
9
9
  border:
10
10
  'bg-cardSurface border border-separator dark:border-subduedSeparator rounded-sm dx-focus-ring-group-y-indicator',
11
11
 
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  import {
6
- type UseArrowNavigationGroupOptions,
7
6
  useArrowNavigationGroup,
8
7
  useFocusableGroup,
9
8
  useMergedTabsterAttributes_unstable,
@@ -13,7 +12,7 @@ import { Primitive } from '@radix-ui/react-primitive';
13
12
  import { Slot } from '@radix-ui/react-slot';
14
13
  import React, { type PropsWithChildren, createContext, forwardRef, useContext, useRef, useState } from 'react';
15
14
 
16
- import { type ThemedClassName } from '@dxos/react-ui';
15
+ import { type Axis, type ThemedClassName } from '@dxos/react-ui';
17
16
  import { mx } from '@dxos/ui-theme';
18
17
 
19
18
  import { styles } from './styles';
@@ -39,17 +38,16 @@ const useFocus = () => useContext(FocusContext);
39
38
  //
40
39
 
41
40
  type GroupProps = ThemedClassName<
42
- PropsWithChildren<
43
- {
44
- asChild?: boolean;
45
- } & Pick<UseArrowNavigationGroupOptions, 'axis'>
46
- >
41
+ PropsWithChildren<{
42
+ asChild?: boolean;
43
+ orientation?: Axis;
44
+ }>
47
45
  > & { className?: string };
48
46
 
49
47
  // TODO(wittjosiah): Consider how this could integrate with with react-ui-attention.
50
48
  // Perhaps react-ui-attention comes under the mosaic umbrella as it supports selection?
51
49
  const Group = forwardRef<HTMLDivElement, GroupProps>(
52
- ({ classNames, className, children, asChild, axis = 'vertical', ...props }: GroupProps, forwardedRef) => {
50
+ ({ classNames, className, children, asChild, orientation = 'vertical', ...props }: GroupProps, forwardedRef) => {
53
51
  const rootRef = useRef<HTMLDivElement>(null);
54
52
  const composedRef = useComposedRefs<HTMLDivElement>(rootRef, forwardedRef);
55
53
  const Root = asChild ? Slot : Primitive.div;
@@ -59,7 +57,7 @@ const Group = forwardRef<HTMLDivElement, GroupProps>(
59
57
  tabBehavior: 'limited-trap-focus',
60
58
  });
61
59
  const arrowNavigationAttrs = useArrowNavigationGroup({
62
- axis,
60
+ axis: orientation,
63
61
  memorizeCurrent: true,
64
62
  });
65
63
  const tabsterAttrs = useMergedTabsterAttributes_unstable(focusableGroupAttrs, arrowNavigationAttrs);
@@ -4,20 +4,17 @@
4
4
 
5
5
  import { type ClassNameValue } from '@dxos/react-ui';
6
6
 
7
- // TODO(burdon): Theme?
7
+ // TODO(burdon): Create theme for component.
8
8
  export const styles = {
9
9
  container: {
10
- // TODO(burdon): Handle selection (aria-current?)
11
- // TODO(burdon): Use ring instead of border?
12
10
  root: [
13
- 'outline-none border border-separator rounded-sm',
11
+ // TODO(burdon): Option for border/rounded; ring/outline vs border?
12
+ 'outline-none border border-separator md:rounded-sm',
14
13
  // Focus (e.g., via tabster).
15
- // TODO(burdon): Why is ! required?
16
14
  'focus:!border-accentSurface',
17
15
  // Active (e.g., drop target).
18
16
  'data-[focus-state=active]:border-neutralFocusIndicator',
19
17
  // Error
20
- // TODO(burdon): Error token.
21
18
  'data-[focus-state=error]:border-rose-500',
22
19
  ],
23
20
  },
@@ -22,7 +22,7 @@ const meta = {
22
22
  <Image {...args} />
23
23
  </div>
24
24
  ),
25
- decorators: [withTheme],
25
+ decorators: [withTheme()],
26
26
  parameters: {
27
27
  layout: 'centered',
28
28
  },
@@ -42,17 +42,14 @@ import React, {
42
42
  import { createPortal } from 'react-dom';
43
43
 
44
44
  import { log } from '@dxos/log';
45
- import { type SlottableClassName, type ThemedClassName } from '@dxos/react-ui';
45
+ import { type AllowedAxis, type Axis, type SlottableClassName, type ThemedClassName } from '@dxos/react-ui';
46
46
  import { mx } from '@dxos/ui-theme';
47
47
  import { isTruthy } from '@dxos/util';
48
48
 
49
49
  import { useFocus } from '../Focus';
50
- import { Scrollable, type ScrollableProps } from '../Scrollable';
51
50
  import { Stack, type StackProps, VirtualStack } from '../Stack';
52
51
 
53
52
  import {
54
- type AllowedAxis,
55
- type Axis,
56
53
  type MosaicContainerData,
57
54
  type MosaicData,
58
55
  type MosaicEventHandler,
@@ -124,10 +121,17 @@ const [RootContextProvider, useRootContext] = createContext<RootContextValue>('M
124
121
  // Root
125
122
  //
126
123
 
124
+ const ROOT_NAME = 'Mosaic.Root';
125
+
127
126
  // State attribute: [&:has(>_[data-mosaic-debug=true])]
128
127
  const ROOT_DEBUG_ATTR = 'mosaic-debug';
129
128
 
130
- type RootProps = ThemedClassName<PropsWithChildren<{ asChild?: boolean; debug?: boolean }>>;
129
+ type RootProps = ThemedClassName<
130
+ PropsWithChildren<{
131
+ asChild?: boolean;
132
+ debug?: boolean;
133
+ }>
134
+ >;
131
135
 
132
136
  const Root = forwardRef<HTMLDivElement, RootProps>(({ classNames, children, asChild, debug }, forwardedRef) => {
133
137
  const rootRef = useRef<HTMLDivElement>(null);
@@ -338,7 +342,7 @@ const Root = forwardRef<HTMLDivElement, RootProps>(({ classNames, children, asCh
338
342
  dragging={dragging}
339
343
  >
340
344
  <Root
341
- className={mx('group overflow-hidden', classNames)}
345
+ className={mx('group', classNames)}
342
346
  {...{
343
347
  [`data-${ROOT_DEBUG_ATTR}`]: debug,
344
348
  }}
@@ -350,16 +354,20 @@ const Root = forwardRef<HTMLDivElement, RootProps>(({ classNames, children, asCh
350
354
  );
351
355
  });
352
356
 
357
+ Root.displayName = ROOT_NAME;
358
+
353
359
  //
354
360
  // Container
355
361
  //
356
362
 
363
+ const CONTAINER_NAME = 'Mosaic.Container';
364
+
357
365
  type ContainerState = { type: 'idle' } | { type: 'active'; bounds?: DOMRect };
358
366
 
359
367
  type ContainerContextValue<TData = any, Location = LocationType> = {
360
368
  id: string;
361
369
  eventHandler: MosaicEventHandler<TData>;
362
- axis?: AllowedAxis;
370
+ orientation?: AllowedAxis;
363
371
  dragging?: DraggingState;
364
372
  scrolling?: boolean;
365
373
  state: ContainerState;
@@ -380,7 +388,7 @@ const CONTAINER_PLACEHOLDER_HEIGHT = '--mosaic-placeholder-height';
380
388
 
381
389
  type ContainerProps = SlottableClassName<
382
390
  PropsWithChildren<
383
- Partial<Pick<ContainerContextValue, 'eventHandler' | 'axis'>> & {
391
+ Partial<Pick<ContainerContextValue, 'eventHandler' | 'orientation'>> & {
384
392
  asChild?: boolean;
385
393
  autoScroll?: HTMLElement | null;
386
394
  withFocus?: boolean;
@@ -399,7 +407,7 @@ const Container = forwardRef<HTMLDivElement, ContainerProps>(
399
407
  classNames,
400
408
  children,
401
409
  eventHandler: eventHandlerProp,
402
- axis = 'vertical',
410
+ orientation = 'vertical',
403
411
  asChild,
404
412
  autoScroll: autoscrollElement,
405
413
  withFocus,
@@ -422,7 +430,7 @@ const Container = forwardRef<HTMLDivElement, ContainerProps>(
422
430
  );
423
431
 
424
432
  // State.
425
- const { dragging } = useRootContext(Container.displayName!);
433
+ const { dragging } = useRootContext(CONTAINER_NAME);
426
434
  const [state, setState] = useState<ContainerState>({ type: 'idle' });
427
435
  const [activeLocation, setActiveLocation] = useState<LocationType | undefined>();
428
436
  const [scrolling, setScrolling] = useState(false);
@@ -539,7 +547,7 @@ const Container = forwardRef<HTMLDivElement, ContainerProps>(
539
547
  // canScroll: ({ element: _ }) => {
540
548
  // return true;
541
549
  // },
542
- getAllowedAxis: () => axis,
550
+ getAllowedAxis: () => orientation,
543
551
  getConfiguration: () => ({
544
552
  maxScrollSpeed: 'fast',
545
553
  }),
@@ -562,7 +570,7 @@ const Container = forwardRef<HTMLDivElement, ContainerProps>(
562
570
  <ContainerContextProvider
563
571
  id={eventHandler.id}
564
572
  eventHandler={eventHandler}
565
- axis={axis}
573
+ orientation={orientation}
566
574
  state={state}
567
575
  dragging={state.type === 'active' ? dragging : undefined}
568
576
  scrolling={scrolling}
@@ -593,12 +601,14 @@ const Container = forwardRef<HTMLDivElement, ContainerProps>(
593
601
  },
594
602
  );
595
603
 
596
- Container.displayName = 'MosaicContainer';
604
+ Container.displayName = CONTAINER_NAME;
597
605
 
598
606
  //
599
607
  // Tile
600
608
  //
601
609
 
610
+ const TILE_NAME = 'Mosaic.Tile';
611
+
602
612
  /** Must implement value equivalence. */
603
613
  type LocationType = string | number;
604
614
 
@@ -651,18 +661,12 @@ const Tile = forwardRef<HTMLDivElement, TileProps>(
651
661
  const Root = asChild ? Slot : Primitive.div;
652
662
 
653
663
  // State.
654
- const {
655
- id: containerId,
656
- eventHandler,
657
- axis,
658
- scrolling,
659
- setActiveLocation,
660
- } = useContainerContext(Tile.displayName!);
664
+ const { id: containerId, eventHandler, orientation, scrolling, setActiveLocation } = useContainerContext(TILE_NAME);
661
665
  const [state, setState] = useState<TileState>({ type: 'idle' });
662
666
 
663
667
  const allowedEdges = useMemo<Edge[]>(
664
- () => allowedEdgesProp || (axis === 'vertical' ? ['top', 'bottom'] : ['left', 'right']),
665
- [allowedEdgesProp, axis],
668
+ () => allowedEdgesProp || (orientation === 'vertical' ? ['top', 'bottom'] : ['left', 'right']),
669
+ [allowedEdgesProp, orientation],
666
670
  );
667
671
 
668
672
  const data = useMemo<MosaicTileData>(
@@ -792,14 +796,16 @@ const Tile = forwardRef<HTMLDivElement, TileProps>(
792
796
  },
793
797
  );
794
798
 
795
- Tile.displayName = 'MosaicTile';
799
+ Tile.displayName = TILE_NAME;
796
800
 
797
801
  //
798
802
  // Placeholder
799
803
  //
800
804
 
801
- // Axis: data-[mosaic-placeholder-axis=vertical]
802
- const PLACEHOLDER_AXIS_ATTR = 'mosaic-placeholder-axis';
805
+ const PLACEHOLDER_NAME = 'Mosaic.Placeholder';
806
+
807
+ // Orientation: data-[mosaic-placeholder-orientation=vertical]
808
+ const PLACEHOLDER_ORIENTATION_ATTR = 'mosaic-placeholder-orientation';
803
809
 
804
810
  // State attribute: data-[mosaic-placeholder-state=active]
805
811
  const PLACEHOLDER_STATE_ATTR = 'mosaic-placeholder-state';
@@ -807,7 +813,7 @@ const PLACEHOLDER_STATE_ATTR = 'mosaic-placeholder-state';
807
813
  type PlaceholderProps<Location = LocationType> = ThemedClassName<
808
814
  PropsWithChildren<{
809
815
  asChild?: boolean;
810
- axis?: Axis;
816
+ orientation?: Axis;
811
817
  location: Location;
812
818
  }>
813
819
  >;
@@ -816,7 +822,7 @@ const Placeholder = <Location extends LocationType = LocationType>({
816
822
  classNames,
817
823
  children,
818
824
  asChild,
819
- axis = 'vertical',
825
+ orientation = 'vertical',
820
826
  location,
821
827
  }: PlaceholderProps<Location>) => {
822
828
  const rootRef = useRef<HTMLDivElement>(null);
@@ -827,8 +833,7 @@ const Placeholder = <Location extends LocationType = LocationType>({
827
833
  scrolling,
828
834
  activeLocation,
829
835
  setActiveLocation,
830
- } = useContainerContext(Placeholder.displayName!);
831
-
836
+ } = useContainerContext(PLACEHOLDER_NAME);
832
837
  const data = useMemo<MosaicPlaceholderData<Location>>(
833
838
  () =>
834
839
  ({
@@ -867,7 +872,7 @@ const Placeholder = <Location extends LocationType = LocationType>({
867
872
  return (
868
873
  <Root
869
874
  {...{
870
- [`data-${PLACEHOLDER_AXIS_ATTR}`]: axis,
875
+ [`data-${PLACEHOLDER_ORIENTATION_ATTR}`]: orientation,
871
876
  [`data-${PLACEHOLDER_STATE_ATTR}`]: data.location === activeLocation ? 'active' : 'idle',
872
877
  }}
873
878
  role='none'
@@ -879,23 +884,25 @@ const Placeholder = <Location extends LocationType = LocationType>({
879
884
  );
880
885
  };
881
886
 
882
- Placeholder.displayName = 'MosaicPlaceholder';
887
+ Placeholder.displayName = PLACEHOLDER_NAME;
883
888
 
884
889
  //
885
890
  // DropIndicator
886
891
  // TODO(burdon): Support DropIndicator or Placeholder variants.
887
892
  //
888
893
 
894
+ const DROP_INDICATOR_NAME = 'Mosaic.DropIndicator';
895
+
889
896
  type DropIndicatorProps = Omit<NativeDropIndicatorProps, 'edge'>;
890
897
 
891
898
  const DropIndicator = (props: DropIndicatorProps) => {
892
- const { state } = useTileContext(DropIndicator.displayName!);
899
+ const { state } = useTileContext(DROP_INDICATOR_NAME);
893
900
  return state.type === 'target' && state.closestEdge ? (
894
901
  <NativeDropIndicator {...props} edge={state.closestEdge} />
895
902
  ) : null;
896
903
  };
897
904
 
898
- DropIndicator.displayName = 'MosaicDropIndicator';
905
+ DropIndicator.displayName = DROP_INDICATOR_NAME;
899
906
 
900
907
  //
901
908
  // Mosaic
@@ -907,9 +914,6 @@ export const Mosaic = {
907
914
  Tile,
908
915
  Placeholder,
909
916
  DropIndicator,
910
-
911
- // TODO(burdon): Move out of Mosaic namespace?
912
- Viewport: Scrollable,
913
917
  Stack,
914
918
  VirtualStack,
915
919
  };
@@ -920,9 +924,6 @@ export type {
920
924
  TileProps as MosaicTileProps,
921
925
  PlaceholderProps as MosiacPlaceholderProps,
922
926
  DropIndicatorProps as MosaicDropIndicatorProps,
923
-
924
- // TODO(burdon): Move out of Mosaic namespace?
925
- ScrollableProps as MosaicViewportProps,
926
927
  StackProps as MosaicStackProps,
927
928
  };
928
929
 
@@ -11,10 +11,11 @@ export const styles = {
11
11
  'group-data-[mosaic-debug="true"]:opacity-100',
12
12
  'group-data-[mosaic-debug="true"]:bg-orange-500',
13
13
  'data-[mosaic-placeholder-state=active]:opacity-100',
14
- 'data-[mosaic-placeholder-axis=vertical]:plb-1',
15
- 'data-[mosaic-placeholder-axis=vertical]:data-[mosaic-placeholder-state=active]:plb-2.5',
16
- 'data-[mosaic-placeholder-axis=horizontal]:pli-1',
17
- 'data-[mosaic-placeholder-axis=horizontal]:data-[mosaic-placeholder-state=active]:pli-2.5',
14
+ 'data-[mosaic-placeholder-orientation=vertical]:snap-start', // TODO(burdon): Option.
15
+ 'data-[mosaic-placeholder-orientation=vertical]:plb-1',
16
+ 'data-[mosaic-placeholder-orientation=vertical]:data-[mosaic-placeholder-state=active]:plb-2.5',
17
+ 'data-[mosaic-placeholder-orientation=horizontal]:pli-1',
18
+ 'data-[mosaic-placeholder-orientation=horizontal]:data-[mosaic-placeholder-state=active]:pli-2.5',
18
19
  ],
19
20
  content: [
20
21
  'transition-all duration-0',
@@ -22,10 +23,10 @@ export const styles = {
22
23
  // TODO(burdon): Flickers when start to drag since source is removed and then the placeholder shows up.
23
24
  // - Use absolute positioning?
24
25
  // 'group-data-[mosaic-placeholder-state=active]:duration-200',
25
- 'group-data-[mosaic-placeholder-axis=vertical]:bs-0',
26
- 'group-data-[mosaic-placeholder-axis=horizontal]:is-0',
27
- 'group-data-[mosaic-placeholder-axis=vertical]:group-data-[mosaic-placeholder-state=active]:bs-[var(--mosaic-placeholder-height)]',
28
- 'group-data-[mosaic-placeholder-axis=horizontal]:group-data-[mosaic-placeholder-state=active]:is-[var(--mosaic-placeholder-width)]',
26
+ 'group-data-[mosaic-placeholder-orientation=vertical]:bs-0',
27
+ 'group-data-[mosaic-placeholder-orientation=vertical]:group-data-[mosaic-placeholder-state=active]:bs-[var(--mosaic-placeholder-height)]',
28
+ 'group-data-[mosaic-placeholder-orientation=horizontal]:is-0',
29
+ 'group-data-[mosaic-placeholder-orientation=horizontal]:group-data-[mosaic-placeholder-state=active]:is-[var(--mosaic-placeholder-width)]',
29
30
  ],
30
31
  },
31
32
  } satisfies Record<string, Record<string, ClassNameValue>>;
@@ -2,10 +2,6 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- // These are not exported from the pragmatic-drag-and-drop-auto-scroll package.
6
- export type Axis = 'vertical' | 'horizontal';
7
- export type AllowedAxis = Axis | 'all';
8
-
9
5
  export type GetId<TData = any> = (data: TData) => string;
10
6
 
11
7
  /**
@@ -8,7 +8,7 @@ import { useMemo } from 'react';
8
8
 
9
9
  import { Obj } from '@dxos/echo';
10
10
  import { faker } from '@dxos/random';
11
- import { Toolbar } from '@dxos/react-ui';
11
+ import { ScrollArea, Toolbar } from '@dxos/react-ui';
12
12
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
13
13
 
14
14
  import { useContainerDebug } from '../../hooks';
@@ -33,12 +33,12 @@ const createTestItems = (n: number) =>
33
33
  const meta: Meta<typeof Stack<Obj.Any>> = {
34
34
  title: 'ui/react-ui-mosaic/Stack',
35
35
  component: Stack,
36
- decorators: [withLayout({ layout: 'column' }), withTheme],
36
+ decorators: [withLayout({ layout: 'column' }), withTheme()],
37
37
  parameters: {
38
38
  layout: 'fullscreen',
39
39
  },
40
40
  args: {
41
- axis: 'vertical',
41
+ orientation: 'vertical',
42
42
  getId: (item) => item.id,
43
43
  Tile: DefaultStackTile,
44
44
  // debug: true,
@@ -62,14 +62,16 @@ export const Default: Story = {
62
62
  </Toolbar.Root>
63
63
  <Mosaic.Container
64
64
  asChild
65
- axis='vertical'
65
+ orientation='vertical'
66
66
  autoScroll={viewport}
67
67
  eventHandler={{ id: 'test', canDrop: () => true }}
68
68
  debug={debugHandler}
69
69
  >
70
- <Mosaic.Viewport axis='vertical' padding viewportRef={setViewport}>
71
- <Mosaic.Stack {...props} items={items} />
72
- </Mosaic.Viewport>
70
+ <ScrollArea.Root orientation='vertical'>
71
+ <ScrollArea.Viewport classNames='p-2' ref={setViewport}>
72
+ <Mosaic.Stack {...props} items={items} />
73
+ </ScrollArea.Viewport>
74
+ </ScrollArea.Root>
73
75
  </Mosaic.Container>
74
76
  <DebugInfo classNames='border-bs border-separator' />
75
77
  </Mosaic.Root>
@@ -91,22 +93,24 @@ export const Virtual: Story = {
91
93
  </Toolbar.Root>
92
94
  <Mosaic.Container
93
95
  asChild
94
- axis='vertical'
96
+ orientation='vertical'
95
97
  autoScroll={viewport}
96
98
  eventHandler={{ id: 'test', canDrop: () => true }}
97
99
  debug={debugHandler}
98
100
  >
99
- <Mosaic.Viewport axis='vertical' padding viewportRef={setViewport}>
100
- <Mosaic.VirtualStack
101
- {...props}
102
- items={items}
103
- getScrollElement={() => viewport}
104
- estimateSize={() => 40}
105
- onChange={(virtualizer) => {
106
- setInfo({ range: virtualizer.range });
107
- }}
108
- />
109
- </Mosaic.Viewport>
101
+ <ScrollArea.Root orientation='vertical'>
102
+ <ScrollArea.Viewport classNames='p-2' ref={setViewport}>
103
+ <Mosaic.VirtualStack
104
+ {...props}
105
+ items={items}
106
+ getScrollElement={() => viewport}
107
+ estimateSize={() => 40}
108
+ onChange={(virtualizer) => {
109
+ setInfo({ range: virtualizer.range });
110
+ }}
111
+ />
112
+ </ScrollArea.Viewport>
113
+ </ScrollArea.Root>
110
114
  </Mosaic.Container>
111
115
  <DebugInfo />
112
116
  </Mosaic.Root>
@@ -6,20 +6,15 @@ import { type ReactVirtualizerOptions, useVirtualizer } from '@tanstack/react-vi
6
6
  import React, { type FC, Fragment, type ReactElement, type Ref, forwardRef } from 'react';
7
7
 
8
8
  import { invariant } from '@dxos/invariant';
9
- import { type SlottableClassName } from '@dxos/react-ui';
9
+ import { type Axis, type SlottableClassName } from '@dxos/react-ui';
10
10
  import { mx } from '@dxos/ui-theme';
11
11
 
12
12
  import { useVisibleItems } from '../../hooks';
13
- import {
14
- type Axis,
15
- type GetId,
16
- Mosaic,
17
- type MosaicTileProps,
18
- type MosiacPlaceholderProps,
19
- useMosaicContainer,
20
- } from '../Mosaic';
13
+ import { type GetId, Mosaic, type MosaicTileProps, type MosiacPlaceholderProps, useMosaicContainer } from '../Mosaic';
21
14
  import { mosaicStyles } from '../Mosaic';
22
15
 
16
+ const STACK_NAME = 'Stack';
17
+
23
18
  type StackTileComponent<TData = any> = FC<MosaicTileProps<TData>>;
24
19
 
25
20
  type StackProps<TData = any> = SlottableClassName<
@@ -27,7 +22,7 @@ type StackProps<TData = any> = SlottableClassName<
27
22
  Tile: StackTileComponent<TData>;
28
23
  getId: GetId<TData>;
29
24
  role?: string;
30
- axis?: Axis;
25
+ orientation?: Axis;
31
26
  items?: TData[];
32
27
  } & Pick<MosaicTileProps<TData>, 'draggable' | 'debug'>
33
28
  >;
@@ -38,12 +33,24 @@ type StackProps<TData = any> = SlottableClassName<
38
33
  */
39
34
  const StackInner = forwardRef<HTMLDivElement, StackProps>(
40
35
  (
41
- { className, classNames, role = 'list', axis = 'vertical', draggable = true, items, getId, Tile, debug, ...props },
36
+ {
37
+ className,
38
+ classNames,
39
+ role = 'list',
40
+ orientation: orientationProp = 'vertical',
41
+ draggable = true,
42
+ items,
43
+ getId,
44
+ Tile,
45
+ debug,
46
+ ...props
47
+ },
42
48
  forwardedRef,
43
49
  ) => {
44
50
  invariant(Tile);
45
- const { id, dragging } = useMosaicContainer(StackInner.displayName!);
51
+ const { id, orientation = orientationProp, dragging } = useMosaicContainer(STACK_NAME);
46
52
  const visibleItems = useVisibleItems({ id, items, dragging: dragging?.source.data, getId });
53
+ invariant(orientation === 'vertical' || orientation === 'horizontal', `Invalid orientation: ${orientation}`);
47
54
 
48
55
  return (
49
56
  <div
@@ -51,18 +58,18 @@ const StackInner = forwardRef<HTMLDivElement, StackProps>(
51
58
  role={role}
52
59
  className={mx(
53
60
  'flex',
54
- axis === 'horizontal' && 'bs-full [&>*]:shrink-0',
55
- axis === 'vertical' && 'flex-col',
61
+ orientation === 'horizontal' && 'bs-full [&>*]:shrink-0',
62
+ orientation === 'vertical' && 'flex-col',
56
63
  classNames,
57
64
  className,
58
65
  )}
59
66
  ref={forwardedRef}
60
67
  >
61
- <Placeholder axis={axis} location={0.5} />
68
+ <Placeholder orientation={orientation} location={0.5} />
62
69
  {visibleItems?.map((item, index) => (
63
70
  <Fragment key={getId(item)}>
64
71
  <Tile id={getId(item)} data={item} location={index + 1} draggable={draggable} debug={debug} />
65
- <Placeholder axis={axis} location={index + 1.5} />
72
+ <Placeholder orientation={orientation} location={index + 1.5} />
66
73
  </Fragment>
67
74
  ))}
68
75
  </div>
@@ -70,7 +77,7 @@ const StackInner = forwardRef<HTMLDivElement, StackProps>(
70
77
  },
71
78
  );
72
79
 
73
- StackInner.displayName = 'Stack';
80
+ StackInner.displayName = STACK_NAME;
74
81
 
75
82
  const Stack = StackInner as <TData = any>(props: StackProps<TData> & { ref?: Ref<HTMLDivElement> }) => ReactElement;
76
83
 
@@ -78,6 +85,8 @@ const Stack = StackInner as <TData = any>(props: StackProps<TData> & { ref?: Ref
78
85
  // VirtualStack
79
86
  //
80
87
 
88
+ const VIRTUAL_STACK_NAME = 'VirtualStackInner';
89
+
81
90
  type VirtualStackProps<TData = any> = StackProps<TData> &
82
91
  Pick<
83
92
  ReactVirtualizerOptions<HTMLElement, HTMLDivElement>,
@@ -90,7 +99,7 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
90
99
  className,
91
100
  classNames,
92
101
  role = 'list',
93
- axis = 'vertical',
102
+ orientation = 'vertical',
94
103
  items,
95
104
  getId,
96
105
  Tile,
@@ -104,7 +113,7 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
104
113
  forwardedRef,
105
114
  ) => {
106
115
  invariant(Tile);
107
- const { id, dragging } = useMosaicContainer(VirtualStackInner.displayName!);
116
+ const { id, dragging } = useMosaicContainer(VIRTUAL_STACK_NAME);
108
117
  const visibleItems = useVisibleItems({ id, items, dragging: dragging?.source.data, getId });
109
118
  const virtualizer = useVirtualizer({
110
119
  count: visibleItems.length * 2 + 1,
@@ -122,14 +131,14 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
122
131
  role={role}
123
132
  className={mx(
124
133
  'flex',
125
- axis === 'horizontal' && 'bs-full [&>*]:shrink-0',
126
- axis === 'vertical' && 'flex-col',
134
+ orientation === 'horizontal' && 'bs-full [&>*]:shrink-0',
135
+ orientation === 'vertical' && 'flex-col',
127
136
  classNames,
128
137
  className,
129
138
  )}
130
139
  style={{
131
140
  position: 'relative',
132
- ...(axis === 'vertical'
141
+ ...(orientation === 'vertical'
133
142
  ? {
134
143
  width: '100%',
135
144
  height: virtualizer.getTotalSize(),
@@ -151,7 +160,7 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
151
160
  position: 'absolute',
152
161
  top: 0,
153
162
  left: 0,
154
- ...(axis === 'vertical'
163
+ ...(orientation === 'vertical'
155
164
  ? {
156
165
  width: '100%',
157
166
  transform: `translateY(${virtualItem.start}px)`,
@@ -164,7 +173,7 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
164
173
  ref={virtualizer.measureElement}
165
174
  >
166
175
  {virtualItem.index % 2 === 0 ? (
167
- <Placeholder axis={axis} location={Math.floor(virtualItem.index / 2) + 0.5} />
176
+ <Placeholder orientation={orientation} location={Math.floor(virtualItem.index / 2) + 0.5} />
168
177
  ) : (
169
178
  <Tile id={getId(data)} data={data} location={Math.floor(virtualItem.index / 2) + 1} debug={debug} />
170
179
  )}
@@ -176,7 +185,7 @@ const VirtualStackInner = forwardRef<HTMLDivElement, VirtualStackProps>(
176
185
  },
177
186
  );
178
187
 
179
- VirtualStackInner.displayName = 'VirtualStackInner';
188
+ VirtualStackInner.displayName = VIRTUAL_STACK_NAME;
180
189
 
181
190
  const VirtualStack = VirtualStackInner as <TData = any>(
182
191
  props: VirtualStackProps<TData> & { ref?: Ref<HTMLDivElement> },