@moneko/react 3.0.0-beta.2 → 3.0.0-beta.4

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.
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ export type ActivityMode = 'visible' | 'hidden';
3
+ export interface ActivityProps {
4
+ mode: ActivityMode;
5
+ children: React.ReactNode;
6
+ }
7
+ /**
8
+ * @param {ActivityProps} props
9
+ * @description 状态保持组件
10
+ */ declare const Activity: React.FC<ActivityProps>;
11
+ export default Activity;
@@ -0,0 +1 @@
1
+ import{jsxDEV as e}from"react/jsx-dev-runtime";var t=$RefreshSig$();import i from"react";let r="Activity"in i&&i.Activity||"unstable_Activity"in i&&i.unstable_Activity||null,l=e=>{t();let{mode:r,children:l}=e,n=i.useRef(null),u=i.useRef(null),c=i.useCallback(()=>{"function"==typeof u.current&&(u.current(),u.current=null,n.current=null)},[]);if(i.useEffect(()=>c,[c]),"hidden"===r){null===u.current&&(n.current=new Promise(e=>u.current=e));let e=n.current;if("use"in i&&"function"==typeof i.use)i.use(e);else throw e}return"visible"===r&&c(),l};t(l,"t7VQz0w8/C4yQSfti2FIneuLTJc=");let n=t=>r?e(r,{mode:t.mode,children:t.children},void 0,!1,{fileName:"src/activity.tsx",lineNumber:56,columnNumber:12},this):e(i.Suspense,{fallback:null,children:e(l,{mode:t.mode,children:t.children},void 0,!1,{fileName:"src/activity.tsx",lineNumber:61,columnNumber:7},this)},void 0,!1,{fileName:"src/activity.tsx",lineNumber:60,columnNumber:5},this);export default n;$RefreshReg$(l,"Repeater"),$RefreshReg$(n,"Activity");
@@ -0,0 +1,22 @@
1
+ import * as React from 'react';
2
+ export interface ErrorBoundaryProps {
3
+ children: React.ReactNode;
4
+ /**
5
+ * 自定义错误降级组件
6
+ */ fallback?: React.ComponentType<ErrorBoundaryState>;
7
+ }
8
+ /** 错误边界状态 */ export interface ErrorBoundaryState {
9
+ /** 捕获的错误 */ error?: Error;
10
+ /** 错误信息 */ errorInfo: {
11
+ /** 组件堆栈 */ componentStack?: string;
12
+ /** 错误摘要 */ digest?: string;
13
+ };
14
+ }
15
+ /** 错误边界 */ declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, Partial<ErrorBoundaryState>> {
16
+ componentNameRegex: RegExp;
17
+ constructor(props: ErrorBoundaryProps);
18
+ componentDidCatch(error: ErrorBoundaryState['error'], errorInfo: ErrorBoundaryState['errorInfo']): void;
19
+ getComponentName(componentStack?: string): string | null;
20
+ render(): React.ReactNode;
21
+ }
22
+ export default ErrorBoundary;
@@ -0,0 +1,4 @@
1
+ import{jsxDEV as r,Fragment as e}from"react/jsx-dev-runtime";var t=$RefreshSig$();import*as n from"react";let o=({stack:o,heading:i})=>{t();let[a,s]=n.useState(null);if(!o)return null;let l=o.split("\n");return r(e,{children:[i&&r("strong",{children:["🛑 ",i]},void 0,!0,{fileName:"src/error-boundary.tsx",lineNumber:131,columnNumber:19},this),l.map((t,o)=>{let i=function(r){let e=r.match(/webpack-internal:\/\/\/(.*?):(\d+):(\d+)/);if(e){let[r,t,n,o]=e;return{prefix:e.input?.substring(0,e.index),file:t,fileName:t.split("/").pop(),line:parseInt(n,10),column:parseInt(o,10),suffix:e.input?.substring((e.index??0)+r.length)}}let t=r.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))/);if(t){let[r,e,n,o,i]=t;return{prefix:t.input?.substring(0,t.index),func:e,file:n,fileName:n.split("/").pop(),line:parseInt(o,10),column:parseInt(i,10),suffix:t.input?.substring((t.index??0)+r.length)}}return null}(t);return r(n.Fragment,{children:[" ",i?r(e,{children:[i.prefix,r("a",{style:{color:"var(--link-color, #1677ff)",textDecoration:"none"},onClick:()=>{i.file===a?.file?s(null):s({file:i.file,source:function(r){try{let e=__webpack_require__.m,t=Object.keys(e).find(e=>e.includes(r));if(t)return function(r){let e=__webpack_require__.m[r].toString(),t=function(r){let e="//# sourceMappingURL=data:application/json;charset=utf-8;base64,",t=r.indexOf(e)+e.length,n="";if(-1!==t){let e=r.indexOf("\\n//#",t);n=r.substring(t,e)}return n}(e);if(t){let r=new TextDecoder("utf-8"),e=atob(t);if(e){let t=function(r){try{return JSON.parse(r)}catch{return null}}(r.decode(new Uint8Array(e.split("").map(r=>r.charCodeAt(0)))));if(t?.sourcesContent)return t.sourcesContent[0]}}return e}(t);return null}catch(r){return r.message}}(i.file)})},children:[i.fileName,":",i.line,":",i.column]},void 0,!0,{fileName:"src/error-boundary.tsx",lineNumber:141,columnNumber:17},this),i.suffix]},void 0,!0):t,r("br",{},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:158,columnNumber:13},this)]},t+o,!0,{fileName:"src/error-boundary.tsx",lineNumber:136,columnNumber:11},this)}),a&&r("div",{style:{marginBlockStart:16,border:"1px solid var(--warning-border, #ffe58f)",borderRadius:"var(--border-radius, 8px)",padding:16,backgroundColor:"var(--warning-bg, #fffbe6)"},children:[r("strong",{children:["Source: ",a.file]},void 0,!0,{fileName:"src/error-boundary.tsx",lineNumber:172,columnNumber:11},this),r("pre",{style:{whiteSpace:"pre-wrap"},children:a.source},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:173,columnNumber:11},this)]},void 0,!0,{fileName:"src/error-boundary.tsx",lineNumber:163,columnNumber:9},this)]},void 0,!0)};t(o,"Us3ayDKlF5Fj0pCacaPVHhfjLWk=");class i extends n.Component{constructor(r){super(r),this.componentNameRegex=/at (?:(.+?)\s+\()?(?:(.+?):(\d+):(\d+))/,this.state={}}componentDidCatch(r,e){this.setState({error:r,errorInfo:e})}getComponentName(r){let e=r?.trim().split("\n")?.[0].match(this.componentNameRegex)?.[1];return e?`The above error occurred in the <${e}> component.
2
+
3
+ React will try to recreate this component tree from scratch using the error boundary you provided, ErrorBoundary.
4
+ Error Component Stack`:null}render(){if(this.state.errorInfo){let t=this.props.fallback;return t?r(t,{error:this.state.error,errorInfo:this.state.errorInfo},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:213,columnNumber:16},this):r("pre",{className:"error-boundary-component-stack",style:{display:"block",maxInlineSize:"100%",maxBlockSize:"100%",overflow:"auto",margin:24,border:"1px solid var(--error-border, #ffccc7)",borderRadius:"var(--border-radius, 8px)",padding:20,backgroundColor:"var(--error-bg, #fff2f0)",whiteSpace:"pre-wrap",fontSize:12,color:"var(--error-color, rgb(0 0 0 / 75%))",fontFamily:"var(--font-family, inherit)"},children:this.state.error&&r(e,{children:[r(o,{stack:this.state.error.stack?.replace(`${this.state.error.name}: ${this.state.error.message}`,""),heading:`${this.state.error.name}: ${this.state.error.message}`},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:236,columnNumber:15},this),r("br",{},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:243,columnNumber:15},this),r(o,{stack:this.state.errorInfo.componentStack,heading:this.getComponentName(this.state.errorInfo.componentStack)},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:244,columnNumber:15},this)]},void 0,!0)},void 0,!1,{fileName:"src/error-boundary.tsx",lineNumber:216,columnNumber:9},this)}return this.props.children}}export default i;$RefreshReg$(o,"ErrorStack");
package/dev/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ export * from 'react-router-dom';
3
+ // 导入并覆盖 useNavigate,使用自定义版本
4
+ export { default as ErrorBoundary, type ErrorBoundaryProps, type ErrorBoundaryState } from './error-boundary.js';
5
+ export { default as Link } from './link.js';
6
+ export { default as parseToByReservedWord, type To } from './parse-reserved-word.js';
7
+ export { default as useNavigate } from './use-navgate.js';
8
+ export { default as useQuery } from './use-query.js';
9
+ export { /** 原版 Link */ Link as LinkReactRouter, /** 原版 useNavigate */ useNavigate as useNavigateReactRouter } from 'react-router-dom';
10
+ export type RenderAppProps = {
11
+ container?: HTMLElement;
12
+ basename?: string;
13
+ fallback?: React.JSX.Element;
14
+ language?: string;
15
+ };
16
+ export { default as Activity, type ActivityMode, type ActivityProps } from './activity.js';
17
+ export default React;
package/dev/index.js ADDED
@@ -0,0 +1 @@
1
+ import*as e from"react";export*from"react-router-dom";export{default as ErrorBoundary}from"./error-boundary.js";export{default as Link}from"./link.js";export{default as parseToByReservedWord}from"./parse-reserved-word.js";export{default as useNavigate}from"./use-navgate.js";export{default as useQuery}from"./use-query.js";export{Link as LinkReactRouter,useNavigate as useNavigateReactRouter}from"react-router-dom";export{default as Activity}from"./activity.js";export default e;
package/dev/link.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { type LinkProps as ReactRouterLinkProps } from 'react-router-dom';
3
+ import { type To } from './parse-reserved-word.js';
4
+ export interface LinkProps extends Omit<ReactRouterLinkProps, 'to'> {
5
+ /** 保留字 */ reserved?: string | string[];
6
+ to: To;
7
+ }
8
+ /** 跳转时继承部分query参数
9
+ * @default {string[]} ['menuId', 'dynamicTitle']
10
+ */ declare const Link: React.FC<LinkProps>;
11
+ export default Link;
package/dev/link.js ADDED
@@ -0,0 +1 @@
1
+ import{jsxDEV as r}from"react/jsx-dev-runtime";import"react";import{Link as e}from"react-router-dom";import t from"./parse-reserved-word.js";let o=({reserved:o,to:i,children:m,...s})=>r(e,{...s,to:t(i,o),children:m},void 0,!1,{fileName:"src/link.tsx",lineNumber:17,columnNumber:5},this);export default o;$RefreshReg$(o,"Link");
@@ -0,0 +1,9 @@
1
+ import type { Path } from 'react-router-dom';
2
+ type SearchParams = ConstructorParameters<typeof URLSearchParams>[0];
3
+ type NormalRecord = Record<string, string | number | boolean | undefined | null>;
4
+ export interface IPath extends Partial<Omit<Path, 'search'>> {
5
+ search?: SearchParams | NormalRecord;
6
+ }
7
+ export type To = string | IPath;
8
+ declare const parseToByReservedWord: (to: To | number, reserved?: string | string[]) => Partial<Path>;
9
+ export default parseToByReservedWord;
@@ -0,0 +1 @@
1
+ export default((e,a)=>{let r,t,n;if("number"==typeof e)return e;if("string"==typeof e){let a=e.split("?");t=a[0],r=new URLSearchParams(a[1])}else{let a=e.pathname?e.pathname.split("?"):[];t=a[0],r=new URLSearchParams(e.search),a[1]&&new URLSearchParams(a[1]).forEach((e,a)=>{r.has(a)||r.set(a,e)}),n=e.hash}let s=new URLSearchParams(location.search);return Array.from(new Set(["menuId","dynamicTitle"].concat(Array.isArray(a)?a:a?[a]:[]))).forEach(e=>{r.has(e)?"undefined"===r.get(e)&&r.delete(e):s.has(e)&&r.set(e,s.get(e)??"")}),{pathname:t,search:r.toString(),hash:n}});
@@ -0,0 +1,10 @@
1
+ import { type NavigateOptions } from 'react-router-dom';
2
+ import { type To } from './parse-reserved-word.js';
3
+ interface NavigateFunction {
4
+ (to: To, options?: NavigateOptions) : void;
5
+ (delta: number) : void;
6
+ }
7
+ /** 跳转时继承部分query参数
8
+ * @default {string[]} ['menuId', 'dynamicTitle']
9
+ */ declare const useNavigate: (/** search保留字 */ reserved?: string | string[]) => NavigateFunction;
10
+ export default useNavigate;
@@ -0,0 +1 @@
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)=>o(e(r,t),a)});
@@ -0,0 +1,2 @@
1
+ declare const useQuery: <T>() => T;
2
+ export default useQuery;
@@ -0,0 +1 @@
1
+ import*as r from"react";import{useLocation as e}from"react-router-dom";export default(()=>{let t=e();return r.useMemo(()=>Object.fromEntries(new URLSearchParams(t.search)),[t.search])});
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@moneko/react",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.4",
4
4
  "description": "react",
5
- "main": "index.js",
5
+ "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "prebuild": "rm -rf ./lib",
8
8
  "build": "node ./build.mjs",
@@ -11,6 +11,18 @@
11
11
  "lint:commit": "lint-git mode=commit",
12
12
  "lint:ci": "lint-git mode=ci"
13
13
  },
14
+ "exports": {
15
+ ".": {
16
+ "development": "./dev/index.js",
17
+ "production": "./lib/index.js",
18
+ "default": "./lib/index.js"
19
+ },
20
+ "./mdx": {
21
+ "development": "./mdx.dev.js",
22
+ "production": "./mdx.prod.js",
23
+ "default": "./mdx.prod.js"
24
+ }
25
+ },
14
26
  "author": "moneko",
15
27
  "type": "module",
16
28
  "license": "MIT",
@@ -27,12 +39,12 @@
27
39
  "@moneko/convert": "1.1.4",
28
40
  "@moneko/eslint": "1.10.0",
29
41
  "@moneko/stylelint": "1.7.0",
30
- "@moneko/transform-imports": "1.3.0",
42
+ "@moneko/transform-imports": "1.3.1",
31
43
  "@moneko/utils": "0.3.3",
32
44
  "@swc/core": "^1.15.1",
33
- "@types/node": "24.10.0",
34
- "@types/react": "19.2.2",
35
- "@types/react-dom": "19.2.2",
45
+ "@types/node": "24.10.1",
46
+ "@types/react": "19.2.3",
47
+ "@types/react-dom": "19.2.3",
36
48
  "husky": "9.1.7",
37
49
  "lint-staged-by-git": "1.3.0",
38
50
  "react": "19.2.0",
@@ -41,16 +53,13 @@
41
53
  },
42
54
  "files": [
43
55
  "lib",
56
+ "dev",
44
57
  "jest-preset.js",
45
58
  "base.json",
46
59
  "lib.json",
47
60
  "env.d.ts",
48
- "mdx.js",
49
61
  "mdx.dev.js",
50
62
  "mdx.prod.js",
51
- "mdx.js.map",
52
- "mdx.d.ts",
53
- "index.js",
54
- "index.d.ts"
63
+ "mdx.d.ts"
55
64
  ]
56
65
  }
package/index.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./lib/index.js');
5
- } else {
6
- module.exports = require('./dev/index.js');
7
- }
package/mdx.js DELETED
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === 'production') {
4
- module.exports = require('./mdx.prod.js');
5
- } else {
6
- module.exports = require('./mdx.dev.js');
7
- }