@htmlplus/element 0.4.2 → 0.4.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/client/decorators/element.js +25 -21
- package/client/decorators/event.js +14 -4
- package/client/decorators/property.js +2 -2
- package/client/utils/appendToMethod.d.ts +1 -2
- package/client/utils/call.d.ts +1 -2
- package/client/utils/config.d.ts +0 -5
- package/client/utils/config.js +0 -1
- 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 +5 -2
- package/client/utils/index.js +5 -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.js +4 -2
- package/client/utils/sync.js +2 -1
- package/client/utils/task.js +1 -1
- package/compiler/plugins/customElement.js +50 -21
- package/compiler/plugins/customElementReact/customElementReact.js +8 -4
- package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +0 -3
- 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/index.d.ts +1 -0
- package/compiler/plugins/index.js +1 -0
- package/compiler/plugins/webTypes.d.ts +11 -0
- package/compiler/plugins/webTypes.js +82 -0
- package/package.json +1 -1
- package/client/utils/event.d.ts +0 -5
- package/client/utils/event.js +0 -11
- package/client/utils/getMembers.d.ts +0 -2
- package/client/utils/getMembers.js +0 -5
|
@@ -1,56 +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
|
-
|
|
38
|
-
|
|
40
|
+
const instance = instances.get(this);
|
|
41
|
+
instance[CONSTANTS.API_STATUS] = 'connected';
|
|
42
|
+
call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
43
|
+
request(instance)
|
|
39
44
|
.then(() => {
|
|
40
|
-
|
|
41
|
-
call(
|
|
45
|
+
instance[CONSTANTS.API_STATUS] = 'loaded';
|
|
46
|
+
call(instance, CONSTANTS.LIFECYCLE_LOADED);
|
|
42
47
|
})
|
|
43
48
|
.catch((error) => {
|
|
44
49
|
throw error;
|
|
45
50
|
});
|
|
46
51
|
}
|
|
47
52
|
disconnectedCallback() {
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const instance = instances.get(this);
|
|
54
|
+
instance[CONSTANTS.API_STATUS] = 'disconnected';
|
|
55
|
+
call(instance, CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
|
-
if (customElements.get(tag))
|
|
53
|
-
return;
|
|
54
58
|
customElements.define(tag, Plus);
|
|
55
59
|
};
|
|
56
60
|
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import { paramCase } from 'change-case';
|
|
2
|
-
import { defineProperty,
|
|
1
|
+
import { paramCase, pascalCase } from 'change-case';
|
|
2
|
+
import { defineProperty, getFramework, host } from '../utils/index.js';
|
|
3
3
|
export function Event(options = {}) {
|
|
4
4
|
return function (target, propertyKey) {
|
|
5
5
|
defineProperty(target, propertyKey, {
|
|
6
6
|
get() {
|
|
7
7
|
return (detail) => {
|
|
8
8
|
var _a;
|
|
9
|
+
const element = host(this);
|
|
10
|
+
const framework = getFramework(element);
|
|
9
11
|
(_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
|
|
10
|
-
|
|
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
|
+
}
|
|
11
21
|
const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
|
|
12
|
-
|
|
22
|
+
element.dispatchEvent(event);
|
|
13
23
|
return event;
|
|
14
24
|
};
|
|
15
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);
|
|
@@ -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;
|
package/client/utils/config.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
interface Options {
|
|
2
|
-
event?: OptionsEvent;
|
|
3
2
|
}
|
|
4
|
-
interface OptionsEvent {
|
|
5
|
-
dispatch?: (target: OptionsEventTarget, event: Event) => boolean;
|
|
6
|
-
}
|
|
7
|
-
declare type OptionsEventTarget = Window | Document | Element;
|
|
8
3
|
export declare const getConfig: () => Options;
|
|
9
4
|
export declare const setConfig: (config: Options) => void;
|
|
10
5
|
export {};
|
package/client/utils/config.js
CHANGED
|
@@ -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
|
@@ -2,12 +2,15 @@ export * from './appendToMethod.js';
|
|
|
2
2
|
export * from './call.js';
|
|
3
3
|
export * from './config.js';
|
|
4
4
|
export * from './defineProperty.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './getFramework.js';
|
|
6
|
+
export * from './getMembersKey.js';
|
|
7
|
+
export * from './getMemberType.js';
|
|
7
8
|
export * from './getStyles.js';
|
|
8
9
|
export * from './host.js';
|
|
9
10
|
export * from './isEvent.js';
|
|
10
11
|
export * from './isServer.js';
|
|
12
|
+
export * from './off.js';
|
|
13
|
+
export * from './on.js';
|
|
11
14
|
export * from './parseValue.js';
|
|
12
15
|
export * from './request.js';
|
|
13
16
|
export * from './sync.js';
|
package/client/utils/index.js
CHANGED
|
@@ -2,12 +2,15 @@ export * from './appendToMethod.js';
|
|
|
2
2
|
export * from './call.js';
|
|
3
3
|
export * from './config.js';
|
|
4
4
|
export * from './defineProperty.js';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
5
|
+
export * from './getFramework.js';
|
|
6
|
+
export * from './getMembersKey.js';
|
|
7
|
+
export * from './getMemberType.js';
|
|
7
8
|
export * from './getStyles.js';
|
|
8
9
|
export * from './host.js';
|
|
9
10
|
export * from './isEvent.js';
|
|
10
11
|
export * from './isServer.js';
|
|
12
|
+
export * from './off.js';
|
|
13
|
+
export * from './on.js';
|
|
11
14
|
export * from './parseValue.js';
|
|
12
15
|
export * from './request.js';
|
|
13
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
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import t from '@babel/types';
|
|
2
|
+
import { pascalCase } from 'change-case';
|
|
2
3
|
import * as CONSTANTS from '../../constants/index.js';
|
|
3
4
|
import { print, visitor } from '../utils/index.js';
|
|
4
5
|
const defaults = {
|
|
5
6
|
typings: true
|
|
6
7
|
};
|
|
8
|
+
// TODO: support {variable && jsxElement}
|
|
7
9
|
export const customElement = (options) => {
|
|
8
10
|
const name = 'customElement';
|
|
9
11
|
options = Object.assign({}, defaults, options);
|
|
@@ -17,6 +19,17 @@ export const customElement = (options) => {
|
|
|
17
19
|
path.node.body.body.unshift(t.classProperty(t.identifier('uhtml')));
|
|
18
20
|
}
|
|
19
21
|
});
|
|
22
|
+
// replace className
|
|
23
|
+
visitor(ast, {
|
|
24
|
+
JSXAttribute(path) {
|
|
25
|
+
if (path.node.name.name != 'className')
|
|
26
|
+
return;
|
|
27
|
+
const hasClass = path.parentPath.node.attributes.some((attribute) => attribute.name.name == 'class');
|
|
28
|
+
if (hasClass)
|
|
29
|
+
return path.remove();
|
|
30
|
+
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), path.node.value));
|
|
31
|
+
}
|
|
32
|
+
});
|
|
20
33
|
// jsx to uhtml syntax
|
|
21
34
|
visitor(ast, {
|
|
22
35
|
JSXAttribute: {
|
|
@@ -104,11 +117,32 @@ export const customElement = (options) => {
|
|
|
104
117
|
if (options === null || options === void 0 ? void 0 : options.typings) {
|
|
105
118
|
visitor(ast, {
|
|
106
119
|
Program(path) {
|
|
120
|
+
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
121
|
+
// TODO
|
|
122
|
+
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
123
|
+
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
124
|
+
optional: property.optional,
|
|
125
|
+
leadingComments: t.cloneNode(property, true).leadingComments
|
|
126
|
+
})),
|
|
127
|
+
...context.classEvents.map((event) => {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return Object.assign(t.tSPropertySignature(t.identifier('on' + pascalCase(event.key['name'])), t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
130
|
+
Object.assign({}, t.identifier('event'), {
|
|
131
|
+
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))
|
|
132
|
+
})
|
|
133
|
+
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
134
|
+
optional: true,
|
|
135
|
+
leadingComments: t.cloneNode(event, true).leadingComments
|
|
136
|
+
});
|
|
137
|
+
})
|
|
138
|
+
]))));
|
|
107
139
|
path.node.body.push(Object.assign(t.tsModuleDeclaration(t.identifier('global'), t.tsModuleBlock([
|
|
108
|
-
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
|
|
140
|
+
t.tsInterfaceDeclaration(t.identifier(context.componentInterfaceName), null, [
|
|
141
|
+
t.tSExpressionWithTypeArguments(t.identifier('HTMLElement')) // TODO
|
|
142
|
+
], t.tsInterfaceBody([
|
|
109
143
|
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
110
144
|
optional: property.optional,
|
|
111
|
-
leadingComments: property.leadingComments
|
|
145
|
+
leadingComments: t.cloneNode(property, true).leadingComments
|
|
112
146
|
}))
|
|
113
147
|
])),
|
|
114
148
|
t.variableDeclaration('var', [
|
|
@@ -121,30 +155,25 @@ export const customElement = (options) => {
|
|
|
121
155
|
]),
|
|
122
156
|
t.tsInterfaceDeclaration(t.identifier('HTMLElementTagNameMap'), null, [], t.tsInterfaceBody([
|
|
123
157
|
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([t.tSTypeReference(t.identifier(context.componentInterfaceName))])))
|
|
158
|
+
])),
|
|
159
|
+
t.tSModuleDeclaration(t.identifier('JSX'), t.tSModuleBlock([
|
|
160
|
+
t.tSInterfaceDeclaration(t.identifier('IntrinsicElements'), undefined, undefined, t.tSInterfaceBody([
|
|
161
|
+
t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([
|
|
162
|
+
t.tSTypeReference(t.identifier(context.componentClassName + 'JSX')),
|
|
163
|
+
t.tSTypeLiteral([
|
|
164
|
+
t.tSIndexSignature([
|
|
165
|
+
Object.assign({}, t.identifier('key'), {
|
|
166
|
+
typeAnnotation: t.tSTypeAnnotation(t.tSStringKeyword())
|
|
167
|
+
})
|
|
168
|
+
], t.tSTypeAnnotation(t.tSAnyKeyword()))
|
|
169
|
+
])
|
|
170
|
+
])))
|
|
171
|
+
]))
|
|
124
172
|
]))
|
|
125
173
|
])), {
|
|
126
174
|
declare: true,
|
|
127
175
|
global: true
|
|
128
176
|
}));
|
|
129
|
-
path.node.body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
|
|
130
|
-
// TODO
|
|
131
|
-
t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
|
|
132
|
-
...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
|
|
133
|
-
optional: property.optional,
|
|
134
|
-
leadingComments: property.leadingComments
|
|
135
|
-
})),
|
|
136
|
-
...context.classEvents.map((event) => {
|
|
137
|
-
var _a, _b;
|
|
138
|
-
return Object.assign(t.tSPropertySignature(event.key, t.tsTypeAnnotation(t.tsFunctionType(undefined, [
|
|
139
|
-
Object.assign({}, t.identifier('event'), {
|
|
140
|
-
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))
|
|
141
|
-
})
|
|
142
|
-
], t.tsTypeAnnotation(t.tsVoidKeyword())))), {
|
|
143
|
-
optional: true,
|
|
144
|
-
leadingComments: event.leadingComments
|
|
145
|
-
});
|
|
146
|
-
})
|
|
147
|
-
]))));
|
|
148
177
|
}
|
|
149
178
|
});
|
|
150
179
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { pascalCase } from 'change-case';
|
|
1
2
|
import { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
|
|
2
3
|
const defaults = {
|
|
3
4
|
compact: false,
|
|
4
5
|
destination: '',
|
|
5
|
-
eventName
|
|
6
|
+
eventName(eventName) {
|
|
7
|
+
return eventName;
|
|
8
|
+
},
|
|
6
9
|
importerComponent(context) {
|
|
7
10
|
return `YOUR_CORE_PACKAGE_NAME#${context.componentClassName}`;
|
|
8
11
|
},
|
|
@@ -36,9 +39,10 @@ export const customElementReact = (options) => {
|
|
|
36
39
|
};
|
|
37
40
|
};
|
|
38
41
|
const classEvents = context.classEvents.map((classEvent) => {
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
return Object.assign(Object.assign({}, classEvent), {
|
|
42
|
+
const from = 'on' + pascalCase(classEvent.key.name);
|
|
43
|
+
const to = options.eventName(from);
|
|
44
|
+
return Object.assign(Object.assign({}, classEvent), { from,
|
|
45
|
+
to });
|
|
42
46
|
});
|
|
43
47
|
const fileName = context.fileName;
|
|
44
48
|
const importerComponent = parse(options.importerComponent(context));
|
|
@@ -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
|
|
|
@@ -15,7 +11,7 @@ type Rename<T, R extends { [K in keyof R]: K extends keyof T ? PropertyKey : "Er
|
|
|
15
11
|
|
|
16
12
|
type Renamed = Rename<{{importerComponentType.variable}}, {
|
|
17
13
|
{{#each classEvents}}
|
|
18
|
-
{{
|
|
14
|
+
{{from}}: '{{to}}',
|
|
19
15
|
{{/each}}
|
|
20
16
|
}>
|
|
21
17
|
|
|
@@ -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'];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Global } from '../../types/index.js';
|
|
2
|
+
export interface WebTypesOptions {
|
|
3
|
+
destination: string;
|
|
4
|
+
docUrl: () => string;
|
|
5
|
+
packageName: string;
|
|
6
|
+
packageVersion: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const webTypes: (options: WebTypesOptions) => {
|
|
9
|
+
name: string;
|
|
10
|
+
finish: (global: Global) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { camelCase, paramCase } from 'change-case';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getTags, print } from '../utils/index.js';
|
|
5
|
+
export const webTypes = (options) => {
|
|
6
|
+
const name = 'webTypes';
|
|
7
|
+
const finish = (global) => {
|
|
8
|
+
const json = {
|
|
9
|
+
'$schema': 'http://json.schemastore.org/web-types',
|
|
10
|
+
'name': options.packageName,
|
|
11
|
+
'version': options.packageVersion,
|
|
12
|
+
'description-markup': 'markdown',
|
|
13
|
+
'framework-config': {
|
|
14
|
+
'enable-when': {
|
|
15
|
+
'node-packages': [options.packageName]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
'contributions': {
|
|
19
|
+
html: {
|
|
20
|
+
elements: global.contexts
|
|
21
|
+
.sort((a, b) => ((a.componentTag || '') > (b.componentTag || '') ? 1 : -1))
|
|
22
|
+
.map((context) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return ({
|
|
25
|
+
'name': context.componentTag,
|
|
26
|
+
'description': '',
|
|
27
|
+
'doc-url': options.docUrl(),
|
|
28
|
+
'js': {
|
|
29
|
+
properties: [
|
|
30
|
+
...(context.classProperties || []).map((property) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return ({
|
|
33
|
+
name: camelCase(property.key['name']),
|
|
34
|
+
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
35
|
+
value: {
|
|
36
|
+
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}),
|
|
40
|
+
...(context.classMethods || []).map((method) => {
|
|
41
|
+
var _a;
|
|
42
|
+
return ({
|
|
43
|
+
name: camelCase(method.key['name']),
|
|
44
|
+
description: (_a = getTags(method).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
45
|
+
value: {}
|
|
46
|
+
});
|
|
47
|
+
})
|
|
48
|
+
],
|
|
49
|
+
events: (_a = context.classEvents) === null || _a === void 0 ? void 0 : _a.map((event) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return ({
|
|
52
|
+
name: paramCase(event.key['name']),
|
|
53
|
+
description: (_a = getTags(event).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value
|
|
54
|
+
});
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
'attributes': (_b = context.classProperties) === null || _b === void 0 ? void 0 : _b.map((property) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
return ({
|
|
60
|
+
name: paramCase(property.key['name']),
|
|
61
|
+
description: (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value,
|
|
62
|
+
value: {
|
|
63
|
+
type: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation'])
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const dirname = path.dirname(options.destination);
|
|
73
|
+
if (!fs.existsSync(dirname))
|
|
74
|
+
fs.mkdirSync(dirname, { recursive: true });
|
|
75
|
+
const raw = JSON.stringify(json, null, 2);
|
|
76
|
+
fs.writeFileSync(options.destination, raw, 'utf8');
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
name,
|
|
80
|
+
finish
|
|
81
|
+
};
|
|
82
|
+
};
|
package/package.json
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) => void;
|
|
4
|
-
export declare const off: (target: Target, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void;
|
|
5
|
-
export {};
|
package/client/utils/event.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { getConfig } from './config.js';
|
|
2
|
-
export const dispatch = (target, event) => {
|
|
3
|
-
var _a, _b;
|
|
4
|
-
return ((_b = (_a = getConfig().event) === null || _a === void 0 ? void 0 : _a.dispatch) === null || _b === void 0 ? void 0 : _b.call(_a, target, event)) || target.dispatchEvent(event);
|
|
5
|
-
};
|
|
6
|
-
export const on = (target, type, handler, options) => {
|
|
7
|
-
target.addEventListener(type, handler, options);
|
|
8
|
-
};
|
|
9
|
-
export const off = (target, type, handler, options) => {
|
|
10
|
-
target.removeEventListener(type, handler, options);
|
|
11
|
-
};
|