@atlaskit/editor-plugin-mentions 0.2.0 → 0.2.2

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 0.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#70152](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70152) [`53ed3673df28`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/53ed3673df28) - Updating adf-schema version to 35.5.1
8
+
9
+ ## 0.2.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#68640](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68640) [`6a3ea210641a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6a3ea210641a) - Create new context identifier plugin which contains the provider.
14
+ - Updated dependencies
15
+
3
16
  ## 0.2.0
4
17
 
5
18
  ### Minor Changes
@@ -39,7 +39,8 @@ var mentionsPlugin = exports.mentionsPlugin = function mentionsPlugin(_ref) {
39
39
  sanitizePrivateContent: options === null || options === void 0 ? void 0 : options.sanitizePrivateContent,
40
40
  mentionInsertDisplayName: options === null || options === void 0 ? void 0 : options.insertDisplayName,
41
41
  HighlightComponent: options === null || options === void 0 ? void 0 : options.HighlightComponent,
42
- fireEvent: fireEvent
42
+ fireEvent: fireEvent,
43
+ api: api
43
44
  });
44
45
  return {
45
46
  name: 'mention',
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createMentionPlugin = createMentionPlugin;
8
- exports.setContext = void 0;
9
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _reactNodeView = require("@atlaskit/editor-common/react-node-view");
11
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
@@ -16,8 +15,7 @@ var _utils = require("./utils");
16
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
17
  var ACTIONS = {
19
- SET_PROVIDER: 'SET_PROVIDER',
20
- SET_CONTEXT: 'SET_CONTEXT'
18
+ SET_PROVIDER: 'SET_PROVIDER'
21
19
  };
22
20
  var setProvider = function setProvider(provider) {
23
21
  return function (state, dispatch) {
@@ -32,19 +30,6 @@ var setProvider = function setProvider(provider) {
32
30
  return true;
33
31
  };
34
32
  };
35
- var setContext = exports.setContext = function setContext(context) {
36
- return function (state, dispatch) {
37
- if (dispatch) {
38
- dispatch(state.tr.setMeta(_key.mentionPluginKey, {
39
- action: ACTIONS.SET_CONTEXT,
40
- params: {
41
- context: context
42
- }
43
- }));
44
- }
45
- return true;
46
- };
47
- };
48
33
  function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
49
34
  var mentionProvider;
50
35
  var sendAnalytics = function sendAnalytics(event, actionSubject, action, attributes) {
@@ -84,12 +69,6 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
84
69
  });
85
70
  hasNewPluginState = true;
86
71
  break;
87
- case ACTIONS.SET_CONTEXT:
88
- newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
89
- contextIdentifierProvider: params.context
90
- });
91
- hasNewPluginState = true;
92
- break;
93
72
  }
94
73
  if (hasNewPluginState) {
95
74
  pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
@@ -127,24 +106,14 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
127
106
  return setProvider(undefined)(editorView.state, editorView.dispatch);
128
107
  });
129
108
  break;
130
- case 'contextIdentifierProvider':
131
- if (!providerPromise) {
132
- return setContext(undefined)(editorView.state, editorView.dispatch);
133
- }
134
- providerPromise.then(function (provider) {
135
- setContext(provider)(editorView.state, editorView.dispatch);
136
- });
137
- break;
138
109
  }
139
110
  return;
140
111
  };
141
112
  pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
142
- pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
143
113
  return {
144
114
  destroy: function destroy() {
145
115
  if (pmPluginFactoryParams.providerFactory) {
146
116
  pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
147
- pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
148
117
  }
149
118
  if (mentionProvider) {
150
119
  mentionProvider.unsubscribe('mentionPlugin');
@@ -193,7 +193,8 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
193
193
  var sanitizePrivateContent = _ref6.sanitizePrivateContent,
194
194
  mentionInsertDisplayName = _ref6.mentionInsertDisplayName,
195
195
  fireEvent = _ref6.fireEvent,
196
- HighlightComponent = _ref6.HighlightComponent;
196
+ HighlightComponent = _ref6.HighlightComponent,
197
+ api = _ref6.api;
197
198
  var sessionId = (0, _uuid.default)();
198
199
  var firstQueryWithoutResults = null;
199
200
  var subscriptionKeys = new Set();
@@ -211,14 +212,16 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
211
212
  return null;
212
213
  },
213
214
  getItems: function getItems(_ref7) {
215
+ var _api$contextIdentifie, _api$contextIdentifie2;
214
216
  var query = _ref7.query,
215
217
  editorState = _ref7.editorState;
216
218
  var pluginState = (0, _utils2.getMentionPluginState)(editorState);
217
219
  if (!(pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider)) {
218
220
  return Promise.resolve([]);
219
221
  }
220
- var mentionProvider = pluginState.mentionProvider,
221
- contextIdentifierProvider = pluginState.contextIdentifierProvider;
222
+ var mentionProvider = pluginState.mentionProvider;
223
+ var _ref8 = (_api$contextIdentifie = api === null || api === void 0 || (_api$contextIdentifie2 = api.contextIdentifier) === null || _api$contextIdentifie2 === void 0 ? void 0 : _api$contextIdentifie2.sharedState.currentState()) !== null && _api$contextIdentifie !== void 0 ? _api$contextIdentifie : {},
224
+ contextIdentifierProvider = _ref8.contextIdentifierProvider;
222
225
  return new Promise(function (resolve) {
223
226
  var key = "loadingMentionsForTypeAhead_".concat((0, _uuid.default)());
224
227
  var mentionsSubscribeCallback = function mentionsSubscribeCallback(mentions) {
@@ -271,11 +274,12 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
271
274
  onOpen: function onOpen() {
272
275
  firstQueryWithoutResults = null;
273
276
  },
274
- selectItem: function selectItem(state, item, insert, _ref8) {
275
- var mode = _ref8.mode,
276
- stats = _ref8.stats,
277
- query = _ref8.query,
278
- sourceListItem = _ref8.sourceListItem;
277
+ selectItem: function selectItem(state, item, insert, _ref9) {
278
+ var _api$contextIdentifie3, _api$contextIdentifie4;
279
+ var mode = _ref9.mode,
280
+ stats = _ref9.stats,
281
+ query = _ref9.query,
282
+ sourceListItem = _ref9.sourceListItem;
279
283
  var schema = state.schema;
280
284
  var pluginState = (0, _utils2.getMentionPluginState)(state);
281
285
  var mentionProvider = pluginState.mentionProvider;
@@ -287,7 +291,9 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
287
291
  userType = _item$mention.userType;
288
292
  var trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
289
293
  var renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
290
- var mentionContext = _objectSpread(_objectSpread({}, pluginState.contextIdentifierProvider), {}, {
294
+ var _ref10 = (_api$contextIdentifie3 = api === null || api === void 0 || (_api$contextIdentifie4 = api.contextIdentifier) === null || _api$contextIdentifie4 === void 0 ? void 0 : _api$contextIdentifie4.sharedState.currentState()) !== null && _api$contextIdentifie3 !== void 0 ? _api$contextIdentifie3 : {},
295
+ contextIdentifierProvider = _ref10.contextIdentifierProvider;
296
+ var mentionContext = _objectSpread(_objectSpread({}, contextIdentifierProvider), {}, {
291
297
  sessionId: sessionId
292
298
  });
293
299
  if (mentionProvider && !(0, _utils3.isInviteItem)(item.mention)) {
@@ -299,7 +305,7 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
299
305
  if (mentionProvider && mentionProvider.shouldEnableInvite && (0, _utils3.isInviteItem)(item.mention)) {
300
306
  // Don't fire event and the callback with selection by space press
301
307
  if (mode !== 'space') {
302
- fireEvent((0, _analytics.buildTypeAheadInviteItemClickedPayload)(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, pluginState.contextIdentifierProvider, mentionProvider.userRole));
308
+ fireEvent((0, _analytics.buildTypeAheadInviteItemClickedPayload)(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, contextIdentifierProvider, mentionProvider.userRole));
303
309
  if (mentionProvider.onInviteItemClick) {
304
310
  mentionProvider.onInviteItemClick('mention');
305
311
  }
@@ -317,7 +323,7 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
317
323
  }
318
324
  fireEvent((0, _analytics.buildTypeAheadInsertedPayload)(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, sourceListItem.map(function (x) {
319
325
  return x.mention;
320
- }), query, pluginState.contextIdentifierProvider, taskListId, taskItemId));
326
+ }), query, contextIdentifierProvider, taskListId, taskItemId));
321
327
  sessionId = (0, _uuid.default)();
322
328
  if (mentionProvider && (0, _utils3.isTeamType)(userType)) {
323
329
  return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
@@ -338,11 +344,11 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
338
344
  var space = schema.text(' ');
339
345
  return insert(_model.Fragment.from([mentionNode, space]));
340
346
  },
341
- dismiss: function dismiss(_ref9) {
342
- var editorState = _ref9.editorState,
343
- query = _ref9.query,
344
- stats = _ref9.stats,
345
- wasItemInserted = _ref9.wasItemInserted;
347
+ dismiss: function dismiss(_ref11) {
348
+ var editorState = _ref11.editorState,
349
+ query = _ref11.query,
350
+ stats = _ref11.stats,
351
+ wasItemInserted = _ref11.wasItemInserted;
346
352
  firstQueryWithoutResults = null;
347
353
  var pickerElapsedTime = stats.startedAt ? performance.now() - stats.startedAt : 0;
348
354
  if (!wasItemInserted) {
@@ -31,7 +31,8 @@ const mentionsPlugin = ({
31
31
  sanitizePrivateContent: options === null || options === void 0 ? void 0 : options.sanitizePrivateContent,
32
32
  mentionInsertDisplayName: options === null || options === void 0 ? void 0 : options.insertDisplayName,
33
33
  HighlightComponent: options === null || options === void 0 ? void 0 : options.HighlightComponent,
34
- fireEvent
34
+ fireEvent,
35
+ api
35
36
  });
36
37
  return {
37
38
  name: 'mention',
@@ -5,8 +5,7 @@ import { MentionNodeView } from '../nodeviews/mention';
5
5
  import { mentionPluginKey } from './key';
6
6
  import { canMentionBeCreatedInRange } from './utils';
7
7
  const ACTIONS = {
8
- SET_PROVIDER: 'SET_PROVIDER',
9
- SET_CONTEXT: 'SET_CONTEXT'
8
+ SET_PROVIDER: 'SET_PROVIDER'
10
9
  };
11
10
  const setProvider = provider => (state, dispatch) => {
12
11
  if (dispatch) {
@@ -19,17 +18,6 @@ const setProvider = provider => (state, dispatch) => {
19
18
  }
20
19
  return true;
21
20
  };
22
- export const setContext = context => (state, dispatch) => {
23
- if (dispatch) {
24
- dispatch(state.tr.setMeta(mentionPluginKey, {
25
- action: ACTIONS.SET_CONTEXT,
26
- params: {
27
- context
28
- }
29
- }));
30
- }
31
- return true;
32
- };
33
21
  export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
34
22
  let mentionProvider;
35
23
  const sendAnalytics = (event, actionSubject, action, attributes) => {
@@ -72,13 +60,6 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
72
60
  };
73
61
  hasNewPluginState = true;
74
62
  break;
75
- case ACTIONS.SET_CONTEXT:
76
- newPluginState = {
77
- ...newPluginState,
78
- contextIdentifierProvider: params.context
79
- };
80
- hasNewPluginState = true;
81
- break;
82
63
  }
83
64
  if (hasNewPluginState) {
84
65
  pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
@@ -114,24 +95,14 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
114
95
  provider.subscribe('mentionPlugin', undefined, undefined, undefined, undefined, sendAnalytics);
115
96
  }).catch(() => setProvider(undefined)(editorView.state, editorView.dispatch));
116
97
  break;
117
- case 'contextIdentifierProvider':
118
- if (!providerPromise) {
119
- return setContext(undefined)(editorView.state, editorView.dispatch);
120
- }
121
- providerPromise.then(provider => {
122
- setContext(provider)(editorView.state, editorView.dispatch);
123
- });
124
- break;
125
98
  }
126
99
  return;
127
100
  };
128
101
  pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
129
- pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
130
102
  return {
131
103
  destroy() {
132
104
  if (pmPluginFactoryParams.providerFactory) {
133
105
  pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
134
- pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
135
106
  }
136
107
  if (mentionProvider) {
137
108
  mentionProvider.unsubscribe('mentionPlugin');
@@ -169,7 +169,8 @@ export const createTypeAheadConfig = ({
169
169
  sanitizePrivateContent,
170
170
  mentionInsertDisplayName,
171
171
  fireEvent,
172
- HighlightComponent
172
+ HighlightComponent,
173
+ api
173
174
  }) => {
174
175
  let sessionId = uuid();
175
176
  let firstQueryWithoutResults = null;
@@ -191,14 +192,17 @@ export const createTypeAheadConfig = ({
191
192
  query,
192
193
  editorState
193
194
  }) {
195
+ var _api$contextIdentifie, _api$contextIdentifie2;
194
196
  const pluginState = getMentionPluginState(editorState);
195
197
  if (!(pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider)) {
196
198
  return Promise.resolve([]);
197
199
  }
198
200
  const {
199
- mentionProvider,
200
- contextIdentifierProvider
201
+ mentionProvider
201
202
  } = pluginState;
203
+ const {
204
+ contextIdentifierProvider
205
+ } = (_api$contextIdentifie = api === null || api === void 0 ? void 0 : (_api$contextIdentifie2 = api.contextIdentifier) === null || _api$contextIdentifie2 === void 0 ? void 0 : _api$contextIdentifie2.sharedState.currentState()) !== null && _api$contextIdentifie !== void 0 ? _api$contextIdentifie : {};
202
206
  return new Promise(resolve => {
203
207
  const key = `loadingMentionsForTypeAhead_${uuid()}`;
204
208
  const mentionsSubscribeCallback = (mentions, resultQuery = '', stats) => {
@@ -256,6 +260,7 @@ export const createTypeAheadConfig = ({
256
260
  query,
257
261
  sourceListItem
258
262
  }) {
263
+ var _api$contextIdentifie3, _api$contextIdentifie4;
259
264
  const {
260
265
  schema
261
266
  } = state;
@@ -272,8 +277,11 @@ export const createTypeAheadConfig = ({
272
277
  } = item.mention;
273
278
  const trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
274
279
  const renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
280
+ const {
281
+ contextIdentifierProvider
282
+ } = (_api$contextIdentifie3 = api === null || api === void 0 ? void 0 : (_api$contextIdentifie4 = api.contextIdentifier) === null || _api$contextIdentifie4 === void 0 ? void 0 : _api$contextIdentifie4.sharedState.currentState()) !== null && _api$contextIdentifie3 !== void 0 ? _api$contextIdentifie3 : {};
275
283
  const mentionContext = {
276
- ...pluginState.contextIdentifierProvider,
284
+ ...contextIdentifierProvider,
277
285
  sessionId
278
286
  };
279
287
  if (mentionProvider && !isInviteItem(item.mention)) {
@@ -285,7 +293,7 @@ export const createTypeAheadConfig = ({
285
293
  if (mentionProvider && mentionProvider.shouldEnableInvite && isInviteItem(item.mention)) {
286
294
  // Don't fire event and the callback with selection by space press
287
295
  if (mode !== 'space') {
288
- fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, pluginState.contextIdentifierProvider, mentionProvider.userRole));
296
+ fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, contextIdentifierProvider, mentionProvider.userRole));
289
297
  if (mentionProvider.onInviteItemClick) {
290
298
  mentionProvider.onInviteItemClick('mention');
291
299
  }
@@ -301,7 +309,7 @@ export const createTypeAheadConfig = ({
301
309
  taskItemId = taskItem.node.attrs.localId;
302
310
  }
303
311
  }
304
- fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, sourceListItem.map(x => x.mention), query, pluginState.contextIdentifierProvider, taskListId, taskItemId));
312
+ fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, sourceListItem.map(x => x.mention), query, contextIdentifierProvider, taskListId, taskItemId));
305
313
  sessionId = uuid();
306
314
  if (mentionProvider && isTeamType(userType)) {
307
315
  return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
@@ -32,7 +32,8 @@ var mentionsPlugin = function mentionsPlugin(_ref) {
32
32
  sanitizePrivateContent: options === null || options === void 0 ? void 0 : options.sanitizePrivateContent,
33
33
  mentionInsertDisplayName: options === null || options === void 0 ? void 0 : options.insertDisplayName,
34
34
  HighlightComponent: options === null || options === void 0 ? void 0 : options.HighlightComponent,
35
- fireEvent: fireEvent
35
+ fireEvent: fireEvent,
36
+ api: api
36
37
  });
37
38
  return {
38
39
  name: 'mention',
@@ -8,8 +8,7 @@ import { MentionNodeView } from '../nodeviews/mention';
8
8
  import { mentionPluginKey } from './key';
9
9
  import { canMentionBeCreatedInRange } from './utils';
10
10
  var ACTIONS = {
11
- SET_PROVIDER: 'SET_PROVIDER',
12
- SET_CONTEXT: 'SET_CONTEXT'
11
+ SET_PROVIDER: 'SET_PROVIDER'
13
12
  };
14
13
  var setProvider = function setProvider(provider) {
15
14
  return function (state, dispatch) {
@@ -24,19 +23,6 @@ var setProvider = function setProvider(provider) {
24
23
  return true;
25
24
  };
26
25
  };
27
- export var setContext = function setContext(context) {
28
- return function (state, dispatch) {
29
- if (dispatch) {
30
- dispatch(state.tr.setMeta(mentionPluginKey, {
31
- action: ACTIONS.SET_CONTEXT,
32
- params: {
33
- context: context
34
- }
35
- }));
36
- }
37
- return true;
38
- };
39
- };
40
26
  export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
41
27
  var mentionProvider;
42
28
  var sendAnalytics = function sendAnalytics(event, actionSubject, action, attributes) {
@@ -76,12 +62,6 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
76
62
  });
77
63
  hasNewPluginState = true;
78
64
  break;
79
- case ACTIONS.SET_CONTEXT:
80
- newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
81
- contextIdentifierProvider: params.context
82
- });
83
- hasNewPluginState = true;
84
- break;
85
65
  }
86
66
  if (hasNewPluginState) {
87
67
  pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
@@ -119,24 +99,14 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
119
99
  return setProvider(undefined)(editorView.state, editorView.dispatch);
120
100
  });
121
101
  break;
122
- case 'contextIdentifierProvider':
123
- if (!providerPromise) {
124
- return setContext(undefined)(editorView.state, editorView.dispatch);
125
- }
126
- providerPromise.then(function (provider) {
127
- setContext(provider)(editorView.state, editorView.dispatch);
128
- });
129
- break;
130
102
  }
131
103
  return;
132
104
  };
133
105
  pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
134
- pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
135
106
  return {
136
107
  destroy: function destroy() {
137
108
  if (pmPluginFactoryParams.providerFactory) {
138
109
  pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
139
- pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
140
110
  }
141
111
  if (mentionProvider) {
142
112
  mentionProvider.unsubscribe('mentionPlugin');
@@ -181,7 +181,8 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
181
181
  var sanitizePrivateContent = _ref6.sanitizePrivateContent,
182
182
  mentionInsertDisplayName = _ref6.mentionInsertDisplayName,
183
183
  fireEvent = _ref6.fireEvent,
184
- HighlightComponent = _ref6.HighlightComponent;
184
+ HighlightComponent = _ref6.HighlightComponent,
185
+ api = _ref6.api;
185
186
  var sessionId = uuid();
186
187
  var firstQueryWithoutResults = null;
187
188
  var subscriptionKeys = new Set();
@@ -199,14 +200,16 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
199
200
  return null;
200
201
  },
201
202
  getItems: function getItems(_ref7) {
203
+ var _api$contextIdentifie, _api$contextIdentifie2;
202
204
  var query = _ref7.query,
203
205
  editorState = _ref7.editorState;
204
206
  var pluginState = getMentionPluginState(editorState);
205
207
  if (!(pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider)) {
206
208
  return Promise.resolve([]);
207
209
  }
208
- var mentionProvider = pluginState.mentionProvider,
209
- contextIdentifierProvider = pluginState.contextIdentifierProvider;
210
+ var mentionProvider = pluginState.mentionProvider;
211
+ var _ref8 = (_api$contextIdentifie = api === null || api === void 0 || (_api$contextIdentifie2 = api.contextIdentifier) === null || _api$contextIdentifie2 === void 0 ? void 0 : _api$contextIdentifie2.sharedState.currentState()) !== null && _api$contextIdentifie !== void 0 ? _api$contextIdentifie : {},
212
+ contextIdentifierProvider = _ref8.contextIdentifierProvider;
210
213
  return new Promise(function (resolve) {
211
214
  var key = "loadingMentionsForTypeAhead_".concat(uuid());
212
215
  var mentionsSubscribeCallback = function mentionsSubscribeCallback(mentions) {
@@ -259,11 +262,12 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
259
262
  onOpen: function onOpen() {
260
263
  firstQueryWithoutResults = null;
261
264
  },
262
- selectItem: function selectItem(state, item, insert, _ref8) {
263
- var mode = _ref8.mode,
264
- stats = _ref8.stats,
265
- query = _ref8.query,
266
- sourceListItem = _ref8.sourceListItem;
265
+ selectItem: function selectItem(state, item, insert, _ref9) {
266
+ var _api$contextIdentifie3, _api$contextIdentifie4;
267
+ var mode = _ref9.mode,
268
+ stats = _ref9.stats,
269
+ query = _ref9.query,
270
+ sourceListItem = _ref9.sourceListItem;
267
271
  var schema = state.schema;
268
272
  var pluginState = getMentionPluginState(state);
269
273
  var mentionProvider = pluginState.mentionProvider;
@@ -275,7 +279,9 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
275
279
  userType = _item$mention.userType;
276
280
  var trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
277
281
  var renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
278
- var mentionContext = _objectSpread(_objectSpread({}, pluginState.contextIdentifierProvider), {}, {
282
+ var _ref10 = (_api$contextIdentifie3 = api === null || api === void 0 || (_api$contextIdentifie4 = api.contextIdentifier) === null || _api$contextIdentifie4 === void 0 ? void 0 : _api$contextIdentifie4.sharedState.currentState()) !== null && _api$contextIdentifie3 !== void 0 ? _api$contextIdentifie3 : {},
283
+ contextIdentifierProvider = _ref10.contextIdentifierProvider;
284
+ var mentionContext = _objectSpread(_objectSpread({}, contextIdentifierProvider), {}, {
279
285
  sessionId: sessionId
280
286
  });
281
287
  if (mentionProvider && !isInviteItem(item.mention)) {
@@ -287,7 +293,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
287
293
  if (mentionProvider && mentionProvider.shouldEnableInvite && isInviteItem(item.mention)) {
288
294
  // Don't fire event and the callback with selection by space press
289
295
  if (mode !== 'space') {
290
- fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, pluginState.contextIdentifierProvider, mentionProvider.userRole));
296
+ fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, contextIdentifierProvider, mentionProvider.userRole));
291
297
  if (mentionProvider.onInviteItemClick) {
292
298
  mentionProvider.onInviteItemClick('mention');
293
299
  }
@@ -305,7 +311,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
305
311
  }
306
312
  fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, sourceListItem.map(function (x) {
307
313
  return x.mention;
308
- }), query, pluginState.contextIdentifierProvider, taskListId, taskItemId));
314
+ }), query, contextIdentifierProvider, taskListId, taskItemId));
309
315
  sessionId = uuid();
310
316
  if (mentionProvider && isTeamType(userType)) {
311
317
  return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
@@ -326,11 +332,11 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
326
332
  var space = schema.text(' ');
327
333
  return insert(Fragment.from([mentionNode, space]));
328
334
  },
329
- dismiss: function dismiss(_ref9) {
330
- var editorState = _ref9.editorState,
331
- query = _ref9.query,
332
- stats = _ref9.stats,
333
- wasItemInserted = _ref9.wasItemInserted;
335
+ dismiss: function dismiss(_ref11) {
336
+ var editorState = _ref11.editorState,
337
+ query = _ref11.query,
338
+ stats = _ref11.stats,
339
+ wasItemInserted = _ref11.wasItemInserted;
334
340
  firstQueryWithoutResults = null;
335
341
  var pickerElapsedTime = stats.startedAt ? performance.now() - stats.startedAt : 0;
336
342
  if (!wasItemInserted) {
@@ -1,6 +1,4 @@
1
- import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { Command, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
2
+ import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
4
3
  import type { MentionPluginOptions, MentionPluginState } from '../types';
5
- export declare const setContext: (context: ContextIdentifierProvider | undefined) => Command;
6
4
  export declare function createMentionPlugin(pmPluginFactoryParams: PMPluginFactoryParams, fireEvent: (payload: any) => void, options?: MentionPluginOptions): SafePlugin<MentionPluginState>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
+ import type { ExtractInjectionAPI, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
3
3
  import type { MentionDescription } from '@atlaskit/mention/resource';
4
- import type { FireElementsChannelEvent } from '../types';
4
+ import type { FireElementsChannelEvent, MentionsPlugin } from '../types';
5
5
  export declare const mentionToTypeaheadItem: (mention: MentionDescription) => TypeAheadItem;
6
6
  export declare function memoize<ResultFn extends (mention: MentionDescription) => TypeAheadItem>(fn: ResultFn): {
7
7
  call: ResultFn;
@@ -12,6 +12,7 @@ type Props = {
12
12
  mentionInsertDisplayName?: boolean;
13
13
  HighlightComponent?: React.ComponentType;
14
14
  fireEvent: FireElementsChannelEvent;
15
+ api: ExtractInjectionAPI<MentionsPlugin> | undefined;
15
16
  };
16
- export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, }: Props) => TypeAheadHandler;
17
+ export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, }: Props) => TypeAheadHandler;
17
18
  export {};
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import type { AnalyticsEventPayload } from '@atlaskit/analytics-next';
3
- import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
4
3
  import type { NextEditorPlugin, OptionalPlugin, TypeAheadHandler } from '@atlaskit/editor-common/types';
5
4
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
+ import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
6
6
  import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
7
7
  import type { MentionDescription, MentionProvider } from '@atlaskit/mention';
8
8
  export interface TeamInfoAttrAnalytics {
@@ -20,7 +20,6 @@ export interface MentionPluginOptions extends MentionPluginConfig {
20
20
  }
21
21
  export type MentionPluginState = {
22
22
  mentionProvider?: MentionProvider;
23
- contextIdentifierProvider?: ContextIdentifierProvider;
24
23
  mentions?: Array<MentionDescription>;
25
24
  canInsertMention?: boolean;
26
25
  };
@@ -30,7 +29,11 @@ export type MentionSharedState = MentionPluginState & {
30
29
  };
31
30
  export type MentionsPlugin = NextEditorPlugin<'mention', {
32
31
  pluginConfiguration: MentionPluginOptions | undefined;
33
- dependencies: [OptionalPlugin<AnalyticsPlugin>, TypeAheadPlugin];
32
+ dependencies: [
33
+ OptionalPlugin<AnalyticsPlugin>,
34
+ TypeAheadPlugin,
35
+ OptionalPlugin<ContextIdentifierPlugin>
36
+ ];
34
37
  sharedState: MentionSharedState | undefined;
35
38
  actions: {
36
39
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
@@ -1,6 +1,4 @@
1
- import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { Command, PMPluginFactoryParams } from '@atlaskit/editor-common/types';
2
+ import type { PMPluginFactoryParams } from '@atlaskit/editor-common/types';
4
3
  import type { MentionPluginOptions, MentionPluginState } from '../types';
5
- export declare const setContext: (context: ContextIdentifierProvider | undefined) => Command;
6
4
  export declare function createMentionPlugin(pmPluginFactoryParams: PMPluginFactoryParams, fireEvent: (payload: any) => void, options?: MentionPluginOptions): SafePlugin<MentionPluginState>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
+ import type { ExtractInjectionAPI, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
3
3
  import type { MentionDescription } from '@atlaskit/mention/resource';
4
- import type { FireElementsChannelEvent } from '../types';
4
+ import type { FireElementsChannelEvent, MentionsPlugin } from '../types';
5
5
  export declare const mentionToTypeaheadItem: (mention: MentionDescription) => TypeAheadItem;
6
6
  export declare function memoize<ResultFn extends (mention: MentionDescription) => TypeAheadItem>(fn: ResultFn): {
7
7
  call: ResultFn;
@@ -12,6 +12,7 @@ type Props = {
12
12
  mentionInsertDisplayName?: boolean;
13
13
  HighlightComponent?: React.ComponentType;
14
14
  fireEvent: FireElementsChannelEvent;
15
+ api: ExtractInjectionAPI<MentionsPlugin> | undefined;
15
16
  };
16
- export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, }: Props) => TypeAheadHandler;
17
+ export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, }: Props) => TypeAheadHandler;
17
18
  export {};
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import type { AnalyticsEventPayload } from '@atlaskit/analytics-next';
3
- import type { ContextIdentifierProvider } from '@atlaskit/editor-common/provider-factory';
4
3
  import type { NextEditorPlugin, OptionalPlugin, TypeAheadHandler } from '@atlaskit/editor-common/types';
5
4
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
+ import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
6
6
  import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
7
7
  import type { MentionDescription, MentionProvider } from '@atlaskit/mention';
8
8
  export interface TeamInfoAttrAnalytics {
@@ -20,7 +20,6 @@ export interface MentionPluginOptions extends MentionPluginConfig {
20
20
  }
21
21
  export type MentionPluginState = {
22
22
  mentionProvider?: MentionProvider;
23
- contextIdentifierProvider?: ContextIdentifierProvider;
24
23
  mentions?: Array<MentionDescription>;
25
24
  canInsertMention?: boolean;
26
25
  };
@@ -32,7 +31,8 @@ export type MentionsPlugin = NextEditorPlugin<'mention', {
32
31
  pluginConfiguration: MentionPluginOptions | undefined;
33
32
  dependencies: [
34
33
  OptionalPlugin<AnalyticsPlugin>,
35
- TypeAheadPlugin
34
+ TypeAheadPlugin,
35
+ OptionalPlugin<ContextIdentifierPlugin>
36
36
  ];
37
37
  sharedState: MentionSharedState | undefined;
38
38
  actions: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,10 +33,11 @@
33
33
  ".": "./src/index.ts"
34
34
  },
35
35
  "dependencies": {
36
- "@atlaskit/adf-schema": "^35.3.0",
36
+ "@atlaskit/adf-schema": "^35.5.1",
37
37
  "@atlaskit/analytics-gas-types": "^5.1.0",
38
- "@atlaskit/editor-common": "^77.1.0",
38
+ "@atlaskit/editor-common": "^77.2.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^0.4.0",
40
+ "@atlaskit/editor-plugin-context-identifier": "^0.1.0",
40
41
  "@atlaskit/editor-plugin-type-ahead": "^0.9.0",
41
42
  "@atlaskit/editor-prosemirror": "1.1.0",
42
43
  "@atlaskit/icon": "^22.0.0",