@atlaskit/editor-plugin-media 1.35.1 → 1.36.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 +12 -0
- package/dist/cjs/plugin.js +70 -43
- package/dist/cjs/pm-plugins/actions.js +10 -0
- package/dist/cjs/pm-plugins/commands.js +28 -0
- package/dist/cjs/pm-plugins/main.js +14 -0
- package/dist/cjs/toolbar/filePreviewItem.js +3 -2
- package/dist/cjs/toolbar/index.js +46 -12
- package/dist/cjs/toolbar/mediaInline.js +14 -1
- package/dist/es2019/plugin.js +31 -2
- package/dist/es2019/pm-plugins/actions.js +4 -0
- package/dist/es2019/pm-plugins/commands.js +22 -0
- package/dist/es2019/pm-plugins/main.js +14 -0
- package/dist/es2019/toolbar/filePreviewItem.js +3 -2
- package/dist/es2019/toolbar/index.js +40 -5
- package/dist/es2019/toolbar/mediaInline.js +15 -2
- package/dist/esm/plugin.js +70 -43
- package/dist/esm/pm-plugins/actions.js +4 -0
- package/dist/esm/pm-plugins/commands.js +22 -0
- package/dist/esm/pm-plugins/main.js +14 -0
- package/dist/esm/toolbar/filePreviewItem.js +3 -2
- package/dist/esm/toolbar/index.js +46 -12
- package/dist/esm/toolbar/mediaInline.js +15 -2
- package/dist/types/next-plugin-type.d.ts +6 -1
- package/dist/types/pm-plugins/actions.d.ts +4 -0
- package/dist/types/pm-plugins/commands.d.ts +4 -0
- package/dist/types/pm-plugins/types.d.ts +3 -1
- package/dist/types/toolbar/index.d.ts +4 -0
- package/dist/types-ts4.5/next-plugin-type.d.ts +6 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/commands.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/types.d.ts +3 -1
- package/dist/types-ts4.5/toolbar/index.d.ts +4 -0
- package/package.json +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 1.36.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#151938](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151938)
|
|
8
|
+
[`91b5768ef0c7c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/91b5768ef0c7c) -
|
|
9
|
+
[ux] ED-25203 refactor image previewer outside of floating toolbar
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 1.35.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -21,6 +21,7 @@ var _lazyMediaInline = require("./nodeviews/lazy-media-inline");
|
|
|
21
21
|
var _lazyMediaSingle = require("./nodeviews/lazy-media-single");
|
|
22
22
|
var _altText = require("./pm-plugins/alt-text");
|
|
23
23
|
var _keymap = _interopRequireDefault(require("./pm-plugins/alt-text/keymap"));
|
|
24
|
+
var _commands = require("./pm-plugins/commands");
|
|
24
25
|
var _keymap2 = _interopRequireDefault(require("./pm-plugins/keymap"));
|
|
25
26
|
var _keymapMedia = _interopRequireDefault(require("./pm-plugins/keymap-media"));
|
|
26
27
|
var _linking = _interopRequireDefault(require("./pm-plugins/linking"));
|
|
@@ -32,6 +33,7 @@ var _mediaInline = require("./toDOM-fixes/mediaInline");
|
|
|
32
33
|
var _mediaSingle = require("./toDOM-fixes/mediaSingle");
|
|
33
34
|
var _toolbar = require("./toolbar");
|
|
34
35
|
var _MediaPicker = require("./ui/MediaPicker");
|
|
36
|
+
var _PortalWrapper = require("./ui/MediaViewer/PortalWrapper");
|
|
35
37
|
var _ToolbarMedia = _interopRequireDefault(require("./ui/ToolbarMedia"));
|
|
36
38
|
var _mediaSingle2 = require("./utils/media-single");
|
|
37
39
|
var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_ref) {
|
|
@@ -50,10 +52,29 @@ var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_re
|
|
|
50
52
|
api: api
|
|
51
53
|
});
|
|
52
54
|
};
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_ref2) {
|
|
56
|
+
var api = _ref2.api;
|
|
57
|
+
var _useSharedPluginState2 = (0, _hooks.useSharedPluginState)(api, ['media']),
|
|
58
|
+
mediaState = _useSharedPluginState2.mediaState;
|
|
59
|
+
|
|
60
|
+
// Viewer does not have required attributes to render the media viewer
|
|
61
|
+
if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
var handleOnClose = function handleOnClose() {
|
|
65
|
+
// Run Command to hide the media viewer
|
|
66
|
+
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.hideMediaViewer);
|
|
67
|
+
};
|
|
68
|
+
return /*#__PURE__*/_react.default.createElement(_PortalWrapper.RenderMediaViewer, {
|
|
69
|
+
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
|
|
70
|
+
onClose: handleOnClose,
|
|
71
|
+
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
|
|
75
|
+
var _ref3$config = _ref3.config,
|
|
76
|
+
options = _ref3$config === void 0 ? {} : _ref3$config,
|
|
77
|
+
api = _ref3.api;
|
|
57
78
|
var previousMediaProvider;
|
|
58
79
|
return {
|
|
59
80
|
name: 'media',
|
|
@@ -75,22 +96,26 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
75
96
|
return false;
|
|
76
97
|
}
|
|
77
98
|
previousMediaProvider = provider;
|
|
78
|
-
return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (
|
|
79
|
-
var tr =
|
|
99
|
+
return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref4) {
|
|
100
|
+
var tr = _ref4.tr;
|
|
80
101
|
return tr.setMeta(_main.stateKey, {
|
|
81
102
|
mediaProvider: provider
|
|
82
103
|
});
|
|
83
104
|
})) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
|
|
84
105
|
}
|
|
85
106
|
},
|
|
107
|
+
commands: {
|
|
108
|
+
showMediaViewer: _commands.showMediaViewer,
|
|
109
|
+
hideMediaViewer: _commands.hideMediaViewer
|
|
110
|
+
},
|
|
86
111
|
nodes: function nodes() {
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
allowMediaGroup =
|
|
90
|
-
|
|
91
|
-
allowMediaSingle =
|
|
92
|
-
allowCaptions =
|
|
93
|
-
mediaFeatureFlags =
|
|
112
|
+
var _ref5 = options || {},
|
|
113
|
+
_ref5$allowMediaGroup = _ref5.allowMediaGroup,
|
|
114
|
+
allowMediaGroup = _ref5$allowMediaGroup === void 0 ? true : _ref5$allowMediaGroup,
|
|
115
|
+
_ref5$allowMediaSingl = _ref5.allowMediaSingle,
|
|
116
|
+
allowMediaSingle = _ref5$allowMediaSingl === void 0 ? false : _ref5$allowMediaSingl,
|
|
117
|
+
allowCaptions = _ref5.allowCaptions,
|
|
118
|
+
mediaFeatureFlags = _ref5.featureFlags;
|
|
94
119
|
var allowMediaInline = (0, _mediaCommon.getMediaFeatureFlag)('mediaInline', mediaFeatureFlags);
|
|
95
120
|
var mediaSingleOption = (0, _platformFeatureFlags.fg)('platform.editor.media.extended-resize-experience') ? {
|
|
96
121
|
withCaption: allowCaptions,
|
|
@@ -127,15 +152,15 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
127
152
|
pmPlugins: function pmPlugins() {
|
|
128
153
|
var pmPlugins = [{
|
|
129
154
|
name: 'media',
|
|
130
|
-
plugin: function plugin(
|
|
131
|
-
var schema =
|
|
132
|
-
dispatch =
|
|
133
|
-
getIntl =
|
|
134
|
-
eventDispatcher =
|
|
135
|
-
providerFactory =
|
|
136
|
-
errorReporter =
|
|
137
|
-
portalProviderAPI =
|
|
138
|
-
dispatchAnalyticsEvent =
|
|
155
|
+
plugin: function plugin(_ref6) {
|
|
156
|
+
var schema = _ref6.schema,
|
|
157
|
+
dispatch = _ref6.dispatch,
|
|
158
|
+
getIntl = _ref6.getIntl,
|
|
159
|
+
eventDispatcher = _ref6.eventDispatcher,
|
|
160
|
+
providerFactory = _ref6.providerFactory,
|
|
161
|
+
errorReporter = _ref6.errorReporter,
|
|
162
|
+
portalProviderAPI = _ref6.portalProviderAPI,
|
|
163
|
+
dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
|
|
139
164
|
return (0, _main.createPlugin)(schema, {
|
|
140
165
|
providerFactory: providerFactory,
|
|
141
166
|
nodeViews: {
|
|
@@ -154,17 +179,17 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
154
179
|
}
|
|
155
180
|
}, {
|
|
156
181
|
name: 'mediaKeymap',
|
|
157
|
-
plugin: function plugin(
|
|
182
|
+
plugin: function plugin(_ref7) {
|
|
158
183
|
var _api$analytics2, _api$selection;
|
|
159
|
-
var getIntl =
|
|
184
|
+
var getIntl = _ref7.getIntl;
|
|
160
185
|
return (0, _keymap2.default)(options, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.actions, api === null || api === void 0 ? void 0 : api.width, getIntl);
|
|
161
186
|
}
|
|
162
187
|
}];
|
|
163
188
|
if (options && options.allowMediaSingle) {
|
|
164
189
|
pmPlugins.push({
|
|
165
190
|
name: 'mediaSingleKeymap',
|
|
166
|
-
plugin: function plugin(
|
|
167
|
-
var schema =
|
|
191
|
+
plugin: function plugin(_ref8) {
|
|
192
|
+
var schema = _ref8.schema;
|
|
168
193
|
return (0, _keymapMedia.default)(schema);
|
|
169
194
|
}
|
|
170
195
|
});
|
|
@@ -176,9 +201,9 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
176
201
|
});
|
|
177
202
|
pmPlugins.push({
|
|
178
203
|
name: 'mediaAltTextKeymap',
|
|
179
|
-
plugin: function plugin(
|
|
204
|
+
plugin: function plugin(_ref9) {
|
|
180
205
|
var _api$analytics3;
|
|
181
|
-
var schema =
|
|
206
|
+
var schema = _ref9.schema;
|
|
182
207
|
return (0, _keymap.default)(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
|
|
183
208
|
}
|
|
184
209
|
});
|
|
@@ -186,15 +211,15 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
186
211
|
if (options && options.allowLinking) {
|
|
187
212
|
pmPlugins.push({
|
|
188
213
|
name: 'mediaLinking',
|
|
189
|
-
plugin: function plugin(
|
|
190
|
-
var dispatch =
|
|
214
|
+
plugin: function plugin(_ref10) {
|
|
215
|
+
var dispatch = _ref10.dispatch;
|
|
191
216
|
return (0, _linking.default)(dispatch);
|
|
192
217
|
}
|
|
193
218
|
});
|
|
194
219
|
pmPlugins.push({
|
|
195
220
|
name: 'mediaLinkingKeymap',
|
|
196
|
-
plugin: function plugin(
|
|
197
|
-
var schema =
|
|
221
|
+
plugin: function plugin(_ref11) {
|
|
222
|
+
var schema = _ref11.schema;
|
|
198
223
|
return (0, _keymap3.default)(schema);
|
|
199
224
|
}
|
|
200
225
|
});
|
|
@@ -230,19 +255,21 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
230
255
|
});
|
|
231
256
|
return pmPlugins;
|
|
232
257
|
},
|
|
233
|
-
contentComponent: function contentComponent(
|
|
234
|
-
var editorView =
|
|
235
|
-
appearance =
|
|
236
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
258
|
+
contentComponent: function contentComponent(_ref12) {
|
|
259
|
+
var editorView = _ref12.editorView,
|
|
260
|
+
appearance = _ref12.appearance;
|
|
261
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _platformFeatureFlags.fg)('platform_editor_media_previewer_bugfix') && /*#__PURE__*/_react.default.createElement(MediaViewerFunctionalComponent, {
|
|
262
|
+
api: api
|
|
263
|
+
}), /*#__PURE__*/_react.default.createElement(MediaPickerFunctionalComponent, {
|
|
237
264
|
editorDomElement: editorView.dom,
|
|
238
265
|
appearance: appearance,
|
|
239
266
|
api: api
|
|
240
|
-
});
|
|
267
|
+
}));
|
|
241
268
|
},
|
|
242
|
-
secondaryToolbarComponent: function secondaryToolbarComponent(
|
|
243
|
-
var editorView =
|
|
244
|
-
eventDispatcher =
|
|
245
|
-
disabled =
|
|
269
|
+
secondaryToolbarComponent: function secondaryToolbarComponent(_ref13) {
|
|
270
|
+
var editorView = _ref13.editorView,
|
|
271
|
+
eventDispatcher = _ref13.eventDispatcher,
|
|
272
|
+
disabled = _ref13.disabled;
|
|
246
273
|
return /*#__PURE__*/_react.default.createElement(_ToolbarMedia.default, {
|
|
247
274
|
isDisabled: disabled,
|
|
248
275
|
isReducedSpacing: true,
|
|
@@ -250,8 +277,8 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref2) {
|
|
|
250
277
|
});
|
|
251
278
|
},
|
|
252
279
|
pluginsOptions: {
|
|
253
|
-
quickInsert: function quickInsert(
|
|
254
|
-
var formatMessage =
|
|
280
|
+
quickInsert: function quickInsert(_ref14) {
|
|
281
|
+
var formatMessage = _ref14.formatMessage;
|
|
255
282
|
return (0, _experiments.editorExperiment)('add-media-from-url', true) ? [] : [{
|
|
256
283
|
id: 'media',
|
|
257
284
|
title: formatMessage(_messages.toolbarInsertBlockMessages.mediaFiles),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showMediaViewer = exports.hideMediaViewer = void 0;
|
|
7
|
+
var _actions = require("../pm-plugins/actions");
|
|
8
|
+
var _pluginKey = require("../pm-plugins/plugin-key");
|
|
9
|
+
var showMediaViewer = exports.showMediaViewer = function showMediaViewer(media) {
|
|
10
|
+
return function (_ref) {
|
|
11
|
+
var tr = _ref.tr;
|
|
12
|
+
tr.setMeta(_pluginKey.stateKey, {
|
|
13
|
+
type: _actions.ACTIONS.SHOW_MEDIA_VIEWER,
|
|
14
|
+
mediaViewerSelectedMedia: media,
|
|
15
|
+
isMediaViewerVisible: true
|
|
16
|
+
});
|
|
17
|
+
return tr;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var hideMediaViewer = exports.hideMediaViewer = function hideMediaViewer(_ref2) {
|
|
21
|
+
var tr = _ref2.tr;
|
|
22
|
+
tr.setMeta(_pluginKey.stateKey, {
|
|
23
|
+
type: _actions.ACTIONS.HIDE_MEDIA_VIEWER,
|
|
24
|
+
mediaViewerSelectedMedia: null,
|
|
25
|
+
isMediaViewerVisible: false
|
|
26
|
+
});
|
|
27
|
+
return tr;
|
|
28
|
+
};
|
|
@@ -42,6 +42,7 @@ var _mediaCommon2 = require("../utils/media-common");
|
|
|
42
42
|
var _mediaFiles = require("../utils/media-files");
|
|
43
43
|
var _mediaInline2 = require("../utils/media-inline");
|
|
44
44
|
var _mediaSingle2 = require("../utils/media-single");
|
|
45
|
+
var _actions = require("./actions");
|
|
45
46
|
var _mediaTaskManager = require("./mediaTaskManager");
|
|
46
47
|
var _pluginKey = require("./plugin-key");
|
|
47
48
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -781,6 +782,19 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
|
|
|
781
782
|
nextPluginState = nextPluginState.clone();
|
|
782
783
|
}
|
|
783
784
|
|
|
785
|
+
// ACTIONS
|
|
786
|
+
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
787
|
+
case _actions.ACTIONS.SHOW_MEDIA_VIEWER:
|
|
788
|
+
pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
|
|
789
|
+
pluginState.isMediaViewerVisible = true;
|
|
790
|
+
nextPluginState = nextPluginState.clone();
|
|
791
|
+
break;
|
|
792
|
+
case _actions.ACTIONS.HIDE_MEDIA_VIEWER:
|
|
793
|
+
pluginState.mediaViewerSelectedMedia = undefined;
|
|
794
|
+
nextPluginState = nextPluginState.clone();
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
|
|
784
798
|
// NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
|
|
785
799
|
// throughout the lifetime of view. We injected the view into the plugin state, because we dispatch()
|
|
786
800
|
// transformations from within the plugin state (i.e. when adding a new file).
|
|
@@ -15,6 +15,7 @@ var _PortalWrapper = require("../ui/MediaViewer/PortalWrapper");
|
|
|
15
15
|
var _utils = require("./utils");
|
|
16
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
// This function will eventially be removed when platform_editor_media_previewer_bugfix is cleaned up
|
|
18
19
|
var FilePreviewItem = exports.FilePreviewItem = function FilePreviewItem(_ref) {
|
|
19
20
|
var mediaPluginState = _ref.mediaPluginState,
|
|
20
21
|
intl = _ref.intl;
|
|
@@ -22,7 +23,7 @@ var FilePreviewItem = exports.FilePreviewItem = function FilePreviewItem(_ref) {
|
|
|
22
23
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
23
24
|
isMediaViewerVisible = _useState2[0],
|
|
24
25
|
setMediaViewerVisible = _useState2[1];
|
|
25
|
-
var
|
|
26
|
+
var showMediaViewer = function showMediaViewer() {
|
|
26
27
|
setMediaViewerVisible(true);
|
|
27
28
|
};
|
|
28
29
|
var onMediaViewerClose = function onMediaViewerClose() {
|
|
@@ -34,7 +35,7 @@ var FilePreviewItem = exports.FilePreviewItem = function FilePreviewItem(_ref) {
|
|
|
34
35
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ui.FloatingToolbarButton, {
|
|
35
36
|
testId: "file-preview-toolbar-button",
|
|
36
37
|
key: "editor.media.card.preview",
|
|
37
|
-
onClick:
|
|
38
|
+
onClick: showMediaViewer,
|
|
38
39
|
icon: /*#__PURE__*/_react.default.createElement(_filePreview.default, {
|
|
39
40
|
label: "file preview"
|
|
40
41
|
}),
|
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.generateFilePreviewItem = exports.floatingToolbar = void 0;
|
|
8
|
+
exports.handleShowMediaViewer = exports.generateFilePreviewItem = exports.floatingToolbar = void 0;
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -19,6 +19,7 @@ var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
|
19
19
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
20
20
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
21
21
|
var _download = _interopRequireDefault(require("@atlaskit/icon/glyph/download"));
|
|
22
|
+
var _filePreview = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/file-preview"));
|
|
22
23
|
var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
|
|
23
24
|
var _mediaFilmstrip = require("@atlaskit/media-filmstrip");
|
|
24
25
|
var _mediaUi = require("@atlaskit/media-ui");
|
|
@@ -81,7 +82,16 @@ var generateFilePreviewItem = exports.generateFilePreviewItem = function generat
|
|
|
81
82
|
supportsViewMode: true
|
|
82
83
|
};
|
|
83
84
|
};
|
|
84
|
-
var
|
|
85
|
+
var handleShowMediaViewer = exports.handleShowMediaViewer = function handleShowMediaViewer(_ref) {
|
|
86
|
+
var api = _ref.api,
|
|
87
|
+
mediaPluginState = _ref.mediaPluginState;
|
|
88
|
+
var selectedNodeAttrs = (0, _utils2.getSelectedNearestMediaContainerNodeAttrs)(mediaPluginState);
|
|
89
|
+
if (!selectedNodeAttrs) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.showMediaViewer(selectedNodeAttrs));
|
|
93
|
+
};
|
|
94
|
+
var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, editorAnalyticsAPI, forceFocusSelector, isViewOnly) {
|
|
85
95
|
if (isViewOnly) {
|
|
86
96
|
return [];
|
|
87
97
|
}
|
|
@@ -112,7 +122,19 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
|
|
|
112
122
|
className: 'thumbnail-appearance' // a11y. uses to force focus on item
|
|
113
123
|
}, {
|
|
114
124
|
type: 'separator'
|
|
115
|
-
},
|
|
125
|
+
}, (0, _platformFeatureFlags.fg)('platform_editor_media_previewer_bugfix') ? {
|
|
126
|
+
id: 'editor.media.viewer',
|
|
127
|
+
type: 'button',
|
|
128
|
+
icon: _filePreview.default,
|
|
129
|
+
title: intl.formatMessage(_mediaUi.messages.preview),
|
|
130
|
+
onClick: function onClick() {
|
|
131
|
+
var _handleShowMediaViewe;
|
|
132
|
+
return (_handleShowMediaViewe = handleShowMediaViewer({
|
|
133
|
+
mediaPluginState: mediaPluginState,
|
|
134
|
+
api: pluginInjectionApi
|
|
135
|
+
})) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
|
|
136
|
+
}
|
|
137
|
+
} : generateFilePreviewItem(mediaPluginState, intl), {
|
|
116
138
|
type: 'separator'
|
|
117
139
|
}, {
|
|
118
140
|
id: 'editor.media.card.download',
|
|
@@ -167,8 +189,8 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
167
189
|
isViewOnly = options.isViewOnly;
|
|
168
190
|
var editorFeatureFlags = getEditorFeatureFlags ? getEditorFeatureFlags() : undefined;
|
|
169
191
|
var toolbarButtons = [];
|
|
170
|
-
var
|
|
171
|
-
hoverDecoration =
|
|
192
|
+
var _ref2 = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
|
|
193
|
+
hoverDecoration = _ref2.hoverDecoration;
|
|
172
194
|
if ((0, _imageBorder.shouldShowImageBorder)(state)) {
|
|
173
195
|
toolbarButtons.push({
|
|
174
196
|
type: 'custom',
|
|
@@ -343,10 +365,10 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
343
365
|
hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
|
|
344
366
|
}
|
|
345
367
|
},
|
|
346
|
-
onSubmit: function onSubmit(
|
|
368
|
+
onSubmit: function onSubmit(_ref3) {
|
|
347
369
|
var _pluginInjectionApi$a5;
|
|
348
|
-
var width =
|
|
349
|
-
validation =
|
|
370
|
+
var width = _ref3.width,
|
|
371
|
+
validation = _ref3.validation;
|
|
350
372
|
var newLayout = (0, _utils2.calcNewLayout)(width, layout, contentWidth, options.fullWidthEnabled, isNested);
|
|
351
373
|
(0, _commands.updateMediaSingleWidth)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a5 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a5 === void 0 ? void 0 : _pluginInjectionApi$a5.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
|
|
352
374
|
},
|
|
@@ -444,7 +466,19 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
444
466
|
var _selectedMediaSingleNode = (0, _utils2.getSelectedMediaSingle)(state);
|
|
445
467
|
var mediaNode = _selectedMediaSingleNode === null || _selectedMediaSingleNode === void 0 ? void 0 : _selectedMediaSingleNode.node.content.firstChild;
|
|
446
468
|
if (!(0, _mediaSingle2.isVideo)(mediaNode === null || mediaNode === void 0 || (_mediaNode$attrs = mediaNode.attrs) === null || _mediaNode$attrs === void 0 ? void 0 : _mediaNode$attrs.__fileMimeType)) {
|
|
447
|
-
toolbarButtons.push(
|
|
469
|
+
toolbarButtons.push((0, _platformFeatureFlags.fg)('platform_editor_media_previewer_bugfix') ? {
|
|
470
|
+
id: 'editor.media.viewer',
|
|
471
|
+
type: 'button',
|
|
472
|
+
icon: _filePreview.default,
|
|
473
|
+
title: intl.formatMessage(_mediaUi.messages.preview),
|
|
474
|
+
onClick: function onClick() {
|
|
475
|
+
var _handleShowMediaViewe2;
|
|
476
|
+
return (_handleShowMediaViewe2 = handleShowMediaViewer({
|
|
477
|
+
api: pluginInjectionApi,
|
|
478
|
+
mediaPluginState: pluginState
|
|
479
|
+
})) !== null && _handleShowMediaViewe2 !== void 0 ? _handleShowMediaViewe2 : false;
|
|
480
|
+
}
|
|
481
|
+
} : generateFilePreviewItem(pluginState, intl), {
|
|
448
482
|
type: 'separator',
|
|
449
483
|
supportsViewMode: true
|
|
450
484
|
});
|
|
@@ -528,8 +562,8 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
528
562
|
isViewOnly = options.isViewOnly;
|
|
529
563
|
var mediaPluginState = _pluginKey.stateKey.getState(state);
|
|
530
564
|
var mediaLinkingState = (0, _linking2.getMediaLinkingState)(state);
|
|
531
|
-
var
|
|
532
|
-
hoverDecoration =
|
|
565
|
+
var _ref4 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
|
|
566
|
+
hoverDecoration = _ref4.hoverDecoration;
|
|
533
567
|
if (!mediaPluginState) {
|
|
534
568
|
return;
|
|
535
569
|
}
|
|
@@ -571,7 +605,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
571
605
|
var selector = (0, _mediaFilmstrip.mediaFilmstripItemDOMSelector)(mediaOffset);
|
|
572
606
|
return (_mediaPluginState$ele = mediaPluginState.element) === null || _mediaPluginState$ele === void 0 ? void 0 : _mediaPluginState$ele.querySelector(selector);
|
|
573
607
|
};
|
|
574
|
-
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.forceFocusSelector, isViewOnly);
|
|
608
|
+
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.forceFocusSelector, isViewOnly);
|
|
575
609
|
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
576
610
|
items = (0, _mediaInline2.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
|
|
577
611
|
} else {
|
|
@@ -12,6 +12,7 @@ var _card = require("@atlaskit/editor-common/card");
|
|
|
12
12
|
var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
|
|
13
13
|
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
14
14
|
var _download = _interopRequireDefault(require("@atlaskit/icon/glyph/download"));
|
|
15
|
+
var _filePreview = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/file-preview"));
|
|
15
16
|
var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
|
|
16
17
|
var _mediaUi = require("@atlaskit/media-ui");
|
|
17
18
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
@@ -227,7 +228,19 @@ var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl
|
|
|
227
228
|
|
|
228
229
|
//Image Preview
|
|
229
230
|
if (options.allowImagePreview) {
|
|
230
|
-
inlineImageItems.push((0,
|
|
231
|
+
inlineImageItems.push((0, _platformFeatureFlags.fg)('platform_editor_media_previewer_bugfix') ? {
|
|
232
|
+
id: 'editor.media.viewer',
|
|
233
|
+
type: 'button',
|
|
234
|
+
icon: _filePreview.default,
|
|
235
|
+
title: intl.formatMessage(_mediaUi.messages.preview),
|
|
236
|
+
onClick: function onClick() {
|
|
237
|
+
var _handleShowMediaViewe;
|
|
238
|
+
return (_handleShowMediaViewe = (0, _index.handleShowMediaViewer)({
|
|
239
|
+
mediaPluginState: mediaPluginState,
|
|
240
|
+
api: pluginInjectionApi
|
|
241
|
+
})) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
|
|
242
|
+
}
|
|
243
|
+
} : (0, _index.generateFilePreviewItem)(mediaPluginState, intl), {
|
|
231
244
|
type: 'separator',
|
|
232
245
|
supportsViewMode: true
|
|
233
246
|
});
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -14,6 +14,7 @@ import { lazyMediaInlineView } from './nodeviews/lazy-media-inline';
|
|
|
14
14
|
import { lazyMediaSingleView } from './nodeviews/lazy-media-single';
|
|
15
15
|
import { createPlugin as createMediaAltTextPlugin } from './pm-plugins/alt-text';
|
|
16
16
|
import keymapMediaAltTextPlugin from './pm-plugins/alt-text/keymap';
|
|
17
|
+
import { hideMediaViewer, showMediaViewer } from './pm-plugins/commands';
|
|
17
18
|
import keymapPlugin from './pm-plugins/keymap';
|
|
18
19
|
import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
|
|
19
20
|
import linkingPlugin from './pm-plugins/linking';
|
|
@@ -25,6 +26,7 @@ import { mediaInlineSpecWithFixedToDOM } from './toDOM-fixes/mediaInline';
|
|
|
25
26
|
import { mediaSingleSpecWithFixedToDOM } from './toDOM-fixes/mediaSingle';
|
|
26
27
|
import { floatingToolbar } from './toolbar';
|
|
27
28
|
import { MediaPickerComponents } from './ui/MediaPicker';
|
|
29
|
+
import { RenderMediaViewer } from './ui/MediaViewer/PortalWrapper';
|
|
28
30
|
import ToolbarMedia from './ui/ToolbarMedia';
|
|
29
31
|
import { insertMediaAsMediaSingle } from './utils/media-single';
|
|
30
32
|
const MediaPickerFunctionalComponent = ({
|
|
@@ -45,6 +47,27 @@ const MediaPickerFunctionalComponent = ({
|
|
|
45
47
|
api: api
|
|
46
48
|
});
|
|
47
49
|
};
|
|
50
|
+
const MediaViewerFunctionalComponent = ({
|
|
51
|
+
api
|
|
52
|
+
}) => {
|
|
53
|
+
const {
|
|
54
|
+
mediaState
|
|
55
|
+
} = useSharedPluginState(api, ['media']);
|
|
56
|
+
|
|
57
|
+
// Viewer does not have required attributes to render the media viewer
|
|
58
|
+
if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const handleOnClose = () => {
|
|
62
|
+
// Run Command to hide the media viewer
|
|
63
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.hideMediaViewer);
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/React.createElement(RenderMediaViewer, {
|
|
66
|
+
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
|
|
67
|
+
onClose: handleOnClose,
|
|
68
|
+
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
|
|
69
|
+
});
|
|
70
|
+
};
|
|
48
71
|
export const mediaPlugin = ({
|
|
49
72
|
config: options = {},
|
|
50
73
|
api
|
|
@@ -77,6 +100,10 @@ export const mediaPlugin = ({
|
|
|
77
100
|
}))) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
|
|
78
101
|
}
|
|
79
102
|
},
|
|
103
|
+
commands: {
|
|
104
|
+
showMediaViewer,
|
|
105
|
+
hideMediaViewer
|
|
106
|
+
},
|
|
80
107
|
nodes() {
|
|
81
108
|
const {
|
|
82
109
|
allowMediaGroup = true,
|
|
@@ -232,11 +259,13 @@ export const mediaPlugin = ({
|
|
|
232
259
|
editorView,
|
|
233
260
|
appearance
|
|
234
261
|
}) {
|
|
235
|
-
return /*#__PURE__*/React.createElement(
|
|
262
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, fg('platform_editor_media_previewer_bugfix') && /*#__PURE__*/React.createElement(MediaViewerFunctionalComponent, {
|
|
263
|
+
api: api
|
|
264
|
+
}), /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
|
|
236
265
|
editorDomElement: editorView.dom,
|
|
237
266
|
appearance: appearance,
|
|
238
267
|
api: api
|
|
239
|
-
});
|
|
268
|
+
}));
|
|
240
269
|
},
|
|
241
270
|
secondaryToolbarComponent({
|
|
242
271
|
editorView,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ACTIONS } from '../pm-plugins/actions';
|
|
2
|
+
import { stateKey } from '../pm-plugins/plugin-key';
|
|
3
|
+
export const showMediaViewer = media => ({
|
|
4
|
+
tr
|
|
5
|
+
}) => {
|
|
6
|
+
tr.setMeta(stateKey, {
|
|
7
|
+
type: ACTIONS.SHOW_MEDIA_VIEWER,
|
|
8
|
+
mediaViewerSelectedMedia: media,
|
|
9
|
+
isMediaViewerVisible: true
|
|
10
|
+
});
|
|
11
|
+
return tr;
|
|
12
|
+
};
|
|
13
|
+
export const hideMediaViewer = ({
|
|
14
|
+
tr
|
|
15
|
+
}) => {
|
|
16
|
+
tr.setMeta(stateKey, {
|
|
17
|
+
type: ACTIONS.HIDE_MEDIA_VIEWER,
|
|
18
|
+
mediaViewerSelectedMedia: null,
|
|
19
|
+
isMediaViewerVisible: false
|
|
20
|
+
});
|
|
21
|
+
return tr;
|
|
22
|
+
};
|
|
@@ -24,6 +24,7 @@ import { removeMediaNode, splitMediaGroup } from '../utils/media-common';
|
|
|
24
24
|
import { insertMediaGroupNode, insertMediaInlineNode } from '../utils/media-files';
|
|
25
25
|
import { getMediaNodeInsertionType } from '../utils/media-inline';
|
|
26
26
|
import { insertMediaSingleNode } from '../utils/media-single';
|
|
27
|
+
import { ACTIONS } from './actions';
|
|
27
28
|
import { MediaTaskManager } from './mediaTaskManager';
|
|
28
29
|
import { stateKey } from './plugin-key';
|
|
29
30
|
export { stateKey } from './plugin-key';
|
|
@@ -668,6 +669,19 @@ export const createPlugin = (_schema, options, getIntl, pluginInjectionApi, disp
|
|
|
668
669
|
nextPluginState = nextPluginState.clone();
|
|
669
670
|
}
|
|
670
671
|
|
|
672
|
+
// ACTIONS
|
|
673
|
+
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
674
|
+
case ACTIONS.SHOW_MEDIA_VIEWER:
|
|
675
|
+
pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
|
|
676
|
+
pluginState.isMediaViewerVisible = true;
|
|
677
|
+
nextPluginState = nextPluginState.clone();
|
|
678
|
+
break;
|
|
679
|
+
case ACTIONS.HIDE_MEDIA_VIEWER:
|
|
680
|
+
pluginState.mediaViewerSelectedMedia = undefined;
|
|
681
|
+
nextPluginState = nextPluginState.clone();
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
|
|
671
685
|
// NOTE: We're not calling passing new state to the Editor, because we depend on the view.state reference
|
|
672
686
|
// throughout the lifetime of view. We injected the view into the plugin state, because we dispatch()
|
|
673
687
|
// transformations from within the plugin state (i.e. when adding a new file).
|
|
@@ -4,12 +4,13 @@ import FilePreviewIcon from '@atlaskit/icon/glyph/editor/file-preview';
|
|
|
4
4
|
import { messages } from '@atlaskit/media-ui';
|
|
5
5
|
import { RenderMediaViewer } from '../ui/MediaViewer/PortalWrapper';
|
|
6
6
|
import { getSelectedNearestMediaContainerNodeAttrs } from './utils';
|
|
7
|
+
// This function will eventially be removed when platform_editor_media_previewer_bugfix is cleaned up
|
|
7
8
|
export const FilePreviewItem = ({
|
|
8
9
|
mediaPluginState,
|
|
9
10
|
intl
|
|
10
11
|
}) => {
|
|
11
12
|
const [isMediaViewerVisible, setMediaViewerVisible] = useState(false);
|
|
12
|
-
const
|
|
13
|
+
const showMediaViewer = () => {
|
|
13
14
|
setMediaViewerVisible(true);
|
|
14
15
|
};
|
|
15
16
|
const onMediaViewerClose = () => {
|
|
@@ -21,7 +22,7 @@ export const FilePreviewItem = ({
|
|
|
21
22
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ToolbarButton, {
|
|
22
23
|
testId: "file-preview-toolbar-button",
|
|
23
24
|
key: "editor.media.card.preview",
|
|
24
|
-
onClick:
|
|
25
|
+
onClick: showMediaViewer,
|
|
25
26
|
icon: /*#__PURE__*/React.createElement(FilePreviewIcon, {
|
|
26
27
|
label: "file preview"
|
|
27
28
|
}),
|