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