@atlaskit/editor-plugin-selection-extension 3.4.1 → 3.4.2

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-extension
2
2
 
3
+ ## 3.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`373e833d95d52`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/373e833d95d52) -
8
+ [ux] COMMIT-19456:Fix forge app coords bug
9
+ - Updated dependencies
10
+
3
11
  ## 3.4.1
4
12
 
5
13
  ### Patch Changes
@@ -9,6 +9,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _messages = require("@atlaskit/editor-common/messages");
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
12
13
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
14
  var _actions = require("./pm-plugins/actions");
14
15
  var _insertAdfAtEndOfDoc2 = require("./pm-plugins/actions/insertAdfAtEndOfDoc");
@@ -169,12 +170,19 @@ var selectionExtensionPlugin = exports.selectionExtensionPlugin = function selec
169
170
  return;
170
171
  }
171
172
  var getSelection = function getSelection(view) {
173
+ var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode2;
172
174
  // ensure the same document state is applied to editor view to avoid mismatches
173
175
  var currentSelection = view.state.selection;
176
+ var toolbarDocking = (0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
177
+ var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 || (_api$editorViewMode2 = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.mode) === 'edit');
178
+ var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && (0, _platformFeatureFlags.fg)('platform_editor_selection_extension_api_v2');
174
179
  var from = currentSelection.from,
175
180
  to = currentSelection.to;
176
181
  var text = view.state.doc.textBetween(from, to, '\n');
177
- var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to);
182
+ var coords = (0, _getBoundingBoxFromSelection.getBoundingBoxFromSelection)(view, from, to, {
183
+ top: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0,
184
+ bottom: shouldOffsetToolbarHeight ? _editorSharedStyles.akEditorFullPageToolbarHeight : 0
185
+ });
178
186
  return {
179
187
  text: text,
180
188
  from: from,
@@ -10,9 +10,14 @@ exports.getBoundingBoxFromSelection = void 0;
10
10
  * @param view - The editor view instance.
11
11
  * @param from - The starting position of the selection.
12
12
  * @param to - The ending position of the selection.
13
+ * @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
13
14
  * @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
14
15
  */
15
16
  var getBoundingBoxFromSelection = exports.getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
17
+ var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
18
+ top: 0,
19
+ bottom: 0
20
+ };
16
21
  var top = Infinity,
17
22
  left = Infinity,
18
23
  bottom = -Infinity,
@@ -26,6 +31,8 @@ var getBoundingBoxFromSelection = exports.getBoundingBoxFromSelection = function
26
31
  bottom = Math.max(bottom, coords.bottom);
27
32
  right = Math.max(right, coords.right);
28
33
  }
34
+ top = top - offset.top;
35
+ bottom = bottom - offset.bottom;
29
36
  return {
30
37
  top: top,
31
38
  left: left,
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { insertSmartLinks } from './pm-plugins/actions';
6
7
  import { insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
@@ -162,16 +163,23 @@ export const selectionExtensionPlugin = ({
162
163
  return;
163
164
  }
164
165
  const getSelection = view => {
166
+ var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3, _api$editorViewMode2, _api$editorViewMode2$;
165
167
  // ensure the same document state is applied to editor view to avoid mismatches
166
168
  const {
167
169
  selection: currentSelection
168
170
  } = view.state;
171
+ const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : (_api$userPreferences$ = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences$ === void 0 ? void 0 : (_api$userPreferences$2 = _api$userPreferences$.preferences) === null || _api$userPreferences$2 === void 0 ? void 0 : _api$userPreferences$2.toolbarDockingPosition : api === null || api === void 0 ? void 0 : (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 ? void 0 : (_api$selectionToolbar2 = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.currentState()) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.toolbarDocking;
172
+ const isEditMode = Boolean((api === null || api === void 0 ? void 0 : (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 ? void 0 : (_api$editorViewMode2$ = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2$ === void 0 ? void 0 : _api$editorViewMode2$.mode) === 'edit');
173
+ const shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
169
174
  const {
170
175
  from,
171
176
  to
172
177
  } = currentSelection;
173
178
  const text = view.state.doc.textBetween(from, to, '\n');
174
- const coords = getBoundingBoxFromSelection(view, from, to);
179
+ const coords = getBoundingBoxFromSelection(view, from, to, {
180
+ top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
181
+ bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
182
+ });
175
183
  return {
176
184
  text,
177
185
  from,
@@ -4,9 +4,13 @@
4
4
  * @param view - The editor view instance.
5
5
  * @param from - The starting position of the selection.
6
6
  * @param to - The ending position of the selection.
7
+ * @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
7
8
  * @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
8
9
  */
9
- export const getBoundingBoxFromSelection = (view, from, to) => {
10
+ export const getBoundingBoxFromSelection = (view, from, to, offset = {
11
+ top: 0,
12
+ bottom: 0
13
+ }) => {
10
14
  let top = Infinity,
11
15
  left = Infinity,
12
16
  bottom = -Infinity,
@@ -20,6 +24,8 @@ export const getBoundingBoxFromSelection = (view, from, to) => {
20
24
  bottom = Math.max(bottom, coords.bottom);
21
25
  right = Math.max(right, coords.right);
22
26
  }
27
+ top = top - offset.top;
28
+ bottom = bottom - offset.bottom;
23
29
  return {
24
30
  top,
25
31
  left,
@@ -2,6 +2,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import React from 'react';
3
3
  import { selectionExtensionMessages } from '@atlaskit/editor-common/messages';
4
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
+ import { akEditorFullPageToolbarHeight } from '@atlaskit/editor-shared-styles';
5
6
  import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { insertSmartLinks as _insertSmartLinks } from './pm-plugins/actions';
7
8
  import { insertAdfAtEndOfDoc as _insertAdfAtEndOfDoc } from './pm-plugins/actions/insertAdfAtEndOfDoc';
@@ -162,12 +163,19 @@ export var selectionExtensionPlugin = function selectionExtensionPlugin(_ref) {
162
163
  return;
163
164
  }
164
165
  var getSelection = function getSelection(view) {
166
+ var _api$userPreferences, _api$selectionToolbar, _api$editorViewMode2;
165
167
  // ensure the same document state is applied to editor view to avoid mismatches
166
168
  var currentSelection = view.state.selection;
169
+ var toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
170
+ var isEditMode = Boolean((api === null || api === void 0 || (_api$editorViewMode2 = api.editorViewMode) === null || _api$editorViewMode2 === void 0 || (_api$editorViewMode2 = _api$editorViewMode2.sharedState.currentState()) === null || _api$editorViewMode2 === void 0 ? void 0 : _api$editorViewMode2.mode) === 'edit');
171
+ var shouldOffsetToolbarHeight = toolbarDocking === 'top' && isEditMode && fg('platform_editor_selection_extension_api_v2');
167
172
  var from = currentSelection.from,
168
173
  to = currentSelection.to;
169
174
  var text = view.state.doc.textBetween(from, to, '\n');
170
- var coords = getBoundingBoxFromSelection(view, from, to);
175
+ var coords = getBoundingBoxFromSelection(view, from, to, {
176
+ top: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0,
177
+ bottom: shouldOffsetToolbarHeight ? akEditorFullPageToolbarHeight : 0
178
+ });
171
179
  return {
172
180
  text: text,
173
181
  from: from,
@@ -4,9 +4,14 @@
4
4
  * @param view - The editor view instance.
5
5
  * @param from - The starting position of the selection.
6
6
  * @param to - The ending position of the selection.
7
+ * @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
7
8
  * @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
8
9
  */
9
10
  export var getBoundingBoxFromSelection = function getBoundingBoxFromSelection(view, from, to) {
11
+ var offset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
12
+ top: 0,
13
+ bottom: 0
14
+ };
10
15
  var top = Infinity,
11
16
  left = Infinity,
12
17
  bottom = -Infinity,
@@ -20,6 +25,8 @@ export var getBoundingBoxFromSelection = function getBoundingBoxFromSelection(vi
20
25
  bottom = Math.max(bottom, coords.bottom);
21
26
  right = Math.max(right, coords.right);
22
27
  }
28
+ top = top - offset.top;
29
+ bottom = bottom - offset.bottom;
23
30
  return {
24
31
  top: top,
25
32
  left: left,
@@ -4,6 +4,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
6
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
7
+ import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
7
8
  import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
8
9
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
9
10
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
@@ -11,6 +12,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
11
12
  OptionalPlugin<AnalyticsPlugin>,
12
13
  OptionalPlugin<EditorViewModePlugin>,
13
14
  OptionalPlugin<PrimaryToolbarPlugin>,
15
+ OptionalPlugin<UserPreferencesPlugin>,
14
16
  SelectionToolbarPlugin
15
17
  ];
16
18
  sharedState: SelectionExtensionPluginState | null;
@@ -75,6 +75,10 @@ export type SelectionExtensionCoords = {
75
75
  top: number;
76
76
  bottom: number;
77
77
  };
78
+ export type BoundingBoxOffset = {
79
+ top: number;
80
+ bottom: number;
81
+ };
78
82
  export type InsertPosition = {
79
83
  pointer: string;
80
84
  from?: number;
@@ -1,11 +1,12 @@
1
1
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
- import type { SelectionExtensionCoords } from '../types';
2
+ import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
3
3
  /**
4
4
  * Calculates the bounding box coordinates of a text selection within an editor view.
5
5
  *
6
6
  * @param view - The editor view instance.
7
7
  * @param from - The starting position of the selection.
8
8
  * @param to - The ending position of the selection.
9
+ * @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
9
10
  * @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
10
11
  */
11
- export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number) => SelectionExtensionCoords;
12
+ export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
@@ -4,6 +4,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
5
5
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
6
6
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
7
+ import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
7
8
  import type { DynamicSelectionExtension, InsertAdfAtEndOfDocResult, LinkInsertionOption, ReplaceWithAdfResult, SelectionExtension, SelectionExtensionPluginOptions, SelectionExtensionPluginState, SelectionExtensionSelectionInfo } from './types';
8
9
  export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
9
10
  pluginConfiguration: SelectionExtensionPluginOptions | undefined;
@@ -11,6 +12,7 @@ export type SelectionExtensionPlugin = NextEditorPlugin<'selectionExtension', {
11
12
  OptionalPlugin<AnalyticsPlugin>,
12
13
  OptionalPlugin<EditorViewModePlugin>,
13
14
  OptionalPlugin<PrimaryToolbarPlugin>,
15
+ OptionalPlugin<UserPreferencesPlugin>,
14
16
  SelectionToolbarPlugin
15
17
  ];
16
18
  sharedState: SelectionExtensionPluginState | null;
@@ -75,6 +75,10 @@ export type SelectionExtensionCoords = {
75
75
  top: number;
76
76
  bottom: number;
77
77
  };
78
+ export type BoundingBoxOffset = {
79
+ top: number;
80
+ bottom: number;
81
+ };
78
82
  export type InsertPosition = {
79
83
  pointer: string;
80
84
  from?: number;
@@ -1,11 +1,12 @@
1
1
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
- import type { SelectionExtensionCoords } from '../types';
2
+ import type { SelectionExtensionCoords, BoundingBoxOffset } from '../types';
3
3
  /**
4
4
  * Calculates the bounding box coordinates of a text selection within an editor view.
5
5
  *
6
6
  * @param view - The editor view instance.
7
7
  * @param from - The starting position of the selection.
8
8
  * @param to - The ending position of the selection.
9
+ * @param offset - Optional offset to adjust the top and bottom coordinates of the bounding box.`
9
10
  * @returns An object containing the top, left, bottom, and right coordinates of the bounding box.
10
11
  */
11
- export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number) => SelectionExtensionCoords;
12
+ export declare const getBoundingBoxFromSelection: (view: EditorView, from: number, to: number, offset?: BoundingBoxOffset) => SelectionExtensionCoords;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-extension",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
4
4
  "description": "editor-plugin-selection-extension plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,19 +41,21 @@
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
42
42
  "@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
43
43
  "@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
44
+ "@atlaskit/editor-plugin-user-preferences": "^1.2.0",
44
45
  "@atlaskit/editor-prosemirror": "7.0.0",
46
+ "@atlaskit/editor-shared-styles": "^3.5.0",
45
47
  "@atlaskit/editor-tables": "^2.9.0",
46
48
  "@atlaskit/icon": "^27.8.0",
47
49
  "@atlaskit/platform-feature-flags": "^1.1.0",
48
50
  "@atlaskit/primitives": "^14.11.0",
49
- "@atlaskit/tmp-editor-statsig": "^9.17.0",
51
+ "@atlaskit/tmp-editor-statsig": "^9.20.0",
50
52
  "@babel/runtime": "^7.0.0",
51
53
  "lodash": "^4.17.21",
52
54
  "react-intl-next": "npm:react-intl@^5.18.1",
53
55
  "uuid": "^3.1.0"
54
56
  },
55
57
  "peerDependencies": {
56
- "@atlaskit/editor-common": "^107.13.0",
58
+ "@atlaskit/editor-common": "^107.16.0",
57
59
  "react": "^18.2.0"
58
60
  },
59
61
  "devDependencies": {
@@ -110,6 +112,9 @@
110
112
  },
111
113
  "platform_editor_selection_extension_api_v2": {
112
114
  "type": "boolean"
115
+ },
116
+ "platform_editor_use_preferences_plugin": {
117
+ "type": "boolean"
113
118
  }
114
119
  }
115
120
  }