@atlaskit/editor-plugin-table 8.2.2 → 8.3.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/commands/insert.js +97 -3
  3. package/dist/cjs/plugin.js +57 -38
  4. package/dist/cjs/pm-plugins/drag-and-drop/utils/autoscrollers.js +3 -3
  5. package/dist/cjs/pm-plugins/keymap.js +18 -1
  6. package/dist/es2019/commands/insert.js +91 -2
  7. package/dist/es2019/plugin.js +58 -41
  8. package/dist/es2019/pm-plugins/drag-and-drop/utils/autoscrollers.js +3 -3
  9. package/dist/es2019/pm-plugins/keymap.js +20 -3
  10. package/dist/esm/commands/insert.js +97 -2
  11. package/dist/esm/plugin.js +58 -39
  12. package/dist/esm/pm-plugins/drag-and-drop/utils/autoscrollers.js +3 -3
  13. package/dist/esm/pm-plugins/keymap.js +20 -3
  14. package/dist/types/commands/insert.d.ts +41 -1
  15. package/dist/types/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  16. package/dist/types/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +2 -4
  17. package/dist/types/ui/TableFloatingControls/index.d.ts +1 -2
  18. package/dist/types/utils/drag-menu.d.ts +3 -3
  19. package/dist/types-ts4.5/commands/insert.d.ts +41 -1
  20. package/dist/types-ts4.5/ui/TableFloatingColumnControls/ColumnControls/index.d.ts +1 -2
  21. package/dist/types-ts4.5/ui/TableFloatingControls/CornerControls/DragCornerControls.d.ts +2 -4
  22. package/dist/types-ts4.5/ui/TableFloatingControls/index.d.ts +1 -2
  23. package/dist/types-ts4.5/utils/drag-menu.d.ts +3 -3
  24. package/package.json +5 -5
  25. package/src/commands/insert.ts +119 -3
  26. package/src/plugin.tsx +78 -54
  27. package/src/pm-plugins/drag-and-drop/utils/autoscrollers.ts +3 -3
  28. package/src/pm-plugins/keymap.ts +40 -10
  29. package/src/utils/drag-menu.ts +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 8.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#170735](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/170735)
8
+ [`147418939b2eb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/147418939b2eb) -
9
+ [ux] ED-25880 Use consistent table insertion logic for primary toolbar button, primary toolbar
10
+ size selector dropdown and table insert keyboard shortcut which handles node nesting support
11
+
12
+ ### Patch Changes
13
+
14
+ - [#170839](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/170839)
15
+ [`90284312a1050`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/90284312a1050) -
16
+ Internal change to account for a dependency change.
17
+ - [#171994](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/171994)
18
+ [`be58e4bb2e387`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/be58e4bb2e387) -
19
+ Migrating usages of UNSAFE types and entrypoints that have been renamed in `@atlaskit/icon` and
20
+ `@atlaskit/icon-lab`.
21
+ - Updated dependencies
22
+
3
23
  ## 8.2.2
4
24
 
5
25
  ### Patch Changes
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.addColumnAfter = void 0;
7
8
  exports.addColumnAt = addColumnAt;
8
- exports.insertTableWithSize = exports.insertRow = exports.insertColumn = exports.createTable = exports.addColumnBefore = void 0;
9
+ exports.insertTableWithSize = exports.insertTableWithNestingSupport = exports.insertRow = exports.insertColumn = exports.createTable = exports.addColumnBefore = void 0;
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
11
  var _customSteps = require("@atlaskit/custom-steps");
10
12
  var _analytics = require("@atlaskit/editor-common/analytics");
13
+ var _nesting = require("@atlaskit/editor-common/nesting");
11
14
  var _state = require("@atlaskit/editor-prosemirror/state");
12
15
  var _utils = require("@atlaskit/editor-prosemirror/utils");
13
16
  var _tableMap = require("@atlaskit/editor-tables/table-map");
14
17
  var _utils2 = require("@atlaskit/editor-tables/utils");
18
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
15
20
  var _commands = require("../pm-plugins/analytics/commands");
16
21
  var _tableAnalytics = require("../pm-plugins/table-analytics");
17
22
  var _columnWidth = require("../transforms/column-width");
18
23
  var _utils3 = require("../utils");
19
24
  var _getAllowAddColumnCustomStep = require("../utils/get-allow-add-column-custom-step");
20
- // #region Imports
21
-
25
+ 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; }
26
+ 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; } // #region Imports
22
27
  function addColumnAtCustomStep(column) {
23
28
  return function (tr) {
24
29
  var table = (0, _utils2.findTable)(tr.selection);
@@ -150,6 +155,12 @@ var insertRow = exports.insertRow = function insertRow(row, moveCursorToTheNewRo
150
155
  return true;
151
156
  };
152
157
  };
158
+
159
+ /**
160
+ * @private
161
+ * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
162
+ * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
163
+ */
153
164
  var createTable = exports.createTable = function createTable(isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor, isTableResizingEnabled) {
154
165
  return function (state, dispatch) {
155
166
  var table = (0, _utils3.createTableWithWidth)({
@@ -178,6 +189,12 @@ var createTable = exports.createTable = function createTable(isTableScalingEnabl
178
189
  return true;
179
190
  };
180
191
  };
192
+
193
+ /**
194
+ * @private
195
+ * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
196
+ * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
197
+ */
181
198
  var insertTableWithSize = exports.insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, isTableScalingEnabled, isTableAlignmentEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor) {
182
199
  return function (rowsCount, colsCount, inputMethod) {
183
200
  return function (_ref) {
@@ -210,4 +227,81 @@ var insertTableWithSize = exports.insertTableWithSize = function insertTableWith
210
227
  return newTr;
211
228
  };
212
229
  };
230
+ };
231
+
232
+ /**
233
+ * Unified command to insert a new table into the editor.
234
+ *
235
+ * @param {Object} options - Configuration options for table insertion.
236
+ * @param {boolean} [options.isTableScalingEnabled=false] - Flag to enable table scaling.
237
+ * @param {boolean} [options.isTableAlignmentEnabled=false] - Flag to enable table alignment.
238
+ * @param {boolean} [options.isFullWidthModeEnabled=false] - Flag to enable full-width mode for the table.
239
+ * @param {boolean} [options.isCommentEditor=false] - Flag to indicate if the editor is in comment mode.
240
+ * @param {boolean} [options.isChromelessEditor=false] - Flag to indicate if the editor is chromeless.
241
+ * @param {boolean} [options.isTableResizingEnabled=false] - Flag to enable table resizing.
242
+ * @param {Object} [options.createTableProps={}] - Additional properties for table creation, including table size.
243
+ * @param {Object} api - PluginInjectinoApi object for content insertion commands.
244
+ * @param {Object} analyticsPayload - Payload for analytics tracking.
245
+ *
246
+ * @returns {Function} A function that takes a transaction and inserts a table.
247
+ */
248
+ var insertTableWithNestingSupport = exports.insertTableWithNestingSupport = function insertTableWithNestingSupport(_ref2, api, analyticsPayload) {
249
+ var _ref2$isTableScalingE = _ref2.isTableScalingEnabled,
250
+ isTableScalingEnabled = _ref2$isTableScalingE === void 0 ? false : _ref2$isTableScalingE,
251
+ _ref2$isTableAlignmen = _ref2.isTableAlignmentEnabled,
252
+ isTableAlignmentEnabled = _ref2$isTableAlignmen === void 0 ? false : _ref2$isTableAlignmen,
253
+ _ref2$isFullWidthMode = _ref2.isFullWidthModeEnabled,
254
+ isFullWidthModeEnabled = _ref2$isFullWidthMode === void 0 ? false : _ref2$isFullWidthMode,
255
+ _ref2$isCommentEditor = _ref2.isCommentEditor,
256
+ isCommentEditor = _ref2$isCommentEditor === void 0 ? false : _ref2$isCommentEditor,
257
+ _ref2$isChromelessEdi = _ref2.isChromelessEditor,
258
+ isChromelessEditor = _ref2$isChromelessEdi === void 0 ? false : _ref2$isChromelessEdi,
259
+ _ref2$isTableResizing = _ref2.isTableResizingEnabled,
260
+ isTableResizingEnabled = _ref2$isTableResizing === void 0 ? false : _ref2$isTableResizing,
261
+ _ref2$createTableProp = _ref2.createTableProps,
262
+ createTableProps = _ref2$createTableProp === void 0 ? {} : _ref2$createTableProp;
263
+ return function (_ref3) {
264
+ var _api$contentInsertion;
265
+ var tr = _ref3.tr;
266
+ var schema = tr.doc.type.schema;
267
+ var node = (0, _utils3.createTableWithWidth)({
268
+ isTableScalingEnabled: isTableScalingEnabled,
269
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
270
+ isFullWidthModeEnabled: isFullWidthModeEnabled,
271
+ isCommentEditor: isCommentEditor,
272
+ isChromelessEditor: isChromelessEditor,
273
+ isTableResizingEnabled: isTableResizingEnabled,
274
+ createTableProps: createTableProps
275
+ })(schema);
276
+
277
+ // If the cursor is inside a table
278
+ var insertAt;
279
+ if ((0, _utils.hasParentNodeOfType)(schema.nodes.table)(tr.selection) && (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes')) {
280
+ // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
281
+ if ((0, _experiments.editorExperiment)('nested-tables-in-tables', false, {
282
+ exposure: true
283
+ }) || (0, _nesting.getParentOfTypeCount)(schema.nodes.table)(tr.selection) > 1) {
284
+ var positionAfterTopTable = (0, _nesting.getPositionAfterTopParentNodeOfType)(schema.nodes.table)(tr.selection);
285
+ if (!positionAfterTopTable) {
286
+ return tr;
287
+ }
288
+ insertAt = _state.TextSelection.create(tr.doc, positionAfterTopTable);
289
+ }
290
+ }
291
+ api === null || api === void 0 || (_api$contentInsertion = api.contentInsertion) === null || _api$contentInsertion === void 0 || (_api$contentInsertion = _api$contentInsertion.commands) === null || _api$contentInsertion === void 0 || _api$contentInsertion.insert({
292
+ node: node,
293
+ options: {
294
+ selectNodeInserted: false,
295
+ analyticsPayload: analyticsPayload ? _objectSpread(_objectSpread({}, analyticsPayload), {}, {
296
+ attributes: _objectSpread(_objectSpread({}, analyticsPayload.attributes), {}, {
297
+ localId: node.attrs.localId
298
+ })
299
+ }) : undefined,
300
+ insertAt: insertAt
301
+ }
302
+ })({
303
+ tr: tr
304
+ });
305
+ return tr;
306
+ };
213
307
  };
@@ -15,9 +15,9 @@ var _icons = require("@atlaskit/editor-common/icons");
15
15
  var _keymaps = require("@atlaskit/editor-common/keymaps");
16
16
  var _messages = require("@atlaskit/editor-common/messages");
17
17
  var _nesting = require("@atlaskit/editor-common/nesting");
18
+ var _preset = require("@atlaskit/editor-common/preset");
18
19
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
19
20
  var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
20
- var _state = require("@atlaskit/editor-prosemirror/state");
21
21
  var _utils = require("@atlaskit/editor-prosemirror/utils");
22
22
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
23
23
  var _pmPlugins = require("@atlaskit/editor-tables/pm-plugins");
@@ -116,53 +116,72 @@ var tablesPlugin = function tablesPlugin(_ref) {
116
116
  actions: {
117
117
  insertTable: function insertTable(analyticsPayload) {
118
118
  return function (state, dispatch) {
119
- var _api$contentInsertion, _api$contentInsertion2;
120
- var node = (0, _utils2.createTableWithWidth)({
121
- isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
122
- isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
123
- isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
124
- isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
125
- isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
126
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
127
- })(state.schema);
128
-
129
- // If the cursor is inside a table
130
- var insertAt;
131
- if ((0, _utils.hasParentNodeOfType)(state.schema.nodes.table)(state.selection) && (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes')) {
132
- // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
133
- if ((0, _experiments.editorExperiment)('nested-tables-in-tables', false, {
134
- exposure: true
135
- }) || (0, _nesting.getParentOfTypeCount)(state.schema.nodes.table)(state.selection) > 1) {
136
- var positionAfterTopTable = (0, _nesting.getPositionAfterTopParentNodeOfType)(state.schema.nodes.table)(state.selection);
137
- if (!positionAfterTopTable) {
138
- return false;
119
+ if ((0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes')) {
120
+ return (0, _preset.editorCommandToPMCommand)((0, _insert.insertTableWithNestingSupport)({
121
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
122
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
123
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
124
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
125
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
126
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
127
+ }, api, analyticsPayload))(state, dispatch);
128
+ } else {
129
+ var _api$contentInsertion, _api$contentInsertion2;
130
+ var node = (0, _utils2.createTableWithWidth)({
131
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
132
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
133
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
134
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
135
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
136
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
137
+ })(state.schema);
138
+ 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({
139
+ state: state,
140
+ dispatch: dispatch,
141
+ node: node,
142
+ options: {
143
+ selectNodeInserted: false,
144
+ analyticsPayload: _objectSpread(_objectSpread({}, analyticsPayload), {}, {
145
+ attributes: _objectSpread(_objectSpread({}, analyticsPayload.attributes), {}, {
146
+ localId: node.attrs.localId
147
+ })
148
+ })
139
149
  }
140
- insertAt = _state.TextSelection.create(state.doc, positionAfterTopTable);
141
- }
150
+ })) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
142
151
  }
143
- 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({
144
- state: state,
145
- dispatch: dispatch,
146
- node: node,
147
- options: {
148
- selectNodeInserted: false,
149
- analyticsPayload: _objectSpread(_objectSpread({}, analyticsPayload), {}, {
150
- attributes: _objectSpread(_objectSpread({}, analyticsPayload.attributes), {}, {
151
- localId: node.attrs.localId
152
- })
153
- }),
154
- insertAt: insertAt
155
- }
156
- })) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
157
152
  };
158
153
  }
159
154
  },
160
155
  commands: {
161
- 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.tableOptions.allowTableAlignment, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
156
+ insertTableWithSize: (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes') ? function (rowsCount, colsCount, inputMethod) {
157
+ return (0, _insert.insertTableWithNestingSupport)({
158
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
159
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
160
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
161
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
162
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
163
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing,
164
+ createTableProps: {
165
+ rowsCount: rowsCount,
166
+ colsCount: colsCount
167
+ }
168
+ }, api, {
169
+ action: _analytics.ACTION.INSERTED,
170
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
171
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
172
+ attributes: {
173
+ inputMethod: inputMethod !== null && inputMethod !== void 0 ? inputMethod : _analytics.INPUT_METHOD.PICKER,
174
+ totalRowCount: rowsCount,
175
+ totalColumnCount: colsCount
176
+ },
177
+ eventType: _analytics.EVENT_TYPE.TRACK
178
+ });
179
+ } : (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.tableOptions.allowTableAlignment, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
162
180
  },
163
181
  nodes: function nodes() {
164
182
  var _pluginConfig = (0, _createPluginConfig.pluginConfig)(options === null || options === void 0 ? void 0 : options.tableOptions),
165
183
  allowColumnResizing = _pluginConfig.allowColumnResizing;
184
+ // TODO: ED-25901 - We need to move this into a plugin config option so we don't accidentally enable nested nodes in Jira
166
185
  var isNestingSupported = (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes');
167
186
  return isNestingSupported ? [{
168
187
  name: 'table',
@@ -32,17 +32,17 @@ var autoScrollerFactory = exports.autoScrollerFactory = function autoScrollerFac
32
32
  },
33
33
  getOverflow: function getOverflow() {
34
34
  return {
35
- fromTopEdge: {
35
+ forTopEdge: {
36
36
  top: _consts.dropTargetExtendedWidth,
37
37
  right: _consts.dropTargetExtendedWidth,
38
38
  left: _consts.dropTargetExtendedWidth
39
39
  },
40
- fromRightEdge: {
40
+ forRightEdge: {
41
41
  right: _consts.dropTargetExtendedWidth,
42
42
  top: _consts.dropTargetExtendedWidth,
43
43
  bottom: _consts.dropTargetExtendedWidth
44
44
  },
45
- fromLeftEdge: {
45
+ forLeftEdge: {
46
46
  top: _consts.dropTargetExtendedWidth,
47
47
  left: _consts.dropTargetExtendedWidth,
48
48
  bottom: _consts.dropTargetExtendedWidth
@@ -7,8 +7,10 @@ exports.default = void 0;
7
7
  exports.keymapPlugin = keymapPlugin;
8
8
  var _analytics = require("@atlaskit/editor-common/analytics");
9
9
  var _keymaps = require("@atlaskit/editor-common/keymaps");
10
+ var _preset = require("@atlaskit/editor-common/preset");
10
11
  var _commands = require("@atlaskit/editor-prosemirror/commands");
11
12
  var _keymap = require("@atlaskit/editor-prosemirror/keymap");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
14
  var _commands2 = require("../commands");
13
15
  var _commandsWithAnalytics = require("../commands-with-analytics");
14
16
  var _columnResize = require("../commands/column-resize");
@@ -30,7 +32,22 @@ function keymapPlugin(getEditorContainerWidth, api, nodeViewPortalProviderAPI, e
30
32
  var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
31
33
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
32
34
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
33
- (0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, (0, _insert.createTable)(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor, isTableResizingEnabled), list);
35
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleTable.common, (0, _platformFeatureFlags.fg)('platform_editor_use_nested_table_pm_nodes') ? (0, _preset.editorCommandToPMCommand)((0, _insert.insertTableWithNestingSupport)({
36
+ isTableScalingEnabled: isTableScalingEnabled,
37
+ isTableAlignmentEnabled: isTableAlignmentEnabled,
38
+ isFullWidthModeEnabled: !!isFullWidthEnabled,
39
+ isCommentEditor: isCommentEditor,
40
+ isChromelessEditor: isChromelessEditor,
41
+ isTableResizingEnabled: isTableResizingEnabled
42
+ }, api, {
43
+ action: _analytics.ACTION.INSERTED,
44
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
45
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
46
+ attributes: {
47
+ inputMethod: _analytics.INPUT_METHOD.SHORTCUT
48
+ },
49
+ eventType: _analytics.EVENT_TYPE.TRACK
50
+ })) : (0, _insert.createTable)(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor, isTableResizingEnabled), list);
34
51
  (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);
35
52
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, _commands2.moveCursorBackward, list);
36
53
 
@@ -1,10 +1,13 @@
1
1
  // #region Imports
2
2
  import { AddColumnStep } from '@atlaskit/custom-steps';
3
3
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD, TABLE_OVERFLOW_CHANGE_TRIGGER } from '@atlaskit/editor-common/analytics';
4
- import { Selection } from '@atlaskit/editor-prosemirror/state';
5
- import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
4
+ import { getParentOfTypeCount, getPositionAfterTopParentNodeOfType } from '@atlaskit/editor-common/nesting';
5
+ import { Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
6
+ import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
6
7
  import { TableMap } from '@atlaskit/editor-tables/table-map';
7
8
  import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
10
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
8
11
  import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
9
12
  import { META_KEYS } from '../pm-plugins/table-analytics';
10
13
  import { rescaleColumns } from '../transforms/column-width';
@@ -119,6 +122,12 @@ export const insertRow = (row, moveCursorToTheNewRow) => (state, dispatch) => {
119
122
  }
120
123
  return true;
121
124
  };
125
+
126
+ /**
127
+ * @private
128
+ * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
129
+ * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
130
+ */
122
131
  export const createTable = (isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor, isTableResizingEnabled) => (state, dispatch) => {
123
132
  const table = createTableWithWidth({
124
133
  isTableScalingEnabled,
@@ -145,6 +154,12 @@ export const createTable = (isTableScalingEnabled, isTableAlignmentEnabled, isFu
145
154
  }
146
155
  return true;
147
156
  };
157
+
158
+ /**
159
+ * @private
160
+ * @deprecated This function is deprecated - please use insertTableWithNestingSupport instead.
161
+ * (To be removed with feature gate: `platform_editor_use_nested_table_pm_nodes`)
162
+ */
148
163
  export const insertTableWithSize = (isFullWidthModeEnabled, isTableScalingEnabled, isTableAlignmentEnabled, editorAnalyticsAPI, isCommentEditor, isChromelessEditor) => (rowsCount, colsCount, inputMethod) => {
149
164
  return ({
150
165
  tr
@@ -176,4 +191,78 @@ export const insertTableWithSize = (isFullWidthModeEnabled, isTableScalingEnable
176
191
  }
177
192
  return newTr;
178
193
  };
194
+ };
195
+
196
+ /**
197
+ * Unified command to insert a new table into the editor.
198
+ *
199
+ * @param {Object} options - Configuration options for table insertion.
200
+ * @param {boolean} [options.isTableScalingEnabled=false] - Flag to enable table scaling.
201
+ * @param {boolean} [options.isTableAlignmentEnabled=false] - Flag to enable table alignment.
202
+ * @param {boolean} [options.isFullWidthModeEnabled=false] - Flag to enable full-width mode for the table.
203
+ * @param {boolean} [options.isCommentEditor=false] - Flag to indicate if the editor is in comment mode.
204
+ * @param {boolean} [options.isChromelessEditor=false] - Flag to indicate if the editor is chromeless.
205
+ * @param {boolean} [options.isTableResizingEnabled=false] - Flag to enable table resizing.
206
+ * @param {Object} [options.createTableProps={}] - Additional properties for table creation, including table size.
207
+ * @param {Object} api - PluginInjectinoApi object for content insertion commands.
208
+ * @param {Object} analyticsPayload - Payload for analytics tracking.
209
+ *
210
+ * @returns {Function} A function that takes a transaction and inserts a table.
211
+ */
212
+ export const insertTableWithNestingSupport = ({
213
+ isTableScalingEnabled = false,
214
+ isTableAlignmentEnabled = false,
215
+ isFullWidthModeEnabled = false,
216
+ isCommentEditor = false,
217
+ isChromelessEditor = false,
218
+ isTableResizingEnabled = false,
219
+ createTableProps = {}
220
+ }, api, analyticsPayload) => ({
221
+ tr
222
+ }) => {
223
+ var _api$contentInsertion, _api$contentInsertion2;
224
+ const {
225
+ schema
226
+ } = tr.doc.type;
227
+ const node = createTableWithWidth({
228
+ isTableScalingEnabled,
229
+ isTableAlignmentEnabled,
230
+ isFullWidthModeEnabled,
231
+ isCommentEditor,
232
+ isChromelessEditor,
233
+ isTableResizingEnabled,
234
+ createTableProps
235
+ })(schema);
236
+
237
+ // If the cursor is inside a table
238
+ let insertAt;
239
+ if (hasParentNodeOfType(schema.nodes.table)(tr.selection) && fg('platform_editor_use_nested_table_pm_nodes')) {
240
+ // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
241
+ if (editorExperiment('nested-tables-in-tables', false, {
242
+ exposure: true
243
+ }) || getParentOfTypeCount(schema.nodes.table)(tr.selection) > 1) {
244
+ const positionAfterTopTable = getPositionAfterTopParentNodeOfType(schema.nodes.table)(tr.selection);
245
+ if (!positionAfterTopTable) {
246
+ return tr;
247
+ }
248
+ insertAt = TextSelection.create(tr.doc, positionAfterTopTable);
249
+ }
250
+ }
251
+ api === null || api === void 0 ? void 0 : (_api$contentInsertion = api.contentInsertion) === null || _api$contentInsertion === void 0 ? void 0 : (_api$contentInsertion2 = _api$contentInsertion.commands) === null || _api$contentInsertion2 === void 0 ? void 0 : _api$contentInsertion2.insert({
252
+ node,
253
+ options: {
254
+ selectNodeInserted: false,
255
+ analyticsPayload: analyticsPayload ? {
256
+ ...analyticsPayload,
257
+ attributes: {
258
+ ...analyticsPayload.attributes,
259
+ localId: node.attrs.localId
260
+ }
261
+ } : undefined,
262
+ insertAt
263
+ }
264
+ })({
265
+ tr
266
+ });
267
+ return tr;
179
268
  };
@@ -7,15 +7,15 @@ import { IconTable } from '@atlaskit/editor-common/icons';
7
7
  import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
8
8
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
9
9
  import { getParentOfTypeCount, getPositionAfterTopParentNodeOfType } from '@atlaskit/editor-common/nesting';
10
+ import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
10
11
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
11
12
  import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
12
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
13
13
  import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
14
14
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
15
15
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
16
16
  import { fg } from '@atlaskit/platform-feature-flags';
17
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
18
- import { insertTableWithSize } from './commands/insert';
18
+ import { insertTableWithNestingSupport, insertTableWithSize } from './commands/insert';
19
19
  import { pluginConfig } from './create-plugin-config';
20
20
  import { createPlugin as createTableAnalyticsPlugin } from './pm-plugins/analytics/plugin';
21
21
  import { pluginKey as tableAnalyticsPluginKey } from './pm-plugins/analytics/plugin-key';
@@ -104,55 +104,72 @@ const tablesPlugin = ({
104
104
  },
105
105
  actions: {
106
106
  insertTable: analyticsPayload => (state, dispatch) => {
107
- var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
108
- const node = createTableWithWidth({
109
- isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
110
- isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
111
- isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
112
- isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
113
- isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
114
- isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
115
- })(state.schema);
116
-
117
- // If the cursor is inside a table
118
- let insertAt;
119
- if (hasParentNodeOfType(state.schema.nodes.table)(state.selection) && fg('platform_editor_use_nested_table_pm_nodes')) {
120
- // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
121
- if (editorExperiment('nested-tables-in-tables', false, {
122
- exposure: true
123
- }) || getParentOfTypeCount(state.schema.nodes.table)(state.selection) > 1) {
124
- const positionAfterTopTable = getPositionAfterTopParentNodeOfType(state.schema.nodes.table)(state.selection);
125
- if (!positionAfterTopTable) {
126
- return false;
107
+ if (fg('platform_editor_use_nested_table_pm_nodes')) {
108
+ return editorCommandToPMCommand(insertTableWithNestingSupport({
109
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
110
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
111
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
112
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
113
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
114
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
115
+ }, api, analyticsPayload))(state, dispatch);
116
+ } else {
117
+ var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
118
+ const node = createTableWithWidth({
119
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
120
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
121
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
122
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
123
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
124
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing
125
+ })(state.schema);
126
+ 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({
127
+ state,
128
+ dispatch,
129
+ node,
130
+ options: {
131
+ selectNodeInserted: false,
132
+ analyticsPayload: {
133
+ ...analyticsPayload,
134
+ attributes: {
135
+ ...analyticsPayload.attributes,
136
+ localId: node.attrs.localId
137
+ }
138
+ }
127
139
  }
128
- insertAt = TextSelection.create(state.doc, positionAfterTopTable);
129
- }
140
+ })) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
130
141
  }
131
- 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({
132
- state,
133
- dispatch,
134
- node,
135
- options: {
136
- selectNodeInserted: false,
137
- analyticsPayload: {
138
- ...analyticsPayload,
139
- attributes: {
140
- ...analyticsPayload.attributes,
141
- localId: node.attrs.localId
142
- }
143
- },
144
- insertAt
145
- }
146
- })) !== null && _api$contentInsertion !== void 0 ? _api$contentInsertion : false;
147
142
  }
148
143
  },
149
144
  commands: {
150
- 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.tableOptions.allowTableAlignment, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
145
+ insertTableWithSize: fg('platform_editor_use_nested_table_pm_nodes') ? (rowsCount, colsCount, inputMethod) => insertTableWithNestingSupport({
146
+ isTableScalingEnabled: options === null || options === void 0 ? void 0 : options.isTableScalingEnabled,
147
+ isTableAlignmentEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableAlignment,
148
+ isFullWidthModeEnabled: options === null || options === void 0 ? void 0 : options.fullWidthEnabled,
149
+ isCommentEditor: options === null || options === void 0 ? void 0 : options.isCommentEditor,
150
+ isChromelessEditor: options === null || options === void 0 ? void 0 : options.isChromelessEditor,
151
+ isTableResizingEnabled: options === null || options === void 0 ? void 0 : options.tableOptions.allowTableResizing,
152
+ createTableProps: {
153
+ rowsCount,
154
+ colsCount
155
+ }
156
+ }, api, {
157
+ action: ACTION.INSERTED,
158
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
159
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
160
+ attributes: {
161
+ inputMethod: inputMethod !== null && inputMethod !== void 0 ? inputMethod : INPUT_METHOD.PICKER,
162
+ totalRowCount: rowsCount,
163
+ totalColumnCount: colsCount
164
+ },
165
+ eventType: EVENT_TYPE.TRACK
166
+ }) : 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.tableOptions.allowTableAlignment, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, options === null || options === void 0 ? void 0 : options.isCommentEditor)
151
167
  },
152
168
  nodes() {
153
169
  const {
154
170
  allowColumnResizing
155
171
  } = pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions);
172
+ // TODO: ED-25901 - We need to move this into a plugin config option so we don't accidentally enable nested nodes in Jira
156
173
  const isNestingSupported = fg('platform_editor_use_nested_table_pm_nodes');
157
174
  return isNestingSupported ? [{
158
175
  name: 'table',
@@ -30,17 +30,17 @@ export const autoScrollerFactory = ({
30
30
  return localId === (node === null || node === void 0 ? void 0 : node.attrs.localId) && type === 'table-column';
31
31
  },
32
32
  getOverflow: () => ({
33
- fromTopEdge: {
33
+ forTopEdge: {
34
34
  top: dropTargetExtendedWidth,
35
35
  right: dropTargetExtendedWidth,
36
36
  left: dropTargetExtendedWidth
37
37
  },
38
- fromRightEdge: {
38
+ forRightEdge: {
39
39
  right: dropTargetExtendedWidth,
40
40
  top: dropTargetExtendedWidth,
41
41
  bottom: dropTargetExtendedWidth
42
42
  },
43
- fromLeftEdge: {
43
+ forLeftEdge: {
44
44
  top: dropTargetExtendedWidth,
45
45
  left: dropTargetExtendedWidth,
46
46
  bottom: dropTargetExtendedWidth