message-verify 0.0.29-beta.0 → 0.0.30-beta.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/dist/index.d.ts CHANGED
@@ -1,14 +1,5 @@
1
- interface Props {
2
- data: {
3
- mobile: string;
4
- verifyCodeKey: string;
5
- sendSuccess: boolean;
6
- };
7
- refresh: () => void;
8
- isShow: boolean;
9
- }
10
- declare function createMessageVerify(props: Props): {
11
- destroy: () => void;
1
+ export type ModalConfig = {
2
+ content: React.ReactNode;
3
+ onClose?: () => void;
12
4
  };
13
- export { createMessageVerify };
14
- export default createMessageVerify;
5
+ export declare const showModal: (config: ModalConfig) => void;
package/dist/index.js CHANGED
@@ -1,21 +1,53 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import App from './app.js';
3
- import { createRoot } from 'react-dom/client';
4
- function createMessageVerify(props) {
5
- // 创建一个挂载点
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // import App from './app.js';
3
+ // import { createRoot } from 'react-dom/client';
4
+ // interface Props {
5
+ // data: {
6
+ // mobile: string;
7
+ // verifyCodeKey: string;
8
+ // sendSuccess: boolean;
9
+ // };
10
+ // refresh: () => void;
11
+ // isShow: boolean;
12
+ // }
13
+ // function createMessageVerify(props: Props) {
14
+ // // 创建一个挂载点
15
+ // const container = document.createElement('div');
16
+ // document.body.appendChild(container);
17
+ // // 渲染弹窗
18
+ // const root = createRoot(container);
19
+ // // 这里 isShow 直接传 true,弹窗立即显示
20
+ // root.render(<App {...props} isShow={true} />);
21
+ // // 可选:返回关闭方法
22
+ // return {
23
+ // destroy: () => {
24
+ // root.unmount();
25
+ // document.body.removeChild(container);
26
+ // }
27
+ // };
28
+ // }
29
+ // export { createMessageVerify };
30
+ // export default createMessageVerify;
31
+ // src/modal.tsx
32
+ import ReactDOM from 'react-dom/client';
33
+ let modalRoot = null;
34
+ const Modal = ({ content, onClose }) => (_jsx("div", { className: "modal-overlay", children: _jsxs("div", { className: "modal-content", children: [content, _jsx("button", { onClick: onClose, children: "Close" })] }) }));
35
+ export const showModal = (config) => {
36
+ // 创建容器
6
37
  const container = document.createElement('div');
38
+ container.id = 'global-modal-container';
7
39
  document.body.appendChild(container);
8
40
  // 渲染弹窗
9
- const root = createRoot(container);
10
- // 这里 isShow 直接传 true,弹窗立即显示
11
- root.render(_jsx(App, { ...props, isShow: true }));
12
- // 可选:返回关闭方法
13
- return {
14
- destroy: () => {
15
- root.unmount();
16
- document.body.removeChild(container);
17
- }
18
- };
19
- }
20
- export { createMessageVerify };
21
- export default createMessageVerify;
41
+ modalRoot = ReactDOM.createRoot(container);
42
+ modalRoot.render(_jsx(Modal, { ...config, onClose: () => {
43
+ config.onClose?.();
44
+ destroyModal();
45
+ } }));
46
+ };
47
+ const destroyModal = () => {
48
+ if (modalRoot) {
49
+ modalRoot.unmount();
50
+ document.getElementById('global-modal-container')?.remove();
51
+ modalRoot = null;
52
+ }
53
+ };
package/dist/main.js CHANGED
@@ -1,8 +1,4 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createRoot } from 'react-dom/client';
3
- import App from './app.js'; // 或 './index'
4
- createRoot(document.getElementById('root')).render(_jsx(App, { data: {
5
- mobile: '185****7760',
6
- verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
7
- sendSuccess: true
8
- }, refresh: () => { console.log('刷新'); }, isShow: true }));
3
+ import { showModal } from './index.js'; // 或 './index'
4
+ createRoot(document.getElementById('root')).render(_jsx("button", { onClick: () => showModal({ content: 'React Content' }), children: "Show Modal" }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "message-verify",
3
- "version": "0.0.29-beta.0",
3
+ "version": "0.0.30-beta.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "dependencies": {
package/src/index.tsx CHANGED
@@ -1,34 +1,79 @@
1
- import App from './app.js';
2
- import { createRoot } from 'react-dom/client';
3
-
4
- interface Props {
5
- data: {
6
- mobile: string;
7
- verifyCodeKey: string;
8
- sendSuccess: boolean;
9
- };
10
- refresh: () => void;
11
- isShow: boolean;
1
+ // import App from './app.js';
2
+ // import { createRoot } from 'react-dom/client';
3
+
4
+ // interface Props {
5
+ // data: {
6
+ // mobile: string;
7
+ // verifyCodeKey: string;
8
+ // sendSuccess: boolean;
9
+ // };
10
+ // refresh: () => void;
11
+ // isShow: boolean;
12
+ // }
13
+
14
+ // function createMessageVerify(props: Props) {
15
+ // // 创建一个挂载点
16
+ // const container = document.createElement('div');
17
+ // document.body.appendChild(container);
18
+
19
+ // // 渲染弹窗
20
+ // const root = createRoot(container);
21
+ // // 这里 isShow 直接传 true,弹窗立即显示
22
+ // root.render(<App {...props} isShow={true} />);
23
+
24
+ // // 可选:返回关闭方法
25
+ // return {
26
+ // destroy: () => {
27
+ // root.unmount();
28
+ // document.body.removeChild(container);
29
+ // }
30
+ // };
31
+ // }
32
+
33
+ // export { createMessageVerify };
34
+ // export default createMessageVerify;
35
+ // src/modal.tsx
36
+ import ReactDOM from 'react-dom/client'
37
+
38
+ export type ModalConfig = {
39
+ content: React.ReactNode
40
+ onClose?: () => void
12
41
  }
13
42
 
14
- function createMessageVerify(props: Props) {
15
- // 创建一个挂载点
16
- const container = document.createElement('div');
17
- document.body.appendChild(container);
18
-
19
- // 渲染弹窗
20
- const root = createRoot(container);
21
- // 这里 isShow 直接传 true,弹窗立即显示
22
- root.render(<App {...props} isShow={true} />);
23
-
24
- // 可选:返回关闭方法
25
- return {
26
- destroy: () => {
27
- root.unmount();
28
- document.body.removeChild(container);
29
- }
30
- };
43
+ let modalRoot: ReactDOM.Root | null = null
44
+
45
+ const Modal = ({ content, onClose }: ModalConfig) => (
46
+ <div className="modal-overlay">
47
+ <div className="modal-content">
48
+ {content}
49
+ <button onClick={onClose}>Close</button>
50
+ </div>
51
+ </div>
52
+ )
53
+
54
+ export const showModal = (config: ModalConfig) => {
55
+ // 创建容器
56
+ const container = document.createElement('div')
57
+ container.id = 'global-modal-container'
58
+ document.body.appendChild(container)
59
+
60
+ // 渲染弹窗
61
+ modalRoot = ReactDOM.createRoot(container)
62
+ modalRoot.render(
63
+ <Modal
64
+ {...config}
65
+ onClose={() => {
66
+ config.onClose?.()
67
+ destroyModal()
68
+ }}
69
+ />
70
+ )
31
71
  }
32
72
 
33
- export { createMessageVerify };
34
- export default createMessageVerify;
73
+ const destroyModal = () => {
74
+ if (modalRoot) {
75
+ modalRoot.unmount()
76
+ document.getElementById('global-modal-container')?.remove()
77
+ modalRoot = null
78
+ }
79
+ }
package/src/main.tsx CHANGED
@@ -1,13 +1,7 @@
1
1
  import { createRoot } from 'react-dom/client';
2
- import App from './app.js'; // 或 './index'
2
+ import { showModal } from './index.js'; // 或 './index'
3
3
 
4
4
  createRoot(document.getElementById('root')!).render(
5
- <App
6
- data={{
7
- mobile: '185****7760',
8
- verifyCodeKey: 'e381c5f9-c7f4-4bf1-a948-744334fb0203',
9
- sendSuccess: true
10
- }}
11
- refresh={() => {console.log('刷新')}}
12
- isShow={true}
13
- />);
5
+ <button onClick={() => showModal({ content: 'React Content' })}>
6
+ Show Modal
7
+ </button>);