compelem 0.20.0-b2 → 0.20.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/CompElem.d.ts +19 -47
- package/IComponent.d.ts +4 -19
- package/README.md +63 -41
- package/compelem.umd.js +814 -839
- package/constants.d.ts +19 -7
- package/decorators/event.d.ts +1 -1
- package/events/event.d.ts +1 -1
- package/index.d.ts +2 -3
- package/index.js +816 -839
- package/package.json +1 -1
- package/reactive.d.ts +3 -1
- package/render/CssTemplate.d.ts +3 -3
- package/render/render.d.ts +1 -8
package/compelem.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* compelem v0.20.0
|
|
2
|
+
* compelem v0.20.0.1773502279
|
|
3
3
|
* A modern, reactive, fast, lightweight and flexible lib for building web components
|
|
4
4
|
* @holyhigh2
|
|
5
5
|
* git+https://github.com/holyhigh2/compelem.git
|
|
@@ -14,29 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
var myfx__default = /*#__PURE__*/_interopDefaultLegacy(myfx);
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* 样式模板
|
|
19
|
-
* @author holyhigh2
|
|
20
|
-
*/
|
|
21
|
-
class CssTemplate {
|
|
22
|
-
strings;
|
|
23
|
-
vars;
|
|
24
|
-
constructor(strings, vars) {
|
|
25
|
-
this.strings = myfx.concat(strings);
|
|
26
|
-
this.vars = vars;
|
|
27
|
-
}
|
|
28
|
-
getCss(comp) {
|
|
29
|
-
let str = '';
|
|
30
|
-
this.strings.forEach((s, i) => {
|
|
31
|
-
str = str + s + (this.vars[i] ?? '');
|
|
32
|
-
});
|
|
33
|
-
return str;
|
|
34
|
-
}
|
|
35
|
-
destroy() {
|
|
36
|
-
this.strings = this.vars = null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
17
|
const SLOT_NAME_DEFAULT = 'default';
|
|
41
18
|
/**
|
|
42
19
|
* 共享内容
|
|
@@ -55,14 +32,26 @@
|
|
|
55
32
|
})(Mode || (Mode = {}));
|
|
56
33
|
const DefinitionCompEventMap = new Map();
|
|
57
34
|
const DefinitionTagMap = {};
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const DefinitionPropMap = new Map();
|
|
35
|
+
const DefinitionComputedMap = new WeakMap();
|
|
36
|
+
const DefinitionStateMap = new WeakMap();
|
|
37
|
+
const DefinitionPropMap = new WeakMap();
|
|
62
38
|
const DefinitionDecoratorMap = new Map();
|
|
63
39
|
const ObservedAttrsMap = new Map();
|
|
40
|
+
const WatchKeysOnceMap = new WeakMap();
|
|
41
|
+
const WatchKeysDeepListMap = new WeakMap();
|
|
42
|
+
const WatchKeysListMap = new WeakMap();
|
|
43
|
+
const WatchUpdateMap = new WeakMap();
|
|
44
|
+
const WatchDeepUpdateMap = new WeakMap();
|
|
45
|
+
const WatchImmediateListMap = new WeakMap();
|
|
46
|
+
const PropSyncKeySetMap = new WeakMap();
|
|
47
|
+
const StateShallowKeySetMap = new WeakMap();
|
|
48
|
+
const HasChangedPropOrStateMap = new WeakMap();
|
|
49
|
+
const ComputedUpdateDepsMap = new WeakMap();
|
|
50
|
+
const CssUpdateDepsMap = new WeakMap();
|
|
64
51
|
const ComponentDynamicCssUpdaterMap = new WeakMap();
|
|
65
52
|
const PATH_SEPARATOR = '-';
|
|
53
|
+
const PROP_NAME_SLOTS$1 = 'slots';
|
|
54
|
+
const DATA_KEY = '__data_';
|
|
66
55
|
|
|
67
56
|
function showError(msg) {
|
|
68
57
|
console.error(`[CompElem]`, msg);
|
|
@@ -154,6 +143,303 @@
|
|
|
154
143
|
return documentFragment ? documentFragment.host : undefined;
|
|
155
144
|
}
|
|
156
145
|
|
|
146
|
+
/**
|
|
147
|
+
* 用于提供全局state状态管理
|
|
148
|
+
* @author holyhigh2
|
|
149
|
+
*/
|
|
150
|
+
function getterValue(getter, propertyKey, context) {
|
|
151
|
+
let thisHost = context;
|
|
152
|
+
let v = getter ? getter.call(thisHost) : Reflect.get(thisHost[DATA_KEY], propertyKey);
|
|
153
|
+
if (Collector.__collecting) {
|
|
154
|
+
Collector.__varPathList.push(propertyKey);
|
|
155
|
+
}
|
|
156
|
+
if (PROXY_MAP.has(v)) {
|
|
157
|
+
let contextList = EXTRA_CONTEXT_OF_VAR.get(v);
|
|
158
|
+
if (!contextList) {
|
|
159
|
+
contextList = new Set();
|
|
160
|
+
EXTRA_CONTEXT_OF_VAR.set(v, contextList);
|
|
161
|
+
}
|
|
162
|
+
contextList.add(thisHost.__thisRef);
|
|
163
|
+
return PROXY_MAP.get(v);
|
|
164
|
+
}
|
|
165
|
+
if (myfx.isObject(v) && !myfx.isFunction(v) && !(v instanceof Node) && !Object.isFrozen(v)) {
|
|
166
|
+
let keySet = StateShallowKeySetMap.get(thisHost.constructor);
|
|
167
|
+
let shallow = keySet?.has(propertyKey);
|
|
168
|
+
v = shallow || propertyKey === PROP_NAME_SLOTS$1 ? v : reactive(v, thisHost, propertyKey);
|
|
169
|
+
}
|
|
170
|
+
return v;
|
|
171
|
+
}
|
|
172
|
+
function setterValue(propertyKey, v, context) {
|
|
173
|
+
let thisHost = context;
|
|
174
|
+
if (!thisHost.__inited) {
|
|
175
|
+
Reflect.set(thisHost[DATA_KEY], propertyKey, v);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
let oldValue = thisHost[DATA_KEY][propertyKey];
|
|
179
|
+
let stateMap = HasChangedPropOrStateMap.get(thisHost.constructor);
|
|
180
|
+
let hasChanged = stateMap?.get(propertyKey);
|
|
181
|
+
if (hasChanged) {
|
|
182
|
+
if (!hasChanged.call(thisHost, v, oldValue, [propertyKey], v, oldValue))
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
//默认对比算法
|
|
187
|
+
if (Object.is(oldValue, v)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//check watch
|
|
192
|
+
requestWatchUpdate(thisHost, v, oldValue, propertyKey);
|
|
193
|
+
//check computed
|
|
194
|
+
requestComputedUpdate(thisHost, propertyKey);
|
|
195
|
+
//check css
|
|
196
|
+
requestCssUpdate(thisHost, propertyKey);
|
|
197
|
+
Reflect.set(thisHost[DATA_KEY], propertyKey, v);
|
|
198
|
+
thisHost._notify(oldValue, [propertyKey]);
|
|
199
|
+
//update sync
|
|
200
|
+
let syncKeySet = PropSyncKeySetMap.get(thisHost.constructor);
|
|
201
|
+
if (syncKeySet?.has(propertyKey)) {
|
|
202
|
+
thisHost.emit('update' + ":" + propertyKey, { value: v });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function requestWatchUpdate(context, newValue, oldValue, fullPath, rootObjNew, rootObjOld) {
|
|
206
|
+
let superComp = _getSuper(context.constructor);
|
|
207
|
+
let watchKeys = WatchKeysListMap.get(context.constructor) ?? WatchKeysListMap.get(superComp);
|
|
208
|
+
let watchKeysDeep = WatchKeysDeepListMap.get(context.constructor) ?? WatchKeysDeepListMap.get(superComp);
|
|
209
|
+
let watchDeepUpdateMap = WatchDeepUpdateMap.get(context.constructor) ?? WatchDeepUpdateMap.get(superComp);
|
|
210
|
+
let watchUpdateMap = WatchUpdateMap.get(context.constructor) ?? WatchUpdateMap.get(superComp);
|
|
211
|
+
let onceMap = WatchKeysOnceMap.get(context.constructor) ?? WatchKeysOnceMap.get(superComp);
|
|
212
|
+
watchKeys?.forEach(wk => {
|
|
213
|
+
if (fullPath === wk ||
|
|
214
|
+
(myfx.startsWith(wk, fullPath + '.') && !Object.is(myfx.get(context._getPrivateData(), wk), myfx.get(newValue, wk))) ||
|
|
215
|
+
(myfx.startsWith(fullPath, wk + '.') && watchKeysDeep?.includes(wk) && !Object.is(myfx.get(context._getPrivateData(), wk), myfx.get(newValue, wk)))) {
|
|
216
|
+
myfx.concat(myfx.toArray(watchUpdateMap[wk]), myfx.toArray(watchDeepUpdateMap[wk])).forEach(fn => {
|
|
217
|
+
if (!fn)
|
|
218
|
+
return;
|
|
219
|
+
if (onceMap.get(wk) === true)
|
|
220
|
+
return;
|
|
221
|
+
context._watchUpdateArgsInNextTick.set(fn, {
|
|
222
|
+
newValue, oldValue, chain: fullPath.split('.'), rootObjNew, rootObjOld, fullMatch: wk === fullPath
|
|
223
|
+
});
|
|
224
|
+
context._watchUpdateSetInNextTick.add(fn);
|
|
225
|
+
if (onceMap.has(wk))
|
|
226
|
+
onceMap.set(wk, true);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function requestComputedUpdate(context, fullPath) {
|
|
232
|
+
let depMap = ComputedUpdateDepsMap.get(context.constructor);
|
|
233
|
+
if (depMap?.has(fullPath)) {
|
|
234
|
+
depMap.get(fullPath)?.forEach(fn => {
|
|
235
|
+
context._computedUpdateSetInNextTick.add(fn);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function requestCssUpdate(context, fullPath) {
|
|
240
|
+
let deps = CssUpdateDepsMap.get(context.constructor);
|
|
241
|
+
if (!deps)
|
|
242
|
+
return;
|
|
243
|
+
let pathChain = fullPath.split('.');
|
|
244
|
+
let path = '';
|
|
245
|
+
pathChain.forEach(p => {
|
|
246
|
+
path = path ? path + '.' + p : p;
|
|
247
|
+
if (deps.has(path)) {
|
|
248
|
+
context._cssUpdateInNextTick = true;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
const Collector = {
|
|
253
|
+
popDirectiveQ() {
|
|
254
|
+
let rs = this.__varPathList.reduceRight((acc, p) => {
|
|
255
|
+
if (!acc.includes(p)) {
|
|
256
|
+
acc.unshift(p);
|
|
257
|
+
}
|
|
258
|
+
return acc;
|
|
259
|
+
}, []);
|
|
260
|
+
return rs;
|
|
261
|
+
},
|
|
262
|
+
start() {
|
|
263
|
+
this.__collecting = true;
|
|
264
|
+
this.__varPathList = [];
|
|
265
|
+
},
|
|
266
|
+
end(renderComponent, up) {
|
|
267
|
+
if (renderComponent && up) {
|
|
268
|
+
renderComponent._regSubViewDeps(Collector.popVarPathList(), up);
|
|
269
|
+
}
|
|
270
|
+
this.__collecting = false;
|
|
271
|
+
},
|
|
272
|
+
popVarPathList() {
|
|
273
|
+
let rs = Array.from(new Set(this.__varPathList));
|
|
274
|
+
this.__varPathList = [];
|
|
275
|
+
return rs;
|
|
276
|
+
},
|
|
277
|
+
__varPathList: [],
|
|
278
|
+
__collecting: false,
|
|
279
|
+
};
|
|
280
|
+
//对象值在不同上下文的根路径
|
|
281
|
+
const OBJECT_VAR_ROOT_PATH_IN_CONTEXT = new WeakMap();
|
|
282
|
+
const OBJECT_VAR_PATH = new WeakMap();
|
|
283
|
+
//缓存已经创建的proxy对象
|
|
284
|
+
const PROXY_MAP = new WeakMap();
|
|
285
|
+
//对象值的创建上下文
|
|
286
|
+
const OBJECT_VAR_ROOT_CONTEXT = new WeakMap();
|
|
287
|
+
//上级对象所在的扩展context
|
|
288
|
+
const EXTRA_CONTEXT_OF_VAR = new WeakMap();
|
|
289
|
+
function reactive(obj, context, rootProp) {
|
|
290
|
+
if (PROXY_MAP.has(obj))
|
|
291
|
+
return PROXY_MAP.get(obj);
|
|
292
|
+
if (OBJECT_VAR_ROOT_CONTEXT.has(obj)) {
|
|
293
|
+
if (rootProp) {
|
|
294
|
+
let pathMap = OBJECT_VAR_ROOT_PATH_IN_CONTEXT.get(context);
|
|
295
|
+
if (!pathMap) {
|
|
296
|
+
pathMap = new WeakMap();
|
|
297
|
+
OBJECT_VAR_ROOT_PATH_IN_CONTEXT.set(context, pathMap);
|
|
298
|
+
}
|
|
299
|
+
pathMap.set(obj, rootProp);
|
|
300
|
+
let contextList = EXTRA_CONTEXT_OF_VAR.get(obj);
|
|
301
|
+
if (!contextList) {
|
|
302
|
+
contextList = new Set();
|
|
303
|
+
EXTRA_CONTEXT_OF_VAR.set(obj, contextList);
|
|
304
|
+
}
|
|
305
|
+
if (!contextList.values().some(v => v.deref() === context)) {
|
|
306
|
+
contextList.add(new WeakRef(context));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return obj;
|
|
310
|
+
}
|
|
311
|
+
const proxyObject = new Proxy(obj, {
|
|
312
|
+
get(target, prop, receiver) {
|
|
313
|
+
if (!prop)
|
|
314
|
+
return undefined;
|
|
315
|
+
const value = Reflect.get(target, prop, receiver);
|
|
316
|
+
if (myfx.isSymbol(prop))
|
|
317
|
+
return value;
|
|
318
|
+
if (myfx.isFunction(value))
|
|
319
|
+
return value;
|
|
320
|
+
if (prop === 'length' && myfx.isArray(target))
|
|
321
|
+
return value;
|
|
322
|
+
if (Collector.__collecting) {
|
|
323
|
+
let supPath = OBJECT_VAR_PATH.has(receiver) ? myfx.concat(OBJECT_VAR_PATH.get(receiver)) : [];
|
|
324
|
+
supPath.push(prop);
|
|
325
|
+
let propPath = supPath.join('.');
|
|
326
|
+
Collector.__varPathList.push(propPath);
|
|
327
|
+
}
|
|
328
|
+
if (PROXY_MAP.has(value))
|
|
329
|
+
return PROXY_MAP.get(value);
|
|
330
|
+
let reactiveVal = value;
|
|
331
|
+
if (myfx.isObject(value) && !myfx.isFunction(value) && !(value instanceof Node) && !Object.isFrozen(value)) {
|
|
332
|
+
reactiveVal = reactive(value, context);
|
|
333
|
+
let supPath = OBJECT_VAR_PATH.has(receiver) ? myfx.concat(OBJECT_VAR_PATH.get(receiver)) : [];
|
|
334
|
+
supPath.push(prop);
|
|
335
|
+
OBJECT_VAR_PATH.set(reactiveVal, supPath);
|
|
336
|
+
PROXY_MAP.set(value, reactiveVal);
|
|
337
|
+
}
|
|
338
|
+
return reactiveVal;
|
|
339
|
+
},
|
|
340
|
+
set(target, prop, newValue, receiver) {
|
|
341
|
+
if (!prop)
|
|
342
|
+
return false;
|
|
343
|
+
let ov = target[prop];
|
|
344
|
+
let chain = OBJECT_VAR_PATH.get(receiver) ?? [];
|
|
345
|
+
let subChain = myfx.concat(chain, [prop]);
|
|
346
|
+
let stateMap = HasChangedPropOrStateMap.get(context.constructor);
|
|
347
|
+
let hasChanged = stateMap?.get(subChain[0]);
|
|
348
|
+
let moreThan1 = subChain.length > 1;
|
|
349
|
+
let rootObjNew = newValue;
|
|
350
|
+
let rootObjOld = ov;
|
|
351
|
+
if (moreThan1) {
|
|
352
|
+
rootObjOld = rootObjNew = context._getPrivateData()[subChain[0]];
|
|
353
|
+
}
|
|
354
|
+
if (hasChanged) {
|
|
355
|
+
if (!hasChanged.call(context, rootObjNew, rootObjOld, subChain, newValue, ov))
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
//默认对比算法
|
|
360
|
+
if (Object.is(ov, newValue)) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
let nv = newValue;
|
|
365
|
+
let rs = Reflect.set(target, prop, nv);
|
|
366
|
+
let extraContext = EXTRA_CONTEXT_OF_VAR.get(receiver);
|
|
367
|
+
let k = subChain.join('.');
|
|
368
|
+
//check watch
|
|
369
|
+
requestWatchUpdate(context, nv, ov, k, rootObjNew, rootObjOld);
|
|
370
|
+
//check computed
|
|
371
|
+
requestComputedUpdate(context, k);
|
|
372
|
+
//check css
|
|
373
|
+
requestCssUpdate(context, k);
|
|
374
|
+
notifyUpdate(context, rootObjOld, subChain);
|
|
375
|
+
extraContext?.forEach(ctxRef => {
|
|
376
|
+
let ctx = ctxRef.deref();
|
|
377
|
+
if (!ctx)
|
|
378
|
+
return;
|
|
379
|
+
let ctxRootPath = ctx._wrapperProp[subChain[0]];
|
|
380
|
+
let ck = subChain.join('.');
|
|
381
|
+
ck = ck.replace(subChain[0], ctxRootPath);
|
|
382
|
+
//check watch
|
|
383
|
+
requestWatchUpdate(ctx, nv, ov, ck);
|
|
384
|
+
//check computed
|
|
385
|
+
requestComputedUpdate(ctx, ck);
|
|
386
|
+
//check css
|
|
387
|
+
requestCssUpdate(ctx, ck);
|
|
388
|
+
notifyUpdate(ctx, rootObjOld, ck.split('.'));
|
|
389
|
+
});
|
|
390
|
+
return rs;
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
if (!OBJECT_VAR_PATH.has(proxyObject)) {
|
|
394
|
+
OBJECT_VAR_PATH.set(proxyObject, rootProp ? [rootProp] : []);
|
|
395
|
+
}
|
|
396
|
+
PROXY_MAP.set(obj, proxyObject);
|
|
397
|
+
if (rootProp) {
|
|
398
|
+
OBJECT_VAR_ROOT_CONTEXT.set(proxyObject, context);
|
|
399
|
+
if (!OBJECT_VAR_ROOT_PATH_IN_CONTEXT.has(context)) {
|
|
400
|
+
let pathMap = new WeakMap();
|
|
401
|
+
pathMap.set(proxyObject, rootProp);
|
|
402
|
+
OBJECT_VAR_ROOT_PATH_IN_CONTEXT.set(context, pathMap);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return proxyObject;
|
|
406
|
+
}
|
|
407
|
+
function notifyUpdate(context, oldValue, path, subNewValue, subOldValue) {
|
|
408
|
+
let i = myfx.size(path);
|
|
409
|
+
myfx.eachRight(path, (p) => {
|
|
410
|
+
let varPath = myfx.slice(path, 0, i--);
|
|
411
|
+
context._notify(oldValue, varPath);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
const QMap = new Map();
|
|
415
|
+
class Queue {
|
|
416
|
+
static nextSet = new Set();
|
|
417
|
+
static nextPending = false;
|
|
418
|
+
static next;
|
|
419
|
+
static flush() {
|
|
420
|
+
Queue.nextPending = false;
|
|
421
|
+
let nq = Array.from(Queue.nextSet);
|
|
422
|
+
Queue.nextSet.clear();
|
|
423
|
+
QMap.clear();
|
|
424
|
+
nq.forEach(u => u());
|
|
425
|
+
nq = null;
|
|
426
|
+
}
|
|
427
|
+
static pushNext(updater) {
|
|
428
|
+
Queue.nextSet.add(updater);
|
|
429
|
+
if (!Queue.nextPending) {
|
|
430
|
+
Queue.nextPending = true;
|
|
431
|
+
Queue.next();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
(() => {
|
|
436
|
+
const p = Promise.resolve();
|
|
437
|
+
const nextFn = Queue.flush;
|
|
438
|
+
Queue.next = () => {
|
|
439
|
+
p.then(nextFn);
|
|
440
|
+
};
|
|
441
|
+
})();
|
|
442
|
+
|
|
157
443
|
function prop(options) {
|
|
158
444
|
if (arguments.length === 1) {
|
|
159
445
|
return (target, propertyKey, descriptor) => {
|
|
@@ -175,11 +461,11 @@
|
|
|
175
461
|
showError(`Prop '${propertyKey}' must be in CamelCase`);
|
|
176
462
|
}
|
|
177
463
|
let attrSet;
|
|
178
|
-
if (!DefinitionPropMap.has(target.constructor
|
|
464
|
+
if (!DefinitionPropMap.has(target.constructor)) {
|
|
179
465
|
const mixinProps = {};
|
|
180
466
|
let parentCtor = target.constructor;
|
|
181
467
|
while ((parentCtor = _getSuper(parentCtor)) !== CompElem) {
|
|
182
|
-
myfx.merge(mixinProps, DefinitionPropMap.get(parentCtor
|
|
468
|
+
myfx.merge(mixinProps, DefinitionPropMap.get(parentCtor) ?? {});
|
|
183
469
|
}
|
|
184
470
|
attrSet = new Set();
|
|
185
471
|
myfx.each(mixinProps, (v, k) => {
|
|
@@ -188,8 +474,8 @@
|
|
|
188
474
|
attrSet?.add(kbb);
|
|
189
475
|
}
|
|
190
476
|
});
|
|
191
|
-
ObservedAttrsMap.set(target.constructor
|
|
192
|
-
DefinitionPropMap.set(target.constructor
|
|
477
|
+
ObservedAttrsMap.set(target.constructor, attrSet);
|
|
478
|
+
DefinitionPropMap.set(target.constructor, mixinProps);
|
|
193
479
|
}
|
|
194
480
|
if (descriptor) {
|
|
195
481
|
if (descriptor.get)
|
|
@@ -199,7 +485,7 @@
|
|
|
199
485
|
}
|
|
200
486
|
if (options.attribute) {
|
|
201
487
|
if (!attrSet) {
|
|
202
|
-
attrSet = ObservedAttrsMap.get(target.constructor
|
|
488
|
+
attrSet = ObservedAttrsMap.get(target.constructor);
|
|
203
489
|
}
|
|
204
490
|
let kbb = myfx.kebabCase(propertyKey);
|
|
205
491
|
attrSet?.add(kbb);
|
|
@@ -210,12 +496,43 @@
|
|
|
210
496
|
}
|
|
211
497
|
if (attrSet)
|
|
212
498
|
target.constructor.observedAttributes = myfx.toArray(attrSet);
|
|
213
|
-
myfx.set(DefinitionPropMap.get(target.constructor
|
|
499
|
+
myfx.set(DefinitionPropMap.get(target.constructor), propertyKey, options);
|
|
500
|
+
//cache tags
|
|
501
|
+
if (options.hasChanged) {
|
|
502
|
+
let changeMap = HasChangedPropOrStateMap.get(target.constructor);
|
|
503
|
+
if (!changeMap) {
|
|
504
|
+
changeMap = new Map();
|
|
505
|
+
HasChangedPropOrStateMap.set(target.constructor, changeMap);
|
|
506
|
+
}
|
|
507
|
+
changeMap.set(propertyKey, options.hasChanged);
|
|
508
|
+
}
|
|
509
|
+
if (options.sync) {
|
|
510
|
+
let keySet = PropSyncKeySetMap.get(target.constructor);
|
|
511
|
+
if (!keySet) {
|
|
512
|
+
keySet = new Set();
|
|
513
|
+
PropSyncKeySetMap.set(target.constructor, keySet);
|
|
514
|
+
}
|
|
515
|
+
keySet.add(propertyKey);
|
|
516
|
+
}
|
|
517
|
+
//setters & getters
|
|
518
|
+
Reflect.defineProperty(target, propertyKey, {
|
|
519
|
+
get() {
|
|
520
|
+
return getterValue(descriptor?.get, propertyKey, this);
|
|
521
|
+
},
|
|
522
|
+
set(v) {
|
|
523
|
+
if (descriptor?.set) {
|
|
524
|
+
descriptor.set(v);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
setterValue(propertyKey, v, this);
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
});
|
|
214
531
|
}
|
|
215
532
|
//内部接口
|
|
216
533
|
const emptySet = new Set;
|
|
217
534
|
function _getObservedAttrs(ctor) {
|
|
218
|
-
return ObservedAttrsMap.get(ctor
|
|
535
|
+
return ObservedAttrsMap.get(ctor) ?? emptySet;
|
|
219
536
|
}
|
|
220
537
|
|
|
221
538
|
/*************************************************************
|
|
@@ -233,6 +550,7 @@
|
|
|
233
550
|
const AllOutsideDownEls = [];
|
|
234
551
|
const AllOutsideClickEls = [];
|
|
235
552
|
const AllOutsideDblClickEls = [];
|
|
553
|
+
const ResizeTargetInitSet = new WeakSet();
|
|
236
554
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
237
555
|
for (const entry of entries) {
|
|
238
556
|
const contentBoxSize = Array.isArray(entry.contentBoxSize)
|
|
@@ -241,17 +559,13 @@
|
|
|
241
559
|
const borderBoxSize = Array.isArray(entry.borderBoxSize)
|
|
242
560
|
? entry.borderBoxSize[0]
|
|
243
561
|
: entry.borderBoxSize;
|
|
562
|
+
if (!ResizeTargetInitSet.has(entry.target)) {
|
|
563
|
+
ResizeTargetInitSet.add(entry.target);
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
244
566
|
let cbk = AllResizeEls.get(entry.target);
|
|
245
567
|
if (cbk) {
|
|
246
|
-
|
|
247
|
-
bubbles: false,
|
|
248
|
-
cancelable: false,
|
|
249
|
-
detail: {
|
|
250
|
-
borderBox: { w: borderBoxSize.inlineSize, h: borderBoxSize.blockSize },
|
|
251
|
-
contentBox: { w: contentBoxSize.inlineSize, h: contentBoxSize.blockSize },
|
|
252
|
-
},
|
|
253
|
-
});
|
|
254
|
-
cbk(ev, entry.target);
|
|
568
|
+
cbk({ target: entry.target, contentBoxSize, borderBoxSize, type: 'resize' });
|
|
255
569
|
}
|
|
256
570
|
}
|
|
257
571
|
});
|
|
@@ -313,12 +627,8 @@
|
|
|
313
627
|
break;
|
|
314
628
|
}
|
|
315
629
|
if (cbk) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
cancelable: false,
|
|
319
|
-
detail
|
|
320
|
-
});
|
|
321
|
-
cbk(ev);
|
|
630
|
+
detail.type = 'mutate';
|
|
631
|
+
cbk(detail);
|
|
322
632
|
}
|
|
323
633
|
}
|
|
324
634
|
});
|
|
@@ -363,15 +673,7 @@
|
|
|
363
673
|
let t = myfx.get(e.composedPath(), 0, e.target);
|
|
364
674
|
AllOutsideDownEls.forEach(([node, cbk]) => {
|
|
365
675
|
if (!node.contains(t) && !node.contains(myfx.closest(t, (node) => node instanceof ShadowRoot, 'parentNode')?.host)) {
|
|
366
|
-
|
|
367
|
-
bubbles: false,
|
|
368
|
-
cancelable: false,
|
|
369
|
-
detail: {
|
|
370
|
-
currentTarget: node,
|
|
371
|
-
event: e
|
|
372
|
-
},
|
|
373
|
-
});
|
|
374
|
-
cbk(ev, node);
|
|
676
|
+
cbk({ type: 'outside', target: node, modifier: 'mousedown', event: e });
|
|
375
677
|
}
|
|
376
678
|
});
|
|
377
679
|
}, false);
|
|
@@ -379,15 +681,7 @@
|
|
|
379
681
|
let t = myfx.get(e.composedPath(), 0, e.target);
|
|
380
682
|
AllOutsideClickEls.forEach(([node, cbk]) => {
|
|
381
683
|
if (!node.contains(t) && !node.contains(myfx.closest(t, (node) => node instanceof ShadowRoot, 'parentNode')?.host)) {
|
|
382
|
-
|
|
383
|
-
bubbles: false,
|
|
384
|
-
cancelable: false,
|
|
385
|
-
detail: {
|
|
386
|
-
currentTarget: node,
|
|
387
|
-
event: e
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
cbk(ev, node);
|
|
684
|
+
cbk({ type: 'outside', target: node, modifier: 'click', event: e });
|
|
391
685
|
}
|
|
392
686
|
});
|
|
393
687
|
}, false);
|
|
@@ -395,15 +689,7 @@
|
|
|
395
689
|
let t = myfx.get(e.composedPath(), 0, e.target);
|
|
396
690
|
AllOutsideDblClickEls.forEach(([node, cbk]) => {
|
|
397
691
|
if (!node.contains(t) && !node.contains(myfx.closest(t, (node) => node instanceof ShadowRoot, 'parentNode')?.host)) {
|
|
398
|
-
|
|
399
|
-
bubbles: false,
|
|
400
|
-
cancelable: false,
|
|
401
|
-
detail: {
|
|
402
|
-
currentTarget: node,
|
|
403
|
-
event: e
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
cbk(ev, node);
|
|
692
|
+
cbk({ type: 'outside', target: node, modifier: 'dblclick', event: e });
|
|
407
693
|
}
|
|
408
694
|
});
|
|
409
695
|
}, false);
|
|
@@ -424,311 +710,130 @@
|
|
|
424
710
|
function addOutsideDblClick(node, cbk, component) {
|
|
425
711
|
AllOutsideDblClickEls.push([node, cbk]);
|
|
426
712
|
//record
|
|
427
|
-
return (remove = false) => {
|
|
428
|
-
myfx__default["default"].remove(AllOutsideDblClickEls, el => el[0] === node && el[1] === cbk);
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
function isExtEvent(evName) {
|
|
432
|
-
return ExtEvNames.includes(evName);
|
|
433
|
-
}
|
|
434
|
-
function addExtEvent(evName, node, cbk, parts, component) {
|
|
435
|
-
if (evName === 'resize') {
|
|
436
|
-
return addResize(node, cbk);
|
|
437
|
-
}
|
|
438
|
-
else if (evName === 'outside') {
|
|
439
|
-
switch (parts[0]) {
|
|
440
|
-
case 'mousedown':
|
|
441
|
-
return addOutsideMouseDown(node, cbk);
|
|
442
|
-
case 'dblclick':
|
|
443
|
-
return addOutsideDblClick(node, cbk);
|
|
444
|
-
case 'click':
|
|
445
|
-
default:
|
|
446
|
-
return addOutsideClick(node, cbk);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else if (evName === 'mutate') {
|
|
450
|
-
return addMutation(node, cbk, parts);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const MODI_EV_DEBOUNCE = /,|^(debounce:.+)|(debounce$)/;
|
|
455
|
-
const MODI_EV_THROTTLE = /,|^(throttle:.+)|(throttle$)/;
|
|
456
|
-
const MODI_EV_SELF = 'self';
|
|
457
|
-
const MODI_EV_STOP = 'stop';
|
|
458
|
-
const MODI_EV_PREVENT = 'prevent';
|
|
459
|
-
const MODI_EV_ONCE = 'once';
|
|
460
|
-
const MODI_EV_CAPTURE = 'capture';
|
|
461
|
-
const MODI_EV_PASSIVE = 'passive';
|
|
462
|
-
const MODI_EV_MOUSE_LEFT = 'left';
|
|
463
|
-
const MODI_EV_MOUSE_RIGHT = 'right';
|
|
464
|
-
const MODI_EV_MOUSE_MIDDLE = 'middle';
|
|
465
|
-
const MODI_EV_KEYBOARD_COMBO_CTRL = 'ctrl';
|
|
466
|
-
const MODI_EV_KEYBOARD_COMBO_ALT = 'alt';
|
|
467
|
-
const MODI_EV_KEYBOARD_COMBO_SHIFT = 'shift';
|
|
468
|
-
const MODI_EV_KEYBOARD_COMBO_META = 'meta';
|
|
469
|
-
const MODI_EV_KEYBOARD_KEY_MAP = {
|
|
470
|
-
'esc': 'escape'
|
|
471
|
-
};
|
|
472
|
-
const MODI_PARAM_DIVIDER = ":";
|
|
473
|
-
/*************************************************************
|
|
474
|
-
* 事件修饰符
|
|
475
|
-
* @author holyhigh2
|
|
476
|
-
*
|
|
477
|
-
* 全部通用 debounce/once/throttle/capture/passive 可组合
|
|
478
|
-
* 原生通用 stop/prevent/self 可组合
|
|
479
|
-
* 鼠标 left/right/middle 不可组合
|
|
480
|
-
* 键盘 ctrl/alt/shift/meta 可组合 esc/letters... 不可组合,多个key并列式表示可选
|
|
481
|
-
*
|
|
482
|
-
* 部分修饰符支持参数,使用冒号传参如:throttle:100 / debounce:100
|
|
483
|
-
*************************************************************/
|
|
484
|
-
const VFN = () => { };
|
|
485
|
-
function addEvent(fullName, cbk, node, component) {
|
|
486
|
-
let parts = fullName.split('.');
|
|
487
|
-
let evName = parts.shift();
|
|
488
|
-
let isOnce = parts.includes(MODI_EV_ONCE);
|
|
489
|
-
let c = cbk ?? VFN;
|
|
490
|
-
let modi;
|
|
491
|
-
if (modi = myfx.find(parts, x => MODI_EV_DEBOUNCE.test(x))) {
|
|
492
|
-
let params = modi.split(MODI_PARAM_DIVIDER);
|
|
493
|
-
c = myfx.debounce(c, parseInt(params[1]) || 100);
|
|
494
|
-
}
|
|
495
|
-
if (modi = myfx.find(parts, x => MODI_EV_THROTTLE.test(x))) {
|
|
496
|
-
let params = modi.split(MODI_PARAM_DIVIDER);
|
|
497
|
-
c = myfx.throttle(c, parseInt(params[1]) || 100);
|
|
498
|
-
}
|
|
499
|
-
if (isOnce) {
|
|
500
|
-
c = myfx.once(c);
|
|
501
|
-
}
|
|
502
|
-
if (isExtEvent(evName)) {
|
|
503
|
-
return addExtEvent(evName, node, c, parts);
|
|
504
|
-
}
|
|
505
|
-
let listener = (e) => {
|
|
506
|
-
if (parts.includes(MODI_EV_PREVENT))
|
|
507
|
-
e.preventDefault();
|
|
508
|
-
if (parts.includes(MODI_EV_STOP))
|
|
509
|
-
e.stopPropagation();
|
|
510
|
-
if (parts.includes(MODI_EV_SELF) && e.target !== e.currentTarget)
|
|
511
|
-
return;
|
|
512
|
-
if (e instanceof MouseEvent) {
|
|
513
|
-
if (parts.includes(MODI_EV_MOUSE_LEFT) && e.button != 0)
|
|
514
|
-
return;
|
|
515
|
-
if (parts.includes(MODI_EV_MOUSE_RIGHT) && e.button != 2)
|
|
516
|
-
return;
|
|
517
|
-
if (parts.includes(MODI_EV_MOUSE_MIDDLE) && e.button != 1)
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
else if (e instanceof KeyboardEvent) {
|
|
521
|
-
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_CTRL)[0] && !e.ctrlKey)
|
|
522
|
-
return;
|
|
523
|
-
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_ALT)[0] && !e.altKey)
|
|
524
|
-
return;
|
|
525
|
-
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_SHIFT)[0] && !e.shiftKey)
|
|
526
|
-
return;
|
|
527
|
-
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_META)[0] && !e.metaKey)
|
|
528
|
-
return;
|
|
529
|
-
let checkKeys = myfx.map(parts, k => MODI_EV_KEYBOARD_KEY_MAP[k] || k);
|
|
530
|
-
if (myfx.size(checkKeys) > 0 && !checkKeys.includes(e.key.toLowerCase()))
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
console.debug(evName, c.name, node.tagName);
|
|
534
|
-
c(e);
|
|
535
|
-
};
|
|
536
|
-
let capture = parts.includes(MODI_EV_CAPTURE) || false;
|
|
537
|
-
let passive = parts.includes(MODI_EV_PASSIVE) || false;
|
|
538
|
-
let options = { capture, passive };
|
|
539
|
-
node.addEventListener(evName, listener, options);
|
|
540
|
-
//record
|
|
541
|
-
return (remove = false) => {
|
|
542
|
-
node.removeEventListener(evName, listener, options);
|
|
543
|
-
if (remove)
|
|
544
|
-
node = null;
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* 用于提供全局state状态管理
|
|
550
|
-
* @author holyhigh2
|
|
551
|
-
*/
|
|
552
|
-
const Collector = {
|
|
553
|
-
popDirectiveQ() {
|
|
554
|
-
let rs = this.__varPathList.reduceRight((acc, p) => {
|
|
555
|
-
if (!acc.includes(p)) {
|
|
556
|
-
acc.unshift(p);
|
|
557
|
-
}
|
|
558
|
-
return acc;
|
|
559
|
-
}, []);
|
|
560
|
-
return rs;
|
|
561
|
-
},
|
|
562
|
-
start() {
|
|
563
|
-
this.__collecting = true;
|
|
564
|
-
this.__varPathList = [];
|
|
565
|
-
},
|
|
566
|
-
end(renderComponent, up) {
|
|
567
|
-
if (renderComponent && up) {
|
|
568
|
-
renderComponent._regSubViewDeps(Collector.popVarPathList(), up);
|
|
569
|
-
}
|
|
570
|
-
this.__collecting = false;
|
|
571
|
-
},
|
|
572
|
-
popVarPathList() {
|
|
573
|
-
let rs = Array.from(new Set(this.__varPathList));
|
|
574
|
-
this.__varPathList = [];
|
|
575
|
-
return rs;
|
|
576
|
-
},
|
|
577
|
-
__varPathList: [],
|
|
578
|
-
__collecting: false,
|
|
579
|
-
};
|
|
580
|
-
//对象值在不同上下文的根路径
|
|
581
|
-
const OBJECT_VAR_ROOT_PATH_IN_CONTEXT = new WeakMap();
|
|
582
|
-
const OBJECT_VAR_PATH = new WeakMap();
|
|
583
|
-
//缓存已经创建的proxy对象
|
|
584
|
-
const PROXY_MAP = new WeakMap();
|
|
585
|
-
//对象值的创建上下文
|
|
586
|
-
const OBJECT_VAR_ROOT_CONTEXT = new WeakMap();
|
|
587
|
-
//上级对象所在的扩展context
|
|
588
|
-
const EXTRA_CONTEXT_OF_VAR = new WeakMap();
|
|
589
|
-
function reactive(obj, context, rootProp) {
|
|
590
|
-
if (PROXY_MAP.has(obj))
|
|
591
|
-
return PROXY_MAP.get(obj);
|
|
592
|
-
if (OBJECT_VAR_ROOT_CONTEXT.has(obj)) {
|
|
593
|
-
if (rootProp) {
|
|
594
|
-
let pathMap = OBJECT_VAR_ROOT_PATH_IN_CONTEXT.get(context);
|
|
595
|
-
if (!pathMap) {
|
|
596
|
-
pathMap = new WeakMap();
|
|
597
|
-
OBJECT_VAR_ROOT_PATH_IN_CONTEXT.set(context, pathMap);
|
|
598
|
-
}
|
|
599
|
-
pathMap.set(obj, rootProp);
|
|
600
|
-
let contextList = EXTRA_CONTEXT_OF_VAR.get(obj);
|
|
601
|
-
if (!contextList) {
|
|
602
|
-
contextList = new Set();
|
|
603
|
-
EXTRA_CONTEXT_OF_VAR.set(obj, contextList);
|
|
604
|
-
}
|
|
605
|
-
contextList.add(context);
|
|
606
|
-
}
|
|
607
|
-
return obj;
|
|
608
|
-
}
|
|
609
|
-
const proxyObject = new Proxy(obj, {
|
|
610
|
-
get(target, prop, receiver) {
|
|
611
|
-
if (!prop)
|
|
612
|
-
return undefined;
|
|
613
|
-
const value = Reflect.get(target, prop, receiver);
|
|
614
|
-
if (myfx.isSymbol(prop))
|
|
615
|
-
return value;
|
|
616
|
-
if (myfx.isFunction(value))
|
|
617
|
-
return value;
|
|
618
|
-
if (prop === 'length' && myfx.isArray(target))
|
|
619
|
-
return value;
|
|
620
|
-
if (Collector.__collecting) {
|
|
621
|
-
let supPath = OBJECT_VAR_PATH.has(receiver) ? myfx.concat(OBJECT_VAR_PATH.get(receiver)) : [];
|
|
622
|
-
supPath.push(prop);
|
|
623
|
-
let propPath = supPath.join('.');
|
|
624
|
-
Collector.__varPathList.push(propPath);
|
|
625
|
-
}
|
|
626
|
-
if (PROXY_MAP.has(value))
|
|
627
|
-
return PROXY_MAP.get(value);
|
|
628
|
-
let reactiveVal = value;
|
|
629
|
-
if (myfx.isObject(value) && !myfx.isFunction(value) && !(value instanceof Node) && !Object.isFrozen(value)) {
|
|
630
|
-
reactiveVal = reactive(value, context);
|
|
631
|
-
let supPath = OBJECT_VAR_PATH.has(receiver) ? myfx.concat(OBJECT_VAR_PATH.get(receiver)) : [];
|
|
632
|
-
supPath.push(prop);
|
|
633
|
-
OBJECT_VAR_PATH.set(reactiveVal, supPath);
|
|
634
|
-
PROXY_MAP.set(value, reactiveVal);
|
|
635
|
-
}
|
|
636
|
-
return reactiveVal;
|
|
637
|
-
},
|
|
638
|
-
set(target, prop, newValue, receiver) {
|
|
639
|
-
if (!prop)
|
|
640
|
-
return false;
|
|
641
|
-
let ov = target[prop];
|
|
642
|
-
let chain = OBJECT_VAR_PATH.get(receiver) ?? [];
|
|
643
|
-
let subChain = myfx.concat(chain, [prop]);
|
|
644
|
-
let hasChanged = context._hasChangedPropOrStateMap?.get(subChain[0]);
|
|
645
|
-
let moreThan1 = subChain.length > 1;
|
|
646
|
-
let rootObjNew = newValue;
|
|
647
|
-
let rootObjOld = ov;
|
|
648
|
-
if (moreThan1) {
|
|
649
|
-
rootObjOld = rootObjNew = context._getPrivateData()[subChain[0]];
|
|
650
|
-
}
|
|
651
|
-
if (hasChanged) {
|
|
652
|
-
if (!hasChanged.call(context, rootObjNew, rootObjOld, subChain, newValue, ov))
|
|
653
|
-
return true;
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
//默认对比算法
|
|
657
|
-
if (Object.is(ov, newValue)) {
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
let nv = newValue;
|
|
662
|
-
let rs = Reflect.set(target, prop, nv);
|
|
663
|
-
let extraContext = EXTRA_CONTEXT_OF_VAR.get(receiver);
|
|
664
|
-
let k = subChain.join('.');
|
|
665
|
-
//check watch
|
|
666
|
-
context._requestWatchUpdate(nv, ov, k, rootObjNew, rootObjOld);
|
|
667
|
-
//check computed
|
|
668
|
-
context._requestComputedUpdate(k);
|
|
669
|
-
notifyUpdate(context, rootObjOld, subChain);
|
|
670
|
-
myfx.each(extraContext, ctx => {
|
|
671
|
-
let ctxRootPath = ctx._wrapperProp[subChain[0]];
|
|
672
|
-
let ck = subChain.join('.');
|
|
673
|
-
ck = ck.replace(subChain[0], ctxRootPath);
|
|
674
|
-
//check watch
|
|
675
|
-
ctx._requestWatchUpdate(nv, ov, ck);
|
|
676
|
-
//check computed
|
|
677
|
-
ctx._requestComputedUpdate(ck);
|
|
678
|
-
notifyUpdate(ctx, rootObjOld, ck.split('.'));
|
|
679
|
-
});
|
|
680
|
-
return rs;
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
if (!OBJECT_VAR_PATH.has(proxyObject)) {
|
|
684
|
-
OBJECT_VAR_PATH.set(proxyObject, rootProp ? [rootProp] : []);
|
|
685
|
-
}
|
|
686
|
-
PROXY_MAP.set(obj, proxyObject);
|
|
687
|
-
if (rootProp) {
|
|
688
|
-
OBJECT_VAR_ROOT_CONTEXT.set(proxyObject, context);
|
|
689
|
-
if (!OBJECT_VAR_ROOT_PATH_IN_CONTEXT.has(context)) {
|
|
690
|
-
let pathMap = new WeakMap();
|
|
691
|
-
pathMap.set(proxyObject, rootProp);
|
|
692
|
-
OBJECT_VAR_ROOT_PATH_IN_CONTEXT.set(context, pathMap);
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
return proxyObject;
|
|
696
|
-
}
|
|
697
|
-
function notifyUpdate(context, oldValue, path, subNewValue, subOldValue) {
|
|
698
|
-
let i = myfx.size(path);
|
|
699
|
-
myfx.eachRight(path, (p) => {
|
|
700
|
-
let varPath = myfx.slice(path, 0, i--);
|
|
701
|
-
context._notify(oldValue, varPath);
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
const QMap = new Map();
|
|
705
|
-
class Queue {
|
|
706
|
-
static nextSet = new Set();
|
|
707
|
-
static nextPending = false;
|
|
708
|
-
static next;
|
|
709
|
-
static flush() {
|
|
710
|
-
Queue.nextPending = false;
|
|
711
|
-
let nq = Array.from(Queue.nextSet);
|
|
712
|
-
Queue.nextSet.clear();
|
|
713
|
-
QMap.clear();
|
|
714
|
-
nq.forEach(u => u());
|
|
715
|
-
nq = null;
|
|
713
|
+
return (remove = false) => {
|
|
714
|
+
myfx__default["default"].remove(AllOutsideDblClickEls, el => el[0] === node && el[1] === cbk);
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
function isExtEvent(evName) {
|
|
718
|
+
return ExtEvNames.includes(evName);
|
|
719
|
+
}
|
|
720
|
+
function addExtEvent(evName, node, cbk, parts, component) {
|
|
721
|
+
if (evName === 'resize') {
|
|
722
|
+
return addResize(node, cbk);
|
|
716
723
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
724
|
+
else if (evName === 'outside') {
|
|
725
|
+
switch (parts[0]) {
|
|
726
|
+
case 'mousedown':
|
|
727
|
+
return addOutsideMouseDown(node, cbk);
|
|
728
|
+
case 'dblclick':
|
|
729
|
+
return addOutsideDblClick(node, cbk);
|
|
730
|
+
case 'click':
|
|
731
|
+
default:
|
|
732
|
+
return addOutsideClick(node, cbk);
|
|
722
733
|
}
|
|
723
734
|
}
|
|
735
|
+
else if (evName === 'mutate') {
|
|
736
|
+
return addMutation(node, cbk, parts);
|
|
737
|
+
}
|
|
724
738
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
739
|
+
|
|
740
|
+
const MODI_EV_DEBOUNCE = /,|^(debounce:.+)|(debounce$)/;
|
|
741
|
+
const MODI_EV_THROTTLE = /,|^(throttle:.+)|(throttle$)/;
|
|
742
|
+
const MODI_EV_NATIVE = 'native';
|
|
743
|
+
const MODI_EV_SELF = 'self';
|
|
744
|
+
const MODI_EV_STOP = 'stop';
|
|
745
|
+
const MODI_EV_PREVENT = 'prevent';
|
|
746
|
+
const MODI_EV_ONCE = 'once';
|
|
747
|
+
const MODI_EV_CAPTURE = 'capture';
|
|
748
|
+
const MODI_EV_PASSIVE = 'passive';
|
|
749
|
+
const MODI_EV_MOUSE_LEFT = 'left';
|
|
750
|
+
const MODI_EV_MOUSE_RIGHT = 'right';
|
|
751
|
+
const MODI_EV_MOUSE_MIDDLE = 'middle';
|
|
752
|
+
const MODI_EV_KEYBOARD_COMBO_CTRL = 'ctrl';
|
|
753
|
+
const MODI_EV_KEYBOARD_COMBO_ALT = 'alt';
|
|
754
|
+
const MODI_EV_KEYBOARD_COMBO_SHIFT = 'shift';
|
|
755
|
+
const MODI_EV_KEYBOARD_COMBO_META = 'meta';
|
|
756
|
+
const MODI_EV_KEYBOARD_KEY_MAP = {
|
|
757
|
+
'esc': 'escape'
|
|
758
|
+
};
|
|
759
|
+
const MODI_PARAM_DIVIDER = ":";
|
|
760
|
+
/*************************************************************
|
|
761
|
+
* 事件修饰符
|
|
762
|
+
* @author holyhigh2
|
|
763
|
+
*
|
|
764
|
+
* 全部通用 debounce/once/throttle/capture/passive 可组合
|
|
765
|
+
* 原生通用 stop/prevent/self 可组合
|
|
766
|
+
* 鼠标 left/right/middle 不可组合
|
|
767
|
+
* 键盘 ctrl/alt/shift/meta 可组合 esc/letters... 不可组合,多个key并列式表示可选
|
|
768
|
+
* 组件 native 监听组件元素原生事件
|
|
769
|
+
*
|
|
770
|
+
* 部分修饰符支持参数,使用冒号传参如:throttle:100 / debounce:100
|
|
771
|
+
*************************************************************/
|
|
772
|
+
const VFN = () => { };
|
|
773
|
+
function addEvent(fullName, cbk, node, component) {
|
|
774
|
+
let parts = fullName.split('.');
|
|
775
|
+
let evName = parts.shift();
|
|
776
|
+
let isOnce = parts.includes(MODI_EV_ONCE);
|
|
777
|
+
let c = cbk ?? VFN;
|
|
778
|
+
let modi;
|
|
779
|
+
if (modi = myfx.find(parts, x => MODI_EV_DEBOUNCE.test(x))) {
|
|
780
|
+
let params = modi.split(MODI_PARAM_DIVIDER);
|
|
781
|
+
c = myfx.debounce(c, parseInt(params[1]) || 100);
|
|
782
|
+
}
|
|
783
|
+
if (modi = myfx.find(parts, x => MODI_EV_THROTTLE.test(x))) {
|
|
784
|
+
let params = modi.split(MODI_PARAM_DIVIDER);
|
|
785
|
+
c = myfx.throttle(c, parseInt(params[1]) || 100);
|
|
786
|
+
}
|
|
787
|
+
if (isOnce) {
|
|
788
|
+
c = myfx.once(c);
|
|
789
|
+
}
|
|
790
|
+
if (node instanceof CompElem && !parts.includes(MODI_EV_NATIVE)) {
|
|
791
|
+
return node._addEvent(evName, cbk);
|
|
792
|
+
}
|
|
793
|
+
if (isExtEvent(evName)) {
|
|
794
|
+
return addExtEvent(evName, node, c, parts);
|
|
795
|
+
}
|
|
796
|
+
let listener = (e) => {
|
|
797
|
+
if (parts.includes(MODI_EV_PREVENT))
|
|
798
|
+
e.preventDefault();
|
|
799
|
+
if (parts.includes(MODI_EV_STOP))
|
|
800
|
+
e.stopPropagation();
|
|
801
|
+
if (parts.includes(MODI_EV_SELF) && e.target !== e.currentTarget)
|
|
802
|
+
return;
|
|
803
|
+
if (e instanceof MouseEvent) {
|
|
804
|
+
if (parts.includes(MODI_EV_MOUSE_LEFT) && e.button != 0)
|
|
805
|
+
return;
|
|
806
|
+
if (parts.includes(MODI_EV_MOUSE_RIGHT) && e.button != 2)
|
|
807
|
+
return;
|
|
808
|
+
if (parts.includes(MODI_EV_MOUSE_MIDDLE) && e.button != 1)
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
else if (e instanceof KeyboardEvent) {
|
|
812
|
+
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_CTRL)[0] && !e.ctrlKey)
|
|
813
|
+
return;
|
|
814
|
+
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_ALT)[0] && !e.altKey)
|
|
815
|
+
return;
|
|
816
|
+
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_SHIFT)[0] && !e.shiftKey)
|
|
817
|
+
return;
|
|
818
|
+
if (myfx.remove(parts, p => p == MODI_EV_KEYBOARD_COMBO_META)[0] && !e.metaKey)
|
|
819
|
+
return;
|
|
820
|
+
let checkKeys = myfx.map(parts, k => MODI_EV_KEYBOARD_KEY_MAP[k] || k);
|
|
821
|
+
if (myfx.size(checkKeys) > 0 && !checkKeys.includes(e.key.toLowerCase()))
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
c(e);
|
|
730
825
|
};
|
|
731
|
-
|
|
826
|
+
let capture = parts.includes(MODI_EV_CAPTURE) || false;
|
|
827
|
+
let passive = parts.includes(MODI_EV_PASSIVE) || false;
|
|
828
|
+
let options = { capture, passive };
|
|
829
|
+
node.addEventListener(evName, listener, options);
|
|
830
|
+
//record
|
|
831
|
+
return (remove = false) => {
|
|
832
|
+
node.removeEventListener(evName, listener, options);
|
|
833
|
+
if (remove)
|
|
834
|
+
node = null;
|
|
835
|
+
};
|
|
836
|
+
}
|
|
732
837
|
|
|
733
838
|
const PropTypeMap = {
|
|
734
839
|
boolean: Boolean,
|
|
@@ -775,29 +880,21 @@
|
|
|
775
880
|
}
|
|
776
881
|
#cid;
|
|
777
882
|
#slotPropsMap = {};
|
|
778
|
-
|
|
883
|
+
__data_ = {};
|
|
779
884
|
#updateSources = {};
|
|
780
885
|
#shadow;
|
|
781
886
|
//保存所有渲染上下文 {CompElem/Directive}
|
|
782
887
|
__updateTree;
|
|
783
|
-
|
|
784
|
-
|
|
888
|
+
_eventBindList;
|
|
889
|
+
_listerners = {};
|
|
785
890
|
__docoEventMap;
|
|
786
|
-
__updateCssDeps;
|
|
787
891
|
__updateSubViewDeps;
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
_watchKeys;
|
|
792
|
-
_watchKeysOnceMap;
|
|
793
|
-
_watchKeysDeep;
|
|
892
|
+
_cssUpdateInNextTick = false;
|
|
893
|
+
_cssVarOldValueMap;
|
|
894
|
+
__cssSheets;
|
|
794
895
|
_watchUpdateSetInNextTick;
|
|
795
896
|
_watchUpdateArgsInNextTick;
|
|
796
|
-
_computedUpdateDeps;
|
|
797
897
|
_computedUpdateSetInNextTick;
|
|
798
|
-
_hasChangedPropOrStateMap;
|
|
799
|
-
_hasSyncPropSet;
|
|
800
|
-
_hasShallowStateSet;
|
|
801
898
|
get [Symbol.toStringTag]() {
|
|
802
899
|
return this.constructor.name;
|
|
803
900
|
}
|
|
@@ -820,29 +917,29 @@
|
|
|
820
917
|
return this.#parentComponent?.deref();
|
|
821
918
|
}
|
|
822
919
|
get wrapperComponent() {
|
|
823
|
-
return this
|
|
920
|
+
return this.__wrapperComponent?.deref();
|
|
921
|
+
}
|
|
922
|
+
get slots() {
|
|
923
|
+
return EMPTY_SLOTS;
|
|
824
924
|
}
|
|
825
925
|
get slotHooks() {
|
|
826
926
|
return this.#slotHooks;
|
|
827
927
|
}
|
|
828
|
-
get
|
|
829
|
-
return ComponentStaticStyleMap.get(this);
|
|
928
|
+
get cssSheets() {
|
|
929
|
+
return ComponentStaticStyleMap.get(this.constructor);
|
|
830
930
|
}
|
|
831
|
-
get
|
|
931
|
+
get globalCssSheet() {
|
|
832
932
|
return CompElem.__l_globalRule.sheet;
|
|
833
933
|
}
|
|
834
934
|
get isMounted() {
|
|
835
935
|
return this.#mounted;
|
|
836
936
|
}
|
|
837
|
-
get slots() {
|
|
838
|
-
return EMPTY_SLOTS;
|
|
839
|
-
}
|
|
840
937
|
#attrs;
|
|
841
938
|
#props;
|
|
842
939
|
#renderRoot;
|
|
843
940
|
#renderRoots;
|
|
844
941
|
#parentComponent;
|
|
845
|
-
|
|
942
|
+
__wrapperComponent;
|
|
846
943
|
#slotsEl = {};
|
|
847
944
|
#slotHooks = {};
|
|
848
945
|
#slotNodes = {};
|
|
@@ -853,33 +950,46 @@
|
|
|
853
950
|
/**
|
|
854
951
|
* 组件样式,CSSStyleSheet可动态变更
|
|
855
952
|
*/
|
|
856
|
-
static get
|
|
953
|
+
static get css() {
|
|
857
954
|
return [];
|
|
858
955
|
}
|
|
859
|
-
static get
|
|
956
|
+
static get globalCss() {
|
|
860
957
|
return undefined;
|
|
861
958
|
}
|
|
862
|
-
static get
|
|
959
|
+
static get hostCss() {
|
|
863
960
|
return undefined;
|
|
864
961
|
}
|
|
865
|
-
get
|
|
866
|
-
return
|
|
962
|
+
get cssVars() {
|
|
963
|
+
return {};
|
|
867
964
|
}
|
|
868
|
-
|
|
965
|
+
__inited = false;
|
|
869
966
|
#initiating = false;
|
|
967
|
+
#onSlotChangeHookBindThis;
|
|
968
|
+
__thisRef;
|
|
870
969
|
constructor(...args) {
|
|
871
970
|
super();
|
|
872
971
|
this.#cid = CompElemSn++;
|
|
873
972
|
this.__updateTree = [];
|
|
973
|
+
this.__thisRef = new WeakRef(this);
|
|
974
|
+
this.#onSlotChangeHookBindThis = this.#onSlotChangeHook.bind(this);
|
|
874
975
|
//init props via constructor
|
|
875
976
|
if (myfx.size(args) === 1) {
|
|
876
977
|
this.#props = {};
|
|
877
978
|
myfx.assign(this.#props, myfx.first(args));
|
|
878
979
|
}
|
|
879
980
|
/////////////////////////////////////////////////// slots
|
|
880
|
-
|
|
981
|
+
if (!Reflect.getOwnPropertyDescriptor(this.constructor.prototype, 'slots')) {
|
|
982
|
+
Reflect.defineProperty(this.constructor.prototype, 'slots', {
|
|
983
|
+
get() {
|
|
984
|
+
return getterValue(undefined, 'slots', this);
|
|
985
|
+
},
|
|
986
|
+
set(v) {
|
|
987
|
+
setterValue('slots', v, this);
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
}
|
|
881
991
|
/////////////////////////////////////////////////// decorators create
|
|
882
|
-
let ary = DefinitionDecoratorMap.get(this.constructor
|
|
992
|
+
let ary = DefinitionDecoratorMap.get(this.constructor) ?? DefinitionDecoratorMap.get(_getSuper(this.constructor));
|
|
883
993
|
ary && ary.sort((a, b) => b.priority - a.priority).forEach(dw => dw.create(this));
|
|
884
994
|
this.#updatedD = this.#update.bind(this);
|
|
885
995
|
}
|
|
@@ -902,7 +1012,7 @@
|
|
|
902
1012
|
}
|
|
903
1013
|
this.#shadow.adoptedStyleSheets = [...this.#shadow.adoptedStyleSheets, cssSheet];
|
|
904
1014
|
// Keep ComponentStyleMap in sync for this constructor
|
|
905
|
-
const cur = ComponentStaticStyleMap.get(this) ?? [];
|
|
1015
|
+
const cur = ComponentStaticStyleMap.get(this.constructor) ?? [];
|
|
906
1016
|
cur.push(cssSheet);
|
|
907
1017
|
return cssSheet;
|
|
908
1018
|
}
|
|
@@ -929,8 +1039,8 @@
|
|
|
929
1039
|
document.head.appendChild(CompElem.__l_globalRule);
|
|
930
1040
|
}
|
|
931
1041
|
//host styles
|
|
932
|
-
let hostStyle = myfx.get(this.constructor, "
|
|
933
|
-
let styleSheet = myfx.get(this.constructor, '
|
|
1042
|
+
let hostStyle = myfx.get(this.constructor, "hostCss");
|
|
1043
|
+
let styleSheet = myfx.get(this.constructor, 'hostCssSheet');
|
|
934
1044
|
if (hostStyle) {
|
|
935
1045
|
if (!styleSheet) {
|
|
936
1046
|
if (myfx.isString(hostStyle)) {
|
|
@@ -940,11 +1050,11 @@
|
|
|
940
1050
|
else {
|
|
941
1051
|
styleSheet = hostStyle;
|
|
942
1052
|
}
|
|
943
|
-
myfx.set(this.constructor, '
|
|
1053
|
+
myfx.set(this.constructor, 'hostCssSheet', styleSheet);
|
|
944
1054
|
}
|
|
945
|
-
let styleRoot = this
|
|
1055
|
+
let styleRoot = this.__wrapperComponent?.deref()?.shadowRoot ?? this.#parentComponent?.deref()?.shadowRoot ?? this.ownerDocument;
|
|
946
1056
|
//detached el
|
|
947
|
-
if (this
|
|
1057
|
+
if (this.__wrapperComponent && !this.__wrapperComponent.deref()?.shadowRoot?.contains(this)) {
|
|
948
1058
|
styleRoot = myfx.closest(this, n => n instanceof HTMLDocument || n instanceof ShadowRoot, 'parentNode');
|
|
949
1059
|
}
|
|
950
1060
|
if (styleRoot && styleSheet && !styleRoot.adoptedStyleSheets.includes(styleSheet)) {
|
|
@@ -958,7 +1068,7 @@
|
|
|
958
1068
|
this.__unbindEvents();
|
|
959
1069
|
}
|
|
960
1070
|
__bindEvents() {
|
|
961
|
-
let evs = this.
|
|
1071
|
+
let evs = this._eventBindList;
|
|
962
1072
|
myfx.each(evs, (v) => {
|
|
963
1073
|
let [evName, cbk, node, binded] = v;
|
|
964
1074
|
if (binded)
|
|
@@ -970,7 +1080,7 @@
|
|
|
970
1080
|
v[3] = unbinder;
|
|
971
1081
|
});
|
|
972
1082
|
//event decoration
|
|
973
|
-
let events = DefinitionCompEventMap.get(this.constructor
|
|
1083
|
+
let events = DefinitionCompEventMap.get(this.constructor);
|
|
974
1084
|
if (myfx.size(events) > 0) {
|
|
975
1085
|
if (!this.__docoEventMap)
|
|
976
1086
|
this.__docoEventMap = new Map();
|
|
@@ -986,7 +1096,7 @@
|
|
|
986
1096
|
}
|
|
987
1097
|
}
|
|
988
1098
|
__unbindEvents() {
|
|
989
|
-
myfx.each(this.
|
|
1099
|
+
myfx.each(this._eventBindList, (v) => {
|
|
990
1100
|
let [, , , unbinder] = v;
|
|
991
1101
|
if (unbinder)
|
|
992
1102
|
unbinder();
|
|
@@ -1012,45 +1122,26 @@
|
|
|
1012
1122
|
if (this.#destroyed)
|
|
1013
1123
|
return;
|
|
1014
1124
|
this.#destroyed = true;
|
|
1015
|
-
let ary = DefinitionDecoratorMap.get(this.constructor
|
|
1125
|
+
let ary = DefinitionDecoratorMap.get(this.constructor) ?? DefinitionDecoratorMap.get(_getSuper(this.constructor));
|
|
1016
1126
|
ary && ary.sort((a, b) => b.priority - a.priority).forEach(dw => {
|
|
1017
1127
|
dw.destroy(this);
|
|
1018
1128
|
});
|
|
1019
1129
|
this.beforeDestroyed();
|
|
1020
1130
|
//events
|
|
1021
1131
|
this.__unbindEvents();
|
|
1022
|
-
|
|
1023
|
-
myfx.each(hooks, hook => {
|
|
1024
|
-
this.removeEventListener(evName, hook);
|
|
1025
|
-
});
|
|
1026
|
-
this.#rootEvs[evName] = null;
|
|
1027
|
-
});
|
|
1028
|
-
myfx.each(this.#nodeEvs, (hooks, evName) => {
|
|
1029
|
-
myfx.each(hooks, ([hook, ref]) => {
|
|
1030
|
-
ref.deref()?.removeEventListener(evName, hook);
|
|
1031
|
-
});
|
|
1032
|
-
this.#nodeEvs[evName] = null;
|
|
1033
|
-
});
|
|
1132
|
+
this._listerners = null;
|
|
1034
1133
|
this.__docoEventMap?.clear();
|
|
1035
|
-
this.__docoEventMap = this.
|
|
1134
|
+
this.__docoEventMap = this._eventBindList = null;
|
|
1036
1135
|
//styles
|
|
1037
|
-
ComponentStaticStyleMap.delete(this);
|
|
1038
1136
|
ComponentDynamicCssUpdaterMap.get(this)?.clear();
|
|
1039
1137
|
ComponentDynamicCssUpdaterMap.delete(this);
|
|
1040
1138
|
//reactive
|
|
1041
1139
|
this._watchUpdateArgsInNextTick?.clear();
|
|
1042
1140
|
this._watchUpdateSetInNextTick?.clear();
|
|
1043
|
-
this._watchKeysOnceMap?.clear();
|
|
1044
|
-
this._watchUpdateMap = this._watchDeepUpdateMap = this._watchKeys = this._watchKeysDeep = this._watchKeysOnceMap = null;
|
|
1045
|
-
this._computedUpdateDeps?.clear();
|
|
1046
1141
|
this._computedUpdateSetInNextTick?.clear();
|
|
1047
|
-
this.
|
|
1048
|
-
this.
|
|
1142
|
+
this._computedUpdateSetInNextTick = null;
|
|
1143
|
+
this.__cssSheets = null;
|
|
1049
1144
|
this.__updateSubViewDeps?.clear();
|
|
1050
|
-
this._hasChangedPropOrStateMap?.clear();
|
|
1051
|
-
this._hasShallowStateSet?.clear();
|
|
1052
|
-
this._hasSyncPropSet?.clear();
|
|
1053
|
-
this._hasChangedPropOrStateMap = this._hasShallowStateSet = this._hasSyncPropSet = null;
|
|
1054
1145
|
//sup scope
|
|
1055
1146
|
if (this.#parentComponent) {
|
|
1056
1147
|
let pComp = this.#parentComponent.deref();
|
|
@@ -1073,32 +1164,28 @@
|
|
|
1073
1164
|
myfx.each(this.#slotNodes, (nodes) => {
|
|
1074
1165
|
myfx.each(nodes, (node) => node.remove());
|
|
1075
1166
|
});
|
|
1076
|
-
myfx.each(this
|
|
1167
|
+
myfx.each(this.__data_.slots, (nodes, k) => {
|
|
1077
1168
|
myfx.each(nodes, (node) => node.remove());
|
|
1078
1169
|
});
|
|
1079
1170
|
this.#updateSlots.clear();
|
|
1080
|
-
this.#updateSlots = this.#slotPropsMap = this
|
|
1171
|
+
this.#slotNodes = this.#slotsEl = this.#updateSlots = this.#slotPropsMap = this.__data_.slots = null;
|
|
1081
1172
|
this.remove();
|
|
1082
1173
|
//data
|
|
1083
1174
|
this._wrapperProp =
|
|
1084
|
-
this.#
|
|
1085
|
-
this.#
|
|
1086
|
-
this.#
|
|
1087
|
-
this.#
|
|
1088
|
-
this.#
|
|
1089
|
-
this.#
|
|
1090
|
-
this.#
|
|
1091
|
-
this.#
|
|
1092
|
-
this.#
|
|
1093
|
-
this
|
|
1094
|
-
this
|
|
1095
|
-
this.#
|
|
1096
|
-
this
|
|
1097
|
-
this
|
|
1098
|
-
this.__updateTree =
|
|
1099
|
-
this.#parentComponent =
|
|
1100
|
-
this._asyncDirectives =
|
|
1101
|
-
this.#wrapperComponent = null;
|
|
1175
|
+
this.#propsReady =
|
|
1176
|
+
this.#renderRoot = this.#renderRoots = this.#shadow =
|
|
1177
|
+
this.#updateSources =
|
|
1178
|
+
this.#attrs =
|
|
1179
|
+
this.#props =
|
|
1180
|
+
this.#renderRoot =
|
|
1181
|
+
this.#renderRoots =
|
|
1182
|
+
this.#slotHooks =
|
|
1183
|
+
this.#updatedD =
|
|
1184
|
+
this.__data_ =
|
|
1185
|
+
this.__updateTree =
|
|
1186
|
+
this.#parentComponent =
|
|
1187
|
+
this._asyncDirectives =
|
|
1188
|
+
this.__wrapperComponent = null;
|
|
1102
1189
|
//unmount
|
|
1103
1190
|
this.destroyed();
|
|
1104
1191
|
}
|
|
@@ -1106,24 +1193,23 @@
|
|
|
1106
1193
|
//********************************** 首次渲染
|
|
1107
1194
|
//构造时上级传递的参数
|
|
1108
1195
|
__init() {
|
|
1109
|
-
if (this
|
|
1196
|
+
if (this.__inited)
|
|
1110
1197
|
return;
|
|
1111
1198
|
//防止在钩子中出现重新挂载的情况
|
|
1112
1199
|
if (this.#initiating)
|
|
1113
1200
|
return;
|
|
1114
1201
|
this.#initiating = true;
|
|
1115
|
-
let thisRef = new WeakRef(this);
|
|
1116
1202
|
//global styles
|
|
1117
|
-
let globalTextContent = myfx.get(this.constructor, "
|
|
1203
|
+
let globalTextContent = myfx.get(this.constructor, "globalCss");
|
|
1118
1204
|
if (!myfx.isEmpty(globalTextContent) && myfx.isString(globalTextContent) && !myfx.get(this.constructor, '_globalRuleInserted')) {
|
|
1119
1205
|
CompElem.__l_globalRule.textContent += globalTextContent; //.sheet?.insertRule(globalTextContent, 0)
|
|
1120
1206
|
myfx.set(this.constructor, '_globalRuleInserted', true);
|
|
1121
1207
|
}
|
|
1122
1208
|
//component styles
|
|
1123
|
-
let beAttached2 = ComponentStaticStyleMap.get(this);
|
|
1209
|
+
let beAttached2 = ComponentStaticStyleMap.get(this.constructor);
|
|
1124
1210
|
let styleSheets = beAttached2 ?? [];
|
|
1125
1211
|
if (!beAttached2) {
|
|
1126
|
-
myfx.each(myfx.get(this.constructor, "
|
|
1212
|
+
myfx.each(myfx.get(this.constructor, "css"), (st) => {
|
|
1127
1213
|
if (myfx.isString(st)) {
|
|
1128
1214
|
let sheet = new CSSStyleSheet();
|
|
1129
1215
|
sheet.replaceSync(st);
|
|
@@ -1134,156 +1220,78 @@
|
|
|
1134
1220
|
styleSheets.push(st);
|
|
1135
1221
|
}
|
|
1136
1222
|
});
|
|
1137
|
-
ComponentStaticStyleMap.set(this, styleSheets);
|
|
1223
|
+
ComponentStaticStyleMap.set(this.constructor, styleSheets);
|
|
1138
1224
|
}
|
|
1139
1225
|
////////////////////////////////////////////////// Props & States
|
|
1140
1226
|
const props = this.#initProps();
|
|
1141
1227
|
this.propsReady(props);
|
|
1142
1228
|
for (const key in props) {
|
|
1143
1229
|
const v = props[key];
|
|
1144
|
-
this
|
|
1230
|
+
this.__data_[key] = v;
|
|
1145
1231
|
}
|
|
1146
1232
|
this.#initStates();
|
|
1147
1233
|
//2. Data
|
|
1148
|
-
this
|
|
1149
|
-
|
|
1150
|
-
let descr = Reflect.getOwnPropertyDescriptor(this.#data, k);
|
|
1151
|
-
Reflect.defineProperty(this, k, {
|
|
1152
|
-
get() {
|
|
1153
|
-
let thisHost = thisRef.deref();
|
|
1154
|
-
let v = descr?.get ? descr?.get() : Reflect.get(thisHost.#data, k);
|
|
1155
|
-
if (Collector.__collecting) {
|
|
1156
|
-
Collector.__varPathList.push(k);
|
|
1157
|
-
}
|
|
1158
|
-
if (PROXY_MAP.has(v)) {
|
|
1159
|
-
let contextList = EXTRA_CONTEXT_OF_VAR.get(v);
|
|
1160
|
-
if (!contextList) {
|
|
1161
|
-
contextList = new Set();
|
|
1162
|
-
EXTRA_CONTEXT_OF_VAR.set(v, contextList);
|
|
1163
|
-
}
|
|
1164
|
-
contextList.add(thisHost);
|
|
1165
|
-
return PROXY_MAP.get(v);
|
|
1166
|
-
}
|
|
1167
|
-
if (myfx.isObject(v) && !myfx.isFunction(v) && !(v instanceof Node) && !Object.isFrozen(v)) {
|
|
1168
|
-
let shallow = thisHost._hasShallowStateSet?.has(k);
|
|
1169
|
-
v = shallow || k === PROP_NAME_SLOTS ? v : reactive(v, this, k);
|
|
1170
|
-
}
|
|
1171
|
-
return v;
|
|
1172
|
-
},
|
|
1173
|
-
set(v) {
|
|
1174
|
-
if (descr?.set) {
|
|
1175
|
-
descr?.set(v);
|
|
1176
|
-
}
|
|
1177
|
-
else {
|
|
1178
|
-
let thisHost = thisRef.deref();
|
|
1179
|
-
if (!thisHost.#inited) {
|
|
1180
|
-
Reflect.set(thisHost.#data, k, v);
|
|
1181
|
-
return;
|
|
1182
|
-
}
|
|
1183
|
-
let oldValue = thisHost.#data[k];
|
|
1184
|
-
let hasChanged = thisHost._hasChangedPropOrStateMap?.get(k);
|
|
1185
|
-
if (hasChanged) {
|
|
1186
|
-
if (!hasChanged.call(thisHost, v, oldValue, [k], v, oldValue))
|
|
1187
|
-
return true;
|
|
1188
|
-
}
|
|
1189
|
-
else {
|
|
1190
|
-
//默认对比算法
|
|
1191
|
-
if (Object.is(oldValue, v)) {
|
|
1192
|
-
return true;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
//check watch
|
|
1196
|
-
thisHost._requestWatchUpdate(v, oldValue, k);
|
|
1197
|
-
//check computed
|
|
1198
|
-
thisHost._requestComputedUpdate(k);
|
|
1199
|
-
Reflect.set(thisHost.#data, k, v);
|
|
1200
|
-
thisHost._notify(oldValue, [k]);
|
|
1201
|
-
//update sync
|
|
1202
|
-
if (thisHost._hasSyncPropSet?.has(k)) {
|
|
1203
|
-
thisHost.emit('update' + ":" + k, { value: v });
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
});
|
|
1208
|
-
});
|
|
1209
|
-
Reflect.defineProperty(this.#data, '__isData', {
|
|
1234
|
+
this.__data_.slots = {};
|
|
1235
|
+
Reflect.defineProperty(this.__data_, '__isData', {
|
|
1210
1236
|
enumerable: false,
|
|
1211
1237
|
value: true
|
|
1212
1238
|
});
|
|
1213
1239
|
//3. Watch
|
|
1214
|
-
let
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
this._watchDeepUpdateMap = {};
|
|
1218
|
-
this._watchKeys = [];
|
|
1219
|
-
this._watchKeysDeep = [];
|
|
1240
|
+
let superComp = _getSuper(this.constructor);
|
|
1241
|
+
let watchKeys = WatchKeysListMap.get(this.constructor) ?? WatchKeysListMap.get(superComp);
|
|
1242
|
+
if (watchKeys) {
|
|
1220
1243
|
this._watchUpdateSetInNextTick = new Set();
|
|
1221
1244
|
this._watchUpdateArgsInNextTick = new Map();
|
|
1222
|
-
this.
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
if (onceWatch) {
|
|
1229
|
-
this._watchKeysOnceMap.set(k, false);
|
|
1230
|
-
}
|
|
1231
|
-
let deep = myfx.get(options, "deep", false);
|
|
1232
|
-
this._watchKeys.push(k);
|
|
1233
|
-
if (deep) {
|
|
1234
|
-
this._watchDeepUpdateMap[k] = this._watchDeepUpdateMap[k] ?? new Set();
|
|
1235
|
-
this._watchDeepUpdateMap[k].add(fn);
|
|
1236
|
-
this._watchKeysDeep.push(k);
|
|
1237
|
-
}
|
|
1238
|
-
else {
|
|
1239
|
-
this._watchUpdateMap[k] = this._watchUpdateMap[k] ?? new Set();
|
|
1240
|
-
this._watchUpdateMap[k].add(fn);
|
|
1241
|
-
}
|
|
1242
|
-
let immediate = myfx.get(options, "immediate", false);
|
|
1243
|
-
if (!immediate)
|
|
1244
|
-
return;
|
|
1245
|
-
let nv = myfx.get(this, source);
|
|
1246
|
-
fn.call(this, nv, undefined, source);
|
|
1247
|
-
if (onceWatch) {
|
|
1248
|
-
this._watchKeysOnceMap.set(k, true);
|
|
1249
|
-
}
|
|
1245
|
+
let onceMap = WatchKeysOnceMap.get(this.constructor) ?? WatchKeysOnceMap.get(superComp);
|
|
1246
|
+
let watchImmediateList = WatchImmediateListMap.get(this.constructor) ?? WatchImmediateListMap.get(superComp);
|
|
1247
|
+
myfx.each(watchImmediateList, (fns, k) => {
|
|
1248
|
+
let nv = myfx.get(this, k);
|
|
1249
|
+
fns.forEach(fn => {
|
|
1250
|
+
fn.call(this, nv, undefined, k);
|
|
1250
1251
|
});
|
|
1252
|
+
if (onceMap.has(k)) {
|
|
1253
|
+
onceMap.set(k, true);
|
|
1254
|
+
}
|
|
1251
1255
|
});
|
|
1252
1256
|
}
|
|
1253
1257
|
//4. Computed
|
|
1254
|
-
let computedMap = DefinitionComputedMap.get(this.constructor
|
|
1258
|
+
let computedMap = myfx.assign({}, DefinitionComputedMap.get(this.constructor), DefinitionComputedMap.get(superComp));
|
|
1255
1259
|
if (computedMap) {
|
|
1256
|
-
this._computedUpdateDeps = new Map();
|
|
1257
1260
|
this._computedUpdateSetInNextTick = new Set();
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
get() {
|
|
1274
|
-
let v = Reflect.get(thisRef.deref().#data, propKey);
|
|
1275
|
-
if (Collector.__collecting) {
|
|
1276
|
-
Collector.__varPathList.push(propKey);
|
|
1261
|
+
let depMap = ComputedUpdateDepsMap.get(this.constructor);
|
|
1262
|
+
if (!depMap) {
|
|
1263
|
+
depMap = new Map();
|
|
1264
|
+
ComputedUpdateDepsMap.set(this.constructor, depMap);
|
|
1265
|
+
myfx.each(computedMap, (getter, propKey) => {
|
|
1266
|
+
myfx.set(getter, 'key', propKey);
|
|
1267
|
+
Collector.start();
|
|
1268
|
+
this[DATA_KEY][propKey] = getter.call(this);
|
|
1269
|
+
Collector.end();
|
|
1270
|
+
let computedDeps = Collector.popVarPathList();
|
|
1271
|
+
computedDeps.forEach(dep => {
|
|
1272
|
+
let list = depMap.get(dep);
|
|
1273
|
+
if (!list) {
|
|
1274
|
+
list = new Set();
|
|
1275
|
+
depMap.set(dep, list);
|
|
1277
1276
|
}
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1277
|
+
list.add(getter);
|
|
1278
|
+
});
|
|
1280
1279
|
});
|
|
1281
|
-
}
|
|
1280
|
+
}
|
|
1281
|
+
else {
|
|
1282
|
+
myfx.each(computedMap, (getter, propKey) => {
|
|
1283
|
+
this[DATA_KEY][propKey] = getter.call(this);
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1282
1286
|
}
|
|
1283
1287
|
//5. Render
|
|
1284
1288
|
Collector.start();
|
|
1285
1289
|
let tmpl = this.render();
|
|
1286
1290
|
Collector.end();
|
|
1291
|
+
let viewDeps = Collector.popVarPathList();
|
|
1292
|
+
if (!this.constructor.prototype._viewDeps) {
|
|
1293
|
+
this.constructor.prototype._viewDeps = viewDeps;
|
|
1294
|
+
}
|
|
1287
1295
|
let nodes;
|
|
1288
1296
|
if (tmpl === null) {
|
|
1289
1297
|
this.#renderRoots = [];
|
|
@@ -1294,16 +1302,14 @@
|
|
|
1294
1302
|
this.#shadow = this.attachShadow({
|
|
1295
1303
|
mode: "open"
|
|
1296
1304
|
});
|
|
1297
|
-
|
|
1298
|
-
this.__updateViewDeps = viewDeps;
|
|
1299
|
-
this.#shadow.adoptedStyleSheets = [...DefaultCss, ...(ComponentStaticStyleMap.get(this) ?? [])];
|
|
1305
|
+
this.#shadow.adoptedStyleSheets = [...DefaultCss, ...(ComponentStaticStyleMap.get(this.constructor) ?? [])];
|
|
1300
1306
|
nodes = buildView(tmpl, this);
|
|
1301
1307
|
if (nodes) {
|
|
1302
1308
|
this.#renderRoots = myfx.filter(nodes, (n) => n.nodeType === Node.ELEMENT_NODE).map(n => new WeakRef(n));
|
|
1303
|
-
this.#renderRoot =
|
|
1309
|
+
this.#renderRoot = this.#renderRoots[0];
|
|
1304
1310
|
}
|
|
1305
1311
|
}
|
|
1306
|
-
this
|
|
1312
|
+
this.__inited = true;
|
|
1307
1313
|
/////////////////////////////////////////////////// slots
|
|
1308
1314
|
this.#updateSlotsAry();
|
|
1309
1315
|
//slot hook
|
|
@@ -1311,11 +1317,11 @@
|
|
|
1311
1317
|
this.#updateSlot(k);
|
|
1312
1318
|
});
|
|
1313
1319
|
const that = this;
|
|
1314
|
-
let ary = DefinitionDecoratorMap.get(this.constructor
|
|
1320
|
+
let ary = DefinitionDecoratorMap.get(this.constructor) ?? DefinitionDecoratorMap.get(_getSuper(this.constructor));
|
|
1315
1321
|
ary && ary.sort((a, b) => b.priority - a.priority).forEach(dw => {
|
|
1316
1322
|
dw.beforeMount(this, (key, value) => {
|
|
1317
|
-
that
|
|
1318
|
-
return that
|
|
1323
|
+
that.__data_[key] = value;
|
|
1324
|
+
return that.__data_[key];
|
|
1319
1325
|
});
|
|
1320
1326
|
});
|
|
1321
1327
|
this.beforeMount();
|
|
@@ -1327,30 +1333,34 @@
|
|
|
1327
1333
|
this.#mounted = true;
|
|
1328
1334
|
if (this.#shadow) {
|
|
1329
1335
|
//instance dynamic style
|
|
1330
|
-
let cssAry = [];
|
|
1331
1336
|
Collector.start();
|
|
1332
|
-
let
|
|
1337
|
+
let cssVarObj = this.cssVars;
|
|
1333
1338
|
Collector.end();
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
let
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1339
|
+
if (!myfx.isEmpty(cssVarObj)) {
|
|
1340
|
+
this._cssVarOldValueMap = {};
|
|
1341
|
+
let deps = CssUpdateDepsMap.get(this.constructor);
|
|
1342
|
+
if (!deps) {
|
|
1343
|
+
deps = new Set(Collector.popVarPathList());
|
|
1344
|
+
CssUpdateDepsMap.set(this.constructor, deps);
|
|
1345
|
+
}
|
|
1346
|
+
let cssStr = '';
|
|
1347
|
+
myfx.each(cssVarObj, (v, k) => {
|
|
1348
|
+
let cssVarKey = '--' + myfx.kebabCase(k).replace(/^-+/, '');
|
|
1349
|
+
if (myfx.isBlank(v) || myfx.isNil(v)) {
|
|
1350
|
+
v = 'initial'; // invalid value
|
|
1351
|
+
}
|
|
1352
|
+
this._cssVarOldValueMap[cssVarKey] = v;
|
|
1353
|
+
cssStr += ';' + cssVarKey + ':' + v;
|
|
1354
|
+
});
|
|
1355
|
+
this.style.cssText += cssStr;
|
|
1346
1356
|
}
|
|
1347
1357
|
}
|
|
1348
1358
|
if (nodes)
|
|
1349
1359
|
this.#shadow.append(...nodes);
|
|
1350
1360
|
ary && ary.forEach(dw => {
|
|
1351
1361
|
dw.mounted(this, (key, value) => {
|
|
1352
|
-
that
|
|
1353
|
-
return that
|
|
1362
|
+
that.__data_[key] = value;
|
|
1363
|
+
return that.__data_[key];
|
|
1354
1364
|
});
|
|
1355
1365
|
});
|
|
1356
1366
|
if (this.#updateNextImmediatelyQ) {
|
|
@@ -1369,7 +1379,7 @@
|
|
|
1369
1379
|
}
|
|
1370
1380
|
beforeMount() { }
|
|
1371
1381
|
mounted() { }
|
|
1372
|
-
|
|
1382
|
+
#onSlotChangeHook(e) {
|
|
1373
1383
|
let t = e.currentTarget;
|
|
1374
1384
|
let name = '';
|
|
1375
1385
|
myfx.each(this.#slotsEl, (el, n) => {
|
|
@@ -1378,7 +1388,7 @@
|
|
|
1378
1388
|
return false;
|
|
1379
1389
|
}
|
|
1380
1390
|
});
|
|
1381
|
-
if (this
|
|
1391
|
+
if (this.__inited)
|
|
1382
1392
|
this.#onSlotChange(t, name === SLOT_NAME_DEFAULT ? '' : name);
|
|
1383
1393
|
}
|
|
1384
1394
|
#onSlotChange(slot, name) {
|
|
@@ -1421,18 +1431,18 @@
|
|
|
1421
1431
|
}
|
|
1422
1432
|
slotChange(slot, name) { }
|
|
1423
1433
|
attributeChangedCallback(attributeName, oldValue, newValue) {
|
|
1424
|
-
if (!this
|
|
1434
|
+
if (!this.__inited)
|
|
1425
1435
|
return;
|
|
1426
1436
|
if (Object.is(newValue, oldValue))
|
|
1427
1437
|
return;
|
|
1428
1438
|
let propName = myfx.camelCase(attributeName);
|
|
1429
|
-
let propDef = DefinitionPropMap.get(this.constructor
|
|
1439
|
+
let propDef = DefinitionPropMap.get(this.constructor)[propName];
|
|
1430
1440
|
if (isBooleanProp(propDef.type)) {
|
|
1431
1441
|
let v = myfx.isNull(newValue) ? false : getBooleanValue(newValue);
|
|
1432
1442
|
if (myfx.get(this, propName) === v)
|
|
1433
1443
|
return;
|
|
1434
1444
|
}
|
|
1435
|
-
this
|
|
1445
|
+
this.#attrChanged(attributeName, oldValue, newValue);
|
|
1436
1446
|
}
|
|
1437
1447
|
//********************************** 更新
|
|
1438
1448
|
/**
|
|
@@ -1450,8 +1460,6 @@
|
|
|
1450
1460
|
* @param changed
|
|
1451
1461
|
*/
|
|
1452
1462
|
updated(changed) { }
|
|
1453
|
-
#rootEvs = {};
|
|
1454
|
-
#nodeEvs = {};
|
|
1455
1463
|
/**
|
|
1456
1464
|
* 由监控变量调用
|
|
1457
1465
|
* @param stateKey
|
|
@@ -1475,33 +1483,6 @@
|
|
|
1475
1483
|
}
|
|
1476
1484
|
Queue.pushNext(this.#updatedD);
|
|
1477
1485
|
}
|
|
1478
|
-
_requestWatchUpdate(newValue, oldValue, fullPath, rootObjNew, rootObjOld) {
|
|
1479
|
-
this._watchKeys?.forEach(wk => {
|
|
1480
|
-
if (fullPath === wk ||
|
|
1481
|
-
(myfx.startsWith(wk, fullPath + '.') && !Object.is(myfx.get(this._getPrivateData(), wk), myfx.get(newValue, wk))) ||
|
|
1482
|
-
(myfx.startsWith(fullPath, wk + '.') && this._watchKeysDeep.includes(wk) && !Object.is(myfx.get(this._getPrivateData(), wk), myfx.get(newValue, wk)))) {
|
|
1483
|
-
myfx.concat(myfx.toArray(this._watchUpdateMap[wk]), myfx.toArray(this._watchDeepUpdateMap[wk])).forEach(fn => {
|
|
1484
|
-
if (!fn)
|
|
1485
|
-
return;
|
|
1486
|
-
if (this._watchKeysOnceMap.get(wk) === true)
|
|
1487
|
-
return;
|
|
1488
|
-
this._watchUpdateArgsInNextTick.set(fn, {
|
|
1489
|
-
newValue, oldValue, chain: fullPath.split('.'), rootObjNew, rootObjOld, fullMatch: wk === fullPath
|
|
1490
|
-
});
|
|
1491
|
-
this._watchUpdateSetInNextTick.add(fn);
|
|
1492
|
-
if (this._watchKeysOnceMap.has(wk))
|
|
1493
|
-
this._watchKeysOnceMap.set(wk, true);
|
|
1494
|
-
});
|
|
1495
|
-
}
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
_requestComputedUpdate(fullPath) {
|
|
1499
|
-
if (this._computedUpdateDeps?.has(fullPath)) {
|
|
1500
|
-
this._computedUpdateDeps.get(fullPath)?.forEach(fn => {
|
|
1501
|
-
this._computedUpdateSetInNextTick.add(fn);
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
1486
|
#update() {
|
|
1506
1487
|
if (myfx.size(this.#updateSources) < 1)
|
|
1507
1488
|
return;
|
|
@@ -1513,19 +1494,16 @@
|
|
|
1513
1494
|
if (toBreak)
|
|
1514
1495
|
return;
|
|
1515
1496
|
//update decorators
|
|
1516
|
-
let ary = DefinitionDecoratorMap.get(this.constructor
|
|
1497
|
+
let ary = DefinitionDecoratorMap.get(this.constructor) ?? DefinitionDecoratorMap.get(_getSuper(this.constructor));
|
|
1517
1498
|
ary && ary.sort((a, b) => b.priority - a.priority).forEach(dw => {
|
|
1518
1499
|
dw.updated(this, changed);
|
|
1519
1500
|
});
|
|
1520
1501
|
//1. filter update point
|
|
1521
|
-
let toUpdateCss = false;
|
|
1522
1502
|
let toUpdateView = false;
|
|
1523
1503
|
let toUpdateUps = new Set();
|
|
1504
|
+
let viewDeps = this.constructor.prototype._viewDeps;
|
|
1524
1505
|
myfx.each(changed, (x, k) => {
|
|
1525
|
-
if (
|
|
1526
|
-
toUpdateCss = true;
|
|
1527
|
-
}
|
|
1528
|
-
if (!toUpdateView && this.__updateViewDeps?.includes(k)) {
|
|
1506
|
+
if (!toUpdateView && viewDeps?.includes(k)) {
|
|
1529
1507
|
toUpdateView = true;
|
|
1530
1508
|
}
|
|
1531
1509
|
if (this.__updateSubViewDeps?.has(k)) {
|
|
@@ -1546,18 +1524,32 @@
|
|
|
1546
1524
|
// update computed
|
|
1547
1525
|
this._computedUpdateSetInNextTick?.forEach(fn => {
|
|
1548
1526
|
let k = myfx.get(fn, 'key');
|
|
1549
|
-
let oldValue = this
|
|
1527
|
+
let oldValue = this.__data_[k];
|
|
1550
1528
|
let newValue = fn.call(this);
|
|
1551
1529
|
if (!myfx.isObject(newValue) && newValue === oldValue)
|
|
1552
1530
|
return;
|
|
1553
|
-
this
|
|
1531
|
+
this.__data_[k] = newValue;
|
|
1554
1532
|
this._notify(oldValue, [k]);
|
|
1555
1533
|
});
|
|
1556
1534
|
this._computedUpdateSetInNextTick?.clear();
|
|
1535
|
+
// update css
|
|
1536
|
+
if (this._cssUpdateInNextTick) {
|
|
1537
|
+
let cssVarObj = this.cssVars;
|
|
1538
|
+
myfx.each(cssVarObj, (v, k) => {
|
|
1539
|
+
let cssVarKey = '--' + myfx.kebabCase(k).replace(/^-+/, '');
|
|
1540
|
+
if (this._cssVarOldValueMap[cssVarKey] == v) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
if (myfx.isBlank(v) || myfx.isNil(v)) {
|
|
1544
|
+
v = 'initial'; // invalid value
|
|
1545
|
+
}
|
|
1546
|
+
this._cssVarOldValueMap[cssVarKey] = v;
|
|
1547
|
+
this.style.setProperty(cssVarKey, v + '');
|
|
1548
|
+
});
|
|
1549
|
+
}
|
|
1557
1550
|
//2. update view
|
|
1558
1551
|
if (this.#renderRoot?.deref()) {
|
|
1559
1552
|
if (toUpdateView) {
|
|
1560
|
-
console.debug('update view....', this.constructor.name);
|
|
1561
1553
|
updateView(this.render(), this, this.__updateTree);
|
|
1562
1554
|
}
|
|
1563
1555
|
if (myfx.size(toUpdateUps) > 0) {
|
|
@@ -1570,10 +1562,6 @@
|
|
|
1570
1562
|
this.#updateSlots.forEach((v) => {
|
|
1571
1563
|
this.#updateSlot(v);
|
|
1572
1564
|
});
|
|
1573
|
-
//update dcss
|
|
1574
|
-
if (toUpdateCss) {
|
|
1575
|
-
this.#updateCss();
|
|
1576
|
-
}
|
|
1577
1565
|
this.updated(changed);
|
|
1578
1566
|
}
|
|
1579
1567
|
/**
|
|
@@ -1583,7 +1571,7 @@
|
|
|
1583
1571
|
* @returns 非props的attr集合
|
|
1584
1572
|
*/
|
|
1585
1573
|
#initProps() {
|
|
1586
|
-
let propDefs = DefinitionPropMap.get(this.constructor
|
|
1574
|
+
let propDefs = DefinitionPropMap.get(this.constructor) ?? DefinitionPropMap.get(_getSuper(this.constructor));
|
|
1587
1575
|
let attrs = this.attributes;
|
|
1588
1576
|
let tagName = this.tagName;
|
|
1589
1577
|
let parentProps = this.#props;
|
|
@@ -1602,7 +1590,7 @@
|
|
|
1602
1590
|
this.#attrs = this.#attrs ? myfx.assign(this.#attrs, filterAttrs) : filterAttrs;
|
|
1603
1591
|
let rs = {};
|
|
1604
1592
|
if (!propDefs)
|
|
1605
|
-
return
|
|
1593
|
+
return rs;
|
|
1606
1594
|
let keys = Object.keys(propDefs);
|
|
1607
1595
|
let size = keys.length;
|
|
1608
1596
|
for (let i = 0; i < size; i++) {
|
|
@@ -1626,18 +1614,6 @@
|
|
|
1626
1614
|
propDef.type = inferredType;
|
|
1627
1615
|
}
|
|
1628
1616
|
}
|
|
1629
|
-
if (propDef.hasChanged) {
|
|
1630
|
-
if (!this._hasChangedPropOrStateMap) {
|
|
1631
|
-
this._hasChangedPropOrStateMap = new Map();
|
|
1632
|
-
}
|
|
1633
|
-
this._hasChangedPropOrStateMap.set(key, propDef.hasChanged);
|
|
1634
|
-
}
|
|
1635
|
-
if (propDef.sync) {
|
|
1636
|
-
if (!this._hasSyncPropSet) {
|
|
1637
|
-
this._hasSyncPropSet = new Set();
|
|
1638
|
-
}
|
|
1639
|
-
this._hasSyncPropSet.add(key);
|
|
1640
|
-
}
|
|
1641
1617
|
let val = undefined;
|
|
1642
1618
|
if (isInited) {
|
|
1643
1619
|
val = myfx.isNil(parentProps[key]) ? defaultVal : parentProps[key];
|
|
@@ -1658,25 +1634,14 @@
|
|
|
1658
1634
|
break;
|
|
1659
1635
|
}
|
|
1660
1636
|
val = this.#propTypeCheck(propDefs, key, val, hasAttr);
|
|
1661
|
-
let getter = myfx.get(propDefs, [key, 'getter']);
|
|
1662
|
-
if (getter)
|
|
1663
|
-
getter = myfx.bind(getter, this);
|
|
1664
|
-
let setter = myfx.get(propDefs, [key, 'setter']);
|
|
1665
|
-
if (setter)
|
|
1666
|
-
setter = myfx.bind(setter, this);
|
|
1667
|
-
if (getter || setter) {
|
|
1668
|
-
Reflect.defineProperty(this.#data, key, {
|
|
1669
|
-
set: setter || function (v) { },
|
|
1670
|
-
get: getter
|
|
1671
|
-
});
|
|
1672
|
-
}
|
|
1673
1637
|
if (propDef.attribute && myfx.isDefined(val) && !myfx.isObject(val)) {
|
|
1674
1638
|
this.#updateAttribute(propDef, key, val);
|
|
1675
1639
|
}
|
|
1676
|
-
this
|
|
1640
|
+
this.__data_[key] = val;
|
|
1677
1641
|
rs[key] = val;
|
|
1642
|
+
delete this[key];
|
|
1678
1643
|
}
|
|
1679
|
-
return
|
|
1644
|
+
return rs;
|
|
1680
1645
|
}
|
|
1681
1646
|
#updateAttribute(propDef, key, val) {
|
|
1682
1647
|
let k = myfx.kebabCase(key);
|
|
@@ -1774,35 +1739,24 @@
|
|
|
1774
1739
|
showTagError(this.tagName, `Invalid prop '${propKey}'. expected '${expectTypeAry.map((t) => t.name || t)}' but got '${realType}'`);
|
|
1775
1740
|
}
|
|
1776
1741
|
if (validator) {
|
|
1777
|
-
if (!validator.call(this, val, this
|
|
1742
|
+
if (!validator.call(this, val, this.__data_)) {
|
|
1778
1743
|
showTagError(this.tagName, `Invalid prop '${propKey}'. IsValid() check failed`);
|
|
1779
1744
|
}
|
|
1780
1745
|
}
|
|
1781
1746
|
return val;
|
|
1782
1747
|
}
|
|
1783
1748
|
#initStates() {
|
|
1784
|
-
let stateDefs = DefinitionStateMap.get(this.constructor
|
|
1749
|
+
let stateDefs = DefinitionStateMap.get(this.constructor) ?? DefinitionStateMap.get(_getSuper(this.constructor));
|
|
1785
1750
|
if (stateDefs)
|
|
1786
1751
|
myfx.each(stateDefs, (def, key) => {
|
|
1787
1752
|
let stateDef = stateDefs[key];
|
|
1788
1753
|
let val = myfx.get(this, key);
|
|
1789
1754
|
if (stateDef) {
|
|
1790
1755
|
let propName = stateDef.prop;
|
|
1791
|
-
val = propName ? myfx.cloneDeep(this
|
|
1792
|
-
}
|
|
1793
|
-
if (stateDef.hasChanged) {
|
|
1794
|
-
if (!this._hasChangedPropOrStateMap) {
|
|
1795
|
-
this._hasChangedPropOrStateMap = new Map();
|
|
1796
|
-
}
|
|
1797
|
-
this._hasChangedPropOrStateMap.set(key, stateDef.hasChanged);
|
|
1798
|
-
}
|
|
1799
|
-
if (stateDef.shallow) {
|
|
1800
|
-
if (!this._hasShallowStateSet) {
|
|
1801
|
-
this._hasShallowStateSet = new Set();
|
|
1802
|
-
}
|
|
1803
|
-
this._hasShallowStateSet.add(key);
|
|
1756
|
+
val = propName ? myfx.cloneDeep(this.__data_[propName]) : myfx.get(this, key);
|
|
1804
1757
|
}
|
|
1805
|
-
this
|
|
1758
|
+
this.__data_[key] = val;
|
|
1759
|
+
delete this[key];
|
|
1806
1760
|
});
|
|
1807
1761
|
}
|
|
1808
1762
|
/**
|
|
@@ -1811,9 +1765,8 @@
|
|
|
1811
1765
|
* @param attrs
|
|
1812
1766
|
*/
|
|
1813
1767
|
#propsReady = myfx.debounce(this.propsReady, 100);
|
|
1814
|
-
//todo 这里需要直接修改prop
|
|
1815
1768
|
_updateProps(props) {
|
|
1816
|
-
let propDefs = DefinitionPropMap.get(this.constructor
|
|
1769
|
+
let propDefs = DefinitionPropMap.get(this.constructor);
|
|
1817
1770
|
if (!propDefs)
|
|
1818
1771
|
return;
|
|
1819
1772
|
let need2UpdateAttrs = [];
|
|
@@ -1846,10 +1799,10 @@
|
|
|
1846
1799
|
if (fromPath) {
|
|
1847
1800
|
let propPath = fromPath.join(PATH_SEPARATOR);
|
|
1848
1801
|
this._wrapperProp[propPath] = k;
|
|
1849
|
-
let parentStateDefs = this.wrapperComponent ? DefinitionStateMap.get(this.wrapperComponent?.constructor
|
|
1802
|
+
let parentStateDefs = this.wrapperComponent ? DefinitionStateMap.get(this.wrapperComponent?.constructor) : null;
|
|
1850
1803
|
let parentStateKey = fromPath[0];
|
|
1851
1804
|
if (parentStateDefs && parentStateDefs[parentStateKey]) {
|
|
1852
|
-
let propDefs = DefinitionPropMap.get(this.constructor
|
|
1805
|
+
let propDefs = DefinitionPropMap.get(this.constructor);
|
|
1853
1806
|
myfx.set(propDefs, [k, 'shallow'], parentStateDefs[parentStateKey].shallow);
|
|
1854
1807
|
}
|
|
1855
1808
|
}
|
|
@@ -1865,7 +1818,9 @@
|
|
|
1865
1818
|
this.#slotsEl[name] = slot;
|
|
1866
1819
|
SlotCompMap.set(slot, this);
|
|
1867
1820
|
}
|
|
1868
|
-
|
|
1821
|
+
let evName = 'slotchange';
|
|
1822
|
+
let unbinder = addEvent(evName, this.#onSlotChangeHookBindThis, slot);
|
|
1823
|
+
this._eventBindList.push([evName, this.#onSlotChangeHookBindThis, slot, unbinder]);
|
|
1869
1824
|
//3. 保存参数
|
|
1870
1825
|
if (!myfx.isEmpty(props)) {
|
|
1871
1826
|
let slotMap = this.#slotPropsMap[name];
|
|
@@ -1965,9 +1920,9 @@
|
|
|
1965
1920
|
if (!hook)
|
|
1966
1921
|
return;
|
|
1967
1922
|
let slotMap = this.#slotPropsMap[name];
|
|
1968
|
-
if (!this
|
|
1923
|
+
if (!this.__data_.slots)
|
|
1969
1924
|
return;
|
|
1970
|
-
let slot = this
|
|
1925
|
+
let slot = this.__data_.slots[name];
|
|
1971
1926
|
//slot not ready yet
|
|
1972
1927
|
//1. 可能是if/each等指令还未插入
|
|
1973
1928
|
if (!slot)
|
|
@@ -1994,22 +1949,14 @@
|
|
|
1994
1949
|
_asyncDirectives = new WeakMap();
|
|
1995
1950
|
renderAsync(cbk, ...args) {
|
|
1996
1951
|
}
|
|
1997
|
-
#
|
|
1998
|
-
|
|
1999
|
-
cssTmpls.forEach((cssTmpl, i) => {
|
|
2000
|
-
let cssss = this.__cssSheets[i];
|
|
2001
|
-
let css = cssTmpl.getCss(this);
|
|
2002
|
-
cssss.replaceSync(css);
|
|
2003
|
-
});
|
|
2004
|
-
}
|
|
2005
|
-
__attrChanged(name, oldValue, newValue) {
|
|
2006
|
-
if (!this.#inited)
|
|
1952
|
+
#attrChanged(name, oldValue, newValue) {
|
|
1953
|
+
if (!this.__inited)
|
|
2007
1954
|
return;
|
|
2008
1955
|
let observedAttrs = _getObservedAttrs(this.constructor);
|
|
2009
1956
|
if (observedAttrs.has(name)) {
|
|
2010
1957
|
let camelName = myfx.camelCase(name);
|
|
2011
1958
|
if (myfx.isNull(newValue)) {
|
|
2012
|
-
let propDefs = DefinitionPropMap.get(this.constructor
|
|
1959
|
+
let propDefs = DefinitionPropMap.get(this.constructor);
|
|
2013
1960
|
//使用默认值
|
|
2014
1961
|
if (propDefs)
|
|
2015
1962
|
newValue = propDefs[camelName]._defaultValue;
|
|
@@ -2017,9 +1964,6 @@
|
|
|
2017
1964
|
this._updateProps({ [camelName]: newValue });
|
|
2018
1965
|
}
|
|
2019
1966
|
}
|
|
2020
|
-
_regWrapper(wrapperComponent) {
|
|
2021
|
-
this.#wrapperComponent = new WeakRef(wrapperComponent);
|
|
2022
|
-
}
|
|
2023
1967
|
_regSubViewDeps(props, up) {
|
|
2024
1968
|
if (!this.__updateSubViewDeps) {
|
|
2025
1969
|
this.__updateSubViewDeps = new Map();
|
|
@@ -2034,78 +1978,38 @@
|
|
|
2034
1978
|
});
|
|
2035
1979
|
}
|
|
2036
1980
|
_getPrivateData() {
|
|
2037
|
-
return this
|
|
1981
|
+
return this.__data_;
|
|
2038
1982
|
}
|
|
2039
1983
|
////////////////////----------------------------/////////////// APIs
|
|
2040
1984
|
/**
|
|
2041
|
-
*
|
|
1985
|
+
* 发出组件事件
|
|
2042
1986
|
* @param evName 事件名称
|
|
2043
1987
|
* @param args 自定义参数
|
|
2044
1988
|
*/
|
|
2045
|
-
emit(evName, arg = {},
|
|
2046
|
-
if (
|
|
2047
|
-
arg.event =
|
|
1989
|
+
emit(evName, arg = {}, event) {
|
|
1990
|
+
if (event) {
|
|
1991
|
+
arg.event = event;
|
|
2048
1992
|
}
|
|
2049
1993
|
arg.target = this;
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
/**
|
|
2058
|
-
* 在root上绑定事件
|
|
2059
|
-
* @param evName
|
|
2060
|
-
* @param hook
|
|
2061
|
-
* @returns 函数钩子,用于卸载
|
|
2062
|
-
*/
|
|
2063
|
-
on(evName, hook) {
|
|
2064
|
-
if (!this.#rootEvs[evName]) {
|
|
2065
|
-
this.#rootEvs[evName] = [];
|
|
2066
|
-
}
|
|
2067
|
-
let cbk = hook.bind(this);
|
|
2068
|
-
this.#rootEvs[evName].push(cbk);
|
|
2069
|
-
this.addEventListener(evName, cbk);
|
|
2070
|
-
return cbk;
|
|
2071
|
-
}
|
|
2072
|
-
/**
|
|
2073
|
-
* 从root上移除事件
|
|
2074
|
-
* @param evName
|
|
2075
|
-
* @param hook on函数返回的钩子,可选。为空时移除所有evName事件
|
|
2076
|
-
*/
|
|
2077
|
-
off(evName, hook) {
|
|
2078
|
-
if (hook) {
|
|
2079
|
-
this.removeEventListener(evName, hook);
|
|
2080
|
-
myfx.remove(this.#rootEvs[evName], cbk => cbk === hook);
|
|
1994
|
+
if (myfx.has(this.#attrs, 'emit-native')) {
|
|
1995
|
+
this.dispatchEvent(new CustomEvent(evName, {
|
|
1996
|
+
bubbles: false,
|
|
1997
|
+
composed: false,
|
|
1998
|
+
cancelable: true,
|
|
1999
|
+
detail: arg,
|
|
2000
|
+
}));
|
|
2081
2001
|
}
|
|
2082
2002
|
else {
|
|
2083
|
-
|
|
2084
|
-
this.
|
|
2085
|
-
}
|
|
2086
|
-
this.#rootEvs[evName] = [];
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
addEvent(node, evName, hook) {
|
|
2090
|
-
if (!this.#nodeEvs[evName]) {
|
|
2091
|
-
this.#nodeEvs[evName] = [];
|
|
2003
|
+
if (this._listerners[evName]) {
|
|
2004
|
+
this._listerners[evName](arg);
|
|
2005
|
+
}
|
|
2092
2006
|
}
|
|
2093
|
-
let cbk = hook.bind(this);
|
|
2094
|
-
this.#nodeEvs[evName].push([cbk, new WeakRef(node)]);
|
|
2095
|
-
node.addEventListener(evName, cbk);
|
|
2096
|
-
return cbk;
|
|
2097
2007
|
}
|
|
2098
|
-
|
|
2099
|
-
if (
|
|
2100
|
-
|
|
2101
|
-
myfx.remove(this.#nodeEvs[evName], ([cbk]) => cbk === hook);
|
|
2102
|
-
}
|
|
2103
|
-
else {
|
|
2104
|
-
myfx.each(this.#nodeEvs[evName], ([cbk]) => {
|
|
2105
|
-
node.removeEventListener(evName, cbk);
|
|
2106
|
-
});
|
|
2107
|
-
this.#nodeEvs[evName] = [];
|
|
2008
|
+
_addEvent(evName, hook) {
|
|
2009
|
+
if (!this._listerners) {
|
|
2010
|
+
this._listerners = {};
|
|
2108
2011
|
}
|
|
2012
|
+
this._listerners[evName] = hook;
|
|
2109
2013
|
}
|
|
2110
2014
|
/**
|
|
2111
2015
|
* 下一帧执行
|
|
@@ -2126,7 +2030,7 @@
|
|
|
2126
2030
|
* 强制更新一次视图
|
|
2127
2031
|
*/
|
|
2128
2032
|
forceUpdate() {
|
|
2129
|
-
myfx.each(this
|
|
2033
|
+
myfx.each(this.__data_, (v, k) => {
|
|
2130
2034
|
this.#updateSources[k] = {
|
|
2131
2035
|
value: undefined,
|
|
2132
2036
|
chain: undefined,
|
|
@@ -2694,7 +2598,7 @@
|
|
|
2694
2598
|
const EXP_ATTR_CHECK = /[.?-a-z]+\s*=\s*(['"])\s*([^='"]*<\!--c_ui-pl_df-->){2,}.*?\1/ims;
|
|
2695
2599
|
const EXP_PLACEHOLDER = /<\s*[a-z0-9-]+([^>]*<\!--c_ui-pl_df-->)*[^>]*?(?<!-)>/imgs;
|
|
2696
2600
|
const SLOT_KEY_PROPS = 'slot-props';
|
|
2697
|
-
const HTML_TMPL_CACHE =
|
|
2601
|
+
const HTML_TMPL_CACHE = new Map();
|
|
2698
2602
|
/**
|
|
2699
2603
|
* 提供渲染函数相关操作
|
|
2700
2604
|
* @author holyhigh2
|
|
@@ -2772,12 +2676,12 @@
|
|
|
2772
2676
|
* 构建模板为DOM结构
|
|
2773
2677
|
* @param html
|
|
2774
2678
|
*/
|
|
2775
|
-
function buildTmplate(updatePoints, html, vars, renderComponent
|
|
2679
|
+
function buildTmplate(updatePoints, html, vars, renderComponent) {
|
|
2776
2680
|
const container = document.createElement("div");
|
|
2777
2681
|
container.innerHTML = html;
|
|
2778
|
-
let evList = renderComponent.
|
|
2682
|
+
let evList = renderComponent._eventBindList;
|
|
2779
2683
|
if (!evList) {
|
|
2780
|
-
evList = renderComponent.
|
|
2684
|
+
evList = renderComponent._eventBindList = [];
|
|
2781
2685
|
}
|
|
2782
2686
|
//遍历dom
|
|
2783
2687
|
const nodeIterator = document.createNodeIterator(container, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
|
|
@@ -2985,7 +2889,7 @@
|
|
|
2985
2889
|
} //endif
|
|
2986
2890
|
} //endfor
|
|
2987
2891
|
if (currentNode instanceof CompElem) {
|
|
2988
|
-
currentNode
|
|
2892
|
+
setWrapper(currentNode, renderComponent);
|
|
2989
2893
|
if (myfx.size(props) > 0)
|
|
2990
2894
|
currentNode._initProps(props);
|
|
2991
2895
|
}
|
|
@@ -3059,14 +2963,14 @@
|
|
|
3059
2963
|
function buildView(tmpl, component) {
|
|
3060
2964
|
let updatePoints = [];
|
|
3061
2965
|
let nodes;
|
|
3062
|
-
if (HTML_TMPL_CACHE
|
|
3063
|
-
let htmlTmpl = HTML_TMPL_CACHE
|
|
2966
|
+
if (HTML_TMPL_CACHE.has(component.constructor)) {
|
|
2967
|
+
let htmlTmpl = HTML_TMPL_CACHE.get(component.constructor);
|
|
3064
2968
|
let vars = buildVars(component, tmpl);
|
|
3065
2969
|
nodes = buildTmplate(updatePoints, htmlTmpl, vars, component);
|
|
3066
2970
|
}
|
|
3067
2971
|
else {
|
|
3068
2972
|
let [html, vars] = buildHTML(component, tmpl);
|
|
3069
|
-
HTML_TMPL_CACHE
|
|
2973
|
+
HTML_TMPL_CACHE.set(component.constructor, html);
|
|
3070
2974
|
nodes = buildTmplate(updatePoints, html, vars, component);
|
|
3071
2975
|
}
|
|
3072
2976
|
component.__updateTree = updatePoints;
|
|
@@ -3075,7 +2979,7 @@
|
|
|
3075
2979
|
function buildSubView(pointNode, tmpl, component, po, bindEvent = false) {
|
|
3076
2980
|
let [html, vars] = buildHTML(component, tmpl);
|
|
3077
2981
|
let updatePoints = [];
|
|
3078
|
-
let nodes = buildTmplate(updatePoints, html, vars, component
|
|
2982
|
+
let nodes = buildTmplate(updatePoints, html, vars, component);
|
|
3079
2983
|
if (bindEvent)
|
|
3080
2984
|
component.__bindEvents();
|
|
3081
2985
|
updatePoints.forEach(up => {
|
|
@@ -3200,14 +3104,6 @@
|
|
|
3200
3104
|
function html(strings, ...vars) {
|
|
3201
3105
|
return new Template(myfx.isString(strings) ? [strings] : strings, vars);
|
|
3202
3106
|
}
|
|
3203
|
-
/**
|
|
3204
|
-
* 标签函数,用于构建样式
|
|
3205
|
-
* @param strings
|
|
3206
|
-
* @param vars
|
|
3207
|
-
*/
|
|
3208
|
-
function css(strings, ...vars) {
|
|
3209
|
-
return new CssTemplate(myfx.isString(strings) ? [strings] : strings, vars);
|
|
3210
|
-
}
|
|
3211
3107
|
const EXP_STR = /([a-z0-9"'])\s*>\s*</img;
|
|
3212
3108
|
class RefObject {
|
|
3213
3109
|
#ref;
|
|
@@ -3226,6 +3122,9 @@
|
|
|
3226
3122
|
function createRef() {
|
|
3227
3123
|
return new RefObject();
|
|
3228
3124
|
}
|
|
3125
|
+
function setWrapper(target, wrapperComponent) {
|
|
3126
|
+
target.__wrapperComponent = new WeakRef(wrapperComponent);
|
|
3127
|
+
}
|
|
3229
3128
|
|
|
3230
3129
|
//装饰器类型
|
|
3231
3130
|
exports.DecoratorType = void 0;
|
|
@@ -3324,12 +3223,12 @@
|
|
|
3324
3223
|
let fn = (...args) => {
|
|
3325
3224
|
return (...metadata) => {
|
|
3326
3225
|
let ctor = metadata[0].constructor;
|
|
3327
|
-
let ary = DefinitionDecoratorMap.get(ctor
|
|
3328
|
-
if (!DefinitionDecoratorMap.has(ctor
|
|
3226
|
+
let ary = DefinitionDecoratorMap.get(ctor); // ctor[_DecoratorsKey]
|
|
3227
|
+
if (!DefinitionDecoratorMap.has(ctor)) {
|
|
3329
3228
|
//继承父类
|
|
3330
3229
|
let proto = Object.getPrototypeOf(ctor);
|
|
3331
|
-
ary = proto ? myfx.concat(DefinitionDecoratorMap.get(proto
|
|
3332
|
-
DefinitionDecoratorMap.set(ctor
|
|
3230
|
+
ary = proto ? myfx.concat(DefinitionDecoratorMap.get(proto) ?? []) : [];
|
|
3231
|
+
DefinitionDecoratorMap.set(ctor, ary);
|
|
3333
3232
|
}
|
|
3334
3233
|
let dw = new DecoratorWrapper(args, metadata.splice(1), decoClass);
|
|
3335
3234
|
ary?.push(dw);
|
|
@@ -3343,12 +3242,12 @@
|
|
|
3343
3242
|
if (!metadata || metadata.length < 1)
|
|
3344
3243
|
return;
|
|
3345
3244
|
let ctor = metadata[0].constructor;
|
|
3346
|
-
let ary = DefinitionDecoratorMap.get(ctor
|
|
3347
|
-
if (!DefinitionDecoratorMap.has(ctor
|
|
3245
|
+
let ary = DefinitionDecoratorMap.get(ctor); // ctor[_DecoratorsKey]
|
|
3246
|
+
if (!DefinitionDecoratorMap.has(ctor)) {
|
|
3348
3247
|
//继承父类
|
|
3349
3248
|
let proto = Object.getPrototypeOf(ctor);
|
|
3350
|
-
ary = proto ? myfx.concat(DefinitionDecoratorMap.get(proto
|
|
3351
|
-
DefinitionDecoratorMap.set(ctor
|
|
3249
|
+
ary = proto ? myfx.concat(DefinitionDecoratorMap.get(proto) ?? []) : [];
|
|
3250
|
+
DefinitionDecoratorMap.set(ctor, ary);
|
|
3352
3251
|
}
|
|
3353
3252
|
let dw = new DecoratorWrapper([], metadata.splice(1), decoClass);
|
|
3354
3253
|
ary?.push(dw);
|
|
@@ -3361,10 +3260,22 @@
|
|
|
3361
3260
|
if (!descriptor.get) {
|
|
3362
3261
|
showError(`Computed '${propertyKey}' must be a getter`);
|
|
3363
3262
|
}
|
|
3364
|
-
if (!DefinitionComputedMap.has(target.constructor
|
|
3365
|
-
DefinitionComputedMap.set(target.constructor
|
|
3263
|
+
if (!DefinitionComputedMap.has(target.constructor)) {
|
|
3264
|
+
DefinitionComputedMap.set(target.constructor, {});
|
|
3366
3265
|
}
|
|
3367
|
-
DefinitionComputedMap.get(target.constructor
|
|
3266
|
+
DefinitionComputedMap.get(target.constructor)[propertyKey] = descriptor.get;
|
|
3267
|
+
//getter
|
|
3268
|
+
delete target[propertyKey];
|
|
3269
|
+
Reflect.defineProperty(target, propertyKey, {
|
|
3270
|
+
get() {
|
|
3271
|
+
if (Collector.__collecting) {
|
|
3272
|
+
Collector.__varPathList.push(propertyKey);
|
|
3273
|
+
}
|
|
3274
|
+
let v = Reflect.get(this[DATA_KEY], propertyKey);
|
|
3275
|
+
return v;
|
|
3276
|
+
}
|
|
3277
|
+
});
|
|
3278
|
+
return Reflect.getOwnPropertyDescriptor(target, propertyKey);
|
|
3368
3279
|
}
|
|
3369
3280
|
|
|
3370
3281
|
/**
|
|
@@ -3409,15 +3320,15 @@
|
|
|
3409
3320
|
*/
|
|
3410
3321
|
function event(eventName, eventTarget) {
|
|
3411
3322
|
return (target, name, descriptor) => {
|
|
3412
|
-
if (!DefinitionCompEventMap.has(target.constructor
|
|
3323
|
+
if (!DefinitionCompEventMap.has(target.constructor)) {
|
|
3413
3324
|
let mixinEvents = [];
|
|
3414
3325
|
let parentCtor = target.constructor;
|
|
3415
3326
|
while ((parentCtor = _getSuper(parentCtor)) !== CompElem) {
|
|
3416
|
-
mixinEvents = myfx.concat(mixinEvents, DefinitionCompEventMap.get(parentCtor
|
|
3327
|
+
mixinEvents = myfx.concat(mixinEvents, DefinitionCompEventMap.get(parentCtor) ?? []);
|
|
3417
3328
|
}
|
|
3418
|
-
DefinitionCompEventMap.set(target.constructor
|
|
3329
|
+
DefinitionCompEventMap.set(target.constructor, mixinEvents);
|
|
3419
3330
|
}
|
|
3420
|
-
DefinitionCompEventMap.get(target.constructor
|
|
3331
|
+
DefinitionCompEventMap.get(target.constructor)?.push({ name: eventName, targetFn: eventTarget, fnName: name });
|
|
3421
3332
|
};
|
|
3422
3333
|
}
|
|
3423
3334
|
|
|
@@ -3535,16 +3446,42 @@
|
|
|
3535
3446
|
defineState(target, stateKey, { prop: "" });
|
|
3536
3447
|
}
|
|
3537
3448
|
function defineState(target, stateKey, options) {
|
|
3538
|
-
if (!DefinitionStateMap.has(target.constructor
|
|
3449
|
+
if (!DefinitionStateMap.has(target.constructor)) {
|
|
3539
3450
|
const mixinStates = {};
|
|
3540
3451
|
let parentCtor = target.constructor;
|
|
3541
3452
|
while ((parentCtor = _getSuper(parentCtor)) !== CompElem) {
|
|
3542
|
-
myfx.merge(mixinStates, DefinitionStateMap.get(parentCtor
|
|
3453
|
+
myfx.merge(mixinStates, DefinitionStateMap.get(parentCtor) ?? {});
|
|
3543
3454
|
}
|
|
3544
|
-
DefinitionStateMap.set(target.constructor
|
|
3455
|
+
DefinitionStateMap.set(target.constructor, mixinStates);
|
|
3545
3456
|
}
|
|
3546
3457
|
options.shallow = options.shallow || false;
|
|
3547
|
-
myfx.set(DefinitionStateMap.get(target.constructor
|
|
3458
|
+
myfx.set(DefinitionStateMap.get(target.constructor), stateKey, options);
|
|
3459
|
+
//cache tags
|
|
3460
|
+
if (options.hasChanged) {
|
|
3461
|
+
let changeMap = HasChangedPropOrStateMap.get(target.constructor);
|
|
3462
|
+
if (!changeMap) {
|
|
3463
|
+
changeMap = new Map();
|
|
3464
|
+
HasChangedPropOrStateMap.set(target.constructor, changeMap);
|
|
3465
|
+
}
|
|
3466
|
+
changeMap.set(stateKey, options.hasChanged);
|
|
3467
|
+
}
|
|
3468
|
+
if (options.shallow) {
|
|
3469
|
+
let keySet = StateShallowKeySetMap.get(target.constructor);
|
|
3470
|
+
if (!keySet) {
|
|
3471
|
+
keySet = new Set();
|
|
3472
|
+
StateShallowKeySetMap.set(target.constructor, keySet);
|
|
3473
|
+
}
|
|
3474
|
+
keySet.add(stateKey);
|
|
3475
|
+
}
|
|
3476
|
+
//setters & getters
|
|
3477
|
+
Reflect.defineProperty(target.constructor.prototype, stateKey, {
|
|
3478
|
+
get() {
|
|
3479
|
+
return getterValue(undefined, stateKey, this);
|
|
3480
|
+
},
|
|
3481
|
+
set(v) {
|
|
3482
|
+
setterValue(stateKey, v, this);
|
|
3483
|
+
},
|
|
3484
|
+
});
|
|
3548
3485
|
}
|
|
3549
3486
|
/**
|
|
3550
3487
|
* 同@state装饰器,但可用于构造器中调用
|
|
@@ -3609,27 +3546,67 @@
|
|
|
3609
3546
|
*/
|
|
3610
3547
|
function watch(source, options) {
|
|
3611
3548
|
return (target, name) => {
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3549
|
+
let watchDeepUpdateMap = WatchDeepUpdateMap.get(target.constructor);
|
|
3550
|
+
let watchUpdateMap = WatchUpdateMap.get(target.constructor);
|
|
3551
|
+
let onceMap = WatchKeysOnceMap.get(target.constructor);
|
|
3552
|
+
let watchKeysDeep = WatchKeysDeepListMap.get(target.constructor);
|
|
3553
|
+
let watchKeys = WatchKeysListMap.get(target.constructor);
|
|
3554
|
+
let watchImmediateList = WatchImmediateListMap.get(target.constructor);
|
|
3555
|
+
if (!watchKeys) {
|
|
3556
|
+
watchKeys = [];
|
|
3557
|
+
WatchKeysListMap.set(target.constructor, watchKeys);
|
|
3558
|
+
watchKeysDeep = [];
|
|
3559
|
+
WatchKeysDeepListMap.set(target.constructor, watchKeysDeep);
|
|
3560
|
+
onceMap = new Map();
|
|
3561
|
+
WatchKeysOnceMap.set(target.constructor, onceMap);
|
|
3562
|
+
watchDeepUpdateMap = {};
|
|
3563
|
+
WatchDeepUpdateMap.set(target.constructor, watchDeepUpdateMap);
|
|
3564
|
+
watchUpdateMap = {};
|
|
3565
|
+
WatchUpdateMap.set(target.constructor, watchUpdateMap);
|
|
3566
|
+
watchImmediateList = {};
|
|
3567
|
+
WatchImmediateListMap.set(target.constructor, watchImmediateList);
|
|
3568
|
+
let parentCtor = _getSuper(target.constructor);
|
|
3569
|
+
while (parentCtor) {
|
|
3570
|
+
if (WatchKeysListMap.has(parentCtor)) {
|
|
3571
|
+
watchKeys.push(...WatchKeysListMap.get(parentCtor));
|
|
3572
|
+
watchKeysDeep.push(...WatchKeysDeepListMap.get(parentCtor));
|
|
3573
|
+
WatchKeysOnceMap.get(parentCtor)?.forEach((v, k) => {
|
|
3574
|
+
onceMap.set(k, v);
|
|
3620
3575
|
});
|
|
3576
|
+
myfx.assign(watchDeepUpdateMap, WatchDeepUpdateMap.get(parentCtor));
|
|
3577
|
+
myfx.assign(watchUpdateMap, WatchUpdateMap.get(parentCtor));
|
|
3578
|
+
myfx.assign(watchImmediateList, WatchImmediateListMap.get(parentCtor));
|
|
3621
3579
|
}
|
|
3580
|
+
parentCtor = _getSuper(parentCtor);
|
|
3622
3581
|
}
|
|
3623
|
-
DefinitionWatchMap.set(target.constructor.name, watchMap);
|
|
3624
3582
|
}
|
|
3625
3583
|
const sources = myfx.isArray(source) ? source : [source];
|
|
3626
3584
|
sources.forEach(src => {
|
|
3627
|
-
let
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3585
|
+
let handler = target[name];
|
|
3586
|
+
//////////////////////////////
|
|
3587
|
+
let onceWatch = myfx.get(options, "once", false);
|
|
3588
|
+
if (onceWatch) {
|
|
3589
|
+
onceMap.set(src, false);
|
|
3590
|
+
}
|
|
3591
|
+
let deep = myfx.get(options, "deep", false);
|
|
3592
|
+
watchKeys.push(src);
|
|
3593
|
+
if (deep) {
|
|
3594
|
+
watchDeepUpdateMap[src] = watchDeepUpdateMap[src] ?? new Set();
|
|
3595
|
+
watchDeepUpdateMap[src].add(handler);
|
|
3596
|
+
watchKeysDeep.push(src);
|
|
3597
|
+
}
|
|
3598
|
+
else {
|
|
3599
|
+
watchUpdateMap[src] = watchUpdateMap[src] ?? new Set();
|
|
3600
|
+
watchUpdateMap[src].add(handler);
|
|
3601
|
+
}
|
|
3602
|
+
let immediate = myfx.get(options, "immediate", false);
|
|
3603
|
+
if (immediate) {
|
|
3604
|
+
let handlerSet = watchImmediateList[src];
|
|
3605
|
+
if (!handlerSet) {
|
|
3606
|
+
handlerSet = watchImmediateList[src] = new Set();
|
|
3607
|
+
}
|
|
3608
|
+
handlerSet.add(handler);
|
|
3631
3609
|
}
|
|
3632
|
-
srcList.push({ source: src, options, handler: target[name] });
|
|
3633
3610
|
});
|
|
3634
3611
|
};
|
|
3635
3612
|
}
|
|
@@ -3652,7 +3629,7 @@
|
|
|
3652
3629
|
//判断是否prop
|
|
3653
3630
|
let props = {};
|
|
3654
3631
|
let attrs = {};
|
|
3655
|
-
let propDefs = DefinitionPropMap.get(el.constructor
|
|
3632
|
+
let propDefs = DefinitionPropMap.get(el.constructor);
|
|
3656
3633
|
myfx.each(obj, (v, k) => {
|
|
3657
3634
|
if (Ignores.includes(k))
|
|
3658
3635
|
return;
|
|
@@ -3952,13 +3929,13 @@
|
|
|
3952
3929
|
if (!(rootPath in renderComponent) && !renderComponent._wrapperProp[rootPath]) {
|
|
3953
3930
|
showError(`model - property '${rootPath}' is not defined on the instance of ` + renderComponent.tagName);
|
|
3954
3931
|
}
|
|
3955
|
-
let evList = renderComponent.
|
|
3932
|
+
let evList = renderComponent._eventBindList;
|
|
3956
3933
|
if (!myfx.isObject(modelValue) && !myfx.trim(modelValue))
|
|
3957
3934
|
modelValue = '';
|
|
3958
3935
|
if (node instanceof CompElem) {
|
|
3959
3936
|
node._initProps({ [updateProp]: modelValue });
|
|
3960
3937
|
let evName = 'update:' + updateProp;
|
|
3961
|
-
evList.push([evName, function (
|
|
3938
|
+
evList.push([evName, function (obj) {
|
|
3962
3939
|
console.debug('Model =>', path);
|
|
3963
3940
|
let ctx = this;
|
|
3964
3941
|
let pathFromWrapperComponent = ctx._wrapperProp[rootPath];
|
|
@@ -3966,7 +3943,7 @@
|
|
|
3966
3943
|
if (!hasPath && pathFromWrapperComponent && myfx.get(ctx.wrapperComponent, rootPath) === myfx.get(ctx, pathFromWrapperComponent)) {
|
|
3967
3944
|
ctx = ctx.wrapperComponent || ctx;
|
|
3968
3945
|
}
|
|
3969
|
-
myfx.set(ctx, path,
|
|
3946
|
+
myfx.set(ctx, path, obj.value);
|
|
3970
3947
|
}, node]);
|
|
3971
3948
|
}
|
|
3972
3949
|
else if (node instanceof HTMLTextAreaElement) {
|
|
@@ -4188,7 +4165,6 @@
|
|
|
4188
4165
|
|
|
4189
4166
|
exports.CompElem = CompElem;
|
|
4190
4167
|
exports.CssHelper = CssHelper;
|
|
4191
|
-
exports.CssTemplate = CssTemplate;
|
|
4192
4168
|
exports.DI_COMMENT_START_NODE_MAP = DI_COMMENT_START_NODE_MAP;
|
|
4193
4169
|
exports.Decorator = Decorator;
|
|
4194
4170
|
exports.DecoratorWrapper = DecoratorWrapper;
|
|
@@ -4204,7 +4180,6 @@
|
|
|
4204
4180
|
exports.classes = classes;
|
|
4205
4181
|
exports.computed = computed;
|
|
4206
4182
|
exports.createRef = createRef;
|
|
4207
|
-
exports.css = css;
|
|
4208
4183
|
exports.debounced = debounced;
|
|
4209
4184
|
exports.decorator = decorator;
|
|
4210
4185
|
exports.decoratorWithNoArgs = decoratorWithNoArgs;
|