@atlaskit/editor-core 187.14.4 → 187.14.8

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,27 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 187.14.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8fe864e4f7a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8fe864e4f7a) - [ux] ED-19336: Fixed insert column button not visible when sticky header is enabled."
8
+ - [`4cbae03c15c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4cbae03c15c) - Set maxWidth for ResizerNext to stop lable updating when reaching max width
9
+
10
+ ## 187.14.7
11
+
12
+ ### Patch Changes
13
+
14
+ - [`3bbe8f91f34`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3bbe8f91f34) - refactor ResizableMediaSingleNext around guidelines and snapping
15
+ - [`a675f834911`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a675f834911) - Introduce `commands` optional parameter to `NextEditorPlugin`. It can be used similarly to `actions` in `NextEditorPlugin` but `commands` must adhere to the type of `PluginCommand`:
16
+
17
+ ```ts
18
+ type PluginCommand = ({ tr }: { tr: Transaction }) => Transaction | null;
19
+ ```
20
+
21
+ `PluginCommand`s are specifically used for code that is executed to modify a Transaction. They should be used in preference to the existing prosemirror `Command` type.
22
+
23
+ - Updated dependencies
24
+
3
25
  ## 187.14.4
4
26
 
5
27
  ### Patch Changes
@@ -19,6 +19,7 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
19
19
  var _reactIntlNext = require("react-intl-next");
20
20
  var _picker = require("@atlaskit/emoji/picker");
21
21
  var _ui = require("@atlaskit/editor-common/ui");
22
+ var _preset = require("@atlaskit/editor-common/preset");
22
23
  var _ToolbarButton = _interopRequireDefault(require("../../../../ui/ToolbarButton"));
23
24
  var _styles = require("@atlaskit/editor-common/styles");
24
25
  var _actions = require("../../../date/actions");
@@ -177,7 +178,9 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
177
178
  pluginInjectionApi = _this$props.pluginInjectionApi;
178
179
  var state = editorView.state,
179
180
  dispatch = editorView.dispatch;
180
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions.showLinkToolbar(inputMethod)(state, dispatch);
181
+
182
+ // We should update this to use `pluginInjectionApi.executeCommand` once available
183
+ (0, _preset.pluginCommandToPMCommand)(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.commands.showLinkToolbar(inputMethod))(state, dispatch);
181
184
  return true;
182
185
  });
183
186
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertMention", function (inputMethod) {
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = exports.ReactMediaSingleNode = void 0;
9
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
10
  var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
11
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
13
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
14
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -247,11 +248,17 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
247
248
  }
248
249
  (0, _captions.insertAndSelectCaptionFromMediaSinglePos)(getPos(), node)(view.state, view.dispatch);
249
250
  });
250
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getLineLength", function (view, pos) {
251
+ /**
252
+ * Get parent width for a nested media single node
253
+ * @param view Editor view
254
+ * @param pos node position
255
+ * @param includeMoreParentNodeTypes should consider table and list as parent nodes(only true for new experience)
256
+ */
257
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getLineLength", function (view, pos, includeMoreParentNodeTypes) {
251
258
  if (typeof pos !== 'number') {
252
259
  return null;
253
260
  }
254
- if ((0, _utils.isRichMediaInsideOfBlockNode)(view, pos)) {
261
+ if ((0, _utils.isRichMediaInsideOfBlockNode)(view, pos, includeMoreParentNodeTypes)) {
255
262
  var $pos = view.state.doc.resolve(pos);
256
263
  var domNode = view.nodeDOM($pos.pos);
257
264
  if ($pos.nodeAfter && _utils.floatingLayouts.indexOf($pos.nodeAfter.attrs.layout) > -1 && domNode && domNode.parentElement) {
@@ -363,7 +370,8 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
363
370
  height = _mediaSingle.DEFAULT_IMAGE_HEIGHT;
364
371
  }
365
372
  var isSelected = selected();
366
- var contentWidth = this.getLineLength(view, getPos()) || lineLength;
373
+ var contentWidthForLegacyExperience = this.getLineLength(view, getPos()) || lineLength;
374
+ var contentWidth = this.getLineLength(view, getPos(), true) || lineLength;
367
375
  var mediaSingleProps = {
368
376
  layout: layout,
369
377
  width: width,
@@ -378,7 +386,9 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
378
386
  widthType: widthType,
379
387
  origWidth: width,
380
388
  layout: layout,
381
- contentWidth: contentWidth,
389
+ // This will only be used when calculating legacy media single width
390
+ // thus we use the legecy value (exclude table as container node)
391
+ contentWidth: contentWidthForLegacyExperience,
382
392
  containerWidth: containerWidth,
383
393
  gutterOffset: _mediaSingle.MEDIA_SINGLE_GUTTER_SIZE
384
394
  })
@@ -417,7 +427,9 @@ var MediaSingleNode = /*#__PURE__*/function (_Component) {
417
427
  ref: this.captionPlaceHolderRef,
418
428
  onClick: this.clickPlaceholder
419
429
  }));
420
- return canResize ? (0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.extended-resize-experience') ? (0, _react.jsx)(_ResizableMediaSingleNext.default, ResizableMediaSingleProps, MediaChildren) : (0, _react.jsx)(_ResizableMediaSingle.default, ResizableMediaSingleProps, MediaChildren) : (0, _react.jsx)(_ui.MediaSingle, mediaSingleProps, MediaChildren);
430
+ return canResize ? (0, _platformFeatureFlags.getBooleanFF)('platform.editor.media.extended-resize-experience') ? (0, _react.jsx)(_ResizableMediaSingleNext.default, ResizableMediaSingleProps, MediaChildren) : (0, _react.jsx)(_ResizableMediaSingle.default, (0, _extends2.default)({}, ResizableMediaSingleProps, {
431
+ lineLength: contentWidthForLegacyExperience
432
+ }), MediaChildren) : (0, _react.jsx)(_ui.MediaSingle, mediaSingleProps, MediaChildren);
421
433
  }
422
434
  }]);
423
435
  return MediaSingleNode;
@@ -32,6 +32,7 @@ var _classnames = _interopRequireDefault(require("classnames"));
32
32
  var _styles = require("@atlaskit/editor-common/styles");
33
33
  var _mediaSingle = require("@atlaskit/editor-common/media-single");
34
34
  var _guideline = require("@atlaskit/editor-common/guideline");
35
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
35
36
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
36
37
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } /** @jsx jsx */
37
38
  var resizerNextTestId = 'mediaSingle.resizerNext.testid';
@@ -58,12 +59,28 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
58
59
  var _this;
59
60
  (0, _classCallCheck2.default)(this, ResizableMediaSingleNext);
60
61
  _this = _super.call(this, props);
61
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcNewSize", function (newWidth, stop) {
62
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "guidelines", []);
63
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getAllGuidelines", function () {
62
64
  var _this$props = _this.props,
63
- layout = _this$props.layout,
64
- state = _this$props.view.state,
65
- containerWidth = _this$props.containerWidth,
65
+ view = _this$props.view,
66
66
  lineLength = _this$props.lineLength;
67
+ var defaultGuidelines = _this.getDefaultGuidelines();
68
+ // disable guidelines for nested media single node
69
+ var dynamicGuidelines = _this.isNestedNode() ? [] : (0, _guideline.generateDynamicGuidelines)(view.state, lineLength, {
70
+ styles: {
71
+ lineStyle: 'dashed'
72
+ },
73
+ show: false
74
+ });
75
+ var guidelines = [].concat((0, _toConsumableArray2.default)(defaultGuidelines), (0, _toConsumableArray2.default)(dynamicGuidelines));
76
+ return guidelines;
77
+ });
78
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcNewSize", function (newWidth, stop) {
79
+ var _this$props2 = _this.props,
80
+ layout = _this$props2.layout,
81
+ state = _this$props2.view.state,
82
+ containerWidth = _this$props2.containerWidth,
83
+ lineLength = _this$props2.lineLength;
67
84
  var newPct = (0, _ui.calcPctFromPx)(newWidth, _this.props.lineLength) * 100;
68
85
  _this.setState({
69
86
  resizedPctWidth: newPct
@@ -102,10 +119,10 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
102
119
  return _this.insideInlineLike ? (0, _ui.calcColumnsFromPx)(offsetLeft, _this.props.lineLength, _this.props.gridSize) : 0;
103
120
  });
104
121
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcPxHeight", function (newWidth) {
105
- var _this$props2 = _this.props,
106
- _this$props2$width = _this$props2.width,
107
- width = _this$props2$width === void 0 ? newWidth : _this$props2$width,
108
- height = _this$props2.height;
122
+ var _this$props3 = _this.props,
123
+ _this$props3$width = _this$props3.width,
124
+ width = _this$props3$width === void 0 ? newWidth : _this$props3$width,
125
+ height = _this$props3.height;
109
126
  return Math.round(height / width * newWidth);
110
127
  });
111
128
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "saveWrapper", function (wrapper) {
@@ -126,6 +143,111 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
126
143
  tr.setMeta('mediaSinglePlugin.isResizing', isResizing);
127
144
  return dispatch(tr);
128
145
  });
146
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcMaxWidth", (0, _memoizeOne.default)(function (contentWidth, containerWidth, fullWidthMode) {
147
+ if (_this.isNestedNode() || fullWidthMode) {
148
+ return contentWidth;
149
+ }
150
+ return (0, _mediaSingle.calcMediaSingleMaxWidth)(containerWidth);
151
+ }));
152
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateActiveGuidelines", function () {
153
+ var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
154
+ var guidelines = arguments.length > 1 ? arguments[1] : undefined;
155
+ var guidelineSnapsReference = arguments.length > 2 ? arguments[2] : undefined;
156
+ if (guidelineSnapsReference.snaps.x) {
157
+ var _findClosestSnap = (0, _guideline.findClosestSnap)(width, guidelineSnapsReference.snaps.x, guidelineSnapsReference.guidelineReference, _mediaSingle.MEDIA_SINGLE_SNAP_GAP),
158
+ gap = _findClosestSnap.gap,
159
+ activeGuidelineKeys = _findClosestSnap.keys;
160
+ _this.displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _mediaSingle.MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines));
161
+ }
162
+ });
163
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "roundPixelValue", function (value) {
164
+ return Math.round(value);
165
+ });
166
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getHeightFromNewWidth", function (originalWidth, originalHeight, newWidth) {
167
+ return _this.roundPixelValue(originalHeight / originalWidth * newWidth);
168
+ });
169
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calculateSizeState", function (size, delta) {
170
+ var originalWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
171
+ var originalHeight = arguments.length > 3 ? arguments[3] : undefined;
172
+ var onResizeStop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
173
+ var calculatedWidth = _this.roundPixelValue(size.width + delta.width);
174
+ var calculatedWidthWithLayout = _this.calcNewSize(calculatedWidth, onResizeStop);
175
+ var calculatedHeightWithLayout = _this.getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
176
+ return {
177
+ width: calculatedWidth,
178
+ height: calculatedHeightWithLayout,
179
+ calculatedWidthWithLayout: calculatedWidthWithLayout
180
+ };
181
+ });
182
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "selectCurrentMediaNode", function () {
183
+ // TODO: if adding !this.props.selected, it doesn't work if media single node is at top postion
184
+ if (typeof _this.props.getPos === 'function') {
185
+ var propPos = _this.props.getPos();
186
+ if (propPos !== undefined) {
187
+ (0, _utils2.setNodeSelection)(_this.props.view, propPos);
188
+ }
189
+ }
190
+ });
191
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleResizeStart", function () {
192
+ _this.setState({
193
+ isResizing: true
194
+ });
195
+ _this.selectCurrentMediaNode();
196
+ _this.setIsResizing(true);
197
+ // re-calucate guidelines
198
+ _this.guidelines = _this.getAllGuidelines();
199
+ return 0;
200
+ });
201
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleResize", function (size, delta) {
202
+ var _this$props4 = _this.props,
203
+ originalWidth = _this$props4.width,
204
+ originalHeight = _this$props4.height,
205
+ layout = _this$props4.layout,
206
+ updateSize = _this$props4.updateSize,
207
+ lineLength = _this$props4.lineLength;
208
+ var _this$calculateSizeSt = _this.calculateSizeState(size, delta, originalWidth, originalHeight),
209
+ width = _this$calculateSizeSt.width,
210
+ height = _this$calculateSizeSt.height,
211
+ calculatedWidthWithLayout = _this$calculateSizeSt.calculatedWidthWithLayout;
212
+ var guidelineSnaps = (0, _guideline.getGuidelineSnaps)(_this.guidelines, lineLength, layout);
213
+ _this.updateActiveGuidelines(width, _this.guidelines, guidelineSnaps);
214
+ _this.setState({
215
+ size: {
216
+ width: width,
217
+ height: height
218
+ },
219
+ snaps: guidelineSnaps.snaps
220
+ });
221
+ if (calculatedWidthWithLayout.layout !== layout) {
222
+ updateSize(width, calculatedWidthWithLayout.layout);
223
+ }
224
+ });
225
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handleResizeStop", function (size, delta) {
226
+ var _this$props5 = _this.props,
227
+ originalWidth = _this$props5.width,
228
+ originalHeight = _this$props5.height,
229
+ updateSize = _this$props5.updateSize,
230
+ dispatchAnalyticsEvent = _this$props5.dispatchAnalyticsEvent,
231
+ nodeType = _this$props5.nodeType;
232
+ var _this$calculateSizeSt2 = _this.calculateSizeState(size, delta, originalWidth, originalHeight, true),
233
+ width = _this$calculateSizeSt2.width,
234
+ height = _this$calculateSizeSt2.height,
235
+ calculatedWidthWithLayout = _this$calculateSizeSt2.calculatedWidthWithLayout;
236
+ _this.setIsResizing(false);
237
+ _this.displayGuideline([]);
238
+ if (dispatchAnalyticsEvent) {
239
+ dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
240
+ }
241
+ _this.setState({
242
+ isResizing: false,
243
+ size: {
244
+ width: width,
245
+ height: height
246
+ }
247
+ }, function () {
248
+ updateSize(width, calculatedWidthWithLayout.layout);
249
+ });
250
+ });
129
251
  var initialWidth = props.mediaSingleWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH;
130
252
  _this.state = {
131
253
  offsetLeft: (0, _mediaSingle.calculateOffsetLeft)(_this.insideInlineLike, _this.insideLayout, _this.props.view.dom, undefined),
@@ -135,7 +257,8 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
135
257
  size: {
136
258
  width: initialWidth,
137
259
  height: _this.calcPxHeight(initialWidth)
138
- }
260
+ },
261
+ snaps: {}
139
262
  };
140
263
  return _this;
141
264
  }
@@ -149,15 +272,15 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
149
272
  (0, _createClass2.default)(ResizableMediaSingleNext, [{
150
273
  key: "calcInitialWidth",
151
274
  value: function calcInitialWidth() {
152
- var _this$props3 = this.props,
153
- origWidth = _this$props3.width,
154
- contentWidth = _this$props3.lineLength,
155
- containerWidth = _this$props3.containerWidth;
275
+ var _this$props6 = this.props,
276
+ origWidth = _this$props6.width,
277
+ contentWidth = _this$props6.lineLength,
278
+ containerWidth = _this$props6.containerWidth;
156
279
  return Math.max(Math.min(origWidth || _mediaSingle.DEFAULT_IMAGE_WIDTH, contentWidth || containerWidth || _editorSharedStyles.akEditorDefaultLayoutWidth), _mediaSingle.MEDIA_SINGLE_MIN_PIXEL_WIDTH);
157
280
  }
158
281
  }, {
159
282
  key: "componentDidUpdate",
160
- value: function componentDidUpdate(prevProps, prevState) {
283
+ value: function componentDidUpdate(prevProps) {
161
284
  var offsetLeft = (0, _mediaSingle.calculateOffsetLeft)(this.insideInlineLike, this.insideLayout, this.props.view.dom, this.wrapper);
162
285
  if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
163
286
  this.setState({
@@ -172,10 +295,6 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
172
295
  resizedPctWidth: this.props.pctWidth
173
296
  });
174
297
  }
175
- if (prevState.isResizing !== this.state.isResizing && this.state.isResizing) {
176
- var guidelines = this.getDefaultGuidelines();
177
- this.displayGuideline(guidelines);
178
- }
179
298
  if (prevProps.mediaSingleWidth !== this.props.mediaSingleWidth && this.props.mediaSingleWidth) {
180
299
  // update size when lineLength becomes defined later
181
300
  // ensures extended experience renders legacy image with the same size as the legacy experience
@@ -199,78 +318,14 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
199
318
  }, {
200
319
  key: "getDefaultGuidelines",
201
320
  value: function getDefaultGuidelines() {
202
- var _this$props4 = this.props,
203
- lineLength = _this$props4.lineLength,
204
- containerWidth = _this$props4.containerWidth,
205
- fullWidthMode = _this$props4.fullWidthMode;
321
+ var _this$props7 = this.props,
322
+ lineLength = _this$props7.lineLength,
323
+ containerWidth = _this$props7.containerWidth,
324
+ fullWidthMode = _this$props7.fullWidthMode;
206
325
 
207
326
  // disable guidelines for nested media single node
208
327
  return this.isNestedNode() ? [] : (0, _guideline.generateDefaultGuidelines)(lineLength, containerWidth, fullWidthMode);
209
328
  }
210
-
211
- // Calculate width of media nodes for snaps based on dynamic guidelines
212
- // TODO: refactor this later, maybe use state to hold snaps array
213
- }, {
214
- key: "getSnaps",
215
- value: function getSnaps() {
216
- var _this$props5 = this.props,
217
- view = _this$props5.view,
218
- lineLength = _this$props5.lineLength;
219
- var dom = view.dom;
220
- var defaultGuidelines = this.getDefaultGuidelines();
221
- // disable guidelines for nested media single node
222
- var dynamicGuidelines = this.isNestedNode() ? [] : (0, _guideline.generateDynamicGuidelines)(view.state, lineLength, {
223
- styles: {
224
- lineStyle: 'dashed'
225
- },
226
- show: false
227
- });
228
- var guidelines = [].concat((0, _toConsumableArray2.default)(defaultGuidelines), (0, _toConsumableArray2.default)(dynamicGuidelines));
229
- var mediaSingleSelector = 'div.mediaSingleView-content-wrap.ProseMirror-selectednode';
230
- var _dom$getBoundingClien = dom.getBoundingClientRect(),
231
- width = _dom$getBoundingClien.width;
232
- var halfWidth = width / 2;
233
- var selectedMedia = dom.querySelector(mediaSingleSelector);
234
- if (selectedMedia) {
235
- var pixelWidth = parseFloat(selectedMedia.getAttribute('width') || '') || 0;
236
- var layout = selectedMedia.getAttribute('layout');
237
- var snap = 0;
238
- switch (layout) {
239
- case 'align-start':
240
- case 'wrap-left':
241
- snap = pixelWidth - halfWidth;
242
- break;
243
- case 'align-end':
244
- case 'wrap-right':
245
- snap = width - pixelWidth - halfWidth;
246
- break;
247
- case 'center':
248
- case 'wide':
249
- case 'full-width':
250
- snap = -pixelWidth / 2;
251
- break;
252
- // we ingnore full-width and wide
253
- default:
254
- snap = 0;
255
- }
256
- var snapWidths = (0, _guideline.getSnapWidth)(guidelines, pixelWidth, snap, layout);
257
- var snapToWidths = snapWidths.map(function (s) {
258
- return s && s.width;
259
- });
260
-
261
- // update guidelines
262
- if (this.state.isResizing) {
263
- var _findClosestSnap = (0, _guideline.findClosestSnap)(this.state.size.width, snapToWidths, snapWidths, _mediaSingle.MEDIA_SINGLE_HIGHLIGHT_GAP),
264
- gap = _findClosestSnap.gap,
265
- activeGuidelineKeys = _findClosestSnap.keys;
266
- this.displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _mediaSingle.MEDIA_SINGLE_HIGHLIGHT_GAP, activeGuidelineKeys, guidelines));
267
- }
268
- return snapToWidths.length > 0 ? {
269
- x: snapToWidths
270
- } : {};
271
- }
272
- return {};
273
- }
274
329
  }, {
275
330
  key: "wrappedLayout",
276
331
  get: function get() {
@@ -411,15 +466,16 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
411
466
  key: "render",
412
467
  value: function render() {
413
468
  var _this2 = this;
414
- var _this$props6 = this.props,
415
- origWidth = _this$props6.width,
416
- layout = _this$props6.layout,
417
- pctWidth = _this$props6.pctWidth,
418
- containerWidth = _this$props6.containerWidth,
419
- fullWidthMode = _this$props6.fullWidthMode,
420
- selected = _this$props6.selected,
421
- children = _this$props6.children,
422
- intl = _this$props6.intl;
469
+ var _this$props8 = this.props,
470
+ origWidth = _this$props8.width,
471
+ layout = _this$props8.layout,
472
+ pctWidth = _this$props8.pctWidth,
473
+ containerWidth = _this$props8.containerWidth,
474
+ fullWidthMode = _this$props8.fullWidthMode,
475
+ selected = _this$props8.selected,
476
+ children = _this$props8.children,
477
+ intl = _this$props8.intl,
478
+ lineLength = _this$props8.lineLength;
423
479
  var _this$state = this.state,
424
480
  isResizing = _this$state.isResizing,
425
481
  size = _this$state.size;
@@ -432,99 +488,6 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
432
488
  }
433
489
  });
434
490
 
435
- /**
436
- * NEW REFACTOR
437
- */
438
- var roundPixelValue = function roundPixelValue(value) {
439
- return Math.round(value);
440
- };
441
- var getHeightFromNewWidth = function getHeightFromNewWidth(originalWidth, originalHeight, newWidth) {
442
- return roundPixelValue(originalHeight / originalWidth * newWidth);
443
- };
444
- var calculateSizeState = function calculateSizeState(size, delta) {
445
- var originalWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
446
- var originalHeight = arguments.length > 3 ? arguments[3] : undefined;
447
- var onResizeStop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
448
- var calculatedWidth = roundPixelValue(size.width + delta.width);
449
- var calculatedWidthWithLayout = _this2.calcNewSize(calculatedWidth, onResizeStop);
450
- var calculatedHeightWithLayout = getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
451
- return {
452
- width: calculatedWidth,
453
- height: calculatedHeightWithLayout,
454
- calculatedWidthWithLayout: calculatedWidthWithLayout
455
- };
456
- };
457
- var selectCurrentMediaNode = function selectCurrentMediaNode() {
458
- if (!_this2.props.selected && typeof _this2.props.getPos === 'function') {
459
- var propPos = _this2.props.getPos();
460
- if (propPos !== undefined) {
461
- (0, _utils2.setNodeSelection)(_this2.props.view, propPos);
462
- }
463
- }
464
- };
465
- var handleResizeStart = function handleResizeStart() {
466
- _this2.setState({
467
- isResizing: true
468
- });
469
- selectCurrentMediaNode();
470
- _this2.setIsResizing(true);
471
-
472
- // TODO: Update once type updated from editor common resizer
473
- return 0;
474
- };
475
- var handleResize = function handleResize(size, delta) {
476
- var _this2$props = _this2.props,
477
- originalWidth = _this2$props.width,
478
- originalHeight = _this2$props.height,
479
- layout = _this2$props.layout,
480
- updateSize = _this2$props.updateSize;
481
- var _calculateSizeState = calculateSizeState(size, delta, originalWidth, originalHeight),
482
- width = _calculateSizeState.width,
483
- height = _calculateSizeState.height,
484
- calculatedWidthWithLayout = _calculateSizeState.calculatedWidthWithLayout;
485
- _this2.setState({
486
- size: {
487
- width: width,
488
- height: height
489
- }
490
- });
491
- if (calculatedWidthWithLayout.layout !== layout) {
492
- updateSize(width, calculatedWidthWithLayout.layout);
493
- }
494
-
495
- // TODO: Update once type updated from editor common resizer
496
- return 0;
497
- };
498
- var handleResizeStop = function handleResizeStop(size, delta) {
499
- var _this2$props2 = _this2.props,
500
- originalWidth = _this2$props2.width,
501
- originalHeight = _this2$props2.height,
502
- updateSize = _this2$props2.updateSize,
503
- dispatchAnalyticsEvent = _this2$props2.dispatchAnalyticsEvent,
504
- nodeType = _this2$props2.nodeType;
505
- var _calculateSizeState2 = calculateSizeState(size, delta, originalWidth, originalHeight, true),
506
- width = _calculateSizeState2.width,
507
- height = _calculateSizeState2.height,
508
- calculatedWidthWithLayout = _calculateSizeState2.calculatedWidthWithLayout;
509
- _this2.setIsResizing(false);
510
- _this2.displayGuideline([]);
511
- if (dispatchAnalyticsEvent) {
512
- dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
513
- }
514
- _this2.setState({
515
- isResizing: false,
516
- size: {
517
- width: width,
518
- height: height
519
- }
520
- }, function () {
521
- updateSize(width, calculatedWidthWithLayout.layout);
522
- });
523
-
524
- // TODO: Update once type updated from editor common resizer
525
- return 0;
526
- };
527
-
528
491
  // TODO: Clean up where this lives and how it gets generated
529
492
  var className = (0, _classnames.default)(_styles.richMediaClassName, "image-".concat(layout), isResizing ? 'is-resizing' : 'not-resizing', this.props.className, {
530
493
  'not-resized': !pctWidth,
@@ -534,6 +497,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
534
497
  var resizerNextClassName = (0, _classnames.default)(className, _styles.resizerStyles);
535
498
  var showSizeGuide = selected || isResizing;
536
499
  var label = layout === 'full-width' ? intl.formatMessage(_resizableMediaSingleMessages.messages.fullWidthImage) : "".concat(this.state.size.width, " x ").concat(this.state.size.height);
500
+ var maxWidth = this.calcMaxWidth(lineLength, containerWidth, fullWidthMode);
537
501
  return (0, _react2.jsx)("div", {
538
502
  ref: this.saveWrapper,
539
503
  css: (0, _styled.wrapperStyle)({
@@ -547,14 +511,15 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
547
511
  })
548
512
  }, (0, _react2.jsx)(_resizer.ResizerNext, {
549
513
  minWidth: _mediaSingle.MEDIA_SINGLE_MIN_PIXEL_WIDTH,
514
+ maxWidth: maxWidth,
550
515
  className: resizerNextClassName,
551
516
  snapGap: _mediaSingle.MEDIA_SINGLE_SNAP_GAP,
552
517
  enable: enable,
553
518
  width: size.width,
554
- handleResizeStart: handleResizeStart,
555
- handleResize: handleResize,
556
- handleResizeStop: handleResizeStop,
557
- snap: this.getSnaps(),
519
+ handleResizeStart: this.handleResizeStart,
520
+ handleResize: this.handleResize,
521
+ handleResizeStop: this.handleResizeStop,
522
+ snap: this.state.snaps,
558
523
  resizeRatio: _utils2.nonWrappedLayouts.includes(layout) ? 2 : 1,
559
524
  "data-testid": resizerNextTestId
560
525
  }, showSizeGuide && (0, _react2.jsx)(_ResizeLabel.default, {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "187.14.4";
9
+ var version = "187.14.8";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.14.4",
3
+ "version": "187.14.8",
4
4
  "sideEffects": false
5
5
  }
@@ -6,6 +6,7 @@ import ReactDOM from 'react-dom';
6
6
  import { injectIntl } from 'react-intl-next';
7
7
  import { EmojiPicker as AkEmojiPicker } from '@atlaskit/emoji/picker';
8
8
  import { Popup } from '@atlaskit/editor-common/ui';
9
+ import { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
9
10
  import ToolbarButton from '../../../../ui/ToolbarButton';
10
11
  import { separatorStyles, buttonGroupStyle, wrapperStyle } from '@atlaskit/editor-common/styles';
11
12
  import { insertDate } from '../../../date/actions';
@@ -161,7 +162,9 @@ export class ToolbarInsertBlock extends React.PureComponent {
161
162
  state,
162
163
  dispatch
163
164
  } = editorView;
164
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions.showLinkToolbar(inputMethod)(state, dispatch);
165
+
166
+ // We should update this to use `pluginInjectionApi.executeCommand` once available
167
+ pluginCommandToPMCommand(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.commands.showLinkToolbar(inputMethod))(state, dispatch);
165
168
  return true;
166
169
  });
167
170
  _defineProperty(this, "insertMention", inputMethod => {
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
3
  /** @jsx jsx */
3
4
  import { jsx } from '@emotion/react';
@@ -173,11 +174,17 @@ export default class MediaSingleNode extends Component {
173
174
  }
174
175
  insertAndSelectCaptionFromMediaSinglePos(getPos(), node)(view.state, view.dispatch);
175
176
  });
176
- _defineProperty(this, "getLineLength", (view, pos) => {
177
+ /**
178
+ * Get parent width for a nested media single node
179
+ * @param view Editor view
180
+ * @param pos node position
181
+ * @param includeMoreParentNodeTypes should consider table and list as parent nodes(only true for new experience)
182
+ */
183
+ _defineProperty(this, "getLineLength", (view, pos, includeMoreParentNodeTypes) => {
177
184
  if (typeof pos !== 'number') {
178
185
  return null;
179
186
  }
180
- if (isRichMediaInsideOfBlockNode(view, pos)) {
187
+ if (isRichMediaInsideOfBlockNode(view, pos, includeMoreParentNodeTypes)) {
181
188
  const $pos = view.state.doc.resolve(pos);
182
189
  const domNode = view.nodeDOM($pos.pos);
183
190
  if ($pos.nodeAfter && floatingLayouts.indexOf($pos.nodeAfter.attrs.layout) > -1 && domNode && domNode.parentElement) {
@@ -270,7 +277,8 @@ export default class MediaSingleNode extends Component {
270
277
  height = DEFAULT_IMAGE_HEIGHT;
271
278
  }
272
279
  const isSelected = selected();
273
- const contentWidth = this.getLineLength(view, getPos()) || lineLength;
280
+ const contentWidthForLegacyExperience = this.getLineLength(view, getPos()) || lineLength;
281
+ const contentWidth = this.getLineLength(view, getPos(), true) || lineLength;
274
282
  const mediaSingleProps = {
275
283
  layout,
276
284
  width,
@@ -285,7 +293,9 @@ export default class MediaSingleNode extends Component {
285
293
  widthType,
286
294
  origWidth: width,
287
295
  layout,
288
- contentWidth,
296
+ // This will only be used when calculating legacy media single width
297
+ // thus we use the legecy value (exclude table as container node)
298
+ contentWidth: contentWidthForLegacyExperience,
289
299
  containerWidth,
290
300
  gutterOffset: MEDIA_SINGLE_GUTTER_SIZE
291
301
  })
@@ -327,7 +337,9 @@ export default class MediaSingleNode extends Component {
327
337
  ref: this.captionPlaceHolderRef,
328
338
  onClick: this.clickPlaceholder
329
339
  }));
330
- return canResize ? getBooleanFF('platform.editor.media.extended-resize-experience') ? jsx(ResizableMediaSingleNext, ResizableMediaSingleProps, MediaChildren) : jsx(ResizableMediaSingle, ResizableMediaSingleProps, MediaChildren) : jsx(MediaSingle, mediaSingleProps, MediaChildren);
340
+ return canResize ? getBooleanFF('platform.editor.media.extended-resize-experience') ? jsx(ResizableMediaSingleNext, ResizableMediaSingleProps, MediaChildren) : jsx(ResizableMediaSingle, _extends({}, ResizableMediaSingleProps, {
341
+ lineLength: contentWidthForLegacyExperience
342
+ }), MediaChildren) : jsx(MediaSingle, mediaSingleProps, MediaChildren);
331
343
  }
332
344
  }
333
345
  _defineProperty(MediaSingleNode, "defaultProps", {