@dune2/tools 1.0.2 → 1.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dune2/tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "i18n"
@@ -27,7 +27,6 @@
27
27
  "./storage/*": "./src/storage/*.ts",
28
28
  "./logger": "./src/logger/index.ts",
29
29
  "./logger/*": "./src/logger/*.ts",
30
- "./niceModal": "./src/niceModal/index.tsx",
31
30
  "./store": "./src/store/index.ts",
32
31
  "./package.json": "./package.json",
33
32
  ".": "./src/index.ts"
@@ -36,16 +35,14 @@
36
35
  "src"
37
36
  ],
38
37
  "dependencies": {
39
- "@ebay/nice-modal-react": "^1.2.13",
40
38
  "bignumber.js": "^9.1.2",
39
+ "es-toolkit": "^1",
41
40
  "js-cookie": "^3.0.5",
42
- "lodash": "^4",
43
41
  "store2": "^2.14.3"
44
42
  },
45
43
  "devDependencies": {
46
44
  "@tanstack/react-query": "5.51.11",
47
45
  "@types/js-cookie": "3.0.3",
48
- "@types/lodash": "^4.17.0",
49
46
  "axios": "^1.6.8",
50
47
  "react": "^19",
51
48
  "valtio": "^2"
@@ -1,4 +1,4 @@
1
- import _ from "lodash";
1
+ import { noop } from "es-toolkit";
2
2
  import store2 from "store2";
3
3
  import { Level, type OnLogParams } from "./shared";
4
4
 
@@ -16,7 +16,7 @@ export class Logger {
16
16
  * 只有大于等于当前等级的日志才会输出
17
17
  */
18
18
  public level = Level.Debug,
19
- public onLog: OnLog = _.noop,
19
+ public onLog: OnLog = noop,
20
20
  ) {
21
21
  this.level = this.getStorageLevel() ?? level;
22
22
  }
@@ -1,4 +1,5 @@
1
- import _ from "lodash";
1
+ import { camelCase } from "es-toolkit";
2
+ import { forEach } from "es-toolkit/compat";
2
3
  import { Logger, type OnLog } from "./Logger";
3
4
  import { Level } from "./shared";
4
5
 
@@ -30,7 +31,7 @@ export function createLogger<Name extends string>(config: Config<Name>) {
30
31
  }
31
32
  // 输入:foo.login
32
33
  // 输出:fooLogin
33
- const key = (name.includes(".") ? _.camelCase(name) : name) as Key;
34
+ const key = (name.includes(".") ? camelCase(name) : name) as Key;
34
35
 
35
36
  if (loggerMap[key]) {
36
37
  throw new Error(`logger name "${name}" is duplicated`);
@@ -47,17 +48,17 @@ export function createLogger<Name extends string>(config: Config<Name>) {
47
48
 
48
49
  const method = {
49
50
  enable() {
50
- _.forEach(loggerMap, (v) => {
51
+ forEach(loggerMap, (v) => {
51
52
  v.enable();
52
53
  });
53
54
  },
54
55
  disable() {
55
- _.forEach(loggerMap, (v) => {
56
+ forEach(loggerMap, (v) => {
56
57
  v.disable();
57
58
  });
58
59
  },
59
60
  setLevel(level: Level) {
60
- _.forEach(loggerMap, (v) => {
61
+ forEach(loggerMap, (v) => {
61
62
  v.setLevel(level);
62
63
  });
63
64
  },
@@ -1,6 +1,5 @@
1
1
  import type { QueryClient } from "@tanstack/react-query";
2
2
 
3
- import { queryClient } from "./defaultQueryClient";
4
3
  import type { Basic, RequestBuilderOptions, RequestConfig } from "./options";
5
4
 
6
5
  export class RequestBuilder<Req = any, Res = any> {
@@ -19,7 +18,7 @@ export class RequestBuilder<Req = any, Res = any> {
19
18
  //#endregion
20
19
 
21
20
  // 这是默认的 Query Client 实例
22
- static queryClient: QueryClient | null = queryClient;
21
+ static queryClient: QueryClient | null = null;
23
22
  static setQueryClient(queryClient: QueryClient | null) {
24
23
  RequestBuilder.queryClient = queryClient;
25
24
  }
@@ -1,4 +1,5 @@
1
- import _ from "lodash";
1
+ import { isEqual } from "es-toolkit";
2
+
2
3
  import { useSyncExternalStore } from "react";
3
4
  import type { StoreType } from "store2";
4
5
  import baseStore from "store2";
@@ -52,7 +53,7 @@ class StorageHelper<V = any> {
52
53
 
53
54
  get(): V | undefined {
54
55
  const r = this.store.get(this.baseKey) ?? this.defaultValue;
55
- if (!_.isEqual(r, this.currentValue)) {
56
+ if (!isEqual(r, this.currentValue)) {
56
57
  this.currentValue = r;
57
58
  }
58
59
  return this.currentValue;
@@ -62,7 +63,7 @@ class StorageHelper<V = any> {
62
63
  * 设置为 undefined 时,会删除该 key
63
64
  */
64
65
  set(v: V | undefined): void {
65
- if (_.isEqual(v, this.currentValue)) {
66
+ if (isEqual(v, this.currentValue)) {
66
67
  return;
67
68
  }
68
69
  this.currentValue = v;
@@ -1,4 +1,4 @@
1
- import _ from "lodash";
1
+ import { isEqual } from "es-toolkit";
2
2
  import { useDebugValue, useRef, useSyncExternalStore } from "react";
3
3
  import { proxy, snapshot, subscribe, useSnapshot } from "valtio";
4
4
 
@@ -69,7 +69,7 @@ export function createStore<
69
69
  const prev = useRef<T>(undefined);
70
70
  const combinedSelector = (state: S) => {
71
71
  const next = selector(state);
72
- if (!_.isEqual(prev.current, next)) {
72
+ if (!isEqual(prev.current, next)) {
73
73
  prev.current = next;
74
74
  }
75
75
  return prev.current;
@@ -1,31 +0,0 @@
1
- import NiceModal from "@ebay/nice-modal-react";
2
- import _ from "lodash";
3
- import { niceModalStore } from "./niceModalStore";
4
-
5
- export const createModal = <P extends object, Res = unknown>(
6
- Comp: React.ComponentType<P>,
7
- ) => {
8
- const customModal = NiceModal.create(Comp);
9
-
10
- const modalId: string = _.uniqueId("niceModal_");
11
-
12
- NiceModal.register(modalId, customModal);
13
- return Object.assign(customModal, {
14
- async show(props?: P): Promise<Res> {
15
- await niceModalStore.actions.initModal(modalId);
16
- return NiceModal.show(modalId, props);
17
- },
18
- hide() {
19
- return NiceModal.hide(modalId);
20
- },
21
- remove() {
22
- return NiceModal.remove(modalId);
23
- },
24
- /**
25
- * 获取当前弹框是否打开
26
- */
27
- getVisible() {
28
- return !!niceModalStore.getState().modals[modalId]?.visible;
29
- },
30
- });
31
- };
@@ -1,32 +0,0 @@
1
- import { Provider } from "@ebay/nice-modal-react";
2
- import type { PropsWithChildren } from "react";
3
- import { niceModalStore } from "./niceModalStore";
4
-
5
- export {
6
- antdDrawer,
7
- antdDrawerV5,
8
- antdModal,
9
- antdModalV5,
10
- bootstrapDialog,
11
- muiDialog,
12
- muiDialogV5,
13
- useModal,
14
- } from "@ebay/nice-modal-react";
15
- export { createModal } from "./createModal";
16
- export {
17
- /**
18
- * 一般情况下不需要使用这个,这里导出主要是给 storybook 使用,防止弹出多个 modal
19
- */
20
- Provider as BaseNiceModalProvider,
21
- niceModalStore,
22
- };
23
-
24
- export function NiceModalProvider(props: PropsWithChildren) {
25
- const { modals } = niceModalStore.useSnapshot();
26
-
27
- return (
28
- <Provider dispatch={niceModalStore.actions.dispatch} modals={modals}>
29
- {props.children}
30
- </Provider>
31
- );
32
- }
@@ -1,40 +0,0 @@
1
- import {
2
- reducer,
3
- type NiceModalAction,
4
- type NiceModalStore,
5
- } from "@ebay/nice-modal-react";
6
- import { createStore } from "../store";
7
-
8
- export const niceModalStore = createStore({
9
- name: "niceModalStore",
10
- state: {
11
- modals: {} as NiceModalStore,
12
- },
13
- actionsCreator: (state) => {
14
- return {
15
- dispatch(action: NiceModalAction) {
16
- state.modals = reducer(state.modals, action);
17
- },
18
- /**
19
- * 为了让 modal 第一次打开的时候过渡动画存在
20
- * 目前主要是兼容 mantine ui,它们使用的是 css 动画
21
- * 要确保 dom 存在
22
- */
23
- async initModal(id: string) {
24
- if (state.modals[id]) {
25
- return;
26
- }
27
- state.modals = {
28
- ...state.modals,
29
- [id]: {
30
- id,
31
- visible: false,
32
- delayVisible: false,
33
- },
34
- };
35
- // 确保下一帧调用,让 过渡动画有效果
36
- return Promise.resolve();
37
- },
38
- };
39
- },
40
- });