@livepreso/content-react 2.3.1 → 3.0.0
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/.lintstagedrc.js +4 -4
- package/.rush/temp/package-deps_build.json +26 -0
- package/.rush/temp/package-deps_test.json +26 -0
- package/.rush/temp/shrinkwrap-deps.json +306 -10
- package/CHANGELOG.json +34 -0
- package/CHANGELOG.md +15 -1
- package/babel.config.js +8 -0
- package/jest.config.js +11 -0
- package/lib/components/OverlayPortal.js +5 -1
- package/lib/hooks/cmsvals.js +46 -5
- package/lib/hooks/cmsvals.spec.js +87 -0
- package/lib/hooks/cwe-editable.js +5 -3
- package/lib/hooks/index.js +3 -1
- package/lib/hooks/prep-editable.js +7 -6
- package/lib/hooks/prep-editable.spec.js +78 -0
- package/lib/hooks/slide.js +2 -2
- package/lib/hooks/use-actions.js +112 -0
- package/lib/hooks/use-actions.spec.js +150 -0
- package/lib/hooks/use-editable-field-key.js +7 -2
- package/lib/hooks/use-root-slide.js +2 -2
- package/lib/hooks/use-slide-context.js +8 -4
- package/lib/hooks/use-target-key.js +25 -0
- package/lib/hooks/use-target-key.spec.js +23 -0
- package/lib/utils.js +7 -2
- package/package.json +10 -4
- package/test/project.json +3 -0
|
@@ -13,7 +13,12 @@ export function useEditableFieldKey(key) {
|
|
|
13
13
|
const presomanagerTemplateKey = getPMTemplateFieldKey(key, slideID);
|
|
14
14
|
const userTemplateKey = getUserTemplateFieldKey(key, slideID);
|
|
15
15
|
|
|
16
|
-
if (isUserTemplate)
|
|
17
|
-
|
|
16
|
+
if (isUserTemplate) {
|
|
17
|
+
return userTemplateKey;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isPMTemplate) {
|
|
21
|
+
return presomanagerTemplateKey;
|
|
22
|
+
}
|
|
18
23
|
return key;
|
|
19
24
|
}
|
|
@@ -164,8 +164,8 @@ export function useRootSlide(article) {
|
|
|
164
164
|
// If for whatever reason this isn't in the dom, we fall back to the ID.
|
|
165
165
|
presentationKey,
|
|
166
166
|
|
|
167
|
-
//
|
|
168
|
-
// "deck/section/slide"
|
|
167
|
+
// Reads data-slide-path from the article, in the form
|
|
168
|
+
// "deck/section/slide", which is the form Bridge commands expect.
|
|
169
169
|
slidePath,
|
|
170
170
|
|
|
171
171
|
isCurrentSlide: isCurrent,
|
|
@@ -54,18 +54,22 @@ export function useSlideContext(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
useEffect(() => {
|
|
57
|
-
if (isPresomanager || !enabled)
|
|
57
|
+
if (isPresomanager || !enabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
function onContextChange() {
|
|
60
62
|
const newValue = getValue();
|
|
61
|
-
if (isEqual(newValue, context))
|
|
63
|
+
if (isEqual(newValue, context)) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
62
66
|
setContextState(newValue);
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
Bridge.
|
|
69
|
+
Bridge.Context.on("changed", onContextChange);
|
|
66
70
|
|
|
67
71
|
return () => {
|
|
68
|
-
Bridge.
|
|
72
|
+
Bridge.Context.off("changed", onContextChange);
|
|
69
73
|
};
|
|
70
74
|
}, [enabled, isPresomanager, context, getValue]);
|
|
71
75
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useSlide } from "./slide.js";
|
|
2
|
+
|
|
3
|
+
const TEMPLATE_PREFIX = /^template-/;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The key of the slide, section or template being rendered, spelled the way
|
|
7
|
+
* `project.yaml` spells it.
|
|
8
|
+
*
|
|
9
|
+
* This is what a declared editable's `{targetKey}` resolves to, so a component
|
|
10
|
+
* using one hands it to `resolveEditable`:
|
|
11
|
+
*
|
|
12
|
+
* const { attrs } = resolveEditable(editable, props, {
|
|
13
|
+
* targetKey: useTargetKey(),
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* It exists rather than each component reaching into `useSlide` itself because
|
|
17
|
+
* a slide carries an id as well as a key. Keying a field off the wrong one
|
|
18
|
+
* stores it somewhere nothing reads, and nothing about the resulting key looks
|
|
19
|
+
* wrong enough to notice.
|
|
20
|
+
*/
|
|
21
|
+
export function useTargetKey() {
|
|
22
|
+
const { slideKey } = useSlide();
|
|
23
|
+
|
|
24
|
+
return slideKey.replace(TEMPLATE_PREFIX, "");
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useSlide } from "./slide.js";
|
|
2
|
+
import { useTargetKey } from "./use-target-key.js";
|
|
3
|
+
|
|
4
|
+
jest.mock("./slide.js", () => ({ useSlide: jest.fn() }));
|
|
5
|
+
|
|
6
|
+
describe("useTargetKey", () => {
|
|
7
|
+
// A slide carries an id as well as a key, and they are different things. A
|
|
8
|
+
// field keyed by the wrong one stores somewhere nothing reads, which is the
|
|
9
|
+
// mistake this hook exists to stop each content library making for itself.
|
|
10
|
+
it("answers with the slide's key rather than anything else it carries", () => {
|
|
11
|
+
useSlide.mockReturnValue({ slideKey: "a-target", slideID: "an-id" });
|
|
12
|
+
|
|
13
|
+
expect(useTargetKey()).toBe("a-target");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// The prefix belongs to the runtime, not to the deck's own vocabulary, and a
|
|
17
|
+
// key composed with it in would not match what project.yaml registers.
|
|
18
|
+
it("drops the prefix a template's key arrives with", () => {
|
|
19
|
+
useSlide.mockReturnValue({ slideKey: "template-a-target" });
|
|
20
|
+
|
|
21
|
+
expect(useTargetKey()).toBe("a-target");
|
|
22
|
+
});
|
|
23
|
+
});
|
package/lib/utils.js
CHANGED
|
@@ -39,9 +39,14 @@ export function testCWEJSONExists({
|
|
|
39
39
|
|
|
40
40
|
const presomanagerTemplateKey = getPMTemplateFieldKey(key, slideID);
|
|
41
41
|
const userTemplateKey = getUserTemplateFieldKey(key, slideID);
|
|
42
|
+
if (isUserTemplate) {
|
|
43
|
+
return cweKeys.includes(userTemplateKey);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (isPMTemplate) {
|
|
47
|
+
return cweKeys.includes(presomanagerTemplateKey);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
|
-
if (isUserTemplate) return cweKeys.includes(userTemplateKey);
|
|
44
|
-
if (isPMTemplate) return cweKeys.includes(presomanagerTemplateKey);
|
|
45
50
|
return cweKeys.includes(key);
|
|
46
51
|
}
|
|
47
52
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livepreso/content-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"eslint": "~9.15.0",
|
|
14
|
+
"@babel/core": "~7.26.0",
|
|
15
|
+
"@babel/preset-env": "^7.14.9",
|
|
14
16
|
"@babel/preset-react": "~7.25.9",
|
|
17
|
+
"babel-jest": "~29.7.0",
|
|
18
|
+
"jest": "~29.7.0",
|
|
15
19
|
"@livepreso/eslint-config": "1.0.0"
|
|
16
20
|
},
|
|
17
21
|
"peerDependencies": {
|
|
@@ -19,15 +23,17 @@
|
|
|
19
23
|
"react-dom": ">= 18.0.0 <= 19.x"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"@livepreso/content-base": "~
|
|
26
|
+
"@livepreso/content-base": "~2.0.0",
|
|
23
27
|
"ulog": "~2.0.0-beta.19",
|
|
24
28
|
"lodash.get": "~4.4.2",
|
|
25
29
|
"lodash.isplainobject": "~4.0.6",
|
|
26
30
|
"lodash.set": "~4.3.2",
|
|
27
31
|
"lodash.unescape": "~4.0.1",
|
|
28
|
-
"lodash.isequal": "~4.5.0"
|
|
32
|
+
"lodash.isequal": "~4.5.0",
|
|
33
|
+
"@livepreso/webpack-deck": "4.0.0"
|
|
29
34
|
},
|
|
30
35
|
"scripts": {
|
|
31
|
-
"build": ""
|
|
36
|
+
"build": "",
|
|
37
|
+
"test": "jest --maxWorkers=2 --workerIdleMemoryLimit=512MB"
|
|
32
38
|
}
|
|
33
39
|
}
|