@htmlplus/element 0.1.6 → 0.1.9
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 +22 -92
- package/dist/client/decorators/listen.js +2 -2
- package/dist/client/decorators/property.js +21 -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 +7 -1
- package/dist/client/utils/index.js +7 -1
- package/dist/client/utils/is-ready.d.ts +2 -0
- package/dist/client/utils/is-ready.js +4 -0
- 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 +17 -4
- package/dist/compiler/plugins/extract.js +8 -8
- package/dist/compiler/plugins/react.proxy/react.proxy.js +3 -1
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +4 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs +4 -1
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +4 -1
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +4 -3
- package/dist/compiler/plugins/uhtml.js +6 -0
- 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 -2
- package/package.json +1 -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,49 @@
|
|
|
1
|
-
|
|
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';
|
|
1
|
+
import { camelCase, paramCase } from 'change-case';
|
|
11
2
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
12
|
-
import { isServer, parseValue } from '../utils/index.js';
|
|
3
|
+
import { call, getMembers, isServer, parseValue, request } from '../utils/index.js';
|
|
13
4
|
export function Element(tag) {
|
|
14
5
|
return function (constructor) {
|
|
15
6
|
if (isServer())
|
|
16
7
|
return;
|
|
17
|
-
const members = constructor
|
|
18
|
-
|
|
19
|
-
customElements.define(tag, class extends HTMLElement {
|
|
8
|
+
const members = getMembers(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
|
-
return Object.keys(members)
|
|
19
|
+
return Object.keys(members)
|
|
20
|
+
.filter((key) => members[key][0] != CONSTANTS.TYPE_FUNCTION)
|
|
21
|
+
.map((key) => paramCase(key));
|
|
86
22
|
}
|
|
87
23
|
adoptedCallback() {
|
|
88
|
-
|
|
89
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_ADOPTED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
24
|
+
call(this.plus, CONSTANTS.LIFECYCLE_ADOPTED);
|
|
90
25
|
}
|
|
91
26
|
attributeChangedCallback(name, prev, next) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.plus[CONSTANTS.TOKEN_API][CONSTANTS.TOKEN_API_REQUEST]().catch((error) => {
|
|
97
|
-
throw error;
|
|
98
|
-
});
|
|
27
|
+
const key = camelCase(name);
|
|
28
|
+
const [type] = members[key];
|
|
29
|
+
const parsed = parseValue(next, type);
|
|
30
|
+
this.plus[key] = parsed;
|
|
99
31
|
}
|
|
100
32
|
connectedCallback() {
|
|
101
|
-
|
|
102
|
-
(
|
|
103
|
-
this.plus
|
|
33
|
+
this.plus[CONSTANTS.API_READY] = true;
|
|
34
|
+
call(this.plus, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
35
|
+
request(this.plus)
|
|
104
36
|
.then(() => {
|
|
105
|
-
|
|
106
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_LOADED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
37
|
+
call(this.plus, CONSTANTS.LIFECYCLE_LOADED);
|
|
107
38
|
})
|
|
108
39
|
.catch((error) => {
|
|
109
40
|
throw error;
|
|
110
41
|
});
|
|
111
|
-
this.plus[CONSTANTS.TOKEN_API][CONSTANTS.TOKEN_API_READY] = true;
|
|
112
42
|
}
|
|
113
43
|
disconnectedCallback() {
|
|
114
|
-
|
|
115
|
-
(_a = this.plus[CONSTANTS.TOKEN_LIFECYCLE_DISCONNECTED]) === null || _a === void 0 ? void 0 : _a.call(this.plus);
|
|
44
|
+
call(this.plus, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
116
45
|
}
|
|
117
|
-
}
|
|
46
|
+
}
|
|
47
|
+
customElements.define(tag, Plus);
|
|
118
48
|
};
|
|
119
49
|
}
|
|
@@ -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,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { api, defineProperty, host, onReady, parseValue, updateAttribute } from '../utils/index.js';
|
|
1
|
+
import { defineProperty, getMembers, host, isReady, 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
|
-
|
|
17
|
-
|
|
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
|
+
// TODO
|
|
15
|
+
const ready = isReady(this);
|
|
16
|
+
request(this, { [propertyKey]: [input, value] })
|
|
26
17
|
.then((renderd) => {
|
|
18
|
+
const name = String(propertyKey);
|
|
19
|
+
const element = host(this);
|
|
20
|
+
const hasAttribute = element.hasAttribute(name);
|
|
21
|
+
// TODO
|
|
22
|
+
if ((options === null || options === void 0 ? void 0 : options.reflect) && !hasAttribute && !renderd && !ready)
|
|
23
|
+
updateAttribute(element, name, input);
|
|
27
24
|
if (!renderd)
|
|
28
25
|
return;
|
|
29
26
|
if (!(options === null || options === void 0 ? void 0 : options.reflect))
|
|
30
27
|
return;
|
|
31
|
-
|
|
28
|
+
const raw = element.getAttribute(name);
|
|
29
|
+
const [type] = getMembers(target)[propertyKey];
|
|
30
|
+
const parsed = parseValue(raw, type);
|
|
31
|
+
if (parsed === input)
|
|
32
|
+
return;
|
|
33
|
+
updateAttribute(element, name, input);
|
|
32
34
|
})
|
|
33
35
|
.catch((error) => {
|
|
34
36
|
throw error;
|
|
35
37
|
});
|
|
36
|
-
prev = next;
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
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,19 @@
|
|
|
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';
|
|
9
|
+
export * from './is-ready.js';
|
|
7
10
|
export * from './is-server.js';
|
|
8
11
|
export * from './on-ready.js';
|
|
9
12
|
export * from './parse-value.js';
|
|
13
|
+
export * from './render.js';
|
|
14
|
+
export * from './request.js';
|
|
10
15
|
export * from './sync.js';
|
|
16
|
+
export * from './task.js';
|
|
11
17
|
export * from './to-boolean.js';
|
|
12
18
|
export * from './to-event.js';
|
|
13
19
|
export * from './type-of.js';
|
|
@@ -1,13 +1,19 @@
|
|
|
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';
|
|
9
|
+
export * from './is-ready.js';
|
|
7
10
|
export * from './is-server.js';
|
|
8
11
|
export * from './on-ready.js';
|
|
9
12
|
export * from './parse-value.js';
|
|
13
|
+
export * from './render.js';
|
|
14
|
+
export * from './request.js';
|
|
10
15
|
export * from './sync.js';
|
|
16
|
+
export * from './task.js';
|
|
11
17
|
export * from './to-boolean.js';
|
|
12
18
|
export * from './to-event.js';
|
|
13
19
|
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, isReady, render, task } from '../utils/index.js';
|
|
3
|
+
const targets = new Map();
|
|
4
|
+
export const request = (target, state) => {
|
|
5
|
+
if (!isReady(target))
|
|
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;
|
|
@@ -71,11 +71,24 @@ export const attach = (options) => {
|
|
|
71
71
|
declare: true,
|
|
72
72
|
global: true
|
|
73
73
|
}));
|
|
74
|
-
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
74
|
+
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
75
|
+
// TODO
|
|
76
|
+
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
75
77
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
76
78
|
optional: property.optional,
|
|
77
79
|
leadingComments: property.leadingComments
|
|
78
|
-
}))
|
|
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
|
+
})
|
|
79
92
|
]))));
|
|
80
93
|
}
|
|
81
94
|
});
|
|
@@ -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,
|
|
@@ -32,7 +32,9 @@ export const reactProxy = (options) => {
|
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
const classEvents = context.classEvents.map((classEvent) => {
|
|
35
|
-
|
|
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) });
|
|
36
38
|
});
|
|
37
39
|
const fileName = context.fileName;
|
|
38
40
|
const importerComponent = parse(options.importerComponent(context));
|
package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.compact.ts.hbs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
/* tslint:disable */
|
|
3
|
-
/* auto-generated */
|
|
4
3
|
|
|
4
|
+
/**************************************************
|
|
5
|
+
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
|
+
**************************************************/
|
|
7
|
+
|
|
5
8
|
{{#each all}}
|
|
6
9
|
import { {{componentClassName}} } from './{{fileName}}';
|
|
7
10
|
{{/each}}
|
|
@@ -1,6 +1,9 @@
|
|
|
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
9
|
|
|
@@ -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,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
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
|
-
};
|