@livepreso/content-react 0.3.8 → 0.4.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/shrinkwrap-deps.json +1 -1
- package/CHANGELOG.json +24 -0
- package/CHANGELOG.md +15 -1
- package/index.js +22 -8
- package/lib/components/CompanywideJSON.js +14 -24
- package/lib/constants.js +1 -0
- package/lib/contexts.js +3 -0
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/use-editable-initial-state.js +113 -0
- package/lib/hooks/use-prep-editable.js +2 -0
- package/lib/hooks/use-root-slide.js +5 -1
- package/lib/hooks/use-slide.js +16 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"../../content/content-react": "../../content/content-react:
|
|
2
|
+
"../../content/content-react": "../../content/content-react:EzqiqRduP5X0d1LxP9lAJ1h2NzQwqXXZ5qngKBr1MMQ=:",
|
|
3
3
|
"/@babel/helper-annotate-as-pure/7.16.7": "sha512-s6t2w/IPQVTAET1HitoowRGXooX8mCgtuP5195wD/QJPV6wYjpujCGF7JuMODVX2ZAJOf1GT6DT9MHEZvLOFSw==",
|
|
4
4
|
"/@babel/helper-module-imports/7.16.7": "sha512-LVtS6TqjJHFc+nYeITRo6VLXve70xmq7wPhWTqDJusJEgGmkAACWwMiTNrvfoQo6hEhFwAIixNkvB0jPXDL8Wg==",
|
|
5
5
|
"/@babel/helper-plugin-utils/7.16.7": "sha512-Qg3Nk7ZxpgMrsox6HreY1ZNKdBq7K72tDSliA6dCl5f007jR4ne8iD5UzuNnCJH2xBf2BEEVGr+/OL6Gdp7RxA==",
|
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livepreso/content-react",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.4.0",
|
|
6
|
+
"tag": "@livepreso/content-react_v0.4.0",
|
|
7
|
+
"date": "Tue, 24 Sep 2024 03:37:23 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Allow overriding react errors"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.3.9",
|
|
18
|
+
"tag": "@livepreso/content-react_v0.3.9",
|
|
19
|
+
"date": "Fri, 23 Aug 2024 05:02:46 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"patch": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Company wide editables fixes"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
4
28
|
{
|
|
5
29
|
"version": "0.3.8",
|
|
6
30
|
"tag": "@livepreso/content-react_v0.3.8",
|
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 Tue, 24 Sep 2024 03:37:23 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.4.0
|
|
6
|
+
Tue, 24 Sep 2024 03:37:23 GMT
|
|
7
|
+
|
|
8
|
+
### Minor changes
|
|
9
|
+
|
|
10
|
+
- Allow overriding react errors
|
|
11
|
+
|
|
12
|
+
## 0.3.9
|
|
13
|
+
Fri, 23 Aug 2024 05:02:46 GMT
|
|
14
|
+
|
|
15
|
+
### Patches
|
|
16
|
+
|
|
17
|
+
- Company wide editables fixes
|
|
4
18
|
|
|
5
19
|
## 0.3.8
|
|
6
20
|
Wed, 24 Jul 2024 06:53:26 GMT
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect } from "react";
|
|
1
|
+
import React, { useContext, useEffect, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
import { AppBase } from "@livepreso/content-base";
|
|
4
4
|
import { CompanywideJSON } from "./lib/components/CompanywideJSON.js";
|
|
@@ -7,6 +7,18 @@ import { createRoot } from "react-dom/client";
|
|
|
7
7
|
import errorFn from "@livepreso/content-base/error.js";
|
|
8
8
|
import { useRootSlide } from "./lib/hooks/use-root-slide.js";
|
|
9
9
|
|
|
10
|
+
function DefaultErrorComponent({ error }) {
|
|
11
|
+
const slideContext = useContext(SlideContext);
|
|
12
|
+
const ref = useRef();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const errorRenderer = errorFn(error);
|
|
16
|
+
errorRenderer(ref.current, slideContext.slideKey);
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
return <div ref={ref} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
class ErrorBoundary extends React.Component {
|
|
11
23
|
static getDerivedStateFromError(error) {
|
|
12
24
|
return { error, hasError: true };
|
|
@@ -19,8 +31,8 @@ class ErrorBoundary extends React.Component {
|
|
|
19
31
|
|
|
20
32
|
render() {
|
|
21
33
|
if (this.state.hasError) {
|
|
22
|
-
|
|
23
|
-
return
|
|
34
|
+
const ErrorComponent = this.props.errorComponent;
|
|
35
|
+
return <ErrorComponent error={this.state.error} />;
|
|
24
36
|
}
|
|
25
37
|
return this.props.children;
|
|
26
38
|
}
|
|
@@ -31,6 +43,8 @@ if (module.hot && typeof window.__deck_roots__ === "undefined") {
|
|
|
31
43
|
}
|
|
32
44
|
|
|
33
45
|
export class App extends AppBase {
|
|
46
|
+
// can be overridden in subclass
|
|
47
|
+
errorComponent = DefaultErrorComponent;
|
|
34
48
|
static run(rootApp = null) {
|
|
35
49
|
const base = new App();
|
|
36
50
|
if (rootApp) {
|
|
@@ -57,8 +71,7 @@ export class App extends AppBase {
|
|
|
57
71
|
}
|
|
58
72
|
|
|
59
73
|
const RootApp = this.rootApp(Slide);
|
|
60
|
-
|
|
61
|
-
function App() {
|
|
74
|
+
const AppComponent = () => {
|
|
62
75
|
// TODO: Refactor this to be a prop
|
|
63
76
|
const slideState = useRootSlide(article);
|
|
64
77
|
|
|
@@ -80,15 +93,16 @@ export class App extends AppBase {
|
|
|
80
93
|
return (
|
|
81
94
|
<SlideContext.Provider value={slideState}>
|
|
82
95
|
{!slideState.transitions.exited && (
|
|
83
|
-
|
|
96
|
+
// eslint-disable-next-line react/no-this-in-sfc
|
|
97
|
+
<ErrorBoundary errorComponent={this.errorComponent}>
|
|
84
98
|
<CompanywideJSON>{RootApp}</CompanywideJSON>
|
|
85
99
|
</ErrorBoundary>
|
|
86
100
|
)}
|
|
87
101
|
</SlideContext.Provider>
|
|
88
102
|
);
|
|
89
|
-
}
|
|
103
|
+
};
|
|
90
104
|
|
|
91
|
-
root.render(<
|
|
105
|
+
root.render(<AppComponent />);
|
|
92
106
|
}
|
|
93
107
|
|
|
94
108
|
unmountRoot(key) {
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
import { CompanywideJSONContext } from "../contexts.js";
|
|
2
1
|
import React, { useMemo, useRef, useState } from "react";
|
|
3
2
|
|
|
3
|
+
import { CWE_JSON_KEY } from "../constants.js";
|
|
4
|
+
import { CompanywideJSONContext } from "../contexts.js";
|
|
4
5
|
import unescape from "lodash.unescape";
|
|
6
|
+
import { useEditableInitialState } from "../hooks/use-editable-initial-state.js";
|
|
7
|
+
import { useSlide } from "../hooks/use-slide.js";
|
|
5
8
|
|
|
6
9
|
export function CompanywideJSON({ children }) {
|
|
7
|
-
const
|
|
10
|
+
const { slideKey } = useSlide();
|
|
8
11
|
const editableRef = useRef();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const [editableValue, editableName] = useEditableInitialState(
|
|
13
|
+
`${slideKey}-${CWE_JSON_KEY}`,
|
|
14
|
+
"{}"
|
|
12
15
|
);
|
|
13
16
|
|
|
14
17
|
let initialState = {};
|
|
15
18
|
|
|
16
19
|
try {
|
|
17
|
-
|
|
18
|
-
const data = result[0];
|
|
19
|
-
|
|
20
|
-
initialState = JSON.parse(
|
|
21
|
-
unescape(
|
|
22
|
-
data?.value || data?.accepted?.value || data?.saved?.value || "{}"
|
|
23
|
-
)
|
|
24
|
-
);
|
|
20
|
+
initialState = JSON.parse(unescape(editableValue));
|
|
25
21
|
} catch (e) {
|
|
22
|
+
/* eslint-disable-next-line no-console */
|
|
26
23
|
console.error(e);
|
|
27
24
|
// Failed to parse json
|
|
28
25
|
}
|
|
@@ -30,15 +27,10 @@ export function CompanywideJSON({ children }) {
|
|
|
30
27
|
const [state, setState] = useState(initialState);
|
|
31
28
|
|
|
32
29
|
function updateField(json) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const currEl = document.activeElement;
|
|
36
|
-
|
|
30
|
+
window.$(editableRef.current).text(JSON.stringify(json));
|
|
31
|
+
window.$(editableRef.current).trigger("save");
|
|
37
32
|
setTimeout(() => {
|
|
38
|
-
|
|
39
|
-
if (currEl) {
|
|
40
|
-
currEl.focus();
|
|
41
|
-
}
|
|
33
|
+
setState(json);
|
|
42
34
|
}, 0);
|
|
43
35
|
}
|
|
44
36
|
|
|
@@ -63,9 +55,7 @@ export function CompanywideJSON({ children }) {
|
|
|
63
55
|
top: -1000,
|
|
64
56
|
left: -1000,
|
|
65
57
|
}}
|
|
66
|
-
|
|
67
|
-
{JSON.stringify(state)}
|
|
68
|
-
</div>
|
|
58
|
+
/>
|
|
69
59
|
)}
|
|
70
60
|
{children}
|
|
71
61
|
</CompanywideJSONContext.Provider>
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CWE_JSON_KEY = "cwe-json";
|
package/lib/contexts.js
CHANGED
|
@@ -2,8 +2,11 @@ import React from "react";
|
|
|
2
2
|
|
|
3
3
|
export const SlideContext = React.createContext({
|
|
4
4
|
transitions: null,
|
|
5
|
+
slideID: null,
|
|
5
6
|
slideKey: null,
|
|
6
7
|
isCurrentSlide: false,
|
|
8
|
+
isUserTemplate: false,
|
|
9
|
+
isPMTemplate: false,
|
|
7
10
|
});
|
|
8
11
|
|
|
9
12
|
export const SubslidesContext = React.createContext({
|
package/lib/hooks/index.js
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { CWE_JSON_KEY } from "../constants.js";
|
|
2
|
+
import { useSlide } from "./use-slide.js";
|
|
3
|
+
|
|
4
|
+
// captures all the digits within the slide name, prefaced by a hyphen and optional trailed by -temp
|
|
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
|
+
* Slide ID variations:
|
|
15
|
+
* saved user template: adjunct-template-slide-415
|
|
16
|
+
* unsaved user template: adjunct-template-slide-tempkey-1168
|
|
17
|
+
*
|
|
18
|
+
* Constructed field keys:
|
|
19
|
+
* saved user template: slideID--key-tempkey-415
|
|
20
|
+
* unsaved user template: slideID--key-adjunct-1168
|
|
21
|
+
*
|
|
22
|
+
* @param {string} key - The base key of the target field.
|
|
23
|
+
* @returns {string} - The constructed field key for the user template.
|
|
24
|
+
*/
|
|
25
|
+
function getUserTemplateFieldKey(key) {
|
|
26
|
+
const { slideID } = useSlide();
|
|
27
|
+
const slideNumericID = getSlideNumericID();
|
|
28
|
+
const isUnsavedTemplate = slideID.indexOf("-tempkey") > -1;
|
|
29
|
+
const keyPrefix = `${slideID}--${key}`;
|
|
30
|
+
|
|
31
|
+
// unsaved user template adds all this on the end
|
|
32
|
+
if (isUnsavedTemplate) {
|
|
33
|
+
return `${keyPrefix}-tempkey-${slideNumericID}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return `${keyPrefix}-adjunct-${slideNumericID}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getUserTemplateData(fieldKey) {
|
|
40
|
+
const userValues = Bridge.Context.getDict()._userTemplateCMSvals;
|
|
41
|
+
return userValues?.find?.((vals) => vals.key === fieldKey) || {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a PM template field key based on the provided key and slide details.
|
|
46
|
+
*
|
|
47
|
+
* Slide ID variations:
|
|
48
|
+
* saved PM template: template-slide-11
|
|
49
|
+
* unsaved PM template: template-slide-1120-temp
|
|
50
|
+
*
|
|
51
|
+
* Constructed field keys:
|
|
52
|
+
* saved PM template: key-autoadjunct-11
|
|
53
|
+
* unsaved PM template: key-autoadjunct-1120-temp
|
|
54
|
+
*
|
|
55
|
+
* @param {string} key - The base key of the target field.
|
|
56
|
+
* @returns {string} - The constructed field key for the PM template.
|
|
57
|
+
*/
|
|
58
|
+
function getPMTemplateFieldKey(key) {
|
|
59
|
+
const { slideID, slideKey } = useSlide();
|
|
60
|
+
const isCWEJSON = key.endsWith(CWE_JSON_KEY);
|
|
61
|
+
const slideNumericID = getSlideNumericID();
|
|
62
|
+
// example: image_plus_text_columns-options-autoadjunct-767-temp
|
|
63
|
+
const isUnsavedTemplate = slideID.indexOf("-temp") > -1;
|
|
64
|
+
// "template-" is added to the start of the slideKey of PM templates
|
|
65
|
+
// this is not included in CWE field keys and needs to be removed if
|
|
66
|
+
// slideKey was used to generate the field key request.
|
|
67
|
+
// NOTE: CWE JSON field keys require the "template-" prefix
|
|
68
|
+
const fieldKey =
|
|
69
|
+
!isCWEJSON && key.startsWith(slideKey) && key.startsWith("template-")
|
|
70
|
+
? key.replace("template-", "")
|
|
71
|
+
: key;
|
|
72
|
+
|
|
73
|
+
if (isUnsavedTemplate) {
|
|
74
|
+
return `${fieldKey}-autoadjunct-${slideNumericID}-temp`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return `${fieldKey}-autoadjunct-${slideNumericID}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getCWEData(fieldKey) {
|
|
81
|
+
// PM template or standard slide companywide editable field
|
|
82
|
+
const cweVals = Bridge.Companywide.getWithKeys([fieldKey]);
|
|
83
|
+
return cweVals.find((vals) => vals.key === fieldKey) || {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves the key and value of a requested slide CWE, PM template or user template field.
|
|
88
|
+
* Adjusts the field key as required for user and PM templates.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} key - The base key of the field to retrieve.
|
|
91
|
+
* @param {string} [defaultValue=''] - The default value to use if the field is not found.
|
|
92
|
+
* @returns {Array} - An array containing the value of the field and the adjusted field key.
|
|
93
|
+
*/
|
|
94
|
+
export function useEditableInitialState(key, defaultValue = "") {
|
|
95
|
+
const { isUserTemplate, isPMTemplate } = useSlide();
|
|
96
|
+
let fieldKey = key;
|
|
97
|
+
let data;
|
|
98
|
+
|
|
99
|
+
if (isUserTemplate) {
|
|
100
|
+
fieldKey = getUserTemplateFieldKey(key);
|
|
101
|
+
data = getUserTemplateData(fieldKey);
|
|
102
|
+
} else if (isPMTemplate) {
|
|
103
|
+
fieldKey = getPMTemplateFieldKey(key);
|
|
104
|
+
data = getCWEData(fieldKey);
|
|
105
|
+
} else {
|
|
106
|
+
data = getCWEData(fieldKey);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const value =
|
|
110
|
+
data?.value || data?.accepted?.value || data?.saved?.value || defaultValue;
|
|
111
|
+
|
|
112
|
+
return [value, fieldKey];
|
|
113
|
+
}
|
|
@@ -17,6 +17,8 @@ import { useSlide } from "../hooks/use-slide";
|
|
|
17
17
|
export function usePrepEditable(id) {
|
|
18
18
|
const { slideKey } = useSlide();
|
|
19
19
|
|
|
20
|
+
// TODO: This won't work with user templates, and might
|
|
21
|
+
// have problems with PM templates too. Fix this.
|
|
20
22
|
const prepKey = `${slideKey}--${slideKey}-${id}`;
|
|
21
23
|
const keyPath = `_editableContent.${prepKey}.value`;
|
|
22
24
|
|
|
@@ -22,13 +22,14 @@ const DEFAULT_TRANSITION_STATE = {
|
|
|
22
22
|
*/
|
|
23
23
|
export function useRootSlide(article) {
|
|
24
24
|
const { isRemote, isClient, isMaster } = useModes();
|
|
25
|
+
const slideID = article.attr("id");
|
|
25
26
|
const key = article.data("slide-key");
|
|
26
27
|
const isCurrent = article.closest(".presoSlide").hasClass("current");
|
|
27
28
|
const [synced, setSynced] = useState(!isRemote);
|
|
28
29
|
const [internalSlideState, setInternalSlideState] = useAsyncReference({});
|
|
29
30
|
const [totalSubslides, setTotalSubslides] = useAsyncReference(0);
|
|
30
31
|
const [currentSubslide, setCurrentSubslide] = useAsyncReference(
|
|
31
|
-
totalSubslides ? 1 : null
|
|
32
|
+
totalSubslides ? 1 : null
|
|
32
33
|
);
|
|
33
34
|
const [subslideAnimating, setSubslideAnimating] = useAsyncReference({
|
|
34
35
|
up: false,
|
|
@@ -139,10 +140,13 @@ export function useRootSlide(article) {
|
|
|
139
140
|
return {
|
|
140
141
|
isSlideReady: slideReady,
|
|
141
142
|
transitions,
|
|
143
|
+
slideID,
|
|
142
144
|
slideKey: key,
|
|
143
145
|
isCurrentSlide: isCurrent,
|
|
144
146
|
doneRegister,
|
|
145
147
|
rootElement: article.get(0),
|
|
148
|
+
isUserTemplate: slideID.startsWith("adjunct-template-slide"),
|
|
149
|
+
isPMTemplate: slideID.startsWith("template-slide"),
|
|
146
150
|
|
|
147
151
|
registerSubslide: () => setTotalSubslides(totalSubslides.current + 1),
|
|
148
152
|
unregisterSubslide: () => setTotalSubslides(totalSubslides.current - 1),
|
package/lib/hooks/use-slide.js
CHANGED
|
@@ -3,14 +3,28 @@ import { useContext } from "react";
|
|
|
3
3
|
|
|
4
4
|
export function useSlide() {
|
|
5
5
|
const {
|
|
6
|
+
slideID,
|
|
6
7
|
slideKey,
|
|
7
8
|
isSlideReady,
|
|
8
9
|
doneRegister,
|
|
9
10
|
isCurrentSlide,
|
|
10
11
|
totalSubslides,
|
|
11
12
|
currentSubslide,
|
|
12
|
-
transitions
|
|
13
|
+
transitions,
|
|
14
|
+
isUserTemplate,
|
|
15
|
+
isPMTemplate,
|
|
13
16
|
} = useContext(SlideContext);
|
|
14
17
|
|
|
15
|
-
return {
|
|
18
|
+
return {
|
|
19
|
+
slideID,
|
|
20
|
+
slideKey,
|
|
21
|
+
isSlideReady,
|
|
22
|
+
doneRegister,
|
|
23
|
+
isCurrentSlide,
|
|
24
|
+
currentSubslide,
|
|
25
|
+
totalSubslides,
|
|
26
|
+
transitions,
|
|
27
|
+
isUserTemplate,
|
|
28
|
+
isPMTemplate,
|
|
29
|
+
};
|
|
16
30
|
}
|