@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
package/dist/es2019/plugin.js
CHANGED
|
@@ -9,7 +9,6 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
9
9
|
import { browser } from '@atlaskit/editor-common/utils';
|
|
10
10
|
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
11
11
|
import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
|
|
12
|
-
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
13
12
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
13
|
import { insertTableWithSize } from './commands/insert';
|
|
15
14
|
import { pluginConfig } from './create-plugin-config';
|
|
@@ -34,7 +33,7 @@ import FloatingDeleteButton from './ui/FloatingDeleteButton';
|
|
|
34
33
|
import FloatingDragMenu from './ui/FloatingDragMenu';
|
|
35
34
|
import FloatingInsertButton from './ui/FloatingInsertButton';
|
|
36
35
|
import LayoutButton from './ui/LayoutButton';
|
|
37
|
-
import { isLayoutSupported } from './utils';
|
|
36
|
+
import { createTableWithWidth, isLayoutSupported } from './utils';
|
|
38
37
|
const defaultGetEditorFeatureFlags = () => ({});
|
|
39
38
|
/**
|
|
40
39
|
* Table plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
@@ -58,12 +57,18 @@ const tablesPlugin = ({
|
|
|
58
57
|
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
59
58
|
return {
|
|
60
59
|
name: 'table',
|
|
60
|
+
// Use getSharedState to store fullWidthEnabled and wasFullWidthModeEnabled to guarantee access
|
|
61
|
+
// to most up to date values - passing to createPluginState will not re-initialise the state
|
|
62
|
+
getSharedState: () => {
|
|
63
|
+
return {
|
|
64
|
+
isFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.fullWidthEnabled),
|
|
65
|
+
wasFullWidthModeEnabled: !!(options !== null && options !== void 0 && options.wasFullWidthEnabled)
|
|
66
|
+
};
|
|
67
|
+
},
|
|
61
68
|
actions: {
|
|
62
69
|
insertTable: analyticsPayload => (state, dispatch) => {
|
|
63
70
|
var _api$contentInsertion, _api$contentInsertion2, _api$contentInsertion3;
|
|
64
|
-
const node =
|
|
65
|
-
schema: state.schema
|
|
66
|
-
});
|
|
71
|
+
const node = createTableWithWidth(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema);
|
|
67
72
|
return (_api$contentInsertion = api === null || api === void 0 ? void 0 : (_api$contentInsertion2 = api.contentInsertion) === null || _api$contentInsertion2 === void 0 ? void 0 : (_api$contentInsertion3 = _api$contentInsertion2.actions) === null || _api$contentInsertion3 === void 0 ? void 0 : _api$contentInsertion3.insert({
|
|
68
73
|
state,
|
|
69
74
|
dispatch,
|
|
@@ -76,7 +81,7 @@ const tablesPlugin = ({
|
|
|
76
81
|
}
|
|
77
82
|
},
|
|
78
83
|
commands: {
|
|
79
|
-
insertTableWithSize: insertTableWithSize(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
84
|
+
insertTableWithSize: insertTableWithSize(options === null || options === void 0 ? void 0 : options.fullWidthEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
|
|
80
85
|
},
|
|
81
86
|
nodes() {
|
|
82
87
|
const tableNode = options !== null && options !== void 0 && options.tableResizingEnabled ? tableWithCustomWidth : table;
|
|
@@ -198,7 +203,7 @@ const tablesPlugin = ({
|
|
|
198
203
|
dispatch
|
|
199
204
|
}) => {
|
|
200
205
|
var _options$fullWidthEna;
|
|
201
|
-
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
|
|
206
|
+
return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags) : undefined;
|
|
202
207
|
}
|
|
203
208
|
},
|
|
204
209
|
// TODO: should be deprecated and eventually replaced with 'tableAnalyticsPlugin'
|
|
@@ -386,9 +391,10 @@ const tablesPlugin = ({
|
|
|
386
391
|
keyshortcut: tooltip(toggleTable),
|
|
387
392
|
icon: () => /*#__PURE__*/React.createElement(IconTable, null),
|
|
388
393
|
action(insert, state) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
var _api$table;
|
|
395
|
+
// see comment on tablesPlugin.getSharedState on usage
|
|
396
|
+
const tableState = api === null || api === void 0 ? void 0 : (_api$table = api.table) === null || _api$table === void 0 ? void 0 : _api$table.sharedState.currentState();
|
|
397
|
+
const tr = insert(createTableWithWidth(tableState === null || tableState === void 0 ? void 0 : tableState.isFullWidthModeEnabled, options === null || options === void 0 ? void 0 : options.getEditorFeatureFlags)(state.schema));
|
|
392
398
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
|
|
393
399
|
action: ACTION.INSERTED,
|
|
394
400
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -11,130 +11,149 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
11
11
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
12
12
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
13
13
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
14
|
+
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
14
15
|
export const pluginKey = new PluginKey('tableWidthPlugin');
|
|
15
|
-
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
apply(tr, pluginState) {
|
|
24
|
-
const meta = tr.getMeta(pluginKey);
|
|
25
|
-
if (meta && meta.resizing !== pluginState.resizing) {
|
|
26
|
-
const newState = {
|
|
27
|
-
resizing: meta.resizing
|
|
16
|
+
const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled, getEditorFeatureFlags) => {
|
|
17
|
+
return new SafePlugin({
|
|
18
|
+
key: pluginKey,
|
|
19
|
+
state: {
|
|
20
|
+
init() {
|
|
21
|
+
return {
|
|
22
|
+
resizing: false
|
|
28
23
|
};
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
},
|
|
25
|
+
apply(tr, pluginState) {
|
|
26
|
+
const meta = tr.getMeta(pluginKey);
|
|
27
|
+
if (meta && meta.resizing !== pluginState.resizing) {
|
|
28
|
+
const newState = {
|
|
29
|
+
resizing: meta.resizing
|
|
30
|
+
};
|
|
31
|
+
dispatch(pluginKey, newState);
|
|
32
|
+
return newState;
|
|
33
|
+
}
|
|
34
|
+
return pluginState;
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const selectedTableOldState = findTable(oldState.selection);
|
|
38
|
-
const selectedTableNewState = findTable(newState.selection);
|
|
36
|
+
},
|
|
37
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
38
|
+
// do not fire select table analytics events when a table is being created or deleted
|
|
39
|
+
const selectedTableOldState = findTable(oldState.selection);
|
|
40
|
+
const selectedTableNewState = findTable(newState.selection);
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
// When document first load in Confluence, initially it is an empty document
|
|
57
|
-
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
58
|
-
// what we need to do is to add width attr to all tables in the real document
|
|
59
|
-
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
60
|
-
const isReplaceDocumentOperation = transactions.some(tr => {
|
|
61
|
-
if (tr.getMeta('replaceDocument')) {
|
|
62
|
-
return true;
|
|
42
|
+
/**
|
|
43
|
+
* Select table event
|
|
44
|
+
* condition: 1
|
|
45
|
+
* When users selection changes to table
|
|
46
|
+
*/
|
|
47
|
+
if (!selectedTableOldState && selectedTableNewState) {
|
|
48
|
+
dispatchAnalyticsEvent({
|
|
49
|
+
action: ACTION.SELECTED,
|
|
50
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
51
|
+
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
52
|
+
eventType: EVENT_TYPE.TRACK,
|
|
53
|
+
attributes: {
|
|
54
|
+
localId: selectedTableNewState.node.attrs.localId || ''
|
|
55
|
+
}
|
|
56
|
+
});
|
|
63
57
|
}
|
|
64
|
-
const hasStepReplacingEntireDocument = tr.steps.some(step => {
|
|
65
|
-
if (!(step instanceof ReplaceStep)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
const isStepReplacingFromDocStart = step.from === 0;
|
|
69
|
-
const isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
|
|
70
|
-
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
});
|
|
75
|
-
return hasStepReplacingEntireDocument;
|
|
76
|
-
});
|
|
77
|
-
if (!isReplaceDocumentOperation) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const tr = newState.tr;
|
|
81
|
-
const {
|
|
82
|
-
table
|
|
83
|
-
} = newState.schema.nodes;
|
|
84
58
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
action: ACTION.SELECTED,
|
|
93
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
94
|
-
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
95
|
-
eventType: EVENT_TYPE.TRACK,
|
|
96
|
-
attributes: {
|
|
97
|
-
localId: selectedTableOldState.node.attrs.localId || ''
|
|
59
|
+
// When document first load in Confluence, initially it is an empty document
|
|
60
|
+
// and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
|
|
61
|
+
// what we need to do is to add width attr to all tables in the real document
|
|
62
|
+
// isReplaceDocumentOperation is checking if the transaction is the one that replace the empty document with the real document
|
|
63
|
+
const isReplaceDocumentOperation = transactions.some(tr => {
|
|
64
|
+
if (tr.getMeta('replaceDocument')) {
|
|
65
|
+
return true;
|
|
98
66
|
}
|
|
67
|
+
const hasStepReplacingEntireDocument = tr.steps.some(step => {
|
|
68
|
+
if (!(step instanceof ReplaceStep)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
const isStepReplacingFromDocStart = step.from === 0;
|
|
72
|
+
const isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
|
|
73
|
+
if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
return hasStepReplacingEntireDocument;
|
|
99
79
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
80
|
+
const referentialityTr = transactions.find(tr => tr.getMeta('referentialityTableInserted'));
|
|
81
|
+
const shouldPatchTable = fullWidthEnabled && getEditorFeatureFlags && getEditorFeatureFlags()['tablePreserveWidth'];
|
|
82
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTable || !referentialityTr)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const {
|
|
86
|
+
table
|
|
87
|
+
} = newState.schema.nodes;
|
|
88
|
+
const tr = newState.tr;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Select table event
|
|
92
|
+
* condition: 2
|
|
93
|
+
* Users selection defaults to table, if first node
|
|
94
|
+
*/
|
|
95
|
+
if (selectedTableOldState) {
|
|
96
|
+
dispatchAnalyticsEvent({
|
|
97
|
+
action: ACTION.SELECTED,
|
|
98
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
99
|
+
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
100
|
+
eventType: EVENT_TYPE.TRACK,
|
|
101
|
+
attributes: {
|
|
102
|
+
localId: selectedTableOldState.node.attrs.localId || ''
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (isReplaceDocumentOperation) {
|
|
107
|
+
newState.doc.forEach((node, offset) => {
|
|
108
|
+
if (node.type === table) {
|
|
109
|
+
const width = node.attrs.width;
|
|
110
|
+
const layout = node.attrs.layout;
|
|
111
|
+
if (!width && layout) {
|
|
112
|
+
let tableWidthCal;
|
|
113
|
+
if (fullWidthEnabled) {
|
|
115
114
|
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
} else {
|
|
116
|
+
switch (layout) {
|
|
117
|
+
case 'wide':
|
|
118
|
+
tableWidthCal = akEditorWideLayoutWidth;
|
|
119
|
+
break;
|
|
120
|
+
case 'full-width':
|
|
121
|
+
tableWidthCal = akEditorFullWidthLayoutWidth;
|
|
122
|
+
break;
|
|
123
|
+
// when in fix-width appearance, no need to assign value to table width attr
|
|
124
|
+
// as when table is created, width attr is null by default, table rendered using layout attr
|
|
125
|
+
default:
|
|
126
|
+
tableWidthCal = akEditorDefaultLayoutWidth;
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const {
|
|
131
|
+
width,
|
|
132
|
+
...rest
|
|
133
|
+
} = node.attrs;
|
|
134
|
+
if (tableWidthCal) {
|
|
135
|
+
tr.step(new SetAttrsStep(offset, {
|
|
136
|
+
width: tableWidthCal,
|
|
137
|
+
...rest
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
122
140
|
}
|
|
123
141
|
}
|
|
124
|
-
|
|
125
|
-
width,
|
|
126
|
-
...rest
|
|
127
|
-
} = node.attrs;
|
|
128
|
-
if (tableWidthCal) {
|
|
129
|
-
tr.step(new SetAttrsStep(offset, {
|
|
130
|
-
width: tableWidthCal,
|
|
131
|
-
...rest
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
142
|
+
});
|
|
135
143
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
144
|
+
if (referentialityTr) {
|
|
145
|
+
referentialityTr.steps.forEach(step => {
|
|
146
|
+
step.getMap().forEach((oldStart, oldEnd, newStart, newEnd) => {
|
|
147
|
+
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
148
|
+
if (node.type === table && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
149
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return tr;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
};
|
|
140
159
|
export { createPlugin };
|
|
@@ -5,7 +5,7 @@ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
|
5
5
|
import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
import { findCellRectClosestToPos, getSelectionRect, isSelectionType } from '@atlaskit/editor-tables/utils';
|
|
7
7
|
import { getPluginState } from '../../pm-plugins/plugin-factory';
|
|
8
|
-
import { contextualMenuDropdownWidth, contextualMenuDropdownWidthDnD, contextualMenuTriggerSize } from '../consts';
|
|
8
|
+
import { contextualMenuDropdownWidth, contextualMenuDropdownWidthDnD, contextualMenuTriggerSize, tablePopupMenuFitHeight } from '../consts';
|
|
9
9
|
import ContextualMenu from './ContextualMenu';
|
|
10
10
|
import { tablePopupStyles } from './styles';
|
|
11
11
|
const FloatingContextualMenu = ({
|
|
@@ -46,7 +46,7 @@ const FloatingContextualMenu = ({
|
|
|
46
46
|
mountTo: mountPoint,
|
|
47
47
|
boundariesElement: boundariesElement,
|
|
48
48
|
scrollableElement: scrollableElement,
|
|
49
|
-
fitHeight:
|
|
49
|
+
fitHeight: tablePopupMenuFitHeight,
|
|
50
50
|
fitWidth: isDragAndDropEnabled ? contextualMenuDropdownWidthDnD : contextualMenuDropdownWidth
|
|
51
51
|
// z-index value below is to ensure that this menu is above other floating menu
|
|
52
52
|
// in table, but below floating dialogs like typeaheads, pickers, etc.
|
|
@@ -170,7 +170,12 @@ export const DragMenu = /*#__PURE__*/React.memo(({
|
|
|
170
170
|
pluginConfig,
|
|
171
171
|
intl: {
|
|
172
172
|
formatMessage
|
|
173
|
-
}
|
|
173
|
+
},
|
|
174
|
+
fitHeight,
|
|
175
|
+
fitWidth,
|
|
176
|
+
mountPoint,
|
|
177
|
+
scrollableElement,
|
|
178
|
+
boundariesElement
|
|
174
179
|
}) => {
|
|
175
180
|
var _pluginConfig$allowBa;
|
|
176
181
|
const {
|
|
@@ -457,12 +462,17 @@ export const DragMenu = /*#__PURE__*/React.memo(({
|
|
|
457
462
|
section: {
|
|
458
463
|
hasSeparator: true
|
|
459
464
|
},
|
|
460
|
-
target: target,
|
|
461
465
|
items: menuItems,
|
|
462
466
|
onItemActivated: handleMenuItemActivated,
|
|
463
467
|
onMouseEnter: handleItemMouseEnter,
|
|
464
468
|
onMouseLeave: handleItemMouseLeave,
|
|
465
|
-
handleClose: closeMenu
|
|
469
|
+
handleClose: closeMenu,
|
|
470
|
+
fitHeight: fitHeight,
|
|
471
|
+
fitWidth: fitWidth,
|
|
472
|
+
direction: direction,
|
|
473
|
+
mountPoint: mountPoint,
|
|
474
|
+
boundariesElement: boundariesElement,
|
|
475
|
+
scrollableElement: scrollableElement
|
|
466
476
|
});
|
|
467
477
|
});
|
|
468
478
|
export default injectIntl(DragMenu);
|
|
@@ -1,26 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/* eslint-disable @atlaskit/design-system/prefer-primitives */
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { DropList, Popup } from '@atlaskit/editor-common/ui';
|
|
3
4
|
import { ArrowKeyNavigationProvider, ArrowKeyNavigationType, DropdownMenuItem } from '@atlaskit/editor-common/ui-menu';
|
|
4
5
|
import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-react';
|
|
6
|
+
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
5
7
|
import { MenuGroup, Section } from '@atlaskit/menu';
|
|
6
8
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
9
|
import { dragMenuDropdownWidth } from '../consts';
|
|
8
10
|
const DropListWithOutsideListeners = withReactEditorViewOuterListeners(DropList);
|
|
9
11
|
export const DropdownMenu = ({
|
|
10
|
-
target,
|
|
11
12
|
items,
|
|
12
13
|
section,
|
|
13
14
|
disableKeyboardHandling,
|
|
14
15
|
onItemActivated,
|
|
15
16
|
handleClose,
|
|
16
17
|
onMouseEnter,
|
|
17
|
-
onMouseLeave
|
|
18
|
+
onMouseLeave,
|
|
19
|
+
fitWidth,
|
|
20
|
+
fitHeight,
|
|
21
|
+
direction,
|
|
22
|
+
mountPoint,
|
|
23
|
+
boundariesElement,
|
|
24
|
+
scrollableElement
|
|
18
25
|
}) => {
|
|
26
|
+
const [popupPlacement, setPopupPlacement] = useState(['bottom', 'left']);
|
|
27
|
+
const [targetRefDiv, setTargetRefDiv] = useState(null);
|
|
28
|
+
const handleRef = ref => {
|
|
29
|
+
setTargetRefDiv(ref);
|
|
30
|
+
};
|
|
19
31
|
const innerMenu = () => {
|
|
20
32
|
return /*#__PURE__*/React.createElement(DropListWithOutsideListeners, {
|
|
21
33
|
isOpen: true,
|
|
22
34
|
shouldFitContainer: true,
|
|
23
|
-
position:
|
|
35
|
+
position: popupPlacement.join(' '),
|
|
24
36
|
handleClickOutside: () => handleClose('editor'),
|
|
25
37
|
handleEscapeKeydown: () => {
|
|
26
38
|
if (!disableKeyboardHandling) {
|
|
@@ -33,7 +45,7 @@ export const DropdownMenu = ({
|
|
|
33
45
|
e.stopPropagation();
|
|
34
46
|
}
|
|
35
47
|
},
|
|
36
|
-
targetRef:
|
|
48
|
+
targetRef: targetRefDiv
|
|
37
49
|
}, /*#__PURE__*/React.createElement("div", {
|
|
38
50
|
style: {
|
|
39
51
|
height: 0,
|
|
@@ -60,7 +72,29 @@ export const DropdownMenu = ({
|
|
|
60
72
|
if (disableKeyboardHandling) {
|
|
61
73
|
return innerMenu();
|
|
62
74
|
}
|
|
63
|
-
|
|
75
|
+
|
|
76
|
+
// more offsets calculation as offsets depend on the direction and updated placement here
|
|
77
|
+
let offsetY = direction === 'row' ? popupPlacement[0] === 'bottom' ? -8 : -34 : 0;
|
|
78
|
+
let offsetX = direction === 'column' ? popupPlacement[1] === 'left' ? 0 : -7 : 0;
|
|
79
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
80
|
+
className: "drag-dropdown-menu-wrapper"
|
|
81
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: "drag-dropdown-menu-popup-ref",
|
|
83
|
+
ref: handleRef
|
|
84
|
+
}), /*#__PURE__*/React.createElement(Popup, {
|
|
85
|
+
target: targetRefDiv,
|
|
86
|
+
mountTo: mountPoint,
|
|
87
|
+
boundariesElement: boundariesElement,
|
|
88
|
+
scrollableElement: scrollableElement,
|
|
89
|
+
onPlacementChanged: placement => {
|
|
90
|
+
setPopupPlacement(placement);
|
|
91
|
+
},
|
|
92
|
+
fitHeight: fitHeight,
|
|
93
|
+
fitWidth: fitWidth,
|
|
94
|
+
zIndex: akEditorFloatingPanelZIndex,
|
|
95
|
+
offset: [offsetX, offsetY],
|
|
96
|
+
allowOutOfBounds: true // 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
|
|
97
|
+
}, /*#__PURE__*/React.createElement(ArrowKeyNavigationProvider, {
|
|
64
98
|
closeOnTab: true,
|
|
65
99
|
type: ArrowKeyNavigationType.MENU,
|
|
66
100
|
onSelection: index => {
|
|
@@ -105,5 +139,5 @@ export const DropdownMenu = ({
|
|
|
105
139
|
});
|
|
106
140
|
}
|
|
107
141
|
}
|
|
108
|
-
}, innerMenu());
|
|
142
|
+
}, innerMenu())));
|
|
109
143
|
};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Popup } from '@atlaskit/editor-common/ui';
|
|
3
3
|
import { akEditorFloatingDialogZIndex, akEditorFloatingOverlapPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
5
|
-
import { dragMenuDropdownWidth } from '../consts';
|
|
5
|
+
import { dragMenuDropdownWidth, tablePopupMenuFitHeight } from '../consts';
|
|
6
6
|
import DragMenu from './DragMenu';
|
|
7
7
|
const FloatingDragMenu = ({
|
|
8
8
|
mountPoint,
|
|
@@ -24,12 +24,10 @@ const FloatingDragMenu = ({
|
|
|
24
24
|
}
|
|
25
25
|
const inStickyMode = stickyHeaders === null || stickyHeaders === void 0 ? void 0 : stickyHeaders.sticky;
|
|
26
26
|
const targetHandleRef = direction === 'row' ? document.querySelector('#drag-handle-button-row') : document.querySelector('#drag-handle-button-column');
|
|
27
|
-
const offset = direction === 'row' ? [-9,
|
|
27
|
+
const offset = direction === 'row' ? [-9, 0] : [0, -7];
|
|
28
28
|
if (!targetHandleRef || !(editorView.state.selection instanceof CellSelection)) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
// TODO: we will need to adjust the alignment and offset values depending on whether this is a row or column menu.
|
|
33
31
|
return /*#__PURE__*/React.createElement(Popup, {
|
|
34
32
|
alignX: direction === 'row' ? 'right' : undefined,
|
|
35
33
|
alignY: direction === 'row' ? 'start' : undefined,
|
|
@@ -37,7 +35,8 @@ const FloatingDragMenu = ({
|
|
|
37
35
|
mountTo: mountPoint,
|
|
38
36
|
boundariesElement: boundariesElement,
|
|
39
37
|
scrollableElement: scrollableElement,
|
|
40
|
-
fitWidth: dragMenuDropdownWidth
|
|
38
|
+
fitWidth: dragMenuDropdownWidth,
|
|
39
|
+
fitHeight: tablePopupMenuFitHeight
|
|
41
40
|
// z-index value below is to ensure that this menu is above other floating menu
|
|
42
41
|
// in table, but below floating dialogs like typeaheads, pickers, etc.
|
|
43
42
|
// In sticky mode, we want to show the menu above the sticky header
|
|
@@ -56,7 +55,12 @@ const FloatingDragMenu = ({
|
|
|
56
55
|
targetCellPosition: targetCellPosition,
|
|
57
56
|
getEditorContainerWidth: getEditorContainerWidth,
|
|
58
57
|
editorAnalyticsAPI: editorAnalyticsAPI,
|
|
59
|
-
pluginConfig: pluginConfig
|
|
58
|
+
pluginConfig: pluginConfig,
|
|
59
|
+
fitWidth: dragMenuDropdownWidth,
|
|
60
|
+
fitHeight: tablePopupMenuFitHeight,
|
|
61
|
+
mountPoint: mountPoint,
|
|
62
|
+
boundariesElement: boundariesElement,
|
|
63
|
+
scrollableElement: scrollableElement
|
|
60
64
|
}));
|
|
61
65
|
};
|
|
62
66
|
FloatingDragMenu.displayName = 'FloatingDragMenu';
|
package/dist/es2019/ui/consts.js
CHANGED
|
@@ -56,6 +56,7 @@ export const stickyRowOffsetTop = 8;
|
|
|
56
56
|
export const stickyHeaderBorderBottomWidth = 1;
|
|
57
57
|
export const tableOverflowShadowWidth = 8;
|
|
58
58
|
export const tableOverflowShadowWidthWide = 32;
|
|
59
|
+
export const tablePopupMenuFitHeight = 188;
|
|
59
60
|
export const dropTargetsZIndex = 14;
|
|
60
61
|
export const TABLE_SNAP_GAP = 9;
|
|
61
62
|
export const TABLE_HIGHLIGHT_GAP = 10;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
2
|
+
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
3
|
+
export const createTableWithWidth = (isFullWidthModeEnabled, getEditorFeatureFlags, createTableProps) => schema => {
|
|
4
|
+
const {
|
|
5
|
+
tablePreserveWidth = false
|
|
6
|
+
} = getEditorFeatureFlags ? getEditorFeatureFlags() : {};
|
|
7
|
+
if (tablePreserveWidth && isFullWidthModeEnabled) {
|
|
8
|
+
return createTable({
|
|
9
|
+
schema,
|
|
10
|
+
tableWidth: TABLE_MAX_WIDTH,
|
|
11
|
+
...createTableProps
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return createTable({
|
|
15
|
+
schema,
|
|
16
|
+
...createTableProps
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -8,4 +8,5 @@ export { getRowHeights, isRowDeleteButtonVisible, getRowDeleteButtonParams, getR
|
|
|
8
8
|
export { getSelectedTableInfo, getSelectedCellInfo } from './analytics';
|
|
9
9
|
export { getMergedCellsPositions } from './table';
|
|
10
10
|
export { updatePluginStateDecorations } from './update-plugin-state-decorations';
|
|
11
|
-
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
11
|
+
export { hasMergedCellsInColumn, hasMergedCellsInRow, hasMergedCellsInBetween, hasMergedCellsInSelection, findDuplicatePosition, checkEdgeHasMergedCells } from './merged-cells';
|
|
12
|
+
export { createTableWithWidth } from './create';
|
|
@@ -4,12 +4,12 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, TABLE_OVERFLOW_C
|
|
|
4
4
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { TableMap } from '@atlaskit/editor-tables/table-map';
|
|
7
|
-
import { addColumnAt as addColumnAtPMUtils, addRowAt,
|
|
7
|
+
import { addColumnAt as addColumnAtPMUtils, addRowAt, findTable, selectedRect } from '@atlaskit/editor-tables/utils';
|
|
8
8
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
9
9
|
import { updateRowOrColumnMovedTransform } from '../pm-plugins/analytics/commands';
|
|
10
10
|
import { META_KEYS } from '../pm-plugins/table-analytics';
|
|
11
11
|
import { rescaleColumns } from '../transforms/column-width';
|
|
12
|
-
import { checkIfHeaderRowEnabled, copyPreviousRow } from '../utils';
|
|
12
|
+
import { checkIfHeaderRowEnabled, copyPreviousRow, createTableWithWidth } from '../utils';
|
|
13
13
|
import { getAllowAddColumnCustomStep } from '../utils/get-allow-add-column-custom-step';
|
|
14
14
|
function addColumnAtCustomStep(column) {
|
|
15
15
|
return function (tr) {
|
|
@@ -80,8 +80,6 @@ export var addColumnAfter = function addColumnAfter(getEditorContainerWidth) {
|
|
|
80
80
|
return true;
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
// #region Commands
|
|
85
83
|
export var insertColumn = function insertColumn(getEditorContainerWidth) {
|
|
86
84
|
return function (column) {
|
|
87
85
|
return function (state, dispatch, view) {
|
|
@@ -134,28 +132,23 @@ export var insertRow = function insertRow(row, moveCursorToTheNewRow) {
|
|
|
134
132
|
return true;
|
|
135
133
|
};
|
|
136
134
|
};
|
|
137
|
-
export var createTable = function createTable() {
|
|
135
|
+
export var createTable = function createTable(isFullWidthModeEnabled, getEditorFeatureFlags) {
|
|
138
136
|
return function (state, dispatch) {
|
|
139
|
-
var table =
|
|
140
|
-
schema: state.schema
|
|
141
|
-
});
|
|
137
|
+
var table = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags)(state.schema);
|
|
142
138
|
if (dispatch) {
|
|
143
139
|
dispatch(safeInsert(table)(state.tr).scrollIntoView());
|
|
144
140
|
}
|
|
145
141
|
return true;
|
|
146
142
|
};
|
|
147
143
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
export var insertTableWithSize = function insertTableWithSize(editorAnalyticsAPI) {
|
|
144
|
+
export var insertTableWithSize = function insertTableWithSize(isFullWidthModeEnabled, getEditorFeatureFlags, editorAnalyticsAPI) {
|
|
151
145
|
return function (rowsCount, colsCount, inputMethod) {
|
|
152
146
|
return function (_ref) {
|
|
153
147
|
var tr = _ref.tr;
|
|
154
|
-
var tableNode =
|
|
155
|
-
schema: tr.doc.type.schema,
|
|
148
|
+
var tableNode = createTableWithWidth(isFullWidthModeEnabled, getEditorFeatureFlags, {
|
|
156
149
|
rowsCount: rowsCount,
|
|
157
150
|
colsCount: colsCount
|
|
158
|
-
});
|
|
151
|
+
})(tr.doc.type.schema);
|
|
159
152
|
var newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
160
153
|
if (inputMethod) {
|
|
161
154
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
|