Skip to content

Commit 7907671

Browse files
wip
1 parent 58bf8d7 commit 7907671

File tree

7 files changed

+263
-122
lines changed

7 files changed

+263
-122
lines changed

src/frontend/apps/impress/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"stylelint-config-standard": "36.0.1",
7272
"stylelint-prettier": "5.0.2",
7373
"typescript": "*",
74+
"use-resize-observer": "^9.1.0",
7475
"webpack": "5.97.1",
7576
"workbox-webpack-plugin": "7.1.0"
7677
}

src/frontend/apps/impress/src/components/common/tree/TreeView.tsx

Lines changed: 49 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/* eslint-disable jsx-a11y/no-static-element-interactions */
22
import { clsx } from 'clsx';
33
import { useEffect, useRef, useState } from 'react';
4-
import { MoveHandler, NodeApi, NodeRendererProps, Tree } from 'react-arborist';
4+
import {
5+
CursorProps,
6+
MoveHandler,
7+
NodeApi,
8+
NodeRendererProps,
9+
Tree,
10+
} from 'react-arborist';
511

612
import { Box } from '../../Box';
713
import { Icon } from '../../Icon';
@@ -21,14 +27,19 @@ const addAllChildren = <T,>(
2127
data: TreeViewDataType<T>[],
2228
): TreeViewDataType<T>[] => {
2329
return data.map((item) => {
24-
return { ...item, children: item.children ?? [] };
30+
console.log('item', item);
31+
return {
32+
...item,
33+
children: item.children ? addAllChildren(item.children) : [],
34+
};
2535
});
2636
};
2737

2838
export type TreeViewProps<T> = {
2939
data: TreeViewDataType<T>[];
40+
width?: number;
3041
allCanBeFolder?: boolean;
31-
rootNode: BaseType<T>;
42+
3243
renderNode?: (node: TreeViewDataType<T>) => React.ReactNode;
3344
loadChildren?: (node: TreeViewDataType<T>) => Promise<TreeViewDataType<T>[]>;
3445
afterMove?: (
@@ -38,12 +49,11 @@ export type TreeViewProps<T> = {
3849
) => void;
3950
};
4051

41-
type ArgumentTypes<T> = Parameters<MoveHandler<TreeViewDataType<T>>>;
42-
4352
export const TreeView = <T,>({
4453
data: initialData,
54+
width,
4555
allCanBeFolder,
46-
rootNode,
56+
4757
renderNode,
4858
loadChildren,
4959
afterMove,
@@ -52,47 +62,6 @@ export const TreeView = <T,>({
5262
allCanBeFolder ? addAllChildren(initialData) : initialData,
5363
);
5464

55-
const onMove3 = (args: {
56-
dragIds: string[];
57-
dragNodes: NodeApi<BaseType<T>>[];
58-
parentId: string | null;
59-
parentNode: NodeApi<BaseType<T>> | null;
60-
index: number;
61-
}): {
62-
targetNodeId: string;
63-
mode: 'first-child' | 'last-child' | 'left' | 'right';
64-
} | null => {
65-
const newData = JSON.parse(JSON.stringify(data)) as TreeViewDataType<T>[];
66-
67-
const newIndex = args.index;
68-
const targetNodeId = args.parentId ?? rootNode.id;
69-
const children = args.parentId
70-
? (args.parentNode?.children ?? [])
71-
: newData;
72-
73-
if (newIndex === 0) {
74-
return { targetNodeId: targetNodeId, mode: 'first-child' };
75-
}
76-
if (newIndex === children.length) {
77-
return { targetNodeId: targetNodeId, mode: 'last-child' };
78-
}
79-
80-
const siblingIndex = newIndex - 1;
81-
const sibling = children[siblingIndex];
82-
83-
if (sibling) {
84-
return { targetNodeId: sibling.id, mode: 'right' };
85-
}
86-
87-
const nextSiblingIndex = newIndex + 1;
88-
const nextSibling = children[nextSiblingIndex];
89-
if (nextSibling) {
90-
return { targetNodeId: nextSibling.id, mode: 'left' };
91-
}
92-
93-
return null;
94-
};
95-
9665
const onMove = (args: {
9766
dragIds: string[];
9867
dragNodes: NodeApi<BaseType<T>>[];
@@ -182,7 +151,6 @@ export const TreeView = <T,>({
182151
findParentAndInsert(newData);
183152
}
184153

185-
console.log('onMove --- ', onMove3(args));
186154
setData(newData);
187155
};
188156

@@ -192,30 +160,24 @@ export const TreeView = <T,>({
192160
}, [initialData, setData, allCanBeFolder]);
193161

194162
return (
195-
<Box className={styles.container}>
196-
<Tree
197-
data={data}
198-
openByDefault={false}
199-
height={1000}
200-
indent={20}
201-
width={280}
202-
rowHeight={28}
203-
overscanCount={1}
204-
paddingTop={30}
205-
paddingBottom={10}
206-
padding={25}
207-
onMove={onMove as MoveHandler<TreeViewDataType<T>>}
208-
>
209-
{(props) => (
210-
<Node
211-
{...props}
212-
renderNode={renderNode}
213-
loadChildren={loadChildren}
214-
/>
215-
)}
216-
</Tree>
217-
e
218-
</Box>
163+
<Tree
164+
data={data}
165+
openByDefault={false}
166+
height={1000}
167+
indent={20}
168+
openByDefault={true}
169+
// width={280}
170+
width={width}
171+
rowHeight={32}
172+
overscanCount={20}
173+
padding={25}
174+
renderCursor={Cursor}
175+
onMove={onMove as MoveHandler<TreeViewDataType<T>>}
176+
>
177+
{(props) => (
178+
<Node {...props} renderNode={renderNode} loadChildren={loadChildren} />
179+
)}
180+
</Tree>
219181
);
220182
};
221183

@@ -224,6 +186,18 @@ export type NodeProps<T> = NodeRendererProps<TreeViewDataType<T>> & {
224186
loadChildren?: (node: TreeViewDataType<T>) => Promise<TreeViewDataType<T>[]>;
225187
};
226188

189+
function Cursor({ top, left }: CursorProps) {
190+
return (
191+
<div
192+
className={styles.cursor}
193+
style={{
194+
top,
195+
left: left + 10,
196+
}}
197+
></div>
198+
);
199+
}
200+
227201
export const Node = <T,>({
228202
renderNode,
229203
node,
@@ -275,6 +249,7 @@ export const Node = <T,>({
275249
if (timeoutRef.current && !node.willReceiveDrop) {
276250
clearTimeout(timeoutRef.current);
277251
}
252+
// eslint-disable-next-line react-hooks/exhaustive-deps
278253
}, [node]);
279254

280255
return (
@@ -283,9 +258,11 @@ export const Node = <T,>({
283258
className={clsx(styles.node, {
284259
[styles.willReceiveDrop]: node.willReceiveDrop,
285260
[styles.selected]: node.isSelected,
261+
toto: true,
286262
})}
287263
style={{
288264
...style,
265+
width: `calc(100% + ${node.level * 20}px)`,
289266
}}
290267
ref={dragHandle}
291268
>

src/frontend/apps/impress/src/components/common/tree/treeview.module.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
.container {
2+
[role='treeitem'] {
3+
display: flex;
4+
align-items: center;
5+
}
26
}
37

48
.node {
9+
// padding-left: 0px !important;
10+
// margin-left: 180px;
11+
min-width: 300px;
12+
height: calc(100% - 2px);
13+
overflow: hidden;
514
display: flex;
615
align-items: center;
16+
flex-wrap: nowrap;
717
border-radius: 4px;
818
border: 1.5px solid rgba(0, 0, 0, 0);
919
cursor: pointer;
20+
1021
padding: var(--c--theme--spacings--4xs) 0;
1122
gap: var(--c--theme--spacings--3xs);
1223

@@ -16,10 +27,19 @@
1627

1728
&.selected {
1829
background-color: var(--c--theme--colors--greyscale-100);
30+
31+
font-weight: 700;
1932
}
2033

2134
&.willReceiveDrop {
2235
background-color: var(--c--theme--colors--primary-100);
2336
border: 1.5px solid var(--c--theme--colors--primary-500);
2437
}
2538
}
39+
40+
.cursor {
41+
position: absolute;
42+
width: 100%;
43+
height: 0;
44+
border-top: 2px solid var(--c--theme--colors--primary-500);
45+
}

src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGridItem.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ export const DocsGridItem = ({ doc }: DocsGridItemProps) => {
6868
<SimpleDocItem isPinned={doc.is_favorite} doc={doc} />
6969
{showAccesses && (
7070
<Box
71-
$padding={{ top: '3xs' }}
72-
$css={css`
73-
align-self: flex-start;
74-
`}
71+
$padding={{ top: !isDesktop ? '4xs' : undefined }}
72+
$css={
73+
!isDesktop
74+
? css`
75+
align-self: flex-start;
76+
`
77+
: undefined
78+
}
7579
>
7680
<Tooltip
7781
content={

0 commit comments

Comments
 (0)