How to use the dragula function in dragula

To help you get started, we’ve selected a few dragula examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ant-design / ant-design-landing / site / edit / template / components / EditStageController.jsx View on Github external
componentDidMount() {
    // 接收子级里传来的 dom 数据;
    // window.addEventListener('message', this.receiveDomData);
    window.receiveDomData = this.receiveDomData;
    // 重置框
    window.addEventListener('resize', () => {
      this.reRect();
    });
    // 拖动
    let newId;
    this.side = document.querySelector('.edit-side-drawer .drawer-content .img-content-wrapper');
    this.stage = document.querySelector('.edit-stage .overlay');

    let stateChild;
    const t = dragula([this.side, this.stage], {
      copy: (el, source) => source === this.side,
      moves: (el, container, handle) => (
        handle.classList.contains('drag-hints') || handle.classList.contains('img')
        || handle.tagName.toLocaleLowerCase() === 'img'
      ),
      accepts: (el, source) => {
        if (source === this.stage) {
          const elKey = el.getAttribute('data-key');
          const data = this.state.data;
          const dArr = Object.keys(data).filter((key) => key.split('_')[0] === elKey)
            .map((key) => parseFloat(key.split('_')[1])).sort((a, b) => a - b);
          newId = `${elKey}_${(dArr[dArr.length - 1] + 1) || 0}`;
          const sourceArray = Array.prototype.slice.call(source.children);
          stateChild = stateChild || sourceArray;
          const placeholder = source.querySelectorAll('.placeholder')[0];
          const ci = sourceArray.indexOf(placeholder);
github Astray-git / vue-dragula / src / vue-dragula.js View on Github external
const bagName = vnode
        ? vnode.data.attrs.bag // Vue 2
        : this.params.bag // Vue 1
      if (!vnode) {
        container = this.el // Vue 1
      }
      if (bagName !== undefined && bagName.length !== 0) {
        name = bagName
      }
      const bag = service.find(name)
      if (bag) {
        drake = bag.drake
        drake.containers.push(container)
        return
      }
      drake = dragula({
        containers: [container]
      })
      service.add(name, drake)

      service.handleModels(name, drake)
    },
github marktext / marktext / src / renderer / components / editorWithTabs / tabs.vue View on Github external
this.$nextTick(() => {
      const tabs = this.$refs.tabContainer

      // Allow to scroll through the tabs by mouse wheel or touchpad.
      tabs.addEventListener('wheel', this.handleTabScroll)

      // Allow tab drag and drop to reorder tabs.
      const drake = this.drake = dragula([this.$refs.tabDropContainer], {
        direction: 'horizontal',
        revertOnSpill: true,
        mirrorContainer: this.$refs.tabDropContainer,
        ignoreInputTextSelection: false
      }).on('drop', (el, target, source, sibling) => {
        // Current tab that was dropped and need to be reordered.
        const droppedId = el.getAttribute('data-id')
        // This should be the next tab (tab | ... | el | sibling | tab | ...) but may be
        // the mirror image or null (tab | ... | el | sibling or null) if last tab.
        const nextTabId = sibling && sibling.getAttribute('data-id')
        const isLastTab = !sibling || sibling.classList.contains('gu-mirror')
        if (!droppedId || (sibling && !nextTabId)) {
          throw new Error('Cannot reorder tabs: invalid tab id.')
        }

        this.$store.dispatch('EXCHANGE_TABS_BY_ID', {
github Autodesk-Forge / forge-boilers.nodejs / 7 - viewer+extension+server+data-mng+derivatives / src / client / utils / TabManager / TabManager.js View on Github external
this.containerId = this.guid()
    this.class = this.guid()
    this.nbTabs = 0

    var html = `
      <div class="c${this.class} tabs" id="${this.containerId}">
        <ul class="headers" id="${this.tabsHeaderId}">
        </ul>
      </div>
    `

    $(container).append(html)

    if (opts.allowDrag) {

      this.drake = dragula(
        [$(`#${this.tabsHeaderId}`)[0]],
        {removeOnSpill: false})

      var drakeEvents = [
        'drag', 'dragend', 'drop', 'cancel', 'remove'
      ]

      drakeEvents.forEach((event) =&gt; {

        this.drake.on(event, () =&gt; {

          this.emit('drake.' + event, arguments)
        })
      })
    }
  }
github danilosampaio / semantic-kanban / src / semanticKanban.vue View on Github external
configDragula () {
				const self = this
				/*
					Disable swipe-history-navigation
					https://superuser.com/questions/840102/how-do-you-disable-swipe-history-navigation
					Go to chrome://flags/#overscroll-history-navigation
					Disable the Overscroll history navigation experiment:
				*/
				var drake = dragula({
					isContainer: function (el) {
						return el.classList.contains('todo') ||
							el.classList.contains('doing') ||
							el.classList.contains('blocked') ||
							el.classList.contains('done')
					},
					moves: function (el, target, source, sibling) {
						var owner = $(target).attr('owner')
						var status = $(target).attr('class').split(' ').reverse()[0]

						var sourceOwner = $(source).attr('owner')
						var sourceStatus = $(source).attr('class').split(' ').reverse()[0]

						if (owner !== sourceOwner || status !== sourceStatus) {
							return true
						} else {
github WebVella / WebVella-ERP / WebVella.Erp.Site / wwwroot / js / wv-pb-manager / collection / components / wv-pb-manager / wv-pb-manager.js View on Github external
initStore.componentMeta[component["name"]] = component;
        });
        this.store.setStore(configureStore(initStore));
        this.store.mapStateToProps(this, (state) => {
            return {
                pageNodes: state.pageNodes
            };
        });
        this.store.mapDispatchToProps(this, {
            setDrake: action.setDrake,
            addReloadNodeIds: action.addReloadNodeIds,
            updatePageNodes: action.updatePageNodes,
            removeNode: action.removeNode
        });
        let scope = this;
        let drake = dragula({
            revertOnSpill: false,
            direction: 'vertical',
        });
        drake.on('drop', function (el, target, source) {
            let newIndex = 0;
            _.forEach(el.parentElement.childNodes, function (node) {
                if (node === el) {
                    return false;
                }
                newIndex++;
            });
            var moveInfo = {
                originContainerId: source.getAttribute("data-container-id"),
                originParentNodeId: source.getAttribute("data-parent-id"),
                newContainerId: target.getAttribute("data-container-id"),
                newParentNodeId: target.getAttribute("data-parent-id"),
github kubenstein / starboard / src / frontend / components / dndSupport / dnd-columns-configurator.js View on Github external
setup() {
    return Dragula([], {
      direction: 'horizontal',
      moves: (_el, _container, handle) => handle.classList.contains(this.dndHandlerCssClass),
    });
  }
github funday-force / funday.com / src / Components / Dashboard / Boards / Items.js View on Github external
render() {
    var d = dragula({
      moves: function(el, cont, handle) {
        return handle.className !== 'title';
      }
    });
    var cs = document.querySelectorAll('.listI');
    for (var i in cs) {
      d.containers.push(cs[i]);
    }
    let items = this.state.items;
    return (
      <div>
        <ul>
          {items.map(item =&gt; (
            </ul></div>
github Nks / orchid-repeater-field / resources / js / controllers / fields / repeater_controller.js View on Github external
initDragDrop() {
        let self = this;

        this.drake = dragula([this.blocksTarget], {
            moves: function (el, container, handle) {
                let isCorrectHandle = (handle.dataset.parentContainerKey === self.blocksTarget.dataset.containerKey);

                return handle.classList.contains('card-handle') && isCorrectHandle;
            }
        }).on('drop', () => {
            this.sort();
        });

        return this;
    }
github accera-tech / solar-components / src / components / organisms / ac-pick-list / ac-pick-list.tsx View on Github external
componentDidRender() {
    const drake = dragula([this.acListAvalibles.querySelector('.ac-list'), this.acListSelectedOptions.querySelector('.ac-list')], {
      invalid: (el: HTMLElement) => {
        return el.classList.contains('ac-list__list-separator');
      }
    });
    drake
    .on('drop', (el, target, source) => {
        drake.cancel(true);
        if (!source.parentElement || !target.parentElement) {
          return;
        }
        const acListSource = source.parentElement.parentElement;
        const acListTarget = target.parentElement.parentElement;
        if (acListTarget === acListSource) {
          return;
        }
        const option = acListSource.options.find(x => x.value.toString() === el.value.toString());

dragula

Drag and drop so simple it hurts

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis