@livepreso/content-react 0.3.2 → 0.3.4
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 -21
- 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.4",
|
|
6
|
+
"tag": "@livepreso/content-react_v0.3.4",
|
|
7
|
+
"date": "Sun, 14 Jan 2024 21:06:16 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Remove observer in use-modes due to render loops"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.3.3",
|
|
18
|
+
"tag": "@livepreso/content-react_v0.3.3",
|
|
19
|
+
"date": "Thu, 21 Dec 2023 00:50:30 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"patch": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Use useState over useSharedState for now"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
"version": "0.3.2",
|
|
6
30
|
"tag": "@livepreso/content-react_v0.3.2",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
# Change Log - @livepreso/content-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on Sun,
|
|
3
|
+
This log was last generated on Sun, 14 Jan 2024 21:06:16 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.3.4
|
|
6
|
+
Sun, 14 Jan 2024 21:06:16 GMT
|
|
7
|
+
|
|
8
|
+
### Patches
|
|
9
|
+
|
|
10
|
+
- Remove observer in use-modes due to render loops
|
|
11
|
+
|
|
12
|
+
## 0.3.3
|
|
13
|
+
Thu, 21 Dec 2023 00:50:30 GMT
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Use useState over useSharedState for now
|
|
4
18
|
|
|
5
19
|
## 0.3.2
|
|
6
20
|
Sun, 17 Dec 2023 21:02:31 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
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function getModes() {
|
|
1
|
+
export function useModes() {
|
|
4
2
|
const bodyClasses = [...document.body.classList];
|
|
5
3
|
|
|
6
4
|
const isMaster = bodyClasses.includes("master");
|
|
@@ -33,21 +31,3 @@ function getModes() {
|
|
|
33
31
|
isPresomanager,
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
|
-
|
|
37
|
-
export function useModes() {
|
|
38
|
-
const [modes, setModes] = useState(getModes());
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
const observer = new MutationObserver(() => {
|
|
42
|
-
setModes(getModes());
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
observer.observe(document.body, {
|
|
46
|
-
attributes: ["classList"],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return () => observer.disconnect();
|
|
50
|
-
}, []);
|
|
51
|
-
|
|
52
|
-
return modes;
|
|
53
|
-
}
|