@htmlplus/element 0.1.4 → 0.1.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/dist/client/decorators/attributes.js +2 -2
- package/dist/client/decorators/element.js +17 -90
- package/dist/client/decorators/listen.js +2 -2
- package/dist/client/decorators/property.js +15 -20
- package/dist/client/decorators/state.js +8 -11
- package/dist/client/decorators/watch.js +1 -1
- package/dist/client/helpers/direction.d.ts +2 -1
- package/dist/client/helpers/is-rtl.d.ts +2 -1
- package/dist/client/helpers/slots.d.ts +2 -1
- package/dist/client/utils/append-to-method.d.ts +2 -1
- package/dist/client/utils/call.d.ts +2 -0
- package/dist/client/utils/call.js +4 -0
- package/dist/client/utils/get-members.d.ts +2 -0
- package/dist/client/utils/get-members.js +5 -0
- package/dist/client/utils/get-styles.d.ts +2 -0
- package/dist/client/utils/get-styles.js +5 -0
- package/dist/client/utils/host.d.ts +2 -1
- package/dist/client/utils/host.js +4 -2
- package/dist/client/utils/index.d.ts +6 -1
- package/dist/client/utils/index.js +6 -1
- package/dist/client/utils/on-ready.d.ts +2 -1
- package/dist/client/utils/on-ready.js +3 -1
- package/dist/client/utils/render.d.ts +2 -0
- package/dist/client/utils/render.js +17 -0
- package/dist/client/utils/request.d.ts +2 -0
- package/dist/client/utils/request.js +25 -0
- package/dist/client/utils/task.d.ts +6 -0
- package/dist/client/utils/task.js +46 -0
- package/dist/client/utils/type-of.d.ts +2 -2
- package/dist/compiler/plugins/attach.js +23 -15
- package/dist/compiler/plugins/extract.js +8 -8
- package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +5 -3
- package/dist/compiler/plugins/react.proxy/react.proxy.js +106 -45
- package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +3 -2
- package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +7 -6
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +15 -1
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs +18 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +17 -29
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +4 -3
- package/dist/compiler/plugins/uhtml.js +6 -0
- package/dist/compiler/utils/is-directory-empty.d.ts +1 -1
- package/dist/compiler/utils/is-directory-empty.js +3 -12
- package/dist/configs/constants.d.ts +17 -18
- package/dist/configs/constants.js +17 -18
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +4 -1
- package/package.json +4 -1
- package/dist/client/utils/api.d.ts +0 -6
- package/dist/client/utils/api.js +0 -2
- package/dist/client/utils/proxy.d.ts +0 -4
- package/dist/client/utils/proxy.js +0 -124
|
@@ -1,58 +1,119 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
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
|
+
};
|
|
11
13
|
export const reactProxy = (options) => {
|
|
12
14
|
const name = 'react-proxy';
|
|
13
|
-
const finish = (global) =>
|
|
15
|
+
const finish = (global) => {
|
|
16
|
+
options = Object.assign(Object.assign({}, defaults), options);
|
|
17
|
+
global = Object.assign(Object.assign({}, global), { options });
|
|
14
18
|
const config = { cwd: __dirname(import.meta.url) };
|
|
15
|
-
const
|
|
16
|
-
global = Object.assign({}, global, { options });
|
|
19
|
+
const isEmpty = isDirectoryEmpty(options.dist);
|
|
17
20
|
const skip = [];
|
|
18
21
|
const getKey = (component) => component.componentClassName;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return true;
|
|
31
|
-
})
|
|
32
|
-
.map((group) => {
|
|
33
|
-
const root = group.components.find((component) => getKey(component) == group.key);
|
|
34
|
-
const all = group.components
|
|
35
|
-
.map((component) => (Object.assign(Object.assign({}, component), { componentClassNameInCategory: getKey(component).replace(group.key, '') })))
|
|
36
|
-
.reverse();
|
|
37
|
-
const filterd = all.filter((component) => getKey(component) != group.key);
|
|
38
|
-
return {
|
|
39
|
-
single: !filterd.length,
|
|
40
|
-
root,
|
|
41
|
-
all,
|
|
42
|
-
filterd
|
|
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
|
+
};
|
|
43
33
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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);
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
}
|
|
51
103
|
}
|
|
52
|
-
|
|
53
|
-
|
|
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);
|
|
54
111
|
}
|
|
55
|
-
|
|
112
|
+
if (!isEmpty) {
|
|
113
|
+
const patterns = ['templates/src/proxy*', 'templates/src/components/index*'];
|
|
114
|
+
renderTemplate(patterns, options.dist, config)(global);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
56
117
|
return {
|
|
57
118
|
name,
|
|
58
119
|
finish
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "YOUR_REACT_PACKAGE_NAME",
|
|
3
3
|
"version": "0.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React output target for your custom element.",
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"
|
|
17
|
+
"YOUR_CORE_PACKAGE_NAME": "latest",
|
|
18
18
|
"change-case": "^4.1.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@rollup/plugin-commonjs": "^15.0.0",
|
|
22
22
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
|
23
23
|
"@types/react": "^16.9.49",
|
|
24
|
+
"glob": "^7.2.0",
|
|
24
25
|
"react": "^17.0.1",
|
|
25
26
|
"react-dom": "^17.0.1",
|
|
26
27
|
"rimraf": "^3.0.2",
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import commonjs from '@rollup/plugin-commonjs';
|
|
2
2
|
import resolve from '@rollup/plugin-node-resolve';
|
|
3
|
+
import glob from 'glob';
|
|
3
4
|
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
|
|
4
5
|
import typescript from 'rollup-plugin-typescript2';
|
|
5
6
|
|
|
6
7
|
export default {
|
|
7
|
-
input: 'src
|
|
8
|
+
input: glob.sync('src/**/*.ts'),
|
|
8
9
|
output: [
|
|
9
10
|
{
|
|
10
|
-
dir: 'dist
|
|
11
|
-
format: 'esm'
|
|
12
|
-
}
|
|
11
|
+
dir: 'dist',
|
|
12
|
+
format: 'esm',
|
|
13
|
+
},
|
|
13
14
|
],
|
|
14
15
|
plugins: [
|
|
15
16
|
peerDepsExternal(),
|
|
16
17
|
resolve(),
|
|
17
18
|
commonjs(),
|
|
18
|
-
typescript()
|
|
19
|
-
]
|
|
19
|
+
typescript(),
|
|
20
|
+
],
|
|
20
21
|
};
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**************************************************
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
3
|
+
**************************************************/
|
|
4
|
+
|
|
5
|
+
{{#if options.compact}}
|
|
1
6
|
{{#each groups}}
|
|
7
|
+
{{#if single}}
|
|
2
8
|
export * from './{{root.fileName}}';
|
|
3
|
-
{{
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
|
|
4
|
+
/**************************************************
|
|
5
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
|
+
**************************************************/
|
|
7
|
+
|
|
8
|
+
{{#each all}}
|
|
9
|
+
import { {{componentClassName}} } from './{{fileName}}';
|
|
10
|
+
{{/each}}
|
|
11
|
+
|
|
12
|
+
const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
|
|
13
|
+
{{#each filterd}}
|
|
14
|
+
{{componentClassNameInCategory}}: {{componentClassName}},
|
|
15
|
+
{{/each}}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export { All as {{root.componentClassName}} }
|
|
@@ -1,38 +1,26 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
/* tslint:disable */
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**************************************************
|
|
5
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
|
+
**************************************************/
|
|
4
7
|
|
|
5
8
|
import { proxy } from '../proxy';
|
|
6
|
-
import type { JSX } from '{{options.corePackageName}}';
|
|
7
9
|
|
|
8
|
-
{{
|
|
9
|
-
import
|
|
10
|
-
{{
|
|
10
|
+
{{!-- import { {{importerComponent.root}} as Component } from '{{importerComponent.source}}'; --}}
|
|
11
|
+
import '{{importerComponent.source}}';
|
|
12
|
+
import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
|
|
11
13
|
|
|
12
|
-
{{
|
|
13
|
-
const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, JSX.{{componentClassName}}>(
|
|
14
|
-
'{{componentTag}}',
|
|
15
|
-
[
|
|
16
|
-
{{#each classProperties}}
|
|
17
|
-
'{{key.name}}',
|
|
18
|
-
{{/each}}
|
|
19
|
-
],
|
|
20
|
-
[
|
|
21
|
-
{{#each classEvents}}
|
|
22
|
-
'{{key.name}}',
|
|
23
|
-
{{/each}}
|
|
24
|
-
],
|
|
25
|
-
);
|
|
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] }
|
|
26
15
|
|
|
27
|
-
{{
|
|
28
|
-
{{#
|
|
29
|
-
|
|
30
|
-
{{else}}
|
|
31
|
-
const All = /*@__PURE__*/ Object.assign({{root.componentClassName}}, {
|
|
32
|
-
{{#each filterd}}
|
|
33
|
-
{{componentClassNameInCategory}}: {{componentClassName}},
|
|
16
|
+
type Renamed = Rename<{{importerComponentType.variable}}, {
|
|
17
|
+
{{#each classEvents}}
|
|
18
|
+
{{key.name}}: '{{converted}}',
|
|
34
19
|
{{/each}}
|
|
35
|
-
}
|
|
20
|
+
}>
|
|
36
21
|
|
|
37
|
-
export {
|
|
38
|
-
{{
|
|
22
|
+
export const {{componentClassName}} = /*@__PURE__*/ proxy<{{componentInterfaceName}}, Renamed>(
|
|
23
|
+
'{{componentTag}}',
|
|
24
|
+
[{{#each classProperties}}'{{key.name}}', {{/each}}],
|
|
25
|
+
[{{#each classEvents}}'{{key.name}}', {{/each}}],
|
|
26
|
+
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
1
|
+
/**************************************************
|
|
2
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
3
|
+
**************************************************/
|
|
4
|
+
|
|
4
5
|
import { camelCase, paramCase, pascalCase } from 'change-case';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isDirectoryEmpty: (directory: string) =>
|
|
1
|
+
export declare const isDirectoryEmpty: (directory: string) => boolean;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import fs from 'fs';
|
|
11
|
-
export const isDirectoryEmpty = (directory) =>
|
|
2
|
+
export const isDirectoryEmpty = (directory) => {
|
|
12
3
|
try {
|
|
13
|
-
const files =
|
|
4
|
+
const files = fs.readdirSync(directory);
|
|
14
5
|
return !files.length;
|
|
15
6
|
}
|
|
16
7
|
catch (_a) {
|
|
17
8
|
return true;
|
|
18
9
|
}
|
|
19
|
-
}
|
|
10
|
+
};
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const TOKEN_STATIC_STYLES = "styles";
|
|
1
|
+
export declare const API_HOST = "$host$";
|
|
2
|
+
export declare const API_READY = "$ready$";
|
|
3
|
+
export declare const API_SETUP = "$setup$";
|
|
4
|
+
export declare const DECORATOR_ELEMENT = "Element";
|
|
5
|
+
export declare const DECORATOR_EVENT = "Event";
|
|
6
|
+
export declare const DECORATOR_PROPERTY = "Property";
|
|
7
|
+
export declare const DECORATOR_STATE = "State";
|
|
8
|
+
export declare const DECORATOR_METHOD = "Method";
|
|
9
|
+
export declare const LIFECYCLE_ADOPTED = "adoptedCallback";
|
|
10
|
+
export declare const LIFECYCLE_CONNECTED = "connectedCallback";
|
|
11
|
+
export declare const LIFECYCLE_DISCONNECTED = "disconnectedCallback";
|
|
12
|
+
export declare const LIFECYCLE_LOADED = "loadedCallback";
|
|
13
|
+
export declare const LIFECYCLE_UPDATE = "updateCallback";
|
|
14
|
+
export declare const LIFECYCLE_UPDATED = "updatedCallback";
|
|
15
|
+
export declare const METHOD_RENDER = "render";
|
|
16
|
+
export declare const STATIC_MEMBERS = "members";
|
|
17
|
+
export declare const STATIC_STYLES = "styles";
|
|
19
18
|
export declare const TYPE_BOOLEAN = "boolean";
|
|
20
19
|
export declare const TYPE_DATE = "date";
|
|
21
20
|
export declare const TYPE_FUNCTION = "function";
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
// apis
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const TOKEN_API_REQUEST = 'request';
|
|
2
|
+
export const API_HOST = '$host$';
|
|
3
|
+
export const API_READY = '$ready$';
|
|
4
|
+
export const API_SETUP = '$setup$';
|
|
6
5
|
// decorators
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
9
|
-
export const
|
|
10
|
-
export const
|
|
11
|
-
export const
|
|
6
|
+
export const DECORATOR_ELEMENT = 'Element';
|
|
7
|
+
export const DECORATOR_EVENT = 'Event';
|
|
8
|
+
export const DECORATOR_PROPERTY = 'Property';
|
|
9
|
+
export const DECORATOR_STATE = 'State';
|
|
10
|
+
export const DECORATOR_METHOD = 'Method';
|
|
12
11
|
// lifecycle
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
17
|
-
export const
|
|
18
|
-
export const
|
|
12
|
+
export const LIFECYCLE_ADOPTED = 'adoptedCallback';
|
|
13
|
+
export const LIFECYCLE_CONNECTED = 'connectedCallback';
|
|
14
|
+
export const LIFECYCLE_DISCONNECTED = 'disconnectedCallback';
|
|
15
|
+
export const LIFECYCLE_LOADED = 'loadedCallback';
|
|
16
|
+
export const LIFECYCLE_UPDATE = 'updateCallback';
|
|
17
|
+
export const LIFECYCLE_UPDATED = 'updatedCallback';
|
|
19
18
|
// methods
|
|
20
|
-
export const
|
|
19
|
+
export const METHOD_RENDER = 'render';
|
|
21
20
|
// statics
|
|
22
|
-
export const
|
|
23
|
-
export const
|
|
21
|
+
export const STATIC_MEMBERS = 'members';
|
|
22
|
+
export const STATIC_STYLES = 'styles';
|
|
24
23
|
// types
|
|
25
24
|
export const TYPE_BOOLEAN = 'boolean';
|
|
26
25
|
export const TYPE_DATE = 'date';
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const html: (template: any, ...values: any[]) => any;
|
package/dist/runtime/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
+
"prebuild": "npm run clean",
|
|
9
10
|
"build": "tsc",
|
|
10
11
|
"build:watch": "tsc -w",
|
|
11
12
|
"postbuild": "node scripts/build.post.js",
|
|
13
|
+
"clean": "rimraf dist",
|
|
12
14
|
"format": "prettier --write .",
|
|
13
15
|
"dev:start": "node src/dev/start.js",
|
|
14
16
|
"dev:build": "node src/dev/build.js"
|
|
@@ -91,6 +93,7 @@
|
|
|
91
93
|
"@trivago/prettier-plugin-sort-imports": "^3.1.1",
|
|
92
94
|
"cpy": "^9.0.0",
|
|
93
95
|
"prettier": "^2.5.0",
|
|
96
|
+
"rimraf": "^3.0.2",
|
|
94
97
|
"vite": "^2.7.10"
|
|
95
98
|
}
|
|
96
99
|
}
|
package/dist/client/utils/api.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { html, render } from 'uhtml';
|
|
11
|
-
import * as CONSTANTS from '../../configs/constants.js';
|
|
12
|
-
import { isServer } from './is-server.js';
|
|
13
|
-
import { parseValue } from './parse-value.js';
|
|
14
|
-
// TODO: input type
|
|
15
|
-
export const proxy = (Class) => {
|
|
16
|
-
if (isServer())
|
|
17
|
-
return class {
|
|
18
|
-
};
|
|
19
|
-
let host, instance;
|
|
20
|
-
const members = Class[CONSTANTS.TOKEN_STATIC_MEMBERS] || {};
|
|
21
|
-
// TODO
|
|
22
|
-
let states;
|
|
23
|
-
let isPending = false;
|
|
24
|
-
let updatePromise;
|
|
25
|
-
const request = (state) => {
|
|
26
|
-
if (!true /*hasChange*/)
|
|
27
|
-
return;
|
|
28
|
-
states = Object.assign(Object.assign({}, (states || {})), state);
|
|
29
|
-
if (isPending)
|
|
30
|
-
return;
|
|
31
|
-
updatePromise = enqueue();
|
|
32
|
-
};
|
|
33
|
-
const enqueue = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
isPending = true;
|
|
35
|
-
try {
|
|
36
|
-
yield updatePromise;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
Promise.reject(error);
|
|
40
|
-
}
|
|
41
|
-
const result = perform();
|
|
42
|
-
if (result != null)
|
|
43
|
-
yield result;
|
|
44
|
-
return !isPending;
|
|
45
|
-
});
|
|
46
|
-
const perform = () => {
|
|
47
|
-
if (!isPending)
|
|
48
|
-
return;
|
|
49
|
-
try {
|
|
50
|
-
if (true /*shouldUpdate*/) {
|
|
51
|
-
// TODO
|
|
52
|
-
// call(CONSTANTS.TOKEN_LIFECYCLE_UPDATE, [allStates]);
|
|
53
|
-
render(host.shadowRoot, () => {
|
|
54
|
-
const markup = call(CONSTANTS.TOKEN_METHOD_RENDER);
|
|
55
|
-
const styles = Class[CONSTANTS.TOKEN_STATIC_STYLES];
|
|
56
|
-
if (!styles && !markup)
|
|
57
|
-
return html ``;
|
|
58
|
-
if (!styles)
|
|
59
|
-
return markup;
|
|
60
|
-
if (!markup)
|
|
61
|
-
return html `<style>${styles}</style>`;
|
|
62
|
-
return html `<style>${styles}</style>${markup}`;
|
|
63
|
-
});
|
|
64
|
-
// TODO
|
|
65
|
-
call(CONSTANTS.TOKEN_LIFECYCLE_UPDATED, [states]);
|
|
66
|
-
states = undefined;
|
|
67
|
-
}
|
|
68
|
-
isPending = false;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
isPending = false;
|
|
72
|
-
throw error;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const call = (key, args) => {
|
|
76
|
-
var _a;
|
|
77
|
-
return (_a = instance[key]) === null || _a === void 0 ? void 0 : _a.apply(instance, args);
|
|
78
|
-
};
|
|
79
|
-
const get = (key) => {
|
|
80
|
-
return instance[CONSTANTS.TOKEN_API][key];
|
|
81
|
-
};
|
|
82
|
-
const set = (key, value) => {
|
|
83
|
-
instance[CONSTANTS.TOKEN_API][key] = value;
|
|
84
|
-
};
|
|
85
|
-
return class extends HTMLElement {
|
|
86
|
-
constructor() {
|
|
87
|
-
var _a, _b;
|
|
88
|
-
var _c;
|
|
89
|
-
super();
|
|
90
|
-
host = this;
|
|
91
|
-
// TODO
|
|
92
|
-
instance = new Class();
|
|
93
|
-
(_a = instance[_c = CONSTANTS.TOKEN_API]) !== null && _a !== void 0 ? _a : (instance[_c] = {});
|
|
94
|
-
set(CONSTANTS.TOKEN_API_HOST, () => host);
|
|
95
|
-
set(CONSTANTS.TOKEN_API_REQUEST, request);
|
|
96
|
-
// TODO
|
|
97
|
-
(_b = instance.setup) === null || _b === void 0 ? void 0 : _b.forEach((setup) => setup.bind(instance)());
|
|
98
|
-
this.attachShadow({ mode: 'open' });
|
|
99
|
-
}
|
|
100
|
-
static get observedAttributes() {
|
|
101
|
-
return Object.keys(members).filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION);
|
|
102
|
-
}
|
|
103
|
-
adoptedCallback() {
|
|
104
|
-
call(CONSTANTS.TOKEN_LIFECYCLE_ADOPTED);
|
|
105
|
-
}
|
|
106
|
-
attributeChangedCallback(name, prev, next) {
|
|
107
|
-
const [type] = members[name];
|
|
108
|
-
instance[name] = parseValue(next, type);
|
|
109
|
-
if (!get(CONSTANTS.TOKEN_API_READY))
|
|
110
|
-
return;
|
|
111
|
-
request();
|
|
112
|
-
}
|
|
113
|
-
connectedCallback() {
|
|
114
|
-
call(CONSTANTS.TOKEN_LIFECYCLE_CONNECTED);
|
|
115
|
-
request();
|
|
116
|
-
// TODO
|
|
117
|
-
setTimeout(() => call(CONSTANTS.TOKEN_LIFECYCLE_LOADED));
|
|
118
|
-
set(CONSTANTS.TOKEN_API_READY, true);
|
|
119
|
-
}
|
|
120
|
-
disconnectedCallback() {
|
|
121
|
-
call(CONSTANTS.TOKEN_LIFECYCLE_DISCONNECTED);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
};
|