@next-core/brick-kit 2.166.1 → 2.167.1

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