@joker.front/core 1.2.153 → 1.2.170
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/dist/bundle.es.js +59 -35
- package/dist/bundle.js +62 -34
- package/package.json +4 -3
- package/types/component.d.ts +3 -2
- package/types/index.d.ts +1 -0
- package/types/observer/dep.d.ts +3 -1
- package/types/observer/index.d.ts +3 -0
- package/types/parser/component.d.ts +3 -3
- package/types/parser/index.d.ts +1 -1
- package/types/parser/render.d.ts +1 -2
- package/types/parser/vnode.d.ts +3 -1
package/dist/bundle.es.js
CHANGED
|
@@ -313,6 +313,13 @@ function escape2Html(str) {
|
|
|
313
313
|
});
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
let otherWindowDeps = [];
|
|
317
|
+
function registerOtherWindowDep(dep) {
|
|
318
|
+
otherWindowDeps.push(dep);
|
|
319
|
+
}
|
|
320
|
+
function removeOtherWindowDep(dep) {
|
|
321
|
+
remove(otherWindowDeps, dep);
|
|
322
|
+
}
|
|
316
323
|
/**
|
|
317
324
|
* 作为观察者和对象代理中间的关系桥
|
|
318
325
|
* 数据变更时:Ob->dep->watcher
|
|
@@ -320,7 +327,7 @@ function escape2Html(str) {
|
|
|
320
327
|
*/
|
|
321
328
|
class Dep {
|
|
322
329
|
/**
|
|
323
|
-
* 关系id
|
|
330
|
+
* 关系id,仅在production模式下生效
|
|
324
331
|
*/
|
|
325
332
|
id = process.env.NODE_ENV === "production" ? "" : guid();
|
|
326
333
|
/**
|
|
@@ -340,6 +347,9 @@ class Dep {
|
|
|
340
347
|
*/
|
|
341
348
|
depend(key) {
|
|
342
349
|
Dep.target?.addDep(this, key);
|
|
350
|
+
otherWindowDeps.forEach((n) => {
|
|
351
|
+
n.target?.addDep(this, key);
|
|
352
|
+
});
|
|
343
353
|
}
|
|
344
354
|
/**
|
|
345
355
|
* 添加观察者
|
|
@@ -404,12 +414,12 @@ function notifyGroupDeps(list) {
|
|
|
404
414
|
/**
|
|
405
415
|
* 存放劫持对象的Dep的Key
|
|
406
416
|
*/
|
|
407
|
-
const OBJECTPROXY_DEPID = Symbol("
|
|
408
|
-
const OBJECTPROXY_DATA_KEY = Symbol("
|
|
417
|
+
const OBJECTPROXY_DEPID = Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__");
|
|
418
|
+
const OBJECTPROXY_DATA_KEY = Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__");
|
|
409
419
|
/**
|
|
410
420
|
* 针对深度劫持关系时,需要给该对象做一个虚拟劫持的关系Key,方便事件传播
|
|
411
421
|
*/
|
|
412
|
-
const OBJECTPROXY_DEPLEVE_ID = Symbol("
|
|
422
|
+
const OBJECTPROXY_DEPLEVE_ID = Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");
|
|
413
423
|
/**
|
|
414
424
|
* 检测是否允许劫持代理
|
|
415
425
|
* @param data
|
|
@@ -423,8 +433,9 @@ function checkEnableProxy(data) {
|
|
|
423
433
|
//非冻结
|
|
424
434
|
!Object.isFrozen(data) &&
|
|
425
435
|
!(data instanceof Element) &&
|
|
426
|
-
!(
|
|
427
|
-
!(
|
|
436
|
+
!(JOKER_VNODE_TAG in data) &&
|
|
437
|
+
!(JOKER_SHALLOW_OBSERVER_TAG in data) &&
|
|
438
|
+
!(JOKER_COMPONENT_TAG in data));
|
|
428
439
|
}
|
|
429
440
|
function proxyData(data) {
|
|
430
441
|
let proxyDepTarget = getProxyDep(data);
|
|
@@ -520,7 +531,7 @@ function getProxyDep(data) {
|
|
|
520
531
|
//@ts-ignore
|
|
521
532
|
if (isObject(data)) {
|
|
522
533
|
let dep = Reflect.get(data, OBJECTPROXY_DEPID);
|
|
523
|
-
if (dep
|
|
534
|
+
if (dep) {
|
|
524
535
|
//@ts-ignore
|
|
525
536
|
return dep;
|
|
526
537
|
}
|
|
@@ -585,12 +596,14 @@ function defineObserverProperty(target, key, value) {
|
|
|
585
596
|
}
|
|
586
597
|
});
|
|
587
598
|
}
|
|
599
|
+
const JOKER_SHALLOW_OBSERVER_TAG = Symbol.for("JOKER_SHALLOW_OBSERVER");
|
|
588
600
|
/**
|
|
589
601
|
* 浅劫持监听,不污染数据源,只对根值监听,不对属性监听
|
|
590
602
|
* @returns
|
|
591
603
|
*/
|
|
592
604
|
class ShallowObserver {
|
|
593
605
|
data;
|
|
606
|
+
[JOKER_SHALLOW_OBSERVER_TAG] = true;
|
|
594
607
|
dep = new Dep();
|
|
595
608
|
constructor(data) {
|
|
596
609
|
this.data = data;
|
|
@@ -730,7 +743,7 @@ class Watcher {
|
|
|
730
743
|
if (expOrFn === undefined) {
|
|
731
744
|
this.getter = (obj) => obj;
|
|
732
745
|
}
|
|
733
|
-
else if (expOrFn
|
|
746
|
+
else if (typeof expOrFn === "function") {
|
|
734
747
|
this.getter = expOrFn;
|
|
735
748
|
}
|
|
736
749
|
else {
|
|
@@ -866,6 +879,7 @@ var IContainer;
|
|
|
866
879
|
IContainer.get = get;
|
|
867
880
|
})(IContainer || (IContainer = {}));
|
|
868
881
|
|
|
882
|
+
const JOKER_VNODE_TAG = Symbol.for("JOKER_VNODE_TAG");
|
|
869
883
|
/**
|
|
870
884
|
* 虚拟DOM
|
|
871
885
|
*
|
|
@@ -873,12 +887,13 @@ var IContainer;
|
|
|
873
887
|
*/
|
|
874
888
|
var VNode;
|
|
875
889
|
(function (VNode) {
|
|
876
|
-
VNode.PARSERKEY = Symbol("JOKER_PARSER_KEY");
|
|
890
|
+
VNode.PARSERKEY = Symbol.for("JOKER_PARSER_KEY");
|
|
877
891
|
/**
|
|
878
892
|
* VNode 基类
|
|
879
893
|
*/
|
|
880
894
|
class Node {
|
|
881
895
|
parent;
|
|
896
|
+
[JOKER_VNODE_TAG] = true;
|
|
882
897
|
/**
|
|
883
898
|
* 是否是静态节点,非动态节点。例如:element、text、comment等
|
|
884
899
|
*/
|
|
@@ -1140,7 +1155,7 @@ var Render;
|
|
|
1140
1155
|
/**
|
|
1141
1156
|
* 注入TagId
|
|
1142
1157
|
*/
|
|
1143
|
-
Render.IRENDERIOCTAGID = Symbol("JOKER_IRENDERIOC_TAGID");
|
|
1158
|
+
Render.IRENDERIOCTAGID = Symbol.for("JOKER_IRENDERIOC_TAGID");
|
|
1144
1159
|
/**
|
|
1145
1160
|
* 默认Render,采用H5-DOM模式进行输出
|
|
1146
1161
|
*/
|
|
@@ -1302,6 +1317,9 @@ var Render;
|
|
|
1302
1317
|
let resolve = () => {
|
|
1303
1318
|
removeClassName(node, getTransitionClassName(transitionName, model, "to"));
|
|
1304
1319
|
removeClassName(node, getTransitionClassName(transitionName, model, "active"));
|
|
1320
|
+
//可能存在越级删除,造成动画元素过早移除,
|
|
1321
|
+
if (!node.output)
|
|
1322
|
+
return;
|
|
1305
1323
|
node.output.removeEventListener(`${type}end`, onEnd);
|
|
1306
1324
|
if (id === node.output.__TRANSITION_EVNETID__) {
|
|
1307
1325
|
callBack?.();
|
|
@@ -1337,6 +1355,8 @@ var Render;
|
|
|
1337
1355
|
}
|
|
1338
1356
|
else if (node instanceof VNode.Html) {
|
|
1339
1357
|
let conatiner = document.createElement("joker-html-container");
|
|
1358
|
+
//@ts-ignore
|
|
1359
|
+
conatiner.JOKER_NODE = node;
|
|
1340
1360
|
conatiner.root.innerHTML = node.html;
|
|
1341
1361
|
node.output = conatiner;
|
|
1342
1362
|
}
|
|
@@ -1354,6 +1374,8 @@ var Render;
|
|
|
1354
1374
|
for (let attrName in node.attributes) {
|
|
1355
1375
|
this.setAttribute(element, attrName, node.attributes[attrName]);
|
|
1356
1376
|
}
|
|
1377
|
+
//@ts-ignore
|
|
1378
|
+
element.JOKER_NODE = node;
|
|
1357
1379
|
node.output = element;
|
|
1358
1380
|
//做穿透延迟仅对outside.click
|
|
1359
1381
|
if (node.events.some((n) => n[0] === "click" && n[1].modifiers?.includes("outside"))) {
|
|
@@ -2818,11 +2840,11 @@ class ParserTemplate {
|
|
|
2818
2840
|
this.nodeWatcherEvents = {};
|
|
2819
2841
|
this.asts.length = 0;
|
|
2820
2842
|
}
|
|
2821
|
-
|
|
2843
|
+
reSetAsts(asts, keepalive) {
|
|
2822
2844
|
//销毁历史产物
|
|
2823
2845
|
this.destroy(keepalive);
|
|
2824
2846
|
this.render = IContainer.get(Render.IRENDERIOCTAGID) ?? new Render.DomRender();
|
|
2825
|
-
this.
|
|
2847
|
+
this.asts = asts;
|
|
2826
2848
|
}
|
|
2827
2849
|
nodeTransition(node, mode, name, callBack, type) {
|
|
2828
2850
|
if (node && node.parent?.childrens && (node instanceof VNode.Element || node instanceof VNode.Component)) {
|
|
@@ -2968,13 +2990,13 @@ function isPropsType(propOption) {
|
|
|
2968
2990
|
}
|
|
2969
2991
|
|
|
2970
2992
|
const LOGTAG = "组件";
|
|
2971
|
-
const PROPS_DATA_KEY = Symbol("JOKER_PROPS_DATA_KEY");
|
|
2972
|
-
const PROPS_DATA_PROXY = Symbol("JOKER_PROPS_DATA_PROXY");
|
|
2973
|
-
const PRIVATE_WATCHERS = Symbol("JOKER_PRIVATE_WATCHERS");
|
|
2974
|
-
const EVENT_DATA_KEY = Symbol("JOKER_EVENT_DATA_KEY");
|
|
2975
|
-
const PARSER_TEMPLATE_TARGET = Symbol("JOKER_PARSER_TEMPLATE_TARGET");
|
|
2976
|
-
const SCOPE_ID = Symbol("JOKER_SCOPE_ID");
|
|
2977
|
-
const JOKER_COMPONENT_TAG = Symbol("JOKER_COMPONENT_TAG");
|
|
2993
|
+
const PROPS_DATA_KEY = Symbol.for("JOKER_PROPS_DATA_KEY");
|
|
2994
|
+
const PROPS_DATA_PROXY = Symbol.for("JOKER_PROPS_DATA_PROXY");
|
|
2995
|
+
const PRIVATE_WATCHERS = Symbol.for("JOKER_PRIVATE_WATCHERS");
|
|
2996
|
+
const EVENT_DATA_KEY = Symbol.for("JOKER_EVENT_DATA_KEY");
|
|
2997
|
+
const PARSER_TEMPLATE_TARGET = Symbol.for("JOKER_PARSER_TEMPLATE_TARGET");
|
|
2998
|
+
const SCOPE_ID = Symbol.for("JOKER_SCOPE_ID");
|
|
2999
|
+
const JOKER_COMPONENT_TAG = Symbol.for("JOKER_COMPONENT_TAG");
|
|
2978
3000
|
/**
|
|
2979
3001
|
* Joker组件
|
|
2980
3002
|
*/
|
|
@@ -3292,7 +3314,7 @@ class Component {
|
|
|
3292
3314
|
}
|
|
3293
3315
|
//执行一次render,则初始化一次template
|
|
3294
3316
|
this.template ??= [];
|
|
3295
|
-
this[PARSER_TEMPLATE_TARGET]?.
|
|
3317
|
+
this[PARSER_TEMPLATE_TARGET]?.reSetAsts(this.template, keepalive);
|
|
3296
3318
|
this[PARSER_TEMPLATE_TARGET] ??= new ParserTemplate(this.template, this, this.$root);
|
|
3297
3319
|
this[PARSER_TEMPLATE_TARGET].parser();
|
|
3298
3320
|
this[PARSER_TEMPLATE_TARGET].mount(this.$root);
|
|
@@ -3393,20 +3415,22 @@ class ComponentContainer extends Component {
|
|
|
3393
3415
|
propsVaule;
|
|
3394
3416
|
created() {
|
|
3395
3417
|
let propsData = {};
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
this
|
|
3418
|
+
if (!this.props.props) {
|
|
3419
|
+
Object.keys(this.props).forEach((p) => {
|
|
3420
|
+
//过滤
|
|
3421
|
+
if (typeof p !== "string")
|
|
3422
|
+
return;
|
|
3423
|
+
let pName = toLowerCase(p);
|
|
3424
|
+
if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
|
|
3425
|
+
return;
|
|
3426
|
+
propsData[p] = this.props[p];
|
|
3427
|
+
//单项数据同步
|
|
3428
|
+
this.$watch(() => this.props[p], () => {
|
|
3429
|
+
this.propsVaule[p] = this.props[p];
|
|
3430
|
+
});
|
|
3407
3431
|
});
|
|
3408
|
-
|
|
3409
|
-
|
|
3432
|
+
this.propsVaule = observer(propsData);
|
|
3433
|
+
}
|
|
3410
3434
|
}
|
|
3411
3435
|
async loadComponent(componentName) {
|
|
3412
3436
|
if (!componentName) {
|
|
@@ -3430,7 +3454,7 @@ class ComponentContainer extends Component {
|
|
|
3430
3454
|
if (!(JOKER_COMPONENT_TAG in component)) {
|
|
3431
3455
|
component = (await component()).default;
|
|
3432
3456
|
}
|
|
3433
|
-
cacheComponent = new component(this.propsVaule, this.$sections, this.isKeepAlive);
|
|
3457
|
+
cacheComponent = new component(this.props.props || this.propsVaule, this.$sections, this.isKeepAlive);
|
|
3434
3458
|
//事件向上穿透广播
|
|
3435
3459
|
cacheComponent.$on("*", (e) => {
|
|
3436
3460
|
this.$trigger(e.eventName, e.data, e);
|
|
@@ -3606,4 +3630,4 @@ class EventBus {
|
|
|
3606
3630
|
}
|
|
3607
3631
|
}
|
|
3608
3632
|
|
|
3609
|
-
export { Component, ComponentContainer, EventBus, IContainer, JOKER_COMPONENT_TAG, OBJECTPROXY_DEPID, ParserTemplate, SCOPE_ID, ShallowObserver, Template, VNode, Watcher, __JOKER_HMR_RUNTIME, combinedReply, defineObserverProperty, getGlobalComponent, isObserverData, observer, registerGlobalComponent, registerGlobalFunction };
|
|
3633
|
+
export { Component, ComponentContainer, Dep, EventBus, IContainer, JOKER_COMPONENT_TAG, JOKER_VNODE_TAG, OBJECTPROXY_DEPID, ParserTemplate, SCOPE_ID, ShallowObserver, Template, VNode, Watcher, __JOKER_HMR_RUNTIME, combinedReply, defineObserverProperty, getGlobalComponent, isObserverData, observer, registerGlobalComponent, registerGlobalFunction, registerOtherWindowDep, removeOtherWindowDep };
|
package/dist/bundle.js
CHANGED
|
@@ -314,6 +314,13 @@ function escape2Html(str) {
|
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
let otherWindowDeps = [];
|
|
318
|
+
function registerOtherWindowDep(dep) {
|
|
319
|
+
otherWindowDeps.push(dep);
|
|
320
|
+
}
|
|
321
|
+
function removeOtherWindowDep(dep) {
|
|
322
|
+
remove(otherWindowDeps, dep);
|
|
323
|
+
}
|
|
317
324
|
/**
|
|
318
325
|
* 作为观察者和对象代理中间的关系桥
|
|
319
326
|
* 数据变更时:Ob->dep->watcher
|
|
@@ -321,7 +328,7 @@ function escape2Html(str) {
|
|
|
321
328
|
*/
|
|
322
329
|
class Dep {
|
|
323
330
|
/**
|
|
324
|
-
* 关系id
|
|
331
|
+
* 关系id,仅在production模式下生效
|
|
325
332
|
*/
|
|
326
333
|
id = process.env.NODE_ENV === "production" ? "" : guid();
|
|
327
334
|
/**
|
|
@@ -341,6 +348,9 @@ class Dep {
|
|
|
341
348
|
*/
|
|
342
349
|
depend(key) {
|
|
343
350
|
Dep.target?.addDep(this, key);
|
|
351
|
+
otherWindowDeps.forEach((n) => {
|
|
352
|
+
n.target?.addDep(this, key);
|
|
353
|
+
});
|
|
344
354
|
}
|
|
345
355
|
/**
|
|
346
356
|
* 添加观察者
|
|
@@ -405,12 +415,12 @@ function notifyGroupDeps(list) {
|
|
|
405
415
|
/**
|
|
406
416
|
* 存放劫持对象的Dep的Key
|
|
407
417
|
*/
|
|
408
|
-
const OBJECTPROXY_DEPID = Symbol("
|
|
409
|
-
const OBJECTPROXY_DATA_KEY = Symbol("
|
|
418
|
+
const OBJECTPROXY_DEPID = Symbol.for("__JOKER_OBJECT_PROXY_DEP_ID__");
|
|
419
|
+
const OBJECTPROXY_DATA_KEY = Symbol.for("__JOKER_OBJECT_PROXY_DATA_KEY__");
|
|
410
420
|
/**
|
|
411
421
|
* 针对深度劫持关系时,需要给该对象做一个虚拟劫持的关系Key,方便事件传播
|
|
412
422
|
*/
|
|
413
|
-
const OBJECTPROXY_DEPLEVE_ID = Symbol("
|
|
423
|
+
const OBJECTPROXY_DEPLEVE_ID = Symbol.for("__JOKER_OBJECTPROXY_DEPLEVE_ID__");
|
|
414
424
|
/**
|
|
415
425
|
* 检测是否允许劫持代理
|
|
416
426
|
* @param data
|
|
@@ -424,8 +434,9 @@ function checkEnableProxy(data) {
|
|
|
424
434
|
//非冻结
|
|
425
435
|
!Object.isFrozen(data) &&
|
|
426
436
|
!(data instanceof Element) &&
|
|
427
|
-
!(
|
|
428
|
-
!(
|
|
437
|
+
!(JOKER_VNODE_TAG in data) &&
|
|
438
|
+
!(JOKER_SHALLOW_OBSERVER_TAG in data) &&
|
|
439
|
+
!(JOKER_COMPONENT_TAG in data));
|
|
429
440
|
}
|
|
430
441
|
function proxyData(data) {
|
|
431
442
|
let proxyDepTarget = getProxyDep(data);
|
|
@@ -521,7 +532,7 @@ function getProxyDep(data) {
|
|
|
521
532
|
//@ts-ignore
|
|
522
533
|
if (isObject(data)) {
|
|
523
534
|
let dep = Reflect.get(data, OBJECTPROXY_DEPID);
|
|
524
|
-
if (dep
|
|
535
|
+
if (dep) {
|
|
525
536
|
//@ts-ignore
|
|
526
537
|
return dep;
|
|
527
538
|
}
|
|
@@ -586,12 +597,14 @@ function defineObserverProperty(target, key, value) {
|
|
|
586
597
|
}
|
|
587
598
|
});
|
|
588
599
|
}
|
|
600
|
+
const JOKER_SHALLOW_OBSERVER_TAG = Symbol.for("JOKER_SHALLOW_OBSERVER");
|
|
589
601
|
/**
|
|
590
602
|
* 浅劫持监听,不污染数据源,只对根值监听,不对属性监听
|
|
591
603
|
* @returns
|
|
592
604
|
*/
|
|
593
605
|
class ShallowObserver {
|
|
594
606
|
data;
|
|
607
|
+
[JOKER_SHALLOW_OBSERVER_TAG] = true;
|
|
595
608
|
dep = new Dep();
|
|
596
609
|
constructor(data) {
|
|
597
610
|
this.data = data;
|
|
@@ -731,7 +744,7 @@ class Watcher {
|
|
|
731
744
|
if (expOrFn === undefined) {
|
|
732
745
|
this.getter = (obj) => obj;
|
|
733
746
|
}
|
|
734
|
-
else if (expOrFn
|
|
747
|
+
else if (typeof expOrFn === "function") {
|
|
735
748
|
this.getter = expOrFn;
|
|
736
749
|
}
|
|
737
750
|
else {
|
|
@@ -867,6 +880,7 @@ exports.IContainer = void 0;
|
|
|
867
880
|
IContainer.get = get;
|
|
868
881
|
})(exports.IContainer || (exports.IContainer = {}));
|
|
869
882
|
|
|
883
|
+
const JOKER_VNODE_TAG = Symbol.for("JOKER_VNODE_TAG");
|
|
870
884
|
/**
|
|
871
885
|
* 虚拟DOM
|
|
872
886
|
*
|
|
@@ -874,12 +888,13 @@ exports.IContainer = void 0;
|
|
|
874
888
|
*/
|
|
875
889
|
exports.VNode = void 0;
|
|
876
890
|
(function (VNode) {
|
|
877
|
-
VNode.PARSERKEY = Symbol("JOKER_PARSER_KEY");
|
|
891
|
+
VNode.PARSERKEY = Symbol.for("JOKER_PARSER_KEY");
|
|
878
892
|
/**
|
|
879
893
|
* VNode 基类
|
|
880
894
|
*/
|
|
881
895
|
class Node {
|
|
882
896
|
parent;
|
|
897
|
+
[JOKER_VNODE_TAG] = true;
|
|
883
898
|
/**
|
|
884
899
|
* 是否是静态节点,非动态节点。例如:element、text、comment等
|
|
885
900
|
*/
|
|
@@ -1141,7 +1156,7 @@ var Render;
|
|
|
1141
1156
|
/**
|
|
1142
1157
|
* 注入TagId
|
|
1143
1158
|
*/
|
|
1144
|
-
Render.IRENDERIOCTAGID = Symbol("JOKER_IRENDERIOC_TAGID");
|
|
1159
|
+
Render.IRENDERIOCTAGID = Symbol.for("JOKER_IRENDERIOC_TAGID");
|
|
1145
1160
|
/**
|
|
1146
1161
|
* 默认Render,采用H5-DOM模式进行输出
|
|
1147
1162
|
*/
|
|
@@ -1303,6 +1318,9 @@ var Render;
|
|
|
1303
1318
|
let resolve = () => {
|
|
1304
1319
|
removeClassName(node, getTransitionClassName(transitionName, model, "to"));
|
|
1305
1320
|
removeClassName(node, getTransitionClassName(transitionName, model, "active"));
|
|
1321
|
+
//可能存在越级删除,造成动画元素过早移除,
|
|
1322
|
+
if (!node.output)
|
|
1323
|
+
return;
|
|
1306
1324
|
node.output.removeEventListener(`${type}end`, onEnd);
|
|
1307
1325
|
if (id === node.output.__TRANSITION_EVNETID__) {
|
|
1308
1326
|
callBack?.();
|
|
@@ -1338,6 +1356,8 @@ var Render;
|
|
|
1338
1356
|
}
|
|
1339
1357
|
else if (node instanceof exports.VNode.Html) {
|
|
1340
1358
|
let conatiner = document.createElement("joker-html-container");
|
|
1359
|
+
//@ts-ignore
|
|
1360
|
+
conatiner.JOKER_NODE = node;
|
|
1341
1361
|
conatiner.root.innerHTML = node.html;
|
|
1342
1362
|
node.output = conatiner;
|
|
1343
1363
|
}
|
|
@@ -1355,6 +1375,8 @@ var Render;
|
|
|
1355
1375
|
for (let attrName in node.attributes) {
|
|
1356
1376
|
this.setAttribute(element, attrName, node.attributes[attrName]);
|
|
1357
1377
|
}
|
|
1378
|
+
//@ts-ignore
|
|
1379
|
+
element.JOKER_NODE = node;
|
|
1358
1380
|
node.output = element;
|
|
1359
1381
|
//做穿透延迟仅对outside.click
|
|
1360
1382
|
if (node.events.some((n) => n[0] === "click" && n[1].modifiers?.includes("outside"))) {
|
|
@@ -2819,11 +2841,11 @@ class ParserTemplate {
|
|
|
2819
2841
|
this.nodeWatcherEvents = {};
|
|
2820
2842
|
this.asts.length = 0;
|
|
2821
2843
|
}
|
|
2822
|
-
|
|
2844
|
+
reSetAsts(asts, keepalive) {
|
|
2823
2845
|
//销毁历史产物
|
|
2824
2846
|
this.destroy(keepalive);
|
|
2825
2847
|
this.render = exports.IContainer.get(Render.IRENDERIOCTAGID) ?? new Render.DomRender();
|
|
2826
|
-
this.
|
|
2848
|
+
this.asts = asts;
|
|
2827
2849
|
}
|
|
2828
2850
|
nodeTransition(node, mode, name, callBack, type) {
|
|
2829
2851
|
if (node && node.parent?.childrens && (node instanceof exports.VNode.Element || node instanceof exports.VNode.Component)) {
|
|
@@ -2969,13 +2991,13 @@ function isPropsType(propOption) {
|
|
|
2969
2991
|
}
|
|
2970
2992
|
|
|
2971
2993
|
const LOGTAG = "组件";
|
|
2972
|
-
const PROPS_DATA_KEY = Symbol("JOKER_PROPS_DATA_KEY");
|
|
2973
|
-
const PROPS_DATA_PROXY = Symbol("JOKER_PROPS_DATA_PROXY");
|
|
2974
|
-
const PRIVATE_WATCHERS = Symbol("JOKER_PRIVATE_WATCHERS");
|
|
2975
|
-
const EVENT_DATA_KEY = Symbol("JOKER_EVENT_DATA_KEY");
|
|
2976
|
-
const PARSER_TEMPLATE_TARGET = Symbol("JOKER_PARSER_TEMPLATE_TARGET");
|
|
2977
|
-
const SCOPE_ID = Symbol("JOKER_SCOPE_ID");
|
|
2978
|
-
const JOKER_COMPONENT_TAG = Symbol("JOKER_COMPONENT_TAG");
|
|
2994
|
+
const PROPS_DATA_KEY = Symbol.for("JOKER_PROPS_DATA_KEY");
|
|
2995
|
+
const PROPS_DATA_PROXY = Symbol.for("JOKER_PROPS_DATA_PROXY");
|
|
2996
|
+
const PRIVATE_WATCHERS = Symbol.for("JOKER_PRIVATE_WATCHERS");
|
|
2997
|
+
const EVENT_DATA_KEY = Symbol.for("JOKER_EVENT_DATA_KEY");
|
|
2998
|
+
const PARSER_TEMPLATE_TARGET = Symbol.for("JOKER_PARSER_TEMPLATE_TARGET");
|
|
2999
|
+
const SCOPE_ID = Symbol.for("JOKER_SCOPE_ID");
|
|
3000
|
+
const JOKER_COMPONENT_TAG = Symbol.for("JOKER_COMPONENT_TAG");
|
|
2979
3001
|
/**
|
|
2980
3002
|
* Joker组件
|
|
2981
3003
|
*/
|
|
@@ -3293,7 +3315,7 @@ class Component {
|
|
|
3293
3315
|
}
|
|
3294
3316
|
//执行一次render,则初始化一次template
|
|
3295
3317
|
this.template ??= [];
|
|
3296
|
-
this[PARSER_TEMPLATE_TARGET]?.
|
|
3318
|
+
this[PARSER_TEMPLATE_TARGET]?.reSetAsts(this.template, keepalive);
|
|
3297
3319
|
this[PARSER_TEMPLATE_TARGET] ??= new ParserTemplate(this.template, this, this.$root);
|
|
3298
3320
|
this[PARSER_TEMPLATE_TARGET].parser();
|
|
3299
3321
|
this[PARSER_TEMPLATE_TARGET].mount(this.$root);
|
|
@@ -3394,20 +3416,22 @@ class ComponentContainer extends Component {
|
|
|
3394
3416
|
propsVaule;
|
|
3395
3417
|
created() {
|
|
3396
3418
|
let propsData = {};
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
this
|
|
3419
|
+
if (!this.props.props) {
|
|
3420
|
+
Object.keys(this.props).forEach((p) => {
|
|
3421
|
+
//过滤
|
|
3422
|
+
if (typeof p !== "string")
|
|
3423
|
+
return;
|
|
3424
|
+
let pName = toLowerCase(p);
|
|
3425
|
+
if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
|
|
3426
|
+
return;
|
|
3427
|
+
propsData[p] = this.props[p];
|
|
3428
|
+
//单项数据同步
|
|
3429
|
+
this.$watch(() => this.props[p], () => {
|
|
3430
|
+
this.propsVaule[p] = this.props[p];
|
|
3431
|
+
});
|
|
3408
3432
|
});
|
|
3409
|
-
|
|
3410
|
-
|
|
3433
|
+
this.propsVaule = observer(propsData);
|
|
3434
|
+
}
|
|
3411
3435
|
}
|
|
3412
3436
|
async loadComponent(componentName) {
|
|
3413
3437
|
if (!componentName) {
|
|
@@ -3431,7 +3455,7 @@ class ComponentContainer extends Component {
|
|
|
3431
3455
|
if (!(JOKER_COMPONENT_TAG in component)) {
|
|
3432
3456
|
component = (await component()).default;
|
|
3433
3457
|
}
|
|
3434
|
-
cacheComponent = new component(this.propsVaule, this.$sections, this.isKeepAlive);
|
|
3458
|
+
cacheComponent = new component(this.props.props || this.propsVaule, this.$sections, this.isKeepAlive);
|
|
3435
3459
|
//事件向上穿透广播
|
|
3436
3460
|
cacheComponent.$on("*", (e) => {
|
|
3437
3461
|
this.$trigger(e.eventName, e.data, e);
|
|
@@ -3645,8 +3669,10 @@ Object.defineProperty(exports, 'createText', {
|
|
|
3645
3669
|
});
|
|
3646
3670
|
exports.Component = Component;
|
|
3647
3671
|
exports.ComponentContainer = ComponentContainer;
|
|
3672
|
+
exports.Dep = Dep;
|
|
3648
3673
|
exports.EventBus = EventBus;
|
|
3649
3674
|
exports.JOKER_COMPONENT_TAG = JOKER_COMPONENT_TAG;
|
|
3675
|
+
exports.JOKER_VNODE_TAG = JOKER_VNODE_TAG;
|
|
3650
3676
|
exports.OBJECTPROXY_DEPID = OBJECTPROXY_DEPID;
|
|
3651
3677
|
exports.ParserTemplate = ParserTemplate;
|
|
3652
3678
|
exports.SCOPE_ID = SCOPE_ID;
|
|
@@ -3661,3 +3687,5 @@ exports.isObserverData = isObserverData;
|
|
|
3661
3687
|
exports.observer = observer;
|
|
3662
3688
|
exports.registerGlobalComponent = registerGlobalComponent;
|
|
3663
3689
|
exports.registerGlobalFunction = registerGlobalFunction;
|
|
3690
|
+
exports.registerOtherWindowDep = registerOtherWindowDep;
|
|
3691
|
+
exports.removeOtherWindowDep = removeOtherWindowDep;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joker.front/core",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.170",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/bundle.js",
|
|
6
6
|
"module": "./dist/bundle.es.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "jest",
|
|
23
|
-
"test:temp": "jest test/
|
|
23
|
+
"test:temp": "jest test/parser/cmd.spec.ts",
|
|
24
24
|
"build": "joker_build_library --sourcemap=false",
|
|
25
25
|
"release": "npm run test && npm run build && joker_release_library",
|
|
26
26
|
"release:prod": "npm run test && npm run build && npm publish --access public --registry https://registry.npmjs.org/"
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"type": "git"
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
|
-
"joker"
|
|
34
|
+
"joker",
|
|
35
|
+
"front"
|
|
35
36
|
],
|
|
36
37
|
"homepage": "jokers.pub",
|
|
37
38
|
"dependencies": {
|
package/types/component.d.ts
CHANGED
|
@@ -73,12 +73,12 @@ export declare class Component<T extends DefaultKeyVal = {}> implements ICompone
|
|
|
73
73
|
* 主动声明接受的参数
|
|
74
74
|
* @returns
|
|
75
75
|
*/
|
|
76
|
-
get props(): Readonly<
|
|
76
|
+
get props(): Readonly<T>;
|
|
77
77
|
/**
|
|
78
78
|
* 挂载
|
|
79
79
|
* @param root
|
|
80
80
|
*/
|
|
81
|
-
$mount(root: any | VNode.Component
|
|
81
|
+
$mount(root: any | VNode.Component): this;
|
|
82
82
|
/**
|
|
83
83
|
* 节点动画,仅支持 element及组件节点
|
|
84
84
|
*/
|
|
@@ -197,6 +197,7 @@ export declare function getGlobalComponent(key: string): ComponentConstructor |
|
|
|
197
197
|
export declare class ComponentContainer extends Component<{
|
|
198
198
|
[key: string]: any;
|
|
199
199
|
name: string;
|
|
200
|
+
props: object;
|
|
200
201
|
"transition-name": string;
|
|
201
202
|
}> {
|
|
202
203
|
template: never[];
|
package/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./component";
|
|
|
3
3
|
export * from "./parser/vnode";
|
|
4
4
|
export { ParserTemplate, NodeChangeType } from "./parser/index";
|
|
5
5
|
export * from "./observer/watcher";
|
|
6
|
+
export { Dep, registerOtherWindowDep, removeOtherWindowDep } from "./observer/dep";
|
|
6
7
|
export * from "./observer/index";
|
|
7
8
|
export * from "./utils/DI";
|
|
8
9
|
export * from "./hmr";
|
package/types/observer/dep.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Watcher } from "./watcher";
|
|
2
|
+
export declare function registerOtherWindowDep(dep: typeof Dep): void;
|
|
3
|
+
export declare function removeOtherWindowDep(dep: typeof Dep): void;
|
|
2
4
|
/**
|
|
3
5
|
* 作为观察者和对象代理中间的关系桥
|
|
4
6
|
* 数据变更时:Ob->dep->watcher
|
|
@@ -6,7 +8,7 @@ import { Watcher } from "./watcher";
|
|
|
6
8
|
*/
|
|
7
9
|
export declare class Dep {
|
|
8
10
|
/**
|
|
9
|
-
* 关系id
|
|
11
|
+
* 关系id,仅在production模式下生效
|
|
10
12
|
*/
|
|
11
13
|
id: string;
|
|
12
14
|
/**
|
|
@@ -18,12 +18,14 @@ export declare function observer<T extends Object>(data: T, clone?: boolean): T;
|
|
|
18
18
|
* @param value
|
|
19
19
|
*/
|
|
20
20
|
export declare function defineObserverProperty(target: any, key: string | symbol, value: any): void;
|
|
21
|
+
declare const JOKER_SHALLOW_OBSERVER_TAG: unique symbol;
|
|
21
22
|
/**
|
|
22
23
|
* 浅劫持监听,不污染数据源,只对根值监听,不对属性监听
|
|
23
24
|
* @returns
|
|
24
25
|
*/
|
|
25
26
|
export declare class ShallowObserver<T> {
|
|
26
27
|
private data;
|
|
28
|
+
[JOKER_SHALLOW_OBSERVER_TAG]: boolean;
|
|
27
29
|
private dep;
|
|
28
30
|
constructor(data: T);
|
|
29
31
|
/**
|
|
@@ -44,3 +46,4 @@ export declare function combinedReply(func: Function): void;
|
|
|
44
46
|
* 判断一个值是否是已被数据代理劫持
|
|
45
47
|
*/
|
|
46
48
|
export declare function isObserverData(data: any): boolean;
|
|
49
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AST
|
|
1
|
+
import { AST } from "@joker.front/ast";
|
|
2
2
|
import { IParser } from "./parser";
|
|
3
3
|
import { Component } from "../component";
|
|
4
4
|
import { VNode } from "./vnode";
|
|
5
5
|
export declare function checkIsComponent(tagName: string, ob: Component): boolean;
|
|
6
6
|
export declare class ParserComponent extends IParser<(AST.Element | AST.Component) & {
|
|
7
|
-
node?: VNode.Component
|
|
8
|
-
}, VNode.Component
|
|
7
|
+
node?: VNode.Component;
|
|
8
|
+
}, VNode.Component> {
|
|
9
9
|
parser(): void;
|
|
10
10
|
/**
|
|
11
11
|
* 是否允许重载
|
package/types/parser/index.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export declare class ParserTemplate {
|
|
|
67
67
|
* 销毁
|
|
68
68
|
*/
|
|
69
69
|
destroy(keepalive?: boolean): void;
|
|
70
|
-
|
|
70
|
+
reSetAsts(asts: AST.Node[], keepalive?: boolean): void;
|
|
71
71
|
nodeTransition(node: VNode.Node | undefined, mode: "enter" | "leave", name?: string, callBack?: Function, type?: "transition" | "animation"): boolean;
|
|
72
72
|
}
|
|
73
73
|
export declare function getFirstElement(node: VNode.Node): VNode.Element | undefined;
|
package/types/parser/render.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { VNode } from "./vnode";
|
|
2
|
-
import { IComponent } from "@joker.front/ast";
|
|
3
2
|
type TransitionType = "transition" | "animation";
|
|
4
3
|
export declare namespace Render {
|
|
5
4
|
/**
|
|
@@ -72,7 +71,7 @@ export declare namespace Render {
|
|
|
72
71
|
destroy(): void;
|
|
73
72
|
elementToEnter(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
74
73
|
elementToLeave(node: VNode.Element, name: string, type?: TransitionType, callBack?: Function): void;
|
|
75
|
-
triggerEvent(node: VNode.Component
|
|
74
|
+
triggerEvent(node: VNode.Component, _eventName: string, _e: VNode.Event): void | false;
|
|
76
75
|
private transitionFrame;
|
|
77
76
|
private renderNode;
|
|
78
77
|
private initElementEvents;
|
package/types/parser/vnode.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Component as ComponentClass } from "../component";
|
|
|
3
3
|
import { ObType } from ".";
|
|
4
4
|
import { SectionType } from "../component";
|
|
5
5
|
import { IParser } from "./parser";
|
|
6
|
+
export declare const JOKER_VNODE_TAG: unique symbol;
|
|
6
7
|
/**
|
|
7
8
|
* 虚拟DOM
|
|
8
9
|
*
|
|
@@ -15,6 +16,7 @@ export declare namespace VNode {
|
|
|
15
16
|
*/
|
|
16
17
|
class Node {
|
|
17
18
|
parent?: Node | undefined;
|
|
19
|
+
[JOKER_VNODE_TAG]: boolean;
|
|
18
20
|
/**
|
|
19
21
|
* 是否是静态节点,非动态节点。例如:element、text、comment等
|
|
20
22
|
*/
|
|
@@ -127,7 +129,7 @@ export declare namespace VNode {
|
|
|
127
129
|
/**
|
|
128
130
|
* 组件节点
|
|
129
131
|
*/
|
|
130
|
-
class Component<T extends
|
|
132
|
+
class Component<T extends ComponentClass = ComponentClass<any> & Record<string, any>> extends Node {
|
|
131
133
|
/** 组件名(template标签名) */
|
|
132
134
|
name?: string;
|
|
133
135
|
/** 组件实例 */
|