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