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