Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
708ff0b
fix: install "history" package or explorer would fail to compile
dragonman225 Apr 11, 2022
3b8dbbf
feat(outliner): add drag handle
dragonman225 Mar 29, 2022
a0e751f
refactor(outline): allow arbitrary props in drag handle
dragonman225 Mar 29, 2022
3e213da
feat(outliner): show drag handle for every outline
dragonman225 Mar 29, 2022
aef0f0c
refactor(outliner): rename for clarity
dragonman225 Mar 29, 2022
513deef
refactor(outliner): fix types
dragonman225 Mar 29, 2022
f38669e
refactor(outliner): extract <Outline> component
dragonman225 Mar 29, 2022
9982167
refactor(outliner): fix types
dragonman225 Mar 29, 2022
783e242
feat(outliner): add rough support for drag and drop
dragonman225 Mar 29, 2022
f1a655a
refactor(outliner): fix types
dragonman225 Mar 30, 2022
a053c79
fix(outliner): prevent wrong order when reorder in the same parent
dragonman225 Mar 30, 2022
0f59659
feat(outliner): improve button colors
dragonman225 Mar 30, 2022
6210805
fix(outliner): prevent <DragHandle> shrinking
dragonman225 Mar 30, 2022
ed4b2ea
feat(outliner): support reorder to the first item in the same list
dragonman225 Mar 30, 2022
36c98a7
fix(outliner): disable selection box when dragging an outline
dragonman225 Mar 30, 2022
467784c
feat(outliner): support adding items before indexes in another list
dragonman225 Mar 31, 2022
45193ef
docs(outliner): add helpful comments
dragonman225 Mar 31, 2022
d6c762f
fix(outliner): keep collapsed bullets collpased after dnd
dragonman225 Mar 31, 2022
fb0bd72
feat(outliner): make DragHandle easier to click
dragonman225 Mar 31, 2022
a5e50fd
feat(outliner): show grab cursor for DragHandle
dragonman225 Mar 31, 2022
7aeac10
feat(outliner): prevent dropping into descendants
dragonman225 Apr 1, 2022
2a7028e
fix(outliner): tune drag-and-drop
dragonman225 Apr 4, 2022
781a94c
fix(outliner): try react-dnd-touch-backend
dragonman225 Apr 5, 2022
9db5848
fix(outliner): prevent drop target block focus-to-edit
dragonman225 Apr 6, 2022
a52f5b0
feat(outliner): show grabbing cursor when dragging
dragonman225 Apr 7, 2022
b1fa216
refactor(outliner): removed unused code
dragonman225 Apr 7, 2022
617d350
fix(outliner): prevent drop targets block text editing
dragonman225 Apr 11, 2022
5891e2a
feat(dnd): speedup editor dnd
thesophiaxu Apr 13, 2022
b168625
fix(outliner): prevent crash when reordering a bullet with children
dragonman225 Apr 13, 2022
2cf86d8
refactor(outliner): remove unused code
dragonman225 Apr 13, 2022
79655be
fix(outliner): prevent useless drops
dragonman225 Apr 13, 2022
f7d2d12
fix(outliner): dropping before/after itself should not move
dragonman225 Apr 13, 2022
fbf47e7
refactor(outliner): remove unused code
dragonman225 Apr 13, 2022
1c32fbe
Merge branch 'main' into alex/dnd
thesophiaxu Apr 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const destUidOrName = context.params.where;
const sourceUid = context.params.item;
/** Set `true` to add items before indexes, otherwise after indexes. */
const listBefore = context.params.before;
const { indexes, subIds } = context.params;
let destUid;

Expand Down Expand Up @@ -39,7 +41,7 @@ if (indexes && Array.isArray(indexes) && indexes.length === sources.length) {
if (listUid)
await unigraph.reorderItemInArray(
listUid,
sources.map((el, idx) => [el, indexes[idx]]),
sources.map((el, idx) => [el, indexes[listBefore ? idx - 1 : idx]]),
undefined,
subIds,
);
Expand Down
5 changes: 3 additions & 2 deletions packages/unigraph-dev-common/src/api/unigraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export default function unigraph(url: string, browserId: string): Unigraph<WebSo
}

subResults[subId] = newObj;
// console.log(newObj);
console.log(newObj);

// Record state changes
if (id) {
Expand All @@ -585,12 +585,13 @@ export default function unigraph(url: string, browserId: string): Unigraph<WebSo
deleteRelation: (uid, relation) => {
sendEvent(connection, 'delete_relation', { uid, relation });
},
reorderItemInArray: (uid, item, relUid, subIds) => {
reorderItemInArray: (uid, item, relUid, subIds, eventId) => {
sendEvent(connection, 'reorder_item_in_array', {
uid,
item,
relUid,
subIds,
id: eventId,
});
},
deleteItemFromArray: (uid, item, relUid, subIds) => {
Expand Down
1 change: 1 addition & 0 deletions packages/unigraph-dev-common/src/types/unigraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export interface Unigraph<TT = WebSocket | undefined> {
item: [number | string, number] | [number | string, number][],
relationUid?: string,
subIds?: any[] | any,
eventId?: string,
): any;
/**
* Deletes an item from an array (ordered list).
Expand Down
8 changes: 5 additions & 3 deletions packages/unigraph-dev-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
"react-app-polyfill": "^2.0.0",
"react-big-calendar": "^0.38.5",
"react-dev-utils": "^11.0.3",
"react-dnd": "^14.0.2",
"react-dnd-html5-backend": "^14.0.0",
"react-dnd": "^15.1.2",
"react-dnd-html5-backend": "^15.1.3",
"react-dnd-touch-backend": "^15.1.2",
"react-error-boundary": "^3.1.3",
"react-force-graph-2d": "^1.23.6",
"react-grid-layout": "^1.2.4",
Expand Down Expand Up @@ -94,7 +95,8 @@
"webpack": "4.44.2",
"webpack-dev-server": "3.11.1",
"webpack-manifest-plugin": "2.2.0",
"workbox-webpack-plugin": "5.1.4"
"workbox-webpack-plugin": "5.1.4",
"zustand": "^3.7.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.4",
Expand Down
9 changes: 8 additions & 1 deletion packages/unigraph-dev-explorer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { styled } from '@mui/styles';

import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { TouchBackend } from 'react-dnd-touch-backend';
import { getParameters, globalTheme, isElectron, NavigationContext } from './utils';
import { ContextMenu } from './components/UnigraphCore/ContextMenu';
import { InlineSearch } from './components/UnigraphCore/InlineSearchPopup';
import { SearchOverlayPopover } from './pages/SearchOverlay';
import { MobileBar } from './components/UnigraphCore/MobileBar';
import { CustomDragLayer } from './CustomDragLayer';

declare module '@mui/styles/defaultTheme' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down Expand Up @@ -50,6 +52,10 @@ const StyledStyledEngineProvider = styled(StyledEngineProvider)(({ theme }) => (

const providedTheme = createTheme(globalTheme);

const dndOpts = {
enableMouseEvents: true,
};

function AppToWrap() {
const history = createBrowserHistory();
const componentPathName = new URLSearchParams(window.location.search).get('pageName');
Expand All @@ -59,7 +65,8 @@ function AppToWrap() {

return (
<div className={classes.root}>
<DndProvider backend={HTML5Backend}>
<DndProvider backend={TouchBackend} options={dndOpts}>
<CustomDragLayer />
<div id="global-elements">
<ContextMenu />
<InlineSearch />
Expand Down
58 changes: 58 additions & 0 deletions packages/unigraph-dev-explorer/src/CustomDragLayer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { useDragLayer, XYCoord } from 'react-dnd';
import { DragHandle } from './examples/notes/DragHandle';

const layerStyles: React.CSSProperties = {
position: 'fixed',
pointerEvents: 'none',
zIndex: 100,
left: 0,
top: 0,
width: '100%',
height: '100%',
};

function getItemStyles(initialOffset: XYCoord | null, currentOffset: XYCoord | null) {
if (!initialOffset || !currentOffset) {
return {
display: 'none',
};
}

const { x, y } = currentOffset;

const transform = `translate(${x}px, ${y}px)`;
return {
transform,
WebkitTransform: transform,
};
}

export const CustomDragLayer = () => {
const { isDragging, initialOffset, currentOffset } = useDragLayer((monitor) => ({
item: monitor.getItem(),
itemType: monitor.getItemType(),
initialOffset: monitor.getInitialSourceClientOffset(),
currentOffset: monitor.getSourceClientOffset(),
isDragging: monitor.isDragging(),
}));

React.useEffect(() => {
if (isDragging) {
document.body.style.cursor = 'grabbing';
} else {
document.body.style.cursor = 'auto';
}
}, [isDragging]);

if (!isDragging) {
return null;
}
return (
<div style={layerStyles}>
<div style={getItemStyles(initialOffset, currentOffset)}>
<DragHandle />
</div>
</div>
);
};
10 changes: 8 additions & 2 deletions packages/unigraph-dev-explorer/src/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isJsonString } from 'unigraph-dev-common/lib/utils/utils';
import { getRandomInt } from 'unigraph-dev-common/lib/api/unigraph';
import { Menu, Details, Home } from '@mui/icons-material';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { TouchBackend } from 'react-dnd-touch-backend';

import MomentUtils from '@date-io/moment';
// or @mui/lab/Adapter{Dayjs,Luxon,Moment} or any valid date-io adapter
Expand All @@ -33,6 +33,7 @@ import { ContextMenu } from './components/UnigraphCore/ContextMenu';
import { getComponentFromPage, getParameters, globalTheme, isElectron, isSmallScreen, TabContext } from './utils';
import { SearchOverlayPopover } from './pages/SearchOverlay';
import { MobileBar } from './components/UnigraphCore/MobileBar';
import { CustomDragLayer } from './CustomDragLayer';

export function WorkspacePageComponent({ children, maximize, paddingTop, id, tabCtx }: any) {
const [_maximize, setMaximize] = React.useState(maximize);
Expand Down Expand Up @@ -279,6 +280,10 @@ const setTitleOnRenderTab = (model: Model) => {

const providedTheme = createTheme(globalTheme);

const dndOpts = {
enableMouseEvents: true,
};

export function WorkSpace(this: any) {
const json: any = {
global: {
Expand Down Expand Up @@ -491,7 +496,8 @@ export function WorkSpace(this: any) {
<StyledEngineProvider injectFirst>
<ThemeProvider theme={providedTheme}>
<LocalizationProvider dateAdapter={AdapterMoment}>
<DndProvider backend={HTML5Backend}>
<DndProvider backend={TouchBackend} options={dndOpts}>
<CustomDragLayer />
<div id="global-elements" className="lol1">
<SearchOverlayPopover />
<ContextMenu />
Expand Down
37 changes: 37 additions & 0 deletions packages/unigraph-dev-explorer/src/examples/notes/DragHandle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable react/require-default-props */
import { styled } from '@mui/styles';
import React from 'react';

const DragHandleContainer = styled('div')({
flex: '0 0 1rem',
width: '1rem',
height: '1.25rem',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
cursor: 'grab',
borderRadius: '0.25rem',
transition: 'background 30ms ease-in',
'&:hover': {
background: 'rgba(0, 0, 0, 0.1)',
},
'&:active': {
background: 'rgba(0, 0, 0, 0.2)',
cursor: 'grabbing',
},
});

export const DragHandle = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>((props, ref) => {
return (
<DragHandleContainer ref={ref} {...props}>
<svg width="100%" height="100%" viewBox="0 0 20 24" xmlns="http://www.w3.org/2000/svg">
<circle cx="7" cy="7" r="1.5" />
<circle cx="7" cy="12" r="1.5" />
<circle cx="7" cy="17" r="1.5" />
<circle cx="13" cy="7" r="1.5" />
<circle cx="13" cy="12" r="1.5" />
<circle cx="13" cy="17" r="1.5" />
</svg>
</DragHandleContainer>
);
});
Loading