@htmlplus/element 2.3.0 → 2.4.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/client/decorators/bind.d.ts +1 -1
- package/client/decorators/bind.js +2 -2
- package/client/decorators/consumer.d.ts +6 -0
- package/client/decorators/consumer.js +21 -0
- package/client/decorators/direction.d.ts +1 -1
- package/client/decorators/element.d.ts +2 -2
- package/client/decorators/element.js +9 -9
- package/client/decorators/event.d.ts +2 -2
- package/client/decorators/event.js +6 -7
- package/client/decorators/host.d.ts +1 -1
- package/client/decorators/index.d.ts +2 -0
- package/client/decorators/index.js +2 -0
- package/client/decorators/isRTL.d.ts +1 -1
- package/client/decorators/listen.d.ts +2 -2
- package/client/decorators/listen.js +8 -9
- package/client/decorators/method.d.ts +2 -2
- package/client/decorators/method.js +3 -3
- package/client/decorators/property.d.ts +2 -2
- package/client/decorators/property.js +12 -10
- package/client/decorators/provider.d.ts +6 -0
- package/client/decorators/provider.js +31 -0
- package/client/decorators/query.d.ts +1 -1
- package/client/decorators/queryAll.d.ts +1 -1
- package/client/decorators/slots.d.ts +1 -1
- package/client/decorators/state.d.ts +2 -2
- package/client/decorators/state.js +3 -3
- package/client/decorators/watch.d.ts +2 -2
- package/client/decorators/watch.js +5 -5
- package/client/index.d.ts +1 -1
- package/client/index.js +1 -1
- package/client/utils/appendToMethod.d.ts +1 -1
- package/client/utils/appendToMethod.js +3 -3
- package/client/utils/attributes.d.ts +2 -1
- package/client/utils/attributes.js +3 -1
- package/client/utils/call.d.ts +1 -1
- package/client/utils/direction.d.ts +2 -2
- package/client/utils/event.d.ts +7 -8
- package/client/utils/event.js +30 -17
- package/client/utils/getFramework.d.ts +2 -1
- package/client/utils/getFramework.js +7 -5
- package/client/utils/getStyles.d.ts +2 -2
- package/client/utils/getTag.d.ts +2 -2
- package/client/utils/host.d.ts +2 -2
- package/client/utils/host.js +6 -1
- package/client/utils/isRTL.d.ts +2 -2
- package/client/utils/query.d.ts +2 -2
- package/client/utils/queryAll.d.ts +2 -2
- package/client/utils/request.d.ts +2 -2
- package/client/utils/shadowRoot.d.ts +2 -2
- package/client/utils/slots.d.ts +2 -2
- package/client/utils/slots.js +2 -1
- package/client/utils/toDecorator.d.ts +2 -2
- package/client/utils/toDecorator.js +2 -2
- package/client/utils/updateAttribute.d.ts +2 -1
- package/client/utils/updateAttribute.js +7 -4
- package/package.json +1 -1
- package/transformer/plugins/customElement.js +1 -3
- package/types/index.d.ts +5 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Used to bind a method of a class to the current context,
|
|
3
3
|
* making it easier to reference `this` within the method.
|
|
4
4
|
*/
|
|
5
|
-
export declare function Bind(): (target: Object,
|
|
5
|
+
export declare function Bind(): (target: Object, key: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
6
6
|
configurable: boolean;
|
|
7
7
|
get(): any;
|
|
8
8
|
};
|
|
@@ -4,12 +4,12 @@ import { defineProperty } from '../utils/index.js';
|
|
|
4
4
|
* making it easier to reference `this` within the method.
|
|
5
5
|
*/
|
|
6
6
|
export function Bind() {
|
|
7
|
-
return function (target,
|
|
7
|
+
return function (target, key, descriptor) {
|
|
8
8
|
return {
|
|
9
9
|
configurable: true,
|
|
10
10
|
get() {
|
|
11
11
|
const value = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value.bind(this);
|
|
12
|
-
defineProperty(this,
|
|
12
|
+
defineProperty(this, key, {
|
|
13
13
|
value,
|
|
14
14
|
configurable: true,
|
|
15
15
|
writable: true
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod, dispatch, host } from '../utils/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* TODO
|
|
5
|
+
* @param namespace
|
|
6
|
+
*/
|
|
7
|
+
export function Consumer(namespace) {
|
|
8
|
+
return function (target, key) {
|
|
9
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
10
|
+
const options = {
|
|
11
|
+
bubbles: true
|
|
12
|
+
};
|
|
13
|
+
options.detail = (state) => {
|
|
14
|
+
this[key] = state;
|
|
15
|
+
const successful = !!host(this).parentElement;
|
|
16
|
+
return successful;
|
|
17
|
+
};
|
|
18
|
+
dispatch(this, `internal:context:${namespace}`, options);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
* Indicates whether the [Direction](https://mdn.io/css-direction)
|
|
3
3
|
* of the element is `Right-To-Left` or `Left-To-Right`.
|
|
4
4
|
*/
|
|
5
|
-
export declare function Direction(): (target: import("../../types/index.js").
|
|
5
|
+
export declare function Direction(): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* The class marked with this decorator is considered a
|
|
4
4
|
* [Custom Element](https://mdn.io/using-custom-elements),
|
|
5
5
|
* and its name, in kebab-case, serves as the element name.
|
|
6
6
|
*/
|
|
7
|
-
export declare function Element(): (constructor:
|
|
7
|
+
export declare function Element(): (constructor: HTMLPlusElement) => void;
|
|
@@ -16,20 +16,16 @@ export function Element() {
|
|
|
16
16
|
class Plus extends HTMLElement {
|
|
17
17
|
constructor() {
|
|
18
18
|
super();
|
|
19
|
-
this.attachShadow({
|
|
19
|
+
this.attachShadow({
|
|
20
|
+
mode: 'open',
|
|
21
|
+
delegatesFocus: constructor['delegatesFocus'],
|
|
22
|
+
slotAssignment: constructor['slotAssignment']
|
|
23
|
+
});
|
|
20
24
|
const instance = (this[CONSTANTS.API_INSTANCE] = new constructor());
|
|
21
25
|
instance[CONSTANTS.API_HOST] = () => this;
|
|
22
26
|
// TODO
|
|
23
27
|
call(instance, CONSTANTS.LIFECYCLE_CONSTRUCTED);
|
|
24
28
|
}
|
|
25
|
-
// TODO
|
|
26
|
-
static get formAssociated() {
|
|
27
|
-
return constructor['formAssociated'];
|
|
28
|
-
}
|
|
29
|
-
// TODO
|
|
30
|
-
static get observedAttributes() {
|
|
31
|
-
return constructor['observedAttributes'];
|
|
32
|
-
}
|
|
33
29
|
adoptedCallback() {
|
|
34
30
|
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_ADOPTED);
|
|
35
31
|
}
|
|
@@ -64,6 +60,10 @@ export function Element() {
|
|
|
64
60
|
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
65
61
|
}
|
|
66
62
|
}
|
|
63
|
+
// TODO
|
|
64
|
+
Plus.formAssociated = constructor['formAssociated'];
|
|
65
|
+
// TODO
|
|
66
|
+
Plus.observedAttributes = constructor['observedAttributes'];
|
|
67
67
|
customElements.define(tag, Plus);
|
|
68
68
|
};
|
|
69
69
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* A function type that generates a `CustomEvent`.
|
|
4
4
|
*/
|
|
@@ -32,4 +32,4 @@ export interface EventOptions {
|
|
|
32
32
|
*
|
|
33
33
|
* @param options An object that configures options for the event dispatcher.
|
|
34
34
|
*/
|
|
35
|
-
export declare function Event<T = any>(options?: EventOptions): (target:
|
|
35
|
+
export declare function Event<T = any>(options?: EventOptions): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { kebabCase, pascalCase } from 'change-case';
|
|
2
|
-
import { defineProperty, getConfig, getFramework, host } from '../utils/index.js';
|
|
2
|
+
import { defineProperty, dispatch, getConfig, getFramework, host } from '../utils/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Provides the capability to dispatch a [CustomEvent](https://mdn.io/custom-event)
|
|
5
5
|
* from an element.
|
|
@@ -7,15 +7,15 @@ import { defineProperty, getConfig, getFramework, host } from '../utils/index.js
|
|
|
7
7
|
* @param options An object that configures options for the event dispatcher.
|
|
8
8
|
*/
|
|
9
9
|
export function Event(options = {}) {
|
|
10
|
-
return function (target,
|
|
11
|
-
defineProperty(target,
|
|
10
|
+
return function (target, key) {
|
|
11
|
+
defineProperty(target, key, {
|
|
12
12
|
get() {
|
|
13
13
|
return (detail) => {
|
|
14
14
|
var _a, _b;
|
|
15
15
|
const element = host(this);
|
|
16
|
-
const framework = getFramework(
|
|
16
|
+
const framework = getFramework(this);
|
|
17
17
|
(_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
|
|
18
|
-
let type = String(
|
|
18
|
+
let type = String(key);
|
|
19
19
|
switch (framework) {
|
|
20
20
|
case 'qwik':
|
|
21
21
|
case 'solid':
|
|
@@ -30,8 +30,7 @@ export function Event(options = {}) {
|
|
|
30
30
|
}
|
|
31
31
|
let event;
|
|
32
32
|
event || (event = (_b = getConfig('event', 'resolver')) === null || _b === void 0 ? void 0 : _b({ detail, element, framework, options, type }));
|
|
33
|
-
event || (event =
|
|
34
|
-
element.dispatchEvent(event);
|
|
33
|
+
event || (event = dispatch(this, type, Object.assign(Object.assign({}, options), { detail })));
|
|
35
34
|
return event;
|
|
36
35
|
};
|
|
37
36
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Indicates the host of the element.
|
|
3
3
|
*/
|
|
4
|
-
export declare function Host(): (target: import("../../types/index.js").
|
|
4
|
+
export declare function Host(): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './bind.js';
|
|
2
|
+
export * from './consumer.js';
|
|
2
3
|
export * from './direction.js';
|
|
3
4
|
export * from './element.js';
|
|
4
5
|
export * from './event.js';
|
|
@@ -7,6 +8,7 @@ export * from './isRTL.js';
|
|
|
7
8
|
export * from './listen.js';
|
|
8
9
|
export * from './method.js';
|
|
9
10
|
export * from './property.js';
|
|
11
|
+
export * from './provider.js';
|
|
10
12
|
export * from './query.js';
|
|
11
13
|
export * from './queryAll.js';
|
|
12
14
|
export * from './slots.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from './bind.js';
|
|
2
|
+
export * from './consumer.js';
|
|
2
3
|
export * from './direction.js';
|
|
3
4
|
export * from './element.js';
|
|
4
5
|
export * from './event.js';
|
|
@@ -7,6 +8,7 @@ export * from './isRTL.js';
|
|
|
7
8
|
export * from './listen.js';
|
|
8
9
|
export * from './method.js';
|
|
9
10
|
export * from './property.js';
|
|
11
|
+
export * from './provider.js';
|
|
10
12
|
export * from './query.js';
|
|
11
13
|
export * from './queryAll.js';
|
|
12
14
|
export * from './slots.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Indicates whether the direction of the element is `Right-To-Left` or not.
|
|
3
3
|
*/
|
|
4
|
-
export declare function IsRTL(): (target: import("../../types/index.js").
|
|
4
|
+
export declare function IsRTL(): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* An object that configures
|
|
4
4
|
* [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options)
|
|
@@ -46,7 +46,7 @@ export interface ListenOptions {
|
|
|
46
46
|
* [options](https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener#options)
|
|
47
47
|
* for the event listener.
|
|
48
48
|
*/
|
|
49
|
-
export declare function Listen(type: string, options?: ListenOptions): (target:
|
|
49
|
+
export declare function Listen(type: string, options?: ListenOptions): (target: HTMLPlusElement, key: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
50
50
|
configurable: boolean;
|
|
51
51
|
get(): any;
|
|
52
52
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { appendToMethod,
|
|
2
|
+
import { appendToMethod, on, off } from '../utils/index.js';
|
|
3
3
|
import { Bind } from './bind.js';
|
|
4
4
|
/**
|
|
5
5
|
* Will be called whenever the specified event is delivered to the target
|
|
@@ -11,10 +11,9 @@ import { Bind } from './bind.js';
|
|
|
11
11
|
* for the event listener.
|
|
12
12
|
*/
|
|
13
13
|
export function Listen(type, options) {
|
|
14
|
-
return function (target,
|
|
15
|
-
options = Object.assign({ target: 'host' }, options);
|
|
14
|
+
return function (target, key, descriptor) {
|
|
16
15
|
const element = (instance) => {
|
|
17
|
-
switch (options.target) {
|
|
16
|
+
switch (options === null || options === void 0 ? void 0 : options.target) {
|
|
18
17
|
case 'body':
|
|
19
18
|
return window.document.body;
|
|
20
19
|
case 'document':
|
|
@@ -22,17 +21,17 @@ export function Listen(type, options) {
|
|
|
22
21
|
case 'window':
|
|
23
22
|
return window;
|
|
24
23
|
case 'host':
|
|
25
|
-
return
|
|
24
|
+
return instance;
|
|
26
25
|
default:
|
|
27
|
-
return
|
|
26
|
+
return instance;
|
|
28
27
|
}
|
|
29
28
|
};
|
|
30
29
|
appendToMethod(target, CONSTANTS.LIFECYCLE_CONNECTED, function () {
|
|
31
|
-
on(element(this), type, this[
|
|
30
|
+
on(element(this), type, this[key], options);
|
|
32
31
|
});
|
|
33
32
|
appendToMethod(target, CONSTANTS.LIFECYCLE_DISCONNECTED, function () {
|
|
34
|
-
off(element(this), type, this[
|
|
33
|
+
off(element(this), type, this[key], options);
|
|
35
34
|
});
|
|
36
|
-
return Bind()(target,
|
|
35
|
+
return Bind()(target, key, descriptor);
|
|
37
36
|
};
|
|
38
37
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Provides a way to encapsulate functionality within an element
|
|
4
4
|
* and invoke it as needed, both internally and externally.
|
|
5
5
|
*/
|
|
6
|
-
export declare function Method(): (target:
|
|
6
|
+
export declare function Method(): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -5,10 +5,10 @@ import { appendToMethod, defineProperty, host } from '../utils/index.js';
|
|
|
5
5
|
* and invoke it as needed, both internally and externally.
|
|
6
6
|
*/
|
|
7
7
|
export function Method() {
|
|
8
|
-
return function (target,
|
|
8
|
+
return function (target, key) {
|
|
9
9
|
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
10
|
-
defineProperty(host(this),
|
|
11
|
-
get: () => this[
|
|
10
|
+
defineProperty(host(this), key, {
|
|
11
|
+
get: () => this[key].bind(this)
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
14
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* The configuration for property decorator.
|
|
4
4
|
*/
|
|
@@ -16,4 +16,4 @@ export interface PropertyOptions {
|
|
|
16
16
|
* Creates a reactive property, reflecting a corresponding attribute value,
|
|
17
17
|
* and updates the element when the property is set.
|
|
18
18
|
*/
|
|
19
|
-
export declare function Property(options?: PropertyOptions): (target:
|
|
19
|
+
export declare function Property(options?: PropertyOptions): (target: HTMLPlusElement, key: PropertyKey, descriptor?: PropertyDescriptor) => void;
|
|
@@ -6,10 +6,10 @@ import { appendToMethod, defineProperty, host, request, toProperty, updateAttrib
|
|
|
6
6
|
* and updates the element when the property is set.
|
|
7
7
|
*/
|
|
8
8
|
export function Property(options) {
|
|
9
|
-
return function (target,
|
|
9
|
+
return function (target, key, descriptor) {
|
|
10
10
|
var _a;
|
|
11
11
|
// Converts property name to string.
|
|
12
|
-
const name = String(
|
|
12
|
+
const name = String(key);
|
|
13
13
|
// Registers an attribute that is intricately linked to the property.
|
|
14
14
|
((_a = target.constructor)['observedAttributes'] || (_a['observedAttributes'] = [])).push(kebabCase(name));
|
|
15
15
|
// TODO: This feature is an experimental
|
|
@@ -22,8 +22,10 @@ export function Property(options) {
|
|
|
22
22
|
// Defines a new getter function.
|
|
23
23
|
descriptor.get = function () {
|
|
24
24
|
const value = getter === null || getter === void 0 ? void 0 : getter.apply(this);
|
|
25
|
+
// TODO: target or this
|
|
25
26
|
target[CONSTANTS.API_LOCKED] = true;
|
|
26
|
-
updateAttribute(
|
|
27
|
+
updateAttribute(this, name, value);
|
|
28
|
+
// TODO: target or this
|
|
27
29
|
target[CONSTANTS.API_LOCKED] = false;
|
|
28
30
|
return value;
|
|
29
31
|
};
|
|
@@ -51,31 +53,31 @@ export function Property(options) {
|
|
|
51
53
|
request(this, name, previous, (skipped) => {
|
|
52
54
|
if (!(options === null || options === void 0 ? void 0 : options.reflect) || skipped)
|
|
53
55
|
return;
|
|
56
|
+
// TODO: target or this
|
|
54
57
|
target[CONSTANTS.API_LOCKED] = true;
|
|
55
|
-
updateAttribute(
|
|
58
|
+
updateAttribute(this, name, next);
|
|
59
|
+
// TODO: target or this
|
|
56
60
|
target[CONSTANTS.API_LOCKED] = false;
|
|
57
61
|
});
|
|
58
62
|
}
|
|
59
63
|
// Attaches the getter and setter functions to the current property of the target class.
|
|
60
|
-
defineProperty(target,
|
|
64
|
+
defineProperty(target, key, { get, set });
|
|
61
65
|
}
|
|
62
66
|
// TODO: Check the lifecycle
|
|
63
67
|
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
64
|
-
// Gets the host element from the target class.
|
|
65
|
-
const element = host(this);
|
|
66
68
|
// Defines a getter function to use in the host element.
|
|
67
69
|
const get = () => {
|
|
68
|
-
return this[
|
|
70
|
+
return this[key];
|
|
69
71
|
};
|
|
70
72
|
// Defines a setter function to use in the host element.
|
|
71
73
|
const set = descriptor
|
|
72
74
|
? undefined
|
|
73
75
|
: (input) => {
|
|
74
|
-
this[
|
|
76
|
+
this[key] = toProperty(input, options === null || options === void 0 ? void 0 : options.type);
|
|
75
77
|
};
|
|
76
78
|
// TODO: Check the configuration.
|
|
77
79
|
// Attaches the getter and setter functions to the current property of the host element.
|
|
78
|
-
defineProperty(
|
|
80
|
+
defineProperty(host(this), key, { get, set, configurable: true });
|
|
79
81
|
});
|
|
80
82
|
};
|
|
81
83
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
+
import { appendToMethod, on } from '../utils/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* TODO
|
|
5
|
+
* @param namespace
|
|
6
|
+
*/
|
|
7
|
+
export function Provider(namespace) {
|
|
8
|
+
return function (target, key, descriptor) {
|
|
9
|
+
const symbol = Symbol();
|
|
10
|
+
const update = (instance) => (updater) => {
|
|
11
|
+
const state = descriptor.get.call(instance);
|
|
12
|
+
const successful = updater(state);
|
|
13
|
+
if (successful)
|
|
14
|
+
return;
|
|
15
|
+
instance[symbol].delete(updater);
|
|
16
|
+
};
|
|
17
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
18
|
+
this[symbol] || (this[symbol] = new Set());
|
|
19
|
+
const handler = (event) => {
|
|
20
|
+
event.stopPropagation();
|
|
21
|
+
const updater = event.detail;
|
|
22
|
+
this[symbol].add(updater);
|
|
23
|
+
update(this)(updater);
|
|
24
|
+
};
|
|
25
|
+
on(this, `internal:context:${namespace}`, handler);
|
|
26
|
+
});
|
|
27
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
|
|
28
|
+
this[symbol].forEach(update(this));
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* [Locating DOM elements using selectors](https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors)
|
|
7
7
|
* for more about selectors and how to manage them.
|
|
8
8
|
*/
|
|
9
|
-
export declare function Query(selectors: string): (target: import("../../types/index.js").
|
|
9
|
+
export declare function Query(selectors: string): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* for more information about using selectors to identify elements.
|
|
10
10
|
* Multiple selectors may be specified by separating them using commas.
|
|
11
11
|
*/
|
|
12
|
-
export declare function QueryAll(selectors: string): (target: import("../../types/index.js").
|
|
12
|
+
export declare function QueryAll(selectors: string): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the slots name.
|
|
3
3
|
*/
|
|
4
|
-
export declare function Slots(): (target: import("../../types/index.js").
|
|
4
|
+
export declare function Slots(): (target: import("../../types/index.js").HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Applying this decorator to any `class property` will trigger the
|
|
4
4
|
* element to re-render upon the desired property changes.
|
|
5
5
|
*/
|
|
6
|
-
export declare function State(): (target:
|
|
6
|
+
export declare function State(): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -4,8 +4,8 @@ import { defineProperty, request } from '../utils/index.js';
|
|
|
4
4
|
* element to re-render upon the desired property changes.
|
|
5
5
|
*/
|
|
6
6
|
export function State() {
|
|
7
|
-
return function (target,
|
|
8
|
-
const name = String(
|
|
7
|
+
return function (target, key) {
|
|
8
|
+
const name = String(key);
|
|
9
9
|
const symbol = Symbol();
|
|
10
10
|
function get() {
|
|
11
11
|
return this[symbol];
|
|
@@ -18,6 +18,6 @@ export function State() {
|
|
|
18
18
|
request(this, name, previous);
|
|
19
19
|
}
|
|
20
20
|
// TODO: configurable
|
|
21
|
-
defineProperty(target,
|
|
21
|
+
defineProperty(target, key, { get, set, configurable: true });
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Monitors `@Property` and `@State` to detect changes.
|
|
4
4
|
* The decorated method will be called after any changes,
|
|
@@ -8,4 +8,4 @@ import { PlusElement } from '../../types';
|
|
|
8
8
|
* @param keys Collection of `@Property` and `@State` names.
|
|
9
9
|
* @param immediate Triggers the callback immediately after initialization.
|
|
10
10
|
*/
|
|
11
|
-
export declare function Watch(keys?: string | string[], immediate?: boolean): (target:
|
|
11
|
+
export declare function Watch(keys?: string | string[], immediate?: boolean): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -10,21 +10,21 @@ import { appendToMethod } from '../utils/index.js';
|
|
|
10
10
|
* @param immediate Triggers the callback immediately after initialization.
|
|
11
11
|
*/
|
|
12
12
|
export function Watch(keys, immediate) {
|
|
13
|
-
return function (target,
|
|
13
|
+
return function (target, key) {
|
|
14
14
|
// Gets all keys
|
|
15
|
-
const all = [keys].flat().filter((
|
|
15
|
+
const all = [keys].flat().filter((item) => item);
|
|
16
16
|
// Registers a lifecycle to detect changes.
|
|
17
17
|
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function (states) {
|
|
18
18
|
// Skips the logic if 'immediate' wasn't passed.
|
|
19
19
|
if (!immediate && !this[CONSTANTS.API_RENDER_COMPLETED])
|
|
20
20
|
return;
|
|
21
21
|
// Loops the keys.
|
|
22
|
-
states.forEach((previous,
|
|
22
|
+
states.forEach((previous, item) => {
|
|
23
23
|
// Skips the current key.
|
|
24
|
-
if (all.length && !all.includes(
|
|
24
|
+
if (all.length && !all.includes(item))
|
|
25
25
|
return;
|
|
26
26
|
// Invokes the method with parameters.
|
|
27
|
-
this[
|
|
27
|
+
this[key](this[item], previous, item);
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
};
|
package/client/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './decorators/index.js';
|
|
2
|
-
export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig, type Config, type ConfigOptions } from './utils/index.js';
|
|
2
|
+
export { classes, direction, dispatch, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig, type Config, type ConfigOptions } from './utils/index.js';
|
package/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './decorators/index.js';
|
|
2
|
-
export { classes, direction, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig } from './utils/index.js';
|
|
2
|
+
export { classes, direction, dispatch, getConfig, host, isCSSColor, isRTL, query, queryAll, on, off, slots, toUnit, setConfig } from './utils/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const appendToMethod: (target:
|
|
1
|
+
export declare const appendToMethod: (target: Object, key: PropertyKey, handler: (this: any, ...parameters: Array<any>) => void) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const appendToMethod = (target,
|
|
1
|
+
export const appendToMethod = (target, key, handler) => {
|
|
2
2
|
// Gets the previous function
|
|
3
|
-
const previous = target[
|
|
3
|
+
const previous = target[key];
|
|
4
4
|
// Creates new function
|
|
5
5
|
function next(...parameters) {
|
|
6
6
|
// Calls the previous
|
|
@@ -11,5 +11,5 @@ export const appendToMethod = (target, propertyKey, handler) => {
|
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
13
|
// Replaces the next with the previous one
|
|
14
|
-
target[
|
|
14
|
+
target[key] = next;
|
|
15
15
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const attributes: (target: HTMLElement | HTMLPlusElement, attributes: any[]) => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { off, on } from './event.js';
|
|
2
|
+
import { host } from './host.js';
|
|
2
3
|
import { isEvent } from './isEvent.js';
|
|
3
4
|
import { toEvent } from './toEvent.js';
|
|
4
5
|
import { updateAttribute } from './updateAttribute.js';
|
|
5
6
|
const symbol = Symbol();
|
|
6
|
-
export const attributes = (
|
|
7
|
+
export const attributes = (target, attributes) => {
|
|
8
|
+
const element = host(target);
|
|
7
9
|
const prev = element[symbol] || {};
|
|
8
10
|
const next = Object.assign({}, ...attributes);
|
|
9
11
|
const prevClass = (prev.class || '').split(' ');
|
package/client/utils/call.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const call: (target:
|
|
1
|
+
export declare const call: (target: Object, key: PropertyKey, ...parameters: Array<any>) => any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Indicates whether the [Direction](https://mdn.io/css-direction)
|
|
4
4
|
* of the element is `Right-To-Left` or `Left-To-Right`.
|
|
5
5
|
*/
|
|
6
|
-
export declare const direction: (target:
|
|
6
|
+
export declare const direction: (target: HTMLElement | HTMLPlusElement) => 'ltr' | 'rtl';
|
package/client/utils/event.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
type EventType = 'outside' | (string & {});
|
|
3
|
-
type EventHandler = EventListenerOrEventListenerObject;
|
|
4
|
-
type EventOptions = boolean | AddEventListenerOptions;
|
|
5
|
-
type EventListener = (target: EventTarget, type: EventType, handler: EventHandler, options?: EventOptions) => void;
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
6
2
|
/**
|
|
7
3
|
* TODO
|
|
8
4
|
*/
|
|
9
|
-
export declare const
|
|
5
|
+
export declare const dispatch: <T = any>(target: HTMLElement | HTMLPlusElement, type: string, eventInitDict?: CustomEventInit<T> | undefined) => CustomEvent<T>;
|
|
10
6
|
/**
|
|
11
7
|
* TODO
|
|
12
8
|
*/
|
|
13
|
-
export declare const on:
|
|
14
|
-
|
|
9
|
+
export declare const on: (target: Window | Document | HTMLElement | HTMLPlusElement, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
|
|
10
|
+
/**
|
|
11
|
+
* TODO
|
|
12
|
+
*/
|
|
13
|
+
export declare const off: (target: Window | Document | HTMLElement | HTMLPlusElement, type: string, handler: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void;
|
package/client/utils/event.js
CHANGED
|
@@ -1,35 +1,48 @@
|
|
|
1
|
+
import { host } from './host.js';
|
|
1
2
|
const outsides = [];
|
|
2
3
|
/**
|
|
3
4
|
* TODO
|
|
4
5
|
*/
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return outside.target == target && outside.handler == handler && outside.options == options;
|
|
10
|
-
});
|
|
11
|
-
const outside = outsides[index];
|
|
12
|
-
if (!outside)
|
|
13
|
-
return;
|
|
14
|
-
off(document, outside.type, outside.callback, outside.options);
|
|
15
|
-
outsides.splice(index, 1);
|
|
6
|
+
export const dispatch = (target, type, eventInitDict) => {
|
|
7
|
+
const event = new CustomEvent(type, eventInitDict);
|
|
8
|
+
host(target).dispatchEvent(event);
|
|
9
|
+
return event;
|
|
16
10
|
};
|
|
17
11
|
/**
|
|
18
12
|
* TODO
|
|
19
13
|
*/
|
|
20
14
|
export const on = (target, type, handler, options) => {
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const element = host(target);
|
|
16
|
+
if (type != 'outside') {
|
|
17
|
+
return element.addEventListener(type, handler, options);
|
|
18
|
+
}
|
|
23
19
|
const callback = (event) => {
|
|
24
|
-
!event.composedPath().some((item) => item ==
|
|
20
|
+
!event.composedPath().some((item) => item == element) && handler(event);
|
|
25
21
|
};
|
|
26
22
|
type = 'ontouchstart' in window.document.documentElement ? 'touchstart' : 'click';
|
|
27
23
|
on(document, type, callback, options);
|
|
28
24
|
outsides.push({
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
callback,
|
|
26
|
+
element,
|
|
31
27
|
handler,
|
|
32
28
|
options,
|
|
33
|
-
|
|
29
|
+
type
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* TODO
|
|
34
|
+
*/
|
|
35
|
+
export const off = (target, type, handler, options) => {
|
|
36
|
+
const element = host(target);
|
|
37
|
+
if (type != 'outside') {
|
|
38
|
+
return element.removeEventListener(type, handler, options);
|
|
39
|
+
}
|
|
40
|
+
const index = outsides.findIndex((outside) => {
|
|
41
|
+
return outside.element == element && outside.handler == handler && outside.options == options;
|
|
34
42
|
});
|
|
43
|
+
const outside = outsides[index];
|
|
44
|
+
if (!outside)
|
|
45
|
+
return;
|
|
46
|
+
off(document, outside.type, outside.callback, outside.options);
|
|
47
|
+
outsides.splice(index, 1);
|
|
35
48
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const getFramework: (target: HTMLElement | HTMLPlusElement) => string | undefined;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { host } from './host.js';
|
|
1
2
|
export const getFramework = (target) => {
|
|
2
|
-
|
|
3
|
+
const element = host(target);
|
|
4
|
+
if ('_qc_' in element)
|
|
3
5
|
return 'qwik';
|
|
4
|
-
if ('_$owner' in
|
|
6
|
+
if ('_$owner' in element)
|
|
5
7
|
return 'solid';
|
|
6
|
-
if ('__svelte_meta' in
|
|
8
|
+
if ('__svelte_meta' in element)
|
|
7
9
|
return 'svelte';
|
|
8
|
-
if ('__vnode' in
|
|
10
|
+
if ('__vnode' in element)
|
|
9
11
|
return 'vue';
|
|
10
|
-
const keys = Object.keys(
|
|
12
|
+
const keys = Object.keys(element);
|
|
11
13
|
const has = (input) => keys.some((key) => key.startsWith(input));
|
|
12
14
|
if (has('__zone_symbol__'))
|
|
13
15
|
return 'angular';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getStyles: (target:
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const getStyles: (target: HTMLPlusElement) => string | undefined;
|
package/client/utils/getTag.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const getTag: (target:
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const getTag: (target: HTMLPlusElement) => string | undefined;
|
package/client/utils/host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Indicates the host of the element.
|
|
4
4
|
*/
|
|
5
|
-
export declare const host: (target:
|
|
5
|
+
export declare const host: (target: HTMLElement | HTMLPlusElement) => HTMLElement;
|
package/client/utils/host.js
CHANGED
|
@@ -3,5 +3,10 @@ import * as CONSTANTS from '../../constants/index.js';
|
|
|
3
3
|
* Indicates the host of the element.
|
|
4
4
|
*/
|
|
5
5
|
export const host = (target) => {
|
|
6
|
-
|
|
6
|
+
try {
|
|
7
|
+
return target[CONSTANTS.API_HOST]();
|
|
8
|
+
}
|
|
9
|
+
catch (_a) {
|
|
10
|
+
return target;
|
|
11
|
+
}
|
|
7
12
|
};
|
package/client/utils/isRTL.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Indicates whether the direction of the element is `Right-To-Left` or not.
|
|
4
4
|
*/
|
|
5
|
-
export declare const isRTL: (target:
|
|
5
|
+
export declare const isRTL: (target: HTMLPlusElement) => boolean;
|
package/client/utils/query.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Selects the first element in the shadow dom that matches a specified CSS selector.
|
|
4
4
|
*/
|
|
5
|
-
export declare function query(target:
|
|
5
|
+
export declare function query(target: HTMLPlusElement, selectors: string): Element | null | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Selects all elements in the shadow dom that match a specified CSS selector.
|
|
4
4
|
*/
|
|
5
|
-
export declare function queryAll(target:
|
|
5
|
+
export declare function queryAll(target: HTMLPlusElement, selectors: string): NodeListOf<Element> | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Updates the DOM with a scheduled task.
|
|
4
4
|
* @param target The element instance.
|
|
@@ -6,4 +6,4 @@ import { PlusElement } from '../../types';
|
|
|
6
6
|
* @param previous The previous value of Property/State.
|
|
7
7
|
* @param callback Invoked when the rendering phase is completed.
|
|
8
8
|
*/
|
|
9
|
-
export declare const request: (target:
|
|
9
|
+
export declare const request: (target: HTMLPlusElement, name?: string, previous?: any, callback?: ((skipped: boolean) => void) | undefined) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const shadowRoot: (target:
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const shadowRoot: (target: HTMLElement | HTMLPlusElement) => ShadowRoot | null;
|
package/client/utils/slots.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
2
|
type Slots = {
|
|
3
3
|
[key: string]: boolean;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
6
|
* Returns the slots name.
|
|
7
7
|
*/
|
|
8
|
-
export declare const slots: (target:
|
|
8
|
+
export declare const slots: (target: HTMLElement | HTMLPlusElement) => Slots;
|
|
9
9
|
export {};
|
package/client/utils/slots.js
CHANGED
|
@@ -4,8 +4,9 @@ import { host } from './host.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export const slots = (target) => {
|
|
6
6
|
var _a;
|
|
7
|
+
const element = host(target);
|
|
7
8
|
const slots = {};
|
|
8
|
-
const children = Array.from(
|
|
9
|
+
const children = Array.from(element.childNodes);
|
|
9
10
|
for (const child of children) {
|
|
10
11
|
if (child.nodeName == '#comment')
|
|
11
12
|
continue;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function toDecorator(util: Function, ...parameters: any[]): (target:
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare function toDecorator(util: Function, ...parameters: any[]): (target: HTMLPlusElement, key: PropertyKey) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineProperty } from './defineProperty.js';
|
|
2
2
|
export function toDecorator(util, ...parameters) {
|
|
3
|
-
return function (target,
|
|
4
|
-
defineProperty(target,
|
|
3
|
+
return function (target, key) {
|
|
4
|
+
defineProperty(target, key, {
|
|
5
5
|
get() {
|
|
6
6
|
return util(this, ...parameters);
|
|
7
7
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { HTMLPlusElement } from '../../types';
|
|
2
|
+
export declare const updateAttribute: (target: HTMLElement | HTMLPlusElement, key: string, value: any) => void;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { kebabCase } from 'change-case';
|
|
2
|
-
|
|
2
|
+
import { host } from './host.js';
|
|
3
|
+
export const updateAttribute = (target, key, value) => {
|
|
4
|
+
const element = host(target);
|
|
3
5
|
const name = kebabCase(key);
|
|
4
|
-
if ([undefined, null, false].includes(value))
|
|
5
|
-
return
|
|
6
|
-
|
|
6
|
+
if ([undefined, null, false].includes(value)) {
|
|
7
|
+
return element.removeAttribute(name);
|
|
8
|
+
}
|
|
9
|
+
element.setAttribute(name, value === true ? '' : value);
|
|
7
10
|
};
|
package/package.json
CHANGED
|
@@ -103,9 +103,7 @@ export const customElement = (options) => {
|
|
|
103
103
|
const children = node.children.map(render).flat();
|
|
104
104
|
if (!attributes.length)
|
|
105
105
|
return children;
|
|
106
|
-
|
|
107
|
-
const host = t.callExpression(t.identifier(local), [t.thisExpression()]);
|
|
108
|
-
return [TODO(host, attributes), ...children];
|
|
106
|
+
return [TODO(t.thisExpression(), attributes), ...children];
|
|
109
107
|
}
|
|
110
108
|
const name = node.openingElement.name.name;
|
|
111
109
|
const children = node.children.map(render).flat();
|