@manuscripts/transform 2.1.1-LEAN-3336-4 → 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.
@@ -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({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
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
  {
@@ -586,10 +582,6 @@ const nodes = [
586
582
  };
587
583
  },
588
584
  },
589
- {
590
- tag: 'colgroup',
591
- node: 'table_colgroup',
592
- },
593
585
  {
594
586
  tag: 'xref[ref-type="bibr"]',
595
587
  node: 'citation',
@@ -241,6 +241,7 @@ exports.jatsBodyTransformations = {
241
241
  fixTables(body, createElement) {
242
242
  const tables = body.querySelectorAll('table-wrap > table');
243
243
  tables.forEach((table) => {
244
+ var _a;
244
245
  const colgroup = table.querySelector('colgroup');
245
246
  const cols = table.querySelectorAll('col');
246
247
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -248,20 +249,19 @@ exports.jatsBodyTransformations = {
248
249
  for (const col of cols) {
249
250
  colgroup.appendChild(col);
250
251
  }
251
- table.insertBefore(colgroup, table.firstChild);
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);
252
261
  }
253
262
  const tbody = table.querySelector('tbody');
254
263
  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
- }
264
+ table.removeChild(tbody);
265
265
  }
266
266
  });
267
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
- return (0, transformer_1.encode)(node).values();
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
- node.attrs.celltype,
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
- node.attrs.celltype,
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
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
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);
@@ -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,9 +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
- table_cell: table_row_1.tableCell,
214
+ table_cell: table_1.tableCell,
217
215
  table_element: table_element_1.tableElement,
218
- table_row: table_row_1.tableRow,
216
+ table_row: table_1.tableRow,
219
217
  table_col: table_col_1.tableCol,
220
218
  table_colgroup: table_col_1.tableColGroup,
221
219
  text: text_1.text,
@@ -229,6 +227,6 @@ exports.schema = new prosemirror_model_1.Schema({
229
227
  contributors: contributors_1.contributors,
230
228
  supplements: supplements_1.supplements,
231
229
  supplement: supplement_1.supplement,
232
- table_header: table_row_1.tableHeader,
230
+ table_header: table_1.tableHeader,
233
231
  },
234
232
  });
@@ -15,43 +15,84 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.table = void 0;
19
- exports.table = {
20
- content: 'table_row+',
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
- };
18
+ exports.tableHeader = exports.tableRow = exports.tableCell = exports.table = exports.tableNodes = void 0;
19
+ const prosemirror_tables_1 = require("prosemirror-tables");
20
+ const table_cell_styles_1 = require("../../lib/table-cell-styles");
21
+ const tableOptions = {
22
+ tableGroup: 'block',
23
+ cellContent: 'inline*',
24
+ cellAttributes: {
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
+ }
42
90
  },
43
91
  },
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),
53
- },
54
- 0,
55
- ];
56
92
  },
57
93
  };
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: '' },
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*!
3
- * © 2019 Atypon Systems LLC
3
+ * © 2024 Atypon Systems LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -14,108 +14,3 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableHeader = 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 | table_header)*',
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: [{ tag: 'td', getAttrs: getCellAttrs }],
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 = (0, table_cell_styles_1.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
- };
121
- exports.tableHeader = Object.assign(Object.assign({}, exports.tableCell), { tableRole: 'header_cell', parseDOM: [{ tag: 'th', getAttrs: getCellAttrs }] });
@@ -557,18 +557,16 @@ class Decoder {
557
557
  },
558
558
  [json_schema_1.ObjectTypes.Table]: (data) => {
559
559
  const model = data;
560
- const comments = this.createCommentNodes(model);
561
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
562
- return this.parseContents(model.contents, undefined, this.getComments(model), {
560
+ return this.parseContents(model.contents, undefined, [], {
563
561
  topNode: schema_1.schema.nodes.table.create({
564
562
  id: model._id,
565
- comments: comments.map((c) => c.attrs.id),
566
563
  }),
567
564
  });
568
565
  },
569
566
  [json_schema_1.ObjectTypes.TableElement]: (data) => {
570
567
  const model = data;
571
568
  const table = this.createTable(model);
569
+ const tableColGroup = this.createTableColGroup(model);
572
570
  const tableElementFooter = this.createTableElementFooter(model);
573
571
  const figcaption = this.getFigcaption(model);
574
572
  const comments = this.createCommentNodes(model);
@@ -576,6 +574,9 @@ class Decoder {
576
574
  const content = tableElementFooter
577
575
  ? [table, tableElementFooter, figcaption]
578
576
  : [table, figcaption];
577
+ if (tableColGroup) {
578
+ content.unshift(tableColGroup);
579
+ }
579
580
  if (model.listingID) {
580
581
  const listing = this.createListing(model.listingID);
581
582
  content.push(listing);
@@ -789,6 +790,15 @@ class Decoder {
789
790
  }
790
791
  return table;
791
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
+ }
792
802
  createTableElementFooter(model) {
793
803
  const tableElementFooterID = model.tableElementFooterID;
794
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({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
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
  {
@@ -580,10 +576,6 @@ const nodes = [
580
576
  };
581
577
  },
582
578
  },
583
- {
584
- tag: 'colgroup',
585
- node: 'table_colgroup',
586
- },
587
579
  {
588
580
  tag: 'xref[ref-type="bibr"]',
589
581
  node: 'citation',
@@ -238,6 +238,7 @@ 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;
241
242
  const colgroup = table.querySelector('colgroup');
242
243
  const cols = table.querySelectorAll('col');
243
244
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -245,20 +246,19 @@ export const jatsBodyTransformations = {
245
246
  for (const col of cols) {
246
247
  colgroup.appendChild(col);
247
248
  }
248
- table.insertBefore(colgroup, table.firstChild);
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);
249
258
  }
250
259
  const tbody = table.querySelector('tbody');
251
260
  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
- }
261
+ table.removeChild(tbody);
262
262
  }
263
263
  });
264
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
- return encode(node).values();
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
- node.attrs.celltype,
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
- node.attrs.celltype,
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
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
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);
@@ -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 } from './nodes/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, tableHeader, 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';
@@ -13,42 +13,83 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export const table = {
17
- content: 'table_row+',
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
- };
16
+ import { tableNodes as createTableNodes, } from 'prosemirror-tables';
17
+ import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
18
+ const tableOptions = {
19
+ tableGroup: 'block',
20
+ cellContent: 'inline*',
21
+ cellAttributes: {
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
+ }
39
87
  },
40
88
  },
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),
50
- },
51
- 0,
52
- ];
53
89
  },
54
90
  };
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: '' },
@@ -1,5 +1,6 @@
1
+ "use strict";
1
2
  /*!
2
- * © 2019 Atypon Systems LLC
3
+ * © 2024 Atypon Systems LLC
3
4
  *
4
5
  * Licensed under the Apache License, Version 2.0 (the "License");
5
6
  * you may not use this file except in compliance with the License.
@@ -13,106 +14,3 @@
13
14
  * See the License for the specific language governing permissions and
14
15
  * limitations under the License.
15
16
  */
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 | table_header)*',
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: [{ tag: 'td', getAttrs: getCellAttrs }],
80
- toDOM: (node) => {
81
- const tableCellNode = node;
82
- const attrs = {};
83
- const tag = tableCellNode.attrs.celltype;
84
- if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
85
- attrs.colspan = String(tableCellNode.attrs.colspan);
86
- }
87
- if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
88
- attrs.rowspan = String(tableCellNode.attrs.rowspan);
89
- }
90
- if (tableCellNode.attrs.colwidth) {
91
- attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
92
- }
93
- if (tableCellNode.attrs.placeholder) {
94
- attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
95
- }
96
- if (!tableCellNode.textContent) {
97
- attrs.class = 'placeholder';
98
- }
99
- const styleString = serializeTableCellStyles(tableCellNode.attrs.styles);
100
- if (styleString) {
101
- attrs.style = styleString;
102
- }
103
- if (tableCellNode.attrs.valign) {
104
- attrs.valign = tableCellNode.attrs.valign;
105
- }
106
- if (tableCellNode.attrs.align) {
107
- attrs.align = tableCellNode.attrs.align;
108
- }
109
- if (tableCellNode.attrs.scope) {
110
- attrs.scope = tableCellNode.attrs.scope;
111
- }
112
- if (tableCellNode.attrs.style) {
113
- attrs.style = tableCellNode.attrs.style;
114
- }
115
- return [tag, attrs, 0];
116
- },
117
- };
118
- export const tableHeader = Object.assign(Object.assign({}, tableCell), { tableRole: 'header_cell', parseDOM: [{ tag: 'th', getAttrs: getCellAttrs }] });
@@ -548,18 +548,16 @@ export class Decoder {
548
548
  },
549
549
  [ObjectTypes.Table]: (data) => {
550
550
  const model = data;
551
- const comments = this.createCommentNodes(model);
552
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
553
- return this.parseContents(model.contents, undefined, this.getComments(model), {
551
+ return this.parseContents(model.contents, undefined, [], {
554
552
  topNode: schema.nodes.table.create({
555
553
  id: model._id,
556
- comments: comments.map((c) => c.attrs.id),
557
554
  }),
558
555
  });
559
556
  },
560
557
  [ObjectTypes.TableElement]: (data) => {
561
558
  const model = data;
562
559
  const table = this.createTable(model);
560
+ const tableColGroup = this.createTableColGroup(model);
563
561
  const tableElementFooter = this.createTableElementFooter(model);
564
562
  const figcaption = this.getFigcaption(model);
565
563
  const comments = this.createCommentNodes(model);
@@ -567,6 +565,9 @@ export class Decoder {
567
565
  const content = tableElementFooter
568
566
  ? [table, tableElementFooter, figcaption]
569
567
  : [table, figcaption];
568
+ if (tableColGroup) {
569
+ content.unshift(tableColGroup);
570
+ }
570
571
  if (model.listingID) {
571
572
  const listing = this.createListing(model.listingID);
572
573
  content.push(listing);
@@ -780,6 +781,15 @@ export class Decoder {
780
781
  }
781
782
  return table;
782
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
+ }
783
793
  createTableElementFooter(model) {
784
794
  const tableElementFooterID = model.tableElementFooterID;
785
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) {
@@ -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,14 +13,32 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ManuscriptNode, TableNodeSpec } from '../types';
17
- import { CommentNode } from './comment';
18
- export interface TableNode extends ManuscriptNode {
16
+ import { TableNodes } from 'prosemirror-tables';
17
+ export declare const tableNodes: TableNodes;
18
+ export declare const table: {
19
19
  attrs: {
20
- id: string;
21
- headerRows: number;
22
- footerRows: number;
23
- comments?: CommentNode[];
20
+ id: {
21
+ default: string;
22
+ };
24
23
  };
25
- }
26
- export declare const table: TableNodeSpec;
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: import("prosemirror-model").NodeSpec;
43
+ export declare const tableRow: import("prosemirror-model").NodeSpec;
44
+ export declare const tableHeader: import("prosemirror-model").NodeSpec;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,30 +13,3 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
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;
42
- export declare const tableHeader: TableNodeSpec;
@@ -43,6 +43,7 @@ export declare class Decoder {
43
43
  private getManuscriptID;
44
44
  private getFigcaption;
45
45
  private createTable;
46
+ private createTableColGroup;
46
47
  private createTableElementFooter;
47
48
  private createListing;
48
49
  }
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",
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",
@@ -36,6 +36,7 @@
36
36
  "mathjax-full": "^3.2.2",
37
37
  "mime": "^3.0.0",
38
38
  "prosemirror-model": "^1.18.3",
39
+ "prosemirror-tables": "^1.3.5",
39
40
  "uuid": "^9.0.0",
40
41
  "w3c-xmlserializer": "^4.0.0"
41
42
  },
@@ -64,9 +65,9 @@
64
65
  "eslint-plugin-mdx": "^2.0.5",
65
66
  "eslint-plugin-prettier": "^4.2.1",
66
67
  "eslint-plugin-promise": "^6.1.1",
67
- "eslint-plugin-simple-import-sort": "^8.0.0",
68
68
  "eslint-plugin-react": "^7.31.11",
69
69
  "eslint-plugin-react-hooks": "^4.6.0",
70
+ "eslint-plugin-simple-import-sort": "^8.0.0",
70
71
  "husky": "^8.0.2",
71
72
  "jest": "^29.3.1",
72
73
  "jest-environment-jsdom": "^29.3.1",