@teleporthq/teleport-plugin-html-base-component 0.43.0-alpha.0 → 0.43.3
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 +5 -3
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +48 -17
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node-handlers.d.ts +10 -2
- package/dist/cjs/node-handlers.d.ts.map +1 -1
- package/dist/cjs/node-handlers.js +817 -181
- package/dist/cjs/node-handlers.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +49 -18
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node-handlers.d.ts +10 -2
- package/dist/esm/node-handlers.d.ts.map +1 -1
- package/dist/esm/node-handlers.js +817 -181
- 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 +71 -20
- package/src/node-handlers.ts +1152 -207
package/__tests__/index.ts
CHANGED
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
import { component, dynamicNode, elementNode, staticNode } from '@teleporthq/teleport-uidl-builders'
|
|
9
9
|
import { createHTMLBasePlugin } from '../src'
|
|
10
10
|
|
|
11
|
-
const getMockComponentStructure
|
|
11
|
+
const getMockComponentStructure = (): ComponentStructure => ({
|
|
12
12
|
chunks: [],
|
|
13
|
-
options: {
|
|
13
|
+
options: {
|
|
14
|
+
extractedResources: {},
|
|
15
|
+
},
|
|
14
16
|
uidl: component('Test', elementNode('container')),
|
|
15
17
|
dependencies: {},
|
|
16
18
|
})
|
|
@@ -23,7 +25,7 @@ describe('plugin-html-base-component', () => {
|
|
|
23
25
|
|
|
24
26
|
expect(chunks.length).toBe(1)
|
|
25
27
|
expect(htmlChunk).toBeDefined()
|
|
26
|
-
expect(htmlChunk
|
|
28
|
+
expect(htmlChunk?.name).toBe('html-chunk')
|
|
27
29
|
})
|
|
28
30
|
|
|
29
31
|
it('adds attributes to the HAST node', async () => {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ComponentPlugin, ComponentDefaultPluginParams, ComponentUIDL } from '@t
|
|
|
2
2
|
interface HtmlPluginConfig {
|
|
3
3
|
componentChunkName: string;
|
|
4
4
|
wrapComponent?: boolean;
|
|
5
|
+
standaloneHtmlComponents?: boolean;
|
|
5
6
|
}
|
|
6
7
|
interface HtmlPlugin {
|
|
7
8
|
htmlComponentPlugin: ComponentPlugin;
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIf,4BAA4B,EAC5B,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAIf,4BAA4B,EAC5B,aAAa,EAGd,MAAM,4BAA4B,CAAA;AAMnC,UAAU,gBAAgB;IACxB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,UAAU,UAAU;IAClB,mBAAmB,EAAE,eAAe,CAAA;IACpC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAA;CACxF;AAED,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,4BAA4B,CAAC,KAAK,UAAU,CAAA;AAE9F,eAAO,MAAM,oBAAoB,EAAE,iBAAiB,CAAC,gBAAgB,CAiHpE,CAAA;;AAED,wBAAqC"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var constants_1 = require("./constants");
|
|
|
54
54
|
var node_handlers_1 = require("./node-handlers");
|
|
55
55
|
var teleport_shared_1 = require("@teleporthq/teleport-shared");
|
|
56
56
|
var createHTMLBasePlugin = function (config) {
|
|
57
|
-
var _a = config || {}, _b = _a.componentChunkName, componentChunkName = _b === void 0 ? constants_1.DEFAULT_COMPONENT_CHUNK_NAME : _b, _c = _a.wrapComponent, wrapComponent = _c === void 0 ? false : _c;
|
|
57
|
+
var _a = config || {}, _b = _a.componentChunkName, componentChunkName = _b === void 0 ? constants_1.DEFAULT_COMPONENT_CHUNK_NAME : _b, _c = _a.wrapComponent, wrapComponent = _c === void 0 ? false : _c, _d = _a.standaloneHtmlComponents, standaloneHtmlComponents = _d === void 0 ? false : _d;
|
|
58
58
|
var externals = {};
|
|
59
59
|
var plugins = [];
|
|
60
60
|
var addExternals = function (list, subComponentPlugins) {
|
|
@@ -63,28 +63,58 @@ var createHTMLBasePlugin = function (config) {
|
|
|
63
63
|
plugins = subComponentPlugins;
|
|
64
64
|
};
|
|
65
65
|
var htmlComponentPlugin = function (structure) { return __awaiter(void 0, void 0, void 0, function () {
|
|
66
|
-
var uidl, _a, chunks, dependencies, options, _b, propDefinitions, _c, stateDefinitions, outputOptions,
|
|
67
|
-
return __generator(this, function (
|
|
68
|
-
switch (
|
|
66
|
+
var uidl, _a, chunks, dependencies, options, _b, propDefinitions, _c, stateDefinitions, outputOptions, nodesLookup, compBase, scopedRootClass, subComponents, templateOptions, _i, _d, propKey, prop, bodyContent;
|
|
67
|
+
return __generator(this, function (_e) {
|
|
68
|
+
switch (_e.label) {
|
|
69
69
|
case 0:
|
|
70
70
|
uidl = structure.uidl, _a = structure.chunks, chunks = _a === void 0 ? [] : _a, dependencies = structure.dependencies, options = structure.options;
|
|
71
71
|
_b = uidl.propDefinitions, propDefinitions = _b === void 0 ? {} : _b, _c = uidl.stateDefinitions, stateDefinitions = _c === void 0 ? {} : _c, outputOptions = uidl.outputOptions;
|
|
72
|
-
|
|
72
|
+
nodesLookup = {};
|
|
73
73
|
compBase = wrapComponent
|
|
74
74
|
? teleport_plugin_common_1.HASTBuilders.createHTMLNode('body')
|
|
75
75
|
: teleport_plugin_common_1.HASTBuilders.createHTMLNode('div');
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
scopedRootClass = standaloneHtmlComponents
|
|
77
|
+
? "tprt-".concat(teleport_shared_1.StringUtils.camelCaseToDashCase(uidl.name), "-root")
|
|
78
|
+
: undefined;
|
|
79
|
+
if (scopedRootClass) {
|
|
80
|
+
teleport_plugin_common_1.HASTUtils.addClassToNode(compBase, scopedRootClass);
|
|
81
|
+
}
|
|
82
|
+
subComponents = {
|
|
83
|
+
externals: Object.values(externals).reduce(function (acc, comp) {
|
|
84
|
+
teleport_shared_1.UIDLUtils.setFriendlyOutputOptions(comp);
|
|
85
|
+
comp.name = teleport_shared_1.StringUtils.removeIllegalCharacters(comp.name) || 'AppComponent';
|
|
86
|
+
comp.name = teleport_shared_1.UIDLUtils.getComponentClassName(comp);
|
|
87
|
+
acc[comp.name] = comp;
|
|
88
|
+
return acc;
|
|
89
|
+
}, {}),
|
|
90
|
+
plugins: plugins,
|
|
91
|
+
standaloneHtmlComponents: standaloneHtmlComponents,
|
|
92
|
+
};
|
|
93
|
+
templateOptions = {
|
|
94
|
+
chunks: chunks,
|
|
95
|
+
dependencies: dependencies,
|
|
96
|
+
options: options,
|
|
97
|
+
outputOptions: outputOptions,
|
|
98
|
+
};
|
|
99
|
+
_i = 0, _d = Object.keys(propDefinitions);
|
|
100
|
+
_e.label = 1;
|
|
86
101
|
case 1:
|
|
87
|
-
|
|
102
|
+
if (!(_i < _d.length)) return [3 /*break*/, 4];
|
|
103
|
+
propKey = _d[_i];
|
|
104
|
+
prop = propDefinitions[propKey];
|
|
105
|
+
if (!(prop.type === 'element' &&
|
|
106
|
+
prop.defaultValue !== undefined &&
|
|
107
|
+
typeof prop.defaultValue === 'object')) return [3 /*break*/, 3];
|
|
108
|
+
return [4 /*yield*/, (0, node_handlers_1.generateHtmlSyntax)(prop.defaultValue, uidl.name, nodesLookup, propDefinitions, stateDefinitions, subComponents, templateOptions)];
|
|
109
|
+
case 2:
|
|
110
|
+
_e.sent();
|
|
111
|
+
_e.label = 3;
|
|
112
|
+
case 3:
|
|
113
|
+
_i++;
|
|
114
|
+
return [3 /*break*/, 1];
|
|
115
|
+
case 4: return [4 /*yield*/, (0, node_handlers_1.generateHtmlSyntax)(uidl.node, uidl.name, nodesLookup, propDefinitions, stateDefinitions, subComponents, templateOptions)];
|
|
116
|
+
case 5:
|
|
117
|
+
bodyContent = _e.sent();
|
|
88
118
|
teleport_plugin_common_1.HASTUtils.addChildNode(compBase, bodyContent);
|
|
89
119
|
chunks.push({
|
|
90
120
|
type: teleport_types_1.ChunkType.HAST,
|
|
@@ -93,7 +123,8 @@ var createHTMLBasePlugin = function (config) {
|
|
|
93
123
|
content: compBase,
|
|
94
124
|
linkAfter: [],
|
|
95
125
|
meta: {
|
|
96
|
-
nodesLookup:
|
|
126
|
+
nodesLookup: nodesLookup,
|
|
127
|
+
scopedRootClass: scopedRootClass,
|
|
97
128
|
},
|
|
98
129
|
});
|
|
99
130
|
return [2 /*return*/, structure];
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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AA4B,CAAA;;wBAmB9B,qBAAM,IAAA,kCAAkB,EAC1C,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,IAAI,EACT,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,CAChB,EAAA;;oBARK,WAAW,GAAG,SAQnB;oBAED,kCAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,WAAuB,CAAC,CAAA;oBAEzD,MAAM,CAAC,IAAI,CAAC;wBACV,IAAI,EAAE,0BAAS,CAAC,IAAI;wBACpB,QAAQ,EAAE,yBAAQ,CAAC,IAAI;wBACvB,IAAI,EAAE,kBAAkB;wBACxB,OAAO,EAAE,QAAQ;wBACjB,SAAS,EAAE,EAAE;wBACb,IAAI,EAAE;4BACJ,WAAW,aAAA;4BACX,eAAe,iBAAA;yBAChB;qBACF,CAAC,CAAA;oBAEF,sBAAO,SAAS,EAAA;;;SACjB,CAAA;IAED,OAAO;QACL,mBAAmB,qBAAA;QACnB,YAAY,cAAA;KACb,CAAA;AACH,CAAC,CAAA;AAjHY,QAAA,oBAAoB,wBAiHhC;AAED,kBAAe,IAAA,4BAAoB,GAAE,CAAA"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { UIDLNode, HastNode, UIDLPropDefinition, UIDLStateDefinition, HastText, ComponentUIDL, ChunkDefinition, UIDLDependency, GeneratorOptions, ComponentPlugin, UIDLComponentOutputOptions } from '@teleporthq/teleport-types';
|
|
2
|
-
type NodeToHTML<NodeType, ReturnType> = (node: NodeType,
|
|
2
|
+
type NodeToHTML<NodeType, ReturnType> = (node: NodeType, componentName: string, nodesLookup: Record<string, HastNode | HastText | Array<HastNode | HastText>>, propDefinitions: Record<string, UIDLPropDefinition>, stateDefinitions: Record<string, UIDLStateDefinition>, subComponentOptions: {
|
|
3
3
|
externals: Record<string, ComponentUIDL>;
|
|
4
4
|
plugins: ComponentPlugin[];
|
|
5
|
+
standaloneHtmlComponents?: boolean;
|
|
5
6
|
}, structure: {
|
|
6
7
|
chunks: ChunkDefinition[];
|
|
7
8
|
dependencies: Record<string, UIDLDependency>;
|
|
8
9
|
options: GeneratorOptions;
|
|
9
10
|
outputOptions: UIDLComponentOutputOptions;
|
|
11
|
+
},
|
|
12
|
+
/**
|
|
13
|
+
* This param is just to be able to handle CMS array mappers/Repeater nodes. A bit hacky, better support should be implemented
|
|
14
|
+
*/
|
|
15
|
+
resolvedExpressions?: {
|
|
16
|
+
expressions: Record<string, UIDLPropDefinition>;
|
|
17
|
+
currentIndex: number;
|
|
10
18
|
}) => ReturnType;
|
|
11
|
-
export declare const
|
|
19
|
+
export declare const generateHtmlSyntax: NodeToHTML<UIDLNode, Promise<HastNode | HastText | Array<HastNode | HastText>>>;
|
|
12
20
|
export {};
|
|
13
21
|
//# sourceMappingURL=node-handlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-handlers.d.ts","sourceRoot":"","sources":["../../src/node-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,QAAQ,EAGR,kBAAkB,EAClB,mBAAmB,EAGnB,QAAQ,EACR,aAAa,EAGb,eAAe,EACf,cAAc,EAEd,gBAAgB,EAEhB,eAAe,EAEf,0BAA0B,
|
|
1
|
+
{"version":3,"file":"node-handlers.d.ts","sourceRoot":"","sources":["../../src/node-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,QAAQ,EAGR,kBAAkB,EAClB,mBAAmB,EAGnB,QAAQ,EACR,aAAa,EAGb,eAAe,EACf,cAAc,EAEd,gBAAgB,EAEhB,eAAe,EAEf,0BAA0B,EAQ3B,MAAM,4BAA4B,CAAA;AA4EnC,KAAK,UAAU,CAAC,QAAQ,EAAE,UAAU,IAAI,CACtC,IAAI,EAAE,QAAQ,EACd,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,QAAQ,C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