Skip to content

Commit

Permalink
Activation constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
clauderic committed Aug 2, 2023
1 parent 80486f2 commit c63cefd
Show file tree
Hide file tree
Showing 25 changed files with 966 additions and 501 deletions.
Binary file removed .storybook/assets/apple-touch-icon.png
Binary file not shown.
17 changes: 0 additions & 17 deletions .storybook/assets/dnd-kit-banner.svg

This file was deleted.

Binary file removed .storybook/assets/favicon-16x16.png
Binary file not shown.
Binary file removed .storybook/assets/favicon-32x32.png
Binary file not shown.
Binary file removed .storybook/assets/favicon.ico
Binary file not shown.
44 changes: 0 additions & 44 deletions .storybook/main.js

This file was deleted.

25 changes: 0 additions & 25 deletions .storybook/manager-head.html

This file was deleted.

7 changes: 0 additions & 7 deletions .storybook/manager.js

This file was deleted.

30 changes: 0 additions & 30 deletions .storybook/preview.js

This file was deleted.

8 changes: 0 additions & 8 deletions .storybook/theme.js

This file was deleted.

4 changes: 2 additions & 2 deletions apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ['dnd-kit'],
};
extends: ['dnd-kit', 'plugin:storybook/recommended']
};
34 changes: 22 additions & 12 deletions apps/docs/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
import {dirname, join} from 'path';
import {mergeConfig} from 'vite';
import {addons} from '@storybook/manager-api';

import {theme} from './theme';

addons.setConfig({
theme,
});

export default {
stories: ['../stories/**/*.stories.mdx', '../stories/**/*.stories.tsx'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react-vite',
core: {
builder: '@storybook/builder-vite',
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
],
framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
async viteFinal(config, {configType}) {
// customize the Vite config here
return mergeConfig(config, {
define: {'process.env': {}},
define: {
'process.env': {},
},
});
},
docs: {
autodocs: true,
},
};

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value) {
return dirname(require.resolve(join(value, 'package.json')));
}
7 changes: 7 additions & 0 deletions apps/docs/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {addons} from '@storybook/manager-api';
import {theme} from './theme';

addons.setConfig({
theme,
showPanel: false,
});
4 changes: 2 additions & 2 deletions apps/docs/.storybook/theme.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {create} from '@storybook/theming/create';
import {default as brandImage} from './assets/dnd-kit-banner.svg';

export const theme = create({
base: 'light',
brandImage:
'https://raw.githubusercontent.com/clauderic/dnd-kit/master/.storybook/assets/dnd-kit-banner.svg',
brandImage,
appBg: '#F9F9F9',
});
26 changes: 13 additions & 13 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
"@dnd-kit/dom": "*",
"@dnd-kit/react": "*",
"@dnd-kit/utilities": "*",
"use-pan-and-zoom": "^0.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"use-pan-and-zoom": "^0.6.5"
},
"devDependencies": {
"@dnd-kit/config-ts": "*",
"@dnd-kit/abstract": "*",
"@dnd-kit/config-eslint": "*",
"@dnd-kit/config-ts": "*",
"@dnd-kit/dom": "*",
"@dnd-kit/react": "*",
"@dnd-kit/utilities": "*",
"@dnd-kit/config-eslint": "*",
"@storybook/addon-actions": "^7.1.1",
"@storybook/addon-docs": "^7.1.1",
"@storybook/addon-essentials": "^7.1.1",
"@storybook/addon-links": "^7.1.1",
"@storybook/builder-vite": "^7.1.1",
"@storybook/manager-api": "^7.1.1",
"@storybook/react": "^7.1.1",
"@storybook/react-vite": "^7.1.1",
"@storybook/theming": "^7.1.1",
"@storybook/addon-actions": "^7.2.0",
"@storybook/addon-docs": "^7.2.0",
"@storybook/addon-essentials": "^7.2.0",
"@storybook/addon-links": "^7.2.0",
"@storybook/manager-api": "^7.2.0",
"@storybook/react": "^7.2.0",
"@storybook/react-vite": "^7.2.0",
"@storybook/theming": "^7.2.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint-plugin-storybook": "^0.6.13",
"serve": "^13.0.2",
"storybook": "next",
"typescript": "^5.1.6",
Expand Down
16 changes: 15 additions & 1 deletion apps/docs/stories/Droppable/DroppableExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {closestCenter, CollisionDetector} from '@dnd-kit/collision';

import {Button, Dropzone} from '../components';
import {DraggableIcon} from '../icons';
import {cloneDeep} from '../utilities';

export function DroppableExample() {
const [items, setItems] = useState({
Expand All @@ -31,6 +32,7 @@ export function DroppableExample() {
C4: [],
},
});
const snapshot = useRef(cloneDeep(items));

return (
<DndContext
Expand Down Expand Up @@ -61,6 +63,13 @@ export function DroppableExample() {
}
}
}}
onDragEnd={(event) => {
if (event.canceled) {
setItems(snapshot.current);
} else {
snapshot.current = cloneDeep(items);
}
}}
>
<div style={{display: 'flex', flexDirection: 'row', gap: 20}}>
{Object.entries(items).map(([columnId, items]) => (
Expand All @@ -76,7 +85,12 @@ export function DroppableExample() {
collisionDetector={closestCenter}
>
{children.map((child) => (
<Draggable id={child.id} type={child.type} parent={rowId} />
<Draggable
key={child.id}
id={child.id}
type={child.type}
parent={rowId}
/>
))}
</Droppable>
))}
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/stories/utilities/cloneDeep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function cloneDeep(obejct: Object) {
return JSON.parse(JSON.stringify(obejct));
}
1 change: 1 addition & 0 deletions apps/docs/stories/utilities/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {classNames} from './classnames';
export {cloneDeep} from './cloneDeep';
27 changes: 17 additions & 10 deletions packages/abstract/src/manager/dragOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ export function DragOperationManager<
position,
};

const reset = () =>
requestAnimationFrame(() => {
batch(() => {
status.value = Status.Idle;
sourceIdentifier.value = null;
targetIdentifier.value = null;
shape.value = null;
position.reset({x: 0, y: 0});
});
});


return {
operation,
actions: {
Expand Down Expand Up @@ -148,11 +160,14 @@ export function DragOperationManager<
monitor.dispatch('dragmove', {});
},
cancel() {
// TO-DO
status.value = Status.Dropping;

monitor.dispatch('dragend', {
operation: snapshot(operation),
canceled: true,
});

reset()
},
stop() {
status.value = Status.Dropping;
Expand All @@ -162,15 +177,7 @@ export function DragOperationManager<
canceled: false,
});

requestAnimationFrame(() => {
batch(() => {
status.value = Status.Idle;
sourceIdentifier.value = null;
targetIdentifier.value = null;
shape.value = null;
position.reset({x: 0, y: 0});
});
});
reset();
},
},
};
Expand Down
1 change: 0 additions & 1 deletion packages/dom/src/plugins/feedback/PlaceholderFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export class PlaceholderFeedback extends Plugin<DragDropManager> {
element.replaceWith(placeholder);
overlay.appendChild(element);
document.body.appendChild(overlay);
console.log('mount overlay');

return () => {
const clone = cloneElement(element);
Expand Down
Loading

0 comments on commit c63cefd

Please sign in to comment.