@mandujs/core 0.9.8 → 0.9.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -171,6 +171,10 @@ export interface NavLinkProps extends Omit<LinkProps, "className" | "style"> {
171
171
  style?:
172
172
  | React.CSSProperties
173
173
  | ((props: { isActive: boolean }) => React.CSSProperties);
174
+ /** 활성 상태일 때 적용할 style (style과 병합됨) */
175
+ activeStyle?: React.CSSProperties;
176
+ /** 활성 상태일 때 추가할 className */
177
+ activeClassName?: string;
174
178
  /** 정확히 일치해야 활성화 (기본: false) */
175
179
  exact?: boolean;
176
180
  }
@@ -179,6 +183,8 @@ export function NavLink({
179
183
  href,
180
184
  className,
181
185
  style,
186
+ activeStyle,
187
+ activeClassName,
182
188
  exact = false,
183
189
  ...rest
184
190
  }: NavLinkProps): React.ReactElement {
@@ -190,12 +196,24 @@ export function NavLink({
190
196
  : window.location.pathname.startsWith(href)
191
197
  : false;
192
198
 
193
- const resolvedClassName =
199
+ // className 처리
200
+ let resolvedClassName =
194
201
  typeof className === "function" ? className({ isActive }) : className;
195
202
 
196
- const resolvedStyle =
203
+ if (isActive && activeClassName) {
204
+ resolvedClassName = resolvedClassName
205
+ ? `${resolvedClassName} ${activeClassName}`
206
+ : activeClassName;
207
+ }
208
+
209
+ // style 처리
210
+ let resolvedStyle =
197
211
  typeof style === "function" ? style({ isActive }) : style;
198
212
 
213
+ if (isActive && activeStyle) {
214
+ resolvedStyle = { ...resolvedStyle, ...activeStyle };
215
+ }
216
+
199
217
  return (
200
218
  <Link
201
219
  href={href}
@@ -264,11 +264,24 @@ function handlePopState(event: PopStateEvent): void {
264
264
  const state = event.state;
265
265
 
266
266
  if (state?.routeId) {
267
- // 이미 방문한 페이지 - 데이터 다시 fetch
267
+ // Mandu로 방문한 페이지 - 데이터 다시 fetch
268
268
  navigate(window.location.pathname + window.location.search, {
269
269
  replace: true,
270
270
  scroll: false,
271
271
  });
272
+ } else {
273
+ // 직접 URL 입력 등으로 방문한 페이지 - 상태만 업데이트
274
+ const route = (window as any).__MANDU_ROUTE__;
275
+ setGlobalRouterState({
276
+ currentRoute: route ? {
277
+ id: route.id,
278
+ pattern: route.pattern,
279
+ params: route.params || {},
280
+ } : null,
281
+ loaderData: getGlobalRouterState().loaderData,
282
+ navigation: { state: "idle" },
283
+ });
284
+ notifyListeners();
272
285
  }
273
286
  }
274
287