@atlaskit/editor-core 188.10.5 → 188.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/labs/next/presets/universal.js +2 -1
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/version-wrapper.js +1 -1
  5. package/dist/es2019/labs/next/presets/universal.js +2 -1
  6. package/dist/es2019/plugins/index.js +0 -1
  7. package/dist/es2019/version-wrapper.js +1 -1
  8. package/dist/esm/labs/next/presets/universal.js +2 -1
  9. package/dist/esm/plugins/index.js +0 -1
  10. package/dist/esm/version-wrapper.js +1 -1
  11. package/dist/types/plugins/index.d.ts +0 -1
  12. package/dist/types/plugins/insert-block/types.d.ts +2 -4
  13. package/dist/types/types/editor-props.d.ts +1 -1
  14. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  15. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -4
  16. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  17. package/package.json +2 -2
  18. package/report.api.md +1 -9
  19. package/tmp/api-report-tmp.d.ts +1 -9
  20. package/dist/cjs/plugins/mentions/analytics.js +0 -157
  21. package/dist/cjs/plugins/mentions/index.js +0 -142
  22. package/dist/cjs/plugins/mentions/messages.js +0 -29
  23. package/dist/cjs/plugins/mentions/nodeviews/mention.js +0 -117
  24. package/dist/cjs/plugins/mentions/pm-plugins/key.js +0 -8
  25. package/dist/cjs/plugins/mentions/pm-plugins/main.js +0 -156
  26. package/dist/cjs/plugins/mentions/pm-plugins/utils.js +0 -23
  27. package/dist/cjs/plugins/mentions/type-ahead/index.js +0 -362
  28. package/dist/cjs/plugins/mentions/types.js +0 -5
  29. package/dist/cjs/plugins/mentions/ui/InviteItem/index.js +0 -76
  30. package/dist/cjs/plugins/mentions/ui/InviteItem/styles.js +0 -19
  31. package/dist/cjs/plugins/mentions/ui/Mention/index.js +0 -98
  32. package/dist/cjs/plugins/mentions/ui/ToolbarMention/index.js +0 -63
  33. package/dist/cjs/plugins/mentions/utils.js +0 -32
  34. package/dist/es2019/plugins/mentions/analytics.js +0 -147
  35. package/dist/es2019/plugins/mentions/index.js +0 -124
  36. package/dist/es2019/plugins/mentions/messages.js +0 -23
  37. package/dist/es2019/plugins/mentions/nodeviews/mention.js +0 -80
  38. package/dist/es2019/plugins/mentions/pm-plugins/key.js +0 -2
  39. package/dist/es2019/plugins/mentions/pm-plugins/main.js +0 -143
  40. package/dist/es2019/plugins/mentions/pm-plugins/utils.js +0 -14
  41. package/dist/es2019/plugins/mentions/type-ahead/index.js +0 -338
  42. package/dist/es2019/plugins/mentions/types.js +0 -1
  43. package/dist/es2019/plugins/mentions/ui/InviteItem/index.js +0 -66
  44. package/dist/es2019/plugins/mentions/ui/InviteItem/styles.js +0 -47
  45. package/dist/es2019/plugins/mentions/ui/Mention/index.js +0 -71
  46. package/dist/es2019/plugins/mentions/ui/ToolbarMention/index.js +0 -33
  47. package/dist/es2019/plugins/mentions/utils.js +0 -20
  48. package/dist/esm/plugins/mentions/analytics.js +0 -150
  49. package/dist/esm/plugins/mentions/index.js +0 -130
  50. package/dist/esm/plugins/mentions/messages.js +0 -23
  51. package/dist/esm/plugins/mentions/nodeviews/mention.js +0 -107
  52. package/dist/esm/plugins/mentions/pm-plugins/key.js +0 -2
  53. package/dist/esm/plugins/mentions/pm-plugins/main.js +0 -148
  54. package/dist/esm/plugins/mentions/pm-plugins/utils.js +0 -16
  55. package/dist/esm/plugins/mentions/type-ahead/index.js +0 -350
  56. package/dist/esm/plugins/mentions/types.js +0 -1
  57. package/dist/esm/plugins/mentions/ui/InviteItem/index.js +0 -65
  58. package/dist/esm/plugins/mentions/ui/InviteItem/styles.js +0 -12
  59. package/dist/esm/plugins/mentions/ui/Mention/index.js +0 -91
  60. package/dist/esm/plugins/mentions/ui/ToolbarMention/index.js +0 -53
  61. package/dist/esm/plugins/mentions/utils.js +0 -26
  62. package/dist/types/plugins/mentions/analytics.d.ts +0 -13
  63. package/dist/types/plugins/mentions/index.d.ts +0 -19
  64. package/dist/types/plugins/mentions/messages.d.ts +0 -22
  65. package/dist/types/plugins/mentions/nodeviews/mention.d.ts +0 -9
  66. package/dist/types/plugins/mentions/pm-plugins/key.d.ts +0 -3
  67. package/dist/types/plugins/mentions/pm-plugins/main.d.ts +0 -6
  68. package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  69. package/dist/types/plugins/mentions/type-ahead/index.d.ts +0 -17
  70. package/dist/types/plugins/mentions/types.d.ts +0 -24
  71. package/dist/types/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  72. package/dist/types/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  73. package/dist/types/plugins/mentions/ui/Mention/index.d.ts +0 -19
  74. package/dist/types/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  75. package/dist/types/plugins/mentions/utils.d.ts +0 -8
  76. package/dist/types-ts4.5/plugins/mentions/analytics.d.ts +0 -13
  77. package/dist/types-ts4.5/plugins/mentions/index.d.ts +0 -22
  78. package/dist/types-ts4.5/plugins/mentions/messages.d.ts +0 -22
  79. package/dist/types-ts4.5/plugins/mentions/nodeviews/mention.d.ts +0 -9
  80. package/dist/types-ts4.5/plugins/mentions/pm-plugins/key.d.ts +0 -3
  81. package/dist/types-ts4.5/plugins/mentions/pm-plugins/main.d.ts +0 -6
  82. package/dist/types-ts4.5/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  83. package/dist/types-ts4.5/plugins/mentions/type-ahead/index.d.ts +0 -17
  84. package/dist/types-ts4.5/plugins/mentions/types.d.ts +0 -24
  85. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  86. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  87. package/dist/types-ts4.5/plugins/mentions/ui/Mention/index.d.ts +0 -19
  88. package/dist/types-ts4.5/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  89. package/dist/types-ts4.5/plugins/mentions/utils.d.ts +0 -8
@@ -1,147 +0,0 @@
1
- import { OPERATIONAL_EVENT_TYPE, UI_EVENT_TYPE } from '@atlaskit/analytics-gas-types';
2
- import { isSpecialMention } from '@atlaskit/mention/resource';
3
- import { isTeamType } from './utils';
4
- const componentName = 'mention';
5
- export const buildAnalyticsPayload = (actionSubject, action, eventType, sessionId, otherAttributes = {}, tags = []) => ({
6
- action,
7
- actionSubject,
8
- eventType,
9
- attributes: {
10
- componentName,
11
- sessionId,
12
- ...otherAttributes
13
- },
14
- tags
15
- });
16
- const emptyQueryResponse = {
17
- queryLength: 0,
18
- spaceInQuery: false
19
- };
20
- const extractAttributesFromQuery = query => {
21
- if (query) {
22
- return {
23
- queryLength: query.length,
24
- spaceInQuery: query.indexOf(' ') !== -1
25
- };
26
- }
27
- return emptyQueryResponse;
28
- };
29
- export const buildTypeAheadCancelPayload = (duration, upKeyCount, downKeyCount, sessionId, query) => {
30
- const {
31
- queryLength,
32
- spaceInQuery
33
- } = extractAttributesFromQuery(query);
34
- return buildAnalyticsPayload('mentionTypeahead', 'cancelled', UI_EVENT_TYPE, sessionId, {
35
- duration,
36
- downKeyCount,
37
- upKeyCount,
38
- queryLength,
39
- spaceInQuery
40
- });
41
- };
42
- const getPosition = (mentionList, selectedMention) => {
43
- if (mentionList) {
44
- const index = mentionList.findIndex(mention => mention.id === selectedMention.id);
45
- return index === -1 ? undefined : index;
46
- }
47
- return;
48
- };
49
- const isClicked = insertType => insertType === 'selected';
50
- export const buildTypeAheadInviteItemViewedPayload = (sessionId, contextIdentifierProvider, userRole) => {
51
- const {
52
- containerId,
53
- objectId,
54
- childObjectId
55
- } = contextIdentifierProvider || {};
56
- return buildAnalyticsPayload('inviteItem', 'rendered', UI_EVENT_TYPE, sessionId, {
57
- containerId,
58
- objectId,
59
- childObjectId,
60
- userRole
61
- });
62
- };
63
- export const buildTypeAheadInviteExposurePayload = (sessionId, contextIdentifierProvider, inviteExperimentCohort, userRole) => {
64
- const {
65
- containerId,
66
- objectId,
67
- childObjectId
68
- } = contextIdentifierProvider || {};
69
- return buildAnalyticsPayload('feature', 'exposed', OPERATIONAL_EVENT_TYPE, sessionId, {
70
- flagKey: 'confluence.frontend.invite.from.mention',
71
- value: inviteExperimentCohort || 'not-enrolled',
72
- containerId,
73
- objectId,
74
- childObjectId,
75
- userRole
76
- }, ['measurement', 'hasCustomAttributes']);
77
- };
78
- export const buildTypeAheadInviteItemClickedPayload = (duration, upKeyCount, downKeyCount, sessionId, insertType, query, contextIdentifierProvider, userRole) => {
79
- const {
80
- queryLength,
81
- spaceInQuery
82
- } = extractAttributesFromQuery(query);
83
- const {
84
- containerId,
85
- objectId,
86
- childObjectId
87
- } = contextIdentifierProvider || {};
88
- return buildAnalyticsPayload('inviteItem', isClicked(insertType) ? 'clicked' : 'pressed', UI_EVENT_TYPE, sessionId, {
89
- duration,
90
- queryLength,
91
- spaceInQuery,
92
- upKeyCount,
93
- downKeyCount,
94
- containerId,
95
- objectId,
96
- childObjectId,
97
- userRole
98
- });
99
- };
100
- export const buildTypeAheadInsertedPayload = (duration, upKeyCount, downKeyCount, sessionId, insertType, mention, mentionList, query, contextIdentifierProvider) => {
101
- const {
102
- queryLength,
103
- spaceInQuery
104
- } = extractAttributesFromQuery(query);
105
- let analyticsPayload = buildAnalyticsPayload('mentionTypeahead', isClicked(insertType) ? 'clicked' : 'pressed', UI_EVENT_TYPE, sessionId, {
106
- duration,
107
- position: getPosition(mentionList, mention),
108
- keyboardKey: isClicked(insertType) ? undefined : insertType,
109
- source: mention.source,
110
- queryLength,
111
- spaceInQuery,
112
- isSpecial: isSpecialMention(mention),
113
- accessLevel: mention.accessLevel || '',
114
- userType: mention.userType,
115
- userId: mention.id,
116
- upKeyCount,
117
- downKeyCount,
118
- memberCount: isTeamType(mention.userType) && mention.context ? mention.context.memberCount : null,
119
- includesYou: isTeamType(mention.userType) && mention.context ? mention.context.includesYou : null
120
- });
121
- if (contextIdentifierProvider) {
122
- analyticsPayload.containerId = contextIdentifierProvider.containerId || undefined;
123
- analyticsPayload.objectId = contextIdentifierProvider.objectId || undefined;
124
- analyticsPayload.childObjectId = contextIdentifierProvider.childObjectId || undefined;
125
- }
126
- return analyticsPayload;
127
- };
128
- export const buildTypeAheadRenderedPayload = (duration, userIds, query, teams) => {
129
- const {
130
- queryLength,
131
- spaceInQuery
132
- } = extractAttributesFromQuery(query);
133
- const actionSubject = userIds ? 'mentionTypeahead' : 'teamMentionTypeahead';
134
- return {
135
- action: 'rendered',
136
- actionSubject,
137
- eventType: OPERATIONAL_EVENT_TYPE,
138
- attributes: {
139
- componentName,
140
- duration,
141
- userIds,
142
- teams,
143
- queryLength,
144
- spaceInQuery
145
- }
146
- };
147
- };
@@ -1,124 +0,0 @@
1
- import React from 'react';
2
- import uuid from 'uuid';
3
- import { ELEMENTS_CHANNEL } from '@atlaskit/mention/resource';
4
- import { mention } from '@atlaskit/adf-schema';
5
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
6
- import ToolbarMention from './ui/ToolbarMention';
7
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
8
- import { IconMention } from '@atlaskit/editor-common/quick-insert';
9
- import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
10
- import { createTypeAheadConfig } from './type-ahead';
11
- import { mentionPluginKey } from './pm-plugins/key';
12
- import { createMentionPlugin } from './pm-plugins/main';
13
- export { mentionPluginKey };
14
- const mentionsPlugin = ({
15
- config: options,
16
- api
17
- }) => {
18
- let sessionId = uuid();
19
- const fireEvent = payload => {
20
- var _api$analytics$shared, _api$analytics;
21
- const {
22
- createAnalyticsEvent
23
- } = (_api$analytics$shared = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.sharedState.currentState()) !== null && _api$analytics$shared !== void 0 ? _api$analytics$shared : {};
24
- if (!createAnalyticsEvent) {
25
- return;
26
- }
27
- if (payload.attributes && !payload.attributes.sessionId) {
28
- payload.attributes.sessionId = sessionId;
29
- }
30
- createAnalyticsEvent(payload).fire(ELEMENTS_CHANNEL);
31
- };
32
- const typeAhead = createTypeAheadConfig({
33
- sanitizePrivateContent: options === null || options === void 0 ? void 0 : options.sanitizePrivateContent,
34
- mentionInsertDisplayName: options === null || options === void 0 ? void 0 : options.insertDisplayName,
35
- HighlightComponent: options === null || options === void 0 ? void 0 : options.HighlightComponent,
36
- fireEvent
37
- });
38
- return {
39
- name: 'mention',
40
- nodes() {
41
- return [{
42
- name: 'mention',
43
- node: mention
44
- }];
45
- },
46
- pmPlugins() {
47
- return [{
48
- name: 'mention',
49
- plugin: pmPluginFactoryParams => createMentionPlugin(pmPluginFactoryParams, fireEvent, options)
50
- }];
51
- },
52
- secondaryToolbarComponent({
53
- editorView,
54
- disabled
55
- }) {
56
- const openMentionTypeAhead = () => {
57
- var _api$typeAhead, _api$typeAhead$action;
58
- api === null || api === void 0 ? void 0 : (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 ? void 0 : (_api$typeAhead$action = _api$typeAhead.actions) === null || _api$typeAhead$action === void 0 ? void 0 : _api$typeAhead$action.open({
59
- triggerHandler: typeAhead,
60
- inputMethod: INPUT_METHOD.INSERT_MENU
61
- });
62
- };
63
- return /*#__PURE__*/React.createElement(WithPluginState, {
64
- editorView: editorView,
65
- plugins: {
66
- mentionState: mentionPluginKey
67
- },
68
- render: ({
69
- mentionState = {}
70
- }) => !mentionState.mentionProvider ? null : /*#__PURE__*/React.createElement(ToolbarMention, {
71
- editorView: editorView,
72
- onInsertMention: openMentionTypeAhead,
73
- isDisabled: disabled || (api === null || api === void 0 ? void 0 : api.typeAhead.actions.isAllowed(editorView.state))
74
- })
75
- });
76
- },
77
- actions: {
78
- openTypeAhead(inputMethod) {
79
- var _api$typeAhead2, _api$typeAhead2$actio;
80
- return Boolean(api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.open({
81
- triggerHandler: typeAhead,
82
- inputMethod
83
- }));
84
- }
85
- },
86
- getSharedState(editorState) {
87
- if (!editorState) {
88
- return undefined;
89
- }
90
- const mentionPluginState = mentionPluginKey.getState(editorState);
91
- return {
92
- ...mentionPluginState,
93
- typeAheadHandler: typeAhead
94
- };
95
- },
96
- pluginsOptions: {
97
- quickInsert: ({
98
- formatMessage
99
- }) => [{
100
- id: 'mention',
101
- title: formatMessage(messages.mention),
102
- description: formatMessage(messages.mentionDescription),
103
- keywords: ['team', 'user'],
104
- priority: 400,
105
- keyshortcut: '@',
106
- icon: () => /*#__PURE__*/React.createElement(IconMention, null),
107
- action(insert, state) {
108
- const tr = insert(undefined);
109
- const pluginState = mentionPluginKey.getState(state);
110
- if (pluginState && pluginState.canInsertMention === false) {
111
- return false;
112
- }
113
- api === null || api === void 0 ? void 0 : api.typeAhead.actions.openAtTransaction({
114
- triggerHandler: typeAhead,
115
- inputMethod: INPUT_METHOD.QUICK_INSERT
116
- })(tr);
117
- return tr;
118
- }
119
- }],
120
- typeAhead
121
- }
122
- };
123
- };
124
- export default mentionsPlugin;
@@ -1,23 +0,0 @@
1
- import { defineMessages } from 'react-intl-next';
2
- export const messages = defineMessages({
3
- inviteItemTitle: {
4
- id: 'fabric.editor.inviteItem.title',
5
- defaultMessage: '{userRole, select, admin {Invite} trusted {Invite} other {Add}} teammate to {productName}',
6
- description: 'Title of the invite teammate item in typeahead plugin'
7
- },
8
- mentionsAddLabel: {
9
- id: 'fabric.editor.mentionsAddLabel',
10
- defaultMessage: 'add-icon',
11
- description: 'icon label to describe adding a new mention'
12
- },
13
- mentionsIconLabel: {
14
- id: 'fabric.editor.mentionsIconLabel',
15
- defaultMessage: 'Mention',
16
- description: 'icon label to describe the mention icon'
17
- },
18
- mentionsNodeLabel: {
19
- id: 'fabric.editor.mentionNode.label',
20
- defaultMessage: 'Tagged user',
21
- description: 'Label to indicate mention node to Screen reader users, that preceeds with user name ex: "Tagged user @XXX'
22
- }
23
- });
@@ -1,80 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import { WithProviders } from '@atlaskit/editor-common/provider-factory';
3
- import Mention from '../ui/Mention';
4
- import { useIntl } from 'react-intl-next';
5
- import { messages } from '../messages';
6
- import { isResolvingMentionProvider, MentionNameStatus } from '@atlaskit/mention';
7
- import { isPromise } from '@atlaskit/mention/types';
8
- const UNKNOWN_USER_ID = '_|unknown|_';
9
- const MentionAssistiveTextComponent = ({
10
- id,
11
- text,
12
- providers,
13
- accessLevel,
14
- mentionProvider
15
- }) => {
16
- const [resolvedName, setResolvedName] = useState(text);
17
- const intl = useIntl();
18
- const processName = name => {
19
- if (name.status === MentionNameStatus.OK) {
20
- return `@${name.name || ''}`;
21
- } else {
22
- return `@${UNKNOWN_USER_ID}`;
23
- }
24
- };
25
- useEffect(() => {
26
- if (mentionProvider) {
27
- mentionProvider.then(async provider => {
28
- if (!text && isResolvingMentionProvider(provider)) {
29
- const nameDetail = provider.resolveMentionName(id);
30
- if (isPromise(nameDetail)) {
31
- return processName(await nameDetail);
32
- } else {
33
- return processName(nameDetail);
34
- }
35
- } else {
36
- return text;
37
- }
38
- }).then(resolvedName => {
39
- setResolvedName(resolvedName);
40
- });
41
- }
42
- }, [id, text, mentionProvider]);
43
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
44
- className: 'assistive'
45
- }, `${intl.formatMessage(messages.mentionsNodeLabel)} ${resolvedName}`), /*#__PURE__*/React.createElement("span", {
46
- "aria-hidden": "true"
47
- }, /*#__PURE__*/React.createElement(Mention, {
48
- id: id,
49
- text: resolvedName,
50
- accessLevel: accessLevel,
51
- providers: providers
52
- })));
53
- };
54
- export const MentionNodeView = props => {
55
- const {
56
- providerFactory
57
- } = props;
58
- const {
59
- id,
60
- text,
61
- accessLevel
62
- } = props.node.attrs;
63
- const renderAssistiveTextWithProviders = providers => {
64
- const {
65
- mentionProvider
66
- } = providers;
67
- return /*#__PURE__*/React.createElement(MentionAssistiveTextComponent, {
68
- mentionProvider: mentionProvider,
69
- id: id,
70
- text: text,
71
- providers: providerFactory,
72
- accessLevel: accessLevel
73
- });
74
- };
75
- return /*#__PURE__*/React.createElement(WithProviders, {
76
- providers: ['mentionProvider', 'profilecardProvider'],
77
- providerFactory: providerFactory,
78
- renderNode: renderAssistiveTextWithProviders
79
- });
80
- };
@@ -1,2 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const mentionPluginKey = new PluginKey('mentionPlugin');
@@ -1,143 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { SLI_EVENT_TYPE, SMART_EVENT_TYPE, buildSliPayload } from '@atlaskit/mention/resource';
3
- import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
4
- import { MentionNodeView } from '../nodeviews/mention';
5
- import { mentionPluginKey } from './key';
6
- import { canMentionBeCreatedInRange } from './utils';
7
- const ACTIONS = {
8
- SET_PROVIDER: 'SET_PROVIDER',
9
- SET_CONTEXT: 'SET_CONTEXT'
10
- };
11
- const setProvider = provider => (state, dispatch) => {
12
- if (dispatch) {
13
- dispatch(state.tr.setMeta(mentionPluginKey, {
14
- action: ACTIONS.SET_PROVIDER,
15
- params: {
16
- provider
17
- }
18
- }));
19
- }
20
- return true;
21
- };
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
- export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
34
- let mentionProvider;
35
- const sendAnalytics = (event, actionSubject, action, attributes) => {
36
- if (event === SLI_EVENT_TYPE || event === SMART_EVENT_TYPE) {
37
- fireEvent(buildSliPayload(actionSubject, action, attributes));
38
- }
39
- };
40
- return new SafePlugin({
41
- key: mentionPluginKey,
42
- state: {
43
- init(_, state) {
44
- const canInsertMention = canMentionBeCreatedInRange(state.selection.from, state.selection.to)(state);
45
- return {
46
- canInsertMention
47
- };
48
- },
49
- apply(tr, pluginState, oldState, newState) {
50
- const {
51
- action,
52
- params
53
- } = tr.getMeta(mentionPluginKey) || {
54
- action: null,
55
- params: null
56
- };
57
- let hasNewPluginState = false;
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
- }
67
- switch (action) {
68
- case ACTIONS.SET_PROVIDER:
69
- newPluginState = {
70
- ...newPluginState,
71
- mentionProvider: params.provider
72
- };
73
- hasNewPluginState = true;
74
- break;
75
- case ACTIONS.SET_CONTEXT:
76
- newPluginState = {
77
- ...newPluginState,
78
- contextIdentifierProvider: params.context
79
- };
80
- hasNewPluginState = true;
81
- break;
82
- }
83
- if (hasNewPluginState) {
84
- pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
85
- }
86
- return newPluginState;
87
- }
88
- },
89
- props: {
90
- nodeViews: {
91
- mention: getInlineNodeViewProducer({
92
- pmPluginFactoryParams,
93
- Component: MentionNodeView,
94
- extraComponentProps: {
95
- providerFactory: pmPluginFactoryParams.providerFactory,
96
- options
97
- }
98
- })
99
- }
100
- },
101
- view(editorView) {
102
- const providerHandler = (name, providerPromise) => {
103
- switch (name) {
104
- case 'mentionProvider':
105
- if (!providerPromise) {
106
- return setProvider(undefined)(editorView.state, editorView.dispatch);
107
- }
108
- providerPromise.then(provider => {
109
- if (mentionProvider) {
110
- mentionProvider.unsubscribe('mentionPlugin');
111
- }
112
- mentionProvider = provider;
113
- setProvider(provider)(editorView.state, editorView.dispatch);
114
- provider.subscribe('mentionPlugin', undefined, undefined, undefined, undefined, sendAnalytics);
115
- }).catch(() => setProvider(undefined)(editorView.state, editorView.dispatch));
116
- 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
- }
126
- return;
127
- };
128
- pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
129
- pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
130
- return {
131
- destroy() {
132
- if (pmPluginFactoryParams.providerFactory) {
133
- pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
134
- pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
135
- }
136
- if (mentionProvider) {
137
- mentionProvider.unsubscribe('mentionPlugin');
138
- }
139
- }
140
- };
141
- }
142
- });
143
- }
@@ -1,14 +0,0 @@
1
- import { mentionPluginKey } from './key';
2
- import { canInsert } from '@atlaskit/editor-prosemirror/utils';
3
- export function getMentionPluginState(state) {
4
- return mentionPluginKey.getState(state);
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
- };