@dxos/react-ui-list 0.7.4 → 0.7.5-feature-compute.4d9d99a

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.
@@ -3,11 +3,7 @@
3
3
  //
4
4
 
5
5
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
6
- import {
7
- draggable as pragmaticDraggable,
8
- dropTargetForElements,
9
- } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
10
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
6
+ import { draggable, dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
11
7
  import {
12
8
  attachInstruction,
13
9
  extractInstruction,
@@ -18,7 +14,7 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState, type FC
18
14
 
19
15
  import { S } from '@dxos/echo-schema';
20
16
  import { invariant } from '@dxos/invariant';
21
- import { Treegrid } from '@dxos/react-ui';
17
+ import { Treegrid, TreeItem as NaturalTreeItem } from '@dxos/react-ui';
22
18
  import {
23
19
  focusRing,
24
20
  ghostHover,
@@ -28,7 +24,6 @@ import {
28
24
  mx,
29
25
  } from '@dxos/react-ui-theme';
30
26
 
31
- import { DropIndicator } from './DropIndicator';
32
27
  import { useTree } from './TreeContext';
33
28
  import { TreeItemHeading } from './TreeItemHeading';
34
29
  import { TreeItemToggle } from './TreeItemToggle';
@@ -54,7 +49,13 @@ export type TreeItemProps<T = any> = {
54
49
  path: string[];
55
50
  last: boolean;
56
51
  draggable?: boolean;
57
- renderColumns?: FC<{ item: T; path: string[]; menuOpen: boolean; setMenuOpen: (open: boolean) => void }>;
52
+ renderColumns?: FC<{
53
+ item: T;
54
+ path: string[];
55
+ open: boolean;
56
+ menuOpen: boolean;
57
+ setMenuOpen: (open: boolean) => void;
58
+ }>;
58
59
  canDrop?: (source: TreeData, target: TreeData) => boolean;
59
60
  onOpenChange?: (params: { item: T; path: string[]; open: boolean }) => void;
60
61
  onSelect?: (params: { item: T; path: string[]; current: boolean; option: boolean }) => void;
@@ -64,7 +65,7 @@ export const RawTreeItem = <T = any,>({
64
65
  item,
65
66
  path: _path,
66
67
  last,
67
- draggable,
68
+ draggable: _draggable,
68
69
  renderColumns: Columns,
69
70
  canDrop,
70
71
  onOpenChange,
@@ -97,7 +98,7 @@ export const RawTreeItem = <T = any,>({
97
98
  }, []);
98
99
 
99
100
  useEffect(() => {
100
- if (!draggable) {
101
+ if (!_draggable) {
101
102
  return;
102
103
  }
103
104
 
@@ -105,7 +106,7 @@ export const RawTreeItem = <T = any,>({
105
106
 
106
107
  // https://atlassian.design/components/pragmatic-drag-and-drop/core-package/adapters/element/about
107
108
  return combine(
108
- pragmaticDraggable({
109
+ draggable({
109
110
  element: buttonRef.current,
110
111
  getInitialData: () => data,
111
112
  onDragStart: () => {
@@ -122,6 +123,7 @@ export const RawTreeItem = <T = any,>({
122
123
  }
123
124
  },
124
125
  }),
126
+ // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx
125
127
  dropTargetForElements({
126
128
  element: buttonRef.current,
127
129
  getData: ({ input, element }) => {
@@ -171,7 +173,7 @@ export const RawTreeItem = <T = any,>({
171
173
  },
172
174
  }),
173
175
  );
174
- }, [draggable, item, id, mode, path, open, canDrop]);
176
+ }, [_draggable, item, id, mode, path, open, canDrop]);
175
177
 
176
178
  // Cancel expand on unmount.
177
179
  useEffect(() => () => cancelExpand(), [cancelExpand]);
@@ -253,8 +255,8 @@ export const RawTreeItem = <T = any,>({
253
255
  onSelect={handleSelect}
254
256
  />
255
257
  </div>
256
- {Columns && <Columns item={item} path={path} menuOpen={menuOpen} setMenuOpen={setMenuOpen} />}
257
- {instruction && <DropIndicator instruction={instruction} gap={2} />}
258
+ {Columns && <Columns item={item} path={path} open={open} menuOpen={menuOpen} setMenuOpen={setMenuOpen} />}
259
+ {instruction && <NaturalTreeItem.DropIndicator instruction={instruction} gap={2} />}
258
260
  </Treegrid.Cell>
259
261
  </Treegrid.Row>
260
262
  {open &&
@@ -264,7 +266,7 @@ export const RawTreeItem = <T = any,>({
264
266
  item={item}
265
267
  path={path}
266
268
  last={index === items.length - 1}
267
- draggable={draggable}
269
+ draggable={_draggable}
268
270
  renderColumns={Columns}
269
271
  canDrop={canDrop}
270
272
  onOpenChange={onOpenChange}
@@ -1,11 +0,0 @@
1
- import { type Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/types';
2
- import React from 'react';
3
- export type DropIndicatorProps = {
4
- edge: Edge;
5
- gap?: number;
6
- };
7
- /**
8
- * This is a tailwind port of `@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box`
9
- */
10
- export declare const DropIndicator: ({ edge, gap }: DropIndicatorProps) => React.JSX.Element;
11
- //# sourceMappingURL=DropIndicator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropIndicator.d.ts","sourceRoot":"","sources":["../../../../../src/components/List/DropIndicator.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,gDAAgD,CAAC;AAC3E,OAAO,KAAkD,MAAM,OAAO,CAAC;AA6BvE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,kBAAuB,kBAAkB,sBA0BlE,CAAC"}
@@ -1,8 +0,0 @@
1
- import { type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
2
- import React from 'react';
3
- export type DropIndicatorProps = {
4
- instruction: Instruction;
5
- gap?: number;
6
- };
7
- export declare const DropIndicator: ({ instruction, gap }: DropIndicatorProps) => React.JSX.Element | null;
8
- //# sourceMappingURL=DropIndicator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropIndicator.d.ts","sourceRoot":"","sources":["../../../../../src/components/Tree/DropIndicator.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oDAAoD,CAAC;AACtF,OAAO,KAAkD,MAAM,OAAO,CAAC;AAoCvE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,WAAW,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,aAAa,yBAA8B,kBAAkB,6BA+BzE,CAAC"}
@@ -1,69 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Edge } from '@atlaskit/pragmatic-drag-and-drop-hitbox/types';
6
- import React, { type CSSProperties, type HTMLAttributes } from 'react';
7
-
8
- import { mx } from '@dxos/react-ui-theme';
9
-
10
- type Orientation = 'horizontal' | 'vertical';
11
-
12
- const edgeToOrientationMap: Record<Edge, Orientation> = {
13
- top: 'horizontal',
14
- bottom: 'horizontal',
15
- left: 'vertical',
16
- right: 'vertical',
17
- };
18
-
19
- const orientationStyles: Record<Orientation, HTMLAttributes<HTMLElement>['className']> = {
20
- horizontal: 'h-[--line-thickness] left-[--terminal-radius] right-0 before:left-[--negative-terminal-size]',
21
- vertical: 'w-[--line-thickness] top-[--terminal-radius] bottom-0 before:top-[--negative-terminal-size]',
22
- };
23
-
24
- const edgeStyles: Record<Edge, HTMLAttributes<HTMLElement>['className']> = {
25
- top: 'top-[--line-offset] before:top-[--offset-terminal]',
26
- right: 'right-[--line-offset] before:right-[--offset-terminal]',
27
- bottom: 'bottom-[--line-offset] before:bottom-[--offset-terminal]',
28
- left: 'left-[--line-offset] before:left-[--offset-terminal]',
29
- };
30
-
31
- const strokeSize = 2;
32
- const terminalSize = 8;
33
- const offsetToAlignTerminalWithLine = (strokeSize - terminalSize) / 2;
34
-
35
- export type DropIndicatorProps = {
36
- edge: Edge;
37
- gap?: number;
38
- };
39
-
40
- /**
41
- * This is a tailwind port of `@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box`
42
- */
43
- export const DropIndicator = ({ edge, gap = 0 }: DropIndicatorProps) => {
44
- const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize}px))`;
45
-
46
- const orientation = edgeToOrientationMap[edge];
47
-
48
- return (
49
- <div
50
- style={
51
- {
52
- '--line-thickness': `${strokeSize}px`,
53
- '--line-offset': `${lineOffset}`,
54
- '--terminal-size': `${terminalSize}px`,
55
- '--terminal-radius': `${terminalSize / 2}px`,
56
- '--negative-terminal-size': `-${terminalSize}px`,
57
- '--offset-terminal': `${offsetToAlignTerminalWithLine}px`,
58
- } as CSSProperties
59
- }
60
- className={mx(
61
- 'absolute z-10 pointer-events-none bg-blue-700',
62
- "before:content-[''] before:w-[--terminal-size] before:h-[--terminal-size] box-border before:absolute",
63
- 'before:border-[length:--line-thickness] before:border-solid before:border-blue-700 before:rounded-full',
64
- orientationStyles[orientation],
65
- edgeStyles[edge],
66
- )}
67
- ></div>
68
- );
69
- };
@@ -1,78 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type Instruction } from '@atlaskit/pragmatic-drag-and-drop-hitbox/tree-item';
6
- import React, { type HTMLAttributes, type CSSProperties } from 'react';
7
-
8
- import { mx } from '@dxos/react-ui-theme';
9
-
10
- // Tree item hitbox
11
- // https://github.com/atlassian/pragmatic-drag-and-drop/blob/main/packages/hitbox/constellation/index/about.mdx#tree-item
12
-
13
- type InstructionType = Exclude<Instruction, { type: 'instruction-blocked' }>['type'];
14
- type Orientation = 'sibling' | 'child';
15
-
16
- const edgeToOrientationMap: Record<InstructionType, Orientation> = {
17
- 'reorder-above': 'sibling',
18
- 'reorder-below': 'sibling',
19
- 'make-child': 'child',
20
- reparent: 'child',
21
- };
22
-
23
- const orientationStyles: Record<Orientation, HTMLAttributes<HTMLElement>['className']> = {
24
- // TODO(wittjosiah): Stop using left/right here.
25
- sibling:
26
- 'bs-[--line-thickness] left-[--horizontal-indent] right-0 bg-accentSurface before:left-[--negative-terminal-size]',
27
- child: 'is-full block-start-0 block-end-0 border-[length:--line-thickness] before:invisible',
28
- };
29
-
30
- const instructionStyles: Record<InstructionType, HTMLAttributes<HTMLElement>['className']> = {
31
- 'reorder-above': 'block-start-[--line-offset] before:block-start-[--offset-terminal]',
32
- 'reorder-below': 'block-end-[--line-offset] before:block-end-[--offset-terminal]',
33
- 'make-child': 'border-accentSurface',
34
- // TODO(wittjosiah): This is not occurring in the current implementation.
35
- reparent: '',
36
- };
37
-
38
- const strokeSize = 2;
39
- const terminalSize = 8;
40
- const offsetToAlignTerminalWithLine = (strokeSize - terminalSize) / 2;
41
-
42
- export type DropIndicatorProps = {
43
- instruction: Instruction;
44
- gap?: number;
45
- };
46
-
47
- export const DropIndicator = ({ instruction, gap = 0 }: DropIndicatorProps) => {
48
- const lineOffset = `calc(-0.5 * (${gap}px + ${strokeSize}px))`;
49
- const isBlocked = instruction.type === 'instruction-blocked';
50
- const desiredInstruction = isBlocked ? instruction.desired : instruction;
51
- const orientation = edgeToOrientationMap[desiredInstruction.type];
52
- if (isBlocked) {
53
- return null;
54
- }
55
-
56
- return (
57
- <div
58
- style={
59
- {
60
- '--line-thickness': `${strokeSize}px`,
61
- '--line-offset': `${lineOffset}`,
62
- '--terminal-size': `${terminalSize}px`,
63
- '--terminal-radius': `${terminalSize / 2}px`,
64
- '--negative-terminal-size': `-${terminalSize}px`,
65
- '--offset-terminal': `${offsetToAlignTerminalWithLine}px`,
66
- '--horizontal-indent': `${desiredInstruction.currentLevel * desiredInstruction.indentPerLevel + 4}px`,
67
- } as CSSProperties
68
- }
69
- className={mx(
70
- 'absolute z-10 pointer-events-none',
71
- 'before:is-[--terminal-size] before:bs-[--terminal-size] box-border before:absolute',
72
- 'before:border-[length:--line-thickness] before:border-solid before:border-accentSurface before:rounded-full',
73
- orientationStyles[orientation],
74
- instructionStyles[desiredInstruction.type],
75
- )}
76
- ></div>
77
- );
78
- };