@teleporthq/teleport-uidl-validator
Advanced tools
Comparing version 0.32.0-alpha.0 to 0.32.0
@@ -31,3 +31,3 @@ "use strict"; | ||
} | ||
var navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$'); | ||
var navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*'); | ||
if (navLinkRegex.test(link)) { | ||
@@ -41,3 +41,3 @@ return json_type_validation_1.Result.ok(link); | ||
return new CustomCombinators(function (json) { | ||
var fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$'); | ||
var fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$'); | ||
if (json && typeof json === 'string' && fileNameRegex.test(json)) { | ||
@@ -44,0 +44,0 @@ return json_type_validation_1.Result.ok(json); |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, VCMSListRepeaterElementNode, UIDLResourceMapper } from '@teleporthq/teleport-types'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails, VUIDLCMSMixedTypeNode, UIDLLocalFontAsset } from '@teleporthq/teleport-types'; | ||
export declare const referenceTypeDecoder: Decoder<ReferenceType>; | ||
@@ -14,2 +14,3 @@ export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>; | ||
export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>; | ||
export declare const injectValueDecoder: Decoder<UIDLInjectValue>; | ||
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>; | ||
@@ -28,5 +29,7 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>; | ||
export declare const fontAssetDecoder: Decoder<VUIDLFontAsset>; | ||
export declare const localFontDecoder: Decoder<UIDLLocalFontAsset>; | ||
export declare const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset>; | ||
export declare const iconAssetDecoder: Decoder<UIDLIconAsset>; | ||
export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>; | ||
export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>; | ||
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>; | ||
@@ -36,3 +39,2 @@ export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>; | ||
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>; | ||
@@ -74,6 +76,10 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>; | ||
export declare const dateTimeNodeDecoder: Decoder<VUIDLDateTimeNode>; | ||
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>; | ||
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>; | ||
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>; | ||
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode>; | ||
export declare const uidlNodeDecoder: Decoder<VUIDLNode>; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = exports.dynamicLinkDecoder = exports.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.resourceMapperDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.stateValueDetailsDecoder = exports.pageOptionsDecoder = exports.stateDefinitionsDecoder = exports.pageOptionsPaginationDecoder = exports.propDefinitionsDecoder = exports.componentSeoDecoder = exports.iconAssetDecoder = exports.canonicalAssetDecoder = exports.fontAssetDecoder = exports.externalStyleAssetDecoder = exports.inlineStyletAssetDecoder = exports.externalScriptAssetDecoder = exports.inlineScriptAssetDecoder = exports.baseAssetDecoder = exports.globalAssetsDecoder = exports.stateOrPropDefinitionDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.initialPathsDecoder = exports.initialPropsDecoder = exports.resourceItemDecoder = exports.dyamicFunctionStateParam = exports.dyamicFunctionParam = exports.envValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0; | ||
exports.uidlNodeDecoder = exports.cmsListNodeDecoder = exports.cmsListRepeaterNodeDecoder = exports.cmsItemNodeDecoder = exports.dateTimeNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = exports.classDynamicReferenceDecoder = exports.elementInlineReferencedStyle = exports.elementProjectReferencedStyle = exports.styleConditionsDecoder = exports.elementStyleWithMediaConditionDecoder = exports.elementStyleWithStateConditionDecoder = exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = void 0; | ||
exports.dynamicLinkDecoder = exports.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.resourceMapperDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.pageOptionsDecoder = exports.stateDefinitionsDecoder = exports.pageOptionsPaginationDecoder = exports.propDefinitionsDecoder = exports.stateValueDetailsDecoder = exports.componentSeoDecoder = exports.iconAssetDecoder = exports.canonicalAssetDecoder = exports.localFontDecoder = exports.fontAssetDecoder = exports.externalStyleAssetDecoder = exports.inlineStyletAssetDecoder = exports.externalScriptAssetDecoder = exports.inlineScriptAssetDecoder = exports.baseAssetDecoder = exports.globalAssetsDecoder = exports.stateOrPropDefinitionDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.injectValueDecoder = exports.initialPathsDecoder = exports.initialPropsDecoder = exports.resourceItemDecoder = exports.dyamicFunctionStateParam = exports.dyamicFunctionParam = exports.envValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0; | ||
exports.uidlNodeDecoder = exports.cmsMixedTypeNodeDecoder = exports.cmsListRepeaterNodeDecoder = exports.cmsListNodeDecoder = exports.cmsItemNodeDecoder = exports.uidlResourceLinkDecoder = exports.uidlExternalResourceDecoder = exports.uidlLocalResourcerDecpder = exports.dateTimeNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = exports.classDynamicReferenceDecoder = exports.elementInlineReferencedStyle = exports.elementProjectReferencedStyle = exports.styleConditionsDecoder = exports.elementStyleWithMediaConditionDecoder = exports.elementStyleWithStateConditionDecoder = exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = void 0; | ||
var json_type_validation_1 = require("@mojotech/json-type-validation"); | ||
@@ -13,3 +13,3 @@ var custom_combinators_1 = require("./custom-combinators"); | ||
referenceType: exports.referenceTypeDecoder, | ||
path: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
refPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
id: (0, json_type_validation_1.string)(), | ||
@@ -58,3 +58,3 @@ }), | ||
mappers: (0, json_type_validation_1.withDefault)([], (0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.dyamicFunctionStateParam))), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.dyamicFunctionStateParam, exports.expressionValueDecoder))), | ||
response: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
@@ -70,6 +70,10 @@ type: (0, json_type_validation_1.withDefault)('json', (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('json'), (0, json_type_validation_1.constant)('headers'), (0, json_type_validation_1.constant)('text'), (0, json_type_validation_1.constant)('none'))), | ||
}), | ||
resource: (0, json_type_validation_1.object)({ | ||
resource: (0, json_type_validation_1.union)((0, json_type_validation_1.object)({ | ||
id: (0, json_type_validation_1.string)(), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder))), | ||
}), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))), | ||
}), (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))), | ||
})), | ||
cache: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ revalidate: (0, json_type_validation_1.number)() })), | ||
@@ -83,7 +87,16 @@ }); | ||
}), | ||
resource: (0, json_type_validation_1.object)({ | ||
resource: (0, json_type_validation_1.union)((0, json_type_validation_1.object)({ | ||
id: (0, json_type_validation_1.string)(), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder))), | ||
}), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))), | ||
}), (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.expressionValueDecoder))), | ||
})), | ||
}); | ||
exports.injectValueDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('inject'), | ||
content: (0, json_type_validation_1.string)(), | ||
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; })), | ||
}); | ||
exports.styleSetMediaConditionDecoder = (0, json_type_validation_1.object)({ | ||
@@ -123,3 +136,3 @@ type: (0, json_type_validation_1.constant)('screen-size'), | ||
exports.stateOrPropDefinitionDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)(), (0, json_type_validation_1.array)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.object)())), (0, json_type_validation_1.object)()); | ||
exports.globalAssetsDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.lazy)(function () { return exports.inlineScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.inlineStyletAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalStyleAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.fontAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.canonicalAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.iconAssetDecoder; })); | ||
exports.globalAssetsDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.lazy)(function () { return exports.inlineScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalScriptAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.inlineStyletAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.externalStyleAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.fontAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.canonicalAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.iconAssetDecoder; }), (0, json_type_validation_1.lazy)(function () { return exports.localFontDecoder; })); | ||
exports.baseAssetDecoder = (0, json_type_validation_1.object)({ | ||
@@ -154,2 +167,7 @@ options: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
}); | ||
exports.localFontDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('local-font'), | ||
path: (0, json_type_validation_1.string)(), | ||
properties: (0, json_type_validation_1.dict)(exports.staticValueDecoder), | ||
}); | ||
exports.canonicalAssetDecoder = (0, json_type_validation_1.object)({ | ||
@@ -172,2 +190,7 @@ type: (0, json_type_validation_1.constant)('canonical'), | ||
}); | ||
exports.stateValueDetailsDecoder = (0, json_type_validation_1.object)({ | ||
value: (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)()), | ||
pageOptions: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.pageOptionsDecoder; })), | ||
seo: (0, json_type_validation_1.optional)(exports.componentSeoDecoder), | ||
}); | ||
exports.propDefinitionsDecoder = (0, json_type_validation_1.object)({ | ||
@@ -196,4 +219,2 @@ type: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('string'), (0, json_type_validation_1.constant)('boolean'), (0, json_type_validation_1.constant)('number'), (0, json_type_validation_1.constant)('array'), (0, json_type_validation_1.constant)('func'), (0, json_type_validation_1.constant)('object'), (0, json_type_validation_1.constant)('children')), | ||
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()), | ||
dynamicRouteAttribute: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
isIndex: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()), | ||
pagination: (0, json_type_validation_1.optional)(exports.pageOptionsPaginationDecoder), | ||
@@ -205,8 +226,2 @@ initialPropsData: (0, json_type_validation_1.optional)(exports.initialPropsDecoder), | ||
}); | ||
// @ts-ignore | ||
exports.stateValueDetailsDecoder = (0, json_type_validation_1.object)({ | ||
value: (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)()), | ||
pageOptions: (0, json_type_validation_1.optional)(exports.pageOptionsDecoder), | ||
seo: (0, json_type_validation_1.optional)(exports.componentSeoDecoder), | ||
}); | ||
exports.outputOptionsDecoder = (0, json_type_validation_1.object)({ | ||
@@ -369,3 +384,3 @@ componentClassName: (0, json_type_validation_1.optional)(isValidComponentName()), | ||
attrs: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)()))), | ||
events: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.array)(exports.eventHandlerStatementDecoder))), | ||
events: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)((0, json_type_validation_1.array)(exports.eventHandlerStatementDecoder))), | ||
abilities: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
@@ -404,2 +419,3 @@ link: (0, json_type_validation_1.optional)((0, json_type_validation_1.anyJson)()), | ||
reference: exports.dynamicValueDecoder, | ||
importDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.externaldependencyDecoder)), | ||
value: (0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), (0, json_type_validation_1.boolean)()), | ||
@@ -420,2 +436,12 @@ condition: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
}); | ||
exports.uidlLocalResourcerDecpder = (0, json_type_validation_1.object)({ | ||
id: (0, json_type_validation_1.string)(), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionStateParam; })))), | ||
}); | ||
exports.uidlExternalResourceDecoder = (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
dependency: (0, json_type_validation_1.lazy)(function () { return exports.externaldependencyDecoder; }), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder, (0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionStateParam; })))), | ||
}); | ||
exports.uidlResourceLinkDecoder = (0, json_type_validation_1.union)(exports.uidlLocalResourcerDecpder, exports.uidlExternalResourceDecoder); | ||
exports.cmsItemNodeDecoder = (0, json_type_validation_1.object)({ | ||
@@ -437,21 +463,7 @@ type: (0, json_type_validation_1.constant)('cms-item'), | ||
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
resource: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
id: (0, json_type_validation_1.string)(), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.expressionValueDecoder))), | ||
})), | ||
resource: (0, json_type_validation_1.optional)(exports.uidlResourceLinkDecoder), | ||
initialData: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionParam; })), | ||
entityKeyProperty: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
}), | ||
}); | ||
exports.cmsListRepeaterNodeDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('cms-list-repeater'), | ||
content: (0, json_type_validation_1.object)({ | ||
elementType: (0, json_type_validation_1.string)(), | ||
name: (0, json_type_validation_1.withDefault)('cms-list-repeater', (0, json_type_validation_1.string)()), | ||
nodes: (0, json_type_validation_1.object)({ | ||
list: (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }), | ||
empty: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })), | ||
}), | ||
renderPropIdentifier: (0, json_type_validation_1.string)(), | ||
}), | ||
}); | ||
exports.cmsListNodeDecoder = (0, json_type_validation_1.object)({ | ||
@@ -474,10 +486,36 @@ type: (0, json_type_validation_1.constant)('cms-list'), | ||
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
resource: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
id: (0, json_type_validation_1.string)(), | ||
params: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.dyamicFunctionParam, exports.dyamicFunctionStateParam, exports.expressionValueDecoder))), | ||
})), | ||
resource: (0, json_type_validation_1.optional)(exports.uidlResourceLinkDecoder), | ||
initialData: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dyamicFunctionParam; })), | ||
}), | ||
}); | ||
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.cmsListRepeaterNodeDecoder, exports.dynamicValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, (0, json_type_validation_1.union)(exports.staticValueDecoder, exports.repeatNodeDecoder, exports.slotNodeDecoder, exports.expressionValueDecoder, (0, json_type_validation_1.string)())); | ||
exports.cmsListRepeaterNodeDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('cms-list-repeater'), | ||
content: (0, json_type_validation_1.object)({ | ||
elementType: (0, json_type_validation_1.string)(), | ||
name: (0, json_type_validation_1.withDefault)('cms-list-repeater', (0, json_type_validation_1.string)()), | ||
nodes: (0, json_type_validation_1.object)({ | ||
list: (0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }), | ||
empty: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })), | ||
}), | ||
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })), | ||
source: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
renderPropIdentifier: (0, json_type_validation_1.string)(), | ||
}), | ||
}); | ||
exports.cmsMixedTypeNodeDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('cms-mixed-type'), | ||
content: (0, json_type_validation_1.object)({ | ||
elementType: (0, json_type_validation_1.string)(), | ||
name: (0, json_type_validation_1.withDefault)('cms-mixed-type', (0, json_type_validation_1.string)()), | ||
attrs: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.lazy)(function () { return (0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.attributeValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)())); })), | ||
renderPropIdentifier: (0, json_type_validation_1.string)(), | ||
nodes: (0, json_type_validation_1.object)({ | ||
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })), | ||
error: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })), | ||
}), | ||
dependency: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.dependencyDecoder; })), | ||
mappings: (0, json_type_validation_1.withDefault)({}, (0, json_type_validation_1.dict)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; }))), | ||
}), | ||
}); | ||
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.dynamicValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, (0, json_type_validation_1.union)(exports.staticValueDecoder, exports.repeatNodeDecoder, exports.slotNodeDecoder, exports.expressionValueDecoder, (0, json_type_validation_1.string)()), (0, json_type_validation_1.union)(exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.cmsListRepeaterNodeDecoder, exports.cmsMixedTypeNodeDecoder)); | ||
//# sourceMappingURL=utils.js.map |
@@ -91,47 +91,71 @@ "use strict"; | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _a, _b; | ||
switch (node.type) { | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'cms-list-repeater': | ||
case 'element': | ||
if (node.type === 'cms-item') { | ||
var _k = node.content, initialData = _k.initialData, _l = _k.nodes, success = _l.success, error = _l.error, loading = _l.loading; | ||
if (initialData) { | ||
initialData.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (success) { | ||
success.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_a = success === null || success === void 0 ? void 0 : success.content) === null || _a === void 0 ? void 0 : _a.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_b = error === null || error === void 0 ? void 0 : error.content) === null || _b === void 0 ? void 0 : _b.attrs) || {}); | ||
} | ||
if (loading) { | ||
loading.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_c = loading === null || loading === void 0 ? void 0 : loading.content) === null || _c === void 0 ? void 0 : _c.attrs) || {}); | ||
} | ||
case 'cms-list': { | ||
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading, resource = _c.resource; | ||
if (initialData) { | ||
initialData.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (node.type === 'cms-list') { | ||
var _m = node.content, initialData = _m.initialData, _o = _m.nodes, success = _o.success, error = _o.error, loading = _o.loading; | ||
if (initialData) { | ||
initialData.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (success) { | ||
success.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_d = success === null || success === void 0 ? void 0 : success.content) === null || _d === void 0 ? void 0 : _d.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_e = error === null || error === void 0 ? void 0 : error.content) === null || _e === void 0 ? void 0 : _e.attrs) || {}); | ||
} | ||
if (loading) { | ||
loading.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_f = loading === null || loading === void 0 ? void 0 : loading.content) === null || _f === void 0 ? void 0 : _f.attrs) || {}); | ||
} | ||
// TODO all this casting is really ugly, maybe we'll be able to do something about it | ||
if (success) { | ||
; | ||
node.content.nodes.success = | ||
parseComponentNode(success, component); | ||
} | ||
if (node.type === 'cms-list-repeater') { | ||
var _p = node.content.nodes, list = _p.list, empty = _p.empty; | ||
if (list) { | ||
list.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_g = list === null || list === void 0 ? void 0 : list.content) === null || _g === void 0 ? void 0 : _g.attrs) || {}); | ||
} | ||
if (empty) { | ||
empty.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_h = empty === null || empty === void 0 ? void 0 : empty.content) === null || _h === void 0 ? void 0 : _h.attrs) || {}); | ||
} | ||
if (error) { | ||
; | ||
node.content.nodes.error = | ||
parseComponentNode(error, component); | ||
} | ||
if (loading) { | ||
; | ||
node.content.nodes.loading = | ||
parseComponentNode(loading, component); | ||
} | ||
if (resource === null || resource === void 0 ? void 0 : resource.params) { | ||
Object.values((resource === null || resource === void 0 ? void 0 : resource.params) || {}).forEach(function (param) { | ||
if (param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) { | ||
param.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(param.content.id); | ||
} | ||
}); | ||
} | ||
return node; | ||
} | ||
case 'cms-list-repeater': { | ||
var _e = node.content.nodes, list = _e.list, empty = _e.empty; | ||
if (list) { | ||
; | ||
node.content.nodes.list = parseComponentNode(list, component); | ||
} | ||
if (empty) { | ||
; | ||
node.content.nodes.empty = parseComponentNode(empty, component); | ||
} | ||
return node; | ||
} | ||
case 'cms-mixed-type': { | ||
var _f = node.content, _g = _f.nodes, fallback = _g.fallback, error = _g.error, dependency = _f.dependency, attrs = _f.attrs, mappings_1 = _f.mappings; | ||
if (attrs) { | ||
; | ||
node.content.attrs = | ||
teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(attrs, dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'local'); | ||
} | ||
if (fallback) { | ||
; | ||
node.content.nodes.fallback = parseComponentNode(fallback, component); | ||
} | ||
if (error) { | ||
; | ||
node.content.nodes.error = parseComponentNode(error, component); | ||
} | ||
Object.keys(mappings_1).forEach(function (mapping) { | ||
; | ||
node.content.mappings[mapping] = | ||
parseComponentNode(mappings_1[mapping], component); | ||
}); | ||
return node; | ||
} | ||
case 'element': | ||
var elementContent = node.content; | ||
@@ -163,2 +187,14 @@ if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) { | ||
} | ||
if (elementContent.events) { | ||
Object.values(elementContent.events).forEach(function (eventHandler) { | ||
eventHandler.forEach(function (eventStatement) { | ||
if (eventStatement.type === 'stateChange') { | ||
eventStatement.modifies = teleport_shared_1.StringUtils.createStateOrPropStoringValue(eventStatement.modifies); | ||
} | ||
if (eventStatement.type === 'propCall') { | ||
eventStatement.calls = teleport_shared_1.StringUtils.createStateOrPropStoringValue(eventStatement.calls); | ||
} | ||
}); | ||
}); | ||
} | ||
if (elementContent.style) { | ||
@@ -168,6 +204,7 @@ elementContent.style = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(elementContent.style); | ||
if (elementContent.attrs) { | ||
elementContent.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs); | ||
elementContent.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent && | ||
((_a = elementContent.dependency) === null || _a === void 0 ? void 0 : _a.type) === 'local'); | ||
} | ||
if ((_j = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _j === void 0 ? void 0 : _j.hasOwnProperty('link')) { | ||
var _q = elementContent.abilities.link, content = _q.content, type = _q.type; | ||
if ((_b = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('link')) { | ||
var _h = elementContent.abilities.link, content = _h.content, type = _h.type; | ||
if (type === 'navlink' && typeof content.routeName === 'string') { | ||
@@ -233,2 +270,4 @@ var route = { | ||
case 'raw': | ||
case 'expr': | ||
case 'inject': | ||
return node; | ||
@@ -235,0 +274,0 @@ default: |
@@ -86,3 +86,3 @@ "use strict"; | ||
teleport_shared_1.UIDLUtils.traverseNodes(input.node, function (node, parent) { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (node.type === 'element') { | ||
@@ -98,4 +98,14 @@ var content = node.content; | ||
} | ||
if (node.type === 'cms-item' || node.type === 'cms-list') { | ||
Object.values(((_c = (_b = node.content) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.params) || {}).forEach(function (param) { | ||
if (param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) { | ||
param.content.referenceType === 'prop' | ||
? usedPropKeys.push(param.content.id) | ||
: usedStateKeys.push(param.content.id); | ||
} | ||
}); | ||
} | ||
if (node.type === 'element') { | ||
Object.keys(((_b = node.content) === null || _b === void 0 ? void 0 : _b.events) || {}).forEach(function (eventKey) { | ||
Object.keys(((_d = node.content) === null || _d === void 0 ? void 0 : _d.events) || {}).forEach(function (eventKey) { | ||
node.content.events[eventKey].forEach(function (event) { | ||
@@ -114,3 +124,3 @@ if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) { | ||
var dynamicVariants_1 = []; | ||
Object.values(((_c = node.content) === null || _c === void 0 ? void 0 : _c.referencedStyles) || {}).forEach(function (styleRef) { | ||
Object.values(((_e = node.content) === null || _e === void 0 ? void 0 : _e.referencedStyles) || {}).forEach(function (styleRef) { | ||
if (styleRef.content.mapType === 'component-referenced' && | ||
@@ -137,3 +147,3 @@ styleRef.content.content.type === 'dynamic') { | ||
if (dynamicVariants_1.length > 1) { | ||
errors.push("Node ".concat(((_d = node.content) === null || _d === void 0 ? void 0 : _d.name) || ((_e = node.content) === null || _e === void 0 ? void 0 : _e.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once")); | ||
errors.push("Node ".concat(((_f = node.content) === null || _f === void 0 ? void 0 : _f.name) || ((_g = node.content) === null || _g === void 0 ? void 0 : _g.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once")); | ||
} | ||
@@ -140,0 +150,0 @@ } |
@@ -28,3 +28,3 @@ /* tslint:disable member-ordering */ | ||
} | ||
var navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$'); | ||
var navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*'); | ||
if (navLinkRegex.test(link)) { | ||
@@ -38,3 +38,3 @@ return Result.ok(link); | ||
return new CustomCombinators(function (json) { | ||
var fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$'); | ||
var fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$'); | ||
if (json && typeof json === 'string' && fileNameRegex.test(json)) { | ||
@@ -41,0 +41,0 @@ return Result.ok(json); |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, VCMSListRepeaterElementNode, UIDLResourceMapper } from '@teleporthq/teleport-types'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLMailLinkNode, UIDLPhoneLinkNode, UIDLRawValue, UIDLElementStyleStates, UIDLStyleStateCondition, UIDLStyleMediaQueryScreenSizeCondition, UIDLStyleConditions, UIDLElementNodeProjectReferencedStyle, VUIDLComponentSEO, VUIDLGlobalAsset, UIDLExternalDependency, UIDLLocalDependency, UIDLPeerDependency, UIDLImportReference, UIDLStyleSetTokenReference, VUIDLStyleSetDefnition, VUIDLElement, VUIDLSlotNode, VUIDLConditionalNode, VUIDLRepeatNode, VUIDLElementNode, VUIDLNode, VUIDLElementNodeInlineReferencedStyle, VUIDLSectionLinkNode, VUIDLLinkNode, VUIDLURLLinkNode, VUIDLStyleSetConditions, VUIDLStyleSetMediaCondition, VUIDLStyleSetStateCondition, VUIDLDesignTokens, UIDLPropCallEvent, UIDLStateModifierEvent, UIDLScriptExternalAsset, UIDLScriptInlineAsset, VUIDLStyleInlineAsset, UIDLStyleExternalAsset, VUIDLFontAsset, UIDLCanonicalAsset, UIDLIconAsset, UIDLAssetBase, VUIDLElementNodeClassReferencedStyle, UIDLCompDynamicReference, UIDLComponentStyleReference, PagePaginationOptions, VCMSItemUIDLElementNode, VCMSListUIDLElementNode, UIDLInitialPathsData, UIDLInitialPropsData, UIDLExpressionValue, UIDLDynamicLinkNode, UIDLENVValue, UIDLPropValue, UIDLResourceItem, VUIDLNavLinkNode, VUIDLDateTimeNode, UIDLStateValue, UIDLResourceLink, UIDLLocalResource, UIDLExternalResource, VCMSListRepeaterElementNode, UIDLResourceMapper, UIDLInjectValue, VUIDLStateValueDetails, VUIDLCMSMixedTypeNode, UIDLLocalFontAsset } from '@teleporthq/teleport-types'; | ||
export declare const referenceTypeDecoder: Decoder<ReferenceType>; | ||
@@ -14,2 +14,3 @@ export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>; | ||
export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>; | ||
export declare const injectValueDecoder: Decoder<UIDLInjectValue>; | ||
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>; | ||
@@ -28,5 +29,7 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>; | ||
export declare const fontAssetDecoder: Decoder<VUIDLFontAsset>; | ||
export declare const localFontDecoder: Decoder<UIDLLocalFontAsset>; | ||
export declare const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset>; | ||
export declare const iconAssetDecoder: Decoder<UIDLIconAsset>; | ||
export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>; | ||
export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>; | ||
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>; | ||
@@ -36,3 +39,2 @@ export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>; | ||
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>; | ||
@@ -74,6 +76,10 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>; | ||
export declare const dateTimeNodeDecoder: Decoder<VUIDLDateTimeNode>; | ||
export declare const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource>; | ||
export declare const uidlExternalResourceDecoder: Decoder<UIDLExternalResource>; | ||
export declare const uidlResourceLinkDecoder: Decoder<UIDLResourceLink>; | ||
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode>; | ||
export declare const uidlNodeDecoder: Decoder<VUIDLNode>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -9,3 +9,3 @@ import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, withDefault, anyJson, } from '@mojotech/json-type-validation'; | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
refPath: optional(array(string())), | ||
id: string(), | ||
@@ -54,3 +54,3 @@ }), | ||
mappers: withDefault([], array(string())), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam))), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam, expressionValueDecoder))), | ||
response: optional(object({ | ||
@@ -66,6 +66,10 @@ type: withDefault('json', union(constant('json'), constant('headers'), constant('text'), constant('none'))), | ||
}), | ||
resource: object({ | ||
resource: union(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}), object({ | ||
name: string(), | ||
dependency: lazy(function () { return externaldependencyDecoder; }), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
})), | ||
cache: optional(object({ revalidate: number() })), | ||
@@ -79,7 +83,16 @@ }); | ||
}), | ||
resource: object({ | ||
resource: union(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}), object({ | ||
name: string(), | ||
dependency: lazy(function () { return externaldependencyDecoder; }), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
})), | ||
}); | ||
export var injectValueDecoder = object({ | ||
type: constant('inject'), | ||
content: string(), | ||
dependency: optional(lazy(function () { return externaldependencyDecoder; })), | ||
}); | ||
export var styleSetMediaConditionDecoder = object({ | ||
@@ -119,3 +132,3 @@ type: constant('screen-size'), | ||
export var stateOrPropDefinitionDecoder = union(string(), number(), boolean(), array(union(string(), number(), object())), object()); | ||
export var globalAssetsDecoder = union(lazy(function () { return inlineScriptAssetDecoder; }), lazy(function () { return externalScriptAssetDecoder; }), lazy(function () { return inlineStyletAssetDecoder; }), lazy(function () { return externalStyleAssetDecoder; }), lazy(function () { return fontAssetDecoder; }), lazy(function () { return canonicalAssetDecoder; }), lazy(function () { return iconAssetDecoder; })); | ||
export var globalAssetsDecoder = union(lazy(function () { return inlineScriptAssetDecoder; }), lazy(function () { return externalScriptAssetDecoder; }), lazy(function () { return inlineStyletAssetDecoder; }), lazy(function () { return externalStyleAssetDecoder; }), lazy(function () { return fontAssetDecoder; }), lazy(function () { return canonicalAssetDecoder; }), lazy(function () { return iconAssetDecoder; }), lazy(function () { return localFontDecoder; })); | ||
export var baseAssetDecoder = object({ | ||
@@ -150,2 +163,7 @@ options: optional(object({ | ||
}); | ||
export var localFontDecoder = object({ | ||
type: constant('local-font'), | ||
path: string(), | ||
properties: dict(staticValueDecoder), | ||
}); | ||
export var canonicalAssetDecoder = object({ | ||
@@ -168,2 +186,7 @@ type: constant('canonical'), | ||
}); | ||
export var stateValueDetailsDecoder = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(lazy(function () { return pageOptionsDecoder; })), | ||
seo: optional(componentSeoDecoder), | ||
}); | ||
export var propDefinitionsDecoder = object({ | ||
@@ -192,4 +215,2 @@ type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')), | ||
fallback: optional(boolean()), | ||
dynamicRouteAttribute: optional(string()), | ||
isIndex: optional(boolean()), | ||
pagination: optional(pageOptionsPaginationDecoder), | ||
@@ -201,8 +222,2 @@ initialPropsData: optional(initialPropsDecoder), | ||
}); | ||
// @ts-ignore | ||
export var stateValueDetailsDecoder = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(pageOptionsDecoder), | ||
seo: optional(componentSeoDecoder), | ||
}); | ||
export var outputOptionsDecoder = object({ | ||
@@ -365,3 +380,3 @@ componentClassName: optional(isValidComponentName()), | ||
attrs: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
events: optional(dict(array(eventHandlerStatementDecoder))), | ||
events: withDefault({}, dict(array(eventHandlerStatementDecoder))), | ||
abilities: optional(object({ | ||
@@ -400,2 +415,3 @@ link: optional(anyJson()), | ||
reference: dynamicValueDecoder, | ||
importDefinitions: optional(dict(externaldependencyDecoder)), | ||
value: union(string(), number(), boolean()), | ||
@@ -416,2 +432,12 @@ condition: optional(object({ | ||
}); | ||
export var uidlLocalResourcerDecpder = object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder, lazy(function () { return dyamicFunctionStateParam; })))), | ||
}); | ||
export var uidlExternalResourceDecoder = object({ | ||
name: string(), | ||
dependency: lazy(function () { return externaldependencyDecoder; }), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder, lazy(function () { return dyamicFunctionStateParam; })))), | ||
}); | ||
export var uidlResourceLinkDecoder = union(uidlLocalResourcerDecpder, uidlExternalResourceDecoder); | ||
export var cmsItemNodeDecoder = object({ | ||
@@ -433,21 +459,7 @@ type: constant('cms-item'), | ||
itemValuePath: optional(array(string())), | ||
resource: optional(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
})), | ||
resource: optional(uidlResourceLinkDecoder), | ||
initialData: optional(lazy(function () { return dyamicFunctionParam; })), | ||
entityKeyProperty: optional(string()), | ||
}), | ||
}); | ||
export var cmsListRepeaterNodeDecoder = object({ | ||
type: constant('cms-list-repeater'), | ||
content: object({ | ||
elementType: string(), | ||
name: withDefault('cms-list-repeater', string()), | ||
nodes: object({ | ||
list: lazy(function () { return elementNodeDecoder; }), | ||
empty: optional(lazy(function () { return elementNodeDecoder; })), | ||
}), | ||
renderPropIdentifier: string(), | ||
}), | ||
}); | ||
export var cmsListNodeDecoder = object({ | ||
@@ -470,10 +482,36 @@ type: constant('cms-list'), | ||
valuePath: optional(array(string())), | ||
resource: optional(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam, expressionValueDecoder))), | ||
})), | ||
resource: optional(uidlResourceLinkDecoder), | ||
initialData: optional(lazy(function () { return dyamicFunctionParam; })), | ||
}), | ||
}); | ||
export var uidlNodeDecoder = union(elementNodeDecoder, cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, dynamicValueDecoder, rawValueDecoder, conditionalNodeDecoder, union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string())); | ||
export var cmsListRepeaterNodeDecoder = object({ | ||
type: constant('cms-list-repeater'), | ||
content: object({ | ||
elementType: string(), | ||
name: withDefault('cms-list-repeater', string()), | ||
nodes: object({ | ||
list: lazy(function () { return elementNodeDecoder; }), | ||
empty: optional(lazy(function () { return elementNodeDecoder; })), | ||
}), | ||
dependency: optional(lazy(function () { return dependencyDecoder; })), | ||
source: optional(string()), | ||
renderPropIdentifier: string(), | ||
}), | ||
}); | ||
export var cmsMixedTypeNodeDecoder = object({ | ||
type: constant('cms-mixed-type'), | ||
content: object({ | ||
elementType: string(), | ||
name: withDefault('cms-mixed-type', string()), | ||
attrs: withDefault({}, lazy(function () { return dict(union(attributeValueDecoder, string(), number())); })), | ||
renderPropIdentifier: string(), | ||
nodes: object({ | ||
fallback: optional(lazy(function () { return elementNodeDecoder; })), | ||
error: optional(lazy(function () { return elementNodeDecoder; })), | ||
}), | ||
dependency: optional(lazy(function () { return dependencyDecoder; })), | ||
mappings: withDefault({}, dict(lazy(function () { return elementNodeDecoder; }))), | ||
}), | ||
}); | ||
export var uidlNodeDecoder = union(elementNodeDecoder, dynamicValueDecoder, rawValueDecoder, conditionalNodeDecoder, union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()), union(cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, cmsMixedTypeNodeDecoder)); | ||
//# sourceMappingURL=utils.js.map |
@@ -86,47 +86,71 @@ var __assign = (this && this.__assign) || function () { | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j; | ||
var _a, _b; | ||
switch (node.type) { | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'cms-list-repeater': | ||
case 'element': | ||
if (node.type === 'cms-item') { | ||
var _k = node.content, initialData = _k.initialData, _l = _k.nodes, success = _l.success, error = _l.error, loading = _l.loading; | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_a = success === null || success === void 0 ? void 0 : success.content) === null || _a === void 0 ? void 0 : _a.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_b = error === null || error === void 0 ? void 0 : error.content) === null || _b === void 0 ? void 0 : _b.attrs) || {}); | ||
} | ||
if (loading) { | ||
loading.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_c = loading === null || loading === void 0 ? void 0 : loading.content) === null || _c === void 0 ? void 0 : _c.attrs) || {}); | ||
} | ||
case 'cms-list': { | ||
var _c = node.content, initialData = _c.initialData, _d = _c.nodes, success = _d.success, error = _d.error, loading = _d.loading, resource = _c.resource; | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (node.type === 'cms-list') { | ||
var _m = node.content, initialData = _m.initialData, _o = _m.nodes, success = _o.success, error = _o.error, loading = _o.loading; | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id); | ||
} | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_d = success === null || success === void 0 ? void 0 : success.content) === null || _d === void 0 ? void 0 : _d.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_e = error === null || error === void 0 ? void 0 : error.content) === null || _e === void 0 ? void 0 : _e.attrs) || {}); | ||
} | ||
if (loading) { | ||
loading.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_f = loading === null || loading === void 0 ? void 0 : loading.content) === null || _f === void 0 ? void 0 : _f.attrs) || {}); | ||
} | ||
// TODO all this casting is really ugly, maybe we'll be able to do something about it | ||
if (success) { | ||
; | ||
node.content.nodes.success = | ||
parseComponentNode(success, component); | ||
} | ||
if (node.type === 'cms-list-repeater') { | ||
var _p = node.content.nodes, list = _p.list, empty = _p.empty; | ||
if (list) { | ||
list.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_g = list === null || list === void 0 ? void 0 : list.content) === null || _g === void 0 ? void 0 : _g.attrs) || {}); | ||
} | ||
if (empty) { | ||
empty.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_h = empty === null || empty === void 0 ? void 0 : empty.content) === null || _h === void 0 ? void 0 : _h.attrs) || {}); | ||
} | ||
if (error) { | ||
; | ||
node.content.nodes.error = | ||
parseComponentNode(error, component); | ||
} | ||
if (loading) { | ||
; | ||
node.content.nodes.loading = | ||
parseComponentNode(loading, component); | ||
} | ||
if (resource === null || resource === void 0 ? void 0 : resource.params) { | ||
Object.values((resource === null || resource === void 0 ? void 0 : resource.params) || {}).forEach(function (param) { | ||
if (param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) { | ||
param.content.id = StringUtils.createStateOrPropStoringValue(param.content.id); | ||
} | ||
}); | ||
} | ||
return node; | ||
} | ||
case 'cms-list-repeater': { | ||
var _e = node.content.nodes, list = _e.list, empty = _e.empty; | ||
if (list) { | ||
; | ||
node.content.nodes.list = parseComponentNode(list, component); | ||
} | ||
if (empty) { | ||
; | ||
node.content.nodes.empty = parseComponentNode(empty, component); | ||
} | ||
return node; | ||
} | ||
case 'cms-mixed-type': { | ||
var _f = node.content, _g = _f.nodes, fallback = _g.fallback, error = _g.error, dependency = _f.dependency, attrs = _f.attrs, mappings_1 = _f.mappings; | ||
if (attrs) { | ||
; | ||
node.content.attrs = | ||
UIDLUtils.transformAttributesAssignmentsToJson(attrs, dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'local'); | ||
} | ||
if (fallback) { | ||
; | ||
node.content.nodes.fallback = parseComponentNode(fallback, component); | ||
} | ||
if (error) { | ||
; | ||
node.content.nodes.error = parseComponentNode(error, component); | ||
} | ||
Object.keys(mappings_1).forEach(function (mapping) { | ||
; | ||
node.content.mappings[mapping] = | ||
parseComponentNode(mappings_1[mapping], component); | ||
}); | ||
return node; | ||
} | ||
case 'element': | ||
var elementContent = node.content; | ||
@@ -158,2 +182,14 @@ if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) { | ||
} | ||
if (elementContent.events) { | ||
Object.values(elementContent.events).forEach(function (eventHandler) { | ||
eventHandler.forEach(function (eventStatement) { | ||
if (eventStatement.type === 'stateChange') { | ||
eventStatement.modifies = StringUtils.createStateOrPropStoringValue(eventStatement.modifies); | ||
} | ||
if (eventStatement.type === 'propCall') { | ||
eventStatement.calls = StringUtils.createStateOrPropStoringValue(eventStatement.calls); | ||
} | ||
}); | ||
}); | ||
} | ||
if (elementContent.style) { | ||
@@ -163,6 +199,7 @@ elementContent.style = UIDLUtils.transformStylesAssignmentsToJson(elementContent.style); | ||
if (elementContent.attrs) { | ||
elementContent.attrs = UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs); | ||
elementContent.attrs = UIDLUtils.transformAttributesAssignmentsToJson(elementContent.attrs, 'dependency' in elementContent && | ||
((_a = elementContent.dependency) === null || _a === void 0 ? void 0 : _a.type) === 'local'); | ||
} | ||
if ((_j = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _j === void 0 ? void 0 : _j.hasOwnProperty('link')) { | ||
var _q = elementContent.abilities.link, content = _q.content, type = _q.type; | ||
if ((_b = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('link')) { | ||
var _h = elementContent.abilities.link, content = _h.content, type = _h.type; | ||
if (type === 'navlink' && typeof content.routeName === 'string') { | ||
@@ -228,2 +265,4 @@ var route = { | ||
case 'raw': | ||
case 'expr': | ||
case 'inject': | ||
return node; | ||
@@ -230,0 +269,0 @@ default: |
@@ -81,3 +81,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
UIDLUtils.traverseNodes(input.node, function (node, parent) { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (node.type === 'element') { | ||
@@ -93,4 +93,14 @@ var content = node.content; | ||
} | ||
if (node.type === 'cms-item' || node.type === 'cms-list') { | ||
Object.values(((_c = (_b = node.content) === null || _b === void 0 ? void 0 : _b.resource) === null || _c === void 0 ? void 0 : _c.params) || {}).forEach(function (param) { | ||
if (param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop')) { | ||
param.content.referenceType === 'prop' | ||
? usedPropKeys.push(param.content.id) | ||
: usedStateKeys.push(param.content.id); | ||
} | ||
}); | ||
} | ||
if (node.type === 'element') { | ||
Object.keys(((_b = node.content) === null || _b === void 0 ? void 0 : _b.events) || {}).forEach(function (eventKey) { | ||
Object.keys(((_d = node.content) === null || _d === void 0 ? void 0 : _d.events) || {}).forEach(function (eventKey) { | ||
node.content.events[eventKey].forEach(function (event) { | ||
@@ -109,3 +119,3 @@ if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) { | ||
var dynamicVariants_1 = []; | ||
Object.values(((_c = node.content) === null || _c === void 0 ? void 0 : _c.referencedStyles) || {}).forEach(function (styleRef) { | ||
Object.values(((_e = node.content) === null || _e === void 0 ? void 0 : _e.referencedStyles) || {}).forEach(function (styleRef) { | ||
if (styleRef.content.mapType === 'component-referenced' && | ||
@@ -132,3 +142,3 @@ styleRef.content.content.type === 'dynamic') { | ||
if (dynamicVariants_1.length > 1) { | ||
errors.push("Node ".concat(((_d = node.content) === null || _d === void 0 ? void 0 : _d.name) || ((_e = node.content) === null || _e === void 0 ? void 0 : _e.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once")); | ||
errors.push("Node ".concat(((_f = node.content) === null || _f === void 0 ? void 0 : _f.name) || ((_g = node.content) === null || _g === void 0 ? void 0 : _g.key), " is using multiple dynamic variants using propDefinitions.\n We can have only one dynamic variant at once")); | ||
} | ||
@@ -135,0 +145,0 @@ } |
{ | ||
"name": "@teleporthq/teleport-uidl-validator", | ||
"version": "0.32.0-alpha.0", | ||
"version": "0.32.0", | ||
"description": "A module that offers validation and parsing for non-standard UIDL structures", | ||
@@ -28,6 +28,6 @@ "author": "teleportHQ", | ||
"@mojotech/json-type-validation": "^3.1.0", | ||
"@teleporthq/teleport-shared": "^0.32.0-alpha.0", | ||
"@teleporthq/teleport-types": "^0.32.0-alpha.0" | ||
"@teleporthq/teleport-shared": "^0.32.0", | ||
"@teleporthq/teleport-types": "^0.32.0" | ||
}, | ||
"gitHead": "de47527436cc4f1d00f241718fbdfdb86e616e3b" | ||
"gitHead": "08e6b6b0a6328cdbf86891871be39a377450a084" | ||
} |
@@ -36,3 +36,3 @@ /* tslint:disable member-ordering */ | ||
const navLinkRegex = new RegExp('/[a-zA-Z0-9-_]*$') | ||
const navLinkRegex = new RegExp('/(?:[a-zA-Z0-9-_]+|/[[a-zA-Z]+]|[/[a-zA-Z]+])*') | ||
if (navLinkRegex.test(link)) { | ||
@@ -48,3 +48,3 @@ return Result.ok(link) | ||
return new CustomCombinators<string>((json: string) => { | ||
const fileNameRegex = new RegExp('^[a-zA-Z0-9-_.]*$') | ||
const fileNameRegex = new RegExp('^[[a-zA-Z0-9-_.]+]*$') | ||
if (json && typeof json === 'string' && fileNameRegex.test(json)) { | ||
@@ -51,0 +51,0 @@ return Result.ok(json) |
@@ -24,3 +24,2 @@ import { | ||
UIDLStateDefinition, | ||
UIDLStateValueDetails, | ||
UIDLPageOptions, | ||
@@ -89,4 +88,11 @@ UIDLComponentOutputOptions, | ||
UIDLStateValue, | ||
UIDLResourceLink, | ||
UIDLLocalResource, | ||
UIDLExternalResource, | ||
VCMSListRepeaterElementNode, | ||
UIDLResourceMapper, | ||
UIDLInjectValue, | ||
VUIDLStateValueDetails, | ||
VUIDLCMSMixedTypeNode, | ||
UIDLLocalFontAsset, | ||
} from '@teleporthq/teleport-types' | ||
@@ -112,3 +118,3 @@ import { CustomCombinators } from './custom-combinators' | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
refPath: optional(array(string())), | ||
id: string(), | ||
@@ -164,3 +170,12 @@ }), | ||
mappers: withDefault([], array(string())), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, dyamicFunctionStateParam))), | ||
params: optional( | ||
dict( | ||
union( | ||
staticValueDecoder, | ||
dyamicFunctionParam, | ||
dyamicFunctionStateParam, | ||
expressionValueDecoder | ||
) | ||
) | ||
), | ||
response: optional( | ||
@@ -182,6 +197,13 @@ object({ | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
resource: union( | ||
object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}), | ||
object({ | ||
name: string(), | ||
dependency: lazy(() => externaldependencyDecoder), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}) | ||
), | ||
cache: optional(object({ revalidate: number() })), | ||
@@ -196,8 +218,21 @@ }) | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
resource: union( | ||
object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}), | ||
object({ | ||
name: string(), | ||
dependency: lazy(() => externaldependencyDecoder), | ||
params: optional(dict(union(staticValueDecoder, expressionValueDecoder))), | ||
}) | ||
), | ||
}) | ||
export const injectValueDecoder: Decoder<UIDLInjectValue> = object({ | ||
type: constant('inject'), | ||
content: string(), | ||
dependency: optional(lazy(() => externaldependencyDecoder)), | ||
}) | ||
export const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition> = object({ | ||
@@ -277,3 +312,4 @@ type: constant('screen-size'), | ||
lazy(() => canonicalAssetDecoder), | ||
lazy(() => iconAssetDecoder) | ||
lazy(() => iconAssetDecoder), | ||
lazy(() => localFontDecoder) | ||
) | ||
@@ -324,2 +360,8 @@ | ||
export const localFontDecoder: Decoder<UIDLLocalFontAsset> = object({ | ||
type: constant('local-font' as const), | ||
path: string(), | ||
properties: dict(staticValueDecoder), | ||
}) | ||
export const canonicalAssetDecoder: Decoder<UIDLCanonicalAsset> = object({ | ||
@@ -347,2 +389,8 @@ type: constant('canonical' as const), | ||
export const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails> = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(lazy(() => pageOptionsDecoder)), | ||
seo: optional(componentSeoDecoder), | ||
}) | ||
export const propDefinitionsDecoder: Decoder<UIDLPropDefinition> = object({ | ||
@@ -390,4 +438,2 @@ type: union( | ||
fallback: optional(boolean()), | ||
dynamicRouteAttribute: optional(string()), | ||
isIndex: optional(boolean()), | ||
pagination: optional(pageOptionsPaginationDecoder), | ||
@@ -400,9 +446,2 @@ initialPropsData: optional(initialPropsDecoder), | ||
// @ts-ignore | ||
export const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails> = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(pageOptionsDecoder), | ||
seo: optional(componentSeoDecoder), | ||
}) | ||
export const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions> = object({ | ||
@@ -641,3 +680,3 @@ componentClassName: optional(isValidComponentName() as unknown as Decoder<string>), | ||
attrs: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
events: optional(dict(array(eventHandlerStatementDecoder))), | ||
events: withDefault({}, dict(array(eventHandlerStatementDecoder))), | ||
abilities: optional( | ||
@@ -700,2 +739,3 @@ object({ | ||
reference: dynamicValueDecoder, | ||
importDefinitions: optional(dict(externaldependencyDecoder)), | ||
value: union(string(), number(), boolean()), | ||
@@ -723,2 +763,36 @@ condition: optional( | ||
export const uidlLocalResourcerDecpder: Decoder<UIDLLocalResource> = object({ | ||
id: string(), | ||
params: optional( | ||
dict( | ||
union( | ||
staticValueDecoder, | ||
dyamicFunctionParam, | ||
expressionValueDecoder, | ||
lazy(() => dyamicFunctionStateParam) | ||
) | ||
) | ||
), | ||
}) | ||
export const uidlExternalResourceDecoder: Decoder<UIDLExternalResource> = object({ | ||
name: string(), | ||
dependency: lazy(() => externaldependencyDecoder), | ||
params: optional( | ||
dict( | ||
union( | ||
staticValueDecoder, | ||
dyamicFunctionParam, | ||
expressionValueDecoder, | ||
lazy(() => dyamicFunctionStateParam) | ||
) | ||
) | ||
), | ||
}) | ||
export const uidlResourceLinkDecoder: Decoder<UIDLResourceLink> = union( | ||
uidlLocalResourcerDecpder, | ||
uidlExternalResourceDecoder | ||
) | ||
export const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode> = object({ | ||
@@ -740,14 +814,30 @@ type: constant('cms-item'), | ||
itemValuePath: optional(array(string())), | ||
resource: optional( | ||
object({ | ||
id: string(), | ||
params: optional( | ||
dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder)) | ||
), | ||
}) | ||
), | ||
resource: optional(uidlResourceLinkDecoder), | ||
initialData: optional(lazy(() => dyamicFunctionParam)), | ||
entityKeyProperty: optional(string()), | ||
}), | ||
}) | ||
export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({ | ||
type: constant('cms-list'), | ||
content: object({ | ||
elementType: string(), | ||
name: withDefault('cms-list', string()), | ||
attrs: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
nodes: object({ | ||
success: lazy(() => elementNodeDecoder), | ||
error: optional(lazy(() => elementNodeDecoder)), | ||
loading: optional(lazy(() => elementNodeDecoder)), | ||
empty: optional(lazy(() => elementNodeDecoder)), | ||
}), | ||
router: optional(lazy(() => dependencyDecoder)), | ||
dependency: optional(lazy(() => dependencyDecoder)), | ||
renderPropIdentifier: string(), | ||
itemValuePath: optional(array(string())), | ||
valuePath: optional(array(string())), | ||
resource: optional(uidlResourceLinkDecoder), | ||
initialData: optional(lazy(() => dyamicFunctionParam)), | ||
}), | ||
}) | ||
export const cmsListRepeaterNodeDecoder: Decoder<VCMSListRepeaterElementNode> = object({ | ||
@@ -762,2 +852,4 @@ type: constant('cms-list-repeater'), | ||
}), | ||
dependency: optional(lazy(() => dependencyDecoder)), | ||
source: optional(string()), | ||
renderPropIdentifier: string(), | ||
@@ -767,35 +859,18 @@ }), | ||
export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({ | ||
type: constant('cms-list'), | ||
export const cmsMixedTypeNodeDecoder: Decoder<VUIDLCMSMixedTypeNode> = object({ | ||
type: constant('cms-mixed-type'), | ||
content: object({ | ||
elementType: string(), | ||
name: withDefault('cms-list', string()), | ||
attrs: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
name: withDefault('cms-mixed-type', string()), | ||
attrs: withDefault( | ||
{}, | ||
lazy(() => dict(union(attributeValueDecoder, string(), number()))) | ||
), | ||
renderPropIdentifier: string(), | ||
nodes: object({ | ||
success: lazy(() => elementNodeDecoder), | ||
fallback: optional(lazy(() => elementNodeDecoder)), | ||
error: optional(lazy(() => elementNodeDecoder)), | ||
loading: optional(lazy(() => elementNodeDecoder)), | ||
empty: optional(lazy(() => elementNodeDecoder)), | ||
}), | ||
router: optional(lazy(() => dependencyDecoder)), | ||
dependency: optional(lazy(() => dependencyDecoder)), | ||
renderPropIdentifier: string(), | ||
itemValuePath: optional(array(string())), | ||
valuePath: optional(array(string())), | ||
resource: optional( | ||
object({ | ||
id: string(), | ||
params: optional( | ||
dict( | ||
union( | ||
staticValueDecoder, | ||
dyamicFunctionParam, | ||
dyamicFunctionStateParam, | ||
expressionValueDecoder | ||
) | ||
) | ||
), | ||
}) | ||
), | ||
initialData: optional(lazy(() => dyamicFunctionParam)), | ||
mappings: withDefault({}, dict(lazy(() => elementNodeDecoder))), | ||
}), | ||
@@ -806,9 +881,7 @@ }) | ||
elementNodeDecoder, | ||
cmsItemNodeDecoder, | ||
cmsListNodeDecoder, | ||
cmsListRepeaterNodeDecoder, | ||
dynamicValueDecoder, | ||
rawValueDecoder, | ||
conditionalNodeDecoder, | ||
union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()) | ||
union(staticValueDecoder, repeatNodeDecoder, slotNodeDecoder, expressionValueDecoder, string()), | ||
union(cmsItemNodeDecoder, cmsListNodeDecoder, cmsListRepeaterNodeDecoder, cmsMixedTypeNodeDecoder) | ||
) |
@@ -25,4 +25,7 @@ import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared' | ||
UIDLCMSItemNode, | ||
UIDLCMSListRepeaterNode, | ||
UIDLCMSListNode, | ||
UIDLCMSListRepeaterNode, | ||
UIDLDependency, | ||
UIDLEventHandlerStatement, | ||
UIDLCMSMixedTypeNode, | ||
} from '@teleporthq/teleport-types' | ||
@@ -150,81 +153,113 @@ | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'cms-list-repeater': | ||
case 'element': | ||
if (node.type === 'cms-item') { | ||
const { | ||
initialData, | ||
nodes: { success, error, loading }, | ||
} = (node as unknown as UIDLCMSItemNode).content | ||
case 'cms-list': { | ||
const { | ||
initialData, | ||
nodes: { success, error, loading }, | ||
resource, | ||
} = (node as unknown as UIDLCMSItemNode).content | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id) | ||
} | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id) | ||
} | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
success?.content?.attrs || {} | ||
) | ||
} | ||
// TODO all this casting is really ugly, maybe we'll be able to do something about it | ||
if (success) { | ||
;(node as unknown as UIDLCMSItemNode | UIDLCMSListNode).content.nodes.success = | ||
parseComponentNode( | ||
success as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
error?.content?.attrs || {} | ||
) | ||
} | ||
if (error) { | ||
;(node as unknown as UIDLCMSItemNode | UIDLCMSListNode).content.nodes.error = | ||
parseComponentNode( | ||
error as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (loading) { | ||
loading.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
loading?.content?.attrs || {} | ||
) | ||
} | ||
if (loading) { | ||
;(node as unknown as UIDLCMSItemNode | UIDLCMSListNode).content.nodes.loading = | ||
parseComponentNode( | ||
loading as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (node.type === 'cms-list') { | ||
const { | ||
initialData, | ||
nodes: { success, error, loading }, | ||
} = (node as unknown as UIDLCMSListNode).content | ||
if (resource?.params) { | ||
Object.values(resource?.params || {}).forEach((param) => { | ||
if ( | ||
param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop') | ||
) { | ||
param.content.id = StringUtils.createStateOrPropStoringValue(param.content.id) | ||
} | ||
}) | ||
} | ||
if (initialData) { | ||
initialData.content.id = StringUtils.createStateOrPropStoringValue(initialData.content.id) | ||
} | ||
return node as unknown as UIDLCMSListNode | UIDLCMSItemNode | ||
} | ||
case 'cms-list-repeater': { | ||
const { | ||
nodes: { list, empty }, | ||
} = (node as unknown as UIDLCMSListRepeaterNode).content | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
success?.content?.attrs || {} | ||
) | ||
} | ||
if (list) { | ||
;(node as unknown as UIDLCMSListRepeaterNode).content.nodes.list = parseComponentNode( | ||
list as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
error?.content?.attrs || {} | ||
) | ||
} | ||
if (loading) { | ||
loading.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
loading?.content?.attrs || {} | ||
) | ||
} | ||
if (empty) { | ||
;(node as unknown as UIDLCMSListRepeaterNode).content.nodes.empty = parseComponentNode( | ||
empty as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (node.type === 'cms-list-repeater') { | ||
const { | ||
nodes: { list, empty }, | ||
} = (node as unknown as UIDLCMSListRepeaterNode).content | ||
return node as unknown as UIDLCMSListRepeaterNode | ||
} | ||
case 'cms-mixed-type': { | ||
const { | ||
nodes: { fallback, error }, | ||
dependency, | ||
attrs, | ||
mappings, | ||
} = (node as unknown as UIDLCMSMixedTypeNode).content | ||
if (list) { | ||
list.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
list?.content?.attrs || {} | ||
if (attrs) { | ||
;(node.content as UIDLCMSMixedTypeNode['content']).attrs = | ||
UIDLUtils.transformAttributesAssignmentsToJson( | ||
attrs as Record<string, unknown>, | ||
dependency && (dependency as UIDLDependency)?.type === 'local' | ||
) | ||
} | ||
} | ||
if (empty) { | ||
empty.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
empty?.content?.attrs || {} | ||
) | ||
} | ||
if (fallback) { | ||
;(node as unknown as UIDLCMSMixedTypeNode).content.nodes.fallback = parseComponentNode( | ||
fallback as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
if (error) { | ||
;(node as unknown as UIDLCMSMixedTypeNode).content.nodes.error = parseComponentNode( | ||
error as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
} | ||
Object.keys(mappings).forEach((mapping) => { | ||
;(node.content as unknown as UIDLCMSMixedTypeNode['content']).mappings[mapping] = | ||
parseComponentNode( | ||
mappings[mapping] as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
}) | ||
return node as unknown as UIDLCMSMixedTypeNode | ||
} | ||
case 'element': | ||
const elementContent = node.content as Record<string, unknown> | ||
@@ -263,2 +298,22 @@ if (elementContent?.referencedStyles) { | ||
if (elementContent.events) { | ||
Object.values(elementContent.events).forEach( | ||
(eventHandler: UIDLEventHandlerStatement[]) => { | ||
eventHandler.forEach((eventStatement) => { | ||
if (eventStatement.type === 'stateChange') { | ||
eventStatement.modifies = StringUtils.createStateOrPropStoringValue( | ||
eventStatement.modifies | ||
) | ||
} | ||
if (eventStatement.type === 'propCall') { | ||
eventStatement.calls = StringUtils.createStateOrPropStoringValue( | ||
eventStatement.calls | ||
) | ||
} | ||
}) | ||
} | ||
) | ||
} | ||
if (elementContent.style) { | ||
@@ -272,3 +327,5 @@ elementContent.style = UIDLUtils.transformStylesAssignmentsToJson( | ||
elementContent.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
elementContent.attrs as Record<string, unknown> | ||
elementContent.attrs as Record<string, unknown>, | ||
'dependency' in elementContent && | ||
(elementContent.dependency as UIDLDependency)?.type === 'local' | ||
) | ||
@@ -367,2 +424,4 @@ } | ||
case 'raw': | ||
case 'expr': | ||
case 'inject': | ||
return node as unknown as UIDLNode | ||
@@ -369,0 +428,0 @@ |
@@ -124,2 +124,15 @@ import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
if (node.type === 'cms-item' || node.type === 'cms-list') { | ||
Object.values(node.content?.resource?.params || {}).forEach((param) => { | ||
if ( | ||
param.type === 'dynamic' && | ||
(param.content.referenceType === 'state' || param.content.referenceType === 'prop') | ||
) { | ||
param.content.referenceType === 'prop' | ||
? usedPropKeys.push(param.content.id) | ||
: usedStateKeys.push(param.content.id) | ||
} | ||
}) | ||
} | ||
if (node.type === 'element') { | ||
@@ -126,0 +139,0 @@ Object.keys(node.content?.events || {}).forEach((eventKey) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
539100
8462