@next-core/brick-kit 2.104.4 → 2.105.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/CHANGELOG.md CHANGED
@@ -3,6 +3,47 @@
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.105.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.7...@next-core/brick-kit@2.105.0) (2022-02-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * 新增`PATH_NAME`常量 ([094fe48](https://github.com/easyops-cn/next-core/commit/094fe4877581b7594ea297a3da5c4ae047d9cc4d))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.104.7](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.6...@next-core/brick-kit@2.104.7) (2022-02-17)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * mark lazy useBrick for tpl property merge ([5794719](https://github.com/easyops-cn/next-core/commit/579471913e569856772e24ccdf024519b6680aaa))
23
+
24
+
25
+
26
+
27
+
28
+ ## [2.104.6](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.104.5...@next-core/brick-kit@2.104.6) (2022-02-15)
29
+
30
+ **Note:** Version bump only for package @next-core/brick-kit
31
+
32
+
33
+
34
+
35
+
36
+ ## [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)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * fix re-render of useBrick of tpl ([7cbd0d8](https://github.com/easyops-cn/next-core/commit/7cbd0d83517afdb1eef9fafb5e803655f3e698b9))
42
+
43
+
44
+
45
+
46
+
6
47
  ## [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)
7
48
 
8
49
 
@@ -1979,17 +1979,38 @@
1979
1979
 
1980
1980
  return _asyncToGenerator__default["default"](function* () {
1981
1981
  if (Array.isArray(contextConfs)) {
1982
- yield brickUtils.resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, coreContext, _this, brick));
1982
+ var {
1983
+ mergedContext,
1984
+ keyword
1985
+ } = _this.getResolveOptions(coreContext);
1986
+
1987
+ yield brickUtils.resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, mergedContext, _this, brick), keyword);
1983
1988
  }
1984
1989
  })();
1985
1990
  }
1986
1991
 
1987
1992
  syncDefine(contextConfs, coreContext, brick) {
1988
1993
  if (Array.isArray(contextConfs)) {
1989
- brickUtils.syncResolveContextConcurrently(contextConfs, contextConf => syncResolveStoryboardContext(contextConf, coreContext, this, brick));
1994
+ var {
1995
+ mergedContext,
1996
+ keyword
1997
+ } = this.getResolveOptions(coreContext);
1998
+ brickUtils.syncResolveContextConcurrently(contextConfs, contextConf => syncResolveStoryboardContext(contextConf, mergedContext, this, brick), keyword);
1990
1999
  }
1991
2000
  }
1992
2001
 
2002
+ getResolveOptions(coreContext) {
2003
+ return this.tplContextId ? {
2004
+ mergedContext: _objectSpread__default["default"](_objectSpread__default["default"]({}, coreContext), {}, {
2005
+ tplContextId: this.tplContextId
2006
+ }),
2007
+ keyword: "STATE"
2008
+ } : {
2009
+ mergedContext: coreContext,
2010
+ keyword: "CTX"
2011
+ };
2012
+ }
2013
+
1993
2014
  }
1994
2015
 
1995
2016
  function resolveStoryboardContext(_x, _x2, _x3, _x4) {
@@ -2024,23 +2045,23 @@
2024
2045
  }
2025
2046
 
2026
2047
  function _resolveNormalStoryboardContext() {
2027
- _resolveNormalStoryboardContext = _asyncToGenerator__default["default"](function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2028
- if (!looseCheckIf(contextConf, coreContext)) {
2048
+ _resolveNormalStoryboardContext = _asyncToGenerator__default["default"](function* (contextConf, mergedContext, storyboardContextWrapper, brick) {
2049
+ if (!looseCheckIf(contextConf, mergedContext)) {
2029
2050
  return false;
2030
2051
  }
2031
2052
 
2032
2053
  var isResolve = false;
2033
- var value = getDefinedTemplateState(contextConf, storyboardContextWrapper, brick);
2054
+ var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2034
2055
 
2035
2056
  if (value === undefined) {
2036
2057
  if (contextConf.resolve) {
2037
- if (looseCheckIf(contextConf.resolve, coreContext)) {
2058
+ if (looseCheckIf(contextConf.resolve, mergedContext)) {
2038
2059
  isResolve = true;
2039
2060
  var valueConf = {};
2040
2061
  yield _internalApiGetResolver().resolveOne("reference", _objectSpread__default["default"]({
2041
2062
  transform: "value",
2042
2063
  transformMapArray: false
2043
- }, contextConf.resolve), valueConf, null, coreContext);
2064
+ }, contextConf.resolve), valueConf, null, mergedContext);
2044
2065
  value = valueConf.value;
2045
2066
  } else if (!brickUtils.hasOwnProperty(contextConf, "value")) {
2046
2067
  return false;
@@ -2048,18 +2069,18 @@
2048
2069
  }
2049
2070
 
2050
2071
  if (!isResolve && contextConf.value !== undefined) {
2051
- value = computeRealValue(contextConf.value, coreContext, true);
2072
+ value = computeRealValue(contextConf.value, mergedContext, true);
2052
2073
  }
2053
2074
  }
2054
2075
 
2055
- resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick);
2076
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2056
2077
  return true;
2057
2078
  });
2058
2079
  return _resolveNormalStoryboardContext.apply(this, arguments);
2059
2080
  }
2060
2081
 
2061
- function syncResolveStoryboardContext(contextConf, coreContext, storyboardContextWrapper, brick) {
2062
- if (!looseCheckIf(contextConf, coreContext)) {
2082
+ function syncResolveStoryboardContext(contextConf, mergedContext, storyboardContextWrapper, brick) {
2083
+ if (!looseCheckIf(contextConf, mergedContext)) {
2063
2084
  return false;
2064
2085
  }
2065
2086
 
@@ -2067,23 +2088,23 @@
2067
2088
  throw new Error("resolve is not allowed here");
2068
2089
  }
2069
2090
 
2070
- var value = getDefinedTemplateState(contextConf, storyboardContextWrapper, brick);
2091
+ var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2071
2092
 
2072
2093
  if (value === undefined) {
2073
- value = computeRealValue(contextConf.value, coreContext, true);
2094
+ value = computeRealValue(contextConf.value, mergedContext, true);
2074
2095
  }
2075
2096
 
2076
- resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick);
2097
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2077
2098
  return true;
2078
2099
  }
2079
2100
 
2080
- function getDefinedTemplateState(contextConf, storyboardContextWrapper, brick) {
2081
- if (storyboardContextWrapper.tplContextId && brick.properties && brickUtils.hasOwnProperty(brick.properties, contextConf.name)) {
2101
+ function getDefinedTemplateState(isTemplateState, contextConf, brick) {
2102
+ if (isTemplateState && brick.properties && brickUtils.hasOwnProperty(brick.properties, contextConf.name)) {
2082
2103
  return brick.properties[contextConf.name];
2083
2104
  }
2084
2105
  }
2085
2106
 
2086
- function resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick) {
2107
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
2087
2108
  var newContext = {
2088
2109
  type: "free-variable",
2089
2110
  value,
@@ -2093,13 +2114,7 @@
2093
2114
 
2094
2115
  if (contextConf.onChange) {
2095
2116
  for (var handler of [].concat(contextConf.onChange)) {
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
- }
2117
+ newContext.eventTarget.addEventListener(storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
2103
2118
  }
2104
2119
  }
2105
2120
 
@@ -2277,6 +2292,7 @@
2277
2292
  sys,
2278
2293
  flags,
2279
2294
  hash,
2295
+ pathname,
2280
2296
  segues,
2281
2297
  storyboardContext
2282
2298
  } = _internalApiGetCurrentContext();
@@ -2317,6 +2333,9 @@
2317
2333
  case "HASH":
2318
2334
  return hash;
2319
2335
 
2336
+ case "PATH_NAME":
2337
+ return pathname;
2338
+
2320
2339
  case "INSTALLED_APPS":
2321
2340
  return {
2322
2341
  has: (appId, matchVersion) => getRuntime().hasInstalledApp(appId, matchVersion)
@@ -8492,6 +8511,7 @@
8492
8511
  var auth = getAuth();
8493
8512
  var context = {
8494
8513
  hash: this.location.hash,
8514
+ pathname: this.location.pathname,
8495
8515
  query: this.query,
8496
8516
  match,
8497
8517
  app: this.kernel.nextApp,
@@ -10129,7 +10149,9 @@
10129
10149
  // Use an approach like template-literal's quasis:
10130
10150
  // `quasi0${0}quais1${1}quasi2...`
10131
10151
  // Every quasi can be merged with multiple items.
10132
- var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true) : [];
10152
+ var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true, {
10153
+ $$lazyForUseBrick: true
10154
+ }) : [];
10133
10155
  var quasis = [];
10134
10156
  var size = computedBaseValue.length + 1;
10135
10157
 
@@ -10519,7 +10541,7 @@
10519
10541
  return false;
10520
10542
  }
10521
10543
 
10522
- function handleProxyOfCustomTemplate(brick, reRun) {
10544
+ function handleProxyOfCustomTemplate(brick) {
10523
10545
  // Ignore non-tpl bricks.
10524
10546
  if (!brick.proxyRefs) {
10525
10547
  return;
@@ -10533,17 +10555,18 @@
10533
10555
 
10534
10556
  return (_brick$proxyRefs$get$ = brick.proxyRefs.get(ref).brick) === null || _brick$proxyRefs$get$ === void 0 ? void 0 : _brick$proxyRefs$get$.element;
10535
10557
  }
10536
- } // For usages of `targetRef: "..."`.
10537
- // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10558
+ }
10538
10559
 
10560
+ var firstRun = !node.$$getElementByRef; // For usages of `targetRef: "..."`.
10561
+ // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10539
10562
 
10540
- if (!reRun) {
10563
+ if (firstRun) {
10541
10564
  Object.defineProperty(node, "$$getElementByRef", {
10542
10565
  value: getElementByRef
10543
10566
  });
10544
10567
  }
10545
10568
 
10546
- if (!reRun && brick.stateNames) {
10569
+ if (firstRun && brick.stateNames) {
10547
10570
  (function () {
10548
10571
  // Define properties from state for tpl.
10549
10572
  var getState = () => getCustomTemplateContext(brick.tplContextId).state;
@@ -11203,7 +11226,7 @@
11203
11226
  handleProxyOfCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, tplBrick), {}, {
11204
11227
  proxyRefs: singleRefBrickProxyMap,
11205
11228
  proxy: getFilterProxy(tplBrick.proxy, brick.ref)
11206
- }), true);
11229
+ }));
11207
11230
  setRealProperties(tplBrick.element, tplBrick.properties || {});
11208
11231
  }
11209
11232
  }