feffery_utils_components 0.0.20 → 0.0.22

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.
Files changed (45) hide show
  1. package/DESCRIPTION +1 -1
  2. package/NAMESPACE +3 -0
  3. package/Project.toml +1 -1
  4. package/build/lib/feffery_utils_components/FefferyCaptcha.py +5 -3
  5. package/build/lib/feffery_utils_components/FefferyDiv.py +9 -5
  6. package/build/lib/feffery_utils_components/FefferyDocumentVisibility.py +46 -0
  7. package/{feffery_utils_components/FefferySliderColorPicker.py → build/lib/feffery_utils_components/FefferyExternalCss.py} +9 -11
  8. package/build/lib/feffery_utils_components/FefferyGeolocation.py +46 -0
  9. package/build/lib/feffery_utils_components/FefferyIdle.py +48 -0
  10. package/build/lib/feffery_utils_components/FefferyKeyPress.py +48 -0
  11. package/build/lib/feffery_utils_components/FefferyResponsive.py +46 -0
  12. package/build/lib/feffery_utils_components/FefferySetTitle.py +46 -0
  13. package/build/lib/feffery_utils_components/FefferyTimeout.py +48 -0
  14. package/build/lib/feffery_utils_components/FefferyWindowSize.py +48 -0
  15. package/build/lib/feffery_utils_components/_imports_.py +18 -0
  16. package/build/lib/feffery_utils_components/feffery_utils_components.min.js +1 -1
  17. package/build/lib/feffery_utils_components/metadata.json +582 -10
  18. package/build/lib/feffery_utils_components/package-info.json +2 -1
  19. package/feffery_utils_components/FefferyCaptcha.py +5 -3
  20. package/feffery_utils_components/FefferyCountDown.py +50 -0
  21. package/feffery_utils_components/FefferyDiv.py +7 -5
  22. package/feffery_utils_components/FefferyKeyPress.py +48 -0
  23. package/feffery_utils_components/FefferyTimeout.py +48 -0
  24. package/feffery_utils_components/_imports_.py +6 -0
  25. package/feffery_utils_components/feffery_utils_components.min.js +1 -1
  26. package/feffery_utils_components/metadata.json +216 -2
  27. package/feffery_utils_components/package-info.json +1 -1
  28. package/package.json +1 -1
  29. package/src/FefferyUtilsComponents.jl +6 -3
  30. package/src/jl/''_fefferycaptcha.jl +2 -1
  31. package/src/jl/''_fefferycountdown.jl +26 -0
  32. package/src/jl/''_fefferydiv.jl +4 -3
  33. package/src/jl/''_fefferykeypress.jl +25 -0
  34. package/src/jl/''_fefferytimeout.jl +25 -0
  35. package/src/lib/components/FefferyCaptcha.react.js +14 -2
  36. package/src/lib/components/FefferyCountDown.react.js +92 -0
  37. package/src/lib/components/FefferyTimeout.react.js +68 -0
  38. package/src/lib/components/listeners/FefferyDiv.react.js +20 -11
  39. package/src/lib/components/listeners/FefferyKeyPress.react.js +69 -0
  40. package/src/lib/index.js +7 -1
  41. package/tests/FefferyCaptchaRefreshRef/app.py +49 -0
  42. package/tests/FefferyClickAwayTest/app.py +41 -0
  43. package/tests/FefferyCountDownTest/app.py +53 -0
  44. package/tests/FefferyKeyPressTest/app.py +43 -0
  45. package/tests/FefferyTimeoutTest/app.py +63 -0
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect, useRef } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { useSize, useRequest, useHover } from 'ahooks';
3
+ import { useSize, useRequest, useHover, useClickAway } from 'ahooks';
4
4
 
5
5
  // 定义进阶div容器组件FefferyDiv
6
6
  const FefferyDiv = (props) => {
@@ -10,12 +10,13 @@ const FefferyDiv = (props) => {
10
10
  children,
11
11
  style,
12
12
  className,
13
- mouseEnterCounts,
14
- mouseLeaveCounts,
13
+ mouseEnterCount,
14
+ mouseLeaveCount,
15
15
  nClicks,
16
16
  nDoubleClicks,
17
17
  enableListenContextMenu,
18
18
  debounceWait,
19
+ clickAwayCount,
19
20
  setProps,
20
21
  loading_state
21
22
  } = props;
@@ -37,7 +38,6 @@ const FefferyDiv = (props) => {
37
38
  },
38
39
  {
39
40
  debounceWait: debounceWait,
40
- debounceLeading: true,
41
41
  manual: true
42
42
  }
43
43
  )
@@ -54,6 +54,11 @@ const FefferyDiv = (props) => {
54
54
  })
55
55
  }, [_isHovering])
56
56
 
57
+ // 监听元素外点击事件
58
+ useClickAway(() => {
59
+ setProps({ clickAwayCount: clickAwayCount + 1 })
60
+ }, ref);
61
+
57
62
  return <div
58
63
  id={id}
59
64
  style={style}
@@ -73,8 +78,8 @@ const FefferyDiv = (props) => {
73
78
  })
74
79
  }
75
80
  }}
76
- onMouseEnter={() => setProps({ mouseEnterCounts: mouseEnterCounts + 1 })}
77
- onMouseLeave={() => setProps({ mouseLeaveCounts: mouseLeaveCounts + 1 })}
81
+ onMouseEnter={() => setProps({ mouseEnterCount: mouseEnterCount + 1 })}
82
+ onMouseLeave={() => setProps({ mouseLeaveCount: mouseLeaveCount + 1 })}
78
83
  data-dash-is-loading={
79
84
  (loading_state && loading_state.is_loading) || undefined
80
85
  } >
@@ -104,10 +109,10 @@ FefferyDiv.propTypes = {
104
109
  debounceWait: PropTypes.number,
105
110
 
106
111
  // 监听鼠标移入事件次数,初始化为0
107
- mouseEnterCounts: PropTypes.number,
112
+ mouseEnterCount: PropTypes.number,
108
113
 
109
114
  // 监听鼠标移出事件次数,初始化为0
110
- mouseLeaveCounts: PropTypes.number,
115
+ mouseLeaveCount: PropTypes.number,
111
116
 
112
117
  // 监听单击事件次数,初始化为0
113
118
  nClicks: PropTypes.number,
@@ -132,6 +137,9 @@ FefferyDiv.propTypes = {
132
137
  // 监听当前元素是否被鼠标悬浮
133
138
  isHovering: PropTypes.bool,
134
139
 
140
+ // 监听元素外点击事件发生次数,默认为0
141
+ clickAwayCount: PropTypes.number,
142
+
135
143
  /**
136
144
  * Dash-assigned callback that should be called to report property changes
137
145
  * to Dash, to make them available for callbacks.
@@ -156,12 +164,13 @@ FefferyDiv.propTypes = {
156
164
 
157
165
  // 设置默认参数
158
166
  FefferyDiv.defaultProps = {
159
- mouseEnterCounts: 0,
160
- mouseLeaveCounts: 0,
167
+ mouseEnterCount: 0,
168
+ mouseLeaveCount: 0,
161
169
  nClicks: 0,
162
170
  nDoubleClicks: 0,
163
171
  enableListenContextMenu: false,
164
- debounceWait: 150
172
+ debounceWait: 150,
173
+ clickAwayCount: 0
165
174
  }
166
175
 
167
176
  export default FefferyDiv;
@@ -0,0 +1,69 @@
1
+ import { useKeyPress } from 'ahooks';
2
+ import PropTypes from 'prop-types';
3
+
4
+ // 定义按键事件监听组件FefferyKeyPress
5
+ const FefferyKeyPress = (props) => {
6
+
7
+ const {
8
+ id,
9
+ keys,
10
+ pressedTimes,
11
+ setProps,
12
+ loading_state
13
+ } = props;
14
+
15
+ useKeyPress(
16
+ keys,
17
+ () => {
18
+ setProps({
19
+ pressedTimes: pressedTimes + 1
20
+ })
21
+ }
22
+ );
23
+
24
+ return (<div
25
+ id={id}
26
+ data-dash-is-loading={
27
+ (loading_state && loading_state.is_loading) || undefined
28
+ } />);
29
+ }
30
+
31
+ // 定义参数或属性
32
+ FefferyKeyPress.propTypes = {
33
+ // 部件id
34
+ id: PropTypes.string,
35
+
36
+ // 用于设置要监听的按键组合,必填
37
+ keys: PropTypes.string.isRequired,
38
+
39
+ // 记录设置的按键或按键组合事件已被触发的次数,默认为0
40
+ pressedTimes: PropTypes.number,
41
+
42
+ /**
43
+ * Dash-assigned callback that should be called to report property changes
44
+ * to Dash, to make them available for callbacks.
45
+ */
46
+ setProps: PropTypes.func,
47
+
48
+ loading_state: PropTypes.shape({
49
+ /**
50
+ * Determines if the component is loading or not
51
+ */
52
+ is_loading: PropTypes.bool,
53
+ /**
54
+ * Holds which property is loading
55
+ */
56
+ prop_name: PropTypes.string,
57
+ /**
58
+ * Holds the name of the component that is loading
59
+ */
60
+ component_name: PropTypes.string
61
+ })
62
+ };
63
+
64
+ // 设置默认参数
65
+ FefferyKeyPress.defaultProps = {
66
+ pressedTimes: 0
67
+ }
68
+
69
+ export default React.memo(FefferyKeyPress);
package/src/lib/index.js CHANGED
@@ -30,6 +30,9 @@ import FefferyResponsive from "./components/listeners/FefferyResponsive.react";
30
30
  import FefferyGeolocation from "./components/listeners/FefferyGeolocation.react";
31
31
  import FefferyIdle from "./components/listeners/FefferyIdle.react";
32
32
  import FefferyWindowSize from "./components/listeners/FefferyWindowSize.react";
33
+ import FefferyKeyPress from "./components/listeners/FefferyKeyPress.react";
34
+ import FefferyTimeout from "./components/FefferyTimeout.react";
35
+ import FefferyCountDown from "./components/FefferyCountDown.react";
33
36
 
34
37
  /*
35
38
  忽略部分设计React中规范的console警告信息
@@ -84,5 +87,8 @@ export {
84
87
  FefferyResponsive,
85
88
  FefferyGeolocation,
86
89
  FefferyIdle,
87
- FefferyWindowSize
90
+ FefferyWindowSize,
91
+ FefferyKeyPress,
92
+ FefferyTimeout,
93
+ FefferyCountDown
88
94
  };
@@ -0,0 +1,49 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ html.Button(
16
+ '刷新',
17
+ id='refresh-demo'
18
+ ),
19
+ fuc.FefferyCaptcha(
20
+ id='captcha-demo'
21
+ ),
22
+ html.Div(id='current-captcha')
23
+ ],
24
+ style={
25
+ 'height': '2000px'
26
+ }
27
+ )
28
+
29
+
30
+ @app.callback(
31
+ Output('captcha-demo', 'refresh'),
32
+ Input('refresh-demo', 'n_clicks')
33
+ )
34
+ def demo1(n_clicks):
35
+
36
+ return bool(n_clicks)
37
+
38
+
39
+ @app.callback(
40
+ Output('current-captcha', 'children'),
41
+ Input('captcha-demo', 'captcha')
42
+ )
43
+ def demo2(captcha):
44
+
45
+ return captcha
46
+
47
+
48
+ if __name__ == '__main__':
49
+ app.run(debug=True)
@@ -0,0 +1,41 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ fuc.FefferyDiv(
16
+ id='div-demo',
17
+ style={
18
+ 'width': '200px',
19
+ 'height': '100px',
20
+ 'background': 'lightgrey',
21
+ 'border': '1ox dashed black'
22
+ }
23
+ )
24
+ ],
25
+ style={
26
+ 'height': '2000px'
27
+ }
28
+ )
29
+
30
+
31
+ @app.callback(
32
+ Output('div-demo', 'children'),
33
+ Input('div-demo', 'clickAwayCount')
34
+ )
35
+ def demo(clickAwayCount):
36
+
37
+ return clickAwayCount
38
+
39
+
40
+ if __name__ == '__main__':
41
+ app.run(debug=True)
@@ -0,0 +1,53 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ fuc.FefferyCountDown(
16
+ id='count-down-demo',
17
+ interval=2
18
+ ),
19
+ html.Button(
20
+ '设置10秒倒计时',
21
+ id='set-10s-count-down'
22
+ ),
23
+ html.Div(id='count-down-output')
24
+ ],
25
+ style={
26
+ 'height': '2000px'
27
+ }
28
+ )
29
+
30
+
31
+ @app.callback(
32
+ Output('count-down-demo', 'delay'),
33
+ Input('set-10s-count-down', 'n_clicks')
34
+ )
35
+ def demo1(n_clicks):
36
+
37
+ if n_clicks:
38
+ return 10
39
+
40
+
41
+ @app.callback(
42
+ Output('count-down-output', 'children'),
43
+ Input('count-down-demo', 'countdown')
44
+ )
45
+ def demo2(countdown):
46
+
47
+ print(countdown)
48
+
49
+ return countdown
50
+
51
+
52
+ if __name__ == '__main__':
53
+ app.run(debug=True)
@@ -0,0 +1,43 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ '请按i键',
16
+
17
+ fuc.FefferyKeyPress(
18
+ id='key-press-demo',
19
+ keys='i'
20
+ ),
21
+
22
+ html.Div(
23
+ '',
24
+ id='output'
25
+ )
26
+ ],
27
+ style={
28
+ 'height': '2000px'
29
+ }
30
+ )
31
+
32
+
33
+ app.clientside_callback(
34
+ '''(pressedTimes, children) => {
35
+ return `${children}❤️`
36
+ }''',
37
+ Output('output', 'children'),
38
+ Input('key-press-demo', 'pressedTimes'),
39
+ State('output', 'children'),
40
+ prevent_initial_call=True
41
+ )
42
+ if __name__ == '__main__':
43
+ app.run(debug=True)
@@ -0,0 +1,63 @@
1
+ if True:
2
+ import sys
3
+ import time
4
+ sys.path.append('../..')
5
+ import dash
6
+ from dash import html, dcc
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output, State
9
+
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ html.Div(
16
+ [
17
+ dcc.Input(
18
+ id='delay',
19
+ value=3000,
20
+ style={
21
+ 'width': '200px'
22
+ }
23
+ ),
24
+ html.Button(
25
+ '执行',
26
+ id='button'
27
+ )
28
+ ]
29
+ ),
30
+ fuc.FefferyTimeout(id='timeout', delay=5000),
31
+ html.Div(id='timeout-result')
32
+ ],
33
+ style={
34
+ 'height': '2000px'
35
+ }
36
+ )
37
+
38
+
39
+ @app.callback(
40
+ Output('timeout', 'delay'),
41
+ Input('button', 'n_clicks'),
42
+ State('delay', 'value')
43
+ )
44
+ def demo1(n_clicks, delay):
45
+
46
+ if delay:
47
+ print(int(delay))
48
+ return int(delay)
49
+
50
+
51
+ @app.callback(
52
+ Output('timeout-result', 'children'),
53
+ Input('timeout', 'timeoutCount')
54
+ )
55
+ def demo2(timeoutCount):
56
+
57
+ print(timeoutCount)
58
+
59
+ return timeoutCount
60
+
61
+
62
+ if __name__ == '__main__':
63
+ app.run(debug=True)