@next-core/brick-kit 2.157.0 → 2.157.2

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.
@@ -869,10 +869,12 @@
869
869
  }
870
870
  var contextNames = brickUtils.trackContext(raw);
871
871
  var stateNames = brickUtils.trackState(raw);
872
- if (contextNames || stateNames) {
872
+ var formStateNames = brickUtils.trackFormState(raw);
873
+ if (contextNames || stateNames || formStateNames) {
873
874
  options.trackingContextList.push({
874
875
  contextNames,
875
876
  stateNames,
877
+ formStateNames,
876
878
  propName: k,
877
879
  propValue: v
878
880
  });
@@ -1717,10 +1719,12 @@
1717
1719
  }
1718
1720
 
1719
1721
  class StoryboardContextWrapper {
1720
- constructor(tplContextId) {
1722
+ constructor(tplContextId, formContextId) {
1721
1723
  _defineProperty__default["default"](this, "data", new Map());
1722
1724
  _defineProperty__default["default"](this, "tplContextId", void 0);
1725
+ _defineProperty__default["default"](this, "formContextId", void 0);
1723
1726
  this.tplContextId = tplContextId;
1727
+ this.formContextId = formContextId;
1724
1728
  }
1725
1729
  set(name, item) {
1726
1730
  if (this.data.has(name)) {
@@ -1781,7 +1785,7 @@
1781
1785
  var _item$eventTarget;
1782
1786
  item.loaded = true;
1783
1787
  item.value = val;
1784
- (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
1788
+ (_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change", {
1785
1789
  detail: item.value
1786
1790
  }));
1787
1791
  }, err => {
@@ -1816,7 +1820,7 @@
1816
1820
  item.value = value;
1817
1821
  }
1818
1822
  }
1819
- (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
1823
+ (_item$eventTarget2 = item.eventTarget) === null || _item$eventTarget2 === void 0 ? void 0 : _item$eventTarget2.dispatchEvent(new CustomEvent(this.formContextId ? "formstate.change" : this.tplContextId ? "state.change" : "context.change", {
1820
1824
  detail: item.value
1821
1825
  }));
1822
1826
  }
@@ -1952,7 +1956,7 @@
1952
1956
  };
1953
1957
  if (contextConf.onChange) {
1954
1958
  for (var handler of [].concat(contextConf.onChange)) {
1955
- newContext.eventTarget.addEventListener(storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
1959
+ newContext.eventTarget.addEventListener(storyboardContextWrapper.formContextId ? "formstate.change" : storyboardContextWrapper.tplContextId ? "state.change" : "context.change", listenerFactory(handler, mergedContext, brick));
1956
1960
  }
1957
1961
  }
1958
1962
  if (contextConf.track) {
@@ -1962,7 +1966,7 @@
1962
1966
  for (var dep of deps) {
1963
1967
  var _eventTarget;
1964
1968
  var ctx = storyboardContextWrapper.get().get(dep);
1965
- ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(isTemplateState ? "state.change" : "context.change", () => {
1969
+ ctx === null || ctx === void 0 ? void 0 : (_eventTarget = ctx.eventTarget) === null || _eventTarget === void 0 ? void 0 : _eventTarget.addEventListener(storyboardContextWrapper.formContextId ? "formstate.change" : isTemplateState ? "state.change" : "context.change", () => {
1966
1970
  if (load) {
1967
1971
  storyboardContextWrapper.updateValue(contextConf.name, {
1968
1972
  cache: "default"
@@ -2057,7 +2061,7 @@
2057
2061
  _defineProperty__default["default"](this, "formState", void 0);
2058
2062
  _defineProperty__default["default"](this, "id", _.uniqueId("form-ctx-"));
2059
2063
  FormContextMap.set(this.id, this);
2060
- this.formState = new StoryboardContextWrapper();
2064
+ this.formState = new StoryboardContextWrapper("", this.id);
2061
2065
  }
2062
2066
  }
2063
2067
  function getCustomFormContext(formContextId) {
@@ -2677,10 +2681,12 @@
2677
2681
  var raw = typeof propValue === "string" ? propValue : getPreEvaluatedRaw(propValue);
2678
2682
  var contextNames = brickUtils.trackContext(raw);
2679
2683
  var stateNames = brickUtils.trackState(raw);
2680
- if (contextNames || stateNames) {
2684
+ var formStateNames = brickUtils.trackFormState(raw);
2685
+ if (contextNames || stateNames || formStateNames) {
2681
2686
  trackingContextList.push({
2682
2687
  contextNames,
2683
2688
  stateNames,
2689
+ formStateNames,
2684
2690
  propName,
2685
2691
  propValue
2686
2692
  });
@@ -5683,6 +5689,8 @@
5683
5689
  case "state.refresh":
5684
5690
  case "state.load":
5685
5691
  return builtinStateListenerFactory(method, handler.args, handler, handler.callback, context);
5692
+ case "formstate.update":
5693
+ return builtinFormStateListenerFactory(method, handler.args, handler, handler.callback, context);
5686
5694
  case "tpl.dispatchEvent":
5687
5695
  return builtinTplDispatchEventFactory(handler.args, handler, context);
5688
5696
  case "message.subscribe":
@@ -5775,6 +5783,13 @@
5775
5783
  }
5776
5784
  return getCustomTemplateContext(tplContextId);
5777
5785
  }
5786
+ function getFormContext(formContextId) {
5787
+ // istanbul ignore if
5788
+ if (!formContextId) {
5789
+ throw new Error("Calling tpl but no formContextId was found in context!");
5790
+ }
5791
+ return getCustomFormContext(formContextId);
5792
+ }
5778
5793
  function builtinTplDispatchEventFactory(args, ifContainer, context) {
5779
5794
  return function (event) {
5780
5795
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
@@ -5811,6 +5826,18 @@
5811
5826
  tplContext.state.updateValue(name, value, method === "update" ? "replace" : method, callback);
5812
5827
  };
5813
5828
  }
5829
+ function builtinFormStateListenerFactory(method, args, ifContainer, callback, context) {
5830
+ return function (event) {
5831
+ if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
5832
+ event
5833
+ }))) {
5834
+ return;
5835
+ }
5836
+ var formContext = getFormContext(context.formContextId);
5837
+ var [name, value] = argsFactory(args, context, event);
5838
+ formContext.formState.updateValue(name, value, method === "update" ? "replace" : method, callback);
5839
+ };
5840
+ }
5814
5841
  function builtinLocationListenerFactory(method, args, ifContainer, context) {
5815
5842
  return function (event) {
5816
5843
  if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
@@ -6347,36 +6374,6 @@
6347
6374
  };
6348
6375
  }();
6349
6376
 
6350
- /**
6351
- * @description 独立小产品Runtime接口
6352
- * @endpoint GET /api/v1/micro_app_standalone/runtime/:appId
6353
- */
6354
- var RuntimeApi_runtimeMicroAppStandalone = /*#__PURE__*/function () {
6355
- var _ref = _asyncToGenerator__default["default"](function* (appId, options) {
6356
- return (/**! @contract easyops.api.micro_app_standalone.runtime.RuntimeMicroAppStandalone@1.0.1 */
6357
- (yield brickHttp.http.get("api/gateway/micro_app_standalone.runtime.RuntimeMicroAppStandalone/api/v1/micro_app_standalone/runtime/".concat(appId), options)).data
6358
- );
6359
- });
6360
- return function RuntimeApi_runtimeMicroAppStandalone(_x, _x2) {
6361
- return _ref.apply(this, arguments);
6362
- };
6363
- }();
6364
-
6365
- /**
6366
- * @description 查询独立部署小产品
6367
- * @endpoint POST /api/v1/micro_app_standalone/search
6368
- */
6369
- var RuntimeApi_searchMicroAppStandalone = /*#__PURE__*/function () {
6370
- var _ref = _asyncToGenerator__default["default"](function* (data, options) {
6371
- return (/**! @contract easyops.api.micro_app_standalone.runtime.SearchMicroAppStandalone@1.0.1 */
6372
- (yield brickHttp.http.post("api/gateway/micro_app_standalone.runtime.SearchMicroAppStandalone/api/v1/micro_app_standalone/search", data, options)).data
6373
- );
6374
- });
6375
- return function RuntimeApi_searchMicroAppStandalone(_x, _x2) {
6376
- return _ref.apply(this, arguments);
6377
- };
6378
- }();
6379
-
6380
6377
  /**
6381
6378
  * Merge `app.defaultConfig` and `app.userConfig` to `app.config`.
6382
6379
  *
@@ -6558,6 +6555,36 @@
6558
6555
  }
6559
6556
  }
6560
6557
 
6558
+ /**
6559
+ * @description 独立小产品Runtime接口
6560
+ * @endpoint GET /api/v1/micro_app_standalone/runtime/:appId
6561
+ */
6562
+ var RuntimeApi_runtimeMicroAppStandalone = /*#__PURE__*/function () {
6563
+ var _ref = _asyncToGenerator__default["default"](function* (appId, options) {
6564
+ return (/**! @contract easyops.api.micro_app_standalone.runtime.RuntimeMicroAppStandalone@1.0.1 */
6565
+ (yield brickHttp.http.get("api/gateway/micro_app_standalone.runtime.RuntimeMicroAppStandalone/api/v1/micro_app_standalone/runtime/".concat(appId), options)).data
6566
+ );
6567
+ });
6568
+ return function RuntimeApi_runtimeMicroAppStandalone(_x, _x2) {
6569
+ return _ref.apply(this, arguments);
6570
+ };
6571
+ }();
6572
+
6573
+ /**
6574
+ * @description 查询独立部署小产品
6575
+ * @endpoint POST /api/v1/micro_app_standalone/search
6576
+ */
6577
+ var RuntimeApi_searchMicroAppStandalone = /*#__PURE__*/function () {
6578
+ var _ref = _asyncToGenerator__default["default"](function* (data, options) {
6579
+ return (/**! @contract easyops.api.micro_app_standalone.runtime.SearchMicroAppStandalone@1.0.1 */
6580
+ (yield brickHttp.http.post("api/gateway/micro_app_standalone.runtime.SearchMicroAppStandalone/api/v1/micro_app_standalone/search", data, options)).data
6581
+ );
6582
+ });
6583
+ return function RuntimeApi_searchMicroAppStandalone(_x, _x2) {
6584
+ return _ref.apply(this, arguments);
6585
+ };
6586
+ }();
6587
+
6561
6588
  var _excluded$4 = ["feature_flags"],
6562
6589
  _excluded2$1 = ["featureFlags", "misc"];
6563
6590
  function standaloneBootstrap() {
@@ -6565,14 +6592,23 @@
6565
6592
  }
6566
6593
  function _standaloneBootstrap() {
6567
6594
  _standaloneBootstrap = _asyncToGenerator__default["default"](function* () {
6568
- var [bootstrapResult, confString, runtimeData] = yield Promise.all([brickHttp.http.get(window.BOOTSTRAP_FILE), brickHttp.http.get("".concat(window.APP_ROOT, "conf.yaml"), {
6595
+ var requests = [brickHttp.http.get(window.BOOTSTRAP_FILE), brickHttp.http.get("".concat(window.APP_ROOT, "conf.yaml"), {
6569
6596
  responseType: "text"
6570
- }), yield BootstrapStandaloneApi_runtimeStandalone().catch(function (error) {
6597
+ }), BootstrapStandaloneApi_runtimeStandalone().catch(function (error) {
6571
6598
  // make it not crash when the backend service is not updated.
6572
6599
  // eslint-disable-next-line no-console
6573
6600
  console.warn("request runtime api from api-gateway failed: ", error, ", something might went wrong running standalone micro app");
6574
- return undefined;
6575
- })]);
6601
+ return;
6602
+ })];
6603
+ if (!window.NO_AUTH_GUARD) {
6604
+ var matches;
6605
+ var appId = window.APP_ID || (window.APP_ROOT && (matches = window.APP_ROOT.match(/^(?:\/next)?\/sa-static\/([^/]+)\/versions\//)) ? matches[1] : null);
6606
+ if (appId) {
6607
+ // No need to wait.
6608
+ safeGetRuntimeMicroAppStandalone(appId);
6609
+ }
6610
+ }
6611
+ var [bootstrapResult, confString, runtimeData] = yield Promise.all(requests);
6576
6612
  var conf;
6577
6613
  try {
6578
6614
  conf = confString ? yaml__default["default"].safeLoad(confString, {
@@ -6613,16 +6649,16 @@
6613
6649
  }
6614
6650
  }
6615
6651
  if (runtimeData) {
6616
- var runtimeSetings = runtimeData.settings;
6617
- if (!_.isEmpty(runtimeSetings)) {
6652
+ var runtimeSettings = runtimeData.settings;
6653
+ if (!_.isEmpty(runtimeSettings)) {
6618
6654
  // Merge Feature Flags
6619
6655
  if (!settings) {
6620
- settings = runtimeSetings;
6656
+ settings = runtimeSettings;
6621
6657
  } else {
6622
6658
  // Merge Feature Flags & Misc
6623
- var rest = _objectWithoutProperties__default["default"](runtimeSetings, _excluded2$1);
6624
- settings.featureFlags = _objectSpread__default["default"](_objectSpread__default["default"]({}, settings.featureFlags), runtimeSetings.featureFlags);
6625
- settings.misc = _objectSpread__default["default"](_objectSpread__default["default"]({}, settings.misc), runtimeSetings.misc);
6659
+ var rest = _objectWithoutProperties__default["default"](runtimeSettings, _excluded2$1);
6660
+ settings.featureFlags = _objectSpread__default["default"](_objectSpread__default["default"]({}, settings.featureFlags), runtimeSettings.featureFlags);
6661
+ settings.misc = _objectSpread__default["default"](_objectSpread__default["default"]({}, settings.misc), runtimeSettings.misc);
6626
6662
  settings = Object.assign(settings, rest);
6627
6663
  }
6628
6664
  }
@@ -6633,6 +6669,24 @@
6633
6669
  });
6634
6670
  return _standaloneBootstrap.apply(this, arguments);
6635
6671
  }
6672
+ var appRuntimeDataMap = new Map();
6673
+ function safeGetRuntimeMicroAppStandalone(_x) {
6674
+ return _safeGetRuntimeMicroAppStandalone.apply(this, arguments);
6675
+ }
6676
+ function _safeGetRuntimeMicroAppStandalone() {
6677
+ _safeGetRuntimeMicroAppStandalone = _asyncToGenerator__default["default"](function* (appId) {
6678
+ if (appRuntimeDataMap.has(appId)) {
6679
+ return appRuntimeDataMap.get(appId);
6680
+ }
6681
+ var promise = RuntimeApi_runtimeMicroAppStandalone(appId).catch(function (error) {
6682
+ // make it not crash when the backend service is not updated.
6683
+ // eslint-disable-next-line no-console
6684
+ console.warn("request standalone runtime api from micro-app-standalone failed: ", error, ", something might went wrong running standalone micro app");
6685
+ });
6686
+ appRuntimeDataMap.set(appId, promise);
6687
+ });
6688
+ return _safeGetRuntimeMicroAppStandalone.apply(this, arguments);
6689
+ }
6636
6690
 
6637
6691
  /**
6638
6692
  * Take input from [0, n] and return it as [0, 1]
@@ -8234,7 +8288,8 @@
8234
8288
  if (!window.NO_AUTH_GUARD) {
8235
8289
  var appRuntimeData;
8236
8290
  try {
8237
- appRuntimeData = yield RuntimeApi_runtimeMicroAppStandalone(storyboard.app.id);
8291
+ // Note: the request maybe have fired already during bootstrap.
8292
+ appRuntimeData = yield safeGetRuntimeMicroAppStandalone(storyboard.app.id);
8238
8293
  } catch (error) {
8239
8294
  // make it not crash when the backend service is not updated.
8240
8295
  // eslint-disable-next-line no-console
@@ -8981,6 +9036,14 @@
8981
9036
  _ctx === null || _ctx === void 0 ? void 0 : (_eventTarget2 = _ctx.eventTarget) === null || _eventTarget2 === void 0 ? void 0 : _eventTarget2.addEventListener("state.change", listener);
8982
9037
  }
8983
9038
  }
9039
+ if (track.formStateNames) {
9040
+ var formContext = getCustomFormContext(context.formContextId);
9041
+ for (var _stateName of track.formStateNames) {
9042
+ var _eventTarget3;
9043
+ var _ctx2 = formContext.formState.get().get(_stateName);
9044
+ _ctx2 === null || _ctx2 === void 0 ? void 0 : (_eventTarget3 = _ctx2.eventTarget) === null || _eventTarget3 === void 0 ? void 0 : _eventTarget3.addEventListener("formstate.change", listener);
9045
+ }
9046
+ }
8984
9047
  };
8985
9048
  for (var track of trackingContextList) {
8986
9049
  _loop(track);