@atlaskit/editor-core 190.1.20 → 190.1.24

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 (126) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/composable-editor/editor-internal.js +11 -1
  4. package/dist/cjs/create-editor/ReactEditorView.js +6 -1
  5. package/dist/cjs/index.js +1 -1
  6. package/dist/cjs/plugins/index.js +0 -7
  7. package/dist/cjs/plugins/paste/pm-plugins/main.js +14 -10
  8. package/dist/cjs/presets/default.js +2 -2
  9. package/dist/cjs/presets/universal.js +2 -1
  10. package/dist/cjs/utils/index.js +12 -18
  11. package/dist/cjs/utils/performance/measure-enum.js +1 -2
  12. package/dist/cjs/version-wrapper.js +1 -1
  13. package/dist/es2019/composable-editor/editor-internal.js +11 -1
  14. package/dist/es2019/create-editor/ReactEditorView.js +6 -1
  15. package/dist/es2019/index.js +14 -1
  16. package/dist/es2019/plugins/index.js +0 -1
  17. package/dist/es2019/plugins/paste/pm-plugins/main.js +11 -5
  18. package/dist/es2019/presets/default.js +1 -1
  19. package/dist/es2019/presets/universal.js +2 -1
  20. package/dist/es2019/utils/index.js +0 -7
  21. package/dist/es2019/utils/performance/measure-enum.js +1 -2
  22. package/dist/es2019/version-wrapper.js +1 -1
  23. package/dist/esm/composable-editor/editor-internal.js +11 -1
  24. package/dist/esm/create-editor/ReactEditorView.js +6 -1
  25. package/dist/esm/index.js +14 -1
  26. package/dist/esm/plugins/index.js +0 -1
  27. package/dist/esm/plugins/paste/pm-plugins/main.js +9 -5
  28. package/dist/esm/presets/default.js +1 -1
  29. package/dist/esm/presets/universal.js +2 -1
  30. package/dist/esm/utils/index.js +0 -5
  31. package/dist/esm/utils/performance/measure-enum.js +1 -2
  32. package/dist/esm/version-wrapper.js +1 -1
  33. package/dist/types/index.d.ts +15 -2
  34. package/dist/types/plugins/index.d.ts +0 -1
  35. package/dist/types/plugins/paste/pm-plugins/main.d.ts +2 -0
  36. package/dist/types/presets/default.d.ts +1 -1
  37. package/dist/types/types/editor-props.d.ts +1 -1
  38. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  39. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  40. package/dist/types/utils/index.d.ts +0 -1
  41. package/dist/types/utils/performance/measure-enum.d.ts +0 -1
  42. package/dist/types-ts4.5/index.d.ts +15 -2
  43. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  44. package/dist/types-ts4.5/plugins/paste/pm-plugins/main.d.ts +2 -0
  45. package/dist/types-ts4.5/presets/default.d.ts +1 -1
  46. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  47. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +2 -2
  48. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  49. package/dist/types-ts4.5/utils/index.d.ts +0 -1
  50. package/dist/types-ts4.5/utils/performance/measure-enum.d.ts +0 -1
  51. package/package.json +7 -5
  52. package/dist/cjs/plugins/annotation/commands/index.js +0 -150
  53. package/dist/cjs/plugins/annotation/commands/transform.js +0 -86
  54. package/dist/cjs/plugins/annotation/index.js +0 -130
  55. package/dist/cjs/plugins/annotation/nodeviews/index.js +0 -59
  56. package/dist/cjs/plugins/annotation/pm-plugins/inline-comment.js +0 -243
  57. package/dist/cjs/plugins/annotation/pm-plugins/keymap.js +0 -15
  58. package/dist/cjs/plugins/annotation/pm-plugins/plugin-factory.js +0 -107
  59. package/dist/cjs/plugins/annotation/pm-plugins/reducer.js +0 -84
  60. package/dist/cjs/plugins/annotation/pm-plugins/types.js +0 -17
  61. package/dist/cjs/plugins/annotation/toolbar.js +0 -59
  62. package/dist/cjs/plugins/annotation/types.js +0 -20
  63. package/dist/cjs/plugins/annotation/ui/AnnotationViewWrapper.js +0 -38
  64. package/dist/cjs/plugins/annotation/ui/InlineCommentView.js +0 -149
  65. package/dist/cjs/plugins/annotation/update-provider.js +0 -36
  66. package/dist/cjs/plugins/annotation/utils.js +0 -372
  67. package/dist/es2019/plugins/annotation/commands/index.js +0 -123
  68. package/dist/es2019/plugins/annotation/commands/transform.js +0 -64
  69. package/dist/es2019/plugins/annotation/index.js +0 -125
  70. package/dist/es2019/plugins/annotation/nodeviews/index.js +0 -31
  71. package/dist/es2019/plugins/annotation/pm-plugins/inline-comment.js +0 -178
  72. package/dist/es2019/plugins/annotation/pm-plugins/keymap.js +0 -9
  73. package/dist/es2019/plugins/annotation/pm-plugins/plugin-factory.js +0 -108
  74. package/dist/es2019/plugins/annotation/pm-plugins/reducer.js +0 -94
  75. package/dist/es2019/plugins/annotation/pm-plugins/types.js +0 -11
  76. package/dist/es2019/plugins/annotation/toolbar.js +0 -53
  77. package/dist/es2019/plugins/annotation/types.js +0 -14
  78. package/dist/es2019/plugins/annotation/ui/AnnotationViewWrapper.js +0 -14
  79. package/dist/es2019/plugins/annotation/ui/InlineCommentView.js +0 -147
  80. package/dist/es2019/plugins/annotation/update-provider.js +0 -9
  81. package/dist/es2019/plugins/annotation/utils.js +0 -334
  82. package/dist/esm/plugins/annotation/commands/index.js +0 -143
  83. package/dist/esm/plugins/annotation/commands/transform.js +0 -80
  84. package/dist/esm/plugins/annotation/index.js +0 -118
  85. package/dist/esm/plugins/annotation/nodeviews/index.js +0 -52
  86. package/dist/esm/plugins/annotation/pm-plugins/inline-comment.js +0 -236
  87. package/dist/esm/plugins/annotation/pm-plugins/keymap.js +0 -9
  88. package/dist/esm/plugins/annotation/pm-plugins/plugin-factory.js +0 -101
  89. package/dist/esm/plugins/annotation/pm-plugins/reducer.js +0 -77
  90. package/dist/esm/plugins/annotation/pm-plugins/types.js +0 -11
  91. package/dist/esm/plugins/annotation/toolbar.js +0 -52
  92. package/dist/esm/plugins/annotation/types.js +0 -14
  93. package/dist/esm/plugins/annotation/ui/AnnotationViewWrapper.js +0 -31
  94. package/dist/esm/plugins/annotation/ui/InlineCommentView.js +0 -144
  95. package/dist/esm/plugins/annotation/update-provider.js +0 -29
  96. package/dist/esm/plugins/annotation/utils.js +0 -345
  97. package/dist/types/plugins/annotation/commands/index.d.ts +0 -15
  98. package/dist/types/plugins/annotation/commands/transform.d.ts +0 -11
  99. package/dist/types/plugins/annotation/index.d.ts +0 -15
  100. package/dist/types/plugins/annotation/nodeviews/index.d.ts +0 -11
  101. package/dist/types/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  102. package/dist/types/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  103. package/dist/types/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  104. package/dist/types/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  105. package/dist/types/plugins/annotation/pm-plugins/types.d.ts +0 -78
  106. package/dist/types/plugins/annotation/toolbar.d.ts +0 -5
  107. package/dist/types/plugins/annotation/types.d.ts +0 -86
  108. package/dist/types/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  109. package/dist/types/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  110. package/dist/types/plugins/annotation/update-provider.d.ts +0 -12
  111. package/dist/types/plugins/annotation/utils.d.ts +0 -45
  112. package/dist/types-ts4.5/plugins/annotation/commands/index.d.ts +0 -15
  113. package/dist/types-ts4.5/plugins/annotation/commands/transform.d.ts +0 -11
  114. package/dist/types-ts4.5/plugins/annotation/index.d.ts +0 -17
  115. package/dist/types-ts4.5/plugins/annotation/nodeviews/index.d.ts +0 -11
  116. package/dist/types-ts4.5/plugins/annotation/pm-plugins/inline-comment.d.ts +0 -3
  117. package/dist/types-ts4.5/plugins/annotation/pm-plugins/keymap.d.ts +0 -3
  118. package/dist/types-ts4.5/plugins/annotation/pm-plugins/plugin-factory.d.ts +0 -2
  119. package/dist/types-ts4.5/plugins/annotation/pm-plugins/reducer.d.ts +0 -3
  120. package/dist/types-ts4.5/plugins/annotation/pm-plugins/types.d.ts +0 -78
  121. package/dist/types-ts4.5/plugins/annotation/toolbar.d.ts +0 -5
  122. package/dist/types-ts4.5/plugins/annotation/types.d.ts +0 -86
  123. package/dist/types-ts4.5/plugins/annotation/ui/AnnotationViewWrapper.d.ts +0 -10
  124. package/dist/types-ts4.5/plugins/annotation/ui/InlineCommentView.d.ts +0 -13
  125. package/dist/types-ts4.5/plugins/annotation/update-provider.d.ts +0 -12
  126. package/dist/types-ts4.5/plugins/annotation/utils.d.ts +0 -45
@@ -1,144 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React from 'react';
3
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
- import { AnnotationViewWrapper } from './AnnotationViewWrapper';
6
- import { AnnotationTestIds } from '../types';
7
- import { getAnnotationViewKey, getSelectionPositions, getPluginState, getAllAnnotations } from '../utils';
8
- import { removeInlineCommentNearSelection, updateInlineCommentResolvedState, setInlineCommentDraftState, createAnnotation, closeComponent } from '../commands';
9
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
10
- import { CONTENT_COMPONENT } from '@atlaskit/editor-common/analytics';
11
- import { RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
12
- var findPosForDOM = function findPosForDOM(sel) {
13
- var $from = sel.$from,
14
- from = sel.from;
15
-
16
- // Retrieve current TextNode
17
- var index = $from.index();
18
- var node = index < $from.parent.childCount && $from.parent.child(index);
19
-
20
- // Right edge of a mark.
21
- if (!node && $from.nodeBefore && $from.nodeBefore.isText && $from.nodeBefore.marks.find(function (mark) {
22
- return mark.type.name === 'annotation';
23
- })) {
24
- return from - 1;
25
- }
26
- return from;
27
- };
28
- export function InlineCommentView(_ref) {
29
- var providers = _ref.providers,
30
- editorView = _ref.editorView,
31
- editorAnalyticsAPI = _ref.editorAnalyticsAPI,
32
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
33
- // As inlineComment is the only annotation present, this function is not generic
34
- var inlineCommentProvider = providers.inlineComment;
35
- var state = editorView.state,
36
- dispatch = editorView.dispatch;
37
- var CreateComponent = inlineCommentProvider.createComponent,
38
- ViewComponent = inlineCommentProvider.viewComponent;
39
- var inlineCommentState = getPluginState(state);
40
- var _ref2 = inlineCommentState || {},
41
- bookmark = _ref2.bookmark,
42
- selectedAnnotations = _ref2.selectedAnnotations,
43
- annotations = _ref2.annotations,
44
- isInlineCommentViewClosed = _ref2.isInlineCommentViewClosed;
45
- var annotationsList = getAllAnnotations(editorView.state.doc);
46
- var selection = getSelectionPositions(state, inlineCommentState);
47
- var position = findPosForDOM(selection);
48
- var dom;
49
- try {
50
- dom = findDomRefAtPos(position, editorView.domAtPos.bind(editorView));
51
- } catch (error) {
52
- // eslint-disable-next-line no-console
53
- console.warn(error);
54
- if (dispatchAnalyticsEvent) {
55
- var payload = {
56
- action: ACTION.ERRORED,
57
- actionSubject: ACTION_SUBJECT.CONTENT_COMPONENT,
58
- eventType: EVENT_TYPE.OPERATIONAL,
59
- attributes: {
60
- component: CONTENT_COMPONENT.INLINE_COMMENT,
61
- selection: selection.toJSON(),
62
- position: position,
63
- docSize: editorView.state.doc.nodeSize,
64
- error: error.toString()
65
- }
66
- };
67
- dispatchAnalyticsEvent(payload);
68
- }
69
- }
70
- if (!dom) {
71
- return null;
72
- }
73
-
74
- // Create Component
75
- if (bookmark) {
76
- if (!CreateComponent) {
77
- return null;
78
- }
79
-
80
- //getting all text between bookmarked positions
81
- var textSelection = state.doc.textBetween(selection.from, selection.to);
82
- return /*#__PURE__*/React.createElement("div", {
83
- "data-testid": AnnotationTestIds.floatingComponent,
84
- "data-editor-popup": "true"
85
- }, /*#__PURE__*/React.createElement(CreateComponent, {
86
- dom: dom,
87
- textSelection: textSelection,
88
- onCreate: function onCreate(id) {
89
- createAnnotation(editorAnalyticsAPI)(id)(editorView.state, editorView.dispatch);
90
- !editorView.hasFocus() && editorView.focus();
91
- },
92
- onClose: function onClose() {
93
- setInlineCommentDraftState(editorAnalyticsAPI)(false)(editorView.state, editorView.dispatch);
94
- !editorView.hasFocus() && editorView.focus();
95
- }
96
- }));
97
- }
98
-
99
- // View Component
100
- var activeAnnotations = (selectedAnnotations === null || selectedAnnotations === void 0 ? void 0 : selectedAnnotations.filter(function (mark) {
101
- return annotations && annotations[mark.id] === false;
102
- })) || [];
103
- if (!ViewComponent || activeAnnotations.length === 0) {
104
- return null;
105
- }
106
- var onAnnotationViewed = function onAnnotationViewed() {
107
- if (!dispatchAnalyticsEvent) {
108
- return;
109
- }
110
- // fire analytics
111
- var payload = {
112
- action: ACTION.VIEWED,
113
- actionSubject: ACTION_SUBJECT.ANNOTATION,
114
- actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
115
- eventType: EVENT_TYPE.TRACK,
116
- attributes: {
117
- overlap: activeAnnotations.length ? activeAnnotations.length - 1 : 0
118
- }
119
- };
120
- dispatchAnalyticsEvent(payload);
121
- };
122
- if (getBooleanFF('platform.editor.annotation.decouple-inline-comment-closed_flmox') && isInlineCommentViewClosed || !selectedAnnotations) {
123
- return null;
124
- }
125
- return /*#__PURE__*/React.createElement(AnnotationViewWrapper, {
126
- "data-editor-popup": "true",
127
- "data-testid": AnnotationTestIds.floatingComponent,
128
- key: getAnnotationViewKey(activeAnnotations),
129
- onViewed: onAnnotationViewed
130
- }, /*#__PURE__*/React.createElement(ViewComponent, {
131
- annotationsList: annotationsList,
132
- annotations: activeAnnotations,
133
- dom: dom,
134
- onDelete: function onDelete(id) {
135
- return removeInlineCommentNearSelection(id)(state, dispatch);
136
- },
137
- onResolve: function onResolve(id) {
138
- return updateInlineCommentResolvedState(editorAnalyticsAPI)(_defineProperty({}, id, true), RESOLVE_METHOD.COMPONENT)(editorView.state, editorView.dispatch);
139
- },
140
- onClose: function onClose() {
141
- closeComponent()(editorView.state, editorView.dispatch);
142
- }
143
- }));
144
- }
@@ -1,29 +0,0 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _get from "@babel/runtime/helpers/get";
4
- import _inherits from "@babel/runtime/helpers/inherits";
5
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
- 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); }; }
8
- 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; } }
9
- import { EventEmitter } from 'events';
10
- export var AnnotationUpdateEmitter = /*#__PURE__*/function (_EventEmitter) {
11
- _inherits(AnnotationUpdateEmitter, _EventEmitter);
12
- var _super = _createSuper(AnnotationUpdateEmitter);
13
- function AnnotationUpdateEmitter() {
14
- _classCallCheck(this, AnnotationUpdateEmitter);
15
- return _super.apply(this, arguments);
16
- }
17
- _createClass(AnnotationUpdateEmitter, [{
18
- key: "on",
19
- value: function on(event, listener) {
20
- return _get(_getPrototypeOf(AnnotationUpdateEmitter.prototype), "on", this).call(this, event, listener);
21
- }
22
- }, {
23
- key: "off",
24
- value: function off(event, listener) {
25
- return _get(_getPrototypeOf(AnnotationUpdateEmitter.prototype), "removeListener", this).call(this, event, listener);
26
- }
27
- }]);
28
- return AnnotationUpdateEmitter;
29
- }(EventEmitter);
@@ -1,345 +0,0 @@
1
- import { PluginKey, TextSelection, AllSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- import { AnnotationSharedClassNames } from '@atlaskit/editor-common/styles';
4
- import { canApplyAnnotationOnRange, getAnnotationIdsFromRange, isText, isParagraph, hasAnnotationMark, containsAnyAnnotations } from '@atlaskit/editor-common/utils';
5
- import { AnnotationTypes } from '@atlaskit/adf-schema';
6
- import { AnnotationSelectionType } from './types';
7
- import { ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, ACTION } from '@atlaskit/editor-common/analytics';
8
- export { hasAnnotationMark, containsAnyAnnotations };
9
- function sum(arr, f) {
10
- return arr.reduce(function (val, x) {
11
- return val + f(x);
12
- }, 0);
13
- }
14
- /**
15
- * Finds the marks in the nodes to the left and right.
16
- * @param $pos Position to center search around
17
- */
18
- export var surroundingMarks = function surroundingMarks($pos) {
19
- var nodeBefore = $pos.nodeBefore,
20
- nodeAfter = $pos.nodeAfter;
21
- var markNodeBefore = nodeBefore && $pos.doc.nodeAt(Math.max(0, $pos.pos - nodeBefore.nodeSize - 1));
22
- var markNodeAfter = nodeAfter && $pos.doc.nodeAt($pos.pos + nodeAfter.nodeSize);
23
- return [markNodeBefore && markNodeBefore.marks || [], markNodeAfter && markNodeAfter.marks || []];
24
- };
25
-
26
- /**
27
- * Finds annotation marks, and returns their IDs.
28
- * @param marks Array of marks to search in
29
- */
30
- var filterAnnotationIds = function filterAnnotationIds(marks) {
31
- if (!marks.length) {
32
- return [];
33
- }
34
- var annotation = marks[0].type.schema.marks.annotation;
35
- return marks.filter(function (mark) {
36
- return mark.type === annotation;
37
- }).map(function (mark) {
38
- return mark.attrs.id;
39
- });
40
- };
41
-
42
- /**
43
- * Re-orders the annotation array based on the order in the document.
44
- *
45
- * This places the marks that do not appear in the surrounding nodes
46
- * higher in the list. That is, the inner-most one appears first.
47
- *
48
- * Undo, for example, can re-order annotation marks in the document.
49
- * @param annotations annotation metadata
50
- * @param $from location to look around (usually the selection)
51
- */
52
- var reorderAnnotations = function reorderAnnotations(annotations, $from) {
53
- var idSet = surroundingMarks($from).map(filterAnnotationIds);
54
- annotations.sort(function (a, b) {
55
- return sum(idSet, function (ids) {
56
- return ids.indexOf(a.id);
57
- }) - sum(idSet, function (ids) {
58
- return ids.indexOf(b.id);
59
- });
60
- });
61
- };
62
- export var getAllAnnotations = function getAllAnnotations(doc) {
63
- var allAnnotationIds = new Set();
64
- doc.descendants(function (node) {
65
- node.marks.filter(function (mark) {
66
- return mark.type.name === 'annotation';
67
- })
68
- // filter out annotations with invalid attributes as they cause errors when interacting with them
69
- .filter(validateAnnotationMark).forEach(function (m) {
70
- return allAnnotationIds.add(m.attrs.id);
71
- });
72
- return true;
73
- });
74
- return Array.from(allAnnotationIds);
75
- };
76
-
77
- /*
78
- * verifies if annotation mark contains valid attributes
79
- */
80
- var validateAnnotationMark = function validateAnnotationMark(annotationMark) {
81
- var _ref = annotationMark.attrs,
82
- id = _ref.id,
83
- annotationType = _ref.annotationType;
84
- return validateAnnotationId(id) && validateAnnotationType(annotationType);
85
- function validateAnnotationId(id) {
86
- if (!id || typeof id !== 'string') {
87
- return false;
88
- }
89
- var invalidIds = ['null', 'undefined'];
90
- return !invalidIds.includes(id.toLowerCase());
91
- }
92
- function validateAnnotationType(type) {
93
- if (!type || typeof type !== 'string') {
94
- return false;
95
- }
96
- var allowedTypes = Object.values(AnnotationTypes);
97
- return allowedTypes.includes(type);
98
- }
99
- };
100
-
101
- /*
102
- * add decoration for the comment selection in draft state
103
- * (when creating new comment)
104
- */
105
- export var addDraftDecoration = function addDraftDecoration(start, end) {
106
- return Decoration.inline(start, end, {
107
- class: "".concat(AnnotationSharedClassNames.draft)
108
- });
109
- };
110
- export var getAnnotationViewKey = function getAnnotationViewKey(annotations) {
111
- var keys = annotations.map(function (mark) {
112
- return mark.id;
113
- }).join('_');
114
- return "view-annotation-wrapper_".concat(keys);
115
- };
116
- export var findAnnotationsInSelection = function findAnnotationsInSelection(selection, doc) {
117
- var empty = selection.empty,
118
- $anchor = selection.$anchor,
119
- anchor = selection.anchor;
120
- // Only detect annotations on caret selection
121
- if (!empty || !doc) {
122
- return [];
123
- }
124
- var node = doc.nodeAt(anchor);
125
- if (!node && !$anchor.nodeBefore) {
126
- return [];
127
- }
128
- var annotationMark = doc.type.schema.marks.annotation;
129
- var nodeBefore = $anchor.nodeBefore;
130
- var anchorAnnotationMarks = node && node.marks || [];
131
- var marks = [];
132
- if (annotationMark.isInSet(anchorAnnotationMarks)) {
133
- marks = anchorAnnotationMarks;
134
- } else if (nodeBefore && annotationMark.isInSet(nodeBefore.marks)) {
135
- marks = nodeBefore.marks;
136
- }
137
- var annotations = marks.filter(function (mark) {
138
- return mark.type.name === 'annotation';
139
- }).map(function (mark) {
140
- return {
141
- id: mark.attrs.id,
142
- type: mark.attrs.annotationType
143
- };
144
- });
145
- reorderAnnotations(annotations, $anchor);
146
- return annotations;
147
- };
148
-
149
- /**
150
- * get selection from position to apply new comment for
151
- * @return bookmarked positions if they exists, otherwise current selection positions
152
- */
153
- export function getSelectionPositions(editorState, inlineCommentState) {
154
- var _ref2 = inlineCommentState || {},
155
- bookmark = _ref2.bookmark;
156
- // get positions via saved bookmark if it is available
157
- // this is to make comments box positioned relative to temporary highlight rather then current selection
158
- if (bookmark) {
159
- return bookmark.resolve(editorState.doc);
160
- }
161
- return editorState.selection;
162
- }
163
- export var inlineCommentPluginKey = new PluginKey('inlineCommentPluginKey');
164
- export var getPluginState = function getPluginState(state) {
165
- return inlineCommentPluginKey.getState(state);
166
- };
167
-
168
- /**
169
- * get number of unique annotations within current selection
170
- */
171
- var getAnnotationsInSelectionCount = function getAnnotationsInSelectionCount(state) {
172
- var _state$selection = state.selection,
173
- from = _state$selection.from,
174
- to = _state$selection.to;
175
- var annotations = getAnnotationIdsFromRange({
176
- from: from,
177
- to: to
178
- }, state.doc, state.schema);
179
- return annotations.length;
180
- };
181
-
182
- /**
183
- * get payload for the open/close analytics event
184
- */
185
- export var getDraftCommandAnalyticsPayload = function getDraftCommandAnalyticsPayload(drafting, inputMethod) {
186
- var payload = function payload(state) {
187
- var attributes = {};
188
- if (drafting) {
189
- attributes = {
190
- inputMethod: inputMethod,
191
- overlap: getAnnotationsInSelectionCount(state)
192
- };
193
- }
194
- return {
195
- action: drafting ? ACTION.OPENED : ACTION.CLOSED,
196
- actionSubject: ACTION_SUBJECT.ANNOTATION,
197
- actionSubjectId: ACTION_SUBJECT_ID.INLINE_COMMENT,
198
- eventType: EVENT_TYPE.TRACK,
199
- attributes: attributes
200
- };
201
- };
202
- return payload;
203
- };
204
- export var isSelectionValid = function isSelectionValid(state) {
205
- var selection = state.selection;
206
- var _ref3 = getPluginState(state) || {},
207
- disallowOnWhitespace = _ref3.disallowOnWhitespace;
208
- if (selection.empty || !(selection instanceof TextSelection || selection instanceof AllSelection)) {
209
- return AnnotationSelectionType.INVALID;
210
- }
211
- var containsInvalidNodes = hasInvalidNodes(state);
212
-
213
- // A selection that only covers 1 pos, and is an invalid node
214
- // e.g. a text selection over a mention
215
- if (containsInvalidNodes && selection.to - selection.from === 1) {
216
- return AnnotationSelectionType.INVALID;
217
- }
218
- if (containsInvalidNodes) {
219
- return AnnotationSelectionType.DISABLED;
220
- }
221
- if (disallowOnWhitespace && hasInvalidWhitespaceNode(selection, state.schema)) {
222
- return AnnotationSelectionType.INVALID;
223
- }
224
- if (isEmptyTextSelection(selection, state.schema)) {
225
- return AnnotationSelectionType.INVALID;
226
- }
227
- return AnnotationSelectionType.VALID;
228
- };
229
- export var hasInvalidNodes = function hasInvalidNodes(state) {
230
- var selection = state.selection,
231
- doc = state.doc,
232
- schema = state.schema;
233
- return !canApplyAnnotationOnRange({
234
- from: selection.from,
235
- to: selection.to
236
- }, doc, schema);
237
- };
238
-
239
- /**
240
- * Checks if selection contains only empty text
241
- * e.g. when you select across multiple empty paragraphs
242
- */
243
- function isEmptyTextSelection(selection, schema) {
244
- var _schema$nodes = schema.nodes,
245
- text = _schema$nodes.text,
246
- paragraph = _schema$nodes.paragraph;
247
- var hasContent = false;
248
- selection.content().content.descendants(function (node) {
249
- // for empty paragraph - consider empty (nothing to comment on)
250
- if (node.type === paragraph && !node.content.size) {
251
- return false;
252
- }
253
- // for not a text or nonempty text - consider nonempty (can comment if the node is supported for annotations)
254
- if (node.type !== text || !node.textContent) {
255
- hasContent = true;
256
- }
257
- return !hasContent;
258
- });
259
- return !hasContent;
260
- }
261
-
262
- /**
263
- * Checks if any of the nodes in a given selection are completely whitespace
264
- * This is to conform to Confluence annotation specifications
265
- */
266
- export function hasInvalidWhitespaceNode(selection, schema) {
267
- var foundInvalidWhitespace = false;
268
- var content = selection.content().content;
269
- content.descendants(function (node) {
270
- if (isText(node, schema)) {
271
- return false;
272
- }
273
- if (node.textContent.trim() === '') {
274
- // Trailing new lines do not result in the annotation spanning into
275
- // the trailing new line so can be ignored when looking for invalid
276
- // whitespace nodes.
277
- var nodeIsTrailingNewLine =
278
- // it is the final node
279
- node.eq(content.lastChild) &&
280
- // and there are multiple nodes
281
- !node.eq(content.firstChild) &&
282
- // and it is a paragraph node
283
- isParagraph(node, schema);
284
- if (!nodeIsTrailingNewLine) {
285
- foundInvalidWhitespace = true;
286
- }
287
- }
288
- return !foundInvalidWhitespace;
289
- });
290
- return foundInvalidWhitespace;
291
- }
292
-
293
- /*
294
- * verifies that the annotation exists by the given id
295
- */
296
- export function annotationExists(annotationId, state) {
297
- var commentsPluginState = getPluginState(state);
298
- return !!(commentsPluginState !== null && commentsPluginState !== void 0 && commentsPluginState.annotations) && Object.keys(commentsPluginState.annotations).includes(annotationId);
299
- }
300
-
301
- /*
302
- * remove annotations that dont exsist in plugin state from slice
303
- */
304
- export function stripNonExistingAnnotations(slice, state) {
305
- if (!slice.content.size) {
306
- return false;
307
- }
308
- slice.content.forEach(function (node) {
309
- stripNonExistingAnnotationsFromNode(node, state);
310
- node.content.descendants(function (node) {
311
- stripNonExistingAnnotationsFromNode(node, state);
312
- return true;
313
- });
314
- });
315
- }
316
-
317
- /*
318
- * remove annotations that dont exsist in plugin state
319
- * from node
320
- */
321
- function stripNonExistingAnnotationsFromNode(node, state) {
322
- if (hasAnnotationMark(node, state)) {
323
- node.marks = node.marks.filter(function (mark) {
324
- if (mark.type.name === 'annotation') {
325
- return annotationExists(mark.attrs.id, state);
326
- }
327
- return true;
328
- });
329
- }
330
- return node;
331
- }
332
-
333
- /**
334
- * Compares two sets of annotationInfos to see if the annotations have changed
335
- * This function assumes annotations will have unique id's for simplicity
336
- */
337
- export function isSelectedAnnotationsChanged(oldSelectedAnnotations, newSelectedAnnotations) {
338
- return newSelectedAnnotations.length !== oldSelectedAnnotations.length ||
339
- // assuming annotations have unique id's for simplicity
340
- newSelectedAnnotations.some(function (annotation) {
341
- return !oldSelectedAnnotations.find(function (pluginStateAnnotation) {
342
- return annotation.id === pluginStateAnnotation.id && annotation.type === pluginStateAnnotation.type;
343
- });
344
- });
345
- }
@@ -1,15 +0,0 @@
1
- import type { EditorAnalyticsAPI, RESOLVE_METHOD } from '@atlaskit/editor-common/analytics';
2
- import type { Command } from '../../../types';
3
- import { AnnotationTypes } from '@atlaskit/adf-schema';
4
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
- import type { InlineCommentMap, InlineCommentMouseData } from '../pm-plugins/types';
6
- export declare const updateInlineCommentResolvedState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (partialNewState: InlineCommentMap, resolveMethod?: RESOLVE_METHOD) => Command;
7
- export declare const closeComponent: () => Command;
8
- export declare const clearDirtyMark: () => Command;
9
- export declare const removeInlineCommentNearSelection: (id: string) => Command;
10
- export declare const setInlineCommentDraftState: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, inputMethod?: INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHORTCUT) => Command;
11
- export declare const addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => Command;
12
- export declare const updateMouseState: (mouseData: InlineCommentMouseData) => Command;
13
- export declare const setSelectedAnnotation: (id: string) => Command;
14
- export declare const createAnnotation: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string, annotationType?: AnnotationTypes) => Command;
15
- export declare const setInlineCommentsVisibility: (isVisible: boolean) => Command;
@@ -1,11 +0,0 @@
1
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
2
- import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
- import type { RESOLVE_METHOD, EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
4
- declare const _default: {
5
- addAnnotationMark: (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
6
- addInlineComment: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (id: string) => (transaction: Transaction, state: EditorState) => Transaction;
7
- addOpenCloseAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (drafting: boolean, method?: INPUT_METHOD.SHORTCUT | INPUT_METHOD.TOOLBAR) => (transaction: Transaction, state: EditorState) => Transaction;
8
- addInsertAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
9
- addResolveAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (method?: RESOLVE_METHOD | undefined) => (transaction: Transaction, state: EditorState) => Transaction;
10
- };
11
- export default _default;
@@ -1,15 +0,0 @@
1
- import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
- import type { AnnotationProviders, InlineCommentAnnotationProvider, AnnotationInfo, AnnotationState, InlineCommentState, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationTypeProvider } from './types';
3
- import type { UpdateEvent } from './update-provider';
4
- import { AnnotationUpdateEmitter } from './update-provider';
5
- import type { InlineCommentPluginState } from './pm-plugins/types';
6
- import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
7
- export type AnnotationPlugin = NextEditorPlugin<'annotation', {
8
- pluginConfiguration: AnnotationProviders | undefined;
9
- sharedState: InlineCommentPluginState | undefined;
10
- dependencies: [OptionalPlugin<AnalyticsPlugin>];
11
- }>;
12
- declare const annotationPlugin: AnnotationPlugin;
13
- export default annotationPlugin;
14
- export { AnnotationUpdateEmitter };
15
- export type { AnnotationProviders, InlineCommentAnnotationProvider, InlineCommentCreateComponentProps, InlineCommentViewComponentProps, AnnotationTypeProvider, AnnotationInfo, AnnotationState, InlineCommentState, UpdateEvent, };
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- import { ForwardRef } from '../../../nodeviews';
3
- import ReactNodeView from '@atlaskit/editor-common/react-node-view';
4
- export declare class AnnotationNodeView extends ReactNodeView {
5
- createDomRef(): HTMLSpanElement;
6
- getContentDOM(): {
7
- dom: HTMLSpanElement;
8
- };
9
- render(_props: {}, forwardRef: ForwardRef): JSX.Element;
10
- }
11
- export declare const getAnnotationViewClassname: (isUnresolved: boolean, hasFocus: boolean) => string | undefined;
@@ -1,3 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { InlineCommentPluginState, InlineCommentPluginOptions } from './types';
3
- export declare const inlineCommentPlugin: (options: InlineCommentPluginOptions) => SafePlugin<InlineCommentPluginState>;
@@ -1,3 +0,0 @@
1
- import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- export declare function keymapPlugin(editorAnalyticsAPI: EditorAnalyticsAPI | undefined): SafePlugin;
@@ -1,2 +0,0 @@
1
- import type { InlineCommentPluginState } from './types';
2
- export declare const createPluginState: (dispatch: import("@atlaskit/editor-common/event-dispatcher").Dispatch<any>, initialState: InlineCommentPluginState | ((state: import("prosemirror-state").EditorState) => InlineCommentPluginState)) => import("prosemirror-state").SafeStateField<InlineCommentPluginState>, createCommand: <A = import("./types").InlineCommentAction>(action: A | ((state: Readonly<import("prosemirror-state").EditorState>) => false | A), transform?: ((tr: import("prosemirror-state").Transaction, state: import("prosemirror-state").EditorState) => import("prosemirror-state").Transaction) | undefined) => import("@atlaskit/editor-common/types").Command;
@@ -1,3 +0,0 @@
1
- import type { InlineCommentAction, InlineCommentPluginState } from './types';
2
- declare const _default: (pluginState: InlineCommentPluginState, action: InlineCommentAction) => InlineCommentPluginState;
3
- export default _default;
@@ -1,78 +0,0 @@
1
- import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
2
- import type { EditorState, SelectionBookmark } from '@atlaskit/editor-prosemirror/state';
3
- import type { PortalProviderAPI } from '@atlaskit/editor-common/portal-provider';
4
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
5
- import type { Dispatch, EventDispatcher } from '@atlaskit/editor-common/event-dispatcher';
6
- import type { InlineCommentAnnotationProvider, AnnotationInfo } from '../types';
7
- export declare enum ACTIONS {
8
- UPDATE_INLINE_COMMENT_STATE = 0,
9
- SET_INLINE_COMMENT_DRAFT_STATE = 1,
10
- INLINE_COMMENT_UPDATE_MOUSE_STATE = 2,
11
- INLINE_COMMENT_CLEAR_DIRTY_MARK = 3,
12
- ADD_INLINE_COMMENT = 4,
13
- INLINE_COMMENT_SET_VISIBLE = 5,
14
- CLOSE_COMPONENT = 6,
15
- SET_SELECTED_ANNOTATION = 7
16
- }
17
- export interface InlineCommentPluginOptions {
18
- dispatch: Dispatch;
19
- eventDispatcher: EventDispatcher;
20
- portalProviderAPI: PortalProviderAPI;
21
- provider: InlineCommentAnnotationProvider;
22
- editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
23
- }
24
- export interface InlineCommentMouseData {
25
- isSelecting: boolean;
26
- }
27
- export type InlineCommentMap = {
28
- [key: string]: boolean;
29
- };
30
- export type InlineCommentAction = {
31
- type: ACTIONS.UPDATE_INLINE_COMMENT_STATE;
32
- data: InlineCommentMap;
33
- } | {
34
- type: ACTIONS.SET_INLINE_COMMENT_DRAFT_STATE;
35
- data: {
36
- drafting: boolean;
37
- editorState: EditorState;
38
- };
39
- } | {
40
- type: ACTIONS.INLINE_COMMENT_UPDATE_MOUSE_STATE;
41
- data: {
42
- mouseData: InlineCommentMouseData;
43
- };
44
- } | {
45
- type: ACTIONS.INLINE_COMMENT_CLEAR_DIRTY_MARK;
46
- } | {
47
- type: ACTIONS.CLOSE_COMPONENT;
48
- } | {
49
- type: ACTIONS.ADD_INLINE_COMMENT;
50
- data: {
51
- drafting: boolean;
52
- inlineComments: InlineCommentMap;
53
- editorState: EditorState;
54
- selectedAnnotations: AnnotationInfo[];
55
- };
56
- } | {
57
- type: ACTIONS.INLINE_COMMENT_SET_VISIBLE;
58
- data: {
59
- isVisible: boolean;
60
- };
61
- } | {
62
- type: ACTIONS.SET_SELECTED_ANNOTATION;
63
- data: {
64
- selectedAnnotations: AnnotationInfo[];
65
- };
66
- };
67
- export type InlineCommentPluginState = {
68
- annotations: InlineCommentMap;
69
- selectedAnnotations: AnnotationInfo[];
70
- dirtyAnnotations?: boolean;
71
- mouseData: InlineCommentMouseData;
72
- draftDecorationSet?: DecorationSet;
73
- bookmark?: SelectionBookmark;
74
- disallowOnWhitespace: boolean;
75
- isInlineCommentViewClosed: boolean;
76
- isVisible: boolean;
77
- skipSelectionHandling: boolean;
78
- };