@next-core/brick-kit 2.136.0 → 2.137.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
@@ -2035,7 +2035,7 @@ class StoryboardContextWrapper {
2035
2035
  }
2036
2036
 
2037
2037
  if (callback) {
2038
- var callbackFactory = eventCallbackFactory(callback, () => this.getResolveOptions(_internalApiGetCurrentContext()).mergedContext);
2038
+ var callbackFactory = eventCallbackFactory(callback, () => this.getResolveOptions(_internalApiGetCurrentContext()).mergedContext, null);
2039
2039
  promise.then(val => {
2040
2040
  callbackFactory("success")({
2041
2041
  value: val
@@ -2344,6 +2344,22 @@ mediaBreakpointMinWidthMap.forEach((minWidth, breakpoint) => {
2344
2344
  });
2345
2345
  var getMedia = () => MEDIA;
2346
2346
 
2347
+ var FormContextMap = new Map();
2348
+ class CustomFormContext {
2349
+ constructor() {
2350
+ _defineProperty$1(this, "formState", void 0);
2351
+
2352
+ _defineProperty$1(this, "id", uniqueId("form-ctx-"));
2353
+
2354
+ FormContextMap.set(this.id, this);
2355
+ this.formState = new StoryboardContextWrapper();
2356
+ }
2357
+
2358
+ }
2359
+ function getCustomFormContext(formContextId) {
2360
+ return FormContextMap.get(formContextId);
2361
+ }
2362
+
2347
2363
  var symbolForRaw = Symbol.for("pre.evaluated.raw");
2348
2364
  var symbolForContext = Symbol.for("pre.evaluated.context");
2349
2365
  function isPreEvaluated(raw) {
@@ -2416,6 +2432,7 @@ function evaluate(raw) {
2416
2432
  var attemptToVisitData = attemptToVisitGlobals.has("DATA");
2417
2433
  var attemptToVisitTpl = attemptToVisitGlobals.has("TPL");
2418
2434
  var attemptToVisitState = attemptToVisitGlobals.has("STATE");
2435
+ var attemptToVisitFormState = attemptToVisitGlobals.has("FORM_STATE");
2419
2436
  var attemptToVisitTplOrState = attemptToVisitTpl || attemptToVisitState; // Ignore evaluating if `event` is missing in context.
2420
2437
  // Since it should be evaluated during events handling.
2421
2438
 
@@ -2467,6 +2484,20 @@ function evaluate(raw) {
2467
2484
  }
2468
2485
  }
2469
2486
 
2487
+ if (attemptToVisitFormState && runtimeContext.formContextId) {
2488
+ var formContext = getCustomFormContext(runtimeContext.formContextId);
2489
+ globalVariables.FORM_STATE = getDynamicReadOnlyProxy({
2490
+ get(target, key) {
2491
+ return formContext.formState.getValue(key);
2492
+ },
2493
+
2494
+ ownKeys() {
2495
+ return Array.from(formContext.formState.get().keys());
2496
+ }
2497
+
2498
+ });
2499
+ }
2500
+
2470
2501
  var {
2471
2502
  app: currentApp,
2472
2503
  query,
@@ -2920,7 +2951,7 @@ var computeRealValue = (value, context, injectDeep, internalOptions) => {
2920
2951
 
2921
2952
  if (preEvaluated || isEvaluable(value)) {
2922
2953
  var runtimeContext = {};
2923
- var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace"];
2954
+ var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId"];
2924
2955
 
2925
2956
  for (var key of keys) {
2926
2957
  if (context !== null && context !== void 0 && context[key]) {
@@ -6024,13 +6055,25 @@ var ContractApi_searchSingleContract = /*#__PURE__*/function () {
6024
6055
  }();
6025
6056
 
6026
6057
  var contractsMap = new Map();
6027
- function collectContract(contracts) {
6058
+ var widgetContractMap = new Map();
6059
+
6060
+ var addContract = (contracts, map) => {
6028
6061
  contracts === null || contracts === void 0 ? void 0 : contracts.forEach(contract => {
6029
- contractsMap.set("".concat(contract.namespaceId, ".").concat(contract.name), contract);
6062
+ map.set("".concat(contract.namespaceId, ".").concat(contract.name), contract);
6030
6063
  });
6064
+ };
6065
+
6066
+ function collectContract(contracts) {
6067
+ addContract(contracts, contractsMap);
6068
+ }
6069
+ function collectWidgetContract(contracts) {
6070
+ addContract(contracts, widgetContractMap);
6071
+ }
6072
+ function clearCollectWidgetContract() {
6073
+ widgetContractMap.clear();
6031
6074
  }
6032
6075
  function getContract(name) {
6033
- return contractsMap.get(name);
6076
+ return contractsMap.get(name) || widgetContractMap.get(name);
6034
6077
  }
6035
6078
 
6036
6079
  var flowApiDefinitionPromiseMap = new Map(); // Legacy Custom API: `${namespace}@${name}`
@@ -6693,7 +6736,7 @@ function customListenerFactory(handler, ifContainer, context, runtimeBrick) {
6693
6736
  };
6694
6737
  }
6695
6738
 
6696
- function eventCallbackFactory(callback, getContext) {
6739
+ function eventCallbackFactory(callback, getContext, runtimeBrick) {
6697
6740
  return function callbackFactory(type) {
6698
6741
  return function (result) {
6699
6742
  if (callback !== null && callback !== void 0 && callback[type]) {
@@ -6703,7 +6746,7 @@ function eventCallbackFactory(callback, getContext) {
6703
6746
  });
6704
6747
  var context = getContext();
6705
6748
  [].concat(callback[type]).forEach(eachHandler => {
6706
- listenerFactory(eachHandler, context, null)(event);
6749
+ listenerFactory(eachHandler, context, runtimeBrick)(event);
6707
6750
  });
6708
6751
  } catch (err) {
6709
6752
  // Do not throw errors in `callback.success` or `callback.progress`,
@@ -6757,7 +6800,7 @@ function _brickCallback() {
6757
6800
  return;
6758
6801
  }
6759
6802
 
6760
- var callbackFactory = eventCallbackFactory(handler.callback, () => context);
6803
+ var callbackFactory = eventCallbackFactory(handler.callback, () => context, runtimeBrick);
6761
6804
  var pollableCallback = {
6762
6805
  progress: callbackFactory("progress"),
6763
6806
  success: callbackFactory("success"),
@@ -8276,6 +8319,7 @@ function applyColorTheme(options) {
8276
8319
 
8277
8320
  var formRenderer = "form-renderer.form-renderer";
8278
8321
  var filterProperties = ["instanceId", "brick", "slots", "properties", "events", "if", "context", "bricks", "mountPoint"];
8322
+ var symbolForFormContextId = Symbol.for("form.contextId");
8279
8323
 
8280
8324
  function collectRefsInTemplate(template) {
8281
8325
  var refMap = new Map();
@@ -8374,7 +8418,8 @@ function lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context,
8374
8418
  var {
8375
8419
  bricks,
8376
8420
  proxy,
8377
- state
8421
+ state,
8422
+ contracts
8378
8423
  } = template;
8379
8424
 
8380
8425
  var {
@@ -8390,6 +8435,11 @@ function lowLevelExpandCustomTemplate(template, brickConf, proxyBrick, context,
8390
8435
  proxyBrick.proxy = proxyCopy;
8391
8436
  proxyBrick.proxyRefs = new Map();
8392
8437
  proxyBrick.stateNames = state === null || state === void 0 ? void 0 : state.map(item => item.name);
8438
+
8439
+ if (contracts) {
8440
+ collectWidgetContract(contracts);
8441
+ }
8442
+
8393
8443
  var refToBrickConf = collectRefsInTemplate(template); // Reversed proxies are used for expand storyboard before rendering page.
8394
8444
 
8395
8445
  var reversedProxies = {
@@ -9957,58 +10007,73 @@ function listenOnTrackingContext(brick, trackingContextList, context) {
9957
10007
  }
9958
10008
  }
9959
10009
 
9960
- function ExpandCustomForm(formData, brickConf, isPreview) {
9961
- var errorBrick = {
9962
- brick: "presentational-bricks.brick-illustration",
9963
- properties: {
9964
- category: "default",
9965
- header: {
9966
- title: "参数错误"
9967
- },
9968
- mode: "guide",
9969
- name: "search-empty"
10010
+ function ExpandCustomForm(_x, _x2, _x3, _x4) {
10011
+ return _ExpandCustomForm.apply(this, arguments);
10012
+ }
10013
+
10014
+ function _ExpandCustomForm() {
10015
+ _ExpandCustomForm = _asyncToGenerator$3(function* (formData, brickConf, isPreview, context) {
10016
+ var errorBrick = {
10017
+ brick: "presentational-bricks.brick-illustration",
10018
+ properties: {
10019
+ category: "default",
10020
+ header: {
10021
+ title: "参数错误"
10022
+ },
10023
+ mode: "guide",
10024
+ name: "search-empty"
10025
+ }
10026
+ };
10027
+ var formContext = new CustomFormContext();
10028
+
10029
+ if (Array.isArray(formData.context)) {
10030
+ yield formContext.formState.define(formData.context, _objectSpread(_objectSpread({}, context), {}, {
10031
+ formContextId: formContext.id
10032
+ }), {});
9970
10033
  }
9971
- };
9972
10034
 
9973
- try {
9974
- var formStoryboard = getStoryboard([formData.formSchema], [], formData.fields, isPreview);
9975
- formStoryboard[0] = _.isEmpty(formStoryboard[0]) ? errorBrick : formStoryboard[0];
9976
- return _objectSpread(_objectSpread({}, brickConf), {}, {
9977
- brick: "div",
9978
- slots: {
9979
- "": {
9980
- bricks: [{
9981
- brick: "basic-bricks.micro-view",
9982
- properties: {
9983
- style: {
9984
- padding: "12px"
9985
- }
9986
- },
9987
- slots: {
9988
- content: {
9989
- bricks: formStoryboard,
9990
- type: "bricks"
10035
+ try {
10036
+ var formStoryboard = getStoryboard([formData.formSchema], [], formData.fields, isPreview, formContext.id);
10037
+ formStoryboard[0] = _.isEmpty(formStoryboard[0]) ? errorBrick : formStoryboard[0];
10038
+ return _objectSpread(_objectSpread({}, brickConf), {}, {
10039
+ brick: "div",
10040
+ slots: {
10041
+ "": {
10042
+ bricks: [{
10043
+ brick: "basic-bricks.micro-view",
10044
+ properties: {
10045
+ style: {
10046
+ padding: "12px"
10047
+ }
10048
+ },
10049
+ slots: {
10050
+ content: {
10051
+ bricks: formStoryboard,
10052
+ type: "bricks"
10053
+ }
9991
10054
  }
9992
- }
9993
- }],
9994
- type: "bricks"
10055
+ }],
10056
+ type: "bricks"
10057
+ }
9995
10058
  }
9996
- }
9997
- });
9998
- } catch (error) {
9999
- // eslint-disable-next-line no-console
10000
- console.warn(error.message);
10001
- return {
10002
- brick: "div",
10003
- slots: {
10004
- "": {
10005
- bricks: [errorBrick],
10006
- type: "bricks"
10059
+ });
10060
+ } catch (error) {
10061
+ // eslint-disable-next-line no-console
10062
+ console.warn(error.message);
10063
+ return {
10064
+ brick: "div",
10065
+ slots: {
10066
+ "": {
10067
+ bricks: [errorBrick],
10068
+ type: "bricks"
10069
+ }
10007
10070
  }
10008
- }
10009
- };
10010
- }
10071
+ };
10072
+ }
10073
+ });
10074
+ return _ExpandCustomForm.apply(this, arguments);
10011
10075
  }
10076
+
10012
10077
  function getDefaultProperties(_name, fields) {
10013
10078
  var field = fields.filter(item => item.fieldId === _name)[0];
10014
10079
 
@@ -10241,7 +10306,7 @@ function getDefaultProperties(_name, fields) {
10241
10306
  return defaultValue;
10242
10307
  } else return {};
10243
10308
  }
10244
- function getStoryboard(datasource, result, fields, isPreview) {
10309
+ function getStoryboard(datasource, result, fields, isPreview, formContextId) {
10245
10310
  var _loop = function (i) {
10246
10311
  var dataItem = datasource[i];
10247
10312
  var resultItem = {}; //数据初始化:根据id,字段类型获取默认属性
@@ -10283,7 +10348,7 @@ function getStoryboard(datasource, result, fields, isPreview) {
10283
10348
  if (Array.isArray(dataItem.bricks)) {
10284
10349
  var _Object$keys;
10285
10350
 
10286
- resultItem["slots"] = _.groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview), "mountPoint");
10351
+ resultItem["slots"] = _.groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview, formContextId), "mountPoint");
10287
10352
  (_Object$keys = Object.keys(resultItem["slots"])) === null || _Object$keys === void 0 ? void 0 : _Object$keys.forEach(item => {
10288
10353
  resultItem.slots[item] = {
10289
10354
  bricks: resultItem.slots[item],
@@ -10292,6 +10357,9 @@ function getStoryboard(datasource, result, fields, isPreview) {
10292
10357
  });
10293
10358
  }
10294
10359
 
10360
+ resultItem = _objectSpread(_objectSpread({}, resultItem), {}, {
10361
+ [symbolForFormContextId]: formContextId
10362
+ });
10295
10363
  result[i] = resultItem;
10296
10364
  };
10297
10365
 
@@ -10348,7 +10416,8 @@ class LocationContext {
10348
10416
  getContext(_ref) {
10349
10417
  var {
10350
10418
  match,
10351
- tplContextId
10419
+ tplContextId,
10420
+ formContextId
10352
10421
  } = _ref;
10353
10422
  var auth = getAuth();
10354
10423
  var context = {
@@ -10368,7 +10437,8 @@ class LocationContext {
10368
10437
  flags: this.kernel.getFeatureFlags(),
10369
10438
  segues: this.segues,
10370
10439
  storyboardContext: this.storyboardContextWrapper.get(),
10371
- tplContextId
10440
+ tplContextId,
10441
+ formContextId
10372
10442
  };
10373
10443
  return context;
10374
10444
  }
@@ -10708,10 +10778,12 @@ class LocationContext {
10708
10778
 
10709
10779
  var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : [];
10710
10780
  var tplContextId = brickConf[symbolForTplContextId];
10781
+ var formContextId = brickConf[symbolForFormContextId];
10711
10782
 
10712
10783
  var context = _this6.getContext({
10713
10784
  match,
10714
- tplContextId
10785
+ tplContextId,
10786
+ formContextId
10715
10787
  }); // First, check whether the brick should be rendered.
10716
10788
 
10717
10789
 
@@ -10741,6 +10813,10 @@ class LocationContext {
10741
10813
  tplStack.push(tplTagName);
10742
10814
  }
10743
10815
 
10816
+ if (brickConf.brick === formRenderer) {
10817
+ brickConf.properties.formData = JSON.stringify(brickConf.properties.formData);
10818
+ }
10819
+
10744
10820
  var brick = {};
10745
10821
  yield _this6.storyboardContextWrapper.define(brickConf.context, context, brick);
10746
10822
  yield _this6.preCheckPermissions(brickConf, context);
@@ -10754,6 +10830,7 @@ class LocationContext {
10754
10830
  slotId,
10755
10831
  refForProxy: brickConf[symbolForRefForProxy],
10756
10832
  tplContextId,
10833
+ formContextId,
10757
10834
  iid: brickConf.iid
10758
10835
  }, (_brickConf$lifeCycle = brickConf.lifeCycle) !== null && _brickConf$lifeCycle !== void 0 && _brickConf$lifeCycle.onScrollIntoView ? {
10759
10836
  lifeCycle: {
@@ -10799,8 +10876,8 @@ class LocationContext {
10799
10876
  }
10800
10877
 
10801
10878
  if (brick.type === formRenderer) {
10802
- var formData = brick.properties.formData;
10803
- expandedBrickConf = ExpandCustomForm(formData, brickConf, brick.properties.isPreview);
10879
+ var formData = JSON.parse(brick.properties.formData);
10880
+ expandedBrickConf = yield ExpandCustomForm(formData, brickConf, brick.properties.isPreview, context);
10804
10881
  yield _this6.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10805
10882
  }
10806
10883
 
@@ -11867,6 +11944,7 @@ class Router {
11867
11944
  _this3.renderId = uniqueId("render-id-");
11868
11945
  resetAllInjected();
11869
11946
  clearPollTimeout();
11947
+ clearCollectWidgetContract();
11870
11948
 
11871
11949
  if (_this3.locationContext) {
11872
11950
  _this3.locationContext.resolver.resetRefreshQueue();