@atlaskit/editor-plugin-insert-block 3.2.0 → 3.2.2
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 +19 -0
- package/dist/cjs/ui/ElementBrowser/InsertMenu.js +2 -1
- package/dist/cjs/ui/ToolbarInsertBlock/index.js +5 -4
- package/dist/es2019/ui/ElementBrowser/InsertMenu.js +2 -1
- package/dist/es2019/ui/ToolbarInsertBlock/index.js +3 -2
- package/dist/esm/ui/ElementBrowser/InsertMenu.js +2 -1
- package/dist/esm/ui/ToolbarInsertBlock/index.js +3 -2
- package/package.json +16 -13
- package/dist/cjs/ui/ToolbarInsertBlock/table-selector-popup-with-listeners.js +0 -258
- package/dist/cjs/ui/ToolbarInsertBlock/table-selector-popup.js +0 -158
- package/dist/es2019/ui/ToolbarInsertBlock/table-selector-popup-with-listeners.js +0 -250
- package/dist/es2019/ui/ToolbarInsertBlock/table-selector-popup.js +0 -150
- package/dist/esm/ui/ToolbarInsertBlock/table-selector-popup-with-listeners.js +0 -252
- package/dist/esm/ui/ToolbarInsertBlock/table-selector-popup.js +0 -150
- package/dist/types/ui/ToolbarInsertBlock/table-selector-popup-with-listeners.d.ts +0 -20
- package/dist/types/ui/ToolbarInsertBlock/table-selector-popup.d.ts +0 -31
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/table-selector-popup-with-listeners.d.ts +0 -20
- package/dist/types-ts4.5/ui/ToolbarInsertBlock/table-selector-popup.d.ts +0 -31
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxRuntime classic
|
|
3
|
-
* @jsx jsx
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
9
|
-
import { css, jsx } from '@emotion/react';
|
|
10
|
-
import { bind } from 'bind-event-listener';
|
|
11
|
-
import { Popup } from '@atlaskit/editor-common/ui';
|
|
12
|
-
import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
13
|
-
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
14
|
-
import { N0, N30A, N60A } from '@atlaskit/theme/colors';
|
|
15
|
-
import tableSelectorPopup, { TABLE_SELECTOR_BUTTON_GAP, TABLE_SELECTOR_BUTTON_SIZE } from './table-selector-popup';
|
|
16
|
-
const TABLE_SELECTOR_PADDING_TOP = 8;
|
|
17
|
-
const TABLE_SELECTOR_PADDING_SIDE = 10;
|
|
18
|
-
const DEFAULT_TABLE_SELECTOR_ROWS = 5;
|
|
19
|
-
const DEFAULT_TABLE_SELECTOR_COLS = 10;
|
|
20
|
-
const DEFAULT_TABLE_SELECTOR_SELECTION_SIZE = 1;
|
|
21
|
-
const DEFAULT_MAX_TABLE_SELECTOR_ROWS = 10;
|
|
22
|
-
const TableSelectorWithListeners = withOuterListeners(tableSelectorPopup);
|
|
23
|
-
const initialSizeState = {
|
|
24
|
-
col: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
|
|
25
|
-
row: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
|
|
26
|
-
maxCol: DEFAULT_TABLE_SELECTOR_COLS,
|
|
27
|
-
maxRow: DEFAULT_TABLE_SELECTOR_ROWS
|
|
28
|
-
};
|
|
29
|
-
const tableSelectorPopupWrapperStyles = css({
|
|
30
|
-
borderRadius: "var(--ds-border-radius, 3px)",
|
|
31
|
-
backgroundColor: `var(--ds-surface-overlay, ${N0})`,
|
|
32
|
-
boxShadow: `var(--ds-shadow-overlay, ${`0 0 0 1px ${N30A}, 0 2px 1px ${N30A}, 0 0 20px -6px ${N60A}`})`,
|
|
33
|
-
padding: `${`var(--ds-space-100, ${`${TABLE_SELECTOR_PADDING_TOP}px`})`} ${TABLE_SELECTOR_PADDING_SIDE}px`
|
|
34
|
-
});
|
|
35
|
-
export const TableSelectorPopup = props => {
|
|
36
|
-
const [size, setSize] = useState(initialSizeState);
|
|
37
|
-
const tablePopupRef = useRef(null);
|
|
38
|
-
// If popup opened by keyboard enable keyboard mode
|
|
39
|
-
const isKeyboardMode = useRef(props.isOpenedByKeyboard);
|
|
40
|
-
const enableKeyboardMode = useCallback(() => {
|
|
41
|
-
if (!isKeyboardMode.current) {
|
|
42
|
-
isKeyboardMode.current = true;
|
|
43
|
-
}
|
|
44
|
-
}, [isKeyboardMode]);
|
|
45
|
-
const disableKeyboardMode = useCallback(() => {
|
|
46
|
-
if (isKeyboardMode.current) {
|
|
47
|
-
isKeyboardMode.current = false;
|
|
48
|
-
}
|
|
49
|
-
}, [isKeyboardMode]);
|
|
50
|
-
|
|
51
|
-
// Mouse move is used to allow selection changes outside of the popup and is more reactive to changes.
|
|
52
|
-
const handleMouseMove = useCallback(e => {
|
|
53
|
-
if (!tablePopupRef.current) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
disableKeyboardMode();
|
|
57
|
-
const tablePopup = tablePopupRef.current;
|
|
58
|
-
const {
|
|
59
|
-
left,
|
|
60
|
-
top
|
|
61
|
-
} = tablePopup.getBoundingClientRect();
|
|
62
|
-
|
|
63
|
-
// Mouse position on popup
|
|
64
|
-
const selectedWidth = e.clientX - left;
|
|
65
|
-
const selectedHeight = e.clientY - top;
|
|
66
|
-
|
|
67
|
-
// Calculate number grid cells selected
|
|
68
|
-
let selectedGridCols = Math.ceil((selectedWidth - TABLE_SELECTOR_PADDING_SIDE + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
|
|
69
|
-
let selectedGridRows = Math.ceil((selectedHeight - TABLE_SELECTOR_PADDING_TOP + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
|
|
70
|
-
// Keep the selected rows and columns within the defined bounds
|
|
71
|
-
let gridRows = DEFAULT_TABLE_SELECTOR_ROWS;
|
|
72
|
-
if (selectedGridCols < 1) {
|
|
73
|
-
selectedGridCols = 1;
|
|
74
|
-
}
|
|
75
|
-
if (selectedGridCols > size.maxCol) {
|
|
76
|
-
selectedGridCols = size.maxCol;
|
|
77
|
-
}
|
|
78
|
-
if (selectedGridRows < 1) {
|
|
79
|
-
selectedGridRows = 1;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Expand grid when row selection is greater than the default grid size
|
|
83
|
-
if (selectedGridRows >= DEFAULT_TABLE_SELECTOR_ROWS && selectedGridRows < DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
84
|
-
gridRows = selectedGridRows + 1;
|
|
85
|
-
}
|
|
86
|
-
if (selectedGridRows >= DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
87
|
-
selectedGridRows = DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
88
|
-
gridRows = DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
89
|
-
}
|
|
90
|
-
if (selectedGridCols !== size.col || selectedGridRows !== size.row) {
|
|
91
|
-
setSize({
|
|
92
|
-
col: selectedGridCols,
|
|
93
|
-
row: selectedGridRows,
|
|
94
|
-
maxCol: DEFAULT_TABLE_SELECTOR_COLS,
|
|
95
|
-
maxRow: gridRows
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}, [disableKeyboardMode, size, setSize]);
|
|
99
|
-
const decreasingSequence = (maxNumber, prevNumber) => {
|
|
100
|
-
let nextNumber = prevNumber - 1;
|
|
101
|
-
if (prevNumber === 1) {
|
|
102
|
-
nextNumber = maxNumber;
|
|
103
|
-
}
|
|
104
|
-
return nextNumber;
|
|
105
|
-
};
|
|
106
|
-
const getMaxRow = (prevSize, eventKey) => {
|
|
107
|
-
switch (eventKey) {
|
|
108
|
-
case 'ArrowDown':
|
|
109
|
-
// Expand the grid size when last row selected
|
|
110
|
-
if (prevSize.maxRow < DEFAULT_MAX_TABLE_SELECTOR_ROWS && prevSize.row >= DEFAULT_TABLE_SELECTOR_ROWS - 1) {
|
|
111
|
-
return prevSize.maxRow + 1;
|
|
112
|
-
}
|
|
113
|
-
if (prevSize.row === DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
114
|
-
return DEFAULT_TABLE_SELECTOR_ROWS;
|
|
115
|
-
}
|
|
116
|
-
return prevSize.maxRow;
|
|
117
|
-
case 'ArrowLeft':
|
|
118
|
-
const moveToPrevRow = prevSize.col === 1 && prevSize.row > 1;
|
|
119
|
-
const moveToLastRow = prevSize.row === 1 && prevSize.col === 1;
|
|
120
|
-
// Expand the popup to max size when selected row wraps around to last row
|
|
121
|
-
if (moveToLastRow) {
|
|
122
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
123
|
-
}
|
|
124
|
-
// Decrease the popup when decreased row selection
|
|
125
|
-
if (prevSize.maxRow > DEFAULT_TABLE_SELECTOR_ROWS && moveToPrevRow) {
|
|
126
|
-
return prevSize.row;
|
|
127
|
-
}
|
|
128
|
-
return prevSize.maxRow;
|
|
129
|
-
case 'ArrowUp':
|
|
130
|
-
if (prevSize.row === 1) {
|
|
131
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
132
|
-
// Decrease the popup size when decreased row selection
|
|
133
|
-
} else if (prevSize.maxRow > DEFAULT_TABLE_SELECTOR_ROWS) {
|
|
134
|
-
return prevSize.row;
|
|
135
|
-
}
|
|
136
|
-
return prevSize.maxRow;
|
|
137
|
-
case 'ArrowRight':
|
|
138
|
-
const moveToNextRow = prevSize.col === DEFAULT_TABLE_SELECTOR_COLS;
|
|
139
|
-
const increaseMaxRow = prevSize.maxRow < DEFAULT_MAX_TABLE_SELECTOR_ROWS && moveToNextRow && prevSize.row + 1 === prevSize.maxRow;
|
|
140
|
-
|
|
141
|
-
// Decrease popup size for wrap around to selection 1 x 1
|
|
142
|
-
if (prevSize.row === DEFAULT_MAX_TABLE_SELECTOR_ROWS && prevSize.col === DEFAULT_TABLE_SELECTOR_COLS) {
|
|
143
|
-
return DEFAULT_TABLE_SELECTOR_ROWS;
|
|
144
|
-
// Decrease the popup size when decreased row selection
|
|
145
|
-
} else if (increaseMaxRow) {
|
|
146
|
-
return prevSize.maxRow + 1;
|
|
147
|
-
}
|
|
148
|
-
return prevSize.maxRow;
|
|
149
|
-
default:
|
|
150
|
-
return prevSize.maxRow;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const handleInitialButtonFocus = useCallback(() => {
|
|
154
|
-
if (isKeyboardMode.current !== true) {
|
|
155
|
-
enableKeyboardMode();
|
|
156
|
-
setSize(initialSizeState);
|
|
157
|
-
}
|
|
158
|
-
}, [enableKeyboardMode, setSize]);
|
|
159
|
-
const handleKeyDown = useCallback(
|
|
160
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
|
-
event => {
|
|
162
|
-
if (event.key === 'ArrowDown') {
|
|
163
|
-
enableKeyboardMode();
|
|
164
|
-
setSize(prevSize => {
|
|
165
|
-
return {
|
|
166
|
-
...prevSize,
|
|
167
|
-
row: prevSize.row % prevSize.maxRow + 1,
|
|
168
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
169
|
-
};
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if (event.key === 'ArrowRight') {
|
|
173
|
-
enableKeyboardMode();
|
|
174
|
-
setSize(prevSize => {
|
|
175
|
-
const moveToNextRow = prevSize.col === DEFAULT_TABLE_SELECTOR_COLS;
|
|
176
|
-
return {
|
|
177
|
-
...prevSize,
|
|
178
|
-
col: prevSize.col % DEFAULT_TABLE_SELECTOR_COLS + 1,
|
|
179
|
-
row: moveToNextRow ? prevSize.row % prevSize.maxRow + 1 : prevSize.row,
|
|
180
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
181
|
-
};
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (event.key === 'ArrowLeft') {
|
|
185
|
-
enableKeyboardMode();
|
|
186
|
-
setSize(prevSize => {
|
|
187
|
-
const getRow = (prevRow, prevCol) => {
|
|
188
|
-
const row = prevRow;
|
|
189
|
-
// Move to previous row for wrap around
|
|
190
|
-
if (prevSize.col === 1 && prevSize.row > 1) {
|
|
191
|
-
return prevRow - 1;
|
|
192
|
-
// Increase the selection to max size when selected row and column wraps around
|
|
193
|
-
} else if (prevRow === 1 && prevCol === 1) {
|
|
194
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
195
|
-
}
|
|
196
|
-
return row;
|
|
197
|
-
};
|
|
198
|
-
return {
|
|
199
|
-
...prevSize,
|
|
200
|
-
col: decreasingSequence(prevSize.maxCol, prevSize.col),
|
|
201
|
-
row: getRow(prevSize.row, prevSize.col),
|
|
202
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
if (event.key === 'ArrowUp') {
|
|
207
|
-
enableKeyboardMode();
|
|
208
|
-
setSize(prevSize => {
|
|
209
|
-
const moveToLastRow = prevSize.row === 1;
|
|
210
|
-
return {
|
|
211
|
-
...prevSize,
|
|
212
|
-
row: moveToLastRow ? DEFAULT_MAX_TABLE_SELECTOR_ROWS : decreasingSequence(prevSize.maxRow, prevSize.row),
|
|
213
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
214
|
-
};
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
}, [enableKeyboardMode, setSize]);
|
|
218
|
-
useEffect(() => {
|
|
219
|
-
const unbind = bind(window, {
|
|
220
|
-
type: 'mousemove',
|
|
221
|
-
listener: handleMouseMove
|
|
222
|
-
});
|
|
223
|
-
return unbind;
|
|
224
|
-
}, [handleMouseMove]);
|
|
225
|
-
return jsx(Popup, {
|
|
226
|
-
target: props.target,
|
|
227
|
-
offset: [0, 3],
|
|
228
|
-
mountTo: props.popupsMountPoint,
|
|
229
|
-
boundariesElement: props.popupsBoundariesElement,
|
|
230
|
-
scrollableElement: props.popupsScrollableElement,
|
|
231
|
-
focusTrap: true,
|
|
232
|
-
onUnmount: props.onUnmount,
|
|
233
|
-
zIndex: akEditorMenuZIndex
|
|
234
|
-
}, jsx("div", {
|
|
235
|
-
css: tableSelectorPopupWrapperStyles,
|
|
236
|
-
ref: tablePopupRef
|
|
237
|
-
}, jsx(TableSelectorWithListeners, {
|
|
238
|
-
handleClickOutside: props.handleClickOutside,
|
|
239
|
-
handleEscapeKeydown: props.handleEscapeKeydown,
|
|
240
|
-
maxCols: size.maxCol,
|
|
241
|
-
maxRows: size.maxRow,
|
|
242
|
-
onSelection: props.onSelection,
|
|
243
|
-
selectedCol: size.col,
|
|
244
|
-
selectedRow: size.row,
|
|
245
|
-
onKeyDown: handleKeyDown,
|
|
246
|
-
isFocused: isKeyboardMode.current,
|
|
247
|
-
handleInitialButtonFocus: handleInitialButtonFocus
|
|
248
|
-
})));
|
|
249
|
-
};
|
|
250
|
-
export default TableSelectorPopup;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxRuntime classic
|
|
3
|
-
* @jsx jsx
|
|
4
|
-
*/
|
|
5
|
-
import { useContext, useEffect, useMemo, useRef } from 'react';
|
|
6
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
7
|
-
import { css, jsx } from '@emotion/react';
|
|
8
|
-
import { injectIntl } from 'react-intl-next';
|
|
9
|
-
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
10
|
-
import { OutsideClickTargetRefContext } from '@atlaskit/editor-common/ui-react';
|
|
11
|
-
import { Stack } from '@atlaskit/primitives';
|
|
12
|
-
import { B100 } from '@atlaskit/theme/colors';
|
|
13
|
-
export const TABLE_SELECTOR_BUTTON_GAP = 2;
|
|
14
|
-
export const TABLE_SELECTOR_BUTTON_SIZE = 17;
|
|
15
|
-
const selectedButtonStyles = css({
|
|
16
|
-
backgroundColor: "var(--ds-background-accent-blue-subtlest, #579DFF)",
|
|
17
|
-
border: `1px solid ${"var(--ds-background-accent-blue-subtle, #579DFF)"}`
|
|
18
|
-
});
|
|
19
|
-
const buttonStyles = css({
|
|
20
|
-
height: `${TABLE_SELECTOR_BUTTON_SIZE}px`,
|
|
21
|
-
width: `${TABLE_SELECTOR_BUTTON_SIZE}px`,
|
|
22
|
-
border: `1px solid ${"var(--ds-border, #091e4224)"}`,
|
|
23
|
-
backgroundColor: "var(--ds-background-input, #ffffff)",
|
|
24
|
-
borderRadius: '3px',
|
|
25
|
-
cursor: 'pointer',
|
|
26
|
-
display: 'block',
|
|
27
|
-
'&:focus': {
|
|
28
|
-
outline: 'none',
|
|
29
|
-
border: `1px solid ${`var(--ds-border-focused, ${B100})`}`,
|
|
30
|
-
boxShadow: `0 0 0 0.5px ${`var(--ds-border-focused, ${B100})`}`
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const selectionSizeTextStyles = css({
|
|
34
|
-
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
35
|
-
lineHeight: '14px',
|
|
36
|
-
display: 'flex',
|
|
37
|
-
justifyContent: 'center',
|
|
38
|
-
marginTop: "var(--ds-space-075, 5px)",
|
|
39
|
-
padding: "var(--ds-space-075, 10px)"
|
|
40
|
-
});
|
|
41
|
-
const TableSelectorButton = ({
|
|
42
|
-
row,
|
|
43
|
-
col,
|
|
44
|
-
isActive,
|
|
45
|
-
onClick,
|
|
46
|
-
label,
|
|
47
|
-
onKeyDown,
|
|
48
|
-
isFocused,
|
|
49
|
-
handleInitialButtonFocus
|
|
50
|
-
}) => {
|
|
51
|
-
const btnRef = useRef(null);
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (btnRef.current) {
|
|
54
|
-
if (isFocused) {
|
|
55
|
-
btnRef.current.focus();
|
|
56
|
-
} else {
|
|
57
|
-
btnRef.current.blur();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}, [isFocused, btnRef]);
|
|
61
|
-
const handleFocus = col === 1 && row === 1 ? () => handleInitialButtonFocus() : undefined;
|
|
62
|
-
return jsx("button", {
|
|
63
|
-
type: "button",
|
|
64
|
-
css: [buttonStyles, isActive ? selectedButtonStyles : undefined],
|
|
65
|
-
onClick: () => onClick(row, col),
|
|
66
|
-
"aria-label": label,
|
|
67
|
-
onKeyDown: onKeyDown,
|
|
68
|
-
ref: btnRef,
|
|
69
|
-
onFocus: handleFocus
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
const createArray = (maxCols, maxRows) => {
|
|
73
|
-
const arr = [];
|
|
74
|
-
for (let i = 1; i < maxRows + 1; i++) {
|
|
75
|
-
for (let j = 1; j < maxCols + 1; j++) {
|
|
76
|
-
arr.push({
|
|
77
|
-
col: j,
|
|
78
|
-
row: i
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return arr;
|
|
83
|
-
};
|
|
84
|
-
const gridWrapperStyles = ({
|
|
85
|
-
maxCols,
|
|
86
|
-
maxRows
|
|
87
|
-
}) => css({
|
|
88
|
-
display: 'grid',
|
|
89
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
90
|
-
gridTemplateColumns: `repeat(${maxCols}, 1fr)`,
|
|
91
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
92
|
-
gridTemplateRows: `repeat(${maxRows}, 1fr)`,
|
|
93
|
-
gap: `${`var(--ds-space-025, ${`${TABLE_SELECTOR_BUTTON_GAP}px`})`}`
|
|
94
|
-
});
|
|
95
|
-
const TableSelectorPopup = ({
|
|
96
|
-
maxCols,
|
|
97
|
-
maxRows,
|
|
98
|
-
onSelection,
|
|
99
|
-
selectedCol,
|
|
100
|
-
selectedRow,
|
|
101
|
-
onKeyDown,
|
|
102
|
-
isFocused,
|
|
103
|
-
handleInitialButtonFocus,
|
|
104
|
-
intl: {
|
|
105
|
-
formatMessage
|
|
106
|
-
}
|
|
107
|
-
}) => {
|
|
108
|
-
const buttons = useMemo(() => {
|
|
109
|
-
return createArray(maxCols, maxRows);
|
|
110
|
-
}, [maxCols, maxRows]);
|
|
111
|
-
const setOutsideClickTargetRef = useContext(OutsideClickTargetRefContext);
|
|
112
|
-
return jsx(Stack, {
|
|
113
|
-
ref: setOutsideClickTargetRef
|
|
114
|
-
}, jsx("div", {
|
|
115
|
-
"aria-label": `${formatMessage(messages.tableSizeSelectorPopup)}`,
|
|
116
|
-
css:
|
|
117
|
-
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
118
|
-
gridWrapperStyles({
|
|
119
|
-
maxCols: maxCols,
|
|
120
|
-
maxRows: maxRows
|
|
121
|
-
})
|
|
122
|
-
}, buttons.map(({
|
|
123
|
-
col,
|
|
124
|
-
row
|
|
125
|
-
}, index) => {
|
|
126
|
-
const isCurrentFocused = isFocused && selectedCol === col && selectedRow === row;
|
|
127
|
-
const isActive = selectedCol >= col && selectedRow >= row ? true : false;
|
|
128
|
-
return jsx(TableSelectorButton
|
|
129
|
-
// Ignored via go/ees005
|
|
130
|
-
// eslint-disable-next-line react/no-array-index-key
|
|
131
|
-
, {
|
|
132
|
-
key: index,
|
|
133
|
-
isActive: isActive,
|
|
134
|
-
col: col,
|
|
135
|
-
row: row,
|
|
136
|
-
onClick: onSelection,
|
|
137
|
-
label: `${formatMessage(messages.tableSizeSelectorButton, {
|
|
138
|
-
numberOfColumns: col,
|
|
139
|
-
numberOfRows: row
|
|
140
|
-
})}`,
|
|
141
|
-
onKeyDown: onKeyDown,
|
|
142
|
-
isFocused: isCurrentFocused,
|
|
143
|
-
handleInitialButtonFocus: handleInitialButtonFocus
|
|
144
|
-
});
|
|
145
|
-
})), jsx("span", {
|
|
146
|
-
css: selectionSizeTextStyles,
|
|
147
|
-
"aria-hidden": true
|
|
148
|
-
}, `${selectedCol} x ${selectedRow}`));
|
|
149
|
-
};
|
|
150
|
-
export default injectIntl(TableSelectorPopup);
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
/**
|
|
6
|
-
* @jsxRuntime classic
|
|
7
|
-
* @jsx jsx
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
13
|
-
import { css, jsx } from '@emotion/react';
|
|
14
|
-
import { bind } from 'bind-event-listener';
|
|
15
|
-
import { Popup } from '@atlaskit/editor-common/ui';
|
|
16
|
-
import { withReactEditorViewOuterListeners as withOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
17
|
-
import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
|
|
18
|
-
import { N0, N30A, N60A } from '@atlaskit/theme/colors';
|
|
19
|
-
import tableSelectorPopup, { TABLE_SELECTOR_BUTTON_GAP, TABLE_SELECTOR_BUTTON_SIZE } from './table-selector-popup';
|
|
20
|
-
var TABLE_SELECTOR_PADDING_TOP = 8;
|
|
21
|
-
var TABLE_SELECTOR_PADDING_SIDE = 10;
|
|
22
|
-
var DEFAULT_TABLE_SELECTOR_ROWS = 5;
|
|
23
|
-
var DEFAULT_TABLE_SELECTOR_COLS = 10;
|
|
24
|
-
var DEFAULT_TABLE_SELECTOR_SELECTION_SIZE = 1;
|
|
25
|
-
var DEFAULT_MAX_TABLE_SELECTOR_ROWS = 10;
|
|
26
|
-
var TableSelectorWithListeners = withOuterListeners(tableSelectorPopup);
|
|
27
|
-
var initialSizeState = {
|
|
28
|
-
col: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
|
|
29
|
-
row: DEFAULT_TABLE_SELECTOR_SELECTION_SIZE,
|
|
30
|
-
maxCol: DEFAULT_TABLE_SELECTOR_COLS,
|
|
31
|
-
maxRow: DEFAULT_TABLE_SELECTOR_ROWS
|
|
32
|
-
};
|
|
33
|
-
var tableSelectorPopupWrapperStyles = css({
|
|
34
|
-
borderRadius: "var(--ds-border-radius, 3px)",
|
|
35
|
-
backgroundColor: "var(--ds-surface-overlay, ".concat(N0, ")"),
|
|
36
|
-
boxShadow: "var(--ds-shadow-overlay, ".concat("0 0 0 1px ".concat(N30A, ", 0 2px 1px ").concat(N30A, ", 0 0 20px -6px ").concat(N60A), ")"),
|
|
37
|
-
padding: "".concat("var(--ds-space-100, ".concat("".concat(TABLE_SELECTOR_PADDING_TOP, "px"), ")"), " ", TABLE_SELECTOR_PADDING_SIDE, "px")
|
|
38
|
-
});
|
|
39
|
-
export var TableSelectorPopup = function TableSelectorPopup(props) {
|
|
40
|
-
var _useState = useState(initialSizeState),
|
|
41
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
42
|
-
size = _useState2[0],
|
|
43
|
-
setSize = _useState2[1];
|
|
44
|
-
var tablePopupRef = useRef(null);
|
|
45
|
-
// If popup opened by keyboard enable keyboard mode
|
|
46
|
-
var isKeyboardMode = useRef(props.isOpenedByKeyboard);
|
|
47
|
-
var enableKeyboardMode = useCallback(function () {
|
|
48
|
-
if (!isKeyboardMode.current) {
|
|
49
|
-
isKeyboardMode.current = true;
|
|
50
|
-
}
|
|
51
|
-
}, [isKeyboardMode]);
|
|
52
|
-
var disableKeyboardMode = useCallback(function () {
|
|
53
|
-
if (isKeyboardMode.current) {
|
|
54
|
-
isKeyboardMode.current = false;
|
|
55
|
-
}
|
|
56
|
-
}, [isKeyboardMode]);
|
|
57
|
-
|
|
58
|
-
// Mouse move is used to allow selection changes outside of the popup and is more reactive to changes.
|
|
59
|
-
var handleMouseMove = useCallback(function (e) {
|
|
60
|
-
if (!tablePopupRef.current) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
disableKeyboardMode();
|
|
64
|
-
var tablePopup = tablePopupRef.current;
|
|
65
|
-
var _tablePopup$getBoundi = tablePopup.getBoundingClientRect(),
|
|
66
|
-
left = _tablePopup$getBoundi.left,
|
|
67
|
-
top = _tablePopup$getBoundi.top;
|
|
68
|
-
|
|
69
|
-
// Mouse position on popup
|
|
70
|
-
var selectedWidth = e.clientX - left;
|
|
71
|
-
var selectedHeight = e.clientY - top;
|
|
72
|
-
|
|
73
|
-
// Calculate number grid cells selected
|
|
74
|
-
var selectedGridCols = Math.ceil((selectedWidth - TABLE_SELECTOR_PADDING_SIDE + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
|
|
75
|
-
var selectedGridRows = Math.ceil((selectedHeight - TABLE_SELECTOR_PADDING_TOP + TABLE_SELECTOR_BUTTON_GAP) / (TABLE_SELECTOR_BUTTON_GAP + TABLE_SELECTOR_BUTTON_SIZE));
|
|
76
|
-
// Keep the selected rows and columns within the defined bounds
|
|
77
|
-
var gridRows = DEFAULT_TABLE_SELECTOR_ROWS;
|
|
78
|
-
if (selectedGridCols < 1) {
|
|
79
|
-
selectedGridCols = 1;
|
|
80
|
-
}
|
|
81
|
-
if (selectedGridCols > size.maxCol) {
|
|
82
|
-
selectedGridCols = size.maxCol;
|
|
83
|
-
}
|
|
84
|
-
if (selectedGridRows < 1) {
|
|
85
|
-
selectedGridRows = 1;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Expand grid when row selection is greater than the default grid size
|
|
89
|
-
if (selectedGridRows >= DEFAULT_TABLE_SELECTOR_ROWS && selectedGridRows < DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
90
|
-
gridRows = selectedGridRows + 1;
|
|
91
|
-
}
|
|
92
|
-
if (selectedGridRows >= DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
93
|
-
selectedGridRows = DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
94
|
-
gridRows = DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
95
|
-
}
|
|
96
|
-
if (selectedGridCols !== size.col || selectedGridRows !== size.row) {
|
|
97
|
-
setSize({
|
|
98
|
-
col: selectedGridCols,
|
|
99
|
-
row: selectedGridRows,
|
|
100
|
-
maxCol: DEFAULT_TABLE_SELECTOR_COLS,
|
|
101
|
-
maxRow: gridRows
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}, [disableKeyboardMode, size, setSize]);
|
|
105
|
-
var decreasingSequence = function decreasingSequence(maxNumber, prevNumber) {
|
|
106
|
-
var nextNumber = prevNumber - 1;
|
|
107
|
-
if (prevNumber === 1) {
|
|
108
|
-
nextNumber = maxNumber;
|
|
109
|
-
}
|
|
110
|
-
return nextNumber;
|
|
111
|
-
};
|
|
112
|
-
var getMaxRow = function getMaxRow(prevSize, eventKey) {
|
|
113
|
-
switch (eventKey) {
|
|
114
|
-
case 'ArrowDown':
|
|
115
|
-
// Expand the grid size when last row selected
|
|
116
|
-
if (prevSize.maxRow < DEFAULT_MAX_TABLE_SELECTOR_ROWS && prevSize.row >= DEFAULT_TABLE_SELECTOR_ROWS - 1) {
|
|
117
|
-
return prevSize.maxRow + 1;
|
|
118
|
-
}
|
|
119
|
-
if (prevSize.row === DEFAULT_MAX_TABLE_SELECTOR_ROWS) {
|
|
120
|
-
return DEFAULT_TABLE_SELECTOR_ROWS;
|
|
121
|
-
}
|
|
122
|
-
return prevSize.maxRow;
|
|
123
|
-
case 'ArrowLeft':
|
|
124
|
-
var moveToPrevRow = prevSize.col === 1 && prevSize.row > 1;
|
|
125
|
-
var moveToLastRow = prevSize.row === 1 && prevSize.col === 1;
|
|
126
|
-
// Expand the popup to max size when selected row wraps around to last row
|
|
127
|
-
if (moveToLastRow) {
|
|
128
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
129
|
-
}
|
|
130
|
-
// Decrease the popup when decreased row selection
|
|
131
|
-
if (prevSize.maxRow > DEFAULT_TABLE_SELECTOR_ROWS && moveToPrevRow) {
|
|
132
|
-
return prevSize.row;
|
|
133
|
-
}
|
|
134
|
-
return prevSize.maxRow;
|
|
135
|
-
case 'ArrowUp':
|
|
136
|
-
if (prevSize.row === 1) {
|
|
137
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
138
|
-
// Decrease the popup size when decreased row selection
|
|
139
|
-
} else if (prevSize.maxRow > DEFAULT_TABLE_SELECTOR_ROWS) {
|
|
140
|
-
return prevSize.row;
|
|
141
|
-
}
|
|
142
|
-
return prevSize.maxRow;
|
|
143
|
-
case 'ArrowRight':
|
|
144
|
-
var moveToNextRow = prevSize.col === DEFAULT_TABLE_SELECTOR_COLS;
|
|
145
|
-
var increaseMaxRow = prevSize.maxRow < DEFAULT_MAX_TABLE_SELECTOR_ROWS && moveToNextRow && prevSize.row + 1 === prevSize.maxRow;
|
|
146
|
-
|
|
147
|
-
// Decrease popup size for wrap around to selection 1 x 1
|
|
148
|
-
if (prevSize.row === DEFAULT_MAX_TABLE_SELECTOR_ROWS && prevSize.col === DEFAULT_TABLE_SELECTOR_COLS) {
|
|
149
|
-
return DEFAULT_TABLE_SELECTOR_ROWS;
|
|
150
|
-
// Decrease the popup size when decreased row selection
|
|
151
|
-
} else if (increaseMaxRow) {
|
|
152
|
-
return prevSize.maxRow + 1;
|
|
153
|
-
}
|
|
154
|
-
return prevSize.maxRow;
|
|
155
|
-
default:
|
|
156
|
-
return prevSize.maxRow;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var handleInitialButtonFocus = useCallback(function () {
|
|
160
|
-
if (isKeyboardMode.current !== true) {
|
|
161
|
-
enableKeyboardMode();
|
|
162
|
-
setSize(initialSizeState);
|
|
163
|
-
}
|
|
164
|
-
}, [enableKeyboardMode, setSize]);
|
|
165
|
-
var handleKeyDown = useCallback(
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
167
|
-
function (event) {
|
|
168
|
-
if (event.key === 'ArrowDown') {
|
|
169
|
-
enableKeyboardMode();
|
|
170
|
-
setSize(function (prevSize) {
|
|
171
|
-
return _objectSpread(_objectSpread({}, prevSize), {}, {
|
|
172
|
-
row: prevSize.row % prevSize.maxRow + 1,
|
|
173
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
if (event.key === 'ArrowRight') {
|
|
178
|
-
enableKeyboardMode();
|
|
179
|
-
setSize(function (prevSize) {
|
|
180
|
-
var moveToNextRow = prevSize.col === DEFAULT_TABLE_SELECTOR_COLS;
|
|
181
|
-
return _objectSpread(_objectSpread({}, prevSize), {}, {
|
|
182
|
-
col: prevSize.col % DEFAULT_TABLE_SELECTOR_COLS + 1,
|
|
183
|
-
row: moveToNextRow ? prevSize.row % prevSize.maxRow + 1 : prevSize.row,
|
|
184
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (event.key === 'ArrowLeft') {
|
|
189
|
-
enableKeyboardMode();
|
|
190
|
-
setSize(function (prevSize) {
|
|
191
|
-
var getRow = function getRow(prevRow, prevCol) {
|
|
192
|
-
var row = prevRow;
|
|
193
|
-
// Move to previous row for wrap around
|
|
194
|
-
if (prevSize.col === 1 && prevSize.row > 1) {
|
|
195
|
-
return prevRow - 1;
|
|
196
|
-
// Increase the selection to max size when selected row and column wraps around
|
|
197
|
-
} else if (prevRow === 1 && prevCol === 1) {
|
|
198
|
-
return DEFAULT_MAX_TABLE_SELECTOR_ROWS;
|
|
199
|
-
}
|
|
200
|
-
return row;
|
|
201
|
-
};
|
|
202
|
-
return _objectSpread(_objectSpread({}, prevSize), {}, {
|
|
203
|
-
col: decreasingSequence(prevSize.maxCol, prevSize.col),
|
|
204
|
-
row: getRow(prevSize.row, prevSize.col),
|
|
205
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
if (event.key === 'ArrowUp') {
|
|
210
|
-
enableKeyboardMode();
|
|
211
|
-
setSize(function (prevSize) {
|
|
212
|
-
var moveToLastRow = prevSize.row === 1;
|
|
213
|
-
return _objectSpread(_objectSpread({}, prevSize), {}, {
|
|
214
|
-
row: moveToLastRow ? DEFAULT_MAX_TABLE_SELECTOR_ROWS : decreasingSequence(prevSize.maxRow, prevSize.row),
|
|
215
|
-
maxRow: getMaxRow(prevSize, event.key)
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}, [enableKeyboardMode, setSize]);
|
|
220
|
-
useEffect(function () {
|
|
221
|
-
var unbind = bind(window, {
|
|
222
|
-
type: 'mousemove',
|
|
223
|
-
listener: handleMouseMove
|
|
224
|
-
});
|
|
225
|
-
return unbind;
|
|
226
|
-
}, [handleMouseMove]);
|
|
227
|
-
return jsx(Popup, {
|
|
228
|
-
target: props.target,
|
|
229
|
-
offset: [0, 3],
|
|
230
|
-
mountTo: props.popupsMountPoint,
|
|
231
|
-
boundariesElement: props.popupsBoundariesElement,
|
|
232
|
-
scrollableElement: props.popupsScrollableElement,
|
|
233
|
-
focusTrap: true,
|
|
234
|
-
onUnmount: props.onUnmount,
|
|
235
|
-
zIndex: akEditorMenuZIndex
|
|
236
|
-
}, jsx("div", {
|
|
237
|
-
css: tableSelectorPopupWrapperStyles,
|
|
238
|
-
ref: tablePopupRef
|
|
239
|
-
}, jsx(TableSelectorWithListeners, {
|
|
240
|
-
handleClickOutside: props.handleClickOutside,
|
|
241
|
-
handleEscapeKeydown: props.handleEscapeKeydown,
|
|
242
|
-
maxCols: size.maxCol,
|
|
243
|
-
maxRows: size.maxRow,
|
|
244
|
-
onSelection: props.onSelection,
|
|
245
|
-
selectedCol: size.col,
|
|
246
|
-
selectedRow: size.row,
|
|
247
|
-
onKeyDown: handleKeyDown,
|
|
248
|
-
isFocused: isKeyboardMode.current,
|
|
249
|
-
handleInitialButtonFocus: handleInitialButtonFocus
|
|
250
|
-
})));
|
|
251
|
-
};
|
|
252
|
-
export default TableSelectorPopup;
|