@atlaskit/editor-plugin-mentions 14.5.16 → 14.5.18

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,18 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 14.5.18
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2395ac6f0f1e1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2395ac6f0f1e1) -
8
+ Ensures agent profile card remains within viewport
9
+
10
+ ## 14.5.17
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 14.5.16
4
17
 
5
18
  ### Patch Changes
@@ -53,7 +53,7 @@ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
53
53
  var AGENT_MENTION_INACTIVITY_MS = 3000;
54
54
  var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
55
55
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
56
- var PACKAGE_VERSION = "14.5.15";
56
+ var PACKAGE_VERSION = "14.5.17";
57
57
  var setProvider = function setProvider(provider) {
58
58
  return function (state, dispatch) {
59
59
  if (dispatch) {
@@ -12,6 +12,7 @@ var _react = _interopRequireWildcard(require("react"));
12
12
  var _popper = require("@atlaskit/popper");
13
13
  var _portal = _interopRequireDefault(require("@atlaskit/portal"));
14
14
  var _constants = require("@atlaskit/theme/constants");
15
+ var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
15
16
  var _useFocusTrap = require("./useFocusTrap");
16
17
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
18
  // From `packages/design-system/popup/src/reposition-on-update.tsx`
@@ -31,6 +32,39 @@ var RepositionOnUpdate = exports.RepositionOnUpdate = function RepositionOnUpdat
31
32
  return children;
32
33
  };
33
34
 
35
+ /**
36
+ * Hook that attaches a ResizeObserver to the popup container div and calls
37
+ * forceUpdate whenever the popup's size changes. This handles the case where
38
+ * the popup content changes size due to internal state changes (e.g. the agent
39
+ * profile card transitioning from loading → loaded), which cannot be detected
40
+ * via the `children` prop dependency alone.
41
+ */
42
+ function useResizeAwarePopper(_ref2) {
43
+ var popupRef = _ref2.popupRef,
44
+ forceUpdate = _ref2.forceUpdate;
45
+ var forceUpdateRef = (0, _react.useRef)(forceUpdate);
46
+ (0, _react.useLayoutEffect)(function () {
47
+ forceUpdateRef.current = forceUpdate;
48
+ }, [forceUpdate]);
49
+ (0, _react.useEffect)(function () {
50
+ if (!popupRef || typeof ResizeObserver === 'undefined') {
51
+ return;
52
+ }
53
+ var observer = new ResizeObserver(function () {
54
+ // forceUpdate is synchronous unlike update() which is debounced.
55
+ // This ensures Popper recalculates position (and flips if needed)
56
+ // immediately when the popup content grows, before the browser repaints.
57
+ if (typeof forceUpdateRef.current === 'function') {
58
+ forceUpdateRef.current();
59
+ }
60
+ });
61
+ observer.observe(popupRef);
62
+ return function () {
63
+ return observer.disconnect();
64
+ };
65
+ }, [popupRef]);
66
+ }
67
+
34
68
  /**
35
69
  * A popup wrapper to match the behaviour of `@atlaskit/popup`
36
70
  *
@@ -42,9 +76,9 @@ var RepositionOnUpdate = exports.RepositionOnUpdate = function RepositionOnUpdat
42
76
  * @param children React.ReactNode - Returns the element to be positioned.
43
77
  * @returns React popper component
44
78
  */
45
- function Popup(_ref2) {
46
- var referenceElement = _ref2.referenceElement,
47
- children = _ref2.children;
79
+ function Popup(_ref3) {
80
+ var referenceElement = _ref3.referenceElement,
81
+ children = _ref3.children;
48
82
  var _React$useState = _react.default.useState(null),
49
83
  _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
50
84
  targetRef = _React$useState2[0],
@@ -61,26 +95,65 @@ function Popup(_ref2) {
61
95
  offset: [0, 8],
62
96
  placement: "bottom-end",
63
97
  strategy: "fixed"
64
- }, function (_ref3) {
65
- var _ref4 = _ref3.ref,
66
- style = _ref3.style,
67
- update = _ref3.update;
68
- return /*#__PURE__*/_react.default.createElement("div", {
69
- ref: function ref(node) {
70
- if (node) {
71
- if (typeof _ref4 === 'function') {
72
- _ref4(node);
73
- } else {
74
- _ref4.current = node;
75
- }
76
- setPopupRef(node);
77
- }
98
+ // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
99
+ ,
100
+ modifiers: (0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false) ? [{
101
+ name: 'flip',
102
+ options: {
103
+ rootBoundary: 'viewport',
104
+ padding: 5
78
105
  }
79
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
80
- ,
81
- style: style
82
- }, /*#__PURE__*/_react.default.createElement(RepositionOnUpdate, {
83
- update: update
84
- }, children));
106
+ }, {
107
+ name: 'preventOverflow',
108
+ options: {
109
+ rootBoundary: 'viewport',
110
+ padding: 5
111
+ }
112
+ }] : []
113
+ }, function (_ref4) {
114
+ var ref = _ref4.ref,
115
+ style = _ref4.style,
116
+ update = _ref4.update,
117
+ forceUpdate = _ref4.forceUpdate;
118
+ return /*#__PURE__*/_react.default.createElement(PopupInner, {
119
+ ref: ref,
120
+ style: style,
121
+ update: update,
122
+ forceUpdate: (0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false) ? forceUpdate : undefined,
123
+ setPopupRef: setPopupRef
124
+ }, children);
85
125
  })));
86
- }
126
+ }
127
+ var PopupInner = /*#__PURE__*/_react.default.forwardRef(function (_ref5, _ref6) {
128
+ var style = _ref5.style,
129
+ update = _ref5.update,
130
+ forceUpdate = _ref5.forceUpdate,
131
+ setPopupRef = _ref5.setPopupRef,
132
+ children = _ref5.children;
133
+ var _React$useState3 = _react.default.useState(null),
134
+ _React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
135
+ popupDiv = _React$useState4[0],
136
+ setPopupDiv = _React$useState4[1];
137
+ useResizeAwarePopper({
138
+ popupRef: popupDiv,
139
+ forceUpdate: forceUpdate
140
+ });
141
+ return /*#__PURE__*/_react.default.createElement("div", {
142
+ ref: function ref(node) {
143
+ if (node) {
144
+ if (typeof _ref6 === 'function') {
145
+ _ref6(node);
146
+ } else if (_ref6) {
147
+ _ref6.current = node;
148
+ }
149
+ setPopupRef(node);
150
+ setPopupDiv(node);
151
+ }
152
+ }
153
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
154
+ ,
155
+ style: style
156
+ }, /*#__PURE__*/_react.default.createElement(RepositionOnUpdate, {
157
+ update: update
158
+ }, children));
159
+ });
@@ -38,7 +38,7 @@ const AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
38
38
  const AGENT_MENTION_INACTIVITY_MS = 3000;
39
39
  const MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
40
40
  const PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
41
- const PACKAGE_VERSION = "14.5.15";
41
+ const PACKAGE_VERSION = "14.5.17";
42
42
  const setProvider = provider => (state, dispatch) => {
43
43
  if (dispatch) {
44
44
  dispatch(state.tr.setMeta(mentionPluginKey, {
@@ -1,7 +1,8 @@
1
- import React, { useRef, useEffect, Suspense } from 'react';
1
+ import React, { useRef, useLayoutEffect, useEffect, Suspense } from 'react';
2
2
  import { Popper as ReactPopper } from '@atlaskit/popper';
3
3
  import Portal from '@atlaskit/portal';
4
4
  import { layers } from '@atlaskit/theme/constants';
5
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
5
6
  import { useFocusTrap } from './useFocusTrap';
6
7
  // From `packages/design-system/popup/src/reposition-on-update.tsx`
7
8
  export const RepositionOnUpdate = ({
@@ -21,6 +22,38 @@ export const RepositionOnUpdate = ({
21
22
  return children;
22
23
  };
23
24
 
25
+ /**
26
+ * Hook that attaches a ResizeObserver to the popup container div and calls
27
+ * forceUpdate whenever the popup's size changes. This handles the case where
28
+ * the popup content changes size due to internal state changes (e.g. the agent
29
+ * profile card transitioning from loading → loaded), which cannot be detected
30
+ * via the `children` prop dependency alone.
31
+ */
32
+ function useResizeAwarePopper({
33
+ popupRef,
34
+ forceUpdate
35
+ }) {
36
+ const forceUpdateRef = useRef(forceUpdate);
37
+ useLayoutEffect(() => {
38
+ forceUpdateRef.current = forceUpdate;
39
+ }, [forceUpdate]);
40
+ useEffect(() => {
41
+ if (!popupRef || typeof ResizeObserver === 'undefined') {
42
+ return;
43
+ }
44
+ const observer = new ResizeObserver(() => {
45
+ // forceUpdate is synchronous unlike update() which is debounced.
46
+ // This ensures Popper recalculates position (and flips if needed)
47
+ // immediately when the popup content grows, before the browser repaints.
48
+ if (typeof forceUpdateRef.current === 'function') {
49
+ forceUpdateRef.current();
50
+ }
51
+ });
52
+ observer.observe(popupRef);
53
+ return () => observer.disconnect();
54
+ }, [popupRef]);
55
+ }
56
+
24
57
  /**
25
58
  * A popup wrapper to match the behaviour of `@atlaskit/popup`
26
59
  *
@@ -49,19 +82,56 @@ export function Popup({
49
82
  offset: [0, 8],
50
83
  placement: "bottom-end",
51
84
  strategy: "fixed"
85
+ // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
86
+ ,
87
+ modifiers: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? [{
88
+ name: 'flip',
89
+ options: {
90
+ rootBoundary: 'viewport',
91
+ padding: 5
92
+ }
93
+ }, {
94
+ name: 'preventOverflow',
95
+ options: {
96
+ rootBoundary: 'viewport',
97
+ padding: 5
98
+ }
99
+ }] : []
52
100
  }, ({
53
101
  ref,
54
102
  style,
55
- update
56
- }) => /*#__PURE__*/React.createElement("div", {
103
+ update,
104
+ forceUpdate
105
+ }) => /*#__PURE__*/React.createElement(PopupInner, {
106
+ ref: ref,
107
+ style: style,
108
+ update: update,
109
+ forceUpdate: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? forceUpdate : undefined,
110
+ setPopupRef: setPopupRef
111
+ }, children))));
112
+ }
113
+ const PopupInner = /*#__PURE__*/React.forwardRef(({
114
+ style,
115
+ update,
116
+ forceUpdate,
117
+ setPopupRef,
118
+ children
119
+ }, ref) => {
120
+ const [popupDiv, setPopupDiv] = React.useState(null);
121
+ useResizeAwarePopper({
122
+ popupRef: popupDiv,
123
+ forceUpdate
124
+ });
125
+ return /*#__PURE__*/React.createElement("div", {
57
126
  ref: node => {
58
127
  if (node) {
59
128
  if (typeof ref === 'function') {
60
129
  ref(node);
61
- } else {
130
+ } else if (ref) {
62
131
  ref.current = node;
63
132
  }
64
133
  setPopupRef(node);
134
+ setPopupDiv(node);
65
135
  }
66
136
  }
67
137
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
@@ -69,5 +139,5 @@ export function Popup({
69
139
  style: style
70
140
  }, /*#__PURE__*/React.createElement(RepositionOnUpdate, {
71
141
  update: update
72
- }, children)))));
73
- }
142
+ }, children));
143
+ });
@@ -45,7 +45,7 @@ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
45
45
  var AGENT_MENTION_INACTIVITY_MS = 3000;
46
46
  var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
47
47
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
48
- var PACKAGE_VERSION = "14.5.15";
48
+ var PACKAGE_VERSION = "14.5.17";
49
49
  var setProvider = function setProvider(provider) {
50
50
  return function (state, dispatch) {
51
51
  if (dispatch) {
@@ -1,8 +1,9 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import React, { useRef, useEffect, Suspense } from 'react';
2
+ import React, { useRef, useLayoutEffect, useEffect, Suspense } from 'react';
3
3
  import { Popper as ReactPopper } from '@atlaskit/popper';
4
4
  import Portal from '@atlaskit/portal';
5
5
  import { layers } from '@atlaskit/theme/constants';
6
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
6
7
  import { useFocusTrap } from './useFocusTrap';
7
8
  // From `packages/design-system/popup/src/reposition-on-update.tsx`
8
9
  export var RepositionOnUpdate = function RepositionOnUpdate(_ref) {
@@ -21,6 +22,39 @@ export var RepositionOnUpdate = function RepositionOnUpdate(_ref) {
21
22
  return children;
22
23
  };
23
24
 
25
+ /**
26
+ * Hook that attaches a ResizeObserver to the popup container div and calls
27
+ * forceUpdate whenever the popup's size changes. This handles the case where
28
+ * the popup content changes size due to internal state changes (e.g. the agent
29
+ * profile card transitioning from loading → loaded), which cannot be detected
30
+ * via the `children` prop dependency alone.
31
+ */
32
+ function useResizeAwarePopper(_ref2) {
33
+ var popupRef = _ref2.popupRef,
34
+ forceUpdate = _ref2.forceUpdate;
35
+ var forceUpdateRef = useRef(forceUpdate);
36
+ useLayoutEffect(function () {
37
+ forceUpdateRef.current = forceUpdate;
38
+ }, [forceUpdate]);
39
+ useEffect(function () {
40
+ if (!popupRef || typeof ResizeObserver === 'undefined') {
41
+ return;
42
+ }
43
+ var observer = new ResizeObserver(function () {
44
+ // forceUpdate is synchronous unlike update() which is debounced.
45
+ // This ensures Popper recalculates position (and flips if needed)
46
+ // immediately when the popup content grows, before the browser repaints.
47
+ if (typeof forceUpdateRef.current === 'function') {
48
+ forceUpdateRef.current();
49
+ }
50
+ });
51
+ observer.observe(popupRef);
52
+ return function () {
53
+ return observer.disconnect();
54
+ };
55
+ }, [popupRef]);
56
+ }
57
+
24
58
  /**
25
59
  * A popup wrapper to match the behaviour of `@atlaskit/popup`
26
60
  *
@@ -32,9 +66,9 @@ export var RepositionOnUpdate = function RepositionOnUpdate(_ref) {
32
66
  * @param children React.ReactNode - Returns the element to be positioned.
33
67
  * @returns React popper component
34
68
  */
35
- export function Popup(_ref2) {
36
- var referenceElement = _ref2.referenceElement,
37
- children = _ref2.children;
69
+ export function Popup(_ref3) {
70
+ var referenceElement = _ref3.referenceElement,
71
+ children = _ref3.children;
38
72
  var _React$useState = React.useState(null),
39
73
  _React$useState2 = _slicedToArray(_React$useState, 2),
40
74
  targetRef = _React$useState2[0],
@@ -51,26 +85,65 @@ export function Popup(_ref2) {
51
85
  offset: [0, 8],
52
86
  placement: "bottom-end",
53
87
  strategy: "fixed"
54
- }, function (_ref3) {
55
- var _ref4 = _ref3.ref,
56
- style = _ref3.style,
57
- update = _ref3.update;
58
- return /*#__PURE__*/React.createElement("div", {
59
- ref: function ref(node) {
60
- if (node) {
61
- if (typeof _ref4 === 'function') {
62
- _ref4(node);
63
- } else {
64
- _ref4.current = node;
65
- }
66
- setPopupRef(node);
67
- }
88
+ // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
89
+ ,
90
+ modifiers: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? [{
91
+ name: 'flip',
92
+ options: {
93
+ rootBoundary: 'viewport',
94
+ padding: 5
68
95
  }
69
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
70
- ,
71
- style: style
72
- }, /*#__PURE__*/React.createElement(RepositionOnUpdate, {
73
- update: update
74
- }, children));
96
+ }, {
97
+ name: 'preventOverflow',
98
+ options: {
99
+ rootBoundary: 'viewport',
100
+ padding: 5
101
+ }
102
+ }] : []
103
+ }, function (_ref4) {
104
+ var ref = _ref4.ref,
105
+ style = _ref4.style,
106
+ update = _ref4.update,
107
+ forceUpdate = _ref4.forceUpdate;
108
+ return /*#__PURE__*/React.createElement(PopupInner, {
109
+ ref: ref,
110
+ style: style,
111
+ update: update,
112
+ forceUpdate: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? forceUpdate : undefined,
113
+ setPopupRef: setPopupRef
114
+ }, children);
75
115
  })));
76
- }
116
+ }
117
+ var PopupInner = /*#__PURE__*/React.forwardRef(function (_ref5, _ref6) {
118
+ var style = _ref5.style,
119
+ update = _ref5.update,
120
+ forceUpdate = _ref5.forceUpdate,
121
+ setPopupRef = _ref5.setPopupRef,
122
+ children = _ref5.children;
123
+ var _React$useState3 = React.useState(null),
124
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
125
+ popupDiv = _React$useState4[0],
126
+ setPopupDiv = _React$useState4[1];
127
+ useResizeAwarePopper({
128
+ popupRef: popupDiv,
129
+ forceUpdate: forceUpdate
130
+ });
131
+ return /*#__PURE__*/React.createElement("div", {
132
+ ref: function ref(node) {
133
+ if (node) {
134
+ if (typeof _ref6 === 'function') {
135
+ _ref6(node);
136
+ } else if (_ref6) {
137
+ _ref6.current = node;
138
+ }
139
+ setPopupRef(node);
140
+ setPopupDiv(node);
141
+ }
142
+ }
143
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
144
+ ,
145
+ style: style
146
+ }, /*#__PURE__*/React.createElement(RepositionOnUpdate, {
147
+ update: update
148
+ }, children));
149
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "14.5.16",
3
+ "version": "14.5.18",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  "@atlaskit/profilecard": "^26.8.0",
42
42
  "@atlaskit/teams-app-config": "^2.1.0",
43
43
  "@atlaskit/theme": "^26.1.0",
44
- "@atlaskit/tmp-editor-statsig": "^123.0.0",
44
+ "@atlaskit/tmp-editor-statsig": "^124.0.0",
45
45
  "@atlaskit/tokens": "^15.5.0",
46
46
  "@atlaskit/tooltip": "^23.1.0",
47
47
  "@atlaskit/user-picker": "^13.4.0",