@livepreso/content-react 0.0.2 → 0.1.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "../../content/content-react": "../../content/content-react:cklG8HGZMCD4xcvDWwkIseCBlSaZo+2oxATz93QU/k4=:",
2
+ "../../content/content-react": "../../content/content-react:DyqLgzfL3vk7OCJ/PyEiYCLeOAqS6ZdVtM6kgjFrYgk=:",
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==",
@@ -93,12 +93,14 @@
93
93
  "/kurly/2.0.0-beta.3": "sha512-WXSRkhL2VV9lI/sPomBDV9Xf4oQ1s/RiUqzxKt4slkG7ndCxcDfXJ2ZXdxEYDRfevnkSOxmiVX3etunBlHqTAw==",
94
94
  "/lodash.get/4.4.2": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=",
95
95
  "/lodash.isplainobject/4.0.6": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=",
96
+ "/lodash.set/4.3.2": "sha512-4hNPN5jlm/N/HLMCO43v8BXKq9Z7QdAGc/VGrRD61w8gN9g/6jF9A4L1pbUgBLCffi0w9VsXfTOij5x8iTyFvg==",
97
+ "/lodash.unescape/4.0.1": "sha512-DhhGRshNS1aX6s5YdBE3njCCouPgnG29ebyHvImlZzXZf2SHgt+J08DHgytTPnpywNbO1Y8mNUFyQuIDBq2JZg==",
96
98
  "/loose-envify/1.4.0": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
97
99
  "/lru-cache/6.0.0": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
98
100
  "/merge2/1.4.1": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==",
99
101
  "/micromatch/4.0.4": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==",
100
102
  "/ms/2.1.2": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
101
- "/object-assign/4.1.1": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
103
+ "/object-assign/4.1.1": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
102
104
  "/object-inspect/1.12.0": "sha512-Ho2z80bVIvJloH+YzRmpZVQe87+qASmBUKZDWgx9cu+KDrX2ZDH/3tMy+gXbZETVGs2M8YdxObOh7XAtim9Y0g==",
103
105
  "/object-keys/1.1.1": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==",
104
106
  "/object.assign/4.1.2": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==",
package/CHANGELOG.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "@livepreso/content-react",
3
3
  "entries": [
4
+ {
5
+ "version": "0.1.0",
6
+ "tag": "@livepreso/content-react_v0.1.0",
7
+ "date": "Tue, 28 Jun 2022 23:37:28 GMT",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "comment": "Add support for companywide json"
12
+ }
13
+ ]
14
+ }
15
+ },
4
16
  {
5
17
  "version": "0.0.2",
6
18
  "tag": "@livepreso/content-react_v0.0.2",
package/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Change Log - @livepreso/content-react
2
2
 
3
- This log was last generated on Wed, 01 Jun 2022 00:56:50 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 28 Jun 2022 23:37:28 GMT and should not be manually modified.
4
+
5
+ ## 0.1.0
6
+ Tue, 28 Jun 2022 23:37:28 GMT
7
+
8
+ ### Minor changes
9
+
10
+ - Add support for companywide json
4
11
 
5
12
  ## 0.0.2
6
13
  Wed, 01 Jun 2022 00:55:51 GMT
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect } from "react";
2
2
 
3
3
  import { AppBase } from "@livepreso/content-base";
4
+ import { CompanywideJSON } from "./lib/components/CompanywideJSON.js";
4
5
  import ReactDOM from "react-dom";
5
6
  import { SlideContext } from "./lib/contexts.js";
6
7
  import errorFn from "@livepreso/content-base/error.js";
@@ -58,7 +59,9 @@ export class App extends AppBase {
58
59
  return (
59
60
  <SlideContext.Provider value={slideState}>
60
61
  {!slideState.transitions.exited && (
61
- <ErrorBoundary el={el}>{RootApp}</ErrorBoundary>
62
+ <ErrorBoundary el={el}>
63
+ <CompanywideJSON>{RootApp}</CompanywideJSON>
64
+ </ErrorBoundary>
62
65
  )}
63
66
  </SlideContext.Provider>
64
67
  );
@@ -0,0 +1,73 @@
1
+ import { CompanywideJSONContext } from "../contexts.js";
2
+ import React, { useMemo, useRef, useState } from "react";
3
+
4
+ import unescape from "lodash.unescape";
5
+
6
+ export function CompanywideJSON({ children }) {
7
+ const cweJsonKey = "cwe-json"
8
+ const editableRef = useRef();
9
+
10
+ const editableName = window.Bridge.Companywide?.getSlideKeysForArticle?.()?.find(
11
+ (s) => s.includes(cweJsonKey)
12
+ );
13
+
14
+ let initialState = {};
15
+
16
+ try {
17
+ const result = window.Bridge.Companywide.getWithKeys([editableName]);
18
+ const data = result[0];
19
+
20
+ initialState = JSON.parse(
21
+ unescape(
22
+ data?.value || data?.accepted?.value || data?.saved?.value || "{}"
23
+ )
24
+ );
25
+ } catch (e) {
26
+ console.error(e);
27
+ // Failed to parse json
28
+ }
29
+
30
+ const [state, setState] = useState(initialState);
31
+
32
+ function updateField(json) {
33
+ setState(json);
34
+
35
+ const currEl = document.activeElement;
36
+
37
+ setTimeout(() => {
38
+ editableRef.current.focus();
39
+ if (currEl) {
40
+ currEl.focus();
41
+ }
42
+ }, 0);
43
+ }
44
+
45
+ const providerValues = useMemo(
46
+ () => ({
47
+ companyWide: state,
48
+ // If not editable, we just pass a no-op function
49
+ updateCompanywide: editableName ? updateField : () => {},
50
+ }),
51
+ [state]
52
+ );
53
+
54
+ return (
55
+ <CompanywideJSONContext.Provider value={providerValues}>
56
+ {editableName && (
57
+ <div
58
+ data-companywide-editable={editableName}
59
+ ref={editableRef}
60
+ tabIndex={-1}
61
+ style={{
62
+ position: "absolute",
63
+ top: -1000,
64
+ left: -1000,
65
+ }}
66
+ >
67
+ {JSON.stringify(state)}
68
+ </div>
69
+ )}
70
+ {children}
71
+ </CompanywideJSONContext.Provider>
72
+ );
73
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./Subslide.js";
2
2
  export * from "./Subslides.js";
3
3
  export * from "./ScrollableArea.js";
4
+ export * from "./CompanywideJSON.js";
package/lib/contexts.js CHANGED
@@ -1,20 +1,24 @@
1
1
  import React from "react";
2
2
 
3
3
  export const SlideContext = React.createContext({
4
- transitions: null,
5
- slideKey: null,
6
- isCurrentSlide: false,
4
+ transitions: null,
5
+ slideKey: null,
6
+ isCurrentSlide: false,
7
7
  });
8
8
 
9
9
  export const SubslidesContext = React.createContext({
10
- animating: {
11
- up: false,
12
- down: false
13
- }
10
+ animating: {
11
+ up: false,
12
+ down: false,
13
+ },
14
14
  });
15
15
 
16
16
  export const SubslideContext = React.createContext({
17
- transitions: null,
18
- isActive: false
17
+ transitions: null,
18
+ isActive: false,
19
19
  });
20
20
 
21
+ export const CompanywideJSONContext = React.createContext({
22
+ companyWide: {},
23
+ updateCompanywide: () => {},
24
+ });
@@ -2,5 +2,7 @@ export * from "./use-shared-state.js";
2
2
  export * from "./use-async-reference.js";
3
3
  export * from "./use-modes.js";
4
4
  export * from "./use-context.js";
5
+ export * from "./use-companywide.js";
6
+ export * from "./use-slide.js";
5
7
  export * from "./use-transitions.js";
6
8
  export * from "./use-subslides.js";
@@ -0,0 +1,22 @@
1
+ import { CompanywideJSONContext } from "../contexts.js";
2
+ import get from "lodash.get";
3
+ import set from "lodash.set";
4
+ import { useContext } from "react";
5
+
6
+ export function useCompanywide(cwePath, defaultValue) {
7
+ if (!cwePath) {
8
+ throw new Error("Must include a path for useCompanywide hook");
9
+ }
10
+
11
+ const { companyWide, updateCompanywide } = useContext(CompanywideJSONContext);
12
+
13
+ const value = get(companyWide, cwePath, defaultValue);
14
+
15
+ function update(val) {
16
+ const obj = { ...(companyWide || {}) };
17
+ set(obj, cwePath, val);
18
+ updateCompanywide(obj);
19
+ }
20
+
21
+ return [value, update];
22
+ }
@@ -7,6 +7,7 @@ export function useModes() {
7
7
  const isScreenshot = bodyClasses.includes("screenshot");
8
8
  const isShareOnline = bodyClasses.includes("share_online");
9
9
  const isPreview = bodyClasses.includes("preview");
10
+ const isPresomanager = bodyClasses.includes("edit-mode");
10
11
  const isRemote = isOnline && isClient && !isShareOnline;
11
12
 
12
13
  return {
@@ -16,5 +17,6 @@ export function useModes() {
16
17
  isRemote,
17
18
  isScreenshot,
18
19
  isPreview,
20
+ isPresomanager,
19
21
  };
20
22
  }
@@ -0,0 +1,6 @@
1
+ import { SlideContext } from "../contexts.js";
2
+ import { useContext } from "react";
3
+
4
+ export function useSlide() {
5
+ return useContext(SlideContext);
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livepreso/content-react",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -20,7 +20,9 @@
20
20
  "@livepreso/content-base": "~0.0.2",
21
21
  "ulog": "~2.0.0-beta.18",
22
22
  "lodash.get": "~4.4.2",
23
- "lodash.isplainobject": "~4.0.6"
23
+ "lodash.isplainobject": "~4.0.6",
24
+ "lodash.set": "~4.3.2",
25
+ "lodash.unescape": "~4.0.1"
24
26
  },
25
27
  "scripts": {
26
28
  "build": ""