@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.
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-insert-block",
3
- "version": "0.2.17",
3
+ "version": "0.2.19",
4
4
  "description": "Insert block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  ".": "./src/index.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@atlaskit/editor-common": "^76.36.0",
36
+ "@atlaskit/editor-common": "^76.39.0",
37
37
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
38
38
  "@atlaskit/editor-plugin-block-type": "^3.0.0",
39
39
  "@atlaskit/editor-plugin-code-block": "^0.1.0",
@@ -42,7 +42,7 @@
42
42
  "@atlaskit/editor-plugin-expand": "^0.4.0",
43
43
  "@atlaskit/editor-plugin-extension": "^0.5.0",
44
44
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
45
- "@atlaskit/editor-plugin-hyperlink": "^0.7.0",
45
+ "@atlaskit/editor-plugin-hyperlink": "^0.8.0",
46
46
  "@atlaskit/editor-plugin-image-upload": "^0.2.0",
47
47
  "@atlaskit/editor-plugin-layout": "^0.1.0",
48
48
  "@atlaskit/editor-plugin-media": "^0.11.0",
@@ -52,17 +52,19 @@
52
52
  "@atlaskit/editor-plugin-quick-insert": "^0.2.0",
53
53
  "@atlaskit/editor-plugin-rule": "^0.1.0",
54
54
  "@atlaskit/editor-plugin-status": "^0.2.0",
55
- "@atlaskit/editor-plugin-table": "^5.7.0",
55
+ "@atlaskit/editor-plugin-table": "^5.8.0",
56
56
  "@atlaskit/editor-plugin-tasks-and-decisions": "^0.2.0",
57
57
  "@atlaskit/editor-plugin-type-ahead": "^0.9.0",
58
58
  "@atlaskit/editor-prosemirror": "1.1.0",
59
59
  "@atlaskit/editor-shared-styles": "^2.9.0",
60
60
  "@atlaskit/emoji": "^67.6.0",
61
61
  "@atlaskit/icon": "^22.0.0",
62
+ "@atlaskit/primitives": "^1.16.0",
62
63
  "@atlaskit/theme": "^12.6.0",
63
64
  "@atlaskit/tokens": "^1.33.0",
64
65
  "@babel/runtime": "^7.0.0",
65
66
  "@emotion/react": "^11.7.1",
67
+ "bind-event-listener": "^2.1.1",
66
68
  "lodash": "^4.17.21",
67
69
  "memoize-one": "^6.0.0"
68
70
  },