@atlaskit/editor-plugin-table 7.30.0 → 7.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/plugin.tsx CHANGED
@@ -22,6 +22,10 @@ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
22
22
  import { IconTable } from '@atlaskit/editor-common/icons';
23
23
  import { toggleTable, tooltip } from '@atlaskit/editor-common/keymaps';
24
24
  import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
25
+ import {
26
+ getParentOfTypeCount,
27
+ getPositionAfterTopParentNodeOfType,
28
+ } from '@atlaskit/editor-common/nesting';
25
29
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
26
30
  import type {
27
31
  Command,
@@ -42,11 +46,14 @@ import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
42
46
  import type { GuidelinePlugin } from '@atlaskit/editor-plugin-guideline';
43
47
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
44
48
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
49
+ import { type Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
45
50
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
51
+ import { hasParentNodeOfType, safeInsert } from '@atlaskit/editor-prosemirror/utils';
46
52
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
47
53
  import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
48
54
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
49
55
  import { fg } from '@atlaskit/platform-feature-flags';
56
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
50
57
 
51
58
  import { insertTableWithSize } from './commands/insert';
52
59
  import { pluginConfig } from './create-plugin-config';
@@ -233,12 +240,32 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
233
240
  isTableResizingEnabled: options?.tableResizingEnabled,
234
241
  })(state.schema);
235
242
 
243
+ // If the cursor is inside a table
244
+ let insertAt: Selection | undefined;
245
+ if (
246
+ hasParentNodeOfType(state.schema.nodes.table)(state.selection) &&
247
+ fg('platform_editor_use_nested_table_pm_nodes')
248
+ ) {
249
+ // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
250
+ if (
251
+ editorExperiment('nested-tables-in-tables', false, { exposure: true }) ||
252
+ getParentOfTypeCount(state.schema.nodes.table)(state.selection) > 1
253
+ ) {
254
+ const positionAfterTopTable = getPositionAfterTopParentNodeOfType(
255
+ state.schema.nodes.table,
256
+ )(state.selection);
257
+ if (!positionAfterTopTable) {
258
+ return false;
259
+ }
260
+ insertAt = TextSelection.create(state.doc, positionAfterTopTable);
261
+ }
262
+ }
263
+
236
264
  return (
237
265
  api?.contentInsertion?.actions?.insert({
238
266
  state,
239
267
  dispatch,
240
268
  node,
241
-
242
269
  options: {
243
270
  selectNodeInserted: false,
244
271
  analyticsPayload: {
@@ -248,6 +275,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
248
275
  localId: node.attrs.localId,
249
276
  },
250
277
  },
278
+ insertAt,
251
279
  },
252
280
  }) ?? false
253
281
  );
@@ -749,7 +777,30 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
749
777
  isTableResizingEnabled: options?.tableResizingEnabled,
750
778
  })(state.schema);
751
779
 
752
- const tr = insert(tableNode);
780
+ let { tr } = state;
781
+ // If the cursor is inside a table
782
+ if (
783
+ hasParentNodeOfType(state.schema.nodes.table)(state.selection) &&
784
+ fg('platform_editor_use_nested_table_pm_nodes')
785
+ ) {
786
+ // If the experiment is disabled, or we're trying to nest deeper than one level, we insert the table after the top table
787
+ if (
788
+ editorExperiment('nested-tables-in-tables', false, { exposure: true }) ||
789
+ getParentOfTypeCount(state.schema.nodes.table)(state.selection) > 1
790
+ ) {
791
+ // Nesting is too deep insert table after the top parent table
792
+ const positionAfterTopTable = getPositionAfterTopParentNodeOfType(
793
+ state.schema.nodes.table,
794
+ )(state.selection);
795
+ tr = safeInsert(tableNode, positionAfterTopTable)(tr);
796
+ tr.scrollIntoView();
797
+ } else {
798
+ // Table can be nested in parent table
799
+ tr = insert(tableNode);
800
+ }
801
+ } else {
802
+ tr = insert(tableNode);
803
+ }
753
804
 
754
805
  editorAnalyticsAPI?.attachAnalyticsEvent({
755
806
  action: ACTION.INSERTED,
@@ -316,7 +316,7 @@ export function keymapPlugin(
316
316
  ),
317
317
  list,
318
318
  );
319
-
319
+
320
320
  bindKeymapWithCommand(
321
321
  escape.common!,
322
322
  stopKeyboardColumnResizing({
package/src/toDOM.ts CHANGED
@@ -2,7 +2,7 @@ import kebabCase from 'lodash/kebabCase';
2
2
 
3
3
  import { table, tableWithNestedTable } from '@atlaskit/adf-schema';
4
4
  import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
5
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/src/types';
5
+ import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
6
6
  import type { DOMOutputSpec, NodeSpec, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
7
7
  import { akEditorGutterPaddingDynamic } from '@atlaskit/editor-shared-styles';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
package/src/toolbar.tsx CHANGED
@@ -11,7 +11,7 @@ import { CHANGE_ALIGNMENT_REASON, INPUT_METHOD } from '@atlaskit/editor-common/a
11
11
  import { addColumnAfter, addRowAfter, backspace, tooltip } from '@atlaskit/editor-common/keymaps';
12
12
  import commonMessages, { tableMessages as messages } from '@atlaskit/editor-common/messages';
13
13
  import { getTableContainerWidth } from '@atlaskit/editor-common/node-width';
14
- import type { typeOption } from '@atlaskit/editor-common/src/types/floating-toolbar';
14
+ import type { typeOption } from '@atlaskit/editor-common/types';
15
15
  import type {
16
16
  Command,
17
17
  CommandDispatch,
@@ -137,7 +137,7 @@ export const FixedButton = ({
137
137
  return 0;
138
138
  }
139
139
 
140
- const container = targetCellRef.closest('[data-testid="ak-editor-fp-content-area"]');
140
+ const container = targetCellRef.closest('[data-editor-container="true"]');
141
141
  return container?.getBoundingClientRect().left || 0;
142
142
  }, [targetCellRef]);
143
143
 
@@ -21,9 +21,9 @@ import {
21
21
  SelectionStyle,
22
22
  } from '@atlaskit/editor-shared-styles';
23
23
  import { scrollbarStyles } from '@atlaskit/editor-shared-styles/scrollbar';
24
- import { fg } from '@atlaskit/platform-feature-flags';
25
24
  import { N0, N40A, R500 } from '@atlaskit/theme/colors';
26
25
  import { fontSize } from '@atlaskit/theme/constants';
26
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
27
27
  import { token } from '@atlaskit/tokens';
28
28
 
29
29
  import { SORTING_ICON_CLASS_NAME } from '../pm-plugins/view-mode-sort/consts';
@@ -192,19 +192,6 @@ const breakoutWidthStyling = () => {
192
192
  `;
193
193
  };
194
194
 
195
- const stickyHeaderMarginTop = () => {
196
- // Exceptional case: can't add this FF to package.json as a new ratcheting rule was added to prevent new LD flags.
197
- // This LD flag existed in other packages before the rule was introduced.
198
- // eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-registration
199
- if (!fg('platform.confluence.frontend.narrow-full-page-editor-toolbar')) {
200
- return css`
201
- margin-top: 2px;
202
- `;
203
- }
204
-
205
- return css``;
206
- };
207
-
208
195
  const viewModeSortStyles = () => {
209
196
  return css`
210
197
  th {
@@ -284,7 +271,7 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
284
271
  ${hoveredDeleteButton()};
285
272
  ${hoveredCell()};
286
273
  ${hoveredWarningCell};
287
- ${props.featureFlags?.tableDragAndDrop && insertLine()};
274
+ ${insertLine()};
288
275
  ${resizeHandle(props.featureFlags?.tableDragAndDrop)};
289
276
  ${rangeSelectionStyles};
290
277
  ${viewModeSortStyles()};
@@ -401,9 +388,6 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
401
388
  /* background for where controls apply */
402
389
  background: ${token('elevation.surface', 'white')};
403
390
  box-sizing: content-box;
404
-
405
- ${stickyHeaderMarginTop()}
406
-
407
391
  box-shadow: 0 6px 4px -4px ${token('elevation.shadow.overflow.perimeter', N40A)};
408
392
  margin-left: -1px;
409
393
 
@@ -848,7 +832,10 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
848
832
  position: relative;
849
833
  float: right;
850
834
  margin-left: ${akEditorTableToolbarSize}px;
851
- top: ${props.featureFlags?.tableDragAndDrop ? 0 : akEditorTableToolbarSize}px;
835
+ top: ${props.featureFlags?.tableDragAndDrop ||
836
+ editorExperiment('support_table_in_comment_jira', true)
837
+ ? 0
838
+ : akEditorTableToolbarSize}px;
852
839
  width: ${akEditorTableNumberColumnWidth + 1}px;
853
840
  box-sizing: border-box;
854
841
  }