@htmlplus/element 2.11.0 → 2.13.0
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 +2 -2
- package/bundlers.d.ts +20 -0
- package/{bundlers/vite.js → bundlers.js} +39 -3
- package/client-5FqNUiuz.d.ts +309 -0
- package/client-Dse96R-O.js +1805 -0
- package/client.d.ts +1 -0
- package/client.js +3 -0
- package/constants.d.ts +48 -0
- package/constants.js +60 -0
- package/internal.d.ts +1 -0
- package/internal.js +3 -0
- package/package.json +8 -4
- package/transformer.d.ts +139 -0
- package/transformer.js +1277 -0
- package/bundlers/rollup.d.ts +0 -7
- package/bundlers/rollup.js +0 -23
- package/bundlers/vite.d.ts +0 -8
- package/client/decorators/bind.d.ts +0 -8
- package/client/decorators/bind.js +0 -21
- package/client/decorators/context.d.ts +0 -3
- package/client/decorators/context.js +0 -121
- package/client/decorators/direction.d.ts +0 -5
- package/client/decorators/direction.js +0 -8
- package/client/decorators/element.d.ts +0 -7
- package/client/decorators/element.js +0 -65
- package/client/decorators/event.d.ts +0 -35
- package/client/decorators/event.js +0 -53
- package/client/decorators/host.d.ts +0 -4
- package/client/decorators/host.js +0 -7
- package/client/decorators/index.d.ts +0 -15
- package/client/decorators/index.js +0 -15
- package/client/decorators/isRTL.d.ts +0 -4
- package/client/decorators/isRTL.js +0 -7
- package/client/decorators/listen.d.ts +0 -52
- package/client/decorators/listen.js +0 -37
- package/client/decorators/method.d.ts +0 -6
- package/client/decorators/method.js +0 -15
- package/client/decorators/property.d.ts +0 -25
- package/client/decorators/property.js +0 -94
- package/client/decorators/query.d.ts +0 -9
- package/client/decorators/query.js +0 -12
- package/client/decorators/queryAll.d.ts +0 -12
- package/client/decorators/queryAll.js +0 -15
- package/client/decorators/slots.d.ts +0 -4
- package/client/decorators/slots.js +0 -7
- package/client/decorators/state.d.ts +0 -6
- package/client/decorators/state.js +0 -23
- package/client/decorators/watch.d.ts +0 -11
- package/client/decorators/watch.js +0 -31
- package/client/index.d.ts +0 -2
- package/client/index.js +0 -2
- package/client/utils/appendToMethod.d.ts +0 -1
- package/client/utils/appendToMethod.js +0 -15
- package/client/utils/attributes.d.ts +0 -2
- package/client/utils/attributes.js +0 -33
- package/client/utils/call.d.ts +0 -1
- package/client/utils/call.js +0 -3
- package/client/utils/classes.d.ts +0 -4
- package/client/utils/classes.js +0 -45
- package/client/utils/config.d.ts +0 -39
- package/client/utils/config.js +0 -28
- package/client/utils/defineProperty.d.ts +0 -1
- package/client/utils/defineProperty.js +0 -1
- package/client/utils/direction.d.ts +0 -6
- package/client/utils/direction.js +0 -8
- package/client/utils/event.d.ts +0 -13
- package/client/utils/event.js +0 -48
- package/client/utils/getFramework.d.ts +0 -2
- package/client/utils/getFramework.js +0 -20
- package/client/utils/getStyles.d.ts +0 -2
- package/client/utils/getStyles.js +0 -4
- package/client/utils/getTag.d.ts +0 -2
- package/client/utils/getTag.js +0 -4
- package/client/utils/host.d.ts +0 -5
- package/client/utils/host.js +0 -12
- package/client/utils/index.d.ts +0 -32
- package/client/utils/index.js +0 -32
- package/client/utils/isCSSColor.d.ts +0 -5
- package/client/utils/isCSSColor.js +0 -9
- package/client/utils/isEvent.d.ts +0 -1
- package/client/utils/isEvent.js +0 -3
- package/client/utils/isRTL.d.ts +0 -5
- package/client/utils/isRTL.js +0 -5
- package/client/utils/isServer.d.ts +0 -4
- package/client/utils/isServer.js +0 -6
- package/client/utils/merge.d.ts +0 -1
- package/client/utils/merge.js +0 -22
- package/client/utils/query.d.ts +0 -5
- package/client/utils/query.js +0 -7
- package/client/utils/queryAll.d.ts +0 -5
- package/client/utils/queryAll.js +0 -7
- package/client/utils/request.d.ts +0 -9
- package/client/utils/request.js +0 -65
- package/client/utils/shadowRoot.d.ts +0 -2
- package/client/utils/shadowRoot.js +0 -4
- package/client/utils/slots.d.ts +0 -9
- package/client/utils/slots.js +0 -18
- package/client/utils/styles.d.ts +0 -4
- package/client/utils/styles.js +0 -10
- package/client/utils/task.d.ts +0 -6
- package/client/utils/task.js +0 -34
- package/client/utils/toBoolean.d.ts +0 -1
- package/client/utils/toBoolean.js +0 -3
- package/client/utils/toDecorator.d.ts +0 -2
- package/client/utils/toDecorator.js +0 -10
- package/client/utils/toEvent.d.ts +0 -1
- package/client/utils/toEvent.js +0 -3
- package/client/utils/toProperty.d.ts +0 -1
- package/client/utils/toProperty.js +0 -55
- package/client/utils/toUnit.d.ts +0 -4
- package/client/utils/toUnit.js +0 -10
- package/client/utils/typeOf.d.ts +0 -3
- package/client/utils/typeOf.js +0 -6
- package/client/utils/uhtml.d.ts +0 -22
- package/client/utils/uhtml.js +0 -703
- package/client/utils/updateAttribute.d.ts +0 -2
- package/client/utils/updateAttribute.js +0 -10
- package/constants/index.d.ts +0 -47
- package/constants/index.js +0 -59
- package/transformer/index.d.ts +0 -3
- package/transformer/index.js +0 -3
- package/transformer/plugins/assets.d.ts +0 -7
- package/transformer/plugins/assets.js +0 -26
- package/transformer/plugins/copy.d.ts +0 -9
- package/transformer/plugins/copy.js +0 -29
- package/transformer/plugins/customElement.d.ts +0 -7
- package/transformer/plugins/customElement.js +0 -383
- package/transformer/plugins/document.d.ts +0 -7
- package/transformer/plugins/document.js +0 -206
- package/transformer/plugins/extract.d.ts +0 -2
- package/transformer/plugins/extract.js +0 -22
- package/transformer/plugins/index.d.ts +0 -12
- package/transformer/plugins/index.js +0 -12
- package/transformer/plugins/parse.d.ts +0 -6
- package/transformer/plugins/parse.js +0 -13
- package/transformer/plugins/read.d.ts +0 -7
- package/transformer/plugins/read.js +0 -19
- package/transformer/plugins/readme.d.ts +0 -6
- package/transformer/plugins/readme.js +0 -24
- package/transformer/plugins/style.d.ts +0 -6
- package/transformer/plugins/style.js +0 -42
- package/transformer/plugins/validate.d.ts +0 -2
- package/transformer/plugins/validate.js +0 -40
- package/transformer/plugins/visualStudioCode.d.ts +0 -8
- package/transformer/plugins/visualStudioCode.js +0 -73
- package/transformer/plugins/webTypes.d.ts +0 -10
- package/transformer/plugins/webTypes.js +0 -74
- package/transformer/transformer.d.ts +0 -8
- package/transformer/transformer.js +0 -78
- package/transformer/transformer.types.d.ts +0 -52
- package/transformer/transformer.types.js +0 -1
- package/transformer/utils/addDependency.d.ts +0 -7
- package/transformer/utils/addDependency.js +0 -64
- package/transformer/utils/extractAttribute.d.ts +0 -2
- package/transformer/utils/extractAttribute.js +0 -10
- package/transformer/utils/extractFromComment.d.ts +0 -4
- package/transformer/utils/extractFromComment.js +0 -51
- package/transformer/utils/getInitializer.d.ts +0 -2
- package/transformer/utils/getInitializer.js +0 -3
- package/transformer/utils/getType.d.ts +0 -2
- package/transformer/utils/getType.js +0 -89
- package/transformer/utils/getTypeReference.d.ts +0 -2
- package/transformer/utils/getTypeReference.js +0 -33
- package/transformer/utils/hasDecorator.d.ts +0 -1
- package/transformer/utils/hasDecorator.js +0 -5
- package/transformer/utils/index.d.ts +0 -10
- package/transformer/utils/index.js +0 -10
- package/transformer/utils/print.d.ts +0 -2
- package/transformer/utils/print.js +0 -5
- package/transformer/utils/printType.d.ts +0 -1
- package/transformer/utils/printType.js +0 -69
- package/transformer/utils/visitor.d.ts +0 -2
- package/transformer/utils/visitor.js +0 -5
- package/types/index.d.ts +0 -2
- package/types/index.js +0 -1
package/bundlers/rollup.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { TransformerPlugin } from '../transformer/index.js';
|
|
2
|
-
export declare const htmlplus: (...plugins: Array<TransformerPlugin>) => {
|
|
3
|
-
name: string;
|
|
4
|
-
buildStart(): Promise<void>;
|
|
5
|
-
load(id: any): Promise<string | undefined>;
|
|
6
|
-
buildEnd(error?: Error): Promise<void>;
|
|
7
|
-
};
|
package/bundlers/rollup.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { transformer } from '../transformer/index.js';
|
|
2
|
-
export const htmlplus = (...plugins) => {
|
|
3
|
-
const { start, run, finish } = transformer(...plugins);
|
|
4
|
-
return {
|
|
5
|
-
name: 'htmlplus',
|
|
6
|
-
async buildStart() {
|
|
7
|
-
await start();
|
|
8
|
-
},
|
|
9
|
-
async load(id) {
|
|
10
|
-
if (!id.endsWith('.tsx'))
|
|
11
|
-
return;
|
|
12
|
-
const { script, skipped } = await run(id);
|
|
13
|
-
if (skipped)
|
|
14
|
-
return;
|
|
15
|
-
return script;
|
|
16
|
-
},
|
|
17
|
-
async buildEnd(error) {
|
|
18
|
-
if (error)
|
|
19
|
-
throw error;
|
|
20
|
-
await finish();
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
};
|
package/bundlers/vite.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TransformerPlugin } from '../transformer/index.js';
|
|
2
|
-
export declare const htmlplus: (...plugins: Array<TransformerPlugin>) => {
|
|
3
|
-
name: string;
|
|
4
|
-
buildStart(): Promise<void>;
|
|
5
|
-
load(id: any): Promise<string | undefined>;
|
|
6
|
-
buildEnd(): Promise<void>;
|
|
7
|
-
writeBundle(options: any, bundles: any): Promise<void>;
|
|
8
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Used to bind a method of a class to the current context,
|
|
3
|
-
* making it easier to reference `this` within the method.
|
|
4
|
-
*/
|
|
5
|
-
export declare function Bind(): (target: Object, key: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
6
|
-
configurable: boolean;
|
|
7
|
-
get(): any;
|
|
8
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { defineProperty } from '../utils/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Used to bind a method of a class to the current context,
|
|
4
|
-
* making it easier to reference `this` within the method.
|
|
5
|
-
*/
|
|
6
|
-
export function Bind() {
|
|
7
|
-
return function (target, key, descriptor) {
|
|
8
|
-
return {
|
|
9
|
-
configurable: true,
|
|
10
|
-
get() {
|
|
11
|
-
const value = descriptor?.value.bind(this);
|
|
12
|
-
defineProperty(this, key, {
|
|
13
|
-
value,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true
|
|
16
|
-
});
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
export declare function Provider(namespace: string): (target: HTMLPlusElement, key: PropertyKey, descriptor: PropertyDescriptor) => void;
|
|
3
|
-
export declare function Consumer(namespace: string): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { appendToMethod, dispatch, off, on } from '../utils/index.js';
|
|
3
|
-
export function Provider(namespace) {
|
|
4
|
-
return function (target, key, descriptor) {
|
|
5
|
-
const symbol = Symbol();
|
|
6
|
-
const [MAIN, SUB] = namespace.split('.');
|
|
7
|
-
const prefix = `htmlplus:${MAIN}`;
|
|
8
|
-
const cleanups = (instance) => {
|
|
9
|
-
return (instance[symbol] ||= new Map());
|
|
10
|
-
};
|
|
11
|
-
const update = (instance) => {
|
|
12
|
-
const options = {};
|
|
13
|
-
options.detail = descriptor.get.call(instance);
|
|
14
|
-
dispatch(instance, `${prefix}:update`, options);
|
|
15
|
-
if (!SUB)
|
|
16
|
-
return;
|
|
17
|
-
options.bubbles = true;
|
|
18
|
-
dispatch(instance, `${prefix}:${instance[SUB]}:update`, options);
|
|
19
|
-
};
|
|
20
|
-
// TODO
|
|
21
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
22
|
-
const cleanup = () => {
|
|
23
|
-
off(this, `${prefix}:presence`, onPresence);
|
|
24
|
-
cleanups(this).delete(prefix);
|
|
25
|
-
};
|
|
26
|
-
const onPresence = (event) => {
|
|
27
|
-
event.stopPropagation();
|
|
28
|
-
event.detail(this, descriptor.get.call(this));
|
|
29
|
-
};
|
|
30
|
-
on(this, `${prefix}:presence`, onPresence);
|
|
31
|
-
cleanups(this).set(prefix, cleanup);
|
|
32
|
-
});
|
|
33
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATE, function (states) {
|
|
34
|
-
update(this);
|
|
35
|
-
if (cleanups(this).size && !states.has(SUB))
|
|
36
|
-
return;
|
|
37
|
-
cleanups(this).get(`${prefix}:${states.get(SUB)}`)?.();
|
|
38
|
-
const type = `${prefix}:${this[SUB]}`;
|
|
39
|
-
const cleanup = () => {
|
|
40
|
-
off(window, `${type}:presence`, onPresence);
|
|
41
|
-
cleanups(this).delete(type);
|
|
42
|
-
dispatch(window, `${type}:disconnect`);
|
|
43
|
-
};
|
|
44
|
-
const onPresence = () => {
|
|
45
|
-
update(this);
|
|
46
|
-
};
|
|
47
|
-
on(window, `${type}:presence`, onPresence);
|
|
48
|
-
cleanups(this).set(type, cleanup);
|
|
49
|
-
});
|
|
50
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
51
|
-
cleanups(this).forEach((cleanup) => cleanup());
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
export function Consumer(namespace) {
|
|
56
|
-
return function (target, key) {
|
|
57
|
-
const symbol = Symbol();
|
|
58
|
-
const [MAIN, SUB] = namespace.split('.');
|
|
59
|
-
const prefix = `htmlplus:${MAIN}`;
|
|
60
|
-
const cleanups = (instance) => {
|
|
61
|
-
return (instance[symbol] ||= new Map());
|
|
62
|
-
};
|
|
63
|
-
const update = (instance, state) => {
|
|
64
|
-
instance[key] = state;
|
|
65
|
-
};
|
|
66
|
-
// TODO
|
|
67
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
68
|
-
// TODO
|
|
69
|
-
if (SUB && this[SUB])
|
|
70
|
-
return;
|
|
71
|
-
// TODO
|
|
72
|
-
let connected;
|
|
73
|
-
const options = {
|
|
74
|
-
bubbles: true
|
|
75
|
-
};
|
|
76
|
-
options.detail = (parent, state) => {
|
|
77
|
-
// TODO
|
|
78
|
-
connected = true;
|
|
79
|
-
update(this, state);
|
|
80
|
-
const cleanup = () => {
|
|
81
|
-
off(parent, `${prefix}:update`, onUpdate);
|
|
82
|
-
cleanups(this).delete(prefix);
|
|
83
|
-
update(this, undefined);
|
|
84
|
-
};
|
|
85
|
-
const onUpdate = (event) => {
|
|
86
|
-
update(this, event.detail);
|
|
87
|
-
};
|
|
88
|
-
on(parent, `${prefix}:update`, onUpdate);
|
|
89
|
-
cleanups(this).set(prefix, cleanup);
|
|
90
|
-
};
|
|
91
|
-
dispatch(this, `${prefix}:presence`, options);
|
|
92
|
-
// TODO: When the `Provider` element is activated after the `Consumer` element.
|
|
93
|
-
!connected && setTimeout(() => dispatch(this, `${prefix}:presence`, options));
|
|
94
|
-
});
|
|
95
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATE, function (states) {
|
|
96
|
-
if (cleanups(this).size && !states.has(SUB))
|
|
97
|
-
return;
|
|
98
|
-
cleanups(this).get(`${prefix}:${states.get(SUB)}`)?.();
|
|
99
|
-
const type = `${prefix}:${this[SUB]}`;
|
|
100
|
-
const cleanup = () => {
|
|
101
|
-
off(window, `${type}:disconnect`, onDisconnect);
|
|
102
|
-
off(window, `${type}:update`, onUpdate);
|
|
103
|
-
cleanups(this).delete(type);
|
|
104
|
-
update(this, undefined);
|
|
105
|
-
};
|
|
106
|
-
const onDisconnect = () => {
|
|
107
|
-
update(this, undefined);
|
|
108
|
-
};
|
|
109
|
-
const onUpdate = (event) => {
|
|
110
|
-
update(this, event.detail);
|
|
111
|
-
};
|
|
112
|
-
on(window, `${type}:disconnect`, onDisconnect);
|
|
113
|
-
on(window, `${type}:update`, onUpdate);
|
|
114
|
-
cleanups(this).set(type, cleanup);
|
|
115
|
-
dispatch(window, `${type}:presence`);
|
|
116
|
-
});
|
|
117
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
118
|
-
cleanups(this).forEach((cleanup) => cleanup());
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* The class marked with this decorator is considered a
|
|
4
|
-
* [Custom Element](https://mdn.io/using-custom-elements),
|
|
5
|
-
* and its name, in kebab-case, serves as the element name.
|
|
6
|
-
*/
|
|
7
|
-
export declare function Element(): (constructor: HTMLPlusElement) => void;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { camelCase } from 'change-case';
|
|
2
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { call, getConfig, getTag, isServer, request } from '../utils/index.js';
|
|
4
|
-
/**
|
|
5
|
-
* The class marked with this decorator is considered a
|
|
6
|
-
* [Custom Element](https://mdn.io/using-custom-elements),
|
|
7
|
-
* and its name, in kebab-case, serves as the element name.
|
|
8
|
-
*/
|
|
9
|
-
export function Element() {
|
|
10
|
-
return function (constructor) {
|
|
11
|
-
if (isServer())
|
|
12
|
-
return;
|
|
13
|
-
const tag = getTag(constructor);
|
|
14
|
-
if (customElements.get(tag))
|
|
15
|
-
return;
|
|
16
|
-
customElements.define(tag, proxy(constructor));
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const proxy = (constructor) => {
|
|
20
|
-
return class Plus extends HTMLElement {
|
|
21
|
-
static formAssociated = constructor['formAssociated'];
|
|
22
|
-
static observedAttributes = constructor['observedAttributes'];
|
|
23
|
-
constructor() {
|
|
24
|
-
super();
|
|
25
|
-
this.attachShadow({
|
|
26
|
-
mode: 'open',
|
|
27
|
-
delegatesFocus: constructor['delegatesFocus'],
|
|
28
|
-
slotAssignment: constructor['slotAssignment']
|
|
29
|
-
});
|
|
30
|
-
const instance = (this[CONSTANTS.API_INSTANCE] = new constructor());
|
|
31
|
-
instance[CONSTANTS.API_HOST] = () => this;
|
|
32
|
-
call(instance, CONSTANTS.LIFECYCLE_CONSTRUCTED);
|
|
33
|
-
}
|
|
34
|
-
adoptedCallback() {
|
|
35
|
-
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_ADOPTED);
|
|
36
|
-
}
|
|
37
|
-
attributeChangedCallback(key, prev, next) {
|
|
38
|
-
// Ensures the integrity of readonly properties to prevent potential errors.
|
|
39
|
-
try {
|
|
40
|
-
const attribute = constructor[CONSTANTS.MAPPER]?.[key];
|
|
41
|
-
const property = attribute || camelCase(key);
|
|
42
|
-
this[property] = next;
|
|
43
|
-
}
|
|
44
|
-
catch { }
|
|
45
|
-
}
|
|
46
|
-
connectedCallback() {
|
|
47
|
-
const instance = this[CONSTANTS.API_INSTANCE];
|
|
48
|
-
// TODO: experimental for global config
|
|
49
|
-
Object.assign(instance, getConfig('element', getTag(instance), 'property'));
|
|
50
|
-
instance[CONSTANTS.API_CONNECTED] = true;
|
|
51
|
-
const connect = () => {
|
|
52
|
-
request(instance, undefined, undefined, () => {
|
|
53
|
-
call(instance, CONSTANTS.LIFECYCLE_LOADED);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const callback = call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
57
|
-
if (!callback?.then)
|
|
58
|
-
return connect();
|
|
59
|
-
callback.then(() => connect());
|
|
60
|
-
}
|
|
61
|
-
disconnectedCallback() {
|
|
62
|
-
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* A function type that generates a `CustomEvent`.
|
|
4
|
-
*/
|
|
5
|
-
export type EventEmitter<T = any> = (data?: T) => CustomEvent<T>;
|
|
6
|
-
/**
|
|
7
|
-
* An object that configures
|
|
8
|
-
* [options](https://developer.mozilla.org/docs/Web/API/Event/EventEvent#options)
|
|
9
|
-
* for the event dispatcher.
|
|
10
|
-
*/
|
|
11
|
-
export interface EventOptions {
|
|
12
|
-
/**
|
|
13
|
-
* A boolean value indicating whether the event bubbles.
|
|
14
|
-
* The default is `false`.
|
|
15
|
-
*/
|
|
16
|
-
bubbles?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* A boolean value indicating whether the event can be cancelled.
|
|
19
|
-
* The default is `false`.
|
|
20
|
-
*/
|
|
21
|
-
cancelable?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* A boolean value indicating whether the event will trigger listeners outside of a shadow root
|
|
24
|
-
* (see [Event.composed](https://mdn.io/event-composed) for more details).
|
|
25
|
-
* The default is `false`.
|
|
26
|
-
*/
|
|
27
|
-
composed?: boolean;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Provides the capability to dispatch a [CustomEvent](https://mdn.io/custom-event)
|
|
31
|
-
* from an element.
|
|
32
|
-
*
|
|
33
|
-
* @param options An object that configures options for the event dispatcher.
|
|
34
|
-
*/
|
|
35
|
-
export declare function Event<T = any>(options?: EventOptions): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { kebabCase, pascalCase } from 'change-case';
|
|
2
|
-
import { defineProperty, dispatch, getConfig, getFramework, host } from '../utils/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Provides the capability to dispatch a [CustomEvent](https://mdn.io/custom-event)
|
|
5
|
-
* from an element.
|
|
6
|
-
*
|
|
7
|
-
* @param options An object that configures options for the event dispatcher.
|
|
8
|
-
*/
|
|
9
|
-
export function Event(options = {}) {
|
|
10
|
-
return function (target, key) {
|
|
11
|
-
defineProperty(target, key, {
|
|
12
|
-
get() {
|
|
13
|
-
return (detail) => {
|
|
14
|
-
const element = host(this);
|
|
15
|
-
const framework = getFramework(this);
|
|
16
|
-
options.bubbles ??= false;
|
|
17
|
-
let type = String(key);
|
|
18
|
-
switch (framework) {
|
|
19
|
-
// TODO: Experimental
|
|
20
|
-
case 'blazor':
|
|
21
|
-
options.bubbles = true;
|
|
22
|
-
type = pascalCase(type);
|
|
23
|
-
try {
|
|
24
|
-
window['Blazor'].registerCustomEventType(type, {
|
|
25
|
-
createEventArgs: (event) => ({
|
|
26
|
-
detail: event.detail
|
|
27
|
-
})
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
catch { }
|
|
31
|
-
break;
|
|
32
|
-
case 'qwik':
|
|
33
|
-
case 'solid':
|
|
34
|
-
type = pascalCase(type).toLowerCase();
|
|
35
|
-
break;
|
|
36
|
-
case 'react':
|
|
37
|
-
case 'preact':
|
|
38
|
-
type = pascalCase(type);
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
type = kebabCase(type);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
let event;
|
|
45
|
-
event ||= getConfig('event', 'resolver')?.({ detail, element, framework, options, type });
|
|
46
|
-
event && element.dispatchEvent(event);
|
|
47
|
-
event ||= dispatch(this, type, { ...options, detail });
|
|
48
|
-
return event;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './bind.js';
|
|
2
|
-
export * from './context.js';
|
|
3
|
-
export * from './direction.js';
|
|
4
|
-
export * from './element.js';
|
|
5
|
-
export * from './event.js';
|
|
6
|
-
export * from './host.js';
|
|
7
|
-
export * from './isRTL.js';
|
|
8
|
-
export * from './listen.js';
|
|
9
|
-
export * from './method.js';
|
|
10
|
-
export * from './property.js';
|
|
11
|
-
export * from './query.js';
|
|
12
|
-
export * from './queryAll.js';
|
|
13
|
-
export * from './slots.js';
|
|
14
|
-
export * from './state.js';
|
|
15
|
-
export * from './watch.js';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from './bind.js';
|
|
2
|
-
export * from './context.js';
|
|
3
|
-
export * from './direction.js';
|
|
4
|
-
export * from './element.js';
|
|
5
|
-
export * from './event.js';
|
|
6
|
-
export * from './host.js';
|
|
7
|
-
export * from './isRTL.js';
|
|
8
|
-
export * from './listen.js';
|
|
9
|
-
export * from './method.js';
|
|
10
|
-
export * from './property.js';
|
|
11
|
-
export * from './query.js';
|
|
12
|
-
export * from './queryAll.js';
|
|
13
|
-
export * from './slots.js';
|
|
14
|
-
export * from './state.js';
|
|
15
|
-
export * from './watch.js';
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* An object that configures
|
|
4
|
-
* [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options)
|
|
5
|
-
* for the event listener.
|
|
6
|
-
*/
|
|
7
|
-
export interface ListenOptions {
|
|
8
|
-
/**
|
|
9
|
-
* A boolean value indicating that events of this type will be dispatched to the registered
|
|
10
|
-
* `listener` before being dispatched to any `EventTarget` beneath it in the DOM tree.
|
|
11
|
-
* If not specified, defaults to `false`.
|
|
12
|
-
*/
|
|
13
|
-
capture?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* A boolean value indicating that the `listener` should be invoked at most once after being added.
|
|
16
|
-
* If `true`, the `listener` would be automatically removed when invoked.
|
|
17
|
-
* If not specified, defaults to `false`.
|
|
18
|
-
*/
|
|
19
|
-
once?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* A boolean value that, if `true`,
|
|
22
|
-
* indicates that the function specified by `listener` will never call
|
|
23
|
-
* [preventDefault()](https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault).
|
|
24
|
-
* If a passive listener does call `preventDefault()`,
|
|
25
|
-
* the user agent will do nothing other than generate a console warning.
|
|
26
|
-
*/
|
|
27
|
-
passive?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal).
|
|
30
|
-
* The listener will be removed when the given `AbortSignal` object's
|
|
31
|
-
* [abort()](https://developer.mozilla.org/en-US/docs/Web/API/AbortController/abort) method is called.
|
|
32
|
-
* If not specified, no `AbortSignal` is associated with the listener.
|
|
33
|
-
*/
|
|
34
|
-
signal?: AbortSignal;
|
|
35
|
-
/**
|
|
36
|
-
* The target element, defaults to `host`.
|
|
37
|
-
*/
|
|
38
|
-
target?: 'host' | 'body' | 'document' | 'window';
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Will be called whenever the specified event is delivered to the target
|
|
42
|
-
* [More](https://mdn.io/add-event-listener).
|
|
43
|
-
*
|
|
44
|
-
* @param type A case-sensitive string representing the [Event Type](https://mdn.io/events) to listen for.
|
|
45
|
-
* @param options An object that configures
|
|
46
|
-
* [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options)
|
|
47
|
-
* for the event listener.
|
|
48
|
-
*/
|
|
49
|
-
export declare function Listen(type: string, options?: ListenOptions): (target: HTMLPlusElement, key: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
50
|
-
configurable: boolean;
|
|
51
|
-
get(): any;
|
|
52
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { appendToMethod, on, off } from '../utils/index.js';
|
|
3
|
-
import { Bind } from './bind.js';
|
|
4
|
-
/**
|
|
5
|
-
* Will be called whenever the specified event is delivered to the target
|
|
6
|
-
* [More](https://mdn.io/add-event-listener).
|
|
7
|
-
*
|
|
8
|
-
* @param type A case-sensitive string representing the [Event Type](https://mdn.io/events) to listen for.
|
|
9
|
-
* @param options An object that configures
|
|
10
|
-
* [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options)
|
|
11
|
-
* for the event listener.
|
|
12
|
-
*/
|
|
13
|
-
export function Listen(type, options) {
|
|
14
|
-
return function (target, key, descriptor) {
|
|
15
|
-
const element = (instance) => {
|
|
16
|
-
switch (options?.target) {
|
|
17
|
-
case 'body':
|
|
18
|
-
return window.document.body;
|
|
19
|
-
case 'document':
|
|
20
|
-
return window.document;
|
|
21
|
-
case 'window':
|
|
22
|
-
return window;
|
|
23
|
-
case 'host':
|
|
24
|
-
return instance;
|
|
25
|
-
default:
|
|
26
|
-
return instance;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
30
|
-
on(element(this), type, this[key], options);
|
|
31
|
-
});
|
|
32
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
33
|
-
off(element(this), type, this[key], options);
|
|
34
|
-
});
|
|
35
|
-
return Bind()(target, key, descriptor);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Provides a way to encapsulate functionality within an element
|
|
4
|
-
* and invoke it as needed, both internally and externally.
|
|
5
|
-
*/
|
|
6
|
-
export declare function Method(): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { appendToMethod, defineProperty, host } from '../utils/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Provides a way to encapsulate functionality within an element
|
|
5
|
-
* and invoke it as needed, both internally and externally.
|
|
6
|
-
*/
|
|
7
|
-
export function Method() {
|
|
8
|
-
return function (target, key) {
|
|
9
|
-
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
10
|
-
defineProperty(host(this), key, {
|
|
11
|
-
get: () => this[key].bind(this)
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { HTMLPlusElement } from '../../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* The configuration for property decorator.
|
|
4
|
-
*/
|
|
5
|
-
export interface PropertyOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Specifies the name of the attribute related to the property.
|
|
8
|
-
*/
|
|
9
|
-
attribute?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Whether property value is reflected back to the associated attribute. default is `false`.
|
|
12
|
-
*/
|
|
13
|
-
reflect?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Specifies the property `type` and supports
|
|
16
|
-
* [data types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures).
|
|
17
|
-
* If this value is not set, it will be set automatically during transforming.
|
|
18
|
-
*/
|
|
19
|
-
type?: any;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates a reactive property, reflecting a corresponding attribute value,
|
|
23
|
-
* and updates the element when the property is set.
|
|
24
|
-
*/
|
|
25
|
-
export declare function Property(options?: PropertyOptions): (target: HTMLPlusElement, key: PropertyKey, descriptor?: PropertyDescriptor) => void;
|