@htmlplus/element 0.4.4 → 0.4.7
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/bundler/index.d.ts +2 -0
- package/bundler/index.js +2 -0
- package/bundler/rollup.d.ts +7 -0
- package/bundler/rollup.js +21 -0
- package/bundler/vite.d.ts +7 -0
- package/bundler/vite.js +25 -0
- package/client/decorators/attributes.d.ts +1 -1
- package/client/decorators/element.d.ts +1 -1
- package/client/decorators/event.d.ts +1 -1
- package/client/decorators/listen.d.ts +1 -1
- package/client/decorators/method.d.ts +1 -1
- package/client/decorators/property.d.ts +1 -1
- package/client/decorators/state.d.ts +1 -1
- package/client/decorators/watch.d.ts +1 -1
- package/client/helpers/direction.d.ts +1 -1
- package/client/helpers/isRTL.d.ts +1 -1
- package/client/helpers/slots.d.ts +1 -1
- package/client/utils/getMemberType.d.ts +1 -1
- package/client/utils/getMembersKey.d.ts +1 -1
- package/client/utils/getStyles.d.ts +1 -1
- package/client/utils/host.d.ts +1 -1
- package/client/utils/request.d.ts +1 -1
- package/client/utils/request.js +2 -2
- package/compiler/compiler.d.ts +1 -1
- package/compiler/plugins/{external.d.ts → assets.d.ts} +4 -4
- package/compiler/plugins/assets.js +26 -0
- package/compiler/plugins/customElement.d.ts +1 -1
- package/compiler/plugins/customElement.js +32 -15
- package/compiler/plugins/customElementReact/customElementReact.d.ts +1 -1
- package/compiler/plugins/customElementReact/customElementReact.js +2 -5
- package/compiler/plugins/document.d.ts +2 -4
- package/compiler/plugins/document.js +219 -226
- package/compiler/plugins/extract.d.ts +1 -1
- package/compiler/plugins/extract.js +7 -6
- package/compiler/plugins/finish.d.ts +4 -0
- package/compiler/plugins/finish.js +7 -0
- package/compiler/plugins/index.d.ts +3 -1
- package/compiler/plugins/index.js +3 -1
- package/compiler/plugins/parse.d.ts +1 -1
- package/compiler/plugins/parse.js +1 -4
- package/compiler/plugins/read.d.ts +1 -1
- package/compiler/plugins/read.js +4 -8
- package/compiler/plugins/start.d.ts +4 -0
- package/compiler/plugins/start.js +7 -0
- package/compiler/plugins/style.d.ts +2 -4
- package/compiler/plugins/style.js +19 -21
- package/compiler/plugins/validate.d.ts +1 -1
- package/compiler/plugins/validate.js +1 -4
- package/compiler/plugins/visualStudioCode.d.ts +8 -0
- package/compiler/plugins/visualStudioCode.js +28 -0
- package/compiler/plugins/webTypes.d.ts +2 -2
- package/compiler/plugins/webTypes.js +6 -9
- package/compiler/utils/addDependency.d.ts +4 -0
- package/compiler/utils/addDependency.js +51 -0
- package/compiler/utils/getType.js +1 -1
- package/compiler/utils/index.d.ts +2 -0
- package/compiler/utils/index.js +2 -0
- package/compiler/utils/isDirectoryEmpty.js +1 -1
- package/compiler/utils/removeUnusedImport.d.ts +1 -0
- package/compiler/utils/removeUnusedImport.js +49 -0
- package/compiler/utils/renderTemplate.js +2 -4
- package/constants/index.d.ts +1 -0
- package/constants/index.js +2 -0
- package/package.json +5 -12
- package/types/context.d.ts +1 -0
- package/types/global.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/types/index.js +4 -4
- package/types/plugin.d.ts +1 -1
- package/compiler/plugins/external.js +0 -25
- package/compiler/plugins/vscode.d.ts +0 -11
- package/compiler/plugins/vscode.js +0 -83
package/bundler/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import compiler from '../compiler/index.js';
|
|
2
|
+
export const rollup = (...plugins) => {
|
|
3
|
+
const { start, next, finish } = compiler(...plugins);
|
|
4
|
+
return {
|
|
5
|
+
name: 'htmlplus',
|
|
6
|
+
async buildStart() {
|
|
7
|
+
await start();
|
|
8
|
+
},
|
|
9
|
+
async load(id) {
|
|
10
|
+
if (!id.endsWith('.tsx'))
|
|
11
|
+
return;
|
|
12
|
+
const { isInvalid, script } = await next(id);
|
|
13
|
+
if (isInvalid)
|
|
14
|
+
return;
|
|
15
|
+
return script;
|
|
16
|
+
},
|
|
17
|
+
async buildEnd() {
|
|
18
|
+
await finish();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
package/bundler/vite.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import compiler from '../compiler/index.js';
|
|
3
|
+
export const vite = (...plugins) => {
|
|
4
|
+
const { start, next, finish } = compiler(...plugins);
|
|
5
|
+
return {
|
|
6
|
+
name: 'htmlplus',
|
|
7
|
+
async buildStart() {
|
|
8
|
+
await start();
|
|
9
|
+
},
|
|
10
|
+
async load(id) {
|
|
11
|
+
if (!id.endsWith('.tsx'))
|
|
12
|
+
return;
|
|
13
|
+
let { isInvalid, script, stylePath } = await next(id);
|
|
14
|
+
if (isInvalid)
|
|
15
|
+
return;
|
|
16
|
+
if (script && stylePath) {
|
|
17
|
+
script = script.replace(path.basename(stylePath), `${path.basename(stylePath)}?inline`);
|
|
18
|
+
}
|
|
19
|
+
return script;
|
|
20
|
+
},
|
|
21
|
+
async buildEnd() {
|
|
22
|
+
await finish();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Attributes(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Element(tag?: string): (constructor: PlusElement) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function Method(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare function State(): (target: PlusElement, propertyKey: PropertyKey) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const isRTL: (target: PlusElement) => boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getMemberType: (target: PlusElement, key: string) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getMembersKey: (target: PlusElement) => string[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const getStyles: (target: PlusElement) => string | undefined;
|
package/client/utils/host.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PlusElement } from '../../types
|
|
1
|
+
import { PlusElement } from '../../types';
|
|
2
2
|
export declare const host: (target: PlusElement) => HTMLElement;
|
package/client/utils/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { call } from '../utils/call';
|
|
3
|
-
import { task } from '../utils/task';
|
|
2
|
+
import { call } from '../utils/call.js';
|
|
3
|
+
import { task } from '../utils/task.js';
|
|
4
4
|
import { html, render } from '../vendor/uhtml.js';
|
|
5
5
|
import { getStyles } from './getStyles.js';
|
|
6
6
|
import { host } from './host.js';
|
package/compiler/compiler.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Context } from '../../types
|
|
2
|
-
export declare type
|
|
3
|
-
source?: (context: Context) => string;
|
|
1
|
+
import { Context } from '../../types';
|
|
2
|
+
export declare type AssetsOptions = {
|
|
4
3
|
destination: (context: Context) => string;
|
|
4
|
+
source?: (context: Context) => string;
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const assets: (options: AssetsOptions) => {
|
|
7
7
|
name: string;
|
|
8
8
|
next: (context: Context) => void;
|
|
9
9
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
const defaults = {
|
|
4
|
+
destination(context) {
|
|
5
|
+
return `assets/${context.fileName}`;
|
|
6
|
+
},
|
|
7
|
+
source(context) {
|
|
8
|
+
return path.join(context.directoryPath, 'assets');
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export const assets = (options) => {
|
|
12
|
+
const name = 'assets';
|
|
13
|
+
options = Object.assign({}, defaults, options);
|
|
14
|
+
const next = (context) => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const destination = (_a = options.destination) === null || _a === void 0 ? void 0 : _a.call(options, context);
|
|
17
|
+
const source = (_b = options.source) === null || _b === void 0 ? void 0 : _b.call(options, context);
|
|
18
|
+
if (!source)
|
|
19
|
+
return;
|
|
20
|
+
if (!fs.existsSync(source))
|
|
21
|
+
return;
|
|
22
|
+
fs.copySync(source, destination);
|
|
23
|
+
context.assets = source;
|
|
24
|
+
};
|
|
25
|
+
return { name, next };
|
|
26
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import t from '@babel/types';
|
|
2
2
|
import { pascalCase } from 'change-case';
|
|
3
3
|
import * as CONSTANTS from '../../constants/index.js';
|
|
4
|
-
import { print, visitor } from '../utils/index.js';
|
|
4
|
+
import { addDependency, print, visitor } from '../utils/index.js';
|
|
5
5
|
const defaults = {
|
|
6
6
|
typings: true
|
|
7
7
|
};
|
|
@@ -11,26 +11,43 @@ export const customElement = (options) => {
|
|
|
11
11
|
options = Object.assign({}, defaults, options);
|
|
12
12
|
const next = (context) => {
|
|
13
13
|
const ast = t.cloneNode(context.fileAST, true);
|
|
14
|
+
// attach style mapper for 'style' attribute
|
|
15
|
+
visitor(ast, {
|
|
16
|
+
JSXAttribute(path) {
|
|
17
|
+
const { name, value } = path.node;
|
|
18
|
+
if (name.name != 'style')
|
|
19
|
+
return;
|
|
20
|
+
if (!value)
|
|
21
|
+
return;
|
|
22
|
+
if (value.type != 'JSXExpressionContainer')
|
|
23
|
+
return;
|
|
24
|
+
const local = addDependency(path, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTILS_STYLE_MAP, CONSTANTS.UTILS_STYLE_MAP);
|
|
25
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('style'), t.jsxExpressionContainer(t.callExpression(t.identifier(local), [value.expression]))));
|
|
26
|
+
path.skip();
|
|
27
|
+
}
|
|
28
|
+
});
|
|
14
29
|
// TODO
|
|
15
30
|
visitor(ast, {
|
|
16
31
|
ClassDeclaration(path) {
|
|
17
|
-
|
|
32
|
+
const { body, id } = path.node;
|
|
33
|
+
if (id.name != context.className)
|
|
18
34
|
return;
|
|
19
|
-
|
|
35
|
+
body.body.unshift(t.classProperty(t.identifier('uhtml')));
|
|
20
36
|
}
|
|
21
37
|
});
|
|
22
|
-
// replace className
|
|
38
|
+
// replace 'className' attribute to 'class'
|
|
23
39
|
visitor(ast, {
|
|
24
40
|
JSXAttribute(path) {
|
|
25
|
-
|
|
41
|
+
const { name, value } = path.node;
|
|
42
|
+
if (name.name != 'className')
|
|
26
43
|
return;
|
|
27
44
|
const hasClass = path.parentPath.node.attributes.some((attribute) => attribute.name.name == 'class');
|
|
28
45
|
if (hasClass)
|
|
29
46
|
return path.remove();
|
|
30
|
-
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'),
|
|
47
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), value));
|
|
31
48
|
}
|
|
32
49
|
});
|
|
33
|
-
// jsx to uhtml syntax
|
|
50
|
+
// TODO: convert 'jsx' to 'uhtml' syntax
|
|
34
51
|
visitor(ast, {
|
|
35
52
|
JSXAttribute: {
|
|
36
53
|
exit(path) {
|
|
@@ -81,9 +98,10 @@ export const customElement = (options) => {
|
|
|
81
98
|
// attach members
|
|
82
99
|
visitor(ast, {
|
|
83
100
|
ClassDeclaration(path) {
|
|
84
|
-
|
|
101
|
+
const { body, id } = path.node;
|
|
102
|
+
if (id.name != context.className)
|
|
85
103
|
return;
|
|
86
|
-
|
|
104
|
+
body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
|
|
87
105
|
...context.classProperties.map((property) => {
|
|
88
106
|
var _a, _b;
|
|
89
107
|
const type = (_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type;
|
|
@@ -117,7 +135,8 @@ export const customElement = (options) => {
|
|
|
117
135
|
if (options === null || options === void 0 ? void 0 : options.typings) {
|
|
118
136
|
visitor(ast, {
|
|
119
137
|
Program(path) {
|
|
120
|
-
path.node
|
|
138
|
+
const { body } = path.node;
|
|
139
|
+
body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
121
140
|
// TODO
|
|
122
141
|
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
123
142
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
@@ -136,7 +155,7 @@ export const customElement = (options) => {
|
|
|
136
155
|
});
|
|
137
156
|
})
|
|
138
157
|
]))));
|
|
139
|
-
|
|
158
|
+
body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
140
159
|
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
|
|
141
160
|
t.tSExpressionWithTypeArguments(t.identifier('HTMLElement')) // TODO
|
|
142
161
|
], t.tsInterfaceBody([
|
|
@@ -177,10 +196,8 @@ export const customElement = (options) => {
|
|
|
177
196
|
}
|
|
178
197
|
});
|
|
179
198
|
}
|
|
199
|
+
// TODO
|
|
180
200
|
context.script = print(ast);
|
|
181
201
|
};
|
|
182
|
-
return {
|
|
183
|
-
name,
|
|
184
|
-
next
|
|
185
|
-
};
|
|
202
|
+
return { name, next };
|
|
186
203
|
};
|
|
@@ -15,8 +15,8 @@ const defaults = {
|
|
|
15
15
|
};
|
|
16
16
|
export const customElementReact = (options) => {
|
|
17
17
|
const name = 'customElementReact';
|
|
18
|
+
options = Object.assign({}, defaults, options);
|
|
18
19
|
const finish = (global) => {
|
|
19
|
-
options = Object.assign(Object.assign({}, defaults), options);
|
|
20
20
|
// TODO
|
|
21
21
|
const globalNew = {
|
|
22
22
|
contexts: global.contexts.reduce((previous, current) => (Object.assign(Object.assign({}, previous), { [current.filePath]: current })), {}),
|
|
@@ -126,8 +126,5 @@ export const customElementReact = (options) => {
|
|
|
126
126
|
renderTemplate(patterns, options.destination, config)(globalNew);
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
-
return {
|
|
130
|
-
name,
|
|
131
|
-
finish
|
|
132
|
-
};
|
|
129
|
+
return { name, finish };
|
|
133
130
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Global } from '../../types';
|
|
2
2
|
export interface DocumentOptions {
|
|
3
3
|
destination: string;
|
|
4
4
|
}
|
|
5
5
|
export declare const document: (options: DocumentOptions) => {
|
|
6
6
|
name: string;
|
|
7
|
-
|
|
8
|
-
next: (context: Context, global: any) => void;
|
|
9
|
-
finish: (global: any) => void;
|
|
7
|
+
finish: (global: Global) => void;
|
|
10
8
|
};
|