@atlaskit/editor-plugin-media 1.37.0 → 1.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/plugin.js +22 -4
- package/dist/cjs/pm-plugins/main.js +2 -1
- package/dist/cjs/ui/MediaViewer/PortalWrapper.js +4 -2
- package/dist/cjs/utils/media-common.js +51 -1
- package/dist/es2019/plugin.js +19 -4
- package/dist/es2019/pm-plugins/main.js +2 -1
- package/dist/es2019/ui/MediaViewer/PortalWrapper.js +3 -2
- package/dist/es2019/utils/media-common.js +50 -1
- package/dist/esm/plugin.js +19 -4
- package/dist/esm/pm-plugins/main.js +2 -1
- package/dist/esm/ui/MediaViewer/PortalWrapper.js +4 -2
- package/dist/esm/utils/media-common.js +50 -1
- package/dist/types/ui/MediaViewer/PortalWrapper.d.ts +3 -2
- package/dist/types/utils/media-common.d.ts +5 -0
- package/dist/types-ts4.5/ui/MediaViewer/PortalWrapper.d.ts +3 -2
- package/dist/types-ts4.5/utils/media-common.d.ts +5 -0
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 1.37.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#155735](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/155735)
|
|
8
|
+
[`1beeeda29023a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1beeeda29023a) -
|
|
9
|
+
Upgrades editor packages to react 18
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 1.37.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#155195](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/155195)
|
|
17
|
+
[`086e77aecf6e5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/086e77aecf6e5) -
|
|
18
|
+
[ux] ED-25202 Support Preview in media files
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 1.37.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
8
|
exports.mediaPlugin = void 0;
|
|
8
|
-
var _react =
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
11
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
@@ -35,7 +36,10 @@ var _toolbar = require("./toolbar");
|
|
|
35
36
|
var _MediaPicker = require("./ui/MediaPicker");
|
|
36
37
|
var _PortalWrapper = require("./ui/MediaViewer/PortalWrapper");
|
|
37
38
|
var _ToolbarMedia = _interopRequireDefault(require("./ui/ToolbarMedia"));
|
|
39
|
+
var _mediaCommon2 = require("./utils/media-common");
|
|
38
40
|
var _mediaSingle2 = require("./utils/media-single");
|
|
41
|
+
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); }
|
|
42
|
+
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; }
|
|
39
43
|
var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_ref) {
|
|
40
44
|
var api = _ref.api,
|
|
41
45
|
editorDomElement = _ref.editorDomElement,
|
|
@@ -53,10 +57,22 @@ var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_re
|
|
|
53
57
|
});
|
|
54
58
|
};
|
|
55
59
|
var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_ref2) {
|
|
56
|
-
var api = _ref2.api
|
|
60
|
+
var api = _ref2.api,
|
|
61
|
+
editorView = _ref2.editorView;
|
|
57
62
|
var _useSharedPluginState2 = (0, _hooks.useSharedPluginState)(api, ['media']),
|
|
58
63
|
mediaState = _useSharedPluginState2.mediaState;
|
|
59
64
|
|
|
65
|
+
// Only traverse document once when media viewer is visible, media viewer items will not update
|
|
66
|
+
// when document changes are made while media viewer is open
|
|
67
|
+
|
|
68
|
+
var mediaItems = (0, _react.useMemo)(function () {
|
|
69
|
+
if (mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible && (0, _platformFeatureFlags.fg)('platform_editor_media_interaction_improvements')) {
|
|
70
|
+
var mediaNodes = (0, _mediaCommon2.extractMediaNodes)(editorView.state.doc);
|
|
71
|
+
return (0, _mediaCommon2.createMediaIdentifierArray)(mediaNodes);
|
|
72
|
+
}
|
|
73
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only update mediaItems once when media viewer is visible
|
|
74
|
+
}, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible]);
|
|
75
|
+
|
|
60
76
|
// Viewer does not have required attributes to render the media viewer
|
|
61
77
|
if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
|
|
62
78
|
return null;
|
|
@@ -68,7 +84,8 @@ var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_re
|
|
|
68
84
|
return /*#__PURE__*/_react.default.createElement(_PortalWrapper.RenderMediaViewer, {
|
|
69
85
|
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
|
|
70
86
|
onClose: handleOnClose,
|
|
71
|
-
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
|
|
87
|
+
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia,
|
|
88
|
+
items: (0, _platformFeatureFlags.fg)('platform_editor_media_interaction_improvements') ? mediaItems : undefined
|
|
72
89
|
});
|
|
73
90
|
};
|
|
74
91
|
var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
|
|
@@ -259,7 +276,8 @@ var mediaPlugin = exports.mediaPlugin = function mediaPlugin(_ref3) {
|
|
|
259
276
|
var editorView = _ref12.editorView,
|
|
260
277
|
appearance = _ref12.appearance;
|
|
261
278
|
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
|
|
279
|
+
api: api,
|
|
280
|
+
editorView: editorView
|
|
263
281
|
}), /*#__PURE__*/_react.default.createElement(MediaPickerFunctionalComponent, {
|
|
264
282
|
editorDomElement: editorView.dom,
|
|
265
283
|
appearance: appearance,
|
|
@@ -786,11 +786,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
|
|
|
786
786
|
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
787
787
|
case _actions.ACTIONS.SHOW_MEDIA_VIEWER:
|
|
788
788
|
pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
|
|
789
|
-
pluginState.isMediaViewerVisible =
|
|
789
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
790
790
|
nextPluginState = nextPluginState.clone();
|
|
791
791
|
break;
|
|
792
792
|
case _actions.ACTIONS.HIDE_MEDIA_VIEWER:
|
|
793
793
|
pluginState.mediaViewerSelectedMedia = undefined;
|
|
794
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
794
795
|
nextPluginState = nextPluginState.clone();
|
|
795
796
|
break;
|
|
796
797
|
}
|
|
@@ -30,13 +30,15 @@ var getIdentifier = function getIdentifier(attrs) {
|
|
|
30
30
|
var RenderMediaViewer = exports.RenderMediaViewer = function RenderMediaViewer(_ref) {
|
|
31
31
|
var mediaClientConfig = _ref.mediaClientConfig,
|
|
32
32
|
onClose = _ref.onClose,
|
|
33
|
-
selectedNodeAttrs = _ref.selectedNodeAttrs
|
|
33
|
+
selectedNodeAttrs = _ref.selectedNodeAttrs,
|
|
34
|
+
_ref$items = _ref.items,
|
|
35
|
+
items = _ref$items === void 0 ? [] : _ref$items;
|
|
34
36
|
if ((0, _experiments.editorExperiment)('add-media-from-url', true)) {
|
|
35
37
|
var _identifier = getIdentifier(selectedNodeAttrs);
|
|
36
38
|
var collectionName = (0, _utils.isExternalMedia)(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
|
|
37
39
|
return /*#__PURE__*/_reactDom.default.createPortal( /*#__PURE__*/_react.default.createElement(_mediaViewer.MediaViewer, {
|
|
38
40
|
collectionName: collectionName,
|
|
39
|
-
items:
|
|
41
|
+
items: items,
|
|
40
42
|
mediaClientConfig: mediaClientConfig,
|
|
41
43
|
selectedItem: _identifier,
|
|
42
44
|
onClose: onClose
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.splitMediaGroup = exports.removeMediaNode = exports.posOfPrecedingMediaGroup = exports.posOfParentMediaGroup = exports.posOfMediaGroupNearby = exports.isSelectionNonMediaBlockNode = exports.isSelectionMediaSingleNode = exports.isMediaSingleOrInlineNodeSelected = exports.isMediaBlobUrlFromAttrs = exports.isInsidePotentialEmptyParagraph = exports.getMediaSingleOrInlineNodeFromSelection = exports.getMediaNodeFromSelection = exports.getMediaFromSupportedMediaNodesFromSelection = exports.copyOptionalAttrsFromMediaState = void 0;
|
|
7
|
+
exports.splitMediaGroup = exports.removeMediaNode = exports.posOfPrecedingMediaGroup = exports.posOfParentMediaGroup = exports.posOfMediaGroupNearby = exports.isSelectionNonMediaBlockNode = exports.isSelectionMediaSingleNode = exports.isMediaSingleOrInlineNodeSelected = exports.isMediaBlobUrlFromAttrs = exports.isInsidePotentialEmptyParagraph = exports.getMediaSingleOrInlineNodeFromSelection = exports.getMediaNodeFromSelection = exports.getMediaFromSupportedMediaNodesFromSelection = exports.getIdentifier = exports.extractMediaNodes = exports.createMediaIdentifierArray = exports.copyOptionalAttrsFromMediaState = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
7
9
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
10
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
9
11
|
var _commands = require("@atlaskit/editor-prosemirror/commands");
|
|
@@ -11,6 +13,8 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
11
13
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
12
14
|
var _mediaClient = require("@atlaskit/media-client");
|
|
13
15
|
var _main = require("../pm-plugins/main");
|
|
16
|
+
var _utils3 = require("../toolbar/utils");
|
|
17
|
+
var _mediaSingle = require("./media-single");
|
|
14
18
|
var isTemporary = function isTemporary(id) {
|
|
15
19
|
return id.indexOf('temporary:') === 0;
|
|
16
20
|
};
|
|
@@ -218,4 +222,50 @@ var getMediaFromSupportedMediaNodesFromSelection = exports.getMediaFromSupported
|
|
|
218
222
|
default:
|
|
219
223
|
return null;
|
|
220
224
|
}
|
|
225
|
+
};
|
|
226
|
+
var getIdentifier = exports.getIdentifier = function getIdentifier(attrs) {
|
|
227
|
+
if ((0, _utils3.isExternalMedia)(attrs)) {
|
|
228
|
+
return {
|
|
229
|
+
mediaItemType: 'external-image',
|
|
230
|
+
dataURI: attrs.url
|
|
231
|
+
};
|
|
232
|
+
} else {
|
|
233
|
+
var id = attrs.id,
|
|
234
|
+
_attrs$collection = attrs.collection,
|
|
235
|
+
collection = _attrs$collection === void 0 ? '' : _attrs$collection;
|
|
236
|
+
return {
|
|
237
|
+
id: id,
|
|
238
|
+
mediaItemType: 'file',
|
|
239
|
+
collectionName: collection
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var extractMediaNodes = exports.extractMediaNodes = function extractMediaNodes(doc) {
|
|
244
|
+
var mediaNodes = [];
|
|
245
|
+
doc.descendants(function (node) {
|
|
246
|
+
if (node.type.name === 'media' || node.type.name === 'mediaInline') {
|
|
247
|
+
mediaNodes.push(node);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return mediaNodes;
|
|
251
|
+
};
|
|
252
|
+
var createMediaIdentifierArray = exports.createMediaIdentifierArray = function createMediaIdentifierArray(mediaNodes) {
|
|
253
|
+
var mediaIdentifierMap = new Map();
|
|
254
|
+
mediaNodes.forEach(function (item) {
|
|
255
|
+
var attrs = item.attrs;
|
|
256
|
+
if (!attrs) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if ((0, _mediaSingle.isVideo)(attrs.__fileMimeType)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
var identifier = getIdentifier(attrs);
|
|
263
|
+
|
|
264
|
+
// Add only if not already processed
|
|
265
|
+
var idKey = (0, _mediaClient.isExternalImageIdentifier)(identifier) ? identifier.dataURI : identifier.id;
|
|
266
|
+
if (!mediaIdentifierMap.has(idKey)) {
|
|
267
|
+
mediaIdentifierMap.set(idKey, identifier);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
return (0, _toConsumableArray2.default)(mediaIdentifierMap.values());
|
|
221
271
|
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
@@ -28,6 +28,7 @@ import { floatingToolbar } from './toolbar';
|
|
|
28
28
|
import { MediaPickerComponents } from './ui/MediaPicker';
|
|
29
29
|
import { RenderMediaViewer } from './ui/MediaViewer/PortalWrapper';
|
|
30
30
|
import ToolbarMedia from './ui/ToolbarMedia';
|
|
31
|
+
import { createMediaIdentifierArray, extractMediaNodes } from './utils/media-common';
|
|
31
32
|
import { insertMediaAsMediaSingle } from './utils/media-single';
|
|
32
33
|
const MediaPickerFunctionalComponent = ({
|
|
33
34
|
api,
|
|
@@ -48,12 +49,24 @@ const MediaPickerFunctionalComponent = ({
|
|
|
48
49
|
});
|
|
49
50
|
};
|
|
50
51
|
const MediaViewerFunctionalComponent = ({
|
|
51
|
-
api
|
|
52
|
+
api,
|
|
53
|
+
editorView
|
|
52
54
|
}) => {
|
|
53
55
|
const {
|
|
54
56
|
mediaState
|
|
55
57
|
} = useSharedPluginState(api, ['media']);
|
|
56
58
|
|
|
59
|
+
// Only traverse document once when media viewer is visible, media viewer items will not update
|
|
60
|
+
// when document changes are made while media viewer is open
|
|
61
|
+
|
|
62
|
+
const mediaItems = useMemo(() => {
|
|
63
|
+
if (mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible && fg('platform_editor_media_interaction_improvements')) {
|
|
64
|
+
const mediaNodes = extractMediaNodes(editorView.state.doc);
|
|
65
|
+
return createMediaIdentifierArray(mediaNodes);
|
|
66
|
+
}
|
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only update mediaItems once when media viewer is visible
|
|
68
|
+
}, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible]);
|
|
69
|
+
|
|
57
70
|
// Viewer does not have required attributes to render the media viewer
|
|
58
71
|
if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
|
|
59
72
|
return null;
|
|
@@ -65,7 +78,8 @@ const MediaViewerFunctionalComponent = ({
|
|
|
65
78
|
return /*#__PURE__*/React.createElement(RenderMediaViewer, {
|
|
66
79
|
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
|
|
67
80
|
onClose: handleOnClose,
|
|
68
|
-
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
|
|
81
|
+
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia,
|
|
82
|
+
items: fg('platform_editor_media_interaction_improvements') ? mediaItems : undefined
|
|
69
83
|
});
|
|
70
84
|
};
|
|
71
85
|
export const mediaPlugin = ({
|
|
@@ -260,7 +274,8 @@ export const mediaPlugin = ({
|
|
|
260
274
|
appearance
|
|
261
275
|
}) {
|
|
262
276
|
return /*#__PURE__*/React.createElement(React.Fragment, null, fg('platform_editor_media_previewer_bugfix') && /*#__PURE__*/React.createElement(MediaViewerFunctionalComponent, {
|
|
263
|
-
api: api
|
|
277
|
+
api: api,
|
|
278
|
+
editorView: editorView
|
|
264
279
|
}), /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
|
|
265
280
|
editorDomElement: editorView.dom,
|
|
266
281
|
appearance: appearance,
|
|
@@ -673,11 +673,12 @@ export const createPlugin = (_schema, options, getIntl, pluginInjectionApi, disp
|
|
|
673
673
|
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
674
674
|
case ACTIONS.SHOW_MEDIA_VIEWER:
|
|
675
675
|
pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
|
|
676
|
-
pluginState.isMediaViewerVisible =
|
|
676
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
677
677
|
nextPluginState = nextPluginState.clone();
|
|
678
678
|
break;
|
|
679
679
|
case ACTIONS.HIDE_MEDIA_VIEWER:
|
|
680
680
|
pluginState.mediaViewerSelectedMedia = undefined;
|
|
681
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
681
682
|
nextPluginState = nextPluginState.clone();
|
|
682
683
|
break;
|
|
683
684
|
}
|
|
@@ -24,14 +24,15 @@ const getIdentifier = attrs => {
|
|
|
24
24
|
export const RenderMediaViewer = ({
|
|
25
25
|
mediaClientConfig,
|
|
26
26
|
onClose,
|
|
27
|
-
selectedNodeAttrs
|
|
27
|
+
selectedNodeAttrs,
|
|
28
|
+
items = []
|
|
28
29
|
}) => {
|
|
29
30
|
if (editorExperiment('add-media-from-url', true)) {
|
|
30
31
|
const identifier = getIdentifier(selectedNodeAttrs);
|
|
31
32
|
const collectionName = isExternalMedia(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
|
|
32
33
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
|
|
33
34
|
collectionName: collectionName,
|
|
34
|
-
items:
|
|
35
|
+
items: items,
|
|
35
36
|
mediaClientConfig: mediaClientConfig,
|
|
36
37
|
selectedItem: identifier,
|
|
37
38
|
onClose: onClose
|
|
@@ -3,8 +3,10 @@ import { createNewParagraphBelow, createParagraphNear } from '@atlaskit/editor-c
|
|
|
3
3
|
import { deleteSelection, splitBlock } from '@atlaskit/editor-prosemirror/commands';
|
|
4
4
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { findPositionOfNodeBefore } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
-
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
6
|
+
import { isExternalImageIdentifier, isMediaBlobUrl } from '@atlaskit/media-client';
|
|
7
7
|
import { getMediaPluginState } from '../pm-plugins/main';
|
|
8
|
+
import { isExternalMedia } from '../toolbar/utils';
|
|
9
|
+
import { isVideo } from './media-single';
|
|
8
10
|
const isTemporary = id => {
|
|
9
11
|
return id.indexOf('temporary:') === 0;
|
|
10
12
|
};
|
|
@@ -230,4 +232,51 @@ export const getMediaFromSupportedMediaNodesFromSelection = state => {
|
|
|
230
232
|
default:
|
|
231
233
|
return null;
|
|
232
234
|
}
|
|
235
|
+
};
|
|
236
|
+
export const getIdentifier = attrs => {
|
|
237
|
+
if (isExternalMedia(attrs)) {
|
|
238
|
+
return {
|
|
239
|
+
mediaItemType: 'external-image',
|
|
240
|
+
dataURI: attrs.url
|
|
241
|
+
};
|
|
242
|
+
} else {
|
|
243
|
+
const {
|
|
244
|
+
id,
|
|
245
|
+
collection = ''
|
|
246
|
+
} = attrs;
|
|
247
|
+
return {
|
|
248
|
+
id,
|
|
249
|
+
mediaItemType: 'file',
|
|
250
|
+
collectionName: collection
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
export const extractMediaNodes = doc => {
|
|
255
|
+
const mediaNodes = [];
|
|
256
|
+
doc.descendants(node => {
|
|
257
|
+
if (node.type.name === 'media' || node.type.name === 'mediaInline') {
|
|
258
|
+
mediaNodes.push(node);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return mediaNodes;
|
|
262
|
+
};
|
|
263
|
+
export const createMediaIdentifierArray = mediaNodes => {
|
|
264
|
+
const mediaIdentifierMap = new Map();
|
|
265
|
+
mediaNodes.forEach(item => {
|
|
266
|
+
const attrs = item.attrs;
|
|
267
|
+
if (!attrs) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (isVideo(attrs.__fileMimeType)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const identifier = getIdentifier(attrs);
|
|
274
|
+
|
|
275
|
+
// Add only if not already processed
|
|
276
|
+
const idKey = isExternalImageIdentifier(identifier) ? identifier.dataURI : identifier.id;
|
|
277
|
+
if (!mediaIdentifierMap.has(idKey)) {
|
|
278
|
+
mediaIdentifierMap.set(idKey, identifier);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return [...mediaIdentifierMap.values()];
|
|
233
282
|
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
@@ -28,6 +28,7 @@ import { floatingToolbar as _floatingToolbar } from './toolbar';
|
|
|
28
28
|
import { MediaPickerComponents } from './ui/MediaPicker';
|
|
29
29
|
import { RenderMediaViewer } from './ui/MediaViewer/PortalWrapper';
|
|
30
30
|
import ToolbarMedia from './ui/ToolbarMedia';
|
|
31
|
+
import { createMediaIdentifierArray, extractMediaNodes } from './utils/media-common';
|
|
31
32
|
import { insertMediaAsMediaSingle as _insertMediaAsMediaSingle } from './utils/media-single';
|
|
32
33
|
var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_ref) {
|
|
33
34
|
var api = _ref.api,
|
|
@@ -46,10 +47,22 @@ var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_re
|
|
|
46
47
|
});
|
|
47
48
|
};
|
|
48
49
|
var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_ref2) {
|
|
49
|
-
var api = _ref2.api
|
|
50
|
+
var api = _ref2.api,
|
|
51
|
+
editorView = _ref2.editorView;
|
|
50
52
|
var _useSharedPluginState2 = useSharedPluginState(api, ['media']),
|
|
51
53
|
mediaState = _useSharedPluginState2.mediaState;
|
|
52
54
|
|
|
55
|
+
// Only traverse document once when media viewer is visible, media viewer items will not update
|
|
56
|
+
// when document changes are made while media viewer is open
|
|
57
|
+
|
|
58
|
+
var mediaItems = useMemo(function () {
|
|
59
|
+
if (mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible && fg('platform_editor_media_interaction_improvements')) {
|
|
60
|
+
var mediaNodes = extractMediaNodes(editorView.state.doc);
|
|
61
|
+
return createMediaIdentifierArray(mediaNodes);
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only update mediaItems once when media viewer is visible
|
|
64
|
+
}, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible]);
|
|
65
|
+
|
|
53
66
|
// Viewer does not have required attributes to render the media viewer
|
|
54
67
|
if (!(mediaState !== null && mediaState !== void 0 && mediaState.isMediaViewerVisible) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaViewerSelectedMedia) || !(mediaState !== null && mediaState !== void 0 && mediaState.mediaClientConfig)) {
|
|
55
68
|
return null;
|
|
@@ -61,7 +74,8 @@ var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_re
|
|
|
61
74
|
return /*#__PURE__*/React.createElement(RenderMediaViewer, {
|
|
62
75
|
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig,
|
|
63
76
|
onClose: handleOnClose,
|
|
64
|
-
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia
|
|
77
|
+
selectedNodeAttrs: mediaState.mediaViewerSelectedMedia,
|
|
78
|
+
items: fg('platform_editor_media_interaction_improvements') ? mediaItems : undefined
|
|
65
79
|
});
|
|
66
80
|
};
|
|
67
81
|
export var mediaPlugin = function mediaPlugin(_ref3) {
|
|
@@ -252,7 +266,8 @@ export var mediaPlugin = function mediaPlugin(_ref3) {
|
|
|
252
266
|
var editorView = _ref12.editorView,
|
|
253
267
|
appearance = _ref12.appearance;
|
|
254
268
|
return /*#__PURE__*/React.createElement(React.Fragment, null, fg('platform_editor_media_previewer_bugfix') && /*#__PURE__*/React.createElement(MediaViewerFunctionalComponent, {
|
|
255
|
-
api: api
|
|
269
|
+
api: api,
|
|
270
|
+
editorView: editorView
|
|
256
271
|
}), /*#__PURE__*/React.createElement(MediaPickerFunctionalComponent, {
|
|
257
272
|
editorDomElement: editorView.dom,
|
|
258
273
|
appearance: appearance,
|
|
@@ -771,11 +771,12 @@ export var createPlugin = function createPlugin(_schema, options, getIntl, plugi
|
|
|
771
771
|
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
772
772
|
case ACTIONS.SHOW_MEDIA_VIEWER:
|
|
773
773
|
pluginState.mediaViewerSelectedMedia = meta.mediaViewerSelectedMedia;
|
|
774
|
-
pluginState.isMediaViewerVisible =
|
|
774
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
775
775
|
nextPluginState = nextPluginState.clone();
|
|
776
776
|
break;
|
|
777
777
|
case ACTIONS.HIDE_MEDIA_VIEWER:
|
|
778
778
|
pluginState.mediaViewerSelectedMedia = undefined;
|
|
779
|
+
pluginState.isMediaViewerVisible = meta.isMediaViewerVisible;
|
|
779
780
|
nextPluginState = nextPluginState.clone();
|
|
780
781
|
break;
|
|
781
782
|
}
|
|
@@ -23,13 +23,15 @@ var getIdentifier = function getIdentifier(attrs) {
|
|
|
23
23
|
export var RenderMediaViewer = function RenderMediaViewer(_ref) {
|
|
24
24
|
var mediaClientConfig = _ref.mediaClientConfig,
|
|
25
25
|
onClose = _ref.onClose,
|
|
26
|
-
selectedNodeAttrs = _ref.selectedNodeAttrs
|
|
26
|
+
selectedNodeAttrs = _ref.selectedNodeAttrs,
|
|
27
|
+
_ref$items = _ref.items,
|
|
28
|
+
items = _ref$items === void 0 ? [] : _ref$items;
|
|
27
29
|
if (editorExperiment('add-media-from-url', true)) {
|
|
28
30
|
var _identifier = getIdentifier(selectedNodeAttrs);
|
|
29
31
|
var collectionName = isExternalMedia(selectedNodeAttrs) ? '' : selectedNodeAttrs.collection;
|
|
30
32
|
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/React.createElement(MediaViewer, {
|
|
31
33
|
collectionName: collectionName,
|
|
32
|
-
items:
|
|
34
|
+
items: items,
|
|
33
35
|
mediaClientConfig: mediaClientConfig,
|
|
34
36
|
selectedItem: _identifier,
|
|
35
37
|
onClose: onClose
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
1
2
|
import { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, endPositionOfParent, GapCursorSelection, startPositionOfParent } from '@atlaskit/editor-common/selection';
|
|
2
3
|
import { createNewParagraphBelow, createParagraphNear } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { deleteSelection, splitBlock } from '@atlaskit/editor-prosemirror/commands';
|
|
4
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import { findPositionOfNodeBefore } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
-
import { isMediaBlobUrl } from '@atlaskit/media-client';
|
|
7
|
+
import { isExternalImageIdentifier, isMediaBlobUrl } from '@atlaskit/media-client';
|
|
7
8
|
import { getMediaPluginState } from '../pm-plugins/main';
|
|
9
|
+
import { isExternalMedia } from '../toolbar/utils';
|
|
10
|
+
import { isVideo } from './media-single';
|
|
8
11
|
var isTemporary = function isTemporary(id) {
|
|
9
12
|
return id.indexOf('temporary:') === 0;
|
|
10
13
|
};
|
|
@@ -212,4 +215,50 @@ export var getMediaFromSupportedMediaNodesFromSelection = function getMediaFromS
|
|
|
212
215
|
default:
|
|
213
216
|
return null;
|
|
214
217
|
}
|
|
218
|
+
};
|
|
219
|
+
export var getIdentifier = function getIdentifier(attrs) {
|
|
220
|
+
if (isExternalMedia(attrs)) {
|
|
221
|
+
return {
|
|
222
|
+
mediaItemType: 'external-image',
|
|
223
|
+
dataURI: attrs.url
|
|
224
|
+
};
|
|
225
|
+
} else {
|
|
226
|
+
var id = attrs.id,
|
|
227
|
+
_attrs$collection = attrs.collection,
|
|
228
|
+
collection = _attrs$collection === void 0 ? '' : _attrs$collection;
|
|
229
|
+
return {
|
|
230
|
+
id: id,
|
|
231
|
+
mediaItemType: 'file',
|
|
232
|
+
collectionName: collection
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
export var extractMediaNodes = function extractMediaNodes(doc) {
|
|
237
|
+
var mediaNodes = [];
|
|
238
|
+
doc.descendants(function (node) {
|
|
239
|
+
if (node.type.name === 'media' || node.type.name === 'mediaInline') {
|
|
240
|
+
mediaNodes.push(node);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
return mediaNodes;
|
|
244
|
+
};
|
|
245
|
+
export var createMediaIdentifierArray = function createMediaIdentifierArray(mediaNodes) {
|
|
246
|
+
var mediaIdentifierMap = new Map();
|
|
247
|
+
mediaNodes.forEach(function (item) {
|
|
248
|
+
var attrs = item.attrs;
|
|
249
|
+
if (!attrs) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (isVideo(attrs.__fileMimeType)) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
var identifier = getIdentifier(attrs);
|
|
256
|
+
|
|
257
|
+
// Add only if not already processed
|
|
258
|
+
var idKey = isExternalImageIdentifier(identifier) ? identifier.dataURI : identifier.id;
|
|
259
|
+
if (!mediaIdentifierMap.has(idKey)) {
|
|
260
|
+
mediaIdentifierMap.set(idKey, identifier);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return _toConsumableArray(mediaIdentifierMap.values());
|
|
215
264
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { MediaADFAttrs } from '@atlaskit/adf-schema';
|
|
3
|
-
import type { MediaClientConfig } from '@atlaskit/media-client';
|
|
3
|
+
import type { Identifier, MediaClientConfig } from '@atlaskit/media-client';
|
|
4
4
|
interface RenderMediaViewerProps {
|
|
5
5
|
mediaClientConfig: MediaClientConfig;
|
|
6
6
|
onClose: () => void;
|
|
7
7
|
selectedNodeAttrs: MediaADFAttrs;
|
|
8
|
+
items?: Identifier[];
|
|
8
9
|
}
|
|
9
|
-
export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, }: RenderMediaViewerProps) => React.ReactPortal;
|
|
10
|
+
export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, items, }: RenderMediaViewerProps) => React.ReactPortal;
|
|
10
11
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { MediaADFAttrs } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { type Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import { type Identifier } from '@atlaskit/media-client';
|
|
5
7
|
import type { MediaState, getPosHandler as ProsemirrorGetPosHandler } from '../types';
|
|
6
8
|
export declare const isMediaBlobUrlFromAttrs: (attrs: MediaADFAttrs) => boolean;
|
|
7
9
|
export declare const posOfMediaGroupNearby: (state: EditorState) => number | undefined;
|
|
@@ -21,3 +23,6 @@ export declare const getMediaNodeFromSelection: (state: EditorState) => PMNode |
|
|
|
21
23
|
export declare const isMediaSingleOrInlineNodeSelected: (state: EditorState) => boolean | undefined;
|
|
22
24
|
export declare const getMediaSingleOrInlineNodeFromSelection: (state: EditorState) => PMNode | null;
|
|
23
25
|
export declare const getMediaFromSupportedMediaNodesFromSelection: (state: EditorState) => PMNode | null;
|
|
26
|
+
export declare const getIdentifier: (attrs: MediaADFAttrs) => Identifier;
|
|
27
|
+
export declare const extractMediaNodes: (doc: ProseMirrorNode) => PMNode[];
|
|
28
|
+
export declare const createMediaIdentifierArray: (mediaNodes: ProseMirrorNode[]) => any[];
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { MediaADFAttrs } from '@atlaskit/adf-schema';
|
|
3
|
-
import type { MediaClientConfig } from '@atlaskit/media-client';
|
|
3
|
+
import type { Identifier, MediaClientConfig } from '@atlaskit/media-client';
|
|
4
4
|
interface RenderMediaViewerProps {
|
|
5
5
|
mediaClientConfig: MediaClientConfig;
|
|
6
6
|
onClose: () => void;
|
|
7
7
|
selectedNodeAttrs: MediaADFAttrs;
|
|
8
|
+
items?: Identifier[];
|
|
8
9
|
}
|
|
9
|
-
export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, }: RenderMediaViewerProps) => React.ReactPortal;
|
|
10
|
+
export declare const RenderMediaViewer: ({ mediaClientConfig, onClose, selectedNodeAttrs, items, }: RenderMediaViewerProps) => React.ReactPortal;
|
|
10
11
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { MediaADFAttrs } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { Node as PMNode, ResolvedPos } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import { type Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
4
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
6
|
+
import { type Identifier } from '@atlaskit/media-client';
|
|
5
7
|
import type { MediaState, getPosHandler as ProsemirrorGetPosHandler } from '../types';
|
|
6
8
|
export declare const isMediaBlobUrlFromAttrs: (attrs: MediaADFAttrs) => boolean;
|
|
7
9
|
export declare const posOfMediaGroupNearby: (state: EditorState) => number | undefined;
|
|
@@ -21,3 +23,6 @@ export declare const getMediaNodeFromSelection: (state: EditorState) => PMNode |
|
|
|
21
23
|
export declare const isMediaSingleOrInlineNodeSelected: (state: EditorState) => boolean | undefined;
|
|
22
24
|
export declare const getMediaSingleOrInlineNodeFromSelection: (state: EditorState) => PMNode | null;
|
|
23
25
|
export declare const getMediaFromSupportedMediaNodesFromSelection: (state: EditorState) => PMNode | null;
|
|
26
|
+
export declare const getIdentifier: (attrs: MediaADFAttrs) => Identifier;
|
|
27
|
+
export declare const extractMediaNodes: (doc: ProseMirrorNode) => PMNode[];
|
|
28
|
+
export declare const createMediaIdentifierArray: (mediaNodes: ProseMirrorNode[]) => any[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "1.37.
|
|
3
|
+
"version": "1.37.2",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"@atlaskit/adf-schema": "^42.3.1",
|
|
36
36
|
"@atlaskit/analytics-namespaced-context": "^6.12.0",
|
|
37
37
|
"@atlaskit/analytics-next": "^10.1.0",
|
|
38
|
-
"@atlaskit/button": "^20.
|
|
39
|
-
"@atlaskit/editor-common": "^94.
|
|
40
|
-
"@atlaskit/editor-palette": "1.6.
|
|
38
|
+
"@atlaskit/button": "^20.3.0",
|
|
39
|
+
"@atlaskit/editor-common": "^94.2.0",
|
|
40
|
+
"@atlaskit/editor-palette": "1.6.2",
|
|
41
41
|
"@atlaskit/editor-plugin-analytics": "^1.10.0",
|
|
42
|
-
"@atlaskit/editor-plugin-annotation": "1.21.
|
|
42
|
+
"@atlaskit/editor-plugin-annotation": "1.21.3",
|
|
43
43
|
"@atlaskit/editor-plugin-decorations": "^1.3.0",
|
|
44
44
|
"@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
|
|
45
45
|
"@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"@atlaskit/editor-shared-styles": "^3.0.0",
|
|
54
54
|
"@atlaskit/editor-tables": "^2.8.0",
|
|
55
55
|
"@atlaskit/form": "^10.5.0",
|
|
56
|
-
"@atlaskit/icon": "^22.
|
|
57
|
-
"@atlaskit/media-card": "^78.
|
|
56
|
+
"@atlaskit/icon": "^22.24.0",
|
|
57
|
+
"@atlaskit/media-card": "^78.8.0",
|
|
58
58
|
"@atlaskit/media-client": "^28.0.0",
|
|
59
59
|
"@atlaskit/media-client-react": "^2.2.0",
|
|
60
60
|
"@atlaskit/media-common": "^11.6.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@atlaskit/primitives": "^12.2.0",
|
|
67
67
|
"@atlaskit/textfield": "^6.5.0",
|
|
68
68
|
"@atlaskit/theme": "^14.0.0",
|
|
69
|
-
"@atlaskit/tmp-editor-statsig": "^2.
|
|
69
|
+
"@atlaskit/tmp-editor-statsig": "^2.8.0",
|
|
70
70
|
"@atlaskit/tokens": "^2.0.0",
|
|
71
71
|
"@atlaskit/tooltip": "^18.8.0",
|
|
72
72
|
"@babel/runtime": "^7.0.0",
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
"uuid": "^3.1.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"react-dom": "^16.8.0",
|
|
82
81
|
"typescript": "~5.4.2"
|
|
83
82
|
},
|
|
84
83
|
"peerDependencies": {
|