@manuscripts/transform 2.1.3 → 2.1.4
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/dist/cjs/jats/importer/jats-body-dom-parser.js +2 -16
- package/dist/cjs/jats/importer/jats-body-transformations.js +7 -16
- package/dist/cjs/jats/jats-exporter.js +27 -3
- package/dist/cjs/schema/index.js +3 -5
- package/dist/cjs/schema/nodes/table.js +52 -30
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/transformer/decode.js +26 -17
- package/dist/cjs/transformer/encode.js +2 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +2 -16
- package/dist/es/jats/importer/jats-body-transformations.js +7 -16
- package/dist/es/jats/jats-exporter.js +27 -3
- package/dist/es/schema/index.js +2 -4
- package/dist/es/schema/nodes/table.js +51 -29
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/transformer/decode.js +26 -17
- package/dist/es/transformer/encode.js +2 -1
- package/dist/types/schema/index.d.ts +0 -1
- package/dist/types/schema/nodes/table.d.ts +5 -12
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/decode.d.ts +1 -0
- package/package.json +4 -3
- package/dist/cjs/schema/nodes/table_row.js +0 -123
- package/dist/es/schema/nodes/table_row.js +0 -120
- package/dist/types/schema/nodes/table_row.d.ts +0 -41
|
@@ -525,23 +525,9 @@ const nodes = [
|
|
|
525
525
|
const element = node;
|
|
526
526
|
return {
|
|
527
527
|
id: element.getAttribute('id'),
|
|
528
|
-
suppressFooter: !element.querySelector('table > tfoot > tr'),
|
|
529
|
-
suppressHeader: !element.querySelector('table > thead > tr'),
|
|
530
528
|
};
|
|
531
529
|
},
|
|
532
530
|
},
|
|
533
|
-
{
|
|
534
|
-
tag: 'tbody',
|
|
535
|
-
skip: true,
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
tag: 'tfoot',
|
|
539
|
-
skip: true,
|
|
540
|
-
},
|
|
541
|
-
{
|
|
542
|
-
tag: 'thead',
|
|
543
|
-
skip: true,
|
|
544
|
-
},
|
|
545
531
|
{
|
|
546
532
|
tag: 'title',
|
|
547
533
|
node: 'section_title',
|
|
@@ -568,12 +554,12 @@ const nodes = [
|
|
|
568
554
|
},
|
|
569
555
|
{
|
|
570
556
|
tag: 'th',
|
|
571
|
-
node: '
|
|
557
|
+
node: 'table_header',
|
|
572
558
|
getAttrs: (node) => {
|
|
573
559
|
const element = node;
|
|
574
560
|
const colspan = element.getAttribute('colspan');
|
|
575
561
|
const rowspan = element.getAttribute('rowspan');
|
|
576
|
-
return Object.assign(Object.assign(Object.assign({
|
|
562
|
+
return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
577
563
|
},
|
|
578
564
|
},
|
|
579
565
|
{
|
|
@@ -239,8 +239,12 @@ exports.jatsBodyTransformations = {
|
|
|
239
239
|
}
|
|
240
240
|
},
|
|
241
241
|
fixTables(body, createElement) {
|
|
242
|
-
const
|
|
243
|
-
|
|
242
|
+
const tableWraps = body.querySelectorAll('table-wrap');
|
|
243
|
+
tableWraps.forEach((tableWrap) => {
|
|
244
|
+
const table = tableWrap.querySelector('table');
|
|
245
|
+
if (!table) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
244
248
|
const colgroup = table.querySelector('colgroup');
|
|
245
249
|
const cols = table.querySelectorAll('col');
|
|
246
250
|
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
@@ -248,20 +252,7 @@ exports.jatsBodyTransformations = {
|
|
|
248
252
|
for (const col of cols) {
|
|
249
253
|
colgroup.appendChild(col);
|
|
250
254
|
}
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
const tbody = table.querySelector('tbody');
|
|
254
|
-
if (tbody) {
|
|
255
|
-
const headerRow = table.querySelector('thead > tr');
|
|
256
|
-
if (!headerRow) {
|
|
257
|
-
const tr = createElement('tr');
|
|
258
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
259
|
-
}
|
|
260
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
261
|
-
if (!footerRow) {
|
|
262
|
-
const tr = createElement('tr');
|
|
263
|
-
tbody.appendChild(tr);
|
|
264
|
-
}
|
|
255
|
+
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
265
256
|
}
|
|
266
257
|
});
|
|
267
258
|
},
|
|
@@ -873,9 +873,13 @@ class JATSExporter {
|
|
|
873
873
|
element.setAttribute('position', 'anchor');
|
|
874
874
|
return element;
|
|
875
875
|
},
|
|
876
|
-
table_body: () => ['tbody', 0],
|
|
877
876
|
table_cell: (node) => [
|
|
878
|
-
|
|
877
|
+
'td',
|
|
878
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
879
|
+
0,
|
|
880
|
+
],
|
|
881
|
+
table_header: (node) => [
|
|
882
|
+
'th',
|
|
879
883
|
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
880
884
|
0,
|
|
881
885
|
],
|
|
@@ -956,6 +960,26 @@ class JATSExporter {
|
|
|
956
960
|
element.appendChild(this.serializeNode(childNode));
|
|
957
961
|
}
|
|
958
962
|
};
|
|
963
|
+
const appendTable = (element, node) => {
|
|
964
|
+
const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
|
|
965
|
+
const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
|
|
966
|
+
if (!tableNode) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
const table = this.serializeNode(tableNode);
|
|
970
|
+
const tbodyElement = this.document.createElement('tbody');
|
|
971
|
+
while (table.firstChild) {
|
|
972
|
+
const child = table.firstChild;
|
|
973
|
+
table.removeChild(child);
|
|
974
|
+
tbodyElement.appendChild(child);
|
|
975
|
+
}
|
|
976
|
+
table.appendChild(tbodyElement);
|
|
977
|
+
if (colGroupNode) {
|
|
978
|
+
const colGroup = this.serializeNode(colGroupNode);
|
|
979
|
+
table.insertBefore(colGroup, table.firstChild);
|
|
980
|
+
}
|
|
981
|
+
element.appendChild(table);
|
|
982
|
+
};
|
|
959
983
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
960
984
|
const element = createElement(node, nodeName);
|
|
961
985
|
if (figType) {
|
|
@@ -976,7 +1000,7 @@ class JATSExporter {
|
|
|
976
1000
|
const element = createElement(node, nodeName);
|
|
977
1001
|
appendLabels(element, node);
|
|
978
1002
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
979
|
-
|
|
1003
|
+
appendTable(element, node);
|
|
980
1004
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
981
1005
|
if ((0, node_types_1.isExecutableNodeType)(node.type)) {
|
|
982
1006
|
processExecutableNode(node, element);
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -87,7 +87,6 @@ const table_1 = require("./nodes/table");
|
|
|
87
87
|
const table_col_1 = require("./nodes/table_col");
|
|
88
88
|
const table_element_1 = require("./nodes/table_element");
|
|
89
89
|
const table_element_footer_1 = require("./nodes/table_element_footer");
|
|
90
|
-
const table_row_1 = require("./nodes/table_row");
|
|
91
90
|
const text_1 = require("./nodes/text");
|
|
92
91
|
const title_1 = require("./nodes/title");
|
|
93
92
|
const toc_element_1 = require("./nodes/toc_element");
|
|
@@ -137,7 +136,6 @@ __exportStar(require("./nodes/section_title"), exports);
|
|
|
137
136
|
__exportStar(require("./nodes/table"), exports);
|
|
138
137
|
__exportStar(require("./nodes/table_col"), exports);
|
|
139
138
|
__exportStar(require("./nodes/table_element"), exports);
|
|
140
|
-
__exportStar(require("./nodes/table_row"), exports);
|
|
141
139
|
__exportStar(require("./nodes/text"), exports);
|
|
142
140
|
__exportStar(require("./nodes/toc_element"), exports);
|
|
143
141
|
__exportStar(require("./nodes/toc_section"), exports);
|
|
@@ -213,10 +211,9 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
213
211
|
section_title: section_title_1.sectionTitle,
|
|
214
212
|
section_title_plain: section_title_1.sectionTitle,
|
|
215
213
|
table: table_1.table,
|
|
216
|
-
|
|
217
|
-
table_cell: table_row_1.tableCell,
|
|
214
|
+
table_cell: table_1.tableCell,
|
|
218
215
|
table_element: table_element_1.tableElement,
|
|
219
|
-
table_row:
|
|
216
|
+
table_row: table_1.tableRow,
|
|
220
217
|
table_col: table_col_1.tableCol,
|
|
221
218
|
table_colgroup: table_col_1.tableColGroup,
|
|
222
219
|
text: text_1.text,
|
|
@@ -230,5 +227,6 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
230
227
|
contributors: contributors_1.contributors,
|
|
231
228
|
supplements: supplements_1.supplements,
|
|
232
229
|
supplement: supplement_1.supplement,
|
|
230
|
+
table_header: table_1.tableHeader,
|
|
233
231
|
},
|
|
234
232
|
});
|
|
@@ -15,20 +15,57 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = void 0;
|
|
19
|
+
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
20
|
+
function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
|
|
21
|
+
return {
|
|
22
|
+
default: defaultValue,
|
|
23
|
+
getFromDOM(dom) {
|
|
24
|
+
if (customGetFromDOM) {
|
|
25
|
+
return customGetFromDOM(dom);
|
|
26
|
+
}
|
|
27
|
+
return dom.getAttribute(attributeName);
|
|
28
|
+
},
|
|
29
|
+
setDOMAttr(value, attrs) {
|
|
30
|
+
if (customSetDOMAttr) {
|
|
31
|
+
customSetDOMAttr(value, attrs);
|
|
32
|
+
}
|
|
33
|
+
else if (value) {
|
|
34
|
+
attrs[attributeName] = value;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const tableOptions = {
|
|
40
|
+
cellContent: 'inline*',
|
|
41
|
+
cellAttributes: {
|
|
42
|
+
placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
|
|
43
|
+
valign: createCellAttribute('valign'),
|
|
44
|
+
align: createCellAttribute('align'),
|
|
45
|
+
scope: createCellAttribute('scope'),
|
|
46
|
+
style: createCellAttribute('style'),
|
|
47
|
+
colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
|
|
48
|
+
if (value && value !== 1) {
|
|
49
|
+
attrs['colspan'] = String(value);
|
|
50
|
+
}
|
|
51
|
+
}),
|
|
52
|
+
rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
|
|
53
|
+
if (value && value !== 1) {
|
|
54
|
+
attrs['rowspan'] = String(value);
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
19
60
|
exports.table = {
|
|
20
|
-
content: 'table_colgroup? table_body',
|
|
21
|
-
tableRole: 'table',
|
|
22
|
-
isolating: true,
|
|
23
|
-
group: 'block',
|
|
24
|
-
selectable: false,
|
|
25
61
|
attrs: {
|
|
26
62
|
id: { default: '' },
|
|
27
|
-
headerRows: { default: 1 },
|
|
28
|
-
footerRows: { default: 1 },
|
|
29
63
|
dataTracked: { default: null },
|
|
30
|
-
comments: { default: null },
|
|
31
64
|
},
|
|
65
|
+
content: 'table_row+',
|
|
66
|
+
tableRole: 'table',
|
|
67
|
+
isolating: true,
|
|
68
|
+
group: 'block',
|
|
32
69
|
parseDOM: [
|
|
33
70
|
{
|
|
34
71
|
tag: 'table',
|
|
@@ -36,35 +73,20 @@ exports.table = {
|
|
|
36
73
|
const dom = p;
|
|
37
74
|
return {
|
|
38
75
|
id: dom.getAttribute('id'),
|
|
39
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
41
76
|
};
|
|
42
77
|
},
|
|
43
78
|
},
|
|
44
79
|
],
|
|
45
|
-
toDOM
|
|
46
|
-
const tableNode = node;
|
|
80
|
+
toDOM(node) {
|
|
47
81
|
return [
|
|
48
82
|
'table',
|
|
49
83
|
{
|
|
50
|
-
id:
|
|
51
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
84
|
+
id: node.attrs.id,
|
|
53
85
|
},
|
|
54
|
-
0,
|
|
86
|
+
['tbody', 0],
|
|
55
87
|
];
|
|
56
88
|
},
|
|
57
89
|
};
|
|
58
|
-
exports.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tableRole: 'table',
|
|
62
|
-
parseDOM: [
|
|
63
|
-
{
|
|
64
|
-
tag: 'tbody',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
toDOM() {
|
|
68
|
-
return ['tbody', 0];
|
|
69
|
-
},
|
|
70
|
-
};
|
|
90
|
+
exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
91
|
+
exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
92
|
+
exports.tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.tableElement = void 0;
|
|
19
19
|
exports.tableElement = {
|
|
20
|
-
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
20
|
+
content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -558,33 +558,32 @@ class Decoder {
|
|
|
558
558
|
},
|
|
559
559
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
560
560
|
const model = data;
|
|
561
|
-
|
|
562
|
-
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
563
|
-
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
561
|
+
return this.parseContents(model.contents, undefined, [], {
|
|
564
562
|
topNode: schema_1.schema.nodes.table.create({
|
|
565
563
|
id: model._id,
|
|
566
|
-
comments: comments.map((c) => c.attrs.id),
|
|
567
564
|
}),
|
|
568
565
|
});
|
|
569
566
|
},
|
|
570
567
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
571
568
|
const model = data;
|
|
572
569
|
const table = this.createTable(model);
|
|
570
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
573
571
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
574
572
|
const figcaption = this.getFigcaption(model);
|
|
575
573
|
const comments = this.createCommentNodes(model);
|
|
576
574
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
577
|
-
const content =
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (model.listingID) {
|
|
581
|
-
const listing = this.createListing(model.listingID);
|
|
582
|
-
content.push(listing);
|
|
575
|
+
const content = [table];
|
|
576
|
+
if (tableColGroup) {
|
|
577
|
+
content.push(tableColGroup);
|
|
583
578
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
content.push(listing);
|
|
579
|
+
if (tableElementFooter) {
|
|
580
|
+
content.push(tableElementFooter);
|
|
587
581
|
}
|
|
582
|
+
content.push(figcaption);
|
|
583
|
+
const listing = model.listingID
|
|
584
|
+
? this.createListing(model.listingID)
|
|
585
|
+
: schema_1.schema.nodes.listing.create();
|
|
586
|
+
content.push(listing);
|
|
588
587
|
return schema_1.schema.nodes.table_element.createChecked({
|
|
589
588
|
id: model._id,
|
|
590
589
|
table: model.containedObjectID,
|
|
@@ -773,23 +772,33 @@ class Decoder {
|
|
|
773
772
|
this.allowMissingElements = allowMissingElements;
|
|
774
773
|
}
|
|
775
774
|
createTable(model) {
|
|
776
|
-
const
|
|
777
|
-
const tableModel = this.getModel(
|
|
775
|
+
const tableID = model.containedObjectID;
|
|
776
|
+
const tableModel = this.getModel(tableID);
|
|
778
777
|
let table;
|
|
779
778
|
if (tableModel) {
|
|
780
779
|
table = this.decode(tableModel);
|
|
781
780
|
}
|
|
782
781
|
else if (this.allowMissingElements) {
|
|
783
782
|
table = schema_1.schema.nodes.placeholder.create({
|
|
784
|
-
id:
|
|
783
|
+
id: tableID,
|
|
785
784
|
label: 'A table',
|
|
786
785
|
});
|
|
787
786
|
}
|
|
788
787
|
else {
|
|
789
|
-
throw new errors_1.MissingElement(
|
|
788
|
+
throw new errors_1.MissingElement(tableID);
|
|
790
789
|
}
|
|
791
790
|
return table;
|
|
792
791
|
}
|
|
792
|
+
createTableColGroup(model) {
|
|
793
|
+
const tableID = model.containedObjectID;
|
|
794
|
+
const tableModel = this.getModel(tableID);
|
|
795
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
796
|
+
return undefined;
|
|
797
|
+
}
|
|
798
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
799
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
800
|
+
});
|
|
801
|
+
}
|
|
793
802
|
createTableElementFooter(model) {
|
|
794
803
|
const tableElementFooterID = model.tableElementFooterID;
|
|
795
804
|
if (!tableElementFooterID) {
|
|
@@ -115,8 +115,9 @@ function buildTableColGroup(cols) {
|
|
|
115
115
|
}
|
|
116
116
|
const tableContents = (node, parent) => {
|
|
117
117
|
const input = serializer.serializeNode(node);
|
|
118
|
+
const parentInput = serializer.serializeNode(parent);
|
|
118
119
|
const output = document.createElement('table');
|
|
119
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
120
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
120
121
|
if (colgroup) {
|
|
121
122
|
output.appendChild(colgroup);
|
|
122
123
|
}
|
|
@@ -519,23 +519,9 @@ const nodes = [
|
|
|
519
519
|
const element = node;
|
|
520
520
|
return {
|
|
521
521
|
id: element.getAttribute('id'),
|
|
522
|
-
suppressFooter: !element.querySelector('table > tfoot > tr'),
|
|
523
|
-
suppressHeader: !element.querySelector('table > thead > tr'),
|
|
524
522
|
};
|
|
525
523
|
},
|
|
526
524
|
},
|
|
527
|
-
{
|
|
528
|
-
tag: 'tbody',
|
|
529
|
-
skip: true,
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
tag: 'tfoot',
|
|
533
|
-
skip: true,
|
|
534
|
-
},
|
|
535
|
-
{
|
|
536
|
-
tag: 'thead',
|
|
537
|
-
skip: true,
|
|
538
|
-
},
|
|
539
525
|
{
|
|
540
526
|
tag: 'title',
|
|
541
527
|
node: 'section_title',
|
|
@@ -562,12 +548,12 @@ const nodes = [
|
|
|
562
548
|
},
|
|
563
549
|
{
|
|
564
550
|
tag: 'th',
|
|
565
|
-
node: '
|
|
551
|
+
node: 'table_header',
|
|
566
552
|
getAttrs: (node) => {
|
|
567
553
|
const element = node;
|
|
568
554
|
const colspan = element.getAttribute('colspan');
|
|
569
555
|
const rowspan = element.getAttribute('rowspan');
|
|
570
|
-
return Object.assign(Object.assign(Object.assign({
|
|
556
|
+
return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
571
557
|
},
|
|
572
558
|
},
|
|
573
559
|
{
|
|
@@ -236,8 +236,12 @@ export const jatsBodyTransformations = {
|
|
|
236
236
|
}
|
|
237
237
|
},
|
|
238
238
|
fixTables(body, createElement) {
|
|
239
|
-
const
|
|
240
|
-
|
|
239
|
+
const tableWraps = body.querySelectorAll('table-wrap');
|
|
240
|
+
tableWraps.forEach((tableWrap) => {
|
|
241
|
+
const table = tableWrap.querySelector('table');
|
|
242
|
+
if (!table) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
241
245
|
const colgroup = table.querySelector('colgroup');
|
|
242
246
|
const cols = table.querySelectorAll('col');
|
|
243
247
|
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
@@ -245,20 +249,7 @@ export const jatsBodyTransformations = {
|
|
|
245
249
|
for (const col of cols) {
|
|
246
250
|
colgroup.appendChild(col);
|
|
247
251
|
}
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
const tbody = table.querySelector('tbody');
|
|
251
|
-
if (tbody) {
|
|
252
|
-
const headerRow = table.querySelector('thead > tr');
|
|
253
|
-
if (!headerRow) {
|
|
254
|
-
const tr = createElement('tr');
|
|
255
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
256
|
-
}
|
|
257
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
258
|
-
if (!footerRow) {
|
|
259
|
-
const tr = createElement('tr');
|
|
260
|
-
tbody.appendChild(tr);
|
|
261
|
-
}
|
|
252
|
+
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
262
253
|
}
|
|
263
254
|
});
|
|
264
255
|
},
|
|
@@ -865,9 +865,13 @@ export class JATSExporter {
|
|
|
865
865
|
element.setAttribute('position', 'anchor');
|
|
866
866
|
return element;
|
|
867
867
|
},
|
|
868
|
-
table_body: () => ['tbody', 0],
|
|
869
868
|
table_cell: (node) => [
|
|
870
|
-
|
|
869
|
+
'td',
|
|
870
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
871
|
+
0,
|
|
872
|
+
],
|
|
873
|
+
table_header: (node) => [
|
|
874
|
+
'th',
|
|
871
875
|
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
872
876
|
0,
|
|
873
877
|
],
|
|
@@ -948,6 +952,26 @@ export class JATSExporter {
|
|
|
948
952
|
element.appendChild(this.serializeNode(childNode));
|
|
949
953
|
}
|
|
950
954
|
};
|
|
955
|
+
const appendTable = (element, node) => {
|
|
956
|
+
const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
|
|
957
|
+
const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
|
|
958
|
+
if (!tableNode) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const table = this.serializeNode(tableNode);
|
|
962
|
+
const tbodyElement = this.document.createElement('tbody');
|
|
963
|
+
while (table.firstChild) {
|
|
964
|
+
const child = table.firstChild;
|
|
965
|
+
table.removeChild(child);
|
|
966
|
+
tbodyElement.appendChild(child);
|
|
967
|
+
}
|
|
968
|
+
table.appendChild(tbodyElement);
|
|
969
|
+
if (colGroupNode) {
|
|
970
|
+
const colGroup = this.serializeNode(colGroupNode);
|
|
971
|
+
table.insertBefore(colGroup, table.firstChild);
|
|
972
|
+
}
|
|
973
|
+
element.appendChild(table);
|
|
974
|
+
};
|
|
951
975
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
952
976
|
const element = createElement(node, nodeName);
|
|
953
977
|
if (figType) {
|
|
@@ -968,7 +992,7 @@ export class JATSExporter {
|
|
|
968
992
|
const element = createElement(node, nodeName);
|
|
969
993
|
appendLabels(element, node);
|
|
970
994
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
971
|
-
|
|
995
|
+
appendTable(element, node);
|
|
972
996
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
973
997
|
if (isExecutableNodeType(node.type)) {
|
|
974
998
|
processExecutableNode(node, element);
|
package/dist/es/schema/index.js
CHANGED
|
@@ -66,11 +66,10 @@ import { sectionLabel } from './nodes/section_label';
|
|
|
66
66
|
import { sectionTitle } from './nodes/section_title';
|
|
67
67
|
import { supplement } from './nodes/supplement';
|
|
68
68
|
import { supplements } from './nodes/supplements';
|
|
69
|
-
import { table,
|
|
69
|
+
import { table, tableCell, tableHeader, tableRow } from './nodes/table';
|
|
70
70
|
import { tableCol, tableColGroup } from './nodes/table_col';
|
|
71
71
|
import { tableElement } from './nodes/table_element';
|
|
72
72
|
import { tableElementFooter } from './nodes/table_element_footer';
|
|
73
|
-
import { tableCell, tableRow } from './nodes/table_row';
|
|
74
73
|
import { text } from './nodes/text';
|
|
75
74
|
import { title } from './nodes/title';
|
|
76
75
|
import { tocElement } from './nodes/toc_element';
|
|
@@ -120,7 +119,6 @@ export * from './nodes/section_title';
|
|
|
120
119
|
export * from './nodes/table';
|
|
121
120
|
export * from './nodes/table_col';
|
|
122
121
|
export * from './nodes/table_element';
|
|
123
|
-
export * from './nodes/table_row';
|
|
124
122
|
export * from './nodes/text';
|
|
125
123
|
export * from './nodes/toc_element';
|
|
126
124
|
export * from './nodes/toc_section';
|
|
@@ -196,7 +194,6 @@ export const schema = new Schema({
|
|
|
196
194
|
section_title: sectionTitle,
|
|
197
195
|
section_title_plain: sectionTitle,
|
|
198
196
|
table,
|
|
199
|
-
table_body: tableBody,
|
|
200
197
|
table_cell: tableCell,
|
|
201
198
|
table_element: tableElement,
|
|
202
199
|
table_row: tableRow,
|
|
@@ -213,5 +210,6 @@ export const schema = new Schema({
|
|
|
213
210
|
contributors,
|
|
214
211
|
supplements,
|
|
215
212
|
supplement,
|
|
213
|
+
table_header: tableHeader,
|
|
216
214
|
},
|
|
217
215
|
});
|
|
@@ -13,19 +13,56 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { tableNodes as createTableNodes, } from 'prosemirror-tables';
|
|
17
|
+
function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
|
|
18
|
+
return {
|
|
19
|
+
default: defaultValue,
|
|
20
|
+
getFromDOM(dom) {
|
|
21
|
+
if (customGetFromDOM) {
|
|
22
|
+
return customGetFromDOM(dom);
|
|
23
|
+
}
|
|
24
|
+
return dom.getAttribute(attributeName);
|
|
25
|
+
},
|
|
26
|
+
setDOMAttr(value, attrs) {
|
|
27
|
+
if (customSetDOMAttr) {
|
|
28
|
+
customSetDOMAttr(value, attrs);
|
|
29
|
+
}
|
|
30
|
+
else if (value) {
|
|
31
|
+
attrs[attributeName] = value;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const tableOptions = {
|
|
37
|
+
cellContent: 'inline*',
|
|
38
|
+
cellAttributes: {
|
|
39
|
+
placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
|
|
40
|
+
valign: createCellAttribute('valign'),
|
|
41
|
+
align: createCellAttribute('align'),
|
|
42
|
+
scope: createCellAttribute('scope'),
|
|
43
|
+
style: createCellAttribute('style'),
|
|
44
|
+
colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
|
|
45
|
+
if (value && value !== 1) {
|
|
46
|
+
attrs['colspan'] = String(value);
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
|
|
50
|
+
if (value && value !== 1) {
|
|
51
|
+
attrs['rowspan'] = String(value);
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const tableNodes = createTableNodes(tableOptions);
|
|
16
57
|
export const table = {
|
|
17
|
-
content: 'table_colgroup? table_body',
|
|
18
|
-
tableRole: 'table',
|
|
19
|
-
isolating: true,
|
|
20
|
-
group: 'block',
|
|
21
|
-
selectable: false,
|
|
22
58
|
attrs: {
|
|
23
59
|
id: { default: '' },
|
|
24
|
-
headerRows: { default: 1 },
|
|
25
|
-
footerRows: { default: 1 },
|
|
26
60
|
dataTracked: { default: null },
|
|
27
|
-
comments: { default: null },
|
|
28
61
|
},
|
|
62
|
+
content: 'table_row+',
|
|
63
|
+
tableRole: 'table',
|
|
64
|
+
isolating: true,
|
|
65
|
+
group: 'block',
|
|
29
66
|
parseDOM: [
|
|
30
67
|
{
|
|
31
68
|
tag: 'table',
|
|
@@ -33,35 +70,20 @@ export const table = {
|
|
|
33
70
|
const dom = p;
|
|
34
71
|
return {
|
|
35
72
|
id: dom.getAttribute('id'),
|
|
36
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
37
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
38
73
|
};
|
|
39
74
|
},
|
|
40
75
|
},
|
|
41
76
|
],
|
|
42
|
-
toDOM
|
|
43
|
-
const tableNode = node;
|
|
77
|
+
toDOM(node) {
|
|
44
78
|
return [
|
|
45
79
|
'table',
|
|
46
80
|
{
|
|
47
|
-
id:
|
|
48
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
49
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
81
|
+
id: node.attrs.id,
|
|
50
82
|
},
|
|
51
|
-
0,
|
|
83
|
+
['tbody', 0],
|
|
52
84
|
];
|
|
53
85
|
},
|
|
54
86
|
};
|
|
55
|
-
export const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tableRole: 'table',
|
|
59
|
-
parseDOM: [
|
|
60
|
-
{
|
|
61
|
-
tag: 'tbody',
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
toDOM() {
|
|
65
|
-
return ['tbody', 0];
|
|
66
|
-
},
|
|
67
|
-
};
|
|
87
|
+
export const tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
88
|
+
export const tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
89
|
+
export const tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export const tableElement = {
|
|
17
|
-
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
17
|
+
content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
|
|
18
18
|
attrs: {
|
|
19
19
|
id: { default: '' },
|
|
20
20
|
paragraphStyle: { default: '' },
|
|
@@ -549,33 +549,32 @@ export class Decoder {
|
|
|
549
549
|
},
|
|
550
550
|
[ObjectTypes.Table]: (data) => {
|
|
551
551
|
const model = data;
|
|
552
|
-
|
|
553
|
-
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
554
|
-
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
552
|
+
return this.parseContents(model.contents, undefined, [], {
|
|
555
553
|
topNode: schema.nodes.table.create({
|
|
556
554
|
id: model._id,
|
|
557
|
-
comments: comments.map((c) => c.attrs.id),
|
|
558
555
|
}),
|
|
559
556
|
});
|
|
560
557
|
},
|
|
561
558
|
[ObjectTypes.TableElement]: (data) => {
|
|
562
559
|
const model = data;
|
|
563
560
|
const table = this.createTable(model);
|
|
561
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
564
562
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
565
563
|
const figcaption = this.getFigcaption(model);
|
|
566
564
|
const comments = this.createCommentNodes(model);
|
|
567
565
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
568
|
-
const content =
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
if (model.listingID) {
|
|
572
|
-
const listing = this.createListing(model.listingID);
|
|
573
|
-
content.push(listing);
|
|
566
|
+
const content = [table];
|
|
567
|
+
if (tableColGroup) {
|
|
568
|
+
content.push(tableColGroup);
|
|
574
569
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
content.push(listing);
|
|
570
|
+
if (tableElementFooter) {
|
|
571
|
+
content.push(tableElementFooter);
|
|
578
572
|
}
|
|
573
|
+
content.push(figcaption);
|
|
574
|
+
const listing = model.listingID
|
|
575
|
+
? this.createListing(model.listingID)
|
|
576
|
+
: schema.nodes.listing.create();
|
|
577
|
+
content.push(listing);
|
|
579
578
|
return schema.nodes.table_element.createChecked({
|
|
580
579
|
id: model._id,
|
|
581
580
|
table: model.containedObjectID,
|
|
@@ -764,23 +763,33 @@ export class Decoder {
|
|
|
764
763
|
this.allowMissingElements = allowMissingElements;
|
|
765
764
|
}
|
|
766
765
|
createTable(model) {
|
|
767
|
-
const
|
|
768
|
-
const tableModel = this.getModel(
|
|
766
|
+
const tableID = model.containedObjectID;
|
|
767
|
+
const tableModel = this.getModel(tableID);
|
|
769
768
|
let table;
|
|
770
769
|
if (tableModel) {
|
|
771
770
|
table = this.decode(tableModel);
|
|
772
771
|
}
|
|
773
772
|
else if (this.allowMissingElements) {
|
|
774
773
|
table = schema.nodes.placeholder.create({
|
|
775
|
-
id:
|
|
774
|
+
id: tableID,
|
|
776
775
|
label: 'A table',
|
|
777
776
|
});
|
|
778
777
|
}
|
|
779
778
|
else {
|
|
780
|
-
throw new MissingElement(
|
|
779
|
+
throw new MissingElement(tableID);
|
|
781
780
|
}
|
|
782
781
|
return table;
|
|
783
782
|
}
|
|
783
|
+
createTableColGroup(model) {
|
|
784
|
+
const tableID = model.containedObjectID;
|
|
785
|
+
const tableModel = this.getModel(tableID);
|
|
786
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
787
|
+
return undefined;
|
|
788
|
+
}
|
|
789
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
790
|
+
topNode: schema.nodes.table_colgroup.create(),
|
|
791
|
+
});
|
|
792
|
+
}
|
|
784
793
|
createTableElementFooter(model) {
|
|
785
794
|
const tableElementFooterID = model.tableElementFooterID;
|
|
786
795
|
if (!tableElementFooterID) {
|
|
@@ -107,8 +107,9 @@ function buildTableColGroup(cols) {
|
|
|
107
107
|
}
|
|
108
108
|
const tableContents = (node, parent) => {
|
|
109
109
|
const input = serializer.serializeNode(node);
|
|
110
|
+
const parentInput = serializer.serializeNode(parent);
|
|
110
111
|
const output = document.createElement('table');
|
|
111
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
112
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
112
113
|
if (colgroup) {
|
|
113
114
|
output.appendChild(colgroup);
|
|
114
115
|
}
|
|
@@ -60,7 +60,6 @@ export * from './nodes/section_title';
|
|
|
60
60
|
export * from './nodes/table';
|
|
61
61
|
export * from './nodes/table_col';
|
|
62
62
|
export * from './nodes/table_element';
|
|
63
|
-
export * from './nodes/table_row';
|
|
64
63
|
export * from './nodes/text';
|
|
65
64
|
export * from './nodes/toc_element';
|
|
66
65
|
export * from './nodes/toc_section';
|
|
@@ -13,15 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
headerRows: number;
|
|
22
|
-
footerRows: number;
|
|
23
|
-
comments?: CommentNode[];
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export declare const table: TableNodeSpec;
|
|
27
|
-
export declare const tableBody: TableNodeSpec;
|
|
16
|
+
import { NodeSpec } from 'prosemirror-model';
|
|
17
|
+
export declare const table: NodeSpec;
|
|
18
|
+
export declare const tableRow: NodeSpec;
|
|
19
|
+
export declare const tableCell: NodeSpec;
|
|
20
|
+
export declare const tableHeader: NodeSpec;
|
|
@@ -17,7 +17,7 @@ import { Fragment, Mark as ProsemirrorMark, MarkType, Node as ProsemirrorNode, N
|
|
|
17
17
|
import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from 'prosemirror-state';
|
|
18
18
|
import { EditorView, NodeView } from 'prosemirror-view';
|
|
19
19
|
export type Marks = 'bold' | 'code' | 'italic' | 'smallcaps' | 'strikethrough' | 'styled' | 'subscript' | 'superscript' | 'underline' | 'tracked_insert' | 'tracked_delete';
|
|
20
|
-
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comments' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keyword_group' | 'keywords' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'abstracts' | 'body' | 'backmatter' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | '
|
|
20
|
+
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comments' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keyword_group' | 'keywords' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'abstracts' | 'body' | 'backmatter' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'contributor' | 'table_element_footer' | 'title' | 'affiliations' | 'contributors' | 'supplements' | 'supplement' | 'table_header';
|
|
21
21
|
export type ManuscriptSchema = Schema<Nodes, Marks>;
|
|
22
22
|
export type ManuscriptEditorState = EditorState;
|
|
23
23
|
export type ManuscriptEditorView = EditorView;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "2.1.
|
|
4
|
+
"version": "2.1.4",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"mathjax-full": "^3.2.2",
|
|
37
37
|
"mime": "^3.0.0",
|
|
38
38
|
"prosemirror-model": "^1.18.3",
|
|
39
|
+
"prosemirror-tables": "^1.3.5",
|
|
39
40
|
"uuid": "^9.0.0",
|
|
40
41
|
"w3c-xmlserializer": "^4.0.0"
|
|
41
42
|
},
|
|
@@ -64,9 +65,9 @@
|
|
|
64
65
|
"eslint-plugin-mdx": "^2.0.5",
|
|
65
66
|
"eslint-plugin-prettier": "^4.2.1",
|
|
66
67
|
"eslint-plugin-promise": "^6.1.1",
|
|
67
|
-
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
68
68
|
"eslint-plugin-react": "^7.31.11",
|
|
69
69
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
70
|
+
"eslint-plugin-simple-import-sort": "^8.0.0",
|
|
70
71
|
"husky": "^8.0.2",
|
|
71
72
|
"jest": "^29.3.1",
|
|
72
73
|
"jest-environment-jsdom": "^29.3.1",
|
|
@@ -78,4 +79,4 @@
|
|
|
78
79
|
"rimraf": "^3.0.2",
|
|
79
80
|
"typescript": "^4.0.5"
|
|
80
81
|
}
|
|
81
|
-
}
|
|
82
|
+
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* © 2019 Atypon Systems LLC
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.tableCell = exports.tableRow = void 0;
|
|
19
|
-
const table_cell_styles_1 = require("../../lib/table-cell-styles");
|
|
20
|
-
const getCellAttrs = (p) => {
|
|
21
|
-
const dom = p;
|
|
22
|
-
const celltype = dom.tagName.toLowerCase();
|
|
23
|
-
const widthAttr = dom.getAttribute('data-colwidth');
|
|
24
|
-
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
|
|
25
|
-
? widthAttr.split(',').map((s) => Number(s))
|
|
26
|
-
: null;
|
|
27
|
-
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
28
|
-
const valign = dom.getAttribute('valign');
|
|
29
|
-
const align = dom.getAttribute('align');
|
|
30
|
-
const scope = dom.getAttribute('scope');
|
|
31
|
-
const style = dom.getAttribute('style');
|
|
32
|
-
return {
|
|
33
|
-
celltype,
|
|
34
|
-
colspan,
|
|
35
|
-
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
36
|
-
colwidth: widths && widths.length === colspan ? widths : null,
|
|
37
|
-
placeholder: dom.getAttribute('data-placeholder-text') || '',
|
|
38
|
-
styles: (0, table_cell_styles_1.getTableCellStyles)(dom.style),
|
|
39
|
-
valign,
|
|
40
|
-
align,
|
|
41
|
-
scope,
|
|
42
|
-
style,
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
exports.tableRow = {
|
|
46
|
-
content: 'table_cell+',
|
|
47
|
-
tableRole: 'row',
|
|
48
|
-
attrs: {
|
|
49
|
-
placeholder: { default: '' },
|
|
50
|
-
},
|
|
51
|
-
parseDOM: [
|
|
52
|
-
{
|
|
53
|
-
tag: 'tr',
|
|
54
|
-
priority: 80,
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
toDOM: (node) => {
|
|
58
|
-
const tableRowNode = node;
|
|
59
|
-
const attrs = {};
|
|
60
|
-
if (tableRowNode.attrs.placeholder) {
|
|
61
|
-
attrs['data-placeholder-text'] = tableRowNode.attrs.placeholder;
|
|
62
|
-
}
|
|
63
|
-
return ['tr', attrs, 0];
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
exports.tableCell = {
|
|
67
|
-
content: 'inline*',
|
|
68
|
-
attrs: {
|
|
69
|
-
celltype: { default: 'td' },
|
|
70
|
-
colspan: { default: 1 },
|
|
71
|
-
rowspan: { default: 1 },
|
|
72
|
-
colwidth: { default: null },
|
|
73
|
-
placeholder: { default: 'Data' },
|
|
74
|
-
styles: { default: {} },
|
|
75
|
-
valign: { default: null },
|
|
76
|
-
align: { default: null },
|
|
77
|
-
scope: { default: null },
|
|
78
|
-
style: { default: null },
|
|
79
|
-
},
|
|
80
|
-
tableRole: 'cell',
|
|
81
|
-
isolating: true,
|
|
82
|
-
parseDOM: [
|
|
83
|
-
{ tag: 'td', getAttrs: getCellAttrs },
|
|
84
|
-
{ tag: 'th', getAttrs: getCellAttrs },
|
|
85
|
-
],
|
|
86
|
-
toDOM: (node) => {
|
|
87
|
-
const tableCellNode = node;
|
|
88
|
-
const attrs = {};
|
|
89
|
-
const tag = tableCellNode.attrs.celltype;
|
|
90
|
-
if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
|
|
91
|
-
attrs.colspan = String(tableCellNode.attrs.colspan);
|
|
92
|
-
}
|
|
93
|
-
if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
|
|
94
|
-
attrs.rowspan = String(tableCellNode.attrs.rowspan);
|
|
95
|
-
}
|
|
96
|
-
if (tableCellNode.attrs.colwidth) {
|
|
97
|
-
attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
|
|
98
|
-
}
|
|
99
|
-
if (tableCellNode.attrs.placeholder) {
|
|
100
|
-
attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
|
|
101
|
-
}
|
|
102
|
-
if (!tableCellNode.textContent) {
|
|
103
|
-
attrs.class = 'placeholder';
|
|
104
|
-
}
|
|
105
|
-
const styleString = (0, table_cell_styles_1.serializeTableCellStyles)(tableCellNode.attrs.styles);
|
|
106
|
-
if (styleString) {
|
|
107
|
-
attrs.style = styleString;
|
|
108
|
-
}
|
|
109
|
-
if (tableCellNode.attrs.valign) {
|
|
110
|
-
attrs.valign = tableCellNode.attrs.valign;
|
|
111
|
-
}
|
|
112
|
-
if (tableCellNode.attrs.align) {
|
|
113
|
-
attrs.align = tableCellNode.attrs.align;
|
|
114
|
-
}
|
|
115
|
-
if (tableCellNode.attrs.scope) {
|
|
116
|
-
attrs.scope = tableCellNode.attrs.scope;
|
|
117
|
-
}
|
|
118
|
-
if (tableCellNode.attrs.style) {
|
|
119
|
-
attrs.style = tableCellNode.attrs.style;
|
|
120
|
-
}
|
|
121
|
-
return [tag, attrs, 0];
|
|
122
|
-
},
|
|
123
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 Atypon Systems LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
|
|
17
|
-
const getCellAttrs = (p) => {
|
|
18
|
-
const dom = p;
|
|
19
|
-
const celltype = dom.tagName.toLowerCase();
|
|
20
|
-
const widthAttr = dom.getAttribute('data-colwidth');
|
|
21
|
-
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
|
|
22
|
-
? widthAttr.split(',').map((s) => Number(s))
|
|
23
|
-
: null;
|
|
24
|
-
const colspan = Number(dom.getAttribute('colspan') || 1);
|
|
25
|
-
const valign = dom.getAttribute('valign');
|
|
26
|
-
const align = dom.getAttribute('align');
|
|
27
|
-
const scope = dom.getAttribute('scope');
|
|
28
|
-
const style = dom.getAttribute('style');
|
|
29
|
-
return {
|
|
30
|
-
celltype,
|
|
31
|
-
colspan,
|
|
32
|
-
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
33
|
-
colwidth: widths && widths.length === colspan ? widths : null,
|
|
34
|
-
placeholder: dom.getAttribute('data-placeholder-text') || '',
|
|
35
|
-
styles: getTableCellStyles(dom.style),
|
|
36
|
-
valign,
|
|
37
|
-
align,
|
|
38
|
-
scope,
|
|
39
|
-
style,
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
export const tableRow = {
|
|
43
|
-
content: 'table_cell+',
|
|
44
|
-
tableRole: 'row',
|
|
45
|
-
attrs: {
|
|
46
|
-
placeholder: { default: '' },
|
|
47
|
-
},
|
|
48
|
-
parseDOM: [
|
|
49
|
-
{
|
|
50
|
-
tag: 'tr',
|
|
51
|
-
priority: 80,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
toDOM: (node) => {
|
|
55
|
-
const tableRowNode = node;
|
|
56
|
-
const attrs = {};
|
|
57
|
-
if (tableRowNode.attrs.placeholder) {
|
|
58
|
-
attrs['data-placeholder-text'] = tableRowNode.attrs.placeholder;
|
|
59
|
-
}
|
|
60
|
-
return ['tr', attrs, 0];
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
export const tableCell = {
|
|
64
|
-
content: 'inline*',
|
|
65
|
-
attrs: {
|
|
66
|
-
celltype: { default: 'td' },
|
|
67
|
-
colspan: { default: 1 },
|
|
68
|
-
rowspan: { default: 1 },
|
|
69
|
-
colwidth: { default: null },
|
|
70
|
-
placeholder: { default: 'Data' },
|
|
71
|
-
styles: { default: {} },
|
|
72
|
-
valign: { default: null },
|
|
73
|
-
align: { default: null },
|
|
74
|
-
scope: { default: null },
|
|
75
|
-
style: { default: null },
|
|
76
|
-
},
|
|
77
|
-
tableRole: 'cell',
|
|
78
|
-
isolating: true,
|
|
79
|
-
parseDOM: [
|
|
80
|
-
{ tag: 'td', getAttrs: getCellAttrs },
|
|
81
|
-
{ tag: 'th', getAttrs: getCellAttrs },
|
|
82
|
-
],
|
|
83
|
-
toDOM: (node) => {
|
|
84
|
-
const tableCellNode = node;
|
|
85
|
-
const attrs = {};
|
|
86
|
-
const tag = tableCellNode.attrs.celltype;
|
|
87
|
-
if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
|
|
88
|
-
attrs.colspan = String(tableCellNode.attrs.colspan);
|
|
89
|
-
}
|
|
90
|
-
if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
|
|
91
|
-
attrs.rowspan = String(tableCellNode.attrs.rowspan);
|
|
92
|
-
}
|
|
93
|
-
if (tableCellNode.attrs.colwidth) {
|
|
94
|
-
attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
|
|
95
|
-
}
|
|
96
|
-
if (tableCellNode.attrs.placeholder) {
|
|
97
|
-
attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
|
|
98
|
-
}
|
|
99
|
-
if (!tableCellNode.textContent) {
|
|
100
|
-
attrs.class = 'placeholder';
|
|
101
|
-
}
|
|
102
|
-
const styleString = serializeTableCellStyles(tableCellNode.attrs.styles);
|
|
103
|
-
if (styleString) {
|
|
104
|
-
attrs.style = styleString;
|
|
105
|
-
}
|
|
106
|
-
if (tableCellNode.attrs.valign) {
|
|
107
|
-
attrs.valign = tableCellNode.attrs.valign;
|
|
108
|
-
}
|
|
109
|
-
if (tableCellNode.attrs.align) {
|
|
110
|
-
attrs.align = tableCellNode.attrs.align;
|
|
111
|
-
}
|
|
112
|
-
if (tableCellNode.attrs.scope) {
|
|
113
|
-
attrs.scope = tableCellNode.attrs.scope;
|
|
114
|
-
}
|
|
115
|
-
if (tableCellNode.attrs.style) {
|
|
116
|
-
attrs.style = tableCellNode.attrs.style;
|
|
117
|
-
}
|
|
118
|
-
return [tag, attrs, 0];
|
|
119
|
-
},
|
|
120
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2019 Atypon Systems LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { TableCellStyleKey } from '../../lib/table-cell-styles';
|
|
17
|
-
import { ManuscriptNode, TableNodeSpec } from '../types';
|
|
18
|
-
export interface TableRowNode extends ManuscriptNode {
|
|
19
|
-
attrs: {
|
|
20
|
-
placeholder: string;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export declare const tableRow: TableNodeSpec;
|
|
24
|
-
export type TableCellStyles = {
|
|
25
|
-
[key in TableCellStyleKey]?: string | null;
|
|
26
|
-
};
|
|
27
|
-
export interface TableCellNode extends ManuscriptNode {
|
|
28
|
-
attrs: {
|
|
29
|
-
celltype: 'td' | 'th';
|
|
30
|
-
colspan: number | null;
|
|
31
|
-
rowspan: number | null;
|
|
32
|
-
colwidth: number[] | null;
|
|
33
|
-
placeholder: string | null;
|
|
34
|
-
styles: TableCellStyles;
|
|
35
|
-
valign: string | null;
|
|
36
|
-
align: string | null;
|
|
37
|
-
scope: string | null;
|
|
38
|
-
style: string | null;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export declare const tableCell: TableNodeSpec;
|