@htmlplus/element 0.3.1 → 0.4.0
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/README.md +2 -2
- 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 +53 -0
- package/client/decorators/event.d.ts +21 -0
- package/client/decorators/event.js +17 -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 +31 -0
- package/client/decorators/method.d.ts +2 -0
- package/client/decorators/method.js +11 -0
- package/client/decorators/property.d.ts +8 -0
- package/client/decorators/property.js +45 -0
- package/client/decorators/state.d.ts +2 -0
- package/client/decorators/state.js +23 -0
- package/client/decorators/watch.d.ts +8 -0
- package/client/decorators/watch.js +34 -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/isRTL.d.ts +2 -0
- package/client/helpers/isRTL.js +2 -0
- package/client/helpers/query.d.ts +3 -0
- package/client/helpers/query.js +5 -0
- package/client/helpers/queryAll.d.ts +3 -0
- package/client/helpers/queryAll.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 +17 -0
- package/client/helpers/toUnit.d.ts +1 -0
- package/client/helpers/toUnit.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/appendToMethod.d.ts +2 -0
- package/client/utils/appendToMethod.js +7 -0
- package/client/utils/call.d.ts +2 -0
- package/client/utils/call.js +4 -0
- package/client/utils/defineProperty.d.ts +1 -0
- package/client/utils/defineProperty.js +1 -0
- package/client/utils/event.d.ts +5 -0
- package/client/utils/event.js +9 -0
- package/client/utils/getMembers.d.ts +2 -0
- package/client/utils/getMembers.js +5 -0
- package/client/utils/getStyles.d.ts +2 -0
- package/client/utils/getStyles.js +5 -0
- package/client/utils/host.d.ts +2 -0
- package/client/utils/host.js +4 -0
- package/client/utils/index.d.ts +17 -0
- package/client/utils/index.js +17 -0
- package/client/utils/isEvent.d.ts +1 -0
- package/client/utils/isEvent.js +3 -0
- package/client/utils/isServer.d.ts +1 -0
- package/client/utils/isServer.js +3 -0
- package/client/utils/parseValue.d.ts +1 -0
- package/client/utils/parseValue.js +15 -0
- package/client/utils/request.d.ts +4 -0
- package/client/utils/request.js +38 -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/toBoolean.d.ts +1 -0
- package/client/utils/toBoolean.js +3 -0
- package/client/utils/toEvent.d.ts +1 -0
- package/client/utils/toEvent.js +3 -0
- package/client/utils/typeOf.d.ts +3 -0
- package/client/utils/typeOf.js +6 -0
- package/client/utils/updateAttribute.d.ts +1 -0
- package/client/utils/updateAttribute.js +7 -0
- package/client/vendor/uhtml.d.ts +22 -0
- package/client/vendor/uhtml.js +700 -0
- package/compiler/compiler.d.ts +7 -0
- package/compiler/compiler.js +72 -0
- package/compiler/index.d.ts +2 -0
- package/compiler/index.js +2 -0
- package/compiler/plugins/customElement.d.ts +8 -0
- package/compiler/plugins/customElement.js +157 -0
- package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
- package/compiler/plugins/customElementReact/customElementReact.js +129 -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/document.d.ts +10 -0
- package/compiler/plugins/document.js +254 -0
- package/compiler/plugins/external.d.ts +9 -0
- package/compiler/plugins/external.js +25 -0
- package/compiler/plugins/extract.d.ts +8 -0
- package/compiler/plugins/extract.js +62 -0
- package/compiler/plugins/index.d.ts +9 -0
- package/compiler/plugins/index.js +9 -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/getInitializer.d.ts +2 -0
- package/compiler/utils/getInitializer.js +10 -0
- package/compiler/utils/getType.d.ts +2 -0
- package/compiler/utils/getType.js +69 -0
- package/compiler/utils/getTypeReference.d.ts +2 -0
- package/compiler/utils/getTypeReference.js +33 -0
- package/compiler/utils/hasDecorator.d.ts +1 -0
- package/compiler/utils/hasDecorator.js +5 -0
- package/compiler/utils/index.d.ts +11 -0
- package/compiler/utils/index.js +11 -0
- package/compiler/utils/isDirectoryEmpty.d.ts +1 -0
- package/compiler/utils/isDirectoryEmpty.js +10 -0
- package/compiler/utils/print.d.ts +2 -0
- package/compiler/utils/print.js +5 -0
- package/compiler/utils/printType.d.ts +1 -0
- package/compiler/utils/printType.js +69 -0
- package/compiler/utils/renderTemplate.d.ts +1 -0
- package/compiler/utils/renderTemplate.js +25 -0
- package/compiler/utils/tags.d.ts +13 -0
- package/compiler/utils/tags.js +53 -0
- package/compiler/utils/visitor.d.ts +2 -0
- package/compiler/utils/visitor.js +5 -0
- package/constants/index.d.ts +22 -0
- package/constants/index.js +28 -0
- package/package.json +14 -17
- package/types/context.d.ts +38 -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 +10 -0
- package/types/plugin.js +1 -0
- package/types/plusElement.d.ts +2 -0
- package/types/plusElement.js +1 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import ora from 'ora';
|
|
2
|
+
const logger = ora({
|
|
3
|
+
color: 'yellow'
|
|
4
|
+
});
|
|
5
|
+
export default (...plugins) => {
|
|
6
|
+
let global = {
|
|
7
|
+
contexts: []
|
|
8
|
+
};
|
|
9
|
+
logger.start(`${plugins.length} Plugins found.`).succeed();
|
|
10
|
+
const start = async () => {
|
|
11
|
+
logger.start('Starting...').succeed();
|
|
12
|
+
for (const plugin of plugins) {
|
|
13
|
+
if (!plugin.start)
|
|
14
|
+
continue;
|
|
15
|
+
logger.start(`Plugin '${plugin.name}' starting...`);
|
|
16
|
+
await plugin.start(global);
|
|
17
|
+
logger.start(`Plugin '${plugin.name}' started successfully.`);
|
|
18
|
+
}
|
|
19
|
+
logger.start(`Plugins started successfully.`).succeed();
|
|
20
|
+
};
|
|
21
|
+
const next = async (filePath) => {
|
|
22
|
+
var _a;
|
|
23
|
+
const key = filePath.split(/[\/|\\]/g).pop();
|
|
24
|
+
let context = {
|
|
25
|
+
filePath
|
|
26
|
+
};
|
|
27
|
+
for (const plugin of plugins) {
|
|
28
|
+
if (!plugin.next)
|
|
29
|
+
continue;
|
|
30
|
+
logger.start(`Plugin '${plugin.name}' executing...`);
|
|
31
|
+
const output = await plugin.next(context, global);
|
|
32
|
+
// TODO
|
|
33
|
+
if (output) {
|
|
34
|
+
context.outputs = ((_a = context.outputs) !== null && _a !== void 0 ? _a : [])
|
|
35
|
+
.filter((output) => {
|
|
36
|
+
if (plugin.name != output.name)
|
|
37
|
+
return true;
|
|
38
|
+
if (plugin.options && plugin.options != output.options)
|
|
39
|
+
return true;
|
|
40
|
+
})
|
|
41
|
+
.concat({
|
|
42
|
+
name: plugin.name,
|
|
43
|
+
options: plugin.options,
|
|
44
|
+
output
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
logger.start(`Plugin '${plugin.name}' executed successfully.`);
|
|
48
|
+
global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
|
|
49
|
+
if (context.isInvalid)
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
if (context.isInvalid)
|
|
53
|
+
logger.start(`File '${key}' break executing because file is invalid.`).succeed();
|
|
54
|
+
return context;
|
|
55
|
+
};
|
|
56
|
+
const finish = async () => {
|
|
57
|
+
logger.start('Finishing...').succeed();
|
|
58
|
+
for (const plugin of plugins) {
|
|
59
|
+
if (!plugin.finish)
|
|
60
|
+
continue;
|
|
61
|
+
logger.start(`Plugin '${plugin.name}' finishing...`);
|
|
62
|
+
await plugin.finish(global);
|
|
63
|
+
logger.start(`Plugin '${plugin.name}' finished successfully.`);
|
|
64
|
+
}
|
|
65
|
+
logger.start(`Plugins finished successfully.`).succeed();
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
start,
|
|
69
|
+
next,
|
|
70
|
+
finish
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import t from '@babel/types';
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
+
import { print, visitor } from '../utils/index.js';
|
|
4
|
+
const defaults = {
|
|
5
|
+
typings: true
|
|
6
|
+
};
|
|
7
|
+
export const customElement = (options) => {
|
|
8
|
+
const name = 'customElement';
|
|
9
|
+
options = Object.assign({}, defaults, options);
|
|
10
|
+
const next = (context) => {
|
|
11
|
+
const ast = t.cloneNode(context.fileAST, true);
|
|
12
|
+
// TODO
|
|
13
|
+
visitor(ast, {
|
|
14
|
+
ClassDeclaration(path) {
|
|
15
|
+
if (path.node.id.name != context.className)
|
|
16
|
+
return;
|
|
17
|
+
path.node.body.body.unshift(t.classProperty(t.identifier('uhtml')));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
// jsx to uhtml syntax
|
|
21
|
+
visitor(ast, {
|
|
22
|
+
JSXAttribute: {
|
|
23
|
+
exit(path) {
|
|
24
|
+
var _a;
|
|
25
|
+
if (((_a = path.node.value) === null || _a === void 0 ? void 0 : _a.type) == 'JSXExpressionContainer') {
|
|
26
|
+
let node = path.node;
|
|
27
|
+
if (path.node.name.name == 'ref') {
|
|
28
|
+
node = t.jsxAttribute(path.node.name, t.jSXExpressionContainer(t.arrowFunctionExpression([t.identifier('$element')], t.assignmentExpression('=', path.node.value.expression, t.identifier('$element')))));
|
|
29
|
+
}
|
|
30
|
+
path.replaceWith(t.jsxIdentifier(print(node).replace('={', '=${')));
|
|
31
|
+
path.skip();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
JSXElement: {
|
|
37
|
+
exit(path) {
|
|
38
|
+
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
39
|
+
path.replaceWith(t.identifier(print(path.node)));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
path.replaceWith(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('uhtml')), t.identifier(`html\`${print(path.node)}\``)));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
JSXFragment: {
|
|
49
|
+
exit(path) {
|
|
50
|
+
path.replaceWith(t.memberExpression(t.memberExpression(t.thisExpression(), t.identifier('uhtml')), t.identifier(['html`', ...path.node.children.map((child) => print(child)), '`'].join(''))));
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
JSXExpressionContainer: {
|
|
54
|
+
exit(path) {
|
|
55
|
+
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
56
|
+
path.replaceWith(t.identifier('$' + print(path.node)));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
JSXSpreadAttribute: {
|
|
62
|
+
enter(path) {
|
|
63
|
+
// TODO
|
|
64
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('.dataset'), t.jsxExpressionContainer(path.node.argument)));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
// attach members
|
|
69
|
+
visitor(ast, {
|
|
70
|
+
ClassDeclaration(path) {
|
|
71
|
+
if (path.node.id.name != context.className)
|
|
72
|
+
return;
|
|
73
|
+
path.node.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
|
|
74
|
+
...context.classProperties.map((property) => {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const type = (_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type;
|
|
77
|
+
const elements = [];
|
|
78
|
+
switch (type) {
|
|
79
|
+
case 'TSBooleanKeyword':
|
|
80
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_BOOLEAN));
|
|
81
|
+
break;
|
|
82
|
+
case 'TSStringKeyword':
|
|
83
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_STRING));
|
|
84
|
+
break;
|
|
85
|
+
case 'TSNumberKeyword':
|
|
86
|
+
elements.push(t.stringLiteral(CONSTANTS.TYPE_NUMBER));
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
elements.push(t.nullLiteral());
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (property.value)
|
|
93
|
+
elements.push(property.value);
|
|
94
|
+
return t.objectProperty(t.identifier(property.key['name']), t.arrayExpression(elements));
|
|
95
|
+
}),
|
|
96
|
+
...context.classMethods.map((method) => {
|
|
97
|
+
const elements = [t.stringLiteral(CONSTANTS.TYPE_FUNCTION)];
|
|
98
|
+
return t.objectProperty(t.identifier(method.key['name']), t.arrayExpression(elements));
|
|
99
|
+
})
|
|
100
|
+
]), undefined, undefined, undefined, true));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
// attach typings
|
|
104
|
+
if (options === null || options === void 0 ? void 0 : options.typings) {
|
|
105
|
+
visitor(ast, {
|
|
106
|
+
Program(path) {
|
|
107
|
+
path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
108
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [], t.tsInterfaceBody([
|
|
109
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
110
|
+
optional: property.optional,
|
|
111
|
+
leadingComments: property.leadingComments
|
|
112
|
+
}))
|
|
113
|
+
])),
|
|
114
|
+
t.variableDeclaration('var', [
|
|
115
|
+
t.variableDeclarator(Object.assign(t.identifier(context.componentInterfaceName), {
|
|
116
|
+
typeAnnotation: t.tSTypeAnnotation(t.tSTypeLiteral([
|
|
117
|
+
t.tSPropertySignature(t.identifier('prototype'), t.tsTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName)))),
|
|
118
|
+
t.tSConstructSignatureDeclaration(null, [], t.tSTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName))))
|
|
119
|
+
]))
|
|
120
|
+
}))
|
|
121
|
+
]),
|
|
122
|
+
t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
|
|
123
|
+
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentInterfaceName))])))
|
|
124
|
+
]))
|
|
125
|
+
])), {
|
|
126
|
+
declare: true,
|
|
127
|
+
global: true
|
|
128
|
+
}));
|
|
129
|
+
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
130
|
+
// TODO
|
|
131
|
+
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
132
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
133
|
+
optional: property.optional,
|
|
134
|
+
leadingComments: property.leadingComments
|
|
135
|
+
})),
|
|
136
|
+
...context.classEvents.map((event) => {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
return Object.assign(t.tSPropertySignature(event.key, t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
139
|
+
Object.assign({}, t.identifier('event'), {
|
|
140
|
+
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))
|
|
141
|
+
})
|
|
142
|
+
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
143
|
+
optional: true,
|
|
144
|
+
leadingComments: event.leadingComments
|
|
145
|
+
});
|
|
146
|
+
})
|
|
147
|
+
]))));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
context.script = print(ast);
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
name,
|
|
155
|
+
next
|
|
156
|
+
};
|
|
157
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Global } from '../../../types/index.js';
|
|
2
|
+
export interface CustomElementReactOptions {
|
|
3
|
+
compact?: boolean;
|
|
4
|
+
destination: 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,129 @@
|
|
|
1
|
+
import { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
|
|
2
|
+
const defaults = {
|
|
3
|
+
compact: false,
|
|
4
|
+
destination: '',
|
|
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.destination);
|
|
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.destination, 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
|
|
73
|
+
.reverse()
|
|
74
|
+
.map((component, index) => {
|
|
75
|
+
const componentClassNameInCategory = getKey(component).replace(group.key, '');
|
|
76
|
+
const parse = (input) => {
|
|
77
|
+
const [source, key] = input.split('#');
|
|
78
|
+
const [root, ...sub] = key.split('.');
|
|
79
|
+
const local = root + (index + 1);
|
|
80
|
+
const variable = [local, ...sub].join('.');
|
|
81
|
+
return {
|
|
82
|
+
source,
|
|
83
|
+
variable,
|
|
84
|
+
root,
|
|
85
|
+
local
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const importerComponent = parse(options.importerComponent(component));
|
|
89
|
+
const importerComponentType = parse(options.importerComponentType(component));
|
|
90
|
+
return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
|
|
91
|
+
importerComponent,
|
|
92
|
+
importerComponentType });
|
|
93
|
+
})
|
|
94
|
+
// TODO: experimental
|
|
95
|
+
.sort((a, b) => (b.componentClassName < a.componentClassName ? 0 : -1));
|
|
96
|
+
return {
|
|
97
|
+
all,
|
|
98
|
+
filterd: all.slice(1),
|
|
99
|
+
root: all.at(0),
|
|
100
|
+
single: all.length == 1
|
|
101
|
+
};
|
|
102
|
+
})
|
|
103
|
+
.sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
|
|
104
|
+
for (const group of globalNew.groups) {
|
|
105
|
+
if (group.single)
|
|
106
|
+
continue;
|
|
107
|
+
const state = Object.assign({ fileName: group.root.fileName, options }, group);
|
|
108
|
+
const patterns = ['templates/src/components/*fileName*.compact.ts.hbs'];
|
|
109
|
+
renderTemplate(patterns, options.destination, config)(state);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (isEmpty) {
|
|
113
|
+
const patterns = [
|
|
114
|
+
'templates/**',
|
|
115
|
+
'!templates/src/components/*fileName*.ts.hbs',
|
|
116
|
+
'!templates/src/components/*fileName*.compact.ts.hbs'
|
|
117
|
+
];
|
|
118
|
+
renderTemplate(patterns, options.destination, config)(globalNew);
|
|
119
|
+
}
|
|
120
|
+
if (!isEmpty) {
|
|
121
|
+
const patterns = ['templates/src/proxy*', 'templates/src/components/index*'];
|
|
122
|
+
renderTemplate(patterns, options.destination, config)(globalNew);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
name,
|
|
127
|
+
finish
|
|
128
|
+
};
|
|
129
|
+
};
|
|
@@ -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 { {{componentClassNamePrune}} } from './{{fileName}}';
|
|
10
|
+
{{/each}}
|
|
11
|
+
|
|
12
|
+
const All = /*@__PURE__*/ Object.assign({{root.componentClassNamePrune}}, {
|
|
13
|
+
{{#each filterd}}
|
|
14
|
+
{{componentClassNameInCategory}}: {{componentClassNamePrune}},
|
|
15
|
+
{{/each}}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { All as {{root.componentClassNamePrune}} }
|
|
@@ -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 {{componentClassNamePrune}} = /*@__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';
|