@atlaskit/editor-plugin-media 0.6.12 → 0.8.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 +20 -0
- package/dist/cjs/commands/linking.js +61 -18
- package/dist/cjs/nodeviews/mediaInline.js +9 -1
- package/dist/cjs/pm-plugins/linking/index.js +3 -2
- 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/current-media-node.js +22 -1
- package/dist/es2019/commands/linking.js +63 -20
- package/dist/es2019/nodeviews/mediaInline.js +7 -1
- package/dist/es2019/pm-plugins/linking/index.js +3 -2
- 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/current-media-node.js +23 -0
- package/dist/esm/commands/linking.js +63 -20
- package/dist/esm/nodeviews/mediaInline.js +9 -1
- package/dist/esm/pm-plugins/linking/index.js +3 -2
- 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/current-media-node.js +21 -0
- package/dist/types/toolbar/linking-toolbar-appearance.d.ts +1 -0
- package/dist/types/toolbar/mediaInline.d.ts +4 -2
- 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/current-media-node.d.ts +5 -0
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 0.7.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#61685](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61685) [`ac1ec9ea4cd3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ac1ec9ea4cd3) - [ux] Add border mark support to mediaInline in Editor/Renderer
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
3
23
|
## 0.6.12
|
|
4
24
|
|
|
5
25
|
### Patch 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) {
|
|
@@ -115,6 +115,7 @@ var handleNewNode = exports.handleNewNode = function handleNewNode(props) {
|
|
|
115
115
|
});
|
|
116
116
|
};
|
|
117
117
|
var MediaInline = exports.MediaInline = function MediaInline(props) {
|
|
118
|
+
var _props$node;
|
|
118
119
|
var _useState = (0, _react.useState)(),
|
|
119
120
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
120
121
|
viewMediaClientConfig = _useState2[0],
|
|
@@ -185,6 +186,9 @@ var MediaInline = exports.MediaInline = function MediaInline(props) {
|
|
|
185
186
|
});
|
|
186
187
|
}
|
|
187
188
|
var allowInlineImages = props.mediaPluginState.allowInlineImages;
|
|
189
|
+
var borderMark = (_props$node = props.node) === null || _props$node === void 0 || (_props$node = _props$node.marks) === null || _props$node === void 0 ? void 0 : _props$node.find(function (mark) {
|
|
190
|
+
return mark.type.name === 'border';
|
|
191
|
+
});
|
|
188
192
|
if (allowInlineImages && (0, _isType.isImage)(type)) {
|
|
189
193
|
return /*#__PURE__*/_react.default.createElement(_mediaInline.MediaInlineImageCard, {
|
|
190
194
|
mediaClient: (0, _mediaClientReact.getMediaClient)(viewMediaClientConfig),
|
|
@@ -192,7 +196,11 @@ var MediaInline = exports.MediaInline = function MediaInline(props) {
|
|
|
192
196
|
isSelected: props.isSelected,
|
|
193
197
|
alt: alt,
|
|
194
198
|
width: width,
|
|
195
|
-
height: height
|
|
199
|
+
height: height,
|
|
200
|
+
border: {
|
|
201
|
+
borderSize: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
|
|
202
|
+
borderColor: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.color
|
|
203
|
+
}
|
|
196
204
|
});
|
|
197
205
|
}
|
|
198
206
|
return /*#__PURE__*/_react.default.createElement(_mediaCard.MediaInlineCard, {
|
|
@@ -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) {
|
|
@@ -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,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) {
|
|
@@ -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) => {
|
|
@@ -62,6 +62,7 @@ export const handleNewNode = props => {
|
|
|
62
62
|
mediaPluginState.handleMediaNodeMount(node, () => getPos());
|
|
63
63
|
};
|
|
64
64
|
export const MediaInline = props => {
|
|
65
|
+
var _props$node, _props$node$marks;
|
|
65
66
|
const [viewMediaClientConfig, setViewMediaClientConfig] = useState();
|
|
66
67
|
const [isContextIdUnsync, setIsContextIdUnsync] = useState(true);
|
|
67
68
|
useEffect(() => {
|
|
@@ -114,6 +115,7 @@ export const MediaInline = props => {
|
|
|
114
115
|
const {
|
|
115
116
|
allowInlineImages
|
|
116
117
|
} = props.mediaPluginState;
|
|
118
|
+
const borderMark = (_props$node = props.node) === null || _props$node === void 0 ? void 0 : (_props$node$marks = _props$node.marks) === null || _props$node$marks === void 0 ? void 0 : _props$node$marks.find(mark => mark.type.name === 'border');
|
|
117
119
|
if (allowInlineImages && isImage(type)) {
|
|
118
120
|
return /*#__PURE__*/React.createElement(MediaInlineImageCard, {
|
|
119
121
|
mediaClient: getMediaClient(viewMediaClientConfig),
|
|
@@ -121,7 +123,11 @@ export const MediaInline = props => {
|
|
|
121
123
|
isSelected: props.isSelected,
|
|
122
124
|
alt: alt,
|
|
123
125
|
width: width,
|
|
124
|
-
height: height
|
|
126
|
+
height: height,
|
|
127
|
+
border: {
|
|
128
|
+
borderSize: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
|
|
129
|
+
borderColor: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.color
|
|
130
|
+
}
|
|
125
131
|
});
|
|
126
132
|
}
|
|
127
133
|
return /*#__PURE__*/React.createElement(MediaInlineCard, {
|
|
@@ -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');
|
|
@@ -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
|
}
|
|
@@ -11,14 +11,15 @@ export function shouldShowMediaLinkToolbar(editorState) {
|
|
|
11
11
|
}
|
|
12
12
|
const {
|
|
13
13
|
nodes: {
|
|
14
|
-
media
|
|
14
|
+
media,
|
|
15
|
+
mediaInline
|
|
15
16
|
},
|
|
16
17
|
marks: {
|
|
17
18
|
link
|
|
18
19
|
}
|
|
19
20
|
} = editorState.schema;
|
|
20
21
|
const node = editorState.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
21
|
-
if (!node || node.type
|
|
22
|
+
if (!node || ![media, mediaInline].includes(node.type)) {
|
|
22
23
|
return false;
|
|
23
24
|
}
|
|
24
25
|
const {
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { IconEmbed, IconInline } from '@atlaskit/editor-common/card';
|
|
3
4
|
import commonMessages, { cardMessages, mediaAndEmbedToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
4
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
6
7
|
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
7
8
|
import { messages } from '@atlaskit/media-ui';
|
|
9
|
+
import { showLinkingToolbar } from '../commands/linking';
|
|
10
|
+
import { getMediaLinkingState } from '../pm-plugins/linking';
|
|
8
11
|
import { isImage } from '../utils/is-type';
|
|
9
12
|
import { changeInlineToMediaCard, changeMediaInlineToMediaSingle, removeInlineCard } from './commands';
|
|
10
13
|
import { FilePreviewItem } from './filePreviewItem';
|
|
14
|
+
import { LinkToolbarAppearance } from './linking-toolbar-appearance';
|
|
11
15
|
import { downloadMedia } from './utils';
|
|
12
|
-
export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) => {
|
|
16
|
+
export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options = {}) => {
|
|
13
17
|
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
14
18
|
const editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
15
19
|
const widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
@@ -17,8 +21,9 @@ export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState
|
|
|
17
21
|
mediaInline
|
|
18
22
|
} = state.schema.nodes;
|
|
19
23
|
const mediaType = state.selection instanceof NodeSelection && state.selection.node.attrs.type;
|
|
24
|
+
const mediaLinkingState = getMediaLinkingState(state);
|
|
20
25
|
if (mediaPluginState.allowInlineImages && isImage(mediaType)) {
|
|
21
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
26
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState);
|
|
22
27
|
}
|
|
23
28
|
const items = [{
|
|
24
29
|
id: 'editor.media.view.switcher',
|
|
@@ -91,15 +96,16 @@ export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState
|
|
|
91
96
|
}];
|
|
92
97
|
return items;
|
|
93
98
|
};
|
|
94
|
-
export const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) => {
|
|
99
|
+
export const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState) => {
|
|
95
100
|
const {
|
|
96
101
|
mediaInline
|
|
97
102
|
} = state.schema.nodes;
|
|
98
103
|
const mediaInlineImageTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
99
104
|
const mediaSingleTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
105
|
+
|
|
100
106
|
// if type is image, return inline image floating toolbar items
|
|
101
107
|
const inlineImageItems = [
|
|
102
|
-
// TODO: border marks, media single switcher,
|
|
108
|
+
// TODO: border marks, media single switcher, alt text, etc
|
|
103
109
|
{
|
|
104
110
|
id: 'editor.media.convert.mediainline',
|
|
105
111
|
type: 'button',
|
|
@@ -123,6 +129,52 @@ export const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverD
|
|
|
123
129
|
onClick: changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState)
|
|
124
130
|
}, {
|
|
125
131
|
type: 'separator'
|
|
132
|
+
}, {
|
|
133
|
+
type: 'custom',
|
|
134
|
+
fallback: [],
|
|
135
|
+
render: (editorView, idx) => {
|
|
136
|
+
if (editorView !== null && editorView !== void 0 && editorView.state) {
|
|
137
|
+
const editLink = () => {
|
|
138
|
+
if (editorView) {
|
|
139
|
+
const {
|
|
140
|
+
state,
|
|
141
|
+
dispatch
|
|
142
|
+
} = editorView;
|
|
143
|
+
showLinkingToolbar(state, dispatch);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const openLink = () => {
|
|
147
|
+
if (editorView) {
|
|
148
|
+
var _pluginInjectionApi$a2;
|
|
149
|
+
const {
|
|
150
|
+
state: {
|
|
151
|
+
tr
|
|
152
|
+
},
|
|
153
|
+
dispatch
|
|
154
|
+
} = editorView;
|
|
155
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.attachAnalyticsEvent({
|
|
156
|
+
eventType: EVENT_TYPE.TRACK,
|
|
157
|
+
action: ACTION.VISITED,
|
|
158
|
+
actionSubject: ACTION_SUBJECT.MEDIA,
|
|
159
|
+
actionSubjectId: ACTION_SUBJECT_ID.LINK
|
|
160
|
+
})(tr);
|
|
161
|
+
dispatch(tr);
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
|
|
166
|
+
key: idx,
|
|
167
|
+
editorState: editorView.state,
|
|
168
|
+
intl: intl,
|
|
169
|
+
mediaLinkingState: mediaLinkingState,
|
|
170
|
+
onAddLink: editLink,
|
|
171
|
+
onEditLink: editLink,
|
|
172
|
+
onOpenLink: openLink,
|
|
173
|
+
isInlineNode: true
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
126
178
|
}, {
|
|
127
179
|
type: 'copy-button',
|
|
128
180
|
items: [{
|
|
@@ -18,10 +18,33 @@ export const currentMediaNodeWithPos = editorState => {
|
|
|
18
18
|
pos
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
+
export const currentMediaInlineNodeWithPos = editorState => {
|
|
22
|
+
const {
|
|
23
|
+
doc,
|
|
24
|
+
selection,
|
|
25
|
+
schema
|
|
26
|
+
} = editorState;
|
|
27
|
+
if (!doc || !selection || !(selection instanceof NodeSelection) || selection.node.type !== schema.nodes.mediaInline) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const pos = selection.$anchor.pos;
|
|
31
|
+
const node = doc.nodeAt(pos);
|
|
32
|
+
if (!node || node.type !== schema.nodes.mediaInline) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
node,
|
|
37
|
+
pos
|
|
38
|
+
};
|
|
39
|
+
};
|
|
21
40
|
export const currentMediaNode = editorState => {
|
|
22
41
|
var _currentMediaNodeWith;
|
|
23
42
|
return (_currentMediaNodeWith = currentMediaNodeWithPos(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node;
|
|
24
43
|
};
|
|
44
|
+
export const currentMediaInlineNode = editorState => {
|
|
45
|
+
var _currentMediaInlineNo;
|
|
46
|
+
return (_currentMediaInlineNo = currentMediaInlineNodeWithPos(editorState)) === null || _currentMediaInlineNo === void 0 ? void 0 : _currentMediaInlineNo.node;
|
|
47
|
+
};
|
|
25
48
|
export const currentMediaNodeBorderMark = editorState => {
|
|
26
49
|
const node = currentMediaNode(editorState);
|
|
27
50
|
if (!node) {
|
|
@@ -2,18 +2,18 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
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; }
|
|
3
3
|
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) { _defineProperty(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; }
|
|
4
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
5
|
-
import { createToggleBlockMarkOnRange } from '@atlaskit/editor-common/commands';
|
|
5
|
+
import { createToggleBlockMarkOnRange, createToggleInlineMarkOnRange } from '@atlaskit/editor-common/commands';
|
|
6
6
|
import { normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import { createMediaLinkingCommand, getMediaLinkingState, mediaLinkingPluginKey } from '../pm-plugins/linking';
|
|
8
8
|
import { MediaLinkingActionsTypes } from '../pm-plugins/linking/actions';
|
|
9
9
|
import { getMediaPluginState } from '../pm-plugins/main';
|
|
10
10
|
import { checkMediaType } from '../utils/check-media-type';
|
|
11
|
-
import { currentMediaNode } from '../utils/current-media-node';
|
|
11
|
+
import { currentMediaInlineNode, currentMediaNode } from '../utils/current-media-node';
|
|
12
12
|
export var showLinkingToolbar = createMediaLinkingCommand(function (state) {
|
|
13
13
|
var mediaLinkingState = getMediaLinkingState(state);
|
|
14
14
|
if (mediaLinkingState && mediaLinkingState.mediaPos !== null) {
|
|
15
|
-
var
|
|
16
|
-
if (
|
|
15
|
+
var node = state.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
16
|
+
if (node) {
|
|
17
17
|
return {
|
|
18
18
|
type: MediaLinkingActionsTypes.showToolbar
|
|
19
19
|
};
|
|
@@ -24,7 +24,10 @@ export var showLinkingToolbar = createMediaLinkingCommand(function (state) {
|
|
|
24
24
|
export var showLinkingToolbarWithMediaTypeCheck = function showLinkingToolbarWithMediaTypeCheck(editorState, dispatch, editorView) {
|
|
25
25
|
if (dispatch && editorView) {
|
|
26
26
|
var mediaNode = currentMediaNode(editorState);
|
|
27
|
-
|
|
27
|
+
var mediaInlineNode = currentMediaInlineNode(editorState);
|
|
28
|
+
var nodeSelection = editorState.selection;
|
|
29
|
+
var currentSelectedNode = nodeSelection.node;
|
|
30
|
+
if (!mediaNode && !mediaInlineNode) {
|
|
28
31
|
return false;
|
|
29
32
|
}
|
|
30
33
|
var _getMediaPluginState = getMediaPluginState(editorState),
|
|
@@ -32,15 +35,28 @@ export var showLinkingToolbarWithMediaTypeCheck = function showLinkingToolbarWit
|
|
|
32
35
|
if (!mediaClientConfig) {
|
|
33
36
|
return false;
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
if (mediaNode && currentSelectedNode !== mediaInlineNode) {
|
|
39
|
+
checkMediaType(mediaNode, mediaClientConfig).then(function (mediaType) {
|
|
40
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
41
|
+
// We make sure the selection and the node hasn't changed.
|
|
42
|
+
currentMediaNode(editorView.state) === mediaNode) {
|
|
43
|
+
dispatch(editorView.state.tr.setMeta(mediaLinkingPluginKey, {
|
|
44
|
+
type: MediaLinkingActionsTypes.showToolbar
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (mediaInlineNode) {
|
|
50
|
+
checkMediaType(mediaInlineNode, mediaClientConfig).then(function (mediaType) {
|
|
51
|
+
if ((mediaType === 'external' || mediaType === 'image') &&
|
|
52
|
+
// We make sure the selection and the node hasn't changed.
|
|
53
|
+
currentMediaInlineNode(editorView.state) === mediaInlineNode) {
|
|
54
|
+
dispatch(editorView.state.tr.setMeta(mediaLinkingPluginKey, {
|
|
55
|
+
type: MediaLinkingActionsTypes.showToolbar
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
return true;
|
|
46
62
|
};
|
|
@@ -90,10 +106,37 @@ function toggleLinkMark(tr, state, _ref) {
|
|
|
90
106
|
return tr;
|
|
91
107
|
}
|
|
92
108
|
var linkMark = state.schema.marks.link;
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
var _state$schema$nodes = state.schema.nodes,
|
|
110
|
+
media = _state$schema$nodes.media,
|
|
111
|
+
mediaInline = _state$schema$nodes.mediaInline;
|
|
112
|
+
if (node.type !== mediaInline) {
|
|
113
|
+
var toggleBlockLinkMark = createToggleBlockMarkOnRange(linkMark, function (prevAttrs, node) {
|
|
114
|
+
// Only add mark to media
|
|
115
|
+
if (!node || node.type !== media) {
|
|
116
|
+
return; //No op
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (forceRemove) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
var href = normalizeUrl(url);
|
|
123
|
+
if (prevAttrs && prevAttrs.href === href) {
|
|
124
|
+
return; //No op
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (href.trim() === '') {
|
|
128
|
+
return false; // remove
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return _objectSpread(_objectSpread({}, prevAttrs), {}, {
|
|
132
|
+
href: href
|
|
133
|
+
});
|
|
134
|
+
}, [media]);
|
|
135
|
+
toggleBlockLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
136
|
+
}
|
|
137
|
+
var toggleInlineLinkMark = createToggleInlineMarkOnRange(linkMark, function (prevAttrs, node) {
|
|
138
|
+
// Only add mark to mediaInline
|
|
139
|
+
if (!node || node.type !== mediaInline) {
|
|
97
140
|
return; //No op
|
|
98
141
|
}
|
|
99
142
|
|
|
@@ -112,8 +155,8 @@ function toggleLinkMark(tr, state, _ref) {
|
|
|
112
155
|
return _objectSpread(_objectSpread({}, prevAttrs), {}, {
|
|
113
156
|
href: href
|
|
114
157
|
});
|
|
115
|
-
}
|
|
116
|
-
|
|
158
|
+
});
|
|
159
|
+
toggleInlineLinkMark($pos.pos, $pos.pos + node.nodeSize, tr, state);
|
|
117
160
|
return tr;
|
|
118
161
|
}
|
|
119
162
|
var fireAnalyticForMediaLink = function fireAnalyticForMediaLink(tr, action) {
|
|
@@ -105,6 +105,7 @@ export var handleNewNode = function handleNewNode(props) {
|
|
|
105
105
|
});
|
|
106
106
|
};
|
|
107
107
|
export var MediaInline = function MediaInline(props) {
|
|
108
|
+
var _props$node;
|
|
108
109
|
var _useState = useState(),
|
|
109
110
|
_useState2 = _slicedToArray(_useState, 2),
|
|
110
111
|
viewMediaClientConfig = _useState2[0],
|
|
@@ -175,6 +176,9 @@ export var MediaInline = function MediaInline(props) {
|
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
178
|
var allowInlineImages = props.mediaPluginState.allowInlineImages;
|
|
179
|
+
var borderMark = (_props$node = props.node) === null || _props$node === void 0 || (_props$node = _props$node.marks) === null || _props$node === void 0 ? void 0 : _props$node.find(function (mark) {
|
|
180
|
+
return mark.type.name === 'border';
|
|
181
|
+
});
|
|
178
182
|
if (allowInlineImages && isImage(type)) {
|
|
179
183
|
return /*#__PURE__*/React.createElement(MediaInlineImageCard, {
|
|
180
184
|
mediaClient: getMediaClient(viewMediaClientConfig),
|
|
@@ -182,7 +186,11 @@ export var MediaInline = function MediaInline(props) {
|
|
|
182
186
|
isSelected: props.isSelected,
|
|
183
187
|
alt: alt,
|
|
184
188
|
width: width,
|
|
185
|
-
height: height
|
|
189
|
+
height: height,
|
|
190
|
+
border: {
|
|
191
|
+
borderSize: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.size,
|
|
192
|
+
borderColor: borderMark === null || borderMark === void 0 ? void 0 : borderMark.attrs.color
|
|
193
|
+
}
|
|
186
194
|
});
|
|
187
195
|
}
|
|
188
196
|
return /*#__PURE__*/React.createElement(MediaInlineCard, {
|
|
@@ -25,9 +25,10 @@ function onSelectionChanged(tr) {
|
|
|
25
25
|
if (!isNodeSelection) {
|
|
26
26
|
return initialState;
|
|
27
27
|
}
|
|
28
|
-
var
|
|
28
|
+
var pos = tr.selection.$from.pos;
|
|
29
|
+
var mediaPos = tr.selection.node.type.name === 'mediaInline' ? pos : pos + 1;
|
|
29
30
|
var node = tr.doc.nodeAt(mediaPos);
|
|
30
|
-
if (!node || node.type.name
|
|
31
|
+
if (!node || !['media', 'mediaInline'].includes(node.type.name)) {
|
|
31
32
|
return initialState;
|
|
32
33
|
}
|
|
33
34
|
var mark = node.marks.find(function (mark) {
|
|
@@ -507,7 +507,7 @@ export var floatingToolbar = function floatingToolbar(state, intl) {
|
|
|
507
507
|
var element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(".".concat(MediaInlineNodeSelector));
|
|
508
508
|
return element || mediaPluginState.element;
|
|
509
509
|
};
|
|
510
|
-
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
510
|
+
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
|
|
511
511
|
} else {
|
|
512
512
|
baseToolbar.getDomRef = function () {
|
|
513
513
|
var _mediaPluginState$ele3;
|
|
@@ -7,13 +7,12 @@ import { css, jsx } from '@emotion/react';
|
|
|
7
7
|
import { isSafeUrl } from '@atlaskit/adf-schema';
|
|
8
8
|
import { addLink, ToolTipContent } from '@atlaskit/editor-common/keymaps';
|
|
9
9
|
import { linkMessages, linkToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
10
|
-
import { FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
|
|
11
|
-
import { FloatingToolbarSeparator as Separator } from '@atlaskit/editor-common/ui';
|
|
10
|
+
import { FloatingToolbarSeparator as Separator, FloatingToolbarButton as ToolbarButton } from '@atlaskit/editor-common/ui';
|
|
12
11
|
import LinkIcon from '@atlaskit/icon/glyph/editor/link';
|
|
13
12
|
import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
14
13
|
import { stateKey } from '../pm-plugins/plugin-key';
|
|
15
14
|
import { checkMediaType } from '../utils/check-media-type';
|
|
16
|
-
import { currentMediaNode } from '../utils/current-media-node';
|
|
15
|
+
import { currentMediaInlineNode, currentMediaNode } from '../utils/current-media-node';
|
|
17
16
|
// need this wrapper, need to have 4px between items.
|
|
18
17
|
var wrapper = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n margin-right: ", ";\n"])), "var(--ds-space-050, 4px)");
|
|
19
18
|
export var LinkToolbarAppearance = function LinkToolbarAppearance(_ref) {
|
|
@@ -22,14 +21,15 @@ export var LinkToolbarAppearance = function LinkToolbarAppearance(_ref) {
|
|
|
22
21
|
intl = _ref.intl,
|
|
23
22
|
onAddLink = _ref.onAddLink,
|
|
24
23
|
onEditLink = _ref.onEditLink,
|
|
25
|
-
onOpenLink = _ref.onOpenLink
|
|
24
|
+
onOpenLink = _ref.onOpenLink,
|
|
25
|
+
isInlineNode = _ref.isInlineNode;
|
|
26
26
|
var _useState = useState(true),
|
|
27
27
|
_useState2 = _slicedToArray(_useState, 2),
|
|
28
28
|
showLinkingControls = _useState2[0],
|
|
29
29
|
setShowLinkingControls = _useState2[1];
|
|
30
30
|
useEffect(function () {
|
|
31
31
|
var _stateKey$getState;
|
|
32
|
-
var mediaNode = currentMediaNode(editorState);
|
|
32
|
+
var mediaNode = isInlineNode ? currentMediaInlineNode(editorState) : currentMediaNode(editorState);
|
|
33
33
|
if (!mediaNode) {
|
|
34
34
|
setShowLinkingControls(false);
|
|
35
35
|
return;
|
|
@@ -42,7 +42,7 @@ export var LinkToolbarAppearance = function LinkToolbarAppearance(_ref) {
|
|
|
42
42
|
checkMediaType(mediaNode, mediaClientConfig).then(function (mediaType) {
|
|
43
43
|
setShowLinkingControls(mediaType === 'external' || mediaType === 'image');
|
|
44
44
|
});
|
|
45
|
-
}, [editorState]);
|
|
45
|
+
}, [editorState, isInlineNode]);
|
|
46
46
|
if (!showLinkingControls) {
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
@@ -13,10 +13,12 @@ export function shouldShowMediaLinkToolbar(editorState) {
|
|
|
13
13
|
return false;
|
|
14
14
|
}
|
|
15
15
|
var _editorState$schema = editorState.schema,
|
|
16
|
-
|
|
16
|
+
_editorState$schema$n = _editorState$schema.nodes,
|
|
17
|
+
media = _editorState$schema$n.media,
|
|
18
|
+
mediaInline = _editorState$schema$n.mediaInline,
|
|
17
19
|
link = _editorState$schema.marks.link;
|
|
18
20
|
var node = editorState.doc.nodeAt(mediaLinkingState.mediaPos);
|
|
19
|
-
if (!node || node.type
|
|
21
|
+
if (!node || ![media, mediaInline].includes(node.type)) {
|
|
20
22
|
return false;
|
|
21
23
|
}
|
|
22
24
|
var _editorState$doc$reso = editorState.doc.resolve(mediaLinkingState.mediaPos),
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
3
|
import { IconEmbed, IconInline } from '@atlaskit/editor-common/card';
|
|
3
4
|
import commonMessages, { cardMessages, mediaAndEmbedToolbarMessages } from '@atlaskit/editor-common/messages';
|
|
4
5
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
6
|
import DownloadIcon from '@atlaskit/icon/glyph/download';
|
|
6
7
|
import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
|
|
7
8
|
import { messages } from '@atlaskit/media-ui';
|
|
9
|
+
import { showLinkingToolbar } from '../commands/linking';
|
|
10
|
+
import { getMediaLinkingState } from '../pm-plugins/linking';
|
|
8
11
|
import { isImage } from '../utils/is-type';
|
|
9
12
|
import { changeInlineToMediaCard, changeMediaInlineToMediaSingle, removeInlineCard } from './commands';
|
|
10
13
|
import { FilePreviewItem } from './filePreviewItem';
|
|
14
|
+
import { LinkToolbarAppearance } from './linking-toolbar-appearance';
|
|
11
15
|
import { downloadMedia } from './utils';
|
|
12
16
|
export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) {
|
|
13
17
|
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
18
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
14
19
|
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
15
20
|
var widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
16
21
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
17
22
|
var mediaType = state.selection instanceof NodeSelection && state.selection.node.attrs.type;
|
|
23
|
+
var mediaLinkingState = getMediaLinkingState(state);
|
|
18
24
|
if (mediaPluginState.allowInlineImages && isImage(mediaType)) {
|
|
19
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
25
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState);
|
|
20
26
|
}
|
|
21
27
|
var items = [{
|
|
22
28
|
id: 'editor.media.view.switcher',
|
|
@@ -89,13 +95,14 @@ export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloa
|
|
|
89
95
|
}];
|
|
90
96
|
return items;
|
|
91
97
|
};
|
|
92
|
-
export var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) {
|
|
98
|
+
export var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState, pluginInjectionApi, mediaLinkingState) {
|
|
93
99
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
94
100
|
var mediaInlineImageTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
95
101
|
var mediaSingleTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
102
|
+
|
|
96
103
|
// if type is image, return inline image floating toolbar items
|
|
97
104
|
var inlineImageItems = [
|
|
98
|
-
// TODO: border marks, media single switcher,
|
|
105
|
+
// TODO: border marks, media single switcher, alt text, etc
|
|
99
106
|
{
|
|
100
107
|
id: 'editor.media.convert.mediainline',
|
|
101
108
|
type: 'button',
|
|
@@ -123,6 +130,46 @@ export var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(stat
|
|
|
123
130
|
onClick: changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState)
|
|
124
131
|
}, {
|
|
125
132
|
type: 'separator'
|
|
133
|
+
}, {
|
|
134
|
+
type: 'custom',
|
|
135
|
+
fallback: [],
|
|
136
|
+
render: function render(editorView, idx) {
|
|
137
|
+
if (editorView !== null && editorView !== void 0 && editorView.state) {
|
|
138
|
+
var editLink = function editLink() {
|
|
139
|
+
if (editorView) {
|
|
140
|
+
var _state = editorView.state,
|
|
141
|
+
dispatch = editorView.dispatch;
|
|
142
|
+
showLinkingToolbar(_state, dispatch);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var openLink = function openLink() {
|
|
146
|
+
if (editorView) {
|
|
147
|
+
var _pluginInjectionApi$a2;
|
|
148
|
+
var tr = editorView.state.tr,
|
|
149
|
+
dispatch = editorView.dispatch;
|
|
150
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.actions.attachAnalyticsEvent({
|
|
151
|
+
eventType: EVENT_TYPE.TRACK,
|
|
152
|
+
action: ACTION.VISITED,
|
|
153
|
+
actionSubject: ACTION_SUBJECT.MEDIA,
|
|
154
|
+
actionSubjectId: ACTION_SUBJECT_ID.LINK
|
|
155
|
+
})(tr);
|
|
156
|
+
dispatch(tr);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
|
|
161
|
+
key: idx,
|
|
162
|
+
editorState: editorView.state,
|
|
163
|
+
intl: intl,
|
|
164
|
+
mediaLinkingState: mediaLinkingState,
|
|
165
|
+
onAddLink: editLink,
|
|
166
|
+
onEditLink: editLink,
|
|
167
|
+
onOpenLink: openLink,
|
|
168
|
+
isInlineNode: true
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
126
173
|
}, {
|
|
127
174
|
type: 'copy-button',
|
|
128
175
|
items: [{
|
|
@@ -16,10 +16,31 @@ export var currentMediaNodeWithPos = function currentMediaNodeWithPos(editorStat
|
|
|
16
16
|
pos: pos
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
+
export var currentMediaInlineNodeWithPos = function currentMediaInlineNodeWithPos(editorState) {
|
|
20
|
+
var doc = editorState.doc,
|
|
21
|
+
selection = editorState.selection,
|
|
22
|
+
schema = editorState.schema;
|
|
23
|
+
if (!doc || !selection || !(selection instanceof NodeSelection) || selection.node.type !== schema.nodes.mediaInline) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
var pos = selection.$anchor.pos;
|
|
27
|
+
var node = doc.nodeAt(pos);
|
|
28
|
+
if (!node || node.type !== schema.nodes.mediaInline) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
node: node,
|
|
33
|
+
pos: pos
|
|
34
|
+
};
|
|
35
|
+
};
|
|
19
36
|
export var currentMediaNode = function currentMediaNode(editorState) {
|
|
20
37
|
var _currentMediaNodeWith;
|
|
21
38
|
return (_currentMediaNodeWith = currentMediaNodeWithPos(editorState)) === null || _currentMediaNodeWith === void 0 ? void 0 : _currentMediaNodeWith.node;
|
|
22
39
|
};
|
|
40
|
+
export var currentMediaInlineNode = function currentMediaInlineNode(editorState) {
|
|
41
|
+
var _currentMediaInlineNo;
|
|
42
|
+
return (_currentMediaInlineNo = currentMediaInlineNodeWithPos(editorState)) === null || _currentMediaInlineNo === void 0 ? void 0 : _currentMediaInlineNo.node;
|
|
43
|
+
};
|
|
23
44
|
export var currentMediaNodeBorderMark = function currentMediaNodeBorderMark(editorState) {
|
|
24
45
|
var node = currentMediaNode(editorState);
|
|
25
46
|
if (!node) {
|
|
@@ -10,5 +10,6 @@ export interface LinkingToolbarProps {
|
|
|
10
10
|
onAddLink: React.MouseEventHandler;
|
|
11
11
|
onEditLink: React.MouseEventHandler;
|
|
12
12
|
onOpenLink: React.MouseEventHandler;
|
|
13
|
+
isInlineNode?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export declare const LinkToolbarAppearance: React.FC<LinkingToolbarProps>;
|
|
@@ -5,6 +5,8 @@ import type { HoverDecorationHandler } from '@atlaskit/editor-plugin-decorations
|
|
|
5
5
|
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
6
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import type { MediaNextEditorPluginType } from '../next-plugin-type';
|
|
8
|
+
import type { MediaLinkingState } from '../pm-plugins/linking';
|
|
8
9
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
10
|
+
import type { MediaFloatingToolbarOptions } from '../types';
|
|
11
|
+
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, options?: MediaFloatingToolbarOptions) => FloatingToolbarItem<Command>[];
|
|
12
|
+
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, mediaLinkingState: MediaLinkingState) => FloatingToolbarItem<Command>[];
|
|
@@ -5,5 +5,10 @@ export declare const currentMediaNodeWithPos: (editorState: EditorState) => {
|
|
|
5
5
|
node: PMNode;
|
|
6
6
|
pos: number;
|
|
7
7
|
} | undefined;
|
|
8
|
+
export declare const currentMediaInlineNodeWithPos: (editorState: EditorState) => {
|
|
9
|
+
node: PMNode;
|
|
10
|
+
pos: number;
|
|
11
|
+
} | undefined;
|
|
8
12
|
export declare const currentMediaNode: (editorState: EditorState) => PMNode | undefined;
|
|
13
|
+
export declare const currentMediaInlineNode: (editorState: EditorState) => PMNode | undefined;
|
|
9
14
|
export declare const currentMediaNodeBorderMark: (editorState: EditorState) => BorderMarkAttributes | undefined;
|
|
@@ -10,5 +10,6 @@ export interface LinkingToolbarProps {
|
|
|
10
10
|
onAddLink: React.MouseEventHandler;
|
|
11
11
|
onEditLink: React.MouseEventHandler;
|
|
12
12
|
onOpenLink: React.MouseEventHandler;
|
|
13
|
+
isInlineNode?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export declare const LinkToolbarAppearance: React.FC<LinkingToolbarProps>;
|
|
@@ -5,6 +5,8 @@ import type { HoverDecorationHandler } from '@atlaskit/editor-plugin-decorations
|
|
|
5
5
|
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
6
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import type { MediaNextEditorPluginType } from '../next-plugin-type';
|
|
8
|
+
import type { MediaLinkingState } from '../pm-plugins/linking';
|
|
8
9
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
9
|
-
|
|
10
|
-
export declare const
|
|
10
|
+
import type { MediaFloatingToolbarOptions } from '../types';
|
|
11
|
+
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, options?: MediaFloatingToolbarOptions) => FloatingToolbarItem<Command>[];
|
|
12
|
+
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined, mediaLinkingState: MediaLinkingState) => FloatingToolbarItem<Command>[];
|
|
@@ -5,5 +5,10 @@ export declare const currentMediaNodeWithPos: (editorState: EditorState) => {
|
|
|
5
5
|
node: PMNode;
|
|
6
6
|
pos: number;
|
|
7
7
|
} | undefined;
|
|
8
|
+
export declare const currentMediaInlineNodeWithPos: (editorState: EditorState) => {
|
|
9
|
+
node: PMNode;
|
|
10
|
+
pos: number;
|
|
11
|
+
} | undefined;
|
|
8
12
|
export declare const currentMediaNode: (editorState: EditorState) => PMNode | undefined;
|
|
13
|
+
export declare const currentMediaInlineNode: (editorState: EditorState) => PMNode | undefined;
|
|
9
14
|
export declare const currentMediaNodeBorderMark: (editorState: EditorState) => BorderMarkAttributes | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"atlassian": {
|
|
11
11
|
"team": "Editor: Media Experience Porygon",
|
|
12
12
|
"releaseModel": "continuous",
|
|
13
|
-
"singleton": true
|
|
13
|
+
"singleton": true,
|
|
14
|
+
"runReact18": false
|
|
14
15
|
},
|
|
15
16
|
"repository": "https://bitbucket.org/atlassian/atlassian-frontend",
|
|
16
17
|
"main": "dist/cjs/index.js",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"@atlaskit/analytics-namespaced-context": "^6.7.0",
|
|
37
38
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
38
39
|
"@atlaskit/button": "^17.1.0",
|
|
39
|
-
"@atlaskit/editor-common": "^76.
|
|
40
|
+
"@atlaskit/editor-common": "^76.29.0",
|
|
40
41
|
"@atlaskit/editor-palette": "1.5.2",
|
|
41
42
|
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
42
43
|
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|
|
@@ -64,8 +65,8 @@
|
|
|
64
65
|
"@atlaskit/platform-feature-flags": "^0.2.0",
|
|
65
66
|
"@atlaskit/textfield": "^6.0.0",
|
|
66
67
|
"@atlaskit/theme": "^12.6.0",
|
|
67
|
-
"@atlaskit/tokens": "^1.
|
|
68
|
-
"@atlaskit/tooltip": "^18.
|
|
68
|
+
"@atlaskit/tokens": "^1.31.0",
|
|
69
|
+
"@atlaskit/tooltip": "^18.1.0",
|
|
69
70
|
"@babel/runtime": "^7.0.0",
|
|
70
71
|
"@emotion/react": "^11.7.1",
|
|
71
72
|
"classnames": "^2.2.5",
|