@next-core/brick-kit 2.130.0 → 2.132.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,45 @@
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.132.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.131.1...@next-core/brick-kit@2.132.0) (2022-08-25)
7
+
8
+
9
+ ### Features
10
+
11
+ * the next site in iframe and loading bar is triggered by outerside ([8bfc755](https://github.com/easyops-cn/next-core/commit/8bfc755ec0c73c8b2290a2b1d588e462c3c9d551))
12
+
13
+
14
+ ### Reverts
15
+
16
+ * Revert "feat(): support MISC variable" ([a03e603](https://github.com/easyops-cn/next-core/commit/a03e60340c77b68e2cb11d2d4963b20110d1a845))
17
+
18
+
19
+
20
+
21
+
22
+ ## [2.131.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.131.0...@next-core/brick-kit@2.131.1) (2022-08-25)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * preview error when legacy was iframe ([f79e45f](https://github.com/easyops-cn/next-core/commit/f79e45f5e09afa70a02912e6086f02947563312a))
28
+
29
+
30
+
31
+
32
+
33
+ # [2.131.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.130.0...@next-core/brick-kit@2.131.0) (2022-08-25)
34
+
35
+
36
+ ### Features
37
+
38
+ * context can track its deps now ([4993308](https://github.com/easyops-cn/next-core/commit/49933089e1ff6ec1ec5f01eeac5609dde07c1e2e))
39
+ * support lazy context ([39fdffb](https://github.com/easyops-cn/next-core/commit/39fdffb0500df36d5bb9447d63a448bd2b78df14))
40
+
41
+
42
+
43
+
44
+
6
45
  # [2.130.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.129.3...@next-core/brick-kit@2.130.0) (2022-08-23)
7
46
 
8
47
 
@@ -1564,44 +1564,6 @@
1564
1564
  });
1565
1565
  }
1566
1566
 
1567
- var misc;
1568
- function getRuntimeMisc() {
1569
- if (!misc) {
1570
- misc = {
1571
- isInIframe: false,
1572
- isInIframeOfSameSite: false,
1573
- isInIframeOfNext: false,
1574
- isInIframeOfVisualBuilder: false,
1575
- isInIframeOfLegacyConsole: false
1576
- };
1577
-
1578
- if (window !== window.parent) {
1579
- misc.isInIframe = true;
1580
-
1581
- try {
1582
- // Handle:
1583
- // - Previewing in visual builder by iframe.
1584
- // - Nesting next in next.
1585
- // - Nesting console in next.
1586
- if (window.origin === window.parent.origin) {
1587
- misc.isInIframeOfSameSite = true;
1588
- var selfIsNext = getBasePath() === "/next/";
1589
- var parentPathname = window.parent.location.pathname;
1590
- var parentIsNext = parentPathname.startsWith("/next/");
1591
- misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
1592
- misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
1593
- misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
1594
- }
1595
- } catch (e) {// do nothing
1596
- }
1597
- }
1598
-
1599
- Object.freeze(misc);
1600
- }
1601
-
1602
- return misc;
1603
- }
1604
-
1605
1567
  // `GeneralGlobals` are globals which are page-state-agnostic,
1606
1568
  // thus they can be used both in storyboard expressions and functions.
1607
1569
  function getGeneralGlobals(attemptToVisitGlobals, options) {
@@ -1654,9 +1616,6 @@
1654
1616
  getCssPropertyValue: collectCoverage ? () => "" : getCssPropertyValue
1655
1617
  };
1656
1618
 
1657
- case "RUNTIME_MISC":
1658
- return collectCoverage ? fakeRuntimeMisc() : getRuntimeMisc();
1659
-
1660
1619
  case "console":
1661
1620
  return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;
1662
1621
 
@@ -1692,16 +1651,6 @@
1692
1651
  return true;
1693
1652
  }
1694
1653
 
1695
- function fakeRuntimeMisc() {
1696
- return {
1697
- isInIframe: false,
1698
- isInIframeOfSameSite: false,
1699
- isInIframeOfNext: false,
1700
- isInIframeOfVisualBuilder: false,
1701
- isInIframeOfLegacyConsole: false
1702
- };
1703
- }
1704
-
1705
1654
  /** @internal */
1706
1655
 
1707
1656
  /** @internal */
@@ -2040,7 +1989,7 @@
2040
1989
  }
2041
1990
 
2042
1991
  updateValue(name, value, method) {
2043
- var _item$eventTarget;
1992
+ var _item$eventTarget2;
2044
1993
 
2045
1994
  if (!this.data.has(name)) {
2046
1995
  if (this.tplContextId) {
@@ -2064,6 +2013,22 @@
2064
2013
  return;
2065
2014
  }
2066
2015
 
2016
+ if (method === "refresh") {
2017
+ if (!item.refresh) {
2018
+ throw new Error("You can not refresh the storyboard context \"".concat(name, "\" which has no resolve."));
2019
+ }
2020
+
2021
+ item.refresh().then(val => {
2022
+ var _item$eventTarget;
2023
+
2024
+ item.value = val;
2025
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2026
+ detail: item.value
2027
+ }));
2028
+ }, handleHttpError);
2029
+ return;
2030
+ }
2031
+
2067
2032
  if (method === "replace") {
2068
2033
  item.value = value;
2069
2034
  } else {
@@ -2076,7 +2041,7 @@
2076
2041
  }
2077
2042
  }
2078
2043
 
2079
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2044
+ (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2080
2045
  detail: item.value
2081
2046
  }));
2082
2047
  }
@@ -2157,30 +2122,65 @@
2157
2122
  return false;
2158
2123
  }
2159
2124
 
2160
- var isResolve = false;
2161
- var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2125
+ var isTemplateState = !!storyboardContextWrapper.tplContextId;
2126
+ var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
2127
+ var refresh = null;
2128
+ var isLazyResolve = false;
2162
2129
 
2163
2130
  if (value === undefined) {
2164
2131
  if (contextConf.resolve) {
2165
2132
  if (looseCheckIf(contextConf.resolve, mergedContext)) {
2166
- isResolve = true;
2167
- var valueConf = {};
2168
- yield _internalApiGetResolver().resolveOne("reference", _objectSpread__default["default"]({
2169
- transform: "value",
2170
- transformMapArray: false
2171
- }, contextConf.resolve), valueConf, null, mergedContext);
2172
- value = valueConf.value;
2133
+ refresh = /*#__PURE__*/function () {
2134
+ var _ref = _asyncToGenerator__default["default"](function* () {
2135
+ var valueConf = {};
2136
+ yield _internalApiGetResolver().resolveOne("reference", _objectSpread__default["default"]({
2137
+ transform: "value",
2138
+ transformMapArray: false
2139
+ }, contextConf.resolve), valueConf, null, mergedContext);
2140
+ return valueConf.value;
2141
+ });
2142
+
2143
+ return function refresh() {
2144
+ return _ref.apply(this, arguments);
2145
+ };
2146
+ }();
2147
+
2148
+ isLazyResolve = contextConf.resolve.lazy;
2149
+
2150
+ if (!isLazyResolve) {
2151
+ value = yield refresh();
2152
+ }
2173
2153
  } else if (!brickUtils.hasOwnProperty(contextConf, "value")) {
2174
2154
  return false;
2175
2155
  }
2176
2156
  }
2177
2157
 
2178
- if (!isResolve && contextConf.value !== undefined) {
2158
+ if ((!refresh || isLazyResolve) && contextConf.value !== undefined) {
2159
+ // If the context has no resolve, just use its `value`.
2160
+ // Or if the resolve is ignored or lazy, use its `value` as a fallback.
2179
2161
  value = computeRealValue(contextConf.value, mergedContext, true);
2180
2162
  }
2163
+
2164
+ if (contextConf.track) {
2165
+ // Track its dependencies and auto update when each of them changed.
2166
+ var deps = (isTemplateState ? brickUtils.trackUsedState : brickUtils.trackUsedContext)(refresh ? contextConf.resolve : contextConf.value);
2167
+
2168
+ for (var dep of deps) {
2169
+ var _eventTarget;
2170
+
2171
+ var ctx = storyboardContextWrapper.get().get(dep);
2172
+ ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(isTemplateState ? "state.change" : "context.change", () => {
2173
+ if (refresh) {
2174
+ storyboardContextWrapper.updateValue(contextConf.name, undefined, "refresh");
2175
+ } else {
2176
+ storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
2177
+ }
2178
+ });
2179
+ }
2180
+ }
2181
2181
  }
2182
2182
 
2183
- resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2183
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh);
2184
2184
  return true;
2185
2185
  });
2186
2186
  return _resolveNormalStoryboardContext.apply(this, arguments);
@@ -2211,12 +2211,13 @@
2211
2211
  }
2212
2212
  }
2213
2213
 
2214
- function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
2214
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh) {
2215
2215
  var newContext = {
2216
2216
  type: "free-variable",
2217
2217
  value,
2218
2218
  // This is required for tracking context, even if no `onChange` is specified.
2219
- eventTarget: new EventTarget$1()
2219
+ eventTarget: new EventTarget$1(),
2220
+ refresh
2220
2221
  };
2221
2222
 
2222
2223
  if (contextConf.onChange) {
@@ -6287,10 +6288,12 @@
6287
6288
 
6288
6289
  case "context.assign":
6289
6290
  case "context.replace":
6291
+ case "context.refresh":
6290
6292
  return builtinContextListenerFactory(method, handler.args, handler, context);
6291
6293
 
6292
6294
  case "state.update":
6293
- return builtinStateListenerFactory(handler.args, handler, context);
6295
+ case "state.refresh":
6296
+ return builtinStateListenerFactory(method, handler.args, handler, context);
6294
6297
 
6295
6298
  case "tpl.dispatchEvent":
6296
6299
  return builtinTplDispatchEventFactory(handler.args, handler, context);
@@ -6434,7 +6437,7 @@
6434
6437
  };
6435
6438
  }
6436
6439
 
6437
- function builtinStateListenerFactory(args, ifContainer, context) {
6440
+ function builtinStateListenerFactory(method, args, ifContainer, context) {
6438
6441
  return function (event) {
6439
6442
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
6440
6443
  event
@@ -6444,7 +6447,7 @@
6444
6447
 
6445
6448
  var tplContext = getTplContext(context.tplContextId);
6446
6449
  var [name, value] = argsFactory(args, context, event);
6447
- tplContext.state.updateValue(name, value, "replace");
6450
+ tplContext.state.updateValue(name, value, method === "refresh" ? method : "replace");
6448
6451
  };
6449
6452
  }
6450
6453
 
@@ -8765,6 +8768,44 @@
8765
8768
  return ((_state$map = state === null || state === void 0 ? void 0 : state.map(item => item.name)) !== null && _state$map !== void 0 ? _state$map : []).concat(Object.keys((_proxy$properties = proxy === null || proxy === void 0 ? void 0 : proxy.properties) !== null && _proxy$properties !== void 0 ? _proxy$properties : {}));
8766
8769
  }
8767
8770
 
8771
+ var misc;
8772
+ function getRuntimeMisc() {
8773
+ if (!misc) {
8774
+ misc = {
8775
+ isInIframe: false,
8776
+ isInIframeOfSameSite: false,
8777
+ isInIframeOfNext: false,
8778
+ isInIframeOfVisualBuilder: false,
8779
+ isInIframeOfLegacyConsole: false
8780
+ };
8781
+
8782
+ if (window !== window.parent) {
8783
+ misc.isInIframe = true;
8784
+
8785
+ try {
8786
+ // Handle:
8787
+ // - Previewing in visual builder by iframe.
8788
+ // - Nesting next in next.
8789
+ // - Nesting console in next.
8790
+ if (window.origin === window.parent.origin) {
8791
+ misc.isInIframeOfSameSite = true;
8792
+ var selfIsNext = getBasePath() === "/next/";
8793
+ var parentPathname = window.parent.location.pathname;
8794
+ var parentIsNext = parentPathname.startsWith("/next/");
8795
+ misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
8796
+ misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
8797
+ misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
8798
+ }
8799
+ } catch (e) {// do nothing
8800
+ }
8801
+ }
8802
+
8803
+ Object.freeze(misc);
8804
+ }
8805
+
8806
+ return misc;
8807
+ }
8808
+
8768
8809
  class Kernel {
8769
8810
  constructor() {
8770
8811
  var _this = this;
@@ -8895,6 +8936,11 @@
8895
8936
 
8896
8937
  listenDevtoolsEagerly();
8897
8938
  _this2.mountPoints = mountPoints;
8939
+
8940
+ if (getRuntimeMisc().isInIframeOfSameSite && !getRuntimeMisc().isInIframeOfVisualBuilder) {
8941
+ document.body.classList.add("bars-hidden-in-iframe");
8942
+ }
8943
+
8898
8944
  yield Promise.all([_this2.loadCheckLogin(), _this2.loadMicroApps()]);
8899
8945
 
8900
8946
  if (_this2.bootstrapData.storyboards.length === 0) {
@@ -9176,7 +9222,8 @@
9176
9222
 
9177
9223
  _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
9178
9224
  var {
9179
- routes
9225
+ routes,
9226
+ app
9180
9227
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9181
9228
  var previewPath = "${APP.homepage}/_dev_only_/template-preview/".concat(templateId);
9182
9229
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9186,7 +9233,8 @@
9186
9233
  brick: templateId
9187
9234
  }, _.pick(settings, "properties", "events", "lifeCycle", "context"))],
9188
9235
  menu: false,
9189
- exact: true
9236
+ exact: true,
9237
+ hybrid: app.legacy === "iframe"
9190
9238
  };
9191
9239
 
9192
9240
  if (previewRouteIndex === -1) {
@@ -9200,7 +9248,8 @@
9200
9248
  var _snippetData$bricks;
9201
9249
 
9202
9250
  var {
9203
- routes
9251
+ routes,
9252
+ app
9204
9253
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9205
9254
  var previewPath = "${APP.homepage}/_dev_only_/snippet-preview/".concat(snippetData.snippetId);
9206
9255
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9210,7 +9259,8 @@
9210
9259
  brick: "span"
9211
9260
  }],
9212
9261
  menu: false,
9213
- exact: true
9262
+ exact: true,
9263
+ hybrid: app.legacy === "iframe"
9214
9264
  };
9215
9265
 
9216
9266
  if (previewRouteIndex === -1) {
@@ -10801,7 +10851,7 @@
10801
10851
  if (expandedBrickConf.exports) {
10802
10852
  for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
10803
10853
  if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
10804
- _this6.storyboardContextWrapper.set(ctxName.substr(4), {
10854
+ _this6.storyboardContextWrapper.set(ctxName.substring(4), {
10805
10855
  type: "brick-property",
10806
10856
  brick,
10807
10857
  prop
@@ -11380,19 +11430,33 @@
11380
11430
  }
11381
11431
  }
11382
11432
 
11383
- var cacheKey = JSON.stringify({
11384
- provider,
11385
- useProvider,
11386
- method,
11387
- args
11388
- });
11433
+ var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11434
+ : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11435
+ var cacheKey;
11436
+
11437
+ try {
11438
+ // `actualArgs` may contain circular references, which makes
11439
+ // JSON stringify failed, thus we fallback to original args.
11440
+ cacheKey = JSON.stringify({
11441
+ provider,
11442
+ useProvider,
11443
+ method,
11444
+ actualArgs
11445
+ });
11446
+ } catch (e) {
11447
+ cacheKey = JSON.stringify({
11448
+ provider,
11449
+ useProvider,
11450
+ method,
11451
+ args
11452
+ });
11453
+ }
11454
+
11389
11455
  var promise;
11390
11456
 
11391
11457
  if (_this2.cache.has(cacheKey)) {
11392
11458
  promise = _this2.cache.get(cacheKey);
11393
11459
  } else {
11394
- var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11395
- : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11396
11460
  promise = _asyncToGenerator__default["default"](function* () {
11397
11461
  if (useProvider) {
11398
11462
  actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
@@ -14729,6 +14793,7 @@
14729
14793
  exports.getHistory = getHistory;
14730
14794
  exports.getMockInfo = getMockInfo;
14731
14795
  exports.getRuntime = getRuntime;
14796
+ exports.getRuntimeMisc = getRuntimeMisc;
14732
14797
  exports.handleHttpError = handleHttpError;
14733
14798
  exports.httpErrorToString = httpErrorToString;
14734
14799
  exports.i18nText = i18nText;