@atlaskit/editor-plugin-media 1.29.8 → 1.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/nodeviews/mediaNodeUpdater.js +36 -8
- package/dist/cjs/nodeviews/mediaSingle.js +65 -86
- package/dist/cjs/ui/CommentBadge/index.js +13 -16
- package/dist/cjs/utils/batchMediaNodeAttrs.js +161 -0
- package/dist/cjs/utils/batchSteps.js +36 -0
- package/dist/es2019/nodeviews/mediaNodeUpdater.js +36 -8
- package/dist/es2019/nodeviews/mediaSingle.js +24 -43
- package/dist/es2019/ui/CommentBadge/index.js +16 -19
- package/dist/es2019/utils/batchMediaNodeAttrs.js +149 -0
- package/dist/es2019/utils/batchSteps.js +32 -0
- package/dist/esm/nodeviews/mediaNodeUpdater.js +36 -8
- package/dist/esm/nodeviews/mediaSingle.js +67 -88
- package/dist/esm/ui/CommentBadge/index.js +15 -18
- package/dist/esm/utils/batchMediaNodeAttrs.js +155 -0
- package/dist/esm/utils/batchSteps.js +30 -0
- package/dist/types/nodeviews/mediaSingle.d.ts +1 -1
- package/dist/types/ui/CommentBadge/index.d.ts +17 -1
- package/dist/types/utils/batchMediaNodeAttrs.d.ts +54 -0
- package/dist/types/utils/batchSteps.d.ts +19 -0
- package/dist/types-ts4.5/nodeviews/mediaSingle.d.ts +1 -1
- package/dist/types-ts4.5/ui/CommentBadge/index.d.ts +17 -1
- package/dist/types-ts4.5/utils/batchMediaNodeAttrs.d.ts +54 -0
- package/dist/types-ts4.5/utils/batchSteps.d.ts +19 -0
- package/package.json +16 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-media
|
|
2
2
|
|
|
3
|
+
## 1.30.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#137821](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/137821)
|
|
8
|
+
[`e26174c7d02a6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e26174c7d02a6) -
|
|
9
|
+
ED-24631 Refactor how ExternalImageBadge and CommentBadge are rendered
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#138118](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138118)
|
|
14
|
+
[`5e4d9eb1aefe4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5e4d9eb1aefe4) -
|
|
15
|
+
NOISSUE: Upgrades editor React peer dependencies to v18
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
18
|
+
## 1.29.9
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#135555](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/135555)
|
|
23
|
+
[`b7c55014a5c15`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b7c55014a5c15) -
|
|
24
|
+
add batch steps for media node attributes update
|
|
25
|
+
|
|
3
26
|
## 1.29.8
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -15,7 +15,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
15
15
|
var _mediaSingle = require("@atlaskit/editor-common/media-single");
|
|
16
16
|
var _mediaClient = require("@atlaskit/media-client");
|
|
17
17
|
var _mediaClientReact = require("@atlaskit/media-client-react");
|
|
18
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
19
|
var _helpers = require("../commands/helpers");
|
|
20
|
+
var _batchMediaNodeAttrs = require("../utils/batchMediaNodeAttrs");
|
|
19
21
|
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; }
|
|
20
22
|
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; }
|
|
21
23
|
var isMediaTypeSupported = function isMediaTypeSupported(type) {
|
|
@@ -46,9 +48,18 @@ var MediaNodeUpdater = exports.MediaNodeUpdater = /*#__PURE__*/function () {
|
|
|
46
48
|
return _this.getObjectId();
|
|
47
49
|
case 6:
|
|
48
50
|
objectId = _context.sent;
|
|
49
|
-
(0,
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_media_batch_updates')) {
|
|
52
|
+
(0, _batchMediaNodeAttrs.batchMediaNodeAttrsUpdate)(_this.props.view, {
|
|
53
|
+
id: id,
|
|
54
|
+
nextAttributes: {
|
|
55
|
+
__contextId: objectId
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
(0, _helpers.updateAllMediaNodesAttrs)(id, {
|
|
60
|
+
__contextId: objectId
|
|
61
|
+
})(_this.props.view.state, _this.props.view.dispatch);
|
|
62
|
+
}
|
|
52
63
|
case 8:
|
|
53
64
|
case "end":
|
|
54
65
|
return _context.stop();
|
|
@@ -172,7 +183,14 @@ var MediaNodeUpdater = exports.MediaNodeUpdater = /*#__PURE__*/function () {
|
|
|
172
183
|
newAttrs = _context4.sent;
|
|
173
184
|
_ref5 = _this.getAttrs(), id = _ref5.id;
|
|
174
185
|
if (id && newAttrs) {
|
|
175
|
-
(0,
|
|
186
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_media_batch_updates')) {
|
|
187
|
+
(0, _batchMediaNodeAttrs.batchMediaNodeAttrsUpdate)(_this.props.view, {
|
|
188
|
+
id: id,
|
|
189
|
+
nextAttributes: newAttrs
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
(0, _helpers.updateAllMediaNodesAttrs)(id, newAttrs)(_this.props.view.state, _this.props.view.dispatch);
|
|
193
|
+
}
|
|
176
194
|
}
|
|
177
195
|
case 5:
|
|
178
196
|
case "end":
|
|
@@ -304,10 +322,20 @@ var MediaNodeUpdater = exports.MediaNodeUpdater = /*#__PURE__*/function () {
|
|
|
304
322
|
return attrs.__contextId || null;
|
|
305
323
|
});
|
|
306
324
|
(0, _defineProperty2.default)(this, "updateDimensions", function (dimensions) {
|
|
307
|
-
(0,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
325
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_media_batch_updates')) {
|
|
326
|
+
(0, _batchMediaNodeAttrs.batchMediaNodeAttrsUpdate)(_this.props.view, {
|
|
327
|
+
id: dimensions.id,
|
|
328
|
+
nextAttributes: {
|
|
329
|
+
height: dimensions.height,
|
|
330
|
+
width: dimensions.width
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
} else {
|
|
334
|
+
(0, _helpers.updateAllMediaNodesAttrs)(dimensions.id, {
|
|
335
|
+
height: dimensions.height,
|
|
336
|
+
width: dimensions.width
|
|
337
|
+
})(_this.props.view.state, _this.props.view.dispatch);
|
|
338
|
+
}
|
|
311
339
|
});
|
|
312
340
|
(0, _defineProperty2.default)(this, "hasDifferentContextId", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8() {
|
|
313
341
|
var nodeContextId, currentContextId;
|
|
@@ -48,6 +48,7 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
48
48
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
|
|
49
49
|
* @jsxRuntime classic
|
|
50
50
|
* @jsx jsx
|
|
51
|
+
* @jsxFrag
|
|
51
52
|
*/ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
52
53
|
var figureWrapperStyles = (0, _react2.css)({
|
|
53
54
|
margin: 0
|
|
@@ -72,7 +73,6 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
72
73
|
});
|
|
73
74
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "mediaSingleWrapperRef", /*#__PURE__*/_react.default.createRef());
|
|
74
75
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "captionPlaceHolderRef", /*#__PURE__*/_react.default.createRef());
|
|
75
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "commentBadgeRef", /*#__PURE__*/_react.default.createRef());
|
|
76
76
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createOrUpdateMediaNodeUpdater", function (props) {
|
|
77
77
|
var node = _this.props.node.firstChild;
|
|
78
78
|
var updaterProps = _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -332,12 +332,7 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
332
332
|
}, {
|
|
333
333
|
key: "render",
|
|
334
334
|
value: function render() {
|
|
335
|
-
var _mediaOptions$getEdit,
|
|
336
|
-
_pluginInjectionApi$m,
|
|
337
|
-
_node$firstChild,
|
|
338
|
-
_this2 = this,
|
|
339
|
-
_mediaOptions$getEdit3,
|
|
340
|
-
_mediaOptions$getEdit4;
|
|
335
|
+
var _mediaOptions$getEdit, _pluginInjectionApi$m, _node$firstChild, _mediaOptions$getEdit2;
|
|
341
336
|
var _this$props2 = this.props,
|
|
342
337
|
selected = _this$props2.selected,
|
|
343
338
|
getPos = _this$props2.getPos,
|
|
@@ -431,9 +426,9 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
431
426
|
var canResize = !!this.props.mediaOptions.allowResizing && !editorDisabled && !editorViewMode;
|
|
432
427
|
if (!this.props.mediaOptions.allowResizingInTables) {
|
|
433
428
|
// If resizing not allowed in tables, check parents for tables
|
|
434
|
-
var
|
|
435
|
-
if (
|
|
436
|
-
var $pos = state.doc.resolve(
|
|
429
|
+
var _pos = getPos();
|
|
430
|
+
if (_pos) {
|
|
431
|
+
var $pos = state.doc.resolve(_pos);
|
|
437
432
|
var table = state.schema.nodes.table;
|
|
438
433
|
var disabledNode = !!(0, _utils2.findParentNodeOfTypeClosestToPos)($pos, [table]);
|
|
439
434
|
canResize = canResize && !disabledNode;
|
|
@@ -454,33 +449,14 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
454
449
|
shouldShowPlaceholder = !editorDisabled && shouldShowPlaceholder;
|
|
455
450
|
}
|
|
456
451
|
var isCurrentNodeDrafting = (annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.isDrafting) && (annotationPluginState === null || annotationPluginState === void 0 ? void 0 : annotationPluginState.targetNodeId) === (node === null || node === void 0 || (_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.attrs.id);
|
|
457
|
-
var
|
|
458
|
-
var
|
|
459
|
-
var
|
|
460
|
-
if (_this2.commentBadgeRef.current) {
|
|
461
|
-
var _mediaOptions$getEdit2;
|
|
462
|
-
var commentsOnMediaBugFixEnabled = mediaOptions === null || mediaOptions === void 0 || (_mediaOptions$getEdit2 = mediaOptions.getEditorFeatureFlags) === null || _mediaOptions$getEdit2 === void 0 || (_mediaOptions$getEdit2 = _mediaOptions$getEdit2.call(mediaOptions)) === null || _mediaOptions$getEdit2 === void 0 ? void 0 : _mediaOptions$getEdit2.commentsOnMediaBugFix;
|
|
463
|
-
var commentBadgeWidth = _this2.commentBadgeRef.current.offsetWidth;
|
|
464
|
-
var isMediaInsideTable = function isMediaInsideTable() {
|
|
465
|
-
var pos = getPos();
|
|
466
|
-
if (pos !== undefined) {
|
|
467
|
-
var _$pos2 = view.state.doc.resolve(pos);
|
|
468
|
-
var _table2 = view.state.schema.nodes.table;
|
|
469
|
-
var foundTableNode = (0, _utils2.findParentNodeOfTypeClosestToPos)(_$pos2, [_table2]);
|
|
470
|
-
return Boolean(foundTableNode);
|
|
471
|
-
}
|
|
472
|
-
return false;
|
|
473
|
-
};
|
|
474
|
-
if (commentsOnMediaBugFixEnabled && isMediaInsideTable()) {
|
|
475
|
-
return commentBadgeWidth + 2;
|
|
476
|
-
}
|
|
477
|
-
return commentBadgeWidth + 14;
|
|
478
|
-
}
|
|
479
|
-
return 0;
|
|
480
|
-
};
|
|
452
|
+
var shouldShowExternalMediaBadge = attrs.type === 'external';
|
|
453
|
+
var pos = getPos();
|
|
454
|
+
var isInsideTable = pos !== undefined && (0, _utils2.findParentNodeOfTypeClosestToPos)(state.doc.resolve(pos), [state.schema.nodes.table]);
|
|
481
455
|
var currentMediaElement = function currentMediaElement() {
|
|
482
|
-
|
|
483
|
-
|
|
456
|
+
if (pos !== undefined) {
|
|
457
|
+
return view.domAtPos(pos + 1).node;
|
|
458
|
+
}
|
|
459
|
+
return null;
|
|
484
460
|
};
|
|
485
461
|
var MediaChildren = (0, _react2.jsx)("figure", {
|
|
486
462
|
ref: this.mediaSingleWrapperRef,
|
|
@@ -489,29 +465,32 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
489
465
|
,
|
|
490
466
|
className: _styles.MediaSingleNodeSelector,
|
|
491
467
|
onClick: this.onMediaSingleClicked
|
|
492
|
-
},
|
|
493
|
-
commentBadgeRightOffset: commentBadgeOffset(),
|
|
468
|
+
}, (0, _platformFeatureFlags.fg)('platform_editor_insert_media_plugin_phase_one') && (0, _react2.jsx)(_mediaSingle.MediaBadges, {
|
|
494
469
|
mediaElement: currentMediaElement(),
|
|
495
470
|
mediaHeight: height,
|
|
496
|
-
mediaWidth: width
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
471
|
+
mediaWidth: width,
|
|
472
|
+
extendedResizeOffset: (0, _platformFeatureFlags.fg)('platform.editor.media.extended-resize-experience') && !isInsideTable
|
|
473
|
+
}, function (_ref6) {
|
|
474
|
+
var badgeSize = _ref6.badgeSize;
|
|
475
|
+
return (0, _react2.jsx)(_react.default.Fragment, null, shouldShowExternalMediaBadge && (0, _react2.jsx)(_mediaSingle.ExternalImageBadge, {
|
|
476
|
+
badgeSize: badgeSize
|
|
477
|
+
}), commentsOnMedia && (0, _react2.jsx)(_CommentBadge.CommentBadgeNextWrapper, {
|
|
478
|
+
view: view,
|
|
479
|
+
api: pluginInjectionApi,
|
|
480
|
+
mediaNode: node === null || node === void 0 ? void 0 : node.firstChild,
|
|
481
|
+
getPos: getPos,
|
|
482
|
+
isDrafting: isCurrentNodeDrafting,
|
|
483
|
+
badgeSize: badgeSize
|
|
484
|
+
}));
|
|
485
|
+
}), !(0, _platformFeatureFlags.fg)('platform_editor_insert_media_plugin_phase_one') && commentsOnMedia && (0, _react2.jsx)(_CommentBadge.CommentBadge, {
|
|
486
|
+
commentsOnMediaBugFixEnabled: mediaOptions === null || mediaOptions === void 0 || (_mediaOptions$getEdit2 = mediaOptions.getEditorFeatureFlags) === null || _mediaOptions$getEdit2 === void 0 || (_mediaOptions$getEdit2 = _mediaOptions$getEdit2.call(mediaOptions)) === null || _mediaOptions$getEdit2 === void 0 ? void 0 : _mediaOptions$getEdit2.commentsOnMediaBugFix,
|
|
500
487
|
view: view,
|
|
501
488
|
api: pluginInjectionApi,
|
|
502
489
|
mediaNode: node === null || node === void 0 ? void 0 : node.firstChild,
|
|
503
490
|
badgeOffsetRight: badgeOffsetRight,
|
|
504
491
|
getPos: getPos,
|
|
505
492
|
isDrafting: isCurrentNodeDrafting
|
|
506
|
-
})
|
|
507
|
-
commentsOnMediaBugFixEnabled: mediaOptions === null || mediaOptions === void 0 || (_mediaOptions$getEdit4 = mediaOptions.getEditorFeatureFlags) === null || _mediaOptions$getEdit4 === void 0 || (_mediaOptions$getEdit4 = _mediaOptions$getEdit4.call(mediaOptions)) === null || _mediaOptions$getEdit4 === void 0 ? void 0 : _mediaOptions$getEdit4.commentsOnMediaBugFix,
|
|
508
|
-
view: view,
|
|
509
|
-
api: pluginInjectionApi,
|
|
510
|
-
mediaNode: node === null || node === void 0 ? void 0 : node.firstChild,
|
|
511
|
-
badgeOffsetRight: badgeOffsetRight,
|
|
512
|
-
getPos: getPos,
|
|
513
|
-
isDrafting: isCurrentNodeDrafting
|
|
514
|
-
})), (0, _react2.jsx)("div", {
|
|
493
|
+
}), (0, _react2.jsx)("div", {
|
|
515
494
|
ref: this.props.forwardRef
|
|
516
495
|
}), shouldShowPlaceholder && (0, _react2.jsx)(_CaptionPlaceholder.default, {
|
|
517
496
|
ref: this.captionPlaceHolderRef,
|
|
@@ -537,19 +516,19 @@ var MediaSingleNode = exports.default = /*#__PURE__*/function (_Component) {
|
|
|
537
516
|
mediaOptions: {}
|
|
538
517
|
});
|
|
539
518
|
(0, _defineProperty2.default)(MediaSingleNode, "displayName", 'MediaSingleNode');
|
|
540
|
-
var MediaSingleNodeWrapper = function MediaSingleNodeWrapper(
|
|
541
|
-
var pluginInjectionApi =
|
|
542
|
-
contextIdentifierProvider =
|
|
543
|
-
node =
|
|
544
|
-
getPos =
|
|
545
|
-
mediaOptions =
|
|
546
|
-
view =
|
|
547
|
-
fullWidthMode =
|
|
548
|
-
selected =
|
|
549
|
-
eventDispatcher =
|
|
550
|
-
dispatchAnalyticsEvent =
|
|
551
|
-
forwardRef =
|
|
552
|
-
editorAppearance =
|
|
519
|
+
var MediaSingleNodeWrapper = function MediaSingleNodeWrapper(_ref7) {
|
|
520
|
+
var pluginInjectionApi = _ref7.pluginInjectionApi,
|
|
521
|
+
contextIdentifierProvider = _ref7.contextIdentifierProvider,
|
|
522
|
+
node = _ref7.node,
|
|
523
|
+
getPos = _ref7.getPos,
|
|
524
|
+
mediaOptions = _ref7.mediaOptions,
|
|
525
|
+
view = _ref7.view,
|
|
526
|
+
fullWidthMode = _ref7.fullWidthMode,
|
|
527
|
+
selected = _ref7.selected,
|
|
528
|
+
eventDispatcher = _ref7.eventDispatcher,
|
|
529
|
+
dispatchAnalyticsEvent = _ref7.dispatchAnalyticsEvent,
|
|
530
|
+
forwardRef = _ref7.forwardRef,
|
|
531
|
+
editorAppearance = _ref7.editorAppearance;
|
|
553
532
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['width', 'media', 'annotation', 'editorDisabled', 'editorViewMode']),
|
|
554
533
|
widthState = _useSharedPluginState.widthState,
|
|
555
534
|
mediaState = _useSharedPluginState.mediaState,
|
|
@@ -585,18 +564,18 @@ var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
585
564
|
(0, _inherits2.default)(MediaSingleNodeView, _ReactNodeView);
|
|
586
565
|
var _super2 = _createSuper(MediaSingleNodeView);
|
|
587
566
|
function MediaSingleNodeView() {
|
|
588
|
-
var
|
|
567
|
+
var _this2;
|
|
589
568
|
(0, _classCallCheck2.default)(this, MediaSingleNodeView);
|
|
590
569
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
591
570
|
args[_key2] = arguments[_key2];
|
|
592
571
|
}
|
|
593
|
-
|
|
594
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(
|
|
595
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(
|
|
596
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(
|
|
597
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(
|
|
598
|
-
var getPos =
|
|
599
|
-
var selection =
|
|
572
|
+
_this2 = _super2.call.apply(_super2, [this].concat(args));
|
|
573
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "lastOffsetLeft", 0);
|
|
574
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "forceViewUpdate", false);
|
|
575
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "selectionType", null);
|
|
576
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "checkAndUpdateSelectionType", function () {
|
|
577
|
+
var getPos = _this2.getPos;
|
|
578
|
+
var selection = _this2.view.state.selection;
|
|
600
579
|
|
|
601
580
|
/**
|
|
602
581
|
* ED-19831
|
|
@@ -609,15 +588,15 @@ var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
609
588
|
} catch (e) {
|
|
610
589
|
pos = undefined;
|
|
611
590
|
}
|
|
612
|
-
var isNodeSelected = (0, _utils.isNodeSelectedOrInRange)(selection.$anchor.pos, selection.$head.pos, pos,
|
|
613
|
-
|
|
591
|
+
var isNodeSelected = (0, _utils.isNodeSelectedOrInRange)(selection.$anchor.pos, selection.$head.pos, pos, _this2.node.nodeSize);
|
|
592
|
+
_this2.selectionType = isNodeSelected;
|
|
614
593
|
return isNodeSelected;
|
|
615
594
|
});
|
|
616
|
-
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(
|
|
617
|
-
|
|
618
|
-
return
|
|
595
|
+
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this2), "isNodeSelected", function () {
|
|
596
|
+
_this2.checkAndUpdateSelectionType();
|
|
597
|
+
return _this2.selectionType !== null;
|
|
619
598
|
});
|
|
620
|
-
return
|
|
599
|
+
return _this2;
|
|
621
600
|
}
|
|
622
601
|
(0, _createClass2.default)(MediaSingleNodeView, [{
|
|
623
602
|
key: "createDomRef",
|
|
@@ -682,10 +661,10 @@ var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
682
661
|
}, {
|
|
683
662
|
key: "update",
|
|
684
663
|
value: function update(node, decorations, _innerDecorations, isValidUpdate) {
|
|
685
|
-
var
|
|
664
|
+
var _this3 = this;
|
|
686
665
|
if (!isValidUpdate) {
|
|
687
666
|
isValidUpdate = function isValidUpdate(currentNode, newNode) {
|
|
688
|
-
return
|
|
667
|
+
return _this3.getNodeMediaId(currentNode) === _this3.getNodeMediaId(newNode);
|
|
689
668
|
};
|
|
690
669
|
}
|
|
691
670
|
return (0, _get2.default)((0, _getPrototypeOf2.default)(MediaSingleNodeView.prototype), "update", this).call(this, node, decorations, _innerDecorations, isValidUpdate);
|
|
@@ -693,7 +672,7 @@ var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
693
672
|
}, {
|
|
694
673
|
key: "render",
|
|
695
674
|
value: function render(props, forwardRef) {
|
|
696
|
-
var
|
|
675
|
+
var _this4 = this;
|
|
697
676
|
var _this$reactComponentP = this.reactComponentProps,
|
|
698
677
|
eventDispatcher = _this$reactComponentP.eventDispatcher,
|
|
699
678
|
fullWidthMode = _this$reactComponentP.fullWidthMode,
|
|
@@ -708,17 +687,17 @@ var MediaSingleNodeView = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
708
687
|
return (0, _react2.jsx)(_providerFactory.WithProviders, {
|
|
709
688
|
providers: ['contextIdentifierProvider'],
|
|
710
689
|
providerFactory: providerFactory,
|
|
711
|
-
renderNode: function renderNode(
|
|
712
|
-
var contextIdentifierProvider =
|
|
690
|
+
renderNode: function renderNode(_ref8) {
|
|
691
|
+
var contextIdentifierProvider = _ref8.contextIdentifierProvider;
|
|
713
692
|
return (0, _react2.jsx)(MediaSingleNodeWrapper, {
|
|
714
693
|
pluginInjectionApi: pluginInjectionApi,
|
|
715
694
|
contextIdentifierProvider: contextIdentifierProvider,
|
|
716
|
-
node:
|
|
695
|
+
node: _this4.node,
|
|
717
696
|
getPos: getPos,
|
|
718
697
|
mediaOptions: mediaOptions,
|
|
719
|
-
view:
|
|
698
|
+
view: _this4.view,
|
|
720
699
|
fullWidthMode: fullWidthMode,
|
|
721
|
-
selected:
|
|
700
|
+
selected: _this4.isNodeSelected,
|
|
722
701
|
eventDispatcher: eventDispatcher,
|
|
723
702
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
724
703
|
forwardRef: forwardRef,
|
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.CommentBadgeNextWrapper = exports.CommentBadge = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _reactIntlNext = require("react-intl-next");
|
|
@@ -77,17 +77,19 @@ var CommentBadgeWrapper = function CommentBadgeWrapper(_ref) {
|
|
|
77
77
|
};
|
|
78
78
|
var CommentBadge = exports.CommentBadge = (0, _reactIntlNext.injectIntl)(CommentBadgeWrapper);
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Remove CommentBadgeWrapper component above
|
|
82
|
+
* and rename CommentBadgeNextWrapper to CommentBadgeWrapper
|
|
83
|
+
* when clean up platform_editor_insert_media_plugin_phase_one feature flag
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
var CommentBadgeNextWrapper = exports.CommentBadgeNextWrapper = function CommentBadgeNextWrapper(_ref2) {
|
|
83
87
|
var api = _ref2.api,
|
|
84
88
|
mediaNode = _ref2.mediaNode,
|
|
85
89
|
view = _ref2.view,
|
|
86
90
|
getPos = _ref2.getPos,
|
|
87
91
|
isDrafting = _ref2.isDrafting,
|
|
88
|
-
|
|
89
|
-
commentsOnMediaBugFixEnabled = _ref2.commentsOnMediaBugFixEnabled;
|
|
90
|
-
var intl = (0, _reactIntlNext.useIntl)();
|
|
92
|
+
badgeSize = _ref2.badgeSize;
|
|
91
93
|
var _useState3 = (0, _react.useState)(false),
|
|
92
94
|
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
93
95
|
entered = _useState4[0],
|
|
@@ -123,21 +125,16 @@ var CommentBadgeWithRef = exports.CommentBadgeWithRef = /*#__PURE__*/(0, _react.
|
|
|
123
125
|
return null;
|
|
124
126
|
}
|
|
125
127
|
var mediaSingleElement = view.domAtPos(pos + 1).node;
|
|
126
|
-
return /*#__PURE__*/_react.default.createElement(_mediaSingle.
|
|
127
|
-
ref: ref,
|
|
128
|
-
commentsOnMediaBugFixEnabled: commentsOnMediaBugFixEnabled,
|
|
129
|
-
badgeOffsetRight: badgeOffsetRight,
|
|
130
|
-
width: mediaNode.attrs.width,
|
|
131
|
-
height: mediaNode.attrs.height,
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(_mediaSingle.CommentBadgeNext, {
|
|
132
129
|
onClick: onClick,
|
|
133
130
|
mediaSingleElement: mediaSingleElement,
|
|
134
|
-
intl: intl,
|
|
135
131
|
status: entered ? 'entered' : status,
|
|
136
132
|
onMouseEnter: function onMouseEnter() {
|
|
137
133
|
return setEntered(true);
|
|
138
134
|
},
|
|
139
135
|
onMouseLeave: function onMouseLeave() {
|
|
140
136
|
return setEntered(false);
|
|
141
|
-
}
|
|
137
|
+
},
|
|
138
|
+
badgeSize: badgeSize
|
|
142
139
|
});
|
|
143
|
-
}
|
|
140
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.runUpdateDebounced = exports.runUpdate = exports.containsSameAttributes = exports.batchMediaNodeAttrsUpdate = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _debounce = _interopRequireDefault(require("lodash/debounce"));
|
|
12
|
+
var _memoize = _interopRequireDefault(require("lodash/memoize"));
|
|
13
|
+
var _batchSteps = require("./batchSteps");
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
/**
|
|
17
|
+
* 🧱 Internal: Editor FE Platform
|
|
18
|
+
* Based on https://github.com/lodash/lodash/issues/2403#issuecomment-1706130395
|
|
19
|
+
*
|
|
20
|
+
* Creates a debounced function that delays invoking the provided function until after a specified
|
|
21
|
+
* wait time has elapsed since the last time the debounced function was invoked. Additionally, the
|
|
22
|
+
* debounced function is memoized so that the same function instance is used for each unique set
|
|
23
|
+
* of arguments based on the resolver.
|
|
24
|
+
*
|
|
25
|
+
* This is particularly useful in scenarios where you want to debounce function calls while ensuring
|
|
26
|
+
* that each unique input combination receives its own debounced function instance. It's a combination
|
|
27
|
+
* of lodash's `debounce` and `memoize`.
|
|
28
|
+
*
|
|
29
|
+
* @template T
|
|
30
|
+
* @param {T} func - The function to debounce.
|
|
31
|
+
* @param {number} [wait=0] - The number of milliseconds to delay.
|
|
32
|
+
* @param {Object} [options] - The options object to pass to `debounce`.
|
|
33
|
+
* @param {Function} [resolver] - The function to resolve the cache key for memoization.
|
|
34
|
+
* @returns {Function} A new debounced and memoized function.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const debouncedFunction = memoizeDebounce(myFunction, 300, { leading: true }, myResolver);
|
|
38
|
+
* debouncedFunction(arg1, arg2);
|
|
39
|
+
*/
|
|
40
|
+
function memoizeDebounce(func) {
|
|
41
|
+
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
42
|
+
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
43
|
+
var resolver = arguments.length > 3 ? arguments[3] : undefined;
|
|
44
|
+
var mem = (0, _memoize.default)(function () {
|
|
45
|
+
return (0, _debounce.default)(func, wait, options);
|
|
46
|
+
}, resolver);
|
|
47
|
+
return function () {
|
|
48
|
+
return mem.apply(void 0, arguments).apply(void 0, arguments);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var mediaAttributesCache = new WeakMap();
|
|
52
|
+
var debouncedTime = 500;
|
|
53
|
+
var containsSameAttributes = exports.containsSameAttributes = function containsSameAttributes(a, b) {
|
|
54
|
+
// a contains b, and want to check if attributes in b are same in a
|
|
55
|
+
return Object.entries(b).every(function (_ref) {
|
|
56
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
57
|
+
bkey = _ref2[0],
|
|
58
|
+
bValue = _ref2[1];
|
|
59
|
+
if (bkey in a) {
|
|
60
|
+
var aValue = a[bkey];
|
|
61
|
+
// Check if types match before comparing values
|
|
62
|
+
return (0, _typeof2.default)(aValue) === (0, _typeof2.default)(bValue) && aValue === bValue;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Updates media node attributes in the editor view based on the provided cache.
|
|
70
|
+
*
|
|
71
|
+
* @param {EditorView} editorView - The editor view instance where the updates will be applied.
|
|
72
|
+
* @param {MediaAttributesCache} cache - The cache containing media attributes to be updated.
|
|
73
|
+
*
|
|
74
|
+
* This function performs the following steps:
|
|
75
|
+
* 1. Retrieves the media attributes to update from the cache for the given editor view.
|
|
76
|
+
* 2. Clears the media attributes cache for the editor view.
|
|
77
|
+
* 3. Searches for media nodes in the document and collects their positions and new attributes.
|
|
78
|
+
* 4. If there are any media nodes to update, it applies the updates in a batch.
|
|
79
|
+
*/
|
|
80
|
+
var runUpdate = exports.runUpdate = function runUpdate(editorView, cache) {
|
|
81
|
+
var toUpdateValues = cache.get(editorView) || {};
|
|
82
|
+
// clear the media attributes cache per editor view
|
|
83
|
+
cache.delete(editorView);
|
|
84
|
+
var ids = Object.keys(toUpdateValues);
|
|
85
|
+
var state = editorView.state;
|
|
86
|
+
var mediaSteps = [];
|
|
87
|
+
|
|
88
|
+
// search node positions by id
|
|
89
|
+
state.doc.descendants(function (node, position) {
|
|
90
|
+
if (![node.type.schema.nodes.media, node.type.schema.nodes.mediaInline].includes(node.type)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
if (!ids.includes(node.attrs.id)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
var attrs = toUpdateValues[node.attrs.id];
|
|
97
|
+
if (containsSameAttributes(node.attrs, attrs)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
mediaSteps.push({
|
|
101
|
+
position: position,
|
|
102
|
+
nodeType: node.type.name,
|
|
103
|
+
attrs: attrs
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
if (mediaSteps.length > 0) {
|
|
107
|
+
(0, _batchSteps.batchStepsUpdate)(editorView, mediaSteps);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Creates a debounced version of the `runUpdate` function to update media node attributes in the editor view.
|
|
113
|
+
*
|
|
114
|
+
* @constant
|
|
115
|
+
* @type {Function}
|
|
116
|
+
* @param {Function} runUpdate - The function to be debounced.
|
|
117
|
+
* @param {number} debouncedTime - The debounce delay in milliseconds.
|
|
118
|
+
* @param {Object} [options] - The debounce options. Defaults to {leading: false, trailing: true}.
|
|
119
|
+
* @param {Function} keyResolver - A function that returns the key to be used for memoization. In this case, it returns the editor view instance.
|
|
120
|
+
*
|
|
121
|
+
* This function performs the following steps:
|
|
122
|
+
* 1. Debounces the `runUpdate` function with the specified delay and options.
|
|
123
|
+
* 2. Uses the editor view instance as the key for memoization to ensure that updates are applied correctly.
|
|
124
|
+
*/
|
|
125
|
+
var runUpdateDebounced = exports.runUpdateDebounced = memoizeDebounce(runUpdate, debouncedTime,
|
|
126
|
+
/**
|
|
127
|
+
* Use the default debounce options:
|
|
128
|
+
* {leading: false, trailing: true}
|
|
129
|
+
*/
|
|
130
|
+
undefined, function (view) {
|
|
131
|
+
/**
|
|
132
|
+
* EditorView is a singleton.
|
|
133
|
+
* There is only one instance per Editor.
|
|
134
|
+
*/
|
|
135
|
+
return view;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Updates the media node attributes cache for the given editor view and triggers a debounced update.
|
|
140
|
+
*
|
|
141
|
+
* @param {EditorView} editorView - The editor view instance where the updates will be applied.
|
|
142
|
+
* @param {Props} props - The properties containing the media node ID and the next attributes to be updated.
|
|
143
|
+
*
|
|
144
|
+
* This function performs the following steps:
|
|
145
|
+
* 1. Retrieves the media attributes cache for the given editor view.
|
|
146
|
+
* 2. If no cache exists, initializes a new cache.
|
|
147
|
+
* 3. Updates the cache with the new attributes for the specified media node ID.
|
|
148
|
+
* 4. Sets the updated cache back to the media attributes cache.
|
|
149
|
+
* 5. Triggers a debounced update to apply the changes in the editor view.
|
|
150
|
+
*/
|
|
151
|
+
var batchMediaNodeAttrsUpdate = exports.batchMediaNodeAttrsUpdate = function batchMediaNodeAttrsUpdate(editorView, props) {
|
|
152
|
+
var cachePerView = mediaAttributesCache.get(editorView);
|
|
153
|
+
if (!cachePerView) {
|
|
154
|
+
cachePerView = {
|
|
155
|
+
records: {}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
cachePerView[props.id] = _objectSpread(_objectSpread({}, cachePerView[props.id] || {}), props.nextAttributes);
|
|
159
|
+
mediaAttributesCache.set(editorView, cachePerView);
|
|
160
|
+
runUpdateDebounced(editorView, mediaAttributesCache);
|
|
161
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.batchStepsUpdate = void 0;
|
|
7
|
+
var _steps = require("@atlaskit/adf-schema/steps");
|
|
8
|
+
/**
|
|
9
|
+
* Applies a batch of attribute update steps to media nodes in the editor view.
|
|
10
|
+
*
|
|
11
|
+
* @param {EditorView} editorView - The editor view instance where the updates will be applied.
|
|
12
|
+
* @param {BatchAttrsStepData[]} steps - An array of steps containing the positions and new attributes for media nodes.
|
|
13
|
+
* @returns {boolean} - Returns false if no steps were applied or if the document remains unchanged after applying the steps.
|
|
14
|
+
*
|
|
15
|
+
* This function performs the following steps:
|
|
16
|
+
* 1. Creates a new transaction from the current editor state.
|
|
17
|
+
* 2. If there are no steps to apply, it returns false.
|
|
18
|
+
* 3. Adds a new `BatchAttrsStep` to the transaction with the provided steps.
|
|
19
|
+
* 4. If the transaction has no steps or the document remains unchanged, it returns false.
|
|
20
|
+
* 5. Dispatches the transaction to apply the updates to the editor view.
|
|
21
|
+
*
|
|
22
|
+
* TODO: use pluginInjectionAPI to batch updates from a command in a separate PR later
|
|
23
|
+
*/
|
|
24
|
+
var batchStepsUpdate = exports.batchStepsUpdate = function batchStepsUpdate(editorView, steps) {
|
|
25
|
+
var state = editorView.state,
|
|
26
|
+
dispatch = editorView.dispatch;
|
|
27
|
+
var tr = state.tr;
|
|
28
|
+
if (steps.length === 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
tr.step(new _steps.BatchAttrsStep(steps));
|
|
32
|
+
if (tr.steps.length > 0 && tr.doc.eq(state.doc)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
dispatch(tr);
|
|
36
|
+
};
|