@htmlplus/element 0.1.1 → 0.1.4
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 +123 -25
- package/dist/client/decorators/attributes.js +5 -8
- package/dist/client/decorators/bind.d.ts +4 -1
- package/dist/client/decorators/bind.js +2 -3
- package/dist/client/decorators/element.js +115 -2
- package/dist/client/decorators/event.d.ts +20 -2
- package/dist/client/decorators/event.js +6 -6
- package/dist/client/decorators/index.js +0 -1
- package/dist/client/decorators/listen.d.ts +12 -2
- package/dist/client/decorators/listen.js +5 -10
- package/dist/client/decorators/method.d.ts +2 -1
- package/dist/client/decorators/method.js +9 -13
- package/dist/client/decorators/property.d.ts +12 -2
- package/dist/client/decorators/property.js +25 -18
- package/dist/client/decorators/state.d.ts +2 -1
- package/dist/client/decorators/state.js +19 -17
- package/dist/client/decorators/watch.js +3 -4
- package/dist/client/helpers/direction.d.ts +1 -1
- package/dist/client/helpers/direction.js +1 -1
- package/dist/client/helpers/index.d.ts +1 -3
- package/dist/client/helpers/index.js +1 -3
- package/dist/client/helpers/query-all.js +1 -1
- package/dist/client/helpers/query.js +1 -1
- package/dist/client/services/link.js +3 -3
- package/dist/client/utils/api.d.ts +5 -1
- package/dist/client/utils/append-to-method.d.ts +1 -0
- package/dist/client/utils/append-to-method.js +7 -0
- package/dist/client/{helpers → utils}/event.d.ts +0 -0
- package/dist/client/{helpers → utils}/event.js +0 -0
- package/dist/client/{helpers → utils}/host.d.ts +0 -0
- package/dist/client/{helpers → utils}/host.js +1 -1
- package/dist/client/utils/index.d.ts +4 -4
- package/dist/client/utils/index.js +4 -4
- package/dist/client/utils/on-ready.d.ts +1 -0
- package/dist/client/utils/on-ready.js +4 -0
- package/dist/client/utils/proxy.js +65 -25
- package/dist/client/utils/sync.js +3 -2
- package/dist/compiler/compiler.js +3 -3
- package/dist/compiler/index.d.ts +1 -2
- package/dist/compiler/index.js +1 -2
- package/dist/compiler/plugins/attach.js +7 -10
- package/dist/compiler/plugins/docs.js +1 -0
- package/dist/compiler/plugins/extract.js +14 -2
- package/dist/compiler/plugins/index.d.ts +1 -0
- package/dist/compiler/plugins/index.js +1 -0
- package/dist/compiler/plugins/react.proxy/index.d.ts +1 -0
- package/dist/compiler/plugins/react.proxy/index.js +1 -0
- package/dist/compiler/plugins/react.proxy/react.proxy.d.ts +9 -0
- package/dist/compiler/plugins/react.proxy/react.proxy.js +60 -0
- package/dist/compiler/plugins/react.proxy/templates/README.md.hbs +1 -0
- package/dist/compiler/plugins/react.proxy/templates/_.gitignore.hbs +2 -0
- package/dist/compiler/plugins/react.proxy/templates/package.json.hbs +36 -0
- package/dist/compiler/plugins/react.proxy/templates/rollup.config.js.hbs +20 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/index.ts.hbs +3 -0
- package/dist/compiler/plugins/react.proxy/templates/src/components/{{fileName}}.ts.hbs +38 -0
- package/dist/compiler/plugins/react.proxy/templates/src/index.ts.hbs +1 -0
- package/dist/compiler/plugins/react.proxy/templates/src/proxy.ts.hbs +277 -0
- package/dist/compiler/plugins/react.proxy/templates/tsconfig.json.hbs +17 -0
- package/dist/compiler/utils/__dirname.d.ts +1 -0
- package/dist/compiler/utils/__dirname.js +5 -0
- package/dist/compiler/utils/index.d.ts +3 -0
- package/dist/compiler/utils/index.js +3 -0
- package/dist/compiler/utils/is-directory-empty.d.ts +1 -0
- package/dist/compiler/utils/is-directory-empty.js +19 -0
- package/dist/compiler/utils/render-template.d.ts +1 -0
- package/dist/compiler/utils/render-template.js +25 -0
- package/dist/types/context.d.ts +2 -0
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types/plugin.d.ts +4 -3
- package/package.json +9 -6
- package/dist/client/decorators/listen-options.d.ts +0 -2
- package/dist/client/decorators/listen-options.js +0 -2
- package/dist/client/helpers/is-server.d.ts +0 -1
- package/dist/client/helpers/is-server.js +0 -1
- package/dist/client/utils/decorator.d.ts +0 -5
- package/dist/client/utils/decorator.js +0 -14
- package/dist/client/utils/define-element.d.ts +0 -1
- package/dist/client/utils/define-element.js +0 -7
- package/dist/client/utils/define-method.d.ts +0 -1
- package/dist/client/utils/define-method.js +0 -7
- package/dist/types/api.d.ts +0 -5
- package/dist/types/api.js +0 -1
- package/dist/types/direction.d.ts +0 -1
- package/dist/types/direction.js +0 -1
- package/dist/types/event-options.d.ts +0 -18
- package/dist/types/event-options.js +0 -1
- package/dist/types/listen-options.d.ts +0 -7
- package/dist/types/listen-options.js +0 -1
- package/dist/types/property-options.d.ts +0 -10
- package/dist/types/property-options.js +0 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { host } from '../
|
|
2
|
-
import { api, decorator, defineProperty } from '../utils/index.js';
|
|
1
|
+
import { api, defineProperty, host, onReady } from '../utils/index.js';
|
|
3
2
|
export function State() {
|
|
4
|
-
|
|
3
|
+
return function (target, propertyKey) {
|
|
5
4
|
let prev, next;
|
|
6
|
-
|
|
5
|
+
defineProperty(target, propertyKey, {
|
|
7
6
|
get() {
|
|
8
7
|
return next;
|
|
9
8
|
},
|
|
@@ -14,20 +13,23 @@ export function State() {
|
|
|
14
13
|
next = input;
|
|
15
14
|
if (!((_a = api(this)) === null || _a === void 0 ? void 0 : _a.ready))
|
|
16
15
|
return;
|
|
17
|
-
api(this)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
defineProperty(host(this), propertyKey, {
|
|
22
|
-
get: () => {
|
|
23
|
-
return this[propertyKey];
|
|
24
|
-
},
|
|
25
|
-
set: (value) => {
|
|
26
|
-
this[propertyKey] = value;
|
|
27
|
-
}
|
|
16
|
+
api(this)
|
|
17
|
+
.request({ [propertyKey]: [next, prev] })
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
throw error;
|
|
28
20
|
});
|
|
21
|
+
prev = next;
|
|
29
22
|
}
|
|
30
|
-
};
|
|
23
|
+
});
|
|
24
|
+
onReady(target, function () {
|
|
25
|
+
defineProperty(host(this), propertyKey, {
|
|
26
|
+
get: () => {
|
|
27
|
+
return this[propertyKey];
|
|
28
|
+
},
|
|
29
|
+
set: (value) => {
|
|
30
|
+
this[propertyKey] = value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
});
|
|
31
34
|
};
|
|
32
|
-
return decorator(setup);
|
|
33
35
|
}
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
2
|
-
import {
|
|
2
|
+
import { appendToMethod } from '../utils/index.js';
|
|
3
3
|
// TODO: support * key
|
|
4
4
|
export function Watch(...keys) {
|
|
5
5
|
return function (target, propertyKey) {
|
|
6
6
|
if (!keys.length)
|
|
7
7
|
return;
|
|
8
|
-
|
|
8
|
+
appendToMethod(target, CONSTANTS.TOKEN_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]) {
|
|
12
|
-
|
|
12
|
+
this[propertyKey](...states[key], key);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
return callback === null || callback === void 0 ? void 0 : callback(...args);
|
|
16
15
|
});
|
|
17
16
|
};
|
|
18
17
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export declare type Direction = 'ltr' | 'rtl';
|
|
2
2
|
export declare const direction: (target: any) => Direction;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export * from './classes.js';
|
|
2
2
|
export * from './direction.js';
|
|
3
|
-
export * from './event.js';
|
|
4
|
-
export * from './host.js';
|
|
5
3
|
export * from './is-rtl.js';
|
|
6
|
-
export * from './is-server.js';
|
|
7
4
|
export * from './query.js';
|
|
8
5
|
export * from './query-all.js';
|
|
9
6
|
export * from './slots.js';
|
|
10
7
|
export * from './styles.js';
|
|
11
8
|
export * from './to-unit.js';
|
|
9
|
+
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export * from './classes.js';
|
|
2
2
|
export * from './direction.js';
|
|
3
|
-
export * from './event.js';
|
|
4
|
-
export * from './host.js';
|
|
5
3
|
export * from './is-rtl.js';
|
|
6
|
-
export * from './is-server.js';
|
|
7
4
|
export * from './query.js';
|
|
8
5
|
export * from './query-all.js';
|
|
9
6
|
export * from './slots.js';
|
|
10
7
|
export * from './styles.js';
|
|
11
8
|
export * from './to-unit.js';
|
|
9
|
+
export { host, isServer, on, off } from '../utils/index.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { host } from '
|
|
1
|
+
import { host } from '../utils/index.js';
|
|
2
2
|
export function queryAll(target, selectors) {
|
|
3
3
|
var _a, _b;
|
|
4
4
|
return (_b = (_a = host(target)) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelectorAll(selectors);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { host } from '
|
|
1
|
+
import { host } from '../utils/index.js';
|
|
2
2
|
export function query(target, selectors) {
|
|
3
3
|
var _a, _b;
|
|
4
4
|
return (_b = (_a = host(target)) === null || _a === void 0 ? void 0 : _a.shadowRoot) === null || _b === void 0 ? void 0 : _b.querySelector(selectors);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { host } from '../
|
|
1
|
+
import { defineProperty, host } from '../utils/index.js';
|
|
2
2
|
const links = new Map();
|
|
3
3
|
// TODO: return type
|
|
4
4
|
export const createLink = (namespace) => {
|
|
@@ -51,7 +51,7 @@ export const createLink = (namespace) => {
|
|
|
51
51
|
if (source.type === 'inject')
|
|
52
52
|
return set(source, source.value /* TODO */);
|
|
53
53
|
// TODO: any
|
|
54
|
-
|
|
54
|
+
defineProperty(source.instance, source.name, {
|
|
55
55
|
value: get(source) /* TODO */,
|
|
56
56
|
enumerable: true,
|
|
57
57
|
configurable: true
|
|
@@ -66,7 +66,7 @@ export const createLink = (namespace) => {
|
|
|
66
66
|
const proxy = (source) => {
|
|
67
67
|
let value = get(source);
|
|
68
68
|
// TODO: any
|
|
69
|
-
|
|
69
|
+
defineProperty(source.instance, source.name, {
|
|
70
70
|
enumerable: true,
|
|
71
71
|
configurable: true,
|
|
72
72
|
get() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const appendToMethod: (target: any, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const appendToMethod = (target, propertyKey, handler) => {
|
|
2
|
+
const callback = target[propertyKey];
|
|
3
|
+
target[propertyKey] = function () {
|
|
4
|
+
handler.bind(this)(Array.from(arguments));
|
|
5
|
+
return callback === null || callback === void 0 ? void 0 : callback.bind(this)(arguments);
|
|
6
|
+
};
|
|
7
|
+
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { api } from '
|
|
1
|
+
import { api } from './api.js';
|
|
2
2
|
export const host = (target) => api(target).host();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export * from './api.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './define-element.js';
|
|
4
|
-
export * from './define-method.js';
|
|
2
|
+
export * from './append-to-method.js';
|
|
5
3
|
export * from './define-property.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './host.js';
|
|
6
6
|
export * from './is-event.js';
|
|
7
7
|
export * from './is-server.js';
|
|
8
|
+
export * from './on-ready.js';
|
|
8
9
|
export * from './parse-value.js';
|
|
9
|
-
export * from './proxy.js';
|
|
10
10
|
export * from './sync.js';
|
|
11
11
|
export * from './to-boolean.js';
|
|
12
12
|
export * from './to-event.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export * from './api.js';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './define-element.js';
|
|
4
|
-
export * from './define-method.js';
|
|
2
|
+
export * from './append-to-method.js';
|
|
5
3
|
export * from './define-property.js';
|
|
4
|
+
export * from './event.js';
|
|
5
|
+
export * from './host.js';
|
|
6
6
|
export * from './is-event.js';
|
|
7
7
|
export * from './is-server.js';
|
|
8
|
+
export * from './on-ready.js';
|
|
8
9
|
export * from './parse-value.js';
|
|
9
|
-
export * from './proxy.js';
|
|
10
10
|
export * from './sync.js';
|
|
11
11
|
export * from './to-boolean.js';
|
|
12
12
|
export * from './to-event.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function onReady(target: any, callback: (this: any) => void): void;
|
|
@@ -1,3 +1,12 @@
|
|
|
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
|
+
};
|
|
1
10
|
import { html, render } from 'uhtml';
|
|
2
11
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
3
12
|
import { isServer } from './is-server.js';
|
|
@@ -9,6 +18,60 @@ export const proxy = (Class) => {
|
|
|
9
18
|
};
|
|
10
19
|
let host, instance;
|
|
11
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
|
+
};
|
|
12
75
|
const call = (key, args) => {
|
|
13
76
|
var _a;
|
|
14
77
|
return (_a = instance[key]) === null || _a === void 0 ? void 0 : _a.apply(instance, args);
|
|
@@ -19,30 +82,6 @@ export const proxy = (Class) => {
|
|
|
19
82
|
const set = (key, value) => {
|
|
20
83
|
instance[CONSTANTS.TOKEN_API][key] = value;
|
|
21
84
|
};
|
|
22
|
-
// TODO
|
|
23
|
-
let timeout, allStates;
|
|
24
|
-
const request = (states) => {
|
|
25
|
-
clearTimeout(timeout);
|
|
26
|
-
allStates = Object.assign(Object.assign({}, (allStates || {})), states);
|
|
27
|
-
timeout = setTimeout(() => {
|
|
28
|
-
// TODO
|
|
29
|
-
// call(CONSTANTS.TOKEN_LIFECYCLE_UPDATE, [allStates]);
|
|
30
|
-
render(host.shadowRoot, () => {
|
|
31
|
-
const markup = call(CONSTANTS.TOKEN_METHOD_RENDER);
|
|
32
|
-
const styles = Class[CONSTANTS.TOKEN_STATIC_STYLES];
|
|
33
|
-
if (!styles && !markup)
|
|
34
|
-
return html ``;
|
|
35
|
-
if (!styles)
|
|
36
|
-
return markup;
|
|
37
|
-
if (!markup)
|
|
38
|
-
return html `<style>${styles}</style>`;
|
|
39
|
-
return html `<style>${styles}</style>${markup}`;
|
|
40
|
-
});
|
|
41
|
-
// TODO
|
|
42
|
-
call(CONSTANTS.TOKEN_LIFECYCLE_UPDATED, [allStates]);
|
|
43
|
-
allStates = undefined;
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
85
|
return class extends HTMLElement {
|
|
47
86
|
constructor() {
|
|
48
87
|
var _a, _b;
|
|
@@ -74,7 +113,8 @@ export const proxy = (Class) => {
|
|
|
74
113
|
connectedCallback() {
|
|
75
114
|
call(CONSTANTS.TOKEN_LIFECYCLE_CONNECTED);
|
|
76
115
|
request();
|
|
77
|
-
|
|
116
|
+
// TODO
|
|
117
|
+
setTimeout(() => call(CONSTANTS.TOKEN_LIFECYCLE_LOADED));
|
|
78
118
|
set(CONSTANTS.TOKEN_API_READY, true);
|
|
79
119
|
}
|
|
80
120
|
disconnectedCallback() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { on, off } from './event.js';
|
|
1
2
|
import { isEvent } from './is-event.js';
|
|
2
3
|
import { toEvent } from './to-event.js';
|
|
3
4
|
import { updateAttribute } from './update-attribute.js';
|
|
@@ -16,12 +17,12 @@ export const sync = (node) => {
|
|
|
16
17
|
if (prev.style || next.style)
|
|
17
18
|
node.setAttribute('style', next.style || '');
|
|
18
19
|
for (const key in prev)
|
|
19
|
-
isEvent(key) && node
|
|
20
|
+
isEvent(key) && off(node, toEvent(key), prev[key]);
|
|
20
21
|
for (const key in next) {
|
|
21
22
|
if (['class', 'style'].includes(key))
|
|
22
23
|
continue;
|
|
23
24
|
if (isEvent(key))
|
|
24
|
-
node
|
|
25
|
+
on(node, toEvent(key), next[key]);
|
|
25
26
|
else
|
|
26
27
|
updateAttribute(node, key, next[key]);
|
|
27
28
|
}
|
|
@@ -12,7 +12,7 @@ const log = (namespace, message) => {
|
|
|
12
12
|
logUpdate(`${new Date().toLocaleTimeString()} [@htmlplus/element]${namespace ? `[${namespace}]` : ''} ${message}`);
|
|
13
13
|
};
|
|
14
14
|
export default (...plugins) => {
|
|
15
|
-
|
|
15
|
+
let global = {
|
|
16
16
|
contexts: {}
|
|
17
17
|
};
|
|
18
18
|
const start = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -20,7 +20,7 @@ export default (...plugins) => {
|
|
|
20
20
|
for (const plugin of plugins) {
|
|
21
21
|
if (!plugin.start)
|
|
22
22
|
continue;
|
|
23
|
-
yield plugin.start(global);
|
|
23
|
+
global = (yield plugin.start(global)) || global;
|
|
24
24
|
log(plugin.name, 'Started successfully.');
|
|
25
25
|
}
|
|
26
26
|
});
|
|
@@ -43,7 +43,7 @@ export default (...plugins) => {
|
|
|
43
43
|
for (const plugin of plugins) {
|
|
44
44
|
if (!plugin.finish)
|
|
45
45
|
continue;
|
|
46
|
-
yield plugin.finish(global);
|
|
46
|
+
global = (yield plugin.finish(global)) || global;
|
|
47
47
|
log(plugin.name, 'Finished successfully.');
|
|
48
48
|
}
|
|
49
49
|
log(undefined, 'Finished.');
|
package/dist/compiler/index.d.ts
CHANGED
package/dist/compiler/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import t from '@babel/types';
|
|
2
|
-
import { pascalCase } from 'change-case';
|
|
3
2
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
4
3
|
import { visitor } from '../utils/index.js';
|
|
5
4
|
const defaults = {
|
|
@@ -48,37 +47,35 @@ export const attach = (options) => {
|
|
|
48
47
|
]), undefined, undefined, undefined, true));
|
|
49
48
|
}
|
|
50
49
|
if (options.typings) {
|
|
51
|
-
const className = pascalCase(context.componentTag.split('-').slice(1).join('-'));
|
|
52
|
-
const elementName = `HTML${className}Element`;
|
|
53
50
|
visitor(context.fileAST, {
|
|
54
51
|
Program(path) {
|
|
55
52
|
path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
56
|
-
t.tsInterfaceDeclaration(t.identifier(
|
|
53
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [], t.tsInterfaceBody([
|
|
57
54
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
58
55
|
optional: property.optional,
|
|
59
56
|
leadingComments: property.leadingComments
|
|
60
57
|
}))
|
|
61
58
|
])),
|
|
62
59
|
t.variableDeclaration('var', [
|
|
63
|
-
t.variableDeclarator(Object.assign(t.identifier(
|
|
60
|
+
t.variableDeclarator(Object.assign(t.identifier(context.componentInterfaceName), {
|
|
64
61
|
typeAnnotation: t.tSTypeAnnotation(t.tSTypeLiteral([
|
|
65
|
-
t.tSPropertySignature(t.identifier('prototype'), t.tsTypeAnnotation(t.tSTypeReference(t.identifier(
|
|
66
|
-
t.tSConstructSignatureDeclaration(null, [], t.tSTypeAnnotation(t.tSTypeReference(t.identifier(
|
|
62
|
+
t.tSPropertySignature(t.identifier('prototype'), t.tsTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName)))),
|
|
63
|
+
t.tSConstructSignatureDeclaration(null, [], t.tSTypeAnnotation(t.tSTypeReference(t.identifier(context.componentInterfaceName))))
|
|
67
64
|
]))
|
|
68
65
|
}))
|
|
69
66
|
]),
|
|
70
|
-
t.tsInterfaceDeclaration(t.identifier(
|
|
67
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentClassName), null, [], t.tsInterfaceBody([
|
|
71
68
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
72
69
|
optional: property.optional,
|
|
73
70
|
leadingComments: property.leadingComments
|
|
74
71
|
}))
|
|
75
72
|
])),
|
|
76
73
|
t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
|
|
77
|
-
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(
|
|
74
|
+
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentClassName))])))
|
|
78
75
|
])),
|
|
79
76
|
t.exportNamedDeclaration(t.tSModuleDeclaration(t.identifier('JSX'), t.tsModuleBlock([
|
|
80
77
|
t.tsInterfaceDeclaration(t.identifier('IntrinsicElements'), undefined, undefined, t.tsInterfaceBody([
|
|
81
|
-
t.tsPropertySignature(t.stringLiteral(context.componentTag), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(
|
|
78
|
+
t.tsPropertySignature(t.stringLiteral(context.componentTag), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(context.componentClassName))))
|
|
82
79
|
]))
|
|
83
80
|
])))
|
|
84
81
|
])), {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
|
-
import { paramCase } from 'change-case';
|
|
2
|
+
import { pascalCase, paramCase } from 'change-case';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import * as CONSTANTS from '../../configs/constants.js';
|
|
@@ -43,7 +43,19 @@ export const extract = (options) => {
|
|
|
43
43
|
context.fileExtension = path.extname(context.filePath);
|
|
44
44
|
context.fileName = path.basename(context.filePath, context.fileExtension);
|
|
45
45
|
context.className = (_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name;
|
|
46
|
-
|
|
46
|
+
// TODO
|
|
47
|
+
// context.componentKey = paramCase(context.className);
|
|
48
|
+
context.componentClassName = pascalCase(context.componentTag.split('-').slice(1).join('-'));
|
|
49
|
+
context.componentInterfaceName = `HTML${context.componentClassName}Element`;
|
|
50
|
+
// TODO
|
|
51
|
+
// const componentClassName = "DialogBody"; [OK]
|
|
52
|
+
// const componentInterfaceName = "HTMLDialogBodyElement"; [OK]
|
|
53
|
+
// const componentTag = "plus-dialog-body"; [OK]
|
|
54
|
+
// const componentClassNameInCategory = "Body"; [RAW]
|
|
55
|
+
// const componentKey = "dialog-body-1"; [RAW]
|
|
56
|
+
// const fileName = "dialogBodyNew"; [OK]
|
|
57
|
+
// const className = "DialogBody1"; [OK]
|
|
58
|
+
// const category = "Dialog"; [RAW]
|
|
47
59
|
(() => {
|
|
48
60
|
const stylePath = path.join(context.directoryPath, `${context.fileName}.scss`);
|
|
49
61
|
if (!fs.existsSync(stylePath))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react.proxy.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react.proxy.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
|
|
11
|
+
export const reactProxy = (options) => {
|
|
12
|
+
const name = 'react-proxy';
|
|
13
|
+
const finish = (global) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
const config = { cwd: __dirname(import.meta.url) };
|
|
15
|
+
const component = 'templates/src/components/*fileName*';
|
|
16
|
+
global = Object.assign({}, global, { options });
|
|
17
|
+
const skip = [];
|
|
18
|
+
const getKey = (component) => component.componentClassName;
|
|
19
|
+
global.groups = Object.values(global.contexts)
|
|
20
|
+
.sort((a, b) => getKey(b).length - getKey(a).length)
|
|
21
|
+
.map((component, index, components) => ({
|
|
22
|
+
key: getKey(component),
|
|
23
|
+
components: components.filter((current) => getKey(current).startsWith(getKey(component)))
|
|
24
|
+
}))
|
|
25
|
+
.sort((a, b) => b.components.length - a.components.length)
|
|
26
|
+
.filter((group) => {
|
|
27
|
+
if (skip.includes(group.key))
|
|
28
|
+
return;
|
|
29
|
+
group.components.forEach((component) => skip.push(getKey(component)));
|
|
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
|
|
43
|
+
};
|
|
44
|
+
})
|
|
45
|
+
.sort((a, b) => (getKey(a.root) < getKey(b.root) ? -1 : 0));
|
|
46
|
+
if (yield isDirectoryEmpty(options.dist)) {
|
|
47
|
+
renderTemplate(['templates/**', `!${component}`], options.dist, config)(global);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
renderTemplate(['templates/src/proxy*', 'templates/src/components/index*'], options.dist, config)(global);
|
|
51
|
+
}
|
|
52
|
+
for (const group of global.groups) {
|
|
53
|
+
renderTemplate(component, options.dist, config)(Object.assign({ options, fileName: group.root.fileName }, group));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
name,
|
|
58
|
+
finish
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# React output target for your custom element.
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
"{{options.corePackageName}}": "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
|
+
"react": "^17.0.1",
|
|
25
|
+
"react-dom": "^17.0.1",
|
|
26
|
+
"rimraf": "^3.0.2",
|
|
27
|
+
"rollup": "^2.27.1",
|
|
28
|
+
"rollup-plugin-peer-deps-external": "^2.2.3",
|
|
29
|
+
"rollup-plugin-typescript2": "^0.27.2",
|
|
30
|
+
"typescript": "^4.0.2"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": "^16.0.0 || ^17.0.0",
|
|
34
|
+
"react-dom": "^16.0.0 || ^17.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|