function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { Node } from 'prosemirror-model';
import { Decoration, EditorView } from 'prosemirror-view';
import { MARK_TEXT_COLOR, MARK_FONT_SIZE } from '../MarkNames.js';

// This implements the `NodeView` interface
// https://prosemirror.net/docs/ref/#view.NodeView
var ListItemNodeView = /*#__PURE__*/function () {
  function ListItemNodeView(node, editorView, getPos, decorations) {
    _classCallCheck(this, ListItemNodeView);
    // This implements the `NodeView` interface
    // The outer DOM node that represents the list item element.
    _defineProperty(this, "dom", void 0);
    // This implements the `NodeView` interface.
    // The DOM node that should hold the node's content.
    _defineProperty(this, "contentDOM", void 0);
    _defineProperty(this, "_nodeUpdated", void 0);
    var dom = document.createElement('li');
    this.dom = dom;
    this.contentDOM = dom;
    this._updateDOM(node);
  }

  // This implements the `NodeView` interface.
  return _createClass(ListItemNodeView, [{
    key: "update",
    value: function update(node, decorations) {
      return this._updateDOM(node);
    }
  }, {
    key: "_updateDOM",
    value: function _updateDOM(node) {
      if (this._nodeUpdated === node) {
        return false;
      }
      this._nodeUpdated = node;
      var dom = this.dom;
      // According to `ListItemNodeSpec`, a valid list item has the following
      // structure: `li > paragraph > text`.
      var paragraph = node.firstChild;
      var initialContent = paragraph ? paragraph.firstChild : null;

      // This resolves the styles for the counter by examines the marks for the
      // first text node of the list item.
      var marks = initialContent && initialContent.isText && initialContent.textContent ? initialContent.marks : null;
      var cssColor;
      var cssFontSize;
      var cssText = '';
      if (Array.isArray(marks)) {
        marks.forEach(function (mark) {
          var attrs = mark.attrs,
            type = mark.type;
          switch (type.name) {
            case MARK_TEXT_COLOR:
              cssColor = attrs.color;
              break;
            case MARK_FONT_SIZE:
              cssFontSize = attrs.pt;
              break;
          }
        });
      }

      // The counter of the list item is a pseudo-element that uses
      // the CSS variables (e.g `--czi-list-style-color`) for styling.
      // This defines the CSS variables scoped for the pseudo-element.
      // See `src/ui/czi-list.css` for more details.
      if (cssColor) {
        cssText += "--czi-list-style-color: ".concat(cssColor, ";");
      }
      if (cssFontSize) {
        cssText += "--czi-list-style-font-size: ".concat(cssFontSize, "pt;");
      }
      dom.style.cssText = cssText;
      var align = node.attrs.align;
      if (align) {
        dom.setAttribute('data-align', align);
      } else {
        dom.removeAttribute('data-align');
      }
      return true;
    }
  }]);
}();
export default ListItemNodeView;