feffery_utils_components 0.2.0-rc17 → 0.2.0-rc19
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/DESCRIPTION +1 -1
- package/NAMESPACE +1 -0
- package/Project.toml +1 -1
- package/README.md +1 -1
- package/feffery_utils_components/FefferyEventSource.py +82 -0
- package/feffery_utils_components/_imports_.py +2 -0
- package/feffery_utils_components/async-feffery_animated_3d_background_p5.js +1 -1
- package/feffery_utils_components/async-feffery_animated_3d_background_three.js +1 -1
- package/feffery_utils_components/async-feffery_animated_image.js +1 -1
- package/feffery_utils_components/async-feffery_aplayer.js +1 -1
- package/feffery_utils_components/async-feffery_auto_animate.js +1 -1
- package/feffery_utils_components/async-feffery_auto_fit.js +1 -1
- package/feffery_utils_components/async-feffery_burger.js +1 -1
- package/feffery_utils_components/async-feffery_captcha.js +1 -1
- package/feffery_utils_components/async-feffery_color_pickers.js +1 -1
- package/feffery_utils_components/async-feffery_dom2image.js +1 -1
- package/feffery_utils_components/async-feffery_dplayer.js +1 -1
- package/feffery_utils_components/async-feffery_emoji_picker.js +1 -1
- package/feffery_utils_components/async-feffery_excel_preview.js +1 -1
- package/feffery_utils_components/async-feffery_extra_spinner.js +1 -1
- package/feffery_utils_components/async-feffery_fancy_button.js +1 -1
- package/feffery_utils_components/async-feffery_grid.js +1 -1
- package/feffery_utils_components/async-feffery_http_requests.js +1 -1
- package/feffery_utils_components/async-feffery_image_cropper.js +1 -1
- package/feffery_utils_components/async-feffery_json_viewer.js +1 -1
- package/feffery_utils_components/async-feffery_local_large_storage.js +1 -1
- package/feffery_utils_components/async-feffery_markdown_editor.js +1 -1
- package/feffery_utils_components/async-feffery_motion.js +1 -1
- package/feffery_utils_components/async-feffery_music_player.js +1 -1
- package/feffery_utils_components/async-feffery_photo_sphere_viewer.js +1 -1
- package/feffery_utils_components/async-feffery_resizable.js +1 -1
- package/feffery_utils_components/async-feffery_rich_text_editor.js +1 -1
- package/feffery_utils_components/async-feffery_rnd.js +1 -1
- package/feffery_utils_components/async-feffery_seamless_scroll.js +1 -1
- package/feffery_utils_components/async-feffery_shortcut_panel.js +1 -1
- package/feffery_utils_components/async-feffery_slider_captcha.js +1 -1
- package/feffery_utils_components/async-feffery_sortable.js +1 -1
- package/feffery_utils_components/async-feffery_vditor.js +1 -1
- package/feffery_utils_components/async-feffery_word_preview.js +1 -1
- package/feffery_utils_components/feffery_utils_components.min.js +2 -2
- package/feffery_utils_components/metadata.json +153 -0
- package/feffery_utils_components/package-info.json +1 -1
- package/package.json +1 -1
- package/src/lib/components/FefferyCountUp.react.js +28 -5
- package/src/lib/components/FefferyEventSource.react.js +150 -0
- package/src/lib/index.js +3 -1
- package/usage.py +33 -28
|
@@ -11251,6 +11251,159 @@
|
|
|
11251
11251
|
}
|
|
11252
11252
|
}
|
|
11253
11253
|
},
|
|
11254
|
+
"src/lib/components/FefferyEventSource.react.js": {
|
|
11255
|
+
"description": "EventSource\u901a\u4fe1\u7ec4\u4ef6FefferyEventSource",
|
|
11256
|
+
"displayName": "FefferyEventSource",
|
|
11257
|
+
"methods": [],
|
|
11258
|
+
"props": {
|
|
11259
|
+
"id": {
|
|
11260
|
+
"type": {
|
|
11261
|
+
"name": "string"
|
|
11262
|
+
},
|
|
11263
|
+
"required": false,
|
|
11264
|
+
"description": "\u7ec4\u4ef6id"
|
|
11265
|
+
},
|
|
11266
|
+
"key": {
|
|
11267
|
+
"type": {
|
|
11268
|
+
"name": "string"
|
|
11269
|
+
},
|
|
11270
|
+
"required": false,
|
|
11271
|
+
"description": "\u5f3a\u5236\u5237\u65b0\u7528\u552f\u4e00\u6807\u8bc6key\u503c"
|
|
11272
|
+
},
|
|
11273
|
+
"url": {
|
|
11274
|
+
"type": {
|
|
11275
|
+
"name": "string"
|
|
11276
|
+
},
|
|
11277
|
+
"required": true,
|
|
11278
|
+
"description": "\u5fc5\u586b\uff0c\u76ee\u6807\u670d\u52a1\u5730\u5740"
|
|
11279
|
+
},
|
|
11280
|
+
"events": {
|
|
11281
|
+
"type": {
|
|
11282
|
+
"name": "arrayOf",
|
|
11283
|
+
"value": {
|
|
11284
|
+
"name": "string"
|
|
11285
|
+
}
|
|
11286
|
+
},
|
|
11287
|
+
"required": false,
|
|
11288
|
+
"description": "\u76ee\u6807\u4e8b\u4ef6\u540d\u79f0\u5217\u8868",
|
|
11289
|
+
"defaultValue": {
|
|
11290
|
+
"value": "[]",
|
|
11291
|
+
"computed": false
|
|
11292
|
+
}
|
|
11293
|
+
},
|
|
11294
|
+
"immediate": {
|
|
11295
|
+
"type": {
|
|
11296
|
+
"name": "bool"
|
|
11297
|
+
},
|
|
11298
|
+
"required": false,
|
|
11299
|
+
"description": "\u662f\u5426\u7acb\u5373\u5efa\u7acb\u8fde\u63a5\r\n\u9ed8\u8ba4\uff1a`true`",
|
|
11300
|
+
"defaultValue": {
|
|
11301
|
+
"value": "true",
|
|
11302
|
+
"computed": false
|
|
11303
|
+
}
|
|
11304
|
+
},
|
|
11305
|
+
"autoReconnect": {
|
|
11306
|
+
"type": {
|
|
11307
|
+
"name": "union",
|
|
11308
|
+
"value": [
|
|
11309
|
+
{
|
|
11310
|
+
"name": "shape",
|
|
11311
|
+
"value": {
|
|
11312
|
+
"retries": {
|
|
11313
|
+
"name": "number",
|
|
11314
|
+
"description": "\u91cd\u8bd5\u6b21\u6570",
|
|
11315
|
+
"required": false
|
|
11316
|
+
},
|
|
11317
|
+
"delay": {
|
|
11318
|
+
"name": "number",
|
|
11319
|
+
"description": "\u91cd\u8bd5\u524d\u7684\u5ef6\u65f6\u65f6\u957f\uff0c\u5355\u4f4d\uff1a\u6beb\u79d2",
|
|
11320
|
+
"required": false
|
|
11321
|
+
}
|
|
11322
|
+
}
|
|
11323
|
+
},
|
|
11324
|
+
{
|
|
11325
|
+
"name": "bool"
|
|
11326
|
+
}
|
|
11327
|
+
]
|
|
11328
|
+
},
|
|
11329
|
+
"required": false,
|
|
11330
|
+
"description": "\u914d\u7f6e\u8fde\u63a5\u65ad\u5f00\u81ea\u52a8\u91cd\u8fde\u76f8\u5173\u53c2\u6570\uff0c\u8bbe\u7f6e\u4e3a`false`\u65f6\u5c06\u4e0d\u4f1a\u81ea\u52a8\u91cd\u8fde\r\n\u9ed8\u8ba4\uff1a`false`",
|
|
11331
|
+
"defaultValue": {
|
|
11332
|
+
"value": "false",
|
|
11333
|
+
"computed": false
|
|
11334
|
+
}
|
|
11335
|
+
},
|
|
11336
|
+
"status": {
|
|
11337
|
+
"type": {
|
|
11338
|
+
"name": "string"
|
|
11339
|
+
},
|
|
11340
|
+
"required": false,
|
|
11341
|
+
"description": "\u76d1\u542c\u6700\u65b0\u7684\u8fde\u63a5\u72b6\u6001"
|
|
11342
|
+
},
|
|
11343
|
+
"data": {
|
|
11344
|
+
"type": {
|
|
11345
|
+
"name": "any"
|
|
11346
|
+
},
|
|
11347
|
+
"required": false,
|
|
11348
|
+
"description": "\u76d1\u542c\u6700\u65b0\u7684\u8fd4\u56de\u6570\u636e"
|
|
11349
|
+
},
|
|
11350
|
+
"event": {
|
|
11351
|
+
"type": {
|
|
11352
|
+
"name": "string"
|
|
11353
|
+
},
|
|
11354
|
+
"required": false,
|
|
11355
|
+
"description": "\u76d1\u542c\u6700\u65b0\u7684\u4e8b\u4ef6\u540d\u79f0"
|
|
11356
|
+
},
|
|
11357
|
+
"operation": {
|
|
11358
|
+
"type": {
|
|
11359
|
+
"name": "enum",
|
|
11360
|
+
"value": [
|
|
11361
|
+
{
|
|
11362
|
+
"value": "'open'",
|
|
11363
|
+
"computed": false
|
|
11364
|
+
},
|
|
11365
|
+
{
|
|
11366
|
+
"value": "'close'",
|
|
11367
|
+
"computed": false
|
|
11368
|
+
}
|
|
11369
|
+
]
|
|
11370
|
+
},
|
|
11371
|
+
"required": false,
|
|
11372
|
+
"description": "\u63a7\u5236\u8981\u7acb\u5373\u6267\u884c\u7684\u64cd\u4f5c\uff0c\u53ef\u9009\u9879\u6709`'open'`\u3001`'close'`\uff0c\u6bcf\u6b21\u65b0\u7684\u64cd\u4f5c\u6267\u884c\u5b8c\u6210\u540e\u90fd\u4f1a\u91cd\u7f6e\u4e3a\u7a7a\u503c"
|
|
11373
|
+
},
|
|
11374
|
+
"setProps": {
|
|
11375
|
+
"type": {
|
|
11376
|
+
"name": "func"
|
|
11377
|
+
},
|
|
11378
|
+
"required": false,
|
|
11379
|
+
"description": "Dash-assigned callback that should be called to report property changes\r\nto Dash, to make them available for callbacks."
|
|
11380
|
+
},
|
|
11381
|
+
"loading_state": {
|
|
11382
|
+
"type": {
|
|
11383
|
+
"name": "shape",
|
|
11384
|
+
"value": {
|
|
11385
|
+
"is_loading": {
|
|
11386
|
+
"name": "bool",
|
|
11387
|
+
"description": "Determines if the component is loading or not",
|
|
11388
|
+
"required": false
|
|
11389
|
+
},
|
|
11390
|
+
"prop_name": {
|
|
11391
|
+
"name": "string",
|
|
11392
|
+
"description": "Holds which property is loading",
|
|
11393
|
+
"required": false
|
|
11394
|
+
},
|
|
11395
|
+
"component_name": {
|
|
11396
|
+
"name": "string",
|
|
11397
|
+
"description": "Holds the name of the component that is loading",
|
|
11398
|
+
"required": false
|
|
11399
|
+
}
|
|
11400
|
+
}
|
|
11401
|
+
},
|
|
11402
|
+
"required": false,
|
|
11403
|
+
"description": ""
|
|
11404
|
+
}
|
|
11405
|
+
}
|
|
11406
|
+
},
|
|
11254
11407
|
"src/lib/components/FefferyExecuteJs.react.js": {
|
|
11255
11408
|
"description": "js\u76f4\u63a5\u6267\u884c\u7ec4\u4ef6FefferyExecuteJs",
|
|
11256
11409
|
"displayName": "FefferyExecuteJs",
|
package/package.json
CHANGED
|
@@ -21,6 +21,31 @@ const FefferyCountUp = (props) => {
|
|
|
21
21
|
loading_state
|
|
22
22
|
} = props;
|
|
23
23
|
|
|
24
|
+
if (enableScrollSpy) {
|
|
25
|
+
// #70
|
|
26
|
+
// 参考资料:https://stackoverflow.com/questions/76977652/countup-target-is-null-or-undefined-null-react-js
|
|
27
|
+
return (
|
|
28
|
+
<CountUp
|
|
29
|
+
id={id}
|
|
30
|
+
className={className}
|
|
31
|
+
style={style}
|
|
32
|
+
key={key}
|
|
33
|
+
end={end}
|
|
34
|
+
start={start}
|
|
35
|
+
duration={duration}
|
|
36
|
+
decimals={decimals}
|
|
37
|
+
enableScrollSpy={enableScrollSpy}
|
|
38
|
+
scrollSpyDelay={scrollSpyDelay}
|
|
39
|
+
scrollSpyOnce={scrollSpyOnce}
|
|
40
|
+
separator={separator}
|
|
41
|
+
data-dash-is-loading={
|
|
42
|
+
(loading_state && loading_state.is_loading) || undefined
|
|
43
|
+
} >
|
|
44
|
+
{({ countUpRef }) => <span ref={countUpRef} />}
|
|
45
|
+
</CountUp>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
24
49
|
return (
|
|
25
50
|
<CountUp
|
|
26
51
|
id={id}
|
|
@@ -31,14 +56,12 @@ const FefferyCountUp = (props) => {
|
|
|
31
56
|
start={start}
|
|
32
57
|
duration={duration}
|
|
33
58
|
decimals={decimals}
|
|
34
|
-
enableScrollSpy={enableScrollSpy}
|
|
35
|
-
scrollSpyDelay={scrollSpyDelay}
|
|
36
|
-
scrollSpyOnce={scrollSpyOnce}
|
|
37
59
|
separator={separator}
|
|
38
60
|
data-dash-is-loading={
|
|
39
61
|
(loading_state && loading_state.is_loading) || undefined
|
|
40
|
-
}
|
|
41
|
-
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useEventSource } from '@reactuses/core';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* EventSource通信组件FefferyEventSource
|
|
7
|
+
*/
|
|
8
|
+
const FefferyEventSource = (props) => {
|
|
9
|
+
const {
|
|
10
|
+
url,
|
|
11
|
+
events,
|
|
12
|
+
immediate,
|
|
13
|
+
autoReconnect,
|
|
14
|
+
operation,
|
|
15
|
+
setProps,
|
|
16
|
+
loading_state
|
|
17
|
+
} = props;
|
|
18
|
+
|
|
19
|
+
const { status: _status, data: _data, event: _event, close, open } = useEventSource(
|
|
20
|
+
url,
|
|
21
|
+
events,
|
|
22
|
+
{
|
|
23
|
+
immediate,
|
|
24
|
+
autoReconnect,
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!autoReconnect && _status === 'DISCONNECTED' && _data) {
|
|
30
|
+
close();
|
|
31
|
+
}
|
|
32
|
+
setProps({ status: _status })
|
|
33
|
+
}, [_status])
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setProps({ data: _data })
|
|
37
|
+
}, [_data])
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setProps({ event: _event })
|
|
41
|
+
}, [_event])
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (operation) {
|
|
45
|
+
if (operation === 'close') {
|
|
46
|
+
close();
|
|
47
|
+
} else if (operation === 'open') {
|
|
48
|
+
open();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, [operation])
|
|
52
|
+
|
|
53
|
+
return <></>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
FefferyEventSource.propTypes = {
|
|
57
|
+
/**
|
|
58
|
+
* 组件id
|
|
59
|
+
*/
|
|
60
|
+
id: PropTypes.string,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 强制刷新用唯一标识key值
|
|
64
|
+
*/
|
|
65
|
+
key: PropTypes.string,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 必填,目标服务地址
|
|
69
|
+
*/
|
|
70
|
+
url: PropTypes.string.isRequired,
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 目标事件名称列表
|
|
74
|
+
*/
|
|
75
|
+
events: PropTypes.arrayOf(PropTypes.string),
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 是否立即建立连接
|
|
79
|
+
* 默认:`true`
|
|
80
|
+
*/
|
|
81
|
+
immediate: PropTypes.bool,
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 配置连接断开自动重连相关参数,设置为`false`时将不会自动重连
|
|
85
|
+
* 默认:`false`
|
|
86
|
+
*/
|
|
87
|
+
autoReconnect: PropTypes.oneOfType([
|
|
88
|
+
PropTypes.shape({
|
|
89
|
+
/**
|
|
90
|
+
* 重试次数
|
|
91
|
+
*/
|
|
92
|
+
retries: PropTypes.number,
|
|
93
|
+
/**
|
|
94
|
+
* 重试前的延时时长,单位:毫秒
|
|
95
|
+
*/
|
|
96
|
+
delay: PropTypes.number
|
|
97
|
+
}),
|
|
98
|
+
PropTypes.bool
|
|
99
|
+
]),
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 监听最新的连接状态
|
|
103
|
+
*/
|
|
104
|
+
status: PropTypes.string,
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 监听最新的返回数据
|
|
108
|
+
*/
|
|
109
|
+
data: PropTypes.any,
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 监听最新的事件名称
|
|
113
|
+
*/
|
|
114
|
+
event: PropTypes.string,
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 控制要立即执行的操作,可选项有`'open'`、`'close'`,每次新的操作执行完成后都会重置为空值
|
|
118
|
+
*/
|
|
119
|
+
operation: PropTypes.oneOf(['open', 'close']),
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Dash-assigned callback that should be called to report property changes
|
|
123
|
+
* to Dash, to make them available for callbacks.
|
|
124
|
+
*/
|
|
125
|
+
setProps: PropTypes.func,
|
|
126
|
+
|
|
127
|
+
loading_state: PropTypes.shape({
|
|
128
|
+
/**
|
|
129
|
+
* Determines if the component is loading or not
|
|
130
|
+
*/
|
|
131
|
+
is_loading: PropTypes.bool,
|
|
132
|
+
/**
|
|
133
|
+
* Holds which property is loading
|
|
134
|
+
*/
|
|
135
|
+
prop_name: PropTypes.string,
|
|
136
|
+
/**
|
|
137
|
+
* Holds the name of the component that is loading
|
|
138
|
+
*/
|
|
139
|
+
component_name: PropTypes.string
|
|
140
|
+
})
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// 设置默认参数
|
|
144
|
+
FefferyEventSource.defaultProps = {
|
|
145
|
+
immediate: true,
|
|
146
|
+
autoReconnect: false,
|
|
147
|
+
events: []
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default FefferyEventSource;
|
package/src/lib/index.js
CHANGED
|
@@ -109,6 +109,7 @@ import FefferyPortal from "./components/FefferyPortal.react";
|
|
|
109
109
|
import FefferyVditor from "./components/editor/FefferyVditor.react.js";
|
|
110
110
|
import FefferyHttpRequests from "./components/FefferyHttpRequests.react.js";
|
|
111
111
|
import FefferyBurger from './components/FefferyBurger.react';
|
|
112
|
+
import FefferyEventSource from "./components/FefferyEventSource.react.js";
|
|
112
113
|
import './components/styles.css';
|
|
113
114
|
|
|
114
115
|
// 自定义sessionStorage事件监听
|
|
@@ -242,5 +243,6 @@ export {
|
|
|
242
243
|
FefferyPortal,
|
|
243
244
|
FefferyVditor,
|
|
244
245
|
FefferyHttpRequests,
|
|
245
|
-
FefferyBurger
|
|
246
|
+
FefferyBurger,
|
|
247
|
+
FefferyEventSource
|
|
246
248
|
};
|
package/usage.py
CHANGED
|
@@ -1,40 +1,45 @@
|
|
|
1
1
|
import dash
|
|
2
|
+
import time
|
|
3
|
+
import random
|
|
2
4
|
from dash import html
|
|
5
|
+
from urllib.parse import unquote
|
|
3
6
|
import feffery_utils_components as fuc
|
|
7
|
+
from flask import request, Response
|
|
8
|
+
from dash.dependencies import Input, Output, State
|
|
4
9
|
|
|
5
10
|
app = dash.Dash(__name__)
|
|
6
11
|
|
|
12
|
+
|
|
13
|
+
@app.server.route('/stream-chat')
|
|
14
|
+
def chatgpt():
|
|
15
|
+
question = request.args.get('question', '')
|
|
16
|
+
question = unquote(question).strip()
|
|
17
|
+
|
|
18
|
+
def stream():
|
|
19
|
+
for s in '测试问题回复结果' + '巴拉' * 1000:
|
|
20
|
+
time.sleep(random.uniform(0.05, 0.25))
|
|
21
|
+
yield 'data: %s\n\n' % s
|
|
22
|
+
|
|
23
|
+
return Response(stream(), mimetype='text/event-stream')
|
|
24
|
+
|
|
25
|
+
|
|
7
26
|
app.layout = html.Div(
|
|
8
27
|
[
|
|
9
|
-
fuc.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
for t in [
|
|
17
|
-
'default',
|
|
18
|
-
'squash',
|
|
19
|
-
'cross',
|
|
20
|
-
'twirl',
|
|
21
|
-
'fade',
|
|
22
|
-
'slant',
|
|
23
|
-
'spiral',
|
|
24
|
-
'divide',
|
|
25
|
-
'turn',
|
|
26
|
-
'pivot',
|
|
27
|
-
'sling',
|
|
28
|
-
'squeeze',
|
|
29
|
-
'spin',
|
|
30
|
-
'rotate',
|
|
31
|
-
]
|
|
28
|
+
fuc.FefferyEventSource(
|
|
29
|
+
id='sse-demo',
|
|
30
|
+
url='/stream-chat?question=%E4%BD%A0%E6%98%AF%E8%B0%81',
|
|
31
|
+
autoReconnect=False,
|
|
32
|
+
),
|
|
33
|
+
html.Div('', id='sse-demo-output'),
|
|
32
34
|
],
|
|
33
|
-
style={
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
style={'padding': 50},
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
app.clientside_callback(
|
|
39
|
+
"""(data, children) => data ? children + data : ''""",
|
|
40
|
+
Output('sse-demo-output', 'children'),
|
|
41
|
+
Input('sse-demo', 'data'),
|
|
42
|
+
State('sse-demo-output', 'children'),
|
|
38
43
|
)
|
|
39
44
|
|
|
40
45
|
if __name__ == '__main__':
|