@croct/plug-react 0.5.6 → 0.6.1

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/CroctProvider.js CHANGED
@@ -7,10 +7,15 @@ const react_1 = require("react");
7
7
  const ssr_polyfills_1 = require("./ssr-polyfills");
8
8
  exports.CroctContext = (0, react_1.createContext)(null);
9
9
  exports.CroctContext.displayName = 'CroctContext';
10
+ function useLiveRef(value) {
11
+ const ref = (0, react_1.useRef)(value);
12
+ ref.current = value;
13
+ return ref;
14
+ }
10
15
  const CroctProvider = (props) => {
11
16
  const { children, ...configuration } = props;
12
17
  const parent = (0, react_1.useContext)(exports.CroctContext);
13
- const initialConfiguration = (0, react_1.useRef)(configuration);
18
+ const baseConfiguration = useLiveRef(configuration);
14
19
  if (parent !== null) {
15
20
  throw new Error('You cannot render <CroctProvider> inside another <CroctProvider>. '
16
21
  + 'Croct should only be initialized once in the application.');
@@ -18,19 +23,28 @@ const CroctProvider = (props) => {
18
23
  const context = (0, react_1.useMemo)(() => ({
19
24
  get plug() {
20
25
  if (!ssr_polyfills_1.croct.initialized) {
21
- ssr_polyfills_1.croct.plug(initialConfiguration.current);
26
+ ssr_polyfills_1.croct.plug(baseConfiguration.current);
22
27
  }
23
- return ssr_polyfills_1.croct;
28
+ return new Proxy(ssr_polyfills_1.croct, {
29
+ get: function getProperty(target, property) {
30
+ if (property === 'plug') {
31
+ return (options) => {
32
+ ssr_polyfills_1.croct.plug({ ...baseConfiguration.current, ...options });
33
+ };
34
+ }
35
+ return target[property];
36
+ },
37
+ });
24
38
  },
25
- }), []);
39
+ }), [baseConfiguration]);
26
40
  (0, react_1.useEffect)(() => {
27
- ssr_polyfills_1.croct.plug(initialConfiguration.current);
41
+ ssr_polyfills_1.croct.plug(baseConfiguration.current);
28
42
  return () => {
29
43
  ssr_polyfills_1.croct.unplug().catch(() => {
30
44
  // Suppress errors.
31
45
  });
32
46
  };
33
- }, []);
47
+ }, [baseConfiguration]);
34
48
  return ((0, jsx_runtime_1.jsx)(exports.CroctContext.Provider, { value: context, children: children }));
35
49
  };
36
50
  exports.CroctProvider = CroctProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"CroctProvider.js","sourceRoot":"","sources":["src/CroctProvider.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;AAEb,iCASe;AAEf,mDAAsC;AAIzB,QAAA,YAAY,GAAG,IAAA,qBAAa,EAAoB,IAAI,CAAC,CAAC;AACnE,oBAAY,CAAC,WAAW,GAAG,cAAc,CAAC;AAEnC,MAAM,aAAa,GAA0C,CAAC,KAAK,EAAgB,EAAE;IACxF,MAAM,EAAC,QAAQ,EAAE,GAAG,aAAa,EAAC,GAAG,KAAK,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,oBAAY,CAAC,CAAC;IACxC,MAAM,oBAAoB,GAAG,IAAA,cAAM,EAAC,aAAa,CAAC,CAAC;IAEnD,IAAI,MAAM,KAAK,IAAI,EAAE;QACjB,MAAM,IAAI,KAAK,CACX,oEAAoE;cAClE,2DAA2D,CAChE,CAAC;KACL;IAED,MAAM,OAAO,GAAG,IAAA,eAAO,EACnB,GAAG,EAAE,CAAC,CAAC;QACH,IAAI,IAAI;YACJ,IAAI,CAAC,qBAAK,CAAC,WAAW,EAAE;gBACpB,qBAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;aAC5C;YAED,OAAO,qBAAK,CAAC;QACjB,CAAC;KACJ,CAAC,EACF,EAAE,CACL,CAAC;IAEF,IAAA,iBAAS,EACL,GAAG,EAAE;QACD,qBAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEzC,OAAO,GAAG,EAAE;YACR,qBAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;gBACtB,mBAAmB;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;IACN,CAAC,EACD,EAAE,CACL,CAAC;I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B,OAAO,CAAC,OAAsB,EAAQ,EAAE;4BACpC,qBAAK,CAAC,IAAI,CAAC,EAAC,GAAG,iBAAiB,CAAC,OAAO,EAAE,GAAG,OAAO,EAAC,CAAC,CAAC;wBAC3D,CAAC,CAAC;qBACL;oBAED,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC5B,CAAC;aACJ,CAAC,CAAC;QACP,CAAC;KACJ,CAAC,EACF,CAAC,iBAAiB,CAAC,CACtB,CAAC;IAEF,IAAA,iBAAS,EACL,GAAG,EAAE;QACD,qBAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEtC,OAAO,GAAG,EAAE;YACR,qBAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;gBACtB,mBAAmB;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;IACN,CAAC,EACD,CAAC,iBAAiB,CAAC,CACtB,CAAC;IAEF,OAAO,CACH,uBAAC,oBAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAChC,QAAQ,GACW,CAC3B,CAAC;AACN,CAAC,CAAC;AArDW,QAAA,aAAa,iBAqDxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug-react",
3
- "version": "0.5.6",
3
+ "version": "0.6.1",
4
4
  "description": "React components and hooks to plug your React applications into Croct.",
5
5
  "author": {
6
6
  "name": "Croct",
@@ -37,7 +37,7 @@
37
37
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@croct/plug": "^0.12.2",
40
+ "@croct/plug": "^0.13.0",
41
41
  "@croct/sdk": "^0.12.3"
42
42
  },
43
43
  "devDependencies": {
@@ -53,7 +53,7 @@
53
53
  "@storybook/manager-webpack5": "^6.5.13",
54
54
  "@storybook/react": "^6.1.21",
55
55
  "@testing-library/jest-dom": "^5.16.5",
56
- "@testing-library/react": "^13.4.0",
56
+ "@testing-library/react": "^14.0.0",
57
57
  "@types/jest": "^29.2.3",
58
58
  "@types/node": "^18.11.9",
59
59
  "@types/react": "^18.0.25",