@joker.front/core 1.2.149 → 1.2.157

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 CHANGED
@@ -432,10 +432,9 @@ function proxyData(data) {
432
432
  if (proxyDepTarget) {
433
433
  return data;
434
434
  }
435
- //@ts-ignore
436
- if (data[OBJECTPROXY_DATA_KEY]) {
437
- //@ts-ignore
438
- return data[OBJECTPROXY_DATA_KEY];
435
+ let readiedData = Reflect.get(data, OBJECTPROXY_DATA_KEY);
436
+ if (readiedData) {
437
+ return readiedData;
439
438
  }
440
439
  let dep = new Dep();
441
440
  //首次重置值
@@ -455,7 +454,7 @@ function proxyData(data) {
455
454
  if (key === OBJECTPROXY_DEPLEVE_ID) {
456
455
  return undefined;
457
456
  }
458
- let result = target[key];
457
+ let result = Reflect.get(target, key);
459
458
  if (hasProperty(target, key) === false && key !== "length") {
460
459
  return result;
461
460
  }
@@ -469,8 +468,7 @@ function proxyData(data) {
469
468
  },
470
469
  set(target, key, value) {
471
470
  if (resetData) {
472
- //@ts-ignore
473
- target[key] = value;
471
+ Reflect.set(target, key, value);
474
472
  return true;
475
473
  }
476
474
  if (checkEnableProxy(value)) {
@@ -478,8 +476,7 @@ function proxyData(data) {
478
476
  value = observer(value);
479
477
  }
480
478
  let isNewProperty = hasOwnProperty(target, key) === false;
481
- //@ts-ignore
482
- target[key] = value;
479
+ Reflect.set(target, key, value);
483
480
  notifyDep(dep, key);
484
481
  //数组长度变更,属于数组change,则对该对象做change广播
485
482
  if (Array.isArray(target)) {
@@ -492,8 +489,7 @@ function proxyData(data) {
492
489
  return true;
493
490
  },
494
491
  deleteProperty(target, key) {
495
- //@ts-ignore
496
- delete target[key];
492
+ Reflect.deleteProperty(target, key);
497
493
  //操作成功 && 非数组,删除属性时,要进行广播
498
494
  if (Array.isArray(target) === false) {
499
495
  notifyDep(dep, OBJECTPROXY_DEPLEVE_ID);
@@ -522,9 +518,12 @@ function proxyData(data) {
522
518
  */
523
519
  function getProxyDep(data) {
524
520
  //@ts-ignore
525
- if (isObject(data) && data?.[OBJECTPROXY_DEPID] && data[OBJECTPROXY_DEPID] instanceof Dep) {
526
- //@ts-ignore
527
- return data[OBJECTPROXY_DEPID];
521
+ if (isObject(data)) {
522
+ let dep = Reflect.get(data, OBJECTPROXY_DEPID);
523
+ if (dep && dep instanceof Dep) {
524
+ //@ts-ignore
525
+ return dep;
526
+ }
528
527
  }
529
528
  }
530
529
  /**
@@ -1303,6 +1302,9 @@ var Render;
1303
1302
  let resolve = () => {
1304
1303
  removeClassName(node, getTransitionClassName(transitionName, model, "to"));
1305
1304
  removeClassName(node, getTransitionClassName(transitionName, model, "active"));
1305
+ //可能存在越级删除,造成动画元素过早移除,
1306
+ if (!node.output)
1307
+ return;
1306
1308
  node.output.removeEventListener(`${type}end`, onEnd);
1307
1309
  if (id === node.output.__TRANSITION_EVNETID__) {
1308
1310
  callBack?.();
@@ -1338,6 +1340,8 @@ var Render;
1338
1340
  }
1339
1341
  else if (node instanceof VNode.Html) {
1340
1342
  let conatiner = document.createElement("joker-html-container");
1343
+ //@ts-ignore
1344
+ conatiner.JOKER_NODE = node;
1341
1345
  conatiner.root.innerHTML = node.html;
1342
1346
  node.output = conatiner;
1343
1347
  }
@@ -1355,6 +1359,8 @@ var Render;
1355
1359
  for (let attrName in node.attributes) {
1356
1360
  this.setAttribute(element, attrName, node.attributes[attrName]);
1357
1361
  }
1362
+ //@ts-ignore
1363
+ element.JOKER_NODE = node;
1358
1364
  node.output = element;
1359
1365
  //做穿透延迟仅对outside.click
1360
1366
  if (node.events.some((n) => n[0] === "click" && n[1].modifiers?.includes("outside"))) {
@@ -2301,10 +2307,16 @@ class ParserRenderSection extends IParser {
2301
2307
  *
2302
2308
  * 渲染出来的子集属于组件的子集
2303
2309
  */
2304
- this.node.ob = Object.create(this.node.section.ob || this.ob);
2305
- this.node.section.params?.forEach((item, index) => {
2306
- defineObserverProperty(this.node.ob, item, this.node.params[index]);
2307
- });
2310
+ if (this.node.section.params) {
2311
+ this.node.ob = Object.create(this.node.section.ob || this.ob);
2312
+ this.node.section.params?.forEach((item, index) => {
2313
+ defineObserverProperty(this.node.ob, item, this.node.params[index]);
2314
+ });
2315
+ }
2316
+ else {
2317
+ //无参数 不需要创建新的对象,避免性能开销
2318
+ this.node.ob = this.node.section.ob || this.ob;
2319
+ }
2308
2320
  //使用之前的node.parser去渲染
2309
2321
  (this.node.section.parser || this.ext).parserNodes(this.node.section.asts, this.node, this.node.ob);
2310
2322
  }
@@ -2433,7 +2445,7 @@ class ParserComponent extends IParser {
2433
2445
  //事件触发时,主动获取,不需要做数据劫持监听
2434
2446
  eventParams = this.runExpress(`[${event.functionParam}]`, this.ob);
2435
2447
  }
2436
- eventCallBack.call(this.ob, e, ...eventParams);
2448
+ eventCallBack.call(this.ext.ob, e, ...eventParams);
2437
2449
  }
2438
2450
  }
2439
2451
  ]);
@@ -2540,7 +2552,7 @@ class ParserComponent extends IParser {
2540
2552
  }
2541
2553
  transformPropValue(val) {
2542
2554
  if (typeof val === "function" && !(JOKER_COMPONENT_TAG in val)) {
2543
- return val.bind(this.ob);
2555
+ return val.bind(this.ext.ob);
2544
2556
  }
2545
2557
  return val;
2546
2558
  }
@@ -2599,7 +2611,7 @@ class ParserElement extends IParser {
2599
2611
  eventParams = this.runExpress(`[${event.functionParam}]`, this.ob);
2600
2612
  }
2601
2613
  if (eventCallBack) {
2602
- eventCallBack.call(this.ob, e, ...eventParams);
2614
+ eventCallBack.call(this.ext.ob, e, ...eventParams);
2603
2615
  }
2604
2616
  }
2605
2617
  }
@@ -2813,11 +2825,11 @@ class ParserTemplate {
2813
2825
  this.nodeWatcherEvents = {};
2814
2826
  this.asts.length = 0;
2815
2827
  }
2816
- reParser(asts, keepalive) {
2828
+ reSetAsts(asts, keepalive) {
2817
2829
  //销毁历史产物
2818
2830
  this.destroy(keepalive);
2819
2831
  this.render = IContainer.get(Render.IRENDERIOCTAGID) ?? new Render.DomRender();
2820
- this.parserNodes(asts, this.root);
2832
+ this.asts = asts;
2821
2833
  }
2822
2834
  nodeTransition(node, mode, name, callBack, type) {
2823
2835
  if (node && node.parent?.childrens && (node instanceof VNode.Element || node instanceof VNode.Component)) {
@@ -3287,7 +3299,7 @@ class Component {
3287
3299
  }
3288
3300
  //执行一次render,则初始化一次template
3289
3301
  this.template ??= [];
3290
- this[PARSER_TEMPLATE_TARGET]?.reParser(this.template, keepalive);
3302
+ this[PARSER_TEMPLATE_TARGET]?.reSetAsts(this.template, keepalive);
3291
3303
  this[PARSER_TEMPLATE_TARGET] ??= new ParserTemplate(this.template, this, this.$root);
3292
3304
  this[PARSER_TEMPLATE_TARGET].parser();
3293
3305
  this[PARSER_TEMPLATE_TARGET].mount(this.$root);
@@ -3388,20 +3400,22 @@ class ComponentContainer extends Component {
3388
3400
  propsVaule;
3389
3401
  created() {
3390
3402
  let propsData = {};
3391
- Object.keys(this.props).forEach((p) => {
3392
- //过滤
3393
- if (typeof p !== "string")
3394
- return;
3395
- let pName = toLowerCase(p);
3396
- if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
3397
- return;
3398
- propsData[p] = this.props[p];
3399
- //单项数据同步
3400
- this.$watch(() => this.props[p], () => {
3401
- this.propsVaule[p] = this.props[p];
3403
+ if (!this.props.props) {
3404
+ Object.keys(this.props).forEach((p) => {
3405
+ //过滤
3406
+ if (typeof p !== "string")
3407
+ return;
3408
+ let pName = toLowerCase(p);
3409
+ if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
3410
+ return;
3411
+ propsData[p] = this.props[p];
3412
+ //单项数据同步
3413
+ this.$watch(() => this.props[p], () => {
3414
+ this.propsVaule[p] = this.props[p];
3415
+ });
3402
3416
  });
3403
- });
3404
- this.propsVaule = observer(propsData);
3417
+ this.propsVaule = observer(propsData);
3418
+ }
3405
3419
  }
3406
3420
  async loadComponent(componentName) {
3407
3421
  if (!componentName) {
@@ -3425,7 +3439,7 @@ class ComponentContainer extends Component {
3425
3439
  if (!(JOKER_COMPONENT_TAG in component)) {
3426
3440
  component = (await component()).default;
3427
3441
  }
3428
- cacheComponent = new component(this.propsVaule, this.$sections, this.isKeepAlive);
3442
+ cacheComponent = new component(this.props.props || this.propsVaule, this.$sections, this.isKeepAlive);
3429
3443
  //事件向上穿透广播
3430
3444
  cacheComponent.$on("*", (e) => {
3431
3445
  this.$trigger(e.eventName, e.data, e);
package/dist/bundle.js CHANGED
@@ -433,10 +433,9 @@ function proxyData(data) {
433
433
  if (proxyDepTarget) {
434
434
  return data;
435
435
  }
436
- //@ts-ignore
437
- if (data[OBJECTPROXY_DATA_KEY]) {
438
- //@ts-ignore
439
- return data[OBJECTPROXY_DATA_KEY];
436
+ let readiedData = Reflect.get(data, OBJECTPROXY_DATA_KEY);
437
+ if (readiedData) {
438
+ return readiedData;
440
439
  }
441
440
  let dep = new Dep();
442
441
  //首次重置值
@@ -456,7 +455,7 @@ function proxyData(data) {
456
455
  if (key === OBJECTPROXY_DEPLEVE_ID) {
457
456
  return undefined;
458
457
  }
459
- let result = target[key];
458
+ let result = Reflect.get(target, key);
460
459
  if (hasProperty(target, key) === false && key !== "length") {
461
460
  return result;
462
461
  }
@@ -470,8 +469,7 @@ function proxyData(data) {
470
469
  },
471
470
  set(target, key, value) {
472
471
  if (resetData) {
473
- //@ts-ignore
474
- target[key] = value;
472
+ Reflect.set(target, key, value);
475
473
  return true;
476
474
  }
477
475
  if (checkEnableProxy(value)) {
@@ -479,8 +477,7 @@ function proxyData(data) {
479
477
  value = observer(value);
480
478
  }
481
479
  let isNewProperty = hasOwnProperty(target, key) === false;
482
- //@ts-ignore
483
- target[key] = value;
480
+ Reflect.set(target, key, value);
484
481
  notifyDep(dep, key);
485
482
  //数组长度变更,属于数组change,则对该对象做change广播
486
483
  if (Array.isArray(target)) {
@@ -493,8 +490,7 @@ function proxyData(data) {
493
490
  return true;
494
491
  },
495
492
  deleteProperty(target, key) {
496
- //@ts-ignore
497
- delete target[key];
493
+ Reflect.deleteProperty(target, key);
498
494
  //操作成功 && 非数组,删除属性时,要进行广播
499
495
  if (Array.isArray(target) === false) {
500
496
  notifyDep(dep, OBJECTPROXY_DEPLEVE_ID);
@@ -523,9 +519,12 @@ function proxyData(data) {
523
519
  */
524
520
  function getProxyDep(data) {
525
521
  //@ts-ignore
526
- if (isObject(data) && data?.[OBJECTPROXY_DEPID] && data[OBJECTPROXY_DEPID] instanceof Dep) {
527
- //@ts-ignore
528
- return data[OBJECTPROXY_DEPID];
522
+ if (isObject(data)) {
523
+ let dep = Reflect.get(data, OBJECTPROXY_DEPID);
524
+ if (dep && dep instanceof Dep) {
525
+ //@ts-ignore
526
+ return dep;
527
+ }
529
528
  }
530
529
  }
531
530
  /**
@@ -1304,6 +1303,9 @@ var Render;
1304
1303
  let resolve = () => {
1305
1304
  removeClassName(node, getTransitionClassName(transitionName, model, "to"));
1306
1305
  removeClassName(node, getTransitionClassName(transitionName, model, "active"));
1306
+ //可能存在越级删除,造成动画元素过早移除,
1307
+ if (!node.output)
1308
+ return;
1307
1309
  node.output.removeEventListener(`${type}end`, onEnd);
1308
1310
  if (id === node.output.__TRANSITION_EVNETID__) {
1309
1311
  callBack?.();
@@ -1339,6 +1341,8 @@ var Render;
1339
1341
  }
1340
1342
  else if (node instanceof exports.VNode.Html) {
1341
1343
  let conatiner = document.createElement("joker-html-container");
1344
+ //@ts-ignore
1345
+ conatiner.JOKER_NODE = node;
1342
1346
  conatiner.root.innerHTML = node.html;
1343
1347
  node.output = conatiner;
1344
1348
  }
@@ -1356,6 +1360,8 @@ var Render;
1356
1360
  for (let attrName in node.attributes) {
1357
1361
  this.setAttribute(element, attrName, node.attributes[attrName]);
1358
1362
  }
1363
+ //@ts-ignore
1364
+ element.JOKER_NODE = node;
1359
1365
  node.output = element;
1360
1366
  //做穿透延迟仅对outside.click
1361
1367
  if (node.events.some((n) => n[0] === "click" && n[1].modifiers?.includes("outside"))) {
@@ -2302,10 +2308,16 @@ class ParserRenderSection extends IParser {
2302
2308
  *
2303
2309
  * 渲染出来的子集属于组件的子集
2304
2310
  */
2305
- this.node.ob = Object.create(this.node.section.ob || this.ob);
2306
- this.node.section.params?.forEach((item, index) => {
2307
- defineObserverProperty(this.node.ob, item, this.node.params[index]);
2308
- });
2311
+ if (this.node.section.params) {
2312
+ this.node.ob = Object.create(this.node.section.ob || this.ob);
2313
+ this.node.section.params?.forEach((item, index) => {
2314
+ defineObserverProperty(this.node.ob, item, this.node.params[index]);
2315
+ });
2316
+ }
2317
+ else {
2318
+ //无参数 不需要创建新的对象,避免性能开销
2319
+ this.node.ob = this.node.section.ob || this.ob;
2320
+ }
2309
2321
  //使用之前的node.parser去渲染
2310
2322
  (this.node.section.parser || this.ext).parserNodes(this.node.section.asts, this.node, this.node.ob);
2311
2323
  }
@@ -2434,7 +2446,7 @@ class ParserComponent extends IParser {
2434
2446
  //事件触发时,主动获取,不需要做数据劫持监听
2435
2447
  eventParams = this.runExpress(`[${event.functionParam}]`, this.ob);
2436
2448
  }
2437
- eventCallBack.call(this.ob, e, ...eventParams);
2449
+ eventCallBack.call(this.ext.ob, e, ...eventParams);
2438
2450
  }
2439
2451
  }
2440
2452
  ]);
@@ -2541,7 +2553,7 @@ class ParserComponent extends IParser {
2541
2553
  }
2542
2554
  transformPropValue(val) {
2543
2555
  if (typeof val === "function" && !(JOKER_COMPONENT_TAG in val)) {
2544
- return val.bind(this.ob);
2556
+ return val.bind(this.ext.ob);
2545
2557
  }
2546
2558
  return val;
2547
2559
  }
@@ -2600,7 +2612,7 @@ class ParserElement extends IParser {
2600
2612
  eventParams = this.runExpress(`[${event.functionParam}]`, this.ob);
2601
2613
  }
2602
2614
  if (eventCallBack) {
2603
- eventCallBack.call(this.ob, e, ...eventParams);
2615
+ eventCallBack.call(this.ext.ob, e, ...eventParams);
2604
2616
  }
2605
2617
  }
2606
2618
  }
@@ -2814,11 +2826,11 @@ class ParserTemplate {
2814
2826
  this.nodeWatcherEvents = {};
2815
2827
  this.asts.length = 0;
2816
2828
  }
2817
- reParser(asts, keepalive) {
2829
+ reSetAsts(asts, keepalive) {
2818
2830
  //销毁历史产物
2819
2831
  this.destroy(keepalive);
2820
2832
  this.render = exports.IContainer.get(Render.IRENDERIOCTAGID) ?? new Render.DomRender();
2821
- this.parserNodes(asts, this.root);
2833
+ this.asts = asts;
2822
2834
  }
2823
2835
  nodeTransition(node, mode, name, callBack, type) {
2824
2836
  if (node && node.parent?.childrens && (node instanceof exports.VNode.Element || node instanceof exports.VNode.Component)) {
@@ -3288,7 +3300,7 @@ class Component {
3288
3300
  }
3289
3301
  //执行一次render,则初始化一次template
3290
3302
  this.template ??= [];
3291
- this[PARSER_TEMPLATE_TARGET]?.reParser(this.template, keepalive);
3303
+ this[PARSER_TEMPLATE_TARGET]?.reSetAsts(this.template, keepalive);
3292
3304
  this[PARSER_TEMPLATE_TARGET] ??= new ParserTemplate(this.template, this, this.$root);
3293
3305
  this[PARSER_TEMPLATE_TARGET].parser();
3294
3306
  this[PARSER_TEMPLATE_TARGET].mount(this.$root);
@@ -3389,20 +3401,22 @@ class ComponentContainer extends Component {
3389
3401
  propsVaule;
3390
3402
  created() {
3391
3403
  let propsData = {};
3392
- Object.keys(this.props).forEach((p) => {
3393
- //过滤
3394
- if (typeof p !== "string")
3395
- return;
3396
- let pName = toLowerCase(p);
3397
- if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
3398
- return;
3399
- propsData[p] = this.props[p];
3400
- //单项数据同步
3401
- this.$watch(() => this.props[p], () => {
3402
- this.propsVaule[p] = this.props[p];
3404
+ if (!this.props.props) {
3405
+ Object.keys(this.props).forEach((p) => {
3406
+ //过滤
3407
+ if (typeof p !== "string")
3408
+ return;
3409
+ let pName = toLowerCase(p);
3410
+ if (pName === "transition-name" || pName === "name" || pName === "keep-alive" || pName === "ref")
3411
+ return;
3412
+ propsData[p] = this.props[p];
3413
+ //单项数据同步
3414
+ this.$watch(() => this.props[p], () => {
3415
+ this.propsVaule[p] = this.props[p];
3416
+ });
3403
3417
  });
3404
- });
3405
- this.propsVaule = observer(propsData);
3418
+ this.propsVaule = observer(propsData);
3419
+ }
3406
3420
  }
3407
3421
  async loadComponent(componentName) {
3408
3422
  if (!componentName) {
@@ -3426,7 +3440,7 @@ class ComponentContainer extends Component {
3426
3440
  if (!(JOKER_COMPONENT_TAG in component)) {
3427
3441
  component = (await component()).default;
3428
3442
  }
3429
- cacheComponent = new component(this.propsVaule, this.$sections, this.isKeepAlive);
3443
+ cacheComponent = new component(this.props.props || this.propsVaule, this.$sections, this.isKeepAlive);
3430
3444
  //事件向上穿透广播
3431
3445
  cacheComponent.$on("*", (e) => {
3432
3446
  this.$trigger(e.eventName, e.data, e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joker.front/core",
3
- "version": "1.2.149",
3
+ "version": "1.2.157",
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/parser/html.spec.ts",
23
+ "test:temp": "jest test/other/ob-source.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/"
@@ -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[];
@@ -67,7 +67,7 @@ export declare class ParserTemplate {
67
67
  * 销毁
68
68
  */
69
69
  destroy(keepalive?: boolean): void;
70
- reParser(asts: AST.Node[], keepalive?: boolean): void;
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;
@@ -0,0 +1,2 @@
1
+ export declare function createObject(source: Object): any;
2
+ export declare function getObjectRootProtorype(source: any): Object;