@atlaskit/editor-plugin-table 7.4.7 → 7.4.9
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 +12 -0
- package/dist/cjs/commands/insert.js +5 -12
- package/dist/cjs/plugin.js +17 -11
- package/dist/cjs/pm-plugins/table-width.js +53 -34
- package/dist/cjs/ui/FloatingContextualMenu/index.js +1 -1
- package/dist/cjs/ui/FloatingDragMenu/DragMenu.js +13 -3
- package/dist/cjs/ui/FloatingDragMenu/DropdownMenu.js +53 -8
- package/dist/cjs/ui/FloatingDragMenu/index.js +9 -5
- package/dist/cjs/ui/consts.js +2 -1
- package/dist/cjs/utils/create.js +28 -0
- package/dist/cjs/utils/index.js +8 -1
- package/dist/es2019/commands/insert.js +7 -14
- package/dist/es2019/plugin.js +16 -10
- package/dist/es2019/pm-plugins/table-width.js +133 -114
- package/dist/es2019/ui/FloatingContextualMenu/index.js +2 -2
- package/dist/es2019/ui/FloatingDragMenu/DragMenu.js +13 -3
- package/dist/es2019/ui/FloatingDragMenu/DropdownMenu.js +42 -8
- package/dist/es2019/ui/FloatingDragMenu/index.js +10 -6
- package/dist/es2019/ui/consts.js +1 -0
- package/dist/es2019/utils/create.js +18 -0
- package/dist/es2019/utils/index.js +2 -1
- package/dist/esm/commands/insert.js +7 -14
- package/dist/esm/plugin.js +16 -10
- package/dist/esm/pm-plugins/table-width.js +53 -34
- package/dist/esm/ui/FloatingContextualMenu/index.js +2 -2
- package/dist/esm/ui/FloatingDragMenu/DragMenu.js +13 -3
- package/dist/esm/ui/FloatingDragMenu/DropdownMenu.js +50 -9
- package/dist/esm/ui/FloatingDragMenu/index.js +10 -6
- package/dist/esm/ui/consts.js +1 -0
- package/dist/esm/utils/create.js +21 -0
- package/dist/esm/utils/index.js +2 -1
- package/dist/types/commands/insert.d.ts +3 -3
- package/dist/types/plugin.d.ts +4 -0
- package/dist/types/pm-plugins/table-width.d.ts +2 -1
- package/dist/types/ui/FloatingDragMenu/DragMenu.d.ts +6 -1
- package/dist/types/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
- package/dist/types/ui/consts.d.ts +1 -0
- package/dist/types/utils/create.d.ts +6 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types-ts4.5/commands/insert.d.ts +3 -3
- package/dist/types-ts4.5/plugin.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +2 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DragMenu.d.ts +6 -1
- package/dist/types-ts4.5/ui/FloatingDragMenu/DropdownMenu.d.ts +8 -2
- package/dist/types-ts4.5/ui/consts.d.ts +1 -0
- package/dist/types-ts4.5/utils/create.d.ts +6 -0
- package/dist/types-ts4.5/utils/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/commands/insert.ts +35 -19
- package/src/plugin.tsx +32 -9
- package/src/pm-plugins/table-width.ts +71 -38
- package/src/ui/FloatingContextualMenu/index.tsx +2 -1
- package/src/ui/FloatingDragMenu/DragMenu.tsx +16 -1
- package/src/ui/FloatingDragMenu/DropdownMenu.tsx +94 -50
- package/src/ui/FloatingDragMenu/index.tsx +8 -3
- package/src/ui/consts.ts +1 -0
- package/src/utils/create.ts +32 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
export declare const createTableWithWidth: (isFullWidthModeEnabled?: boolean, getEditorFeatureFlags?: GetEditorFeatureFlags, createTableProps?: {
|
|
4
|
+
rowsCount?: number;
|
|
5
|
+
colsCount?: number;
|
|
6
|
+
}) => (schema: Schema) => import("prosemirror-model").Node;
|
|
@@ -10,3 +10,4 @@ export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
|
10
10
|
export { getMergedCellsPositions } from './table';
|
|
11
11
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
12
12
|
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells, } from './merged-cells';
|
|
13
|
+
export { createTableWithWidth } from './create';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "7.4.
|
|
3
|
+
"version": "7.4.9",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@atlaskit/adf-schema": "^35.5.2",
|
|
32
32
|
"@atlaskit/custom-steps": "^0.0.14",
|
|
33
|
-
"@atlaskit/editor-common": "^78.
|
|
33
|
+
"@atlaskit/editor-common": "^78.11.0",
|
|
34
34
|
"@atlaskit/editor-palette": "1.5.2",
|
|
35
35
|
"@atlaskit/editor-plugin-analytics": "^1.0.0",
|
|
36
36
|
"@atlaskit/editor-plugin-content-insertion": "^1.0.0",
|
package/src/commands/insert.ts
CHANGED
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
Command,
|
|
16
16
|
EditorCommand,
|
|
17
17
|
GetEditorContainerWidth,
|
|
18
|
+
GetEditorFeatureFlags,
|
|
18
19
|
} from '@atlaskit/editor-common/types';
|
|
19
20
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
20
21
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -24,7 +25,6 @@ import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
|
24
25
|
import {
|
|
25
26
|
addColumnAt as addColumnAtPMUtils,
|
|
26
27
|
addRowAt,
|
|
27
|
-
createTable as createTableNode,
|
|
28
28
|
findTable,
|
|
29
29
|
selectedRect,
|
|
30
30
|
} from '@atlaskit/editor-tables/utils';
|
|
@@ -33,7 +33,11 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
33
33
|
import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
|
|
34
34
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
35
35
|
import { rescaleColumns } from '../transforms/column-width';
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
checkIfHeaderRowEnabled,
|
|
38
|
+
copyPreviousRow,
|
|
39
|
+
createTableWithWidth,
|
|
40
|
+
} from '../utils';
|
|
37
41
|
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
38
42
|
|
|
39
43
|
function addColumnAtCustomStep(column: number) {
|
|
@@ -128,7 +132,6 @@ export const addColumnAfter =
|
|
|
128
132
|
return true;
|
|
129
133
|
};
|
|
130
134
|
|
|
131
|
-
// #region Commands
|
|
132
135
|
export const insertColumn =
|
|
133
136
|
(getEditorContainerWidth: GetEditorContainerWidth) =>
|
|
134
137
|
(column: number): Command =>
|
|
@@ -199,31 +202,44 @@ export const insertRow =
|
|
|
199
202
|
return true;
|
|
200
203
|
};
|
|
201
204
|
|
|
202
|
-
export const createTable =
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
export const createTable =
|
|
206
|
+
(
|
|
207
|
+
isFullWidthModeEnabled?: boolean,
|
|
208
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
209
|
+
): Command =>
|
|
210
|
+
(state, dispatch) => {
|
|
211
|
+
const table = createTableWithWidth(
|
|
212
|
+
isFullWidthModeEnabled,
|
|
213
|
+
getEditorFeatureFlags,
|
|
214
|
+
)(state.schema);
|
|
206
215
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
};
|
|
212
|
-
// #endregion
|
|
216
|
+
if (dispatch) {
|
|
217
|
+
dispatch(safeInsert(table)(state.tr).scrollIntoView());
|
|
218
|
+
}
|
|
219
|
+
return true;
|
|
220
|
+
};
|
|
213
221
|
|
|
214
222
|
export const insertTableWithSize =
|
|
215
|
-
(
|
|
223
|
+
(
|
|
224
|
+
isFullWidthModeEnabled?: boolean,
|
|
225
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
226
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
227
|
+
) =>
|
|
216
228
|
(
|
|
217
229
|
rowsCount: number,
|
|
218
230
|
colsCount: number,
|
|
219
231
|
inputMethod?: INPUT_METHOD.PICKER,
|
|
220
232
|
): EditorCommand => {
|
|
221
233
|
return ({ tr }) => {
|
|
222
|
-
const tableNode =
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
234
|
+
const tableNode = createTableWithWidth(
|
|
235
|
+
isFullWidthModeEnabled,
|
|
236
|
+
getEditorFeatureFlags,
|
|
237
|
+
{
|
|
238
|
+
rowsCount: rowsCount,
|
|
239
|
+
colsCount: colsCount,
|
|
240
|
+
},
|
|
241
|
+
)(tr.doc.type.schema);
|
|
242
|
+
|
|
227
243
|
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
228
244
|
if (inputMethod) {
|
|
229
245
|
editorAnalyticsAPI?.attachAnalyticsEvent({
|
package/src/plugin.tsx
CHANGED
|
@@ -39,7 +39,6 @@ import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
|
39
39
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
40
40
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
41
41
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
42
|
-
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
43
42
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
44
43
|
|
|
45
44
|
import { insertTableWithSize } from './commands/insert';
|
|
@@ -79,7 +78,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
|
79
78
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
80
79
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
81
80
|
import LayoutButton from './ui/LayoutButton';
|
|
82
|
-
import { isLayoutSupported } from './utils';
|
|
81
|
+
import { createTableWithWidth, isLayoutSupported } from './utils';
|
|
83
82
|
|
|
84
83
|
export interface TablePluginOptions {
|
|
85
84
|
tableOptions: PluginConfig;
|
|
@@ -106,6 +105,10 @@ export type TablePlugin = NextEditorPlugin<
|
|
|
106
105
|
actions: {
|
|
107
106
|
insertTable: InsertTableAction;
|
|
108
107
|
};
|
|
108
|
+
sharedState: {
|
|
109
|
+
isFullWidthModeEnabled: boolean;
|
|
110
|
+
wasFullWidthModeEnabled: boolean;
|
|
111
|
+
};
|
|
109
112
|
commands: {
|
|
110
113
|
insertTableWithSize: (
|
|
111
114
|
rowsCount: number,
|
|
@@ -140,13 +143,23 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
140
143
|
return {
|
|
141
144
|
name: 'table',
|
|
142
145
|
|
|
146
|
+
// Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
|
|
147
|
+
// to most up to date values - passing to createPluginState will not re-initialise the state
|
|
148
|
+
getSharedState: () => {
|
|
149
|
+
return {
|
|
150
|
+
isFullWidthModeEnabled: !!options?.fullWidthEnabled,
|
|
151
|
+
wasFullWidthModeEnabled: !!options?.wasFullWidthEnabled,
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
|
|
143
155
|
actions: {
|
|
144
156
|
insertTable:
|
|
145
157
|
(analyticsPayload): Command =>
|
|
146
158
|
(state, dispatch) => {
|
|
147
|
-
const node =
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
const node = createTableWithWidth(
|
|
160
|
+
options?.fullWidthEnabled,
|
|
161
|
+
options?.getEditorFeatureFlags,
|
|
162
|
+
)(state.schema);
|
|
150
163
|
|
|
151
164
|
return (
|
|
152
165
|
api?.contentInsertion?.actions?.insert({
|
|
@@ -162,8 +175,13 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
162
175
|
);
|
|
163
176
|
},
|
|
164
177
|
},
|
|
178
|
+
|
|
165
179
|
commands: {
|
|
166
|
-
insertTableWithSize: insertTableWithSize(
|
|
180
|
+
insertTableWithSize: insertTableWithSize(
|
|
181
|
+
options?.fullWidthEnabled,
|
|
182
|
+
options?.getEditorFeatureFlags,
|
|
183
|
+
api?.analytics?.actions,
|
|
184
|
+
),
|
|
167
185
|
},
|
|
168
186
|
|
|
169
187
|
nodes() {
|
|
@@ -321,6 +339,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
321
339
|
dispatch,
|
|
322
340
|
dispatchAnalyticsEvent,
|
|
323
341
|
options?.fullWidthEnabled ?? false,
|
|
342
|
+
options?.getEditorFeatureFlags,
|
|
324
343
|
)
|
|
325
344
|
: undefined,
|
|
326
345
|
},
|
|
@@ -558,10 +577,14 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
558
577
|
keyshortcut: tooltip(toggleTable),
|
|
559
578
|
icon: () => <IconTable />,
|
|
560
579
|
action(insert, state) {
|
|
580
|
+
// see comment on tablesPlugin.getSharedState on usage
|
|
581
|
+
const tableState = api?.table?.sharedState.currentState();
|
|
582
|
+
|
|
561
583
|
const tr = insert(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
584
|
+
createTableWithWidth(
|
|
585
|
+
tableState?.isFullWidthModeEnabled,
|
|
586
|
+
options?.getEditorFeatureFlags,
|
|
587
|
+
)(state.schema),
|
|
565
588
|
);
|
|
566
589
|
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
567
590
|
action: ACTION.INSERTED,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
15
15
|
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
16
16
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
17
|
+
import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
|
|
17
18
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
18
19
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
19
20
|
import {
|
|
@@ -23,6 +24,8 @@ import {
|
|
|
23
24
|
} from '@atlaskit/editor-shared-styles';
|
|
24
25
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
25
26
|
|
|
27
|
+
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
28
|
+
|
|
26
29
|
type __ReplaceStep = ReplaceStep & {
|
|
27
30
|
// Properties `to` and `from` are private attributes of ReplaceStep.
|
|
28
31
|
to: number;
|
|
@@ -41,8 +44,9 @@ const createPlugin = (
|
|
|
41
44
|
dispatch: Dispatch,
|
|
42
45
|
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
43
46
|
fullWidthEnabled: boolean,
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
getEditorFeatureFlags?: GetEditorFeatureFlags,
|
|
48
|
+
) => {
|
|
49
|
+
return new SafePlugin({
|
|
46
50
|
key: pluginKey,
|
|
47
51
|
state: {
|
|
48
52
|
init() {
|
|
@@ -83,6 +87,7 @@ const createPlugin = (
|
|
|
83
87
|
},
|
|
84
88
|
});
|
|
85
89
|
}
|
|
90
|
+
|
|
86
91
|
// When document first load in Confluence, initially it is an empty document
|
|
87
92
|
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
88
93
|
// what we need to do is to add width attr to all tables in the real document
|
|
@@ -114,12 +119,24 @@ const createPlugin = (
|
|
|
114
119
|
return hasStepReplacingEntireDocument;
|
|
115
120
|
});
|
|
116
121
|
|
|
117
|
-
|
|
122
|
+
const referentialityTr = transactions.find((tr) =>
|
|
123
|
+
tr.getMeta('referentialityTableInserted'),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const shouldPatchTable =
|
|
127
|
+
fullWidthEnabled &&
|
|
128
|
+
getEditorFeatureFlags &&
|
|
129
|
+
getEditorFeatureFlags()['tablePreserveWidth'];
|
|
130
|
+
|
|
131
|
+
if (
|
|
132
|
+
!isReplaceDocumentOperation &&
|
|
133
|
+
(!shouldPatchTable || !referentialityTr)
|
|
134
|
+
) {
|
|
118
135
|
return null;
|
|
119
136
|
}
|
|
120
137
|
|
|
121
|
-
const tr = newState.tr;
|
|
122
138
|
const { table } = newState.schema.nodes;
|
|
139
|
+
const tr = newState.tr;
|
|
123
140
|
|
|
124
141
|
/**
|
|
125
142
|
* Select table event
|
|
@@ -138,47 +155,63 @@ const createPlugin = (
|
|
|
138
155
|
});
|
|
139
156
|
}
|
|
140
157
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
if (isReplaceDocumentOperation) {
|
|
159
|
+
newState.doc.forEach((node, offset) => {
|
|
160
|
+
if (node.type === table) {
|
|
161
|
+
const width = node.attrs.width;
|
|
162
|
+
const layout = node.attrs.layout;
|
|
163
|
+
|
|
164
|
+
if (!width && layout) {
|
|
165
|
+
let tableWidthCal;
|
|
166
|
+
|
|
167
|
+
if (fullWidthEnabled) {
|
|
168
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
169
|
+
} else {
|
|
170
|
+
switch (layout) {
|
|
171
|
+
case 'wide':
|
|
172
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
173
|
+
break;
|
|
174
|
+
case 'full-width':
|
|
175
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
176
|
+
break;
|
|
177
|
+
// when in fix-width appearance, no need to assign value to table width attr
|
|
178
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
179
|
+
default:
|
|
180
|
+
tableWidthCal = akEditorDefaultLayoutWidth;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
164
183
|
}
|
|
165
|
-
}
|
|
166
184
|
|
|
167
|
-
|
|
185
|
+
const { width, ...rest } = node.attrs;
|
|
168
186
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
187
|
+
if (tableWidthCal) {
|
|
188
|
+
tr.step(
|
|
189
|
+
new SetAttrsStep(offset, {
|
|
190
|
+
width: tableWidthCal,
|
|
191
|
+
...rest,
|
|
192
|
+
}),
|
|
193
|
+
);
|
|
194
|
+
}
|
|
176
195
|
}
|
|
177
196
|
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (referentialityTr) {
|
|
201
|
+
referentialityTr.steps.forEach((step) => {
|
|
202
|
+
step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
203
|
+
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
204
|
+
if (node.type === table && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
205
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
180
212
|
return tr;
|
|
181
213
|
},
|
|
182
214
|
});
|
|
215
|
+
};
|
|
183
216
|
|
|
184
217
|
export { createPlugin };
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
contextualMenuDropdownWidth,
|
|
26
26
|
contextualMenuDropdownWidthDnD,
|
|
27
27
|
contextualMenuTriggerSize,
|
|
28
|
+
tablePopupMenuFitHeight,
|
|
28
29
|
} from '../consts';
|
|
29
30
|
|
|
30
31
|
import ContextualMenu from './ContextualMenu';
|
|
@@ -91,7 +92,7 @@ const FloatingContextualMenu = ({
|
|
|
91
92
|
mountTo={mountPoint}
|
|
92
93
|
boundariesElement={boundariesElement}
|
|
93
94
|
scrollableElement={scrollableElement}
|
|
94
|
-
fitHeight={
|
|
95
|
+
fitHeight={tablePopupMenuFitHeight}
|
|
95
96
|
fitWidth={
|
|
96
97
|
isDragAndDropEnabled
|
|
97
98
|
? contextualMenuDropdownWidthDnD
|
|
@@ -96,6 +96,11 @@ type DragMenuProps = {
|
|
|
96
96
|
pluginConfig?: PluginConfig;
|
|
97
97
|
getEditorContainerWidth: GetEditorContainerWidth;
|
|
98
98
|
editorAnalyticsAPI?: EditorAnalyticsAPI;
|
|
99
|
+
fitWidth?: number;
|
|
100
|
+
fitHeight?: number;
|
|
101
|
+
mountPoint?: HTMLElement;
|
|
102
|
+
boundariesElement?: HTMLElement;
|
|
103
|
+
scrollableElement?: HTMLElement;
|
|
99
104
|
};
|
|
100
105
|
|
|
101
106
|
type PluralOptionType = 'noOfCols' | 'noOfRows' | 'noOfCells' | null;
|
|
@@ -269,6 +274,11 @@ export const DragMenu = React.memo(
|
|
|
269
274
|
editorAnalyticsAPI,
|
|
270
275
|
pluginConfig,
|
|
271
276
|
intl: { formatMessage },
|
|
277
|
+
fitHeight,
|
|
278
|
+
fitWidth,
|
|
279
|
+
mountPoint,
|
|
280
|
+
scrollableElement,
|
|
281
|
+
boundariesElement,
|
|
272
282
|
}: DragMenuProps & WrappedComponentProps) => {
|
|
273
283
|
const { state, dispatch } = editorView;
|
|
274
284
|
const { selection } = state;
|
|
@@ -627,12 +637,17 @@ export const DragMenu = React.memo(
|
|
|
627
637
|
<DropdownMenu
|
|
628
638
|
disableKeyboardHandling={isSubmenuOpen}
|
|
629
639
|
section={{ hasSeparator: true }}
|
|
630
|
-
target={target as HTMLElement | undefined}
|
|
631
640
|
items={menuItems}
|
|
632
641
|
onItemActivated={handleMenuItemActivated}
|
|
633
642
|
onMouseEnter={handleItemMouseEnter}
|
|
634
643
|
onMouseLeave={handleItemMouseLeave}
|
|
635
644
|
handleClose={closeMenu}
|
|
645
|
+
fitHeight={fitHeight}
|
|
646
|
+
fitWidth={fitWidth}
|
|
647
|
+
direction={direction}
|
|
648
|
+
mountPoint={mountPoint}
|
|
649
|
+
boundariesElement={boundariesElement}
|
|
650
|
+
scrollableElement={scrollableElement}
|
|
636
651
|
/>
|
|
637
652
|
);
|
|
638
653
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
import React, { useState } from 'react';
|
|
2
3
|
|
|
3
|
-
import { DropList } from '@atlaskit/editor-common/ui';
|
|
4
|
+
import { DropList, Popup } from '@atlaskit/editor-common/ui';
|
|
4
5
|
import type { MenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
5
6
|
import {
|
|
6
7
|
ArrowKeyNavigationProvider,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
DropdownMenuItem,
|
|
9
10
|
} from '@atlaskit/editor-common/ui-menu';
|
|
10
11
|
import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
12
|
+
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
11
13
|
import { MenuGroup, Section } from '@atlaskit/menu';
|
|
12
14
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
15
|
|
|
@@ -17,7 +19,6 @@ const DropListWithOutsideListeners =
|
|
|
17
19
|
withReactEditorViewOuterListeners(DropList);
|
|
18
20
|
|
|
19
21
|
type DropdownMenuProps = {
|
|
20
|
-
target?: HTMLElement;
|
|
21
22
|
items: Array<{
|
|
22
23
|
items: MenuItem[];
|
|
23
24
|
}>;
|
|
@@ -34,10 +35,16 @@ type DropdownMenuProps = {
|
|
|
34
35
|
handleClose: (focusTarget: 'editor' | 'handle') => void;
|
|
35
36
|
onMouseEnter: (attrs: { item: MenuItem }) => void;
|
|
36
37
|
onMouseLeave: (attrs: { item: MenuItem }) => void;
|
|
38
|
+
fitWidth?: number;
|
|
39
|
+
fitHeight?: number;
|
|
40
|
+
direction?: string;
|
|
41
|
+
offset?: Array<number>;
|
|
42
|
+
mountPoint?: HTMLElement;
|
|
43
|
+
boundariesElement?: HTMLElement;
|
|
44
|
+
scrollableElement?: HTMLElement;
|
|
37
45
|
};
|
|
38
46
|
|
|
39
47
|
export const DropdownMenu = ({
|
|
40
|
-
target,
|
|
41
48
|
items,
|
|
42
49
|
section,
|
|
43
50
|
disableKeyboardHandling,
|
|
@@ -45,13 +52,24 @@ export const DropdownMenu = ({
|
|
|
45
52
|
handleClose,
|
|
46
53
|
onMouseEnter,
|
|
47
54
|
onMouseLeave,
|
|
55
|
+
fitWidth,
|
|
56
|
+
fitHeight,
|
|
57
|
+
direction,
|
|
58
|
+
mountPoint,
|
|
59
|
+
boundariesElement,
|
|
60
|
+
scrollableElement,
|
|
48
61
|
}: DropdownMenuProps) => {
|
|
62
|
+
const [popupPlacement, setPopupPlacement] = useState(['bottom', 'left']);
|
|
63
|
+
const [targetRefDiv, setTargetRefDiv] = useState<HTMLDivElement | null>(null);
|
|
64
|
+
const handleRef = (ref: HTMLDivElement | null) => {
|
|
65
|
+
setTargetRefDiv(ref);
|
|
66
|
+
};
|
|
49
67
|
const innerMenu = () => {
|
|
50
68
|
return (
|
|
51
69
|
<DropListWithOutsideListeners
|
|
52
70
|
isOpen
|
|
53
71
|
shouldFitContainer
|
|
54
|
-
position={
|
|
72
|
+
position={popupPlacement.join(' ')}
|
|
55
73
|
handleClickOutside={() => handleClose('editor')}
|
|
56
74
|
handleEscapeKeydown={() => {
|
|
57
75
|
if (!disableKeyboardHandling) {
|
|
@@ -64,7 +82,7 @@ export const DropdownMenu = ({
|
|
|
64
82
|
e.stopPropagation();
|
|
65
83
|
}
|
|
66
84
|
}}
|
|
67
|
-
targetRef={
|
|
85
|
+
targetRef={targetRefDiv}
|
|
68
86
|
>
|
|
69
87
|
<div style={{ height: 0, minWidth: dragMenuDropdownWidth }} />
|
|
70
88
|
<MenuGroup role="menu">
|
|
@@ -95,56 +113,82 @@ export const DropdownMenu = ({
|
|
|
95
113
|
return innerMenu();
|
|
96
114
|
}
|
|
97
115
|
|
|
116
|
+
// more offsets calculation as offsets depend on the direction and updated placement here
|
|
117
|
+
let offsetY =
|
|
118
|
+
direction === 'row' ? (popupPlacement[0] === 'bottom' ? -8 : -34) : 0;
|
|
119
|
+
let offsetX =
|
|
120
|
+
direction === 'column' ? (popupPlacement[1] === 'left' ? 0 : -7) : 0;
|
|
121
|
+
|
|
98
122
|
return (
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
<div className="drag-dropdown-menu-wrapper">
|
|
124
|
+
<div className="drag-dropdown-menu-popup-ref" ref={handleRef}></div>
|
|
125
|
+
<Popup
|
|
126
|
+
target={targetRefDiv as HTMLElement}
|
|
127
|
+
mountTo={mountPoint}
|
|
128
|
+
boundariesElement={boundariesElement}
|
|
129
|
+
scrollableElement={scrollableElement}
|
|
130
|
+
onPlacementChanged={(placement: [string, string]) => {
|
|
131
|
+
setPopupPlacement(placement);
|
|
132
|
+
}}
|
|
133
|
+
fitHeight={fitHeight}
|
|
134
|
+
fitWidth={fitWidth}
|
|
135
|
+
zIndex={akEditorFloatingPanelZIndex}
|
|
136
|
+
offset={[offsetX, offsetY]}
|
|
137
|
+
allowOutOfBounds // required as this popup is child of a parent popup, should be allowed to be out of bound of the parent popup, otherwise horizontal offset is not right
|
|
138
|
+
>
|
|
139
|
+
<ArrowKeyNavigationProvider
|
|
140
|
+
closeOnTab
|
|
141
|
+
type={ArrowKeyNavigationType.MENU}
|
|
142
|
+
onSelection={(index) => {
|
|
143
|
+
const results = items.flatMap((item) =>
|
|
144
|
+
'items' in item ? item.items : item,
|
|
145
|
+
);
|
|
106
146
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
147
|
+
// onSelection is called when any focusable element is 'activated'
|
|
148
|
+
// this is an issue as some menu items have toggles, which cause the index value
|
|
149
|
+
// in the callback to be outside of array length.
|
|
150
|
+
// The logic below normalises the index value based on the number
|
|
151
|
+
// of menu items with 2 focusable elements, and adjusts the index to ensure
|
|
152
|
+
// the correct menu item is sent in onItemActivated callback
|
|
153
|
+
if (
|
|
154
|
+
getBooleanFF(
|
|
155
|
+
'platform.editor.table.new-cell-context-menu-styling',
|
|
156
|
+
)
|
|
157
|
+
) {
|
|
158
|
+
const keys = ['row_numbers', 'header_row', 'header_column'];
|
|
159
|
+
let doubleItemCount = 0;
|
|
118
160
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
161
|
+
const firstIndex = results.findIndex((value) =>
|
|
162
|
+
keys.includes(value.key!),
|
|
163
|
+
);
|
|
122
164
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
if (firstIndex === -1 || index <= firstIndex) {
|
|
166
|
+
onItemActivated && onItemActivated({ item: results[index] });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
127
169
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
170
|
+
for (let i = firstIndex; i < results.length; i += 1) {
|
|
171
|
+
if (keys.includes(results[i].key!)) {
|
|
172
|
+
doubleItemCount += 1;
|
|
173
|
+
}
|
|
174
|
+
if (firstIndex % 2 === 0 && index - doubleItemCount === i) {
|
|
175
|
+
onItemActivated && onItemActivated({ item: results[i] });
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
136
178
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
179
|
+
if (firstIndex % 2 === 1 && index - doubleItemCount === i) {
|
|
180
|
+
onItemActivated && onItemActivated({ item: results[i] });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
onItemActivated && onItemActivated({ item: results[index] });
|
|
140
186
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
>
|
|
147
|
-
{innerMenu()}
|
|
148
|
-
</ArrowKeyNavigationProvider>
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
{innerMenu()}
|
|
190
|
+
</ArrowKeyNavigationProvider>
|
|
191
|
+
</Popup>
|
|
192
|
+
</div>
|
|
149
193
|
);
|
|
150
194
|
};
|