@next-core/brick-kit 2.107.2 → 2.108.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,36 @@
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.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
+
8
+
9
+ ### Features
10
+
11
+ * React组件支持调用provider ([1fe6096](https://github.com/easyops-cn/next-core/commit/1fe60963f96b4cddd889837da3ae5dd19f472d46))
12
+
13
+
14
+
15
+
16
+
17
+ ## [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)
18
+
19
+ **Note:** Version bump only for package @next-core/brick-kit
20
+
21
+
22
+
23
+
24
+
25
+ ## [2.107.3](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.107.2...@next-core/brick-kit@2.107.3) (2022-03-15)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * switch dark theme ([00ebb32](https://github.com/easyops-cn/next-core/commit/00ebb32101d86dcf05942746a25258cb9e84b699))
31
+
32
+
33
+
34
+
35
+
6
36
  ## [2.107.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.107.1...@next-core/brick-kit@2.107.2) (2022-03-07)
7
37
 
8
38
 
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('history'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/objectWithoutProperties'), require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/helpers/defineProperty'), require('react'), require('lodash'), require('@next-core/brick-utils'), require('@next-core/brick-http'), require('moment'), require('@next-core/pipes'), require('i18next'), require('@next-core/easyops-analytics'), require('antd'), require('@ant-design/icons'), require('js-yaml'), require('react-i18next'), require('@babel/runtime/helpers/esm/extends'), require('@next-core/illustrations'), require('@babel/runtime/helpers/decorate')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'history', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/objectWithoutProperties', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/helpers/defineProperty', 'react', 'lodash', '@next-core/brick-utils', '@next-core/brick-http', 'moment', '@next-core/pipes', 'i18next', '@next-core/easyops-analytics', 'antd', '@ant-design/icons', 'js-yaml', 'react-i18next', '@babel/runtime/helpers/esm/extends', '@next-core/illustrations', '@babel/runtime/helpers/decorate'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickKit = {}, global.history$1, global._objectSpread, global._objectWithoutProperties, global._asyncToGenerator$4, global._defineProperty$1, global.React, global.lodash, global.brickUtils, global.brickHttp, global.moment, global.pipes, global.i18next, global.easyopsAnalytics, global.antd, global.icons, global.yaml, global.reactI18next, global._extends, global.illustrations, global._decorate));
5
- })(this, (function (exports, history$1, _objectSpread, _objectWithoutProperties, _asyncToGenerator$4, _defineProperty$1, React, lodash, brickUtils, brickHttp, moment, pipes, i18next, easyopsAnalytics, antd, icons, yaml, reactI18next, _extends, illustrations, _decorate) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('history'), require('@babel/runtime/helpers/objectSpread2'), require('@babel/runtime/helpers/objectWithoutProperties'), require('@babel/runtime/helpers/asyncToGenerator'), require('@babel/runtime/helpers/defineProperty'), require('react'), require('@next-core/brick-utils'), require('lodash'), require('@next-core/brick-http'), require('moment'), require('@next-core/pipes'), require('i18next'), require('@next-core/easyops-analytics'), require('antd'), require('@ant-design/icons'), require('js-yaml'), require('react-i18next'), require('@babel/runtime/helpers/esm/extends'), require('@next-core/illustrations'), require('@babel/runtime/helpers/decorate')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'history', '@babel/runtime/helpers/objectSpread2', '@babel/runtime/helpers/objectWithoutProperties', '@babel/runtime/helpers/asyncToGenerator', '@babel/runtime/helpers/defineProperty', 'react', '@next-core/brick-utils', 'lodash', '@next-core/brick-http', 'moment', '@next-core/pipes', 'i18next', '@next-core/easyops-analytics', 'antd', '@ant-design/icons', 'js-yaml', 'react-i18next', '@babel/runtime/helpers/esm/extends', '@next-core/illustrations', '@babel/runtime/helpers/decorate'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BrickKit = {}, global.history$1, global._objectSpread, global._objectWithoutProperties, global._asyncToGenerator$4, global._defineProperty$1, global.React, global.brickUtils, global.lodash, global.brickHttp, global.moment, global.pipes, global.i18next, global.easyopsAnalytics, global.antd, global.icons, global.yaml, global.reactI18next, global._extends, global.illustrations, global._decorate));
5
+ })(this, (function (exports, history$1, _objectSpread, _objectWithoutProperties, _asyncToGenerator$4, _defineProperty$1, React, brickUtils, lodash, brickHttp, moment, pipes, i18next, easyopsAnalytics, antd, icons, yaml, reactI18next, _extends, illustrations, _decorate) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -332,9 +332,10 @@
332
332
  brickTemplateRegistry.set(name, factory);
333
333
  }
334
334
 
335
- // Themes.
336
335
  var DEFAULT_THEME = "light";
337
336
  var theme = DEFAULT_THEME;
337
+ var storage = new brickUtils.JsonStorage(localStorage);
338
+ var LOCAL_STORAGE_APPS_THEME_KEY = "apps-theme";
338
339
  function setTheme(value) {
339
340
  if (value !== "dark" && value !== "light" && value !== "dark-v2") {
340
341
  throw new Error("Unsupported theme: ".concat(value));
@@ -375,6 +376,21 @@
375
376
  };
376
377
  }, []);
377
378
  return currentTheme;
379
+ }
380
+ function batchSetAppsLocalTheme(appsTheme) {
381
+ storage.setItem(LOCAL_STORAGE_APPS_THEME_KEY, _objectSpread__default["default"](_objectSpread__default["default"]({}, getLocalAppsTheme()), appsTheme));
382
+ }
383
+ function getLocalAppsTheme() {
384
+ var result;
385
+
386
+ try {
387
+ result = storage.getItem(LOCAL_STORAGE_APPS_THEME_KEY);
388
+ } catch (_unused) {
389
+ // eslint-disable-next-line no-console
390
+ console.error("JSON parse error inside `getLocalAppsTheme()`");
391
+ }
392
+
393
+ return result || {};
378
394
  } // Modes.
379
395
 
380
396
  var DEFAULT_MODE = "default";
@@ -2631,7 +2647,7 @@
2631
2647
  }) : internalOptions;
2632
2648
  }
2633
2649
 
2634
- var _excluded$4 = ["children"],
2650
+ var _excluded$6 = ["children"],
2635
2651
  _excluded2$1 = ["items", "app"];
2636
2652
  var symbolAppId = Symbol("appId");
2637
2653
  // Caching menu requests to avoid flicker.
@@ -2843,7 +2859,7 @@
2843
2859
  var {
2844
2860
  children
2845
2861
  } = _ref,
2846
- rest = _objectWithoutProperties__default["default"](_ref, _excluded$4);
2862
+ rest = _objectWithoutProperties__default["default"](_ref, _excluded$6);
2847
2863
 
2848
2864
  return _objectSpread__default["default"](_objectSpread__default["default"]({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
2849
2865
  children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
@@ -3404,7 +3420,7 @@
3404
3420
  return kernel.loadDynamicBricksInBrickConf(brickConf);
3405
3421
  }
3406
3422
 
3407
- var _excluded$3 = ["extraQuery", "clear", "keepHash"];
3423
+ var _excluded$5 = ["extraQuery", "clear", "keepHash"];
3408
3424
  function historyExtended(browserHistory) {
3409
3425
  var {
3410
3426
  push: originalPush,
@@ -3420,7 +3436,7 @@
3420
3436
  clear,
3421
3437
  keepHash
3422
3438
  } = options,
3423
- state = _objectWithoutProperties__default["default"](options, _excluded$3);
3439
+ state = _objectWithoutProperties__default["default"](options, _excluded$5);
3424
3440
 
3425
3441
  var urlSearchParams = new URLSearchParams(clear ? "" : browserHistory.location.search);
3426
3442
  var params = {};
@@ -6590,7 +6606,7 @@
6590
6606
  }
6591
6607
  }
6592
6608
 
6593
- var _excluded$2 = ["feature_flags"];
6609
+ var _excluded$4 = ["feature_flags"];
6594
6610
  function standaloneBootstrap() {
6595
6611
  return _standaloneBootstrap.apply(this, arguments);
6596
6612
  }
@@ -6626,7 +6642,7 @@
6626
6642
  var {
6627
6643
  feature_flags: featureFlags
6628
6644
  } = sys_settings,
6629
- rest = _objectWithoutProperties__default["default"](sys_settings, _excluded$2);
6645
+ rest = _objectWithoutProperties__default["default"](sys_settings, _excluded$4);
6630
6646
 
6631
6647
  settings = _objectSpread__default["default"]({
6632
6648
  featureFlags
@@ -9811,7 +9827,7 @@
9811
9827
  var _this3 = this;
9812
9828
 
9813
9829
  return _asyncToGenerator__default["default"](function* () {
9814
- var _apiAnalyzer$getInsta;
9830
+ var _apiAnalyzer$getInsta, _getLocalAppsTheme;
9815
9831
 
9816
9832
  _this3.state = "initial";
9817
9833
  _this3.renderId = lodash.uniqueId("render-id-");
@@ -9862,7 +9878,7 @@
9862
9878
  var legacy = currentApp ? currentApp.legacy : undefined;
9863
9879
  _this3.kernel.nextApp = currentApp;
9864
9880
  var layoutType = (currentApp === null || currentApp === void 0 ? void 0 : currentApp.layoutType) || "console";
9865
- setTheme((currentApp === null || currentApp === void 0 ? void 0 : currentApp.theme) || "light");
9881
+ setTheme(((_getLocalAppsTheme = getLocalAppsTheme()) === null || _getLocalAppsTheme === void 0 ? void 0 : _getLocalAppsTheme[currentApp === null || currentApp === void 0 ? void 0 : currentApp.id]) || (currentApp === null || currentApp === void 0 ? void 0 : currentApp.theme) || "light");
9866
9882
  setMode("default");
9867
9883
  devtoolsHookEmit("rendering");
9868
9884
  unmountTree(mountPoints.bg);
@@ -10318,7 +10334,7 @@
10318
10334
  }
10319
10335
  }
10320
10336
 
10321
- var _excluded$1 = ["properties", "slots"],
10337
+ var _excluded$3 = ["properties", "slots"],
10322
10338
  _excluded2 = ["ref", "slots"];
10323
10339
  function expandCustomTemplate(brickConf, proxyBrick, context) {
10324
10340
  var tplContext = new CustomTemplateContext(proxyBrick);
@@ -10359,7 +10375,7 @@
10359
10375
  properties: templateProperties,
10360
10376
  slots: externalSlots
10361
10377
  } = brickConf,
10362
- restBrickConf = _objectWithoutProperties__default["default"](brickConf, _excluded$1);
10378
+ restBrickConf = _objectWithoutProperties__default["default"](brickConf, _excluded$3);
10363
10379
 
10364
10380
  var newBrickConf = restBrickConf; // Get a copy of proxy for each instance of custom template.
10365
10381
 
@@ -12795,7 +12811,7 @@
12795
12811
  checkoutTplContext: lodash.noop
12796
12812
  };
12797
12813
 
12798
- var _excluded = ["type"];
12814
+ var _excluded$2 = ["type"];
12799
12815
  // Inspired by [LitElement](https://github.com/Polymer/lit-element)
12800
12816
 
12801
12817
  /**
@@ -13065,7 +13081,7 @@
13065
13081
  var {
13066
13082
  type
13067
13083
  } = options,
13068
- eventInit = _objectWithoutProperties__default["default"](options, _excluded);
13084
+ eventInit = _objectWithoutProperties__default["default"](options, _excluded$2);
13069
13085
 
13070
13086
  this.__dev_only_definedEvents.add(type); // Make event emitter readonly.
13071
13087
 
@@ -13157,6 +13173,242 @@
13157
13173
  };
13158
13174
  }, UpdatingElement);
13159
13175
 
13176
+ var useProviderArgsDefaults = {
13177
+ provider: "",
13178
+ customOptions: {
13179
+ onError: () => {
13180
+ /* Do nothing.. */
13181
+ },
13182
+ transform: (oldData, newData) => newData,
13183
+ data: undefined,
13184
+ loading: false,
13185
+ suspense: false
13186
+ },
13187
+ dependencies: undefined
13188
+ };
13189
+ var defaults = Object.entries(useProviderArgsDefaults).reduce((acc, _ref) => {
13190
+ var [key, value] = _ref;
13191
+ if (Object.prototype.toString.call(value) === "[object Object]") return _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), value);
13192
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), {}, {
13193
+ [key]: value
13194
+ });
13195
+ }, {});
13196
+
13197
+ var _excluded$1 = ["body"];
13198
+ function useProviderArgs(providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps, deps) {
13199
+ var provider = React.useMemo(() => {
13200
+ if (typeof providerOrParamsOrGlobalOptions === "string") {
13201
+ return providerOrParamsOrGlobalOptions;
13202
+ }
13203
+
13204
+ return useProviderArgsDefaults.provider;
13205
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13206
+ var options = React.useMemo(() => {
13207
+ var localOptions = {};
13208
+
13209
+ if (lodash.isObject(providerOrParamsOrGlobalOptions)) {
13210
+ localOptions = providerOrParamsOrGlobalOptions;
13211
+ } else if (lodash.isObject(gloabalOptionsOrDeps)) {
13212
+ localOptions = gloabalOptionsOrDeps;
13213
+ }
13214
+
13215
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, defaults), localOptions);
13216
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13217
+ var requestInit = React.useMemo(() => {
13218
+ var customOptionKeys = [...Object.keys(useProviderArgsDefaults), ...Object.keys(useProviderArgsDefaults.customOptions)];
13219
+
13220
+ var _reduce = Object.keys(options).reduce((acc, key) => {
13221
+ if (!customOptionKeys.includes(key)) acc[key] = options[key];
13222
+ return acc;
13223
+ }, {}),
13224
+ {
13225
+ body = null
13226
+ } = _reduce,
13227
+ restOptions = _objectWithoutProperties__default["default"](_reduce, _excluded$1);
13228
+
13229
+ return {
13230
+ options: _objectSpread__default["default"]({}, restOptions),
13231
+ body
13232
+ };
13233
+ }, [options]);
13234
+ var dependencies = React.useMemo(() => {
13235
+ if (Array.isArray(gloabalOptionsOrDeps)) return gloabalOptionsOrDeps;
13236
+ if (Array.isArray(deps)) return deps;
13237
+ return defaults.dependencies;
13238
+ }, [gloabalOptionsOrDeps, deps]);
13239
+ var loading = options.loading || Array.isArray(dependencies);
13240
+ var customOptions = React.useMemo(() => {
13241
+ var customOptionKeys = Object.keys(useProviderArgsDefaults.customOptions);
13242
+ var customOptions = customOptionKeys.reduce((opts, key) => {
13243
+ opts[key] = options[key];
13244
+ return opts;
13245
+ }, {});
13246
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, customOptions), {}, {
13247
+ loading
13248
+ });
13249
+ }, [options]);
13250
+ return {
13251
+ provider,
13252
+ customOptions,
13253
+ requestInit,
13254
+ dependencies
13255
+ };
13256
+ }
13257
+
13258
+ var cache = new Map();
13259
+ function fetchProviderArgs(_x) {
13260
+ return _fetchProviderArgs.apply(this, arguments);
13261
+ }
13262
+
13263
+ 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];
13267
+ }
13268
+
13269
+ var cacheKey = JSON.stringify({
13270
+ provider,
13271
+ originalArgs
13272
+ });
13273
+ if (cache.has(cacheKey)) return cache.get(cacheKey);
13274
+ var args = yield getArgsOfCustomApi(provider, originalArgs);
13275
+ cache.set(cacheKey, args);
13276
+ return args;
13277
+ });
13278
+ return _fetchProviderArgs.apply(this, arguments);
13279
+ }
13280
+
13281
+ var _excluded = ["onError", "transform", "suspense"];
13282
+ function useProvider() {
13283
+ var {
13284
+ provider,
13285
+ customOptions,
13286
+ dependencies,
13287
+ requestInit
13288
+ } = useProviderArgs(...arguments);
13289
+
13290
+ var {
13291
+ onError,
13292
+ transform,
13293
+ suspense
13294
+ } = customOptions,
13295
+ defaults = _objectWithoutProperties__default["default"](customOptions, _excluded);
13296
+
13297
+ var [loading, setLoading] = React.useState(defaults.loading);
13298
+ var suspenseStatus = React.useRef("pending");
13299
+ var suspender = React.useRef();
13300
+ var mounted = React.useRef(false);
13301
+ var error = React.useRef();
13302
+ var response = React.useRef();
13303
+ var data = React.useRef(defaults.data);
13304
+ var forceUpdate = React.useReducer(() => ({}), [])[1];
13305
+ var doFetch = React.useCallback( /*#__PURE__*/_asyncToGenerator__default["default"](function* () {
13306
+ try {
13307
+ error.current = undefined;
13308
+ if (!suspense) setLoading(true);
13309
+ var newRes = yield CustomApi(...arguments);
13310
+ response.current = newRes;
13311
+ data.current = transform(data.current, newRes);
13312
+ } catch (e) {
13313
+ error.current = e;
13314
+ }
13315
+
13316
+ if (!suspense) setLoading(false);
13317
+ if (error.current) onError(error.current);
13318
+ return data.current;
13319
+ }), [provider, customOptions, dependencies, requestInit, suspense, transform, defaults.data, onError]);
13320
+ var makeFetch = React.useCallback( /*#__PURE__*/function () {
13321
+ var _ref2 = _asyncToGenerator__default["default"](function* (providerOrBody, body) {
13322
+ var providerStr = provider;
13323
+ var data = {};
13324
+
13325
+ if (lodash.isString(providerOrBody)) {
13326
+ providerStr = providerOrBody;
13327
+ }
13328
+
13329
+ if (lodash.isObject(providerOrBody)) {
13330
+ data = providerOrBody;
13331
+ } else if (lodash.isObject(body)) {
13332
+ data = body;
13333
+ }
13334
+
13335
+ var args = yield fetchProviderArgs(providerStr, data, requestInit.options);
13336
+
13337
+ if (suspense) {
13338
+ return _asyncToGenerator__default["default"](function* () {
13339
+ suspender.current = doFetch(...args).then(newData => {
13340
+ suspenseStatus.current = "success";
13341
+ return newData;
13342
+ }, error => {
13343
+ suspenseStatus.current = "error";
13344
+ error.current = error;
13345
+ return error;
13346
+ });
13347
+ forceUpdate();
13348
+ return yield suspender.current;
13349
+ })();
13350
+ }
13351
+
13352
+ return doFetch(...args);
13353
+ });
13354
+
13355
+ return function (_x, _x2) {
13356
+ return _ref2.apply(this, arguments);
13357
+ };
13358
+ }(), [doFetch]);
13359
+ var request = React.useMemo(() => Object.defineProperties({
13360
+ query: makeFetch
13361
+ }, {
13362
+ loading: {
13363
+ get() {
13364
+ return loading;
13365
+ }
13366
+
13367
+ },
13368
+ data: {
13369
+ get() {
13370
+ return data.current;
13371
+ }
13372
+
13373
+ },
13374
+ error: {
13375
+ get() {
13376
+ return error.current;
13377
+ }
13378
+
13379
+ }
13380
+ }), [makeFetch]); // onMount/onUpdate
13381
+
13382
+ React.useEffect(() => {
13383
+ mounted.current = true;
13384
+
13385
+ if (Array.isArray(dependencies) && provider) {
13386
+ request.query(provider, requestInit.body);
13387
+ }
13388
+
13389
+ return () => mounted.current = false;
13390
+ }, dependencies);
13391
+
13392
+ if (suspense && suspender.current) {
13393
+ switch (suspenseStatus.current) {
13394
+ case "pending":
13395
+ throw suspender.current;
13396
+
13397
+ case "error":
13398
+ throw error.current;
13399
+ }
13400
+ }
13401
+
13402
+ return Object.assign([request, response.current, loading, error.current], _objectSpread__default["default"](_objectSpread__default["default"]({
13403
+ request
13404
+ }, request), {}, {
13405
+ response: response.current,
13406
+ data: data.current,
13407
+ loading,
13408
+ error: error.current
13409
+ }));
13410
+ }
13411
+
13160
13412
  exports.BrickAsComponent = BrickAsComponent;
13161
13413
  exports.BrickWrapper = BrickWrapper;
13162
13414
  exports.DisplayByFeatureFlags = DisplayByFeatureFlags;
@@ -13169,6 +13421,7 @@
13169
13421
  exports.StoryboardFunctionRegistryFactory = StoryboardFunctionRegistryFactory;
13170
13422
  exports.UpdatingElement = UpdatingElement;
13171
13423
  exports.authenticate = authenticate;
13424
+ exports.batchSetAppsLocalTheme = batchSetAppsLocalTheme;
13172
13425
  exports.checkIf = checkIf;
13173
13426
  exports.checkIfByTransform = checkIfByTransform;
13174
13427
  exports.createHistory = createHistory;
@@ -13178,6 +13431,7 @@
13178
13431
  exports.event = event;
13179
13432
  exports.getAuth = getAuth;
13180
13433
  exports.getCssPropertyValue = getCssPropertyValue;
13434
+ exports.getCurrentTheme = getCurrentTheme;
13181
13435
  exports.getHistory = getHistory;
13182
13436
  exports.getMockInfo = getMockInfo;
13183
13437
  exports.getRuntime = getRuntime;
@@ -13204,6 +13458,7 @@
13204
13458
  exports.useCurrentTheme = useCurrentTheme;
13205
13459
  exports.useFeatureFlags = useFeatureFlags;
13206
13460
  exports.useLocation = useLocation;
13461
+ exports.useProvider = useProvider;
13207
13462
  exports.useRecentApps = useRecentApps;
13208
13463
 
13209
13464
  Object.defineProperty(exports, '__esModule', { value: true });