@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/dist/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
6
6
  import React, { useState, useEffect, useRef, forwardRef, useImperativeHandle, useMemo, useContext, createContext, useReducer, useCallback } from 'react';
7
- import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
7
+ import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
8
  import _, { set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, isEmpty, sortBy, merge, isObject as isObject$1, pick, orderBy, omit, findLastIndex, noop, isString } from 'lodash';
9
9
  import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
10
10
  import moment from 'moment';
@@ -1565,44 +1565,6 @@ function getDynamicReadOnlyProxy(_ref) {
1565
1565
  });
1566
1566
  }
1567
1567
 
1568
- var misc;
1569
- function getRuntimeMisc() {
1570
- if (!misc) {
1571
- misc = {
1572
- isInIframe: false,
1573
- isInIframeOfSameSite: false,
1574
- isInIframeOfNext: false,
1575
- isInIframeOfVisualBuilder: false,
1576
- isInIframeOfLegacyConsole: false
1577
- };
1578
-
1579
- if (window !== window.parent) {
1580
- misc.isInIframe = true;
1581
-
1582
- try {
1583
- // Handle:
1584
- // - Previewing in visual builder by iframe.
1585
- // - Nesting next in next.
1586
- // - Nesting console in next.
1587
- if (window.origin === window.parent.origin) {
1588
- misc.isInIframeOfSameSite = true;
1589
- var selfIsNext = getBasePath() === "/next/";
1590
- var parentPathname = window.parent.location.pathname;
1591
- var parentIsNext = parentPathname.startsWith("/next/");
1592
- misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
1593
- misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
1594
- misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
1595
- }
1596
- } catch (e) {// do nothing
1597
- }
1598
- }
1599
-
1600
- Object.freeze(misc);
1601
- }
1602
-
1603
- return misc;
1604
- }
1605
-
1606
1568
  // `GeneralGlobals` are globals which are page-state-agnostic,
1607
1569
  // thus they can be used both in storyboard expressions and functions.
1608
1570
  function getGeneralGlobals(attemptToVisitGlobals, options) {
@@ -1655,9 +1617,6 @@ function getIndividualGlobal(variableName, _ref) {
1655
1617
  getCssPropertyValue: collectCoverage ? () => "" : getCssPropertyValue
1656
1618
  };
1657
1619
 
1658
- case "RUNTIME_MISC":
1659
- return collectCoverage ? fakeRuntimeMisc() : getRuntimeMisc();
1660
-
1661
1620
  case "console":
1662
1621
  return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;
1663
1622
 
@@ -1693,16 +1652,6 @@ function fakeCheckPermissions() {
1693
1652
  return true;
1694
1653
  }
1695
1654
 
1696
- function fakeRuntimeMisc() {
1697
- return {
1698
- isInIframe: false,
1699
- isInIframeOfSameSite: false,
1700
- isInIframeOfNext: false,
1701
- isInIframeOfVisualBuilder: false,
1702
- isInIframeOfLegacyConsole: false
1703
- };
1704
- }
1705
-
1706
1655
  /** @internal */
1707
1656
 
1708
1657
  /** @internal */
@@ -2041,7 +1990,7 @@ class StoryboardContextWrapper {
2041
1990
  }
2042
1991
 
2043
1992
  updateValue(name, value, method) {
2044
- var _item$eventTarget;
1993
+ var _item$eventTarget2;
2045
1994
 
2046
1995
  if (!this.data.has(name)) {
2047
1996
  if (this.tplContextId) {
@@ -2065,6 +2014,22 @@ class StoryboardContextWrapper {
2065
2014
  return;
2066
2015
  }
2067
2016
 
2017
+ if (method === "refresh") {
2018
+ if (!item.refresh) {
2019
+ throw new Error("You can not refresh the storyboard context \"".concat(name, "\" which has no resolve."));
2020
+ }
2021
+
2022
+ item.refresh().then(val => {
2023
+ var _item$eventTarget;
2024
+
2025
+ item.value = val;
2026
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2027
+ detail: item.value
2028
+ }));
2029
+ }, handleHttpError);
2030
+ return;
2031
+ }
2032
+
2068
2033
  if (method === "replace") {
2069
2034
  item.value = value;
2070
2035
  } else {
@@ -2077,7 +2042,7 @@ class StoryboardContextWrapper {
2077
2042
  }
2078
2043
  }
2079
2044
 
2080
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2045
+ (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
2081
2046
  detail: item.value
2082
2047
  }));
2083
2048
  }
@@ -2158,30 +2123,65 @@ function _resolveNormalStoryboardContext() {
2158
2123
  return false;
2159
2124
  }
2160
2125
 
2161
- var isResolve = false;
2162
- var value = getDefinedTemplateState(!!storyboardContextWrapper.tplContextId, contextConf, brick);
2126
+ var isTemplateState = !!storyboardContextWrapper.tplContextId;
2127
+ var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
2128
+ var refresh = null;
2129
+ var isLazyResolve = false;
2163
2130
 
2164
2131
  if (value === undefined) {
2165
2132
  if (contextConf.resolve) {
2166
2133
  if (looseCheckIf(contextConf.resolve, mergedContext)) {
2167
- isResolve = true;
2168
- var valueConf = {};
2169
- yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
2170
- transform: "value",
2171
- transformMapArray: false
2172
- }, contextConf.resolve), valueConf, null, mergedContext);
2173
- value = valueConf.value;
2134
+ refresh = /*#__PURE__*/function () {
2135
+ var _ref = _asyncToGenerator$3(function* () {
2136
+ var valueConf = {};
2137
+ yield _internalApiGetResolver().resolveOne("reference", _objectSpread({
2138
+ transform: "value",
2139
+ transformMapArray: false
2140
+ }, contextConf.resolve), valueConf, null, mergedContext);
2141
+ return valueConf.value;
2142
+ });
2143
+
2144
+ return function refresh() {
2145
+ return _ref.apply(this, arguments);
2146
+ };
2147
+ }();
2148
+
2149
+ isLazyResolve = contextConf.resolve.lazy;
2150
+
2151
+ if (!isLazyResolve) {
2152
+ value = yield refresh();
2153
+ }
2174
2154
  } else if (!hasOwnProperty(contextConf, "value")) {
2175
2155
  return false;
2176
2156
  }
2177
2157
  }
2178
2158
 
2179
- if (!isResolve && contextConf.value !== undefined) {
2159
+ if ((!refresh || isLazyResolve) && contextConf.value !== undefined) {
2160
+ // If the context has no resolve, just use its `value`.
2161
+ // Or if the resolve is ignored or lazy, use its `value` as a fallback.
2180
2162
  value = computeRealValue(contextConf.value, mergedContext, true);
2181
2163
  }
2164
+
2165
+ if (contextConf.track) {
2166
+ // Track its dependencies and auto update when each of them changed.
2167
+ var deps = (isTemplateState ? trackUsedState : trackUsedContext)(refresh ? contextConf.resolve : contextConf.value);
2168
+
2169
+ for (var dep of deps) {
2170
+ var _eventTarget;
2171
+
2172
+ var ctx = storyboardContextWrapper.get().get(dep);
2173
+ ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(isTemplateState ? "state.change" : "context.change", () => {
2174
+ if (refresh) {
2175
+ storyboardContextWrapper.updateValue(contextConf.name, undefined, "refresh");
2176
+ } else {
2177
+ storyboardContextWrapper.updateValue(contextConf.name, computeRealValue(contextConf.value, mergedContext, true), "replace");
2178
+ }
2179
+ });
2180
+ }
2181
+ }
2182
2182
  }
2183
2183
 
2184
- resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick);
2184
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh);
2185
2185
  return true;
2186
2186
  });
2187
2187
  return _resolveNormalStoryboardContext.apply(this, arguments);
@@ -2212,12 +2212,13 @@ function getDefinedTemplateState(isTemplateState, contextConf, brick) {
2212
2212
  }
2213
2213
  }
2214
2214
 
2215
- function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick) {
2215
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, refresh) {
2216
2216
  var newContext = {
2217
2217
  type: "free-variable",
2218
2218
  value,
2219
2219
  // This is required for tracking context, even if no `onChange` is specified.
2220
- eventTarget: new EventTarget$1()
2220
+ eventTarget: new EventTarget$1(),
2221
+ refresh
2221
2222
  };
2222
2223
 
2223
2224
  if (contextConf.onChange) {
@@ -6288,10 +6289,12 @@ function listenerFactory(handler, context, runtimeBrick) {
6288
6289
 
6289
6290
  case "context.assign":
6290
6291
  case "context.replace":
6292
+ case "context.refresh":
6291
6293
  return builtinContextListenerFactory(method, handler.args, handler, context);
6292
6294
 
6293
6295
  case "state.update":
6294
- return builtinStateListenerFactory(handler.args, handler, context);
6296
+ case "state.refresh":
6297
+ return builtinStateListenerFactory(method, handler.args, handler, context);
6295
6298
 
6296
6299
  case "tpl.dispatchEvent":
6297
6300
  return builtinTplDispatchEventFactory(handler.args, handler, context);
@@ -6435,7 +6438,7 @@ function builtinContextListenerFactory(method, args, ifContainer, context) {
6435
6438
  };
6436
6439
  }
6437
6440
 
6438
- function builtinStateListenerFactory(args, ifContainer, context) {
6441
+ function builtinStateListenerFactory(method, args, ifContainer, context) {
6439
6442
  return function (event) {
6440
6443
  if (!looseCheckIf(ifContainer, _objectSpread(_objectSpread({}, context), {}, {
6441
6444
  event
@@ -6445,7 +6448,7 @@ function builtinStateListenerFactory(args, ifContainer, context) {
6445
6448
 
6446
6449
  var tplContext = getTplContext(context.tplContextId);
6447
6450
  var [name, value] = argsFactory(args, context, event);
6448
- tplContext.state.updateValue(name, value, "replace");
6451
+ tplContext.state.updateValue(name, value, method === "refresh" ? method : "replace");
6449
6452
  };
6450
6453
  }
6451
6454
 
@@ -8766,6 +8769,44 @@ function getPropsOfCustomTemplate(tagName) {
8766
8769
  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 : {}));
8767
8770
  }
8768
8771
 
8772
+ var misc;
8773
+ function getRuntimeMisc() {
8774
+ if (!misc) {
8775
+ misc = {
8776
+ isInIframe: false,
8777
+ isInIframeOfSameSite: false,
8778
+ isInIframeOfNext: false,
8779
+ isInIframeOfVisualBuilder: false,
8780
+ isInIframeOfLegacyConsole: false
8781
+ };
8782
+
8783
+ if (window !== window.parent) {
8784
+ misc.isInIframe = true;
8785
+
8786
+ try {
8787
+ // Handle:
8788
+ // - Previewing in visual builder by iframe.
8789
+ // - Nesting next in next.
8790
+ // - Nesting console in next.
8791
+ if (window.origin === window.parent.origin) {
8792
+ misc.isInIframeOfSameSite = true;
8793
+ var selfIsNext = getBasePath() === "/next/";
8794
+ var parentPathname = window.parent.location.pathname;
8795
+ var parentIsNext = parentPathname.startsWith("/next/");
8796
+ misc.isInIframeOfNext = (Number(selfIsNext) ^ Number(parentIsNext)) === 0;
8797
+ misc.isInIframeOfVisualBuilder = parentPathname.startsWith("".concat(parentIsNext ? "/next" : "", "/visual-builder/"));
8798
+ misc.isInIframeOfLegacyConsole = selfIsNext && !parentIsNext;
8799
+ }
8800
+ } catch (e) {// do nothing
8801
+ }
8802
+ }
8803
+
8804
+ Object.freeze(misc);
8805
+ }
8806
+
8807
+ return misc;
8808
+ }
8809
+
8769
8810
  class Kernel {
8770
8811
  constructor() {
8771
8812
  var _this = this;
@@ -8896,6 +8937,11 @@ class Kernel {
8896
8937
 
8897
8938
  listenDevtoolsEagerly();
8898
8939
  _this2.mountPoints = mountPoints;
8940
+
8941
+ if (getRuntimeMisc().isInIframeOfSameSite && !getRuntimeMisc().isInIframeOfVisualBuilder) {
8942
+ document.body.classList.add("bars-hidden-in-iframe");
8943
+ }
8944
+
8899
8945
  yield Promise.all([_this2.loadCheckLogin(), _this2.loadMicroApps()]);
8900
8946
 
8901
8947
  if (_this2.bootstrapData.storyboards.length === 0) {
@@ -9177,7 +9223,8 @@ class Kernel {
9177
9223
 
9178
9224
  _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
9179
9225
  var {
9180
- routes
9226
+ routes,
9227
+ app
9181
9228
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9182
9229
  var previewPath = "${APP.homepage}/_dev_only_/template-preview/".concat(templateId);
9183
9230
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9187,7 +9234,8 @@ class Kernel {
9187
9234
  brick: templateId
9188
9235
  }, pick(settings, "properties", "events", "lifeCycle", "context"))],
9189
9236
  menu: false,
9190
- exact: true
9237
+ exact: true,
9238
+ hybrid: app.legacy === "iframe"
9191
9239
  };
9192
9240
 
9193
9241
  if (previewRouteIndex === -1) {
@@ -9201,7 +9249,8 @@ class Kernel {
9201
9249
  var _snippetData$bricks;
9202
9250
 
9203
9251
  var {
9204
- routes
9252
+ routes,
9253
+ app
9205
9254
  } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
9206
9255
  var previewPath = "${APP.homepage}/_dev_only_/snippet-preview/".concat(snippetData.snippetId);
9207
9256
  var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
@@ -9211,7 +9260,8 @@ class Kernel {
9211
9260
  brick: "span"
9212
9261
  }],
9213
9262
  menu: false,
9214
- exact: true
9263
+ exact: true,
9264
+ hybrid: app.legacy === "iframe"
9215
9265
  };
9216
9266
 
9217
9267
  if (previewRouteIndex === -1) {
@@ -10802,7 +10852,7 @@ class LocationContext {
10802
10852
  if (expandedBrickConf.exports) {
10803
10853
  for (var [prop, ctxName] of Object.entries(expandedBrickConf.exports)) {
10804
10854
  if (typeof ctxName === "string" && ctxName.startsWith("CTX.")) {
10805
- _this6.storyboardContextWrapper.set(ctxName.substr(4), {
10855
+ _this6.storyboardContextWrapper.set(ctxName.substring(4), {
10806
10856
  type: "brick-property",
10807
10857
  brick,
10808
10858
  prop
@@ -11381,19 +11431,33 @@ class Resolver {
11381
11431
  }
11382
11432
  }
11383
11433
 
11384
- var cacheKey = JSON.stringify({
11385
- provider,
11386
- useProvider,
11387
- method,
11388
- args
11389
- });
11434
+ var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11435
+ : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11436
+ var cacheKey;
11437
+
11438
+ try {
11439
+ // `actualArgs` may contain circular references, which makes
11440
+ // JSON stringify failed, thus we fallback to original args.
11441
+ cacheKey = JSON.stringify({
11442
+ provider,
11443
+ useProvider,
11444
+ method,
11445
+ actualArgs
11446
+ });
11447
+ } catch (e) {
11448
+ cacheKey = JSON.stringify({
11449
+ provider,
11450
+ useProvider,
11451
+ method,
11452
+ args
11453
+ });
11454
+ }
11455
+
11390
11456
  var promise;
11391
11457
 
11392
11458
  if (_this2.cache.has(cacheKey)) {
11393
11459
  promise = _this2.cache.get(cacheKey);
11394
11460
  } else {
11395
- var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
11396
- : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
11397
11461
  promise = _asyncToGenerator$3(function* () {
11398
11462
  if (useProvider) {
11399
11463
  actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
@@ -14704,5 +14768,5 @@ function useProvider() {
14704
14768
  }));
14705
14769
  }
14706
14770
 
14707
- export { BrickAsComponent, BrickWrapper, DisplayByFeatureFlags, EasyopsEmpty, ErrorBoundary, FeatureFlagsProvider, ForwardRefSingleBrickAsComponent, ModalElement, SingleBrickAsComponent, StoryboardFunctionRegistryFactory, UpdatingElement, authenticate, batchSetAppsLocalTheme, checkIf, checkIfByTransform, createHistory, createRuntime, developHelper, doTransform, event, getAuth, getCssPropertyValue, getCurrentTheme, getHistory, getMockInfo, getRuntime, handleHttpError, httpErrorToString, i18nText, initI18n, isLoggedIn, logout, looseCheckIf, looseCheckIfByTransform, looseCheckIfOfComputed, method, preprocessTransformProperties, property, reTransformForDevtools, renderEasyopsEmpty, transformElementProperties, transformIntermediateData, transformProperties, useApplyPageTitle, useCurrentApp, useCurrentMode, useCurrentTheme, useFeatureFlags, useLocation, useProvider, useRecentApps };
14771
+ export { BrickAsComponent, BrickWrapper, DisplayByFeatureFlags, EasyopsEmpty, ErrorBoundary, FeatureFlagsProvider, ForwardRefSingleBrickAsComponent, ModalElement, SingleBrickAsComponent, StoryboardFunctionRegistryFactory, UpdatingElement, authenticate, batchSetAppsLocalTheme, checkIf, checkIfByTransform, createHistory, createRuntime, developHelper, doTransform, event, getAuth, getCssPropertyValue, getCurrentTheme, getHistory, getMockInfo, getRuntime, getRuntimeMisc, handleHttpError, httpErrorToString, i18nText, initI18n, isLoggedIn, logout, looseCheckIf, looseCheckIfByTransform, looseCheckIfOfComputed, method, preprocessTransformProperties, property, reTransformForDevtools, renderEasyopsEmpty, transformElementProperties, transformIntermediateData, transformProperties, useApplyPageTitle, useCurrentApp, useCurrentMode, useCurrentTheme, useFeatureFlags, useLocation, useProvider, useRecentApps };
14708
14772
  //# sourceMappingURL=index.esm.js.map