feffery_utils_components 0.1.7 → 0.1.9
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 +2 -0
- package/Project.toml +1 -1
- package/build/lib/feffery_utils_components/FefferyTopProgress.py +8 -4
- package/build/lib/feffery_utils_components/FefferyWebSocket.py +60 -0
- package/build/lib/feffery_utils_components/_imports_.py +2 -0
- package/build/lib/feffery_utils_components/feffery_utils_components.min.js +2 -2
- package/build/lib/feffery_utils_components/metadata.json +148 -0
- package/build/lib/feffery_utils_components/package-info.json +1 -1
- package/feffery_utils_components/FefferyShadowDom.py +49 -0
- package/feffery_utils_components/FefferyWebSocket.py +60 -0
- package/feffery_utils_components/_imports_.py +4 -0
- package/feffery_utils_components/feffery_utils_components.min.js +2 -2
- package/feffery_utils_components/metadata.json +199 -0
- package/feffery_utils_components/package-info.json +3 -2
- package/package.json +3 -2
- package/src/FefferyUtilsComponents.jl +5 -3
- package/src/jl/''_fefferyshadowdom.jl +33 -0
- package/src/jl/''_fefferywebsocket.jl +30 -0
- package/src/lib/components/FefferyShadowDom.react.js +72 -0
- package/src/lib/components/FefferyWebSocket.react.js +128 -0
- package/src/lib/index.js +5 -1
- package/tests/FefferyShadowDomTest/app.py +53 -0
- package/feffery_utils_components/README.md +0 -96
|
@@ -3494,6 +3494,79 @@
|
|
|
3494
3494
|
}
|
|
3495
3495
|
}
|
|
3496
3496
|
},
|
|
3497
|
+
"src/lib/components/FefferyShadowDom.react.js": {
|
|
3498
|
+
"description": "",
|
|
3499
|
+
"displayName": "FefferyShadowDom",
|
|
3500
|
+
"methods": [],
|
|
3501
|
+
"props": {
|
|
3502
|
+
"id": {
|
|
3503
|
+
"type": {
|
|
3504
|
+
"name": "string"
|
|
3505
|
+
},
|
|
3506
|
+
"required": false,
|
|
3507
|
+
"description": ""
|
|
3508
|
+
},
|
|
3509
|
+
"key": {
|
|
3510
|
+
"type": {
|
|
3511
|
+
"name": "string"
|
|
3512
|
+
},
|
|
3513
|
+
"required": false,
|
|
3514
|
+
"description": ""
|
|
3515
|
+
},
|
|
3516
|
+
"children": {
|
|
3517
|
+
"type": {
|
|
3518
|
+
"name": "node"
|
|
3519
|
+
},
|
|
3520
|
+
"required": false,
|
|
3521
|
+
"description": ""
|
|
3522
|
+
},
|
|
3523
|
+
"className": {
|
|
3524
|
+
"type": {
|
|
3525
|
+
"name": "string"
|
|
3526
|
+
},
|
|
3527
|
+
"required": false,
|
|
3528
|
+
"description": ""
|
|
3529
|
+
},
|
|
3530
|
+
"style": {
|
|
3531
|
+
"type": {
|
|
3532
|
+
"name": "object"
|
|
3533
|
+
},
|
|
3534
|
+
"required": false,
|
|
3535
|
+
"description": ""
|
|
3536
|
+
},
|
|
3537
|
+
"loading_state": {
|
|
3538
|
+
"type": {
|
|
3539
|
+
"name": "shape",
|
|
3540
|
+
"value": {
|
|
3541
|
+
"is_loading": {
|
|
3542
|
+
"name": "bool",
|
|
3543
|
+
"description": "Determines if the component is loading or not",
|
|
3544
|
+
"required": false
|
|
3545
|
+
},
|
|
3546
|
+
"prop_name": {
|
|
3547
|
+
"name": "string",
|
|
3548
|
+
"description": "Holds which property is loading",
|
|
3549
|
+
"required": false
|
|
3550
|
+
},
|
|
3551
|
+
"component_name": {
|
|
3552
|
+
"name": "string",
|
|
3553
|
+
"description": "Holds the name of the component that is loading",
|
|
3554
|
+
"required": false
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
},
|
|
3558
|
+
"required": false,
|
|
3559
|
+
"description": ""
|
|
3560
|
+
},
|
|
3561
|
+
"setProps": {
|
|
3562
|
+
"type": {
|
|
3563
|
+
"name": "func"
|
|
3564
|
+
},
|
|
3565
|
+
"required": false,
|
|
3566
|
+
"description": "Dash-assigned callback that should be called to report property changes\r\nto Dash, to make them available for callbacks."
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
},
|
|
3497
3570
|
"src/lib/components/FefferyShortcutPanel.react.js": {
|
|
3498
3571
|
"description": "",
|
|
3499
3572
|
"displayName": "FefferyShortcutPanel",
|
|
@@ -4371,6 +4444,132 @@
|
|
|
4371
4444
|
}
|
|
4372
4445
|
}
|
|
4373
4446
|
},
|
|
4447
|
+
"src/lib/components/FefferyWebSocket.react.js": {
|
|
4448
|
+
"description": "",
|
|
4449
|
+
"displayName": "FefferyWebSocket",
|
|
4450
|
+
"methods": [],
|
|
4451
|
+
"props": {
|
|
4452
|
+
"id": {
|
|
4453
|
+
"type": {
|
|
4454
|
+
"name": "string"
|
|
4455
|
+
},
|
|
4456
|
+
"required": false,
|
|
4457
|
+
"description": ""
|
|
4458
|
+
},
|
|
4459
|
+
"socketUrl": {
|
|
4460
|
+
"type": {
|
|
4461
|
+
"name": "string"
|
|
4462
|
+
},
|
|
4463
|
+
"required": true,
|
|
4464
|
+
"description": ""
|
|
4465
|
+
},
|
|
4466
|
+
"reconnectLimit": {
|
|
4467
|
+
"type": {
|
|
4468
|
+
"name": "number"
|
|
4469
|
+
},
|
|
4470
|
+
"required": false,
|
|
4471
|
+
"description": ""
|
|
4472
|
+
},
|
|
4473
|
+
"reconnectInterval": {
|
|
4474
|
+
"type": {
|
|
4475
|
+
"name": "number"
|
|
4476
|
+
},
|
|
4477
|
+
"required": false,
|
|
4478
|
+
"description": ""
|
|
4479
|
+
},
|
|
4480
|
+
"operation": {
|
|
4481
|
+
"type": {
|
|
4482
|
+
"name": "enum",
|
|
4483
|
+
"value": [
|
|
4484
|
+
{
|
|
4485
|
+
"value": "'connect'",
|
|
4486
|
+
"computed": false
|
|
4487
|
+
},
|
|
4488
|
+
{
|
|
4489
|
+
"value": "'disconnect'",
|
|
4490
|
+
"computed": false
|
|
4491
|
+
},
|
|
4492
|
+
{
|
|
4493
|
+
"value": "'send'",
|
|
4494
|
+
"computed": false
|
|
4495
|
+
}
|
|
4496
|
+
]
|
|
4497
|
+
},
|
|
4498
|
+
"required": false,
|
|
4499
|
+
"description": ""
|
|
4500
|
+
},
|
|
4501
|
+
"message": {
|
|
4502
|
+
"type": {
|
|
4503
|
+
"name": "string"
|
|
4504
|
+
},
|
|
4505
|
+
"required": false,
|
|
4506
|
+
"description": ""
|
|
4507
|
+
},
|
|
4508
|
+
"latestMessage": {
|
|
4509
|
+
"type": {
|
|
4510
|
+
"name": "string"
|
|
4511
|
+
},
|
|
4512
|
+
"required": false,
|
|
4513
|
+
"description": ""
|
|
4514
|
+
},
|
|
4515
|
+
"state": {
|
|
4516
|
+
"type": {
|
|
4517
|
+
"name": "enum",
|
|
4518
|
+
"value": [
|
|
4519
|
+
{
|
|
4520
|
+
"value": "'connecting'",
|
|
4521
|
+
"computed": false
|
|
4522
|
+
},
|
|
4523
|
+
{
|
|
4524
|
+
"value": "'open'",
|
|
4525
|
+
"computed": false
|
|
4526
|
+
},
|
|
4527
|
+
{
|
|
4528
|
+
"value": "'closing'",
|
|
4529
|
+
"computed": false
|
|
4530
|
+
},
|
|
4531
|
+
{
|
|
4532
|
+
"value": "'closed'",
|
|
4533
|
+
"computed": false
|
|
4534
|
+
}
|
|
4535
|
+
]
|
|
4536
|
+
},
|
|
4537
|
+
"required": false,
|
|
4538
|
+
"description": ""
|
|
4539
|
+
},
|
|
4540
|
+
"setProps": {
|
|
4541
|
+
"type": {
|
|
4542
|
+
"name": "func"
|
|
4543
|
+
},
|
|
4544
|
+
"required": false,
|
|
4545
|
+
"description": "Dash-assigned callback that should be called to report property changes\r\nto Dash, to make them available for callbacks."
|
|
4546
|
+
},
|
|
4547
|
+
"loading_state": {
|
|
4548
|
+
"type": {
|
|
4549
|
+
"name": "shape",
|
|
4550
|
+
"value": {
|
|
4551
|
+
"is_loading": {
|
|
4552
|
+
"name": "bool",
|
|
4553
|
+
"description": "Determines if the component is loading or not",
|
|
4554
|
+
"required": false
|
|
4555
|
+
},
|
|
4556
|
+
"prop_name": {
|
|
4557
|
+
"name": "string",
|
|
4558
|
+
"description": "Holds which property is loading",
|
|
4559
|
+
"required": false
|
|
4560
|
+
},
|
|
4561
|
+
"component_name": {
|
|
4562
|
+
"name": "string",
|
|
4563
|
+
"description": "Holds the name of the component that is loading",
|
|
4564
|
+
"required": false
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
},
|
|
4568
|
+
"required": false,
|
|
4569
|
+
"description": ""
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
},
|
|
4374
4573
|
"src/lib/components/listeners/FefferyDocumentVisibility.react.js": {
|
|
4375
4574
|
"description": "",
|
|
4376
4575
|
"displayName": "FefferyDocumentVisibility",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feffery_utils_components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Build more utility components for Plotly Dash.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"react-lazy-load-image-component": "^1.5.5",
|
|
46
46
|
"react-resize-detector": "^7.1.2",
|
|
47
47
|
"react-scroll": "^1.8.6",
|
|
48
|
+
"react-shadow": "^19.0.3",
|
|
48
49
|
"react-sortable-hoc": "^2.0.0",
|
|
49
50
|
"react-spinners-kit": "^1.9.1",
|
|
50
51
|
"react-split": "^2.0.14",
|
|
@@ -101,4 +102,4 @@
|
|
|
101
102
|
"node": ">=8.11.0",
|
|
102
103
|
"npm": ">=6.1.0"
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feffery_utils_components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Build more utility components for Plotly Dash.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"react-lazy-load-image-component": "^1.5.5",
|
|
46
46
|
"react-resize-detector": "^7.1.2",
|
|
47
47
|
"react-scroll": "^1.8.6",
|
|
48
|
+
"react-shadow": "^19.0.3",
|
|
48
49
|
"react-sortable-hoc": "^2.0.0",
|
|
49
50
|
"react-spinners-kit": "^1.9.1",
|
|
50
51
|
"react-split": "^2.0.14",
|
|
@@ -101,4 +102,4 @@
|
|
|
101
102
|
"node": ">=8.11.0",
|
|
102
103
|
"npm": ">=6.1.0"
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
}
|
|
@@ -3,7 +3,7 @@ module FefferyUtilsComponents
|
|
|
3
3
|
using Dash
|
|
4
4
|
|
|
5
5
|
const resources_path = realpath(joinpath( @__DIR__, "..", "deps"))
|
|
6
|
-
const version = "0.1.
|
|
6
|
+
const version = "0.1.9"
|
|
7
7
|
|
|
8
8
|
include("jl/''_fefferyblockcolorpicker.jl")
|
|
9
9
|
include("jl/''_fefferycirclecolorpicker.jl")
|
|
@@ -33,6 +33,7 @@ include("jl/''_fefferyreload.jl")
|
|
|
33
33
|
include("jl/''_fefferyscroll.jl")
|
|
34
34
|
include("jl/''_fefferyscrollbars.jl")
|
|
35
35
|
include("jl/''_fefferysettitle.jl")
|
|
36
|
+
include("jl/''_fefferyshadowdom.jl")
|
|
36
37
|
include("jl/''_fefferyshortcutpanel.jl")
|
|
37
38
|
include("jl/''_fefferysticky.jl")
|
|
38
39
|
include("jl/''_fefferystyle.jl")
|
|
@@ -40,6 +41,7 @@ include("jl/''_fefferysyntaxhighlighter.jl")
|
|
|
40
41
|
include("jl/''_fefferytimeout.jl")
|
|
41
42
|
include("jl/''_fefferytopprogress.jl")
|
|
42
43
|
include("jl/''_fefferyvirtuallist.jl")
|
|
44
|
+
include("jl/''_fefferywebsocket.jl")
|
|
43
45
|
include("jl/''_fefferydocumentvisibility.jl")
|
|
44
46
|
include("jl/''_fefferygeolocation.jl")
|
|
45
47
|
include("jl/''_fefferyidle.jl")
|
|
@@ -62,14 +64,14 @@ function __init__()
|
|
|
62
64
|
[
|
|
63
65
|
DashBase.Resource(
|
|
64
66
|
relative_package_path = "feffery_utils_components.min.js",
|
|
65
|
-
external_url = "https://unpkg.com/feffery_utils_components@0.1.
|
|
67
|
+
external_url = "https://unpkg.com/feffery_utils_components@0.1.9/feffery_utils_components/feffery_utils_components.min.js",
|
|
66
68
|
dynamic = nothing,
|
|
67
69
|
async = nothing,
|
|
68
70
|
type = :js
|
|
69
71
|
),
|
|
70
72
|
DashBase.Resource(
|
|
71
73
|
relative_package_path = "feffery_utils_components.min.js.map",
|
|
72
|
-
external_url = "https://unpkg.com/feffery_utils_components@0.1.
|
|
74
|
+
external_url = "https://unpkg.com/feffery_utils_components@0.1.9/feffery_utils_components/feffery_utils_components.min.js.map",
|
|
73
75
|
dynamic = true,
|
|
74
76
|
async = nothing,
|
|
75
77
|
type = :js
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# AUTO GENERATED FILE - DO NOT EDIT
|
|
2
|
+
|
|
3
|
+
export ''_fefferyshadowdom
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
''_fefferyshadowdom(;kwargs...)
|
|
7
|
+
''_fefferyshadowdom(children::Any;kwargs...)
|
|
8
|
+
''_fefferyshadowdom(children_maker::Function;kwargs...)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
A FefferyShadowDom component.
|
|
12
|
+
|
|
13
|
+
Keyword arguments:
|
|
14
|
+
- `children` (a list of or a singular dash component, string or number; optional)
|
|
15
|
+
- `id` (String; optional)
|
|
16
|
+
- `className` (String; optional)
|
|
17
|
+
- `key` (String; optional)
|
|
18
|
+
- `loading_state` (optional): . loading_state has the following type: lists containing elements 'is_loading', 'prop_name', 'component_name'.
|
|
19
|
+
Those elements have the following types:
|
|
20
|
+
- `is_loading` (Bool; optional): Determines if the component is loading or not
|
|
21
|
+
- `prop_name` (String; optional): Holds which property is loading
|
|
22
|
+
- `component_name` (String; optional): Holds the name of the component that is loading
|
|
23
|
+
- `style` (Dict; optional)
|
|
24
|
+
"""
|
|
25
|
+
function ''_fefferyshadowdom(; kwargs...)
|
|
26
|
+
available_props = Symbol[:children, :id, :className, :key, :loading_state, :style]
|
|
27
|
+
wild_props = Symbol[]
|
|
28
|
+
return Component("''_fefferyshadowdom", "FefferyShadowDom", "feffery_utils_components", available_props, wild_props; kwargs...)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
''_fefferyshadowdom(children::Any; kwargs...) = ''_fefferyshadowdom(;kwargs..., children = children)
|
|
32
|
+
''_fefferyshadowdom(children_maker::Function; kwargs...) = ''_fefferyshadowdom(children_maker(); kwargs...)
|
|
33
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# AUTO GENERATED FILE - DO NOT EDIT
|
|
2
|
+
|
|
3
|
+
export ''_fefferywebsocket
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
''_fefferywebsocket(;kwargs...)
|
|
7
|
+
|
|
8
|
+
A FefferyWebSocket component.
|
|
9
|
+
|
|
10
|
+
Keyword arguments:
|
|
11
|
+
- `id` (String; optional)
|
|
12
|
+
- `latestMessage` (String; optional)
|
|
13
|
+
- `loading_state` (optional): . loading_state has the following type: lists containing elements 'is_loading', 'prop_name', 'component_name'.
|
|
14
|
+
Those elements have the following types:
|
|
15
|
+
- `is_loading` (Bool; optional): Determines if the component is loading or not
|
|
16
|
+
- `prop_name` (String; optional): Holds which property is loading
|
|
17
|
+
- `component_name` (String; optional): Holds the name of the component that is loading
|
|
18
|
+
- `message` (String; optional)
|
|
19
|
+
- `operation` (a value equal to: 'connect', 'disconnect', 'send'; optional)
|
|
20
|
+
- `reconnectInterval` (Real; optional)
|
|
21
|
+
- `reconnectLimit` (Real; optional)
|
|
22
|
+
- `socketUrl` (String; required)
|
|
23
|
+
- `state` (a value equal to: 'connecting', 'open', 'closing', 'closed'; optional)
|
|
24
|
+
"""
|
|
25
|
+
function ''_fefferywebsocket(; kwargs...)
|
|
26
|
+
available_props = Symbol[:id, :latestMessage, :loading_state, :message, :operation, :reconnectInterval, :reconnectLimit, :socketUrl, :state]
|
|
27
|
+
wild_props = Symbol[]
|
|
28
|
+
return Component("''_fefferywebsocket", "FefferyWebSocket", "feffery_utils_components", available_props, wild_props; kwargs...)
|
|
29
|
+
end
|
|
30
|
+
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import root from 'react-shadow';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
// 定义Shadow DOM组件FefferyShadowDom
|
|
6
|
+
const FefferyShadowDom = (props) => {
|
|
7
|
+
// 取得必要属性或参数
|
|
8
|
+
const {
|
|
9
|
+
id,
|
|
10
|
+
key,
|
|
11
|
+
children,
|
|
12
|
+
className,
|
|
13
|
+
style,
|
|
14
|
+
setProps,
|
|
15
|
+
loading_state
|
|
16
|
+
} = props;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<root.div
|
|
20
|
+
id={id}
|
|
21
|
+
key={key}
|
|
22
|
+
className={className}
|
|
23
|
+
style={style}
|
|
24
|
+
data-dash-is-loading={
|
|
25
|
+
(loading_state && loading_state.is_loading) || undefined
|
|
26
|
+
} >
|
|
27
|
+
{children}
|
|
28
|
+
</ root.div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// 定义参数或属性
|
|
34
|
+
FefferyShadowDom.propTypes = {
|
|
35
|
+
// 部件id
|
|
36
|
+
id: PropTypes.string,
|
|
37
|
+
|
|
38
|
+
key: PropTypes.string,
|
|
39
|
+
|
|
40
|
+
children: PropTypes.node,
|
|
41
|
+
|
|
42
|
+
className: PropTypes.string,
|
|
43
|
+
|
|
44
|
+
style: PropTypes.object,
|
|
45
|
+
|
|
46
|
+
loading_state: PropTypes.shape({
|
|
47
|
+
/**
|
|
48
|
+
* Determines if the component is loading or not
|
|
49
|
+
*/
|
|
50
|
+
is_loading: PropTypes.bool,
|
|
51
|
+
/**
|
|
52
|
+
* Holds which property is loading
|
|
53
|
+
*/
|
|
54
|
+
prop_name: PropTypes.string,
|
|
55
|
+
/**
|
|
56
|
+
* Holds the name of the component that is loading
|
|
57
|
+
*/
|
|
58
|
+
component_name: PropTypes.string
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Dash-assigned callback that should be called to report property changes
|
|
63
|
+
* to Dash, to make them available for callbacks.
|
|
64
|
+
*/
|
|
65
|
+
setProps: PropTypes.func,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 设置默认参数
|
|
69
|
+
FefferyShadowDom.defaultProps = {
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default React.memo(FefferyShadowDom);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useWebSocket } from 'ahooks';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
const num2state = new Map([
|
|
6
|
+
[0, 'connecting'],
|
|
7
|
+
[1, 'open'],
|
|
8
|
+
[2, 'closing'],
|
|
9
|
+
[3, 'closed']
|
|
10
|
+
])
|
|
11
|
+
|
|
12
|
+
// 定义WebSocket通信组件FefferyWebSocket
|
|
13
|
+
const FefferyWebSocket = (props) => {
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
id,
|
|
17
|
+
socketUrl,
|
|
18
|
+
reconnectLimit,
|
|
19
|
+
reconnectInterval,
|
|
20
|
+
operation,
|
|
21
|
+
message,
|
|
22
|
+
setProps,
|
|
23
|
+
loading_state
|
|
24
|
+
} = props;
|
|
25
|
+
|
|
26
|
+
const { readyState: _readyState, sendMessage, latestMessage: _latestMessage, disconnect, connect } = useWebSocket(
|
|
27
|
+
socketUrl,
|
|
28
|
+
{
|
|
29
|
+
reconnectLimit,
|
|
30
|
+
reconnectInterval
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// 监听服务器发送来的最新信息
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (_latestMessage) {
|
|
37
|
+
setProps({
|
|
38
|
+
latestMessage: _latestMessage.data
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
}, [_latestMessage])
|
|
42
|
+
|
|
43
|
+
// 监听当前WebSocket连接的状态
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
setProps({
|
|
46
|
+
state: num2state.get(_readyState)
|
|
47
|
+
})
|
|
48
|
+
}, [_readyState])
|
|
49
|
+
|
|
50
|
+
// 监听operation,从而执行不同操作
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (operation) {
|
|
53
|
+
// 断开连接操作
|
|
54
|
+
if (operation === 'connect') {
|
|
55
|
+
connect()
|
|
56
|
+
} else if (operation === 'disconnect') {
|
|
57
|
+
disconnect()
|
|
58
|
+
} else if (operation === 'send') {
|
|
59
|
+
sendMessage(message)
|
|
60
|
+
}
|
|
61
|
+
// 重置operation
|
|
62
|
+
setProps({
|
|
63
|
+
operation: null
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}, [operation])
|
|
67
|
+
|
|
68
|
+
return (<div
|
|
69
|
+
id={id}
|
|
70
|
+
data-dash-is-loading={
|
|
71
|
+
(loading_state && loading_state.is_loading) || undefined
|
|
72
|
+
} />);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 定义参数或属性
|
|
76
|
+
FefferyWebSocket.propTypes = {
|
|
77
|
+
// 部件id
|
|
78
|
+
id: PropTypes.string,
|
|
79
|
+
|
|
80
|
+
// 设置要建立连接的WebSocket服务url
|
|
81
|
+
socketUrl: PropTypes.string.isRequired,
|
|
82
|
+
|
|
83
|
+
// 设置连接重试次数,默认为3
|
|
84
|
+
reconnectLimit: PropTypes.number,
|
|
85
|
+
|
|
86
|
+
// 设置连接重试间隔,默认为3000,单位:毫秒
|
|
87
|
+
reconnectInterval: PropTypes.number,
|
|
88
|
+
|
|
89
|
+
// 用于执行连接/断开连接/发送信息操作,可选项有'connect'、'disconnect'、'send'
|
|
90
|
+
// 每次新操作执行后,operation参数都会被重置为null
|
|
91
|
+
operation: PropTypes.oneOf(['connect', 'disconnect', 'send']),
|
|
92
|
+
|
|
93
|
+
// 当operation更新为'send'时,用于设置要通过WebSocket服务向服务器发送的数据
|
|
94
|
+
message: PropTypes.string,
|
|
95
|
+
|
|
96
|
+
// 监听从服务器传来的最新信息
|
|
97
|
+
latestMessage: PropTypes.string,
|
|
98
|
+
|
|
99
|
+
// 用于监听当前此连接的状态,有'connecting'、'open'、'closing'、'closed'四种状态
|
|
100
|
+
state: PropTypes.oneOf(['connecting', 'open', 'closing', 'closed']),
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Dash-assigned callback that should be called to report property changes
|
|
104
|
+
* to Dash, to make them available for callbacks.
|
|
105
|
+
*/
|
|
106
|
+
setProps: PropTypes.func,
|
|
107
|
+
|
|
108
|
+
loading_state: PropTypes.shape({
|
|
109
|
+
/**
|
|
110
|
+
* Determines if the component is loading or not
|
|
111
|
+
*/
|
|
112
|
+
is_loading: PropTypes.bool,
|
|
113
|
+
/**
|
|
114
|
+
* Holds which property is loading
|
|
115
|
+
*/
|
|
116
|
+
prop_name: PropTypes.string,
|
|
117
|
+
/**
|
|
118
|
+
* Holds the name of the component that is loading
|
|
119
|
+
*/
|
|
120
|
+
component_name: PropTypes.string
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// 设置默认参数
|
|
125
|
+
FefferyWebSocket.defaultProps = {
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default React.memo(FefferyWebSocket);
|
package/src/lib/index.js
CHANGED
|
@@ -46,6 +46,8 @@ import FefferyEyeDropper from "./components/colorPickers/FefferyEyeDropper.react
|
|
|
46
46
|
import FefferySticky from "./components/FefferySticky.react";
|
|
47
47
|
import FefferyLazyLoadImage from "./components/FefferyLazyLoadImage.react";
|
|
48
48
|
import FefferySessionStorage from "./components/store/FefferySessionStorage";
|
|
49
|
+
import FefferyWebSocket from "./components/FefferyWebSocket.react";
|
|
50
|
+
import FefferyShadowDom from "./components/FefferyShadowDom.react";
|
|
49
51
|
|
|
50
52
|
/*
|
|
51
53
|
忽略部分设计React中规范的console警告信息
|
|
@@ -126,5 +128,7 @@ export {
|
|
|
126
128
|
FefferyEyeDropper,
|
|
127
129
|
FefferySticky,
|
|
128
130
|
FefferyLazyLoadImage,
|
|
129
|
-
FefferySessionStorage
|
|
131
|
+
FefferySessionStorage,
|
|
132
|
+
FefferyWebSocket,
|
|
133
|
+
FefferyShadowDom
|
|
130
134
|
};
|
|
@@ -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.FefferyShadowDom(
|
|
16
|
+
[
|
|
17
|
+
fuc.FefferyStyle(
|
|
18
|
+
rawStyle='''
|
|
19
|
+
.div-demo {
|
|
20
|
+
width: 200px;
|
|
21
|
+
height: 200px;
|
|
22
|
+
background: black;
|
|
23
|
+
}
|
|
24
|
+
'''
|
|
25
|
+
),
|
|
26
|
+
html.Div(
|
|
27
|
+
className='div-demo'
|
|
28
|
+
)
|
|
29
|
+
]
|
|
30
|
+
),
|
|
31
|
+
|
|
32
|
+
fuc.FefferyShadowDom(
|
|
33
|
+
[
|
|
34
|
+
fuc.FefferyStyle(
|
|
35
|
+
rawStyle='''
|
|
36
|
+
.div-demo {
|
|
37
|
+
width: 200px;
|
|
38
|
+
height: 200px;
|
|
39
|
+
background: grey;
|
|
40
|
+
}
|
|
41
|
+
'''
|
|
42
|
+
),
|
|
43
|
+
html.Div(
|
|
44
|
+
className='div-demo'
|
|
45
|
+
)
|
|
46
|
+
]
|
|
47
|
+
)
|
|
48
|
+
]
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == '__main__':
|
|
53
|
+
app.run(debug=True)
|