@atlaskit/editor-plugin-table 1.6.9 → 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 +16 -0
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +48 -21
- package/dist/cjs/plugins/table/transforms/column-width.js +47 -27
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +44 -19
- package/dist/es2019/plugins/table/transforms/column-width.js +47 -27
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +48 -21
- package/dist/esm/plugins/table/transforms/column-width.js +47 -27
- package/dist/esm/version.json +1 -1
- package/package.json +7 -4
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -1
- package/src/plugins/table/pm-plugins/table-resizing/utils/colgroup.ts +46 -15
- package/src/plugins/table/transforms/column-width.ts +61 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
9
|
+
## 1.7.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`cb69e6847ec`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb69e6847ec) - [ux] The table colgroup will always set the width to the min width when the custom-table-width flag is enabled
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 1.6.9
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -32,6 +32,7 @@ var _updateOverflowShadows = require("./update-overflow-shadows");
|
|
|
32
32
|
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
33
33
|
var _OverflowShadowsObserver = require("./OverflowShadowsObserver");
|
|
34
34
|
var _TableContainer = require("./TableContainer");
|
|
35
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
35
36
|
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; }
|
|
36
37
|
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, _defineProperty3.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; }
|
|
37
38
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
@@ -135,7 +136,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
135
136
|
// Usually happens on window resize.
|
|
136
137
|
layoutSize !== _this.layoutSize || noOfColumnsChanged) {
|
|
137
138
|
// If column has been inserted/deleted avoid multi dispatch
|
|
138
|
-
if (!hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
139
|
+
if (!(0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && !hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
139
140
|
_this.scaleTable({
|
|
140
141
|
parentWidth: parentWidth,
|
|
141
142
|
layoutChanged: layoutChanged
|
|
@@ -10,29 +10,56 @@ var _prosemirrorModel = require("prosemirror-model");
|
|
|
10
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
11
11
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
12
12
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
13
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
14
|
var generateColgroup = function generateColgroup(table) {
|
|
14
15
|
var cols = [];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width')) {
|
|
17
|
+
table.content.firstChild.content.forEach(function (cell) {
|
|
18
|
+
var colspan = cell.attrs.colspan || 1;
|
|
19
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
20
|
+
// We slice here to guard against our colwidth array having more entries
|
|
21
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
22
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
23
|
+
cols.push(['col', {
|
|
24
|
+
style: "width: ".concat(width ? Math.max(width, _styles.tableCellMinWidth) : _styles.tableCellMinWidth, "px;")
|
|
25
|
+
}]);
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
// When we have merged cells on the first row (firstChild),
|
|
29
|
+
// We want to ensure we're creating the appropriate amount of
|
|
30
|
+
// cols the table still has.
|
|
31
|
+
cols.push.apply(cols, (0, _toConsumableArray2.default)(Array.from({
|
|
32
|
+
length: colspan
|
|
33
|
+
}, function (_) {
|
|
34
|
+
return ['col', {
|
|
35
|
+
style: "width: ".concat(_styles.tableCellMinWidth, "px;")
|
|
36
|
+
}];
|
|
37
|
+
})));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
table.content.firstChild.content.forEach(function (cell) {
|
|
42
|
+
var colspan = cell.attrs.colspan || 1;
|
|
43
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
44
|
+
// We slice here to guard against our colwidth array having more entries
|
|
45
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
46
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
47
|
+
cols.push(['col', width ? {
|
|
48
|
+
style: "width: ".concat(width, "px;")
|
|
49
|
+
} : {}]);
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
// When we have merged cells on the first row (firstChild),
|
|
53
|
+
// We want to ensure we're creating the appropriate amount of
|
|
54
|
+
// cols the table still has.
|
|
55
|
+
cols.push.apply(cols, (0, _toConsumableArray2.default)(Array.from({
|
|
56
|
+
length: colspan
|
|
57
|
+
}, function (_) {
|
|
58
|
+
return ['col', {}];
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
36
63
|
return cols;
|
|
37
64
|
};
|
|
38
65
|
exports.generateColgroup = generateColgroup;
|
|
@@ -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
|
@@ -20,6 +20,7 @@ import { updateOverflowShadows } from './update-overflow-shadows';
|
|
|
20
20
|
import memoizeOne from 'memoize-one';
|
|
21
21
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
22
22
|
import { TableContainer } from './TableContainer';
|
|
23
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
23
24
|
const isIE11 = browser.ie_version === 11;
|
|
24
25
|
const NOOP = () => undefined;
|
|
25
26
|
class TableComponent extends React.Component {
|
|
@@ -121,7 +122,7 @@ class TableComponent extends React.Component {
|
|
|
121
122
|
// Usually happens on window resize.
|
|
122
123
|
layoutSize !== this.layoutSize || noOfColumnsChanged) {
|
|
123
124
|
// If column has been inserted/deleted avoid multi dispatch
|
|
124
|
-
if (!hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
125
|
+
if (!getBooleanFF('platform.editor.custom-table-width') && !hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
125
126
|
this.scaleTable({
|
|
126
127
|
parentWidth,
|
|
127
128
|
layoutChanged
|
|
@@ -2,27 +2,52 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
2
2
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
3
3
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
export const generateColgroup = table => {
|
|
6
7
|
const cols = [];
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
9
|
+
table.content.firstChild.content.forEach(cell => {
|
|
10
|
+
const colspan = cell.attrs.colspan || 1;
|
|
11
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
12
|
+
// We slice here to guard against our colwidth array having more entries
|
|
13
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
14
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(width => {
|
|
15
|
+
cols.push(['col', {
|
|
16
|
+
style: `width: ${width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth}px;`
|
|
17
|
+
}]);
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
// When we have merged cells on the first row (firstChild),
|
|
21
|
+
// We want to ensure we're creating the appropriate amount of
|
|
22
|
+
// cols the table still has.
|
|
23
|
+
cols.push(...Array.from({
|
|
24
|
+
length: colspan
|
|
25
|
+
}, _ => ['col', {
|
|
26
|
+
style: `width: ${tableCellMinWidth}px;`
|
|
27
|
+
}]));
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
table.content.firstChild.content.forEach(cell => {
|
|
32
|
+
const colspan = cell.attrs.colspan || 1;
|
|
33
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
34
|
+
// We slice here to guard against our colwidth array having more entries
|
|
35
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
36
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(width => {
|
|
37
|
+
cols.push(['col', width ? {
|
|
38
|
+
style: `width: ${width}px;`
|
|
39
|
+
} : {}]);
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
// When we have merged cells on the first row (firstChild),
|
|
43
|
+
// We want to ensure we're creating the appropriate amount of
|
|
44
|
+
// cols the table still has.
|
|
45
|
+
cols.push(...Array.from({
|
|
46
|
+
length: colspan
|
|
47
|
+
}, _ => ['col', {}]));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
26
51
|
return cols;
|
|
27
52
|
};
|
|
28
53
|
export const insertColgroupFromNode = (tableRef, table) => {
|
|
@@ -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
|
@@ -30,6 +30,7 @@ import { updateOverflowShadows } from './update-overflow-shadows';
|
|
|
30
30
|
import memoizeOne from 'memoize-one';
|
|
31
31
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
32
32
|
import { TableContainer } from './TableContainer';
|
|
33
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
33
34
|
var isIE11 = browser.ie_version === 11;
|
|
34
35
|
var NOOP = function NOOP() {
|
|
35
36
|
return undefined;
|
|
@@ -129,7 +130,7 @@ var TableComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
129
130
|
// Usually happens on window resize.
|
|
130
131
|
layoutSize !== _this.layoutSize || noOfColumnsChanged) {
|
|
131
132
|
// If column has been inserted/deleted avoid multi dispatch
|
|
132
|
-
if (!hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
133
|
+
if (!getBooleanFF('platform.editor.custom-table-width') && !hasNumberedColumnChanged && !noOfColumnsChanged) {
|
|
133
134
|
_this.scaleTable({
|
|
134
135
|
parentWidth: parentWidth,
|
|
135
136
|
layoutChanged: layoutChanged
|
|
@@ -3,29 +3,56 @@ import { DOMSerializer } from 'prosemirror-model';
|
|
|
3
3
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
4
4
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
5
5
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
6
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
export var generateColgroup = function generateColgroup(table) {
|
|
7
8
|
var cols = [];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
10
|
+
table.content.firstChild.content.forEach(function (cell) {
|
|
11
|
+
var colspan = cell.attrs.colspan || 1;
|
|
12
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
13
|
+
// We slice here to guard against our colwidth array having more entries
|
|
14
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
15
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
16
|
+
cols.push(['col', {
|
|
17
|
+
style: "width: ".concat(width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth, "px;")
|
|
18
|
+
}]);
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
// When we have merged cells on the first row (firstChild),
|
|
22
|
+
// We want to ensure we're creating the appropriate amount of
|
|
23
|
+
// cols the table still has.
|
|
24
|
+
cols.push.apply(cols, _toConsumableArray(Array.from({
|
|
25
|
+
length: colspan
|
|
26
|
+
}, function (_) {
|
|
27
|
+
return ['col', {
|
|
28
|
+
style: "width: ".concat(tableCellMinWidth, "px;")
|
|
29
|
+
}];
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
table.content.firstChild.content.forEach(function (cell) {
|
|
35
|
+
var colspan = cell.attrs.colspan || 1;
|
|
36
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
37
|
+
// We slice here to guard against our colwidth array having more entries
|
|
38
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
39
|
+
cell.attrs.colwidth.slice(0, colspan).forEach(function (width) {
|
|
40
|
+
cols.push(['col', width ? {
|
|
41
|
+
style: "width: ".concat(width, "px;")
|
|
42
|
+
} : {}]);
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
// When we have merged cells on the first row (firstChild),
|
|
46
|
+
// We want to ensure we're creating the appropriate amount of
|
|
47
|
+
// cols the table still has.
|
|
48
|
+
cols.push.apply(cols, _toConsumableArray(Array.from({
|
|
49
|
+
length: colspan
|
|
50
|
+
}, function (_) {
|
|
51
|
+
return ['col', {}];
|
|
52
|
+
})));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
29
56
|
return cols;
|
|
30
57
|
};
|
|
31
58
|
export var insertColgroupFromNode = function insertColgroupFromNode(tableRef, table) {
|
|
@@ -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.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@atlaskit/adf-schema": "^25.10.0",
|
|
31
|
-
"@atlaskit/editor-common": "^74.
|
|
31
|
+
"@atlaskit/editor-common": "^74.12.0",
|
|
32
32
|
"@atlaskit/editor-palette": "1.5.1",
|
|
33
33
|
"@atlaskit/editor-plugin-analytics": "^0.0.3",
|
|
34
34
|
"@atlaskit/editor-plugin-content-insertion": "^0.0.3",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@atlaskit/icon": "^21.12.0",
|
|
38
38
|
"@atlaskit/platform-feature-flags": "^0.2.1",
|
|
39
39
|
"@atlaskit/theme": "^12.5.0",
|
|
40
|
-
"@atlaskit/tokens": "^1.
|
|
40
|
+
"@atlaskit/tokens": "^1.11.0",
|
|
41
41
|
"@atlaskit/tooltip": "^17.8.0",
|
|
42
42
|
"@babel/runtime": "^7.0.0",
|
|
43
43
|
"@emotion/react": "^11.7.1",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@af/editor-libra": "*",
|
|
66
66
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
67
67
|
"@atlaskit/button": "^16.8.0",
|
|
68
|
-
"@atlaskit/editor-core": "^185.
|
|
68
|
+
"@atlaskit/editor-core": "^185.6.0",
|
|
69
69
|
"@atlaskit/editor-plugin-decorations": "^0.1.0",
|
|
70
70
|
"@atlaskit/editor-plugin-feature-flags": "^0.1.0",
|
|
71
71
|
"@atlaskit/editor-plugin-grid": "^0.1.0",
|
|
@@ -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
|
}
|
|
@@ -52,6 +52,7 @@ import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
|
|
|
52
52
|
import memoizeOne from 'memoize-one';
|
|
53
53
|
import { OverflowShadowsObserver } from './OverflowShadowsObserver';
|
|
54
54
|
import { TableContainer } from './TableContainer';
|
|
55
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
55
56
|
|
|
56
57
|
const isIE11 = browser.ie_version === 11;
|
|
57
58
|
const NOOP = () => undefined;
|
|
@@ -550,7 +551,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
|
|
|
550
551
|
noOfColumnsChanged
|
|
551
552
|
) {
|
|
552
553
|
// If column has been inserted/deleted avoid multi dispatch
|
|
553
|
-
if (
|
|
554
|
+
if (
|
|
555
|
+
!getBooleanFF('platform.editor.custom-table-width') &&
|
|
556
|
+
!hasNumberedColumnChanged &&
|
|
557
|
+
!noOfColumnsChanged
|
|
558
|
+
) {
|
|
554
559
|
this.scaleTable({ parentWidth, layoutChanged });
|
|
555
560
|
}
|
|
556
561
|
this.updateParentWidth(parentWidth);
|
|
@@ -2,27 +2,58 @@ import { DOMSerializer, Node as PmNode } from 'prosemirror-model';
|
|
|
2
2
|
import { getFragmentBackingArray } from '@atlaskit/editor-common/utils';
|
|
3
3
|
import { tableCellMinWidth } from '@atlaskit/editor-common/styles';
|
|
4
4
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
5
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
|
|
6
7
|
type Col = Array<string | { [name: string]: string }>;
|
|
7
8
|
|
|
8
9
|
export const generateColgroup = (table: PmNode): Col[] => {
|
|
9
10
|
const cols: Col[] = [];
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
if (getBooleanFF('platform.editor.custom-table-width')) {
|
|
13
|
+
table.content.firstChild!.content.forEach((cell) => {
|
|
14
|
+
const colspan = cell.attrs.colspan || 1;
|
|
15
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
16
|
+
// We slice here to guard against our colwidth array having more entries
|
|
17
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
18
|
+
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
19
|
+
cols.push([
|
|
20
|
+
'col',
|
|
21
|
+
{
|
|
22
|
+
style: `width: ${
|
|
23
|
+
width ? Math.max(width, tableCellMinWidth) : tableCellMinWidth
|
|
24
|
+
}px;`,
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
// When we have merged cells on the first row (firstChild),
|
|
30
|
+
// We want to ensure we're creating the appropriate amount of
|
|
31
|
+
// cols the table still has.
|
|
32
|
+
cols.push(
|
|
33
|
+
...Array.from({ length: colspan }, (_) => [
|
|
34
|
+
'col',
|
|
35
|
+
{ style: `width: ${tableCellMinWidth}px;` },
|
|
36
|
+
]),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
} else {
|
|
41
|
+
table.content.firstChild!.content.forEach((cell) => {
|
|
42
|
+
const colspan = cell.attrs.colspan || 1;
|
|
43
|
+
if (Array.isArray(cell.attrs.colwidth)) {
|
|
44
|
+
// We slice here to guard against our colwidth array having more entries
|
|
45
|
+
// Than the we actually span. We'll patch the document at a later point.
|
|
46
|
+
cell.attrs.colwidth.slice(0, colspan).forEach((width) => {
|
|
47
|
+
cols.push(['col', width ? { style: `width: ${width}px;` } : {}]);
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
// When we have merged cells on the first row (firstChild),
|
|
51
|
+
// We want to ensure we're creating the appropriate amount of
|
|
52
|
+
// cols the table still has.
|
|
53
|
+
cols.push(...Array.from({ length: colspan }, (_) => ['col', {}]));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
26
57
|
|
|
27
58
|
return cols;
|
|
28
59
|
};
|
|
@@ -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
|
/**
|