Skip to content

Commit a487782

Browse files
committed
🐛(frontend) fix dnd conflict with tree and Blocknote
We have different DND system in the page, one on the menu tree and one in the Blocknote editor. The menu tree was adding a transparent layer when user were dragging element on the Blocknote editor, blocking the Blocknote DND. We update the ui-kit to add the prop dndRootElement, dndRootElement is now used to specify the root element for DND, this transparent layer is now only applied when a drag is made from the menu tree. It stabilize as well the drop position, making it easier to drop element.
1 parent a57ae0b commit a487782

File tree

3 files changed

+36
-56
lines changed

3 files changed

+36
-56
lines changed

src/frontend/apps/impress/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@emoji-mart/react": "1.1.1",
3030
"@fontsource/material-icons": "5.2.5",
3131
"@gouvfr-lasuite/integration": "1.0.3",
32-
"@gouvfr-lasuite/ui-kit": "0.16.0",
32+
"@gouvfr-lasuite/ui-kit": "0.16.1",
3333
"@hocuspocus/provider": "2.15.2",
3434
"@openfun/cunningham-react": "3.2.3",
3535
"@react-pdf/renderer": "4.3.0",

src/frontend/apps/impress/src/features/docs/doc-tree/components/DocTree.tsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const DocTree = ({ currentDoc }: DocTreeProps) => {
3030
const treeContext = useTreeContext<Doc | null>();
3131
const router = useRouter();
3232
const { isDesktop } = useResponsive();
33+
const [treeRoot, setTreeRoot] = useState<HTMLElement | null>(null);
3334

3435
const [initialOpenState, setInitialOpenState] = useState<OpenMap | undefined>(
3536
undefined,
@@ -148,6 +149,7 @@ export const DocTree = ({ currentDoc }: DocTreeProps) => {
148149

149150
return (
150151
<Box
152+
ref={setTreeRoot}
151153
data-testid="doc-tree"
152154
$height="100%"
153155
$css={css`
@@ -232,30 +234,33 @@ export const DocTree = ({ currentDoc }: DocTreeProps) => {
232234
</Box>
233235
</Box>
234236

235-
{initialOpenState && treeContext.treeData.nodes.length > 0 && (
236-
<TreeView
237-
initialOpenState={initialOpenState}
238-
afterMove={handleMove}
239-
selectedNodeId={
240-
treeContext.treeData.selectedNode?.id ??
241-
treeContext.initialTargetId ??
242-
undefined
243-
}
244-
canDrop={({ parentNode }) => {
245-
const parentDoc = parentNode?.data.value as Doc;
246-
if (!parentDoc) {
247-
return currentDoc.abilities.move && isDesktop;
237+
{initialOpenState &&
238+
treeContext.treeData.nodes.length > 0 &&
239+
treeRoot && (
240+
<TreeView
241+
dndRootElement={treeRoot}
242+
initialOpenState={initialOpenState}
243+
afterMove={handleMove}
244+
selectedNodeId={
245+
treeContext.treeData.selectedNode?.id ??
246+
treeContext.initialTargetId ??
247+
undefined
248248
}
249-
return parentDoc.abilities.move && isDesktop;
250-
}}
251-
canDrag={(node) => {
252-
const doc = node.value as Doc;
253-
return doc.abilities.move && isDesktop;
254-
}}
255-
rootNodeId={treeContext.root.id}
256-
renderNode={DocSubPageItem}
257-
/>
258-
)}
249+
canDrop={({ parentNode }) => {
250+
const parentDoc = parentNode?.data.value as Doc;
251+
if (!parentDoc) {
252+
return currentDoc.abilities.move && isDesktop;
253+
}
254+
return parentDoc.abilities.move && isDesktop;
255+
}}
256+
canDrag={(node) => {
257+
const doc = node.value as Doc;
258+
return doc.abilities.move && isDesktop;
259+
}}
260+
rootNodeId={treeContext.root.id}
261+
renderNode={DocSubPageItem}
262+
/>
263+
)}
259264
</Box>
260265
);
261266
};

src/frontend/yarn.lock

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,10 +1734,10 @@
17341734
resolved "https://registry.yarnpkg.com/@gouvfr-lasuite/integration/-/integration-1.0.3.tgz#7aca824ba61d343a7905dc90c8a8bbdbce8f9a09"
17351735
integrity sha512-OgP28CqlPi35wQPul1Dr52SngACXAk8buLGqHYXDp23fbTOJThqarrZE/pgJHoc9Ndwiu7ngwBSO4rZ7OPyMpA==
17361736

1737-
"@gouvfr-lasuite/[email protected].0":
1738-
version "0.16.0"
1739-
resolved "https://registry.yarnpkg.com/@gouvfr-lasuite/ui-kit/-/ui-kit-0.16.0.tgz#6cf2f786759384904ac1b4c99b4082b0508aa71f"
1740-
integrity sha512-VLjDLxuBM647OOD66ylJEnfcQrcO8fWyrfVSvhk/3QLMu9UImqSIE62RGh9PbeZ0+fXso9I8xI/wamkvyujXCQ==
1737+
"@gouvfr-lasuite/[email protected].1":
1738+
version "0.16.1"
1739+
resolved "https://registry.yarnpkg.com/@gouvfr-lasuite/ui-kit/-/ui-kit-0.16.1.tgz#3dfac5c38ea31c292f38cd25b5372b4633661f37"
1740+
integrity sha512-mx2gM1vv7NvL0LOOd3zqtT4H58rR9ogmmswYV6ocDFx7hoMWE/gA6i1R2grktFrJP/Pt3JgcvDET8iKbp+56VQ==
17411741
dependencies:
17421742
"@dnd-kit/core" "6.3.1"
17431743
"@dnd-kit/modifiers" "9.0.0"
@@ -14712,16 +14712,7 @@ string-length@^4.0.2:
1471214712
char-regex "^1.0.2"
1471314713
strip-ansi "^6.0.0"
1471414714

14715-
"string-width-cjs@npm:string-width@^4.2.0":
14716-
version "4.2.3"
14717-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
14718-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
14719-
dependencies:
14720-
emoji-regex "^8.0.0"
14721-
is-fullwidth-code-point "^3.0.0"
14722-
strip-ansi "^6.0.1"
14723-
14724-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
14715+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1472514716
version "4.2.3"
1472614717
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1472714718
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -14847,14 +14838,7 @@ stringify-object@^3.3.0:
1484714838
is-obj "^1.0.1"
1484814839
is-regexp "^1.0.0"
1484914840

14850-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
14851-
version "6.0.1"
14852-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
14853-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
14854-
dependencies:
14855-
ansi-regex "^5.0.1"
14856-
14857-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
14841+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1485814842
version "6.0.1"
1485914843
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1486014844
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -16389,16 +16373,7 @@ [email protected]:
1638916373
"@types/trusted-types" "^2.0.2"
1639016374
workbox-core "7.1.0"
1639116375

16392-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
16393-
version "7.0.0"
16394-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
16395-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
16396-
dependencies:
16397-
ansi-styles "^4.0.0"
16398-
string-width "^4.1.0"
16399-
strip-ansi "^6.0.0"
16400-
16401-
wrap-ansi@^7.0.0:
16376+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1640216377
version "7.0.0"
1640316378
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1640416379
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

0 commit comments

Comments
 (0)