@atlaskit/editor-plugin-media 3.0.3 → 3.0.5
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/mediaPlugin.js +43 -22
- package/dist/cjs/nodeviews/mediaGroup.js +22 -20
- package/dist/cjs/nodeviews/mediaInline.js +43 -38
- package/dist/cjs/nodeviews/mediaNodeView/index.js +20 -11
- package/dist/cjs/nodeviews/mediaSingle.js +48 -43
- package/dist/cjs/pm-plugins/alt-text/ui/AltTextEdit.js +1 -1
- package/dist/cjs/pm-plugins/pixel-resizing/ui/pixel-entry.js +24 -1
- package/dist/cjs/ui/CommentBadge/index.js +26 -33
- package/dist/cjs/ui/MediaLinkingToolbar.js +5 -2
- package/dist/cjs/ui/MediaPicker/BrowserWrapper.js +2 -2
- package/dist/cjs/ui/MediaPicker/ClipboardWrapper.js +4 -4
- package/dist/cjs/ui/MediaPicker/DropzoneWrapper.js +72 -31
- package/dist/cjs/ui/MediaPicker/PickerFacadeProvider.js +37 -9
- package/dist/cjs/ui/MediaPicker/index.js +32 -25
- package/dist/cjs/ui/ToolbarMedia/index.js +18 -13
- package/dist/cjs/ui/hooks/useMediaProvider.js +14 -9
- package/dist/es2019/mediaPlugin.js +47 -24
- package/dist/es2019/nodeviews/mediaGroup.js +23 -20
- package/dist/es2019/nodeviews/mediaInline.js +45 -39
- package/dist/es2019/nodeviews/mediaNodeView/index.js +22 -12
- package/dist/es2019/nodeviews/mediaSingle.js +49 -43
- package/dist/es2019/pm-plugins/alt-text/ui/AltTextEdit.js +1 -1
- package/dist/es2019/pm-plugins/pixel-resizing/ui/pixel-entry.js +23 -1
- package/dist/es2019/ui/CommentBadge/index.js +29 -35
- package/dist/es2019/ui/MediaLinkingToolbar.js +5 -2
- package/dist/es2019/ui/MediaPicker/BrowserWrapper.js +2 -2
- package/dist/es2019/ui/MediaPicker/ClipboardWrapper.js +4 -4
- package/dist/es2019/ui/MediaPicker/DropzoneWrapper.js +53 -14
- package/dist/es2019/ui/MediaPicker/PickerFacadeProvider.js +37 -7
- package/dist/es2019/ui/MediaPicker/index.js +34 -26
- package/dist/es2019/ui/ToolbarMedia/index.js +20 -14
- package/dist/es2019/ui/hooks/useMediaProvider.js +16 -10
- package/dist/esm/mediaPlugin.js +44 -23
- package/dist/esm/nodeviews/mediaGroup.js +23 -21
- package/dist/esm/nodeviews/mediaInline.js +44 -39
- package/dist/esm/nodeviews/mediaNodeView/index.js +21 -12
- package/dist/esm/nodeviews/mediaSingle.js +49 -44
- package/dist/esm/pm-plugins/alt-text/ui/AltTextEdit.js +1 -1
- package/dist/esm/pm-plugins/pixel-resizing/ui/pixel-entry.js +23 -1
- package/dist/esm/ui/CommentBadge/index.js +27 -34
- package/dist/esm/ui/MediaLinkingToolbar.js +5 -2
- package/dist/esm/ui/MediaPicker/BrowserWrapper.js +2 -2
- package/dist/esm/ui/MediaPicker/ClipboardWrapper.js +4 -4
- package/dist/esm/ui/MediaPicker/DropzoneWrapper.js +72 -31
- package/dist/esm/ui/MediaPicker/PickerFacadeProvider.js +37 -9
- package/dist/esm/ui/MediaPicker/index.js +33 -26
- package/dist/esm/ui/ToolbarMedia/index.js +19 -14
- package/dist/esm/ui/hooks/useMediaProvider.js +15 -10
- package/dist/types/ui/MediaPicker/BrowserWrapper.d.ts +4 -3
- package/dist/types/ui/MediaPicker/ClipboardWrapper.d.ts +4 -3
- package/dist/types/ui/MediaPicker/DropzoneWrapper.d.ts +4 -4
- package/dist/types/ui/MediaPicker/PickerFacadeProvider.d.ts +4 -3
- package/dist/types/ui/MediaPicker/index.d.ts +2 -2
- package/dist/types-ts4.5/ui/MediaPicker/BrowserWrapper.d.ts +4 -3
- package/dist/types-ts4.5/ui/MediaPicker/ClipboardWrapper.d.ts +4 -3
- package/dist/types-ts4.5/ui/MediaPicker/DropzoneWrapper.d.ts +4 -4
- package/dist/types-ts4.5/ui/MediaPicker/PickerFacadeProvider.d.ts +4 -3
- package/dist/types-ts4.5/ui/MediaPicker/index.d.ts +2 -2
- package/package.json +9 -6
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
2
3
|
import { findOverflowScrollParent } from '@atlaskit/editor-common/ui';
|
|
4
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
5
|
import { Dropzone } from '@atlaskit/media-picker';
|
|
4
6
|
import PickerFacadeProvider from './PickerFacadeProvider';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
const useSharedState = sharedPluginStateHookMigratorFactory(api => {
|
|
8
|
+
const options = useSharedPluginStateSelector(api, 'media.options');
|
|
9
|
+
const handleDrag = useSharedPluginStateSelector(api, 'media.handleDrag');
|
|
10
|
+
return {
|
|
11
|
+
options,
|
|
12
|
+
handleDrag
|
|
13
|
+
};
|
|
14
|
+
}, api => {
|
|
15
|
+
const {
|
|
16
|
+
mediaState
|
|
17
|
+
} = useSharedPluginState(api, ['media']);
|
|
18
|
+
return {
|
|
19
|
+
options: mediaState === null || mediaState === void 0 ? void 0 : mediaState.options,
|
|
20
|
+
handleDrag: mediaState === null || mediaState === void 0 ? void 0 : mediaState.handleDrag
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
const DropzoneWrapperInternal = ({
|
|
24
|
+
api,
|
|
7
25
|
isActive,
|
|
8
26
|
featureFlags,
|
|
9
27
|
editorDomElement,
|
|
10
|
-
appearance
|
|
11
|
-
}) => /*#__PURE__*/React.createElement(PickerFacadeProvider, {
|
|
12
|
-
mediaState: mediaState,
|
|
13
|
-
analyticsName: "dropzone"
|
|
14
|
-
}, ({
|
|
28
|
+
appearance,
|
|
15
29
|
mediaClientConfig,
|
|
16
30
|
config,
|
|
17
31
|
pickerFacadeInstance
|
|
18
32
|
}) => {
|
|
19
33
|
const {
|
|
20
|
-
options
|
|
21
|
-
customDropzoneContainer
|
|
22
|
-
},
|
|
34
|
+
options,
|
|
23
35
|
handleDrag
|
|
24
|
-
} =
|
|
36
|
+
} = useSharedState(api);
|
|
37
|
+
const {
|
|
38
|
+
customDropzoneContainer
|
|
39
|
+
} = options || {};
|
|
40
|
+
|
|
25
41
|
// Ignored via go/ees005
|
|
26
42
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
27
43
|
const editorHtmlElement = editorDomElement;
|
|
@@ -37,8 +53,31 @@ export const DropzoneWrapper = ({
|
|
|
37
53
|
onError: pickerFacadeInstance.handleUploadError,
|
|
38
54
|
onPreviewUpdate: pickerFacadeInstance.handleUploadPreviewUpdate,
|
|
39
55
|
onEnd: pickerFacadeInstance.handleReady,
|
|
40
|
-
onDragEnter: () => handleDrag('enter'),
|
|
41
|
-
onDragLeave: () => handleDrag('leave'),
|
|
56
|
+
onDragEnter: () => handleDrag === null || handleDrag === void 0 ? void 0 : handleDrag('enter'),
|
|
57
|
+
onDragLeave: () => handleDrag === null || handleDrag === void 0 ? void 0 : handleDrag('leave'),
|
|
42
58
|
featureFlags: featureFlags
|
|
43
59
|
}) : null;
|
|
44
|
-
}
|
|
60
|
+
};
|
|
61
|
+
export const DropzoneWrapper = ({
|
|
62
|
+
api,
|
|
63
|
+
isActive,
|
|
64
|
+
featureFlags,
|
|
65
|
+
editorDomElement,
|
|
66
|
+
appearance
|
|
67
|
+
}) => /*#__PURE__*/React.createElement(PickerFacadeProvider, {
|
|
68
|
+
api: api,
|
|
69
|
+
analyticsName: "dropzone"
|
|
70
|
+
}, ({
|
|
71
|
+
mediaClientConfig,
|
|
72
|
+
config,
|
|
73
|
+
pickerFacadeInstance
|
|
74
|
+
}) => /*#__PURE__*/React.createElement(DropzoneWrapperInternal, {
|
|
75
|
+
api: api,
|
|
76
|
+
isActive: isActive,
|
|
77
|
+
featureFlags: featureFlags,
|
|
78
|
+
editorDomElement: editorDomElement,
|
|
79
|
+
appearance: appearance,
|
|
80
|
+
mediaClientConfig: mediaClientConfig,
|
|
81
|
+
config: config,
|
|
82
|
+
pickerFacadeInstance: pickerFacadeInstance
|
|
83
|
+
}));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { flushSync } from 'react-dom';
|
|
3
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
3
5
|
import { ErrorReporter } from '@atlaskit/editor-common/utils';
|
|
4
6
|
import PickerFacade from '../../pm-plugins/picker-facade';
|
|
5
7
|
const dummyMediaPickerObject = {
|
|
@@ -9,8 +11,31 @@ const dummyMediaPickerObject = {
|
|
|
9
11
|
destroy: () => {},
|
|
10
12
|
setUploadParams: () => {}
|
|
11
13
|
};
|
|
14
|
+
const useSharedState = sharedPluginStateHookMigratorFactory(api => {
|
|
15
|
+
const mediaProvider = useSharedPluginStateSelector(api, 'media.mediaProvider');
|
|
16
|
+
const mediaOptions = useSharedPluginStateSelector(api, 'media.mediaOptions');
|
|
17
|
+
const insertFile = useSharedPluginStateSelector(api, 'media.insertFile');
|
|
18
|
+
const options = useSharedPluginStateSelector(api, 'media.options');
|
|
19
|
+
return {
|
|
20
|
+
mediaProvider,
|
|
21
|
+
mediaOptions,
|
|
22
|
+
insertFile,
|
|
23
|
+
options
|
|
24
|
+
};
|
|
25
|
+
}, api => {
|
|
26
|
+
const {
|
|
27
|
+
mediaState
|
|
28
|
+
} = useSharedPluginState(api, ['media']);
|
|
29
|
+
const mediaProvider = useMemo(() => mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider, [mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider]);
|
|
30
|
+
return {
|
|
31
|
+
mediaProvider,
|
|
32
|
+
mediaOptions: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaOptions,
|
|
33
|
+
insertFile: mediaState === null || mediaState === void 0 ? void 0 : mediaState.insertFile,
|
|
34
|
+
options: mediaState === null || mediaState === void 0 ? void 0 : mediaState.options
|
|
35
|
+
};
|
|
36
|
+
});
|
|
12
37
|
export default function PickerFacadeProvider({
|
|
13
|
-
|
|
38
|
+
api,
|
|
14
39
|
analyticsName,
|
|
15
40
|
children
|
|
16
41
|
}) {
|
|
@@ -19,10 +44,15 @@ export default function PickerFacadeProvider({
|
|
|
19
44
|
config: undefined,
|
|
20
45
|
mediaClientConfig: undefined
|
|
21
46
|
});
|
|
22
|
-
const
|
|
47
|
+
const {
|
|
48
|
+
mediaProvider,
|
|
49
|
+
mediaOptions,
|
|
50
|
+
insertFile,
|
|
51
|
+
options
|
|
52
|
+
} = useSharedState(api);
|
|
23
53
|
const handleMediaProvider = useCallback(async (_name, provider) => {
|
|
24
54
|
const mediaProvider = await provider;
|
|
25
|
-
if (!mediaProvider || !mediaProvider.uploadParams) {
|
|
55
|
+
if (!mediaProvider || !mediaProvider.uploadParams || !insertFile) {
|
|
26
56
|
return;
|
|
27
57
|
}
|
|
28
58
|
const resolvedMediaClientConfig = (await mediaProvider.uploadMediaClientConfig) || (await mediaProvider.viewMediaClientConfig);
|
|
@@ -31,11 +61,11 @@ export default function PickerFacadeProvider({
|
|
|
31
61
|
}
|
|
32
62
|
const pickerFacadeConfig = {
|
|
33
63
|
mediaClientConfig: resolvedMediaClientConfig,
|
|
34
|
-
errorReporter:
|
|
35
|
-
featureFlags:
|
|
64
|
+
errorReporter: (options === null || options === void 0 ? void 0 : options.errorReporter) || new ErrorReporter(),
|
|
65
|
+
featureFlags: mediaOptions && mediaOptions.featureFlags
|
|
36
66
|
};
|
|
37
67
|
const pickerFacadeInstance = await new PickerFacade('customMediaPicker', pickerFacadeConfig, dummyMediaPickerObject, analyticsName).init();
|
|
38
|
-
pickerFacadeInstance.onNewMedia(
|
|
68
|
+
pickerFacadeInstance.onNewMedia(insertFile);
|
|
39
69
|
pickerFacadeInstance.setUploadParams(mediaProvider.uploadParams);
|
|
40
70
|
const config = {
|
|
41
71
|
uploadParams: mediaProvider.uploadParams
|
|
@@ -47,7 +77,7 @@ export default function PickerFacadeProvider({
|
|
|
47
77
|
mediaClientConfig: resolvedMediaClientConfig
|
|
48
78
|
});
|
|
49
79
|
});
|
|
50
|
-
}, [analyticsName,
|
|
80
|
+
}, [analyticsName, insertFile, mediaOptions, options === null || options === void 0 ? void 0 : options.errorReporter]);
|
|
51
81
|
useEffect(() => {
|
|
52
82
|
if (mediaProvider) {
|
|
53
83
|
handleMediaProvider('mediaProvider', Promise.resolve(mediaProvider));
|
|
@@ -1,35 +1,45 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
5
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
5
|
import { BrowserWrapper } from './BrowserWrapper';
|
|
7
6
|
import { ClipboardWrapper } from './ClipboardWrapper';
|
|
8
7
|
import { DropzoneWrapper } from './DropzoneWrapper';
|
|
8
|
+
const useMediaPickerState = sharedPluginStateHookMigratorFactory(api => {
|
|
9
|
+
const hasFocus = useSharedPluginStateSelector(api, 'focus.hasFocus');
|
|
10
|
+
const connectivityMode = useSharedPluginStateSelector(api, 'connectivity.mode');
|
|
11
|
+
const mediaOptions = useSharedPluginStateSelector(api, 'media.mediaOptions');
|
|
12
|
+
return {
|
|
13
|
+
hasFocus,
|
|
14
|
+
connectivityMode,
|
|
15
|
+
mediaOptions
|
|
16
|
+
};
|
|
17
|
+
}, api => {
|
|
18
|
+
const {
|
|
19
|
+
focusState,
|
|
20
|
+
connectivityState,
|
|
21
|
+
mediaState
|
|
22
|
+
} = useSharedPluginState(api, ['focus', 'connectivity', 'media']);
|
|
23
|
+
return {
|
|
24
|
+
hasFocus: focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus,
|
|
25
|
+
connectivityMode: connectivityState === null || connectivityState === void 0 ? void 0 : connectivityState.mode,
|
|
26
|
+
mediaOptions: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaOptions
|
|
27
|
+
};
|
|
28
|
+
});
|
|
9
29
|
const MediaPicker = ({
|
|
10
30
|
api,
|
|
11
31
|
isPopupOpened,
|
|
12
32
|
appearance,
|
|
13
|
-
mediaState,
|
|
14
33
|
onBrowseFn,
|
|
15
34
|
editorDomElement
|
|
16
35
|
}) => {
|
|
17
36
|
var _editorDom$parentElem;
|
|
18
37
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const hasFocusSelector = useSharedPluginStateSelector(api, 'focus.hasFocus', {
|
|
25
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
26
|
-
});
|
|
27
|
-
const connectivityModeSelector = useSharedPluginStateSelector(api, 'connectivity.mode', {
|
|
28
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
29
|
-
});
|
|
30
|
-
const hasFocus = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? hasFocusSelector : focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus;
|
|
31
|
-
const connectivityMode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? connectivityModeSelector : connectivityState === null || connectivityState === void 0 ? void 0 : connectivityState.mode;
|
|
32
|
-
const featureFlags = mediaState.mediaOptions && mediaState.mediaOptions.featureFlags;
|
|
38
|
+
hasFocus,
|
|
39
|
+
connectivityMode,
|
|
40
|
+
mediaOptions
|
|
41
|
+
} = useMediaPickerState(api);
|
|
42
|
+
const featureFlags = mediaOptions && mediaOptions.featureFlags;
|
|
33
43
|
|
|
34
44
|
// Ignored via go/ees005
|
|
35
45
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
@@ -44,12 +54,12 @@ const MediaPicker = ({
|
|
|
44
54
|
*/
|
|
45
55
|
const container = editorParent;
|
|
46
56
|
const clipboard = hasFocus ? /*#__PURE__*/React.createElement(ClipboardWrapper, {
|
|
47
|
-
|
|
57
|
+
api: api,
|
|
48
58
|
featureFlags: featureFlags,
|
|
49
59
|
container: container
|
|
50
60
|
}) : null;
|
|
51
61
|
return /*#__PURE__*/React.createElement(React.Fragment, null, clipboard, /*#__PURE__*/React.createElement(DropzoneWrapper, {
|
|
52
|
-
|
|
62
|
+
api: api,
|
|
53
63
|
isActive: !isPopupOpened &&
|
|
54
64
|
// If we're offline don't show the dropzone
|
|
55
65
|
connectivityMode !== 'offline',
|
|
@@ -57,8 +67,8 @@ const MediaPicker = ({
|
|
|
57
67
|
editorDomElement: editorDomElement,
|
|
58
68
|
appearance: appearance
|
|
59
69
|
}), /*#__PURE__*/React.createElement(BrowserWrapper, {
|
|
70
|
+
api: api,
|
|
60
71
|
onBrowseFn: onBrowseFn,
|
|
61
|
-
mediaState: mediaState,
|
|
62
72
|
featureFlags: featureFlags
|
|
63
73
|
}));
|
|
64
74
|
};
|
|
@@ -72,16 +82,16 @@ export class MediaPickerComponents extends React.Component {
|
|
|
72
82
|
});
|
|
73
83
|
_defineProperty(this, "onBrowseFn", nativeBrowseFn => {
|
|
74
84
|
const {
|
|
75
|
-
|
|
85
|
+
setBrowseFn
|
|
76
86
|
} = this.props;
|
|
77
|
-
|
|
87
|
+
setBrowseFn(nativeBrowseFn);
|
|
78
88
|
});
|
|
79
89
|
}
|
|
80
90
|
componentDidMount() {
|
|
81
91
|
const {
|
|
82
|
-
|
|
92
|
+
onPopupToggle
|
|
83
93
|
} = this.props;
|
|
84
|
-
|
|
94
|
+
onPopupToggle(isPopupOpened => {
|
|
85
95
|
this.setState({
|
|
86
96
|
isPopupOpened
|
|
87
97
|
});
|
|
@@ -90,7 +100,6 @@ export class MediaPickerComponents extends React.Component {
|
|
|
90
100
|
render() {
|
|
91
101
|
const {
|
|
92
102
|
api,
|
|
93
|
-
mediaState,
|
|
94
103
|
editorDomElement,
|
|
95
104
|
appearance
|
|
96
105
|
} = this.props;
|
|
@@ -98,7 +107,6 @@ export class MediaPickerComponents extends React.Component {
|
|
|
98
107
|
isPopupOpened
|
|
99
108
|
} = this.state;
|
|
100
109
|
return /*#__PURE__*/React.createElement(MediaPicker, {
|
|
101
|
-
mediaState: mediaState,
|
|
102
110
|
editorDomElement: editorDomElement,
|
|
103
111
|
appearance: appearance,
|
|
104
112
|
isPopupOpened: isPopupOpened,
|
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { injectIntl } from 'react-intl-next';
|
|
3
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { toolbarMediaMessages } from '@atlaskit/editor-common/media';
|
|
5
5
|
import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
6
6
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
7
7
|
import AttachmentIcon from '@atlaskit/icon/core/migration/attachment--editor-attachment';
|
|
8
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
9
8
|
const onClickMediaButton = showMediaPicker => () => {
|
|
10
9
|
showMediaPicker();
|
|
11
10
|
return true;
|
|
12
11
|
};
|
|
12
|
+
const useSharedState = sharedPluginStateHookMigratorFactory(api => {
|
|
13
|
+
const allowsUploads = useSharedPluginStateSelector(api, 'media.allowsUploads');
|
|
14
|
+
const showMediaPicker = useSharedPluginStateSelector(api, 'media.showMediaPicker');
|
|
15
|
+
return {
|
|
16
|
+
allowsUploads,
|
|
17
|
+
showMediaPicker
|
|
18
|
+
};
|
|
19
|
+
}, api => {
|
|
20
|
+
const {
|
|
21
|
+
mediaState
|
|
22
|
+
} = useSharedPluginState(api, ['media']);
|
|
23
|
+
return {
|
|
24
|
+
allowsUploads: mediaState === null || mediaState === void 0 ? void 0 : mediaState.allowsUploads,
|
|
25
|
+
showMediaPicker: mediaState === null || mediaState === void 0 ? void 0 : mediaState.showMediaPicker
|
|
26
|
+
};
|
|
27
|
+
});
|
|
13
28
|
const ToolbarMedia = ({
|
|
14
29
|
isDisabled,
|
|
15
30
|
isReducedSpacing,
|
|
@@ -17,18 +32,9 @@ const ToolbarMedia = ({
|
|
|
17
32
|
api
|
|
18
33
|
}) => {
|
|
19
34
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
const allowsUploadsSelector = useSharedPluginStateSelector(api, 'media.allowsUploads', {
|
|
25
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
26
|
-
});
|
|
27
|
-
const showMediaPickerSelector = useSharedPluginStateSelector(api, 'media.showMediaPicker', {
|
|
28
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
29
|
-
});
|
|
30
|
-
const allowsUploads = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? allowsUploadsSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.allowsUploads;
|
|
31
|
-
const showMediaPicker = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? showMediaPickerSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.showMediaPicker;
|
|
35
|
+
allowsUploads,
|
|
36
|
+
showMediaPicker
|
|
37
|
+
} = useSharedState(api);
|
|
32
38
|
if (!allowsUploads || !showMediaPicker) {
|
|
33
39
|
return null;
|
|
34
40
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
2
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
3
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
|
|
5
|
+
const mediaProvider = useSharedPluginStateSelector(pluginInjectionApi, 'media.mediaProvider');
|
|
6
|
+
return {
|
|
7
|
+
mediaProvider
|
|
8
|
+
};
|
|
9
|
+
}, pluginInjectionApi => {
|
|
6
10
|
const {
|
|
7
11
|
mediaState
|
|
8
|
-
} = useSharedPluginState(pluginInjectionApi, ['media']
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
12
|
+
} = useSharedPluginState(pluginInjectionApi, ['media']);
|
|
13
|
+
return {
|
|
14
|
+
mediaProvider: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaProvider
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
export const useMediaProvider = pluginInjectionApi => {
|
|
18
|
+
const {
|
|
19
|
+
mediaProvider
|
|
20
|
+
} = useSharedState(pluginInjectionApi);
|
|
15
21
|
const provider = useMemo(() => {
|
|
16
22
|
return mediaProvider;
|
|
17
23
|
}, [mediaProvider]);
|
package/dist/esm/mediaPlugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
3
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
5
5
|
import { IconImages } from '@atlaskit/editor-common/quick-insert';
|
|
6
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
@@ -33,45 +33,66 @@ import { MediaPickerComponents } from './ui/MediaPicker';
|
|
|
33
33
|
import { RenderMediaViewer } from './ui/MediaViewer/PortalWrapper';
|
|
34
34
|
import { floatingToolbar as _floatingToolbar } from './ui/toolbar';
|
|
35
35
|
import ToolbarMedia from './ui/ToolbarMedia';
|
|
36
|
+
var useMediaPickerSharedState = sharedPluginStateHookMigratorFactory(function (api) {
|
|
37
|
+
var onPopupToggle = useSharedPluginStateSelector(api, 'media.onPopupToggle');
|
|
38
|
+
var setBrowseFn = useSharedPluginStateSelector(api, 'media.setBrowseFn');
|
|
39
|
+
return {
|
|
40
|
+
onPopupToggle: onPopupToggle,
|
|
41
|
+
setBrowseFn: setBrowseFn
|
|
42
|
+
};
|
|
43
|
+
}, function (api) {
|
|
44
|
+
var _useSharedPluginState = useSharedPluginState(api, ['media']),
|
|
45
|
+
mediaState = _useSharedPluginState.mediaState;
|
|
46
|
+
return {
|
|
47
|
+
onPopupToggle: mediaState === null || mediaState === void 0 ? void 0 : mediaState.onPopupToggle,
|
|
48
|
+
setBrowseFn: mediaState === null || mediaState === void 0 ? void 0 : mediaState.setBrowseFn
|
|
49
|
+
};
|
|
50
|
+
});
|
|
36
51
|
var MediaPickerFunctionalComponent = function MediaPickerFunctionalComponent(_ref) {
|
|
37
52
|
var api = _ref.api,
|
|
38
53
|
editorDomElement = _ref.editorDomElement,
|
|
39
54
|
appearance = _ref.appearance;
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
var _useMediaPickerShared = useMediaPickerSharedState(api),
|
|
56
|
+
onPopupToggle = _useMediaPickerShared.onPopupToggle,
|
|
57
|
+
setBrowseFn = _useMediaPickerShared.setBrowseFn;
|
|
58
|
+
if (!onPopupToggle || !setBrowseFn) {
|
|
43
59
|
return null;
|
|
44
60
|
}
|
|
45
61
|
return /*#__PURE__*/React.createElement(MediaPickerComponents, {
|
|
62
|
+
onPopupToggle: onPopupToggle,
|
|
63
|
+
setBrowseFn: setBrowseFn,
|
|
46
64
|
editorDomElement: editorDomElement,
|
|
47
|
-
mediaState: mediaState,
|
|
48
65
|
appearance: appearance,
|
|
49
66
|
api: api
|
|
50
67
|
});
|
|
51
68
|
};
|
|
69
|
+
var useMediaViewerSharedState = sharedPluginStateHookMigratorFactory(function (api) {
|
|
70
|
+
var isMediaViewerVisible = useSharedPluginStateSelector(api, 'media.isMediaViewerVisible');
|
|
71
|
+
var mediaViewerSelectedMedia = useSharedPluginStateSelector(api, 'media.mediaViewerSelectedMedia');
|
|
72
|
+
var mediaClientConfig = useSharedPluginStateSelector(api, 'media.mediaClientConfig');
|
|
73
|
+
return {
|
|
74
|
+
isMediaViewerVisible: isMediaViewerVisible,
|
|
75
|
+
mediaViewerSelectedMedia: mediaViewerSelectedMedia,
|
|
76
|
+
mediaClientConfig: mediaClientConfig
|
|
77
|
+
};
|
|
78
|
+
}, function (api) {
|
|
79
|
+
var _useSharedPluginState2 = useSharedPluginState(api, ['media']),
|
|
80
|
+
mediaState = _useSharedPluginState2.mediaState;
|
|
81
|
+
return {
|
|
82
|
+
isMediaViewerVisible: mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible,
|
|
83
|
+
mediaViewerSelectedMedia: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaViewerSelectedMedia,
|
|
84
|
+
mediaClientConfig: mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig
|
|
85
|
+
};
|
|
86
|
+
});
|
|
52
87
|
var MediaViewerFunctionalComponent = function MediaViewerFunctionalComponent(_ref2) {
|
|
53
88
|
var api = _ref2.api,
|
|
54
89
|
editorView = _ref2.editorView;
|
|
55
|
-
var _useSharedPluginState2 = useSharedPluginState(api, ['media'], {
|
|
56
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', true)
|
|
57
|
-
}),
|
|
58
|
-
mediaState = _useSharedPluginState2.mediaState;
|
|
59
|
-
var isMediaViewerVisibleSelector = useSharedPluginStateSelector(api, 'media.isMediaViewerVisible', {
|
|
60
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
61
|
-
});
|
|
62
|
-
var mediaViewerSelectedMediaSelector = useSharedPluginStateSelector(api, 'media.mediaViewerSelectedMedia', {
|
|
63
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
64
|
-
});
|
|
65
|
-
var mediaClientConfigSelector = useSharedPluginStateSelector(api, 'media.mediaClientConfig', {
|
|
66
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
67
|
-
});
|
|
68
|
-
var isMediaViewerVisible = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? isMediaViewerVisibleSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.isMediaViewerVisible;
|
|
69
|
-
var mediaViewerSelectedMedia = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaViewerSelectedMediaSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaViewerSelectedMedia;
|
|
70
|
-
var mediaClientConfig = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? mediaClientConfigSelector : mediaState === null || mediaState === void 0 ? void 0 : mediaState.mediaClientConfig;
|
|
71
|
-
|
|
72
90
|
// Only traverse document once when media viewer is visible, media viewer items will not update
|
|
73
91
|
// when document changes are made while media viewer is open
|
|
74
|
-
|
|
92
|
+
var _useMediaViewerShared = useMediaViewerSharedState(api),
|
|
93
|
+
isMediaViewerVisible = _useMediaViewerShared.isMediaViewerVisible,
|
|
94
|
+
mediaViewerSelectedMedia = _useMediaViewerShared.mediaViewerSelectedMedia,
|
|
95
|
+
mediaClientConfig = _useMediaViewerShared.mediaClientConfig;
|
|
75
96
|
var mediaItems = useMemo(function () {
|
|
76
97
|
if (isMediaViewerVisible) {
|
|
77
98
|
var mediaNodes = extractMediaNodes(editorView.state.doc);
|
|
@@ -12,7 +12,7 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
|
|
|
12
12
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
13
13
|
import React from 'react';
|
|
14
14
|
import { injectIntl } from 'react-intl-next';
|
|
15
|
-
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
15
|
+
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
16
16
|
import { nodeViewsMessages as messages } from '@atlaskit/editor-common/media';
|
|
17
17
|
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
18
18
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
@@ -302,26 +302,30 @@ var MediaGroup = /*#__PURE__*/function (_React$Component) {
|
|
|
302
302
|
_defineProperty(MediaGroup, "displayName", 'MediaGroup');
|
|
303
303
|
var IntlMediaGroup = injectIntl(MediaGroup);
|
|
304
304
|
export default IntlMediaGroup;
|
|
305
|
+
var useSharedState = sharedPluginStateHookMigratorFactory(function (pluginInjectionApi) {
|
|
306
|
+
var editorDisabled = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled');
|
|
307
|
+
var editorViewMode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
|
|
308
|
+
return {
|
|
309
|
+
editorDisabled: editorDisabled,
|
|
310
|
+
editorViewMode: editorViewMode
|
|
311
|
+
};
|
|
312
|
+
}, function (pluginInjectionApi) {
|
|
313
|
+
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['editorDisabled', 'editorViewMode']),
|
|
314
|
+
editorDisabledPlugin = _useSharedPluginState.editorDisabledState,
|
|
315
|
+
editorViewModePlugin = _useSharedPluginState.editorViewModeState;
|
|
316
|
+
return {
|
|
317
|
+
editorDisabled: editorDisabledPlugin === null || editorDisabledPlugin === void 0 ? void 0 : editorDisabledPlugin.editorDisabled,
|
|
318
|
+
editorViewMode: editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode
|
|
319
|
+
};
|
|
320
|
+
});
|
|
305
321
|
function MediaGroupNodeViewInternal(_ref3) {
|
|
306
322
|
var renderFn = _ref3.renderFn,
|
|
307
323
|
pluginInjectionApi = _ref3.pluginInjectionApi;
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
editorDisabledPlugin = _useSharedPluginState.editorDisabledState,
|
|
312
|
-
editorViewModePlugin = _useSharedPluginState.editorViewModeState;
|
|
313
|
-
var editorDisabledSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled', {
|
|
314
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
315
|
-
});
|
|
316
|
-
var editorViewModeSelector = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode', {
|
|
317
|
-
disabled: editorExperiment('platform_editor_usesharedpluginstateselector', false)
|
|
318
|
-
});
|
|
319
|
-
var editorDisabled = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorDisabledSelector : editorDisabledPlugin === null || editorDisabledPlugin === void 0 ? void 0 : editorDisabledPlugin.editorDisabled;
|
|
320
|
-
var editorViewMode = editorExperiment('platform_editor_usesharedpluginstateselector', true) ? editorViewModeSelector : editorViewModePlugin === null || editorViewModePlugin === void 0 ? void 0 : editorViewModePlugin.mode;
|
|
324
|
+
var _useSharedState = useSharedState(pluginInjectionApi),
|
|
325
|
+
editorDisabled = _useSharedState.editorDisabled,
|
|
326
|
+
editorViewMode = _useSharedState.editorViewMode;
|
|
321
327
|
var mediaProvider = useMediaProvider(pluginInjectionApi);
|
|
322
328
|
return renderFn({
|
|
323
|
-
editorDisabledPlugin: editorDisabledPlugin,
|
|
324
|
-
editorViewModePlugin: editorViewModePlugin,
|
|
325
329
|
editorDisabled: editorDisabled,
|
|
326
330
|
editorViewMode: editorViewMode,
|
|
327
331
|
mediaProvider: mediaProvider
|
|
@@ -347,9 +351,7 @@ var MediaGroupNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
347
351
|
renderNode: function renderNode(_ref4) {
|
|
348
352
|
var contextIdentifierProvider = _ref4.contextIdentifierProvider;
|
|
349
353
|
var renderFn = function renderFn(_ref5) {
|
|
350
|
-
var
|
|
351
|
-
editorViewModePlugin = _ref5.editorViewModePlugin,
|
|
352
|
-
mediaProviderFromState = _ref5.mediaProvider,
|
|
354
|
+
var mediaProviderFromState = _ref5.mediaProvider,
|
|
353
355
|
editorDisabled = _ref5.editorDisabled,
|
|
354
356
|
editorViewMode = _ref5.editorViewMode;
|
|
355
357
|
var mediaProvider = mediaProviderFromState ? Promise.resolve(mediaProviderFromState) : undefined;
|
|
@@ -378,7 +380,7 @@ var MediaGroupNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
378
380
|
getPos: getPos,
|
|
379
381
|
view: _this3.view,
|
|
380
382
|
forwardRef: forwardRef,
|
|
381
|
-
disabled:
|
|
383
|
+
disabled: editorDisabled,
|
|
382
384
|
allowLazyLoading: mediaOptions.allowLazyLoading,
|
|
383
385
|
mediaProvider: mediaProvider,
|
|
384
386
|
contextIdentifierProvider: contextIdentifierProvider,
|
|
@@ -386,7 +388,7 @@ var MediaGroupNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
386
388
|
anchorPos: _this3.view.state.selection.$anchor.pos,
|
|
387
389
|
headPos: _this3.view.state.selection.$head.pos,
|
|
388
390
|
mediaOptions: mediaOptions,
|
|
389
|
-
editorViewMode:
|
|
391
|
+
editorViewMode: editorViewMode === 'view'
|
|
390
392
|
});
|
|
391
393
|
};
|
|
392
394
|
return /*#__PURE__*/React.createElement(MediaGroupNodeViewInternal, {
|