@next-core/brick-kit 2.166.1 → 2.167.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.
@@ -6551,6 +6551,267 @@
6551
6551
  };
6552
6552
  }();
6553
6553
 
6554
+ var cache$1 = new Map();
6555
+ function loadScript(src, prefix) {
6556
+ if (Array.isArray(src)) {
6557
+ return Promise.all(src.map(item => loadScript(item, prefix)));
6558
+ }
6559
+ var fixedSrc = prefix ? "".concat(prefix).concat(src) : src;
6560
+ var cachedPromise = cache$1.get(fixedSrc);
6561
+ if (cachedPromise) {
6562
+ return cachedPromise;
6563
+ }
6564
+ var promise = new Promise((resolve, reject) => {
6565
+ var end = () => {
6566
+ window.dispatchEvent(new Event("request.end"));
6567
+ };
6568
+ var script = document.createElement("script");
6569
+ script.src = fixedSrc;
6570
+ script.type = "text/javascript";
6571
+ script.async = true;
6572
+ script.onload = () => {
6573
+ resolve(fixedSrc);
6574
+ end();
6575
+ };
6576
+ script.onerror = e => {
6577
+ reject(e);
6578
+ end();
6579
+ };
6580
+ var firstScript = document.currentScript || document.getElementsByTagName("script")[0];
6581
+ firstScript.parentNode.insertBefore(script, firstScript);
6582
+ window.dispatchEvent(new Event("request.start"));
6583
+ });
6584
+ cache$1.set(fixedSrc, promise);
6585
+ return promise;
6586
+ }
6587
+
6588
+ // https://github.com/module-federation/module-federation-examples/blob/eda9493f3991a423479fd834cfb1d7b241d9d1f0/advanced-api/dynamic-remotes/app1/src/App.js
6589
+ function loadSharedModule(_x, _x2) {
6590
+ return _loadSharedModule.apply(this, arguments);
6591
+ }
6592
+ function _loadSharedModule() {
6593
+ _loadSharedModule = _asyncToGenerator__default["default"](function* (scope, module) {
6594
+ // Initializes the share scope. This fills it with known provided modules from this build and all remotes
6595
+ yield __webpack_init_sharing__("default");
6596
+ var container = window[scope]; // or get the container somewhere else
6597
+ // Initialize the container, it may provide shared modules
6598
+ yield container.init(__webpack_share_scopes__.default);
6599
+ var factory = yield container.get(module);
6600
+ return factory();
6601
+ });
6602
+ return _loadSharedModule.apply(this, arguments);
6603
+ }
6604
+
6605
+ var resolveBasicPkg;
6606
+ var basicPkgWillBeResolved = false;
6607
+ var waitBasicPkg = new Promise(resolve => {
6608
+ resolveBasicPkg = resolve;
6609
+ });
6610
+ function flushStableLoadBricks() {
6611
+ if (!basicPkgWillBeResolved) {
6612
+ resolveBasicPkg();
6613
+ }
6614
+ }
6615
+ function loadBricksImperatively(_x, _x2) {
6616
+ return _loadBricksImperatively.apply(this, arguments);
6617
+ }
6618
+ function _loadBricksImperatively() {
6619
+ _loadBricksImperatively = _asyncToGenerator__default["default"](function* (bricks, brickPackages) {
6620
+ var promise = enqueueStableLoad("bricks", bricks, brickPackages);
6621
+ flushStableLoadBricks();
6622
+ return dispatchRequestStatus(promise);
6623
+ });
6624
+ return _loadBricksImperatively.apply(this, arguments);
6625
+ }
6626
+ function loadProcessorsImperatively(processors, brickPackages) {
6627
+ var promise = enqueueStableLoad("processors", processors, brickPackages);
6628
+ flushStableLoadBricks();
6629
+ return dispatchRequestStatus(promise);
6630
+ }
6631
+ var v2AdapterPromise;
6632
+ var V2_ADAPTER_LOAD_BRICKS = "v2-adapter.load-bricks";
6633
+
6634
+ // Get brick/processor items including their dependencies
6635
+ function getItemsByPkg(type, list, brickPackagesMap) {
6636
+ var itemsByPkg = new Map();
6637
+ var listToLoad = new Set();
6638
+ var add = item => {
6639
+ var _pkg$dependencies;
6640
+ if (listToLoad.has(item)) {
6641
+ return;
6642
+ }
6643
+ listToLoad.add(item);
6644
+ var pkg;
6645
+ var namespace;
6646
+ var itemName;
6647
+ if (type === "processors" || item.includes(".")) {
6648
+ [namespace, itemName] = item.split(".");
6649
+ var pkgId = "bricks/".concat(type === "processors" ? getProcessorPackageName(namespace) : namespace);
6650
+ pkg = brickPackagesMap.get(pkgId);
6651
+ } else {
6652
+ itemName = item;
6653
+ for (var p of brickPackagesMap.values()) {
6654
+ var _p$elements;
6655
+ if ((_p$elements = p.elements) !== null && _p$elements !== void 0 && _p$elements.some(e => e === itemName)) {
6656
+ pkg = p;
6657
+ break;
6658
+ }
6659
+ }
6660
+ }
6661
+ if (!pkg) {
6662
+ throw new Error("Package for ".concat(item, " not found."));
6663
+ }
6664
+ var groupItems = itemsByPkg.get(pkg);
6665
+ if (!groupItems) {
6666
+ groupItems = [];
6667
+ itemsByPkg.set(pkg, groupItems);
6668
+ }
6669
+ groupItems.push(itemName);
6670
+
6671
+ // Load their dependencies too
6672
+ var deps = (_pkg$dependencies = pkg.dependencies) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies[item];
6673
+ if (deps) {
6674
+ for (var dep of deps) {
6675
+ add(dep);
6676
+ }
6677
+ }
6678
+ };
6679
+ for (var item of list) {
6680
+ add(item);
6681
+ }
6682
+ return itemsByPkg;
6683
+ }
6684
+ function loadBrickModule(_x3, _x4, _x5) {
6685
+ return _loadBrickModule.apply(this, arguments);
6686
+ }
6687
+ function _loadBrickModule() {
6688
+ _loadBrickModule = _asyncToGenerator__default["default"](function* (type, pkgId, itemName) {
6689
+ var moduleName = "".concat(type === "processors" ? "./processors/" : "./").concat(itemName);
6690
+ try {
6691
+ yield loadSharedModule(pkgId, moduleName);
6692
+ } catch (error) {
6693
+ // eslint-disable-next-line no-console
6694
+ console.error(error);
6695
+ throw new Error("Load ".concat(type, " of \"").concat(pkgId.split("/").pop(), ".").concat(moduleName.split("/").pop(), "\" failed"));
6696
+ }
6697
+ });
6698
+ return _loadBrickModule.apply(this, arguments);
6699
+ }
6700
+ function loadRestBricks(type, pkgs, itemsMap) {
6701
+ return pkgs.map( /*#__PURE__*/function () {
6702
+ var _ref = _asyncToGenerator__default["default"](function* (pkg) {
6703
+ var _window$PUBLIC_ROOT;
6704
+ yield loadScript(pkg.filePath, (_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "");
6705
+ yield waitBasicPkg;
6706
+ return Promise.all(
6707
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6708
+ itemsMap.get(pkg).map(itemName => loadBrickModule(type, pkg.id, itemName)));
6709
+ });
6710
+ return function (_x6) {
6711
+ return _ref.apply(this, arguments);
6712
+ };
6713
+ }());
6714
+ }
6715
+ function enqueueStableLoad(_x7, _x8, _x9) {
6716
+ return _enqueueStableLoad.apply(this, arguments);
6717
+ }
6718
+ function _enqueueStableLoad() {
6719
+ _enqueueStableLoad = _asyncToGenerator__default["default"](function* (type, list, brickPackages) {
6720
+ var brickPackagesMap = new Map();
6721
+ for (var pkg of brickPackages) {
6722
+ var _pkg$id;
6723
+ var pkgId = (_pkg$id = pkg.id) !== null && _pkg$id !== void 0 ? _pkg$id : getPkgIdByFilePath(pkg.filePath);
6724
+ brickPackagesMap.set(pkgId, pkg);
6725
+ }
6726
+ var itemsByPkg = getItemsByPkg(type, list, brickPackagesMap);
6727
+ var foundBasicPkg;
6728
+ var v2Packages = [];
6729
+ var v3PackagesOtherThanBasic = [];
6730
+ var maybeV2Adapter;
6731
+ for (var _pkg of itemsByPkg.keys()) {
6732
+ if (_pkg.id) {
6733
+ if (_pkg.id === "bricks/basic") {
6734
+ foundBasicPkg = _pkg;
6735
+ } else {
6736
+ v3PackagesOtherThanBasic.push(_pkg);
6737
+ }
6738
+ } else {
6739
+ // Brick packages of v2 has no `id`
6740
+ v2Packages.push(_pkg);
6741
+ maybeV2Adapter = brickPackagesMap.get("bricks/v2-adapter");
6742
+ if (!maybeV2Adapter) {
6743
+ // eslint-disable-next-line no-console
6744
+ console.error("Using v2 bricks, but v2-adapter not found");
6745
+ }
6746
+ }
6747
+ }
6748
+ var v2Adapter = maybeV2Adapter;
6749
+ var basicPkgPromise;
6750
+ var basicPkg = foundBasicPkg;
6751
+ if (basicPkg) {
6752
+ var _window$PUBLIC_ROOT2;
6753
+ var tempPromise = loadScript(basicPkg.filePath, (_window$PUBLIC_ROOT2 = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT2 !== void 0 ? _window$PUBLIC_ROOT2 : "");
6754
+ // Packages other than BASIC will wait for an extra micro-task tick.
6755
+ if (!basicPkgWillBeResolved) {
6756
+ basicPkgWillBeResolved = true;
6757
+ tempPromise.then(() => Promise.resolve()).then(resolveBasicPkg);
6758
+ }
6759
+ basicPkgPromise = tempPromise.then(() => Promise.all(
6760
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6761
+ itemsByPkg.get(basicPkg).map(itemName => loadBrickModule(type, basicPkg.id, itemName))));
6762
+ }
6763
+ var pkgPromises = [basicPkgPromise].concat(loadRestBricks(type, v3PackagesOtherThanBasic, itemsByPkg));
6764
+ if (v2Adapter && v2Packages.length > 0) {
6765
+ if (!v2AdapterPromise) {
6766
+ // Load `v2-adapter.load-bricks` and its dependencies
6767
+ var v2AdapterItemsByPkg = getItemsByPkg("bricks", [V2_ADAPTER_LOAD_BRICKS], brickPackagesMap);
6768
+ var v2AdapterPackages = [...v2AdapterItemsByPkg.keys()];
6769
+ var loadV2Adapter = /*#__PURE__*/function () {
6770
+ var _ref2 = _asyncToGenerator__default["default"](function* () {
6771
+ yield Promise.all(loadRestBricks("bricks", v2AdapterPackages, v2AdapterItemsByPkg));
6772
+ return document.createElement(V2_ADAPTER_LOAD_BRICKS);
6773
+ });
6774
+ return function loadV2Adapter() {
6775
+ return _ref2.apply(this, arguments);
6776
+ };
6777
+ }();
6778
+ v2AdapterPromise = loadV2Adapter();
6779
+ }
6780
+ pkgPromises.push(v2AdapterPromise.then(adapter => Promise.all(v2Packages.map(pkg => {
6781
+ var pkgId = getPkgIdByFilePath(pkg.filePath);
6782
+ var pkgNamespace = pkgId.split("/")[1];
6783
+ return adapter.resolve(v2Adapter.filePath, pkg.filePath, type === "bricks" ?
6784
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6785
+ itemsByPkg.get(pkg).map(itemName => "".concat(pkgNamespace, ".").concat(itemName)) : [], pkg.dll,
6786
+ // Todo: remove `brickPackages` as an argument
6787
+ brickPackages);
6788
+ }))));
6789
+ }
6790
+ yield Promise.all(pkgPromises);
6791
+ });
6792
+ return _enqueueStableLoad.apply(this, arguments);
6793
+ }
6794
+ function dispatchRequestStatus(_x10) {
6795
+ return _dispatchRequestStatus.apply(this, arguments);
6796
+ }
6797
+ function _dispatchRequestStatus() {
6798
+ _dispatchRequestStatus = _asyncToGenerator__default["default"](function* (promise) {
6799
+ window.dispatchEvent(new Event("request.start"));
6800
+ try {
6801
+ yield promise;
6802
+ } finally {
6803
+ window.dispatchEvent(new Event("request.end"));
6804
+ }
6805
+ });
6806
+ return _dispatchRequestStatus.apply(this, arguments);
6807
+ }
6808
+ function getProcessorPackageName(camelPackageName) {
6809
+ return camelPackageName.replace(/[A-Z]/g, match => "-".concat(match[0].toLocaleLowerCase())).replace(/_[0-9]/g, match => "-".concat(match[1]));
6810
+ }
6811
+ function getPkgIdByFilePath(filePath) {
6812
+ return filePath.split("/").slice(0, 2).join("/");
6813
+ }
6814
+
6554
6815
  /**
6555
6816
  * Merge `app.defaultConfig` and `app.userConfig` to `app.config`.
6556
6817
  *
@@ -8318,6 +8579,7 @@
8318
8579
  pendingTask: Promise.resolve()
8319
8580
  };
8320
8581
  } else {
8582
+ var _eager$v3Bricks;
8321
8583
  // 先加载模板
8322
8584
  var templateDeps = brickUtils.getTemplateDepsOfStoryboard(storyboard, templatePackages);
8323
8585
  yield loadScriptOfBricksOrTemplates(templateDeps);
@@ -8326,6 +8588,8 @@
8326
8588
  dll,
8327
8589
  deps,
8328
8590
  bricks,
8591
+ v3Bricks,
8592
+ v3Processors,
8329
8593
  eager
8330
8594
  } = brickUtils.getDllAndDepsOfStoryboard(yield brickUtils.asyncProcessStoryboard(storyboard, brickTemplateRegistry, templatePackages), brickPackages, {
8331
8595
  ignoreBricksInUnusedCustomTemplates: true
@@ -8333,10 +8597,15 @@
8333
8597
  // 需要先阻塞加载 Custom Processors 和 widgets。
8334
8598
  yield loadScriptOfDll(eager.dll);
8335
8599
  yield loadScriptOfBricksOrTemplates(eager.deps);
8600
+ if ((_eager$v3Bricks = eager.v3Bricks) !== null && _eager$v3Bricks !== void 0 && _eager$v3Bricks.length) {
8601
+ yield loadBricksImperatively(eager.v3Bricks, brickPackages);
8602
+ }
8336
8603
  // 加载构件资源时,不再阻塞后续业务数据的加载,在挂载构件时再等待该任务完成。
8337
8604
  // 挂载构件可能包括:Provider 构件实时挂载、路由准备完成后的统一挂载等。
8338
8605
  return {
8339
- pendingTask: loadScriptOfDll(dll).then(() => loadScriptOfBricksOrTemplates(deps)).then(() => loadLazyBricks(bricks))
8606
+ pendingTask: loadScriptOfDll(dll).then(() => loadScriptOfBricksOrTemplates(deps)).then( /*#__PURE__*/_asyncToGenerator__default["default"](function* () {
8607
+ yield Promise.all([loadLazyBricks(bricks), (v3Bricks === null || v3Bricks === void 0 ? void 0 : v3Bricks.length) && loadBricksImperatively(v3Bricks, brickPackages), (v3Processors === null || v3Processors === void 0 ? void 0 : v3Processors.length) && loadProcessorsImperatively(v3Processors, brickPackages)]);
8608
+ }))
8340
8609
  };
8341
8610
  }
8342
8611
  });
@@ -8345,28 +8614,33 @@
8345
8614
  };
8346
8615
  }());
8347
8616
  _defineProperty__default["default"](this, "_loadDynamicBricks", /*#__PURE__*/function () {
8348
- var _ref2 = _asyncToGenerator__default["default"](function* (bricks, processors) {
8617
+ var _ref3 = _asyncToGenerator__default["default"](function* (bricks, processors) {
8349
8618
  var filteredBricks = bricks.filter(
8350
8619
  // Only try to load undefined custom elements.
8351
8620
  item => !customElements.get(item));
8621
+ var {
8622
+ brickPackages
8623
+ } = _this.bootstrapData;
8352
8624
  // Try to load deps for dynamic added bricks.
8353
8625
  var {
8354
8626
  dll,
8355
- deps
8627
+ deps,
8628
+ v3Bricks,
8629
+ v3Processors
8356
8630
  } = brickUtils.getDllAndDepsByResource({
8357
8631
  bricks: filteredBricks,
8358
8632
  processors
8359
8633
  }, _this.bootstrapData.brickPackages);
8360
8634
  yield loadScriptOfDll(dll);
8361
8635
  yield loadScriptOfBricksOrTemplates(deps);
8362
- yield loadLazyBricks(filteredBricks);
8636
+ yield Promise.all([loadLazyBricks(filteredBricks), (v3Bricks === null || v3Bricks === void 0 ? void 0 : v3Bricks.length) && loadBricksImperatively(v3Bricks, brickPackages), (v3Processors === null || v3Processors === void 0 ? void 0 : v3Processors.length) && loadProcessorsImperatively(v3Processors, brickPackages)]);
8363
8637
  });
8364
8638
  return function (_x2, _x3) {
8365
- return _ref2.apply(this, arguments);
8639
+ return _ref3.apply(this, arguments);
8366
8640
  };
8367
8641
  }());
8368
8642
  _defineProperty__default["default"](this, "_loadEditorBricks", /*#__PURE__*/function () {
8369
- var _ref3 = _asyncToGenerator__default["default"](function* (editorBricks) {
8643
+ var _ref4 = _asyncToGenerator__default["default"](function* (editorBricks) {
8370
8644
  var {
8371
8645
  dll,
8372
8646
  deps
@@ -8379,7 +8653,7 @@
8379
8653
  yield loadScriptOfBricksOrTemplates(deps);
8380
8654
  });
8381
8655
  return function (_x4) {
8382
- return _ref3.apply(this, arguments);
8656
+ return _ref4.apply(this, arguments);
8383
8657
  };
8384
8658
  }());
8385
8659
  }
@@ -8563,8 +8837,8 @@
8563
8837
  // Prefix to avoid conflict between brick package's i18n namespace.
8564
8838
  var i18nNamespace = getI18nNamespace("app", storyboard.app.id);
8565
8839
  // Support any language in `meta.i18n`.
8566
- Object.entries(storyboard.meta.i18n).forEach(_ref4 => {
8567
- var [lang, resources] = _ref4;
8840
+ Object.entries(storyboard.meta.i18n).forEach(_ref5 => {
8841
+ var [lang, resources] = _ref5;
8568
8842
  i18next__default["default"].addResourceBundle(lang, i18nNamespace, resources);
8569
8843
  });
8570
8844
  }
@@ -8986,8 +9260,8 @@
8986
9260
  });
8987
9261
  });
8988
9262
  if (!filterMenus.length) {
8989
- var _ref5, _yield$InstanceApi_po;
8990
- filterMenus = (_ref5 = (_yield$InstanceApi_po = yield InstanceApi_postSearch("STANDALONE_MENU@EASYOPS", {
9263
+ var _ref6, _yield$InstanceApi_po;
9264
+ filterMenus = (_ref6 = (_yield$InstanceApi_po = yield InstanceApi_postSearch("STANDALONE_MENU@EASYOPS", {
8991
9265
  page: 1,
8992
9266
  page_size: 200,
8993
9267
  fields: {
@@ -9016,7 +9290,7 @@
9016
9290
  $eq: true
9017
9291
  }
9018
9292
  }
9019
- })) === null || _yield$InstanceApi_po === void 0 ? void 0 : _yield$InstanceApi_po.list) !== null && _ref5 !== void 0 ? _ref5 : [];
9293
+ })) === null || _yield$InstanceApi_po === void 0 ? void 0 : _yield$InstanceApi_po.list) !== null && _ref6 !== void 0 ? _ref6 : [];
9020
9294
  }
9021
9295
  return filterMenus;
9022
9296
  })();