@next-core/brick-kit 2.104.3 → 2.104.7

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/index.esm.js CHANGED
@@ -1904,12 +1904,12 @@ function _checkIf(rawIf, ctx, fn) {
1904
1904
  }
1905
1905
 
1906
1906
  class StoryboardContextWrapper {
1907
- constructor(isTemplateState) {
1907
+ constructor(tplContextId) {
1908
1908
  _defineProperty$1(this, "data", new Map());
1909
1909
 
1910
- _defineProperty$1(this, "isTemplateState", void 0);
1910
+ _defineProperty$1(this, "tplContextId", void 0);
1911
1911
 
1912
- this.isTemplateState = isTemplateState;
1912
+ this.tplContextId = tplContextId;
1913
1913
  }
1914
1914
 
1915
1915
  set(name, item) {
@@ -1937,7 +1937,7 @@ class StoryboardContextWrapper {
1937
1937
  var _item$eventTarget;
1938
1938
 
1939
1939
  if (!this.data.has(name)) {
1940
- if (this.isTemplateState) {
1940
+ if (this.tplContextId) {
1941
1941
  throw new Error("State not found: ".concat(name));
1942
1942
  } else {
1943
1943
  // eslint-disable-next-line no-console
@@ -1970,7 +1970,7 @@ class StoryboardContextWrapper {
1970
1970
  }
1971
1971
  }
1972
1972
 
1973
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.isTemplateState ? "state.change" : "context.change", {
1973
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
1974
1974
  detail: item.value
1975
1975
  }));
1976
1976
  }
@@ -1980,27 +1980,48 @@ class StoryboardContextWrapper {
1980
1980
 
1981
1981
  return _asyncToGenerator$4(function* () {
1982
1982
  if (Array.isArray(contextConfs)) {
1983
- yield resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(_this.isTemplateState, contextConf, coreContext, _this, brick));
1983
+ var {
1984
+ mergedContext,
1985
+ keyword
1986
+ } = _this.getResolveOptions(coreContext);
1987
+
1988
+ yield resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, mergedContext, _this, brick), keyword);
1984
1989
  }
1985
1990
  })();
1986
1991
  }
1987
1992
 
1988
1993
  syncDefine(contextConfs, coreContext, brick) {
1989
1994
  if (Array.isArray(contextConfs)) {
1990
- syncResolveContextConcurrently(contextConfs, contextConf => syncResolveStoryboardContext(contextConf, coreContext, this, brick));
1995
+ var {
1996
+ mergedContext,
1997
+ keyword
1998
+ } = this.getResolveOptions(coreContext);
1999
+ syncResolveContextConcurrently(contextConfs, contextConf => syncResolveStoryboardContext(contextConf, mergedContext, this, brick), keyword);
1991
2000
  }
1992
2001
  }
1993
2002
 
2003
+ getResolveOptions(coreContext) {
2004
+ return this.tplContextId ? {
2005
+ mergedContext: _objectSpread(_objectSpread({}, coreContext), {}, {
2006
+ tplContextId: this.tplContextId
2007
+ }),
2008
+ keyword: "STATE"
2009
+ } : {
2010
+ mergedContext: coreContext,
2011
+ keyword: "CTX"
2012
+ };
2013
+ }
2014
+
1994
2015
  }
1995
2016
 
1996
- function resolveStoryboardContext(_x, _x2, _x3, _x4, _x5) {
2017
+ function resolveStoryboardContext(_x, _x2, _x3, _x4) {
1997
2018
  return _resolveStoryboardContext.apply(this, arguments);
1998
2019
  }
1999
2020
 
2000
2021
  function _resolveStoryboardContext() {
2001
- _resolveStoryboardContext = _asyncToGenerator$4(function* (isTemplateState, contextConf, coreContext, storyboardContextWrapper, brick) {
2022
+ _resolveStoryboardContext = _asyncToGenerator$4(function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2002
2023
  if (contextConf.property) {
2003
- if (isTemplateState) {
2024
+ if (storyboardContextWrapper.tplContextId) {
2004
2025
  throw new Error("Setting `property` is not allowed in template scoped context");
2005
2026
  }
2006
2027
 
@@ -2020,28 +2041,28 @@ function _resolveStoryboardContext() {
2020
2041
  return _resolveStoryboardContext.apply(this, arguments);
2021
2042
  }
2022
2043
 
2023
- function resolveNormalStoryboardContext(_x6, _x7, _x8, _x9) {
2044
+ function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
2024
2045
  return _resolveNormalStoryboardContext.apply(this, arguments);
2025
2046
  }
2026
2047
 
2027
2048
  function _resolveNormalStoryboardContext() {
2028
- _resolveNormalStoryboardContext = _asyncToGenerator$4(function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2029
- if (!looseCheckIf(contextConf, coreContext)) {
2049
+ _resolveNormalStoryboardContext = _asyncToGenerator$4(function* (contextConf, mergedContext, storyboardContextWrapper, brick) {
2050
+ if (!looseCheckIf(contextConf, mergedContext)) {
2030
2051
  return false;
2031
2052
  }
2032
2053
 
2033
2054
  var isResolve = false;
2034
- var value = getDefinedTemplateState(contextConf, storyboardContextWrapper, brick);
2055
+ var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2035
2056
 
2036
2057
  if (value === undefined) {
2037
2058
  if (contextConf.resolve) {
2038
- if (looseCheckIf(contextConf.resolve, coreContext)) {
2059
+ if (looseCheckIf(contextConf.resolve, mergedContext)) {
2039
2060
  isResolve = true;
2040
2061
  var valueConf = {};
2041
2062
  yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
2042
2063
  transform: "value",
2043
2064
  transformMapArray: false
2044
- }, contextConf.resolve), valueConf, null, coreContext);
2065
+ }, contextConf.resolve), valueConf, null, mergedContext);
2045
2066
  value = valueConf.value;
2046
2067
  } else if (!hasOwnProperty(contextConf, "value")) {
2047
2068
  return false;
@@ -2049,18 +2070,18 @@ function _resolveNormalStoryboardContext() {
2049
2070
  }
2050
2071
 
2051
2072
  if (!isResolve && contextConf.value !== undefined) {
2052
- value = computeRealValue(contextConf.value, coreContext, true);
2073
+ value = computeRealValue(contextConf.value, mergedContext, true);
2053
2074
  }
2054
2075
  }
2055
2076
 
2056
- resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick);
2077
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2057
2078
  return true;
2058
2079
  });
2059
2080
  return _resolveNormalStoryboardContext.apply(this, arguments);
2060
2081
  }
2061
2082
 
2062
- function syncResolveStoryboardContext(contextConf, coreContext, storyboardContextWrapper, brick) {
2063
- if (!looseCheckIf(contextConf, coreContext)) {
2083
+ function syncResolveStoryboardContext(contextConf, mergedContext, storyboardContextWrapper, brick) {
2084
+ if (!looseCheckIf(contextConf, mergedContext)) {
2064
2085
  return false;
2065
2086
  }
2066
2087
 
@@ -2068,23 +2089,23 @@ function syncResolveStoryboardContext(contextConf, coreContext, storyboardContex
2068
2089
  throw new Error("resolve is not allowed here");
2069
2090
  }
2070
2091
 
2071
- var value = getDefinedTemplateState(contextConf, storyboardContextWrapper, brick);
2092
+ var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2072
2093
 
2073
2094
  if (value === undefined) {
2074
- value = computeRealValue(contextConf.value, coreContext, true);
2095
+ value = computeRealValue(contextConf.value, mergedContext, true);
2075
2096
  }
2076
2097
 
2077
- resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick);
2098
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2078
2099
  return true;
2079
2100
  }
2080
2101
 
2081
- function getDefinedTemplateState(contextConf, storyboardContextWrapper, brick) {
2082
- if (storyboardContextWrapper.isTemplateState && brick.properties && hasOwnProperty(brick.properties, contextConf.name)) {
2102
+ function getDefinedTemplateState(isTemplateState, contextConf, brick) {
2103
+ if (isTemplateState && brick.properties && hasOwnProperty(brick.properties, contextConf.name)) {
2083
2104
  return brick.properties[contextConf.name];
2084
2105
  }
2085
2106
  }
2086
2107
 
2087
- function resolveFreeVariableValue(value, contextConf, coreContext, storyboardContextWrapper, brick) {
2108
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
2088
2109
  var newContext = {
2089
2110
  type: "free-variable",
2090
2111
  value,
@@ -2094,7 +2115,7 @@ function resolveFreeVariableValue(value, contextConf, coreContext, storyboardCon
2094
2115
 
2095
2116
  if (contextConf.onChange) {
2096
2117
  for (var handler of [].concat(contextConf.onChange)) {
2097
- newContext.eventTarget.addEventListener(storyboardContextWrapper.isTemplateState ? "state.change" : "context.change", listenerFactory(handler, coreContext, brick));
2118
+ newContext.eventTarget.addEventListener(storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
2098
2119
  }
2099
2120
  }
2100
2121
 
@@ -2106,12 +2127,13 @@ class CustomTemplateContext {
2106
2127
  constructor(brick) {
2107
2128
  _defineProperty$1(this, "variables", void 0);
2108
2129
 
2109
- _defineProperty$1(this, "state", new StoryboardContextWrapper(true));
2130
+ _defineProperty$1(this, "state", void 0);
2110
2131
 
2111
2132
  _defineProperty$1(this, "id", uniqueId("tpl-ctx-"));
2112
2133
 
2113
2134
  this.brick = brick;
2114
2135
  tplContextMap.set(this.id, this);
2136
+ this.state = new StoryboardContextWrapper(this.id);
2115
2137
  brick.tplContextId = this.id;
2116
2138
  }
2117
2139
 
@@ -10123,7 +10145,9 @@ function propertyMergeAllOfArray(_ref, object) {
10123
10145
  // Use an approach like template-literal's quasis:
10124
10146
  // `quasi0${0}quais1${1}quasi2...`
10125
10147
  // Every quasi can be merged with multiple items.
10126
- var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true) : [];
10148
+ var computedBaseValue = Array.isArray(baseValue) ? computeRealValue(baseValue, context, true, {
10149
+ $$lazyForUseBrick: true
10150
+ }) : [];
10127
10151
  var quasis = [];
10128
10152
  var size = computedBaseValue.length + 1;
10129
10153
 
@@ -10513,7 +10537,7 @@ function getTagNameOfCustomTemplate(brick, appId) {
10513
10537
  return false;
10514
10538
  }
10515
10539
 
10516
- function handleProxyOfCustomTemplate(brick, reRun) {
10540
+ function handleProxyOfCustomTemplate(brick) {
10517
10541
  // Ignore non-tpl bricks.
10518
10542
  if (!brick.proxyRefs) {
10519
10543
  return;
@@ -10527,17 +10551,18 @@ function handleProxyOfCustomTemplate(brick, reRun) {
10527
10551
 
10528
10552
  return (_brick$proxyRefs$get$ = brick.proxyRefs.get(ref).brick) === null || _brick$proxyRefs$get$ === void 0 ? void 0 : _brick$proxyRefs$get$.element;
10529
10553
  }
10530
- } // For usages of `targetRef: "..."`.
10531
- // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10554
+ }
10532
10555
 
10556
+ var firstRun = !node.$$getElementByRef; // For usages of `targetRef: "..."`.
10557
+ // `tpl.$$getElementByRef(ref)` will return the ref element inside a custom template.
10533
10558
 
10534
- if (!reRun) {
10559
+ if (firstRun) {
10535
10560
  Object.defineProperty(node, "$$getElementByRef", {
10536
10561
  value: getElementByRef
10537
10562
  });
10538
10563
  }
10539
10564
 
10540
- if (!reRun && brick.stateNames) {
10565
+ if (firstRun && brick.stateNames) {
10541
10566
  (function () {
10542
10567
  // Define properties from state for tpl.
10543
10568
  var getState = () => getCustomTemplateContext(brick.tplContextId).state;
@@ -11197,7 +11222,7 @@ var handleProxyOfParentTemplate = (brick, tplContextId) => {
11197
11222
  handleProxyOfCustomTemplate(_objectSpread(_objectSpread({}, tplBrick), {}, {
11198
11223
  proxyRefs: singleRefBrickProxyMap,
11199
11224
  proxy: getFilterProxy(tplBrick.proxy, brick.ref)
11200
- }), true);
11225
+ }));
11201
11226
  setRealProperties(tplBrick.element, tplBrick.properties || {});
11202
11227
  }
11203
11228
  }