@livepreso/content-react 0.7.2 → 1.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/.rush/temp/package-deps_build.json +26 -0
- package/.rush/temp/shrinkwrap-deps.json +152 -144
- package/CHANGELOG.json +443 -414
- package/CHANGELOG.md +20 -32
- package/content-react.build.log +4 -0
- package/lib/components/CompanywideJSON.js +17 -7
- package/lib/hooks/cwe-editable.js +82 -0
- package/lib/hooks/index.js +3 -1
- package/lib/hooks/prep-editable.js +74 -0
- package/lib/hooks/use-editable-field-key.js +19 -0
- package/lib/hooks/use-editable-initial-state.js +13 -108
- package/lib/hooks/use-modes.js +4 -1
- package/lib/utils.js +152 -0
- package/package.json +29 -29
- package/lib/hooks/use-prep-editable.js +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
# Change Log - @livepreso/content-react
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 08 May 2025 06:12:34 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 1.0.0
|
|
6
|
+
Thu, 08 May 2025 06:12:34 GMT
|
|
7
|
+
|
|
8
|
+
### Breaking changes
|
|
9
|
+
|
|
10
|
+
- Replace usePrepEditable() hook with usePrepEditableInfo(), add useCWEEditableInfo(), improve editables interactions with new utils.
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- Add warning to companywide editable docs about repeated keys
|
|
6
15
|
|
|
16
|
+
## 0.7.3
|
|
17
|
+
Wed, 23 Apr 2025 22:55:14 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- Previous deploy failed, forcing a new one
|
|
22
|
+
|
|
23
|
+
## 0.7.2
|
|
7
24
|
Wed, 23 Apr 2025 06:25:28 GMT
|
|
8
25
|
|
|
9
26
|
### Patches
|
|
@@ -11,7 +28,6 @@ Wed, 23 Apr 2025 06:25:28 GMT
|
|
|
11
28
|
- When using useEditableInitialState for user templates, only prefix returned key with slideID-- when it's going to be used to traverse userCMSVals context data. If slideID-- prefix is already included in the provided key, do not add it again.
|
|
12
29
|
|
|
13
30
|
## 0.7.1
|
|
14
|
-
|
|
15
31
|
Thu, 03 Apr 2025 22:38:00 GMT
|
|
16
32
|
|
|
17
33
|
### Patches
|
|
@@ -19,7 +35,6 @@ Thu, 03 Apr 2025 22:38:00 GMT
|
|
|
19
35
|
- fix useEditableInitialState user template value retrieval
|
|
20
36
|
|
|
21
37
|
## 0.7.0
|
|
22
|
-
|
|
23
38
|
Thu, 06 Mar 2025 00:08:07 GMT
|
|
24
39
|
|
|
25
40
|
### Minor changes
|
|
@@ -27,7 +42,6 @@ Thu, 06 Mar 2025 00:08:07 GMT
|
|
|
27
42
|
- Add isEmptyPreview to useModes hook, move CWE JSON field to underneath slide
|
|
28
43
|
|
|
29
44
|
## 0.6.2
|
|
30
|
-
|
|
31
45
|
Tue, 25 Feb 2025 03:34:02 GMT
|
|
32
46
|
|
|
33
47
|
### Patches
|
|
@@ -35,7 +49,6 @@ Tue, 25 Feb 2025 03:34:02 GMT
|
|
|
35
49
|
- setContext(key, value) allows setting of falsy values
|
|
36
50
|
|
|
37
51
|
## 0.6.1
|
|
38
|
-
|
|
39
52
|
Thu, 20 Feb 2025 01:26:11 GMT
|
|
40
53
|
|
|
41
54
|
### Patches
|
|
@@ -43,7 +56,6 @@ Thu, 20 Feb 2025 01:26:11 GMT
|
|
|
43
56
|
- Update dependencies
|
|
44
57
|
|
|
45
58
|
## 0.6.0
|
|
46
|
-
|
|
47
59
|
Sun, 09 Feb 2025 23:36:42 GMT
|
|
48
60
|
|
|
49
61
|
### Minor changes
|
|
@@ -51,7 +63,6 @@ Sun, 09 Feb 2025 23:36:42 GMT
|
|
|
51
63
|
- added explicit exports to improve IDE hinting
|
|
52
64
|
|
|
53
65
|
## 0.5.2
|
|
54
|
-
|
|
55
66
|
Fri, 17 Jan 2025 04:54:14 GMT
|
|
56
67
|
|
|
57
68
|
### Patches
|
|
@@ -59,7 +70,6 @@ Fri, 17 Jan 2025 04:54:14 GMT
|
|
|
59
70
|
- resolved race condition in useCompanywide setter
|
|
60
71
|
|
|
61
72
|
## 0.5.1
|
|
62
|
-
|
|
63
73
|
Fri, 17 Jan 2025 03:37:56 GMT
|
|
64
74
|
|
|
65
75
|
### Patches
|
|
@@ -67,7 +77,6 @@ Fri, 17 Jan 2025 03:37:56 GMT
|
|
|
67
77
|
- Properly call slideready on hot module reload
|
|
68
78
|
|
|
69
79
|
## 0.5.0
|
|
70
|
-
|
|
71
80
|
Tue, 26 Nov 2024 03:54:55 GMT
|
|
72
81
|
|
|
73
82
|
### Minor changes
|
|
@@ -75,7 +84,6 @@ Tue, 26 Nov 2024 03:54:55 GMT
|
|
|
75
84
|
- Add internal presentation slide key to useSlide()
|
|
76
85
|
|
|
77
86
|
## 0.4.3
|
|
78
|
-
|
|
79
87
|
Thu, 21 Nov 2024 01:14:47 GMT
|
|
80
88
|
|
|
81
89
|
### Patches
|
|
@@ -83,7 +91,6 @@ Thu, 21 Nov 2024 01:14:47 GMT
|
|
|
83
91
|
- Move CWE Editables far below content
|
|
84
92
|
|
|
85
93
|
## 0.4.2
|
|
86
|
-
|
|
87
94
|
Thu, 21 Nov 2024 00:05:45 GMT
|
|
88
95
|
|
|
89
96
|
### Patches
|
|
@@ -91,7 +98,6 @@ Thu, 21 Nov 2024 00:05:45 GMT
|
|
|
91
98
|
- Always add global
|
|
92
99
|
|
|
93
100
|
## 0.4.1
|
|
94
|
-
|
|
95
101
|
Wed, 20 Nov 2024 23:28:52 GMT
|
|
96
102
|
|
|
97
103
|
### Patches
|
|
@@ -99,7 +105,6 @@ Wed, 20 Nov 2024 23:28:52 GMT
|
|
|
99
105
|
- Components were not correctly unmounting
|
|
100
106
|
|
|
101
107
|
## 0.4.0
|
|
102
|
-
|
|
103
108
|
Tue, 24 Sep 2024 03:37:23 GMT
|
|
104
109
|
|
|
105
110
|
### Minor changes
|
|
@@ -107,7 +112,6 @@ Tue, 24 Sep 2024 03:37:23 GMT
|
|
|
107
112
|
- Allow overriding react errors
|
|
108
113
|
|
|
109
114
|
## 0.3.9
|
|
110
|
-
|
|
111
115
|
Fri, 23 Aug 2024 05:02:46 GMT
|
|
112
116
|
|
|
113
117
|
### Patches
|
|
@@ -115,7 +119,6 @@ Fri, 23 Aug 2024 05:02:46 GMT
|
|
|
115
119
|
- Company wide editables fixes
|
|
116
120
|
|
|
117
121
|
## 0.3.8
|
|
118
|
-
|
|
119
122
|
Wed, 24 Jul 2024 06:53:26 GMT
|
|
120
123
|
|
|
121
124
|
### Patches
|
|
@@ -123,7 +126,6 @@ Wed, 24 Jul 2024 06:53:26 GMT
|
|
|
123
126
|
- Update latest
|
|
124
127
|
|
|
125
128
|
## 0.3.7
|
|
126
|
-
|
|
127
129
|
Fri, 03 May 2024 00:56:03 GMT
|
|
128
130
|
|
|
129
131
|
### Patches
|
|
@@ -131,7 +133,6 @@ Fri, 03 May 2024 00:56:03 GMT
|
|
|
131
133
|
- New version of content-base
|
|
132
134
|
|
|
133
135
|
## 0.3.6
|
|
134
|
-
|
|
135
136
|
Wed, 20 Mar 2024 01:31:57 GMT
|
|
136
137
|
|
|
137
138
|
### Patches
|
|
@@ -139,7 +140,6 @@ Wed, 20 Mar 2024 01:31:57 GMT
|
|
|
139
140
|
- Subslide functionaly accessible throughout slides
|
|
140
141
|
|
|
141
142
|
## 0.3.5
|
|
142
|
-
|
|
143
143
|
Sun, 03 Mar 2024 23:59:09 GMT
|
|
144
144
|
|
|
145
145
|
### Patches
|
|
@@ -147,7 +147,6 @@ Sun, 03 Mar 2024 23:59:09 GMT
|
|
|
147
147
|
- Hot reload improvements
|
|
148
148
|
|
|
149
149
|
## 0.3.4
|
|
150
|
-
|
|
151
150
|
Sun, 14 Jan 2024 21:06:16 GMT
|
|
152
151
|
|
|
153
152
|
### Patches
|
|
@@ -155,7 +154,6 @@ Sun, 14 Jan 2024 21:06:16 GMT
|
|
|
155
154
|
- Remove observer in use-modes due to render loops
|
|
156
155
|
|
|
157
156
|
## 0.3.3
|
|
158
|
-
|
|
159
157
|
Thu, 21 Dec 2023 00:50:30 GMT
|
|
160
158
|
|
|
161
159
|
### Patches
|
|
@@ -163,7 +161,6 @@ Thu, 21 Dec 2023 00:50:30 GMT
|
|
|
163
161
|
- Use useState over useSharedState for now
|
|
164
162
|
|
|
165
163
|
## 0.3.2
|
|
166
|
-
|
|
167
164
|
Sun, 17 Dec 2023 21:02:31 GMT
|
|
168
165
|
|
|
169
166
|
### Patches
|
|
@@ -171,7 +168,6 @@ Sun, 17 Dec 2023 21:02:31 GMT
|
|
|
171
168
|
- Add isShareOnline to useMode
|
|
172
169
|
|
|
173
170
|
## 0.3.1
|
|
174
|
-
|
|
175
171
|
Fri, 15 Dec 2023 00:19:06 GMT
|
|
176
172
|
|
|
177
173
|
### Patches
|
|
@@ -179,7 +175,6 @@ Fri, 15 Dec 2023 00:19:06 GMT
|
|
|
179
175
|
- Add modes and fix use-prep-editables import
|
|
180
176
|
|
|
181
177
|
## 0.3.0
|
|
182
|
-
|
|
183
178
|
Thu, 14 Dec 2023 03:11:26 GMT
|
|
184
179
|
|
|
185
180
|
### Minor changes
|
|
@@ -187,7 +182,6 @@ Thu, 14 Dec 2023 03:11:26 GMT
|
|
|
187
182
|
- Add use-prep-editable hook and new pdf modes
|
|
188
183
|
|
|
189
184
|
## 0.2.2
|
|
190
|
-
|
|
191
185
|
Tue, 14 Nov 2023 01:02:01 GMT
|
|
192
186
|
|
|
193
187
|
### Patches
|
|
@@ -195,7 +189,6 @@ Tue, 14 Nov 2023 01:02:01 GMT
|
|
|
195
189
|
- Always use correct article element
|
|
196
190
|
|
|
197
191
|
## 0.2.1
|
|
198
|
-
|
|
199
192
|
Wed, 18 Oct 2023 05:58:34 GMT
|
|
200
193
|
|
|
201
194
|
### Patches
|
|
@@ -203,7 +196,6 @@ Wed, 18 Oct 2023 05:58:34 GMT
|
|
|
203
196
|
- Update content base
|
|
204
197
|
|
|
205
198
|
## 0.2.0
|
|
206
|
-
|
|
207
199
|
Tue, 03 Oct 2023 23:32:09 GMT
|
|
208
200
|
|
|
209
201
|
### Minor changes
|
|
@@ -211,7 +203,6 @@ Tue, 03 Oct 2023 23:32:09 GMT
|
|
|
211
203
|
- Allow error page to be overriden
|
|
212
204
|
|
|
213
205
|
## 0.1.2
|
|
214
|
-
|
|
215
206
|
Mon, 04 Sep 2023 04:10:06 GMT
|
|
216
207
|
|
|
217
208
|
### Patches
|
|
@@ -219,13 +210,11 @@ Mon, 04 Sep 2023 04:10:06 GMT
|
|
|
219
210
|
- Don't attempt to render image slides
|
|
220
211
|
|
|
221
212
|
## 0.1.1
|
|
222
|
-
|
|
223
213
|
Tue, 11 Jul 2023 22:54:01 GMT
|
|
224
214
|
|
|
225
215
|
_Version update only_
|
|
226
216
|
|
|
227
217
|
## 0.1.0
|
|
228
|
-
|
|
229
218
|
Tue, 28 Jun 2022 23:37:28 GMT
|
|
230
219
|
|
|
231
220
|
### Minor changes
|
|
@@ -233,7 +222,6 @@ Tue, 28 Jun 2022 23:37:28 GMT
|
|
|
233
222
|
- Add support for companywide json
|
|
234
223
|
|
|
235
224
|
## 0.0.2
|
|
236
|
-
|
|
237
225
|
Wed, 01 Jun 2022 00:55:51 GMT
|
|
238
226
|
|
|
239
227
|
### Patches
|
|
@@ -241,7 +229,7 @@ Wed, 01 Jun 2022 00:55:51 GMT
|
|
|
241
229
|
- General fixes
|
|
242
230
|
|
|
243
231
|
## 0.0.1
|
|
244
|
-
|
|
245
232
|
Thu, 05 Aug 2021 06:38:32 GMT
|
|
246
233
|
|
|
247
234
|
_Initial release_
|
|
235
|
+
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
|
|
3
|
-
import { CWE_JSON_KEY } from "../constants.js";
|
|
4
3
|
import { CompanywideJSONContext } from "../contexts.js";
|
|
5
4
|
import set from "lodash.set";
|
|
6
5
|
import unescape from "lodash.unescape";
|
|
7
6
|
import { useEditableInitialState } from "../hooks/use-editable-initial-state.js";
|
|
8
7
|
import { useSlide } from "../hooks/use-slide.js";
|
|
8
|
+
import { getCWEJSONKey, testCWEJSONExists } from "../utils.js";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* IMPORTANT: This component must always wrap RootApp in index.js.
|
|
12
|
+
* We attempted to limit its use to the on-stage / active slide,
|
|
13
|
+
* but that resulted in off-stage slides (ie. previous and next)
|
|
14
|
+
* getting default values instead of latest, resulting in janky animations
|
|
15
|
+
* (and probably more problems too...)
|
|
16
|
+
*/
|
|
10
17
|
export function CompanywideJSON({ children }) {
|
|
11
|
-
const
|
|
18
|
+
const slideState = useSlide();
|
|
19
|
+
const { slideKey } = slideState;
|
|
12
20
|
const editableRef = useRef();
|
|
13
21
|
const [editableValue, editableKey] = useEditableInitialState(
|
|
14
|
-
|
|
22
|
+
getCWEJSONKey(slideKey),
|
|
15
23
|
"{}",
|
|
16
24
|
);
|
|
17
25
|
|
|
26
|
+
const cweJsonExists = testCWEJSONExists(slideState);
|
|
27
|
+
|
|
18
28
|
let initialState = {};
|
|
19
29
|
|
|
20
30
|
try {
|
|
@@ -43,15 +53,15 @@ export function CompanywideJSON({ children }) {
|
|
|
43
53
|
const providerValues = useMemo(
|
|
44
54
|
() => ({
|
|
45
55
|
companyWide: state,
|
|
46
|
-
//
|
|
47
|
-
updateCompanywide:
|
|
56
|
+
// Returns no-op if CWE JSON is not in use on the current slide
|
|
57
|
+
updateCompanywide: cweJsonExists ? updateField : () => {},
|
|
48
58
|
}),
|
|
49
|
-
[state],
|
|
59
|
+
[cweJsonExists, state],
|
|
50
60
|
);
|
|
51
61
|
|
|
52
62
|
return (
|
|
53
63
|
<CompanywideJSONContext.Provider value={providerValues}>
|
|
54
|
-
{
|
|
64
|
+
{cweJsonExists && (
|
|
55
65
|
<div
|
|
56
66
|
data-companywide-editable={editableKey}
|
|
57
67
|
ref={editableRef}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { useModes } from "./use-modes";
|
|
4
|
+
import { useSlide } from "./use-slide";
|
|
5
|
+
import { useEditableFieldKey } from "./use-editable-field-key";
|
|
6
|
+
import { getCWEData, getUserTemplateData } from "../utils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns information about a CWE, PresoManager template or user template editable
|
|
10
|
+
* on the current slide. Returns a modified key when the requested editable is found
|
|
11
|
+
* on a user or PM template.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* useCWEEditable("test");
|
|
16
|
+
* => {
|
|
17
|
+
* key: "test-adjunct-1168",
|
|
18
|
+
* value: "User edited text",
|
|
19
|
+
* hasValue: true
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export function useCWEEditableInfo(id) {
|
|
23
|
+
const { isPresomanager } = useModes();
|
|
24
|
+
const { slideID, isUserTemplate } = useSlide();
|
|
25
|
+
|
|
26
|
+
const key = useEditableFieldKey(id);
|
|
27
|
+
|
|
28
|
+
const getValue = useCallback(() => {
|
|
29
|
+
let data;
|
|
30
|
+
|
|
31
|
+
if (isUserTemplate) {
|
|
32
|
+
data = getUserTemplateData(key, slideID);
|
|
33
|
+
} else {
|
|
34
|
+
data = getCWEData(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return data?.value || data?.accepted?.value || data?.saved?.value || null;
|
|
38
|
+
}, [key, slideID, isUserTemplate]);
|
|
39
|
+
|
|
40
|
+
const [value, setValue] = useState(getValue);
|
|
41
|
+
|
|
42
|
+
function updateValue() {
|
|
43
|
+
const newValue = getValue();
|
|
44
|
+
|
|
45
|
+
if (value === newValue) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setValue(newValue);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (isPresomanager) return;
|
|
54
|
+
|
|
55
|
+
function onContextChange() {
|
|
56
|
+
updateValue();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Bridge.presenter.getPresentation().on("change:context", onContextChange);
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
Bridge.presenter.getPresentation().off("change:context", onContextChange);
|
|
63
|
+
};
|
|
64
|
+
}, [isPresomanager, value, getValue]);
|
|
65
|
+
|
|
66
|
+
// When in Presomanager we cannot use a state (nothing we can watch - yet),
|
|
67
|
+
// in this mode, the latest saved value can be fetched on re-render.
|
|
68
|
+
return {
|
|
69
|
+
key,
|
|
70
|
+
value: isPresomanager ? getValue() : value,
|
|
71
|
+
hasValue: (isPresomanager ? getValue() : value) !== null,
|
|
72
|
+
updateValue,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the current value of a CWE editable on the current slide.
|
|
78
|
+
* (standard slide, PresoManager template or user template)
|
|
79
|
+
*/
|
|
80
|
+
export function useCWEEditableValue(id, defaultValue = null) {
|
|
81
|
+
return useCWEEditableInfo(id).value ?? defaultValue;
|
|
82
|
+
}
|
package/lib/hooks/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export { useCompanywide } from "./use-companywide.js";
|
|
|
7
7
|
export { useSlide } from "./use-slide.js";
|
|
8
8
|
export { useTransitions } from "./use-transitions.js";
|
|
9
9
|
export { useSubslides } from "./use-subslides.js";
|
|
10
|
-
export { usePrepEditable } from "./use-prep-editable.js";
|
|
11
10
|
export { useSlideDone } from "./use-slide-done.js";
|
|
11
|
+
export { useEditableFieldKey } from "./use-editable-field-key.js";
|
|
12
12
|
export { useEditableInitialState } from "./use-editable-initial-state.js";
|
|
13
|
+
export { usePrepEditableInfo, usePrepEditableValue } from "./prep-editable.js";
|
|
14
|
+
export { useCWEEditableInfo, useCWEEditableValue } from "./cwe-editable.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { useModes } from "./use-modes";
|
|
4
|
+
import { useSlide } from "./use-slide";
|
|
5
|
+
import { useEditableFieldKey } from "./use-editable-field-key";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns information about a prep editable on the current slide.
|
|
9
|
+
*
|
|
10
|
+
* If the prep editable field is found on a user or PM template, the key
|
|
11
|
+
* will be adjusted to match the required format.
|
|
12
|
+
*
|
|
13
|
+
* Example:
|
|
14
|
+
*
|
|
15
|
+
* usePrepEditable("test");
|
|
16
|
+
* => {
|
|
17
|
+
* key: "test",
|
|
18
|
+
* value: "User edited text",
|
|
19
|
+
* hasValue: true
|
|
20
|
+
* }
|
|
21
|
+
*/
|
|
22
|
+
export function usePrepEditableInfo(id) {
|
|
23
|
+
const { isPresomanager } = useModes();
|
|
24
|
+
const { slideID } = useSlide();
|
|
25
|
+
|
|
26
|
+
const key = useEditableFieldKey(id, { isPrep: true });
|
|
27
|
+
|
|
28
|
+
const prepKey = `${slideID}--${key}`;
|
|
29
|
+
const keyPath = `_editableContent.${prepKey}.value`;
|
|
30
|
+
|
|
31
|
+
const getValue = useCallback(() => {
|
|
32
|
+
return Bridge.Context.get(keyPath, null);
|
|
33
|
+
}, [keyPath]);
|
|
34
|
+
|
|
35
|
+
const [value, setValue] = useState(getValue());
|
|
36
|
+
|
|
37
|
+
function updateValue() {
|
|
38
|
+
const newValue = getValue();
|
|
39
|
+
|
|
40
|
+
if (value === newValue) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setValue(newValue);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (isPresomanager) return;
|
|
49
|
+
|
|
50
|
+
function onContextChange() {
|
|
51
|
+
updateValue();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Bridge.presenter.getPresentation().on("change:context", onContextChange);
|
|
55
|
+
|
|
56
|
+
return () => {
|
|
57
|
+
Bridge.presenter.getPresentation().off("change:context", onContextChange);
|
|
58
|
+
};
|
|
59
|
+
}, [isPresomanager, value, getValue]);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
key,
|
|
63
|
+
value: value,
|
|
64
|
+
hasValue: value !== null,
|
|
65
|
+
updateValue,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Returns the current value of a prep editable on the current slide.
|
|
71
|
+
*/
|
|
72
|
+
export function usePrepEditableValue(id, defaultValue = null) {
|
|
73
|
+
return usePrepEditableInfo(id).value ?? defaultValue;
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useSlide } from "./use-slide.js";
|
|
2
|
+
import { getPMTemplateFieldKey, getUserTemplateFieldKey } from "../utils.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Takes a base field key, and returns a modified field key depending on the slide type
|
|
6
|
+
* (ie. standard, user template or presomanager template).
|
|
7
|
+
*
|
|
8
|
+
* @param {string} key - The base key of the target field.
|
|
9
|
+
* @returns {string} - The field key modified depending on the slide type.
|
|
10
|
+
*/
|
|
11
|
+
export function useEditableFieldKey(key) {
|
|
12
|
+
const { slideID, isPMTemplate, isUserTemplate } = useSlide();
|
|
13
|
+
const presomanagerTemplateKey = getPMTemplateFieldKey(key, slideID);
|
|
14
|
+
const userTemplateKey = getUserTemplateFieldKey(key, slideID);
|
|
15
|
+
|
|
16
|
+
if (isUserTemplate) return userTemplateKey;
|
|
17
|
+
if (isPMTemplate) return presomanagerTemplateKey;
|
|
18
|
+
return key;
|
|
19
|
+
}
|
|
@@ -1,128 +1,33 @@
|
|
|
1
|
-
import { CWE_JSON_KEY } from "../constants.js";
|
|
2
1
|
import { useSlide } from "./use-slide.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function getSlideNumericID() {
|
|
6
|
-
const { slideID } = useSlide();
|
|
7
|
-
const numericRegex = /-(\d+)(?:-temp)*$/;
|
|
8
|
-
return slideID.match(numericRegex)?.[1];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Constructs a user template field key based on the provided key and slide details.
|
|
13
|
-
*
|
|
14
|
-
* Note: field keys are prefixed with the slide ID when saved to the Context (_userTemplateCMSvals)
|
|
15
|
-
* however they are not prefixed when used for the data-companywide-editable attribute.
|
|
16
|
-
*
|
|
17
|
-
* Slide ID variations:
|
|
18
|
-
* saved user template: adjunct-template-slide-415
|
|
19
|
-
* unsaved user template: adjunct-template-slide-tempkey-1168
|
|
20
|
-
*
|
|
21
|
-
* Constructed field keys:
|
|
22
|
-
* saved user template: slideID--key-tempkey-415
|
|
23
|
-
* unsaved user template: slideID--key-adjunct-1168
|
|
24
|
-
*
|
|
25
|
-
* @param {string} key - The base key of the target field.
|
|
26
|
-
* @param {boolean} options.isUserCMSVals - If true, prefix the returned key with the slide ID.
|
|
27
|
-
* @returns {string} - The constructed field key for the user template.
|
|
28
|
-
*/
|
|
29
|
-
function getUserTemplateFieldKey(key, { isUserCMSVals = false } = {}) {
|
|
30
|
-
const { slideID } = useSlide();
|
|
31
|
-
const slideNumericID = getSlideNumericID();
|
|
32
|
-
const isUnsavedTemplate = slideID.indexOf("-tempkey") > -1;
|
|
33
|
-
let fieldKey = key;
|
|
34
|
-
|
|
35
|
-
// Add slideID prefix if requested and not included in key
|
|
36
|
-
if (isUserCMSVals && !key.startsWith(`${slideID}--`)) {
|
|
37
|
-
fieldKey = `${slideID}--${key}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// unsaved user template adds all this on the end
|
|
41
|
-
if (isUnsavedTemplate) {
|
|
42
|
-
return `${fieldKey}-tempkey-${slideNumericID}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return `${fieldKey}-adjunct-${slideNumericID}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getUserTemplateData(fieldKey) {
|
|
49
|
-
const userValues = Bridge.Context.getDict()._userTemplateCMSvals;
|
|
50
|
-
return (
|
|
51
|
-
Object.values(userValues || {})?.find?.((vals) => vals.key === fieldKey) ||
|
|
52
|
-
{}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Constructs a PM template field key based on the provided key and slide details.
|
|
58
|
-
*
|
|
59
|
-
* Slide ID variations:
|
|
60
|
-
* saved PM template: template-slide-11
|
|
61
|
-
* unsaved PM template: template-slide-1120-temp
|
|
62
|
-
*
|
|
63
|
-
* Constructed field keys:
|
|
64
|
-
* saved PM template: key-autoadjunct-11
|
|
65
|
-
* unsaved PM template: key-autoadjunct-1120-temp
|
|
66
|
-
*
|
|
67
|
-
* @param {string} key - The base key of the target field.
|
|
68
|
-
* @returns {string} - The constructed field key for the PM template.
|
|
69
|
-
*/
|
|
70
|
-
function getPMTemplateFieldKey(key) {
|
|
71
|
-
const { slideID, slideKey } = useSlide();
|
|
72
|
-
const isCWEJSON = key.endsWith(CWE_JSON_KEY);
|
|
73
|
-
const slideNumericID = getSlideNumericID();
|
|
74
|
-
// example: image_plus_text_columns-options-autoadjunct-767-temp
|
|
75
|
-
const isUnsavedTemplate = slideID.indexOf("-temp") > -1;
|
|
76
|
-
// "template-" is added to the start of the slideKey of PM templates
|
|
77
|
-
// this is not included in CWE field keys and needs to be removed if
|
|
78
|
-
// slideKey was used to generate the field key request.
|
|
79
|
-
// NOTE: CWE JSON field keys require the "template-" prefix
|
|
80
|
-
const fieldKey =
|
|
81
|
-
!isCWEJSON && key.startsWith(slideKey) && key.startsWith("template-")
|
|
82
|
-
? key.replace("template-", "")
|
|
83
|
-
: key;
|
|
84
|
-
|
|
85
|
-
if (isUnsavedTemplate) {
|
|
86
|
-
return `${fieldKey}-autoadjunct-${slideNumericID}-temp`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return `${fieldKey}-autoadjunct-${slideNumericID}`;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function getCWEData(fieldKey) {
|
|
93
|
-
// PM template or standard slide companywide editable field
|
|
94
|
-
const cweVals = Bridge.Companywide.getWithKeys([fieldKey]);
|
|
95
|
-
return cweVals.find((vals) => vals.key === fieldKey) || {};
|
|
96
|
-
}
|
|
2
|
+
import { useEditableFieldKey } from "./use-editable-field-key.js";
|
|
3
|
+
import { getCWEData, getUserTemplateData } from "../utils.js";
|
|
97
4
|
|
|
98
5
|
/**
|
|
99
6
|
* Retrieves the key and value of a requested slide CWE, PM template or user template field.
|
|
100
7
|
* Adjusts the field key as required for user and PM templates.
|
|
101
8
|
*
|
|
9
|
+
* Note: This hook is not tied to a state, as such it will not update when changes are made
|
|
10
|
+
* to the requested editable field. This hook will only return a new value when re-run.
|
|
11
|
+
*
|
|
102
12
|
* @param {string} key - The base key of the field to retrieve.
|
|
103
13
|
* @param {string} [defaultValue=''] - The default value to use if the field is not found.
|
|
104
14
|
* @returns {Array} - An array containing the value of the field and the adjusted field key.
|
|
105
15
|
*/
|
|
106
|
-
export function useEditableInitialState(
|
|
107
|
-
const {
|
|
108
|
-
|
|
16
|
+
export function useEditableInitialState(id, defaultValue = "") {
|
|
17
|
+
const { slideID, isUserTemplate } = useSlide();
|
|
18
|
+
|
|
19
|
+
const key = useEditableFieldKey(id);
|
|
20
|
+
|
|
109
21
|
let data;
|
|
110
22
|
|
|
111
23
|
if (isUserTemplate) {
|
|
112
|
-
|
|
113
|
-
const dataKey = getUserTemplateFieldKey(key, {
|
|
114
|
-
isUserCMSVals: true,
|
|
115
|
-
});
|
|
116
|
-
data = getUserTemplateData(dataKey);
|
|
117
|
-
} else if (isPMTemplate) {
|
|
118
|
-
fieldKey = getPMTemplateFieldKey(key);
|
|
119
|
-
data = getCWEData(fieldKey);
|
|
24
|
+
data = getUserTemplateData(key, slideID);
|
|
120
25
|
} else {
|
|
121
|
-
data = getCWEData(
|
|
26
|
+
data = getCWEData(key);
|
|
122
27
|
}
|
|
123
28
|
|
|
124
29
|
const value =
|
|
125
30
|
data?.value || data?.accepted?.value || data?.saved?.value || defaultValue;
|
|
126
31
|
|
|
127
|
-
return [value,
|
|
32
|
+
return [value, key];
|
|
128
33
|
}
|
package/lib/hooks/use-modes.js
CHANGED
|
@@ -12,7 +12,10 @@ export function useModes() {
|
|
|
12
12
|
const isPreview = bodyClasses.includes("preview");
|
|
13
13
|
const isPresent = bodyClasses.includes("present");
|
|
14
14
|
const isReview = bodyClasses.includes("review");
|
|
15
|
-
|
|
15
|
+
// Editing user templates in prep results in both the 'preview' and 'edit-mode'
|
|
16
|
+
// classes being added to the body. In order to detect if we are truly on the
|
|
17
|
+
// PresoManager page in the app, we need to ignore the 'preview' class.
|
|
18
|
+
const isPresomanager = bodyClasses.includes("edit-mode") && !isPreview;
|
|
16
19
|
const isEmptyPreview = bodyClasses.includes("empty-preview");
|
|
17
20
|
const isRemote = isOnline && isClient && !isShareOnline;
|
|
18
21
|
const isCdk = typeof window.__cdk_version__ !== "undefined";
|