@atlaskit/side-navigation 1.3.1 → 1.4.1
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 +12 -0
- package/codemods/helpers/generic.tsx +10 -12
- package/dist/cjs/components/NestableNavigationContent/index.js +10 -2
- package/dist/cjs/components/NestingItem/index.js +10 -3
- package/dist/cjs/components/utils/hooks.js +48 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/components/NestableNavigationContent/index.js +8 -2
- package/dist/es2019/components/NestingItem/index.js +9 -3
- package/dist/es2019/components/utils/hooks.js +34 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/components/NestableNavigationContent/index.js +9 -2
- package/dist/esm/components/NestingItem/index.js +9 -3
- package/dist/esm/components/utils/hooks.js +34 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/components/NestableNavigationContent/context.d.ts +2 -1
- package/dist/types/components/NestableNavigationContent/index.d.ts +5 -0
- package/dist/types/components/utils/hooks.d.ts +5 -0
- package/package.json +6 -14
- package/report.api.md +92 -375
- package/dist/types-ts4.0/common/constants.d.ts +0 -2
- package/dist/types-ts4.0/common/styles.d.ts +0 -12
- package/dist/types-ts4.0/components/Footer/index.d.ts +0 -11
- package/dist/types-ts4.0/components/Header/index.d.ts +0 -50
- package/dist/types-ts4.0/components/Item/button-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/custom-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/go-back-item.d.ts +0 -14
- package/dist/types-ts4.0/components/Item/index.d.ts +0 -10
- package/dist/types-ts4.0/components/Item/link-item.d.ts +0 -16
- package/dist/types-ts4.0/components/Item/skeleton-item.d.ts +0 -13
- package/dist/types-ts4.0/components/LoadingItems/index.d.ts +0 -35
- package/dist/types-ts4.0/components/NavigationContent/index.d.ts +0 -25
- package/dist/types-ts4.0/components/NavigationContent/styles.d.ts +0 -91
- package/dist/types-ts4.0/components/NavigationFooter/index.d.ts +0 -16
- package/dist/types-ts4.0/components/NavigationHeader/index.d.ts +0 -16
- package/dist/types-ts4.0/components/NestableNavigationContent/context.d.ts +0 -23
- package/dist/types-ts4.0/components/NestableNavigationContent/index.d.ts +0 -69
- package/dist/types-ts4.0/components/NestableNavigationContent/nesting-motion.d.ts +0 -22
- package/dist/types-ts4.0/components/NestingItem/hack-for-ert.d.ts +0 -2
- package/dist/types-ts4.0/components/NestingItem/index.d.ts +0 -91
- package/dist/types-ts4.0/components/NestingItem/styles.d.ts +0 -28
- package/dist/types-ts4.0/components/Section/heading-item.d.ts +0 -11
- package/dist/types-ts4.0/components/Section/index.d.ts +0 -6
- package/dist/types-ts4.0/components/Section/section.d.ts +0 -34
- package/dist/types-ts4.0/components/Section/skeleton-heading-item.d.ts +0 -12
- package/dist/types-ts4.0/components/SideNavigation/index.d.ts +0 -32
- package/dist/types-ts4.0/components/index.d.ts +0 -22
- package/dist/types-ts4.0/index.d.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/side-navigation
|
|
2
2
|
|
|
3
|
+
## 1.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 1.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`5c065ba2010`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5c065ba2010) - Improve state management to allow detection of invalid stack state. Add prop `onUnknownNest` to allow handling of invalid stack state.
|
|
14
|
+
|
|
3
15
|
## 1.3.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -562,19 +562,17 @@ export function changeImportFor({
|
|
|
562
562
|
.filter((path) => path.node.source.value === oldPackagePath)
|
|
563
563
|
.find(j.ImportSpecifier)
|
|
564
564
|
.nodes()
|
|
565
|
-
.map(
|
|
566
|
-
(specifier
|
|
567
|
-
if (specifier.imported.name !== currentName) {
|
|
568
|
-
return null;
|
|
569
|
-
}
|
|
570
|
-
// If aliased: return the alias
|
|
571
|
-
if (specifier.local && specifier.local.name !== currentName) {
|
|
572
|
-
return specifier.local.name;
|
|
573
|
-
}
|
|
574
|
-
|
|
565
|
+
.map((specifier): Nullable<string> => {
|
|
566
|
+
if (specifier.imported.name !== currentName) {
|
|
575
567
|
return null;
|
|
576
|
-
}
|
|
577
|
-
|
|
568
|
+
}
|
|
569
|
+
// If aliased: return the alias
|
|
570
|
+
if (specifier.local && specifier.local.name !== currentName) {
|
|
571
|
+
return specifier.local.name;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return null;
|
|
575
|
+
})
|
|
578
576
|
.filter(Boolean)[0] || null;
|
|
579
577
|
|
|
580
578
|
base
|
|
@@ -21,6 +21,8 @@ var _Item = require("../Item");
|
|
|
21
21
|
|
|
22
22
|
var _NestingItem = _interopRequireDefault(require("../NestingItem"));
|
|
23
23
|
|
|
24
|
+
var _hooks = require("../utils/hooks");
|
|
25
|
+
|
|
24
26
|
var _context = require("./context");
|
|
25
27
|
|
|
26
28
|
var _nestingMotion = require("./nesting-motion");
|
|
@@ -57,6 +59,7 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
57
59
|
overrides = props.overrides,
|
|
58
60
|
initialStack = props.initialStack,
|
|
59
61
|
onChange = props.onChange,
|
|
62
|
+
onUnknownNest = props.onUnknownNest,
|
|
60
63
|
stack = props.stack;
|
|
61
64
|
|
|
62
65
|
var _useState = (0, _react.useState)(stack || initialStack || []),
|
|
@@ -76,6 +79,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
76
79
|
var renderGoBackItem = overrides && overrides.GoBackItem && overrides.GoBackItem.render ? overrides.GoBackItem.render : function (props) {
|
|
77
80
|
return (0, _react2.jsx)(_Item.GoBackItem, props, "Go back");
|
|
78
81
|
};
|
|
82
|
+
|
|
83
|
+
var _useChildIds = (0, _hooks.useChildIds)(currentStackId, committedStack, onUnknownNest),
|
|
84
|
+
childIdsRef = _useChildIds.childIdsRef;
|
|
85
|
+
|
|
79
86
|
var onNestHandler = (0, _react.useCallback)(function (layerId) {
|
|
80
87
|
onChange && onChange(committedStack.concat(layerId));
|
|
81
88
|
|
|
@@ -149,9 +156,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
149
156
|
stack: committedStack,
|
|
150
157
|
onNest: onNestHandler,
|
|
151
158
|
onUnNest: onUnNestHandler,
|
|
152
|
-
parentId: ROOT_ID
|
|
159
|
+
parentId: ROOT_ID,
|
|
160
|
+
childIds: childIdsRef
|
|
153
161
|
};
|
|
154
|
-
}, [
|
|
162
|
+
}, [currentStackId, backButton, committedStack, onNestHandler, onUnNestHandler, childIdsRef]);
|
|
155
163
|
|
|
156
164
|
var manageFocus = function manageFocus(event) {
|
|
157
165
|
var triggeredByKeyboard = event.nativeEvent.detail === 0;
|
|
@@ -37,6 +37,8 @@ var _NestableNavigationContent = require("../NestableNavigationContent");
|
|
|
37
37
|
|
|
38
38
|
var _context = require("../NestableNavigationContent/context");
|
|
39
39
|
|
|
40
|
+
var _hooks = require("../utils/hooks");
|
|
41
|
+
|
|
40
42
|
var _styles2 = require("./styles");
|
|
41
43
|
|
|
42
44
|
var _excluded = ["children", "iconAfter", "title", "onClick", "cssFn", "isSelected", "id", "component", "testId"];
|
|
@@ -79,7 +81,8 @@ var NestingItem = function NestingItem(props) {
|
|
|
79
81
|
onNest = _useNestedContext.onNest,
|
|
80
82
|
onUnNest = _useNestedContext.onUnNest,
|
|
81
83
|
contextualBackButton = _useNestedContext.backButton,
|
|
82
|
-
stack = _useNestedContext.stack
|
|
84
|
+
stack = _useNestedContext.stack,
|
|
85
|
+
childIds = _useNestedContext.childIds;
|
|
83
86
|
|
|
84
87
|
var mergedStyles = (0, _styles.overrideStyleFunction)(_styles2.nestingItemStyle, cssFn);
|
|
85
88
|
|
|
@@ -99,9 +102,13 @@ var NestingItem = function NestingItem(props) {
|
|
|
99
102
|
onNest: onNest,
|
|
100
103
|
onUnNest: onUnNest,
|
|
101
104
|
backButton: backButton,
|
|
102
|
-
parentId: id
|
|
105
|
+
parentId: id,
|
|
106
|
+
childIds: childIds
|
|
103
107
|
};
|
|
104
|
-
},
|
|
108
|
+
}, // childIds shouldn't change as it's a ref
|
|
109
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
+
[onNest, onUnNest, backButton, stack, id, currentStackId]);
|
|
111
|
+
(0, _hooks.useChildIdsEffect)(childIds, id);
|
|
105
112
|
|
|
106
113
|
var isNormalClick = function isNormalClick(e) {
|
|
107
114
|
return !(e.button || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useChildIdsEffect = exports.useChildIds = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _NestableNavigationContent = require("../NestableNavigationContent");
|
|
11
|
+
|
|
12
|
+
var useChildIds = function useChildIds(currentStackId, committedStack, onUnknownNest) {
|
|
13
|
+
var childIdsRef = (0, _react.useRef)(new Set());
|
|
14
|
+
(0, _react.useEffect)(function () {
|
|
15
|
+
// we are holding navigation item IDs in childIdsRef
|
|
16
|
+
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
|
|
17
|
+
if (currentStackId === _NestableNavigationContent.ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onUnknownNest(committedStack || [currentStackId]);
|
|
22
|
+
}, [currentStackId, committedStack, onUnknownNest]);
|
|
23
|
+
return {
|
|
24
|
+
childIdsRef: childIdsRef
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
exports.useChildIds = useChildIds;
|
|
29
|
+
|
|
30
|
+
var useChildIdsEffect = function useChildIdsEffect(childIds, id) {
|
|
31
|
+
(0, _react.useEffect)(function () {
|
|
32
|
+
if (!childIds || !childIds.current) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!childIds.current.has(id)) {
|
|
37
|
+
childIds.current.add(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return function () {
|
|
41
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
42
|
+
childIds.current.delete(id);
|
|
43
|
+
}; // childIds shouldn't change as it's a ref
|
|
44
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
45
|
+
}, [id]);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
exports.useChildIdsEffect = useChildIdsEffect;
|
package/dist/cjs/version.json
CHANGED
|
@@ -6,6 +6,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
6
6
|
import { ExitingPersistence } from '@atlaskit/motion';
|
|
7
7
|
import { GoBackItem as GoBackButton } from '../Item';
|
|
8
8
|
import { default as NestingItem } from '../NestingItem';
|
|
9
|
+
import { useChildIds } from '../utils/hooks';
|
|
9
10
|
import { NestedContext } from './context';
|
|
10
11
|
import { NestingMotion } from './nesting-motion'; // Named so ERT doesn't pick up the override name as a type.
|
|
11
12
|
|
|
@@ -39,6 +40,7 @@ const NestableNavigationContent = props => {
|
|
|
39
40
|
overrides,
|
|
40
41
|
initialStack,
|
|
41
42
|
onChange,
|
|
43
|
+
onUnknownNest,
|
|
42
44
|
stack
|
|
43
45
|
} = props;
|
|
44
46
|
const [committedStack, setCommittedStack] = useState(stack || initialStack || []);
|
|
@@ -47,6 +49,9 @@ const NestableNavigationContent = props => {
|
|
|
47
49
|
const [transition, setTransition] = useState('nesting');
|
|
48
50
|
const backTestId = testId && `${testId}--go-back-item`;
|
|
49
51
|
const renderGoBackItem = overrides && overrides.GoBackItem && overrides.GoBackItem.render ? overrides.GoBackItem.render : props => jsx(GoBackButton, props, "Go back");
|
|
52
|
+
const {
|
|
53
|
+
childIdsRef
|
|
54
|
+
} = useChildIds(currentStackId, committedStack, onUnknownNest);
|
|
50
55
|
const onNestHandler = useCallback(layerId => {
|
|
51
56
|
onChange && onChange(committedStack.concat(layerId));
|
|
52
57
|
|
|
@@ -119,8 +124,9 @@ const NestableNavigationContent = props => {
|
|
|
119
124
|
stack: committedStack,
|
|
120
125
|
onNest: onNestHandler,
|
|
121
126
|
onUnNest: onUnNestHandler,
|
|
122
|
-
parentId: ROOT_ID
|
|
123
|
-
|
|
127
|
+
parentId: ROOT_ID,
|
|
128
|
+
childIds: childIdsRef
|
|
129
|
+
}), [currentStackId, backButton, committedStack, onNestHandler, onUnNestHandler, childIdsRef]);
|
|
124
130
|
|
|
125
131
|
const manageFocus = event => {
|
|
126
132
|
const triggeredByKeyboard = event.nativeEvent.detail === 0;
|
|
@@ -10,6 +10,7 @@ import { overrideStyleFunction } from '../../common/styles';
|
|
|
10
10
|
import { ButtonItem, CustomItem, NavigationContent } from '../index';
|
|
11
11
|
import { ROOT_ID } from '../NestableNavigationContent';
|
|
12
12
|
import { NestedContext, useNestedContext } from '../NestableNavigationContent/context';
|
|
13
|
+
import { useChildIdsEffect } from '../utils/hooks';
|
|
13
14
|
import { nestingItemStyle } from './styles';
|
|
14
15
|
const nestingItemStyles = css({
|
|
15
16
|
marginRight: gridSize(),
|
|
@@ -42,7 +43,8 @@ const NestingItem = props => {
|
|
|
42
43
|
onNest,
|
|
43
44
|
onUnNest,
|
|
44
45
|
backButton: contextualBackButton,
|
|
45
|
-
stack
|
|
46
|
+
stack,
|
|
47
|
+
childIds
|
|
46
48
|
} = useNestedContext();
|
|
47
49
|
const mergedStyles = overrideStyleFunction(nestingItemStyle, cssFn);
|
|
48
50
|
const [isInteracted, setIsInteracted] = useState(false);
|
|
@@ -56,8 +58,12 @@ const NestingItem = props => {
|
|
|
56
58
|
onNest,
|
|
57
59
|
onUnNest,
|
|
58
60
|
backButton,
|
|
59
|
-
parentId: id
|
|
60
|
-
|
|
61
|
+
parentId: id,
|
|
62
|
+
childIds
|
|
63
|
+
}), // childIds shouldn't change as it's a ref
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
[onNest, onUnNest, backButton, stack, id, currentStackId]);
|
|
66
|
+
useChildIdsEffect(childIds, id);
|
|
61
67
|
|
|
62
68
|
const isNormalClick = e => !(e.button || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
63
69
|
/**
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ROOT_ID } from '../NestableNavigationContent';
|
|
3
|
+
export const useChildIds = (currentStackId, committedStack, onUnknownNest) => {
|
|
4
|
+
const childIdsRef = useRef(new Set());
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
// we are holding navigation item IDs in childIdsRef
|
|
7
|
+
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
|
|
8
|
+
if (currentStackId === ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
onUnknownNest(committedStack || [currentStackId]);
|
|
13
|
+
}, [currentStackId, committedStack, onUnknownNest]);
|
|
14
|
+
return {
|
|
15
|
+
childIdsRef
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const useChildIdsEffect = (childIds, id) => {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!childIds || !childIds.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!childIds.current.has(id)) {
|
|
25
|
+
childIds.current.add(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
childIds.current.delete(id);
|
|
31
|
+
}; // childIds shouldn't change as it's a ref
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [id]);
|
|
34
|
+
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -7,6 +7,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
7
7
|
import { ExitingPersistence } from '@atlaskit/motion';
|
|
8
8
|
import { GoBackItem as GoBackButton } from '../Item';
|
|
9
9
|
import { default as NestingItem } from '../NestingItem';
|
|
10
|
+
import { useChildIds } from '../utils/hooks';
|
|
10
11
|
import { NestedContext } from './context';
|
|
11
12
|
import { NestingMotion } from './nesting-motion'; // Named so ERT doesn't pick up the override name as a type.
|
|
12
13
|
|
|
@@ -39,6 +40,7 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
39
40
|
overrides = props.overrides,
|
|
40
41
|
initialStack = props.initialStack,
|
|
41
42
|
onChange = props.onChange,
|
|
43
|
+
onUnknownNest = props.onUnknownNest,
|
|
42
44
|
stack = props.stack;
|
|
43
45
|
|
|
44
46
|
var _useState = useState(stack || initialStack || []),
|
|
@@ -58,6 +60,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
58
60
|
var renderGoBackItem = overrides && overrides.GoBackItem && overrides.GoBackItem.render ? overrides.GoBackItem.render : function (props) {
|
|
59
61
|
return jsx(GoBackButton, props, "Go back");
|
|
60
62
|
};
|
|
63
|
+
|
|
64
|
+
var _useChildIds = useChildIds(currentStackId, committedStack, onUnknownNest),
|
|
65
|
+
childIdsRef = _useChildIds.childIdsRef;
|
|
66
|
+
|
|
61
67
|
var onNestHandler = useCallback(function (layerId) {
|
|
62
68
|
onChange && onChange(committedStack.concat(layerId));
|
|
63
69
|
|
|
@@ -131,9 +137,10 @@ var NestableNavigationContent = function NestableNavigationContent(props) {
|
|
|
131
137
|
stack: committedStack,
|
|
132
138
|
onNest: onNestHandler,
|
|
133
139
|
onUnNest: onUnNestHandler,
|
|
134
|
-
parentId: ROOT_ID
|
|
140
|
+
parentId: ROOT_ID,
|
|
141
|
+
childIds: childIdsRef
|
|
135
142
|
};
|
|
136
|
-
}, [
|
|
143
|
+
}, [currentStackId, backButton, committedStack, onNestHandler, onUnNestHandler, childIdsRef]);
|
|
137
144
|
|
|
138
145
|
var manageFocus = function manageFocus(event) {
|
|
139
146
|
var triggeredByKeyboard = event.nativeEvent.detail === 0;
|
|
@@ -19,6 +19,7 @@ import { overrideStyleFunction } from '../../common/styles';
|
|
|
19
19
|
import { ButtonItem, CustomItem, NavigationContent } from '../index';
|
|
20
20
|
import { ROOT_ID } from '../NestableNavigationContent';
|
|
21
21
|
import { NestedContext, useNestedContext } from '../NestableNavigationContent/context';
|
|
22
|
+
import { useChildIdsEffect } from '../utils/hooks';
|
|
22
23
|
import { nestingItemStyle } from './styles';
|
|
23
24
|
var nestingItemStyles = css({
|
|
24
25
|
marginRight: gridSize(),
|
|
@@ -50,7 +51,8 @@ var NestingItem = function NestingItem(props) {
|
|
|
50
51
|
onNest = _useNestedContext.onNest,
|
|
51
52
|
onUnNest = _useNestedContext.onUnNest,
|
|
52
53
|
contextualBackButton = _useNestedContext.backButton,
|
|
53
|
-
stack = _useNestedContext.stack
|
|
54
|
+
stack = _useNestedContext.stack,
|
|
55
|
+
childIds = _useNestedContext.childIds;
|
|
54
56
|
|
|
55
57
|
var mergedStyles = overrideStyleFunction(nestingItemStyle, cssFn);
|
|
56
58
|
|
|
@@ -70,9 +72,13 @@ var NestingItem = function NestingItem(props) {
|
|
|
70
72
|
onNest: onNest,
|
|
71
73
|
onUnNest: onUnNest,
|
|
72
74
|
backButton: backButton,
|
|
73
|
-
parentId: id
|
|
75
|
+
parentId: id,
|
|
76
|
+
childIds: childIds
|
|
74
77
|
};
|
|
75
|
-
},
|
|
78
|
+
}, // childIds shouldn't change as it's a ref
|
|
79
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
80
|
+
[onNest, onUnNest, backButton, stack, id, currentStackId]);
|
|
81
|
+
useChildIdsEffect(childIds, id);
|
|
76
82
|
|
|
77
83
|
var isNormalClick = function isNormalClick(e) {
|
|
78
84
|
return !(e.button || e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ROOT_ID } from '../NestableNavigationContent';
|
|
3
|
+
export var useChildIds = function useChildIds(currentStackId, committedStack, onUnknownNest) {
|
|
4
|
+
var childIdsRef = useRef(new Set());
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
// we are holding navigation item IDs in childIdsRef
|
|
7
|
+
// check if the current displayed nav item (currentStackId) is in childIdsRef. if it's not, this means it's undefined
|
|
8
|
+
if (currentStackId === ROOT_ID || !childIdsRef.current.size || childIdsRef.current.has(currentStackId) || !onUnknownNest) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
onUnknownNest(committedStack || [currentStackId]);
|
|
13
|
+
}, [currentStackId, committedStack, onUnknownNest]);
|
|
14
|
+
return {
|
|
15
|
+
childIdsRef: childIdsRef
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export var useChildIdsEffect = function useChildIdsEffect(childIds, id) {
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
if (!childIds || !childIds.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!childIds.current.has(id)) {
|
|
25
|
+
childIds.current.add(id);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return function () {
|
|
29
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
+
childIds.current.delete(id);
|
|
31
|
+
}; // childIds shouldn't change as it's a ref
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [id]);
|
|
34
|
+
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
2
|
interface NestedContext {
|
|
3
3
|
currentStackId: string;
|
|
4
4
|
onNest: (id: string) => void;
|
|
@@ -6,6 +6,7 @@ interface NestedContext {
|
|
|
6
6
|
stack: string[];
|
|
7
7
|
parentId: string;
|
|
8
8
|
backButton?: React.ReactNode;
|
|
9
|
+
childIds: MutableRefObject<Set<string>>;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* @internal
|
|
@@ -38,6 +38,11 @@ export interface NestableNavigationContentProps {
|
|
|
38
38
|
* This prop should be used with the `stack` prop for controlled behavior.
|
|
39
39
|
*/
|
|
40
40
|
onChange?: (stack: string[]) => void;
|
|
41
|
+
/**
|
|
42
|
+
* Called when a nesting id that does not exist among `<NestingItem>`s is pushed to the stack. Use this callback to be notified when there is an undefined nesting state.
|
|
43
|
+
* Provides you with the stack which led to the undefined state, with the top of the stack (last item in array) being the invalid item.
|
|
44
|
+
*/
|
|
45
|
+
onUnknownNest?: (stack: string[]) => void;
|
|
41
46
|
/**
|
|
42
47
|
* Custom overrides for the composed components.
|
|
43
48
|
*
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
export declare const useChildIds: (currentStackId: string, committedStack: string[], onUnknownNest?: ((stack: string[]) => void) | undefined) => {
|
|
3
|
+
childIdsRef: MutableRefObject<Set<string>>;
|
|
4
|
+
};
|
|
5
|
+
export declare const useChildIdsEffect: (childIds: MutableRefObject<Set<string>>, id: string) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/side-navigation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "A highly composable side navigation component that supports nested views.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -12,14 +12,6 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"module:es2019": "dist/es2019/index.js",
|
|
14
14
|
"types": "dist/types/index.d.ts",
|
|
15
|
-
"typesVersions": {
|
|
16
|
-
">=4.0 <4.5": {
|
|
17
|
-
"*": [
|
|
18
|
-
"dist/types-ts4.0/*",
|
|
19
|
-
"dist/types-ts4.0/index.d.ts"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
15
|
"sideEffects": false,
|
|
24
16
|
"atlaskit:src": "src/index.tsx",
|
|
25
17
|
"atlassian": {
|
|
@@ -35,10 +27,10 @@
|
|
|
35
27
|
"dependencies": {
|
|
36
28
|
"@atlaskit/ds-lib": "^2.1.0",
|
|
37
29
|
"@atlaskit/icon": "^21.11.0",
|
|
38
|
-
"@atlaskit/menu": "^1.
|
|
39
|
-
"@atlaskit/motion": "^1.
|
|
30
|
+
"@atlaskit/menu": "^1.4.0",
|
|
31
|
+
"@atlaskit/motion": "^1.3.0",
|
|
40
32
|
"@atlaskit/theme": "^12.2.0",
|
|
41
|
-
"@atlaskit/tokens": "^0.
|
|
33
|
+
"@atlaskit/tokens": "^0.11.0",
|
|
42
34
|
"@babel/runtime": "^7.0.0",
|
|
43
35
|
"@emotion/react": "^11.7.1"
|
|
44
36
|
},
|
|
@@ -46,8 +38,8 @@
|
|
|
46
38
|
"react": "^16.8.0"
|
|
47
39
|
},
|
|
48
40
|
"devDependencies": {
|
|
49
|
-
"@atlaskit/atlassian-navigation": "^2.
|
|
50
|
-
"@atlaskit/button": "^16.
|
|
41
|
+
"@atlaskit/atlassian-navigation": "^2.3.0",
|
|
42
|
+
"@atlaskit/button": "^16.4.0",
|
|
51
43
|
"@atlaskit/docs": "*",
|
|
52
44
|
"@atlaskit/logo": "^13.10.0",
|
|
53
45
|
"@atlaskit/onboarding": "^10.6.0",
|