@manuscripts/transform 3.0.50 → 3.0.52

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.
@@ -127,9 +127,20 @@ class JATSExporter {
127
127
  };
128
128
  };
129
129
  };
130
+ this.nodesMap = new Map();
131
+ this.populateNodesMap = () => {
132
+ this.manuscriptNode.descendants((node) => {
133
+ var _a;
134
+ const type = node.type;
135
+ const nodes = (_a = this.nodesMap.get(type)) !== null && _a !== void 0 ? _a : [];
136
+ nodes.push(node);
137
+ this.nodesMap.set(type, nodes);
138
+ });
139
+ };
130
140
  this.serializeToJATS = async (manuscriptNode, options) => {
131
141
  var _a;
132
142
  this.manuscriptNode = manuscriptNode;
143
+ this.populateNodesMap();
133
144
  this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
134
145
  this.createSerializer();
135
146
  const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
@@ -269,13 +280,13 @@ class JATSExporter {
269
280
  articleMeta.appendChild(articleID);
270
281
  }
271
282
  const titleGroup = this.document.createElement('title-group');
272
- const titleNode = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.title).map((r) => r.node)[0];
283
+ const titleNode = this.getFirstChildOfType(schema_1.schema.nodes.title);
273
284
  if (titleNode) {
274
285
  const element = this.document.createElement('article-title');
275
286
  this.setTitleContent(element, titleNode.textContent);
276
287
  titleGroup.appendChild(element);
277
288
  }
278
- const altTitlesNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.alt_title).map((r) => r.node);
289
+ const altTitlesNodes = this.getChildrenOfType(schema_1.schema.nodes.alt_title);
279
290
  altTitlesNodes.forEach((titleNode) => {
280
291
  const element = this.document.createElement('alt-title');
281
292
  element.setAttribute('alt-title-type', titleNode.attrs.type);
@@ -284,8 +295,8 @@ class JATSExporter {
284
295
  });
285
296
  articleMeta.appendChild(titleGroup);
286
297
  this.buildContributors(articleMeta);
287
- const supplementsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.supplement);
288
- supplementsNodes.forEach(({ node }) => {
298
+ const supplementsNodes = this.getChildrenOfType(schema_1.schema.nodes.supplement);
299
+ supplementsNodes.forEach((node) => {
289
300
  var _a, _b, _c, _d;
290
301
  const supplementaryMaterial = this.document.createElement('supplementary-material');
291
302
  supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
@@ -330,13 +341,13 @@ class JATSExporter {
330
341
  }
331
342
  this.buildKeywords(articleMeta);
332
343
  let countingElements = [];
333
- const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
344
+ const figureCount = this.getChildrenOfType(schema_1.schema.nodes.figure).length;
334
345
  countingElements.push(this.buildCountingElement('fig-count', figureCount));
335
- const tableCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.table).length;
346
+ const tableCount = this.getChildrenOfType(schema_1.schema.nodes.table).length;
336
347
  countingElements.push(this.buildCountingElement('table-count', tableCount));
337
- const equationCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.equation_element).length;
348
+ const equationCount = this.getChildrenOfType(schema_1.schema.nodes.equation_element).length;
338
349
  countingElements.push(this.buildCountingElement('equation-count', equationCount));
339
- const referencesCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).length;
350
+ const referencesCount = this.getChildrenOfType(schema_1.schema.nodes.bibliography_item).length;
340
351
  countingElements.push(this.buildCountingElement('ref-count', referencesCount));
341
352
  const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
342
353
  countingElements.push(this.buildCountingElement('word-count', wordCount));
@@ -349,7 +360,7 @@ class JATSExporter {
349
360
  if (!journalMeta.hasChildNodes()) {
350
361
  journalMeta.remove();
351
362
  }
352
- const selfUriAttachments = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.attachment).map((r) => r.node);
363
+ const selfUriAttachments = this.getChildrenOfType(schema_1.schema.nodes.attachment);
353
364
  selfUriAttachments.forEach((attachment) => {
354
365
  const selfUriElement = this.document.createElement('self-uri');
355
366
  selfUriElement.setAttribute('content-type', attachment.attrs.type);
@@ -416,7 +427,7 @@ class JATSExporter {
416
427
  refList = this.document.createElement('ref-list');
417
428
  }
418
429
  back.appendChild(refList);
419
- const bibliographyItems = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.bibliography_item).map((n) => n.node);
430
+ const bibliographyItems = this.getChildrenOfType(schema_1.schema.nodes.bibliography_item);
420
431
  const [meta] = this.citationProvider.makeBibliography();
421
432
  for (const [id] of meta.entry_ids) {
422
433
  const bibliographyItem = bibliographyItems.find((n) => n.attrs.id === id);
@@ -805,11 +816,14 @@ class JATSExporter {
805
816
  placeholder_element: () => {
806
817
  return this.document.createElement('boxed-text');
807
818
  },
808
- pullquote_element: () => [
809
- 'disp-quote',
810
- { 'content-type': 'pullquote' },
811
- 0,
812
- ],
819
+ pullquote_element: (node) => {
820
+ var _a;
821
+ let type = 'pullquote';
822
+ if (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema_1.schema.nodes.figure) {
823
+ type = 'quote-with-image';
824
+ }
825
+ return ['disp-quote', { 'content-type': type }, 0];
826
+ },
813
827
  graphical_abstract_section: (node) => {
814
828
  const attrs = {
815
829
  id: normalizeID(node.attrs.id),
@@ -913,16 +927,14 @@ class JATSExporter {
913
927
  }
914
928
  };
915
929
  const appendChildNodeOfType = (element, node, type) => {
916
- var _a;
917
- const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
930
+ const childNode = this.getFirstChildOfType(type, node);
918
931
  if (childNode) {
919
932
  element.appendChild(this.serializeNode(childNode));
920
933
  }
921
934
  };
922
935
  const appendTable = (element, node) => {
923
- var _a, _b;
924
- const tableNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
925
- const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
936
+ const tableNode = this.getFirstChildOfType(schema_1.schema.nodes.table, node);
937
+ const colGroupNode = this.getFirstChildOfType(schema_1.schema.nodes.table_colgroup, node);
926
938
  if (!tableNode) {
927
939
  return;
928
940
  }
@@ -947,6 +959,13 @@ class JATSExporter {
947
959
  processChildNodes(element, node, node.type.schema.nodes.section);
948
960
  return element;
949
961
  };
962
+ const isChildOfNodeType = (targetID, type, descend = false) => {
963
+ const nodes = this.getChildrenOfType(type);
964
+ return nodes.some((node) => {
965
+ const result = (0, prosemirror_utils_1.findChildrenByAttr)(node, (attrs) => attrs.id === targetID, descend)[0];
966
+ return !!result;
967
+ });
968
+ };
950
969
  const createImage = (node) => {
951
970
  const graphicNode = node.content.firstChild;
952
971
  if (graphicNode) {
@@ -957,18 +976,19 @@ class JATSExporter {
957
976
  }
958
977
  return '';
959
978
  };
960
- const createGraphic = (node, isChildOfFigure = true) => {
979
+ const createGraphic = (node) => {
961
980
  const graphic = this.document.createElement('graphic');
962
981
  graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
963
- if (!isChildOfFigure && node.attrs.type) {
982
+ if (!isChildOfNodeType(node.attrs.id, schema_1.schema.nodes.figure_element) &&
983
+ node.attrs.type) {
964
984
  graphic.setAttribute('content-type', node.attrs.type);
965
985
  }
966
986
  return graphic;
967
987
  };
968
988
  const createFigureElement = (node, contentNodeType) => {
969
989
  const element = createElement(node, 'fig');
970
- const figNode = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.figure)[0];
971
- const figType = figNode === null || figNode === void 0 ? void 0 : figNode.node.attrs.type;
990
+ const figNode = this.getFirstChildOfType(schema_1.schema.nodes.figure, node);
991
+ const figType = figNode === null || figNode === void 0 ? void 0 : figNode.attrs.type;
972
992
  if (figType) {
973
993
  element.setAttribute('fig-type', figType);
974
994
  }
@@ -999,8 +1019,7 @@ class JATSExporter {
999
1019
  return element;
1000
1020
  };
1001
1021
  const processExecutableNode = (node, element) => {
1002
- var _a;
1003
- const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
1022
+ const listingNode = this.getFirstChildOfType(schema_1.schema.nodes.listing, node);
1004
1023
  if (listingNode) {
1005
1024
  const { contents, languageKey } = listingNode.attrs;
1006
1025
  if (contents && languageKey) {
@@ -1029,7 +1048,7 @@ class JATSExporter {
1029
1048
  }
1030
1049
  };
1031
1050
  this.buildContributors = (articleMeta) => {
1032
- const contributorNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1051
+ const contributorNodes = this.getChildrenOfType(schema_1.schema.nodes.contributor);
1033
1052
  const authorContributorNodes = contributorNodes
1034
1053
  .filter((n) => n.attrs.role === 'author')
1035
1054
  .sort(sortContributors);
@@ -1163,8 +1182,8 @@ class JATSExporter {
1163
1182
  affiliationRIDs.push(...contributor.attrs.affiliations);
1164
1183
  }
1165
1184
  }
1166
- const affiliations = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.affiliation).map((result) => result.node);
1167
- if (affiliations) {
1185
+ const affiliations = this.getChildrenOfType(schema_1.schema.nodes.affiliation);
1186
+ if (affiliations.length) {
1168
1187
  const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1169
1188
  usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1170
1189
  affiliationRIDs.indexOf(b.attrs.id));
@@ -1230,9 +1249,8 @@ class JATSExporter {
1230
1249
  }
1231
1250
  };
1232
1251
  this.createAuthorNotesElement = () => {
1233
- var _a;
1234
1252
  const authorNotesEl = this.document.createElement('author-notes');
1235
- const authorNotesNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1253
+ const authorNotesNode = this.getFirstChildOfType(schema_1.schema.nodes.author_notes);
1236
1254
  if (authorNotesNode) {
1237
1255
  this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1238
1256
  }
@@ -1394,9 +1412,8 @@ class JATSExporter {
1394
1412
  }
1395
1413
  };
1396
1414
  this.moveAbstracts = (front, body) => {
1397
- var _a;
1398
1415
  const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
1399
- const abstractsNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.abstracts)[0]) === null || _a === void 0 ? void 0 : _a.node;
1416
+ const abstractsNode = this.getFirstChildOfType(schema_1.schema.nodes.abstracts);
1400
1417
  const abstractCategories = this.getAbstractCategories(abstractsNode);
1401
1418
  const abstractSections = this.getAbstractSections(container, body, abstractCategories);
1402
1419
  if (abstractSections.length) {
@@ -1531,6 +1548,15 @@ class JATSExporter {
1531
1548
  this.citationTexts.set(id, output);
1532
1549
  });
1533
1550
  }
1551
+ getFirstChildOfType(type, node) {
1552
+ return this.getChildrenOfType(type, node)[0];
1553
+ }
1554
+ getChildrenOfType(type, node) {
1555
+ const nodes = node
1556
+ ? (0, prosemirror_utils_1.findChildrenByType)(node, type).map(({ node }) => node)
1557
+ : this.nodesMap.get(type);
1558
+ return (nodes !== null && nodes !== void 0 ? nodes : []).filter((n) => (0, schema_1.isNodeOfType)(n, type));
1559
+ }
1534
1560
  createEquation(node, isInline = false) {
1535
1561
  if (node.attrs.format === 'tex') {
1536
1562
  const texMath = this.document.createElement('tex-math');
@@ -1554,7 +1580,7 @@ class JATSExporter {
1554
1580
  }
1555
1581
  }
1556
1582
  appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1557
- const contributorsNodes = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.contributor).map((result) => result.node);
1583
+ const contributorsNodes = this.getChildrenOfType(schema_1.schema.nodes.contributor);
1558
1584
  const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1559
1585
  authorNotesNode.descendants((node) => {
1560
1586
  switch (node.type) {
@@ -1583,7 +1609,7 @@ class JATSExporter {
1583
1609
  .filter((corresp) => !!corresp);
1584
1610
  }
1585
1611
  buildKeywords(articleMeta) {
1586
- const keywordGroups = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.keyword_group).map((result) => result.node);
1612
+ const keywordGroups = this.getChildrenOfType(schema_1.schema.nodes.keyword_group);
1587
1613
  keywordGroups.forEach((group) => {
1588
1614
  const kwdGroup = this.document.createElement('kwd-group');
1589
1615
  if (group.attrs.type) {
@@ -553,7 +553,7 @@ class JATSDOMParser {
553
553
  },
554
554
  },
555
555
  {
556
- tag: 'disp-quote[content-type=pullquote]',
556
+ tag: 'disp-quote',
557
557
  node: 'pullquote_element',
558
558
  getAttrs: (node) => {
559
559
  const element = node;
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.isPullquoteElement = exports.pullquoteElement = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  exports.pullquoteElement = {
21
- content: 'paragraph+ attribution',
21
+ content: 'figure? paragraph+ attribution',
22
22
  attrs: {
23
23
  id: { default: '' },
24
24
  placeholder: { default: '' },
@@ -15,3 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.isNodeOfType = void 0;
19
+ function isNodeOfType(node, type) {
20
+ return node.type === type;
21
+ }
22
+ exports.isNodeOfType = isNodeOfType;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "3.0.50";
4
+ exports.VERSION = "3.0.52";
@@ -21,7 +21,7 @@ import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
21
21
  import serializeToXML from 'w3c-xmlserializer';
22
22
  import { generateFootnoteLabels } from '../../lib/footnotes';
23
23
  import { nodeFromHTML, textFromHTML } from '../../lib/html';
24
- import { isCitationNode, schema, } from '../../schema';
24
+ import { isCitationNode, isNodeOfType, schema, } from '../../schema';
25
25
  import { isExecutableNodeType, isNodeType } from '../../transformer';
26
26
  import { selectVersionIds } from './jats-versions';
27
27
  import { buildTargets } from './labels';
@@ -119,9 +119,20 @@ export class JATSExporter {
119
119
  };
120
120
  };
121
121
  };
122
+ this.nodesMap = new Map();
123
+ this.populateNodesMap = () => {
124
+ this.manuscriptNode.descendants((node) => {
125
+ var _a;
126
+ const type = node.type;
127
+ const nodes = (_a = this.nodesMap.get(type)) !== null && _a !== void 0 ? _a : [];
128
+ nodes.push(node);
129
+ this.nodesMap.set(type, nodes);
130
+ });
131
+ };
122
132
  this.serializeToJATS = async (manuscriptNode, options) => {
123
133
  var _a;
124
134
  this.manuscriptNode = manuscriptNode;
135
+ this.populateNodesMap();
125
136
  this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
126
137
  this.createSerializer();
127
138
  const versionIds = selectVersionIds((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
@@ -261,13 +272,13 @@ export class JATSExporter {
261
272
  articleMeta.appendChild(articleID);
262
273
  }
263
274
  const titleGroup = this.document.createElement('title-group');
264
- const titleNode = findChildrenByType(this.manuscriptNode, schema.nodes.title).map((r) => r.node)[0];
275
+ const titleNode = this.getFirstChildOfType(schema.nodes.title);
265
276
  if (titleNode) {
266
277
  const element = this.document.createElement('article-title');
267
278
  this.setTitleContent(element, titleNode.textContent);
268
279
  titleGroup.appendChild(element);
269
280
  }
270
- const altTitlesNodes = findChildrenByType(this.manuscriptNode, schema.nodes.alt_title).map((r) => r.node);
281
+ const altTitlesNodes = this.getChildrenOfType(schema.nodes.alt_title);
271
282
  altTitlesNodes.forEach((titleNode) => {
272
283
  const element = this.document.createElement('alt-title');
273
284
  element.setAttribute('alt-title-type', titleNode.attrs.type);
@@ -276,8 +287,8 @@ export class JATSExporter {
276
287
  });
277
288
  articleMeta.appendChild(titleGroup);
278
289
  this.buildContributors(articleMeta);
279
- const supplementsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.supplement);
280
- supplementsNodes.forEach(({ node }) => {
290
+ const supplementsNodes = this.getChildrenOfType(schema.nodes.supplement);
291
+ supplementsNodes.forEach((node) => {
281
292
  var _a, _b, _c, _d;
282
293
  const supplementaryMaterial = this.document.createElement('supplementary-material');
283
294
  supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
@@ -322,13 +333,13 @@ export class JATSExporter {
322
333
  }
323
334
  this.buildKeywords(articleMeta);
324
335
  let countingElements = [];
325
- const figureCount = findChildrenByType(this.manuscriptNode, schema.nodes.figure).length;
336
+ const figureCount = this.getChildrenOfType(schema.nodes.figure).length;
326
337
  countingElements.push(this.buildCountingElement('fig-count', figureCount));
327
- const tableCount = findChildrenByType(this.manuscriptNode, schema.nodes.table).length;
338
+ const tableCount = this.getChildrenOfType(schema.nodes.table).length;
328
339
  countingElements.push(this.buildCountingElement('table-count', tableCount));
329
- const equationCount = findChildrenByType(this.manuscriptNode, schema.nodes.equation_element).length;
340
+ const equationCount = this.getChildrenOfType(schema.nodes.equation_element).length;
330
341
  countingElements.push(this.buildCountingElement('equation-count', equationCount));
331
- const referencesCount = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).length;
342
+ const referencesCount = this.getChildrenOfType(schema.nodes.bibliography_item).length;
332
343
  countingElements.push(this.buildCountingElement('ref-count', referencesCount));
333
344
  const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
334
345
  countingElements.push(this.buildCountingElement('word-count', wordCount));
@@ -341,7 +352,7 @@ export class JATSExporter {
341
352
  if (!journalMeta.hasChildNodes()) {
342
353
  journalMeta.remove();
343
354
  }
344
- const selfUriAttachments = findChildrenByType(this.manuscriptNode, schema.nodes.attachment).map((r) => r.node);
355
+ const selfUriAttachments = this.getChildrenOfType(schema.nodes.attachment);
345
356
  selfUriAttachments.forEach((attachment) => {
346
357
  const selfUriElement = this.document.createElement('self-uri');
347
358
  selfUriElement.setAttribute('content-type', attachment.attrs.type);
@@ -408,7 +419,7 @@ export class JATSExporter {
408
419
  refList = this.document.createElement('ref-list');
409
420
  }
410
421
  back.appendChild(refList);
411
- const bibliographyItems = findChildrenByType(this.manuscriptNode, schema.nodes.bibliography_item).map((n) => n.node);
422
+ const bibliographyItems = this.getChildrenOfType(schema.nodes.bibliography_item);
412
423
  const [meta] = this.citationProvider.makeBibliography();
413
424
  for (const [id] of meta.entry_ids) {
414
425
  const bibliographyItem = bibliographyItems.find((n) => n.attrs.id === id);
@@ -797,11 +808,14 @@ export class JATSExporter {
797
808
  placeholder_element: () => {
798
809
  return this.document.createElement('boxed-text');
799
810
  },
800
- pullquote_element: () => [
801
- 'disp-quote',
802
- { 'content-type': 'pullquote' },
803
- 0,
804
- ],
811
+ pullquote_element: (node) => {
812
+ var _a;
813
+ let type = 'pullquote';
814
+ if (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.figure) {
815
+ type = 'quote-with-image';
816
+ }
817
+ return ['disp-quote', { 'content-type': type }, 0];
818
+ },
805
819
  graphical_abstract_section: (node) => {
806
820
  const attrs = {
807
821
  id: normalizeID(node.attrs.id),
@@ -905,16 +919,14 @@ export class JATSExporter {
905
919
  }
906
920
  };
907
921
  const appendChildNodeOfType = (element, node, type) => {
908
- var _a;
909
- const childNode = (_a = findChildrenByType(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
922
+ const childNode = this.getFirstChildOfType(type, node);
910
923
  if (childNode) {
911
924
  element.appendChild(this.serializeNode(childNode));
912
925
  }
913
926
  };
914
927
  const appendTable = (element, node) => {
915
- var _a, _b;
916
- const tableNode = (_a = findChildrenByType(node, node.type.schema.nodes.table)[0]) === null || _a === void 0 ? void 0 : _a.node;
917
- const colGroupNode = (_b = findChildrenByType(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
928
+ const tableNode = this.getFirstChildOfType(schema.nodes.table, node);
929
+ const colGroupNode = this.getFirstChildOfType(schema.nodes.table_colgroup, node);
918
930
  if (!tableNode) {
919
931
  return;
920
932
  }
@@ -939,6 +951,13 @@ export class JATSExporter {
939
951
  processChildNodes(element, node, node.type.schema.nodes.section);
940
952
  return element;
941
953
  };
954
+ const isChildOfNodeType = (targetID, type, descend = false) => {
955
+ const nodes = this.getChildrenOfType(type);
956
+ return nodes.some((node) => {
957
+ const result = findChildrenByAttr(node, (attrs) => attrs.id === targetID, descend)[0];
958
+ return !!result;
959
+ });
960
+ };
942
961
  const createImage = (node) => {
943
962
  const graphicNode = node.content.firstChild;
944
963
  if (graphicNode) {
@@ -949,18 +968,19 @@ export class JATSExporter {
949
968
  }
950
969
  return '';
951
970
  };
952
- const createGraphic = (node, isChildOfFigure = true) => {
971
+ const createGraphic = (node) => {
953
972
  const graphic = this.document.createElement('graphic');
954
973
  graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
955
- if (!isChildOfFigure && node.attrs.type) {
974
+ if (!isChildOfNodeType(node.attrs.id, schema.nodes.figure_element) &&
975
+ node.attrs.type) {
956
976
  graphic.setAttribute('content-type', node.attrs.type);
957
977
  }
958
978
  return graphic;
959
979
  };
960
980
  const createFigureElement = (node, contentNodeType) => {
961
981
  const element = createElement(node, 'fig');
962
- const figNode = findChildrenByType(node, node.type.schema.nodes.figure)[0];
963
- const figType = figNode === null || figNode === void 0 ? void 0 : figNode.node.attrs.type;
982
+ const figNode = this.getFirstChildOfType(schema.nodes.figure, node);
983
+ const figType = figNode === null || figNode === void 0 ? void 0 : figNode.attrs.type;
964
984
  if (figType) {
965
985
  element.setAttribute('fig-type', figType);
966
986
  }
@@ -991,8 +1011,7 @@ export class JATSExporter {
991
1011
  return element;
992
1012
  };
993
1013
  const processExecutableNode = (node, element) => {
994
- var _a;
995
- const listingNode = (_a = findChildrenByType(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
1014
+ const listingNode = this.getFirstChildOfType(schema.nodes.listing, node);
996
1015
  if (listingNode) {
997
1016
  const { contents, languageKey } = listingNode.attrs;
998
1017
  if (contents && languageKey) {
@@ -1021,7 +1040,7 @@ export class JATSExporter {
1021
1040
  }
1022
1041
  };
1023
1042
  this.buildContributors = (articleMeta) => {
1024
- const contributorNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
1043
+ const contributorNodes = this.getChildrenOfType(schema.nodes.contributor);
1025
1044
  const authorContributorNodes = contributorNodes
1026
1045
  .filter((n) => n.attrs.role === 'author')
1027
1046
  .sort(sortContributors);
@@ -1155,8 +1174,8 @@ export class JATSExporter {
1155
1174
  affiliationRIDs.push(...contributor.attrs.affiliations);
1156
1175
  }
1157
1176
  }
1158
- const affiliations = findChildrenByType(this.manuscriptNode, schema.nodes.affiliation).map((result) => result.node);
1159
- if (affiliations) {
1177
+ const affiliations = this.getChildrenOfType(schema.nodes.affiliation);
1178
+ if (affiliations.length) {
1160
1179
  const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1161
1180
  usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1162
1181
  affiliationRIDs.indexOf(b.attrs.id));
@@ -1222,9 +1241,8 @@ export class JATSExporter {
1222
1241
  }
1223
1242
  };
1224
1243
  this.createAuthorNotesElement = () => {
1225
- var _a;
1226
1244
  const authorNotesEl = this.document.createElement('author-notes');
1227
- const authorNotesNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.author_notes)[0]) === null || _a === void 0 ? void 0 : _a.node;
1245
+ const authorNotesNode = this.getFirstChildOfType(schema.nodes.author_notes);
1228
1246
  if (authorNotesNode) {
1229
1247
  this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
1230
1248
  }
@@ -1386,9 +1404,8 @@ export class JATSExporter {
1386
1404
  }
1387
1405
  };
1388
1406
  this.moveAbstracts = (front, body) => {
1389
- var _a;
1390
1407
  const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
1391
- const abstractsNode = (_a = findChildrenByType(this.manuscriptNode, schema.nodes.abstracts)[0]) === null || _a === void 0 ? void 0 : _a.node;
1408
+ const abstractsNode = this.getFirstChildOfType(schema.nodes.abstracts);
1392
1409
  const abstractCategories = this.getAbstractCategories(abstractsNode);
1393
1410
  const abstractSections = this.getAbstractSections(container, body, abstractCategories);
1394
1411
  if (abstractSections.length) {
@@ -1523,6 +1540,15 @@ export class JATSExporter {
1523
1540
  this.citationTexts.set(id, output);
1524
1541
  });
1525
1542
  }
1543
+ getFirstChildOfType(type, node) {
1544
+ return this.getChildrenOfType(type, node)[0];
1545
+ }
1546
+ getChildrenOfType(type, node) {
1547
+ const nodes = node
1548
+ ? findChildrenByType(node, type).map(({ node }) => node)
1549
+ : this.nodesMap.get(type);
1550
+ return (nodes !== null && nodes !== void 0 ? nodes : []).filter((n) => isNodeOfType(n, type));
1551
+ }
1526
1552
  createEquation(node, isInline = false) {
1527
1553
  if (node.attrs.format === 'tex') {
1528
1554
  const texMath = this.document.createElement('tex-math');
@@ -1546,7 +1572,7 @@ export class JATSExporter {
1546
1572
  }
1547
1573
  }
1548
1574
  appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
1549
- const contributorsNodes = findChildrenByType(this.manuscriptNode, schema.nodes.contributor).map((result) => result.node);
1575
+ const contributorsNodes = this.getChildrenOfType(schema.nodes.contributor);
1550
1576
  const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
1551
1577
  authorNotesNode.descendants((node) => {
1552
1578
  switch (node.type) {
@@ -1575,7 +1601,7 @@ export class JATSExporter {
1575
1601
  .filter((corresp) => !!corresp);
1576
1602
  }
1577
1603
  buildKeywords(articleMeta) {
1578
- const keywordGroups = findChildrenByType(this.manuscriptNode, schema.nodes.keyword_group).map((result) => result.node);
1604
+ const keywordGroups = this.getChildrenOfType(schema.nodes.keyword_group);
1579
1605
  keywordGroups.forEach((group) => {
1580
1606
  const kwdGroup = this.document.createElement('kwd-group');
1581
1607
  if (group.attrs.type) {
@@ -550,7 +550,7 @@ export class JATSDOMParser {
550
550
  },
551
551
  },
552
552
  {
553
- tag: 'disp-quote[content-type=pullquote]',
553
+ tag: 'disp-quote',
554
554
  node: 'pullquote_element',
555
555
  getAttrs: (node) => {
556
556
  const element = node;
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  export const pullquoteElement = {
18
- content: 'paragraph+ attribution',
18
+ content: 'figure? paragraph+ attribution',
19
19
  attrs: {
20
20
  id: { default: '' },
21
21
  placeholder: { default: '' },
@@ -13,4 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export {};
16
+ export function isNodeOfType(node, type) {
17
+ return node.type === type;
18
+ }
@@ -1 +1 @@
1
- export const VERSION = "3.0.50";
1
+ export const VERSION = "3.0.52";
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { BibliographyItem, Journal } from '@manuscripts/json-schema';
17
17
  import { CitationProvider } from '@manuscripts/library';
18
- import { DOMSerializer } from 'prosemirror-model';
18
+ import { type NodeType, DOMSerializer } from 'prosemirror-model';
19
19
  import { CitationNode, ManuscriptNode } from '../../schema';
20
20
  import { IDGenerator } from '../types';
21
21
  import { Version } from './jats-versions';
@@ -60,6 +60,10 @@ export declare class JATSExporter {
60
60
  }[];
61
61
  protected getLibraryItem: (manuscriptID: string) => (id: string) => BibliographyItem | undefined;
62
62
  protected generateCitationTexts(csl: CSLOptions, manuscriptID: string): void;
63
+ private nodesMap;
64
+ private populateNodesMap;
65
+ protected getFirstChildOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T | undefined;
66
+ protected getChildrenOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T[];
63
67
  serializeToJATS: (manuscriptNode: ManuscriptNode, options: ExportOptions) => Promise<string>;
64
68
  private nodeFromJATS;
65
69
  protected rewriteIDs: (generator?: IDGenerator) => Promise<void>;
@@ -63,3 +63,4 @@ export type MarkRule = ParseRule & {
63
63
  export type NodeRule = ParseRule & {
64
64
  node?: Nodes | null;
65
65
  };
66
+ export declare function isNodeOfType<T extends ManuscriptNode>(node: ManuscriptNode, type: NodeType): node is T;
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.50";
1
+ export declare const VERSION = "3.0.52";
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": "3.0.50",
4
+ "version": "3.0.52",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",