@modusoperandi/licit 1.6.1 → 1.6.2
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.
- package/TableNodesSpecs.js +147 -5
- package/TableNodesSpecs.js.flow +150 -6
- package/TableNodesSpecs.test.js +49 -0
- package/TableNodesSpecs.test.js.flow +76 -0
- package/bom.xml +8232 -8111
- package/insertTable.js +3 -1
- package/insertTable.js.flow +4 -1
- package/package.json +7 -7
- package/ui/TableNodeView.js +12 -4
- package/ui/TableNodeView.js.flow +9 -0
- package/ui/toCSSLength.js +38 -0
- package/ui/toCSSLength.js.flow +38 -0
package/TableNodesSpecs.js
CHANGED
|
@@ -5,9 +5,13 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
6
|
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); }
|
|
7
7
|
import toCSSColor from './ui/toCSSColor.js';
|
|
8
|
+
import { toCSSLengthOrNull as toCSSLength } from './ui/toCSSLength.js';
|
|
8
9
|
import { Node } from 'prosemirror-model';
|
|
9
10
|
import { tableNodes } from 'prosemirror-tables';
|
|
10
11
|
var NO_VISIBLE_BORDER_WIDTH = new Set(['0pt', '0px']);
|
|
12
|
+
function appendStyle(attrs, cssText) {
|
|
13
|
+
attrs.style = (attrs.style || '') + ";".concat(cssText, ";");
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
// https://github.com/ProseMirror/prosemirror-tables/blob/master/demo.js
|
|
13
17
|
var TableNodesSpecs = tableNodes({
|
|
@@ -99,6 +103,83 @@ var TableNodesSpecs = tableNodes({
|
|
|
99
103
|
attrs.style = (attrs.style || '') + ";background-color: ".concat(colorValue, ";");
|
|
100
104
|
}
|
|
101
105
|
}
|
|
106
|
+
},
|
|
107
|
+
cellWidth: {
|
|
108
|
+
"default": null,
|
|
109
|
+
getFromDOM: function getFromDOM(dom) {
|
|
110
|
+
return dom.style.width || dom.getAttribute('width') || null;
|
|
111
|
+
},
|
|
112
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
113
|
+
var cssValue = toCSSLength(value);
|
|
114
|
+
if (cssValue) {
|
|
115
|
+
appendStyle(attrs, "width: ".concat(cssValue));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
cellStyle: {
|
|
120
|
+
"default": null,
|
|
121
|
+
getFromDOM: function getFromDOM(dom) {
|
|
122
|
+
return dom.getAttribute('data-cell-style') || null;
|
|
123
|
+
},
|
|
124
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
125
|
+
if (value === null || value === undefined) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
var styleValue = String(value).trim();
|
|
129
|
+
if (!styleValue) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
attrs['data-cell-style'] = styleValue;
|
|
133
|
+
attrs.style = (attrs.style || '') + ";".concat(styleValue);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
fontSize: {
|
|
137
|
+
"default": null,
|
|
138
|
+
getFromDOM: function getFromDOM(dom) {
|
|
139
|
+
return dom.style.fontSize || null;
|
|
140
|
+
},
|
|
141
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
142
|
+
var cssValue = toCSSLength(value);
|
|
143
|
+
if (cssValue) {
|
|
144
|
+
appendStyle(attrs, "font-size: ".concat(cssValue));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
letterSpacing: {
|
|
149
|
+
"default": null,
|
|
150
|
+
getFromDOM: function getFromDOM(dom) {
|
|
151
|
+
return dom.style.letterSpacing || null;
|
|
152
|
+
},
|
|
153
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
154
|
+
var cssValue = toCSSLength(value);
|
|
155
|
+
if (cssValue) {
|
|
156
|
+
appendStyle(attrs, "letter-spacing: ".concat(cssValue));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
marginTop: {
|
|
161
|
+
"default": null,
|
|
162
|
+
getFromDOM: function getFromDOM(dom) {
|
|
163
|
+
return dom.style.marginTop || null;
|
|
164
|
+
},
|
|
165
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
166
|
+
var cssValue = toCSSLength(value);
|
|
167
|
+
if (cssValue) {
|
|
168
|
+
appendStyle(attrs, "margin-top: ".concat(cssValue));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
marginBottom: {
|
|
173
|
+
"default": null,
|
|
174
|
+
getFromDOM: function getFromDOM(dom) {
|
|
175
|
+
return dom.style.marginBottom || null;
|
|
176
|
+
},
|
|
177
|
+
setDOMAttr: function setDOMAttr(value, attrs) {
|
|
178
|
+
var cssValue = toCSSLength(value);
|
|
179
|
+
if (cssValue) {
|
|
180
|
+
appendStyle(attrs, "margin-bottom: ".concat(cssValue));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
102
183
|
}
|
|
103
184
|
}
|
|
104
185
|
});
|
|
@@ -106,6 +187,12 @@ var TableNodesSpecs = tableNodes({
|
|
|
106
187
|
// Override the default table node spec to support custom attributes.
|
|
107
188
|
var TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
108
189
|
attrs: _objectSpread(_objectSpread({}, TableNodesSpecs.table.attrs), {}, {
|
|
190
|
+
noOfColumns: {
|
|
191
|
+
"default": null
|
|
192
|
+
},
|
|
193
|
+
tableheight: {
|
|
194
|
+
"default": null
|
|
195
|
+
},
|
|
109
196
|
marginLeft: {
|
|
110
197
|
"default": null
|
|
111
198
|
},
|
|
@@ -121,14 +208,30 @@ var TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
121
208
|
getAttrs: function getAttrs(dom) {
|
|
122
209
|
var dirty = dom.getAttribute('dirty') || false;
|
|
123
210
|
var coverPage = dom.getAttribute('data-cover-page') === 'true';
|
|
124
|
-
var
|
|
211
|
+
var _dom$style2 = dom.style,
|
|
212
|
+
marginLeft = _dom$style2.marginLeft,
|
|
213
|
+
height = _dom$style2.height;
|
|
214
|
+
var noOfColumnsAttr = dom.getAttribute('data-no-of-columns') || dom.getAttribute('noOfColumns') || dom.getAttribute('no-of-columns');
|
|
125
215
|
var attrs = {
|
|
126
216
|
dirty: dirty,
|
|
127
217
|
coverPage: coverPage
|
|
128
218
|
};
|
|
129
|
-
if (marginLeft && /\d
|
|
219
|
+
if (marginLeft && /\d{1,1000}px/.test(marginLeft)) {
|
|
130
220
|
attrs.marginLeft = parseFloat(marginLeft);
|
|
131
221
|
}
|
|
222
|
+
if (height || dom.getAttribute('height')) {
|
|
223
|
+
attrs.tableheight = height || dom.getAttribute('height');
|
|
224
|
+
}
|
|
225
|
+
if (noOfColumnsAttr && /^\d{1,1000}$/.test(noOfColumnsAttr)) {
|
|
226
|
+
attrs.noOfColumns = parseInt(noOfColumnsAttr, 10);
|
|
227
|
+
}
|
|
228
|
+
if (!attrs.noOfColumns) {
|
|
229
|
+
var firstRow = dom.querySelector('tr');
|
|
230
|
+
var cells = firstRow ? firstRow.querySelectorAll('th, td').length : 0;
|
|
231
|
+
if (cells > 0) {
|
|
232
|
+
attrs.noOfColumns = cells;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
132
235
|
return attrs;
|
|
133
236
|
}
|
|
134
237
|
}],
|
|
@@ -138,12 +241,22 @@ var TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
138
241
|
// table node and copies it, which triggers the "serialize to HTML" flow
|
|
139
242
|
// that calles this method.
|
|
140
243
|
var _node$attrs = node.attrs,
|
|
244
|
+
noOfColumns = _node$attrs.noOfColumns,
|
|
245
|
+
tableheight = _node$attrs.tableheight,
|
|
141
246
|
marginLeft = _node$attrs.marginLeft,
|
|
142
247
|
dirty = _node$attrs.dirty,
|
|
143
248
|
coverPage = _node$attrs.coverPage;
|
|
144
249
|
var domAttrs = {};
|
|
145
|
-
|
|
146
|
-
|
|
250
|
+
var styleChunks = [];
|
|
251
|
+
if (marginLeft !== null && marginLeft !== undefined) {
|
|
252
|
+
styleChunks.push("margin-left: ".concat(marginLeft, "px"));
|
|
253
|
+
}
|
|
254
|
+
var tableHeight = toCSSLength(tableheight);
|
|
255
|
+
if (tableHeight) {
|
|
256
|
+
styleChunks.push("height: ".concat(tableHeight));
|
|
257
|
+
}
|
|
258
|
+
if (styleChunks.length) {
|
|
259
|
+
domAttrs.style = styleChunks.join('; ');
|
|
147
260
|
}
|
|
148
261
|
if (dirty) {
|
|
149
262
|
domAttrs.dirty = dirty;
|
|
@@ -151,10 +264,39 @@ var TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
151
264
|
if (coverPage) {
|
|
152
265
|
domAttrs['data-cover-page'] = 'true';
|
|
153
266
|
}
|
|
267
|
+
if (typeof noOfColumns === 'number' && noOfColumns > 0) {
|
|
268
|
+
domAttrs['data-no-of-columns'] = String(noOfColumns);
|
|
269
|
+
}
|
|
154
270
|
return ['table', domAttrs, 0];
|
|
155
271
|
}
|
|
156
272
|
});
|
|
273
|
+
var TableRowNodeSpec = Object.assign({}, TableNodesSpecs.table_row, {
|
|
274
|
+
attrs: _objectSpread(_objectSpread({}, TableNodesSpecs.table_row.attrs), {}, {
|
|
275
|
+
rowHeight: {
|
|
276
|
+
"default": null
|
|
277
|
+
}
|
|
278
|
+
}),
|
|
279
|
+
parseDOM: [{
|
|
280
|
+
tag: 'tr',
|
|
281
|
+
getAttrs: function getAttrs(dom) {
|
|
282
|
+
var rowHeight = dom.style.height || dom.getAttribute('height') || null;
|
|
283
|
+
return rowHeight ? {
|
|
284
|
+
rowHeight: rowHeight
|
|
285
|
+
} : null;
|
|
286
|
+
}
|
|
287
|
+
}],
|
|
288
|
+
toDOM: function toDOM(node) {
|
|
289
|
+
var _node$attrs2;
|
|
290
|
+
var domAttrs = {};
|
|
291
|
+
var rowHeight = toCSSLength((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.rowHeight);
|
|
292
|
+
if (rowHeight) {
|
|
293
|
+
domAttrs.style = "height: ".concat(rowHeight);
|
|
294
|
+
}
|
|
295
|
+
return ['tr', domAttrs, 0];
|
|
296
|
+
}
|
|
297
|
+
});
|
|
157
298
|
Object.assign(TableNodesSpecs, {
|
|
158
|
-
table: TableNodeSpec
|
|
299
|
+
table: TableNodeSpec,
|
|
300
|
+
table_row: TableRowNodeSpec
|
|
159
301
|
});
|
|
160
302
|
export default TableNodesSpecs;
|
package/TableNodesSpecs.js.flow
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
3
|
import toCSSColor from './ui/toCSSColor.js';
|
|
4
|
+
import { toCSSLengthOrNull as toCSSLength } from './ui/toCSSLength.js';
|
|
4
5
|
import { Node } from 'prosemirror-model';
|
|
5
6
|
import { tableNodes } from 'prosemirror-tables';
|
|
6
7
|
|
|
7
8
|
const NO_VISIBLE_BORDER_WIDTH = new Set(['0pt', '0px']);
|
|
8
9
|
|
|
10
|
+
function appendStyle(attrs: Object, cssText: string): void {
|
|
11
|
+
attrs.style = (attrs.style || '') + `;${cssText};`;
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
// https://github.com/ProseMirror/prosemirror-tables/blob/master/demo.js
|
|
10
15
|
const TableNodesSpecs = tableNodes({
|
|
11
16
|
tableGroup: 'block',
|
|
@@ -98,6 +103,83 @@ const TableNodesSpecs = tableNodes({
|
|
|
98
103
|
}
|
|
99
104
|
},
|
|
100
105
|
},
|
|
106
|
+
cellWidth: {
|
|
107
|
+
default: null,
|
|
108
|
+
getFromDOM(dom) {
|
|
109
|
+
return dom.style.width || dom.getAttribute('width') || null;
|
|
110
|
+
},
|
|
111
|
+
setDOMAttr(value, attrs) {
|
|
112
|
+
const cssValue = toCSSLength(value);
|
|
113
|
+
if (cssValue) {
|
|
114
|
+
appendStyle(attrs, `width: ${cssValue}`);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
cellStyle: {
|
|
119
|
+
default: null,
|
|
120
|
+
getFromDOM(dom) {
|
|
121
|
+
return dom.getAttribute('data-cell-style') || null;
|
|
122
|
+
},
|
|
123
|
+
setDOMAttr(value, attrs) {
|
|
124
|
+
if (value === null || value === undefined) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const styleValue = String(value).trim();
|
|
128
|
+
if (!styleValue) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
attrs['data-cell-style'] = styleValue;
|
|
132
|
+
attrs.style = (attrs.style || '') + `;${styleValue}`;
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
fontSize: {
|
|
136
|
+
default: null,
|
|
137
|
+
getFromDOM(dom) {
|
|
138
|
+
return dom.style.fontSize || null;
|
|
139
|
+
},
|
|
140
|
+
setDOMAttr(value, attrs) {
|
|
141
|
+
const cssValue = toCSSLength(value);
|
|
142
|
+
if (cssValue) {
|
|
143
|
+
appendStyle(attrs, `font-size: ${cssValue}`);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
letterSpacing: {
|
|
148
|
+
default: null,
|
|
149
|
+
getFromDOM(dom) {
|
|
150
|
+
return dom.style.letterSpacing || null;
|
|
151
|
+
},
|
|
152
|
+
setDOMAttr(value, attrs) {
|
|
153
|
+
const cssValue = toCSSLength(value);
|
|
154
|
+
if (cssValue) {
|
|
155
|
+
appendStyle(attrs, `letter-spacing: ${cssValue}`);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
marginTop: {
|
|
160
|
+
default: null,
|
|
161
|
+
getFromDOM(dom) {
|
|
162
|
+
return dom.style.marginTop || null;
|
|
163
|
+
},
|
|
164
|
+
setDOMAttr(value, attrs) {
|
|
165
|
+
const cssValue = toCSSLength(value);
|
|
166
|
+
if (cssValue) {
|
|
167
|
+
appendStyle(attrs, `margin-top: ${cssValue}`);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
marginBottom: {
|
|
172
|
+
default: null,
|
|
173
|
+
getFromDOM(dom) {
|
|
174
|
+
return dom.style.marginBottom || null;
|
|
175
|
+
},
|
|
176
|
+
setDOMAttr(value, attrs) {
|
|
177
|
+
const cssValue = toCSSLength(value);
|
|
178
|
+
if (cssValue) {
|
|
179
|
+
appendStyle(attrs, `margin-bottom: ${cssValue}`);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
},
|
|
101
183
|
},
|
|
102
184
|
});
|
|
103
185
|
|
|
@@ -105,6 +187,8 @@ const TableNodesSpecs = tableNodes({
|
|
|
105
187
|
const TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
106
188
|
attrs: {
|
|
107
189
|
...TableNodesSpecs.table.attrs,
|
|
190
|
+
noOfColumns: { default: null },
|
|
191
|
+
tableheight: { default: null },
|
|
108
192
|
marginLeft: { default: null },
|
|
109
193
|
dirty: { default: false },
|
|
110
194
|
coverPage: { default: false },
|
|
@@ -115,12 +199,31 @@ const TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
115
199
|
getAttrs(dom: HTMLElement): ?Object {
|
|
116
200
|
const dirty = dom.getAttribute('dirty') || false;
|
|
117
201
|
const coverPage = dom.getAttribute('data-cover-page') === 'true';
|
|
118
|
-
const { marginLeft } = dom.style;
|
|
202
|
+
const { marginLeft, height } = dom.style;
|
|
203
|
+
const noOfColumnsAttr =
|
|
204
|
+
dom.getAttribute('data-no-of-columns') ||
|
|
205
|
+
dom.getAttribute('noOfColumns') ||
|
|
206
|
+
dom.getAttribute('no-of-columns');
|
|
119
207
|
const attrs = { dirty, coverPage };
|
|
120
208
|
|
|
121
|
-
if (marginLeft && /\d
|
|
209
|
+
if (marginLeft && /\d{1,1000}px/.test(marginLeft)) {
|
|
122
210
|
attrs.marginLeft = parseFloat(marginLeft);
|
|
123
211
|
}
|
|
212
|
+
if (height || dom.getAttribute('height')) {
|
|
213
|
+
attrs.tableheight = height || dom.getAttribute('height');
|
|
214
|
+
}
|
|
215
|
+
if (noOfColumnsAttr && /^\d{1,1000}$/.test(noOfColumnsAttr)) {
|
|
216
|
+
attrs.noOfColumns = parseInt(noOfColumnsAttr, 10);
|
|
217
|
+
}
|
|
218
|
+
if (!attrs.noOfColumns) {
|
|
219
|
+
const firstRow = dom.querySelector('tr');
|
|
220
|
+
const cells = firstRow
|
|
221
|
+
? firstRow.querySelectorAll('th, td').length
|
|
222
|
+
: 0;
|
|
223
|
+
if (cells > 0) {
|
|
224
|
+
attrs.noOfColumns = cells;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
124
227
|
|
|
125
228
|
return attrs;
|
|
126
229
|
},
|
|
@@ -131,10 +234,19 @@ const TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
131
234
|
// `TableNodeView`. This method is only called when user selects a
|
|
132
235
|
// table node and copies it, which triggers the "serialize to HTML" flow
|
|
133
236
|
// that calles this method.
|
|
134
|
-
const { marginLeft, dirty, coverPage } =
|
|
237
|
+
const { noOfColumns, tableheight, marginLeft, dirty, coverPage } =
|
|
238
|
+
node.attrs;
|
|
135
239
|
const domAttrs = {};
|
|
136
|
-
|
|
137
|
-
|
|
240
|
+
const styleChunks = [];
|
|
241
|
+
if (marginLeft !== null && marginLeft !== undefined) {
|
|
242
|
+
styleChunks.push(`margin-left: ${marginLeft}px`);
|
|
243
|
+
}
|
|
244
|
+
const tableHeight = toCSSLength(tableheight);
|
|
245
|
+
if (tableHeight) {
|
|
246
|
+
styleChunks.push(`height: ${tableHeight}`);
|
|
247
|
+
}
|
|
248
|
+
if (styleChunks.length) {
|
|
249
|
+
domAttrs.style = styleChunks.join('; ');
|
|
138
250
|
}
|
|
139
251
|
if (dirty) {
|
|
140
252
|
domAttrs.dirty = dirty;
|
|
@@ -142,9 +254,41 @@ const TableNodeSpec = Object.assign({}, TableNodesSpecs.table, {
|
|
|
142
254
|
if (coverPage) {
|
|
143
255
|
domAttrs['data-cover-page'] = 'true';
|
|
144
256
|
}
|
|
257
|
+
if (typeof noOfColumns === 'number' && noOfColumns > 0) {
|
|
258
|
+
domAttrs['data-no-of-columns'] = String(noOfColumns);
|
|
259
|
+
}
|
|
145
260
|
return ['table', domAttrs, 0];
|
|
146
261
|
},
|
|
147
262
|
});
|
|
148
|
-
|
|
263
|
+
|
|
264
|
+
const TableRowNodeSpec = Object.assign({}, TableNodesSpecs.table_row, {
|
|
265
|
+
attrs: {
|
|
266
|
+
...TableNodesSpecs.table_row.attrs,
|
|
267
|
+
rowHeight: { default: null },
|
|
268
|
+
},
|
|
269
|
+
parseDOM: [
|
|
270
|
+
{
|
|
271
|
+
tag: 'tr',
|
|
272
|
+
getAttrs(dom: HTMLElement): ?Object {
|
|
273
|
+
const rowHeight =
|
|
274
|
+
dom.style.height || dom.getAttribute('height') || null;
|
|
275
|
+
return rowHeight ? { rowHeight } : null;
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
toDOM(node: Node): Array<any> {
|
|
280
|
+
const domAttrs = {};
|
|
281
|
+
const rowHeight = toCSSLength(node.attrs?.rowHeight);
|
|
282
|
+
if (rowHeight) {
|
|
283
|
+
domAttrs.style = `height: ${rowHeight}`;
|
|
284
|
+
}
|
|
285
|
+
return ['tr', domAttrs, 0];
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
Object.assign(TableNodesSpecs, {
|
|
290
|
+
table: TableNodeSpec,
|
|
291
|
+
table_row: TableRowNodeSpec,
|
|
292
|
+
});
|
|
149
293
|
|
|
150
294
|
export default TableNodesSpecs;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { DOMParser as PMDOMParser, DOMSerializer } from 'prosemirror-model';
|
|
2
|
+
import EditorSchema from './EditorSchema.js';
|
|
3
|
+
describe('TableNodesSpecs custom attrs', function () {
|
|
4
|
+
it('parses table, row, and cell custom attributes from DOM', function () {
|
|
5
|
+
var root = document.createElement('div');
|
|
6
|
+
root.innerHTML = "\n <table data-no-of-columns=\"3\" style=\"height: 240px; margin-left: 12px;\">\n <tbody>\n <tr style=\"height: 44px;\">\n <td\n data-cell-style=\"text-align: center\"\n style=\"width: 96px; font-size: 14px; letter-spacing: 1px; margin-top: 2px; margin-bottom: 3px;\"\n >\n <p>Cell</p>\n </td>\n </tr>\n </tbody>\n </table>\n ";
|
|
7
|
+
var doc = PMDOMParser.fromSchema(EditorSchema).parse(root);
|
|
8
|
+
var tableNode = doc.firstChild;
|
|
9
|
+
var rowNode = tableNode.firstChild;
|
|
10
|
+
var cellNode = rowNode.firstChild;
|
|
11
|
+
expect(tableNode.attrs.noOfColumns).toBe(3);
|
|
12
|
+
expect(tableNode.attrs.tableheight).toBe('240px');
|
|
13
|
+
expect(rowNode.attrs.rowHeight).toBe('44px');
|
|
14
|
+
expect(cellNode.attrs.cellWidth).toBe('96px');
|
|
15
|
+
expect(cellNode.attrs.cellStyle).toBe('text-align: center');
|
|
16
|
+
expect(cellNode.attrs.fontSize).toBe('14px');
|
|
17
|
+
expect(cellNode.attrs.letterSpacing).toBe('1px');
|
|
18
|
+
expect(cellNode.attrs.marginTop).toBe('2px');
|
|
19
|
+
expect(cellNode.attrs.marginBottom).toBe('3px');
|
|
20
|
+
});
|
|
21
|
+
it('serializes table, row, and cell custom attributes to DOM', function () {
|
|
22
|
+
var paragraph = EditorSchema.nodes.paragraph.create(null, EditorSchema.text('x'));
|
|
23
|
+
var cellNode = EditorSchema.nodes.table_cell.create({
|
|
24
|
+
cellWidth: 110,
|
|
25
|
+
cellStyle: 'text-align: center',
|
|
26
|
+
fontSize: 13,
|
|
27
|
+
letterSpacing: '0.8px',
|
|
28
|
+
marginTop: 4,
|
|
29
|
+
marginBottom: '5px'
|
|
30
|
+
}, paragraph);
|
|
31
|
+
var rowNode = EditorSchema.nodes.table_row.create({
|
|
32
|
+
rowHeight: 52
|
|
33
|
+
}, cellNode);
|
|
34
|
+
var tableNode = EditorSchema.nodes.table.create({
|
|
35
|
+
noOfColumns: 1,
|
|
36
|
+
tableheight: 300,
|
|
37
|
+
marginLeft: 20
|
|
38
|
+
}, rowNode);
|
|
39
|
+
var tableEl = DOMSerializer.fromSchema(EditorSchema).serializeNode(tableNode);
|
|
40
|
+
var rowEl = tableEl.querySelector('tr');
|
|
41
|
+
var cellEl = tableEl.querySelector('td');
|
|
42
|
+
expect(tableEl.getAttribute('data-no-of-columns')).toBe('1');
|
|
43
|
+
expect(tableEl.style.height).toBe('300px');
|
|
44
|
+
expect(rowEl.style.height).toBe('52px');
|
|
45
|
+
var cellStyleText = cellEl.getAttribute('style') || '';
|
|
46
|
+
expect(cellStyleText).toContain('font-size: 13px');
|
|
47
|
+
expect(cellEl.getAttribute('data-cell-style')).toBe('text-align: center');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DOMParser as PMDOMParser, DOMSerializer } from 'prosemirror-model';
|
|
2
|
+
import EditorSchema from './EditorSchema.js';
|
|
3
|
+
|
|
4
|
+
describe('TableNodesSpecs custom attrs', () => {
|
|
5
|
+
it('parses table, row, and cell custom attributes from DOM', () => {
|
|
6
|
+
const root = document.createElement('div');
|
|
7
|
+
root.innerHTML = `
|
|
8
|
+
<table data-no-of-columns="3" style="height: 240px; margin-left: 12px;">
|
|
9
|
+
<tbody>
|
|
10
|
+
<tr style="height: 44px;">
|
|
11
|
+
<td
|
|
12
|
+
data-cell-style="text-align: center"
|
|
13
|
+
style="width: 96px; font-size: 14px; letter-spacing: 1px; margin-top: 2px; margin-bottom: 3px;"
|
|
14
|
+
>
|
|
15
|
+
<p>Cell</p>
|
|
16
|
+
</td>
|
|
17
|
+
</tr>
|
|
18
|
+
</tbody>
|
|
19
|
+
</table>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const doc = PMDOMParser.fromSchema(EditorSchema).parse(root);
|
|
23
|
+
const tableNode = doc.firstChild;
|
|
24
|
+
const rowNode = tableNode.firstChild;
|
|
25
|
+
const cellNode = rowNode.firstChild;
|
|
26
|
+
|
|
27
|
+
expect(tableNode.attrs.noOfColumns).toBe(3);
|
|
28
|
+
expect(tableNode.attrs.tableheight).toBe('240px');
|
|
29
|
+
expect(rowNode.attrs.rowHeight).toBe('44px');
|
|
30
|
+
expect(cellNode.attrs.cellWidth).toBe('96px');
|
|
31
|
+
expect(cellNode.attrs.cellStyle).toBe('text-align: center');
|
|
32
|
+
expect(cellNode.attrs.fontSize).toBe('14px');
|
|
33
|
+
expect(cellNode.attrs.letterSpacing).toBe('1px');
|
|
34
|
+
expect(cellNode.attrs.marginTop).toBe('2px');
|
|
35
|
+
expect(cellNode.attrs.marginBottom).toBe('3px');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('serializes table, row, and cell custom attributes to DOM', () => {
|
|
39
|
+
const paragraph = EditorSchema.nodes.paragraph.create(
|
|
40
|
+
null,
|
|
41
|
+
EditorSchema.text('x')
|
|
42
|
+
);
|
|
43
|
+
const cellNode = EditorSchema.nodes.table_cell.create(
|
|
44
|
+
{
|
|
45
|
+
cellWidth: 110,
|
|
46
|
+
cellStyle: 'text-align: center',
|
|
47
|
+
fontSize: 13,
|
|
48
|
+
letterSpacing: '0.8px',
|
|
49
|
+
marginTop: 4,
|
|
50
|
+
marginBottom: '5px',
|
|
51
|
+
},
|
|
52
|
+
paragraph
|
|
53
|
+
);
|
|
54
|
+
const rowNode = EditorSchema.nodes.table_row.create(
|
|
55
|
+
{ rowHeight: 52 },
|
|
56
|
+
cellNode
|
|
57
|
+
);
|
|
58
|
+
const tableNode = EditorSchema.nodes.table.create(
|
|
59
|
+
{ noOfColumns: 1, tableheight: 300, marginLeft: 20 },
|
|
60
|
+
rowNode
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const tableEl = DOMSerializer.fromSchema(EditorSchema).serializeNode(
|
|
64
|
+
tableNode
|
|
65
|
+
);
|
|
66
|
+
const rowEl = tableEl.querySelector('tr');
|
|
67
|
+
const cellEl = tableEl.querySelector('td');
|
|
68
|
+
|
|
69
|
+
expect(tableEl.getAttribute('data-no-of-columns')).toBe('1');
|
|
70
|
+
expect(tableEl.style.height).toBe('300px');
|
|
71
|
+
expect(rowEl.style.height).toBe('52px');
|
|
72
|
+
const cellStyleText = cellEl.getAttribute('style') || '';
|
|
73
|
+
expect(cellStyleText).toContain('font-size: 13px');
|
|
74
|
+
expect(cellEl.getAttribute('data-cell-style')).toBe('text-align: center');
|
|
75
|
+
});
|
|
76
|
+
});
|