@storyblok/svelte 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -214,6 +214,51 @@ You can easily render rich text by using the `renderRichText`function that comes
214
214
  <div>{@html articleHTML}</div>
215
215
  ```
216
216
 
217
+ You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
218
+
219
+ ```js
220
+ import { RichTextSchema, storyblokInit } from "@storyblok/svelte";
221
+ import cloneDeep from "clone-deep";
222
+
223
+ const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
224
+ // ... and edit the nodes and marks, or add your own.
225
+ // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
226
+
227
+ storyblokInit({
228
+ accessToken: "<your-token>",
229
+ richText: {
230
+ schema: mySchema,
231
+ resolver: (component, blok) => {
232
+ switch (component) {
233
+ case "my-custom-component":
234
+ return `<div class="my-component-class">${blok.text}</div>`;
235
+ default:
236
+ return "Resolver not defined";
237
+ }
238
+ },
239
+ },
240
+ });
241
+ ```
242
+
243
+ You can also set a **custom Schema and component resolver only once** by passing the options as the second parameter to `renderRichText` function:
244
+
245
+ ```js
246
+ import { renderRichText } from "@storyblok/svelte";
247
+
248
+ renderRichText(blok.richTextField, {
249
+ schema: mySchema,
250
+ resolver: (component, blok) => {
251
+ switch (component) {
252
+ case "my-custom-component":
253
+ return `<div class="my-component-class">${blok.text}</div>`;
254
+ break;
255
+ default:
256
+ return `Component ${component} not found`;
257
+ }
258
+ },
259
+ });
260
+ ```
261
+
217
262
  ### Compatibility
218
263
 
219
264
  This plugin is for Svelte. Thus, it supports the [same browsers as Svelte 3](https://github.com/sveltejs/svelte/issues/558). In short: all modern browsers and IE10+.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="svelte/types/runtime/ambient" />
2
- export { useStoryblokBridge, apiPlugin, renderRichText } from "@storyblok/js";
2
+ export { useStoryblokBridge, apiPlugin, renderRichText, RichTextSchema, } from "@storyblok/js";
3
3
  import type { SbSvelteSDKOptions, StoryblokClient, SbBlokData } from "./types";
4
4
  export declare const storyblokEditable: (node: HTMLElement, value: SbBlokData) => {
5
5
  update(newValue: SbBlokData): void;
@@ -1,14 +1,14 @@
1
- (function(h,m){typeof exports=="object"&&typeof module!="undefined"?m(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],m):(h=typeof globalThis!="undefined"?globalThis:h||self,m(h.storyblokSvelte={},h.e))})(this,function(h,m){"use strict";function nt(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var st=nt(m),ot=Object.defineProperty,it=Object.defineProperties,at=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,lt=Object.prototype.hasOwnProperty,ct=Object.prototype.propertyIsEnumerable,q=(r,t,e)=>t in r?ot(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,d=(r,t)=>{for(var e in t||(t={}))lt.call(t,e)&&q(r,e,t[e]);if(I)for(var e of I(t))ct.call(t,e)&&q(r,e,t[e]);return r},R=(r,t)=>it(r,at(t));let L=!1;const B=[],ut=r=>new Promise((t,e)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}L?s():B.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const n=document.createElement("script");n.async=!0,n.src=r,n.id="storyblok-javascript-bridge",n.onerror=s=>e(s),n.onload=s=>{B.forEach(o=>o()),L=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(n)}),ht=function(r,t){if(!r)return null;let e={};for(let n in r){let s=r[n];t.indexOf(n)>-1&&s!==null&&(e[n]=s)}return e},ft=r=>r==="email";var dt={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(r){return{tag:["pre",{tag:"code",attrs:r.attrs}]}},hard_break(){return{singleTag:"br"}},heading(r){return{tag:`h${r.attrs.level}`}},image(r){return{singleTag:[{tag:"img",attrs:ht(r.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(r){const t=d({},r.attrs),{linktype:e="url"}=r.attrs;return ft(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled(r){return{tag:[{tag:"span",attrs:r.attrs}]}}}};const pt=function(r){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,n=RegExp(e.source);return r&&n.test(r)?r.replace(e,s=>t[s]):r};class gt{constructor(t){t||(t=dt),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(n=>{e+=this.renderNode(n)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const n=this.getMatchingNode(t);return n&&n.tag&&e.push(this.renderOpeningTag(n.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(pt(t.text)):n&&n.singleTag?e.push(this.renderTag(n.singleTag," /")):n&&n.html&&e.push(n.html),n&&n.tag&&e.push(this.renderClosingTag(n.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let o=`<${s.tag}`;if(s.attrs)for(let a in s.attrs){let i=s.attrs[a];i!==null&&(o+=` ${a}="${i}"`)}return`${o}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(n=>n.constructor===String?`</${n}>`:`</${n.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}/*!
1
+ (function(h,m){typeof exports=="object"&&typeof module!="undefined"?m(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],m):(h=typeof globalThis!="undefined"?globalThis:h||self,m(h.storyblokSvelte={},h.e))})(this,function(h,m){"use strict";function at(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var lt=at(m),ct=Object.defineProperty,ut=Object.defineProperties,ht=Object.getOwnPropertyDescriptors,q=Object.getOwnPropertySymbols,ft=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable,L=(r,t,e)=>t in r?ct(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,d=(r,t)=>{for(var e in t||(t={}))ft.call(t,e)&&L(r,e,t[e]);if(q)for(var e of q(t))dt.call(t,e)&&L(r,e,t[e]);return r},E=(r,t)=>ut(r,ht(t));let B=!1;const z=[],pt=r=>new Promise((t,e)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=o=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}B?o():z.push(o)},document.getElementById("storyblok-javascript-bridge")))return;const n=document.createElement("script");n.async=!0,n.src=r,n.id="storyblok-javascript-bridge",n.onerror=o=>e(o),n.onload=o=>{z.forEach(s=>s()),B=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(n)}),gt=function(r,t){if(!r)return null;let e={};for(let n in r){let o=r[n];t.indexOf(n)>-1&&o!==null&&(e[n]=o)}return e},mt=r=>r==="email";var D={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(r){return{tag:["pre",{tag:"code",attrs:r.attrs}]}},hard_break(){return{singleTag:"br"}},heading(r){return{tag:`h${r.attrs.level}`}},image(r){return{singleTag:[{tag:"img",attrs:gt(r.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(r){const t=d({},r.attrs),{linktype:e="url"}=r.attrs;return mt(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled(r){return{tag:[{tag:"span",attrs:r.attrs}]}}}};const yt=function(r){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,n=RegExp(e.source);return r&&n.test(r)?r.replace(e,o=>t[o]):r};class U{constructor(t){t||(t=D),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(n=>{e+=this.renderNode(n)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(o=>{const s=this.getMatchingMark(o);s&&e.push(this.renderOpeningTag(s.tag))});const n=this.getMatchingNode(t);return n&&n.tag&&e.push(this.renderOpeningTag(n.tag)),t.content?t.content.forEach(o=>{e.push(this.renderNode(o))}):t.text?e.push(yt(t.text)):n&&n.singleTag?e.push(this.renderTag(n.singleTag," /")):n&&n.html&&e.push(n.html),n&&n.tag&&e.push(this.renderClosingTag(n.tag)),t.marks&&t.marks.slice(0).reverse().forEach(o=>{const s=this.getMatchingMark(o);s&&e.push(this.renderClosingTag(s.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(o=>{if(o.constructor===String)return`<${o}${e}>`;{let s=`<${o.tag}`;if(o.attrs)for(let a in o.attrs){let i=o.attrs[a];i!==null&&(s+=` ${a}="${i}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(n=>n.constructor===String?`</${n}>`:`</${n.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}/*!
2
2
  * storyblok-js-client v4.5.2
3
3
  * Universal JavaScript SDK for Storyblok's API
4
4
  * (c) 2020-2022 Stobylok Team
5
- */function z(r){return typeof r=="number"&&r==r&&r!==1/0&&r!==-1/0}function D(r,t,e){if(!z(t))throw new TypeError("Expected `limit` to be a finite number");if(!z(e))throw new TypeError("Expected `interval` to be a finite number");var n=[],s=[],o=0,a=function(){o++;var l=setTimeout(function(){o--,n.length>0&&a(),s=s.filter(function(u){return u!==l})},e);s.indexOf(l)<0&&s.push(l);var c=n.shift();c.resolve(r.apply(c.self,c.args))},i=function(){var l=arguments,c=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:l,self:c}),o<t&&a()})};return i.abort=function(){s.forEach(clearTimeout),s=[],n.forEach(function(l){l.reject(new throttle.AbortError)}),n.length=0},i}D.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const mt=function(r,t){if(!r)return null;let e={};for(let n in r){let s=r[n];t.indexOf(n)>-1&&s!==null&&(e[n]=s)}return e};var yt={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:r=>({tag:`h${r.attrs.level}`}),image:r=>({singleTag:[{tag:"img",attrs:mt(r.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(r){const t=d({},r.attrs),{linktype:e="url"}=r.attrs;return e==="email"&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:r=>({tag:[{tag:"span",attrs:r.attrs}]})}};class kt{constructor(t){t||(t=yt),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(n=>{e+=this.renderNode(n)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const n=this.getMatchingNode(t);return n&&n.tag&&e.push(this.renderOpeningTag(n.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(function(s){const o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a=/[&<>"']/g,i=RegExp(a.source);return s&&i.test(s)?s.replace(a,l=>o[l]):s}(t.text)):n&&n.singleTag?e.push(this.renderTag(n.singleTag," /")):n&&n.html&&e.push(n.html),n&&n.tag&&e.push(this.renderClosingTag(n.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(n=>{if(n.constructor===String)return`<${n}${e}>`;{let s=`<${n.tag}`;if(n.attrs)for(let o in n.attrs){let a=n.attrs[o];a!==null&&(s+=` ${o}="${a}"`)}return`${s}${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){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}const _t=(r=0,t=r)=>{const e=Math.abs(t-r)||0,n=r<t?1:-1;return((s=0,o)=>[...Array(s)].map(o))(e,(s,o)=>o*n+r)},E=(r,t,e)=>{const n=[];for(const s in r){if(!Object.prototype.hasOwnProperty.call(r,s))continue;const o=r[s],a=e?"":encodeURIComponent(s);let i;i=typeof o=="object"?E(o,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(o)):(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(o),n.push(i)}return n.join("&")};let b={},g={};class bt{constructor(t,e){if(!e){let o=t.region?`-${t.region}`:"",a=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${a}://api${o}.storyblok.com/v2`:`${a}://api${o}.storyblok.com/v1`}let n=Object.assign({},t.headers),s=5;t.oauthToken!==void 0&&(n.Authorization=t.oauthToken,s=3),t.rateLimit!==void 0&&(s=t.rateLimit),this.richTextResolver=new kt(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=D(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=st.default.create({baseURL:e,timeout:t.timeout||0,headers:n,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(o=>t.responseInterceptor(o)),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let n="";return e.attrs.body.forEach(s=>{n+=t(s.component,s)}),{html:n}})}parseParams(t={}){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e={}){return((n="")=>n.indexOf("/cdn/")>-1)(t)?this.parseParams(e):e}makeRequest(t,e,n,s){const o=this.factoryParamOptions(t,((a={},i=25,l=1)=>R(d({},a),{per_page:i,page:l}))(e,n,s));return this.cacheResponse(t,o)}get(t,e){let n=`/${t}`;const s=this.factoryParamOptions(n,e);return this.cacheResponse(n,s)}async getAll(t,e={},n){const s=e.per_page||25,o=`/${t}`,a=o.split("/");n=n||a[a.length-1];const i=await this.makeRequest(o,e,s,1),l=Math.ceil(i.total/s);return((c=[],u)=>c.map(u).reduce((f,T)=>[...f,...T],[]))([i,...await(async(c=[],u)=>Promise.all(c.map(u)))(_t(1,l),async c=>this.makeRequest(o,e,s,c+1))],c=>Object.values(c.data[n]))}post(t,e){let n=`/${t}`;return this.throttle("post",n,e)}put(t,e){let n=`/${t}`;return this.throttle("put",n,e)}delete(t,e){let n=`/${t}`;return this.throttle("delete",n,e)}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}setToken(t){this.accessToken=t}getToken(){return this.accessToken}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const n=t[e];n&&n.fieldtype=="multilink"&&n.linktype=="story"&&typeof n.id=="string"&&this.links[n.id]?n.story=this._cleanCopy(this.links[n.id]):n&&n.linktype==="story"&&typeof n.uuid=="string"&&this.links[n.uuid]&&(n.story=this._cleanCopy(this.links[n.uuid]))}_insertRelations(t,e,n){if(n.indexOf(t.component+"."+e)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e].constructor===Array){let s=[];t[e].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),t[e]=s}}}_insertAssetsRelations(t,e){e.forEach(n=>{t.id===n.id&&(t.original=n,t.original.filename=t.filename,t.original.filename=t.original.filename.includes("https://s3.amazonaws.com/")?t.original.filename:t.original.filename.replace("https://","https://s3.amazonaws.com/"),delete t.original.s3_filename)})}iterateTree(t,e){let n=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)n(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,e),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),n(s[o])}}};n(t.content)}async resolveLinks(t,e){let n=[];if(t.link_uuids){const s=t.link_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const l=Math.min(s,i+a);o.push(t.link_uuids.slice(i,l))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:e.language,version:e.version,by_uuids:o[i].join(",")})).data.stories.forEach(l=>{n.push(l)})}else n=t.links;n.forEach(s=>{this.links[s.uuid]=R(d({},s),{_stopResolving:!0})})}async resolveRelations(t,e){let n=[];if(t.rel_uuids){const s=t.rel_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const l=Math.min(s,i+a);o.push(t.rel_uuids.slice(i,l))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:e.language,version:e.version,by_uuids:o[i].join(",")})).data.stories.forEach(l=>{n.push(l)})}else n=t.rels;n.forEach(s=>{this.relations[s.uuid]=R(d({},s),{_stopResolving:!0})})}async resolveStories(t,e){let n=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(t.rels||t.rel_uuids)&&(n=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&(t.links||t.link_uuids)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],n);t.story?this.iterateTree(t.story,n):t.stories.forEach(s=>{this.iterateTree(s,n)})}resolveAssetsRelations(t){const{assets:e,stories:n,story:s}=t;if(n)for(const o of n)this.iterateTree(o,e);else{if(!s)return t;this.iterateTree(s,e)}}cacheResponse(t,e,n){return n===void 0&&(n=0),new Promise(async(s,o)=>{let a=E({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 c=await i.get(a);if(c)return s(c)}try{let c=await this.throttle("get",t,{params:e,paramsSerializer:f=>E(f)}),u={data:c.data,headers:c.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),c.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(c.headers["per-page"]),total:parseInt(c.headers.total)})),c.status!=200)return o(c);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&i.set(a,u),u.data.cv&&(e.version=="draft"&&g[e.token]!=u.data.cv&&this.flushCache(),g[e.token]=u.data.cv),s(u)}catch(c){if(c.response&&c.response.status===429&&(n+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${n} seconds.`),await(l=1e3*n,new Promise(u=>setTimeout(u,l))),this.cacheResponse(t,e,n).then(s).catch(o);o(c)}var l})}throttledRequest(t,e,n){return this.client[t](e,n)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){return this.cache.type==="memory"?{get:t=>b[t],getAll:()=>b,set(t,e){b[t]=e},flush(){b={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const vt=(r={})=>{const{apiOptions:t}=r;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 bt(t)}};var wt=r=>{if(typeof r!="object"||typeof r._editable=="undefined")return{};const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const $t=new gt,Tt="https://app.storyblok.com/f/storyblok-v2-latest.js",Rt=(r,t,e={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!r){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],s=>{s.story.id===r&&(s.action==="input"?t(s.story):window.location.reload())})})}},Et=(r={})=>{const{bridge:t,accessToken:e,use:n=[],apiOptions:s={}}=r;s.accessToken=s.accessToken||e;const o={bridge:t,apiOptions:s};let a={};return n.forEach(i=>{a=d(d({},a),i(o))}),t!==!1&&ut(Tt),a},Ot=r=>r===""?"":r?$t.render(r):(console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
5
+ */function H(r){return typeof r=="number"&&r==r&&r!==1/0&&r!==-1/0}function V(r,t,e){if(!H(t))throw new TypeError("Expected `limit` to be a finite number");if(!H(e))throw new TypeError("Expected `interval` to be a finite number");var n=[],o=[],s=0,a=function(){s++;var l=setTimeout(function(){s--,n.length>0&&a(),o=o.filter(function(u){return u!==l})},e);o.indexOf(l)<0&&o.push(l);var c=n.shift();c.resolve(r.apply(c.self,c.args))},i=function(){var l=arguments,c=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:l,self:c}),s<t&&a()})};return i.abort=function(){o.forEach(clearTimeout),o=[],n.forEach(function(l){l.reject(new throttle.AbortError)}),n.length=0},i}V.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const kt=function(r,t){if(!r)return null;let e={};for(let n in r){let o=r[n];t.indexOf(n)>-1&&o!==null&&(e[n]=o)}return e};var _t={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:r=>({tag:`h${r.attrs.level}`}),image:r=>({singleTag:[{tag:"img",attrs:kt(r.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(r){const t=d({},r.attrs),{linktype:e="url"}=r.attrs;return e==="email"&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:r=>({tag:[{tag:"span",attrs:r.attrs}]})}};class bt{constructor(t){t||(t=_t),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(n=>{e+=this.renderNode(n)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(o=>{const s=this.getMatchingMark(o);s&&e.push(this.renderOpeningTag(s.tag))});const n=this.getMatchingNode(t);return n&&n.tag&&e.push(this.renderOpeningTag(n.tag)),t.content?t.content.forEach(o=>{e.push(this.renderNode(o))}):t.text?e.push(function(o){const s={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},a=/[&<>"']/g,i=RegExp(a.source);return o&&i.test(o)?o.replace(a,l=>s[l]):o}(t.text)):n&&n.singleTag?e.push(this.renderTag(n.singleTag," /")):n&&n.html&&e.push(n.html),n&&n.tag&&e.push(this.renderClosingTag(n.tag)),t.marks&&t.marks.slice(0).reverse().forEach(o=>{const s=this.getMatchingMark(o);s&&e.push(this.renderClosingTag(s.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(n=>{if(n.constructor===String)return`<${n}${e}>`;{let o=`<${n.tag}`;if(n.attrs)for(let s in n.attrs){let a=n.attrs[s];a!==null&&(o+=` ${s}="${a}"`)}return`${o}${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){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}const vt=(r=0,t=r)=>{const e=Math.abs(t-r)||0,n=r<t?1:-1;return((o=0,s)=>[...Array(o)].map(s))(e,(o,s)=>s*n+r)},S=(r,t,e)=>{const n=[];for(const o in r){if(!Object.prototype.hasOwnProperty.call(r,o))continue;const s=r[o],a=e?"":encodeURIComponent(o);let i;i=typeof s=="object"?S(s,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(s)):(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(s),n.push(i)}return n.join("&")};let b={},g={};class wt{constructor(t,e){if(!e){let s=t.region?`-${t.region}`:"",a=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${a}://api${s}.storyblok.com/v2`:`${a}://api${s}.storyblok.com/v1`}let n=Object.assign({},t.headers),o=5;t.oauthToken!==void 0&&(n.Authorization=t.oauthToken,o=3),t.rateLimit!==void 0&&(o=t.rateLimit),this.richTextResolver=new bt(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=V(this.throttledRequest,o,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=lt.default.create({baseURL:e,timeout:t.timeout||0,headers:n,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(s=>t.responseInterceptor(s)),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let n="";return e.attrs.body.forEach(o=>{n+=t(o.component,o)}),{html:n}})}parseParams(t={}){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e={}){return((n="")=>n.indexOf("/cdn/")>-1)(t)?this.parseParams(e):e}makeRequest(t,e,n,o){const s=this.factoryParamOptions(t,((a={},i=25,l=1)=>E(d({},a),{per_page:i,page:l}))(e,n,o));return this.cacheResponse(t,s)}get(t,e){let n=`/${t}`;const o=this.factoryParamOptions(n,e);return this.cacheResponse(n,o)}async getAll(t,e={},n){const o=e.per_page||25,s=`/${t}`,a=s.split("/");n=n||a[a.length-1];const i=await this.makeRequest(s,e,o,1),l=Math.ceil(i.total/o);return((c=[],u)=>c.map(u).reduce((f,R)=>[...f,...R],[]))([i,...await(async(c=[],u)=>Promise.all(c.map(u)))(vt(1,l),async c=>this.makeRequest(s,e,o,c+1))],c=>Object.values(c.data[n]))}post(t,e){let n=`/${t}`;return this.throttle("post",n,e)}put(t,e){let n=`/${t}`;return this.throttle("put",n,e)}delete(t,e){let n=`/${t}`;return this.throttle("delete",n,e)}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}setToken(t){this.accessToken=t}getToken(){return this.accessToken}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const n=t[e];n&&n.fieldtype=="multilink"&&n.linktype=="story"&&typeof n.id=="string"&&this.links[n.id]?n.story=this._cleanCopy(this.links[n.id]):n&&n.linktype==="story"&&typeof n.uuid=="string"&&this.links[n.uuid]&&(n.story=this._cleanCopy(this.links[n.uuid]))}_insertRelations(t,e,n){if(n.indexOf(t.component+"."+e)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e].constructor===Array){let o=[];t[e].forEach(s=>{this.relations[s]&&o.push(this._cleanCopy(this.relations[s]))}),t[e]=o}}}_insertAssetsRelations(t,e){e.forEach(n=>{t.id===n.id&&(t.original=n,t.original.filename=t.filename,t.original.filename=t.original.filename.includes("https://s3.amazonaws.com/")?t.original.filename:t.original.filename.replace("https://","https://s3.amazonaws.com/"),delete t.original.s3_filename)})}iterateTree(t,e){let n=o=>{if(o!=null){if(o.constructor===Array)for(let s=0;s<o.length;s++)n(o[s]);else if(o.constructor===Object){if(o._stopResolving)return;for(let s in o)o.component&&o._uid||o.type==="link"?(this._insertRelations(o,s,e),this._insertLinks(o,s)):"id"in o&&o.fieldtype==="asset"&&this._insertAssetsRelations(o,e),n(o[s])}}};n(t.content)}async resolveLinks(t,e){let n=[];if(t.link_uuids){const o=t.link_uuids.length;let s=[];const a=50;for(let i=0;i<o;i+=a){const l=Math.min(o,i+a);s.push(t.link_uuids.slice(i,l))}for(let i=0;i<s.length;i++)(await this.getStories({per_page:a,language:e.language,version:e.version,by_uuids:s[i].join(",")})).data.stories.forEach(l=>{n.push(l)})}else n=t.links;n.forEach(o=>{this.links[o.uuid]=E(d({},o),{_stopResolving:!0})})}async resolveRelations(t,e){let n=[];if(t.rel_uuids){const o=t.rel_uuids.length;let s=[];const a=50;for(let i=0;i<o;i+=a){const l=Math.min(o,i+a);s.push(t.rel_uuids.slice(i,l))}for(let i=0;i<s.length;i++)(await this.getStories({per_page:a,language:e.language,version:e.version,by_uuids:s[i].join(",")})).data.stories.forEach(l=>{n.push(l)})}else n=t.rels;n.forEach(o=>{this.relations[o.uuid]=E(d({},o),{_stopResolving:!0})})}async resolveStories(t,e){let n=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(t.rels||t.rel_uuids)&&(n=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&(t.links||t.link_uuids)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const o in this.relations)this.iterateTree(this.relations[o],n);t.story?this.iterateTree(t.story,n):t.stories.forEach(o=>{this.iterateTree(o,n)})}resolveAssetsRelations(t){const{assets:e,stories:n,story:o}=t;if(n)for(const s of n)this.iterateTree(s,e);else{if(!o)return t;this.iterateTree(o,e)}}cacheResponse(t,e,n){return n===void 0&&(n=0),new Promise(async(o,s)=>{let a=S({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 c=await i.get(a);if(c)return o(c)}try{let c=await this.throttle("get",t,{params:e,paramsSerializer:f=>S(f)}),u={data:c.data,headers:c.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),c.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(c.headers["per-page"]),total:parseInt(c.headers.total)})),c.status!=200)return s(c);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&i.set(a,u),u.data.cv&&(e.version=="draft"&&g[e.token]!=u.data.cv&&this.flushCache(),g[e.token]=u.data.cv),o(u)}catch(c){if(c.response&&c.response.status===429&&(n+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${n} seconds.`),await(l=1e3*n,new Promise(u=>setTimeout(u,l))),this.cacheResponse(t,e,n).then(o).catch(s);s(c)}var l})}throttledRequest(t,e,n){return this.client[t](e,n)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){return this.cache.type==="memory"?{get:t=>b[t],getAll:()=>b,set(t,e){b[t]=e},flush(){b={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const Tt=(r={})=>{const{apiOptions:t}=r;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 wt(t)}};var $t=r=>{if(typeof r!="object"||typeof r._editable=="undefined")return{};const t=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};let v;const Rt="https://app.storyblok.com/f/storyblok-v2-latest.js",Et=(r,t,e={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!r){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.story.id===r&&(o.action==="input"?t(o.story):window.location.reload())})})}},St=(r={})=>{const{bridge:t,accessToken:e,use:n=[],apiOptions:o={},richText:s={}}=r;o.accessToken=o.accessToken||e;const a={bridge:t,apiOptions:o};let i={};return n.forEach(l=>{i=d(d({},i),l(a))}),t!==!1&&pt(Rt),v=new U(s.schema),s.resolver&&J(v,s.resolver),i},J=(r,t)=>{r.addNode("blok",e=>{let n="";return e.attrs.body.forEach(o=>{n+=t(o.component,o)}),{html:n}})},xt=(r,t)=>{if(!v){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}if(r==="")return"";if(!r)return console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
6
6
 
7
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"");function U(){}function O(r,t){for(const e in t)r[e]=t[e];return r}function H(r){return r()}function V(){return Object.create(null)}function y(r){r.forEach(H)}function St(r){return typeof r=="function"}function jt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function xt(r){return Object.keys(r).length===0}function Pt(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function J(r,t){const e={};t=new Set(t);for(const n in r)!t.has(n)&&n[0]!=="$"&&(e[n]=r[n]);return e}function At(r,t,e){r.insertBefore(t,e||null)}function Y(r){r.parentNode.removeChild(r)}function Ct(r){return document.createTextNode(r)}function Mt(){return Ct("")}function Nt(r){return Array.from(r.childNodes)}let S;function k(r){S=r}const _=[],F=[],v=[],G=[],It=Promise.resolve();let j=!1;function qt(){j||(j=!0,It.then(K))}function x(r){v.push(r)}const P=new Set;let w=0;function K(){const r=S;do{for(;w<_.length;){const t=_[w];w++,k(t),Lt(t.$$)}for(k(null),_.length=0,w=0;F.length;)F.pop()();for(let t=0;t<v.length;t+=1){const e=v[t];P.has(e)||(P.add(e),e())}v.length=0}while(_.length);for(;G.length;)G.pop()();j=!1,P.clear(),k(r)}function Lt(r){if(r.fragment!==null){r.update(),y(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(x)}}const $=new Set;let p;function Bt(){p={r:0,c:[],p}}function zt(){p.r||y(p.c),p=p.p}function A(r,t){r&&r.i&&($.delete(r),r.i(t))}function Q(r,t,e,n){if(r&&r.o){if($.has(r))return;$.add(r),p.c.push(()=>{$.delete(r),n&&(e&&r.d(1),n())}),r.o(t)}else n&&n()}function Dt(r,t){const e={},n={},s={$$scope:1};let o=r.length;for(;o--;){const a=r[o],i=t[o];if(i){for(const l in a)l in i||(n[l]=1);for(const l in i)s[l]||(e[l]=i[l],s[l]=1);r[o]=i}else for(const l in a)s[l]=1}for(const a in n)a in e||(e[a]=void 0);return e}function Ut(r){return typeof r=="object"&&r!==null?r:{}}function W(r){r&&r.c()}function C(r,t,e,n){const{fragment:s,on_mount:o,on_destroy:a,after_update:i}=r.$$;s&&s.m(t,e),n||x(()=>{const l=o.map(H).filter(St);a?a.push(...l):y(l),r.$$.on_mount=[]}),i.forEach(x)}function M(r,t){const e=r.$$;e.fragment!==null&&(y(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Ht(r,t){r.$$.dirty[0]===-1&&(_.push(r),qt(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Vt(r,t,e,n,s,o,a,i=[-1]){const l=S;k(r);const c=r.$$={fragment:null,ctx:null,props:o,update:U,not_equal:s,bound:V(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:V(),dirty:i,skip_bound:!1,root:t.target||l.$$.root};a&&a(c.root);let u=!1;if(c.ctx=e?e(r,t.props||{},(f,T,...et)=>{const rt=et.length?et[0]:T;return c.ctx&&s(c.ctx[f],c.ctx[f]=rt)&&(!c.skip_bound&&c.bound[f]&&c.bound[f](rt),u&&Ht(r,f)),T}):[],c.update(),u=!0,y(c.before_update),c.fragment=n?n(c.ctx):!1,t.target){if(t.hydrate){const f=Nt(t.target);c.fragment&&c.fragment.l(f),f.forEach(Y)}else c.fragment&&c.fragment.c();t.intro&&A(r.$$.fragment),C(r,t.target,t.anchor,t.customElement),K()}k(l)}class Jt{$destroy(){M(this,1),this.$destroy=U}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const s=n.indexOf(e);s!==-1&&n.splice(s,1)}}$set(t){this.$$set&&!xt(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function Yt(r){let t,e,n;const s=[{blok:r[0]},r[2]];var o=r[1];function a(i){let l={};for(let c=0;c<s.length;c+=1)l=O(l,s[c]);return{props:l}}return o&&(t=new o(a())),{c(){t&&W(t.$$.fragment),e=Mt()},m(i,l){t&&C(t,i,l),At(i,e,l),n=!0},p(i,[l]){const c=l&5?Dt(s,[l&1&&{blok:i[0]},l&4&&Ut(i[2])]):{};if(o!==(o=i[1])){if(t){Bt();const u=t;Q(u.$$.fragment,1,0,()=>{M(u,1)}),zt()}o?(t=new o(a()),W(t.$$.fragment),A(t.$$.fragment,1),C(t,e.parentNode,e)):t=null}else o&&t.$set(c)},i(i){n||(t&&A(t.$$.fragment,i),n=!0)},o(i){t&&Q(t.$$.fragment,i),n=!1},d(i){i&&Y(e),t&&M(t,i)}}}function Ft(r,t,e){const n=["blok"];let s=J(t,n),o,{blok:a}=t;return a?o=tt(a.component):console.error("Please provide a 'blok' property to the StoryblokComponent"),r.$$set=i=>{t=O(O({},t),Pt(i)),e(2,s=J(t,n)),"blok"in i&&e(0,a=i.blok)},[a,o,s]}class Gt extends Jt{constructor(t){super(),Vt(this,t,Ft,Yt,jt,{blok:0})}}const Kt=(r,t)=>{const e=n=>{const s=wt(n);s["data-blok-c"]&&(r.setAttribute("data-blok-c",s["data-blok-c"]),r.setAttribute("data-blok-uid",s["data-blok-uid"]),r.classList.add("storyblok__outline"))};return e(t),{update(n){e(n)}}};let N=null;const X=()=>(N||console.log("You can't use getStoryblokApi if you're not loading apiPlugin."),N);let Z=null;const Qt=r=>{const{storyblokApi:t}=Et(r);N=t,Z=r.components||{}},tt=r=>{const t=Z[r];return t||console.error(`You didn't load the ${r} component. Please load it in storyblokInit. For example:
7
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"";let e=v;return t&&(e=new U(t.schema),t.resolver&&J(e,t.resolver)),e.render(r)};function Y(){}function x(r,t){for(const e in t)r[e]=t[e];return r}function F(r){return r()}function K(){return Object.create(null)}function y(r){r.forEach(F)}function Ot(r){return typeof r=="function"}function jt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Pt(r){return Object.keys(r).length===0}function At(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function G(r,t){const e={};t=new Set(t);for(const n in r)!t.has(n)&&n[0]!=="$"&&(e[n]=r[n]);return e}function Ct(r,t,e){r.insertBefore(t,e||null)}function Q(r){r.parentNode.removeChild(r)}function Mt(r){return document.createTextNode(r)}function Nt(){return Mt("")}function It(r){return Array.from(r.childNodes)}let O;function k(r){O=r}const _=[],W=[],w=[],X=[],qt=Promise.resolve();let j=!1;function Lt(){j||(j=!0,qt.then(Z))}function P(r){w.push(r)}const A=new Set;let T=0;function Z(){const r=O;do{for(;T<_.length;){const t=_[T];T++,k(t),Bt(t.$$)}for(k(null),_.length=0,T=0;W.length;)W.pop()();for(let t=0;t<w.length;t+=1){const e=w[t];A.has(e)||(A.add(e),e())}w.length=0}while(_.length);for(;X.length;)X.pop()();j=!1,A.clear(),k(r)}function Bt(r){if(r.fragment!==null){r.update(),y(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(P)}}const $=new Set;let p;function zt(){p={r:0,c:[],p}}function Dt(){p.r||y(p.c),p=p.p}function C(r,t){r&&r.i&&($.delete(r),r.i(t))}function tt(r,t,e,n){if(r&&r.o){if($.has(r))return;$.add(r),p.c.push(()=>{$.delete(r),n&&(e&&r.d(1),n())}),r.o(t)}else n&&n()}function Ut(r,t){const e={},n={},o={$$scope:1};let s=r.length;for(;s--;){const a=r[s],i=t[s];if(i){for(const l in a)l in i||(n[l]=1);for(const l in i)o[l]||(e[l]=i[l],o[l]=1);r[s]=i}else for(const l in a)o[l]=1}for(const a in n)a in e||(e[a]=void 0);return e}function Ht(r){return typeof r=="object"&&r!==null?r:{}}function et(r){r&&r.c()}function M(r,t,e,n){const{fragment:o,on_mount:s,on_destroy:a,after_update:i}=r.$$;o&&o.m(t,e),n||P(()=>{const l=s.map(F).filter(Ot);a?a.push(...l):y(l),r.$$.on_mount=[]}),i.forEach(P)}function N(r,t){const e=r.$$;e.fragment!==null&&(y(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Vt(r,t){r.$$.dirty[0]===-1&&(_.push(r),Lt(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Jt(r,t,e,n,o,s,a,i=[-1]){const l=O;k(r);const c=r.$$={fragment:null,ctx:null,props:s,update:Y,not_equal:o,bound:K(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:K(),dirty:i,skip_bound:!1,root:t.target||l.$$.root};a&&a(c.root);let u=!1;if(c.ctx=e?e(r,t.props||{},(f,R,...st)=>{const it=st.length?st[0]:R;return c.ctx&&o(c.ctx[f],c.ctx[f]=it)&&(!c.skip_bound&&c.bound[f]&&c.bound[f](it),u&&Vt(r,f)),R}):[],c.update(),u=!0,y(c.before_update),c.fragment=n?n(c.ctx):!1,t.target){if(t.hydrate){const f=It(t.target);c.fragment&&c.fragment.l(f),f.forEach(Q)}else c.fragment&&c.fragment.c();t.intro&&C(r.$$.fragment),M(r,t.target,t.anchor,t.customElement),Z()}k(l)}class Yt{$destroy(){N(this,1),this.$destroy=Y}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const o=n.indexOf(e);o!==-1&&n.splice(o,1)}}$set(t){this.$$set&&!Pt(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function Ft(r){let t,e,n;const o=[{blok:r[0]},r[2]];var s=r[1];function a(i){let l={};for(let c=0;c<o.length;c+=1)l=x(l,o[c]);return{props:l}}return s&&(t=new s(a())),{c(){t&&et(t.$$.fragment),e=Nt()},m(i,l){t&&M(t,i,l),Ct(i,e,l),n=!0},p(i,[l]){const c=l&5?Ut(o,[l&1&&{blok:i[0]},l&4&&Ht(i[2])]):{};if(s!==(s=i[1])){if(t){zt();const u=t;tt(u.$$.fragment,1,0,()=>{N(u,1)}),Dt()}s?(t=new s(a()),et(t.$$.fragment),C(t.$$.fragment,1),M(t,e.parentNode,e)):t=null}else s&&t.$set(c)},i(i){n||(t&&C(t.$$.fragment,i),n=!0)},o(i){t&&tt(t.$$.fragment,i),n=!1},d(i){i&&Q(e),t&&N(t,i)}}}function Kt(r,t,e){const n=["blok"];let o=G(t,n),s,{blok:a}=t;return a?s=ot(a.component):console.error("Please provide a 'blok' property to the StoryblokComponent"),r.$$set=i=>{t=x(x({},t),At(i)),e(2,o=G(t,n)),"blok"in i&&e(0,a=i.blok)},[a,s,o]}class Gt extends Yt{constructor(t){super(),Jt(this,t,Kt,Ft,jt,{blok:0})}}const Qt=(r,t)=>{const e=n=>{const o=$t(n);o["data-blok-c"]&&(r.setAttribute("data-blok-c",o["data-blok-c"]),r.setAttribute("data-blok-uid",o["data-blok-uid"]),r.classList.add("storyblok__outline"))};return e(t),{update(n){e(n)}}};let I=null;const rt=()=>(I||console.log("You can't use getStoryblokApi if you're not loading apiPlugin."),I);let nt=null;const Wt=r=>{const{storyblokApi:t}=St(r);I=t,nt=r.components||{}},ot=r=>{const t=nt[r];return t||console.error(`You didn't load the ${r} component. Please load it in storyblokInit. For example:
8
8
  storyblokInit({
9
9
  accessToken: "<your-token>",
10
10
  components: {
11
11
  "teaser": Teaser
12
12
  }
13
13
  })
14
- `),t};h.StoryblokComponent=Gt,h.apiPlugin=vt,h.getComponent=tt,h.getStoryblokApi=X,h.renderRichText=Ot,h.storyblokEditable=Kt,h.storyblokInit=Qt,h.useStoryblokApi=X,h.useStoryblokBridge=Rt,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
14
+ `),t};h.RichTextSchema=D,h.StoryblokComponent=Gt,h.apiPlugin=Tt,h.getComponent=ot,h.getStoryblokApi=rt,h.renderRichText=xt,h.storyblokEditable=Qt,h.storyblokInit=Wt,h.useStoryblokApi=rt,h.useStoryblokBridge=Et,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -683,7 +683,7 @@ var editable = (blok) => {
683
683
  "data-blok-uid": options.id + "-" + options.uid
684
684
  };
685
685
  };
686
- const resolver = new RichTextResolver();
686
+ let richTextResolver;
687
687
  const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
688
688
  const useStoryblokBridge = (id, cb, options = {}) => {
689
689
  if (typeof window === "undefined") {
@@ -710,7 +710,13 @@ const useStoryblokBridge = (id, cb, options = {}) => {
710
710
  });
711
711
  };
712
712
  const storyblokInit$1 = (pluginOptions = {}) => {
713
- const { bridge, accessToken, use = [], apiOptions = {} } = pluginOptions;
713
+ const {
714
+ bridge,
715
+ accessToken,
716
+ use = [],
717
+ apiOptions = {},
718
+ richText = {}
719
+ } = pluginOptions;
714
720
  apiOptions.accessToken = apiOptions.accessToken || accessToken;
715
721
  const options = { bridge, apiOptions };
716
722
  let result = {};
@@ -720,18 +726,44 @@ const storyblokInit$1 = (pluginOptions = {}) => {
720
726
  if (bridge !== false) {
721
727
  loadBridge(bridgeLatest);
722
728
  }
729
+ richTextResolver = new RichTextResolver(richText.schema);
730
+ if (richText.resolver) {
731
+ setComponentResolver(richTextResolver, richText.resolver);
732
+ }
723
733
  return result;
724
734
  };
725
- const renderRichText = (text2) => {
726
- if (text2 === "") {
735
+ const setComponentResolver = (resolver, resolveFn) => {
736
+ resolver.addNode("blok", (node) => {
737
+ let html = "";
738
+ node.attrs.body.forEach((blok) => {
739
+ html += resolveFn(blok.component, blok);
740
+ });
741
+ return {
742
+ html
743
+ };
744
+ });
745
+ };
746
+ const renderRichText = (data, options) => {
747
+ if (!richTextResolver) {
748
+ console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
749
+ return;
750
+ }
751
+ if (data === "") {
727
752
  return "";
728
- } else if (!text2) {
729
- console.warn(`${text2} is not a valid Richtext object. This might be because the value of the richtext field is empty.
753
+ } else if (!data) {
754
+ console.warn(`${data} is not a valid Richtext object. This might be because the value of the richtext field is empty.
730
755
 
731
756
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
732
757
  return "";
733
758
  }
734
- return resolver.render(text2);
759
+ let localResolver = richTextResolver;
760
+ if (options) {
761
+ localResolver = new RichTextResolver(options.schema);
762
+ if (options.resolver) {
763
+ setComponentResolver(localResolver, options.resolver);
764
+ }
765
+ }
766
+ return localResolver.render(data);
735
767
  };
736
768
  function noop() {
737
769
  }
@@ -1151,7 +1183,9 @@ const storyblokEditable = (node, value) => {
1151
1183
  let storyblokApiInstance = null;
1152
1184
  const useStoryblokApi = () => {
1153
1185
  if (!storyblokApiInstance) {
1154
- console.log(`You can't use getStoryblokApi if you're not loading apiPlugin.`);
1186
+ console.log(
1187
+ `You can't use getStoryblokApi if you're not loading apiPlugin.`
1188
+ );
1155
1189
  }
1156
1190
  return storyblokApiInstance;
1157
1191
  };
@@ -1175,4 +1209,4 @@ storyblokInit({
1175
1209
  }
1176
1210
  return component;
1177
1211
  };
1178
- export { StoryblokComponent, apiFactory as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, renderRichText, storyblokEditable, storyblokInit, useStoryblokApi, useStoryblokBridge };
1212
+ export { defaultHtmlSerializer as RichTextSchema, StoryblokComponent, apiFactory as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, renderRichText, storyblokEditable, storyblokInit, useStoryblokApi, useStoryblokBridge };
package/index.ts CHANGED
@@ -2,7 +2,12 @@ import {
2
2
  storyblokEditable as sbEdit,
3
3
  storyblokInit as sbInit,
4
4
  } from "@storyblok/js";
5
- export { useStoryblokBridge, apiPlugin, renderRichText } from "@storyblok/js";
5
+ export {
6
+ useStoryblokBridge,
7
+ apiPlugin,
8
+ renderRichText,
9
+ RichTextSchema,
10
+ } from "@storyblok/js";
6
11
 
7
12
  import type {
8
13
  SbSvelteSDKOptions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storyblok/svelte",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "Storyblok SDK to connect Storyblok with Svelte",
5
5
  "main": "./dist/storyblok-svelte.js",
6
6
  "module": "./dist/storyblok-svelte.mjs",
@@ -28,18 +28,18 @@
28
28
  "prepublishOnly": "npm run build && cp ../README.md ./"
29
29
  },
30
30
  "dependencies": {
31
- "@storyblok/js": "^1.7.2"
31
+ "@storyblok/js": "^1.8.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@babel/core": "^7.18.10",
34
+ "@babel/core": "^7.18.13",
35
35
  "@cypress/vite-dev-server": "^2.2.3",
36
36
  "@tsconfig/svelte": "^3.0.0",
37
37
  "babel-jest": "^28.1.3",
38
38
  "cypress": "^9.6.0",
39
39
  "cypress-svelte-unit-test": "^3.3.4",
40
40
  "eslint-plugin-cypress": "^2.12.1",
41
- "eslint-plugin-jest": "^26.8.3",
42
- "jest": "^27.5.1",
41
+ "eslint-plugin-jest": "^26.8.7",
42
+ "jest": "^29.0.2",
43
43
  "svelte-preprocess": "^4.10.7",
44
44
  "typescript": "^4.7.4",
45
45
  "vite": "^2.9.13"