@atlaskit/editor-plugin-table 7.16.4 → 7.16.6
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 +17 -0
- package/dist/cjs/commands/insert.js +15 -6
- package/dist/cjs/plugin.js +16 -6
- package/dist/cjs/pm-plugins/keymap.js +5 -4
- package/dist/cjs/pm-plugins/table-width.js +13 -6
- package/dist/cjs/utils/alignment.js +5 -2
- package/dist/cjs/utils/create.js +12 -7
- package/dist/es2019/commands/insert.js +15 -6
- package/dist/es2019/plugin.js +15 -6
- package/dist/es2019/pm-plugins/keymap.js +2 -2
- package/dist/es2019/pm-plugins/table-width.js +13 -6
- package/dist/es2019/utils/alignment.js +4 -1
- package/dist/es2019/utils/create.js +13 -7
- package/dist/esm/commands/insert.js +15 -6
- package/dist/esm/plugin.js +16 -6
- package/dist/esm/pm-plugins/keymap.js +5 -4
- package/dist/esm/pm-plugins/table-width.js +13 -6
- package/dist/esm/utils/alignment.js +4 -1
- package/dist/esm/utils/create.js +12 -7
- package/dist/types/commands/insert.d.ts +2 -2
- package/dist/types/pm-plugins/keymap.d.ts +1 -1
- package/dist/types/pm-plugins/table-width.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +2 -0
- package/dist/types/utils/create.d.ts +8 -3
- package/dist/types-ts4.5/commands/insert.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +2 -0
- package/dist/types-ts4.5/utils/create.d.ts +8 -3
- package/package.json +4 -4
- package/src/commands/insert.ts +28 -22
- package/src/plugin.tsx +14 -8
- package/src/pm-plugins/keymap.ts +2 -0
- package/src/pm-plugins/table-width.ts +19 -5
- package/src/utils/alignment.ts +4 -1
- package/src/utils/create.ts +24 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 7.16.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#102478](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102478)
|
|
8
|
+
[`3378951608b0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3378951608b0) -
|
|
9
|
+
[ED-23332] Update adf-schema package to 36.10.1
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 7.16.5
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#102210](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102210)
|
|
17
|
+
[`fe0d7aa7668a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fe0d7aa7668a) -
|
|
18
|
+
Set layout attribute for tables to align-left when inserted in full width editor
|
|
19
|
+
|
|
3
20
|
## 7.16.4
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -143,9 +143,13 @@ var insertRow = exports.insertRow = function insertRow(row, moveCursorToTheNewRo
|
|
|
143
143
|
return true;
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
|
-
var createTable = exports.createTable = function createTable(isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
146
|
+
var createTable = exports.createTable = function createTable(isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
147
147
|
return function (state, dispatch) {
|
|
148
|
-
var table = (0, _utils3.createTableWithWidth)(
|
|
148
|
+
var table = (0, _utils3.createTableWithWidth)({
|
|
149
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
150
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
151
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled
|
|
152
|
+
})(state.schema);
|
|
149
153
|
if (dispatch) {
|
|
150
154
|
var tr = (0, _utils.safeInsert)(table)(state.tr).scrollIntoView();
|
|
151
155
|
if (editorAnalyticsAPI) {
|
|
@@ -164,13 +168,18 @@ var createTable = exports.createTable = function createTable(isTableScalingEnabl
|
|
|
164
168
|
return true;
|
|
165
169
|
};
|
|
166
170
|
};
|
|
167
|
-
var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, isTableScalingEnabled, editorAnalyticsAPI) {
|
|
171
|
+
var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, isTableScalingEnabled, isTableAlignmentEnabled, editorAnalyticsAPI) {
|
|
168
172
|
return function (rowsCount, colsCount, inputMethod) {
|
|
169
173
|
return function (_ref) {
|
|
170
174
|
var tr = _ref.tr;
|
|
171
|
-
var tableNode = (0, _utils3.createTableWithWidth)(
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
var tableNode = (0, _utils3.createTableWithWidth)({
|
|
176
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
177
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled,
|
|
178
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
179
|
+
createTableProps: {
|
|
180
|
+
rowsCount: rowsCount,
|
|
181
|
+
colsCount: colsCount
|
|
182
|
+
}
|
|
174
183
|
})(tr.doc.type.schema);
|
|
175
184
|
var newTr = (0, _utils.safeInsert)(tableNode)(tr).scrollIntoView();
|
|
176
185
|
if (inputMethod) {
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -106,7 +106,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
106
106
|
insertTable: function insertTable(analyticsPayload) {
|
|
107
107
|
return function (state, dispatch) {
|
|
108
108
|
var _api$contentInsertion, _api$contentInsertion2;
|
|
109
|
-
var node = (0, _utils2.createTableWithWidth)(
|
|
109
|
+
var node = (0, _utils2.createTableWithWidth)({
|
|
110
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
111
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
112
|
+
isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled
|
|
113
|
+
})(state.schema);
|
|
110
114
|
return (_api$contentInsertion = api === null || api === void 0 || (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 || (_api$contentInsertion2 = _api$contentInsertion2.actions) === null || _api$contentInsertion2 === void 0 ? void 0 : _api$contentInsertion2.insert({
|
|
111
115
|
state: state,
|
|
112
116
|
dispatch: dispatch,
|
|
@@ -124,7 +128,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
124
128
|
}
|
|
125
129
|
},
|
|
126
130
|
commands: {
|
|
127
|
-
insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
131
|
+
insertTableWithSize: (0, _insert.insertTableWithSize)(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
128
132
|
},
|
|
129
133
|
nodes: function nodes() {
|
|
130
134
|
return [{
|
|
@@ -192,9 +196,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
192
196
|
dragAndDropEnabled = _ref7.dragAndDropEnabled,
|
|
193
197
|
_ref7$isTableScalingE = _ref7.isTableScalingEnabled,
|
|
194
198
|
isTableScalingEnabled = _ref7$isTableScalingE === void 0 ? false : _ref7$isTableScalingE,
|
|
199
|
+
_ref7$isTableAlignmen = _ref7.isTableAlignmentEnabled,
|
|
200
|
+
isTableAlignmentEnabled = _ref7$isTableAlignmen === void 0 ? false : _ref7$isTableAlignmen,
|
|
195
201
|
_ref7$fullWidthEnable = _ref7.fullWidthEnabled,
|
|
196
202
|
fullWidthEnabled = _ref7$fullWidthEnable === void 0 ? false : _ref7$fullWidthEnable;
|
|
197
|
-
return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled, api, getIntl);
|
|
203
|
+
return (0, _keymap.keymapPlugin)(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, isTableAlignmentEnabled, fullWidthEnabled, api, getIntl);
|
|
198
204
|
}
|
|
199
205
|
}, {
|
|
200
206
|
name: 'tableSelectionKeymap',
|
|
@@ -252,10 +258,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
252
258
|
}, {
|
|
253
259
|
name: 'tableWidth',
|
|
254
260
|
plugin: function plugin(_ref13) {
|
|
255
|
-
var _options$fullWidthEna, _options$isTableScali;
|
|
261
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
256
262
|
var dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent,
|
|
257
263
|
dispatch = _ref13.dispatch;
|
|
258
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false) : undefined;
|
|
264
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false) : undefined;
|
|
259
265
|
}
|
|
260
266
|
},
|
|
261
267
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -442,7 +448,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
442
448
|
var _api$table;
|
|
443
449
|
// see comment on tablesPlugin.getSharedState on usage
|
|
444
450
|
var tableState = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
445
|
-
var tableNode = (0, _utils2.createTableWithWidth)(
|
|
451
|
+
var tableNode = (0, _utils2.createTableWithWidth)({
|
|
452
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
453
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
454
|
+
isFullWidthModeEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled
|
|
455
|
+
})(state.schema);
|
|
446
456
|
var tr = insert(tableNode);
|
|
447
457
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
448
458
|
action: _analytics.ACTION.INSERTED,
|
|
@@ -18,14 +18,15 @@ var _commandsWithAnalytics2 = require("../pm-plugins/drag-and-drop/commands-with
|
|
|
18
18
|
function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
19
19
|
var _pluginInjectionApi$a;
|
|
20
20
|
var isTableScalingEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
21
|
+
var isTableAlignmentEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
22
|
+
var isFullWidthEnabled = arguments.length > 5 ? arguments[5] : undefined;
|
|
23
|
+
var pluginInjectionApi = arguments.length > 6 ? arguments[6] : undefined;
|
|
24
|
+
var getIntl = arguments.length > 7 ? arguments[7] : undefined;
|
|
24
25
|
var list = {};
|
|
25
26
|
var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
|
|
26
27
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
|
|
27
28
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
|
|
28
|
-
(0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, (0, _insert.createTable)(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
29
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, (0, _insert.createTable)(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
29
30
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, (0, _commands.chainCommands)((0, _commandsWithAnalytics.deleteTableIfSelectedWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), (0, _commandsWithAnalytics.emptyMultipleCellsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)), list);
|
|
30
31
|
(0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, _commands2.moveCursorBackward, list);
|
|
31
32
|
|
|
@@ -14,6 +14,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
14
14
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
15
15
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
16
16
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
17
|
+
var _alignment = require("../utils/alignment");
|
|
17
18
|
var _utils2 = require("./table-resizing/utils");
|
|
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; }
|
|
@@ -23,7 +24,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
23
24
|
* Also holds resizing state to hide / show table controls
|
|
24
25
|
*/
|
|
25
26
|
var pluginKey = exports.pluginKey = new _state.PluginKey('tableWidthPlugin');
|
|
26
|
-
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) {
|
|
27
|
+
var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) {
|
|
27
28
|
return new _safePlugin.SafePlugin({
|
|
28
29
|
key: pluginKey,
|
|
29
30
|
state: {
|
|
@@ -96,8 +97,9 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
96
97
|
var referentialityTr = transactions.find(function (tr) {
|
|
97
98
|
return tr.getMeta('referentialityTableInserted');
|
|
98
99
|
});
|
|
99
|
-
var
|
|
100
|
-
|
|
100
|
+
var shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
101
|
+
var shouldPatchTableAlignment = fullWidthEnabled && isTableAlignmentEnabled;
|
|
102
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTableWidth && !shouldPatchTableAlignment || !referentialityTr)) {
|
|
101
103
|
return null;
|
|
102
104
|
}
|
|
103
105
|
var table = newState.schema.nodes.table;
|
|
@@ -157,10 +159,15 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
157
159
|
}
|
|
158
160
|
if (referentialityTr) {
|
|
159
161
|
referentialityTr.steps.forEach(function (step) {
|
|
160
|
-
step.getMap().forEach(function (
|
|
162
|
+
step.getMap().forEach(function (_, __, newStart, newEnd) {
|
|
161
163
|
newState.doc.nodesBetween(newStart, newEnd, function (node, pos) {
|
|
162
|
-
if (node.type === table
|
|
163
|
-
|
|
164
|
+
if (node.type === table) {
|
|
165
|
+
if (shouldPatchTableWidth && node.attrs.width !== _utils2.TABLE_MAX_WIDTH) {
|
|
166
|
+
tr.setNodeAttribute(pos, 'width', _utils2.TABLE_MAX_WIDTH);
|
|
167
|
+
}
|
|
168
|
+
if (shouldPatchTableAlignment) {
|
|
169
|
+
tr.setNodeAttribute(pos, 'layout', _alignment.ALIGN_START);
|
|
170
|
+
}
|
|
164
171
|
}
|
|
165
172
|
});
|
|
166
173
|
});
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.normaliseAlignment = void 0;
|
|
6
|
+
exports.normaliseAlignment = exports.ALIGN_START = exports.ALIGN_CENTER = void 0;
|
|
7
|
+
var ALIGN_START = exports.ALIGN_START = 'align-start';
|
|
8
|
+
var ALIGN_CENTER = exports.ALIGN_CENTER = 'center';
|
|
9
|
+
|
|
7
10
|
/**
|
|
8
11
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
9
12
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
10
13
|
*/
|
|
11
14
|
var normaliseAlignment = exports.normaliseAlignment = function normaliseAlignment(layout) {
|
|
12
|
-
return layout ===
|
|
15
|
+
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
13
16
|
};
|
package/dist/cjs/utils/create.js
CHANGED
|
@@ -10,16 +10,21 @@ var _utils = require("@atlaskit/editor-tables/utils");
|
|
|
10
10
|
var _utils2 = require("../pm-plugins/table-resizing/utils");
|
|
11
11
|
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; }
|
|
12
12
|
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; }
|
|
13
|
-
var createTableWithWidth = exports.createTableWithWidth = function createTableWithWidth(
|
|
13
|
+
var createTableWithWidth = exports.createTableWithWidth = function createTableWithWidth(_ref) {
|
|
14
|
+
var isTableScalingEnabled = _ref.isTableScalingEnabled,
|
|
15
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled,
|
|
16
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled,
|
|
17
|
+
createTableProps = _ref.createTableProps;
|
|
14
18
|
return function (schema) {
|
|
19
|
+
var attrsOverrides = {};
|
|
15
20
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
16
|
-
|
|
17
|
-
schema: schema,
|
|
18
|
-
tableWidth: _utils2.TABLE_MAX_WIDTH
|
|
19
|
-
}, createTableProps));
|
|
21
|
+
attrsOverrides.tableWidth = _utils2.TABLE_MAX_WIDTH;
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
24
|
+
attrsOverrides.layout = 'align-start';
|
|
25
|
+
}
|
|
26
|
+
return (0, _utils.createTable)(_objectSpread(_objectSpread({
|
|
22
27
|
schema: schema
|
|
23
|
-
}, createTableProps));
|
|
28
|
+
}, createTableProps), attrsOverrides));
|
|
24
29
|
};
|
|
25
30
|
};
|
|
@@ -119,8 +119,12 @@ export const insertRow = (row, moveCursorToTheNewRow, isCellBackgroundDuplicated
|
|
|
119
119
|
}
|
|
120
120
|
return true;
|
|
121
121
|
};
|
|
122
|
-
export const createTable = (isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) => (state, dispatch) => {
|
|
123
|
-
const table = createTableWithWidth(
|
|
122
|
+
export const createTable = (isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) => (state, dispatch) => {
|
|
123
|
+
const table = createTableWithWidth({
|
|
124
|
+
isTableScalingEnabled,
|
|
125
|
+
isTableAlignmentEnabled,
|
|
126
|
+
isFullWidthModeEnabled
|
|
127
|
+
})(state.schema);
|
|
124
128
|
if (dispatch) {
|
|
125
129
|
const tr = safeInsert(table)(state.tr).scrollIntoView();
|
|
126
130
|
if (editorAnalyticsAPI) {
|
|
@@ -138,13 +142,18 @@ export const createTable = (isTableScalingEnabled, isFullWidthModeEnabled, edito
|
|
|
138
142
|
}
|
|
139
143
|
return true;
|
|
140
144
|
};
|
|
141
|
-
export const insertTableWithSize = (isFullWidthModeEnabled, isTableScalingEnabled, editorAnalyticsAPI) => (rowsCount, colsCount, inputMethod) => {
|
|
145
|
+
export const insertTableWithSize = (isFullWidthModeEnabled, isTableScalingEnabled, isTableAlignmentEnabled, editorAnalyticsAPI) => (rowsCount, colsCount, inputMethod) => {
|
|
142
146
|
return ({
|
|
143
147
|
tr
|
|
144
148
|
}) => {
|
|
145
|
-
const tableNode = createTableWithWidth(
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
const tableNode = createTableWithWidth({
|
|
150
|
+
isTableScalingEnabled,
|
|
151
|
+
isFullWidthModeEnabled,
|
|
152
|
+
isTableAlignmentEnabled,
|
|
153
|
+
createTableProps: {
|
|
154
|
+
rowsCount: rowsCount,
|
|
155
|
+
colsCount: colsCount
|
|
156
|
+
}
|
|
148
157
|
})(tr.doc.type.schema);
|
|
149
158
|
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
150
159
|
if (inputMethod) {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -94,7 +94,11 @@ const tablesPlugin = ({
|
|
|
94
94
|
actions: {
|
|
95
95
|
insertTable: analyticsPayload => (state, dispatch) => {
|
|
96
96
|
var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
|
|
97
|
-
const node = createTableWithWidth(
|
|
97
|
+
const node = createTableWithWidth({
|
|
98
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
99
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
100
|
+
isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled
|
|
101
|
+
})(state.schema);
|
|
98
102
|
return (_api$contentInsertion = api === null || api === void 0 ? void 0 : (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 ? void 0 : (_api$contentInsertion3 = _api$contentInsertion2.actions) === null || _api$contentInsertion3 === void 0 ? void 0 : _api$contentInsertion3.insert({
|
|
99
103
|
state,
|
|
100
104
|
dispatch,
|
|
@@ -113,7 +117,7 @@ const tablesPlugin = ({
|
|
|
113
117
|
}
|
|
114
118
|
},
|
|
115
119
|
commands: {
|
|
116
|
-
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
120
|
+
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
117
121
|
},
|
|
118
122
|
nodes() {
|
|
119
123
|
return [{
|
|
@@ -184,9 +188,10 @@ const tablesPlugin = ({
|
|
|
184
188
|
const {
|
|
185
189
|
dragAndDropEnabled,
|
|
186
190
|
isTableScalingEnabled = false,
|
|
191
|
+
isTableAlignmentEnabled = false,
|
|
187
192
|
fullWidthEnabled = false
|
|
188
193
|
} = options || {};
|
|
189
|
-
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled, api, getIntl);
|
|
194
|
+
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, isTableAlignmentEnabled, fullWidthEnabled, api, getIntl);
|
|
190
195
|
}
|
|
191
196
|
}, {
|
|
192
197
|
name: 'tableSelectionKeymap',
|
|
@@ -244,8 +249,8 @@ const tablesPlugin = ({
|
|
|
244
249
|
dispatchAnalyticsEvent,
|
|
245
250
|
dispatch
|
|
246
251
|
}) => {
|
|
247
|
-
var _options$fullWidthEna, _options$isTableScali;
|
|
248
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false) : undefined;
|
|
252
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
253
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false) : undefined;
|
|
249
254
|
}
|
|
250
255
|
},
|
|
251
256
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -435,7 +440,11 @@ const tablesPlugin = ({
|
|
|
435
440
|
var _api$table;
|
|
436
441
|
// see comment on tablesPlugin.getSharedState on usage
|
|
437
442
|
const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
438
|
-
const tableNode = createTableWithWidth(
|
|
443
|
+
const tableNode = createTableWithWidth({
|
|
444
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
445
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
446
|
+
isFullWidthModeEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled
|
|
447
|
+
})(state.schema);
|
|
439
448
|
const tr = insert(tableNode);
|
|
440
449
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
441
450
|
action: ACTION.INSERTED,
|
|
@@ -8,13 +8,13 @@ import { addRowAroundSelection, changeColumnWidthByStepWithAnalytics, deleteSele
|
|
|
8
8
|
import { activateNextResizeArea, initiateKeyboardColumnResizing, stopKeyboardColumnResizing } from '../commands/column-resize';
|
|
9
9
|
import { addColumnAfter as addColumnAfterCommand, addColumnBefore as addColumnBeforeCommand, createTable } from '../commands/insert';
|
|
10
10
|
import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/commands-with-analytics';
|
|
11
|
-
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false, isFullWidthEnabled, pluginInjectionApi, getIntl) {
|
|
11
|
+
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled = false, isTableAlignmentEnabled = false, isFullWidthEnabled, pluginInjectionApi, getIntl) {
|
|
12
12
|
var _pluginInjectionApi$a;
|
|
13
13
|
const list = {};
|
|
14
14
|
const ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
|
|
15
15
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
|
|
16
16
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
|
|
17
|
-
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
17
|
+
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
18
18
|
bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
|
|
19
19
|
bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
|
|
20
20
|
|
|
@@ -11,9 +11,10 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
11
11
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
12
12
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
13
13
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
14
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
14
15
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
15
16
|
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
16
|
-
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) => {
|
|
17
|
+
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) => {
|
|
17
18
|
return new SafePlugin({
|
|
18
19
|
key: pluginKey,
|
|
19
20
|
state: {
|
|
@@ -87,8 +88,9 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTabl
|
|
|
87
88
|
return hasStepReplacingEntireDocument;
|
|
88
89
|
});
|
|
89
90
|
const referentialityTr = transactions.find(tr => tr.getMeta('referentialityTableInserted'));
|
|
90
|
-
const
|
|
91
|
-
|
|
91
|
+
const shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
92
|
+
const shouldPatchTableAlignment = fullWidthEnabled && isTableAlignmentEnabled;
|
|
93
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTableWidth && !shouldPatchTableAlignment || !referentialityTr)) {
|
|
92
94
|
return null;
|
|
93
95
|
}
|
|
94
96
|
const {
|
|
@@ -152,10 +154,15 @@ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTabl
|
|
|
152
154
|
}
|
|
153
155
|
if (referentialityTr) {
|
|
154
156
|
referentialityTr.steps.forEach(step => {
|
|
155
|
-
step.getMap().forEach((
|
|
157
|
+
step.getMap().forEach((_, __, newStart, newEnd) => {
|
|
156
158
|
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
157
|
-
if (node.type === table
|
|
158
|
-
|
|
159
|
+
if (node.type === table) {
|
|
160
|
+
if (shouldPatchTableWidth && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
161
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
162
|
+
}
|
|
163
|
+
if (shouldPatchTableAlignment) {
|
|
164
|
+
tr.setNodeAttribute(pos, 'layout', ALIGN_START);
|
|
165
|
+
}
|
|
159
166
|
}
|
|
160
167
|
});
|
|
161
168
|
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export const ALIGN_START = 'align-start';
|
|
2
|
+
export const ALIGN_CENTER = 'center';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
3
6
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
4
7
|
*/
|
|
5
|
-
export const normaliseAlignment = layout => layout ===
|
|
8
|
+
export const normaliseAlignment = layout => layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
2
2
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
3
|
-
export const createTableWithWidth = (
|
|
3
|
+
export const createTableWithWidth = ({
|
|
4
|
+
isTableScalingEnabled,
|
|
5
|
+
isTableAlignmentEnabled,
|
|
6
|
+
isFullWidthModeEnabled,
|
|
7
|
+
createTableProps
|
|
8
|
+
}) => schema => {
|
|
9
|
+
const attrsOverrides = {};
|
|
4
10
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
11
|
+
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
12
|
+
}
|
|
13
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
14
|
+
attrsOverrides.layout = 'align-start';
|
|
10
15
|
}
|
|
11
16
|
return createTable({
|
|
12
17
|
schema,
|
|
13
|
-
...createTableProps
|
|
18
|
+
...createTableProps,
|
|
19
|
+
...attrsOverrides
|
|
14
20
|
});
|
|
15
21
|
};
|
|
@@ -134,9 +134,13 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow, isCellBack
|
|
|
134
134
|
return true;
|
|
135
135
|
};
|
|
136
136
|
};
|
|
137
|
-
export var createTable = function createTable(isTableScalingEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
137
|
+
export var createTable = function createTable(isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, editorAnalyticsAPI) {
|
|
138
138
|
return function (state, dispatch) {
|
|
139
|
-
var table = createTableWithWidth(
|
|
139
|
+
var table = createTableWithWidth({
|
|
140
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
141
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
142
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled
|
|
143
|
+
})(state.schema);
|
|
140
144
|
if (dispatch) {
|
|
141
145
|
var tr = safeInsert(table)(state.tr).scrollIntoView();
|
|
142
146
|
if (editorAnalyticsAPI) {
|
|
@@ -155,13 +159,18 @@ export var createTable = function createTable(isTableScalingEnabled, isFullWidth
|
|
|
155
159
|
return true;
|
|
156
160
|
};
|
|
157
161
|
};
|
|
158
|
-
export var insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, isTableScalingEnabled, editorAnalyticsAPI) {
|
|
162
|
+
export var insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, isTableScalingEnabled, isTableAlignmentEnabled, editorAnalyticsAPI) {
|
|
159
163
|
return function (rowsCount, colsCount, inputMethod) {
|
|
160
164
|
return function (_ref) {
|
|
161
165
|
var tr = _ref.tr;
|
|
162
|
-
var tableNode = createTableWithWidth(
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
var tableNode = createTableWithWidth({
|
|
167
|
+
isTableScalingEnabled: isTableScalingEnabled,
|
|
168
|
+
isFullWidthModeEnabled: isFullWidthModeEnabled,
|
|
169
|
+
isTableAlignmentEnabled: isTableAlignmentEnabled,
|
|
170
|
+
createTableProps: {
|
|
171
|
+
rowsCount: rowsCount,
|
|
172
|
+
colsCount: colsCount
|
|
173
|
+
}
|
|
165
174
|
})(tr.doc.type.schema);
|
|
166
175
|
var newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
167
176
|
if (inputMethod) {
|
package/dist/esm/plugin.js
CHANGED
|
@@ -99,7 +99,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
99
99
|
insertTable: function insertTable(analyticsPayload) {
|
|
100
100
|
return function (state, dispatch) {
|
|
101
101
|
var _api$contentInsertion, _api$contentInsertion2;
|
|
102
|
-
var node = createTableWithWidth(
|
|
102
|
+
var node = createTableWithWidth({
|
|
103
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
104
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
105
|
+
isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled
|
|
106
|
+
})(state.schema);
|
|
103
107
|
return (_api$contentInsertion = api === null || api === void 0 || (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 || (_api$contentInsertion2 = _api$contentInsertion2.actions) === null || _api$contentInsertion2 === void 0 ? void 0 : _api$contentInsertion2.insert({
|
|
104
108
|
state: state,
|
|
105
109
|
dispatch: dispatch,
|
|
@@ -117,7 +121,7 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
117
121
|
}
|
|
118
122
|
},
|
|
119
123
|
commands: {
|
|
120
|
-
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
124
|
+
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.isTableScalingEnabled, options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
121
125
|
},
|
|
122
126
|
nodes: function nodes() {
|
|
123
127
|
return [{
|
|
@@ -185,9 +189,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
185
189
|
dragAndDropEnabled = _ref7.dragAndDropEnabled,
|
|
186
190
|
_ref7$isTableScalingE = _ref7.isTableScalingEnabled,
|
|
187
191
|
isTableScalingEnabled = _ref7$isTableScalingE === void 0 ? false : _ref7$isTableScalingE,
|
|
192
|
+
_ref7$isTableAlignmen = _ref7.isTableAlignmentEnabled,
|
|
193
|
+
isTableAlignmentEnabled = _ref7$isTableAlignmen === void 0 ? false : _ref7$isTableAlignmen,
|
|
188
194
|
_ref7$fullWidthEnable = _ref7.fullWidthEnabled,
|
|
189
195
|
fullWidthEnabled = _ref7$fullWidthEnable === void 0 ? false : _ref7$fullWidthEnable;
|
|
190
|
-
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, fullWidthEnabled, api, getIntl);
|
|
196
|
+
return keymapPlugin(defaultGetEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled, isTableScalingEnabled, isTableAlignmentEnabled, fullWidthEnabled, api, getIntl);
|
|
191
197
|
}
|
|
192
198
|
}, {
|
|
193
199
|
name: 'tableSelectionKeymap',
|
|
@@ -245,10 +251,10 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
245
251
|
}, {
|
|
246
252
|
name: 'tableWidth',
|
|
247
253
|
plugin: function plugin(_ref13) {
|
|
248
|
-
var _options$fullWidthEna, _options$isTableScali;
|
|
254
|
+
var _options$fullWidthEna, _options$isTableScali, _options$isTableAlign;
|
|
249
255
|
var dispatchAnalyticsEvent = _ref13.dispatchAnalyticsEvent,
|
|
250
256
|
dispatch = _ref13.dispatch;
|
|
251
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false) : undefined;
|
|
257
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, (_options$isTableScali = options === null || options === void 0 ? void 0 : options.isTableScalingEnabled) !== null && _options$isTableScali !== void 0 ? _options$isTableScali : false, (_options$isTableAlign = options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled) !== null && _options$isTableAlign !== void 0 ? _options$isTableAlign : false) : undefined;
|
|
252
258
|
}
|
|
253
259
|
},
|
|
254
260
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -435,7 +441,11 @@ var tablesPlugin = function tablesPlugin(_ref) {
|
|
|
435
441
|
var _api$table;
|
|
436
442
|
// see comment on tablesPlugin.getSharedState on usage
|
|
437
443
|
var tableState = api === null || api === void 0 || (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
438
|
-
var tableNode = createTableWithWidth(
|
|
444
|
+
var tableNode = createTableWithWidth({
|
|
445
|
+
isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
|
|
446
|
+
isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.isTableAlignmentEnabled,
|
|
447
|
+
isFullWidthModeEnabled: tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled
|
|
448
|
+
})(state.schema);
|
|
439
449
|
var tr = insert(tableNode);
|
|
440
450
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|
|
441
451
|
action: ACTION.INSERTED,
|
|
@@ -11,14 +11,15 @@ import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/
|
|
|
11
11
|
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
12
12
|
var _pluginInjectionApi$a;
|
|
13
13
|
var isTableScalingEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
14
|
+
var isTableAlignmentEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
15
|
+
var isFullWidthEnabled = arguments.length > 5 ? arguments[5] : undefined;
|
|
16
|
+
var pluginInjectionApi = arguments.length > 6 ? arguments[6] : undefined;
|
|
17
|
+
var getIntl = arguments.length > 7 ? arguments[7] : undefined;
|
|
17
18
|
var list = {};
|
|
18
19
|
var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
|
|
19
20
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
|
|
20
21
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
|
|
21
|
-
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
22
|
+
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
22
23
|
bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
|
|
23
24
|
bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
|
|
24
25
|
|
|
@@ -16,9 +16,10 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
16
16
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
17
17
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
18
18
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
19
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
19
20
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
20
21
|
export var pluginKey = new PluginKey('tableWidthPlugin');
|
|
21
|
-
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) {
|
|
22
|
+
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) {
|
|
22
23
|
return new SafePlugin({
|
|
23
24
|
key: pluginKey,
|
|
24
25
|
state: {
|
|
@@ -91,8 +92,9 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
91
92
|
var referentialityTr = transactions.find(function (tr) {
|
|
92
93
|
return tr.getMeta('referentialityTableInserted');
|
|
93
94
|
});
|
|
94
|
-
var
|
|
95
|
-
|
|
95
|
+
var shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
96
|
+
var shouldPatchTableAlignment = fullWidthEnabled && isTableAlignmentEnabled;
|
|
97
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTableWidth && !shouldPatchTableAlignment || !referentialityTr)) {
|
|
96
98
|
return null;
|
|
97
99
|
}
|
|
98
100
|
var table = newState.schema.nodes.table;
|
|
@@ -152,10 +154,15 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
152
154
|
}
|
|
153
155
|
if (referentialityTr) {
|
|
154
156
|
referentialityTr.steps.forEach(function (step) {
|
|
155
|
-
step.getMap().forEach(function (
|
|
157
|
+
step.getMap().forEach(function (_, __, newStart, newEnd) {
|
|
156
158
|
newState.doc.nodesBetween(newStart, newEnd, function (node, pos) {
|
|
157
|
-
if (node.type === table
|
|
158
|
-
|
|
159
|
+
if (node.type === table) {
|
|
160
|
+
if (shouldPatchTableWidth && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
161
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
162
|
+
}
|
|
163
|
+
if (shouldPatchTableAlignment) {
|
|
164
|
+
tr.setNodeAttribute(pos, 'layout', ALIGN_START);
|
|
165
|
+
}
|
|
159
166
|
}
|
|
160
167
|
});
|
|
161
168
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
export var ALIGN_START = 'align-start';
|
|
2
|
+
export var ALIGN_CENTER = 'center';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
3
6
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
4
7
|
*/
|
|
5
8
|
export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
6
|
-
return layout ===
|
|
9
|
+
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
7
10
|
};
|
package/dist/esm/utils/create.js
CHANGED
|
@@ -3,16 +3,21 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
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) { _defineProperty(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; }
|
|
4
4
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
6
|
-
export var createTableWithWidth = function createTableWithWidth(
|
|
6
|
+
export var createTableWithWidth = function createTableWithWidth(_ref) {
|
|
7
|
+
var isTableScalingEnabled = _ref.isTableScalingEnabled,
|
|
8
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled,
|
|
9
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled,
|
|
10
|
+
createTableProps = _ref.createTableProps;
|
|
7
11
|
return function (schema) {
|
|
12
|
+
var attrsOverrides = {};
|
|
8
13
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
9
|
-
|
|
10
|
-
schema: schema,
|
|
11
|
-
tableWidth: TABLE_MAX_WIDTH
|
|
12
|
-
}, createTableProps));
|
|
14
|
+
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
17
|
+
attrsOverrides.layout = 'align-start';
|
|
18
|
+
}
|
|
19
|
+
return createTable(_objectSpread(_objectSpread({
|
|
15
20
|
schema: schema
|
|
16
|
-
}, createTableProps));
|
|
21
|
+
}, createTableProps), attrsOverrides));
|
|
17
22
|
};
|
|
18
23
|
};
|
|
@@ -8,5 +8,5 @@ export declare const addColumnBefore: (isTableScalingEnabled?: boolean) => Comma
|
|
|
8
8
|
export declare const addColumnAfter: (isTableScalingEnabled?: boolean) => Command;
|
|
9
9
|
export declare const insertColumn: (isTableScalingEnabled?: boolean, isCellBackgroundDuplicated?: boolean) => (column: number) => Command;
|
|
10
10
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean, isCellBackgroundDuplicated?: boolean) => Command;
|
|
11
|
-
export declare const createTable: (isTableScalingEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
-
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
11
|
+
export declare const createTable: (isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
+
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
@@ -3,5 +3,5 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { PluginInjectionAPIWithA11y } from '../types';
|
|
6
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
7
7
|
export default keymapPlugin;
|
|
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
|
|
|
13
13
|
tableRef: HTMLTableElement | null;
|
|
14
14
|
};
|
|
15
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
16
|
-
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
16
|
+
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
17
17
|
resizing: boolean;
|
|
18
18
|
tableLocalId: string;
|
|
19
19
|
tableRef: null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { AlignmentOptions } from '../types';
|
|
3
|
+
export declare const ALIGN_START = "align-start";
|
|
4
|
+
export declare const ALIGN_CENTER = "center";
|
|
3
5
|
/**
|
|
4
6
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
7
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const createTableWithWidth: (isTableScalingEnabled
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const createTableWithWidth: ({ isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, createTableProps, }: {
|
|
3
|
+
isTableScalingEnabled?: boolean | undefined;
|
|
4
|
+
isTableAlignmentEnabled?: boolean | undefined;
|
|
5
|
+
isFullWidthModeEnabled?: boolean | undefined;
|
|
6
|
+
createTableProps?: {
|
|
7
|
+
rowsCount?: number | undefined;
|
|
8
|
+
colsCount?: number | undefined;
|
|
9
|
+
} | undefined;
|
|
5
10
|
}) => (schema: Schema) => import("prosemirror-model").Node;
|
|
@@ -8,5 +8,5 @@ export declare const addColumnBefore: (isTableScalingEnabled?: boolean) => Comma
|
|
|
8
8
|
export declare const addColumnAfter: (isTableScalingEnabled?: boolean) => Command;
|
|
9
9
|
export declare const insertColumn: (isTableScalingEnabled?: boolean, isCellBackgroundDuplicated?: boolean) => (column: number) => Command;
|
|
10
10
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean, isCellBackgroundDuplicated?: boolean) => Command;
|
|
11
|
-
export declare const createTable: (isTableScalingEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
-
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
11
|
+
export declare const createTable: (isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
+
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
@@ -3,5 +3,5 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { PluginInjectionAPIWithA11y } from '../types';
|
|
6
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
7
7
|
export default keymapPlugin;
|
|
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
|
|
|
13
13
|
tableRef: HTMLTableElement | null;
|
|
14
14
|
};
|
|
15
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
16
|
-
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
16
|
+
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
17
17
|
resizing: boolean;
|
|
18
18
|
tableLocalId: string;
|
|
19
19
|
tableRef: null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { AlignmentOptions } from '../types';
|
|
3
|
+
export declare const ALIGN_START = "align-start";
|
|
4
|
+
export declare const ALIGN_CENTER = "center";
|
|
3
5
|
/**
|
|
4
6
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
7
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const createTableWithWidth: (isTableScalingEnabled
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const createTableWithWidth: ({ isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, createTableProps, }: {
|
|
3
|
+
isTableScalingEnabled?: boolean | undefined;
|
|
4
|
+
isTableAlignmentEnabled?: boolean | undefined;
|
|
5
|
+
isFullWidthModeEnabled?: boolean | undefined;
|
|
6
|
+
createTableProps?: {
|
|
7
|
+
rowsCount?: number | undefined;
|
|
8
|
+
colsCount?: number | undefined;
|
|
9
|
+
} | undefined;
|
|
5
10
|
}) => (schema: Schema) => import("prosemirror-model").Node;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.16.
|
|
3
|
+
"version": "7.16.6",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"runReact18": false
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/adf-schema": "^36.
|
|
32
|
-
"@atlaskit/button": "^17.
|
|
31
|
+
"@atlaskit/adf-schema": "^36.10.7",
|
|
32
|
+
"@atlaskit/button": "^17.16.0",
|
|
33
33
|
"@atlaskit/custom-steps": "^0.2.0",
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
34
|
+
"@atlaskit/editor-common": "^81.0.0",
|
|
35
35
|
"@atlaskit/editor-palette": "1.6.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.2.0",
|
package/src/commands/insert.ts
CHANGED
|
@@ -201,37 +201,42 @@ export const insertRow =
|
|
|
201
201
|
return true;
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
export const createTable =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
204
|
+
export const createTable =
|
|
205
|
+
(
|
|
206
|
+
isTableScalingEnabled?: boolean,
|
|
207
|
+
isTableAlignmentEnabled?: boolean,
|
|
208
|
+
isFullWidthModeEnabled?: boolean,
|
|
209
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
|
|
210
|
+
): Command =>
|
|
211
|
+
(state, dispatch) => {
|
|
212
|
+
const table = createTableWithWidth({
|
|
213
|
+
isTableScalingEnabled,
|
|
214
|
+
isTableAlignmentEnabled,
|
|
215
|
+
isFullWidthModeEnabled,
|
|
216
|
+
})(state.schema);
|
|
213
217
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
if (dispatch) {
|
|
219
|
+
const tr = safeInsert(table)(state.tr).scrollIntoView();
|
|
220
|
+
if (editorAnalyticsAPI) {
|
|
221
|
+
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
218
222
|
action: ACTION.INSERTED,
|
|
219
223
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
220
224
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
221
225
|
attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
|
|
222
226
|
eventType: EVENT_TYPE.TRACK,
|
|
223
|
-
|
|
227
|
+
})(tr);
|
|
228
|
+
}
|
|
229
|
+
dispatch(tr);
|
|
224
230
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
};
|
|
230
234
|
|
|
231
235
|
export const insertTableWithSize =
|
|
232
236
|
(
|
|
233
237
|
isFullWidthModeEnabled?: boolean,
|
|
234
238
|
isTableScalingEnabled?: boolean,
|
|
239
|
+
isTableAlignmentEnabled?: boolean,
|
|
235
240
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
236
241
|
) =>
|
|
237
242
|
(
|
|
@@ -240,14 +245,15 @@ export const insertTableWithSize =
|
|
|
240
245
|
inputMethod?: INPUT_METHOD.PICKER,
|
|
241
246
|
): EditorCommand => {
|
|
242
247
|
return ({ tr }) => {
|
|
243
|
-
const tableNode = createTableWithWidth(
|
|
248
|
+
const tableNode = createTableWithWidth({
|
|
244
249
|
isTableScalingEnabled,
|
|
245
250
|
isFullWidthModeEnabled,
|
|
246
|
-
|
|
251
|
+
isTableAlignmentEnabled,
|
|
252
|
+
createTableProps: {
|
|
247
253
|
rowsCount: rowsCount,
|
|
248
254
|
colsCount: colsCount,
|
|
249
255
|
},
|
|
250
|
-
)(tr.doc.type.schema);
|
|
256
|
+
})(tr.doc.type.schema);
|
|
251
257
|
|
|
252
258
|
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
253
259
|
if (inputMethod) {
|
package/src/plugin.tsx
CHANGED
|
@@ -199,10 +199,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
199
199
|
insertTable:
|
|
200
200
|
(analyticsPayload): Command =>
|
|
201
201
|
(state, dispatch) => {
|
|
202
|
-
const node = createTableWithWidth(
|
|
203
|
-
options?.isTableScalingEnabled,
|
|
204
|
-
options?.
|
|
205
|
-
|
|
202
|
+
const node = createTableWithWidth({
|
|
203
|
+
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
204
|
+
isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
|
|
205
|
+
isFullWidthModeEnabled: options?.fullWidthEnabled,
|
|
206
|
+
})(state.schema);
|
|
206
207
|
|
|
207
208
|
return (
|
|
208
209
|
api?.contentInsertion?.actions?.insert({
|
|
@@ -229,6 +230,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
229
230
|
insertTableWithSize: insertTableWithSize(
|
|
230
231
|
options?.fullWidthEnabled,
|
|
231
232
|
options?.isTableScalingEnabled,
|
|
233
|
+
options?.isTableAlignmentEnabled,
|
|
232
234
|
api?.analytics?.actions,
|
|
233
235
|
),
|
|
234
236
|
},
|
|
@@ -318,6 +320,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
318
320
|
const {
|
|
319
321
|
dragAndDropEnabled,
|
|
320
322
|
isTableScalingEnabled = false,
|
|
323
|
+
isTableAlignmentEnabled = false,
|
|
321
324
|
fullWidthEnabled = false,
|
|
322
325
|
} = options || ({} as TablePluginOptions);
|
|
323
326
|
return keymapPlugin(
|
|
@@ -325,6 +328,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
325
328
|
editorAnalyticsAPI,
|
|
326
329
|
dragAndDropEnabled,
|
|
327
330
|
isTableScalingEnabled,
|
|
331
|
+
isTableAlignmentEnabled,
|
|
328
332
|
fullWidthEnabled,
|
|
329
333
|
api,
|
|
330
334
|
getIntl,
|
|
@@ -401,6 +405,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
401
405
|
dispatchAnalyticsEvent,
|
|
402
406
|
options?.fullWidthEnabled ?? false,
|
|
403
407
|
options?.isTableScalingEnabled ?? false,
|
|
408
|
+
options?.isTableAlignmentEnabled ?? false,
|
|
404
409
|
)
|
|
405
410
|
: undefined,
|
|
406
411
|
},
|
|
@@ -644,10 +649,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
644
649
|
// see comment on tablesPlugin.getSharedState on usage
|
|
645
650
|
const tableState = api?.table?.sharedState.currentState();
|
|
646
651
|
|
|
647
|
-
const tableNode = createTableWithWidth(
|
|
648
|
-
options?.isTableScalingEnabled,
|
|
649
|
-
|
|
650
|
-
|
|
652
|
+
const tableNode = createTableWithWidth({
|
|
653
|
+
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
654
|
+
isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
|
|
655
|
+
isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
|
|
656
|
+
})(state.schema);
|
|
651
657
|
|
|
652
658
|
const tr = insert(tableNode);
|
|
653
659
|
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -57,6 +57,7 @@ export function keymapPlugin(
|
|
|
57
57
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
58
58
|
dragAndDropEnabled?: boolean,
|
|
59
59
|
isTableScalingEnabled = false,
|
|
60
|
+
isTableAlignmentEnabled = false,
|
|
60
61
|
isFullWidthEnabled?: boolean,
|
|
61
62
|
pluginInjectionApi?: PluginInjectionAPIWithA11y,
|
|
62
63
|
getIntl?: () => IntlShape,
|
|
@@ -80,6 +81,7 @@ export function keymapPlugin(
|
|
|
80
81
|
toggleTable.common!,
|
|
81
82
|
createTable(
|
|
82
83
|
isTableScalingEnabled,
|
|
84
|
+
isTableAlignmentEnabled,
|
|
83
85
|
!!isFullWidthEnabled,
|
|
84
86
|
editorAnalyticsAPI,
|
|
85
87
|
),
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
} from '@atlaskit/editor-shared-styles';
|
|
24
24
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
25
25
|
|
|
26
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
27
|
+
|
|
26
28
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
27
29
|
|
|
28
30
|
type __ReplaceStep = ReplaceStep & {
|
|
@@ -46,6 +48,7 @@ const createPlugin = (
|
|
|
46
48
|
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
47
49
|
fullWidthEnabled: boolean,
|
|
48
50
|
isTableScalingEnabled: boolean,
|
|
51
|
+
isTableAlignmentEnabled: boolean,
|
|
49
52
|
) => {
|
|
50
53
|
return new SafePlugin({
|
|
51
54
|
key: pluginKey,
|
|
@@ -133,11 +136,14 @@ const createPlugin = (
|
|
|
133
136
|
tr.getMeta('referentialityTableInserted'),
|
|
134
137
|
);
|
|
135
138
|
|
|
136
|
-
const
|
|
139
|
+
const shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
140
|
+
const shouldPatchTableAlignment =
|
|
141
|
+
fullWidthEnabled && isTableAlignmentEnabled;
|
|
137
142
|
|
|
138
143
|
if (
|
|
139
144
|
!isReplaceDocumentOperation &&
|
|
140
|
-
(!
|
|
145
|
+
((!shouldPatchTableWidth && !shouldPatchTableAlignment) ||
|
|
146
|
+
!referentialityTr)
|
|
141
147
|
) {
|
|
142
148
|
return null;
|
|
143
149
|
}
|
|
@@ -206,10 +212,18 @@ const createPlugin = (
|
|
|
206
212
|
|
|
207
213
|
if (referentialityTr) {
|
|
208
214
|
referentialityTr.steps.forEach((step) => {
|
|
209
|
-
step.getMap().forEach((
|
|
215
|
+
step.getMap().forEach((_, __, newStart, newEnd) => {
|
|
210
216
|
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
211
|
-
if (node.type === table
|
|
212
|
-
|
|
217
|
+
if (node.type === table) {
|
|
218
|
+
if (
|
|
219
|
+
shouldPatchTableWidth &&
|
|
220
|
+
node.attrs.width !== TABLE_MAX_WIDTH
|
|
221
|
+
) {
|
|
222
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
223
|
+
}
|
|
224
|
+
if (shouldPatchTableAlignment) {
|
|
225
|
+
tr.setNodeAttribute(pos, 'layout', ALIGN_START);
|
|
226
|
+
}
|
|
213
227
|
}
|
|
214
228
|
});
|
|
215
229
|
});
|
package/src/utils/alignment.ts
CHANGED
|
@@ -2,9 +2,12 @@ import type { TableLayout } from '@atlaskit/adf-schema';
|
|
|
2
2
|
|
|
3
3
|
import type { AlignmentOptions } from '../types';
|
|
4
4
|
|
|
5
|
+
export const ALIGN_START = 'align-start';
|
|
6
|
+
export const ALIGN_CENTER = 'center';
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
7
10
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
11
|
*/
|
|
9
12
|
export const normaliseAlignment = (layout: TableLayout): AlignmentOptions =>
|
|
10
|
-
layout ===
|
|
13
|
+
layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
package/src/utils/create.ts
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
+
import type { TableAttributes } from '@atlaskit/adf-schema';
|
|
1
2
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
3
4
|
|
|
4
5
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
5
6
|
|
|
7
|
+
type CreateTableOverrides = {
|
|
8
|
+
tableWidth?: TableAttributes['width'];
|
|
9
|
+
layout?: TableAttributes['layout'];
|
|
10
|
+
};
|
|
11
|
+
|
|
6
12
|
export const createTableWithWidth =
|
|
7
|
-
(
|
|
8
|
-
isTableScalingEnabled
|
|
9
|
-
|
|
13
|
+
({
|
|
14
|
+
isTableScalingEnabled,
|
|
15
|
+
isTableAlignmentEnabled,
|
|
16
|
+
isFullWidthModeEnabled,
|
|
17
|
+
createTableProps,
|
|
18
|
+
}: {
|
|
19
|
+
isTableScalingEnabled?: boolean;
|
|
20
|
+
isTableAlignmentEnabled?: boolean;
|
|
21
|
+
isFullWidthModeEnabled?: boolean;
|
|
10
22
|
createTableProps?: {
|
|
11
23
|
rowsCount?: number;
|
|
12
24
|
colsCount?: number;
|
|
13
|
-
}
|
|
14
|
-
) =>
|
|
25
|
+
};
|
|
26
|
+
}) =>
|
|
15
27
|
(schema: Schema) => {
|
|
28
|
+
const attrsOverrides: CreateTableOverrides = {};
|
|
16
29
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
30
|
+
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
31
|
+
}
|
|
32
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
33
|
+
attrsOverrides.layout = 'align-start';
|
|
22
34
|
}
|
|
35
|
+
|
|
23
36
|
return createTable({
|
|
24
37
|
schema,
|
|
25
38
|
...createTableProps,
|
|
39
|
+
...attrsOverrides,
|
|
26
40
|
});
|
|
27
41
|
};
|