@htmlplus/element 0.2.0 → 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/README.md +34 -4
- package/{dist/client → client}/decorators/attributes.d.ts +0 -0
- package/{dist/client → client}/decorators/attributes.js +1 -1
- package/{dist/client → client}/decorators/bind.d.ts +0 -0
- package/{dist/client → client}/decorators/bind.js +0 -0
- package/{dist/client → client}/decorators/element.d.ts +0 -0
- package/{dist/client → client}/decorators/element.js +1 -1
- package/{dist/client → client}/decorators/event.d.ts +0 -0
- package/{dist/client → client}/decorators/event.js +0 -0
- package/{dist/client → client}/decorators/index.d.ts +0 -0
- package/{dist/client → client}/decorators/index.js +0 -0
- package/{dist/client → client}/decorators/listen.d.ts +0 -0
- package/{dist/client → client}/decorators/listen.js +1 -1
- package/{dist/client → client}/decorators/method.d.ts +0 -0
- package/{dist/client → client}/decorators/method.js +0 -0
- package/{dist/client → client}/decorators/property.d.ts +0 -0
- package/{dist/client → client}/decorators/property.js +0 -0
- package/{dist/client → client}/decorators/state.d.ts +0 -0
- package/{dist/client → client}/decorators/state.js +0 -0
- package/{dist/client → client}/decorators/watch.d.ts +0 -0
- package/{dist/client → client}/decorators/watch.js +1 -1
- package/{dist/client → client}/helpers/classes.d.ts +0 -0
- package/{dist/client → client}/helpers/classes.js +0 -0
- package/{dist/client → client}/helpers/direction.d.ts +0 -0
- package/{dist/client → client}/helpers/direction.js +0 -0
- package/{dist/client → client}/helpers/index.d.ts +0 -0
- package/{dist/client → client}/helpers/index.js +0 -0
- package/{dist/client → client}/helpers/is-rtl.d.ts +0 -0
- package/{dist/client → client}/helpers/is-rtl.js +0 -0
- package/{dist/client → client}/helpers/query-all.d.ts +0 -0
- package/{dist/client → client}/helpers/query-all.js +0 -0
- package/{dist/client → client}/helpers/query.d.ts +0 -0
- package/{dist/client → client}/helpers/query.js +0 -0
- package/{dist/client → client}/helpers/slots.d.ts +0 -0
- package/{dist/client → client}/helpers/slots.js +0 -0
- package/{dist/client → client}/helpers/styles.d.ts +0 -0
- package/{dist/client → client}/helpers/styles.js +0 -0
- package/{dist/client → client}/helpers/to-unit.d.ts +0 -0
- package/{dist/client → client}/helpers/to-unit.js +0 -0
- package/{dist/client → client}/index.d.ts +0 -0
- package/{dist/client → client}/index.js +0 -0
- package/{dist/client → client}/services/index.d.ts +0 -0
- package/{dist/client → client}/services/index.js +0 -0
- package/{dist/client → client}/services/link.d.ts +0 -0
- package/{dist/client → client}/services/link.js +0 -0
- package/{dist/client → client}/utils/append-to-method.d.ts +0 -0
- package/{dist/client → client}/utils/append-to-method.js +0 -0
- package/{dist/client → client}/utils/call.d.ts +0 -0
- package/{dist/client → client}/utils/call.js +0 -0
- package/{dist/client → client}/utils/define-property.d.ts +0 -0
- package/{dist/client → client}/utils/define-property.js +0 -0
- package/{dist/client → client}/utils/event.d.ts +0 -0
- package/{dist/client → client}/utils/event.js +0 -0
- package/{dist/client → client}/utils/get-members.d.ts +0 -0
- package/{dist/client → client}/utils/get-members.js +1 -1
- package/{dist/client → client}/utils/get-styles.d.ts +0 -0
- package/{dist/client → client}/utils/get-styles.js +1 -1
- package/{dist/client → client}/utils/host.d.ts +0 -0
- package/{dist/client → client}/utils/host.js +1 -1
- package/{dist/client → client}/utils/index.d.ts +0 -0
- package/{dist/client → client}/utils/index.js +0 -0
- package/{dist/client → client}/utils/is-event.d.ts +0 -0
- package/{dist/client → client}/utils/is-event.js +0 -0
- package/{dist/client → client}/utils/is-ready.d.ts +0 -0
- package/{dist/client → client}/utils/is-ready.js +1 -1
- package/{dist/client → client}/utils/is-server.d.ts +0 -0
- package/{dist/client → client}/utils/is-server.js +0 -0
- package/{dist/client → client}/utils/on-ready.d.ts +0 -0
- package/{dist/client → client}/utils/on-ready.js +1 -1
- package/{dist/client → client}/utils/parse-value.d.ts +0 -0
- package/{dist/client → client}/utils/parse-value.js +1 -1
- package/{dist/client → client}/utils/render.d.ts +0 -0
- package/{dist/client → client}/utils/render.js +1 -1
- package/{dist/client → client}/utils/request.d.ts +0 -0
- package/{dist/client → client}/utils/request.js +5 -2
- package/{dist/client → client}/utils/sync.d.ts +0 -0
- package/{dist/client → client}/utils/sync.js +0 -0
- package/{dist/client → client}/utils/task.d.ts +0 -0
- package/{dist/client → client}/utils/task.js +0 -0
- package/{dist/client → client}/utils/to-boolean.d.ts +0 -0
- package/{dist/client → client}/utils/to-boolean.js +0 -0
- package/{dist/client → client}/utils/to-event.d.ts +0 -0
- package/{dist/client → client}/utils/to-event.js +0 -0
- package/{dist/client → client}/utils/type-of.d.ts +0 -0
- package/{dist/client → client}/utils/type-of.js +0 -0
- package/{dist/client → client}/utils/update-attribute.d.ts +0 -0
- package/{dist/client → client}/utils/update-attribute.js +0 -0
- package/{dist/compiler → compiler}/compiler.d.ts +0 -0
- package/compiler/compiler.js +55 -0
- package/{dist/compiler → compiler}/index.d.ts +0 -0
- package/{dist/compiler → compiler}/index.js +0 -0
- package/compiler/plugins/componentDependencyResolver.d.ts +5 -0
- package/compiler/plugins/componentDependencyResolver.js +40 -0
- package/{dist/compiler/plugins/uhtml.d.ts → compiler/plugins/customElement.d.ts} +1 -1
- package/compiler/plugins/customElement.js +138 -0
- package/compiler/plugins/customElementReact/customElementReact.d.ts +12 -0
- package/{dist/compiler/plugins/react.proxy/react.proxy.js → compiler/plugins/customElementReact/customElementReact.js} +13 -9
- package/compiler/plugins/customElementReact/index.d.ts +1 -0
- package/compiler/plugins/customElementReact/index.js +1 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/README.md.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/_.gitignore.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/package.json.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/rollup.config.js.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/src/components/index.ts.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/src/components/{{fileName}}.compact.ts.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/src/components/{{fileName}}.ts.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/src/index.ts.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/src/proxy.ts.hbs +0 -0
- package/{dist/compiler/plugins/react.proxy → compiler/plugins/customElementReact}/templates/tsconfig.json.hbs +0 -0
- package/{dist/compiler → compiler}/plugins/docs.d.ts +0 -0
- package/{dist/compiler → compiler}/plugins/docs.js +0 -0
- package/{dist/compiler → compiler}/plugins/extract.d.ts +0 -0
- package/{dist/compiler → compiler}/plugins/extract.js +1 -8
- package/compiler/plugins/index.d.ts +7 -0
- package/compiler/plugins/index.js +7 -0
- package/{dist/compiler → compiler}/plugins/parse.d.ts +0 -0
- package/{dist/compiler → compiler}/plugins/parse.js +0 -0
- package/{dist/compiler → compiler}/plugins/read.d.ts +0 -0
- package/{dist/compiler → compiler}/plugins/read.js +0 -0
- package/compiler/plugins/style.d.ts +10 -0
- package/compiler/plugins/style.js +36 -0
- package/{dist/compiler → compiler}/plugins/validate.d.ts +0 -0
- package/compiler/plugins/validate.js +40 -0
- package/{dist/compiler → compiler}/plugins/vscode.d.ts +0 -0
- package/{dist/compiler → compiler}/plugins/vscode.js +0 -0
- package/{dist/compiler → compiler}/utils/__dirname.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/__dirname.js +0 -0
- package/{dist/compiler → compiler}/utils/get-initializer.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/get-initializer.js +0 -0
- package/{dist/compiler → compiler}/utils/get-tags.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/get-tags.js +0 -0
- package/{dist/compiler → compiler}/utils/get-type.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/get-type.js +0 -0
- package/{dist/compiler → compiler}/utils/has-decorator.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/has-decorator.js +0 -0
- package/{dist/compiler → compiler}/utils/index.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/index.js +0 -0
- package/{dist/compiler → compiler}/utils/is-directory-empty.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/is-directory-empty.js +0 -0
- package/{dist/compiler → compiler}/utils/print-type.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/print-type.js +0 -0
- package/{dist/compiler → compiler}/utils/print.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/print.js +0 -0
- package/{dist/compiler → compiler}/utils/render-template.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/render-template.js +0 -0
- package/{dist/compiler → compiler}/utils/visitor.d.ts +0 -0
- package/{dist/compiler → compiler}/utils/visitor.js +0 -0
- package/{dist/configs/constants.d.ts → constants/index.d.ts} +1 -0
- package/{dist/configs/constants.js → constants/index.js} +1 -0
- package/package.json +10 -47
- package/{dist/runtime → runtime}/index.d.ts +0 -0
- package/{dist/runtime → runtime}/index.js +0 -0
- package/{dist/types → types}/context.d.ts +3 -0
- package/{dist/types → types}/context.js +0 -0
- package/types/global.d.ts +4 -0
- package/{dist/types/plugin.js → types/global.js} +0 -0
- package/{dist/types → types}/index.d.ts +1 -0
- package/{dist/types → types}/index.js +1 -0
- package/types/plugin.d.ts +9 -0
- package/{dist/types/plus-element.js → types/plugin.js} +0 -0
- package/{dist/types → types}/plus-element.d.ts +0 -0
- package/types/plus-element.js +1 -0
- package/dist/compiler/compiler.js +0 -47
- package/dist/compiler/plugins/attach.d.ts +0 -11
- package/dist/compiler/plugins/attach.js +0 -101
- package/dist/compiler/plugins/index.d.ts +0 -11
- package/dist/compiler/plugins/index.js +0 -11
- package/dist/compiler/plugins/print.d.ts +0 -5
- package/dist/compiler/plugins/print.js +0 -11
- package/dist/compiler/plugins/react.proxy/index.d.ts +0 -1
- package/dist/compiler/plugins/react.proxy/index.js +0 -1
- package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +0 -11
- package/dist/compiler/plugins/sass.d.ts +0 -6
- package/dist/compiler/plugins/sass.js +0 -15
- package/dist/compiler/plugins/uhtml.js +0 -59
- package/dist/compiler/plugins/validate.js +0 -8
- package/dist/types/plugin.d.ts +0 -8
package/README.md
CHANGED
|
@@ -258,6 +258,36 @@ export class MyCounter {
|
|
|
258
258
|
|
|
259
259
|
</details>
|
|
260
260
|
|
|
261
|
+
<details>
|
|
262
|
+
<summary>Attributes</summary>
|
|
263
|
+
|
|
264
|
+
TODO
|
|
265
|
+
|
|
266
|
+
```tsx
|
|
267
|
+
import { Attributes, Element } from '@htmlplus/element';
|
|
268
|
+
|
|
269
|
+
@Element('my-button')
|
|
270
|
+
export class MyButton {
|
|
271
|
+
|
|
272
|
+
@Attributes()
|
|
273
|
+
get attributes() {
|
|
274
|
+
return {
|
|
275
|
+
role: 'button'
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
render() {
|
|
280
|
+
return <button><slot /></button>
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```html
|
|
286
|
+
<my-button role="button"></my-button>
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
</details>
|
|
290
|
+
|
|
261
291
|
<details>
|
|
262
292
|
<summary>Watch</summary>
|
|
263
293
|
|
|
@@ -912,15 +942,15 @@ TODO
|
|
|
912
942
|
|
|
913
943
|
```js
|
|
914
944
|
import compiler from '@htmlplus/element/compiler';
|
|
915
|
-
import {
|
|
945
|
+
import { customElement, extract, parse, read, style, validate } from '@htmlplus/element/compiler';
|
|
916
946
|
|
|
917
947
|
const { start, next, finish } = compiler(
|
|
918
948
|
read(),
|
|
919
949
|
parse(),
|
|
950
|
+
validate(),
|
|
920
951
|
extract(),
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
print(),
|
|
952
|
+
style(),
|
|
953
|
+
customElement(),
|
|
924
954
|
);
|
|
925
955
|
|
|
926
956
|
await start();
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { camelCase, paramCase } from 'change-case';
|
|
2
|
-
import * as CONSTANTS from '../../
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
3
|
import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
|
|
4
4
|
export function Element(tag) {
|
|
5
5
|
return function (constructor) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
2
|
export const getMembers = (target) => {
|
|
3
3
|
var _a;
|
|
4
4
|
return (_a = target.constructor[CONSTANTS.STATIC_MEMBERS]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_MEMBERS];
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
2
|
export const getStyles = (target) => {
|
|
3
3
|
var _a;
|
|
4
4
|
return (_a = target.constructor[CONSTANTS.STATIC_STYLES]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_STYLES];
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { html, render as renderer } from 'uhtml';
|
|
2
|
-
import * as CONSTANTS from '../../
|
|
2
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
3
3
|
import { call } from './call.js';
|
|
4
4
|
import { getStyles } from './get-styles.js';
|
|
5
5
|
import { host } from './host.js';
|
|
File without changes
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../
|
|
2
|
-
import { call
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { call } from '../utils/call';
|
|
3
|
+
import { isReady } from '../utils/is-ready';
|
|
4
|
+
import { render } from '../utils/render';
|
|
5
|
+
import { task } from '../utils/task';
|
|
3
6
|
const targets = new Map();
|
|
4
7
|
export const request = (target, state) => {
|
|
5
8
|
if (!isReady(target))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import logUpdate from 'log-update';
|
|
2
|
+
const log = (namespace, message, persist) => {
|
|
3
|
+
logUpdate(`${new Date().toLocaleTimeString()} [@htmlplus/element]${namespace ? `[${namespace}]` : ''} ${message}`);
|
|
4
|
+
persist && logUpdate.done();
|
|
5
|
+
};
|
|
6
|
+
export default (...plugins) => {
|
|
7
|
+
let global = {
|
|
8
|
+
contexts: []
|
|
9
|
+
};
|
|
10
|
+
const start = async () => {
|
|
11
|
+
log(undefined, 'Starting...', true);
|
|
12
|
+
for (const plugin of plugins) {
|
|
13
|
+
if (plugin.start) {
|
|
14
|
+
global = (await plugin.start(global)) || global;
|
|
15
|
+
}
|
|
16
|
+
log(plugin.name, 'Started successfully.');
|
|
17
|
+
}
|
|
18
|
+
log(undefined, `${plugins.length} Plugins started successfully.`, true);
|
|
19
|
+
};
|
|
20
|
+
const next = async (filePath) => {
|
|
21
|
+
const key = filePath.split(/[\/|\\]/g).pop();
|
|
22
|
+
let context = {
|
|
23
|
+
filePath
|
|
24
|
+
};
|
|
25
|
+
log(`${key}`, 'Executing...');
|
|
26
|
+
for (const plugin of plugins) {
|
|
27
|
+
if (!plugin.next)
|
|
28
|
+
continue;
|
|
29
|
+
context = (await plugin.next(context, global)) || context;
|
|
30
|
+
global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
|
|
31
|
+
if (context.isInvalid)
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
if (context.isInvalid)
|
|
35
|
+
log(key, 'Break executing because file is invalid.');
|
|
36
|
+
else
|
|
37
|
+
log(key, 'Executed successfully.');
|
|
38
|
+
return context;
|
|
39
|
+
};
|
|
40
|
+
const finish = async () => {
|
|
41
|
+
log(undefined, 'Finishing...', true);
|
|
42
|
+
for (const plugin of plugins) {
|
|
43
|
+
if (plugin.finish) {
|
|
44
|
+
global = (await plugin.finish(global)) || global;
|
|
45
|
+
}
|
|
46
|
+
log(plugin.name, 'Finished successfully.');
|
|
47
|
+
}
|
|
48
|
+
log(undefined, `${plugins.length} Plugins finished successfully.`, true);
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
start,
|
|
52
|
+
next,
|
|
53
|
+
finish
|
|
54
|
+
};
|
|
55
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -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
|
+
};
|