@webflow/data-types
Advanced tools
+6
-0
| # @webflow/data-types | ||
| ## 0.0.4 | ||
| ### Patch Changes | ||
| - Minor fixes | ||
| ## 0.0.3 | ||
@@ -4,0 +10,0 @@ |
+1
-1
@@ -1,1 +0,1 @@ | ||
| 'use strict';var s=(o=>(o.FEDERATION="FEDERATION",o))(s||{}),a=(o=>(o.React="React",o))(a||{}),u=(n=>(n.Client="Client",n.Server="Server",n))(u||{}),i=(p=>(p.Id="Id",p.Text="Text",p.TextBlock="TextBlock",p.RichText="RichText",p.Link="Link",p.Image="Image",p.Visibility="Visibility",p.Slot="Slot",p))(i||{});var l={Text:e=>({type:"Text",defaultValue:e?.defaultValue}),Id:()=>({type:"Id"}),Link:()=>({type:"Link"}),Image:()=>({type:"Image"}),Visibility:e=>({type:"Visibility",defaultValue:e?.defaultValue}),Slot:()=>({type:"Slot"}),TextBlock:()=>({type:"TextBlock"}),RichText:()=>({type:"RichText"})},f=Object.values(i).reduce((e,o)=>({...e,[o]:l[o]}),{});var t=class extends Error{constructor(o){super(`Invalid ComponentData: ${o}`),this.name="InvalidComponentDataError";}};function d(e){return typeof e=="string"&&Object.values(i).includes(e)}function y(e,o){if(e!=null){if(typeof e!="string")throw new t(`prop "${o}" defaultValue must be a string for Text type`);return e}}function m(e,o){if(e!=null){if(typeof e!="boolean")throw new t(`prop "${o}" defaultValue must be a boolean for Visibility type`);return e}}function c(e,o,n){if(e!==void 0)throw new t(`prop "${o}" defaultValue is not supported for ${n} type`)}function T(e,o){let n=e.type;switch(n){case "Text":return {type:"Text",defaultValue:y(e.defaultValue,o)};case "Visibility":return {type:"Visibility",defaultValue:m(e.defaultValue,o)};case "Id":case "Link":case "Image":case "Slot":case "TextBlock":case "RichText":return {type:n,defaultValue:c(e.defaultValue,o,n)};default:let r=n;throw new t(`prop "${o}" has invalid type: ${r}`)}}function P(e){if(!e||typeof e!="object")throw new t("props must be an object");let o={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!="object")throw new t(`prop "${n}" must be an object`);if(!("type"in r))throw new t(`prop "${n}" is missing required field: type`);if(!d(r.type))throw new t(`prop "${n}" has invalid type: ${String(r.type)}`);o[n]=T(r,n);}return o}function w(e){if(!e||typeof e!="object")throw new t("options must be an object");let o={};for(let[n,r]of Object.entries(e))if(n==="applyTagSelectors"){if(typeof r!="boolean")throw new t('option "applyTagSelectors" must be a boolean');o.applyTagSelectors=r;}return o}function x(e){if(!e||typeof e!="object")throw new t("input must be an object");if(!("name"in e))throw new t("missing required field: 'name'");if(typeof e.name!="string")throw new t("'name' must be a string");if(e.name==="")throw new t("'name' cannot be empty");let o={name:e.name};if("description"in e){if(typeof e.description!="string")throw new t("'description' must be a string when provided");o.description=e.description;}if("group"in e){if(typeof e.group!="string")throw new t("'group' must be a string when provided");o.group=e.group;}return "props"in e&&(o.props=P(e.props)),"options"in e&&(o.options=w(e.options)),o}exports.Environment=u;exports.Framework=a;exports.ModuleLoader=s;exports.PropType=i;exports.parseComponentData=x;exports.props=f; | ||
| 'use strict';var u=(t=>(t.FEDERATION="FEDERATION",t))(u||{}),l=(t=>(t.React="React",t))(l||{}),m=(n=>(n.Client="Client",n.Server="Server",n))(m||{}),s=(p=>(p.Id="Id",p.Text="Text",p.TextBlock="TextBlock",p.RichText="RichText",p.Link="Link",p.Image="Image",p.Visibility="Visibility",p.Slot="Slot",p))(s||{});var f={Text:e=>({type:"Text",defaultValue:e?.defaultValue,displayName:i(e)}),Id:e=>({type:"Id",displayName:i(e)}),Link:e=>({type:"Link",displayName:i(e)}),Image:e=>({type:"Image",displayName:i(e)}),Visibility:e=>({type:"Visibility",defaultValue:e?.defaultValue,displayName:i(e)}),Slot:e=>({type:"Slot",displayName:i(e)}),TextBlock:e=>({type:"TextBlock",displayName:i(e)}),RichText:e=>({type:"RichText",displayName:i(e)})},d=Object.values(s).reduce((e,t)=>({...e,[t]:f[t]}),{});function i(e){return [e.group,e.name.replaceAll("/","-")].filter(Boolean).join("/")}var o=class extends Error{constructor(t){super(`Invalid ComponentData: ${t}`),this.name="InvalidComponentDataError";}};function y(e){return typeof e=="string"&&Object.values(s).includes(e)}function a(e,t){if(typeof e!="string")throw new o(`prop "${t}" 'name' must be a string`);if(e==="")throw new o(`prop "${t}" 'name' cannot be empty`);return e}function c(e,t){if(e!=null){if(typeof e!="string")throw new o(`prop "${t}" defaultValue must be a string for Text type`);return e}}function T(e,t){if(e!=null){if(typeof e!="boolean")throw new o(`prop "${t}" defaultValue must be a boolean for Visibility type`);return e}}function w(e,t,n){if(e!==void 0)throw new o(`prop "${t}" defaultValue is not supported for ${n} type`)}function P(e,t){let n=e.type;switch(n){case "Text":return {type:"Text",displayName:a(e.displayName,t),defaultValue:c(e.defaultValue,t)};case "Visibility":return {type:"Visibility",displayName:a(e.displayName,t),defaultValue:T(e.defaultValue,t)};case "Id":case "Link":case "Image":case "Slot":case "TextBlock":case "RichText":return {type:n,displayName:a(e.displayName,t),defaultValue:w(e.defaultValue,t,n)};default:let r=n;throw new o(`prop "${t}" has invalid type: ${r}`)}}function g(e){if(!e||typeof e!="object")throw new o("props must be an object");let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!="object")throw new o(`prop "${n}" must be an object`);if(!("type"in r))throw new o(`prop "${n}" is missing required field: type`);if(!y(r.type))throw new o(`prop "${n}" has invalid type: ${String(r.type)}`);t[n]=P(r,n);}return t}function x(e){if(!e||typeof e!="object")throw new o("options must be an object");let t={};for(let[n,r]of Object.entries(e))if(n==="applyTagSelectors"){if(typeof r!="boolean")throw new o('option "applyTagSelectors" must be a boolean');t.applyTagSelectors=r;}return t}function C(e){if(!e||typeof e!="object")throw new o("input must be an object");if(!("name"in e))throw new o("missing required field: 'name'");if(typeof e.name!="string")throw new o("'name' must be a string");if(e.name==="")throw new o("'name' cannot be empty");let t={name:e.name};if("description"in e){if(typeof e.description!="string")throw new o("'description' must be a string when provided");t.description=e.description;}if("group"in e){if(typeof e.group!="string")throw new o("'group' must be a string when provided");t.group=e.group;}return "props"in e&&(t.props=g(e.props)),"options"in e&&(t.options=x(e.options)),t}exports.Environment=m;exports.Framework=l;exports.ModuleLoader=u;exports.PropType=s;exports.parseComponentData=C;exports.props=d; |
+52
-46
@@ -34,44 +34,2 @@ /** | ||
| /** | ||
| * Webflow props definition constructor | ||
| */ | ||
| declare const props: { | ||
| Id: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.Id; | ||
| }; | ||
| Text: (opts?: { | ||
| defaultValue?: string | undefined; | ||
| } | undefined) => { | ||
| defaultValue?: string | undefined; | ||
| type: PropType.Text; | ||
| }; | ||
| TextBlock: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.TextBlock; | ||
| }; | ||
| RichText: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.RichText; | ||
| }; | ||
| Link: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.Link; | ||
| }; | ||
| Image: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.Image; | ||
| }; | ||
| Visibility: (opts?: { | ||
| defaultValue?: boolean | undefined; | ||
| } | undefined) => { | ||
| defaultValue?: boolean | undefined; | ||
| type: PropType.Visibility; | ||
| }; | ||
| Slot: (opts?: undefined) => { | ||
| defaultValue?: undefined; | ||
| type: PropType.Slot; | ||
| }; | ||
| }; | ||
| type PropValues<NodeType = unknown> = { | ||
@@ -100,8 +58,11 @@ [PropType.Id]: string; | ||
| type: T; | ||
| displayName: string; | ||
| } : T extends PropTypesWithOptionalDefaultValue ? { | ||
| defaultValue?: PropValues<NodeType>[T]; | ||
| type: T; | ||
| displayName: string; | ||
| } : T extends PropTypesWithoutDefaultValue ? { | ||
| defaultValue?: undefined; | ||
| type: T; | ||
| displayName: string; | ||
| } : never; | ||
@@ -119,2 +80,11 @@ type ComponentProps<P extends {}, NodeType> = { | ||
| }; | ||
| type ComponentRuntimeError = { | ||
| error: Error; | ||
| message: string; | ||
| stack?: string; | ||
| code?: string; | ||
| }; | ||
| type ComponentRuntimeOptions = { | ||
| onError?: (error: ComponentRuntimeError) => void; | ||
| }; | ||
| type ComponentOptions = { | ||
@@ -137,4 +107,4 @@ applyTagSelectors?: boolean; | ||
| mount: (domNode: Element) => RootType; | ||
| hydrate: (domNode: Element, props?: ComponentRuntimeProps<NodeType>) => RootType; | ||
| render: (root: RootType, props?: ComponentRuntimeProps<NodeType>) => void; | ||
| hydrate: (domNode: Element, props?: ComponentRuntimeProps<NodeType>, options?: ComponentRuntimeOptions) => RootType; | ||
| render: (root: RootType, props?: ComponentRuntimeProps<NodeType>, options?: ComponentRuntimeOptions) => void; | ||
| createSlot: (name: string) => NodeType; | ||
@@ -144,3 +114,3 @@ }; | ||
| type ComponentServerRenderer<StreamType, NodeType, StreamOptionsType> = { | ||
| renderToStream: (props?: ComponentRuntimeProps<NodeType>, options?: StreamOptionsType) => StreamType; | ||
| renderToStream: (props?: ComponentRuntimeProps<NodeType>, options?: ComponentRuntimeOptions, streamOptions?: StreamOptionsType) => StreamType; | ||
| createSlot: (name: string) => NodeType; | ||
@@ -167,3 +137,27 @@ }; | ||
| type BaseOptions = { | ||
| name: string; | ||
| group?: string; | ||
| }; | ||
| type PropOptions<T extends PropType> = T extends PropTypesWithRequiredDefaultValue ? { | ||
| defaultValue: PropValues[T]; | ||
| } & BaseOptions : T extends PropTypesWithOptionalDefaultValue ? { | ||
| defaultValue?: PropValues[T]; | ||
| } & BaseOptions : T extends PropTypesWithoutDefaultValue ? BaseOptions : never; | ||
| type PropConstructor<T extends PropType> = (opts: PropOptions<T>) => ComponentProp<T>; | ||
| /** | ||
| * Webflow props definition constructor | ||
| */ | ||
| declare const props: { | ||
| Id: PropConstructor<PropType.Id>; | ||
| Text: PropConstructor<PropType.Text>; | ||
| TextBlock: PropConstructor<PropType.TextBlock>; | ||
| RichText: PropConstructor<PropType.RichText>; | ||
| Link: PropConstructor<PropType.Link>; | ||
| Image: PropConstructor<PropType.Image>; | ||
| Visibility: PropConstructor<PropType.Visibility>; | ||
| Slot: PropConstructor<PropType.Slot>; | ||
| }; | ||
| /** | ||
| * Validates that input data is of type ComponentData | ||
@@ -173,2 +167,14 @@ */ | ||
| export { type ComponentClientRendererFactory, type ComponentData, type ComponentDefinition, type ComponentOptions, type ComponentProps, type ComponentRendererInterface, type ComponentRendererRuntimeModule, type ComponentRuntimeProps, type ComponentServerRendererFactory, Environment, Framework, ModuleLoader, PropType, type PropValues, parseComponentData, props }; | ||
| type SSRAnnotations = Record<string, string | number | Array<string | number>>; | ||
| type SSRManifest = { | ||
| metadata: { | ||
| annotations: SSRAnnotations; | ||
| }; | ||
| spec: { | ||
| identifier: string; | ||
| entrypoint: string; | ||
| type: "esm"; | ||
| }; | ||
| }; | ||
| export { type ComponentClientRendererFactory, type ComponentData, type ComponentDefinition, type ComponentOptions, type ComponentProps, type ComponentRendererInterface, type ComponentRendererRuntimeModule, type ComponentRuntimeError, type ComponentRuntimeOptions, type ComponentRuntimeProps, type ComponentServerRendererFactory, Environment, Framework, ModuleLoader, PropType, type PropValues, type SSRAnnotations, type SSRManifest, parseComponentData, props }; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var s=(o=>(o.FEDERATION="FEDERATION",o))(s||{}),a=(o=>(o.React="React",o))(a||{}),u=(n=>(n.Client="Client",n.Server="Server",n))(u||{}),i=(p=>(p.Id="Id",p.Text="Text",p.TextBlock="TextBlock",p.RichText="RichText",p.Link="Link",p.Image="Image",p.Visibility="Visibility",p.Slot="Slot",p))(i||{});var l={Text:e=>({type:"Text",defaultValue:e?.defaultValue}),Id:()=>({type:"Id"}),Link:()=>({type:"Link"}),Image:()=>({type:"Image"}),Visibility:e=>({type:"Visibility",defaultValue:e?.defaultValue}),Slot:()=>({type:"Slot"}),TextBlock:()=>({type:"TextBlock"}),RichText:()=>({type:"RichText"})},f=Object.values(i).reduce((e,o)=>({...e,[o]:l[o]}),{});var t=class extends Error{constructor(o){super(`Invalid ComponentData: ${o}`),this.name="InvalidComponentDataError";}};function d(e){return typeof e=="string"&&Object.values(i).includes(e)}function y(e,o){if(e!=null){if(typeof e!="string")throw new t(`prop "${o}" defaultValue must be a string for Text type`);return e}}function m(e,o){if(e!=null){if(typeof e!="boolean")throw new t(`prop "${o}" defaultValue must be a boolean for Visibility type`);return e}}function c(e,o,n){if(e!==void 0)throw new t(`prop "${o}" defaultValue is not supported for ${n} type`)}function T(e,o){let n=e.type;switch(n){case "Text":return {type:"Text",defaultValue:y(e.defaultValue,o)};case "Visibility":return {type:"Visibility",defaultValue:m(e.defaultValue,o)};case "Id":case "Link":case "Image":case "Slot":case "TextBlock":case "RichText":return {type:n,defaultValue:c(e.defaultValue,o,n)};default:let r=n;throw new t(`prop "${o}" has invalid type: ${r}`)}}function P(e){if(!e||typeof e!="object")throw new t("props must be an object");let o={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!="object")throw new t(`prop "${n}" must be an object`);if(!("type"in r))throw new t(`prop "${n}" is missing required field: type`);if(!d(r.type))throw new t(`prop "${n}" has invalid type: ${String(r.type)}`);o[n]=T(r,n);}return o}function w(e){if(!e||typeof e!="object")throw new t("options must be an object");let o={};for(let[n,r]of Object.entries(e))if(n==="applyTagSelectors"){if(typeof r!="boolean")throw new t('option "applyTagSelectors" must be a boolean');o.applyTagSelectors=r;}return o}function x(e){if(!e||typeof e!="object")throw new t("input must be an object");if(!("name"in e))throw new t("missing required field: 'name'");if(typeof e.name!="string")throw new t("'name' must be a string");if(e.name==="")throw new t("'name' cannot be empty");let o={name:e.name};if("description"in e){if(typeof e.description!="string")throw new t("'description' must be a string when provided");o.description=e.description;}if("group"in e){if(typeof e.group!="string")throw new t("'group' must be a string when provided");o.group=e.group;}return "props"in e&&(o.props=P(e.props)),"options"in e&&(o.options=w(e.options)),o}export{u as Environment,a as Framework,s as ModuleLoader,i as PropType,x as parseComponentData,f as props}; | ||
| var u=(t=>(t.FEDERATION="FEDERATION",t))(u||{}),l=(t=>(t.React="React",t))(l||{}),m=(n=>(n.Client="Client",n.Server="Server",n))(m||{}),s=(p=>(p.Id="Id",p.Text="Text",p.TextBlock="TextBlock",p.RichText="RichText",p.Link="Link",p.Image="Image",p.Visibility="Visibility",p.Slot="Slot",p))(s||{});var f={Text:e=>({type:"Text",defaultValue:e?.defaultValue,displayName:i(e)}),Id:e=>({type:"Id",displayName:i(e)}),Link:e=>({type:"Link",displayName:i(e)}),Image:e=>({type:"Image",displayName:i(e)}),Visibility:e=>({type:"Visibility",defaultValue:e?.defaultValue,displayName:i(e)}),Slot:e=>({type:"Slot",displayName:i(e)}),TextBlock:e=>({type:"TextBlock",displayName:i(e)}),RichText:e=>({type:"RichText",displayName:i(e)})},d=Object.values(s).reduce((e,t)=>({...e,[t]:f[t]}),{});function i(e){return [e.group,e.name.replaceAll("/","-")].filter(Boolean).join("/")}var o=class extends Error{constructor(t){super(`Invalid ComponentData: ${t}`),this.name="InvalidComponentDataError";}};function y(e){return typeof e=="string"&&Object.values(s).includes(e)}function a(e,t){if(typeof e!="string")throw new o(`prop "${t}" 'name' must be a string`);if(e==="")throw new o(`prop "${t}" 'name' cannot be empty`);return e}function c(e,t){if(e!=null){if(typeof e!="string")throw new o(`prop "${t}" defaultValue must be a string for Text type`);return e}}function T(e,t){if(e!=null){if(typeof e!="boolean")throw new o(`prop "${t}" defaultValue must be a boolean for Visibility type`);return e}}function w(e,t,n){if(e!==void 0)throw new o(`prop "${t}" defaultValue is not supported for ${n} type`)}function P(e,t){let n=e.type;switch(n){case "Text":return {type:"Text",displayName:a(e.displayName,t),defaultValue:c(e.defaultValue,t)};case "Visibility":return {type:"Visibility",displayName:a(e.displayName,t),defaultValue:T(e.defaultValue,t)};case "Id":case "Link":case "Image":case "Slot":case "TextBlock":case "RichText":return {type:n,displayName:a(e.displayName,t),defaultValue:w(e.defaultValue,t,n)};default:let r=n;throw new o(`prop "${t}" has invalid type: ${r}`)}}function g(e){if(!e||typeof e!="object")throw new o("props must be an object");let t={};for(let[n,r]of Object.entries(e)){if(!r||typeof r!="object")throw new o(`prop "${n}" must be an object`);if(!("type"in r))throw new o(`prop "${n}" is missing required field: type`);if(!y(r.type))throw new o(`prop "${n}" has invalid type: ${String(r.type)}`);t[n]=P(r,n);}return t}function x(e){if(!e||typeof e!="object")throw new o("options must be an object");let t={};for(let[n,r]of Object.entries(e))if(n==="applyTagSelectors"){if(typeof r!="boolean")throw new o('option "applyTagSelectors" must be a boolean');t.applyTagSelectors=r;}return t}function C(e){if(!e||typeof e!="object")throw new o("input must be an object");if(!("name"in e))throw new o("missing required field: 'name'");if(typeof e.name!="string")throw new o("'name' must be a string");if(e.name==="")throw new o("'name' cannot be empty");let t={name:e.name};if("description"in e){if(typeof e.description!="string")throw new o("'description' must be a string when provided");t.description=e.description;}if("group"in e){if(typeof e.group!="string")throw new o("'group' must be a string when provided");t.group=e.group;}return "props"in e&&(t.props=g(e.props)),"options"in e&&(t.options=x(e.options)),t}export{m as Environment,l as Framework,u as ModuleLoader,s as PropType,C as parseComponentData,d as props}; |
+1
-1
| { | ||
| "name": "@webflow/data-types", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
15653
10.97%169
3.05%