@teleporthq/teleport-plugin-html-base-component 0.40.0-alpha.0 → 0.40.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/index.ts +26 -20
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +40 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers.d.ts +12 -4
- package/dist/cjs/node-handlers.d.ts.map +1 -1
- package/dist/cjs/node-handlers.js +519 -143
- package/dist/cjs/node-handlers.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +41 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers.d.ts +12 -4
- package/dist/esm/node-handlers.d.ts.map +1 -1
- package/dist/esm/node-handlers.js +519 -143
- package/dist/esm/node-handlers.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/index.ts +55 -21
- package/src/node-handlers.ts +747 -170
|
@@ -56,64 +56,275 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
56
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
57
|
};
|
|
58
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
-
exports.
|
|
59
|
+
exports.generateHtmlSyntax = void 0;
|
|
60
60
|
var teleport_types_1 = require("@teleporthq/teleport-types");
|
|
61
|
+
var path_1 = require("path");
|
|
61
62
|
var teleport_plugin_common_1 = require("@teleporthq/teleport-plugin-common");
|
|
62
63
|
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
63
64
|
var teleport_uidl_builders_1 = require("@teleporthq/teleport-uidl-builders");
|
|
64
65
|
var teleport_plugin_css_1 = require("@teleporthq/teleport-plugin-css");
|
|
66
|
+
var teleport_uidl_resolver_1 = require("@teleporthq/teleport-uidl-resolver");
|
|
65
67
|
var constants_1 = require("./constants");
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
var isValidURL = function (url) {
|
|
69
|
+
try {
|
|
70
|
+
/* tslint:disable:no-unused-expression */
|
|
71
|
+
new URL(url);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var addNodeToLookup = function (key, tag, nodesLoookup) {
|
|
79
|
+
// In html code-generation we combine the nodes of the component that is being consumed with the current component.
|
|
80
|
+
// As html can't load the component at runtime like react or any other frameworks. So, we merge the component as a standalone
|
|
81
|
+
// component in the current component.
|
|
82
|
+
var currentLookup = nodesLoookup[key];
|
|
83
|
+
if (currentLookup) {
|
|
84
|
+
if (Array.isArray(currentLookup)) {
|
|
85
|
+
Array.isArray(tag) ? currentLookup.push.apply(currentLookup, tag) : currentLookup.push(tag);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
nodesLoookup[key] = Array.isArray(tag) ? __spreadArray([currentLookup], tag, true) : [currentLookup, tag];
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
nodesLoookup[key] = tag;
|
|
93
|
+
};
|
|
94
|
+
var generateHtmlSyntax = function (node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
|
+
var _a, elementNode, dynamicNode, conditionalNodeComment, _b, staticValue, reference, _c, conditions, matchingCriteria, _d, referenceType, id, _e, refPath, usedProp, defaultValue, _i, refPath_1, path, dynamicConditions, matchCondition, conditionString, isConditionPassing, content, uidlDynamicRef, generatedNode;
|
|
96
|
+
var _f;
|
|
97
|
+
return __generator(this, function (_g) {
|
|
98
|
+
switch (_g.label) {
|
|
99
|
+
case 0:
|
|
100
|
+
_a = node.type;
|
|
101
|
+
switch (_a) {
|
|
102
|
+
case 'inject': return [3 /*break*/, 1];
|
|
103
|
+
case 'raw': return [3 /*break*/, 1];
|
|
104
|
+
case 'static': return [3 /*break*/, 2];
|
|
105
|
+
case 'slot': return [3 /*break*/, 3];
|
|
106
|
+
case 'element': return [3 /*break*/, 4];
|
|
107
|
+
case 'dynamic': return [3 /*break*/, 6];
|
|
108
|
+
case 'conditional': return [3 /*break*/, 8];
|
|
109
|
+
case 'expr': return [3 /*break*/, 9];
|
|
110
|
+
case 'cms-list-repeater': return [3 /*break*/, 12];
|
|
111
|
+
}
|
|
112
|
+
return [3 /*break*/, 13];
|
|
113
|
+
case 1: return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createTextNode(node.content.toString())];
|
|
114
|
+
case 2: return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createTextNode(teleport_shared_1.StringUtils.encode(node.content.toString()))];
|
|
115
|
+
case 3: return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createHTMLNode(node.type)];
|
|
116
|
+
case 4: return [4 /*yield*/, generateElementNode(node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions)];
|
|
117
|
+
case 5:
|
|
118
|
+
elementNode = _g.sent();
|
|
119
|
+
return [2 /*return*/, elementNode];
|
|
120
|
+
case 6: return [4 /*yield*/, generateDynamicNode(node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure)];
|
|
121
|
+
case 7:
|
|
122
|
+
dynamicNode = _g.sent();
|
|
123
|
+
return [2 /*return*/, dynamicNode];
|
|
124
|
+
case 8:
|
|
125
|
+
conditionalNodeComment = teleport_plugin_common_1.HASTBuilders.createTextNode('');
|
|
126
|
+
_b = node.content, staticValue = _b.value, reference = _b.reference, _c = _b.condition, conditions = _c.conditions, matchingCriteria = _c.matchingCriteria;
|
|
127
|
+
if (reference.type !== 'dynamic') {
|
|
128
|
+
return [2 /*return*/, conditionalNodeComment];
|
|
129
|
+
}
|
|
130
|
+
_d = reference.content, referenceType = _d.referenceType, id = _d.id, _e = _d.refPath, refPath = _e === void 0 ? [] : _e;
|
|
131
|
+
switch (referenceType) {
|
|
132
|
+
case 'prop': {
|
|
133
|
+
usedProp = propDefinitions[id];
|
|
134
|
+
if (usedProp === undefined || usedProp.defaultValue === undefined) {
|
|
135
|
+
return [2 /*return*/, conditionalNodeComment];
|
|
136
|
+
}
|
|
137
|
+
defaultValue = usedProp.defaultValue;
|
|
138
|
+
for (_i = 0, refPath_1 = refPath; _i < refPath_1.length; _i++) {
|
|
139
|
+
path = refPath_1[_i];
|
|
140
|
+
defaultValue = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue[path];
|
|
141
|
+
}
|
|
142
|
+
// If defaultValue is undefined or null after path traversal, use original default
|
|
143
|
+
defaultValue = defaultValue !== null && defaultValue !== void 0 ? defaultValue : usedProp.defaultValue;
|
|
144
|
+
dynamicConditions = createConditionalStatement(staticValue !== undefined ? [{ operand: staticValue, operation: '===' }] : conditions, defaultValue);
|
|
145
|
+
matchCondition = matchingCriteria && matchingCriteria === 'all' ? '&&' : '||';
|
|
146
|
+
conditionString = dynamicConditions.join(" ".concat(matchCondition, " "));
|
|
147
|
+
try {
|
|
148
|
+
isConditionPassing = new Function("return ".concat(conditionString))();
|
|
149
|
+
if (isConditionPassing) {
|
|
150
|
+
return [2 /*return*/, (0, exports.generateHtmlSyntax)(node.content.node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions)];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
return [2 /*return*/, conditionalNodeComment];
|
|
155
|
+
}
|
|
156
|
+
return [2 /*return*/, conditionalNodeComment];
|
|
157
|
+
}
|
|
158
|
+
case 'state':
|
|
159
|
+
default:
|
|
160
|
+
return [2 /*return*/, conditionalNodeComment];
|
|
161
|
+
}
|
|
162
|
+
_g.label = 9;
|
|
163
|
+
case 9:
|
|
164
|
+
content = node.content.split('?.');
|
|
165
|
+
if (!(resolvedExpressions && ((_f = resolvedExpressions.expressions) === null || _f === void 0 ? void 0 : _f[content[0] || '']))) return [3 /*break*/, 11];
|
|
166
|
+
uidlDynamicRef = {
|
|
167
|
+
type: 'dynamic',
|
|
168
|
+
content: {
|
|
169
|
+
referenceType: 'prop',
|
|
170
|
+
refPath: __spreadArray([resolvedExpressions.currentIndex.toString()], content.slice(1), true),
|
|
171
|
+
id: content[0],
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
return [4 /*yield*/, generateDynamicNode(uidlDynamicRef, compName, nodesLookup, resolvedExpressions.expressions, stateDefinitions, subComponentOptions, structure)];
|
|
175
|
+
case 10:
|
|
176
|
+
generatedNode = _g.sent();
|
|
177
|
+
return [2 /*return*/, generatedNode];
|
|
178
|
+
case 11: return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createComment('Expressions are not supported in HTML')];
|
|
179
|
+
case 12: return [2 /*return*/, generateRepeaterNode(node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure)];
|
|
180
|
+
case 13: throw new teleport_types_1.HTMLComponentGeneratorError("generateHtmlSyntax encountered a node of unsupported type: ".concat(JSON.stringify(node, null, 2), " "));
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}); };
|
|
184
|
+
exports.generateHtmlSyntax = generateHtmlSyntax;
|
|
185
|
+
var createConditionalStatement = function (conditions, leftOperand) {
|
|
186
|
+
return conditions.map(function (condition) {
|
|
187
|
+
var operation = condition.operation, operand = condition.operand;
|
|
188
|
+
if (operand === undefined) {
|
|
189
|
+
return "".concat(teleport_plugin_common_1.ASTUtils.convertToUnaryOperator(operation)).concat(getValueType(operand));
|
|
190
|
+
}
|
|
191
|
+
return "".concat(getValueType(leftOperand), " ").concat(teleport_plugin_common_1.ASTUtils.convertToBinaryOperator(operation), " ").concat(getValueType(operand));
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
var getValueType = function (value) {
|
|
195
|
+
var valueType = typeof value;
|
|
196
|
+
switch (valueType) {
|
|
197
|
+
case 'string':
|
|
198
|
+
return "\"".concat(value, "\"");
|
|
199
|
+
case 'number':
|
|
200
|
+
return value;
|
|
201
|
+
case 'boolean':
|
|
202
|
+
return value;
|
|
203
|
+
default:
|
|
204
|
+
throw new teleport_types_1.HTMLComponentGeneratorError("Conditional node received an operand of type ".concat(valueType, " \n\n Received ").concat(JSON.stringify(value)));
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var generateRepeaterNode = function (node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure) { return __awaiter(void 0, void 0, void 0, function () {
|
|
208
|
+
var nodes, contextId, sourceValue, propDef, parsedSource, elementNode, emptyChildren, _i, emptyChildren_1, child, childTag, listChildren, index, _a, listChildren_1, child, childTag;
|
|
209
|
+
var _b;
|
|
210
|
+
return __generator(this, function (_c) {
|
|
211
|
+
switch (_c.label) {
|
|
212
|
+
case 0:
|
|
213
|
+
nodes = node.content.nodes;
|
|
214
|
+
contextId = node.content.renderPropIdentifier;
|
|
215
|
+
sourceValue = node.content.source;
|
|
216
|
+
propDef = propDefinitions[Object.keys(propDefinitions).find(function (propKey) { return sourceValue.includes(propKey); }) || ''];
|
|
217
|
+
if (!propDef || !Array.isArray(propDef.defaultValue)) {
|
|
218
|
+
// If no prop is found we might have a static source value
|
|
219
|
+
try {
|
|
220
|
+
parsedSource = JSON.parse(sourceValue);
|
|
221
|
+
propDef = {
|
|
222
|
+
defaultValue: parsedSource,
|
|
223
|
+
id: contextId,
|
|
224
|
+
type: 'array',
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch (_d) {
|
|
228
|
+
// Silent fail
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// We do the check again to keep typescript happy, otherwise this could be in catch
|
|
232
|
+
if (!propDef || !Array.isArray(propDef.defaultValue)) {
|
|
233
|
+
return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createComment('CMS Array Mapper/Repeater not supported in HTML without a prop source')];
|
|
234
|
+
}
|
|
235
|
+
propDefinitions[contextId] = propDef;
|
|
236
|
+
elementNode = teleport_plugin_common_1.HASTBuilders.createHTMLNode('div');
|
|
237
|
+
node.content.nodes.list.content.style = { display: { type: 'static', content: 'contents' } };
|
|
238
|
+
if (node.content.nodes.empty) {
|
|
239
|
+
node.content.nodes.empty.content.style = { display: { type: 'static', content: 'contents' } };
|
|
240
|
+
}
|
|
241
|
+
if (!(propDef.defaultValue.length === 0)) return [3 /*break*/, 5];
|
|
242
|
+
emptyChildren = nodes.empty.content.children;
|
|
243
|
+
if (!emptyChildren) return [3 /*break*/, 4];
|
|
244
|
+
_i = 0, emptyChildren_1 = emptyChildren;
|
|
245
|
+
_c.label = 1;
|
|
246
|
+
case 1:
|
|
247
|
+
if (!(_i < emptyChildren_1.length)) return [3 /*break*/, 4];
|
|
248
|
+
child = emptyChildren_1[_i];
|
|
249
|
+
return [4 /*yield*/, (0, exports.generateHtmlSyntax)(child, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure)];
|
|
250
|
+
case 2:
|
|
251
|
+
childTag = _c.sent();
|
|
252
|
+
if (typeof childTag === 'string') {
|
|
253
|
+
teleport_plugin_common_1.HASTUtils.addTextNode(elementNode, childTag);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
teleport_plugin_common_1.HASTUtils.addChildNode(elementNode, childTag);
|
|
257
|
+
}
|
|
258
|
+
_c.label = 3;
|
|
259
|
+
case 3:
|
|
260
|
+
_i++;
|
|
261
|
+
return [3 /*break*/, 1];
|
|
262
|
+
case 4:
|
|
263
|
+
addNodeToLookup("".concat(node.content.nodes.empty.content.key), elementNode, nodesLookup);
|
|
264
|
+
return [2 /*return*/, elementNode];
|
|
265
|
+
case 5:
|
|
266
|
+
listChildren = nodes.list.content.children;
|
|
267
|
+
if (!listChildren) return [3 /*break*/, 11];
|
|
268
|
+
index = 0;
|
|
269
|
+
_c.label = 6;
|
|
270
|
+
case 6:
|
|
271
|
+
if (!(index < propDef.defaultValue.length)) return [3 /*break*/, 11];
|
|
272
|
+
_a = 0, listChildren_1 = listChildren;
|
|
273
|
+
_c.label = 7;
|
|
274
|
+
case 7:
|
|
275
|
+
if (!(_a < listChildren_1.length)) return [3 /*break*/, 10];
|
|
276
|
+
child = listChildren_1[_a];
|
|
277
|
+
return [4 /*yield*/, (0, exports.generateHtmlSyntax)(child, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, { currentIndex: index, expressions: (_b = {}, _b[contextId] = propDef, _b) })];
|
|
278
|
+
case 8:
|
|
279
|
+
childTag = _c.sent();
|
|
280
|
+
if (typeof childTag === 'string') {
|
|
281
|
+
teleport_plugin_common_1.HASTUtils.addTextNode(elementNode, childTag);
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
teleport_plugin_common_1.HASTUtils.addChildNode(elementNode, childTag);
|
|
285
|
+
}
|
|
286
|
+
_c.label = 9;
|
|
287
|
+
case 9:
|
|
288
|
+
_a++;
|
|
289
|
+
return [3 /*break*/, 7];
|
|
290
|
+
case 10:
|
|
291
|
+
index++;
|
|
292
|
+
return [3 /*break*/, 6];
|
|
293
|
+
case 11:
|
|
294
|
+
addNodeToLookup("".concat(node.content.nodes.list.content.key), elementNode, nodesLookup);
|
|
295
|
+
return [2 /*return*/, elementNode];
|
|
82
296
|
}
|
|
83
|
-
return [2 /*return*/];
|
|
84
297
|
});
|
|
85
298
|
}); };
|
|
86
|
-
|
|
87
|
-
var
|
|
88
|
-
var _a, elementType, children, _b, attrs, _c, style, _d, referencedStyles, dependency, key, elementNode, dependencies, compTag, _i, children_1, child, childTag;
|
|
299
|
+
var generateElementNode = function (node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
300
|
+
var _a, elementType, children, _b, attrs, _c, style, _d, referencedStyles, dependency, dependencies, compTag, elementNode, _i, children_1, child, childTag;
|
|
89
301
|
return __generator(this, function (_e) {
|
|
90
302
|
switch (_e.label) {
|
|
91
303
|
case 0:
|
|
92
|
-
_a = node.content, elementType = _a.elementType, children = _a.children, _b = _a.attrs, attrs = _b === void 0 ? {} : _b, _c = _a.style, style = _c === void 0 ? {} : _c, _d = _a.referencedStyles, referencedStyles = _d === void 0 ? {} : _d, dependency = _a.dependency
|
|
93
|
-
elementNode = teleport_plugin_common_1.HASTBuilders.createHTMLNode(elementType);
|
|
94
|
-
templatesLookUp[key] = elementNode;
|
|
304
|
+
_a = node.content, elementType = _a.elementType, children = _a.children, _b = _a.attrs, attrs = _b === void 0 ? {} : _b, _c = _a.style, style = _c === void 0 ? {} : _c, _d = _a.referencedStyles, referencedStyles = _d === void 0 ? {} : _d, dependency = _a.dependency;
|
|
95
305
|
dependencies = structure.dependencies;
|
|
96
|
-
if (dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) !== 'local') {
|
|
97
|
-
dependencies[dependency.path] = dependency;
|
|
98
|
-
}
|
|
99
306
|
if (!(dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) === 'local')) return [3 /*break*/, 2];
|
|
100
|
-
return [4 /*yield*/, generateComponentContent(node, propDefinitions, stateDefinitions, subComponentOptions,
|
|
307
|
+
return [4 /*yield*/, generateComponentContent(node, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions)];
|
|
101
308
|
case 1:
|
|
102
309
|
compTag = _e.sent();
|
|
310
|
+
if ('tagName' in compTag) {
|
|
311
|
+
compTag.children.unshift(teleport_plugin_common_1.HASTBuilders.createComment("".concat(node.content.semanticType, " component")));
|
|
312
|
+
}
|
|
103
313
|
return [2 /*return*/, compTag];
|
|
104
314
|
case 2:
|
|
315
|
+
if (dependency && (dependency === null || dependency === void 0 ? void 0 : dependency.type) !== 'local') {
|
|
316
|
+
dependencies[dependency.path] = dependency;
|
|
317
|
+
}
|
|
318
|
+
elementNode = teleport_plugin_common_1.HASTBuilders.createHTMLNode(elementType);
|
|
105
319
|
if (!children) return [3 /*break*/, 6];
|
|
106
320
|
_i = 0, children_1 = children;
|
|
107
321
|
_e.label = 3;
|
|
108
322
|
case 3:
|
|
109
323
|
if (!(_i < children_1.length)) return [3 /*break*/, 6];
|
|
110
324
|
child = children_1[_i];
|
|
111
|
-
return [4 /*yield*/, (0, exports.
|
|
325
|
+
return [4 /*yield*/, (0, exports.generateHtmlSyntax)(child, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions)];
|
|
112
326
|
case 4:
|
|
113
327
|
childTag = _e.sent();
|
|
114
|
-
if (!childTag) {
|
|
115
|
-
return [2 /*return*/];
|
|
116
|
-
}
|
|
117
328
|
if (typeof childTag === 'string') {
|
|
118
329
|
teleport_plugin_common_1.HASTUtils.addTextNode(elementNode, childTag);
|
|
119
330
|
}
|
|
@@ -130,38 +341,47 @@ var generatElementNode = function (node, templatesLookUp, propDefinitions, state
|
|
|
130
341
|
var refStyle = referencedStyles[styleRef];
|
|
131
342
|
if (refStyle.content.mapType === 'inlined') {
|
|
132
343
|
handleStyles(node, refStyle.content.styles, propDefinitions, stateDefinitions);
|
|
133
|
-
return;
|
|
134
344
|
}
|
|
135
345
|
});
|
|
136
346
|
}
|
|
137
347
|
if (Object.keys(style).length > 0) {
|
|
138
348
|
handleStyles(node, style, propDefinitions, stateDefinitions);
|
|
139
349
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
350
|
+
handleAttributes(elementType, elementNode, attrs, propDefinitions, stateDefinitions, structure.options.projectRouteDefinition, structure.outputOptions, resolvedExpressions === null || resolvedExpressions === void 0 ? void 0 : resolvedExpressions.currentIndex);
|
|
351
|
+
addNodeToLookup(node.content.key, elementNode, nodesLookup);
|
|
143
352
|
return [2 /*return*/, elementNode];
|
|
144
353
|
}
|
|
145
354
|
});
|
|
146
355
|
}); };
|
|
147
|
-
var
|
|
148
|
-
var
|
|
149
|
-
var
|
|
150
|
-
|
|
151
|
-
|
|
356
|
+
var createLookupTable = function (component, nodesLookup) {
|
|
357
|
+
var lookup = {};
|
|
358
|
+
for (var _i = 0, _a = Object.keys(nodesLookup); _i < _a.length; _i++) {
|
|
359
|
+
var node = _a[_i];
|
|
360
|
+
lookup[node] = {
|
|
361
|
+
count: 1,
|
|
362
|
+
nextKey: '1',
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
(0, teleport_uidl_resolver_1.createNodesLookup)(component, lookup);
|
|
366
|
+
return lookup;
|
|
367
|
+
};
|
|
368
|
+
var generateComponentContent = function (node, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure, resolvedExpressions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
369
|
+
var externals, plugins, _a, elementType, _b, attrs, _c, children, dependencies, _d, chunks, options, componentName, component, componentClone, lookupTableForCurrentPage, combinedProps, combinedStates, statesForInstance, propsForInstance, _loop_1, _i, _e, propKey, componentWrapper, isExistingNode, componentInstanceToGenerate, compTag, cssPlugin, initialStructure, result;
|
|
370
|
+
var _f, _g, _h;
|
|
371
|
+
return __generator(this, function (_j) {
|
|
372
|
+
switch (_j.label) {
|
|
152
373
|
case 0:
|
|
153
374
|
externals = subComponentOptions.externals, plugins = subComponentOptions.plugins;
|
|
154
|
-
_a = node.content, elementType = _a.elementType, _b = _a.attrs, attrs = _b === void 0 ? {} : _b,
|
|
375
|
+
_a = node.content, elementType = _a.elementType, _b = _a.attrs, attrs = _b === void 0 ? {} : _b, _c = _a.children, children = _c === void 0 ? [] : _c;
|
|
155
376
|
dependencies = structure.dependencies, _d = structure.chunks, chunks = _d === void 0 ? [] : _d, options = structure.options;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
throw new teleport_types_1.HTMLComponentGeneratorError("".concat(elementType, " is not found from the externals. \n\n Received ").concat(JSON.stringify(Object.keys(externals), null, 2)));
|
|
377
|
+
componentName = elementType === 'Component' ? 'AppComponent' : elementType;
|
|
378
|
+
component = externals[componentName];
|
|
379
|
+
if (component === undefined) {
|
|
380
|
+
throw new teleport_types_1.HTMLComponentGeneratorError("".concat(componentName, " is missing from externals object"));
|
|
161
381
|
}
|
|
382
|
+
componentClone = teleport_shared_1.UIDLUtils.cloneObject(component);
|
|
162
383
|
if (children.length) {
|
|
163
|
-
|
|
164
|
-
teleport_shared_1.UIDLUtils.traverseNodes(comp.node, function (childNode, parentNode) {
|
|
384
|
+
teleport_shared_1.UIDLUtils.traverseNodes(componentClone.node, function (childNode, parentNode) {
|
|
165
385
|
var _a, _b;
|
|
166
386
|
if (childNode.type === 'slot' && parentNode.type === 'element') {
|
|
167
387
|
var nonSlotNodes = (_b = (_a = parentNode.content) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.filter(function (n) { return n.type !== 'slot'; });
|
|
@@ -171,6 +391,7 @@ var generateComponentContent = function (node, propDefinitions, stateDefinitions
|
|
|
171
391
|
content: {
|
|
172
392
|
key: 'custom-slot',
|
|
173
393
|
elementType: 'slot',
|
|
394
|
+
name: componentClone.name + 'slot',
|
|
174
395
|
style: {
|
|
175
396
|
display: {
|
|
176
397
|
type: 'static',
|
|
@@ -189,46 +410,117 @@ var generateComponentContent = function (node, propDefinitions, stateDefinitions
|
|
|
189
410
|
*/
|
|
190
411
|
node.content.children = [];
|
|
191
412
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
acc[propKey] = __assign(__assign({}, combinedProps[propKey]), { defaultValue: ((_a = attrs[propKey]) === null || _a === void 0 ? void 0 : _a.content) || ((_b = combinedProps[propKey]) === null || _b === void 0 ? void 0 : _b.defaultValue) });
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
acc[propKey] = combinedProps[propKey];
|
|
200
|
-
}
|
|
413
|
+
lookupTableForCurrentPage = createLookupTable(componentClone, nodesLookup);
|
|
414
|
+
(0, teleport_uidl_resolver_1.generateUniqueKeys)(componentClone, lookupTableForCurrentPage);
|
|
415
|
+
combinedProps = __assign(__assign({}, Object.keys(propDefinitions).reduce(function (acc, propKey) {
|
|
416
|
+
acc[propKey] = propDefinitions[propKey];
|
|
201
417
|
return acc;
|
|
202
|
-
}, {});
|
|
203
|
-
combinedStates = __assign(__assign({}, stateDefinitions), ((
|
|
418
|
+
}, {})), ((componentClone === null || componentClone === void 0 ? void 0 : componentClone.propDefinitions) || {}));
|
|
419
|
+
combinedStates = __assign(__assign({}, stateDefinitions), ((componentClone === null || componentClone === void 0 ? void 0 : componentClone.stateDefinitions) || {}));
|
|
204
420
|
statesForInstance = Object.keys(combinedStates).reduce(function (acc, propKey) {
|
|
205
421
|
var _a, _b;
|
|
206
|
-
|
|
207
|
-
|
|
422
|
+
var attr = attrs[propKey];
|
|
423
|
+
if ((attr === null || attr === void 0 ? void 0 : attr.type) === 'object') {
|
|
424
|
+
throw new Error("Object attributes are not supported in html exports");
|
|
425
|
+
}
|
|
426
|
+
if (attr) {
|
|
427
|
+
acc[propKey] = __assign(__assign({}, combinedStates[propKey]), { defaultValue: (_a = attr === null || attr === void 0 ? void 0 : attr.content) !== null && _a !== void 0 ? _a : (_b = combinedStates[propKey]) === null || _b === void 0 ? void 0 : _b.defaultValue });
|
|
208
428
|
}
|
|
209
429
|
else {
|
|
210
430
|
acc[propKey] = combinedStates[propKey];
|
|
211
431
|
}
|
|
212
432
|
return acc;
|
|
213
433
|
}, {});
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
434
|
+
propsForInstance = {};
|
|
435
|
+
_loop_1 = function (propKey) {
|
|
436
|
+
var attribute = attrs[propKey];
|
|
437
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'element') {
|
|
438
|
+
propsForInstance[propKey] = __assign(__assign({}, combinedProps[propKey]), { defaultValue: attrs[propKey] });
|
|
439
|
+
}
|
|
440
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'dynamic') {
|
|
441
|
+
// When we are using a component instance in a component and the attribute
|
|
442
|
+
// that is passed to the component is of dynamic reference.
|
|
443
|
+
// If means, the component is redirecting the prop that is received to the prop of the component that it is consuming.
|
|
444
|
+
// In this case, we need to pass the value of the prop that is received to the prop of the component that it is consuming.
|
|
445
|
+
// And similary we do the same for the states.
|
|
446
|
+
switch (attribute.content.referenceType) {
|
|
447
|
+
case 'prop':
|
|
448
|
+
propsForInstance[propKey] = combinedProps[attribute.content.id];
|
|
449
|
+
break;
|
|
450
|
+
case 'state':
|
|
451
|
+
propsForInstance[propKey] = combinedStates[attribute.content.id];
|
|
452
|
+
break;
|
|
453
|
+
case 'expr':
|
|
454
|
+
// Ignore expr type attributes in html comp instances for the time being.
|
|
455
|
+
break;
|
|
456
|
+
default:
|
|
457
|
+
throw new Error("ReferenceType ".concat(attribute.content.referenceType, " is not supported in HTML Export."));
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'object') {
|
|
461
|
+
propsForInstance[propKey] = __assign(__assign({}, combinedProps[propKey]), { defaultValue: (attribute === null || attribute === void 0 ? void 0 : attribute.content) || ((_f = combinedProps[propKey]) === null || _f === void 0 ? void 0 : _f.defaultValue) });
|
|
462
|
+
}
|
|
463
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) === 'expr') {
|
|
464
|
+
var _k = attribute.content.split('?.'), ctxId_1 = _k[0], refPath = _k.slice(1);
|
|
465
|
+
var propKeyFromAttr = Object.keys(combinedProps).find(function (key) { return key === ctxId_1; });
|
|
466
|
+
var resolvedValue = combinedProps[propKeyFromAttr];
|
|
467
|
+
propsForInstance[propKey] = Array.isArray(resolvedValue)
|
|
468
|
+
? resolvedValue
|
|
469
|
+
: __assign(__assign({}, resolvedValue), { defaultValue: refPath.length > 0 && (resolvedValue === null || resolvedValue === void 0 ? void 0 : resolvedValue.defaultValue)
|
|
470
|
+
? extractDefaultValueFromRefPath(resolvedValue.defaultValue, __spreadArray([
|
|
471
|
+
resolvedExpressions.currentIndex.toString()
|
|
472
|
+
], refPath, true))
|
|
473
|
+
: null });
|
|
474
|
+
}
|
|
475
|
+
if ((attribute === null || attribute === void 0 ? void 0 : attribute.type) !== 'dynamic' &&
|
|
476
|
+
(attribute === null || attribute === void 0 ? void 0 : attribute.type) !== 'element' &&
|
|
477
|
+
(attribute === null || attribute === void 0 ? void 0 : attribute.type) !== 'object' &&
|
|
478
|
+
(attribute === null || attribute === void 0 ? void 0 : attribute.type) !== 'expr') {
|
|
479
|
+
propsForInstance[propKey] = __assign(__assign({}, combinedProps[propKey]), { defaultValue: (_g = attribute === null || attribute === void 0 ? void 0 : attribute.content) !== null && _g !== void 0 ? _g : (_h = combinedProps[propKey]) === null || _h === void 0 ? void 0 : _h.defaultValue });
|
|
480
|
+
}
|
|
481
|
+
if (attribute === undefined) {
|
|
482
|
+
var propFromCurrentComponent = combinedProps[propKey];
|
|
483
|
+
propsForInstance[propKey] = propFromCurrentComponent;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
// this is where we check if the component we are conusming is actually passing any props to the instance.
|
|
487
|
+
// We check if we are passing any props and pick the value from the atrrs, if not we pick the value from the propDefinitions of
|
|
488
|
+
// the component instance that we are using here.
|
|
489
|
+
for (_i = 0, _e = Object.keys(combinedProps); _i < _e.length; _i++) {
|
|
490
|
+
propKey = _e[_i];
|
|
491
|
+
_loop_1(propKey);
|
|
492
|
+
}
|
|
493
|
+
componentWrapper = teleport_shared_1.StringUtils.camelCaseToDashCase("".concat(componentName, "-wrapper"));
|
|
494
|
+
isExistingNode = nodesLookup[componentWrapper];
|
|
495
|
+
if (isExistingNode !== undefined) {
|
|
496
|
+
componentWrapper = "".concat(componentWrapper, "-").concat(teleport_shared_1.StringUtils.generateRandomString());
|
|
497
|
+
}
|
|
498
|
+
componentInstanceToGenerate = {
|
|
499
|
+
type: 'element',
|
|
500
|
+
content: {
|
|
501
|
+
elementType: componentWrapper,
|
|
502
|
+
key: componentWrapper,
|
|
503
|
+
children: [componentClone.node],
|
|
504
|
+
style: {
|
|
505
|
+
display: {
|
|
506
|
+
type: 'static',
|
|
507
|
+
content: 'contents',
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
return [4 /*yield*/, (0, exports.generateHtmlSyntax)(componentInstanceToGenerate, component.name, nodesLookup, propsForInstance, statesForInstance, subComponentOptions, structure)];
|
|
220
513
|
case 1:
|
|
221
|
-
compTag =
|
|
514
|
+
compTag = _j.sent();
|
|
222
515
|
cssPlugin = (0, teleport_plugin_css_1.createCSSPlugin)({
|
|
223
516
|
templateStyle: 'html',
|
|
224
517
|
templateChunkName: constants_1.DEFAULT_COMPONENT_CHUNK_NAME,
|
|
225
518
|
declareDependency: 'import',
|
|
226
|
-
|
|
227
|
-
chunkName: comp.name,
|
|
519
|
+
chunkName: componentClone.name,
|
|
228
520
|
staticPropReferences: true,
|
|
229
521
|
});
|
|
230
522
|
initialStructure = {
|
|
231
|
-
uidl: __assign(__assign({},
|
|
523
|
+
uidl: __assign(__assign({}, componentClone), { node: componentInstanceToGenerate, propDefinitions: propsForInstance, stateDefinitions: statesForInstance }),
|
|
232
524
|
chunks: [
|
|
233
525
|
{
|
|
234
526
|
type: teleport_types_1.ChunkType.HAST,
|
|
@@ -237,7 +529,7 @@ var generateComponentContent = function (node, propDefinitions, stateDefinitions
|
|
|
237
529
|
linkAfter: [],
|
|
238
530
|
content: compTag,
|
|
239
531
|
meta: {
|
|
240
|
-
nodesLookup:
|
|
532
|
+
nodesLookup: nodesLookup,
|
|
241
533
|
},
|
|
242
534
|
},
|
|
243
535
|
],
|
|
@@ -256,99 +548,183 @@ var generateComponentContent = function (node, propDefinitions, stateDefinitions
|
|
|
256
548
|
});
|
|
257
549
|
}); }, Promise.resolve(initialStructure))];
|
|
258
550
|
case 2:
|
|
259
|
-
result =
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
chunks.push(chunk);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
chunk = chunks.find(function (item) { return item.name === comp.name; });
|
|
269
|
-
if (!chunk) {
|
|
270
|
-
styleChunk = result.chunks.find(function (item) { return item.fileType === teleport_types_1.FileType.CSS; });
|
|
271
|
-
if (!styleChunk) {
|
|
272
|
-
return [2 /*return*/];
|
|
273
|
-
}
|
|
274
|
-
chunks.push(styleChunk);
|
|
551
|
+
result = _j.sent();
|
|
552
|
+
result.chunks.forEach(function (chunk) {
|
|
553
|
+
if (chunk.fileType === teleport_types_1.FileType.CSS) {
|
|
554
|
+
chunks.push(chunk);
|
|
275
555
|
}
|
|
276
|
-
}
|
|
556
|
+
});
|
|
557
|
+
addNodeToLookup(node.content.key, compTag, nodesLookup);
|
|
277
558
|
return [2 /*return*/, compTag];
|
|
278
559
|
}
|
|
279
560
|
});
|
|
280
561
|
}); };
|
|
281
|
-
var generateDynamicNode = function (node,
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
562
|
+
var generateDynamicNode = function (node, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure) { return __awaiter(void 0, void 0, void 0, function () {
|
|
563
|
+
var localeTag, commentNode, usedReferenceValue, elementNode, elementTag, spanTagWrapper, commentNode, spanTag;
|
|
564
|
+
return __generator(this, function (_a) {
|
|
565
|
+
switch (_a.label) {
|
|
566
|
+
case 0:
|
|
567
|
+
if (node.content.referenceType === 'locale') {
|
|
568
|
+
localeTag = teleport_plugin_common_1.HASTBuilders.createHTMLNode('span');
|
|
569
|
+
commentNode = teleport_plugin_common_1.HASTBuilders.createComment("Content for locale ".concat(node.content.id));
|
|
570
|
+
teleport_plugin_common_1.HASTUtils.addChildNode(localeTag, commentNode);
|
|
571
|
+
return [2 /*return*/, localeTag];
|
|
572
|
+
}
|
|
573
|
+
usedReferenceValue = getValueFromReference(node.content.id, node.content.referenceType === 'prop' ? propDefinitions : stateDefinitions);
|
|
574
|
+
if ((usedReferenceValue.type === 'object' || usedReferenceValue.type === 'array') &&
|
|
575
|
+
usedReferenceValue.defaultValue) {
|
|
576
|
+
// Let's say users are biding the prop to a node using something like this "fields.Title"
|
|
577
|
+
// But the fields in the object is the value where the object is defined either in propDefinitions
|
|
578
|
+
// or on the attrs. So, we just need to parsed the rest of the object path and get the value from the object.
|
|
579
|
+
return [2 /*return*/, teleport_plugin_common_1.HASTBuilders.createTextNode(String(extractDefaultValueFromRefPath(usedReferenceValue.defaultValue, node.content.refPath)))];
|
|
580
|
+
}
|
|
581
|
+
if (!(usedReferenceValue.type === 'element')) return [3 /*break*/, 4];
|
|
582
|
+
elementNode = usedReferenceValue.defaultValue;
|
|
583
|
+
if (!elementNode) return [3 /*break*/, 3];
|
|
584
|
+
if (!(elementNode.content.key in nodesLookup)) return [3 /*break*/, 1];
|
|
585
|
+
return [2 /*return*/, nodesLookup[elementNode.content.key]];
|
|
586
|
+
case 1: return [4 /*yield*/, (0, exports.generateHtmlSyntax)(elementNode, compName, nodesLookup, propDefinitions, stateDefinitions, subComponentOptions, structure)];
|
|
587
|
+
case 2:
|
|
588
|
+
elementTag = _a.sent();
|
|
589
|
+
return [2 /*return*/, elementTag];
|
|
590
|
+
case 3:
|
|
591
|
+
spanTagWrapper = teleport_plugin_common_1.HASTBuilders.createHTMLNode('span');
|
|
592
|
+
commentNode = teleport_plugin_common_1.HASTBuilders.createComment("Content for slot ".concat(node.content.id));
|
|
593
|
+
teleport_plugin_common_1.HASTUtils.addChildNode(spanTagWrapper, commentNode);
|
|
594
|
+
return [2 /*return*/, spanTagWrapper];
|
|
595
|
+
case 4:
|
|
596
|
+
spanTag = teleport_plugin_common_1.HASTBuilders.createHTMLNode('span');
|
|
597
|
+
teleport_plugin_common_1.HASTUtils.addTextNode(spanTag, String(usedReferenceValue.defaultValue));
|
|
598
|
+
return [2 /*return*/, spanTag];
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}); };
|
|
289
602
|
var handleStyles = function (node, styles, propDefinitions, stateDefinitions) {
|
|
290
603
|
Object.keys(styles).forEach(function (styleKey) {
|
|
291
|
-
var _a;
|
|
604
|
+
var _a, _b;
|
|
292
605
|
var style = styles[styleKey];
|
|
293
606
|
if (style.type === 'dynamic' && ((_a = style.content) === null || _a === void 0 ? void 0 : _a.referenceType) !== 'token') {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
else if (style.content.referenceType === 'state') {
|
|
298
|
-
style = getValueFromReference(style.content.id, stateDefinitions);
|
|
607
|
+
var referencedValue = getValueFromReference(style.content.id, style.content.referenceType === 'prop' ? propDefinitions : stateDefinitions);
|
|
608
|
+
if (referencedValue.type === 'string' || referencedValue.type === 'number') {
|
|
609
|
+
style = String(extractDefaultValueFromRefPath(referencedValue.defaultValue, (_b = style === null || style === void 0 ? void 0 : style.content) === null || _b === void 0 ? void 0 : _b.refPath));
|
|
299
610
|
}
|
|
300
611
|
node.content.style[styleKey] = typeof style === 'string' ? (0, teleport_uidl_builders_1.staticNode)(style) : style;
|
|
301
612
|
}
|
|
302
613
|
});
|
|
303
614
|
};
|
|
304
|
-
var handleAttributes = function (htmlNode, attrs, propDefinitions, stateDefinitions, routeDefinitions) {
|
|
305
|
-
|
|
615
|
+
var handleAttributes = function (elementType, htmlNode, attrs, propDefinitions, stateDefinitions, routeDefinitions, outputOptions, currentIndex) {
|
|
616
|
+
var _loop_2 = function (attrKey) {
|
|
306
617
|
var attrValue = attrs[attrKey];
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
618
|
+
var type = attrValue.type, content = attrValue.content;
|
|
619
|
+
switch (type) {
|
|
620
|
+
case 'static': {
|
|
621
|
+
if (attrKey === 'href' && typeof content === 'string' && content.startsWith('/')) {
|
|
622
|
+
var targetLink = void 0;
|
|
623
|
+
var targetRoute = ((routeDefinitions === null || routeDefinitions === void 0 ? void 0 : routeDefinitions.values) || []).find(function (route) { return route.pageOptions.navLink === content; });
|
|
624
|
+
if (targetRoute) {
|
|
625
|
+
targetLink = targetRoute.pageOptions.navLink;
|
|
626
|
+
}
|
|
627
|
+
if (!targetRoute && content === '/home') {
|
|
628
|
+
targetLink = '/';
|
|
629
|
+
}
|
|
630
|
+
if (!targetLink && !targetRoute) {
|
|
631
|
+
targetLink = content;
|
|
632
|
+
}
|
|
633
|
+
var currentPageRoute = path_1.join.apply(void 0, __spreadArray(__spreadArray([], ((outputOptions === null || outputOptions === void 0 ? void 0 : outputOptions.folderPath) || []), false), ['./'], false));
|
|
634
|
+
var localPrefix = (0, path_1.relative)("/".concat(currentPageRoute), "/".concat(targetLink === '/' ? 'index' : targetLink));
|
|
635
|
+
teleport_plugin_common_1.HASTUtils.addAttributeToNode(htmlNode, attrKey, "".concat(localPrefix, ".html"));
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
if (typeof content === 'boolean') {
|
|
639
|
+
htmlNode.properties[attrKey] = content === true ? 'true' : 'false';
|
|
640
|
+
}
|
|
641
|
+
else if (typeof content === 'string' || typeof attrValue.content === 'number') {
|
|
642
|
+
var value = teleport_shared_1.StringUtils.encode(String(attrValue.content));
|
|
643
|
+
/*
|
|
644
|
+
elementType of image is always mapped to img.
|
|
645
|
+
For reference, check `html-mapping` file.
|
|
646
|
+
*/
|
|
647
|
+
if (elementType === 'img' && attrKey === 'src' && !isValidURL(value)) {
|
|
648
|
+
/*
|
|
649
|
+
By default we just prefix all the asset paths with just the
|
|
650
|
+
assetPrefix that is configured in the project. But for `html` generators
|
|
651
|
+
we need to prefix that with the current file location.
|
|
652
|
+
|
|
653
|
+
Because, all the other frameworks have a build setup. which serves all the
|
|
654
|
+
assets from the `public` folder. But in the case of `html` here is how it works
|
|
655
|
+
|
|
656
|
+
We load a file from `index.html` the request for the image goes from
|
|
657
|
+
'...url.../public/...image...'
|
|
658
|
+
If it's a nested url, then the request goes from
|
|
659
|
+
'...url/nested/public/...image..'
|
|
660
|
+
|
|
661
|
+
But the nested folder is available only on the root. With this
|
|
662
|
+
The url changes prefixes to
|
|
663
|
+
|
|
664
|
+
../public/playground_assets/..image.. etc depending on the dept the file is in.
|
|
665
|
+
*/
|
|
666
|
+
value = (0, path_1.join)((0, path_1.relative)(path_1.join.apply(void 0, outputOptions.folderPath), './'), value);
|
|
667
|
+
}
|
|
668
|
+
teleport_plugin_common_1.HASTUtils.addAttributeToNode(htmlNode, attrKey, value);
|
|
669
|
+
}
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
case 'dynamic': {
|
|
673
|
+
var value = getValueFromReference(content.id, content.referenceType === 'prop' ? propDefinitions : stateDefinitions);
|
|
674
|
+
teleport_plugin_common_1.HASTUtils.addAttributeToNode(htmlNode, attrKey, String(extractDefaultValueFromRefPath(value.defaultValue, content.refPath)));
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
case 'raw': {
|
|
678
|
+
teleport_plugin_common_1.HASTUtils.addAttributeToNode(htmlNode, attrKey, content);
|
|
679
|
+
break;
|
|
680
|
+
}
|
|
681
|
+
case 'expr': {
|
|
682
|
+
var fullPath = content.split('?.');
|
|
683
|
+
var prop = propDefinitions[(fullPath === null || fullPath === void 0 ? void 0 : fullPath[0]) || ''];
|
|
684
|
+
if (!prop) {
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
var path = typeof currentIndex === 'number'
|
|
688
|
+
? __spreadArray([currentIndex.toString()], fullPath.slice(1), true) : fullPath.slice(1);
|
|
689
|
+
var value = extractDefaultValueFromRefPath(prop.defaultValue, path);
|
|
690
|
+
if (!value) {
|
|
691
|
+
break;
|
|
692
|
+
}
|
|
693
|
+
teleport_plugin_common_1.HASTUtils.addAttributeToNode(htmlNode, attrKey, String(value));
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
case 'element':
|
|
697
|
+
case 'import':
|
|
698
|
+
case 'object':
|
|
699
|
+
break;
|
|
700
|
+
default: {
|
|
701
|
+
throw new teleport_types_1.HTMLComponentGeneratorError("Received ".concat(JSON.stringify(attrValue, null, 2), " \n in handleAttributes for html"));
|
|
702
|
+
}
|
|
338
703
|
}
|
|
339
|
-
}
|
|
704
|
+
};
|
|
705
|
+
for (var _i = 0, _a = Object.keys(attrs); _i < _a.length; _i++) {
|
|
706
|
+
var attrKey = _a[_i];
|
|
707
|
+
_loop_2(attrKey);
|
|
708
|
+
}
|
|
340
709
|
};
|
|
341
710
|
var getValueFromReference = function (key, definitions) {
|
|
342
|
-
var usedReferenceValue = definitions[key.includes('
|
|
711
|
+
var usedReferenceValue = definitions[key.includes('?.') ? key.split('?.')[0] : key];
|
|
343
712
|
if (!usedReferenceValue) {
|
|
344
713
|
throw new teleport_types_1.HTMLComponentGeneratorError("Definition for ".concat(key, " is missing from ").concat(JSON.stringify(definitions, null, 2)));
|
|
345
714
|
}
|
|
346
|
-
if (
|
|
715
|
+
if (['string', 'number', 'object', 'element', 'array', 'boolean'].includes(usedReferenceValue === null || usedReferenceValue === void 0 ? void 0 : usedReferenceValue.type) === false) {
|
|
716
|
+
throw new teleport_types_1.HTMLComponentGeneratorError("Attribute is using dynamic value, but received of type ".concat(JSON.stringify(usedReferenceValue, null, 2)));
|
|
717
|
+
}
|
|
718
|
+
if (usedReferenceValue.type !== 'element' &&
|
|
719
|
+
usedReferenceValue.hasOwnProperty('defaultValue') === false) {
|
|
347
720
|
throw new teleport_types_1.HTMLComponentGeneratorError("Default value is missing from dynamic reference - ".concat(JSON.stringify(usedReferenceValue, null, 2)));
|
|
348
721
|
}
|
|
349
|
-
|
|
350
|
-
|
|
722
|
+
return usedReferenceValue;
|
|
723
|
+
};
|
|
724
|
+
var extractDefaultValueFromRefPath = function (propDefaultValue, refPath) {
|
|
725
|
+
if (typeof propDefaultValue !== 'object' || !(refPath === null || refPath === void 0 ? void 0 : refPath.length)) {
|
|
726
|
+
return propDefaultValue;
|
|
351
727
|
}
|
|
352
|
-
return
|
|
728
|
+
return teleport_shared_1.GenericUtils.getValueFromPath(refPath.join('.'), propDefaultValue);
|
|
353
729
|
};
|
|
354
730
|
//# sourceMappingURL=node-handlers.js.map
|