@atlaskit/editor-plugin-table 7.24.3 → 7.24.5

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 (52) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/commands/misc.js +4 -2
  3. package/dist/cjs/commands-with-analytics.js +2 -2
  4. package/dist/cjs/nodeviews/TableCell.js +60 -4
  5. package/dist/cjs/nodeviews/TableComponent.js +2 -2
  6. package/dist/cjs/nodeviews/TableContainer.js +4 -1
  7. package/dist/cjs/toolbar.js +3 -3
  8. package/dist/cjs/types.js +1 -1
  9. package/dist/cjs/ui/TableFloatingColumnControls/index.js +1 -1
  10. package/dist/cjs/ui/TableFloatingControls/index.js +2 -2
  11. package/dist/cjs/ui/common-styles.js +1 -1
  12. package/dist/es2019/commands/misc.js +4 -2
  13. package/dist/es2019/commands-with-analytics.js +2 -2
  14. package/dist/es2019/nodeviews/TableCell.js +49 -0
  15. package/dist/es2019/nodeviews/TableComponent.js +2 -2
  16. package/dist/es2019/nodeviews/TableContainer.js +5 -1
  17. package/dist/es2019/toolbar.js +3 -3
  18. package/dist/es2019/types.js +1 -1
  19. package/dist/es2019/ui/TableFloatingColumnControls/index.js +1 -1
  20. package/dist/es2019/ui/TableFloatingControls/index.js +2 -2
  21. package/dist/es2019/ui/common-styles.js +8 -2
  22. package/dist/esm/commands/misc.js +4 -2
  23. package/dist/esm/commands-with-analytics.js +2 -2
  24. package/dist/esm/nodeviews/TableCell.js +60 -4
  25. package/dist/esm/nodeviews/TableComponent.js +2 -2
  26. package/dist/esm/nodeviews/TableContainer.js +4 -1
  27. package/dist/esm/toolbar.js +3 -3
  28. package/dist/esm/types.js +1 -1
  29. package/dist/esm/ui/TableFloatingColumnControls/index.js +1 -1
  30. package/dist/esm/ui/TableFloatingControls/index.js +2 -2
  31. package/dist/esm/ui/common-styles.js +1 -1
  32. package/dist/types/commands/misc.d.ts +1 -1
  33. package/dist/types/commands-with-analytics.d.ts +1 -1
  34. package/dist/types/nodeviews/TableCell.d.ts +2 -0
  35. package/dist/types/toolbar.d.ts +1 -1
  36. package/dist/types/types.d.ts +1 -1
  37. package/dist/types-ts4.5/commands/misc.d.ts +1 -1
  38. package/dist/types-ts4.5/commands-with-analytics.d.ts +1 -1
  39. package/dist/types-ts4.5/nodeviews/TableCell.d.ts +2 -0
  40. package/dist/types-ts4.5/toolbar.d.ts +1 -1
  41. package/dist/types-ts4.5/types.d.ts +1 -1
  42. package/package.json +7 -7
  43. package/src/commands/misc.ts +4 -2
  44. package/src/commands-with-analytics.ts +4 -2
  45. package/src/nodeviews/TableCell.ts +55 -0
  46. package/src/nodeviews/TableComponent.tsx +10 -2
  47. package/src/nodeviews/TableContainer.tsx +7 -1
  48. package/src/toolbar.tsx +3 -1
  49. package/src/types.ts +1 -1
  50. package/src/ui/TableFloatingColumnControls/index.tsx +1 -1
  51. package/src/ui/TableFloatingControls/index.tsx +2 -4
  52. package/src/ui/common-styles.ts +8 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "7.24.3",
3
+ "version": "7.24.5",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -31,7 +31,7 @@
31
31
  "@atlaskit/adf-schema": "^40.3.0",
32
32
  "@atlaskit/button": "^19.1.0",
33
33
  "@atlaskit/custom-steps": "^0.6.0",
34
- "@atlaskit/editor-common": "^87.1.0",
34
+ "@atlaskit/editor-common": "^87.3.0",
35
35
  "@atlaskit/editor-palette": "1.6.0",
36
36
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^1.6.0",
@@ -43,8 +43,8 @@
43
43
  "@atlaskit/editor-prosemirror": "5.0.1",
44
44
  "@atlaskit/editor-shared-styles": "^2.13.0",
45
45
  "@atlaskit/editor-tables": "^2.8.0",
46
- "@atlaskit/icon": "^22.8.0",
47
- "@atlaskit/menu": "^2.8.0",
46
+ "@atlaskit/icon": "^22.10.0",
47
+ "@atlaskit/menu": "^2.9.0",
48
48
  "@atlaskit/platform-feature-flags": "^0.3.0",
49
49
  "@atlaskit/pragmatic-drag-and-drop": "^1.2.0",
50
50
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
@@ -52,7 +52,7 @@
52
52
  "@atlaskit/primitives": "^11.1.0",
53
53
  "@atlaskit/theme": "^12.11.0",
54
54
  "@atlaskit/toggle": "^13.2.0",
55
- "@atlaskit/tokens": "^1.56.0",
55
+ "@atlaskit/tokens": "^1.57.0",
56
56
  "@atlaskit/tooltip": "^18.5.0",
57
57
  "@babel/runtime": "^7.0.0",
58
58
  "@emotion/react": "^11.7.1",
@@ -111,10 +111,10 @@
111
111
  "platform.editor.table.use-increased-scaling-percent": {
112
112
  "type": "boolean"
113
113
  },
114
- "platform.editor.table.live-pages-sorting_4malx": {
114
+ "platform_editor_dark_mode_cell_header_color_fix": {
115
115
  "type": "boolean"
116
116
  },
117
- "platform_editor_element_drag_and_drop_ed_24041": {
117
+ "platform.editor.table.live-pages-sorting_4malx": {
118
118
  "type": "boolean"
119
119
  },
120
120
  "editor_react_18_fix_table_delete_col_decorations": {
@@ -726,7 +726,7 @@ export const updateWidthToWidest = (widthToWidest: WidthToWidest) =>
726
726
  });
727
727
 
728
728
  export const setTableAlignment =
729
- (newAlignment: TableLayout): EditorCommand =>
729
+ (newAlignment: TableLayout, isCommentEditor: boolean): EditorCommand =>
730
730
  ({ tr }) => {
731
731
  const tableObject = findTable(tr.selection);
732
732
 
@@ -741,7 +741,9 @@ export const setTableAlignment =
741
741
 
742
742
  // table uses old breakout values in layout attribute to determine width
743
743
  // but that information is lost when alignment changes, so we need to ensure we retain that info
744
- if (!tableObject.node.attrs.width) {
744
+ // If table width is not set in the Comment editor, it means that the table width is inherited from the editor and is "full width".
745
+ // In that case when switching between alignment options in the Comment editor we should keep the table width unset.
746
+ if (!tableObject.node.attrs.width && !isCommentEditor) {
745
747
  const tableWidth = getTableContainerWidth(tableObject.node);
746
748
  nextTableAttrs.width = tableWidth;
747
749
  }
@@ -658,7 +658,7 @@ export const toggleFixedColumnWidthsOptionAnalytics = (
658
658
  })(editorAnalyticsAPI)(editorCommandToPMCommand(setTableDisplayMode));
659
659
 
660
660
  export const setTableAlignmentWithAnalytics =
661
- (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
661
+ (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, isCommentEditor: boolean) =>
662
662
  (
663
663
  newAlignment: AlignmentOptions,
664
664
  // previous alignment could be a breakout value, if so use 'null' to indicate alignment was not previously set
@@ -687,7 +687,9 @@ export const setTableAlignmentWithAnalytics =
687
687
  reason,
688
688
  },
689
689
  };
690
- })(editorAnalyticsAPI)(editorCommandToPMCommand(setTableAlignment(newAlignment)));
690
+ })(editorAnalyticsAPI)(
691
+ editorCommandToPMCommand(setTableAlignment(newAlignment, isCommentEditor)),
692
+ );
691
693
 
692
694
  export const setTableAlignmentWithTableContentWithPosWithAnalytics =
693
695
  (editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null) =>
@@ -3,13 +3,33 @@ import { getCellAttrs, getCellDomAttrs } from '@atlaskit/adf-schema';
3
3
  import type { EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
4
4
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
5
5
  import type { EditorView, NodeView } from '@atlaskit/editor-prosemirror/view';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
 
7
8
  import TableNodeView from './TableNodeViewBase';
8
9
 
9
10
  const DEFAULT_COL_SPAN = 1;
10
11
  const DEFAULT_ROW_SPAN = 1;
11
12
 
13
+ /**
14
+ * For performance reasons we do this in the background - it shouldn't block the main thread
15
+ */
16
+ function delayUntilIdle(cb: Function) {
17
+ if (typeof window === 'undefined') {
18
+ return;
19
+ }
20
+ // eslint-disable-next-line compat/compat
21
+ if (window.requestIdleCallback !== undefined) {
22
+ // eslint-disable-next-line compat/compat
23
+ return window.requestIdleCallback(() => cb(), { timeout: 500 });
24
+ }
25
+ return window.requestAnimationFrame(() => cb());
26
+ }
27
+
28
+ const cssVariablePattern = /^VAR\(--.*\)$/;
29
+
12
30
  export default class TableCell extends TableNodeView<HTMLElement> implements NodeView {
31
+ private delayHandle: number | undefined;
32
+
13
33
  constructor(
14
34
  node: PMNode,
15
35
  view: EditorView,
@@ -17,8 +37,43 @@ export default class TableCell extends TableNodeView<HTMLElement> implements Nod
17
37
  eventDispatcher: EventDispatcher,
18
38
  ) {
19
39
  super(node, view, getPos, eventDispatcher);
40
+
41
+ // CONFCLOUD-78239: Previously we had a bug which tried to invert the heading colour of a table
42
+ // Obviously design tokens can't be inverted and so it would result in `VAR(--DS-BACKGROUND-ACCENT-GRAY-SUBTLEST, #F4F5F7)`
43
+ // which is not a valid CSS variable.
44
+ //
45
+ // We should follow-up and remove this in TODO-xx in 6 months once we're confident
46
+ // that this has fixed most of the cases in the wild.
47
+ //
48
+ // This is a workaround to fix those cases on the fly. Note it is super specific on purpose
49
+ // so that it just fixes the heading token (other tokens should be unaffected)
50
+ // At some point in the future
51
+ if (
52
+ cssVariablePattern.test(node.attrs.background) &&
53
+ fg('platform_editor_dark_mode_cell_header_color_fix')
54
+ ) {
55
+ this.delayHandle = delayUntilIdle(() => {
56
+ const pos = getPos();
57
+ if (pos) {
58
+ view.dispatch(
59
+ view.state.tr
60
+ .setNodeAttribute(pos, 'background', node.attrs.background.toLowerCase())
61
+ // Ensures dispatch does not contribute to undo history (otherwise user requires multiple undo's to revert table)
62
+ .setMeta('addToHistory', false),
63
+ );
64
+ }
65
+ });
66
+ }
20
67
  }
21
68
 
69
+ destroy = () => {
70
+ if (this.delayHandle && typeof window !== 'undefined') {
71
+ // eslint-disable-next-line compat/compat
72
+ window?.cancelIdleCallback?.(this.delayHandle);
73
+ window?.cancelAnimationFrame?.(this.delayHandle);
74
+ }
75
+ };
76
+
22
77
  update(node: PMNode) {
23
78
  const didUpdate = this.updateNodeView(node);
24
79
  if (didUpdate) {
@@ -852,7 +852,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
852
852
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
853
853
  style={shadowStyle(showBeforeShadow)}
854
854
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
855
- className={ClassName.TABLE_LEFT_SHADOW}
855
+ className={
856
+ options?.isChromelessEditor && !isDragAndDropEnabled
857
+ ? ClassName.TABLE_LEFT_SHADOW + ' ' + ClassName.TABLE_CHROMELESS
858
+ : ClassName.TABLE_LEFT_SHADOW
859
+ }
856
860
  />
857
861
  {this.state.stickyHeader && (
858
862
  <div
@@ -910,7 +914,11 @@ class TableComponent extends React.Component<ComponentProps, TableState> {
910
914
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
911
915
  style={shadowStyle(showAfterShadow)}
912
916
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
913
- className={ClassName.TABLE_RIGHT_SHADOW}
917
+ className={
918
+ options?.isChromelessEditor && !isDragAndDropEnabled
919
+ ? ClassName.TABLE_RIGHT_SHADOW + ' ' + ClassName.TABLE_CHROMELESS
920
+ : ClassName.TABLE_RIGHT_SHADOW
921
+ }
914
922
  />
915
923
  {this.state.stickyHeader && (
916
924
  <div
@@ -21,6 +21,7 @@ import {
21
21
  } from '@atlaskit/editor-shared-styles';
22
22
 
23
23
  import { setTableAlignmentWithTableContentWithPosWithAnalytics } from '../commands-with-analytics';
24
+ import { getPluginState } from '../pm-plugins/plugin-factory';
24
25
  import {
25
26
  TABLE_MAX_WIDTH,
26
27
  TABLE_OFFSET_IN_COMMENT_EDITOR,
@@ -455,12 +456,17 @@ export const TableContainer = ({
455
456
  );
456
457
  }
457
458
 
459
+ const { isDragAndDropEnabled } = getPluginState(editorView.state);
460
+
458
461
  return (
459
462
  <InnerContainer
460
463
  node={node}
461
464
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
462
465
  className={classNames(className, {
463
- 'less-padding': editorWidth < akEditorMobileBreakoutPoint && !isNested,
466
+ 'less-padding':
467
+ editorWidth < akEditorMobileBreakoutPoint &&
468
+ !isNested &&
469
+ !(isChromelessEditor && isDragAndDropEnabled),
464
470
  })}
465
471
  style={{
466
472
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
package/src/toolbar.tsx CHANGED
@@ -530,6 +530,7 @@ export const getToolbarConfig =
530
530
  editorView,
531
531
  shouldUseIncreasedScalingPercent,
532
532
  options?.fullWidthEnabled,
533
+ options?.isCommentEditor,
533
534
  )
534
535
  : [];
535
536
 
@@ -862,6 +863,7 @@ export const getAlignmentOptionsConfig = (
862
863
  editorView: EditorView | null,
863
864
  shouldUseIncreasedScalingPercent: boolean,
864
865
  isFullWidthEditor?: boolean,
866
+ isCommentEditor?: boolean,
865
867
  ): Array<FloatingToolbarDropdown<Command>> => {
866
868
  const tableObject = findTable(editorState.selection);
867
869
 
@@ -898,7 +900,7 @@ export const getAlignmentOptionsConfig = (
898
900
  icon: icon,
899
901
  title: formatMessage(layoutToMessages[value]),
900
902
  selected: normaliseAlignment(currentLayout) === value,
901
- onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI)(
903
+ onClick: setTableAlignmentWithAnalytics(editorAnalyticsAPI, isCommentEditor || false)(
902
904
  value,
903
905
  currentLayout,
904
906
  INPUT_METHOD.FLOATING_TB,
package/src/types.ts CHANGED
@@ -389,7 +389,6 @@ export const TableCssClassName = {
389
389
  /** drag and drop controls */
390
390
  DRAG_ROW_CONTROLS_WRAPPER: `${tablePrefixSelector}-drag-row-controls-wrapper`,
391
391
  DRAG_ROW_CONTROLS: `${tablePrefixSelector}-drag-row-controls`,
392
- DRAG_CONTROLS_CHROMELESS: `drag-controls-chromeless`,
393
392
  DRAG_ROW_FLOATING_INSERT_DOT_WRAPPER: `${tablePrefixSelector}-drag-row-floating-insert-dot-wrapper`,
394
393
  DRAG_ROW_FLOATING_INSERT_DOT: `${tablePrefixSelector}-drag-row-floating-insert-dot`,
395
394
 
@@ -454,6 +453,7 @@ export const TableCssClassName = {
454
453
  TABLE_CELL: tableCellSelector,
455
454
  TABLE_HEADER_CELL: tableHeaderSelector,
456
455
  TABLE_STICKY: `${tablePrefixSelector}-sticky`,
456
+ TABLE_CHROMELESS: `${tablePrefixSelector}-chromeless`,
457
457
 
458
458
  TOP_LEFT_CELL: 'table > tbody > tr:nth-child(2) > td:nth-child(1)',
459
459
  LAST_ITEM_IN_CELL: `${tablePrefixSelector}-last-item-in-cell`,
@@ -113,7 +113,7 @@ export const TableFloatingColumnControls = ({
113
113
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
114
114
  className={
115
115
  ClassName.DRAG_COLUMN_CONTROLS_WRAPPER +
116
- (isChromelessEditor ? ' ' + ClassName.DRAG_CONTROLS_CHROMELESS : '')
116
+ (isChromelessEditor ? ' ' + ClassName.TABLE_CHROMELESS : '')
117
117
  }
118
118
  data-testid="table-floating-column-controls-wrapper"
119
119
  >
@@ -129,15 +129,13 @@ export const TableFloatingControls = ({
129
129
 
130
130
  const wrapperClassName = isDragAndDropEnabled
131
131
  ? isChromelessEditor
132
- ? ClassName.DRAG_ROW_CONTROLS_WRAPPER + ' ' + ClassName.DRAG_CONTROLS_CHROMELESS
132
+ ? ClassName.DRAG_ROW_CONTROLS_WRAPPER + ' ' + ClassName.TABLE_CHROMELESS
133
133
  : ClassName.DRAG_ROW_CONTROLS_WRAPPER
134
134
  : ClassName.ROW_CONTROLS_WRAPPER;
135
135
 
136
136
  const tablePos = findTable(editorView.state.selection)?.pos;
137
137
  const isNested = tablePos !== undefined && isTableNested(editorView.state, tablePos!);
138
- const shouldShowCornerControls = fg('platform_editor_element_drag_and_drop_ed_24041')
139
- ? !featureFlagsState?.elementDragAndDrop || isNested
140
- : !featureFlagsState?.elementDragAndDrop;
138
+ const shouldShowCornerControls = !featureFlagsState?.elementDragAndDrop || isNested;
141
139
 
142
140
  return (
143
141
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
@@ -514,7 +514,7 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
514
514
  }
515
515
  }
516
516
 
517
- .${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.DRAG_CONTROLS_CHROMELESS} {
517
+ .${ClassName.DRAG_ROW_CONTROLS_WRAPPER}.${ClassName.TABLE_CHROMELESS} {
518
518
  left: -4px;
519
519
  }
520
520
 
@@ -522,7 +522,7 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
522
522
  padding: 0 ${tablePadding}px;
523
523
  }
524
524
 
525
- .${ClassName.DRAG_COLUMN_CONTROLS_WRAPPER}.${ClassName.DRAG_CONTROLS_CHROMELESS} {
525
+ .${ClassName.DRAG_COLUMN_CONTROLS_WRAPPER}.${ClassName.TABLE_CHROMELESS} {
526
526
  left: -8px;
527
527
  }
528
528
 
@@ -536,10 +536,16 @@ export const baseTableStyles = (props: { featureFlags?: FeatureFlags }) => css`
536
536
  .${ClassName.TABLE_LEFT_SHADOW} {
537
537
  left: 6px;
538
538
  }
539
+ .${ClassName.TABLE_LEFT_SHADOW}.${ClassName.TABLE_CHROMELESS} {
540
+ left: 8px;
541
+ }
539
542
 
540
543
  .${ClassName.TABLE_RIGHT_SHADOW} {
541
544
  left: calc(100% - 6px);
542
545
  }
546
+ .${ClassName.TABLE_RIGHT_SHADOW}.${ClassName.TABLE_CHROMELESS} {
547
+ left: calc(100% - 16px);
548
+ }
543
549
  }
544
550
 
545
551
  > .${ClassName.NODEVIEW_WRAPPER} {