@atlaskit/editor-plugin-mentions 2.4.1 → 2.5.0

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,13 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 2.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#133315](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/133315)
8
+ [`5c94ca338de14`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5c94ca338de14) -
9
+ Updating mentions plugin config for handling deleted mentions and refactor
10
+
3
11
  ## 2.4.1
4
12
 
5
13
  ### Patch Changes
@@ -39,7 +39,7 @@ 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
- handleMentionsInserted: options === null || options === void 0 ? void 0 : options.handleMentionsInserted,
42
+ handleMentionsChanged: options === null || options === void 0 ? void 0 : options.handleMentionsChanged,
43
43
  fireEvent: fireEvent,
44
44
  api: api
45
45
  });
@@ -77,9 +77,9 @@ var mentionsPlugin = exports.mentionsPlugin = function mentionsPlugin(_ref) {
77
77
  inputMethod: inputMethod
78
78
  }));
79
79
  },
80
- announceMentionsInsertion: function announceMentionsInsertion(mentionIds) {
81
- if (options !== null && options !== void 0 && options.handleMentionsInserted) {
82
- options.handleMentionsInserted(mentionIds);
80
+ announceMentionsInsertion: function announceMentionsInsertion(mentionChanges) {
81
+ if (options !== null && options !== void 0 && options.handleMentionsChanged) {
82
+ options.handleMentionsChanged(mentionChanges);
83
83
  }
84
84
  }
85
85
  },
@@ -8,10 +8,12 @@ exports.createMentionPlugin = createMentionPlugin;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _reactNodeView = require("@atlaskit/editor-common/react-node-view");
10
10
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
+ var _utils = require("@atlaskit/editor-prosemirror/utils");
11
12
  var _resource = require("@atlaskit/mention/resource");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
14
  var _mention = require("../nodeviews/mention");
13
15
  var _key = require("./key");
14
- var _utils = require("./utils");
16
+ var _utils2 = require("./utils");
15
17
  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; }
16
18
  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; }
17
19
  var ACTIONS = {
@@ -41,7 +43,7 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
41
43
  key: _key.mentionPluginKey,
42
44
  state: {
43
45
  init: function init(_, state) {
44
- var canInsertMention = (0, _utils.canMentionBeCreatedInRange)(state.selection.from, state.selection.to)(state);
46
+ var canInsertMention = (0, _utils2.canMentionBeCreatedInRange)(state.selection.from, state.selection.to)(state);
45
47
  return {
46
48
  canInsertMention: canInsertMention
47
49
  };
@@ -58,7 +60,7 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
58
60
  var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
59
61
  if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
60
62
  newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
61
- canInsertMention: (0, _utils.canMentionBeCreatedInRange)(newState.selection.from, newState.selection.to)(newState)
63
+ canInsertMention: (0, _utils2.canMentionBeCreatedInRange)(newState.selection.from, newState.selection.to)(newState)
62
64
  });
63
65
  hasNewPluginState = true;
64
66
  }
@@ -118,6 +120,33 @@ function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
118
120
  if (mentionProvider) {
119
121
  mentionProvider.unsubscribe('mentionPlugin');
120
122
  }
123
+ },
124
+ update: function update(view, prevState) {
125
+ var newState = view.state;
126
+ if (options !== null && options !== void 0 && options.handleMentionsChanged && (0, _platformFeatureFlags.fg)('confluence_updated_mentions_livepages')) {
127
+ var mentionSchema = newState.schema.nodes.mention;
128
+ var mentionNodesBefore = (0, _utils.findChildrenByType)(prevState.doc, mentionSchema);
129
+ var mentionLocalIdsAfter = new Set((0, _utils.findChildrenByType)(newState.doc, mentionSchema).map(function (_ref2) {
130
+ var node = _ref2.node;
131
+ return node.attrs.localId;
132
+ }));
133
+ if (mentionNodesBefore.length > mentionLocalIdsAfter.size) {
134
+ var deletedMentions = mentionNodesBefore.filter(function (_ref3) {
135
+ var node = _ref3.node;
136
+ return !mentionLocalIdsAfter.has(node.attrs.localId);
137
+ }).map(function (_ref4) {
138
+ var node = _ref4.node;
139
+ return {
140
+ type: 'deleted',
141
+ id: node.attrs.id,
142
+ localId: node.attrs.localId
143
+ };
144
+ });
145
+ if (deletedMentions.length > 0) {
146
+ options.handleMentionsChanged(deletedMentions);
147
+ }
148
+ }
149
+ }
121
150
  }
122
151
  };
123
152
  }
@@ -198,7 +198,7 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
198
198
  fireEvent = _ref6.fireEvent,
199
199
  HighlightComponent = _ref6.HighlightComponent,
200
200
  api = _ref6.api,
201
- handleMentionsInserted = _ref6.handleMentionsInserted;
201
+ handleMentionsChanged = _ref6.handleMentionsChanged;
202
202
  var sessionId = (0, _uuid.default)();
203
203
  var firstQueryWithoutResults = null;
204
204
  var subscriptionKeys = new Set();
@@ -319,8 +319,9 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
319
319
  }
320
320
  }
321
321
  var mentionLocalId = (0, _uuid.default)();
322
- if (handleMentionsInserted) {
323
- handleMentionsInserted([{
322
+ if (handleMentionsChanged) {
323
+ handleMentionsChanged([{
324
+ type: 'added',
324
325
  localId: mentionLocalId,
325
326
  id: id
326
327
  }]);
@@ -31,7 +31,7 @@ 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
- handleMentionsInserted: options === null || options === void 0 ? void 0 : options.handleMentionsInserted,
34
+ handleMentionsChanged: options === null || options === void 0 ? void 0 : options.handleMentionsChanged,
35
35
  fireEvent,
36
36
  api
37
37
  });
@@ -68,9 +68,9 @@ const mentionsPlugin = ({
68
68
  inputMethod
69
69
  }));
70
70
  },
71
- announceMentionsInsertion: mentionIds => {
72
- if (options !== null && options !== void 0 && options.handleMentionsInserted) {
73
- options.handleMentionsInserted(mentionIds);
71
+ announceMentionsInsertion: mentionChanges => {
72
+ if (options !== null && options !== void 0 && options.handleMentionsChanged) {
73
+ options.handleMentionsChanged(mentionChanges);
74
74
  }
75
75
  }
76
76
  },
@@ -1,6 +1,8 @@
1
1
  import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
3
4
  import { buildSliPayload, SLI_EVENT_TYPE, SMART_EVENT_TYPE } from '@atlaskit/mention/resource';
5
+ import { fg } from '@atlaskit/platform-feature-flags';
4
6
  import { MentionNodeView } from '../nodeviews/mention';
5
7
  import { mentionPluginKey } from './key';
6
8
  import { canMentionBeCreatedInRange } from './utils';
@@ -107,6 +109,30 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
107
109
  if (mentionProvider) {
108
110
  mentionProvider.unsubscribe('mentionPlugin');
109
111
  }
112
+ },
113
+ update(view, prevState) {
114
+ const newState = view.state;
115
+ if (options !== null && options !== void 0 && options.handleMentionsChanged && fg('confluence_updated_mentions_livepages')) {
116
+ const mentionSchema = newState.schema.nodes.mention;
117
+ const mentionNodesBefore = findChildrenByType(prevState.doc, mentionSchema);
118
+ const mentionLocalIdsAfter = new Set(findChildrenByType(newState.doc, mentionSchema).map(({
119
+ node
120
+ }) => node.attrs.localId));
121
+ if (mentionNodesBefore.length > mentionLocalIdsAfter.size) {
122
+ const deletedMentions = mentionNodesBefore.filter(({
123
+ node
124
+ }) => !mentionLocalIdsAfter.has(node.attrs.localId)).map(({
125
+ node
126
+ }) => ({
127
+ type: 'deleted',
128
+ id: node.attrs.id,
129
+ localId: node.attrs.localId
130
+ }));
131
+ if (deletedMentions.length > 0) {
132
+ options.handleMentionsChanged(deletedMentions);
133
+ }
134
+ }
135
+ }
110
136
  }
111
137
  };
112
138
  }
@@ -174,7 +174,7 @@ export const createTypeAheadConfig = ({
174
174
  fireEvent,
175
175
  HighlightComponent,
176
176
  api,
177
- handleMentionsInserted
177
+ handleMentionsChanged
178
178
  }) => {
179
179
  let sessionId = uuid();
180
180
  let firstQueryWithoutResults = null;
@@ -305,8 +305,9 @@ export const createTypeAheadConfig = ({
305
305
  }
306
306
  }
307
307
  const mentionLocalId = uuid();
308
- if (handleMentionsInserted) {
309
- handleMentionsInserted([{
308
+ if (handleMentionsChanged) {
309
+ handleMentionsChanged([{
310
+ type: 'added',
310
311
  localId: mentionLocalId,
311
312
  id: id
312
313
  }]);
@@ -32,7 +32,7 @@ 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
- handleMentionsInserted: options === null || options === void 0 ? void 0 : options.handleMentionsInserted,
35
+ handleMentionsChanged: options === null || options === void 0 ? void 0 : options.handleMentionsChanged,
36
36
  fireEvent: fireEvent,
37
37
  api: api
38
38
  });
@@ -70,9 +70,9 @@ var mentionsPlugin = function mentionsPlugin(_ref) {
70
70
  inputMethod: inputMethod
71
71
  }));
72
72
  },
73
- announceMentionsInsertion: function announceMentionsInsertion(mentionIds) {
74
- if (options !== null && options !== void 0 && options.handleMentionsInserted) {
75
- options.handleMentionsInserted(mentionIds);
73
+ announceMentionsInsertion: function announceMentionsInsertion(mentionChanges) {
74
+ if (options !== null && options !== void 0 && options.handleMentionsChanged) {
75
+ options.handleMentionsChanged(mentionChanges);
76
76
  }
77
77
  }
78
78
  },
@@ -3,7 +3,9 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  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) { _defineProperty(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; }
4
4
  import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
5
5
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
6
7
  import { buildSliPayload, SLI_EVENT_TYPE, SMART_EVENT_TYPE } from '@atlaskit/mention/resource';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
7
9
  import { MentionNodeView } from '../nodeviews/mention';
8
10
  import { mentionPluginKey } from './key';
9
11
  import { canMentionBeCreatedInRange } from './utils';
@@ -111,6 +113,33 @@ export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
111
113
  if (mentionProvider) {
112
114
  mentionProvider.unsubscribe('mentionPlugin');
113
115
  }
116
+ },
117
+ update: function update(view, prevState) {
118
+ var newState = view.state;
119
+ if (options !== null && options !== void 0 && options.handleMentionsChanged && fg('confluence_updated_mentions_livepages')) {
120
+ var mentionSchema = newState.schema.nodes.mention;
121
+ var mentionNodesBefore = findChildrenByType(prevState.doc, mentionSchema);
122
+ var mentionLocalIdsAfter = new Set(findChildrenByType(newState.doc, mentionSchema).map(function (_ref2) {
123
+ var node = _ref2.node;
124
+ return node.attrs.localId;
125
+ }));
126
+ if (mentionNodesBefore.length > mentionLocalIdsAfter.size) {
127
+ var deletedMentions = mentionNodesBefore.filter(function (_ref3) {
128
+ var node = _ref3.node;
129
+ return !mentionLocalIdsAfter.has(node.attrs.localId);
130
+ }).map(function (_ref4) {
131
+ var node = _ref4.node;
132
+ return {
133
+ type: 'deleted',
134
+ id: node.attrs.id,
135
+ localId: node.attrs.localId
136
+ };
137
+ });
138
+ if (deletedMentions.length > 0) {
139
+ options.handleMentionsChanged(deletedMentions);
140
+ }
141
+ }
142
+ }
114
143
  }
115
144
  };
116
145
  }
@@ -186,7 +186,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
186
186
  fireEvent = _ref6.fireEvent,
187
187
  HighlightComponent = _ref6.HighlightComponent,
188
188
  api = _ref6.api,
189
- handleMentionsInserted = _ref6.handleMentionsInserted;
189
+ handleMentionsChanged = _ref6.handleMentionsChanged;
190
190
  var sessionId = uuid();
191
191
  var firstQueryWithoutResults = null;
192
192
  var subscriptionKeys = new Set();
@@ -307,8 +307,9 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
307
307
  }
308
308
  }
309
309
  var mentionLocalId = uuid();
310
- if (handleMentionsInserted) {
311
- handleMentionsInserted([{
310
+ if (handleMentionsChanged) {
311
+ handleMentionsChanged([{
312
+ type: 'added',
312
313
  localId: mentionLocalId,
313
314
  id: id
314
315
  }]);
@@ -13,10 +13,11 @@ type Props = {
13
13
  HighlightComponent?: React.ComponentType<React.PropsWithChildren<unknown>>;
14
14
  fireEvent: FireElementsChannelEvent;
15
15
  api: ExtractInjectionAPI<MentionsPlugin> | undefined;
16
- handleMentionsInserted?: (mentionIds: {
16
+ handleMentionsChanged?: (mentionChanges: {
17
+ type: 'added' | 'deleted';
17
18
  localId: string;
18
19
  id: string;
19
20
  }[]) => void;
20
21
  };
21
- export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, handleMentionsInserted, }: Props) => TypeAheadHandler;
22
+ export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, handleMentionsChanged, }: Props) => TypeAheadHandler;
22
23
  export {};
@@ -19,7 +19,8 @@ export interface MentionPluginConfig {
19
19
  export interface MentionPluginOptions extends MentionPluginConfig {
20
20
  sanitizePrivateContent?: boolean;
21
21
  allowZeroWidthSpaceAfter?: boolean;
22
- handleMentionsInserted?: (mentionIds: {
22
+ handleMentionsChanged?: (mentionChanges: {
23
+ type: 'added' | 'deleted';
23
24
  localId: string;
24
25
  id: string;
25
26
  }[]) => void;
@@ -44,6 +45,7 @@ export type MentionsPlugin = NextEditorPlugin<'mention', {
44
45
  actions: {
45
46
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
46
47
  announceMentionsInsertion: (mentionIds: {
48
+ type: 'added' | 'deleted';
47
49
  localId: string;
48
50
  id: string;
49
51
  }[]) => void;
@@ -13,10 +13,11 @@ type Props = {
13
13
  HighlightComponent?: React.ComponentType<React.PropsWithChildren<unknown>>;
14
14
  fireEvent: FireElementsChannelEvent;
15
15
  api: ExtractInjectionAPI<MentionsPlugin> | undefined;
16
- handleMentionsInserted?: (mentionIds: {
16
+ handleMentionsChanged?: (mentionChanges: {
17
+ type: 'added' | 'deleted';
17
18
  localId: string;
18
19
  id: string;
19
20
  }[]) => void;
20
21
  };
21
- export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, handleMentionsInserted, }: Props) => TypeAheadHandler;
22
+ export declare const createTypeAheadConfig: ({ sanitizePrivateContent, mentionInsertDisplayName, fireEvent, HighlightComponent, api, handleMentionsChanged, }: Props) => TypeAheadHandler;
22
23
  export {};
@@ -19,7 +19,8 @@ export interface MentionPluginConfig {
19
19
  export interface MentionPluginOptions extends MentionPluginConfig {
20
20
  sanitizePrivateContent?: boolean;
21
21
  allowZeroWidthSpaceAfter?: boolean;
22
- handleMentionsInserted?: (mentionIds: {
22
+ handleMentionsChanged?: (mentionChanges: {
23
+ type: 'added' | 'deleted';
23
24
  localId: string;
24
25
  id: string;
25
26
  }[]) => void;
@@ -44,6 +45,7 @@ export type MentionsPlugin = NextEditorPlugin<'mention', {
44
45
  actions: {
45
46
  openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
46
47
  announceMentionsInsertion: (mentionIds: {
48
+ type: 'added' | 'deleted';
47
49
  localId: string;
48
50
  id: string;
49
51
  }[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^40.8.1",
37
37
  "@atlaskit/analytics-gas-types": "^5.1.0",
38
- "@atlaskit/editor-common": "^88.0.0",
38
+ "@atlaskit/editor-common": "^88.1.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
40
40
  "@atlaskit/editor-plugin-context-identifier": "^1.3.0",
41
41
  "@atlaskit/editor-plugin-type-ahead": "^1.8.0",
@@ -110,6 +110,9 @@
110
110
  },
111
111
  "editor_inline_comments_paste_insert_nodes": {
112
112
  "type": "boolean"
113
+ },
114
+ "confluence_updated_mentions_livepages": {
115
+ "type": "boolean"
113
116
  }
114
117
  }
115
118
  }