@atlaskit/editor-plugin-table 19.0.0 → 20.0.0
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 +37 -0
- package/dist/cjs/nodeviews/TableResizer.js +1 -1
- package/dist/cjs/nodeviews/table.js +18 -2
- package/dist/cjs/nodeviews/toDOM.js +18 -4
- package/dist/cjs/pm-plugins/keymap.js +12 -12
- package/dist/cjs/pm-plugins/main.js +41 -7
- package/dist/cjs/pm-plugins/table-width.js +10 -0
- package/dist/cjs/pm-plugins/transforms/content-mode.js +48 -0
- package/dist/cjs/pm-plugins/transforms/fix-tables.js +4 -35
- package/dist/cjs/pm-plugins/transforms/table-transform-utils.js +62 -0
- package/dist/cjs/pm-plugins/utils/tableMode.js +149 -0
- package/dist/cjs/tablePlugin.js +45 -40
- package/dist/cjs/ui/ContentComponent.js +1 -0
- package/dist/cjs/ui/event-handlers.js +3 -2
- package/dist/cjs/ui/global-styles.js +2 -1
- package/dist/cjs/ui/toolbar.js +36 -7
- package/dist/es2019/nodeviews/TableResizer.js +1 -1
- package/dist/es2019/nodeviews/table.js +18 -2
- package/dist/es2019/nodeviews/toDOM.js +18 -4
- package/dist/es2019/pm-plugins/keymap.js +2 -2
- package/dist/es2019/pm-plugins/main.js +41 -7
- package/dist/es2019/pm-plugins/table-width.js +10 -0
- package/dist/es2019/pm-plugins/transforms/content-mode.js +39 -0
- package/dist/es2019/pm-plugins/transforms/fix-tables.js +2 -33
- package/dist/es2019/pm-plugins/transforms/table-transform-utils.js +56 -0
- package/dist/es2019/pm-plugins/utils/tableMode.js +148 -0
- package/dist/es2019/tablePlugin.js +10 -4
- package/dist/es2019/ui/ContentComponent.js +1 -0
- package/dist/es2019/ui/event-handlers.js +4 -3
- package/dist/es2019/ui/global-styles.js +2 -1
- package/dist/es2019/ui/toolbar.js +33 -6
- package/dist/esm/nodeviews/TableResizer.js +1 -1
- package/dist/esm/nodeviews/table.js +18 -2
- package/dist/esm/nodeviews/toDOM.js +18 -4
- package/dist/esm/pm-plugins/keymap.js +12 -12
- package/dist/esm/pm-plugins/main.js +41 -7
- package/dist/esm/pm-plugins/table-width.js +10 -0
- package/dist/esm/pm-plugins/transforms/content-mode.js +41 -0
- package/dist/esm/pm-plugins/transforms/fix-tables.js +2 -33
- package/dist/esm/pm-plugins/transforms/table-transform-utils.js +56 -0
- package/dist/esm/pm-plugins/utils/tableMode.js +143 -0
- package/dist/esm/tablePlugin.js +45 -40
- package/dist/esm/ui/ContentComponent.js +1 -0
- package/dist/esm/ui/event-handlers.js +4 -3
- package/dist/esm/ui/global-styles.js +2 -1
- package/dist/esm/ui/toolbar.js +36 -7
- package/dist/types/pm-plugins/keymap.d.ts +1 -1
- package/dist/types/pm-plugins/main.d.ts +1 -1
- package/dist/types/pm-plugins/transforms/content-mode.d.ts +8 -0
- package/dist/types/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
- package/dist/types/pm-plugins/utils/tableMode.d.ts +22 -0
- package/dist/types/tablePluginType.d.ts +6 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/ui/global-styles.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/transforms/content-mode.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/transforms/table-transform-utils.d.ts +11 -0
- package/dist/types-ts4.5/pm-plugins/utils/tableMode.d.ts +22 -0
- package/dist/types-ts4.5/tablePluginType.d.ts +6 -0
- package/dist/types-ts4.5/types/index.d.ts +3 -0
- package/dist/types-ts4.5/ui/global-styles.d.ts +2 -1
- package/package.json +21 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 20.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b10c935ca9497`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b10c935ca9497) -
|
|
8
|
+
Removed deprecated `browser` singleton from editor-common. This has been replaced with a
|
|
9
|
+
`getBrowserInfo` function that returns the same information. This change was made to avoid issues
|
|
10
|
+
with module loading order and to provide a more consistent API for accessing browser information.
|
|
11
|
+
|
|
12
|
+
Please update any imports of `browser` to use `getBrowserInfo` instead. For example, the following
|
|
13
|
+
imports have been removed:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { browser } from '@atlaskit/editor-common/utils';
|
|
17
|
+
import { browser } from '@atlaskit/editor-common/browser';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Instead, please use:
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If you were previously using `browser.ie_version`, you would now use
|
|
27
|
+
`getBrowserInfo().ie_version`.
|
|
28
|
+
|
|
29
|
+
- Updated dependencies
|
|
30
|
+
|
|
31
|
+
## 19.0.1
|
|
32
|
+
|
|
33
|
+
### Patch Changes
|
|
34
|
+
|
|
35
|
+
- [`ed96586aa0e43`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ed96586aa0e43) -
|
|
36
|
+
Cleanup experiment platform_editor_table_resizer_extended_zone: ship treatment
|
|
37
|
+
(needExtendedResizeZone always true)
|
|
38
|
+
- Updated dependencies
|
|
39
|
+
|
|
3
40
|
## 19.0.0
|
|
4
41
|
|
|
5
42
|
### Major Changes
|
|
@@ -517,7 +517,7 @@ var TableResizer = exports.TableResizer = function TableResizer(_ref) {
|
|
|
517
517
|
snap: guidelineSnaps,
|
|
518
518
|
handlePositioning: "adjacent",
|
|
519
519
|
isHandleVisible: isTableSelected,
|
|
520
|
-
needExtendedResizeZone:
|
|
520
|
+
needExtendedResizeZone: true,
|
|
521
521
|
appearance: isTableSelected && isWholeTableInDanger ? 'danger' : undefined,
|
|
522
522
|
handleHighlight: "shadow"
|
|
523
523
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
@@ -22,10 +22,12 @@ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
|
22
22
|
var _tableMap = require("@atlaskit/editor-tables/table-map");
|
|
23
23
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
24
24
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
25
|
+
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
25
26
|
var _createPluginConfig = require("../pm-plugins/create-plugin-config");
|
|
26
27
|
var _pluginFactory = require("../pm-plugins/plugin-factory");
|
|
27
28
|
var _tableWidth = require("../pm-plugins/table-width");
|
|
28
29
|
var _nodes = require("../pm-plugins/utils/nodes");
|
|
30
|
+
var _tableMode = require("../pm-plugins/utils/tableMode");
|
|
29
31
|
var _TableComponentWithSharedState = require("./TableComponentWithSharedState");
|
|
30
32
|
var _toDOM = require("./toDOM");
|
|
31
33
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
@@ -205,7 +207,7 @@ var TableView = exports.default = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
205
207
|
key: "setDomAttrs",
|
|
206
208
|
value: function setDomAttrs(node) {
|
|
207
209
|
var _this3 = this,
|
|
208
|
-
_this$
|
|
210
|
+
_this$reactComponentP8,
|
|
209
211
|
_this$getEditorFeatur2,
|
|
210
212
|
_this$options3,
|
|
211
213
|
_this$options4;
|
|
@@ -213,12 +215,26 @@ var TableView = exports.default = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
213
215
|
return; // width / attribute application to actual table will happen later when table is set
|
|
214
216
|
}
|
|
215
217
|
var attrs = tableAttributes(node);
|
|
218
|
+
if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) {
|
|
219
|
+
var _this$reactComponentP6, _this$reactComponentP7;
|
|
220
|
+
if ((0, _tableMode.isTableInContentMode)({
|
|
221
|
+
node: node,
|
|
222
|
+
allowColumnResizing: !!this.reactComponentProps.allowColumnResizing,
|
|
223
|
+
allowTableResizing: !!this.reactComponentProps.allowTableResizing,
|
|
224
|
+
isFullPageEditor: !((_this$reactComponentP6 = this.reactComponentProps.options) !== null && _this$reactComponentP6 !== void 0 && _this$reactComponentP6.isCommentEditor) && !((_this$reactComponentP7 = this.reactComponentProps.options) !== null && _this$reactComponentP7 !== void 0 && _this$reactComponentP7.isChromelessEditor),
|
|
225
|
+
isTableNested: (0, _nodes.isTableNested)(this.view.state, this.getPos())
|
|
226
|
+
}) && (0, _expValEquals.expValEquals)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) {
|
|
227
|
+
attrs['data-initial-width-mode'] = 'content';
|
|
228
|
+
} else {
|
|
229
|
+
this.table.removeAttribute('data-initial-width-mode');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
216
232
|
Object.keys(attrs).forEach(function (attr) {
|
|
217
233
|
// Ignored via go/ees005
|
|
218
234
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
219
235
|
_this3.table.setAttribute(attr, attrs[attr]);
|
|
220
236
|
});
|
|
221
|
-
var isTableFixedColumnWidthsOptionEnabled = ((0, _platformFeatureFlags.fg)('platform_editor_table_fixed_column_width_prop') ? (_this$
|
|
237
|
+
var isTableFixedColumnWidthsOptionEnabled = ((0, _platformFeatureFlags.fg)('platform_editor_table_fixed_column_width_prop') ? (_this$reactComponentP8 = this.reactComponentProps) === null || _this$reactComponentP8 === void 0 ? void 0 : _this$reactComponentP8.allowFixedColumnWidthOption : (_this$getEditorFeatur2 = this.getEditorFeatureFlags) === null || _this$getEditorFeatur2 === void 0 ? void 0 : _this$getEditorFeatur2.call(this).tableWithFixedColumnWidthsOption) || false;
|
|
222
238
|
// Preserve Table Width cannot have inline width set on the table
|
|
223
239
|
if (!((_this$options3 = this.options) !== null && _this$options3 !== void 0 && _this$options3.isTableScalingEnabled) || (_this$options4 = this.options) !== null && _this$options4 !== void 0 && _this$options4.isTableScalingEnabled && isTableFixedColumnWidthsOptionEnabled && node.attrs.displayMode === 'fixed') {
|
|
224
240
|
var _tableWidthPluginKey$;
|
|
@@ -8,6 +8,7 @@ exports.tableNodeSpecWithFixedToDOM = void 0;
|
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
12
|
var _kebabCase = _interopRequireDefault(require("lodash/kebabCase"));
|
|
12
13
|
var _adfSchema = require("@atlaskit/adf-schema");
|
|
13
14
|
var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
|
|
@@ -15,6 +16,7 @@ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
|
15
16
|
var _colgroup = require("../pm-plugins/table-resizing/utils/colgroup");
|
|
16
17
|
var _consts = require("../pm-plugins/table-resizing/utils/consts");
|
|
17
18
|
var _misc = require("../pm-plugins/table-resizing/utils/misc");
|
|
19
|
+
var _tableMode = require("../pm-plugins/utils/tableMode");
|
|
18
20
|
var _tableContainerStyles = require("./table-container-styles");
|
|
19
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -22,6 +24,14 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
|
|
|
22
24
|
var tableNode = config.isNestingSupported ? _adfSchema.tableWithNestedTable : _adfSchema.table;
|
|
23
25
|
return _objectSpread(_objectSpread({}, tableNode), {}, {
|
|
24
26
|
toDOM: function toDOM(node) {
|
|
27
|
+
var isFullPageEditor = !config.isChromelessEditor && !config.isCommentEditor;
|
|
28
|
+
var isInContentMode = (0, _tableMode.isTableInContentMode)({
|
|
29
|
+
node: node,
|
|
30
|
+
allowColumnResizing: config.allowColumnResizing,
|
|
31
|
+
allowTableResizing: config.tableResizingEnabled,
|
|
32
|
+
isFullPageEditor: isFullPageEditor,
|
|
33
|
+
isTableNested: config.isNested
|
|
34
|
+
}) && (0, _expValEquals.expValEquals)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true);
|
|
25
35
|
var alignmentStyle = Object.entries((0, _tableContainerStyles.getAlignmentStyle)(node.attrs.layout)).map(function (_ref) {
|
|
26
36
|
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
27
37
|
k = _ref2[0],
|
|
@@ -29,7 +39,6 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
|
|
|
29
39
|
return "".concat((0, _kebabCase.default)(k), ": ").concat((0, _kebabCase.default)(v));
|
|
30
40
|
}).join(';');
|
|
31
41
|
var tableMinWidth = (0, _colgroup.getResizerMinWidth)(node);
|
|
32
|
-
var isFullPageEditor = !config.isChromelessEditor && !config.isCommentEditor;
|
|
33
42
|
var attrs = {
|
|
34
43
|
'data-number-column': node.attrs.isNumberColumnEnabled,
|
|
35
44
|
'data-layout': node.attrs.layout,
|
|
@@ -39,6 +48,9 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
|
|
|
39
48
|
'data-ssr-placeholder': "table-".concat(node.attrs.localId),
|
|
40
49
|
'data-ssr-placeholder-replace': "table-".concat(node.attrs.localId)
|
|
41
50
|
};
|
|
51
|
+
if (isInContentMode) {
|
|
52
|
+
attrs['data-initial-width-mode'] = 'content';
|
|
53
|
+
}
|
|
42
54
|
if ((0, _expValEquals.expValEquals)('platform_editor_table_display_mode_in_to_dom', 'isEnabled', true)) {
|
|
43
55
|
attrs['data-table-display-mode'] = node.attrs.displayMode;
|
|
44
56
|
}
|
|
@@ -91,11 +103,13 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
|
|
|
91
103
|
class: 'pm-table-resizer-container',
|
|
92
104
|
style: (0, _lazyNodeView.convertToInlineCss)({
|
|
93
105
|
'--ak-editor-table-gutter-padding': config.isTableScalingEnabled ? 'calc(var(--ak-editor--large-gutter-padding) * 2)' : 'calc(var(--ak-editor--large-gutter-padding) * 2 - var(--ak-editor-resizer-handle-spacing))',
|
|
94
|
-
'--ak-editor-table-width': resizableTableWidth,
|
|
106
|
+
'--ak-editor-table-width': isInContentMode ? 'max-content' : resizableTableWidth,
|
|
95
107
|
width: "var(--ak-editor-table-width)"
|
|
96
108
|
})
|
|
97
109
|
}, ['div', {
|
|
98
|
-
class: 'resizer-item display-handle',
|
|
110
|
+
class: (0, _expValEquals.expValEquals)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true) ? 'resizer-item display-handle' : (0, _classnames.default)('resizer-item', {
|
|
111
|
+
'display-handle': !isInContentMode
|
|
112
|
+
}),
|
|
99
113
|
style: (0, _lazyNodeView.convertToInlineCss)({
|
|
100
114
|
position: 'relative',
|
|
101
115
|
userSelect: 'auto',
|
|
@@ -104,7 +118,7 @@ var tableNodeSpecWithFixedToDOM = exports.tableNodeSpecWithFixedToDOM = function
|
|
|
104
118
|
'--ak-editor-table-min-width': "".concat(tableMinWidth, "px"),
|
|
105
119
|
minWidth: 'var(--ak-editor-table-min-width)',
|
|
106
120
|
maxWidth: (0, _misc.getTableResizerContainerMaxWidthInCSS)(config.isCommentEditor, config.isChromelessEditor, config.isTableScalingEnabled),
|
|
107
|
-
width: (0, _misc.getTableResizerItemWidthInCSS)(node, config.isCommentEditor, config.isChromelessEditor)
|
|
121
|
+
width: isInContentMode ? 'auto' : (0, _misc.getTableResizerItemWidthInCSS)(node, config.isCommentEditor, config.isChromelessEditor)
|
|
108
122
|
})
|
|
109
123
|
}, ['span', {
|
|
110
124
|
class: 'resizer-hover-zone'
|
|
@@ -17,18 +17,18 @@ var _columnResize = require("./commands/column-resize");
|
|
|
17
17
|
var _commandsWithAnalytics2 = require("./commands/commands-with-analytics");
|
|
18
18
|
var _goToNextCell = require("./commands/go-to-next-cell");
|
|
19
19
|
var _insert = require("./commands/insert");
|
|
20
|
-
function keymapPlugin(getEditorContainerWidth, api, nodeViewPortalProviderAPI, editorAnalyticsAPI) {
|
|
20
|
+
function keymapPlugin(getEditorContainerWidth, api, nodeViewPortalProviderAPI, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
21
21
|
var _pluginInjectionApi$a;
|
|
22
|
-
var isTableScalingEnabled = arguments.length >
|
|
23
|
-
var isTableAlignmentEnabled = arguments.length >
|
|
24
|
-
var isFullWidthEnabled = arguments.length >
|
|
25
|
-
var pluginInjectionApi = arguments.length >
|
|
26
|
-
var getIntl = arguments.length >
|
|
27
|
-
var isTableFixedColumnWidthsOptionEnabled = arguments.length >
|
|
28
|
-
var shouldUseIncreasedScalingPercent = arguments.length >
|
|
29
|
-
var isCommentEditor = arguments.length >
|
|
30
|
-
var isChromelessEditor = arguments.length >
|
|
31
|
-
var isTableResizingEnabled = arguments.length >
|
|
22
|
+
var isTableScalingEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
23
|
+
var isTableAlignmentEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
24
|
+
var isFullWidthEnabled = arguments.length > 7 ? arguments[7] : undefined;
|
|
25
|
+
var pluginInjectionApi = arguments.length > 8 ? arguments[8] : undefined;
|
|
26
|
+
var getIntl = arguments.length > 9 ? arguments[9] : undefined;
|
|
27
|
+
var isTableFixedColumnWidthsOptionEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
|
|
28
|
+
var shouldUseIncreasedScalingPercent = arguments.length > 11 ? arguments[11] : undefined;
|
|
29
|
+
var isCommentEditor = arguments.length > 12 ? arguments[12] : undefined;
|
|
30
|
+
var isChromelessEditor = arguments.length > 13 ? arguments[13] : undefined;
|
|
31
|
+
var isTableResizingEnabled = arguments.length > 14 ? arguments[14] : undefined;
|
|
32
32
|
var list = {};
|
|
33
33
|
var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
|
|
34
34
|
(0, _keymaps.bindKeymapWithCommand)(
|
|
@@ -99,7 +99,7 @@ function keymapPlugin(getEditorContainerWidth, api, nodeViewPortalProviderAPI, e
|
|
|
99
99
|
// Ignored via go/ees005
|
|
100
100
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
101
101
|
_keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list);
|
|
102
|
-
if (_keymaps.moveRowDown.common && _keymaps.moveRowUp.common && _keymaps.moveColumnLeft.common && _keymaps.moveColumnRight.common) {
|
|
102
|
+
if (dragAndDropEnabled && _keymaps.moveRowDown.common && _keymaps.moveRowUp.common && _keymaps.moveColumnLeft.common && _keymaps.moveColumnRight.common) {
|
|
103
103
|
var isNewKeyMapExperiment = (0, _expValEquals.expValEquals)('editor-a11y-fy26-keyboard-move-row-column', 'isEnabled', true);
|
|
104
104
|
// Move row/column shortcuts
|
|
105
105
|
/**
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _bindEventListener = require("bind-event-listener");
|
|
9
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
11
|
var _browser = require("@atlaskit/editor-common/browser");
|
|
11
12
|
var _coreUtils = require("@atlaskit/editor-common/core-utils");
|
|
@@ -32,12 +33,15 @@ var _fixTables = require("./transforms/fix-tables");
|
|
|
32
33
|
var _replaceTable = require("./transforms/replace-table");
|
|
33
34
|
var _decoration = require("./utils/decoration");
|
|
34
35
|
var _paste = require("./utils/paste");
|
|
36
|
+
var _tableMode = require("./utils/tableMode");
|
|
35
37
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
36
38
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
37
|
-
var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, nodeViewPortalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, fullWidthModeEnabled, previousFullWidthModeEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled, shouldUseIncreasedScalingPercent, isCommentEditor, isChromelessEditor, allowFixedColumnWidthOption) {
|
|
39
|
+
var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, nodeViewPortalProviderAPI, eventDispatcher, pluginConfig, getEditorContainerWidth, getEditorFeatureFlags, getIntl, fullWidthModeEnabled, previousFullWidthModeEnabled, dragAndDropEnabled, editorAnalyticsAPI, pluginInjectionApi, isTableScalingEnabled, shouldUseIncreasedScalingPercent, isCommentEditor, isChromelessEditor, allowFixedColumnWidthOption) {
|
|
38
40
|
var _accessibilityUtils;
|
|
39
41
|
var state = (0, _pluginFactory.createPluginState)(dispatch, _objectSpread(_objectSpread(_objectSpread({
|
|
40
42
|
pluginConfig: pluginConfig,
|
|
43
|
+
isCommentEditor: isCommentEditor,
|
|
44
|
+
isChromelessEditor: isChromelessEditor,
|
|
41
45
|
isTableHovered: false,
|
|
42
46
|
insertColumnButtonIndex: undefined,
|
|
43
47
|
insertRowButtonIndex: undefined,
|
|
@@ -45,7 +49,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
45
49
|
wasFullWidthModeEnabled: previousFullWidthModeEnabled,
|
|
46
50
|
isHeaderRowEnabled: !!pluginConfig.allowHeaderRow,
|
|
47
51
|
isHeaderColumnEnabled: false,
|
|
48
|
-
isDragAndDropEnabled:
|
|
52
|
+
isDragAndDropEnabled: dragAndDropEnabled,
|
|
49
53
|
isTableScalingEnabled: isTableScalingEnabled
|
|
50
54
|
}, _defaultTableSelection.defaultHoveredCell), _defaultTableSelection.defaultTableSelection), {}, {
|
|
51
55
|
getIntl: getIntl
|
|
@@ -78,7 +82,7 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
78
82
|
tableRow: (0, _tableNodeViews.tableRowView)({
|
|
79
83
|
eventDispatcher: eventDispatcher,
|
|
80
84
|
pluginInjectionApi: pluginInjectionApi,
|
|
81
|
-
isDragAndDropEnabled:
|
|
85
|
+
isDragAndDropEnabled: dragAndDropEnabled
|
|
82
86
|
}),
|
|
83
87
|
tableCell: (0, _tableNodeViews.tableCellView)({
|
|
84
88
|
eventDispatcher: eventDispatcher,
|
|
@@ -132,8 +136,34 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
132
136
|
}
|
|
133
137
|
},
|
|
134
138
|
view: function view(editorView) {
|
|
139
|
+
var _pluginInjectionApi$e;
|
|
135
140
|
var domAtPos = editorView.domAtPos.bind(editorView);
|
|
136
141
|
editorViewRef = editorView;
|
|
142
|
+
var contentModeSizeTableId = null;
|
|
143
|
+
var focusListenerBinding = null;
|
|
144
|
+
if ((pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.mode) !== 'view' && (0, _tableMode.isContentModeSupported)({
|
|
145
|
+
allowColumnResizing: !!pluginConfig.allowColumnResizing,
|
|
146
|
+
allowTableResizing: !!pluginConfig.allowTableResizing,
|
|
147
|
+
isFullPageEditor: !isChromelessEditor && !isCommentEditor
|
|
148
|
+
}) && (0, _expValEquals.expValEquals)('platform_editor_table_fit_to_content_auto_convert', 'isEnabled', true)) {
|
|
149
|
+
focusListenerBinding = (0, _bindEventListener.bind)(editorView.dom, {
|
|
150
|
+
type: 'focus',
|
|
151
|
+
listener: function listener() {
|
|
152
|
+
if (contentModeSizeTableId) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
contentModeSizeTableId = requestAnimationFrame(function () {
|
|
156
|
+
if (!editorViewRef) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
(0, _tableMode.applyMeasuredWidthToAllTables)(editorViewRef, pluginInjectionApi);
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
options: {
|
|
163
|
+
once: true
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
137
167
|
return {
|
|
138
168
|
update: function update(view, prevState) {
|
|
139
169
|
var state = view.state,
|
|
@@ -142,12 +172,12 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
142
172
|
var pluginState = (0, _pluginFactory.getPluginState)(state);
|
|
143
173
|
var tableRef;
|
|
144
174
|
if ((0, _platformFeatureFlags.fg)('platform_editor_enable_table_dnd')) {
|
|
145
|
-
var _pluginInjectionApi$
|
|
175
|
+
var _pluginInjectionApi$e2;
|
|
146
176
|
var parent = (0, _utils2.findParentDomRefOfType)(state.schema.nodes.table, domAtPos)(selection);
|
|
147
|
-
var shouldSetTableRef = (0, _platformFeatureFlags.fg)('platform_editor_enable_table_dnd_patch_1') ? parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
177
|
+
var shouldSetTableRef = (0, _platformFeatureFlags.fg)('platform_editor_enable_table_dnd_patch_1') ? parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e2 = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e2 === void 0 || (_pluginInjectionApi$e2 = _pluginInjectionApi$e2.sharedState.currentState()) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.mode) !== 'view' : parent;
|
|
148
178
|
if ((0, _expValEquals.expValEquals)('platform_editor_table_update_table_ref', 'isEnabled', true) && (0, _platformFeatureFlags.fg)('platform_editor_update_table_ref_fix')) {
|
|
149
|
-
var _pluginInjectionApi$
|
|
150
|
-
shouldSetTableRef = parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
179
|
+
var _pluginInjectionApi$e3, _pluginInjectionApi$i;
|
|
180
|
+
shouldSetTableRef = parent && (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e3 = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e3 === void 0 || (_pluginInjectionApi$e3 = _pluginInjectionApi$e3.sharedState.currentState()) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : _pluginInjectionApi$e3.mode) !== 'view' && (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$i = pluginInjectionApi.interaction) === null || _pluginInjectionApi$i === void 0 || (_pluginInjectionApi$i = _pluginInjectionApi$i.sharedState.currentState()) === null || _pluginInjectionApi$i === void 0 ? void 0 : _pluginInjectionApi$i.interactionState) !== 'hasNotHadInteraction';
|
|
151
181
|
}
|
|
152
182
|
if (shouldSetTableRef) {
|
|
153
183
|
tableRef =
|
|
@@ -209,6 +239,10 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatchAnalytic
|
|
|
209
239
|
} else if (pluginState.isResizeHandleWidgetAdded) {
|
|
210
240
|
(0, _misc.removeResizeHandleDecorations)()(state, dispatch);
|
|
211
241
|
}
|
|
242
|
+
},
|
|
243
|
+
destroy: function destroy() {
|
|
244
|
+
contentModeSizeTableId && cancelAnimationFrame(contentModeSizeTableId);
|
|
245
|
+
focusListenerBinding && focusListenerBinding();
|
|
212
246
|
}
|
|
213
247
|
};
|
|
214
248
|
},
|
|
@@ -15,6 +15,7 @@ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
|
15
15
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
16
16
|
var _consts = require("./table-resizing/utils/consts");
|
|
17
17
|
var _alignment = require("./utils/alignment");
|
|
18
|
+
var _tableMode = require("./utils/tableMode");
|
|
18
19
|
var _excluded = ["width"];
|
|
19
20
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
21
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
|
@@ -68,6 +69,15 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
68
69
|
var tr = newState.tr;
|
|
69
70
|
if (isReplaceDocumentOperation && !isCommentEditor) {
|
|
70
71
|
newState.doc.forEach(function (node, offset) {
|
|
72
|
+
if ((0, _tableMode.isTableInContentMode)({
|
|
73
|
+
node: node,
|
|
74
|
+
allowColumnResizing: true,
|
|
75
|
+
allowTableResizing: true,
|
|
76
|
+
isFullPageEditor: true,
|
|
77
|
+
isTableNested: false
|
|
78
|
+
})) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
71
81
|
if (node.type === table) {
|
|
72
82
|
var width = node.attrs.width;
|
|
73
83
|
var layout = node.attrs.layout;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getTableMeasurement = exports.applyTableMeasurement = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
10
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
11
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
12
|
+
var _tableTransformUtils = require("./table-transform-utils");
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
var tableWidth = function tableWidth(contentWidth) {
|
|
16
|
+
var maxEditorWidth = (0, _expValEquals.expValEquals)('editor_tinymce_full_width_mode', 'isEnabled', true) || (0, _expValEquals.expValEquals)('confluence_max_width_content_appearance', 'isEnabled', true) ? _editorSharedStyles.akEditorMaxLayoutWidth : _editorSharedStyles.akEditorFullWidthLayoutWidth;
|
|
17
|
+
return Math.min(maxEditorWidth, contentWidth);
|
|
18
|
+
};
|
|
19
|
+
var getTableMeasurement = exports.getTableMeasurement = function getTableMeasurement(tableRef) {
|
|
20
|
+
var colWidths = getRenderedColgroupColumnWidths(tableRef);
|
|
21
|
+
var totalContentWidth = colWidths.reduce(function (acc, current) {
|
|
22
|
+
return acc + current;
|
|
23
|
+
}, 0);
|
|
24
|
+
return {
|
|
25
|
+
colWidths: colWidths,
|
|
26
|
+
tableWidth: tableWidth(totalContentWidth)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var applyTableMeasurement = exports.applyTableMeasurement = function applyTableMeasurement(tr, tableNode, _ref, tablePos) {
|
|
30
|
+
var colWidths = _ref.colWidths,
|
|
31
|
+
tableWidth = _ref.tableWidth;
|
|
32
|
+
tr = (0, _tableTransformUtils.updateCellsMarkup)(tr, tableNode, tablePos, function (cell, _rowIndex, colIndex) {
|
|
33
|
+
var newColWidths = colWidths.slice(colIndex, colIndex + cell.attrs.colspan);
|
|
34
|
+
return cell.type.createChecked(_objectSpread(_objectSpread({}, cell.attrs), {}, {
|
|
35
|
+
colwidth: newColWidths.length ? newColWidths : null
|
|
36
|
+
}), cell.content, cell.marks);
|
|
37
|
+
});
|
|
38
|
+
return tr.setNodeMarkup(tablePos, undefined, _objectSpread(_objectSpread({}, tableNode.attrs), {}, {
|
|
39
|
+
width: tableWidth
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
function getRenderedColgroupColumnWidths(tableRef) {
|
|
43
|
+
var cols = Array.from(tableRef.querySelectorAll(':scope > colgroup > col'));
|
|
44
|
+
return cols.map(function (col) {
|
|
45
|
+
var width = col.getBoundingClientRect().width;
|
|
46
|
+
return Math.max(Math.round(width), _styles.tableCellMinWidth);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -11,6 +11,7 @@ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
|
11
11
|
var _columnState = require("../table-resizing/utils/column-state");
|
|
12
12
|
var _contentWidth = require("../table-resizing/utils/content-width");
|
|
13
13
|
var _misc = require("../table-resizing/utils/misc");
|
|
14
|
+
var _tableTransformUtils = require("./table-transform-utils");
|
|
14
15
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
16
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
17
|
var validateTableCellNodeAttrs = function validateTableCellNodeAttrs(_ref, reportInvalidTableCellSpanAttrs) {
|
|
@@ -47,7 +48,7 @@ var validateTableCellNodeAttrs = function validateTableCellNodeAttrs(_ref, repor
|
|
|
47
48
|
// We remove the third width here, assumed duplicate content.
|
|
48
49
|
var removeExtraneousColumnWidths = exports.removeExtraneousColumnWidths = function removeExtraneousColumnWidths(node, basePos, tr, reportInvalidTableCellSpanAttrs) {
|
|
49
50
|
var hasProblems = false;
|
|
50
|
-
tr = replaceCells(tr, node, basePos, function (cell) {
|
|
51
|
+
tr = (0, _tableTransformUtils.replaceCells)(tr, node, basePos, function (cell) {
|
|
51
52
|
var _cell$attrs = cell.attrs,
|
|
52
53
|
colwidth = _cell$attrs.colwidth,
|
|
53
54
|
colspan = _cell$attrs.colspan,
|
|
@@ -117,7 +118,7 @@ var fixAutoSizedTable = exports.fixAutoSizedTable = function fixAutoSizedTable(v
|
|
|
117
118
|
var scaledColumnWidths = colWidths.map(function (width) {
|
|
118
119
|
return Math.floor(width * scale);
|
|
119
120
|
});
|
|
120
|
-
tr = replaceCells(tr, tableNode, tablePos, function (cell, _rowIndex, colIndex) {
|
|
121
|
+
tr = (0, _tableTransformUtils.replaceCells)(tr, tableNode, tablePos, function (cell, _rowIndex, colIndex) {
|
|
121
122
|
var newColWidths = scaledColumnWidths.slice(colIndex, colIndex + cell.attrs.colspan);
|
|
122
123
|
return cell.type.createChecked(_objectSpread(_objectSpread({}, cell.attrs), {}, {
|
|
123
124
|
colwidth: newColWidths.length ? newColWidths : null
|
|
@@ -160,36 +161,4 @@ function parseDOMColumnWidths(domAtPos, tableNode, tableStart, tableRef) {
|
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
return cols;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// TODO: ED-26961 - move to prosemirror-utils
|
|
166
|
-
var replaceCells = function replaceCells(tr, table, tablePos, modifyCell) {
|
|
167
|
-
var rows = [];
|
|
168
|
-
var modifiedCells = 0;
|
|
169
|
-
for (var rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
|
|
170
|
-
var row = table.child(rowIndex);
|
|
171
|
-
var cells = [];
|
|
172
|
-
for (var colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
173
|
-
var cell = row.child(colIndex);
|
|
174
|
-
|
|
175
|
-
// TODO: ED-26961 - The rowIndex and colIndex are not accurate in a merged cell scenario
|
|
176
|
-
// e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
|
|
177
|
-
var node = modifyCell(cell, rowIndex, colIndex);
|
|
178
|
-
if (node.sameMarkup(cell) === false) {
|
|
179
|
-
modifiedCells++;
|
|
180
|
-
}
|
|
181
|
-
cells.push(node);
|
|
182
|
-
}
|
|
183
|
-
if (cells.length) {
|
|
184
|
-
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Check if the table has changed before replacing.
|
|
189
|
-
// If no cells are modified our counter will be zero.
|
|
190
|
-
if (rows.length && modifiedCells !== 0) {
|
|
191
|
-
var newTable = table.type.createChecked(table.attrs, rows, table.marks);
|
|
192
|
-
return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
|
|
193
|
-
}
|
|
194
|
-
return tr;
|
|
195
|
-
};
|
|
164
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.updateCellsMarkup = exports.replaceCells = void 0;
|
|
7
|
+
// TODO: ED-26961 - move to prosemirror-utils
|
|
8
|
+
var replaceCells = exports.replaceCells = function replaceCells(tr, table, tablePos, modifyCell) {
|
|
9
|
+
var rows = [];
|
|
10
|
+
var modifiedCells = 0;
|
|
11
|
+
for (var rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
|
|
12
|
+
var row = table.child(rowIndex);
|
|
13
|
+
var cells = [];
|
|
14
|
+
for (var colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
15
|
+
var cell = row.child(colIndex);
|
|
16
|
+
|
|
17
|
+
// TODO: ED-26961 - The rowIndex and colIndex are not accurate in a merged cell scenario
|
|
18
|
+
// e.g. table with 5 columns might have only one cell in a row, colIndex will be 1, where it should be 4
|
|
19
|
+
var node = modifyCell(cell, rowIndex, colIndex);
|
|
20
|
+
if (node.sameMarkup(cell) === false) {
|
|
21
|
+
modifiedCells++;
|
|
22
|
+
}
|
|
23
|
+
cells.push(node);
|
|
24
|
+
}
|
|
25
|
+
if (cells.length) {
|
|
26
|
+
rows.push(row.type.createChecked(row.attrs, cells, row.marks));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check if the table has changed before replacing.
|
|
31
|
+
// If no cells are modified our counter will be zero.
|
|
32
|
+
if (rows.length && modifiedCells !== 0) {
|
|
33
|
+
var newTable = table.type.createChecked(table.attrs, rows, table.marks);
|
|
34
|
+
return tr.replaceWith(tablePos, tablePos + table.nodeSize, newTable);
|
|
35
|
+
}
|
|
36
|
+
return tr;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Position-preserving alternative to `replaceCells`.
|
|
41
|
+
*
|
|
42
|
+
* Uses `setNodeMarkup` per cell instead of rebuilding the whole table with
|
|
43
|
+
* `replaceWith`, so document positions inside cells are never invalidated.
|
|
44
|
+
* This preserves any existing selection through `tr.mapping`.
|
|
45
|
+
*/
|
|
46
|
+
var updateCellsMarkup = exports.updateCellsMarkup = function updateCellsMarkup(tr, table, tablePos, modifyCell) {
|
|
47
|
+
var rowOffset = tablePos + 1;
|
|
48
|
+
for (var rowIndex = 0; rowIndex < table.childCount; rowIndex++) {
|
|
49
|
+
var row = table.child(rowIndex);
|
|
50
|
+
var cellOffset = rowOffset + 1;
|
|
51
|
+
for (var colIndex = 0; colIndex < row.childCount; colIndex++) {
|
|
52
|
+
var cell = row.child(colIndex);
|
|
53
|
+
var modified = modifyCell(cell, rowIndex, colIndex);
|
|
54
|
+
if (!modified.sameMarkup(cell)) {
|
|
55
|
+
tr.setNodeMarkup(cellOffset, modified.type, modified.attrs, modified.marks);
|
|
56
|
+
}
|
|
57
|
+
cellOffset += cell.nodeSize;
|
|
58
|
+
}
|
|
59
|
+
rowOffset += row.nodeSize;
|
|
60
|
+
}
|
|
61
|
+
return tr;
|
|
62
|
+
};
|