@manuscripts/transform 3.0.29 → 3.0.30

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.
@@ -544,7 +544,7 @@ class JATSExporter {
544
544
  this.createSerializer = () => {
545
545
  const nodes = {
546
546
  image_element: (node) => node.content.firstChild
547
- ? this.serializeNode(node.content.firstChild)
547
+ ? createGraphic(node.content.firstChild, false)
548
548
  : '',
549
549
  embed: (node) => {
550
550
  const mediaElement = this.document.createElement('media');
@@ -913,17 +913,18 @@ class JATSExporter {
913
913
  processChildNodes(element, node, node.type.schema.nodes.section);
914
914
  return element;
915
915
  };
916
- const createGraphic = (node) => {
916
+ const createGraphic = (node, isChildOfFigure = true) => {
917
917
  const graphic = this.document.createElement('graphic');
918
918
  graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
919
- if (node.attrs.contentType) {
920
- graphic.setAttribute('content-type', node.attrs.contentType);
919
+ if (!isChildOfFigure && node.attrs.type) {
920
+ graphic.setAttribute('content-type', node.attrs.type);
921
921
  }
922
922
  return graphic;
923
923
  };
924
924
  const createFigureElement = (node, contentNodeType) => {
925
925
  const element = createElement(node, 'fig');
926
- const figType = node.attrs.type;
926
+ const figNode = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.figure)[0];
927
+ const figType = figNode === null || figNode === void 0 ? void 0 : figNode.node.attrs.type;
927
928
  if (figType) {
928
929
  element.setAttribute('fig-type', figType);
929
930
  }
@@ -101,10 +101,12 @@ class JATSDOMParser {
101
101
  }
102
102
  };
103
103
  this.getFigureAttrs = (node) => {
104
+ var _a, _b;
104
105
  const element = node;
106
+ const parentElement = element.parentElement;
105
107
  return {
106
108
  id: element.getAttribute('id'),
107
- contentType: element.getAttribute('content-type'),
109
+ type: (_b = (_a = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('fig-type')) !== null && _a !== void 0 ? _a : element.getAttribute('content-type')) !== null && _b !== void 0 ? _b : '',
108
110
  src: element.getAttributeNS(this.XLINK_NAMESPACE, 'href'),
109
111
  };
110
112
  };
@@ -606,7 +608,6 @@ class JATSDOMParser {
606
608
  return {
607
609
  id: element.getAttribute('id'),
608
610
  attribution,
609
- type: element.getAttribute('fig-type'),
610
611
  };
611
612
  },
612
613
  },
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2025 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
+ class Migration3030 {
19
+ constructor() {
20
+ this.fromVersion = '3.0.29';
21
+ this.toVersion = '3.0.30';
22
+ }
23
+ addTypeToFigures(node, type) {
24
+ if (!Array.isArray(node.content)) {
25
+ return node.content;
26
+ }
27
+ return node.content.map((child) => child.type === 'figure'
28
+ ? Object.assign(Object.assign({}, child), { attrs: Object.assign(Object.assign({}, child.attrs), { type }) }) : child);
29
+ }
30
+ migrateFigure(node) {
31
+ const type = node.attrs.contentType || node.attrs.type || '';
32
+ if (node.attrs.contentType) {
33
+ delete node.attrs.contentType;
34
+ }
35
+ return Object.assign(Object.assign({}, node), { attrs: Object.assign(Object.assign({}, node.attrs), { type }) });
36
+ }
37
+ migrateFigureElement(node) {
38
+ const newContent = this.addTypeToFigures(node, node.attrs.type || '');
39
+ if (node.attrs.type) {
40
+ delete node.attrs.type;
41
+ }
42
+ return Object.assign(Object.assign({}, node), { content: newContent, attrs: Object.assign({}, node.attrs) });
43
+ }
44
+ migrateNode(node) {
45
+ if (node.type === 'figure') {
46
+ return this.migrateFigure(node);
47
+ }
48
+ if (node.type === 'figure_element') {
49
+ return this.migrateFigureElement(node);
50
+ }
51
+ return node;
52
+ }
53
+ }
54
+ exports.default = Migration3030;
@@ -22,10 +22,12 @@ const _1_2_5_1 = __importDefault(require("./1.2.5"));
22
22
  const _2_3_22_1 = __importDefault(require("./2.3.22"));
23
23
  const _3_0_12_1 = require("./3.0.12");
24
24
  const _3_0_21_1 = __importDefault(require("./3.0.21"));
25
+ const _3_0_30_1 = __importDefault(require("./3.0.30"));
25
26
  const migrations = [
26
27
  new _1_2_5_1.default(),
27
28
  new _2_3_22_1.default(),
28
29
  new _3_0_12_1.Migration3012(),
29
30
  new _3_0_21_1.default(),
31
+ new _3_0_30_1.default(),
30
32
  ];
31
33
  exports.default = migrations;
@@ -20,7 +20,7 @@ exports.figure = {
20
20
  attrs: {
21
21
  id: { default: '' },
22
22
  src: { default: '' },
23
- contentType: { default: '' },
23
+ type: { default: '' },
24
24
  dataTracked: { default: null },
25
25
  },
26
26
  selectable: false,
@@ -22,7 +22,6 @@ exports.figureElement = {
22
22
  id: { default: '' },
23
23
  attribution: { default: undefined },
24
24
  dataTracked: { default: null },
25
- type: { default: undefined },
26
25
  },
27
26
  selectable: false,
28
27
  group: 'block element executable',
@@ -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.29";
4
+ exports.VERSION = "3.0.30";
@@ -536,7 +536,7 @@ export class JATSExporter {
536
536
  this.createSerializer = () => {
537
537
  const nodes = {
538
538
  image_element: (node) => node.content.firstChild
539
- ? this.serializeNode(node.content.firstChild)
539
+ ? createGraphic(node.content.firstChild, false)
540
540
  : '',
541
541
  embed: (node) => {
542
542
  const mediaElement = this.document.createElement('media');
@@ -905,17 +905,18 @@ export class JATSExporter {
905
905
  processChildNodes(element, node, node.type.schema.nodes.section);
906
906
  return element;
907
907
  };
908
- const createGraphic = (node) => {
908
+ const createGraphic = (node, isChildOfFigure = true) => {
909
909
  const graphic = this.document.createElement('graphic');
910
910
  graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
911
- if (node.attrs.contentType) {
912
- graphic.setAttribute('content-type', node.attrs.contentType);
911
+ if (!isChildOfFigure && node.attrs.type) {
912
+ graphic.setAttribute('content-type', node.attrs.type);
913
913
  }
914
914
  return graphic;
915
915
  };
916
916
  const createFigureElement = (node, contentNodeType) => {
917
917
  const element = createElement(node, 'fig');
918
- const figType = node.attrs.type;
918
+ const figNode = findChildrenByType(node, node.type.schema.nodes.figure)[0];
919
+ const figType = figNode === null || figNode === void 0 ? void 0 : figNode.node.attrs.type;
919
920
  if (figType) {
920
921
  element.setAttribute('fig-type', figType);
921
922
  }
@@ -98,10 +98,12 @@ export class JATSDOMParser {
98
98
  }
99
99
  };
100
100
  this.getFigureAttrs = (node) => {
101
+ var _a, _b;
101
102
  const element = node;
103
+ const parentElement = element.parentElement;
102
104
  return {
103
105
  id: element.getAttribute('id'),
104
- contentType: element.getAttribute('content-type'),
106
+ type: (_b = (_a = parentElement === null || parentElement === void 0 ? void 0 : parentElement.getAttribute('fig-type')) !== null && _a !== void 0 ? _a : element.getAttribute('content-type')) !== null && _b !== void 0 ? _b : '',
105
107
  src: element.getAttributeNS(this.XLINK_NAMESPACE, 'href'),
106
108
  };
107
109
  };
@@ -603,7 +605,6 @@ export class JATSDOMParser {
603
605
  return {
604
606
  id: element.getAttribute('id'),
605
607
  attribution,
606
- type: element.getAttribute('fig-type'),
607
608
  };
608
609
  },
609
610
  },
@@ -0,0 +1,52 @@
1
+ /*!
2
+ * © 2025 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
+ class Migration3030 {
17
+ constructor() {
18
+ this.fromVersion = '3.0.29';
19
+ this.toVersion = '3.0.30';
20
+ }
21
+ addTypeToFigures(node, type) {
22
+ if (!Array.isArray(node.content)) {
23
+ return node.content;
24
+ }
25
+ return node.content.map((child) => child.type === 'figure'
26
+ ? Object.assign(Object.assign({}, child), { attrs: Object.assign(Object.assign({}, child.attrs), { type }) }) : child);
27
+ }
28
+ migrateFigure(node) {
29
+ const type = node.attrs.contentType || node.attrs.type || '';
30
+ if (node.attrs.contentType) {
31
+ delete node.attrs.contentType;
32
+ }
33
+ return Object.assign(Object.assign({}, node), { attrs: Object.assign(Object.assign({}, node.attrs), { type }) });
34
+ }
35
+ migrateFigureElement(node) {
36
+ const newContent = this.addTypeToFigures(node, node.attrs.type || '');
37
+ if (node.attrs.type) {
38
+ delete node.attrs.type;
39
+ }
40
+ return Object.assign(Object.assign({}, node), { content: newContent, attrs: Object.assign({}, node.attrs) });
41
+ }
42
+ migrateNode(node) {
43
+ if (node.type === 'figure') {
44
+ return this.migrateFigure(node);
45
+ }
46
+ if (node.type === 'figure_element') {
47
+ return this.migrateFigureElement(node);
48
+ }
49
+ return node;
50
+ }
51
+ }
52
+ export default Migration3030;
@@ -17,10 +17,12 @@ import Migration125 from './1.2.5';
17
17
  import Migration2322 from './2.3.22';
18
18
  import { Migration3012 } from './3.0.12';
19
19
  import Migration3021 from './3.0.21';
20
+ import Migration3030 from './3.0.30';
20
21
  const migrations = [
21
22
  new Migration125(),
22
23
  new Migration2322(),
23
24
  new Migration3012(),
24
25
  new Migration3021(),
26
+ new Migration3030(),
25
27
  ];
26
28
  export default migrations;
@@ -17,7 +17,7 @@ export const figure = {
17
17
  attrs: {
18
18
  id: { default: '' },
19
19
  src: { default: '' },
20
- contentType: { default: '' },
20
+ type: { default: '' },
21
21
  dataTracked: { default: null },
22
22
  },
23
23
  selectable: false,
@@ -19,7 +19,6 @@ export const figureElement = {
19
19
  id: { default: '' },
20
20
  attribution: { default: undefined },
21
21
  dataTracked: { default: null },
22
- type: { default: undefined },
23
22
  },
24
23
  selectable: false,
25
24
  group: 'block element executable',
@@ -1 +1 @@
1
- export const VERSION = "3.0.29";
1
+ export const VERSION = "3.0.30";
@@ -0,0 +1,26 @@
1
+ /*!
2
+ * © 2025 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 { JSONNode } from '../migrate';
17
+ import { MigrationScript } from '../migration-script';
18
+ declare class Migration3030 implements MigrationScript {
19
+ fromVersion: string;
20
+ toVersion: string;
21
+ private addTypeToFigures;
22
+ private migrateFigure;
23
+ private migrateFigureElement;
24
+ migrateNode(node: JSONNode): JSONNode;
25
+ }
26
+ export default Migration3030;
@@ -17,5 +17,6 @@ import Migration125 from './1.2.5';
17
17
  import Migration2322 from './2.3.22';
18
18
  import { Migration3012 } from './3.0.12';
19
19
  import Migration3021 from './3.0.21';
20
- declare const migrations: (Migration125 | Migration2322 | Migration3012 | Migration3021)[];
20
+ import Migration3030 from './3.0.30';
21
+ declare const migrations: (Migration125 | Migration2322 | Migration3012 | Migration3021 | Migration3030)[];
21
22
  export default migrations;
@@ -19,7 +19,7 @@ export interface FigureNode extends ManuscriptNode {
19
19
  attrs: {
20
20
  id: string;
21
21
  src: string;
22
- contentType: string;
22
+ type: string;
23
23
  };
24
24
  }
25
25
  export declare const figure: NodeSpec;
@@ -19,7 +19,6 @@ import { AttributionNode } from './attribution';
19
19
  interface Attrs {
20
20
  id: string;
21
21
  attribution?: AttributionNode;
22
- type?: string;
23
22
  }
24
23
  export interface FigureElementNode extends ManuscriptNode {
25
24
  attrs: Attrs;
@@ -1 +1 @@
1
- export declare const VERSION = "3.0.29";
1
+ export declare const VERSION = "3.0.30";
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.29",
4
+ "version": "3.0.30",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",