@storyblok/react 2.3.2 → 2.3.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.
- package/dist/index.js +1 -1
- package/dist/index.mjs +37 -36
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +10 -13
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),b=require("./client.js"),a=require("./storyblok-component.js"),d=(i,r={},t={})=>{const l=o.useStoryblokApi();if(!l)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;let[u,n]=y.useState({});t.resolveRelations=t.resolveRelations??r.resolve_relations,t.resolveLinks=t.resolveLinks??r.resolve_links;const k=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return y.useEffect(()=>{async function c(){const{data:s}=await l.get(`cdn/stories/${i}`,r);n(s.story),k&&s.story.id&&e.registerStoryblokBridge(s.story.id,S=>n(S),t)}c()},[i,JSON.stringify(r)]),u};exports.RichTextResolver=e.RichTextResolver;exports.RichTextSchema=e.RichTextSchema;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;exports.getComponent=o.getComponent;exports.getStoryblokApi=o.useStoryblokApi;exports.setComponents=o.setComponents;exports.storyblokInit=o.storyblokInit;exports.useStoryblokApi=o.useStoryblokApi;exports.useStoryblokState=b.useStoryblokState;exports.StoryblokComponent=a;exports.useStoryblok=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
import { RichTextResolver as
|
|
4
|
-
import { useStoryblokApi as
|
|
5
|
-
import { getComponent as
|
|
6
|
-
import { useStoryblokState as
|
|
7
|
-
import { default as
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
import { registerStoryblokBridge as k } from "./storyblok-js.mjs";
|
|
3
|
+
import { RichTextResolver as v, RichTextSchema as x, apiPlugin as R, loadStoryblokBridge as w, renderRichText as B, storyblokEditable as h } from "./storyblok-js.mjs";
|
|
4
|
+
import { useStoryblokApi as d } from "./index2.mjs";
|
|
5
|
+
import { getComponent as A, setComponents as C, storyblokInit as T } from "./index2.mjs";
|
|
6
|
+
import { useStoryblokState as L } from "./client.mjs";
|
|
7
|
+
import { default as _ } from "./storyblok-component.mjs";
|
|
8
|
+
const b = (r, e = {}, o = {}) => {
|
|
9
|
+
const s = d();
|
|
10
|
+
if (!s)
|
|
11
11
|
return console.error(
|
|
12
12
|
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
13
13
|
), null;
|
|
14
|
-
let [
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
let [l, n] = f({});
|
|
15
|
+
o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links;
|
|
16
|
+
const i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
|
|
17
|
+
return u(() => {
|
|
17
18
|
async function y() {
|
|
18
|
-
const { data:
|
|
19
|
-
`cdn/stories/${
|
|
19
|
+
const { data: t } = await s.get(
|
|
20
|
+
`cdn/stories/${r}`,
|
|
20
21
|
e
|
|
21
22
|
);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
(a) =>
|
|
25
|
-
|
|
23
|
+
n(t.story), i && t.story.id && k(
|
|
24
|
+
t.story.id,
|
|
25
|
+
(a) => n(a),
|
|
26
|
+
o
|
|
26
27
|
);
|
|
27
28
|
}
|
|
28
29
|
y();
|
|
29
|
-
}, [
|
|
30
|
+
}, [r, JSON.stringify(e)]), l;
|
|
30
31
|
};
|
|
31
32
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
33
|
+
v as RichTextResolver,
|
|
34
|
+
x as RichTextSchema,
|
|
35
|
+
_ as StoryblokComponent,
|
|
36
|
+
R as apiPlugin,
|
|
37
|
+
A as getComponent,
|
|
38
|
+
d as getStoryblokApi,
|
|
39
|
+
w as loadStoryblokBridge,
|
|
40
|
+
k as registerStoryblokBridge,
|
|
41
|
+
B as renderRichText,
|
|
42
|
+
C as setComponents,
|
|
43
|
+
h as storyblokEditable,
|
|
44
|
+
T as storyblokInit,
|
|
45
|
+
b as useStoryblok,
|
|
46
|
+
d as useStoryblokApi,
|
|
47
|
+
k as useStoryblokBridge,
|
|
48
|
+
L as useStoryblokState
|
|
48
49
|
};
|
package/dist/storyblok-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let R=!1;const _=[],E=n=>new Promise((t,e)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}R?r():_.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>e(r),s.onload=r=>{_.forEach(i=>i()),R=!0,t(r)},document.getElementsByTagName("head")[0].appendChild(s)});var A=Object.defineProperty,N=(n,t,e)=>t in n?A(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,h=(n,t,e)=>(N(n,typeof t!="symbol"?t+"":t,e),e);function j(n){return!(n!==n||n===1/0||n===-1/0)}function M(n,t,e){if(!j(t))throw new TypeError("Expected `limit` to be a finite number");if(!j(e))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],i=0;const o=function(){i++;const a=setTimeout(function(){i--,s.length>0&&o(),r=r.filter(function(u){return u!==a})},e);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(n.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,d){s.push({resolve:u,reject:d,args:a,self:l}),i<t&&o()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let R=!1;const _=[],E=n=>new Promise((t,e)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}R?r():_.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=n,s.id="storyblok-javascript-bridge",s.onerror=r=>e(r),s.onload=r=>{_.forEach(i=>i()),R=!0,t(r)},document.getElementsByTagName("head")[0].appendChild(s)});var A=Object.defineProperty,N=(n,t,e)=>t in n?A(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,h=(n,t,e)=>(N(n,typeof t!="symbol"?t+"":t,e),e);function j(n){return!(n!==n||n===1/0||n===-1/0)}function M(n,t,e){if(!j(t))throw new TypeError("Expected `limit` to be a finite number");if(!j(e))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],i=0;const o=function(){i++;const a=setTimeout(function(){i--,s.length>0&&o(),r=r.filter(function(u){return u!==a})},e);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(n.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,d){s.push({resolve:u,reject:d,args:a,self:l}),i<t&&o()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}const z=function(n,t){const e={};for(const s in n){const r=n[s];t.indexOf(s)>-1&&r!==null&&(e[s]=r)}return e},L=n=>n==="email",U=()=>({singleTag:"hr"}),q=()=>({tag:"blockquote"}),H=()=>({tag:"ul"}),B=n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),V=()=>({singleTag:"br"}),D=n=>({tag:`h${n.attrs.level}`}),J=n=>({singleTag:[{tag:"img",attrs:z(n.attrs,["src","alt","title"])}]}),F=()=>({tag:"li"}),Y=()=>({tag:"ol"}),K=()=>({tag:"p"}),W=n=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":n.attrs.name,emoji:n.attrs.emoji}}]}),G=()=>({tag:"b"}),Q=()=>({tag:"strike"}),X=()=>({tag:"u"}),Z=()=>({tag:"strong"}),tt=()=>({tag:"code"}),et=()=>({tag:"i"}),st=n=>{const t={...n.attrs},{linktype:e="url"}=n.attrs;if(L(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const s in t.custom)t[s]=t.custom[s];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},rt=n=>({tag:[{tag:"span",attrs:n.attrs}]}),it=()=>({tag:"sub"}),ot=()=>({tag:"sup"}),nt=n=>({tag:[{tag:"span",attrs:n.attrs}]}),at=n=>{var t;return(t=n.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`background-color:${n.attrs.color};`}}]}:{tag:""}},lt=n=>{var t;return(t=n.attrs)!=null&&t.color?{tag:[{tag:"span",attrs:{style:`color:${n.attrs.color}`}}]}:{tag:""}},P={nodes:{horizontal_rule:U,blockquote:q,bullet_list:H,code_block:B,hard_break:V,heading:D,image:J,list_item:F,ordered_list:Y,paragraph:K,emoji:W},marks:{bold:G,strike:Q,underline:X,strong:Z,code:tt,italic:et,link:st,styled:rt,subscript:it,superscript:ot,anchor:nt,highlight:at,textStyle:lt}},ct=function(n){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},e=/[&<>"']/g,s=RegExp(e.source);return n&&s.test(n)?n.replace(e,r=>t[r]):n};class m{constructor(t){h(this,"marks"),h(this,"nodes"),t||(t=P),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t,e={optimizeImages:!1}){if(t&&t.content&&Array.isArray(t.content)){let s="";return t.content.forEach(r=>{s+=this.renderNode(r)}),e.optimizeImages?this.optimizeImages(s,e.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
|
|
2
2
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
3
3
|
ISbRichtext:
|
|
4
4
|
content?: ISbRichtext[]
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
type: 'doc'
|
|
24
|
-
}`),""}optimizeImages(t,e){let s=0,r=0,i="",o="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(i+=`width="${e.width}" `,s=e.width),typeof e.height=="number"&&e.height>0&&(i+=`height="${e.height}" `,r=e.height),(e.loading==="lazy"||e.loading==="eager")&&(i+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(i+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(o+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(o+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(o+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(o+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(o+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(o+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(o+=`:rotate(${e.filters.rotate})`),o.length>0&&(o="/filters"+o))),i.length>0&&(t=t.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(l=e.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${d}/m/${g}x0${o} ${g}w`;if(typeof g=="object"&&g.length===2){let v=0,T=0;return typeof g[0]=="number"&&(v=g[0]),typeof g[1]=="number"&&(T=g[1]),`//${d}/m/${v}x${T}${o} ${v}w`}}).join(", "),sizes:(u=e.sizes)==null?void 0:u.map(g=>g).join(", ")};let b="";return p.srcset&&(b+=`srcset="${p.srcset}" `),p.sizes&&(b+=`sizes="${p.sizes}" `),a.replace(/<img/g,`<img ${b.trim()}`)}return a})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&e.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach(r=>{e.push(this.renderNode(r))}):t.text?e.push(ct(t.text)):s&&s.singleTag?e.push(this.renderTag(s.singleTag," /")):s&&s.html?e.push(s.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),s&&s.tag&&e.push(this.renderClosingTag(s.tag)),t.marks&&t.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&e.push(this.renderClosingTag(i.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const o=s.attrs[i];o!==null&&(r+=` ${i}="${o}"`)}return`${r}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class w{constructor(){h(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(t,e=25,s=1)=>({...t,per_page:e,page:s})),h(this,"delay",t=>new Promise(e=>setTimeout(e,t))),h(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),h(this,"range",(t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,(i,o)=>o*r+t)}),h(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),h(this,"flatMap",(t=[],e)=>t.map(e).reduce((s,r)=>[...s,...r],[]))}stringify(t,e,s){const r=[];for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const o=t[i],c=s?"":encodeURIComponent(i);let a;typeof o=="object"?a=this.stringify(o,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(o)):a=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")}getRegionURL(t){const e="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(t){case"us":return s;case"cn":return r;default:return e}}}class ht{constructor(t){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=t.baseURL,this.headers=t.headers||new Headers,this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(r=>{s.data=r});for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if(t==="get"){const a=new w;e=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),i=new AbortController,{signal:o}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:o});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((s,r)=>{if(e.test(`${t.status}`))return s(t);const i={message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug};r(i)})}}const x="SB-Agent",k={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"2.2.6"};let y={};const f={};class ut{constructor(t,e){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=t.endpoint||e;if(!s){const o=new w().getRegionURL,c=t.https===!1?"http":"https";t.oauthToken?s=`${c}://${o(t.region)}/v1`:s=`${c}://${o(t.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),t.headers)for(const o in t.headers)r.set(o,t.headers[o]);r.has(x)||(r.set(x,k.defaultAgentName),r.set(k.defaultAgentVersion,k.packageVersion));let i=5;t.oauthToken&&(r.set("Authorization",t.oauthToken),i=3),t.rateLimit&&(i=t.rateLimit),t.richTextSchema?this.richTextResolver=new m(t.richTextSchema):this.richTextResolver=new m,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=M(this.throttledRequest,i,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new w,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new ht({baseURL:s,timeout:t.timeout||0,headers:r,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let s="";return e.attrs.body&&e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=f[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const i=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,i)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(e==null?void 0:e.per_page)||25,i=`/${t}`,o=i.split("/"),c=s||o[o.length-1],a=1,l=await this.makeRequest(i,e,r,a),u=l.total?Math.ceil(l.total/r):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),p=>this.makeRequest(i,e,r,p+1));return this.helpers.flatMap([l,...d],p=>Object.values(p.data[c]))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,s){const r=t[e];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(t,e,s,r){if(s.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[r][t[e]]&&(t[e]=this._cleanCopy(this.relations[r][t[e]]));else if(t[e]&&t[e].constructor===Array){const i=[];t[e].forEach(o=>{this.relations[r][o]&&i.push(this._cleanCopy(this.relations[r][o]))}),t[e]=i}}}iterateTree(t,e,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let o=0;o<i.length;o++)r(i[o]);else if(i.constructor===Object){if(i._stopResolving)return;for(const o in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,o,e,s),this._insertLinks(i,o,s)),r(i[o])}}};r(t.content)}async resolveLinks(t,e,s){let r=[];if(t.link_uuids){const i=t.link_uuids.length,o=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);o.push(t.link_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=t.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(t,e,s){let r=[];if(t.rel_uuids){const i=t.rel_uuids.length,o=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);o.push(t.rel_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=t.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(t,e,s){var r,i;let o=[];if(this.links[s]={},this.relations[s]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(o=e.resolve_relations.split(",")),await this.resolveRelations(t,e,s)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((r=t.links)!=null&&r.length||(i=t.link_uuids)!=null&&i.length)&&await this.resolveLinks(t,e,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],o,s);t.story?this.iterateTree(t.story,o,s):t.stories.forEach(c=>{this.iterateTree(c,o,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),i=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const o=await i.get(r);if(o)return Promise.resolve(o)}return new Promise((o,c)=>{try{(async()=>{var a;try{const l=await this.throttle("get",t,e);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200)return c(l);if(u.data.story||u.data.stories){const d=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,e,`${d}`)}return e.version==="published"&&t!="/cdn/spaces/me"&&await i.set(r,u),u.data.cv&&e.token&&(e.version=="draft"&&f[e.token]!=u.data.cv&&await this.flushCache(),f[e.token]=u.data.cv),o(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(t){this.accessToken&&(f[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(y[t])},getAll(){return Promise.resolve(y)},set(t,e){return y[t]=e,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const dt=(n={})=>{const{apiOptions:t}=n;if(!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ut(t)}},gt=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const t=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let $;const S="https://app.storyblok.com/f/storyblok-v2-latest.js",I=(n,t,e={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===n;if(!(!r||!i)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],o=>{o.action==="input"&&o.story.id===n?t(o.story):(o.action==="change"||o.action==="published")&&o.storyId===n&&window.location.reload()})})}},pt=(n={})=>{var t,e;const{bridge:s,accessToken:r,use:i=[],apiOptions:o={},richText:c={}}=n;o.accessToken=o.accessToken||r;const a={bridge:s,apiOptions:o};let l={};i.forEach(d=>{l={...l,...d(a)}});const u=!(typeof window>"u")&&((e=(t=window.location)==null?void 0:t.search)==null?void 0:e.includes("_storyblok_tk"));return s!==!1&&u&&E(S),$=new m(c.schema),c.resolver&&O($,c.resolver),l},O=(n,t)=>{n.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})},C=n=>{var t,e;return!n||((t=n==null?void 0:n.content)==null?void 0:t[0].type)!=="blok"&&!((e=n==null?void 0:n.content)!=null&&e[0].content)},ft=(n,t,e)=>{let s=e||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(n)?"":(t&&(s=new m(t.schema),t.resolver&&O(s,t.resolver)),s.render(n))},mt=()=>E(S);exports.RichTextResolver=m;exports.RichTextSchema=P;exports.apiPlugin=dt;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=mt;exports.registerStoryblokBridge=I;exports.renderRichText=ft;exports.storyblokEditable=gt;exports.storyblokInit=pt;exports.useStoryblokBridge=I;
|
|
24
|
+
}`),""}optimizeImages(t,e){let s=0,r=0,i="",o="";typeof e!="boolean"&&(typeof e.width=="number"&&e.width>0&&(i+=`width="${e.width}" `,s=e.width),typeof e.height=="number"&&e.height>0&&(i+=`height="${e.height}" `,r=e.height),(e.loading==="lazy"||e.loading==="eager")&&(i+=`loading="${e.loading}" `),typeof e.class=="string"&&e.class.length>0&&(i+=`class="${e.class}" `),e.filters&&(typeof e.filters.blur=="number"&&e.filters.blur>=0&&e.filters.blur<=100&&(o+=`:blur(${e.filters.blur})`),typeof e.filters.brightness=="number"&&e.filters.brightness>=-100&&e.filters.brightness<=100&&(o+=`:brightness(${e.filters.brightness})`),e.filters.fill&&(e.filters.fill.match(/[0-9A-Fa-f]{6}/g)||e.filters.fill==="transparent")&&(o+=`:fill(${e.filters.fill})`),e.filters.format&&["webp","png","jpeg"].includes(e.filters.format)&&(o+=`:format(${e.filters.format})`),typeof e.filters.grayscale=="boolean"&&e.filters.grayscale&&(o+=":grayscale()"),typeof e.filters.quality=="number"&&e.filters.quality>=0&&e.filters.quality<=100&&(o+=`:quality(${e.filters.quality})`),e.filters.rotate&&[90,180,270].includes(e.filters.rotate)&&(o+=`:rotate(${e.filters.rotate})`),o.length>0&&(o="/filters"+o))),i.length>0&&(t=t.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||o.length>0?`${s}x${r}${o}`:"";return t=t.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof e!="boolean"&&(e.sizes||e.srcset)&&(t=t.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const g={srcset:(l=e.srcset)==null?void 0:l.map(p=>{if(typeof p=="number")return`//${d}/m/${p}x0${o} ${p}w`;if(typeof p=="object"&&p.length===2){let v=0,T=0;return typeof p[0]=="number"&&(v=p[0]),typeof p[1]=="number"&&(T=p[1]),`//${d}/m/${v}x${T}${o} ${v}w`}}).join(", "),sizes:(u=e.sizes)==null?void 0:u.map(p=>p).join(", ")};let b="";return g.srcset&&(b+=`srcset="${g.srcset}" `),g.sizes&&(b+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${b.trim()}`)}return a})),t}renderNode(t){const e=[];t.marks&&t.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&e.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(t);return s&&s.tag&&e.push(this.renderOpeningTag(s.tag)),t.content?t.content.forEach(r=>{e.push(this.renderNode(r))}):t.text?e.push(ct(t.text)):s&&s.singleTag?e.push(this.renderTag(s.singleTag," /")):s&&s.html?e.push(s.html):t.type==="emoji"&&e.push(this.renderEmoji(t)),s&&s.tag&&e.push(this.renderClosingTag(s.tag)),t.marks&&t.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&e.push(this.renderClosingTag(i.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const o=s.attrs[i];o!==null&&(r+=` ${i}="${o}"`)}return`${r}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){const e=this.nodes[t.type];if(typeof e=="function")return e(t)}getMatchingMark(t){const e=this.marks[t.type];if(typeof e=="function")return e(t)}renderEmoji(t){if(t.attrs.emoji)return t.attrs.emoji;const e=[{tag:"img",attrs:{src:t.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(e," /")}}class w{constructor(){h(this,"isCDNUrl",(t="")=>t.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(t,e=25,s=1)=>({...t,per_page:e,page:s})),h(this,"delay",t=>new Promise(e=>setTimeout(e,t))),h(this,"arrayFrom",(t=0,e)=>[...Array(t)].map(e)),h(this,"range",(t=0,e=t)=>{const s=Math.abs(e-t)||0,r=t<e?1:-1;return this.arrayFrom(s,(i,o)=>o*r+t)}),h(this,"asyncMap",async(t,e)=>Promise.all(t.map(e))),h(this,"flatMap",(t=[],e)=>t.map(e).reduce((s,r)=>[...s,...r],[]))}stringify(t,e,s){const r=[];for(const i in t){if(!Object.prototype.hasOwnProperty.call(t,i))continue;const o=t[i],c=s?"":encodeURIComponent(i);let a;typeof o=="object"?a=this.stringify(o,e?e+encodeURIComponent("["+c+"]"):c,Array.isArray(o)):a=(e?e+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")}getRegionURL(t){const e="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(t){case"us":return s;case"cn":return r;default:return e}}}class ht{constructor(t){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=t.baseURL,this.headers=t.headers||new Headers,this.timeout=t!=null&&t.timeout?t.timeout*1e3:0,this.responseInterceptor=t.responseInterceptor,this.fetch=(...e)=>t.fetch?t.fetch(...e):fetch(...e),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(t,e){return this.url=t,this.parameters=e,this._methodHandler("get")}post(t,e){return this.url=t,this.parameters=e,this._methodHandler("post")}put(t,e){return this.url=t,this.parameters=e,this._methodHandler("put")}delete(t,e){return this.url=t,this.parameters=e,this._methodHandler("delete")}async _responseHandler(t){const e=[],s={data:{},headers:{},status:0,statusText:""};t.status!==204&&await t.json().then(r=>{s.data=r});for(const r of t.headers.entries())e[r[0]]=r[1];return s.headers={...e},s.status=t.status,s.statusText=t.statusText,s}async _methodHandler(t){let e=`${this.baseURL}${this.url}`,s=null;if(t==="get"){const a=new w;e=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(e),i=new AbortController,{signal:o}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:t,headers:this.headers,body:s,signal:o});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(t){const e=/20[0-6]/g;return new Promise((s,r)=>{if(e.test(`${t.status}`))return s(t);const i={message:new Error(t.statusText),status:t.status,response:Array.isArray(t.data)?t.data[0]:t.data.error||t.data.slug};r(i)})}}const x="SB-Agent",k={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"2.2.7"};let y={};const f={};class ut{constructor(t,e){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=t.endpoint||e;if(!s){const o=new w().getRegionURL,c=t.https===!1?"http":"https";t.oauthToken?s=`${c}://${o(t.region)}/v1`:s=`${c}://${o(t.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),t.headers)for(const o in t.headers)r.set(o,t.headers[o]);r.has(x)||(r.set(x,k.defaultAgentName),r.set(k.defaultAgentVersion,k.packageVersion));let i=5;t.oauthToken&&(r.set("Authorization",t.oauthToken),i=3),t.rateLimit&&(i=t.rateLimit),t.richTextSchema?this.richTextResolver=new m(t.richTextSchema):this.richTextResolver=new m,t.componentResolver&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=M(this.throttledRequest,i,1e3),this.accessToken=t.accessToken||"",this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.helpers=new w,this.resolveCounter=0,this.resolveNestedRelations=t.resolveNestedRelations||!0,this.client=new ht({baseURL:s,timeout:t.timeout||0,headers:r,responseInterceptor:t.responseInterceptor,fetch:t.fetch})}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let s="";return e.attrs.body&&e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})}parseParams(t){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=f[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e){return this.helpers.isCDNUrl(t)?this.parseParams(e):e}makeRequest(t,e,s,r){const i=this.factoryParamOptions(t,this.helpers.getOptionsPage(e,s,r));return this.cacheResponse(t,i)}get(t,e){e||(e={});const s=`/${t}`,r=this.factoryParamOptions(s,e);return this.cacheResponse(s,r)}async getAll(t,e,s){const r=(e==null?void 0:e.per_page)||25,i=`/${t}`,o=i.split("/"),c=s||o[o.length-1],a=1,l=await this.makeRequest(i,e,r,a),u=l.total?Math.ceil(l.total/r):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),g=>this.makeRequest(i,e,r,g+1));return this.helpers.flatMap([l,...d],g=>Object.values(g.data[c]))}post(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("post",s,e))}put(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("put",s,e))}delete(t,e){const s=`/${t}`;return Promise.resolve(this.throttle("delete",s,e))}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e,s){const r=t[e];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(t,e,s,r){if(s.indexOf(`${t.component}.${e}`)>-1){if(typeof t[e]=="string")this.relations[r][t[e]]&&(t[e]=this._cleanCopy(this.relations[r][t[e]]));else if(t[e]&&t[e].constructor===Array){const i=[];t[e].forEach(o=>{this.relations[r][o]&&i.push(this._cleanCopy(this.relations[r][o]))}),t[e]=i}}}iterateTree(t,e,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let o=0;o<i.length;o++)r(i[o]);else if(i.constructor===Object){if(i._stopResolving)return;for(const o in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,o,e,s),this._insertLinks(i,o,s)),r(i[o])}}};r(t.content)}async resolveLinks(t,e,s){let r=[];if(t.link_uuids){const i=t.link_uuids.length,o=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);o.push(t.link_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=t.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(t,e,s){let r=[];if(t.rel_uuids){const i=t.rel_uuids.length,o=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);o.push(t.rel_uuids.slice(a,l))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:c,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=t.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(t,e,s){var r,i;let o=[];if(this.links[s]={},this.relations[s]={},typeof e.resolve_relations<"u"&&e.resolve_relations.length>0&&(typeof e.resolve_relations=="string"&&(o=e.resolve_relations.split(",")),await this.resolveRelations(t,e,s)),e.resolve_links&&["1","story","url"].indexOf(e.resolve_links)>-1&&((r=t.links)!=null&&r.length||(i=t.link_uuids)!=null&&i.length)&&await this.resolveLinks(t,e,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],o,s);t.story?this.iterateTree(t.story,o,s):t.stories.forEach(c=>{this.iterateTree(c,o,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(t,e,s){const r=this.helpers.stringify({url:t,params:e}),i=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const o=await i.get(r);if(o)return Promise.resolve(o)}return new Promise((o,c)=>{try{(async()=>{var a;try{const l=await this.throttle("get",t,e);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200)return c(l);if(u.data.story||u.data.stories){const d=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,e,`${d}`)}return e.version==="published"&&t!="/cdn/spaces/me"&&await i.set(r,u),u.data.cv&&e.token&&(e.version=="draft"&&f[e.token]!=u.data.cv&&await this.flushCache(),f[e.token]=u.data.cv),o(u)}catch(l){return c(l)}})()}catch{}})}throttledRequest(t,e,s){return this.client[t](e,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(t){this.accessToken&&(f[this.accessToken]=t)}cacheProvider(){switch(this.cache.type){case"memory":return{get(t){return Promise.resolve(y[t])},getAll(){return Promise.resolve(y)},set(t,e){return y[t]=e,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const dt=(n={})=>{const{apiOptions:t}=n;if(!t.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ut(t)}},pt=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const t=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let $;const S="https://app.storyblok.com/f/storyblok-v2-latest.js",I=(n,t,e={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===n;if(!(!r||!i)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],o=>{o.action==="input"&&o.story.id===n?t(o.story):(o.action==="change"||o.action==="published")&&o.storyId===n&&window.location.reload()})})}},gt=(n={})=>{var t,e;const{bridge:s,accessToken:r,use:i=[],apiOptions:o={},richText:c={}}=n;o.accessToken=o.accessToken||r;const a={bridge:s,apiOptions:o};let l={};i.forEach(d=>{l={...l,...d(a)}});const u=!(typeof window>"u")&&((e=(t=window.location)==null?void 0:t.search)==null?void 0:e.includes("_storyblok_tk"));return s!==!1&&u&&E(S),$=new m(c.schema),c.resolver&&O($,c.resolver),l},O=(n,t)=>{n.addNode("blok",e=>{let s="";return e.attrs.body.forEach(r=>{s+=t(r.component,r)}),{html:s}})},C=n=>!n||!(n!=null&&n.content.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule")),ft=(n,t,e)=>{let s=e||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(n)?"":(t&&(s=new m(t.schema),t.resolver&&O(s,t.resolver)),s.render(n))},mt=()=>E(S);exports.RichTextResolver=m;exports.RichTextSchema=P;exports.apiPlugin=dt;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=mt;exports.registerStoryblokBridge=I;exports.renderRichText=ft;exports.storyblokEditable=pt;exports.storyblokInit=gt;exports.useStoryblokBridge=I;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -62,9 +62,9 @@ const A = function(n, t) {
|
|
|
62
62
|
return e;
|
|
63
63
|
}, N = (n) => n === "email", M = () => ({
|
|
64
64
|
singleTag: "hr"
|
|
65
|
-
}), L = () => ({
|
|
66
|
-
tag: "blockquote"
|
|
67
65
|
}), z = () => ({
|
|
66
|
+
tag: "blockquote"
|
|
67
|
+
}), L = () => ({
|
|
68
68
|
tag: "ul"
|
|
69
69
|
}), U = (n) => ({
|
|
70
70
|
tag: [
|
|
@@ -178,8 +178,8 @@ const A = function(n, t) {
|
|
|
178
178
|
}, nt = {
|
|
179
179
|
nodes: {
|
|
180
180
|
horizontal_rule: M,
|
|
181
|
-
blockquote:
|
|
182
|
-
bullet_list:
|
|
181
|
+
blockquote: z,
|
|
182
|
+
bullet_list: L,
|
|
183
183
|
code_block: U,
|
|
184
184
|
hard_break: q,
|
|
185
185
|
heading: H,
|
|
@@ -276,8 +276,8 @@ class y {
|
|
|
276
276
|
if (typeof p == "number")
|
|
277
277
|
return `//${d}/m/${p}x0${o} ${p}w`;
|
|
278
278
|
if (typeof p == "object" && p.length === 2) {
|
|
279
|
-
let
|
|
280
|
-
return typeof p[0] == "number" && (
|
|
279
|
+
let k = 0, T = 0;
|
|
280
|
+
return typeof p[0] == "number" && (k = p[0]), typeof p[1] == "number" && (T = p[1]), `//${d}/m/${k}x${T}${o} ${k}w`;
|
|
281
281
|
}
|
|
282
282
|
}).join(", "),
|
|
283
283
|
sizes: (u = e.sizes) == null ? void 0 : u.map((p) => p).join(", ")
|
|
@@ -481,10 +481,10 @@ class lt {
|
|
|
481
481
|
});
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
const x = "SB-Agent",
|
|
484
|
+
const x = "SB-Agent", v = {
|
|
485
485
|
defaultAgentName: "SB-JS-CLIENT",
|
|
486
486
|
defaultAgentVersion: "SB-Agent-Version",
|
|
487
|
-
packageVersion: "2.2.
|
|
487
|
+
packageVersion: "2.2.7"
|
|
488
488
|
};
|
|
489
489
|
let m = {};
|
|
490
490
|
const f = {};
|
|
@@ -505,7 +505,7 @@ class ct {
|
|
|
505
505
|
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), t.headers)
|
|
506
506
|
for (const o in t.headers)
|
|
507
507
|
r.set(o, t.headers[o]);
|
|
508
|
-
r.has(x) || (r.set(x,
|
|
508
|
+
r.has(x) || (r.set(x, v.defaultAgentName), r.set(v.defaultAgentVersion, v.packageVersion));
|
|
509
509
|
let i = 5;
|
|
510
510
|
t.oauthToken && (r.set("Authorization", t.oauthToken), i = 3), t.rateLimit && (i = t.rateLimit), t.richTextSchema ? this.richTextResolver = new y(t.richTextSchema) : this.richTextResolver = new y(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = O(this.throttledRequest, i, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new w(), this.resolveCounter = 0, this.resolveNestedRelations = t.resolveNestedRelations || !0, this.client = new lt({
|
|
511
511
|
baseURL: s,
|
|
@@ -839,10 +839,7 @@ const P = "https://app.storyblok.com/f/storyblok-v2-latest.js", pt = (n, t, e =
|
|
|
839
839
|
html: s
|
|
840
840
|
};
|
|
841
841
|
});
|
|
842
|
-
}, ht = (n) => {
|
|
843
|
-
var t, e;
|
|
844
|
-
return !n || ((t = n == null ? void 0 : n.content) == null ? void 0 : t[0].type) !== "blok" && !((e = n == null ? void 0 : n.content) != null && e[0].content);
|
|
845
|
-
}, ft = (n, t, e) => {
|
|
842
|
+
}, ht = (n) => !n || !(n != null && n.content.some((t) => t.content || t.type === "blok" || t.type === "horizontal_rule")), ft = (n, t, e) => {
|
|
846
843
|
let s = e || $;
|
|
847
844
|
if (!s) {
|
|
848
845
|
console.error(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.4",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "^2.2.
|
|
47
|
+
"@storyblok/js": "^2.2.7"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/core": "^7.22.9",
|