@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3881.0

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.
@@ -149,6 +149,17 @@ const nodes = [
149
149
  node: 'figcaption',
150
150
  context: 'table_element/',
151
151
  },
152
+ {
153
+ tag: 'caption',
154
+ node: 'figcaption',
155
+ context: 'box_element/',
156
+ getAttrs: (node) => {
157
+ const element = node;
158
+ return {
159
+ id: element.getAttribute('id'),
160
+ };
161
+ },
162
+ },
152
163
  {
153
164
  tag: 'code',
154
165
  node: 'listing',
@@ -428,6 +439,18 @@ const nodes = [
428
439
  tag: 'sec[sec-type="backmatter"]',
429
440
  node: 'backmatter',
430
441
  },
442
+ {
443
+ tag: 'sec[sec-type="box-element"]',
444
+ node: 'box_element',
445
+ getAttrs: (node) => {
446
+ var _a;
447
+ const element = node;
448
+ return {
449
+ id: element.getAttribute('id'),
450
+ label: (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent,
451
+ };
452
+ },
453
+ },
431
454
  {
432
455
  tag: 'sec',
433
456
  node: 'section',
@@ -460,6 +483,11 @@ const nodes = [
460
483
  context: 'keyword_group//',
461
484
  node: 'keyword',
462
485
  },
486
+ {
487
+ tag: 'label',
488
+ context: 'box_element/',
489
+ ignore: true,
490
+ },
463
491
  {
464
492
  tag: 'label',
465
493
  context: 'section/',
@@ -156,6 +156,25 @@ exports.jatsBodyTransformations = {
156
156
  group.appendChild(sec);
157
157
  }
158
158
  },
159
+ createBoxedElementSection(doc, body, createElement) {
160
+ const boxedTexts = body.querySelectorAll('boxed-text');
161
+ for (const boxedText of boxedTexts) {
162
+ const boxElementSec = createElement('sec');
163
+ boxElementSec.setAttribute('sec-type', 'box-element');
164
+ const title = createElement('title');
165
+ title.textContent = 'BoxElement';
166
+ boxElementSec.append(title);
167
+ for (const element of [...boxedText.children]) {
168
+ if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
169
+ boxElementSec.append(element);
170
+ }
171
+ }
172
+ const containerSection = createElement('sec');
173
+ containerSection.append(...boxedText.children);
174
+ boxElementSec.append(containerSection);
175
+ boxedText.replaceWith(boxElementSec);
176
+ }
177
+ },
159
178
  createBody(doc, body, createElement) {
160
179
  const group = createSectionGroup(section_group_type_1.bodyType, createElement);
161
180
  this.wrapBodySections(doc, group);
@@ -221,7 +240,9 @@ exports.jatsBodyTransformations = {
221
240
  moveCaptionsToEnd(body) {
222
241
  const captions = body.querySelectorAll('caption');
223
242
  for (const caption of captions) {
224
- if (caption.parentNode && caption.parentNode.nodeName !== 'table-wrap') {
243
+ if (caption.parentNode &&
244
+ caption.parentNode.nodeName !== 'table-wrap' &&
245
+ caption.parentNode.nodeName !== 'boxed-text') {
225
246
  caption.parentNode.appendChild(caption);
226
247
  }
227
248
  }
@@ -60,6 +60,7 @@ const parseJATSBody = (doc, body, references) => {
60
60
  jats_body_transformations_1.jatsBodyTransformations.ensureSection(body, createElement);
61
61
  jats_body_transformations_1.jatsBodyTransformations.moveCaptionsToEnd(body);
62
62
  jats_body_transformations_1.jatsBodyTransformations.fixTables(body, createElement);
63
+ jats_body_transformations_1.jatsBodyTransformations.createBoxedElementSection(doc, body, createElement);
63
64
  jats_body_transformations_1.jatsBodyTransformations.createBody(doc, body, createElement);
64
65
  jats_body_transformations_1.jatsBodyTransformations.createAbstracts(doc, body, createElement);
65
66
  jats_body_transformations_1.jatsBodyTransformations.createBackmatter(doc, body, createElement);
@@ -596,7 +596,7 @@ class JATSExporter {
596
596
  const nodes = {
597
597
  award: () => '',
598
598
  awards: () => '',
599
- box_element: () => ['boxed-text', 0],
599
+ box_element: (node) => createBoxElement(node),
600
600
  author_notes: () => '',
601
601
  corresp: () => '',
602
602
  title: () => '',
@@ -948,6 +948,13 @@ class JATSExporter {
948
948
  }
949
949
  element.appendChild(table);
950
950
  };
951
+ const createBoxElement = (node) => {
952
+ const element = createElement(node, 'boxed-text');
953
+ appendLabels(element, node);
954
+ appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
955
+ processChildNodes(element, node, node.type.schema.nodes.section);
956
+ return element;
957
+ };
951
958
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
952
959
  const element = createElement(node, nodeName);
953
960
  if (figType) {
@@ -576,23 +576,38 @@ class Decoder {
576
576
  }
577
577
  const nestedSections = getSections(this.modelMap)
578
578
  .filter(hasParentSection(model._id))
579
+ .filter((s) => s.category !== 'MPSectionCategory:box-element')
579
580
  .map(this.creators[json_schema_1.ObjectTypes.Section]);
580
581
  const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
581
582
  const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
582
583
  const comments = this.createCommentNodes(model);
583
584
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
584
- const content = (sectionLabelNode
585
- ? [sectionLabelNode, sectionTitleNode]
586
- : [sectionTitleNode])
587
- .concat(elementNodes)
588
- .concat(nestedSections);
589
- const sectionNode = sectionNodeType.createAndFill({
585
+ let content = [];
586
+ if (sectionLabelNode &&
587
+ model.category !== 'MPSectionCategory:box-element') {
588
+ content.push(sectionLabelNode);
589
+ }
590
+ const attrs = {
590
591
  id: model._id,
591
592
  category: sectionCategory,
592
593
  titleSuppressed: model.titleSuppressed,
593
594
  pageBreakStyle: model.pageBreakStyle,
594
595
  generatedLabel: model.generatedLabel,
595
- }, content);
596
+ };
597
+ if (model.category === 'MPSectionCategory:box-element') {
598
+ const figCaption = this.getBoxElementFigCaption(model);
599
+ if (figCaption) {
600
+ content.push(figCaption);
601
+ }
602
+ if (model.label) {
603
+ attrs.label = model.label;
604
+ }
605
+ }
606
+ else {
607
+ content.push(sectionTitleNode);
608
+ }
609
+ content = content.concat(elementNodes).concat(nestedSections);
610
+ const sectionNode = sectionNodeType.createAndFill(attrs, content);
596
611
  if (!sectionNode) {
597
612
  console.error(model);
598
613
  throw new Error('Invalid content for section ' + model._id);
@@ -785,6 +800,15 @@ class Decoder {
785
800
  }
786
801
  }
787
802
  };
803
+ this.getBoxElementFigCaption = (model) => {
804
+ const titleNode = schema_1.schema.nodes.caption_title.create();
805
+ const captionTitle = model.title
806
+ ? this.parseContents(model.title, 'caption_title', this.getComments(model), {
807
+ topNode: titleNode,
808
+ })
809
+ : titleNode;
810
+ return schema_1.schema.nodes.figcaption.create({}, captionTitle);
811
+ };
788
812
  this.getFigcaption = (model) => {
789
813
  const titleNode = schema_1.schema.nodes.caption_title.create();
790
814
  const captionTitle = model.title
@@ -543,6 +543,16 @@ const encoders = {
543
543
  contents: (0, exports.inlineContents)(node),
544
544
  label: node.attrs.label,
545
545
  }),
546
+ box_element: (node, parent, path, priority) => ({
547
+ label: node.attrs.label,
548
+ priority: priority.value++,
549
+ path: path.concat([node.attrs.id]),
550
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
551
+ elementIDs: childElements(node)
552
+ .map((childNode) => childNode.attrs.id)
553
+ .filter((id) => id),
554
+ category: (0, section_category_1.buildSectionCategory)(node),
555
+ }),
546
556
  };
547
557
  const modelData = (node, parent, path, priority) => {
548
558
  const encoder = encoders[node.type.name];
@@ -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 = "2.3.37";
4
+ exports.VERSION = "2.3.38-LEAN-3881.0";
@@ -143,6 +143,17 @@ const nodes = [
143
143
  node: 'figcaption',
144
144
  context: 'table_element/',
145
145
  },
146
+ {
147
+ tag: 'caption',
148
+ node: 'figcaption',
149
+ context: 'box_element/',
150
+ getAttrs: (node) => {
151
+ const element = node;
152
+ return {
153
+ id: element.getAttribute('id'),
154
+ };
155
+ },
156
+ },
146
157
  {
147
158
  tag: 'code',
148
159
  node: 'listing',
@@ -422,6 +433,18 @@ const nodes = [
422
433
  tag: 'sec[sec-type="backmatter"]',
423
434
  node: 'backmatter',
424
435
  },
436
+ {
437
+ tag: 'sec[sec-type="box-element"]',
438
+ node: 'box_element',
439
+ getAttrs: (node) => {
440
+ var _a;
441
+ const element = node;
442
+ return {
443
+ id: element.getAttribute('id'),
444
+ label: (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent,
445
+ };
446
+ },
447
+ },
425
448
  {
426
449
  tag: 'sec',
427
450
  node: 'section',
@@ -454,6 +477,11 @@ const nodes = [
454
477
  context: 'keyword_group//',
455
478
  node: 'keyword',
456
479
  },
480
+ {
481
+ tag: 'label',
482
+ context: 'box_element/',
483
+ ignore: true,
484
+ },
457
485
  {
458
486
  tag: 'label',
459
487
  context: 'section/',
@@ -153,6 +153,25 @@ export const jatsBodyTransformations = {
153
153
  group.appendChild(sec);
154
154
  }
155
155
  },
156
+ createBoxedElementSection(doc, body, createElement) {
157
+ const boxedTexts = body.querySelectorAll('boxed-text');
158
+ for (const boxedText of boxedTexts) {
159
+ const boxElementSec = createElement('sec');
160
+ boxElementSec.setAttribute('sec-type', 'box-element');
161
+ const title = createElement('title');
162
+ title.textContent = 'BoxElement';
163
+ boxElementSec.append(title);
164
+ for (const element of [...boxedText.children]) {
165
+ if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
166
+ boxElementSec.append(element);
167
+ }
168
+ }
169
+ const containerSection = createElement('sec');
170
+ containerSection.append(...boxedText.children);
171
+ boxElementSec.append(containerSection);
172
+ boxedText.replaceWith(boxElementSec);
173
+ }
174
+ },
156
175
  createBody(doc, body, createElement) {
157
176
  const group = createSectionGroup(bodyType, createElement);
158
177
  this.wrapBodySections(doc, group);
@@ -218,7 +237,9 @@ export const jatsBodyTransformations = {
218
237
  moveCaptionsToEnd(body) {
219
238
  const captions = body.querySelectorAll('caption');
220
239
  for (const caption of captions) {
221
- if (caption.parentNode && caption.parentNode.nodeName !== 'table-wrap') {
240
+ if (caption.parentNode &&
241
+ caption.parentNode.nodeName !== 'table-wrap' &&
242
+ caption.parentNode.nodeName !== 'boxed-text') {
222
243
  caption.parentNode.appendChild(caption);
223
244
  }
224
245
  }
@@ -56,6 +56,7 @@ export const parseJATSBody = (doc, body, references) => {
56
56
  jatsBodyTransformations.ensureSection(body, createElement);
57
57
  jatsBodyTransformations.moveCaptionsToEnd(body);
58
58
  jatsBodyTransformations.fixTables(body, createElement);
59
+ jatsBodyTransformations.createBoxedElementSection(doc, body, createElement);
59
60
  jatsBodyTransformations.createBody(doc, body, createElement);
60
61
  jatsBodyTransformations.createAbstracts(doc, body, createElement);
61
62
  jatsBodyTransformations.createBackmatter(doc, body, createElement);
@@ -588,7 +588,7 @@ export class JATSExporter {
588
588
  const nodes = {
589
589
  award: () => '',
590
590
  awards: () => '',
591
- box_element: () => ['boxed-text', 0],
591
+ box_element: (node) => createBoxElement(node),
592
592
  author_notes: () => '',
593
593
  corresp: () => '',
594
594
  title: () => '',
@@ -940,6 +940,13 @@ export class JATSExporter {
940
940
  }
941
941
  element.appendChild(table);
942
942
  };
943
+ const createBoxElement = (node) => {
944
+ const element = createElement(node, 'boxed-text');
945
+ appendLabels(element, node);
946
+ appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
947
+ processChildNodes(element, node, node.type.schema.nodes.section);
948
+ return element;
949
+ };
943
950
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
944
951
  const element = createElement(node, nodeName);
945
952
  if (figType) {
@@ -567,23 +567,38 @@ export class Decoder {
567
567
  }
568
568
  const nestedSections = getSections(this.modelMap)
569
569
  .filter(hasParentSection(model._id))
570
+ .filter((s) => s.category !== 'MPSectionCategory:box-element')
570
571
  .map(this.creators[ObjectTypes.Section]);
571
572
  const sectionCategory = model.category || guessSectionCategory(elements);
572
573
  const sectionNodeType = chooseSectionNodeType(sectionCategory);
573
574
  const comments = this.createCommentNodes(model);
574
575
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
575
- const content = (sectionLabelNode
576
- ? [sectionLabelNode, sectionTitleNode]
577
- : [sectionTitleNode])
578
- .concat(elementNodes)
579
- .concat(nestedSections);
580
- const sectionNode = sectionNodeType.createAndFill({
576
+ let content = [];
577
+ if (sectionLabelNode &&
578
+ model.category !== 'MPSectionCategory:box-element') {
579
+ content.push(sectionLabelNode);
580
+ }
581
+ const attrs = {
581
582
  id: model._id,
582
583
  category: sectionCategory,
583
584
  titleSuppressed: model.titleSuppressed,
584
585
  pageBreakStyle: model.pageBreakStyle,
585
586
  generatedLabel: model.generatedLabel,
586
- }, content);
587
+ };
588
+ if (model.category === 'MPSectionCategory:box-element') {
589
+ const figCaption = this.getBoxElementFigCaption(model);
590
+ if (figCaption) {
591
+ content.push(figCaption);
592
+ }
593
+ if (model.label) {
594
+ attrs.label = model.label;
595
+ }
596
+ }
597
+ else {
598
+ content.push(sectionTitleNode);
599
+ }
600
+ content = content.concat(elementNodes).concat(nestedSections);
601
+ const sectionNode = sectionNodeType.createAndFill(attrs, content);
587
602
  if (!sectionNode) {
588
603
  console.error(model);
589
604
  throw new Error('Invalid content for section ' + model._id);
@@ -776,6 +791,15 @@ export class Decoder {
776
791
  }
777
792
  }
778
793
  };
794
+ this.getBoxElementFigCaption = (model) => {
795
+ const titleNode = schema.nodes.caption_title.create();
796
+ const captionTitle = model.title
797
+ ? this.parseContents(model.title, 'caption_title', this.getComments(model), {
798
+ topNode: titleNode,
799
+ })
800
+ : titleNode;
801
+ return schema.nodes.figcaption.create({}, captionTitle);
802
+ };
779
803
  this.getFigcaption = (model) => {
780
804
  const titleNode = schema.nodes.caption_title.create();
781
805
  const captionTitle = model.title
@@ -535,6 +535,16 @@ const encoders = {
535
535
  contents: inlineContents(node),
536
536
  label: node.attrs.label,
537
537
  }),
538
+ box_element: (node, parent, path, priority) => ({
539
+ label: node.attrs.label,
540
+ priority: priority.value++,
541
+ path: path.concat([node.attrs.id]),
542
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
543
+ elementIDs: childElements(node)
544
+ .map((childNode) => childNode.attrs.id)
545
+ .filter((id) => id),
546
+ category: buildSectionCategory(node),
547
+ }),
538
548
  };
539
549
  const modelData = (node, parent, path, priority) => {
540
550
  const encoder = encoders[node.type.name];
@@ -1 +1 @@
1
- export const VERSION = "2.3.37";
1
+ export const VERSION = "2.3.38-LEAN-3881.0";
@@ -25,6 +25,7 @@ export declare const jatsBodyTransformations: {
25
25
  moveBackSections(doc: Document, group: Element): void;
26
26
  moveAcknowledgments(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
27
27
  moveAppendices(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
28
+ createBoxedElementSection(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
28
29
  createBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
29
30
  createAbstracts(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
30
31
  createBackmatter(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
@@ -43,6 +43,7 @@ export declare class Decoder {
43
43
  parseContents: (contents: string, wrapper?: string, commentAnnotations?: CommentAnnotation[], options?: ParseOptions) => ManuscriptNode;
44
44
  private getManuscriptID;
45
45
  private getManuscript;
46
+ private getBoxElementFigCaption;
46
47
  private getFigcaption;
47
48
  private createTable;
48
49
  private createTableColGroup;
@@ -1 +1 @@
1
- export declare const VERSION = "2.3.37";
1
+ export declare const VERSION = "2.3.38-LEAN-3881.0";
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.3.37",
4
+ "version": "2.3.38-LEAN-3881.0",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",