feffery_utils_components 0.2.0-rc26 → 0.2.0-rc27

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,6 +1,6 @@
1
1
  {
2
2
  "name": "feffery_utils_components",
3
- "version": "0.2.0-rc26",
3
+ "version": "0.2.0-rc27",
4
4
  "description": "Build more utility components for Plotly Dash.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "@js-preview/excel": "^1.6.0",
34
34
  "@microlink/react-json-view": "^1.23.4",
35
35
  "@photo-sphere-viewer/autorotate-plugin": "^5.7.3",
36
- "@reactuses/core": "^5.0.23",
36
+ "@reactuses/core": "^6.0.0",
37
37
  "@shoelace-style/shoelace": "^2.14.0",
38
38
  "@uiw/color-convert": "^1.1.0",
39
39
  "@uiw/react-color-wheel": "^1.1.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feffery_utils_components",
3
- "version": "0.2.0-rc26",
3
+ "version": "0.2.0-rc27",
4
4
  "description": "Build more utility components for Plotly Dash.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,7 @@
33
33
  "@js-preview/excel": "^1.6.0",
34
34
  "@microlink/react-json-view": "^1.23.4",
35
35
  "@photo-sphere-viewer/autorotate-plugin": "^5.7.3",
36
- "@reactuses/core": "^5.0.23",
36
+ "@reactuses/core": "^6.0.0",
37
37
  "@shoelace-style/shoelace": "^2.14.0",
38
38
  "@uiw/color-convert": "^1.1.0",
39
39
  "@uiw/react-color-wheel": "^1.1.0",
@@ -28,7 +28,8 @@ const FefferyPostEventSource = (props) => {
28
28
  headers,
29
29
  body,
30
30
  withCredentials,
31
- method: 'POST'
31
+ method: 'POST',
32
+ openWhenHidden: true
32
33
  }
33
34
  );
34
35
 
@@ -358,6 +358,19 @@ const FefferyDiv = (props) => {
358
358
  () => setProps({ isTouching: false }) :
359
359
  undefined
360
360
  }
361
+ // 监听容器内文本粘贴事件
362
+ onPaste={
363
+ enableEvents?.includes('paste') ?
364
+ (e) => {
365
+ setProps({
366
+ pasteEvent: {
367
+ text: e.clipboardData.getData('text'),
368
+ timestamp: Date.now()
369
+ }
370
+ })
371
+ } :
372
+ undefined
373
+ }
361
374
  tabIndex={enableFocus || enableEvents?.includes('focus') ? 0 : undefined}
362
375
  data-dash-is-loading={
363
376
  (loading_state && loading_state.is_loading) || undefined
@@ -399,7 +412,7 @@ FefferyDiv.propTypes = {
399
412
  * 控制要开启的事件监听类型数组,可选项有`'click'`(单击事件)、`'dbclick'`(双击事件)、`'size'`(尺寸变化事件)、
400
413
  * `'mouseenter'`(鼠标移入事件),`'mouseleave'`(鼠标移出事件)、`'contextmenu'`(鼠标右键点击事件)、
401
414
  * `'hover'`(鼠标悬停事件)、`'touch'`(移动端触碰事件)、`'clickaway'`(元素外点击事件)、`'position'`(左上角坐标位置变化事件)、
402
- * `'focus'`(聚焦状态切换事件)
415
+ * `'focus'`(聚焦状态切换事件)、`'paste'`(文本粘贴事件)
403
416
  * 默认值:`['click', 'dbclick']`
404
417
  */
405
418
  enableEvents: PropTypes.arrayOf(
@@ -414,7 +427,8 @@ FefferyDiv.propTypes = {
414
427
  'touch',
415
428
  'clickaway',
416
429
  'position',
417
- 'focus'
430
+ 'focus',
431
+ 'paste'
418
432
  ])
419
433
  ),
420
434
 
@@ -613,6 +627,20 @@ FefferyDiv.propTypes = {
613
627
  */
614
628
  isFocused: PropTypes.bool,
615
629
 
630
+ /**
631
+ * 监听文本粘贴事件
632
+ */
633
+ pasteEvent: PropTypes.exact({
634
+ /**
635
+ * 已粘贴文本内容
636
+ */
637
+ text: PropTypes.string,
638
+ /**
639
+ * 粘贴事件对应的时间戳
640
+ */
641
+ timestamp: PropTypes.number
642
+ }),
643
+
616
644
  /**
617
645
  * 设置当前组件内部处理鼠标滑轮事件的策略,可选项有`'default'`、`'internally-only'`(不向外传递)
618
646
  * 默认值:`'default'
@@ -0,0 +1,78 @@
1
+ import { useEffect } from 'react';
2
+ import { useWebNotification } from '@reactuses/core';
3
+ import PropTypes from 'prop-types';
4
+
5
+ /**
6
+ * web通知组件FefferyWebNotification
7
+ */
8
+ const FefferyWebNotification = (props) => {
9
+ const {
10
+ message,
11
+ setProps,
12
+ loading_state
13
+ } = props;
14
+
15
+ const { isSupported: _isSupported, show } = useWebNotification(true);
16
+
17
+ useEffect(() => {
18
+ setProps({ isSupported: _isSupported })
19
+ }, [_isSupported])
20
+
21
+ useEffect(() => {
22
+ if (_isSupported && message) {
23
+ show(message);
24
+ // 重置message
25
+ setProps({ message: null });
26
+ }
27
+ }, [message])
28
+
29
+ return <></>;
30
+ }
31
+
32
+ FefferyWebNotification.propTypes = {
33
+ /**
34
+ * 组件唯一id
35
+ */
36
+ id: PropTypes.string,
37
+
38
+ /**
39
+ * 对当前组件的`key`值进行更新,可实现强制重绘当前组件的效果
40
+ */
41
+ key: PropTypes.string,
42
+
43
+ /**
44
+ * 设置要发送的信息内容,每次成功发送后都会重置为空
45
+ */
46
+ message: PropTypes.string,
47
+
48
+ /**
49
+ * 监听用户浏览器中是否支持web通知
50
+ */
51
+ isSupported: PropTypes.bool,
52
+
53
+ /**
54
+ * Dash-assigned callback that should be called to report property changes
55
+ * to Dash, to make them available for callbacks.
56
+ */
57
+ setProps: PropTypes.func,
58
+
59
+ loading_state: PropTypes.shape({
60
+ /**
61
+ * Determines if the component is loading or not
62
+ */
63
+ is_loading: PropTypes.bool,
64
+ /**
65
+ * Holds which property is loading
66
+ */
67
+ prop_name: PropTypes.string,
68
+ /**
69
+ * Holds the name of the component that is loading
70
+ */
71
+ component_name: PropTypes.string
72
+ })
73
+ };
74
+
75
+ FefferyWebNotification.defaultProps = {
76
+ }
77
+
78
+ export default FefferyWebNotification;
package/src/lib/index.js CHANGED
@@ -131,6 +131,7 @@ import FefferySeamlessScroll from "./components/dataDisplay/FefferySeamlessScrol
131
131
  // 反馈
132
132
  import FefferyFancyMessage from "./components/feedback/FefferyFancyMessage.js";
133
133
  import FefferyFancyNotification from "./components/feedback/FefferyFancyNotification.js";
134
+ import FefferyWebNotification from './components/feedback/FefferyWebNotification.react.js';
134
135
  // 存储
135
136
  import FefferyCookie from "./components/store/FefferyCookie.react";
136
137
  import FefferyLocalLargeStorage from "./components/store/FefferyLocalLargeStorage.react";
@@ -302,6 +303,7 @@ export {
302
303
  // 反馈
303
304
  FefferyFancyMessage,
304
305
  FefferyFancyNotification,
306
+ FefferyWebNotification,
305
307
  // 存储
306
308
  FefferyCookie,
307
309
  FefferyLocalLargeStorage,
@@ -0,0 +1,38 @@
1
+ if True:
2
+ import sys
3
+
4
+ sys.path.append('../../')
5
+ import dash
6
+ from dash import html
7
+ import feffery_utils_components as fuc
8
+ from dash.dependencies import Input, Output
9
+ from feffery_dash_utils.style_utils import style
10
+
11
+ app = dash.Dash(__name__)
12
+
13
+ app.layout = html.Div(
14
+ [
15
+ fuc.FefferyDiv(
16
+ id='div-demo',
17
+ enableEvents=['paste'],
18
+ style=style(
19
+ height=200,
20
+ border='1px solid #d9d9d9',
21
+ ),
22
+ )
23
+ ],
24
+ style=style(padding=100),
25
+ )
26
+
27
+
28
+ @app.callback(
29
+ Output('div-demo', 'children'),
30
+ Input('div-demo', 'pasteEvent'),
31
+ prevent_initial_call=True,
32
+ )
33
+ def demo(pasteEvent):
34
+ return pasteEvent.get('text')
35
+
36
+
37
+ if __name__ == '__main__':
38
+ app.run(debug=True)
@@ -0,0 +1,22 @@
1
+ if True:
2
+ import sys
3
+
4
+ sys.path.append('../../')
5
+ import dash
6
+ from dash import html
7
+ import feffery_utils_components as fuc
8
+ from feffery_dash_utils.style_utils import style
9
+
10
+ app = dash.Dash(__name__)
11
+
12
+ app.layout = html.Div(
13
+ [
14
+ fuc.FefferyPostEventSource(
15
+ url='https://broad-scene-1112.ploomberapp.io/stream-post',
16
+ )
17
+ ],
18
+ style=style(padding=100),
19
+ )
20
+
21
+ if __name__ == '__main__':
22
+ app.run(debug=True)
@@ -0,0 +1,35 @@
1
+ if True:
2
+ import sys
3
+
4
+ sys.path.append('../../')
5
+ import uuid
6
+ import dash
7
+ from dash import html
8
+ import feffery_utils_components as fuc
9
+ from dash.dependencies import Input, Output
10
+ from feffery_dash_utils.style_utils import style
11
+
12
+ app = dash.Dash(__name__)
13
+
14
+ app.layout = html.Div(
15
+ [
16
+ html.Button('新的通知', id='new-web-notification'),
17
+ fuc.FefferyWebNotification(
18
+ id='web-notification-demo',
19
+ ),
20
+ ],
21
+ style=style(padding=100),
22
+ )
23
+
24
+
25
+ @app.callback(
26
+ Output('web-notification-demo', 'message'),
27
+ Input('new-web-notification', 'n_clicks'),
28
+ prevent_initial_call=True,
29
+ )
30
+ def demo(n_clicks):
31
+ return '通知测试' + str(uuid.uuid4())
32
+
33
+
34
+ if __name__ == '__main__':
35
+ app.run(debug=True)