@atlaskit/editor-common 134.1.1 → 134.1.3

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,23 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 134.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`96fcf7d06fe72`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/96fcf7d06fe72) -
8
+ Fixed `Layer` not calling `onPositioned` when the top layer is on.
9
+ - Updated dependencies
10
+
11
+ ## 134.1.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [`9e0f075939161`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9e0f075939161) -
16
+ Deduplicate registered Quick Insert items across recommended, search, and browse views, while
17
+ preserving selection identity and registration context when `platform_editor_slash_command` is
18
+ enabled.
19
+ - Updated dependencies
20
+
3
21
  ## 134.1.1
4
22
 
5
23
  ### Patch Changes
@@ -27,7 +27,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
27
27
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
28
28
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
29
29
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
30
- var packageVersion = "134.1.0";
30
+ var packageVersion = "134.1.2";
31
31
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
32
32
  // Remove URL as it has UGC
33
33
  // Ignored via go/ees007
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.reconcileRegisteredMenuSelection = void 0;
7
+ /** Keeps selection attached to the same registration when live menu updates reorder rows. */
8
+ var reconcileRegisteredMenuSelection = exports.reconcileRegisteredMenuSelection = function reconcileRegisteredMenuSelection(_ref) {
9
+ var nextIdentities = _ref.nextIdentities,
10
+ previousIdentities = _ref.previousIdentities,
11
+ previousIndex = _ref.previousIndex,
12
+ reset = _ref.reset;
13
+ if (nextIdentities.length === 0) {
14
+ return -1;
15
+ }
16
+ if (reset) {
17
+ return 0;
18
+ }
19
+ var previousIdentity = previousIdentities[previousIndex];
20
+ if (previousIdentity !== undefined) {
21
+ var nextIndex = nextIdentities.indexOf(previousIdentity);
22
+ if (nextIndex >= 0) {
23
+ return nextIndex;
24
+ }
25
+ }
26
+ return Math.min(Math.max(previousIndex, 0), nextIdentities.length - 1);
27
+ };
@@ -6,10 +6,14 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.useRegisteredMenu = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
9
10
  var _react = require("react");
10
11
  var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
11
- var _getRegisteredMenuRows = require("./getRegisteredMenuRows");
12
12
  var _useRegisteredMenuSelection = require("./useRegisteredMenuSelection");
13
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
+ var getSelectableItemIdentity = function getSelectableItemIdentity(item, scope) {
15
+ return JSON.stringify([scope.type, scope.type === 'section' ? scope.sectionKey : undefined, (0, _surfaceRenderer.getComponentIdentity)(item)]);
16
+ };
13
17
  /**
14
18
  * Connects menu rows to keyboard selection and tracks which item is active through
15
19
  * keyboard, pointer and focus events. Selection controls navigation; activation lets
@@ -20,18 +24,37 @@ var useRegisteredMenu = exports.useRegisteredMenu = function useRegisteredMenu(_
20
24
  var model = _ref.model,
21
25
  resetKey = _ref.resetKey;
22
26
  var _useMemo = (0, _react.useMemo)(function () {
23
- var rows = (0, _getRegisteredMenuRows.getRegisteredMenuRows)(model);
27
+ var rows = [];
24
28
  var selectableItems = [];
25
29
  var selectableItemIdentities = [];
26
- rows.forEach(function (row) {
27
- if (row.type === 'menu-item') {
28
- selectableItems.push(row);
29
- selectableItemIdentities.push((0, _surfaceRenderer.getComponentIdentity)(row));
30
- }
30
+ var appendItem = function appendItem(item, scope) {
31
+ rows.push(item);
32
+ selectableItems.push(item);
33
+ // A shared item key in another section is a different selection target.
34
+ selectableItemIdentities.push(getSelectableItemIdentity(item, scope));
35
+ };
36
+ model.sections.forEach(function (_ref2) {
37
+ var _ref3 = (0, _toArray2.default)(_ref2),
38
+ section = _ref3[0],
39
+ items = _arrayLikeToArray(_ref3).slice(1);
40
+ rows.push(section);
41
+ items.forEach(function (item) {
42
+ return appendItem(item, {
43
+ sectionKey: (0, _surfaceRenderer.getComponentIdentity)(section),
44
+ type: 'section'
45
+ });
46
+ });
47
+ });
48
+ model.fallbackItems.forEach(function (item) {
49
+ return appendItem(item, {
50
+ type: 'fallback'
51
+ });
31
52
  });
32
53
  // The footer participates in navigation but is rendered outside the scrolling rows.
33
54
  if (model.footer) {
34
- selectableItemIdentities.push((0, _surfaceRenderer.getComponentIdentity)(model.footer));
55
+ selectableItemIdentities.push(getSelectableItemIdentity(model.footer, {
56
+ type: 'footer'
57
+ }));
35
58
  }
36
59
  return {
37
60
  rows: rows,
@@ -7,9 +7,11 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.useRegisteredMenuSelection = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
+ var _reconcileRegisteredMenuSelection = require("./reconcileRegisteredMenuSelection");
10
11
  /**
11
- * Resets keyboard selection when the ordered items or reset key changes.
12
- * The caller chooses the key, for example a search term or the current category.
12
+ * Keeps selection on the same item as items reorder. If that item disappears,
13
+ * keeps the previous index within the remaining items. A changed reset key
14
+ * selects the first item instead.
13
15
  */
14
16
  var useRegisteredMenuSelection = exports.useRegisteredMenuSelection = function useRegisteredMenuSelection(_ref) {
15
17
  var identities = _ref.identities,
@@ -21,17 +23,28 @@ var useRegisteredMenuSelection = exports.useRegisteredMenuSelection = function u
21
23
  selectedIndex = _useState2[0],
22
24
  setSelectedIndex = _useState2[1];
23
25
  var selectedIndexRef = (0, _react.useRef)(selectedIndex);
24
- var identitySignature = (0, _react.useMemo)(function () {
25
- return JSON.stringify(identities);
26
- }, [identities]);
26
+ var previousRef = (0, _react.useRef)({
27
+ identities: identities,
28
+ resetKey: resetKey
29
+ });
27
30
  var itemCount = identities.length;
28
31
  var select = (0, _react.useCallback)(function (index) {
29
32
  selectedIndexRef.current = index;
30
33
  setSelectedIndex(index);
31
34
  }, []);
32
35
  (0, _react.useLayoutEffect)(function () {
33
- select(itemCount > 0 ? 0 : -1);
34
- }, [identitySignature, itemCount, resetKey, select]);
36
+ var previous = previousRef.current;
37
+ previousRef.current = {
38
+ identities: identities,
39
+ resetKey: resetKey
40
+ };
41
+ select((0, _reconcileRegisteredMenuSelection.reconcileRegisteredMenuSelection)({
42
+ nextIdentities: identities,
43
+ previousIdentities: previous.identities,
44
+ previousIndex: selectedIndexRef.current,
45
+ reset: previous.resetKey !== resetKey
46
+ }));
47
+ }, [identities, resetKey, select]);
35
48
  var selectNext = (0, _react.useCallback)(function () {
36
49
  var currentIndex = selectedIndexRef.current;
37
50
  var nextIndex = itemCount === 0 ? -1 : currentIndex < 0 ? 0 : (currentIndex + 1) % itemCount;
@@ -23,7 +23,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
23
23
  * @jsx jsx
24
24
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
25
25
  var packageName = "@atlaskit/editor-common";
26
- var packageVersion = "134.1.0";
26
+ var packageVersion = "134.1.2";
27
27
  var halfFocusRing = 1;
28
28
  var dropOffset = '0, 8';
29
29
  // Ignored via go/ees005
@@ -236,12 +236,23 @@ var popperInteropModifiers = [{
236
236
  enabled: false
237
237
  }];
238
238
  function usePopperInteropModifiers(_ref2) {
239
- var onPositioned = _ref2.onPositioned;
239
+ var isContentShown = _ref2.isContentShown,
240
+ onPositioned = _ref2.onPositioned;
240
241
  var onPositionedRef = (0, _react.useRef)(onPositioned);
241
242
  var hasPositionedRef = (0, _react.useRef)(false);
242
243
  (0, _react.useLayoutEffect)(function () {
243
244
  onPositionedRef.current = onPositioned;
244
245
  }, [onPositioned]);
246
+
247
+ // On the top-layer path `@atlaskit/popper` ignores `modifiers`: CSS Anchor Positioning places
248
+ // the content when it mounts. So report the first position once the content is shown.
249
+ (0, _react.useLayoutEffect)(function () {
250
+ if (!(0, _fg.fg)('platform-dst-top-layer') || !isContentShown || hasPositionedRef.current) {
251
+ return;
252
+ }
253
+ hasPositionedRef.current = true;
254
+ onPositionedRef.current();
255
+ }, [isContentShown]);
245
256
  return (0, _react.useMemo)(function () {
246
257
  return [].concat(popperInteropModifiers, [{
247
258
  name: 'editorLayerFirstPositioned',
@@ -270,7 +281,9 @@ function PopperInterop(_ref3) {
270
281
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
271
282
  referenceElement = _useState2[0],
272
283
  setReferenceElement = _useState2[1];
284
+ var isContentShown = Boolean(content && referenceElement);
273
285
  var modifiers = usePopperInteropModifiers({
286
+ isContentShown: isContentShown,
274
287
  onPositioned: onPositioned
275
288
  });
276
289
  // Popper v2 compares the offset prop by reference, so memoise to avoid re-running positioning every render.
@@ -13,7 +13,7 @@ const NETWORK_FAILURE_REGEX = /^network failure/i;
13
13
  const RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
14
14
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
15
15
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
16
- const packageVersion = "134.1.0";
16
+ const packageVersion = "134.1.2";
17
17
  const sanitiseSentryEvents = (data, _hint) => {
18
18
  // Remove URL as it has UGC
19
19
  // Ignored via go/ees007
@@ -0,0 +1,22 @@
1
+ /** Keeps selection attached to the same registration when live menu updates reorder rows. */
2
+ export const reconcileRegisteredMenuSelection = ({
3
+ nextIdentities,
4
+ previousIdentities,
5
+ previousIndex,
6
+ reset
7
+ }) => {
8
+ if (nextIdentities.length === 0) {
9
+ return -1;
10
+ }
11
+ if (reset) {
12
+ return 0;
13
+ }
14
+ const previousIdentity = previousIdentities[previousIndex];
15
+ if (previousIdentity !== undefined) {
16
+ const nextIndex = nextIdentities.indexOf(previousIdentity);
17
+ if (nextIndex >= 0) {
18
+ return nextIndex;
19
+ }
20
+ }
21
+ return Math.min(Math.max(previousIndex, 0), nextIdentities.length - 1);
22
+ };
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
2
2
  import { getComponentIdentity } from '@atlaskit/editor-ui-control-model/surface-renderer';
3
- import { getRegisteredMenuRows } from './getRegisteredMenuRows';
4
3
  import { useRegisteredMenuSelection } from './useRegisteredMenuSelection';
4
+ const getSelectableItemIdentity = (item, scope) => JSON.stringify([scope.type, scope.type === 'section' ? scope.sectionKey : undefined, getComponentIdentity(item)]);
5
5
  /**
6
6
  * Connects menu rows to keyboard selection and tracks which item is active through
7
7
  * keyboard, pointer and focus events. Selection controls navigation; activation lets
@@ -17,18 +17,30 @@ export const useRegisteredMenu = ({
17
17
  selectableItems,
18
18
  selectableItemIdentities
19
19
  } = useMemo(() => {
20
- const rows = getRegisteredMenuRows(model);
20
+ const rows = [];
21
21
  const selectableItems = [];
22
22
  const selectableItemIdentities = [];
23
- rows.forEach(row => {
24
- if (row.type === 'menu-item') {
25
- selectableItems.push(row);
26
- selectableItemIdentities.push(getComponentIdentity(row));
27
- }
23
+ const appendItem = (item, scope) => {
24
+ rows.push(item);
25
+ selectableItems.push(item);
26
+ // A shared item key in another section is a different selection target.
27
+ selectableItemIdentities.push(getSelectableItemIdentity(item, scope));
28
+ };
29
+ model.sections.forEach(([section, ...items]) => {
30
+ rows.push(section);
31
+ items.forEach(item => appendItem(item, {
32
+ sectionKey: getComponentIdentity(section),
33
+ type: 'section'
34
+ }));
28
35
  });
36
+ model.fallbackItems.forEach(item => appendItem(item, {
37
+ type: 'fallback'
38
+ }));
29
39
  // The footer participates in navigation but is rendered outside the scrolling rows.
30
40
  if (model.footer) {
31
- selectableItemIdentities.push(getComponentIdentity(model.footer));
41
+ selectableItemIdentities.push(getSelectableItemIdentity(model.footer, {
42
+ type: 'footer'
43
+ }));
32
44
  }
33
45
  return {
34
46
  rows,
@@ -1,7 +1,9 @@
1
- import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
1
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
2
+ import { reconcileRegisteredMenuSelection } from './reconcileRegisteredMenuSelection';
2
3
  /**
3
- * Resets keyboard selection when the ordered items or reset key changes.
4
- * The caller chooses the key, for example a search term or the current category.
4
+ * Keeps selection on the same item as items reorder. If that item disappears,
5
+ * keeps the previous index within the remaining items. A changed reset key
6
+ * selects the first item instead.
5
7
  */
6
8
  export const useRegisteredMenuSelection = ({
7
9
  identities,
@@ -9,15 +11,28 @@ export const useRegisteredMenuSelection = ({
9
11
  }) => {
10
12
  const [selectedIndex, setSelectedIndex] = useState(() => identities.length > 0 ? 0 : -1);
11
13
  const selectedIndexRef = useRef(selectedIndex);
12
- const identitySignature = useMemo(() => JSON.stringify(identities), [identities]);
14
+ const previousRef = useRef({
15
+ identities,
16
+ resetKey
17
+ });
13
18
  const itemCount = identities.length;
14
19
  const select = useCallback(index => {
15
20
  selectedIndexRef.current = index;
16
21
  setSelectedIndex(index);
17
22
  }, []);
18
23
  useLayoutEffect(() => {
19
- select(itemCount > 0 ? 0 : -1);
20
- }, [identitySignature, itemCount, resetKey, select]);
24
+ const previous = previousRef.current;
25
+ previousRef.current = {
26
+ identities,
27
+ resetKey
28
+ };
29
+ select(reconcileRegisteredMenuSelection({
30
+ nextIdentities: identities,
31
+ previousIdentities: previous.identities,
32
+ previousIndex: selectedIndexRef.current,
33
+ reset: previous.resetKey !== resetKey
34
+ }));
35
+ }, [identities, resetKey, select]);
21
36
  const selectNext = useCallback(() => {
22
37
  const currentIndex = selectedIndexRef.current;
23
38
  const nextIndex = itemCount === 0 ? -1 : currentIndex < 0 ? 0 : (currentIndex + 1) % itemCount;
@@ -13,7 +13,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
13
13
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import Layer from '../Layer';
15
15
  const packageName = "@atlaskit/editor-common";
16
- const packageVersion = "134.1.0";
16
+ const packageVersion = "134.1.2";
17
17
  const halfFocusRing = 1;
18
18
  const dropOffset = '0, 8';
19
19
  // Ignored via go/ees005
@@ -206,6 +206,7 @@ const popperInteropModifiers = [{
206
206
  enabled: false
207
207
  }];
208
208
  function usePopperInteropModifiers({
209
+ isContentShown,
209
210
  onPositioned
210
211
  }) {
211
212
  const onPositionedRef = useRef(onPositioned);
@@ -213,6 +214,16 @@ function usePopperInteropModifiers({
213
214
  useLayoutEffect(() => {
214
215
  onPositionedRef.current = onPositioned;
215
216
  }, [onPositioned]);
217
+
218
+ // On the top-layer path `@atlaskit/popper` ignores `modifiers`: CSS Anchor Positioning places
219
+ // the content when it mounts. So report the first position once the content is shown.
220
+ useLayoutEffect(() => {
221
+ if (!fg('platform-dst-top-layer') || !isContentShown || hasPositionedRef.current) {
222
+ return;
223
+ }
224
+ hasPositionedRef.current = true;
225
+ onPositionedRef.current();
226
+ }, [isContentShown]);
216
227
  return useMemo(() => [...popperInteropModifiers, {
217
228
  name: 'editorLayerFirstPositioned',
218
229
  enabled: true,
@@ -237,7 +248,9 @@ function PopperInterop({
237
248
  }) {
238
249
  const targetRef = useRef(null);
239
250
  const [referenceElement, setReferenceElement] = useState(null);
251
+ const isContentShown = Boolean(content && referenceElement);
240
252
  const modifiers = usePopperInteropModifiers({
253
+ isContentShown,
241
254
  onPositioned
242
255
  });
243
256
  // Popper v2 compares the offset prop by reference, so memoise to avoid re-running positioning every render.
@@ -19,7 +19,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
19
19
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
20
20
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
21
21
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
22
- var packageVersion = "134.1.0";
22
+ var packageVersion = "134.1.2";
23
23
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
24
24
  // Remove URL as it has UGC
25
25
  // Ignored via go/ees007
@@ -0,0 +1,21 @@
1
+ /** Keeps selection attached to the same registration when live menu updates reorder rows. */
2
+ export var reconcileRegisteredMenuSelection = function reconcileRegisteredMenuSelection(_ref) {
3
+ var nextIdentities = _ref.nextIdentities,
4
+ previousIdentities = _ref.previousIdentities,
5
+ previousIndex = _ref.previousIndex,
6
+ reset = _ref.reset;
7
+ if (nextIdentities.length === 0) {
8
+ return -1;
9
+ }
10
+ if (reset) {
11
+ return 0;
12
+ }
13
+ var previousIdentity = previousIdentities[previousIndex];
14
+ if (previousIdentity !== undefined) {
15
+ var nextIndex = nextIdentities.indexOf(previousIdentity);
16
+ if (nextIndex >= 0) {
17
+ return nextIndex;
18
+ }
19
+ }
20
+ return Math.min(Math.max(previousIndex, 0), nextIdentities.length - 1);
21
+ };
@@ -1,8 +1,12 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _toArray from "@babel/runtime/helpers/toArray";
3
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2
4
  import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
3
5
  import { getComponentIdentity } from '@atlaskit/editor-ui-control-model/surface-renderer';
4
- import { getRegisteredMenuRows } from './getRegisteredMenuRows';
5
6
  import { useRegisteredMenuSelection } from './useRegisteredMenuSelection';
7
+ var getSelectableItemIdentity = function getSelectableItemIdentity(item, scope) {
8
+ return JSON.stringify([scope.type, scope.type === 'section' ? scope.sectionKey : undefined, getComponentIdentity(item)]);
9
+ };
6
10
  /**
7
11
  * Connects menu rows to keyboard selection and tracks which item is active through
8
12
  * keyboard, pointer and focus events. Selection controls navigation; activation lets
@@ -13,18 +17,37 @@ export var useRegisteredMenu = function useRegisteredMenu(_ref) {
13
17
  var model = _ref.model,
14
18
  resetKey = _ref.resetKey;
15
19
  var _useMemo = useMemo(function () {
16
- var rows = getRegisteredMenuRows(model);
20
+ var rows = [];
17
21
  var selectableItems = [];
18
22
  var selectableItemIdentities = [];
19
- rows.forEach(function (row) {
20
- if (row.type === 'menu-item') {
21
- selectableItems.push(row);
22
- selectableItemIdentities.push(getComponentIdentity(row));
23
- }
23
+ var appendItem = function appendItem(item, scope) {
24
+ rows.push(item);
25
+ selectableItems.push(item);
26
+ // A shared item key in another section is a different selection target.
27
+ selectableItemIdentities.push(getSelectableItemIdentity(item, scope));
28
+ };
29
+ model.sections.forEach(function (_ref2) {
30
+ var _ref3 = _toArray(_ref2),
31
+ section = _ref3[0],
32
+ items = _arrayLikeToArray(_ref3).slice(1);
33
+ rows.push(section);
34
+ items.forEach(function (item) {
35
+ return appendItem(item, {
36
+ sectionKey: getComponentIdentity(section),
37
+ type: 'section'
38
+ });
39
+ });
40
+ });
41
+ model.fallbackItems.forEach(function (item) {
42
+ return appendItem(item, {
43
+ type: 'fallback'
44
+ });
24
45
  });
25
46
  // The footer participates in navigation but is rendered outside the scrolling rows.
26
47
  if (model.footer) {
27
- selectableItemIdentities.push(getComponentIdentity(model.footer));
48
+ selectableItemIdentities.push(getSelectableItemIdentity(model.footer, {
49
+ type: 'footer'
50
+ }));
28
51
  }
29
52
  return {
30
53
  rows: rows,
@@ -1,8 +1,10 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
2
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
3
+ import { reconcileRegisteredMenuSelection } from './reconcileRegisteredMenuSelection';
3
4
  /**
4
- * Resets keyboard selection when the ordered items or reset key changes.
5
- * The caller chooses the key, for example a search term or the current category.
5
+ * Keeps selection on the same item as items reorder. If that item disappears,
6
+ * keeps the previous index within the remaining items. A changed reset key
7
+ * selects the first item instead.
6
8
  */
7
9
  export var useRegisteredMenuSelection = function useRegisteredMenuSelection(_ref) {
8
10
  var identities = _ref.identities,
@@ -14,17 +16,28 @@ export var useRegisteredMenuSelection = function useRegisteredMenuSelection(_ref
14
16
  selectedIndex = _useState2[0],
15
17
  setSelectedIndex = _useState2[1];
16
18
  var selectedIndexRef = useRef(selectedIndex);
17
- var identitySignature = useMemo(function () {
18
- return JSON.stringify(identities);
19
- }, [identities]);
19
+ var previousRef = useRef({
20
+ identities: identities,
21
+ resetKey: resetKey
22
+ });
20
23
  var itemCount = identities.length;
21
24
  var select = useCallback(function (index) {
22
25
  selectedIndexRef.current = index;
23
26
  setSelectedIndex(index);
24
27
  }, []);
25
28
  useLayoutEffect(function () {
26
- select(itemCount > 0 ? 0 : -1);
27
- }, [identitySignature, itemCount, resetKey, select]);
29
+ var previous = previousRef.current;
30
+ previousRef.current = {
31
+ identities: identities,
32
+ resetKey: resetKey
33
+ };
34
+ select(reconcileRegisteredMenuSelection({
35
+ nextIdentities: identities,
36
+ previousIdentities: previous.identities,
37
+ previousIndex: selectedIndexRef.current,
38
+ reset: previous.resetKey !== resetKey
39
+ }));
40
+ }, [identities, resetKey, select]);
28
41
  var selectNext = useCallback(function () {
29
42
  var currentIndex = selectedIndexRef.current;
30
43
  var nextIndex = itemCount === 0 ? -1 : currentIndex < 0 ? 0 : (currentIndex + 1) % itemCount;
@@ -20,7 +20,7 @@ import withAnalyticsContext from '@atlaskit/analytics-next/withAnalyticsContext'
20
20
  import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import Layer from '../Layer';
22
22
  var packageName = "@atlaskit/editor-common";
23
- var packageVersion = "134.1.0";
23
+ var packageVersion = "134.1.2";
24
24
  var halfFocusRing = 1;
25
25
  var dropOffset = '0, 8';
26
26
  // Ignored via go/ees005
@@ -228,12 +228,23 @@ var popperInteropModifiers = [{
228
228
  enabled: false
229
229
  }];
230
230
  function usePopperInteropModifiers(_ref2) {
231
- var onPositioned = _ref2.onPositioned;
231
+ var isContentShown = _ref2.isContentShown,
232
+ onPositioned = _ref2.onPositioned;
232
233
  var onPositionedRef = useRef(onPositioned);
233
234
  var hasPositionedRef = useRef(false);
234
235
  useLayoutEffect(function () {
235
236
  onPositionedRef.current = onPositioned;
236
237
  }, [onPositioned]);
238
+
239
+ // On the top-layer path `@atlaskit/popper` ignores `modifiers`: CSS Anchor Positioning places
240
+ // the content when it mounts. So report the first position once the content is shown.
241
+ useLayoutEffect(function () {
242
+ if (!fg('platform-dst-top-layer') || !isContentShown || hasPositionedRef.current) {
243
+ return;
244
+ }
245
+ hasPositionedRef.current = true;
246
+ onPositionedRef.current();
247
+ }, [isContentShown]);
237
248
  return useMemo(function () {
238
249
  return [].concat(popperInteropModifiers, [{
239
250
  name: 'editorLayerFirstPositioned',
@@ -262,7 +273,9 @@ function PopperInterop(_ref3) {
262
273
  _useState2 = _slicedToArray(_useState, 2),
263
274
  referenceElement = _useState2[0],
264
275
  setReferenceElement = _useState2[1];
276
+ var isContentShown = Boolean(content && referenceElement);
265
277
  var modifiers = usePopperInteropModifiers({
278
+ isContentShown: isContentShown,
266
279
  onPositioned: onPositioned
267
280
  });
268
281
  // Popper v2 compares the offset prop by reference, so memoise to avoid re-running positioning every render.
@@ -0,0 +1,7 @@
1
+ /** Keeps selection attached to the same registration when live menu updates reorder rows. */
2
+ export declare const reconcileRegisteredMenuSelection: ({ nextIdentities, previousIdentities, previousIndex, reset, }: {
3
+ nextIdentities: readonly string[];
4
+ previousIdentities: readonly string[];
5
+ previousIndex: number;
6
+ reset: boolean;
7
+ }) => number;
@@ -9,8 +9,9 @@ type RegisteredMenuSelectionState = {
9
9
  selectPrevious: () => number;
10
10
  };
11
11
  /**
12
- * Resets keyboard selection when the ordered items or reset key changes.
13
- * The caller chooses the key, for example a search term or the current category.
12
+ * Keeps selection on the same item as items reorder. If that item disappears,
13
+ * keeps the previous index within the remaining items. A changed reset key
14
+ * selects the first item instead.
14
15
  */
15
16
  export declare const useRegisteredMenuSelection: ({ identities, resetKey, }: Options) => RegisteredMenuSelectionState;
16
17
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "134.1.1",
3
+ "version": "134.1.3",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -74,7 +74,7 @@
74
74
  "@atlaskit/platform-feature-flags-react": "^1.2.0",
75
75
  "@atlaskit/popper": "^9.4.0",
76
76
  "@atlaskit/primitives": "^22.6.0",
77
- "@atlaskit/profilecard": "^27.3.0",
77
+ "@atlaskit/profilecard": "^27.4.0",
78
78
  "@atlaskit/prosemirror-history": "^1.3.0",
79
79
  "@atlaskit/react-compiler-gating": "^0.2.0",
80
80
  "@atlaskit/react-ufo": "^8.3.0",
@@ -84,7 +84,7 @@
84
84
  "@atlaskit/spinner": "^20.4.0",
85
85
  "@atlaskit/task-decision": "^21.13.0",
86
86
  "@atlaskit/teams-app-config": "^3.1.0",
87
- "@atlaskit/textfield": "^10.2.0",
87
+ "@atlaskit/textfield": "^10.3.0",
88
88
  "@atlaskit/tmp-editor-statsig": "^248.0.0",
89
89
  "@atlaskit/tokens": "^20.8.0",
90
90
  "@atlaskit/tooltip": "^24.4.0",
@@ -180,6 +180,9 @@
180
180
  "type": "boolean",
181
181
  "referenceOnly": true
182
182
  },
183
+ "platform-dst-top-layer": {
184
+ "type": "boolean"
185
+ },
183
186
  "platform-dst-tokens-finesse": {
184
187
  "type": "boolean",
185
188
  "referenceOnly": true