@atlaskit/editor-plugin-media 0.7.0 → 0.8.1
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 +17 -0
- package/dist/cjs/commands/linking.js +61 -18
- package/dist/cjs/pm-plugins/linking/index.js +3 -2
- package/dist/cjs/pm-plugins/mediaResizeAnnouncerMess.js +1 -1
- package/dist/cjs/toolbar/index.js +1 -1
- package/dist/cjs/toolbar/linking-toolbar-appearance.js +4 -3
- package/dist/cjs/toolbar/linking.js +4 -2
- package/dist/cjs/toolbar/mediaInline.js +52 -5
- package/dist/cjs/utils/analytics.js +25 -2
- package/dist/cjs/utils/current-media-node.js +22 -1
- package/dist/cjs/utils/media-single.js +11 -3
- package/dist/es2019/commands/linking.js +63 -20
- package/dist/es2019/pm-plugins/linking/index.js +3 -2
- package/dist/es2019/pm-plugins/mediaResizeAnnouncerMess.js +1 -1
- package/dist/es2019/toolbar/index.js +1 -1
- package/dist/es2019/toolbar/linking-toolbar-appearance.js +6 -6
- package/dist/es2019/toolbar/linking.js +3 -2
- package/dist/es2019/toolbar/mediaInline.js +56 -4
- package/dist/es2019/utils/analytics.js +20 -1
- package/dist/es2019/utils/current-media-node.js +23 -0
- package/dist/es2019/utils/media-single.js +11 -3
- package/dist/esm/commands/linking.js +63 -20
- package/dist/esm/pm-plugins/linking/index.js +3 -2
- package/dist/esm/pm-plugins/mediaResizeAnnouncerMess.js +1 -1
- package/dist/esm/toolbar/index.js +1 -1
- package/dist/esm/toolbar/linking-toolbar-appearance.js +6 -6
- package/dist/esm/toolbar/linking.js +4 -2
- package/dist/esm/toolbar/mediaInline.js +50 -3
- package/dist/esm/utils/analytics.js +23 -1
- package/dist/esm/utils/current-media-node.js +21 -0
- package/dist/esm/utils/media-single.js +11 -3
- package/dist/types/toolbar/linking-toolbar-appearance.d.ts +1 -0
- package/dist/types/toolbar/mediaInline.d.ts +4 -2
- package/dist/types/utils/analytics.d.ts +4 -1
- package/dist/types/utils/current-media-node.d.ts +5 -0
- package/dist/types-ts4.5/toolbar/linking-toolbar-appearance.d.ts +1 -0
- package/dist/types-ts4.5/toolbar/mediaInline.d.ts +4 -2
- package/dist/types-ts4.5/utils/analytics.d.ts +4 -1
- package/dist/types-ts4.5/utils/current-media-node.d.ts +5 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 0.8.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#63388](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63388) [`999a8302f404`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/999a8302f404) - add analytics for changing media inline to media single
|
|
8
|
+
- [#63608](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63608) [`bfb98fe84eae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bfb98fe84eae) - [ux] EDF-93: Report and resolve existing duplicate i18n message descriptor keys/IDs in editor, as precursor work to adding CI check
|
|
9
|
+
|
|
10
|
+
## 0.8.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#62560](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/62560) [`5ad72b247e6a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5ad72b247e6a) - [ux] ED-20895 Added linking support for inline images
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 0.7.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -19,8 +19,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
19
19
|
var showLinkingToolbar = exports.showLinkingToolbar = (0, _linking.createMediaLinkingCommand)(function (state) {
|
|
20
20
|
var mediaLinkingState = (0, _linking.getMediaLinkingState)(state);
|
|
21
21
|
if (mediaLinkingState && mediaLinkingState.mediaPos !== null) {
|
|
22
|
-
var
|
|
23
|
-
if (
|
|
22
|
+
var node = state.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
23
|
+
if (node) {
|
|
24
24
|
return {
|
|
25
25
|
type: _actions.MediaLinkingActionsTypes.showToolbar
|
|
26
26
|
};
|
|
@@ -31,7 +31,10 @@ var showLinkingToolbar = exports.showLinkingToolbar = (0, _linking.createMediaLi
|
|
|
31
31
|
var showLinkingToolbarWithMediaTypeCheck = exports.showLinkingToolbarWithMediaTypeCheck = function showLinkingToolbarWithMediaTypeCheck(editorState, dispatch, editorView) {
|
|
32
32
|
if (dispatch && editorView) {
|
|
33
33
|
var mediaNode = (0, _currentMediaNode.currentMediaNode)(editorState);
|
|
34
|
-
|
|
34
|
+
var mediaInlineNode = (0, _currentMediaNode.currentMediaInlineNode)(editorState);
|
|
35
|
+
var nodeSelection = editorState.selection;
|
|
36
|
+
var currentSelectedNode = nodeSelection.node;
|
|
37
|
+
if (!mediaNode && !mediaInlineNode) {
|
|
35
38
|
return false;
|
|
36
39
|
}
|
|
37
40
|
var _getMediaPluginState = (0, _main.getMediaPluginState)(editorState),
|
|
@@ -39,15 +42,28 @@ var showLinkingToolbarWithMediaTypeCheck = exports.showLinkingToolbarWithMediaTy
|
|
|
39
42
|
if (!mediaClientConfig) {
|
|
40
43
|
return false;
|
|
41
44
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
if (mediaNode && currentSelectedNode !== mediaInlineNode) {
|
|
46
|
+
(0, _checkMediaType.checkMediaType)(mediaNode, mediaClientConfig).then(function (mediaType) {
|
|
47
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
48
|
+
// We make sure the selection and the node hasn't changed.
|
|
49
|
+
(0, _currentMediaNode.currentMediaNode)(editorView.state) === mediaNode) {
|
|
50
|
+
dispatch(editorView.state.tr.setMeta(_linking.mediaLinkingPluginKey, {
|
|
51
|
+
type: _actions.MediaLinkingActionsTypes.showToolbar
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (mediaInlineNode) {
|
|
57
|
+
(0, _checkMediaType.checkMediaType)(mediaInlineNode, mediaClientConfig).then(function (mediaType) {
|
|
58
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
59
|
+
// We make sure the selection and the node hasn't changed.
|
|
60
|
+
(0, _currentMediaNode.currentMediaInlineNode)(editorView.state) === mediaInlineNode) {
|
|
61
|
+
dispatch(editorView.state.tr.setMeta(_linking.mediaLinkingPluginKey, {
|
|
62
|
+
type: _actions.MediaLinkingActionsTypes.showToolbar
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
51
67
|
}
|
|
52
68
|
return true;
|
|
53
69
|
};
|
|
@@ -97,10 +113,37 @@ function toggleLinkMark(tr, state, _ref) {
|
|
|
97
113
|
return tr;
|
|
98
114
|
}
|
|
99
115
|
var linkMark = state.schema.marks.link;
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
117
|
+
media = _state$schema$nodes.media,
|
|
118
|
+
mediaInline = _state$schema$nodes.mediaInline;
|
|
119
|
+
if (node.type !== mediaInline) {
|
|
120
|
+
var toggleBlockLinkMark = (0, _commands.createToggleBlockMarkOnRange)(linkMark, function (prevAttrs, node) {
|
|
121
|
+
// Only add mark to media
|
|
122
|
+
if (!node || node.type !== media) {
|
|
123
|
+
return; //No op
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (forceRemove) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
var href = (0, _utils.normalizeUrl)(url);
|
|
130
|
+
if (prevAttrs && prevAttrs.href === href) {
|
|
131
|
+
return; //No op
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (href.trim() === '') {
|
|
135
|
+
return false; // remove
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return _objectSpread(_objectSpread({}, prevAttrs), {}, {
|
|
139
|
+
href: href
|
|
140
|
+
});
|
|
141
|
+
}, [media]);
|
|
142
|
+
toggleBlockLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
143
|
+
}
|
|
144
|
+
var toggleInlineLinkMark = (0, _commands.createToggleInlineMarkOnRange)(linkMark, function (prevAttrs, node) {
|
|
145
|
+
// Only add mark to mediaInline
|
|
146
|
+
if (!node || node.type !== mediaInline) {
|
|
104
147
|
return; //No op
|
|
105
148
|
}
|
|
106
149
|
|
|
@@ -119,8 +162,8 @@ function toggleLinkMark(tr, state, _ref) {
|
|
|
119
162
|
return _objectSpread(_objectSpread({}, prevAttrs), {}, {
|
|
120
163
|
href: href
|
|
121
164
|
});
|
|
122
|
-
}
|
|
123
|
-
|
|
165
|
+
});
|
|
166
|
+
toggleInlineLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
124
167
|
return tr;
|
|
125
168
|
}
|
|
126
169
|
var fireAnalyticForMediaLink = function fireAnalyticForMediaLink(tr, action) {
|
|
@@ -32,9 +32,10 @@ function onSelectionChanged(tr) {
|
|
|
32
32
|
if (!isNodeSelection) {
|
|
33
33
|
return initialState;
|
|
34
34
|
}
|
|
35
|
-
var
|
|
35
|
+
var pos = tr.selection.$from.pos;
|
|
36
|
+
var mediaPos = tr.selection.node.type.name === 'mediaInline' ? pos : pos + 1;
|
|
36
37
|
var node = tr.doc.nodeAt(mediaPos);
|
|
37
|
-
if (!node || node.type.name
|
|
38
|
+
if (!node || !['media', 'mediaInline'].includes(node.type.name)) {
|
|
38
39
|
return initialState;
|
|
39
40
|
}
|
|
40
41
|
var mark = node.marks.find(function (mark) {
|
|
@@ -22,7 +22,7 @@ var mediaResizeAnnouncerMess = exports.mediaResizeAnnouncerMess = (0, _reactIntl
|
|
|
22
22
|
description: 'Media width {action} to {newMediaWidth} pixels.'
|
|
23
23
|
},
|
|
24
24
|
IncreasedAction: {
|
|
25
|
-
id: 'fabric.editor.media.
|
|
25
|
+
id: 'fabric.editor.media.increased',
|
|
26
26
|
defaultMessage: 'increased',
|
|
27
27
|
description: 'Increased action'
|
|
28
28
|
},
|
|
@@ -517,7 +517,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
517
517
|
var element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(".".concat(_styles.MediaInlineNodeSelector));
|
|
518
518
|
return element || mediaPluginState.element;
|
|
519
519
|
};
|
|
520
|
-
items = (0, _mediaInline.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
520
|
+
items = (0, _mediaInline.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
|
|
521
521
|
} else {
|
|
522
522
|
baseToolbar.getDomRef = function () {
|
|
523
523
|
var _mediaPluginState$ele3;
|
|
@@ -31,14 +31,15 @@ var LinkToolbarAppearance = exports.LinkToolbarAppearance = function LinkToolbar
|
|
|
31
31
|
intl = _ref.intl,
|
|
32
32
|
onAddLink = _ref.onAddLink,
|
|
33
33
|
onEditLink = _ref.onEditLink,
|
|
34
|
-
onOpenLink = _ref.onOpenLink
|
|
34
|
+
onOpenLink = _ref.onOpenLink,
|
|
35
|
+
isInlineNode = _ref.isInlineNode;
|
|
35
36
|
var _useState = (0, _react.useState)(true),
|
|
36
37
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
37
38
|
showLinkingControls = _useState2[0],
|
|
38
39
|
setShowLinkingControls = _useState2[1];
|
|
39
40
|
(0, _react.useEffect)(function () {
|
|
40
41
|
var _stateKey$getState;
|
|
41
|
-
var mediaNode = (0, _currentMediaNode.currentMediaNode)(editorState);
|
|
42
|
+
var mediaNode = isInlineNode ? (0, _currentMediaNode.currentMediaInlineNode)(editorState) : (0, _currentMediaNode.currentMediaNode)(editorState);
|
|
42
43
|
if (!mediaNode) {
|
|
43
44
|
setShowLinkingControls(false);
|
|
44
45
|
return;
|
|
@@ -51,7 +52,7 @@ var LinkToolbarAppearance = exports.LinkToolbarAppearance = function LinkToolbar
|
|
|
51
52
|
(0, _checkMediaType.checkMediaType)(mediaNode, mediaClientConfig).then(function (mediaType) {
|
|
52
53
|
setShowLinkingControls(mediaType === 'external' || mediaType === 'image');
|
|
53
54
|
});
|
|
54
|
-
}, [editorState]);
|
|
55
|
+
}, [editorState, isInlineNode]);
|
|
55
56
|
if (!showLinkingControls) {
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
@@ -21,10 +21,12 @@ function shouldShowMediaLinkToolbar(editorState) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
var _editorState$schema = editorState.schema,
|
|
24
|
-
|
|
24
|
+
_editorState$schema$n = _editorState$schema.nodes,
|
|
25
|
+
media = _editorState$schema$n.media,
|
|
26
|
+
mediaInline = _editorState$schema$n.mediaInline,
|
|
25
27
|
link = _editorState$schema.marks.link;
|
|
26
28
|
var node = editorState.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
27
|
-
if (!node || node.type
|
|
29
|
+
if (!node || ![media, mediaInline].includes(node.type)) {
|
|
28
30
|
return false;
|
|
29
31
|
}
|
|
30
32
|
var _editorState$doc$reso = editorState.doc.resolve(mediaLinkingState.mediaPos),
|
|
@@ -7,26 +7,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getMediaInlineImageToolbar = exports.generateMediaInlineFloatingToolbar = void 0;
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
11
|
var _card = require("@atlaskit/editor-common/card");
|
|
11
12
|
var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
|
|
12
|
-
var
|
|
13
|
+
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
13
14
|
var _download = _interopRequireDefault(require("@atlaskit/icon/glyph/download"));
|
|
14
15
|
var _remove = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/remove"));
|
|
15
16
|
var _mediaUi = require("@atlaskit/media-ui");
|
|
17
|
+
var _linking = require("../commands/linking");
|
|
18
|
+
var _linking2 = require("../pm-plugins/linking");
|
|
16
19
|
var _isType = require("../utils/is-type");
|
|
17
20
|
var _commands = require("./commands");
|
|
18
21
|
var _filePreviewItem = require("./filePreviewItem");
|
|
22
|
+
var _linkingToolbarAppearance = require("./linking-toolbar-appearance");
|
|
19
23
|
var _utils = require("./utils");
|
|
20
24
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
25
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
22
26
|
var generateMediaInlineFloatingToolbar = exports.generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) {
|
|
23
27
|
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
28
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
24
29
|
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
25
30
|
var widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
26
31
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
27
|
-
var mediaType = state.selection instanceof
|
|
32
|
+
var mediaType = state.selection instanceof _state2.NodeSelection && state.selection.node.attrs.type;
|
|
33
|
+
var mediaLinkingState = (0, _linking2.getMediaLinkingState)(state);
|
|
28
34
|
if (mediaPluginState.allowInlineImages && (0, _isType.isImage)(mediaType)) {
|
|
29
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
35
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState);
|
|
30
36
|
}
|
|
31
37
|
var items = [{
|
|
32
38
|
id: 'editor.media.view.switcher',
|
|
@@ -99,13 +105,14 @@ var generateMediaInlineFloatingToolbar = exports.generateMediaInlineFloatingTool
|
|
|
99
105
|
}];
|
|
100
106
|
return items;
|
|
101
107
|
};
|
|
102
|
-
var getMediaInlineImageToolbar = exports.getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) {
|
|
108
|
+
var getMediaInlineImageToolbar = exports.getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState) {
|
|
103
109
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
104
110
|
var mediaInlineImageTitle = intl.formatMessage(_messages.mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
105
111
|
var mediaSingleTitle = intl.formatMessage(_messages.mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
112
|
+
|
|
106
113
|
// if type is image, return inline image floating toolbar items
|
|
107
114
|
var inlineImageItems = [
|
|
108
|
-
// TODO: border marks, media single switcher,
|
|
115
|
+
// TODO: border marks, media single switcher, alt text, etc
|
|
109
116
|
{
|
|
110
117
|
id: 'editor.media.convert.mediainline',
|
|
111
118
|
type: 'button',
|
|
@@ -133,6 +140,46 @@ var getMediaInlineImageToolbar = exports.getMediaInlineImageToolbar = function g
|
|
|
133
140
|
onClick: (0, _commands.changeMediaInlineToMediaSingle)(editorAnalyticsAPI, widthPluginState)
|
|
134
141
|
}, {
|
|
135
142
|
type: 'separator'
|
|
143
|
+
}, {
|
|
144
|
+
type: 'custom',
|
|
145
|
+
fallback: [],
|
|
146
|
+
render: function render(editorView, idx) {
|
|
147
|
+
if (editorView !== null && editorView !== void 0 && editorView.state) {
|
|
148
|
+
var editLink = function editLink() {
|
|
149
|
+
if (editorView) {
|
|
150
|
+
var _state = editorView.state,
|
|
151
|
+
dispatch = editorView.dispatch;
|
|
152
|
+
(0, _linking.showLinkingToolbar)(_state, dispatch);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
var openLink = function openLink() {
|
|
156
|
+
if (editorView) {
|
|
157
|
+
var _pluginInjectionApi$a2;
|
|
158
|
+
var tr = editorView.state.tr,
|
|
159
|
+
dispatch = editorView.dispatch;
|
|
160
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.actions.attachAnalyticsEvent({
|
|
161
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
162
|
+
action: _analytics.ACTION.VISITED,
|
|
163
|
+
actionSubject: _analytics.ACTION_SUBJECT.MEDIA,
|
|
164
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.LINK
|
|
165
|
+
})(tr);
|
|
166
|
+
dispatch(tr);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return /*#__PURE__*/_react.default.createElement(_linkingToolbarAppearance.LinkToolbarAppearance, {
|
|
171
|
+
key: idx,
|
|
172
|
+
editorState: editorView.state,
|
|
173
|
+
intl: intl,
|
|
174
|
+
mediaLinkingState: mediaLinkingState,
|
|
175
|
+
onAddLink: editLink,
|
|
176
|
+
onEditLink: editLink,
|
|
177
|
+
onOpenLink: openLink,
|
|
178
|
+
isInlineNode: true
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
136
183
|
}, {
|
|
137
184
|
type: 'copy-button',
|
|
138
185
|
items: [{
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.findChangeFromLocation = findChangeFromLocation;
|
|
7
|
+
exports.getMediaResizeAnalyticsEvent = exports.getMediaInputResizeAnalyticsEvent = exports.getChangeMediaAnalytics = void 0;
|
|
7
8
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
|
+
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
8
10
|
var getMediaResizeAnalyticsEvent = exports.getMediaResizeAnalyticsEvent = function getMediaResizeAnalyticsEvent(type, attributes) {
|
|
9
11
|
if (!attributes) {
|
|
10
12
|
return;
|
|
@@ -54,4 +56,25 @@ var getMediaInputResizeAnalyticsEvent = exports.getMediaInputResizeAnalyticsEven
|
|
|
54
56
|
},
|
|
55
57
|
eventType: _analytics.EVENT_TYPE.UI
|
|
56
58
|
};
|
|
57
|
-
};
|
|
59
|
+
};
|
|
60
|
+
var getChangeMediaAnalytics = exports.getChangeMediaAnalytics = function getChangeMediaAnalytics(previousType, newType, changeFromLocation) {
|
|
61
|
+
return {
|
|
62
|
+
action: _analytics.ACTION.CHANGED_TYPE,
|
|
63
|
+
actionSubject: _analytics.ACTION_SUBJECT.MEDIA,
|
|
64
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
65
|
+
attributes: {
|
|
66
|
+
newType: newType,
|
|
67
|
+
previousType: previousType,
|
|
68
|
+
changeFromLocation: changeFromLocation
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
function findChangeFromLocation(selection) {
|
|
73
|
+
var _selection$$from$doc$ = selection.$from.doc.type,
|
|
74
|
+
schema = _selection$$from$doc$.schema,
|
|
75
|
+
name = _selection$$from$doc$.name;
|
|
76
|
+
var parentNodeInfo = (0, _utils.findParentNode)(function (node) {
|
|
77
|
+
return node.type !== schema.nodes.paragraph;
|
|
78
|
+
})(selection);
|
|
79
|
+
return parentNodeInfo ? parentNodeInfo.node.type.name : name;
|
|
80
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.currentMediaNodeWithPos = exports.currentMediaNodeBorderMark = exports.currentMediaNode = void 0;
|
|
6
|
+
exports.currentMediaNodeWithPos = exports.currentMediaNodeBorderMark = exports.currentMediaNode = exports.currentMediaInlineNodeWithPos = exports.currentMediaInlineNode = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
8
|
var currentMediaNodeWithPos = exports.currentMediaNodeWithPos = function currentMediaNodeWithPos(editorState) {
|
|
9
9
|
var doc = editorState.doc,
|
|
@@ -22,10 +22,31 @@ var currentMediaNodeWithPos = exports.currentMediaNodeWithPos = function current
|
|
|
22
22
|
pos: pos
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
var currentMediaInlineNodeWithPos = exports.currentMediaInlineNodeWithPos = function currentMediaInlineNodeWithPos(editorState) {
|
|
26
|
+
var doc = editorState.doc,
|
|
27
|
+
selection = editorState.selection,
|
|
28
|
+
schema = editorState.schema;
|
|
29
|
+
if (!doc || !selection || !(selection instanceof _state.NodeSelection) || selection.node.type !== schema.nodes.mediaInline) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var pos = selection.$anchor.pos;
|
|
33
|
+
var node = doc.nodeAt(pos);
|
|
34
|
+
if (!node || node.type !== schema.nodes.mediaInline) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
node: node,
|
|
39
|
+
pos: pos
|
|
40
|
+
};
|
|
41
|
+
};
|
|
25
42
|
var currentMediaNode = exports.currentMediaNode = function currentMediaNode(editorState) {
|
|
26
43
|
var _currentMediaNodeWith;
|
|
27
44
|
return (_currentMediaNodeWith = currentMediaNodeWithPos(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node;
|
|
28
45
|
};
|
|
46
|
+
var currentMediaInlineNode = exports.currentMediaInlineNode = function currentMediaInlineNode(editorState) {
|
|
47
|
+
var _currentMediaInlineNo;
|
|
48
|
+
return (_currentMediaInlineNo = currentMediaInlineNodeWithPos(editorState)) === null || _currentMediaInlineNo === void 0 ? void 0 : _currentMediaInlineNo.node;
|
|
49
|
+
};
|
|
29
50
|
var currentMediaNodeBorderMark = exports.currentMediaNodeBorderMark = function currentMediaNodeBorderMark(editorState) {
|
|
30
51
|
var node = currentMediaNode(editorState);
|
|
31
52
|
if (!node) {
|
|
@@ -18,6 +18,7 @@ var _model = require("@atlaskit/editor-prosemirror/model");
|
|
|
18
18
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
19
19
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
20
20
|
var _mediaCommon = require("../utils/media-common");
|
|
21
|
+
var _analytics2 = require("./analytics");
|
|
21
22
|
var _isType = require("./is-type");
|
|
22
23
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23
24
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
@@ -45,7 +46,9 @@ function insertNodesWithOptionalParagraph(nodes) {
|
|
|
45
46
|
schema = state.schema;
|
|
46
47
|
var paragraph = schema.nodes.paragraph;
|
|
47
48
|
var inputMethod = analyticsAttributes.inputMethod,
|
|
48
|
-
fileExtension = analyticsAttributes.fileExtension
|
|
49
|
+
fileExtension = analyticsAttributes.fileExtension,
|
|
50
|
+
newType = analyticsAttributes.newType,
|
|
51
|
+
previousType = analyticsAttributes.previousType;
|
|
49
52
|
var openEnd = 0;
|
|
50
53
|
if (shouldAddParagraph(state)) {
|
|
51
54
|
nodes.push(paragraph.create());
|
|
@@ -55,6 +58,9 @@ function insertNodesWithOptionalParagraph(nodes) {
|
|
|
55
58
|
if (inputMethod) {
|
|
56
59
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(getInsertMediaAnalytics(inputMethod, fileExtension))(tr);
|
|
57
60
|
}
|
|
61
|
+
if (newType && previousType) {
|
|
62
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent((0, _analytics2.getChangeMediaAnalytics)(previousType, newType, (0, _analytics2.findChangeFromLocation)(state.selection)))(tr);
|
|
63
|
+
}
|
|
58
64
|
if (dispatch) {
|
|
59
65
|
dispatch(tr);
|
|
60
66
|
}
|
|
@@ -163,7 +169,9 @@ var changeFromMediaInlineToMediaSingleNode = exports.changeFromMediaInlineToMedi
|
|
|
163
169
|
content: node
|
|
164
170
|
})) {
|
|
165
171
|
return insertNodesWithOptionalParagraph([node], {
|
|
166
|
-
fileExtension: fileExtension
|
|
172
|
+
fileExtension: fileExtension,
|
|
173
|
+
newType: _analytics.ACTION_SUBJECT_ID.MEDIA_SINGLE,
|
|
174
|
+
previousType: _analytics.ACTION_SUBJECT_ID.MEDIA_INLINE
|
|
167
175
|
}, editorAnalyticsAPI)(state, dispatch);
|
|
168
176
|
} else {
|
|
169
177
|
var nodePos = state.tr.doc.resolve(state.selection.from).end();
|
|
@@ -174,7 +182,7 @@ var changeFromMediaInlineToMediaSingleNode = exports.changeFromMediaInlineToMedi
|
|
|
174
182
|
var content = shouldAddParagraph(view.state) ? _model.Fragment.fromArray([node, state.schema.nodes.paragraph.create()]) : node;
|
|
175
183
|
tr = (0, _utils2.safeInsert)(content, undefined, true)(state.tr);
|
|
176
184
|
}
|
|
177
|
-
|
|
185
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent((0, _analytics2.getChangeMediaAnalytics)(_analytics.ACTION_SUBJECT_ID.MEDIA_INLINE, _analytics.ACTION_SUBJECT_ID.MEDIA_SINGLE, (0, _analytics2.findChangeFromLocation)(state.selection)))(tr);
|
|
178
186
|
dispatch(tr);
|
|
179
187
|
}
|
|
180
188
|
return true;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import { createToggleBlockMarkOnRange } from '@atlaskit/editor-common/commands';
|
|
2
|
+
import { createToggleBlockMarkOnRange, createToggleInlineMarkOnRange } from '@atlaskit/editor-common/commands';
|
|
3
3
|
import { normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
4
4
|
import { createMediaLinkingCommand, getMediaLinkingState, mediaLinkingPluginKey } from '../pm-plugins/linking';
|
|
5
5
|
import { MediaLinkingActionsTypes } from '../pm-plugins/linking/actions';
|
|
6
6
|
import { getMediaPluginState } from '../pm-plugins/main';
|
|
7
7
|
import { checkMediaType } from '../utils/check-media-type';
|
|
8
|
-
import { currentMediaNode } from '../utils/current-media-node';
|
|
8
|
+
import { currentMediaInlineNode, currentMediaNode } from '../utils/current-media-node';
|
|
9
9
|
export const showLinkingToolbar = createMediaLinkingCommand(state => {
|
|
10
10
|
const mediaLinkingState = getMediaLinkingState(state);
|
|
11
11
|
if (mediaLinkingState && mediaLinkingState.mediaPos !== null) {
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
12
|
+
const node = state.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
13
|
+
if (node) {
|
|
14
14
|
return {
|
|
15
15
|
type: MediaLinkingActionsTypes.showToolbar
|
|
16
16
|
};
|
|
@@ -21,7 +21,10 @@ export const showLinkingToolbar = createMediaLinkingCommand(state => {
|
|
|
21
21
|
export const showLinkingToolbarWithMediaTypeCheck = (editorState, dispatch, editorView) => {
|
|
22
22
|
if (dispatch && editorView) {
|
|
23
23
|
const mediaNode = currentMediaNode(editorState);
|
|
24
|
-
|
|
24
|
+
const mediaInlineNode = currentMediaInlineNode(editorState);
|
|
25
|
+
const nodeSelection = editorState.selection;
|
|
26
|
+
const currentSelectedNode = nodeSelection.node;
|
|
27
|
+
if (!mediaNode && !mediaInlineNode) {
|
|
25
28
|
return false;
|
|
26
29
|
}
|
|
27
30
|
const {
|
|
@@ -30,15 +33,28 @@ export const showLinkingToolbarWithMediaTypeCheck = (editorState, dispatch, edit
|
|
|
30
33
|
if (!mediaClientConfig) {
|
|
31
34
|
return false;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (mediaNode && currentSelectedNode !== mediaInlineNode) {
|
|
37
|
+
checkMediaType(mediaNode, mediaClientConfig).then(mediaType => {
|
|
38
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
39
|
+
// We make sure the selection and the node hasn't changed.
|
|
40
|
+
currentMediaNode(editorView.state) === mediaNode) {
|
|
41
|
+
dispatch(editorView.state.tr.setMeta(mediaLinkingPluginKey, {
|
|
42
|
+
type: MediaLinkingActionsTypes.showToolbar
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (mediaInlineNode) {
|
|
48
|
+
checkMediaType(mediaInlineNode, mediaClientConfig).then(mediaType => {
|
|
49
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
50
|
+
// We make sure the selection and the node hasn't changed.
|
|
51
|
+
currentMediaInlineNode(editorView.state) === mediaInlineNode) {
|
|
52
|
+
dispatch(editorView.state.tr.setMeta(mediaLinkingPluginKey, {
|
|
53
|
+
type: MediaLinkingActionsTypes.showToolbar
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
42
58
|
}
|
|
43
59
|
return true;
|
|
44
60
|
};
|
|
@@ -89,11 +105,38 @@ function toggleLinkMark(tr, state, {
|
|
|
89
105
|
}
|
|
90
106
|
const linkMark = state.schema.marks.link;
|
|
91
107
|
const {
|
|
92
|
-
media
|
|
108
|
+
media,
|
|
109
|
+
mediaInline
|
|
93
110
|
} = state.schema.nodes;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
if (node.type !== mediaInline) {
|
|
112
|
+
const toggleBlockLinkMark = createToggleBlockMarkOnRange(linkMark, (prevAttrs, node) => {
|
|
113
|
+
// Only add mark to media
|
|
114
|
+
if (!node || node.type !== media) {
|
|
115
|
+
return; //No op
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (forceRemove) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
const href = normalizeUrl(url);
|
|
122
|
+
if (prevAttrs && prevAttrs.href === href) {
|
|
123
|
+
return; //No op
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (href.trim() === '') {
|
|
127
|
+
return false; // remove
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
...prevAttrs,
|
|
132
|
+
href: href
|
|
133
|
+
};
|
|
134
|
+
}, [media]);
|
|
135
|
+
toggleBlockLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
136
|
+
}
|
|
137
|
+
const toggleInlineLinkMark = createToggleInlineMarkOnRange(linkMark, (prevAttrs, node) => {
|
|
138
|
+
// Only add mark to mediaInline
|
|
139
|
+
if (!node || node.type !== mediaInline) {
|
|
97
140
|
return; //No op
|
|
98
141
|
}
|
|
99
142
|
|
|
@@ -113,8 +156,8 @@ function toggleLinkMark(tr, state, {
|
|
|
113
156
|
...prevAttrs,
|
|
114
157
|
href: href
|
|
115
158
|
};
|
|
116
|
-
}
|
|
117
|
-
|
|
159
|
+
});
|
|
160
|
+
toggleInlineLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
118
161
|
return tr;
|
|
119
162
|
}
|
|
120
163
|
const fireAnalyticForMediaLink = (tr, action, attributes = undefined, editorAnalyticsAPI) => {
|
|
@@ -23,9 +23,10 @@ function onSelectionChanged(tr) {
|
|
|
23
23
|
if (!isNodeSelection) {
|
|
24
24
|
return initialState;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const pos = tr.selection.$from.pos;
|
|
27
|
+
const mediaPos = tr.selection.node.type.name === 'mediaInline' ? pos : pos + 1;
|
|
27
28
|
const node = tr.doc.nodeAt(mediaPos);
|
|
28
|
-
if (!node || node.type.name
|
|
29
|
+
if (!node || !['media', 'mediaInline'].includes(node.type.name)) {
|
|
29
30
|
return initialState;
|
|
30
31
|
}
|
|
31
32
|
const mark = node.marks.find(mark => mark.type.name === 'link');
|
|
@@ -16,7 +16,7 @@ export const mediaResizeAnnouncerMess = defineMessages({
|
|
|
16
16
|
description: 'Media width {action} to {newMediaWidth} pixels.'
|
|
17
17
|
},
|
|
18
18
|
IncreasedAction: {
|
|
19
|
-
id: 'fabric.editor.media.
|
|
19
|
+
id: 'fabric.editor.media.increased',
|
|
20
20
|
defaultMessage: 'increased',
|
|
21
21
|
description: 'Increased action'
|
|
22
22
|
},
|
|
@@ -520,7 +520,7 @@ export const floatingToolbar = (state, intl, options = {}, pluginInjectionApi) =
|
|
|
520
520
|
const element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(`.${MediaInlineNodeSelector}`);
|
|
521
521
|
return element || mediaPluginState.element;
|
|
522
522
|
};
|
|
523
|
-
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
523
|
+
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
|
|
524
524
|
} else {
|
|
525
525
|
baseToolbar.getDomRef = () => {
|
|
526
526
|
var _mediaPluginState$ele3;
|
|
@@ -4,13 +4,12 @@ import { css, jsx } from '@emotion/react';
|
|
|
4
4
|
import { isSafeUrl } from '@atlaskit/adf-schema';
|
|
5
5
|
import { addLink, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
6
6
|
import { linkMessages, linkToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
7
|
-
import { FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
|
|
8
|
-
import { FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
|
|
7
|
+
import { FloatingToolbarSeparator as Separator, FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
|
|
9
8
|
import LinkIcon from '@atlaskit/icon/glyph/editor/link';
|
|
10
9
|
import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
11
10
|
import { stateKey } from '../pm-plugins/plugin-key';
|
|
12
11
|
import { checkMediaType } from '../utils/check-media-type';
|
|
13
|
-
import { currentMediaNode } from '../utils/current-media-node';
|
|
12
|
+
import { currentMediaInlineNode, currentMediaNode } from '../utils/current-media-node';
|
|
14
13
|
// need this wrapper, need to have 4px between items.
|
|
15
14
|
const wrapper = css`
|
|
16
15
|
display: flex;
|
|
@@ -23,12 +22,13 @@ export const LinkToolbarAppearance = ({
|
|
|
23
22
|
intl,
|
|
24
23
|
onAddLink,
|
|
25
24
|
onEditLink,
|
|
26
|
-
onOpenLink
|
|
25
|
+
onOpenLink,
|
|
26
|
+
isInlineNode
|
|
27
27
|
}) => {
|
|
28
28
|
const [showLinkingControls, setShowLinkingControls] = useState(true);
|
|
29
29
|
useEffect(() => {
|
|
30
30
|
var _stateKey$getState;
|
|
31
|
-
const mediaNode = currentMediaNode(editorState);
|
|
31
|
+
const mediaNode = isInlineNode ? currentMediaInlineNode(editorState) : currentMediaNode(editorState);
|
|
32
32
|
if (!mediaNode) {
|
|
33
33
|
setShowLinkingControls(false);
|
|
34
34
|
return;
|
|
@@ -41,7 +41,7 @@ export const LinkToolbarAppearance = ({
|
|
|
41
41
|
checkMediaType(mediaNode, mediaClientConfig).then(mediaType => {
|
|
42
42
|
setShowLinkingControls(mediaType === 'external' || mediaType === 'image');
|
|
43
43
|
});
|
|
44
|
-
}, [editorState]);
|
|
44
|
+
}, [editorState, isInlineNode]);
|
|
45
45
|
if (!showLinkingControls) {
|
|
46
46
|
return null;
|
|
47
47
|
}
|