@teleporthq/teleport-uidl-validator
Advanced tools
Comparing version 0.27.3-alpha.0 to 0.27.3-alpha.2
@@ -383,4 +383,2 @@ "use strict"; | ||
itemValuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), | ||
loadingStatePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
errorStatePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
resourceMappers: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.object)({ | ||
@@ -403,4 +401,2 @@ name: (0, json_type_validation_1.string)(), | ||
statePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
loadingStatePersistanceName: (0, json_type_validation_1.optional)((0, json_type_validation_1.string)()), | ||
errorStatePersistanceName: (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)())), | ||
@@ -407,0 +403,0 @@ valuePath: (0, json_type_validation_1.optional)((0, json_type_validation_1.array)((0, json_type_validation_1.string)())), |
@@ -20,5 +20,18 @@ "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) { | ||
var styleSetDefinitions = safeInput.styleSetDefinitions; | ||
Object.values(styleSetDefinitions).forEach(function (styleRef) { | ||
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) { | ||
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a; | ||
@@ -41,3 +54,3 @@ styleRef.content = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(styleRef.content); | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node); | ||
result.node = parseComponentNode(node, result); | ||
return result; | ||
@@ -79,4 +92,4 @@ }; | ||
exports.parseProjectJSON = parseProjectJSON; | ||
var parseComponentNode = function (node) { | ||
var _a, _b; | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e; | ||
switch (node.type) { | ||
@@ -87,7 +100,54 @@ case 'cms-item': | ||
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) { | ||
var content = styleRef.content; | ||
switch (content.mapType) { | ||
switch (styleRef.content.mapType) { | ||
case 'inlined': { | ||
var content = styleRef.content; | ||
content.styles = teleport_shared_1.UIDLUtils.transformStylesAssignmentsToJson(content.styles); | ||
@@ -108,3 +168,3 @@ break; | ||
default: { | ||
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType)); | ||
throw new teleport_types_1.ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType)); | ||
} | ||
@@ -120,9 +180,15 @@ } | ||
} | ||
// @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 ((_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; | ||
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), | ||
}; | ||
} | ||
} | ||
@@ -135,3 +201,3 @@ if (Array.isArray(elementContent.children)) { | ||
else { | ||
return parseComponentNode(child); | ||
return parseComponentNode(child, component); | ||
} | ||
@@ -144,3 +210,3 @@ }, []); | ||
var reference = conditionalNode.content.reference; | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node); | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component); | ||
if (typeof reference === 'string') { | ||
@@ -153,3 +219,3 @@ conditionalNode.content.reference = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(reference); | ||
var dataSource = repeatNode.content.dataSource; | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node); | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component); | ||
if (typeof dataSource === 'string') { | ||
@@ -162,6 +228,11 @@ repeatNode.content.dataSource = teleport_shared_1.UIDLUtils.transformStringAssignmentToJson(dataSource); | ||
if (slotNode.content.fallback) { | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback); | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component); | ||
} | ||
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': | ||
@@ -168,0 +239,0 @@ case 'raw': |
@@ -101,3 +101,3 @@ "use strict"; | ||
if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) { | ||
var errorMsg = "\"".concat(event.modifies, "\" is used in events, but not defined. Please add it in stateDefinitions"); | ||
var errorMsg = "\"".concat(event.modifies, "\" is used in events, but not defined. Please add it in stateDefinitions of ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -107,3 +107,3 @@ return; | ||
if (event.type === 'propCall' && !propKeys.includes(event.calls)) { | ||
errors.push("\"".concat(event.calls, "\" is used in events, but missing from propDefinitons. Please add it in propDefinitions ")); | ||
errors.push("\"".concat(event.calls, "\" is used in events, but missing from propDefinitons. Please add it in propDefinitions ").concat(input.name, " ")); | ||
return; | ||
@@ -120,3 +120,3 @@ } | ||
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) { | ||
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions"); | ||
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -142,3 +142,3 @@ return; | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions"); | ||
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)); | ||
errors.push(errorMsg); | ||
@@ -336,3 +336,3 @@ } | ||
typeof styleContent.content !== 'number') { | ||
errors.push("Project Style sheet / styleSetDefinitions only support styles with static \n content and dynamic tokens, received ".concat(styleContent)); | ||
errors.push("Project Style sheet / styleSetDefinitions only support styles with static\n content and dynamic tokens, received ".concat(styleContent)); | ||
} | ||
@@ -339,0 +339,0 @@ }); |
@@ -379,4 +379,2 @@ import { object, string, dict, constant, number, optional, union, boolean, array, lazy, oneOf, intersection, unknownJson, withDefault, anyJson, } from '@mojotech/json-type-validation'; | ||
itemValuePath: optional(array(string())), | ||
loadingStatePersistanceName: optional(string()), | ||
errorStatePersistanceName: optional(string()), | ||
resourceMappers: optional(array(object({ | ||
@@ -399,4 +397,2 @@ name: string(), | ||
statePersistanceName: optional(string()), | ||
loadingStatePersistanceName: optional(string()), | ||
errorStatePersistanceName: optional(string()), | ||
itemValuePath: optional(array(string())), | ||
@@ -403,0 +399,0 @@ valuePath: optional(array(string())), |
@@ -12,3 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared'; | ||
import { ParserError, } from '@teleporthq/teleport-types'; | ||
@@ -18,5 +18,18 @@ 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) { | ||
var styleSetDefinitions = safeInput.styleSetDefinitions; | ||
Object.values(styleSetDefinitions).forEach(function (styleRef) { | ||
Object.values(safeInput === null || safeInput === void 0 ? void 0 : safeInput.styleSetDefinitions).forEach(function (styleRef) { | ||
var _a = styleRef.conditions, conditions = _a === void 0 ? [] : _a; | ||
@@ -39,3 +52,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content); | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node); | ||
result.node = parseComponentNode(node, result); | ||
return result; | ||
@@ -75,4 +88,4 @@ }; | ||
}; | ||
var parseComponentNode = function (node) { | ||
var _a, _b; | ||
var parseComponentNode = function (node, component) { | ||
var _a, _b, _c, _d, _e; | ||
switch (node.type) { | ||
@@ -83,7 +96,54 @@ case 'cms-item': | ||
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) { | ||
var content = styleRef.content; | ||
switch (content.mapType) { | ||
switch (styleRef.content.mapType) { | ||
case 'inlined': { | ||
var content = styleRef.content; | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles); | ||
@@ -104,3 +164,3 @@ break; | ||
default: { | ||
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(content.mapType)); | ||
throw new ParserError("Un-expected mapType passed in referencedStyles - ".concat(styleRef.content.mapType)); | ||
} | ||
@@ -116,9 +176,15 @@ } | ||
} | ||
// @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 ((_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; | ||
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), | ||
}; | ||
} | ||
} | ||
@@ -131,3 +197,3 @@ if (Array.isArray(elementContent.children)) { | ||
else { | ||
return parseComponentNode(child); | ||
return parseComponentNode(child, component); | ||
} | ||
@@ -140,3 +206,3 @@ }, []); | ||
var reference = conditionalNode.content.reference; | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node); | ||
conditionalNode.content.node = parseComponentNode(conditionalNode.content.node, component); | ||
if (typeof reference === 'string') { | ||
@@ -149,3 +215,3 @@ conditionalNode.content.reference = UIDLUtils.transformStringAssignmentToJson(reference); | ||
var dataSource = repeatNode.content.dataSource; | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node); | ||
repeatNode.content.node = parseComponentNode(repeatNode.content.node, component); | ||
if (typeof dataSource === 'string') { | ||
@@ -158,6 +224,11 @@ repeatNode.content.dataSource = UIDLUtils.transformStringAssignmentToJson(dataSource); | ||
if (slotNode.content.fallback) { | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback); | ||
slotNode.content.fallback = parseComponentNode(slotNode.content.fallback, component); | ||
} | ||
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': | ||
@@ -164,0 +235,0 @@ case 'raw': |
@@ -96,3 +96,3 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) { | ||
var errorMsg = "\"".concat(event.modifies, "\" is used in events, but not defined. Please add it in stateDefinitions"); | ||
var errorMsg = "\"".concat(event.modifies, "\" is used in events, but not defined. Please add it in stateDefinitions of ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -102,3 +102,3 @@ return; | ||
if (event.type === 'propCall' && !propKeys.includes(event.calls)) { | ||
errors.push("\"".concat(event.calls, "\" is used in events, but missing from propDefinitons. Please add it in propDefinitions ")); | ||
errors.push("\"".concat(event.calls, "\" is used in events, but missing from propDefinitons. Please add it in propDefinitions ").concat(input.name, " ")); | ||
return; | ||
@@ -115,3 +115,3 @@ } | ||
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) { | ||
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions"); | ||
var errorMsg = "\"".concat(referencedProp, "\" is used but not defined. Please add it in propDefinitions ").concat(input.name); | ||
errors.push(errorMsg); | ||
@@ -137,3 +137,3 @@ return; | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
var errorMsg = "\"".concat(node.content.id, "\" is used but not defined. Please add it in propDefinitions"); | ||
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)); | ||
errors.push(errorMsg); | ||
@@ -326,3 +326,3 @@ } | ||
typeof styleContent.content !== 'number') { | ||
errors.push("Project Style sheet / styleSetDefinitions only support styles with static \n content and dynamic tokens, received ".concat(styleContent)); | ||
errors.push("Project Style sheet / styleSetDefinitions only support styles with static\n content and dynamic tokens, received ".concat(styleContent)); | ||
} | ||
@@ -329,0 +329,0 @@ }); |
{ | ||
"name": "@teleporthq/teleport-uidl-validator", | ||
"version": "0.27.3-alpha.0", | ||
"version": "0.27.3-alpha.2", | ||
"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.3-alpha.0", | ||
"@teleporthq/teleport-types": "^0.27.3-alpha.0" | ||
"@teleporthq/teleport-shared": "^0.27.3-alpha.2", | ||
"@teleporthq/teleport-types": "^0.27.3-alpha.2" | ||
}, | ||
"gitHead": "5e89aee4d95121ae24e6909b9b09ccee9918bd2c" | ||
"gitHead": "1826e455b9c5c73c972391f96f740d7cd548134b" | ||
} |
@@ -688,4 +688,2 @@ import { | ||
itemValuePath: optional(array(string())), | ||
loadingStatePersistanceName: optional(string()), | ||
errorStatePersistanceName: optional(string()), | ||
resourceMappers: optional( | ||
@@ -713,4 +711,2 @@ array( | ||
statePersistanceName: optional(string()), | ||
loadingStatePersistanceName: optional(string()), | ||
errorStatePersistanceName: optional(string()), | ||
itemValuePath: optional(array(string())), | ||
@@ -717,0 +713,0 @@ valuePath: optional(array(string())), |
@@ -1,3 +0,2 @@ | ||
import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { StringUtils, UIDLUtils } from '@teleporthq/teleport-shared' | ||
import { | ||
@@ -20,2 +19,9 @@ UIDLDynamicReference, | ||
UIDLRootComponent, | ||
VUIDLLinkNode, | ||
UIDLCMSItemNode, | ||
UIDLPropDefinition, | ||
UIDLStateDefinition, | ||
UIDLCMSListNode, | ||
UIDLElementNodeInlineReferencedStyle, | ||
UIDLURLLinkNode, | ||
} from '@teleporthq/teleport-types' | ||
@@ -33,6 +39,26 @@ | ||
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?.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) { | ||
const { styleSetDefinitions } = safeInput | ||
Object.values(styleSetDefinitions).forEach((styleRef) => { | ||
Object.values(safeInput?.styleSetDefinitions).forEach((styleRef) => { | ||
const { conditions = [] } = styleRef | ||
@@ -64,3 +90,3 @@ styleRef.content = UIDLUtils.transformStylesAssignmentsToJson(styleRef.content) | ||
// other parsers for other sections of the component here | ||
result.node = parseComponentNode(node) as UIDLElementNode | ||
result.node = parseComponentNode(node, result) as UIDLElementNode | ||
@@ -122,3 +148,3 @@ return result | ||
const parseComponentNode = (node: Record<string, unknown>): UIDLNode => { | ||
const parseComponentNode = (node: Record<string, unknown>, component: ComponentUIDL): UIDLNode => { | ||
switch ((node as unknown as UIDLNode).type) { | ||
@@ -130,11 +156,84 @@ case 'cms-item': | ||
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) => { | ||
const { content } = styleRef | ||
switch (content.mapType) { | ||
switch (styleRef.content.mapType) { | ||
case 'inlined': { | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson( | ||
content.styles as Record<string, string> | ||
) | ||
const { content } = styleRef as UIDLElementNodeInlineReferencedStyle | ||
content.styles = UIDLUtils.transformStylesAssignmentsToJson(content.styles) | ||
break | ||
@@ -153,2 +252,3 @@ } | ||
} | ||
break | ||
@@ -159,3 +259,3 @@ } | ||
throw new ParserError( | ||
`Un-expected mapType passed in referencedStyles - ${content.mapType}` | ||
`Un-expected mapType passed in referencedStyles - ${styleRef.content.mapType}` | ||
) | ||
@@ -179,9 +279,17 @@ } | ||
// @ts-ignore | ||
if (elementContent.abilities?.link) { | ||
// @ts-ignore | ||
const { content, type } = elementContent.abilities?.link | ||
if (elementContent?.abilities?.hasOwnProperty('link')) { | ||
const { content, type } = (elementContent.abilities as { link: VUIDLLinkNode }).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 | ||
), | ||
} | ||
} | ||
} | ||
@@ -194,3 +302,3 @@ | ||
} else { | ||
return parseComponentNode(child) | ||
return parseComponentNode(child, component) | ||
} | ||
@@ -207,3 +315,4 @@ }, []) | ||
conditionalNode.content.node = parseComponentNode( | ||
conditionalNode.content.node as unknown as Record<string, unknown> | ||
conditionalNode.content.node as unknown as Record<string, unknown>, | ||
component | ||
) | ||
@@ -224,3 +333,4 @@ | ||
repeatNode.content.node = parseComponentNode( | ||
repeatNode.content.node as unknown as Record<string, unknown> | ||
repeatNode.content.node as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | ||
@@ -239,3 +349,4 @@ | ||
slotNode.content.fallback = parseComponentNode( | ||
slotNode.content.fallback as unknown as Record<string, unknown> | ||
slotNode.content.fallback as unknown as Record<string, unknown>, | ||
component | ||
) as UIDLElementNode | UIDLStaticValue | UIDLDynamicReference | ||
@@ -247,2 +358,7 @@ } | ||
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': | ||
@@ -249,0 +365,0 @@ case 'raw': |
@@ -128,3 +128,3 @@ import { UIDLUtils } from '@teleporthq/teleport-shared' | ||
if (event.type === 'stateChange' && !stateKeys.includes(event.modifies)) { | ||
const errorMsg = `"${event.modifies}" is used in events, but not defined. Please add it in stateDefinitions` | ||
const errorMsg = `"${event.modifies}" is used in events, but not defined. Please add it in stateDefinitions of ${input.name}` | ||
errors.push(errorMsg) | ||
@@ -136,3 +136,3 @@ return | ||
errors.push( | ||
`"${event.calls}" is used in events, but missing from propDefinitons. Please add it in propDefinitions ` | ||
`"${event.calls}" is used in events, but missing from propDefinitons. Please add it in propDefinitions ${input.name} ` | ||
) | ||
@@ -153,3 +153,3 @@ return | ||
if (!dynamicPathExistsInDefinitions(referencedProp, propKeys)) { | ||
const errorMsg = `"${referencedProp}" is used but not defined. Please add it in propDefinitions` | ||
const errorMsg = `"${referencedProp}" is used but not defined. Please add it in propDefinitions ${input.name}` | ||
errors.push(errorMsg) | ||
@@ -184,3 +184,7 @@ return | ||
if (!dynamicPathExistsInDefinitions(node.content.id, propKeys)) { | ||
const errorMsg = `"${node.content.id}" is used but not defined. Please add it in propDefinitions` | ||
const errorMsg = `"${ | ||
node.content.id | ||
}" is used but not defined. Please add it in propDefinitions \n Used on Node ${JSON.stringify( | ||
node.content | ||
)}` | ||
errors.push(errorMsg) | ||
@@ -432,3 +436,3 @@ } | ||
errors.push( | ||
`Project Style sheet / styleSetDefinitions only support styles with static | ||
`Project Style sheet / styleSetDefinitions only support styles with static | ||
content and dynamic tokens, received ${styleContent}` | ||
@@ -435,0 +439,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
487518
7948