@atlaskit/editor-core 187.6.0 → 187.6.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.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/plugins/insert-block/index.js +7 -10
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
- package/dist/cjs/plugins/insert-block/ui/ToolbarInsertBlock/index.js +40 -32
- package/dist/cjs/plugins/mentions/index.js +11 -0
- package/dist/cjs/plugins/mentions/pm-plugins/main.js +24 -9
- package/dist/cjs/plugins/mentions/pm-plugins/utils.js +15 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/insert-block/index.js +4 -7
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
- package/dist/es2019/plugins/insert-block/ui/ToolbarInsertBlock/index.js +11 -4
- package/dist/es2019/plugins/mentions/index.js +11 -0
- package/dist/es2019/plugins/mentions/pm-plugins/main.js +25 -9
- package/dist/es2019/plugins/mentions/pm-plugins/utils.js +11 -1
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/insert-block/index.js +5 -8
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/create-items.js +2 -1
- package/dist/esm/plugins/insert-block/ui/ToolbarInsertBlock/index.js +40 -32
- package/dist/esm/plugins/mentions/index.js +11 -0
- package/dist/esm/plugins/mentions/pm-plugins/main.js +24 -9
- package/dist/esm/plugins/mentions/pm-plugins/utils.js +13 -1
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/plugins/insert-block/index.d.ts +5 -3
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +7 -6
- package/dist/types/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +10 -9
- package/dist/types/plugins/mentions/index.d.ts +3 -2
- package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +3 -2
- package/dist/types/plugins/mentions/types.d.ts +1 -0
- package/dist/types-ts4.5/plugins/insert-block/index.d.ts +5 -3
- package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/create-items.d.ts +7 -6
- package/dist/types-ts4.5/plugins/insert-block/ui/ToolbarInsertBlock/types.d.ts +10 -9
- package/dist/types-ts4.5/plugins/mentions/index.d.ts +3 -2
- package/dist/types-ts4.5/plugins/mentions/pm-plugins/utils.d.ts +3 -2
- package/dist/types-ts4.5/plugins/mentions/types.d.ts +1 -0
- package/package.json +1 -1
- package/report.api.md +1 -0
- package/tmp/api-report-tmp.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-core
|
|
2
2
|
|
|
3
|
+
## 187.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`65f1e2bf9fc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/65f1e2bf9fc) - [ux] ED-18212 Disable toolbar mention when cursor is inside a codeblock
|
|
8
|
+
|
|
3
9
|
## 187.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -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
|
|
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:
|
|
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
|
|
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
|
|
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$
|
|
193
|
-
var _this$
|
|
194
|
-
pluginInjectionApi = _this$
|
|
195
|
-
editorView = _this$
|
|
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$
|
|
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$
|
|
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$
|
|
230
|
-
onShowMediaPicker = _this$
|
|
231
|
-
dispatchAnalyticsEvent = _this$
|
|
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$
|
|
259
|
-
_this$
|
|
260
|
-
state = _this$
|
|
261
|
-
dispatch = _this$
|
|
262
|
-
featureFlags = _this$
|
|
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$
|
|
274
|
-
editorView = _this$
|
|
275
|
-
onInsertBlockType = _this$
|
|
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$
|
|
295
|
-
editorView = _this$
|
|
296
|
-
editorActions = _this$
|
|
297
|
-
handleImageUpload = _this$
|
|
298
|
-
expandEnabled = _this$
|
|
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$
|
|
415
|
-
popupsMountPoint = _this$
|
|
416
|
-
popupsBoundariesElement = _this$
|
|
417
|
-
popupsScrollableElement = _this$
|
|
418
|
-
emojiProvider = _this$
|
|
419
|
-
replacePlusMenuWithElementBrowser = _this$
|
|
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$
|
|
456
|
-
isDisabled = _this$
|
|
457
|
-
isReducedSpacing = _this$
|
|
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
|
-
|
|
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({},
|
|
83
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
72
84
|
mentionProvider: params.provider
|
|
73
85
|
});
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
hasNewPluginState = true;
|
|
87
|
+
break;
|
|
76
88
|
case ACTIONS.SET_CONTEXT:
|
|
77
|
-
newPluginState = _objectSpread(_objectSpread({},
|
|
89
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
78
90
|
contextIdentifierProvider: params.context
|
|
79
91
|
});
|
|
80
|
-
|
|
81
|
-
|
|
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;
|
|
@@ -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.
|
|
9
|
+
var version = "187.6.1";
|
|
10
10
|
exports.version = version;
|
|
11
11
|
var nextMajorVersion = function nextMajorVersion() {
|
|
12
12
|
return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
|
package/dist/cjs/version.json
CHANGED
|
@@ -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
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
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
|
|
@@ -3,6 +3,7 @@ import { SLI_EVENT_TYPE, SMART_EVENT_TYPE, buildSliPayload } from '@atlaskit/men
|
|
|
3
3
|
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
4
4
|
import { MentionNodeView } from '../nodeviews/mention';
|
|
5
5
|
import { mentionPluginKey } from './key';
|
|
6
|
+
import { canMentionBeCreatedInRange } from './utils';
|
|
6
7
|
const ACTIONS = {
|
|
7
8
|
SET_PROVIDER: 'SET_PROVIDER',
|
|
8
9
|
SET_CONTEXT: 'SET_CONTEXT'
|
|
@@ -39,10 +40,13 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
|
|
|
39
40
|
return new SafePlugin({
|
|
40
41
|
key: mentionPluginKey,
|
|
41
42
|
state: {
|
|
42
|
-
init() {
|
|
43
|
-
|
|
43
|
+
init(_, state) {
|
|
44
|
+
const canInsertMention = canMentionBeCreatedInRange(state.selection.from, state.selection.to)(state);
|
|
45
|
+
return {
|
|
46
|
+
canInsertMention
|
|
47
|
+
};
|
|
44
48
|
},
|
|
45
|
-
apply(tr, pluginState) {
|
|
49
|
+
apply(tr, pluginState, oldState, newState) {
|
|
46
50
|
const {
|
|
47
51
|
action,
|
|
48
52
|
params
|
|
@@ -50,22 +54,34 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
|
|
|
50
54
|
action: null,
|
|
51
55
|
params: null
|
|
52
56
|
};
|
|
57
|
+
let hasNewPluginState = false;
|
|
53
58
|
let newPluginState = pluginState;
|
|
59
|
+
const hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
60
|
+
if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
|
|
61
|
+
newPluginState = {
|
|
62
|
+
...pluginState,
|
|
63
|
+
canInsertMention: canMentionBeCreatedInRange(newState.selection.from, newState.selection.to)(newState)
|
|
64
|
+
};
|
|
65
|
+
hasNewPluginState = true;
|
|
66
|
+
}
|
|
54
67
|
switch (action) {
|
|
55
68
|
case ACTIONS.SET_PROVIDER:
|
|
56
69
|
newPluginState = {
|
|
57
|
-
...
|
|
70
|
+
...newPluginState,
|
|
58
71
|
mentionProvider: params.provider
|
|
59
72
|
};
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
hasNewPluginState = true;
|
|
74
|
+
break;
|
|
62
75
|
case ACTIONS.SET_CONTEXT:
|
|
63
76
|
newPluginState = {
|
|
64
|
-
...
|
|
77
|
+
...newPluginState,
|
|
65
78
|
contextIdentifierProvider: params.context
|
|
66
79
|
};
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
hasNewPluginState = true;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (hasNewPluginState) {
|
|
84
|
+
pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
|
|
69
85
|
}
|
|
70
86
|
return newPluginState;
|
|
71
87
|
}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { mentionPluginKey } from './key';
|
|
2
|
+
import { canInsert } from 'prosemirror-utils';
|
|
2
3
|
export function getMentionPluginState(state) {
|
|
3
4
|
return mentionPluginKey.getState(state);
|
|
4
|
-
}
|
|
5
|
+
}
|
|
6
|
+
export const canMentionBeCreatedInRange = (from, to) => state => {
|
|
7
|
+
const $from = state.doc.resolve(from);
|
|
8
|
+
const $to = state.doc.resolve(to);
|
|
9
|
+
const mention = state.schema.nodes.mention.createChecked();
|
|
10
|
+
if ($from.parent === $to.parent && canInsert($from, mention)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
package/dist/es2019/version.json
CHANGED