@progress/kendo-editor-common 1.6.1-dev.202112152003 → 1.7.0-dev.202201030643

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
+ var prosemirror_model_1 = require("prosemirror-model");
4
5
  var prosemirror_tables_1 = require("prosemirror-tables");
6
+ var source_1 = require("../source");
7
+ var constants_1 = require("./constants");
5
8
  var hole = 0;
6
9
  var blockquoteDOM = ['blockquote', hole], hrDOM = ['hr'], preDOM = ['pre', ['code', hole]];
7
10
  var olDOM = ['ol', 0], ulDOM = ['ul', 0], liDOM = ['li', 0];
8
- var getAttributes = function (dom) {
11
+ var domAttributes = function (dom) {
9
12
  var result = {};
10
13
  var attributes = dom.attributes, attr;
11
14
  for (var i = 0; i < attributes.length; i++) {
@@ -14,13 +17,14 @@ var getAttributes = function (dom) {
14
17
  }
15
18
  return result;
16
19
  };
17
- var commonAttributes = function () {
18
- return {
19
- style: { default: null },
20
- class: { default: null },
21
- id: { default: null }
22
- };
20
+ var defaultAttrs = function (attrs) {
21
+ var nodeAttrs = {};
22
+ attrs.forEach(function (attr) {
23
+ nodeAttrs[attr] = { default: null };
24
+ });
25
+ return nodeAttrs;
23
26
  };
27
+ var commonAttributes = function () { return defaultAttrs(['style', 'class', 'id']); };
24
28
  var hasAttrs = function (attrs, exclude) {
25
29
  for (var attr in attrs) {
26
30
  if (attr && attrs[attr] !== null && attr !== exclude) {
@@ -29,7 +33,7 @@ var hasAttrs = function (attrs, exclude) {
29
33
  }
30
34
  return false;
31
35
  };
32
- var getAttrs = function (attrs, exclude) {
36
+ var pmAttributes = function (attrs, exclude) {
33
37
  var result = {};
34
38
  for (var attr in attrs) {
35
39
  if (attr && attrs[attr] !== null && attr !== exclude) {
@@ -56,18 +60,92 @@ var marks = tslib_1.__assign({
56
60
  link: {
57
61
  attrs: tslib_1.__assign({}, commonAttributes(), { href: { default: null }, target: { default: null }, title: { default: null } }),
58
62
  inclusive: false,
59
- parseDOM: [{ tag: 'a', getAttrs: getAttributes }],
60
- toDOM: function (node) { return ['a', getAttrs(node.attrs), hole]; }
63
+ parseDOM: [{ tag: 'a', getAttrs: domAttributes }],
64
+ toDOM: function (node) { return ['a', pmAttributes(node.attrs), hole]; }
61
65
  } }, tagMark('strong'), tagMark('b'), tagMark('em'), tagMark('i'), tagMark('u'), tagMark('del'), tagMark('sub'), tagMark('sup'), tagMark('code'), { style: {
62
66
  attrs: tslib_1.__assign({}, commonAttributes()),
63
67
  parseDOM: [{
64
68
  tag: 'span',
65
- getAttrs: getAttributes
69
+ getAttrs: domAttributes
66
70
  }],
67
71
  toDOM: function (node) { return hasAttrs(node.attrs) ?
68
- ['span', getAttrs(node.attrs), hole] : ['span', hole]; }
72
+ ['span', pmAttributes(node.attrs), hole] : ['span', hole]; }
69
73
  } });
70
74
  exports.marks = marks;
75
+ var cellAttribute = function (name) {
76
+ var _a;
77
+ return _a = {},
78
+ _a[name] = {
79
+ default: null,
80
+ getFromDOM: function (cell) { return cell.getAttribute(name); },
81
+ setDOMAttr: function (value, attrs) { attrs[name] = value; }
82
+ },
83
+ _a;
84
+ };
85
+ var cellAttributes = tslib_1.__assign({}, cellAttribute('style'), cellAttribute('class'), cellAttribute('id'), cellAttribute('headers'));
86
+ var colgroupNodes = {
87
+ doc: { content: 'colgroup*' },
88
+ col: {
89
+ attrs: defaultAttrs(['id', 'class', 'style', 'span']),
90
+ parseDOM: [{ getAttrs: domAttributes, tag: 'col' }],
91
+ toDOM: function (node) { return ['col', node.attrs]; }
92
+ },
93
+ colgroup: {
94
+ attrs: defaultAttrs(['id', 'class', 'style', 'span']),
95
+ content: 'col*',
96
+ parseDOM: [{ getAttrs: domAttributes, tag: 'colgroup' }],
97
+ toDOM: function (node) { return ['colgroup', node.attrs, 0]; }
98
+ },
99
+ text: { inline: true, group: 'inline' }
100
+ };
101
+ var colgroupSchema = new prosemirror_model_1.Schema({ nodes: colgroupNodes, marks: {} });
102
+ // will be removed when we implement our own columnResizing
103
+ var shouldSkipColgroup = function (node) {
104
+ var shouldSkip = false;
105
+ var row = node.child(0);
106
+ for (var r = 0; r < row.childCount; r++) {
107
+ var cell = row.child(r);
108
+ if (cell.attrs.colwidth) {
109
+ shouldSkip = true;
110
+ break;
111
+ }
112
+ }
113
+ return shouldSkip;
114
+ };
115
+ var tNodes = prosemirror_tables_1.tableNodes({ tableGroup: 'block', cellContent: 'block+', cellAttributes: cellAttributes });
116
+ tNodes.table_row.attrs = tslib_1.__assign({}, tNodes.table_row.attrs, defaultAttrs([constants_1.rowTypeAttr, 'style', 'class', 'id']));
117
+ tNodes.table_row.toDOM = function (node) { return ['tr', pmAttributes(node.attrs), 0]; };
118
+ tNodes.table_row.parseDOM = [{ tag: 'tr', getAttrs: domAttributes }];
119
+ tNodes.table.attrs = tslib_1.__assign({}, tNodes.table.attrs, defaultAttrs(['style', 'class', 'id', constants_1.colgroupAttr]));
120
+ tNodes.table.toDOM = function (node) {
121
+ var tableAttrs = hasAttrs(node.attrs) ? pmAttributes(node.attrs, constants_1.colgroupAttr) : {};
122
+ var colgroup = null;
123
+ if (node.attrs[constants_1.colgroupAttr] && !shouldSkipColgroup(node)) {
124
+ var doc = source_1.domToPmDoc(source_1.htmlToFragment(node.attrs[constants_1.colgroupAttr]), colgroupSchema, { preserveWhitespace: false });
125
+ var fragment = source_1.pmDocToFragment(doc);
126
+ var colgroupEl = fragment.firstChild;
127
+ if (colgroupEl) {
128
+ var cols = Array.from(colgroupEl.children).map(function (c) { return ['col', domAttributes(c)]; });
129
+ colgroup = [
130
+ 'colgroup',
131
+ domAttributes(colgroupEl)
132
+ ].concat(cols);
133
+ }
134
+ }
135
+ return colgroup ? ['table', tableAttrs, colgroup, ['tbody', 0]] :
136
+ ['table', tableAttrs, ['tbody', 0]];
137
+ };
138
+ tNodes.table.parseDOM = [{
139
+ tag: 'table',
140
+ getAttrs: function (node) {
141
+ var attrs = domAttributes(node);
142
+ var colgroup = Array.from(node.childNodes).find(function (c) { return c.nodeName === 'COLGROUP'; });
143
+ if (colgroup) {
144
+ attrs[constants_1.colgroupAttr] = colgroup.outerHTML;
145
+ }
146
+ return attrs;
147
+ }
148
+ }];
71
149
  var nodes = tslib_1.__assign({
72
150
  // :: NodeSpec The top level document node.
73
151
  doc: {
@@ -81,9 +159,9 @@ var nodes = tslib_1.__assign({
81
159
  attrs: tslib_1.__assign({}, commonAttributes()),
82
160
  parseDOM: [{
83
161
  tag: 'p',
84
- getAttrs: getAttributes
162
+ getAttrs: domAttributes
85
163
  }],
86
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['p', getAttrs(node.attrs), hole] : ['p', hole]; }
164
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['p', pmAttributes(node.attrs), hole] : ['p', hole]; }
87
165
  }, div: {
88
166
  // Uncaught SyntaxError: Mixing inline and block content (in content expression '(block | inline)*')
89
167
  // content: '(block | inline)*',
@@ -92,9 +170,9 @@ var nodes = tslib_1.__assign({
92
170
  attrs: tslib_1.__assign({}, commonAttributes()),
93
171
  parseDOM: [{
94
172
  tag: 'div',
95
- getAttrs: getAttributes
173
+ getAttrs: domAttributes
96
174
  }],
97
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['div', getAttrs(node.attrs), hole] : ['div', hole]; }
175
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['div', pmAttributes(node.attrs), hole] : ['div', hole]; }
98
176
  },
99
177
  // :: NodeSpec A blockquote (`<blockquote>`) wrapping one or more blocks.
100
178
  blockquote: {
@@ -104,9 +182,9 @@ var nodes = tslib_1.__assign({
104
182
  defining: true,
105
183
  parseDOM: [{
106
184
  tag: 'blockquote',
107
- getAttrs: getAttributes
185
+ getAttrs: domAttributes
108
186
  }],
109
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['blockquote', getAttrs(node.attrs), hole] : blockquoteDOM; }
187
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['blockquote', pmAttributes(node.attrs), hole] : blockquoteDOM; }
110
188
  },
111
189
  // :: NodeSpec A horizontal rule (`<hr>`).
112
190
  horizontal_rule: {
@@ -123,15 +201,15 @@ var nodes = tslib_1.__assign({
123
201
  group: 'block',
124
202
  defining: true,
125
203
  parseDOM: [
126
- { tag: 'h1', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 1 })); } },
127
- { tag: 'h2', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 2 })); } },
128
- { tag: 'h3', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 3 })); } },
129
- { tag: 'h4', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 4 })); } },
130
- { tag: 'h5', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 5 })); } },
131
- { tag: 'h6', getAttrs: function (node) { return (tslib_1.__assign({}, getAttributes(node), { level: 6 })); } }
204
+ { tag: 'h1', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 1 })); } },
205
+ { tag: 'h2', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 2 })); } },
206
+ { tag: 'h3', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 3 })); } },
207
+ { tag: 'h4', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 4 })); } },
208
+ { tag: 'h5', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 5 })); } },
209
+ { tag: 'h6', getAttrs: function (node) { return (tslib_1.__assign({}, domAttributes(node), { level: 6 })); } }
132
210
  ],
133
211
  toDOM: function (node) { return hasAttrs(node.attrs, 'level') ?
134
- ['h' + node.attrs.level, getAttrs(node.attrs, 'level'), hole] :
212
+ ['h' + node.attrs.level, pmAttributes(node.attrs, 'level'), hole] :
135
213
  ['h' + node.attrs.level, hole]; }
136
214
  },
137
215
  // :: NodeSpec A code listing. Disallows marks or non-text inline
@@ -159,8 +237,8 @@ var nodes = tslib_1.__assign({
159
237
  attrs: tslib_1.__assign({ src: { default: null }, alt: { default: null }, title: { default: null }, width: { default: null }, height: { default: null } }, commonAttributes()),
160
238
  group: 'inline',
161
239
  draggable: true,
162
- parseDOM: [{ tag: 'img', getAttrs: getAttributes }],
163
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['img', getAttrs(node.attrs)] : ['img']; }
240
+ parseDOM: [{ tag: 'img', getAttrs: domAttributes }],
241
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['img', pmAttributes(node.attrs)] : ['img']; }
164
242
  },
165
243
  // :: NodeSpec A hard line break represented in the DOM as a `<br>` element.
166
244
  hard_break: {
@@ -170,9 +248,9 @@ var nodes = tslib_1.__assign({
170
248
  selectable: false,
171
249
  parseDOM: [{
172
250
  tag: 'br',
173
- getAttrs: getAttributes
251
+ getAttrs: domAttributes
174
252
  }],
175
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['br', getAttrs(node.attrs)] : ['br']; }
253
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['br', pmAttributes(node.attrs)] : ['br']; }
176
254
  },
177
255
  // :: NodeSpec
178
256
  // An ordered list [node spec](#model.NodeSpec). Has a single
@@ -184,12 +262,12 @@ var nodes = tslib_1.__assign({
184
262
  group: 'block',
185
263
  attrs: tslib_1.__assign({}, commonAttributes(), { type: { default: null }, order: { default: 1 } }),
186
264
  parseDOM: [{ tag: 'ol', getAttrs: function (dom) {
187
- return tslib_1.__assign({}, getAttributes(dom), { order: dom.hasAttribute('start') ? parseInt(dom.getAttribute('start') || '1', 10) : 1 });
265
+ return tslib_1.__assign({}, domAttributes(dom), { order: dom.hasAttribute('start') ? parseInt(dom.getAttribute('start') || '1', 10) : 1 });
188
266
  } }],
189
267
  toDOM: function (node) {
190
268
  return node.attrs.order === 1 ?
191
- (hasAttrs(node.attrs, 'order') ? ['ol', getAttrs(node.attrs, 'order'), hole] : olDOM) :
192
- ['ol', tslib_1.__assign({}, getAttrs(node.attrs, 'order'), { start: node.attrs.order }), hole];
269
+ (hasAttrs(node.attrs, 'order') ? ['ol', pmAttributes(node.attrs, 'order'), hole] : olDOM) :
270
+ ['ol', tslib_1.__assign({}, pmAttributes(node.attrs, 'order'), { start: node.attrs.order }), hole];
193
271
  }
194
272
  },
195
273
  // :: NodeSpec
@@ -198,16 +276,16 @@ var nodes = tslib_1.__assign({
198
276
  content: 'list_item+',
199
277
  group: 'block',
200
278
  attrs: tslib_1.__assign({}, commonAttributes()),
201
- parseDOM: [{ tag: 'ul', getAttrs: getAttributes }],
202
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['ul', getAttrs(node.attrs), hole] : ulDOM; }
279
+ parseDOM: [{ tag: 'ul', getAttrs: domAttributes }],
280
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['ul', pmAttributes(node.attrs), hole] : ulDOM; }
203
281
  },
204
282
  // :: NodeSpec
205
283
  // A list item (`<li>`) specification.
206
284
  list_item: {
207
285
  content: '(paragraph | heading) block*',
208
286
  attrs: tslib_1.__assign({}, commonAttributes()),
209
- parseDOM: [{ tag: 'li', getAttrs: getAttributes }],
210
- toDOM: function (node) { return hasAttrs(node.attrs) ? ['li', getAttrs(node.attrs), hole] : liDOM; },
287
+ parseDOM: [{ tag: 'li', getAttrs: domAttributes }],
288
+ toDOM: function (node) { return hasAttrs(node.attrs) ? ['li', pmAttributes(node.attrs), hole] : liDOM; },
211
289
  defining: true
212
- } }, prosemirror_tables_1.tableNodes({ tableGroup: 'block', cellContent: 'block+', cellAttributes: {} }));
290
+ } }, tNodes);
213
291
  exports.nodes = nodes;
@@ -20,7 +20,6 @@ export { buildKeymap, buildListKeymap } from './config/keymap';
20
20
  export { bold, italic, underline, strikethrough, subscript, superscript, link } from './config/commands';
21
21
  export { sanitize, removeComments, removeTag, pasteCleanup, sanitizeClassAttr, sanitizeStyleAttr, removeAttribute, replaceImageSourcesFromRtf } from './paste';
22
22
  export { convertMsLists } from './listConvert';
23
- export { createTable } from './table';
24
23
  export { find, findAt, findAll, replace, replaceAll, SearchOptions } from './find-replace';
25
24
  export { placeholder } from './plugins/placeholder';
26
25
  export { spacesFix } from './plugins/spaces-fix';
@@ -38,3 +37,4 @@ export * from 'prosemirror-state';
38
37
  export * from 'prosemirror-tables';
39
38
  export * from 'prosemirror-transform';
40
39
  export * from 'prosemirror-view';
40
+ export { createTable, addRowAfter, addRowBefore, pmAddRowAfter, pmAddRowBefore } from './table';
package/dist/npm/main.js CHANGED
@@ -100,8 +100,6 @@ exports.removeAttribute = paste_1.removeAttribute;
100
100
  exports.replaceImageSourcesFromRtf = paste_1.replaceImageSourcesFromRtf;
101
101
  var listConvert_1 = require("./listConvert");
102
102
  exports.convertMsLists = listConvert_1.convertMsLists;
103
- var table_1 = require("./table");
104
- exports.createTable = table_1.createTable;
105
103
  var find_replace_1 = require("./find-replace");
106
104
  exports.find = find_replace_1.find;
107
105
  exports.findAt = find_replace_1.findAt;
@@ -131,3 +129,9 @@ tslib_1.__exportStar(require("prosemirror-state"), exports);
131
129
  tslib_1.__exportStar(require("prosemirror-tables"), exports);
132
130
  tslib_1.__exportStar(require("prosemirror-transform"), exports);
133
131
  tslib_1.__exportStar(require("prosemirror-view"), exports);
132
+ var table_1 = require("./table");
133
+ exports.createTable = table_1.createTable;
134
+ exports.addRowAfter = table_1.addRowAfter;
135
+ exports.addRowBefore = table_1.addRowBefore;
136
+ exports.pmAddRowAfter = table_1.pmAddRowAfter;
137
+ exports.pmAddRowBefore = table_1.pmAddRowBefore;
@@ -2,10 +2,59 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var prosemirror_model_1 = require("prosemirror-model");
4
4
  var prosemirror_state_1 = require("prosemirror-state");
5
+ var constants_1 = require("./config/constants");
5
6
  var blockWrappers = [
6
7
  'div', 'ol', 'ul', 'li', 'table', 'tbody', 'thead', 'tfoot', 'td', 'th', 'p',
7
8
  'tr', 'col', 'colgroup', 'article', 'main', 'nav', 'header', 'footer', 'aside', 'section'
8
9
  ];
10
+ var removeRowType = function (table, nodeName) {
11
+ var wrapper = (table.ownerDocument || document).createElement(nodeName);
12
+ Array.from(table.rows).filter(function (r) { return r.getAttribute(constants_1.rowTypeAttr) === nodeName; }).forEach(function (row) {
13
+ row.removeAttribute(constants_1.rowTypeAttr);
14
+ wrapper.appendChild(row);
15
+ });
16
+ if (wrapper.children.length) {
17
+ table.appendChild(wrapper);
18
+ }
19
+ };
20
+ var restoreTables = function (fragment) {
21
+ Array.from(fragment.querySelectorAll('table')).forEach(function (table) {
22
+ removeRowType(table, 'thead');
23
+ removeRowType(table, 'tbody');
24
+ removeRowType(table, 'tfoot');
25
+ var emptyElement = Array.from(table.children).find(function (el) { return el.children.length === 0; });
26
+ if (emptyElement) {
27
+ emptyElement.remove();
28
+ }
29
+ });
30
+ };
31
+ var setRowType = function (children, nodeName) {
32
+ var tag = nodeName.toUpperCase();
33
+ children.filter(function (c) { return c.nodeName === tag; }).forEach(function (rowsWrapper) {
34
+ Array.from(rowsWrapper.children).forEach(function (row) {
35
+ row.setAttribute(constants_1.rowTypeAttr, nodeName);
36
+ if (rowsWrapper.parentNode) {
37
+ rowsWrapper.parentNode.insertBefore(row, rowsWrapper);
38
+ }
39
+ });
40
+ rowsWrapper.remove();
41
+ });
42
+ };
43
+ var validateTablesToPmSchema = function (fragment) {
44
+ Array.from(fragment.querySelectorAll('table')).forEach(function (table) {
45
+ var children = Array.from(table.children);
46
+ if (children.some(function (e) { return e.nodeName === 'THEAD' || e.nodeName === 'TFOOT'; })) {
47
+ setRowType(children, 'thead');
48
+ setRowType(children, 'tbody');
49
+ setRowType(children, 'tfoot');
50
+ }
51
+ var colgroup = children.find(function (c) { return c.nodeName === 'COLGROUP'; });
52
+ if (colgroup) {
53
+ table.setAttribute(constants_1.colgroupAttr, colgroup.outerHTML);
54
+ colgroup.remove();
55
+ }
56
+ });
57
+ };
9
58
  /**
10
59
  * Trims the whitespace around the provided block nodes.
11
60
  *
@@ -54,7 +103,9 @@ exports.htmlToFragment = function (html) {
54
103
  * @returns DocumentFragment
55
104
  */
56
105
  exports.pmDocToFragment = function (doc) {
57
- return prosemirror_model_1.DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content);
106
+ var fragment = prosemirror_model_1.DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content);
107
+ restoreTables(fragment);
108
+ return fragment;
58
109
  };
59
110
  /**
60
111
  * Creates a ProseMirrorNode from the given DOM element.
@@ -77,6 +128,7 @@ exports.domToPmDoc = function (dom, schema, parseOptions) {
77
128
  */
78
129
  exports.parseContent = function (content, schema, parseOptions) {
79
130
  var dom = exports.htmlToFragment(content);
131
+ validateTablesToPmSchema(dom);
80
132
  return exports.domToPmDoc(dom, schema, parseOptions);
81
133
  };
82
134
  /**
@@ -1,4 +1,6 @@
1
1
  import { Node, NodeType } from 'prosemirror-model';
2
+ import { EditorState, Transaction } from 'prosemirror-state';
3
+ import { addRowAfter as pmAddRowAfter, addRowBefore as pmAddRowBefore } from 'prosemirror-tables';
2
4
  /**
3
5
  * Creates a table.
4
6
  * @returns Node
@@ -8,3 +10,6 @@ export declare const createTable: (nodes: {
8
10
  table_row: NodeType<any>;
9
11
  table_cell: NodeType<any>;
10
12
  }, rows: number, columns: number) => Node<any>;
13
+ export declare const addRowBefore: (state: EditorState<any>, dispatch?: (tr: Transaction<any>) => void) => boolean;
14
+ export declare const addRowAfter: (state: EditorState<any>, dispatch?: (tr: Transaction<any>) => void) => boolean;
15
+ export { pmAddRowBefore, pmAddRowAfter };
package/dist/npm/table.js CHANGED
@@ -1,5 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var prosemirror_tables_1 = require("prosemirror-tables");
4
+ exports.pmAddRowAfter = prosemirror_tables_1.addRowAfter;
5
+ exports.pmAddRowBefore = prosemirror_tables_1.addRowBefore;
6
+ var constants_1 = require("./config/constants");
3
7
  /**
4
8
  * Creates a table.
5
9
  * @returns Node
@@ -17,3 +21,49 @@ exports.createTable = function (nodes, rows, columns) {
17
21
  }
18
22
  return table.createAndFill(undefined, tableRows);
19
23
  };
24
+ var closest = function (selection, name) {
25
+ var pos = selection.$head;
26
+ for (var i = pos.depth; i > 0; i--) {
27
+ var node = pos.node(i);
28
+ if (node.type.name === name) {
29
+ return {
30
+ pos: pos.before(i),
31
+ node: node
32
+ };
33
+ }
34
+ }
35
+ return null;
36
+ };
37
+ exports.addRowBefore = function (state, dispatch) {
38
+ var cmdDispatch = dispatch && (function (tr) {
39
+ var _a;
40
+ var row = closest(tr.selection, 'table_row');
41
+ var table = closest(tr.selection, 'table');
42
+ if (row && table && row.node.attrs[constants_1.rowTypeAttr]) {
43
+ var index = 0;
44
+ for (var i = 0; i < table.node.nodeSize; i++) {
45
+ if (table.node.child(i).eq(row.node)) {
46
+ index = i;
47
+ break;
48
+ }
49
+ }
50
+ var next = table.node.child(index - 1);
51
+ var from = row.pos - next.nodeSize;
52
+ tr.setNodeMarkup(from, undefined, (_a = {}, _a[constants_1.rowTypeAttr] = row.node.attrs[constants_1.rowTypeAttr], _a));
53
+ }
54
+ return dispatch(tr);
55
+ });
56
+ return prosemirror_tables_1.addRowBefore(state, cmdDispatch);
57
+ };
58
+ exports.addRowAfter = function (state, dispatch) {
59
+ var cmdDispatch = dispatch && (function (tr) {
60
+ var _a;
61
+ var row = closest(tr.selection, 'table_row');
62
+ if (row && row.node.attrs[constants_1.rowTypeAttr]) {
63
+ var from = row.pos + row.node.nodeSize;
64
+ tr.setNodeMarkup(from, undefined, (_a = {}, _a[constants_1.rowTypeAttr] = row.node.attrs[constants_1.rowTypeAttr], _a));
65
+ }
66
+ return dispatch(tr);
67
+ });
68
+ return prosemirror_tables_1.addRowAfter(state, cmdDispatch);
69
+ };