@atlaskit/editor-plugin-media 4.0.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cjs/nodeviews/lazy-media-group.js +1 -3
- package/dist/cjs/nodeviews/lazy-media-inline.js +1 -3
- package/dist/cjs/nodeviews/mediaGroup.js +16 -323
- package/dist/cjs/nodeviews/mediaSingle.js +47 -593
- package/dist/cjs/pm-plugins/alt-text/ui/AltTextEdit.js +2 -3
- package/dist/cjs/pm-plugins/pixel-resizing/ui/pixel-entry.js +1 -1
- package/dist/cjs/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +67 -649
- package/dist/cjs/ui/toolbar/alt-text.js +1 -2
- package/dist/cjs/ui/toolbar/index.js +4 -12
- package/dist/cjs/ui/toolbar/linking.js +3 -4
- package/dist/cjs/ui/toolbar/mediaInline.js +2 -6
- package/dist/cjs/ui/toolbar/pixel-resizing.js +1 -5
- package/dist/es2019/nodeviews/lazy-media-group.js +1 -3
- package/dist/es2019/nodeviews/lazy-media-inline.js +1 -3
- package/dist/es2019/nodeviews/mediaGroup.js +1 -272
- package/dist/es2019/nodeviews/mediaSingle.js +6 -477
- package/dist/es2019/pm-plugins/alt-text/ui/AltTextEdit.js +2 -3
- package/dist/es2019/pm-plugins/pixel-resizing/ui/pixel-entry.js +1 -1
- package/dist/es2019/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +2 -510
- package/dist/es2019/ui/toolbar/alt-text.js +1 -2
- package/dist/es2019/ui/toolbar/index.js +4 -12
- package/dist/es2019/ui/toolbar/linking.js +3 -4
- package/dist/es2019/ui/toolbar/mediaInline.js +2 -6
- package/dist/es2019/ui/toolbar/pixel-resizing.js +1 -5
- package/dist/esm/nodeviews/lazy-media-group.js +1 -3
- package/dist/esm/nodeviews/lazy-media-inline.js +1 -3
- package/dist/esm/nodeviews/mediaGroup.js +15 -322
- package/dist/esm/nodeviews/mediaSingle.js +47 -593
- package/dist/esm/pm-plugins/alt-text/ui/AltTextEdit.js +2 -3
- package/dist/esm/pm-plugins/pixel-resizing/ui/pixel-entry.js +1 -1
- package/dist/esm/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +64 -650
- package/dist/esm/ui/toolbar/alt-text.js +1 -2
- package/dist/esm/ui/toolbar/index.js +4 -12
- package/dist/esm/ui/toolbar/linking.js +3 -4
- package/dist/esm/ui/toolbar/mediaInline.js +2 -6
- package/dist/esm/ui/toolbar/pixel-resizing.js +1 -5
- package/dist/types/nodeviews/__mocks__/mediaNodeUpdater.d.ts +1 -0
- package/dist/types/nodeviews/mediaGroup.d.ts +2 -23
- package/dist/types/nodeviews/mediaSingle.d.ts +2 -38
- package/dist/types/nodeviews/mediaSingleNext.d.ts +1 -2
- package/dist/types-ts4.5/nodeviews/__mocks__/mediaNodeUpdater.d.ts +1 -0
- package/dist/types-ts4.5/nodeviews/mediaGroup.d.ts +2 -23
- package/dist/types-ts4.5/nodeviews/mediaSingle.d.ts +2 -38
- package/dist/types-ts4.5/nodeviews/mediaSingleNext.d.ts +1 -2
- package/package.json +4 -16
|
@@ -13,7 +13,6 @@ var _styles = require("@atlaskit/editor-common/styles");
|
|
|
13
13
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
14
14
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
15
15
|
var _text = _interopRequireDefault(require("@atlaskit/icon/core/text"));
|
|
16
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
16
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
18
17
|
var _commands = require("../../pm-plugins/alt-text/commands");
|
|
19
18
|
var _AltTextEdit = _interopRequireDefault(require("../../pm-plugins/alt-text/ui/AltTextEdit"));
|
|
@@ -61,7 +60,7 @@ var altTextEditComponent = function altTextEditComponent(options) {
|
|
|
61
60
|
var _options$forceFocusSe;
|
|
62
61
|
var tr = view.state.tr,
|
|
63
62
|
dispatch = view.dispatch;
|
|
64
|
-
var elementSelector = options !== null && options !== void 0 && options.triggerButtonSelector && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')
|
|
63
|
+
var elementSelector = options !== null && options !== void 0 && options.triggerButtonSelector && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? options.triggerButtonSelector : "[data-testid=\"".concat(testId, "\"]");
|
|
65
64
|
var newTr = options === null || options === void 0 || (_options$forceFocusSe = options.forceFocusSelector) === null || _options$forceFocusSe === void 0 ? void 0 : _options$forceFocusSe.call(options, elementSelector)(tr);
|
|
66
65
|
if (newTr) {
|
|
67
66
|
dispatch(newTr);
|
|
@@ -435,7 +435,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
435
435
|
icon: /*#__PURE__*/_react.default.createElement(_imageInline.default, {
|
|
436
436
|
color: "currentColor",
|
|
437
437
|
spacing: "spacious",
|
|
438
|
-
label:
|
|
438
|
+
label: ""
|
|
439
439
|
}),
|
|
440
440
|
tooltip: hasCaption ? inlineSwitcherTitle : undefined
|
|
441
441
|
}, {
|
|
@@ -445,14 +445,10 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
445
445
|
onClick: function onClick() {
|
|
446
446
|
return true;
|
|
447
447
|
},
|
|
448
|
-
icon:
|
|
448
|
+
icon: /*#__PURE__*/_react.default.createElement(_maximize.default, {
|
|
449
449
|
color: "currentColor",
|
|
450
450
|
spacing: "spacious",
|
|
451
451
|
label: ""
|
|
452
|
-
}) : /*#__PURE__*/_react.default.createElement(_imageFullscreen.default, {
|
|
453
|
-
color: "currentColor",
|
|
454
|
-
spacing: "spacious",
|
|
455
|
-
label: (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') ? '' : floatingSwitcherTitle
|
|
456
452
|
})
|
|
457
453
|
}];
|
|
458
454
|
var switchFromBlockToInline;
|
|
@@ -466,11 +462,7 @@ var generateMediaSingleFloatingToolbar = function generateMediaSingleFloatingToo
|
|
|
466
462
|
options: _options2,
|
|
467
463
|
title: intl.formatMessage(_mediaUi.messages.sizeOptions),
|
|
468
464
|
icon: function icon() {
|
|
469
|
-
return
|
|
470
|
-
color: "currentColor",
|
|
471
|
-
spacing: "spacious",
|
|
472
|
-
label: intl.formatMessage(_mediaUi.messages.sizeOptions)
|
|
473
|
-
}) : /*#__PURE__*/_react.default.createElement(_imageFullscreen.default, {
|
|
465
|
+
return /*#__PURE__*/_react.default.createElement(_maximize.default, {
|
|
474
466
|
color: "currentColor",
|
|
475
467
|
spacing: "spacious",
|
|
476
468
|
label: intl.formatMessage(_mediaUi.messages.sizeOptions)
|
|
@@ -783,7 +775,7 @@ var floatingToolbar = exports.floatingToolbar = function floatingToolbar(state,
|
|
|
783
775
|
|
|
784
776
|
// testId is required to show focus on trigger button on ESC key press
|
|
785
777
|
// see hideOnEsc in platform/packages/editor/editor-plugin-floating-toolbar/src/ui/Dropdown.tsx
|
|
786
|
-
var overflowButtonSelector = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')
|
|
778
|
+
var overflowButtonSelector = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? "[data-testid=\"".concat(overflowDropdwonBtnTriggerTestId, "\"]") : undefined;
|
|
787
779
|
if (allowAltTextOnImages) {
|
|
788
780
|
var mediaAltTextPluginState = (0, _altText.getPluginState)(state);
|
|
789
781
|
if (mediaAltTextPluginState.isAltTextEditorOpen) {
|
|
@@ -14,7 +14,6 @@ var _messages = require("@atlaskit/editor-common/messages");
|
|
|
14
14
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
15
15
|
var _link = _interopRequireDefault(require("@atlaskit/icon/core/link"));
|
|
16
16
|
var _linkExternal = _interopRequireDefault(require("@atlaskit/icon/core/link-external"));
|
|
17
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
17
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
19
18
|
var _linking = require("../../pm-plugins/commands/linking");
|
|
20
19
|
var _linking2 = require("../../pm-plugins/linking");
|
|
@@ -63,7 +62,7 @@ var getLinkingToolbar = exports.getLinkingToolbar = function getLinkingToolbar(t
|
|
|
63
62
|
return null;
|
|
64
63
|
}
|
|
65
64
|
var setFocusOnFloatingToolbar = function setFocusOnFloatingToolbar(setFocus) {
|
|
66
|
-
if (setFocus && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')
|
|
65
|
+
if (setFocus && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
67
66
|
var _pluginInjectionApi$f;
|
|
68
67
|
var tr = view.state.tr,
|
|
69
68
|
dispatch = view.dispatch;
|
|
@@ -98,7 +97,7 @@ var getLinkingToolbar = exports.getLinkingToolbar = function getLinkingToolbar(t
|
|
|
98
97
|
*/
|
|
99
98
|
var tr = view.state.tr,
|
|
100
99
|
dispatch = view.dispatch;
|
|
101
|
-
var selector = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')
|
|
100
|
+
var selector = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? FORCE_FOCUS_SELECTOR_EDITOR_CONTROLS : FORCE_FOCUS_SELECTOR;
|
|
102
101
|
pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$f2 = pluginInjectionApi.floatingToolbar) === null || _pluginInjectionApi$f2 === void 0 || (_pluginInjectionApi$f2 = _pluginInjectionApi$f2.actions) === null || _pluginInjectionApi$f2 === void 0 || _pluginInjectionApi$f2.forceFocusSelector(selector)(tr);
|
|
103
102
|
dispatch(tr);
|
|
104
103
|
},
|
|
@@ -152,7 +151,7 @@ var getLinkingDropdownOptions = exports.getLinkingDropdownOptions = function get
|
|
|
152
151
|
return true;
|
|
153
152
|
},
|
|
154
153
|
icon: /*#__PURE__*/_react.default.createElement(_link.default, {
|
|
155
|
-
label:
|
|
154
|
+
label: ""
|
|
156
155
|
})
|
|
157
156
|
}];
|
|
158
157
|
} else {
|
|
@@ -321,20 +321,16 @@ var getMediaInlineImageToolbar = function getMediaInlineImageToolbar(state, intl
|
|
|
321
321
|
icon: /*#__PURE__*/_react.default.createElement(_imageInline.default, {
|
|
322
322
|
color: "currentColor",
|
|
323
323
|
spacing: "spacious",
|
|
324
|
-
label:
|
|
324
|
+
label: ""
|
|
325
325
|
})
|
|
326
326
|
}, {
|
|
327
327
|
id: 'editor.media.convert.mediasingle',
|
|
328
328
|
title: mediaSingleTitle,
|
|
329
329
|
onClick: (0, _commands.changeMediaInlineToMediaSingle)(editorAnalyticsAPI, widthPluginState),
|
|
330
|
-
icon:
|
|
330
|
+
icon: /*#__PURE__*/_react.default.createElement(_maximize.default, {
|
|
331
331
|
color: "currentColor",
|
|
332
332
|
spacing: "spacious",
|
|
333
333
|
label: ""
|
|
334
|
-
}) : /*#__PURE__*/_react.default.createElement(_imageFullscreen.default, {
|
|
335
|
-
color: "currentColor",
|
|
336
|
-
spacing: "spacious",
|
|
337
|
-
label: (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') ? '' : mediaSingleTitle
|
|
338
334
|
})
|
|
339
335
|
}];
|
|
340
336
|
var switchFromInlineToBlock;
|
|
@@ -9,9 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _media = require("@atlaskit/editor-common/media");
|
|
11
11
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
12
|
-
var _growHorizontal = _interopRequireDefault(require("@atlaskit/icon/core/grow-horizontal"));
|
|
13
12
|
var _imageFullscreen = _interopRequireDefault(require("@atlaskit/icon/core/image-fullscreen"));
|
|
14
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
13
|
var _commands = require("../../pm-plugins/pixel-resizing/commands");
|
|
16
14
|
var _ui = require("../../pm-plugins/pixel-resizing/ui");
|
|
17
15
|
var _constants = require("../../pm-plugins/pixel-resizing/ui/constants");
|
|
@@ -66,9 +64,7 @@ var getResizeDropdownOption = exports.getResizeDropdownOption = function getResi
|
|
|
66
64
|
return [{
|
|
67
65
|
title: formatMessage(_media.pixelEntryMessages.resizeOption),
|
|
68
66
|
onClick: (0, _commands.openPixelEditor)(),
|
|
69
|
-
icon:
|
|
70
|
-
label: ""
|
|
71
|
-
}) : /*#__PURE__*/_react.default.createElement(_growHorizontal.default, {
|
|
67
|
+
icon: /*#__PURE__*/_react.default.createElement(_imageFullscreen.default, {
|
|
72
68
|
label: ""
|
|
73
69
|
}),
|
|
74
70
|
testId: 'media-pixel-resizing-dropdown-option'
|
|
@@ -2,9 +2,7 @@ import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
|
|
|
2
2
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
3
3
|
import { ReactMediaGroupNode } from './mediaGroup';
|
|
4
4
|
export const lazyMediaGroupView = (portalProviderAPI, eventDispatcher, providerFactory, options = {}, api) => {
|
|
5
|
-
if (editorExperiment('platform_editor_exp_lazy_node_views', false)
|
|
6
|
-
exposure: true
|
|
7
|
-
})) {
|
|
5
|
+
if (editorExperiment('platform_editor_exp_lazy_node_views', false)) {
|
|
8
6
|
return ReactMediaGroupNode(portalProviderAPI, eventDispatcher, providerFactory, options, api);
|
|
9
7
|
}
|
|
10
8
|
return withLazyLoading({
|
|
@@ -2,9 +2,7 @@ import { withLazyLoading } from '@atlaskit/editor-common/lazy-node-view';
|
|
|
2
2
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
3
3
|
import { ReactMediaInlineNode } from './mediaInline';
|
|
4
4
|
export const lazyMediaInlineView = (portalProviderAPI, eventDispatcher, providerFactory, api, dispatchAnalyticsEvent) => {
|
|
5
|
-
if (editorExperiment('platform_editor_exp_lazy_node_views', false)
|
|
6
|
-
exposure: true
|
|
7
|
-
})) {
|
|
5
|
+
if (editorExperiment('platform_editor_exp_lazy_node_views', false)) {
|
|
8
6
|
return ReactMediaInlineNode(portalProviderAPI, eventDispatcher, providerFactory, api, dispatchAnalyticsEvent);
|
|
9
7
|
}
|
|
10
8
|
return withLazyLoading({
|
|
@@ -1,264 +1,10 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import { injectIntl } from 'react-intl-next';
|
|
4
2
|
import { sharedPluginStateHookMigratorFactory, useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
5
|
-
import { nodeViewsMessages as messages } from '@atlaskit/editor-common/media';
|
|
6
3
|
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
7
4
|
import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
8
5
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
9
|
-
import { isNodeSelectedOrInRange, SelectedState, setNodeSelection } from '@atlaskit/editor-common/utils';
|
|
10
|
-
import EditorCloseIcon from '@atlaskit/icon/core/migration/close--editor-close';
|
|
11
|
-
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
12
|
-
import { Filmstrip } from '@atlaskit/media-filmstrip';
|
|
13
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
15
|
-
import { stateKey as mediaStateKey } from '../pm-plugins/plugin-key';
|
|
16
6
|
import { useMediaProvider } from '../ui/hooks/useMediaProvider';
|
|
17
7
|
import { MediaGroupNext } from './mediaGroupNext';
|
|
18
|
-
import { MediaNodeUpdater } from './mediaNodeUpdater';
|
|
19
|
-
const isMediaGroupSelectedFromProps = props => {
|
|
20
|
-
/**
|
|
21
|
-
* ED-19831
|
|
22
|
-
* There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
|
|
23
|
-
* directly to confluence since this bug is now in production.
|
|
24
|
-
*/
|
|
25
|
-
let pos;
|
|
26
|
-
try {
|
|
27
|
-
pos = props.getPos ? props.getPos() : undefined;
|
|
28
|
-
} catch (e) {
|
|
29
|
-
pos = undefined;
|
|
30
|
-
}
|
|
31
|
-
if (typeof pos !== 'number') {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
return isNodeSelectedOrInRange(props.anchorPos, props.headPos, pos, props.node.nodeSize);
|
|
35
|
-
};
|
|
36
|
-
const hasSelectionChanged = (oldProps, newProps) => {
|
|
37
|
-
if (isMediaGroupSelectedFromProps(oldProps) !== isMediaGroupSelectedFromProps(newProps)) {
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
if (isMediaGroupSelectedFromProps(newProps) === SelectedState.selectedInside) {
|
|
41
|
-
return oldProps.anchorPos !== newProps.anchorPos;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
47
|
-
class MediaGroup extends React.Component {
|
|
48
|
-
constructor(_props) {
|
|
49
|
-
super(_props);
|
|
50
|
-
_defineProperty(this, "state", {
|
|
51
|
-
viewMediaClientConfig: undefined
|
|
52
|
-
});
|
|
53
|
-
_defineProperty(this, "updateNodeAttrs", (props, node, getPos) => {
|
|
54
|
-
const {
|
|
55
|
-
view,
|
|
56
|
-
mediaProvider,
|
|
57
|
-
contextIdentifierProvider
|
|
58
|
-
} = props;
|
|
59
|
-
const mediaNodeUpdater = new MediaNodeUpdater({
|
|
60
|
-
view,
|
|
61
|
-
mediaProvider,
|
|
62
|
-
contextIdentifierProvider,
|
|
63
|
-
node,
|
|
64
|
-
isMediaSingle: false
|
|
65
|
-
});
|
|
66
|
-
mediaNodeUpdater.updateNodeAttrs(getPos);
|
|
67
|
-
});
|
|
68
|
-
_defineProperty(this, "setMediaItems", (props, updatedAttrs = false) => {
|
|
69
|
-
var _this$mediaPluginStat;
|
|
70
|
-
const {
|
|
71
|
-
node
|
|
72
|
-
} = props;
|
|
73
|
-
const oldMediaNodes = this.mediaNodes;
|
|
74
|
-
this.mediaNodes = [];
|
|
75
|
-
node.forEach((item, childOffset) => {
|
|
76
|
-
const getPos = () => {
|
|
77
|
-
const pos = props.getPos();
|
|
78
|
-
if (typeof pos !== 'number') {
|
|
79
|
-
// That may seems weird, but the previous type wasn't match with the real ProseMirror code. And a lot of Media API was built expecting a number
|
|
80
|
-
// Because the original code would return NaN on runtime
|
|
81
|
-
// We are just make it explict now.
|
|
82
|
-
// We may run a deep investagation on Media code to figure out a better fix. But, for now, we want to keep the current behavior.
|
|
83
|
-
// TODO: ED-13910 - prosemirror-bump leftovers
|
|
84
|
-
return NaN;
|
|
85
|
-
}
|
|
86
|
-
return pos + childOffset + 1;
|
|
87
|
-
};
|
|
88
|
-
this.mediaNodes.push(item);
|
|
89
|
-
if (updatedAttrs) {
|
|
90
|
-
this.updateNodeAttrs(props, item, getPos);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
(_this$mediaPluginStat = this.mediaPluginState) === null || _this$mediaPluginStat === void 0 ? void 0 : _this$mediaPluginStat.handleMediaGroupUpdate(oldMediaNodes, this.mediaNodes);
|
|
94
|
-
});
|
|
95
|
-
_defineProperty(this, "getIdentifier", item => {
|
|
96
|
-
if (item.attrs.type === 'external') {
|
|
97
|
-
return {
|
|
98
|
-
mediaItemType: 'external-image',
|
|
99
|
-
dataURI: item.attrs.url
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
id: item.attrs.id,
|
|
104
|
-
mediaItemType: 'file',
|
|
105
|
-
collectionName: item.attrs.collection
|
|
106
|
-
};
|
|
107
|
-
});
|
|
108
|
-
_defineProperty(this, "isNodeSelected", nodePos => {
|
|
109
|
-
const selected = isMediaGroupSelectedFromProps(this.props);
|
|
110
|
-
if (selected === SelectedState.selectedInRange) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
if (selected === SelectedState.selectedInside && this.props.anchorPos === nodePos) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
});
|
|
118
|
-
_defineProperty(this, "renderChildNodes", () => {
|
|
119
|
-
const {
|
|
120
|
-
viewMediaClientConfig
|
|
121
|
-
} = this.state;
|
|
122
|
-
const {
|
|
123
|
-
getPos,
|
|
124
|
-
allowLazyLoading,
|
|
125
|
-
disabled,
|
|
126
|
-
mediaOptions,
|
|
127
|
-
editorViewMode
|
|
128
|
-
} = this.props;
|
|
129
|
-
const items = this.mediaNodes.map((item, idx) => {
|
|
130
|
-
// We declared this to get a fresh position every time
|
|
131
|
-
const getNodePos = () => {
|
|
132
|
-
const pos = getPos();
|
|
133
|
-
if (typeof pos !== 'number') {
|
|
134
|
-
// That may seems weird, but the previous type wasn't match with the real ProseMirror code. And a lot of Media API was built expecting a number
|
|
135
|
-
// Because the original code would return NaN on runtime
|
|
136
|
-
// We are just make it explict now.
|
|
137
|
-
// We may run a deep investagation on Media code to figure out a better fix. But, for now, we want to keep the current behavior.
|
|
138
|
-
// TODO: ED-13910 - prosemirror-bump leftovers
|
|
139
|
-
return NaN;
|
|
140
|
-
}
|
|
141
|
-
return pos + idx + 1;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// Media Inline creates a floating toolbar with the same options, excludes these options if enabled
|
|
145
|
-
const mediaInlineOptions = (allowMediaInline = false) => {
|
|
146
|
-
if (!allowMediaInline) {
|
|
147
|
-
return {
|
|
148
|
-
shouldEnableDownloadButton: mediaOptions.enableDownloadButton,
|
|
149
|
-
actions: [{
|
|
150
|
-
handler: disabled || !this.mediaPluginState ? () => {} : this.mediaPluginState.handleMediaNodeRemoval.bind(null, undefined, getNodePos),
|
|
151
|
-
icon: /*#__PURE__*/React.createElement(EditorCloseIcon, {
|
|
152
|
-
label: this.props.intl.formatMessage(messages.mediaGroupDeleteLabel)
|
|
153
|
-
})
|
|
154
|
-
}]
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
return {
|
|
159
|
-
identifier: this.getIdentifier(item),
|
|
160
|
-
isLazy: allowLazyLoading,
|
|
161
|
-
selected: this.isNodeSelected(getNodePos()),
|
|
162
|
-
onClick: () => {
|
|
163
|
-
setNodeSelection(this.props.view, getNodePos());
|
|
164
|
-
},
|
|
165
|
-
...mediaInlineOptions(fg('platform_editor_remove_media_inline_feature_flag') ? mediaOptions.allowMediaInlineImages : getMediaFeatureFlag('mediaInline', mediaOptions.featureFlags))
|
|
166
|
-
};
|
|
167
|
-
});
|
|
168
|
-
return /*#__PURE__*/React.createElement(Filmstrip, {
|
|
169
|
-
items: items,
|
|
170
|
-
mediaClientConfig: viewMediaClientConfig,
|
|
171
|
-
featureFlags: mediaOptions.featureFlags,
|
|
172
|
-
shouldOpenMediaViewer: editorViewMode && editorExperiment('platform_editor_controls', 'control')
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
this.mediaNodes = [];
|
|
176
|
-
this.mediaPluginState = mediaStateKey.getState(_props.view.state);
|
|
177
|
-
this.setMediaItems(_props);
|
|
178
|
-
this.state = {
|
|
179
|
-
viewMediaClientConfig: undefined
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
componentDidMount() {
|
|
183
|
-
this.updateMediaClientConfig();
|
|
184
|
-
this.mediaNodes.forEach(async node => {
|
|
185
|
-
if (node.attrs.type === 'external') {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
const {
|
|
189
|
-
view,
|
|
190
|
-
mediaProvider,
|
|
191
|
-
contextIdentifierProvider
|
|
192
|
-
} = this.props;
|
|
193
|
-
const mediaNodeUpdater = new MediaNodeUpdater({
|
|
194
|
-
view,
|
|
195
|
-
mediaProvider,
|
|
196
|
-
contextIdentifierProvider,
|
|
197
|
-
node,
|
|
198
|
-
isMediaSingle: false
|
|
199
|
-
});
|
|
200
|
-
const getPos = () => {
|
|
201
|
-
const pos = this.props.getPos();
|
|
202
|
-
if (typeof pos !== 'number') {
|
|
203
|
-
// That may seems weird, but the previous type wasn't match with the real ProseMirror code. And a lot of Media API was built expecting a number
|
|
204
|
-
// Because the original code would return NaN on runtime
|
|
205
|
-
// We are just make it explict now.
|
|
206
|
-
// We may run a deep investagation on Media code to figure out a better fix. But, for now, we want to keep the current behavior.
|
|
207
|
-
// TODO: ED-13910 - prosemirror-bump leftovers
|
|
208
|
-
return NaN;
|
|
209
|
-
}
|
|
210
|
-
return pos + 1;
|
|
211
|
-
};
|
|
212
|
-
const contextId = mediaNodeUpdater.getNodeContextId();
|
|
213
|
-
if (!contextId) {
|
|
214
|
-
await mediaNodeUpdater.updateNodeContextId(getPos);
|
|
215
|
-
}
|
|
216
|
-
const shouldNodeBeDeepCopied = await mediaNodeUpdater.shouldNodeBeDeepCopied();
|
|
217
|
-
if (shouldNodeBeDeepCopied) {
|
|
218
|
-
await mediaNodeUpdater.copyNodeFromPos(getPos, {
|
|
219
|
-
traceId: node.attrs.__mediaTraceId
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
componentWillUnmount() {
|
|
225
|
-
var _this$mediaPluginStat2;
|
|
226
|
-
(_this$mediaPluginStat2 = this.mediaPluginState) === null || _this$mediaPluginStat2 === void 0 ? void 0 : _this$mediaPluginStat2.handleMediaGroupUpdate(this.mediaNodes, []);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Ignored via go/ees005
|
|
230
|
-
// eslint-disable-next-line react/no-unsafe
|
|
231
|
-
UNSAFE_componentWillReceiveProps(props) {
|
|
232
|
-
this.updateMediaClientConfig();
|
|
233
|
-
this.setMediaItems(props, props.isCopyPasteEnabled || props.isCopyPasteEnabled === undefined);
|
|
234
|
-
}
|
|
235
|
-
shouldComponentUpdate(nextProps) {
|
|
236
|
-
var _this$mediaPluginStat3;
|
|
237
|
-
if (hasSelectionChanged(this.props, nextProps) || this.props.node !== nextProps.node || this.state.viewMediaClientConfig !== ((_this$mediaPluginStat3 = this.mediaPluginState) === null || _this$mediaPluginStat3 === void 0 ? void 0 : _this$mediaPluginStat3.mediaClientConfig)) {
|
|
238
|
-
return true;
|
|
239
|
-
}
|
|
240
|
-
return false;
|
|
241
|
-
}
|
|
242
|
-
updateMediaClientConfig() {
|
|
243
|
-
const {
|
|
244
|
-
viewMediaClientConfig
|
|
245
|
-
} = this.state;
|
|
246
|
-
const {
|
|
247
|
-
mediaClientConfig
|
|
248
|
-
} = this.mediaPluginState || {};
|
|
249
|
-
if (!viewMediaClientConfig && mediaClientConfig) {
|
|
250
|
-
this.setState({
|
|
251
|
-
viewMediaClientConfig: mediaClientConfig
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
render() {
|
|
256
|
-
return this.renderChildNodes();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
_defineProperty(MediaGroup, "displayName", 'MediaGroup');
|
|
260
|
-
const IntlMediaGroup = injectIntl(MediaGroup);
|
|
261
|
-
export default IntlMediaGroup;
|
|
262
8
|
const useSharedState = sharedPluginStateHookMigratorFactory(pluginInjectionApi => {
|
|
263
9
|
const editorDisabled = useSharedPluginStateSelector(pluginInjectionApi, 'editorDisabled.editorDisabled');
|
|
264
10
|
const editorViewMode = useSharedPluginStateSelector(pluginInjectionApi, 'editorViewMode.mode');
|
|
@@ -314,24 +60,7 @@ class MediaGroupNodeView extends ReactNodeView {
|
|
|
314
60
|
if (!mediaProvider) {
|
|
315
61
|
return null;
|
|
316
62
|
}
|
|
317
|
-
|
|
318
|
-
return /*#__PURE__*/React.createElement(MediaGroupNext, {
|
|
319
|
-
node: this.node,
|
|
320
|
-
getPos: getPos,
|
|
321
|
-
view: this.view,
|
|
322
|
-
forwardRef: forwardRef,
|
|
323
|
-
disabled: editorDisabled,
|
|
324
|
-
allowLazyLoading: mediaOptions.allowLazyLoading,
|
|
325
|
-
mediaProvider: mediaProvider,
|
|
326
|
-
contextIdentifierProvider: contextIdentifierProvider,
|
|
327
|
-
isCopyPasteEnabled: mediaOptions.isCopyPasteEnabled,
|
|
328
|
-
anchorPos: this.view.state.selection.$anchor.pos,
|
|
329
|
-
headPos: this.view.state.selection.$head.pos,
|
|
330
|
-
mediaOptions: mediaOptions,
|
|
331
|
-
editorViewMode: editorViewMode === 'view'
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
return /*#__PURE__*/React.createElement(IntlMediaGroup, {
|
|
63
|
+
return /*#__PURE__*/React.createElement(MediaGroupNext, {
|
|
335
64
|
node: this.node,
|
|
336
65
|
getPos: getPos,
|
|
337
66
|
view: this.view,
|