litten-hooks 1.1.0 → 1.2.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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ![GitHub Repo stars](https://img.shields.io/github/stars/liuxian496/litten-hooks)
6
6
 
7
7
 
8
- <p>litten-hooks是一个基于react的工具库,提供开发「用户组件库」时需要的hooks</p>
8
+ <p>litten-hooks是一个基于react的工具库,提供开发「控件库」时需要的hooks</p>
9
9
 
10
10
  <p>
11
11
  主页
@@ -13,6 +13,12 @@
13
13
 
14
14
  [https://liuxian496.github.io/litten-hooks/](https://liuxian496.github.io/litten-hooks/)
15
15
 
16
+ ## 依赖
17
+ <code>react</code>
18
+ <code>react-dom</code>
19
+ <code>loadsh</code>
20
+ 上述依赖,打包时不包含,需要使用的项目自行引入。
21
+
16
22
  ## 如果你想请我喝一咖啡(Buy Me a Coffee)
17
23
  <img src=".\\public\\wechat.jpg" height="360">
18
24
  <img src=".\\public\\alipay.jpg" height="360">
@@ -0,0 +1,20 @@
1
+ import { useState as i } from "react";
2
+ import l from "lodash/isFunction";
3
+ import { FocusState as n } from "../enum.js";
4
+ function p(e) {
5
+ const { onFocus: t, onBlur: u, onLabelMouseStateCheck: r } = e, [c, o] = i(!1);
6
+ function f(s) {
7
+ l(r) && r(), o(!0), t == null || t(s);
8
+ }
9
+ function a(s) {
10
+ o(!1), u == null || u(s);
11
+ }
12
+ return [c, f, a];
13
+ }
14
+ function S(e) {
15
+ return e === !0 ? n.focus : n.blur;
16
+ }
17
+ export {
18
+ S as g,
19
+ p as u
20
+ };
@@ -0,0 +1,36 @@
1
+ import { useState as d, useEffect as a } from "react";
2
+ import { u as v } from "./usePrevious.VSe_Wq1g.js";
3
+ function l(u, i) {
4
+ const [e, s] = d({
5
+ left: 0,
6
+ right: 0,
7
+ top: 0,
8
+ bottom: 0,
9
+ targetWidth: 0,
10
+ targetHeight: 0
11
+ }), m = v(e);
12
+ a(() => {
13
+ m !== e && e.targetWidth > 0 && i && i(e);
14
+ });
15
+ function c() {
16
+ document.addEventListener("mousedown", o), document.addEventListener("mousemove", o), document.addEventListener("mouseup", r);
17
+ }
18
+ function o(n) {
19
+ let t;
20
+ u.current && (t = u.current.getBoundingClientRect()), t && s({
21
+ left: n.clientX - t.left,
22
+ right: n.clientX - t.right,
23
+ top: n.clientY - t.top,
24
+ bottom: n.clientY - t.bottom,
25
+ targetWidth: t.width,
26
+ targetHeight: t.height
27
+ });
28
+ }
29
+ function r() {
30
+ document.removeEventListener("mousedown", o), document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", r);
31
+ }
32
+ return [c];
33
+ }
34
+ export {
35
+ l as u
36
+ };
@@ -16,4 +16,5 @@ export interface FocusControlProps<T> extends UserControlProps {
16
16
  * @returns void
17
17
  */
18
18
  onBlur?: (e: FocusEvent<T>) => void;
19
+ onLabelMouseStateCheck?: () => boolean;
19
20
  }
@@ -1,17 +1,6 @@
1
1
  import { MutableRefObject } from 'react';
2
- import { MouseState } from '../../global/enum';
3
2
  import { RelativeRect } from './userControl.types';
4
3
 
5
- /**
6
- * 获取littenLabelMouseState
7
- * @returns
8
- */
9
- export declare function getLabelMouseState(): MouseState;
10
- /**
11
- * 设置littenLabelMouseState
12
- * @param state 待设置的MouseState {MouseState}
13
- */
14
- export declare function setLabelMouseState(state: MouseState): void;
15
4
  /**
16
5
  * 鼠标按下时,获取鼠标相对于指定的DOM节点的相对位置
17
6
  * @param ref DOM节点的ref
@@ -1,4 +1,4 @@
1
- import { g as o, u as t } from "./chunks/focusControl.CRsuxRz-.js";
1
+ import { g as o, u as t } from "./chunks/focusControl.DFx-5f45.js";
2
2
  export {
3
3
  o as getStateByFocused,
4
4
  t as useFocused
package/dist/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export { setCheckedByGroupValue, useCurrentChecked, } from '../src/control/check
3
3
  export { getCurrentValue, getDefaultValueByDisplayName, useCurrentValue, } from '../src/control/contentControl/contentControl';
4
4
  export { useDisabled } from '../src/control/disabledControl/disabledControl';
5
5
  export { getStateByFocused, useFocused, } from '../src/control/focusControl/focusControl';
6
- export { getLabelMouseState, setLabelMouseState, useRelativePosition, } from '../src/control/userControl/userControl';
6
+ export { useRelativePosition } from '../src/control/userControl/userControl';
7
7
  export { usePrevious } from '../src/hooks/usePrevious';
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ChangeEventState as a, CheckState as s, ControlType as u, EnableState as o, FocusState as r, MouseState as l, Orientation as p, Placement as n, Shape as i, TextFieldType as m } from "./enum.js";
2
- import { s as f, u as g } from "./chunks/checkedControl.BcxCIv6S.js";
3
- import { g as C, a as c, u as d } from "./chunks/contentControl.BDOf7ZM1.js";
2
+ import { s as x, u as C } from "./chunks/checkedControl.BcxCIv6S.js";
3
+ import { g as S, a as d, u as g } from "./chunks/contentControl.BDOf7ZM1.js";
4
4
  import { u as h } from "./chunks/disabledControl.SpguzRdp.js";
5
- import { g as F, u as V } from "./chunks/focusControl.CRsuxRz-.js";
6
- import { g as v, s as B, u as D } from "./chunks/userControl.BSXLnyVL.js";
5
+ import { g as V, u as k } from "./chunks/focusControl.DFx-5f45.js";
6
+ import { u as B } from "./chunks/userControl.BT9ukSvp.js";
7
7
  import { u as P } from "./chunks/usePrevious.VSe_Wq1g.js";
8
8
  export {
9
9
  a as ChangeEventState,
@@ -16,16 +16,14 @@ export {
16
16
  n as Placement,
17
17
  i as Shape,
18
18
  m as TextFieldType,
19
- C as getCurrentValue,
20
- c as getDefaultValueByDisplayName,
21
- v as getLabelMouseState,
22
- F as getStateByFocused,
23
- f as setCheckedByGroupValue,
24
- B as setLabelMouseState,
25
- g as useCurrentChecked,
26
- d as useCurrentValue,
19
+ S as getCurrentValue,
20
+ d as getDefaultValueByDisplayName,
21
+ V as getStateByFocused,
22
+ x as setCheckedByGroupValue,
23
+ C as useCurrentChecked,
24
+ g as useCurrentValue,
27
25
  h as useDisabled,
28
- V as useFocused,
26
+ k as useFocused,
29
27
  P as usePrevious,
30
- D as useRelativePosition
28
+ B as useRelativePosition
31
29
  };
@@ -1 +1 @@
1
- export { getLabelMouseState, setLabelMouseState, useRelativePosition, } from '../src/control/userControl/userControl';
1
+ export { useRelativePosition } from '../src/control/userControl/userControl';
@@ -1,6 +1,4 @@
1
- import { g as t, s as a, u as o } from "./chunks/userControl.BSXLnyVL.js";
1
+ import { u as i } from "./chunks/userControl.BT9ukSvp.js";
2
2
  export {
3
- t as getLabelMouseState,
4
- a as setLabelMouseState,
5
- o as useRelativePosition
3
+ i as useRelativePosition
6
4
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "litten-hooks",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -28,6 +28,12 @@
28
28
  "prepare": "husky"
29
29
  },
30
30
  "dependencies": {
31
+ "lodash": "^4.17.21",
32
+ "react": "^18.2.0",
33
+ "react-dom": "^18.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "lodash": "^4.17.21",
31
37
  "react": "^18.2.0",
32
38
  "react-dom": "^18.2.0"
33
39
  },
@@ -1,20 +0,0 @@
1
- import { useState as i } from "react";
2
- import { FocusState as a, MouseState as n } from "../enum.js";
3
- import { g as l, s as d } from "./userControl.BSXLnyVL.js";
4
- function p(e) {
5
- const { onFocus: t, onBlur: s } = e, [r, u] = i(!1);
6
- function c(o) {
7
- l() === n.none ? u(!0) : d(n.none), t == null || t(o);
8
- }
9
- function f(o) {
10
- u(!1), s == null || s(o);
11
- }
12
- return [r, c, f];
13
- }
14
- function F(e) {
15
- return e === !0 ? a.focus : a.blur;
16
- }
17
- export {
18
- F as g,
19
- p as u
20
- };
@@ -1,46 +0,0 @@
1
- import { useState as d, useEffect as l } from "react";
2
- import { MouseState as g } from "../enum.js";
3
- import { u as v } from "./usePrevious.VSe_Wq1g.js";
4
- let s = g.none;
5
- function L() {
6
- return s;
7
- }
8
- function M(e) {
9
- s = e;
10
- }
11
- function E(e, i) {
12
- const [o, m] = d({
13
- left: 0,
14
- right: 0,
15
- top: 0,
16
- bottom: 0,
17
- targetWidth: 0,
18
- targetHeight: 0
19
- }), c = v(o);
20
- l(() => {
21
- c !== o && o.targetWidth > 0 && i && i(o);
22
- });
23
- function a() {
24
- document.addEventListener("mousedown", n), document.addEventListener("mousemove", n), document.addEventListener("mouseup", r);
25
- }
26
- function n(u) {
27
- let t;
28
- e.current && (t = e.current.getBoundingClientRect()), t && m({
29
- left: u.clientX - t.left,
30
- right: u.clientX - t.right,
31
- top: u.clientY - t.top,
32
- bottom: u.clientY - t.bottom,
33
- targetWidth: t.width,
34
- targetHeight: t.height
35
- });
36
- }
37
- function r() {
38
- document.removeEventListener("mousedown", n), document.removeEventListener("mousemove", n), document.removeEventListener("mouseup", r);
39
- }
40
- return [a];
41
- }
42
- export {
43
- L as g,
44
- M as s,
45
- E as u
46
- };