@atlaskit/editor-plugin-media 2.3.7 → 2.3.9
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 +15 -0
- package/dist/cjs/mediaPlugin.js +7 -0
- package/dist/cjs/pm-plugins/pixel-resizing/commands.js +22 -0
- package/dist/cjs/pm-plugins/pixel-resizing/index.js +31 -0
- package/dist/cjs/pm-plugins/pixel-resizing/reducer.js +28 -0
- package/dist/cjs/pm-plugins/pixel-resizing/ui/constants.js +11 -0
- package/dist/cjs/pm-plugins/pixel-resizing/ui/index.js +124 -0
- package/dist/cjs/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +168 -13
- package/dist/cjs/ui/toolbar/commands.js +29 -22
- package/dist/cjs/ui/toolbar/index.js +63 -97
- package/dist/cjs/ui/toolbar/linking.js +1 -1
- package/dist/cjs/ui/toolbar/pixel-resizing.js +47 -0
- package/dist/es2019/mediaPlugin.js +7 -0
- package/dist/es2019/pm-plugins/pixel-resizing/commands.js +16 -0
- package/dist/es2019/pm-plugins/pixel-resizing/index.js +27 -0
- package/dist/es2019/pm-plugins/pixel-resizing/reducer.js +20 -0
- package/dist/es2019/pm-plugins/pixel-resizing/ui/constants.js +5 -0
- package/dist/es2019/pm-plugins/pixel-resizing/ui/index.js +126 -0
- package/dist/es2019/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +170 -19
- package/dist/es2019/ui/toolbar/commands.js +9 -2
- package/dist/es2019/ui/toolbar/index.js +55 -91
- package/dist/es2019/ui/toolbar/linking.js +1 -1
- package/dist/es2019/ui/toolbar/pixel-resizing.js +37 -0
- package/dist/esm/mediaPlugin.js +7 -0
- package/dist/esm/pm-plugins/pixel-resizing/commands.js +16 -0
- package/dist/esm/pm-plugins/pixel-resizing/index.js +25 -0
- package/dist/esm/pm-plugins/pixel-resizing/reducer.js +21 -0
- package/dist/esm/pm-plugins/pixel-resizing/ui/constants.js +5 -0
- package/dist/esm/pm-plugins/pixel-resizing/ui/index.js +120 -0
- package/dist/esm/{ui/PixelEntry/index.js → pm-plugins/pixel-resizing/ui/pixel-entry.js} +172 -17
- package/dist/esm/ui/toolbar/commands.js +28 -21
- package/dist/esm/ui/toolbar/index.js +55 -89
- package/dist/esm/ui/toolbar/linking.js +1 -1
- package/dist/esm/ui/toolbar/pixel-resizing.js +40 -0
- package/dist/types/pm-plugins/pixel-resizing/commands.d.ts +4 -0
- package/dist/types/pm-plugins/pixel-resizing/index.d.ts +13 -0
- package/dist/types/pm-plugins/pixel-resizing/reducer.d.ts +12 -0
- package/dist/types/pm-plugins/pixel-resizing/ui/constants.d.ts +3 -0
- package/dist/types/pm-plugins/pixel-resizing/ui/index.d.ts +21 -0
- package/dist/types/pm-plugins/pixel-resizing/ui/pixel-entry.d.ts +4 -0
- package/dist/types/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.d.ts +18 -0
- package/dist/types/ui/toolbar/commands.d.ts +2 -1
- package/dist/types/ui/toolbar/pixel-resizing.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/commands.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/index.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/reducer.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/constants.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/index.d.ts +21 -0
- package/dist/types-ts4.5/pm-plugins/pixel-resizing/ui/pixel-entry.d.ts +4 -0
- package/dist/types-ts4.5/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.d.ts +18 -0
- package/dist/types-ts4.5/ui/toolbar/commands.d.ts +2 -1
- package/dist/types-ts4.5/ui/toolbar/pixel-resizing.d.ts +4 -0
- package/package.json +8 -8
- package/dist/cjs/ui/PixelEntry/constants.js +0 -7
- package/dist/es2019/ui/PixelEntry/constants.js +0 -1
- package/dist/esm/ui/PixelEntry/constants.js +0 -1
- package/dist/types/ui/PixelEntry/constants.d.ts +0 -1
- package/dist/types/ui/PixelEntry/index.d.ts +0 -7
- package/dist/types-ts4.5/ui/PixelEntry/constants.d.ts +0 -1
- package/dist/types-ts4.5/ui/PixelEntry/index.d.ts +0 -7
- /package/dist/cjs/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
- /package/dist/cjs/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
- /package/dist/es2019/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
- /package/dist/es2019/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
- /package/dist/esm/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.js +0 -0
- /package/dist/esm/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/types.js +0 -0
- /package/dist/types/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.d.ts +0 -0
- /package/dist/types-ts4.5/{ui/PixelEntry → pm-plugins/pixel-resizing/ui}/styles.d.ts +0 -0
|
@@ -14,11 +14,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
14
14
|
var _card = require("@atlaskit/editor-common/card");
|
|
15
15
|
var _media = require("@atlaskit/editor-common/media");
|
|
16
16
|
var _mediaInline = require("@atlaskit/editor-common/media-inline");
|
|
17
|
-
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
18
17
|
var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
|
|
19
18
|
var _state2 = require("@atlaskit/editor-prosemirror/state");
|
|
20
19
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
21
|
-
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
22
20
|
var _copy = _interopRequireDefault(require("@atlaskit/icon/core/copy"));
|
|
23
21
|
var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
|
|
24
22
|
var _growDiagonal = _interopRequireDefault(require("@atlaskit/icon/core/grow-diagonal"));
|
|
@@ -40,19 +38,22 @@ var _altText = require("../../pm-plugins/alt-text");
|
|
|
40
38
|
var _commands = require("../../pm-plugins/alt-text/commands");
|
|
41
39
|
var _linking = require("../../pm-plugins/commands/linking");
|
|
42
40
|
var _linking2 = require("../../pm-plugins/linking");
|
|
41
|
+
var _pixelResizing = require("../../pm-plugins/pixel-resizing");
|
|
42
|
+
var _commands2 = require("../../pm-plugins/pixel-resizing/commands");
|
|
43
|
+
var _ui = require("../../pm-plugins/pixel-resizing/ui");
|
|
43
44
|
var _pluginKey = require("../../pm-plugins/plugin-key");
|
|
44
45
|
var _currentMediaNode = require("../../pm-plugins/utils/current-media-node");
|
|
45
|
-
var
|
|
46
|
+
var _mediaSingle = require("../../pm-plugins/utils/media-single");
|
|
46
47
|
var _ImageBorder = _interopRequireDefault(require("../../ui/ImageBorder"));
|
|
47
|
-
var _PixelEntry = require("../../ui/PixelEntry");
|
|
48
48
|
var _altText2 = require("./alt-text");
|
|
49
|
-
var
|
|
49
|
+
var _commands3 = require("./commands");
|
|
50
50
|
var _comments = require("./comments");
|
|
51
51
|
var _imageBorder = require("./imageBorder");
|
|
52
52
|
var _layoutGroup = require("./layout-group");
|
|
53
53
|
var _linking3 = require("./linking");
|
|
54
54
|
var _linkingToolbarAppearance = require("./linking-toolbar-appearance");
|
|
55
55
|
var _mediaInline2 = require("./mediaInline");
|
|
56
|
+
var _pixelResizing2 = require("./pixel-resizing");
|
|
56
57
|
var _utils2 = require("./utils");
|
|
57
58
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
58
59
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -89,7 +90,7 @@ var handleShowMediaViewer = exports.handleShowMediaViewer = function handleShowM
|
|
|
89
90
|
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.media.commands.showMediaViewer(selectedNodeAttrs));
|
|
90
91
|
};
|
|
91
92
|
var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, editorAnalyticsAPI, forceFocusSelector, isViewOnly) {
|
|
92
|
-
var _mediaPluginState$med;
|
|
93
|
+
var _mediaPluginState$med, _pluginInjectionApi$c;
|
|
93
94
|
if (isViewOnly) {
|
|
94
95
|
return [];
|
|
95
96
|
}
|
|
@@ -104,7 +105,7 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
|
|
|
104
105
|
selected: false,
|
|
105
106
|
focusEditoronEnter: true,
|
|
106
107
|
disabled: false,
|
|
107
|
-
onClick: (0,
|
|
108
|
+
onClick: (0, _commands3.changeMediaCardToInline)(editorAnalyticsAPI, forceFocusSelector),
|
|
108
109
|
title: intl.formatMessage(_messages.cardMessages.inlineTitle),
|
|
109
110
|
testId: 'inline-appearance',
|
|
110
111
|
className: 'inline-appearance' // a11y. uses to force focus on item
|
|
@@ -138,6 +139,7 @@ var generateMediaCardFloatingToolbar = function generateMediaCardFloatingToolbar
|
|
|
138
139
|
api: pluginInjectionApi
|
|
139
140
|
})) !== null && _handleShowMediaViewe !== void 0 ? _handleShowMediaViewe : false;
|
|
140
141
|
},
|
|
142
|
+
disabled: (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.connectivity) === null || _pluginInjectionApi$c === void 0 || (_pluginInjectionApi$c = _pluginInjectionApi$c.sharedState) === null || _pluginInjectionApi$c === void 0 || (_pluginInjectionApi$c = _pluginInjectionApi$c.currentState()) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.mode) === 'offline',
|
|
141
143
|
supportsViewMode: true
|
|
142
144
|
}, {
|
|
143
145
|
type: 'separator'
|
|
@@ -210,11 +212,11 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
210
212
|
return /*#__PURE__*/_react.default.createElement(_ImageBorder.default, {
|
|
211
213
|
toggleBorder: function toggleBorder() {
|
|
212
214
|
var _pluginInjectionApi$a;
|
|
213
|
-
(0,
|
|
215
|
+
(0, _commands3.toggleBorderMark)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)(state, dispatch);
|
|
214
216
|
},
|
|
215
217
|
setBorder: function setBorder(attrs) {
|
|
216
218
|
var _pluginInjectionApi$a2;
|
|
217
|
-
(0,
|
|
219
|
+
(0, _commands3.setBorderMark)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions)(attrs)(state, dispatch);
|
|
218
220
|
},
|
|
219
221
|
borderMark: borderMark,
|
|
220
222
|
intl: intl
|
|
@@ -297,7 +299,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
297
299
|
LEGACY_fallbackIcon: _card.IconInline
|
|
298
300
|
});
|
|
299
301
|
},
|
|
300
|
-
onClick: (0,
|
|
302
|
+
onClick: (0, _commands3.changeMediaSingleToMediaInline)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a4 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a4 === void 0 ? void 0 : _pluginInjectionApi$a4.actions),
|
|
301
303
|
testId: 'image-inline-appearance'
|
|
302
304
|
}, {
|
|
303
305
|
type: 'button',
|
|
@@ -325,7 +327,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
325
327
|
var _options2 = [{
|
|
326
328
|
id: 'editor.media.convert.mediainline',
|
|
327
329
|
title: inlineSwitcherTitle,
|
|
328
|
-
onClick: (0,
|
|
330
|
+
onClick: (0, _commands3.changeMediaSingleToMediaInline)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a5 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a5 === void 0 ? void 0 : _pluginInjectionApi$a5.actions),
|
|
329
331
|
icon: /*#__PURE__*/_react.default.createElement(_imageInline.default, {
|
|
330
332
|
color: "currentColor",
|
|
331
333
|
spacing: "spacious",
|
|
@@ -381,69 +383,17 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
381
383
|
type: 'custom',
|
|
382
384
|
fallback: [],
|
|
383
385
|
render: function render(editorView) {
|
|
384
|
-
var _widthPlugin$sharedSt2, _pluginInjectionApi$m;
|
|
385
386
|
if (!editorView || !selectedMediaSingleNode) {
|
|
386
387
|
return null;
|
|
387
388
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
var contentWidth = (widthPlugin === null || widthPlugin === void 0 || (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength) || _editorSharedStyles.akEditorDefaultLayoutWidth;
|
|
391
|
-
var selectedMediaNode = selectedMediaSingleNode.node.content.firstChild;
|
|
392
|
-
if (!selectedMediaNode) {
|
|
393
|
-
return null;
|
|
394
|
-
}
|
|
395
|
-
var _selectedMediaSingleN = selectedMediaSingleNode.node.attrs,
|
|
396
|
-
mediaSingleWidth = _selectedMediaSingleN.width,
|
|
397
|
-
widthType = _selectedMediaSingleN.widthType,
|
|
398
|
-
layout = _selectedMediaSingleN.layout;
|
|
399
|
-
var _selectedMediaNode$at = selectedMediaNode.attrs,
|
|
400
|
-
mediaWidth = _selectedMediaNode$at.width,
|
|
401
|
-
mediaHeight = _selectedMediaNode$at.height;
|
|
402
|
-
var maxWidthForNestedNode = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 || (_pluginInjectionApi$m = _pluginInjectionApi$m.sharedState.currentState()) === null || _pluginInjectionApi$m === void 0 ? void 0 : _pluginInjectionApi$m.currentMaxWidth;
|
|
403
|
-
var maxWidth = maxWidthForNestedNode || _editorSharedStyles.akEditorFullWidthLayoutWidth;
|
|
404
|
-
var isVideoFile = (0, _mediaSingle2.isVideo)(selectedMediaNode.attrs.__fileMimeType);
|
|
405
|
-
var minWidth = (0, _mediaSingle.calcMinWidth)(isVideoFile, maxWidthForNestedNode || contentWidth);
|
|
406
|
-
var hasPixelType = widthType === 'pixel';
|
|
407
|
-
var pixelWidthFromElement = (0, _utils2.getPixelWidthOfElement)(editorView, selectedMediaSingleNode.pos + 1,
|
|
408
|
-
// get pos of media node
|
|
409
|
-
mediaWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH);
|
|
410
|
-
var pixelWidth = hasPixelType ? mediaSingleWidth : pixelWidthFromElement;
|
|
411
|
-
|
|
412
|
-
//hasParentNode will return falsey value if selection depth === 0
|
|
413
|
-
var isNested = (0, _utils.hasParentNode)(function (n) {
|
|
414
|
-
return n.type !== state.schema.nodes.doc;
|
|
415
|
-
})(state.selection);
|
|
416
|
-
return /*#__PURE__*/_react.default.createElement(_PixelEntry.PixelEntry, {
|
|
389
|
+
return /*#__PURE__*/_react.default.createElement(_ui.PixelEntry, {
|
|
390
|
+
editorView: editorView,
|
|
417
391
|
intl: intl,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
maxWidth: maxWidth,
|
|
424
|
-
onChange: function onChange(valid) {
|
|
425
|
-
if (valid) {
|
|
426
|
-
hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, true, 'warning')(editorView.state, dispatch, editorView);
|
|
427
|
-
} else {
|
|
428
|
-
hoverDecoration === null || hoverDecoration === void 0 || hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
|
|
429
|
-
}
|
|
430
|
-
},
|
|
431
|
-
onSubmit: function onSubmit(_ref3) {
|
|
432
|
-
var _pluginInjectionApi$a6;
|
|
433
|
-
var width = _ref3.width,
|
|
434
|
-
validation = _ref3.validation;
|
|
435
|
-
var newLayout = (0, _utils2.calcNewLayout)(width, layout, contentWidth, options.fullWidthEnabled, isNested);
|
|
436
|
-
(0, _commands2.updateMediaSingleWidth)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a6 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a6 === void 0 ? void 0 : _pluginInjectionApi$a6.actions)(width, validation, 'floatingToolBar', newLayout)(state, dispatch);
|
|
437
|
-
},
|
|
438
|
-
onMigrate: function onMigrate() {
|
|
439
|
-
var tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, _objectSpread(_objectSpread({}, selectedMediaSingleNode.node.attrs), {}, {
|
|
440
|
-
width: pixelWidthFromElement,
|
|
441
|
-
widthType: 'pixel'
|
|
442
|
-
}));
|
|
443
|
-
tr.setMeta('scrollIntoView', false);
|
|
444
|
-
tr.setSelection(_state2.NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
|
|
445
|
-
dispatch(tr);
|
|
446
|
-
}
|
|
392
|
+
selectedMediaSingleNode: selectedMediaSingleNode,
|
|
393
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
394
|
+
pluginState: pluginState,
|
|
395
|
+
hoverDecoration: hoverDecoration,
|
|
396
|
+
isEditorFullWidthEnabled: options.fullWidthEnabled
|
|
447
397
|
});
|
|
448
398
|
}
|
|
449
399
|
};
|
|
@@ -459,7 +409,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
459
409
|
type: 'custom',
|
|
460
410
|
fallback: [],
|
|
461
411
|
render: function render() {
|
|
462
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
412
|
+
return /*#__PURE__*/_react.default.createElement(_ui.FullWidthDisplay, {
|
|
463
413
|
intl: intl
|
|
464
414
|
});
|
|
465
415
|
}
|
|
@@ -497,10 +447,10 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
497
447
|
};
|
|
498
448
|
var openLink = function openLink() {
|
|
499
449
|
if (editorView) {
|
|
500
|
-
var _pluginInjectionApi$
|
|
450
|
+
var _pluginInjectionApi$a6;
|
|
501
451
|
var tr = editorView.state.tr,
|
|
502
452
|
dispatch = editorView.dispatch;
|
|
503
|
-
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
453
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a6 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a6 === void 0 || _pluginInjectionApi$a6.actions.attachAnalyticsEvent({
|
|
504
454
|
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
505
455
|
action: _analytics.ACTION.VISITED,
|
|
506
456
|
actionSubject: _analytics.ACTION_SUBJECT.MEDIA,
|
|
@@ -531,7 +481,8 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
531
481
|
var _mediaNode$attrs;
|
|
532
482
|
var _selectedMediaSingleNode = (0, _utils2.getSelectedMediaSingle)(state);
|
|
533
483
|
var mediaNode = _selectedMediaSingleNode === null || _selectedMediaSingleNode === void 0 ? void 0 : _selectedMediaSingleNode.node.content.firstChild;
|
|
534
|
-
if (!(0,
|
|
484
|
+
if (!(0, _mediaSingle.isVideo)(mediaNode === null || mediaNode === void 0 || (_mediaNode$attrs = mediaNode.attrs) === null || _mediaNode$attrs === void 0 ? void 0 : _mediaNode$attrs.__fileMimeType)) {
|
|
485
|
+
var _pluginInjectionApi$c2;
|
|
535
486
|
toolbarButtons.push({
|
|
536
487
|
id: 'editor.media.viewer',
|
|
537
488
|
testId: 'file-preview-toolbar-button',
|
|
@@ -546,6 +497,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
546
497
|
mediaPluginState: pluginState
|
|
547
498
|
})) !== null && _handleShowMediaViewe2 !== void 0 ? _handleShowMediaViewe2 : false;
|
|
548
499
|
},
|
|
500
|
+
disabled: (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.connectivity) === null || _pluginInjectionApi$c2 === void 0 || (_pluginInjectionApi$c2 = _pluginInjectionApi$c2.sharedState) === null || _pluginInjectionApi$c2 === void 0 || (_pluginInjectionApi$c2 = _pluginInjectionApi$c2.currentState()) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.mode) === 'offline',
|
|
549
501
|
supportsViewMode: true
|
|
550
502
|
}, {
|
|
551
503
|
type: 'separator',
|
|
@@ -572,8 +524,8 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
572
524
|
});
|
|
573
525
|
}
|
|
574
526
|
if (allowAltTextOnImages && (0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
|
|
575
|
-
var _pluginInjectionApi$
|
|
576
|
-
toolbarButtons.push((0, _altText2.altTextButton)(intl, state, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
527
|
+
var _pluginInjectionApi$a7;
|
|
528
|
+
toolbarButtons.push((0, _altText2.altTextButton)(intl, state, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a7 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a7 === void 0 ? void 0 : _pluginInjectionApi$a7.actions), {
|
|
577
529
|
type: 'separator'
|
|
578
530
|
});
|
|
579
531
|
}
|
|
@@ -599,7 +551,8 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
599
551
|
var _mediaNode$attrs2;
|
|
600
552
|
var _selectedMediaSingleNode2 = (0, _utils2.getSelectedMediaSingle)(state);
|
|
601
553
|
var _mediaNode = _selectedMediaSingleNode2 === null || _selectedMediaSingleNode2 === void 0 ? void 0 : _selectedMediaSingleNode2.node.content.firstChild;
|
|
602
|
-
if (!(0,
|
|
554
|
+
if (!(0, _mediaSingle.isVideo)(_mediaNode === null || _mediaNode === void 0 || (_mediaNode$attrs2 = _mediaNode.attrs) === null || _mediaNode$attrs2 === void 0 ? void 0 : _mediaNode$attrs2.__fileMimeType)) {
|
|
555
|
+
var _pluginInjectionApi$c3;
|
|
603
556
|
toolbarButtons.push({
|
|
604
557
|
id: 'editor.media.viewer',
|
|
605
558
|
testId: 'file-preview-toolbar-button',
|
|
@@ -614,6 +567,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
614
567
|
mediaPluginState: pluginState
|
|
615
568
|
})) !== null && _handleShowMediaViewe3 !== void 0 ? _handleShowMediaViewe3 : false;
|
|
616
569
|
},
|
|
570
|
+
disabled: (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.connectivity) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.sharedState) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.currentState()) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.mode) === 'offline',
|
|
617
571
|
supportsViewMode: true
|
|
618
572
|
}, {
|
|
619
573
|
type: 'separator',
|
|
@@ -686,11 +640,13 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
686
640
|
providerFactory = options.providerFactory,
|
|
687
641
|
allowMediaInline = options.allowMediaInline,
|
|
688
642
|
allowResizing = options.allowResizing,
|
|
689
|
-
isViewOnly = options.isViewOnly
|
|
643
|
+
isViewOnly = options.isViewOnly,
|
|
644
|
+
allowResizingInTables = options.allowResizingInTables,
|
|
645
|
+
allowAdvancedToolBarOptions = options.allowAdvancedToolBarOptions;
|
|
690
646
|
var mediaPluginState = _pluginKey.stateKey.getState(state);
|
|
691
647
|
var mediaLinkingState = (0, _linking2.getMediaLinkingState)(state);
|
|
692
|
-
var
|
|
693
|
-
hoverDecoration =
|
|
648
|
+
var _ref3 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d4 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
|
|
649
|
+
hoverDecoration = _ref3.hoverDecoration;
|
|
694
650
|
if (!mediaPluginState) {
|
|
695
651
|
return;
|
|
696
652
|
}
|
|
@@ -718,6 +674,20 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
718
674
|
});
|
|
719
675
|
}
|
|
720
676
|
}
|
|
677
|
+
var selection = state.selection;
|
|
678
|
+
var isWithinTable = (0, _utils.hasParentNodeOfType)([state.schema.nodes.table])(selection);
|
|
679
|
+
if (allowAdvancedToolBarOptions && allowResizing && (!isWithinTable || allowResizingInTables === true) && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_media_extended_resize_experience')) {
|
|
680
|
+
var mediaPixelResizingPluginState = (0, _pixelResizing.getPluginState)(state);
|
|
681
|
+
if (mediaPixelResizingPluginState !== null && mediaPixelResizingPluginState !== void 0 && mediaPixelResizingPluginState.isPixelEditorOpen) {
|
|
682
|
+
return (0, _pixelResizing2.getPixelResizingToolbar)(baseToolbar, {
|
|
683
|
+
intl: intl,
|
|
684
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
685
|
+
pluginState: mediaPluginState,
|
|
686
|
+
hoverDecoration: hoverDecoration,
|
|
687
|
+
isEditorFullWidthEnabled: options.fullWidthEnabled
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
}
|
|
721
691
|
var items = [];
|
|
722
692
|
var parentMediaGroupNode = (0, _utils.findParentNodeOfType)(mediaGroup)(state.selection);
|
|
723
693
|
var selectedNodeType;
|
|
@@ -725,7 +695,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
725
695
|
selectedNodeType = state.selection.node.type;
|
|
726
696
|
}
|
|
727
697
|
if (allowMediaInline && (parentMediaGroupNode === null || parentMediaGroupNode === void 0 ? void 0 : parentMediaGroupNode.node.type) === mediaGroup) {
|
|
728
|
-
var _pluginInjectionApi$
|
|
698
|
+
var _pluginInjectionApi$a8, _pluginInjectionApi$f2;
|
|
729
699
|
var mediaOffset = state.selection.$from.parentOffset + 1;
|
|
730
700
|
baseToolbar.getDomRef = function () {
|
|
731
701
|
var _mediaPluginState$ele;
|
|
@@ -734,7 +704,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
734
704
|
// eslint-disable-next-line @atlaskit/editor/no-as-casting
|
|
735
705
|
return (_mediaPluginState$ele = mediaPluginState.element) === null || _mediaPluginState$ele === void 0 ? void 0 : _mediaPluginState$ele.querySelector(selector);
|
|
736
706
|
};
|
|
737
|
-
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
707
|
+
items = generateMediaCardFloatingToolbar(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a8 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a8 === void 0 ? void 0 : _pluginInjectionApi$a8.actions, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 ? void 0 : _pluginInjectionApi$f2.forceFocusSelector, isViewOnly);
|
|
738
708
|
} else if (allowMediaInline && selectedNodeType && selectedNodeType === mediaInline) {
|
|
739
709
|
items = (0, _mediaInline2.generateMediaInlineFloatingToolbar)(state, intl, mediaPluginState, hoverDecoration, pluginInjectionApi, options);
|
|
740
710
|
} else {
|
|
@@ -748,7 +718,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
748
718
|
items = generateMediaSingleFloatingToolbar(state, intl, options, mediaPluginState, mediaLinkingState, pluginInjectionApi);
|
|
749
719
|
}
|
|
750
720
|
if (!mediaPluginState.isResizing && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
751
|
-
var _pluginInjectionApi$
|
|
721
|
+
var _pluginInjectionApi$a9;
|
|
752
722
|
var lastItem = items.at(-1);
|
|
753
723
|
if ((lastItem === null || lastItem === void 0 ? void 0 : lastItem.type) === 'separator') {
|
|
754
724
|
lastItem.fullHeight = true;
|
|
@@ -763,39 +733,35 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
763
733
|
type: 'overflow-dropdown',
|
|
764
734
|
options: [].concat((0, _toConsumableArray2.default)((0, _linking3.getLinkingDropdownOptions)(state, intl, mediaLinkingState, allowMediaInline && selectedNodeType && selectedNodeType === mediaInline, allowLinking, isViewOnly)), [{
|
|
765
735
|
title: altTextTitle,
|
|
766
|
-
onClick: (0, _commands.openMediaAltTextMenu)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
736
|
+
onClick: (0, _commands.openMediaAltTextMenu)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a9 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a9 === void 0 ? void 0 : _pluginInjectionApi$a9.actions),
|
|
767
737
|
icon: /*#__PURE__*/_react.default.createElement(_text.default, {
|
|
768
|
-
label:
|
|
738
|
+
label: ""
|
|
769
739
|
})
|
|
770
740
|
}, {
|
|
771
741
|
title: 'Resize',
|
|
772
|
-
onClick:
|
|
773
|
-
// Ignored via go/ees007
|
|
774
|
-
// eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
|
|
775
|
-
// TODO open resize dialog?
|
|
776
|
-
return true;
|
|
777
|
-
},
|
|
742
|
+
onClick: (0, _commands2.openPixelEditor)(),
|
|
778
743
|
icon: /*#__PURE__*/_react.default.createElement(_growHorizontal.default, {
|
|
779
|
-
label: "
|
|
780
|
-
})
|
|
744
|
+
label: ""
|
|
745
|
+
}),
|
|
746
|
+
testId: 'media-pixel-resizing-dropdown-option'
|
|
781
747
|
}, {
|
|
782
748
|
type: 'separator'
|
|
783
749
|
}, {
|
|
784
750
|
title: 'Copy',
|
|
785
751
|
onClick: function onClick() {
|
|
786
|
-
var _pluginInjectionApi$
|
|
787
|
-
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$
|
|
752
|
+
var _pluginInjectionApi$c4, _pluginInjectionApi$f3;
|
|
753
|
+
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c4 = pluginInjectionApi.core) === null || _pluginInjectionApi$c4 === void 0 || _pluginInjectionApi$c4.actions.execute( // @ts-ignore
|
|
788
754
|
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f3 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f3 === void 0 ? void 0 : _pluginInjectionApi$f3.commands.copyNode(nodeType));
|
|
789
755
|
return true;
|
|
790
756
|
},
|
|
791
757
|
icon: /*#__PURE__*/_react.default.createElement(_copy.default, {
|
|
792
|
-
label: "
|
|
758
|
+
label: ""
|
|
793
759
|
})
|
|
794
760
|
}, {
|
|
795
761
|
title: 'Delete',
|
|
796
762
|
onClick: remove,
|
|
797
763
|
icon: /*#__PURE__*/_react.default.createElement(_delete.default, {
|
|
798
|
-
label: "
|
|
764
|
+
label: ""
|
|
799
765
|
})
|
|
800
766
|
}])
|
|
801
767
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getPixelResizingToolbar = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _ui = require("../../pm-plugins/pixel-resizing/ui");
|
|
11
|
+
var _constants = require("../../pm-plugins/pixel-resizing/ui/constants");
|
|
12
|
+
var _utils = require("./utils");
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
15
|
+
var getPixelResizingToolbar = exports.getPixelResizingToolbar = function getPixelResizingToolbar(toolbarBaseConfig, _ref) {
|
|
16
|
+
var pluginInjectionApi = _ref.pluginInjectionApi,
|
|
17
|
+
intl = _ref.intl,
|
|
18
|
+
pluginState = _ref.pluginState,
|
|
19
|
+
hoverDecoration = _ref.hoverDecoration,
|
|
20
|
+
isEditorFullWidthEnabled = _ref.isEditorFullWidthEnabled;
|
|
21
|
+
return _objectSpread(_objectSpread({}, toolbarBaseConfig), {}, {
|
|
22
|
+
width: _constants.PIXEL_RESIZING_TOOLBAR_WIDTH,
|
|
23
|
+
scrollable: true,
|
|
24
|
+
items: [{
|
|
25
|
+
type: 'custom',
|
|
26
|
+
fallback: [],
|
|
27
|
+
render: function render(editorView) {
|
|
28
|
+
if (!editorView) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
var selectedMediaSingleNode = (0, _utils.getSelectedMediaSingle)(editorView.state);
|
|
32
|
+
if (!editorView || !selectedMediaSingleNode) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/_react.default.createElement(_ui.PixelEntry, {
|
|
36
|
+
editorView: editorView,
|
|
37
|
+
intl: intl,
|
|
38
|
+
selectedMediaSingleNode: selectedMediaSingleNode,
|
|
39
|
+
pluginInjectionApi: pluginInjectionApi,
|
|
40
|
+
pluginState: pluginState,
|
|
41
|
+
hoverDecoration: hoverDecoration,
|
|
42
|
+
isEditorFullWidthEnabled: isEditorFullWidthEnabled
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}]
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -24,6 +24,7 @@ import keymapMediaSinglePlugin from './pm-plugins/keymap-media';
|
|
|
24
24
|
import linkingPlugin from './pm-plugins/linking';
|
|
25
25
|
import keymapLinkingPlugin from './pm-plugins/linking/keymap';
|
|
26
26
|
import { createPlugin } from './pm-plugins/main';
|
|
27
|
+
import { createPlugin as createMediaPixelResizingPlugin } from './pm-plugins/pixel-resizing';
|
|
27
28
|
import { stateKey } from './pm-plugins/plugin-key';
|
|
28
29
|
import { createMediaIdentifierArray, extractMediaNodes } from './pm-plugins/utils/media-common';
|
|
29
30
|
import { insertMediaAsMediaSingle } from './pm-plugins/utils/media-single';
|
|
@@ -236,6 +237,12 @@ export const mediaPlugin = ({
|
|
|
236
237
|
}) => keymapLinkingPlugin(schema)
|
|
237
238
|
});
|
|
238
239
|
}
|
|
240
|
+
if (options && options.allowAdvancedToolBarOptions && options.allowResizing && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_media_extended_resize_experience')) {
|
|
241
|
+
pmPlugins.push({
|
|
242
|
+
name: 'mediaPixelResizing',
|
|
243
|
+
plugin: createMediaPixelResizingPlugin
|
|
244
|
+
});
|
|
245
|
+
}
|
|
239
246
|
pmPlugins.push({
|
|
240
247
|
name: 'mediaSelectionHandler',
|
|
241
248
|
plugin: () => {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createCommand } from './index';
|
|
2
|
+
export const openPixelEditor = () => {
|
|
3
|
+
return createCommand({
|
|
4
|
+
type: 'openPixelEditor'
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
export const closePixelEditor = () => {
|
|
8
|
+
return createCommand({
|
|
9
|
+
type: 'closePixelEditor'
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export const closePixelEditorAndSave = saveTransform => {
|
|
13
|
+
return createCommand({
|
|
14
|
+
type: 'closePixelEditor'
|
|
15
|
+
}, saveTransform);
|
|
16
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
|
+
import { pluginFactory } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import reducer from './reducer';
|
|
5
|
+
const pluginKey = new PluginKey('mediaPixelResizingPlugin');
|
|
6
|
+
const {
|
|
7
|
+
createPluginState,
|
|
8
|
+
createCommand,
|
|
9
|
+
getPluginState
|
|
10
|
+
} = pluginFactory(pluginKey, reducer, {
|
|
11
|
+
onSelectionChanged() {
|
|
12
|
+
return {
|
|
13
|
+
isPixelEditorOpen: false
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
export const createPlugin = ({
|
|
18
|
+
dispatch
|
|
19
|
+
}) => {
|
|
20
|
+
return new SafePlugin({
|
|
21
|
+
state: createPluginState(dispatch, {
|
|
22
|
+
isPixelEditorOpen: false
|
|
23
|
+
}),
|
|
24
|
+
key: pluginKey
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export { createCommand, getPluginState };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default ((state, action) => {
|
|
2
|
+
switch (action.type) {
|
|
3
|
+
case 'openPixelEditor':
|
|
4
|
+
{
|
|
5
|
+
return {
|
|
6
|
+
...state,
|
|
7
|
+
isPixelEditorOpen: true
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
case 'closePixelEditor':
|
|
11
|
+
{
|
|
12
|
+
return {
|
|
13
|
+
...state,
|
|
14
|
+
isPixelEditorOpen: false
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
default:
|
|
18
|
+
return state;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
|
+
import { jsx } from '@emotion/react';
|
|
9
|
+
import { pixelEntryMessages as messages } from '@atlaskit/editor-common/media';
|
|
10
|
+
import { calcMinWidth, DEFAULT_IMAGE_HEIGHT, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
|
|
11
|
+
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
12
|
+
import { hasParentNode } from '@atlaskit/editor-prosemirror/utils';
|
|
13
|
+
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
14
|
+
import { Text } from '@atlaskit/primitives';
|
|
15
|
+
import { updateMediaSingleWidthTr } from '../../../ui/toolbar/commands';
|
|
16
|
+
import { getPixelWidthOfElement, calcNewLayout } from '../../../ui/toolbar/utils';
|
|
17
|
+
import { isVideo } from '../../utils/media-single';
|
|
18
|
+
import { closePixelEditorAndSave } from '../commands';
|
|
19
|
+
import { PixelEntryComponent } from './pixel-entry';
|
|
20
|
+
import { pixelSizingFullWidthLabelStyles } from './styles';
|
|
21
|
+
export const PixelEntry = ({
|
|
22
|
+
editorView,
|
|
23
|
+
selectedMediaSingleNode,
|
|
24
|
+
pluginInjectionApi,
|
|
25
|
+
intl,
|
|
26
|
+
pluginState,
|
|
27
|
+
hoverDecoration,
|
|
28
|
+
isEditorFullWidthEnabled
|
|
29
|
+
}) => {
|
|
30
|
+
var _pluginInjectionApi$w, _pluginInjectionApi$m, _pluginInjectionApi$m2;
|
|
31
|
+
const {
|
|
32
|
+
state,
|
|
33
|
+
dispatch
|
|
34
|
+
} = editorView;
|
|
35
|
+
const {
|
|
36
|
+
mediaSingle
|
|
37
|
+
} = state.schema.nodes;
|
|
38
|
+
const contentWidth = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$w = pluginInjectionApi.width.sharedState.currentState()) === null || _pluginInjectionApi$w === void 0 ? void 0 : _pluginInjectionApi$w.lineLength) || akEditorDefaultLayoutWidth;
|
|
39
|
+
const {
|
|
40
|
+
width: mediaSingleWidth,
|
|
41
|
+
widthType,
|
|
42
|
+
layout
|
|
43
|
+
} = selectedMediaSingleNode.node.attrs;
|
|
44
|
+
|
|
45
|
+
// hasParentNode will return falsey value if selection depth === 0
|
|
46
|
+
const isNested = hasParentNode(n => n.type !== state.schema.nodes.doc)(state.selection);
|
|
47
|
+
const updateNodeWithTr = useCallback((width, validation) => {
|
|
48
|
+
var _pluginInjectionApi$a;
|
|
49
|
+
const newLayout = calcNewLayout(width, layout, contentWidth, isEditorFullWidthEnabled, isNested);
|
|
50
|
+
return updateMediaSingleWidthTr(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions, state, width, validation, 'floatingToolBar', newLayout);
|
|
51
|
+
}, [layout, contentWidth, isEditorFullWidthEnabled, isNested, state, pluginInjectionApi]);
|
|
52
|
+
const selectedMediaNode = selectedMediaSingleNode.node.content.firstChild;
|
|
53
|
+
if (!selectedMediaNode) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const {
|
|
57
|
+
width: mediaWidth,
|
|
58
|
+
height: mediaHeight
|
|
59
|
+
} = selectedMediaNode.attrs;
|
|
60
|
+
const maxWidthForNestedNode = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$m = pluginInjectionApi.media) === null || _pluginInjectionApi$m === void 0 ? void 0 : (_pluginInjectionApi$m2 = _pluginInjectionApi$m.sharedState.currentState()) === null || _pluginInjectionApi$m2 === void 0 ? void 0 : _pluginInjectionApi$m2.currentMaxWidth;
|
|
61
|
+
const maxWidth = maxWidthForNestedNode || akEditorFullWidthLayoutWidth;
|
|
62
|
+
const isVideoFile = isVideo(selectedMediaNode.attrs.__fileMimeType);
|
|
63
|
+
const minWidth = calcMinWidth(isVideoFile, maxWidthForNestedNode || contentWidth);
|
|
64
|
+
const hasPixelType = widthType === 'pixel';
|
|
65
|
+
const pixelWidthFromElement = getPixelWidthOfElement(editorView, selectedMediaSingleNode.pos + 1,
|
|
66
|
+
// get pos of media node
|
|
67
|
+
mediaWidth || DEFAULT_IMAGE_WIDTH);
|
|
68
|
+
const pixelWidth = hasPixelType ? mediaSingleWidth : pixelWidthFromElement;
|
|
69
|
+
return jsx(PixelEntryComponent, {
|
|
70
|
+
intl: intl,
|
|
71
|
+
width: pluginState.isResizing ? pluginState.resizingWidth : pixelWidth,
|
|
72
|
+
showMigration: !pluginState.isResizing && !hasPixelType,
|
|
73
|
+
mediaWidth: mediaWidth || DEFAULT_IMAGE_WIDTH,
|
|
74
|
+
mediaHeight: mediaHeight || DEFAULT_IMAGE_HEIGHT,
|
|
75
|
+
minWidth: minWidth,
|
|
76
|
+
maxWidth: maxWidth,
|
|
77
|
+
onChange: valid => {
|
|
78
|
+
if (valid) {
|
|
79
|
+
hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, true, 'warning')(editorView.state, dispatch, editorView);
|
|
80
|
+
} else {
|
|
81
|
+
hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(mediaSingle, false)(editorView.state, dispatch, editorView);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onSubmit: ({
|
|
85
|
+
width,
|
|
86
|
+
validation
|
|
87
|
+
}) => {
|
|
88
|
+
const tr = updateNodeWithTr(width, validation);
|
|
89
|
+
if (tr) {
|
|
90
|
+
dispatch(tr);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
onMigrate: () => {
|
|
94
|
+
const tr = state.tr.setNodeMarkup(selectedMediaSingleNode.pos, undefined, {
|
|
95
|
+
...selectedMediaSingleNode.node.attrs,
|
|
96
|
+
width: pixelWidthFromElement,
|
|
97
|
+
widthType: 'pixel'
|
|
98
|
+
});
|
|
99
|
+
tr.setMeta('scrollIntoView', false);
|
|
100
|
+
tr.setSelection(NodeSelection.create(tr.doc, selectedMediaSingleNode.pos));
|
|
101
|
+
dispatch(tr);
|
|
102
|
+
},
|
|
103
|
+
onCloseAndSave: ({
|
|
104
|
+
width,
|
|
105
|
+
validation
|
|
106
|
+
}) => {
|
|
107
|
+
const tr = updateNodeWithTr(width, validation);
|
|
108
|
+
if (tr) {
|
|
109
|
+
return closePixelEditorAndSave(() => tr)(state, dispatch);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
isViewMode: pluginState.isResizing
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
export const FullWidthDisplay = ({
|
|
116
|
+
intl: {
|
|
117
|
+
formatMessage
|
|
118
|
+
}
|
|
119
|
+
}) => {
|
|
120
|
+
return (
|
|
121
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
|
|
122
|
+
jsx("div", {
|
|
123
|
+
css: pixelSizingFullWidthLabelStyles
|
|
124
|
+
}, jsx(Text, null, formatMessage(messages.fullWidthLabel)))
|
|
125
|
+
);
|
|
126
|
+
};
|