@mi-avalon/libs 1.0.6 → 1.0.8

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,4 +1,3 @@
1
- export * from './calc';
2
- export * from './nextTick';
3
- export * from './openModal';
4
- export * from './util';
1
+ export * from "./calc";
2
+ export * from "./nextTick";
3
+ export * from "./util";
@@ -1,4 +1,3 @@
1
- export * from './calc';
2
- export * from './nextTick';
3
- export * from './openModal';
4
- export * from './util';
1
+ export * from "./calc";
2
+ export * from "./nextTick";
3
+ export * from "./util";
@@ -1,5 +1,5 @@
1
- import type { ModalProps } from 'antd';
2
- import { type ComponentType } from 'react';
1
+ import type { ModalProps } from "antd";
2
+ import { type ComponentType } from "react";
3
3
  interface IModalBaseClosedParams {
4
4
  cancel?: boolean;
5
5
  ok?: boolean;
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import * as ReactDOMClient from 'react-dom/client';
2
+ import * as ReactDOMClient from "react-dom/client";
3
3
  const { createRoot } = ReactDOMClient;
4
4
  const destroyFns = [];
5
5
  let modalContainer = null;
6
6
  let root = null;
7
7
  function getOrCreateContainer() {
8
8
  if (!modalContainer) {
9
- modalContainer = document.createElement('div');
9
+ modalContainer = document.createElement("div");
10
10
  document.body.appendChild(modalContainer);
11
11
  }
12
12
  return modalContainer;
@@ -27,7 +27,7 @@ function openModal(DialogComponent, initialConfig) {
27
27
  root = createRoot(container);
28
28
  }
29
29
  catch (error) {
30
- console.error('Failed to create root:', error);
30
+ console.error("Failed to create root:", error);
31
31
  return {
32
32
  destroy: () => { },
33
33
  update: () => { },
@@ -45,7 +45,7 @@ function openModal(DialogComponent, initialConfig) {
45
45
  }
46
46
  };
47
47
  const destroy = (params) => {
48
- if (typeof currentConfig.onClosed === 'function') {
48
+ if (typeof currentConfig.onClosed === "function") {
49
49
  currentConfig.onClosed(params);
50
50
  }
51
51
  // 从 destroyFns 中移除
@@ -63,7 +63,7 @@ function openModal(DialogComponent, initialConfig) {
63
63
  };
64
64
  const update = (configUpdate) => {
65
65
  currentConfig =
66
- typeof configUpdate === 'function'
66
+ typeof configUpdate === "function"
67
67
  ? configUpdate(currentConfig)
68
68
  : { ...currentConfig, ...configUpdate };
69
69
  render(currentConfig);
@@ -85,7 +85,7 @@ function openModal(DialogComponent, initialConfig) {
85
85
  render(currentConfig);
86
86
  }
87
87
  else {
88
- console.warn('Modal is already closed.');
88
+ console.warn("Modal is already closed.");
89
89
  }
90
90
  };
91
91
  render(currentConfig);
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@mi-avalon/libs",
3
3
  "private": false,
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.es.js",
8
8
  "types": "./dist/index.d.ts",
9
+ "style": "./dist/style.css",
9
10
  "files": [
10
11
  "dist"
11
12
  ],
@@ -1,15 +0,0 @@
1
- import { ThemeConfig } from 'antd';
2
- import React, { Component } from 'react';
3
- import { IModalBaseProps, IModalControls } from '../../utils';
4
- export type IMiModalProps = IModalBaseProps & {
5
- mode?: string;
6
- };
7
- export declare class MiModal extends Component<IMiModalProps> {
8
- static setMode: (mode: string) => void;
9
- static setThemeConfig: (fn: (m: string) => ThemeConfig) => void;
10
- static open: (props: IMiModalProps) => IModalControls<IMiModalProps>;
11
- getTheme(): ThemeConfig;
12
- handleCancel: (e: React.MouseEvent<HTMLButtonElement>) => void;
13
- handleOk: (e: React.MouseEvent<HTMLButtonElement>) => void;
14
- render(): import("react/jsx-runtime").JSX.Element;
15
- }
@@ -1,70 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Modal as AntModal, ConfigProvider, theme } from 'antd';
3
- import { Component } from 'react';
4
- import { openModal } from '../../utils';
5
- // 全局状态管理
6
- let globalMode = 'default';
7
- const modalInstances = [];
8
- let getThemeConfig = (mode) => {
9
- switch (mode) {
10
- case 'light':
11
- return {
12
- algorithm: [theme.defaultAlgorithm],
13
- };
14
- case 'dark':
15
- return {
16
- algorithm: [theme.darkAlgorithm],
17
- };
18
- default:
19
- return {
20
- algorithm: [theme.defaultAlgorithm],
21
- };
22
- }
23
- };
24
- export class MiModal extends Component {
25
- // 静态方法设置全局模式并更新所有弹窗
26
- static setMode = (mode) => {
27
- globalMode = mode;
28
- // 更新所有已打开的弹窗
29
- modalInstances.forEach(instance => {
30
- instance.update({ mode });
31
- });
32
- };
33
- // 静态方法设置全局ThemeConfig
34
- static setThemeConfig = (fn) => {
35
- getThemeConfig = fn;
36
- };
37
- static open = (props) => {
38
- const instance = openModal(MiModal, {
39
- mode: globalMode, // 默认使用全局主题
40
- ...props,
41
- });
42
- // 注册实例以便全局更新
43
- modalInstances.push(instance);
44
- // 添加销毁时的清理逻辑
45
- const originalDestroy = instance.destroy;
46
- instance.destroy = (...args) => {
47
- const index = modalInstances.indexOf(instance);
48
- if (index !== -1) {
49
- modalInstances.splice(index, 1);
50
- }
51
- return originalDestroy(...args);
52
- };
53
- return instance;
54
- };
55
- getTheme() {
56
- const mode = this.props.mode || globalMode;
57
- return getThemeConfig(mode);
58
- }
59
- handleCancel = (e) => {
60
- this.props.onCancel?.(e);
61
- this.props.onClosed?.({ cancel: true });
62
- };
63
- handleOk = (e) => {
64
- this.props.onOk?.(e);
65
- this.props.onClosed?.({ ok: true });
66
- };
67
- render() {
68
- return (_jsx(ConfigProvider, { theme: this.getTheme(), componentSize: 'middle', children: _jsx(AntModal, { maskClosable: false, open: this.props.open, onCancel: this.handleCancel, onOk: this.handleOk, okText: '\u786E\u5B9A', cancelText: '\u53D6\u6D88', ...this.props, children: this.props.children }) }));
69
- }
70
- }