@htmlplus/element 0.3.1 → 0.3.2
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/client/decorators/attributes.d.ts +2 -0
- package/client/decorators/attributes.js +13 -0
- package/client/decorators/bind.d.ts +4 -0
- package/client/decorators/bind.js +17 -0
- package/client/decorators/element.d.ts +2 -0
- package/client/decorators/element.js +49 -0
- package/client/decorators/event.d.ts +21 -0
- package/client/decorators/event.js +18 -0
- package/client/decorators/index.d.ts +9 -0
- package/client/decorators/index.js +9 -0
- package/client/decorators/listen.d.ts +12 -0
- package/client/decorators/listen.js +30 -0
- package/client/decorators/method.d.ts +2 -0
- package/client/decorators/method.js +12 -0
- package/client/decorators/property.d.ts +12 -0
- package/client/decorators/property.js +51 -0
- package/client/decorators/state.d.ts +2 -0
- package/client/decorators/state.js +32 -0
- package/client/decorators/watch.d.ts +2 -0
- package/client/decorators/watch.js +17 -0
- package/client/helpers/classes.d.ts +1 -0
- package/client/helpers/classes.js +62 -0
- package/client/helpers/direction.d.ts +3 -0
- package/client/helpers/direction.js +4 -0
- package/client/helpers/index.d.ts +9 -0
- package/client/helpers/index.js +9 -0
- package/client/helpers/is-rtl.d.ts +2 -0
- package/client/helpers/is-rtl.js +2 -0
- package/client/helpers/query-all.d.ts +3 -0
- package/client/helpers/query-all.js +5 -0
- package/client/helpers/query.d.ts +3 -0
- package/client/helpers/query.js +5 -0
- package/client/helpers/slots.d.ts +6 -0
- package/client/helpers/slots.js +15 -0
- package/client/helpers/styles.d.ts +1 -0
- package/client/helpers/styles.js +16 -0
- package/client/helpers/to-unit.d.ts +1 -0
- package/client/helpers/to-unit.js +7 -0
- package/client/index.d.ts +3 -0
- package/client/index.js +3 -0
- package/client/services/index.d.ts +1 -0
- package/client/services/index.js +1 -0
- package/client/services/link.d.ts +4 -0
- package/client/services/link.js +196 -0
- package/client/utils/append-to-method.d.ts +2 -0
- package/client/utils/append-to-method.js +7 -0
- package/client/utils/call.d.ts +2 -0
- package/client/utils/call.js +4 -0
- package/client/utils/define-property.d.ts +1 -0
- package/client/utils/define-property.js +1 -0
- package/client/utils/event.d.ts +2 -0
- package/client/utils/event.js +6 -0
- package/client/utils/get-members.d.ts +2 -0
- package/client/utils/get-members.js +5 -0
- package/client/utils/get-styles.d.ts +2 -0
- package/client/utils/get-styles.js +5 -0
- package/client/utils/host.d.ts +2 -0
- package/client/utils/host.js +4 -0
- package/client/utils/index.d.ts +20 -0
- package/client/utils/index.js +20 -0
- package/client/utils/is-event.d.ts +1 -0
- package/client/utils/is-event.js +3 -0
- package/client/utils/is-ready.d.ts +2 -0
- package/client/utils/is-ready.js +4 -0
- package/client/utils/is-server.d.ts +1 -0
- package/client/utils/is-server.js +3 -0
- package/client/utils/on-ready.d.ts +2 -0
- package/client/utils/on-ready.js +6 -0
- package/client/utils/parse-value.d.ts +1 -0
- package/client/utils/parse-value.js +15 -0
- package/client/utils/render.d.ts +2 -0
- package/client/utils/render.js +19 -0
- package/client/utils/request.d.ts +2 -0
- package/client/utils/request.js +28 -0
- package/client/utils/sync.d.ts +1 -0
- package/client/utils/sync.js +31 -0
- package/client/utils/task.d.ts +6 -0
- package/client/utils/task.js +37 -0
- package/client/utils/to-boolean.d.ts +1 -0
- package/client/utils/to-boolean.js +3 -0
- package/client/utils/to-event.d.ts +1 -0
- package/client/utils/to-event.js +3 -0
- package/client/utils/type-of.d.ts +3 -0
- package/client/utils/type-of.js +6 -0
- package/client/utils/update-attribute.d.ts +1 -0
- package/client/utils/update-attribute.js +7 -0
- package/compiler/compiler.d.ts +7 -0
- package/compiler/compiler.js +55 -0
- package/compiler/index.d.ts +2 -0
- package/compiler/index.js +2 -0
- package/compiler/plugins/componentDependencyResolver.d.ts +5 -0
- package/compiler/plugins/componentDependencyResolver.js +40 -0
- package/compiler/plugins/customElement.d.ts +5 -0
- package/compiler/plugins/customElement.js +138 -0
- package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
- package/compiler/plugins/customElementReact/customElementReact.js +125 -0
- package/compiler/plugins/customElementReact/index.d.ts +1 -0
- package/compiler/plugins/customElementReact/index.js +1 -0
- package/compiler/plugins/customElementReact/templates/README.md.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/_.gitignore.hbs +2 -0
- package/compiler/plugins/customElementReact/templates/package.json.hbs +37 -0
- package/compiler/plugins/customElementReact/templates/rollup.config.js.hbs +21 -0
- package/compiler/plugins/customElementReact/templates/src/components/index.ts.hbs +17 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +26 -0
- package/compiler/plugins/customElementReact/templates/src/index.ts.hbs +1 -0
- package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +278 -0
- package/compiler/plugins/customElementReact/templates/tsconfig.json.hbs +17 -0
- package/compiler/plugins/docs.d.ts +11 -0
- package/compiler/plugins/docs.js +320 -0
- package/compiler/plugins/extract.d.ts +8 -0
- package/compiler/plugins/extract.js +70 -0
- package/compiler/plugins/index.d.ts +7 -0
- package/compiler/plugins/index.js +7 -0
- package/compiler/plugins/parse.d.ts +5 -0
- package/compiler/plugins/parse.js +16 -0
- package/compiler/plugins/read.d.ts +5 -0
- package/compiler/plugins/read.js +13 -0
- package/compiler/plugins/style.d.ts +10 -0
- package/compiler/plugins/style.js +36 -0
- package/compiler/plugins/validate.d.ts +5 -0
- package/compiler/plugins/validate.js +40 -0
- package/compiler/plugins/vscode.d.ts +11 -0
- package/compiler/plugins/vscode.js +83 -0
- package/compiler/utils/__dirname.d.ts +1 -0
- package/compiler/utils/__dirname.js +5 -0
- package/compiler/utils/get-initializer.d.ts +2 -0
- package/compiler/utils/get-initializer.js +10 -0
- package/compiler/utils/get-tags.d.ts +6 -0
- package/compiler/utils/get-tags.js +34 -0
- package/compiler/utils/get-type.d.ts +2 -0
- package/compiler/utils/get-type.js +69 -0
- package/compiler/utils/has-decorator.d.ts +1 -0
- package/compiler/utils/has-decorator.js +5 -0
- package/compiler/utils/index.d.ts +10 -0
- package/compiler/utils/index.js +10 -0
- package/compiler/utils/is-directory-empty.d.ts +1 -0
- package/compiler/utils/is-directory-empty.js +10 -0
- package/compiler/utils/print-type.d.ts +1 -0
- package/compiler/utils/print-type.js +69 -0
- package/compiler/utils/print.d.ts +2 -0
- package/compiler/utils/print.js +5 -0
- package/compiler/utils/render-template.d.ts +1 -0
- package/compiler/utils/render-template.js +25 -0
- package/compiler/utils/visitor.d.ts +2 -0
- package/compiler/utils/visitor.js +5 -0
- package/constants/index.d.ts +23 -0
- package/constants/index.js +29 -0
- package/package.json +1 -1
- package/runtime/index.d.ts +1 -0
- package/runtime/index.js +4 -0
- package/types/context.d.ts +32 -0
- package/types/context.js +1 -0
- package/types/global.d.ts +4 -0
- package/types/global.js +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +4 -0
- package/types/plugin.d.ts +9 -0
- package/types/plugin.js +1 -0
- package/types/plus-element.d.ts +2 -0
- package/types/plus-element.js +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { visitor } from '../utils/index.js';
|
|
2
|
+
export const componentDependencyResolver = () => {
|
|
3
|
+
const name = 'componentDependencyResolver';
|
|
4
|
+
const next = (context, global) => {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
if (!context.dependenciesUnresolved) {
|
|
7
|
+
visitor(context.fileAST, {
|
|
8
|
+
JSXOpeningElement(path) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const name = path.node.name.name;
|
|
11
|
+
if (!name.includes('-'))
|
|
12
|
+
return;
|
|
13
|
+
const find = (_a = context.dependenciesUnresolved) === null || _a === void 0 ? void 0 : _a.includes(name);
|
|
14
|
+
if (find)
|
|
15
|
+
return;
|
|
16
|
+
(_b = context.dependenciesUnresolved) !== null && _b !== void 0 ? _b : (context.dependenciesUnresolved = []);
|
|
17
|
+
(_c = context.dependenciesUnresolved) === null || _c === void 0 ? void 0 : _c.push(name);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
for (const current of global.contexts) {
|
|
22
|
+
if (!((_a = current.dependenciesUnresolved) === null || _a === void 0 ? void 0 : _a.length))
|
|
23
|
+
continue;
|
|
24
|
+
const dependencies = global.contexts.filter((context) => { var _a; return (_a = current.dependenciesUnresolved) === null || _a === void 0 ? void 0 : _a.includes(context.componentTag); });
|
|
25
|
+
for (const dependency of dependencies) {
|
|
26
|
+
if ((_b = current.dependencies) === null || _b === void 0 ? void 0 : _b.some((item) => item.componentTag == dependency.componentTag))
|
|
27
|
+
continue;
|
|
28
|
+
(_c = current.dependencies) !== null && _c !== void 0 ? _c : (current.dependencies = []);
|
|
29
|
+
current.dependencies.push(dependency);
|
|
30
|
+
current.dependenciesUnresolved = (_d = current.dependenciesUnresolved) === null || _d === void 0 ? void 0 : _d.filter((current) => current != dependency.componentTag);
|
|
31
|
+
// TODO
|
|
32
|
+
// current.fileAST!.program.body.unshift(t.importDeclaration([], t.stringLiteral(dependency.filePath!)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
name,
|
|
38
|
+
next
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import t from '@babel/types';
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
+
import { print, visitor } from '../utils/index.js';
|
|
4
|
+
export const customElement = () => {
|
|
5
|
+
const name = 'customElement';
|
|
6
|
+
const next = (context) => {
|
|
7
|
+
// attach uhtml importer
|
|
8
|
+
context.fileAST.program.body.unshift(t.importDeclaration([t.importSpecifier(t.identifier('html'), t.identifier('html'))], t.stringLiteral('@htmlplus/element/runtime')));
|
|
9
|
+
// jsx to uhtml syntax
|
|
10
|
+
visitor(context.fileAST, {
|
|
11
|
+
JSXAttribute: {
|
|
12
|
+
exit(path) {
|
|
13
|
+
var _a;
|
|
14
|
+
if (((_a = path.node.value) === null || _a === void 0 ? void 0 : _a.type) == 'JSXExpressionContainer') {
|
|
15
|
+
let node = path.node;
|
|
16
|
+
if (path.node.name.name == 'ref') {
|
|
17
|
+
node = t.jsxAttribute(path.node.name, t.jSXExpressionContainer(t.arrowFunctionExpression([t.identifier('$element')], t.assignmentExpression('=', path.node.value.expression, t.identifier('$element')))));
|
|
18
|
+
}
|
|
19
|
+
path.replaceWith(t.jsxIdentifier(print(node).replace('={', '=${')));
|
|
20
|
+
path.skip();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
JSXElement: {
|
|
26
|
+
exit(path) {
|
|
27
|
+
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
28
|
+
path.replaceWith(t.identifier(print(path.node)));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
path.replaceWith(t.identifier('html`' + print(path.node) + '`'));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
JSXFragment: {
|
|
38
|
+
exit(path) {
|
|
39
|
+
path.replaceWith(t.identifier(['html`', ...path.node.children.map((child) => print(child)), '`'].join('')));
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
JSXExpressionContainer: {
|
|
43
|
+
exit(path) {
|
|
44
|
+
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
45
|
+
path.replaceWith(t.identifier('$' + print(path.node)));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
JSXSpreadAttribute: {
|
|
51
|
+
enter(path) {
|
|
52
|
+
// TODO
|
|
53
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('.dataset'), t.jsxExpressionContainer(path.node.argument)));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// attach members
|
|
58
|
+
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
|
|
59
|
+
...context.classProperties.map((property) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const type = (_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type;
|
|
62
|
+
const elements = [];
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 'TSBooleanKeyword':
|
|
65
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_BOOLEAN));
|
|
66
|
+
break;
|
|
67
|
+
case 'TSStringKeyword':
|
|
68
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_STRING));
|
|
69
|
+
break;
|
|
70
|
+
case 'TSNumberKeyword':
|
|
71
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_NUMBER));
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
elements.push(t.nullLiteral());
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
if (property.value)
|
|
78
|
+
elements.push(property.value);
|
|
79
|
+
return t.objectProperty(t.identifier(property.key['name']), t.arrayExpression(elements));
|
|
80
|
+
}),
|
|
81
|
+
...context.classMethods.map((method) => {
|
|
82
|
+
const elements = [t.stringLiteral(CONSTANTS.TYPE_FUNCTION)];
|
|
83
|
+
return t.objectProperty(t.identifier(method.key['name']), t.arrayExpression(elements));
|
|
84
|
+
})
|
|
85
|
+
]), undefined, undefined, undefined, true));
|
|
86
|
+
// attach typings
|
|
87
|
+
visitor(context.fileAST, {
|
|
88
|
+
Program(path) {
|
|
89
|
+
path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
90
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [], t.tsInterfaceBody([
|
|
91
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
92
|
+
optional: property.optional,
|
|
93
|
+
leadingComments: property.leadingComments
|
|
94
|
+
}))
|
|
95
|
+
])),
|
|
96
|
+
t.variableDeclaration('var', [
|
|
97
|
+
t.variableDeclarator(Object.assign(t.identifier(context.componentInterfaceName), {
|
|
98
|
+
typeAnnotation: t.tSTypeAnnotation(t.tSTypeLiteral([
|
|
99
|
+
t.tSPropertySignature(t.identifier('prototype'), t.tsTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName)))),
|
|
100
|
+
t.tSConstructSignatureDeclaration(null, [], t.tSTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName))))
|
|
101
|
+
]))
|
|
102
|
+
}))
|
|
103
|
+
]),
|
|
104
|
+
t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
|
|
105
|
+
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentInterfaceName))])))
|
|
106
|
+
]))
|
|
107
|
+
])), {
|
|
108
|
+
declare: true,
|
|
109
|
+
global: true
|
|
110
|
+
}));
|
|
111
|
+
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
112
|
+
// TODO
|
|
113
|
+
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
114
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
115
|
+
optional: property.optional,
|
|
116
|
+
leadingComments: property.leadingComments
|
|
117
|
+
})),
|
|
118
|
+
...context.classEvents.map((event) => {
|
|
119
|
+
var _a, _b;
|
|
120
|
+
return Object.assign(t.tSPropertySignature(event.key, t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
121
|
+
Object.assign({}, t.identifier('event'), {
|
|
122
|
+
typeAnnotation: t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CustomEvent'), (_b = (_a = event.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation']) === null || _b === void 0 ? void 0 : _b.typeParameters))
|
|
123
|
+
})
|
|
124
|
+
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
125
|
+
optional: true,
|
|
126
|
+
leadingComments: event.leadingComments
|
|
127
|
+
});
|
|
128
|
+
})
|
|
129
|
+
]))));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
context.script = print(context.fileAST);
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
name,
|
|
136
|
+
next
|
|
137
|
+
};
|
|
138
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Global } from '../../../types/index.js';
|
|
2
|
+
export interface CustomElementReactOptions {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
dist: string;
|
|
5
|
+
eventName?: (eventName: string) => string;
|
|
6
|
+
importerComponent?: (context: any) => string;
|
|
7
|
+
importerComponentType?: (context: any) => string;
|
|
8
|
+
}
|
|
9
|
+
export declare const customElementReact: (options: CustomElementReactOptions) => {
|
|
10
|
+
name: string;
|
|
11
|
+
finish: (global: Global) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
|
|
2
|
+
const defaults = {
|
|
3
|
+
compact: false,
|
|
4
|
+
dist: '',
|
|
5
|
+
eventName: undefined,
|
|
6
|
+
importerComponent(context) {
|
|
7
|
+
return `YOUR_CORE_PACKAGE_NAME#${context.componentClassName}`;
|
|
8
|
+
},
|
|
9
|
+
importerComponentType(context) {
|
|
10
|
+
return `YOUR_CORE_PACKAGE_NAME#JSX.${context.componentClassName}`;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const customElementReact = (options) => {
|
|
14
|
+
const name = 'customElementReact';
|
|
15
|
+
const finish = (global) => {
|
|
16
|
+
options = Object.assign(Object.assign({}, defaults), options);
|
|
17
|
+
// TODO
|
|
18
|
+
const globalNew = {
|
|
19
|
+
contexts: global.contexts.reduce((previous, current) => (Object.assign(Object.assign({}, previous), { [current.filePath]: current })), {}),
|
|
20
|
+
options
|
|
21
|
+
};
|
|
22
|
+
const config = { cwd: __dirname(import.meta.url) };
|
|
23
|
+
const isEmpty = isDirectoryEmpty(options.dist);
|
|
24
|
+
const skip = [];
|
|
25
|
+
const getKey = (component) => component.componentClassName;
|
|
26
|
+
for (const key in globalNew.contexts) {
|
|
27
|
+
const context = globalNew.contexts[key];
|
|
28
|
+
const parse = (input) => {
|
|
29
|
+
const [source, key] = input.split('#');
|
|
30
|
+
const [root, ...sub] = key.split('.');
|
|
31
|
+
const variable = ['Type', ...sub].join('.');
|
|
32
|
+
return {
|
|
33
|
+
source,
|
|
34
|
+
variable,
|
|
35
|
+
root
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const classEvents = context.classEvents.map((classEvent) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const name = ((_a = options.eventName) === null || _a === void 0 ? void 0 : _a.call(options, classEvent.key.name)) || classEvent.key.name;
|
|
41
|
+
return Object.assign(Object.assign({}, classEvent), { converted: 'on' + name.charAt(0).toUpperCase() + name.slice(1) });
|
|
42
|
+
});
|
|
43
|
+
const fileName = context.fileName;
|
|
44
|
+
const importerComponent = parse(options.importerComponent(context));
|
|
45
|
+
const importerComponentType = parse(options.importerComponentType(context));
|
|
46
|
+
const state = Object.assign(Object.assign({}, context), { classEvents,
|
|
47
|
+
fileName,
|
|
48
|
+
importerComponent,
|
|
49
|
+
importerComponentType,
|
|
50
|
+
options });
|
|
51
|
+
const patterns = [
|
|
52
|
+
'templates/src/components/*fileName*.ts.hbs',
|
|
53
|
+
'!templates/src/components/*fileName*.compact.ts.hbs'
|
|
54
|
+
];
|
|
55
|
+
renderTemplate(patterns, options.dist, config)(state);
|
|
56
|
+
}
|
|
57
|
+
if (options.compact) {
|
|
58
|
+
globalNew.groups = Object.values(globalNew.contexts)
|
|
59
|
+
.sort((a, b) => getKey(b).length - getKey(a).length)
|
|
60
|
+
.map((component, index, components) => ({
|
|
61
|
+
key: getKey(component),
|
|
62
|
+
components: components.filter((current) => getKey(current).startsWith(getKey(component)))
|
|
63
|
+
}))
|
|
64
|
+
.sort((a, b) => b.components.length - a.components.length)
|
|
65
|
+
.filter((group) => {
|
|
66
|
+
if (skip.includes(group.key))
|
|
67
|
+
return;
|
|
68
|
+
group.components.forEach((component) => skip.push(getKey(component)));
|
|
69
|
+
return true;
|
|
70
|
+
})
|
|
71
|
+
.map((group) => {
|
|
72
|
+
const all = group.components.reverse().map((component, index) => {
|
|
73
|
+
const componentClassNameInCategory = getKey(component).replace(group.key, '');
|
|
74
|
+
const parse = (input) => {
|
|
75
|
+
const [source, key] = input.split('#');
|
|
76
|
+
const [root, ...sub] = key.split('.');
|
|
77
|
+
const local = root + (index + 1);
|
|
78
|
+
const variable = [local, ...sub].join('.');
|
|
79
|
+
return {
|
|
80
|
+
source,
|
|
81
|
+
variable,
|
|
82
|
+
root,
|
|
83
|
+
local
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const importerComponent = parse(options.importerComponent(component));
|
|
87
|
+
const importerComponentType = parse(options.importerComponentType(component));
|
|
88
|
+
return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
|
|
89
|
+
importerComponent,
|
|
90
|
+
importerComponentType });
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
all,
|
|
94
|
+
filterd: all.slice(1),
|
|
95
|
+
root: all.at(0),
|
|
96
|
+
single: all.length == 1
|
|
97
|
+
};
|
|
98
|
+
})
|
|
99
|
+
.sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
|
|
100
|
+
for (const group of globalNew.groups) {
|
|
101
|
+
if (group.single)
|
|
102
|
+
continue;
|
|
103
|
+
const state = Object.assign({ fileName: group.root.fileName, options }, group);
|
|
104
|
+
const patterns = ['templates/src/components/*fileName*.compact.ts.hbs'];
|
|
105
|
+
renderTemplate(patterns, options.dist, config)(state);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (isEmpty) {
|
|
109
|
+
const patterns = [
|
|
110
|
+
'templates/**',
|
|
111
|
+
'!templates/src/components/*fileName*.ts.hbs',
|
|
112
|
+
'!templates/src/components/*fileName*.compact.ts.hbs'
|
|
113
|
+
];
|
|
114
|
+
renderTemplate(patterns, options.dist, config)(globalNew);
|
|
115
|
+
}
|
|
116
|
+
if (!isEmpty) {
|
|
117
|
+
const patterns = ['templates/src/proxy*', 'templates/src/components/index*'];
|
|
118
|
+
renderTemplate(patterns, options.dist, config)(globalNew);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
name,
|
|
123
|
+
finish
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './customElementReact.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './customElementReact.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# React output target for your custom element.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "YOUR_REACT_PACKAGE_NAME",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "React output target for your custom element.",
|
|
6
|
+
"exports": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prebuild": "npm run clean",
|
|
10
|
+
"build": "rollup -c",
|
|
11
|
+
"clean": "rimraf dist"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"YOUR_CORE_PACKAGE_NAME": "latest",
|
|
18
|
+
"change-case": "^4.1.2"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@rollup/plugin-commonjs": "^15.0.0",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
23
|
+
"@types/react": "^16.9.49",
|
|
24
|
+
"glob": "^7.2.0",
|
|
25
|
+
"react": "^17.0.1",
|
|
26
|
+
"react-dom": "^17.0.1",
|
|
27
|
+
"rimraf": "^3.0.2",
|
|
28
|
+
"rollup": "^2.27.1",
|
|
29
|
+
"rollup-plugin-peer-deps-external": "^2.2.3",
|
|
30
|
+
"rollup-plugin-typescript2": "^0.27.2",
|
|
31
|
+
"typescript": "^4.0.2"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": "^16.0.0 || ^17.0.0",
|
|
35
|
+
"react-dom": "^16.0.0 || ^17.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
2
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import glob from 'glob';
|
|
4
|
+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
5
|
+
import typescript from 'rollup-plugin-typescript2';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
input: glob.sync('src/**/*.ts'),
|
|
9
|
+
output: [
|
|
10
|
+
{
|
|
11
|
+
dir: 'dist',
|
|
12
|
+
format: 'esm',
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
plugins: [
|
|
16
|
+
peerDepsExternal(),
|
|
17
|
+
resolve(),
|
|
18
|
+
commonjs(),
|
|
19
|
+
typescript(),
|
|
20
|
+
],
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**************************************************
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
3
|
+
**************************************************/
|
|
4
|
+
|
|
5
|
+
{{#if options.compact}}
|
|
6
|
+
{{#each groups}}
|
|
7
|
+
{{#if single}}
|
|
8
|
+
export * from './{{root.fileName}}';
|
|
9
|
+
{{else}}
|
|
10
|
+
export * from './{{root.fileName}}.compact';
|
|
11
|
+
{{/if}}
|
|
12
|
+
{{/each}}
|
|
13
|
+
{{else}}
|
|
14
|
+
{{#each contexts}}
|
|
15
|
+
export * from './{{fileName}}';
|
|
16
|
+
{{/each}}
|
|
17
|
+
{{/if}}
|
package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
|
|
4
|
+
/**************************************************
|
|
5
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
|
+
**************************************************/
|
|
7
|
+
|
|
8
|
+
{{#each all}}
|
|
9
|
+
import { {{componentClassName}} } from './{{fileName}}';
|
|
10
|
+
{{/each}}
|
|
11
|
+
|
|
12
|
+
const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
|
|
13
|
+
{{#each filterd}}
|
|
14
|
+
{{componentClassNameInCategory}}: {{componentClassName}},
|
|
15
|
+
{{/each}}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { All as {{root.componentClassName}} }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
|
|
4
|
+
/**************************************************
|
|
5
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
|
+
**************************************************/
|
|
7
|
+
|
|
8
|
+
import { proxy } from '../proxy';
|
|
9
|
+
|
|
10
|
+
{{!-- import { {{importerComponent.root}} as Component } from '{{importerComponent.source}}'; --}}
|
|
11
|
+
import '{{importerComponent.source}}';
|
|
12
|
+
import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
|
|
13
|
+
|
|
14
|
+
type Rename<T, R extends { [K in keyof R]: K extends keyof T ? PropertyKey : "Error: key not in T" }> = { [P in keyof T as P extends keyof R ? R[P] : P]: T[P] }
|
|
15
|
+
|
|
16
|
+
type Renamed = Rename<{{importerComponentType.variable}}, {
|
|
17
|
+
{{#each classEvents}}
|
|
18
|
+
{{key.name}}: '{{converted}}',
|
|
19
|
+
{{/each}}
|
|
20
|
+
}>
|
|
21
|
+
|
|
22
|
+
export const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, Renamed>(
|
|
23
|
+
'{{componentTag}}',
|
|
24
|
+
[{{#each classProperties}}'{{key.name}}', {{/each}}],
|
|
25
|
+
[{{#each classEvents}}'{{key.name}}', {{/each}}],
|
|
26
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|