@htmlplus/element 0.1.9 → 0.3.1
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/package.json +10 -47
- package/dist/client/decorators/attributes.d.ts +0 -2
- package/dist/client/decorators/attributes.js +0 -13
- package/dist/client/decorators/bind.d.ts +0 -4
- package/dist/client/decorators/bind.js +0 -17
- package/dist/client/decorators/element.d.ts +0 -2
- package/dist/client/decorators/element.js +0 -49
- package/dist/client/decorators/event.d.ts +0 -21
- package/dist/client/decorators/event.js +0 -18
- package/dist/client/decorators/index.d.ts +0 -9
- package/dist/client/decorators/index.js +0 -9
- package/dist/client/decorators/listen.d.ts +0 -12
- package/dist/client/decorators/listen.js +0 -30
- package/dist/client/decorators/method.d.ts +0 -2
- package/dist/client/decorators/method.js +0 -12
- package/dist/client/decorators/property.d.ts +0 -12
- package/dist/client/decorators/property.js +0 -51
- package/dist/client/decorators/state.d.ts +0 -2
- package/dist/client/decorators/state.js +0 -32
- package/dist/client/decorators/watch.d.ts +0 -2
- package/dist/client/decorators/watch.js +0 -17
- package/dist/client/helpers/classes.d.ts +0 -1
- package/dist/client/helpers/classes.js +0 -62
- package/dist/client/helpers/direction.d.ts +0 -3
- package/dist/client/helpers/direction.js +0 -4
- package/dist/client/helpers/index.d.ts +0 -9
- package/dist/client/helpers/index.js +0 -9
- package/dist/client/helpers/is-rtl.d.ts +0 -2
- package/dist/client/helpers/is-rtl.js +0 -2
- package/dist/client/helpers/query-all.d.ts +0 -3
- package/dist/client/helpers/query-all.js +0 -5
- package/dist/client/helpers/query.d.ts +0 -3
- package/dist/client/helpers/query.js +0 -5
- package/dist/client/helpers/slots.d.ts +0 -6
- package/dist/client/helpers/slots.js +0 -15
- package/dist/client/helpers/styles.d.ts +0 -1
- package/dist/client/helpers/styles.js +0 -16
- package/dist/client/helpers/to-unit.d.ts +0 -1
- package/dist/client/helpers/to-unit.js +0 -7
- package/dist/client/index.d.ts +0 -3
- package/dist/client/index.js +0 -3
- package/dist/client/services/index.d.ts +0 -1
- package/dist/client/services/index.js +0 -1
- package/dist/client/services/link.d.ts +0 -4
- package/dist/client/services/link.js +0 -196
- package/dist/client/utils/append-to-method.d.ts +0 -2
- package/dist/client/utils/append-to-method.js +0 -7
- package/dist/client/utils/call.d.ts +0 -2
- package/dist/client/utils/call.js +0 -4
- package/dist/client/utils/define-property.d.ts +0 -1
- package/dist/client/utils/define-property.js +0 -1
- package/dist/client/utils/event.d.ts +0 -2
- package/dist/client/utils/event.js +0 -6
- package/dist/client/utils/get-members.d.ts +0 -2
- package/dist/client/utils/get-members.js +0 -5
- package/dist/client/utils/get-styles.d.ts +0 -2
- package/dist/client/utils/get-styles.js +0 -5
- package/dist/client/utils/host.d.ts +0 -2
- package/dist/client/utils/host.js +0 -4
- package/dist/client/utils/index.d.ts +0 -20
- package/dist/client/utils/index.js +0 -20
- package/dist/client/utils/is-event.d.ts +0 -1
- package/dist/client/utils/is-event.js +0 -3
- package/dist/client/utils/is-ready.d.ts +0 -2
- package/dist/client/utils/is-ready.js +0 -4
- package/dist/client/utils/is-server.d.ts +0 -1
- package/dist/client/utils/is-server.js +0 -3
- package/dist/client/utils/on-ready.d.ts +0 -2
- package/dist/client/utils/on-ready.js +0 -6
- package/dist/client/utils/parse-value.d.ts +0 -1
- package/dist/client/utils/parse-value.js +0 -15
- package/dist/client/utils/render.d.ts +0 -2
- package/dist/client/utils/render.js +0 -17
- package/dist/client/utils/request.d.ts +0 -2
- package/dist/client/utils/request.js +0 -25
- package/dist/client/utils/sync.d.ts +0 -1
- package/dist/client/utils/sync.js +0 -31
- package/dist/client/utils/task.d.ts +0 -6
- package/dist/client/utils/task.js +0 -46
- package/dist/client/utils/to-boolean.d.ts +0 -1
- package/dist/client/utils/to-boolean.js +0 -3
- package/dist/client/utils/to-event.d.ts +0 -1
- package/dist/client/utils/to-event.js +0 -3
- package/dist/client/utils/type-of.d.ts +0 -3
- package/dist/client/utils/type-of.js +0 -6
- package/dist/client/utils/update-attribute.d.ts +0 -1
- package/dist/client/utils/update-attribute.js +0 -7
- package/dist/compiler/compiler.d.ts +0 -7
- package/dist/compiler/compiler.js +0 -56
- package/dist/compiler/index.d.ts +0 -2
- package/dist/compiler/index.js +0 -2
- package/dist/compiler/plugins/attach.d.ts +0 -11
- package/dist/compiler/plugins/attach.js +0 -101
- package/dist/compiler/plugins/docs.d.ts +0 -11
- package/dist/compiler/plugins/docs.js +0 -320
- package/dist/compiler/plugins/extract.d.ts +0 -8
- package/dist/compiler/plugins/extract.js +0 -77
- package/dist/compiler/plugins/index.d.ts +0 -11
- package/dist/compiler/plugins/index.js +0 -11
- package/dist/compiler/plugins/parse.d.ts +0 -5
- package/dist/compiler/plugins/parse.js +0 -16
- 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/react.proxy/react.proxy.js +0 -121
- package/dist/compiler/plugins/react.proxy/templates/README.md.hbs +0 -1
- package/dist/compiler/plugins/react.proxy/templates/_.gitignore.hbs +0 -2
- package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +0 -37
- package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +0 -21
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +0 -17
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs +0 -18
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +0 -26
- package/dist/compiler/plugins/react.proxy/templates/src/index.ts.hbs +0 -1
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +0 -278
- package/dist/compiler/plugins/react.proxy/templates/tsconfig.json.hbs +0 -17
- package/dist/compiler/plugins/read.d.ts +0 -5
- package/dist/compiler/plugins/read.js +0 -13
- package/dist/compiler/plugins/sass.d.ts +0 -6
- package/dist/compiler/plugins/sass.js +0 -15
- package/dist/compiler/plugins/uhtml.d.ts +0 -5
- package/dist/compiler/plugins/uhtml.js +0 -59
- package/dist/compiler/plugins/validate.d.ts +0 -5
- package/dist/compiler/plugins/validate.js +0 -8
- package/dist/compiler/plugins/vscode.d.ts +0 -11
- package/dist/compiler/plugins/vscode.js +0 -83
- package/dist/compiler/utils/__dirname.d.ts +0 -1
- package/dist/compiler/utils/__dirname.js +0 -5
- package/dist/compiler/utils/get-initializer.d.ts +0 -2
- package/dist/compiler/utils/get-initializer.js +0 -10
- package/dist/compiler/utils/get-tags.d.ts +0 -6
- package/dist/compiler/utils/get-tags.js +0 -34
- package/dist/compiler/utils/get-type.d.ts +0 -2
- package/dist/compiler/utils/get-type.js +0 -69
- package/dist/compiler/utils/has-decorator.d.ts +0 -1
- package/dist/compiler/utils/has-decorator.js +0 -5
- package/dist/compiler/utils/index.d.ts +0 -10
- package/dist/compiler/utils/index.js +0 -10
- package/dist/compiler/utils/is-directory-empty.d.ts +0 -1
- package/dist/compiler/utils/is-directory-empty.js +0 -10
- package/dist/compiler/utils/print-type.d.ts +0 -1
- package/dist/compiler/utils/print-type.js +0 -69
- package/dist/compiler/utils/print.d.ts +0 -2
- package/dist/compiler/utils/print.js +0 -5
- package/dist/compiler/utils/render-template.d.ts +0 -1
- package/dist/compiler/utils/render-template.js +0 -25
- package/dist/compiler/utils/visitor.d.ts +0 -2
- package/dist/compiler/utils/visitor.js +0 -5
- package/dist/configs/constants.d.ts +0 -22
- package/dist/configs/constants.js +0 -28
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.js +0 -4
- package/dist/types/context.d.ts +0 -29
- package/dist/types/context.js +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.js +0 -3
- package/dist/types/plugin.d.ts +0 -8
- package/dist/types/plugin.js +0 -1
- package/dist/types/plus-element.d.ts +0 -2
- package/dist/types/plus-element.js +0 -1
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface ReactProxyOptions {
|
|
2
|
-
compact?: boolean;
|
|
3
|
-
dist: string;
|
|
4
|
-
eventName?: (eventName: string) => string;
|
|
5
|
-
importerComponent?: (context: any) => string;
|
|
6
|
-
importerComponentType?: (context: any) => string;
|
|
7
|
-
}
|
|
8
|
-
export declare const reactProxy: (options: ReactProxyOptions) => {
|
|
9
|
-
name: string;
|
|
10
|
-
finish: (global: any) => void;
|
|
11
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
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 reactProxy = (options) => {
|
|
14
|
-
const name = 'react-proxy';
|
|
15
|
-
const finish = (global) => {
|
|
16
|
-
options = Object.assign(Object.assign({}, defaults), options);
|
|
17
|
-
global = Object.assign(Object.assign({}, global), { options });
|
|
18
|
-
const config = { cwd: __dirname(import.meta.url) };
|
|
19
|
-
const isEmpty = isDirectoryEmpty(options.dist);
|
|
20
|
-
const skip = [];
|
|
21
|
-
const getKey = (component) => component.componentClassName;
|
|
22
|
-
for (const key in global.contexts) {
|
|
23
|
-
const context = global.contexts[key];
|
|
24
|
-
const parse = (input) => {
|
|
25
|
-
const [source, key] = input.split('#');
|
|
26
|
-
const [root, ...sub] = key.split('.');
|
|
27
|
-
const variable = ['Type', ...sub].join('.');
|
|
28
|
-
return {
|
|
29
|
-
source,
|
|
30
|
-
variable,
|
|
31
|
-
root
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const classEvents = context.classEvents.map((classEvent) => {
|
|
35
|
-
var _a;
|
|
36
|
-
const name = ((_a = options.eventName) === null || _a === void 0 ? void 0 : _a.call(options, classEvent.key.name)) || classEvent.key.name;
|
|
37
|
-
return Object.assign(Object.assign({}, classEvent), { converted: 'on' + name.charAt(0).toUpperCase() + name.slice(1) });
|
|
38
|
-
});
|
|
39
|
-
const fileName = context.fileName;
|
|
40
|
-
const importerComponent = parse(options.importerComponent(context));
|
|
41
|
-
const importerComponentType = parse(options.importerComponentType(context));
|
|
42
|
-
const state = Object.assign(Object.assign({}, context), { classEvents,
|
|
43
|
-
fileName,
|
|
44
|
-
importerComponent,
|
|
45
|
-
importerComponentType,
|
|
46
|
-
options });
|
|
47
|
-
const patterns = [
|
|
48
|
-
'templates/src/components/*fileName*.ts.hbs',
|
|
49
|
-
'!templates/src/components/*fileName*.compact.ts.hbs'
|
|
50
|
-
];
|
|
51
|
-
renderTemplate(patterns, options.dist, config)(state);
|
|
52
|
-
}
|
|
53
|
-
if (options.compact) {
|
|
54
|
-
global.groups = Object.values(global.contexts)
|
|
55
|
-
.sort((a, b) => getKey(b).length - getKey(a).length)
|
|
56
|
-
.map((component, index, components) => ({
|
|
57
|
-
key: getKey(component),
|
|
58
|
-
components: components.filter((current) => getKey(current).startsWith(getKey(component)))
|
|
59
|
-
}))
|
|
60
|
-
.sort((a, b) => b.components.length - a.components.length)
|
|
61
|
-
.filter((group) => {
|
|
62
|
-
if (skip.includes(group.key))
|
|
63
|
-
return;
|
|
64
|
-
group.components.forEach((component) => skip.push(getKey(component)));
|
|
65
|
-
return true;
|
|
66
|
-
})
|
|
67
|
-
.map((group) => {
|
|
68
|
-
const all = group.components.reverse().map((component, index) => {
|
|
69
|
-
const componentClassNameInCategory = getKey(component).replace(group.key, '');
|
|
70
|
-
const parse = (input) => {
|
|
71
|
-
const [source, key] = input.split('#');
|
|
72
|
-
const [root, ...sub] = key.split('.');
|
|
73
|
-
const local = root + (index + 1);
|
|
74
|
-
const variable = [local, ...sub].join('.');
|
|
75
|
-
return {
|
|
76
|
-
source,
|
|
77
|
-
variable,
|
|
78
|
-
root,
|
|
79
|
-
local
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
const importerComponent = parse(options.importerComponent(component));
|
|
83
|
-
const importerComponentType = parse(options.importerComponentType(component));
|
|
84
|
-
return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
|
|
85
|
-
importerComponent,
|
|
86
|
-
importerComponentType });
|
|
87
|
-
});
|
|
88
|
-
return {
|
|
89
|
-
all,
|
|
90
|
-
filterd: all.slice(1),
|
|
91
|
-
root: all.at(0),
|
|
92
|
-
single: all.length == 1
|
|
93
|
-
};
|
|
94
|
-
})
|
|
95
|
-
.sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
|
|
96
|
-
for (const group of global.groups) {
|
|
97
|
-
if (group.single)
|
|
98
|
-
continue;
|
|
99
|
-
const state = Object.assign({ fileName: group.root.fileName, options }, group);
|
|
100
|
-
const patterns = ['templates/src/components/*fileName*.compact.ts.hbs'];
|
|
101
|
-
renderTemplate(patterns, options.dist, config)(state);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (isEmpty) {
|
|
105
|
-
const patterns = [
|
|
106
|
-
'templates/**',
|
|
107
|
-
'!templates/src/components/*fileName*.ts.hbs',
|
|
108
|
-
'!templates/src/components/*fileName*.compact.ts.hbs'
|
|
109
|
-
];
|
|
110
|
-
renderTemplate(patterns, options.dist, config)(global);
|
|
111
|
-
}
|
|
112
|
-
if (!isEmpty) {
|
|
113
|
-
const patterns = ['templates/src/proxy*', 'templates/src/components/index*'];
|
|
114
|
-
renderTemplate(patterns, options.dist, config)(global);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return {
|
|
118
|
-
name,
|
|
119
|
-
finish
|
|
120
|
-
};
|
|
121
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# React output target for your custom element.
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
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/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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}} }
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './components';
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
/**************************************************
|
|
2
|
-
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
3
|
-
**************************************************/
|
|
4
|
-
|
|
5
|
-
import { camelCase, paramCase, pascalCase } from 'change-case';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
type EventHandlerType = (event: Event) => any;
|
|
9
|
-
|
|
10
|
-
type FinalPropsType<ElementType> = Omit<PropsType<ElementType>, 'forwardedRef'>;
|
|
11
|
-
|
|
12
|
-
type Mutable<T> = { -readonly [P in keyof T]-?: T[P] };
|
|
13
|
-
|
|
14
|
-
interface ExtraType {
|
|
15
|
-
props?: Array<string>;
|
|
16
|
-
events?: Array<string>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface PropsType<ElementType> extends React.HTMLAttributes<ElementType> {
|
|
20
|
-
forwardedRef: React.RefObject<ElementType>;
|
|
21
|
-
ref?: React.Ref<any>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface StyleReactProps {
|
|
25
|
-
class?: string;
|
|
26
|
-
className?: string;
|
|
27
|
-
style?: {
|
|
28
|
-
[key: string]: any;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const arrayToMap = (array: string[] | DOMTokenList) => {
|
|
33
|
-
const map = new Map<string, string>();
|
|
34
|
-
|
|
35
|
-
(array as string[]).forEach((s: string) => map.set(s, s));
|
|
36
|
-
|
|
37
|
-
return map;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const getCustomEvent = (name: string, events: Array<string>) => {
|
|
41
|
-
// TODO
|
|
42
|
-
name = camelCase(name.slice(3));
|
|
43
|
-
|
|
44
|
-
const event = events.find((event) => event.endsWith(name));
|
|
45
|
-
|
|
46
|
-
if (!event) return;
|
|
47
|
-
|
|
48
|
-
return event;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const forwardRef = <ElementType, PropType>(ReactComponent: any) => {
|
|
52
|
-
const forwardRef = (
|
|
53
|
-
props: PropType & Omit<React.HTMLAttributes<ElementType>, 'style'> & StyleReactProps,
|
|
54
|
-
ref: React.Ref<ElementType>
|
|
55
|
-
) => {
|
|
56
|
-
const { children, ...remainedProps } = props;
|
|
57
|
-
|
|
58
|
-
const newProps = {
|
|
59
|
-
...remainedProps,
|
|
60
|
-
forwardedRef: ref
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return React.createElement(ReactComponent, newProps, children);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
forwardRef.displayName = ReactComponent.displayName;
|
|
67
|
-
|
|
68
|
-
return React.forwardRef(forwardRef);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const isEvent = (name: string) => {
|
|
72
|
-
return name.indexOf('on') === 0 && name[2] === name[2].toUpperCase();
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const isPrimitive = (value: any) => {
|
|
76
|
-
const type = typeof value;
|
|
77
|
-
|
|
78
|
-
const match = type.match(/boolean|string|number/);
|
|
79
|
-
|
|
80
|
-
return match;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const getProps = <ElementType>(ref: React.Ref<ElementType>, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
84
|
-
const { forwardedRef } = props;
|
|
85
|
-
|
|
86
|
-
const result: FinalPropsType<ElementType> = {
|
|
87
|
-
ref: mergeRefs(forwardedRef, ref)
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
Object.keys(props).forEach((name) => {
|
|
91
|
-
if (name === 'children' || name === 'className' || name === 'forwardedRef' || name === 'ref') return;
|
|
92
|
-
|
|
93
|
-
const value = props[name];
|
|
94
|
-
|
|
95
|
-
if (isEvent(name)) {
|
|
96
|
-
if (typeof document === 'undefined') return;
|
|
97
|
-
|
|
98
|
-
const event = getCustomEvent(name, extra.events);
|
|
99
|
-
|
|
100
|
-
if (event) return;
|
|
101
|
-
|
|
102
|
-
result[name] = value;
|
|
103
|
-
} else if (extra.props.includes(name)) {
|
|
104
|
-
if (!isPrimitive(value)) return;
|
|
105
|
-
|
|
106
|
-
result[paramCase(name)] = value;
|
|
107
|
-
} else {
|
|
108
|
-
result[name] = value;
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
return result;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const mergeRefs =
|
|
116
|
-
<ElementType>(...refs: React.Ref<ElementType>[]) =>
|
|
117
|
-
(value: ElementType) => {
|
|
118
|
-
return refs.forEach((ref) => {
|
|
119
|
-
if (typeof ref === 'function') return ref(value);
|
|
120
|
-
|
|
121
|
-
if (ref == null) return;
|
|
122
|
-
|
|
123
|
-
(ref as Mutable<React.RefObject<ElementType>>).current = value;
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const setClass = <ElementType>(element: ElementType, props: PropsType<ElementType>) => {
|
|
128
|
-
const classes: string[] = [];
|
|
129
|
-
|
|
130
|
-
const current = arrayToMap((element as any).classList);
|
|
131
|
-
|
|
132
|
-
const prev: string = element['$class'];
|
|
133
|
-
const next: string = props.className || (props as any).class;
|
|
134
|
-
|
|
135
|
-
const prevClass = arrayToMap(prev ? prev.split(' ') : []);
|
|
136
|
-
const nextClass = arrayToMap(next ? next.split(' ') : []);
|
|
137
|
-
|
|
138
|
-
current.forEach((key) => {
|
|
139
|
-
if (nextClass.has(key)) {
|
|
140
|
-
classes.push(key);
|
|
141
|
-
|
|
142
|
-
nextClass.delete(key);
|
|
143
|
-
} else if (!prevClass.has(key)) {
|
|
144
|
-
classes.push(key);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
nextClass.forEach((key) => classes.push(key));
|
|
149
|
-
|
|
150
|
-
const className = classes.join(' ');
|
|
151
|
-
|
|
152
|
-
(element as any).className = className;
|
|
153
|
-
|
|
154
|
-
element['$class'] = className;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const setEvent = (element: Element, name: string, handler: EventHandlerType) => {
|
|
158
|
-
const events = element['$events'] || (element['$events'] = {});
|
|
159
|
-
|
|
160
|
-
const previous = events[name];
|
|
161
|
-
|
|
162
|
-
previous && element.removeEventListener(name, previous);
|
|
163
|
-
|
|
164
|
-
function callback(event: Event) {
|
|
165
|
-
handler && handler.call(this, event);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
element.addEventListener(name, (events[name] = callback));
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
172
|
-
if (!(element instanceof Element)) return;
|
|
173
|
-
|
|
174
|
-
setClass<ElementType>(element, props);
|
|
175
|
-
|
|
176
|
-
Object.keys(props).forEach((name) => {
|
|
177
|
-
if (
|
|
178
|
-
name === 'children' ||
|
|
179
|
-
name === 'class' ||
|
|
180
|
-
name === 'className' ||
|
|
181
|
-
name === 'forwardedRef' ||
|
|
182
|
-
name === 'ref' ||
|
|
183
|
-
name === 'style'
|
|
184
|
-
)
|
|
185
|
-
return;
|
|
186
|
-
|
|
187
|
-
const value = props[name];
|
|
188
|
-
|
|
189
|
-
if (isEvent(name)) {
|
|
190
|
-
if (typeof document === 'undefined') return;
|
|
191
|
-
|
|
192
|
-
const event = getCustomEvent(name, extra.events);
|
|
193
|
-
|
|
194
|
-
if (!event) return;
|
|
195
|
-
|
|
196
|
-
setEvent(element, event, value);
|
|
197
|
-
} else if (extra.props.includes(name)) {
|
|
198
|
-
if (isPrimitive(value)) {
|
|
199
|
-
element.setAttribute(paramCase(name), value);
|
|
200
|
-
} else {
|
|
201
|
-
element[name] = value;
|
|
202
|
-
}
|
|
203
|
-
} else {
|
|
204
|
-
element[name] = value;
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
export const proxy = <ElementType, PropType>(
|
|
210
|
-
tagName: string,
|
|
211
|
-
props: Array<string> = [],
|
|
212
|
-
events: Array<string> = []
|
|
213
|
-
) => {
|
|
214
|
-
const extra: ExtraType = {
|
|
215
|
-
props,
|
|
216
|
-
events
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const ReactComponent = class extends React.Component<PropsType<ElementType>> {
|
|
220
|
-
element!: ElementType;
|
|
221
|
-
|
|
222
|
-
setElement = (element: ElementType) => {
|
|
223
|
-
this.element = element;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
constructor(props: PropsType<ElementType>) {
|
|
227
|
-
super(props);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
componentDidMount() {
|
|
231
|
-
this.componentDidUpdate(/*this.props*/);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
componentDidUpdate(/*prevProps: InternalProps<ElementType>*/) {
|
|
235
|
-
setProps<ElementType>(this.element as any, this.props, extra);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
componentWillUnmount() {
|
|
239
|
-
if (!this.element) return;
|
|
240
|
-
|
|
241
|
-
const events = this.element['$events'] || {};
|
|
242
|
-
|
|
243
|
-
Object.keys(events).forEach((name) => {
|
|
244
|
-
const handler = events[name];
|
|
245
|
-
|
|
246
|
-
(this.element as any).removeEventListener(name, handler);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
delete this.element['$events'];
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
render() {
|
|
253
|
-
const { children } = this.props;
|
|
254
|
-
|
|
255
|
-
const props = getProps<ElementType>(this.setElement, this.props, extra);
|
|
256
|
-
|
|
257
|
-
return React.createElement(tagName, props, children);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// TODO
|
|
262
|
-
// const ReactComponentNew = (props: InternalPropsType<ElementType>) => {
|
|
263
|
-
|
|
264
|
-
// const { children } = props;
|
|
265
|
-
|
|
266
|
-
// const ref = useRef(null);
|
|
267
|
-
|
|
268
|
-
// const newProps: FinalPropsType<ElementType> = getProps(ref, props, events);
|
|
269
|
-
|
|
270
|
-
// useEffect(() => setProps(ref.current, props, events));
|
|
271
|
-
|
|
272
|
-
// return React.createElement(tagName, newProps, children);
|
|
273
|
-
// }
|
|
274
|
-
|
|
275
|
-
ReactComponent['displayName'] = pascalCase(tagName);
|
|
276
|
-
|
|
277
|
-
return forwardRef<ElementType, PropType>(ReactComponent);
|
|
278
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"experimentalDecorators": true,
|
|
4
|
-
"declaration": true,
|
|
5
|
-
"declarationDir": "dist",
|
|
6
|
-
"module": "esnext",
|
|
7
|
-
"target": "es5",
|
|
8
|
-
"lib": ["es6", "dom", "es2016", "es2017"],
|
|
9
|
-
"sourceMap": true,
|
|
10
|
-
"jsx": "react",
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"esModuleInterop": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"],
|
|
16
|
-
"exclude": ["dist", "node_modules"]
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import core from 'sass';
|
|
2
|
-
export const sass = (options) => {
|
|
3
|
-
const name = 'sass';
|
|
4
|
-
const next = (context) => {
|
|
5
|
-
if (!context.stylePath)
|
|
6
|
-
return;
|
|
7
|
-
const { css, loadedUrls } = core.compile(context.stylePath, Object.assign(Object.assign({}, (options || {})), { style: 'compressed' }));
|
|
8
|
-
context.styleParsed = css.toString();
|
|
9
|
-
context.styleDependencies = []; // TODO loadedUrls;
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
name,
|
|
13
|
-
next
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import t from '@babel/types';
|
|
2
|
-
import { print, visitor } from '../utils/index.js';
|
|
3
|
-
export const uhtml = () => {
|
|
4
|
-
const name = 'uhtml';
|
|
5
|
-
const next = (context) => {
|
|
6
|
-
context.fileAST.program.body.unshift(t.importDeclaration([t.importSpecifier(t.identifier('html'), t.identifier('html'))], t.stringLiteral('@htmlplus/element/runtime')));
|
|
7
|
-
visitor(context.fileAST, {
|
|
8
|
-
JSXAttribute: {
|
|
9
|
-
exit(path) {
|
|
10
|
-
var _a;
|
|
11
|
-
if (((_a = path.node.value) === null || _a === void 0 ? void 0 : _a.type) == 'JSXExpressionContainer') {
|
|
12
|
-
let node = path.node;
|
|
13
|
-
if (path.node.name.name == 'ref') {
|
|
14
|
-
node = t.jsxAttribute(path.node.name, t.jSXExpressionContainer(t.arrowFunctionExpression([t.identifier('$element')], t.assignmentExpression('=', path.node.value.expression, t.identifier('$element')))));
|
|
15
|
-
}
|
|
16
|
-
path.replaceWith(t.jsxIdentifier(print(node).replace('={', '=${')));
|
|
17
|
-
path.skip();
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
JSXElement: {
|
|
23
|
-
exit(path) {
|
|
24
|
-
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
25
|
-
path.replaceWith(t.identifier(print(path.node)));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
path.replaceWith(t.identifier('html`' + print(path.node) + '`'));
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
JSXFragment: {
|
|
35
|
-
exit(path) {
|
|
36
|
-
path.replaceWith(t.identifier(['html`', ...path.node.children.map((child) => print(child)), '`'].join('')));
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
JSXExpressionContainer: {
|
|
40
|
-
exit(path) {
|
|
41
|
-
if (path.parent.type == 'JSXElement' || path.parent.type == 'JSXFragment') {
|
|
42
|
-
path.replaceWith(t.identifier('$' + print(path.node)));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
JSXSpreadAttribute: {
|
|
48
|
-
enter(path) {
|
|
49
|
-
// TODO
|
|
50
|
-
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('.dataset'), t.jsxExpressionContainer(path.node.argument)));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
name,
|
|
57
|
-
next
|
|
58
|
-
};
|
|
59
|
-
};
|