Skip to content

Drag placeholder for rendered elements #705

Closed

Description

@austinbiggs

Hello! I'm digging through code and I'm trying to achieve a placeholder effect while dragging the element? Something similar already exists for dragging blocks.

If I want to add something to achieve this, what method would I need to modify/hook into? I don't see a startDrag option for elements on the canvas.

  /**
   * Start block dragging
   * @private
   */
  startDrag: function startDrag(e) {
    //Right or middel click
    if (e.button !== 0) {
      return;
    }

    if (!this.config.getSorter) {
      return;
    }

    this.config.em.refreshCanvas();
    var sorter = this.config.getSorter();
    sorter.setDragHelper(this.el, e);
    sorter.setDropContent(this.model.get('content'));
    sorter.startSort(this.el);
    (0, _mixins.on)(document, 'mouseup', this.endDrag);
  },

similar to: http://gridstackjs.com/

Activity

  1. artf commented on Jan 4, 2018

    @artf
    Member

    Actually, I was thinking about adding such a functionality but didn't go so far 😬
    https://github.com/artf/grapesjs/blob/dev/src/commands/view/MoveComponent.js#L74

  2. austinbiggs commented on Jan 4, 2018

    @austinbiggs
    Author

    @artf - May I ask why you stopped the implementation?

    If it's something I believe I can solve, I'd like to try to finish it and make a PR.

  3. artf commented on Jan 4, 2018

    @artf
    Member

    I don't remember exactly why but I'd appreciate a PR for this (preferably disabled by default and activable via configuration)

  4. austinbiggs commented on Jan 4, 2018

    @austinbiggs
    Author

    @artf - I was playing around with it, and if the user is dragging an element that isn't a photo, it looks a bit funny, since the CSS doesn't apply to the elements in the placeholder. Any thoughts?

  5. artf commented on Jan 4, 2018

    @artf
    Member

    Probably the reason of why I gave up 😂
    As you see from here
    https://github.com/artf/grapesjs/blob/dev/src/commands/view/MoveComponent.js#L74
    I tried using setDragHelper which copies the element's style from getComputedStyle but I also remove its children dragHelper.innerHTML = '' as getting inners style could be too much expensive. At the moment, I see these possible solutions:

    1. Show only the shape of the element
    2. Let the user define its function which returns the placeholder element
    3. Find a way to use the native HTML5 d&d "ghost" image (creates already a screenshot of the element). One of the problems with this is to trigger drag event by clicking external element (in our case move icon)
  6. austinbiggs commented on Jan 19, 2018

    @austinbiggs
    Author

    @artf - Do you think this would be easier now that GrapesJS uses native DnD?

  7. artf commented on Jan 20, 2018

    @artf
    Member

    Unfortunately, moving components is slightly different so I'm still working on this

  8. ahmeddabak commented on Mar 2, 2018

    @ahmeddabak

    Hi @artf @AustinTBiggs , what is the status for this feature.
    i am thinking about doing some work on it this week end 😃

  9. artf commented on Mar 4, 2018

    @artf
    Member

    Still in progress @ahmeddabak
    I was trying to make native DnD work also on components inside the canvas (for now its enabled for blocks and external d&d). Doesn't seem like a big deal but the problem is to trigger it from the 'move' toolbar button.
    Here you find how to activate the dragstart event on the button https://github.com/artf/grapesjs/blob/dev/src/dom_components/model/Component.js#L535
    The logic of setting up the DragImage is inside tlb-move https://github.com/artf/grapesjs/blob/dev/src/commands/index.js#L143

  10. jacobisknight commented on Nov 3, 2022

    @jacobisknight
    Contributor

    I know it's been 4 years since this feature was last discussed. Any possibility that it will be completed?

  11. locked and limited conversation to collaborators on Aug 10, 2023
  12. converted this issue into a discussion #5294 on Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions