@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 +22 -0
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +4 -1
- package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +17 -5
- package/dist/cjs/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +157 -192
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +4 -1
- package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +17 -5
- package/dist/es2019/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +131 -168
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +4 -1
- package/dist/esm/plugins/media/nodeviews/mediaSingle.js +17 -5
- package/dist/esm/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +159 -194
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/labs/next/presets/default.d.ts +12 -4
- package/dist/types/plugins/media/nodeviews/mediaSingle.d.ts +6 -0
- package/dist/types/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +22 -3
- package/dist/types-ts4.5/labs/next/presets/default.d.ts +12 -4
- package/dist/types-ts4.5/plugins/media/nodeviews/mediaSingle.d.ts +6 -0
- package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +22 -3
- package/package.json +4 -4
|
@@ -26,8 +26,9 @@ import { messages } from './resizable-media-single-messages';
|
|
|
26
26
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
27
27
|
import classnames from 'classnames';
|
|
28
28
|
import { richMediaClassName, resizerStyles } from '@atlaskit/editor-common/styles';
|
|
29
|
-
import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP,
|
|
30
|
-
import { findClosestSnap,
|
|
29
|
+
import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH, calcMediaSingleMaxWidth } from '@atlaskit/editor-common/media-single';
|
|
30
|
+
import { findClosestSnap, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines, getGuidelineSnaps } from '@atlaskit/editor-common/guideline';
|
|
31
|
+
import memoizeOne from 'memoize-one';
|
|
31
32
|
export var resizerNextTestId = 'mediaSingle.resizerNext.testid';
|
|
32
33
|
|
|
33
34
|
// TODO: Create new fixed image size event
|
|
@@ -51,12 +52,28 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
51
52
|
var _this;
|
|
52
53
|
_classCallCheck(this, ResizableMediaSingleNext);
|
|
53
54
|
_this = _super.call(this, props);
|
|
54
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "guidelines", []);
|
|
56
|
+
_defineProperty(_assertThisInitialized(_this), "getAllGuidelines", function () {
|
|
55
57
|
var _this$props = _this.props,
|
|
56
|
-
|
|
57
|
-
state = _this$props.view.state,
|
|
58
|
-
containerWidth = _this$props.containerWidth,
|
|
58
|
+
view = _this$props.view,
|
|
59
59
|
lineLength = _this$props.lineLength;
|
|
60
|
+
var defaultGuidelines = _this.getDefaultGuidelines();
|
|
61
|
+
// disable guidelines for nested media single node
|
|
62
|
+
var dynamicGuidelines = _this.isNestedNode() ? [] : generateDynamicGuidelines(view.state, lineLength, {
|
|
63
|
+
styles: {
|
|
64
|
+
lineStyle: 'dashed'
|
|
65
|
+
},
|
|
66
|
+
show: false
|
|
67
|
+
});
|
|
68
|
+
var guidelines = [].concat(_toConsumableArray(defaultGuidelines), _toConsumableArray(dynamicGuidelines));
|
|
69
|
+
return guidelines;
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "calcNewSize", function (newWidth, stop) {
|
|
72
|
+
var _this$props2 = _this.props,
|
|
73
|
+
layout = _this$props2.layout,
|
|
74
|
+
state = _this$props2.view.state,
|
|
75
|
+
containerWidth = _this$props2.containerWidth,
|
|
76
|
+
lineLength = _this$props2.lineLength;
|
|
60
77
|
var newPct = calcPctFromPx(newWidth, _this.props.lineLength) * 100;
|
|
61
78
|
_this.setState({
|
|
62
79
|
resizedPctWidth: newPct
|
|
@@ -95,10 +112,10 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
95
112
|
return _this.insideInlineLike ? calcColumnsFromPx(offsetLeft, _this.props.lineLength, _this.props.gridSize) : 0;
|
|
96
113
|
});
|
|
97
114
|
_defineProperty(_assertThisInitialized(_this), "calcPxHeight", function (newWidth) {
|
|
98
|
-
var _this$
|
|
99
|
-
_this$
|
|
100
|
-
width = _this$
|
|
101
|
-
height = _this$
|
|
115
|
+
var _this$props3 = _this.props,
|
|
116
|
+
_this$props3$width = _this$props3.width,
|
|
117
|
+
width = _this$props3$width === void 0 ? newWidth : _this$props3$width,
|
|
118
|
+
height = _this$props3.height;
|
|
102
119
|
return Math.round(height / width * newWidth);
|
|
103
120
|
});
|
|
104
121
|
_defineProperty(_assertThisInitialized(_this), "saveWrapper", function (wrapper) {
|
|
@@ -119,6 +136,111 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
119
136
|
tr.setMeta('mediaSinglePlugin.isResizing', isResizing);
|
|
120
137
|
return dispatch(tr);
|
|
121
138
|
});
|
|
139
|
+
_defineProperty(_assertThisInitialized(_this), "calcMaxWidth", memoizeOne(function (contentWidth, containerWidth, fullWidthMode) {
|
|
140
|
+
if (_this.isNestedNode() || fullWidthMode) {
|
|
141
|
+
return contentWidth;
|
|
142
|
+
}
|
|
143
|
+
return calcMediaSingleMaxWidth(containerWidth);
|
|
144
|
+
}));
|
|
145
|
+
_defineProperty(_assertThisInitialized(_this), "updateActiveGuidelines", function () {
|
|
146
|
+
var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
147
|
+
var guidelines = arguments.length > 1 ? arguments[1] : undefined;
|
|
148
|
+
var guidelineSnapsReference = arguments.length > 2 ? arguments[2] : undefined;
|
|
149
|
+
if (guidelineSnapsReference.snaps.x) {
|
|
150
|
+
var _findClosestSnap = findClosestSnap(width, guidelineSnapsReference.snaps.x, guidelineSnapsReference.guidelineReference, MEDIA_SINGLE_SNAP_GAP),
|
|
151
|
+
gap = _findClosestSnap.gap,
|
|
152
|
+
activeGuidelineKeys = _findClosestSnap.keys;
|
|
153
|
+
_this.displayGuideline(getGuidelinesWithHighlights(gap, MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
_defineProperty(_assertThisInitialized(_this), "roundPixelValue", function (value) {
|
|
157
|
+
return Math.round(value);
|
|
158
|
+
});
|
|
159
|
+
_defineProperty(_assertThisInitialized(_this), "getHeightFromNewWidth", function (originalWidth, originalHeight, newWidth) {
|
|
160
|
+
return _this.roundPixelValue(originalHeight / originalWidth * newWidth);
|
|
161
|
+
});
|
|
162
|
+
_defineProperty(_assertThisInitialized(_this), "calculateSizeState", function (size, delta) {
|
|
163
|
+
var originalWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
164
|
+
var originalHeight = arguments.length > 3 ? arguments[3] : undefined;
|
|
165
|
+
var onResizeStop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
166
|
+
var calculatedWidth = _this.roundPixelValue(size.width + delta.width);
|
|
167
|
+
var calculatedWidthWithLayout = _this.calcNewSize(calculatedWidth, onResizeStop);
|
|
168
|
+
var calculatedHeightWithLayout = _this.getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
|
|
169
|
+
return {
|
|
170
|
+
width: calculatedWidth,
|
|
171
|
+
height: calculatedHeightWithLayout,
|
|
172
|
+
calculatedWidthWithLayout: calculatedWidthWithLayout
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
_defineProperty(_assertThisInitialized(_this), "selectCurrentMediaNode", function () {
|
|
176
|
+
// TODO: if adding !this.props.selected, it doesn't work if media single node is at top postion
|
|
177
|
+
if (typeof _this.props.getPos === 'function') {
|
|
178
|
+
var propPos = _this.props.getPos();
|
|
179
|
+
if (propPos !== undefined) {
|
|
180
|
+
setNodeSelection(_this.props.view, propPos);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
_defineProperty(_assertThisInitialized(_this), "handleResizeStart", function () {
|
|
185
|
+
_this.setState({
|
|
186
|
+
isResizing: true
|
|
187
|
+
});
|
|
188
|
+
_this.selectCurrentMediaNode();
|
|
189
|
+
_this.setIsResizing(true);
|
|
190
|
+
// re-calucate guidelines
|
|
191
|
+
_this.guidelines = _this.getAllGuidelines();
|
|
192
|
+
return 0;
|
|
193
|
+
});
|
|
194
|
+
_defineProperty(_assertThisInitialized(_this), "handleResize", function (size, delta) {
|
|
195
|
+
var _this$props4 = _this.props,
|
|
196
|
+
originalWidth = _this$props4.width,
|
|
197
|
+
originalHeight = _this$props4.height,
|
|
198
|
+
layout = _this$props4.layout,
|
|
199
|
+
updateSize = _this$props4.updateSize,
|
|
200
|
+
lineLength = _this$props4.lineLength;
|
|
201
|
+
var _this$calculateSizeSt = _this.calculateSizeState(size, delta, originalWidth, originalHeight),
|
|
202
|
+
width = _this$calculateSizeSt.width,
|
|
203
|
+
height = _this$calculateSizeSt.height,
|
|
204
|
+
calculatedWidthWithLayout = _this$calculateSizeSt.calculatedWidthWithLayout;
|
|
205
|
+
var guidelineSnaps = getGuidelineSnaps(_this.guidelines, lineLength, layout);
|
|
206
|
+
_this.updateActiveGuidelines(width, _this.guidelines, guidelineSnaps);
|
|
207
|
+
_this.setState({
|
|
208
|
+
size: {
|
|
209
|
+
width: width,
|
|
210
|
+
height: height
|
|
211
|
+
},
|
|
212
|
+
snaps: guidelineSnaps.snaps
|
|
213
|
+
});
|
|
214
|
+
if (calculatedWidthWithLayout.layout !== layout) {
|
|
215
|
+
updateSize(width, calculatedWidthWithLayout.layout);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
_defineProperty(_assertThisInitialized(_this), "handleResizeStop", function (size, delta) {
|
|
219
|
+
var _this$props5 = _this.props,
|
|
220
|
+
originalWidth = _this$props5.width,
|
|
221
|
+
originalHeight = _this$props5.height,
|
|
222
|
+
updateSize = _this$props5.updateSize,
|
|
223
|
+
dispatchAnalyticsEvent = _this$props5.dispatchAnalyticsEvent,
|
|
224
|
+
nodeType = _this$props5.nodeType;
|
|
225
|
+
var _this$calculateSizeSt2 = _this.calculateSizeState(size, delta, originalWidth, originalHeight, true),
|
|
226
|
+
width = _this$calculateSizeSt2.width,
|
|
227
|
+
height = _this$calculateSizeSt2.height,
|
|
228
|
+
calculatedWidthWithLayout = _this$calculateSizeSt2.calculatedWidthWithLayout;
|
|
229
|
+
_this.setIsResizing(false);
|
|
230
|
+
_this.displayGuideline([]);
|
|
231
|
+
if (dispatchAnalyticsEvent) {
|
|
232
|
+
dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
|
|
233
|
+
}
|
|
234
|
+
_this.setState({
|
|
235
|
+
isResizing: false,
|
|
236
|
+
size: {
|
|
237
|
+
width: width,
|
|
238
|
+
height: height
|
|
239
|
+
}
|
|
240
|
+
}, function () {
|
|
241
|
+
updateSize(width, calculatedWidthWithLayout.layout);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
122
244
|
var initialWidth = props.mediaSingleWidth || DEFAULT_IMAGE_WIDTH;
|
|
123
245
|
_this.state = {
|
|
124
246
|
offsetLeft: calculateOffsetLeft(_this.insideInlineLike, _this.insideLayout, _this.props.view.dom, undefined),
|
|
@@ -128,7 +250,8 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
128
250
|
size: {
|
|
129
251
|
width: initialWidth,
|
|
130
252
|
height: _this.calcPxHeight(initialWidth)
|
|
131
|
-
}
|
|
253
|
+
},
|
|
254
|
+
snaps: {}
|
|
132
255
|
};
|
|
133
256
|
return _this;
|
|
134
257
|
}
|
|
@@ -142,15 +265,15 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
142
265
|
_createClass(ResizableMediaSingleNext, [{
|
|
143
266
|
key: "calcInitialWidth",
|
|
144
267
|
value: function calcInitialWidth() {
|
|
145
|
-
var _this$
|
|
146
|
-
origWidth = _this$
|
|
147
|
-
contentWidth = _this$
|
|
148
|
-
containerWidth = _this$
|
|
268
|
+
var _this$props6 = this.props,
|
|
269
|
+
origWidth = _this$props6.width,
|
|
270
|
+
contentWidth = _this$props6.lineLength,
|
|
271
|
+
containerWidth = _this$props6.containerWidth;
|
|
149
272
|
return Math.max(Math.min(origWidth || DEFAULT_IMAGE_WIDTH, contentWidth || containerWidth || akEditorDefaultLayoutWidth), MEDIA_SINGLE_MIN_PIXEL_WIDTH);
|
|
150
273
|
}
|
|
151
274
|
}, {
|
|
152
275
|
key: "componentDidUpdate",
|
|
153
|
-
value: function componentDidUpdate(prevProps
|
|
276
|
+
value: function componentDidUpdate(prevProps) {
|
|
154
277
|
var offsetLeft = calculateOffsetLeft(this.insideInlineLike, this.insideLayout, this.props.view.dom, this.wrapper);
|
|
155
278
|
if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
|
|
156
279
|
this.setState({
|
|
@@ -165,10 +288,6 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
165
288
|
resizedPctWidth: this.props.pctWidth
|
|
166
289
|
});
|
|
167
290
|
}
|
|
168
|
-
if (prevState.isResizing !== this.state.isResizing && this.state.isResizing) {
|
|
169
|
-
var guidelines = this.getDefaultGuidelines();
|
|
170
|
-
this.displayGuideline(guidelines);
|
|
171
|
-
}
|
|
172
291
|
if (prevProps.mediaSingleWidth !== this.props.mediaSingleWidth && this.props.mediaSingleWidth) {
|
|
173
292
|
// update size when lineLength becomes defined later
|
|
174
293
|
// ensures extended experience renders legacy image with the same size as the legacy experience
|
|
@@ -192,78 +311,14 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
192
311
|
}, {
|
|
193
312
|
key: "getDefaultGuidelines",
|
|
194
313
|
value: function getDefaultGuidelines() {
|
|
195
|
-
var _this$
|
|
196
|
-
lineLength = _this$
|
|
197
|
-
containerWidth = _this$
|
|
198
|
-
fullWidthMode = _this$
|
|
314
|
+
var _this$props7 = this.props,
|
|
315
|
+
lineLength = _this$props7.lineLength,
|
|
316
|
+
containerWidth = _this$props7.containerWidth,
|
|
317
|
+
fullWidthMode = _this$props7.fullWidthMode;
|
|
199
318
|
|
|
200
319
|
// disable guidelines for nested media single node
|
|
201
320
|
return this.isNestedNode() ? [] : generateDefaultGuidelines(lineLength, containerWidth, fullWidthMode);
|
|
202
321
|
}
|
|
203
|
-
|
|
204
|
-
// Calculate width of media nodes for snaps based on dynamic guidelines
|
|
205
|
-
// TODO: refactor this later, maybe use state to hold snaps array
|
|
206
|
-
}, {
|
|
207
|
-
key: "getSnaps",
|
|
208
|
-
value: function getSnaps() {
|
|
209
|
-
var _this$props5 = this.props,
|
|
210
|
-
view = _this$props5.view,
|
|
211
|
-
lineLength = _this$props5.lineLength;
|
|
212
|
-
var dom = view.dom;
|
|
213
|
-
var defaultGuidelines = this.getDefaultGuidelines();
|
|
214
|
-
// disable guidelines for nested media single node
|
|
215
|
-
var dynamicGuidelines = this.isNestedNode() ? [] : generateDynamicGuidelines(view.state, lineLength, {
|
|
216
|
-
styles: {
|
|
217
|
-
lineStyle: 'dashed'
|
|
218
|
-
},
|
|
219
|
-
show: false
|
|
220
|
-
});
|
|
221
|
-
var guidelines = [].concat(_toConsumableArray(defaultGuidelines), _toConsumableArray(dynamicGuidelines));
|
|
222
|
-
var mediaSingleSelector = 'div.mediaSingleView-content-wrap.ProseMirror-selectednode';
|
|
223
|
-
var _dom$getBoundingClien = dom.getBoundingClientRect(),
|
|
224
|
-
width = _dom$getBoundingClien.width;
|
|
225
|
-
var halfWidth = width / 2;
|
|
226
|
-
var selectedMedia = dom.querySelector(mediaSingleSelector);
|
|
227
|
-
if (selectedMedia) {
|
|
228
|
-
var pixelWidth = parseFloat(selectedMedia.getAttribute('width') || '') || 0;
|
|
229
|
-
var layout = selectedMedia.getAttribute('layout');
|
|
230
|
-
var snap = 0;
|
|
231
|
-
switch (layout) {
|
|
232
|
-
case 'align-start':
|
|
233
|
-
case 'wrap-left':
|
|
234
|
-
snap = pixelWidth - halfWidth;
|
|
235
|
-
break;
|
|
236
|
-
case 'align-end':
|
|
237
|
-
case 'wrap-right':
|
|
238
|
-
snap = width - pixelWidth - halfWidth;
|
|
239
|
-
break;
|
|
240
|
-
case 'center':
|
|
241
|
-
case 'wide':
|
|
242
|
-
case 'full-width':
|
|
243
|
-
snap = -pixelWidth / 2;
|
|
244
|
-
break;
|
|
245
|
-
// we ingnore full-width and wide
|
|
246
|
-
default:
|
|
247
|
-
snap = 0;
|
|
248
|
-
}
|
|
249
|
-
var snapWidths = getSnapWidth(guidelines, pixelWidth, snap, layout);
|
|
250
|
-
var snapToWidths = snapWidths.map(function (s) {
|
|
251
|
-
return s && s.width;
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// update guidelines
|
|
255
|
-
if (this.state.isResizing) {
|
|
256
|
-
var _findClosestSnap = findClosestSnap(this.state.size.width, snapToWidths, snapWidths, MEDIA_SINGLE_HIGHLIGHT_GAP),
|
|
257
|
-
gap = _findClosestSnap.gap,
|
|
258
|
-
activeGuidelineKeys = _findClosestSnap.keys;
|
|
259
|
-
this.displayGuideline(getGuidelinesWithHighlights(gap, MEDIA_SINGLE_HIGHLIGHT_GAP, activeGuidelineKeys, guidelines));
|
|
260
|
-
}
|
|
261
|
-
return snapToWidths.length > 0 ? {
|
|
262
|
-
x: snapToWidths
|
|
263
|
-
} : {};
|
|
264
|
-
}
|
|
265
|
-
return {};
|
|
266
|
-
}
|
|
267
322
|
}, {
|
|
268
323
|
key: "wrappedLayout",
|
|
269
324
|
get: function get() {
|
|
@@ -404,15 +459,16 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
404
459
|
key: "render",
|
|
405
460
|
value: function render() {
|
|
406
461
|
var _this2 = this;
|
|
407
|
-
var _this$
|
|
408
|
-
origWidth = _this$
|
|
409
|
-
layout = _this$
|
|
410
|
-
pctWidth = _this$
|
|
411
|
-
containerWidth = _this$
|
|
412
|
-
fullWidthMode = _this$
|
|
413
|
-
selected = _this$
|
|
414
|
-
children = _this$
|
|
415
|
-
intl = _this$
|
|
462
|
+
var _this$props8 = this.props,
|
|
463
|
+
origWidth = _this$props8.width,
|
|
464
|
+
layout = _this$props8.layout,
|
|
465
|
+
pctWidth = _this$props8.pctWidth,
|
|
466
|
+
containerWidth = _this$props8.containerWidth,
|
|
467
|
+
fullWidthMode = _this$props8.fullWidthMode,
|
|
468
|
+
selected = _this$props8.selected,
|
|
469
|
+
children = _this$props8.children,
|
|
470
|
+
intl = _this$props8.intl,
|
|
471
|
+
lineLength = _this$props8.lineLength;
|
|
416
472
|
var _this$state = this.state,
|
|
417
473
|
isResizing = _this$state.isResizing,
|
|
418
474
|
size = _this$state.size;
|
|
@@ -425,99 +481,6 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
425
481
|
}
|
|
426
482
|
});
|
|
427
483
|
|
|
428
|
-
/**
|
|
429
|
-
* NEW REFACTOR
|
|
430
|
-
*/
|
|
431
|
-
var roundPixelValue = function roundPixelValue(value) {
|
|
432
|
-
return Math.round(value);
|
|
433
|
-
};
|
|
434
|
-
var getHeightFromNewWidth = function getHeightFromNewWidth(originalWidth, originalHeight, newWidth) {
|
|
435
|
-
return roundPixelValue(originalHeight / originalWidth * newWidth);
|
|
436
|
-
};
|
|
437
|
-
var calculateSizeState = function calculateSizeState(size, delta) {
|
|
438
|
-
var originalWidth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
439
|
-
var originalHeight = arguments.length > 3 ? arguments[3] : undefined;
|
|
440
|
-
var onResizeStop = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
441
|
-
var calculatedWidth = roundPixelValue(size.width + delta.width);
|
|
442
|
-
var calculatedWidthWithLayout = _this2.calcNewSize(calculatedWidth, onResizeStop);
|
|
443
|
-
var calculatedHeightWithLayout = getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
|
|
444
|
-
return {
|
|
445
|
-
width: calculatedWidth,
|
|
446
|
-
height: calculatedHeightWithLayout,
|
|
447
|
-
calculatedWidthWithLayout: calculatedWidthWithLayout
|
|
448
|
-
};
|
|
449
|
-
};
|
|
450
|
-
var selectCurrentMediaNode = function selectCurrentMediaNode() {
|
|
451
|
-
if (!_this2.props.selected && typeof _this2.props.getPos === 'function') {
|
|
452
|
-
var propPos = _this2.props.getPos();
|
|
453
|
-
if (propPos !== undefined) {
|
|
454
|
-
setNodeSelection(_this2.props.view, propPos);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
var handleResizeStart = function handleResizeStart() {
|
|
459
|
-
_this2.setState({
|
|
460
|
-
isResizing: true
|
|
461
|
-
});
|
|
462
|
-
selectCurrentMediaNode();
|
|
463
|
-
_this2.setIsResizing(true);
|
|
464
|
-
|
|
465
|
-
// TODO: Update once type updated from editor common resizer
|
|
466
|
-
return 0;
|
|
467
|
-
};
|
|
468
|
-
var handleResize = function handleResize(size, delta) {
|
|
469
|
-
var _this2$props = _this2.props,
|
|
470
|
-
originalWidth = _this2$props.width,
|
|
471
|
-
originalHeight = _this2$props.height,
|
|
472
|
-
layout = _this2$props.layout,
|
|
473
|
-
updateSize = _this2$props.updateSize;
|
|
474
|
-
var _calculateSizeState = calculateSizeState(size, delta, originalWidth, originalHeight),
|
|
475
|
-
width = _calculateSizeState.width,
|
|
476
|
-
height = _calculateSizeState.height,
|
|
477
|
-
calculatedWidthWithLayout = _calculateSizeState.calculatedWidthWithLayout;
|
|
478
|
-
_this2.setState({
|
|
479
|
-
size: {
|
|
480
|
-
width: width,
|
|
481
|
-
height: height
|
|
482
|
-
}
|
|
483
|
-
});
|
|
484
|
-
if (calculatedWidthWithLayout.layout !== layout) {
|
|
485
|
-
updateSize(width, calculatedWidthWithLayout.layout);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// TODO: Update once type updated from editor common resizer
|
|
489
|
-
return 0;
|
|
490
|
-
};
|
|
491
|
-
var handleResizeStop = function handleResizeStop(size, delta) {
|
|
492
|
-
var _this2$props2 = _this2.props,
|
|
493
|
-
originalWidth = _this2$props2.width,
|
|
494
|
-
originalHeight = _this2$props2.height,
|
|
495
|
-
updateSize = _this2$props2.updateSize,
|
|
496
|
-
dispatchAnalyticsEvent = _this2$props2.dispatchAnalyticsEvent,
|
|
497
|
-
nodeType = _this2$props2.nodeType;
|
|
498
|
-
var _calculateSizeState2 = calculateSizeState(size, delta, originalWidth, originalHeight, true),
|
|
499
|
-
width = _calculateSizeState2.width,
|
|
500
|
-
height = _calculateSizeState2.height,
|
|
501
|
-
calculatedWidthWithLayout = _calculateSizeState2.calculatedWidthWithLayout;
|
|
502
|
-
_this2.setIsResizing(false);
|
|
503
|
-
_this2.displayGuideline([]);
|
|
504
|
-
if (dispatchAnalyticsEvent) {
|
|
505
|
-
dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
|
|
506
|
-
}
|
|
507
|
-
_this2.setState({
|
|
508
|
-
isResizing: false,
|
|
509
|
-
size: {
|
|
510
|
-
width: width,
|
|
511
|
-
height: height
|
|
512
|
-
}
|
|
513
|
-
}, function () {
|
|
514
|
-
updateSize(width, calculatedWidthWithLayout.layout);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
// TODO: Update once type updated from editor common resizer
|
|
518
|
-
return 0;
|
|
519
|
-
};
|
|
520
|
-
|
|
521
484
|
// TODO: Clean up where this lives and how it gets generated
|
|
522
485
|
var className = classnames(richMediaClassName, "image-".concat(layout), isResizing ? 'is-resizing' : 'not-resizing', this.props.className, {
|
|
523
486
|
'not-resized': !pctWidth,
|
|
@@ -527,6 +490,7 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
527
490
|
var resizerNextClassName = classnames(className, resizerStyles);
|
|
528
491
|
var showSizeGuide = selected || isResizing;
|
|
529
492
|
var label = layout === 'full-width' ? intl.formatMessage(messages.fullWidthImage) : "".concat(this.state.size.width, " x ").concat(this.state.size.height);
|
|
493
|
+
var maxWidth = this.calcMaxWidth(lineLength, containerWidth, fullWidthMode);
|
|
530
494
|
return jsx("div", {
|
|
531
495
|
ref: this.saveWrapper,
|
|
532
496
|
css: wrapperStyle({
|
|
@@ -540,14 +504,15 @@ var ResizableMediaSingleNext = /*#__PURE__*/function (_React$Component) {
|
|
|
540
504
|
})
|
|
541
505
|
}, jsx(ResizerNext, {
|
|
542
506
|
minWidth: MEDIA_SINGLE_MIN_PIXEL_WIDTH,
|
|
507
|
+
maxWidth: maxWidth,
|
|
543
508
|
className: resizerNextClassName,
|
|
544
509
|
snapGap: MEDIA_SINGLE_SNAP_GAP,
|
|
545
510
|
enable: enable,
|
|
546
511
|
width: size.width,
|
|
547
|
-
handleResizeStart: handleResizeStart,
|
|
548
|
-
handleResize: handleResize,
|
|
549
|
-
handleResizeStop: handleResizeStop,
|
|
550
|
-
snap: this.
|
|
512
|
+
handleResizeStart: this.handleResizeStart,
|
|
513
|
+
handleResize: this.handleResize,
|
|
514
|
+
handleResizeStop: this.handleResizeStop,
|
|
515
|
+
snap: this.state.snaps,
|
|
551
516
|
resizeRatio: nonWrappedLayouts.includes(layout) ? 2 : 1,
|
|
552
517
|
"data-testid": resizerNextTestId
|
|
553
518
|
}, showSizeGuide && jsx(ResizeLabel, {
|
package/dist/esm/version.json
CHANGED
|
@@ -344,11 +344,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
344
344
|
}>>];
|
|
345
345
|
actions: {
|
|
346
346
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
347
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
348
347
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
349
348
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
350
349
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
351
350
|
};
|
|
351
|
+
commands: {
|
|
352
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
353
|
+
};
|
|
352
354
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
353
355
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"hyperlink", {
|
|
354
356
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -389,11 +391,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
389
391
|
}>>];
|
|
390
392
|
actions: {
|
|
391
393
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
392
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
393
394
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
394
395
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
395
396
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
396
397
|
};
|
|
398
|
+
commands: {
|
|
399
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
400
|
+
};
|
|
397
401
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
398
402
|
}>, ...import("@atlaskit/editor-common/types").AllEditorPresetPluginTypes[]]>;
|
|
399
403
|
export declare function useDefaultPreset(props: EditorPresetProps & DefaultPresetPluginOptions): EditorPresetBuilder<[...string[], "hyperlink", "textFormatting", "width", "quickInsert", "typeAhead", "unsupportedContent", "editorDisabled", "submitEditor", "fakeTextCursor", "floatingToolbar", "selection", "codeBlock"], [(config: CodeBlockOptions, api?: import("@atlaskit/editor-common/types").PluginInjectionAPI<"codeBlock", {
|
|
@@ -703,11 +707,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
703
707
|
}>>];
|
|
704
708
|
actions: {
|
|
705
709
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
706
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
707
710
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
708
711
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
709
712
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
710
713
|
};
|
|
714
|
+
commands: {
|
|
715
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
716
|
+
};
|
|
711
717
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
712
718
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"hyperlink", {
|
|
713
719
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -748,10 +754,12 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
748
754
|
}>>];
|
|
749
755
|
actions: {
|
|
750
756
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
751
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
752
757
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
753
758
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
754
759
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
755
760
|
};
|
|
761
|
+
commands: {
|
|
762
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
763
|
+
};
|
|
756
764
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
757
765
|
}>, ...import("@atlaskit/editor-common/types").AllEditorPresetPluginTypes[]]>[];
|
|
@@ -41,6 +41,12 @@ export default class MediaSingleNode extends Component<MediaSingleNodeProps, Med
|
|
|
41
41
|
onMediaSingleClicked: (event: MouseEvent) => void;
|
|
42
42
|
render(): jsx.JSX.Element;
|
|
43
43
|
private clickPlaceholder;
|
|
44
|
+
/**
|
|
45
|
+
* Get parent width for a nested media single node
|
|
46
|
+
* @param view Editor view
|
|
47
|
+
* @param pos node position
|
|
48
|
+
* @param includeMoreParentNodeTypes should consider table and list as parent nodes(only true for new experience)
|
|
49
|
+
*/
|
|
44
50
|
private getLineLength;
|
|
45
51
|
}
|
|
46
52
|
declare class MediaSingleNodeView extends ReactNodeView<MediaSingleNodeViewProps> {
|
|
@@ -5,18 +5,21 @@ import { jsx } from '@emotion/react';
|
|
|
5
5
|
import type { RichMediaLayout as MediaSingleLayout } from '@atlaskit/adf-schema';
|
|
6
6
|
import type { MediaClientConfig } from '@atlaskit/media-core';
|
|
7
7
|
import type { Props } from './types';
|
|
8
|
-
import type { Dimensions } from '@atlaskit/editor-common/resizer';
|
|
8
|
+
import type { Dimensions, HandleResize, HandleResizeStart, Position, Snap } from '@atlaskit/editor-common/resizer';
|
|
9
9
|
import type { WrappedComponentProps } from 'react-intl-next';
|
|
10
|
+
import type { GuidelineConfig, GuidelineSnapsReference } from '@atlaskit/editor-common/guideline';
|
|
10
11
|
type State = {
|
|
11
12
|
offsetLeft: number;
|
|
12
13
|
isVideoFile: boolean;
|
|
13
14
|
resizedPctWidth?: number;
|
|
14
15
|
isResizing: boolean;
|
|
15
16
|
size: Dimensions;
|
|
17
|
+
snaps: Snap;
|
|
16
18
|
};
|
|
17
19
|
export declare const resizerNextTestId = "mediaSingle.resizerNext.testid";
|
|
18
20
|
type ResizableMediaSingleNextProps = Props & WrappedComponentProps;
|
|
19
21
|
declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSingleNextProps, State> {
|
|
22
|
+
private guidelines;
|
|
20
23
|
constructor(props: ResizableMediaSingleNextProps);
|
|
21
24
|
/**
|
|
22
25
|
* Calculate media single node initial width if props.mediaSingleWidth is undefined
|
|
@@ -25,10 +28,10 @@ declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSin
|
|
|
25
28
|
* @returns initial width in pixel
|
|
26
29
|
*/
|
|
27
30
|
calcInitialWidth(): number;
|
|
28
|
-
componentDidUpdate(prevProps: Props
|
|
31
|
+
componentDidUpdate(prevProps: Props): boolean;
|
|
29
32
|
isNestedNode(): boolean;
|
|
30
33
|
private getDefaultGuidelines;
|
|
31
|
-
private
|
|
34
|
+
private getAllGuidelines;
|
|
32
35
|
get wrappedLayout(): boolean;
|
|
33
36
|
componentDidMount(): Promise<void>;
|
|
34
37
|
UNSAFE_componentWillReceiveProps(nextProps: Props): void;
|
|
@@ -51,6 +54,22 @@ declare class ResizableMediaSingleNext extends React.Component<ResizableMediaSin
|
|
|
51
54
|
private saveWrapper;
|
|
52
55
|
private displayGuideline;
|
|
53
56
|
private setIsResizing;
|
|
57
|
+
private calcMaxWidth;
|
|
58
|
+
updateActiveGuidelines: (width: number | undefined, guidelines: GuidelineConfig[], guidelineSnapsReference: GuidelineSnapsReference) => void;
|
|
59
|
+
roundPixelValue: (value: number) => number;
|
|
60
|
+
getHeightFromNewWidth: (originalWidth: number, originalHeight: number, newWidth: number) => number;
|
|
61
|
+
calculateSizeState: (size: Position & Dimensions, delta: Dimensions, originalWidth: number | undefined, originalHeight: number, onResizeStop?: boolean) => {
|
|
62
|
+
width: number;
|
|
63
|
+
height: number;
|
|
64
|
+
calculatedWidthWithLayout: {
|
|
65
|
+
width: number | null;
|
|
66
|
+
layout: MediaSingleLayout;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
selectCurrentMediaNode: () => void;
|
|
70
|
+
handleResizeStart: HandleResizeStart;
|
|
71
|
+
handleResize: HandleResize;
|
|
72
|
+
handleResizeStop: HandleResize;
|
|
54
73
|
render(): jsx.JSX.Element;
|
|
55
74
|
}
|
|
56
75
|
export { ResizableMediaSingleNext as UnwrappedResizableMediaSingleNext };
|
|
@@ -413,11 +413,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
413
413
|
];
|
|
414
414
|
actions: {
|
|
415
415
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
416
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
417
416
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
418
417
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
419
418
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
420
419
|
};
|
|
420
|
+
commands: {
|
|
421
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
422
|
+
};
|
|
421
423
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
422
424
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"hyperlink", {
|
|
423
425
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -465,11 +467,13 @@ export declare function createDefaultPreset(options: EditorPresetProps & Default
|
|
|
465
467
|
];
|
|
466
468
|
actions: {
|
|
467
469
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
468
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
469
470
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
470
471
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
471
472
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
472
473
|
};
|
|
474
|
+
commands: {
|
|
475
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
476
|
+
};
|
|
473
477
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
474
478
|
}>,
|
|
475
479
|
...import("@atlaskit/editor-common/types").AllEditorPresetPluginTypes[]
|
|
@@ -850,11 +854,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
850
854
|
];
|
|
851
855
|
actions: {
|
|
852
856
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
853
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
854
857
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
855
858
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
856
859
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
857
860
|
};
|
|
861
|
+
commands: {
|
|
862
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
863
|
+
};
|
|
858
864
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
859
865
|
}> | undefined) => import("@atlaskit/editor-common/types").DefaultEditorPlugin<"hyperlink", {
|
|
860
866
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
@@ -902,11 +908,13 @@ export declare function useDefaultPreset(props: EditorPresetProps & DefaultPrese
|
|
|
902
908
|
];
|
|
903
909
|
actions: {
|
|
904
910
|
prependToolbarButtons: import("@atlaskit/editor-plugin-hyperlink").PrependToolbarButtons;
|
|
905
|
-
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
906
911
|
hideLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").HideLinkToolbar;
|
|
907
912
|
insertLink: import("@atlaskit/editor-plugin-hyperlink").InsertLink;
|
|
908
913
|
updateLink: import("@atlaskit/editor-plugin-hyperlink").UpdateLink;
|
|
909
914
|
};
|
|
915
|
+
commands: {
|
|
916
|
+
showLinkToolbar: import("@atlaskit/editor-plugin-hyperlink").ShowLinkToolbar;
|
|
917
|
+
};
|
|
910
918
|
sharedState: import("@atlaskit/editor-common/link").HyperlinkState | undefined;
|
|
911
919
|
}>,
|
|
912
920
|
...import("@atlaskit/editor-common/types").AllEditorPresetPluginTypes[]
|