Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: port SnapCentertoCursor to experimental branch #1599

Open
wants to merge 4 commits into
base: experimental
Choose a base branch
from

Conversation

khuezy
Copy link

@khuezy khuezy commented Feb 4, 2025

No description provided.

Copy link

changeset-bot bot commented Feb 4, 2025

⚠️ No Changeset found

Latest commit: 5c53afb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@khuezy khuezy force-pushed the snapCenterToCursor branch from a946bd3 to 96e60bf Compare February 4, 2025 21:16
@khuezy
Copy link
Author

khuezy commented Feb 4, 2025

@clauderic Does the DragOverlay respect the modifier? When I add the DragOverlay, it doesn't get centered on cursor.

@clauderic
Copy link
Owner

You should be able to add a story here: apps/stories/stories/react/Draggable/Modifiers/Modifiers.stories.tsx

Something like:

export const SnapToCursor: Story = {
  name: 'Snap to cursor',
  args: {
    modifiers: [SnapCenterToCursor],
  },
};

@khuezy
Copy link
Author

khuezy commented Feb 5, 2025

There is an issue w/ the typing when I apply the modifier to the DragDropProvider:

Type 'typeof SnapCenterToCursor' is not assignable to type 'ModifierConstructor<DragDropManager<Draggable<Data>, Droppable<Data>>> | ModifierDescriptor<DragDropManager<Draggable<Data>, Droppable<...>>>'.
  Type 'typeof SnapCenterToCursor' is not assignable to type 'ModifierConstructor<DragDropManager<Draggable<Data>, Droppable<Data>>>'.
    Types of parameters 'manager' and 'manager' are incompatible.
      Type 'DragDropManager<Draggable<Data>, Droppable<Data>>' is not assignable to type 'DragDropManager<Draggable<Data, DragDropManager<any, any>>, Droppable<Data, DragDropManager<any, any>>>'.
        Types of property 'collisionObserver' are incompatible.
          Type 'CollisionObserver<Draggable<Data>, Droppable<Data>, DragDropManager<Draggable<Data>, Droppable<Data>>>' is not assignable to type 'CollisionObserver<Draggable<Data, DragDropManager<any, any>>, Droppable<Data, DragDropManager<any, any>>, DragDropManager<Draggable<Data,

The code runs correctly but typescript complains. I'm using DragDropProvider from @dnd-kit/react

@yf-yang
Copy link

yf-yang commented Feb 6, 2025

@khuezy There are two DragDropManager, one is from @dnd-kit/abstract and the other is from @dnd-kit/dom. That should be the cause

You can refer to RestrictToWindow's signature

@khuezy
Copy link
Author

khuezy commented Feb 6, 2025

The snap.ts in the abstract package includes the DragDropManage<Draggable, Droppable>, whereas the RestrictToWindow from the dom package doesn't. I'm not sure if omitting those two will lose types.

packages/dom/src/modifiers/index.ts Outdated Show resolved Hide resolved
@@ -8,15 +8,15 @@ import {
} from '@dnd-kit/abstract';

interface Options {
size: number | {x: number; y: number};
size: number | { x: number; y: number };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why your editor isn't respecting the prettier settings, it should be:

{
  "bracketSpacing": false,
  "singleQuote": true,
  "semi": true,
  "trailingComma": "es5"
}

Copy link
Author

@khuezy khuezy Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's really strange. I see the prettier loading .prettierrc but it's not applying those settings.
When I run bun format, it picks up 28 file changes... Should I include that or just leave everything as it is for you to format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants