@atlaskit/editor-plugin-insert-block 0.2.17 → 0.2.19

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.
@@ -15,6 +15,7 @@ import * as colors from '@atlaskit/theme/colors';
15
15
  import { BlockInsertMenu } from './block-insert-menu';
16
16
  import { createItems } from './create-items';
17
17
  import { messages } from './messages';
18
+ import TableSelectorPopup from './table-selector-popup-with-listeners';
18
19
  /**
19
20
  * Checks if an element is detached (i.e. not in the current document)
20
21
  */
@@ -31,10 +32,13 @@ const getHoverStyles = selector => `&:hover ${selector} {
31
32
  background: ${`var(--ds-background-neutral-hovered, ${colors.N30A})`};
32
33
  }
33
34
  }`;
34
- export const tableButtonWrapper = css`
35
+ export const tableButtonWrapper = ({
36
+ isTableSelectorOpen,
37
+ isButtonDisabled
38
+ }) => css`
35
39
  display: flex;
36
- ${getHoverStyles('.table-selector-toolbar-btn')}
37
- ${getHoverStyles('.table-toolbar-btn')}
40
+ ${!isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-selector-toolbar-btn')}
41
+ ${!isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-toolbar-btn')}
38
42
 
39
43
  .table-toolbar-btn {
40
44
  border-top-right-radius: ${"var(--ds-border-radius-200, 0px)"};
@@ -42,6 +46,7 @@ export const tableButtonWrapper = css`
42
46
  margin-right: ${"var(--ds-space-025, 1px)"};
43
47
  padding: ${"var(--ds-space-0, 0px)"};
44
48
  & > span {
49
+ min-width: 16px;
45
50
  margin: ${"var(--ds-space-0, 0px)"};
46
51
  }
47
52
  }
@@ -63,6 +68,8 @@ export const tableButtonWrapper = css`
63
68
  export class ToolbarInsertBlock extends React.PureComponent {
64
69
  constructor(...args) {
65
70
  super(...args);
71
+ _defineProperty(this, "tableButtonRef", /*#__PURE__*/React.createRef());
72
+ _defineProperty(this, "tableSelectorButtonRef", /*#__PURE__*/React.createRef());
66
73
  _defineProperty(this, "state", {
67
74
  isPlusMenuOpen: false,
68
75
  emojiPickerOpen: false,
@@ -169,6 +176,26 @@ export class ToolbarInsertBlock extends React.PureComponent {
169
176
  this.dropdownButtonRef = ref;
170
177
  }
171
178
  });
179
+ _defineProperty(this, "toggleTableSelector", (inputMethod = INPUT_METHOD.TOOLBAR) => {
180
+ this.setState(prevState => ({
181
+ isTableSelectorOpen: !prevState.isTableSelectorOpen
182
+ }));
183
+ });
184
+ _defineProperty(this, "handleSelectedTableSize", (rowsCount, colsCount) => {
185
+ this.insertTableWithSize(INPUT_METHOD.TOOLBAR, rowsCount, colsCount)();
186
+ this.toggleTableSelector();
187
+ });
188
+ _defineProperty(this, "handleTableSelectorPressEscape", () => {
189
+ var _this$tableSelectorBu;
190
+ this.toggleTableSelector(INPUT_METHOD.KEYBOARD);
191
+ (_this$tableSelectorBu = this.tableSelectorButtonRef.current) === null || _this$tableSelectorBu === void 0 ? void 0 : _this$tableSelectorBu.focus();
192
+ });
193
+ _defineProperty(this, "handleTableSelectorClickOutside", e => {
194
+ // Ignore click events for detached elements.
195
+ if (e.target && !isDetachedElement(e.target)) {
196
+ this.toggleTableSelector(INPUT_METHOD.TOOLBAR);
197
+ }
198
+ });
172
199
  _defineProperty(this, "handleClick", () => {
173
200
  this.togglePlusMenuVisibility();
174
201
  });
@@ -374,7 +401,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
374
401
  this.insertTable(inputMethod);
375
402
  break;
376
403
  case 'table selector':
377
- this.insertTableWithSize(inputMethod, 4, 4)(); // adding command here to pass typecheck but will implement the actual feature in future ticket
404
+ this.toggleTableSelector(inputMethod);
378
405
  break;
379
406
  case 'image upload':
380
407
  if (handleImageUpload) {
@@ -490,10 +517,11 @@ export class ToolbarInsertBlock extends React.PureComponent {
490
517
  };
491
518
  }
492
519
  componentDidUpdate(prevProps) {
493
- // If number of visible buttons changed, close emoji picker
520
+ // If number of visible buttons changed, close emoji picker and table selector
494
521
  if (prevProps.buttons !== this.props.buttons) {
495
522
  this.setState({
496
- emojiPickerOpen: false
523
+ emojiPickerOpen: false,
524
+ isTableSelectorOpen: false
497
525
  });
498
526
  }
499
527
  if (this.state.isOpenedByKeyboard) {
@@ -547,12 +575,37 @@ export class ToolbarInsertBlock extends React.PureComponent {
547
575
  handleEscapeKeydown: this.handleEmojiPressEscape
548
576
  }));
549
577
  }
578
+ renderTableSelectorPopup() {
579
+ var _this$tableButtonRef$;
580
+ const {
581
+ isTableSelectorOpen
582
+ } = this.state;
583
+ const {
584
+ popupsMountPoint,
585
+ popupsBoundariesElement,
586
+ popupsScrollableElement
587
+ } = this.props;
588
+ const ref = (_this$tableButtonRef$ = this.tableButtonRef.current) !== null && _this$tableButtonRef$ !== void 0 ? _this$tableButtonRef$ : undefined;
589
+ if (!isTableSelectorOpen) {
590
+ return null;
591
+ }
592
+ return jsx(TableSelectorPopup, {
593
+ target: ref,
594
+ onSelection: this.handleSelectedTableSize,
595
+ popupsMountPoint: popupsMountPoint,
596
+ popupsBoundariesElement: popupsBoundariesElement,
597
+ popupsScrollableElement: popupsScrollableElement,
598
+ handleClickOutside: this.handleTableSelectorClickOutside,
599
+ handleEscapeKeydown: this.handleTableSelectorPressEscape
600
+ });
601
+ }
550
602
  render() {
551
- var _tableButton, _tableButton2, _tableButton3, _tableButton4, _tableButton5, _tableButton6, _tableSelectorButton, _tableSelectorButton2, _tableSelectorButton3, _tableSelectorButton4, _tableSelectorButton5, _tableSelectorButton6, _this$props$isDisable, _this$props$replacePl;
603
+ var _tableButton, _tableButton2, _tableButton3, _tableButton4, _tableButton5, _tableButton6, _tableButton7, _tableSelectorButton, _tableSelectorButton2, _tableSelectorButton3, _tableSelectorButton4, _tableSelectorButton5, _tableSelectorButton6, _this$props$isDisable, _this$props$replacePl;
552
604
  const {
553
605
  buttons,
554
606
  dropdownItems,
555
- emojiPickerOpen
607
+ emojiPickerOpen,
608
+ isTableSelectorOpen
556
609
  } = this.state;
557
610
  const {
558
611
  isDisabled,
@@ -595,20 +648,23 @@ export class ToolbarInsertBlock extends React.PureComponent {
595
648
  "aria-keyshortcuts": btn['aria-keyshortcuts'],
596
649
  onItemClick: this.insertToolbarMenuItem
597
650
  });
598
- }), this.props.tableSelectorSupported &&
599
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
600
- jsx("div", {
601
- css: tableButtonWrapper
651
+ }), this.props.tableSelectorSupported && jsx("div", {
652
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
653
+ css: tableButtonWrapper({
654
+ isTableSelectorOpen,
655
+ isButtonDisabled: (_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.isDisabled
656
+ })
602
657
  }, jsx(ToolbarButton, {
603
658
  className: "table-toolbar-btn",
604
659
  item: tableButton,
605
- testId: String((_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.content),
606
- key: (_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.value.name,
660
+ ref: this.tableButtonRef,
661
+ testId: String((_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.content),
662
+ key: (_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.value.name,
607
663
  spacing: isReducedSpacing ? 'none' : 'default',
608
- disabled: isDisabled || ((_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.isDisabled),
609
- iconBefore: (_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.elemBefore,
610
- selected: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.isActive,
611
- title: (_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.title,
664
+ disabled: isDisabled || ((_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.isDisabled),
665
+ iconBefore: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.elemBefore,
666
+ selected: ((_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.isActive) || isTableSelectorOpen,
667
+ title: (_tableButton7 = tableButton) === null || _tableButton7 === void 0 ? void 0 : _tableButton7.title,
612
668
  "aria-label": tableButton ? tableButton['aria-label'] : undefined,
613
669
  "aria-haspopup": tableButton ? tableButton['aria-haspopup'] : undefined,
614
670
  "aria-keyshortcuts": tableButton ? tableButton['aria-keyshortcuts'] : undefined,
@@ -618,10 +674,11 @@ export class ToolbarInsertBlock extends React.PureComponent {
618
674
  item: tableSelectorButton,
619
675
  testId: String((_tableSelectorButton = tableSelectorButton) === null || _tableSelectorButton === void 0 ? void 0 : _tableSelectorButton.content),
620
676
  key: (_tableSelectorButton2 = tableSelectorButton) === null || _tableSelectorButton2 === void 0 ? void 0 : _tableSelectorButton2.value.name,
677
+ ref: this.tableSelectorButtonRef,
621
678
  spacing: isReducedSpacing ? 'none' : 'default',
622
679
  disabled: isDisabled || ((_tableSelectorButton3 = tableSelectorButton) === null || _tableSelectorButton3 === void 0 ? void 0 : _tableSelectorButton3.isDisabled),
623
680
  iconBefore: (_tableSelectorButton4 = tableSelectorButton) === null || _tableSelectorButton4 === void 0 ? void 0 : _tableSelectorButton4.elemBefore,
624
- selected: (_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive,
681
+ selected: ((_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive) || isTableSelectorOpen,
625
682
  title: (_tableSelectorButton6 = tableSelectorButton) === null || _tableSelectorButton6 === void 0 ? void 0 : _tableSelectorButton6.title,
626
683
  "aria-label": tableSelectorButton ? tableSelectorButton['aria-label'] : undefined,
627
684
  "aria-haspopup": tableSelectorButton ? tableSelectorButton['aria-haspopup'] : undefined,
@@ -629,7 +686,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
629
686
  onItemClick: this.insertToolbarMenuItem
630
687
  })), jsx("span", {
631
688
  css: wrapperStyle
632
- }, this.renderPopup(), jsx(BlockInsertMenu, {
689
+ }, this.renderPopup(), this.renderTableSelectorPopup(), jsx(BlockInsertMenu, {
633
690
  popupsMountPoint: this.props.popupsMountPoint,
634
691
  popupsBoundariesElement: this.props.popupsBoundariesElement,
635
692
  popupsScrollableElement: this.props.popupsScrollableElement,
@@ -0,0 +1,101 @@
1
+ /** @jsx jsx */
2
+
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { css, jsx } from '@emotion/react';
5
+ import { bind } from 'bind-event-listener';
6
+ import { Popup } from '@atlaskit/editor-common/ui';
7
+ import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
8
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
9
+ import { N0, N30A, N60A } from '@atlaskit/theme/colors';
10
+ import tableSelectorPopup, { TABLE_SELECTOR_BUTTON_GAP, TABLE_SELECTOR_BUTTON_SIZE } from './table-selector-popup';
11
+ const TABLE_SELECTOR_PADDING_TOP = 8;
12
+ const TABLE_SELECTOR_PADDING_SIDE = 10;
13
+ const DEFAULT_TABLE_SELECTOR_ROWS = 5;
14
+ const DEFAULT_TABLE_SELECTOR_COLS = 10;
15
+ const DEFAULT_TABLE_SELECTOR_SELECTION_SIZE = 1;
16
+ const TableSelectorWithListeners = withOuterListeners(tableSelectorPopup);
17
+ const tableSelectorPopupWrapperStyles = css({
18
+ borderRadius: "var(--ds-border-radius, 3px)",
19
+ backgroundColor: `var(--ds-surface-overlay, ${N0})`,
20
+ boxShadow: `var(--ds-shadow-overlay, ${`0 0 0 1px ${N30A}, 0 2px 1px ${N30A}, 0 0 20px -6px ${N60A}`})`,
21
+ padding: `${`var(--ds-space-100, ${`${TABLE_SELECTOR_PADDING_TOP}px`})`} ${TABLE_SELECTOR_PADDING_SIDE}px`
22
+ });
23
+ export const TableSelectorPopup = props => {
24
+ const [size, setSize] = useState({
25
+ col: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
26
+ row: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
27
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
28
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
29
+ });
30
+ const tablePopupRef = useRef(null);
31
+
32
+ // Mouse move is used to allow selection changes outside of the popup and is more reactive to changes.
33
+ const handleMouseMove = useCallback(e => {
34
+ if (!tablePopupRef.current) {
35
+ return;
36
+ }
37
+ const tablePopup = tablePopupRef.current;
38
+ const {
39
+ left,
40
+ top
41
+ } = tablePopup.getBoundingClientRect();
42
+
43
+ // Mouse position on popup
44
+ const selectedWidth = e.clientX - left;
45
+ const selectedHeight = e.clientY - top;
46
+
47
+ // Calculate number grid cells selected
48
+ let selectedGridCols = Math.ceil((selectedWidth - TABLE_SELECTOR_PADDING_SIDE + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
49
+ let selectedGridRows = Math.ceil((selectedHeight - TABLE_SELECTOR_PADDING_TOP + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
50
+
51
+ // Keep the selected rows and columns within the defined bounds
52
+ if (selectedGridCols < 1) {
53
+ selectedGridCols = 1;
54
+ }
55
+ if (selectedGridCols > size.maxCol) {
56
+ selectedGridCols = size.maxCol;
57
+ }
58
+ if (selectedGridRows < 1) {
59
+ selectedGridRows = 1;
60
+ }
61
+ if (selectedGridRows > size.maxRow) {
62
+ selectedGridRows = size.maxRow;
63
+ }
64
+ if (selectedGridCols !== size.col || selectedGridRows !== size.row) {
65
+ setSize({
66
+ col: selectedGridCols,
67
+ row: selectedGridRows,
68
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
69
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
70
+ });
71
+ }
72
+ }, [size, setSize]);
73
+ useEffect(() => {
74
+ const unbind = bind(window, {
75
+ type: 'mousemove',
76
+ listener: handleMouseMove
77
+ });
78
+ return unbind;
79
+ }, [handleMouseMove]);
80
+ return jsx(Popup, {
81
+ target: props.target,
82
+ offset: [0, 3],
83
+ mountTo: props.popupsMountPoint,
84
+ boundariesElement: props.popupsBoundariesElement,
85
+ scrollableElement: props.popupsScrollableElement,
86
+ focusTrap: true,
87
+ zIndex: akEditorMenuZIndex
88
+ }, jsx("div", {
89
+ css: tableSelectorPopupWrapperStyles,
90
+ ref: tablePopupRef
91
+ }, jsx(TableSelectorWithListeners, {
92
+ handleClickOutside: props.handleClickOutside,
93
+ handleEscapeKeydown: props.handleEscapeKeydown,
94
+ maxCols: size.maxCol,
95
+ maxRows: size.maxRow,
96
+ onSelection: props.onSelection,
97
+ selectedCol: size.col,
98
+ selectedRow: size.row
99
+ })));
100
+ };
101
+ export default TableSelectorPopup;
@@ -0,0 +1,102 @@
1
+ /** @jsx jsx */
2
+ import { useMemo } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { Stack } from '@atlaskit/primitives';
7
+ export const TABLE_SELECTOR_BUTTON_GAP = 2;
8
+ export const TABLE_SELECTOR_BUTTON_SIZE = 17;
9
+ const selectedButtonStyles = css({
10
+ backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
11
+ border: `1px solid ${"var(--ds-background-accent-blue-subtle, #579DFF)"}`
12
+ });
13
+ const buttonStyles = css({
14
+ height: `${TABLE_SELECTOR_BUTTON_SIZE}px`,
15
+ width: `${TABLE_SELECTOR_BUTTON_SIZE}px`,
16
+ border: `1px solid ${"var(--ds-border, #091e4224)"}`,
17
+ backgroundColor: "var(--ds-background-input, #ffffff)",
18
+ borderRadius: '3px',
19
+ cursor: 'pointer',
20
+ display: 'block',
21
+ '&:hover': {
22
+ backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
23
+ border: `1px solid ${"var(--ds-background-accent-blue-subtle, #579DFF)"}`
24
+ }
25
+ });
26
+ const selectionSizeTextStyles = css({
27
+ lineHeight: '14px',
28
+ display: 'flex',
29
+ justifyContent: 'center',
30
+ marginTop: "var(--ds-space-075, 5px)",
31
+ padding: "var(--ds-space-075, 10px)"
32
+ });
33
+ const TableSelectorButton = ({
34
+ row,
35
+ col,
36
+ isActive,
37
+ onClick,
38
+ label
39
+ }) => {
40
+ return jsx("button", {
41
+ css: [buttonStyles, isActive ? selectedButtonStyles : undefined],
42
+ onClick: () => onClick(row, col),
43
+ "aria-label": label
44
+ });
45
+ };
46
+ const createArray = (maxCols, maxRows) => {
47
+ const arr = [];
48
+ for (let i = 1; i < maxRows + 1; i++) {
49
+ for (let j = 1; j < maxCols + 1; j++) {
50
+ arr.push({
51
+ col: j,
52
+ row: i
53
+ });
54
+ }
55
+ }
56
+ return arr;
57
+ };
58
+ const gridWrapperStyles = ({
59
+ maxCols,
60
+ maxRows
61
+ }) => css({
62
+ display: 'grid',
63
+ gridTemplateColumns: `repeat(${maxCols}, 1fr)`,
64
+ gridTemplateRows: `repeat(${maxRows}, 1fr)`,
65
+ gap: `${`var(--ds-space-025, ${`${TABLE_SELECTOR_BUTTON_GAP}px`})`}`
66
+ });
67
+ const TableSelectorPopup = ({
68
+ maxCols,
69
+ maxRows,
70
+ onSelection,
71
+ selectedCol,
72
+ selectedRow,
73
+ intl
74
+ }) => {
75
+ const buttons = useMemo(() => {
76
+ return createArray(maxCols, maxRows);
77
+ }, [maxCols, maxRows]);
78
+ return jsx(Stack, null, jsx("div", {
79
+ css:
80
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
81
+ gridWrapperStyles({
82
+ maxCols: maxCols,
83
+ maxRows: maxRows
84
+ })
85
+ }, buttons.map(({
86
+ col,
87
+ row
88
+ }, index) => {
89
+ const isActive = selectedCol >= col && selectedRow >= row ? true : false;
90
+ return jsx(TableSelectorButton, {
91
+ key: index,
92
+ isActive: isActive,
93
+ col: col,
94
+ row: row,
95
+ onClick: onSelection,
96
+ label: `${intl.formatMessage(messages.tableSizeSelectorButton)} ${row} x ${col}`
97
+ });
98
+ })), jsx("span", {
99
+ css: selectionSizeTextStyles
100
+ }, `${selectedRow} x ${selectedCol}`));
101
+ };
102
+ export default injectIntl(TableSelectorPopup);
@@ -31,6 +31,7 @@ import * as colors from '@atlaskit/theme/colors';
31
31
  import { BlockInsertMenu } from './block-insert-menu';
32
32
  import { createItems } from './create-items';
33
33
  import { messages } from './messages';
34
+ import TableSelectorPopup from './table-selector-popup-with-listeners';
34
35
  /**
35
36
  * Checks if an element is detached (i.e. not in the current document)
36
37
  */
@@ -45,7 +46,11 @@ var TABLE_SELECTOR_STRING = 'table selector';
45
46
  var getHoverStyles = function getHoverStyles(selector) {
46
47
  return "&:hover ".concat(selector, " {\n background: ", "var(--ds-background-neutral-subtle-hovered, ".concat(colors.N20A, ")"), ";\n\n &:hover {\n background: ", "var(--ds-background-neutral-hovered, ".concat(colors.N30A, ")"), ";\n }\n }");
47
48
  };
48
- export var tableButtonWrapper = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n ", "\n ", "\n\n .table-toolbar-btn {\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n margin-right: ", ";\n padding: ", ";\n & > span {\n margin: ", ";\n }\n }\n .table-selector-toolbar-btn {\n padding: ", ";\n & > span {\n margin: ", ";\n width: 16px !important;\n display: flex;\n justify-content: center;\n }\n\n border-top-left-radius: ", " !important;\n border-bottom-left-radius: ", " !important;\n }\n"])), getHoverStyles('.table-selector-toolbar-btn'), getHoverStyles('.table-toolbar-btn'), "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-space-025, 1px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)");
49
+ export var tableButtonWrapper = function tableButtonWrapper(_ref) {
50
+ var isTableSelectorOpen = _ref.isTableSelectorOpen,
51
+ isButtonDisabled = _ref.isButtonDisabled;
52
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n ", "\n ", "\n\n .table-toolbar-btn {\n border-top-right-radius: ", ";\n border-bottom-right-radius: ", ";\n margin-right: ", ";\n padding: ", ";\n & > span {\n min-width: 16px;\n margin: ", ";\n }\n }\n .table-selector-toolbar-btn {\n padding: ", ";\n & > span {\n margin: ", ";\n width: 16px !important;\n display: flex;\n justify-content: center;\n }\n\n border-top-left-radius: ", " !important;\n border-bottom-left-radius: ", " !important;\n }\n"])), !isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-selector-toolbar-btn'), !isTableSelectorOpen && !isButtonDisabled && getHoverStyles('.table-toolbar-btn'), "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-space-025, 1px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-space-0, 0px)", "var(--ds-border-radius-200, 0px)", "var(--ds-border-radius-200, 0px)");
53
+ };
49
54
 
50
55
  // eslint-disable-next-line @repo/internal/react/no-class-components
51
56
  export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
@@ -58,6 +63,8 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
58
63
  args[_key] = arguments[_key];
59
64
  }
60
65
  _this = _super.call.apply(_super, [this].concat(args));
66
+ _defineProperty(_assertThisInitialized(_this), "tableButtonRef", /*#__PURE__*/React.createRef());
67
+ _defineProperty(_assertThisInitialized(_this), "tableSelectorButtonRef", /*#__PURE__*/React.createRef());
61
68
  _defineProperty(_assertThisInitialized(_this), "state", {
62
69
  isPlusMenuOpen: false,
63
70
  emojiPickerOpen: false,
@@ -100,8 +107,8 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
100
107
  isPlusMenuOpen: !isPlusMenuOpen
101
108
  });
102
109
  if ((event === null || event === void 0 ? void 0 : event.key) === 'Escape') {
103
- var _ref;
104
- (_ref = _this.plusButtonRef || _this.dropdownButtonRef) === null || _ref === void 0 || _ref.focus();
110
+ var _ref2;
111
+ (_ref2 = _this.plusButtonRef || _this.dropdownButtonRef) === null || _ref2 === void 0 || _ref2.focus();
105
112
  }
106
113
  });
107
114
  _defineProperty(_assertThisInitialized(_this), "toggleEmojiPicker", function () {
@@ -159,6 +166,29 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
159
166
  _this.dropdownButtonRef = ref;
160
167
  }
161
168
  });
169
+ _defineProperty(_assertThisInitialized(_this), "toggleTableSelector", function () {
170
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
171
+ _this.setState(function (prevState) {
172
+ return {
173
+ isTableSelectorOpen: !prevState.isTableSelectorOpen
174
+ };
175
+ });
176
+ });
177
+ _defineProperty(_assertThisInitialized(_this), "handleSelectedTableSize", function (rowsCount, colsCount) {
178
+ _this.insertTableWithSize(INPUT_METHOD.TOOLBAR, rowsCount, colsCount)();
179
+ _this.toggleTableSelector();
180
+ });
181
+ _defineProperty(_assertThisInitialized(_this), "handleTableSelectorPressEscape", function () {
182
+ var _this$tableSelectorBu;
183
+ _this.toggleTableSelector(INPUT_METHOD.KEYBOARD);
184
+ (_this$tableSelectorBu = _this.tableSelectorButtonRef.current) === null || _this$tableSelectorBu === void 0 || _this$tableSelectorBu.focus();
185
+ });
186
+ _defineProperty(_assertThisInitialized(_this), "handleTableSelectorClickOutside", function (e) {
187
+ // Ignore click events for detached elements.
188
+ if (e.target && !isDetachedElement(e.target)) {
189
+ _this.toggleTableSelector(INPUT_METHOD.TOOLBAR);
190
+ }
191
+ });
162
192
  _defineProperty(_assertThisInitialized(_this), "handleClick", function () {
163
193
  _this.togglePlusMenuVisibility();
164
194
  });
@@ -319,9 +349,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
319
349
  var pluginInjectionApi = _this.props.pluginInjectionApi;
320
350
  pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$q = pluginInjectionApi.quickInsert) === null || _pluginInjectionApi$q === void 0 ? void 0 : _pluginInjectionApi$q.commands.openElementBrowserModal);
321
351
  });
322
- _defineProperty(_assertThisInitialized(_this), "onItemActivated", function (_ref2) {
323
- var item = _ref2.item,
324
- inputMethod = _ref2.inputMethod;
352
+ _defineProperty(_assertThisInitialized(_this), "onItemActivated", function (_ref3) {
353
+ var item = _ref3.item,
354
+ inputMethod = _ref3.inputMethod;
325
355
  var _this$props11 = _this.props,
326
356
  editorView = _this$props11.editorView,
327
357
  editorActions = _this$props11.editorActions,
@@ -340,7 +370,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
340
370
  _this.insertTable(inputMethod);
341
371
  break;
342
372
  case 'table selector':
343
- _this.insertTableWithSize(inputMethod, 4, 4)(); // adding command here to pass typecheck but will implement the actual feature in future ticket
373
+ _this.toggleTableSelector(inputMethod);
344
374
  break;
345
375
  case 'image upload':
346
376
  if (handleImageUpload) {
@@ -411,8 +441,8 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
411
441
  inputMethod: INPUT_METHOD.TOOLBAR
412
442
  });
413
443
  });
414
- _defineProperty(_assertThisInitialized(_this), "insertInsertMenuItem", function (_ref3) {
415
- var item = _ref3.item;
444
+ _defineProperty(_assertThisInitialized(_this), "insertInsertMenuItem", function (_ref4) {
445
+ var item = _ref4.item;
416
446
  return _this.onItemActivated({
417
447
  item: item,
418
448
  inputMethod: INPUT_METHOD.INSERT_MENU
@@ -423,10 +453,11 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
423
453
  _createClass(ToolbarInsertBlock, [{
424
454
  key: "componentDidUpdate",
425
455
  value: function componentDidUpdate(prevProps) {
426
- // If number of visible buttons changed, close emoji picker
456
+ // If number of visible buttons changed, close emoji picker and table selector
427
457
  if (prevProps.buttons !== this.props.buttons) {
428
458
  this.setState({
429
- emojiPickerOpen: false
459
+ emojiPickerOpen: false,
460
+ isTableSelectorOpen: false
430
461
  });
431
462
  }
432
463
  if (this.state.isOpenedByKeyboard) {
@@ -451,8 +482,8 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
451
482
  popupsScrollableElement = _this$props12.popupsScrollableElement,
452
483
  emojiProvider = _this$props12.emojiProvider,
453
484
  replacePlusMenuWithElementBrowser = _this$props12.replacePlusMenuWithElementBrowser;
454
- var dropdownEmoji = this.state.dropdownItems.some(function (_ref4) {
455
- var name = _ref4.value.name;
485
+ var dropdownEmoji = this.state.dropdownItems.some(function (_ref5) {
486
+ var name = _ref5.value.name;
456
487
  return name === 'emoji';
457
488
  });
458
489
  var dropDownButtonRef = replacePlusMenuWithElementBrowser ? this.plusButtonRef : this.dropdownButtonRef;
@@ -477,6 +508,29 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
477
508
  handleEscapeKeydown: this.handleEmojiPressEscape
478
509
  }));
479
510
  }
511
+ }, {
512
+ key: "renderTableSelectorPopup",
513
+ value: function renderTableSelectorPopup() {
514
+ var _this$tableButtonRef$;
515
+ var isTableSelectorOpen = this.state.isTableSelectorOpen;
516
+ var _this$props13 = this.props,
517
+ popupsMountPoint = _this$props13.popupsMountPoint,
518
+ popupsBoundariesElement = _this$props13.popupsBoundariesElement,
519
+ popupsScrollableElement = _this$props13.popupsScrollableElement;
520
+ var ref = (_this$tableButtonRef$ = this.tableButtonRef.current) !== null && _this$tableButtonRef$ !== void 0 ? _this$tableButtonRef$ : undefined;
521
+ if (!isTableSelectorOpen) {
522
+ return null;
523
+ }
524
+ return jsx(TableSelectorPopup, {
525
+ target: ref,
526
+ onSelection: this.handleSelectedTableSize,
527
+ popupsMountPoint: popupsMountPoint,
528
+ popupsBoundariesElement: popupsBoundariesElement,
529
+ popupsScrollableElement: popupsScrollableElement,
530
+ handleClickOutside: this.handleTableSelectorClickOutside,
531
+ handleEscapeKeydown: this.handleTableSelectorPressEscape
532
+ });
533
+ }
480
534
  }, {
481
535
  key: "render",
482
536
  value: function render() {
@@ -487,6 +541,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
487
541
  _tableButton4,
488
542
  _tableButton5,
489
543
  _tableButton6,
544
+ _tableButton7,
490
545
  _tableSelectorButton,
491
546
  _tableSelectorButton2,
492
547
  _tableSelectorButton3,
@@ -498,10 +553,11 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
498
553
  var _this$state = this.state,
499
554
  buttons = _this$state.buttons,
500
555
  dropdownItems = _this$state.dropdownItems,
501
- emojiPickerOpen = _this$state.emojiPickerOpen;
502
- var _this$props13 = this.props,
503
- isDisabled = _this$props13.isDisabled,
504
- isReducedSpacing = _this$props13.isReducedSpacing;
556
+ emojiPickerOpen = _this$state.emojiPickerOpen,
557
+ isTableSelectorOpen = _this$state.isTableSelectorOpen;
558
+ var _this$props14 = this.props,
559
+ isDisabled = _this$props14.isDisabled,
560
+ isReducedSpacing = _this$props14.isReducedSpacing;
505
561
  if (buttons.length === 0 && dropdownItems.length === 0) {
506
562
  return null;
507
563
  }
@@ -548,20 +604,23 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
548
604
  "aria-keyshortcuts": btn['aria-keyshortcuts'],
549
605
  onItemClick: _this2.insertToolbarMenuItem
550
606
  });
551
- }), this.props.tableSelectorSupported &&
552
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
553
- jsx("div", {
554
- css: tableButtonWrapper
607
+ }), this.props.tableSelectorSupported && jsx("div", {
608
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
609
+ css: tableButtonWrapper({
610
+ isTableSelectorOpen: isTableSelectorOpen,
611
+ isButtonDisabled: (_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.isDisabled
612
+ })
555
613
  }, jsx(ToolbarButton, {
556
614
  className: "table-toolbar-btn",
557
615
  item: tableButton,
558
- testId: String((_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.content),
559
- key: (_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.value.name,
616
+ ref: this.tableButtonRef,
617
+ testId: String((_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.content),
618
+ key: (_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.value.name,
560
619
  spacing: isReducedSpacing ? 'none' : 'default',
561
- disabled: isDisabled || ((_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.isDisabled),
562
- iconBefore: (_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.elemBefore,
563
- selected: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.isActive,
564
- title: (_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.title,
620
+ disabled: isDisabled || ((_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.isDisabled),
621
+ iconBefore: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.elemBefore,
622
+ selected: ((_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.isActive) || isTableSelectorOpen,
623
+ title: (_tableButton7 = tableButton) === null || _tableButton7 === void 0 ? void 0 : _tableButton7.title,
565
624
  "aria-label": tableButton ? tableButton['aria-label'] : undefined,
566
625
  "aria-haspopup": tableButton ? tableButton['aria-haspopup'] : undefined,
567
626
  "aria-keyshortcuts": tableButton ? tableButton['aria-keyshortcuts'] : undefined,
@@ -571,10 +630,11 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
571
630
  item: tableSelectorButton,
572
631
  testId: String((_tableSelectorButton = tableSelectorButton) === null || _tableSelectorButton === void 0 ? void 0 : _tableSelectorButton.content),
573
632
  key: (_tableSelectorButton2 = tableSelectorButton) === null || _tableSelectorButton2 === void 0 ? void 0 : _tableSelectorButton2.value.name,
633
+ ref: this.tableSelectorButtonRef,
574
634
  spacing: isReducedSpacing ? 'none' : 'default',
575
635
  disabled: isDisabled || ((_tableSelectorButton3 = tableSelectorButton) === null || _tableSelectorButton3 === void 0 ? void 0 : _tableSelectorButton3.isDisabled),
576
636
  iconBefore: (_tableSelectorButton4 = tableSelectorButton) === null || _tableSelectorButton4 === void 0 ? void 0 : _tableSelectorButton4.elemBefore,
577
- selected: (_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive,
637
+ selected: ((_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive) || isTableSelectorOpen,
578
638
  title: (_tableSelectorButton6 = tableSelectorButton) === null || _tableSelectorButton6 === void 0 ? void 0 : _tableSelectorButton6.title,
579
639
  "aria-label": tableSelectorButton ? tableSelectorButton['aria-label'] : undefined,
580
640
  "aria-haspopup": tableSelectorButton ? tableSelectorButton['aria-haspopup'] : undefined,
@@ -582,7 +642,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
582
642
  onItemClick: this.insertToolbarMenuItem
583
643
  })), jsx("span", {
584
644
  css: wrapperStyle
585
- }, this.renderPopup(), jsx(BlockInsertMenu, {
645
+ }, this.renderPopup(), this.renderTableSelectorPopup(), jsx(BlockInsertMenu, {
586
646
  popupsMountPoint: this.props.popupsMountPoint,
587
647
  popupsBoundariesElement: this.props.popupsBoundariesElement,
588
648
  popupsScrollableElement: this.props.popupsScrollableElement,