@atlaskit/editor-plugin-media-insert 1.2.2 → 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 +12 -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/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/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/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 +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media-insert
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#129365](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/129365)
|
|
8
|
+
[`0cb229e53ad8f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0cb229e53ad8f) -
|
|
9
|
+
[ux] [ED-24249] Added popup dialog for inserting media using editor-plugin-media-insert
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 1.2.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.showMediaInsertPopup = exports.closeMediaInsertPicker = exports.ACTION_OPEN_POPUP = exports.ACTION_CLOSE_POPUP = void 0;
|
|
7
|
+
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
8
|
+
var ACTION_OPEN_POPUP = exports.ACTION_OPEN_POPUP = 'OPEN_POPUP';
|
|
9
|
+
var ACTION_CLOSE_POPUP = exports.ACTION_CLOSE_POPUP = 'CLOSE_POPUP';
|
|
10
|
+
var setPopupMeta = function setPopupMeta(_ref) {
|
|
11
|
+
var type = _ref.type,
|
|
12
|
+
tr = _ref.tr;
|
|
13
|
+
return tr.setMeta(_pluginKey.pluginKey, {
|
|
14
|
+
type: type
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var showMediaInsertPopup = exports.showMediaInsertPopup = function showMediaInsertPopup(tr) {
|
|
18
|
+
return setPopupMeta({
|
|
19
|
+
type: ACTION_OPEN_POPUP,
|
|
20
|
+
tr: tr
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var closeMediaInsertPicker = exports.closeMediaInsertPicker = function closeMediaInsertPicker(tr) {
|
|
24
|
+
return setPopupMeta({
|
|
25
|
+
type: ACTION_CLOSE_POPUP,
|
|
26
|
+
tr: tr
|
|
27
|
+
});
|
|
28
|
+
};
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -6,24 +6,60 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.mediaInsertPlugin = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
10
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
10
11
|
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
11
|
-
var
|
|
12
|
+
var _actions = require("./actions");
|
|
13
|
+
var _main = require("./pm-plugins/main");
|
|
14
|
+
var _pluginKey = require("./pm-plugins/plugin-key");
|
|
15
|
+
var _MediaInsertPicker = require("./ui/MediaInsertPicker");
|
|
16
|
+
var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin(_ref) {
|
|
17
|
+
var api = _ref.api;
|
|
12
18
|
return {
|
|
13
19
|
name: 'mediaInsert',
|
|
14
20
|
pmPlugins: function pmPlugins() {
|
|
15
21
|
return [{
|
|
16
22
|
name: 'mediaInsert',
|
|
17
23
|
plugin: function plugin() {
|
|
18
|
-
|
|
19
|
-
console.log('mediaInsert plugin');
|
|
20
|
-
return undefined;
|
|
24
|
+
return (0, _main.createPlugin)();
|
|
21
25
|
}
|
|
22
26
|
}];
|
|
23
27
|
},
|
|
28
|
+
getSharedState: function getSharedState(editorState) {
|
|
29
|
+
if (!editorState) {
|
|
30
|
+
return {
|
|
31
|
+
isOpen: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var _ref2 = _pluginKey.pluginKey.getState(editorState) || {},
|
|
35
|
+
isOpen = _ref2.isOpen;
|
|
36
|
+
return {
|
|
37
|
+
isOpen: isOpen
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
contentComponent: function contentComponent(_ref3) {
|
|
41
|
+
var editorView = _ref3.editorView,
|
|
42
|
+
dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent,
|
|
43
|
+
popupsMountPoint = _ref3.popupsMountPoint,
|
|
44
|
+
popupsBoundariesElement = _ref3.popupsBoundariesElement,
|
|
45
|
+
popupsScrollableElement = _ref3.popupsScrollableElement;
|
|
46
|
+
var dispatch = editorView.dispatch,
|
|
47
|
+
state = editorView.state;
|
|
48
|
+
return /*#__PURE__*/_react.default.createElement(_MediaInsertPicker.MediaInsertPicker, {
|
|
49
|
+
api: api,
|
|
50
|
+
editorView: editorView,
|
|
51
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
52
|
+
popupsMountPoint: popupsMountPoint,
|
|
53
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
54
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
55
|
+
closeMediaInsertPicker: function closeMediaInsertPicker() {
|
|
56
|
+
return dispatch((0, _actions.closeMediaInsertPicker)(state.tr));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
24
60
|
pluginsOptions: {
|
|
25
|
-
quickInsert: function quickInsert(
|
|
26
|
-
var formatMessage =
|
|
61
|
+
quickInsert: function quickInsert(_ref4) {
|
|
62
|
+
var formatMessage = _ref4.formatMessage;
|
|
27
63
|
return [{
|
|
28
64
|
id: 'media-insert',
|
|
29
65
|
title: formatMessage(_messages.toolbarInsertBlockMessages.insertMediaFromUrl),
|
|
@@ -34,10 +70,21 @@ var mediaInsertPlugin = exports.mediaInsertPlugin = function mediaInsertPlugin()
|
|
|
34
70
|
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconImages, null);
|
|
35
71
|
},
|
|
36
72
|
action: function action(insert) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
73
|
+
var _api$analytics;
|
|
74
|
+
// Insert empty string to remove the typeahead raw text
|
|
75
|
+
// close the quick insert immediately
|
|
76
|
+
var tr = insert('');
|
|
77
|
+
(0, _actions.showMediaInsertPopup)(tr);
|
|
78
|
+
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({
|
|
79
|
+
action: _analytics.ACTION.OPENED,
|
|
80
|
+
actionSubject: _analytics.ACTION_SUBJECT.PICKER,
|
|
81
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
82
|
+
attributes: {
|
|
83
|
+
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
84
|
+
},
|
|
85
|
+
eventType: _analytics.EVENT_TYPE.UI
|
|
86
|
+
})(tr);
|
|
87
|
+
return tr;
|
|
41
88
|
}
|
|
42
89
|
}];
|
|
43
90
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createPlugin = void 0;
|
|
7
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _actions = require("../actions");
|
|
9
|
+
var _pluginKey = require("./plugin-key");
|
|
10
|
+
var createPlugin = exports.createPlugin = function createPlugin() {
|
|
11
|
+
return new _safePlugin.SafePlugin({
|
|
12
|
+
state: {
|
|
13
|
+
init: function init() {
|
|
14
|
+
return {
|
|
15
|
+
isOpen: false
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
apply: function apply(tr, mediaInsertPluginState) {
|
|
19
|
+
var meta = tr.getMeta(_pluginKey.pluginKey);
|
|
20
|
+
if (meta) {
|
|
21
|
+
switch (meta.type) {
|
|
22
|
+
case _actions.ACTION_OPEN_POPUP:
|
|
23
|
+
return {
|
|
24
|
+
isOpen: true
|
|
25
|
+
};
|
|
26
|
+
case _actions.ACTION_CLOSE_POPUP:
|
|
27
|
+
return {
|
|
28
|
+
isOpen: false
|
|
29
|
+
};
|
|
30
|
+
default:
|
|
31
|
+
return mediaInsertPluginState;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
return mediaInsertPluginState;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
key: _pluginKey.pluginKey
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.MediaInsertContent = void 0;
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _new = _interopRequireDefault(require("@atlaskit/button/new"));
|
|
11
|
+
var _primitives = require("@atlaskit/primitives");
|
|
12
|
+
var _tabs = _interopRequireWildcard(require("@atlaskit/tabs"));
|
|
13
|
+
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); }
|
|
14
|
+
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 && Object.prototype.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; }
|
|
15
|
+
var MediaInsertContent = exports.MediaInsertContent = function MediaInsertContent() {
|
|
16
|
+
return /*#__PURE__*/_react.default.createElement(_tabs.default, {
|
|
17
|
+
id: "media-insert-tab-navigation"
|
|
18
|
+
}, /*#__PURE__*/_react.default.createElement(_primitives.Box, {
|
|
19
|
+
paddingBlockEnd: "space.150"
|
|
20
|
+
}, /*#__PURE__*/_react.default.createElement(_tabs.TabList, null, /*#__PURE__*/_react.default.createElement(_tabs.Tab, null, /*#__PURE__*/_react.default.createElement(_new.default, {
|
|
21
|
+
autoFocus: true,
|
|
22
|
+
appearance: "subtle"
|
|
23
|
+
}, "Link")))), /*#__PURE__*/_react.default.createElement(_tabs.TabPanel, null, /*#__PURE__*/_react.default.createElement("p", null, "InsertLinkPanel here")));
|
|
24
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.MediaInsertPicker = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
11
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
12
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
13
|
+
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
14
|
+
var _MediaInsertContent = require("./MediaInsertContent");
|
|
15
|
+
var _MediaInsertWrapper = require("./MediaInsertWrapper");
|
|
16
|
+
var PopupWithListeners = (0, _ui.withOuterListeners)(_ui.Popup);
|
|
17
|
+
var getDomRefFromSelection = function getDomRefFromSelection(view, dispatchAnalyticsEvent) {
|
|
18
|
+
try {
|
|
19
|
+
var domRef = (0, _utils.findDomRefAtPos)(view.state.selection.from, view.domAtPos.bind(view));
|
|
20
|
+
if (domRef instanceof HTMLElement) {
|
|
21
|
+
return domRef;
|
|
22
|
+
} else {
|
|
23
|
+
throw new Error('Invalid DOM reference');
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (dispatchAnalyticsEvent) {
|
|
27
|
+
var payload = {
|
|
28
|
+
action: _analytics.ACTION.ERRORED,
|
|
29
|
+
actionSubject: _analytics.ACTION_SUBJECT.PICKER,
|
|
30
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
31
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL,
|
|
32
|
+
attributes: {
|
|
33
|
+
error: 'Error getting DOM reference from selection'
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
dispatchAnalyticsEvent(payload);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var MediaInsertPicker = exports.MediaInsertPicker = function MediaInsertPicker(_ref) {
|
|
41
|
+
var api = _ref.api,
|
|
42
|
+
editorView = _ref.editorView,
|
|
43
|
+
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
44
|
+
popupsMountPoint = _ref.popupsMountPoint,
|
|
45
|
+
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
46
|
+
popupsScrollableElement = _ref.popupsScrollableElement,
|
|
47
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker;
|
|
48
|
+
var targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
49
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['mediaInsert']),
|
|
50
|
+
mediaInsertState = _useSharedPluginState.mediaInsertState;
|
|
51
|
+
if (!mediaInsertState || !mediaInsertState.isOpen) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
var handleClose = function handleClose(exitMethod) {
|
|
55
|
+
return function (event) {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
if (dispatchAnalyticsEvent) {
|
|
58
|
+
var payload = {
|
|
59
|
+
action: _analytics.ACTION.CLOSED,
|
|
60
|
+
actionSubject: _analytics.ACTION_SUBJECT.PICKER,
|
|
61
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
62
|
+
eventType: _analytics.EVENT_TYPE.UI,
|
|
63
|
+
attributes: {
|
|
64
|
+
exitMethod: exitMethod
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
dispatchAnalyticsEvent(payload);
|
|
68
|
+
}
|
|
69
|
+
closeMediaInsertPicker();
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
return /*#__PURE__*/_react.default.createElement(PopupWithListeners
|
|
73
|
+
// TODO: i18n
|
|
74
|
+
, {
|
|
75
|
+
ariaLabel: 'Media Insert',
|
|
76
|
+
offset: [0, 12],
|
|
77
|
+
target: targetRef,
|
|
78
|
+
zIndex: _editorSharedStyles.akEditorFloatingDialogZIndex,
|
|
79
|
+
mountTo: popupsMountPoint,
|
|
80
|
+
boundariesElement: popupsBoundariesElement,
|
|
81
|
+
handleClickOutside: handleClose(_analytics.INPUT_METHOD.MOUSE),
|
|
82
|
+
handleEscapeKeydown: handleClose(_analytics.INPUT_METHOD.KEYBOARD),
|
|
83
|
+
scrollableElement: popupsScrollableElement,
|
|
84
|
+
focusTrap: true
|
|
85
|
+
}, /*#__PURE__*/_react.default.createElement(_MediaInsertWrapper.MediaInsertWrapper, null, /*#__PURE__*/_react.default.createElement(_MediaInsertContent.MediaInsertContent, null)));
|
|
86
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.MediaInsertWrapper = void 0;
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _primitives = require("@atlaskit/primitives");
|
|
10
|
+
var styles = (0, _primitives.xcss)({
|
|
11
|
+
boxShadow: 'elevation.shadow.overflow',
|
|
12
|
+
width: '340px',
|
|
13
|
+
padding: 'space.200',
|
|
14
|
+
borderRadius: 'border.radius'
|
|
15
|
+
});
|
|
16
|
+
var MediaInsertWrapper = exports.MediaInsertWrapper = function MediaInsertWrapper(_ref) {
|
|
17
|
+
var children = _ref.children;
|
|
18
|
+
return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
|
|
19
|
+
xcss: styles
|
|
20
|
+
}, children);
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { pluginKey } from './pm-plugins/plugin-key';
|
|
2
|
+
export const ACTION_OPEN_POPUP = 'OPEN_POPUP';
|
|
3
|
+
export const ACTION_CLOSE_POPUP = 'CLOSE_POPUP';
|
|
4
|
+
const setPopupMeta = ({
|
|
5
|
+
type,
|
|
6
|
+
tr
|
|
7
|
+
}) => tr.setMeta(pluginKey, {
|
|
8
|
+
type
|
|
9
|
+
});
|
|
10
|
+
export const showMediaInsertPopup = tr => {
|
|
11
|
+
return setPopupMeta({
|
|
12
|
+
type: ACTION_OPEN_POPUP,
|
|
13
|
+
tr
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export const closeMediaInsertPicker = tr => {
|
|
17
|
+
return setPopupMeta({
|
|
18
|
+
type: ACTION_CLOSE_POPUP,
|
|
19
|
+
tr
|
|
20
|
+
});
|
|
21
|
+
};
|
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 {};
|
|
@@ -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 {};
|
|
@@ -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 var MediaInsertContent = function 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
|
+
var PopupWithListeners = withOuterListeners(Popup);
|
|
10
|
+
var getDomRefFromSelection = function getDomRefFromSelection(view, dispatchAnalyticsEvent) {
|
|
11
|
+
try {
|
|
12
|
+
var 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
|
+
var 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 var MediaInsertPicker = function MediaInsertPicker(_ref) {
|
|
34
|
+
var api = _ref.api,
|
|
35
|
+
editorView = _ref.editorView,
|
|
36
|
+
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
37
|
+
popupsMountPoint = _ref.popupsMountPoint,
|
|
38
|
+
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
39
|
+
popupsScrollableElement = _ref.popupsScrollableElement,
|
|
40
|
+
closeMediaInsertPicker = _ref.closeMediaInsertPicker;
|
|
41
|
+
var targetRef = getDomRefFromSelection(editorView, dispatchAnalyticsEvent);
|
|
42
|
+
var _useSharedPluginState = useSharedPluginState(api, ['mediaInsert']),
|
|
43
|
+
mediaInsertState = _useSharedPluginState.mediaInsertState;
|
|
44
|
+
if (!mediaInsertState || !mediaInsertState.isOpen) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var handleClose = function handleClose(exitMethod) {
|
|
48
|
+
return function (event) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
if (dispatchAnalyticsEvent) {
|
|
51
|
+
var payload = {
|
|
52
|
+
action: ACTION.CLOSED,
|
|
53
|
+
actionSubject: ACTION_SUBJECT.PICKER,
|
|
54
|
+
actionSubjectId: ACTION_SUBJECT_ID.PICKER_MEDIA,
|
|
55
|
+
eventType: EVENT_TYPE.UI,
|
|
56
|
+
attributes: {
|
|
57
|
+
exitMethod: exitMethod
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
dispatchAnalyticsEvent(payload);
|
|
61
|
+
}
|
|
62
|
+
closeMediaInsertPicker();
|
|
63
|
+
};
|
|
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,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
3
|
+
var styles = xcss({
|
|
4
|
+
boxShadow: 'elevation.shadow.overflow',
|
|
5
|
+
width: '340px',
|
|
6
|
+
padding: 'space.200',
|
|
7
|
+
borderRadius: 'border.radius'
|
|
8
|
+
});
|
|
9
|
+
export var MediaInsertWrapper = function MediaInsertWrapper(_ref) {
|
|
10
|
+
var children = _ref.children;
|
|
11
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
12
|
+
xcss: styles
|
|
13
|
+
}, children);
|
|
14
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export type MediaInsertPluginAction = typeof ACTION_OPEN_POPUP | typeof ACTION_CLOSE_POPUP;
|
|
3
|
+
export declare const ACTION_OPEN_POPUP = "OPEN_POPUP";
|
|
4
|
+
export declare const ACTION_CLOSE_POPUP = "CLOSE_POPUP";
|
|
5
|
+
export declare const showMediaInsertPopup: (tr: Transaction) => Transaction;
|
|
6
|
+
export declare const closeMediaInsertPicker: (tr: Transaction) => Transaction;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/plugin.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, UiComponentFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
export type MediaInsertPluginState = {
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type MediaInsertPlugin = NextEditorPlugin<'mediaInsert', {
|
|
8
|
+
dependencies: [OptionalPlugin<AnalyticsPlugin>];
|
|
9
|
+
sharedState: MediaInsertPluginState;
|
|
10
|
+
}>;
|
|
11
|
+
export type MediaInsertPickerProps = Pick<UiComponentFactoryParams, 'editorView' | 'dispatchAnalyticsEvent' | 'popupsMountPoint' | 'popupsBoundariesElement' | 'popupsScrollableElement'> & {
|
|
12
|
+
api?: ExtractInjectionAPI<MediaInsertPlugin>;
|
|
13
|
+
closeMediaInsertPicker: () => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type MediaInsertPickerProps } from '../types';
|
|
3
|
+
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, }: MediaInsertPickerProps) => JSX.Element | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export type MediaInsertPluginAction = typeof ACTION_OPEN_POPUP | typeof ACTION_CLOSE_POPUP;
|
|
3
|
+
export declare const ACTION_OPEN_POPUP = "OPEN_POPUP";
|
|
4
|
+
export declare const ACTION_CLOSE_POPUP = "CLOSE_POPUP";
|
|
5
|
+
export declare const showMediaInsertPopup: (tr: Transaction) => Transaction;
|
|
6
|
+
export declare const closeMediaInsertPicker: (tr: Transaction) => Transaction;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, UiComponentFactoryParams } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
+
export type MediaInsertPluginState = {
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type MediaInsertPlugin = NextEditorPlugin<'mediaInsert', {
|
|
8
|
+
dependencies: [
|
|
9
|
+
OptionalPlugin<AnalyticsPlugin>
|
|
10
|
+
];
|
|
11
|
+
sharedState: MediaInsertPluginState;
|
|
12
|
+
}>;
|
|
13
|
+
export type MediaInsertPickerProps = Pick<UiComponentFactoryParams, 'editorView' | 'dispatchAnalyticsEvent' | 'popupsMountPoint' | 'popupsBoundariesElement' | 'popupsScrollableElement'> & {
|
|
14
|
+
api?: ExtractInjectionAPI<MediaInsertPlugin>;
|
|
15
|
+
closeMediaInsertPicker: () => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type MediaInsertPickerProps } from '../types';
|
|
3
|
+
export declare const MediaInsertPicker: ({ api, editorView, dispatchAnalyticsEvent, popupsMountPoint, popupsBoundariesElement, popupsScrollableElement, closeMediaInsertPicker, }: MediaInsertPickerProps) => JSX.Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media-insert",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Media Insert plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,13 +25,17 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@atlaskit/button": "^19.2.0",
|
|
28
|
-
"@atlaskit/editor-common": "^87.
|
|
28
|
+
"@atlaskit/editor-common": "^87.9.0",
|
|
29
|
+
"@atlaskit/editor-plugin-analytics": "^1.7.0",
|
|
30
|
+
"@atlaskit/editor-prosemirror": "5.0.1",
|
|
31
|
+
"@atlaskit/editor-shared-styles": "^2.13.0",
|
|
29
32
|
"@atlaskit/icon": "^22.12.0",
|
|
30
33
|
"@atlaskit/media-card": "^78.0.0",
|
|
31
34
|
"@atlaskit/media-client": "^27.3.0",
|
|
32
35
|
"@atlaskit/media-client-react": "^2.0.0",
|
|
33
36
|
"@atlaskit/primitives": "^12.0.0",
|
|
34
37
|
"@atlaskit/section-message": "^6.6.0",
|
|
38
|
+
"@atlaskit/tabs": "^16.4.0",
|
|
35
39
|
"@atlaskit/textfield": "^6.5.0",
|
|
36
40
|
"@babel/runtime": "^7.0.0",
|
|
37
41
|
"react": "^16.8.0",
|