@blueking/bkui-form 0.0.42-beta.10 → 0.0.42-beta.12

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.
@@ -1750,197 +1750,6 @@ var isExpression = function isExpression(expression) {
1750
1750
  return typeof expression === 'string' && /{{.*}}/.test(expression);
1751
1751
  };
1752
1752
 
1753
- var WidgetNode = /*#__PURE__*/function () {
1754
- function WidgetNode(config) {
1755
- _classCallCheck(this, WidgetNode);
1756
- this.id = void 0;
1757
- this.instance = void 0;
1758
- this.parent = void 0;
1759
- this.type = void 0;
1760
- this.index = void 0;
1761
- // todo
1762
- this.children = void 0;
1763
- var id = config.id,
1764
- instance = config.instance,
1765
- parent = config.parent,
1766
- index = config.index,
1767
- type = config.type,
1768
- _config$children = config.children,
1769
- children = _config$children === void 0 ? [] : _config$children;
1770
- this.id = id;
1771
- this.type = type;
1772
- this.index = index;
1773
- this.instance = instance;
1774
- this.parent = parent;
1775
- this.children = children;
1776
- }
1777
- // 当前node的值
1778
- return _createClass(WidgetNode, [{
1779
- key: "value",
1780
- get: function get() {
1781
- var _this$instance;
1782
- return (_this$instance = this.instance) === null || _this$instance === void 0 ? void 0 : _this$instance.value;
1783
- }
1784
- // 是否含有可见子节点
1785
- }, {
1786
- key: "isChildrenVisible",
1787
- get: function get() {
1788
- if (this.type === 'node') {
1789
- var _this$instance2;
1790
- return (_this$instance2 = this.instance) === null || _this$instance2 === void 0 ? void 0 : _this$instance2.state.visible;
1791
- }
1792
- return this.children.some(function (child) {
1793
- return child.isChildrenVisible;
1794
- });
1795
- }
1796
- /**
1797
- * 获取 parents
1798
- */
1799
- }, {
1800
- key: "parents",
1801
- get: function get() {
1802
- if (!this.parent) {
1803
- return [];
1804
- }
1805
- return [].concat(_toConsumableArray(this.parent.parents), [this.parent]);
1806
- }
1807
- // 第一个子节点
1808
- }, {
1809
- key: "firstChild",
1810
- get: function get() {
1811
- return this.children[0] || null;
1812
- }
1813
- // 最后一个子节点
1814
- }, {
1815
- key: "lastChild",
1816
- get: function get() {
1817
- return this.children[this.children.length - 1] || null;
1818
- }
1819
- // 指定属性下的同胞节点
1820
- }, {
1821
- key: "getSibling",
1822
- value: function getSibling(lastProp) {
1823
- var _this$parent;
1824
- var reg = new RegExp("".concat(Path.getPathLastProp(this.id) || '', "$"));
1825
- var id = this.id.replace(reg, lastProp);
1826
- return (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.children.find(function (node) {
1827
- return node.id === id;
1828
- });
1829
- }
1830
- // 获取所以同胞节点(不含自己)
1831
- }, {
1832
- key: "getSiblings",
1833
- value: function getSiblings() {
1834
- var _this$parent2,
1835
- _this = this;
1836
- return ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.children.filter(function (node) {
1837
- return node.instance !== _this.instance;
1838
- })) || [];
1839
- }
1840
- /**
1841
- * 是否是叶子节点
1842
- */
1843
- }, {
1844
- key: "isLeaf",
1845
- get: function get() {
1846
- return !this.children.length;
1847
- }
1848
- }, {
1849
- key: "appendChild",
1850
- value: function appendChild(node) {
1851
- var _this$children;
1852
- var nodes = Array.isArray(node) ? node : [node];
1853
- var offset = node.index !== undefined ? node.index : this.children.length;
1854
- (_this$children = this.children).splice.apply(_this$children, [offset, 0].concat(_toConsumableArray(nodes)));
1855
- this.children.slice(offset).forEach(function (node, index) {
1856
- node.index = offset + index;
1857
- });
1858
- return nodes;
1859
- }
1860
- }, {
1861
- key: "removeChild",
1862
- value: function removeChild(node) {
1863
- var _this2 = this;
1864
- var nodes = Array.isArray(node) ? node : [node];
1865
- var removedChildIndex = [];
1866
- nodes.forEach(function (node) {
1867
- var index = node.index;
1868
- removedChildIndex.push(index);
1869
- _this2.children.splice(index, 1);
1870
- });
1871
- var minIndex = Math.min.apply(Math, removedChildIndex);
1872
- this.children.slice(minIndex).forEach(function (node, index) {
1873
- node.index = minIndex + index;
1874
- });
1875
- return nodes;
1876
- }
1877
- }]);
1878
- }();
1879
- var WidgetTree = /*#__PURE__*/function () {
1880
- function WidgetTree() {
1881
- _classCallCheck(this, WidgetTree);
1882
- this.widgetMap = {};
1883
- }
1884
- return _createClass(WidgetTree, [{
1885
- key: "addWidgetNode",
1886
- value: function addWidgetNode(path, instance, type, index) {
1887
- if (path === '') {
1888
- // 根节点
1889
- var node = new WidgetNode({
1890
- id: '',
1891
- type: type,
1892
- index: index,
1893
- parent: null,
1894
- instance: instance,
1895
- children: []
1896
- });
1897
- this.widgetMap[path] = node;
1898
- } else {
1899
- // 普通节点
1900
- var parentId = Path.getParentPath(path);
1901
- var parentNode = this.widgetMap[parentId];
1902
- var _node = new WidgetNode({
1903
- id: (instance === null || instance === void 0 ? void 0 : instance.path) || path,
1904
- type: type,
1905
- index: index,
1906
- parent: parentNode,
1907
- instance: instance,
1908
- children: []
1909
- });
1910
- if (!parentNode) {
1911
- console.warn('Unexpected parent id, please check widget node', _node);
1912
- } else {
1913
- parentNode.appendChild(_node);
1914
- }
1915
- this.widgetMap[path] = _node;
1916
- }
1917
- }
1918
- }, {
1919
- key: "removeWidgetNode",
1920
- value: function removeWidgetNode(path, instance) {
1921
- var node = this.widgetMap[path];
1922
- if (node) {
1923
- if (node.parent) {
1924
- var children = node.parent.children;
1925
- var index = children.findIndex(function (item) {
1926
- return item.instance === instance;
1927
- });
1928
- if (index > -1) {
1929
- children.splice(index, 1);
1930
- children.slice(index).forEach(function (node, i) {
1931
- node.index = index + i;
1932
- });
1933
- }
1934
- }
1935
- if (node.instance === instance) {
1936
- delete this.widgetMap[path];
1937
- }
1938
- }
1939
- }
1940
- }]);
1941
- }();
1942
- var widgetTree = new WidgetTree();
1943
-
1944
1753
  var reactionsMap = {};
1945
1754
  var subscribe = function subscribe(path, typeName, fn) {
1946
1755
  if (!reactionsMap[path]) {
@@ -1972,7 +1781,7 @@ var subscribe = function subscribe(path, typeName, fn) {
1972
1781
  * @param reaction 传入的reacion配置
1973
1782
  * @returns viod
1974
1783
  */
1975
- var resolveReaction = function resolveReaction(crtInsPath, targetPath, reaction) {
1784
+ var resolveReaction = function resolveReaction(crtInsPath, targetPath, reaction, widgetTree) {
1976
1785
  return function () {
1977
1786
  var _ref = widgetTree.widgetMap[crtInsPath] || {},
1978
1787
  crtInstance = _ref.instance; // 当前组件实例,用来条件表达式判断
@@ -2017,6 +1826,7 @@ var parsePath = function parsePath(path, instance) {
2017
1826
  };
2018
1827
  var reactionRegister = function reactionRegister(path) {
2019
1828
  var reactions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1829
+ var widgetTree = arguments.length > 2 ? arguments[2] : undefined;
2020
1830
  var _ref3 = widgetTree.widgetMap[path] || {},
2021
1831
  instance = _ref3.instance;
2022
1832
  if (reactions && Array.isArray(reactions)) {
@@ -2028,13 +1838,13 @@ var reactionRegister = function reactionRegister(path) {
2028
1838
  subscribePaths.forEach(function (p) {
2029
1839
  var sourcePathItem = parsePath(p, instance);
2030
1840
  if (typeof reaction.lifetime === 'string') {
2031
- subscribe(sourcePathItem, "lifetime/".concat(reaction.lifetime), resolveReaction(path, targePath, reaction));
1841
+ subscribe(sourcePathItem, "lifetime/".concat(reaction.lifetime), resolveReaction(path, targePath, reaction, widgetTree));
2032
1842
  }
2033
1843
  if (typeof reaction.effect === 'string') {
2034
- subscribe(sourcePathItem, "effect/".concat(reaction.effect), resolveReaction(path, targePath, reaction));
1844
+ subscribe(sourcePathItem, "effect/".concat(reaction.effect), resolveReaction(path, targePath, reaction, widgetTree));
2035
1845
  }
2036
1846
  if (!reaction.lifetime && !reaction.effect) {
2037
- subscribe(sourcePathItem, 'valChange', resolveReaction(path, targePath, reaction));
1847
+ subscribe(sourcePathItem, 'valChange', resolveReaction(path, targePath, reaction, widgetTree));
2038
1848
  }
2039
1849
  });
2040
1850
  });
@@ -9768,7 +9578,7 @@ var validate = function validate(rule, instance) {
9768
9578
  };
9769
9579
  };
9770
9580
  // 设置表单项校验状态
9771
- var setWidgetErrorTips = function setWidgetErrorTips(path, isError, errorMsg) {
9581
+ var setWidgetErrorTips = function setWidgetErrorTips(path, isError, errorMsg, widgetTree) {
9772
9582
  var formItem = widgetTree.widgetMap[path];
9773
9583
  var instance = formItem.instance;
9774
9584
  if (formItem.type === 'node') {
@@ -9801,7 +9611,7 @@ var setWidgetErrorTips = function setWidgetErrorTips(path, isError, errorMsg) {
9801
9611
  * 校验单个表单项
9802
9612
  * @param path 字段路径
9803
9613
  */
9804
- var validateFormItem = function validateFormItem(path) {
9614
+ var validateFormItem = function validateFormItem(path, widgetTree) {
9805
9615
  var _instance$schema;
9806
9616
  // TODO 校验逻辑梳理
9807
9617
  var formItem = widgetTree.widgetMap[path];
@@ -9841,7 +9651,7 @@ var validateFormItem = function validateFormItem(path) {
9841
9651
  var errorsText = ajv.errorsText(schemaValidate.errors, {
9842
9652
  separator: '\n'
9843
9653
  });
9844
- setWidgetErrorTips(path, true, errorsText);
9654
+ setWidgetErrorTips(path, true, errorsText, widgetTree);
9845
9655
  return {
9846
9656
  result: false,
9847
9657
  message: errorsText,
@@ -9870,7 +9680,7 @@ var validateFormItem = function validateFormItem(path) {
9870
9680
  _iterator.f();
9871
9681
  }
9872
9682
  if (isError) {
9873
- setWidgetErrorTips(path, true, errorMsg);
9683
+ setWidgetErrorTips(path, true, errorMsg, widgetTree);
9874
9684
  return {
9875
9685
  result: false,
9876
9686
  message: errorMsg,
@@ -9886,24 +9696,24 @@ var validateFormItem = function validateFormItem(path) {
9886
9696
  /**
9887
9697
  * 校验整个表单
9888
9698
  */
9889
- var validateForm = function validateForm() {
9699
+ var validateForm = function validateForm(widgetTree) {
9890
9700
  var isValid = true;
9891
9701
  Object.keys(widgetTree.widgetMap).forEach(function (path) {
9892
9702
  var _validateFormItem;
9893
- if (!((_validateFormItem = validateFormItem(path)) !== null && _validateFormItem !== void 0 && _validateFormItem.result)) isValid = false;
9703
+ if (!((_validateFormItem = validateFormItem(path, widgetTree)) !== null && _validateFormItem !== void 0 && _validateFormItem.result)) isValid = false;
9894
9704
  });
9895
9705
  return isValid;
9896
9706
  };
9897
9707
  /**
9898
9708
  * 校验表单(抛出具体错误信息)
9899
9709
  */
9900
- var validateFormWithResult = function validateFormWithResult() {
9710
+ var validateFormWithResult = function validateFormWithResult(widgetTree) {
9901
9711
  return new Promise(function (resolve, reject) {
9902
9712
  var result = Object.keys(widgetTree.widgetMap).filter(function (path) {
9903
9713
  var _widgetTree$widgetMap;
9904
9714
  return ((_widgetTree$widgetMap = widgetTree.widgetMap[path]) === null || _widgetTree$widgetMap === void 0 ? void 0 : _widgetTree$widgetMap.type) === 'node';
9905
9715
  }).reduce(function (pre, path) {
9906
- var validateResult = validateFormItem(path);
9716
+ var validateResult = validateFormItem(path, widgetTree);
9907
9717
  if (!(validateResult !== null && validateResult !== void 0 && validateResult.result)) {
9908
9718
  pre.push(validateResult);
9909
9719
  }
@@ -9946,8 +9756,8 @@ var validateSchema = /*#__PURE__*/function () {
9946
9756
  * 触发校验
9947
9757
  * @param path 字段路径
9948
9758
  */
9949
- var dispatchValidate = function dispatchValidate(path) {
9950
- return validateFormItem(path);
9759
+ var dispatchValidate = function dispatchValidate(path, widgetTree) {
9760
+ return validateFormItem(path, widgetTree);
9951
9761
  };
9952
9762
 
9953
9763
  // 事件订阅器
@@ -10037,6 +9847,7 @@ var _excluded$4 = ["url", "params"],
10037
9847
  var Widget = Vue.extend({
10038
9848
  name: 'Widget',
10039
9849
  props: props,
9850
+ inject: ['widgetTree'],
10040
9851
  data: function data() {
10041
9852
  return {
10042
9853
  loading: false,
@@ -10055,10 +9866,10 @@ var Widget = Vue.extend({
10055
9866
  },
10056
9867
  computed: {
10057
9868
  widgetMap: function widgetMap() {
10058
- return widgetTree.widgetMap;
9869
+ return this.widgetTree.widgetMap;
10059
9870
  },
10060
9871
  widgetNode: function widgetNode() {
10061
- return widgetTree.widgetMap[this.path];
9872
+ return this.widgetTree.widgetMap[this.path];
10062
9873
  },
10063
9874
  parent: function parent() {
10064
9875
  var _this$widgetNode;
@@ -10076,7 +9887,7 @@ var Widget = Vue.extend({
10076
9887
  if (!deepEquals(newValue, oldValue)) {
10077
9888
  setTimeout(function () {
10078
9889
  reactionDispatch(_this.path, 'valChange');
10079
- dispatchValidate(_this.path);
9890
+ dispatchValidate(_this.path, _this.widgetTree);
10080
9891
  }, 0);
10081
9892
  }
10082
9893
  }
@@ -10108,17 +9919,17 @@ var Widget = Vue.extend({
10108
9919
  }
10109
9920
  });
10110
9921
  // 注册widget TreeNode
10111
- widgetTree.addWidgetNode(this.path, this, 'node');
9922
+ this.widgetTree.addWidgetNode(this.path, this, 'node');
10112
9923
  },
10113
9924
  mounted: function mounted() {
10114
9925
  // 注册联动
10115
- reactionRegister(this.path, this.widgetSchema['ui:reactions']);
9926
+ reactionRegister(this.path, this.widgetSchema['ui:reactions'], this.widgetTree);
10116
9927
  // 首次联动
10117
9928
  reactionDispatch(this.path, 'valChange');
10118
9929
  reactionDispatch(this.path, 'lifetime/init');
10119
9930
  },
10120
9931
  beforeDestroy: function beforeDestroy() {
10121
- widgetTree.removeWidgetNode(this.path, this);
9932
+ this.widgetTree.removeWidgetNode(this.path, this);
10122
9933
  reactionUnRegister(this.path);
10123
9934
  },
10124
9935
  methods: {
@@ -10939,6 +10750,7 @@ var getRowDefaultData = function getRowDefaultData() {
10939
10750
  var TableWidget = Vue.extend({
10940
10751
  name: 'TableWidget',
10941
10752
  props: props,
10753
+ inject: ['widgetTree'],
10942
10754
  watch: {
10943
10755
  value: {
10944
10756
  immediate: true,
@@ -10948,9 +10760,9 @@ var TableWidget = Vue.extend({
10948
10760
  (_this$value = this.value) === null || _this$value === void 0 ? void 0 : _this$value.forEach(function (_, index) {
10949
10761
  var path = "".concat(_this.path, ".").concat(index);
10950
10762
  // 销毁上一次的缓存
10951
- widgetTree.removeWidgetNode(path, null);
10763
+ _this.widgetTree.removeWidgetNode(path, null);
10952
10764
  // 重新当前行的父节点
10953
- widgetTree.addWidgetNode(path, null, 'group');
10765
+ _this.widgetTree.addWidgetNode(path, null, 'group');
10954
10766
  });
10955
10767
  }
10956
10768
  }
@@ -10997,7 +10809,19 @@ var TableWidget = Vue.extend({
10997
10809
  }
10998
10810
  var uiOptions = Schema.getUiOptions(schema);
10999
10811
  var getTableColumn = function getTableColumn() {
11000
- var VNodeList = Object.keys(properties).map(function (key) {
10812
+ // 表格列排序优先取 ui:order 属性里配置的顺序
10813
+ var colKeys = Object.keys(properties);
10814
+ var orders = (schemaItems === null || schemaItems === void 0 ? void 0 : schemaItems['ui:order']) || [];
10815
+ var orderMap = new Map();
10816
+ orders.forEach(function (key, index) {
10817
+ orderMap.set(key, index);
10818
+ });
10819
+ colKeys.sort(function (a, b) {
10820
+ var orderA = orderMap.has(a) ? orderMap.get(a) : Infinity;
10821
+ var orderB = orderMap.has(b) ? orderMap.get(b) : Infinity;
10822
+ return orderA - orderB;
10823
+ });
10824
+ var VNodeList = colKeys.map(function (key) {
11001
10825
  var _colField$uiProps, _colField$uiProps2;
11002
10826
  var colField = properties[key];
11003
10827
  // 仅支持基础数据类型的属性配置,render-header、sort-method、formatter等Function类型的属性不属于json支持的数据类型,配置将不会生效
@@ -11119,6 +10943,7 @@ var TableWidget = Vue.extend({
11119
10943
 
11120
10944
  var FieldGroupWrap = Vue.extend({
11121
10945
  name: 'FieldGroupWrap',
10946
+ inject: ['widgetTree'],
11122
10947
  props: _objectSpread2(_objectSpread2({}, props), {}, {
11123
10948
  // 组类型
11124
10949
  type: {
@@ -11158,14 +10983,14 @@ var FieldGroupWrap = Vue.extend({
11158
10983
  },
11159
10984
  created: function created() {
11160
10985
  // 注册widget TreeNode
11161
- widgetTree.addWidgetNode(this.path, this, 'group');
10986
+ this.widgetTree.addWidgetNode(this.path, this, 'group');
11162
10987
  },
11163
10988
  mounted: function mounted() {
11164
10989
  // 更新样式
11165
10990
  this.$forceUpdate();
11166
10991
  },
11167
10992
  beforeDestroy: function beforeDestroy() {
11168
- widgetTree.removeWidgetNode(this.path, this);
10993
+ this.widgetTree.removeWidgetNode(this.path, this);
11169
10994
  },
11170
10995
  methods: {
11171
10996
  setState: function setState(key, value) {
@@ -11701,6 +11526,197 @@ function styleInject(css, ref) {
11701
11526
  var css_248z = "";
11702
11527
  styleInject(css_248z);
11703
11528
 
11529
+ var WidgetNode = /*#__PURE__*/function () {
11530
+ function WidgetNode(config) {
11531
+ _classCallCheck(this, WidgetNode);
11532
+ this.id = void 0;
11533
+ this.instance = void 0;
11534
+ this.parent = void 0;
11535
+ this.type = void 0;
11536
+ this.index = void 0;
11537
+ // todo
11538
+ this.children = void 0;
11539
+ var id = config.id,
11540
+ instance = config.instance,
11541
+ parent = config.parent,
11542
+ index = config.index,
11543
+ type = config.type,
11544
+ _config$children = config.children,
11545
+ children = _config$children === void 0 ? [] : _config$children;
11546
+ this.id = id;
11547
+ this.type = type;
11548
+ this.index = index;
11549
+ this.instance = instance;
11550
+ this.parent = parent;
11551
+ this.children = children;
11552
+ }
11553
+ // 当前node的值
11554
+ return _createClass(WidgetNode, [{
11555
+ key: "value",
11556
+ get: function get() {
11557
+ var _this$instance;
11558
+ return (_this$instance = this.instance) === null || _this$instance === void 0 ? void 0 : _this$instance.value;
11559
+ }
11560
+ // 是否含有可见子节点
11561
+ }, {
11562
+ key: "isChildrenVisible",
11563
+ get: function get() {
11564
+ if (this.type === 'node') {
11565
+ var _this$instance2;
11566
+ return (_this$instance2 = this.instance) === null || _this$instance2 === void 0 ? void 0 : _this$instance2.state.visible;
11567
+ }
11568
+ return this.children.some(function (child) {
11569
+ return child.isChildrenVisible;
11570
+ });
11571
+ }
11572
+ /**
11573
+ * 获取 parents
11574
+ */
11575
+ }, {
11576
+ key: "parents",
11577
+ get: function get() {
11578
+ if (!this.parent) {
11579
+ return [];
11580
+ }
11581
+ return [].concat(_toConsumableArray(this.parent.parents), [this.parent]);
11582
+ }
11583
+ // 第一个子节点
11584
+ }, {
11585
+ key: "firstChild",
11586
+ get: function get() {
11587
+ return this.children[0] || null;
11588
+ }
11589
+ // 最后一个子节点
11590
+ }, {
11591
+ key: "lastChild",
11592
+ get: function get() {
11593
+ return this.children[this.children.length - 1] || null;
11594
+ }
11595
+ // 指定属性下的同胞节点
11596
+ }, {
11597
+ key: "getSibling",
11598
+ value: function getSibling(lastProp) {
11599
+ var _this$parent;
11600
+ var reg = new RegExp("".concat(Path.getPathLastProp(this.id) || '', "$"));
11601
+ var id = this.id.replace(reg, lastProp);
11602
+ return (_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.children.find(function (node) {
11603
+ return node.id === id;
11604
+ });
11605
+ }
11606
+ // 获取所以同胞节点(不含自己)
11607
+ }, {
11608
+ key: "getSiblings",
11609
+ value: function getSiblings() {
11610
+ var _this$parent2,
11611
+ _this = this;
11612
+ return ((_this$parent2 = this.parent) === null || _this$parent2 === void 0 ? void 0 : _this$parent2.children.filter(function (node) {
11613
+ return node.instance !== _this.instance;
11614
+ })) || [];
11615
+ }
11616
+ /**
11617
+ * 是否是叶子节点
11618
+ */
11619
+ }, {
11620
+ key: "isLeaf",
11621
+ get: function get() {
11622
+ return !this.children.length;
11623
+ }
11624
+ }, {
11625
+ key: "appendChild",
11626
+ value: function appendChild(node) {
11627
+ var _this$children;
11628
+ var nodes = Array.isArray(node) ? node : [node];
11629
+ var offset = node.index !== undefined ? node.index : this.children.length;
11630
+ (_this$children = this.children).splice.apply(_this$children, [offset, 0].concat(_toConsumableArray(nodes)));
11631
+ this.children.slice(offset).forEach(function (node, index) {
11632
+ node.index = offset + index;
11633
+ });
11634
+ return nodes;
11635
+ }
11636
+ }, {
11637
+ key: "removeChild",
11638
+ value: function removeChild(node) {
11639
+ var _this2 = this;
11640
+ var nodes = Array.isArray(node) ? node : [node];
11641
+ var removedChildIndex = [];
11642
+ nodes.forEach(function (node) {
11643
+ var index = node.index;
11644
+ removedChildIndex.push(index);
11645
+ _this2.children.splice(index, 1);
11646
+ });
11647
+ var minIndex = Math.min.apply(Math, removedChildIndex);
11648
+ this.children.slice(minIndex).forEach(function (node, index) {
11649
+ node.index = minIndex + index;
11650
+ });
11651
+ return nodes;
11652
+ }
11653
+ }]);
11654
+ }();
11655
+ var WidgetTree = /*#__PURE__*/function () {
11656
+ function WidgetTree() {
11657
+ _classCallCheck(this, WidgetTree);
11658
+ this.widgetMap = {};
11659
+ }
11660
+ return _createClass(WidgetTree, [{
11661
+ key: "addWidgetNode",
11662
+ value: function addWidgetNode(path, instance, type, index) {
11663
+ if (path === '') {
11664
+ // 根节点
11665
+ var node = new WidgetNode({
11666
+ id: '',
11667
+ type: type,
11668
+ index: index,
11669
+ parent: null,
11670
+ instance: instance,
11671
+ children: []
11672
+ });
11673
+ this.widgetMap[path] = node;
11674
+ } else {
11675
+ // 普通节点
11676
+ var parentId = Path.getParentPath(path);
11677
+ var parentNode = this.widgetMap[parentId];
11678
+ var _node = new WidgetNode({
11679
+ id: (instance === null || instance === void 0 ? void 0 : instance.path) || path,
11680
+ type: type,
11681
+ index: index,
11682
+ parent: parentNode,
11683
+ instance: instance,
11684
+ children: []
11685
+ });
11686
+ if (!parentNode) {
11687
+ console.warn('Unexpected parent id, please check widget node', _node);
11688
+ } else {
11689
+ parentNode.appendChild(_node);
11690
+ }
11691
+ this.widgetMap[path] = _node;
11692
+ }
11693
+ }
11694
+ }, {
11695
+ key: "removeWidgetNode",
11696
+ value: function removeWidgetNode(path, instance) {
11697
+ var node = this.widgetMap[path];
11698
+ if (node) {
11699
+ if (node.parent) {
11700
+ var children = node.parent.children;
11701
+ var index = children.findIndex(function (item) {
11702
+ return item.instance === instance;
11703
+ });
11704
+ if (index > -1) {
11705
+ children.splice(index, 1);
11706
+ children.slice(index).forEach(function (node, i) {
11707
+ node.index = index + i;
11708
+ });
11709
+ }
11710
+ }
11711
+ if (node.instance === instance) {
11712
+ delete this.widgetMap[path];
11713
+ }
11714
+ }
11715
+ }
11716
+ }]);
11717
+ }();
11718
+ // export default new WidgetTree();
11719
+
11704
11720
  var defaultOptions = {
11705
11721
  namespace: 'bk',
11706
11722
  components: {
@@ -11748,7 +11764,8 @@ function createForm() {
11748
11764
  data: function data() {
11749
11765
  return {
11750
11766
  rootData: {},
11751
- formKey: 'bk-ui-form'
11767
+ formKey: 'bk-ui-form',
11768
+ widgetTree: new WidgetTree()
11752
11769
  };
11753
11770
  },
11754
11771
  watch: {
@@ -11799,9 +11816,15 @@ function createForm() {
11799
11816
  this.$emit('change', newValue, oldValue);
11800
11817
  }
11801
11818
  },
11802
- validateForm: validateForm,
11803
- validateFormItem: validateFormItem,
11804
- validate: validateFormWithResult,
11819
+ validateForm: function validateForm$1() {
11820
+ return validateForm(this.widgetTree);
11821
+ },
11822
+ validateFormItem: function validateFormItem$1(path) {
11823
+ return validateFormItem(path, this.widgetTree);
11824
+ },
11825
+ validate: function validate() {
11826
+ return validateFormWithResult(this.widgetTree);
11827
+ },
11805
11828
  validateSchema: validateSchema
11806
11829
  },
11807
11830
  render: function render(h) {
@@ -11844,6 +11867,11 @@ function createForm() {
11844
11867
  }
11845
11868
  }
11846
11869
  })]);
11870
+ },
11871
+ provide: function provide() {
11872
+ return {
11873
+ widgetTree: this.widgetTree
11874
+ };
11847
11875
  }
11848
11876
  });
11849
11877
  }