@manuscripts/transform 4.3.13 → 4.3.15

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.
@@ -470,7 +470,11 @@ class JATSExporter {
470
470
  el.textContent = content;
471
471
  }
472
472
  if (attrs) {
473
- Object.entries(attrs).forEach(([k, v]) => el.setAttribute(k, v));
473
+ Object.entries(attrs).forEach(([k, v]) => {
474
+ if (v) {
475
+ el.setAttribute(k, v);
476
+ }
477
+ });
474
478
  }
475
479
  return el;
476
480
  };
@@ -1000,12 +1004,12 @@ class JATSExporter {
1000
1004
  }
1001
1005
  };
1002
1006
  this.buildContributors = (articleMeta) => {
1003
- const contributorNodes = this.getChildrenOfType(schema_1.schema.nodes.contributor).sort(sortContributors);
1007
+ const contributors = this.getChildrenOfType(schema_1.schema.nodes.contributor).sort(sortContributors);
1004
1008
  const affiliationLabels = new Map();
1005
1009
  const creatAffiliationLabel = (rid) => {
1006
1010
  let label = affiliationLabels.get(rid);
1007
1011
  if (!label) {
1008
- label = affiliationLabels.size + 1;
1012
+ label = String(affiliationLabels.size + 1);
1009
1013
  affiliationLabels.set(rid, label);
1010
1014
  }
1011
1015
  const sup = this.createElement('sup');
@@ -1017,11 +1021,11 @@ class JATSExporter {
1017
1021
  sup.textContent = String(content);
1018
1022
  return sup;
1019
1023
  };
1020
- if (contributorNodes.length) {
1024
+ if (contributors.length) {
1021
1025
  const contribGroup = this.createElement('contrib-group');
1022
1026
  contribGroup.setAttribute('content-type', 'authors');
1023
1027
  articleMeta.appendChild(contribGroup);
1024
- contributorNodes.forEach((contributor) => {
1028
+ contributors.forEach((contributor) => {
1025
1029
  try {
1026
1030
  this.validateContributor(contributor);
1027
1031
  }
@@ -1092,70 +1096,54 @@ class JATSExporter {
1092
1096
  contribGroup.appendChild(contrib);
1093
1097
  });
1094
1098
  const affiliationRIDs = [];
1095
- for (const contributor of contributorNodes) {
1099
+ for (const contributor of contributors) {
1096
1100
  if (contributor.attrs.affiliations) {
1097
1101
  affiliationRIDs.push(...contributor.attrs.affiliations);
1098
1102
  }
1099
1103
  }
1100
- const affiliations = this.getChildrenOfType(schema_1.schema.nodes.affiliation);
1101
- if (affiliations.length) {
1102
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1103
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1104
- affiliationRIDs.indexOf(b.attrs.id));
1105
- usedAffiliations.forEach((affiliation) => {
1106
- const aff = this.createElement('aff');
1107
- aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1108
- contribGroup.appendChild(aff);
1109
- if (affiliation.attrs.department) {
1110
- const department = this.createElement('institution');
1111
- department.setAttribute('content-type', 'dept');
1112
- department.textContent = affiliation.attrs.department;
1113
- aff.appendChild(department);
1114
- }
1115
- if (affiliation.attrs.institution) {
1116
- const institution = this.createElement('institution');
1117
- institution.textContent = affiliation.attrs.institution;
1118
- aff.appendChild(institution);
1119
- }
1120
- if (affiliation.attrs.addressLine1) {
1121
- const addressLine = this.createElement('addr-line');
1122
- addressLine.textContent = affiliation.attrs.addressLine1;
1123
- aff.appendChild(addressLine);
1124
- }
1125
- if (affiliation.attrs.addressLine2) {
1126
- const addressLine = this.createElement('addr-line');
1127
- addressLine.textContent = affiliation.attrs.addressLine2;
1128
- aff.appendChild(addressLine);
1129
- }
1130
- if (affiliation.attrs.addressLine3) {
1131
- const addressLine = this.createElement('addr-line');
1132
- addressLine.textContent = affiliation.attrs.addressLine3;
1133
- aff.appendChild(addressLine);
1134
- }
1135
- if (affiliation.attrs.city) {
1136
- const city = this.createElement('city');
1137
- city.textContent = affiliation.attrs.city;
1138
- aff.appendChild(city);
1139
- }
1140
- if (affiliation.attrs.country) {
1141
- const country = this.createElement('country');
1142
- country.textContent = affiliation.attrs.country;
1143
- aff.appendChild(country);
1144
- }
1145
- if (affiliation.attrs.email) {
1146
- const email = this.createElement('email');
1147
- email.setAttributeNS(xml_1.XLINK_NAMESPACE, 'href', affiliation.attrs.email.href ?? '');
1148
- email.textContent = affiliation.attrs.email.text ?? '';
1149
- aff.appendChild(email);
1150
- }
1151
- const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1152
- if (labelNumber) {
1153
- const label = this.createElement('label');
1154
- label.textContent = String(labelNumber);
1155
- aff.appendChild(label);
1104
+ const affiliationIDs = contributors.flatMap((n) => n.attrs.affiliations);
1105
+ const sortAffiliations = (a, b) => affiliationIDs.indexOf(a.attrs.id) - affiliationIDs.indexOf(b.attrs.id);
1106
+ this.getChildrenOfType(schema_1.schema.nodes.affiliation)
1107
+ .filter((a) => affiliationIDs.includes(a.attrs.id))
1108
+ .sort(sortAffiliations)
1109
+ .forEach((affiliation) => {
1110
+ const $aff = this.createElement('aff', '', {
1111
+ id: normalizeID(affiliation.attrs.id),
1112
+ });
1113
+ const label = affiliationLabels.get(affiliation.attrs.id);
1114
+ if (label) {
1115
+ this.appendElement($aff, 'label', String(label));
1116
+ }
1117
+ const affiliationParts = [
1118
+ {
1119
+ value: affiliation.attrs.department,
1120
+ tag: 'institution',
1121
+ 'content-type': 'dept',
1122
+ },
1123
+ { value: affiliation.attrs.institution, tag: 'institution' },
1124
+ { value: affiliation.attrs.addressLine1, tag: 'addr-line' },
1125
+ { value: affiliation.attrs.addressLine2, tag: 'addr-line' },
1126
+ { value: affiliation.attrs.addressLine3, tag: 'addr-line' },
1127
+ { value: affiliation.attrs.city, tag: 'city' },
1128
+ { value: affiliation.attrs.county, tag: 'state' },
1129
+ { value: affiliation.attrs.country, tag: 'country' },
1130
+ { value: affiliation.attrs.postCode, tag: 'postal-code' },
1131
+ ].filter((obj) => obj.value);
1132
+ affiliationParts.forEach((location, index) => {
1133
+ if (index) {
1134
+ const punctuation = this.document.createTextNode(', ');
1135
+ $aff.appendChild(punctuation);
1156
1136
  }
1137
+ const { tag, value, ...rest } = location;
1138
+ this.appendElement($aff, tag, value, rest);
1157
1139
  });
1158
- }
1140
+ const { href, text } = affiliation.attrs.email ?? {};
1141
+ if (href) {
1142
+ const email = this.appendElement($aff, 'email', text ?? href);
1143
+ email.setAttributeNS(xml_1.XLINK_NAMESPACE, 'href', href);
1144
+ }
1145
+ contribGroup.appendChild($aff);
1146
+ });
1159
1147
  const authorNotesEl = this.createAuthorNotesElement();
1160
1148
  if (authorNotesEl.childNodes.length > 0) {
1161
1149
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
@@ -454,6 +454,8 @@ class JATSDOMParser {
454
454
  addressLine3: this.getAddressLine(element, 3),
455
455
  postCode: (0, utils_1.getTrimmedTextContent)(element, 'postal-code') ?? '',
456
456
  country: (0, utils_1.getTrimmedTextContent)(element, 'country') ?? '',
457
+ county: (0, utils_1.getTrimmedTextContent)(element, 'state') ?? '',
458
+ city: (0, utils_1.getTrimmedTextContent)(element, 'city') ?? '',
457
459
  email: this.getEmail(element),
458
460
  priority: this.parsePriority(element.getAttribute('priority')),
459
461
  };
@@ -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 = "4.3.13";
4
+ exports.VERSION = "4.3.15";
@@ -430,7 +430,11 @@ export class JATSExporter {
430
430
  el.textContent = content;
431
431
  }
432
432
  if (attrs) {
433
- Object.entries(attrs).forEach(([k, v]) => el.setAttribute(k, v));
433
+ Object.entries(attrs).forEach(([k, v]) => {
434
+ if (v) {
435
+ el.setAttribute(k, v);
436
+ }
437
+ });
434
438
  }
435
439
  return el;
436
440
  };
@@ -960,12 +964,12 @@ export class JATSExporter {
960
964
  }
961
965
  };
962
966
  this.buildContributors = (articleMeta) => {
963
- const contributorNodes = this.getChildrenOfType(schema.nodes.contributor).sort(sortContributors);
967
+ const contributors = this.getChildrenOfType(schema.nodes.contributor).sort(sortContributors);
964
968
  const affiliationLabels = new Map();
965
969
  const creatAffiliationLabel = (rid) => {
966
970
  let label = affiliationLabels.get(rid);
967
971
  if (!label) {
968
- label = affiliationLabels.size + 1;
972
+ label = String(affiliationLabels.size + 1);
969
973
  affiliationLabels.set(rid, label);
970
974
  }
971
975
  const sup = this.createElement('sup');
@@ -977,11 +981,11 @@ export class JATSExporter {
977
981
  sup.textContent = String(content);
978
982
  return sup;
979
983
  };
980
- if (contributorNodes.length) {
984
+ if (contributors.length) {
981
985
  const contribGroup = this.createElement('contrib-group');
982
986
  contribGroup.setAttribute('content-type', 'authors');
983
987
  articleMeta.appendChild(contribGroup);
984
- contributorNodes.forEach((contributor) => {
988
+ contributors.forEach((contributor) => {
985
989
  try {
986
990
  this.validateContributor(contributor);
987
991
  }
@@ -1052,70 +1056,54 @@ export class JATSExporter {
1052
1056
  contribGroup.appendChild(contrib);
1053
1057
  });
1054
1058
  const affiliationRIDs = [];
1055
- for (const contributor of contributorNodes) {
1059
+ for (const contributor of contributors) {
1056
1060
  if (contributor.attrs.affiliations) {
1057
1061
  affiliationRIDs.push(...contributor.attrs.affiliations);
1058
1062
  }
1059
1063
  }
1060
- const affiliations = this.getChildrenOfType(schema.nodes.affiliation);
1061
- if (affiliations.length) {
1062
- const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
1063
- usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
1064
- affiliationRIDs.indexOf(b.attrs.id));
1065
- usedAffiliations.forEach((affiliation) => {
1066
- const aff = this.createElement('aff');
1067
- aff.setAttribute('id', normalizeID(affiliation.attrs.id));
1068
- contribGroup.appendChild(aff);
1069
- if (affiliation.attrs.department) {
1070
- const department = this.createElement('institution');
1071
- department.setAttribute('content-type', 'dept');
1072
- department.textContent = affiliation.attrs.department;
1073
- aff.appendChild(department);
1074
- }
1075
- if (affiliation.attrs.institution) {
1076
- const institution = this.createElement('institution');
1077
- institution.textContent = affiliation.attrs.institution;
1078
- aff.appendChild(institution);
1079
- }
1080
- if (affiliation.attrs.addressLine1) {
1081
- const addressLine = this.createElement('addr-line');
1082
- addressLine.textContent = affiliation.attrs.addressLine1;
1083
- aff.appendChild(addressLine);
1084
- }
1085
- if (affiliation.attrs.addressLine2) {
1086
- const addressLine = this.createElement('addr-line');
1087
- addressLine.textContent = affiliation.attrs.addressLine2;
1088
- aff.appendChild(addressLine);
1089
- }
1090
- if (affiliation.attrs.addressLine3) {
1091
- const addressLine = this.createElement('addr-line');
1092
- addressLine.textContent = affiliation.attrs.addressLine3;
1093
- aff.appendChild(addressLine);
1094
- }
1095
- if (affiliation.attrs.city) {
1096
- const city = this.createElement('city');
1097
- city.textContent = affiliation.attrs.city;
1098
- aff.appendChild(city);
1099
- }
1100
- if (affiliation.attrs.country) {
1101
- const country = this.createElement('country');
1102
- country.textContent = affiliation.attrs.country;
1103
- aff.appendChild(country);
1104
- }
1105
- if (affiliation.attrs.email) {
1106
- const email = this.createElement('email');
1107
- email.setAttributeNS(XLINK_NAMESPACE, 'href', affiliation.attrs.email.href ?? '');
1108
- email.textContent = affiliation.attrs.email.text ?? '';
1109
- aff.appendChild(email);
1110
- }
1111
- const labelNumber = affiliationLabels.get(affiliation.attrs.id);
1112
- if (labelNumber) {
1113
- const label = this.createElement('label');
1114
- label.textContent = String(labelNumber);
1115
- aff.appendChild(label);
1064
+ const affiliationIDs = contributors.flatMap((n) => n.attrs.affiliations);
1065
+ const sortAffiliations = (a, b) => affiliationIDs.indexOf(a.attrs.id) - affiliationIDs.indexOf(b.attrs.id);
1066
+ this.getChildrenOfType(schema.nodes.affiliation)
1067
+ .filter((a) => affiliationIDs.includes(a.attrs.id))
1068
+ .sort(sortAffiliations)
1069
+ .forEach((affiliation) => {
1070
+ const $aff = this.createElement('aff', '', {
1071
+ id: normalizeID(affiliation.attrs.id),
1072
+ });
1073
+ const label = affiliationLabels.get(affiliation.attrs.id);
1074
+ if (label) {
1075
+ this.appendElement($aff, 'label', String(label));
1076
+ }
1077
+ const affiliationParts = [
1078
+ {
1079
+ value: affiliation.attrs.department,
1080
+ tag: 'institution',
1081
+ 'content-type': 'dept',
1082
+ },
1083
+ { value: affiliation.attrs.institution, tag: 'institution' },
1084
+ { value: affiliation.attrs.addressLine1, tag: 'addr-line' },
1085
+ { value: affiliation.attrs.addressLine2, tag: 'addr-line' },
1086
+ { value: affiliation.attrs.addressLine3, tag: 'addr-line' },
1087
+ { value: affiliation.attrs.city, tag: 'city' },
1088
+ { value: affiliation.attrs.county, tag: 'state' },
1089
+ { value: affiliation.attrs.country, tag: 'country' },
1090
+ { value: affiliation.attrs.postCode, tag: 'postal-code' },
1091
+ ].filter((obj) => obj.value);
1092
+ affiliationParts.forEach((location, index) => {
1093
+ if (index) {
1094
+ const punctuation = this.document.createTextNode(', ');
1095
+ $aff.appendChild(punctuation);
1116
1096
  }
1097
+ const { tag, value, ...rest } = location;
1098
+ this.appendElement($aff, tag, value, rest);
1117
1099
  });
1118
- }
1100
+ const { href, text } = affiliation.attrs.email ?? {};
1101
+ if (href) {
1102
+ const email = this.appendElement($aff, 'email', text ?? href);
1103
+ email.setAttributeNS(XLINK_NAMESPACE, 'href', href);
1104
+ }
1105
+ contribGroup.appendChild($aff);
1106
+ });
1119
1107
  const authorNotesEl = this.createAuthorNotesElement();
1120
1108
  if (authorNotesEl.childNodes.length > 0) {
1121
1109
  articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
@@ -451,6 +451,8 @@ export class JATSDOMParser {
451
451
  addressLine3: this.getAddressLine(element, 3),
452
452
  postCode: getTrimmedTextContent(element, 'postal-code') ?? '',
453
453
  country: getTrimmedTextContent(element, 'country') ?? '',
454
+ county: getTrimmedTextContent(element, 'state') ?? '',
455
+ city: getTrimmedTextContent(element, 'city') ?? '',
454
456
  email: this.getEmail(element),
455
457
  priority: this.parsePriority(element.getAttribute('priority')),
456
458
  };
@@ -1 +1 @@
1
- export const VERSION = "4.3.13";
1
+ export const VERSION = "4.3.15";
@@ -1 +1 @@
1
- export declare const VERSION = "4.3.13";
1
+ export declare const VERSION = "4.3.15";
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": "4.3.13",
4
+ "version": "4.3.15",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",