@blueking/bkui-form 0.0.13 → 0.0.16

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.
@@ -924,6 +924,10 @@
924
924
  complete.splice.apply(complete, [restIndex, 1].concat(_toConsumableArray(rest)));
925
925
  return complete;
926
926
  }
927
+ function upperFirstLetter(str) {
928
+ if (!str) return str;
929
+ return "".concat(str.slice(0, 1).toUpperCase()).concat(str.slice(1));
930
+ }
927
931
 
928
932
  /**
929
933
  * Registry注册Form组件全局相关内容
@@ -1515,9 +1519,9 @@
1515
1519
  return group.reduce(function (area, rows) {
1516
1520
  var newRows = _this2.autoFillColumns(rows, gridTemplate.columns);
1517
1521
 
1518
- area += "\"".concat(newRows.join(' '), "\"\n");
1522
+ area.push("\"".concat(newRows.join(' '), "\""));
1519
1523
  return area;
1520
- }, '');
1524
+ }, []).join('\n');
1521
1525
  } // 当前列数不够时自动填充
1522
1526
 
1523
1527
  }, {
@@ -9821,15 +9825,27 @@
9821
9825
  */
9822
9826
 
9823
9827
  var validateFormWithResult = function validateFormWithResult() {
9824
- return Object.keys(widgetTree.widgetMap).reduce(function (pre, path) {
9825
- var validateResult = validateFormItem(path);
9828
+ return new Promise(function (resolve, reject) {
9829
+ var result = Object.keys(widgetTree.widgetMap).filter(function (path) {
9830
+ var _widgetTree$widgetMap;
9826
9831
 
9827
- if (!(validateResult !== null && validateResult !== void 0 && validateResult.result)) {
9828
- pre.push(validateResult);
9829
- }
9832
+ return ((_widgetTree$widgetMap = widgetTree.widgetMap[path]) === null || _widgetTree$widgetMap === void 0 ? void 0 : _widgetTree$widgetMap.type) === 'node';
9833
+ }).reduce(function (pre, path) {
9834
+ var validateResult = validateFormItem(path);
9835
+
9836
+ if (!(validateResult !== null && validateResult !== void 0 && validateResult.result)) {
9837
+ pre.push(validateResult);
9838
+ }
9830
9839
 
9831
- return pre;
9832
- }, []);
9840
+ return pre;
9841
+ }, []);
9842
+
9843
+ if (result.length) {
9844
+ reject(result);
9845
+ } else {
9846
+ resolve([]);
9847
+ }
9848
+ });
9833
9849
  }; // 校验schema是否正常
9834
9850
 
9835
9851
  var validateSchema = /*#__PURE__*/function () {
@@ -10115,6 +10131,7 @@
10115
10131
  _this$$scopedSlots$de,
10116
10132
  _this$$scopedSlots$de2,
10117
10133
  _this$$scopedSlots,
10134
+ _this$datasource,
10118
10135
  _this$datasource$find,
10119
10136
  _this4 = this,
10120
10137
  _this$$scopedSlots$su,
@@ -10159,7 +10176,7 @@
10159
10176
  attrs: _objectSpread2({}, this.state)
10160
10177
  }))); // 渲染默认readonly模式
10161
10178
 
10162
- var renderReadonlyWidget = h('div', [((_this$datasource$find = this.datasource.find(function (item) {
10179
+ var renderReadonlyWidget = h('div', [((_this$datasource = this.datasource) === null || _this$datasource === void 0 ? void 0 : (_this$datasource$find = _this$datasource.find(function (item) {
10163
10180
  return item.value === _this4.value;
10164
10181
  })) === null || _this$datasource$find === void 0 ? void 0 : _this$datasource$find.label) || this.value]); // 渲染删除按钮(用于数组类型widget删除)
10165
10182
 
@@ -10650,6 +10667,10 @@
10650
10667
  // 注册widget TreeNode
10651
10668
  widgetTree.addWidgetNode(this.path, this, 'group');
10652
10669
  },
10670
+ mounted: function mounted() {
10671
+ // 更新样式
10672
+ this.$forceUpdate();
10673
+ },
10653
10674
  beforeDestroy: function beforeDestroy() {
10654
10675
  widgetTree.removeWidgetNode(this.path, this);
10655
10676
  },
@@ -10662,6 +10683,43 @@
10662
10683
  },
10663
10684
  clearGroupErrorTips: function clearGroupErrorTips() {
10664
10685
  this.groupErrorTips = {};
10686
+ },
10687
+ removeEmptyRows: function removeEmptyRows(container) {
10688
+ var _this = this;
10689
+
10690
+ if (!container) return null;
10691
+ var newContainer = Object.keys(container).reduce(function (pre, key) {
10692
+ // 统一换成驼峰形势
10693
+ var humpKey = key.split('-').reduce(function (pre, str, index) {
10694
+ pre += index === 0 ? str : upperFirstLetter(str);
10695
+ return pre;
10696
+ }, '');
10697
+ pre[humpKey] = container[key];
10698
+ return pre;
10699
+ }, {});
10700
+ var oldGridTemplateAreas = newContainer.gridTemplateAreas,
10701
+ oldGridTemplateRows = newContainer.gridTemplateRows;
10702
+ var hiddenIndexs = [];
10703
+ var gridTemplateAreas = oldGridTemplateAreas === null || oldGridTemplateAreas === void 0 ? void 0 : oldGridTemplateAreas.split('\n').filter(function (row, index) {
10704
+ var hiddenRow = row.replace(/"/g, '').split(' ').every(function (name) {
10705
+ if (name === '.') return true;
10706
+ var fullPath = _this.path ? "".concat(_this.path, ".").concat(name) : name;
10707
+ return widgetTree.widgetMap[fullPath] && widgetTree.widgetMap[fullPath].type === 'node' && widgetTree.widgetMap[fullPath].instance && !widgetTree.widgetMap[fullPath].instance.state.visible;
10708
+ });
10709
+
10710
+ if (hiddenRow) {
10711
+ hiddenIndexs.push(index);
10712
+ }
10713
+
10714
+ return !hiddenRow;
10715
+ }).join('\n');
10716
+ var gridTemplateRows = oldGridTemplateRows === null || oldGridTemplateRows === void 0 ? void 0 : oldGridTemplateRows.split(' ').filter(function (_, index) {
10717
+ return !hiddenIndexs.includes(index);
10718
+ }).join(' ');
10719
+ return _objectSpread2(_objectSpread2({}, newContainer), {}, {
10720
+ gridTemplateAreas: gridTemplateAreas,
10721
+ gridTemplateRows: gridTemplateRows
10722
+ });
10665
10723
  }
10666
10724
  },
10667
10725
  render: function render(h) {
@@ -10669,14 +10727,14 @@
10669
10727
  _this$layout2,
10670
10728
  _this$schema,
10671
10729
  _this$layout3,
10672
- _this = this;
10730
+ _this2 = this;
10673
10731
 
10674
10732
  var schemaFormStyle = _objectSpread2({
10675
10733
  position: 'relative',
10676
10734
  border: this.border ? '1px solid #dcdee5' : 'none'
10677
10735
  }, ((_this$layout = this.layout) === null || _this$layout === void 0 ? void 0 : _this$layout.item) || {});
10678
10736
 
10679
- var groupContentStyle = _objectSpread2({}, ((_this$layout2 = this.layout) === null || _this$layout2 === void 0 ? void 0 : _this$layout2.container) || {
10737
+ var groupContentStyle = _objectSpread2({}, this.removeEmptyRows((_this$layout2 = this.layout) === null || _this$layout2 === void 0 ? void 0 : _this$layout2.container) || {
10680
10738
  display: 'grid',
10681
10739
  gridGap: '24px' // 未设置layout的布局组的默认样式
10682
10740
 
@@ -10703,7 +10761,7 @@
10703
10761
 
10704
10762
  var title = ((_this$schema = this.schema) === null || _this$schema === void 0 ? void 0 : _this$schema.title) || ((_this$layout3 = this.layout) === null || _this$layout3 === void 0 ? void 0 : _this$layout3.prop);
10705
10763
  var groupErrorTipsContent = Object.keys(this.groupErrorTips).map(function (widgetPath) {
10706
- return h("p", [_this.groupErrorTips[widgetPath]]);
10764
+ return h("p", [_this2.groupErrorTips[widgetPath]]);
10707
10765
  });
10708
10766
  var hasError = JSON.stringify(this.groupErrorTips) !== '{}';
10709
10767
  return h("div", {
@@ -10726,8 +10784,8 @@
10726
10784
 
10727
10785
  function _extends(){return _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_extends.apply(this,arguments)}var normalMerge=["attrs","props","domProps"],toArrayMerge=["class","style","directives"],functionalMerge=["on","nativeOn"],mergeJsxProps=function(a){return a.reduce(function(c,a){for(var b in a)if(!c[b])c[b]=a[b];else if(-1!==normalMerge.indexOf(b))c[b]=_extends({},c[b],a[b]);else if(-1!==toArrayMerge.indexOf(b)){var d=c[b]instanceof Array?c[b]:[c[b]],e=a[b]instanceof Array?a[b]:[a[b]];c[b]=d.concat(e);}else if(-1!==functionalMerge.indexOf(b)){for(var f in a[b])if(c[b][f]){var g=c[b][f]instanceof Array?c[b][f]:[c[b][f]],h=a[b][f]instanceof Array?a[b][f]:[a[b][f]];c[b][f]=g.concat(h);}else c[b][f]=a[b][f];}else if("hook"==b)for(var i in a[b])c[b][i]=c[b][i]?mergeFn(c[b][i],a[b][i]):a[b][i];else c[b]=a[b];return c},{})},mergeFn=function(a,b){return function(){a&&a.apply(this,arguments),b&&b.apply(this,arguments);}};var helper=mergeJsxProps;
10728
10786
 
10729
- var NoTitleArray = Vue__default["default"].extend({
10730
- name: 'NoTitleArray',
10787
+ var KeyValueArrayWidget = Vue__default["default"].extend({
10788
+ name: 'ArrayWidget',
10731
10789
  props: _objectSpread2({}, props),
10732
10790
  mounted: function mounted() {
10733
10791
  var _this$value;
@@ -10841,6 +10899,8 @@
10841
10899
  container: _objectSpread2({}, defaultContainerLayout)
10842
10900
  })
10843
10901
  })
10902
+ }, {
10903
+ "class": "mb10"
10844
10904
  }]), [props !== null && props !== void 0 && props.length ? props.map(function (prop) {
10845
10905
  var _this$schema3, _this$schema3$items;
10846
10906
 
@@ -10873,8 +10933,7 @@
10873
10933
  "on": {
10874
10934
  "click": this.handleAddItem
10875
10935
  },
10876
- "style": labelBtnStyle,
10877
- "class": "mt10"
10936
+ "style": labelBtnStyle
10878
10937
  }, [h("i", {
10879
10938
  "class": "bk-icon icon-plus-line"
10880
10939
  })])]);
@@ -11116,13 +11175,23 @@
11116
11175
  }
11117
11176
  });
11118
11177
 
11119
- var UnitInputWidget = Vue__default["default"].extend({
11120
- name: 'UnitInput',
11178
+ var InputWidget = Vue__default["default"].extend({
11179
+ name: 'InputWidget',
11121
11180
  props: {
11122
11181
  value: [String, Number],
11123
11182
  unit: {
11124
11183
  type: String,
11125
11184
  default: ''
11185
+ },
11186
+ maxRows: {
11187
+ type: Number,
11188
+ default: 0
11189
+ }
11190
+ },
11191
+ computed: {
11192
+ rows: function rows() {
11193
+ var len = String(this.value).split('\n').length;
11194
+ return len <= this.maxRows ? len : this.maxRows;
11126
11195
  }
11127
11196
  },
11128
11197
  methods: {
@@ -11133,11 +11202,14 @@
11133
11202
  render: function render(h) {
11134
11203
  return h(registry.getBaseWidget('input'), {
11135
11204
  props: _objectSpread2({
11136
- value: this.value
11205
+ value: this.value,
11206
+ rows: this.rows,
11207
+ type: this.maxRows > 1 ? 'textarea' : 'text'
11137
11208
  }, this.$attrs),
11138
11209
  on: {
11139
11210
  input: this.handleInput
11140
- }
11211
+ },
11212
+ class: ['bk-form-unit-input']
11141
11213
  }, [this.unit && h('div', {
11142
11214
  slot: 'append',
11143
11215
  class: ['group-text']
@@ -11184,12 +11256,12 @@
11184
11256
  checkbox: CheckboxWidget,
11185
11257
  table: TableWidget,
11186
11258
  group: FieldGroupWrap,
11187
- noTitleArray: NoTitleArray,
11259
+ bfArray: KeyValueArrayWidget,
11188
11260
  tab: TabGroupWidget,
11189
11261
  collapse: CollapseGroupWidget,
11190
11262
  switcher: SwitcherWidget,
11191
11263
  color: ColorWidget,
11192
- unitInput: UnitInputWidget,
11264
+ bfInput: InputWidget,
11193
11265
  input: 'bk-input'
11194
11266
  },
11195
11267
  fields: {