@next-core/brick-kit 2.178.4 → 2.178.5

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 _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
5
5
  import _asyncToGenerator$3 from '@babel/runtime/helpers/asyncToGenerator';
6
6
  import _, { set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, isEmpty, merge, sortBy, orderBy, isObject as isObject$1, uniq, pick, omit, findLastIndex, noop, isString as isString$1 } from 'lodash';
7
- import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, isTrackAll, trackAll, trackContext, trackState, trackFormState, transformAndInject, transform, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedFormState, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, scanPermissionActionsInAny, deepFreeze, scanProcessorsInAny, matchPath, asyncProcessBrick, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, snippetEvaluate, scanCustomApisInStoryboard, prefetchScript, scanBricksInBrickConf, loadScript as loadScript$1, scanAppGetMenuInAny, scanInstalledAppsInStoryboard, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
7
+ import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, isTrackAll, trackAll, trackContext, trackState, trackFormState, transformAndInject, transform, scanPermissionActionsInStoryboard, precookFunction, cook, collectContextUsage, deferResolveContextConcurrently, resolveContextConcurrently, syncResolveContextConcurrently, trackUsedFormState, trackUsedState, trackUsedContext, shouldAllowRecursiveEvaluations, preevaluate, inject, scanPermissionActionsInAny, deepFreeze, scanProcessorsInAny, matchPath, asyncProcessBrick, createProviderClass, removeDeadConditionsInTpl, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, snippetEvaluate, scanCustomApisInStoryboard, prefetchScript, scanBricksInBrickConf, loadScript, scanAppGetMenuInAny, scanInstalledAppsInStoryboard, removeDeadConditions, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
8
  import React, { useState, useEffect, useMemo, useContext, createContext, useRef, useReducer, useCallback } from 'react';
9
9
  import { http, HttpResponseError, HttpAbortError, HttpFetchError } from '@next-core/brick-http';
10
10
  import { Modal, message, Empty, ConfigProvider } from 'antd';
@@ -14,6 +14,7 @@ import moment from 'moment';
14
14
  import { pipes } from '@next-core/pipes';
15
15
  import { userAnalytics, apiAnalyzer } from '@next-core/easyops-analytics';
16
16
  import yaml from 'js-yaml';
17
+ import { loadBricksImperatively, loadProcessorsImperatively } from '@next-core/loader';
17
18
  import { withTranslation } from 'react-i18next';
18
19
  import _extends from '@babel/runtime/helpers/esm/extends';
19
20
  import { getIllustration } from '@next-core/illustrations';
@@ -6884,267 +6885,6 @@ var UserAdminApi_searchAllUsersInfo = /*#__PURE__*/function () {
6884
6885
  };
6885
6886
  }();
6886
6887
 
6887
- var cache$1 = new Map();
6888
- function loadScript(src, prefix) {
6889
- if (Array.isArray(src)) {
6890
- return Promise.all(src.map(item => loadScript(item, prefix)));
6891
- }
6892
- var fixedSrc = prefix ? "".concat(prefix).concat(src) : src;
6893
- var cachedPromise = cache$1.get(fixedSrc);
6894
- if (cachedPromise) {
6895
- return cachedPromise;
6896
- }
6897
- var promise = new Promise((resolve, reject) => {
6898
- var end = () => {
6899
- window.dispatchEvent(new Event("request.end"));
6900
- };
6901
- var script = document.createElement("script");
6902
- script.src = fixedSrc;
6903
- script.type = "text/javascript";
6904
- script.async = true;
6905
- script.onload = () => {
6906
- resolve(fixedSrc);
6907
- end();
6908
- };
6909
- script.onerror = e => {
6910
- reject(e);
6911
- end();
6912
- };
6913
- var firstScript = document.currentScript || document.getElementsByTagName("script")[0];
6914
- firstScript.parentNode.insertBefore(script, firstScript);
6915
- window.dispatchEvent(new Event("request.start"));
6916
- });
6917
- cache$1.set(fixedSrc, promise);
6918
- return promise;
6919
- }
6920
-
6921
- // https://github.com/module-federation/module-federation-examples/blob/eda9493f3991a423479fd834cfb1d7b241d9d1f0/advanced-api/dynamic-remotes/app1/src/App.js
6922
- function loadSharedModule(_x, _x2) {
6923
- return _loadSharedModule.apply(this, arguments);
6924
- }
6925
- function _loadSharedModule() {
6926
- _loadSharedModule = _asyncToGenerator$3(function* (scope, module) {
6927
- // Initializes the share scope. This fills it with known provided modules from this build and all remotes
6928
- yield __webpack_init_sharing__("default");
6929
- var container = window[scope]; // or get the container somewhere else
6930
- // Initialize the container, it may provide shared modules
6931
- yield container.init(__webpack_share_scopes__.default);
6932
- var factory = yield container.get(module);
6933
- return factory();
6934
- });
6935
- return _loadSharedModule.apply(this, arguments);
6936
- }
6937
-
6938
- var resolveBasicPkg;
6939
- var basicPkgWillBeResolved = false;
6940
- var waitBasicPkg = new Promise(resolve => {
6941
- resolveBasicPkg = resolve;
6942
- });
6943
- function flushStableLoadBricks() {
6944
- if (!basicPkgWillBeResolved) {
6945
- resolveBasicPkg();
6946
- }
6947
- }
6948
- function loadBricksImperatively(_x, _x2) {
6949
- return _loadBricksImperatively.apply(this, arguments);
6950
- }
6951
- function _loadBricksImperatively() {
6952
- _loadBricksImperatively = _asyncToGenerator$3(function* (bricks, brickPackages) {
6953
- var promise = enqueueStableLoad("bricks", bricks, brickPackages);
6954
- flushStableLoadBricks();
6955
- return dispatchRequestStatus(promise);
6956
- });
6957
- return _loadBricksImperatively.apply(this, arguments);
6958
- }
6959
- function loadProcessorsImperatively(processors, brickPackages) {
6960
- var promise = enqueueStableLoad("processors", processors, brickPackages);
6961
- flushStableLoadBricks();
6962
- return dispatchRequestStatus(promise);
6963
- }
6964
- var v2AdapterPromise;
6965
- var V2_ADAPTER_LOAD_BRICKS = "v2-adapter.load-bricks";
6966
-
6967
- // Get brick/processor items including their dependencies
6968
- function getItemsByPkg(type, list, brickPackagesMap) {
6969
- var itemsByPkg = new Map();
6970
- var listToLoad = new Set();
6971
- var add = item => {
6972
- var _pkg$dependencies;
6973
- if (listToLoad.has(item)) {
6974
- return;
6975
- }
6976
- listToLoad.add(item);
6977
- var pkg;
6978
- var namespace;
6979
- var itemName;
6980
- if (type === "processors" || item.includes(".")) {
6981
- [namespace, itemName] = item.split(".");
6982
- var pkgId = "bricks/".concat(type === "processors" ? getProcessorPackageName(namespace) : namespace);
6983
- pkg = brickPackagesMap.get(pkgId);
6984
- } else {
6985
- itemName = item;
6986
- for (var p of brickPackagesMap.values()) {
6987
- var _p$elements;
6988
- if ((_p$elements = p.elements) !== null && _p$elements !== void 0 && _p$elements.some(e => e === itemName)) {
6989
- pkg = p;
6990
- break;
6991
- }
6992
- }
6993
- }
6994
- if (!pkg) {
6995
- throw new Error("Package for ".concat(item, " not found."));
6996
- }
6997
- var groupItems = itemsByPkg.get(pkg);
6998
- if (!groupItems) {
6999
- groupItems = [];
7000
- itemsByPkg.set(pkg, groupItems);
7001
- }
7002
- groupItems.push(itemName);
7003
-
7004
- // Load their dependencies too
7005
- var deps = (_pkg$dependencies = pkg.dependencies) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies[item];
7006
- if (deps) {
7007
- for (var dep of deps) {
7008
- add(dep);
7009
- }
7010
- }
7011
- };
7012
- for (var item of list) {
7013
- add(item);
7014
- }
7015
- return itemsByPkg;
7016
- }
7017
- function loadBrickModule(_x3, _x4, _x5) {
7018
- return _loadBrickModule.apply(this, arguments);
7019
- }
7020
- function _loadBrickModule() {
7021
- _loadBrickModule = _asyncToGenerator$3(function* (type, pkgId, itemName) {
7022
- var moduleName = "".concat(type === "processors" ? "./processors/" : "./").concat(itemName);
7023
- try {
7024
- yield loadSharedModule(pkgId, moduleName);
7025
- } catch (error) {
7026
- // eslint-disable-next-line no-console
7027
- console.error(error);
7028
- throw new Error("Load ".concat(type, " of \"").concat(pkgId.split("/").pop(), ".").concat(moduleName.split("/").pop(), "\" failed"));
7029
- }
7030
- });
7031
- return _loadBrickModule.apply(this, arguments);
7032
- }
7033
- function loadRestBricks(type, pkgs, itemsMap) {
7034
- return pkgs.map( /*#__PURE__*/function () {
7035
- var _ref = _asyncToGenerator$3(function* (pkg) {
7036
- var _window$PUBLIC_ROOT;
7037
- yield loadScript(pkg.filePath, (_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "");
7038
- yield waitBasicPkg;
7039
- return Promise.all(
7040
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7041
- itemsMap.get(pkg).map(itemName => loadBrickModule(type, pkg.id, itemName)));
7042
- });
7043
- return function (_x6) {
7044
- return _ref.apply(this, arguments);
7045
- };
7046
- }());
7047
- }
7048
- function enqueueStableLoad(_x7, _x8, _x9) {
7049
- return _enqueueStableLoad.apply(this, arguments);
7050
- }
7051
- function _enqueueStableLoad() {
7052
- _enqueueStableLoad = _asyncToGenerator$3(function* (type, list, brickPackages) {
7053
- var brickPackagesMap = new Map();
7054
- for (var pkg of brickPackages) {
7055
- var _pkg$id;
7056
- var pkgId = (_pkg$id = pkg.id) !== null && _pkg$id !== void 0 ? _pkg$id : getPkgIdByFilePath(pkg.filePath);
7057
- brickPackagesMap.set(pkgId, pkg);
7058
- }
7059
- var itemsByPkg = getItemsByPkg(type, list, brickPackagesMap);
7060
- var foundBasicPkg;
7061
- var v2Packages = [];
7062
- var v3PackagesOtherThanBasic = [];
7063
- var maybeV2Adapter;
7064
- for (var _pkg of itemsByPkg.keys()) {
7065
- if (_pkg.id) {
7066
- if (_pkg.id === "bricks/basic") {
7067
- foundBasicPkg = _pkg;
7068
- } else {
7069
- v3PackagesOtherThanBasic.push(_pkg);
7070
- }
7071
- } else {
7072
- // Brick packages of v2 has no `id`
7073
- v2Packages.push(_pkg);
7074
- maybeV2Adapter = brickPackagesMap.get("bricks/v2-adapter");
7075
- if (!maybeV2Adapter) {
7076
- // eslint-disable-next-line no-console
7077
- console.error("Using v2 bricks, but v2-adapter not found");
7078
- }
7079
- }
7080
- }
7081
- var v2Adapter = maybeV2Adapter;
7082
- var basicPkgPromise;
7083
- var basicPkg = foundBasicPkg;
7084
- if (basicPkg) {
7085
- var _window$PUBLIC_ROOT2;
7086
- var tempPromise = loadScript(basicPkg.filePath, (_window$PUBLIC_ROOT2 = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT2 !== void 0 ? _window$PUBLIC_ROOT2 : "");
7087
- // Packages other than BASIC will wait for an extra micro-task tick.
7088
- if (!basicPkgWillBeResolved) {
7089
- basicPkgWillBeResolved = true;
7090
- tempPromise.then(() => Promise.resolve()).then(resolveBasicPkg);
7091
- }
7092
- basicPkgPromise = tempPromise.then(() => Promise.all(
7093
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7094
- itemsByPkg.get(basicPkg).map(itemName => loadBrickModule(type, basicPkg.id, itemName))));
7095
- }
7096
- var pkgPromises = [basicPkgPromise].concat(loadRestBricks(type, v3PackagesOtherThanBasic, itemsByPkg));
7097
- if (v2Adapter && v2Packages.length > 0) {
7098
- if (!v2AdapterPromise) {
7099
- // Load `v2-adapter.load-bricks` and its dependencies
7100
- var v2AdapterItemsByPkg = getItemsByPkg("bricks", [V2_ADAPTER_LOAD_BRICKS], brickPackagesMap);
7101
- var v2AdapterPackages = [...v2AdapterItemsByPkg.keys()];
7102
- var loadV2Adapter = /*#__PURE__*/function () {
7103
- var _ref2 = _asyncToGenerator$3(function* () {
7104
- yield Promise.all(loadRestBricks("bricks", v2AdapterPackages, v2AdapterItemsByPkg));
7105
- return document.createElement(V2_ADAPTER_LOAD_BRICKS);
7106
- });
7107
- return function loadV2Adapter() {
7108
- return _ref2.apply(this, arguments);
7109
- };
7110
- }();
7111
- v2AdapterPromise = loadV2Adapter();
7112
- }
7113
- pkgPromises.push(v2AdapterPromise.then(adapter => Promise.all(v2Packages.map(pkg => {
7114
- var pkgId = getPkgIdByFilePath(pkg.filePath);
7115
- var pkgNamespace = pkgId.split("/")[1];
7116
- return adapter.resolve(v2Adapter.filePath, pkg.filePath, type === "bricks" ?
7117
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7118
- itemsByPkg.get(pkg).map(itemName => "".concat(pkgNamespace, ".").concat(itemName)) : [], pkg.dll,
7119
- // Todo: remove `brickPackages` as an argument
7120
- brickPackages);
7121
- }))));
7122
- }
7123
- yield Promise.all(pkgPromises);
7124
- });
7125
- return _enqueueStableLoad.apply(this, arguments);
7126
- }
7127
- function dispatchRequestStatus(_x10) {
7128
- return _dispatchRequestStatus.apply(this, arguments);
7129
- }
7130
- function _dispatchRequestStatus() {
7131
- _dispatchRequestStatus = _asyncToGenerator$3(function* (promise) {
7132
- window.dispatchEvent(new Event("request.start"));
7133
- try {
7134
- yield promise;
7135
- } finally {
7136
- window.dispatchEvent(new Event("request.end"));
7137
- }
7138
- });
7139
- return _dispatchRequestStatus.apply(this, arguments);
7140
- }
7141
- function getProcessorPackageName(camelPackageName) {
7142
- return camelPackageName.replace(/[A-Z]/g, match => "-".concat(match[0].toLocaleLowerCase())).replace(/_[0-9]/g, match => "-".concat(match[1]));
7143
- }
7144
- function getPkgIdByFilePath(filePath) {
7145
- return filePath.split("/").slice(0, 2).join("/");
7146
- }
7147
-
7148
6888
  /**
7149
6889
  * Merge `app.defaultConfig` and `app.userConfig` to `app.config`.
7150
6890
  *
@@ -9752,15 +9492,15 @@ function _loadScriptOfDll() {
9752
9492
  _loadScriptOfDll = _asyncToGenerator$3(function* (dlls) {
9753
9493
  if (dlls.some(dll => dll.startsWith("dll-of-editor-bricks-helper."))) {
9754
9494
  var dllPath = window.DLL_PATH || {};
9755
- yield loadScript$1(dllPath["react-dnd"], window.CORE_ROOT);
9495
+ yield loadScript(dllPath["react-dnd"], window.CORE_ROOT);
9756
9496
  }
9757
9497
  // `loadScript` is auto cached, no need to filter out `react-dnd`.
9758
- yield loadScript$1(dlls, window.CORE_ROOT);
9498
+ yield loadScript(dlls, window.CORE_ROOT);
9759
9499
  });
9760
9500
  return _loadScriptOfDll.apply(this, arguments);
9761
9501
  }
9762
9502
  function loadScriptOfBricksOrTemplates(src) {
9763
- return loadScript$1(src, window.PUBLIC_ROOT);
9503
+ return loadScript(src, window.PUBLIC_ROOT);
9764
9504
  }
9765
9505
  function generateColorTheme(theme) {
9766
9506
  if (!theme) {