@manuscripts/transform 2.1.1-LEAN-3336-9 → 2.1.1-LEAN-3336-11

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.
@@ -15,9 +15,109 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableCell = exports.tableHeader = exports.tableRow = 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 = 'placeholder';
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*',
@@ -99,28 +199,8 @@ const tableOptions = {
99
199
  },
100
200
  },
101
201
  };
102
- exports.tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
202
+ exports.tableNodes = createTableNodes(tableOptions);
103
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 } }) });
104
- const tableCell = exports.tableNodes.table_cell;
105
- exports.tableCell = tableCell;
106
- tableCell.toDOM = (node) => {
107
- if (!node.textContent) {
108
- node.attrs.class = 'placeholder';
109
- }
110
- if (exports.tableNodes.table_cell.toDOM) {
111
- return exports.tableNodes.table_cell.toDOM(node);
112
- }
113
- return ['td'];
114
- };
115
- const tableHeader = exports.tableNodes.table_cell;
116
- exports.tableHeader = tableHeader;
117
- tableHeader.toDOM = (node) => {
118
- if (!node.textContent) {
119
- node.attrs.class = 'placeholder';
120
- }
121
- if (exports.tableNodes.table_header.toDOM) {
122
- return exports.tableNodes.table_header.toDOM(node);
123
- }
124
- return ['th'];
125
- };
126
204
  exports.tableRow = exports.tableNodes.table_row;
205
+ exports.tableCell = exports.tableNodes.table_cell;
206
+ exports.tableHeader = exports.tableNodes.table_header;
@@ -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 = 'placeholder';
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*',
@@ -98,25 +197,6 @@ const tableOptions = {
98
197
  };
99
198
  export const tableNodes = createTableNodes(tableOptions);
100
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 } }) });
101
- const tableCell = tableNodes.table_cell;
102
- tableCell.toDOM = (node) => {
103
- if (!node.textContent) {
104
- node.attrs.class = 'placeholder';
105
- }
106
- if (tableNodes.table_cell.toDOM) {
107
- return tableNodes.table_cell.toDOM(node);
108
- }
109
- return ['td'];
110
- };
111
- const tableHeader = tableNodes.table_cell;
112
- tableHeader.toDOM = (node) => {
113
- if (!node.textContent) {
114
- node.attrs.class = 'placeholder';
115
- }
116
- if (tableNodes.table_header.toDOM) {
117
- return tableNodes.table_header.toDOM(node);
118
- }
119
- return ['th'];
120
- };
121
200
  export const tableRow = tableNodes.table_row;
122
- export { tableHeader, tableCell };
201
+ export const tableCell = tableNodes.table_cell;
202
+ export const tableHeader = tableNodes.table_header;
@@ -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,12 +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
- declare const tableCell: import("prosemirror-model").NodeSpec;
49
- declare const tableHeader: import("prosemirror-model").NodeSpec;
50
50
  export declare const tableRow: import("prosemirror-model").NodeSpec;
51
- export { tableHeader, tableCell };
51
+ export declare const tableCell: import("prosemirror-model").NodeSpec;
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-9",
4
+ "version": "2.1.1-LEAN-3336-11",
5
5
  "repository": "github:Atypon-OpenSource/manuscripts-transform",
6
6
  "license": "Apache-2.0",
7
7
  "main": "dist/cjs",