@atlaskit/editor-core 187.14.4 → 187.14.7

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.
@@ -15,8 +15,8 @@ import { messages } from './resizable-media-single-messages';
15
15
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
16
16
  import classnames from 'classnames';
17
17
  import { richMediaClassName, resizerStyles } from '@atlaskit/editor-common/styles';
18
- import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_HIGHLIGHT_GAP, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
19
- import { findClosestSnap, getSnapWidth, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines } from '@atlaskit/editor-common/guideline';
18
+ import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH } from '@atlaskit/editor-common/media-single';
19
+ import { findClosestSnap, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines, getGuidelineSnaps } from '@atlaskit/editor-common/guideline';
20
20
  export const resizerNextTestId = 'mediaSingle.resizerNext.testid';
21
21
 
22
22
  // TODO: Create new fixed image size event
@@ -36,6 +36,23 @@ const getResizeAnalyticsEvent = (type, size, layout) => {
36
36
  class ResizableMediaSingleNext extends React.Component {
37
37
  constructor(props) {
38
38
  super(props);
39
+ _defineProperty(this, "guidelines", []);
40
+ _defineProperty(this, "getAllGuidelines", () => {
41
+ const {
42
+ view,
43
+ lineLength
44
+ } = this.props;
45
+ const defaultGuidelines = this.getDefaultGuidelines();
46
+ // disable guidelines for nested media single node
47
+ const dynamicGuidelines = this.isNestedNode() ? [] : generateDynamicGuidelines(view.state, lineLength, {
48
+ styles: {
49
+ lineStyle: 'dashed'
50
+ },
51
+ show: false
52
+ });
53
+ const guidelines = [...defaultGuidelines, ...dynamicGuidelines];
54
+ return guidelines;
55
+ });
39
56
  _defineProperty(this, "calcNewSize", (newWidth, stop) => {
40
57
  const {
41
58
  layout,
@@ -110,6 +127,106 @@ class ResizableMediaSingleNext extends React.Component {
110
127
  tr.setMeta('mediaSinglePlugin.isResizing', isResizing);
111
128
  return dispatch(tr);
112
129
  });
130
+ _defineProperty(this, "updateActiveGuidelines", (width = 0, guidelines, guidelineSnapsReference) => {
131
+ if (guidelineSnapsReference.snaps.x) {
132
+ const {
133
+ gap,
134
+ keys: activeGuidelineKeys
135
+ } = findClosestSnap(width, guidelineSnapsReference.snaps.x, guidelineSnapsReference.guidelineReference, MEDIA_SINGLE_SNAP_GAP);
136
+ this.displayGuideline(getGuidelinesWithHighlights(gap, MEDIA_SINGLE_SNAP_GAP, activeGuidelineKeys, guidelines));
137
+ }
138
+ });
139
+ _defineProperty(this, "roundPixelValue", value => Math.round(value));
140
+ _defineProperty(this, "getHeightFromNewWidth", (originalWidth, originalHeight, newWidth) => this.roundPixelValue(originalHeight / originalWidth * newWidth));
141
+ _defineProperty(this, "calculateSizeState", (size, delta, originalWidth = 0, originalHeight, onResizeStop = false) => {
142
+ const calculatedWidth = this.roundPixelValue(size.width + delta.width);
143
+ const calculatedWidthWithLayout = this.calcNewSize(calculatedWidth, onResizeStop);
144
+ const calculatedHeightWithLayout = this.getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
145
+ return {
146
+ width: calculatedWidth,
147
+ height: calculatedHeightWithLayout,
148
+ calculatedWidthWithLayout
149
+ };
150
+ });
151
+ _defineProperty(this, "selectCurrentMediaNode", () => {
152
+ // TODO: if adding !this.props.selected, it doesn't work if media single node is at top postion
153
+ if (typeof this.props.getPos === 'function') {
154
+ const propPos = this.props.getPos();
155
+ if (propPos !== undefined) {
156
+ setNodeSelection(this.props.view, propPos);
157
+ }
158
+ }
159
+ });
160
+ _defineProperty(this, "handleResizeStart", () => {
161
+ this.setState({
162
+ isResizing: true
163
+ });
164
+ this.selectCurrentMediaNode();
165
+ this.setIsResizing(true);
166
+ // re-calucate guidelines
167
+ this.guidelines = this.getAllGuidelines();
168
+ return 0;
169
+ });
170
+ _defineProperty(this, "handleResize", (size, delta) => {
171
+ const {
172
+ width: originalWidth,
173
+ height: originalHeight,
174
+ layout,
175
+ updateSize,
176
+ lineLength
177
+ } = this.props;
178
+ const {
179
+ width,
180
+ height,
181
+ calculatedWidthWithLayout
182
+ } = this.calculateSizeState(size, delta, originalWidth, originalHeight);
183
+ const guidelineSnaps = getGuidelineSnaps(this.guidelines, lineLength, layout);
184
+ this.updateActiveGuidelines(width, this.guidelines, guidelineSnaps);
185
+ this.setState({
186
+ size: {
187
+ width,
188
+ height
189
+ },
190
+ snaps: guidelineSnaps.snaps
191
+ });
192
+ if (calculatedWidthWithLayout.layout !== layout) {
193
+ updateSize(width, calculatedWidthWithLayout.layout);
194
+ }
195
+
196
+ // TODO: Update once type updated from editor common resizer
197
+ return 0;
198
+ });
199
+ _defineProperty(this, "handleResizeStop", (size, delta) => {
200
+ const {
201
+ width: originalWidth,
202
+ height: originalHeight,
203
+ updateSize,
204
+ dispatchAnalyticsEvent,
205
+ nodeType
206
+ } = this.props;
207
+ const {
208
+ width,
209
+ height,
210
+ calculatedWidthWithLayout
211
+ } = this.calculateSizeState(size, delta, originalWidth, originalHeight, true);
212
+ this.setIsResizing(false);
213
+ this.displayGuideline([]);
214
+ if (dispatchAnalyticsEvent) {
215
+ dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
216
+ }
217
+ this.setState({
218
+ isResizing: false,
219
+ size: {
220
+ width,
221
+ height
222
+ }
223
+ }, () => {
224
+ updateSize(width, calculatedWidthWithLayout.layout);
225
+ });
226
+
227
+ // TODO: Update once type updated from editor common resizer
228
+ return 0;
229
+ });
113
230
  const initialWidth = props.mediaSingleWidth || DEFAULT_IMAGE_WIDTH;
114
231
  this.state = {
115
232
  offsetLeft: calculateOffsetLeft(this.insideInlineLike, this.insideLayout, this.props.view.dom, undefined),
@@ -119,7 +236,8 @@ class ResizableMediaSingleNext extends React.Component {
119
236
  size: {
120
237
  width: initialWidth,
121
238
  height: this.calcPxHeight(initialWidth)
122
- }
239
+ },
240
+ snaps: {}
123
241
  };
124
242
  }
125
243
 
@@ -137,7 +255,7 @@ class ResizableMediaSingleNext extends React.Component {
137
255
  } = this.props;
138
256
  return Math.max(Math.min(origWidth || DEFAULT_IMAGE_WIDTH, contentWidth || containerWidth || akEditorDefaultLayoutWidth), MEDIA_SINGLE_MIN_PIXEL_WIDTH);
139
257
  }
140
- componentDidUpdate(prevProps, prevState) {
258
+ componentDidUpdate(prevProps) {
141
259
  const offsetLeft = calculateOffsetLeft(this.insideInlineLike, this.insideLayout, this.props.view.dom, this.wrapper);
142
260
  if (offsetLeft !== this.state.offsetLeft && offsetLeft >= 0) {
143
261
  this.setState({
@@ -152,10 +270,6 @@ class ResizableMediaSingleNext extends React.Component {
152
270
  resizedPctWidth: this.props.pctWidth
153
271
  });
154
272
  }
155
- if (prevState.isResizing !== this.state.isResizing && this.state.isResizing) {
156
- const guidelines = this.getDefaultGuidelines();
157
- this.displayGuideline(guidelines);
158
- }
159
273
  if (prevProps.mediaSingleWidth !== this.props.mediaSingleWidth && this.props.mediaSingleWidth) {
160
274
  // update size when lineLength becomes defined later
161
275
  // ensures extended experience renders legacy image with the same size as the legacy experience
@@ -184,71 +298,6 @@ class ResizableMediaSingleNext extends React.Component {
184
298
  // disable guidelines for nested media single node
185
299
  return this.isNestedNode() ? [] : generateDefaultGuidelines(lineLength, containerWidth, fullWidthMode);
186
300
  }
187
-
188
- // Calculate width of media nodes for snaps based on dynamic guidelines
189
- // TODO: refactor this later, maybe use state to hold snaps array
190
- getSnaps() {
191
- const {
192
- view,
193
- lineLength
194
- } = this.props;
195
- const {
196
- dom
197
- } = view;
198
- const defaultGuidelines = this.getDefaultGuidelines();
199
- // disable guidelines for nested media single node
200
- const dynamicGuidelines = this.isNestedNode() ? [] : generateDynamicGuidelines(view.state, lineLength, {
201
- styles: {
202
- lineStyle: 'dashed'
203
- },
204
- show: false
205
- });
206
- const guidelines = [...defaultGuidelines, ...dynamicGuidelines];
207
- const mediaSingleSelector = 'div.mediaSingleView-content-wrap.ProseMirror-selectednode';
208
- const {
209
- width
210
- } = dom.getBoundingClientRect();
211
- const halfWidth = width / 2;
212
- const selectedMedia = dom.querySelector(mediaSingleSelector);
213
- if (selectedMedia) {
214
- const pixelWidth = parseFloat(selectedMedia.getAttribute('width') || '') || 0;
215
- const layout = selectedMedia.getAttribute('layout');
216
- let snap = 0;
217
- switch (layout) {
218
- case 'align-start':
219
- case 'wrap-left':
220
- snap = pixelWidth - halfWidth;
221
- break;
222
- case 'align-end':
223
- case 'wrap-right':
224
- snap = width - pixelWidth - halfWidth;
225
- break;
226
- case 'center':
227
- case 'wide':
228
- case 'full-width':
229
- snap = -pixelWidth / 2;
230
- break;
231
- // we ingnore full-width and wide
232
- default:
233
- snap = 0;
234
- }
235
- const snapWidths = getSnapWidth(guidelines, pixelWidth, snap, layout);
236
- const snapToWidths = snapWidths.map(s => s && s.width);
237
-
238
- // update guidelines
239
- if (this.state.isResizing) {
240
- const {
241
- gap,
242
- keys: activeGuidelineKeys
243
- } = findClosestSnap(this.state.size.width, snapToWidths, snapWidths, MEDIA_SINGLE_HIGHLIGHT_GAP);
244
- this.displayGuideline(getGuidelinesWithHighlights(gap, MEDIA_SINGLE_HIGHLIGHT_GAP, activeGuidelineKeys, guidelines));
245
- }
246
- return snapToWidths.length > 0 ? {
247
- x: snapToWidths
248
- } : {};
249
- }
250
- return {};
251
- }
252
301
  get wrappedLayout() {
253
302
  return wrappedLayouts.indexOf(this.props.layout) > -1;
254
303
  }
@@ -356,96 +405,6 @@ class ResizableMediaSingleNext extends React.Component {
356
405
  }
357
406
  });
358
407
 
359
- /**
360
- * NEW REFACTOR
361
- */
362
- const roundPixelValue = value => Math.round(value);
363
- const getHeightFromNewWidth = (originalWidth, originalHeight, newWidth) => roundPixelValue(originalHeight / originalWidth * newWidth);
364
- const calculateSizeState = (size, delta, originalWidth = 0, originalHeight, onResizeStop = false) => {
365
- const calculatedWidth = roundPixelValue(size.width + delta.width);
366
- const calculatedWidthWithLayout = this.calcNewSize(calculatedWidth, onResizeStop);
367
- const calculatedHeightWithLayout = getHeightFromNewWidth(originalWidth, originalHeight, calculatedWidth);
368
- return {
369
- width: calculatedWidth,
370
- height: calculatedHeightWithLayout,
371
- calculatedWidthWithLayout
372
- };
373
- };
374
- const selectCurrentMediaNode = () => {
375
- if (!this.props.selected && typeof this.props.getPos === 'function') {
376
- const propPos = this.props.getPos();
377
- if (propPos !== undefined) {
378
- setNodeSelection(this.props.view, propPos);
379
- }
380
- }
381
- };
382
- const handleResizeStart = () => {
383
- this.setState({
384
- isResizing: true
385
- });
386
- selectCurrentMediaNode();
387
- this.setIsResizing(true);
388
-
389
- // TODO: Update once type updated from editor common resizer
390
- return 0;
391
- };
392
- const handleResize = (size, delta) => {
393
- const {
394
- width: originalWidth,
395
- height: originalHeight,
396
- layout,
397
- updateSize
398
- } = this.props;
399
- const {
400
- width,
401
- height,
402
- calculatedWidthWithLayout
403
- } = calculateSizeState(size, delta, originalWidth, originalHeight);
404
- this.setState({
405
- size: {
406
- width,
407
- height
408
- }
409
- });
410
- if (calculatedWidthWithLayout.layout !== layout) {
411
- updateSize(width, calculatedWidthWithLayout.layout);
412
- }
413
-
414
- // TODO: Update once type updated from editor common resizer
415
- return 0;
416
- };
417
- const handleResizeStop = (size, delta) => {
418
- const {
419
- width: originalWidth,
420
- height: originalHeight,
421
- updateSize,
422
- dispatchAnalyticsEvent,
423
- nodeType
424
- } = this.props;
425
- const {
426
- width,
427
- height,
428
- calculatedWidthWithLayout
429
- } = calculateSizeState(size, delta, originalWidth, originalHeight, true);
430
- this.setIsResizing(false);
431
- this.displayGuideline([]);
432
- if (dispatchAnalyticsEvent) {
433
- dispatchAnalyticsEvent(getResizeAnalyticsEvent(nodeType, calculatedWidthWithLayout.width, calculatedWidthWithLayout.layout));
434
- }
435
- this.setState({
436
- isResizing: false,
437
- size: {
438
- width,
439
- height
440
- }
441
- }, () => {
442
- updateSize(width, calculatedWidthWithLayout.layout);
443
- });
444
-
445
- // TODO: Update once type updated from editor common resizer
446
- return 0;
447
- };
448
-
449
408
  // TODO: Clean up where this lives and how it gets generated
450
409
  const className = classnames(richMediaClassName, `image-${layout}`, isResizing ? 'is-resizing' : 'not-resizing', this.props.className, {
451
410
  'not-resized': !pctWidth,
@@ -472,10 +431,10 @@ class ResizableMediaSingleNext extends React.Component {
472
431
  snapGap: MEDIA_SINGLE_SNAP_GAP,
473
432
  enable: enable,
474
433
  width: size.width,
475
- handleResizeStart: handleResizeStart,
476
- handleResize: handleResize,
477
- handleResizeStop: handleResizeStop,
478
- snap: this.getSnaps(),
434
+ handleResizeStart: this.handleResizeStart,
435
+ handleResize: this.handleResize,
436
+ handleResizeStop: this.handleResizeStop,
437
+ snap: this.state.snaps,
479
438
  resizeRatio: nonWrappedLayouts.includes(layout) ? 2 : 1,
480
439
  "data-testid": resizerNextTestId
481
440
  }, showSizeGuide && jsx(ResizeLabel, {
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.14.4";
2
+ export const version = "187.14.7";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.14.4",
3
+ "version": "187.14.7",
4
4
  "sideEffects": false
5
5
  }
@@ -17,6 +17,7 @@ import ReactDOM from 'react-dom';
17
17
  import { injectIntl } from 'react-intl-next';
18
18
  import { EmojiPicker as AkEmojiPicker } from '@atlaskit/emoji/picker';
19
19
  import { Popup } from '@atlaskit/editor-common/ui';
20
+ import { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
20
21
  import ToolbarButton from '../../../../ui/ToolbarButton';
21
22
  import { separatorStyles, buttonGroupStyle, wrapperStyle } from '@atlaskit/editor-common/styles';
22
23
  import { insertDate } from '../../../date/actions';
@@ -172,7 +173,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
172
173
  pluginInjectionApi = _this$props.pluginInjectionApi;
173
174
  var state = editorView.state,
174
175
  dispatch = editorView.dispatch;
175
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions.showLinkToolbar(inputMethod)(state, dispatch);
176
+
177
+ // We should update this to use `pluginInjectionApi.executeCommand` once available
178
+ pluginCommandToPMCommand(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.hyperlink) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.commands.showLinkToolbar(inputMethod))(state, dispatch);
176
179
  return true;
177
180
  });
178
181
  _defineProperty(_assertThisInitialized(_this), "insertMention", function (inputMethod) {