@manuscripts/transform 2.1.1-LEAN-3377-0 → 2.1.1-LEAN-3336-21
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 -6
- package/dist/cjs/jats/importer/jats-body-transformations.js +0 -23
- package/dist/cjs/jats/importer/parse-jats-article.js +0 -1
- package/dist/cjs/jats/jats-exporter.js +27 -3
- package/dist/cjs/schema/index.js +3 -5
- package/dist/cjs/schema/nodes/table.js +73 -30
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/transformer/decode.js +19 -3
- package/dist/cjs/transformer/encode.js +2 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +2 -6
- package/dist/es/jats/importer/jats-body-transformations.js +0 -23
- package/dist/es/jats/importer/parse-jats-article.js +0 -1
- package/dist/es/jats/jats-exporter.js +27 -3
- package/dist/es/schema/index.js +2 -4
- package/dist/es/schema/nodes/table.js +72 -29
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/transformer/decode.js +19 -3
- package/dist/es/transformer/encode.js +2 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -1
- package/dist/types/schema/index.d.ts +0 -1
- package/dist/types/schema/nodes/table.d.ts +72 -10
- 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
|
@@ -530,10 +530,6 @@ const nodes = [
|
|
|
530
530
|
};
|
|
531
531
|
},
|
|
532
532
|
},
|
|
533
|
-
{
|
|
534
|
-
tag: 'tbody',
|
|
535
|
-
skip: true,
|
|
536
|
-
},
|
|
537
533
|
{
|
|
538
534
|
tag: 'tfoot',
|
|
539
535
|
skip: true,
|
|
@@ -568,12 +564,12 @@ const nodes = [
|
|
|
568
564
|
},
|
|
569
565
|
{
|
|
570
566
|
tag: 'th',
|
|
571
|
-
node: '
|
|
567
|
+
node: 'table_header',
|
|
572
568
|
getAttrs: (node) => {
|
|
573
569
|
const element = node;
|
|
574
570
|
const colspan = element.getAttribute('colspan');
|
|
575
571
|
const rowspan = element.getAttribute('rowspan');
|
|
576
|
-
return Object.assign(Object.assign(Object.assign({
|
|
572
|
+
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
573
|
},
|
|
578
574
|
},
|
|
579
575
|
{
|
|
@@ -250,29 +250,6 @@ exports.jatsBodyTransformations = {
|
|
|
250
250
|
}
|
|
251
251
|
table.insertBefore(colgroup, table.firstChild);
|
|
252
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
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
},
|
|
268
|
-
orderTableFootnote(doc, body) {
|
|
269
|
-
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
270
|
-
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
271
|
-
fnGroups.forEach((fnGroup) => {
|
|
272
|
-
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
273
|
-
? -1
|
|
274
|
-
: 0);
|
|
275
|
-
fnGroup.replaceChildren(...orderedFootnotes);
|
|
276
253
|
});
|
|
277
254
|
},
|
|
278
255
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
@@ -67,7 +67,6 @@ const parseJATSBody = (doc, body, references) => {
|
|
|
67
67
|
jats_body_transformations_1.jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
68
68
|
jats_body_transformations_1.jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
69
69
|
jats_body_transformations_1.jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
70
|
-
jats_body_transformations_1.jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
71
70
|
const node = jats_body_dom_parser_1.jatsBodyDOMParser.parse(body).firstChild;
|
|
72
71
|
if (!node) {
|
|
73
72
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -614,6 +614,11 @@ class JATSExporter {
|
|
|
614
614
|
this.createSerializer = () => {
|
|
615
615
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
616
616
|
const nodes = {
|
|
617
|
+
table_header: (node) => [
|
|
618
|
+
'th',
|
|
619
|
+
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 })),
|
|
620
|
+
0,
|
|
621
|
+
],
|
|
617
622
|
title: () => '',
|
|
618
623
|
affiliations: () => '',
|
|
619
624
|
contributors: () => '',
|
|
@@ -873,9 +878,8 @@ class JATSExporter {
|
|
|
873
878
|
element.setAttribute('position', 'anchor');
|
|
874
879
|
return element;
|
|
875
880
|
},
|
|
876
|
-
table_body: () => ['tbody', 0],
|
|
877
881
|
table_cell: (node) => [
|
|
878
|
-
|
|
882
|
+
'td',
|
|
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,78 @@
|
|
|
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
|
+
const tableOptions = {
|
|
21
|
+
cellContent: 'inline*',
|
|
22
|
+
cellAttributes: {
|
|
23
|
+
placeholder: {
|
|
24
|
+
default: 'Data',
|
|
25
|
+
getFromDOM(dom) {
|
|
26
|
+
return dom.getAttribute('data-placeholder-text') || '';
|
|
27
|
+
},
|
|
28
|
+
setDOMAttr(value, attrs) {
|
|
29
|
+
if (value) {
|
|
30
|
+
attrs['data-placeholder-text'] = value;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
valign: {
|
|
35
|
+
default: null,
|
|
36
|
+
getFromDOM(dom) {
|
|
37
|
+
return dom.getAttribute('valign');
|
|
38
|
+
},
|
|
39
|
+
setDOMAttr(value, attrs) {
|
|
40
|
+
if (value) {
|
|
41
|
+
attrs['valign'] = value;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
align: {
|
|
46
|
+
default: null,
|
|
47
|
+
getFromDOM(dom) {
|
|
48
|
+
return dom.getAttribute('align');
|
|
49
|
+
},
|
|
50
|
+
setDOMAttr(value, attrs) {
|
|
51
|
+
if (value) {
|
|
52
|
+
attrs['align'] = value;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
scope: {
|
|
57
|
+
default: null,
|
|
58
|
+
getFromDOM(dom) {
|
|
59
|
+
return dom.getAttribute('scope');
|
|
60
|
+
},
|
|
61
|
+
setDOMAttr(value, attrs) {
|
|
62
|
+
if (value) {
|
|
63
|
+
attrs['scope'] = value;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
style: {
|
|
68
|
+
default: null,
|
|
69
|
+
getFromDOM(dom) {
|
|
70
|
+
return dom.getAttribute('style');
|
|
71
|
+
},
|
|
72
|
+
setDOMAttr(value, attrs) {
|
|
73
|
+
if (value) {
|
|
74
|
+
attrs['style'] = value;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
19
81
|
exports.table = {
|
|
20
|
-
content: 'table_colgroup? table_body',
|
|
21
|
-
tableRole: 'table',
|
|
22
|
-
isolating: true,
|
|
23
|
-
group: 'block',
|
|
24
|
-
selectable: false,
|
|
25
82
|
attrs: {
|
|
26
83
|
id: { default: '' },
|
|
27
|
-
headerRows: { default: 1 },
|
|
28
|
-
footerRows: { default: 1 },
|
|
29
84
|
dataTracked: { default: null },
|
|
30
|
-
comments: { default: null },
|
|
31
85
|
},
|
|
86
|
+
content: 'table_row+',
|
|
87
|
+
tableRole: 'table',
|
|
88
|
+
isolating: true,
|
|
89
|
+
group: 'block',
|
|
32
90
|
parseDOM: [
|
|
33
91
|
{
|
|
34
92
|
tag: 'table',
|
|
@@ -36,35 +94,20 @@ exports.table = {
|
|
|
36
94
|
const dom = p;
|
|
37
95
|
return {
|
|
38
96
|
id: dom.getAttribute('id'),
|
|
39
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
41
97
|
};
|
|
42
98
|
},
|
|
43
99
|
},
|
|
44
100
|
],
|
|
45
|
-
toDOM
|
|
46
|
-
const tableNode = node;
|
|
101
|
+
toDOM(node) {
|
|
47
102
|
return [
|
|
48
103
|
'table',
|
|
49
104
|
{
|
|
50
|
-
id:
|
|
51
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
105
|
+
id: node.attrs.id,
|
|
53
106
|
},
|
|
54
|
-
0,
|
|
107
|
+
['tbody', 0],
|
|
55
108
|
];
|
|
56
109
|
},
|
|
57
110
|
};
|
|
58
|
-
exports.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tableRole: 'table',
|
|
62
|
-
parseDOM: [
|
|
63
|
-
{
|
|
64
|
-
tag: 'tbody',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
toDOM() {
|
|
68
|
-
return ['tbody', 0];
|
|
69
|
-
},
|
|
70
|
-
};
|
|
111
|
+
exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
112
|
+
exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
113
|
+
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_colgroup? (table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -569,13 +569,19 @@ class Decoder {
|
|
|
569
569
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
570
570
|
const model = data;
|
|
571
571
|
const table = this.createTable(model);
|
|
572
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
572
573
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
573
574
|
const figcaption = this.getFigcaption(model);
|
|
574
575
|
const comments = this.createCommentNodes(model);
|
|
575
576
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
576
|
-
const content =
|
|
577
|
-
|
|
578
|
-
|
|
577
|
+
const content = [table];
|
|
578
|
+
if (tableColGroup) {
|
|
579
|
+
content.unshift(tableColGroup);
|
|
580
|
+
}
|
|
581
|
+
if (tableElementFooter) {
|
|
582
|
+
content.push(tableElementFooter);
|
|
583
|
+
}
|
|
584
|
+
content.push(figcaption);
|
|
579
585
|
if (model.listingID) {
|
|
580
586
|
const listing = this.createListing(model.listingID);
|
|
581
587
|
content.push(listing);
|
|
@@ -789,6 +795,16 @@ class Decoder {
|
|
|
789
795
|
}
|
|
790
796
|
return table;
|
|
791
797
|
}
|
|
798
|
+
createTableColGroup(model) {
|
|
799
|
+
const tableId = model.containedObjectID;
|
|
800
|
+
const tableModel = this.getModel(tableId);
|
|
801
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
805
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
806
|
+
});
|
|
807
|
+
}
|
|
792
808
|
createTableElementFooter(model) {
|
|
793
809
|
const tableElementFooterID = model.tableElementFooterID;
|
|
794
810
|
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
|
}
|
|
@@ -524,10 +524,6 @@ const nodes = [
|
|
|
524
524
|
};
|
|
525
525
|
},
|
|
526
526
|
},
|
|
527
|
-
{
|
|
528
|
-
tag: 'tbody',
|
|
529
|
-
skip: true,
|
|
530
|
-
},
|
|
531
527
|
{
|
|
532
528
|
tag: 'tfoot',
|
|
533
529
|
skip: true,
|
|
@@ -562,12 +558,12 @@ const nodes = [
|
|
|
562
558
|
},
|
|
563
559
|
{
|
|
564
560
|
tag: 'th',
|
|
565
|
-
node: '
|
|
561
|
+
node: 'table_header',
|
|
566
562
|
getAttrs: (node) => {
|
|
567
563
|
const element = node;
|
|
568
564
|
const colspan = element.getAttribute('colspan');
|
|
569
565
|
const rowspan = element.getAttribute('rowspan');
|
|
570
|
-
return Object.assign(Object.assign(Object.assign({
|
|
566
|
+
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
567
|
},
|
|
572
568
|
},
|
|
573
569
|
{
|
|
@@ -247,29 +247,6 @@ export const jatsBodyTransformations = {
|
|
|
247
247
|
}
|
|
248
248
|
table.insertBefore(colgroup, table.firstChild);
|
|
249
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
|
-
}
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
},
|
|
265
|
-
orderTableFootnote(doc, body) {
|
|
266
|
-
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
267
|
-
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
268
|
-
fnGroups.forEach((fnGroup) => {
|
|
269
|
-
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
270
|
-
? -1
|
|
271
|
-
: 0);
|
|
272
|
-
fnGroup.replaceChildren(...orderedFootnotes);
|
|
273
250
|
});
|
|
274
251
|
},
|
|
275
252
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
@@ -63,7 +63,6 @@ export const parseJATSBody = (doc, body, references) => {
|
|
|
63
63
|
jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
64
64
|
jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
65
65
|
jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
66
|
-
jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
67
66
|
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
68
67
|
if (!node) {
|
|
69
68
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -606,6 +606,11 @@ export class JATSExporter {
|
|
|
606
606
|
this.createSerializer = () => {
|
|
607
607
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
608
608
|
const nodes = {
|
|
609
|
+
table_header: (node) => [
|
|
610
|
+
'th',
|
|
611
|
+
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 })),
|
|
612
|
+
0,
|
|
613
|
+
],
|
|
609
614
|
title: () => '',
|
|
610
615
|
affiliations: () => '',
|
|
611
616
|
contributors: () => '',
|
|
@@ -865,9 +870,8 @@ export class JATSExporter {
|
|
|
865
870
|
element.setAttribute('position', 'anchor');
|
|
866
871
|
return element;
|
|
867
872
|
},
|
|
868
|
-
table_body: () => ['tbody', 0],
|
|
869
873
|
table_cell: (node) => [
|
|
870
|
-
|
|
874
|
+
'td',
|
|
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,77 @@
|
|
|
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
|
+
const tableOptions = {
|
|
18
|
+
cellContent: 'inline*',
|
|
19
|
+
cellAttributes: {
|
|
20
|
+
placeholder: {
|
|
21
|
+
default: 'Data',
|
|
22
|
+
getFromDOM(dom) {
|
|
23
|
+
return dom.getAttribute('data-placeholder-text') || '';
|
|
24
|
+
},
|
|
25
|
+
setDOMAttr(value, attrs) {
|
|
26
|
+
if (value) {
|
|
27
|
+
attrs['data-placeholder-text'] = value;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
valign: {
|
|
32
|
+
default: null,
|
|
33
|
+
getFromDOM(dom) {
|
|
34
|
+
return dom.getAttribute('valign');
|
|
35
|
+
},
|
|
36
|
+
setDOMAttr(value, attrs) {
|
|
37
|
+
if (value) {
|
|
38
|
+
attrs['valign'] = value;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
align: {
|
|
43
|
+
default: null,
|
|
44
|
+
getFromDOM(dom) {
|
|
45
|
+
return dom.getAttribute('align');
|
|
46
|
+
},
|
|
47
|
+
setDOMAttr(value, attrs) {
|
|
48
|
+
if (value) {
|
|
49
|
+
attrs['align'] = value;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
scope: {
|
|
54
|
+
default: null,
|
|
55
|
+
getFromDOM(dom) {
|
|
56
|
+
return dom.getAttribute('scope');
|
|
57
|
+
},
|
|
58
|
+
setDOMAttr(value, attrs) {
|
|
59
|
+
if (value) {
|
|
60
|
+
attrs['scope'] = value;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
style: {
|
|
65
|
+
default: null,
|
|
66
|
+
getFromDOM(dom) {
|
|
67
|
+
return dom.getAttribute('style');
|
|
68
|
+
},
|
|
69
|
+
setDOMAttr(value, attrs) {
|
|
70
|
+
if (value) {
|
|
71
|
+
attrs['style'] = value;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const tableNodes = createTableNodes(tableOptions);
|
|
16
78
|
export const table = {
|
|
17
|
-
content: 'table_colgroup? table_body',
|
|
18
|
-
tableRole: 'table',
|
|
19
|
-
isolating: true,
|
|
20
|
-
group: 'block',
|
|
21
|
-
selectable: false,
|
|
22
79
|
attrs: {
|
|
23
80
|
id: { default: '' },
|
|
24
|
-
headerRows: { default: 1 },
|
|
25
|
-
footerRows: { default: 1 },
|
|
26
81
|
dataTracked: { default: null },
|
|
27
|
-
comments: { default: null },
|
|
28
82
|
},
|
|
83
|
+
content: 'table_row+',
|
|
84
|
+
tableRole: 'table',
|
|
85
|
+
isolating: true,
|
|
86
|
+
group: 'block',
|
|
29
87
|
parseDOM: [
|
|
30
88
|
{
|
|
31
89
|
tag: 'table',
|
|
@@ -33,35 +91,20 @@ export const table = {
|
|
|
33
91
|
const dom = p;
|
|
34
92
|
return {
|
|
35
93
|
id: dom.getAttribute('id'),
|
|
36
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
37
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
38
94
|
};
|
|
39
95
|
},
|
|
40
96
|
},
|
|
41
97
|
],
|
|
42
|
-
toDOM
|
|
43
|
-
const tableNode = node;
|
|
98
|
+
toDOM(node) {
|
|
44
99
|
return [
|
|
45
100
|
'table',
|
|
46
101
|
{
|
|
47
|
-
id:
|
|
48
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
49
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
102
|
+
id: node.attrs.id,
|
|
50
103
|
},
|
|
51
|
-
0,
|
|
104
|
+
['tbody', 0],
|
|
52
105
|
];
|
|
53
106
|
},
|
|
54
107
|
};
|
|
55
|
-
export const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
tableRole: 'table',
|
|
59
|
-
parseDOM: [
|
|
60
|
-
{
|
|
61
|
-
tag: 'tbody',
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
toDOM() {
|
|
65
|
-
return ['tbody', 0];
|
|
66
|
-
},
|
|
67
|
-
};
|
|
108
|
+
export const tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
109
|
+
export const tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
110
|
+
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_colgroup? (table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
18
18
|
attrs: {
|
|
19
19
|
id: { default: '' },
|
|
20
20
|
paragraphStyle: { default: '' },
|
|
@@ -560,13 +560,19 @@ export class Decoder {
|
|
|
560
560
|
[ObjectTypes.TableElement]: (data) => {
|
|
561
561
|
const model = data;
|
|
562
562
|
const table = this.createTable(model);
|
|
563
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
563
564
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
564
565
|
const figcaption = this.getFigcaption(model);
|
|
565
566
|
const comments = this.createCommentNodes(model);
|
|
566
567
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
567
|
-
const content =
|
|
568
|
-
|
|
569
|
-
|
|
568
|
+
const content = [table];
|
|
569
|
+
if (tableColGroup) {
|
|
570
|
+
content.unshift(tableColGroup);
|
|
571
|
+
}
|
|
572
|
+
if (tableElementFooter) {
|
|
573
|
+
content.push(tableElementFooter);
|
|
574
|
+
}
|
|
575
|
+
content.push(figcaption);
|
|
570
576
|
if (model.listingID) {
|
|
571
577
|
const listing = this.createListing(model.listingID);
|
|
572
578
|
content.push(listing);
|
|
@@ -780,6 +786,16 @@ export class Decoder {
|
|
|
780
786
|
}
|
|
781
787
|
return table;
|
|
782
788
|
}
|
|
789
|
+
createTableColGroup(model) {
|
|
790
|
+
const tableId = model.containedObjectID;
|
|
791
|
+
const tableModel = this.getModel(tableId);
|
|
792
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
793
|
+
return undefined;
|
|
794
|
+
}
|
|
795
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
796
|
+
topNode: schema.nodes.table_colgroup.create(),
|
|
797
|
+
});
|
|
798
|
+
}
|
|
783
799
|
createTableElementFooter(model) {
|
|
784
800
|
const tableElementFooterID = model.tableElementFooterID;
|
|
785
801
|
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
|
}
|
|
@@ -32,7 +32,6 @@ export declare const jatsBodyTransformations: {
|
|
|
32
32
|
moveFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
33
33
|
moveCaptionsToEnd(body: Element): void;
|
|
34
34
|
fixTables(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
35
|
-
orderTableFootnote(doc: Document, body: Element): void;
|
|
36
35
|
moveFloatsGroupToBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
37
36
|
createKeywords(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
38
37
|
createSuppleMaterials(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
@@ -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,77 @@
|
|
|
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
|
|
16
|
+
import { NodeSpec } from 'prosemirror-model';
|
|
17
|
+
export declare const table: NodeSpec;
|
|
18
|
+
export declare const tableRow: {
|
|
19
19
|
attrs: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
comments?: CommentNode[];
|
|
20
|
+
dataTracked: {
|
|
21
|
+
default: null;
|
|
22
|
+
};
|
|
24
23
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
content?: string | undefined;
|
|
25
|
+
marks?: string | undefined;
|
|
26
|
+
group?: string | undefined;
|
|
27
|
+
inline?: boolean | undefined;
|
|
28
|
+
atom?: boolean | undefined;
|
|
29
|
+
selectable?: boolean | undefined;
|
|
30
|
+
draggable?: boolean | undefined;
|
|
31
|
+
code?: boolean | undefined;
|
|
32
|
+
whitespace?: "pre" | "normal" | undefined;
|
|
33
|
+
definingAsContext?: boolean | undefined;
|
|
34
|
+
definingForContent?: boolean | undefined;
|
|
35
|
+
defining?: boolean | undefined;
|
|
36
|
+
isolating?: boolean | undefined;
|
|
37
|
+
toDOM?: ((node: import("prosemirror-model").Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
38
|
+
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
39
|
+
toDebugString?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
40
|
+
leafText?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare const tableCell: {
|
|
43
|
+
attrs: {
|
|
44
|
+
dataTracked: {
|
|
45
|
+
default: null;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
content?: string | undefined;
|
|
49
|
+
marks?: string | undefined;
|
|
50
|
+
group?: string | undefined;
|
|
51
|
+
inline?: boolean | undefined;
|
|
52
|
+
atom?: boolean | undefined;
|
|
53
|
+
selectable?: boolean | undefined;
|
|
54
|
+
draggable?: boolean | undefined;
|
|
55
|
+
code?: boolean | undefined;
|
|
56
|
+
whitespace?: "pre" | "normal" | undefined;
|
|
57
|
+
definingAsContext?: boolean | undefined;
|
|
58
|
+
definingForContent?: boolean | undefined;
|
|
59
|
+
defining?: boolean | undefined;
|
|
60
|
+
isolating?: boolean | undefined;
|
|
61
|
+
toDOM?: ((node: import("prosemirror-model").Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
62
|
+
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
63
|
+
toDebugString?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
64
|
+
leafText?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
65
|
+
};
|
|
66
|
+
export declare const tableHeader: {
|
|
67
|
+
attrs: {
|
|
68
|
+
dataTracked: {
|
|
69
|
+
default: null;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
content?: string | undefined;
|
|
73
|
+
marks?: string | undefined;
|
|
74
|
+
group?: string | undefined;
|
|
75
|
+
inline?: boolean | undefined;
|
|
76
|
+
atom?: boolean | undefined;
|
|
77
|
+
selectable?: boolean | undefined;
|
|
78
|
+
draggable?: boolean | undefined;
|
|
79
|
+
code?: boolean | undefined;
|
|
80
|
+
whitespace?: "pre" | "normal" | undefined;
|
|
81
|
+
definingAsContext?: boolean | undefined;
|
|
82
|
+
definingForContent?: boolean | undefined;
|
|
83
|
+
defining?: boolean | undefined;
|
|
84
|
+
isolating?: boolean | undefined;
|
|
85
|
+
toDOM?: ((node: import("prosemirror-model").Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
86
|
+
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
87
|
+
toDebugString?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
88
|
+
leafText?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
89
|
+
};
|
|
@@ -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.1-LEAN-
|
|
4
|
+
"version": "2.1.1-LEAN-3336-21",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"jszip": "^3.10.1",
|
|
36
36
|
"mathjax-full": "^3.2.2",
|
|
37
37
|
"mime": "^3.0.0",
|
|
38
|
-
"prosemirror-model": "^1.
|
|
38
|
+
"prosemirror-model": "^1.8.1",
|
|
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",
|
|
@@ -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;
|