@htmlplus/element 0.4.0 → 0.4.3
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/client/decorators/element.js +25 -18
- package/client/decorators/event.js +14 -3
- package/client/decorators/property.js +6 -5
- package/client/decorators/state.js +3 -3
- package/client/decorators/watch.js +7 -10
- package/client/helpers/classes.d.ts +1 -1
- package/client/utils/appendToMethod.d.ts +1 -2
- package/client/utils/call.d.ts +1 -2
- package/client/utils/config.d.ts +5 -0
- package/client/utils/config.js +7 -0
- package/client/utils/getFramework.d.ts +1 -0
- package/client/utils/getFramework.js +12 -0
- package/client/utils/getMemberType.d.ts +2 -0
- package/client/utils/getMemberType.js +5 -0
- package/client/utils/getMembersKey.d.ts +2 -0
- package/client/utils/getMembersKey.js +4 -0
- package/client/utils/index.d.ts +6 -2
- package/client/utils/index.js +6 -2
- package/client/utils/off.d.ts +1 -0
- package/client/utils/off.js +3 -0
- package/client/utils/on.d.ts +1 -0
- package/client/utils/on.js +3 -0
- package/client/utils/request.d.ts +1 -1
- package/client/utils/request.js +4 -2
- package/client/utils/sync.js +2 -1
- package/client/utils/task.js +1 -1
- package/compiler/compiler.js +4 -1
- package/compiler/plugins/customElement.d.ts +1 -1
- package/compiler/plugins/customElement.js +15 -1
- package/compiler/plugins/customElementReact/customElementReact.js +1 -1
- package/compiler/plugins/customElementReact/templates/package.json.hbs +2 -2
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +1 -4
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +1 -5
- package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +3 -3
- package/compiler/plugins/extract.d.ts +1 -1
- package/compiler/plugins/extract.js +11 -1
- package/compiler/utils/tags.d.ts +2 -2
- package/constants/index.d.ts +1 -1
- package/constants/index.js +2 -1
- package/package.json +14 -16
- package/types/context.d.ts +1 -0
- package/client/utils/event.d.ts +0 -5
- package/client/utils/event.js +0 -9
- package/client/utils/getMembers.d.ts +0 -2
- package/client/utils/getMembers.js +0 -5
|
@@ -1,53 +1,60 @@
|
|
|
1
1
|
import { camelCase, paramCase } from 'change-case';
|
|
2
2
|
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { call,
|
|
3
|
+
import { call, getMembersKey, getMemberType, isServer, parseValue, request } from '../utils/index.js';
|
|
4
4
|
import * as uhtml from '../vendor/uhtml.js';
|
|
5
5
|
export function Element(tag) {
|
|
6
6
|
return function (constructor) {
|
|
7
7
|
if (isServer())
|
|
8
8
|
return;
|
|
9
|
-
|
|
9
|
+
if (customElements.get(tag))
|
|
10
|
+
return;
|
|
11
|
+
const instances = new Map();
|
|
10
12
|
class Plus extends HTMLElement {
|
|
11
13
|
constructor() {
|
|
12
14
|
super();
|
|
13
15
|
this.attachShadow({ mode: 'open' });
|
|
14
16
|
// TODO
|
|
15
|
-
|
|
16
|
-
this
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
const instance = new constructor();
|
|
18
|
+
instances.set(this, instance);
|
|
19
|
+
instance[CONSTANTS.API_HOST] = () => this;
|
|
20
|
+
instance['uhtml'] = uhtml;
|
|
21
|
+
instance[CONSTANTS.API_STATUS] = 'initialize';
|
|
19
22
|
}
|
|
20
23
|
static get observedAttributes() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.map((key) => paramCase(key));
|
|
24
|
+
// TODO: ignore functions
|
|
25
|
+
return getMembersKey(constructor).map((key) => paramCase(key));
|
|
24
26
|
}
|
|
25
27
|
adoptedCallback() {
|
|
26
|
-
|
|
28
|
+
const instance = instances.get(this);
|
|
29
|
+
call(instance, CONSTANTS.LIFECYCLE_ADOPTED);
|
|
27
30
|
}
|
|
28
31
|
// TODO
|
|
29
32
|
attributeChangedCallback(name, prev, next) {
|
|
33
|
+
const instance = instances.get(this);
|
|
30
34
|
const key = camelCase(name);
|
|
31
|
-
const
|
|
35
|
+
const type = getMemberType(instance, key);
|
|
32
36
|
const parsed = parseValue(next, type);
|
|
33
|
-
|
|
37
|
+
instance[key] = parsed;
|
|
34
38
|
}
|
|
35
39
|
connectedCallback() {
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
const instance = instances.get(this);
|
|
41
|
+
instance[CONSTANTS.API_STATUS] = 'connected';
|
|
42
|
+
call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
43
|
+
request(instance)
|
|
38
44
|
.then(() => {
|
|
39
|
-
|
|
45
|
+
instance[CONSTANTS.API_STATUS] = 'loaded';
|
|
46
|
+
call(instance, CONSTANTS.LIFECYCLE_LOADED);
|
|
40
47
|
})
|
|
41
48
|
.catch((error) => {
|
|
42
49
|
throw error;
|
|
43
50
|
});
|
|
44
51
|
}
|
|
45
52
|
disconnectedCallback() {
|
|
46
|
-
|
|
53
|
+
const instance = instances.get(this);
|
|
54
|
+
instance[CONSTANTS.API_STATUS] = 'disconnected';
|
|
55
|
+
call(instance, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
|
-
if (customElements.get(tag))
|
|
50
|
-
return;
|
|
51
58
|
customElements.define(tag, Plus);
|
|
52
59
|
};
|
|
53
60
|
}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { paramCase, pascalCase } from 'change-case';
|
|
2
|
+
import { defineProperty, getFramework, host } from '../utils/index.js';
|
|
2
3
|
export function Event(options = {}) {
|
|
3
4
|
return function (target, propertyKey) {
|
|
4
5
|
defineProperty(target, propertyKey, {
|
|
5
6
|
get() {
|
|
6
7
|
return (detail) => {
|
|
7
8
|
var _a;
|
|
9
|
+
const element = host(this);
|
|
10
|
+
const framework = getFramework(element);
|
|
8
11
|
(_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
|
|
9
|
-
|
|
12
|
+
let name = options.name || String(propertyKey);
|
|
13
|
+
switch (framework) {
|
|
14
|
+
case 'react':
|
|
15
|
+
name = pascalCase(name);
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
name = paramCase(name);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
10
21
|
const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
|
|
11
|
-
|
|
22
|
+
element.dispatchEvent(event);
|
|
12
23
|
return event;
|
|
13
24
|
};
|
|
14
25
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { paramCase } from 'change-case';
|
|
2
2
|
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { defineProperty,
|
|
3
|
+
import { defineProperty, getMemberType, host, parseValue, request, updateAttribute, appendToMethod } from '../utils/index.js';
|
|
4
4
|
export function Property(options) {
|
|
5
5
|
return function (target, propertyKey) {
|
|
6
6
|
const name = String(propertyKey);
|
|
7
7
|
const attribute = paramCase(name);
|
|
8
|
-
const type =
|
|
8
|
+
const type = getMemberType(target, name);
|
|
9
9
|
const values = new Map();
|
|
10
10
|
function get() {
|
|
11
11
|
return values.get(this);
|
|
@@ -15,8 +15,8 @@ export function Property(options) {
|
|
|
15
15
|
if (input === value)
|
|
16
16
|
return;
|
|
17
17
|
values.set(this, input);
|
|
18
|
-
const isReady =
|
|
19
|
-
request(this, { [name]: [input, value
|
|
18
|
+
const isReady = this[CONSTANTS.API_STATUS] == 'initialize';
|
|
19
|
+
request(this, { [name]: [input, value] }).then(() => {
|
|
20
20
|
const element = host(this);
|
|
21
21
|
const has = element.hasAttribute(attribute);
|
|
22
22
|
if (!isReady && has)
|
|
@@ -39,7 +39,8 @@ export function Property(options) {
|
|
|
39
39
|
const set = (input) => {
|
|
40
40
|
this[propertyKey] = input;
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
// TODO: configurable
|
|
43
|
+
defineProperty(element, propertyKey, { get, set, configurable: true });
|
|
43
44
|
});
|
|
44
45
|
};
|
|
45
46
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
1
|
import { defineProperty, request } from '../utils/index.js';
|
|
3
2
|
export function State() {
|
|
4
3
|
return function (target, propertyKey) {
|
|
@@ -12,12 +11,13 @@ export function State() {
|
|
|
12
11
|
if (input === value)
|
|
13
12
|
return;
|
|
14
13
|
values.set(this, input);
|
|
15
|
-
request(this, { [name]: [input, value
|
|
14
|
+
request(this, { [name]: [input, value] })
|
|
16
15
|
.then(() => undefined)
|
|
17
16
|
.catch((error) => {
|
|
18
17
|
throw error;
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
// TODO: configurable
|
|
21
|
+
defineProperty(target, propertyKey, { get, set, configurable: true });
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -10,21 +10,18 @@ export function Watch(keys, immediate) {
|
|
|
10
10
|
return function (target, propertyKey) {
|
|
11
11
|
// Registers a lifecycle to detect changes.
|
|
12
12
|
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function ([states]) {
|
|
13
|
-
// Gets all keys
|
|
14
|
-
const keys = Object.keys(states);
|
|
15
13
|
// Loops the keys
|
|
16
|
-
for (const key of keys) {
|
|
17
|
-
//
|
|
18
|
-
|
|
14
|
+
for (const key of Object.keys(states)) {
|
|
15
|
+
// TODO
|
|
16
|
+
if ((keys === null || keys === void 0 ? void 0 : keys.length) && !keys.includes(key))
|
|
17
|
+
continue;
|
|
19
18
|
// Checks the existence of key
|
|
20
|
-
if (
|
|
19
|
+
if ((keys === null || keys === void 0 ? void 0 : keys.length) && !(key in states))
|
|
21
20
|
continue;
|
|
22
21
|
// Gets the current state
|
|
23
|
-
const
|
|
24
|
-
// Destructs the state
|
|
25
|
-
const [next, prev, isInitial] = state;
|
|
22
|
+
const [next, prev] = states[key];
|
|
26
23
|
// TODO
|
|
27
|
-
if (!immediate &&
|
|
24
|
+
if (!immediate && this[CONSTANTS.API_STATUS] != 'loaded')
|
|
28
25
|
continue;
|
|
29
26
|
// Invokes the method with parameters.
|
|
30
27
|
this[propertyKey](next, prev, key);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const classes: (input: any, smart?: boolean
|
|
1
|
+
export declare const classes: (input: any, smart?: boolean) => string;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const appendToMethod: (target: PlusElement, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
|
|
1
|
+
export declare const appendToMethod: (target: any, propertyKey: PropertyKey, handler: (this: any, args: Array<any>) => void) => void;
|
package/client/utils/call.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const call: (target: PlusElement, key: string, ...args: Array<any>) => any;
|
|
1
|
+
export declare const call: (target: any, key: string, ...args: Array<any>) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getFramework: (target: HTMLElement) => string | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const getFramework = (target) => {
|
|
2
|
+
const keys = Object.keys(target);
|
|
3
|
+
const has = (key) => keys.some((key) => key.startsWith(key));
|
|
4
|
+
if (has('__zone_symbol__'))
|
|
5
|
+
return 'angular';
|
|
6
|
+
if (has('__react'))
|
|
7
|
+
return 'react';
|
|
8
|
+
if (has('__svelte'))
|
|
9
|
+
return 'svelte';
|
|
10
|
+
if (has('__vnode'))
|
|
11
|
+
return 'vue';
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
export const getMemberType = (target, key) => {
|
|
3
|
+
var _a;
|
|
4
|
+
return (_a = (target.constructor[CONSTANTS.STATIC_MEMBERS] || target[CONSTANTS.STATIC_MEMBERS] || {})[key]) === null || _a === void 0 ? void 0 : _a[0];
|
|
5
|
+
};
|
package/client/utils/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export * from './appendToMethod.js';
|
|
2
2
|
export * from './call.js';
|
|
3
|
+
export * from './config.js';
|
|
3
4
|
export * from './defineProperty.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './getFramework.js';
|
|
6
|
+
export * from './getMembersKey.js';
|
|
7
|
+
export * from './getMemberType.js';
|
|
6
8
|
export * from './getStyles.js';
|
|
7
9
|
export * from './host.js';
|
|
8
10
|
export * from './isEvent.js';
|
|
9
11
|
export * from './isServer.js';
|
|
12
|
+
export * from './off.js';
|
|
13
|
+
export * from './on.js';
|
|
10
14
|
export * from './parseValue.js';
|
|
11
15
|
export * from './request.js';
|
|
12
16
|
export * from './sync.js';
|
package/client/utils/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export * from './appendToMethod.js';
|
|
2
2
|
export * from './call.js';
|
|
3
|
+
export * from './config.js';
|
|
3
4
|
export * from './defineProperty.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './getFramework.js';
|
|
6
|
+
export * from './getMembersKey.js';
|
|
7
|
+
export * from './getMemberType.js';
|
|
6
8
|
export * from './getStyles.js';
|
|
7
9
|
export * from './host.js';
|
|
8
10
|
export * from './isEvent.js';
|
|
9
11
|
export * from './isServer.js';
|
|
12
|
+
export * from './off.js';
|
|
13
|
+
export * from './on.js';
|
|
10
14
|
export * from './parseValue.js';
|
|
11
15
|
export * from './request.js';
|
|
12
16
|
export * from './sync.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const off: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const on: (target: Window | Document | Element, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
|
package/client/utils/request.js
CHANGED
|
@@ -11,10 +11,12 @@ export const request = (target, state) => {
|
|
|
11
11
|
return run(state);
|
|
12
12
|
run = task({
|
|
13
13
|
canStart: (states, state) => {
|
|
14
|
-
|
|
14
|
+
// TODO: hasChange
|
|
15
|
+
return true;
|
|
15
16
|
},
|
|
16
17
|
canRun: (states) => {
|
|
17
|
-
|
|
18
|
+
// TODO: shouldUpdate
|
|
19
|
+
return true;
|
|
18
20
|
},
|
|
19
21
|
run: (states) => {
|
|
20
22
|
call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
|
package/client/utils/sync.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { on, off } from './event.js';
|
|
2
1
|
import { isEvent } from './isEvent.js';
|
|
2
|
+
import { off } from './off.js';
|
|
3
|
+
import { on } from './on.js';
|
|
3
4
|
import { toEvent } from './toEvent.js';
|
|
4
5
|
import { updateAttribute } from './updateAttribute.js';
|
|
5
6
|
export const sync = (node) => {
|
package/client/utils/task.js
CHANGED
package/compiler/compiler.js
CHANGED
|
@@ -24,11 +24,15 @@ export default (...plugins) => {
|
|
|
24
24
|
let context = {
|
|
25
25
|
filePath
|
|
26
26
|
};
|
|
27
|
+
let timeout;
|
|
27
28
|
for (const plugin of plugins) {
|
|
28
29
|
if (!plugin.next)
|
|
29
30
|
continue;
|
|
31
|
+
clearTimeout(timeout);
|
|
30
32
|
logger.start(`Plugin '${plugin.name}' executing...`);
|
|
31
33
|
const output = await plugin.next(context, global);
|
|
34
|
+
logger.start(`Plugin '${plugin.name}' executed successfully.`);
|
|
35
|
+
timeout = setTimeout(() => logger.stop(), 1500);
|
|
32
36
|
// TODO
|
|
33
37
|
if (output) {
|
|
34
38
|
context.outputs = ((_a = context.outputs) !== null && _a !== void 0 ? _a : [])
|
|
@@ -44,7 +48,6 @@ export default (...plugins) => {
|
|
|
44
48
|
output
|
|
45
49
|
});
|
|
46
50
|
}
|
|
47
|
-
logger.start(`Plugin '${plugin.name}' executed successfully.`);
|
|
48
51
|
global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
|
|
49
52
|
if (context.isInvalid)
|
|
50
53
|
break;
|
|
@@ -2,7 +2,7 @@ import { Context } from '../../types/index.js';
|
|
|
2
2
|
export interface CustomElementOptions {
|
|
3
3
|
typings?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare const customElement: (options?: CustomElementOptions
|
|
5
|
+
export declare const customElement: (options?: CustomElementOptions) => {
|
|
6
6
|
name: string;
|
|
7
7
|
next: (context: Context) => void;
|
|
8
8
|
};
|
|
@@ -4,6 +4,7 @@ import { print, visitor } from '../utils/index.js';
|
|
|
4
4
|
const defaults = {
|
|
5
5
|
typings: true
|
|
6
6
|
};
|
|
7
|
+
// TODO: support {variable && jsxElement}
|
|
7
8
|
export const customElement = (options) => {
|
|
8
9
|
const name = 'customElement';
|
|
9
10
|
options = Object.assign({}, defaults, options);
|
|
@@ -17,6 +18,17 @@ export const customElement = (options) => {
|
|
|
17
18
|
path.node.body.body.unshift(t.classProperty(t.identifier('uhtml')));
|
|
18
19
|
}
|
|
19
20
|
});
|
|
21
|
+
// replace className
|
|
22
|
+
visitor(ast, {
|
|
23
|
+
JSXAttribute(path) {
|
|
24
|
+
if (path.node.name.name != 'className')
|
|
25
|
+
return;
|
|
26
|
+
const hasClass = path.parentPath.node.attributes.some((attribute) => attribute.name.name == 'class');
|
|
27
|
+
if (hasClass)
|
|
28
|
+
return path.remove();
|
|
29
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), path.node.value));
|
|
30
|
+
}
|
|
31
|
+
});
|
|
20
32
|
// jsx to uhtml syntax
|
|
21
33
|
visitor(ast, {
|
|
22
34
|
JSXAttribute: {
|
|
@@ -105,7 +117,9 @@ export const customElement = (options) => {
|
|
|
105
117
|
visitor(ast, {
|
|
106
118
|
Program(path) {
|
|
107
119
|
path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
108
|
-
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
|
|
120
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
|
|
121
|
+
t.tSExpressionWithTypeArguments(t.identifier('HTMLElement')) // TODO
|
|
122
|
+
], t.tsInterfaceBody([
|
|
109
123
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
110
124
|
optional: property.optional,
|
|
111
125
|
leadingComments: property.leadingComments
|
package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
|
|
4
1
|
/**************************************************
|
|
5
2
|
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
3
|
**************************************************/
|
|
@@ -9,7 +6,7 @@
|
|
|
9
6
|
import { {{componentClassNamePrune}} } from './{{fileName}}';
|
|
10
7
|
{{/each}}
|
|
11
8
|
|
|
12
|
-
const All =
|
|
9
|
+
const All = Object.assign({{root.componentClassNamePrune}}, {
|
|
13
10
|
{{#each filterd}}
|
|
14
11
|
{{componentClassNameInCategory}}: {{componentClassNamePrune}},
|
|
15
12
|
{{/each}}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
|
|
4
1
|
/**************************************************
|
|
5
2
|
* THIS FILE IS AUTO-GENERATED, DO NOT EDIT MANUALY
|
|
6
3
|
**************************************************/
|
|
7
4
|
|
|
8
5
|
import { proxy } from '../proxy';
|
|
9
6
|
|
|
10
|
-
{{!-- import { {{importerComponent.root}} as Component } from '{{importerComponent.source}}'; --}}
|
|
11
7
|
import '{{importerComponent.source}}';
|
|
12
8
|
import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
|
|
13
9
|
|
|
@@ -19,7 +15,7 @@ type Renamed = Rename<{{importerComponentType.variable}}, {
|
|
|
19
15
|
{{/each}}
|
|
20
16
|
}>
|
|
21
17
|
|
|
22
|
-
export const {{componentClassNamePrune}} =
|
|
18
|
+
export const {{componentClassNamePrune}} = proxy<{{componentInterfaceName}}, Renamed>(
|
|
23
19
|
'{{componentTag}}',
|
|
24
20
|
[{{#each classProperties}}'{{key.name}}', {{/each}}],
|
|
25
21
|
[{{#each classEvents}}'{{key.name}}', {{/each}}],
|
|
@@ -159,13 +159,13 @@ const setEvent = (element: Element, name: string, handler: EventHandlerType) =>
|
|
|
159
159
|
|
|
160
160
|
const previous = events[name];
|
|
161
161
|
|
|
162
|
-
previous && element.removeEventListener(name, previous);
|
|
162
|
+
previous && element.removeEventListener(paramCase(name), previous);
|
|
163
163
|
|
|
164
164
|
function callback(event: Event) {
|
|
165
165
|
handler && handler.call(this, event);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
element.addEventListener(name, (events[name] = callback));
|
|
168
|
+
element.addEventListener(paramCase(name), (events[name] = callback));
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
const setProps = <ElementType>(element: ElementType, props: PropsType<ElementType>, extra: ExtraType) => {
|
|
@@ -243,7 +243,7 @@ export const proxy = <ElementType, PropType>(
|
|
|
243
243
|
Object.keys(events).forEach((name) => {
|
|
244
244
|
const handler = events[name];
|
|
245
245
|
|
|
246
|
-
(this.element as any).removeEventListener(name, handler);
|
|
246
|
+
(this.element as any).removeEventListener(paramCase(name), handler);
|
|
247
247
|
});
|
|
248
248
|
|
|
249
249
|
delete this.element['$events'];
|
|
@@ -2,7 +2,7 @@ import { Context } from '../../types/index.js';
|
|
|
2
2
|
export interface ExtractOptions {
|
|
3
3
|
prefix?: string;
|
|
4
4
|
}
|
|
5
|
-
export declare const extract: (options?: ExtractOptions
|
|
5
|
+
export declare const extract: (options?: ExtractOptions) => {
|
|
6
6
|
name: string;
|
|
7
7
|
next: (context: Context) => void;
|
|
8
8
|
};
|
|
@@ -35,7 +35,17 @@ export const extract = (options) => {
|
|
|
35
35
|
])));
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
},
|
|
39
|
+
JSXElement(path) {
|
|
40
|
+
var _a;
|
|
41
|
+
const { openingElement } = path.node;
|
|
42
|
+
const name = openingElement.name.name;
|
|
43
|
+
if (!/-/g.test(name))
|
|
44
|
+
return;
|
|
45
|
+
(_a = context.customElementNames) !== null && _a !== void 0 ? _a : (context.customElementNames = []);
|
|
46
|
+
context.customElementNames.push(name);
|
|
47
|
+
context.customElementNames = context.customElementNames.filter((item, index, items) => items.indexOf(item) === index).sort();
|
|
48
|
+
},
|
|
39
49
|
});
|
|
40
50
|
context.directoryPath = path.dirname(context.filePath);
|
|
41
51
|
context.directoryName = path.basename(context.directoryPath);
|
package/compiler/utils/tags.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface TagParsed {
|
|
|
7
7
|
name?: string;
|
|
8
8
|
description?: string;
|
|
9
9
|
}
|
|
10
|
-
export declare const getTag: (node: Node, key?: string
|
|
11
|
-
export declare const getTags: (node: Node, filter?: string
|
|
10
|
+
export declare const getTag: (node: Node, key?: string) => Tag | undefined;
|
|
11
|
+
export declare const getTags: (node: Node, filter?: string) => Array<Tag>;
|
|
12
12
|
export declare const hasTag: (node: Node, name: string) => Boolean;
|
|
13
13
|
export declare const parseTag: (tag: Tag, spliter?: string) => TagParsed;
|
package/constants/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const PACKAGE_NAME = "@htmlplus/element";
|
|
2
2
|
export declare const API_HOST = "$host$";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const API_STATUS = "$status$";
|
|
4
4
|
export declare const DECORATOR_ELEMENT = "Element";
|
|
5
5
|
export declare const DECORATOR_EVENT = "Event";
|
|
6
6
|
export declare const DECORATOR_PROPERTY = "Property";
|
package/constants/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export const PACKAGE_NAME = '@htmlplus/element';
|
|
2
2
|
// apis
|
|
3
3
|
export const API_HOST = '$host$';
|
|
4
|
-
|
|
4
|
+
// TODO
|
|
5
|
+
export const API_STATUS = '$status$';
|
|
5
6
|
// decorators
|
|
6
7
|
export const DECORATOR_ELEMENT = 'Element';
|
|
7
8
|
export const DECORATOR_EVENT = 'Event';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
6
6
|
"description": "Compiler of HTMLPlus",
|
|
@@ -32,28 +32,26 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/htmlplus/element#readme",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@babel/generator": "^7.
|
|
36
|
-
"@babel/parser": "^7.
|
|
37
|
-
"@babel/traverse": "^7.
|
|
38
|
-
"@babel/types": "^7.
|
|
39
|
-
"@types/node": "^
|
|
35
|
+
"@babel/generator": "^7.18.9",
|
|
36
|
+
"@babel/parser": "^7.18.9",
|
|
37
|
+
"@babel/traverse": "^7.18.9",
|
|
38
|
+
"@babel/types": "^7.18.9",
|
|
39
|
+
"@types/node": "^18.6.3",
|
|
40
40
|
"change-case": "^4.1.2",
|
|
41
41
|
"fast-glob": "^3.2.11",
|
|
42
42
|
"fs-extra": "^10.1.0",
|
|
43
43
|
"handlebars": "^4.7.7",
|
|
44
|
-
"listr2": "^
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"typescript": "^4.5.2",
|
|
48
|
-
"uhtml": "^3.0.1"
|
|
44
|
+
"listr2": "^5.0.1",
|
|
45
|
+
"ora": "^6.1.2",
|
|
46
|
+
"typescript": "^4.7.4"
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
|
-
"@trivago/prettier-plugin-sort-imports": "^3.
|
|
49
|
+
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
|
|
52
50
|
"cpy": "^9.0.1",
|
|
53
|
-
"nodemon": "^2.0.
|
|
54
|
-
"prettier": "^2.
|
|
51
|
+
"nodemon": "^2.0.19",
|
|
52
|
+
"prettier": "^2.7.1",
|
|
55
53
|
"rimraf": "^3.0.2",
|
|
56
|
-
"ts-node": "^10.
|
|
57
|
-
"vite": "^
|
|
54
|
+
"ts-node": "^10.9.1",
|
|
55
|
+
"vite": "^3.0.4"
|
|
58
56
|
}
|
|
59
57
|
}
|
package/types/context.d.ts
CHANGED
package/client/utils/event.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
declare type Target = Window | Document | Element;
|
|
2
|
-
export declare const dispatch: (target: Target, event: Event) => boolean;
|
|
3
|
-
export declare const on: (target: Target, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined) => void;
|
|
4
|
-
export declare const off: (target: Target, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined) => void;
|
|
5
|
-
export {};
|
package/client/utils/event.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const dispatch = (target, event) => {
|
|
2
|
-
return target.dispatchEvent(event);
|
|
3
|
-
};
|
|
4
|
-
export const on = (target, type, handler, options) => {
|
|
5
|
-
target.addEventListener(type, handler, options);
|
|
6
|
-
};
|
|
7
|
-
export const off = (target, type, handler, options) => {
|
|
8
|
-
target.removeEventListener(type, handler, options);
|
|
9
|
-
};
|