@storyblok/react 5.1.0 → 5.1.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/dist/index.mjs +5 -5
- package/dist/richtext.mjs +3 -3
- package/dist/storyblok-js.js +1 -1
- package/dist/storyblok-js.mjs +48 -48
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { useState as f, useEffect as k } from "react";
|
|
|
2
2
|
import { registerStoryblokBridge as u } from "./storyblok-js.mjs";
|
|
3
3
|
import { BlockTypes as T, MarkTypes as B, TextTypes as C, apiPlugin as E, loadStoryblokBridge as h, renderRichText as w, richTextResolver as A, storyblokEditable as I } from "./storyblok-js.mjs";
|
|
4
4
|
import { useStoryblokApi as c } from "./index2.mjs";
|
|
5
|
-
import { getComponent as L, getCustomFallbackComponent as P, getEnableFallbackComponent as _, setComponents as
|
|
5
|
+
import { getComponent as L, getCustomFallbackComponent as P, getEnableFallbackComponent as _, setComponents as J, storyblokInit as M } from "./index2.mjs";
|
|
6
6
|
import { useStoryblokRichText as m } from "./richtext.mjs";
|
|
7
|
-
import { useStoryblokState as
|
|
7
|
+
import { useStoryblokState as Y } from "./client.mjs";
|
|
8
8
|
import { default as j } from "./storyblok-rich-text.mjs";
|
|
9
9
|
import { convertAttributesInElement as z } from "./utils.mjs";
|
|
10
10
|
import { default as G } from "./storyblok-component.mjs";
|
|
@@ -47,13 +47,13 @@ export {
|
|
|
47
47
|
u as registerStoryblokBridge,
|
|
48
48
|
w as renderRichText,
|
|
49
49
|
A as richTextResolver,
|
|
50
|
-
|
|
50
|
+
J as setComponents,
|
|
51
51
|
I as storyblokEditable,
|
|
52
|
-
|
|
52
|
+
M as storyblokInit,
|
|
53
53
|
x as useStoryblok,
|
|
54
54
|
c as useStoryblokApi,
|
|
55
55
|
u as useStoryblokBridge,
|
|
56
56
|
m as useStoryblokRichText,
|
|
57
57
|
g as useStoryblokRichTextResolver,
|
|
58
|
-
|
|
58
|
+
Y as useStoryblokState
|
|
59
59
|
};
|
package/dist/richtext.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import o from "react";
|
|
2
2
|
import n from "./storyblok-component.mjs";
|
|
3
|
-
import { BlockTypes as
|
|
3
|
+
import { BlockTypes as m, richTextResolver as a } from "./storyblok-js.mjs";
|
|
4
4
|
function i(e) {
|
|
5
5
|
var t, s;
|
|
6
6
|
const r = (t = e == null ? void 0 : e.attrs) == null ? void 0 : t.body;
|
|
@@ -16,12 +16,12 @@ function p(e) {
|
|
|
16
16
|
key: Math.random().toString(36).substring(2, 15)
|
|
17
17
|
}, t),
|
|
18
18
|
resolvers: {
|
|
19
|
-
[
|
|
19
|
+
[m.COMPONENT]: i,
|
|
20
20
|
...e.resolvers
|
|
21
21
|
},
|
|
22
22
|
keyedResolvers: !0
|
|
23
23
|
};
|
|
24
|
-
return
|
|
24
|
+
return a(r);
|
|
25
25
|
}
|
|
26
26
|
export {
|
|
27
27
|
i as componentResolver,
|
package/dist/storyblok-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function ne(n,e){if(!e)return{src:n,attrs:{}};let t=0,r=0;const s={},o=[];function c(i,h,f,y,$){typeof i!="number"||i<=h||i>=f?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`):$.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(s.height=e.height,r=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:i}=e||{},{blur:h,brightness:f,fill:y,format:$,grayscale:T,quality:A,rotate:I}=i||{};h&&c(h,0,100,"blur",o),A&&c(A,0,100,"quality",o),f&&c(f,0,100,"brightness",o),y&&o.push(`fill(${y})`),T&&o.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${I})`),$&&["webp","png","jpeg"].includes($)&&o.push(`format(${$})`)}e.srcset&&(s.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${n}/m/${i}x0/${o.length>0?`filters:${o.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[h,f]=i;return`${n}/m/${h}x${f}/${o.length>0?`filters:${o.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let l=`${n}/m/`;return t>0&&r>0&&(l=`${l}${t}x${r}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:s}}var b=(n=>(n.DOCUMENT="doc",n.HEADING="heading",n.PARAGRAPH="paragraph",n.QUOTE="blockquote",n.OL_LIST="ordered_list",n.UL_LIST="bullet_list",n.LIST_ITEM="list_item",n.CODE_BLOCK="code_block",n.HR="horizontal_rule",n.BR="hard_break",n.IMAGE="image",n.EMOJI="emoji",n.COMPONENT="blok",n.TABLE="table",n.TABLE_ROW="tableRow",n.TABLE_CELL="tableCell",n.TABLE_HEADER="tableHeader",n))(b||{}),_=(n=>(n.BOLD="bold",n.STRONG="strong",n.STRIKE="strike",n.UNDERLINE="underline",n.ITALIC="italic",n.CODE="code",n.LINK="link",n.ANCHOR="anchor",n.STYLED="styled",n.SUPERSCRIPT="superscript",n.SUBSCRIPT="subscript",n.TEXT_STYLE="textStyle",n.HIGHLIGHT="highlight",n))(_||{}),N=(n=>(n.TEXT="text",n))(N||{}),S=(n=>(n.URL="url",n.STORY="story",n.ASSET="asset",n.EMAIL="email",n))(S||{});const oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ie=(n={})=>Object.keys(n).map(e=>`${e}="${n[e]}"`).join(" "),ae=(n={})=>Object.keys(n).map(e=>`${e}: ${n[e]}`).join("; ");function le(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=n=>Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0));function M(n,e={},t){const r=ie(e),s=r?`${n} ${r}`:n,o=Array.isArray(t)?t.join(""):t||"";if(n){if(oe.includes(n))return`<${s}>`}else return o;return`<${s}>${o}</${n}>`}function q(n={}){const e=new Map,{renderFn:t=M,textFn:r=le,resolvers:s={},optimizeImages:o=!1,keyedResolvers:c=!1}=n,l=t!==M,i=a=>(u,d)=>{const p=u.attrs||{};return d.render(a,p,u.children||null)},h=(a,u)=>{const{src:d,alt:p,title:m,srcset:w,sizes:v}=a.attrs||{};let k=d,R={};if(o){const{src:se,attrs:re}=ne(d,o);k=se,R=re}const te={src:k,alt:p,title:m,srcset:w,sizes:v,...R};return u.render("img",O(te))},f=(a,u)=>{const{level:d,...p}=a.attrs||{};return u.render(`h${d}`,p,a.children)},y=(a,u)=>{var d,p,m,w;const v=u.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=a.attrs)==null?void 0:m.name,"data-emoji":(w=a.attrs)==null?void 0:w.emoji},v)},$=(a,u)=>u.render("pre",a.attrs||{},u.render("code",{},a.children||"")),T=(a,u=!1)=>({text:d,attrs:p},m)=>{const{class:w,id:v,...k}=p||{},R=u?{class:w,id:v,style:ae(k)||void 0}:p||{};return m.render(a,O(R),d)},A=a=>C(a),I=a=>{const{marks:u,...d}=a;if("text"in a){if(u)return u.reduce((m,w)=>A({...w,text:m}),A({...d,children:d.children}));const p=a.attrs||{};if(c){const m=e.get("txt")||0;e.set("txt",m+1),p.key=`txt-${m}`}return r(d.text,p)}return""},U=(a,u)=>{const{linktype:d,href:p,anchor:m,...w}=a.attrs||{};let v="";switch(d){case S.ASSET:case S.URL:v=p;break;case S.EMAIL:v=`mailto:${p}`;break;case S.STORY:v=p,m&&(v=`${v}#${m}`);break;default:v=p;break}const k={...w};return v&&(k.href=v),u.render("a",k,a.text)},K=(a,u)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},W=(a,u)=>{const d={},p=u.render("tbody",{},a.children);return u.render("table",d,p)},X=(a,u)=>{const d={};return u.render("tr",d,a.children)},Q=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("td",O(k),a.children)},Z=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("th",O(k),a.children)},B=new Map([[b.DOCUMENT,i("")],[b.HEADING,f],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,$],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,K],[N.TEXT,I],[_.LINK,U],[_.ANCHOR,U],[_.STYLED,T("span",!0)],[_.BOLD,T("strong")],[_.TEXT_STYLE,T("span",!0)],[_.ITALIC,T("em")],[_.UNDERLINE,T("u")],[_.STRIKE,T("s")],[_.CODE,T("code")],[_.SUPERSCRIPT,T("sup")],[_.SUBSCRIPT,T("sub")],[_.HIGHLIGHT,T("mark")],[b.TABLE,W],[b.TABLE_ROW,X],[b.TABLE_CELL,Q],[b.TABLE_HEADER,Z]]),D=new Map([...B,...Object.entries(s).map(([a,u])=>[a,u])]),ee=()=>({render:(a,u={},d)=>{if(c&&a){const p=e.get(a)||0;e.set(a,p+1),u.key=`${a}-${p}`}return t(a,u,d)},originalResolvers:B,mergedResolvers:D});function L(a){const u=D.get(a.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=ee();if(a.type==="text")return u(a,d);const p=a.content?a.content.map(C):void 0;return u({...a,children:p},d)}function C(a){return a.type==="doc"?l?a.content.map(L):a.content.map(L).join(""):Array.isArray(a)?a.map(L):L(a)}return{render:C}}let z=!1;const F=[],J=n=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():F.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>t(s),r.onload=s=>{F.forEach(o=>o()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)});var ce=Object.defineProperty,he=(n,e,t)=>e in n?ce(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e,t)=>he(n,typeof e!="symbol"?e+"":e,t);class ue extends Error{constructor(e){super(e),this.name="AbortError"}}function de(n,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],o=0,c=!1;const l=async()=>{o++;const h=r.shift();if(h)try{const y=await n(...h.args);h.resolve(y)}catch(y){h.reject(y)}const f=setTimeout(()=>{o--,r.length>0&&l(),s=s.filter(y=>y!==f)},t);s.includes(f)||s.push(f)},i=(...h)=>c?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,y)=>{r.push({resolve:f,reject:y,args:h}),o<e&&l()});return i.abort=()=>{c=!0,s.forEach(clearTimeout),s=[],r.forEach(h=>h.reject(()=>new ue("Throttle function aborted"))),r.length=0},i}const pe=(n="")=>n.includes("/cdn/"),fe=(n,e=25,t=1)=>({...n,per_page:e,page:t}),ye=n=>new Promise(e=>setTimeout(e,n)),ge=(n=0,e)=>Array.from({length:n},e),me=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return ge(t,(s,o)=>o*r+n)},be=async(n,e)=>Promise.all(n.map(e)),ve=(n=[],e)=>n.map(e).reduce((t,r)=>[...t,...r],[]),H=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s];if(o==null)continue;const c=t?"":encodeURIComponent(s);let l;typeof o=="object"?l=H(o,e?e+encodeURIComponent(`[${c}]`):c,Array.isArray(o)):l=`${e?e+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(o)}`,r.push(l)}return r.join("&")},G=n=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[n]??e.eu};class ke{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${H(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:c}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const i=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:c,...this.fetchOptions});this.timeout&&clearTimeout(l);const h=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(i){return{message:i}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}}const V="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"},we={DRAFT:"draft"};let j={};const E={};class Te{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const c=e.https===!1?"http":"https";e.oauthToken?r=`${c}://${G(e.region)}/v1`:r=`${c}://${G(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([c,l])=>{s.set(c,l)}),s.has(V)||(s.set(V,P.defaultAgentName),s.set(P.defaultAgentVersion,P.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=de(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.DRAFT,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return pe(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const c=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,c,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;t.version=t.version||this.version;const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,c=`/${e}`.replace(/\/$/,""),l=r??c.substring(c.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,h=await this.makeRequest(c,t,o,i,s),f=h.total?Math.ceil(h.total/o):1,y=await be(me(i,f),$=>this.makeRequest(c,t,o,$+1,s));return ve([h,...y],$=>Object.values($.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(c=>c.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,c="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,i)=>s(l,`${c}[${i}]`));else if(typeof o=="object")for(const l in o){const i=c?`${c}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],i)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.link_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.rel_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let c=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(c=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],c,r);e.story?this.iterateTree(e.story,c,r):e.stories.forEach(l=>{this.iterateTree(l,c,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=H({url:e,params:t}),c=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await c.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,i)=>{var h;try{const f=await this.throttle("get",e,t,s);if(f.status!==200)return i(f);let y={data:f.data,headers:f.headers};if((h=f.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:f.headers["per-page"]?Number.parseInt(f.headers["per-page"]):0,total:f.headers["per-page"]?Number.parseInt(f.headers.total):0})),y.data.story||y.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${T}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await c.set(o,y);const $=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&($&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(f){if(f.response&&f.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(i);i(f)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}}const Re=(n={})=>{const{apiOptions:e}=n;if(!e||!e.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 Te(e)}},_e=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let x="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(n,e,t={})=>{var r;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((r=window.location)==null?void 0:r.href).searchParams.get("_storyblok"),c=o!==null&&+o===n;if(!(!s||!c)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{var i;l&&(l.action==="input"&&((i=l.story)==null?void 0:i.id)===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload())})})}},$e=(n={})=>{var e,t;const{bridge:r,accessToken:s,use:o=[],apiOptions:c={},bridgeUrl:l}=n;c.accessToken=c.accessToken||s;const i={bridge:r,apiOptions:c};let h={};o.forEach(y=>{h={...h,...y(i)}}),l&&(x=l);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return r!==!1&&f&&J(x),h};function Ee(n,e){return q(e).render(n)}const Ae=()=>J(x);exports.BlockTypes=b;exports.MarkTypes=_;exports.TextTypes=N;exports.apiPlugin=Re;exports.loadStoryblokBridge=Ae;exports.registerStoryblokBridge=Y;exports.renderRichText=Ee;exports.richTextResolver=q;exports.storyblokEditable=_e;exports.storyblokInit=$e;exports.useStoryblokBridge=Y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function oe(n,e){if(!e)return{src:n,attrs:{}};let t=0,r=0;const s={},o=[];function c(i,h,f,y,$){typeof i!="number"||i<=h||i>=f?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`):$.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(s.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(s.height=e.height,r=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(s.loading=e.loading),e.class&&(s.class=e.class),e.filters){const{filters:i}=e||{},{blur:h,brightness:f,fill:y,format:$,grayscale:T,quality:A,rotate:I}=i||{};h&&c(h,0,100,"blur",o),A&&c(A,0,100,"quality",o),f&&c(f,0,100,"brightness",o),y&&o.push(`fill(${y})`),T&&o.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&o.push(`rotate(${I})`),$&&["webp","png","jpeg"].includes($)&&o.push(`format(${$})`)}e.srcset&&(s.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${n}/m/${i}x0/${o.length>0?`filters:${o.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[h,f]=i;return`${n}/m/${h}x${f}/${o.length>0?`filters:${o.join(":")}`:""} ${h}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(s.sizes=e.sizes.join(", "))}let l=`${n}/m/`;return t>0&&r>0&&(l=`${l}${t}x${r}/`),o.length>0&&(l=`${l}filters:${o.join(":")}`),{src:l,attrs:s}}var b=(n=>(n.DOCUMENT="doc",n.HEADING="heading",n.PARAGRAPH="paragraph",n.QUOTE="blockquote",n.OL_LIST="ordered_list",n.UL_LIST="bullet_list",n.LIST_ITEM="list_item",n.CODE_BLOCK="code_block",n.HR="horizontal_rule",n.BR="hard_break",n.IMAGE="image",n.EMOJI="emoji",n.COMPONENT="blok",n.TABLE="table",n.TABLE_ROW="tableRow",n.TABLE_CELL="tableCell",n.TABLE_HEADER="tableHeader",n))(b||{}),_=(n=>(n.BOLD="bold",n.STRONG="strong",n.STRIKE="strike",n.UNDERLINE="underline",n.ITALIC="italic",n.CODE="code",n.LINK="link",n.ANCHOR="anchor",n.STYLED="styled",n.SUPERSCRIPT="superscript",n.SUBSCRIPT="subscript",n.TEXT_STYLE="textStyle",n.HIGHLIGHT="highlight",n))(_||{}),N=(n=>(n.TEXT="text",n))(N||{}),S=(n=>(n.URL="url",n.STORY="story",n.ASSET="asset",n.EMAIL="email",n))(S||{});const ie=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ae=(n={})=>Object.keys(n).map(e=>`${e}="${n[e]}"`).join(" "),le=(n={})=>Object.keys(n).map(e=>`${e}: ${n[e]}`).join("; ");function ce(n){return n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=n=>Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0));function M(n,e={},t){const r=ae(e),s=r?`${n} ${r}`:n,o=Array.isArray(t)?t.join(""):t||"";if(n){if(ie.includes(n))return`<${s}>`}else return o;return`<${s}>${o}</${n}>`}function F(n={}){const e=new Map,{renderFn:t=M,textFn:r=ce,resolvers:s={},optimizeImages:o=!1,keyedResolvers:c=!1}=n,l=t!==M,i=a=>(u,d)=>{const p=u.attrs||{};return d.render(a,p,u.children||null)},h=(a,u)=>{const{src:d,alt:p,title:m,srcset:w,sizes:v}=a.attrs||{};let k=d,R={};if(o){const{src:re,attrs:ne}=oe(d,o);k=re,R=ne}const se={src:k,alt:p,title:m,srcset:w,sizes:v,...R};return u.render("img",O(se))},f=(a,u)=>{const{level:d,...p}=a.attrs||{};return u.render(`h${d}`,p,a.children)},y=(a,u)=>{var d,p,m,w;const v=u.render("img",{src:(d=a.attrs)==null?void 0:d.fallbackImage,alt:(p=a.attrs)==null?void 0:p.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return u.render("span",{"data-type":"emoji","data-name":(m=a.attrs)==null?void 0:m.name,"data-emoji":(w=a.attrs)==null?void 0:w.emoji},v)},$=(a,u)=>u.render("pre",a.attrs||{},u.render("code",{},a.children||"")),T=(a,u=!1)=>({text:d,attrs:p},m)=>{const{class:w,id:v,...k}=p||{},R=u?{class:w,id:v,style:le(k)||void 0}:p||{};return m.render(a,O(R),d)},A=a=>C(a),I=a=>{const{marks:u,...d}=a;if("text"in a){if(u)return u.reduce((m,w)=>A({...w,text:m}),A({...d,children:d.children}));const p=a.attrs||{};if(c){const m=e.get("txt")||0;e.set("txt",m+1),p.key=`txt-${m}`}return r(d.text,p)}return""},U=(a,u)=>{const{linktype:d,href:p,anchor:m,...w}=a.attrs||{};let v="";switch(d){case S.ASSET:case S.URL:v=p;break;case S.EMAIL:v=`mailto:${p}`;break;case S.STORY:v=p,m&&(v=`${v}#${m}`);break;default:v=p;break}const k={...w};return v&&(k.href=v),u.render("a",k,a.text)},W=(a,u)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),u.render("span",{blok:(d=a==null?void 0:a.attrs)==null?void 0:d.body[0],id:(p=a.attrs)==null?void 0:p.id,style:"display: none"})},X=(a,u)=>{const d={},p=u.render("tbody",{},a.children);return u.render("table",d,p)},Q=(a,u)=>{const d={};return u.render("tr",d,a.children)},Z=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("td",O(k),a.children)},ee=(a,u)=>{const{colspan:d,rowspan:p,colwidth:m,backgroundColor:w,...v}=a.attrs||{},k={...v};d>1&&(k.colspan=d),p>1&&(k.rowspan=p);const R=[];return m&&R.push(`width: ${m}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(k.style=R.join(" ")),u.render("th",O(k),a.children)},B=new Map([[b.DOCUMENT,i("")],[b.HEADING,f],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,h],[b.EMOJI,y],[b.CODE_BLOCK,$],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,W],[N.TEXT,I],[_.LINK,U],[_.ANCHOR,U],[_.STYLED,T("span",!0)],[_.BOLD,T("strong")],[_.TEXT_STYLE,T("span",!0)],[_.ITALIC,T("em")],[_.UNDERLINE,T("u")],[_.STRIKE,T("s")],[_.CODE,T("code")],[_.SUPERSCRIPT,T("sup")],[_.SUBSCRIPT,T("sub")],[_.HIGHLIGHT,T("mark")],[b.TABLE,X],[b.TABLE_ROW,Q],[b.TABLE_CELL,Z],[b.TABLE_HEADER,ee]]),D=new Map([...B,...Object.entries(s).map(([a,u])=>[a,u])]),te=()=>({render:(a,u={},d)=>{if(c&&a){const p=e.get(a)||0;e.set(a,p+1),u.key=`${a}-${p}`}return t(a,u,d)},originalResolvers:B,mergedResolvers:D});function L(a){const u=D.get(a.type);if(!u)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";const d=te();if(a.type==="text")return u(a,d);const p=a.content?a.content.map(C):void 0;return u({...a,children:p},d)}function C(a){return a.type==="doc"?l?a.content.map(L):a.content.map(L).join(""):Array.isArray(a)?a.map(L):L(a)}return{render:C}}let z=!1;const G=[],Y=n=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?s():G.push(s)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>t(s),r.onload=s=>{G.forEach(o=>o()),z=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)});var he=Object.defineProperty,ue=(n,e,t)=>e in n?he(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,g=(n,e,t)=>ue(n,typeof e!="symbol"?e+"":e,t);class de extends Error{constructor(e){super(e),this.name="AbortError"}}function pe(n,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const r=[];let s=[],o=0,c=!1;const l=async()=>{o++;const h=r.shift();if(h)try{const y=await n(...h.args);h.resolve(y)}catch(y){h.reject(y)}const f=setTimeout(()=>{o--,r.length>0&&l(),s=s.filter(y=>y!==f)},t);s.includes(f)||s.push(f)},i=(...h)=>c?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((f,y)=>{r.push({resolve:f,reject:y,args:h}),o<e&&l()});return i.abort=()=>{c=!0,s.forEach(clearTimeout),s=[],r.forEach(h=>h.reject(()=>new de("Throttle function aborted"))),r.length=0},i}const V=(n="")=>n.includes("/cdn/"),fe=(n,e=25,t=1)=>({...n,per_page:e,page:t}),ye=n=>new Promise(e=>setTimeout(e,n)),ge=(n=0,e)=>Array.from({length:n},e),me=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return ge(t,(s,o)=>o*r+n)},be=async(n,e)=>Promise.all(n.map(e)),ve=(n=[],e)=>n.map(e).reduce((t,r)=>[...t,...r],[]),H=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s];if(o==null)continue;const c=t?"":encodeURIComponent(s);let l;typeof o=="object"?l=H(o,e?e+encodeURIComponent(`[${c}]`):c,Array.isArray(o)):l=`${e?e+encodeURIComponent(`[${c}]`):c}=${encodeURIComponent(o)}`,r.push(l)}return r.join("&")},q=n=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[n]??e.eu};class ke{constructor(e){g(this,"baseURL"),g(this,"timeout"),g(this,"headers"),g(this,"responseInterceptor"),g(this,"fetch"),g(this,"ejectInterceptor"),g(this,"url"),g(this,"parameters"),g(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t??{},this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${H(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),o=new AbortController,{signal:c}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const i=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:c,...this.fetchOptions});this.timeout&&clearTimeout(l);const h=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(i){return{message:i}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}}const J="SB-Agent",P={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},we={PUBLISHED:"published"};let j={};const E={};class Te{constructor(e,t){g(this,"client"),g(this,"maxRetries"),g(this,"retriesDelay"),g(this,"throttle"),g(this,"accessToken"),g(this,"cache"),g(this,"resolveCounter"),g(this,"relations"),g(this,"links"),g(this,"version"),g(this,"richTextResolver"),g(this,"resolveNestedRelations"),g(this,"stringifiedStoriesCache"),g(this,"inlineAssets");let r=e.endpoint||t;if(!r){const c=e.https===!1?"http":"https";e.oauthToken?r=`${c}://${q(e.region)}/v1`:r=`${c}://${q(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([c,l])=>{s.set(c,l)}),s.has(J)||(s.set(J,P.defaultAgentName),s.set(P.defaultAgentVersion,P.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=pe(this.throttledRequest.bind(this),o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return V(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const c=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,c,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;V(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,c=`/${e}`.replace(/\/$/,""),l=r??c.substring(c.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,h=await this.makeRequest(c,t,o,i,s),f=h.total?Math.ceil(h.total/o):1,y=await be(me(i,f),$=>this.makeRequest(c,t,o,$+1,s));return ve([h,...y],$=>Object.values($.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(c=>c.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,c="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,i)=>s(l,`${c}[${i}]`));else if(typeof o=="object")for(const l in o){const i=c?`${c}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],i)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.link_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(",")})).data.stories.forEach(h=>{s.push(h)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,c=[],l=50;for(let i=0;i<o;i+=l){const h=Math.min(o,i+l);c.push(e.rel_uuids.slice(i,h))}for(let i=0;i<c.length;i++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:c[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(h=>{s.push(h)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let c=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(c=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],c,r);e.story?this.iterateTree(e.story,c,r):e.stories.forEach(l=>{this.iterateTree(l,c,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=H({url:e,params:t}),c=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await c.get(o);if(l)return Promise.resolve(l)}return new Promise(async(l,i)=>{var h;try{const f=await this.throttle("get",e,t,s);if(f.status!==200)return i(f);let y={data:f.data,headers:f.headers};if((h=f.headers)!=null&&h["per-page"]&&(y=Object.assign({},y,{perPage:f.headers["per-page"]?Number.parseInt(f.headers["per-page"]):0,total:f.headers["per-page"]?Number.parseInt(f.headers.total):0})),y.data.story||y.data.stories){const T=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${T}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await c.set(o,y);const $=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&($&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(f){if(f.response&&f.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(i);i(f)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}}const Re=(n={})=>{const{apiOptions:e}=n;if(!e||!e.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 Te(e)}},_e=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};try{const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let x="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(n,e,t={})=>{var r;const s=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((r=window.location)==null?void 0:r.href).searchParams.get("_storyblok"),c=o!==null&&+o===n;if(!(!s||!c)){if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],l=>{var i;l&&(l.action==="input"&&((i=l.story)==null?void 0:i.id)===n?e(l.story):(l.action==="change"||l.action==="published")&&l.storyId===n&&window.location.reload())})})}},$e=(n={})=>{var e,t;const{bridge:r,accessToken:s,use:o=[],apiOptions:c={},bridgeUrl:l}=n;c.accessToken=c.accessToken||s;const i={bridge:r,apiOptions:c};let h={};o.forEach(y=>{h={...h,...y(i)}}),l&&(x=l);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return r!==!1&&f&&Y(x),h};function Ee(n,e){return F(e).render(n)}const Ae=()=>Y(x);exports.BlockTypes=b;exports.MarkTypes=_;exports.TextTypes=N;exports.apiPlugin=Re;exports.loadStoryblokBridge=Ae;exports.registerStoryblokBridge=K;exports.renderRichText=Ee;exports.richTextResolver=F;exports.storyblokEditable=_e;exports.storyblokInit=$e;exports.useStoryblokBridge=K;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function re(n, e) {
|
|
2
2
|
if (!e)
|
|
3
3
|
return { src: n, attrs: {} };
|
|
4
4
|
let t = 0, r = 0;
|
|
@@ -29,8 +29,8 @@ function se(n, e) {
|
|
|
29
29
|
attrs: s
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), $ = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))($ || {}),
|
|
33
|
-
const
|
|
32
|
+
var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), $ = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))($ || {}), J = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(J || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
|
|
33
|
+
const ne = [
|
|
34
34
|
"area",
|
|
35
35
|
"base",
|
|
36
36
|
"br",
|
|
@@ -45,23 +45,23 @@ const re = [
|
|
|
45
45
|
"source",
|
|
46
46
|
"track",
|
|
47
47
|
"wbr"
|
|
48
|
-
],
|
|
49
|
-
function
|
|
48
|
+
], oe = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), ie = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
|
|
49
|
+
function ae(n) {
|
|
50
50
|
return n.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
51
51
|
}
|
|
52
52
|
const O = (n) => Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0));
|
|
53
53
|
function D(n, e = {}, t) {
|
|
54
|
-
const r =
|
|
54
|
+
const r = oe(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
|
|
55
55
|
if (n) {
|
|
56
|
-
if (
|
|
56
|
+
if (ne.includes(n))
|
|
57
57
|
return `<${s}>`;
|
|
58
58
|
} else return o;
|
|
59
59
|
return `<${s}>${o}</${n}>`;
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function le(n = {}) {
|
|
62
62
|
const e = /* @__PURE__ */ new Map(), {
|
|
63
63
|
renderFn: t = D,
|
|
64
|
-
textFn: r =
|
|
64
|
+
textFn: r = ae,
|
|
65
65
|
resolvers: s = {},
|
|
66
66
|
optimizeImages: o = !1,
|
|
67
67
|
keyedResolvers: c = !1
|
|
@@ -72,10 +72,10 @@ function ae(n = {}) {
|
|
|
72
72
|
const { src: d, alt: p, title: m, srcset: w, sizes: b } = a.attrs || {};
|
|
73
73
|
let k = d, R = {};
|
|
74
74
|
if (o) {
|
|
75
|
-
const { src:
|
|
76
|
-
k =
|
|
75
|
+
const { src: te, attrs: se } = re(d, o);
|
|
76
|
+
k = te, R = se;
|
|
77
77
|
}
|
|
78
|
-
const
|
|
78
|
+
const ee = {
|
|
79
79
|
src: k,
|
|
80
80
|
alt: p,
|
|
81
81
|
title: m,
|
|
@@ -83,7 +83,7 @@ function ae(n = {}) {
|
|
|
83
83
|
sizes: b,
|
|
84
84
|
...R
|
|
85
85
|
};
|
|
86
|
-
return u.render("img", O(
|
|
86
|
+
return u.render("img", O(ee));
|
|
87
87
|
}, f = (a, u) => {
|
|
88
88
|
const { level: d, ...p } = a.attrs || {};
|
|
89
89
|
return u.render(`h${d}`, p, a.children);
|
|
@@ -109,7 +109,7 @@ function ae(n = {}) {
|
|
|
109
109
|
const { class: w, id: b, ...k } = p || {}, R = u ? {
|
|
110
110
|
class: w,
|
|
111
111
|
id: b,
|
|
112
|
-
style:
|
|
112
|
+
style: ie(k) || void 0
|
|
113
113
|
} : p || {};
|
|
114
114
|
return m.render(a, O(R), d);
|
|
115
115
|
}, A = (a) => C(a), S = (a) => {
|
|
@@ -148,27 +148,27 @@ function ae(n = {}) {
|
|
|
148
148
|
}
|
|
149
149
|
const k = { ...w };
|
|
150
150
|
return b && (k.href = b), u.render("a", k, a.text);
|
|
151
|
-
},
|
|
151
|
+
}, Y = (a, u) => {
|
|
152
152
|
var d, p;
|
|
153
153
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
|
|
154
154
|
blok: (d = a == null ? void 0 : a.attrs) == null ? void 0 : d.body[0],
|
|
155
155
|
id: (p = a.attrs) == null ? void 0 : p.id,
|
|
156
156
|
style: "display: none"
|
|
157
157
|
});
|
|
158
|
-
},
|
|
158
|
+
}, K = (a, u) => {
|
|
159
159
|
const d = {}, p = u.render("tbody", {}, a.children);
|
|
160
160
|
return u.render("table", d, p);
|
|
161
|
-
},
|
|
161
|
+
}, W = (a, u) => {
|
|
162
162
|
const d = {};
|
|
163
163
|
return u.render("tr", d, a.children);
|
|
164
|
-
},
|
|
164
|
+
}, X = (a, u) => {
|
|
165
165
|
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = a.attrs || {}, k = {
|
|
166
166
|
...b
|
|
167
167
|
};
|
|
168
168
|
d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
|
|
169
169
|
const R = [];
|
|
170
170
|
return m && R.push(`width: ${m}px;`), w && R.push(`background-color: ${w};`), R.length > 0 && (k.style = R.join(" ")), u.render("td", O(k), a.children);
|
|
171
|
-
},
|
|
171
|
+
}, Q = (a, u) => {
|
|
172
172
|
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = a.attrs || {}, k = {
|
|
173
173
|
...b
|
|
174
174
|
};
|
|
@@ -188,8 +188,8 @@ function ae(n = {}) {
|
|
|
188
188
|
[v.HR, i("hr")],
|
|
189
189
|
[v.BR, i("br")],
|
|
190
190
|
[v.QUOTE, i("blockquote")],
|
|
191
|
-
[v.COMPONENT,
|
|
192
|
-
[
|
|
191
|
+
[v.COMPONENT, Y],
|
|
192
|
+
[J.TEXT, S],
|
|
193
193
|
[$.LINK, H],
|
|
194
194
|
[$.ANCHOR, H],
|
|
195
195
|
[$.STYLED, T("span", !0)],
|
|
@@ -202,14 +202,14 @@ function ae(n = {}) {
|
|
|
202
202
|
[$.SUPERSCRIPT, T("sup")],
|
|
203
203
|
[$.SUBSCRIPT, T("sub")],
|
|
204
204
|
[$.HIGHLIGHT, T("mark")],
|
|
205
|
-
[v.TABLE,
|
|
206
|
-
[v.TABLE_ROW,
|
|
207
|
-
[v.TABLE_CELL,
|
|
208
|
-
[v.TABLE_HEADER,
|
|
205
|
+
[v.TABLE, K],
|
|
206
|
+
[v.TABLE_ROW, W],
|
|
207
|
+
[v.TABLE_CELL, X],
|
|
208
|
+
[v.TABLE_HEADER, Q]
|
|
209
209
|
]), B = new Map([
|
|
210
210
|
...U,
|
|
211
211
|
...Object.entries(s).map(([a, u]) => [a, u])
|
|
212
|
-
]),
|
|
212
|
+
]), Z = () => ({
|
|
213
213
|
render: (a, u = {}, d) => {
|
|
214
214
|
if (c && a) {
|
|
215
215
|
const p = e.get(a) || 0;
|
|
@@ -224,7 +224,7 @@ function ae(n = {}) {
|
|
|
224
224
|
const u = B.get(a.type);
|
|
225
225
|
if (!u)
|
|
226
226
|
return console.error("<Storyblok>", `No resolver found for node type ${a.type}`), "";
|
|
227
|
-
const d =
|
|
227
|
+
const d = Z();
|
|
228
228
|
if (a.type === "text")
|
|
229
229
|
return u(a, d);
|
|
230
230
|
const p = a.content ? a.content.map(C) : void 0;
|
|
@@ -241,7 +241,7 @@ function ae(n = {}) {
|
|
|
241
241
|
};
|
|
242
242
|
}
|
|
243
243
|
let M = !1;
|
|
244
|
-
const z = [],
|
|
244
|
+
const z = [], F = (n) => new Promise((e, t) => {
|
|
245
245
|
if (typeof window > "u") {
|
|
246
246
|
t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
247
247
|
return;
|
|
@@ -261,13 +261,13 @@ const z = [], q = (n) => new Promise((e, t) => {
|
|
|
261
261
|
z.forEach((o) => o()), M = !0, e(s);
|
|
262
262
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
263
263
|
});
|
|
264
|
-
var
|
|
265
|
-
class
|
|
264
|
+
var ce = Object.defineProperty, he = (n, e, t) => e in n ? ce(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t) => he(n, typeof e != "symbol" ? e + "" : e, t);
|
|
265
|
+
class ue extends Error {
|
|
266
266
|
constructor(e) {
|
|
267
267
|
super(e), this.name = "AbortError";
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
function
|
|
270
|
+
function de(n, e, t) {
|
|
271
271
|
if (!Number.isFinite(e))
|
|
272
272
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
273
273
|
if (!Number.isFinite(t))
|
|
@@ -301,11 +301,11 @@ function ue(n, e, t) {
|
|
|
301
301
|
});
|
|
302
302
|
return i.abort = () => {
|
|
303
303
|
c = !0, s.forEach(clearTimeout), s = [], r.forEach(
|
|
304
|
-
(h) => h.reject(() => new
|
|
304
|
+
(h) => h.reject(() => new ue("Throttle function aborted"))
|
|
305
305
|
), r.length = 0;
|
|
306
306
|
}, i;
|
|
307
307
|
}
|
|
308
|
-
const
|
|
308
|
+
const G = (n = "") => n.includes("/cdn/"), pe = (n, e = 25, t = 1) => ({
|
|
309
309
|
...n,
|
|
310
310
|
per_page: e,
|
|
311
311
|
page: t
|
|
@@ -329,7 +329,7 @@ const de = (n = "") => n.includes("/cdn/"), pe = (n, e = 25, t = 1) => ({
|
|
|
329
329
|
) : l = `${e ? e + encodeURIComponent(`[${c}]`) : c}=${encodeURIComponent(o)}`, r.push(l);
|
|
330
330
|
}
|
|
331
331
|
return r.join("&");
|
|
332
|
-
},
|
|
332
|
+
}, V = (n) => {
|
|
333
333
|
const e = {
|
|
334
334
|
eu: "api.storyblok.com",
|
|
335
335
|
us: "api-us.storyblok.com",
|
|
@@ -442,12 +442,12 @@ class ve {
|
|
|
442
442
|
});
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
const
|
|
445
|
+
const q = "SB-Agent", P = {
|
|
446
446
|
defaultAgentName: "SB-JS-CLIENT",
|
|
447
447
|
defaultAgentVersion: "SB-Agent-Version",
|
|
448
|
-
packageVersion: "
|
|
448
|
+
packageVersion: "7.0.0"
|
|
449
449
|
}, ke = {
|
|
450
|
-
|
|
450
|
+
PUBLISHED: "published"
|
|
451
451
|
};
|
|
452
452
|
let j = {};
|
|
453
453
|
const E = {};
|
|
@@ -462,21 +462,21 @@ class we {
|
|
|
462
462
|
let r = e.endpoint || t;
|
|
463
463
|
if (!r) {
|
|
464
464
|
const c = e.https === !1 ? "http" : "https";
|
|
465
|
-
e.oauthToken ? r = `${c}://${
|
|
465
|
+
e.oauthToken ? r = `${c}://${V(e.region)}/v1` : r = `${c}://${V(e.region)}/v2`;
|
|
466
466
|
}
|
|
467
467
|
const s = new Headers();
|
|
468
468
|
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([c, l]) => {
|
|
469
469
|
s.set(c, l);
|
|
470
|
-
}), s.has(
|
|
470
|
+
}), s.has(q) || (s.set(q, P.defaultAgentName), s.set(
|
|
471
471
|
P.defaultAgentVersion,
|
|
472
472
|
P.packageVersion
|
|
473
473
|
));
|
|
474
474
|
let o = 5;
|
|
475
|
-
e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle =
|
|
475
|
+
e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = de(
|
|
476
476
|
this.throttledRequest.bind(this),
|
|
477
477
|
o,
|
|
478
478
|
1e3
|
|
479
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ke.
|
|
479
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ke.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ve({
|
|
480
480
|
baseURL: r,
|
|
481
481
|
timeout: e.timeout || 0,
|
|
482
482
|
headers: s,
|
|
@@ -488,7 +488,7 @@ class we {
|
|
|
488
488
|
return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
489
489
|
}
|
|
490
490
|
factoryParamOptions(e, t) {
|
|
491
|
-
return
|
|
491
|
+
return G(e) ? this.parseParams(t) : t;
|
|
492
492
|
}
|
|
493
493
|
makeRequest(e, t, r, s, o) {
|
|
494
494
|
const c = this.factoryParamOptions(
|
|
@@ -500,7 +500,7 @@ class we {
|
|
|
500
500
|
get(e, t = {}, r) {
|
|
501
501
|
t || (t = {});
|
|
502
502
|
const s = `/${e}`;
|
|
503
|
-
t.version = t.version || this.version;
|
|
503
|
+
G(s) && (t.version = t.version || this.version);
|
|
504
504
|
const o = this.factoryParamOptions(s, t);
|
|
505
505
|
return this.cacheResponse(s, o, void 0, r);
|
|
506
506
|
}
|
|
@@ -877,21 +877,21 @@ const _e = (n, e, t = {}) => {
|
|
|
877
877
|
h = { ...h, ...y(i) };
|
|
878
878
|
}), l && (x = l);
|
|
879
879
|
const f = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
880
|
-
return r !== !1 && f &&
|
|
880
|
+
return r !== !1 && f && F(x), h;
|
|
881
881
|
};
|
|
882
882
|
function Ee(n, e) {
|
|
883
|
-
return
|
|
883
|
+
return le(e).render(n);
|
|
884
884
|
}
|
|
885
|
-
const Ae = () =>
|
|
885
|
+
const Ae = () => F(x);
|
|
886
886
|
export {
|
|
887
887
|
v as BlockTypes,
|
|
888
888
|
$ as MarkTypes,
|
|
889
|
-
|
|
889
|
+
J as TextTypes,
|
|
890
890
|
Te as apiPlugin,
|
|
891
891
|
Ae as loadStoryblokBridge,
|
|
892
892
|
_e as registerStoryblokBridge,
|
|
893
893
|
Ee as renderRichText,
|
|
894
|
-
|
|
894
|
+
le as richTextResolver,
|
|
895
895
|
Re as storyblokEditable,
|
|
896
896
|
$e as storyblokInit,
|
|
897
897
|
_e as useStoryblokBridge
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.1.
|
|
4
|
+
"version": "5.1.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
7
7
|
"author": "Storyblok",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "4.1.
|
|
47
|
+
"@storyblok/js": "4.1.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/core": "^7.27.1",
|