@next-core/brick-kit 2.136.1 → 2.136.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.136.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.1...@next-core/brick-kit@2.136.2) (2022-09-06)
7
+
8
+ **Note:** Version bump only for package @next-core/brick-kit
9
+
10
+
11
+
12
+
13
+
6
14
  ## [2.136.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.0...@next-core/brick-kit@2.136.1) (2022-09-05)
7
15
 
8
16
 
@@ -2343,6 +2343,22 @@
2343
2343
  });
2344
2344
  var getMedia = () => MEDIA;
2345
2345
 
2346
+ var FormContextMap = new Map();
2347
+ class CustomFormContext {
2348
+ constructor() {
2349
+ _defineProperty__default["default"](this, "formState", void 0);
2350
+
2351
+ _defineProperty__default["default"](this, "id", _.uniqueId("form-ctx-"));
2352
+
2353
+ FormContextMap.set(this.id, this);
2354
+ this.formState = new StoryboardContextWrapper();
2355
+ }
2356
+
2357
+ }
2358
+ function getCustomFormContext(formContextId) {
2359
+ return FormContextMap.get(formContextId);
2360
+ }
2361
+
2346
2362
  var symbolForRaw = Symbol.for("pre.evaluated.raw");
2347
2363
  var symbolForContext = Symbol.for("pre.evaluated.context");
2348
2364
  function isPreEvaluated(raw) {
@@ -2415,6 +2431,7 @@
2415
2431
  var attemptToVisitData = attemptToVisitGlobals.has("DATA");
2416
2432
  var attemptToVisitTpl = attemptToVisitGlobals.has("TPL");
2417
2433
  var attemptToVisitState = attemptToVisitGlobals.has("STATE");
2434
+ var attemptToVisitFormState = attemptToVisitGlobals.has("FORM_STATE");
2418
2435
  var attemptToVisitTplOrState = attemptToVisitTpl || attemptToVisitState; // Ignore evaluating if `event` is missing in context.
2419
2436
  // Since it should be evaluated during events handling.
2420
2437
 
@@ -2466,6 +2483,20 @@
2466
2483
  }
2467
2484
  }
2468
2485
 
2486
+ if (attemptToVisitFormState && runtimeContext.formContextId) {
2487
+ var formContext = getCustomFormContext(runtimeContext.formContextId);
2488
+ globalVariables.FORM_STATE = getDynamicReadOnlyProxy({
2489
+ get(target, key) {
2490
+ return formContext.formState.getValue(key);
2491
+ },
2492
+
2493
+ ownKeys() {
2494
+ return Array.from(formContext.formState.get().keys());
2495
+ }
2496
+
2497
+ });
2498
+ }
2499
+
2469
2500
  var {
2470
2501
  app: currentApp,
2471
2502
  query,
@@ -2919,7 +2950,7 @@
2919
2950
 
2920
2951
  if (preEvaluated || brickUtils.isEvaluable(value)) {
2921
2952
  var runtimeContext = {};
2922
- var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace"];
2953
+ var keys = ["event", "tplContextId", "overrideApp", "appendI18nNamespace", "formContextId"];
2923
2954
 
2924
2955
  for (var key of keys) {
2925
2956
  if (context !== null && context !== void 0 && context[key]) {
@@ -8275,6 +8306,7 @@
8275
8306
 
8276
8307
  var formRenderer = "form-renderer.form-renderer";
8277
8308
  var filterProperties = ["instanceId", "brick", "slots", "properties", "events", "if", "context", "bricks", "mountPoint"];
8309
+ var symbolForFormContextId = Symbol.for("form.contextId");
8278
8310
 
8279
8311
  function collectRefsInTemplate(template) {
8280
8312
  var refMap = new Map();
@@ -9956,58 +9988,73 @@
9956
9988
  }
9957
9989
  }
9958
9990
 
9959
- function ExpandCustomForm(formData, brickConf, isPreview) {
9960
- var errorBrick = {
9961
- brick: "presentational-bricks.brick-illustration",
9962
- properties: {
9963
- category: "default",
9964
- header: {
9965
- title: "参数错误"
9966
- },
9967
- mode: "guide",
9968
- name: "search-empty"
9991
+ function ExpandCustomForm(_x, _x2, _x3, _x4) {
9992
+ return _ExpandCustomForm.apply(this, arguments);
9993
+ }
9994
+
9995
+ function _ExpandCustomForm() {
9996
+ _ExpandCustomForm = _asyncToGenerator__default["default"](function* (formData, brickConf, isPreview, context) {
9997
+ var errorBrick = {
9998
+ brick: "presentational-bricks.brick-illustration",
9999
+ properties: {
10000
+ category: "default",
10001
+ header: {
10002
+ title: "参数错误"
10003
+ },
10004
+ mode: "guide",
10005
+ name: "search-empty"
10006
+ }
10007
+ };
10008
+ var formContext = new CustomFormContext();
10009
+
10010
+ if (Array.isArray(formData.context)) {
10011
+ yield formContext.formState.define(formData.context, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
10012
+ formContextId: formContext.id
10013
+ }), {});
9969
10014
  }
9970
- };
9971
10015
 
9972
- try {
9973
- var formStoryboard = getStoryboard([formData.formSchema], [], formData.fields, isPreview);
9974
- formStoryboard[0] = ___default["default"].isEmpty(formStoryboard[0]) ? errorBrick : formStoryboard[0];
9975
- return _objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
9976
- brick: "div",
9977
- slots: {
9978
- "": {
9979
- bricks: [{
9980
- brick: "basic-bricks.micro-view",
9981
- properties: {
9982
- style: {
9983
- padding: "12px"
9984
- }
9985
- },
9986
- slots: {
9987
- content: {
9988
- bricks: formStoryboard,
9989
- type: "bricks"
10016
+ try {
10017
+ var formStoryboard = getStoryboard([formData.formSchema], [], formData.fields, isPreview, formContext.id);
10018
+ formStoryboard[0] = ___default["default"].isEmpty(formStoryboard[0]) ? errorBrick : formStoryboard[0];
10019
+ return _objectSpread__default["default"](_objectSpread__default["default"]({}, brickConf), {}, {
10020
+ brick: "div",
10021
+ slots: {
10022
+ "": {
10023
+ bricks: [{
10024
+ brick: "basic-bricks.micro-view",
10025
+ properties: {
10026
+ style: {
10027
+ padding: "12px"
10028
+ }
10029
+ },
10030
+ slots: {
10031
+ content: {
10032
+ bricks: formStoryboard,
10033
+ type: "bricks"
10034
+ }
9990
10035
  }
9991
- }
9992
- }],
9993
- type: "bricks"
10036
+ }],
10037
+ type: "bricks"
10038
+ }
9994
10039
  }
9995
- }
9996
- });
9997
- } catch (error) {
9998
- // eslint-disable-next-line no-console
9999
- console.warn(error.message);
10000
- return {
10001
- brick: "div",
10002
- slots: {
10003
- "": {
10004
- bricks: [errorBrick],
10005
- type: "bricks"
10040
+ });
10041
+ } catch (error) {
10042
+ // eslint-disable-next-line no-console
10043
+ console.warn(error.message);
10044
+ return {
10045
+ brick: "div",
10046
+ slots: {
10047
+ "": {
10048
+ bricks: [errorBrick],
10049
+ type: "bricks"
10050
+ }
10006
10051
  }
10007
- }
10008
- };
10009
- }
10052
+ };
10053
+ }
10054
+ });
10055
+ return _ExpandCustomForm.apply(this, arguments);
10010
10056
  }
10057
+
10011
10058
  function getDefaultProperties(_name, fields) {
10012
10059
  var field = fields.filter(item => item.fieldId === _name)[0];
10013
10060
 
@@ -10240,7 +10287,7 @@
10240
10287
  return defaultValue;
10241
10288
  } else return {};
10242
10289
  }
10243
- function getStoryboard(datasource, result, fields, isPreview) {
10290
+ function getStoryboard(datasource, result, fields, isPreview, formContextId) {
10244
10291
  var _loop = function (i) {
10245
10292
  var dataItem = datasource[i];
10246
10293
  var resultItem = {}; //数据初始化:根据id,字段类型获取默认属性
@@ -10282,7 +10329,7 @@
10282
10329
  if (Array.isArray(dataItem.bricks)) {
10283
10330
  var _Object$keys;
10284
10331
 
10285
- resultItem["slots"] = ___default["default"].groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview), "mountPoint");
10332
+ resultItem["slots"] = ___default["default"].groupBy(getStoryboard(dataItem.bricks, [], fields, isPreview, formContextId), "mountPoint");
10286
10333
  (_Object$keys = Object.keys(resultItem["slots"])) === null || _Object$keys === void 0 ? void 0 : _Object$keys.forEach(item => {
10287
10334
  resultItem.slots[item] = {
10288
10335
  bricks: resultItem.slots[item],
@@ -10291,6 +10338,9 @@
10291
10338
  });
10292
10339
  }
10293
10340
 
10341
+ resultItem = _objectSpread__default["default"](_objectSpread__default["default"]({}, resultItem), {}, {
10342
+ [symbolForFormContextId]: formContextId
10343
+ });
10294
10344
  result[i] = resultItem;
10295
10345
  };
10296
10346
 
@@ -10347,7 +10397,8 @@
10347
10397
  getContext(_ref) {
10348
10398
  var {
10349
10399
  match,
10350
- tplContextId
10400
+ tplContextId,
10401
+ formContextId
10351
10402
  } = _ref;
10352
10403
  var auth = getAuth();
10353
10404
  var context = {
@@ -10367,7 +10418,8 @@
10367
10418
  flags: this.kernel.getFeatureFlags(),
10368
10419
  segues: this.segues,
10369
10420
  storyboardContext: this.storyboardContextWrapper.get(),
10370
- tplContextId
10421
+ tplContextId,
10422
+ formContextId
10371
10423
  };
10372
10424
  return context;
10373
10425
  }
@@ -10707,10 +10759,12 @@
10707
10759
 
10708
10760
  var tplStack = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : [];
10709
10761
  var tplContextId = brickConf[symbolForTplContextId];
10762
+ var formContextId = brickConf[symbolForFormContextId];
10710
10763
 
10711
10764
  var context = _this6.getContext({
10712
10765
  match,
10713
- tplContextId
10766
+ tplContextId,
10767
+ formContextId
10714
10768
  }); // First, check whether the brick should be rendered.
10715
10769
 
10716
10770
 
@@ -10740,6 +10794,10 @@
10740
10794
  tplStack.push(tplTagName);
10741
10795
  }
10742
10796
 
10797
+ if (brickConf.brick === formRenderer) {
10798
+ brickConf.properties.formData = JSON.stringify(brickConf.properties.formData);
10799
+ }
10800
+
10743
10801
  var brick = {};
10744
10802
  yield _this6.storyboardContextWrapper.define(brickConf.context, context, brick);
10745
10803
  yield _this6.preCheckPermissions(brickConf, context);
@@ -10753,6 +10811,7 @@
10753
10811
  slotId,
10754
10812
  refForProxy: brickConf[symbolForRefForProxy],
10755
10813
  tplContextId,
10814
+ formContextId,
10756
10815
  iid: brickConf.iid
10757
10816
  }, (_brickConf$lifeCycle = brickConf.lifeCycle) !== null && _brickConf$lifeCycle !== void 0 && _brickConf$lifeCycle.onScrollIntoView ? {
10758
10817
  lifeCycle: {
@@ -10798,8 +10857,8 @@
10798
10857
  }
10799
10858
 
10800
10859
  if (brick.type === formRenderer) {
10801
- var formData = brick.properties.formData;
10802
- expandedBrickConf = ExpandCustomForm(formData, brickConf, brick.properties.isPreview);
10860
+ var formData = JSON.parse(brick.properties.formData);
10861
+ expandedBrickConf = yield ExpandCustomForm(formData, brickConf, brick.properties.isPreview, context);
10803
10862
  yield _this6.kernel.loadDynamicBricksInBrickConf(expandedBrickConf);
10804
10863
  }
10805
10864