@atlaskit/editor-core 190.1.19 → 190.1.23

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 (123) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/create-editor/ErrorBoundary.js +9 -5
  4. package/dist/cjs/index.js +1 -1
  5. package/dist/cjs/plugins/index.js +0 -7
  6. package/dist/cjs/plugins/paste/pm-plugins/main.js +14 -10
  7. package/dist/cjs/presets/default.js +2 -2
  8. package/dist/cjs/presets/universal.js +2 -1
  9. package/dist/cjs/utils/index.js +12 -18
  10. package/dist/cjs/utils/performance/measure-enum.js +1 -2
  11. package/dist/cjs/version-wrapper.js +1 -1
  12. package/dist/es2019/create-editor/ErrorBoundary.js +10 -7
  13. package/dist/es2019/index.js +14 -1
  14. package/dist/es2019/plugins/index.js +0 -1
  15. package/dist/es2019/plugins/paste/pm-plugins/main.js +11 -5
  16. package/dist/es2019/presets/default.js +1 -1
  17. package/dist/es2019/presets/universal.js +2 -1
  18. package/dist/es2019/utils/index.js +0 -7
  19. package/dist/es2019/utils/performance/measure-enum.js +1 -2
  20. package/dist/es2019/version-wrapper.js +1 -1
  21. package/dist/esm/create-editor/ErrorBoundary.js +10 -7
  22. package/dist/esm/index.js +14 -1
  23. package/dist/esm/plugins/index.js +0 -1
  24. package/dist/esm/plugins/paste/pm-plugins/main.js +9 -5
  25. package/dist/esm/presets/default.js +1 -1
  26. package/dist/esm/presets/universal.js +2 -1
  27. package/dist/esm/utils/index.js +0 -5
  28. package/dist/esm/utils/performance/measure-enum.js +1 -2
  29. package/dist/esm/version-wrapper.js +1 -1
  30. package/dist/types/index.d.ts +15 -2
  31. package/dist/types/plugins/index.d.ts +0 -1
  32. package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -0
  33. package/dist/types/presets/default.d.ts +1 -1
  34. package/dist/types/types/editor-props.d.ts +1 -1
  35. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  36. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  37. package/dist/types/utils/index.d.ts +0 -1
  38. package/dist/types/utils/performance/measure-enum.d.ts +0 -1
  39. package/dist/types-ts4.5/index.d.ts +15 -2
  40. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  41. package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +2 -0
  42. package/dist/types-ts4.5/presets/default.d.ts +1 -1
  43. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  44. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  45. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  46. package/dist/types-ts4.5/utils/index.d.ts +0 -1
  47. package/dist/types-ts4.5/utils/performance/measure-enum.d.ts +0 -1
  48. package/package.json +10 -4
  49. package/dist/cjs/plugins/annotation/commands/index.js +0 -150
  50. package/dist/cjs/plugins/annotation/commands/transform.js +0 -86
  51. package/dist/cjs/plugins/annotation/index.js +0 -130
  52. package/dist/cjs/plugins/annotation/nodeviews/index.js +0 -59
  53. package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +0 -243
  54. package/dist/cjs/plugins/annotation/pm-plugins/keymap.js +0 -15
  55. package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +0 -107
  56. package/dist/cjs/plugins/annotation/pm-plugins/reducer.js +0 -84
  57. package/dist/cjs/plugins/annotation/pm-plugins/types.js +0 -17
  58. package/dist/cjs/plugins/annotation/toolbar.js +0 -59
  59. package/dist/cjs/plugins/annotation/types.js +0 -20
  60. package/dist/cjs/plugins/annotation/ui/AnnotationViewWrapper.js +0 -38
  61. package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +0 -149
  62. package/dist/cjs/plugins/annotation/update-provider.js +0 -36
  63. package/dist/cjs/plugins/annotation/utils.js +0 -372
  64. package/dist/es2019/plugins/annotation/commands/index.js +0 -123
  65. package/dist/es2019/plugins/annotation/commands/transform.js +0 -64
  66. package/dist/es2019/plugins/annotation/index.js +0 -125
  67. package/dist/es2019/plugins/annotation/nodeviews/index.js +0 -31
  68. package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +0 -178
  69. package/dist/es2019/plugins/annotation/pm-plugins/keymap.js +0 -9
  70. package/dist/es2019/plugins/annotation/pm-plugins/plugin-factory.js +0 -108
  71. package/dist/es2019/plugins/annotation/pm-plugins/reducer.js +0 -94
  72. package/dist/es2019/plugins/annotation/pm-plugins/types.js +0 -11
  73. package/dist/es2019/plugins/annotation/toolbar.js +0 -53
  74. package/dist/es2019/plugins/annotation/types.js +0 -14
  75. package/dist/es2019/plugins/annotation/ui/AnnotationViewWrapper.js +0 -14
  76. package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +0 -147
  77. package/dist/es2019/plugins/annotation/update-provider.js +0 -9
  78. package/dist/es2019/plugins/annotation/utils.js +0 -334
  79. package/dist/esm/plugins/annotation/commands/index.js +0 -143
  80. package/dist/esm/plugins/annotation/commands/transform.js +0 -80
  81. package/dist/esm/plugins/annotation/index.js +0 -118
  82. package/dist/esm/plugins/annotation/nodeviews/index.js +0 -52
  83. package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +0 -236
  84. package/dist/esm/plugins/annotation/pm-plugins/keymap.js +0 -9
  85. package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +0 -101
  86. package/dist/esm/plugins/annotation/pm-plugins/reducer.js +0 -77
  87. package/dist/esm/plugins/annotation/pm-plugins/types.js +0 -11
  88. package/dist/esm/plugins/annotation/toolbar.js +0 -52
  89. package/dist/esm/plugins/annotation/types.js +0 -14
  90. package/dist/esm/plugins/annotation/ui/AnnotationViewWrapper.js +0 -31
  91. package/dist/esm/plugins/annotation/ui/InlineCommentView.js +0 -144
  92. package/dist/esm/plugins/annotation/update-provider.js +0 -29
  93. package/dist/esm/plugins/annotation/utils.js +0 -345
  94. package/dist/types/plugins/annotation/commands/index.d.ts +0 -15
  95. package/dist/types/plugins/annotation/commands/transform.d.ts +0 -11
  96. package/dist/types/plugins/annotation/index.d.ts +0 -15
  97. package/dist/types/plugins/annotation/nodeviews/index.d.ts +0 -11
  98. package/dist/types/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  99. package/dist/types/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  100. package/dist/types/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  101. package/dist/types/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  102. package/dist/types/plugins/annotation/pm-plugins/types.d.ts +0 -78
  103. package/dist/types/plugins/annotation/toolbar.d.ts +0 -5
  104. package/dist/types/plugins/annotation/types.d.ts +0 -86
  105. package/dist/types/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  106. package/dist/types/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  107. package/dist/types/plugins/annotation/update-provider.d.ts +0 -12
  108. package/dist/types/plugins/annotation/utils.d.ts +0 -45
  109. package/dist/types-ts4.5/plugins/annotation/commands/index.d.ts +0 -15
  110. package/dist/types-ts4.5/plugins/annotation/commands/transform.d.ts +0 -11
  111. package/dist/types-ts4.5/plugins/annotation/index.d.ts +0 -17
  112. package/dist/types-ts4.5/plugins/annotation/nodeviews/index.d.ts +0 -11
  113. package/dist/types-ts4.5/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  114. package/dist/types-ts4.5/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  115. package/dist/types-ts4.5/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  116. package/dist/types-ts4.5/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  117. package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +0 -78
  118. package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +0 -5
  119. package/dist/types-ts4.5/plugins/annotation/types.d.ts +0 -86
  120. package/dist/types-ts4.5/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  121. package/dist/types-ts4.5/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  122. package/dist/types-ts4.5/plugins/annotation/update-provider.d.ts +0 -12
  123. package/dist/types-ts4.5/plugins/annotation/utils.d.ts +0 -45
@@ -1,80 +0,0 @@
1
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { AnnotationTypes } from '@atlaskit/adf-schema';
3
- import { ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
- import { getSelectionPositions, getPluginState, getDraftCommandAnalyticsPayload } from '../utils';
5
- import { applyMarkOnRange } from '@atlaskit/editor-common/mark';
6
- var addAnnotationMark = function addAnnotationMark(id) {
7
- return function (transaction, state) {
8
- var inlineCommentState = getPluginState(state);
9
- var _getSelectionPosition = getSelectionPositions(state, inlineCommentState),
10
- from = _getSelectionPosition.from,
11
- to = _getSelectionPosition.to,
12
- head = _getSelectionPosition.head;
13
- var annotationMark = state.schema.marks.annotation.create({
14
- id: id,
15
- type: AnnotationTypes.INLINE_COMMENT
16
- });
17
- // Apply the mark only to text node in the range.
18
- var tr = applyMarkOnRange(from, to, false, annotationMark, transaction);
19
- // set selection back to the end of annotation once annotation mark is applied
20
- tr.setSelection(TextSelection.create(tr.doc, head));
21
- return tr;
22
- };
23
- };
24
- var addInlineComment = function addInlineComment(editorAnalyticsAPI) {
25
- return function (id) {
26
- return function (transaction, state) {
27
- var tr = addAnnotationMark(id)(transaction, state);
28
- // add insert analytics step to transaction
29
- tr = addInsertAnalytics(editorAnalyticsAPI)(tr, state);
30
- // add close analytics step to transaction
31
- tr = addOpenCloseAnalytics(editorAnalyticsAPI)(false, INPUT_METHOD.TOOLBAR)(tr, state);
32
- return tr;
33
- };
34
- };
35
- };
36
- var addOpenCloseAnalytics = function addOpenCloseAnalytics(editorAnalyticsAPI) {
37
- return function (drafting) {
38
- var method = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : INPUT_METHOD.TOOLBAR;
39
- return function (transaction, state) {
40
- var draftingPayload = getDraftCommandAnalyticsPayload(drafting, method)(state);
41
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(draftingPayload)(transaction);
42
- return transaction;
43
- };
44
- };
45
- };
46
- var addInsertAnalytics = function addInsertAnalytics(editorAnalyticsAPI) {
47
- return function (transaction, state) {
48
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({
49
- action: ACTION.INSERTED,
50
- actionSubject: ACTION_SUBJECT.ANNOTATION,
51
- eventType: EVENT_TYPE.TRACK,
52
- actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT
53
- })(transaction);
54
- return transaction;
55
- };
56
- };
57
- var addResolveAnalytics = function addResolveAnalytics(editorAnalyticsAPI) {
58
- return function (method) {
59
- return function (transaction, state) {
60
- var resolvedPayload = {
61
- action: ACTION.RESOLVED,
62
- actionSubject: ACTION_SUBJECT.ANNOTATION,
63
- actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
64
- eventType: EVENT_TYPE.TRACK,
65
- attributes: {
66
- method: method
67
- }
68
- };
69
- editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(resolvedPayload)(transaction);
70
- return transaction;
71
- };
72
- };
73
- };
74
- export default {
75
- addAnnotationMark: addAnnotationMark,
76
- addInlineComment: addInlineComment,
77
- addOpenCloseAnalytics: addOpenCloseAnalytics,
78
- addInsertAnalytics: addInsertAnalytics,
79
- addResolveAnalytics: addResolveAnalytics
80
- };
@@ -1,118 +0,0 @@
1
- import React from 'react';
2
- import { annotation } from '@atlaskit/adf-schema';
3
- import { keymapPlugin } from './pm-plugins/keymap';
4
- import { inlineCommentPlugin } from './pm-plugins/inline-comment';
5
- import { AnnotationUpdateEmitter } from './update-provider';
6
- import { getPluginState } from './utils';
7
- import { buildToolbar } from './toolbar';
8
- import { InlineCommentView } from './ui/InlineCommentView';
9
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
10
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
- var annotationPlugin = function annotationPlugin(_ref) {
12
- var annotationProviders = _ref.config,
13
- api = _ref.api;
14
- return {
15
- name: 'annotation',
16
- marks: function marks() {
17
- return [{
18
- name: 'annotation',
19
- mark: annotation
20
- }];
21
- },
22
- getSharedState: function getSharedState(editorState) {
23
- if (!editorState) {
24
- return undefined;
25
- }
26
- return getPluginState(editorState) || undefined;
27
- },
28
- pmPlugins: function pmPlugins() {
29
- return [{
30
- name: 'annotation',
31
- plugin: function plugin(_ref2) {
32
- var dispatch = _ref2.dispatch,
33
- portalProviderAPI = _ref2.portalProviderAPI,
34
- eventDispatcher = _ref2.eventDispatcher;
35
- if (annotationProviders) {
36
- var _api$analytics;
37
- return inlineCommentPlugin({
38
- dispatch: dispatch,
39
- portalProviderAPI: portalProviderAPI,
40
- eventDispatcher: eventDispatcher,
41
- provider: annotationProviders.inlineComment,
42
- editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
43
- });
44
- }
45
- return;
46
- }
47
- }, {
48
- name: 'annotationKeymap',
49
- plugin: function plugin() {
50
- if (annotationProviders) {
51
- var _api$analytics2;
52
- return keymapPlugin(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
53
- }
54
- return;
55
- }
56
- }];
57
- },
58
- pluginsOptions: {
59
- floatingToolbar: function floatingToolbar(state, intl) {
60
- if (getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd') || !annotationProviders) {
61
- return;
62
- }
63
- var pluginState = getPluginState(state);
64
- if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
65
- var _api$analytics3;
66
- var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
67
- return buildToolbar(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions)(state, intl, isToolbarAbove);
68
- }
69
- },
70
- selectionToolbar: function selectionToolbar(state, intl) {
71
- if (!getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd') || !annotationProviders) {
72
- return;
73
- }
74
- var pluginState = getPluginState(state);
75
- if (pluginState && pluginState.isVisible && !pluginState.bookmark && !pluginState.mouseData.isSelecting) {
76
- var _api$analytics4;
77
- var isToolbarAbove = annotationProviders.inlineComment.isToolbarAbove;
78
- return buildToolbar(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions)(state, intl, isToolbarAbove);
79
- }
80
- }
81
- },
82
- contentComponent: function contentComponent(_ref3) {
83
- var editorView = _ref3.editorView,
84
- dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
85
- if (!annotationProviders) {
86
- return null;
87
- }
88
- return /*#__PURE__*/React.createElement(AnnotationContentComponent, {
89
- api: api,
90
- editorView: editorView,
91
- annotationProviders: annotationProviders,
92
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
93
- });
94
- }
95
- };
96
- };
97
- function AnnotationContentComponent(_ref4) {
98
- var _api$analytics5;
99
- var api = _ref4.api,
100
- editorView = _ref4.editorView,
101
- annotationProviders = _ref4.annotationProviders,
102
- dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
103
- var _useSharedPluginState = useSharedPluginState(api, ['annotation']),
104
- inlineCommentState = _useSharedPluginState.annotationState;
105
- if (inlineCommentState && !inlineCommentState.isVisible) {
106
- return null;
107
- }
108
- return /*#__PURE__*/React.createElement("div", {
109
- "data-editor-popup": "true"
110
- }, /*#__PURE__*/React.createElement(InlineCommentView, {
111
- providers: annotationProviders,
112
- editorView: editorView,
113
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
114
- editorAnalyticsAPI: api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions
115
- }));
116
- }
117
- export default annotationPlugin;
118
- export { AnnotationUpdateEmitter };
@@ -1,52 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
7
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
8
- import React from 'react';
9
- import { AnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
10
- import ReactNodeView from '@atlaskit/editor-common/react-node-view';
11
- export var AnnotationNodeView = /*#__PURE__*/function (_ReactNodeView) {
12
- _inherits(AnnotationNodeView, _ReactNodeView);
13
- var _super = _createSuper(AnnotationNodeView);
14
- function AnnotationNodeView() {
15
- _classCallCheck(this, AnnotationNodeView);
16
- return _super.apply(this, arguments);
17
- }
18
- _createClass(AnnotationNodeView, [{
19
- key: "createDomRef",
20
- value: function createDomRef() {
21
- return document.createElement('span');
22
- }
23
- }, {
24
- key: "getContentDOM",
25
- value: function getContentDOM() {
26
- var dom = document.createElement('span');
27
- dom.className = 'ak-editor-annotation';
28
- return {
29
- dom: dom
30
- };
31
- }
32
- }, {
33
- key: "render",
34
- value: function render(_props, forwardRef) {
35
- return (
36
- /*#__PURE__*/
37
- // all inline comment states are now set in decorations at ../pm-plugins/inline-comment.ts
38
- React.createElement("span", {
39
- "data-mark-type": "annotation",
40
- ref: forwardRef
41
- })
42
- );
43
- }
44
- }]);
45
- return AnnotationNodeView;
46
- }(ReactNodeView);
47
- export var getAnnotationViewClassname = function getAnnotationViewClassname(isUnresolved, hasFocus) {
48
- if (!isUnresolved) {
49
- return;
50
- }
51
- return hasFocus ? AnnotationSharedClassNames.focus : AnnotationSharedClassNames.blur;
52
- };
@@ -1,236 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
5
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
- import { AnnotationTypes } from '@atlaskit/adf-schema';
8
- import { AnnotationNodeView, getAnnotationViewClassname } from '../nodeviews';
9
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
10
- import { updateInlineCommentResolvedState, updateMouseState, clearDirtyMark, setInlineCommentsVisibility, setSelectedAnnotation, closeComponent } from '../commands';
11
- import { getAllAnnotations, inlineCommentPluginKey, getPluginState } from '../utils';
12
- import { createPluginState } from './plugin-factory';
13
- var fetchProviderStates = /*#__PURE__*/function () {
14
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(provider, annotationIds) {
15
- var data, result;
16
- return _regeneratorRuntime.wrap(function _callee$(_context) {
17
- while (1) switch (_context.prev = _context.next) {
18
- case 0:
19
- _context.next = 2;
20
- return provider.getState(annotationIds);
21
- case 2:
22
- data = _context.sent;
23
- result = {};
24
- data.forEach(function (annotation) {
25
- if (annotation.annotationType === AnnotationTypes.INLINE_COMMENT) {
26
- result[annotation.id] = annotation.state.resolved;
27
- }
28
- });
29
- return _context.abrupt("return", result);
30
- case 6:
31
- case "end":
32
- return _context.stop();
33
- }
34
- }, _callee);
35
- }));
36
- return function fetchProviderStates(_x, _x2) {
37
- return _ref.apply(this, arguments);
38
- };
39
- }();
40
-
41
- // fetchState is unable to return a command as it's runs async and may dispatch at a later time
42
- // Requires `editorView` instead of the decomposition as the async means state may end up stale
43
- var fetchState = /*#__PURE__*/function () {
44
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(provider, annotationIds, editorView, editorAnalyticsAPI) {
45
- var inlineCommentStates;
46
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
47
- while (1) switch (_context2.prev = _context2.next) {
48
- case 0:
49
- if (!(!annotationIds || !annotationIds.length)) {
50
- _context2.next = 2;
51
- break;
52
- }
53
- return _context2.abrupt("return");
54
- case 2:
55
- _context2.next = 4;
56
- return fetchProviderStates(provider, annotationIds);
57
- case 4:
58
- inlineCommentStates = _context2.sent;
59
- if (editorView.dispatch) {
60
- updateInlineCommentResolvedState(editorAnalyticsAPI)(inlineCommentStates)(editorView.state, editorView.dispatch);
61
- }
62
- case 6:
63
- case "end":
64
- return _context2.stop();
65
- }
66
- }, _callee2);
67
- }));
68
- return function fetchState(_x3, _x4, _x5, _x6) {
69
- return _ref2.apply(this, arguments);
70
- };
71
- }();
72
- var initialState = function initialState() {
73
- var disallowOnWhitespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
74
- return {
75
- annotations: {},
76
- selectedAnnotations: [],
77
- mouseData: {
78
- isSelecting: false
79
- },
80
- disallowOnWhitespace: disallowOnWhitespace,
81
- isInlineCommentViewClosed: false,
82
- isVisible: true,
83
- skipSelectionHandling: false
84
- };
85
- };
86
- var hideToolbar = function hideToolbar(state, dispatch) {
87
- return function () {
88
- updateMouseState({
89
- isSelecting: true
90
- })(state, dispatch);
91
- };
92
- };
93
-
94
- // Subscribe to updates from consumer
95
- var onResolve = function onResolve(editorAnalyticsAPI) {
96
- return function (state, dispatch) {
97
- return function (annotationId) {
98
- updateInlineCommentResolvedState(editorAnalyticsAPI)(_defineProperty({}, annotationId, true), RESOLVE_METHOD.CONSUMER)(state, dispatch);
99
- };
100
- };
101
- };
102
- var onUnResolve = function onUnResolve(editorAnalyticsAPI) {
103
- return function (state, dispatch) {
104
- return function (annotationId) {
105
- updateInlineCommentResolvedState(editorAnalyticsAPI)(_defineProperty({}, annotationId, false))(state, dispatch);
106
- };
107
- };
108
- };
109
- var onMouseUp = function onMouseUp(state, dispatch) {
110
- return function (e) {
111
- var _ref3 = getPluginState(state) || {},
112
- mouseData = _ref3.mouseData;
113
- if (mouseData !== null && mouseData !== void 0 && mouseData.isSelecting) {
114
- updateMouseState({
115
- isSelecting: false
116
- })(state, dispatch);
117
- }
118
- };
119
- };
120
- var onSetVisibility = function onSetVisibility(view) {
121
- return function (isVisible) {
122
- var state = view.state,
123
- dispatch = view.dispatch;
124
- setInlineCommentsVisibility(isVisible)(state, dispatch);
125
- if (isVisible) {
126
- // PM retains focus when we click away from the editor.
127
- // This will restore the visual aspect of the selection,
128
- // otherwise it will seem a floating toolbar will appear
129
- // for no reason.
130
- view.focus();
131
- }
132
- };
133
- };
134
- export var inlineCommentPlugin = function inlineCommentPlugin(options) {
135
- var provider = options.provider,
136
- portalProviderAPI = options.portalProviderAPI,
137
- eventDispatcher = options.eventDispatcher;
138
- return new SafePlugin({
139
- key: inlineCommentPluginKey,
140
- state: createPluginState(options.dispatch, initialState(provider.disallowOnWhitespace)),
141
- view: function view(editorView) {
142
- // Get initial state
143
- // Need to pass `editorView` to mitigate editor state going stale
144
- fetchState(provider, getAllAnnotations(editorView.state.doc), editorView, options.editorAnalyticsAPI);
145
- var resolve = function resolve(annotationId) {
146
- return onResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
147
- };
148
- var unResolve = function unResolve(annotationId) {
149
- return onUnResolve(options.editorAnalyticsAPI)(editorView.state, editorView.dispatch)(annotationId);
150
- };
151
- var mouseUp = function mouseUp(event) {
152
- return onMouseUp(editorView.state, editorView.dispatch)(event);
153
- };
154
- var setVisibility = function setVisibility(isVisible) {
155
- return onSetVisibility(editorView)(isVisible);
156
- };
157
- var setSelectedAnnotationFn = function setSelectedAnnotationFn(annotationId) {
158
- if (!annotationId) {
159
- closeComponent()(editorView.state, editorView.dispatch);
160
- } else {
161
- setSelectedAnnotation(annotationId)(editorView.state, editorView.dispatch);
162
- }
163
- };
164
- var updateSubscriber = provider.updateSubscriber;
165
- if (updateSubscriber) {
166
- updateSubscriber.on('resolve', resolve).on('delete', resolve).on('unresolve', unResolve).on('create', unResolve).on('setvisibility', setVisibility).on('setselectedannotation', setSelectedAnnotationFn);
167
- }
168
- editorView.root.addEventListener('mouseup', mouseUp);
169
- return {
170
- update: function update(view, _prevState) {
171
- var _ref4 = getPluginState(view.state) || {},
172
- dirtyAnnotations = _ref4.dirtyAnnotations;
173
- if (!dirtyAnnotations) {
174
- return;
175
- }
176
- clearDirtyMark()(view.state, view.dispatch);
177
- fetchState(provider, getAllAnnotations(view.state.doc), view, options.editorAnalyticsAPI);
178
- },
179
- destroy: function destroy() {
180
- editorView.root.removeEventListener('mouseup', mouseUp);
181
- if (updateSubscriber) {
182
- updateSubscriber.off('resolve', resolve).off('delete', resolve).off('unresolve', unResolve).off('create', unResolve).off('setvisibility', setVisibility).off('setselectedannotation', setSelectedAnnotationFn);
183
- }
184
- }
185
- };
186
- },
187
- props: {
188
- nodeViews: {
189
- annotation: function annotation(node, view, getPos) {
190
- return new AnnotationNodeView(node, view, getPos, portalProviderAPI, eventDispatcher) // resolved
191
- .init();
192
- }
193
- },
194
- handleDOMEvents: {
195
- mousedown: function mousedown(view) {
196
- var pluginState = getPluginState(view.state);
197
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.mouseData.isSelecting)) {
198
- hideToolbar(view.state, view.dispatch)();
199
- }
200
- return false;
201
- }
202
- },
203
- decorations: function decorations(state) {
204
- // highlight comments, depending on state
205
- var _ref5 = getPluginState(state) || {},
206
- draftDecorationSet = _ref5.draftDecorationSet,
207
- annotations = _ref5.annotations,
208
- selectedAnnotations = _ref5.selectedAnnotations,
209
- isVisible = _ref5.isVisible,
210
- isInlineCommentViewClosed = _ref5.isInlineCommentViewClosed;
211
- var decorations = draftDecorationSet !== null && draftDecorationSet !== void 0 ? draftDecorationSet : DecorationSet.empty;
212
- var focusDecorations = [];
213
- state.doc.descendants(function (node, pos) {
214
- node.marks.filter(function (mark) {
215
- return mark.type === state.schema.marks.annotation;
216
- }).forEach(function (mark) {
217
- var isSelected = getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? !isInlineCommentViewClosed && !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
218
- return selectedAnnotation.id === mark.attrs.id;
219
- })) : !!(selectedAnnotations !== null && selectedAnnotations !== void 0 && selectedAnnotations.some(function (selectedAnnotation) {
220
- return selectedAnnotation.id === mark.attrs.id;
221
- }));
222
- var isUnresolved = !!annotations && annotations[mark.attrs.id] === false;
223
- if (isVisible) {
224
- focusDecorations.push(Decoration.inline(pos, pos + node.nodeSize, {
225
- class: "".concat(getAnnotationViewClassname(isUnresolved, isSelected), " ").concat(isUnresolved),
226
- nodeName: 'span'
227
- }));
228
- }
229
- });
230
- });
231
- decorations = decorations.add(state.doc, focusDecorations);
232
- return decorations;
233
- }
234
- }
235
- });
236
- };
@@ -1,9 +0,0 @@
1
- import { keymap } from '@atlaskit/editor-prosemirror/keymap';
2
- import { bindKeymapWithCommand, addInlineComment } from '../../../keymaps';
3
- import { setInlineCommentDraftState } from '../commands';
4
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
- export function keymapPlugin(editorAnalyticsAPI) {
6
- var list = {};
7
- bindKeymapWithCommand(addInlineComment.common, setInlineCommentDraftState(editorAnalyticsAPI)(true, INPUT_METHOD.SHORTCUT), list);
8
- return keymap(list);
9
- }
@@ -1,101 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- 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; }
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
- import { pluginFactory } from '../../../utils/plugin-state-factory';
5
- import { findAnnotationsInSelection, inlineCommentPluginKey, isSelectedAnnotationsChanged } from '../utils';
6
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
- import reducer from './reducer';
8
- var handleDocChanged = function handleDocChanged(tr, prevPluginState) {
9
- if (!tr.getMeta('replaceDocument')) {
10
- return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? getSelectionChangedHandler(false)(tr, prevPluginState) : handleSelectionChanged(tr, prevPluginState);
11
- }
12
- return _objectSpread(_objectSpread({}, prevPluginState), {}, {
13
- dirtyAnnotations: true
14
- });
15
- };
16
- var handleSelectionChanged = function handleSelectionChanged(tr, pluginState) {
17
- if (pluginState.skipSelectionHandling) {
18
- return _objectSpread(_objectSpread({}, pluginState), {}, {
19
- skipSelectionHandling: false
20
- });
21
- }
22
- var selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
23
- var changed = selectedAnnotations.length !== pluginState.selectedAnnotations.length || selectedAnnotations.some(function (annotationInfo) {
24
- return !pluginState.selectedAnnotations.some(function (aInfo) {
25
- return aInfo.type === annotationInfo.id;
26
- });
27
- });
28
- if (changed) {
29
- return _objectSpread(_objectSpread({}, pluginState), {}, {
30
- selectedAnnotations: selectedAnnotations
31
- });
32
- }
33
- return pluginState;
34
- };
35
- var getSelectionChangedHandler = function getSelectionChangedHandler(reopenCommentView) {
36
- return function (tr, pluginState) {
37
- /**
38
- * If feature flag is **OFF** we want to keep the old behavior. Note that
39
- * reopenCommentView is not relevant here when using old behaviour.
40
- *
41
- * Feature flag is evaluated here rather than directly in onSelectionChanged where it is assigned
42
- * to prevent the plugin from setting up the handler before the feature flag is evaluated.
43
- *
44
- * This comment / logic can be cleaned up once the feature flag is removed.
45
- */
46
- if (!getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox')) {
47
- return handleSelectionChanged(tr, pluginState);
48
- }
49
- if (pluginState.skipSelectionHandling) {
50
- return _objectSpread(_objectSpread({}, pluginState), {}, {
51
- skipSelectionHandling: false
52
- }, reopenCommentView && {
53
- isInlineCommentViewClosed: false
54
- });
55
- }
56
- var selectedAnnotations = findAnnotationsInSelection(tr.selection, tr.doc);
57
- if (selectedAnnotations.length === 0) {
58
- return _objectSpread(_objectSpread({}, pluginState), {}, {
59
- selectedAnnotations: selectedAnnotations,
60
- isInlineCommentViewClosed: true
61
- });
62
- }
63
- if (isSelectedAnnotationsChanged(selectedAnnotations, pluginState.selectedAnnotations)) {
64
- return _objectSpread(_objectSpread({}, pluginState), {}, {
65
- selectedAnnotations: selectedAnnotations
66
- }, reopenCommentView && {
67
- isInlineCommentViewClosed: false
68
- });
69
- }
70
- return _objectSpread(_objectSpread({}, pluginState), reopenCommentView && {
71
- isInlineCommentViewClosed: false
72
- });
73
- };
74
- };
75
- var _pluginFactory = pluginFactory(inlineCommentPluginKey, reducer, {
76
- onSelectionChanged: getSelectionChangedHandler(true),
77
- onDocChanged: handleDocChanged,
78
- mapping: function mapping(tr, pluginState) {
79
- var draftDecorationSet = pluginState.draftDecorationSet,
80
- bookmark = pluginState.bookmark;
81
- var mappedDecorationSet, mappedBookmark;
82
- if (draftDecorationSet) {
83
- mappedDecorationSet = draftDecorationSet.map(tr.mapping, tr.doc);
84
- }
85
- if (bookmark) {
86
- mappedBookmark = bookmark.map(tr.mapping);
87
- }
88
-
89
- // return same pluginState if mappings did not change
90
- if (mappedBookmark === bookmark && mappedDecorationSet === draftDecorationSet) {
91
- return pluginState;
92
- }
93
- return _objectSpread(_objectSpread({}, pluginState), {}, {
94
- draftDecorationSet: mappedDecorationSet,
95
- bookmark: mappedBookmark
96
- });
97
- }
98
- }),
99
- createPluginState = _pluginFactory.createPluginState,
100
- createCommand = _pluginFactory.createCommand;
101
- export { createPluginState, createCommand };
@@ -1,77 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- 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; }
4
- 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; }
5
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
- import { addDraftDecoration } from '../utils';
8
- import { ACTIONS } from './types';
9
- export default (function (pluginState, action) {
10
- switch (action.type) {
11
- case ACTIONS.UPDATE_INLINE_COMMENT_STATE:
12
- return _objectSpread(_objectSpread({}, pluginState), {}, {
13
- annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data)
14
- });
15
- case ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE:
16
- var mouseData = Object.assign({}, pluginState.mouseData, action.data.mouseData);
17
- return _objectSpread(_objectSpread({}, pluginState), {}, {
18
- mouseData: mouseData
19
- });
20
- case ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE:
21
- return getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
22
- case ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK:
23
- return _objectSpread(_objectSpread({}, pluginState), {}, {
24
- dirtyAnnotations: false,
25
- annotations: {}
26
- });
27
- case ACTIONS.CLOSE_COMPONENT:
28
- return getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') ? _objectSpread(_objectSpread({}, pluginState), {}, {
29
- isInlineCommentViewClosed: true
30
- }) : _objectSpread(_objectSpread({}, pluginState), {}, {
31
- selectedAnnotations: []
32
- });
33
- case ACTIONS.ADD_INLINE_COMMENT:
34
- var updatedPluginState = getNewDraftState(pluginState, action.data.drafting, action.data.editorState);
35
- return _objectSpread(_objectSpread({}, updatedPluginState), {}, {
36
- selectedAnnotations: [].concat(_toConsumableArray(updatedPluginState.selectedAnnotations), _toConsumableArray(action.data.selectedAnnotations)),
37
- annotations: _objectSpread(_objectSpread({}, pluginState.annotations), action.data.inlineComments)
38
- }, getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
39
- isInlineCommentViewClosed: false
40
- });
41
- case ACTIONS.INLINE_COMMENT_SET_VISIBLE:
42
- var isVisible = action.data.isVisible;
43
- if (isVisible === pluginState.isVisible) {
44
- return pluginState;
45
- }
46
- return _objectSpread(_objectSpread({}, isVisible ? pluginState : getNewDraftState(pluginState, false)), {}, {
47
- isVisible: isVisible
48
- });
49
- case ACTIONS.SET_SELECTED_ANNOTATION:
50
- return _objectSpread(_objectSpread({}, pluginState), {}, {
51
- selectedAnnotations: _toConsumableArray(action.data.selectedAnnotations),
52
- skipSelectionHandling: true
53
- }, getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && {
54
- // if selecting annotation explicitly, reopen the comment view
55
- isInlineCommentViewClosed: false
56
- });
57
- default:
58
- return pluginState;
59
- }
60
- });
61
- function getNewDraftState(pluginState, drafting, editorState) {
62
- var draftDecorationSet = pluginState.draftDecorationSet;
63
- if (!draftDecorationSet || !drafting) {
64
- draftDecorationSet = DecorationSet.empty;
65
- }
66
- var newState = _objectSpread(_objectSpread({}, pluginState), {}, {
67
- draftDecorationSet: draftDecorationSet
68
- });
69
- newState.bookmark = undefined;
70
- if (drafting && editorState) {
71
- newState.bookmark = editorState.selection.getBookmark();
72
- var resolvedBookmark = newState.bookmark.resolve(editorState.doc);
73
- var draftDecoration = addDraftDecoration(resolvedBookmark.from, resolvedBookmark.to);
74
- newState.draftDecorationSet = draftDecorationSet.add(editorState.doc, [draftDecoration]);
75
- }
76
- return newState;
77
- }