@storyblok/astro 1.2.0 → 2.0.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/README.md +2 -0
- package/StoryblokComponent.astro +6 -0
- package/dist/index.d.ts +38 -0
- package/dist/node_modules/camelcase/index.d.ts +102 -0
- package/dist/node_modules/esbuild/lib/main.d.ts +611 -0
- package/dist/node_modules/rollup/dist/rollup.d.ts +936 -0
- package/dist/node_modules/vite/client.d.ts +272 -0
- package/dist/node_modules/vite/dist/node/index.d.ts +3281 -0
- package/dist/node_modules/vite/types/customEvent.d.ts +23 -0
- package/dist/node_modules/vite/types/hmrPayload.d.ts +61 -0
- package/dist/node_modules/vite/types/hot.d.ts +32 -0
- package/dist/node_modules/vite/types/importGlob.d.ts +97 -0
- package/dist/node_modules/vite/types/importMeta.d.ts +28 -0
- package/dist/storyblok-astro.js +8 -8
- package/dist/storyblok-astro.mjs +210 -239
- package/dist/types.d.ts +12 -0
- package/dist/vite-plugin-storyblok-components.d.ts +5 -0
- package/dist/vite-plugin-storyblok-init.d.ts +5 -0
- package/package.json +12 -8
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ErrorPayload,
|
|
3
|
+
FullReloadPayload,
|
|
4
|
+
PrunePayload,
|
|
5
|
+
UpdatePayload,
|
|
6
|
+
} from './hmrPayload'
|
|
7
|
+
|
|
8
|
+
export interface CustomEventMap {
|
|
9
|
+
'vite:beforeUpdate': UpdatePayload
|
|
10
|
+
'vite:afterUpdate': UpdatePayload
|
|
11
|
+
'vite:beforePrune': PrunePayload
|
|
12
|
+
'vite:beforeFullReload': FullReloadPayload
|
|
13
|
+
'vite:error': ErrorPayload
|
|
14
|
+
'vite:invalidate': InvalidatePayload
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface InvalidatePayload {
|
|
18
|
+
path: string
|
|
19
|
+
message: string | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type InferCustomEventPayload<T extends string> =
|
|
23
|
+
T extends keyof CustomEventMap ? CustomEventMap[T] : any
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export type HMRPayload =
|
|
2
|
+
| ConnectedPayload
|
|
3
|
+
| UpdatePayload
|
|
4
|
+
| FullReloadPayload
|
|
5
|
+
| CustomPayload
|
|
6
|
+
| ErrorPayload
|
|
7
|
+
| PrunePayload
|
|
8
|
+
|
|
9
|
+
export interface ConnectedPayload {
|
|
10
|
+
type: 'connected'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UpdatePayload {
|
|
14
|
+
type: 'update'
|
|
15
|
+
updates: Update[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Update {
|
|
19
|
+
type: 'js-update' | 'css-update'
|
|
20
|
+
path: string
|
|
21
|
+
acceptedPath: string
|
|
22
|
+
timestamp: number
|
|
23
|
+
/**
|
|
24
|
+
* @experimental internal
|
|
25
|
+
*/
|
|
26
|
+
explicitImportRequired?: boolean | undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface PrunePayload {
|
|
30
|
+
type: 'prune'
|
|
31
|
+
paths: string[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface FullReloadPayload {
|
|
35
|
+
type: 'full-reload'
|
|
36
|
+
path?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CustomPayload {
|
|
40
|
+
type: 'custom'
|
|
41
|
+
event: string
|
|
42
|
+
data?: any
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ErrorPayload {
|
|
46
|
+
type: 'error'
|
|
47
|
+
err: {
|
|
48
|
+
[name: string]: any
|
|
49
|
+
message: string
|
|
50
|
+
stack: string
|
|
51
|
+
id?: string
|
|
52
|
+
frame?: string
|
|
53
|
+
plugin?: string
|
|
54
|
+
pluginCode?: string
|
|
55
|
+
loc?: {
|
|
56
|
+
file?: string
|
|
57
|
+
line: number
|
|
58
|
+
column: number
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { InferCustomEventPayload } from './customEvent'
|
|
2
|
+
|
|
3
|
+
export type ModuleNamespace = Record<string, any> & {
|
|
4
|
+
[Symbol.toStringTag]: 'Module'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface ViteHotContext {
|
|
8
|
+
readonly data: any
|
|
9
|
+
|
|
10
|
+
accept(): void
|
|
11
|
+
accept(cb: (mod: ModuleNamespace | undefined) => void): void
|
|
12
|
+
accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
|
|
13
|
+
accept(
|
|
14
|
+
deps: readonly string[],
|
|
15
|
+
cb: (mods: Array<ModuleNamespace | undefined>) => void,
|
|
16
|
+
): void
|
|
17
|
+
|
|
18
|
+
acceptExports(
|
|
19
|
+
exportNames: string | readonly string[],
|
|
20
|
+
cb?: (mod: ModuleNamespace | undefined) => void,
|
|
21
|
+
): void
|
|
22
|
+
|
|
23
|
+
dispose(cb: (data: any) => void): void
|
|
24
|
+
prune(cb: (data: any) => void): void
|
|
25
|
+
invalidate(message?: string): void
|
|
26
|
+
|
|
27
|
+
on<T extends string>(
|
|
28
|
+
event: T,
|
|
29
|
+
cb: (payload: InferCustomEventPayload<T>) => void,
|
|
30
|
+
): void
|
|
31
|
+
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
|
|
32
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export interface ImportGlobOptions<
|
|
2
|
+
Eager extends boolean,
|
|
3
|
+
AsType extends string,
|
|
4
|
+
> {
|
|
5
|
+
/**
|
|
6
|
+
* Import type for the import url.
|
|
7
|
+
*/
|
|
8
|
+
as?: AsType
|
|
9
|
+
/**
|
|
10
|
+
* Import as static or dynamic
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
eager?: Eager
|
|
15
|
+
/**
|
|
16
|
+
* Import only the specific named export. Set to `default` to import the default export.
|
|
17
|
+
*/
|
|
18
|
+
import?: string
|
|
19
|
+
/**
|
|
20
|
+
* Custom queries
|
|
21
|
+
*/
|
|
22
|
+
query?: string | Record<string, string | number | boolean>
|
|
23
|
+
/**
|
|
24
|
+
* Search files also inside `node_modules/` and hidden directories (e.g. `.git/`). This might have impact on performance.
|
|
25
|
+
*
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
exhaustive?: boolean
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type GeneralImportGlobOptions = ImportGlobOptions<boolean, string>
|
|
32
|
+
|
|
33
|
+
export interface KnownAsTypeMap {
|
|
34
|
+
raw: string
|
|
35
|
+
url: string
|
|
36
|
+
worker: Worker
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface ImportGlobFunction {
|
|
40
|
+
/**
|
|
41
|
+
* Import a list of files with a glob pattern.
|
|
42
|
+
*
|
|
43
|
+
* Overload 1: No generic provided, infer the type from `eager` and `as`
|
|
44
|
+
*/
|
|
45
|
+
<
|
|
46
|
+
Eager extends boolean,
|
|
47
|
+
As extends string,
|
|
48
|
+
T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
|
|
49
|
+
>(
|
|
50
|
+
glob: string | string[],
|
|
51
|
+
options?: ImportGlobOptions<Eager, As>,
|
|
52
|
+
): (Eager extends true ? true : false) extends true
|
|
53
|
+
? Record<string, T>
|
|
54
|
+
: Record<string, () => Promise<T>>
|
|
55
|
+
/**
|
|
56
|
+
* Import a list of files with a glob pattern.
|
|
57
|
+
*
|
|
58
|
+
* Overload 2: Module generic provided, infer the type from `eager: false`
|
|
59
|
+
*/
|
|
60
|
+
<M>(
|
|
61
|
+
glob: string | string[],
|
|
62
|
+
options?: ImportGlobOptions<false, string>,
|
|
63
|
+
): Record<string, () => Promise<M>>
|
|
64
|
+
/**
|
|
65
|
+
* Import a list of files with a glob pattern.
|
|
66
|
+
*
|
|
67
|
+
* Overload 3: Module generic provided, infer the type from `eager: true`
|
|
68
|
+
*/
|
|
69
|
+
<M>(
|
|
70
|
+
glob: string | string[],
|
|
71
|
+
options: ImportGlobOptions<true, string>,
|
|
72
|
+
): Record<string, M>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ImportGlobEagerFunction {
|
|
76
|
+
/**
|
|
77
|
+
* Eagerly import a list of files with a glob pattern.
|
|
78
|
+
*
|
|
79
|
+
* Overload 1: No generic provided, infer the type from `as`
|
|
80
|
+
*/
|
|
81
|
+
<
|
|
82
|
+
As extends string,
|
|
83
|
+
T = As extends keyof KnownAsTypeMap ? KnownAsTypeMap[As] : unknown,
|
|
84
|
+
>(
|
|
85
|
+
glob: string | string[],
|
|
86
|
+
options?: Omit<ImportGlobOptions<boolean, As>, 'eager'>,
|
|
87
|
+
): Record<string, T>
|
|
88
|
+
/**
|
|
89
|
+
* Eagerly import a list of files with a glob pattern.
|
|
90
|
+
*
|
|
91
|
+
* Overload 2: Module generic provided
|
|
92
|
+
*/
|
|
93
|
+
<M>(
|
|
94
|
+
glob: string | string[],
|
|
95
|
+
options?: Omit<ImportGlobOptions<boolean, string>, 'eager'>,
|
|
96
|
+
): Record<string, M>
|
|
97
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// This file is an augmentation to the built-in ImportMeta interface
|
|
2
|
+
// Thus cannot contain any top-level imports
|
|
3
|
+
// <https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation>
|
|
4
|
+
|
|
5
|
+
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
6
|
+
|
|
7
|
+
interface ImportMetaEnv {
|
|
8
|
+
[key: string]: any
|
|
9
|
+
BASE_URL: string
|
|
10
|
+
MODE: string
|
|
11
|
+
DEV: boolean
|
|
12
|
+
PROD: boolean
|
|
13
|
+
SSR: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ImportMeta {
|
|
17
|
+
url: string
|
|
18
|
+
|
|
19
|
+
readonly hot?: import('./hot').ViteHotContext
|
|
20
|
+
|
|
21
|
+
readonly env: ImportMetaEnv
|
|
22
|
+
|
|
23
|
+
glob: import('./importGlob').ImportGlobFunction
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `import.meta.glob('*', { eager: true })` instead
|
|
26
|
+
*/
|
|
27
|
+
globEager: import('./importGlob').ImportGlobEagerFunction
|
|
28
|
+
}
|
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.storyblokAstro={}))})(this,function(l){"use strict";function c(t,e,r){const o="virtual:storyblok-init",s="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return`
|
|
2
2
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
3
3
|
const { storyblokApi } = storyblokInit({
|
|
4
|
-
accessToken: "${
|
|
4
|
+
accessToken: "${t}",
|
|
5
5
|
use: ${e?"[]":"[apiPlugin]"},
|
|
6
|
-
apiOptions: ${JSON.stringify(
|
|
6
|
+
apiOptions: ${JSON.stringify(r)},
|
|
7
7
|
});
|
|
8
|
-
export const storyblokApiInstance = storyblokApi;
|
|
9
|
-
`}}}const
|
|
8
|
+
export const storyblokApiInstance = storyblokApi;
|
|
9
|
+
`}}}const A=/[\p{Lu}]/u,E=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,g=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,w=new RegExp("^"+u.source),f=new RegExp(u.source+g.source,"gu"),h=new RegExp("\\d+"+g.source,"gu"),S=(t,e,r)=>{let o=!1,s=!1,n=!1;for(let a=0;a<t.length;a++){const i=t[a];o&&A.test(i)?(t=t.slice(0,a)+"-"+t.slice(a),o=!1,n=s,s=!0,a++):s&&n&&E.test(i)?(t=t.slice(0,a-1)+"-"+t.slice(a-1),n=s,s=!1,o=!0):(o=e(i)===i&&r(i)!==i,n=s,s=r(i)===i&&e(i)!==i)}return t},R=(t,e)=>(d.lastIndex=0,t.replace(d,r=>e(r))),_=(t,e)=>(f.lastIndex=0,h.lastIndex=0,t.replace(f,(r,o)=>e(o)).replace(h,r=>e(r)));function p(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(n=>n.trim()).filter(n=>n.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),o=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return t.length===1?u.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=S(t,r,o)),t=t.replace(w,""),t=e.preserveConsecutiveUppercase?R(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_(t,o))}function C(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const s=[];for await(const[n,a]of Object.entries(t)){const{id:i}=await this.resolve("/src/"+a+".astro");s.push(`import ${p(n)} from "${i}"`)}return`${s.join(";")};export default {${Object.keys(t).map(n=>p(n)).join(",")}}`}}}}var $=Object.defineProperty,b=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,y=(t,e,r)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e)=>{for(var r in e||(e={}))O.call(e,r)&&y(t,r,e[r]);if(b)for(var r of b(e))x.call(e,r)&&y(t,r,e[r]);return t};let m=!1;const k=[],j=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}m?s():k.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=s=>r(s),o.onload=s=>{k.forEach(n=>n()),m=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,L=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(L(t,typeof e!="symbol"?e+"":e,r),r);const M=function(t,e){const r={};for(const o in t){const s=t[o];e.indexOf(o)>-1&&s!==null&&(r[o]=s)}return r},U=t=>t==="email",B=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),z=()=>({tag:"ul"}),F=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),V=()=>({singleTag:"br"}),q=t=>({tag:`h${t.attrs.level}`}),J=t=>({singleTag:[{tag:"img",attrs:M(t.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),K=()=>({tag:"ol"}),H=()=>({tag:"p"}),W=()=>({tag:"b"}),Y=()=>({tag:"strike"}),Q=()=>({tag:"u"}),X=()=>({tag:"strong"}),Z=()=>({tag:"code"}),ee=()=>({tag:"i"}),te=t=>{const e=P({},t.attrs),{linktype:r="url"}=t.attrs;return U(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},re=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:B,blockquote:D,bullet_list:z,code_block:F,hard_break:V,heading:q,image:J,list_item:G,ordered_list:K,paragraph:H},marks:{bold:W,strike:Y,underline:Q,strong:X,code:Z,italic:ee,link:te,styled:re}},oe=function(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,s=>e[s]):t};class I{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(s=>{r.push(this.renderNode(s))}):e.text?r.push(oe(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderClosingTag(n.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${r}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}var se=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let ne;const ae="https://app.storyblok.com/f/storyblok-v2-latest.js",le=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(s=>{o+=e(s.component,s)}),{html:o}})},ie=(t,e,r)=>{let o=r||ne;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new I(e.schema),e.resolver&&le(o,e.resolver)),o.render(t)):(console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
10
10
|
|
|
11
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},
|
|
11
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},ce=()=>j(ae);function ue(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function de(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(t,e,r)}function ge(t={accessToken:"",useCustomApi:!1,apiOptions:{},bridge:!0,components:{}}){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:r})=>{r({vite:{plugins:[c(t.accessToken,t.useCustomApi,t.apiOptions),C(t.components)]}}),e("page-ssr",`
|
|
12
12
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
13
13
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
14
|
-
`),
|
|
14
|
+
`),t.bridge&&e("page",`
|
|
15
15
|
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
16
16
|
loadStoryblokBridge().then(() => {
|
|
17
17
|
const { StoryblokBridge, location } = window;
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
|
-
`)}}}}
|
|
26
|
+
`)}}}}l.RichTextResolver=I,l.RichTextSchema=T,l.default=ge,l.loadStoryblokBridge=ce,l.renderRichText=de,l.storyblokEditable=se,l.useStoryblokApi=ue,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|