@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
|
@@ -3,10 +3,10 @@ import { appendToMethod, host, sync } from '../utils/index.js';
|
|
|
3
3
|
export function Attributes() {
|
|
4
4
|
return function (target, propertyKey) {
|
|
5
5
|
let update;
|
|
6
|
-
appendToMethod(target, CONSTANTS.
|
|
6
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
7
7
|
update = sync(host(this));
|
|
8
8
|
});
|
|
9
|
-
appendToMethod(target, CONSTANTS.
|
|
9
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
|
|
10
10
|
update(this[propertyKey]);
|
|
11
11
|
});
|
|
12
12
|
};
|
|
@@ -1,119 +1,46 @@
|
|
|
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
1
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
12
|
-
import { isServer, parseValue } from '../utils/index.js';
|
|
2
|
+
import { call, isServer, parseValue, request } from '../utils/index.js';
|
|
13
3
|
export function Element(tag) {
|
|
14
4
|
return function (constructor) {
|
|
15
5
|
if (isServer())
|
|
16
6
|
return;
|
|
17
|
-
const members = constructor[CONSTANTS.
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
const members = constructor[CONSTANTS.STATIC_MEMBERS];
|
|
8
|
+
console.log(111, { constructor });
|
|
9
|
+
class Plus extends HTMLElement {
|
|
20
10
|
constructor() {
|
|
21
|
-
var _a
|
|
22
|
-
var _c, _d;
|
|
11
|
+
var _a;
|
|
23
12
|
super();
|
|
24
|
-
// TODO
|
|
25
13
|
this.plus = new constructor();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const request = (state) => {
|
|
29
|
-
if (!true /*hasChange*/)
|
|
30
|
-
return Promise.resolve(false);
|
|
31
|
-
states = Object.assign(Object.assign({}, (states || {})), state);
|
|
32
|
-
if (!isPending)
|
|
33
|
-
updatePromise = enqueue();
|
|
34
|
-
return updatePromise;
|
|
35
|
-
};
|
|
36
|
-
const enqueue = () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
var _e;
|
|
38
|
-
isPending = true;
|
|
39
|
-
try {
|
|
40
|
-
yield updatePromise;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
Promise.reject(error);
|
|
44
|
-
}
|
|
45
|
-
// TODO: may be not used
|
|
46
|
-
if (!isPending)
|
|
47
|
-
return updatePromise;
|
|
48
|
-
try {
|
|
49
|
-
if (!true /*shouldUpdate*/)
|
|
50
|
-
return (isPending = false);
|
|
51
|
-
console.log('render');
|
|
52
|
-
// TODO
|
|
53
|
-
// call(CONSTANTS.TOKEN_LIFECYCLE_UPDATE, [allStates]);
|
|
54
|
-
render(this.shadowRoot, () => {
|
|
55
|
-
var _a;
|
|
56
|
-
const markup = (_a = this.plus[CONSTANTS.TOKEN_METHOD_RENDER]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
57
|
-
if (!styles && !markup)
|
|
58
|
-
return html ``;
|
|
59
|
-
if (!styles)
|
|
60
|
-
return markup;
|
|
61
|
-
if (!markup)
|
|
62
|
-
return html `<style>${styles}</style>`;
|
|
63
|
-
return html `<style>${styles}</style>${markup}`;
|
|
64
|
-
});
|
|
65
|
-
// TODO
|
|
66
|
-
(_e = this.plus[CONSTANTS.TOKEN_LIFECYCLE_UPDATED]) === null || _e === void 0 ? void 0 : _e.call(this.plus, states);
|
|
67
|
-
states = undefined;
|
|
68
|
-
isPending = false;
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
isPending = false;
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
(_a = (_c = this.plus)[_d = CONSTANTS.TOKEN_API]) !== null && _a !== void 0 ? _a : (_c[_d] = {
|
|
77
|
-
[CONSTANTS.TOKEN_API_HOST]: () => this,
|
|
78
|
-
[CONSTANTS.TOKEN_API_REQUEST]: request
|
|
79
|
-
});
|
|
80
|
-
// TODO
|
|
81
|
-
(_b = this.plus.setup) === null || _b === void 0 ? void 0 : _b.forEach((setup) => setup.call(this.plus));
|
|
14
|
+
this.plus[CONSTANTS.API_HOST] = () => this;
|
|
15
|
+
(_a = this.plus[CONSTANTS.API_SETUP]) === null || _a === void 0 ? void 0 : _a.forEach((setup) => setup.call(this.plus));
|
|
82
16
|
this.attachShadow({ mode: 'open' });
|
|
83
17
|
}
|
|
84
18
|
static get observedAttributes() {
|
|
85
19
|
return Object.keys(members).filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION);
|
|
86
20
|
}
|
|
87
21
|
adoptedCallback() {
|
|
88
|
-
|
|
89
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_ADOPTED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
22
|
+
call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
|
|
90
23
|
}
|
|
91
24
|
attributeChangedCallback(name, prev, next) {
|
|
92
25
|
const [type] = members[name];
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return;
|
|
96
|
-
this.plus[CONSTANTS.TOKEN_API][CONSTANTS.TOKEN_API_REQUEST]().catch((error) => {
|
|
97
|
-
throw error;
|
|
98
|
-
});
|
|
26
|
+
const parsed = parseValue(next, type);
|
|
27
|
+
this.plus[name] = parsed;
|
|
99
28
|
}
|
|
100
29
|
connectedCallback() {
|
|
101
|
-
|
|
102
|
-
(
|
|
103
|
-
this.plus
|
|
30
|
+
this.plus[CONSTANTS.API_READY] = true;
|
|
31
|
+
call(this.plus, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
32
|
+
request(this.plus)
|
|
104
33
|
.then(() => {
|
|
105
|
-
|
|
106
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_LOADED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
34
|
+
call(this.plus, CONSTANTS.LIFECYCLE_LOADED);
|
|
107
35
|
})
|
|
108
36
|
.catch((error) => {
|
|
109
37
|
throw error;
|
|
110
38
|
});
|
|
111
|
-
this.plus[CONSTANTS.TOKEN_API][CONSTANTS.TOKEN_API_READY] = true;
|
|
112
39
|
}
|
|
113
40
|
disconnectedCallback() {
|
|
114
|
-
|
|
115
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_DISCONNECTED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
41
|
+
call(this.plus, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
116
42
|
}
|
|
117
|
-
}
|
|
43
|
+
}
|
|
44
|
+
customElements.define(tag, Plus);
|
|
118
45
|
};
|
|
119
46
|
}
|
|
@@ -19,10 +19,10 @@ export function Listen(name, options = defaults) {
|
|
|
19
19
|
return host(instance);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
appendToMethod(target, CONSTANTS.
|
|
22
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
23
23
|
on(element(this), name, this[propertyKey], options);
|
|
24
24
|
});
|
|
25
|
-
appendToMethod(target, CONSTANTS.
|
|
25
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
26
26
|
off(element(this), name, this[propertyKey], options);
|
|
27
27
|
});
|
|
28
28
|
return Bind()(target, propertyKey, descriptor);
|
|
@@ -1,39 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { api, defineProperty, host, onReady, parseValue, updateAttribute } from '../utils/index.js';
|
|
1
|
+
import { defineProperty, getMembers, host, parseValue, request, updateAttribute, onReady } from '../utils/index.js';
|
|
3
2
|
export function Property(options) {
|
|
4
3
|
return function (target, propertyKey) {
|
|
5
|
-
|
|
4
|
+
const values = new Map();
|
|
6
5
|
defineProperty(target, propertyKey, {
|
|
7
6
|
get() {
|
|
8
|
-
return
|
|
7
|
+
return values.get(this);
|
|
9
8
|
},
|
|
10
9
|
set(input) {
|
|
11
|
-
|
|
12
|
-
if (
|
|
10
|
+
const value = values.get(this);
|
|
11
|
+
if (value === input)
|
|
13
12
|
return;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return;
|
|
17
|
-
const element = host(this);
|
|
18
|
-
const name = String(propertyKey);
|
|
19
|
-
const raw = element.getAttribute(name);
|
|
20
|
-
const [type] = target.constructor[CONSTANTS.TOKEN_STATIC_MEMBERS][propertyKey];
|
|
21
|
-
const parsed = parseValue(raw, type);
|
|
22
|
-
if (parsed === next)
|
|
23
|
-
return;
|
|
24
|
-
api(this)
|
|
25
|
-
.request({ [propertyKey]: [next, prev] })
|
|
13
|
+
values.set(this, input);
|
|
14
|
+
request(this, { [propertyKey]: [input, value] })
|
|
26
15
|
.then((renderd) => {
|
|
27
16
|
if (!renderd)
|
|
28
17
|
return;
|
|
29
18
|
if (!(options === null || options === void 0 ? void 0 : options.reflect))
|
|
30
19
|
return;
|
|
31
|
-
|
|
20
|
+
const element = host(this);
|
|
21
|
+
const name = String(propertyKey);
|
|
22
|
+
const raw = element.getAttribute(name);
|
|
23
|
+
const [type] = getMembers(target)[propertyKey];
|
|
24
|
+
const parsed = parseValue(raw, type);
|
|
25
|
+
if (parsed === input)
|
|
26
|
+
return;
|
|
27
|
+
updateAttribute(element, name, input);
|
|
32
28
|
})
|
|
33
29
|
.catch((error) => {
|
|
34
30
|
throw error;
|
|
35
31
|
});
|
|
36
|
-
prev = next;
|
|
37
32
|
}
|
|
38
33
|
});
|
|
39
34
|
onReady(target, function () {
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineProperty, host, onReady, request } from '../utils/index.js';
|
|
2
2
|
export function State() {
|
|
3
3
|
return function (target, propertyKey) {
|
|
4
|
-
|
|
4
|
+
const values = new Map();
|
|
5
5
|
defineProperty(target, propertyKey, {
|
|
6
6
|
get() {
|
|
7
|
-
return
|
|
7
|
+
return values.get(this);
|
|
8
8
|
},
|
|
9
9
|
set(input) {
|
|
10
|
-
|
|
11
|
-
if (
|
|
10
|
+
const value = values.get(this);
|
|
11
|
+
if (value === input)
|
|
12
12
|
return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
api(this)
|
|
17
|
-
.request({ [propertyKey]: [next, prev] })
|
|
13
|
+
values.set(this, input);
|
|
14
|
+
request(this, { [propertyKey]: [input, value] })
|
|
15
|
+
.then(() => { })
|
|
18
16
|
.catch((error) => {
|
|
19
17
|
throw error;
|
|
20
18
|
});
|
|
21
|
-
prev = next;
|
|
22
19
|
}
|
|
23
20
|
});
|
|
24
21
|
onReady(target, function () {
|
|
@@ -5,7 +5,7 @@ export function Watch(...keys) {
|
|
|
5
5
|
return function (target, propertyKey) {
|
|
6
6
|
if (!keys.length)
|
|
7
7
|
return;
|
|
8
|
-
appendToMethod(target, CONSTANTS.
|
|
8
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function (args) {
|
|
9
9
|
const [states] = args;
|
|
10
10
|
for (const key of keys) {
|
|
11
11
|
if (states === null || states === void 0 ? void 0 : states[key]) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export declare const isRTL: (target: PlusElement) => boolean;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export declare const appendToMethod: (target: PlusElement, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export declare const host: (target: PlusElement) => HTMLElement;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
export * from './api.js';
|
|
2
1
|
export * from './append-to-method.js';
|
|
2
|
+
export * from './call.js';
|
|
3
3
|
export * from './define-property.js';
|
|
4
4
|
export * from './event.js';
|
|
5
|
+
export * from './get-members.js';
|
|
6
|
+
export * from './get-styles.js';
|
|
5
7
|
export * from './host.js';
|
|
6
8
|
export * from './is-event.js';
|
|
7
9
|
export * from './is-server.js';
|
|
8
10
|
export * from './on-ready.js';
|
|
9
11
|
export * from './parse-value.js';
|
|
12
|
+
export * from './render.js';
|
|
13
|
+
export * from './request.js';
|
|
10
14
|
export * from './sync.js';
|
|
15
|
+
export * from './task.js';
|
|
11
16
|
export * from './to-boolean.js';
|
|
12
17
|
export * from './to-event.js';
|
|
13
18
|
export * from './type-of.js';
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
export * from './api.js';
|
|
2
1
|
export * from './append-to-method.js';
|
|
2
|
+
export * from './call.js';
|
|
3
3
|
export * from './define-property.js';
|
|
4
4
|
export * from './event.js';
|
|
5
|
+
export * from './get-members.js';
|
|
6
|
+
export * from './get-styles.js';
|
|
5
7
|
export * from './host.js';
|
|
6
8
|
export * from './is-event.js';
|
|
7
9
|
export * from './is-server.js';
|
|
8
10
|
export * from './on-ready.js';
|
|
9
11
|
export * from './parse-value.js';
|
|
12
|
+
export * from './render.js';
|
|
13
|
+
export * from './request.js';
|
|
10
14
|
export * from './sync.js';
|
|
15
|
+
export * from './task.js';
|
|
11
16
|
export * from './to-boolean.js';
|
|
12
17
|
export * from './to-event.js';
|
|
13
18
|
export * from './type-of.js';
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { PlusElement } from '../../types/index.js';
|
|
2
|
+
export declare function onReady(target: PlusElement, callback: (this: any) => void): void;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../configs/constants.js';
|
|
1
2
|
export function onReady(target, callback) {
|
|
2
3
|
var _a;
|
|
3
|
-
|
|
4
|
+
var _b;
|
|
5
|
+
((_a = target[_b = CONSTANTS.API_SETUP]) !== null && _a !== void 0 ? _a : (target[_b] = [])).push(callback);
|
|
4
6
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { html, render as renderer } from 'uhtml';
|
|
2
|
+
import * as CONSTANTS from '../../configs/constants.js';
|
|
3
|
+
import { call, getStyles, host } from '../utils/index.js';
|
|
4
|
+
export const render = (target) => {
|
|
5
|
+
const element = host(target);
|
|
6
|
+
renderer(element.shadowRoot, () => {
|
|
7
|
+
const markup = call(target, CONSTANTS.METHOD_RENDER);
|
|
8
|
+
const styles = getStyles(target);
|
|
9
|
+
if (!styles && !markup)
|
|
10
|
+
return html ``;
|
|
11
|
+
if (!styles)
|
|
12
|
+
return markup;
|
|
13
|
+
if (!markup)
|
|
14
|
+
return html `<style>${styles}</style>`;
|
|
15
|
+
return html `<style>${styles}</style>${markup}`;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
+
import { call, render, task } from '../utils/index.js';
|
|
3
|
+
const targets = new Map();
|
|
4
|
+
export const request = (target, state) => {
|
|
5
|
+
if (!target[CONSTANTS.API_READY])
|
|
6
|
+
return Promise.resolve(false);
|
|
7
|
+
let run = targets.get(target);
|
|
8
|
+
if (run)
|
|
9
|
+
return run(state);
|
|
10
|
+
run = task({
|
|
11
|
+
canStart: (states, state) => {
|
|
12
|
+
return /* hasChange */ true;
|
|
13
|
+
},
|
|
14
|
+
canRun: (states) => {
|
|
15
|
+
return /* shouldUpdate */ true;
|
|
16
|
+
},
|
|
17
|
+
run: (states) => {
|
|
18
|
+
call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
|
|
19
|
+
render(target);
|
|
20
|
+
call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
targets.set(target, run);
|
|
24
|
+
return run(state);
|
|
25
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
export const task = (options) => {
|
|
11
|
+
let states, isPending, updatePromise;
|
|
12
|
+
const run = (state) => {
|
|
13
|
+
const newStates = Object.assign({}, states, state);
|
|
14
|
+
if (options.canStart && !options.canStart(newStates, state))
|
|
15
|
+
return Promise.resolve(false);
|
|
16
|
+
states = newStates;
|
|
17
|
+
if (!isPending)
|
|
18
|
+
updatePromise = enqueue();
|
|
19
|
+
return updatePromise;
|
|
20
|
+
};
|
|
21
|
+
const enqueue = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
isPending = true;
|
|
23
|
+
try {
|
|
24
|
+
yield updatePromise;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
Promise.reject(error);
|
|
28
|
+
}
|
|
29
|
+
// TODO: maybe is optional
|
|
30
|
+
if (!isPending)
|
|
31
|
+
return updatePromise;
|
|
32
|
+
try {
|
|
33
|
+
if (options.canRun && !options.canRun(states))
|
|
34
|
+
return (isPending = false);
|
|
35
|
+
options.run(states);
|
|
36
|
+
states = undefined;
|
|
37
|
+
isPending = false;
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
isPending = false;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return run;
|
|
46
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare type
|
|
2
|
-
export declare const typeOf: (input: any) =>
|
|
1
|
+
declare type Types = 'array' | 'boolean' | 'function' | 'number' | 'object' | 'string';
|
|
2
|
+
export declare const typeOf: (input: any) => Types;
|
|
3
3
|
export {};
|
|
@@ -15,9 +15,9 @@ export const attach = (options) => {
|
|
|
15
15
|
if (options.dependencies) {
|
|
16
16
|
}
|
|
17
17
|
if (options.styles && context.styleParsed)
|
|
18
|
-
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.
|
|
18
|
+
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_STYLES), t.stringLiteral(context.styleParsed), undefined, null, undefined, true));
|
|
19
19
|
if (options.members) {
|
|
20
|
-
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.
|
|
20
|
+
context.class.body.body.unshift(t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
|
|
21
21
|
...context.classProperties.map((property) => {
|
|
22
22
|
var _a, _b;
|
|
23
23
|
const type = (_b = (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type;
|
|
@@ -64,24 +64,32 @@ export const attach = (options) => {
|
|
|
64
64
|
]))
|
|
65
65
|
}))
|
|
66
66
|
]),
|
|
67
|
-
t.tsInterfaceDeclaration(t.identifier(context.componentClassName), null, [], t.tsInterfaceBody([
|
|
68
|
-
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
69
|
-
optional: property.optional,
|
|
70
|
-
leadingComments: property.leadingComments
|
|
71
|
-
}))
|
|
72
|
-
])),
|
|
73
67
|
t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
|
|
74
|
-
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.
|
|
75
|
-
]))
|
|
76
|
-
t.exportNamedDeclaration(t.tSModuleDeclaration(t.identifier('JSX'), t.tsModuleBlock([
|
|
77
|
-
t.tsInterfaceDeclaration(t.identifier('IntrinsicElements'), undefined, undefined, t.tsInterfaceBody([
|
|
78
|
-
t.tsPropertySignature(t.stringLiteral(context.componentTag), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(context.componentClassName))))
|
|
79
|
-
]))
|
|
80
|
-
])))
|
|
68
|
+
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentInterfaceName))])))
|
|
69
|
+
]))
|
|
81
70
|
])), {
|
|
82
71
|
declare: true,
|
|
83
72
|
global: true
|
|
84
73
|
}));
|
|
74
|
+
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
75
|
+
// TODO
|
|
76
|
+
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
77
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
78
|
+
optional: property.optional,
|
|
79
|
+
leadingComments: property.leadingComments
|
|
80
|
+
})),
|
|
81
|
+
...context.classEvents.map((event) => {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
return Object.assign(t.tSPropertySignature(event.key, t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
84
|
+
Object.assign({}, t.identifier('event'), {
|
|
85
|
+
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))
|
|
86
|
+
})
|
|
87
|
+
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
88
|
+
optional: true,
|
|
89
|
+
leadingComments: event.leadingComments
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
]))));
|
|
85
93
|
}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
@@ -21,7 +21,7 @@ export const extract = (options) => {
|
|
|
21
21
|
var _a;
|
|
22
22
|
const name = (_a = path.node.expression.callee) === null || _a === void 0 ? void 0 : _a.name;
|
|
23
23
|
// TODO
|
|
24
|
-
if (CONSTANTS.
|
|
24
|
+
if (CONSTANTS.DECORATOR_ELEMENT == name) {
|
|
25
25
|
const [argument] = path.node.expression.arguments;
|
|
26
26
|
if (argument) {
|
|
27
27
|
context.componentTag = argument === null || argument === void 0 ? void 0 : argument.value;
|
|
@@ -62,13 +62,13 @@ export const extract = (options) => {
|
|
|
62
62
|
return;
|
|
63
63
|
context.stylePath = stylePath;
|
|
64
64
|
})();
|
|
65
|
-
context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.
|
|
66
|
-
context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.
|
|
67
|
-
context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.
|
|
68
|
-
context.classStates = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.
|
|
69
|
-
context.classHasMount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.
|
|
70
|
-
context.classHasUnmount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.
|
|
71
|
-
context.classRender = (context.classMembers || []).find((member) => member['key'].name == CONSTANTS.
|
|
65
|
+
context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
|
|
66
|
+
context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
|
|
67
|
+
context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
|
|
68
|
+
context.classStates = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_STATE));
|
|
69
|
+
context.classHasMount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_CONNECTED);
|
|
70
|
+
context.classHasUnmount = (context.classMembers || []).some((member) => member['key'].name == CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
71
|
+
context.classRender = (context.classMembers || []).find((member) => member['key'].name == CONSTANTS.METHOD_RENDER);
|
|
72
72
|
};
|
|
73
73
|
return {
|
|
74
74
|
name,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export interface ReactProxyOptions {
|
|
2
|
+
compact?: boolean;
|
|
2
3
|
dist: string;
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
eventName?: (eventName: string) => string;
|
|
5
|
+
importerComponent?: (context: any) => string;
|
|
6
|
+
importerComponentType?: (context: any) => string;
|
|
5
7
|
}
|
|
6
8
|
export declare const reactProxy: (options: ReactProxyOptions) => {
|
|
7
9
|
name: string;
|
|
8
|
-
finish: (global: any) =>
|
|
10
|
+
finish: (global: any) => void;
|
|
9
11
|
};
|