@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-insert-block
2
2
 
3
+ ## 0.2.19
4
+
5
+ ### Patch Changes
6
+
7
+ - [#65874](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65874) [`282862992d2a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/282862992d2a) - [ux] added popup to table selector button using mouse movement
8
+
9
+ ## 0.2.18
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 0.2.17
4
16
 
5
17
  ### Patch Changes
@@ -30,6 +30,7 @@ var colors = _interopRequireWildcard(require("@atlaskit/theme/colors"));
30
30
  var _blockInsertMenu = require("./block-insert-menu");
31
31
  var _createItems3 = require("./create-items");
32
32
  var _messages = require("./messages");
33
+ var _tableSelectorPopupWithListeners = _interopRequireDefault(require("./table-selector-popup-with-listeners"));
33
34
  var _templateObject;
34
35
  /** @jsx jsx */
35
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -55,7 +56,11 @@ var TABLE_SELECTOR_STRING = 'table selector';
55
56
  var getHoverStyles = function getHoverStyles(selector) {
56
57
  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 }");
57
58
  };
58
- var tableButtonWrapper = exports.tableButtonWrapper = (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\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)");
59
+ var tableButtonWrapper = exports.tableButtonWrapper = function tableButtonWrapper(_ref) {
60
+ var isTableSelectorOpen = _ref.isTableSelectorOpen,
61
+ isButtonDisabled = _ref.isButtonDisabled;
62
+ return (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\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)");
63
+ };
59
64
 
60
65
  // eslint-disable-next-line @repo/internal/react/no-class-components
61
66
  var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
@@ -68,6 +73,8 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
68
73
  args[_key] = arguments[_key];
69
74
  }
70
75
  _this = _super.call.apply(_super, [this].concat(args));
76
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "tableButtonRef", /*#__PURE__*/_react.default.createRef());
77
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "tableSelectorButtonRef", /*#__PURE__*/_react.default.createRef());
71
78
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", {
72
79
  isPlusMenuOpen: false,
73
80
  emojiPickerOpen: false,
@@ -110,8 +117,8 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
110
117
  isPlusMenuOpen: !isPlusMenuOpen
111
118
  });
112
119
  if ((event === null || event === void 0 ? void 0 : event.key) === 'Escape') {
113
- var _ref;
114
- (_ref = _this.plusButtonRef || _this.dropdownButtonRef) === null || _ref === void 0 || _ref.focus();
120
+ var _ref2;
121
+ (_ref2 = _this.plusButtonRef || _this.dropdownButtonRef) === null || _ref2 === void 0 || _ref2.focus();
115
122
  }
116
123
  });
117
124
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleEmojiPicker", function () {
@@ -169,6 +176,29 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
169
176
  _this.dropdownButtonRef = ref;
170
177
  }
171
178
  });
179
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "toggleTableSelector", function () {
180
+ var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.TOOLBAR;
181
+ _this.setState(function (prevState) {
182
+ return {
183
+ isTableSelectorOpen: !prevState.isTableSelectorOpen
184
+ };
185
+ });
186
+ });
187
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleSelectedTableSize", function (rowsCount, colsCount) {
188
+ _this.insertTableWithSize(_analytics.INPUT_METHOD.TOOLBAR, rowsCount, colsCount)();
189
+ _this.toggleTableSelector();
190
+ });
191
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleTableSelectorPressEscape", function () {
192
+ var _this$tableSelectorBu;
193
+ _this.toggleTableSelector(_analytics.INPUT_METHOD.KEYBOARD);
194
+ (_this$tableSelectorBu = _this.tableSelectorButtonRef.current) === null || _this$tableSelectorBu === void 0 || _this$tableSelectorBu.focus();
195
+ });
196
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleTableSelectorClickOutside", function (e) {
197
+ // Ignore click events for detached elements.
198
+ if (e.target && !isDetachedElement(e.target)) {
199
+ _this.toggleTableSelector(_analytics.INPUT_METHOD.TOOLBAR);
200
+ }
201
+ });
172
202
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleClick", function () {
173
203
  _this.togglePlusMenuVisibility();
174
204
  });
@@ -329,9 +359,9 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
329
359
  var pluginInjectionApi = _this.props.pluginInjectionApi;
330
360
  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);
331
361
  });
332
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onItemActivated", function (_ref2) {
333
- var item = _ref2.item,
334
- inputMethod = _ref2.inputMethod;
362
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onItemActivated", function (_ref3) {
363
+ var item = _ref3.item,
364
+ inputMethod = _ref3.inputMethod;
335
365
  var _this$props11 = _this.props,
336
366
  editorView = _this$props11.editorView,
337
367
  editorActions = _this$props11.editorActions,
@@ -350,7 +380,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
350
380
  _this.insertTable(inputMethod);
351
381
  break;
352
382
  case 'table selector':
353
- _this.insertTableWithSize(inputMethod, 4, 4)(); // adding command here to pass typecheck but will implement the actual feature in future ticket
383
+ _this.toggleTableSelector(inputMethod);
354
384
  break;
355
385
  case 'image upload':
356
386
  if (handleImageUpload) {
@@ -421,8 +451,8 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
421
451
  inputMethod: _analytics.INPUT_METHOD.TOOLBAR
422
452
  });
423
453
  });
424
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertInsertMenuItem", function (_ref3) {
425
- var item = _ref3.item;
454
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertInsertMenuItem", function (_ref4) {
455
+ var item = _ref4.item;
426
456
  return _this.onItemActivated({
427
457
  item: item,
428
458
  inputMethod: _analytics.INPUT_METHOD.INSERT_MENU
@@ -433,10 +463,11 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
433
463
  (0, _createClass2.default)(ToolbarInsertBlock, [{
434
464
  key: "componentDidUpdate",
435
465
  value: function componentDidUpdate(prevProps) {
436
- // If number of visible buttons changed, close emoji picker
466
+ // If number of visible buttons changed, close emoji picker and table selector
437
467
  if (prevProps.buttons !== this.props.buttons) {
438
468
  this.setState({
439
- emojiPickerOpen: false
469
+ emojiPickerOpen: false,
470
+ isTableSelectorOpen: false
440
471
  });
441
472
  }
442
473
  if (this.state.isOpenedByKeyboard) {
@@ -461,8 +492,8 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
461
492
  popupsScrollableElement = _this$props12.popupsScrollableElement,
462
493
  emojiProvider = _this$props12.emojiProvider,
463
494
  replacePlusMenuWithElementBrowser = _this$props12.replacePlusMenuWithElementBrowser;
464
- var dropdownEmoji = this.state.dropdownItems.some(function (_ref4) {
465
- var name = _ref4.value.name;
495
+ var dropdownEmoji = this.state.dropdownItems.some(function (_ref5) {
496
+ var name = _ref5.value.name;
466
497
  return name === 'emoji';
467
498
  });
468
499
  var dropDownButtonRef = replacePlusMenuWithElementBrowser ? this.plusButtonRef : this.dropdownButtonRef;
@@ -487,6 +518,29 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
487
518
  handleEscapeKeydown: this.handleEmojiPressEscape
488
519
  }));
489
520
  }
521
+ }, {
522
+ key: "renderTableSelectorPopup",
523
+ value: function renderTableSelectorPopup() {
524
+ var _this$tableButtonRef$;
525
+ var isTableSelectorOpen = this.state.isTableSelectorOpen;
526
+ var _this$props13 = this.props,
527
+ popupsMountPoint = _this$props13.popupsMountPoint,
528
+ popupsBoundariesElement = _this$props13.popupsBoundariesElement,
529
+ popupsScrollableElement = _this$props13.popupsScrollableElement;
530
+ var ref = (_this$tableButtonRef$ = this.tableButtonRef.current) !== null && _this$tableButtonRef$ !== void 0 ? _this$tableButtonRef$ : undefined;
531
+ if (!isTableSelectorOpen) {
532
+ return null;
533
+ }
534
+ return (0, _react2.jsx)(_tableSelectorPopupWithListeners.default, {
535
+ target: ref,
536
+ onSelection: this.handleSelectedTableSize,
537
+ popupsMountPoint: popupsMountPoint,
538
+ popupsBoundariesElement: popupsBoundariesElement,
539
+ popupsScrollableElement: popupsScrollableElement,
540
+ handleClickOutside: this.handleTableSelectorClickOutside,
541
+ handleEscapeKeydown: this.handleTableSelectorPressEscape
542
+ });
543
+ }
490
544
  }, {
491
545
  key: "render",
492
546
  value: function render() {
@@ -497,6 +551,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
497
551
  _tableButton4,
498
552
  _tableButton5,
499
553
  _tableButton6,
554
+ _tableButton7,
500
555
  _tableSelectorButton,
501
556
  _tableSelectorButton2,
502
557
  _tableSelectorButton3,
@@ -508,10 +563,11 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
508
563
  var _this$state = this.state,
509
564
  buttons = _this$state.buttons,
510
565
  dropdownItems = _this$state.dropdownItems,
511
- emojiPickerOpen = _this$state.emojiPickerOpen;
512
- var _this$props13 = this.props,
513
- isDisabled = _this$props13.isDisabled,
514
- isReducedSpacing = _this$props13.isReducedSpacing;
566
+ emojiPickerOpen = _this$state.emojiPickerOpen,
567
+ isTableSelectorOpen = _this$state.isTableSelectorOpen;
568
+ var _this$props14 = this.props,
569
+ isDisabled = _this$props14.isDisabled,
570
+ isReducedSpacing = _this$props14.isReducedSpacing;
515
571
  if (buttons.length === 0 && dropdownItems.length === 0) {
516
572
  return null;
517
573
  }
@@ -558,20 +614,23 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
558
614
  "aria-keyshortcuts": btn['aria-keyshortcuts'],
559
615
  onItemClick: _this2.insertToolbarMenuItem
560
616
  });
561
- }), this.props.tableSelectorSupported &&
562
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
563
- (0, _react2.jsx)("div", {
564
- css: tableButtonWrapper
617
+ }), this.props.tableSelectorSupported && (0, _react2.jsx)("div", {
618
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
619
+ css: tableButtonWrapper({
620
+ isTableSelectorOpen: isTableSelectorOpen,
621
+ isButtonDisabled: (_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.isDisabled
622
+ })
565
623
  }, (0, _react2.jsx)(_uiMenu.ToolbarButton, {
566
624
  className: "table-toolbar-btn",
567
625
  item: tableButton,
568
- testId: String((_tableButton = tableButton) === null || _tableButton === void 0 ? void 0 : _tableButton.content),
569
- key: (_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.value.name,
626
+ ref: this.tableButtonRef,
627
+ testId: String((_tableButton2 = tableButton) === null || _tableButton2 === void 0 ? void 0 : _tableButton2.content),
628
+ key: (_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.value.name,
570
629
  spacing: isReducedSpacing ? 'none' : 'default',
571
- disabled: isDisabled || ((_tableButton3 = tableButton) === null || _tableButton3 === void 0 ? void 0 : _tableButton3.isDisabled),
572
- iconBefore: (_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.elemBefore,
573
- selected: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.isActive,
574
- title: (_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.title,
630
+ disabled: isDisabled || ((_tableButton4 = tableButton) === null || _tableButton4 === void 0 ? void 0 : _tableButton4.isDisabled),
631
+ iconBefore: (_tableButton5 = tableButton) === null || _tableButton5 === void 0 ? void 0 : _tableButton5.elemBefore,
632
+ selected: ((_tableButton6 = tableButton) === null || _tableButton6 === void 0 ? void 0 : _tableButton6.isActive) || isTableSelectorOpen,
633
+ title: (_tableButton7 = tableButton) === null || _tableButton7 === void 0 ? void 0 : _tableButton7.title,
575
634
  "aria-label": tableButton ? tableButton['aria-label'] : undefined,
576
635
  "aria-haspopup": tableButton ? tableButton['aria-haspopup'] : undefined,
577
636
  "aria-keyshortcuts": tableButton ? tableButton['aria-keyshortcuts'] : undefined,
@@ -581,10 +640,11 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
581
640
  item: tableSelectorButton,
582
641
  testId: String((_tableSelectorButton = tableSelectorButton) === null || _tableSelectorButton === void 0 ? void 0 : _tableSelectorButton.content),
583
642
  key: (_tableSelectorButton2 = tableSelectorButton) === null || _tableSelectorButton2 === void 0 ? void 0 : _tableSelectorButton2.value.name,
643
+ ref: this.tableSelectorButtonRef,
584
644
  spacing: isReducedSpacing ? 'none' : 'default',
585
645
  disabled: isDisabled || ((_tableSelectorButton3 = tableSelectorButton) === null || _tableSelectorButton3 === void 0 ? void 0 : _tableSelectorButton3.isDisabled),
586
646
  iconBefore: (_tableSelectorButton4 = tableSelectorButton) === null || _tableSelectorButton4 === void 0 ? void 0 : _tableSelectorButton4.elemBefore,
587
- selected: (_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive,
647
+ selected: ((_tableSelectorButton5 = tableSelectorButton) === null || _tableSelectorButton5 === void 0 ? void 0 : _tableSelectorButton5.isActive) || isTableSelectorOpen,
588
648
  title: (_tableSelectorButton6 = tableSelectorButton) === null || _tableSelectorButton6 === void 0 ? void 0 : _tableSelectorButton6.title,
589
649
  "aria-label": tableSelectorButton ? tableSelectorButton['aria-label'] : undefined,
590
650
  "aria-haspopup": tableSelectorButton ? tableSelectorButton['aria-haspopup'] : undefined,
@@ -592,7 +652,7 @@ var ToolbarInsertBlock = exports.ToolbarInsertBlock = /*#__PURE__*/function (_Re
592
652
  onItemClick: this.insertToolbarMenuItem
593
653
  })), (0, _react2.jsx)("span", {
594
654
  css: _styles.wrapperStyle
595
- }, this.renderPopup(), (0, _react2.jsx)(_blockInsertMenu.BlockInsertMenu, {
655
+ }, this.renderPopup(), this.renderTableSelectorPopup(), (0, _react2.jsx)(_blockInsertMenu.BlockInsertMenu, {
596
656
  popupsMountPoint: this.props.popupsMountPoint,
597
657
  popupsBoundariesElement: this.props.popupsBoundariesElement,
598
658
  popupsScrollableElement: this.props.popupsScrollableElement,
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = exports.TableSelectorPopup = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = require("react");
11
+ var _react2 = require("@emotion/react");
12
+ var _bindEventListener = require("bind-event-listener");
13
+ var _ui = require("@atlaskit/editor-common/ui");
14
+ var _uiReact = require("@atlaskit/editor-common/ui-react");
15
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
+ var _colors = require("@atlaskit/theme/colors");
17
+ var _tableSelectorPopup = _interopRequireWildcard(require("./table-selector-popup"));
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+ /** @jsx jsx */
21
+
22
+ var TABLE_SELECTOR_PADDING_TOP = 8;
23
+ var TABLE_SELECTOR_PADDING_SIDE = 10;
24
+ var DEFAULT_TABLE_SELECTOR_ROWS = 5;
25
+ var DEFAULT_TABLE_SELECTOR_COLS = 10;
26
+ var DEFAULT_TABLE_SELECTOR_SELECTION_SIZE = 1;
27
+ var TableSelectorWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_tableSelectorPopup.default);
28
+ var tableSelectorPopupWrapperStyles = (0, _react2.css)({
29
+ borderRadius: "var(--ds-border-radius, 3px)",
30
+ backgroundColor: "var(--ds-surface-overlay, ".concat(_colors.N0, ")"),
31
+ boxShadow: "var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(_colors.N30A, ", 0 2px 1px ").concat(_colors.N30A, ", 0 0 20px -6px ").concat(_colors.N60A), ")"),
32
+ padding: "".concat("var(--ds-space-100, ".concat("".concat(TABLE_SELECTOR_PADDING_TOP, "px"), ")"), " ", TABLE_SELECTOR_PADDING_SIDE, "px")
33
+ });
34
+ var TableSelectorPopup = exports.TableSelectorPopup = function TableSelectorPopup(props) {
35
+ var _useState = (0, _react.useState)({
36
+ col: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
37
+ row: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
38
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
39
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
40
+ }),
41
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
42
+ size = _useState2[0],
43
+ setSize = _useState2[1];
44
+ var tablePopupRef = (0, _react.useRef)(null);
45
+
46
+ // Mouse move is used to allow selection changes outside of the popup and is more reactive to changes.
47
+ var handleMouseMove = (0, _react.useCallback)(function (e) {
48
+ if (!tablePopupRef.current) {
49
+ return;
50
+ }
51
+ var tablePopup = tablePopupRef.current;
52
+ var _tablePopup$getBoundi = tablePopup.getBoundingClientRect(),
53
+ left = _tablePopup$getBoundi.left,
54
+ top = _tablePopup$getBoundi.top;
55
+
56
+ // Mouse position on popup
57
+ var selectedWidth = e.clientX - left;
58
+ var selectedHeight = e.clientY - top;
59
+
60
+ // Calculate number grid cells selected
61
+ var selectedGridCols = Math.ceil((selectedWidth - TABLE_SELECTOR_PADDING_SIDE + _tableSelectorPopup.TABLE_SELECTOR_BUTTON_GAP) / (_tableSelectorPopup.TABLE_SELECTOR_BUTTON_GAP + _tableSelectorPopup.TABLE_SELECTOR_BUTTON_SIZE));
62
+ var selectedGridRows = Math.ceil((selectedHeight - TABLE_SELECTOR_PADDING_TOP + _tableSelectorPopup.TABLE_SELECTOR_BUTTON_GAP) / (_tableSelectorPopup.TABLE_SELECTOR_BUTTON_GAP + _tableSelectorPopup.TABLE_SELECTOR_BUTTON_SIZE));
63
+
64
+ // Keep the selected rows and columns within the defined bounds
65
+ if (selectedGridCols < 1) {
66
+ selectedGridCols = 1;
67
+ }
68
+ if (selectedGridCols > size.maxCol) {
69
+ selectedGridCols = size.maxCol;
70
+ }
71
+ if (selectedGridRows < 1) {
72
+ selectedGridRows = 1;
73
+ }
74
+ if (selectedGridRows > size.maxRow) {
75
+ selectedGridRows = size.maxRow;
76
+ }
77
+ if (selectedGridCols !== size.col || selectedGridRows !== size.row) {
78
+ setSize({
79
+ col: selectedGridCols,
80
+ row: selectedGridRows,
81
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
82
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
83
+ });
84
+ }
85
+ }, [size, setSize]);
86
+ (0, _react.useEffect)(function () {
87
+ var unbind = (0, _bindEventListener.bind)(window, {
88
+ type: 'mousemove',
89
+ listener: handleMouseMove
90
+ });
91
+ return unbind;
92
+ }, [handleMouseMove]);
93
+ return (0, _react2.jsx)(_ui.Popup, {
94
+ target: props.target,
95
+ offset: [0, 3],
96
+ mountTo: props.popupsMountPoint,
97
+ boundariesElement: props.popupsBoundariesElement,
98
+ scrollableElement: props.popupsScrollableElement,
99
+ focusTrap: true,
100
+ zIndex: _editorSharedStyles.akEditorMenuZIndex
101
+ }, (0, _react2.jsx)("div", {
102
+ css: tableSelectorPopupWrapperStyles,
103
+ ref: tablePopupRef
104
+ }, (0, _react2.jsx)(TableSelectorWithListeners, {
105
+ handleClickOutside: props.handleClickOutside,
106
+ handleEscapeKeydown: props.handleEscapeKeydown,
107
+ maxCols: size.maxCol,
108
+ maxRows: size.maxRow,
109
+ onSelection: props.onSelection,
110
+ selectedCol: size.col,
111
+ selectedRow: size.row
112
+ })));
113
+ };
114
+ var _default = exports.default = TableSelectorPopup;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.TABLE_SELECTOR_BUTTON_SIZE = exports.TABLE_SELECTOR_BUTTON_GAP = void 0;
7
+ var _react = require("react");
8
+ var _react2 = require("@emotion/react");
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _messages = require("@atlaskit/editor-common/messages");
11
+ var _primitives = require("@atlaskit/primitives");
12
+ /** @jsx jsx */
13
+
14
+ var TABLE_SELECTOR_BUTTON_GAP = exports.TABLE_SELECTOR_BUTTON_GAP = 2;
15
+ var TABLE_SELECTOR_BUTTON_SIZE = exports.TABLE_SELECTOR_BUTTON_SIZE = 17;
16
+ var selectedButtonStyles = (0, _react2.css)({
17
+ backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
18
+ border: "1px solid ".concat("var(--ds-background-accent-blue-subtle, #579DFF)")
19
+ });
20
+ var buttonStyles = (0, _react2.css)({
21
+ height: "".concat(TABLE_SELECTOR_BUTTON_SIZE, "px"),
22
+ width: "".concat(TABLE_SELECTOR_BUTTON_SIZE, "px"),
23
+ border: "1px solid ".concat("var(--ds-border, #091e4224)"),
24
+ backgroundColor: "var(--ds-background-input, #ffffff)",
25
+ borderRadius: '3px',
26
+ cursor: 'pointer',
27
+ display: 'block',
28
+ '&:hover': {
29
+ backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
30
+ border: "1px solid ".concat("var(--ds-background-accent-blue-subtle, #579DFF)")
31
+ }
32
+ });
33
+ var selectionSizeTextStyles = (0, _react2.css)({
34
+ lineHeight: '14px',
35
+ display: 'flex',
36
+ justifyContent: 'center',
37
+ marginTop: "var(--ds-space-075, 5px)",
38
+ padding: "var(--ds-space-075, 10px)"
39
+ });
40
+ var TableSelectorButton = function TableSelectorButton(_ref) {
41
+ var row = _ref.row,
42
+ col = _ref.col,
43
+ isActive = _ref.isActive,
44
+ _onClick = _ref.onClick,
45
+ label = _ref.label;
46
+ return (0, _react2.jsx)("button", {
47
+ css: [buttonStyles, isActive ? selectedButtonStyles : undefined],
48
+ onClick: function onClick() {
49
+ return _onClick(row, col);
50
+ },
51
+ "aria-label": label
52
+ });
53
+ };
54
+ var createArray = function createArray(maxCols, maxRows) {
55
+ var arr = [];
56
+ for (var i = 1; i < maxRows + 1; i++) {
57
+ for (var j = 1; j < maxCols + 1; j++) {
58
+ arr.push({
59
+ col: j,
60
+ row: i
61
+ });
62
+ }
63
+ }
64
+ return arr;
65
+ };
66
+ var gridWrapperStyles = function gridWrapperStyles(_ref2) {
67
+ var maxCols = _ref2.maxCols,
68
+ maxRows = _ref2.maxRows;
69
+ return (0, _react2.css)({
70
+ display: 'grid',
71
+ gridTemplateColumns: "repeat(".concat(maxCols, ", 1fr)"),
72
+ gridTemplateRows: "repeat(".concat(maxRows, ", 1fr)"),
73
+ gap: "".concat("var(--ds-space-025, ".concat("".concat(TABLE_SELECTOR_BUTTON_GAP, "px"), ")"))
74
+ });
75
+ };
76
+ var TableSelectorPopup = function TableSelectorPopup(_ref3) {
77
+ var maxCols = _ref3.maxCols,
78
+ maxRows = _ref3.maxRows,
79
+ onSelection = _ref3.onSelection,
80
+ selectedCol = _ref3.selectedCol,
81
+ selectedRow = _ref3.selectedRow,
82
+ intl = _ref3.intl;
83
+ var buttons = (0, _react.useMemo)(function () {
84
+ return createArray(maxCols, maxRows);
85
+ }, [maxCols, maxRows]);
86
+ return (0, _react2.jsx)(_primitives.Stack, null, (0, _react2.jsx)("div", {
87
+ css:
88
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
89
+ gridWrapperStyles({
90
+ maxCols: maxCols,
91
+ maxRows: maxRows
92
+ })
93
+ }, buttons.map(function (_ref4, index) {
94
+ var col = _ref4.col,
95
+ row = _ref4.row;
96
+ var isActive = selectedCol >= col && selectedRow >= row ? true : false;
97
+ return (0, _react2.jsx)(TableSelectorButton, {
98
+ key: index,
99
+ isActive: isActive,
100
+ col: col,
101
+ row: row,
102
+ onClick: onSelection,
103
+ label: "".concat(intl.formatMessage(_messages.toolbarInsertBlockMessages.tableSizeSelectorButton), " ").concat(row, " x ").concat(col)
104
+ });
105
+ })), (0, _react2.jsx)("span", {
106
+ css: selectionSizeTextStyles
107
+ }, "".concat(selectedRow, " x ").concat(selectedCol)));
108
+ };
109
+ var _default = exports.default = (0, _reactIntlNext.injectIntl)(TableSelectorPopup);