@atlaskit/editor-core 187.8.11 → 187.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugins/floating-toolbar/index.js +1 -3
  3. package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +33 -23
  4. package/dist/cjs/plugins/media/toolbar/index.js +16 -2
  5. package/dist/cjs/plugins/media/toolbar/utils.js +7 -2
  6. package/dist/cjs/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +574 -0
  7. package/dist/cjs/plugins/media/ui/ResizableMediaSingle/guidelines.js +117 -0
  8. package/dist/cjs/plugins/media/ui/ResizableMediaSingle/resizable-media-single-messages.js +15 -0
  9. package/dist/cjs/ui/ElementBrowser/components/ElementSearch.js +5 -3
  10. package/dist/cjs/ui/ElementBrowser/components/StatelessElementBrowser.js +8 -6
  11. package/dist/cjs/ui/Resizer/ResizeLabel/index.js +20 -0
  12. package/dist/cjs/ui/Resizer/ResizeLabel/styles.js +17 -0
  13. package/dist/cjs/version-wrapper.js +1 -1
  14. package/dist/cjs/version.json +1 -1
  15. package/dist/es2019/plugins/floating-toolbar/index.js +1 -1
  16. package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +34 -23
  17. package/dist/es2019/plugins/media/toolbar/index.js +19 -3
  18. package/dist/es2019/plugins/media/toolbar/utils.js +7 -1
  19. package/dist/es2019/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +493 -0
  20. package/dist/es2019/plugins/media/ui/ResizableMediaSingle/guidelines.js +108 -0
  21. package/dist/es2019/plugins/media/ui/ResizableMediaSingle/resizable-media-single-messages.js +8 -0
  22. package/dist/es2019/ui/ElementBrowser/components/ElementSearch.js +5 -3
  23. package/dist/es2019/ui/ElementBrowser/components/StatelessElementBrowser.js +9 -6
  24. package/dist/es2019/ui/Resizer/ResizeLabel/index.js +12 -0
  25. package/dist/es2019/ui/Resizer/ResizeLabel/styles.js +25 -0
  26. package/dist/es2019/version-wrapper.js +1 -1
  27. package/dist/es2019/version.json +1 -1
  28. package/dist/esm/plugins/floating-toolbar/index.js +1 -3
  29. package/dist/esm/plugins/media/nodeviews/mediaSingle.js +33 -23
  30. package/dist/esm/plugins/media/toolbar/index.js +17 -3
  31. package/dist/esm/plugins/media/toolbar/utils.js +5 -1
  32. package/dist/esm/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +564 -0
  33. package/dist/esm/plugins/media/ui/ResizableMediaSingle/guidelines.js +108 -0
  34. package/dist/esm/plugins/media/ui/ResizableMediaSingle/resizable-media-single-messages.js +8 -0
  35. package/dist/esm/ui/ElementBrowser/components/ElementSearch.js +5 -3
  36. package/dist/esm/ui/ElementBrowser/components/StatelessElementBrowser.js +8 -6
  37. package/dist/esm/ui/Resizer/ResizeLabel/index.js +12 -0
  38. package/dist/esm/ui/Resizer/ResizeLabel/styles.js +7 -0
  39. package/dist/esm/version-wrapper.js +1 -1
  40. package/dist/esm/version.json +1 -1
  41. package/dist/types/labs/next/presets/universal.d.ts +1 -2
  42. package/dist/types/plugins/floating-toolbar/index.d.ts +3 -1
  43. package/dist/types/plugins/media/index.d.ts +2 -0
  44. package/dist/types/plugins/media/nodeviews/styles.d.ts +1 -1
  45. package/dist/types/plugins/media/pm-plugins/main.d.ts +1 -1
  46. package/dist/types/plugins/media/toolbar/utils.d.ts +1 -0
  47. package/dist/types/plugins/media/types.d.ts +1 -0
  48. package/dist/types/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +61 -0
  49. package/dist/types/plugins/media/ui/ResizableMediaSingle/guidelines.d.ts +4 -0
  50. package/dist/types/plugins/media/ui/ResizableMediaSingle/resizable-media-single-messages.d.ts +7 -0
  51. package/dist/types/plugins/media/ui/ResizableMediaSingle/types.d.ts +1 -0
  52. package/dist/types/ui/ElementBrowser/components/ElementSearch.d.ts +2 -1
  53. package/dist/types/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +4 -4
  54. package/dist/types/ui/Resizer/ResizeLabel/index.d.ts +8 -0
  55. package/dist/types/ui/Resizer/ResizeLabel/styles.d.ts +3 -0
  56. package/dist/types-ts4.5/labs/next/presets/universal.d.ts +1 -2
  57. package/dist/types-ts4.5/plugins/floating-toolbar/index.d.ts +3 -1
  58. package/dist/types-ts4.5/plugins/media/index.d.ts +2 -0
  59. package/dist/types-ts4.5/plugins/media/nodeviews/styles.d.ts +1 -1
  60. package/dist/types-ts4.5/plugins/media/pm-plugins/main.d.ts +1 -1
  61. package/dist/types-ts4.5/plugins/media/toolbar/utils.d.ts +1 -0
  62. package/dist/types-ts4.5/plugins/media/types.d.ts +1 -0
  63. package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +61 -0
  64. package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/guidelines.d.ts +4 -0
  65. package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/resizable-media-single-messages.d.ts +7 -0
  66. package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/types.d.ts +1 -0
  67. package/dist/types-ts4.5/ui/ElementBrowser/components/ElementSearch.d.ts +2 -1
  68. package/dist/types-ts4.5/ui/ElementBrowser/components/StatelessElementBrowser.d.ts +4 -4
  69. package/dist/types-ts4.5/ui/Resizer/ResizeLabel/index.d.ts +8 -0
  70. package/dist/types-ts4.5/ui/Resizer/ResizeLabel/styles.d.ts +3 -0
  71. package/package.json +2 -2
  72. package/report.api.md +7 -4
  73. package/tmp/api-report-tmp.d.ts +5 -1
@@ -0,0 +1,574 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.UnwrappedResizableMediaSingleNext = void 0;
8
+ exports.calcOffsetLeft = calcOffsetLeft;
9
+ exports.resizerNextTestId = exports.default = void 0;
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
18
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
20
+ var _react = _interopRequireDefault(require("react"));
21
+ var _react2 = require("@emotion/react");
22
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
23
+ var _mediaClient = require("@atlaskit/media-client");
24
+ var _ui = require("@atlaskit/editor-common/ui");
25
+ var _utils2 = require("@atlaskit/editor-common/utils");
26
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
27
+ var _styled = require("./styled");
28
+ var _resizer = require("@atlaskit/editor-common/resizer");
29
+ var _ResizeLabel = _interopRequireDefault(require("../../../../ui/Resizer/ResizeLabel"));
30
+ var _reactIntlNext = require("react-intl-next");
31
+ var _resizableMediaSingleMessages = require("./resizable-media-single-messages");
32
+ var _analytics = require("@atlaskit/editor-common/analytics");
33
+ var _classnames = _interopRequireDefault(require("classnames"));
34
+ var _styles = require("@atlaskit/editor-common/styles");
35
+ var _mediaSingle = require("@atlaskit/editor-common/media-single");
36
+ var _guideline = require("@atlaskit/editor-common/guideline");
37
+ var _guidelines = require("./guidelines");
38
+ 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); }; }
39
+ 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 */
40
+ var resizerNextTestId = 'mediaSingle.resizerNext.testid';
41
+ exports.resizerNextTestId = resizerNextTestId;
42
+ function calcOffsetLeft(insideInlineLike, insideLayout, pmViewDom, wrapper) {
43
+ if (wrapper && insideInlineLike && !insideLayout) {
44
+ var currentNode = wrapper;
45
+ var boundingRect = currentNode.getBoundingClientRect();
46
+ return boundingRect.left - pmViewDom.getBoundingClientRect().left;
47
+ }
48
+ return 0;
49
+ }
50
+
51
+ // TODO: Create new fixed image size event
52
+ var getResizeAnalyticsEvent = function getResizeAnalyticsEvent(type, size, layout) {
53
+ var actionSubject = type === 'embed' ? _analytics.ACTION_SUBJECT.EMBEDS : _analytics.ACTION_SUBJECT.MEDIA_SINGLE;
54
+ return {
55
+ action: _analytics.ACTION.EDITED,
56
+ actionSubject: actionSubject,
57
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.RESIZED,
58
+ attributes: {
59
+ size: size,
60
+ layout: layout
61
+ },
62
+ eventType: _analytics.EVENT_TYPE.UI
63
+ };
64
+ };
65
+ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
66
+ (0, _inherits2.default)(ResizableMediaSingleNext, _React$Component);
67
+ var _super = _createSuper(ResizableMediaSingleNext);
68
+ function ResizableMediaSingleNext(props) {
69
+ var _this;
70
+ (0, _classCallCheck2.default)(this, ResizableMediaSingleNext);
71
+ _this = _super.call(this, props);
72
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcNewSize", function (newWidth, stop) {
73
+ var _this$props = _this.props,
74
+ layout = _this$props.layout,
75
+ state = _this$props.view.state,
76
+ containerWidth = _this$props.containerWidth,
77
+ lineLength = _this$props.lineLength;
78
+ var newPct = (0, _ui.calcPctFromPx)(newWidth, _this.props.lineLength) * 100;
79
+ _this.setState({
80
+ resizedPctWidth: newPct
81
+ });
82
+ var newLayout = (0, _utils.hasParentNodeOfType)(state.schema.nodes.table)(state.selection) ? layout : _this.calcUnwrappedLayout(newWidth, containerWidth, lineLength);
83
+ if (newPct <= 100) {
84
+ if (_this.wrappedLayout && (stop ? newPct !== 100 : true)) {
85
+ newLayout = layout;
86
+ }
87
+ return {
88
+ width: newPct,
89
+ layout: newLayout
90
+ };
91
+ } else {
92
+ return {
93
+ width: _this.props.pctWidth || null,
94
+ layout: newLayout
95
+ };
96
+ }
97
+ });
98
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcUnwrappedLayout", function (width, containerWidth, contentWidth) {
99
+ if (width <= contentWidth) {
100
+ return 'center';
101
+ }
102
+ if (width < Math.min(containerWidth - _editorSharedStyles.akEditorGutterPadding * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth)) {
103
+ return 'wide';
104
+ }
105
+
106
+ // set full width to be containerWidth - akEditorGutterPadding * 2
107
+ // instead of containerWidth - akEditorBreakoutPadding,
108
+ // so that we have image aligned with text
109
+ return 'full-width';
110
+ });
111
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcColumnLeftOffset", function () {
112
+ var offsetLeft = _this.state.offsetLeft;
113
+ return _this.insideInlineLike ? (0, _ui.calcColumnsFromPx)(offsetLeft, _this.props.lineLength, _this.props.gridSize) : 0;
114
+ });
115
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "calcPxHeight", function (newWidth) {
116
+ var _this$props2 = _this.props,
117
+ _this$props2$width = _this$props2.width,
118
+ width = _this$props2$width === void 0 ? newWidth : _this$props2$width,
119
+ height = _this$props2.height;
120
+ return Math.round(height / width * newWidth);
121
+ });
122
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "saveWrapper", function (wrapper) {
123
+ return _this.wrapper = wrapper;
124
+ });
125
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "displayGuideline", function (guidelines) {
126
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3;
127
+ var pluginInjectionApi = _this.props.pluginInjectionApi;
128
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.guideline) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : (_pluginInjectionApi$d3 = _pluginInjectionApi$d2.actions) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : _pluginInjectionApi$d3.displayGuideline(_this.props.view)({
129
+ guidelines: guidelines
130
+ });
131
+ });
132
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "setIsResizing", function (isResizing) {
133
+ var _this$props$view = _this.props.view,
134
+ state = _this$props$view.state,
135
+ dispatch = _this$props$view.dispatch;
136
+ var tr = state.tr;
137
+ tr.setMeta('mediaSinglePlugin.isResizing', isResizing);
138
+ return dispatch(tr);
139
+ });
140
+ var initialWidth = props.mediaSingleWidth || _this.calcInitialWidth();
141
+ _this.state = {
142
+ offsetLeft: calcOffsetLeft(_this.insideInlineLike, _this.insideLayout, _this.props.view.dom, undefined),
143
+ // We default to true until we resolve the file type
144
+ isVideoFile: true,
145
+ isResizing: false,
146
+ size: {
147
+ width: initialWidth,
148
+ height: _this.calcPxHeight(initialWidth)
149
+ }
150
+ };
151
+ return _this;
152
+ }
153
+
154
+ /**
155
+ * Calculate media single node initial width if props.mediaSingleWidth is undefined
156
+ * (Mainly when switching from lagacy experience to new experience).
157
+ *
158
+ * @returns initial width in pixel
159
+ */
160
+ (0, _createClass2.default)(ResizableMediaSingleNext, [{
161
+ key: "calcInitialWidth",
162
+ value: function calcInitialWidth() {
163
+ var _this$props3 = this.props,
164
+ origWidth = _this$props3.width,
165
+ contentWidth = _this$props3.lineLength,
166
+ containerWidth = _this$props3.containerWidth;
167
+ return Math.max(Math.min(origWidth || _ui.DEFAULT_IMAGE_WIDTH, contentWidth || containerWidth || _editorSharedStyles.akEditorDefaultLayoutWidth), _mediaSingle.MEDIA_SINGLE_MIN_PIXEL_WIDTH);
168
+ }
169
+ }, {
170
+ key: "componentDidUpdate",
171
+ value: function componentDidUpdate(prevProps, prevState) {
172
+ var offsetLeft = calcOffsetLeft(this.insideInlineLike, this.insideLayout, this.props.view.dom, this.wrapper);
173
+ if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
174
+ this.setState({
175
+ offsetLeft: offsetLeft
176
+ });
177
+ }
178
+
179
+ // Handle undo, when the actual pctWidth changed,
180
+ // we sync up with the internal state.
181
+ if (prevProps.pctWidth !== this.props.pctWidth) {
182
+ this.setState({
183
+ resizedPctWidth: this.props.pctWidth
184
+ });
185
+ }
186
+ if (prevState.isResizing !== this.state.isResizing && this.state.isResizing) {
187
+ var guidelines = this.getDefaultGuidelines();
188
+ this.displayGuideline(guidelines);
189
+ }
190
+ if (prevProps.lineLength === undefined && this.props.lineLength !== undefined && this.props.mediaSingleWidth === null) {
191
+ // re-initalises size when lineLength becomes defined later
192
+ // ensures extended experience renders legacy image with the same size as the legacy experience
193
+ var initialWidth = this.calcInitialWidth();
194
+ this.setState({
195
+ size: {
196
+ width: initialWidth,
197
+ height: this.calcPxHeight(initialWidth)
198
+ }
199
+ });
200
+ }
201
+ return true;
202
+ }
203
+
204
+ // check if is inside of layout, table, expand, nestedExpand and list item
205
+ }, {
206
+ key: "isNestedNode",
207
+ value: function isNestedNode() {
208
+ return !!(this.$pos && this.$pos.parent.type.name !== 'doc');
209
+ }
210
+ }, {
211
+ key: "getDefaultGuidelines",
212
+ value: function getDefaultGuidelines() {
213
+ var _this$props4 = this.props,
214
+ lineLength = _this$props4.lineLength,
215
+ containerWidth = _this$props4.containerWidth,
216
+ fullWidthMode = _this$props4.fullWidthMode;
217
+
218
+ // disable guidelines for nested media single node
219
+ return this.isNestedNode() ? [] : (0, _guidelines.generateDefaultGuidelines)(lineLength, containerWidth, fullWidthMode);
220
+ }
221
+
222
+ // Calculate width of media nodes for snaps based on dynamic guidelines
223
+ // TODO: refactor this later, maybe use state to hold snaps array
224
+ }, {
225
+ key: "getSnaps",
226
+ value: function getSnaps() {
227
+ var view = this.props.view;
228
+ var dom = view.dom;
229
+ var defaultGuidelines = this.getDefaultGuidelines();
230
+ // disable guidelines for nested media single node
231
+ var dynamicGuidelines = this.isNestedNode() ? [] : (0, _guidelines.generateDynamicGuidelines)(view);
232
+ var guidelines = [].concat((0, _toConsumableArray2.default)(defaultGuidelines), (0, _toConsumableArray2.default)(dynamicGuidelines));
233
+ var mediaSingleSelector = 'div.mediaSingleView-content-wrap.ProseMirror-selectednode';
234
+ var _dom$getBoundingClien = dom.getBoundingClientRect(),
235
+ width = _dom$getBoundingClien.width;
236
+ var halfWidth = width / 2;
237
+ var selectedMedia = dom.querySelector(mediaSingleSelector);
238
+ if (selectedMedia) {
239
+ var pixelWidth = parseFloat(selectedMedia.getAttribute('width') || '') || 0;
240
+ var layout = selectedMedia.getAttribute('layout');
241
+ var snap = 0;
242
+ switch (layout) {
243
+ case 'align-start':
244
+ case 'wrap-left':
245
+ snap = pixelWidth - halfWidth;
246
+ break;
247
+ case 'align-end':
248
+ case 'wrap-right':
249
+ snap = width - pixelWidth - halfWidth;
250
+ break;
251
+ case 'center':
252
+ case 'wide':
253
+ case 'full-width':
254
+ snap = -pixelWidth / 2;
255
+ break;
256
+ // we ingnore full-width and wide
257
+ default:
258
+ snap = 0;
259
+ }
260
+ var snapWidths = (0, _guideline.getSnapWidth)(guidelines, pixelWidth, snap, layout);
261
+ var snapToWidths = snapWidths.map(function (s) {
262
+ return s && s.width;
263
+ });
264
+
265
+ // update guidelines
266
+ if (this.state.isResizing) {
267
+ var _findClosestSnap = (0, _guideline.findClosestSnap)(this.state.size.width, snapToWidths, snapWidths, _mediaSingle.MEDIA_SINGLE_HIGHLIGHT_GAP),
268
+ gap = _findClosestSnap.gap,
269
+ activeGuidelineKeys = _findClosestSnap.keys;
270
+ this.displayGuideline((0, _guideline.getGuidelinesWithHighlights)(gap, _mediaSingle.MEDIA_SINGLE_HIGHLIGHT_GAP, activeGuidelineKeys, guidelines));
271
+ }
272
+ return snapToWidths.length > 0 ? {
273
+ x: snapToWidths
274
+ } : {};
275
+ }
276
+ return {};
277
+ }
278
+ }, {
279
+ key: "wrappedLayout",
280
+ get: function get() {
281
+ return _ui.wrappedLayouts.indexOf(this.props.layout) > -1;
282
+ }
283
+ }, {
284
+ key: "componentDidMount",
285
+ value: function () {
286
+ var _componentDidMount = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
287
+ var viewMediaClientConfig;
288
+ return _regenerator.default.wrap(function _callee$(_context) {
289
+ while (1) switch (_context.prev = _context.next) {
290
+ case 0:
291
+ viewMediaClientConfig = this.props.viewMediaClientConfig;
292
+ if (!viewMediaClientConfig) {
293
+ _context.next = 4;
294
+ break;
295
+ }
296
+ _context.next = 4;
297
+ return this.checkVideoFile(viewMediaClientConfig);
298
+ case 4:
299
+ case "end":
300
+ return _context.stop();
301
+ }
302
+ }, _callee, this);
303
+ }));
304
+ function componentDidMount() {
305
+ return _componentDidMount.apply(this, arguments);
306
+ }
307
+ return componentDidMount;
308
+ }()
309
+ }, {
310
+ key: "UNSAFE_componentWillReceiveProps",
311
+ value: function UNSAFE_componentWillReceiveProps(nextProps) {
312
+ if (this.props.viewMediaClientConfig !== nextProps.viewMediaClientConfig) {
313
+ this.checkVideoFile(nextProps.viewMediaClientConfig);
314
+ }
315
+ }
316
+ }, {
317
+ key: "checkVideoFile",
318
+ value: function () {
319
+ var _checkVideoFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(viewMediaClientConfig) {
320
+ var $pos, mediaNode, mediaClient, state;
321
+ return _regenerator.default.wrap(function _callee2$(_context2) {
322
+ while (1) switch (_context2.prev = _context2.next) {
323
+ case 0:
324
+ $pos = this.$pos;
325
+ if (!(!$pos || !viewMediaClientConfig)) {
326
+ _context2.next = 3;
327
+ break;
328
+ }
329
+ return _context2.abrupt("return");
330
+ case 3:
331
+ mediaNode = this.props.view.state.doc.nodeAt($pos.pos + 1);
332
+ if (!(!mediaNode || !mediaNode.attrs.id)) {
333
+ _context2.next = 6;
334
+ break;
335
+ }
336
+ return _context2.abrupt("return");
337
+ case 6:
338
+ mediaClient = (0, _mediaClient.getMediaClient)(viewMediaClientConfig);
339
+ _context2.prev = 7;
340
+ _context2.next = 10;
341
+ return mediaClient.file.getCurrentState(mediaNode.attrs.id, {
342
+ collectionName: mediaNode.attrs.collection
343
+ });
344
+ case 10:
345
+ state = _context2.sent;
346
+ if (state && state.status !== 'error' && state.mediaType === 'image') {
347
+ this.setState({
348
+ isVideoFile: false
349
+ });
350
+ }
351
+ _context2.next = 17;
352
+ break;
353
+ case 14:
354
+ _context2.prev = 14;
355
+ _context2.t0 = _context2["catch"](7);
356
+ this.setState({
357
+ isVideoFile: false
358
+ });
359
+ case 17:
360
+ case "end":
361
+ return _context2.stop();
362
+ }
363
+ }, _callee2, this, [[7, 14]]);
364
+ }));
365
+ function checkVideoFile(_x) {
366
+ return _checkVideoFile.apply(this, arguments);
367
+ }
368
+ return checkVideoFile;
369
+ }()
370
+ }, {
371
+ key: "$pos",
372
+ get: function get() {
373
+ if (typeof this.props.getPos !== 'function') {
374
+ return null;
375
+ }
376
+ var pos = this.props.getPos();
377
+ if (Number.isNaN(pos) || typeof pos !== 'number') {
378
+ return null;
379
+ }
380
+
381
+ // need to pass view because we may not get updated props in time
382
+ return this.props.view.state.doc.resolve(pos);
383
+ }
384
+
385
+ /**
386
+ * The maxmimum number of grid columns this node can resize to.
387
+ */
388
+ }, {
389
+ key: "gridWidth",
390
+ get: function get() {
391
+ var gridSize = this.props.gridSize;
392
+ return !(this.wrappedLayout || this.insideInlineLike) ? gridSize / 2 : gridSize;
393
+ }
394
+ }, {
395
+ key: "insideInlineLike",
396
+ get: function get() {
397
+ var $pos = this.$pos;
398
+ if (!$pos) {
399
+ return false;
400
+ }
401
+ var listItem = this.props.view.state.schema.nodes.listItem;
402
+ return !!(0, _utils.findParentNodeOfTypeClosestToPos)($pos, [listItem]);
403
+ }
404
+ }, {
405
+ key: "insideLayout",
406
+ get: function get() {
407
+ var $pos = this.$pos;
408
+ if (!$pos) {
409
+ return false;
410
+ }
411
+ var layoutColumn = this.props.view.state.schema.nodes.layoutColumn;
412
+ return !!(0, _utils.findParentNodeOfTypeClosestToPos)($pos, [layoutColumn]);
413
+ }
414
+ }, {
415
+ key: "render",
416
+ value: function render() {
417
+ var _this2 = this;
418
+ var _this$props5 = this.props,
419
+ origWidth = _this$props5.width,
420
+ layout = _this$props5.layout,
421
+ pctWidth = _this$props5.pctWidth,
422
+ containerWidth = _this$props5.containerWidth,
423
+ fullWidthMode = _this$props5.fullWidthMode,
424
+ selected = _this$props5.selected,
425
+ children = _this$props5.children,
426
+ intl = _this$props5.intl;
427
+ var _this$state = this.state,
428
+ isResizing = _this$state.isResizing,
429
+ size = _this$state.size;
430
+ var enable = {};
431
+ _ui.handleSides.forEach(function (side) {
432
+ var oppositeSide = side === 'left' ? 'right' : 'left';
433
+ enable[side] = _utils2.nonWrappedLayouts.concat("wrap-".concat(oppositeSide)).concat("align-".concat(_ui.imageAlignmentMap[oppositeSide])).indexOf(layout) > -1;
434
+ if (side === 'left' && _this2.insideInlineLike) {
435
+ enable[side] = false;
436
+ }
437
+ });
438
+
439
+ /**
440
+ * NEW REFACTOR
441
+ */
442
+ var roundPixelValue = function roundPixelValue(value) {
443
+ return Math.round(value);
444
+ };
445
+ var getHeightFromNewWidth = function getHeightFromNewWidth(originalWidth, originalHeight, newWidth) {
446
+ return roundPixelValue(originalHeight / originalWidth * newWidth);
447
+ };
448
+ var calculateSizeState = function calculateSizeState(size, delta) {
449
+ var originalWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
450
+ var originalHeight = arguments.length > 3 ? arguments[3] : undefined;
451
+ var onResizeStop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
452
+ var calculatedWidth = roundPixelValue(size.width + delta.width);
453
+ var calculatedWidthWithLayout = _this2.calcNewSize(calculatedWidth, onResizeStop);
454
+ var calculatedHeightWithLayout = getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
455
+ return {
456
+ width: calculatedWidth,
457
+ height: calculatedHeightWithLayout,
458
+ calculatedWidthWithLayout: calculatedWidthWithLayout
459
+ };
460
+ };
461
+ var selectCurrentMediaNode = function selectCurrentMediaNode() {
462
+ if (!_this2.props.selected && typeof _this2.props.getPos === 'function') {
463
+ var propPos = _this2.props.getPos();
464
+ if (propPos !== undefined) {
465
+ (0, _utils2.setNodeSelection)(_this2.props.view, propPos);
466
+ }
467
+ }
468
+ };
469
+ var handleResizeStart = function handleResizeStart() {
470
+ _this2.setState({
471
+ isResizing: true
472
+ });
473
+ selectCurrentMediaNode();
474
+ _this2.setIsResizing(true);
475
+
476
+ // TODO: Update once type updated from editor common resizer
477
+ return 0;
478
+ };
479
+ var handleResize = function handleResize(size, delta) {
480
+ var _this2$props = _this2.props,
481
+ originalWidth = _this2$props.width,
482
+ originalHeight = _this2$props.height,
483
+ layout = _this2$props.layout,
484
+ updateSize = _this2$props.updateSize;
485
+ var _calculateSizeState = calculateSizeState(size, delta, originalWidth, originalHeight),
486
+ width = _calculateSizeState.width,
487
+ height = _calculateSizeState.height,
488
+ calculatedWidthWithLayout = _calculateSizeState.calculatedWidthWithLayout;
489
+ _this2.setState({
490
+ size: {
491
+ width: width,
492
+ height: height
493
+ }
494
+ });
495
+ if (calculatedWidthWithLayout.layout !== layout) {
496
+ updateSize(width, calculatedWidthWithLayout.layout);
497
+ }
498
+
499
+ // TODO: Update once type updated from editor common resizer
500
+ return 0;
501
+ };
502
+ var handleResizeStop = function handleResizeStop(size, delta) {
503
+ var _this2$props2 = _this2.props,
504
+ originalWidth = _this2$props2.width,
505
+ originalHeight = _this2$props2.height,
506
+ updateSize = _this2$props2.updateSize,
507
+ dispatchAnalyticsEvent = _this2$props2.dispatchAnalyticsEvent,
508
+ nodeType = _this2$props2.nodeType;
509
+ var _calculateSizeState2 = calculateSizeState(size, delta, originalWidth, originalHeight, true),
510
+ width = _calculateSizeState2.width,
511
+ height = _calculateSizeState2.height,
512
+ calculatedWidthWithLayout = _calculateSizeState2.calculatedWidthWithLayout;
513
+ _this2.setIsResizing(false);
514
+ _this2.displayGuideline([]);
515
+ if (dispatchAnalyticsEvent) {
516
+ dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
517
+ }
518
+ _this2.setState({
519
+ isResizing: false,
520
+ size: {
521
+ width: width,
522
+ height: height
523
+ }
524
+ }, function () {
525
+ updateSize(width, calculatedWidthWithLayout.layout);
526
+ });
527
+
528
+ // TODO: Update once type updated from editor common resizer
529
+ return 0;
530
+ };
531
+
532
+ // TODO: Clean up where this lives and how it gets generated
533
+ var className = (0, _classnames.default)(_styles.richMediaClassName, "image-".concat(layout), isResizing ? 'is-resizing' : 'not-resizing', this.props.className, {
534
+ 'not-resized': !pctWidth,
535
+ 'richMedia-selected': selected,
536
+ 'rich-media-wrapped': layout === 'wrap-left' || layout === 'wrap-right'
537
+ });
538
+ var resizerNextClassName = (0, _classnames.default)(className, _styles.resizerStyles);
539
+ var showSizeGuide = selected || isResizing;
540
+ var label = layout === 'full-width' ? intl.formatMessage(_resizableMediaSingleMessages.messages.fullWidthImage) : "".concat(this.state.size.width, " x ").concat(this.state.size.height);
541
+ return (0, _react2.jsx)("div", {
542
+ ref: this.saveWrapper,
543
+ css: (0, _styled.wrapperStyle)({
544
+ layout: layout,
545
+ isResized: !!pctWidth,
546
+ containerWidth: containerWidth || origWidth,
547
+ fullWidthMode: fullWidthMode,
548
+ mediaSingleWidth: this.state.size.width,
549
+ isNestedNode: this.isNestedNode(),
550
+ isExtendedResizeExperienceOn: true
551
+ })
552
+ }, (0, _react2.jsx)(_resizer.ResizerNext, {
553
+ minWidth: _mediaSingle.MEDIA_SINGLE_MIN_PIXEL_WIDTH,
554
+ className: resizerNextClassName,
555
+ snapGap: _mediaSingle.MEDIA_SINGLE_SNAP_GAP,
556
+ enable: enable,
557
+ width: size.width,
558
+ handleResizeStart: handleResizeStart,
559
+ handleResize: handleResize,
560
+ handleResizeStop: handleResizeStop,
561
+ snap: this.getSnaps(),
562
+ resizeRatio: _utils2.nonWrappedLayouts.includes(layout) ? 2 : 1,
563
+ "data-testid": resizerNextTestId
564
+ }, showSizeGuide && (0, _react2.jsx)(_ResizeLabel.default, {
565
+ label: label,
566
+ containerWidth: this.state.size.width
567
+ }), children));
568
+ }
569
+ }]);
570
+ return ResizableMediaSingleNext;
571
+ }(_react.default.Component); // for testing purpose
572
+ exports.UnwrappedResizableMediaSingleNext = ResizableMediaSingleNext;
573
+ var _default = (0, _reactIntlNext.injectIntl)(ResizableMediaSingleNext);
574
+ exports.default = _default;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.generateDynamicGuidelines = exports.generateDefaultGuidelines = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
11
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
+ var _guideline = require("@atlaskit/editor-common/guideline");
13
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+ var mediaSingleSelector = 'div.mediaSingleView-content-wrap:not(.ProseMirror-selectednode)';
16
+ var getDefaultGuidelines = (0, _memoizeOne.default)(function (editorWidth) {
17
+ return [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6].map(function (val, index) {
18
+ return {
19
+ key: "grid_".concat(index),
20
+ position: {
21
+ x: val / 12 * editorWidth
22
+ }
23
+ };
24
+ });
25
+ });
26
+ var getWideGuidelines = (0, _memoizeOne.default)(function (editorWidth) {
27
+ var wideSpacing = editorWidth * _editorSharedStyles.breakoutWideScaleRatio / 2;
28
+ return [{
29
+ key: "wide_left",
30
+ position: {
31
+ x: -wideSpacing
32
+ }
33
+ }, {
34
+ key: "wide_right",
35
+ position: {
36
+ x: wideSpacing
37
+ }
38
+ }];
39
+ });
40
+ var getFullWidthGuidelines = (0, _memoizeOne.default)(function (containerWidth) {
41
+ var fullWidth = Math.min(containerWidth - _editorSharedStyles.akEditorGutterPadding * 2, _editorSharedStyles.akEditorFullWidthLayoutWidth) / 2;
42
+ return [{
43
+ key: "full_width_left",
44
+ position: {
45
+ x: -fullWidth
46
+ }
47
+ }, {
48
+ key: "full_width_right",
49
+ position: {
50
+ x: fullWidth
51
+ }
52
+ }];
53
+ });
54
+ var generateDefaultGuidelines = function generateDefaultGuidelines(editorWidth, containerWidth) {
55
+ var isFullWidthMode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
56
+ var innerGrids = getDefaultGuidelines(editorWidth);
57
+ var wideGuidelines = !isFullWidthMode ? getWideGuidelines(editorWidth) : [];
58
+ var fullWidthGuidelines = !isFullWidthMode ? getFullWidthGuidelines(containerWidth) : [];
59
+ return [].concat((0, _toConsumableArray2.default)(innerGrids), (0, _toConsumableArray2.default)(wideGuidelines), (0, _toConsumableArray2.default)(fullWidthGuidelines));
60
+ };
61
+ exports.generateDefaultGuidelines = generateDefaultGuidelines;
62
+ var generateDynamicGuidelines = function generateDynamicGuidelines(view) {
63
+ var dom = view.dom;
64
+ var _dom$getBoundingClien = dom.getBoundingClientRect(),
65
+ width = _dom$getBoundingClien.width;
66
+ var halfWidth = width / 2;
67
+ var keyIdx = 0;
68
+ var dynamicGuidelines = (0, _toConsumableArray2.default)(dom.querySelectorAll(mediaSingleSelector)).map(function (elem, _index) {
69
+ var pixelWidthAttr = elem.getAttribute('widthType') === 'pixel' ? elem.getAttribute('width') : '';
70
+ var pixelWidth = parseFloat(pixelWidthAttr || '');
71
+ if (Number.isNaN(pixelWidth)) {
72
+ return [];
73
+ }
74
+ var commonStyles = {
75
+ styles: {
76
+ lineStyle: 'dashed'
77
+ },
78
+ show: false
79
+ };
80
+ var key = "".concat(_guideline.MEDIA_DYNAMIC_GUIDELINE_PREFIX).concat(++keyIdx);
81
+ switch (elem.getAttribute('layout')) {
82
+ case 'align-start':
83
+ case 'wrap-left':
84
+ return _objectSpread({
85
+ position: {
86
+ x: pixelWidth - halfWidth
87
+ },
88
+ key: key
89
+ }, commonStyles);
90
+ case 'align-end':
91
+ case 'wrap-right':
92
+ return _objectSpread({
93
+ position: {
94
+ x: width - pixelWidth - halfWidth
95
+ },
96
+ key: key
97
+ }, commonStyles);
98
+ case 'center':
99
+ return [_objectSpread({
100
+ position: {
101
+ x: pixelWidth / 2
102
+ },
103
+ key: key
104
+ }, commonStyles), _objectSpread({
105
+ position: {
106
+ x: -pixelWidth / 2
107
+ },
108
+ key: key
109
+ }, commonStyles)];
110
+ // we ignore full-width and wide
111
+ default:
112
+ return [];
113
+ }
114
+ }).flat();
115
+ return dynamicGuidelines;
116
+ };
117
+ exports.generateDynamicGuidelines = generateDynamicGuidelines;