@cloudtower/eagle 0.31.17 → 0.31.19

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.
@@ -43,20 +43,22 @@ const TableFormBodyCell = (props) => {
43
43
  onChange,
44
44
  onBlur,
45
45
  validateAll,
46
- error
46
+ error,
47
+ onValidate
47
48
  } = props;
48
49
  const [validateResult, setValidateResult] = React.useState();
49
50
  const [isTouched, setIsTouched] = React.useState(false);
50
51
  const width = typeof column.width === "number" ? column.width + "px" : column.width;
51
52
  const isCellErrorStyle = Boolean((validateResult == null ? void 0 : validateResult.isError) || isRowError);
52
53
  React.useEffect(() => {
53
- if (isTouched)
54
+ if (isTouched) {
54
55
  setValidateResult(
55
56
  error ? {
56
57
  msg: error,
57
58
  isError: true
58
59
  } : void 0
59
60
  );
61
+ }
60
62
  }, [error, isTouched]);
61
63
  const triggerValidate = React.useCallback(
62
64
  (currentValue) => {
@@ -75,10 +77,11 @@ const TableFormBodyCell = (props) => {
75
77
  });
76
78
  const isError = result ? typeof result === "string" : false;
77
79
  setValidateResult({ msg: result || "", isError });
80
+ onValidate == null ? void 0 : onValidate(`${column.key}${rowIndex}`, !isError);
78
81
  return;
79
82
  }
80
83
  },
81
- [data, rowIndex, column, getRowValidateResult]
84
+ [data, rowIndex, column, getRowValidateResult, onValidate]
82
85
  );
83
86
  React.useEffect(() => {
84
87
  if (validateAll) {
@@ -84,7 +84,8 @@ const TableFormRow = (props) => {
84
84
  updateData,
85
85
  onBodyBlur,
86
86
  renderRowDescription,
87
- validateAll
87
+ validateAll,
88
+ onValidate
88
89
  } = props;
89
90
  const rowData = data[rowIndex];
90
91
  const errorFromProps = errors[rowIndex];
@@ -95,6 +96,9 @@ const TableFormRow = (props) => {
95
96
  React.useEffect(() => {
96
97
  setRowError(rowLevelError);
97
98
  }, [rowLevelError]);
99
+ React.useEffect(() => {
100
+ onValidate == null ? void 0 : onValidate(`table_row_${rowIndex}`, !rowError);
101
+ }, [onValidate, rowError, rowIndex]);
98
102
  const rowDeletable = typeof (row == null ? void 0 : row.deletable) === "boolean" ? row.deletable : (_a = typeof (row == null ? void 0 : row.deletable) === "function" || (deleteConfig == null ? void 0 : deleteConfig.deletable)) != null ? _a : false;
99
103
  const getRowValidateResult = React.useCallback(
100
104
  (rowData2) => {
@@ -124,7 +128,8 @@ const TableFormRow = (props) => {
124
128
  isRowError: !!rowError,
125
129
  getRowValidateResult,
126
130
  validateAll,
127
- error: cellError
131
+ error: cellError,
132
+ onValidate
128
133
  }
129
134
  );
130
135
  });
@@ -63,6 +63,7 @@ const TableForm = React__default.default.forwardRef(
63
63
  const [validateAll, setValidateAll] = React.useState(false);
64
64
  const rowSplitType = (row == null ? void 0 : row.splitType) || props.rowSplitType || "border";
65
65
  const draggable = (_b = (_a = row == null ? void 0 : row.draggable) != null ? _a : props.draggable) != null ? _b : false;
66
+ const formValidMapRef = React.useRef({});
66
67
  const updateData = React.useCallback(
67
68
  (value, rowIndex, columnKey) => {
68
69
  setLatestData(value);
@@ -107,11 +108,20 @@ const TableForm = React__default.default.forwardRef(
107
108
  updateData(data2);
108
109
  },
109
110
  validateWholeFields() {
111
+ formValidMapRef.current = {};
110
112
  setValidateAll(true);
113
+ },
114
+ isValid() {
115
+ return Object.values(formValidMapRef.current).every(
116
+ (v) => v === true
117
+ );
111
118
  }
112
119
  }),
113
120
  [updateData]
114
121
  );
122
+ const onValidate = (id, isValid) => {
123
+ formValidMapRef.current[id] = isValid;
124
+ };
115
125
  const headerCells = columns.map((col) => {
116
126
  return /* @__PURE__ */ React__default.default.createElement(
117
127
  TableFormHeaderCell.BatchInputListHeaderCell,
@@ -167,7 +177,8 @@ const TableForm = React__default.default.forwardRef(
167
177
  renderRowDescription,
168
178
  rowValidator,
169
179
  validateAll,
170
- errors
180
+ errors,
181
+ onValidate
171
182
  }
172
183
  ))
173
184
  ), (rowAddConfig == null ? void 0 : rowAddConfig.addible) ? /* @__PURE__ */ React__default.default.createElement(