@blocklet/launcher-layout 1.7.16 → 1.7.19
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/lib/context/step.js +40 -15
- package/lib/nav.js +47 -28
- package/package.json +5 -5
package/lib/context/step.js
CHANGED
|
@@ -24,27 +24,48 @@ const {
|
|
|
24
24
|
function StepProvider(_ref) {
|
|
25
25
|
let {
|
|
26
26
|
children,
|
|
27
|
-
steps
|
|
27
|
+
steps,
|
|
28
|
+
mode
|
|
28
29
|
} = _ref;
|
|
29
|
-
const [activeStep,
|
|
30
|
+
const [activeStep, setActiveStepByIndex] = (0, _react.useState)(0); // can use this to set the activeStep by key
|
|
31
|
+
|
|
32
|
+
function setActiveStepByKey(key) {
|
|
33
|
+
const index = steps.findIndex(step => step.key === key);
|
|
34
|
+
|
|
35
|
+
if (index > -1) {
|
|
36
|
+
setActiveStepByIndex(index);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
30
40
|
(0, _react.useEffect)(() => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
if (mode === 'history') {
|
|
42
|
+
let stepIndex = -1;
|
|
43
|
+
let matchedLength = 0;
|
|
44
|
+
steps.forEach((step, index) => {
|
|
45
|
+
var _step$path;
|
|
46
|
+
|
|
47
|
+
const currentPathname = window.location.pathname.replace(/\/$/, '');
|
|
48
|
+
|
|
49
|
+
if (new RegExp(step.path).test(currentPathname) && ((_step$path = step.path) === null || _step$path === void 0 ? void 0 : _step$path.length) > matchedLength) {
|
|
50
|
+
stepIndex = index;
|
|
51
|
+
matchedLength = step.path.length;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
setActiveStepByIndex(stepIndex);
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
return () => {};
|
|
43
58
|
}, [steps, window.location.pathname]);
|
|
44
59
|
const value = {
|
|
45
60
|
steps,
|
|
46
61
|
activeStep,
|
|
47
|
-
totalStepsCount: steps.length
|
|
62
|
+
totalStepsCount: steps.length,
|
|
63
|
+
setActiveStepByIndex,
|
|
64
|
+
setActiveStepByKey,
|
|
65
|
+
// judge node can be clicked to back if the mode is 'memory'
|
|
66
|
+
canBackToStep: nodeIndex => {
|
|
67
|
+
return mode === 'memory' && activeStep !== 0 && nodeIndex < activeStep;
|
|
68
|
+
}
|
|
48
69
|
};
|
|
49
70
|
return /*#__PURE__*/_react.default.createElement(Provider, {
|
|
50
71
|
value: value
|
|
@@ -57,5 +78,9 @@ function useStepContext() {
|
|
|
57
78
|
|
|
58
79
|
StepProvider.propTypes = {
|
|
59
80
|
children: _propTypes.default.any.isRequired,
|
|
60
|
-
steps: _propTypes.default.array.isRequired
|
|
81
|
+
steps: _propTypes.default.array.isRequired,
|
|
82
|
+
mode: _propTypes.default.string
|
|
83
|
+
};
|
|
84
|
+
StepProvider.defaultProps = {
|
|
85
|
+
mode: 'history'
|
|
61
86
|
};
|
package/lib/nav.js
CHANGED
|
@@ -31,7 +31,10 @@ function Nav(_ref) {
|
|
|
31
31
|
} = _ref;
|
|
32
32
|
const {
|
|
33
33
|
steps,
|
|
34
|
-
activeStep
|
|
34
|
+
activeStep,
|
|
35
|
+
setActiveStepByKey,
|
|
36
|
+
setActiveStepByIndex,
|
|
37
|
+
canBackToStep
|
|
35
38
|
} = (0, _step.useStepContext)();
|
|
36
39
|
const showSkeleton = !blockletMeta || !blockletMeta.title;
|
|
37
40
|
return /*#__PURE__*/_react.default.createElement(Div, {
|
|
@@ -48,42 +51,58 @@ function Nav(_ref) {
|
|
|
48
51
|
did: blockletMeta.did,
|
|
49
52
|
logoUrl: logoUrl,
|
|
50
53
|
locale: locale
|
|
51
|
-
}), /*#__PURE__*/_react.default.createElement(StepContainer, null, steps.map((step, index) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
}), /*#__PURE__*/_react.default.createElement(StepContainer, null, steps.map((step, index) => {
|
|
55
|
+
const canBack = !showSkeleton && canBackToStep(index);
|
|
56
|
+
|
|
57
|
+
const nodeClassName = (() => {
|
|
58
|
+
const classNameList = ['step-block'];
|
|
54
59
|
|
|
55
60
|
if (activeStep === index) {
|
|
56
|
-
|
|
61
|
+
classNameList.push('step-active');
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
if (activeStep > index) {
|
|
60
|
-
|
|
65
|
+
classNameList.push('step-checked');
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
if (step.optional === true && activeStep < index) {
|
|
64
|
-
|
|
69
|
+
classNameList.push('step-optional');
|
|
65
70
|
}
|
|
66
71
|
|
|
67
|
-
return
|
|
68
|
-
})()
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
return classNameList.join(' ');
|
|
73
|
+
})();
|
|
74
|
+
|
|
75
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
76
|
+
onClick: () => {
|
|
77
|
+
if (canBack) {
|
|
78
|
+
if (step.key) {
|
|
79
|
+
setActiveStepByKey(step.key);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setActiveStepByIndex(index);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
className: nodeClassName,
|
|
87
|
+
key: step.key
|
|
88
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
89
|
+
className: "step-icon"
|
|
90
|
+
}, /*#__PURE__*/_react.default.createElement(_Check.default, {
|
|
91
|
+
style: {
|
|
92
|
+
fontSize: 16
|
|
93
|
+
}
|
|
94
|
+
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
95
|
+
className: "step-line"
|
|
96
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
97
|
+
className: "step-name",
|
|
98
|
+
title: step.name
|
|
99
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
100
|
+
className: "step-name-content ".concat(canBack ? ' step-clickable' : '')
|
|
101
|
+
}, showSkeleton ? /*#__PURE__*/_react.default.createElement(_Skeleton.default, {
|
|
102
|
+
variant: "text",
|
|
103
|
+
width: 100
|
|
104
|
+
}) : step.name)));
|
|
105
|
+
})));
|
|
87
106
|
}
|
|
88
107
|
|
|
89
108
|
const AppLink = _styledComponents.default.a.withConfig({
|
|
@@ -99,7 +118,7 @@ const Div = _styledComponents.default.div.withConfig({
|
|
|
99
118
|
const StepContainer = _styledComponents.default.div.withConfig({
|
|
100
119
|
displayName: "nav__StepContainer",
|
|
101
120
|
componentId: "sc-1qwhj4c-2"
|
|
102
|
-
})(["display:flex;flex-direction:column;margin-top:60px;", "{margin-top:30px;}.step-line{display:block;position:absolute;z-index:1;left:11px;top:12px;width:2px;height:100%;opacity:0.5;background-color:", ";transition:all ease 0.2s;}.step-icon{position:relative;z-index:2;display:flex;flex-shrink:0;justify-content:center;align-items:center;width:24px;height:24px;border-radius:13px;background-color:", ";color:", ";transition:all ease 0.3s;&:before{position:absolute;left:4px;top:4px;z-index:3;display:block;background-color:", ";width:16px;height:16px;border-radius:10px;content:'';transform:scale(0);transition:all ease 0.3s;}& > *{transform:scale(0);transition:all ease 0.2s;}}.step-name{position:relative;flex:1;padding-top:1px;margin-left:22px;font-size:16px;color:", ";white-space:nowrap;}", "{.step-name-content{position:absolute;left:0;top:0;width:100%;height:100%;overflow:hidden;text-overflow:ellipsis;}}.step-block{position:relative;display:flex;height:70px;opacity:0.5;overflow:hidden;transition:all ease 0.2s;&.step-optional{height:0;opacity:0;}&.step-checked{opacity:1;.step-icon{color:", ";background-color:", ";& > *{transform:scale(1);}}.step-line{background-color:", ";opacity:1;}}&.step-active{opacity:1;.step-icon{background-color:", ";}.step-icon:before{transform:scale(1);}.step-name{color:", ";}}&:last-child{.step-line{display:none;}}}"], props => props.theme.breakpoints.down('md'), props => props.theme.palette.grey[400], props => props.theme.palette.grey[400], props => props.theme.palette.common.white, props => props.theme.palette.common.white, props => props.theme.palette.grey[700], props => props.theme.breakpoints.up('md'), props => props.theme.palette.common.white, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main);
|
|
121
|
+
})(["display:flex;flex-direction:column;margin-top:60px;", "{margin-top:30px;}.step-clickable{cursor:pointer;&:hover{color:", ";}}.step-line{display:block;position:absolute;z-index:1;left:11px;top:12px;width:2px;height:100%;opacity:0.5;background-color:", ";transition:all ease 0.2s;}.step-icon{position:relative;z-index:2;display:flex;flex-shrink:0;justify-content:center;align-items:center;width:24px;height:24px;border-radius:13px;background-color:", ";color:", ";transition:all ease 0.3s;&:before{position:absolute;left:4px;top:4px;z-index:3;display:block;background-color:", ";width:16px;height:16px;border-radius:10px;content:'';transform:scale(0);transition:all ease 0.3s;}& > *{transform:scale(0);transition:all ease 0.2s;}}.step-name{position:relative;flex:1;padding-top:1px;margin-left:22px;font-size:16px;color:", ";white-space:nowrap;}", "{.step-name-content{position:absolute;left:0;top:0;width:100%;height:100%;overflow:hidden;text-overflow:ellipsis;}}.step-block{position:relative;display:flex;height:70px;opacity:0.5;overflow:hidden;transition:all ease 0.2s;&.step-optional{height:0;opacity:0;}&.step-checked{opacity:1;.step-icon{color:", ";background-color:", ";& > *{transform:scale(1);}}.step-line{background-color:", ";opacity:1;}}&.step-active{opacity:1;.step-icon{background-color:", ";}.step-icon:before{transform:scale(1);}.step-name{color:", ";}}&:last-child{.step-line{display:none;}}}"], props => props.theme.breakpoints.down('md'), props => props.theme.palette.primary.main, props => props.theme.palette.grey[400], props => props.theme.palette.grey[400], props => props.theme.palette.common.white, props => props.theme.palette.common.white, props => props.theme.palette.grey[700], props => props.theme.breakpoints.up('md'), props => props.theme.palette.common.white, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main, props => props.theme.palette.primary.main);
|
|
103
122
|
|
|
104
123
|
Nav.propTypes = {
|
|
105
124
|
blockletMeta: _propTypes.default.object.isRequired,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/launcher-layout",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.19",
|
|
4
4
|
"description": "Common ux components of launcher",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"react": ">=18.1.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@arcblock/did-connect": "^2.1.
|
|
41
|
-
"@arcblock/icons": "^2.1.
|
|
42
|
-
"@arcblock/ux": "^2.1.
|
|
40
|
+
"@arcblock/did-connect": "^2.1.20",
|
|
41
|
+
"@arcblock/icons": "^2.1.20",
|
|
42
|
+
"@arcblock/ux": "^2.1.20",
|
|
43
43
|
"@blocklet/meta": "^1.7.23",
|
|
44
44
|
"@emotion/react": "^11.9.0",
|
|
45
45
|
"@emotion/styled": "^11.8.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"babel-plugin-inline-react-svg": "^2.0.1",
|
|
62
62
|
"babel-plugin-styled-components": "^1.10.7"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "335b512891157bd15d4e01b9317f37a57ddc1343"
|
|
65
65
|
}
|