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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
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 toCSSColor from './ui/toCSSColor.js';
import { Node } from 'prosemirror-model';
import { tableNodes } from 'prosemirror-tables';
var NO_VISIBLE_BORDER_WIDTH = new Set(['0pt', '0px']);

// https://github.com/ProseMirror/prosemirror-tables/blob/master/demo.js
var TableNodesSpecs = tableNodes({
  tableGroup: 'block',
  cellContent: 'block+',
  cellAttributes: {
    className: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        return dom.getAttribute('class') || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          attrs["class"] = value;
        }
      }
    },
    borderTop: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        return dom.style.borderTop || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          attrs.style = (attrs.style || '') + ";border-top: ".concat(value, ";");
        }
      }
    },
    borderRight: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        return dom.style.borderRight || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          attrs.style = (attrs.style || '') + ";border-right: ".concat(value, ";");
        }
      }
    },
    borderBottom: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        return dom.style.borderBottom || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          attrs.style = (attrs.style || '') + ";border-bottom: ".concat(value, ";");
        }
      }
    },
    borderLeft: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        return dom.style.borderLeft || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          attrs.style = (attrs.style || '') + ";border-left: ".concat(value, ";");
        }
      }
    },
    borderColor: {
      "default": null,
      getFromDOM: function getFromDOM(dom) {
        var _dom$style = dom.style,
          borderColor = _dom$style.borderColor,
          borderWidth = _dom$style.borderWidth;
        if (NO_VISIBLE_BORDER_WIDTH.has(borderWidth)) {
          return 'transparent';
        }
        return borderColor && toCSSColor(borderColor) || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          var colorValue = String(value);
          attrs.style = (attrs.style || '') + ";border-color: ".concat(colorValue, ";");
        }
      }
    },
    background: {
      "default": null,
      // TODO: Move these to a table helper.
      getFromDOM: function getFromDOM(dom) {
        return dom.style.backgroundColor || null;
      },
      setDOMAttr: function setDOMAttr(value, attrs) {
        if (value) {
          var colorValue = String(value);
          attrs.style = (attrs.style || '') + ";background-color: ".concat(colorValue, ";");
        }
      }
    }
  }
});

// Override the default table node spec to support custom attributes.
var TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
  attrs: _objectSpread(_objectSpread({}, TableNodesSpecs.table.attrs), {}, {
    marginLeft: {
      "default": null
    },
    dirty: {
      "default": false
    },
    coverPage: {
      "default": false
    }
  }),
  parseDOM: [{
    tag: 'table',
    getAttrs: function getAttrs(dom) {
      var dirty = dom.getAttribute('dirty') || false;
      var coverPage = dom.getAttribute('data-cover-page') === 'true';
      var marginLeft = dom.style.marginLeft;
      var attrs = {
        dirty: dirty,
        coverPage: coverPage
      };
      if (marginLeft && /\d+px/.test(marginLeft)) {
        attrs.marginLeft = parseFloat(marginLeft);
      }
      return attrs;
    }
  }],
  toDOM: function toDOM(node) {
    // Normally, the DOM structure of the table node is rendered by
    // `TableNodeView`. This method is only called when user selects a
    // table node and copies it, which triggers the "serialize to HTML" flow
    //  that calles this method.
    var _node$attrs = node.attrs,
      marginLeft = _node$attrs.marginLeft,
      dirty = _node$attrs.dirty,
      coverPage = _node$attrs.coverPage;
    var domAttrs = {};
    if (marginLeft) {
      domAttrs.style = "margin-left: ".concat(marginLeft, "px");
    }
    if (dirty) {
      domAttrs.dirty = dirty;
    }
    if (coverPage) {
      domAttrs['data-cover-page'] = 'true';
    }
    return ['table', domAttrs, 0];
  }
});
Object.assign(TableNodesSpecs, {
  table: TableNodeSpec
});
export default TableNodesSpecs;