@atlaskit/editor-plugin-media-insert 1.2.1 → 1.3.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 +21 -0
- package/dist/cjs/actions.js +28 -0
- package/dist/cjs/plugin.js +57 -10
- package/dist/cjs/pm-plugins/main.js +40 -0
- package/dist/cjs/pm-plugins/plugin-key.js +8 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/FromURL.js +108 -85
- package/dist/cjs/ui/MediaInsertContent.js +24 -0
- package/dist/cjs/ui/MediaInsertPicker.js +86 -0
- package/dist/cjs/ui/MediaInsertWrapper.js +21 -0
- package/dist/es2019/actions.js +21 -0
- package/dist/es2019/plugin.js +62 -12
- package/dist/es2019/pm-plugins/main.js +34 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/FromURL.js +34 -16
- package/dist/es2019/ui/MediaInsertContent.js +14 -0
- package/dist/es2019/ui/MediaInsertPicker.js +79 -0
- package/dist/es2019/ui/MediaInsertWrapper.js +15 -0
- package/dist/esm/actions.js +22 -0
- package/dist/esm/plugin.js +57 -10
- package/dist/esm/pm-plugins/main.js +34 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/FromURL.js +108 -85
- package/dist/esm/ui/MediaInsertContent.js +14 -0
- package/dist/esm/ui/MediaInsertPicker.js +79 -0
- package/dist/esm/ui/MediaInsertWrapper.js +14 -0
- package/dist/types/actions.d.ts +6 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugin.d.ts +1 -2
- package/dist/types/pm-plugins/main.d.ts +3 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/types.d.ts +14 -0
- package/dist/types/ui/MediaInsertContent.d.ts +2 -0
- package/dist/types/ui/MediaInsertPicker.d.ts +3 -0
- package/dist/types/ui/MediaInsertWrapper.d.ts +4 -0
- package/dist/types-ts4.5/actions.d.ts +6 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +1 -2
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/types.d.ts +16 -0
- package/dist/types-ts4.5/ui/MediaInsertContent.d.ts +2 -0
- package/dist/types-ts4.5/ui/MediaInsertPicker.d.ts +3 -0
- package/dist/types-ts4.5/ui/MediaInsertWrapper.d.ts +4 -0
- package/package.json +11 -7
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,17 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
3
4
|
import { IconImages } from '@atlaskit/editor-common/quick-insert';
|
|
4
|
-
|
|
5
|
+
import { closeMediaInsertPicker, showMediaInsertPopup } from './actions';
|
|
6
|
+
import { createPlugin } from './pm-plugins/main';
|
|
7
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
8
|
+
import { MediaInsertPicker } from './ui/MediaInsertPicker';
|
|
9
|
+
export const mediaInsertPlugin = ({
|
|
10
|
+
api
|
|
11
|
+
}) => {
|
|
5
12
|
return {
|
|
6
13
|
name: 'mediaInsert',
|
|
7
|
-
pmPlugins
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
pmPlugins() {
|
|
15
|
+
return [{
|
|
16
|
+
name: 'mediaInsert',
|
|
17
|
+
plugin: () => createPlugin()
|
|
18
|
+
}];
|
|
19
|
+
},
|
|
20
|
+
getSharedState(editorState) {
|
|
21
|
+
if (!editorState) {
|
|
22
|
+
return {
|
|
23
|
+
isOpen: false
|
|
24
|
+
};
|
|
13
25
|
}
|
|
14
|
-
|
|
26
|
+
const {
|
|
27
|
+
isOpen
|
|
28
|
+
} = pluginKey.getState(editorState) || {};
|
|
29
|
+
return {
|
|
30
|
+
isOpen
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
contentComponent: ({
|
|
34
|
+
editorView,
|
|
35
|
+
dispatchAnalyticsEvent,
|
|
36
|
+
popupsMountPoint,
|
|
37
|
+
popupsBoundariesElement,
|
|
38
|
+
popupsScrollableElement
|
|
39
|
+
}) => {
|
|
40
|
+
const {
|
|
41
|
+
dispatch,
|
|
42
|
+
state
|
|
43
|
+
} = editorView;
|
|
44
|
+
return /*#__PURE__*/React.createElement(MediaInsertPicker, {
|
|
45
|
+
api: api,
|
|
46
|
+
editorView: editorView,
|
|
47
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
48
|
+
popupsMountPoint: popupsMountPoint,
|
|
49
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
50
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
51
|
+
closeMediaInsertPicker: () => dispatch(closeMediaInsertPicker(state.tr))
|
|
52
|
+
});
|
|
53
|
+
},
|
|
15
54
|
pluginsOptions: {
|
|
16
55
|
quickInsert: ({
|
|
17
56
|
formatMessage
|
|
@@ -23,10 +62,21 @@ export const mediaInsertPlugin = () => {
|
|
|
23
62
|
keywords: ['attachment', 'gif', 'media', 'picture', 'image', 'video'],
|
|
24
63
|
icon: () => /*#__PURE__*/React.createElement(IconImages, null),
|
|
25
64
|
action(insert) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
65
|
+
var _api$analytics, _api$analytics$action;
|
|
66
|
+
// Insert empty string to remove the typeahead raw text
|
|
67
|
+
// close the quick insert immediately
|
|
68
|
+
const tr = insert('');
|
|
69
|
+
showMediaInsertPopup(tr);
|
|
70
|
+
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent({
|
|
71
|
+
action: ACTION.OPENED,
|
|
72
|
+
actionSubject: ACTION_SUBJECT.PICKER,
|
|
73
|
+
actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
74
|
+
attributes: {
|
|
75
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
76
|
+
},
|
|
77
|
+
eventType: EVENT_TYPE.UI
|
|
78
|
+
})(tr);
|
|
79
|
+
return tr;
|
|
30
80
|
}
|
|
31
81
|
}]
|
|
32
82
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { ACTION_CLOSE_POPUP, ACTION_OPEN_POPUP } from '../actions';
|
|
3
|
+
import { pluginKey } from './plugin-key';
|
|
4
|
+
export const createPlugin = () => {
|
|
5
|
+
return new SafePlugin({
|
|
6
|
+
state: {
|
|
7
|
+
init() {
|
|
8
|
+
return {
|
|
9
|
+
isOpen: false
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
apply(tr, mediaInsertPluginState) {
|
|
13
|
+
const meta = tr.getMeta(pluginKey);
|
|
14
|
+
if (meta) {
|
|
15
|
+
switch (meta.type) {
|
|
16
|
+
case ACTION_OPEN_POPUP:
|
|
17
|
+
return {
|
|
18
|
+
isOpen: true
|
|
19
|
+
};
|
|
20
|
+
case ACTION_CLOSE_POPUP:
|
|
21
|
+
return {
|
|
22
|
+
isOpen: false
|
|
23
|
+
};
|
|
24
|
+
default:
|
|
25
|
+
return mediaInsertPluginState;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
return mediaInsertPluginState;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
key: pluginKey
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -79,20 +79,15 @@ export function MediaFromURL({
|
|
|
79
79
|
errorMessage: intl.formatMessage(mediaInsertMessages.errorMessage),
|
|
80
80
|
warning: intl.formatMessage(mediaInsertMessages.warning)
|
|
81
81
|
};
|
|
82
|
-
const [
|
|
82
|
+
const [inputUrl, setUrl] = React.useState(placeholders[1]);
|
|
83
83
|
const [previewState, dispatch] = React.useReducer(previewStateReducer, INITIAL_PREVIEW_STATE);
|
|
84
|
+
const pasteFlag = React.useRef(false);
|
|
84
85
|
const {
|
|
85
86
|
onUploadAnalytics,
|
|
86
87
|
onUploadSuccessAnalytics,
|
|
87
88
|
onUploadFailureAnalytics
|
|
88
89
|
} = useAnalyticsEvents(dispatchAnalyticsEvent);
|
|
89
|
-
const
|
|
90
|
-
setUrl(e.target.value);
|
|
91
|
-
dispatch({
|
|
92
|
-
type: 'reset'
|
|
93
|
-
});
|
|
94
|
-
}, []);
|
|
95
|
-
const uploadExternalMedia = React.useCallback(async () => {
|
|
90
|
+
const uploadExternalMedia = React.useCallback(async url => {
|
|
96
91
|
dispatch({
|
|
97
92
|
type: 'loading'
|
|
98
93
|
});
|
|
@@ -131,7 +126,7 @@ export function MediaFromURL({
|
|
|
131
126
|
dispatch({
|
|
132
127
|
type: 'warning',
|
|
133
128
|
warning: e,
|
|
134
|
-
url
|
|
129
|
+
url: inputUrl
|
|
135
130
|
});
|
|
136
131
|
} else if (e instanceof Error) {
|
|
137
132
|
const message = 'Image preview fetch failed';
|
|
@@ -148,27 +143,50 @@ export function MediaFromURL({
|
|
|
148
143
|
});
|
|
149
144
|
}
|
|
150
145
|
}
|
|
151
|
-
}, [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics,
|
|
146
|
+
}, [mediaProvider, onUploadAnalytics, onUploadFailureAnalytics, onUploadSuccessAnalytics, inputUrl]);
|
|
147
|
+
const onURLChange = React.useCallback(e => {
|
|
148
|
+
const url = e.target.value;
|
|
149
|
+
setUrl(url);
|
|
150
|
+
dispatch({
|
|
151
|
+
type: 'reset'
|
|
152
|
+
});
|
|
153
|
+
if (pasteFlag.current === true) {
|
|
154
|
+
pasteFlag.current = false;
|
|
155
|
+
uploadExternalMedia(url);
|
|
156
|
+
}
|
|
157
|
+
}, [uploadExternalMedia]);
|
|
158
|
+
const onPaste = React.useCallback(e => {
|
|
159
|
+
// Note: this is a little weird, but the paste event will always be
|
|
160
|
+
// fired before the change event when pasting. We don't really want to
|
|
161
|
+
// duplicate logic by handling pastes separately to changes, so we're
|
|
162
|
+
// just noting paste occured to then be handled in the onURLChange fn
|
|
163
|
+
// above. The one exception to this is where paste inputs exactly what was
|
|
164
|
+
// already in the input, in which case we want to ignore it.
|
|
165
|
+
if (e.clipboardData.getData('text') !== inputUrl) {
|
|
166
|
+
pasteFlag.current = true;
|
|
167
|
+
}
|
|
168
|
+
}, [inputUrl]);
|
|
152
169
|
const onInsertClick = React.useCallback(() => {
|
|
153
170
|
if (previewState.previewInfo) {
|
|
154
171
|
return onInsert(previewState.previewInfo);
|
|
155
172
|
}
|
|
156
173
|
if (previewState.warning) {
|
|
157
|
-
return onExternalInsert(
|
|
174
|
+
return onExternalInsert(inputUrl);
|
|
158
175
|
}
|
|
159
|
-
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning,
|
|
176
|
+
}, [onExternalInsert, onInsert, previewState.previewInfo, previewState.warning, inputUrl]);
|
|
160
177
|
return /*#__PURE__*/React.createElement("form", {
|
|
161
178
|
onSubmit: e => {
|
|
162
179
|
e.preventDefault();
|
|
163
|
-
uploadExternalMedia();
|
|
180
|
+
uploadExternalMedia(inputUrl);
|
|
164
181
|
}
|
|
165
182
|
}, /*#__PURE__*/React.createElement(Stack, {
|
|
166
183
|
space: "space.150"
|
|
167
184
|
}, /*#__PURE__*/React.createElement(TextField, {
|
|
168
185
|
autoFocus: true,
|
|
169
|
-
value:
|
|
186
|
+
value: inputUrl,
|
|
170
187
|
placeholder: strings.pasteLinkToUpload,
|
|
171
|
-
onChange: onURLChange
|
|
188
|
+
onChange: onURLChange,
|
|
189
|
+
onPaste: onPaste
|
|
172
190
|
}), previewState.previewInfo && /*#__PURE__*/React.createElement(Inline, {
|
|
173
191
|
alignInline: "center",
|
|
174
192
|
alignBlock: "center",
|
|
@@ -188,7 +206,7 @@ export function MediaFromURL({
|
|
|
188
206
|
}, /*#__PURE__*/React.createElement(Button, {
|
|
189
207
|
type: "submit",
|
|
190
208
|
isLoading: previewState.isLoading,
|
|
191
|
-
isDisabled: !
|
|
209
|
+
isDisabled: !inputUrl,
|
|
192
210
|
iconBefore: EditorFilePreviewIcon
|
|
193
211
|
}, strings.loadPreview)), /*#__PURE__*/React.createElement(Box, {
|
|
194
212
|
xcss: ButtonGroupStyles
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Button from '@atlaskit/button/new';
|
|
3
|
+
import { Box } from '@atlaskit/primitives';
|
|
4
|
+
import Tabs, { Tab, TabList, TabPanel } from '@atlaskit/tabs';
|
|
5
|
+
export const MediaInsertContent = () => {
|
|
6
|
+
return /*#__PURE__*/React.createElement(Tabs, {
|
|
7
|
+
id: "media-insert-tab-navigation"
|
|
8
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
9
|
+
paddingBlockEnd: "space.150"
|
|
10
|
+
}, /*#__PURE__*/React.createElement(TabList, null, /*#__PURE__*/React.createElement(Tab, null, /*#__PURE__*/React.createElement(Button, {
|
|
11
|
+
autoFocus: true,
|
|
12
|
+
appearance: "subtle"
|
|
13
|
+
}, "Link")))), /*#__PURE__*/React.createElement(TabPanel, null, /*#__PURE__*/React.createElement("p", null, "InsertLinkPanel here")));
|
|
14
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import React from 'react';
|
|
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';
|
|
4
|
+
import { Popup, withOuterListeners } from '@atlaskit/editor-common/ui';
|
|
5
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
import { akEditorFloatingDialogZIndex } from '@atlaskit/editor-shared-styles';
|
|
7
|
+
import { MediaInsertContent } from './MediaInsertContent';
|
|
8
|
+
import { MediaInsertWrapper } from './MediaInsertWrapper';
|
|
9
|
+
const PopupWithListeners = withOuterListeners(Popup);
|
|
10
|
+
const getDomRefFromSelection = (view, dispatchAnalyticsEvent) => {
|
|
11
|
+
try {
|
|
12
|
+
const domRef = findDomRefAtPos(view.state.selection.from, view.domAtPos.bind(view));
|
|
13
|
+
if (domRef instanceof HTMLElement) {
|
|
14
|
+
return domRef;
|
|
15
|
+
} else {
|
|
16
|
+
throw new Error('Invalid DOM reference');
|
|
17
|
+
}
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (dispatchAnalyticsEvent) {
|
|
20
|
+
const payload = {
|
|
21
|
+
action: ACTION.ERRORED,
|
|
22
|
+
actionSubject: ACTION_SUBJECT.PICKER,
|
|
23
|
+
actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
24
|
+
eventType: EVENT_TYPE.OPERATIONAL,
|
|
25
|
+
attributes: {
|
|
26
|
+
error: 'Error getting DOM reference from selection'
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
dispatchAnalyticsEvent(payload);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export const MediaInsertPicker = ({
|
|
34
|
+
api,
|
|
35
|
+
editorView,
|
|
36
|
+
dispatchAnalyticsEvent,
|
|
37
|
+
popupsMountPoint,
|
|
38
|
+
popupsBoundariesElement,
|
|
39
|
+
popupsScrollableElement,
|
|
40
|
+
closeMediaInsertPicker
|
|
41
|
+
}) => {
|
|
42
|
+
const targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
43
|
+
const {
|
|
44
|
+
mediaInsertState
|
|
45
|
+
} = useSharedPluginState(api, ['mediaInsert']);
|
|
46
|
+
if (!mediaInsertState || !mediaInsertState.isOpen) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const handleClose = exitMethod => event => {
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (dispatchAnalyticsEvent) {
|
|
52
|
+
const payload = {
|
|
53
|
+
action: ACTION.CLOSED,
|
|
54
|
+
actionSubject: ACTION_SUBJECT.PICKER,
|
|
55
|
+
actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
56
|
+
eventType: EVENT_TYPE.UI,
|
|
57
|
+
attributes: {
|
|
58
|
+
exitMethod
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
dispatchAnalyticsEvent(payload);
|
|
62
|
+
}
|
|
63
|
+
closeMediaInsertPicker();
|
|
64
|
+
};
|
|
65
|
+
return /*#__PURE__*/React.createElement(PopupWithListeners
|
|
66
|
+
// TODO: i18n
|
|
67
|
+
, {
|
|
68
|
+
ariaLabel: 'Media Insert',
|
|
69
|
+
offset: [0, 12],
|
|
70
|
+
target: targetRef,
|
|
71
|
+
zIndex: akEditorFloatingDialogZIndex,
|
|
72
|
+
mountTo: popupsMountPoint,
|
|
73
|
+
boundariesElement: popupsBoundariesElement,
|
|
74
|
+
handleClickOutside: handleClose(INPUT_METHOD.MOUSE),
|
|
75
|
+
handleEscapeKeydown: handleClose(INPUT_METHOD.KEYBOARD),
|
|
76
|
+
scrollableElement: popupsScrollableElement,
|
|
77
|
+
focusTrap: true
|
|
78
|
+
}, /*#__PURE__*/React.createElement(MediaInsertWrapper, null, /*#__PURE__*/React.createElement(MediaInsertContent, null)));
|
|
79
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
3
|
+
const styles = xcss({
|
|
4
|
+
boxShadow: 'elevation.shadow.overflow',
|
|
5
|
+
width: '340px',
|
|
6
|
+
padding: 'space.200',
|
|
7
|
+
borderRadius: 'border.radius'
|
|
8
|
+
});
|
|
9
|
+
export const MediaInsertWrapper = ({
|
|
10
|
+
children
|
|
11
|
+
}) => {
|
|
12
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
13
|
+
xcss: styles
|
|
14
|
+
}, children);
|
|
15
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
2
|
+
export var ACTION_OPEN_POPUP = 'OPEN_POPUP';
|
|
3
|
+
export var ACTION_CLOSE_POPUP = 'CLOSE_POPUP';
|
|
4
|
+
var setPopupMeta = function setPopupMeta(_ref) {
|
|
5
|
+
var type = _ref.type,
|
|
6
|
+
tr = _ref.tr;
|
|
7
|
+
return tr.setMeta(pluginKey, {
|
|
8
|
+
type: type
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export var showMediaInsertPopup = function showMediaInsertPopup(tr) {
|
|
12
|
+
return setPopupMeta({
|
|
13
|
+
type: ACTION_OPEN_POPUP,
|
|
14
|
+
tr: tr
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export var closeMediaInsertPicker = function closeMediaInsertPicker(tr) {
|
|
18
|
+
return setPopupMeta({
|
|
19
|
+
type: ACTION_CLOSE_POPUP,
|
|
20
|
+
tr: tr
|
|
21
|
+
});
|
|
22
|
+
};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1,22 +1,58 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
3
4
|
import { IconImages } from '@atlaskit/editor-common/quick-insert';
|
|
4
|
-
|
|
5
|
+
import { closeMediaInsertPicker as _closeMediaInsertPicker, showMediaInsertPopup } from './actions';
|
|
6
|
+
import { createPlugin } from './pm-plugins/main';
|
|
7
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
8
|
+
import { MediaInsertPicker } from './ui/MediaInsertPicker';
|
|
9
|
+
export var mediaInsertPlugin = function mediaInsertPlugin(_ref) {
|
|
10
|
+
var api = _ref.api;
|
|
5
11
|
return {
|
|
6
12
|
name: 'mediaInsert',
|
|
7
13
|
pmPlugins: function pmPlugins() {
|
|
8
14
|
return [{
|
|
9
15
|
name: 'mediaInsert',
|
|
10
16
|
plugin: function plugin() {
|
|
11
|
-
|
|
12
|
-
console.log('mediaInsert plugin');
|
|
13
|
-
return undefined;
|
|
17
|
+
return createPlugin();
|
|
14
18
|
}
|
|
15
19
|
}];
|
|
16
20
|
},
|
|
21
|
+
getSharedState: function getSharedState(editorState) {
|
|
22
|
+
if (!editorState) {
|
|
23
|
+
return {
|
|
24
|
+
isOpen: false
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var _ref2 = pluginKey.getState(editorState) || {},
|
|
28
|
+
isOpen = _ref2.isOpen;
|
|
29
|
+
return {
|
|
30
|
+
isOpen: isOpen
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
contentComponent: function contentComponent(_ref3) {
|
|
34
|
+
var editorView = _ref3.editorView,
|
|
35
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
36
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
37
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
38
|
+
popupsScrollableElement = _ref3.popupsScrollableElement;
|
|
39
|
+
var dispatch = editorView.dispatch,
|
|
40
|
+
state = editorView.state;
|
|
41
|
+
return /*#__PURE__*/React.createElement(MediaInsertPicker, {
|
|
42
|
+
api: api,
|
|
43
|
+
editorView: editorView,
|
|
44
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
45
|
+
popupsMountPoint: popupsMountPoint,
|
|
46
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
47
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
48
|
+
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
49
|
+
return dispatch(_closeMediaInsertPicker(state.tr));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
},
|
|
17
53
|
pluginsOptions: {
|
|
18
|
-
quickInsert: function quickInsert(
|
|
19
|
-
var formatMessage =
|
|
54
|
+
quickInsert: function quickInsert(_ref4) {
|
|
55
|
+
var formatMessage = _ref4.formatMessage;
|
|
20
56
|
return [{
|
|
21
57
|
id: 'media-insert',
|
|
22
58
|
title: formatMessage(messages.insertMediaFromUrl),
|
|
@@ -27,10 +63,21 @@ export var mediaInsertPlugin = function mediaInsertPlugin() {
|
|
|
27
63
|
return /*#__PURE__*/React.createElement(IconImages, null);
|
|
28
64
|
},
|
|
29
65
|
action: function action(insert) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
var _api$analytics;
|
|
67
|
+
// Insert empty string to remove the typeahead raw text
|
|
68
|
+
// close the quick insert immediately
|
|
69
|
+
var tr = insert('');
|
|
70
|
+
showMediaInsertPopup(tr);
|
|
71
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent({
|
|
72
|
+
action: ACTION.OPENED,
|
|
73
|
+
actionSubject: ACTION_SUBJECT.PICKER,
|
|
74
|
+
actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
75
|
+
attributes: {
|
|
76
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
77
|
+
},
|
|
78
|
+
eventType: EVENT_TYPE.UI
|
|
79
|
+
})(tr);
|
|
80
|
+
return tr;
|
|
34
81
|
}
|
|
35
82
|
}];
|
|
36
83
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { ACTION_CLOSE_POPUP, ACTION_OPEN_POPUP } from '../actions';
|
|
3
|
+
import { pluginKey } from './plugin-key';
|
|
4
|
+
export var createPlugin = function createPlugin() {
|
|
5
|
+
return new SafePlugin({
|
|
6
|
+
state: {
|
|
7
|
+
init: function init() {
|
|
8
|
+
return {
|
|
9
|
+
isOpen: false
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
apply: function apply(tr, mediaInsertPluginState) {
|
|
13
|
+
var meta = tr.getMeta(pluginKey);
|
|
14
|
+
if (meta) {
|
|
15
|
+
switch (meta.type) {
|
|
16
|
+
case ACTION_OPEN_POPUP:
|
|
17
|
+
return {
|
|
18
|
+
isOpen: true
|
|
19
|
+
};
|
|
20
|
+
case ACTION_CLOSE_POPUP:
|
|
21
|
+
return {
|
|
22
|
+
isOpen: false
|
|
23
|
+
};
|
|
24
|
+
default:
|
|
25
|
+
return mediaInsertPluginState;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
return mediaInsertPluginState;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
key: pluginKey
|
|
33
|
+
});
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|