@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-mosaic",
3
- "version": "0.8.4-main.bc674ce",
3
+ "version": "0.8.4-main.ef1bc66f44",
4
4
  "description": "Modular UI components.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -49,42 +49,40 @@
49
49
  "@radix-ui/react-use-controllable-state": "1.1.0",
50
50
  "@tanstack/react-virtual": "^3.13.18",
51
51
  "bind-event-listener": "^3.0.0",
52
- "overlayscrollbars": "^2.13.0",
53
- "overlayscrollbars-react": "^0.5.6",
54
- "@dxos/async": "0.8.4-main.bc674ce",
55
- "@dxos/echo": "0.8.4-main.bc674ce",
56
- "@dxos/invariant": "0.8.4-main.bc674ce",
57
- "@dxos/keys": "0.8.4-main.bc674ce",
58
- "@dxos/log": "0.8.4-main.bc674ce",
59
- "@dxos/react-client": "0.8.4-main.bc674ce",
60
- "@dxos/react-ui-dnd": "0.8.4-main.bc674ce",
61
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.bc674ce",
62
- "@dxos/ui-theme": "0.8.4-main.bc674ce",
63
- "@dxos/util": "0.8.4-main.bc674ce"
52
+ "@dxos/async": "0.8.4-main.ef1bc66f44",
53
+ "@dxos/echo": "0.8.4-main.ef1bc66f44",
54
+ "@dxos/invariant": "0.8.4-main.ef1bc66f44",
55
+ "@dxos/keys": "0.8.4-main.ef1bc66f44",
56
+ "@dxos/log": "0.8.4-main.ef1bc66f44",
57
+ "@dxos/react-client": "0.8.4-main.ef1bc66f44",
58
+ "@dxos/react-ui-dnd": "0.8.4-main.ef1bc66f44",
59
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.ef1bc66f44",
60
+ "@dxos/ui-theme": "0.8.4-main.ef1bc66f44",
61
+ "@dxos/util": "0.8.4-main.ef1bc66f44"
64
62
  },
65
63
  "devDependencies": {
66
64
  "@types/react": "~19.2.7",
67
65
  "@types/react-dom": "~19.2.3",
68
- "effect": "3.19.11",
66
+ "effect": "3.19.16",
69
67
  "react": "~19.2.3",
70
68
  "react-dom": "~19.2.3",
71
69
  "vite": "7.1.9",
72
- "@dxos/random": "0.8.4-main.bc674ce",
73
- "@dxos/react-ui": "0.8.4-main.bc674ce",
74
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.bc674ce",
75
- "@dxos/schema": "0.8.4-main.bc674ce",
76
- "@dxos/storybook-utils": "0.8.4-main.bc674ce",
77
- "@dxos/test-utils": "0.8.4-main.bc674ce",
78
- "@dxos/types": "0.8.4-main.bc674ce",
79
- "@dxos/ui-theme": "0.8.4-main.bc674ce"
70
+ "@dxos/random": "0.8.4-main.ef1bc66f44",
71
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.ef1bc66f44",
72
+ "@dxos/react-ui": "0.8.4-main.ef1bc66f44",
73
+ "@dxos/schema": "0.8.4-main.ef1bc66f44",
74
+ "@dxos/test-utils": "0.8.4-main.ef1bc66f44",
75
+ "@dxos/ui-theme": "0.8.4-main.ef1bc66f44",
76
+ "@dxos/types": "0.8.4-main.ef1bc66f44",
77
+ "@dxos/storybook-utils": "0.8.4-main.ef1bc66f44"
80
78
  },
81
79
  "peerDependencies": {
82
- "effect": "3.19.11",
80
+ "effect": "3.19.16",
83
81
  "react": "~19.2.3",
84
82
  "react-dom": "~19.2.3",
85
- "@dxos/random": "0.8.4-main.bc674ce",
86
- "@dxos/ui-theme": "0.8.4-main.bc674ce",
87
- "@dxos/react-ui": "0.8.4-main.bc674ce"
83
+ "@dxos/react-ui": "0.8.4-main.ef1bc66f44",
84
+ "@dxos/random": "0.8.4-main.ef1bc66f44",
85
+ "@dxos/ui-theme": "0.8.4-main.ef1bc66f44"
88
86
  },
89
87
  "publishConfig": {
90
88
  "access": "public"
@@ -3,26 +3,36 @@
3
3
  //
4
4
 
5
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React from 'react';
6
+ import React, { useMemo } from 'react';
7
7
 
8
8
  import { type Database, Filter, Obj, Ref } from '@dxos/echo';
9
+ import { invariant } from '@dxos/invariant';
9
10
  import { faker } from '@dxos/random';
10
11
  import { useQuery } from '@dxos/react-client/echo';
11
12
  import { useClientStory, withClientProvider } from '@dxos/react-client/testing';
12
13
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
13
14
  import { mx } from '@dxos/ui-theme';
14
15
 
15
- import { Board, TestColumn, TestItem } from '../../testing';
16
+ import { TestColumn, TestItem } from '../../testing';
17
+ import { translations } from '../../translations';
16
18
  import { Focus } from '../Focus';
19
+ import { Mosaic } from '../Mosaic';
17
20
 
18
- import { Mosaic } from './Mosaic';
21
+ import { Board, type BoardModel } from './Board';
22
+ import { DefaultBoardColumn } from './Column';
19
23
 
20
24
  faker.seed(999);
21
25
 
26
+ // TODO(burdon): Create model with Kanban, Pipeline, and Hierarchical implementations.
27
+ // TODO(burdon): Factor out Board to react-ui-kanban (replace kanban).
28
+ // TODO(burdon): Mobile implementation.
29
+ // TODO(burdon): Tests/stories (sanity check).
30
+
22
31
  const createTestData = (db: Database.Database, columnCount: number) => {
23
32
  Array.from({ length: columnCount }).forEach((_, i) => {
24
33
  db.add(
25
34
  Obj.make(TestColumn, {
35
+ name: `Column ${i}`,
26
36
  items: Array.from({ length: faker.number.int({ min: 0, max: 20 }) }).map((_, j) => {
27
37
  const item = db.add(
28
38
  Obj.make(TestItem, {
@@ -46,7 +56,40 @@ type StoryProps = {
46
56
 
47
57
  const DefaultStory = ({ debug = false }: StoryProps) => {
48
58
  const { space } = useClientStory();
59
+
60
+ // TODO(burdon): Reactivity check.
49
61
  const columns = useQuery(space?.db, Filter.type(TestColumn));
62
+ const model = useMemo<BoardModel<TestColumn, TestItem>>(() => {
63
+ return {
64
+ isColumn: (obj: Obj.Unknown): obj is TestColumn => Obj.instanceOf(TestColumn, obj),
65
+ isItem: (obj: Obj.Unknown): obj is TestItem => Obj.instanceOf(TestItem, obj),
66
+ getColumns: () => columns,
67
+ getItems: (column: TestColumn) => column.items,
68
+ onItemDelete: (column: TestColumn, current: TestItem) => {
69
+ const idx = model.getItems(column).findIndex((item) => item.target?.id === current?.id);
70
+ if (idx !== -1) {
71
+ Obj.change(column, (mutableColumn) => {
72
+ model.getItems(mutableColumn).splice(idx, 1);
73
+ });
74
+ }
75
+ },
76
+ onItemCreate: async (column: TestColumn) => {
77
+ invariant(space);
78
+ const item = space.db.add(
79
+ Obj.make(TestItem, {
80
+ name: faker.lorem.sentence(3),
81
+ description: faker.lorem.paragraph(1),
82
+ }),
83
+ );
84
+
85
+ Obj.change(column, (column) => {
86
+ model.getItems(column).push(Ref.make(item));
87
+ });
88
+
89
+ return item;
90
+ },
91
+ } satisfies BoardModel<TestColumn, TestItem>;
92
+ }, [space, columns]);
50
93
 
51
94
  if (columns.length === 0) {
52
95
  return <></>;
@@ -54,8 +97,8 @@ const DefaultStory = ({ debug = false }: StoryProps) => {
54
97
 
55
98
  return (
56
99
  <Mosaic.Root asChild debug={debug}>
57
- <div className={mx('grid overflow-hidden', debug && 'grid-cols-[1fr_20rem] gap-2')}>
58
- <Board.Root id='board' columns={columns} debug={debug} />
100
+ <div role='none' className={mx('grid md:p-2 overflow-hidden', debug && 'grid-cols-[1fr_20rem] gap-2')}>
101
+ <Board.Root id='board' model={model} debug={debug} Tile={DefaultBoardColumn} />
59
102
  {debug && (
60
103
  <Focus.Group classNames='flex flex-col gap-2 overflow-hidden'>
61
104
  <Board.Debug classNames='p-2' />
@@ -67,10 +110,10 @@ const DefaultStory = ({ debug = false }: StoryProps) => {
67
110
  };
68
111
 
69
112
  const meta = {
70
- title: 'ui/react-ui-mosaic/Mosaic',
113
+ title: 'ui/react-ui-mosaic/Board',
71
114
  render: DefaultStory,
72
115
  decorators: [
73
- withTheme,
116
+ withTheme({ platform: 'desktop' }),
74
117
  withLayout({ layout: 'fullscreen' }),
75
118
  withClientProvider({
76
119
  types: [TestColumn, TestItem],
@@ -84,6 +127,7 @@ const meta = {
84
127
  ],
85
128
  parameters: {
86
129
  layout: 'fullscreen',
130
+ translations,
87
131
  },
88
132
  argTypes: {
89
133
  columns: {
@@ -101,7 +145,7 @@ type Story = StoryObj<typeof meta>;
101
145
 
102
146
  export const Default: Story = {
103
147
  args: {
104
- columns: 5,
148
+ columns: 8,
105
149
  },
106
150
  };
107
151
 
@@ -0,0 +1,166 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { createContext } from '@radix-ui/react-context';
6
+ import React, { type ReactElement, type Ref as ReactRef, forwardRef, useRef, useState } from 'react';
7
+
8
+ import { type Obj, type Ref } from '@dxos/echo';
9
+ import { Layout, ScrollArea, type ThemedClassName } from '@dxos/react-ui';
10
+ import { Json } from '@dxos/react-ui-syntax-highlighter';
11
+ import { mx } from '@dxos/ui-theme';
12
+
13
+ import { useContainerDebug, useEventHandlerAdapter } from '../../hooks';
14
+ import { Focus } from '../Focus';
15
+ import { Mosaic, type MosiacPlaceholderProps, mosaicStyles, useMosaic } from '../Mosaic';
16
+ import { type StackProps } from '../Stack';
17
+
18
+ import { BoardColumn, type BoardColumnProps, DefaultBoardColumn } from './Column';
19
+ import { BoardItem, type BoardItemProps } from './Item';
20
+
21
+ //
22
+ // Model
23
+ //
24
+
25
+ export interface BoardModel<TColumn extends Obj.Unknown = any, TItem extends Obj.Unknown = any> {
26
+ isColumn: (obj: Obj.Unknown) => obj is TColumn;
27
+ isItem: (obj: Obj.Unknown) => obj is TItem;
28
+ // TODO(burdon): Normalize Column/Item object vs refs?
29
+ getColumns: () => TColumn[];
30
+ getItems: (column: TColumn) => Ref.Ref<TItem>[];
31
+ onColumnDelete?: (column: TColumn) => void;
32
+ onColumnCreate?: () => Promise<TColumn>;
33
+ onItemDelete?: (column: TColumn, item: TItem) => void;
34
+ onItemCreate?: (column: TColumn) => Promise<TItem>;
35
+ }
36
+
37
+ //
38
+ // Context
39
+ //
40
+
41
+ const BOARD_NAME = 'Board';
42
+
43
+ type BoardContextValue<TColumn extends Obj.Unknown = any, TItem extends Obj.Unknown = any> = {
44
+ model: BoardModel<TColumn, TItem>;
45
+ };
46
+
47
+ /**
48
+ * @internal
49
+ */
50
+ export const [BoardContextProvider, useBoardContext] = createContext<BoardContextValue>(BOARD_NAME);
51
+
52
+ //
53
+ // Root
54
+ //
55
+
56
+ const BOARD_ROOT_NAME = 'Board.Root';
57
+
58
+ type BoardRootProps<TColumn extends Obj.Unknown = any, TItem extends Obj.Unknown = any> = ThemedClassName<
59
+ {
60
+ id: string;
61
+ debug?: boolean;
62
+ Tile?: StackProps<TColumn>['Tile'];
63
+ } & BoardContextValue<TColumn, TItem>
64
+ >;
65
+
66
+ const BoardRootInner = forwardRef<HTMLDivElement, BoardRootProps>(
67
+ ({ classNames, id, model, debug, Tile = DefaultBoardColumn }, forwardedRef) => {
68
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
69
+ const [viewport, setViewport] = useState<HTMLElement | null>(null);
70
+
71
+ const items = model.getColumns();
72
+ const eventHandler = useEventHandlerAdapter({
73
+ id,
74
+ items,
75
+ getId: (data) => data.id,
76
+ get: (data) => data,
77
+ make: (object) => object,
78
+ canDrop: ({ source }) => model.isColumn(source.data),
79
+ });
80
+
81
+ return (
82
+ <BoardContextProvider model={model}>
83
+ <Layout.Main ref={forwardedRef} classNames={mx('border-red-500', classNames)}>
84
+ <Focus.Group asChild orientation='horizontal'>
85
+ <Mosaic.Container
86
+ asChild
87
+ withFocus
88
+ orientation='horizontal'
89
+ autoScroll={viewport}
90
+ eventHandler={eventHandler}
91
+ debug={debugHandler}
92
+ >
93
+ <ScrollArea.Root orientation='horizontal' classNames='md:pbs-3' margin padding>
94
+ <ScrollArea.Viewport classNames='snap-mandatory snap-x md:snap-none' ref={setViewport}>
95
+ <Mosaic.Stack items={items} getId={(item) => item.id} Tile={Tile} debug={debug} />
96
+ </ScrollArea.Viewport>
97
+ </ScrollArea.Root>
98
+ </Mosaic.Container>
99
+ </Focus.Group>
100
+ <DebugInfo />
101
+ </Layout.Main>
102
+ </BoardContextProvider>
103
+ );
104
+ },
105
+ );
106
+
107
+ BoardRootInner.displayName = BOARD_ROOT_NAME;
108
+
109
+ const BoardRoot = BoardRootInner as <TColumn extends Obj.Unknown>(
110
+ props: BoardRootProps<TColumn> & { ref?: ReactRef<HTMLDivElement> },
111
+ ) => ReactElement;
112
+
113
+ //
114
+ // Placeholder
115
+ //
116
+
117
+ const BOARD_PLACEHOLDER_NAME = 'Board.Placeholder';
118
+
119
+ const BoardPlaceholder = (props: MosiacPlaceholderProps<number>) => {
120
+ return (
121
+ <Mosaic.Placeholder {...props} classNames={mosaicStyles.placeholder.root}>
122
+ <div
123
+ className={mx(
124
+ 'flex bs-full border border-dashed border-separator rounded-sm',
125
+ mosaicStyles.placeholder.content,
126
+ )}
127
+ />
128
+ </Mosaic.Placeholder>
129
+ );
130
+ };
131
+
132
+ BoardPlaceholder.displayName = BOARD_PLACEHOLDER_NAME;
133
+
134
+ //
135
+ // Debug
136
+ //
137
+
138
+ const BOARD_DEBUG_NAME = 'Board.Debug';
139
+
140
+ export const BoardDebug = forwardRef<HTMLDivElement, ThemedClassName>(({ classNames }, forwardedRef) => {
141
+ const { containers, dragging } = useMosaic(BOARD_DEBUG_NAME);
142
+ const counter = useRef(0);
143
+ return (
144
+ <Json
145
+ data={{ containers, dragging, count: counter.current++ }}
146
+ classNames={mx('text-xs', classNames)}
147
+ ref={forwardedRef}
148
+ />
149
+ );
150
+ });
151
+
152
+ BoardDebug.displayName = BOARD_DEBUG_NAME;
153
+
154
+ //
155
+ // Board
156
+ //
157
+
158
+ export const Board = {
159
+ Root: BoardRoot,
160
+ Column: BoardColumn,
161
+ Item: BoardItem,
162
+ Placeholder: BoardPlaceholder,
163
+ Debug: BoardDebug,
164
+ };
165
+
166
+ export type { BoardRootProps, BoardColumnProps, BoardItemProps };
@@ -0,0 +1,253 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, {
6
+ type PropsWithChildren,
7
+ type ReactElement,
8
+ type Ref as ReactRef,
9
+ type RefObject,
10
+ forwardRef,
11
+ useMemo,
12
+ useRef,
13
+ useState,
14
+ } from 'react';
15
+
16
+ import { Obj, Ref } from '@dxos/echo';
17
+ import { useObject } from '@dxos/react-client/echo';
18
+ import { IconButton, ScrollArea, type ThemedClassName, Toolbar, useTranslation } from '@dxos/react-ui';
19
+ import { mx } from '@dxos/ui-theme';
20
+ import { isNonNullable } from '@dxos/util';
21
+
22
+ import { useContainerDebug, useEventHandlerAdapter } from '../../hooks';
23
+ import { translationKey } from '../../translations';
24
+ import { Card, type CardMenuProps } from '../Card';
25
+ import { Focus } from '../Focus';
26
+ import { Mosaic, type MosaicContainerProps, type MosaicTileProps } from '../Mosaic';
27
+ import { type StackProps } from '../Stack';
28
+
29
+ import { useBoardContext } from './Board';
30
+ import { BoardItem } from './Item';
31
+
32
+ //
33
+ // Column
34
+ //
35
+
36
+ const BOARD_COLUMN_NAME = 'Board.Column';
37
+
38
+ type BoardColumnProps<TColumn extends Obj.Unknown = any> = Pick<
39
+ MosaicTileProps<TColumn>,
40
+ 'classNames' | 'location' | 'data' | 'debug'
41
+ >;
42
+
43
+ type BoardColumnRootInnerProps<TColumn extends Obj.Unknown = any> = BoardColumnProps<TColumn> & {
44
+ dragHandleRef: RefObject<HTMLButtonElement | null>;
45
+ };
46
+
47
+ const BoardColumnRootInner = forwardRef<HTMLDivElement, PropsWithChildren<BoardColumnRootInnerProps>>(
48
+ ({ classNames, children, location, data, debug, dragHandleRef }, forwardedRef) => {
49
+ return (
50
+ <Mosaic.Tile
51
+ asChild
52
+ location={location}
53
+ id={data.id}
54
+ data={data}
55
+ debug={debug}
56
+ dragHandle={dragHandleRef.current}
57
+ >
58
+ <Focus.Group
59
+ classNames={mx(
60
+ // NOTE: Reserves 2px for outer Focus.Group border.
61
+ 'bs-full overflow-hidden is-[calc(100vw-2px)] md:is-card-default-width snap-center bg-deckSurface',
62
+ classNames,
63
+ )}
64
+ ref={forwardedRef}
65
+ >
66
+ {children}
67
+ </Focus.Group>
68
+ </Mosaic.Tile>
69
+ );
70
+ },
71
+ );
72
+
73
+ BoardColumnRootInner.displayName = BOARD_COLUMN_NAME;
74
+
75
+ const BoardColumnRootImpl = forwardRef<HTMLDivElement, BoardColumnProps>((props, forwardedRef) => {
76
+ const dragHandleRef = useRef<HTMLButtonElement>(null);
77
+ return <BoardColumnRootInner {...props} dragHandleRef={dragHandleRef} ref={forwardedRef} />;
78
+ });
79
+
80
+ BoardColumnRootImpl.displayName = 'Board.Column.Root';
81
+
82
+ const BoardColumnRoot = BoardColumnRootImpl as <TColumn extends Obj.Unknown = any>(
83
+ props: BoardColumnProps<TColumn> & { ref?: ReactRef<HTMLDivElement> },
84
+ ) => ReactElement;
85
+
86
+ //
87
+ // Column Header
88
+ //
89
+
90
+ const BOARD_COLUMN_HEADER_NAME = 'Board.Column.Header';
91
+
92
+ type BoardColumnHeaderProps = ThemedClassName<{ label: string; dragHandleRef: ReactRef<HTMLButtonElement> }>;
93
+
94
+ const BoardColumnHeader = forwardRef<HTMLDivElement, BoardColumnHeaderProps>(
95
+ ({ classNames, label, dragHandleRef }, forwardedRef) => {
96
+ return (
97
+ <Card.Toolbar classNames={classNames} ref={forwardedRef}>
98
+ <Card.DragHandle ref={dragHandleRef} />
99
+ <Card.Title>{label}</Card.Title>
100
+ <Card.Menu items={[]} />
101
+ </Card.Toolbar>
102
+ );
103
+ },
104
+ );
105
+
106
+ BoardColumnHeader.displayName = BOARD_COLUMN_HEADER_NAME;
107
+
108
+ //
109
+ // Column Body
110
+ //
111
+
112
+ const BOARD_COLUMN_BODY_NAME = 'Board.Column.Body';
113
+
114
+ type BoardColumnBodyProps = Pick<BoardColumnProps, 'data'> & {
115
+ Tile?: StackProps<Ref.Ref<Obj.Unknown>>['Tile'];
116
+ } & Pick<MosaicContainerProps, 'debug'>;
117
+
118
+ const BoardColumnBody = ({ data, Tile = BoardItem, debug }: BoardColumnBodyProps) => {
119
+ const { t } = useTranslation(translationKey);
120
+ const { model } = useBoardContext(BOARD_COLUMN_BODY_NAME);
121
+ const [column, updateColumn] = useObject(data);
122
+ const [viewport, setViewport] = useState<HTMLElement | null>(null);
123
+
124
+ const eventHandler = useEventHandlerAdapter<Ref.Unknown>({
125
+ id: data.id,
126
+ items: model.getItems(column),
127
+ getId: (data) => data.dxn.toString(),
128
+ get: (data) => data.target!,
129
+ make: (object) => Ref.make(object),
130
+ canDrop: ({ source }) => (source.data.target ? model.isItem(source.data.target) : false),
131
+ onChange: (mutator) => updateColumn((column) => mutator(model.getItems(column))),
132
+ });
133
+
134
+ // Context menu for items.
135
+ const menuItems = useMemo<NonNullable<CardMenuProps<Obj.Unknown>['items']>>(
136
+ () =>
137
+ [
138
+ model.onItemDelete && {
139
+ label: t('delete menu label'),
140
+ onClick: (obj: Obj.Unknown) => {
141
+ model.onItemDelete?.(data, obj);
142
+ },
143
+ },
144
+ ].filter(isNonNullable),
145
+ [model.onItemDelete, data, t],
146
+ );
147
+
148
+ return (
149
+ <Card.Context value={{ menuItems }}>
150
+ <Mosaic.Container
151
+ asChild
152
+ withFocus
153
+ orientation='vertical'
154
+ autoScroll={viewport}
155
+ eventHandler={eventHandler}
156
+ debug={debug}
157
+ >
158
+ <ScrollArea.Root orientation='vertical' thin margin padding>
159
+ <ScrollArea.Viewport classNames='snap-y md:snap-none' ref={setViewport}>
160
+ <Mosaic.Stack items={model.getItems(column)} getId={(data) => data.dxn.toString()} Tile={Tile} />
161
+ </ScrollArea.Viewport>
162
+ </ScrollArea.Root>
163
+ </Mosaic.Container>
164
+ </Card.Context>
165
+ );
166
+ };
167
+
168
+ BoardColumnBody.displayName = BOARD_COLUMN_BODY_NAME;
169
+
170
+ //
171
+ // Column Footer
172
+ //
173
+
174
+ const BOARD_COLUMN_FOOTER_NAME = 'Board.Column.Footer';
175
+
176
+ type BoardColumnFooterProps = ThemedClassName;
177
+
178
+ const BoardColumnFooter = forwardRef<HTMLDivElement, BoardColumnFooterProps>(({ classNames }, forwardedRef) => {
179
+ const { t } = useTranslation(translationKey);
180
+ const { model } = useBoardContext(BOARD_COLUMN_FOOTER_NAME);
181
+
182
+ return (
183
+ <Toolbar.Root classNames={mx('rounded-b-sm', classNames)} ref={forwardedRef}>
184
+ {model.onItemCreate && (
185
+ <IconButton
186
+ classNames='group-hover/column:opacity-100 opacity-0 transition transition-opacity duration-500'
187
+ variant='ghost'
188
+ icon='ph--plus--regular'
189
+ iconOnly
190
+ label={t('add item label')}
191
+ />
192
+ )}
193
+ </Toolbar.Root>
194
+ );
195
+ });
196
+
197
+ BoardColumnFooter.displayName = BOARD_COLUMN_FOOTER_NAME;
198
+
199
+ //
200
+ // DefaultBoardColumn
201
+ //
202
+
203
+ const BOARD_DEFAULT_COLUMN_NAME = 'Board.DefaultColumn';
204
+
205
+ type DefaultBoardColumnProps = BoardColumnProps & Pick<BoardColumnBodyProps, 'Tile'>;
206
+
207
+ const DefaultBoardColumn = forwardRef<HTMLDivElement, DefaultBoardColumnProps>(
208
+ ({ classNames, location, data, debug, Tile = BoardItem }, forwardedRef) => {
209
+ const [DebugInfo, debugHandler] = useContainerDebug(debug);
210
+ const dragHandleRef = useRef<HTMLButtonElement>(null);
211
+
212
+ return (
213
+ <BoardColumnRootInner location={location} data={data} dragHandleRef={dragHandleRef} ref={forwardedRef}>
214
+ <div
215
+ role='none'
216
+ className={mx(
217
+ 'group/column grid bs-full overflow-hidden',
218
+ debug
219
+ ? 'grid-rows-[var(--rail-action)_1fr_20rem]'
220
+ : 'grid-rows-[var(--rail-action)_1fr_var(--rail-action)]',
221
+ classNames,
222
+ )}
223
+ >
224
+ <BoardColumnHeader
225
+ classNames='border-be border-separator'
226
+ label={Obj.getLabel(data) ?? data.id}
227
+ dragHandleRef={dragHandleRef}
228
+ />
229
+ <BoardColumnBody data={data} debug={debugHandler} Tile={Tile} />
230
+ <div role='none' className='flex flex-col'>
231
+ <BoardColumnFooter classNames='border-bs border-separator' />
232
+ <DebugInfo />
233
+ </div>
234
+ </div>
235
+ </BoardColumnRootInner>
236
+ );
237
+ },
238
+ );
239
+
240
+ DefaultBoardColumn.displayName = BOARD_DEFAULT_COLUMN_NAME;
241
+
242
+ //
243
+ // BoardColumn
244
+ //
245
+
246
+ const BoardColumn = {
247
+ Root: BoardColumnRoot,
248
+ Header: BoardColumnHeader,
249
+ Body: BoardColumnBody,
250
+ Footer: BoardColumnFooter,
251
+ };
252
+
253
+ export { BoardColumn, DefaultBoardColumn, type BoardColumnProps };
@@ -0,0 +1,80 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { useComposedRefs } from '@radix-ui/react-compose-refs';
6
+ import React, { type ReactElement, type Ref as ReactRef, forwardRef, useRef } from 'react';
7
+
8
+ import { Obj, type Ref } from '@dxos/echo';
9
+ import { Tag } from '@dxos/react-ui';
10
+ import { getHashStyles } from '@dxos/ui-theme';
11
+
12
+ import { Card } from '../Card';
13
+ import { Focus } from '../Focus';
14
+ import { Mosaic, type MosaicTileProps } from '../Mosaic';
15
+
16
+ //
17
+ // Item
18
+ //
19
+
20
+ const BOARD_ITEM_NAME = 'Board.Item';
21
+
22
+ type BoardItemProps<TItem extends Obj.Unknown = any> = Pick<
23
+ MosaicTileProps<Ref.Ref<TItem>>,
24
+ 'classNames' | 'location' | 'data' | 'debug'
25
+ >;
26
+
27
+ const BoardItemInner = forwardRef<HTMLDivElement, BoardItemProps>(
28
+ ({ classNames, data: ref, location, debug }, forwardedRef) => {
29
+ const rootRef = useRef<HTMLDivElement>(null);
30
+ const composedRef = useComposedRefs<HTMLDivElement>(rootRef, forwardedRef);
31
+ const dragHandleRef = useRef<HTMLButtonElement>(null);
32
+ const object = ref.target;
33
+ if (!object) {
34
+ return null;
35
+ }
36
+
37
+ const label = Obj.getLabel(object);
38
+ const description = Obj.getDescription(object);
39
+
40
+ return (
41
+ <Mosaic.Tile
42
+ asChild
43
+ dragHandle={dragHandleRef.current}
44
+ id={ref.dxn.toString()}
45
+ data={ref}
46
+ location={location}
47
+ debug={debug}
48
+ >
49
+ <Focus.Group asChild>
50
+ <Card.Root classNames={classNames} onClick={() => rootRef.current?.focus()} ref={composedRef}>
51
+ <Card.Toolbar>
52
+ <Card.DragHandle ref={dragHandleRef} />
53
+ <Card.Title>{label}</Card.Title>
54
+ <Card.Menu context={object} />
55
+ </Card.Toolbar>
56
+ {/* TODO(burdon): Replace with surface. */}
57
+ <Card.Row icon='ph--note--regular' classNames='text-description'>
58
+ {description}
59
+ </Card.Row>
60
+ <Card.Row icon='ph--tag--regular'>
61
+ {label && (
62
+ <div role='none' className='shrink-0 flex gap-1 items-center text-xs'>
63
+ <Tag palette={getHashStyles(label).hue}>{label}</Tag>
64
+ </div>
65
+ )}
66
+ </Card.Row>
67
+ </Card.Root>
68
+ </Focus.Group>
69
+ </Mosaic.Tile>
70
+ );
71
+ },
72
+ );
73
+
74
+ BoardItemInner.displayName = BOARD_ITEM_NAME;
75
+
76
+ const BoardItem = BoardItemInner as <TItem extends Obj.Unknown = any>(
77
+ props: BoardItemProps<TItem> & { ref?: ReactRef<HTMLDivElement> },
78
+ ) => ReactElement;
79
+
80
+ export { BoardItem, type BoardItemProps };