@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.
- package/dist/lib/browser/{chunk-UMBPEG4F.mjs → chunk-Y6GU2CCU.mjs} +833 -992
- package/dist/lib/browser/chunk-Y6GU2CCU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +407 -45
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +28 -218
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/{chunk-X6GV7SMK.mjs → chunk-KTLFCRVA.mjs} +833 -992
- package/dist/lib/node-esm/chunk-KTLFCRVA.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +407 -45
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +28 -218
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/components/Board/Board.d.ts +65 -0
- package/dist/types/src/components/Board/Board.d.ts.map +1 -0
- package/dist/types/src/components/{Mosaic/Mosaic.stories.d.ts → Board/Board.stories.d.ts} +9 -1
- package/dist/types/src/components/Board/Board.stories.d.ts.map +1 -0
- package/dist/types/src/components/Board/Column.d.ts +29 -0
- package/dist/types/src/components/Board/Column.d.ts.map +1 -0
- package/dist/types/src/components/Board/Item.d.ts +9 -0
- package/dist/types/src/components/Board/Item.d.ts.map +1 -0
- package/dist/types/src/components/Board/index.d.ts +2 -0
- package/dist/types/src/components/Board/index.d.ts.map +1 -0
- package/dist/types/src/components/Card/Card.d.ts +5 -3
- package/dist/types/src/components/Card/Card.d.ts.map +1 -1
- package/dist/types/src/components/Focus/Focus.d.ts +5 -4
- package/dist/types/src/components/Focus/Focus.d.ts.map +1 -1
- package/dist/types/src/components/Focus/styles.d.ts.map +1 -1
- package/dist/types/src/components/Mosaic/Mosaic.d.ts +8 -17
- package/dist/types/src/components/Mosaic/Mosaic.d.ts.map +1 -1
- package/dist/types/src/components/Mosaic/styles.d.ts.map +1 -1
- package/dist/types/src/components/Mosaic/types.d.ts +0 -2
- package/dist/types/src/components/Mosaic/types.d.ts.map +1 -1
- package/dist/types/src/components/Stack/Stack.d.ts +3 -3
- package/dist/types/src/components/Stack/Stack.d.ts.map +1 -1
- package/dist/types/src/components/Stack/Stack.stories.d.ts.map +1 -1
- package/dist/types/src/{testing/Virtualizer.stories.d.ts → components/Stack/virtualizer.stories.d.ts} +2 -2
- package/dist/types/src/components/Stack/virtualizer.stories.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/testing/CardContainer.d.ts +1 -1
- package/dist/types/src/testing/CardContainer.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +21 -0
- package/dist/types/src/testing/types.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +4 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -26
- package/src/components/{Mosaic/Mosaic.stories.tsx → Board/Board.stories.tsx} +52 -8
- package/src/components/Board/Board.tsx +166 -0
- package/src/components/Board/Column.tsx +253 -0
- package/src/components/Board/Item.tsx +80 -0
- package/src/components/{Layout → Board}/index.ts +1 -1
- package/src/components/Card/Card.stories.tsx +1 -1
- package/src/components/Card/styles.ts +1 -1
- package/src/components/Focus/Focus.tsx +7 -9
- package/src/components/Focus/styles.ts +3 -6
- package/src/components/Image/Image.stories.tsx +1 -1
- package/src/components/Mosaic/Mosaic.tsx +40 -39
- package/src/components/Mosaic/styles.ts +9 -8
- package/src/components/Mosaic/types.ts +0 -4
- package/src/components/Stack/Stack.stories.tsx +23 -19
- package/src/components/Stack/Stack.tsx +34 -25
- package/src/{testing/Virtualizer.stories.tsx → components/Stack/virtualizer.stories.tsx} +47 -37
- package/src/components/index.ts +1 -1
- package/src/hooks/useContainerDebug.tsx +4 -2
- package/src/testing/CardContainer.tsx +12 -7
- package/src/testing/index.ts +1 -1
- package/src/testing/types.ts +38 -0
- package/src/translations.ts +4 -1
- package/dist/lib/browser/chunk-UMBPEG4F.mjs.map +0 -7
- package/dist/lib/browser/index.css +0 -13
- package/dist/lib/browser/index.css.map +0 -7
- package/dist/lib/browser/testing/index.css +0 -13
- package/dist/lib/browser/testing/index.css.map +0 -7
- package/dist/lib/node-esm/chunk-X6GV7SMK.mjs.map +0 -7
- package/dist/lib/node-esm/index.css +0 -13
- package/dist/lib/node-esm/index.css.map +0 -7
- package/dist/lib/node-esm/testing/index.css +0 -13
- package/dist/lib/node-esm/testing/index.css.map +0 -7
- package/dist/types/src/components/Layout/Layout.d.ts +0 -33
- package/dist/types/src/components/Layout/Layout.d.ts.map +0 -1
- package/dist/types/src/components/Layout/Layout.stories.d.ts +0 -10
- package/dist/types/src/components/Layout/Layout.stories.d.ts.map +0 -1
- package/dist/types/src/components/Layout/index.d.ts +0 -2
- package/dist/types/src/components/Layout/index.d.ts.map +0 -1
- package/dist/types/src/components/Mosaic/Mosaic.stories.d.ts.map +0 -1
- package/dist/types/src/components/Scrollable/Scrollable.d.ts +0 -24
- package/dist/types/src/components/Scrollable/Scrollable.d.ts.map +0 -1
- package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts +0 -10
- package/dist/types/src/components/Scrollable/Scrollable.stories.d.ts.map +0 -1
- package/dist/types/src/components/Scrollable/index.d.ts +0 -2
- package/dist/types/src/components/Scrollable/index.d.ts.map +0 -1
- package/dist/types/src/testing/Board.d.ts +0 -45
- package/dist/types/src/testing/Board.d.ts.map +0 -1
- package/dist/types/src/testing/Slot.stories.d.ts +0 -14
- package/dist/types/src/testing/Slot.stories.d.ts.map +0 -1
- package/dist/types/src/testing/Virtualizer.stories.d.ts.map +0 -1
- package/src/components/Layout/Layout.stories.tsx +0 -59
- package/src/components/Layout/Layout.tsx +0 -108
- package/src/components/Scrollable/Scrollable.stories.tsx +0 -59
- package/src/components/Scrollable/Scrollable.tsx +0 -88
- package/src/components/Scrollable/index.ts +0 -5
- package/src/components/Scrollable/scrollable.css +0 -20
- package/src/testing/Board.tsx +0 -278
- package/src/testing/Slot.stories.tsx +0 -101
|
@@ -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]
|
|
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
|
-
|
|
45
|
-
|
|
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,
|
|
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):
|
|
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
|
-
|
|
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
|
},
|
|
@@ -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<
|
|
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
|
|
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
|
-
|
|
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' | '
|
|
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
|
-
|
|
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(
|
|
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: () =>
|
|
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
|
-
|
|
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 =
|
|
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 || (
|
|
665
|
-
[allowedEdgesProp,
|
|
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 =
|
|
799
|
+
Tile.displayName = TILE_NAME;
|
|
796
800
|
|
|
797
801
|
//
|
|
798
802
|
// Placeholder
|
|
799
803
|
//
|
|
800
804
|
|
|
801
|
-
|
|
802
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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-${
|
|
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 =
|
|
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(
|
|
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 =
|
|
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-
|
|
15
|
-
'data-[mosaic-placeholder-
|
|
16
|
-
'data-[mosaic-placeholder-
|
|
17
|
-
'data-[mosaic-placeholder-
|
|
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-
|
|
26
|
-
'group-data-[mosaic-placeholder-
|
|
27
|
-
'group-data-[mosaic-placeholder-
|
|
28
|
-
'group-data-[mosaic-placeholder-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
+
orientation='vertical'
|
|
66
66
|
autoScroll={viewport}
|
|
67
67
|
eventHandler={{ id: 'test', canDrop: () => true }}
|
|
68
68
|
debug={debugHandler}
|
|
69
69
|
>
|
|
70
|
-
<
|
|
71
|
-
<
|
|
72
|
-
|
|
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
|
-
|
|
96
|
+
orientation='vertical'
|
|
95
97
|
autoScroll={viewport}
|
|
96
98
|
eventHandler={{ id: 'test', canDrop: () => true }}
|
|
97
99
|
debug={debugHandler}
|
|
98
100
|
>
|
|
99
|
-
<
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
{
|
|
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(
|
|
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
|
-
|
|
55
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
...(
|
|
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
|
-
...(
|
|
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
|
|
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 =
|
|
188
|
+
VirtualStackInner.displayName = VIRTUAL_STACK_NAME;
|
|
180
189
|
|
|
181
190
|
const VirtualStack = VirtualStackInner as <TData = any>(
|
|
182
191
|
props: VirtualStackProps<TData> & { ref?: Ref<HTMLDivElement> },
|