@atlaskit/editor-plugin-media 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/toolbar/commands.js +15 -1
- package/dist/cjs/toolbar/index.js +1 -2
- package/dist/cjs/toolbar/mediaInline.js +36 -3
- package/dist/cjs/utils/media-single.js +64 -1
- package/dist/es2019/toolbar/commands.js +14 -0
- package/dist/es2019/toolbar/index.js +1 -2
- package/dist/es2019/toolbar/mediaInline.js +34 -5
- package/dist/es2019/utils/media-single.js +70 -1
- package/dist/esm/toolbar/commands.js +14 -0
- package/dist/esm/toolbar/index.js +1 -2
- package/dist/esm/toolbar/mediaInline.js +38 -5
- package/dist/esm/utils/media-single.js +64 -1
- package/dist/types/toolbar/commands.d.ts +2 -0
- package/dist/types/toolbar/mediaInline.d.ts +5 -3
- package/dist/types/utils/media-single.d.ts +1 -0
- package/dist/types-ts4.5/toolbar/commands.d.ts +2 -0
- package/dist/types-ts4.5/toolbar/mediaInline.d.ts +5 -3
- package/dist/types-ts4.5/utils/media-single.d.ts +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 0.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#59086](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/59086) [`8b5cbc397cfd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8b5cbc397cfd) - [ux] add convert media inline image to media single floating toolbar item
|
|
8
|
+
|
|
9
|
+
## 0.6.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 0.6.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.updateMediaSingleWidth = exports.toggleBorderMark = exports.setBorderMark = exports.removeInlineCard = exports.changeMediaCardToInline = exports.changeInlineToMediaCard = exports.DEFAULT_BORDER_SIZE = exports.DEFAULT_BORDER_COLOR = void 0;
|
|
7
|
+
exports.updateMediaSingleWidth = exports.toggleBorderMark = exports.setBorderMark = exports.removeInlineCard = exports.changeMediaInlineToMediaSingle = exports.changeMediaCardToInline = exports.changeInlineToMediaCard = exports.DEFAULT_BORDER_SIZE = exports.DEFAULT_BORDER_COLOR = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
@@ -12,6 +12,7 @@ var _state = require("@atlaskit/editor-prosemirror/state");
|
|
|
12
12
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
13
13
|
var _analytics2 = require("../utils/analytics");
|
|
14
14
|
var _currentMediaNode = require("../utils/current-media-node");
|
|
15
|
+
var _mediaSingle = require("../utils/media-single");
|
|
15
16
|
var _utils2 = require("./utils");
|
|
16
17
|
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; }
|
|
17
18
|
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; }
|
|
@@ -93,6 +94,19 @@ var changeMediaCardToInline = exports.changeMediaCardToInline = function changeM
|
|
|
93
94
|
return true;
|
|
94
95
|
};
|
|
95
96
|
};
|
|
97
|
+
var changeMediaInlineToMediaSingle = exports.changeMediaInlineToMediaSingle = function changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState) {
|
|
98
|
+
return function (state, dispatch, view) {
|
|
99
|
+
var mediaInline = state.schema.nodes.mediaInline;
|
|
100
|
+
var selectedNode = state.selection instanceof _state.NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
|
|
101
|
+
if (!selectedNode) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (view) {
|
|
105
|
+
return (0, _mediaSingle.changeFromMediaInlineToMediaSingleNode)(view, selectedNode, widthPluginState, editorAnalyticsAPI);
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
96
110
|
var removeInlineCard = exports.removeInlineCard = function removeInlineCard(state, dispatch) {
|
|
97
111
|
if ((0, _utils.isNodeSelection)(state.selection)) {
|
|
98
112
|
if (dispatch) {
|
|
@@ -470,13 +470,12 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
470
470
|
};
|
|
471
471
|
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a7 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a7 === void 0 ? void 0 : _pluginInjectionApi$a7.actions);
|
|
472
472
|
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
473
|
-
var _pluginInjectionApi$a8;
|
|
474
473
|
baseToolbar.getDomRef = function () {
|
|
475
474
|
var _mediaPluginState$ele2;
|
|
476
475
|
var element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(".".concat(_styles.MediaInlineNodeSelector));
|
|
477
476
|
return element || mediaPluginState.element;
|
|
478
477
|
};
|
|
479
|
-
items = (0, _mediaInline.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi
|
|
478
|
+
items = (0, _mediaInline.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
480
479
|
} else {
|
|
481
480
|
baseToolbar.getDomRef = function () {
|
|
482
481
|
var _mediaPluginState$ele3;
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getMediaInlineImageToolbar = exports.generateMediaInlineFloatingToolbar = void 0;
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _card = require("@atlaskit/editor-common/card");
|
|
10
11
|
var _mediaInline = require("@atlaskit/editor-common/media-inline");
|
|
11
12
|
var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
|
|
12
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
@@ -18,11 +19,14 @@ var _filePreviewItem = require("./filePreviewItem");
|
|
|
18
19
|
var _utils = require("./utils");
|
|
19
20
|
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); }
|
|
20
21
|
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; }
|
|
21
|
-
var generateMediaInlineFloatingToolbar = exports.generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration,
|
|
22
|
+
var generateMediaInlineFloatingToolbar = exports.generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) {
|
|
23
|
+
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
24
|
+
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
25
|
+
var widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
22
26
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
23
27
|
var mediaType = state.selection instanceof _state.NodeSelection && state.selection.node.attrs.type;
|
|
24
28
|
if ((0, _mediaInline.shouldShowInlineImage)(mediaType)) {
|
|
25
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI);
|
|
29
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
26
30
|
}
|
|
27
31
|
var items = [{
|
|
28
32
|
id: 'editor.media.view.switcher',
|
|
@@ -95,12 +99,41 @@ var generateMediaInlineFloatingToolbar = exports.generateMediaInlineFloatingTool
|
|
|
95
99
|
}];
|
|
96
100
|
return items;
|
|
97
101
|
};
|
|
98
|
-
var getMediaInlineImageToolbar = exports.getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI) {
|
|
102
|
+
var getMediaInlineImageToolbar = exports.getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) {
|
|
99
103
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
104
|
+
var mediaInlineImageTitle = intl.formatMessage(_messages.mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
105
|
+
var mediaSingleTitle = intl.formatMessage(_messages.mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
100
106
|
// if type is image, return inline image floating toolbar items
|
|
101
107
|
var inlineImageItems = [
|
|
102
108
|
// TODO: border marks, media single switcher, link, alt text, etc
|
|
103
109
|
{
|
|
110
|
+
id: 'editor.media.convert.mediainline',
|
|
111
|
+
type: 'button',
|
|
112
|
+
title: mediaInlineImageTitle,
|
|
113
|
+
icon: function icon() {
|
|
114
|
+
return /*#__PURE__*/_react.default.createElement(_card.IconInline, {
|
|
115
|
+
size: "medium",
|
|
116
|
+
label: mediaInlineImageTitle
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
onClick: function onClick() {
|
|
120
|
+
return true;
|
|
121
|
+
},
|
|
122
|
+
selected: true
|
|
123
|
+
}, {
|
|
124
|
+
id: 'editor.media.convert.mediasingle',
|
|
125
|
+
type: 'button',
|
|
126
|
+
title: mediaSingleTitle,
|
|
127
|
+
icon: function icon() {
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(_card.IconEmbed, {
|
|
129
|
+
size: "medium",
|
|
130
|
+
label: mediaSingleTitle
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
onClick: (0, _commands.changeMediaInlineToMediaSingle)(editorAnalyticsAPI, widthPluginState)
|
|
134
|
+
}, {
|
|
135
|
+
type: 'separator'
|
|
136
|
+
}, {
|
|
104
137
|
type: 'copy-button',
|
|
105
138
|
items: [{
|
|
106
139
|
state: state,
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.insertMediaSingleNode = exports.insertMediaAsMediaSingle = exports.createMediaSingleNode = void 0;
|
|
7
|
+
exports.insertMediaSingleNode = exports.insertMediaAsMediaSingle = exports.createMediaSingleNode = exports.changeFromMediaInlineToMediaSingleNode = void 0;
|
|
8
8
|
exports.isCaptionNode = isCaptionNode;
|
|
9
9
|
exports.isVideo = exports.isMediaSingle = void 0;
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -86,6 +86,13 @@ var insertMediaAsMediaSingle = exports.insertMediaAsMediaSingle = function inser
|
|
|
86
86
|
};
|
|
87
87
|
return insertNodesWithOptionalParagraph(nodes, analyticsAttributes, editorAnalyticsAPI)(state, dispatch);
|
|
88
88
|
};
|
|
89
|
+
var getFileExtension = function getFileExtension(fileName) {
|
|
90
|
+
if (fileName) {
|
|
91
|
+
var extensionIdx = fileName.lastIndexOf('.');
|
|
92
|
+
return extensionIdx >= 0 ? fileName.substring(extensionIdx + 1) : undefined;
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
};
|
|
89
96
|
var insertMediaSingleNode = exports.insertMediaSingleNode = function insertMediaSingleNode(view, mediaState, inputMethod, collection, alignLeftOnInsert, newInsertionBehaviour, widthPluginState, editorAnalyticsAPI) {
|
|
90
97
|
var _state$selection$$fro;
|
|
91
98
|
if (collection === undefined) {
|
|
@@ -132,6 +139,46 @@ var insertMediaSingleNode = exports.insertMediaSingleNode = function insertMedia
|
|
|
132
139
|
}
|
|
133
140
|
return true;
|
|
134
141
|
};
|
|
142
|
+
var changeFromMediaInlineToMediaSingleNode = exports.changeFromMediaInlineToMediaSingleNode = function changeFromMediaInlineToMediaSingleNode(view, fromNode, widthPluginState, editorAnalyticsAPI) {
|
|
143
|
+
var _state$selection$$fro2;
|
|
144
|
+
var state = view.state,
|
|
145
|
+
dispatch = view.dispatch;
|
|
146
|
+
var mediaInline = state.schema.nodes.mediaInline;
|
|
147
|
+
if (fromNode.type !== mediaInline) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
var grandParentNodeType = (_state$selection$$fro2 = state.selection.$from.node(-1)) === null || _state$selection$$fro2 === void 0 ? void 0 : _state$selection$$fro2.type;
|
|
151
|
+
var parentNodeType = state.selection.$from.parent.type;
|
|
152
|
+
|
|
153
|
+
// add undefined as fallback as we don't want media single width to have upper limit as 0
|
|
154
|
+
// if widthPluginState.width is 0, default 760 will be used
|
|
155
|
+
var contentWidth = (0, _mediaSingle.getMaxWidthForNestedNodeNext)(view, state.selection.$from.pos, true) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.lineLength) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.width) || undefined;
|
|
156
|
+
var node = replaceWithMediaSingleNode(state.schema, contentWidth, _mediaSingle.MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH)(fromNode);
|
|
157
|
+
var fileExtension = getFileExtension(fromNode.attrs.__fileName);
|
|
158
|
+
// should split if media is valid content for the grandparent of the selected node
|
|
159
|
+
// and the parent node is a paragraph
|
|
160
|
+
if ((0, _insert.shouldSplitSelectedNodeOnNodeInsertion)({
|
|
161
|
+
parentNodeType: parentNodeType,
|
|
162
|
+
grandParentNodeType: grandParentNodeType,
|
|
163
|
+
content: node
|
|
164
|
+
})) {
|
|
165
|
+
return insertNodesWithOptionalParagraph([node], {
|
|
166
|
+
fileExtension: fileExtension
|
|
167
|
+
}, editorAnalyticsAPI)(state, dispatch);
|
|
168
|
+
} else {
|
|
169
|
+
var nodePos = state.tr.doc.resolve(state.selection.from).end();
|
|
170
|
+
var tr = null;
|
|
171
|
+
tr = (0, _utils2.removeSelectedNode)(state.tr);
|
|
172
|
+
tr = (0, _insert.safeInsert)(node, nodePos)(tr);
|
|
173
|
+
if (!tr) {
|
|
174
|
+
var content = shouldAddParagraph(view.state) ? _model.Fragment.fromArray([node, state.schema.nodes.paragraph.create()]) : node;
|
|
175
|
+
tr = (0, _utils2.safeInsert)(content, undefined, true)(state.tr);
|
|
176
|
+
}
|
|
177
|
+
// TODO: add analytics specifically for change mediaInline to mediaSingle later
|
|
178
|
+
dispatch(tr);
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
};
|
|
135
182
|
var createMediaSingleNode = exports.createMediaSingleNode = function createMediaSingleNode(schema, collection, maxWidth, minWidth, alignLeftOnInsert) {
|
|
136
183
|
return function (mediaState) {
|
|
137
184
|
var id = mediaState.id,
|
|
@@ -172,6 +219,22 @@ var createMediaSingleNode = exports.createMediaSingleNode = function createMedia
|
|
|
172
219
|
return mediaSingle.createChecked(extendedMediaSingleAttrs, mediaNode);
|
|
173
220
|
};
|
|
174
221
|
};
|
|
222
|
+
var replaceWithMediaSingleNode = function replaceWithMediaSingleNode(schema, maxWidth, minWidth) {
|
|
223
|
+
return function (mediaNode) {
|
|
224
|
+
var width = mediaNode.attrs.width;
|
|
225
|
+
var _schema$nodes2 = schema.nodes,
|
|
226
|
+
media = _schema$nodes2.media,
|
|
227
|
+
mediaSingle = _schema$nodes2.mediaSingle;
|
|
228
|
+
var copiedMediaNode = media.create(_objectSpread(_objectSpread({}, mediaNode.attrs), {}, {
|
|
229
|
+
type: 'file'
|
|
230
|
+
}), mediaNode.content, mediaNode.marks);
|
|
231
|
+
var extendedMediaSingleAttrs = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.extended-resize-experience') ? {
|
|
232
|
+
width: (0, _mediaSingle.getMediaSingleInitialWidth)(width, maxWidth, minWidth),
|
|
233
|
+
widthType: 'pixel'
|
|
234
|
+
} : {};
|
|
235
|
+
return mediaSingle.createChecked(extendedMediaSingleAttrs, copiedMediaNode);
|
|
236
|
+
};
|
|
237
|
+
};
|
|
175
238
|
function isCaptionNode(editorView) {
|
|
176
239
|
var $from = editorView.state.selection.$from;
|
|
177
240
|
var immediateWrapperParentNode = editorView.state.doc.nodeAt($from.before(Math.max($from.depth, 1)));
|
|
@@ -4,6 +4,7 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
4
4
|
import { isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
5
5
|
import { getMediaInputResizeAnalyticsEvent } from '../utils/analytics';
|
|
6
6
|
import { currentMediaNodeWithPos } from '../utils/current-media-node';
|
|
7
|
+
import { changeFromMediaInlineToMediaSingleNode } from '../utils/media-single';
|
|
7
8
|
import { getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
8
9
|
export const DEFAULT_BORDER_COLOR = '#091e4224';
|
|
9
10
|
export const DEFAULT_BORDER_SIZE = 2;
|
|
@@ -82,6 +83,19 @@ export const changeMediaCardToInline = editorAnalyticsAPI => (state, dispatch) =
|
|
|
82
83
|
}
|
|
83
84
|
return true;
|
|
84
85
|
};
|
|
86
|
+
export const changeMediaInlineToMediaSingle = (editorAnalyticsAPI, widthPluginState) => (state, dispatch, view) => {
|
|
87
|
+
const {
|
|
88
|
+
mediaInline
|
|
89
|
+
} = state.schema.nodes;
|
|
90
|
+
const selectedNode = state.selection instanceof NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
|
|
91
|
+
if (!selectedNode) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (view) {
|
|
95
|
+
return changeFromMediaInlineToMediaSingleNode(view, selectedNode, widthPluginState, editorAnalyticsAPI);
|
|
96
|
+
}
|
|
97
|
+
return true;
|
|
98
|
+
};
|
|
85
99
|
export const removeInlineCard = (state, dispatch) => {
|
|
86
100
|
if (isNodeSelection(state.selection)) {
|
|
87
101
|
if (dispatch) {
|
|
@@ -477,13 +477,12 @@ export const floatingToolbar = (state, intl, options = {}, pluginInjectionApi) =
|
|
|
477
477
|
};
|
|
478
478
|
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a7 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a7 === void 0 ? void 0 : _pluginInjectionApi$a7.actions);
|
|
479
479
|
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
480
|
-
var _pluginInjectionApi$a8;
|
|
481
480
|
baseToolbar.getDomRef = () => {
|
|
482
481
|
var _mediaPluginState$ele2;
|
|
483
482
|
const element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(`.${MediaInlineNodeSelector}`);
|
|
484
483
|
return element || mediaPluginState.element;
|
|
485
484
|
};
|
|
486
|
-
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi
|
|
485
|
+
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
487
486
|
} else {
|
|
488
487
|
baseToolbar.getDomRef = () => {
|
|
489
488
|
var _mediaPluginState$ele3;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { IconEmbed, IconInline } from '@atlaskit/editor-common/card';
|
|
2
3
|
import { shouldShowInlineImage } from '@atlaskit/editor-common/media-inline';
|
|
3
|
-
import commonMessages, { cardMessages } from '@atlaskit/editor-common/messages';
|
|
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';
|
|
8
|
-
import { changeInlineToMediaCard, removeInlineCard } from './commands';
|
|
9
|
+
import { changeInlineToMediaCard, changeMediaInlineToMediaSingle, removeInlineCard } from './commands';
|
|
9
10
|
import { FilePreviewItem } from './filePreviewItem';
|
|
10
11
|
import { downloadMedia } from './utils';
|
|
11
|
-
export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration,
|
|
12
|
+
export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) => {
|
|
13
|
+
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
14
|
+
const editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
15
|
+
const widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
12
16
|
const {
|
|
13
17
|
mediaInline
|
|
14
18
|
} = state.schema.nodes;
|
|
15
19
|
const mediaType = state.selection instanceof NodeSelection && state.selection.node.attrs.type;
|
|
16
20
|
if (shouldShowInlineImage(mediaType)) {
|
|
17
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI);
|
|
21
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
18
22
|
}
|
|
19
23
|
const items = [{
|
|
20
24
|
id: 'editor.media.view.switcher',
|
|
@@ -87,14 +91,39 @@ export const generateMediaInlineFloatingToolbar = (state, intl, mediaPluginState
|
|
|
87
91
|
}];
|
|
88
92
|
return items;
|
|
89
93
|
};
|
|
90
|
-
export const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI) => {
|
|
94
|
+
export const getMediaInlineImageToolbar = (state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) => {
|
|
91
95
|
const {
|
|
92
96
|
mediaInline
|
|
93
97
|
} = state.schema.nodes;
|
|
98
|
+
const mediaInlineImageTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
99
|
+
const mediaSingleTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
94
100
|
// if type is image, return inline image floating toolbar items
|
|
95
101
|
const inlineImageItems = [
|
|
96
102
|
// TODO: border marks, media single switcher, link, alt text, etc
|
|
97
103
|
{
|
|
104
|
+
id: 'editor.media.convert.mediainline',
|
|
105
|
+
type: 'button',
|
|
106
|
+
title: mediaInlineImageTitle,
|
|
107
|
+
icon: () => /*#__PURE__*/React.createElement(IconInline, {
|
|
108
|
+
size: "medium",
|
|
109
|
+
label: mediaInlineImageTitle
|
|
110
|
+
}),
|
|
111
|
+
onClick: () => {
|
|
112
|
+
return true;
|
|
113
|
+
},
|
|
114
|
+
selected: true
|
|
115
|
+
}, {
|
|
116
|
+
id: 'editor.media.convert.mediasingle',
|
|
117
|
+
type: 'button',
|
|
118
|
+
title: mediaSingleTitle,
|
|
119
|
+
icon: () => /*#__PURE__*/React.createElement(IconEmbed, {
|
|
120
|
+
size: "medium",
|
|
121
|
+
label: mediaSingleTitle
|
|
122
|
+
}),
|
|
123
|
+
onClick: changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState)
|
|
124
|
+
}, {
|
|
125
|
+
type: 'separator'
|
|
126
|
+
}, {
|
|
98
127
|
type: 'copy-button',
|
|
99
128
|
items: [{
|
|
100
129
|
state,
|
|
@@ -5,7 +5,7 @@ import { getMaxWidthForNestedNodeNext, getMediaSingleInitialWidth, MEDIA_SINGLE_
|
|
|
5
5
|
import { atTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
|
|
6
6
|
import { checkNodeDown, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
7
7
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
8
|
-
import { safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
8
|
+
import { safeInsert as pmSafeInsert, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
9
9
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { copyOptionalAttrsFromMediaState } from '../utils/media-common';
|
|
11
11
|
import { isImage } from './is-type';
|
|
@@ -77,6 +77,13 @@ export const insertMediaAsMediaSingle = (view, node, inputMethod, editorAnalytic
|
|
|
77
77
|
};
|
|
78
78
|
return insertNodesWithOptionalParagraph(nodes, analyticsAttributes, editorAnalyticsAPI)(state, dispatch);
|
|
79
79
|
};
|
|
80
|
+
const getFileExtension = fileName => {
|
|
81
|
+
if (fileName) {
|
|
82
|
+
const extensionIdx = fileName.lastIndexOf('.');
|
|
83
|
+
return extensionIdx >= 0 ? fileName.substring(extensionIdx + 1) : undefined;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
80
87
|
export const insertMediaSingleNode = (view, mediaState, inputMethod, collection, alignLeftOnInsert, newInsertionBehaviour, widthPluginState, editorAnalyticsAPI) => {
|
|
81
88
|
var _state$selection$$fro;
|
|
82
89
|
if (collection === undefined) {
|
|
@@ -125,6 +132,50 @@ export const insertMediaSingleNode = (view, mediaState, inputMethod, collection,
|
|
|
125
132
|
}
|
|
126
133
|
return true;
|
|
127
134
|
};
|
|
135
|
+
export const changeFromMediaInlineToMediaSingleNode = (view, fromNode, widthPluginState, editorAnalyticsAPI) => {
|
|
136
|
+
var _state$selection$$fro2;
|
|
137
|
+
const {
|
|
138
|
+
state,
|
|
139
|
+
dispatch
|
|
140
|
+
} = view;
|
|
141
|
+
const {
|
|
142
|
+
mediaInline
|
|
143
|
+
} = state.schema.nodes;
|
|
144
|
+
if (fromNode.type !== mediaInline) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
const grandParentNodeType = (_state$selection$$fro2 = state.selection.$from.node(-1)) === null || _state$selection$$fro2 === void 0 ? void 0 : _state$selection$$fro2.type;
|
|
148
|
+
const parentNodeType = state.selection.$from.parent.type;
|
|
149
|
+
|
|
150
|
+
// add undefined as fallback as we don't want media single width to have upper limit as 0
|
|
151
|
+
// if widthPluginState.width is 0, default 760 will be used
|
|
152
|
+
const contentWidth = getMaxWidthForNestedNodeNext(view, state.selection.$from.pos, true) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.lineLength) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.width) || undefined;
|
|
153
|
+
const node = replaceWithMediaSingleNode(state.schema, contentWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH)(fromNode);
|
|
154
|
+
const fileExtension = getFileExtension(fromNode.attrs.__fileName);
|
|
155
|
+
// should split if media is valid content for the grandparent of the selected node
|
|
156
|
+
// and the parent node is a paragraph
|
|
157
|
+
if (shouldSplitSelectedNodeOnNodeInsertion({
|
|
158
|
+
parentNodeType,
|
|
159
|
+
grandParentNodeType,
|
|
160
|
+
content: node
|
|
161
|
+
})) {
|
|
162
|
+
return insertNodesWithOptionalParagraph([node], {
|
|
163
|
+
fileExtension
|
|
164
|
+
}, editorAnalyticsAPI)(state, dispatch);
|
|
165
|
+
} else {
|
|
166
|
+
const nodePos = state.tr.doc.resolve(state.selection.from).end();
|
|
167
|
+
let tr = null;
|
|
168
|
+
tr = removeSelectedNode(state.tr);
|
|
169
|
+
tr = safeInsert(node, nodePos)(tr);
|
|
170
|
+
if (!tr) {
|
|
171
|
+
const content = shouldAddParagraph(view.state) ? Fragment.fromArray([node, state.schema.nodes.paragraph.create()]) : node;
|
|
172
|
+
tr = pmSafeInsert(content, undefined, true)(state.tr);
|
|
173
|
+
}
|
|
174
|
+
// TODO: add analytics specifically for change mediaInline to mediaSingle later
|
|
175
|
+
dispatch(tr);
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
};
|
|
128
179
|
export const createMediaSingleNode = (schema, collection, maxWidth, minWidth, alignLeftOnInsert) => mediaState => {
|
|
129
180
|
const {
|
|
130
181
|
id,
|
|
@@ -168,6 +219,24 @@ export const createMediaSingleNode = (schema, collection, maxWidth, minWidth, al
|
|
|
168
219
|
copyOptionalAttrsFromMediaState(mediaState, mediaNode);
|
|
169
220
|
return mediaSingle.createChecked(extendedMediaSingleAttrs, mediaNode);
|
|
170
221
|
};
|
|
222
|
+
const replaceWithMediaSingleNode = (schema, maxWidth, minWidth) => mediaNode => {
|
|
223
|
+
const {
|
|
224
|
+
width
|
|
225
|
+
} = mediaNode.attrs;
|
|
226
|
+
const {
|
|
227
|
+
media,
|
|
228
|
+
mediaSingle
|
|
229
|
+
} = schema.nodes;
|
|
230
|
+
const copiedMediaNode = media.create({
|
|
231
|
+
...mediaNode.attrs,
|
|
232
|
+
type: 'file'
|
|
233
|
+
}, mediaNode.content, mediaNode.marks);
|
|
234
|
+
const extendedMediaSingleAttrs = getBooleanFF('platform.editor.media.extended-resize-experience') ? {
|
|
235
|
+
width: getMediaSingleInitialWidth(width, maxWidth, minWidth),
|
|
236
|
+
widthType: 'pixel'
|
|
237
|
+
} : {};
|
|
238
|
+
return mediaSingle.createChecked(extendedMediaSingleAttrs, copiedMediaNode);
|
|
239
|
+
};
|
|
171
240
|
export function isCaptionNode(editorView) {
|
|
172
241
|
const {
|
|
173
242
|
$from
|
|
@@ -7,6 +7,7 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
|
7
7
|
import { isNodeSelection, removeSelectedNode, safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
8
8
|
import { getMediaInputResizeAnalyticsEvent } from '../utils/analytics';
|
|
9
9
|
import { currentMediaNodeWithPos } from '../utils/current-media-node';
|
|
10
|
+
import { changeFromMediaInlineToMediaSingleNode } from '../utils/media-single';
|
|
10
11
|
import { getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
11
12
|
export var DEFAULT_BORDER_COLOR = '#091e4224';
|
|
12
13
|
export var DEFAULT_BORDER_SIZE = 2;
|
|
@@ -86,6 +87,19 @@ export var changeMediaCardToInline = function changeMediaCardToInline(editorAnal
|
|
|
86
87
|
return true;
|
|
87
88
|
};
|
|
88
89
|
};
|
|
90
|
+
export var changeMediaInlineToMediaSingle = function changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState) {
|
|
91
|
+
return function (state, dispatch, view) {
|
|
92
|
+
var mediaInline = state.schema.nodes.mediaInline;
|
|
93
|
+
var selectedNode = state.selection instanceof NodeSelection && state.selection.node.type === mediaInline && state.selection.node;
|
|
94
|
+
if (!selectedNode) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (view) {
|
|
98
|
+
return changeFromMediaInlineToMediaSingleNode(view, selectedNode, widthPluginState, editorAnalyticsAPI);
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
89
103
|
export var removeInlineCard = function removeInlineCard(state, dispatch) {
|
|
90
104
|
if (isNodeSelection(state.selection)) {
|
|
91
105
|
if (dispatch) {
|
|
@@ -460,13 +460,12 @@ export var floatingToolbar = function floatingToolbar(state, intl) {
|
|
|
460
460
|
};
|
|
461
461
|
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a7 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a7 === void 0 ? void 0 : _pluginInjectionApi$a7.actions);
|
|
462
462
|
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
463
|
-
var _pluginInjectionApi$a8;
|
|
464
463
|
baseToolbar.getDomRef = function () {
|
|
465
464
|
var _mediaPluginState$ele2;
|
|
466
465
|
var element = (_mediaPluginState$ele2 = mediaPluginState.element) === null || _mediaPluginState$ele2 === void 0 ? void 0 : _mediaPluginState$ele2.querySelector(".".concat(MediaInlineNodeSelector));
|
|
467
466
|
return element || mediaPluginState.element;
|
|
468
467
|
};
|
|
469
|
-
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi
|
|
468
|
+
items = generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi);
|
|
470
469
|
} else {
|
|
471
470
|
baseToolbar.getDomRef = function () {
|
|
472
471
|
var _mediaPluginState$ele3;
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { IconEmbed, IconInline } from '@atlaskit/editor-common/card';
|
|
2
3
|
import { shouldShowInlineImage } from '@atlaskit/editor-common/media-inline';
|
|
3
|
-
import commonMessages, { cardMessages } from '@atlaskit/editor-common/messages';
|
|
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';
|
|
8
|
-
import { changeInlineToMediaCard, removeInlineCard } from './commands';
|
|
9
|
+
import { changeInlineToMediaCard, changeMediaInlineToMediaSingle, removeInlineCard } from './commands';
|
|
9
10
|
import { FilePreviewItem } from './filePreviewItem';
|
|
10
11
|
import { downloadMedia } from './utils';
|
|
11
|
-
export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration,
|
|
12
|
+
export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi) {
|
|
13
|
+
var _pluginInjectionApi$a, _pluginInjectionApi$w;
|
|
14
|
+
var editorAnalyticsAPI = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
15
|
+
var widthPluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$w = pluginInjectionApi.width) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.sharedState.currentState();
|
|
12
16
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
13
17
|
var mediaType = state.selection instanceof NodeSelection && state.selection.node.attrs.type;
|
|
14
18
|
if (shouldShowInlineImage(mediaType)) {
|
|
15
|
-
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI);
|
|
19
|
+
return getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState);
|
|
16
20
|
}
|
|
17
21
|
var items = [{
|
|
18
22
|
id: 'editor.media.view.switcher',
|
|
@@ -85,12 +89,41 @@ export var generateMediaInlineFloatingToolbar = function generateMediaInlineFloa
|
|
|
85
89
|
}];
|
|
86
90
|
return items;
|
|
87
91
|
};
|
|
88
|
-
export var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI) {
|
|
92
|
+
export var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl, mediaPluginState, hoverDecoration, editorAnalyticsAPI, widthPluginState) {
|
|
89
93
|
var mediaInline = state.schema.nodes.mediaInline;
|
|
94
|
+
var mediaInlineImageTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaInlineImage);
|
|
95
|
+
var mediaSingleTitle = intl.formatMessage(mediaAndEmbedToolbarMessages.changeToMediaSingle);
|
|
90
96
|
// if type is image, return inline image floating toolbar items
|
|
91
97
|
var inlineImageItems = [
|
|
92
98
|
// TODO: border marks, media single switcher, link, alt text, etc
|
|
93
99
|
{
|
|
100
|
+
id: 'editor.media.convert.mediainline',
|
|
101
|
+
type: 'button',
|
|
102
|
+
title: mediaInlineImageTitle,
|
|
103
|
+
icon: function icon() {
|
|
104
|
+
return /*#__PURE__*/React.createElement(IconInline, {
|
|
105
|
+
size: "medium",
|
|
106
|
+
label: mediaInlineImageTitle
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
onClick: function onClick() {
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
selected: true
|
|
113
|
+
}, {
|
|
114
|
+
id: 'editor.media.convert.mediasingle',
|
|
115
|
+
type: 'button',
|
|
116
|
+
title: mediaSingleTitle,
|
|
117
|
+
icon: function icon() {
|
|
118
|
+
return /*#__PURE__*/React.createElement(IconEmbed, {
|
|
119
|
+
size: "medium",
|
|
120
|
+
label: mediaSingleTitle
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
onClick: changeMediaInlineToMediaSingle(editorAnalyticsAPI, widthPluginState)
|
|
124
|
+
}, {
|
|
125
|
+
type: 'separator'
|
|
126
|
+
}, {
|
|
94
127
|
type: 'copy-button',
|
|
95
128
|
items: [{
|
|
96
129
|
state: state,
|
|
@@ -8,7 +8,7 @@ import { getMaxWidthForNestedNodeNext, getMediaSingleInitialWidth, MEDIA_SINGLE_
|
|
|
8
8
|
import { atTheBeginningOfBlock } from '@atlaskit/editor-common/selection';
|
|
9
9
|
import { checkNodeDown, isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
10
10
|
import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
11
|
-
import { safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
11
|
+
import { safeInsert as pmSafeInsert, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
12
12
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
13
13
|
import { copyOptionalAttrsFromMediaState } from '../utils/media-common';
|
|
14
14
|
import { isImage } from './is-type';
|
|
@@ -77,6 +77,13 @@ export var insertMediaAsMediaSingle = function insertMediaAsMediaSingle(view, no
|
|
|
77
77
|
};
|
|
78
78
|
return insertNodesWithOptionalParagraph(nodes, analyticsAttributes, editorAnalyticsAPI)(state, dispatch);
|
|
79
79
|
};
|
|
80
|
+
var getFileExtension = function getFileExtension(fileName) {
|
|
81
|
+
if (fileName) {
|
|
82
|
+
var extensionIdx = fileName.lastIndexOf('.');
|
|
83
|
+
return extensionIdx >= 0 ? fileName.substring(extensionIdx + 1) : undefined;
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
};
|
|
80
87
|
export var insertMediaSingleNode = function insertMediaSingleNode(view, mediaState, inputMethod, collection, alignLeftOnInsert, newInsertionBehaviour, widthPluginState, editorAnalyticsAPI) {
|
|
81
88
|
var _state$selection$$fro;
|
|
82
89
|
if (collection === undefined) {
|
|
@@ -123,6 +130,46 @@ export var insertMediaSingleNode = function insertMediaSingleNode(view, mediaSta
|
|
|
123
130
|
}
|
|
124
131
|
return true;
|
|
125
132
|
};
|
|
133
|
+
export var changeFromMediaInlineToMediaSingleNode = function changeFromMediaInlineToMediaSingleNode(view, fromNode, widthPluginState, editorAnalyticsAPI) {
|
|
134
|
+
var _state$selection$$fro2;
|
|
135
|
+
var state = view.state,
|
|
136
|
+
dispatch = view.dispatch;
|
|
137
|
+
var mediaInline = state.schema.nodes.mediaInline;
|
|
138
|
+
if (fromNode.type !== mediaInline) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
var grandParentNodeType = (_state$selection$$fro2 = state.selection.$from.node(-1)) === null || _state$selection$$fro2 === void 0 ? void 0 : _state$selection$$fro2.type;
|
|
142
|
+
var parentNodeType = state.selection.$from.parent.type;
|
|
143
|
+
|
|
144
|
+
// add undefined as fallback as we don't want media single width to have upper limit as 0
|
|
145
|
+
// if widthPluginState.width is 0, default 760 will be used
|
|
146
|
+
var contentWidth = getMaxWidthForNestedNodeNext(view, state.selection.$from.pos, true) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.lineLength) || (widthPluginState === null || widthPluginState === void 0 ? void 0 : widthPluginState.width) || undefined;
|
|
147
|
+
var node = replaceWithMediaSingleNode(state.schema, contentWidth, MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH)(fromNode);
|
|
148
|
+
var fileExtension = getFileExtension(fromNode.attrs.__fileName);
|
|
149
|
+
// should split if media is valid content for the grandparent of the selected node
|
|
150
|
+
// and the parent node is a paragraph
|
|
151
|
+
if (shouldSplitSelectedNodeOnNodeInsertion({
|
|
152
|
+
parentNodeType: parentNodeType,
|
|
153
|
+
grandParentNodeType: grandParentNodeType,
|
|
154
|
+
content: node
|
|
155
|
+
})) {
|
|
156
|
+
return insertNodesWithOptionalParagraph([node], {
|
|
157
|
+
fileExtension: fileExtension
|
|
158
|
+
}, editorAnalyticsAPI)(state, dispatch);
|
|
159
|
+
} else {
|
|
160
|
+
var nodePos = state.tr.doc.resolve(state.selection.from).end();
|
|
161
|
+
var tr = null;
|
|
162
|
+
tr = removeSelectedNode(state.tr);
|
|
163
|
+
tr = safeInsert(node, nodePos)(tr);
|
|
164
|
+
if (!tr) {
|
|
165
|
+
var content = shouldAddParagraph(view.state) ? Fragment.fromArray([node, state.schema.nodes.paragraph.create()]) : node;
|
|
166
|
+
tr = pmSafeInsert(content, undefined, true)(state.tr);
|
|
167
|
+
}
|
|
168
|
+
// TODO: add analytics specifically for change mediaInline to mediaSingle later
|
|
169
|
+
dispatch(tr);
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
};
|
|
126
173
|
export var createMediaSingleNode = function createMediaSingleNode(schema, collection, maxWidth, minWidth, alignLeftOnInsert) {
|
|
127
174
|
return function (mediaState) {
|
|
128
175
|
var id = mediaState.id,
|
|
@@ -163,6 +210,22 @@ export var createMediaSingleNode = function createMediaSingleNode(schema, collec
|
|
|
163
210
|
return mediaSingle.createChecked(extendedMediaSingleAttrs, mediaNode);
|
|
164
211
|
};
|
|
165
212
|
};
|
|
213
|
+
var replaceWithMediaSingleNode = function replaceWithMediaSingleNode(schema, maxWidth, minWidth) {
|
|
214
|
+
return function (mediaNode) {
|
|
215
|
+
var width = mediaNode.attrs.width;
|
|
216
|
+
var _schema$nodes2 = schema.nodes,
|
|
217
|
+
media = _schema$nodes2.media,
|
|
218
|
+
mediaSingle = _schema$nodes2.mediaSingle;
|
|
219
|
+
var copiedMediaNode = media.create(_objectSpread(_objectSpread({}, mediaNode.attrs), {}, {
|
|
220
|
+
type: 'file'
|
|
221
|
+
}), mediaNode.content, mediaNode.marks);
|
|
222
|
+
var extendedMediaSingleAttrs = getBooleanFF('platform.editor.media.extended-resize-experience') ? {
|
|
223
|
+
width: getMediaSingleInitialWidth(width, maxWidth, minWidth),
|
|
224
|
+
widthType: 'pixel'
|
|
225
|
+
} : {};
|
|
226
|
+
return mediaSingle.createChecked(extendedMediaSingleAttrs, copiedMediaNode);
|
|
227
|
+
};
|
|
228
|
+
};
|
|
166
229
|
export function isCaptionNode(editorView) {
|
|
167
230
|
var $from = editorView.state.selection.$from;
|
|
168
231
|
var immediateWrapperParentNode = editorView.state.doc.nodeAt($from.before(Math.max($from.depth, 1)));
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { BorderMarkAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
4
5
|
import type { EventInput } from '../pm-plugins/types';
|
|
5
6
|
import type { PixelEntryValidation } from '../ui/PixelEntry/types';
|
|
6
7
|
export declare const DEFAULT_BORDER_COLOR = "#091e4224";
|
|
7
8
|
export declare const DEFAULT_BORDER_SIZE = 2;
|
|
8
9
|
export declare const changeInlineToMediaCard: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
9
10
|
export declare const changeMediaCardToInline: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
11
|
+
export declare const changeMediaInlineToMediaSingle: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined) => Command;
|
|
10
12
|
export declare const removeInlineCard: Command;
|
|
11
13
|
export declare const toggleBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
12
14
|
export declare const setBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (attrs: Partial<BorderMarkAttributes>) => Command;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { Command, ExtractInjectionAPI, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { HoverDecorationHandler } from '@atlaskit/editor-plugin-decorations';
|
|
5
|
+
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
5
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import type { MediaNextEditorPluginType } from '../next-plugin-type';
|
|
6
8
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
7
|
-
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined,
|
|
8
|
-
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => FloatingToolbarItem<Command>[];
|
|
9
|
+
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined) => FloatingToolbarItem<Command>[];
|
|
10
|
+
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined) => FloatingToolbarItem<Command>[];
|
|
@@ -15,6 +15,7 @@ export declare const isMediaSingle: (schema: Schema, fileMimeType?: string) => b
|
|
|
15
15
|
export type InsertMediaAsMediaSingle = (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia) => boolean;
|
|
16
16
|
export declare const insertMediaAsMediaSingle: (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => boolean;
|
|
17
17
|
export declare const insertMediaSingleNode: (view: EditorView, mediaState: MediaState, inputMethod?: InputMethodInsertMedia, collection?: string, alignLeftOnInsert?: boolean, newInsertionBehaviour?: boolean, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined) => boolean;
|
|
18
|
+
export declare const changeFromMediaInlineToMediaSingleNode: (view: EditorView, fromNode: PMNode, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined) => boolean;
|
|
18
19
|
export declare const createMediaSingleNode: (schema: Schema, collection: string, maxWidth?: number, minWidth?: number, alignLeftOnInsert?: boolean) => (mediaState: MediaSingleState) => PMNode;
|
|
19
20
|
export declare function isCaptionNode(editorView: EditorView): boolean;
|
|
20
21
|
export declare const isVideo: import("memoize-one").MemoizedFn<(fileType?: string) => boolean>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { BorderMarkAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import type { Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
4
5
|
import type { EventInput } from '../pm-plugins/types';
|
|
5
6
|
import type { PixelEntryValidation } from '../ui/PixelEntry/types';
|
|
6
7
|
export declare const DEFAULT_BORDER_COLOR = "#091e4224";
|
|
7
8
|
export declare const DEFAULT_BORDER_SIZE = 2;
|
|
8
9
|
export declare const changeInlineToMediaCard: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
9
10
|
export declare const changeMediaCardToInline: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
11
|
+
export declare const changeMediaInlineToMediaSingle: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined) => Command;
|
|
10
12
|
export declare const removeInlineCard: Command;
|
|
11
13
|
export declare const toggleBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
12
14
|
export declare const setBorderMark: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (attrs: Partial<BorderMarkAttributes>) => Command;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { IntlShape } from 'react-intl-next';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { Command, ExtractInjectionAPI, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { HoverDecorationHandler } from '@atlaskit/editor-plugin-decorations';
|
|
5
|
+
import type { WidthPluginState } from '@atlaskit/editor-plugin-width';
|
|
5
6
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import type { MediaNextEditorPluginType } from '../next-plugin-type';
|
|
6
8
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
7
|
-
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined,
|
|
8
|
-
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => FloatingToolbarItem<Command>[];
|
|
9
|
+
export declare const generateMediaInlineFloatingToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, pluginInjectionApi: ExtractInjectionAPI<MediaNextEditorPluginType> | undefined) => FloatingToolbarItem<Command>[];
|
|
10
|
+
export declare const getMediaInlineImageToolbar: (state: EditorState, intl: IntlShape, mediaPluginState: MediaPluginState, hoverDecoration: HoverDecorationHandler | undefined, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, widthPluginState: WidthPluginState | undefined) => FloatingToolbarItem<Command>[];
|
|
@@ -15,6 +15,7 @@ export declare const isMediaSingle: (schema: Schema, fileMimeType?: string) => b
|
|
|
15
15
|
export type InsertMediaAsMediaSingle = (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia) => boolean;
|
|
16
16
|
export declare const insertMediaAsMediaSingle: (view: EditorView, node: PMNode, inputMethod: InputMethodInsertMedia, editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => boolean;
|
|
17
17
|
export declare const insertMediaSingleNode: (view: EditorView, mediaState: MediaState, inputMethod?: InputMethodInsertMedia, collection?: string, alignLeftOnInsert?: boolean, newInsertionBehaviour?: boolean, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined) => boolean;
|
|
18
|
+
export declare const changeFromMediaInlineToMediaSingleNode: (view: EditorView, fromNode: PMNode, widthPluginState?: WidthPluginState | undefined, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined) => boolean;
|
|
18
19
|
export declare const createMediaSingleNode: (schema: Schema, collection: string, maxWidth?: number, minWidth?: number, alignLeftOnInsert?: boolean) => (mediaState: MediaSingleState) => PMNode;
|
|
19
20
|
export declare function isCaptionNode(editorView: EditorView): boolean;
|
|
20
21
|
export declare const isVideo: import("memoize-one").MemoizedFn<(fileType?: string) => boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@atlaskit/analytics-namespaced-context": "^6.7.0",
|
|
37
37
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
38
38
|
"@atlaskit/button": "^16.18.0",
|
|
39
|
-
"@atlaskit/editor-common": "^76.
|
|
39
|
+
"@atlaskit/editor-common": "^76.26.0",
|
|
40
40
|
"@atlaskit/editor-palette": "1.5.2",
|
|
41
|
-
"@atlaskit/editor-plugin-analytics": "^0.
|
|
41
|
+
"@atlaskit/editor-plugin-analytics": "^0.4.0",
|
|
42
42
|
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|
|
43
43
|
"@atlaskit/editor-plugin-editor-disabled": "^0.2.0",
|
|
44
44
|
"@atlaskit/editor-plugin-feature-flags": "^1.0.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@atlaskit/editor-tables": "^2.3.0",
|
|
54
54
|
"@atlaskit/form": "^9.0.0",
|
|
55
55
|
"@atlaskit/icon": "^22.0.0",
|
|
56
|
-
"@atlaskit/media-card": "^77.
|
|
56
|
+
"@atlaskit/media-card": "^77.5.0",
|
|
57
57
|
"@atlaskit/media-client": "^25.1.0",
|
|
58
58
|
"@atlaskit/media-client-react": "^2.0.0",
|
|
59
59
|
"@atlaskit/media-common": "^11.0.0",
|