@teleporthq/teleport-uidl-validator
Advanced tools
Comparing version 0.27.6-alpha.0 to 0.27.8
@@ -141,4 +141,3 @@ { | ||
} | ||
}, | ||
{ | ||
},{ | ||
"type": "conditional", | ||
@@ -336,7 +335,3 @@ "content": { | ||
"type": "static", | ||
"content": [ | ||
"angular", | ||
"react", | ||
"vue" | ||
] | ||
"content": ["angular", "react", "vue"] | ||
} | ||
@@ -377,8 +372,6 @@ } | ||
"elementType": "text", | ||
"children": [ | ||
{ | ||
"type": "static", | ||
"content": "Now you see me!" | ||
} | ||
] | ||
"children": [{ | ||
"type": "static", | ||
"content": "Now you see me!" | ||
}] | ||
} | ||
@@ -398,20 +391,18 @@ } | ||
}, | ||
"children": [ | ||
{ | ||
"type": "element", | ||
"content": { | ||
"elementType": "source", | ||
"attrs": { | ||
"type": { | ||
"type": "static", | ||
"content": "video/mp4" | ||
}, | ||
"url": { | ||
"type": "static", | ||
"content": "https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" | ||
} | ||
"children": [{ | ||
"type": "element", | ||
"content": { | ||
"elementType": "source", | ||
"attrs": { | ||
"type": { | ||
"type": "static", | ||
"content": "video/mp4" | ||
}, | ||
"url": { | ||
"type": "static", | ||
"content": "https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" | ||
} | ||
} | ||
} | ||
] | ||
}] | ||
} | ||
@@ -482,11 +473,9 @@ }, | ||
"elementType": "text", | ||
"children": [ | ||
{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "title" | ||
} | ||
"children": [{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "title" | ||
} | ||
] | ||
}] | ||
} | ||
@@ -498,38 +487,35 @@ }, | ||
"elementType": "button", | ||
"children": [ | ||
{ | ||
"type": "conditional", | ||
"content": { | ||
"node": { | ||
"type": "static", | ||
"content": "Hide me" | ||
}, | ||
"value": true, | ||
"reference": { | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "state", | ||
"id": "isExpanded" | ||
} | ||
"children": [{ | ||
"type": "conditional", | ||
"content": { | ||
"node": { | ||
"type": "static", | ||
"content": "Hide me" | ||
}, | ||
"value": true, | ||
"reference": { | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "state", | ||
"id": "isExpanded" | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "conditional", | ||
"content": { | ||
"node": { | ||
"type": "static", | ||
"content": "Show me" | ||
}, | ||
"value": false, | ||
"reference": { | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "state", | ||
"id": "isExpanded" | ||
} | ||
} | ||
},{ | ||
"type": "conditional", | ||
"content": { | ||
"node": { | ||
"type": "static", | ||
"content": "Show me" | ||
}, | ||
"value": false, | ||
"reference": { | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "state", | ||
"id": "isExpanded" | ||
} | ||
} | ||
} | ||
], | ||
}], | ||
"events": { | ||
@@ -553,11 +539,9 @@ "click": [ | ||
"elementType": "text", | ||
"children": [ | ||
{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "text" | ||
} | ||
"children": [{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "text" | ||
} | ||
] | ||
}] | ||
} | ||
@@ -597,16 +581,12 @@ }, | ||
"name": "openmodal", | ||
"children": [ | ||
{ | ||
"type": "static", | ||
"content": "Show Popup" | ||
} | ||
], | ||
"children": [{ | ||
"type": "static", | ||
"content": "Show Popup" | ||
}], | ||
"events": { | ||
"click": [ | ||
{ | ||
"type": "stateChange", | ||
"modifies": "isOpen", | ||
"newState": true | ||
} | ||
] | ||
"click": [{ | ||
"type": "stateChange", | ||
"modifies": "isOpen", | ||
"newState": true | ||
}] | ||
} | ||
@@ -628,9 +608,7 @@ } | ||
"events": { | ||
"onClose": [ | ||
{ | ||
"type": "stateChange", | ||
"modifies": "isOpen", | ||
"newState": false | ||
} | ||
] | ||
"onClose": [{ | ||
"type": "stateChange", | ||
"modifies": "isOpen", | ||
"newState": false | ||
}] | ||
} | ||
@@ -675,37 +653,29 @@ } | ||
"elementType": "container", | ||
"children": [ | ||
{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "message" | ||
"children": [{ | ||
"type": "dynamic", | ||
"content": { | ||
"referenceType": "prop", | ||
"id": "message" | ||
} | ||
},{ | ||
"type": "element", | ||
"content": { | ||
"elementType": "button", | ||
"name": "close", | ||
"children": [{ | ||
"type": "static", | ||
"content": "Close me" | ||
}], | ||
"events": { | ||
"click": [{ | ||
"type": "propCall", | ||
"calls": "onClose" | ||
},{ | ||
"type": "stateChange", | ||
"modifies": "fakeState", | ||
"newState": false | ||
}] | ||
} | ||
}, | ||
{ | ||
"type": "element", | ||
"content": { | ||
"elementType": "button", | ||
"name": "close", | ||
"children": [ | ||
{ | ||
"type": "static", | ||
"content": "Close me" | ||
} | ||
], | ||
"events": { | ||
"click": [ | ||
{ | ||
"type": "propCall", | ||
"calls": "onClose" | ||
}, | ||
{ | ||
"type": "stateChange", | ||
"modifies": "fakeState", | ||
"newState": false | ||
} | ||
] | ||
} | ||
} | ||
} | ||
] | ||
}] | ||
} | ||
@@ -715,2 +685,2 @@ } | ||
} | ||
} | ||
} |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL, UIDLResources } from '@teleporthq/teleport-types'; | ||
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types'; | ||
export declare const webManifestDecoder: Decoder<WebManifest>; | ||
export declare const globalProjectValuesDecoder: Decoder<VUIDLGlobalProjectValues>; | ||
export declare const resourcesDecoder: Decoder<UIDLResources>; | ||
export declare const projectUIDLDecoder: Decoder<VProjectUIDL>; | ||
//# sourceMappingURL=project-decoder.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.projectUIDLDecoder = exports.resourcesDecoder = exports.globalProjectValuesDecoder = exports.webManifestDecoder = void 0; | ||
exports.projectUIDLDecoder = exports.globalProjectValuesDecoder = exports.webManifestDecoder = void 0; | ||
var json_type_validation_1 = require("@mojotech/json-type-validation"); | ||
@@ -27,3 +27,2 @@ var utils_1 = require("./utils"); | ||
})), | ||
env: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)())), | ||
meta: (0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)())), | ||
@@ -34,6 +33,2 @@ assets: (0, json_type_validation_1.array)(utils_1.globalAssetsDecoder), | ||
}); | ||
exports.resourcesDecoder = (0, json_type_validation_1.object)({ | ||
resourceMappers: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.lazy)(function () { return utils_1.dependencyDecoder; }))), | ||
items: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.lazy)(function () { return utils_1.resourceItemDecoder; }))), | ||
}); | ||
exports.projectUIDLDecoder = (0, json_type_validation_1.object)({ | ||
@@ -44,11 +39,3 @@ name: (0, json_type_validation_1.string)(), | ||
components: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(component_decoder_1.componentUIDLDecoder)), | ||
resources: (0, json_type_validation_1.optional)(exports.resourcesDecoder), | ||
contexts: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
rootFolder: (0, json_type_validation_1.string)(), | ||
items: (0, json_type_validation_1.dict)((0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
fileName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
})), | ||
})), | ||
}); | ||
//# sourceMappingURL=project-decoder.js.map |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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 } from '@teleporthq/teleport-types'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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, UIDLInjectValue, VUIDLStateValueDetails } from '@teleporthq/teleport-types'; | ||
export declare const referenceTypeDecoder: Decoder<ReferenceType>; | ||
export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>; | ||
export declare const expressionValueDecoder: Decoder<UIDLExpressionValue>; | ||
export declare const staticValueDecoder: Decoder<UIDLStaticValue>; | ||
export declare const rawValueDecoder: Decoder<UIDLRawValue>; | ||
export declare const envValueDecoder: Decoder<UIDLENVValue>; | ||
export declare const dyamicFunctionParam: Decoder<UIDLPropValue>; | ||
export declare const resourceItemDecoder: Decoder<UIDLResourceItem>; | ||
export declare const initialPropsDecoder: Decoder<UIDLInitialPropsData>; | ||
export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>; | ||
export declare const injectValueDecoder: Decoder<UIDLInjectValue>; | ||
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>; | ||
@@ -19,2 +14,3 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>; | ||
export declare const stateOrPropDefinitionDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const globalAssetsDecoder: Decoder<VUIDLGlobalAsset>; | ||
@@ -30,7 +26,5 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>; | ||
export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>; | ||
export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>; | ||
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>; | ||
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>; | ||
export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>; | ||
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>; | ||
@@ -50,3 +44,2 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>; | ||
export declare const urlLinkNodeDecoder: Decoder<VUIDLURLLinkNode>; | ||
export declare const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode>; | ||
export declare const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode>; | ||
@@ -71,5 +64,3 @@ export declare const navLinkNodeDecoder: Decoder<UIDLNavLinkNode>; | ||
export declare const elementNodeDecoder: Decoder<VUIDLElementNode>; | ||
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const uidlNodeDecoder: Decoder<VUIDLNode>; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = 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.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.dyamicFunctionParam = exports.envValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.expressionValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0; | ||
exports.uidlNodeDecoder = exports.cmsListNodeDecoder = exports.cmsItemNodeDecoder = 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 = void 0; | ||
exports.elementInlineReferencedStyle = exports.elementProjectReferencedStyle = exports.styleConditionsDecoder = exports.elementStyleWithMediaConditionDecoder = exports.elementStyleWithStateConditionDecoder = exports.elementStateDecoder = exports.uidlLinkNodeDecoder = exports.phoneLinkNodeDecoder = exports.uidlMailLinkNodeDecoder = exports.navLinkNodeDecoder = exports.sectionLinkNodeDecoder = exports.urlLinkNodeDecoder = exports.stateChangeEventDecoder = exports.propCallEventDecoder = exports.eventHandlerStatementDecoder = exports.styleDefinitionsDecoder = exports.styleValueDecoder = exports.uidlComponentStyleReference = exports.attributeValueDecoder = exports.importReferenceDecoder = exports.dependencyDecoder = exports.localDependencyDecoder = exports.externaldependencyDecoder = exports.peerDependencyDecoder = exports.outputOptionsDecoder = exports.stateDefinitionsDecoder = exports.propDefinitionsDecoder = exports.stateValueDetailsDecoder = exports.componentSeoDecoder = exports.iconAssetDecoder = exports.canonicalAssetDecoder = exports.fontAssetDecoder = exports.externalStyleAssetDecoder = exports.inlineStyletAssetDecoder = exports.externalScriptAssetDecoder = exports.inlineScriptAssetDecoder = exports.baseAssetDecoder = exports.globalAssetsDecoder = exports.pageOptionsDecoder = exports.stateOrPropDefinitionDecoder = exports.styleSetDefinitionDecoder = exports.tokenReferenceDecoder = exports.projectStyleConditionsDecoder = exports.styleSetStateConditionDecoder = exports.styleSetMediaConditionDecoder = exports.injectValueDecoder = exports.rawValueDecoder = exports.staticValueDecoder = exports.dynamicValueDecoder = exports.referenceTypeDecoder = void 0; | ||
exports.uidlNodeDecoder = exports.elementNodeDecoder = exports.conditionalNodeDecoder = exports.repeatNodeDecoder = exports.slotNodeDecoder = exports.elementDecoder = exports.designTokensDecoder = exports.elementComponentReferencedStyle = exports.classDynamicReferenceDecoder = void 0; | ||
var json_type_validation_1 = require("@mojotech/json-type-validation"); | ||
var custom_combinators_1 = require("./custom-combinators"); | ||
var isValidComponentName = custom_combinators_1.CustomCombinators.isValidComponentName, isValidFileName = custom_combinators_1.CustomCombinators.isValidFileName, isValidElementName = custom_combinators_1.CustomCombinators.isValidElementName, isValidNavLink = custom_combinators_1.CustomCombinators.isValidNavLink; | ||
exports.referenceTypeDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('state'), (0, json_type_validation_1.constant)('local'), (0, json_type_validation_1.constant)('attr'), (0, json_type_validation_1.constant)('children'), (0, json_type_validation_1.constant)('token'), (0, json_type_validation_1.constant)('ctx')); | ||
exports.referenceTypeDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('state'), (0, json_type_validation_1.constant)('local'), (0, json_type_validation_1.constant)('attr'), (0, json_type_validation_1.constant)('children'), (0, json_type_validation_1.constant)('token')); | ||
exports.dynamicValueDecoder = (0, json_type_validation_1.object)({ | ||
@@ -13,11 +13,5 @@ type: (0, json_type_validation_1.constant)('dynamic'), | ||
referenceType: exports.referenceTypeDecoder, | ||
path: (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)(), | ||
ctxId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
}), | ||
}); | ||
exports.expressionValueDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('expr'), | ||
content: (0, json_type_validation_1.string)(), | ||
}); | ||
exports.staticValueDecoder = (0, json_type_validation_1.object)({ | ||
@@ -31,50 +25,7 @@ type: (0, json_type_validation_1.constant)('static'), | ||
}); | ||
exports.envValueDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('env'), | ||
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.dyamicFunctionParam = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('dynamic'), | ||
content: (0, json_type_validation_1.object)({ | ||
referenceType: (0, json_type_validation_1.constant)('prop'), | ||
id: (0, json_type_validation_1.string)(), | ||
}), | ||
}); | ||
exports.resourceItemDecoder = (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
headers: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, exports.envValueDecoder))), | ||
path: (0, json_type_validation_1.object)({ | ||
baseUrl: (0, json_type_validation_1.union)(exports.staticValueDecoder, exports.envValueDecoder), | ||
route: exports.staticValueDecoder, | ||
}), | ||
method: (0, json_type_validation_1.withDefault)('GET', (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('GET'), (0, json_type_validation_1.constant)('POST'))), | ||
body: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.staticValueDecoder)), | ||
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))), | ||
response: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
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'))), | ||
})), | ||
}); | ||
exports.initialPropsDecoder = (0, json_type_validation_1.object)({ | ||
exposeAs: (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
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.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))), | ||
}), | ||
}); | ||
exports.initialPathsDecoder = (0, json_type_validation_1.object)({ | ||
exposeAs: (0, json_type_validation_1.object)({ | ||
name: (0, json_type_validation_1.string)(), | ||
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
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.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))), | ||
}), | ||
}); | ||
exports.styleSetMediaConditionDecoder = (0, json_type_validation_1.object)({ | ||
@@ -109,7 +60,11 @@ type: (0, json_type_validation_1.constant)('screen-size'), | ||
content: (0, json_type_validation_1.dict)((0, json_type_validation_1.union)(exports.staticValueDecoder, (0, json_type_validation_1.string)(), (0, json_type_validation_1.number)(), exports.tokenReferenceDecoder)), | ||
className: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
subselectors: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
}); | ||
// TODO: Implement decoder for () => void | ||
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.pageOptionsDecoder = (0, json_type_validation_1.object)({ | ||
componentName: (0, json_type_validation_1.optional)(isValidComponentName()), | ||
navLink: (0, json_type_validation_1.optional)(isValidNavLink()), | ||
fileName: (0, json_type_validation_1.optional)(isValidFileName()), | ||
fallback: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()), | ||
}); | ||
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; })); | ||
@@ -158,6 +113,11 @@ exports.baseAssetDecoder = (0, json_type_validation_1.object)({ | ||
exports.componentSeoDecoder = (0, json_type_validation_1.object)({ | ||
title: (0, json_type_validation_1.optional)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), exports.staticValueDecoder, exports.dynamicValueDecoder)), | ||
metaTags: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), exports.staticValueDecoder, exports.dynamicValueDecoder)))), | ||
title: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
metaTags: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.dict)((0, json_type_validation_1.string)()))), | ||
assets: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)(exports.globalAssetsDecoder)), | ||
}); | ||
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.propDefinitionsDecoder = (0, json_type_validation_1.object)({ | ||
@@ -168,10 +128,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')), | ||
}); | ||
exports.pageOptionsPaginationDecoder = (0, json_type_validation_1.object)({ | ||
attribute: (0, json_type_validation_1.string)(), | ||
pageSize: (0, json_type_validation_1.number)(), | ||
totalCountPath: (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('headers'), (0, json_type_validation_1.constant)('body')), | ||
path: (0, json_type_validation_1.array)((0, json_type_validation_1.union)((0, json_type_validation_1.string)(), (0, json_type_validation_1.number)())), | ||
}), | ||
}); | ||
exports.stateDefinitionsDecoder = (0, json_type_validation_1.object)({ | ||
@@ -181,21 +133,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')), | ||
}); | ||
exports.pageOptionsDecoder = (0, json_type_validation_1.object)({ | ||
componentName: (0, json_type_validation_1.optional)(isValidComponentName()), | ||
navLink: (0, json_type_validation_1.optional)(isValidNavLink()), | ||
fileName: (0, json_type_validation_1.optional)(isValidFileName()), | ||
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), | ||
initialPropsData: (0, json_type_validation_1.optional)(exports.initialPropsDecoder), | ||
initialPathsData: (0, json_type_validation_1.optional)(exports.initialPathsDecoder), | ||
propDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.propDefinitionsDecoder)), | ||
stateDefinitions: (0, json_type_validation_1.optional)((0, json_type_validation_1.dict)(exports.stateDefinitionsDecoder)), | ||
}); | ||
// @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)({ | ||
@@ -234,3 +167,2 @@ componentClassName: (0, json_type_validation_1.optional)(isValidComponentName()), | ||
importJustPath: (0, json_type_validation_1.optional)((0, json_type_validation_1.boolean)()), | ||
importAlias: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
})), | ||
@@ -270,10 +202,2 @@ }); | ||
}); | ||
exports.dynamicLinkDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('dynamic'), | ||
content: (0, json_type_validation_1.object)({ | ||
referenceType: exports.referenceTypeDecoder, | ||
path: (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)(), | ||
}), | ||
}); | ||
exports.sectionLinkNodeDecoder = (0, json_type_validation_1.object)({ | ||
@@ -303,3 +227,3 @@ type: (0, json_type_validation_1.constant)('section'), | ||
}); | ||
exports.uidlLinkNodeDecoder = (0, json_type_validation_1.union)(exports.urlLinkNodeDecoder, exports.sectionLinkNodeDecoder, exports.navLinkNodeDecoder, exports.uidlMailLinkNodeDecoder, exports.phoneLinkNodeDecoder, exports.dynamicLinkDecoder); | ||
exports.uidlLinkNodeDecoder = (0, json_type_validation_1.union)(exports.urlLinkNodeDecoder, exports.sectionLinkNodeDecoder, exports.navLinkNodeDecoder, exports.uidlMailLinkNodeDecoder, exports.phoneLinkNodeDecoder); | ||
exports.elementStateDecoder = (0, json_type_validation_1.oneOf)((0, json_type_validation_1.constant)('hover'), (0, json_type_validation_1.constant)('active'), (0, json_type_validation_1.constant)('focus'), (0, json_type_validation_1.constant)('focus-within'), (0, json_type_validation_1.constant)('focus-visible'), (0, json_type_validation_1.constant)('disabled'), (0, json_type_validation_1.constant)('visited'), (0, json_type_validation_1.constant)('checked'), (0, json_type_validation_1.constant)('link')); | ||
@@ -337,3 +261,3 @@ exports.elementStyleWithStateConditionDecoder = (0, json_type_validation_1.object)({ | ||
content: (0, json_type_validation_1.object)({ | ||
referenceType: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('comp'), (0, json_type_validation_1.constant)('ctx')), | ||
referenceType: (0, json_type_validation_1.union)((0, json_type_validation_1.constant)('prop'), (0, json_type_validation_1.constant)('comp')), | ||
id: (0, json_type_validation_1.string)(), | ||
@@ -355,3 +279,2 @@ }), | ||
key: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
ctxId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
dependency: (0, json_type_validation_1.optional)(exports.dependencyDecoder), | ||
@@ -362,3 +285,3 @@ style: (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)()))), | ||
abilities: (0, json_type_validation_1.optional)((0, json_type_validation_1.object)({ | ||
link: (0, json_type_validation_1.optional)((0, json_type_validation_1.anyJson)()), | ||
link: (0, json_type_validation_1.optional)(exports.uidlLinkNodeDecoder), | ||
})), | ||
@@ -406,40 +329,3 @@ children: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.lazy)(function () { return exports.uidlNodeDecoder; }))), | ||
}); | ||
exports.cmsItemNodeDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('cms-item'), | ||
content: (0, json_type_validation_1.object)({ | ||
nodes: (0, json_type_validation_1.object)({ | ||
success: (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; })), | ||
loading: (0, json_type_validation_1.optional)((0, json_type_validation_1.lazy)(function () { return exports.elementNodeDecoder; })), | ||
}), | ||
resourceId: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
statePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
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))), | ||
})), | ||
}), | ||
}); | ||
exports.cmsListNodeDecoder = (0, json_type_validation_1.object)({ | ||
type: (0, json_type_validation_1.constant)('cms-list'), | ||
content: (0, json_type_validation_1.object)({ | ||
nodes: (0, json_type_validation_1.object)({ | ||
success: (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; })), | ||
loading: (0, json_type_validation_1.optional)((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; })), | ||
}), | ||
statePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
loopItemsReference: (0, json_type_validation_1.optional)(exports.dynamicValueDecoder), | ||
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))), | ||
})), | ||
}), | ||
}); | ||
exports.uidlNodeDecoder = (0, json_type_validation_1.union)(exports.elementNodeDecoder, exports.cmsItemNodeDecoder, exports.cmsListNodeDecoder, exports.dynamicValueDecoder, exports.staticValueDecoder, exports.rawValueDecoder, exports.conditionalNodeDecoder, (0, json_type_validation_1.union)(exports.repeatNodeDecoder, exports.slotNodeDecoder, (0, json_type_validation_1.string)())); | ||
exports.uidlNodeDecoder = (0, json_type_validation_1.union)((0, json_type_validation_1.union)(exports.dynamicValueDecoder, exports.staticValueDecoder), (0, json_type_validation_1.union)(exports.rawValueDecoder, exports.elementNodeDecoder), (0, json_type_validation_1.union)(exports.repeatNodeDecoder, exports.conditionalNodeDecoder), (0, json_type_validation_1.union)(exports.slotNodeDecoder, exports.injectValueDecoder), (0, json_type_validation_1.string)()); | ||
//# sourceMappingURL=utils.js.map |
@@ -20,18 +20,5 @@ "use strict"; | ||
var safeInput = params.noClone ? input : teleport_shared_1.UIDLUtils.cloneObject(input); | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) { | ||
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) { | ||
var propName = teleport_shared_1.StringUtils.createStateOrPropStoringValue(prop); | ||
acc[propName] = safeInput.propDefinitions[prop]; | ||
return acc; | ||
}, {}); | ||
} | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) { | ||
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce(function (acc, state) { | ||
var stateName = teleport_shared_1.StringUtils.createStateOrPropStoringValue(state); | ||
acc[stateName] = safeInput.stateDefinitions[state]; | ||
return acc; | ||
}, {}); | ||
} | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions) { | ||
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) { | ||
var styleSetDefinitions = safeInput.styleSetDefinitions; | ||
Object.values(styleSetDefinitions).forEach(function (styleRef) { | ||
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a; | ||
@@ -54,3 +41,3 @@ styleRef.content = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(styleRef.content); | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node, result); | ||
result.node = parseComponentNode(node); | ||
return result; | ||
@@ -92,61 +79,12 @@ }; | ||
exports.parseProjectJSON = parseProjectJSON; | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e; | ||
var parseComponentNode = function (node) { | ||
var _a, _b; | ||
switch (node.type) { | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'element': | ||
var elementContent = node.content; | ||
if (node.type === 'cms-item') { | ||
var _f = node.content, _g = _f.nodes, success = _g.success, error = _g.error, loading = _g.loading, statePersistanceName = _f.statePersistanceName; | ||
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) || {}); | ||
component.stateDefinitions["".concat(statePersistanceName, "Error")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loading) { | ||
component.stateDefinitions["".concat(statePersistanceName, "Loading")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
} | ||
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) { | ||
var _h = node.content, loopItemsReference = _h.loopItemsReference, statePersistanceName = _h.statePersistanceName, _j = _h.nodes, success = _j.success, error = _j.error, loading = _j.loading; | ||
var identifier = (loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' && | ||
loopItemsReference.content.referenceType === 'prop' | ||
? 'propDefinitions' | ||
: 'stateDefinitions'; | ||
if (success) { | ||
success.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_c = success === null || success === void 0 ? void 0 : success.content) === null || _c === void 0 ? void 0 : _c.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = teleport_shared_1.UIDLUtils.transformAttributesAssignmentsToJson(((_d = error === null || error === void 0 ? void 0 : error.content) === null || _d === void 0 ? void 0 : _d.attrs) || {}); | ||
component[identifier]["".concat(statePersistanceName, "Error")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loading) { | ||
component[identifier]["".concat(statePersistanceName, "Loading")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loopItemsReference && | ||
(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' && | ||
['state', 'prop'].includes(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.content.referenceType)) { | ||
loopItemsReference.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(loopItemsReference.content.id); | ||
} | ||
} | ||
if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) { | ||
Object.values(elementContent.referencedStyles).forEach(function (styleRef) { | ||
switch (styleRef.content.mapType) { | ||
var content = styleRef.content; | ||
switch (content.mapType) { | ||
case 'inlined': { | ||
var content = styleRef.content; | ||
content.styles = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(content.styles); | ||
@@ -167,3 +105,3 @@ break; | ||
default: { | ||
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType)); | ||
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType)); | ||
} | ||
@@ -179,15 +117,9 @@ } | ||
} | ||
if ((_e = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('link')) { | ||
var _k = elementContent.abilities.link, content = _k.content, type = _k.type; | ||
// @ts-ignore | ||
if ((_a = elementContent.abilities) === null || _a === void 0 ? void 0 : _a.link) { | ||
// @ts-ignore | ||
var _c = (_b = elementContent.abilities) === null || _b === void 0 ? void 0 : _b.link, content = _c.content, type = _c.type; | ||
if (type === 'url' && typeof content.url === 'string') { | ||
content.url = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(content.url); | ||
} | ||
if (type === 'url' && content.url.type === 'dynamic') { | ||
; | ||
content.url.content = { | ||
referenceType: content.url | ||
.content.referenceType, | ||
id: teleport_shared_1.StringUtils.createStateOrPropStoringValue(content.url.content.id), | ||
}; | ||
} | ||
} | ||
@@ -200,3 +132,3 @@ if (Array.isArray(elementContent.children)) { | ||
else { | ||
return parseComponentNode(child, component); | ||
return parseComponentNode(child); | ||
} | ||
@@ -209,3 +141,3 @@ }, []); | ||
var reference = conditionalNode.content.reference; | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component); | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node); | ||
if (typeof reference === 'string') { | ||
@@ -218,3 +150,3 @@ conditionalNode.content.reference = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(reference); | ||
var dataSource = repeatNode.content.dataSource; | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component); | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node); | ||
if (typeof dataSource === 'string') { | ||
@@ -227,13 +159,9 @@ repeatNode.content.dataSource = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(dataSource); | ||
if (slotNode.content.fallback) { | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component); | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback); | ||
} | ||
return slotNode; | ||
case 'dynamic': | ||
var dyamicNode = node; | ||
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) { | ||
dyamicNode.content.id = teleport_shared_1.StringUtils.createStateOrPropStoringValue(dyamicNode.content.id); | ||
} | ||
return dyamicNode; | ||
case 'static': | ||
case 'raw': | ||
case 'inject': | ||
return node; | ||
@@ -240,0 +168,0 @@ default: |
@@ -139,3 +139,3 @@ "use strict"; | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions \n Used on Node ").concat(JSON.stringify(node.content)); | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -150,3 +150,4 @@ } | ||
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) { | ||
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions")); | ||
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"); | ||
errors.push(errorMsg); | ||
} | ||
@@ -153,0 +154,0 @@ // for member expression we check the root |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL, UIDLResources } from '@teleporthq/teleport-types'; | ||
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types'; | ||
export declare const webManifestDecoder: Decoder<WebManifest>; | ||
export declare const globalProjectValuesDecoder: Decoder<VUIDLGlobalProjectValues>; | ||
export declare const resourcesDecoder: Decoder<UIDLResources>; | ||
export declare const projectUIDLDecoder: Decoder<VProjectUIDL>; | ||
//# sourceMappingURL=project-decoder.d.ts.map |
@@ -1,3 +0,3 @@ | ||
import { object, optional, string, dict, array, lazy, } from '@mojotech/json-type-validation'; | ||
import { dependencyDecoder, globalAssetsDecoder, resourceItemDecoder } from './utils'; | ||
import { object, optional, string, dict, array } from '@mojotech/json-type-validation'; | ||
import { globalAssetsDecoder } from './utils'; | ||
import { componentUIDLDecoder, rootComponentUIDLDecoder } from './component-decoder'; | ||
@@ -24,3 +24,2 @@ export var webManifestDecoder = object({ | ||
})), | ||
env: optional(dict(string())), | ||
meta: array(dict(string())), | ||
@@ -31,6 +30,2 @@ assets: array(globalAssetsDecoder), | ||
}); | ||
export var resourcesDecoder = object({ | ||
resourceMappers: optional(dict(lazy(function () { return dependencyDecoder; }))), | ||
items: optional(dict(lazy(function () { return resourceItemDecoder; }))), | ||
}); | ||
export var projectUIDLDecoder = object({ | ||
@@ -41,11 +36,3 @@ name: string(), | ||
components: optional(dict(componentUIDLDecoder)), | ||
resources: optional(resourcesDecoder), | ||
contexts: optional(object({ | ||
rootFolder: string(), | ||
items: dict(object({ | ||
name: string(), | ||
fileName: optional(string()), | ||
})), | ||
})), | ||
}); | ||
//# sourceMappingURL=project-decoder.js.map |
import { Decoder } from '@mojotech/json-type-validation'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLStateValueDetails, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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 } from '@teleporthq/teleport-types'; | ||
import { UIDLStaticValue, ReferenceType, UIDLDynamicReference, UIDLPropDefinition, UIDLStateDefinition, UIDLPageOptions, UIDLComponentOutputOptions, UIDLDependency, UIDLStyleDefinitions, UIDLStyleValue, UIDLAttributeValue, UIDLEventHandlerStatement, UIDLNavLinkNode, 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, UIDLInjectValue, VUIDLStateValueDetails } from '@teleporthq/teleport-types'; | ||
export declare const referenceTypeDecoder: Decoder<ReferenceType>; | ||
export declare const dynamicValueDecoder: Decoder<UIDLDynamicReference>; | ||
export declare const expressionValueDecoder: Decoder<UIDLExpressionValue>; | ||
export declare const staticValueDecoder: Decoder<UIDLStaticValue>; | ||
export declare const rawValueDecoder: Decoder<UIDLRawValue>; | ||
export declare const envValueDecoder: Decoder<UIDLENVValue>; | ||
export declare const dyamicFunctionParam: Decoder<UIDLPropValue>; | ||
export declare const resourceItemDecoder: Decoder<UIDLResourceItem>; | ||
export declare const initialPropsDecoder: Decoder<UIDLInitialPropsData>; | ||
export declare const initialPathsDecoder: Decoder<UIDLInitialPathsData>; | ||
export declare const injectValueDecoder: Decoder<UIDLInjectValue>; | ||
export declare const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition>; | ||
@@ -19,2 +14,3 @@ export declare const styleSetStateConditionDecoder: Decoder<VUIDLStyleSetStateCondition>; | ||
export declare const stateOrPropDefinitionDecoder: Decoder<string | number | boolean | Record<string, unknown> | (string | number | Record<string, unknown>)[]>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const globalAssetsDecoder: Decoder<VUIDLGlobalAsset>; | ||
@@ -30,7 +26,5 @@ export declare const baseAssetDecoder: Decoder<UIDLAssetBase>; | ||
export declare const componentSeoDecoder: Decoder<VUIDLComponentSEO>; | ||
export declare const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails>; | ||
export declare const propDefinitionsDecoder: Decoder<UIDLPropDefinition>; | ||
export declare const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions>; | ||
export declare const stateDefinitionsDecoder: Decoder<UIDLStateDefinition>; | ||
export declare const pageOptionsDecoder: Decoder<UIDLPageOptions>; | ||
export declare const stateValueDetailsDecoder: Decoder<UIDLStateValueDetails>; | ||
export declare const outputOptionsDecoder: Decoder<UIDLComponentOutputOptions>; | ||
@@ -50,3 +44,2 @@ export declare const peerDependencyDecoder: Decoder<UIDLPeerDependency>; | ||
export declare const urlLinkNodeDecoder: Decoder<VUIDLURLLinkNode>; | ||
export declare const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode>; | ||
export declare const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode>; | ||
@@ -71,5 +64,3 @@ export declare const navLinkNodeDecoder: Decoder<UIDLNavLinkNode>; | ||
export declare const elementNodeDecoder: Decoder<VUIDLElementNode>; | ||
export declare const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode>; | ||
export declare const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode>; | ||
export declare const uidlNodeDecoder: Decoder<VUIDLNode>; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -1,5 +0,5 @@ | ||
import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, withDefault, anyJson, } from '@mojotech/json-type-validation'; | ||
import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, withDefault, } from '@mojotech/json-type-validation'; | ||
import { CustomCombinators } from './custom-combinators'; | ||
var isValidComponentName = CustomCombinators.isValidComponentName, isValidFileName = CustomCombinators.isValidFileName, isValidElementName = CustomCombinators.isValidElementName, isValidNavLink = CustomCombinators.isValidNavLink; | ||
export var referenceTypeDecoder = union(constant('prop'), constant('state'), constant('local'), constant('attr'), constant('children'), constant('token'), constant('ctx')); | ||
export var referenceTypeDecoder = union(constant('prop'), constant('state'), constant('local'), constant('attr'), constant('children'), constant('token')); | ||
export var dynamicValueDecoder = object({ | ||
@@ -9,11 +9,5 @@ type: constant('dynamic'), | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
id: string(), | ||
ctxId: optional(string()), | ||
}), | ||
}); | ||
export var expressionValueDecoder = object({ | ||
type: constant('expr'), | ||
content: string(), | ||
}); | ||
export var staticValueDecoder = object({ | ||
@@ -27,50 +21,7 @@ type: constant('static'), | ||
}); | ||
export var envValueDecoder = object({ | ||
type: constant('env'), | ||
export var injectValueDecoder = object({ | ||
type: constant('inject'), | ||
content: string(), | ||
dependency: optional(lazy(function () { return externaldependencyDecoder; })), | ||
}); | ||
export var dyamicFunctionParam = object({ | ||
type: constant('dynamic'), | ||
content: object({ | ||
referenceType: constant('prop'), | ||
id: string(), | ||
}), | ||
}); | ||
export var resourceItemDecoder = object({ | ||
name: string(), | ||
headers: optional(dict(union(staticValueDecoder, envValueDecoder))), | ||
path: object({ | ||
baseUrl: union(staticValueDecoder, envValueDecoder), | ||
route: staticValueDecoder, | ||
}), | ||
method: withDefault('GET', union(constant('GET'), constant('POST'))), | ||
body: optional(dict(staticValueDecoder)), | ||
mappers: withDefault([], array(string())), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam))), | ||
response: optional(object({ | ||
type: withDefault('json', union(constant('json'), constant('headers'), constant('text'))), | ||
})), | ||
}); | ||
export var initialPropsDecoder = object({ | ||
exposeAs: object({ | ||
name: string(), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
}); | ||
export var initialPathsDecoder = object({ | ||
exposeAs: object({ | ||
name: string(), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
}); | ||
export var styleSetMediaConditionDecoder = object({ | ||
@@ -105,7 +56,11 @@ type: constant('screen-size'), | ||
content: dict(union(staticValueDecoder, string(), number(), tokenReferenceDecoder)), | ||
className: optional(string()), | ||
subselectors: optional(string()), | ||
}); | ||
// TODO: Implement decoder for () => void | ||
export var stateOrPropDefinitionDecoder = union(string(), number(), boolean(), array(union(string(), number(), object())), object()); | ||
export var pageOptionsDecoder = object({ | ||
componentName: optional(isValidComponentName()), | ||
navLink: optional(isValidNavLink()), | ||
fileName: optional(isValidFileName()), | ||
fallback: optional(boolean()), | ||
}); | ||
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; })); | ||
@@ -154,6 +109,11 @@ export var baseAssetDecoder = object({ | ||
export var componentSeoDecoder = object({ | ||
title: optional(union(string(), staticValueDecoder, dynamicValueDecoder)), | ||
metaTags: optional(array(dict(union(string(), staticValueDecoder, dynamicValueDecoder)))), | ||
title: optional(string()), | ||
metaTags: optional(array(dict(string()))), | ||
assets: optional(array(globalAssetsDecoder)), | ||
}); | ||
export var stateValueDetailsDecoder = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(pageOptionsDecoder), | ||
seo: optional(componentSeoDecoder), | ||
}); | ||
export var propDefinitionsDecoder = object({ | ||
@@ -164,10 +124,2 @@ type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')), | ||
}); | ||
export var pageOptionsPaginationDecoder = object({ | ||
attribute: string(), | ||
pageSize: number(), | ||
totalCountPath: object({ | ||
type: union(constant('headers'), constant('body')), | ||
path: array(union(string(), number())), | ||
}), | ||
}); | ||
export var stateDefinitionsDecoder = object({ | ||
@@ -177,21 +129,2 @@ type: union(constant('string'), constant('boolean'), constant('number'), constant('array'), constant('func'), constant('object'), constant('children')), | ||
}); | ||
export var pageOptionsDecoder = object({ | ||
componentName: optional(isValidComponentName()), | ||
navLink: optional(isValidNavLink()), | ||
fileName: optional(isValidFileName()), | ||
fallback: optional(boolean()), | ||
dynamicRouteAttribute: optional(string()), | ||
isIndex: optional(boolean()), | ||
pagination: optional(pageOptionsPaginationDecoder), | ||
initialPropsData: optional(initialPropsDecoder), | ||
initialPathsData: optional(initialPathsDecoder), | ||
propDefinitions: optional(dict(propDefinitionsDecoder)), | ||
stateDefinitions: optional(dict(stateDefinitionsDecoder)), | ||
}); | ||
// @ts-ignore | ||
export var stateValueDetailsDecoder = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(pageOptionsDecoder), | ||
seo: optional(componentSeoDecoder), | ||
}); | ||
export var outputOptionsDecoder = object({ | ||
@@ -230,3 +163,2 @@ componentClassName: optional(isValidComponentName()), | ||
importJustPath: optional(boolean()), | ||
importAlias: optional(string()), | ||
})), | ||
@@ -266,10 +198,2 @@ }); | ||
}); | ||
export var dynamicLinkDecoder = object({ | ||
type: constant('dynamic'), | ||
content: object({ | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
id: string(), | ||
}), | ||
}); | ||
export var sectionLinkNodeDecoder = object({ | ||
@@ -299,3 +223,3 @@ type: constant('section'), | ||
}); | ||
export var uidlLinkNodeDecoder = union(urlLinkNodeDecoder, sectionLinkNodeDecoder, navLinkNodeDecoder, uidlMailLinkNodeDecoder, phoneLinkNodeDecoder, dynamicLinkDecoder); | ||
export var uidlLinkNodeDecoder = union(urlLinkNodeDecoder, sectionLinkNodeDecoder, navLinkNodeDecoder, uidlMailLinkNodeDecoder, phoneLinkNodeDecoder); | ||
export var elementStateDecoder = oneOf(constant('hover'), constant('active'), constant('focus'), constant('focus-within'), constant('focus-visible'), constant('disabled'), constant('visited'), constant('checked'), constant('link')); | ||
@@ -333,3 +257,3 @@ export var elementStyleWithStateConditionDecoder = object({ | ||
content: object({ | ||
referenceType: union(constant('prop'), constant('comp'), constant('ctx')), | ||
referenceType: union(constant('prop'), constant('comp')), | ||
id: string(), | ||
@@ -351,3 +275,2 @@ }), | ||
key: optional(string()), | ||
ctxId: optional(string()), | ||
dependency: optional(dependencyDecoder), | ||
@@ -358,3 +281,3 @@ style: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
abilities: optional(object({ | ||
link: optional(anyJson()), | ||
link: optional(uidlLinkNodeDecoder), | ||
})), | ||
@@ -402,40 +325,3 @@ children: optional(array(lazy(function () { return uidlNodeDecoder; }))), | ||
}); | ||
export var cmsItemNodeDecoder = object({ | ||
type: constant('cms-item'), | ||
content: object({ | ||
nodes: object({ | ||
success: lazy(function () { return elementNodeDecoder; }), | ||
error: optional(lazy(function () { return elementNodeDecoder; })), | ||
loading: optional(lazy(function () { return elementNodeDecoder; })), | ||
}), | ||
resourceId: optional(string()), | ||
statePersistanceName: optional(string()), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
resource: optional(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
})), | ||
}), | ||
}); | ||
export var cmsListNodeDecoder = object({ | ||
type: constant('cms-list'), | ||
content: object({ | ||
nodes: object({ | ||
success: lazy(function () { return elementNodeDecoder; }), | ||
error: optional(lazy(function () { return elementNodeDecoder; })), | ||
loading: optional(lazy(function () { return elementNodeDecoder; })), | ||
empty: optional(lazy(function () { return elementNodeDecoder; })), | ||
}), | ||
statePersistanceName: optional(string()), | ||
itemValuePath: optional(array(string())), | ||
valuePath: optional(array(string())), | ||
loopItemsReference: optional(dynamicValueDecoder), | ||
resource: optional(object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
})), | ||
}), | ||
}); | ||
export var uidlNodeDecoder = union(elementNodeDecoder, cmsItemNodeDecoder, cmsListNodeDecoder, dynamicValueDecoder, staticValueDecoder, rawValueDecoder, conditionalNodeDecoder, union(repeatNodeDecoder, slotNodeDecoder, string())); | ||
export var uidlNodeDecoder = union(union(dynamicValueDecoder, staticValueDecoder), union(rawValueDecoder, elementNodeDecoder), union(repeatNodeDecoder, conditionalNodeDecoder), union(slotNodeDecoder, injectValueDecoder), string()); | ||
//# sourceMappingURL=utils.js.map |
@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { ParserError, } from '@teleporthq/teleport-types'; | ||
@@ -18,18 +18,5 @@ export var parseComponentJSON = function (input, params) { | ||
var safeInput = params.noClone ? input : UIDLUtils.cloneObject(input); | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.propDefinitions) { | ||
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce(function (acc, prop) { | ||
var propName = StringUtils.createStateOrPropStoringValue(prop); | ||
acc[propName] = safeInput.propDefinitions[prop]; | ||
return acc; | ||
}, {}); | ||
} | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.stateDefinitions) { | ||
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce(function (acc, state) { | ||
var stateName = StringUtils.createStateOrPropStoringValue(state); | ||
acc[stateName] = safeInput.stateDefinitions[state]; | ||
return acc; | ||
}, {}); | ||
} | ||
if (safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions) { | ||
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) { | ||
var styleSetDefinitions = safeInput.styleSetDefinitions; | ||
Object.values(styleSetDefinitions).forEach(function (styleRef) { | ||
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a; | ||
@@ -52,3 +39,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content); | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node, result); | ||
result.node = parseComponentNode(node); | ||
return result; | ||
@@ -88,61 +75,12 @@ }; | ||
}; | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e; | ||
var parseComponentNode = function (node) { | ||
var _a, _b; | ||
switch (node.type) { | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'element': | ||
var elementContent = node.content; | ||
if (node.type === 'cms-item') { | ||
var _f = node.content, _g = _f.nodes, success = _g.success, error = _g.error, loading = _g.loading, statePersistanceName = _f.statePersistanceName; | ||
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) || {}); | ||
component.stateDefinitions["".concat(statePersistanceName, "Error")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loading) { | ||
component.stateDefinitions["".concat(statePersistanceName, "Loading")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
} | ||
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) { | ||
var _h = node.content, loopItemsReference = _h.loopItemsReference, statePersistanceName = _h.statePersistanceName, _j = _h.nodes, success = _j.success, error = _j.error, loading = _j.loading; | ||
var identifier = (loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' && | ||
loopItemsReference.content.referenceType === 'prop' | ||
? 'propDefinitions' | ||
: 'stateDefinitions'; | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_c = success === null || success === void 0 ? void 0 : success.content) === null || _c === void 0 ? void 0 : _c.attrs) || {}); | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson(((_d = error === null || error === void 0 ? void 0 : error.content) === null || _d === void 0 ? void 0 : _d.attrs) || {}); | ||
component[identifier]["".concat(statePersistanceName, "Error")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loading) { | ||
component[identifier]["".concat(statePersistanceName, "Loading")] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
}; | ||
} | ||
if (loopItemsReference && | ||
(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.type) === 'dynamic' && | ||
['state', 'prop'].includes(loopItemsReference === null || loopItemsReference === void 0 ? void 0 : loopItemsReference.content.referenceType)) { | ||
loopItemsReference.content.id = StringUtils.createStateOrPropStoringValue(loopItemsReference.content.id); | ||
} | ||
} | ||
if (elementContent === null || elementContent === void 0 ? void 0 : elementContent.referencedStyles) { | ||
Object.values(elementContent.referencedStyles).forEach(function (styleRef) { | ||
switch (styleRef.content.mapType) { | ||
var content = styleRef.content; | ||
switch (content.mapType) { | ||
case 'inlined': { | ||
var content = styleRef.content; | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles); | ||
@@ -163,3 +101,3 @@ break; | ||
default: { | ||
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType)); | ||
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType)); | ||
} | ||
@@ -175,15 +113,9 @@ } | ||
} | ||
if ((_e = elementContent === null || elementContent === void 0 ? void 0 : elementContent.abilities) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('link')) { | ||
var _k = elementContent.abilities.link, content = _k.content, type = _k.type; | ||
// @ts-ignore | ||
if ((_a = elementContent.abilities) === null || _a === void 0 ? void 0 : _a.link) { | ||
// @ts-ignore | ||
var _c = (_b = elementContent.abilities) === null || _b === void 0 ? void 0 : _b.link, content = _c.content, type = _c.type; | ||
if (type === 'url' && typeof content.url === 'string') { | ||
content.url = UIDLUtils.transformStringAssignmentToJson(content.url); | ||
} | ||
if (type === 'url' && content.url.type === 'dynamic') { | ||
; | ||
content.url.content = { | ||
referenceType: content.url | ||
.content.referenceType, | ||
id: StringUtils.createStateOrPropStoringValue(content.url.content.id), | ||
}; | ||
} | ||
} | ||
@@ -196,3 +128,3 @@ if (Array.isArray(elementContent.children)) { | ||
else { | ||
return parseComponentNode(child, component); | ||
return parseComponentNode(child); | ||
} | ||
@@ -205,3 +137,3 @@ }, []); | ||
var reference = conditionalNode.content.reference; | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component); | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node); | ||
if (typeof reference === 'string') { | ||
@@ -214,3 +146,3 @@ conditionalNode.content.reference = UIDLUtils.transformStringAssignmentToJson(reference); | ||
var dataSource = repeatNode.content.dataSource; | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component); | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node); | ||
if (typeof dataSource === 'string') { | ||
@@ -223,13 +155,9 @@ repeatNode.content.dataSource = UIDLUtils.transformStringAssignmentToJson(dataSource); | ||
if (slotNode.content.fallback) { | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component); | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback); | ||
} | ||
return slotNode; | ||
case 'dynamic': | ||
var dyamicNode = node; | ||
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) { | ||
dyamicNode.content.id = StringUtils.createStateOrPropStoringValue(dyamicNode.content.id); | ||
} | ||
return dyamicNode; | ||
case 'static': | ||
case 'raw': | ||
case 'inject': | ||
return node; | ||
@@ -236,0 +164,0 @@ default: |
@@ -134,3 +134,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions \n Used on Node ").concat(JSON.stringify(node.content)); | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -145,3 +145,4 @@ } | ||
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) { | ||
console.warn("\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions")); | ||
var errorMsg = "\n\"".concat(node.content.id, "\" is used but not defined. Please add it in stateDefinitions"); | ||
errors.push(errorMsg); | ||
} | ||
@@ -148,0 +149,0 @@ // for member expression we check the root |
{ | ||
"name": "@teleporthq/teleport-uidl-validator", | ||
"version": "0.27.6-alpha.0", | ||
"version": "0.27.8", | ||
"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.27.6-alpha.0", | ||
"@teleporthq/teleport-types": "^0.27.6-alpha.0" | ||
"@teleporthq/teleport-shared": "^0.27.8", | ||
"@teleporthq/teleport-types": "^0.27.8" | ||
}, | ||
"gitHead": "6c93c42321beedc5de5cedc424a5cbb184c2d55b" | ||
"gitHead": "3ae7c0728720e2b5b1663c57e08283ede422c227" | ||
} |
@@ -1,17 +0,4 @@ | ||
import { | ||
Decoder, | ||
object, | ||
optional, | ||
string, | ||
dict, | ||
array, | ||
lazy, | ||
} from '@mojotech/json-type-validation' | ||
import { | ||
VUIDLGlobalProjectValues, | ||
WebManifest, | ||
VProjectUIDL, | ||
UIDLResources, | ||
} from '@teleporthq/teleport-types' | ||
import { dependencyDecoder, globalAssetsDecoder, resourceItemDecoder } from './utils' | ||
import { Decoder, object, optional, string, dict, array } from '@mojotech/json-type-validation' | ||
import { VUIDLGlobalProjectValues, WebManifest, VProjectUIDL } from '@teleporthq/teleport-types' | ||
import { globalAssetsDecoder } from './utils' | ||
import { componentUIDLDecoder, rootComponentUIDLDecoder } from './component-decoder' | ||
@@ -42,3 +29,2 @@ | ||
), | ||
env: optional(dict(string())), | ||
meta: array(dict(string())), | ||
@@ -50,7 +36,2 @@ assets: array(globalAssetsDecoder), | ||
export const resourcesDecoder: Decoder<UIDLResources> = object({ | ||
resourceMappers: optional(dict(lazy(() => dependencyDecoder))), | ||
items: optional(dict(lazy(() => resourceItemDecoder))), | ||
}) | ||
export const projectUIDLDecoder: Decoder<VProjectUIDL> = object({ | ||
@@ -61,14 +42,2 @@ name: string(), | ||
components: optional(dict(componentUIDLDecoder)), | ||
resources: optional(resourcesDecoder), | ||
contexts: optional( | ||
object({ | ||
rootFolder: string(), | ||
items: dict( | ||
object({ | ||
name: string(), | ||
fileName: optional(string()), | ||
}) | ||
), | ||
}) | ||
), | ||
}) |
@@ -16,3 +16,2 @@ import { | ||
withDefault, | ||
anyJson, | ||
} from '@mojotech/json-type-validation' | ||
@@ -25,3 +24,2 @@ import { | ||
UIDLStateDefinition, | ||
UIDLStateValueDetails, | ||
UIDLPageOptions, | ||
@@ -78,12 +76,4 @@ UIDLComponentOutputOptions, | ||
UIDLComponentStyleReference, | ||
PagePaginationOptions, | ||
VCMSItemUIDLElementNode, | ||
VCMSListUIDLElementNode, | ||
UIDLInitialPathsData, | ||
UIDLInitialPropsData, | ||
UIDLExpressionValue, | ||
UIDLDynamicLinkNode, | ||
UIDLENVValue, | ||
UIDLPropValue, | ||
UIDLResourceItem, | ||
UIDLInjectValue, | ||
VUIDLStateValueDetails, | ||
} from '@teleporthq/teleport-types' | ||
@@ -101,4 +91,3 @@ import { CustomCombinators } from './custom-combinators' | ||
constant('children'), | ||
constant('token'), | ||
constant('ctx') | ||
constant('token') | ||
) | ||
@@ -110,13 +99,6 @@ | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
id: string(), | ||
ctxId: optional(string()), | ||
}), | ||
}) | ||
export const expressionValueDecoder: Decoder<UIDLExpressionValue> = object({ | ||
type: constant('expr'), | ||
content: string(), | ||
}) | ||
export const staticValueDecoder: Decoder<UIDLStaticValue> = object({ | ||
@@ -132,57 +114,8 @@ type: constant('static'), | ||
export const envValueDecoder: Decoder<UIDLENVValue> = object({ | ||
type: constant('env'), | ||
export const injectValueDecoder: Decoder<UIDLInjectValue> = object({ | ||
type: constant('inject'), | ||
content: string(), | ||
dependency: optional(lazy(() => externaldependencyDecoder)), | ||
}) | ||
export const dyamicFunctionParam: Decoder<UIDLPropValue> = object({ | ||
type: constant('dynamic'), | ||
content: object({ | ||
referenceType: constant('prop'), | ||
id: string(), | ||
}), | ||
}) | ||
export const resourceItemDecoder: Decoder<UIDLResourceItem> = object({ | ||
name: string(), | ||
headers: optional(dict(union(staticValueDecoder, envValueDecoder))), | ||
path: object({ | ||
baseUrl: union(staticValueDecoder, envValueDecoder), | ||
route: staticValueDecoder, | ||
}), | ||
method: withDefault('GET', union(constant('GET'), constant('POST'))), | ||
body: optional(dict(staticValueDecoder)), | ||
mappers: withDefault([], array(string())), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam))), | ||
response: optional( | ||
object({ | ||
type: withDefault('json', union(constant('json'), constant('headers'), constant('text'))), | ||
}) | ||
), | ||
}) | ||
export const initialPropsDecoder: Decoder<UIDLInitialPropsData> = object({ | ||
exposeAs: object({ | ||
name: string(), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
}) | ||
export const initialPathsDecoder: Decoder<UIDLInitialPathsData> = object({ | ||
exposeAs: object({ | ||
name: string(), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
}), | ||
resource: object({ | ||
id: string(), | ||
params: optional(dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder))), | ||
}), | ||
}) | ||
export const styleSetMediaConditionDecoder: Decoder<VUIDLStyleSetMediaCondition> = object({ | ||
@@ -242,4 +175,2 @@ type: constant('screen-size'), | ||
content: dict(union(staticValueDecoder, string(), number(), tokenReferenceDecoder)), | ||
className: optional(string()), | ||
subselectors: optional(string()), | ||
}) | ||
@@ -256,2 +187,9 @@ | ||
export const pageOptionsDecoder: Decoder<UIDLPageOptions> = object({ | ||
componentName: optional(isValidComponentName() as unknown as Decoder<string>), | ||
navLink: optional(isValidNavLink() as unknown as Decoder<string>), | ||
fileName: optional(isValidFileName() as unknown as Decoder<string>), | ||
fallback: optional(boolean()), | ||
}) | ||
export const globalAssetsDecoder: Decoder<VUIDLGlobalAsset> = union( | ||
@@ -327,7 +265,13 @@ lazy(() => inlineScriptAssetDecoder), | ||
export const componentSeoDecoder: Decoder<VUIDLComponentSEO> = object({ | ||
title: optional(union(string(), staticValueDecoder, dynamicValueDecoder)), | ||
metaTags: optional(array(dict(union(string(), staticValueDecoder, dynamicValueDecoder)))), | ||
title: optional(string()), | ||
metaTags: optional(array(dict(string()))), | ||
assets: optional(array(globalAssetsDecoder)), | ||
}) | ||
export const stateValueDetailsDecoder: Decoder<VUIDLStateValueDetails> = object({ | ||
value: union(string(), number(), boolean()), | ||
pageOptions: optional(pageOptionsDecoder), | ||
seo: optional(componentSeoDecoder), | ||
}) | ||
export const propDefinitionsDecoder: Decoder<UIDLPropDefinition> = object({ | ||
@@ -347,11 +291,2 @@ type: union( | ||
export const pageOptionsPaginationDecoder: Decoder<PagePaginationOptions> = object({ | ||
attribute: string(), | ||
pageSize: number(), | ||
totalCountPath: object({ | ||
type: union(constant('headers'), constant('body')), | ||
path: array(union(string(), number())), | ||
}), | ||
}) | ||
export const stateDefinitionsDecoder: Decoder<UIDLStateDefinition> = object({ | ||
@@ -370,23 +305,2 @@ type: union( | ||
export const pageOptionsDecoder: Decoder<UIDLPageOptions> = object({ | ||
componentName: optional(isValidComponentName() as unknown as Decoder<string>), | ||
navLink: optional(isValidNavLink() as unknown as Decoder<string>), | ||
fileName: optional(isValidFileName() as unknown as Decoder<string>), | ||
fallback: optional(boolean()), | ||
dynamicRouteAttribute: optional(string()), | ||
isIndex: optional(boolean()), | ||
pagination: optional(pageOptionsPaginationDecoder), | ||
initialPropsData: optional(initialPropsDecoder), | ||
initialPathsData: optional(initialPathsDecoder), | ||
propDefinitions: optional(dict(propDefinitionsDecoder)), | ||
stateDefinitions: optional(dict(stateDefinitionsDecoder)), | ||
}) | ||
// @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({ | ||
@@ -431,3 +345,2 @@ componentClassName: optional(isValidComponentName() as unknown as Decoder<string>), | ||
importJustPath: optional(boolean()), | ||
importAlias: optional(string()), | ||
}) | ||
@@ -494,11 +407,2 @@ ), | ||
export const dynamicLinkDecoder: Decoder<UIDLDynamicLinkNode> = object({ | ||
type: constant('dynamic'), | ||
content: object({ | ||
referenceType: referenceTypeDecoder, | ||
path: optional(array(string())), | ||
id: string(), | ||
}), | ||
}) | ||
export const sectionLinkNodeDecoder: Decoder<VUIDLSectionLinkNode> = object({ | ||
@@ -537,4 +441,3 @@ type: constant('section'), | ||
uidlMailLinkNodeDecoder, | ||
phoneLinkNodeDecoder, | ||
dynamicLinkDecoder | ||
phoneLinkNodeDecoder | ||
) | ||
@@ -596,3 +499,3 @@ | ||
content: object({ | ||
referenceType: union(constant('prop'), constant('comp'), constant('ctx')), | ||
referenceType: union(constant('prop'), constant('comp')), | ||
id: string(), | ||
@@ -620,3 +523,2 @@ }), | ||
key: optional(string()), | ||
ctxId: optional(string()), | ||
dependency: optional(dependencyDecoder), | ||
@@ -628,3 +530,3 @@ style: optional(dict(union(attributeValueDecoder, string(), number()))), | ||
object({ | ||
link: optional(anyJson()), | ||
link: optional(uidlLinkNodeDecoder), | ||
}) | ||
@@ -701,58 +603,8 @@ ), | ||
export const cmsItemNodeDecoder: Decoder<VCMSItemUIDLElementNode> = object({ | ||
type: constant('cms-item'), | ||
content: object({ | ||
nodes: object({ | ||
success: lazy(() => elementNodeDecoder), | ||
error: optional(lazy(() => elementNodeDecoder)), | ||
loading: optional(lazy(() => elementNodeDecoder)), | ||
}), | ||
resourceId: optional(string()), | ||
statePersistanceName: optional(string()), | ||
valuePath: optional(array(string())), | ||
itemValuePath: optional(array(string())), | ||
resource: optional( | ||
object({ | ||
id: string(), | ||
params: optional( | ||
dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder)) | ||
), | ||
}) | ||
), | ||
}), | ||
}) | ||
export const cmsListNodeDecoder: Decoder<VCMSListUIDLElementNode> = object({ | ||
type: constant('cms-list'), | ||
content: object({ | ||
nodes: object({ | ||
success: lazy(() => elementNodeDecoder), | ||
error: optional(lazy(() => elementNodeDecoder)), | ||
loading: optional(lazy(() => elementNodeDecoder)), | ||
empty: optional(lazy(() => elementNodeDecoder)), | ||
}), | ||
statePersistanceName: optional(string()), | ||
itemValuePath: optional(array(string())), | ||
valuePath: optional(array(string())), | ||
loopItemsReference: optional(dynamicValueDecoder), | ||
resource: optional( | ||
object({ | ||
id: string(), | ||
params: optional( | ||
dict(union(staticValueDecoder, dyamicFunctionParam, expressionValueDecoder)) | ||
), | ||
}) | ||
), | ||
}), | ||
}) | ||
export const uidlNodeDecoder: Decoder<VUIDLNode> = union( | ||
elementNodeDecoder, | ||
cmsItemNodeDecoder, | ||
cmsListNodeDecoder, | ||
dynamicValueDecoder, | ||
staticValueDecoder, | ||
rawValueDecoder, | ||
conditionalNodeDecoder, | ||
union(repeatNodeDecoder, slotNodeDecoder, string()) | ||
union(dynamicValueDecoder, staticValueDecoder), | ||
union(rawValueDecoder, elementNodeDecoder), | ||
union(repeatNodeDecoder, conditionalNodeDecoder), | ||
union(slotNodeDecoder, injectValueDecoder), | ||
string() | ||
) |
@@ -1,2 +0,3 @@ | ||
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { | ||
@@ -19,9 +20,2 @@ UIDLDynamicReference, | ||
UIDLRootComponent, | ||
VUIDLLinkNode, | ||
UIDLCMSItemNode, | ||
UIDLPropDefinition, | ||
UIDLStateDefinition, | ||
UIDLCMSListNode, | ||
UIDLElementNodeInlineReferencedStyle, | ||
UIDLURLLinkNode, | ||
} from '@teleporthq/teleport-types' | ||
@@ -39,26 +33,6 @@ | ||
if (safeInput?.propDefinitions) { | ||
safeInput.propDefinitions = Object.keys(safeInput.propDefinitions).reduce( | ||
(acc: Record<string, UIDLPropDefinition>, prop) => { | ||
const propName = StringUtils.createStateOrPropStoringValue(prop) | ||
acc[propName] = (safeInput.propDefinitions as Record<string, UIDLPropDefinition>)[prop] | ||
return acc | ||
}, | ||
{} | ||
) | ||
} | ||
if (safeInput?.styleSetDefinitions) { | ||
const { styleSetDefinitions } = safeInput | ||
if (safeInput?.stateDefinitions) { | ||
safeInput.stateDefinitions = Object.keys(safeInput.stateDefinitions).reduce( | ||
(acc: Record<string, UIDLStateDefinition>, state) => { | ||
const stateName = StringUtils.createStateOrPropStoringValue(state) | ||
acc[stateName] = (safeInput.stateDefinitions as Record<string, UIDLStateDefinition>)[state] | ||
return acc | ||
}, | ||
{} | ||
) | ||
} | ||
if (safeInput?.styleSetDefinitions) { | ||
Object.values(safeInput?.styleSetDefinitions).forEach((styleRef) => { | ||
Object.values(styleSetDefinitions).forEach((styleRef) => { | ||
const { conditions = [] } = styleRef | ||
@@ -90,3 +64,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content) | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node, result) as UIDLElementNode | ||
result.node = parseComponentNode(node) as UIDLElementNode | ||
@@ -148,91 +122,16 @@ return result | ||
const parseComponentNode = (node: Record<string, unknown>, component: ComponentUIDL): UIDLNode => { | ||
const parseComponentNode = (node: Record<string, unknown>): UIDLNode => { | ||
switch ((node as unknown as UIDLNode).type) { | ||
case 'cms-item': | ||
case 'cms-list': | ||
case 'element': | ||
const elementContent = node.content as Record<string, unknown> | ||
if (node.type === 'cms-item') { | ||
const { | ||
nodes: { success, error, loading }, | ||
statePersistanceName, | ||
} = (node as unknown as UIDLCMSItemNode).content | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
success?.content?.attrs || {} | ||
) | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
error?.content?.attrs || {} | ||
) | ||
component.stateDefinitions[`${statePersistanceName}Error`] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
} | ||
} | ||
if (loading) { | ||
component.stateDefinitions[`${statePersistanceName}Loading`] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
} | ||
} | ||
} | ||
if (node.type === 'cms-list' && elementContent.hasOwnProperty('loopItemsReference')) { | ||
const { | ||
loopItemsReference, | ||
statePersistanceName, | ||
nodes: { success, error, loading }, | ||
} = (node as unknown as UIDLCMSListNode).content | ||
const identifier = | ||
loopItemsReference?.type === 'dynamic' && | ||
loopItemsReference.content.referenceType === 'prop' | ||
? 'propDefinitions' | ||
: 'stateDefinitions' | ||
if (success) { | ||
success.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
success?.content?.attrs || {} | ||
) | ||
} | ||
if (error) { | ||
error.content.attrs = UIDLUtils.transformAttributesAssignmentsToJson( | ||
error?.content?.attrs || {} | ||
) | ||
component[identifier][`${statePersistanceName}Error`] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
} | ||
} | ||
if (loading) { | ||
component[identifier][`${statePersistanceName}Loading`] = { | ||
type: 'boolean', | ||
defaultValue: false, | ||
} | ||
} | ||
if ( | ||
loopItemsReference && | ||
loopItemsReference?.type === 'dynamic' && | ||
['state', 'prop'].includes(loopItemsReference?.content.referenceType) | ||
) { | ||
loopItemsReference.content.id = StringUtils.createStateOrPropStoringValue( | ||
loopItemsReference.content.id | ||
) | ||
} | ||
} | ||
if (elementContent?.referencedStyles) { | ||
Object.values(elementContent.referencedStyles).forEach((styleRef) => { | ||
switch (styleRef.content.mapType) { | ||
const { content } = styleRef | ||
switch (content.mapType) { | ||
case 'inlined': { | ||
const { content } = styleRef as UIDLElementNodeInlineReferencedStyle | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles) | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson( | ||
content.styles as Record<string, string> | ||
) | ||
break | ||
@@ -251,3 +150,2 @@ } | ||
} | ||
break | ||
@@ -258,3 +156,3 @@ } | ||
throw new ParserError( | ||
`Un-expected mapType passed in referencedStyles - ${styleRef.content.mapType}` | ||
`Un-expected mapType passed in referencedStyles - ${content.mapType}` | ||
) | ||
@@ -278,17 +176,9 @@ } | ||
if (elementContent?.abilities?.hasOwnProperty('link')) { | ||
const { content, type } = (elementContent.abilities as { link: VUIDLLinkNode }).link | ||
// @ts-ignore | ||
if (elementContent.abilities?.link) { | ||
// @ts-ignore | ||
const { content, type } = elementContent.abilities?.link | ||
if (type === 'url' && typeof content.url === 'string') { | ||
content.url = UIDLUtils.transformStringAssignmentToJson(content.url) | ||
} | ||
if (type === 'url' && (content as UIDLURLLinkNode['content']).url.type === 'dynamic') { | ||
;(content as UIDLURLLinkNode['content']).url.content = { | ||
referenceType: ((content as UIDLURLLinkNode['content']).url as UIDLDynamicReference) | ||
.content.referenceType, | ||
id: StringUtils.createStateOrPropStoringValue( | ||
((content as UIDLURLLinkNode['content']).url as UIDLDynamicReference).content.id | ||
), | ||
} | ||
} | ||
} | ||
@@ -301,3 +191,3 @@ | ||
} else { | ||
return parseComponentNode(child, component) | ||
return parseComponentNode(child) | ||
} | ||
@@ -314,4 +204,3 @@ }, []) | ||
conditionalNode.content.node = parseComponentNode( | ||
conditionalNode.content.node as unknown as Record<string, unknown>, | ||
component | ||
conditionalNode.content.node as unknown as Record<string, unknown> | ||
) | ||
@@ -332,4 +221,3 @@ | ||
repeatNode.content.node = parseComponentNode( | ||
repeatNode.content.node as unknown as Record<string, unknown>, | ||
component | ||
repeatNode.content.node as unknown as Record<string, unknown> | ||
) as UIDLElementNode | ||
@@ -348,4 +236,3 @@ | ||
slotNode.content.fallback = parseComponentNode( | ||
slotNode.content.fallback as unknown as Record<string, unknown>, | ||
component | ||
slotNode.content.fallback as unknown as Record<string, unknown> | ||
) as UIDLElementNode | UIDLStaticValue | UIDLDynamicReference | ||
@@ -357,9 +244,5 @@ } | ||
case 'dynamic': | ||
const dyamicNode = node as unknown as UIDLDynamicReference | ||
if (['state', 'prop'].includes(dyamicNode.content.referenceType)) { | ||
dyamicNode.content.id = StringUtils.createStateOrPropStoringValue(dyamicNode.content.id) | ||
} | ||
return dyamicNode | ||
case 'static': | ||
case 'raw': | ||
case 'inject': | ||
return node as unknown as UIDLNode | ||
@@ -366,0 +249,0 @@ |
@@ -181,7 +181,3 @@ import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
const errorMsg = `"${ | ||
node.content.id | ||
}" is used but not defined. Please add it in propDefinitions \n Used on Node ${JSON.stringify( | ||
node.content | ||
)}` | ||
const errorMsg = `"${node.content.id}" is used but not defined. Please add it in propDefinitions ${input.name}` | ||
errors.push(errorMsg) | ||
@@ -198,5 +194,4 @@ } | ||
if (!dynamicPathExistsInDefinitions(node.content.id, stateKeys)) { | ||
console.warn( | ||
`\n"${node.content.id}" is used but not defined. Please add it in stateDefinitions` | ||
) | ||
const errorMsg = `\n"${node.content.id}" is used but not defined. Please add it in stateDefinitions` | ||
errors.push(errorMsg) | ||
} | ||
@@ -203,0 +198,0 @@ |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
437855
7245