@manuscripts/transform 2.1.1-LEAN-3336-8 → 2.1.1-LEAN-3336-10

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.
@@ -967,7 +967,7 @@ class JATSExporter {
967
967
  return;
968
968
  }
969
969
  const table = this.serializeNode(tableNode);
970
- const tbodyElement = document.createElement('tbody');
970
+ const tbodyElement = this.document.createElement('tbody');
971
971
  while (table.firstChild) {
972
972
  const child = table.firstChild;
973
973
  table.removeChild(child);
@@ -15,9 +15,109 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableHeader = exports.tableRow = exports.tableCell = exports.table = exports.tableNodes = void 0;
19
- const prosemirror_tables_1 = require("prosemirror-tables");
18
+ exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = exports.tableNodes = exports.createTableNodes = void 0;
20
19
  const table_cell_styles_1 = require("../../lib/table-cell-styles");
20
+ function getCellAttrs(dom, extraAttrs) {
21
+ if (typeof dom === 'string') {
22
+ return {};
23
+ }
24
+ const widthAttr = dom.getAttribute('data-colwidth');
25
+ const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
26
+ ? widthAttr.split(',').map((s) => Number(s))
27
+ : null;
28
+ const colspan = Number(dom.getAttribute('colspan') || 1);
29
+ const result = {
30
+ colspan,
31
+ rowspan: Number(dom.getAttribute('rowspan') || 1),
32
+ colwidth: widths && widths.length == colspan ? widths : null,
33
+ };
34
+ for (const prop in extraAttrs) {
35
+ const getter = extraAttrs[prop].getFromDOM;
36
+ const value = getter && getter(dom);
37
+ if (value != null) {
38
+ result[prop] = value;
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ function setCellAttrs(node, extraAttrs) {
44
+ const attrs = {};
45
+ if (node.attrs.colspan != 1) {
46
+ attrs.colspan = node.attrs.colspan;
47
+ }
48
+ if (node.attrs.rowspan != 1) {
49
+ attrs.rowspan = node.attrs.rowspan;
50
+ }
51
+ if (node.attrs.colwidth) {
52
+ attrs['data-colwidth'] = node.attrs.colwidth.join(',');
53
+ }
54
+ if (node.textContent) {
55
+ attrs.class = 'palceholder';
56
+ }
57
+ for (const prop in extraAttrs) {
58
+ const setter = extraAttrs[prop].setDOMAttr;
59
+ if (setter) {
60
+ setter(node.attrs[prop], attrs);
61
+ }
62
+ }
63
+ return attrs;
64
+ }
65
+ function createTableNodes(options) {
66
+ const extraAttrs = options.cellAttributes || {};
67
+ const cellAttrs = {
68
+ colspan: { default: 1 },
69
+ rowspan: { default: 1 },
70
+ colwidth: { default: null },
71
+ };
72
+ for (const prop in extraAttrs) {
73
+ cellAttrs[prop] = { default: extraAttrs[prop].default };
74
+ }
75
+ return {
76
+ table: {
77
+ content: 'table_row+',
78
+ tableRole: 'table',
79
+ isolating: true,
80
+ group: options.tableGroup,
81
+ parseDOM: [{ tag: 'table' }],
82
+ toDOM() {
83
+ return ['table', ['tbody', 0]];
84
+ },
85
+ },
86
+ table_row: {
87
+ content: '(table_cell | table_header)*',
88
+ tableRole: 'row',
89
+ parseDOM: [{ tag: 'tr' }],
90
+ toDOM() {
91
+ return ['tr', 0];
92
+ },
93
+ },
94
+ table_cell: {
95
+ content: options.cellContent,
96
+ attrs: cellAttrs,
97
+ tableRole: 'cell',
98
+ isolating: true,
99
+ parseDOM: [
100
+ { tag: 'td', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
101
+ ],
102
+ toDOM(node) {
103
+ return ['td', setCellAttrs(node, extraAttrs), 0];
104
+ },
105
+ },
106
+ table_header: {
107
+ content: options.cellContent,
108
+ attrs: cellAttrs,
109
+ tableRole: 'header_cell',
110
+ isolating: true,
111
+ parseDOM: [
112
+ { tag: 'th', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
113
+ ],
114
+ toDOM(node) {
115
+ return ['th', setCellAttrs(node, extraAttrs), 0];
116
+ },
117
+ },
118
+ };
119
+ }
120
+ exports.createTableNodes = createTableNodes;
21
121
  const tableOptions = {
22
122
  tableGroup: 'block',
23
123
  cellContent: 'inline*',
@@ -45,6 +145,14 @@ const tableOptions = {
45
145
  }
46
146
  },
47
147
  },
148
+ class: {
149
+ default: null,
150
+ setDOMAttr(value, attrs) {
151
+ if (value) {
152
+ attrs['class'] = value;
153
+ }
154
+ },
155
+ },
48
156
  valign: {
49
157
  default: null,
50
158
  getFromDOM(dom) {
@@ -91,8 +199,8 @@ const tableOptions = {
91
199
  },
92
200
  },
93
201
  };
94
- exports.tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
202
+ exports.tableNodes = createTableNodes(tableOptions);
95
203
  exports.table = Object.assign(Object.assign({}, exports.tableNodes.table), { attrs: Object.assign(Object.assign({}, exports.tableNodes.table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null } }) });
96
- exports.tableCell = exports.tableNodes.table_cell;
97
204
  exports.tableRow = exports.tableNodes.table_row;
205
+ exports.tableCell = exports.tableNodes.table_cell;
98
206
  exports.tableHeader = exports.tableNodes.table_header;
@@ -796,11 +796,12 @@ class Decoder {
796
796
  createTableColGroup(model) {
797
797
  const tableId = model.containedObjectID;
798
798
  const tableModel = this.getModel(tableId);
799
- if (tableModel) {
800
- return this.parseContents(tableModel.contents, undefined, [], {
801
- topNode: schema_1.schema.nodes.table_colgroup.create(),
802
- });
799
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
800
+ return undefined;
803
801
  }
802
+ return this.parseContents(tableModel.contents, undefined, [], {
803
+ topNode: schema_1.schema.nodes.table_colgroup.create(),
804
+ });
804
805
  }
805
806
  createTableElementFooter(model) {
806
807
  const tableElementFooterID = model.tableElementFooterID;
@@ -959,7 +959,7 @@ export class JATSExporter {
959
959
  return;
960
960
  }
961
961
  const table = this.serializeNode(tableNode);
962
- const tbodyElement = document.createElement('tbody');
962
+ const tbodyElement = this.document.createElement('tbody');
963
963
  while (table.firstChild) {
964
964
  const child = table.firstChild;
965
965
  table.removeChild(child);
@@ -13,8 +13,107 @@
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
16
  import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
17
+ function getCellAttrs(dom, extraAttrs) {
18
+ if (typeof dom === 'string') {
19
+ return {};
20
+ }
21
+ const widthAttr = dom.getAttribute('data-colwidth');
22
+ const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr)
23
+ ? widthAttr.split(',').map((s) => Number(s))
24
+ : null;
25
+ const colspan = Number(dom.getAttribute('colspan') || 1);
26
+ const result = {
27
+ colspan,
28
+ rowspan: Number(dom.getAttribute('rowspan') || 1),
29
+ colwidth: widths && widths.length == colspan ? widths : null,
30
+ };
31
+ for (const prop in extraAttrs) {
32
+ const getter = extraAttrs[prop].getFromDOM;
33
+ const value = getter && getter(dom);
34
+ if (value != null) {
35
+ result[prop] = value;
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+ function setCellAttrs(node, extraAttrs) {
41
+ const attrs = {};
42
+ if (node.attrs.colspan != 1) {
43
+ attrs.colspan = node.attrs.colspan;
44
+ }
45
+ if (node.attrs.rowspan != 1) {
46
+ attrs.rowspan = node.attrs.rowspan;
47
+ }
48
+ if (node.attrs.colwidth) {
49
+ attrs['data-colwidth'] = node.attrs.colwidth.join(',');
50
+ }
51
+ if (node.textContent) {
52
+ attrs.class = 'palceholder';
53
+ }
54
+ for (const prop in extraAttrs) {
55
+ const setter = extraAttrs[prop].setDOMAttr;
56
+ if (setter) {
57
+ setter(node.attrs[prop], attrs);
58
+ }
59
+ }
60
+ return attrs;
61
+ }
62
+ export function createTableNodes(options) {
63
+ const extraAttrs = options.cellAttributes || {};
64
+ const cellAttrs = {
65
+ colspan: { default: 1 },
66
+ rowspan: { default: 1 },
67
+ colwidth: { default: null },
68
+ };
69
+ for (const prop in extraAttrs) {
70
+ cellAttrs[prop] = { default: extraAttrs[prop].default };
71
+ }
72
+ return {
73
+ table: {
74
+ content: 'table_row+',
75
+ tableRole: 'table',
76
+ isolating: true,
77
+ group: options.tableGroup,
78
+ parseDOM: [{ tag: 'table' }],
79
+ toDOM() {
80
+ return ['table', ['tbody', 0]];
81
+ },
82
+ },
83
+ table_row: {
84
+ content: '(table_cell | table_header)*',
85
+ tableRole: 'row',
86
+ parseDOM: [{ tag: 'tr' }],
87
+ toDOM() {
88
+ return ['tr', 0];
89
+ },
90
+ },
91
+ table_cell: {
92
+ content: options.cellContent,
93
+ attrs: cellAttrs,
94
+ tableRole: 'cell',
95
+ isolating: true,
96
+ parseDOM: [
97
+ { tag: 'td', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
98
+ ],
99
+ toDOM(node) {
100
+ return ['td', setCellAttrs(node, extraAttrs), 0];
101
+ },
102
+ },
103
+ table_header: {
104
+ content: options.cellContent,
105
+ attrs: cellAttrs,
106
+ tableRole: 'header_cell',
107
+ isolating: true,
108
+ parseDOM: [
109
+ { tag: 'th', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
110
+ ],
111
+ toDOM(node) {
112
+ return ['th', setCellAttrs(node, extraAttrs), 0];
113
+ },
114
+ },
115
+ };
116
+ }
18
117
  const tableOptions = {
19
118
  tableGroup: 'block',
20
119
  cellContent: 'inline*',
@@ -42,6 +141,14 @@ const tableOptions = {
42
141
  }
43
142
  },
44
143
  },
144
+ class: {
145
+ default: null,
146
+ setDOMAttr(value, attrs) {
147
+ if (value) {
148
+ attrs['class'] = value;
149
+ }
150
+ },
151
+ },
45
152
  valign: {
46
153
  default: null,
47
154
  getFromDOM(dom) {
@@ -90,6 +197,6 @@ const tableOptions = {
90
197
  };
91
198
  export const tableNodes = createTableNodes(tableOptions);
92
199
  export const table = Object.assign(Object.assign({}, tableNodes.table), { attrs: Object.assign(Object.assign({}, tableNodes.table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null } }) });
93
- export const tableCell = tableNodes.table_cell;
94
200
  export const tableRow = tableNodes.table_row;
201
+ export const tableCell = tableNodes.table_cell;
95
202
  export const tableHeader = tableNodes.table_header;
@@ -787,11 +787,12 @@ export class Decoder {
787
787
  createTableColGroup(model) {
788
788
  const tableId = model.containedObjectID;
789
789
  const tableModel = this.getModel(tableId);
790
- if (tableModel) {
791
- return this.parseContents(tableModel.contents, undefined, [], {
792
- topNode: schema.nodes.table_colgroup.create(),
793
- });
790
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
791
+ return undefined;
794
792
  }
793
+ return this.parseContents(tableModel.contents, undefined, [], {
794
+ topNode: schema.nodes.table_colgroup.create(),
795
+ });
795
796
  }
796
797
  createTableElementFooter(model) {
797
798
  const tableElementFooterID = model.tableElementFooterID;
@@ -13,7 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { TableNodes } from 'prosemirror-tables';
16
+ import { Node } from 'prosemirror-model';
17
+ import { TableNodes, TableNodesOptions } from 'prosemirror-tables';
18
+ export declare function createTableNodes(options: TableNodesOptions): TableNodes;
17
19
  export declare const tableNodes: TableNodes;
18
20
  export declare const table: {
19
21
  attrs: {
@@ -40,11 +42,11 @@ export declare const table: {
40
42
  definingForContent?: boolean | undefined;
41
43
  defining?: boolean | undefined;
42
44
  isolating?: boolean | undefined;
43
- toDOM?: ((node: import("prosemirror-model").Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
45
+ toDOM?: ((node: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
44
46
  parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
45
- toDebugString?: ((node: import("prosemirror-model").Node) => string) | undefined;
46
- leafText?: ((node: import("prosemirror-model").Node) => string) | undefined;
47
+ toDebugString?: ((node: Node) => string) | undefined;
48
+ leafText?: ((node: Node) => string) | undefined;
47
49
  };
48
- export declare const tableCell: import("prosemirror-model").NodeSpec;
49
50
  export declare const tableRow: import("prosemirror-model").NodeSpec;
51
+ export declare const tableCell: import("prosemirror-model").NodeSpec;
50
52
  export declare const tableHeader: import("prosemirror-model").NodeSpec;
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.1-LEAN-3336-8",
4
+ "version": "2.1.1-LEAN-3336-10",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",