@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/dist/index.esm.js CHANGED
@@ -3,9 +3,9 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
4
  import _asyncToGenerator$4 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
6
- import React, { useState, useEffect, useRef, forwardRef, useImperativeHandle, useMemo, useContext, createContext } from 'react';
7
- import lodash, { set, get, difference, identity, uniqueId, cloneDeep, isNil, sortBy, merge, orderBy, omit, clamp, isEmpty, noop } from 'lodash';
8
- import { toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
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, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
8
+ import lodash, { set, get, difference, identity, uniqueId, cloneDeep, isNil, sortBy, merge, orderBy, omit, clamp, isEmpty, noop, isObject as isObject$1, isString } from 'lodash';
9
9
  import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
10
10
  import moment from 'moment';
11
11
  import { pipes } from '@next-core/pipes';
@@ -333,9 +333,10 @@ function registerBrickTemplate(name, factory) {
333
333
  brickTemplateRegistry.set(name, factory);
334
334
  }
335
335
 
336
- // Themes.
337
336
  var DEFAULT_THEME = "light";
338
337
  var theme = DEFAULT_THEME;
338
+ var storage = new JsonStorage(localStorage);
339
+ var LOCAL_STORAGE_APPS_THEME_KEY = "apps-theme";
339
340
  function setTheme(value) {
340
341
  if (value !== "dark" && value !== "light" && value !== "dark-v2") {
341
342
  throw new Error("Unsupported theme: ".concat(value));
@@ -376,6 +377,21 @@ function useCurrentTheme() {
376
377
  };
377
378
  }, []);
378
379
  return currentTheme;
380
+ }
381
+ function batchSetAppsLocalTheme(appsTheme) {
382
+ storage.setItem(LOCAL_STORAGE_APPS_THEME_KEY, _objectSpread(_objectSpread({}, getLocalAppsTheme()), appsTheme));
383
+ }
384
+ function getLocalAppsTheme() {
385
+ var result;
386
+
387
+ try {
388
+ result = storage.getItem(LOCAL_STORAGE_APPS_THEME_KEY);
389
+ } catch (_unused) {
390
+ // eslint-disable-next-line no-console
391
+ console.error("JSON parse error inside `getLocalAppsTheme()`");
392
+ }
393
+
394
+ return result || {};
379
395
  } // Modes.
380
396
 
381
397
  var DEFAULT_MODE = "default";
@@ -2632,7 +2648,7 @@ function getNextInternalOptions(internalOptions, isArray, key) {
2632
2648
  }) : internalOptions;
2633
2649
  }
2634
2650
 
2635
- var _excluded$4 = ["children"],
2651
+ var _excluded$6 = ["children"],
2636
2652
  _excluded2$1 = ["items", "app"];
2637
2653
  var symbolAppId = Symbol("appId");
2638
2654
  // Caching menu requests to avoid flicker.
@@ -2844,7 +2860,7 @@ function computeMenuItemsWithOverrideApp(items, context, kernel) {
2844
2860
  var {
2845
2861
  children
2846
2862
  } = _ref,
2847
- rest = _objectWithoutProperties(_ref, _excluded$4);
2863
+ rest = _objectWithoutProperties(_ref, _excluded$6);
2848
2864
 
2849
2865
  return _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(rest, rest[symbolAppId], context, kernel)), {}, {
2850
2866
  children: children && (yield computeMenuItemsWithOverrideApp(children, context, kernel))
@@ -3405,7 +3421,7 @@ function _internalApiLoadDynamicBricksInBrickConf(brickConf) {
3405
3421
  return kernel.loadDynamicBricksInBrickConf(brickConf);
3406
3422
  }
3407
3423
 
3408
- var _excluded$3 = ["extraQuery", "clear", "keepHash"];
3424
+ var _excluded$5 = ["extraQuery", "clear", "keepHash"];
3409
3425
  function historyExtended(browserHistory) {
3410
3426
  var {
3411
3427
  push: originalPush,
@@ -3421,7 +3437,7 @@ function historyExtended(browserHistory) {
3421
3437
  clear,
3422
3438
  keepHash
3423
3439
  } = options,
3424
- state = _objectWithoutProperties(options, _excluded$3);
3440
+ state = _objectWithoutProperties(options, _excluded$5);
3425
3441
 
3426
3442
  var urlSearchParams = new URLSearchParams(clear ? "" : browserHistory.location.search);
3427
3443
  var params = {};
@@ -6591,7 +6607,7 @@ function initAnalytics() {
6591
6607
  }
6592
6608
  }
6593
6609
 
6594
- var _excluded$2 = ["feature_flags"];
6610
+ var _excluded$4 = ["feature_flags"];
6595
6611
  function standaloneBootstrap() {
6596
6612
  return _standaloneBootstrap.apply(this, arguments);
6597
6613
  }
@@ -6627,7 +6643,7 @@ function _standaloneBootstrap() {
6627
6643
  var {
6628
6644
  feature_flags: featureFlags
6629
6645
  } = sys_settings,
6630
- rest = _objectWithoutProperties(sys_settings, _excluded$2);
6646
+ rest = _objectWithoutProperties(sys_settings, _excluded$4);
6631
6647
 
6632
6648
  settings = _objectSpread({
6633
6649
  featureFlags
@@ -9812,7 +9828,7 @@ class Router {
9812
9828
  var _this3 = this;
9813
9829
 
9814
9830
  return _asyncToGenerator$4(function* () {
9815
- var _apiAnalyzer$getInsta;
9831
+ var _apiAnalyzer$getInsta, _getLocalAppsTheme;
9816
9832
 
9817
9833
  _this3.state = "initial";
9818
9834
  _this3.renderId = uniqueId("render-id-");
@@ -9863,7 +9879,7 @@ class Router {
9863
9879
  var legacy = currentApp ? currentApp.legacy : undefined;
9864
9880
  _this3.kernel.nextApp = currentApp;
9865
9881
  var layoutType = (currentApp === null || currentApp === void 0 ? void 0 : currentApp.layoutType) || "console";
9866
- setTheme((currentApp === null || currentApp === void 0 ? void 0 : currentApp.theme) || "light");
9882
+ 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");
9867
9883
  setMode("default");
9868
9884
  devtoolsHookEmit("rendering");
9869
9885
  unmountTree(mountPoints.bg);
@@ -10319,7 +10335,7 @@ function collectMergeBases(conf, mergeBases, contextInTemplate, refToBrickConf)
10319
10335
  }
10320
10336
  }
10321
10337
 
10322
- var _excluded$1 = ["properties", "slots"],
10338
+ var _excluded$3 = ["properties", "slots"],
10323
10339
  _excluded2 = ["ref", "slots"];
10324
10340
  function expandCustomTemplate(brickConf, proxyBrick, context) {
10325
10341
  var tplContext = new CustomTemplateContext(proxyBrick);
@@ -10360,7 +10376,7 @@ function lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context,
10360
10376
  properties: templateProperties,
10361
10377
  slots: externalSlots
10362
10378
  } = brickConf,
10363
- restBrickConf = _objectWithoutProperties(brickConf, _excluded$1);
10379
+ restBrickConf = _objectWithoutProperties(brickConf, _excluded$3);
10364
10380
 
10365
10381
  var newBrickConf = restBrickConf; // Get a copy of proxy for each instance of custom template.
10366
10382
 
@@ -12796,7 +12812,7 @@ var developHelper = {
12796
12812
  checkoutTplContext: noop
12797
12813
  };
12798
12814
 
12799
- var _excluded = ["type"];
12815
+ var _excluded$2 = ["type"];
12800
12816
  // Inspired by [LitElement](https://github.com/Polymer/lit-element)
12801
12817
 
12802
12818
  /**
@@ -13066,7 +13082,7 @@ class UpdatingElement extends HTMLElement {
13066
13082
  var {
13067
13083
  type
13068
13084
  } = options,
13069
- eventInit = _objectWithoutProperties(options, _excluded);
13085
+ eventInit = _objectWithoutProperties(options, _excluded$2);
13070
13086
 
13071
13087
  this.__dev_only_definedEvents.add(type); // Make event emitter readonly.
13072
13088
 
@@ -13158,5 +13174,241 @@ var ModalElement = _decorate(null, function (_initialize, _UpdatingElement) {
13158
13174
  };
13159
13175
  }, UpdatingElement);
13160
13176
 
13161
- export { BrickAsComponent, BrickWrapper, DisplayByFeatureFlags, EasyopsEmpty, ErrorBoundary, FeatureFlagsProvider, ForwardRefSingleBrickAsComponent, ModalElement, SingleBrickAsComponent, StoryboardFunctionRegistryFactory, UpdatingElement, authenticate, checkIf, checkIfByTransform, createHistory, createRuntime, developHelper, doTransform, event, getAuth, getCssPropertyValue, 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, useRecentApps };
13177
+ var useProviderArgsDefaults = {
13178
+ provider: "",
13179
+ customOptions: {
13180
+ onError: () => {
13181
+ /* Do nothing.. */
13182
+ },
13183
+ transform: (oldData, newData) => newData,
13184
+ data: undefined,
13185
+ loading: false,
13186
+ suspense: false
13187
+ },
13188
+ dependencies: undefined
13189
+ };
13190
+ var defaults = Object.entries(useProviderArgsDefaults).reduce((acc, _ref) => {
13191
+ var [key, value] = _ref;
13192
+ if (Object.prototype.toString.call(value) === "[object Object]") return _objectSpread(_objectSpread({}, acc), value);
13193
+ return _objectSpread(_objectSpread({}, acc), {}, {
13194
+ [key]: value
13195
+ });
13196
+ }, {});
13197
+
13198
+ var _excluded$1 = ["body"];
13199
+ function useProviderArgs(providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps, deps) {
13200
+ var provider = useMemo(() => {
13201
+ if (typeof providerOrParamsOrGlobalOptions === "string") {
13202
+ return providerOrParamsOrGlobalOptions;
13203
+ }
13204
+
13205
+ return useProviderArgsDefaults.provider;
13206
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13207
+ var options = useMemo(() => {
13208
+ var localOptions = {};
13209
+
13210
+ if (isObject$1(providerOrParamsOrGlobalOptions)) {
13211
+ localOptions = providerOrParamsOrGlobalOptions;
13212
+ } else if (isObject$1(gloabalOptionsOrDeps)) {
13213
+ localOptions = gloabalOptionsOrDeps;
13214
+ }
13215
+
13216
+ return _objectSpread(_objectSpread({}, defaults), localOptions);
13217
+ }, [providerOrParamsOrGlobalOptions, gloabalOptionsOrDeps]);
13218
+ var requestInit = useMemo(() => {
13219
+ var customOptionKeys = [...Object.keys(useProviderArgsDefaults), ...Object.keys(useProviderArgsDefaults.customOptions)];
13220
+
13221
+ var _reduce = Object.keys(options).reduce((acc, key) => {
13222
+ if (!customOptionKeys.includes(key)) acc[key] = options[key];
13223
+ return acc;
13224
+ }, {}),
13225
+ {
13226
+ body = null
13227
+ } = _reduce,
13228
+ restOptions = _objectWithoutProperties(_reduce, _excluded$1);
13229
+
13230
+ return {
13231
+ options: _objectSpread({}, restOptions),
13232
+ body
13233
+ };
13234
+ }, [options]);
13235
+ var dependencies = useMemo(() => {
13236
+ if (Array.isArray(gloabalOptionsOrDeps)) return gloabalOptionsOrDeps;
13237
+ if (Array.isArray(deps)) return deps;
13238
+ return defaults.dependencies;
13239
+ }, [gloabalOptionsOrDeps, deps]);
13240
+ var loading = options.loading || Array.isArray(dependencies);
13241
+ var customOptions = useMemo(() => {
13242
+ var customOptionKeys = Object.keys(useProviderArgsDefaults.customOptions);
13243
+ var customOptions = customOptionKeys.reduce((opts, key) => {
13244
+ opts[key] = options[key];
13245
+ return opts;
13246
+ }, {});
13247
+ return _objectSpread(_objectSpread({}, customOptions), {}, {
13248
+ loading
13249
+ });
13250
+ }, [options]);
13251
+ return {
13252
+ provider,
13253
+ customOptions,
13254
+ requestInit,
13255
+ dependencies
13256
+ };
13257
+ }
13258
+
13259
+ var cache = new Map();
13260
+ function fetchProviderArgs(_x) {
13261
+ return _fetchProviderArgs.apply(this, arguments);
13262
+ }
13263
+
13264
+ function _fetchProviderArgs() {
13265
+ _fetchProviderArgs = _asyncToGenerator$4(function* (provider) {
13266
+ for (var _len = arguments.length, originalArgs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13267
+ originalArgs[_key - 1] = arguments[_key];
13268
+ }
13269
+
13270
+ var cacheKey = JSON.stringify({
13271
+ provider,
13272
+ originalArgs
13273
+ });
13274
+ if (cache.has(cacheKey)) return cache.get(cacheKey);
13275
+ var args = yield getArgsOfCustomApi(provider, originalArgs);
13276
+ cache.set(cacheKey, args);
13277
+ return args;
13278
+ });
13279
+ return _fetchProviderArgs.apply(this, arguments);
13280
+ }
13281
+
13282
+ var _excluded = ["onError", "transform", "suspense"];
13283
+ function useProvider() {
13284
+ var {
13285
+ provider,
13286
+ customOptions,
13287
+ dependencies,
13288
+ requestInit
13289
+ } = useProviderArgs(...arguments);
13290
+
13291
+ var {
13292
+ onError,
13293
+ transform,
13294
+ suspense
13295
+ } = customOptions,
13296
+ defaults = _objectWithoutProperties(customOptions, _excluded);
13297
+
13298
+ var [loading, setLoading] = useState(defaults.loading);
13299
+ var suspenseStatus = useRef("pending");
13300
+ var suspender = useRef();
13301
+ var mounted = useRef(false);
13302
+ var error = useRef();
13303
+ var response = useRef();
13304
+ var data = useRef(defaults.data);
13305
+ var forceUpdate = useReducer(() => ({}), [])[1];
13306
+ var doFetch = useCallback( /*#__PURE__*/_asyncToGenerator$4(function* () {
13307
+ try {
13308
+ error.current = undefined;
13309
+ if (!suspense) setLoading(true);
13310
+ var newRes = yield CustomApi(...arguments);
13311
+ response.current = newRes;
13312
+ data.current = transform(data.current, newRes);
13313
+ } catch (e) {
13314
+ error.current = e;
13315
+ }
13316
+
13317
+ if (!suspense) setLoading(false);
13318
+ if (error.current) onError(error.current);
13319
+ return data.current;
13320
+ }), [provider, customOptions, dependencies, requestInit, suspense, transform, defaults.data, onError]);
13321
+ var makeFetch = useCallback( /*#__PURE__*/function () {
13322
+ var _ref2 = _asyncToGenerator$4(function* (providerOrBody, body) {
13323
+ var providerStr = provider;
13324
+ var data = {};
13325
+
13326
+ if (isString(providerOrBody)) {
13327
+ providerStr = providerOrBody;
13328
+ }
13329
+
13330
+ if (isObject$1(providerOrBody)) {
13331
+ data = providerOrBody;
13332
+ } else if (isObject$1(body)) {
13333
+ data = body;
13334
+ }
13335
+
13336
+ var args = yield fetchProviderArgs(providerStr, data, requestInit.options);
13337
+
13338
+ if (suspense) {
13339
+ return _asyncToGenerator$4(function* () {
13340
+ suspender.current = doFetch(...args).then(newData => {
13341
+ suspenseStatus.current = "success";
13342
+ return newData;
13343
+ }, error => {
13344
+ suspenseStatus.current = "error";
13345
+ error.current = error;
13346
+ return error;
13347
+ });
13348
+ forceUpdate();
13349
+ return yield suspender.current;
13350
+ })();
13351
+ }
13352
+
13353
+ return doFetch(...args);
13354
+ });
13355
+
13356
+ return function (_x, _x2) {
13357
+ return _ref2.apply(this, arguments);
13358
+ };
13359
+ }(), [doFetch]);
13360
+ var request = useMemo(() => Object.defineProperties({
13361
+ query: makeFetch
13362
+ }, {
13363
+ loading: {
13364
+ get() {
13365
+ return loading;
13366
+ }
13367
+
13368
+ },
13369
+ data: {
13370
+ get() {
13371
+ return data.current;
13372
+ }
13373
+
13374
+ },
13375
+ error: {
13376
+ get() {
13377
+ return error.current;
13378
+ }
13379
+
13380
+ }
13381
+ }), [makeFetch]); // onMount/onUpdate
13382
+
13383
+ useEffect(() => {
13384
+ mounted.current = true;
13385
+
13386
+ if (Array.isArray(dependencies) && provider) {
13387
+ request.query(provider, requestInit.body);
13388
+ }
13389
+
13390
+ return () => mounted.current = false;
13391
+ }, dependencies);
13392
+
13393
+ if (suspense && suspender.current) {
13394
+ switch (suspenseStatus.current) {
13395
+ case "pending":
13396
+ throw suspender.current;
13397
+
13398
+ case "error":
13399
+ throw error.current;
13400
+ }
13401
+ }
13402
+
13403
+ return Object.assign([request, response.current, loading, error.current], _objectSpread(_objectSpread({
13404
+ request
13405
+ }, request), {}, {
13406
+ response: response.current,
13407
+ data: data.current,
13408
+ loading,
13409
+ error: error.current
13410
+ }));
13411
+ }
13412
+
13413
+ 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 };
13162
13414
  //# sourceMappingURL=index.esm.js.map