@next-core/brick-kit 2.104.0 → 2.104.4

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,7 +1980,7 @@ 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
+ yield resolveContextConcurrently(contextConfs, contextConf => resolveStoryboardContext(contextConf, coreContext, _this, brick));
1984
1984
  }
1985
1985
  })();
1986
1986
  }
@@ -1993,14 +1993,14 @@ class StoryboardContextWrapper {
1993
1993
 
1994
1994
  }
1995
1995
 
1996
- function resolveStoryboardContext(_x, _x2, _x3, _x4, _x5) {
1996
+ function resolveStoryboardContext(_x, _x2, _x3, _x4) {
1997
1997
  return _resolveStoryboardContext.apply(this, arguments);
1998
1998
  }
1999
1999
 
2000
2000
  function _resolveStoryboardContext() {
2001
- _resolveStoryboardContext = _asyncToGenerator$4(function* (isTemplateState, contextConf, coreContext, storyboardContextWrapper, brick) {
2001
+ _resolveStoryboardContext = _asyncToGenerator$4(function* (contextConf, coreContext, storyboardContextWrapper, brick) {
2002
2002
  if (contextConf.property) {
2003
- if (isTemplateState) {
2003
+ if (storyboardContextWrapper.tplContextId) {
2004
2004
  throw new Error("Setting `property` is not allowed in template scoped context");
2005
2005
  }
2006
2006
 
@@ -2020,7 +2020,7 @@ function _resolveStoryboardContext() {
2020
2020
  return _resolveStoryboardContext.apply(this, arguments);
2021
2021
  }
2022
2022
 
2023
- function resolveNormalStoryboardContext(_x6, _x7, _x8, _x9) {
2023
+ function resolveNormalStoryboardContext(_x5, _x6, _x7, _x8) {
2024
2024
  return _resolveNormalStoryboardContext.apply(this, arguments);
2025
2025
  }
2026
2026
 
@@ -2079,7 +2079,7 @@ function syncResolveStoryboardContext(contextConf, coreContext, storyboardContex
2079
2079
  }
2080
2080
 
2081
2081
  function getDefinedTemplateState(contextConf, storyboardContextWrapper, brick) {
2082
- if (storyboardContextWrapper.isTemplateState && brick.properties && hasOwnProperty(brick.properties, contextConf.name)) {
2082
+ if (storyboardContextWrapper.tplContextId && brick.properties && hasOwnProperty(brick.properties, contextConf.name)) {
2083
2083
  return brick.properties[contextConf.name];
2084
2084
  }
2085
2085
  }
@@ -2094,7 +2094,13 @@ function resolveFreeVariableValue(value, contextConf, coreContext, storyboardCon
2094
2094
 
2095
2095
  if (contextConf.onChange) {
2096
2096
  for (var handler of [].concat(contextConf.onChange)) {
2097
- newContext.eventTarget.addEventListener("context.change", listenerFactory(handler, coreContext, brick));
2097
+ if (storyboardContextWrapper.tplContextId) {
2098
+ newContext.eventTarget.addEventListener("state.change", listenerFactory(handler, _objectSpread(_objectSpread({}, coreContext), {}, {
2099
+ tplContextId: storyboardContextWrapper.tplContextId
2100
+ }), brick));
2101
+ } else {
2102
+ newContext.eventTarget.addEventListener("context.change", listenerFactory(handler, coreContext, brick));
2103
+ }
2098
2104
  }
2099
2105
  }
2100
2106
 
@@ -2106,12 +2112,13 @@ class CustomTemplateContext {
2106
2112
  constructor(brick) {
2107
2113
  _defineProperty$1(this, "variables", void 0);
2108
2114
 
2109
- _defineProperty$1(this, "state", new StoryboardContextWrapper(true));
2115
+ _defineProperty$1(this, "state", void 0);
2110
2116
 
2111
2117
  _defineProperty$1(this, "id", uniqueId("tpl-ctx-"));
2112
2118
 
2113
2119
  this.brick = brick;
2114
2120
  tplContextMap.set(this.id, this);
2121
+ this.state = new StoryboardContextWrapper(this.id);
2115
2122
  brick.tplContextId = this.id;
2116
2123
  }
2117
2124
 
@@ -2435,6 +2442,49 @@ function evaluate(raw) {
2435
2442
  }
2436
2443
  }
2437
2444
 
2445
+ var customTemplateRegistry = new Map();
2446
+ var appRegistered = new Set();
2447
+ var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
2448
+ var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
2449
+ var symbolForTplContextId = Symbol.for("tpl.contextId");
2450
+
2451
+ function setupUseBrickInTemplate(props, tplContextId) {
2452
+ function walk(props) {
2453
+ if (!props) {
2454
+ return;
2455
+ }
2456
+
2457
+ for (var [key, value] of Object.entries(props)) {
2458
+ if (isObject(value)) {
2459
+ if (key === "useBrick") {
2460
+ if (Array.isArray(value)) {
2461
+ value.forEach(setup);
2462
+ } else {
2463
+ setup(value);
2464
+ }
2465
+ } else {
2466
+ walk(value);
2467
+ }
2468
+ }
2469
+ }
2470
+ }
2471
+
2472
+ function setup(item) {
2473
+ item[symbolForTplContextId] = tplContextId;
2474
+ walk(item.properties);
2475
+
2476
+ if (item.slots) {
2477
+ Object.values(item.slots).forEach(slot => {
2478
+ if (Array.isArray(slot.bricks)) {
2479
+ slot.bricks.forEach(setup);
2480
+ }
2481
+ });
2482
+ }
2483
+ }
2484
+
2485
+ walk(props);
2486
+ }
2487
+
2438
2488
  var computeRealValue = (value, context, injectDeep, internalOptions) => {
2439
2489
  var preEvaluated = isPreEvaluated(value);
2440
2490
 
@@ -2488,6 +2538,10 @@ var computeRealValue = (value, context, injectDeep, internalOptions) => {
2488
2538
  function setProperties(bricks, properties, context, injectDeep) {
2489
2539
  var realProps = computeRealProperties(properties, context, injectDeep);
2490
2540
 
2541
+ if (context.tplContextId) {
2542
+ setupUseBrickInTemplate(realProps, context.tplContextId);
2543
+ }
2544
+
2491
2545
  if (!Array.isArray(bricks)) {
2492
2546
  bricks = [bricks];
2493
2547
  }
@@ -9046,6 +9100,11 @@ class LocationContext {
9046
9100
  getCurrentMatch() {
9047
9101
  return this.currentMatch;
9048
9102
  }
9103
+ /** @deprecated */
9104
+
9105
+
9106
+ getTplContext() {// Keep it for compatibility only.
9107
+ }
9049
9108
 
9050
9109
  dispatchLifeCycleEvent(event, handlers) {
9051
9110
  for (var brickAndHandler of handlers) {
@@ -9997,12 +10056,6 @@ class Router {
9997
10056
 
9998
10057
  }
9999
10058
 
10000
- var customTemplateRegistry = new Map();
10001
- var appRegistered = new Set();
10002
- var symbolForComputedPropsFromProxy = Symbol.for("tpl.computedPropsFromProxy");
10003
- var symbolForRefForProxy = Symbol.for("tpl.refForProxy");
10004
- var symbolForTplContextId = Symbol.for("tpl.contextId");
10005
-
10006
10059
  function isBasicProperty(propRef) {
10007
10060
  return !!propRef.refProperty;
10008
10061
  }
@@ -10177,43 +10230,6 @@ function collectMergeBases(conf, mergeBases, contextInTemplate, refToBrickConf)
10177
10230
  }
10178
10231
  }
10179
10232
 
10180
- function setupUseBrickInTemplate(props, tplContextId) {
10181
- function walk(props) {
10182
- if (!props) {
10183
- return;
10184
- }
10185
-
10186
- for (var [key, value] of Object.entries(props)) {
10187
- if (isObject(value)) {
10188
- if (key === "useBrick") {
10189
- if (Array.isArray(value)) {
10190
- value.forEach(setup);
10191
- } else {
10192
- setup(value);
10193
- }
10194
- } else {
10195
- walk(value);
10196
- }
10197
- }
10198
- }
10199
- }
10200
-
10201
- function setup(item) {
10202
- item[symbolForTplContextId] = tplContextId;
10203
- walk(item.properties);
10204
-
10205
- if (item.slots) {
10206
- Object.values(item.slots).forEach(slot => {
10207
- if (Array.isArray(slot.bricks)) {
10208
- slot.bricks.forEach(setup);
10209
- }
10210
- });
10211
- }
10212
- }
10213
-
10214
- walk(props);
10215
- }
10216
-
10217
10233
  var _excluded$1 = ["properties", "slots"],
10218
10234
  _excluded2 = ["ref", "slots"];
10219
10235
  function expandCustomTemplate(brickConf, proxyBrick, context) {