@manuscripts/transform 2.1.1-LEAN-3336-14 → 2.1.1-LEAN-3336-16

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.
@@ -16,134 +16,89 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = exports.tableNodes = void 0;
19
+ const prosemirror_tables_1 = require("prosemirror-tables");
19
20
  const table_cell_styles_1 = require("../../lib/table-cell-styles");
20
- function getCellAttrs(dom, extraAttrs) {
21
- if (typeof dom === 'string') {
22
- return {};
21
+ const modifyTableCellSchema = (tableCell) => {
22
+ const modifiedTableCell = Object.assign({}, tableCell);
23
+ const originalToDOM = tableCell.toDOM;
24
+ if (!originalToDOM) {
25
+ throw new Error(`toDOM not found inside ${tableCell}, check for table schema changes in prosemirror-tables`);
23
26
  }
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;
27
+ modifiedTableCell.toDOM = function (node) {
28
+ const originalArray = originalToDOM.call(this, node);
29
+ if (!Array.isArray(originalArray)) {
30
+ throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
39
31
  }
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 = 'placeholder';
56
- }
57
- for (const prop in extraAttrs) {
58
- const setter = extraAttrs[prop].setDOMAttr;
59
- if (setter) {
60
- setter(node.attrs[prop], attrs);
32
+ const attrsIndex = originalArray.findIndex((item) => typeof item === 'object' && !Array.isArray(item));
33
+ const modifiedAttrs = Object.assign({}, originalArray[attrsIndex]);
34
+ if (!node.textContent) {
35
+ modifiedAttrs.class = 'placeholder';
61
36
  }
37
+ originalArray[attrsIndex] = modifiedAttrs;
38
+ return originalArray;
39
+ };
40
+ return modifiedTableCell;
41
+ };
42
+ const modifyTableToDOM = (modifiedTable) => {
43
+ const originalToDOM = modifiedTable.toDOM;
44
+ if (!originalToDOM) {
45
+ throw new Error(`toDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
62
46
  }
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 },
47
+ modifiedTable.toDOM = function (node) {
48
+ const originalArray = originalToDOM.call(this, node);
49
+ if (!Array.isArray(originalArray)) {
50
+ throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
51
+ }
52
+ const modifiedAttrs = {
53
+ id: node.attrs.id,
54
+ 'data-header-rows': String(node.attrs.headerRows),
55
+ 'data-footer-rows': String(node.attrs.footerRows),
56
+ };
57
+ if (Array.isArray(originalArray[1])) {
58
+ originalArray.splice(1, 0, modifiedAttrs);
59
+ }
60
+ else if (typeof originalArray[1] === 'object') {
61
+ originalArray[1] = Object.assign(Object.assign({}, originalArray[1]), modifiedAttrs);
62
+ }
63
+ else {
64
+ throw new Error(`toDOM[1] ${originalArray[1]} is of type ${typeof originalArray[1]}, check for table schema changes in prosemirror-tables`);
65
+ }
66
+ return originalArray;
71
67
  };
72
- for (const prop in extraAttrs) {
73
- cellAttrs[prop] = { default: extraAttrs[prop].default };
68
+ };
69
+ const modifyTableParseDOM = (modifiedTable) => {
70
+ if (!modifiedTable.parseDOM || !modifiedTable.parseDOM[0]) {
71
+ throw new Error(`parseDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
74
72
  }
75
- return {
76
- table: {
77
- content: 'table_row+',
78
- tableRole: 'table',
79
- isolating: true,
80
- attrs: {
81
- id: { default: '' },
82
- dataTracked: { default: null },
83
- comments: { default: null },
84
- headerRows: { default: 1 },
85
- footerRows: { default: 1 },
86
- },
87
- group: options.tableGroup,
88
- parseDOM: [
89
- {
90
- tag: 'table',
91
- getAttrs: (p) => {
92
- const dom = p;
93
- return {
94
- id: dom.getAttribute('id'),
95
- headerRows: dom.dataset && dom.dataset['header-rows'],
96
- footerRows: dom.dataset && dom.dataset['footer-rows'],
97
- };
98
- },
99
- },
100
- ],
101
- toDOM(node) {
102
- return [
103
- 'table',
104
- {
105
- id: node.attrs.id,
106
- 'data-header-rows': String(node.attrs.headerRows),
107
- 'data-footer-rows': String(node.attrs.footerRows),
108
- },
109
- ['tbody', 0],
110
- ];
111
- },
112
- },
113
- table_row: {
114
- content: '(table_cell | table_header)*',
115
- tableRole: 'row',
116
- parseDOM: [{ tag: 'tr' }],
117
- toDOM() {
118
- return ['tr', 0];
119
- },
120
- },
121
- table_cell: {
122
- content: options.cellContent,
123
- attrs: cellAttrs,
124
- tableRole: 'cell',
125
- isolating: true,
126
- parseDOM: [
127
- { tag: 'td', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
128
- ],
129
- toDOM(node) {
130
- return ['td', setCellAttrs(node, extraAttrs), 0];
131
- },
132
- },
133
- table_header: {
134
- content: options.cellContent,
135
- attrs: cellAttrs,
136
- tableRole: 'header_cell',
137
- isolating: true,
138
- parseDOM: [
139
- { tag: 'th', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
140
- ],
141
- toDOM(node) {
142
- return ['th', setCellAttrs(node, extraAttrs), 0];
143
- },
144
- },
73
+ const originalGetAttrs = modifiedTable.parseDOM[0].getAttrs;
74
+ let originalAttrs;
75
+ modifiedTable.parseDOM[0].getAttrs = function (p) {
76
+ const dom = p;
77
+ if (originalGetAttrs) {
78
+ originalAttrs = originalGetAttrs.call(this, p);
79
+ }
80
+ if (originalAttrs && typeof originalAttrs === 'object') {
81
+ return Object.assign(Object.assign({}, originalAttrs), { id: dom.getAttribute('id'), headerRows: dom.dataset && dom.dataset['header-rows'], footerRows: dom.dataset && dom.dataset['footer-rows'] });
82
+ }
83
+ else {
84
+ return {
85
+ id: dom.getAttribute('id'),
86
+ headerRows: dom.dataset && dom.dataset['header-rows'],
87
+ footerRows: dom.dataset && dom.dataset['footer-rows'],
88
+ };
89
+ }
145
90
  };
146
- }
91
+ };
92
+ const modifyTableAttrs = (modifiedTable, table) => {
93
+ modifiedTable.attrs = Object.assign(Object.assign({}, table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null }, headerRows: { default: 1 }, footerRows: { default: 1 } });
94
+ };
95
+ const modifyTableSchema = (table) => {
96
+ const modifiedTable = Object.assign({}, table);
97
+ modifyTableAttrs(modifiedTable, table);
98
+ modifyTableToDOM(modifiedTable);
99
+ modifyTableParseDOM(modifiedTable);
100
+ return modifiedTable;
101
+ };
147
102
  const tableOptions = {
148
103
  tableGroup: 'block',
149
104
  cellContent: 'inline*',
@@ -217,8 +172,8 @@ const tableOptions = {
217
172
  },
218
173
  },
219
174
  };
220
- exports.tableNodes = createTableNodes(tableOptions);
221
- exports.table = exports.tableNodes.table;
175
+ exports.tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
176
+ exports.table = modifyTableSchema(exports.tableNodes.table);
222
177
  exports.tableRow = exports.tableNodes.table_row;
223
- exports.tableCell = exports.tableNodes.table_cell;
224
- exports.tableHeader = exports.tableNodes.table_header;
178
+ exports.tableCell = modifyTableCellSchema(exports.tableNodes.table_cell);
179
+ exports.tableHeader = modifyTableCellSchema(exports.tableNodes.table_header);
@@ -13,134 +13,89 @@
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';
16
17
  import { getTableCellStyles, serializeTableCellStyles, } from '../../lib/table-cell-styles';
17
- function getCellAttrs(dom, extraAttrs) {
18
- if (typeof dom === 'string') {
19
- return {};
18
+ const modifyTableCellSchema = (tableCell) => {
19
+ const modifiedTableCell = Object.assign({}, tableCell);
20
+ const originalToDOM = tableCell.toDOM;
21
+ if (!originalToDOM) {
22
+ throw new Error(`toDOM not found inside ${tableCell}, check for table schema changes in prosemirror-tables`);
20
23
  }
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;
24
+ modifiedTableCell.toDOM = function (node) {
25
+ const originalArray = originalToDOM.call(this, node);
26
+ if (!Array.isArray(originalArray)) {
27
+ throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
36
28
  }
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 = 'placeholder';
53
- }
54
- for (const prop in extraAttrs) {
55
- const setter = extraAttrs[prop].setDOMAttr;
56
- if (setter) {
57
- setter(node.attrs[prop], attrs);
29
+ const attrsIndex = originalArray.findIndex((item) => typeof item === 'object' && !Array.isArray(item));
30
+ const modifiedAttrs = Object.assign({}, originalArray[attrsIndex]);
31
+ if (!node.textContent) {
32
+ modifiedAttrs.class = 'placeholder';
58
33
  }
34
+ originalArray[attrsIndex] = modifiedAttrs;
35
+ return originalArray;
36
+ };
37
+ return modifiedTableCell;
38
+ };
39
+ const modifyTableToDOM = (modifiedTable) => {
40
+ const originalToDOM = modifiedTable.toDOM;
41
+ if (!originalToDOM) {
42
+ throw new Error(`toDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
59
43
  }
60
- return attrs;
61
- }
62
- function createTableNodes(options) {
63
- const extraAttrs = options.cellAttributes || {};
64
- const cellAttrs = {
65
- colspan: { default: 1 },
66
- rowspan: { default: 1 },
67
- colwidth: { default: null },
44
+ modifiedTable.toDOM = function (node) {
45
+ const originalArray = originalToDOM.call(this, node);
46
+ if (!Array.isArray(originalArray)) {
47
+ throw new Error(`${originalArray} is of type ${typeof originalArray}, check for table schema changes in prosemirror-tables`);
48
+ }
49
+ const modifiedAttrs = {
50
+ id: node.attrs.id,
51
+ 'data-header-rows': String(node.attrs.headerRows),
52
+ 'data-footer-rows': String(node.attrs.footerRows),
53
+ };
54
+ if (Array.isArray(originalArray[1])) {
55
+ originalArray.splice(1, 0, modifiedAttrs);
56
+ }
57
+ else if (typeof originalArray[1] === 'object') {
58
+ originalArray[1] = Object.assign(Object.assign({}, originalArray[1]), modifiedAttrs);
59
+ }
60
+ else {
61
+ throw new Error(`toDOM[1] ${originalArray[1]} is of type ${typeof originalArray[1]}, check for table schema changes in prosemirror-tables`);
62
+ }
63
+ return originalArray;
68
64
  };
69
- for (const prop in extraAttrs) {
70
- cellAttrs[prop] = { default: extraAttrs[prop].default };
65
+ };
66
+ const modifyTableParseDOM = (modifiedTable) => {
67
+ if (!modifiedTable.parseDOM || !modifiedTable.parseDOM[0]) {
68
+ throw new Error(`parseDOM not found inside ${modifiedTable}, check for table schema changes in prosemirror-tables`);
71
69
  }
72
- return {
73
- table: {
74
- content: 'table_row+',
75
- tableRole: 'table',
76
- isolating: true,
77
- attrs: {
78
- id: { default: '' },
79
- dataTracked: { default: null },
80
- comments: { default: null },
81
- headerRows: { default: 1 },
82
- footerRows: { default: 1 },
83
- },
84
- group: options.tableGroup,
85
- parseDOM: [
86
- {
87
- tag: 'table',
88
- getAttrs: (p) => {
89
- const dom = p;
90
- return {
91
- id: dom.getAttribute('id'),
92
- headerRows: dom.dataset && dom.dataset['header-rows'],
93
- footerRows: dom.dataset && dom.dataset['footer-rows'],
94
- };
95
- },
96
- },
97
- ],
98
- toDOM(node) {
99
- return [
100
- 'table',
101
- {
102
- id: node.attrs.id,
103
- 'data-header-rows': String(node.attrs.headerRows),
104
- 'data-footer-rows': String(node.attrs.footerRows),
105
- },
106
- ['tbody', 0],
107
- ];
108
- },
109
- },
110
- table_row: {
111
- content: '(table_cell | table_header)*',
112
- tableRole: 'row',
113
- parseDOM: [{ tag: 'tr' }],
114
- toDOM() {
115
- return ['tr', 0];
116
- },
117
- },
118
- table_cell: {
119
- content: options.cellContent,
120
- attrs: cellAttrs,
121
- tableRole: 'cell',
122
- isolating: true,
123
- parseDOM: [
124
- { tag: 'td', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
125
- ],
126
- toDOM(node) {
127
- return ['td', setCellAttrs(node, extraAttrs), 0];
128
- },
129
- },
130
- table_header: {
131
- content: options.cellContent,
132
- attrs: cellAttrs,
133
- tableRole: 'header_cell',
134
- isolating: true,
135
- parseDOM: [
136
- { tag: 'th', getAttrs: (dom) => getCellAttrs(dom, extraAttrs) },
137
- ],
138
- toDOM(node) {
139
- return ['th', setCellAttrs(node, extraAttrs), 0];
140
- },
141
- },
70
+ const originalGetAttrs = modifiedTable.parseDOM[0].getAttrs;
71
+ let originalAttrs;
72
+ modifiedTable.parseDOM[0].getAttrs = function (p) {
73
+ const dom = p;
74
+ if (originalGetAttrs) {
75
+ originalAttrs = originalGetAttrs.call(this, p);
76
+ }
77
+ if (originalAttrs && typeof originalAttrs === 'object') {
78
+ return Object.assign(Object.assign({}, originalAttrs), { id: dom.getAttribute('id'), headerRows: dom.dataset && dom.dataset['header-rows'], footerRows: dom.dataset && dom.dataset['footer-rows'] });
79
+ }
80
+ else {
81
+ return {
82
+ id: dom.getAttribute('id'),
83
+ headerRows: dom.dataset && dom.dataset['header-rows'],
84
+ footerRows: dom.dataset && dom.dataset['footer-rows'],
85
+ };
86
+ }
142
87
  };
143
- }
88
+ };
89
+ const modifyTableAttrs = (modifiedTable, table) => {
90
+ modifiedTable.attrs = Object.assign(Object.assign({}, table.attrs), { id: { default: '' }, dataTracked: { default: null }, comments: { default: null }, headerRows: { default: 1 }, footerRows: { default: 1 } });
91
+ };
92
+ const modifyTableSchema = (table) => {
93
+ const modifiedTable = Object.assign({}, table);
94
+ modifyTableAttrs(modifiedTable, table);
95
+ modifyTableToDOM(modifiedTable);
96
+ modifyTableParseDOM(modifiedTable);
97
+ return modifiedTable;
98
+ };
144
99
  const tableOptions = {
145
100
  tableGroup: 'block',
146
101
  cellContent: 'inline*',
@@ -215,7 +170,7 @@ const tableOptions = {
215
170
  },
216
171
  };
217
172
  export const tableNodes = createTableNodes(tableOptions);
218
- export const table = tableNodes.table;
173
+ export const table = modifyTableSchema(tableNodes.table);
219
174
  export const tableRow = tableNodes.table_row;
220
- export const tableCell = tableNodes.table_cell;
221
- export const tableHeader = tableNodes.table_header;
175
+ export const tableCell = modifyTableCellSchema(tableNodes.table_cell);
176
+ export const tableHeader = modifyTableCellSchema(tableNodes.table_header);
@@ -13,9 +13,76 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { Node, NodeSpec } from 'prosemirror-model';
16
17
  import { TableNodes } from 'prosemirror-tables';
17
18
  export declare const tableNodes: TableNodes;
18
- export declare const table: import("prosemirror-model").NodeSpec;
19
- export declare const tableRow: import("prosemirror-model").NodeSpec;
20
- export declare const tableCell: import("prosemirror-model").NodeSpec;
21
- export declare const tableHeader: import("prosemirror-model").NodeSpec;
19
+ export declare const table: {
20
+ [x: string]: any;
21
+ content?: string | undefined;
22
+ marks?: string | undefined;
23
+ group?: string | undefined;
24
+ inline?: boolean | undefined;
25
+ atom?: boolean | undefined;
26
+ attrs?: {
27
+ [name: string]: import("prosemirror-model").AttributeSpec;
28
+ } | undefined;
29
+ selectable?: boolean | undefined;
30
+ draggable?: boolean | undefined;
31
+ code?: boolean | undefined;
32
+ whitespace?: "pre" | "normal" | undefined;
33
+ definingAsContext?: boolean | undefined;
34
+ definingForContent?: boolean | undefined;
35
+ defining?: boolean | undefined;
36
+ isolating?: boolean | undefined;
37
+ toDOM?: ((node: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
38
+ parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
39
+ toDebugString?: ((node: Node) => string) | undefined;
40
+ leafText?: ((node: Node) => string) | undefined;
41
+ };
42
+ export declare const tableRow: NodeSpec;
43
+ export declare const tableCell: {
44
+ [x: string]: any;
45
+ content?: string | undefined;
46
+ marks?: string | undefined;
47
+ group?: string | undefined;
48
+ inline?: boolean | undefined;
49
+ atom?: boolean | undefined;
50
+ attrs?: {
51
+ [name: string]: import("prosemirror-model").AttributeSpec;
52
+ } | undefined;
53
+ selectable?: boolean | undefined;
54
+ draggable?: boolean | undefined;
55
+ code?: boolean | undefined;
56
+ whitespace?: "pre" | "normal" | undefined;
57
+ definingAsContext?: boolean | undefined;
58
+ definingForContent?: boolean | undefined;
59
+ defining?: boolean | undefined;
60
+ isolating?: boolean | undefined;
61
+ toDOM?: ((node: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
62
+ parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
63
+ toDebugString?: ((node: Node) => string) | undefined;
64
+ leafText?: ((node: Node) => string) | undefined;
65
+ };
66
+ export declare const tableHeader: {
67
+ [x: string]: any;
68
+ content?: string | undefined;
69
+ marks?: string | undefined;
70
+ group?: string | undefined;
71
+ inline?: boolean | undefined;
72
+ atom?: boolean | undefined;
73
+ attrs?: {
74
+ [name: string]: import("prosemirror-model").AttributeSpec;
75
+ } | undefined;
76
+ selectable?: boolean | undefined;
77
+ draggable?: boolean | undefined;
78
+ code?: boolean | undefined;
79
+ whitespace?: "pre" | "normal" | undefined;
80
+ definingAsContext?: boolean | undefined;
81
+ definingForContent?: boolean | undefined;
82
+ defining?: boolean | undefined;
83
+ isolating?: boolean | undefined;
84
+ toDOM?: ((node: Node) => import("prosemirror-model").DOMOutputSpec) | undefined;
85
+ parseDOM?: readonly import("prosemirror-model").ParseRule[] | undefined;
86
+ toDebugString?: ((node: Node) => string) | undefined;
87
+ leafText?: ((node: Node) => string) | undefined;
88
+ };
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-14",
4
+ "version": "2.1.1-LEAN-3336-16",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",