@next-core/brick-kit 2.104.2 → 2.104.6

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.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)
7
+
8
+ **Note:** Version bump only for package @next-core/brick-kit
9
+
10
+
11
+
12
+
13
+
14
+ ## [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)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * fix re-render of useBrick of tpl ([7cbd0d8](https://github.com/easyops-cn/next-core/commit/7cbd0d83517afdb1eef9fafb5e803655f3e698b9))
20
+
21
+
22
+
23
+
24
+
25
+ ## [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)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * fix targetRef on working in state.onChange ([bac0003](https://github.com/easyops-cn/next-core/commit/bac000367d82ebd428a2aa08d05193b129718eb7))
31
+
32
+
33
+
34
+
35
+
36
+ ## [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)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * fix missing tpl context when setting properties by callback ([c681dd4](https://github.com/easyops-cn/next-core/commit/c681dd41baec10a9f5eb13ac6bccfa5ae559044c))
42
+
43
+
44
+
45
+
46
+
6
47
  ## [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)
7
48
 
8
49
 
@@ -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,27 +1979,48 @@
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
+ 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
- function resolveStoryboardContext(_x, _x2, _x3, _x4, _x5) {
2016
+ function resolveStoryboardContext(_x, _x2, _x3, _x4) {
1996
2017
  return _resolveStoryboardContext.apply(this, arguments);
1997
2018
  }
1998
2019
 
1999
2020
  function _resolveStoryboardContext() {
2000
- _resolveStoryboardContext = _asyncToGenerator__default["default"](function* (isTemplateState, contextConf, coreContext, storyboardContextWrapper, brick) {
2021
+ _resolveStoryboardContext = _asyncToGenerator__default["default"](function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2001
2022
  if (contextConf.property) {
2002
- if (isTemplateState) {
2023
+ if (storyboardContextWrapper.tplContextId) {
2003
2024
  throw new Error("Setting `property` is not allowed in template scoped context");
2004
2025
  }
2005
2026
 
@@ -2019,28 +2040,28 @@
2019
2040
  return _resolveStoryboardContext.apply(this, arguments);
2020
2041
  }
2021
2042
 
2022
- function resolveNormalStoryboardContext(_x6, _x7, _x8, _x9) {
2043
+ function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
2023
2044
  return _resolveNormalStoryboardContext.apply(this, arguments);
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.isTemplateState && 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,7 +2114,7 @@
2093
2114
 
2094
2115
  if (contextConf.onChange) {
2095
2116
  for (var handler of [].concat(contextConf.onChange)) {
2096
- newContext.eventTarget.addEventListener(storyboardContextWrapper.isTemplateState ? "state.change" : "context.change", listenerFactory(handler, coreContext, brick));
2117
+ newContext.eventTarget.addEventListener(storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
2097
2118
  }
2098
2119
  }
2099
2120
 
@@ -2105,12 +2126,13 @@
2105
2126
  constructor(brick) {
2106
2127
  _defineProperty__default["default"](this, "variables", void 0);
2107
2128
 
2108
- _defineProperty__default["default"](this, "state", new StoryboardContextWrapper(true));
2129
+ _defineProperty__default["default"](this, "state", void 0);
2109
2130
 
2110
2131
  _defineProperty__default["default"](this, "id", lodash.uniqueId("tpl-ctx-"));
2111
2132
 
2112
2133
  this.brick = brick;
2113
2134
  tplContextMap.set(this.id, this);
2135
+ this.state = new StoryboardContextWrapper(this.id);
2114
2136
  brick.tplContextId = this.id;
2115
2137
  }
2116
2138
 
@@ -2434,6 +2456,49 @@
2434
2456
  }
2435
2457
  }
2436
2458
 
2459
+ var customTemplateRegistry = new Map();
2460
+ var appRegistered = new Set();
2461
+ var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
2462
+ var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
2463
+ var symbolForTplContextId = Symbol.for("tpl.contextId");
2464
+
2465
+ function setupUseBrickInTemplate(props, tplContextId) {
2466
+ function walk(props) {
2467
+ if (!props) {
2468
+ return;
2469
+ }
2470
+
2471
+ for (var [key, value] of Object.entries(props)) {
2472
+ if (brickUtils.isObject(value)) {
2473
+ if (key === "useBrick") {
2474
+ if (Array.isArray(value)) {
2475
+ value.forEach(setup);
2476
+ } else {
2477
+ setup(value);
2478
+ }
2479
+ } else {
2480
+ walk(value);
2481
+ }
2482
+ }
2483
+ }
2484
+ }
2485
+
2486
+ function setup(item) {
2487
+ item[symbolForTplContextId] = tplContextId;
2488
+ walk(item.properties);
2489
+
2490
+ if (item.slots) {
2491
+ Object.values(item.slots).forEach(slot => {
2492
+ if (Array.isArray(slot.bricks)) {
2493
+ slot.bricks.forEach(setup);
2494
+ }
2495
+ });
2496
+ }
2497
+ }
2498
+
2499
+ walk(props);
2500
+ }
2501
+
2437
2502
  var computeRealValue = (value, context, injectDeep, internalOptions) => {
2438
2503
  var preEvaluated = isPreEvaluated(value);
2439
2504
 
@@ -2487,6 +2552,10 @@
2487
2552
  function setProperties(bricks, properties, context, injectDeep) {
2488
2553
  var realProps = computeRealProperties(properties, context, injectDeep);
2489
2554
 
2555
+ if (context.tplContextId) {
2556
+ setupUseBrickInTemplate(realProps, context.tplContextId);
2557
+ }
2558
+
2490
2559
  if (!Array.isArray(bricks)) {
2491
2560
  bricks = [bricks];
2492
2561
  }
@@ -10001,12 +10070,6 @@
10001
10070
 
10002
10071
  }
10003
10072
 
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
10073
  function isBasicProperty(propRef) {
10011
10074
  return !!propRef.refProperty;
10012
10075
  }
@@ -10181,43 +10244,6 @@
10181
10244
  }
10182
10245
  }
10183
10246
 
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
10247
  var _excluded$1 = ["properties", "slots"],
10222
10248
  _excluded2 = ["ref", "slots"];
10223
10249
  function expandCustomTemplate(brickConf, proxyBrick, context) {
@@ -10508,7 +10534,7 @@
10508
10534
  return false;
10509
10535
  }
10510
10536
 
10511
- function handleProxyOfCustomTemplate(brick, reRun) {
10537
+ function handleProxyOfCustomTemplate(brick) {
10512
10538
  // Ignore non-tpl bricks.
10513
10539
  if (!brick.proxyRefs) {
10514
10540
  return;
@@ -10522,17 +10548,18 @@
10522
10548
 
10523
10549
  return (_brick$proxyRefs$get$ = brick.proxyRefs.get(ref).brick) === null || _brick$proxyRefs$get$ === void 0 ? void 0 : _brick$proxyRefs$get$.element;
10524
10550
  }
10525
- } // For usages of `targetRef: "..."`.
10526
- // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10551
+ }
10527
10552
 
10553
+ var firstRun = !node.$$getElementByRef; // For usages of `targetRef: "..."`.
10554
+ // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10528
10555
 
10529
- if (!reRun) {
10556
+ if (firstRun) {
10530
10557
  Object.defineProperty(node, "$$getElementByRef", {
10531
10558
  value: getElementByRef
10532
10559
  });
10533
10560
  }
10534
10561
 
10535
- if (!reRun && brick.stateNames) {
10562
+ if (firstRun && brick.stateNames) {
10536
10563
  (function () {
10537
10564
  // Define properties from state for tpl.
10538
10565
  var getState = () => getCustomTemplateContext(brick.tplContextId).state;
@@ -11192,7 +11219,7 @@
11192
11219
  handleProxyOfCustomTemplate(_objectSpread__default["default"](_objectSpread__default["default"]({}, tplBrick), {}, {
11193
11220
  proxyRefs: singleRefBrickProxyMap,
11194
11221
  proxy: getFilterProxy(tplBrick.proxy, brick.ref)
11195
- }), true);
11222
+ }));
11196
11223
  setRealProperties(tplBrick.element, tplBrick.properties || {});
11197
11224
  }
11198
11225
  }