@atlaskit/editor-core 187.27.0 → 187.28.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.
- package/CHANGELOG.md +17 -0
- package/dist/cjs/plugins/insert-block/types.js +5 -0
- package/dist/cjs/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +92 -155
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/plugins/insert-block/types.js +1 -0
- package/dist/es2019/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +73 -136
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/plugins/insert-block/types.js +1 -0
- package/dist/esm/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +94 -157
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/plugins/insert-block/index.d.ts +3 -19
- package/dist/types/plugins/insert-block/types.d.ts +19 -0
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +3 -3
- package/dist/types/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +10 -24
- package/dist/types/use-preset.d.ts +2 -8
- package/dist/types-ts4.5/plugins/insert-block/index.d.ts +3 -19
- package/dist/types-ts4.5/plugins/insert-block/types.d.ts +19 -0
- package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +3 -3
- package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +10 -24
- package/dist/types-ts4.5/use-preset.d.ts +2 -8
- package/package.json +3 -3
|
@@ -4,9 +4,9 @@ import React from 'react';
|
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
5
|
import { findParentNodeOfTypeClosestToPos, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { getMediaClient } from '@atlaskit/media-client';
|
|
7
|
-
import { calcPctFromPx, wrappedLayouts, handleSides, imageAlignmentMap
|
|
7
|
+
import { calcPctFromPx, wrappedLayouts, handleSides, imageAlignmentMap } from '@atlaskit/editor-common/ui';
|
|
8
8
|
import { nonWrappedLayouts, setNodeSelection } from '@atlaskit/editor-common/utils';
|
|
9
|
-
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding
|
|
9
|
+
import { akEditorFullWidthLayoutWidth, akEditorGutterPadding } from '@atlaskit/editor-shared-styles';
|
|
10
10
|
import { wrapperStyle } from './styled';
|
|
11
11
|
import { ResizerNext } from '@atlaskit/editor-common/resizer';
|
|
12
12
|
import classnames from 'classnames';
|
|
@@ -94,12 +94,6 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
94
94
|
// so that we have image aligned with text
|
|
95
95
|
return 'full-width';
|
|
96
96
|
});
|
|
97
|
-
_defineProperty(this, "calcColumnLeftOffset", () => {
|
|
98
|
-
const {
|
|
99
|
-
offsetLeft
|
|
100
|
-
} = this.state;
|
|
101
|
-
return this.insideInlineLike ? calcColumnsFromPx(offsetLeft, this.props.lineLength, this.props.gridSize) : 0;
|
|
102
|
-
});
|
|
103
97
|
_defineProperty(this, "calcPxHeight", newWidth => {
|
|
104
98
|
const {
|
|
105
99
|
width = newWidth,
|
|
@@ -109,11 +103,8 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
109
103
|
});
|
|
110
104
|
_defineProperty(this, "saveWrapper", wrapper => this.wrapper = wrapper);
|
|
111
105
|
_defineProperty(this, "displayGuideline", guidelines => {
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
pluginInjectionApi
|
|
115
|
-
} = this.props;
|
|
116
|
-
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)({
|
|
106
|
+
var _this$props$pluginInj, _this$props$pluginInj2, _this$props$pluginInj3, _this$props$pluginInj4;
|
|
107
|
+
return (_this$props$pluginInj = this.props.pluginInjectionApi) === null || _this$props$pluginInj === void 0 ? void 0 : (_this$props$pluginInj2 = _this$props$pluginInj.dependencies) === null || _this$props$pluginInj2 === void 0 ? void 0 : (_this$props$pluginInj3 = _this$props$pluginInj2.guideline) === null || _this$props$pluginInj3 === void 0 ? void 0 : (_this$props$pluginInj4 = _this$props$pluginInj3.actions) === null || _this$props$pluginInj4 === void 0 ? void 0 : _this$props$pluginInj4.displayGuideline(this.props.view)({
|
|
117
108
|
guidelines
|
|
118
109
|
});
|
|
119
110
|
});
|
|
@@ -142,9 +133,10 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
142
133
|
return calcMediaSingleMaxWidth(containerWidth);
|
|
143
134
|
}));
|
|
144
135
|
_defineProperty(this, "getRelativeGuides", () => {
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
136
|
+
const $pos = this.$pos;
|
|
137
|
+
const relativeGuides = $pos && $pos.nodeAfter && this.state.size.width ? getRelativeGuidelines(this.state.relativeGuides, {
|
|
138
|
+
node: $pos.nodeAfter,
|
|
139
|
+
pos: $pos.pos
|
|
148
140
|
}, this.props.view, this.props.lineLength, this.state.size) : [];
|
|
149
141
|
return relativeGuides;
|
|
150
142
|
});
|
|
@@ -159,51 +151,19 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
159
151
|
this.displayGuideline([...getGuidelinesWithHighlights(gap, MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines), ...relativeGuidelines]);
|
|
160
152
|
}
|
|
161
153
|
});
|
|
162
|
-
_defineProperty(this, "
|
|
163
|
-
|
|
164
|
-
_defineProperty(this, "calculateSizeState", (size, delta, originalWidth = 0, originalHeight, onResizeStop = false) => {
|
|
165
|
-
const calculatedWidth = this.roundPixelValue(size.width + delta.width);
|
|
154
|
+
_defineProperty(this, "calculateSizeState", (size, delta, onResizeStop = false) => {
|
|
155
|
+
const calculatedWidth = Math.round(size.width + delta.width);
|
|
166
156
|
const calculatedWidthWithLayout = this.calcNewSize(calculatedWidth, onResizeStop);
|
|
167
|
-
const calculatedHeightWithLayout = this.getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
|
|
168
157
|
return {
|
|
169
158
|
width: calculatedWidth,
|
|
170
|
-
height:
|
|
159
|
+
height: calculatedWidth / this.aspectRatio,
|
|
171
160
|
calculatedWidthWithLayout
|
|
172
161
|
};
|
|
173
162
|
});
|
|
174
163
|
_defineProperty(this, "selectCurrentMediaNode", () => {
|
|
175
164
|
// TODO: if adding !this.props.selected, it doesn't work if media single node is at top postion
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (propPos !== undefined) {
|
|
179
|
-
setNodeSelection(this.props.view, propPos);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
_defineProperty(this, "getParentNodeTypeNameFromCurrentPositionNode", () => {
|
|
184
|
-
const $pos = this.$pos;
|
|
185
|
-
if (!$pos) {
|
|
186
|
-
return undefined;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// Supported Parent Nodes
|
|
190
|
-
const {
|
|
191
|
-
listItem,
|
|
192
|
-
expand,
|
|
193
|
-
tableCell,
|
|
194
|
-
tableHeader,
|
|
195
|
-
layoutSection,
|
|
196
|
-
nestedExpand
|
|
197
|
-
} = this.props.view.state.schema.nodes;
|
|
198
|
-
const parentNode = findParentNodeOfTypeClosestToPos($pos, [listItem, expand, tableCell, tableHeader, layoutSection, nestedExpand]);
|
|
199
|
-
|
|
200
|
-
// Return matched parent node name
|
|
201
|
-
if (parentNode) {
|
|
202
|
-
return parentNode.node.type.name;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Return undefined if parent node cannot be found
|
|
206
|
-
return undefined;
|
|
165
|
+
const pos = this.pos;
|
|
166
|
+
pos && setNodeSelection(this.props.view, pos);
|
|
207
167
|
});
|
|
208
168
|
_defineProperty(this, "handleResizeStart", () => {
|
|
209
169
|
this.setState({
|
|
@@ -212,13 +172,11 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
212
172
|
this.selectCurrentMediaNode();
|
|
213
173
|
this.setIsResizing(true);
|
|
214
174
|
this.updateSizeInPluginState(this.state.size.width);
|
|
215
|
-
// re-
|
|
175
|
+
// re-calculate guidelines
|
|
216
176
|
this.updateGuidelines();
|
|
217
177
|
});
|
|
218
178
|
_defineProperty(this, "handleResize", (size, delta) => {
|
|
219
179
|
const {
|
|
220
|
-
width: originalWidth,
|
|
221
|
-
height: originalHeight,
|
|
222
180
|
layout,
|
|
223
181
|
updateSize,
|
|
224
182
|
lineLength
|
|
@@ -227,7 +185,7 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
227
185
|
width,
|
|
228
186
|
height,
|
|
229
187
|
calculatedWidthWithLayout
|
|
230
|
-
} = this.calculateSizeState(size, delta
|
|
188
|
+
} = this.calculateSizeState(size, delta);
|
|
231
189
|
const guidelineSnaps = getGuidelineSnaps(this.state.guidelines, lineLength, layout);
|
|
232
190
|
this.updateActiveGuidelines(width, this.state.guidelines, guidelineSnaps);
|
|
233
191
|
const relativeSnaps = getRelativeGuideSnaps(this.state.relativeGuides, this.aspectRatio);
|
|
@@ -247,8 +205,6 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
247
205
|
});
|
|
248
206
|
_defineProperty(this, "handleResizeStop", (size, delta) => {
|
|
249
207
|
const {
|
|
250
|
-
width: originalWidth,
|
|
251
|
-
height: originalHeight,
|
|
252
208
|
updateSize,
|
|
253
209
|
dispatchAnalyticsEvent,
|
|
254
210
|
nodeType
|
|
@@ -257,14 +213,15 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
257
213
|
width,
|
|
258
214
|
height,
|
|
259
215
|
calculatedWidthWithLayout
|
|
260
|
-
} = this.calculateSizeState(size, delta,
|
|
216
|
+
} = this.calculateSizeState(size, delta, true);
|
|
261
217
|
if (dispatchAnalyticsEvent) {
|
|
218
|
+
const $pos = this.$pos;
|
|
262
219
|
const event = getMediaResizeAnalyticsEvent(nodeType || 'mediaSingle', {
|
|
263
220
|
width,
|
|
264
221
|
layout: calculatedWidthWithLayout.layout,
|
|
265
222
|
widthType: 'pixel',
|
|
266
223
|
snapType: getGuidelineTypeFromKey(this.lastSnappedGuidelineKeys, this.state.guidelines),
|
|
267
|
-
parentNode:
|
|
224
|
+
parentNode: $pos ? $pos.parent.type.name : undefined
|
|
268
225
|
});
|
|
269
226
|
if (event) {
|
|
270
227
|
dispatchAnalyticsEvent(event);
|
|
@@ -297,21 +254,6 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
297
254
|
guidelines: []
|
|
298
255
|
};
|
|
299
256
|
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Calculate media single node initial width if props.mediaSingleWidth is undefined
|
|
303
|
-
* (Mainly when switching from lagacy experience to new experience).
|
|
304
|
-
*
|
|
305
|
-
* @returns initial width in pixel
|
|
306
|
-
*/
|
|
307
|
-
calcInitialWidth() {
|
|
308
|
-
const {
|
|
309
|
-
width: origWidth,
|
|
310
|
-
lineLength: contentWidth,
|
|
311
|
-
containerWidth
|
|
312
|
-
} = this.props;
|
|
313
|
-
return Math.max(Math.min(origWidth || DEFAULT_IMAGE_WIDTH, contentWidth || containerWidth || akEditorDefaultLayoutWidth), MEDIA_SINGLE_MIN_PIXEL_WIDTH);
|
|
314
|
-
}
|
|
315
257
|
componentDidUpdate(prevProps) {
|
|
316
258
|
const offsetLeft = calculateOffsetLeft(this.insideInlineLike, this.insideLayout, this.props.view.dom, this.wrapper);
|
|
317
259
|
if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
|
|
@@ -352,24 +294,6 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
352
294
|
}
|
|
353
295
|
return true;
|
|
354
296
|
}
|
|
355
|
-
|
|
356
|
-
// check if is inside of layout, table, expand, nestedExpand and list item
|
|
357
|
-
isNestedNode() {
|
|
358
|
-
return !!(this.$pos && this.$pos.parent.type.name !== 'doc');
|
|
359
|
-
}
|
|
360
|
-
getDefaultGuidelines() {
|
|
361
|
-
const {
|
|
362
|
-
lineLength,
|
|
363
|
-
containerWidth,
|
|
364
|
-
fullWidthMode
|
|
365
|
-
} = this.props;
|
|
366
|
-
|
|
367
|
-
// disable guidelines for nested media single node
|
|
368
|
-
return this.isNestedNode() ? [] : generateDefaultGuidelines(lineLength, containerWidth, fullWidthMode);
|
|
369
|
-
}
|
|
370
|
-
get wrappedLayout() {
|
|
371
|
-
return wrappedLayouts.indexOf(this.props.layout) > -1;
|
|
372
|
-
}
|
|
373
297
|
async componentDidMount() {
|
|
374
298
|
const {
|
|
375
299
|
viewMediaClientConfig
|
|
@@ -383,6 +307,24 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
383
307
|
this.checkVideoFile(nextProps.viewMediaClientConfig);
|
|
384
308
|
}
|
|
385
309
|
}
|
|
310
|
+
get wrappedLayout() {
|
|
311
|
+
return wrappedLayouts.indexOf(this.props.layout) > -1;
|
|
312
|
+
}
|
|
313
|
+
get pos() {
|
|
314
|
+
if (typeof this.props.getPos !== 'function') {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
const pos = this.props.getPos();
|
|
318
|
+
if (Number.isNaN(pos) || typeof pos !== 'number') {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
return pos;
|
|
322
|
+
}
|
|
323
|
+
get $pos() {
|
|
324
|
+
const pos = this.pos;
|
|
325
|
+
// need to pass view because we may not get updated props in time
|
|
326
|
+
return pos && this.props.view.state.doc.resolve(pos);
|
|
327
|
+
}
|
|
386
328
|
get aspectRatio() {
|
|
387
329
|
const {
|
|
388
330
|
width,
|
|
@@ -391,9 +333,46 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
391
333
|
if (width) {
|
|
392
334
|
return width / height;
|
|
393
335
|
}
|
|
336
|
+
|
|
394
337
|
// TODO handle this case
|
|
395
338
|
return 1;
|
|
396
339
|
}
|
|
340
|
+
get insideInlineLike() {
|
|
341
|
+
const $pos = this.$pos;
|
|
342
|
+
if (!$pos) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
const {
|
|
346
|
+
listItem
|
|
347
|
+
} = this.props.view.state.schema.nodes;
|
|
348
|
+
return !!findParentNodeOfTypeClosestToPos($pos, [listItem]);
|
|
349
|
+
}
|
|
350
|
+
get insideLayout() {
|
|
351
|
+
const $pos = this.$pos;
|
|
352
|
+
if (!$pos) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
const {
|
|
356
|
+
layoutColumn
|
|
357
|
+
} = this.props.view.state.schema.nodes;
|
|
358
|
+
return !!findParentNodeOfTypeClosestToPos($pos, [layoutColumn]);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// check if is inside of layout, table, expand, nestedExpand and list item
|
|
362
|
+
isNestedNode() {
|
|
363
|
+
const $pos = this.$pos;
|
|
364
|
+
return !!($pos && $pos.parent.type !== $pos.parent.type.schema.nodes.doc);
|
|
365
|
+
}
|
|
366
|
+
getDefaultGuidelines() {
|
|
367
|
+
const {
|
|
368
|
+
lineLength,
|
|
369
|
+
containerWidth,
|
|
370
|
+
fullWidthMode
|
|
371
|
+
} = this.props;
|
|
372
|
+
|
|
373
|
+
// disable guidelines for nested media single node
|
|
374
|
+
return this.isNestedNode() ? [] : generateDefaultGuidelines(lineLength, containerWidth, fullWidthMode);
|
|
375
|
+
}
|
|
397
376
|
async checkVideoFile(viewMediaClientConfig) {
|
|
398
377
|
const $pos = this.$pos;
|
|
399
378
|
if (!$pos || !viewMediaClientConfig) {
|
|
@@ -419,48 +398,6 @@ class ResizableMediaSingleNext extends React.Component {
|
|
|
419
398
|
});
|
|
420
399
|
}
|
|
421
400
|
}
|
|
422
|
-
get $pos() {
|
|
423
|
-
if (typeof this.props.getPos !== 'function') {
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
|
-
const pos = this.props.getPos();
|
|
427
|
-
if (Number.isNaN(pos) || typeof pos !== 'number') {
|
|
428
|
-
return null;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// need to pass view because we may not get updated props in time
|
|
432
|
-
return this.props.view.state.doc.resolve(pos);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
/**
|
|
436
|
-
* The maxmimum number of grid columns this node can resize to.
|
|
437
|
-
*/
|
|
438
|
-
get gridWidth() {
|
|
439
|
-
const {
|
|
440
|
-
gridSize
|
|
441
|
-
} = this.props;
|
|
442
|
-
return !(this.wrappedLayout || this.insideInlineLike) ? gridSize / 2 : gridSize;
|
|
443
|
-
}
|
|
444
|
-
get insideInlineLike() {
|
|
445
|
-
const $pos = this.$pos;
|
|
446
|
-
if (!$pos) {
|
|
447
|
-
return false;
|
|
448
|
-
}
|
|
449
|
-
const {
|
|
450
|
-
listItem
|
|
451
|
-
} = this.props.view.state.schema.nodes;
|
|
452
|
-
return !!findParentNodeOfTypeClosestToPos($pos, [listItem]);
|
|
453
|
-
}
|
|
454
|
-
get insideLayout() {
|
|
455
|
-
const $pos = this.$pos;
|
|
456
|
-
if (!$pos) {
|
|
457
|
-
return false;
|
|
458
|
-
}
|
|
459
|
-
const {
|
|
460
|
-
layoutColumn
|
|
461
|
-
} = this.props.view.state.schema.nodes;
|
|
462
|
-
return !!findParentNodeOfTypeClosestToPos($pos, [layoutColumn]);
|
|
463
|
-
}
|
|
464
401
|
render() {
|
|
465
402
|
const {
|
|
466
403
|
width: origWidth,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|