@atlaskit/editor-plugin-insert-block 0.2.18 → 0.2.20

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.
@@ -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
  });
@@ -172,9 +202,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
172
202
  }
173
203
  });
174
204
  _defineProperty(_assertThisInitialized(_this), "toggleLinkPanel", function (inputMethod) {
175
- var _pluginInjectionApi$c, _pluginInjectionApi$h;
205
+ var _pluginInjectionApi$c, _pluginInjectionApi$c2, _pluginInjectionApi$h;
176
206
  var pluginInjectionApi = _this.props.pluginInjectionApi;
177
- return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$h = pluginInjectionApi.hyperlink) === null || _pluginInjectionApi$h === void 0 ? void 0 : _pluginInjectionApi$h.commands.showLinkToolbar(inputMethod))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
207
+ return (_pluginInjectionApi$c = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.core) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$h = pluginInjectionApi.hyperlink) === null || _pluginInjectionApi$h === void 0 ? void 0 : _pluginInjectionApi$h.commands.showLinkToolbar(inputMethod))) !== null && _pluginInjectionApi$c !== void 0 ? _pluginInjectionApi$c : false;
178
208
  });
179
209
  _defineProperty(_assertThisInitialized(_this), "insertMention", function (inputMethod) {
180
210
  var _pluginInjectionApi$m, _pluginInjectionApi$m2;
@@ -209,15 +239,15 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
209
239
  });
210
240
  _defineProperty(_assertThisInitialized(_this), "insertTableWithSize", function (inputMethod, rowsCount, colsCount) {
211
241
  return function () {
212
- var _pluginInjectionApi$t5;
242
+ var _pluginInjectionApi$c3, _pluginInjectionApi$t5;
213
243
  var pluginInjectionApi = _this.props.pluginInjectionApi;
214
- return pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$t5 = pluginInjectionApi.table) === null || _pluginInjectionApi$t5 === void 0 ? void 0 : _pluginInjectionApi$t5.commands.insertTableWithSize(rowsCount, colsCount, INPUT_METHOD.PICKER));
244
+ return pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.core) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$t5 = pluginInjectionApi.table) === null || _pluginInjectionApi$t5 === void 0 ? void 0 : _pluginInjectionApi$t5.commands.insertTableWithSize(rowsCount, colsCount, INPUT_METHOD.PICKER));
215
245
  };
216
246
  });
217
247
  _defineProperty(_assertThisInitialized(_this), "createDate", function (inputMethod) {
218
- var _pluginInjectionApi$d;
248
+ var _pluginInjectionApi$c4, _pluginInjectionApi$d;
219
249
  var pluginInjectionApi = _this.props.pluginInjectionApi;
220
- pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d = pluginInjectionApi.date) === null || _pluginInjectionApi$d === void 0 || (_pluginInjectionApi$d = _pluginInjectionApi$d.commands) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.insertDate({
250
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.core) === null || _pluginInjectionApi$c4 === void 0 || _pluginInjectionApi$c4.actions.execute(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d = pluginInjectionApi.date) === null || _pluginInjectionApi$d === void 0 || (_pluginInjectionApi$d = _pluginInjectionApi$d.commands) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.insertDate({
221
251
  inputMethod: inputMethod
222
252
  }));
223
253
  return true;
@@ -307,21 +337,21 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
307
337
  };
308
338
  });
309
339
  _defineProperty(_assertThisInitialized(_this), "handleSelectedEmoji", function (emojiId) {
310
- var _pluginInjectionApi$e3;
340
+ var _pluginInjectionApi$c5, _pluginInjectionApi$e3;
311
341
  var pluginInjectionApi = _this.props.pluginInjectionApi;
312
342
  _this.props.editorView.focus();
313
- pluginInjectionApi === null || pluginInjectionApi === void 0 || pluginInjectionApi.core.actions.execute((_pluginInjectionApi$e3 = pluginInjectionApi.emoji) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : _pluginInjectionApi$e3.commands.insertEmoji(emojiId, INPUT_METHOD.PICKER));
343
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c5 = pluginInjectionApi.core) === null || _pluginInjectionApi$c5 === void 0 || _pluginInjectionApi$c5.actions.execute((_pluginInjectionApi$e3 = pluginInjectionApi.emoji) === null || _pluginInjectionApi$e3 === void 0 ? void 0 : _pluginInjectionApi$e3.commands.insertEmoji(emojiId, INPUT_METHOD.PICKER));
314
344
  _this.toggleEmojiPicker();
315
345
  return true;
316
346
  });
317
347
  _defineProperty(_assertThisInitialized(_this), "openElementBrowser", function () {
318
- var _pluginInjectionApi$q;
348
+ var _pluginInjectionApi$c6, _pluginInjectionApi$q;
319
349
  var pluginInjectionApi = _this.props.pluginInjectionApi;
320
- 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);
350
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c6 = pluginInjectionApi.core) === null || _pluginInjectionApi$c6 === void 0 || _pluginInjectionApi$c6.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,
@@ -0,0 +1,104 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /** @jsx jsx */
3
+
4
+ import { useCallback, useEffect, useRef, useState } from 'react';
5
+ import { css, jsx } from '@emotion/react';
6
+ import { bind } from 'bind-event-listener';
7
+ import { Popup } from '@atlaskit/editor-common/ui';
8
+ import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
9
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
10
+ import { N0, N30A, N60A } from '@atlaskit/theme/colors';
11
+ import tableSelectorPopup, { TABLE_SELECTOR_BUTTON_GAP, TABLE_SELECTOR_BUTTON_SIZE } from './table-selector-popup';
12
+ var TABLE_SELECTOR_PADDING_TOP = 8;
13
+ var TABLE_SELECTOR_PADDING_SIDE = 10;
14
+ var DEFAULT_TABLE_SELECTOR_ROWS = 5;
15
+ var DEFAULT_TABLE_SELECTOR_COLS = 10;
16
+ var DEFAULT_TABLE_SELECTOR_SELECTION_SIZE = 1;
17
+ var TableSelectorWithListeners = withOuterListeners(tableSelectorPopup);
18
+ var tableSelectorPopupWrapperStyles = css({
19
+ borderRadius: "var(--ds-border-radius, 3px)",
20
+ backgroundColor: "var(--ds-surface-overlay, ".concat(N0, ")"),
21
+ boxShadow: "var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(N30A, ", 0 2px 1px ").concat(N30A, ", 0 0 20px -6px ").concat(N60A), ")"),
22
+ padding: "".concat("var(--ds-space-100, ".concat("".concat(TABLE_SELECTOR_PADDING_TOP, "px"), ")"), " ", TABLE_SELECTOR_PADDING_SIDE, "px")
23
+ });
24
+ export var TableSelectorPopup = function TableSelectorPopup(props) {
25
+ var _useState = useState({
26
+ col: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
27
+ row: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
28
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
29
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
30
+ }),
31
+ _useState2 = _slicedToArray(_useState, 2),
32
+ size = _useState2[0],
33
+ setSize = _useState2[1];
34
+ var tablePopupRef = useRef(null);
35
+
36
+ // Mouse move is used to allow selection changes outside of the popup and is more reactive to changes.
37
+ var handleMouseMove = useCallback(function (e) {
38
+ if (!tablePopupRef.current) {
39
+ return;
40
+ }
41
+ var tablePopup = tablePopupRef.current;
42
+ var _tablePopup$getBoundi = tablePopup.getBoundingClientRect(),
43
+ left = _tablePopup$getBoundi.left,
44
+ top = _tablePopup$getBoundi.top;
45
+
46
+ // Mouse position on popup
47
+ var selectedWidth = e.clientX - left;
48
+ var selectedHeight = e.clientY - top;
49
+
50
+ // Calculate number grid cells selected
51
+ var selectedGridCols = Math.ceil((selectedWidth - TABLE_SELECTOR_PADDING_SIDE + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
52
+ var selectedGridRows = Math.ceil((selectedHeight - TABLE_SELECTOR_PADDING_TOP + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
53
+
54
+ // Keep the selected rows and columns within the defined bounds
55
+ if (selectedGridCols < 1) {
56
+ selectedGridCols = 1;
57
+ }
58
+ if (selectedGridCols > size.maxCol) {
59
+ selectedGridCols = size.maxCol;
60
+ }
61
+ if (selectedGridRows < 1) {
62
+ selectedGridRows = 1;
63
+ }
64
+ if (selectedGridRows > size.maxRow) {
65
+ selectedGridRows = size.maxRow;
66
+ }
67
+ if (selectedGridCols !== size.col || selectedGridRows !== size.row) {
68
+ setSize({
69
+ col: selectedGridCols,
70
+ row: selectedGridRows,
71
+ maxCol: DEFAULT_TABLE_SELECTOR_COLS,
72
+ maxRow: DEFAULT_TABLE_SELECTOR_ROWS
73
+ });
74
+ }
75
+ }, [size, setSize]);
76
+ useEffect(function () {
77
+ var unbind = bind(window, {
78
+ type: 'mousemove',
79
+ listener: handleMouseMove
80
+ });
81
+ return unbind;
82
+ }, [handleMouseMove]);
83
+ return jsx(Popup, {
84
+ target: props.target,
85
+ offset: [0, 3],
86
+ mountTo: props.popupsMountPoint,
87
+ boundariesElement: props.popupsBoundariesElement,
88
+ scrollableElement: props.popupsScrollableElement,
89
+ focusTrap: true,
90
+ zIndex: akEditorMenuZIndex
91
+ }, jsx("div", {
92
+ css: tableSelectorPopupWrapperStyles,
93
+ ref: tablePopupRef
94
+ }, jsx(TableSelectorWithListeners, {
95
+ handleClickOutside: props.handleClickOutside,
96
+ handleEscapeKeydown: props.handleEscapeKeydown,
97
+ maxCols: size.maxCol,
98
+ maxRows: size.maxRow,
99
+ onSelection: props.onSelection,
100
+ selectedCol: size.col,
101
+ selectedRow: size.row
102
+ })));
103
+ };
104
+ 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 var TABLE_SELECTOR_BUTTON_GAP = 2;
8
+ export var TABLE_SELECTOR_BUTTON_SIZE = 17;
9
+ var selectedButtonStyles = css({
10
+ backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
11
+ border: "1px solid ".concat("var(--ds-background-accent-blue-subtle, #579DFF)")
12
+ });
13
+ var buttonStyles = css({
14
+ height: "".concat(TABLE_SELECTOR_BUTTON_SIZE, "px"),
15
+ width: "".concat(TABLE_SELECTOR_BUTTON_SIZE, "px"),
16
+ border: "1px solid ".concat("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 ".concat("var(--ds-background-accent-blue-subtle, #579DFF)")
24
+ }
25
+ });
26
+ var 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
+ var TableSelectorButton = function TableSelectorButton(_ref) {
34
+ var row = _ref.row,
35
+ col = _ref.col,
36
+ isActive = _ref.isActive,
37
+ _onClick = _ref.onClick,
38
+ label = _ref.label;
39
+ return jsx("button", {
40
+ css: [buttonStyles, isActive ? selectedButtonStyles : undefined],
41
+ onClick: function onClick() {
42
+ return _onClick(row, col);
43
+ },
44
+ "aria-label": label
45
+ });
46
+ };
47
+ var createArray = function createArray(maxCols, maxRows) {
48
+ var arr = [];
49
+ for (var i = 1; i < maxRows + 1; i++) {
50
+ for (var j = 1; j < maxCols + 1; j++) {
51
+ arr.push({
52
+ col: j,
53
+ row: i
54
+ });
55
+ }
56
+ }
57
+ return arr;
58
+ };
59
+ var gridWrapperStyles = function gridWrapperStyles(_ref2) {
60
+ var maxCols = _ref2.maxCols,
61
+ maxRows = _ref2.maxRows;
62
+ return css({
63
+ display: 'grid',
64
+ gridTemplateColumns: "repeat(".concat(maxCols, ", 1fr)"),
65
+ gridTemplateRows: "repeat(".concat(maxRows, ", 1fr)"),
66
+ gap: "".concat("var(--ds-space-025, ".concat("".concat(TABLE_SELECTOR_BUTTON_GAP, "px"), ")"))
67
+ });
68
+ };
69
+ var TableSelectorPopup = function TableSelectorPopup(_ref3) {
70
+ var maxCols = _ref3.maxCols,
71
+ maxRows = _ref3.maxRows,
72
+ onSelection = _ref3.onSelection,
73
+ selectedCol = _ref3.selectedCol,
74
+ selectedRow = _ref3.selectedRow,
75
+ intl = _ref3.intl;
76
+ var buttons = useMemo(function () {
77
+ return createArray(maxCols, maxRows);
78
+ }, [maxCols, maxRows]);
79
+ return jsx(Stack, null, jsx("div", {
80
+ css:
81
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
82
+ gridWrapperStyles({
83
+ maxCols: maxCols,
84
+ maxRows: maxRows
85
+ })
86
+ }, buttons.map(function (_ref4, index) {
87
+ var col = _ref4.col,
88
+ row = _ref4.row;
89
+ var 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: "".concat(intl.formatMessage(messages.tableSizeSelectorButton), " ").concat(row, " x ").concat(col)
97
+ });
98
+ })), jsx("span", {
99
+ css: selectionSizeTextStyles
100
+ }, "".concat(selectedRow, " x ").concat(selectedCol)));
101
+ };
102
+ export default injectIntl(TableSelectorPopup);
@@ -3,11 +3,16 @@ import React from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import type { WrappedComponentProps } from 'react-intl-next';
5
5
  import type { Props, State } from './types';
6
- export declare const tableButtonWrapper: import("@emotion/react").SerializedStyles;
6
+ export declare const tableButtonWrapper: ({ isTableSelectorOpen, isButtonDisabled, }: {
7
+ isTableSelectorOpen: boolean;
8
+ isButtonDisabled: boolean | undefined;
9
+ }) => import("@emotion/react").SerializedStyles;
7
10
  export declare class ToolbarInsertBlock extends React.PureComponent<Props & WrappedComponentProps, State> {
8
11
  private dropdownButtonRef?;
9
12
  private emojiButtonRef?;
10
13
  private plusButtonRef?;
14
+ private tableButtonRef;
15
+ private tableSelectorButtonRef;
11
16
  state: State;
12
17
  static getDerivedStateFromProps(props: Props & WrappedComponentProps, state: State): State | null;
13
18
  componentDidUpdate(prevProps: Props): void;
@@ -20,6 +25,11 @@ export declare class ToolbarInsertBlock extends React.PureComponent<Props & Wrap
20
25
  private handleEmojiButtonRef;
21
26
  private handlePlusButtonRef;
22
27
  private handleDropDownButtonRef;
28
+ private toggleTableSelector;
29
+ private renderTableSelectorPopup;
30
+ private handleSelectedTableSize;
31
+ private handleTableSelectorPressEscape;
32
+ private handleTableSelectorClickOutside;
23
33
  render(): jsx.JSX.Element | null;
24
34
  private handleClick;
25
35
  private handleOpenByKeyboard;
@@ -0,0 +1,15 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import type { OnTableSizeSelection } from './table-selector-popup';
4
+ type SimpleEventHandler<T> = (event: T) => void;
5
+ export interface TableSelectorPopupProps {
6
+ onSelection: OnTableSizeSelection;
7
+ target?: HTMLElement;
8
+ popupsMountPoint?: HTMLElement;
9
+ popupsBoundariesElement?: HTMLElement;
10
+ popupsScrollableElement?: HTMLElement;
11
+ handleClickOutside?: SimpleEventHandler<MouseEvent>;
12
+ handleEscapeKeydown?: SimpleEventHandler<KeyboardEvent>;
13
+ }
14
+ export declare const TableSelectorPopup: (props: TableSelectorPopupProps) => jsx.JSX.Element;
15
+ export default TableSelectorPopup;
@@ -0,0 +1,25 @@
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ export declare const TABLE_SELECTOR_BUTTON_GAP = 2;
4
+ export declare const TABLE_SELECTOR_BUTTON_SIZE = 17;
5
+ export interface TableSelectorButtonProps {
6
+ row: number;
7
+ col: number;
8
+ isActive: boolean;
9
+ onClick: OnTableSizeSelection;
10
+ label: string;
11
+ }
12
+ export interface OnTableSizeSelection {
13
+ (rowsCount: number, colsCount: number, event?: SyntheticEvent): void;
14
+ }
15
+ interface TableSelectorPopupProps {
16
+ maxCols: number;
17
+ maxRows: number;
18
+ onSelection: OnTableSizeSelection;
19
+ selectedCol: number;
20
+ selectedRow: number;
21
+ }
22
+ declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<TableSelectorPopupProps & WrappedComponentProps<"intl">>> & {
23
+ WrappedComponent: import("react").ComponentType<TableSelectorPopupProps & WrappedComponentProps<"intl">>;
24
+ };
25
+ export default _default;
@@ -3,11 +3,16 @@ import React from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import type { WrappedComponentProps } from 'react-intl-next';
5
5
  import type { Props, State } from './types';
6
- export declare const tableButtonWrapper: import("@emotion/react").SerializedStyles;
6
+ export declare const tableButtonWrapper: ({ isTableSelectorOpen, isButtonDisabled, }: {
7
+ isTableSelectorOpen: boolean;
8
+ isButtonDisabled: boolean | undefined;
9
+ }) => import("@emotion/react").SerializedStyles;
7
10
  export declare class ToolbarInsertBlock extends React.PureComponent<Props & WrappedComponentProps, State> {
8
11
  private dropdownButtonRef?;
9
12
  private emojiButtonRef?;
10
13
  private plusButtonRef?;
14
+ private tableButtonRef;
15
+ private tableSelectorButtonRef;
11
16
  state: State;
12
17
  static getDerivedStateFromProps(props: Props & WrappedComponentProps, state: State): State | null;
13
18
  componentDidUpdate(prevProps: Props): void;
@@ -20,6 +25,11 @@ export declare class ToolbarInsertBlock extends React.PureComponent<Props & Wrap
20
25
  private handleEmojiButtonRef;
21
26
  private handlePlusButtonRef;
22
27
  private handleDropDownButtonRef;
28
+ private toggleTableSelector;
29
+ private renderTableSelectorPopup;
30
+ private handleSelectedTableSize;
31
+ private handleTableSelectorPressEscape;
32
+ private handleTableSelectorClickOutside;
23
33
  render(): jsx.JSX.Element | null;
24
34
  private handleClick;
25
35
  private handleOpenByKeyboard;
@@ -0,0 +1,15 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ import type { OnTableSizeSelection } from './table-selector-popup';
4
+ type SimpleEventHandler<T> = (event: T) => void;
5
+ export interface TableSelectorPopupProps {
6
+ onSelection: OnTableSizeSelection;
7
+ target?: HTMLElement;
8
+ popupsMountPoint?: HTMLElement;
9
+ popupsBoundariesElement?: HTMLElement;
10
+ popupsScrollableElement?: HTMLElement;
11
+ handleClickOutside?: SimpleEventHandler<MouseEvent>;
12
+ handleEscapeKeydown?: SimpleEventHandler<KeyboardEvent>;
13
+ }
14
+ export declare const TableSelectorPopup: (props: TableSelectorPopupProps) => jsx.JSX.Element;
15
+ export default TableSelectorPopup;
@@ -0,0 +1,25 @@
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ export declare const TABLE_SELECTOR_BUTTON_GAP = 2;
4
+ export declare const TABLE_SELECTOR_BUTTON_SIZE = 17;
5
+ export interface TableSelectorButtonProps {
6
+ row: number;
7
+ col: number;
8
+ isActive: boolean;
9
+ onClick: OnTableSizeSelection;
10
+ label: string;
11
+ }
12
+ export interface OnTableSizeSelection {
13
+ (rowsCount: number, colsCount: number, event?: SyntheticEvent): void;
14
+ }
15
+ interface TableSelectorPopupProps {
16
+ maxCols: number;
17
+ maxRows: number;
18
+ onSelection: OnTableSizeSelection;
19
+ selectedCol: number;
20
+ selectedRow: number;
21
+ }
22
+ declare const _default: import("react").FC<import("react-intl-next").WithIntlProps<TableSelectorPopupProps & WrappedComponentProps<"intl">>> & {
23
+ WrappedComponent: import("react").ComponentType<TableSelectorPopupProps & WrappedComponentProps<"intl">>;
24
+ };
25
+ export default _default;