@atlaskit/editor-plugin-table 1.6.8 → 1.7.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 +16 -0
- package/dist/cjs/plugins/table/index.js +32 -25
- package/dist/cjs/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/cjs/plugins/table/pm-plugins/table-add-width.js +87 -0
- package/dist/cjs/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +48 -21
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/table/index.js +6 -0
- package/dist/es2019/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-add-width.js +78 -0
- package/dist/es2019/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +44 -19
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/table/index.js +32 -25
- package/dist/esm/plugins/table/nodeviews/TableComponent.js +2 -1
- package/dist/esm/plugins/table/pm-plugins/table-add-width.js +81 -0
- package/dist/esm/plugins/table/pm-plugins/table-resizing/utils/colgroup.js +48 -21
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/table/pm-plugins/table-add-width.d.ts +8 -0
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-add-width.d.ts +8 -0
- package/package.json +4 -4
- package/src/plugins/table/index.tsx +11 -0
- package/src/plugins/table/nodeviews/TableComponent.tsx +6 -1
- package/src/plugins/table/pm-plugins/table-add-width.ts +103 -0
- package/src/plugins/table/pm-plugins/table-resizing/utils/colgroup.ts +46 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 1.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`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
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 1.6.9
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`6e54d9fbeea`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6e54d9fbeea) - Added tableAddWidthPlugin
|
|
18
|
+
|
|
3
19
|
## 1.6.8
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -18,6 +18,7 @@ var _messages = require("@atlaskit/editor-common/messages");
|
|
|
18
18
|
var _icons = require("@atlaskit/editor-common/icons");
|
|
19
19
|
var _createPluginConfig = require("./create-plugin-config");
|
|
20
20
|
var _tableLocalId = require("./pm-plugins/table-local-id");
|
|
21
|
+
var _tableAddWidth = require("./pm-plugins/table-add-width");
|
|
21
22
|
var _safariDeleteCompositionTextIssueWorkaround = require("./pm-plugins/safari-delete-composition-text-issue-workaround");
|
|
22
23
|
var _plugin = require("./pm-plugins/decorations/plugin");
|
|
23
24
|
var _keymap = require("./pm-plugins/keymap");
|
|
@@ -175,6 +176,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
175
176
|
var dispatch = _ref7.dispatch;
|
|
176
177
|
return (0, _tableLocalId.createPlugin)(dispatch);
|
|
177
178
|
}
|
|
179
|
+
}, {
|
|
180
|
+
name: 'tableAddWidth',
|
|
181
|
+
plugin: function plugin(_ref8) {
|
|
182
|
+
var dispatch = _ref8.dispatch;
|
|
183
|
+
return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') && options ? (0, _tableAddWidth.createPlugin)(dispatch, options.fullWidthEnabled || false) : undefined;
|
|
184
|
+
}
|
|
178
185
|
}, {
|
|
179
186
|
name: 'tableGetEditorViewReferencePlugin',
|
|
180
187
|
plugin: function plugin() {
|
|
@@ -203,12 +210,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
203
210
|
}
|
|
204
211
|
return plugins;
|
|
205
212
|
},
|
|
206
|
-
contentComponent: function contentComponent(
|
|
207
|
-
var editorView =
|
|
208
|
-
popupsMountPoint =
|
|
209
|
-
popupsBoundariesElement =
|
|
210
|
-
popupsScrollableElement =
|
|
211
|
-
dispatchAnalyticsEvent =
|
|
213
|
+
contentComponent: function contentComponent(_ref9) {
|
|
214
|
+
var editorView = _ref9.editorView,
|
|
215
|
+
popupsMountPoint = _ref9.popupsMountPoint,
|
|
216
|
+
popupsBoundariesElement = _ref9.popupsBoundariesElement,
|
|
217
|
+
popupsScrollableElement = _ref9.popupsScrollableElement,
|
|
218
|
+
dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
|
|
212
219
|
return /*#__PURE__*/_react.default.createElement(_errorBoundary.ErrorBoundary, {
|
|
213
220
|
component: _analytics.ACTION_SUBJECT.TABLES_PLUGIN,
|
|
214
221
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -219,25 +226,25 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
219
226
|
tableResizingPluginState: _tableResizing.pluginKey,
|
|
220
227
|
stickyHeadersState: _stickyHeaders.pluginKey
|
|
221
228
|
},
|
|
222
|
-
render: function render(
|
|
223
|
-
var resizingPluginState =
|
|
224
|
-
stickyHeadersState =
|
|
225
|
-
tablePluginState =
|
|
229
|
+
render: function render(_ref10) {
|
|
230
|
+
var resizingPluginState = _ref10.tableResizingPluginState,
|
|
231
|
+
stickyHeadersState = _ref10.stickyHeadersState,
|
|
232
|
+
tablePluginState = _ref10.tablePluginState;
|
|
226
233
|
var state = editorView.state;
|
|
227
234
|
var isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
228
|
-
var
|
|
229
|
-
tableNode =
|
|
230
|
-
tablePos =
|
|
231
|
-
targetCellPosition =
|
|
232
|
-
isContextualMenuOpen =
|
|
233
|
-
layout =
|
|
234
|
-
tableRef =
|
|
235
|
-
pluginConfig =
|
|
236
|
-
insertColumnButtonIndex =
|
|
237
|
-
insertRowButtonIndex =
|
|
238
|
-
isHeaderColumnEnabled =
|
|
239
|
-
isHeaderRowEnabled =
|
|
240
|
-
tableWrapperTarget =
|
|
235
|
+
var _ref11 = tablePluginState,
|
|
236
|
+
tableNode = _ref11.tableNode,
|
|
237
|
+
tablePos = _ref11.tablePos,
|
|
238
|
+
targetCellPosition = _ref11.targetCellPosition,
|
|
239
|
+
isContextualMenuOpen = _ref11.isContextualMenuOpen,
|
|
240
|
+
layout = _ref11.layout,
|
|
241
|
+
tableRef = _ref11.tableRef,
|
|
242
|
+
pluginConfig = _ref11.pluginConfig,
|
|
243
|
+
insertColumnButtonIndex = _ref11.insertColumnButtonIndex,
|
|
244
|
+
insertRowButtonIndex = _ref11.insertRowButtonIndex,
|
|
245
|
+
isHeaderColumnEnabled = _ref11.isHeaderColumnEnabled,
|
|
246
|
+
isHeaderRowEnabled = _ref11.isHeaderRowEnabled,
|
|
247
|
+
tableWrapperTarget = _ref11.tableWrapperTarget;
|
|
241
248
|
var allowControls = pluginConfig.allowControls;
|
|
242
249
|
var stickyHeader = stickyHeadersState ? (0, _stickyHeaders.findStickyHeaderForTable)(stickyHeadersState, tablePos) : undefined;
|
|
243
250
|
var LayoutContent = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.custom-table-width') ? null : (0, _utils3.isLayoutSupported)(state) && options && options.breakoutEnabled ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
|
|
@@ -303,8 +310,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
303
310
|
}));
|
|
304
311
|
},
|
|
305
312
|
pluginsOptions: {
|
|
306
|
-
quickInsert: function quickInsert(
|
|
307
|
-
var formatMessage =
|
|
313
|
+
quickInsert: function quickInsert(_ref12) {
|
|
314
|
+
var formatMessage = _ref12.formatMessage;
|
|
308
315
|
return [{
|
|
309
316
|
id: 'table',
|
|
310
317
|
title: formatMessage(_messages.toolbarInsertBlockMessages.table),
|
|
@@ -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
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createPlugin = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
12
|
+
var _steps = require("@atlaskit/adf-schema/steps");
|
|
13
|
+
var _prosemirrorTransform = require("prosemirror-transform");
|
|
14
|
+
var _excluded = ["width"];
|
|
15
|
+
/**
|
|
16
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
|
|
22
|
+
return new _safePlugin.SafePlugin({
|
|
23
|
+
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
24
|
+
// When document first load in Confluence, initially it is an empty document
|
|
25
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
26
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
27
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
28
|
+
var isReplaceDocumentOperation = transactions.some(function (tr) {
|
|
29
|
+
if (tr.getMeta('replaceDocument')) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
var hasStepReplacingEntireDocument = tr.steps.some(function (step) {
|
|
33
|
+
if (!(step instanceof _prosemirrorTransform.ReplaceStep)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
var isStepReplacingFromDocStart = step.from === 0;
|
|
37
|
+
var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
|
|
38
|
+
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
});
|
|
43
|
+
return hasStepReplacingEntireDocument;
|
|
44
|
+
});
|
|
45
|
+
if (!isReplaceDocumentOperation) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
var tr = newState.tr;
|
|
49
|
+
var table = newState.schema.nodes.table;
|
|
50
|
+
newState.doc.forEach(function (node, offset, index) {
|
|
51
|
+
if (node.type === table) {
|
|
52
|
+
var width = node.attrs.width;
|
|
53
|
+
var layout = node.attrs.layout;
|
|
54
|
+
if (!width && layout) {
|
|
55
|
+
var tableWidthCal;
|
|
56
|
+
if (fullWidthEnabled) {
|
|
57
|
+
tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
|
|
58
|
+
} else {
|
|
59
|
+
switch (layout) {
|
|
60
|
+
case 'wide':
|
|
61
|
+
tableWidthCal = _editorSharedStyles.akEditorWideLayoutWidth;
|
|
62
|
+
break;
|
|
63
|
+
case 'full-width':
|
|
64
|
+
tableWidthCal = _editorSharedStyles.akEditorFullWidthLayoutWidth;
|
|
65
|
+
break;
|
|
66
|
+
// when in fix-width apprearance, no need to assign value to table width attr
|
|
67
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
68
|
+
default:
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var _node$attrs = node.attrs,
|
|
73
|
+
_width = _node$attrs.width,
|
|
74
|
+
rest = (0, _objectWithoutProperties2.default)(_node$attrs, _excluded);
|
|
75
|
+
if (tableWidthCal) {
|
|
76
|
+
tr.step(new _steps.SetAttrsStep(offset, _objectSpread({
|
|
77
|
+
width: tableWidthCal
|
|
78
|
+
}, rest)));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return tr;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
exports.createPlugin = createPlugin;
|
|
@@ -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;
|
package/dist/cjs/version.json
CHANGED
|
@@ -11,6 +11,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
11
11
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
12
12
|
import { pluginConfig } from './create-plugin-config';
|
|
13
13
|
import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
|
|
14
|
+
import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
|
|
14
15
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
15
16
|
import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
|
|
16
17
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
@@ -158,6 +159,11 @@ const tablesPlugin = (options, api) => {
|
|
|
158
159
|
plugin: ({
|
|
159
160
|
dispatch
|
|
160
161
|
}) => createTableLocalIdPlugin(dispatch)
|
|
162
|
+
}, {
|
|
163
|
+
name: 'tableAddWidth',
|
|
164
|
+
plugin: ({
|
|
165
|
+
dispatch
|
|
166
|
+
}) => getBooleanFF('platform.editor.custom-table-width') && options ? createTableAddWidthPlugin(dispatch, options.fullWidthEnabled || false) : undefined
|
|
161
167
|
}, {
|
|
162
168
|
name: 'tableGetEditorViewReferencePlugin',
|
|
163
169
|
plugin: () => {
|
|
@@ -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
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
8
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
9
|
+
import { ReplaceStep } from 'prosemirror-transform';
|
|
10
|
+
const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
|
|
11
|
+
appendTransaction: (transactions, _oldState, newState) => {
|
|
12
|
+
// When document first load in Confluence, initially it is an empty document
|
|
13
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
14
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
15
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
16
|
+
const isReplaceDocumentOperation = transactions.some(tr => {
|
|
17
|
+
if (tr.getMeta('replaceDocument')) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const hasStepReplacingEntireDocument = tr.steps.some(step => {
|
|
21
|
+
if (!(step instanceof ReplaceStep)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const isStepReplacingFromDocStart = step.from === 0;
|
|
25
|
+
const isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
|
|
26
|
+
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
return hasStepReplacingEntireDocument;
|
|
32
|
+
});
|
|
33
|
+
if (!isReplaceDocumentOperation) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const tr = newState.tr;
|
|
37
|
+
const {
|
|
38
|
+
table
|
|
39
|
+
} = newState.schema.nodes;
|
|
40
|
+
newState.doc.forEach((node, offset, index) => {
|
|
41
|
+
if (node.type === table) {
|
|
42
|
+
const width = node.attrs.width;
|
|
43
|
+
const layout = node.attrs.layout;
|
|
44
|
+
if (!width && layout) {
|
|
45
|
+
let tableWidthCal;
|
|
46
|
+
if (fullWidthEnabled) {
|
|
47
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
48
|
+
} else {
|
|
49
|
+
switch (layout) {
|
|
50
|
+
case 'wide':
|
|
51
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
52
|
+
break;
|
|
53
|
+
case 'full-width':
|
|
54
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
55
|
+
break;
|
|
56
|
+
// when in fix-width apprearance, no need to assign value to table width attr
|
|
57
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
58
|
+
default:
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const {
|
|
63
|
+
width,
|
|
64
|
+
...rest
|
|
65
|
+
} = node.attrs;
|
|
66
|
+
if (tableWidthCal) {
|
|
67
|
+
tr.step(new SetAttrsStep(offset, {
|
|
68
|
+
width: tableWidthCal,
|
|
69
|
+
...rest
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return tr;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
export { createPlugin };
|
|
@@ -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) => {
|
package/dist/es2019/version.json
CHANGED
|
@@ -11,6 +11,7 @@ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/
|
|
|
11
11
|
import { IconTable } from '@atlaskit/editor-common/icons';
|
|
12
12
|
import { pluginConfig } from './create-plugin-config';
|
|
13
13
|
import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
|
|
14
|
+
import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
|
|
14
15
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
15
16
|
import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
|
|
16
17
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
@@ -168,6 +169,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
168
169
|
var dispatch = _ref7.dispatch;
|
|
169
170
|
return createTableLocalIdPlugin(dispatch);
|
|
170
171
|
}
|
|
172
|
+
}, {
|
|
173
|
+
name: 'tableAddWidth',
|
|
174
|
+
plugin: function plugin(_ref8) {
|
|
175
|
+
var dispatch = _ref8.dispatch;
|
|
176
|
+
return getBooleanFF('platform.editor.custom-table-width') && options ? createTableAddWidthPlugin(dispatch, options.fullWidthEnabled || false) : undefined;
|
|
177
|
+
}
|
|
171
178
|
}, {
|
|
172
179
|
name: 'tableGetEditorViewReferencePlugin',
|
|
173
180
|
plugin: function plugin() {
|
|
@@ -196,12 +203,12 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
196
203
|
}
|
|
197
204
|
return plugins;
|
|
198
205
|
},
|
|
199
|
-
contentComponent: function contentComponent(
|
|
200
|
-
var editorView =
|
|
201
|
-
popupsMountPoint =
|
|
202
|
-
popupsBoundariesElement =
|
|
203
|
-
popupsScrollableElement =
|
|
204
|
-
dispatchAnalyticsEvent =
|
|
206
|
+
contentComponent: function contentComponent(_ref9) {
|
|
207
|
+
var editorView = _ref9.editorView,
|
|
208
|
+
popupsMountPoint = _ref9.popupsMountPoint,
|
|
209
|
+
popupsBoundariesElement = _ref9.popupsBoundariesElement,
|
|
210
|
+
popupsScrollableElement = _ref9.popupsScrollableElement,
|
|
211
|
+
dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
|
|
205
212
|
return /*#__PURE__*/React.createElement(ErrorBoundary, {
|
|
206
213
|
component: ACTION_SUBJECT.TABLES_PLUGIN,
|
|
207
214
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
@@ -212,25 +219,25 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
212
219
|
tableResizingPluginState: tableResizingPluginKey,
|
|
213
220
|
stickyHeadersState: stickyHeadersPluginKey
|
|
214
221
|
},
|
|
215
|
-
render: function render(
|
|
216
|
-
var resizingPluginState =
|
|
217
|
-
stickyHeadersState =
|
|
218
|
-
tablePluginState =
|
|
222
|
+
render: function render(_ref10) {
|
|
223
|
+
var resizingPluginState = _ref10.tableResizingPluginState,
|
|
224
|
+
stickyHeadersState = _ref10.stickyHeadersState,
|
|
225
|
+
tablePluginState = _ref10.tablePluginState;
|
|
219
226
|
var state = editorView.state;
|
|
220
227
|
var isDragging = resizingPluginState === null || resizingPluginState === void 0 ? void 0 : resizingPluginState.dragging;
|
|
221
|
-
var
|
|
222
|
-
tableNode =
|
|
223
|
-
tablePos =
|
|
224
|
-
targetCellPosition =
|
|
225
|
-
isContextualMenuOpen =
|
|
226
|
-
layout =
|
|
227
|
-
tableRef =
|
|
228
|
-
pluginConfig =
|
|
229
|
-
insertColumnButtonIndex =
|
|
230
|
-
insertRowButtonIndex =
|
|
231
|
-
isHeaderColumnEnabled =
|
|
232
|
-
isHeaderRowEnabled =
|
|
233
|
-
tableWrapperTarget =
|
|
228
|
+
var _ref11 = tablePluginState,
|
|
229
|
+
tableNode = _ref11.tableNode,
|
|
230
|
+
tablePos = _ref11.tablePos,
|
|
231
|
+
targetCellPosition = _ref11.targetCellPosition,
|
|
232
|
+
isContextualMenuOpen = _ref11.isContextualMenuOpen,
|
|
233
|
+
layout = _ref11.layout,
|
|
234
|
+
tableRef = _ref11.tableRef,
|
|
235
|
+
pluginConfig = _ref11.pluginConfig,
|
|
236
|
+
insertColumnButtonIndex = _ref11.insertColumnButtonIndex,
|
|
237
|
+
insertRowButtonIndex = _ref11.insertRowButtonIndex,
|
|
238
|
+
isHeaderColumnEnabled = _ref11.isHeaderColumnEnabled,
|
|
239
|
+
isHeaderRowEnabled = _ref11.isHeaderRowEnabled,
|
|
240
|
+
tableWrapperTarget = _ref11.tableWrapperTarget;
|
|
234
241
|
var allowControls = pluginConfig.allowControls;
|
|
235
242
|
var stickyHeader = stickyHeadersState ? findStickyHeaderForTable(stickyHeadersState, tablePos) : undefined;
|
|
236
243
|
var LayoutContent = getBooleanFF('platform.editor.custom-table-width') ? null : isLayoutSupported(state) && options && options.breakoutEnabled ? /*#__PURE__*/React.createElement(LayoutButton, {
|
|
@@ -296,8 +303,8 @@ var tablesPlugin = function tablesPlugin(options, api) {
|
|
|
296
303
|
}));
|
|
297
304
|
},
|
|
298
305
|
pluginsOptions: {
|
|
299
|
-
quickInsert: function quickInsert(
|
|
300
|
-
var formatMessage =
|
|
306
|
+
quickInsert: function quickInsert(_ref12) {
|
|
307
|
+
var formatMessage = _ref12.formatMessage;
|
|
301
308
|
return [{
|
|
302
309
|
id: 'table',
|
|
303
310
|
title: formatMessage(messages.table),
|
|
@@ -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
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["width"];
|
|
4
|
+
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; }
|
|
5
|
+
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) { _defineProperty(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; }
|
|
6
|
+
/**
|
|
7
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
12
|
+
import { akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
13
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
14
|
+
import { ReplaceStep } from 'prosemirror-transform';
|
|
15
|
+
var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
|
|
16
|
+
return new SafePlugin({
|
|
17
|
+
appendTransaction: function appendTransaction(transactions, _oldState, newState) {
|
|
18
|
+
// When document first load in Confluence, initially it is an empty document
|
|
19
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
20
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
21
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
22
|
+
var isReplaceDocumentOperation = transactions.some(function (tr) {
|
|
23
|
+
if (tr.getMeta('replaceDocument')) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
var hasStepReplacingEntireDocument = tr.steps.some(function (step) {
|
|
27
|
+
if (!(step instanceof ReplaceStep)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var isStepReplacingFromDocStart = step.from === 0;
|
|
31
|
+
var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
|
|
32
|
+
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
return hasStepReplacingEntireDocument;
|
|
38
|
+
});
|
|
39
|
+
if (!isReplaceDocumentOperation) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
var tr = newState.tr;
|
|
43
|
+
var table = newState.schema.nodes.table;
|
|
44
|
+
newState.doc.forEach(function (node, offset, index) {
|
|
45
|
+
if (node.type === table) {
|
|
46
|
+
var width = node.attrs.width;
|
|
47
|
+
var layout = node.attrs.layout;
|
|
48
|
+
if (!width && layout) {
|
|
49
|
+
var tableWidthCal;
|
|
50
|
+
if (fullWidthEnabled) {
|
|
51
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
52
|
+
} else {
|
|
53
|
+
switch (layout) {
|
|
54
|
+
case 'wide':
|
|
55
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
56
|
+
break;
|
|
57
|
+
case 'full-width':
|
|
58
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
59
|
+
break;
|
|
60
|
+
// when in fix-width apprearance, no need to assign value to table width attr
|
|
61
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
62
|
+
default:
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
var _node$attrs = node.attrs,
|
|
67
|
+
_width = _node$attrs.width,
|
|
68
|
+
rest = _objectWithoutProperties(_node$attrs, _excluded);
|
|
69
|
+
if (tableWidthCal) {
|
|
70
|
+
tr.step(new SetAttrsStep(offset, _objectSpread({
|
|
71
|
+
width: tableWidthCal
|
|
72
|
+
}, rest)));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return tr;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
export { createPlugin };
|
|
@@ -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) {
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<any, any>;
|
|
8
|
+
export { createPlugin };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<any, any>;
|
|
8
|
+
export { createPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
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",
|
|
@@ -37,6 +37,7 @@ import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
|
|
|
37
37
|
|
|
38
38
|
import { pluginConfig } from './create-plugin-config';
|
|
39
39
|
import { createPlugin as createTableLocalIdPlugin } from './pm-plugins/table-local-id';
|
|
40
|
+
import { createPlugin as createTableAddWidthPlugin } from './pm-plugins/table-add-width';
|
|
40
41
|
import { createPlugin as createTableSafariDeleteCompositionTextIssueWorkaroundPlugin } from './pm-plugins/safari-delete-composition-text-issue-workaround';
|
|
41
42
|
import { createPlugin as createDecorationsPlugin } from './pm-plugins/decorations/plugin';
|
|
42
43
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
@@ -268,6 +269,16 @@ const tablesPlugin: NextEditorPlugin<
|
|
|
268
269
|
name: 'tableLocalId',
|
|
269
270
|
plugin: ({ dispatch }) => createTableLocalIdPlugin(dispatch),
|
|
270
271
|
},
|
|
272
|
+
{
|
|
273
|
+
name: 'tableAddWidth',
|
|
274
|
+
plugin: ({ dispatch }) =>
|
|
275
|
+
getBooleanFF('platform.editor.custom-table-width') && options
|
|
276
|
+
? createTableAddWidthPlugin(
|
|
277
|
+
dispatch,
|
|
278
|
+
options.fullWidthEnabled || false,
|
|
279
|
+
)
|
|
280
|
+
: undefined,
|
|
281
|
+
},
|
|
271
282
|
|
|
272
283
|
{
|
|
273
284
|
name: 'tableGetEditorViewReferencePlugin',
|
|
@@ -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);
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin for scan the document, add width value to table's width attribute when necessary
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
6
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
+
import {
|
|
8
|
+
akEditorFullWidthLayoutWidth,
|
|
9
|
+
akEditorWideLayoutWidth,
|
|
10
|
+
} from '@atlaskit/editor-shared-styles';
|
|
11
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
12
|
+
import { ReplaceStep } from 'prosemirror-transform';
|
|
13
|
+
|
|
14
|
+
type __ReplaceStep = ReplaceStep & {
|
|
15
|
+
// Properties `to` and `from` are private attributes of ReplaceStep.
|
|
16
|
+
to: number;
|
|
17
|
+
from: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
|
|
21
|
+
new SafePlugin({
|
|
22
|
+
appendTransaction: (transactions, _oldState, newState) => {
|
|
23
|
+
// When document first load in Confluence, initially it is an empty document
|
|
24
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
25
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
26
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
27
|
+
const isReplaceDocumentOperation = transactions.some((tr) => {
|
|
28
|
+
if (tr.getMeta('replaceDocument')) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const hasStepReplacingEntireDocument = tr.steps.some((step) => {
|
|
33
|
+
if (!(step instanceof ReplaceStep)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isStepReplacingFromDocStart =
|
|
38
|
+
(step as __ReplaceStep).from === 0;
|
|
39
|
+
const isStepReplacingUntilTheEndOfDocument =
|
|
40
|
+
(step as __ReplaceStep).to === _oldState.doc.content.size;
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
!isStepReplacingFromDocStart ||
|
|
44
|
+
!isStepReplacingUntilTheEndOfDocument
|
|
45
|
+
) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return hasStepReplacingEntireDocument;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (!isReplaceDocumentOperation) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const tr = newState.tr;
|
|
59
|
+
const { table } = newState.schema.nodes;
|
|
60
|
+
|
|
61
|
+
newState.doc.forEach((node, offset, index) => {
|
|
62
|
+
if (node.type === table) {
|
|
63
|
+
const width = node.attrs.width;
|
|
64
|
+
const layout = node.attrs.layout;
|
|
65
|
+
|
|
66
|
+
if (!width && layout) {
|
|
67
|
+
let tableWidthCal;
|
|
68
|
+
|
|
69
|
+
if (fullWidthEnabled) {
|
|
70
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
71
|
+
} else {
|
|
72
|
+
switch (layout) {
|
|
73
|
+
case 'wide':
|
|
74
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
75
|
+
break;
|
|
76
|
+
case 'full-width':
|
|
77
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
78
|
+
break;
|
|
79
|
+
// when in fix-width apprearance, no need to assign value to table width attr
|
|
80
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
81
|
+
default:
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const { width, ...rest } = node.attrs;
|
|
87
|
+
|
|
88
|
+
if (tableWidthCal) {
|
|
89
|
+
tr.step(
|
|
90
|
+
new SetAttrsStep(offset, {
|
|
91
|
+
width: tableWidthCal,
|
|
92
|
+
...rest,
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return tr;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export { createPlugin };
|
|
@@ -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
|
};
|