@htmlplus/element 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/decorators/element.js +2 -2
- package/client/decorators/index.d.ts +0 -1
- package/client/decorators/index.js +0 -1
- package/client/helpers/index.d.ts +1 -9
- package/client/helpers/index.js +1 -9
- package/client/utils/attributes.d.ts +1 -0
- package/client/utils/attributes.js +31 -0
- package/client/{helpers → utils}/classes.js +1 -1
- package/client/utils/config.d.ts +6 -4
- package/client/utils/config.js +5 -24
- package/client/{helpers → utils}/direction.js +1 -1
- package/client/utils/getNamespace.d.ts +2 -0
- package/client/utils/getNamespace.js +4 -0
- package/client/utils/index.d.ts +12 -1
- package/client/utils/index.js +12 -1
- package/client/utils/merge.d.ts +1 -0
- package/client/utils/merge.js +20 -0
- package/client/{helpers → utils}/query.js +1 -1
- package/client/{helpers → utils}/queryAll.js +1 -1
- package/client/utils/request.js +3 -3
- package/client/{helpers → utils}/slots.js +1 -1
- package/client/{helpers → utils}/styles.js +1 -1
- package/client/utils/uhtml.d.ts +22 -0
- package/client/utils/uhtml.js +699 -0
- package/compiler/plugins/customElement.js +109 -45
- package/compiler/plugins/style.js +1 -2
- package/compiler/utils/addDependency.js +3 -0
- package/constants/index.d.ts +9 -3
- package/constants/index.js +9 -4
- package/package.json +1 -1
- package/client/decorators/attributes.d.ts +0 -2
- package/client/decorators/attributes.js +0 -12
- package/client/utils/syncAttributes.d.ts +0 -1
- package/client/utils/syncAttributes.js +0 -31
- /package/client/{helpers → utils}/classes.d.ts +0 -0
- /package/client/{helpers → utils}/direction.d.ts +0 -0
- /package/client/{helpers → utils}/isRTL.d.ts +0 -0
- /package/client/{helpers → utils}/isRTL.js +0 -0
- /package/client/{helpers → utils}/query.d.ts +0 -0
- /package/client/{helpers → utils}/queryAll.d.ts +0 -0
- /package/client/{helpers → utils}/slots.d.ts +0 -0
- /package/client/{helpers → utils}/styles.d.ts +0 -0
- /package/client/{helpers → utils}/toUnit.d.ts +0 -0
- /package/client/{helpers → utils}/toUnit.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { camelCase, paramCase } from 'change-case';
|
|
2
2
|
import * as CONSTANTS from '../../constants/index.js';
|
|
3
|
-
import { call, fromAttribute, getConfig, getMembers, getTag, isServer, request } from '../utils/index.js';
|
|
3
|
+
import { call, fromAttribute, getConfig, getMembers, getNamespace, getTag, isServer, request } from '../utils/index.js';
|
|
4
4
|
export function Element() {
|
|
5
5
|
return function (constructor) {
|
|
6
6
|
if (isServer())
|
|
@@ -44,7 +44,7 @@ export function Element() {
|
|
|
44
44
|
connectedCallback() {
|
|
45
45
|
const instance = this[CONSTANTS.API_INSTANCE];
|
|
46
46
|
// TODO: experimental for global config
|
|
47
|
-
Object.assign(instance, getConfig('component', getTag(instance), 'property'));
|
|
47
|
+
Object.assign(instance, getConfig(getNamespace(instance), 'component', getTag(instance), 'property'));
|
|
48
48
|
const connect = () => {
|
|
49
49
|
instance[CONSTANTS.API_CONNECTED] = true;
|
|
50
50
|
call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './direction.js';
|
|
3
|
-
export * from './isRTL.js';
|
|
4
|
-
export * from './query.js';
|
|
5
|
-
export * from './queryAll.js';
|
|
6
|
-
export * from './slots.js';
|
|
7
|
-
export * from './styles.js';
|
|
8
|
-
export * from './toUnit.js';
|
|
9
|
-
export { host, isServer, on, off } from '../utils/index.js';
|
|
1
|
+
export { classes, direction, getConfig, host, isRTL, isServer, on, off, query, queryAll, slots, styles, toUnit, setConfig } from '../utils/index.js';
|
package/client/helpers/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './direction.js';
|
|
3
|
-
export * from './isRTL.js';
|
|
4
|
-
export * from './query.js';
|
|
5
|
-
export * from './queryAll.js';
|
|
6
|
-
export * from './slots.js';
|
|
7
|
-
export * from './styles.js';
|
|
8
|
-
export * from './toUnit.js';
|
|
9
|
-
export { host, isServer, on, off } from '../utils/index.js';
|
|
1
|
+
export { classes, direction, getConfig, host, isRTL, isServer, on, off, query, queryAll, slots, styles, toUnit, setConfig } from '../utils/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const attributes: (element: HTMLElement, attributes: any[]) => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { off, on } from './event.js';
|
|
2
|
+
import { isEvent } from './isEvent.js';
|
|
3
|
+
import { toEvent } from './toEvent.js';
|
|
4
|
+
import { updateAttribute } from './updateAttribute.js';
|
|
5
|
+
const symbol = Symbol();
|
|
6
|
+
export const attributes = (element, attributes) => {
|
|
7
|
+
const prev = element[symbol] || {};
|
|
8
|
+
const next = Object.assign({}, ...attributes);
|
|
9
|
+
const prevClass = (prev.class || '').split(' ');
|
|
10
|
+
const nextClass = (next.class || '').split(' ');
|
|
11
|
+
const newClass = element.className
|
|
12
|
+
.split(' ')
|
|
13
|
+
.filter((key) => !prevClass.includes(key) && !nextClass.includes(key))
|
|
14
|
+
.concat(nextClass)
|
|
15
|
+
.filter((key) => key)
|
|
16
|
+
.join(' ');
|
|
17
|
+
updateAttribute(element, 'class', newClass || undefined);
|
|
18
|
+
if (prev.style || next.style)
|
|
19
|
+
element.setAttribute('style', next.style || '');
|
|
20
|
+
for (const key in prev)
|
|
21
|
+
isEvent(key) && off(element, toEvent(key), prev[key]);
|
|
22
|
+
for (const key in next) {
|
|
23
|
+
if (['class', 'style'].includes(key))
|
|
24
|
+
continue;
|
|
25
|
+
if (isEvent(key))
|
|
26
|
+
on(element, toEvent(key), next[key]);
|
|
27
|
+
else
|
|
28
|
+
updateAttribute(element, key, next[key]);
|
|
29
|
+
}
|
|
30
|
+
element[symbol] = Object.assign({}, next);
|
|
31
|
+
};
|
package/client/utils/config.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
interface
|
|
1
|
+
export interface Config {
|
|
2
|
+
asset?: {
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
};
|
|
2
5
|
component?: {
|
|
3
6
|
[key: string]: {
|
|
4
7
|
property?: {
|
|
@@ -7,6 +10,5 @@ interface Options {
|
|
|
7
10
|
};
|
|
8
11
|
};
|
|
9
12
|
}
|
|
10
|
-
export declare const getConfig: (...parameters: string[]) => any;
|
|
11
|
-
export declare const setConfig: (config:
|
|
12
|
-
export {};
|
|
13
|
+
export declare const getConfig: (namespace: string, ...parameters: string[]) => any;
|
|
14
|
+
export declare const setConfig: (namespace: string, config: Config, override?: boolean) => void;
|
package/client/utils/config.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { merge } from './merge.js';
|
|
2
2
|
let defaults = {
|
|
3
3
|
component: {}
|
|
4
4
|
};
|
|
5
|
-
export const getConfig = (...parameters) => {
|
|
5
|
+
export const getConfig = (namespace, ...parameters) => {
|
|
6
6
|
if (typeof window == 'undefined')
|
|
7
7
|
return;
|
|
8
|
-
let config = window[
|
|
8
|
+
let config = window[namespace];
|
|
9
9
|
for (const parameter of parameters) {
|
|
10
10
|
if (!config)
|
|
11
11
|
break;
|
|
@@ -13,27 +13,8 @@ export const getConfig = (...parameters) => {
|
|
|
13
13
|
}
|
|
14
14
|
return config;
|
|
15
15
|
};
|
|
16
|
-
export const setConfig = (config, override) => {
|
|
16
|
+
export const setConfig = (namespace, config, override) => {
|
|
17
17
|
if (typeof window == 'undefined')
|
|
18
18
|
return;
|
|
19
|
-
window[
|
|
20
|
-
};
|
|
21
|
-
const merge = (target, ...sources) => {
|
|
22
|
-
for (const source of sources) {
|
|
23
|
-
if (!source)
|
|
24
|
-
continue;
|
|
25
|
-
if (typeOf(source) != 'object') {
|
|
26
|
-
target = source;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
for (const key of Object.keys(source)) {
|
|
30
|
-
if (target[key] instanceof Object && source[key] instanceof Object && target[key] !== source[key]) {
|
|
31
|
-
target[key] = merge(target[key], source[key]);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
target[key] = source[key];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return target;
|
|
19
|
+
window[namespace] = merge({}, defaults, override ? {} : window[namespace], config);
|
|
39
20
|
};
|
package/client/utils/index.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
export * from './addMember.js';
|
|
2
2
|
export * from './appendToMethod.js';
|
|
3
|
+
export * from './attributes.js';
|
|
3
4
|
export * from './call.js';
|
|
5
|
+
export * from './classes.js';
|
|
4
6
|
export * from './config.js';
|
|
5
7
|
export * from './defineProperty.js';
|
|
8
|
+
export * from './direction.js';
|
|
6
9
|
export * from './event.js';
|
|
7
10
|
export * from './fromAttribute.js';
|
|
8
11
|
export * from './getFramework.js';
|
|
9
12
|
export * from './getMembers.js';
|
|
13
|
+
export * from './getNamespace.js';
|
|
10
14
|
export * from './getStyles.js';
|
|
11
15
|
export * from './getTag.js';
|
|
12
16
|
export * from './host.js';
|
|
13
17
|
export * from './isEvent.js';
|
|
18
|
+
export * from './isRTL.js';
|
|
14
19
|
export * from './isServer.js';
|
|
20
|
+
export * from './merge.js';
|
|
21
|
+
export * from './query.js';
|
|
22
|
+
export * from './queryAll.js';
|
|
15
23
|
export * from './request.js';
|
|
16
24
|
export * from './shadowRoot.js';
|
|
17
|
-
export * from './
|
|
25
|
+
export * from './slots.js';
|
|
26
|
+
export * from './styles.js';
|
|
18
27
|
export * from './task.js';
|
|
19
28
|
export * from './toBoolean.js';
|
|
20
29
|
export * from './toEvent.js';
|
|
30
|
+
export * from './toUnit.js';
|
|
21
31
|
export * from './typeOf.js';
|
|
32
|
+
export * from './uhtml.js';
|
|
22
33
|
export * from './updateAttribute.js';
|
package/client/utils/index.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
export * from './addMember.js';
|
|
2
2
|
export * from './appendToMethod.js';
|
|
3
|
+
export * from './attributes.js';
|
|
3
4
|
export * from './call.js';
|
|
5
|
+
export * from './classes.js';
|
|
4
6
|
export * from './config.js';
|
|
5
7
|
export * from './defineProperty.js';
|
|
8
|
+
export * from './direction.js';
|
|
6
9
|
export * from './event.js';
|
|
7
10
|
export * from './fromAttribute.js';
|
|
8
11
|
export * from './getFramework.js';
|
|
9
12
|
export * from './getMembers.js';
|
|
13
|
+
export * from './getNamespace.js';
|
|
10
14
|
export * from './getStyles.js';
|
|
11
15
|
export * from './getTag.js';
|
|
12
16
|
export * from './host.js';
|
|
13
17
|
export * from './isEvent.js';
|
|
18
|
+
export * from './isRTL.js';
|
|
14
19
|
export * from './isServer.js';
|
|
20
|
+
export * from './merge.js';
|
|
21
|
+
export * from './query.js';
|
|
22
|
+
export * from './queryAll.js';
|
|
15
23
|
export * from './request.js';
|
|
16
24
|
export * from './shadowRoot.js';
|
|
17
|
-
export * from './
|
|
25
|
+
export * from './slots.js';
|
|
26
|
+
export * from './styles.js';
|
|
18
27
|
export * from './task.js';
|
|
19
28
|
export * from './toBoolean.js';
|
|
20
29
|
export * from './toEvent.js';
|
|
30
|
+
export * from './toUnit.js';
|
|
21
31
|
export * from './typeOf.js';
|
|
32
|
+
export * from './uhtml.js';
|
|
22
33
|
export * from './updateAttribute.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const merge: (target: any, ...sources: any[]) => any;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { typeOf } from './typeOf.js';
|
|
2
|
+
export const merge = (target, ...sources) => {
|
|
3
|
+
for (const source of sources) {
|
|
4
|
+
if (!source)
|
|
5
|
+
continue;
|
|
6
|
+
if (typeOf(source) != 'object') {
|
|
7
|
+
target = source;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
for (const key of Object.keys(source)) {
|
|
11
|
+
if (target[key] instanceof Object && source[key] instanceof Object && target[key] !== source[key]) {
|
|
12
|
+
target[key] = merge(target[key], source[key]);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
target[key] = source[key];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
package/client/utils/request.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as CONSTANTS from '../../constants/index.js';
|
|
2
|
-
import { call } from '
|
|
3
|
-
import { task } from '../utils/task.js';
|
|
4
|
-
import { html, render } from '../vendors/uhtml.js';
|
|
2
|
+
import { call } from './call.js';
|
|
5
3
|
import { getStyles } from './getStyles.js';
|
|
6
4
|
import { shadowRoot } from './shadowRoot.js';
|
|
5
|
+
import { task } from './task.js';
|
|
6
|
+
import { html, render } from './uhtml.js';
|
|
7
7
|
/**
|
|
8
8
|
* Updates the DOM with a scheduled task.
|
|
9
9
|
* @param target The component instance.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Holds all details wrappers needed to render the content further on.
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {string} type The hole type, either `html` or `svg`.
|
|
5
|
+
* @param {string[]} template The template literals used to the define the content.
|
|
6
|
+
* @param {Array} values Zero, one, or more interpolated values to render.
|
|
7
|
+
*/
|
|
8
|
+
export class Hole {
|
|
9
|
+
constructor(type: any, template: any, values: any);
|
|
10
|
+
type: any;
|
|
11
|
+
template: any;
|
|
12
|
+
values: any;
|
|
13
|
+
}
|
|
14
|
+
export const html: ((template: any, ...values: any[]) => Hole) & {
|
|
15
|
+
for(ref: any, id: any): any;
|
|
16
|
+
node: (template: any, ...values: any[]) => any;
|
|
17
|
+
};
|
|
18
|
+
export function render(where: any, what: any): any;
|
|
19
|
+
export const svg: ((template: any, ...values: any[]) => Hole) & {
|
|
20
|
+
for(ref: any, id: any): any;
|
|
21
|
+
node: (template: any, ...values: any[]) => any;
|
|
22
|
+
};
|