@htmlplus/element 2.1.4 → 2.1.5
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/utils/event.js +3 -1
- package/client/utils/merge.js +3 -1
- package/client/utils/request.js +40 -40
- package/client/utils/task.d.ts +1 -1
- package/client/utils/task.js +8 -8
- package/package.json +3 -4
- package/transformer/plugins/customElement.js +9 -3
- package/transformer/plugins/extract.js +2 -1
- package/transformer/utils/getType.js +1 -1
package/client/utils/event.js
CHANGED
|
@@ -5,7 +5,9 @@ const outsides = [];
|
|
|
5
5
|
export const off = (target, type, handler, options) => {
|
|
6
6
|
if (type != 'outside')
|
|
7
7
|
return target.removeEventListener(type, handler, options);
|
|
8
|
-
const index = outsides.findIndex((outside) =>
|
|
8
|
+
const index = outsides.findIndex((outside) => {
|
|
9
|
+
return outside.target == target && outside.handler == handler && outside.options == options;
|
|
10
|
+
});
|
|
9
11
|
const outside = outsides[index];
|
|
10
12
|
if (!outside)
|
|
11
13
|
return;
|
package/client/utils/merge.js
CHANGED
|
@@ -8,7 +8,9 @@ export const merge = (target, ...sources) => {
|
|
|
8
8
|
continue;
|
|
9
9
|
}
|
|
10
10
|
for (const key of Object.keys(source)) {
|
|
11
|
-
if (target[key] instanceof Object &&
|
|
11
|
+
if (target[key] instanceof Object &&
|
|
12
|
+
source[key] instanceof Object &&
|
|
13
|
+
target[key] !== source[key]) {
|
|
12
14
|
target[key] = merge(target[key], source[key]);
|
|
13
15
|
}
|
|
14
16
|
else {
|
package/client/utils/request.js
CHANGED
|
@@ -15,52 +15,52 @@ export const request = (target, name, previous, callback) => {
|
|
|
15
15
|
var _a, _b;
|
|
16
16
|
// Creates/Gets a stacks.
|
|
17
17
|
const stacks = (target[_a = CONSTANTS.API_STACKS] || (target[_a] = new Map()));
|
|
18
|
-
// Creates/Updates a stack
|
|
18
|
+
// Creates/Updates a stack.
|
|
19
19
|
const stack = stacks.get(name) || { callbacks: [], previous };
|
|
20
20
|
// Adds the callback to the stack, if exists.
|
|
21
21
|
callback && stack.callbacks.push(callback);
|
|
22
22
|
// Stores the stack.
|
|
23
23
|
stacks.set(name, stack);
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
callback(callbacks.length - 1 != index);
|
|
54
|
-
});
|
|
24
|
+
// Defines a handler.
|
|
25
|
+
const handler = () => {
|
|
26
|
+
// Skips the rendering phase if DOM isn't ready.
|
|
27
|
+
if (!target[CONSTANTS.API_CONNECTED])
|
|
28
|
+
return;
|
|
29
|
+
// Calculates the states to pass into lifecycles' callbacks.
|
|
30
|
+
const states = new Map(Array.from(stacks)
|
|
31
|
+
.filter((stack) => stack[0])
|
|
32
|
+
.map((stack) => [stack[0], stack[1].previous]));
|
|
33
|
+
// Calls the lifecycle's callback before the rendering phase.
|
|
34
|
+
call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
|
|
35
|
+
// Calculates the template.
|
|
36
|
+
const template = () => {
|
|
37
|
+
// Calculates the markup.
|
|
38
|
+
const markup = call(target, CONSTANTS.METHOD_RENDER);
|
|
39
|
+
// Calculates the styles.
|
|
40
|
+
const styles = getStyles(target);
|
|
41
|
+
// Returns the markup if styles don't exist.
|
|
42
|
+
if (!styles)
|
|
43
|
+
return markup;
|
|
44
|
+
// Returns the markup and styles together.
|
|
45
|
+
return html `<style>${styles}</style>${markup}`;
|
|
46
|
+
};
|
|
47
|
+
// Renders template to the DOM.
|
|
48
|
+
render(shadowRoot(target), template);
|
|
49
|
+
// Invokes requests' callback.
|
|
50
|
+
stacks.forEach((state) => {
|
|
51
|
+
state.callbacks.forEach((callback, index, callbacks) => {
|
|
52
|
+
callback(callbacks.length - 1 != index);
|
|
55
53
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
54
|
+
});
|
|
55
|
+
// Calls the lifecycle's callback after the rendering phase.
|
|
56
|
+
call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
|
|
57
|
+
// Clears stacks.
|
|
58
|
+
stacks.clear();
|
|
59
|
+
// TODO: releated to the @Watch decorator.
|
|
60
|
+
target[CONSTANTS.API_RENDER_COMPLETED] = true;
|
|
61
|
+
};
|
|
62
|
+
// Creates/Gets a micro task function.
|
|
63
|
+
target[_b = CONSTANTS.API_REQUEST] || (target[_b] = task({ handler }));
|
|
64
64
|
// Calls the micro task.
|
|
65
65
|
call(target, CONSTANTS.API_REQUEST);
|
|
66
66
|
};
|
package/client/utils/task.d.ts
CHANGED
package/client/utils/task.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export const task = (options) => {
|
|
2
|
-
let
|
|
2
|
+
let running, promise;
|
|
3
3
|
const run = () => {
|
|
4
4
|
if (options.canStart && !options.canStart())
|
|
5
5
|
return Promise.resolve(false);
|
|
6
|
-
if (!
|
|
6
|
+
if (!running)
|
|
7
7
|
promise = enqueue();
|
|
8
8
|
return promise;
|
|
9
9
|
};
|
|
10
10
|
const enqueue = async () => {
|
|
11
|
-
|
|
11
|
+
running = true;
|
|
12
12
|
try {
|
|
13
13
|
await promise;
|
|
14
14
|
}
|
|
@@ -16,17 +16,17 @@ export const task = (options) => {
|
|
|
16
16
|
Promise.reject(error);
|
|
17
17
|
}
|
|
18
18
|
// TODO: maybe is optional
|
|
19
|
-
if (!
|
|
19
|
+
if (!running)
|
|
20
20
|
return promise;
|
|
21
21
|
try {
|
|
22
22
|
if (options.canRun && !options.canRun())
|
|
23
|
-
return (
|
|
24
|
-
options.
|
|
25
|
-
|
|
23
|
+
return (running = false);
|
|
24
|
+
options.handler();
|
|
25
|
+
running = false;
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
|
|
29
|
+
running = false;
|
|
30
30
|
throw error;
|
|
31
31
|
}
|
|
32
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlplus/element",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"author": "Masood Abdolian <m.abdolian@gmail.com>",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"@babel/template": "^7.23.9",
|
|
38
38
|
"@babel/traverse": "^7.23.9",
|
|
39
39
|
"@babel/types": "^7.23.9",
|
|
40
|
-
"@types/node": "^20.11.
|
|
40
|
+
"@types/node": "^20.11.20",
|
|
41
41
|
"change-case": "^5.4.3",
|
|
42
42
|
"fs-extra": "^11.2.0",
|
|
43
43
|
"glob": "^10.3.10",
|
|
44
|
-
"handlebars": "^4.7.8",
|
|
45
44
|
"ora": "^8.0.1",
|
|
46
45
|
"typescript": "^4.9.5"
|
|
47
46
|
},
|
|
@@ -58,6 +57,6 @@
|
|
|
58
57
|
"rimraf": "^5.0.5",
|
|
59
58
|
"semantic-release": "^23.0.2",
|
|
60
59
|
"tsx": "^4.7.1",
|
|
61
|
-
"vite": "^5.1.
|
|
60
|
+
"vite": "^5.1.4"
|
|
62
61
|
}
|
|
63
62
|
}
|
|
@@ -48,7 +48,10 @@ export const customElement = (options) => {
|
|
|
48
48
|
const { name, value } = path.node;
|
|
49
49
|
if (name.name != 'className')
|
|
50
50
|
return;
|
|
51
|
-
const hasClass = path.parentPath.node.attributes.some((attribute) => {
|
|
51
|
+
const hasClass = path.parentPath.node.attributes.some((attribute) => {
|
|
52
|
+
var _a;
|
|
53
|
+
return ((_a = attribute.name) === null || _a === void 0 ? void 0 : _a.name) == 'class';
|
|
54
|
+
});
|
|
52
55
|
if (hasClass)
|
|
53
56
|
return path.remove();
|
|
54
57
|
path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), value));
|
|
@@ -108,7 +111,9 @@ export const customElement = (options) => {
|
|
|
108
111
|
const children = node.children.map(render).flat();
|
|
109
112
|
const parts = [];
|
|
110
113
|
parts.push('<', name);
|
|
111
|
-
const hasSpreadAttribute = attributes.some((attribute) =>
|
|
114
|
+
const hasSpreadAttribute = attributes.some((attribute) => {
|
|
115
|
+
return attribute.type == 'JSXSpreadAttribute';
|
|
116
|
+
});
|
|
112
117
|
if (hasSpreadAttribute) {
|
|
113
118
|
parts.push(' ', TODO(t.identifier('TODO'), attributes));
|
|
114
119
|
}
|
|
@@ -251,7 +256,8 @@ export const customElement = (options) => {
|
|
|
251
256
|
break;
|
|
252
257
|
}
|
|
253
258
|
// TODO
|
|
254
|
-
if ((input === null || input === void 0 ? void 0 : input.type) == 'TSParenthesizedType' &&
|
|
259
|
+
if ((input === null || input === void 0 ? void 0 : input.type) == 'TSParenthesizedType' &&
|
|
260
|
+
((_a = input === null || input === void 0 ? void 0 : input.typeAnnotation) === null || _a === void 0 ? void 0 : _a.type) == 'TSIntersectionType') {
|
|
255
261
|
let types = input.types || input.typeAnnotation.types;
|
|
256
262
|
if (types.length != 2)
|
|
257
263
|
return;
|
|
@@ -14,7 +14,8 @@ export const extract = () => {
|
|
|
14
14
|
context.classMembers = ((_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.body) || [];
|
|
15
15
|
// TODO
|
|
16
16
|
if (path.parentPath.isExportNamedDeclaration() && !((_c = context.class) === null || _c === void 0 ? void 0 : _c.leadingComments)) {
|
|
17
|
-
context.class['_leadingComments'] =
|
|
17
|
+
context.class['_leadingComments'] =
|
|
18
|
+
t.cloneNode(path.parentPath.node, true).leadingComments || [];
|
|
18
19
|
}
|
|
19
20
|
path.skip();
|
|
20
21
|
}
|