@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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/plugins/expand/commands.js +2 -1
- package/dist/cjs/plugins/expand/index.js +1 -1
- 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/ui/Appearance/FullPage/MainToolbar.js +1 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/plugins/expand/commands.js +2 -1
- package/dist/es2019/plugins/expand/index.js +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/ui/Appearance/FullPage/MainToolbar.js +2 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/plugins/expand/commands.js +2 -1
- package/dist/esm/plugins/expand/index.js +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/ui/Appearance/FullPage/MainToolbar.js +2 -2
- 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 +6 -6
- package/report.api.md +1 -0
- package/tmp/api-report-tmp.d.ts +1 -0
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
2
|
import { N30 } from '@atlaskit/theme/colors';
|
|
3
|
-
import {
|
|
3
|
+
import { akEditorFloatingDialogZIndex, akEditorSwoopCubicBezier, akEditorToolbarKeylineHeight, akEditorMobileMaxWidth } from '@atlaskit/editor-shared-styles';
|
|
4
4
|
export const MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT = 868;
|
|
5
5
|
const toolbarLineHeight = 56;
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ const mainToolbar = css`
|
|
|
20
20
|
align-items: center;
|
|
21
21
|
box-shadow: none;
|
|
22
22
|
transition: box-shadow 200ms ${akEditorSwoopCubicBezier};
|
|
23
|
-
z-index: ${
|
|
23
|
+
z-index: ${akEditorFloatingDialogZIndex};
|
|
24
24
|
display: flex;
|
|
25
25
|
height: ${toolbarLineHeight}px;
|
|
26
26
|
flex-shrink: 0;
|
package/dist/es2019/version.json
CHANGED
|
@@ -8,6 +8,7 @@ import { GapCursorSelection, Side } from '../selection/gap-cursor-selection';
|
|
|
8
8
|
import { findExpand } from './utils';
|
|
9
9
|
import { createCommand } from './pm-plugins/plugin-factory';
|
|
10
10
|
import { createWrapSelectionTransaction } from '../block-type/commands/block-type';
|
|
11
|
+
import { safeInsert } from 'prosemirror-utils';
|
|
11
12
|
export var setExpandRef = function setExpandRef(ref) {
|
|
12
13
|
return createCommand({
|
|
13
14
|
type: 'SET_EXPAND_REF',
|
|
@@ -110,7 +111,7 @@ export var insertExpand = function insertExpand(state, dispatch) {
|
|
|
110
111
|
if (!expandNode) {
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
113
|
-
var tr = createWrapSelectionTransaction({
|
|
114
|
+
var tr = state.selection.empty ? safeInsert(expandNode)(state.tr).scrollIntoView() : createWrapSelectionTransaction({
|
|
114
115
|
state: state,
|
|
115
116
|
type: expandNode.type
|
|
116
117
|
});
|
|
@@ -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';
|
|
@@ -65,15 +64,13 @@ var insertBlockPlugin = function insertBlockPlugin() {
|
|
|
65
64
|
typeAheadState: typeAheadPluginKey,
|
|
66
65
|
blockTypeState: blockTypeStateKey,
|
|
67
66
|
mediaState: mediaStateKey,
|
|
68
|
-
mentionState: mentionPluginKey,
|
|
69
67
|
macroState: macroStateKey,
|
|
70
68
|
emojiState: emojiPluginKey,
|
|
71
69
|
placeholderTextState: placeholderTextStateKey,
|
|
72
70
|
layoutState: layoutStateKey
|
|
73
71
|
},
|
|
74
72
|
render: function render(_ref2) {
|
|
75
|
-
var
|
|
76
|
-
blockTypeState = _ref2.blockTypeState,
|
|
73
|
+
var blockTypeState = _ref2.blockTypeState,
|
|
77
74
|
mediaState = _ref2.mediaState,
|
|
78
75
|
_ref2$macroState = _ref2.macroState,
|
|
79
76
|
macroState = _ref2$macroState === void 0 ? {} : _ref2$macroState,
|
|
@@ -94,7 +91,6 @@ var insertBlockPlugin = function insertBlockPlugin() {
|
|
|
94
91
|
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
95
92
|
isLastItem: isLastItem,
|
|
96
93
|
featureFlags: featureFlags,
|
|
97
|
-
mentionState: mentionState,
|
|
98
94
|
blockTypeState: blockTypeState,
|
|
99
95
|
mediaState: mediaState,
|
|
100
96
|
macroState: macroState,
|
|
@@ -131,7 +127,6 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
131
127
|
providers = _ref3.providers,
|
|
132
128
|
pluginInjectionApi = _ref3.pluginInjectionApi,
|
|
133
129
|
options = _ref3.options,
|
|
134
|
-
mentionState = _ref3.mentionState,
|
|
135
130
|
blockTypeState = _ref3.blockTypeState,
|
|
136
131
|
mediaState = _ref3.mediaState,
|
|
137
132
|
macroState = _ref3.macroState,
|
|
@@ -140,10 +135,11 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
140
135
|
layoutState = _ref3.layoutState,
|
|
141
136
|
featureFlags = _ref3.featureFlags;
|
|
142
137
|
var buttons = toolbarSizeToButtons(toolbarSize);
|
|
143
|
-
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload']),
|
|
138
|
+
var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['hyperlink', 'date', 'imageUpload', 'mention']),
|
|
144
139
|
dateState = _useSharedPluginState.dateState,
|
|
145
140
|
hyperlinkState = _useSharedPluginState.hyperlinkState,
|
|
146
|
-
imageUploadState = _useSharedPluginState.imageUploadState
|
|
141
|
+
imageUploadState = _useSharedPluginState.imageUploadState,
|
|
142
|
+
mentionState = _useSharedPluginState.mentionState;
|
|
147
143
|
return /*#__PURE__*/React.createElement(ToolbarInsertBlock, {
|
|
148
144
|
pluginInjectionApi: pluginInjectionApi,
|
|
149
145
|
buttons: buttons,
|
|
@@ -154,6 +150,7 @@ function ToolbarInsertBlockWithInjectionApi(_ref3) {
|
|
|
154
150
|
tableSupported: !!editorView.state.schema.nodes.table,
|
|
155
151
|
actionSupported: !!editorView.state.schema.nodes.taskItem,
|
|
156
152
|
mentionsSupported: !!(mentionState && mentionState.mentionProvider),
|
|
153
|
+
mentionsDisabled: !!(mentionState && !mentionState.canInsertMention),
|
|
157
154
|
decisionSupported: !!editorView.state.schema.nodes.decisionItem,
|
|
158
155
|
dateEnabled: !!dateState,
|
|
159
156
|
placeholderTextEnabled: placeholderTextState && placeholderTextState.allowInserting,
|
|
@@ -37,6 +37,7 @@ var createInsertBlockItems = function createInsertBlockItems(config) {
|
|
|
37
37
|
imageUploadSupported = config.imageUploadSupported,
|
|
38
38
|
imageUploadEnabled = config.imageUploadEnabled,
|
|
39
39
|
mentionsSupported = config.mentionsSupported,
|
|
40
|
+
mentionsDisabled = config.mentionsDisabled,
|
|
40
41
|
availableWrapperBlockTypes = config.availableWrapperBlockTypes,
|
|
41
42
|
actionSupported = config.actionSupported,
|
|
42
43
|
decisionSupported = config.decisionSupported,
|
|
@@ -89,7 +90,7 @@ var createInsertBlockItems = function createInsertBlockItems(config) {
|
|
|
89
90
|
items.push(mention({
|
|
90
91
|
content: formatMessage(messages.mention),
|
|
91
92
|
tooltipDescription: formatMessage(messages.mentionDescription),
|
|
92
|
-
disabled: !isTypeAheadAllowed,
|
|
93
|
+
disabled: !isTypeAheadAllowed || !!mentionsDisabled,
|
|
93
94
|
'aria-haspopup': 'listbox'
|
|
94
95
|
}));
|
|
95
96
|
}
|
|
@@ -176,21 +176,28 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
176
176
|
return true;
|
|
177
177
|
});
|
|
178
178
|
_defineProperty(_assertThisInitialized(_this), "insertMention", function (inputMethod) {
|
|
179
|
-
var
|
|
179
|
+
var _pluginInjectionApi$d3;
|
|
180
|
+
var _this$props2 = _this.props,
|
|
181
|
+
editorView = _this$props2.editorView,
|
|
182
|
+
pluginInjectionApi = _this$props2.pluginInjectionApi;
|
|
180
183
|
if (!editorView) {
|
|
181
184
|
return true;
|
|
182
185
|
}
|
|
186
|
+
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();
|
|
187
|
+
if (pluginState && pluginState.canInsertMention === false) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
183
190
|
createTypeAheadTools(editorView).openMention(inputMethod);
|
|
184
191
|
return true;
|
|
185
192
|
});
|
|
186
193
|
_defineProperty(_assertThisInitialized(_this), "insertTable", function (inputMethod) {
|
|
187
|
-
var _pluginInjectionApi$
|
|
188
|
-
var _this$
|
|
189
|
-
pluginInjectionApi = _this$
|
|
190
|
-
editorView = _this$
|
|
194
|
+
var _pluginInjectionApi$d4, _pluginInjectionApi$d5, _pluginInjectionApi$d6, _pluginInjectionApi$d7;
|
|
195
|
+
var _this$props3 = _this.props,
|
|
196
|
+
pluginInjectionApi = _this$props3.pluginInjectionApi,
|
|
197
|
+
editorView = _this$props3.editorView;
|
|
191
198
|
var state = editorView.state,
|
|
192
199
|
dispatch = editorView.dispatch;
|
|
193
|
-
return (_pluginInjectionApi$
|
|
200
|
+
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, {
|
|
194
201
|
action: ACTION.INSERTED,
|
|
195
202
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
196
203
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
@@ -198,7 +205,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
198
205
|
inputMethod: inputMethod
|
|
199
206
|
},
|
|
200
207
|
eventType: EVENT_TYPE.TRACK
|
|
201
|
-
})(state, dispatch)) !== null && _pluginInjectionApi$
|
|
208
|
+
})(state, dispatch)) !== null && _pluginInjectionApi$d4 !== void 0 ? _pluginInjectionApi$d4 : false;
|
|
202
209
|
});
|
|
203
210
|
_defineProperty(_assertThisInitialized(_this), "createDate", function (inputMethod) {
|
|
204
211
|
var editorView = _this.props.editorView;
|
|
@@ -221,9 +228,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
221
228
|
return true;
|
|
222
229
|
});
|
|
223
230
|
_defineProperty(_assertThisInitialized(_this), "openMediaPicker", function (inputMethod) {
|
|
224
|
-
var _this$
|
|
225
|
-
onShowMediaPicker = _this$
|
|
226
|
-
dispatchAnalyticsEvent = _this$
|
|
231
|
+
var _this$props4 = _this.props,
|
|
232
|
+
onShowMediaPicker = _this$props4.onShowMediaPicker,
|
|
233
|
+
dispatchAnalyticsEvent = _this$props4.dispatchAnalyticsEvent;
|
|
227
234
|
if (onShowMediaPicker) {
|
|
228
235
|
onShowMediaPicker();
|
|
229
236
|
if (dispatchAnalyticsEvent) {
|
|
@@ -250,11 +257,11 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
250
257
|
};
|
|
251
258
|
});
|
|
252
259
|
_defineProperty(_assertThisInitialized(_this), "insertHorizontalRule", function (inputMethod) {
|
|
253
|
-
var _this$
|
|
254
|
-
_this$
|
|
255
|
-
state = _this$
|
|
256
|
-
dispatch = _this$
|
|
257
|
-
featureFlags = _this$
|
|
260
|
+
var _this$props5 = _this.props,
|
|
261
|
+
_this$props5$editorVi = _this$props5.editorView,
|
|
262
|
+
state = _this$props5$editorVi.state,
|
|
263
|
+
dispatch = _this$props5$editorVi.dispatch,
|
|
264
|
+
featureFlags = _this$props5.featureFlags;
|
|
258
265
|
return insertHorizontalRule(inputMethod, featureFlags)(state, dispatch);
|
|
259
266
|
});
|
|
260
267
|
_defineProperty(_assertThisInitialized(_this), "insertExpand", function () {
|
|
@@ -265,9 +272,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
265
272
|
});
|
|
266
273
|
_defineProperty(_assertThisInitialized(_this), "insertBlockType", function (itemName) {
|
|
267
274
|
return function () {
|
|
268
|
-
var _this$
|
|
269
|
-
editorView = _this$
|
|
270
|
-
onInsertBlockType = _this$
|
|
275
|
+
var _this$props6 = _this.props,
|
|
276
|
+
editorView = _this$props6.editorView,
|
|
277
|
+
onInsertBlockType = _this$props6.onInsertBlockType;
|
|
271
278
|
var state = editorView.state,
|
|
272
279
|
dispatch = editorView.dispatch;
|
|
273
280
|
onInsertBlockType(itemName)(state, dispatch);
|
|
@@ -286,11 +293,11 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
286
293
|
_defineProperty(_assertThisInitialized(_this), "onItemActivated", function (_ref2) {
|
|
287
294
|
var item = _ref2.item,
|
|
288
295
|
inputMethod = _ref2.inputMethod;
|
|
289
|
-
var _this$
|
|
290
|
-
editorView = _this$
|
|
291
|
-
editorActions = _this$
|
|
292
|
-
handleImageUpload = _this$
|
|
293
|
-
expandEnabled = _this$
|
|
296
|
+
var _this$props7 = _this.props,
|
|
297
|
+
editorView = _this$props7.editorView,
|
|
298
|
+
editorActions = _this$props7.editorActions,
|
|
299
|
+
handleImageUpload = _this$props7.handleImageUpload,
|
|
300
|
+
expandEnabled = _this$props7.expandEnabled;
|
|
294
301
|
|
|
295
302
|
// need to do this before inserting nodes so scrollIntoView works properly
|
|
296
303
|
if (!editorView.hasFocus()) {
|
|
@@ -406,12 +413,12 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
406
413
|
key: "renderPopup",
|
|
407
414
|
value: function renderPopup() {
|
|
408
415
|
var emojiPickerOpen = this.state.emojiPickerOpen;
|
|
409
|
-
var _this$
|
|
410
|
-
popupsMountPoint = _this$
|
|
411
|
-
popupsBoundariesElement = _this$
|
|
412
|
-
popupsScrollableElement = _this$
|
|
413
|
-
emojiProvider = _this$
|
|
414
|
-
replacePlusMenuWithElementBrowser = _this$
|
|
416
|
+
var _this$props8 = this.props,
|
|
417
|
+
popupsMountPoint = _this$props8.popupsMountPoint,
|
|
418
|
+
popupsBoundariesElement = _this$props8.popupsBoundariesElement,
|
|
419
|
+
popupsScrollableElement = _this$props8.popupsScrollableElement,
|
|
420
|
+
emojiProvider = _this$props8.emojiProvider,
|
|
421
|
+
replacePlusMenuWithElementBrowser = _this$props8.replacePlusMenuWithElementBrowser;
|
|
415
422
|
var dropdownEmoji = this.state.dropdownItems.some(function (_ref4) {
|
|
416
423
|
var name = _ref4.value.name;
|
|
417
424
|
return name === 'emoji';
|
|
@@ -447,9 +454,9 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
447
454
|
buttons = _this$state.buttons,
|
|
448
455
|
dropdownItems = _this$state.dropdownItems,
|
|
449
456
|
emojiPickerOpen = _this$state.emojiPickerOpen;
|
|
450
|
-
var _this$
|
|
451
|
-
isDisabled = _this$
|
|
452
|
-
isReducedSpacing = _this$
|
|
457
|
+
var _this$props9 = this.props,
|
|
458
|
+
isDisabled = _this$props9.isDisabled,
|
|
459
|
+
isReducedSpacing = _this$props9.isReducedSpacing;
|
|
453
460
|
if (buttons.length === 0 && dropdownItems.length === 0) {
|
|
454
461
|
return null;
|
|
455
462
|
}
|
|
@@ -509,6 +516,7 @@ export var ToolbarInsertBlock = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
509
516
|
imageUploadSupported: props.imageUploadSupported,
|
|
510
517
|
imageUploadEnabled: props.imageUploadEnabled,
|
|
511
518
|
mentionsSupported: props.mentionsSupported,
|
|
519
|
+
mentionsDisabled: props.mentionsDisabled,
|
|
512
520
|
actionSupported: props.actionSupported,
|
|
513
521
|
decisionSupported: props.decisionSupported,
|
|
514
522
|
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
|
+
var getSharedState = function getSharedState(editorState) {
|
|
17
|
+
if (!editorState) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
return mentionPluginKey.getState(editorState);
|
|
21
|
+
};
|
|
16
22
|
var mentionsPlugin = function mentionsPlugin(options, api) {
|
|
17
23
|
var sessionId = uuid();
|
|
18
24
|
var fireEvent = function fireEvent(payload) {
|
|
@@ -67,6 +73,7 @@ var mentionsPlugin = function mentionsPlugin(options, api) {
|
|
|
67
73
|
}
|
|
68
74
|
});
|
|
69
75
|
},
|
|
76
|
+
getSharedState: getSharedState,
|
|
70
77
|
pluginsOptions: {
|
|
71
78
|
quickInsert: function quickInsert(_ref4) {
|
|
72
79
|
var formatMessage = _ref4.formatMessage;
|
|
@@ -83,6 +90,10 @@ var mentionsPlugin = function mentionsPlugin(options, api) {
|
|
|
83
90
|
action: function action(insert, state) {
|
|
84
91
|
var _api$dependencies$ana3;
|
|
85
92
|
var tr = insert(undefined);
|
|
93
|
+
var pluginState = getSharedState(state);
|
|
94
|
+
if (pluginState && pluginState.canInsertMention === false) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
86
97
|
openTypeAheadAtCursor({
|
|
87
98
|
triggerHandler: typeAhead,
|
|
88
99
|
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
@@ -6,6 +6,7 @@ import { SLI_EVENT_TYPE, SMART_EVENT_TYPE, buildSliPayload } from '@atlaskit/men
|
|
|
6
6
|
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
7
7
|
import { MentionNodeView } from '../nodeviews/mention';
|
|
8
8
|
import { mentionPluginKey } from './key';
|
|
9
|
+
import { canMentionBeCreatedInRange } from './utils';
|
|
9
10
|
var ACTIONS = {
|
|
10
11
|
SET_PROVIDER: 'SET_PROVIDER',
|
|
11
12
|
SET_CONTEXT: 'SET_CONTEXT'
|
|
@@ -46,30 +47,44 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
|
|
|
46
47
|
return new SafePlugin({
|
|
47
48
|
key: mentionPluginKey,
|
|
48
49
|
state: {
|
|
49
|
-
init: function init() {
|
|
50
|
-
|
|
50
|
+
init: function init(_, state) {
|
|
51
|
+
var canInsertMention = canMentionBeCreatedInRange(state.selection.from, state.selection.to)(state);
|
|
52
|
+
return {
|
|
53
|
+
canInsertMention: canInsertMention
|
|
54
|
+
};
|
|
51
55
|
},
|
|
52
|
-
apply: function apply(tr, pluginState) {
|
|
56
|
+
apply: function apply(tr, pluginState, oldState, newState) {
|
|
53
57
|
var _ref = tr.getMeta(mentionPluginKey) || {
|
|
54
58
|
action: null,
|
|
55
59
|
params: null
|
|
56
60
|
},
|
|
57
61
|
action = _ref.action,
|
|
58
62
|
params = _ref.params;
|
|
63
|
+
var hasNewPluginState = false;
|
|
59
64
|
var newPluginState = pluginState;
|
|
65
|
+
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
66
|
+
if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
|
|
67
|
+
newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
68
|
+
canInsertMention: canMentionBeCreatedInRange(newState.selection.from, newState.selection.to)(newState)
|
|
69
|
+
});
|
|
70
|
+
hasNewPluginState = true;
|
|
71
|
+
}
|
|
60
72
|
switch (action) {
|
|
61
73
|
case ACTIONS.SET_PROVIDER:
|
|
62
|
-
newPluginState = _objectSpread(_objectSpread({},
|
|
74
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
63
75
|
mentionProvider: params.provider
|
|
64
76
|
});
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
hasNewPluginState = true;
|
|
78
|
+
break;
|
|
67
79
|
case ACTIONS.SET_CONTEXT:
|
|
68
|
-
newPluginState = _objectSpread(_objectSpread({},
|
|
80
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
69
81
|
contextIdentifierProvider: params.context
|
|
70
82
|
});
|
|
71
|
-
|
|
72
|
-
|
|
83
|
+
hasNewPluginState = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (hasNewPluginState) {
|
|
87
|
+
pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
|
|
73
88
|
}
|
|
74
89
|
return newPluginState;
|
|
75
90
|
}
|
|
@@ -1,4 +1,16 @@
|
|
|
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 var canMentionBeCreatedInRange = function canMentionBeCreatedInRange(from, to) {
|
|
7
|
+
return function (state) {
|
|
8
|
+
var $from = state.doc.resolve(from);
|
|
9
|
+
var $to = state.doc.resolve(to);
|
|
10
|
+
var mention = state.schema.nodes.mention.createChecked();
|
|
11
|
+
if ($from.parent === $to.parent && canInsert($from, mention)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -2,14 +2,14 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral
|
|
|
2
2
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { N30 } from '@atlaskit/theme/colors';
|
|
5
|
-
import {
|
|
5
|
+
import { akEditorFloatingDialogZIndex, akEditorSwoopCubicBezier, akEditorToolbarKeylineHeight, akEditorMobileMaxWidth } from '@atlaskit/editor-shared-styles';
|
|
6
6
|
export var MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT = 868;
|
|
7
7
|
var toolbarLineHeight = 56;
|
|
8
8
|
|
|
9
9
|
// box-shadow is overriden by the mainToolbar
|
|
10
10
|
var mainToolbarWithKeyline = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n box-shadow: 0 ", "px 0 0\n ", ";\n"])), akEditorToolbarKeylineHeight, "var(--ds-border, ".concat(N30, ")"));
|
|
11
11
|
var mainToolbarTwoLineStyle = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n @media (max-width: ", "px) {\n flex-wrap: wrap;\n height: calc(", "px * 2);\n }\n"])), MAXIMUM_TWO_LINE_TOOLBAR_BREAKPOINT, toolbarLineHeight);
|
|
12
|
-
var mainToolbar = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\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"])), akEditorSwoopCubicBezier,
|
|
12
|
+
var mainToolbar = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\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"])), akEditorSwoopCubicBezier, akEditorFloatingDialogZIndex, toolbarLineHeight, "var(--ds-surface, white)", akEditorMobileMaxWidth, toolbarLineHeight);
|
|
13
13
|
export var mainToolbarStyle = function mainToolbarStyle(showKeyline, twoLineEditorToolbar) {
|
|
14
14
|
return [mainToolbar, showKeyline && mainToolbarWithKeyline, twoLineEditorToolbar && mainToolbarTwoLineStyle];
|
|
15
15
|
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { ImageUploadPlugin } from '../image-upload';
|
|
3
3
|
import type datePlugin from '../date';
|
|
4
|
-
import { tablesPlugin } from '@atlaskit/editor-plugin-table';
|
|
4
|
+
import type { tablesPlugin } from '@atlaskit/editor-plugin-table';
|
|
5
5
|
import type { hyperlinkPlugin } from '@atlaskit/editor-plugin-hyperlink';
|
|
6
6
|
import type featureFlagsPlugin from '@atlaskit/editor-plugin-feature-flags';
|
|
7
7
|
import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
8
|
+
import type mentionsPlugin from '../mentions';
|
|
8
9
|
export interface InsertBlockOptions {
|
|
9
10
|
allowTables?: boolean;
|
|
10
11
|
allowExpand?: boolean;
|
|
@@ -22,7 +23,8 @@ declare const insertBlockPlugin: NextEditorPlugin<'insertBlock', {
|
|
|
22
23
|
OptionalPlugin<typeof hyperlinkPlugin>,
|
|
23
24
|
OptionalPlugin<typeof datePlugin>,
|
|
24
25
|
OptionalPlugin<typeof analyticsPlugin>,
|
|
25
|
-
OptionalPlugin<ImageUploadPlugin
|
|
26
|
+
OptionalPlugin<ImageUploadPlugin>,
|
|
27
|
+
OptionalPlugin<typeof mentionsPlugin>
|
|
26
28
|
];
|
|
27
29
|
}>;
|
|
28
30
|
export default insertBlockPlugin;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
-
import { Schema } from 'prosemirror-model';
|
|
4
|
-
import { EmojiProvider } from '@atlaskit/emoji/resource';
|
|
5
|
-
import { BlockType } from '../../../block-type/types';
|
|
6
|
-
import { MenuItem } from '../../../../ui/DropdownMenu/types';
|
|
7
|
-
import { MacroProvider } from '../../../macro';
|
|
2
|
+
import type { WrappedComponentProps } from 'react-intl-next';
|
|
3
|
+
import type { Schema } from 'prosemirror-model';
|
|
4
|
+
import type { EmojiProvider } from '@atlaskit/emoji/resource';
|
|
5
|
+
import type { BlockType } from '../../../block-type/types';
|
|
6
|
+
import type { MenuItem } from '../../../../ui/DropdownMenu/types';
|
|
7
|
+
import type { MacroProvider } from '../../../macro';
|
|
8
8
|
export interface CreateItemsConfig {
|
|
9
9
|
isTypeAheadAllowed?: boolean;
|
|
10
10
|
tableSupported?: boolean;
|
|
@@ -13,6 +13,7 @@ export interface CreateItemsConfig {
|
|
|
13
13
|
imageUploadSupported?: boolean;
|
|
14
14
|
imageUploadEnabled?: boolean;
|
|
15
15
|
mentionsSupported?: boolean;
|
|
16
|
+
mentionsDisabled?: boolean;
|
|
16
17
|
availableWrapperBlockTypes?: BlockType[];
|
|
17
18
|
actionSupported?: boolean;
|
|
18
19
|
decisionSupported?: boolean;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { INPUT_METHOD, DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import { EditorView } from 'prosemirror-view';
|
|
3
|
-
import { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI, ImageUploadPluginReferenceEvent, Command } from '@atlaskit/editor-common/types';
|
|
4
|
-
import { EmojiProvider } from '@atlaskit/emoji';
|
|
5
|
-
import { BlockType } from '../../../block-type/types';
|
|
6
|
-
import { MacroProvider } from '@atlaskit/editor-common/provider-factory';
|
|
7
|
-
import { MenuItem } from '../../../../ui/DropdownMenu/types';
|
|
8
|
-
import { Node as PMNode } from 'prosemirror-model';
|
|
9
|
-
import { BlockMenuItem } from './create-items';
|
|
1
|
+
import type { INPUT_METHOD, DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import type { EditorView } from 'prosemirror-view';
|
|
3
|
+
import type { EditorActionsOptions as EditorActions, FeatureFlags, ExtractInjectionAPI, ImageUploadPluginReferenceEvent, Command } from '@atlaskit/editor-common/types';
|
|
4
|
+
import type { EmojiProvider } from '@atlaskit/emoji';
|
|
5
|
+
import type { BlockType } from '../../../block-type/types';
|
|
6
|
+
import type { MacroProvider } from '@atlaskit/editor-common/provider-factory';
|
|
7
|
+
import type { MenuItem } from '../../../../ui/DropdownMenu/types';
|
|
8
|
+
import type { Node as PMNode } from 'prosemirror-model';
|
|
9
|
+
import type { BlockMenuItem } from './create-items';
|
|
10
10
|
import type insertBlockPlugin from '../../index';
|
|
11
11
|
export interface Props {
|
|
12
12
|
buttons: number;
|
|
@@ -49,6 +49,7 @@ export interface Props {
|
|
|
49
49
|
dispatchAnalyticsEvent?: DispatchAnalyticsEvent;
|
|
50
50
|
featureFlags: FeatureFlags;
|
|
51
51
|
pluginInjectionApi?: ExtractInjectionAPI<typeof insertBlockPlugin>;
|
|
52
|
+
mentionsDisabled?: boolean;
|
|
52
53
|
}
|
|
53
54
|
export interface State {
|
|
54
55
|
isPlusMenuOpen: boolean;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { MentionPluginOptions } from './types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { MentionPluginOptions, MentionPluginState } from './types';
|
|
3
3
|
import { mentionPluginKey } from './pm-plugins/key';
|
|
4
4
|
import type { analyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
5
5
|
export { mentionPluginKey };
|
|
6
6
|
declare const mentionsPlugin: NextEditorPlugin<'mention', {
|
|
7
7
|
pluginConfiguration: MentionPluginOptions | undefined;
|
|
8
8
|
dependencies: [OptionalPlugin<typeof analyticsPlugin>];
|
|
9
|
+
sharedState: MentionPluginState | undefined;
|
|
9
10
|
}>;
|
|
10
11
|
export default mentionsPlugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { EditorState } from 'prosemirror-state';
|
|
2
|
-
import { MentionPluginState } from '../types';
|
|
1
|
+
import type { EditorState } from 'prosemirror-state';
|
|
2
|
+
import type { MentionPluginState } from '../types';
|
|
3
3
|
export declare function getMentionPluginState(state: EditorState): MentionPluginState;
|
|
4
|
+
export declare const canMentionBeCreatedInRange: (from: number, to: number) => (state: EditorState) => boolean;
|
|
@@ -19,5 +19,6 @@ export type MentionPluginState = {
|
|
|
19
19
|
mentionProvider?: MentionProvider;
|
|
20
20
|
contextIdentifierProvider?: ContextIdentifierProvider;
|
|
21
21
|
mentions?: Array<MentionDescription>;
|
|
22
|
+
canInsertMention?: boolean;
|
|
22
23
|
};
|
|
23
24
|
export type FireElementsChannelEvent = <T extends AnalyticsEventPayload>(payload: T) => void;
|