@ahnseungchan/webviewkit 1.0.8 → 1.2.0
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/README.md +57 -112
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/{packages/core/src/history.d.ts → history.d.ts} +3 -2
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/stack-dev/stack-dev-roadmap.d.ts +15 -0
- package/dist/stack-dev/stack-dev-roadmap.d.ts.map +1 -0
- package/dist/stack-dev/stack-dev-roadmap.js +66 -0
- package/dist/stack-router/_components/back-router.d.ts +3 -0
- package/dist/stack-router/_components/back-router.d.ts.map +1 -0
- package/dist/stack-router/_components/back-router.js +39 -0
- package/dist/stack-router/_components/header.d.ts +3 -0
- package/dist/stack-router/_components/header.d.ts.map +1 -0
- package/dist/stack-router/_components/header.js +42 -0
- package/dist/{packages/core/src/stack-router → stack-router}/stack-router-provider.d.ts +4 -5
- package/dist/stack-router/stack-router-provider.d.ts.map +1 -0
- package/dist/stack-router/stack-router-provider.js +227 -0
- package/dist/{packages/core/src/type.d.ts → type.d.ts} +3 -5
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +14 -0
- package/package.json +22 -26
- package/dist/packages/core/src/__tests__/back-router.test.d.ts +0 -0
- package/dist/packages/core/src/__tests__/back-router.test.js +0 -62
- package/dist/packages/core/src/__tests__/history.test.d.ts +0 -1
- package/dist/packages/core/src/__tests__/history.test.js +0 -114
- package/dist/packages/core/src/__tests__/stack-router.test.d.ts +0 -0
- package/dist/packages/core/src/__tests__/stack-router.test.js +0 -185
- package/dist/packages/core/src/history.js +0 -82
- package/dist/packages/core/src/index.d.ts +0 -5
- package/dist/packages/core/src/index.js +0 -6
- package/dist/packages/core/src/stack-router/__tests__/stack-router.test.d.ts +0 -0
- package/dist/packages/core/src/stack-router/__tests__/stack-router.test.js +0 -153
- package/dist/packages/core/src/stack-router/_components/back-router.d.ts +0 -2
- package/dist/packages/core/src/stack-router/_components/back-router.js +0 -34
- package/dist/packages/core/src/stack-router/_components/header.d.ts +0 -2
- package/dist/packages/core/src/stack-router/_components/header.js +0 -36
- package/dist/packages/core/src/stack-router/stack-router-provider.js +0 -211
- package/dist/packages/core/src/type.js +0 -11
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
-
import { history } from "../history";
|
|
4
|
-
import styled from "@emotion/styled";
|
|
5
|
-
import { keyframes, css } from "@emotion/react";
|
|
6
|
-
import { HistoryAction, Direction, } from "../type";
|
|
7
|
-
const StackRouterContext = createContext(null);
|
|
8
|
-
export const useStackRouter = () => {
|
|
9
|
-
const context = useContext(StackRouterContext);
|
|
10
|
-
if (!context) {
|
|
11
|
-
throw new Error("useStackRouter must be used within a StackRouterProvider");
|
|
12
|
-
}
|
|
13
|
-
return context;
|
|
14
|
-
};
|
|
15
|
-
const StackRouter = ({ maxWidth = "600px", Activities = [], initialActivity, ActivitysLayout, }) => {
|
|
16
|
-
const [currentPath, setCurrentPath] = useState(history.getCurrentState().path);
|
|
17
|
-
const [currentState, setCurrentState] = useState(history.getCurrentState());
|
|
18
|
-
const [isTransitioning, setIsTransitioning] = useState(false);
|
|
19
|
-
const [direction, setDirection] = useState(Direction.FORWARD);
|
|
20
|
-
const [visiblePages, setVisiblePages] = useState([]);
|
|
21
|
-
// initialize visible pages
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
setVisiblePages([
|
|
24
|
-
{
|
|
25
|
-
path: initialActivity.path,
|
|
26
|
-
element: initialActivity.element,
|
|
27
|
-
isEntering: true,
|
|
28
|
-
},
|
|
29
|
-
]);
|
|
30
|
-
}, [initialActivity]);
|
|
31
|
-
// listen to history changes
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const removeListener = history.addListener((state) => {
|
|
34
|
-
if (!isTransitioning || direction !== Direction.BACKWARD) {
|
|
35
|
-
setCurrentPath(state?.path);
|
|
36
|
-
setCurrentState(state);
|
|
37
|
-
}
|
|
38
|
-
setIsTransitioning(true);
|
|
39
|
-
setDirection(state?.action === HistoryAction.POP
|
|
40
|
-
? Direction.BACKWARD
|
|
41
|
-
: Direction.FORWARD);
|
|
42
|
-
});
|
|
43
|
-
return () => {
|
|
44
|
-
removeListener();
|
|
45
|
-
};
|
|
46
|
-
}, [isTransitioning, direction]);
|
|
47
|
-
// handle back
|
|
48
|
-
const handleBack = () => {
|
|
49
|
-
setIsTransitioning(true);
|
|
50
|
-
setDirection(Direction.BACKWARD);
|
|
51
|
-
setTimeout(() => {
|
|
52
|
-
setVisiblePages((prev) => prev.slice(0, -1));
|
|
53
|
-
}, 500);
|
|
54
|
-
history.back();
|
|
55
|
-
};
|
|
56
|
-
// update current path
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (visiblePages.length > 0) {
|
|
59
|
-
setCurrentPath(visiblePages[visiblePages.length - 1].path);
|
|
60
|
-
}
|
|
61
|
-
}, [visiblePages]);
|
|
62
|
-
// handle push
|
|
63
|
-
const handlePush = (path, data) => {
|
|
64
|
-
setIsTransitioning(true);
|
|
65
|
-
setDirection(Direction.FORWARD);
|
|
66
|
-
const currentActivity = Activities.find((a) => a.path === path);
|
|
67
|
-
if (currentActivity) {
|
|
68
|
-
setVisiblePages((prev) => {
|
|
69
|
-
const existingIndex = prev.findIndex((a) => a.path === path);
|
|
70
|
-
if (existingIndex !== -1) {
|
|
71
|
-
const newActivities = [...prev];
|
|
72
|
-
const [removed] = newActivities.splice(existingIndex, 1);
|
|
73
|
-
return [...newActivities, { ...removed, isExiting: true }];
|
|
74
|
-
}
|
|
75
|
-
return [
|
|
76
|
-
...prev,
|
|
77
|
-
{ path, element: currentActivity.element, isExiting: true },
|
|
78
|
-
];
|
|
79
|
-
});
|
|
80
|
-
setTimeout(() => {
|
|
81
|
-
setCurrentPath(path);
|
|
82
|
-
}, 500);
|
|
83
|
-
}
|
|
84
|
-
history.push(path, data);
|
|
85
|
-
};
|
|
86
|
-
const value = {
|
|
87
|
-
currentPath,
|
|
88
|
-
currentState,
|
|
89
|
-
initialActivity,
|
|
90
|
-
Activities,
|
|
91
|
-
visiblePages,
|
|
92
|
-
push: handlePush,
|
|
93
|
-
replace: history.replace,
|
|
94
|
-
back: handleBack,
|
|
95
|
-
forward: history.forward,
|
|
96
|
-
};
|
|
97
|
-
return (_jsx(StackRouterContext.Provider, { value: value, children: _jsx(LayoutContainer, { children: _jsx(Layout, { maxWidth: maxWidth, as: "div", "data-testid": "layout", children: ActivitysLayout ? (_jsx(ActivitysLayout, { children: _jsx(PageContainer, { children: visiblePages.map((page, index) => (_jsx(PageWrapper, { isTransitioning: isTransitioning, direction: direction, currentPage: index === visiblePages.length - 1, isEntering: page.isEntering, isExiting: page.isExiting, zIndex: index, children: page.element }, `${page.path}-${index}`))) }) })) : (_jsx(PageContainer, { children: visiblePages.map((page, index) => (_jsx(PageWrapper, { isTransitioning: isTransitioning, direction: direction, currentPage: index === visiblePages.length - 1, isEntering: page.isEntering, isExiting: page.isExiting, zIndex: index, children: page.element }, `${page.path}-${index}`))) })) }) }) }));
|
|
98
|
-
};
|
|
99
|
-
export default StackRouter;
|
|
100
|
-
/**styles */
|
|
101
|
-
const LayoutContainer = styled.div `
|
|
102
|
-
width: 100%;
|
|
103
|
-
height: 100vh;
|
|
104
|
-
display: flex;
|
|
105
|
-
justify-content: center;
|
|
106
|
-
background: white;
|
|
107
|
-
`;
|
|
108
|
-
const Layout = styled.div `
|
|
109
|
-
width: 100%;
|
|
110
|
-
max-width: ${({ maxWidth }) => maxWidth};
|
|
111
|
-
height: 100%;
|
|
112
|
-
position: relative;
|
|
113
|
-
overflow: hidden;
|
|
114
|
-
`;
|
|
115
|
-
const PageContainer = styled.div `
|
|
116
|
-
position: relative;
|
|
117
|
-
width: 100%;
|
|
118
|
-
height: 100%;
|
|
119
|
-
overflow: hidden;
|
|
120
|
-
background: white;
|
|
121
|
-
`;
|
|
122
|
-
const slideInRight = keyframes `
|
|
123
|
-
from {
|
|
124
|
-
transform: translateX(100%);
|
|
125
|
-
opacity: 0.2;
|
|
126
|
-
}
|
|
127
|
-
to {
|
|
128
|
-
transform: translateX(0);
|
|
129
|
-
opacity: 1;
|
|
130
|
-
}
|
|
131
|
-
`;
|
|
132
|
-
const slideOutLeft = keyframes `
|
|
133
|
-
from {
|
|
134
|
-
transform: translateX(0);
|
|
135
|
-
opacity: 1;
|
|
136
|
-
}
|
|
137
|
-
to {
|
|
138
|
-
transform: translateX(-30%);
|
|
139
|
-
opacity: 0.2;
|
|
140
|
-
}
|
|
141
|
-
`;
|
|
142
|
-
const slideInLeft = keyframes `
|
|
143
|
-
from {
|
|
144
|
-
transform: translateX(-30%);
|
|
145
|
-
opacity: 0.2;
|
|
146
|
-
}
|
|
147
|
-
to {
|
|
148
|
-
transform: translateX(0);
|
|
149
|
-
opacity: 1;
|
|
150
|
-
}
|
|
151
|
-
`;
|
|
152
|
-
const slideOutRight = keyframes `
|
|
153
|
-
from {
|
|
154
|
-
transform: translateX(0);
|
|
155
|
-
opacity: 1;
|
|
156
|
-
}
|
|
157
|
-
to {
|
|
158
|
-
transform: translateX(100%);
|
|
159
|
-
opacity: 0.2;
|
|
160
|
-
}
|
|
161
|
-
`;
|
|
162
|
-
const PageWrapper = styled.div `
|
|
163
|
-
position: absolute;
|
|
164
|
-
top: 0;
|
|
165
|
-
left: 0;
|
|
166
|
-
width: 100%;
|
|
167
|
-
height: 100%;
|
|
168
|
-
background: white;
|
|
169
|
-
cursor: grab;
|
|
170
|
-
user-select: none;
|
|
171
|
-
-webkit-user-select: none;
|
|
172
|
-
-webkit-touch-callout: none;
|
|
173
|
-
-webkit-tap-highlight-color: transparent;
|
|
174
|
-
z-index: ${({ zIndex }) => zIndex};
|
|
175
|
-
will-change: transform, opacity;
|
|
176
|
-
transform: translate3d(0, 0, 0);
|
|
177
|
-
animation: ${({ isTransitioning, direction, currentPage, isEntering, isExiting, }) => {
|
|
178
|
-
if (!isTransitioning)
|
|
179
|
-
return "none";
|
|
180
|
-
if (direction === "forward") {
|
|
181
|
-
if (isExiting) {
|
|
182
|
-
return css `
|
|
183
|
-
${slideInRight} 0.7s ease-in-out forwards
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
if (isEntering) {
|
|
187
|
-
return css `
|
|
188
|
-
${slideOutLeft} 0.7s ease-in-out forwards
|
|
189
|
-
`;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
if (isExiting) {
|
|
194
|
-
return css `
|
|
195
|
-
${slideOutRight} 0.7s ease-in-out forwards
|
|
196
|
-
`;
|
|
197
|
-
}
|
|
198
|
-
if (isEntering) {
|
|
199
|
-
return css `
|
|
200
|
-
${slideInLeft} 0.7s ease-in-out forwards
|
|
201
|
-
`;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return "none";
|
|
205
|
-
}};
|
|
206
|
-
animation-fill-mode: forwards;
|
|
207
|
-
|
|
208
|
-
&:active {
|
|
209
|
-
cursor: grabbing;
|
|
210
|
-
}
|
|
211
|
-
`;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export var Direction;
|
|
2
|
-
(function (Direction) {
|
|
3
|
-
Direction["FORWARD"] = "forward";
|
|
4
|
-
Direction["BACKWARD"] = "backward";
|
|
5
|
-
})(Direction || (Direction = {}));
|
|
6
|
-
export var HistoryAction;
|
|
7
|
-
(function (HistoryAction) {
|
|
8
|
-
HistoryAction["PUSH"] = "PUSH";
|
|
9
|
-
HistoryAction["POP"] = "POP";
|
|
10
|
-
HistoryAction["REPLACE"] = "REPLACE";
|
|
11
|
-
})(HistoryAction || (HistoryAction = {}));
|