@teleporthq/teleport-uidl-resolver
Advanced tools
Comparing version
@@ -86,8 +86,3 @@ "use strict"; | ||
var getLinkElementType = function (link) { | ||
// for now I'm making all dynamic links local. | ||
// Maybe navlinks could have a dynamic reference, | ||
// not just a staic on in the future, but for now | ||
// (for the CMS demo) the navlink was too robust | ||
// to change | ||
return link.type === 'navlink' || link.type === 'dynamic' ? 'navlink' : 'link'; | ||
return link.type === 'navlink' ? 'navlink' : 'link'; | ||
}; | ||
@@ -119,6 +114,2 @@ var createLinkAttributes = function (link, options) { | ||
} | ||
case 'dynamic': | ||
return { | ||
transitionTo: link, | ||
}; | ||
case 'navlink': { | ||
@@ -125,0 +116,0 @@ return { |
@@ -1,2 +0,2 @@ | ||
import { UIDLElement, UIDLNode, Mapping, GeneratorOptions, ComponentUIDL, UIDLStyleSetTokenReference, UIDLStaticValue, UIDLDynamicReference, UIDLConditionalNode } from '@teleporthq/teleport-types'; | ||
import { UIDLElement, UIDLNode, Mapping, GeneratorOptions, ComponentUIDL, UIDLStyleSetTokenReference, UIDLStaticValue, UIDLDynamicReference } from '@teleporthq/teleport-types'; | ||
declare type ElementsLookup = Record<string, { | ||
@@ -10,3 +10,2 @@ count: number; | ||
export declare const resolveNode: (uidlNode: UIDLNode, options: GeneratorOptions) => void; | ||
export declare const resolveConditional: (condNode: UIDLConditionalNode, options: GeneratorOptions) => void; | ||
export declare const resolveElement: (element: UIDLElement, options: GeneratorOptions) => void; | ||
@@ -13,0 +12,0 @@ export declare const resolveChildren: (mappedChildren: UIDLNode[], originalChildren?: UIDLNode[]) => UIDLNode[]; |
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.checkForDefaultStateValueContainingAssets = exports.checkForDefaultPropsContainingAssets = exports.checkForIllegalNames = exports.prefixAssetURLs = exports.ensureDataSourceUniqueness = exports.createNodesLookup = exports.generateUniqueKeys = exports.resolveChildren = exports.resolveElement = exports.resolveConditional = exports.resolveNode = exports.removeIgnoredNodes = exports.resolveMetaTags = exports.mergeMappings = void 0; | ||
exports.checkForDefaultStateValueContainingAssets = exports.checkForDefaultPropsContainingAssets = exports.checkForIllegalNames = exports.prefixAssetURLs = exports.ensureDataSourceUniqueness = exports.createNodesLookup = exports.generateUniqueKeys = exports.resolveChildren = exports.resolveElement = exports.resolveNode = exports.removeIgnoredNodes = exports.resolveMetaTags = exports.mergeMappings = void 0; | ||
var teleport_shared_1 = require("@teleporthq/teleport-shared"); | ||
@@ -77,18 +77,5 @@ var deepmerge_1 = __importDefault(require("deepmerge")); | ||
} | ||
if (node.type === 'conditional') { | ||
(0, exports.resolveConditional)(node, options); | ||
} | ||
}); | ||
}; | ||
exports.resolveNode = resolveNode; | ||
var resolveConditional = function (condNode, options) { | ||
var _a; | ||
if ((_a = condNode.content) === null || _a === void 0 ? void 0 : _a.node) { | ||
var _b = condNode.content.node, type = _b.type, content = _b.content; | ||
if (type === 'element') { | ||
(0, exports.resolveElement)(content, options); | ||
} | ||
} | ||
}; | ||
exports.resolveConditional = resolveConditional; | ||
var resolveElement = function (element, options) { | ||
@@ -287,6 +274,2 @@ var _a; | ||
teleport_shared_1.UIDLUtils.traverseRepeats(node, function (repeat) { | ||
var _a; | ||
if (!((_a = repeat.dataSource) === null || _a === void 0 ? void 0 : _a.type)) { | ||
return; | ||
} | ||
if (repeat.dataSource.type === 'static' && !customDataSourceIdentifierExists(repeat)) { | ||
@@ -420,12 +403,16 @@ repeat.meta = repeat.meta || {}; | ||
} | ||
Object.keys(uidl.propDefinitions || {}).forEach(function (prop) { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error("Illegal prop key '".concat(prop, "'")); | ||
} | ||
}); | ||
Object.keys(uidl.stateDefinitions || {}).forEach(function (state) { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error("Illegal state key '".concat(state, "'")); | ||
} | ||
}); | ||
if (uidl.propDefinitions) { | ||
Object.keys(uidl.propDefinitions).forEach(function (prop) { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error("Illegal prop key '".concat(prop, "'")); | ||
} | ||
}); | ||
} | ||
if (uidl.stateDefinitions) { | ||
Object.keys(uidl.stateDefinitions).forEach(function (state) { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error("Illegal state key '".concat(state, "'")); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -432,0 +419,0 @@ exports.checkForIllegalNames = checkForIllegalNames; |
@@ -81,8 +81,3 @@ var __assign = (this && this.__assign) || function () { | ||
var getLinkElementType = function (link) { | ||
// for now I'm making all dynamic links local. | ||
// Maybe navlinks could have a dynamic reference, | ||
// not just a staic on in the future, but for now | ||
// (for the CMS demo) the navlink was too robust | ||
// to change | ||
return link.type === 'navlink' || link.type === 'dynamic' ? 'navlink' : 'link'; | ||
return link.type === 'navlink' ? 'navlink' : 'link'; | ||
}; | ||
@@ -114,6 +109,2 @@ var createLinkAttributes = function (link, options) { | ||
} | ||
case 'dynamic': | ||
return { | ||
transitionTo: link, | ||
}; | ||
case 'navlink': { | ||
@@ -120,0 +111,0 @@ return { |
@@ -1,2 +0,2 @@ | ||
import { UIDLElement, UIDLNode, Mapping, GeneratorOptions, ComponentUIDL, UIDLStyleSetTokenReference, UIDLStaticValue, UIDLDynamicReference, UIDLConditionalNode } from '@teleporthq/teleport-types'; | ||
import { UIDLElement, UIDLNode, Mapping, GeneratorOptions, ComponentUIDL, UIDLStyleSetTokenReference, UIDLStaticValue, UIDLDynamicReference } from '@teleporthq/teleport-types'; | ||
declare type ElementsLookup = Record<string, { | ||
@@ -10,3 +10,2 @@ count: number; | ||
export declare const resolveNode: (uidlNode: UIDLNode, options: GeneratorOptions) => void; | ||
export declare const resolveConditional: (condNode: UIDLConditionalNode, options: GeneratorOptions) => void; | ||
export declare const resolveElement: (element: UIDLElement, options: GeneratorOptions) => void; | ||
@@ -13,0 +12,0 @@ export declare const resolveChildren: (mappedChildren: UIDLNode[], originalChildren?: UIDLNode[]) => UIDLNode[]; |
@@ -67,16 +67,4 @@ var __assign = (this && this.__assign) || function () { | ||
} | ||
if (node.type === 'conditional') { | ||
resolveConditional(node, options); | ||
} | ||
}); | ||
}; | ||
export var resolveConditional = function (condNode, options) { | ||
var _a; | ||
if ((_a = condNode.content) === null || _a === void 0 ? void 0 : _a.node) { | ||
var _b = condNode.content.node, type = _b.type, content = _b.content; | ||
if (type === 'element') { | ||
resolveElement(content, options); | ||
} | ||
} | ||
}; | ||
export var resolveElement = function (element, options) { | ||
@@ -271,6 +259,2 @@ var _a; | ||
UIDLUtils.traverseRepeats(node, function (repeat) { | ||
var _a; | ||
if (!((_a = repeat.dataSource) === null || _a === void 0 ? void 0 : _a.type)) { | ||
return; | ||
} | ||
if (repeat.dataSource.type === 'static' && !customDataSourceIdentifierExists(repeat)) { | ||
@@ -402,12 +386,16 @@ repeat.meta = repeat.meta || {}; | ||
} | ||
Object.keys(uidl.propDefinitions || {}).forEach(function (prop) { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error("Illegal prop key '".concat(prop, "'")); | ||
} | ||
}); | ||
Object.keys(uidl.stateDefinitions || {}).forEach(function (state) { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error("Illegal state key '".concat(state, "'")); | ||
} | ||
}); | ||
if (uidl.propDefinitions) { | ||
Object.keys(uidl.propDefinitions).forEach(function (prop) { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error("Illegal prop key '".concat(prop, "'")); | ||
} | ||
}); | ||
} | ||
if (uidl.stateDefinitions) { | ||
Object.keys(uidl.stateDefinitions).forEach(function (state) { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error("Illegal state key '".concat(state, "'")); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -414,0 +402,0 @@ export var checkForDefaultPropsContainingAssets = function (uidl, assets) { |
{ | ||
"name": "@teleporthq/teleport-uidl-resolver", | ||
"version": "0.27.3-alpha.3", | ||
"version": "0.27.3", | ||
"description": "A small package that handles the transition from UIDL to HTML elements and has support for custom mappings.", | ||
@@ -27,8 +27,8 @@ "author": "teleportHQ", | ||
"dependencies": { | ||
"@teleporthq/teleport-shared": "^0.27.3-alpha.3", | ||
"@teleporthq/teleport-types": "^0.27.3-alpha.3", | ||
"@teleporthq/teleport-uidl-builders": "^0.27.3-alpha.3", | ||
"@teleporthq/teleport-shared": "^0.27.3", | ||
"@teleporthq/teleport-types": "^0.27.3", | ||
"@teleporthq/teleport-uidl-builders": "^0.27.3", | ||
"deepmerge": "^4.0.0" | ||
}, | ||
"gitHead": "776fa2beea05204929e2ef93ab70aa619fe7b0e3" | ||
"gitHead": "14f69b861cb0838d502a5ba226bb7cb5c1291fbb" | ||
} |
@@ -104,8 +104,3 @@ import { StringUtils } from '@teleporthq/teleport-shared' | ||
const getLinkElementType = (link: UIDLLinkNode): string => { | ||
// for now I'm making all dynamic links local. | ||
// Maybe navlinks could have a dynamic reference, | ||
// not just a staic on in the future, but for now | ||
// (for the CMS demo) the navlink was too robust | ||
// to change | ||
return link.type === 'navlink' || link.type === 'dynamic' ? 'navlink' : 'link' | ||
return link.type === 'navlink' ? 'navlink' : 'link' | ||
} | ||
@@ -145,7 +140,2 @@ | ||
case 'dynamic': | ||
return { | ||
transitionTo: link, | ||
} | ||
case 'navlink': { | ||
@@ -152,0 +142,0 @@ return { |
@@ -16,3 +16,2 @@ import { UIDLUtils, StringUtils } from '@teleporthq/teleport-shared' | ||
UIDLDynamicReference, | ||
UIDLConditionalNode, | ||
} from '@teleporthq/teleport-types' | ||
@@ -60,3 +59,3 @@ import deepmerge from 'deepmerge' | ||
Object.keys(tag).forEach((key) => { | ||
tag[key] = UIDLUtils.prefixAssetsPath(tag[key] as string, options.assets) | ||
tag[key] = UIDLUtils.prefixAssetsPath(tag[key], options.assets) | ||
}) | ||
@@ -86,18 +85,5 @@ }) | ||
} | ||
if (node.type === 'conditional') { | ||
resolveConditional(node, options) | ||
} | ||
}) | ||
} | ||
export const resolveConditional = (condNode: UIDLConditionalNode, options: GeneratorOptions) => { | ||
if (condNode.content?.node) { | ||
const { type, content } = condNode.content.node | ||
if (type === 'element') { | ||
resolveElement(content, options) | ||
} | ||
} | ||
} | ||
export const resolveElement = (element: UIDLElement, options: GeneratorOptions) => { | ||
@@ -344,7 +330,3 @@ const { mapping, localDependenciesPrefix } = options | ||
UIDLUtils.traverseRepeats(node, (repeat: UIDLRepeatContent) => { | ||
if (!repeat.dataSource?.type) { | ||
return | ||
} | ||
UIDLUtils.traverseRepeats(node, (repeat) => { | ||
if (repeat.dataSource.type === 'static' && !customDataSourceIdentifierExists(repeat)) { | ||
@@ -397,3 +379,3 @@ repeat.meta = repeat.meta || {} | ||
background image such as gradient shouldn't be urls | ||
we prevent that by checking if the value is actually an asset or not (same check as in the prefixAssetsPath function | ||
we prevent that by checking if the value is actually an asset or not (same check as in the prefixAssetsPath function | ||
but we don't compute and generate a url) | ||
@@ -428,2 +410,3 @@ */ | ||
const resolvedAttrs: Record<string, UIDLAttributeValue> = {} | ||
// This will gather all the attributes from the UIDL which are mapped using the elements-mapping | ||
@@ -513,13 +496,17 @@ // These attributes will not be added on the tag as they are, but using the elements-mapping | ||
Object.keys(uidl.propDefinitions || {}).forEach((prop) => { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error(`Illegal prop key '${prop}'`) | ||
} | ||
}) | ||
if (uidl.propDefinitions) { | ||
Object.keys(uidl.propDefinitions).forEach((prop) => { | ||
if (illegalPropNames.includes(prop)) { | ||
throw new Error(`Illegal prop key '${prop}'`) | ||
} | ||
}) | ||
} | ||
Object.keys(uidl.stateDefinitions || {}).forEach((state) => { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error(`Illegal state key '${state}'`) | ||
} | ||
}) | ||
if (uidl.stateDefinitions) { | ||
Object.keys(uidl.stateDefinitions).forEach((state) => { | ||
if (illegalPropNames.includes(state)) { | ||
throw new Error(`Illegal state key '${state}'`) | ||
} | ||
}) | ||
} | ||
} | ||
@@ -526,0 +513,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
293014
-1.43%4309
-1.49%