@atlaskit/editor-core 187.19.1 → 187.20.1

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 (113) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/plugins/emoji/commands/insert-emoji.js +21 -20
  3. package/dist/cjs/plugins/emoji/index.js +16 -5
  4. package/dist/cjs/plugins/index.js +2 -2
  5. package/dist/cjs/plugins/insert-block/index.js +3 -7
  6. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +4 -3
  7. package/dist/cjs/plugins/media/nodeviews/mediaSingle.js +28 -10
  8. package/dist/cjs/plugins/media/pm-plugins/main.js +13 -1
  9. package/dist/cjs/plugins/media/styles.js +1 -1
  10. package/dist/cjs/plugins/media/toolbar/index.js +21 -8
  11. package/dist/cjs/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +40 -8
  12. package/dist/cjs/plugins/media/utils/media-single.js +21 -2
  13. package/dist/cjs/plugins/text-color/commands/toggle-color.js +3 -2
  14. package/dist/cjs/utils/document.js +6 -24
  15. package/dist/cjs/utils/index.js +33 -105
  16. package/dist/cjs/utils/prosemirror/position.js +33 -41
  17. package/dist/cjs/version-wrapper.js +1 -1
  18. package/dist/cjs/version.json +1 -1
  19. package/dist/es2019/plugins/emoji/commands/insert-emoji.js +24 -20
  20. package/dist/es2019/plugins/emoji/index.js +14 -4
  21. package/dist/es2019/plugins/index.js +1 -1
  22. package/dist/es2019/plugins/insert-block/index.js +3 -7
  23. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +6 -3
  24. package/dist/es2019/plugins/media/nodeviews/mediaSingle.js +21 -3
  25. package/dist/es2019/plugins/media/pm-plugins/main.js +9 -0
  26. package/dist/es2019/plugins/media/styles.js +8 -2
  27. package/dist/es2019/plugins/media/toolbar/index.js +22 -10
  28. package/dist/es2019/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +39 -7
  29. package/dist/es2019/plugins/media/utils/media-single.js +21 -2
  30. package/dist/es2019/plugins/text-color/commands/toggle-color.js +3 -2
  31. package/dist/es2019/utils/document.js +1 -20
  32. package/dist/es2019/utils/index.js +1 -99
  33. package/dist/es2019/utils/prosemirror/position.js +1 -51
  34. package/dist/es2019/version-wrapper.js +1 -1
  35. package/dist/es2019/version.json +1 -1
  36. package/dist/esm/plugins/emoji/commands/insert-emoji.js +21 -20
  37. package/dist/esm/plugins/emoji/index.js +14 -4
  38. package/dist/esm/plugins/index.js +1 -1
  39. package/dist/esm/plugins/insert-block/index.js +3 -7
  40. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +4 -3
  41. package/dist/esm/plugins/media/nodeviews/mediaSingle.js +21 -3
  42. package/dist/esm/plugins/media/pm-plugins/main.js +11 -0
  43. package/dist/esm/plugins/media/styles.js +1 -1
  44. package/dist/esm/plugins/media/toolbar/index.js +23 -10
  45. package/dist/esm/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.js +41 -9
  46. package/dist/esm/plugins/media/utils/media-single.js +20 -2
  47. package/dist/esm/plugins/text-color/commands/toggle-color.js +3 -2
  48. package/dist/esm/utils/document.js +1 -22
  49. package/dist/esm/utils/index.js +1 -97
  50. package/dist/esm/utils/prosemirror/position.js +1 -39
  51. package/dist/esm/version-wrapper.js +1 -1
  52. package/dist/esm/version.json +1 -1
  53. package/dist/types/actions/index.d.ts +2 -3
  54. package/dist/types/labs/next/presets/default.d.ts +32 -32
  55. package/dist/types/plugins/collab-edit/actions.d.ts +1 -1
  56. package/dist/types/plugins/collab-edit/events/handlers.d.ts +2 -2
  57. package/dist/types/plugins/collab-edit/events/initialize.d.ts +1 -1
  58. package/dist/types/plugins/collab-edit/events/send-transaction.d.ts +1 -1
  59. package/dist/types/plugins/collab-edit/index.d.ts +1 -1
  60. package/dist/types/plugins/collab-edit/native-collab-provider-plugin.d.ts +2 -2
  61. package/dist/types/plugins/collab-edit/participants.d.ts +1 -1
  62. package/dist/types/plugins/collab-edit/plugin.d.ts +5 -6
  63. package/dist/types/plugins/collab-edit/types.d.ts +1 -2
  64. package/dist/types/plugins/collab-edit/ui/to-avatar.d.ts +2 -2
  65. package/dist/types/plugins/collab-edit/utils.d.ts +1 -2
  66. package/dist/types/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  67. package/dist/types/plugins/emoji/index.d.ts +9 -4
  68. package/dist/types/plugins/index.d.ts +1 -1
  69. package/dist/types/plugins/insert-block/index.d.ts +3 -1
  70. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +0 -1
  71. package/dist/types/plugins/media/nodeviews/mediaSingle.d.ts +6 -1
  72. package/dist/types/plugins/media/pm-plugins/main.d.ts +3 -0
  73. package/dist/types/plugins/media/pm-plugins/types.d.ts +2 -0
  74. package/dist/types/plugins/media/toolbar/index.d.ts +1 -2
  75. package/dist/types/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +2 -1
  76. package/dist/types/plugins/media/utils/media-single.d.ts +2 -1
  77. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  78. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  79. package/dist/types/utils/document.d.ts +2 -7
  80. package/dist/types/utils/index.d.ts +2 -6
  81. package/dist/types/utils/prosemirror/position.d.ts +1 -8
  82. package/dist/types-ts4.5/actions/index.d.ts +2 -3
  83. package/dist/types-ts4.5/labs/next/presets/default.d.ts +32 -32
  84. package/dist/types-ts4.5/plugins/collab-edit/actions.d.ts +1 -1
  85. package/dist/types-ts4.5/plugins/collab-edit/events/handlers.d.ts +2 -2
  86. package/dist/types-ts4.5/plugins/collab-edit/events/initialize.d.ts +1 -1
  87. package/dist/types-ts4.5/plugins/collab-edit/events/send-transaction.d.ts +1 -1
  88. package/dist/types-ts4.5/plugins/collab-edit/index.d.ts +1 -1
  89. package/dist/types-ts4.5/plugins/collab-edit/native-collab-provider-plugin.d.ts +2 -2
  90. package/dist/types-ts4.5/plugins/collab-edit/participants.d.ts +1 -1
  91. package/dist/types-ts4.5/plugins/collab-edit/plugin.d.ts +5 -6
  92. package/dist/types-ts4.5/plugins/collab-edit/types.d.ts +1 -2
  93. package/dist/types-ts4.5/plugins/collab-edit/ui/to-avatar.d.ts +2 -2
  94. package/dist/types-ts4.5/plugins/collab-edit/utils.d.ts +1 -2
  95. package/dist/types-ts4.5/plugins/emoji/commands/insert-emoji.d.ts +2 -2
  96. package/dist/types-ts4.5/plugins/emoji/index.d.ts +9 -4
  97. package/dist/types-ts4.5/plugins/index.d.ts +1 -1
  98. package/dist/types-ts4.5/plugins/insert-block/index.d.ts +3 -1
  99. package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/index.d.ts +0 -1
  100. package/dist/types-ts4.5/plugins/media/nodeviews/mediaSingle.d.ts +6 -1
  101. package/dist/types-ts4.5/plugins/media/pm-plugins/main.d.ts +3 -0
  102. package/dist/types-ts4.5/plugins/media/pm-plugins/types.d.ts +2 -0
  103. package/dist/types-ts4.5/plugins/media/toolbar/index.d.ts +1 -2
  104. package/dist/types-ts4.5/plugins/media/ui/ResizableMediaSingle/ResizableMediaSingleNext.d.ts +2 -1
  105. package/dist/types-ts4.5/plugins/media/utils/media-single.d.ts +2 -1
  106. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  107. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  108. package/dist/types-ts4.5/utils/document.d.ts +2 -7
  109. package/dist/types-ts4.5/utils/index.d.ts +2 -6
  110. package/dist/types-ts4.5/utils/prosemirror/position.d.ts +1 -8
  111. package/package.json +4 -4
  112. package/report.api.md +5 -1
  113. package/tmp/api-report-tmp.d.ts +5 -1
@@ -27,6 +27,7 @@ import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
27
27
  export { stateKey } from './plugin-key';
28
28
  export const MEDIA_CONTENT_WRAP_CLASS_NAME = 'media-content-wrap';
29
29
  export const MEDIA_PLUGIN_IS_RESIZING_KEY = 'mediaSinglePlugin.isResizing';
30
+ export const MEDIA_PLUGIN_RESIZING_WIDTH_KEY = 'mediaSinglePlugin.resizing-width';
30
31
  const createDropPlaceholder = (intl, allowDropLine) => {
31
32
  const dropPlaceholder = document.createElement('div');
32
33
  const createElement = React.createElement;
@@ -55,6 +56,7 @@ export class MediaPluginStateImplementation {
55
56
  _defineProperty(this, "layout", 'center');
56
57
  _defineProperty(this, "mediaNodes", []);
57
58
  _defineProperty(this, "isResizing", false);
59
+ _defineProperty(this, "resizingWidth", 0);
58
60
  _defineProperty(this, "destroyed", false);
59
61
  _defineProperty(this, "removeOnCloseListener", () => {});
60
62
  _defineProperty(this, "onPopupToggleCallback", () => {});
@@ -428,6 +430,9 @@ export class MediaPluginStateImplementation {
428
430
  setIsResizing(isResizing) {
429
431
  this.isResizing = isResizing;
430
432
  }
433
+ setResizingWidth(width) {
434
+ this.resizingWidth = width;
435
+ }
431
436
  updateElement() {
432
437
  let newElement;
433
438
  const selectedContainer = this.selectedMediaContainerNode();
@@ -530,9 +535,13 @@ export const createPlugin = (_schema, options, reactContext, getIntl, dispatch,
530
535
  },
531
536
  apply(tr, pluginState) {
532
537
  const isResizing = tr.getMeta(MEDIA_PLUGIN_IS_RESIZING_KEY);
538
+ const resizingWidth = tr.getMeta(MEDIA_PLUGIN_RESIZING_WIDTH_KEY);
533
539
  if (isResizing !== undefined) {
534
540
  pluginState.setIsResizing(isResizing);
535
541
  }
542
+ if (resizingWidth) {
543
+ pluginState.setResizingWidth(resizingWidth);
544
+ }
536
545
 
537
546
  // remap editing media single position if we're in collab
538
547
  if (typeof pluginState.editingMediaSinglePos === 'number') {
@@ -11,6 +11,12 @@ export const mediaStyles = css`
11
11
  transform: translateX(-50%);
12
12
  }
13
13
 
14
+ .media-extended-resize-experience[layout^='wrap-'] {
15
+ // override 'overflow: auto' when viewport <= 410 set by mediaSingleSharedStyle
16
+ // to prevent scroll bar
17
+ overflow: visible !important;
18
+ }
19
+
14
20
  & [layout^='wrap-'] + [layout^='wrap-'] {
15
21
  clear: none;
16
22
  & + p,
@@ -72,13 +78,13 @@ export const mediaStyles = css`
72
78
 
73
79
  .richMedia-resize-handle-right {
74
80
  align-items: flex-end;
75
- padding-right: 12px;
81
+ padding-right: ${"var(--ds-space-150, 12px)"};
76
82
  margin-right: -${akEditorMediaResizeHandlerPadding}px;
77
83
  }
78
84
 
79
85
  .richMedia-resize-handle-left {
80
86
  align-items: flex-start;
81
- padding-left: 12px;
87
+ padding-left: ${"var(--ds-space-150, 12px)"};
82
88
  margin-left: -${akEditorMediaResizeHandlerPadding}px;
83
89
  }
84
90
 
@@ -25,8 +25,8 @@ import ImageBorderItem from '../ui/ImageBorder';
25
25
  import { currentMediaNodeBorderMark } from '../utils/current-media-node';
26
26
  import { shouldShowImageBorder } from './imageBorder';
27
27
  import { PixelEntry } from '../ui/PixelEntry';
28
- import { DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, MEDIA_SINGLE_MIN_PIXEL_WIDTH } from '@atlaskit/editor-common/media-single';
29
- import { akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
28
+ import { DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_GUTTER_SIZE, calcMediaSinglePixelWidth } from '@atlaskit/editor-common/media-single';
29
+ import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth } from '@atlaskit/editor-shared-styles';
30
30
  const remove = (state, dispatch) => {
31
31
  if (dispatch) {
32
32
  dispatch(removeSelectedNode(state.tr));
@@ -266,6 +266,7 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
266
266
  type: 'custom',
267
267
  fallback: [],
268
268
  render: editorView => {
269
+ var _widthPlugin$sharedSt2, _widthPlugin$sharedSt3;
269
270
  if (!editorView) {
270
271
  return null;
271
272
  }
@@ -274,6 +275,8 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
274
275
  dispatch
275
276
  } = editorView;
276
277
  const selectedMediaSingleNode = getSelectedMediaSingle(state);
278
+ const contentWidth = (widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt2 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt2 === void 0 ? void 0 : _widthPlugin$sharedSt2.lineLength) || akEditorDefaultLayoutWidth;
279
+ const containerWidth = (widthPlugin === null || widthPlugin === void 0 ? void 0 : (_widthPlugin$sharedSt3 = widthPlugin.sharedState.currentState()) === null || _widthPlugin$sharedSt3 === void 0 ? void 0 : _widthPlugin$sharedSt3.width) || akEditorFullWidthLayoutWidth;
277
280
  if (!selectedMediaSingleNode) {
278
281
  return null;
279
282
  }
@@ -282,15 +285,26 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
282
285
  return null;
283
286
  }
284
287
  const {
285
- width: singleMediaWidth
288
+ width: singleMediaWidth,
289
+ widthType,
290
+ layout
286
291
  } = selectedMediaSingleNode.node.attrs;
287
292
  const {
288
293
  width: mediaWidth,
289
294
  height: mediaHeight
290
295
  } = selectedMediaNode.attrs;
296
+ const pixelWidth = calcMediaSinglePixelWidth({
297
+ width: singleMediaWidth,
298
+ widthType,
299
+ origWidth: mediaWidth || DEFAULT_IMAGE_WIDTH,
300
+ layout,
301
+ contentWidth,
302
+ containerWidth,
303
+ gutterOffset: MEDIA_SINGLE_GUTTER_SIZE
304
+ });
291
305
  return /*#__PURE__*/React.createElement(PixelEntry, {
292
306
  intl: intl,
293
- width: singleMediaWidth,
307
+ width: pluginState.isResizing ? pluginState.resizingWidth : pixelWidth,
294
308
  mediaWidth: mediaWidth || DEFAULT_IMAGE_WIDTH,
295
309
  mediaHeight: mediaHeight || DEFAULT_IMAGE_HEIGHT,
296
310
  validate: value => {
@@ -312,11 +326,9 @@ const generateMediaSingleFloatingToolbar = (state, intl, options, pluginState, m
312
326
  });
313
327
  }
314
328
  });
315
- if (!pluginState.isResizing) {
316
- toolbarButtons.push({
317
- type: 'separator'
318
- });
319
- }
329
+ toolbarButtons.push({
330
+ type: 'separator'
331
+ });
320
332
  }
321
333
  if (allowLinking && shouldShowMediaLinkToolbar(state)) {
322
334
  toolbarButtons.push({
@@ -423,7 +435,7 @@ export const floatingToolbar = (state, intl, options = {}, pluginInjectionApi) =
423
435
  const {
424
436
  hoverDecoration
425
437
  } = (_pluginInjectionApi$d9 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.decorations.actions) !== null && _pluginInjectionApi$d9 !== void 0 ? _pluginInjectionApi$d9 : {};
426
- if (!mediaPluginState || mediaPluginState.isResizing) {
438
+ if (!mediaPluginState) {
427
439
  return;
428
440
  }
429
441
  const nodeType = allowMediaInline ? [mediaInline, mediaSingle, media] : [mediaSingle];
@@ -12,9 +12,11 @@ import { ResizerNext } from '@atlaskit/editor-common/resizer';
12
12
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
13
13
  import classnames from 'classnames';
14
14
  import { richMediaClassName, resizerStyles } from '@atlaskit/editor-common/styles';
15
- import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH, calcMediaSingleMaxWidth } from '@atlaskit/editor-common/media-single';
15
+ import { MEDIA_SINGLE_MIN_PIXEL_WIDTH, MEDIA_SINGLE_SNAP_GAP, MEDIA_SINGLE_RESIZE_THROTTLE_TIME, calculateOffsetLeft, DEFAULT_IMAGE_WIDTH, calcMediaSingleMaxWidth } from '@atlaskit/editor-common/media-single';
16
16
  import { findClosestSnap, getGuidelinesWithHighlights, generateDefaultGuidelines, generateDynamicGuidelines, getGuidelineSnaps } from '@atlaskit/editor-common/guideline';
17
17
  import memoizeOne from 'memoize-one';
18
+ import throttle from 'lodash/throttle';
19
+ import { MEDIA_PLUGIN_IS_RESIZING_KEY, MEDIA_PLUGIN_RESIZING_WIDTH_KEY } from '../../pm-plugins/main';
18
20
  export const resizerNextTestId = 'mediaSingle.resizerNext.testid';
19
21
 
20
22
  // TODO: Create new fixed image size event
@@ -58,13 +60,14 @@ class ResizableMediaSingleNext extends React.Component {
58
60
  state
59
61
  },
60
62
  containerWidth,
61
- lineLength
63
+ lineLength,
64
+ fullWidthMode
62
65
  } = this.props;
63
66
  const newPct = calcPctFromPx(newWidth, this.props.lineLength) * 100;
64
67
  this.setState({
65
68
  resizedPctWidth: newPct
66
69
  });
67
- let newLayout = hasParentNodeOfType(state.schema.nodes.table)(state.selection) ? layout : this.calcUnwrappedLayout(newWidth, containerWidth, lineLength);
70
+ let newLayout = hasParentNodeOfType(state.schema.nodes.table)(state.selection) ? layout : this.calcUnwrappedLayout(newWidth, containerWidth, lineLength, fullWidthMode);
68
71
  if (newPct <= 100) {
69
72
  if (this.wrappedLayout && (stop ? newPct !== 100 : true)) {
70
73
  newLayout = layout;
@@ -80,7 +83,13 @@ class ResizableMediaSingleNext extends React.Component {
80
83
  };
81
84
  }
82
85
  });
83
- _defineProperty(this, "calcUnwrappedLayout", (width, containerWidth, contentWidth) => {
86
+ _defineProperty(this, "calcUnwrappedLayout", (width, containerWidth, contentWidth, fullWidthMode) => {
87
+ if (fullWidthMode) {
88
+ if (width < contentWidth) {
89
+ return 'center';
90
+ }
91
+ return 'full-width';
92
+ }
84
93
  if (width <= contentWidth) {
85
94
  return 'center';
86
95
  }
@@ -122,7 +131,16 @@ class ResizableMediaSingleNext extends React.Component {
122
131
  dispatch
123
132
  } = this.props.view;
124
133
  const tr = state.tr;
125
- tr.setMeta('mediaSinglePlugin.isResizing', isResizing);
134
+ tr.setMeta(MEDIA_PLUGIN_IS_RESIZING_KEY, isResizing);
135
+ return dispatch(tr);
136
+ });
137
+ _defineProperty(this, "updateSizeInPluginState", width => {
138
+ const {
139
+ state,
140
+ dispatch
141
+ } = this.props.view;
142
+ const tr = state.tr;
143
+ tr.setMeta(MEDIA_PLUGIN_RESIZING_WIDTH_KEY, width);
126
144
  return dispatch(tr);
127
145
  });
128
146
  _defineProperty(this, "calcMaxWidth", memoizeOne((contentWidth, containerWidth, fullWidthMode) => {
@@ -167,11 +185,12 @@ class ResizableMediaSingleNext extends React.Component {
167
185
  });
168
186
  this.selectCurrentMediaNode();
169
187
  this.setIsResizing(true);
188
+ this.updateSizeInPluginState(this.state.size.width);
170
189
  // re-calucate guidelines
171
190
  this.guidelines = this.getAllGuidelines();
172
191
  return 0;
173
192
  });
174
- _defineProperty(this, "handleResize", (size, delta) => {
193
+ _defineProperty(this, "handleResize", throttle((size, delta) => {
175
194
  const {
176
195
  width: originalWidth,
177
196
  height: originalHeight,
@@ -193,10 +212,11 @@ class ResizableMediaSingleNext extends React.Component {
193
212
  },
194
213
  snaps: guidelineSnaps.snaps
195
214
  });
215
+ this.updateSizeInPluginState(width);
196
216
  if (calculatedWidthWithLayout.layout !== layout) {
197
217
  updateSize(width, calculatedWidthWithLayout.layout);
198
218
  }
199
- });
219
+ }, MEDIA_SINGLE_RESIZE_THROTTLE_TIME));
200
220
  _defineProperty(this, "handleResizeStop", (size, delta) => {
201
221
  const {
202
222
  width: originalWidth,
@@ -279,6 +299,18 @@ class ResizableMediaSingleNext extends React.Component {
279
299
  }
280
300
  });
281
301
  }
302
+ if (this.props.layout === 'full-width' && !this.isNestedNode() && prevProps.containerWidth !== this.props.containerWidth) {
303
+ // To achieve edge-to-edge for full-width, we need to update its width according to containerWidth
304
+ // Update state to allow resizer to get most up-to-date width to avoid jumping when start resizing
305
+ this.setState(prevState => {
306
+ return {
307
+ size: {
308
+ width: calcMediaSingleMaxWidth(this.props.containerWidth),
309
+ height: prevState.size.height
310
+ }
311
+ };
312
+ });
313
+ }
282
314
  return true;
283
315
  }
284
316
 
@@ -1,7 +1,7 @@
1
1
  import { Fragment, Slice } from '@atlaskit/editor-prosemirror/model';
2
2
  import { safeInsert as pmSafeInsert, hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
3
3
  import { checkNodeDown } from '../../../utils';
4
- import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
4
+ import { isEmptyParagraph, floatingLayouts } from '@atlaskit/editor-common/utils';
5
5
  import { getMediaSingleInitialWidth } from '@atlaskit/editor-common/media-single';
6
6
  import { copyOptionalAttrsFromMediaState } from '../utils/media-common';
7
7
  import { mapSlice } from '../../../utils/slice';
@@ -218,4 +218,23 @@ export function isCaptionNode(editorView) {
218
218
  return true;
219
219
  }
220
220
  return false;
221
- }
221
+ }
222
+ export const getParentWidthForNestedMediaSingleNode = (resolvedPos, view) => {
223
+ const domNode = view.nodeDOM(resolvedPos.pos);
224
+ if (resolvedPos.nodeAfter && floatingLayouts.includes(resolvedPos.nodeAfter.attrs.layout) && domNode && domNode.parentElement) {
225
+ const {
226
+ tableCell,
227
+ tableHeader
228
+ } = view.state.schema.nodes;
229
+ if ([tableCell, tableHeader].includes(resolvedPos.parent.type)) {
230
+ // since table has constant padding, use hardcoded constant instead of query the dom
231
+ const tablePadding = 8;
232
+ return domNode.parentElement.offsetWidth - tablePadding * 2;
233
+ }
234
+ return domNode.parentElement.offsetWidth;
235
+ }
236
+ if (domNode instanceof HTMLElement) {
237
+ return domNode.offsetWidth;
238
+ }
239
+ return null;
240
+ };
@@ -1,6 +1,7 @@
1
1
  import { toggleMark } from '@atlaskit/editor-common/mark';
2
2
  import { ACTIONS, pluginKey } from '../pm-plugins/main';
3
3
  import { getDisabledState } from '../utils/disabled';
4
+ import { pluginCommandToPMCommand } from '@atlaskit/editor-common/preset';
4
5
  export const toggleColor = color => (state, dispatch) => {
5
6
  const {
6
7
  textColor
@@ -21,9 +22,9 @@ export const toggleColor = color => (state, dispatch) => {
21
22
  color
22
23
  });
23
24
  state.tr.scrollIntoView();
24
- toggleMark(textColor, {
25
+ pluginCommandToPMCommand(toggleMark(textColor, {
25
26
  color
26
- })(state, dispatch);
27
+ }))(state, dispatch);
27
28
  }
28
29
  return true;
29
30
  };
@@ -1,6 +1,7 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
2
  import { getBreakoutMode } from './node-width';
3
3
  import { processRawValue, hasDocAsParent, getStepRange, isEmptyParagraph } from '@atlaskit/editor-common/utils';
4
+ export { findFarthestParentNode } from '@atlaskit/editor-common/utils';
4
5
 
5
6
  /**
6
7
  * Checks if a node has any content. Ignores node that only contain empty block nodes.
@@ -46,26 +47,6 @@ export function processRawFragmentValue(schema, value, providerFactory, sanitize
46
47
  }
47
48
  return Fragment.from(adfEntities);
48
49
  }
49
-
50
- /**
51
- * Find the farthest node given a condition
52
- * @param predicate Function to check the node
53
- */
54
- export const findFarthestParentNode = predicate => $pos => {
55
- let candidate = null;
56
- for (let i = $pos.depth; i > 0; i--) {
57
- const node = $pos.node(i);
58
- if (predicate(node)) {
59
- candidate = {
60
- pos: i > 0 ? $pos.before(i) : 0,
61
- start: $pos.start(i),
62
- depth: i,
63
- node
64
- };
65
- }
66
- }
67
- return candidate;
68
- };
69
50
  export const isSelectionEndOfParagraph = state => state.selection.$to.parent.type === state.schema.nodes.paragraph && state.selection.$to.pos === state.doc.resolve(state.selection.$to.pos).end();
70
51
  export function getChangedNodesIn({
71
52
  tr,
@@ -2,7 +2,7 @@ import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
2
2
  import { JSONTransformer } from '@atlaskit/editor-json-transformer';
3
3
  import { FakeTextCursorSelection } from '../plugins/fake-text-cursor/cursor';
4
4
  import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
- import { isNodeEmpty } from './document';
5
+ export { isEmptyNode, isSelectionInsideLastNodeInDocument, checkNodeDown, insideTableCell, isInListItem } from '@atlaskit/editor-common/utils';
6
6
  export { insideTable } from '@atlaskit/editor-common/core-utils';
7
7
  export { isNodeEmpty, findFarthestParentNode, isSelectionEndOfParagraph, nodesBetweenChanged, getNodesCount } from './document';
8
8
  export { sanitiseMarksInSelection } from './mark';
@@ -15,11 +15,6 @@ function isMarkTypeCompatibleWithMark(markType, mark) {
15
15
  function isMarkTypeAllowedInNode(markType, state) {
16
16
  return toggleMark(markType)(state);
17
17
  }
18
- export function isSelectionInsideLastNodeInDocument(selection) {
19
- const docNode = selection.$anchor.node(0);
20
- const rootNode = selection.$anchor.node(1);
21
- return docNode.lastChild === rootNode;
22
- }
23
18
  export function getCursor(selection) {
24
19
  return selection.$cursor || undefined;
25
20
  }
@@ -67,36 +62,6 @@ export function isMarkTypeAllowedInCurrentSelection(markType, state) {
67
62
  return allowedInActiveMarks;
68
63
  });
69
64
  }
70
- export function checkNodeDown(selection, doc, filter) {
71
- const ancestorDepth = findAncestorPosition(doc, selection.$to).depth;
72
-
73
- // Top level node
74
- if (ancestorDepth === 0) {
75
- return false;
76
- }
77
- const res = doc.resolve(selection.$to.after(ancestorDepth));
78
- return res.nodeAfter ? filter(res.nodeAfter) : false;
79
- }
80
-
81
- /**
82
- * Traverse the document until an "ancestor" is found. Any nestable block can be an ancestor.
83
- */
84
- function findAncestorPosition(doc, pos) {
85
- const nestableBlocks = ['blockquote', 'bulletList', 'orderedList'];
86
- if (pos.depth === 1) {
87
- return pos;
88
- }
89
- let node = pos.node(pos.depth);
90
- let newPos = pos;
91
- while (pos.depth >= 1) {
92
- pos = doc.resolve(pos.before(pos.depth));
93
- node = pos.node(pos.depth);
94
- if (node && nestableBlocks.indexOf(node.type.name) !== -1) {
95
- newPos = pos;
96
- }
97
- }
98
- return newPos;
99
- }
100
65
  const transformer = new JSONTransformer();
101
66
  export function toJSON(node) {
102
67
  return transformer.encode(node);
@@ -142,69 +107,6 @@ export function whichTransitionEvent() {
142
107
  export const isTemporary = id => {
143
108
  return id.indexOf('temporary:') === 0;
144
109
  };
145
- export const isEmptyNode = schema => {
146
- const {
147
- doc,
148
- paragraph,
149
- codeBlock,
150
- blockquote,
151
- panel,
152
- heading,
153
- listItem,
154
- bulletList,
155
- orderedList,
156
- taskList,
157
- taskItem,
158
- decisionList,
159
- decisionItem,
160
- media,
161
- mediaGroup,
162
- mediaSingle
163
- } = schema.nodes;
164
- const innerIsEmptyNode = node => {
165
- switch (node.type) {
166
- case media:
167
- case mediaGroup:
168
- case mediaSingle:
169
- return false;
170
- case paragraph:
171
- case codeBlock:
172
- case heading:
173
- case taskItem:
174
- case decisionItem:
175
- return node.content.size === 0;
176
- case blockquote:
177
- case panel:
178
- case listItem:
179
- return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
180
- case bulletList:
181
- case orderedList:
182
- return node.content.size === 4 && innerIsEmptyNode(node.content.firstChild);
183
- case taskList:
184
- case decisionList:
185
- return node.content.size === 2 && innerIsEmptyNode(node.content.firstChild);
186
- case doc:
187
- let isEmpty = true;
188
- node.content.forEach(child => {
189
- isEmpty = isEmpty && innerIsEmptyNode(child);
190
- });
191
- return isEmpty;
192
- default:
193
- return isNodeEmpty(node);
194
- }
195
- };
196
- return innerIsEmptyNode;
197
- };
198
- export const insideTableCell = state => {
199
- const {
200
- tableCell,
201
- tableHeader
202
- } = state.schema.nodes;
203
- return hasParentNodeOfType([tableCell, tableHeader])(state.selection);
204
- };
205
- export const isInListItem = state => {
206
- return hasParentNodeOfType(state.schema.nodes.listItem)(state.selection);
207
- };
208
110
  export const hasOpenEnd = slice => {
209
111
  return slice.openStart > 0 || slice.openEnd > 0;
210
112
  };
@@ -1,51 +1 @@
1
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { GapCursorSelection } from '../../plugins/selection/gap-cursor/selection';
3
- export function atTheEndOfDoc(state) {
4
- const {
5
- selection,
6
- doc
7
- } = state;
8
- return doc.nodeSize - selection.$to.pos - 2 === selection.$to.depth;
9
- }
10
- export function atTheBeginningOfDoc(state) {
11
- const {
12
- selection
13
- } = state;
14
- return selection.$from.pos === selection.$from.depth;
15
- }
16
- export function atTheEndOfBlock(state) {
17
- const {
18
- selection
19
- } = state;
20
- const {
21
- $to
22
- } = selection;
23
- if (selection instanceof GapCursorSelection) {
24
- return false;
25
- }
26
- if (selection instanceof NodeSelection && selection.node.isBlock) {
27
- return true;
28
- }
29
- return endPositionOfParent($to) === $to.pos + 1;
30
- }
31
- export function atTheBeginningOfBlock(state) {
32
- const {
33
- selection
34
- } = state;
35
- const {
36
- $from
37
- } = selection;
38
- if (selection instanceof GapCursorSelection) {
39
- return false;
40
- }
41
- if (selection instanceof NodeSelection && selection.node.isBlock) {
42
- return true;
43
- }
44
- return startPositionOfParent($from) === $from.pos;
45
- }
46
- export function startPositionOfParent(resolvedPos) {
47
- return resolvedPos.start(resolvedPos.depth);
48
- }
49
- export function endPositionOfParent(resolvedPos) {
50
- return resolvedPos.end(resolvedPos.depth) + 1;
51
- }
1
+ export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, endPositionOfParent, startPositionOfParent } from '@atlaskit/editor-common/selection';
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "187.19.1";
2
+ export const version = "187.20.1";
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.19.1",
3
+ "version": "187.20.1",
4
4
  "sideEffects": false
5
5
  }
@@ -7,32 +7,33 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
7
7
  import { EVENT_TYPE, ACTION_SUBJECT_ID, ACTION_SUBJECT, ACTION } from '@atlaskit/editor-common/analytics';
8
8
  export var insertEmoji = function insertEmoji(editorAnalyticsAPI) {
9
9
  return function (emojiId, inputMethod) {
10
- return function (state, dispatch) {
11
- var emoji = state.schema.nodes.emoji;
10
+ return function (_ref) {
11
+ var tr = _ref.tr;
12
+ var doc = tr.doc,
13
+ selection = tr.selection;
14
+ var emoji = tr.doc.type.schema.nodes.emoji;
12
15
  if (emoji && emojiId) {
13
16
  var node = emoji.createChecked(_objectSpread(_objectSpread({}, emojiId), {}, {
14
17
  text: emojiId.fallback || emojiId.shortName
15
18
  }));
16
- var textNode = state.schema.text(' ');
17
- if (dispatch) {
18
- var fragment = Fragment.fromArray([node, textNode]);
19
- var tr = safeInsert(fragment)(state.tr);
20
- if (inputMethod) {
21
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
22
- action: ACTION.INSERTED,
23
- actionSubject: ACTION_SUBJECT.DOCUMENT,
24
- actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
25
- attributes: {
26
- inputMethod: inputMethod
27
- },
28
- eventType: EVENT_TYPE.TRACK
29
- })(tr);
30
- }
31
- dispatch(tr.setSelection(Selection.near(tr.doc.resolve(state.selection.$from.pos + fragment.size))));
19
+ var textNode = doc.type.schema.text(' ');
20
+ var fragment = Fragment.fromArray([node, textNode]);
21
+ var newTr = safeInsert(fragment)(tr);
22
+ if (inputMethod) {
23
+ editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent({
24
+ action: ACTION.INSERTED,
25
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
26
+ actionSubjectId: ACTION_SUBJECT_ID.EMOJI,
27
+ attributes: {
28
+ inputMethod: inputMethod
29
+ },
30
+ eventType: EVENT_TYPE.TRACK
31
+ })(newTr);
32
32
  }
33
- return true;
33
+ newTr.setSelection(Selection.near(newTr.doc.resolve(selection.$from.pos + fragment.size)));
34
+ return newTr;
34
35
  }
35
- return false;
36
+ return null;
36
37
  };
37
38
  };
38
39
  };
@@ -15,6 +15,7 @@ import { IconEmoji } from '@atlaskit/editor-common/quick-insert';
15
15
  import { EmojiNodeView } from './nodeviews/emoji';
16
16
  import { messages } from '../insert-block/ui/ToolbarInsertBlock/messages';
17
17
  import { openTypeAheadAtCursor } from '../type-ahead/transforms/open-typeahead-at-cursor';
18
+ import { insertEmoji } from './commands/insert-emoji';
18
19
  export var emojiToTypeaheadItem = function emojiToTypeaheadItem(emoji, emojiProvider) {
19
20
  return {
20
21
  title: emoji.shortName || '',
@@ -60,7 +61,8 @@ var isFullShortName = function isFullShortName(query) {
60
61
  return query && query.length > 1 && query.charAt(0) === ':' && query.charAt(query.length - 1) === ':';
61
62
  };
62
63
  var TRIGGER = ':';
63
- var emojiPlugin = function emojiPlugin(options, api) {
64
+ export var emojiPlugin = function emojiPlugin(options, api) {
65
+ var _api$dependencies$ana9;
64
66
  var typeAhead = {
65
67
  id: TypeAheadAvailableNodes.EMOJI,
66
68
  trigger: TRIGGER,
@@ -182,6 +184,15 @@ var emojiPlugin = function emojiPlugin(options, api) {
182
184
  }
183
185
  }];
184
186
  },
187
+ getSharedState: function getSharedState(editorState) {
188
+ if (!editorState) {
189
+ return undefined;
190
+ }
191
+ return emojiPluginKey.getState(editorState);
192
+ },
193
+ commands: {
194
+ insertEmoji: insertEmoji(api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions)
195
+ },
185
196
  pluginsOptions: {
186
197
  quickInsert: function quickInsert(_ref7) {
187
198
  var formatMessage = _ref7.formatMessage;
@@ -195,13 +206,13 @@ var emojiPlugin = function emojiPlugin(options, api) {
195
206
  return /*#__PURE__*/React.createElement(IconEmoji, null);
196
207
  },
197
208
  action: function action(insert, state) {
198
- var _api$dependencies$ana9;
209
+ var _api$dependencies$ana10;
199
210
  var tr = insert(undefined);
200
211
  openTypeAheadAtCursor({
201
212
  triggerHandler: typeAhead,
202
213
  inputMethod: INPUT_METHOD.QUICK_INSERT
203
214
  })(tr);
204
- api === null || api === void 0 ? void 0 : (_api$dependencies$ana9 = api.dependencies.analytics) === null || _api$dependencies$ana9 === void 0 ? void 0 : _api$dependencies$ana9.actions.attachAnalyticsEvent({
215
+ api === null || api === void 0 ? void 0 : (_api$dependencies$ana10 = api.dependencies.analytics) === null || _api$dependencies$ana10 === void 0 ? void 0 : _api$dependencies$ana10.actions.attachAnalyticsEvent({
205
216
  action: ACTION.INVOKED,
206
217
  actionSubject: ACTION_SUBJECT.TYPEAHEAD,
207
218
  actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_EMOJI,
@@ -218,7 +229,6 @@ var emojiPlugin = function emojiPlugin(options, api) {
218
229
  }
219
230
  };
220
231
  };
221
- export default emojiPlugin;
222
232
 
223
233
  /**
224
234
  * Actions
@@ -6,7 +6,7 @@ export { default as clearMarksOnChangeToEmptyDocumentPlugin } from './clear-mark
6
6
  export { default as codeBlockPlugin } from './code-block';
7
7
  export { default as collabEditPlugin } from './collab-edit';
8
8
  export { default as datePlugin } from './date';
9
- export { default as emojiPlugin } from './emoji';
9
+ export { emojiPlugin } from './emoji';
10
10
  export { default as extensionPlugin } from './extension';
11
11
  export { default as fakeTextCursorPlugin } from './fake-text-cursor';
12
12
  export { default as helpDialogPlugin } from './help-dialog';