Sha256: fbbdba2d1d9dee7cbd7e36c29afdf7976217e0591a0f1c94685478dad3035e3a

Contents?: true

Size: 1 KB

Versions: 22

Compression:

Stored size: 1 KB

Contents

import { Controller } from "@hotwired/stimulus";
import Item from "./item";

export default class ItemController extends Controller {
  get item() {
    return new Item(this.li);
  }

  get ol() {
    return this.element.closest("ol");
  }

  get li() {
    return this.element.closest("li");
  }

  connect() {
    if (this.element.dataset.hasOwnProperty("delete")) {
      this.remove();
    }
    // if index is not already set, re-index will set it
    else if (!(this.item.index >= 0)) {
      this.reindex();
    }
    // if item has been replaced via turbo, re-index will run the rules engine
    // update our depth and index with values from the li's data attributes
    else if (this.item.hasItemIdChanged()) {
      this.item.updateAfterChange();
      this.reindex();
    }
  }

  remove() {
    // capture ol
    const ol = this.ol;
    // remove self from dom
    this.li.remove();
    // reindex ol
    this.reindex();
  }

  reindex() {
    this.dispatch("reindex", { bubbles: true, prefix: "content" });
  }
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
katalyst-content-3.0.0.alpha.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.8.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.7.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.7.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.6.2 app/javascript/content/editor/item_controller.js
katalyst-content-2.6.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.6.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.5.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.5.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.4.2 app/javascript/content/editor/item_controller.js
katalyst-content-2.4.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.3.2 app/javascript/content/editor/item_controller.js
katalyst-content-2.3.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.3.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.2.0 app/javascript/content/editor/item_controller.js
katalyst-content-2.1.4 app/javascript/content/editor/item_controller.js
katalyst-content-2.1.3 app/javascript/content/editor/item_controller.js
katalyst-content-2.1.2 app/javascript/content/editor/item_controller.js
katalyst-content-2.1.1 app/javascript/content/editor/item_controller.js
katalyst-content-2.1.0 app/javascript/content/editor/item_controller.js