@manuscripts/transform 2.1.3-LEAN-3376-0 → 2.1.3-LEAN-3376-6

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.
@@ -525,23 +525,9 @@ const nodes = [
525
525
  const element = node;
526
526
  return {
527
527
  id: element.getAttribute('id'),
528
- suppressFooter: !element.querySelector('table > tfoot > tr'),
529
- suppressHeader: !element.querySelector('table > thead > tr'),
530
528
  };
531
529
  },
532
530
  },
533
- {
534
- tag: 'tbody',
535
- skip: true,
536
- },
537
- {
538
- tag: 'tfoot',
539
- skip: true,
540
- },
541
- {
542
- tag: 'thead',
543
- skip: true,
544
- },
545
531
  {
546
532
  tag: 'title',
547
533
  node: 'section_title',
@@ -568,12 +554,12 @@ const nodes = [
568
554
  },
569
555
  {
570
556
  tag: 'th',
571
- node: 'table_cell',
557
+ node: 'table_header',
572
558
  getAttrs: (node) => {
573
559
  const element = node;
574
560
  const colspan = element.getAttribute('colspan');
575
561
  const rowspan = element.getAttribute('rowspan');
576
- return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
562
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
577
563
  },
578
564
  },
579
565
  {
@@ -241,8 +241,12 @@ exports.jatsBodyTransformations = {
241
241
  }
242
242
  },
243
243
  fixTables(body, createElement) {
244
- const tables = body.querySelectorAll('table-wrap > table');
245
- tables.forEach((table) => {
244
+ const tableWraps = body.querySelectorAll('table-wrap');
245
+ tableWraps.forEach((tableWrap) => {
246
+ const table = tableWrap.querySelector('table');
247
+ if (!table) {
248
+ return;
249
+ }
246
250
  const colgroup = table.querySelector('colgroup');
247
251
  const cols = table.querySelectorAll('col');
248
252
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -250,20 +254,7 @@ exports.jatsBodyTransformations = {
250
254
  for (const col of cols) {
251
255
  colgroup.appendChild(col);
252
256
  }
253
- table.insertBefore(colgroup, table.firstChild);
254
- }
255
- const tbody = table.querySelector('tbody');
256
- if (tbody) {
257
- const headerRow = table.querySelector('thead > tr');
258
- if (!headerRow) {
259
- const tr = createElement('tr');
260
- tbody.insertBefore(tr, tbody.firstElementChild);
261
- }
262
- const footerRow = table.querySelector('tfoot > tr');
263
- if (!footerRow) {
264
- const tr = createElement('tr');
265
- tbody.appendChild(tr);
266
- }
257
+ tableWrap.insertBefore(colgroup, table.nextSibling);
267
258
  }
268
259
  });
269
260
  },
@@ -201,6 +201,7 @@ exports.jatsFrontParser = {
201
201
  ]);
202
202
  const authorNotes = [
203
203
  (0, transformer_1.buildAuthorNotes)([
204
+ ...correspondingIDs.values(),
204
205
  ...footnoteIDs.values(),
205
206
  ...authorNotesParagraphs.map((p) => p._id),
206
207
  ]),
@@ -874,9 +874,13 @@ class JATSExporter {
874
874
  element.setAttribute('position', 'anchor');
875
875
  return element;
876
876
  },
877
- table_body: () => ['tbody', 0],
878
877
  table_cell: (node) => [
879
- node.attrs.celltype,
878
+ 'td',
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 })),
880
+ 0,
881
+ ],
882
+ table_header: (node) => [
883
+ 'th',
880
884
  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 })),
881
885
  0,
882
886
  ],
@@ -957,6 +961,26 @@ class JATSExporter {
957
961
  element.appendChild(this.serializeNode(childNode));
958
962
  }
959
963
  };
964
+ const appendTable = (element, node) => {
965
+ const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
966
+ const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
967
+ if (!tableNode) {
968
+ return;
969
+ }
970
+ const table = this.serializeNode(tableNode);
971
+ const tbodyElement = this.document.createElement('tbody');
972
+ while (table.firstChild) {
973
+ const child = table.firstChild;
974
+ table.removeChild(child);
975
+ tbodyElement.appendChild(child);
976
+ }
977
+ table.appendChild(tbodyElement);
978
+ if (colGroupNode) {
979
+ const colGroup = this.serializeNode(colGroupNode);
980
+ table.insertBefore(colGroup, table.firstChild);
981
+ }
982
+ element.appendChild(table);
983
+ };
960
984
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
961
985
  const element = createElement(node, nodeName);
962
986
  if (figType) {
@@ -977,7 +1001,7 @@ class JATSExporter {
977
1001
  const element = createElement(node, nodeName);
978
1002
  appendLabels(element, node);
979
1003
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
980
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
1004
+ appendTable(element, node);
981
1005
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
982
1006
  if ((0, node_types_1.isExecutableNodeType)(node.type)) {
983
1007
  processExecutableNode(node, element);
@@ -1268,6 +1292,9 @@ class JATSExporter {
1268
1292
  else if (id.startsWith('MPFootnote')) {
1269
1293
  this.appendFootnoteToElement(model, authorNotesEl);
1270
1294
  }
1295
+ else if (id.startsWith('MPCorresponding')) {
1296
+ this.appendCorrespondingToElement(model, authorNotesEl);
1297
+ }
1271
1298
  });
1272
1299
  if (authorNotesEl.childNodes.length > 0) {
1273
1300
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
@@ -1275,6 +1302,17 @@ class JATSExporter {
1275
1302
  }
1276
1303
  }
1277
1304
  };
1305
+ this.appendCorrespondingToElement = (corresponding, element) => {
1306
+ const correspondingEl = this.document.createElement('corresp');
1307
+ correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1308
+ if (corresponding.label) {
1309
+ const labelEl = this.document.createElement('label');
1310
+ labelEl.textContent = corresponding.label;
1311
+ correspondingEl.appendChild(labelEl);
1312
+ }
1313
+ correspondingEl.append(corresponding.contents);
1314
+ element.appendChild(correspondingEl);
1315
+ };
1278
1316
  this.appendParagraphToElement = (paragraph, element) => {
1279
1317
  const paragraphEl = this.document.createElement('p');
1280
1318
  paragraphEl.setAttribute('id', normalizeID(paragraph._id));
@@ -88,7 +88,6 @@ const table_1 = require("./nodes/table");
88
88
  const table_col_1 = require("./nodes/table_col");
89
89
  const table_element_1 = require("./nodes/table_element");
90
90
  const table_element_footer_1 = require("./nodes/table_element_footer");
91
- const table_row_1 = require("./nodes/table_row");
92
91
  const text_1 = require("./nodes/text");
93
92
  const title_1 = require("./nodes/title");
94
93
  const toc_element_1 = require("./nodes/toc_element");
@@ -138,7 +137,6 @@ __exportStar(require("./nodes/section_title"), exports);
138
137
  __exportStar(require("./nodes/table"), exports);
139
138
  __exportStar(require("./nodes/table_col"), exports);
140
139
  __exportStar(require("./nodes/table_element"), exports);
141
- __exportStar(require("./nodes/table_row"), exports);
142
140
  __exportStar(require("./nodes/text"), exports);
143
141
  __exportStar(require("./nodes/toc_element"), exports);
144
142
  __exportStar(require("./nodes/toc_section"), exports);
@@ -214,12 +212,12 @@ exports.schema = new prosemirror_model_1.Schema({
214
212
  section_title: section_title_1.sectionTitle,
215
213
  section_title_plain: section_title_1.sectionTitle,
216
214
  table: table_1.table,
217
- table_body: table_1.tableBody,
218
- table_cell: table_row_1.tableCell,
215
+ table_cell: table_1.tableCell,
219
216
  table_element: table_element_1.tableElement,
220
- table_row: table_row_1.tableRow,
217
+ table_row: table_1.tableRow,
221
218
  table_col: table_col_1.tableCol,
222
219
  table_colgroup: table_col_1.tableColGroup,
220
+ table_header: table_1.tableHeader,
223
221
  text: text_1.text,
224
222
  toc_element: toc_element_1.tocElement,
225
223
  toc_section: toc_section_1.tocSection,
@@ -15,20 +15,57 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableBody = exports.table = void 0;
18
+ exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = void 0;
19
+ const prosemirror_tables_1 = require("prosemirror-tables");
20
+ function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
21
+ return {
22
+ default: defaultValue,
23
+ getFromDOM(dom) {
24
+ if (customGetFromDOM) {
25
+ return customGetFromDOM(dom);
26
+ }
27
+ return dom.getAttribute(attributeName);
28
+ },
29
+ setDOMAttr(value, attrs) {
30
+ if (customSetDOMAttr) {
31
+ customSetDOMAttr(value, attrs);
32
+ }
33
+ else if (value) {
34
+ attrs[attributeName] = value;
35
+ }
36
+ },
37
+ };
38
+ }
39
+ const tableOptions = {
40
+ cellContent: 'inline*',
41
+ cellAttributes: {
42
+ placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
43
+ valign: createCellAttribute('valign'),
44
+ align: createCellAttribute('align'),
45
+ scope: createCellAttribute('scope'),
46
+ style: createCellAttribute('style'),
47
+ colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
48
+ if (value && value !== 1) {
49
+ attrs['colspan'] = String(value);
50
+ }
51
+ }),
52
+ rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
53
+ if (value && value !== 1) {
54
+ attrs['rowspan'] = String(value);
55
+ }
56
+ }),
57
+ },
58
+ };
59
+ const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
19
60
  exports.table = {
20
- content: 'table_colgroup? table_body',
21
- tableRole: 'table',
22
- isolating: true,
23
- group: 'block',
24
- selectable: false,
25
61
  attrs: {
26
62
  id: { default: '' },
27
- headerRows: { default: 1 },
28
- footerRows: { default: 1 },
29
63
  dataTracked: { default: null },
30
- comments: { default: null },
31
64
  },
65
+ content: 'table_row+',
66
+ tableRole: 'table',
67
+ isolating: true,
68
+ group: 'block',
32
69
  parseDOM: [
33
70
  {
34
71
  tag: 'table',
@@ -36,35 +73,20 @@ exports.table = {
36
73
  const dom = p;
37
74
  return {
38
75
  id: dom.getAttribute('id'),
39
- headerRows: dom.dataset && dom.dataset['header-rows'],
40
- footerRows: dom.dataset && dom.dataset['footer-rows'],
41
76
  };
42
77
  },
43
78
  },
44
79
  ],
45
- toDOM: (node) => {
46
- const tableNode = node;
80
+ toDOM(node) {
47
81
  return [
48
82
  'table',
49
83
  {
50
- id: tableNode.attrs.id,
51
- 'data-header-rows': String(node.attrs.headerRows),
52
- 'data-footer-rows': String(node.attrs.footerRows),
84
+ id: node.attrs.id,
53
85
  },
54
- 0,
86
+ ['tbody', 0],
55
87
  ];
56
88
  },
57
89
  };
58
- exports.tableBody = {
59
- content: 'table_row+',
60
- group: 'block',
61
- tableRole: 'table',
62
- parseDOM: [
63
- {
64
- tag: 'tbody',
65
- },
66
- ],
67
- toDOM() {
68
- return ['tbody', 0];
69
- },
70
- };
90
+ exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
91
+ exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
92
+ exports.tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
@@ -17,7 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.tableElement = void 0;
19
19
  exports.tableElement = {
20
- content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
20
+ content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  paragraphStyle: { default: '' },
@@ -499,7 +499,9 @@ class Decoder {
499
499
  },
500
500
  [json_schema_1.ObjectTypes.AuthorNotes]: (data) => {
501
501
  const model = data;
502
- const content = model.containedObjectIDs.map((id) => this.decode(this.modelMap.get(id)));
502
+ const content = model.containedObjectIDs
503
+ .filter((id) => !id.startsWith('MPCorresponding'))
504
+ .map((id) => this.decode(this.modelMap.get(id)));
503
505
  return schema_1.schema.nodes.author_notes.create({
504
506
  id: model._id,
505
507
  }, content);
@@ -570,33 +572,32 @@ class Decoder {
570
572
  },
571
573
  [json_schema_1.ObjectTypes.Table]: (data) => {
572
574
  const model = data;
573
- const comments = this.createCommentNodes(model);
574
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
575
- return this.parseContents(model.contents, undefined, this.getComments(model), {
575
+ return this.parseContents(model.contents, undefined, [], {
576
576
  topNode: schema_1.schema.nodes.table.create({
577
577
  id: model._id,
578
- comments: comments.map((c) => c.attrs.id),
579
578
  }),
580
579
  });
581
580
  },
582
581
  [json_schema_1.ObjectTypes.TableElement]: (data) => {
583
582
  const model = data;
584
583
  const table = this.createTable(model);
584
+ const tableColGroup = this.createTableColGroup(model);
585
585
  const tableElementFooter = this.createTableElementFooter(model);
586
586
  const figcaption = this.getFigcaption(model);
587
587
  const comments = this.createCommentNodes(model);
588
588
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
589
- const content = tableElementFooter
590
- ? [table, tableElementFooter, figcaption]
591
- : [table, figcaption];
592
- if (model.listingID) {
593
- const listing = this.createListing(model.listingID);
594
- content.push(listing);
589
+ const content = [table];
590
+ if (tableColGroup) {
591
+ content.push(tableColGroup);
595
592
  }
596
- else {
597
- const listing = schema_1.schema.nodes.listing.create();
598
- content.push(listing);
593
+ if (tableElementFooter) {
594
+ content.push(tableElementFooter);
599
595
  }
596
+ content.push(figcaption);
597
+ const listing = model.listingID
598
+ ? this.createListing(model.listingID)
599
+ : schema_1.schema.nodes.listing.create();
600
+ content.push(listing);
600
601
  return schema_1.schema.nodes.table_element.createChecked({
601
602
  id: model._id,
602
603
  table: model.containedObjectID,
@@ -785,23 +786,33 @@ class Decoder {
785
786
  this.allowMissingElements = allowMissingElements;
786
787
  }
787
788
  createTable(model) {
788
- const tableId = model.containedObjectID;
789
- const tableModel = this.getModel(tableId);
789
+ const tableID = model.containedObjectID;
790
+ const tableModel = this.getModel(tableID);
790
791
  let table;
791
792
  if (tableModel) {
792
793
  table = this.decode(tableModel);
793
794
  }
794
795
  else if (this.allowMissingElements) {
795
796
  table = schema_1.schema.nodes.placeholder.create({
796
- id: tableId,
797
+ id: tableID,
797
798
  label: 'A table',
798
799
  });
799
800
  }
800
801
  else {
801
- throw new errors_1.MissingElement(tableId);
802
+ throw new errors_1.MissingElement(tableID);
802
803
  }
803
804
  return table;
804
805
  }
806
+ createTableColGroup(model) {
807
+ const tableID = model.containedObjectID;
808
+ const tableModel = this.getModel(tableID);
809
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
810
+ return undefined;
811
+ }
812
+ return this.parseContents(tableModel.contents, undefined, [], {
813
+ topNode: schema_1.schema.nodes.table_colgroup.create(),
814
+ });
815
+ }
805
816
  createTableElementFooter(model) {
806
817
  const tableElementFooterID = model.tableElementFooterID;
807
818
  if (!tableElementFooterID) {
@@ -115,8 +115,9 @@ function buildTableColGroup(cols) {
115
115
  }
116
116
  const tableContents = (node, parent) => {
117
117
  const input = serializer.serializeNode(node);
118
+ const parentInput = serializer.serializeNode(parent);
118
119
  const output = document.createElement('table');
119
- const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
120
+ const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
120
121
  if (colgroup) {
121
122
  output.appendChild(colgroup);
122
123
  }
@@ -519,23 +519,9 @@ const nodes = [
519
519
  const element = node;
520
520
  return {
521
521
  id: element.getAttribute('id'),
522
- suppressFooter: !element.querySelector('table > tfoot > tr'),
523
- suppressHeader: !element.querySelector('table > thead > tr'),
524
522
  };
525
523
  },
526
524
  },
527
- {
528
- tag: 'tbody',
529
- skip: true,
530
- },
531
- {
532
- tag: 'tfoot',
533
- skip: true,
534
- },
535
- {
536
- tag: 'thead',
537
- skip: true,
538
- },
539
525
  {
540
526
  tag: 'title',
541
527
  node: 'section_title',
@@ -562,12 +548,12 @@ const nodes = [
562
548
  },
563
549
  {
564
550
  tag: 'th',
565
- node: 'table_cell',
551
+ node: 'table_header',
566
552
  getAttrs: (node) => {
567
553
  const element = node;
568
554
  const colspan = element.getAttribute('colspan');
569
555
  const rowspan = element.getAttribute('rowspan');
570
- return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
556
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
571
557
  },
572
558
  },
573
559
  {
@@ -238,8 +238,12 @@ export const jatsBodyTransformations = {
238
238
  }
239
239
  },
240
240
  fixTables(body, createElement) {
241
- const tables = body.querySelectorAll('table-wrap > table');
242
- tables.forEach((table) => {
241
+ const tableWraps = body.querySelectorAll('table-wrap');
242
+ tableWraps.forEach((tableWrap) => {
243
+ const table = tableWrap.querySelector('table');
244
+ if (!table) {
245
+ return;
246
+ }
243
247
  const colgroup = table.querySelector('colgroup');
244
248
  const cols = table.querySelectorAll('col');
245
249
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -247,20 +251,7 @@ export const jatsBodyTransformations = {
247
251
  for (const col of cols) {
248
252
  colgroup.appendChild(col);
249
253
  }
250
- table.insertBefore(colgroup, table.firstChild);
251
- }
252
- const tbody = table.querySelector('tbody');
253
- if (tbody) {
254
- const headerRow = table.querySelector('thead > tr');
255
- if (!headerRow) {
256
- const tr = createElement('tr');
257
- tbody.insertBefore(tr, tbody.firstElementChild);
258
- }
259
- const footerRow = table.querySelector('tfoot > tr');
260
- if (!footerRow) {
261
- const tr = createElement('tr');
262
- tbody.appendChild(tr);
263
- }
254
+ tableWrap.insertBefore(colgroup, table.nextSibling);
264
255
  }
265
256
  });
266
257
  },
@@ -195,6 +195,7 @@ export const jatsFrontParser = {
195
195
  ]);
196
196
  const authorNotes = [
197
197
  buildAuthorNotes([
198
+ ...correspondingIDs.values(),
198
199
  ...footnoteIDs.values(),
199
200
  ...authorNotesParagraphs.map((p) => p._id),
200
201
  ]),
@@ -866,9 +866,13 @@ export class JATSExporter {
866
866
  element.setAttribute('position', 'anchor');
867
867
  return element;
868
868
  },
869
- table_body: () => ['tbody', 0],
870
869
  table_cell: (node) => [
871
- node.attrs.celltype,
870
+ 'td',
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 })),
872
+ 0,
873
+ ],
874
+ table_header: (node) => [
875
+ 'th',
872
876
  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 })),
873
877
  0,
874
878
  ],
@@ -949,6 +953,26 @@ export class JATSExporter {
949
953
  element.appendChild(this.serializeNode(childNode));
950
954
  }
951
955
  };
956
+ const appendTable = (element, node) => {
957
+ const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
958
+ const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
959
+ if (!tableNode) {
960
+ return;
961
+ }
962
+ const table = this.serializeNode(tableNode);
963
+ const tbodyElement = this.document.createElement('tbody');
964
+ while (table.firstChild) {
965
+ const child = table.firstChild;
966
+ table.removeChild(child);
967
+ tbodyElement.appendChild(child);
968
+ }
969
+ table.appendChild(tbodyElement);
970
+ if (colGroupNode) {
971
+ const colGroup = this.serializeNode(colGroupNode);
972
+ table.insertBefore(colGroup, table.firstChild);
973
+ }
974
+ element.appendChild(table);
975
+ };
952
976
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
953
977
  const element = createElement(node, nodeName);
954
978
  if (figType) {
@@ -969,7 +993,7 @@ export class JATSExporter {
969
993
  const element = createElement(node, nodeName);
970
994
  appendLabels(element, node);
971
995
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
972
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
996
+ appendTable(element, node);
973
997
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
974
998
  if (isExecutableNodeType(node.type)) {
975
999
  processExecutableNode(node, element);
@@ -1260,6 +1284,9 @@ export class JATSExporter {
1260
1284
  else if (id.startsWith('MPFootnote')) {
1261
1285
  this.appendFootnoteToElement(model, authorNotesEl);
1262
1286
  }
1287
+ else if (id.startsWith('MPCorresponding')) {
1288
+ this.appendCorrespondingToElement(model, authorNotesEl);
1289
+ }
1263
1290
  });
1264
1291
  if (authorNotesEl.childNodes.length > 0) {
1265
1292
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
@@ -1267,6 +1294,17 @@ export class JATSExporter {
1267
1294
  }
1268
1295
  }
1269
1296
  };
1297
+ this.appendCorrespondingToElement = (corresponding, element) => {
1298
+ const correspondingEl = this.document.createElement('corresp');
1299
+ correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1300
+ if (corresponding.label) {
1301
+ const labelEl = this.document.createElement('label');
1302
+ labelEl.textContent = corresponding.label;
1303
+ correspondingEl.appendChild(labelEl);
1304
+ }
1305
+ correspondingEl.append(corresponding.contents);
1306
+ element.appendChild(correspondingEl);
1307
+ };
1270
1308
  this.appendParagraphToElement = (paragraph, element) => {
1271
1309
  const paragraphEl = this.document.createElement('p');
1272
1310
  paragraphEl.setAttribute('id', normalizeID(paragraph._id));
@@ -67,11 +67,10 @@ import { sectionLabel } from './nodes/section_label';
67
67
  import { sectionTitle } from './nodes/section_title';
68
68
  import { supplement } from './nodes/supplement';
69
69
  import { supplements } from './nodes/supplements';
70
- import { table, tableBody } from './nodes/table';
70
+ import { table, tableCell, tableHeader, tableRow } from './nodes/table';
71
71
  import { tableCol, tableColGroup } from './nodes/table_col';
72
72
  import { tableElement } from './nodes/table_element';
73
73
  import { tableElementFooter } from './nodes/table_element_footer';
74
- import { tableCell, tableRow } from './nodes/table_row';
75
74
  import { text } from './nodes/text';
76
75
  import { title } from './nodes/title';
77
76
  import { tocElement } from './nodes/toc_element';
@@ -121,7 +120,6 @@ export * from './nodes/section_title';
121
120
  export * from './nodes/table';
122
121
  export * from './nodes/table_col';
123
122
  export * from './nodes/table_element';
124
- export * from './nodes/table_row';
125
123
  export * from './nodes/text';
126
124
  export * from './nodes/toc_element';
127
125
  export * from './nodes/toc_section';
@@ -197,12 +195,12 @@ export const schema = new Schema({
197
195
  section_title: sectionTitle,
198
196
  section_title_plain: sectionTitle,
199
197
  table,
200
- table_body: tableBody,
201
198
  table_cell: tableCell,
202
199
  table_element: tableElement,
203
200
  table_row: tableRow,
204
201
  table_col: tableCol,
205
202
  table_colgroup: tableColGroup,
203
+ table_header: tableHeader,
206
204
  text,
207
205
  toc_element: tocElement,
208
206
  toc_section: tocSection,
@@ -13,19 +13,56 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { tableNodes as createTableNodes, } from 'prosemirror-tables';
17
+ function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
18
+ return {
19
+ default: defaultValue,
20
+ getFromDOM(dom) {
21
+ if (customGetFromDOM) {
22
+ return customGetFromDOM(dom);
23
+ }
24
+ return dom.getAttribute(attributeName);
25
+ },
26
+ setDOMAttr(value, attrs) {
27
+ if (customSetDOMAttr) {
28
+ customSetDOMAttr(value, attrs);
29
+ }
30
+ else if (value) {
31
+ attrs[attributeName] = value;
32
+ }
33
+ },
34
+ };
35
+ }
36
+ const tableOptions = {
37
+ cellContent: 'inline*',
38
+ cellAttributes: {
39
+ placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
40
+ valign: createCellAttribute('valign'),
41
+ align: createCellAttribute('align'),
42
+ scope: createCellAttribute('scope'),
43
+ style: createCellAttribute('style'),
44
+ colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
45
+ if (value && value !== 1) {
46
+ attrs['colspan'] = String(value);
47
+ }
48
+ }),
49
+ rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
50
+ if (value && value !== 1) {
51
+ attrs['rowspan'] = String(value);
52
+ }
53
+ }),
54
+ },
55
+ };
56
+ const tableNodes = createTableNodes(tableOptions);
16
57
  export const table = {
17
- content: 'table_colgroup? table_body',
18
- tableRole: 'table',
19
- isolating: true,
20
- group: 'block',
21
- selectable: false,
22
58
  attrs: {
23
59
  id: { default: '' },
24
- headerRows: { default: 1 },
25
- footerRows: { default: 1 },
26
60
  dataTracked: { default: null },
27
- comments: { default: null },
28
61
  },
62
+ content: 'table_row+',
63
+ tableRole: 'table',
64
+ isolating: true,
65
+ group: 'block',
29
66
  parseDOM: [
30
67
  {
31
68
  tag: 'table',
@@ -33,35 +70,20 @@ export const table = {
33
70
  const dom = p;
34
71
  return {
35
72
  id: dom.getAttribute('id'),
36
- headerRows: dom.dataset && dom.dataset['header-rows'],
37
- footerRows: dom.dataset && dom.dataset['footer-rows'],
38
73
  };
39
74
  },
40
75
  },
41
76
  ],
42
- toDOM: (node) => {
43
- const tableNode = node;
77
+ toDOM(node) {
44
78
  return [
45
79
  'table',
46
80
  {
47
- id: tableNode.attrs.id,
48
- 'data-header-rows': String(node.attrs.headerRows),
49
- 'data-footer-rows': String(node.attrs.footerRows),
81
+ id: node.attrs.id,
50
82
  },
51
- 0,
83
+ ['tbody', 0],
52
84
  ];
53
85
  },
54
86
  };
55
- export const tableBody = {
56
- content: 'table_row+',
57
- group: 'block',
58
- tableRole: 'table',
59
- parseDOM: [
60
- {
61
- tag: 'tbody',
62
- },
63
- ],
64
- toDOM() {
65
- return ['tbody', 0];
66
- },
67
- };
87
+ export const tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
88
+ export const tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
89
+ export const tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const tableElement = {
17
- content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
17
+ content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  paragraphStyle: { default: '' },
@@ -490,7 +490,9 @@ export class Decoder {
490
490
  },
491
491
  [ObjectTypes.AuthorNotes]: (data) => {
492
492
  const model = data;
493
- const content = model.containedObjectIDs.map((id) => this.decode(this.modelMap.get(id)));
493
+ const content = model.containedObjectIDs
494
+ .filter((id) => !id.startsWith('MPCorresponding'))
495
+ .map((id) => this.decode(this.modelMap.get(id)));
494
496
  return schema.nodes.author_notes.create({
495
497
  id: model._id,
496
498
  }, content);
@@ -561,33 +563,32 @@ export class Decoder {
561
563
  },
562
564
  [ObjectTypes.Table]: (data) => {
563
565
  const model = data;
564
- const comments = this.createCommentNodes(model);
565
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
566
- return this.parseContents(model.contents, undefined, this.getComments(model), {
566
+ return this.parseContents(model.contents, undefined, [], {
567
567
  topNode: schema.nodes.table.create({
568
568
  id: model._id,
569
- comments: comments.map((c) => c.attrs.id),
570
569
  }),
571
570
  });
572
571
  },
573
572
  [ObjectTypes.TableElement]: (data) => {
574
573
  const model = data;
575
574
  const table = this.createTable(model);
575
+ const tableColGroup = this.createTableColGroup(model);
576
576
  const tableElementFooter = this.createTableElementFooter(model);
577
577
  const figcaption = this.getFigcaption(model);
578
578
  const comments = this.createCommentNodes(model);
579
579
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
580
- const content = tableElementFooter
581
- ? [table, tableElementFooter, figcaption]
582
- : [table, figcaption];
583
- if (model.listingID) {
584
- const listing = this.createListing(model.listingID);
585
- content.push(listing);
580
+ const content = [table];
581
+ if (tableColGroup) {
582
+ content.push(tableColGroup);
586
583
  }
587
- else {
588
- const listing = schema.nodes.listing.create();
589
- content.push(listing);
584
+ if (tableElementFooter) {
585
+ content.push(tableElementFooter);
590
586
  }
587
+ content.push(figcaption);
588
+ const listing = model.listingID
589
+ ? this.createListing(model.listingID)
590
+ : schema.nodes.listing.create();
591
+ content.push(listing);
591
592
  return schema.nodes.table_element.createChecked({
592
593
  id: model._id,
593
594
  table: model.containedObjectID,
@@ -776,23 +777,33 @@ export class Decoder {
776
777
  this.allowMissingElements = allowMissingElements;
777
778
  }
778
779
  createTable(model) {
779
- const tableId = model.containedObjectID;
780
- const tableModel = this.getModel(tableId);
780
+ const tableID = model.containedObjectID;
781
+ const tableModel = this.getModel(tableID);
781
782
  let table;
782
783
  if (tableModel) {
783
784
  table = this.decode(tableModel);
784
785
  }
785
786
  else if (this.allowMissingElements) {
786
787
  table = schema.nodes.placeholder.create({
787
- id: tableId,
788
+ id: tableID,
788
789
  label: 'A table',
789
790
  });
790
791
  }
791
792
  else {
792
- throw new MissingElement(tableId);
793
+ throw new MissingElement(tableID);
793
794
  }
794
795
  return table;
795
796
  }
797
+ createTableColGroup(model) {
798
+ const tableID = model.containedObjectID;
799
+ const tableModel = this.getModel(tableID);
800
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
801
+ return undefined;
802
+ }
803
+ return this.parseContents(tableModel.contents, undefined, [], {
804
+ topNode: schema.nodes.table_colgroup.create(),
805
+ });
806
+ }
796
807
  createTableElementFooter(model) {
797
808
  const tableElementFooterID = model.tableElementFooterID;
798
809
  if (!tableElementFooterID) {
@@ -107,8 +107,9 @@ function buildTableColGroup(cols) {
107
107
  }
108
108
  const tableContents = (node, parent) => {
109
109
  const input = serializer.serializeNode(node);
110
+ const parentInput = serializer.serializeNode(parent);
110
111
  const output = document.createElement('table');
111
- const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
112
+ const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
112
113
  if (colgroup) {
113
114
  output.appendChild(colgroup);
114
115
  }
@@ -86,6 +86,7 @@ export declare class JATSExporter {
86
86
  protected serializeNode: (node: ManuscriptNode) => Node;
87
87
  private validateContributor;
88
88
  private buildContributors;
89
+ private appendCorrespondingToElement;
89
90
  private appendParagraphToElement;
90
91
  private appendFootnoteToElement;
91
92
  private buildKeywords;
@@ -60,7 +60,6 @@ export * from './nodes/section_title';
60
60
  export * from './nodes/table';
61
61
  export * from './nodes/table_col';
62
62
  export * from './nodes/table_element';
63
- export * from './nodes/table_row';
64
63
  export * from './nodes/text';
65
64
  export * from './nodes/toc_element';
66
65
  export * from './nodes/toc_section';
@@ -13,15 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { 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;
16
+ import { NodeSpec } from 'prosemirror-model';
17
+ export declare const table: NodeSpec;
18
+ export declare const tableRow: NodeSpec;
19
+ export declare const tableCell: NodeSpec;
20
+ export declare const tableHeader: NodeSpec;
@@ -17,7 +17,7 @@ import { Fragment, Mark as ProsemirrorMark, MarkType, Node as ProsemirrorNode, N
17
17
  import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from 'prosemirror-state';
18
18
  import { EditorView, NodeView } from 'prosemirror-view';
19
19
  export type Marks = 'bold' | 'code' | 'italic' | 'smallcaps' | 'strikethrough' | 'styled' | 'subscript' | 'superscript' | 'underline' | 'tracked_insert' | 'tracked_delete';
20
- export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comments' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keyword_group' | 'keywords' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'abstracts' | 'body' | 'backmatter' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | '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' | 'author_notes';
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' | 'table_header' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'contributor' | 'table_element_footer' | 'title' | 'affiliations' | 'contributors' | 'supplements' | 'supplement' | 'author_notes';
21
21
  export type ManuscriptSchema = Schema<Nodes, Marks>;
22
22
  export type ManuscriptEditorState = EditorState;
23
23
  export type ManuscriptEditorView = EditorView;
@@ -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.3-LEAN-3376-0",
4
+ "version": "2.1.3-LEAN-3376-6",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",
@@ -29,13 +29,14 @@
29
29
  "version": "yarn build"
30
30
  },
31
31
  "dependencies": {
32
- "@manuscripts/json-schema": "^2.2.4-LEAN-3376-0",
33
- "@manuscripts/library": "^1.3.3-LEAN-3376-0",
32
+ "@manuscripts/json-schema": "2.2.4-LEAN-3376-1",
33
+ "@manuscripts/library": "1.3.3-LEAN-3376-1",
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
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",
@@ -1,123 +0,0 @@
1
- "use strict";
2
- /*!
3
- * © 2019 Atypon Systems LLC
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableCell = exports.tableRow = void 0;
19
- const table_cell_styles_1 = require("../../lib/table-cell-styles");
20
- const getCellAttrs = (p) => {
21
- const dom = p;
22
- const celltype = dom.tagName.toLowerCase();
23
- const widthAttr = dom.getAttribute('data-colwidth');
24
- const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
25
- ? widthAttr.split(',').map((s) => Number(s))
26
- : null;
27
- const colspan = Number(dom.getAttribute('colspan') || 1);
28
- const valign = dom.getAttribute('valign');
29
- const align = dom.getAttribute('align');
30
- const scope = dom.getAttribute('scope');
31
- const style = dom.getAttribute('style');
32
- return {
33
- celltype,
34
- colspan,
35
- rowspan: Number(dom.getAttribute('rowspan') || 1),
36
- colwidth: widths && widths.length === colspan ? widths : null,
37
- placeholder: dom.getAttribute('data-placeholder-text') || '',
38
- styles: (0, table_cell_styles_1.getTableCellStyles)(dom.style),
39
- valign,
40
- align,
41
- scope,
42
- style,
43
- };
44
- };
45
- exports.tableRow = {
46
- content: 'table_cell+',
47
- tableRole: 'row',
48
- attrs: {
49
- placeholder: { default: '' },
50
- },
51
- parseDOM: [
52
- {
53
- tag: 'tr',
54
- priority: 80,
55
- },
56
- ],
57
- toDOM: (node) => {
58
- const tableRowNode = node;
59
- const attrs = {};
60
- if (tableRowNode.attrs.placeholder) {
61
- attrs['data-placeholder-text'] = tableRowNode.attrs.placeholder;
62
- }
63
- return ['tr', attrs, 0];
64
- },
65
- };
66
- exports.tableCell = {
67
- content: 'inline*',
68
- attrs: {
69
- celltype: { default: 'td' },
70
- colspan: { default: 1 },
71
- rowspan: { default: 1 },
72
- colwidth: { default: null },
73
- placeholder: { default: 'Data' },
74
- styles: { default: {} },
75
- valign: { default: null },
76
- align: { default: null },
77
- scope: { default: null },
78
- style: { default: null },
79
- },
80
- tableRole: 'cell',
81
- isolating: true,
82
- parseDOM: [
83
- { tag: 'td', getAttrs: getCellAttrs },
84
- { tag: 'th', getAttrs: getCellAttrs },
85
- ],
86
- toDOM: (node) => {
87
- const tableCellNode = node;
88
- const attrs = {};
89
- const tag = tableCellNode.attrs.celltype;
90
- if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
91
- attrs.colspan = String(tableCellNode.attrs.colspan);
92
- }
93
- if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
94
- attrs.rowspan = String(tableCellNode.attrs.rowspan);
95
- }
96
- if (tableCellNode.attrs.colwidth) {
97
- attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
98
- }
99
- if (tableCellNode.attrs.placeholder) {
100
- attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
101
- }
102
- if (!tableCellNode.textContent) {
103
- attrs.class = 'placeholder';
104
- }
105
- const styleString = (0, table_cell_styles_1.serializeTableCellStyles)(tableCellNode.attrs.styles);
106
- if (styleString) {
107
- attrs.style = styleString;
108
- }
109
- if (tableCellNode.attrs.valign) {
110
- attrs.valign = tableCellNode.attrs.valign;
111
- }
112
- if (tableCellNode.attrs.align) {
113
- attrs.align = tableCellNode.attrs.align;
114
- }
115
- if (tableCellNode.attrs.scope) {
116
- attrs.scope = tableCellNode.attrs.scope;
117
- }
118
- if (tableCellNode.attrs.style) {
119
- attrs.style = tableCellNode.attrs.style;
120
- }
121
- return [tag, attrs, 0];
122
- },
123
- };
@@ -1,120 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
17
- const getCellAttrs = (p) => {
18
- const dom = p;
19
- const celltype = dom.tagName.toLowerCase();
20
- const widthAttr = dom.getAttribute('data-colwidth');
21
- const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
22
- ? widthAttr.split(',').map((s) => Number(s))
23
- : null;
24
- const colspan = Number(dom.getAttribute('colspan') || 1);
25
- const valign = dom.getAttribute('valign');
26
- const align = dom.getAttribute('align');
27
- const scope = dom.getAttribute('scope');
28
- const style = dom.getAttribute('style');
29
- return {
30
- celltype,
31
- colspan,
32
- rowspan: Number(dom.getAttribute('rowspan') || 1),
33
- colwidth: widths && widths.length === colspan ? widths : null,
34
- placeholder: dom.getAttribute('data-placeholder-text') || '',
35
- styles: getTableCellStyles(dom.style),
36
- valign,
37
- align,
38
- scope,
39
- style,
40
- };
41
- };
42
- export const tableRow = {
43
- content: 'table_cell+',
44
- tableRole: 'row',
45
- attrs: {
46
- placeholder: { default: '' },
47
- },
48
- parseDOM: [
49
- {
50
- tag: 'tr',
51
- priority: 80,
52
- },
53
- ],
54
- toDOM: (node) => {
55
- const tableRowNode = node;
56
- const attrs = {};
57
- if (tableRowNode.attrs.placeholder) {
58
- attrs['data-placeholder-text'] = tableRowNode.attrs.placeholder;
59
- }
60
- return ['tr', attrs, 0];
61
- },
62
- };
63
- export const tableCell = {
64
- content: 'inline*',
65
- attrs: {
66
- celltype: { default: 'td' },
67
- colspan: { default: 1 },
68
- rowspan: { default: 1 },
69
- colwidth: { default: null },
70
- placeholder: { default: 'Data' },
71
- styles: { default: {} },
72
- valign: { default: null },
73
- align: { default: null },
74
- scope: { default: null },
75
- style: { default: null },
76
- },
77
- tableRole: 'cell',
78
- isolating: true,
79
- parseDOM: [
80
- { tag: 'td', getAttrs: getCellAttrs },
81
- { tag: 'th', getAttrs: getCellAttrs },
82
- ],
83
- toDOM: (node) => {
84
- const tableCellNode = node;
85
- const attrs = {};
86
- const tag = tableCellNode.attrs.celltype;
87
- if (tableCellNode.attrs.colspan && tableCellNode.attrs.colspan !== 1) {
88
- attrs.colspan = String(tableCellNode.attrs.colspan);
89
- }
90
- if (tableCellNode.attrs.rowspan && tableCellNode.attrs.rowspan !== 1) {
91
- attrs.rowspan = String(tableCellNode.attrs.rowspan);
92
- }
93
- if (tableCellNode.attrs.colwidth) {
94
- attrs['data-colwidth'] = tableCellNode.attrs.colwidth.join(',');
95
- }
96
- if (tableCellNode.attrs.placeholder) {
97
- attrs['data-placeholder-text'] = tableCellNode.attrs.placeholder;
98
- }
99
- if (!tableCellNode.textContent) {
100
- attrs.class = 'placeholder';
101
- }
102
- const styleString = serializeTableCellStyles(tableCellNode.attrs.styles);
103
- if (styleString) {
104
- attrs.style = styleString;
105
- }
106
- if (tableCellNode.attrs.valign) {
107
- attrs.valign = tableCellNode.attrs.valign;
108
- }
109
- if (tableCellNode.attrs.align) {
110
- attrs.align = tableCellNode.attrs.align;
111
- }
112
- if (tableCellNode.attrs.scope) {
113
- attrs.scope = tableCellNode.attrs.scope;
114
- }
115
- if (tableCellNode.attrs.style) {
116
- attrs.style = tableCellNode.attrs.style;
117
- }
118
- return [tag, attrs, 0];
119
- },
120
- };
@@ -1,41 +0,0 @@
1
- /*!
2
- * © 2019 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { TableCellStyleKey } from '../../lib/table-cell-styles';
17
- import { ManuscriptNode, TableNodeSpec } from '../types';
18
- export interface TableRowNode extends ManuscriptNode {
19
- attrs: {
20
- placeholder: string;
21
- };
22
- }
23
- export declare const tableRow: TableNodeSpec;
24
- export type TableCellStyles = {
25
- [key in TableCellStyleKey]?: string | null;
26
- };
27
- export interface TableCellNode extends ManuscriptNode {
28
- attrs: {
29
- celltype: 'td' | 'th';
30
- colspan: number | null;
31
- rowspan: number | null;
32
- colwidth: number[] | null;
33
- placeholder: string | null;
34
- styles: TableCellStyles;
35
- valign: string | null;
36
- align: string | null;
37
- scope: string | null;
38
- style: string | null;
39
- };
40
- }
41
- export declare const tableCell: TableNodeSpec;