compelem 0.2.0-beta → 0.2.1-beta
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/CompElem.d.ts +2 -2
- package/index.js +36 -12
- package/package.json +1 -1
- package/utils.d.ts +3 -1
package/CompElem.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare const CompElem_base: {
|
|
|
26
26
|
*
|
|
27
27
|
* @author holyhigh2
|
|
28
28
|
*/
|
|
29
|
-
export declare
|
|
29
|
+
export declare class CompElem extends CompElem_base implements IComponent {
|
|
30
30
|
#private;
|
|
31
31
|
static __l_globalRule: HTMLStyleElement;
|
|
32
32
|
__events: Record<string, Array<Node | ((e: Event) => void)>[]>;
|
|
@@ -66,7 +66,7 @@ export declare abstract class CompElem extends CompElem_base implements ICompone
|
|
|
66
66
|
/**
|
|
67
67
|
* 每次更新时调用
|
|
68
68
|
*/
|
|
69
|
-
|
|
69
|
+
render(): Template;
|
|
70
70
|
/**
|
|
71
71
|
* dom渲染完毕后调用,该回调内可以query注解初始化完成
|
|
72
72
|
*/
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* compelem v0.2.
|
|
2
|
+
* compelem v0.2.1-beta.1731600715
|
|
3
3
|
* A modern, reactive, fast, lightweight and flexible lib for building web components
|
|
4
4
|
* @holyhigh2
|
|
5
5
|
* https://github.com/holyhigh2/compelem
|
|
6
6
|
*/
|
|
7
|
-
import { toPath, isObject, isDefined, get, isUndefined, isEmpty, has, concat, set, cloneDeep, kebabCase, last, isEqual, startsWith, includes, clone, isFunction, isElement, isArray, initial, find, debounce, throttle, once, remove, map, size, isBlank, join, split, replace, compact, toArray, assign, first,
|
|
7
|
+
import { toPath, isObject, isDefined, get, isUndefined, isEmpty, has, concat, set, merge, cloneDeep, each, kebabCase, last, isEqual, startsWith, includes, clone, isFunction, isElement, isArray, initial, find, debounce, throttle, once, remove, map, size, isBlank, join, split, replace, compact, toArray, assign, first, isString, closest, bind as bind$1, trim, omitBy, camelCase, isNil, some, isNull, fval, test, omit, flatMap, groupBy, reject, filter, slice, head, trimStart, trimEnd, replaceAll, snakeCase, toString, findIndex, call } from 'myfx';
|
|
8
8
|
|
|
9
9
|
function showError(msg) {
|
|
10
10
|
console.error(`[CompElem]`, msg);
|
|
@@ -16,9 +16,13 @@ function showWarn(...args) {
|
|
|
16
16
|
console.warn(`[CompElem]`, ...args);
|
|
17
17
|
}
|
|
18
18
|
//为依赖收集提供标准地址
|
|
19
|
-
function
|
|
19
|
+
function _toUpdatePath(varPath) {
|
|
20
20
|
return toPath(varPath).join("-");
|
|
21
21
|
}
|
|
22
|
+
//获取父类构造
|
|
23
|
+
function _getSuper(cls) {
|
|
24
|
+
return Object.getPrototypeOf(cls);
|
|
25
|
+
}
|
|
22
26
|
|
|
23
27
|
//装饰器类型
|
|
24
28
|
var DecoratorType;
|
|
@@ -144,8 +148,22 @@ function defineProp(target, propertyKey, options, descriptor) {
|
|
|
144
148
|
if (!/[a-z]/.test(propertyKey[0])) {
|
|
145
149
|
showError(`Prop '${propertyKey}' must be in CamelCase`);
|
|
146
150
|
}
|
|
151
|
+
let attrSet;
|
|
147
152
|
if (!has(target.constructor, '__deco_props')) {
|
|
148
|
-
|
|
153
|
+
const mixinProps = {};
|
|
154
|
+
let parentCtor = target.constructor;
|
|
155
|
+
while ((parentCtor = _getSuper(parentCtor)) !== CompElem) {
|
|
156
|
+
merge(mixinProps, parentCtor.__deco_props ? cloneDeep(parentCtor.__deco_props) : {});
|
|
157
|
+
}
|
|
158
|
+
target.constructor.__deco_props = mixinProps;
|
|
159
|
+
attrSet = new Set();
|
|
160
|
+
each(mixinProps, (v, k) => {
|
|
161
|
+
if (v.attribute) {
|
|
162
|
+
let kbb = kebabCase(k);
|
|
163
|
+
attrSet?.add(kbb);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
ObservedAttrsMap.set(target.constructor, attrSet);
|
|
149
167
|
}
|
|
150
168
|
if (descriptor) {
|
|
151
169
|
if (descriptor.get)
|
|
@@ -154,11 +172,6 @@ function defineProp(target, propertyKey, options, descriptor) {
|
|
|
154
172
|
options.setter = descriptor.set;
|
|
155
173
|
}
|
|
156
174
|
if (options.attribute) {
|
|
157
|
-
let attrSet = ObservedAttrsMap.get(target.constructor);
|
|
158
|
-
if (!attrSet) {
|
|
159
|
-
attrSet = new Set();
|
|
160
|
-
ObservedAttrsMap.set(target.constructor, attrSet);
|
|
161
|
-
}
|
|
162
175
|
let kbb = kebabCase(propertyKey);
|
|
163
176
|
attrSet?.add(kbb);
|
|
164
177
|
}
|
|
@@ -279,7 +292,7 @@ function reactive(obj, context) {
|
|
|
279
292
|
let subChain = concat(chain, [prop]);
|
|
280
293
|
let subChainStr = subChain.join('-');
|
|
281
294
|
if (Collector.__renderCollecting) {
|
|
282
|
-
Collector.collect(
|
|
295
|
+
Collector.collect(_toUpdatePath(subChain));
|
|
283
296
|
Collector.setDirectiveQ(subChain);
|
|
284
297
|
}
|
|
285
298
|
else if (Collector.__computeCollecting) {
|
|
@@ -1116,6 +1129,12 @@ class CompElem extends RenderContext(HTMLElement) {
|
|
|
1116
1129
|
* props初始化完成回调
|
|
1117
1130
|
*/
|
|
1118
1131
|
propsReady() { }
|
|
1132
|
+
/**
|
|
1133
|
+
* 每次更新时调用
|
|
1134
|
+
*/
|
|
1135
|
+
render() {
|
|
1136
|
+
throw Error(`[CompElem <${this.tagName}>] Missing render()`);
|
|
1137
|
+
}
|
|
1119
1138
|
/**
|
|
1120
1139
|
* dom渲染完毕后调用,该回调内可以query注解初始化完成
|
|
1121
1140
|
*/
|
|
@@ -1239,7 +1258,7 @@ class CompElem extends RenderContext(HTMLElement) {
|
|
|
1239
1258
|
each(chain, (seg) => {
|
|
1240
1259
|
varPath.push(seg);
|
|
1241
1260
|
let v = get(this, varPath);
|
|
1242
|
-
let pathStr =
|
|
1261
|
+
let pathStr = _toUpdatePath(varPath);
|
|
1243
1262
|
if (pathStr === "#slots") {
|
|
1244
1263
|
pathStr = 'slots';
|
|
1245
1264
|
}
|
|
@@ -2508,7 +2527,12 @@ function state(options) {
|
|
|
2508
2527
|
}
|
|
2509
2528
|
function defineState(target, stateKey, options) {
|
|
2510
2529
|
if (!has(target.constructor, "__deco_states")) {
|
|
2511
|
-
|
|
2530
|
+
const mixinStates = {};
|
|
2531
|
+
let parentCtor = target.constructor;
|
|
2532
|
+
while ((parentCtor = _getSuper(parentCtor)) !== CompElem) {
|
|
2533
|
+
merge(mixinStates, parentCtor.__deco_states ? cloneDeep(parentCtor.__deco_states) : {});
|
|
2534
|
+
}
|
|
2535
|
+
target.constructor.__deco_states = mixinStates;
|
|
2512
2536
|
}
|
|
2513
2537
|
target.constructor.__deco_states[stateKey] = options;
|
|
2514
2538
|
}
|
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { CompElem } from "./CompElem";
|
|
1
2
|
export declare function showError(msg: string): void;
|
|
2
3
|
export declare function showTagError(tagName: string, msg: string): void;
|
|
3
4
|
export declare function showWarn(...args: unknown[]): void;
|
|
4
5
|
export declare function showTagWarn(tagName: string, msg: string): void;
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function _toUpdatePath(varPath: string[]): string;
|
|
7
|
+
export declare function _getSuper(cls: CompElem): any;
|