@atlaskit/editor-plugin-selection-toolbar 31.0.5 → 31.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-selection-toolbar
2
2
 
3
+ ## 31.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`827a297d8c605`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/827a297d8c605) -
8
+ Delete unreachable source files
9
+ - Updated dependencies
10
+
3
11
  ## 31.0.5
4
12
 
5
13
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-toolbar",
3
- "version": "31.0.5",
3
+ "version": "31.0.6",
4
4
  "description": "@atlaskit/editor-plugin-selection-toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -48,7 +48,7 @@
48
48
  "bind-event-listener": "^3.0.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^134.3.0",
51
+ "@atlaskit/editor-common": "^134.4.0",
52
52
  "react": "^18.2.0 || ^19.2.0",
53
53
  "react-dom": "^18.2.0 || ^19.2.0",
54
54
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -1,127 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.calculateToolbarPositionTrackHead = void 0;
7
- /**
8
- * These functions are currently not used. They were added to provide more control
9
- * of the toolbar in different products, i.e confluence comments and annotations.
10
- * Work to add the toolbar to more products has been paused at the time of writing.
11
- */
12
-
13
- var getScrollParent = function getScrollParent(editorView) {
14
- var _editorContentArea$pa;
15
- // Find the nearest Editor
16
- // Ignored via go/ees005
17
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
18
- var editorContentArea = editorView.dom.closest('.ak-editor-content-area');
19
-
20
- // Check if the Editor is a child of another, the annotation editor inside
21
- // Confluence full-page editor for example.
22
- // If so, we need to append the toolbar to the closest Editor
23
- if (editorContentArea !== null && editorContentArea !== void 0 && (_editorContentArea$pa = editorContentArea.parentElement) !== null && _editorContentArea$pa !== void 0 && _editorContentArea$pa.closest('.ak-editor-content-area')) {
24
- return {
25
- scrollWrapper: editorContentArea,
26
- offset: editorContentArea.offsetTop
27
- };
28
- }
29
-
30
- // If the Editor is full-page there should be a parent .fabric-editor-popup-scroll-parent
31
- var scrollParent = editorView.dom.closest('.fabric-editor-popup-scroll-parent');
32
-
33
- // If there is a scroll parent then we can assume the Editor is full-page
34
- if (scrollParent) {
35
- return {
36
- scrollWrapper: scrollParent,
37
- offset: scrollParent.scrollTop
38
- };
39
- }
40
-
41
- // If there is no scroll parent then we can assume the Editor is not full-page
42
- if (editorContentArea && !scrollParent) {
43
- return {
44
- scrollWrapper: editorContentArea,
45
- offset: editorContentArea.offsetTop
46
- };
47
- }
48
-
49
- // Use the document body as a fallback
50
- return {
51
- scrollWrapper: document.body,
52
- offset: 0
53
- };
54
- };
55
-
56
- /*
57
- Calculates the position of the floating toolbar relative to the selection.
58
- This is a re-implementation which closely matches the behaviour on Confluence renderer.
59
- The main difference is the popup is always above the selection.
60
- Things to consider:
61
- - stick as close to the head X release coordinates as possible
62
- - coordinates of head X and getBoundingClientRect() are absolute in client viewport (not including scroll offsets)
63
- - popup may appear in '.fabric-editor-popup-scroll-parent' (or body)
64
- - we use the toolbarRect to center align toolbar
65
- - use wrapperBounds to clamp values
66
- - editorView.dom bounds differ to wrapperBounds, convert at the end
67
- */
68
- var calculateToolbarPositionTrackHead = exports.calculateToolbarPositionTrackHead = function calculateToolbarPositionTrackHead(toolbarTitle) {
69
- return function (editorView, nextPos) {
70
- // Ignored via go/ees005
71
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
72
- var toolbar = document.querySelector("div[aria-label=\"".concat(toolbarTitle, "\"]"));
73
- if (!toolbar) {
74
- return nextPos;
75
- }
76
- var _getScrollParent = getScrollParent(editorView),
77
- scrollWrapper = _getScrollParent.scrollWrapper,
78
- offset = _getScrollParent.offset;
79
- var wrapperBounds = scrollWrapper.getBoundingClientRect();
80
- var selection = window && window.getSelection();
81
- var range = selection && !selection.isCollapsed && selection.getRangeAt(0);
82
- if (!range) {
83
- return nextPos;
84
- }
85
- var toolbarRect = toolbar.getBoundingClientRect();
86
- var _editorView$state$sel = editorView.state.selection,
87
- head = _editorView$state$sel.head,
88
- anchor = _editorView$state$sel.anchor;
89
- var topCoords = editorView.coordsAtPos(Math.min(head, anchor));
90
- var bottomCoords = editorView.coordsAtPos(Math.max(head, anchor) - Math.min(range.endOffset, 1));
91
- var top;
92
- // If not the same line, display toolbar below.
93
- if (head > anchor && topCoords.top !== bottomCoords.top) {
94
- // We are taking the previous pos to the maxium, so avoid end of line positions
95
- // returning the next line's rect.
96
- top = (bottomCoords.top || 0) + toolbarRect.height / 1.15;
97
- } else {
98
- top = (topCoords.top || 0) - toolbarRect.height * 1.5;
99
- }
100
- var left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
101
- // Place toolbar below selection if not sufficient space above
102
- if (top < wrapperBounds.top) {
103
- var _getCoordsBelowSelect = getCoordsBelowSelection(bottomCoords, toolbarRect);
104
- top = _getCoordsBelowSelect.top;
105
- left = _getCoordsBelowSelect.left;
106
- }
107
- // Make sure the toolbar doesn't extend out of the Editor
108
- if (left + toolbarRect.width > wrapperBounds.right) {
109
- left = wrapperBounds.right - toolbarRect.width;
110
- }
111
- // remap positions from browser document to wrapperBounds
112
- return {
113
- top: top - wrapperBounds.top + offset,
114
- left: Math.max(0, left - wrapperBounds.left)
115
- };
116
- };
117
- };
118
-
119
- /**
120
- * Returns the coordintes at the bottom the selection.
121
- */
122
- var getCoordsBelowSelection = function getCoordsBelowSelection(bottomCoords, toolbarRect) {
123
- return {
124
- top: (bottomCoords.top || 0) + toolbarRect.height / 1.15,
125
- left: bottomCoords.right - toolbarRect.width / 2
126
- };
127
- };
@@ -1,122 +0,0 @@
1
- /**
2
- * These functions are currently not used. They were added to provide more control
3
- * of the toolbar in different products, i.e confluence comments and annotations.
4
- * Work to add the toolbar to more products has been paused at the time of writing.
5
- */
6
-
7
- const getScrollParent = editorView => {
8
- var _editorContentArea$pa;
9
- // Find the nearest Editor
10
- // Ignored via go/ees005
11
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
12
- const editorContentArea = editorView.dom.closest('.ak-editor-content-area');
13
-
14
- // Check if the Editor is a child of another, the annotation editor inside
15
- // Confluence full-page editor for example.
16
- // If so, we need to append the toolbar to the closest Editor
17
- if (editorContentArea !== null && editorContentArea !== void 0 && (_editorContentArea$pa = editorContentArea.parentElement) !== null && _editorContentArea$pa !== void 0 && _editorContentArea$pa.closest('.ak-editor-content-area')) {
18
- return {
19
- scrollWrapper: editorContentArea,
20
- offset: editorContentArea.offsetTop
21
- };
22
- }
23
-
24
- // If the Editor is full-page there should be a parent .fabric-editor-popup-scroll-parent
25
- const scrollParent = editorView.dom.closest('.fabric-editor-popup-scroll-parent');
26
-
27
- // If there is a scroll parent then we can assume the Editor is full-page
28
- if (scrollParent) {
29
- return {
30
- scrollWrapper: scrollParent,
31
- offset: scrollParent.scrollTop
32
- };
33
- }
34
-
35
- // If there is no scroll parent then we can assume the Editor is not full-page
36
- if (editorContentArea && !scrollParent) {
37
- return {
38
- scrollWrapper: editorContentArea,
39
- offset: editorContentArea.offsetTop
40
- };
41
- }
42
-
43
- // Use the document body as a fallback
44
- return {
45
- scrollWrapper: document.body,
46
- offset: 0
47
- };
48
- };
49
-
50
- /*
51
- Calculates the position of the floating toolbar relative to the selection.
52
- This is a re-implementation which closely matches the behaviour on Confluence renderer.
53
- The main difference is the popup is always above the selection.
54
- Things to consider:
55
- - stick as close to the head X release coordinates as possible
56
- - coordinates of head X and getBoundingClientRect() are absolute in client viewport (not including scroll offsets)
57
- - popup may appear in '.fabric-editor-popup-scroll-parent' (or body)
58
- - we use the toolbarRect to center align toolbar
59
- - use wrapperBounds to clamp values
60
- - editorView.dom bounds differ to wrapperBounds, convert at the end
61
- */
62
- export const calculateToolbarPositionTrackHead = toolbarTitle => (editorView, nextPos) => {
63
- // Ignored via go/ees005
64
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
65
- const toolbar = document.querySelector(`div[aria-label="${toolbarTitle}"]`);
66
- if (!toolbar) {
67
- return nextPos;
68
- }
69
- const {
70
- scrollWrapper,
71
- offset
72
- } = getScrollParent(editorView);
73
- const wrapperBounds = scrollWrapper.getBoundingClientRect();
74
- const selection = window && window.getSelection();
75
- const range = selection && !selection.isCollapsed && selection.getRangeAt(0);
76
- if (!range) {
77
- return nextPos;
78
- }
79
- const toolbarRect = toolbar.getBoundingClientRect();
80
- const {
81
- head,
82
- anchor
83
- } = editorView.state.selection;
84
- const topCoords = editorView.coordsAtPos(Math.min(head, anchor));
85
- const bottomCoords = editorView.coordsAtPos(Math.max(head, anchor) - Math.min(range.endOffset, 1));
86
- let top;
87
- // If not the same line, display toolbar below.
88
- if (head > anchor && topCoords.top !== bottomCoords.top) {
89
- // We are taking the previous pos to the maxium, so avoid end of line positions
90
- // returning the next line's rect.
91
- top = (bottomCoords.top || 0) + toolbarRect.height / 1.15;
92
- } else {
93
- top = (topCoords.top || 0) - toolbarRect.height * 1.5;
94
- }
95
- let left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
96
- // Place toolbar below selection if not sufficient space above
97
- if (top < wrapperBounds.top) {
98
- ({
99
- top,
100
- left
101
- } = getCoordsBelowSelection(bottomCoords, toolbarRect));
102
- }
103
- // Make sure the toolbar doesn't extend out of the Editor
104
- if (left + toolbarRect.width > wrapperBounds.right) {
105
- left = wrapperBounds.right - toolbarRect.width;
106
- }
107
- // remap positions from browser document to wrapperBounds
108
- return {
109
- top: top - wrapperBounds.top + offset,
110
- left: Math.max(0, left - wrapperBounds.left)
111
- };
112
- };
113
-
114
- /**
115
- * Returns the coordintes at the bottom the selection.
116
- */
117
- const getCoordsBelowSelection = (bottomCoords, toolbarRect) => {
118
- return {
119
- top: (bottomCoords.top || 0) + toolbarRect.height / 1.15,
120
- left: bottomCoords.right - toolbarRect.width / 2
121
- };
122
- };
@@ -1,121 +0,0 @@
1
- /**
2
- * These functions are currently not used. They were added to provide more control
3
- * of the toolbar in different products, i.e confluence comments and annotations.
4
- * Work to add the toolbar to more products has been paused at the time of writing.
5
- */
6
-
7
- var getScrollParent = function getScrollParent(editorView) {
8
- var _editorContentArea$pa;
9
- // Find the nearest Editor
10
- // Ignored via go/ees005
11
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
12
- var editorContentArea = editorView.dom.closest('.ak-editor-content-area');
13
-
14
- // Check if the Editor is a child of another, the annotation editor inside
15
- // Confluence full-page editor for example.
16
- // If so, we need to append the toolbar to the closest Editor
17
- if (editorContentArea !== null && editorContentArea !== void 0 && (_editorContentArea$pa = editorContentArea.parentElement) !== null && _editorContentArea$pa !== void 0 && _editorContentArea$pa.closest('.ak-editor-content-area')) {
18
- return {
19
- scrollWrapper: editorContentArea,
20
- offset: editorContentArea.offsetTop
21
- };
22
- }
23
-
24
- // If the Editor is full-page there should be a parent .fabric-editor-popup-scroll-parent
25
- var scrollParent = editorView.dom.closest('.fabric-editor-popup-scroll-parent');
26
-
27
- // If there is a scroll parent then we can assume the Editor is full-page
28
- if (scrollParent) {
29
- return {
30
- scrollWrapper: scrollParent,
31
- offset: scrollParent.scrollTop
32
- };
33
- }
34
-
35
- // If there is no scroll parent then we can assume the Editor is not full-page
36
- if (editorContentArea && !scrollParent) {
37
- return {
38
- scrollWrapper: editorContentArea,
39
- offset: editorContentArea.offsetTop
40
- };
41
- }
42
-
43
- // Use the document body as a fallback
44
- return {
45
- scrollWrapper: document.body,
46
- offset: 0
47
- };
48
- };
49
-
50
- /*
51
- Calculates the position of the floating toolbar relative to the selection.
52
- This is a re-implementation which closely matches the behaviour on Confluence renderer.
53
- The main difference is the popup is always above the selection.
54
- Things to consider:
55
- - stick as close to the head X release coordinates as possible
56
- - coordinates of head X and getBoundingClientRect() are absolute in client viewport (not including scroll offsets)
57
- - popup may appear in '.fabric-editor-popup-scroll-parent' (or body)
58
- - we use the toolbarRect to center align toolbar
59
- - use wrapperBounds to clamp values
60
- - editorView.dom bounds differ to wrapperBounds, convert at the end
61
- */
62
- export var calculateToolbarPositionTrackHead = function calculateToolbarPositionTrackHead(toolbarTitle) {
63
- return function (editorView, nextPos) {
64
- // Ignored via go/ees005
65
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
66
- var toolbar = document.querySelector("div[aria-label=\"".concat(toolbarTitle, "\"]"));
67
- if (!toolbar) {
68
- return nextPos;
69
- }
70
- var _getScrollParent = getScrollParent(editorView),
71
- scrollWrapper = _getScrollParent.scrollWrapper,
72
- offset = _getScrollParent.offset;
73
- var wrapperBounds = scrollWrapper.getBoundingClientRect();
74
- var selection = window && window.getSelection();
75
- var range = selection && !selection.isCollapsed && selection.getRangeAt(0);
76
- if (!range) {
77
- return nextPos;
78
- }
79
- var toolbarRect = toolbar.getBoundingClientRect();
80
- var _editorView$state$sel = editorView.state.selection,
81
- head = _editorView$state$sel.head,
82
- anchor = _editorView$state$sel.anchor;
83
- var topCoords = editorView.coordsAtPos(Math.min(head, anchor));
84
- var bottomCoords = editorView.coordsAtPos(Math.max(head, anchor) - Math.min(range.endOffset, 1));
85
- var top;
86
- // If not the same line, display toolbar below.
87
- if (head > anchor && topCoords.top !== bottomCoords.top) {
88
- // We are taking the previous pos to the maxium, so avoid end of line positions
89
- // returning the next line's rect.
90
- top = (bottomCoords.top || 0) + toolbarRect.height / 1.15;
91
- } else {
92
- top = (topCoords.top || 0) - toolbarRect.height * 1.5;
93
- }
94
- var left = (head > anchor ? bottomCoords.right : topCoords.left) - toolbarRect.width / 2;
95
- // Place toolbar below selection if not sufficient space above
96
- if (top < wrapperBounds.top) {
97
- var _getCoordsBelowSelect = getCoordsBelowSelection(bottomCoords, toolbarRect);
98
- top = _getCoordsBelowSelect.top;
99
- left = _getCoordsBelowSelect.left;
100
- }
101
- // Make sure the toolbar doesn't extend out of the Editor
102
- if (left + toolbarRect.width > wrapperBounds.right) {
103
- left = wrapperBounds.right - toolbarRect.width;
104
- }
105
- // remap positions from browser document to wrapperBounds
106
- return {
107
- top: top - wrapperBounds.top + offset,
108
- left: Math.max(0, left - wrapperBounds.left)
109
- };
110
- };
111
- };
112
-
113
- /**
114
- * Returns the coordintes at the bottom the selection.
115
- */
116
- var getCoordsBelowSelection = function getCoordsBelowSelection(bottomCoords, toolbarRect) {
117
- return {
118
- top: (bottomCoords.top || 0) + toolbarRect.height / 1.15,
119
- left: bottomCoords.right - toolbarRect.width / 2
120
- };
121
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * These functions are currently not used. They were added to provide more control
3
- * of the toolbar in different products, i.e confluence comments and annotations.
4
- * Work to add the toolbar to more products has been paused at the time of writing.
5
- */
6
- import type { Position } from '@atlaskit/editor-common/Popup/utils';
7
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
- export declare const calculateToolbarPositionTrackHead: (toolbarTitle: string) => (editorView: EditorView, nextPos: Position) => Position;
9
- export type CoordsAtPos = {
10
- bottom: number;
11
- left: number;
12
- right: number;
13
- top: number;
14
- };