Giter VIP home page Giter VIP logo

rescript-dnd's Introduction

rescript-dnd

npm version license build

Drag & drop for @rescript/react.

Features

  • Vertical lists
  • Horizontal lists
  • Multiple drop targets
  • Mouse & Touch interactions
  • Conditional drag & drop
  • Custom drag handles
  • Scrollable containers
  • Auto-scroll when dragging at container's edge

ShakaCode

If you are looking for help with the development and optimization of your project, ShakaCode can help you to take the reliability and performance of your app to the next level.

If you are a developer interested in working on ReScript / TypeScript / Rust / Ruby on Rails projects, we're hiring!

Installation

# yarn
yarn add rescript-dnd rescript-webapi
# or npm
npm install --save rescript-dnd rescript-webapi

Then add it to bsconfig.json:

"bs-dependencies": [
  "rescript-dnd",
  "rescript-webapi"
]

Docs

Examples

State

๐Ÿšง The library is not feature-complete and some features/apis might be missing.
๐ŸŽ™ Let us know if you miss anything via creating an issue.
๐ŸŒŽ We're using it in production BTW.

Features we'd like to add at some point

  • Keyboard interactions
  • Ignore form elements (opt-out)
  • Drop-zones
  • Multi-select

Thanks

License

MIT.

Supporters

JetBrains ScoutAPM
BrowserStack Rails Autoscale Honeybadger

The following companies support our open source projects, and ShakaCode uses their products!

rescript-dnd's People

Contributors

alex35mil avatar alexfedoseev avatar dfalling avatar tomis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rescript-dnd's Issues

Nested list support

Is there a way to have lists within lists, for example in a nested list hierarchy like so?

- A
    - A1
        -A1a
        -A1b
    -A2
-B

Consider moving Webapi to peer dependency

Not in any way a critical issue, just something to think about...

I'd argue Webapi is almost as common as reason-react as a dependency. So when most people have it installed anyway, it will cause awkward "Duplicated package" warning that could be avoided just by defining it as a peer dependency.

Error: internal error, using unrecognized primitive #raw_function

I have installed re-dnd and added it to bsconfig.json. Then when I compile my project I get

[141/255] Building src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.cmj
FAILED: src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.cmj src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.cmi /home/a-c-sreedhar-reddy/***/demo/node_modules/bs-webapi/src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.js 
/home/a-c-sreedhar-reddy/***/demo/node_modules/bs-platform/linux/bsc.exe -color always -bs-package-name bs-webapi  -bs-package-output es6:src/Webapi/Webapi__Dom -I src/Webapi/Webapi__ResizeObserver -I src/Webapi/Webapi__Dom -I src/Webapi/Webapi__Canvas -I src/Webapi -I src -w a -bs-no-version-header -bs-super-errors -o src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.cmj src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.reast

  We've found a bug for you!
  /home/a-c-sreedhar-reddy/***/demo/node_modules/bs-webapi/src/Webapi/Webapi__Dom/Webapi__Dom__DomStringMap.re 11:5-7
  
   9 โ”‚ let set = (key, value, map) => set(map, key, value);
  10 โ”‚ let unsafeDeleteKey: (key, t) => unit =  
  11 โ”‚   [%raw (key, map) => "delete map[key];"];
  12 โ”‚   
  
  Error: internal error, using unrecognized primitive #raw_function
  
[146/255] Building src/Webapi/Webapi__Dom/Webapi__Dom__EventTarget.cmj
FAILED: subcommand failed.
Failure: /home/a-c-sreedhar-reddy/***/demo/node_modules/bs-platform/linux/ninja.exe 
 Location: /home/a-c-sreedhar-reddy/***/demo/node_modules/bs-webapi/lib/bs

Can't set "cursor" CSS property on DraggableItem

I wanted to update the cursor for my Draggable Items to be grab and then grabbing while dragging, but it wasn't working. In doing some digging, I've found that adding pointer-events: none disables the use cursor (yay CSS ๐Ÿ™„).

I definitely understand the reasoning behind setting pointer-events: none, but I wonder if there'd be way to set it on the underlying child of DraggableItem instead of that <div/> itself, so you could still set the cursor prop of the div? ๐Ÿค”

There may not be an easy/workable fix here, but I figured I'd file it anyway just to see if you had any ideas. Thanks!

Not compatible with rescript-react version 0.11

Compilation throws this error:

FAILED: src/Dnd__DndManager.cmj

  We've found a bug for you!
  /home/development/app/node_modules/rescript-dnd/src/Dnd__DndManager.res:1586:13-1602:7

  1584 โ”† 
  1585 โ”† <Context.Provider
  1586 โ”†   value={
  1587 โ”†     status: state.status,
     . โ”† ...
  1601 โ”†     startDragging: collectEntries,
  1602 โ”†   }>
  1603 โ”†   children
  1604 โ”† </Context.Provider>

  The record field value can't be found.
  
  If it's defined in another module or file, bring it into scope by:
  - Prefixing it with said module name: TheModule.value
  - Or specifying its type: let theValue: TheModule.theType = {value: VALUE}

For more info: https://rescript-lang.org/docs/react/latest/migrate-react

Do another release

We are upgrading all of our packages to use rescript (moving from reason) and seems like res-logger doesn't work. Looking at master, this has been changed to rescript-logger but the npm package hasn't been updated to reflect this.

Can you please do another release. Thank you.

API for `isDragging` other than className

Just started using this lib and it was so easy to get up and running - thanks so much!

I was wondering what you thought of adding a way to know when the Items.DraggableItem component was in the midst of being dragged, other than just when specifying the className prop. My use case is that my app uses React Native Web, so the styling API isn't based on class names. I can think of a few escape hatches I could use, but it'd be great if the library supported tracking that state change somehow.

Not sure if it'd make more sense to add another variant for the component's children that was a render function that contained the state, or possibly it'd make more sense to have another handler at the DndManager level that fired whenever an item started being dragged so you could do a more global state update if you needed? I'm sure you've got a better handle on what would be best performance-wise!

Thanks!

Replace bs-webapi with rescript-webapi?

Looks like bs-webapi hasn't been touched in a year, whereas rescript-webapi is under active development (I'm not affiliated with either). If the bindings are the same but just updated, then might be good to update this.

Would also be great to add a note to Readme to go install that package too (not sure if it's obvious for others but I'm new to Rescript and was a bit surprised).

Map.getExn raising when creating new items

Hello,
I have an issue with re-dnd. What I'm trying to do is: I have a static list of "source" items, that can be inserted (without being removed) into another drag zone.

When I drop an item, Option.getExn is raised.

Here is an (almost) minimal reproducing code:


module Id = {
  type t = int;
  let current = ref(0);

  let make = () => {
    current := 1 + current^;
    current^ - 1;
  };
};

module Item = {
  type t = (Id.t, string);

  let eq = (x1, x2) => x1 == x2; // or more concise: let eq = (==);
  let cmp = compare; // default comparator from Pervasives module
};

module Container = {
  type t =
    | A
    | B;
  let eq = (x1, x2) => x1 == x2; // or more concise: let eq = (==);
  let cmp = compare; // default comparator from Pervasives module
};

let sources = ["a", "b", "c"];

module MyDrag = Dnd.Make(Item, Container);

[@react.component]
let make = () => {
  let reducer = (state, action: Dnd.result(Item.t, Container.t)) => {
    switch (action) {
    | Some(SameContainer(todoId, placement)) =>
      Js.log3("Drag same", todoId, placement);
      state;
    | Some(NewContainer(todoId, targetId, placement)) =>
      Js.log4("Drag new", todoId, targetId, placement);
      [todoId, ...state];
    | None => state
    };
  };

  let (state, dispatch) = React.useReducer(reducer, [((-2), "z"), ((-1), "y")]);

  let rowStyle = ReactDOMRe.Style.make(~display="flex", ~flexDirection="row", ());

  let dndZoneStyle =
    ReactDOMRe.Style.make(~minWidth="100px", ~minHeight="100px", ~background="lightgrey", ~border="1px solid", ());

  <div style=rowStyle>
    <MyDrag.DndManager onReorder={res => dispatch(res)}>
      <MyDrag.DroppableContainer id=A axis=Y>
        <div style=dndZoneStyle>
          {List.mapi(
             (index, item) => {
               <MyDrag.DraggableItem id=(Id.make(), item) containerId=A index key=item>
                 {`Children(item->React.string)}
               </MyDrag.DraggableItem>
             },
             sources,
           )
           ->Array.of_list
           ->React.array}
        </div>
      </MyDrag.DroppableContainer>
      <MyDrag.DroppableContainer id=B axis=Y>
        <div style=dndZoneStyle>
          {List.mapi(
             (index, (id, item)) => {
               <MyDrag.DraggableItem id=(id, item) containerId=B index key=item>
                 {`Children(item->React.string)}
               </MyDrag.DraggableItem>
             },
             state,
           )
           ->Array.of_list
           ->React.array}
        </div>
      </MyDrag.DroppableContainer>
    </MyDrag.DndManager>
  </div>;
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.