@atlaskit/editor-plugin-media 0.4.4 → 0.4.6
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 +32 -0
- package/dist/cjs/toolbar/index.js +34 -6
- package/dist/cjs/toolbar/layout-group.js +44 -0
- package/dist/cjs/toolbar/utils.js +13 -6
- package/dist/es2019/toolbar/index.js +36 -8
- package/dist/es2019/toolbar/layout-group.js +38 -0
- package/dist/es2019/toolbar/utils.js +5 -0
- package/dist/esm/toolbar/index.js +36 -8
- package/dist/esm/toolbar/layout-group.js +37 -0
- package/dist/esm/toolbar/utils.js +7 -0
- package/dist/types/next-plugin-type.d.ts +1 -1
- package/dist/types/toolbar/layout-group.d.ts +10 -0
- package/dist/types/toolbar/utils.d.ts +3 -0
- package/dist/types-ts4.5/next-plugin-type.d.ts +1 -1
- package/dist/types-ts4.5/toolbar/layout-group.d.ts +10 -0
- package/dist/types-ts4.5/toolbar/utils.d.ts +3 -0
- package/package.json +6 -3
- package/report.api.md +1 -1
- package/tmp/api-report-tmp.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 0.4.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#43825](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43825) [`b21c6c1caa8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b21c6c1caa8) - [ux] [ED-20885] Group layout buttons in mediaSingle floating toolbar into a dropdown
|
|
8
|
+
|
|
9
|
+
## 0.4.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#43646](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43646) [`d43f8e9402f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d43f8e9402f) - Make feature flags plugin optional in all plugins including:
|
|
14
|
+
|
|
15
|
+
- analytics
|
|
16
|
+
- base
|
|
17
|
+
- card
|
|
18
|
+
- code-block
|
|
19
|
+
- expand
|
|
20
|
+
- extension
|
|
21
|
+
- floating-toolbar
|
|
22
|
+
- hyperlink
|
|
23
|
+
- insert-block
|
|
24
|
+
- layout
|
|
25
|
+
- layout
|
|
26
|
+
- list
|
|
27
|
+
- media
|
|
28
|
+
- paste
|
|
29
|
+
- rule
|
|
30
|
+
- table
|
|
31
|
+
- tasks-and-decisions
|
|
32
|
+
|
|
33
|
+
We already treat it as optional in the plugins, so this is just ensuring that the plugin is not mandatory to be added to the preset.
|
|
34
|
+
|
|
3
35
|
## 0.4.4
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.floatingToolbar = void 0;
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
12
|
var _react = _interopRequireDefault(require("react"));
|
|
12
13
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -34,6 +35,7 @@ var _altText2 = require("./alt-text");
|
|
|
34
35
|
var _commands = require("./commands");
|
|
35
36
|
var _filePreviewItem = require("./filePreviewItem");
|
|
36
37
|
var _imageBorder = require("./imageBorder");
|
|
38
|
+
var _layoutGroup = require("./layout-group");
|
|
37
39
|
var _linking3 = require("./linking");
|
|
38
40
|
var _linkingToolbarAppearance = require("./linking-toolbar-appearance");
|
|
39
41
|
var _utils2 = require("./utils");
|
|
@@ -244,21 +246,47 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
244
246
|
var _pluginInjectionApi$a3;
|
|
245
247
|
var widthPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width;
|
|
246
248
|
var isChangingLayoutDisabled = false;
|
|
249
|
+
var selectedNode = (0, _utils2.getSelectedMediaSingle)(state);
|
|
247
250
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.extended-resize-experience')) {
|
|
248
251
|
var _widthPlugin$sharedSt;
|
|
249
252
|
var contentWidth = widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength;
|
|
250
|
-
var selectedNode = (0, _utils2.getSelectedMediaSingle)(state);
|
|
251
253
|
var selectedNodeMaxWidth = pluginState.currentMaxWidth || contentWidth;
|
|
252
254
|
if (selectedNode && selectedNodeMaxWidth && selectedNode.node.attrs.width >= selectedNodeMaxWidth) {
|
|
253
255
|
isChangingLayoutDisabled = true;
|
|
254
256
|
}
|
|
255
257
|
}
|
|
256
258
|
var layoutButtons = (0, _card.buildLayoutButtons)(state, intl, state.schema.nodes.mediaSingle, widthPlugin, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.actions, allowResizing, allowResizingInTables, true, true, isChangingLayoutDisabled);
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.grouped-layout') && selectedNode) {
|
|
260
|
+
var selectedLayoutIcon = (0, _utils2.getSelectedLayoutIcon)([].concat((0, _toConsumableArray2.default)(_card.alignmentIcons), (0, _toConsumableArray2.default)(_card.wrappingIcons)), selectedNode.node);
|
|
261
|
+
if (selectedLayoutIcon && layoutButtons.length) {
|
|
262
|
+
var _options = {
|
|
263
|
+
render: function render(props) {
|
|
264
|
+
return /*#__PURE__*/_react.default.createElement(_layoutGroup.LayoutGroup, (0, _extends2.default)({
|
|
265
|
+
layoutButtons: layoutButtons
|
|
266
|
+
}, props));
|
|
267
|
+
},
|
|
268
|
+
width: 156,
|
|
269
|
+
height: 32
|
|
270
|
+
};
|
|
271
|
+
var trigger = {
|
|
272
|
+
id: 'media-single-layout',
|
|
273
|
+
testId: 'media-single-layout-dropdown-trigger',
|
|
274
|
+
type: 'dropdown',
|
|
275
|
+
options: _options,
|
|
276
|
+
title: intl.formatMessage(_card.layoutToMessages[selectedLayoutIcon.value]),
|
|
277
|
+
icon: selectedLayoutIcon.icon
|
|
278
|
+
};
|
|
279
|
+
toolbarButtons = [].concat((0, _toConsumableArray2.default)(toolbarButtons), [trigger, {
|
|
280
|
+
type: 'separator'
|
|
281
|
+
}]);
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
toolbarButtons = [].concat((0, _toConsumableArray2.default)(toolbarButtons), (0, _toConsumableArray2.default)(layoutButtons));
|
|
285
|
+
if (layoutButtons.length) {
|
|
286
|
+
toolbarButtons.push({
|
|
287
|
+
type: 'separator'
|
|
288
|
+
});
|
|
289
|
+
}
|
|
262
290
|
}
|
|
263
291
|
|
|
264
292
|
// Pixel Entry Toolbar Support
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LayoutGroup = void 0;
|
|
7
|
+
var _react = require("@emotion/react");
|
|
8
|
+
var _button = require("@atlaskit/button");
|
|
9
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
|
|
12
|
+
var containerStyles = (0, _react.css)({
|
|
13
|
+
marginLeft: "var(--ds-space-100, 8px)"
|
|
14
|
+
});
|
|
15
|
+
var LayoutGroup = exports.LayoutGroup = function LayoutGroup(_ref) {
|
|
16
|
+
var layoutButtons = _ref.layoutButtons,
|
|
17
|
+
dispatchCommand = _ref.dispatchCommand,
|
|
18
|
+
hide = _ref.hide;
|
|
19
|
+
return (0, _react.jsx)("div", {
|
|
20
|
+
css: containerStyles
|
|
21
|
+
}, (0, _react.jsx)(_button.ButtonGroup, null, layoutButtons.map(function (item, idx) {
|
|
22
|
+
switch (item.type) {
|
|
23
|
+
case 'separator':
|
|
24
|
+
return (0, _react.jsx)(_ui.FloatingToolbarSeparator, {
|
|
25
|
+
key: idx
|
|
26
|
+
});
|
|
27
|
+
case 'button':
|
|
28
|
+
var ButtonIcon = item.icon;
|
|
29
|
+
return (0, _react.jsx)(_ui.FloatingToolbarButton, {
|
|
30
|
+
key: idx,
|
|
31
|
+
icon: item.icon ? (0, _react.jsx)(ButtonIcon, {
|
|
32
|
+
label: item.title
|
|
33
|
+
}) : undefined,
|
|
34
|
+
title: item.title,
|
|
35
|
+
selected: item.selected,
|
|
36
|
+
disabled: item.disabled,
|
|
37
|
+
onClick: function onClick() {
|
|
38
|
+
dispatchCommand(item.onClick);
|
|
39
|
+
hide();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
})));
|
|
44
|
+
};
|
|
@@ -4,12 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.removeMediaGroupNode = exports.getSelectedMediaSingle = exports.getSelectedMediaContainerNodeAttrs = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.calcNewLayout = void 0;
|
|
7
|
+
exports.removeMediaGroupNode = exports.getSelectedMediaSingle = exports.getSelectedMediaContainerNodeAttrs = exports.getSelectedLayoutIcon = exports.getPixelWidthOfElement = exports.getMaxToolbarWidth = exports.downloadMedia = exports.calcNewLayout = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
11
11
|
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
12
|
-
var _utils = require("@atlaskit/editor-
|
|
12
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
13
14
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
14
15
|
var _mediaClientReact = require("@atlaskit/media-client-react");
|
|
15
16
|
var getSelectedMediaContainerNodeAttrs = exports.getSelectedMediaContainerNodeAttrs = function getSelectedMediaContainerNodeAttrs(mediaPluginState) {
|
|
@@ -59,19 +60,19 @@ var downloadMedia = exports.downloadMedia = /*#__PURE__*/function () {
|
|
|
59
60
|
}();
|
|
60
61
|
var removeMediaGroupNode = exports.removeMediaGroupNode = function removeMediaGroupNode(state) {
|
|
61
62
|
var mediaGroup = state.schema.nodes.mediaGroup;
|
|
62
|
-
var mediaGroupParent = (0,
|
|
63
|
+
var mediaGroupParent = (0, _utils2.findParentNodeOfType)(mediaGroup)(state.selection);
|
|
63
64
|
var tr = state.tr;
|
|
64
65
|
// If it is the last media group in filmstrip, remove the entire filmstrip
|
|
65
66
|
if (mediaGroupParent && mediaGroupParent.node.childCount === 1) {
|
|
66
|
-
tr = (0,
|
|
67
|
+
tr = (0, _utils2.removeParentNodeOfType)(mediaGroup)(tr);
|
|
67
68
|
} else {
|
|
68
|
-
tr = (0,
|
|
69
|
+
tr = (0, _utils2.removeSelectedNode)(tr);
|
|
69
70
|
}
|
|
70
71
|
return tr;
|
|
71
72
|
};
|
|
72
73
|
var getSelectedMediaSingle = exports.getSelectedMediaSingle = function getSelectedMediaSingle(state) {
|
|
73
74
|
var mediaSingle = state.schema.nodes.mediaSingle;
|
|
74
|
-
return (0,
|
|
75
|
+
return (0, _utils2.findSelectedNodeOfType)(mediaSingle)(state.selection) || (0, _utils2.findParentNodeOfType)(mediaSingle)(state.selection);
|
|
75
76
|
};
|
|
76
77
|
var getPixelWidthOfElement = exports.getPixelWidthOfElement = (0, _memoizeOne.default)(function (editorView, pos, mediaWidth) {
|
|
77
78
|
var domNode = editorView.nodeDOM(pos);
|
|
@@ -111,4 +112,10 @@ var getMaxToolbarWidth = exports.getMaxToolbarWidth = function getMaxToolbarWidt
|
|
|
111
112
|
maxToolbarFitWidth = toolbarWidth;
|
|
112
113
|
}
|
|
113
114
|
return maxToolbarFitWidth;
|
|
115
|
+
};
|
|
116
|
+
var getSelectedLayoutIcon = exports.getSelectedLayoutIcon = function getSelectedLayoutIcon(layoutIcons, selectedNode) {
|
|
117
|
+
var selectedLayout = selectedNode.attrs.layout;
|
|
118
|
+
return layoutIcons.find(function (icon) {
|
|
119
|
+
return icon.value === (_utils.nonWrappedLayouts.includes(selectedLayout) ? 'center' : selectedLayout);
|
|
120
|
+
});
|
|
114
121
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import { buildLayoutButtons } from '@atlaskit/editor-common/card';
|
|
4
|
+
import { alignmentIcons, buildLayoutButtons, layoutToMessages, wrappingIcons } from '@atlaskit/editor-common/card';
|
|
4
5
|
import { calcMinWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
5
6
|
import commonMessages, { cardMessages } from '@atlaskit/editor-common/messages';
|
|
6
7
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -24,9 +25,10 @@ import { altTextButton, getAltTextToolbar } from './alt-text';
|
|
|
24
25
|
import { changeInlineToMediaCard, changeMediaCardToInline, removeInlineCard, setBorderMark, toggleBorderMark, updateMediaSingleWidth } from './commands';
|
|
25
26
|
import { FilePreviewItem } from './filePreviewItem';
|
|
26
27
|
import { shouldShowImageBorder } from './imageBorder';
|
|
28
|
+
import { LayoutGroup } from './layout-group';
|
|
27
29
|
import { getLinkingToolbar, shouldShowMediaLinkToolbar } from './linking';
|
|
28
30
|
import { LinkToolbarAppearance } from './linking-toolbar-appearance';
|
|
29
|
-
import { calcNewLayout, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
31
|
+
import { calcNewLayout, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
30
32
|
const remove = (state, dispatch) => {
|
|
31
33
|
if (dispatch) {
|
|
32
34
|
dispatch(removeSelectedNode(state.tr));
|
|
@@ -241,21 +243,47 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
|
|
|
241
243
|
var _pluginInjectionApi$a3;
|
|
242
244
|
const widthPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width;
|
|
243
245
|
let isChangingLayoutDisabled = false;
|
|
246
|
+
const selectedNode = getSelectedMediaSingle(state);
|
|
244
247
|
if (getBooleanFF('platform.editor.media.extended-resize-experience')) {
|
|
245
248
|
var _widthPlugin$sharedSt;
|
|
246
249
|
const contentWidth = widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength;
|
|
247
|
-
const selectedNode = getSelectedMediaSingle(state);
|
|
248
250
|
const selectedNodeMaxWidth = pluginState.currentMaxWidth || contentWidth;
|
|
249
251
|
if (selectedNode && selectedNodeMaxWidth && selectedNode.node.attrs.width >= selectedNodeMaxWidth) {
|
|
250
252
|
isChangingLayoutDisabled = true;
|
|
251
253
|
}
|
|
252
254
|
}
|
|
253
255
|
const layoutButtons = buildLayoutButtons(state, intl, state.schema.nodes.mediaSingle, widthPlugin, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.actions, allowResizing, allowResizingInTables, true, true, isChangingLayoutDisabled);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
if (getBooleanFF('platform.editor.media.grouped-layout') && selectedNode) {
|
|
257
|
+
const selectedLayoutIcon = getSelectedLayoutIcon([...alignmentIcons, ...wrappingIcons], selectedNode.node);
|
|
258
|
+
if (selectedLayoutIcon && layoutButtons.length) {
|
|
259
|
+
const options = {
|
|
260
|
+
render: props => {
|
|
261
|
+
return /*#__PURE__*/React.createElement(LayoutGroup, _extends({
|
|
262
|
+
layoutButtons: layoutButtons
|
|
263
|
+
}, props));
|
|
264
|
+
},
|
|
265
|
+
width: 156,
|
|
266
|
+
height: 32
|
|
267
|
+
};
|
|
268
|
+
const trigger = {
|
|
269
|
+
id: 'media-single-layout',
|
|
270
|
+
testId: 'media-single-layout-dropdown-trigger',
|
|
271
|
+
type: 'dropdown',
|
|
272
|
+
options: options,
|
|
273
|
+
title: intl.formatMessage(layoutToMessages[selectedLayoutIcon.value]),
|
|
274
|
+
icon: selectedLayoutIcon.icon
|
|
275
|
+
};
|
|
276
|
+
toolbarButtons = [...toolbarButtons, trigger, {
|
|
277
|
+
type: 'separator'
|
|
278
|
+
}];
|
|
279
|
+
}
|
|
280
|
+
} else {
|
|
281
|
+
toolbarButtons = [...toolbarButtons, ...layoutButtons];
|
|
282
|
+
if (layoutButtons.length) {
|
|
283
|
+
toolbarButtons.push({
|
|
284
|
+
type: 'separator'
|
|
285
|
+
});
|
|
286
|
+
}
|
|
259
287
|
}
|
|
260
288
|
|
|
261
289
|
// Pixel Entry Toolbar Support
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/react';
|
|
3
|
+
import { ButtonGroup } from '@atlaskit/button';
|
|
4
|
+
import { FloatingToolbarButton as Button, FloatingToolbarSeparator } from '@atlaskit/editor-common/ui';
|
|
5
|
+
const containerStyles = css({
|
|
6
|
+
marginLeft: "var(--ds-space-100, 8px)"
|
|
7
|
+
});
|
|
8
|
+
export const LayoutGroup = ({
|
|
9
|
+
layoutButtons,
|
|
10
|
+
dispatchCommand,
|
|
11
|
+
hide
|
|
12
|
+
}) => {
|
|
13
|
+
return jsx("div", {
|
|
14
|
+
css: containerStyles
|
|
15
|
+
}, jsx(ButtonGroup, null, layoutButtons.map((item, idx) => {
|
|
16
|
+
switch (item.type) {
|
|
17
|
+
case 'separator':
|
|
18
|
+
return jsx(FloatingToolbarSeparator, {
|
|
19
|
+
key: idx
|
|
20
|
+
});
|
|
21
|
+
case 'button':
|
|
22
|
+
const ButtonIcon = item.icon;
|
|
23
|
+
return jsx(Button, {
|
|
24
|
+
key: idx,
|
|
25
|
+
icon: item.icon ? jsx(ButtonIcon, {
|
|
26
|
+
label: item.title
|
|
27
|
+
}) : undefined,
|
|
28
|
+
title: item.title,
|
|
29
|
+
selected: item.selected,
|
|
30
|
+
disabled: item.disabled,
|
|
31
|
+
onClick: () => {
|
|
32
|
+
dispatchCommand(item.onClick);
|
|
33
|
+
hide();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
})));
|
|
38
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import memoizeOne from 'memoize-one';
|
|
2
2
|
import { wrappedLayouts } from '@atlaskit/editor-common/media-single';
|
|
3
|
+
import { nonWrappedLayouts } from '@atlaskit/editor-common/utils';
|
|
3
4
|
import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
5
6
|
import { getMediaClient } from '@atlaskit/media-client-react';
|
|
@@ -86,4 +87,8 @@ export const getMaxToolbarWidth = () => {
|
|
|
86
87
|
maxToolbarFitWidth = toolbarWidth;
|
|
87
88
|
}
|
|
88
89
|
return maxToolbarFitWidth;
|
|
90
|
+
};
|
|
91
|
+
export const getSelectedLayoutIcon = (layoutIcons, selectedNode) => {
|
|
92
|
+
const selectedLayout = selectedNode.attrs.layout;
|
|
93
|
+
return layoutIcons.find(icon => icon.value === (nonWrappedLayouts.includes(selectedLayout) ? 'center' : selectedLayout));
|
|
89
94
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
3
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
4
|
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; }
|
|
4
5
|
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; }
|
|
5
6
|
import React from 'react';
|
|
6
7
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
7
|
-
import { buildLayoutButtons } from '@atlaskit/editor-common/card';
|
|
8
|
+
import { alignmentIcons, buildLayoutButtons, layoutToMessages, wrappingIcons } from '@atlaskit/editor-common/card';
|
|
8
9
|
import { calcMinWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
9
10
|
import commonMessages, { cardMessages } from '@atlaskit/editor-common/messages';
|
|
10
11
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
@@ -28,9 +29,10 @@ import { altTextButton, getAltTextToolbar } from './alt-text';
|
|
|
28
29
|
import { changeInlineToMediaCard, changeMediaCardToInline, removeInlineCard, setBorderMark, toggleBorderMark, updateMediaSingleWidth } from './commands';
|
|
29
30
|
import { FilePreviewItem } from './filePreviewItem';
|
|
30
31
|
import { shouldShowImageBorder } from './imageBorder';
|
|
32
|
+
import { LayoutGroup } from './layout-group';
|
|
31
33
|
import { getLinkingToolbar, shouldShowMediaLinkToolbar } from './linking';
|
|
32
34
|
import { LinkToolbarAppearance } from './linking-toolbar-appearance';
|
|
33
|
-
import { calcNewLayout, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
35
|
+
import { calcNewLayout, downloadMedia, getMaxToolbarWidth, getPixelWidthOfElement, getSelectedLayoutIcon, getSelectedMediaSingle, removeMediaGroupNode } from './utils';
|
|
34
36
|
var remove = function remove(state, dispatch) {
|
|
35
37
|
if (dispatch) {
|
|
36
38
|
dispatch(removeSelectedNode(state.tr));
|
|
@@ -234,21 +236,47 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
234
236
|
var _pluginInjectionApi$a3;
|
|
235
237
|
var widthPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width;
|
|
236
238
|
var isChangingLayoutDisabled = false;
|
|
239
|
+
var selectedNode = getSelectedMediaSingle(state);
|
|
237
240
|
if (getBooleanFF('platform.editor.media.extended-resize-experience')) {
|
|
238
241
|
var _widthPlugin$sharedSt;
|
|
239
242
|
var contentWidth = widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt === void 0 ? void 0 : _widthPlugin$sharedSt.lineLength;
|
|
240
|
-
var selectedNode = getSelectedMediaSingle(state);
|
|
241
243
|
var selectedNodeMaxWidth = pluginState.currentMaxWidth || contentWidth;
|
|
242
244
|
if (selectedNode && selectedNodeMaxWidth && selectedNode.node.attrs.width >= selectedNodeMaxWidth) {
|
|
243
245
|
isChangingLayoutDisabled = true;
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
var layoutButtons = buildLayoutButtons(state, intl, state.schema.nodes.mediaSingle, widthPlugin, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a3 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.actions, allowResizing, allowResizingInTables, true, true, isChangingLayoutDisabled);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
if (getBooleanFF('platform.editor.media.grouped-layout') && selectedNode) {
|
|
250
|
+
var selectedLayoutIcon = getSelectedLayoutIcon([].concat(_toConsumableArray(alignmentIcons), _toConsumableArray(wrappingIcons)), selectedNode.node);
|
|
251
|
+
if (selectedLayoutIcon && layoutButtons.length) {
|
|
252
|
+
var _options = {
|
|
253
|
+
render: function render(props) {
|
|
254
|
+
return /*#__PURE__*/React.createElement(LayoutGroup, _extends({
|
|
255
|
+
layoutButtons: layoutButtons
|
|
256
|
+
}, props));
|
|
257
|
+
},
|
|
258
|
+
width: 156,
|
|
259
|
+
height: 32
|
|
260
|
+
};
|
|
261
|
+
var trigger = {
|
|
262
|
+
id: 'media-single-layout',
|
|
263
|
+
testId: 'media-single-layout-dropdown-trigger',
|
|
264
|
+
type: 'dropdown',
|
|
265
|
+
options: _options,
|
|
266
|
+
title: intl.formatMessage(layoutToMessages[selectedLayoutIcon.value]),
|
|
267
|
+
icon: selectedLayoutIcon.icon
|
|
268
|
+
};
|
|
269
|
+
toolbarButtons = [].concat(_toConsumableArray(toolbarButtons), [trigger, {
|
|
270
|
+
type: 'separator'
|
|
271
|
+
}]);
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
toolbarButtons = [].concat(_toConsumableArray(toolbarButtons), _toConsumableArray(layoutButtons));
|
|
275
|
+
if (layoutButtons.length) {
|
|
276
|
+
toolbarButtons.push({
|
|
277
|
+
type: 'separator'
|
|
278
|
+
});
|
|
279
|
+
}
|
|
252
280
|
}
|
|
253
281
|
|
|
254
282
|
// Pixel Entry Toolbar Support
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, jsx } from '@emotion/react';
|
|
3
|
+
import { ButtonGroup } from '@atlaskit/button';
|
|
4
|
+
import { FloatingToolbarButton as Button, FloatingToolbarSeparator } from '@atlaskit/editor-common/ui';
|
|
5
|
+
var containerStyles = css({
|
|
6
|
+
marginLeft: "var(--ds-space-100, 8px)"
|
|
7
|
+
});
|
|
8
|
+
export var LayoutGroup = function LayoutGroup(_ref) {
|
|
9
|
+
var layoutButtons = _ref.layoutButtons,
|
|
10
|
+
dispatchCommand = _ref.dispatchCommand,
|
|
11
|
+
hide = _ref.hide;
|
|
12
|
+
return jsx("div", {
|
|
13
|
+
css: containerStyles
|
|
14
|
+
}, jsx(ButtonGroup, null, layoutButtons.map(function (item, idx) {
|
|
15
|
+
switch (item.type) {
|
|
16
|
+
case 'separator':
|
|
17
|
+
return jsx(FloatingToolbarSeparator, {
|
|
18
|
+
key: idx
|
|
19
|
+
});
|
|
20
|
+
case 'button':
|
|
21
|
+
var ButtonIcon = item.icon;
|
|
22
|
+
return jsx(Button, {
|
|
23
|
+
key: idx,
|
|
24
|
+
icon: item.icon ? jsx(ButtonIcon, {
|
|
25
|
+
label: item.title
|
|
26
|
+
}) : undefined,
|
|
27
|
+
title: item.title,
|
|
28
|
+
selected: item.selected,
|
|
29
|
+
disabled: item.disabled,
|
|
30
|
+
onClick: function onClick() {
|
|
31
|
+
dispatchCommand(item.onClick);
|
|
32
|
+
hide();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
})));
|
|
37
|
+
};
|
|
@@ -2,6 +2,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import memoizeOne from 'memoize-one';
|
|
4
4
|
import { wrappedLayouts } from '@atlaskit/editor-common/media-single';
|
|
5
|
+
import { nonWrappedLayouts } from '@atlaskit/editor-common/utils';
|
|
5
6
|
import { findParentNodeOfType, findSelectedNodeOfType, removeParentNodeOfType, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
6
7
|
import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
7
8
|
import { getMediaClient } from '@atlaskit/media-client-react';
|
|
@@ -104,4 +105,10 @@ export var getMaxToolbarWidth = function getMaxToolbarWidth() {
|
|
|
104
105
|
maxToolbarFitWidth = toolbarWidth;
|
|
105
106
|
}
|
|
106
107
|
return maxToolbarFitWidth;
|
|
108
|
+
};
|
|
109
|
+
export var getSelectedLayoutIcon = function getSelectedLayoutIcon(layoutIcons, selectedNode) {
|
|
110
|
+
var selectedLayout = selectedNode.attrs.layout;
|
|
111
|
+
return layoutIcons.find(function (icon) {
|
|
112
|
+
return icon.value === (nonWrappedLayouts.includes(selectedLayout) ? 'center' : selectedLayout);
|
|
113
|
+
});
|
|
107
114
|
};
|
|
@@ -15,7 +15,7 @@ import type { InsertMediaAsMediaSingle } from './utils/media-single';
|
|
|
15
15
|
export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
|
|
16
16
|
pluginConfiguration: MediaOptions | undefined;
|
|
17
17
|
dependencies: [
|
|
18
|
-
FeatureFlagsPlugin
|
|
18
|
+
OptionalPlugin<FeatureFlagsPlugin>,
|
|
19
19
|
OptionalPlugin<AnalyticsPlugin>,
|
|
20
20
|
GuidelinePlugin,
|
|
21
21
|
GridPlugin,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
3
|
+
import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
4
|
+
type Props = {
|
|
5
|
+
layoutButtons: FloatingToolbarItem<Command>[];
|
|
6
|
+
dispatchCommand: (command: Command) => void;
|
|
7
|
+
hide: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const LayoutGroup: ({ layoutButtons, dispatchCommand, hide, }: Props) => jsx.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { MediaBaseAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { LayoutIcon } from '@atlaskit/editor-common/card';
|
|
3
|
+
import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
6
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
@@ -9,3 +11,4 @@ export declare const getSelectedMediaSingle: (state: EditorState) => import("pro
|
|
|
9
11
|
export declare const getPixelWidthOfElement: import("memoize-one").MemoizedFn<(editorView: EditorView, pos: number, mediaWidth: number) => number>;
|
|
10
12
|
export declare const calcNewLayout: (width: number, layout: RichMediaLayout, contentWidth: number, fullWidthMode?: boolean, isNested?: boolean) => RichMediaLayout;
|
|
11
13
|
export declare const getMaxToolbarWidth: () => number;
|
|
14
|
+
export declare const getSelectedLayoutIcon: (layoutIcons: LayoutIcon[], selectedNode: ProseMirrorNode) => LayoutIcon | undefined;
|
|
@@ -15,7 +15,7 @@ import type { InsertMediaAsMediaSingle } from './utils/media-single';
|
|
|
15
15
|
export type MediaNextEditorPluginType = NextEditorPlugin<'media', {
|
|
16
16
|
pluginConfiguration: MediaOptions | undefined;
|
|
17
17
|
dependencies: [
|
|
18
|
-
FeatureFlagsPlugin
|
|
18
|
+
OptionalPlugin<FeatureFlagsPlugin>,
|
|
19
19
|
OptionalPlugin<AnalyticsPlugin>,
|
|
20
20
|
GuidelinePlugin,
|
|
21
21
|
GridPlugin,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { jsx } from '@emotion/react';
|
|
3
|
+
import type { Command, FloatingToolbarItem } from '@atlaskit/editor-common/types';
|
|
4
|
+
type Props = {
|
|
5
|
+
layoutButtons: FloatingToolbarItem<Command>[];
|
|
6
|
+
dispatchCommand: (command: Command) => void;
|
|
7
|
+
hide: () => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const LayoutGroup: ({ layoutButtons, dispatchCommand, hide, }: Props) => jsx.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { MediaBaseAttributes, RichMediaLayout } from '@atlaskit/adf-schema';
|
|
2
|
+
import type { LayoutIcon } from '@atlaskit/editor-common/card';
|
|
3
|
+
import type { Node as ProseMirrorNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
4
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
5
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
6
|
import type { MediaPluginState } from '../pm-plugins/types';
|
|
@@ -9,3 +11,4 @@ export declare const getSelectedMediaSingle: (state: EditorState) => import("pro
|
|
|
9
11
|
export declare const getPixelWidthOfElement: import("memoize-one").MemoizedFn<(editorView: EditorView, pos: number, mediaWidth: number) => number>;
|
|
10
12
|
export declare const calcNewLayout: (width: number, layout: RichMediaLayout, contentWidth: number, fullWidthMode?: boolean, isNested?: boolean) => RichMediaLayout;
|
|
11
13
|
export declare const getMaxToolbarWidth: () => number;
|
|
14
|
+
export declare const getSelectedLayoutIcon: (layoutIcons: LayoutIcon[], selectedNode: ProseMirrorNode) => LayoutIcon | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-media",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Media plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@atlaskit/analytics-namespaced-context": "^6.7.0",
|
|
37
37
|
"@atlaskit/analytics-next": "^9.1.0",
|
|
38
38
|
"@atlaskit/button": "^16.17.0",
|
|
39
|
-
"@atlaskit/editor-common": "^76.
|
|
39
|
+
"@atlaskit/editor-common": "^76.23.0",
|
|
40
40
|
"@atlaskit/editor-palette": "1.5.2",
|
|
41
41
|
"@atlaskit/editor-plugin-analytics": "^0.3.0",
|
|
42
42
|
"@atlaskit/editor-plugin-decorations": "^0.2.0",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"@atlaskit/platform-feature-flags": "^0.2.0",
|
|
65
65
|
"@atlaskit/textfield": "^6.0.0",
|
|
66
66
|
"@atlaskit/theme": "^12.6.0",
|
|
67
|
-
"@atlaskit/tokens": "^1.
|
|
67
|
+
"@atlaskit/tokens": "^1.29.0",
|
|
68
68
|
"@atlaskit/tooltip": "^18.0.0",
|
|
69
69
|
"@babel/runtime": "^7.0.0",
|
|
70
70
|
"@emotion/react": "^11.7.1",
|
|
@@ -134,6 +134,9 @@
|
|
|
134
134
|
"platform.editor.media.inline-image.base-support": {
|
|
135
135
|
"type": "boolean"
|
|
136
136
|
},
|
|
137
|
+
"platform.editor.media.grouped-layout": {
|
|
138
|
+
"type": "boolean"
|
|
139
|
+
},
|
|
137
140
|
"platform.media-experience.media-viewer-v2_hgsii": {
|
|
138
141
|
"type": "boolean",
|
|
139
142
|
"referenceOnly": "true"
|
package/report.api.md
CHANGED
|
@@ -156,7 +156,7 @@ export type MediaPlugin = NextEditorPlugin<
|
|
|
156
156
|
{
|
|
157
157
|
pluginConfiguration: MediaOptions | undefined;
|
|
158
158
|
dependencies: [
|
|
159
|
-
FeatureFlagsPlugin
|
|
159
|
+
OptionalPlugin<FeatureFlagsPlugin>,
|
|
160
160
|
OptionalPlugin<AnalyticsPlugin>,
|
|
161
161
|
GuidelinePlugin,
|
|
162
162
|
GridPlugin,
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -139,7 +139,7 @@ interface MediaOptions {
|
|
|
139
139
|
export type MediaPlugin = NextEditorPlugin<'media', {
|
|
140
140
|
pluginConfiguration: MediaOptions | undefined;
|
|
141
141
|
dependencies: [
|
|
142
|
-
FeatureFlagsPlugin
|
|
142
|
+
OptionalPlugin<FeatureFlagsPlugin>,
|
|
143
143
|
OptionalPlugin<AnalyticsPlugin>,
|
|
144
144
|
GuidelinePlugin,
|
|
145
145
|
GridPlugin,
|