mirror of
https://github.com/mathuo/dockview
synced 2025-05-07 20:18:26 +00:00
further docs work
This commit is contained in:
parent
d306387a0a
commit
8a51593ac3
@ -236,36 +236,44 @@ Through toggling the checkbox you can see that when you only render those panels
|
|||||||
|
|
||||||
### Drag And Drop
|
### Drag And Drop
|
||||||
|
|
||||||
<DndDockview />
|
The component exposes some method to help determine whether external drag events should be interacted with or not.
|
||||||
|
|
||||||
Both `DockviewReact` and `PaneviewReact` support drag and drop functionality out of the box.
|
|
||||||
|
|
||||||
- `DockviewReact` allows tabs to be repositioned using drag and drop.
|
|
||||||
- `PaneviewReact` allows the repositioning of views using drag and drop on the header section.
|
|
||||||
|
|
||||||
You can use the utility methods `getPaneData` and `getPanelData` to manually extract the data transfer metadata associated with an active drag and drop event for either of the above components.
|
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import {
|
/**
|
||||||
getPaneData,
|
* called when an ondrop event which does not originate from the dockview libray and
|
||||||
getPanelData,
|
* passes the showDndOverlay condition occurs
|
||||||
PanelTransfer,
|
**/
|
||||||
PaneTransfer,
|
const onDidDrop = (event: DockviewDropEvent) => {
|
||||||
} from 'dockview';
|
const { group } = event;
|
||||||
|
|
||||||
const panelData: PanelTransfer | undefined = getPanelData();
|
event.api.addPanel({
|
||||||
|
id: 'test',
|
||||||
|
component: 'default',
|
||||||
|
position: {
|
||||||
|
referencePanel: group.activePanel.id,
|
||||||
|
direction: 'within',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (panelData) {
|
/**
|
||||||
// DockviewReact: data transfer metadata associated with the active drag and drop event
|
* called for drag over events which do not originate from the dockview library
|
||||||
const { viewId, groupId, panelId } = panelData; // deconstructed object
|
* allowing the developer to decide where the overlay should be shown for a
|
||||||
}
|
* particular drag event
|
||||||
|
**/
|
||||||
|
const showDndOverlay = (event: DockviewDndOverlayEvent) => {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
const paneData: PaneTransfer | undefined = getPaneData();
|
return (
|
||||||
|
<DockviewReact
|
||||||
if (paneData) {
|
components={components}
|
||||||
// PaneviewReact: data transfer metadata associated with the active drag and drop event
|
onReady={onReady}
|
||||||
const { viewId, paneId } = paneData; // deconstructed object
|
className="dockview-theme-dark"
|
||||||
}
|
onDidDrop={onDidDrop}
|
||||||
|
showDndOverlay={showDndOverlay}
|
||||||
|
/>
|
||||||
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
See example [here](https://codesandbox.io/s/workspace-saving-example-euo5d).
|
<DndDockview />
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"@docusaurus/preset-classic": "2.0.0-beta.20",
|
"@docusaurus/preset-classic": "2.0.0-beta.20",
|
||||||
"@mdx-js/react": "^1.6.22",
|
"@mdx-js/react": "^1.6.22",
|
||||||
"clsx": "^1.1.1",
|
"clsx": "^1.1.1",
|
||||||
"dockview": "^1.4.1",
|
"dockview": "0.0.0-experimental-d306387a-20220521",
|
||||||
"prism-react-renderer": "^1.3.1",
|
"prism-react-renderer": "^1.3.1",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
|
DockviewDndOverlayEvent,
|
||||||
DockviewDropEvent,
|
DockviewDropEvent,
|
||||||
DockviewReact,
|
DockviewReact,
|
||||||
DockviewReadyEvent,
|
DockviewReadyEvent,
|
||||||
IDockviewPanelProps,
|
IDockviewPanelProps,
|
||||||
} from 'dockview';
|
} from 'dockview';
|
||||||
import { DockviewDropTargets } from 'dockview/dist/cjs/groupview/dnd';
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
const components = {
|
const components = {
|
||||||
@ -54,10 +54,19 @@ export const DndDockview = (props: { renderVisibleOnly: boolean }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onDidDrop = (event: DockviewDropEvent) => {
|
const onDidDrop = (event: DockviewDropEvent) => {
|
||||||
console.log(event);
|
const { group } = event;
|
||||||
|
|
||||||
|
event.api.addPanel({
|
||||||
|
id: 'test',
|
||||||
|
component: 'default',
|
||||||
|
position: {
|
||||||
|
referencePanel: group.activePanel.id,
|
||||||
|
direction: 'within',
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const showDndOverlay = (event: DragEvent, targets: DockviewDropTargets) => {
|
const showDndOverlay = (event: DockviewDndOverlayEvent) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -66,8 +75,10 @@ export const DndDockview = (props: { renderVisibleOnly: boolean }) => {
|
|||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: 'orange',
|
backgroundColor: 'orange',
|
||||||
color: 'white',
|
padding: '0px 8px',
|
||||||
|
borderRadius: '4px',
|
||||||
width: '100px',
|
width: '100px',
|
||||||
|
cursor: 'pointer',
|
||||||
}}
|
}}
|
||||||
draggable={true}
|
draggable={true}
|
||||||
>
|
>
|
||||||
|
@ -3354,10 +3354,10 @@ dns-packet@^5.2.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@leichtgewicht/ip-codec" "^2.0.1"
|
"@leichtgewicht/ip-codec" "^2.0.1"
|
||||||
|
|
||||||
dockview@^1.4.1:
|
dockview@0.0.0-experimental-d306387a-20220521:
|
||||||
version "1.4.2"
|
version "0.0.0-experimental-d306387a-20220521"
|
||||||
resolved "https://registry.yarnpkg.com/dockview/-/dockview-1.4.2.tgz#20efbedccdebc64f0ee95d19460f158d52dc7792"
|
resolved "https://registry.yarnpkg.com/dockview/-/dockview-0.0.0-experimental-d306387a-20220521.tgz#64ecf9ee358c45c7007d0a4b01f0437064fa5232"
|
||||||
integrity sha512-GPELYEOd6u83VLJ8XXMV4VE9otuHJydSoeoy4uKyrZ+ZAxxv1UVJiEjub0GVlsMRgeeatT4pnBQsgRpgm8jPkQ==
|
integrity sha512-pyOhqXORHY9Y6FOmhzFnZueoJ5kdM1J3elcxNbL+hgvaabcykGHeu+3C42lAFA9xnzi/4ru/31547CRFw26oCw==
|
||||||
|
|
||||||
docusaurus-plugin-sass@^0.2.2:
|
docusaurus-plugin-sass@^0.2.2:
|
||||||
version "0.2.2"
|
version "0.2.2"
|
||||||
|
Loading…
Reference in New Issue
Block a user