@atlaskit/editor-core 195.6.2 → 195.8.0
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 +25 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/ui/Appearance/FullPage/FullPage.js +1 -0
- package/dist/cjs/ui/Appearance/FullPage/FullPageContentArea.js +64 -60
- package/dist/cjs/ui/ContextPanel/deprecated.js +283 -0
- package/dist/cjs/ui/ContextPanel/index.js +26 -133
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/index.js +6 -1
- package/dist/es2019/ui/Appearance/FullPage/FullPage.js +1 -0
- package/dist/es2019/ui/Appearance/FullPage/FullPageContentArea.js +4 -1
- package/dist/es2019/ui/ContextPanel/deprecated.js +258 -0
- package/dist/es2019/ui/ContextPanel/index.js +24 -133
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/ui/Appearance/FullPage/FullPage.js +1 -0
- package/dist/esm/ui/Appearance/FullPage/FullPageContentArea.js +64 -60
- package/dist/esm/ui/ContextPanel/deprecated.js +277 -0
- package/dist/esm/ui/ContextPanel/index.js +24 -132
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/create-editor/create-universal-preset.d.ts +81 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/presets/default.d.ts +68 -0
- package/dist/types/presets/universal.d.ts +83 -1
- package/dist/types/presets/useUniversalPreset.d.ts +81 -0
- package/dist/types/ui/Appearance/FullPage/FullPageContentArea.d.ts +3 -1
- package/dist/types/ui/ContextPanel/deprecated.d.ts +44 -0
- package/dist/types/ui/ContextPanel/index.d.ts +5 -9
- package/dist/types-ts4.5/create-editor/create-universal-preset.d.ts +81 -0
- package/dist/types-ts4.5/index.d.ts +6 -1
- package/dist/types-ts4.5/presets/default.d.ts +68 -0
- package/dist/types-ts4.5/presets/universal.d.ts +83 -1
- package/dist/types-ts4.5/presets/useUniversalPreset.d.ts +81 -0
- package/dist/types-ts4.5/ui/Appearance/FullPage/FullPageContentArea.d.ts +5 -1
- package/dist/types-ts4.5/ui/ContextPanel/deprecated.d.ts +44 -0
- package/dist/types-ts4.5/ui/ContextPanel/index.d.ts +7 -9
- package/package.json +7 -12
|
@@ -4,55 +4,18 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
4
4
|
* @jsxRuntime classic
|
|
5
5
|
* @jsx jsx
|
|
6
6
|
*/
|
|
7
|
-
import React
|
|
7
|
+
import React from 'react';
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
10
10
|
import { css, jsx } from '@emotion/react';
|
|
11
11
|
import Transition from 'react-transition-group/Transition';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
13
|
+
import { ContextPanelConsumer } from '@atlaskit/editor-common/ui';
|
|
14
|
+
import { akEditorContextPanelWidth, akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
|
|
15
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
16
|
import { N30 } from '@atlaskit/theme/colors';
|
|
17
|
-
import
|
|
18
|
-
import WithEditorActions from '../WithEditorActions';
|
|
17
|
+
import ContextPanelDeprecated from './deprecated';
|
|
19
18
|
const ANIM_SPEED_MS = 500;
|
|
20
|
-
const EDITOR_WIDTH = akEditorDefaultLayoutWidth + akEditorBreakoutPadding;
|
|
21
|
-
const WIDE_EDITOR_WIDTH = akEditorWideLayoutWidth + akEditorBreakoutPadding;
|
|
22
|
-
const FULLWIDTH_MODE = 'full-width';
|
|
23
|
-
const WIDE_MODE = 'wide';
|
|
24
|
-
const absolutePanelStyles = css({
|
|
25
|
-
position: 'absolute',
|
|
26
|
-
right: 0,
|
|
27
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
28
|
-
height: `calc(100% - ${FULL_PAGE_EDITOR_TOOLBAR_HEIGHT()})`
|
|
29
|
-
});
|
|
30
|
-
const checkTableExistsInDoc = editorView => {
|
|
31
|
-
const tableNodeSchema = editorView.state.schema.nodes.table;
|
|
32
|
-
let findResult = findChildrenByType(editorView.state.doc, tableNodeSchema);
|
|
33
|
-
return findResult.length > 0;
|
|
34
|
-
};
|
|
35
|
-
export const shouldPanelBePositionedOverEditor = (editorWidth, panelWidth, editorView) => {
|
|
36
|
-
const {
|
|
37
|
-
lineLength,
|
|
38
|
-
containerWidth = 0,
|
|
39
|
-
contentBreakoutModes
|
|
40
|
-
} = editorWidth;
|
|
41
|
-
const editorNotFullWidth = !(lineLength && lineLength > akEditorDefaultLayoutWidth);
|
|
42
|
-
const hasSpaceForPanel = !contentBreakoutModes.length && containerWidth >= panelWidth * 2 + EDITOR_WIDTH;
|
|
43
|
-
const hasSpaceForWideBreakoutsAndPanel = !contentBreakoutModes.includes(FULLWIDTH_MODE) && contentBreakoutModes.includes(WIDE_MODE) && containerWidth >= panelWidth * 2 + WIDE_EDITOR_WIDTH;
|
|
44
|
-
if (!editorView) {
|
|
45
|
-
return editorNotFullWidth && (hasSpaceForPanel || hasSpaceForWideBreakoutsAndPanel);
|
|
46
|
-
} else {
|
|
47
|
-
// when custom table width feature flag is on,
|
|
48
|
-
// there are scenarios when a table has attr layout default, but width is in full-width or very wide
|
|
49
|
-
// but in this case we still want the shouldPanelBePositionedOverEditor return false
|
|
50
|
-
// previous logic is returning false when table layout default
|
|
51
|
-
// but when custom table width feature flag is one, we want to return false whenever there is a table in the doc
|
|
52
|
-
const isTableInDoc = checkTableExistsInDoc(editorView);
|
|
53
|
-
return editorNotFullWidth && (hasSpaceForPanel || hasSpaceForWideBreakoutsAndPanel) && !isTableInDoc;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
19
|
const panelHidden = css({
|
|
57
20
|
width: 0
|
|
58
21
|
});
|
|
@@ -87,13 +50,13 @@ export class SwappableContentArea extends React.PureComponent {
|
|
|
87
50
|
currentPluginContent: undefined
|
|
88
51
|
});
|
|
89
52
|
_defineProperty(this, "focusEditor", () => {
|
|
53
|
+
var _editorAPI$core;
|
|
90
54
|
const {
|
|
91
|
-
|
|
55
|
+
editorAPI
|
|
92
56
|
} = this.props;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
57
|
+
editorAPI === null || editorAPI === void 0 ? void 0 : (_editorAPI$core = editorAPI.core) === null || _editorAPI$core === void 0 ? void 0 : _editorAPI$core.actions.focus({
|
|
58
|
+
scrollIntoView: false
|
|
59
|
+
});
|
|
97
60
|
});
|
|
98
61
|
_defineProperty(this, "showPluginContent", () => {
|
|
99
62
|
const {
|
|
@@ -150,29 +113,16 @@ export class SwappableContentArea extends React.PureComponent {
|
|
|
150
113
|
});
|
|
151
114
|
}
|
|
152
115
|
render() {
|
|
153
|
-
const {
|
|
154
|
-
editorWidth,
|
|
155
|
-
editorView
|
|
156
|
-
} = this.props;
|
|
157
116
|
const width = akEditorContextPanelWidth;
|
|
158
117
|
const userVisible = !!this.props.visible;
|
|
159
118
|
const visible = userVisible || !!this.state.currentPluginContent;
|
|
160
119
|
return jsx(ContextPanelConsumer, null, ({
|
|
161
|
-
broadcastWidth
|
|
162
|
-
broadcastPosition,
|
|
163
|
-
positionedOverEditor
|
|
120
|
+
broadcastWidth
|
|
164
121
|
}) => {
|
|
165
122
|
const contextPanelWidth = visible ? width : 0;
|
|
166
|
-
const newPosition = editorWidth ? shouldPanelBePositionedOverEditor(editorWidth, width, editorView) : false;
|
|
167
123
|
broadcastWidth(contextPanelWidth);
|
|
168
|
-
(newPosition && visible) !== positionedOverEditor && broadcastPosition(newPosition && visible);
|
|
169
124
|
return jsx("div", {
|
|
170
|
-
css: [panel, !visible && panelHidden,
|
|
171
|
-
/**
|
|
172
|
-
* Only use absolute position for panel when screen size is wide enough
|
|
173
|
-
* to accommodate breakout content and editor is not in wide mode.
|
|
174
|
-
*/
|
|
175
|
-
newPosition && absolutePanelStyles],
|
|
125
|
+
css: [panel, !visible && panelHidden],
|
|
176
126
|
"data-testid": "context-panel-panel",
|
|
177
127
|
"aria-labelledby": "context-panel-title",
|
|
178
128
|
role: "dialog"
|
|
@@ -183,76 +133,17 @@ export class SwappableContentArea extends React.PureComponent {
|
|
|
183
133
|
});
|
|
184
134
|
}
|
|
185
135
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// not have access to the pluginInjectionApi at this location.
|
|
189
|
-
// It might be that we need to inject the pluginInjectionApi
|
|
190
|
-
// via context so that we can use it in this file (similar to
|
|
191
|
-
// WithEditorActions). To be investigated further.
|
|
192
|
-
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
const widthPluginKey = {
|
|
195
|
-
key: 'widthPlugin$',
|
|
196
|
-
getState: state => {
|
|
197
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
-
return state['widthPlugin$'];
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// @ts-ignore
|
|
203
|
-
const contextPanelPluginKey = {
|
|
204
|
-
key: 'contextPanelPluginKey$',
|
|
205
|
-
getState: state => {
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
207
|
-
return state['contextPanelPluginKey$'];
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
function ContextPanelWithActions({
|
|
211
|
-
actions,
|
|
212
|
-
...props
|
|
213
|
-
}) {
|
|
214
|
-
const eventDispatcher = actions._privateGetEventDispatcher();
|
|
215
|
-
const editorView = actions._privateGetEditorView();
|
|
136
|
+
export function ContextPanel(props) {
|
|
137
|
+
var _contextPanelState$co;
|
|
216
138
|
const {
|
|
217
|
-
|
|
218
|
-
} =
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
return (
|
|
225
|
-
// @ts-ignore - 'WithPluginState' cannot be used as a JSX component.
|
|
226
|
-
// This error was introduced after upgrading to TypeScript 5
|
|
227
|
-
jsx(WithPluginState, {
|
|
228
|
-
eventDispatcher: eventDispatcher,
|
|
229
|
-
plugins: {
|
|
230
|
-
contextPanel: contextPanelPluginKey,
|
|
231
|
-
widthState: widthPluginKey
|
|
232
|
-
},
|
|
233
|
-
render: ({
|
|
234
|
-
contextPanel,
|
|
235
|
-
widthState
|
|
236
|
-
}) => {
|
|
237
|
-
const firstContent = contextPanel && contextPanel.contents.find(Boolean);
|
|
238
|
-
const editorWidth = {
|
|
239
|
-
...widthState,
|
|
240
|
-
containerWidth: width,
|
|
241
|
-
contentBreakoutModes: editorView ? getChildBreakoutModes(editorView.state.doc, editorView.state.schema) : []
|
|
242
|
-
};
|
|
243
|
-
return jsx(SwappableContentArea, _extends({}, props, {
|
|
244
|
-
editorView: editorView,
|
|
245
|
-
pluginContent: firstContent,
|
|
246
|
-
editorWidth: editorWidth
|
|
247
|
-
}));
|
|
248
|
-
}
|
|
249
|
-
})
|
|
250
|
-
);
|
|
139
|
+
contextPanelState
|
|
140
|
+
} = useSharedPluginState(props.editorAPI, ['contextPanel']);
|
|
141
|
+
const firstContent = contextPanelState && (contextPanelState === null || contextPanelState === void 0 ? void 0 : (_contextPanelState$co = contextPanelState.contents) === null || _contextPanelState$co === void 0 ? void 0 : _contextPanelState$co.find(Boolean));
|
|
142
|
+
return jsx(SwappableContentArea, _extends({}, props, {
|
|
143
|
+
editorAPI: props.editorAPI,
|
|
144
|
+
pluginContent: firstContent
|
|
145
|
+
}));
|
|
251
146
|
}
|
|
252
|
-
export default function
|
|
253
|
-
return jsx(
|
|
254
|
-
render: actions => jsx(ContextPanelWithActions, _extends({
|
|
255
|
-
actions: actions
|
|
256
|
-
}, props))
|
|
257
|
-
});
|
|
147
|
+
export default function ContextPanelDefault(props) {
|
|
148
|
+
return fg('platform_editor_context-panel_simplify_behaviour') ? jsx(ContextPanel, props) : jsx(ContextPanelDeprecated, props);
|
|
258
149
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = "@atlaskit/editor-core";
|
|
2
|
-
export const version = "195.
|
|
2
|
+
export const version = "195.8.0";
|
package/dist/esm/index.js
CHANGED
|
@@ -7,7 +7,12 @@ export { default as WithHelpTrigger } from './ui/WithHelpTrigger';
|
|
|
7
7
|
export { default as CollapsedEditor } from './ui/CollapsedEditor';
|
|
8
8
|
export { default as ToolbarHelp } from './ui/ToolbarHelp';
|
|
9
9
|
export { default as ToolbarFeedback } from './ui/ToolbarFeedback';
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
* DO NOT USE THIS WILL BE REMOVED SOON. This was intended for internal usage only
|
|
14
|
+
*/
|
|
15
|
+
default as ContextPanel } from './ui/ContextPanel/deprecated';
|
|
11
16
|
export { EmojiResource } from '@atlaskit/emoji/resource';
|
|
12
17
|
export { MentionResource } from '@atlaskit/mention/resource';
|
|
13
18
|
export { TeamMentionResource } from '@atlaskit/mention/team-resource';
|
|
@@ -97,6 +97,7 @@ export var FullPageEditor = function FullPageEditor(props) {
|
|
|
97
97
|
featureFlags: props.featureFlags,
|
|
98
98
|
hideAvatarGroup: props.hideAvatarGroup
|
|
99
99
|
}), jsx(FullPageContentArea, {
|
|
100
|
+
editorAPI: editorAPI,
|
|
100
101
|
ref: scrollContentContainerRef,
|
|
101
102
|
appearance: props.appearance,
|
|
102
103
|
contentComponents: props.contentComponents,
|
|
@@ -36,67 +36,71 @@ var Content = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
36
36
|
}, []);
|
|
37
37
|
return jsx(WidthConsumer, null, function (_ref) {
|
|
38
38
|
var width = _ref.width;
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
className: "fabric-editor-popup-scroll-parent",
|
|
56
|
-
featureFlags: props.featureFlags,
|
|
57
|
-
ref: scrollContainerRef
|
|
58
|
-
}, jsx(ClickAreaBlock, {
|
|
59
|
-
editorView: props.editorView,
|
|
60
|
-
editorDisabled: props.disabled
|
|
61
|
-
}, jsx("div", {
|
|
62
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
63
|
-
css: editorContentAreaStyle({
|
|
64
|
-
fullWidthMode: fullWidthMode,
|
|
65
|
-
layoutMaxWidth: theme.layoutMaxWidth,
|
|
66
|
-
containerWidth: width
|
|
67
|
-
}),
|
|
68
|
-
role: "region",
|
|
69
|
-
"aria-label": props.intl.formatMessage(messages.editableContentLabel),
|
|
70
|
-
ref: contentAreaRef
|
|
71
|
-
}, jsx("div", {
|
|
72
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
73
|
-
css: editorContentGutterStyle()
|
|
39
|
+
return (
|
|
40
|
+
// Cleaned up with: platform_editor_context-panel_simplify_behaviour
|
|
41
|
+
jsx(ContextPanelConsumer, null, function (_ref2) {
|
|
42
|
+
var _contentAreaRef$curre;
|
|
43
|
+
var positionedOverEditor = _ref2.positionedOverEditor;
|
|
44
|
+
return jsx("div", {
|
|
45
|
+
css: [
|
|
46
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
47
|
+
contentArea,
|
|
48
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
49
|
+
props.isEditorToolbarHidden && contentAreaHeightNoToolbar,
|
|
50
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
51
|
+
positionedOverEditor && positionedOverEditorStyle],
|
|
52
|
+
"data-testid": CONTENT_AREA_TEST_ID,
|
|
53
|
+
ref: containerRef
|
|
54
|
+
}, jsx(ScrollContainer
|
|
74
55
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
75
|
-
,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
56
|
+
, {
|
|
57
|
+
className: "fabric-editor-popup-scroll-parent",
|
|
58
|
+
featureFlags: props.featureFlags,
|
|
59
|
+
ref: scrollContainerRef
|
|
60
|
+
}, jsx(ClickAreaBlock, {
|
|
61
|
+
editorView: props.editorView,
|
|
62
|
+
editorDisabled: props.disabled
|
|
63
|
+
}, jsx("div", {
|
|
64
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
65
|
+
css: editorContentAreaStyle({
|
|
66
|
+
fullWidthMode: fullWidthMode,
|
|
67
|
+
layoutMaxWidth: theme.layoutMaxWidth,
|
|
68
|
+
containerWidth: width
|
|
69
|
+
}),
|
|
70
|
+
role: "region",
|
|
71
|
+
"aria-label": props.intl.formatMessage(messages.editableContentLabel),
|
|
72
|
+
ref: contentAreaRef
|
|
73
|
+
}, jsx("div", {
|
|
74
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
75
|
+
css: editorContentGutterStyle()
|
|
76
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
77
|
+
,
|
|
78
|
+
className: ['ak-editor-content-area', fullWidthMode ? 'fabric-editor--full-width-mode' : ''].join(' '),
|
|
79
|
+
ref: contentAreaRef
|
|
80
|
+
}, !!props.customContentComponents && 'before' in props.customContentComponents ? props.customContentComponents.before : props.customContentComponents, jsx(PluginSlot, {
|
|
81
|
+
editorView: props.editorView,
|
|
82
|
+
editorActions: props.editorActions,
|
|
83
|
+
eventDispatcher: props.eventDispatcher,
|
|
84
|
+
providerFactory: props.providerFactory,
|
|
85
|
+
appearance: props.appearance,
|
|
86
|
+
items: props.contentComponents,
|
|
87
|
+
pluginHooks: props.pluginHooks,
|
|
88
|
+
contentArea: (_contentAreaRef$curre = contentAreaRef.current) !== null && _contentAreaRef$curre !== void 0 ? _contentAreaRef$curre : undefined,
|
|
89
|
+
popupsMountPoint: props.popupsMountPoint,
|
|
90
|
+
popupsBoundariesElement: props.popupsBoundariesElement,
|
|
91
|
+
popupsScrollableElement: props.popupsScrollableElement,
|
|
92
|
+
disabled: !!props.disabled,
|
|
93
|
+
containerElement: scrollContainerRef.current,
|
|
94
|
+
dispatchAnalyticsEvent: props.dispatchAnalyticsEvent,
|
|
95
|
+
wrapperElement: props.wrapperElement
|
|
96
|
+
}), props.editorDOMElement, !!props.customContentComponents && 'after' in props.customContentComponents ? props.customContentComponents.after : null)))), jsx("div", {
|
|
97
|
+
css: sidebarArea
|
|
98
|
+
}, props.contextPanel || jsx(ContextPanel, {
|
|
99
|
+
editorAPI: props.editorAPI,
|
|
100
|
+
visible: false
|
|
101
|
+
})));
|
|
102
|
+
})
|
|
103
|
+
);
|
|
100
104
|
});
|
|
101
105
|
});
|
|
102
106
|
export var FullPageContentArea = injectIntl(Content, {
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
var _excluded = ["actions"];
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
15
|
+
/**
|
|
16
|
+
* @jsxRuntime classic
|
|
17
|
+
* @jsx jsx
|
|
18
|
+
*/
|
|
19
|
+
import React, { useContext } from 'react';
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
22
|
+
import { css, jsx } from '@emotion/react';
|
|
23
|
+
import Transition from 'react-transition-group/Transition';
|
|
24
|
+
import { ContextPanelConsumer, WidthContext } from '@atlaskit/editor-common/ui';
|
|
25
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
26
|
+
import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
|
|
27
|
+
import { akEditorBreakoutPadding, akEditorContextPanelWidth, akEditorDefaultLayoutWidth, akEditorSwoopCubicBezier, akEditorWideLayoutWidth, FULL_PAGE_EDITOR_TOOLBAR_HEIGHT } from '@atlaskit/editor-shared-styles';
|
|
28
|
+
import { N30 } from '@atlaskit/theme/colors';
|
|
29
|
+
import { getChildBreakoutModes } from '../../utils/document';
|
|
30
|
+
import WithEditorActions from '../WithEditorActions';
|
|
31
|
+
var ANIM_SPEED_MS = 500;
|
|
32
|
+
var EDITOR_WIDTH = akEditorDefaultLayoutWidth + akEditorBreakoutPadding;
|
|
33
|
+
var WIDE_EDITOR_WIDTH = akEditorWideLayoutWidth + akEditorBreakoutPadding;
|
|
34
|
+
var FULLWIDTH_MODE = 'full-width';
|
|
35
|
+
var WIDE_MODE = 'wide';
|
|
36
|
+
var absolutePanelStyles = css({
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
right: 0,
|
|
39
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
40
|
+
height: "calc(100% - ".concat(FULL_PAGE_EDITOR_TOOLBAR_HEIGHT(), ")")
|
|
41
|
+
});
|
|
42
|
+
var checkTableExistsInDoc = function checkTableExistsInDoc(editorView) {
|
|
43
|
+
var tableNodeSchema = editorView.state.schema.nodes.table;
|
|
44
|
+
var findResult = findChildrenByType(editorView.state.doc, tableNodeSchema);
|
|
45
|
+
return findResult.length > 0;
|
|
46
|
+
};
|
|
47
|
+
export var shouldPanelBePositionedOverEditor = function shouldPanelBePositionedOverEditor(editorWidth, panelWidth, editorView) {
|
|
48
|
+
var lineLength = editorWidth.lineLength,
|
|
49
|
+
_editorWidth$containe = editorWidth.containerWidth,
|
|
50
|
+
containerWidth = _editorWidth$containe === void 0 ? 0 : _editorWidth$containe,
|
|
51
|
+
contentBreakoutModes = editorWidth.contentBreakoutModes;
|
|
52
|
+
var editorNotFullWidth = !(lineLength && lineLength > akEditorDefaultLayoutWidth);
|
|
53
|
+
var hasSpaceForPanel = !contentBreakoutModes.length && containerWidth >= panelWidth * 2 + EDITOR_WIDTH;
|
|
54
|
+
var hasSpaceForWideBreakoutsAndPanel = !contentBreakoutModes.includes(FULLWIDTH_MODE) && contentBreakoutModes.includes(WIDE_MODE) && containerWidth >= panelWidth * 2 + WIDE_EDITOR_WIDTH;
|
|
55
|
+
if (!editorView) {
|
|
56
|
+
return editorNotFullWidth && (hasSpaceForPanel || hasSpaceForWideBreakoutsAndPanel);
|
|
57
|
+
} else {
|
|
58
|
+
// when custom table width feature flag is on,
|
|
59
|
+
// there are scenarios when a table has attr layout default, but width is in full-width or very wide
|
|
60
|
+
// but in this case we still want the shouldPanelBePositionedOverEditor return false
|
|
61
|
+
// previous logic is returning false when table layout default
|
|
62
|
+
// but when custom table width feature flag is one, we want to return false whenever there is a table in the doc
|
|
63
|
+
var isTableInDoc = checkTableExistsInDoc(editorView);
|
|
64
|
+
return editorNotFullWidth && (hasSpaceForPanel || hasSpaceForWideBreakoutsAndPanel) && !isTableInDoc;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var panelHidden = css({
|
|
68
|
+
width: 0
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
|
|
72
|
+
export var panel = css({
|
|
73
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
74
|
+
width: "".concat(akEditorContextPanelWidth, "px"),
|
|
75
|
+
height: '100%',
|
|
76
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
77
|
+
transition: "width ".concat(ANIM_SPEED_MS, "ms ").concat(akEditorSwoopCubicBezier),
|
|
78
|
+
overflow: 'hidden',
|
|
79
|
+
boxShadow: "inset 2px 0 0 0 ".concat("var(--ds-border, ".concat(N30, ")"))
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
|
|
83
|
+
export var content = css({
|
|
84
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
85
|
+
transition: "width 600ms ".concat(akEditorSwoopCubicBezier),
|
|
86
|
+
boxSizing: 'border-box',
|
|
87
|
+
padding: "var(--ds-space-200, 16px)".concat(" ", "var(--ds-space-200, 16px)", " 0px"),
|
|
88
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
89
|
+
width: "".concat(akEditorContextPanelWidth, "px"),
|
|
90
|
+
height: '100%',
|
|
91
|
+
overflowY: 'auto'
|
|
92
|
+
});
|
|
93
|
+
export var SwappableContentArea = /*#__PURE__*/function (_React$PureComponent) {
|
|
94
|
+
_inherits(SwappableContentArea, _React$PureComponent);
|
|
95
|
+
var _super = _createSuper(SwappableContentArea);
|
|
96
|
+
function SwappableContentArea() {
|
|
97
|
+
var _this;
|
|
98
|
+
_classCallCheck(this, SwappableContentArea);
|
|
99
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
100
|
+
args[_key] = arguments[_key];
|
|
101
|
+
}
|
|
102
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
103
|
+
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
104
|
+
mounted: false,
|
|
105
|
+
currentPluginContent: undefined
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(_assertThisInitialized(_this), "focusEditor", function () {
|
|
108
|
+
var editorView = _this.props.editorView;
|
|
109
|
+
if (editorView && !editorView.hasFocus()) {
|
|
110
|
+
var _editorView$focus;
|
|
111
|
+
(_editorView$focus = editorView.focus) === null || _editorView$focus === void 0 || _editorView$focus.call(editorView);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
_defineProperty(_assertThisInitialized(_this), "showPluginContent", function () {
|
|
115
|
+
var pluginContent = _this.props.pluginContent;
|
|
116
|
+
var currentPluginContent = _this.state.currentPluginContent;
|
|
117
|
+
if (!currentPluginContent) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
return jsx(Transition, {
|
|
121
|
+
timeout: _this.state.mounted ? ANIM_SPEED_MS : 0,
|
|
122
|
+
in: !!pluginContent,
|
|
123
|
+
mountOnEnter: true,
|
|
124
|
+
unmountOnExit: true,
|
|
125
|
+
onExited: function onExited() {
|
|
126
|
+
return _this.unsetPluginContent();
|
|
127
|
+
}
|
|
128
|
+
}, currentPluginContent);
|
|
129
|
+
});
|
|
130
|
+
_defineProperty(_assertThisInitialized(_this), "showProvidedContent", function (isVisible) {
|
|
131
|
+
var children = _this.props.children;
|
|
132
|
+
if (!children) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
return jsx(Transition, {
|
|
136
|
+
timeout: _this.state.mounted ? ANIM_SPEED_MS : 0,
|
|
137
|
+
in: isVisible,
|
|
138
|
+
mountOnEnter: true,
|
|
139
|
+
unmountOnExit: true,
|
|
140
|
+
onExiting: _this.focusEditor
|
|
141
|
+
}, children);
|
|
142
|
+
});
|
|
143
|
+
return _this;
|
|
144
|
+
}
|
|
145
|
+
_createClass(SwappableContentArea, [{
|
|
146
|
+
key: "unsetPluginContent",
|
|
147
|
+
value: function unsetPluginContent() {
|
|
148
|
+
this.setState({
|
|
149
|
+
currentPluginContent: undefined
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "componentDidMount",
|
|
154
|
+
value: function componentDidMount() {
|
|
155
|
+
// use this to trigger an animation
|
|
156
|
+
this.setState({
|
|
157
|
+
mounted: true
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
key: "render",
|
|
162
|
+
value: function render() {
|
|
163
|
+
var _this2 = this;
|
|
164
|
+
var _this$props = this.props,
|
|
165
|
+
editorWidth = _this$props.editorWidth,
|
|
166
|
+
editorView = _this$props.editorView;
|
|
167
|
+
var width = akEditorContextPanelWidth;
|
|
168
|
+
var userVisible = !!this.props.visible;
|
|
169
|
+
var visible = userVisible || !!this.state.currentPluginContent;
|
|
170
|
+
return jsx(ContextPanelConsumer, null, function (_ref) {
|
|
171
|
+
var broadcastWidth = _ref.broadcastWidth,
|
|
172
|
+
broadcastPosition = _ref.broadcastPosition,
|
|
173
|
+
positionedOverEditor = _ref.positionedOverEditor;
|
|
174
|
+
var contextPanelWidth = visible ? width : 0;
|
|
175
|
+
var newPosition = editorWidth ? shouldPanelBePositionedOverEditor(editorWidth, width, editorView) : false;
|
|
176
|
+
broadcastWidth(contextPanelWidth);
|
|
177
|
+
(newPosition && visible) !== positionedOverEditor && broadcastPosition(newPosition && visible);
|
|
178
|
+
return jsx("div", {
|
|
179
|
+
css: [panel, !visible && panelHidden,
|
|
180
|
+
/**
|
|
181
|
+
* Only use absolute position for panel when screen size is wide enough
|
|
182
|
+
* to accommodate breakout content and editor is not in wide mode.
|
|
183
|
+
*/
|
|
184
|
+
newPosition && absolutePanelStyles],
|
|
185
|
+
"data-testid": "context-panel-panel",
|
|
186
|
+
"aria-labelledby": "context-panel-title",
|
|
187
|
+
role: "dialog"
|
|
188
|
+
}, jsx("div", {
|
|
189
|
+
"data-testid": "context-panel-content",
|
|
190
|
+
css: [content, !visible && panelHidden]
|
|
191
|
+
}, _this2.showPluginContent() || _this2.showProvidedContent(userVisible)));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}], [{
|
|
195
|
+
key: "getDerivedStateFromProps",
|
|
196
|
+
value: function getDerivedStateFromProps(props, state) {
|
|
197
|
+
if (props.pluginContent !== state.currentPluginContent) {
|
|
198
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
199
|
+
currentPluginContent: props.pluginContent
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}]);
|
|
205
|
+
return SwappableContentArea;
|
|
206
|
+
}(React.PureComponent);
|
|
207
|
+
|
|
208
|
+
// TODO: ED-17837 We have this workaround because we do
|
|
209
|
+
// not have access to the pluginInjectionApi at this location.
|
|
210
|
+
// It might be that we need to inject the pluginInjectionApi
|
|
211
|
+
// via context so that we can use it in this file (similar to
|
|
212
|
+
// WithEditorActions). To be investigated further.
|
|
213
|
+
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
var widthPluginKey = {
|
|
216
|
+
key: 'widthPlugin$',
|
|
217
|
+
getState: function getState(state) {
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
219
|
+
return state['widthPlugin$'];
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
var contextPanelPluginKey = {
|
|
225
|
+
key: 'contextPanelPluginKey$',
|
|
226
|
+
getState: function getState(state) {
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
228
|
+
return state['contextPanelPluginKey$'];
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
function ContextPanelWithActions(_ref2) {
|
|
232
|
+
var actions = _ref2.actions,
|
|
233
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
234
|
+
var eventDispatcher = actions._privateGetEventDispatcher();
|
|
235
|
+
var editorView = actions._privateGetEditorView();
|
|
236
|
+
var _useContext = useContext(WidthContext),
|
|
237
|
+
width = _useContext.width;
|
|
238
|
+
if (!eventDispatcher) {
|
|
239
|
+
return jsx(SwappableContentArea, _extends({
|
|
240
|
+
editorView: editorView
|
|
241
|
+
}, props));
|
|
242
|
+
}
|
|
243
|
+
return (
|
|
244
|
+
// @ts-ignore - 'WithPluginState' cannot be used as a JSX component.
|
|
245
|
+
// This error was introduced after upgrading to TypeScript 5
|
|
246
|
+
jsx(WithPluginState, {
|
|
247
|
+
eventDispatcher: eventDispatcher,
|
|
248
|
+
plugins: {
|
|
249
|
+
contextPanel: contextPanelPluginKey,
|
|
250
|
+
widthState: widthPluginKey
|
|
251
|
+
},
|
|
252
|
+
render: function render(_ref3) {
|
|
253
|
+
var contextPanel = _ref3.contextPanel,
|
|
254
|
+
widthState = _ref3.widthState;
|
|
255
|
+
var firstContent = contextPanel && contextPanel.contents.find(Boolean);
|
|
256
|
+
var editorWidth = _objectSpread(_objectSpread({}, widthState), {}, {
|
|
257
|
+
containerWidth: width,
|
|
258
|
+
contentBreakoutModes: editorView ? getChildBreakoutModes(editorView.state.doc, editorView.state.schema) : []
|
|
259
|
+
});
|
|
260
|
+
return jsx(SwappableContentArea, _extends({}, props, {
|
|
261
|
+
editorView: editorView,
|
|
262
|
+
pluginContent: firstContent,
|
|
263
|
+
editorWidth: editorWidth
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
export default function ContextPanel(props) {
|
|
270
|
+
return jsx(WithEditorActions, {
|
|
271
|
+
render: function render(actions) {
|
|
272
|
+
return jsx(ContextPanelWithActions, _extends({
|
|
273
|
+
actions: actions
|
|
274
|
+
}, props));
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|