@atlaskit/editor-core 187.6.0 → 187.6.10

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 (49) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/plugins/expand/commands.js +2 -1
  3. package/dist/cjs/plugins/expand/index.js +1 -1
  4. package/dist/cjs/plugins/insert-block/index.js +7 -10
  5. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
  6. package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +40 -32
  7. package/dist/cjs/plugins/mentions/index.js +11 -0
  8. package/dist/cjs/plugins/mentions/pm-plugins/main.js +24 -9
  9. package/dist/cjs/plugins/mentions/pm-plugins/utils.js +15 -1
  10. package/dist/cjs/ui/Appearance/FullPage/MainToolbar.js +1 -1
  11. package/dist/cjs/version-wrapper.js +1 -1
  12. package/dist/cjs/version.json +1 -1
  13. package/dist/es2019/plugins/expand/commands.js +2 -1
  14. package/dist/es2019/plugins/expand/index.js +1 -1
  15. package/dist/es2019/plugins/insert-block/index.js +4 -7
  16. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
  17. package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +11 -4
  18. package/dist/es2019/plugins/mentions/index.js +11 -0
  19. package/dist/es2019/plugins/mentions/pm-plugins/main.js +25 -9
  20. package/dist/es2019/plugins/mentions/pm-plugins/utils.js +11 -1
  21. package/dist/es2019/ui/Appearance/FullPage/MainToolbar.js +2 -2
  22. package/dist/es2019/version-wrapper.js +1 -1
  23. package/dist/es2019/version.json +1 -1
  24. package/dist/esm/plugins/expand/commands.js +2 -1
  25. package/dist/esm/plugins/expand/index.js +1 -1
  26. package/dist/esm/plugins/insert-block/index.js +5 -8
  27. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
  28. package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +40 -32
  29. package/dist/esm/plugins/mentions/index.js +11 -0
  30. package/dist/esm/plugins/mentions/pm-plugins/main.js +24 -9
  31. package/dist/esm/plugins/mentions/pm-plugins/utils.js +13 -1
  32. package/dist/esm/ui/Appearance/FullPage/MainToolbar.js +2 -2
  33. package/dist/esm/version-wrapper.js +1 -1
  34. package/dist/esm/version.json +1 -1
  35. package/dist/types/plugins/insert-block/index.d.ts +5 -3
  36. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +7 -6
  37. package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +10 -9
  38. package/dist/types/plugins/mentions/index.d.ts +3 -2
  39. package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +3 -2
  40. package/dist/types/plugins/mentions/types.d.ts +1 -0
  41. package/dist/types-ts4.5/plugins/insert-block/index.d.ts +5 -3
  42. package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +7 -6
  43. package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +10 -9
  44. package/dist/types-ts4.5/plugins/mentions/index.d.ts +3 -2
  45. package/dist/types-ts4.5/plugins/mentions/pm-plugins/utils.d.ts +3 -2
  46. package/dist/types-ts4.5/plugins/mentions/types.d.ts +1 -0
  47. package/package.json +6 -6
  48. package/report.api.md +1 -0
  49. package/tmp/api-report-tmp.d.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 187.6.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fa2209eee80`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fa2209eee80) - [ux] Fixes z-index full page editor main toolbar
8
+ - [`9b64591559a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9b64591559a) - [ux] ED-19163 Expand should only wrap selected text if added inline
9
+
10
+ ## 187.6.1
11
+
12
+ ### Patch Changes
13
+
14
+ - [`65f1e2bf9fc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/65f1e2bf9fc) - [ux] ED-18212 Disable toolbar mention when cursor is inside a codeblock
15
+
3
16
  ## 187.6.0
4
17
 
5
18
  ### Minor Changes
@@ -13,6 +13,7 @@ var _gapCursorSelection = require("../selection/gap-cursor-selection");
13
13
  var _utils2 = require("./utils");
14
14
  var _pluginFactory = require("./pm-plugins/plugin-factory");
15
15
  var _blockType = require("../block-type/commands/block-type");
16
+ var _prosemirrorUtils = require("prosemirror-utils");
16
17
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
19
  var setExpandRef = function setExpandRef(ref) {
@@ -123,7 +124,7 @@ var insertExpand = function insertExpand(state, dispatch) {
123
124
  if (!expandNode) {
124
125
  return false;
125
126
  }
126
- var tr = (0, _blockType.createWrapSelectionTransaction)({
127
+ var tr = state.selection.empty ? (0, _prosemirrorUtils.safeInsert)(expandNode)(state.tr).scrollIntoView() : (0, _blockType.createWrapSelectionTransaction)({
127
128
  state: state,
128
129
  type: expandNode.type
129
130
  });
@@ -74,7 +74,7 @@ var expandPlugin = function expandPlugin() {
74
74
  if (!node) {
75
75
  return false;
76
76
  }
77
- var tr = (0, _blockType.createWrapSelectionTransaction)({
77
+ var tr = state.selection.empty ? insert(node) : (0, _blockType.createWrapSelectionTransaction)({
78
78
  state: state,
79
79
  type: node.type
80
80
  });
@@ -10,13 +10,12 @@ var _providerFactory = require("@atlaskit/editor-common/provider-factory");
10
10
  var _main = require("../block-type/pm-plugins/main");
11
11
  var _pluginKey = require("../media/pm-plugins/plugin-key");
12
12
  var _utils = require("../type-ahead/utils");
13
- var _key = require("../mentions/pm-plugins/key");
14
13
  var _layout = require("../layout");
15
14
  var _macro = require("../macro");
16
15
  var _emoji = require("../emoji");
17
16
  var _WithPluginState = _interopRequireDefault(require("../../ui/WithPluginState"));
18
17
  var _ToolbarInsertBlock = _interopRequireDefault(require("./ui/ToolbarInsertBlock"));
19
- var _key2 = require("../type-ahead/pm-plugins/key");
18
+ var _key = require("../type-ahead/pm-plugins/key");
20
19
  var _commands = require("../block-type/commands");
21
20
  var _analytics = require("../analytics");
22
21
  var _pluginKey2 = require("../placeholder-text/plugin-key");
@@ -69,18 +68,16 @@ var insertBlockPlugin = function insertBlockPlugin() {
69
68
  // `ToolbarInsertBlockWithInjectionApi` and remove `WithPluginState`
70
69
  return /*#__PURE__*/_react.default.createElement(_WithPluginState.default, {
71
70
  plugins: {
72
- typeAheadState: _key2.pluginKey,
71
+ typeAheadState: _key.pluginKey,
73
72
  blockTypeState: _main.pluginKey,
74
73
  mediaState: _pluginKey.stateKey,
75
- mentionState: _key.mentionPluginKey,
76
74
  macroState: _pluginKey3.pluginKey,
77
75
  emojiState: _emoji.emojiPluginKey,
78
76
  placeholderTextState: _pluginKey2.pluginKey,
79
77
  layoutState: _layout.pluginKey
80
78
  },
81
79
  render: function render(_ref2) {
82
- var mentionState = _ref2.mentionState,
83
- blockTypeState = _ref2.blockTypeState,
80
+ var blockTypeState = _ref2.blockTypeState,
84
81
  mediaState = _ref2.mediaState,
85
82
  _ref2$macroState = _ref2.macroState,
86
83
  macroState = _ref2$macroState === void 0 ? {} : _ref2$macroState,
@@ -101,7 +98,6 @@ var insertBlockPlugin = function insertBlockPlugin() {
101
98
  isToolbarReducedSpacing: isToolbarReducedSpacing,
102
99
  isLastItem: isLastItem,
103
100
  featureFlags: featureFlags,
104
- mentionState: mentionState,
105
101
  blockTypeState: blockTypeState,
106
102
  mediaState: mediaState,
107
103
  macroState: macroState,
@@ -138,7 +134,6 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
138
134
  providers = _ref3.providers,
139
135
  pluginInjectionApi = _ref3.pluginInjectionApi,
140
136
  options = _ref3.options,
141
- mentionState = _ref3.mentionState,
142
137
  blockTypeState = _ref3.blockTypeState,
143
138
  mediaState = _ref3.mediaState,
144
139
  macroState = _ref3.macroState,
@@ -147,10 +142,11 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
147
142
  layoutState = _ref3.layoutState,
148
143
  featureFlags = _ref3.featureFlags;
149
144
  var buttons = toolbarSizeToButtons(toolbarSize);
150
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload']),
145
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention']),
151
146
  dateState = _useSharedPluginState.dateState,
152
147
  hyperlinkState = _useSharedPluginState.hyperlinkState,
153
- imageUploadState = _useSharedPluginState.imageUploadState;
148
+ imageUploadState = _useSharedPluginState.imageUploadState,
149
+ mentionState = _useSharedPluginState.mentionState;
154
150
  return /*#__PURE__*/_react.default.createElement(_ToolbarInsertBlock.default, {
155
151
  pluginInjectionApi: pluginInjectionApi,
156
152
  buttons: buttons,
@@ -161,6 +157,7 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
161
157
  tableSupported: !!editorView.state.schema.nodes.table,
162
158
  actionSupported: !!editorView.state.schema.nodes.taskItem,
163
159
  mentionsSupported: !!(mentionState && mentionState.mentionProvider),
160
+ mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
164
161
  decisionSupported: !!editorView.state.schema.nodes.decisionItem,
165
162
  dateEnabled: !!dateState,
166
163
  placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
@@ -44,6 +44,7 @@ var createInsertBlockItems = function createInsertBlockItems(config) {
44
44
  imageUploadSupported = config.imageUploadSupported,
45
45
  imageUploadEnabled = config.imageUploadEnabled,
46
46
  mentionsSupported = config.mentionsSupported,
47
+ mentionsDisabled = config.mentionsDisabled,
47
48
  availableWrapperBlockTypes = config.availableWrapperBlockTypes,
48
49
  actionSupported = config.actionSupported,
49
50
  decisionSupported = config.decisionSupported,
@@ -96,7 +97,7 @@ var createInsertBlockItems = function createInsertBlockItems(config) {
96
97
  items.push((0, _item.mention)({
97
98
  content: formatMessage(_messages.messages.mention),
98
99
  tooltipDescription: formatMessage(_messages.messages.mentionDescription),
99
- disabled: !isTypeAheadAllowed,
100
+ disabled: !isTypeAheadAllowed || !!mentionsDisabled,
100
101
  'aria-haspopup': 'listbox'
101
102
  }));
102
103
  }
@@ -181,21 +181,28 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
181
181
  return true;
182
182
  });
183
183
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertMention", function (inputMethod) {
184
- var editorView = _this.props.editorView;
184
+ var _pluginInjectionApi$d3;
185
+ var _this$props2 = _this.props,
186
+ editorView = _this$props2.editorView,
187
+ pluginInjectionApi = _this$props2.pluginInjectionApi;
185
188
  if (!editorView) {
186
189
  return true;
187
190
  }
191
+ var pluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.mention) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : _pluginInjectionApi$d3.sharedState.currentState();
192
+ if (pluginState && pluginState.canInsertMention === false) {
193
+ return false;
194
+ }
188
195
  (0, _api.createTypeAheadTools)(editorView).openMention(inputMethod);
189
196
  return true;
190
197
  });
191
198
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertTable", function (inputMethod) {
192
- var _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _pluginInjectionApi$d6;
193
- var _this$props2 = _this.props,
194
- pluginInjectionApi = _this$props2.pluginInjectionApi,
195
- editorView = _this$props2.editorView;
199
+ var _pluginInjectionApi$d4, _pluginInjectionApi$d5, _pluginInjectionApi$d6, _pluginInjectionApi$d7;
200
+ var _this$props3 = _this.props,
201
+ pluginInjectionApi = _this$props3.pluginInjectionApi,
202
+ editorView = _this$props3.editorView;
196
203
  var state = editorView.state,
197
204
  dispatch = editorView.dispatch;
198
- return (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.table) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : (_pluginInjectionApi$d5 = (_pluginInjectionApi$d6 = _pluginInjectionApi$d4.actions).insertTable) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.call(_pluginInjectionApi$d6, {
205
+ return (_pluginInjectionApi$d4 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d5 = pluginInjectionApi.dependencies.table) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : (_pluginInjectionApi$d6 = (_pluginInjectionApi$d7 = _pluginInjectionApi$d5.actions).insertTable) === null || _pluginInjectionApi$d6 === void 0 ? void 0 : _pluginInjectionApi$d6.call(_pluginInjectionApi$d7, {
199
206
  action: _analytics.ACTION.INSERTED,
200
207
  actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
201
208
  actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
@@ -203,7 +210,7 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
203
210
  inputMethod: inputMethod
204
211
  },
205
212
  eventType: _analytics.EVENT_TYPE.TRACK
206
- })(state, dispatch)) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : false;
213
+ })(state, dispatch)) !== null && _pluginInjectionApi$d4 !== void 0 ? _pluginInjectionApi$d4 : false;
207
214
  });
208
215
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "createDate", function (inputMethod) {
209
216
  var editorView = _this.props.editorView;
@@ -226,9 +233,9 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
226
233
  return true;
227
234
  });
228
235
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "openMediaPicker", function (inputMethod) {
229
- var _this$props3 = _this.props,
230
- onShowMediaPicker = _this$props3.onShowMediaPicker,
231
- dispatchAnalyticsEvent = _this$props3.dispatchAnalyticsEvent;
236
+ var _this$props4 = _this.props,
237
+ onShowMediaPicker = _this$props4.onShowMediaPicker,
238
+ dispatchAnalyticsEvent = _this$props4.dispatchAnalyticsEvent;
232
239
  if (onShowMediaPicker) {
233
240
  onShowMediaPicker();
234
241
  if (dispatchAnalyticsEvent) {
@@ -255,11 +262,11 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
255
262
  };
256
263
  });
257
264
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertHorizontalRule", function (inputMethod) {
258
- var _this$props4 = _this.props,
259
- _this$props4$editorVi = _this$props4.editorView,
260
- state = _this$props4$editorVi.state,
261
- dispatch = _this$props4$editorVi.dispatch,
262
- featureFlags = _this$props4.featureFlags;
265
+ var _this$props5 = _this.props,
266
+ _this$props5$editorVi = _this$props5.editorView,
267
+ state = _this$props5$editorVi.state,
268
+ dispatch = _this$props5$editorVi.dispatch,
269
+ featureFlags = _this$props5.featureFlags;
263
270
  return (0, _commands4.insertHorizontalRule)(inputMethod, featureFlags)(state, dispatch);
264
271
  });
265
272
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertExpand", function () {
@@ -270,9 +277,9 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
270
277
  });
271
278
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "insertBlockType", function (itemName) {
272
279
  return function () {
273
- var _this$props5 = _this.props,
274
- editorView = _this$props5.editorView,
275
- onInsertBlockType = _this$props5.onInsertBlockType;
280
+ var _this$props6 = _this.props,
281
+ editorView = _this$props6.editorView,
282
+ onInsertBlockType = _this$props6.onInsertBlockType;
276
283
  var state = editorView.state,
277
284
  dispatch = editorView.dispatch;
278
285
  onInsertBlockType(itemName)(state, dispatch);
@@ -291,11 +298,11 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
291
298
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onItemActivated", function (_ref2) {
292
299
  var item = _ref2.item,
293
300
  inputMethod = _ref2.inputMethod;
294
- var _this$props6 = _this.props,
295
- editorView = _this$props6.editorView,
296
- editorActions = _this$props6.editorActions,
297
- handleImageUpload = _this$props6.handleImageUpload,
298
- expandEnabled = _this$props6.expandEnabled;
301
+ var _this$props7 = _this.props,
302
+ editorView = _this$props7.editorView,
303
+ editorActions = _this$props7.editorActions,
304
+ handleImageUpload = _this$props7.handleImageUpload,
305
+ expandEnabled = _this$props7.expandEnabled;
299
306
 
300
307
  // need to do this before inserting nodes so scrollIntoView works properly
301
308
  if (!editorView.hasFocus()) {
@@ -411,12 +418,12 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
411
418
  key: "renderPopup",
412
419
  value: function renderPopup() {
413
420
  var emojiPickerOpen = this.state.emojiPickerOpen;
414
- var _this$props7 = this.props,
415
- popupsMountPoint = _this$props7.popupsMountPoint,
416
- popupsBoundariesElement = _this$props7.popupsBoundariesElement,
417
- popupsScrollableElement = _this$props7.popupsScrollableElement,
418
- emojiProvider = _this$props7.emojiProvider,
419
- replacePlusMenuWithElementBrowser = _this$props7.replacePlusMenuWithElementBrowser;
421
+ var _this$props8 = this.props,
422
+ popupsMountPoint = _this$props8.popupsMountPoint,
423
+ popupsBoundariesElement = _this$props8.popupsBoundariesElement,
424
+ popupsScrollableElement = _this$props8.popupsScrollableElement,
425
+ emojiProvider = _this$props8.emojiProvider,
426
+ replacePlusMenuWithElementBrowser = _this$props8.replacePlusMenuWithElementBrowser;
420
427
  var dropdownEmoji = this.state.dropdownItems.some(function (_ref4) {
421
428
  var name = _ref4.value.name;
422
429
  return name === 'emoji';
@@ -452,9 +459,9 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
452
459
  buttons = _this$state.buttons,
453
460
  dropdownItems = _this$state.dropdownItems,
454
461
  emojiPickerOpen = _this$state.emojiPickerOpen;
455
- var _this$props8 = this.props,
456
- isDisabled = _this$props8.isDisabled,
457
- isReducedSpacing = _this$props8.isReducedSpacing;
462
+ var _this$props9 = this.props,
463
+ isDisabled = _this$props9.isDisabled,
464
+ isReducedSpacing = _this$props9.isReducedSpacing;
458
465
  if (buttons.length === 0 && dropdownItems.length === 0) {
459
466
  return null;
460
467
  }
@@ -514,6 +521,7 @@ var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
514
521
  imageUploadSupported: props.imageUploadSupported,
515
522
  imageUploadEnabled: props.imageUploadEnabled,
516
523
  mentionsSupported: props.mentionsSupported,
524
+ mentionsDisabled: props.mentionsDisabled,
517
525
  actionSupported: props.actionSupported,
518
526
  decisionSupported: props.decisionSupported,
519
527
  linkSupported: props.linkSupported,
@@ -25,6 +25,12 @@ var _openTypeaheadAtCursor = require("../type-ahead/transforms/open-typeahead-at
25
25
  var _typeAhead = require("./type-ahead");
26
26
  var _key = require("./pm-plugins/key");
27
27
  var _main = require("./pm-plugins/main");
28
+ var getSharedState = function getSharedState(editorState) {
29
+ if (!editorState) {
30
+ return undefined;
31
+ }
32
+ return _key.mentionPluginKey.getState(editorState);
33
+ };
28
34
  var mentionsPlugin = function mentionsPlugin(options, api) {
29
35
  var sessionId = (0, _uuid.default)();
30
36
  var fireEvent = function fireEvent(payload) {
@@ -79,6 +85,7 @@ var mentionsPlugin = function mentionsPlugin(options, api) {
79
85
  }
80
86
  });
81
87
  },
88
+ getSharedState: getSharedState,
82
89
  pluginsOptions: {
83
90
  quickInsert: function quickInsert(_ref4) {
84
91
  var formatMessage = _ref4.formatMessage;
@@ -95,6 +102,10 @@ var mentionsPlugin = function mentionsPlugin(options, api) {
95
102
  action: function action(insert, state) {
96
103
  var _api$dependencies$ana3;
97
104
  var tr = insert(undefined);
105
+ var pluginState = getSharedState(state);
106
+ if (pluginState && pluginState.canInsertMention === false) {
107
+ return false;
108
+ }
98
109
  (0, _openTypeaheadAtCursor.openTypeAheadAtCursor)({
99
110
  triggerHandler: typeAhead,
100
111
  inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
@@ -12,6 +12,7 @@ var _resource = require("@atlaskit/mention/resource");
12
12
  var _reactNodeView = require("@atlaskit/editor-common/react-node-view");
13
13
  var _mention = require("../nodeviews/mention");
14
14
  var _key = require("./key");
15
+ var _utils = require("./utils");
15
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
17
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
18
  var ACTIONS = {
@@ -55,30 +56,44 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
55
56
  return new _safePlugin.SafePlugin({
56
57
  key: _key.mentionPluginKey,
57
58
  state: {
58
- init: function init() {
59
- return {};
59
+ init: function init(_, state) {
60
+ var canInsertMention = (0, _utils.canMentionBeCreatedInRange)(state.selection.from, state.selection.to)(state);
61
+ return {
62
+ canInsertMention: canInsertMention
63
+ };
60
64
  },
61
- apply: function apply(tr, pluginState) {
65
+ apply: function apply(tr, pluginState, oldState, newState) {
62
66
  var _ref = tr.getMeta(_key.mentionPluginKey) || {
63
67
  action: null,
64
68
  params: null
65
69
  },
66
70
  action = _ref.action,
67
71
  params = _ref.params;
72
+ var hasNewPluginState = false;
68
73
  var newPluginState = pluginState;
74
+ var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
75
+ if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
76
+ newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
77
+ canInsertMention: (0, _utils.canMentionBeCreatedInRange)(newState.selection.from, newState.selection.to)(newState)
78
+ });
79
+ hasNewPluginState = true;
80
+ }
69
81
  switch (action) {
70
82
  case ACTIONS.SET_PROVIDER:
71
- newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
83
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
72
84
  mentionProvider: params.provider
73
85
  });
74
- pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
75
- return newPluginState;
86
+ hasNewPluginState = true;
87
+ break;
76
88
  case ACTIONS.SET_CONTEXT:
77
- newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
89
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
78
90
  contextIdentifierProvider: params.context
79
91
  });
80
- pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
81
- return newPluginState;
92
+ hasNewPluginState = true;
93
+ break;
94
+ }
95
+ if (hasNewPluginState) {
96
+ pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
82
97
  }
83
98
  return newPluginState;
84
99
  }
@@ -3,8 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.canMentionBeCreatedInRange = void 0;
6
7
  exports.getMentionPluginState = getMentionPluginState;
7
8
  var _key = require("./key");
9
+ var _prosemirrorUtils = require("prosemirror-utils");
8
10
  function getMentionPluginState(state) {
9
11
  return _key.mentionPluginKey.getState(state);
10
- }
12
+ }
13
+ var canMentionBeCreatedInRange = function canMentionBeCreatedInRange(from, to) {
14
+ return function (state) {
15
+ var $from = state.doc.resolve(from);
16
+ var $to = state.doc.resolve(to);
17
+ var mention = state.schema.nodes.mention.createChecked();
18
+ if ($from.parent === $to.parent && (0, _prosemirrorUtils.canInsert)($from, mention)) {
19
+ return true;
20
+ }
21
+ return false;
22
+ };
23
+ };
24
+ exports.canMentionBeCreatedInRange = canMentionBeCreatedInRange;
@@ -17,7 +17,7 @@ var toolbarLineHeight = 56;
17
17
  // box-shadow is overriden by the mainToolbar
18
18
  var mainToolbarWithKeyline = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n box-shadow: 0 ", "px 0 0\n ", ";\n"])), _editorSharedStyles.akEditorToolbarKeylineHeight, "var(--ds-border, ".concat(_colors.N30, ")"));
19
19
  var mainToolbarTwoLineStyle = (0, _react.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n @media (max-width: ", "px) {\n flex-wrap: wrap;\n height: calc(", "px * 2);\n }\n"])), MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT, toolbarLineHeight);
20
- var mainToolbar = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n align-items: center;\n box-shadow: none;\n transition: box-shadow 200ms ", ";\n z-index: ", ";\n display: flex;\n height: ", "px;\n flex-shrink: 0;\n // TODO: https://product-fabric.atlassian.net/browse/DSP-4456\n background-color: ", ";\n\n & object {\n height: 0 !important;\n }\n\n @media (max-width: ", "px) {\n display: grid;\n height: calc(", "px * 2);\n }\n"])), _editorSharedStyles.akEditorSwoopCubicBezier, _editorSharedStyles.akEditorMenuZIndex, toolbarLineHeight, "var(--ds-surface, white)", _editorSharedStyles.akEditorMobileMaxWidth, toolbarLineHeight);
20
+ var mainToolbar = (0, _react.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n position: relative;\n align-items: center;\n box-shadow: none;\n transition: box-shadow 200ms ", ";\n z-index: ", ";\n display: flex;\n height: ", "px;\n flex-shrink: 0;\n // TODO: https://product-fabric.atlassian.net/browse/DSP-4456\n background-color: ", ";\n\n & object {\n height: 0 !important;\n }\n\n @media (max-width: ", "px) {\n display: grid;\n height: calc(", "px * 2);\n }\n"])), _editorSharedStyles.akEditorSwoopCubicBezier, _editorSharedStyles.akEditorFloatingDialogZIndex, toolbarLineHeight, "var(--ds-surface, white)", _editorSharedStyles.akEditorMobileMaxWidth, toolbarLineHeight);
21
21
  var mainToolbarStyle = function mainToolbarStyle(showKeyline, twoLineEditorToolbar) {
22
22
  return [mainToolbar, showKeyline && mainToolbarWithKeyline, twoLineEditorToolbar && mainToolbarTwoLineStyle];
23
23
  };
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = "@atlaskit/editor-core";
8
8
  exports.name = name;
9
- var version = "187.6.0";
9
+ var version = "187.6.10";
10
10
  exports.version = version;
11
11
  var nextMajorVersion = function nextMajorVersion() {
12
12
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "187.6.0",
3
+ "version": "187.6.10",
4
4
  "sideEffects": false
5
5
  }
@@ -5,6 +5,7 @@ import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
5
5
  import { findExpand } from './utils';
6
6
  import { createCommand } from './pm-plugins/plugin-factory';
7
7
  import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
8
+ import { safeInsert } from 'prosemirror-utils';
8
9
  export const setExpandRef = ref => createCommand({
9
10
  type: 'SET_EXPAND_REF',
10
11
  data: {
@@ -102,7 +103,7 @@ export const insertExpand = (state, dispatch) => {
102
103
  if (!expandNode) {
103
104
  return false;
104
105
  }
105
- const tr = createWrapSelectionTransaction({
106
+ const tr = state.selection.empty ? safeInsert(expandNode)(state.tr).scrollIntoView() : createWrapSelectionTransaction({
106
107
  state,
107
108
  type: expandNode.type
108
109
  });
@@ -56,7 +56,7 @@ const expandPlugin = (options = {}, api) => {
56
56
  if (!node) {
57
57
  return false;
58
58
  }
59
- const tr = createWrapSelectionTransaction({
59
+ const tr = state.selection.empty ? insert(node) : createWrapSelectionTransaction({
60
60
  state,
61
61
  type: node.type
62
62
  });
@@ -3,7 +3,6 @@ import { WithProviders } from '@atlaskit/editor-common/provider-factory';
3
3
  import { pluginKey as blockTypeStateKey } from '../block-type/pm-plugins/main';
4
4
  import { stateKey as mediaStateKey } from '../media/pm-plugins/plugin-key';
5
5
  import { isTypeAheadAllowed } from '../type-ahead/utils';
6
- import { mentionPluginKey } from '../mentions/pm-plugins/key';
7
6
  import { pluginKey as layoutStateKey } from '../layout';
8
7
  import { insertMacroFromMacroBrowser } from '../macro';
9
8
  import { emojiPluginKey } from '../emoji';
@@ -62,14 +61,12 @@ const insertBlockPlugin = (options = {}, api) => {
62
61
  typeAheadState: typeAheadPluginKey,
63
62
  blockTypeState: blockTypeStateKey,
64
63
  mediaState: mediaStateKey,
65
- mentionState: mentionPluginKey,
66
64
  macroState: macroStateKey,
67
65
  emojiState: emojiPluginKey,
68
66
  placeholderTextState: placeholderTextStateKey,
69
67
  layoutState: layoutStateKey
70
68
  },
71
69
  render: ({
72
- mentionState,
73
70
  blockTypeState,
74
71
  mediaState,
75
72
  macroState = {},
@@ -90,7 +87,6 @@ const insertBlockPlugin = (options = {}, api) => {
90
87
  isToolbarReducedSpacing: isToolbarReducedSpacing,
91
88
  isLastItem: isLastItem,
92
89
  featureFlags: featureFlags,
93
- mentionState: mentionState,
94
90
  blockTypeState: blockTypeState,
95
91
  mediaState: mediaState,
96
92
  macroState: macroState,
@@ -125,7 +121,6 @@ function ToolbarInsertBlockWithInjectionApi({
125
121
  providers,
126
122
  pluginInjectionApi,
127
123
  options,
128
- mentionState,
129
124
  blockTypeState,
130
125
  mediaState,
131
126
  macroState,
@@ -139,8 +134,9 @@ function ToolbarInsertBlockWithInjectionApi({
139
134
  const {
140
135
  dateState,
141
136
  hyperlinkState,
142
- imageUploadState
143
- } = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload']);
137
+ imageUploadState,
138
+ mentionState
139
+ } = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention']);
144
140
  return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
145
141
  pluginInjectionApi: pluginInjectionApi,
146
142
  buttons: buttons,
@@ -151,6 +147,7 @@ function ToolbarInsertBlockWithInjectionApi({
151
147
  tableSupported: !!editorView.state.schema.nodes.table,
152
148
  actionSupported: !!editorView.state.schema.nodes.taskItem,
153
149
  mentionsSupported: !!(mentionState && mentionState.mentionProvider),
150
+ mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
154
151
  decisionSupported: !!editorView.state.schema.nodes.decisionItem,
155
152
  dateEnabled: !!dateState,
156
153
  placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
@@ -30,6 +30,7 @@ const createInsertBlockItems = config => {
30
30
  imageUploadSupported,
31
31
  imageUploadEnabled,
32
32
  mentionsSupported,
33
+ mentionsDisabled,
33
34
  availableWrapperBlockTypes,
34
35
  actionSupported,
35
36
  decisionSupported,
@@ -83,7 +84,7 @@ const createInsertBlockItems = config => {
83
84
  items.push(mention({
84
85
  content: formatMessage(messages.mention),
85
86
  tooltipDescription: formatMessage(messages.mentionDescription),
86
- disabled: !isTypeAheadAllowed,
87
+ disabled: !isTypeAheadAllowed || !!mentionsDisabled,
87
88
  'aria-haspopup': 'listbox'
88
89
  }));
89
90
  }
@@ -165,17 +165,23 @@ export class ToolbarInsertBlock extends React.PureComponent {
165
165
  return true;
166
166
  });
167
167
  _defineProperty(this, "insertMention", inputMethod => {
168
+ var _pluginInjectionApi$d3;
168
169
  const {
169
- editorView
170
+ editorView,
171
+ pluginInjectionApi
170
172
  } = this.props;
171
173
  if (!editorView) {
172
174
  return true;
173
175
  }
176
+ const pluginState = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.mention) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : _pluginInjectionApi$d3.sharedState.currentState();
177
+ if (pluginState && pluginState.canInsertMention === false) {
178
+ return false;
179
+ }
174
180
  createTypeAheadTools(editorView).openMention(inputMethod);
175
181
  return true;
176
182
  });
177
183
  _defineProperty(this, "insertTable", inputMethod => {
178
- var _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _pluginInjectionApi$d6;
184
+ var _pluginInjectionApi$d4, _pluginInjectionApi$d5, _pluginInjectionApi$d6, _pluginInjectionApi$d7;
179
185
  const {
180
186
  pluginInjectionApi,
181
187
  editorView
@@ -184,7 +190,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
184
190
  state,
185
191
  dispatch
186
192
  } = editorView;
187
- return (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.table) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : (_pluginInjectionApi$d5 = (_pluginInjectionApi$d6 = _pluginInjectionApi$d4.actions).insertTable) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.call(_pluginInjectionApi$d6, {
193
+ return (_pluginInjectionApi$d4 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d5 = pluginInjectionApi.dependencies.table) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : (_pluginInjectionApi$d6 = (_pluginInjectionApi$d7 = _pluginInjectionApi$d5.actions).insertTable) === null || _pluginInjectionApi$d6 === void 0 ? void 0 : _pluginInjectionApi$d6.call(_pluginInjectionApi$d7, {
188
194
  action: ACTION.INSERTED,
189
195
  actionSubject: ACTION_SUBJECT.DOCUMENT,
190
196
  actionSubjectId: ACTION_SUBJECT_ID.TABLE,
@@ -192,7 +198,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
192
198
  inputMethod
193
199
  },
194
200
  eventType: EVENT_TYPE.TRACK
195
- })(state, dispatch)) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : false;
201
+ })(state, dispatch)) !== null && _pluginInjectionApi$d4 !== void 0 ? _pluginInjectionApi$d4 : false;
196
202
  });
197
203
  _defineProperty(this, "createDate", inputMethod => {
198
204
  const {
@@ -398,6 +404,7 @@ export class ToolbarInsertBlock extends React.PureComponent {
398
404
  imageUploadSupported: props.imageUploadSupported,
399
405
  imageUploadEnabled: props.imageUploadEnabled,
400
406
  mentionsSupported: props.mentionsSupported,
407
+ mentionsDisabled: props.mentionsDisabled,
401
408
  actionSupported: props.actionSupported,
402
409
  decisionSupported: props.decisionSupported,
403
410
  linkSupported: props.linkSupported,
@@ -13,6 +13,12 @@ import { createTypeAheadConfig } from './type-ahead';
13
13
  import { mentionPluginKey } from './pm-plugins/key';
14
14
  import { createMentionPlugin } from './pm-plugins/main';
15
15
  export { mentionPluginKey };
16
+ const getSharedState = editorState => {
17
+ if (!editorState) {
18
+ return undefined;
19
+ }
20
+ return mentionPluginKey.getState(editorState);
21
+ };
16
22
  const mentionsPlugin = (options, api) => {
17
23
  let sessionId = uuid();
18
24
  const fireEvent = payload => {
@@ -65,6 +71,7 @@ const mentionsPlugin = (options, api) => {
65
71
  })
66
72
  });
67
73
  },
74
+ getSharedState,
68
75
  pluginsOptions: {
69
76
  quickInsert: ({
70
77
  formatMessage
@@ -79,6 +86,10 @@ const mentionsPlugin = (options, api) => {
79
86
  action(insert, state) {
80
87
  var _api$dependencies$ana3;
81
88
  const tr = insert(undefined);
89
+ const pluginState = getSharedState(state);
90
+ if (pluginState && pluginState.canInsertMention === false) {
91
+ return false;
92
+ }
82
93
  openTypeAheadAtCursor({
83
94
  triggerHandler: typeAhead,
84
95
  inputMethod: INPUT_METHOD.QUICK_INSERT