@atlaskit/editor-plugin-media 1.37.2 → 1.37.4

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-media
2
2
 
3
+ ## 1.37.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#156360](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/156360)
8
+ [`7125e8ac235ea`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7125e8ac235ea) -
9
+ [ED-25348] Refactor Media ResizeNext React Class component into Function Component
10
+ - Updated dependencies
11
+
12
+ ## 1.37.3
13
+
14
+ ### Patch Changes
15
+
16
+ - [#156556](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/156556)
17
+ [`fa4db989cfa70`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fa4db989cfa70) -
18
+ [HOT-112603] Reduce memory leak footage by using WeakRef to store HTML element
19
+
3
20
  ## 1.37.2
4
21
 
5
22
  ### Patch Changes
@@ -740,7 +740,6 @@ var getMediaPluginState = exports.getMediaPluginState = function getMediaPluginS
740
740
  };
741
741
  var createPlugin = exports.createPlugin = function createPlugin(_schema, options, getIntl, pluginInjectionApi, dispatch, mediaOptions, newInsertionBehaviour) {
742
742
  var intl = getIntl();
743
- var dropPlaceholder = createDropPlaceholder(intl, mediaOptions && mediaOptions.allowDropzoneDropLine);
744
743
  return new _safePlugin.SafePlugin({
745
744
  state: {
746
745
  init: function init(_config, state) {
@@ -882,8 +881,15 @@ var createPlugin = exports.createPlugin = function createPlugin(_schema, options
882
881
  if (pos === null || pos === undefined) {
883
882
  return _view2.DecorationSet.create(state.doc, mediaNodes);
884
883
  }
885
- var dropPlaceholders = [_view2.Decoration.widget(pos, dropPlaceholder, {
886
- key: 'drop-placeholder'
884
+ var dropPlaceholders = [_view2.Decoration.widget(pos, function () {
885
+ return createDropPlaceholder(intl, mediaOptions && mediaOptions.allowDropzoneDropLine);
886
+ }, {
887
+ key: 'drop-placeholder',
888
+ destroy: function destroy(elem) {
889
+ if (elem instanceof HTMLElement) {
890
+ _reactDom.default.unmountComponentAtNode(elem);
891
+ }
892
+ }
887
893
  })].concat(mediaNodes);
888
894
  return _view2.DecorationSet.create(state.doc, dropPlaceholders);
889
895
  },
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
- exports.resizerNextTestId = exports.default = void 0;
8
+ exports.resizerNextTestId = exports.default = exports.ResizableMediaSingleNextFunctional = void 0;
8
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
12
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
13
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
@@ -15,7 +17,7 @@ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits
15
17
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
16
18
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
17
19
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
- var _react = _interopRequireDefault(require("react"));
20
+ var _react = _interopRequireWildcard(require("react"));
19
21
  var _react2 = require("@emotion/react");
20
22
  var _classnames = _interopRequireDefault(require("classnames"));
21
23
  var _throttle = _interopRequireDefault(require("lodash/throttle"));
@@ -26,13 +28,17 @@ var _resizer = require("@atlaskit/editor-common/resizer");
26
28
  var _styles = require("@atlaskit/editor-common/styles");
27
29
  var _ui = require("@atlaskit/editor-common/ui");
28
30
  var _utils = require("@atlaskit/editor-common/utils");
31
+ var _state = require("@atlaskit/editor-prosemirror/state");
29
32
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
30
33
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
34
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
31
35
  var _main = require("../../pm-plugins/main");
32
36
  var _analytics = require("../../utils/analytics");
33
37
  var _checkMediaType = require("../../utils/check-media-type");
34
38
  var _ResizableMediaMigrationNotification = require("./ResizableMediaMigrationNotification");
35
39
  var _styled = require("./styled");
40
+ 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); }
41
+ 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; }
36
42
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
37
43
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /**
38
44
  * @jsxRuntime classic
@@ -81,7 +87,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
81
87
  return layout;
82
88
  }
83
89
  }
84
- return _this.calcUnwrappedLayout(newWidth, containerWidth, lineLength, fullWidthMode, _this.isNestedNode());
90
+ return _this.calcUnwrappedLayout(newWidth, containerWidth || 0, lineLength, fullWidthMode, _this.isNestedNode());
85
91
  });
86
92
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcUnwrappedLayout", function (width, containerWidth, contentWidth, fullWidthMode, isNestedNode) {
87
93
  if (isNestedNode) {
@@ -424,7 +430,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
424
430
  fullWidthMode = _this$props7.fullWidthMode;
425
431
 
426
432
  // disable guidelines for nested media single node
427
- return this.isNestedNode() ? [] : (0, _guideline.generateDefaultGuidelines)(lineLength, containerWidth, fullWidthMode);
433
+ return this.isNestedNode() ? [] : (0, _guideline.generateDefaultGuidelines)(lineLength, containerWidth || 0, fullWidthMode);
428
434
  }
429
435
  }, {
430
436
  key: "checkVideoFile",
@@ -545,4 +551,549 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
545
551
  }]);
546
552
  return ResizableMediaSingleNext;
547
553
  }(_react.default.Component);
548
- var _default = exports.default = ResizableMediaSingleNext;
554
+ var calcPxHeight = function calcPxHeight(props) {
555
+ var newWidth = props.newWidth,
556
+ previousWidth = props.previousWidth,
557
+ previousHeight = props.previousHeight;
558
+ return Math.round(previousHeight / previousWidth * newWidth);
559
+ };
560
+ var calcMinWidth = function calcMinWidth(_ref2) {
561
+ var isVideoFile = _ref2.isVideoFile,
562
+ contentWidth = _ref2.contentWidth;
563
+ return Math.min(contentWidth || _editorSharedStyles.akEditorDefaultLayoutWidth, isVideoFile ? _mediaSingle.MEDIA_SINGLE_VIDEO_MIN_PIXEL_WIDTH : _mediaSingle.MEDIA_SINGLE_DEFAULT_MIN_PIXEL_WIDTH);
564
+ };
565
+ var calcMaxWidth = function calcMaxWidth(_ref3) {
566
+ var containerWidth = _ref3.containerWidth,
567
+ editorAppearance = _ref3.editorAppearance;
568
+ return (0, _mediaSingle.calcMediaSingleMaxWidth)(containerWidth, editorAppearance);
569
+ };
570
+ var setIsResizingPluginState = function setIsResizingPluginState(_ref4) {
571
+ var isResizing = _ref4.isResizing,
572
+ nodePosition = _ref4.nodePosition,
573
+ initialWidth = _ref4.initialWidth;
574
+ return function (state, dispatch) {
575
+ var tr = state.tr;
576
+ tr.setMeta(_main.MEDIA_PLUGIN_IS_RESIZING_KEY, isResizing);
577
+ tr.setMeta('is-resizer-resizing', isResizing);
578
+ if (isResizing && typeof nodePosition === 'number') {
579
+ tr.setSelection(_state.NodeSelection.create(state.doc, nodePosition));
580
+ }
581
+ if (isResizing && typeof initialWidth === 'number') {
582
+ tr.setMeta(_main.MEDIA_PLUGIN_RESIZING_WIDTH_KEY, initialWidth);
583
+ }
584
+ if (dispatch) {
585
+ dispatch(tr);
586
+ }
587
+ return true;
588
+ };
589
+ };
590
+ var calcUnwrappedLayout = function calcUnwrappedLayout(width, containerWidth, contentWidth, fullWidthMode, isNestedNode) {
591
+ if (isNestedNode) {
592
+ return 'center';
593
+ }
594
+ if (fullWidthMode) {
595
+ if (width < contentWidth) {
596
+ return 'center';
597
+ }
598
+ return 'full-width';
599
+ }
600
+
601
+ // handle top-level node in fixed-width editor
602
+ if (width <= contentWidth) {
603
+ return 'center';
604
+ }
605
+ if (width < Math.min(containerWidth - (0, _editorSharedStyles.akEditorGutterPaddingDynamic)() * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth)) {
606
+ return 'wide';
607
+ }
608
+
609
+ // set full width to be containerWidth - akEditorGutterPaddingDynamic() * 2
610
+ // instead of containerWidth - akEditorBreakoutPadding,
611
+ // so that we have image aligned with text
612
+ return 'full-width';
613
+ };
614
+ var calcNewLayout = function calcNewLayout(_ref5) {
615
+ var layout = _ref5.layout,
616
+ containerWidth = _ref5.containerWidth,
617
+ lineLength = _ref5.lineLength,
618
+ fullWidthMode = _ref5.fullWidthMode,
619
+ isNestedNode = _ref5.isNestedNode;
620
+ return function (newWidth, stop) {
621
+ var newPct = (0, _ui.calcPctFromPx)(newWidth, lineLength) * 100;
622
+ var wrappedLayout = _ui.wrappedLayouts.indexOf(layout) > -1;
623
+ if (newPct <= 100 && wrappedLayout) {
624
+ if (!stop || newPct !== 100) {
625
+ return layout;
626
+ }
627
+ }
628
+ return calcUnwrappedLayout(newWidth, containerWidth, lineLength, fullWidthMode, isNestedNode);
629
+ };
630
+ };
631
+ var calculateSizeState = function calculateSizeState(props) {
632
+ return function (size, delta) {
633
+ var onResizeStop = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
634
+ var aspectRatio = arguments.length > 3 ? arguments[3] : undefined;
635
+ var calculatedWidth = Math.round(size.width + delta.width);
636
+ var calculatedWidthWithLayout = calcNewLayout(props)(calculatedWidth, onResizeStop);
637
+ return {
638
+ width: calculatedWidth,
639
+ height: calculatedWidth / aspectRatio,
640
+ layout: calculatedWidthWithLayout
641
+ };
642
+ };
643
+ };
644
+ var getAspectRatio = function getAspectRatio(_ref6) {
645
+ var width = _ref6.width,
646
+ height = _ref6.height;
647
+ if (width && height > 0) {
648
+ return width / height;
649
+ }
650
+
651
+ // TODO handle this case
652
+ return 1;
653
+ };
654
+ var updateSizeInPluginState = (0, _throttle.default)(function (_ref7) {
655
+ var width = _ref7.width,
656
+ view = _ref7.view;
657
+ var state = view.state,
658
+ dispatch = view.dispatch;
659
+ var tr = state.tr;
660
+ tr.setMeta(_main.MEDIA_PLUGIN_RESIZING_WIDTH_KEY, width);
661
+ return dispatch(tr);
662
+ }, _mediaSingle.MEDIA_SINGLE_RESIZE_THROTTLE_TIME);
663
+ var ResizableMediaSingleNextFunctional = exports.ResizableMediaSingleNextFunctional = function ResizableMediaSingleNextFunctional(props) {
664
+ var origWidth = props.width,
665
+ children = props.children,
666
+ containerWidth = props.containerWidth,
667
+ fullWidthMode = props.fullWidthMode,
668
+ layout = props.layout,
669
+ selected = props.selected,
670
+ showLegacyNotification = props.showLegacyNotification,
671
+ className = props.className,
672
+ dispatchAnalyticsEvent = props.dispatchAnalyticsEvent,
673
+ editorAppearance = props.editorAppearance,
674
+ getPos = props.getPos,
675
+ lineLength = props.lineLength,
676
+ mediaSingleWidth = props.mediaSingleWidth,
677
+ height = props.height,
678
+ nodeType = props.nodeType,
679
+ pluginInjectionApi = props.pluginInjectionApi,
680
+ updateSize = props.updateSize,
681
+ view = props.view,
682
+ viewMediaClientConfig = props.viewMediaClientConfig;
683
+ var initialWidth = (0, _react.useMemo)(function () {
684
+ return mediaSingleWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH;
685
+ }, [mediaSingleWidth]);
686
+ var _useState = (0, _react.useState)({
687
+ width: initialWidth,
688
+ height: calcPxHeight({
689
+ newWidth: initialWidth,
690
+ previousWidth: initialWidth,
691
+ previousHeight: height
692
+ })
693
+ }),
694
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
695
+ dimensions = _useState2[0],
696
+ setDimensions = _useState2[1];
697
+ var dimensionsRef = (0, _react.useRef)(dimensions);
698
+ var lastSnappedGuidelineKeysRef = (0, _react.useRef)([]);
699
+ var _useState3 = (0, _react.useState)({}),
700
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
701
+ snaps = _useState4[0],
702
+ setSnaps = _useState4[1];
703
+ var _useState5 = (0, _react.useState)(false),
704
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
705
+ isResizing = _useState6[0],
706
+ setIsResizing = _useState6[1];
707
+ var _useState7 = (0, _react.useState)(true),
708
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
709
+ isVideoFile = _useState8[0],
710
+ setIsVideoFile = _useState8[1];
711
+ var nodePosition = (0, _react.useMemo)(function () {
712
+ if (typeof getPos !== 'function') {
713
+ return null;
714
+ }
715
+ var pos = getPos();
716
+ if (Number.isNaN(pos) || typeof pos !== 'number') {
717
+ return null;
718
+ }
719
+ return pos;
720
+ }, [getPos]);
721
+ var isNestedNode = (0, _react.useMemo)(function () {
722
+ if (nodePosition === null) {
723
+ return false;
724
+ }
725
+ var $pos = view.state.doc.resolve(nodePosition);
726
+ return !!($pos && $pos.depth !== 0);
727
+ }, [nodePosition, view]);
728
+ var maybeContainerWidth = containerWidth || origWidth;
729
+ var memoizedCss = (0, _react.useMemo)(function () {
730
+ return (0, _styled.wrapperStyle)({
731
+ layout: layout,
732
+ containerWidth: maybeContainerWidth,
733
+ fullWidthMode: fullWidthMode,
734
+ mediaSingleWidth: dimensions.width,
735
+ isNestedNode: isNestedNode,
736
+ isExtendedResizeExperienceOn: true
737
+ });
738
+ }, [layout, maybeContainerWidth, fullWidthMode, dimensions.width, isNestedNode]);
739
+ var maxWidth = (0, _react.useMemo)(function () {
740
+ if (!isResizing && isNestedNode) {
741
+ return undefined;
742
+ }
743
+ if (isNestedNode || fullWidthMode) {
744
+ return lineLength;
745
+ }
746
+ return calcMaxWidth({
747
+ containerWidth: containerWidth,
748
+ editorAppearance: editorAppearance
749
+ });
750
+ }, [isNestedNode, fullWidthMode, lineLength, editorAppearance, containerWidth, isResizing]);
751
+ var minWidth = calcMinWidth({
752
+ isVideoFile: isVideoFile,
753
+ contentWidth: lineLength
754
+ });
755
+
756
+ // while is not resizing, we take 100% as min-width if the container width is less than the min-width
757
+ var minViewWidth = isResizing ? minWidth : "min(".concat(minWidth, "px, 100%)");
758
+ var resizerNextClassName = (0, _react.useMemo)(function () {
759
+ // TODO: Clean up where this lives and how it gets generated
760
+ var classNameNext = (0, _classnames.default)(_styles.richMediaClassName, "image-".concat(layout), isResizing ? 'is-resizing' : 'not-resizing', className, {
761
+ 'richMedia-selected': selected,
762
+ 'rich-media-wrapped': layout === 'wrap-left' || layout === 'wrap-right'
763
+ });
764
+ return (0, _classnames.default)(classNameNext, _styles.resizerStyles);
765
+ }, [className, isResizing, layout, selected]);
766
+ var isInsideInlineLike = (0, _react.useMemo)(function () {
767
+ if (nodePosition === null) {
768
+ return false;
769
+ }
770
+ var $pos = view.state.doc.resolve(nodePosition);
771
+ var listItem = view.state.schema.nodes.listItem;
772
+ return !!(0, _utils2.findParentNodeOfTypeClosestToPos)($pos, [listItem]);
773
+ }, [nodePosition, view]);
774
+ var enable = (0, _react.useMemo)(function () {
775
+ return _ui.handleSides.reduce(function (acc, side) {
776
+ var oppositeSide = side === 'left' ? 'right' : 'left';
777
+ acc[side] = _utils.nonWrappedLayouts.concat("wrap-".concat(oppositeSide)).concat("align-".concat(_ui.imageAlignmentMap[oppositeSide])).indexOf(layout) > -1;
778
+ if (side === 'left' && isInsideInlineLike) {
779
+ acc[side] = false;
780
+ }
781
+ return acc;
782
+ }, {});
783
+ }, [layout, isInsideInlineLike]);
784
+ var defaultGuidelines = (0, _react.useMemo)(function () {
785
+ if (isNestedNode) {
786
+ return [];
787
+ }
788
+ return (0, _guideline.generateDefaultGuidelines)(lineLength, containerWidth, fullWidthMode);
789
+ }, [isNestedNode, lineLength, containerWidth, fullWidthMode]);
790
+ var relativeGuidesRef = (0, _react.useRef)({});
791
+ var guidelinesRef = (0, _react.useRef)([]);
792
+ var updateGuidelines = (0, _react.useCallback)(function () {
793
+ var _generateDynamicGuide2 = (0, _guideline.generateDynamicGuidelines)(view.state, lineLength, {
794
+ styles: {
795
+ lineStyle: 'dashed'
796
+ },
797
+ show: false
798
+ }),
799
+ relativeGuides = _generateDynamicGuide2.relativeGuides,
800
+ dynamicGuides = _generateDynamicGuide2.dynamicGuides;
801
+
802
+ // disable guidelines for nested media single node
803
+ var dynamicGuidelines = isNestedNode ? [] : dynamicGuides;
804
+ relativeGuidesRef.current = relativeGuides;
805
+ guidelinesRef.current = [].concat((0, _toConsumableArray2.default)(defaultGuidelines), (0, _toConsumableArray2.default)(dynamicGuidelines));
806
+ }, [view, lineLength, defaultGuidelines, isNestedNode]);
807
+ var isGuidelineEnabled = (0, _react.useMemo)(function () {
808
+ return !!(pluginInjectionApi !== null && pluginInjectionApi !== void 0 && pluginInjectionApi.guideline);
809
+ }, [pluginInjectionApi]);
810
+ var handleResizeStart = (0, _react.useCallback)(function () {
811
+ setIsResizing(true);
812
+ setIsResizingPluginState({
813
+ isResizing: true,
814
+ nodePosition: nodePosition,
815
+ initialWidth: dimensionsRef.current.width
816
+ })(view.state, view.dispatch);
817
+ if (isGuidelineEnabled) {
818
+ updateGuidelines();
819
+ }
820
+ }, [view, nodePosition, updateGuidelines, isGuidelineEnabled]);
821
+ var getRelativeGuides = (0, _react.useCallback)(function () {
822
+ var _pluginInjectionApi$g;
823
+ if (typeof nodePosition !== 'number') {
824
+ return [];
825
+ }
826
+ var guidelinePluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$g = pluginInjectionApi.guideline) === null || _pluginInjectionApi$g === void 0 || (_pluginInjectionApi$g = _pluginInjectionApi$g.sharedState) === null || _pluginInjectionApi$g === void 0 ? void 0 : _pluginInjectionApi$g.currentState();
827
+ var _ref8 = (guidelinePluginState === null || guidelinePluginState === void 0 ? void 0 : guidelinePluginState.rect) || {
828
+ top: 0,
829
+ left: 0
830
+ },
831
+ topOffset = _ref8.top;
832
+ var $pos = view.state.doc.resolve(nodePosition);
833
+ var relativeGuides = $pos && $pos.nodeAfter && dimensionsRef.current.width ? (0, _guideline.getRelativeGuidelines)(relativeGuidesRef.current, {
834
+ node: $pos.nodeAfter,
835
+ pos: $pos.pos
836
+ }, view, lineLength, topOffset, dimensionsRef.current) : [];
837
+ return relativeGuides;
838
+ }, [pluginInjectionApi, nodePosition, view, lineLength]);
839
+ var updateActiveGuidelines = (0, _react.useCallback)(function () {
840
+ var _pluginInjectionApi$g2;
841
+ var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
842
+ var guidelines = arguments.length > 1 ? arguments[1] : undefined;
843
+ var guidelineSnapsReference = arguments.length > 2 ? arguments[2] : undefined;
844
+ if (!guidelineSnapsReference.snaps.x) {
845
+ return;
846
+ }
847
+ var _findClosestSnap2 = (0, _guideline.findClosestSnap)(width, guidelineSnapsReference.snaps.x, guidelineSnapsReference.guidelineReference, _mediaSingle.MEDIA_SINGLE_SNAP_GAP),
848
+ gap = _findClosestSnap2.gap,
849
+ activeGuidelineKeys = _findClosestSnap2.keys;
850
+ var relativeGuidelines = activeGuidelineKeys.length ? [] : getRelativeGuides();
851
+ lastSnappedGuidelineKeysRef.current = activeGuidelineKeys.length ? activeGuidelineKeys : relativeGuidelines.map(function (rg) {
852
+ return rg.key;
853
+ });
854
+ var nextGuideLines = [].concat((0, _toConsumableArray2.default)((0, _guideline.getGuidelinesWithHighlights)(gap, _mediaSingle.MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines)), (0, _toConsumableArray2.default)(relativeGuidelines));
855
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$g2 = pluginInjectionApi.guideline) === null || _pluginInjectionApi$g2 === void 0 || (_pluginInjectionApi$g2 = _pluginInjectionApi$g2.actions) === null || _pluginInjectionApi$g2 === void 0 || _pluginInjectionApi$g2.displayGuideline(view)({
856
+ guidelines: nextGuideLines
857
+ });
858
+ }, [getRelativeGuides, pluginInjectionApi, view]);
859
+ var aspectRatioRef = (0, _react.useRef)(getAspectRatio({
860
+ width: props.width,
861
+ height: props.height
862
+ }));
863
+ var handleResize = (0, _react.useCallback)(function (size, delta) {
864
+ var _calculateSizeState = calculateSizeState({
865
+ layout: layout,
866
+ containerWidth: containerWidth,
867
+ lineLength: lineLength,
868
+ fullWidthMode: fullWidthMode,
869
+ isNestedNode: isNestedNode
870
+ })(size, delta, false, aspectRatioRef.current),
871
+ width = _calculateSizeState.width,
872
+ height = _calculateSizeState.height,
873
+ newLayout = _calculateSizeState.layout;
874
+ if (isGuidelineEnabled) {
875
+ var guidelineSnaps = (0, _guideline.getGuidelineSnaps)(guidelinesRef.current, lineLength, layout);
876
+ updateActiveGuidelines(width, guidelinesRef.current, guidelineSnaps);
877
+ var relativeSnaps = (0, _guideline.getRelativeGuideSnaps)(relativeGuidesRef.current, aspectRatioRef.current);
878
+ setSnaps({
879
+ x: [].concat((0, _toConsumableArray2.default)(guidelineSnaps.snaps.x || []), (0, _toConsumableArray2.default)(relativeSnaps))
880
+ });
881
+ }
882
+ setDimensions({
883
+ width: width,
884
+ height: height
885
+ });
886
+ updateSizeInPluginState({
887
+ width: width,
888
+ view: view
889
+ });
890
+ if (newLayout !== layout) {
891
+ updateSize(width, newLayout);
892
+ }
893
+ }, [view, updateSize, layout, isGuidelineEnabled, containerWidth, lineLength, fullWidthMode, isNestedNode, updateActiveGuidelines]);
894
+ var handleResizeStop = (0, _react.useCallback)(function (size, delta) {
895
+ var _pluginInjectionApi$g3;
896
+ if (typeof nodePosition !== 'number') {
897
+ return;
898
+ }
899
+ var _calculateSizeState2 = calculateSizeState({
900
+ layout: layout,
901
+ containerWidth: containerWidth,
902
+ lineLength: lineLength,
903
+ fullWidthMode: fullWidthMode,
904
+ isNestedNode: isNestedNode
905
+ })(size, delta, false, aspectRatioRef.current),
906
+ width = _calculateSizeState2.width,
907
+ height = _calculateSizeState2.height,
908
+ newLayout = _calculateSizeState2.layout;
909
+ if (dispatchAnalyticsEvent) {
910
+ var $pos = view.state.doc.resolve(nodePosition);
911
+ var event = (0, _analytics.getMediaResizeAnalyticsEvent)(nodeType || 'mediaSingle', {
912
+ width: width,
913
+ layout: newLayout,
914
+ widthType: 'pixel',
915
+ snapType: (0, _guideline.getGuidelineTypeFromKey)(lastSnappedGuidelineKeysRef.current, guidelinesRef.current),
916
+ parentNode: $pos ? $pos.parent.type.name : undefined,
917
+ inputMethod: 'mouse'
918
+ });
919
+ if (event) {
920
+ dispatchAnalyticsEvent(event);
921
+ }
922
+ }
923
+ setIsResizing(false);
924
+ setIsResizingPluginState({
925
+ isResizing: false
926
+ })(view.state, view.dispatch);
927
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$g3 = pluginInjectionApi.guideline) === null || _pluginInjectionApi$g3 === void 0 || (_pluginInjectionApi$g3 = _pluginInjectionApi$g3.actions) === null || _pluginInjectionApi$g3 === void 0 || _pluginInjectionApi$g3.displayGuideline(view)({
928
+ guidelines: []
929
+ });
930
+ var newWidth = width;
931
+ if (newLayout === 'full-width') {
932
+ // When a node reaches full width in current viewport,
933
+ // update its width with 1800 to align with pixel entry
934
+ newWidth = _editorSharedStyles.akEditorFullWidthLayoutWidth;
935
+ }
936
+ setDimensions({
937
+ width: newWidth,
938
+ height: height
939
+ });
940
+ updateSize(newWidth, newLayout);
941
+ }, [nodeType, dispatchAnalyticsEvent, containerWidth, fullWidthMode, isNestedNode, layout, lineLength, view, nodePosition, pluginInjectionApi, updateSize]);
942
+ var mountedRef = _react.default.useRef(true);
943
+ (0, _react.useLayoutEffect)(function () {
944
+ mountedRef.current = true;
945
+ return function () {
946
+ mountedRef.current = false;
947
+ };
948
+ }, []);
949
+ (0, _react.useLayoutEffect)(function () {
950
+ setDimensions({
951
+ width: initialWidth,
952
+ height: calcPxHeight({
953
+ newWidth: initialWidth,
954
+ previousWidth: initialWidth,
955
+ previousHeight: height
956
+ })
957
+ });
958
+ }, [initialWidth, height]);
959
+ (0, _react.useEffect)(function () {
960
+ dimensionsRef.current = dimensions;
961
+ }, [dimensions]);
962
+ (0, _react.useEffect)(function () {
963
+ if (!viewMediaClientConfig || typeof nodePosition !== 'number') {
964
+ return;
965
+ }
966
+ var mediaNode = view.state.doc.nodeAt(nodePosition + 1);
967
+ if (!mediaNode) {
968
+ return;
969
+ }
970
+ (0, _checkMediaType.checkMediaType)(mediaNode, viewMediaClientConfig).then(function (mediaType) {
971
+ if (mountedRef.current) {
972
+ var _isVideoFile = mediaType !== 'external' && mediaType !== 'image';
973
+ setIsVideoFile(_isVideoFile);
974
+ }
975
+ });
976
+ }, [view, viewMediaClientConfig, nodePosition]);
977
+ return (0, _react2.jsx)("div", {
978
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/consistent-css-prop-usage -- Ignored via go/DSP-18766
979
+ css: memoizedCss
980
+ }, (0, _react2.jsx)(_resizer.ResizerNext, {
981
+ minWidth: minViewWidth,
982
+ maxWidth: maxWidth
983
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
984
+ ,
985
+ className: resizerNextClassName,
986
+ snapGap: _mediaSingle.MEDIA_SINGLE_SNAP_GAP,
987
+ enable: enable,
988
+ width: dimensions.width,
989
+ handleResizeStart: handleResizeStart,
990
+ handleResize: handleResize,
991
+ handleResizeStop: handleResizeStop,
992
+ snap: snaps,
993
+ resizeRatio: _utils.nonWrappedLayouts.includes(layout) ? 2 : 1,
994
+ "data-testid": resizerNextTestId,
995
+ isHandleVisible: selected,
996
+ handlePositioning: isNestedNode ? 'adjacent' : undefined,
997
+ handleHighlight: "full-height"
998
+ }, children, showLegacyNotification && (0, _react2.jsx)(_ResizableMediaMigrationNotification.ResizableMediaMigrationNotification, null)));
999
+ };
1000
+ var ResizableMediaSingleToggle = function ResizableMediaSingleToggle(_ref9) {
1001
+ var allowBreakoutSnapPoints = _ref9.allowBreakoutSnapPoints,
1002
+ children = _ref9.children,
1003
+ className = _ref9.className,
1004
+ containerWidth = _ref9.containerWidth,
1005
+ dataAttributes = _ref9.dataAttributes,
1006
+ disableHandles = _ref9.disableHandles,
1007
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent,
1008
+ editorAppearance = _ref9.editorAppearance,
1009
+ fullWidthMode = _ref9.fullWidthMode,
1010
+ getPos = _ref9.getPos,
1011
+ gridSize = _ref9.gridSize,
1012
+ handleMediaSingleRef = _ref9.handleMediaSingleRef,
1013
+ hasFallbackContainer = _ref9.hasFallbackContainer,
1014
+ height = _ref9.height,
1015
+ isInsideOfInlineExtension = _ref9.isInsideOfInlineExtension,
1016
+ isLoading = _ref9.isLoading,
1017
+ layout = _ref9.layout,
1018
+ lineLength = _ref9.lineLength,
1019
+ mediaSingleWidth = _ref9.mediaSingleWidth,
1020
+ nodeType = _ref9.nodeType,
1021
+ pctWidth = _ref9.pctWidth,
1022
+ pluginInjectionApi = _ref9.pluginInjectionApi,
1023
+ selected = _ref9.selected,
1024
+ showLegacyNotification = _ref9.showLegacyNotification,
1025
+ size = _ref9.size,
1026
+ updateSize = _ref9.updateSize,
1027
+ view = _ref9.view,
1028
+ viewMediaClientConfig = _ref9.viewMediaClientConfig,
1029
+ width = _ref9.width;
1030
+ if ((0, _platformFeatureFlags.fg)('platform_editor_react18_phase2__media_single')) {
1031
+ return (0, _react2.jsx)(ResizableMediaSingleNextFunctional, {
1032
+ allowBreakoutSnapPoints: allowBreakoutSnapPoints,
1033
+ children: children
1034
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1035
+ ,
1036
+ className: className,
1037
+ containerWidth: containerWidth,
1038
+ dataAttributes: dataAttributes,
1039
+ disableHandles: disableHandles,
1040
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
1041
+ editorAppearance: editorAppearance,
1042
+ fullWidthMode: fullWidthMode,
1043
+ getPos: getPos,
1044
+ gridSize: gridSize,
1045
+ handleMediaSingleRef: handleMediaSingleRef,
1046
+ hasFallbackContainer: hasFallbackContainer,
1047
+ height: height,
1048
+ isInsideOfInlineExtension: isInsideOfInlineExtension,
1049
+ isLoading: isLoading,
1050
+ layout: layout,
1051
+ lineLength: lineLength,
1052
+ mediaSingleWidth: mediaSingleWidth,
1053
+ nodeType: nodeType,
1054
+ pctWidth: pctWidth,
1055
+ pluginInjectionApi: pluginInjectionApi,
1056
+ selected: selected,
1057
+ showLegacyNotification: showLegacyNotification,
1058
+ size: size,
1059
+ updateSize: updateSize,
1060
+ view: view,
1061
+ viewMediaClientConfig: viewMediaClientConfig,
1062
+ width: width
1063
+ });
1064
+ }
1065
+ return (0, _react2.jsx)(ResizableMediaSingleNext, {
1066
+ allowBreakoutSnapPoints: allowBreakoutSnapPoints,
1067
+ children: children
1068
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
1069
+ ,
1070
+ className: className,
1071
+ containerWidth: containerWidth,
1072
+ dataAttributes: dataAttributes,
1073
+ disableHandles: disableHandles,
1074
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
1075
+ editorAppearance: editorAppearance,
1076
+ fullWidthMode: fullWidthMode,
1077
+ getPos: getPos,
1078
+ gridSize: gridSize,
1079
+ handleMediaSingleRef: handleMediaSingleRef,
1080
+ hasFallbackContainer: hasFallbackContainer,
1081
+ height: height,
1082
+ isInsideOfInlineExtension: isInsideOfInlineExtension,
1083
+ isLoading: isLoading,
1084
+ layout: layout,
1085
+ lineLength: lineLength,
1086
+ mediaSingleWidth: mediaSingleWidth,
1087
+ nodeType: nodeType,
1088
+ pctWidth: pctWidth,
1089
+ pluginInjectionApi: pluginInjectionApi,
1090
+ selected: selected,
1091
+ showLegacyNotification: showLegacyNotification,
1092
+ size: size,
1093
+ updateSize: updateSize,
1094
+ view: view,
1095
+ viewMediaClientConfig: viewMediaClientConfig,
1096
+ width: width
1097
+ });
1098
+ };
1099
+ var _default = exports.default = ResizableMediaSingleToggle;
@@ -625,7 +625,6 @@ export class MediaPluginStateImplementation {
625
625
  export const getMediaPluginState = state => stateKey.getState(state);
626
626
  export const createPlugin = (_schema, options, getIntl, pluginInjectionApi, dispatch, mediaOptions, newInsertionBehaviour) => {
627
627
  const intl = getIntl();
628
- const dropPlaceholder = createDropPlaceholder(intl, mediaOptions && mediaOptions.allowDropzoneDropLine);
629
628
  return new SafePlugin({
630
629
  state: {
631
630
  init(_config, state) {
@@ -764,8 +763,15 @@ export const createPlugin = (_schema, options, getIntl, pluginInjectionApi, disp
764
763
  if (pos === null || pos === undefined) {
765
764
  return DecorationSet.create(state.doc, mediaNodes);
766
765
  }
767
- const dropPlaceholders = [Decoration.widget(pos, dropPlaceholder, {
768
- key: 'drop-placeholder'
766
+ const dropPlaceholders = [Decoration.widget(pos, () => {
767
+ return createDropPlaceholder(intl, mediaOptions && mediaOptions.allowDropzoneDropLine);
768
+ }, {
769
+ key: 'drop-placeholder',
770
+ destroy: elem => {
771
+ if (elem instanceof HTMLElement) {
772
+ ReactDOM.unmountComponentAtNode(elem);
773
+ }
774
+ }
769
775
  }), ...mediaNodes];
770
776
  return DecorationSet.create(state.doc, dropPlaceholders);
771
777
  },