@next-core/brick-kit 2.107.4 → 2.110.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/index.bundle.js +335 -45
  3. package/dist/index.bundle.js.map +1 -1
  4. package/dist/index.esm.js +337 -48
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/types/core/StoryboardFunctionRegistryFactory.d.ts.map +1 -1
  7. package/dist/types/hooks/index.d.ts +2 -0
  8. package/dist/types/hooks/index.d.ts.map +1 -0
  9. package/dist/types/hooks/useProvider/fetch.d.ts +3 -0
  10. package/dist/types/hooks/useProvider/fetch.d.ts.map +1 -0
  11. package/dist/types/hooks/useProvider/fetchProviderArgs.d.ts +3 -0
  12. package/dist/types/hooks/useProvider/fetchProviderArgs.d.ts.map +1 -0
  13. package/dist/types/hooks/useProvider/useProvider.d.ts +3 -0
  14. package/dist/types/hooks/useProvider/useProvider.d.ts.map +1 -0
  15. package/dist/types/hooks/useProvider/useProvider.spec.d.ts +2 -0
  16. package/dist/types/hooks/useProvider/useProvider.spec.d.ts.map +1 -0
  17. package/dist/types/hooks/useProvider/useProviderArgs.d.ts +3 -0
  18. package/dist/types/hooks/useProvider/useProviderArgs.d.ts.map +1 -0
  19. package/dist/types/hooks/useProvider/useProviderArgsDefaults.d.ts +5 -0
  20. package/dist/types/hooks/useProvider/useProviderArgsDefaults.d.ts.map +1 -0
  21. package/dist/types/hooks/useProvider/useProviderTypes.d.ts +60 -0
  22. package/dist/types/hooks/useProvider/useProviderTypes.d.ts.map +1 -0
  23. package/dist/types/index.d.ts +1 -0
  24. package/dist/types/index.d.ts.map +1 -1
  25. package/dist/types/internal/getGeneralGlobals.d.ts +1 -0
  26. package/dist/types/internal/getGeneralGlobals.d.ts.map +1 -1
  27. package/package.json +3 -3
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.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)
7
+
8
+
9
+ ### Features
10
+
11
+ * support console in storyboard functions ([db24b0b](https://github.com/easyops-cn/next-core/commit/db24b0b1e6545a64974ab2ec1ffb1d8a2220d726))
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * React组件支持调用skd生成的provider ([aced8ff](https://github.com/easyops-cn/next-core/commit/aced8ffc0d05f5f700169ee06525c5a56e309fe3))
23
+
24
+
25
+
26
+
27
+
28
+ # [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)
29
+
30
+
31
+ ### Features
32
+
33
+ * React组件支持调用provider ([1fe6096](https://github.com/easyops-cn/next-core/commit/1fe60963f96b4cddd889837da3ae5dd19f472d46))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [2.107.4](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.107.3...@next-core/brick-kit@2.107.4) (2022-03-15)
7
40
 
8
41
  **Note:** Version bump only for package @next-core/brick-kit
@@ -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
 
@@ -2647,7 +2652,7 @@
2647
2652
  }) : internalOptions;
2648
2653
  }
2649
2654
 
2650
- var _excluded$4 = ["children"],
2655
+ var _excluded$6 = ["children"],
2651
2656
  _excluded2$1 = ["items", "app"];
2652
2657
  var symbolAppId = Symbol("appId");
2653
2658
  // Caching menu requests to avoid flicker.
@@ -2859,7 +2864,7 @@
2859
2864
  var {
2860
2865
  children
2861
2866
  } = _ref,
2862
- rest = _objectWithoutProperties__default["default"](_ref, _excluded$4);
2867
+ rest = _objectWithoutProperties__default["default"](_ref, _excluded$6);
2863
2868
 
2864
2869
  return _objectSpread__default["default"](_objectSpread__default["default"]({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
2865
2870
  children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
@@ -3420,7 +3425,7 @@
3420
3425
  return kernel.loadDynamicBricksInBrickConf(brickConf);
3421
3426
  }
3422
3427
 
3423
- var _excluded$3 = ["extraQuery", "clear", "keepHash"];
3428
+ var _excluded$5 = ["extraQuery", "clear", "keepHash"];
3424
3429
  function historyExtended(browserHistory) {
3425
3430
  var {
3426
3431
  push: originalPush,
@@ -3436,7 +3441,7 @@
3436
3441
  clear,
3437
3442
  keepHash
3438
3443
  } = options,
3439
- state = _objectWithoutProperties__default["default"](options, _excluded$3);
3444
+ state = _objectWithoutProperties__default["default"](options, _excluded$5);
3440
3445
 
3441
3446
  var urlSearchParams = new URLSearchParams(clear ? "" : browserHistory.location.search);
3442
3447
  var params = {};
@@ -6606,7 +6611,7 @@
6606
6611
  }
6607
6612
  }
6608
6613
 
6609
- var _excluded$2 = ["feature_flags"];
6614
+ var _excluded$4 = ["feature_flags"];
6610
6615
  function standaloneBootstrap() {
6611
6616
  return _standaloneBootstrap.apply(this, arguments);
6612
6617
  }
@@ -6642,7 +6647,7 @@
6642
6647
  var {
6643
6648
  feature_flags: featureFlags
6644
6649
  } = sys_settings,
6645
- rest = _objectWithoutProperties__default["default"](sys_settings, _excluded$2);
6650
+ rest = _objectWithoutProperties__default["default"](sys_settings, _excluded$4);
6646
6651
 
6647
6652
  settings = _objectSpread__default["default"]({
6648
6653
  featureFlags
@@ -10334,7 +10339,7 @@
10334
10339
  }
10335
10340
  }
10336
10341
 
10337
- var _excluded$1 = ["properties", "slots"],
10342
+ var _excluded$3 = ["properties", "slots"],
10338
10343
  _excluded2 = ["ref", "slots"];
10339
10344
  function expandCustomTemplate(brickConf, proxyBrick, context) {
10340
10345
  var tplContext = new CustomTemplateContext(proxyBrick);
@@ -10375,7 +10380,7 @@
10375
10380
  properties: templateProperties,
10376
10381
  slots: externalSlots
10377
10382
  } = brickConf,
10378
- restBrickConf = _objectWithoutProperties__default["default"](brickConf, _excluded$1);
10383
+ restBrickConf = _objectWithoutProperties__default["default"](brickConf, _excluded$3);
10379
10384
 
10380
10385
  var newBrickConf = restBrickConf; // Get a copy of proxy for each instance of custom template.
10381
10386
 
@@ -12811,7 +12816,7 @@
12811
12816
  checkoutTplContext: lodash.noop
12812
12817
  };
12813
12818
 
12814
- var _excluded = ["type"];
12819
+ var _excluded$2 = ["type"];
12815
12820
  // Inspired by [LitElement](https://github.com/Polymer/lit-element)
12816
12821
 
12817
12822
  /**
@@ -13081,7 +13086,7 @@
13081
13086
  var {
13082
13087
  type
13083
13088
  } = options,
13084
- eventInit = _objectWithoutProperties__default["default"](options, _excluded);
13089
+ eventInit = _objectWithoutProperties__default["default"](options, _excluded$2);
13085
13090
 
13086
13091
  this.__dev_only_definedEvents.add(type); // Make event emitter readonly.
13087
13092
 
@@ -13173,6 +13178,290 @@
13173
13178
  };
13174
13179
  }, UpdatingElement);
13175
13180
 
13181
+ var useProviderArgsDefaults = {
13182
+ provider: "",
13183
+ customOptions: {
13184
+ onError: () => {
13185
+ /* Do nothing.. */
13186
+ },
13187
+ transform: (oldData, newData) => newData,
13188
+ data: undefined,
13189
+ loading: false,
13190
+ suspense: false
13191
+ },
13192
+ dependencies: undefined
13193
+ };
13194
+ var defaults = Object.entries(useProviderArgsDefaults).reduce((acc, _ref) => {
13195
+ var [key, value] = _ref;
13196
+ if (Object.prototype.toString.call(value) === "[object Object]") return _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), value);
13197
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), {}, {
13198
+ [key]: value
13199
+ });
13200
+ }, {});
13201
+
13202
+ var _excluded$1 = ["args"];
13203
+ function useProviderArgs(providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps, deps) {
13204
+ var provider = React.useMemo(() => {
13205
+ if (typeof providerOrParamsOrGlobalOptions === "string") {
13206
+ return providerOrParamsOrGlobalOptions;
13207
+ }
13208
+
13209
+ return useProviderArgsDefaults.provider;
13210
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13211
+ var options = React.useMemo(() => {
13212
+ var localOptions = {};
13213
+
13214
+ if (lodash.isObject(providerOrParamsOrGlobalOptions)) {
13215
+ localOptions = providerOrParamsOrGlobalOptions;
13216
+ } else if (lodash.isObject(gloabalOptionsOrDeps)) {
13217
+ localOptions = gloabalOptionsOrDeps;
13218
+ }
13219
+
13220
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, defaults), localOptions);
13221
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13222
+ var requestInit = React.useMemo(() => {
13223
+ var customOptionKeys = [...Object.keys(useProviderArgsDefaults), ...Object.keys(useProviderArgsDefaults.customOptions)];
13224
+
13225
+ var _reduce = Object.keys(options).reduce((acc, key) => {
13226
+ if (!customOptionKeys.includes(key)) acc[key] = options[key];
13227
+ return acc;
13228
+ }, {}),
13229
+ {
13230
+ args = null
13231
+ } = _reduce,
13232
+ restOptions = _objectWithoutProperties__default["default"](_reduce, _excluded$1);
13233
+
13234
+ return {
13235
+ options: _objectSpread__default["default"]({}, restOptions),
13236
+ args
13237
+ };
13238
+ }, [options]);
13239
+ var dependencies = React.useMemo(() => {
13240
+ if (Array.isArray(gloabalOptionsOrDeps)) return gloabalOptionsOrDeps;
13241
+ if (Array.isArray(deps)) return deps;
13242
+ return defaults.dependencies;
13243
+ }, [gloabalOptionsOrDeps, deps]);
13244
+ var loading = options.loading || Array.isArray(dependencies);
13245
+ var customOptions = React.useMemo(() => {
13246
+ var customOptionKeys = Object.keys(useProviderArgsDefaults.customOptions);
13247
+ var customOptions = customOptionKeys.reduce((opts, key) => {
13248
+ opts[key] = options[key];
13249
+ return opts;
13250
+ }, {});
13251
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, customOptions), {}, {
13252
+ loading
13253
+ });
13254
+ }, [options]);
13255
+ return {
13256
+ provider,
13257
+ customOptions,
13258
+ requestInit,
13259
+ dependencies
13260
+ };
13261
+ }
13262
+
13263
+ var cache$1 = new Map();
13264
+ function fetchProviderArgs(_x, _x2) {
13265
+ return _fetchProviderArgs.apply(this, arguments);
13266
+ }
13267
+
13268
+ function _fetchProviderArgs() {
13269
+ _fetchProviderArgs = _asyncToGenerator__default["default"](function* (provider, args) {
13270
+ for (var _len = arguments.length, originalArgs = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
13271
+ originalArgs[_key - 2] = arguments[_key];
13272
+ }
13273
+
13274
+ var cacheKey = JSON.stringify({
13275
+ provider,
13276
+ args,
13277
+ originalArgs
13278
+ });
13279
+ if (cache$1.has(cacheKey)) return cache$1.get(cacheKey);
13280
+ var actualArgs = yield getArgsOfCustomApi(provider, [...args, ...originalArgs]);
13281
+ cache$1.set(cacheKey, actualArgs);
13282
+ return actualArgs;
13283
+ });
13284
+ return _fetchProviderArgs.apply(this, arguments);
13285
+ }
13286
+
13287
+ var cache = new Map();
13288
+ function fetch(_x) {
13289
+ return _fetch.apply(this, arguments);
13290
+ }
13291
+
13292
+ function _fetch() {
13293
+ _fetch = _asyncToGenerator__default["default"](function* (provider) {
13294
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13295
+ args[_key - 1] = arguments[_key];
13296
+ }
13297
+
13298
+ var cacheKey = JSON.stringify({
13299
+ provider,
13300
+ args
13301
+ });
13302
+ var promise;
13303
+
13304
+ if (cache.has(cacheKey)) {
13305
+ promise = cache.get(cacheKey);
13306
+ } else {
13307
+ promise = _asyncToGenerator__default["default"](function* () {
13308
+ if (!isCustomApiProvider(provider)) {
13309
+ var providerBrick = yield _internalApiGetProviderBrick(provider);
13310
+ var providerTagName = providerBrick.tagName.toLowerCase();
13311
+
13312
+ if (!customElements.get(providerTagName)) {
13313
+ throw new Error("Provider not defined: \"".concat(providerTagName, "\", please make sure the related package is installed."));
13314
+ }
13315
+
13316
+ return providerBrick["resolve"](...args);
13317
+ }
13318
+
13319
+ return CustomApi(...args);
13320
+ })();
13321
+ cache.set(cacheKey, promise);
13322
+ }
13323
+
13324
+ return promise;
13325
+ });
13326
+ return _fetch.apply(this, arguments);
13327
+ }
13328
+
13329
+ var _excluded = ["onError", "transform", "suspense"];
13330
+ function useProvider() {
13331
+ var {
13332
+ provider,
13333
+ customOptions,
13334
+ dependencies,
13335
+ requestInit
13336
+ } = useProviderArgs(...arguments);
13337
+
13338
+ var {
13339
+ onError,
13340
+ transform,
13341
+ suspense
13342
+ } = customOptions,
13343
+ defaults = _objectWithoutProperties__default["default"](customOptions, _excluded);
13344
+
13345
+ var [loading, setLoading] = React.useState(defaults.loading);
13346
+ var suspenseStatus = React.useRef("pending");
13347
+ var suspender = React.useRef();
13348
+ var mounted = React.useRef(false);
13349
+ var error = React.useRef();
13350
+ var response = React.useRef();
13351
+ var data = React.useRef(defaults.data);
13352
+ var forceUpdate = React.useReducer(() => ({}), [])[1];
13353
+ var doFetch = React.useCallback( /*#__PURE__*/_asyncToGenerator__default["default"](function* () {
13354
+ try {
13355
+ error.current = undefined;
13356
+ if (!suspense) setLoading(true);
13357
+
13358
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13359
+ args[_key] = arguments[_key];
13360
+ }
13361
+
13362
+ var newRes = yield fetch(provider, ...args);
13363
+ response.current = newRes;
13364
+ data.current = transform(data.current, newRes);
13365
+ } catch (e) {
13366
+ error.current = e;
13367
+ }
13368
+
13369
+ if (!suspense) setLoading(false);
13370
+ if (error.current) onError(error.current);
13371
+ return data.current;
13372
+ }), [provider, customOptions, dependencies, requestInit, suspense, transform, defaults.data, onError]);
13373
+ var makeFetch = React.useCallback( /*#__PURE__*/function () {
13374
+ var _ref2 = _asyncToGenerator__default["default"](function* (providerOrBody, args) {
13375
+ var providerStr = provider;
13376
+ var providerArgs = [];
13377
+
13378
+ if (lodash.isString(providerOrBody)) {
13379
+ providerStr = providerOrBody;
13380
+ }
13381
+
13382
+ if (lodash.isObject(providerOrBody)) {
13383
+ providerArgs = providerOrBody;
13384
+ } else if (lodash.isObject(args)) {
13385
+ providerArgs = args;
13386
+ }
13387
+
13388
+ var actualArgs = yield fetchProviderArgs(providerStr, providerArgs, requestInit.options);
13389
+
13390
+ if (suspense) {
13391
+ return _asyncToGenerator__default["default"](function* () {
13392
+ suspender.current = doFetch(...actualArgs).then(newData => {
13393
+ suspenseStatus.current = "success";
13394
+ return newData;
13395
+ }, error => {
13396
+ suspenseStatus.current = "error";
13397
+ error.current = error;
13398
+ return error;
13399
+ });
13400
+ forceUpdate();
13401
+ return yield suspender.current;
13402
+ })();
13403
+ }
13404
+
13405
+ return doFetch(...actualArgs);
13406
+ });
13407
+
13408
+ return function (_x, _x2) {
13409
+ return _ref2.apply(this, arguments);
13410
+ };
13411
+ }(), [doFetch]);
13412
+ var request = React.useMemo(() => Object.defineProperties({
13413
+ query: makeFetch
13414
+ }, {
13415
+ loading: {
13416
+ get() {
13417
+ return loading;
13418
+ }
13419
+
13420
+ },
13421
+ data: {
13422
+ get() {
13423
+ return data.current;
13424
+ }
13425
+
13426
+ },
13427
+ error: {
13428
+ get() {
13429
+ return error.current;
13430
+ }
13431
+
13432
+ }
13433
+ }), [makeFetch]); // onMount/onUpdate
13434
+
13435
+ React.useEffect(() => {
13436
+ mounted.current = true;
13437
+
13438
+ if (Array.isArray(dependencies) && provider) {
13439
+ request.query(provider, requestInit.args);
13440
+ }
13441
+
13442
+ return () => mounted.current = false;
13443
+ }, dependencies);
13444
+
13445
+ if (suspense && suspender.current) {
13446
+ switch (suspenseStatus.current) {
13447
+ case "pending":
13448
+ throw suspender.current;
13449
+
13450
+ case "error":
13451
+ throw error.current;
13452
+ }
13453
+ }
13454
+
13455
+ return Object.assign([request, response.current, loading, error.current], _objectSpread__default["default"](_objectSpread__default["default"]({
13456
+ request
13457
+ }, request), {}, {
13458
+ response: response.current,
13459
+ data: data.current,
13460
+ loading,
13461
+ error: error.current
13462
+ }));
13463
+ }
13464
+
13176
13465
  exports.BrickAsComponent = BrickAsComponent;
13177
13466
  exports.BrickWrapper = BrickWrapper;
13178
13467
  exports.DisplayByFeatureFlags = DisplayByFeatureFlags;
@@ -13222,6 +13511,7 @@
13222
13511
  exports.useCurrentTheme = useCurrentTheme;
13223
13512
  exports.useFeatureFlags = useFeatureFlags;
13224
13513
  exports.useLocation = useLocation;
13514
+ exports.useProvider = useProvider;
13225
13515
  exports.useRecentApps = useRecentApps;
13226
13516
 
13227
13517
  Object.defineProperty(exports, '__esModule', { value: true });