@next-core/brick-kit 2.104.1 → 2.104.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,50 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.104.5](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.4...@next-core/brick-kit@2.104.5) (2022-02-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix re-render of useBrick of tpl ([7cbd0d8](https://github.com/easyops-cn/next-core/commit/7cbd0d83517afdb1eef9fafb5e803655f3e698b9))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.104.4](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.3...@next-core/brick-kit@2.104.4) (2022-02-15)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * fix targetRef on working in state.onChange ([bac0003](https://github.com/easyops-cn/next-core/commit/bac000367d82ebd428a2aa08d05193b129718eb7))
23
+
24
+
25
+
26
+
27
+
28
+ ## [2.104.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.2...@next-core/brick-kit@2.104.3) (2022-02-15)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * fix missing tpl context when setting properties by callback ([c681dd4](https://github.com/easyops-cn/next-core/commit/c681dd41baec10a9f5eb13ac6bccfa5ae559044c))
34
+
35
+
36
+
37
+
38
+
39
+ ## [2.104.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.1...@next-core/brick-kit@2.104.2) (2022-02-15)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * fix state.onChange ([cfdfbf8](https://github.com/easyops-cn/next-core/commit/cfdfbf80574cbaa38168b42b5c0899a71f28be12))
45
+
46
+
47
+
48
+
49
+
6
50
  ## [2.104.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.0...@next-core/brick-kit@2.104.1) (2022-02-14)
7
51
 
8
52
 
@@ -1903,12 +1903,12 @@
1903
1903
  }
1904
1904
 
1905
1905
  class StoryboardContextWrapper {
1906
- constructor(isTemplateState) {
1906
+ constructor(tplContextId) {
1907
1907
  _defineProperty__default["default"](this, "data", new Map());
1908
1908
 
1909
- _defineProperty__default["default"](this, "isTemplateState", void 0);
1909
+ _defineProperty__default["default"](this, "tplContextId", void 0);
1910
1910
 
1911
- this.isTemplateState = isTemplateState;
1911
+ this.tplContextId = tplContextId;
1912
1912
  }
1913
1913
 
1914
1914
  set(name, item) {
@@ -1936,7 +1936,7 @@
1936
1936
  var _item$eventTarget;
1937
1937
 
1938
1938
  if (!this.data.has(name)) {
1939
- if (this.isTemplateState) {
1939
+ if (this.tplContextId) {
1940
1940
  throw new Error("State not found: ".concat(name));
1941
1941
  } else {
1942
1942
  // eslint-disable-next-line no-console
@@ -1969,7 +1969,7 @@
1969
1969
  }
1970
1970
  }
1971
1971
 
1972
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.isTemplateState ? "state.change" : "context.change", {
1972
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
1973
1973
  detail: item.value
1974
1974
  }));
1975
1975
  }
@@ -1979,7 +1979,7 @@
1979
1979
 
1980
1980
  return _asyncToGenerator__default["default"](function* () {
1981
1981
  if (Array.isArray(contextConfs)) {
1982
- yield brickUtils.resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(_this.isTemplateState, contextConf, coreContext, _this, brick));
1982
+ yield brickUtils.resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, coreContext, _this, brick));
1983
1983
  }
1984
1984
  })();
1985
1985
  }
@@ -1992,14 +1992,14 @@
1992
1992
 
1993
1993
  }
1994
1994
 
1995
- function resolveStoryboardContext(_x, _x2, _x3, _x4, _x5) {
1995
+ function resolveStoryboardContext(_x, _x2, _x3, _x4) {
1996
1996
  return _resolveStoryboardContext.apply(this, arguments);
1997
1997
  }
1998
1998
 
1999
1999
  function _resolveStoryboardContext() {
2000
- _resolveStoryboardContext = _asyncToGenerator__default["default"](function* (isTemplateState, contextConf, coreContext, storyboardContextWrapper, brick) {
2000
+ _resolveStoryboardContext = _asyncToGenerator__default["default"](function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2001
2001
  if (contextConf.property) {
2002
- if (isTemplateState) {
2002
+ if (storyboardContextWrapper.tplContextId) {
2003
2003
  throw new Error("Setting `property` is not allowed in template scoped context");
2004
2004
  }
2005
2005
 
@@ -2019,7 +2019,7 @@
2019
2019
  return _resolveStoryboardContext.apply(this, arguments);
2020
2020
  }
2021
2021
 
2022
- function resolveNormalStoryboardContext(_x6, _x7, _x8, _x9) {
2022
+ function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
2023
2023
  return _resolveNormalStoryboardContext.apply(this, arguments);
2024
2024
  }
2025
2025
 
@@ -2078,7 +2078,7 @@
2078
2078
  }
2079
2079
 
2080
2080
  function getDefinedTemplateState(contextConf, storyboardContextWrapper, brick) {
2081
- if (storyboardContextWrapper.isTemplateState && brick.properties && brickUtils.hasOwnProperty(brick.properties, contextConf.name)) {
2081
+ if (storyboardContextWrapper.tplContextId && brick.properties && brickUtils.hasOwnProperty(brick.properties, contextConf.name)) {
2082
2082
  return brick.properties[contextConf.name];
2083
2083
  }
2084
2084
  }
@@ -2093,7 +2093,13 @@
2093
2093
 
2094
2094
  if (contextConf.onChange) {
2095
2095
  for (var handler of [].concat(contextConf.onChange)) {
2096
- newContext.eventTarget.addEventListener("context.change", listenerFactory(handler, coreContext, brick));
2096
+ if (storyboardContextWrapper.tplContextId) {
2097
+ newContext.eventTarget.addEventListener("state.change", listenerFactory(handler, _objectSpread__default["default"](_objectSpread__default["default"]({}, coreContext), {}, {
2098
+ tplContextId: storyboardContextWrapper.tplContextId
2099
+ }), brick));
2100
+ } else {
2101
+ newContext.eventTarget.addEventListener("context.change", listenerFactory(handler, coreContext, brick));
2102
+ }
2097
2103
  }
2098
2104
  }
2099
2105
 
@@ -2105,12 +2111,13 @@
2105
2111
  constructor(brick) {
2106
2112
  _defineProperty__default["default"](this, "variables", void 0);
2107
2113
 
2108
- _defineProperty__default["default"](this, "state", new StoryboardContextWrapper(true));
2114
+ _defineProperty__default["default"](this, "state", void 0);
2109
2115
 
2110
2116
  _defineProperty__default["default"](this, "id", lodash.uniqueId("tpl-ctx-"));
2111
2117
 
2112
2118
  this.brick = brick;
2113
2119
  tplContextMap.set(this.id, this);
2120
+ this.state = new StoryboardContextWrapper(this.id);
2114
2121
  brick.tplContextId = this.id;
2115
2122
  }
2116
2123
 
@@ -2434,6 +2441,49 @@
2434
2441
  }
2435
2442
  }
2436
2443
 
2444
+ var customTemplateRegistry = new Map();
2445
+ var appRegistered = new Set();
2446
+ var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
2447
+ var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
2448
+ var symbolForTplContextId = Symbol.for("tpl.contextId");
2449
+
2450
+ function setupUseBrickInTemplate(props, tplContextId) {
2451
+ function walk(props) {
2452
+ if (!props) {
2453
+ return;
2454
+ }
2455
+
2456
+ for (var [key, value] of Object.entries(props)) {
2457
+ if (brickUtils.isObject(value)) {
2458
+ if (key === "useBrick") {
2459
+ if (Array.isArray(value)) {
2460
+ value.forEach(setup);
2461
+ } else {
2462
+ setup(value);
2463
+ }
2464
+ } else {
2465
+ walk(value);
2466
+ }
2467
+ }
2468
+ }
2469
+ }
2470
+
2471
+ function setup(item) {
2472
+ item[symbolForTplContextId] = tplContextId;
2473
+ walk(item.properties);
2474
+
2475
+ if (item.slots) {
2476
+ Object.values(item.slots).forEach(slot => {
2477
+ if (Array.isArray(slot.bricks)) {
2478
+ slot.bricks.forEach(setup);
2479
+ }
2480
+ });
2481
+ }
2482
+ }
2483
+
2484
+ walk(props);
2485
+ }
2486
+
2437
2487
  var computeRealValue = (value, context, injectDeep, internalOptions) => {
2438
2488
  var preEvaluated = isPreEvaluated(value);
2439
2489
 
@@ -2487,6 +2537,10 @@
2487
2537
  function setProperties(bricks, properties, context, injectDeep) {
2488
2538
  var realProps = computeRealProperties(properties, context, injectDeep);
2489
2539
 
2540
+ if (context.tplContextId) {
2541
+ setupUseBrickInTemplate(realProps, context.tplContextId);
2542
+ }
2543
+
2490
2544
  if (!Array.isArray(bricks)) {
2491
2545
  bricks = [bricks];
2492
2546
  }
@@ -10001,12 +10055,6 @@
10001
10055
 
10002
10056
  }
10003
10057
 
10004
- var customTemplateRegistry = new Map();
10005
- var appRegistered = new Set();
10006
- var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
10007
- var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
10008
- var symbolForTplContextId = Symbol.for("tpl.contextId");
10009
-
10010
10058
  function isBasicProperty(propRef) {
10011
10059
  return !!propRef.refProperty;
10012
10060
  }
@@ -10181,43 +10229,6 @@
10181
10229
  }
10182
10230
  }
10183
10231
 
10184
- function setupUseBrickInTemplate(props, tplContextId) {
10185
- function walk(props) {
10186
- if (!props) {
10187
- return;
10188
- }
10189
-
10190
- for (var [key, value] of Object.entries(props)) {
10191
- if (brickUtils.isObject(value)) {
10192
- if (key === "useBrick") {
10193
- if (Array.isArray(value)) {
10194
- value.forEach(setup);
10195
- } else {
10196
- setup(value);
10197
- }
10198
- } else {
10199
- walk(value);
10200
- }
10201
- }
10202
- }
10203
- }
10204
-
10205
- function setup(item) {
10206
- item[symbolForTplContextId] = tplContextId;
10207
- walk(item.properties);
10208
-
10209
- if (item.slots) {
10210
- Object.values(item.slots).forEach(slot => {
10211
- if (Array.isArray(slot.bricks)) {
10212
- slot.bricks.forEach(setup);
10213
- }
10214
- });
10215
- }
10216
- }
10217
-
10218
- walk(props);
10219
- }
10220
-
10221
10232
  var _excluded$1 = ["properties", "slots"],
10222
10233
  _excluded2 = ["ref", "slots"];
10223
10234
  function expandCustomTemplate(brickConf, proxyBrick, context) {
@@ -10508,7 +10519,7 @@
10508
10519
  return false;
10509
10520
  }
10510
10521
 
10511
- function handleProxyOfCustomTemplate(brick, reRun) {
10522
+ function handleProxyOfCustomTemplate(brick) {
10512
10523
  // Ignore non-tpl bricks.
10513
10524
  if (!brick.proxyRefs) {
10514
10525
  return;
@@ -10522,17 +10533,18 @@
10522
10533
 
10523
10534
  return (_brick$proxyRefs$get$ = brick.proxyRefs.get(ref).brick) === null || _brick$proxyRefs$get$ === void 0 ? void 0 : _brick$proxyRefs$get$.element;
10524
10535
  }
10525
- } // For usages of `targetRef: "..."`.
10526
- // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10536
+ }
10527
10537
 
10538
+ var firstRun = !node.$$getElementByRef; // For usages of `targetRef: "..."`.
10539
+ // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10528
10540
 
10529
- if (!reRun) {
10541
+ if (firstRun) {
10530
10542
  Object.defineProperty(node, "$$getElementByRef", {
10531
10543
  value: getElementByRef
10532
10544
  });
10533
10545
  }
10534
10546
 
10535
- if (!reRun && brick.stateNames) {
10547
+ if (firstRun && brick.stateNames) {
10536
10548
  (function () {
10537
10549
  // Define properties from state for tpl.
10538
10550
  var getState = () => getCustomTemplateContext(brick.tplContextId).state;
@@ -11192,7 +11204,7 @@
11192
11204
  handleProxyOfCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, tplBrick), {}, {
11193
11205
  proxyRefs: singleRefBrickProxyMap,
11194
11206
  proxy: getFilterProxy(tplBrick.proxy, brick.ref)
11195
- }), true);
11207
+ }));
11196
11208
  setRealProperties(tplBrick.element, tplBrick.properties || {});
11197
11209
  }
11198
11210
  }