@next-core/brick-kit 2.108.0 → 2.111.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,39 @@
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.111.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.110.0...@next-core/brick-kit@2.111.0) (2022-03-24)
7
+
8
+
9
+ ### Features
10
+
11
+ * support APP.getMenu ([#1651](https://github.com/easyops-cn/next-core/issues/1651)) ([5b9f53a](https://github.com/easyops-cn/next-core/commit/5b9f53a3367087a062f415dd68070f15b98bf966))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.110.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.109.0...@next-core/brick-kit@2.110.0) (2022-03-23)
18
+
19
+
20
+ ### Features
21
+
22
+ * support console in storyboard functions ([db24b0b](https://github.com/easyops-cn/next-core/commit/db24b0b1e6545a64974ab2ec1ffb1d8a2220d726))
23
+
24
+
25
+
26
+
27
+
28
+ # [2.109.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.108.0...@next-core/brick-kit@2.109.0) (2022-03-22)
29
+
30
+
31
+ ### Features
32
+
33
+ * React组件支持调用skd生成的provider ([aced8ff](https://github.com/easyops-cn/next-core/commit/aced8ffc0d05f5f700169ee06525c5a56e309fe3))
34
+
35
+
36
+
37
+
38
+
6
39
  # [2.108.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.107.4...@next-core/brick-kit@2.108.0) (2022-03-18)
7
40
 
8
41
 
@@ -1510,6 +1510,39 @@
1510
1510
  permissionMap.clear();
1511
1511
  }
1512
1512
 
1513
+ var THROW = () => {
1514
+ throw new Error("Can't modify read-only proxy object");
1515
+ };
1516
+
1517
+ var readOnlyHandler = {
1518
+ set: THROW,
1519
+ defineProperty: THROW,
1520
+ deleteProperty: THROW,
1521
+ setPrototypeOf: THROW
1522
+ };
1523
+ function getReadOnlyProxy(object) {
1524
+ return new Proxy(object, readOnlyHandler);
1525
+ } // First, we want to make accessing property of globals lazy,
1526
+ // So we use *Proxy* to make a dynamic accessor for each of these globals.
1527
+ // But we also want to keep them working in devtools.
1528
+
1529
+ function getDynamicReadOnlyProxy(_ref) {
1530
+ var {
1531
+ get,
1532
+ ownKeys
1533
+ } = _ref;
1534
+
1535
+ if (getDevHook()) {
1536
+ // In devtools, we extract them at beginning.
1537
+ var target = Object.fromEntries(ownKeys(null).map(key => [key, get(null, key, null)]));
1538
+ return getReadOnlyProxy(target);
1539
+ }
1540
+
1541
+ return new Proxy(Object.freeze({}), {
1542
+ get
1543
+ });
1544
+ }
1545
+
1513
1546
  // `GeneralGlobals` are globals which are page-state-agnostic,
1514
1547
  // thus they can be used both in storyboard expressions and functions.
1515
1548
  function getGeneralGlobals(attemptToVisitGlobals, options) {
@@ -1531,7 +1564,8 @@
1531
1564
  collectCoverage,
1532
1565
  widgetId,
1533
1566
  app,
1534
- storyboardFunctions
1567
+ storyboardFunctions,
1568
+ isStoryboardFunction
1535
1569
  } = _ref;
1536
1570
 
1537
1571
  switch (variableName) {
@@ -1559,6 +1593,9 @@
1559
1593
  return {
1560
1594
  getTheme: collectCoverage ? () => "light" : getTheme
1561
1595
  };
1596
+
1597
+ case "console":
1598
+ return isStoryboardFunction ? getReadOnlyProxy(console) : undefined;
1562
1599
  }
1563
1600
  }
1564
1601
 
@@ -1645,7 +1682,8 @@
1645
1682
  collectCoverage,
1646
1683
  widgetId,
1647
1684
  app: currentApp,
1648
- storyboardFunctions
1685
+ storyboardFunctions,
1686
+ isStoryboardFunction: true
1649
1687
  })),
1650
1688
  hooks: collector && {
1651
1689
  beforeEvaluate: collector.beforeEvaluate,
@@ -1699,39 +1737,6 @@
1699
1737
  registerStoryboardFunctions(functions);
1700
1738
  }
1701
1739
 
1702
- var THROW = () => {
1703
- throw new Error("Can't modify read-only proxy object");
1704
- };
1705
-
1706
- var readOnlyHandler = {
1707
- set: THROW,
1708
- defineProperty: THROW,
1709
- deleteProperty: THROW,
1710
- setPrototypeOf: THROW
1711
- };
1712
- function getReadOnlyProxy(object) {
1713
- return new Proxy(object, readOnlyHandler);
1714
- } // First, we want to make accessing property of globals lazy,
1715
- // So we use *Proxy* to make a dynamic accessor for each of these globals.
1716
- // But we also want to keep them working in devtools.
1717
-
1718
- function getDynamicReadOnlyProxy(_ref) {
1719
- var {
1720
- get,
1721
- ownKeys
1722
- } = _ref;
1723
-
1724
- if (getDevHook()) {
1725
- // In devtools, we extract them at beginning.
1726
- var target = Object.fromEntries(ownKeys(null).map(key => [key, get(null, key, null)]));
1727
- return getReadOnlyProxy(target);
1728
- }
1729
-
1730
- return new Proxy(Object.freeze({}), {
1731
- get
1732
- });
1733
- }
1734
-
1735
1740
  /*! (c) Andrea Giammarchi - ISC */
1736
1741
  var self = {};
1737
1742
 
@@ -2326,7 +2331,9 @@
2326
2331
  return hash ? hash.substr(1) : null;
2327
2332
 
2328
2333
  case "APP":
2329
- return lodash.cloneDeep(app);
2334
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, lodash.cloneDeep(app)), {}, {
2335
+ getMenu
2336
+ });
2330
2337
 
2331
2338
  case "CTX":
2332
2339
  return getDynamicReadOnlyProxy({
@@ -2683,7 +2690,19 @@
2683
2690
  return _constructMenu.apply(this, arguments);
2684
2691
  }
2685
2692
 
2686
- function fetchMenuById(_x4, _x5) {
2693
+ function constructMenuByMenusList(_x4, _x5, _x6) {
2694
+ return _constructMenuByMenusList.apply(this, arguments);
2695
+ }
2696
+
2697
+ function _constructMenuByMenusList() {
2698
+ _constructMenuByMenusList = _asyncToGenerator__default["default"](function* (menus, context, kernel) {
2699
+ yield Promise.all(menus.map(menuId => processMenu(menuId, context, kernel)));
2700
+ });
2701
+ return _constructMenuByMenusList.apply(this, arguments);
2702
+ }
2703
+
2704
+ var getMenu = menuId => menuCache.get(menuId);
2705
+ function fetchMenuById(_x7, _x8) {
2687
2706
  return _fetchMenuById.apply(this, arguments);
2688
2707
  }
2689
2708
 
@@ -2789,7 +2808,7 @@
2789
2808
  });
2790
2809
  }
2791
2810
 
2792
- function loadDynamicMenuItems(_x6) {
2811
+ function loadDynamicMenuItems(_x9) {
2793
2812
  return _loadDynamicMenuItems.apply(this, arguments);
2794
2813
  }
2795
2814
 
@@ -2807,7 +2826,7 @@
2807
2826
  return _loadDynamicMenuItems.apply(this, arguments);
2808
2827
  }
2809
2828
 
2810
- function processMenu(_x7, _x8, _x9, _x10) {
2829
+ function processMenu(_x10, _x11, _x12, _x13) {
2811
2830
  return _processMenu.apply(this, arguments);
2812
2831
  }
2813
2832
 
@@ -2866,13 +2885,13 @@
2866
2885
  });
2867
2886
  });
2868
2887
 
2869
- return function (_x11) {
2888
+ return function (_x14) {
2870
2889
  return _ref2.apply(this, arguments);
2871
2890
  };
2872
2891
  }()));
2873
2892
  }
2874
2893
 
2875
- function processMenuTitle(_x12) {
2894
+ function processMenuTitle(_x15) {
2876
2895
  return _processMenuTitle.apply(this, arguments);
2877
2896
  }
2878
2897
 
@@ -2967,7 +2986,7 @@
2967
2986
  return false;
2968
2987
  }
2969
2988
 
2970
- function computeRealValueWithOverrideApp(_x13, _x14, _x15, _x16) {
2989
+ function computeRealValueWithOverrideApp(_x16, _x17, _x18, _x19) {
2971
2990
  return _computeRealValueWithOverrideApp.apply(this, arguments);
2972
2991
  }
2973
2992
 
@@ -8739,6 +8758,12 @@
8739
8758
  if (isRouteConfOfRoutes(route) && Array.isArray(route.routes)) {
8740
8759
  yield _this.mountRoutes(route.routes, slotId, mountRoutesResult);
8741
8760
  } else if (isRouteConfOfBricks(route) && Array.isArray(route.bricks)) {
8761
+ var useMenus = brickUtils.scanAppGetMenuInAny(route);
8762
+
8763
+ if (useMenus.length) {
8764
+ yield constructMenuByMenusList(useMenus, _this.getCurrentContext(), _this.kernel);
8765
+ }
8766
+
8742
8767
  yield _this.mountBricks(route.bricks, matched.match, slotId, mountRoutesResult); // analytics data (page_view event)
8743
8768
 
8744
8769
  if (route.analyticsData) {
@@ -13194,7 +13219,7 @@
13194
13219
  });
13195
13220
  }, {});
13196
13221
 
13197
- var _excluded$1 = ["body"];
13222
+ var _excluded$1 = ["args"];
13198
13223
  function useProviderArgs(providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps, deps) {
13199
13224
  var provider = React.useMemo(() => {
13200
13225
  if (typeof providerOrParamsOrGlobalOptions === "string") {
@@ -13222,13 +13247,13 @@
13222
13247
  return acc;
13223
13248
  }, {}),
13224
13249
  {
13225
- body = null
13250
+ args = null
13226
13251
  } = _reduce,
13227
13252
  restOptions = _objectWithoutProperties__default["default"](_reduce, _excluded$1);
13228
13253
 
13229
13254
  return {
13230
13255
  options: _objectSpread__default["default"]({}, restOptions),
13231
- body
13256
+ args
13232
13257
  };
13233
13258
  }, [options]);
13234
13259
  var dependencies = React.useMemo(() => {
@@ -13255,29 +13280,72 @@
13255
13280
  };
13256
13281
  }
13257
13282
 
13258
- var cache = new Map();
13259
- function fetchProviderArgs(_x) {
13283
+ var cache$1 = new Map();
13284
+ function fetchProviderArgs(_x, _x2) {
13260
13285
  return _fetchProviderArgs.apply(this, arguments);
13261
13286
  }
13262
13287
 
13263
13288
  function _fetchProviderArgs() {
13264
- _fetchProviderArgs = _asyncToGenerator__default["default"](function* (provider) {
13265
- for (var _len = arguments.length, originalArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13266
- originalArgs[_key - 1] = arguments[_key];
13289
+ _fetchProviderArgs = _asyncToGenerator__default["default"](function* (provider, args) {
13290
+ for (var _len = arguments.length, originalArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
13291
+ originalArgs[_key - 2] = arguments[_key];
13267
13292
  }
13268
13293
 
13269
13294
  var cacheKey = JSON.stringify({
13270
13295
  provider,
13296
+ args,
13271
13297
  originalArgs
13272
13298
  });
13273
- if (cache.has(cacheKey)) return cache.get(cacheKey);
13274
- var args = yield getArgsOfCustomApi(provider, originalArgs);
13275
- cache.set(cacheKey, args);
13276
- return args;
13299
+ if (cache$1.has(cacheKey)) return cache$1.get(cacheKey);
13300
+ var actualArgs = yield getArgsOfCustomApi(provider, [...args, ...originalArgs]);
13301
+ cache$1.set(cacheKey, actualArgs);
13302
+ return actualArgs;
13277
13303
  });
13278
13304
  return _fetchProviderArgs.apply(this, arguments);
13279
13305
  }
13280
13306
 
13307
+ var cache = new Map();
13308
+ function fetch(_x) {
13309
+ return _fetch.apply(this, arguments);
13310
+ }
13311
+
13312
+ function _fetch() {
13313
+ _fetch = _asyncToGenerator__default["default"](function* (provider) {
13314
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13315
+ args[_key - 1] = arguments[_key];
13316
+ }
13317
+
13318
+ var cacheKey = JSON.stringify({
13319
+ provider,
13320
+ args
13321
+ });
13322
+ var promise;
13323
+
13324
+ if (cache.has(cacheKey)) {
13325
+ promise = cache.get(cacheKey);
13326
+ } else {
13327
+ promise = _asyncToGenerator__default["default"](function* () {
13328
+ if (!isCustomApiProvider(provider)) {
13329
+ var providerBrick = yield _internalApiGetProviderBrick(provider);
13330
+ var providerTagName = providerBrick.tagName.toLowerCase();
13331
+
13332
+ if (!customElements.get(providerTagName)) {
13333
+ throw new Error("Provider not defined: \"".concat(providerTagName, "\", please make sure the related package is installed."));
13334
+ }
13335
+
13336
+ return providerBrick["resolve"](...args);
13337
+ }
13338
+
13339
+ return CustomApi(...args);
13340
+ })();
13341
+ cache.set(cacheKey, promise);
13342
+ }
13343
+
13344
+ return promise;
13345
+ });
13346
+ return _fetch.apply(this, arguments);
13347
+ }
13348
+
13281
13349
  var _excluded = ["onError", "transform", "suspense"];
13282
13350
  function useProvider() {
13283
13351
  var {
@@ -13306,7 +13374,12 @@
13306
13374
  try {
13307
13375
  error.current = undefined;
13308
13376
  if (!suspense) setLoading(true);
13309
- var newRes = yield CustomApi(...arguments);
13377
+
13378
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13379
+ args[_key] = arguments[_key];
13380
+ }
13381
+
13382
+ var newRes = yield fetch(provider, ...args);
13310
13383
  response.current = newRes;
13311
13384
  data.current = transform(data.current, newRes);
13312
13385
  } catch (e) {
@@ -13318,25 +13391,25 @@
13318
13391
  return data.current;
13319
13392
  }), [provider, customOptions, dependencies, requestInit, suspense, transform, defaults.data, onError]);
13320
13393
  var makeFetch = React.useCallback( /*#__PURE__*/function () {
13321
- var _ref2 = _asyncToGenerator__default["default"](function* (providerOrBody, body) {
13394
+ var _ref2 = _asyncToGenerator__default["default"](function* (providerOrBody, args) {
13322
13395
  var providerStr = provider;
13323
- var data = {};
13396
+ var providerArgs = [];
13324
13397
 
13325
13398
  if (lodash.isString(providerOrBody)) {
13326
13399
  providerStr = providerOrBody;
13327
13400
  }
13328
13401
 
13329
13402
  if (lodash.isObject(providerOrBody)) {
13330
- data = providerOrBody;
13331
- } else if (lodash.isObject(body)) {
13332
- data = body;
13403
+ providerArgs = providerOrBody;
13404
+ } else if (lodash.isObject(args)) {
13405
+ providerArgs = args;
13333
13406
  }
13334
13407
 
13335
- var args = yield fetchProviderArgs(providerStr, data, requestInit.options);
13408
+ var actualArgs = yield fetchProviderArgs(providerStr, providerArgs, requestInit.options);
13336
13409
 
13337
13410
  if (suspense) {
13338
13411
  return _asyncToGenerator__default["default"](function* () {
13339
- suspender.current = doFetch(...args).then(newData => {
13412
+ suspender.current = doFetch(...actualArgs).then(newData => {
13340
13413
  suspenseStatus.current = "success";
13341
13414
  return newData;
13342
13415
  }, error => {
@@ -13349,7 +13422,7 @@
13349
13422
  })();
13350
13423
  }
13351
13424
 
13352
- return doFetch(...args);
13425
+ return doFetch(...actualArgs);
13353
13426
  });
13354
13427
 
13355
13428
  return function (_x, _x2) {
@@ -13383,7 +13456,7 @@
13383
13456
  mounted.current = true;
13384
13457
 
13385
13458
  if (Array.isArray(dependencies) && provider) {
13386
- request.query(provider, requestInit.body);
13459
+ request.query(provider, requestInit.args);
13387
13460
  }
13388
13461
 
13389
13462
  return () => mounted.current = false;