@htmlplus/element 2.2.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/README.md +1 -1
- 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 +16 -24
- 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 +4 -4
- package/client/decorators/property.d.ts +3 -3
- package/client/decorators/property.js +68 -30
- 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/getStyles.js +1 -1
- 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/index.d.ts +0 -2
- package/client/utils/index.js +0 -2
- 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/toProperty.js +2 -2
- package/client/utils/updateAttribute.d.ts +2 -1
- package/client/utils/updateAttribute.js +7 -4
- package/constants/index.d.ts +3 -5
- package/constants/index.js +3 -5
- package/package.json +1 -1
- package/transformer/plugins/customElement.js +3 -5
- package/transformer/plugins/document.js +9 -4
- package/transformer/plugins/style.js +1 -1
- package/types/index.d.ts +5 -0
- package/client/utils/addMember.d.ts +0 -2
- package/client/utils/addMember.js +0 -6
- package/client/utils/getMembers.d.ts +0 -8
- package/client/utils/getMembers.js +0 -5
package/README.md
CHANGED
|
@@ -475,7 +475,7 @@ Parameters:
|
|
|
475
475
|
<br />
|
|
476
476
|
- `type` (Optional)
|
|
477
477
|
<br />
|
|
478
|
-
Do not set the value to this property. This value is automatically set during
|
|
478
|
+
Do not set the value to this property. This value is automatically set during transforming.
|
|
479
479
|
<br />
|
|
480
480
|
<br />
|
|
481
481
|
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { camelCase
|
|
1
|
+
import { camelCase } from 'change-case';
|
|
2
2
|
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { call, getConfig,
|
|
3
|
+
import { call, getConfig, getTag, isServer, request } from '../utils/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* The class marked with this decorator is considered a
|
|
6
6
|
* [Custom Element](https://mdn.io/using-custom-elements),
|
|
@@ -13,44 +13,32 @@ export function Element() {
|
|
|
13
13
|
const tag = getTag(constructor);
|
|
14
14
|
if (customElements.get(tag))
|
|
15
15
|
return;
|
|
16
|
-
const members = getMembers(constructor);
|
|
17
16
|
class Plus extends HTMLElement {
|
|
18
17
|
constructor() {
|
|
19
18
|
super();
|
|
20
|
-
this.attachShadow({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
members[key].default = instance[key];
|
|
25
|
-
}
|
|
19
|
+
this.attachShadow({
|
|
20
|
+
mode: 'open',
|
|
21
|
+
delegatesFocus: constructor['delegatesFocus'],
|
|
22
|
+
slotAssignment: constructor['slotAssignment']
|
|
26
23
|
});
|
|
24
|
+
const instance = (this[CONSTANTS.API_INSTANCE] = new constructor());
|
|
27
25
|
instance[CONSTANTS.API_HOST] = () => this;
|
|
28
26
|
// TODO
|
|
29
27
|
call(instance, CONSTANTS.LIFECYCLE_CONSTRUCTED);
|
|
30
28
|
}
|
|
31
|
-
// TODO
|
|
32
|
-
static get formAssociated() {
|
|
33
|
-
return constructor['formAssociated'];
|
|
34
|
-
}
|
|
35
|
-
static get observedAttributes() {
|
|
36
|
-
return Object.keys(members)
|
|
37
|
-
.filter((key) => members[key].type != CONSTANTS.TYPE_FUNCTION)
|
|
38
|
-
.map((key) => kebabCase(key));
|
|
39
|
-
}
|
|
40
29
|
adoptedCallback() {
|
|
41
30
|
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_ADOPTED);
|
|
42
31
|
}
|
|
43
32
|
attributeChangedCallback(attribute, prev, next) {
|
|
44
|
-
var _a;
|
|
45
33
|
const instance = this[CONSTANTS.API_INSTANCE];
|
|
46
34
|
if (instance[CONSTANTS.API_LOCKED])
|
|
47
35
|
return;
|
|
48
36
|
const name = camelCase(attribute);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
// ensures the integrity of readonly properties to prevent potential errors.
|
|
38
|
+
try {
|
|
39
|
+
this[name] = next;
|
|
40
|
+
}
|
|
41
|
+
catch (_a) { }
|
|
54
42
|
}
|
|
55
43
|
connectedCallback() {
|
|
56
44
|
const instance = this[CONSTANTS.API_INSTANCE];
|
|
@@ -72,6 +60,10 @@ export function Element() {
|
|
|
72
60
|
call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_DISCONNECTED);
|
|
73
61
|
}
|
|
74
62
|
}
|
|
63
|
+
// TODO
|
|
64
|
+
Plus.formAssociated = constructor['formAssociated'];
|
|
65
|
+
// TODO
|
|
66
|
+
Plus.observedAttributes = constructor['observedAttributes'];
|
|
75
67
|
customElements.define(tag, Plus);
|
|
76
68
|
};
|
|
77
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,
|
|
9
|
-
appendToMethod(target, CONSTANTS.
|
|
10
|
-
defineProperty(host(this),
|
|
11
|
-
get: () => this[
|
|
8
|
+
return function (target, key) {
|
|
9
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
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
|
*/
|
|
@@ -8,7 +8,7 @@ export interface PropertyOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
reflect?: boolean;
|
|
10
10
|
/**
|
|
11
|
-
* Do not set the value to this property. This value is automatically set during
|
|
11
|
+
* Do not set the value to this property. This value is automatically set during transforming.
|
|
12
12
|
*/
|
|
13
13
|
type?: number;
|
|
14
14
|
}
|
|
@@ -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;
|
|
@@ -1,45 +1,83 @@
|
|
|
1
|
+
import { kebabCase } from 'change-case';
|
|
1
2
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import {
|
|
3
|
+
import { appendToMethod, defineProperty, host, request, toProperty, updateAttribute } from '../utils/index.js';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a reactive property, reflecting a corresponding attribute value,
|
|
5
6
|
* and updates the element when the property is set.
|
|
6
7
|
*/
|
|
7
8
|
export function Property(options) {
|
|
8
|
-
return function (target,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return function (target, key, descriptor) {
|
|
10
|
+
var _a;
|
|
11
|
+
// Converts property name to string.
|
|
12
|
+
const name = String(key);
|
|
13
|
+
// Registers an attribute that is intricately linked to the property.
|
|
14
|
+
((_a = target.constructor)['observedAttributes'] || (_a['observedAttributes'] = [])).push(kebabCase(name));
|
|
15
|
+
// TODO: This feature is an experimental
|
|
16
|
+
// When the property is a getter function.
|
|
17
|
+
if (descriptor) {
|
|
18
|
+
// Checks the reflection.
|
|
19
|
+
if (options === null || options === void 0 ? void 0 : options.reflect) {
|
|
20
|
+
// Stores the original getter function.
|
|
21
|
+
const getter = descriptor.get;
|
|
22
|
+
// Defines a new getter function.
|
|
23
|
+
descriptor.get = function () {
|
|
24
|
+
const value = getter === null || getter === void 0 ? void 0 : getter.apply(this);
|
|
25
|
+
// TODO: target or this
|
|
26
|
+
target[CONSTANTS.API_LOCKED] = true;
|
|
27
|
+
updateAttribute(this, name, value);
|
|
28
|
+
// TODO: target or this
|
|
29
|
+
target[CONSTANTS.API_LOCKED] = false;
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
// TODO: Check the lifecycle
|
|
33
|
+
appendToMethod(target, CONSTANTS.LIFECYCLE_UPDATED, function () {
|
|
34
|
+
// Calls the getter function to update the related attribute.
|
|
35
|
+
this[name];
|
|
36
|
+
});
|
|
37
|
+
}
|
|
14
38
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
39
|
+
// When the property is normal.
|
|
40
|
+
else {
|
|
41
|
+
// Creates a unique symbol.
|
|
42
|
+
const symbol = Symbol();
|
|
43
|
+
// Defines a getter function to use in the target class.
|
|
44
|
+
function get() {
|
|
45
|
+
return this[symbol];
|
|
46
|
+
}
|
|
47
|
+
// Defines a setter function to use in the target class.
|
|
48
|
+
function set(next) {
|
|
49
|
+
const previous = this[symbol];
|
|
50
|
+
if (next === previous)
|
|
22
51
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
52
|
+
this[symbol] = next;
|
|
53
|
+
request(this, name, previous, (skipped) => {
|
|
54
|
+
if (!(options === null || options === void 0 ? void 0 : options.reflect) || skipped)
|
|
55
|
+
return;
|
|
56
|
+
// TODO: target or this
|
|
57
|
+
target[CONSTANTS.API_LOCKED] = true;
|
|
58
|
+
updateAttribute(this, name, next);
|
|
59
|
+
// TODO: target or this
|
|
60
|
+
target[CONSTANTS.API_LOCKED] = false;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Attaches the getter and setter functions to the current property of the target class.
|
|
64
|
+
defineProperty(target, key, { get, set });
|
|
27
65
|
}
|
|
28
|
-
|
|
29
|
-
// TODO: check the lifecycle
|
|
66
|
+
// TODO: Check the lifecycle
|
|
30
67
|
appendToMethod(target, CONSTANTS.LIFECYCLE_CONSTRUCTED, function () {
|
|
31
|
-
|
|
32
|
-
// TODO: experimental for isolated options
|
|
33
|
-
if (element === this)
|
|
34
|
-
return;
|
|
68
|
+
// Defines a getter function to use in the host element.
|
|
35
69
|
const get = () => {
|
|
36
|
-
return this[
|
|
70
|
+
return this[key];
|
|
37
71
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
72
|
+
// Defines a setter function to use in the host element.
|
|
73
|
+
const set = descriptor
|
|
74
|
+
? undefined
|
|
75
|
+
: (input) => {
|
|
76
|
+
this[key] = toProperty(input, options === null || options === void 0 ? void 0 : options.type);
|
|
77
|
+
};
|
|
78
|
+
// TODO: Check the configuration.
|
|
79
|
+
// Attaches the getter and setter functions to the current property of the host element.
|
|
80
|
+
defineProperty(host(this), key, { get, set, configurable: true });
|
|
43
81
|
});
|
|
44
82
|
};
|
|
45
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
2
|
export const getStyles = (target) => {
|
|
3
3
|
var _a;
|
|
4
|
-
return (_a = target.constructor[CONSTANTS.
|
|
4
|
+
return (_a = target.constructor[CONSTANTS.STATIC_STYLE]) !== null && _a !== void 0 ? _a : target[CONSTANTS.STATIC_STYLE];
|
|
5
5
|
};
|
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/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './addMember.js';
|
|
2
1
|
export * from './appendToMethod.js';
|
|
3
2
|
export * from './attributes.js';
|
|
4
3
|
export * from './call.js';
|
|
@@ -8,7 +7,6 @@ export * from './defineProperty.js';
|
|
|
8
7
|
export * from './direction.js';
|
|
9
8
|
export * from './event.js';
|
|
10
9
|
export * from './getFramework.js';
|
|
11
|
-
export * from './getMembers.js';
|
|
12
10
|
export * from './getStyles.js';
|
|
13
11
|
export * from './getTag.js';
|
|
14
12
|
export * from './host.js';
|
package/client/utils/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './addMember.js';
|
|
2
1
|
export * from './appendToMethod.js';
|
|
3
2
|
export * from './attributes.js';
|
|
4
3
|
export * from './call.js';
|
|
@@ -8,7 +7,6 @@ export * from './defineProperty.js';
|
|
|
8
7
|
export * from './direction.js';
|
|
9
8
|
export * from './event.js';
|
|
10
9
|
export * from './getFramework.js';
|
|
11
|
-
export * from './getMembers.js';
|
|
12
10
|
export * from './getStyles.js';
|
|
13
11
|
export * from './getTag.js';
|
|
14
12
|
export * from './host.js';
|
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
|
}
|
|
@@ -7,10 +7,10 @@ export const toProperty = (input, type) => {
|
|
|
7
7
|
if (CONSTANTS.TYPE_BOOLEAN & type) {
|
|
8
8
|
if (string === '')
|
|
9
9
|
return true;
|
|
10
|
-
if (string === 'false')
|
|
11
|
-
return false;
|
|
12
10
|
if (string === 'true')
|
|
13
11
|
return true;
|
|
12
|
+
if (string === 'false')
|
|
13
|
+
return false;
|
|
14
14
|
}
|
|
15
15
|
if (CONSTANTS.TYPE_NUMBER & type) {
|
|
16
16
|
if (string != '' && !isNaN(input)) {
|
|
@@ -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/constants/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const DECORATOR_CSS_VARIABLE = "@Property()";
|
|
|
11
11
|
export declare const DECORATOR_ELEMENT = "Element";
|
|
12
12
|
export declare const DECORATOR_EVENT = "Event";
|
|
13
13
|
export declare const DECORATOR_PROPERTY = "Property";
|
|
14
|
+
export declare const DECORATOR_PROPERTY_TYPE = "type";
|
|
14
15
|
export declare const DECORATOR_STATE = "State";
|
|
15
16
|
export declare const DECORATOR_METHOD = "Method";
|
|
16
17
|
export declare const ELEMENT_HOST_NAME = "host";
|
|
@@ -23,11 +24,8 @@ export declare const LIFECYCLE_LOADED = "loadedCallback";
|
|
|
23
24
|
export declare const LIFECYCLE_UPDATE = "updateCallback";
|
|
24
25
|
export declare const LIFECYCLE_UPDATED = "updatedCallback";
|
|
25
26
|
export declare const METHOD_RENDER = "render";
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const STATIC_MEMBERS_TYPE = "type";
|
|
29
|
-
export declare const STATIC_STYLES = "STYLES";
|
|
30
|
-
export declare const STATIC_TAG = "TAG";
|
|
27
|
+
export declare const STATIC_STYLE = "style";
|
|
28
|
+
export declare const STATIC_TAG = "tag";
|
|
31
29
|
export declare const STYLE_IMPORTED = "STYLE_IMPORTED";
|
|
32
30
|
export declare const TYPE_ARRAY: number;
|
|
33
31
|
export declare const TYPE_BOOLEAN: number;
|
package/constants/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export const DECORATOR_CSS_VARIABLE = '@Property()';
|
|
|
15
15
|
export const DECORATOR_ELEMENT = 'Element';
|
|
16
16
|
export const DECORATOR_EVENT = 'Event';
|
|
17
17
|
export const DECORATOR_PROPERTY = 'Property';
|
|
18
|
+
export const DECORATOR_PROPERTY_TYPE = 'type';
|
|
18
19
|
export const DECORATOR_STATE = 'State';
|
|
19
20
|
export const DECORATOR_METHOD = 'Method';
|
|
20
21
|
// element
|
|
@@ -31,11 +32,8 @@ export const LIFECYCLE_UPDATED = 'updatedCallback';
|
|
|
31
32
|
// methods
|
|
32
33
|
export const METHOD_RENDER = 'render';
|
|
33
34
|
// statics
|
|
34
|
-
export const
|
|
35
|
-
export const
|
|
36
|
-
export const STATIC_MEMBERS_TYPE = 'type';
|
|
37
|
-
export const STATIC_STYLES = 'STYLES';
|
|
38
|
-
export const STATIC_TAG = 'TAG';
|
|
35
|
+
export const STATIC_STYLE = 'style';
|
|
36
|
+
export const STATIC_TAG = 'tag';
|
|
39
37
|
// style
|
|
40
38
|
export const STYLE_IMPORTED = 'STYLE_IMPORTED';
|
|
41
39
|
// types
|
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();
|
|
@@ -273,9 +271,9 @@ export const customElement = (options) => {
|
|
|
273
271
|
}
|
|
274
272
|
const [argument] = expression.arguments;
|
|
275
273
|
argument.properties = argument.properties.filter((property) => {
|
|
276
|
-
return property.key.name != CONSTANTS.
|
|
274
|
+
return property.key.name != CONSTANTS.DECORATOR_PROPERTY_TYPE;
|
|
277
275
|
});
|
|
278
|
-
argument.properties.push(t.objectProperty(t.identifier(CONSTANTS.
|
|
276
|
+
argument.properties.push(t.objectProperty(t.identifier(CONSTANTS.DECORATOR_PROPERTY_TYPE), t.numericLiteral(type)));
|
|
279
277
|
}
|
|
280
278
|
});
|
|
281
279
|
// attach typings
|
|
@@ -116,11 +116,12 @@ export const document = (options) => {
|
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
const properties = context.classProperties.map((property) => {
|
|
119
|
-
var _a, _b;
|
|
119
|
+
var _a, _b, _c;
|
|
120
120
|
const attribute = kebabCase(property.key['name']);
|
|
121
121
|
// TODO
|
|
122
122
|
const initializer = getInitializer(property.value);
|
|
123
123
|
const name = property.key['name'];
|
|
124
|
+
const readonly = property['kind'] == 'get';
|
|
124
125
|
// TODO
|
|
125
126
|
const reflects = (() => {
|
|
126
127
|
if (!property.decorators)
|
|
@@ -143,13 +144,17 @@ export const document = (options) => {
|
|
|
143
144
|
catch (_a) { }
|
|
144
145
|
return false;
|
|
145
146
|
})();
|
|
146
|
-
const required = !property.optional;
|
|
147
|
-
|
|
148
|
-
const
|
|
147
|
+
const required = 'optional' in property && !property.optional;
|
|
148
|
+
// TODO
|
|
149
|
+
const type = property['returnType']
|
|
150
|
+
? print((_a = property['returnType']) === null || _a === void 0 ? void 0 : _a['typeAnnotation'])
|
|
151
|
+
: print((_b = property.typeAnnotation) === null || _b === void 0 ? void 0 : _b['typeAnnotation']);
|
|
152
|
+
const typeReference = getTypeReference(context.fileAST, (_c = property.typeAnnotation) === null || _c === void 0 ? void 0 : _c['typeAnnotation']);
|
|
149
153
|
return Object.assign({
|
|
150
154
|
attribute,
|
|
151
155
|
initializer,
|
|
152
156
|
name,
|
|
157
|
+
readonly,
|
|
153
158
|
reflects,
|
|
154
159
|
required,
|
|
155
160
|
type,
|
|
@@ -34,7 +34,7 @@ export const style = (options) => {
|
|
|
34
34
|
context.styleName = path.basename(context.stylePath, context.styleExtension);
|
|
35
35
|
const { local } = addDependency(context.fileAST, context.stylePath, CONSTANTS.STYLE_IMPORTED, undefined, true);
|
|
36
36
|
// TODO: remove 'local!'
|
|
37
|
-
const property = t.classProperty(t.identifier(CONSTANTS.
|
|
37
|
+
const property = t.classProperty(t.identifier(CONSTANTS.STATIC_STYLE), t.identifier(local), undefined, null, undefined, true);
|
|
38
38
|
t.addComment(property, 'leading', CONSTANTS.COMMENT_AUTO_ADDED, true);
|
|
39
39
|
context.class.body.body.unshift(property);
|
|
40
40
|
};
|
package/types/index.d.ts
CHANGED