@livepreso/content-react 0.3.1 → 0.3.3
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/CHANGELOG.json +24 -0
- package/CHANGELOG.md +15 -1
- package/lib/hooks/use-context.js +53 -54
- package/lib/hooks/use-modes.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livepreso/content-react",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.3.3",
|
|
6
|
+
"tag": "@livepreso/content-react_v0.3.3",
|
|
7
|
+
"date": "Thu, 21 Dec 2023 00:50:30 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Use useState over useSharedState for now"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.3.2",
|
|
18
|
+
"tag": "@livepreso/content-react_v0.3.2",
|
|
19
|
+
"date": "Sun, 17 Dec 2023 21:02:31 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"patch": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Add isShareOnline to useMode"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
"version": "0.3.1",
|
|
6
30
|
"tag": "@livepreso/content-react_v0.3.1",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @livepreso/content-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 21 Dec 2023 00:50:30 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.3
|
|
6
|
+
Thu, 21 Dec 2023 00:50:30 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Use useState over useSharedState for now
|
|
11
|
+
|
|
12
|
+
## 0.3.2
|
|
13
|
+
Sun, 17 Dec 2023 21:02:31 GMT
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Add isShareOnline to useMode
|
|
4
18
|
|
|
5
19
|
## 0.3.1
|
|
6
20
|
Fri, 15 Dec 2023 00:19:06 GMT
|
package/lib/hooks/use-context.js
CHANGED
|
@@ -1,62 +1,61 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
1
3
|
import isPlainObject from "lodash.isplainobject";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { useSharedState } from "./index.js";
|
|
4
4
|
|
|
5
5
|
function getValueFromContext(context, path, defaultValue) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (path) {
|
|
7
|
+
return Bridge.Context.get(path, defaultValue);
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
return context;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function useContext(contextPath = null, defaultValue = null) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
14
|
+
let persist = false;
|
|
15
|
+
let path = contextPath;
|
|
16
|
+
|
|
17
|
+
const value = getValueFromContext(
|
|
18
|
+
window.Bridge.Context.getDict(),
|
|
19
|
+
path,
|
|
20
|
+
defaultValue,
|
|
21
|
+
);
|
|
22
|
+
const [context, setContextState] = useState(value);
|
|
23
|
+
|
|
24
|
+
// You could pass in an object, so that you can set whether
|
|
25
|
+
// the saves are persistent or not.
|
|
26
|
+
if (isPlainObject(contextPath)) {
|
|
27
|
+
path = contextPath.path || null;
|
|
28
|
+
persist = contextPath.save || false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function setContext(key, data) {
|
|
32
|
+
let setPath = key;
|
|
33
|
+
let setData = data;
|
|
34
|
+
|
|
35
|
+
if (path) {
|
|
36
|
+
if (data) {
|
|
37
|
+
setPath = `${path}.${key}`;
|
|
38
|
+
} else {
|
|
39
|
+
setPath = path;
|
|
40
|
+
setData = key;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Bridge.Context.set(setPath, setData, persist);
|
|
45
|
+
|
|
46
|
+
const value = getValueFromContext(
|
|
47
|
+
Bridge.Context.getDict(),
|
|
48
|
+
path,
|
|
49
|
+
defaultValue,
|
|
50
|
+
);
|
|
51
|
+
setContextState(value);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (context !== value) {
|
|
56
|
+
Bridge.Context.set(path, context, persist);
|
|
57
|
+
}
|
|
58
|
+
}, [context]);
|
|
59
|
+
|
|
60
|
+
return [context, setContext];
|
|
61
61
|
}
|
|
62
|
-
|
package/lib/hooks/use-modes.js
CHANGED