@manuscripts/transform 2.1.1-LEAN-3336-6 → 2.1.1-LEAN-3336-7
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 +1 -5
- package/dist/cjs/jats/importer/jats-body-transformations.js +19 -10
- package/dist/cjs/jats/importer/parse-jats-article.js +2 -1
- package/dist/cjs/jats/jats-exporter.js +23 -3
- package/dist/cjs/schema/nodes/table.js +74 -12
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/transformer/decode.js +13 -0
- package/dist/cjs/transformer/encode.js +19 -0
- package/dist/es/jats/importer/jats-body-dom-parser.js +1 -5
- package/dist/es/jats/importer/jats-body-transformations.js +19 -10
- package/dist/es/jats/importer/parse-jats-article.js +2 -1
- package/dist/es/jats/jats-exporter.js +23 -3
- package/dist/es/schema/nodes/table.js +74 -12
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/transformer/decode.js +13 -0
- package/dist/es/transformer/encode.js +19 -0
- package/dist/types/schema/nodes/table.d.ts +2 -2
- package/dist/types/transformer/decode.d.ts +1 -0
- package/package.json +2 -2
|
@@ -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,
|
|
@@ -573,7 +569,7 @@ const nodes = [
|
|
|
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
|
{
|
|
@@ -241,18 +241,27 @@ exports.jatsBodyTransformations = {
|
|
|
241
241
|
fixTables(body, createElement) {
|
|
242
242
|
const tables = body.querySelectorAll('table-wrap > table');
|
|
243
243
|
tables.forEach((table) => {
|
|
244
|
+
var _a;
|
|
245
|
+
const colgroup = table.querySelector('colgroup');
|
|
246
|
+
const cols = table.querySelectorAll('col');
|
|
247
|
+
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
248
|
+
const colgroup = createElement('colgroup');
|
|
249
|
+
for (const col of cols) {
|
|
250
|
+
colgroup.appendChild(col);
|
|
251
|
+
}
|
|
252
|
+
(_a = table.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(colgroup, table);
|
|
253
|
+
}
|
|
254
|
+
const rows = table.querySelectorAll('tr');
|
|
255
|
+
for (const row of rows) {
|
|
256
|
+
table.appendChild(row);
|
|
257
|
+
}
|
|
258
|
+
const thead = table.querySelector('thead');
|
|
259
|
+
if (thead) {
|
|
260
|
+
table.removeChild(thead);
|
|
261
|
+
}
|
|
244
262
|
const tbody = table.querySelector('tbody');
|
|
245
263
|
if (tbody) {
|
|
246
|
-
|
|
247
|
-
if (!headerRow) {
|
|
248
|
-
const tr = createElement('tr');
|
|
249
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
250
|
-
}
|
|
251
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
252
|
-
if (!footerRow) {
|
|
253
|
-
const tr = createElement('tr');
|
|
254
|
-
tbody.appendChild(tr);
|
|
255
|
-
}
|
|
264
|
+
table.removeChild(tbody);
|
|
256
265
|
}
|
|
257
266
|
});
|
|
258
267
|
},
|
|
@@ -73,7 +73,8 @@ const parseJATSBody = (doc, body, references) => {
|
|
|
73
73
|
}
|
|
74
74
|
const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
|
|
75
75
|
(0, jats_parser_utils_1.updateDocumentIDs)(node, replacements);
|
|
76
|
-
|
|
76
|
+
const models = (0, transformer_1.encode)(node);
|
|
77
|
+
return models.values();
|
|
77
78
|
};
|
|
78
79
|
exports.parseJATSBody = parseJATSBody;
|
|
79
80
|
const createBibliographyModels = (references) => {
|
|
@@ -615,7 +615,7 @@ class JATSExporter {
|
|
|
615
615
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
616
616
|
const nodes = {
|
|
617
617
|
table_header: (node) => [
|
|
618
|
-
|
|
618
|
+
'th',
|
|
619
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
620
|
0,
|
|
621
621
|
],
|
|
@@ -879,7 +879,7 @@ class JATSExporter {
|
|
|
879
879
|
return element;
|
|
880
880
|
},
|
|
881
881
|
table_cell: (node) => [
|
|
882
|
-
|
|
882
|
+
'td',
|
|
883
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 })),
|
|
884
884
|
0,
|
|
885
885
|
],
|
|
@@ -960,6 +960,26 @@ class JATSExporter {
|
|
|
960
960
|
element.appendChild(this.serializeNode(childNode));
|
|
961
961
|
}
|
|
962
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 = 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
|
+
};
|
|
963
983
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
964
984
|
const element = createElement(node, nodeName);
|
|
965
985
|
if (figType) {
|
|
@@ -980,7 +1000,7 @@ class JATSExporter {
|
|
|
980
1000
|
const element = createElement(node, nodeName);
|
|
981
1001
|
appendLabels(element, node);
|
|
982
1002
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
983
|
-
|
|
1003
|
+
appendTable(element, node);
|
|
984
1004
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
985
1005
|
if ((0, node_types_1.isExecutableNodeType)(node.type)) {
|
|
986
1006
|
processExecutableNode(node, element);
|
|
@@ -15,22 +15,84 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.tableHeader = exports.
|
|
18
|
+
exports.tableHeader = exports.tableRow = exports.tableCell = exports.table = exports.tableNodes = void 0;
|
|
19
19
|
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
20
|
+
const table_cell_styles_1 = require("../../lib/table-cell-styles");
|
|
20
21
|
const tableOptions = {
|
|
21
22
|
tableGroup: 'block',
|
|
22
23
|
cellContent: 'inline*',
|
|
23
24
|
cellAttributes: {
|
|
24
|
-
placeholder: {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
placeholder: {
|
|
26
|
+
default: 'Data',
|
|
27
|
+
getFromDOM(dom) {
|
|
28
|
+
return dom.getAttribute('data-placeholder-text') || '';
|
|
29
|
+
},
|
|
30
|
+
setDOMAttr(value, attrs) {
|
|
31
|
+
if (value) {
|
|
32
|
+
attrs['data-placeholder-text'] = value;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
styles: {
|
|
37
|
+
default: {},
|
|
38
|
+
getFromDOM(dom) {
|
|
39
|
+
return (0, table_cell_styles_1.getTableCellStyles)(dom.style);
|
|
40
|
+
},
|
|
41
|
+
setDOMAttr(value, attrs) {
|
|
42
|
+
const styleString = (0, table_cell_styles_1.serializeTableCellStyles)(value);
|
|
43
|
+
if (styleString) {
|
|
44
|
+
attrs['style'] = value;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
valign: {
|
|
49
|
+
default: null,
|
|
50
|
+
getFromDOM(dom) {
|
|
51
|
+
return dom.getAttribute('valign');
|
|
52
|
+
},
|
|
53
|
+
setDOMAttr(value, attrs) {
|
|
54
|
+
if (value) {
|
|
55
|
+
attrs['valign'] = value;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
align: {
|
|
60
|
+
default: null,
|
|
61
|
+
getFromDOM(dom) {
|
|
62
|
+
return dom.getAttribute('align');
|
|
63
|
+
},
|
|
64
|
+
setDOMAttr(value, attrs) {
|
|
65
|
+
if (value) {
|
|
66
|
+
attrs['align'] = value;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
scope: {
|
|
71
|
+
default: null,
|
|
72
|
+
getFromDOM(dom) {
|
|
73
|
+
return dom.getAttribute('scope');
|
|
74
|
+
},
|
|
75
|
+
setDOMAttr(value, attrs) {
|
|
76
|
+
if (value) {
|
|
77
|
+
attrs['scope'] = value;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
style: {
|
|
82
|
+
default: null,
|
|
83
|
+
getFromDOM(dom) {
|
|
84
|
+
return dom.getAttribute('style');
|
|
85
|
+
},
|
|
86
|
+
setDOMAttr(value, attrs) {
|
|
87
|
+
if (value) {
|
|
88
|
+
attrs['style'] = value;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
},
|
|
30
92
|
},
|
|
31
93
|
};
|
|
32
|
-
exports.
|
|
33
|
-
exports.table = Object.assign(Object.assign({}, exports.
|
|
34
|
-
exports.
|
|
35
|
-
exports.
|
|
36
|
-
exports.tableHeader = exports.
|
|
94
|
+
exports.tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
95
|
+
exports.table = Object.assign(Object.assign({}, exports.tableNodes.table), { attrs: Object.assign(Object.assign({}, exports.tableNodes.table.attrs), { id: { default: '' } }) });
|
|
96
|
+
exports.tableCell = exports.tableNodes.table_cell;
|
|
97
|
+
exports.tableRow = exports.tableNodes.table_row;
|
|
98
|
+
exports.tableHeader = 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: '(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: '' },
|
|
@@ -566,6 +566,7 @@ class Decoder {
|
|
|
566
566
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
567
567
|
const model = data;
|
|
568
568
|
const table = this.createTable(model);
|
|
569
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
569
570
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
570
571
|
const figcaption = this.getFigcaption(model);
|
|
571
572
|
const comments = this.createCommentNodes(model);
|
|
@@ -573,6 +574,9 @@ class Decoder {
|
|
|
573
574
|
const content = tableElementFooter
|
|
574
575
|
? [table, tableElementFooter, figcaption]
|
|
575
576
|
: [table, figcaption];
|
|
577
|
+
if (tableColGroup) {
|
|
578
|
+
content.unshift(tableColGroup);
|
|
579
|
+
}
|
|
576
580
|
if (model.listingID) {
|
|
577
581
|
const listing = this.createListing(model.listingID);
|
|
578
582
|
content.push(listing);
|
|
@@ -786,6 +790,15 @@ class Decoder {
|
|
|
786
790
|
}
|
|
787
791
|
return table;
|
|
788
792
|
}
|
|
793
|
+
createTableColGroup(model) {
|
|
794
|
+
const tableId = model.containedObjectID;
|
|
795
|
+
const tableModel = this.getModel(tableId);
|
|
796
|
+
if (tableModel) {
|
|
797
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
798
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
}
|
|
789
802
|
createTableElementFooter(model) {
|
|
790
803
|
const tableElementFooterID = model.tableElementFooterID;
|
|
791
804
|
if (!tableElementFooterID) {
|
|
@@ -99,9 +99,28 @@ const buildTableSection = (tagName, inputRows, parent) => {
|
|
|
99
99
|
}
|
|
100
100
|
return section;
|
|
101
101
|
};
|
|
102
|
+
function buildTableColGroup(cols) {
|
|
103
|
+
if (cols.length === 0) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const colgroup = document.createElement('colgroup');
|
|
107
|
+
for (const inputCol of cols) {
|
|
108
|
+
const col = document.createElement('col');
|
|
109
|
+
for (const attribute of inputCol.attributes) {
|
|
110
|
+
col.setAttribute(attribute.name, attribute.value);
|
|
111
|
+
}
|
|
112
|
+
colgroup.appendChild(inputCol);
|
|
113
|
+
}
|
|
114
|
+
return colgroup;
|
|
115
|
+
}
|
|
102
116
|
const tableContents = (node, parent) => {
|
|
103
117
|
const input = serializer.serializeNode(node);
|
|
118
|
+
const parentInput = serializer.serializeNode(parent);
|
|
104
119
|
const output = document.createElement('table');
|
|
120
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
121
|
+
if (colgroup) {
|
|
122
|
+
output.appendChild(colgroup);
|
|
123
|
+
}
|
|
105
124
|
output.setAttribute('id', parent.attrs.id);
|
|
106
125
|
output.classList.add('MPElement');
|
|
107
126
|
if (parent.attrs.tableStyle) {
|
|
@@ -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,
|
|
@@ -567,7 +563,7 @@ const nodes = [
|
|
|
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
|
{
|
|
@@ -238,18 +238,27 @@ export const jatsBodyTransformations = {
|
|
|
238
238
|
fixTables(body, createElement) {
|
|
239
239
|
const tables = body.querySelectorAll('table-wrap > table');
|
|
240
240
|
tables.forEach((table) => {
|
|
241
|
+
var _a;
|
|
242
|
+
const colgroup = table.querySelector('colgroup');
|
|
243
|
+
const cols = table.querySelectorAll('col');
|
|
244
|
+
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
245
|
+
const colgroup = createElement('colgroup');
|
|
246
|
+
for (const col of cols) {
|
|
247
|
+
colgroup.appendChild(col);
|
|
248
|
+
}
|
|
249
|
+
(_a = table.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(colgroup, table);
|
|
250
|
+
}
|
|
251
|
+
const rows = table.querySelectorAll('tr');
|
|
252
|
+
for (const row of rows) {
|
|
253
|
+
table.appendChild(row);
|
|
254
|
+
}
|
|
255
|
+
const thead = table.querySelector('thead');
|
|
256
|
+
if (thead) {
|
|
257
|
+
table.removeChild(thead);
|
|
258
|
+
}
|
|
241
259
|
const tbody = table.querySelector('tbody');
|
|
242
260
|
if (tbody) {
|
|
243
|
-
|
|
244
|
-
if (!headerRow) {
|
|
245
|
-
const tr = createElement('tr');
|
|
246
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
247
|
-
}
|
|
248
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
249
|
-
if (!footerRow) {
|
|
250
|
-
const tr = createElement('tr');
|
|
251
|
-
tbody.appendChild(tr);
|
|
252
|
-
}
|
|
261
|
+
table.removeChild(tbody);
|
|
253
262
|
}
|
|
254
263
|
});
|
|
255
264
|
},
|
|
@@ -69,7 +69,8 @@ export const parseJATSBody = (doc, body, references) => {
|
|
|
69
69
|
}
|
|
70
70
|
const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
|
|
71
71
|
updateDocumentIDs(node, replacements);
|
|
72
|
-
|
|
72
|
+
const models = encode(node);
|
|
73
|
+
return models.values();
|
|
73
74
|
};
|
|
74
75
|
const createBibliographyModels = (references) => {
|
|
75
76
|
const models = [];
|
|
@@ -607,7 +607,7 @@ export class JATSExporter {
|
|
|
607
607
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
608
608
|
const nodes = {
|
|
609
609
|
table_header: (node) => [
|
|
610
|
-
|
|
610
|
+
'th',
|
|
611
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
612
|
0,
|
|
613
613
|
],
|
|
@@ -871,7 +871,7 @@ export class JATSExporter {
|
|
|
871
871
|
return element;
|
|
872
872
|
},
|
|
873
873
|
table_cell: (node) => [
|
|
874
|
-
|
|
874
|
+
'td',
|
|
875
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 })),
|
|
876
876
|
0,
|
|
877
877
|
],
|
|
@@ -952,6 +952,26 @@ export class JATSExporter {
|
|
|
952
952
|
element.appendChild(this.serializeNode(childNode));
|
|
953
953
|
}
|
|
954
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 = 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
|
+
};
|
|
955
975
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
956
976
|
const element = createElement(node, nodeName);
|
|
957
977
|
if (figType) {
|
|
@@ -972,7 +992,7 @@ export class JATSExporter {
|
|
|
972
992
|
const element = createElement(node, nodeName);
|
|
973
993
|
appendLabels(element, node);
|
|
974
994
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
975
|
-
|
|
995
|
+
appendTable(element, node);
|
|
976
996
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
977
997
|
if (isExecutableNodeType(node.type)) {
|
|
978
998
|
processExecutableNode(node, element);
|
|
@@ -13,21 +13,83 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { tableNodes } from 'prosemirror-tables';
|
|
16
|
+
import { tableNodes as createTableNodes, } from 'prosemirror-tables';
|
|
17
|
+
import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
|
|
17
18
|
const tableOptions = {
|
|
18
19
|
tableGroup: 'block',
|
|
19
20
|
cellContent: 'inline*',
|
|
20
21
|
cellAttributes: {
|
|
21
|
-
placeholder: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
placeholder: {
|
|
23
|
+
default: 'Data',
|
|
24
|
+
getFromDOM(dom) {
|
|
25
|
+
return dom.getAttribute('data-placeholder-text') || '';
|
|
26
|
+
},
|
|
27
|
+
setDOMAttr(value, attrs) {
|
|
28
|
+
if (value) {
|
|
29
|
+
attrs['data-placeholder-text'] = value;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
styles: {
|
|
34
|
+
default: {},
|
|
35
|
+
getFromDOM(dom) {
|
|
36
|
+
return getTableCellStyles(dom.style);
|
|
37
|
+
},
|
|
38
|
+
setDOMAttr(value, attrs) {
|
|
39
|
+
const styleString = serializeTableCellStyles(value);
|
|
40
|
+
if (styleString) {
|
|
41
|
+
attrs['style'] = value;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
valign: {
|
|
46
|
+
default: null,
|
|
47
|
+
getFromDOM(dom) {
|
|
48
|
+
return dom.getAttribute('valign');
|
|
49
|
+
},
|
|
50
|
+
setDOMAttr(value, attrs) {
|
|
51
|
+
if (value) {
|
|
52
|
+
attrs['valign'] = value;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
align: {
|
|
57
|
+
default: null,
|
|
58
|
+
getFromDOM(dom) {
|
|
59
|
+
return dom.getAttribute('align');
|
|
60
|
+
},
|
|
61
|
+
setDOMAttr(value, attrs) {
|
|
62
|
+
if (value) {
|
|
63
|
+
attrs['align'] = value;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
scope: {
|
|
68
|
+
default: null,
|
|
69
|
+
getFromDOM(dom) {
|
|
70
|
+
return dom.getAttribute('scope');
|
|
71
|
+
},
|
|
72
|
+
setDOMAttr(value, attrs) {
|
|
73
|
+
if (value) {
|
|
74
|
+
attrs['scope'] = value;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
style: {
|
|
79
|
+
default: null,
|
|
80
|
+
getFromDOM(dom) {
|
|
81
|
+
return dom.getAttribute('style');
|
|
82
|
+
},
|
|
83
|
+
setDOMAttr(value, attrs) {
|
|
84
|
+
if (value) {
|
|
85
|
+
attrs['style'] = value;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
},
|
|
27
89
|
},
|
|
28
90
|
};
|
|
29
|
-
export const
|
|
30
|
-
export const table = Object.assign(Object.assign({},
|
|
31
|
-
export const
|
|
32
|
-
export const
|
|
33
|
-
export const tableHeader =
|
|
91
|
+
export const tableNodes = createTableNodes(tableOptions);
|
|
92
|
+
export const table = Object.assign(Object.assign({}, tableNodes.table), { attrs: Object.assign(Object.assign({}, tableNodes.table.attrs), { id: { default: '' } }) });
|
|
93
|
+
export const tableCell = tableNodes.table_cell;
|
|
94
|
+
export const tableRow = tableNodes.table_row;
|
|
95
|
+
export const tableHeader = tableNodes.table_header;
|
|
@@ -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: '' },
|
|
@@ -557,6 +557,7 @@ export class Decoder {
|
|
|
557
557
|
[ObjectTypes.TableElement]: (data) => {
|
|
558
558
|
const model = data;
|
|
559
559
|
const table = this.createTable(model);
|
|
560
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
560
561
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
561
562
|
const figcaption = this.getFigcaption(model);
|
|
562
563
|
const comments = this.createCommentNodes(model);
|
|
@@ -564,6 +565,9 @@ export class Decoder {
|
|
|
564
565
|
const content = tableElementFooter
|
|
565
566
|
? [table, tableElementFooter, figcaption]
|
|
566
567
|
: [table, figcaption];
|
|
568
|
+
if (tableColGroup) {
|
|
569
|
+
content.unshift(tableColGroup);
|
|
570
|
+
}
|
|
567
571
|
if (model.listingID) {
|
|
568
572
|
const listing = this.createListing(model.listingID);
|
|
569
573
|
content.push(listing);
|
|
@@ -777,6 +781,15 @@ export class Decoder {
|
|
|
777
781
|
}
|
|
778
782
|
return table;
|
|
779
783
|
}
|
|
784
|
+
createTableColGroup(model) {
|
|
785
|
+
const tableId = model.containedObjectID;
|
|
786
|
+
const tableModel = this.getModel(tableId);
|
|
787
|
+
if (tableModel) {
|
|
788
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
789
|
+
topNode: schema.nodes.table_colgroup.create(),
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
780
793
|
createTableElementFooter(model) {
|
|
781
794
|
const tableElementFooterID = model.tableElementFooterID;
|
|
782
795
|
if (!tableElementFooterID) {
|
|
@@ -91,9 +91,28 @@ const buildTableSection = (tagName, inputRows, parent) => {
|
|
|
91
91
|
}
|
|
92
92
|
return section;
|
|
93
93
|
};
|
|
94
|
+
function buildTableColGroup(cols) {
|
|
95
|
+
if (cols.length === 0) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
const colgroup = document.createElement('colgroup');
|
|
99
|
+
for (const inputCol of cols) {
|
|
100
|
+
const col = document.createElement('col');
|
|
101
|
+
for (const attribute of inputCol.attributes) {
|
|
102
|
+
col.setAttribute(attribute.name, attribute.value);
|
|
103
|
+
}
|
|
104
|
+
colgroup.appendChild(inputCol);
|
|
105
|
+
}
|
|
106
|
+
return colgroup;
|
|
107
|
+
}
|
|
94
108
|
const tableContents = (node, parent) => {
|
|
95
109
|
const input = serializer.serializeNode(node);
|
|
110
|
+
const parentInput = serializer.serializeNode(parent);
|
|
96
111
|
const output = document.createElement('table');
|
|
112
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
113
|
+
if (colgroup) {
|
|
114
|
+
output.appendChild(colgroup);
|
|
115
|
+
}
|
|
97
116
|
output.setAttribute('id', parent.attrs.id);
|
|
98
117
|
output.classList.add('MPElement');
|
|
99
118
|
if (parent.attrs.tableStyle) {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { TableNodes } from 'prosemirror-tables';
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const tableNodes: TableNodes;
|
|
18
18
|
export declare const table: {
|
|
19
19
|
attrs: {
|
|
20
20
|
id: {
|
|
@@ -39,6 +39,6 @@ export declare const table: {
|
|
|
39
39
|
toDebugString?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
40
40
|
leafText?: ((node: import("prosemirror-model").Node) => string) | undefined;
|
|
41
41
|
};
|
|
42
|
-
export declare const tableRow: import("prosemirror-model").NodeSpec;
|
|
43
42
|
export declare const tableCell: import("prosemirror-model").NodeSpec;
|
|
43
|
+
export declare const tableRow: import("prosemirror-model").NodeSpec;
|
|
44
44
|
export declare const tableHeader: import("prosemirror-model").NodeSpec;
|
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-3336-
|
|
4
|
+
"version": "2.1.1-LEAN-3336-7",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
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.18.3",
|
|
39
39
|
"prosemirror-tables": "^1.3.5",
|
|
40
40
|
"uuid": "^9.0.0",
|
|
41
41
|
"w3c-xmlserializer": "^4.0.0"
|