Sha256: abe40a96f0747a9610df19b9239b9d0e91c5f97040d032fe8ffa5d713d1bdbe8

Contents?: true

Size: 707 Bytes

Versions: 6

Compression:

Stored size: 707 Bytes

Contents

import { Controller } from "@hotwired/stimulus"
import { put } from "https://cdn.skypack.dev/@rails/request.js@0.0.11"
import Sortable from "https://cdn.skypack.dev/sortablejs"

export default class extends Controller {
  static values  = { url: String, group: String, handle: String }

  connect() {
    this.sortable = new Sortable(this.element, this.#options)
  }

  disconnect() {
    this.sortable.destroy()
  }

  #submit({ item, newIndex, to }) {
    put(item.dataset.urlValue, { query: { position: newIndex, parent_id: to.dataset.parentId } })
  }

  get #options() {
    return { animation: 150, onAdd: this.#submit, onUpdate: this.#submit, group: this.groupValue, handle: this.handleValue }
  }
}

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
css-zero-0.0.70 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js
css-zero-0.0.69 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js
css-zero-0.0.68 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js
css-zero-0.0.67 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js
css-zero-0.0.66 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js
css-zero-0.0.65 lib/generators/css_zero/add/templates/app/javascript/controllers/sortable_controller.js