@moneko/react 1.7.0-beta.2 → 1.7.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.
@@ -1,25 +1,17 @@
1
1
  import * as React from 'react';
2
2
  export interface ErrorBoundaryProps {
3
3
  children: React.ReactNode;
4
- /**
5
- * 自定义错误降级组件
6
- */
7
4
  fallback?: React.ComponentType<ErrorBoundaryState>;
8
5
  }
9
- /** 错误边界状态 */
10
6
  export interface ErrorBoundaryState {
11
- /** 捕获的错误 */
12
7
  error?: Error;
13
- /** 错误信息 */
14
8
  errorInfo: {
15
- /** 组件堆栈 */
16
9
  componentStack?: string;
17
10
  };
18
11
  }
19
- /** 错误边界 */
20
12
  declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, Partial<ErrorBoundaryState>> {
21
13
  constructor(props: ErrorBoundaryProps);
22
- componentDidCatch(error: ErrorBoundaryState['error'], errorInfo: ErrorBoundaryState['errorInfo']): void;
23
- render(): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
14
+ componentDidCatch(error: ErrorBoundaryState['error'], errorInfo: ErrorBoundaryState['errorInfo']);
15
+ render();
24
16
  }
25
17
  export default ErrorBoundary;
@@ -1 +1 @@
1
- import{jsx as r,jsxs as t}from"react/jsx-runtime";import*as e from"react";class o extends e.Component{constructor(r){super(r),this.state={}}componentDidCatch(r,t){this.setState({error:r,errorInfo:t})}render(){if(this.state.errorInfo){let e=this.props.fallback;return e?/*#__PURE__*/r(e,{error:this.state.error,errorInfo:this.state.errorInfo}):/*#__PURE__*/t("div",{children:[/*#__PURE__*/r("h2",{children:"Something went wrong."}),/*#__PURE__*/t("details",{style:{whiteSpace:"pre-wrap",color:"var(--error-color, red)"},children:[this.state.error&&this.state.error.toString(),/*#__PURE__*/r("br",{}),this.state.errorInfo.componentStack]})]})}return this.props.children}}export default o;
1
+ import{jsx as r,jsxs as t}from"react/jsx-runtime";import*as e from"react";class o extends e.Component{constructor(r){super(r),this.state={}}componentDidCatch(r,t){this.setState({error:r,errorInfo:t})}render(){if(this.state.errorInfo){let e=this.props.fallback;return e?r(e,{error:this.state.error,errorInfo:this.state.errorInfo}):t("div",{children:[r("h2",{children:"Something went wrong."}),t("details",{style:{whiteSpace:"pre-wrap",color:"var(--error-color, red)"},children:[this.state.error&&this.state.error.toString(),r("br",{}),this.state.errorInfo.componentStack]})]})}return this.props.children}}export default o;
package/lib/index.d.ts CHANGED
@@ -2,16 +2,13 @@ import * as React from 'react';
2
2
  export * from 'react-router-dom';
3
3
  export { default as useNavigate } from './use-navgate.js';
4
4
  export { default as Link } from './link.js';
5
- export {
6
- /** 原版 useNavigate */
7
- useNavigate as useNavigateReactRouter,
8
- /** 原版 Link */
9
- Link as LinkReactRouter, } from 'react-router-dom';
10
- export { default as ErrorBoundary, type ErrorBoundaryProps, type ErrorBoundaryState, } from './error-boundary.js';
5
+ export { default as useQuery } from './use-query.js';
6
+ export { useNavigate as useNavigateReactRouter, Link as LinkReactRouter } from 'react-router-dom';
7
+ export { default as ErrorBoundary, type ErrorBoundaryProps, type ErrorBoundaryState } from './error-boundary.js';
11
8
  export type RenderAppProps = {
12
9
  container?: HTMLElement;
13
10
  basename?: string;
14
- fallback?: JSX.Element;
11
+ fallback?: React.JSX.Element;
15
12
  language?: string;
16
13
  };
17
14
  export default React;
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import*as r from"react";export*from"react-router-dom";export{default as useNavigate}from"./use-navgate.js";export{default as Link}from"./link.js";export{useNavigate as useNavigateReactRouter,Link as LinkReactRouter}from"react-router-dom";export{default as ErrorBoundary}from"./error-boundary.js";export default r;
1
+ import*as e from"react";export*from"react-router-dom";export{default as useNavigate}from"./use-navgate.js";export{default as Link}from"./link.js";export{default as useQuery}from"./use-query.js";export{useNavigate as useNavigateReactRouter,Link as LinkReactRouter}from"react-router-dom";export{default as ErrorBoundary}from"./error-boundary.js";export default e;
@@ -1 +1,3 @@
1
- export declare const injectReactRefresh: () => void;
1
+ import ReactDOM from 'react-dom';
2
+ import { injectIntoGlobalHook } from 'react-refresh';
3
+ export declare const injectReactRefresh: () => any;
package/lib/link.d.tsx ADDED
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { Link as ReactRouterLink, type LinkProps as ReactRouterLinkProps } from 'react-router-dom';
3
+ import parseToByReservedWord from './parse-reserved-word.js';
4
+ export interface LinkProps extends ReactRouterLinkProps {
5
+ reserved?: string | string[];
6
+ }
7
+ declare const Link: React.FC<LinkProps>;
8
+ export default Link;
package/lib/link.js CHANGED
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import{useMemo as e}from"react";import{Link as t,useSearchParams as a}from"react-router-dom";export default(({reserved:i,to:n,children:o,...m})=>{let l=e(()=>["menuId","dynamicTitle",...Array.isArray(i)?i:[i]].filter(Boolean),[i]),[c]=a(),s=e(()=>{if(-1===n)return -1;let r={};c.forEach((e,t)=>{l.includes(t)&&(r[t]=e)});let e=n,t=e.indexOf("?");-1!==t&&(new URLSearchParams(e.slice(t)).forEach((e,t)=>{r[t]=e}),e=e.substring(0,t));let a=new URLSearchParams(r).toString();return a?.trim().length?[e,a].join("?"):e},[l,c,n]);return /*#__PURE__*/r(t,{...m,to:s,children:o})});
1
+ import{jsx as r}from"react/jsx-runtime";import"react";import{Link as e}from"react-router-dom";import o from"./parse-reserved-word.js";export default(({reserved:t,to:m,children:a,...i})=>r(e,{...i,to:o(m,t),children:a}));
@@ -0,0 +1,5 @@
1
+ import type { To } from 'react-router-dom';
2
+ declare function parse(reserved?: string | string[]);
3
+ declare function parseReservedWord(reserved?: string | string[]): string[];
4
+ declare const parseToByReservedWord: (to: To, reserved?: string | string[]) => any;
5
+ export default parseToByReservedWord;
@@ -0,0 +1 @@
1
+ export default((e,a)=>{let r,t,s;if("string"==typeof e){let a=e.split("?");t=a[0],r=new URLSearchParams(a[1])}else t=e.pathname,r=new URLSearchParams(e.search),s=e.hash;let n=new URLSearchParams(location.search);return Array.from(new Set(["menuId","dynamicTitle",...(Array.isArray(a)?a:[a]).filter(Boolean)])).forEach(e=>{n.has(e)&&r.set(e,n.get(e))}),{pathname:t,search:r.toString(),hash:s}});
@@ -1,6 +1,4 @@
1
- import { type NavigateOptions, type To } from 'react-router-dom';
2
- /** 跳转时继承部分query参数
3
- * @default {string[]} ['menuId', 'dynamicTitle']
4
- */
5
- declare const useNavigate: (reserved?: string | string[]) => (to: To | -1, options?: NavigateOptions) => void;
1
+ import { type NavigateFunction, type NavigateOptions, type To, useNavigate as useNavigateReactRouter } from 'react-router-dom';
2
+ import parseToByReservedWord from './parse-reserved-word.js';
3
+ declare const useNavigate: (reserved?: string | string[]) => NavigateFunction;
6
4
  export default useNavigate;
@@ -1 +1 @@
1
- import{useNavigate as e,useSearchParams as r}from"react-router-dom";export default(t=>{let a=Array.from(new Set(["menuId","dynamicTitle",...t||[]])).filter(Boolean),o=e(),[l]=r();return(e,r)=>{if(-1===e){o(-1);return}let t={},n=e.split("?"),i=new URLSearchParams(n[1]||"");for(let[e,r]of l)a.includes(e)&&(t[e]=r);for(let[e,r]of i)a.includes(e)&&(t[e]=r);let f=new URLSearchParams(t).toString();o(f?`${n[0]}?${f}`:n[0],r)}});
1
+ import{useNavigate as r}from"react-router-dom";import e from"./parse-reserved-word.js";export default(t=>{let o=r();return(r,a)=>"number"==typeof r?o(r):o(e(r,t),a)});
@@ -0,0 +1,4 @@
1
+ import { useMemo } from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ declare const useQuery: <T>() => any;
4
+ export default useQuery;
@@ -0,0 +1 @@
1
+ import{useMemo as r}from"react";import{useLocation as e}from"react-router-dom";export default(()=>{let t=e();return r(()=>Object.fromEntries(new URLSearchParams(t.search)),[t.search])});
package/mdx.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import * as React from 'react';
2
2
  export interface MDXComponents {
3
- [k: string]: (props: Record<string, any>) => JSX.Element;
3
+ [k: string]: (props: Record<string, any>) => React.JSX.Element;
4
4
  }
5
5
  export interface MDXProviderProps extends React.Component {
6
- children: JSX.Element;
6
+ children: React.JSX.Element;
7
7
  components: MDXComponents | ((props: Record<string, any>) => MDXComponents);
8
8
  disableParentContext?: boolean;
9
9
  }
10
+ declare const emptyComponents: Readonly<MDXComponents>;
11
+ declare const MDXContext: React.Context<Readonly<MDXComponents>>;
10
12
  export declare function useMDXComponents(components: MDXComponents | ((props: Record<string, any>) => MDXComponents)): MDXComponents;
11
- export declare function MDXProvider(props: MDXProviderProps): JSX.Element;
13
+ export declare function MDXProvider(props: MDXProviderProps): React.JSX.Element;
package/mdx.js CHANGED
@@ -1 +1 @@
1
- import{jsx as e}from"react/jsx-runtime";import*as t from"react";let n={},o=/*#__PURE__*/t.createContext(n);export function useMDXComponents(e){let n=t.useContext(o);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}export function MDXProvider(r){let s=t.useMemo(()=>r.disableParentContext?"function"==typeof r.components?r.components(n):r.components||n:useMDXComponents(r.components),[r.components,r.disableParentContext]);return /*#__PURE__*/e(o.Provider,{value:s,children:r.children})}
1
+ import{jsx as e}from"react/jsx-runtime";import*as t from"react";let n={},o=t.createContext(n);export function useMDXComponents(e){let n=t.useContext(o);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}export function MDXProvider(r){let s=t.useMemo(()=>r.disableParentContext?"function"==typeof r.components?r.components(n):r.components||n:useMDXComponents(r.components),[r.components,r.disableParentContext]);return e(o.Provider,{value:s,children:r.children})}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@moneko/react",
3
- "version": "1.7.0-beta.2",
3
+ "version": "1.7.1",
4
4
  "description": "react",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "prebuild": "rm -rf ./lib",
8
- "postbuild": "tsc && tsc mdx.tsx --jsx react --lib es2015 --declaration --emitDeclarationOnly",
9
- "build": "swc src -d lib --strip-leading-paths -D && swc mdx.tsx -o mdx.js"
8
+ "build": "node ./build.mjs",
9
+ "prepublishOnly": "npm run build"
10
10
  },
11
11
  "author": "moneko",
12
12
  "type": "module",
@@ -17,19 +17,19 @@
17
17
  "react-refresh-typescript": "2.0.10",
18
18
  "react-router": "6.27.0",
19
19
  "react-router-dom": "6.27.0",
20
- "shared-store-object": "1.1.4"
20
+ "shared-store-object": "1.2.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@moneko/transform-imports": "0.7.1",
24
- "@swc/cli": "0.5.0",
25
- "@swc/core": "1.9.2",
26
- "@types/node": "22.9.0",
27
- "@types/react": "18.3.12",
28
- "@types/react-dom": "18.3.1",
29
- "eslint-config-neko": "3.0.0",
30
- "react": "18.3.1",
31
- "react-dom": "18.3.1",
32
- "typescript": "5.6.3"
23
+ "@moneko/convert": "1.0.0",
24
+ "@moneko/transform-imports": "0.6.1",
25
+ "@moneko/utils": "0.1.22",
26
+ "@types/node": "22.10.5",
27
+ "@types/react": "19.0.2",
28
+ "@types/react-dom": "19.0.2",
29
+ "eslint-config-neko": "3.0.3",
30
+ "react": "19.0.0",
31
+ "react-dom": "19.0.0",
32
+ "typescript": "5.7.2"
33
33
  },
34
34
  "files": [
35
35
  "lib",
package/lib/link.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { type FC } from 'react';
2
- import { type LinkProps as ReactRouterLinkProps, type To } from 'react-router-dom';
3
- export interface LinkProps extends Omit<ReactRouterLinkProps, 'to'> {
4
- /** 保留字 */
5
- reserved?: string | string[];
6
- to: To | -1;
7
- }
8
- /** 跳转时继承部分query参数
9
- * @default {string[]} ['menuId', 'dynamicTitle']
10
- */
11
- declare const Link: FC<LinkProps>;
12
- export default Link;