@storyblok/react 6.1.2 → 6.1.4

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 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let o=null;const e=new Map;let n=!1,l=null;globalThis.storyCache=globalThis.storyCache||new Map;const c=()=>o,b=t=>{o=t},p=t=>(Object.entries(t).forEach(([s,a])=>{e.set(s,a)}),e),r=t=>e.has(t)?e.get(t):(console.error(`Component ${t} doesn't exist.`),!1),C=()=>n,m=t=>{n=t},k=()=>l,g=t=>{l=t};exports.getComponent=r;exports.getCustomFallbackComponent=k;exports.getEnableFallbackComponent=C;exports.getStoryblokApiInstance=c;exports.setComponents=p;exports.setCustomFallbackComponent=g;exports.setEnableFallbackComponent=m;exports.setStoryblokApiInstance=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let n=null;const e=new Map;let o=!1,l=null;const c=()=>n,b=t=>{n=t},p=t=>(Object.entries(t).forEach(([s,a])=>{e.set(s,a)}),e),m=t=>e.has(t)?e.get(t):(console.error(`Component ${t} doesn't exist.`),!1),r=()=>o,C=t=>{o=t},k=()=>l,u=t=>{l=t};exports.getComponent=m;exports.getCustomFallbackComponent=k;exports.getEnableFallbackComponent=r;exports.getStoryblokApiInstance=c;exports.setComponents=p;exports.setCustomFallbackComponent=u;exports.setEnableFallbackComponent=C;exports.setStoryblokApiInstance=b;
@@ -1,23 +1,22 @@
1
- let o = null;
1
+ let e = null;
2
2
  const n = /* @__PURE__ */ new Map();
3
- let e = !1, s = null;
4
- globalThis.storyCache = globalThis.storyCache || /* @__PURE__ */ new Map();
5
- const c = () => o, r = (t) => {
6
- o = t;
7
- }, b = (t) => (Object.entries(t).forEach(([l, a]) => {
8
- n.set(l, a);
9
- }), n), p = (t) => n.has(t) ? n.get(t) : (console.error(`Component ${t} doesn't exist.`), !1), C = () => e, m = (t) => {
3
+ let o = !1, s = null;
4
+ const c = () => e, r = (t) => {
10
5
  e = t;
11
- }, k = () => s, i = (t) => {
6
+ }, p = (t) => (Object.entries(t).forEach(([l, a]) => {
7
+ n.set(l, a);
8
+ }), n), b = (t) => n.has(t) ? n.get(t) : (console.error(`Component ${t} doesn't exist.`), !1), m = () => o, C = (t) => {
9
+ o = t;
10
+ }, k = () => s, u = (t) => {
12
11
  s = t;
13
12
  };
14
13
  export {
15
- p as getComponent,
14
+ b as getComponent,
16
15
  k as getCustomFallbackComponent,
17
- C as getEnableFallbackComponent,
16
+ m as getEnableFallbackComponent,
18
17
  c as getStoryblokApiInstance,
19
- b as setComponents,
20
- i as setCustomFallbackComponent,
21
- m as setEnableFallbackComponent,
18
+ p as setComponents,
19
+ u as setCustomFallbackComponent,
20
+ C as setEnableFallbackComponent,
22
21
  r as setStoryblokApiInstance
23
22
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});globalThis.storyCache=globalThis.storyCache||new Map;const a=e=>typeof(e==null?void 0:e.id)!="number"?null:String(e.id),n=e=>{const c=a(e);if(!c)return e;const t=globalThis.storyCache.get(c);return globalThis.storyCache.delete(c),t?{...e,...t}:e};exports.consumeCachedStory=n;exports.getStoryCacheKey=a;
@@ -0,0 +1,12 @@
1
+ globalThis.storyCache = globalThis.storyCache || /* @__PURE__ */ new Map();
2
+ const n = (e) => typeof (e == null ? void 0 : e.id) != "number" ? null : String(e.id), h = (e) => {
3
+ const c = n(e);
4
+ if (!c)
5
+ return e;
6
+ const a = globalThis.storyCache.get(c);
7
+ return globalThis.storyCache.delete(c), a ? { ...e, ...a } : e;
8
+ };
9
+ export {
10
+ h as consumeCachedStory,
11
+ n as getStoryCacheKey
12
+ };
@@ -1,2 +1,2 @@
1
1
  "use server";
2
- "use strict";var n=Object.create;var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty;var p=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!s.call(e,o)&&o!==i&&a(e,o,{get:()=>t[o],enumerable:!(r=c(t,o))||r.enumerable});return e};var v=(e,t,i)=>(i=e!=null?n(l(e)):{},p(t||!e||!e.__esModule?a(i,"default",{value:e,enumerable:!0}):i,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function u({story:e,pathToRevalidate:t}){var i;if(!e||!t)return console.error("liveEditUpdateAction: story or pathToRevalidate is not provided");if((i=globalThis.storyCache)==null||i.set(e.uuid,e),process.env.NEXT_RUNTIME)try{const{revalidatePath:r}=await import("next/cache");r(t)}catch(r){console.error("liveEditUpdateAction: error while revalidating path",r)}}exports.liveEditUpdateAction=u;
2
+ "use strict";var c=Object.create;var a=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty;var h=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of d(t))!s.call(e,i)&&i!==r&&a(e,i,{get:()=>t[i],enumerable:!(o=n(t,i))||o.enumerable});return e};var p=(e,t,r)=>(r=e!=null?c(l(e)):{},h(t||!e||!e.__esModule?a(r,"default",{value:e,enumerable:!0}):r,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../core/story-cache.js");async function y({story:e,pathToRevalidate:t}){var o;if(!e||!t)return console.error("liveEditUpdateAction: story or pathToRevalidate is not provided");const r=v.getStoryCacheKey(e);if(r&&((o=globalThis.storyCache)==null||o.set(r,e)),process.env.NEXT_RUNTIME)try{const{revalidatePath:i}=await import("next/cache");i(t)}catch(i){console.error("liveEditUpdateAction: error while revalidating path",i)}}exports.liveEditUpdateAction=y;
@@ -1,16 +1,21 @@
1
1
  "use server";
2
- async function o({ story: e, pathToRevalidate: i }) {
3
- var r;
4
- if (!e || !i)
2
+ import { getStoryCacheKey as a } from "../core/story-cache.mjs";
3
+ async function n({
4
+ story: e,
5
+ pathToRevalidate: r
6
+ }) {
7
+ var i;
8
+ if (!e || !r)
5
9
  return console.error("liveEditUpdateAction: story or pathToRevalidate is not provided");
6
- if ((r = globalThis.storyCache) == null || r.set(e.uuid, e), process.env.NEXT_RUNTIME)
10
+ const o = a(e);
11
+ if (o && ((i = globalThis.storyCache) == null || i.set(o, e)), process.env.NEXT_RUNTIME)
7
12
  try {
8
13
  const { revalidatePath: t } = await import("next/cache");
9
- t(i);
14
+ t(r);
10
15
  } catch (t) {
11
16
  console.error("liveEditUpdateAction: error while revalidating path", t);
12
17
  }
13
18
  }
14
19
  export {
15
- o as liveEditUpdateAction
20
+ n as liveEditUpdateAction
16
21
  };
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";const o=require("@storyblok/js"),l=require("react"),s=require("../utils.js"),u=({story:t=null,bridgeOptions:r={}})=>{if(!s.isVisualEditor())return null;const n=(t==null?void 0:t.id)??0;return l.useEffect(()=>{(async()=>{s.isBridgeLoaded()||await o.loadStoryblokBridge();const c=async i=>{var a;if(i)try{const{liveEditUpdateAction:e}=await Promise.resolve().then(()=>require("./live-edit-update-action.js"));l.startTransition(()=>{e({story:i,pathToRevalidate:window.location.pathname})})}catch(e){console.warn("Server action not available, caching story locally:",e),i.uuid&&((a=globalThis.storyCache)==null||a.set(i.uuid,i))}};o.registerStoryblokBridge(n,i=>c(i),r)})()},[n,JSON.stringify(r)]),null};module.exports=u;
2
+ "use strict";const n=require("@storyblok/js"),s=require("react"),d=require("../core/story-cache.js"),c=require("../utils.js"),y=({story:e=null,bridgeOptions:a={}})=>{if(!c.isVisualEditor())return null;const r=typeof(e==null?void 0:e.id)=="number"?e.id:null;return s.useEffect(()=>{r!==null&&(async()=>{c.isBridgeLoaded()||await n.loadStoryblokBridge();const u=async t=>{var o;if(t)try{const{liveEditUpdateAction:i}=await Promise.resolve().then(()=>require("./live-edit-update-action.js"));s.startTransition(()=>{i({story:t,pathToRevalidate:window.location.pathname})})}catch(i){console.warn("Server action not available, caching story locally:",i);const l=d.getStoryCacheKey(t);l&&((o=globalThis.storyCache)==null||o.set(l,t))}};n.registerStoryblokBridge(r,t=>u(t),a)})()},[r,JSON.stringify(a)]),null};module.exports=y;
@@ -1,30 +1,36 @@
1
1
  "use client";
2
- import { loadStoryblokBridge as l, registerStoryblokBridge as d } from "@storyblok/js";
3
- import { useEffect as c, startTransition as s } from "react";
4
- import { isVisualEditor as u, isBridgeLoaded as f } from "../utils.mjs";
5
- const E = ({ story: t = null, bridgeOptions: o = {} }) => {
6
- if (!u())
2
+ import { loadStoryblokBridge as s, registerStoryblokBridge as c } from "@storyblok/js";
3
+ import { useEffect as d, startTransition as u } from "react";
4
+ import { getStoryCacheKey as f } from "../core/story-cache.mjs";
5
+ import { isVisualEditor as y, isBridgeLoaded as p } from "../utils.mjs";
6
+ const g = ({ story: r = null, bridgeOptions: a = {} }) => {
7
+ if (!y())
7
8
  return null;
8
- const r = (t == null ? void 0 : t.id) ?? 0;
9
- return c(() => {
10
- (async () => {
11
- f() || await l();
12
- const e = async (i) => {
13
- var n;
14
- if (i)
9
+ const i = typeof (r == null ? void 0 : r.id) == "number" ? r.id : null;
10
+ return d(() => {
11
+ i !== null && (async () => {
12
+ p() || await s();
13
+ const n = async (t) => {
14
+ var e;
15
+ if (t)
15
16
  try {
16
- const { liveEditUpdateAction: a } = await import("./live-edit-update-action.mjs");
17
- s(() => {
18
- a({ story: i, pathToRevalidate: window.location.pathname });
17
+ const { liveEditUpdateAction: o } = await import("./live-edit-update-action.mjs");
18
+ u(() => {
19
+ o({
20
+ story: t,
21
+ pathToRevalidate: window.location.pathname
22
+ });
19
23
  });
20
- } catch (a) {
21
- console.warn("Server action not available, caching story locally:", a), i.uuid && ((n = globalThis.storyCache) == null || n.set(i.uuid, i));
24
+ } catch (o) {
25
+ console.warn("Server action not available, caching story locally:", o);
26
+ const l = f(t);
27
+ l && ((e = globalThis.storyCache) == null || e.set(l, t));
22
28
  }
23
29
  };
24
- d(r, (i) => e(i), o);
30
+ c(i, (t) => n(t), a);
25
31
  })();
26
- }, [r, JSON.stringify(o)]), null;
32
+ }, [i, JSON.stringify(a)]), null;
27
33
  };
28
34
  export {
29
- E as default
35
+ g as default
30
36
  };
package/dist/rsc/story.js CHANGED
@@ -1 +1 @@
1
- "use strict";const r=require("react/jsx-runtime"),i=require("react"),s=require("../server/server-component.js"),l=require("./live-editing.js"),u=i.forwardRef(({story:e,bridgeOptions:t,...o},n)=>{if(!e)return console.error("Please provide a 'story' property to the StoryblokServerComponent"),null;if(globalThis!=null&&globalThis.storyCache.has(e.uuid)&&(e=globalThis.storyCache.get(e.uuid),globalThis.storyCache.delete(e.uuid)),typeof e.content=="string")try{e.content=JSON.parse(e.content)}catch(c){console.error("An error occurred while trying to parse the story content",c),e.content={}}return r.jsxs(r.Fragment,{children:[r.jsx(s,{ref:n,blok:e.content,...o}),r.jsx(l,{story:e,bridgeOptions:t})]})});module.exports=u;
1
+ "use strict";const r=require("react/jsx-runtime"),i=require("react"),s=require("../core/story-cache.js"),u=require("../server/server-component.js"),l=require("./live-editing.js"),a=i.forwardRef(({story:e,bridgeOptions:t,...n},o)=>{if(!e)return console.error("Please provide a 'story' property to the StoryblokServerComponent"),null;if(e=s.consumeCachedStory(e),typeof e.content=="string")try{e.content=JSON.parse(e.content)}catch(c){console.error("An error occurred while trying to parse the story content",c),e.content={}}return r.jsxs(r.Fragment,{children:[r.jsx(u,{ref:o,blok:e.content,...n}),r.jsx(l,{story:e,bridgeOptions:t})]})});module.exports=a;
@@ -1,28 +1,29 @@
1
- import { jsxs as l, Fragment as c, jsx as o } from "react/jsx-runtime";
2
- import { forwardRef as a } from "react";
3
- import p from "../server/server-component.mjs";
4
- import h from "./live-editing.mjs";
5
- const s = a(
6
- ({ story: e, bridgeOptions: r, ...t }, n) => {
7
- if (!e)
1
+ import { jsxs as i, Fragment as m, jsx as o } from "react/jsx-runtime";
2
+ import { forwardRef as p } from "react";
3
+ import { consumeCachedStory as l } from "../core/story-cache.mjs";
4
+ import f from "../server/server-component.mjs";
5
+ import a from "./live-editing.mjs";
6
+ const b = p(
7
+ ({ story: r, bridgeOptions: e, ...t }, n) => {
8
+ if (!r)
8
9
  return console.error(
9
10
  "Please provide a 'story' property to the StoryblokServerComponent"
10
11
  ), null;
11
- if (globalThis != null && globalThis.storyCache.has(e.uuid) && (e = globalThis.storyCache.get(e.uuid), globalThis.storyCache.delete(e.uuid)), typeof e.content == "string")
12
+ if (r = l(r), typeof r.content == "string")
12
13
  try {
13
- e.content = JSON.parse(e.content);
14
- } catch (i) {
14
+ r.content = JSON.parse(r.content);
15
+ } catch (c) {
15
16
  console.error(
16
17
  "An error occurred while trying to parse the story content",
17
- i
18
- ), e.content = {};
18
+ c
19
+ ), r.content = {};
19
20
  }
20
- return /* @__PURE__ */ l(c, { children: [
21
- /* @__PURE__ */ o(p, { ref: n, blok: e.content, ...t }),
22
- /* @__PURE__ */ o(h, { story: e, bridgeOptions: r })
21
+ return /* @__PURE__ */ i(m, { children: [
22
+ /* @__PURE__ */ o(f, { ref: n, blok: r.content, ...t }),
23
+ /* @__PURE__ */ o(a, { story: r, bridgeOptions: e })
23
24
  ] });
24
25
  }
25
26
  );
26
27
  export {
27
- s as default
28
+ b as default
28
29
  };
@@ -1 +1 @@
1
- "use strict";const n=require("react/jsx-runtime"),c=require("react"),i=require("./server-component.js"),l=c.forwardRef(({story:e,...r},t)=>{if(!e)return console.error("Please provide a 'story' property to the StoryblokServerStory"),null;if(globalThis!=null&&globalThis.storyCache.has(e.uuid)&&(e=globalThis.storyCache.get(e.uuid),globalThis.storyCache.delete(e.uuid)),typeof e.content=="string")try{e.content=JSON.parse(e.content)}catch(o){console.error("An error occurred while trying to parse the story content",o),e.content={}}return n.jsx(i,{ref:t,blok:e.content,...r})});module.exports=l;
1
+ "use strict";const n=require("react/jsx-runtime"),c=require("react"),s=require("../core/story-cache.js"),i=require("./server-component.js"),u=c.forwardRef(({story:e,...r},t)=>{if(!e)return console.error("Please provide a 'story' property to the StoryblokServerStory"),null;if(e=s.consumeCachedStory(e),typeof e.content=="string")try{e.content=JSON.parse(e.content)}catch(o){console.error("An error occurred while trying to parse the story content",o),e.content={}}return n.jsx(i,{ref:t,blok:e.content,...r})});module.exports=u;
@@ -1,24 +1,25 @@
1
1
  import { jsx as n } from "react/jsx-runtime";
2
- import { forwardRef as l } from "react";
3
- import c from "./server-component.mjs";
4
- const p = l(
5
- ({ story: e, ...r }, o) => {
6
- if (!e)
2
+ import { forwardRef as c } from "react";
3
+ import { consumeCachedStory as p } from "../core/story-cache.mjs";
4
+ import l from "./server-component.mjs";
5
+ const a = c(
6
+ ({ story: r, ...o }, e) => {
7
+ if (!r)
7
8
  return console.error(
8
9
  "Please provide a 'story' property to the StoryblokServerStory"
9
10
  ), null;
10
- if (globalThis != null && globalThis.storyCache.has(e.uuid) && (e = globalThis.storyCache.get(e.uuid), globalThis.storyCache.delete(e.uuid)), typeof e.content == "string")
11
+ if (r = p(r), typeof r.content == "string")
11
12
  try {
12
- e.content = JSON.parse(e.content);
13
+ r.content = JSON.parse(r.content);
13
14
  } catch (t) {
14
15
  console.error(
15
16
  "An error occurred while trying to parse the story content",
16
17
  t
17
- ), e.content = {};
18
+ ), r.content = {};
18
19
  }
19
- return /* @__PURE__ */ n(c, { ref: o, blok: e.content, ...r });
20
+ return /* @__PURE__ */ n(l, { ref: e, blok: r.content, ...o });
20
21
  }
21
22
  );
22
23
  export {
23
- p as default
24
+ a as default
24
25
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/react",
3
3
  "type": "module",
4
- "version": "6.1.2",
4
+ "version": "6.1.4",
5
5
  "private": false,
6
6
  "description": "SDK to integrate Storyblok into your project using React.",
7
7
  "author": "Storyblok",
@@ -49,7 +49,7 @@
49
49
  }
50
50
  },
51
51
  "dependencies": {
52
- "@storyblok/js": "5.1.2"
52
+ "@storyblok/js": "5.1.3"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@babel/core": "^7.27.1",