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