@manuscripts/transform 2.1.1-LEAN-3336-16 → 2.1.1-LEAN-3366-0
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 +6 -2
- package/dist/cjs/jats/jats-exporter.js +3 -27
- package/dist/cjs/schema/index.js +5 -3
- package/dist/cjs/schema/nodes/table.js +47 -156
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/schema/nodes/table_row.js +123 -0
- package/dist/cjs/transformer/decode.js +3 -19
- package/dist/cjs/transformer/encode.js +1 -2
- package/dist/es/jats/importer/jats-body-dom-parser.js +6 -2
- package/dist/es/jats/jats-exporter.js +3 -27
- package/dist/es/schema/index.js +4 -2
- package/dist/es/schema/nodes/table.js +46 -155
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/schema/nodes/table_row.js +120 -0
- package/dist/es/transformer/decode.js +3 -19
- package/dist/es/transformer/encode.js +1 -2
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/nodes/table.d.ts +12 -73
- package/dist/types/schema/nodes/table_row.d.ts +41 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/decode.d.ts +0 -1
- package/package.json +5 -6
|
@@ -530,6 +530,10 @@ const nodes = [
|
|
|
530
530
|
};
|
|
531
531
|
},
|
|
532
532
|
},
|
|
533
|
+
{
|
|
534
|
+
tag: 'tbody',
|
|
535
|
+
skip: true,
|
|
536
|
+
},
|
|
533
537
|
{
|
|
534
538
|
tag: 'tfoot',
|
|
535
539
|
skip: true,
|
|
@@ -564,12 +568,12 @@ const nodes = [
|
|
|
564
568
|
},
|
|
565
569
|
{
|
|
566
570
|
tag: 'th',
|
|
567
|
-
node: '
|
|
571
|
+
node: 'table_cell',
|
|
568
572
|
getAttrs: (node) => {
|
|
569
573
|
const element = node;
|
|
570
574
|
const colspan = element.getAttribute('colspan');
|
|
571
575
|
const rowspan = element.getAttribute('rowspan');
|
|
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') });
|
|
576
|
+
return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
573
577
|
},
|
|
574
578
|
},
|
|
575
579
|
{
|
|
@@ -614,11 +614,6 @@ 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
|
-
],
|
|
622
617
|
title: () => '',
|
|
623
618
|
affiliations: () => '',
|
|
624
619
|
contributors: () => '',
|
|
@@ -878,8 +873,9 @@ class JATSExporter {
|
|
|
878
873
|
element.setAttribute('position', 'anchor');
|
|
879
874
|
return element;
|
|
880
875
|
},
|
|
876
|
+
table_body: () => ['tbody', 0],
|
|
881
877
|
table_cell: (node) => [
|
|
882
|
-
|
|
878
|
+
node.attrs.celltype,
|
|
883
879
|
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 })),
|
|
884
880
|
0,
|
|
885
881
|
],
|
|
@@ -960,26 +956,6 @@ class JATSExporter {
|
|
|
960
956
|
element.appendChild(this.serializeNode(childNode));
|
|
961
957
|
}
|
|
962
958
|
};
|
|
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
|
-
};
|
|
983
959
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
984
960
|
const element = createElement(node, nodeName);
|
|
985
961
|
if (figType) {
|
|
@@ -1000,7 +976,7 @@ class JATSExporter {
|
|
|
1000
976
|
const element = createElement(node, nodeName);
|
|
1001
977
|
appendLabels(element, node);
|
|
1002
978
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
1003
|
-
|
|
979
|
+
appendChildNodeOfType(element, node, node.type.schema.nodes.table);
|
|
1004
980
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
1005
981
|
if ((0, node_types_1.isExecutableNodeType)(node.type)) {
|
|
1006
982
|
processExecutableNode(node, element);
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -87,6 +87,7 @@ 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");
|
|
90
91
|
const text_1 = require("./nodes/text");
|
|
91
92
|
const title_1 = require("./nodes/title");
|
|
92
93
|
const toc_element_1 = require("./nodes/toc_element");
|
|
@@ -136,6 +137,7 @@ __exportStar(require("./nodes/section_title"), exports);
|
|
|
136
137
|
__exportStar(require("./nodes/table"), exports);
|
|
137
138
|
__exportStar(require("./nodes/table_col"), exports);
|
|
138
139
|
__exportStar(require("./nodes/table_element"), exports);
|
|
140
|
+
__exportStar(require("./nodes/table_row"), exports);
|
|
139
141
|
__exportStar(require("./nodes/text"), exports);
|
|
140
142
|
__exportStar(require("./nodes/toc_element"), exports);
|
|
141
143
|
__exportStar(require("./nodes/toc_section"), exports);
|
|
@@ -211,9 +213,10 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
211
213
|
section_title: section_title_1.sectionTitle,
|
|
212
214
|
section_title_plain: section_title_1.sectionTitle,
|
|
213
215
|
table: table_1.table,
|
|
214
|
-
|
|
216
|
+
table_body: table_1.tableBody,
|
|
217
|
+
table_cell: table_row_1.tableCell,
|
|
215
218
|
table_element: table_element_1.tableElement,
|
|
216
|
-
table_row:
|
|
219
|
+
table_row: table_row_1.tableRow,
|
|
217
220
|
table_col: table_col_1.tableCol,
|
|
218
221
|
table_colgroup: table_col_1.tableColGroup,
|
|
219
222
|
text: text_1.text,
|
|
@@ -227,6 +230,5 @@ exports.schema = new prosemirror_model_1.Schema({
|
|
|
227
230
|
contributors: contributors_1.contributors,
|
|
228
231
|
supplements: supplements_1.supplements,
|
|
229
232
|
supplement: supplement_1.supplement,
|
|
230
|
-
table_header: table_1.tableHeader,
|
|
231
233
|
},
|
|
232
234
|
});
|
|
@@ -15,165 +15,56 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
const modifyTableToDOM = (modifiedTable) => {
|
|
43
|
-
const originalToDOM = modifiedTable.toDOM;
|
|
44
|
-
if (!originalToDOM) {
|
|
45
|
-
throw new Error(`toDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
|
|
46
|
-
}
|
|
47
|
-
modifiedTable.toDOM = function (node) {
|
|
48
|
-
const originalArray = originalToDOM.call(this, node);
|
|
49
|
-
if (!Array.isArray(originalArray)) {
|
|
50
|
-
throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
|
|
51
|
-
}
|
|
52
|
-
const modifiedAttrs = {
|
|
53
|
-
id: node.attrs.id,
|
|
54
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
55
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
56
|
-
};
|
|
57
|
-
if (Array.isArray(originalArray[1])) {
|
|
58
|
-
originalArray.splice(1, 0, modifiedAttrs);
|
|
59
|
-
}
|
|
60
|
-
else if (typeof originalArray[1] === 'object') {
|
|
61
|
-
originalArray[1] = Object.assign(Object.assign({}, originalArray[1]), modifiedAttrs);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
throw new Error(`toDOM[1] ${originalArray[1]} is of type ${typeof originalArray[1]}, check for table schema changes in prosemirror-tables`);
|
|
65
|
-
}
|
|
66
|
-
return originalArray;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
const modifyTableParseDOM = (modifiedTable) => {
|
|
70
|
-
if (!modifiedTable.parseDOM || !modifiedTable.parseDOM[0]) {
|
|
71
|
-
throw new Error(`parseDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
|
|
72
|
-
}
|
|
73
|
-
const originalGetAttrs = modifiedTable.parseDOM[0].getAttrs;
|
|
74
|
-
let originalAttrs;
|
|
75
|
-
modifiedTable.parseDOM[0].getAttrs = function (p) {
|
|
76
|
-
const dom = p;
|
|
77
|
-
if (originalGetAttrs) {
|
|
78
|
-
originalAttrs = originalGetAttrs.call(this, p);
|
|
79
|
-
}
|
|
80
|
-
if (originalAttrs && typeof originalAttrs === 'object') {
|
|
81
|
-
return Object.assign(Object.assign({}, originalAttrs), { id: dom.getAttribute('id'), headerRows: dom.dataset && dom.dataset['header-rows'], footerRows: dom.dataset && dom.dataset['footer-rows'] });
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return {
|
|
85
|
-
id: dom.getAttribute('id'),
|
|
86
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
87
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
const modifyTableAttrs = (modifiedTable, table) => {
|
|
93
|
-
modifiedTable.attrs = Object.assign(Object.assign({}, table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null }, headerRows: { default: 1 }, footerRows: { default: 1 } });
|
|
94
|
-
};
|
|
95
|
-
const modifyTableSchema = (table) => {
|
|
96
|
-
const modifiedTable = Object.assign({}, table);
|
|
97
|
-
modifyTableAttrs(modifiedTable, table);
|
|
98
|
-
modifyTableToDOM(modifiedTable);
|
|
99
|
-
modifyTableParseDOM(modifiedTable);
|
|
100
|
-
return modifiedTable;
|
|
101
|
-
};
|
|
102
|
-
const tableOptions = {
|
|
103
|
-
tableGroup: 'block',
|
|
104
|
-
cellContent: 'inline*',
|
|
105
|
-
cellAttributes: {
|
|
106
|
-
placeholder: {
|
|
107
|
-
default: 'Data',
|
|
108
|
-
getFromDOM(dom) {
|
|
109
|
-
return dom.getAttribute('data-placeholder-text') || '';
|
|
110
|
-
},
|
|
111
|
-
setDOMAttr(value, attrs) {
|
|
112
|
-
if (value) {
|
|
113
|
-
attrs['data-placeholder-text'] = value;
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
styles: {
|
|
118
|
-
default: {},
|
|
119
|
-
getFromDOM(dom) {
|
|
120
|
-
return (0, table_cell_styles_1.getTableCellStyles)(dom.style);
|
|
121
|
-
},
|
|
122
|
-
setDOMAttr(value, attrs) {
|
|
123
|
-
const styleString = (0, table_cell_styles_1.serializeTableCellStyles)(value);
|
|
124
|
-
if (styleString) {
|
|
125
|
-
attrs['style'] = value;
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
valign: {
|
|
130
|
-
default: null,
|
|
131
|
-
getFromDOM(dom) {
|
|
132
|
-
return dom.getAttribute('valign');
|
|
133
|
-
},
|
|
134
|
-
setDOMAttr(value, attrs) {
|
|
135
|
-
if (value) {
|
|
136
|
-
attrs['valign'] = value;
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
align: {
|
|
141
|
-
default: null,
|
|
142
|
-
getFromDOM(dom) {
|
|
143
|
-
return dom.getAttribute('align');
|
|
144
|
-
},
|
|
145
|
-
setDOMAttr(value, attrs) {
|
|
146
|
-
if (value) {
|
|
147
|
-
attrs['align'] = value;
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
scope: {
|
|
152
|
-
default: null,
|
|
153
|
-
getFromDOM(dom) {
|
|
154
|
-
return dom.getAttribute('scope');
|
|
155
|
-
},
|
|
156
|
-
setDOMAttr(value, attrs) {
|
|
157
|
-
if (value) {
|
|
158
|
-
attrs['scope'] = value;
|
|
159
|
-
}
|
|
18
|
+
exports.tableBody = exports.table = void 0;
|
|
19
|
+
exports.table = {
|
|
20
|
+
content: 'table_colgroup? table_body',
|
|
21
|
+
tableRole: 'table',
|
|
22
|
+
isolating: true,
|
|
23
|
+
group: 'block',
|
|
24
|
+
selectable: false,
|
|
25
|
+
attrs: {
|
|
26
|
+
id: { default: '' },
|
|
27
|
+
headerRows: { default: 1 },
|
|
28
|
+
footerRows: { default: 1 },
|
|
29
|
+
dataTracked: { default: null },
|
|
30
|
+
comments: { default: null },
|
|
31
|
+
},
|
|
32
|
+
parseDOM: [
|
|
33
|
+
{
|
|
34
|
+
tag: 'table',
|
|
35
|
+
getAttrs: (p) => {
|
|
36
|
+
const dom = p;
|
|
37
|
+
return {
|
|
38
|
+
id: dom.getAttribute('id'),
|
|
39
|
+
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
+
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
41
|
+
};
|
|
160
42
|
},
|
|
161
43
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
44
|
+
],
|
|
45
|
+
toDOM: (node) => {
|
|
46
|
+
const tableNode = node;
|
|
47
|
+
return [
|
|
48
|
+
'table',
|
|
49
|
+
{
|
|
50
|
+
id: tableNode.attrs.id,
|
|
51
|
+
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
+
'data-footer-rows': String(node.attrs.footerRows),
|
|
171
53
|
},
|
|
54
|
+
0,
|
|
55
|
+
];
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
exports.tableBody = {
|
|
59
|
+
content: 'table_row+',
|
|
60
|
+
group: 'block',
|
|
61
|
+
tableRole: 'table',
|
|
62
|
+
parseDOM: [
|
|
63
|
+
{
|
|
64
|
+
tag: 'tbody',
|
|
172
65
|
},
|
|
66
|
+
],
|
|
67
|
+
toDOM() {
|
|
68
|
+
return ['tbody', 0];
|
|
173
69
|
},
|
|
174
70
|
};
|
|
175
|
-
exports.tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
176
|
-
exports.table = modifyTableSchema(exports.tableNodes.table);
|
|
177
|
-
exports.tableRow = exports.tableNodes.table_row;
|
|
178
|
-
exports.tableCell = modifyTableCellSchema(exports.tableNodes.table_cell);
|
|
179
|
-
exports.tableHeader = modifyTableCellSchema(exports.tableNodes.table_header);
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.tableElement = void 0;
|
|
19
19
|
exports.tableElement = {
|
|
20
|
-
content: '
|
|
20
|
+
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
+
};
|
|
@@ -569,19 +569,13 @@ 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);
|
|
573
572
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
574
573
|
const figcaption = this.getFigcaption(model);
|
|
575
574
|
const comments = this.createCommentNodes(model);
|
|
576
575
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
577
|
-
const content =
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
}
|
|
581
|
-
if (tableElementFooter) {
|
|
582
|
-
content.push(tableElementFooter);
|
|
583
|
-
}
|
|
584
|
-
content.push(figcaption);
|
|
576
|
+
const content = tableElementFooter
|
|
577
|
+
? [table, tableElementFooter, figcaption]
|
|
578
|
+
: [table, figcaption];
|
|
585
579
|
if (model.listingID) {
|
|
586
580
|
const listing = this.createListing(model.listingID);
|
|
587
581
|
content.push(listing);
|
|
@@ -795,16 +789,6 @@ class Decoder {
|
|
|
795
789
|
}
|
|
796
790
|
return table;
|
|
797
791
|
}
|
|
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
|
-
}
|
|
808
792
|
createTableElementFooter(model) {
|
|
809
793
|
const tableElementFooterID = model.tableElementFooterID;
|
|
810
794
|
if (!tableElementFooterID) {
|
|
@@ -115,9 +115,8 @@ function buildTableColGroup(cols) {
|
|
|
115
115
|
}
|
|
116
116
|
const tableContents = (node, parent) => {
|
|
117
117
|
const input = serializer.serializeNode(node);
|
|
118
|
-
const parentInput = serializer.serializeNode(parent);
|
|
119
118
|
const output = document.createElement('table');
|
|
120
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
119
|
+
const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
|
|
121
120
|
if (colgroup) {
|
|
122
121
|
output.appendChild(colgroup);
|
|
123
122
|
}
|
|
@@ -524,6 +524,10 @@ const nodes = [
|
|
|
524
524
|
};
|
|
525
525
|
},
|
|
526
526
|
},
|
|
527
|
+
{
|
|
528
|
+
tag: 'tbody',
|
|
529
|
+
skip: true,
|
|
530
|
+
},
|
|
527
531
|
{
|
|
528
532
|
tag: 'tfoot',
|
|
529
533
|
skip: true,
|
|
@@ -558,12 +562,12 @@ const nodes = [
|
|
|
558
562
|
},
|
|
559
563
|
{
|
|
560
564
|
tag: 'th',
|
|
561
|
-
node: '
|
|
565
|
+
node: 'table_cell',
|
|
562
566
|
getAttrs: (node) => {
|
|
563
567
|
const element = node;
|
|
564
568
|
const colspan = element.getAttribute('colspan');
|
|
565
569
|
const rowspan = element.getAttribute('rowspan');
|
|
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') });
|
|
570
|
+
return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
567
571
|
},
|
|
568
572
|
},
|
|
569
573
|
{
|
|
@@ -606,11 +606,6 @@ 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
|
-
],
|
|
614
609
|
title: () => '',
|
|
615
610
|
affiliations: () => '',
|
|
616
611
|
contributors: () => '',
|
|
@@ -870,8 +865,9 @@ export class JATSExporter {
|
|
|
870
865
|
element.setAttribute('position', 'anchor');
|
|
871
866
|
return element;
|
|
872
867
|
},
|
|
868
|
+
table_body: () => ['tbody', 0],
|
|
873
869
|
table_cell: (node) => [
|
|
874
|
-
|
|
870
|
+
node.attrs.celltype,
|
|
875
871
|
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 })),
|
|
876
872
|
0,
|
|
877
873
|
],
|
|
@@ -952,26 +948,6 @@ export class JATSExporter {
|
|
|
952
948
|
element.appendChild(this.serializeNode(childNode));
|
|
953
949
|
}
|
|
954
950
|
};
|
|
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
|
-
};
|
|
975
951
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
976
952
|
const element = createElement(node, nodeName);
|
|
977
953
|
if (figType) {
|
|
@@ -992,7 +968,7 @@ export class JATSExporter {
|
|
|
992
968
|
const element = createElement(node, nodeName);
|
|
993
969
|
appendLabels(element, node);
|
|
994
970
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
995
|
-
|
|
971
|
+
appendChildNodeOfType(element, node, node.type.schema.nodes.table);
|
|
996
972
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
997
973
|
if (isExecutableNodeType(node.type)) {
|
|
998
974
|
processExecutableNode(node, element);
|
package/dist/es/schema/index.js
CHANGED
|
@@ -66,10 +66,11 @@ 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, tableBody } 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';
|
|
73
74
|
import { text } from './nodes/text';
|
|
74
75
|
import { title } from './nodes/title';
|
|
75
76
|
import { tocElement } from './nodes/toc_element';
|
|
@@ -119,6 +120,7 @@ export * from './nodes/section_title';
|
|
|
119
120
|
export * from './nodes/table';
|
|
120
121
|
export * from './nodes/table_col';
|
|
121
122
|
export * from './nodes/table_element';
|
|
123
|
+
export * from './nodes/table_row';
|
|
122
124
|
export * from './nodes/text';
|
|
123
125
|
export * from './nodes/toc_element';
|
|
124
126
|
export * from './nodes/toc_section';
|
|
@@ -194,6 +196,7 @@ export const schema = new Schema({
|
|
|
194
196
|
section_title: sectionTitle,
|
|
195
197
|
section_title_plain: sectionTitle,
|
|
196
198
|
table,
|
|
199
|
+
table_body: tableBody,
|
|
197
200
|
table_cell: tableCell,
|
|
198
201
|
table_element: tableElement,
|
|
199
202
|
table_row: tableRow,
|
|
@@ -210,6 +213,5 @@ export const schema = new Schema({
|
|
|
210
213
|
contributors,
|
|
211
214
|
supplements,
|
|
212
215
|
supplement,
|
|
213
|
-
table_header: tableHeader,
|
|
214
216
|
},
|
|
215
217
|
});
|
|
@@ -13,164 +13,55 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
const modifyTableToDOM = (modifiedTable) => {
|
|
40
|
-
const originalToDOM = modifiedTable.toDOM;
|
|
41
|
-
if (!originalToDOM) {
|
|
42
|
-
throw new Error(`toDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
|
|
43
|
-
}
|
|
44
|
-
modifiedTable.toDOM = function (node) {
|
|
45
|
-
const originalArray = originalToDOM.call(this, node);
|
|
46
|
-
if (!Array.isArray(originalArray)) {
|
|
47
|
-
throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
|
|
48
|
-
}
|
|
49
|
-
const modifiedAttrs = {
|
|
50
|
-
id: node.attrs.id,
|
|
51
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
53
|
-
};
|
|
54
|
-
if (Array.isArray(originalArray[1])) {
|
|
55
|
-
originalArray.splice(1, 0, modifiedAttrs);
|
|
56
|
-
}
|
|
57
|
-
else if (typeof originalArray[1] === 'object') {
|
|
58
|
-
originalArray[1] = Object.assign(Object.assign({}, originalArray[1]), modifiedAttrs);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new Error(`toDOM[1] ${originalArray[1]} is of type ${typeof originalArray[1]}, check for table schema changes in prosemirror-tables`);
|
|
62
|
-
}
|
|
63
|
-
return originalArray;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
const modifyTableParseDOM = (modifiedTable) => {
|
|
67
|
-
if (!modifiedTable.parseDOM || !modifiedTable.parseDOM[0]) {
|
|
68
|
-
throw new Error(`parseDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
|
|
69
|
-
}
|
|
70
|
-
const originalGetAttrs = modifiedTable.parseDOM[0].getAttrs;
|
|
71
|
-
let originalAttrs;
|
|
72
|
-
modifiedTable.parseDOM[0].getAttrs = function (p) {
|
|
73
|
-
const dom = p;
|
|
74
|
-
if (originalGetAttrs) {
|
|
75
|
-
originalAttrs = originalGetAttrs.call(this, p);
|
|
76
|
-
}
|
|
77
|
-
if (originalAttrs && typeof originalAttrs === 'object') {
|
|
78
|
-
return Object.assign(Object.assign({}, originalAttrs), { id: dom.getAttribute('id'), headerRows: dom.dataset && dom.dataset['header-rows'], footerRows: dom.dataset && dom.dataset['footer-rows'] });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return {
|
|
82
|
-
id: dom.getAttribute('id'),
|
|
83
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
84
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
const modifyTableAttrs = (modifiedTable, table) => {
|
|
90
|
-
modifiedTable.attrs = Object.assign(Object.assign({}, table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null }, headerRows: { default: 1 }, footerRows: { default: 1 } });
|
|
91
|
-
};
|
|
92
|
-
const modifyTableSchema = (table) => {
|
|
93
|
-
const modifiedTable = Object.assign({}, table);
|
|
94
|
-
modifyTableAttrs(modifiedTable, table);
|
|
95
|
-
modifyTableToDOM(modifiedTable);
|
|
96
|
-
modifyTableParseDOM(modifiedTable);
|
|
97
|
-
return modifiedTable;
|
|
98
|
-
};
|
|
99
|
-
const tableOptions = {
|
|
100
|
-
tableGroup: 'block',
|
|
101
|
-
cellContent: 'inline*',
|
|
102
|
-
cellAttributes: {
|
|
103
|
-
placeholder: {
|
|
104
|
-
default: 'Data',
|
|
105
|
-
getFromDOM(dom) {
|
|
106
|
-
return dom.getAttribute('data-placeholder-text') || '';
|
|
107
|
-
},
|
|
108
|
-
setDOMAttr(value, attrs) {
|
|
109
|
-
if (value) {
|
|
110
|
-
attrs['data-placeholder-text'] = value;
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
styles: {
|
|
115
|
-
default: {},
|
|
116
|
-
getFromDOM(dom) {
|
|
117
|
-
return getTableCellStyles(dom.style);
|
|
118
|
-
},
|
|
119
|
-
setDOMAttr(value, attrs) {
|
|
120
|
-
const styleString = serializeTableCellStyles(value);
|
|
121
|
-
if (styleString) {
|
|
122
|
-
attrs['style'] = value;
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
valign: {
|
|
127
|
-
default: null,
|
|
128
|
-
getFromDOM(dom) {
|
|
129
|
-
return dom.getAttribute('valign');
|
|
130
|
-
},
|
|
131
|
-
setDOMAttr(value, attrs) {
|
|
132
|
-
if (value) {
|
|
133
|
-
attrs['valign'] = value;
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
align: {
|
|
138
|
-
default: null,
|
|
139
|
-
getFromDOM(dom) {
|
|
140
|
-
return dom.getAttribute('align');
|
|
141
|
-
},
|
|
142
|
-
setDOMAttr(value, attrs) {
|
|
143
|
-
if (value) {
|
|
144
|
-
attrs['align'] = value;
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
scope: {
|
|
149
|
-
default: null,
|
|
150
|
-
getFromDOM(dom) {
|
|
151
|
-
return dom.getAttribute('scope');
|
|
152
|
-
},
|
|
153
|
-
setDOMAttr(value, attrs) {
|
|
154
|
-
if (value) {
|
|
155
|
-
attrs['scope'] = value;
|
|
156
|
-
}
|
|
16
|
+
export const table = {
|
|
17
|
+
content: 'table_colgroup? table_body',
|
|
18
|
+
tableRole: 'table',
|
|
19
|
+
isolating: true,
|
|
20
|
+
group: 'block',
|
|
21
|
+
selectable: false,
|
|
22
|
+
attrs: {
|
|
23
|
+
id: { default: '' },
|
|
24
|
+
headerRows: { default: 1 },
|
|
25
|
+
footerRows: { default: 1 },
|
|
26
|
+
dataTracked: { default: null },
|
|
27
|
+
comments: { default: null },
|
|
28
|
+
},
|
|
29
|
+
parseDOM: [
|
|
30
|
+
{
|
|
31
|
+
tag: 'table',
|
|
32
|
+
getAttrs: (p) => {
|
|
33
|
+
const dom = p;
|
|
34
|
+
return {
|
|
35
|
+
id: dom.getAttribute('id'),
|
|
36
|
+
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
37
|
+
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
38
|
+
};
|
|
157
39
|
},
|
|
158
40
|
},
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
41
|
+
],
|
|
42
|
+
toDOM: (node) => {
|
|
43
|
+
const tableNode = node;
|
|
44
|
+
return [
|
|
45
|
+
'table',
|
|
46
|
+
{
|
|
47
|
+
id: tableNode.attrs.id,
|
|
48
|
+
'data-header-rows': String(node.attrs.headerRows),
|
|
49
|
+
'data-footer-rows': String(node.attrs.footerRows),
|
|
168
50
|
},
|
|
51
|
+
0,
|
|
52
|
+
];
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const tableBody = {
|
|
56
|
+
content: 'table_row+',
|
|
57
|
+
group: 'block',
|
|
58
|
+
tableRole: 'table',
|
|
59
|
+
parseDOM: [
|
|
60
|
+
{
|
|
61
|
+
tag: 'tbody',
|
|
169
62
|
},
|
|
63
|
+
],
|
|
64
|
+
toDOM() {
|
|
65
|
+
return ['tbody', 0];
|
|
170
66
|
},
|
|
171
67
|
};
|
|
172
|
-
export const tableNodes = createTableNodes(tableOptions);
|
|
173
|
-
export const table = modifyTableSchema(tableNodes.table);
|
|
174
|
-
export const tableRow = tableNodes.table_row;
|
|
175
|
-
export const tableCell = modifyTableCellSchema(tableNodes.table_cell);
|
|
176
|
-
export const tableHeader = modifyTableCellSchema(tableNodes.table_header);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export const tableElement = {
|
|
17
|
-
content: '
|
|
17
|
+
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
18
18
|
attrs: {
|
|
19
19
|
id: { default: '' },
|
|
20
20
|
paragraphStyle: { default: '' },
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
};
|
|
@@ -560,19 +560,13 @@ 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);
|
|
564
563
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
565
564
|
const figcaption = this.getFigcaption(model);
|
|
566
565
|
const comments = this.createCommentNodes(model);
|
|
567
566
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
568
|
-
const content =
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
}
|
|
572
|
-
if (tableElementFooter) {
|
|
573
|
-
content.push(tableElementFooter);
|
|
574
|
-
}
|
|
575
|
-
content.push(figcaption);
|
|
567
|
+
const content = tableElementFooter
|
|
568
|
+
? [table, tableElementFooter, figcaption]
|
|
569
|
+
: [table, figcaption];
|
|
576
570
|
if (model.listingID) {
|
|
577
571
|
const listing = this.createListing(model.listingID);
|
|
578
572
|
content.push(listing);
|
|
@@ -786,16 +780,6 @@ export class Decoder {
|
|
|
786
780
|
}
|
|
787
781
|
return table;
|
|
788
782
|
}
|
|
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
|
-
}
|
|
799
783
|
createTableElementFooter(model) {
|
|
800
784
|
const tableElementFooterID = model.tableElementFooterID;
|
|
801
785
|
if (!tableElementFooterID) {
|
|
@@ -107,9 +107,8 @@ function buildTableColGroup(cols) {
|
|
|
107
107
|
}
|
|
108
108
|
const tableContents = (node, parent) => {
|
|
109
109
|
const input = serializer.serializeNode(node);
|
|
110
|
-
const parentInput = serializer.serializeNode(parent);
|
|
111
110
|
const output = document.createElement('table');
|
|
112
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
111
|
+
const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
|
|
113
112
|
if (colgroup) {
|
|
114
113
|
output.appendChild(colgroup);
|
|
115
114
|
}
|
|
@@ -60,6 +60,7 @@ 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';
|
|
63
64
|
export * from './nodes/text';
|
|
64
65
|
export * from './nodes/toc_element';
|
|
65
66
|
export * from './nodes/toc_section';
|
|
@@ -13,76 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} | 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: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
38
|
-
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
39
|
-
toDebugString?: ((node: Node) => string) | undefined;
|
|
40
|
-
leafText?: ((node: Node) => string) | undefined;
|
|
41
|
-
};
|
|
42
|
-
export declare const tableRow: NodeSpec;
|
|
43
|
-
export declare const tableCell: {
|
|
44
|
-
[x: string]: any;
|
|
45
|
-
content?: string | undefined;
|
|
46
|
-
marks?: string | undefined;
|
|
47
|
-
group?: string | undefined;
|
|
48
|
-
inline?: boolean | undefined;
|
|
49
|
-
atom?: boolean | undefined;
|
|
50
|
-
attrs?: {
|
|
51
|
-
[name: string]: import("prosemirror-model").AttributeSpec;
|
|
52
|
-
} | 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: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
62
|
-
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
63
|
-
toDebugString?: ((node: Node) => string) | undefined;
|
|
64
|
-
leafText?: ((node: Node) => string) | undefined;
|
|
65
|
-
};
|
|
66
|
-
export declare const tableHeader: {
|
|
67
|
-
[x: string]: any;
|
|
68
|
-
content?: string | undefined;
|
|
69
|
-
marks?: string | undefined;
|
|
70
|
-
group?: string | undefined;
|
|
71
|
-
inline?: boolean | undefined;
|
|
72
|
-
atom?: boolean | undefined;
|
|
73
|
-
attrs?: {
|
|
74
|
-
[name: string]: import("prosemirror-model").AttributeSpec;
|
|
75
|
-
} | undefined;
|
|
76
|
-
selectable?: boolean | undefined;
|
|
77
|
-
draggable?: boolean | undefined;
|
|
78
|
-
code?: boolean | undefined;
|
|
79
|
-
whitespace?: "pre" | "normal" | undefined;
|
|
80
|
-
definingAsContext?: boolean | undefined;
|
|
81
|
-
definingForContent?: boolean | undefined;
|
|
82
|
-
defining?: boolean | undefined;
|
|
83
|
-
isolating?: boolean | undefined;
|
|
84
|
-
toDOM?: ((node: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
|
|
85
|
-
parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
|
|
86
|
-
toDebugString?: ((node: Node) => string) | undefined;
|
|
87
|
-
leafText?: ((node: Node) => string) | undefined;
|
|
88
|
-
};
|
|
16
|
+
import { ManuscriptNode, TableNodeSpec } from '../types';
|
|
17
|
+
import { CommentNode } from './comment';
|
|
18
|
+
export interface TableNode extends ManuscriptNode {
|
|
19
|
+
attrs: {
|
|
20
|
+
id: string;
|
|
21
|
+
headerRows: number;
|
|
22
|
+
footerRows: number;
|
|
23
|
+
comments?: CommentNode[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare const table: TableNodeSpec;
|
|
27
|
+
export declare const tableBody: TableNodeSpec;
|
|
@@ -0,0 +1,41 @@
|
|
|
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;
|
|
@@ -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' | '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'
|
|
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_body' | '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';
|
|
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-3366-0",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -29,14 +29,13 @@
|
|
|
29
29
|
"version": "yarn build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@manuscripts/json-schema": "
|
|
33
|
-
"@manuscripts/library": "1.3.2",
|
|
32
|
+
"@manuscripts/json-schema": "2.2.2-LEAN-3366-0",
|
|
33
|
+
"@manuscripts/library": "1.3.2-LEAN-3366-0",
|
|
34
34
|
"debug": "^4.3.4",
|
|
35
35
|
"jszip": "^3.10.1",
|
|
36
36
|
"mathjax-full": "^3.2.2",
|
|
37
37
|
"mime": "^3.0.0",
|
|
38
|
-
"prosemirror-model": "^1.
|
|
39
|
-
"prosemirror-tables": "^1.3.5",
|
|
38
|
+
"prosemirror-model": "^1.18.3",
|
|
40
39
|
"uuid": "^9.0.0",
|
|
41
40
|
"w3c-xmlserializer": "^4.0.0"
|
|
42
41
|
},
|
|
@@ -65,9 +64,9 @@
|
|
|
65
64
|
"eslint-plugin-mdx": "^2.0.5",
|
|
66
65
|
"eslint-plugin-prettier": "^4.2.1",
|
|
67
66
|
"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",
|
|
71
70
|
"husky": "^8.0.2",
|
|
72
71
|
"jest": "^29.3.1",
|
|
73
72
|
"jest-environment-jsdom": "^29.3.1",
|