@atlaskit/editor-plugin-table 1.7.0 → 1.7.1
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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/table/transforms/column-width.js +47 -27
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/transforms/column-width.js +47 -27
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/transforms/column-width.js +47 -27
- package/dist/esm/version.json +1 -1
- package/package.json +4 -1
- package/src/plugins/table/transforms/column-width.ts +61 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 1.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`7a720ec3e8e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7a720ec3e8e) - ED-18796 Use setAttrsStep to update colwidth attribute when scaling the table
|
|
8
|
+
|
|
3
9
|
## 1.7.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -10,11 +10,13 @@ var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
|
10
10
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
11
11
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
12
|
var _utils = require("../pm-plugins/table-resizing/utils");
|
|
13
|
+
var _steps = require("@atlaskit/adf-schema/steps");
|
|
13
14
|
var _resizeState = require("../pm-plugins/table-resizing/utils/resize-state");
|
|
14
15
|
var _misc = require("../pm-plugins/table-resizing/utils/misc");
|
|
15
16
|
var _scaleTable = require("../pm-plugins/table-resizing/utils/scale-table");
|
|
16
17
|
var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
|
|
17
18
|
var _commonStyles = require("../ui/common-styles");
|
|
19
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
20
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
21
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
22
|
var updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
|
|
@@ -58,36 +60,54 @@ var updateColumnWidths = function updateColumnWidths(resizeState, table, start)
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
// updating all cells with new attributes
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.update-table-cell-width-via-step')) {
|
|
64
|
+
var seen = {};
|
|
65
|
+
for (var _rowIndex = 0; _rowIndex < map.height; _rowIndex++) {
|
|
66
|
+
for (var _columnIndex = 0; _columnIndex < map.width; _columnIndex++) {
|
|
67
|
+
var _mapIndex = _rowIndex * map.width + _columnIndex;
|
|
68
|
+
var pos = map.map[_mapIndex];
|
|
69
|
+
var cell = table.nodeAt(pos);
|
|
70
|
+
if (!seen[pos] && cell) {
|
|
71
|
+
if (updatedCellsAttrs[pos]) {
|
|
72
|
+
tr.step(new _steps.SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
|
|
73
|
+
}
|
|
74
|
+
seen[pos] = true;
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
} else {
|
|
79
|
+
var rows = [];
|
|
80
|
+
var _seen = {};
|
|
81
|
+
for (var _rowIndex2 = 0; _rowIndex2 < map.height; _rowIndex2++) {
|
|
82
|
+
var row = table.child(_rowIndex2);
|
|
83
|
+
var cells = [];
|
|
84
|
+
for (var _columnIndex2 = 0; _columnIndex2 < map.width; _columnIndex2++) {
|
|
85
|
+
var _mapIndex2 = _rowIndex2 * map.width + _columnIndex2;
|
|
86
|
+
var _pos = map.map[_mapIndex2];
|
|
87
|
+
var _cell = table.nodeAt(_pos);
|
|
88
|
+
if (!_seen[_pos] && _cell) {
|
|
89
|
+
cells.push(_cell.type.createChecked(updatedCellsAttrs[_pos] || _cell.attrs, _cell.content, _cell.marks));
|
|
90
|
+
_seen[_pos] = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
94
|
+
}
|
|
95
|
+
var tablePos = start - 1;
|
|
96
|
+
var selectionBookmark = tr.selection.getBookmark();
|
|
97
|
+
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
98
|
+
/**
|
|
99
|
+
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
100
|
+
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
101
|
+
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
102
|
+
* e.g. if we change the content before a selection. This is because mapping
|
|
103
|
+
* means moving it if the content in front of it changed. Instead we can get
|
|
104
|
+
* bookmark of selection.
|
|
105
|
+
*
|
|
106
|
+
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
107
|
+
*/
|
|
108
|
+
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
76
109
|
}
|
|
77
|
-
|
|
78
|
-
var selectionBookmark = tr.selection.getBookmark();
|
|
79
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
80
|
-
/**
|
|
81
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
82
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
83
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
84
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
85
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
86
|
-
* bookmark of selection.
|
|
87
|
-
*
|
|
88
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
89
|
-
*/
|
|
90
|
-
return tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
110
|
+
return tr;
|
|
91
111
|
};
|
|
92
112
|
};
|
|
93
113
|
|
package/dist/cjs/version.json
CHANGED
|
@@ -2,12 +2,14 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
2
2
|
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
3
3
|
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
4
4
|
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
5
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
5
6
|
import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
6
7
|
import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
|
|
7
8
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
8
9
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
9
10
|
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
10
11
|
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
12
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
11
13
|
export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
12
14
|
const map = TableMap.get(table);
|
|
13
15
|
const updatedCellsAttrs = {};
|
|
@@ -51,36 +53,54 @@ export const updateColumnWidths = (resizeState, table, start) => tr => {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
// updating all cells with new attributes
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
if (getBooleanFF('platform.editor.update-table-cell-width-via-step')) {
|
|
57
|
+
const seen = {};
|
|
58
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
59
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
60
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
61
|
+
const pos = map.map[mapIndex];
|
|
62
|
+
const cell = table.nodeAt(pos);
|
|
63
|
+
if (!seen[pos] && cell) {
|
|
64
|
+
if (updatedCellsAttrs[pos]) {
|
|
65
|
+
tr.step(new SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
|
|
66
|
+
}
|
|
67
|
+
seen[pos] = true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
const rows = [];
|
|
73
|
+
const seen = {};
|
|
74
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
75
|
+
const row = table.child(rowIndex);
|
|
76
|
+
const cells = [];
|
|
77
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
78
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
79
|
+
const pos = map.map[mapIndex];
|
|
80
|
+
const cell = table.nodeAt(pos);
|
|
81
|
+
if (!seen[pos] && cell) {
|
|
82
|
+
cells.push(cell.type.createChecked(updatedCellsAttrs[pos] || cell.attrs, cell.content, cell.marks));
|
|
83
|
+
seen[pos] = true;
|
|
84
|
+
}
|
|
66
85
|
}
|
|
86
|
+
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
67
87
|
}
|
|
68
|
-
|
|
88
|
+
const tablePos = start - 1;
|
|
89
|
+
const selectionBookmark = tr.selection.getBookmark();
|
|
90
|
+
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
91
|
+
/**
|
|
92
|
+
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
93
|
+
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
94
|
+
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
95
|
+
* e.g. if we change the content before a selection. This is because mapping
|
|
96
|
+
* means moving it if the content in front of it changed. Instead we can get
|
|
97
|
+
* bookmark of selection.
|
|
98
|
+
*
|
|
99
|
+
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
100
|
+
*/
|
|
101
|
+
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
69
102
|
}
|
|
70
|
-
|
|
71
|
-
const selectionBookmark = tr.selection.getBookmark();
|
|
72
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
73
|
-
/**
|
|
74
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
75
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
76
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
77
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
78
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
79
|
-
* bookmark of selection.
|
|
80
|
-
*
|
|
81
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
82
|
-
*/
|
|
83
|
-
return tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
103
|
+
return tr;
|
|
84
104
|
};
|
|
85
105
|
|
|
86
106
|
/**
|
package/dist/es2019/version.json
CHANGED
|
@@ -5,12 +5,14 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
5
5
|
import { tableNewColumnMinWidth } from '@atlaskit/editor-common/styles';
|
|
6
6
|
import { akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
7
7
|
import { hasTableBeenResized } from '../pm-plugins/table-resizing/utils';
|
|
8
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
8
9
|
import { getResizeState, normaliseTableLayout } from '../pm-plugins/table-resizing/utils/resize-state';
|
|
9
10
|
import { getTableMaxWidth } from '../pm-plugins/table-resizing/utils/misc';
|
|
10
11
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
11
12
|
import { scaleTableTo } from '../pm-plugins/table-resizing/utils/scale-table';
|
|
12
13
|
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
13
14
|
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
15
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
16
|
export var updateColumnWidths = function updateColumnWidths(resizeState, table, start) {
|
|
15
17
|
return function (tr) {
|
|
16
18
|
var map = TableMap.get(table);
|
|
@@ -52,36 +54,54 @@ export var updateColumnWidths = function updateColumnWidths(resizeState, table,
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
// updating all cells with new attributes
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
if (getBooleanFF('platform.editor.update-table-cell-width-via-step')) {
|
|
58
|
+
var seen = {};
|
|
59
|
+
for (var _rowIndex = 0; _rowIndex < map.height; _rowIndex++) {
|
|
60
|
+
for (var _columnIndex = 0; _columnIndex < map.width; _columnIndex++) {
|
|
61
|
+
var _mapIndex = _rowIndex * map.width + _columnIndex;
|
|
62
|
+
var pos = map.map[_mapIndex];
|
|
63
|
+
var cell = table.nodeAt(pos);
|
|
64
|
+
if (!seen[pos] && cell) {
|
|
65
|
+
if (updatedCellsAttrs[pos]) {
|
|
66
|
+
tr.step(new SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
|
|
67
|
+
}
|
|
68
|
+
seen[pos] = true;
|
|
69
|
+
}
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
|
-
|
|
72
|
+
} else {
|
|
73
|
+
var rows = [];
|
|
74
|
+
var _seen = {};
|
|
75
|
+
for (var _rowIndex2 = 0; _rowIndex2 < map.height; _rowIndex2++) {
|
|
76
|
+
var row = table.child(_rowIndex2);
|
|
77
|
+
var cells = [];
|
|
78
|
+
for (var _columnIndex2 = 0; _columnIndex2 < map.width; _columnIndex2++) {
|
|
79
|
+
var _mapIndex2 = _rowIndex2 * map.width + _columnIndex2;
|
|
80
|
+
var _pos = map.map[_mapIndex2];
|
|
81
|
+
var _cell = table.nodeAt(_pos);
|
|
82
|
+
if (!_seen[_pos] && _cell) {
|
|
83
|
+
cells.push(_cell.type.createChecked(updatedCellsAttrs[_pos] || _cell.attrs, _cell.content, _cell.marks));
|
|
84
|
+
_seen[_pos] = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
88
|
+
}
|
|
89
|
+
var tablePos = start - 1;
|
|
90
|
+
var selectionBookmark = tr.selection.getBookmark();
|
|
91
|
+
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
92
|
+
/**
|
|
93
|
+
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
94
|
+
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
95
|
+
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
96
|
+
* e.g. if we change the content before a selection. This is because mapping
|
|
97
|
+
* means moving it if the content in front of it changed. Instead we can get
|
|
98
|
+
* bookmark of selection.
|
|
99
|
+
*
|
|
100
|
+
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
101
|
+
*/
|
|
102
|
+
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
70
103
|
}
|
|
71
|
-
|
|
72
|
-
var selectionBookmark = tr.selection.getBookmark();
|
|
73
|
-
tr.replaceWith(tablePos, tablePos + table.nodeSize, table.type.createChecked(table.attrs, rows, table.marks));
|
|
74
|
-
/**
|
|
75
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
76
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
77
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
78
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
79
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
80
|
-
* bookmark of selection.
|
|
81
|
-
*
|
|
82
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
83
|
-
*/
|
|
84
|
-
return tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
104
|
+
return tr;
|
|
85
105
|
};
|
|
86
106
|
};
|
|
87
107
|
|
package/dist/esm/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -108,6 +108,9 @@
|
|
|
108
108
|
"platform-feature-flags": {
|
|
109
109
|
"platform.editor.custom-table-width": {
|
|
110
110
|
"type": "boolean"
|
|
111
|
+
},
|
|
112
|
+
"platform.editor.update-table-cell-width-via-step": {
|
|
113
|
+
"type": "boolean"
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
116
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import { ContentNodeWithPos } from 'prosemirror-utils';
|
|
15
15
|
import { EditorView } from 'prosemirror-view';
|
|
16
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
16
17
|
import {
|
|
17
18
|
getResizeState,
|
|
18
19
|
normaliseTableLayout,
|
|
@@ -24,6 +25,8 @@ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
|
24
25
|
import { isMinCellWidthTable } from '../pm-plugins/table-resizing/utils/colgroup';
|
|
25
26
|
import { insertColumnButtonOffset } from '../ui/common-styles';
|
|
26
27
|
|
|
28
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
29
|
+
|
|
27
30
|
export const updateColumnWidths =
|
|
28
31
|
(resizeState: ResizeState, table: PMNode, start: number) =>
|
|
29
32
|
(tr: Transaction): Transaction => {
|
|
@@ -71,49 +74,68 @@ export const updateColumnWidths =
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
// updating all cells with new attributes
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
if (getBooleanFF('platform.editor.update-table-cell-width-via-step')) {
|
|
78
|
+
const seen: { [key: number]: boolean } = {};
|
|
79
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
80
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
81
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
82
|
+
const pos = map.map[mapIndex];
|
|
83
|
+
const cell = table.nodeAt(pos);
|
|
84
|
+
if (!seen[pos] && cell) {
|
|
85
|
+
if (updatedCellsAttrs[pos]) {
|
|
86
|
+
tr.step(new SetAttrsStep(pos + start, updatedCellsAttrs[pos]));
|
|
87
|
+
}
|
|
88
|
+
seen[pos] = true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
const rows: PMNode[] = [];
|
|
94
|
+
const seen: { [key: number]: boolean } = {};
|
|
95
|
+
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
96
|
+
const row = table.child(rowIndex);
|
|
97
|
+
const cells: PMNode[] = [];
|
|
98
|
+
|
|
99
|
+
for (let columnIndex = 0; columnIndex < map.width; columnIndex++) {
|
|
100
|
+
const mapIndex = rowIndex * map.width + columnIndex;
|
|
101
|
+
const pos = map.map[mapIndex];
|
|
102
|
+
const cell = table.nodeAt(pos);
|
|
103
|
+
if (!seen[pos] && cell) {
|
|
104
|
+
cells.push(
|
|
105
|
+
cell.type.createChecked(
|
|
106
|
+
updatedCellsAttrs[pos] || cell.attrs,
|
|
107
|
+
cell.content,
|
|
108
|
+
cell.marks,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
seen[pos] = true;
|
|
112
|
+
}
|
|
93
113
|
}
|
|
114
|
+
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
94
115
|
}
|
|
95
|
-
|
|
116
|
+
|
|
117
|
+
const tablePos = start - 1;
|
|
118
|
+
const selectionBookmark = tr.selection.getBookmark();
|
|
119
|
+
|
|
120
|
+
tr.replaceWith(
|
|
121
|
+
tablePos,
|
|
122
|
+
tablePos + table.nodeSize,
|
|
123
|
+
table.type.createChecked(table.attrs, rows, table.marks),
|
|
124
|
+
);
|
|
125
|
+
/**
|
|
126
|
+
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
127
|
+
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
128
|
+
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
129
|
+
* e.g. if we change the content before a selection. This is because mapping
|
|
130
|
+
* means moving it if the content in front of it changed. Instead we can get
|
|
131
|
+
* bookmark of selection.
|
|
132
|
+
*
|
|
133
|
+
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
134
|
+
*/
|
|
135
|
+
tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
96
136
|
}
|
|
97
137
|
|
|
98
|
-
|
|
99
|
-
const selectionBookmark = tr.selection.getBookmark();
|
|
100
|
-
|
|
101
|
-
tr.replaceWith(
|
|
102
|
-
tablePos,
|
|
103
|
-
tablePos + table.nodeSize,
|
|
104
|
-
table.type.createChecked(table.attrs, rows, table.marks),
|
|
105
|
-
);
|
|
106
|
-
/**
|
|
107
|
-
* We want to restore to the original selection but w/o applying the mapping. Function
|
|
108
|
-
* tr.replaceWith puts the selection after the inserted content. We need to manually
|
|
109
|
-
* set the selection back to original state. Mapping in this case doesn't quite work
|
|
110
|
-
* e.g. if we change the content before a selection. This is because mapping
|
|
111
|
-
* means moving it if the content in front of it changed. Instead we can get
|
|
112
|
-
* bookmark of selection.
|
|
113
|
-
*
|
|
114
|
-
* @see https://github.com/ProseMirror/prosemirror/issues/645
|
|
115
|
-
*/
|
|
116
|
-
return tr.setSelection(selectionBookmark.resolve(tr.doc));
|
|
138
|
+
return tr;
|
|
117
139
|
};
|
|
118
140
|
|
|
119
141
|
/**
|