@cloudtower/eagle 0.22.40 → 0.23.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/umd/index.js CHANGED
@@ -3620,6 +3620,15 @@
3620
3620
  ) : void 0);
3621
3621
  };
3622
3622
 
3623
+ const CheckboxColumnHeaderCell = ({ onChange }) => {
3624
+ const _onChange = React.useCallback(
3625
+ (e) => {
3626
+ onChange(e.target.checked, true);
3627
+ },
3628
+ [onChange]
3629
+ );
3630
+ return /* @__PURE__ */ React.createElement(antd.Checkbox, { onChange: _onChange });
3631
+ };
3623
3632
  const CheckboxColumnBodyCell = ({ data, column, index, onChange }) => {
3624
3633
  const value = data[index][column.key] === void 0 ? column.defaultValue : data[index][column.key];
3625
3634
  const _onChange = React.useCallback(
@@ -3757,11 +3766,7 @@
3757
3766
  column.subTitle
3758
3767
  );
3759
3768
  };
3760
- const TextColumnBodyCell = ({
3761
- data,
3762
- column,
3763
- index
3764
- }) => {
3769
+ const TextColumnBodyCell = ({ data, column, index }) => {
3765
3770
  const text = column.displayText || data[index][column.key];
3766
3771
  const CellDescription = React.useMemo(() => {
3767
3772
  var _a, _b;
@@ -3790,7 +3795,7 @@
3790
3795
  input: InputColumnHeaderCell,
3791
3796
  password: InputColumnHeaderCell,
3792
3797
  affix: AffixColumnHeaderCell,
3793
- checkbox: TextColumnHeaderCell
3798
+ checkbox: CheckboxColumnHeaderCell
3794
3799
  };
3795
3800
  const ColumnBodyImpls = {
3796
3801
  text: TextColumnBodyCell,
@@ -3810,10 +3815,17 @@
3810
3815
  return /* @__PURE__ */React.createElement(antd.Form.Item, {
3811
3816
  className: FormItemStyle,
3812
3817
  validateStatus,
3813
- help: validateStatus ? message : ""
3818
+ help: validateStatus && message ? message : void 0
3814
3819
  }, children);
3815
3820
  };
3816
3821
 
3822
+ var ValidateTriggerType = /* @__PURE__ */ ((ValidateTriggerType2) => {
3823
+ ValidateTriggerType2[ValidateTriggerType2["Normal"] = 0] = "Normal";
3824
+ ValidateTriggerType2[ValidateTriggerType2["Aggressive"] = 1] = "Aggressive";
3825
+ ValidateTriggerType2[ValidateTriggerType2["Lazy"] = 2] = "Lazy";
3826
+ return ValidateTriggerType2;
3827
+ })(ValidateTriggerType || {});
3828
+
3817
3829
  var __defProp$5 = Object.defineProperty;
3818
3830
  var __defProps$5 = Object.defineProperties;
3819
3831
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
@@ -3836,40 +3848,77 @@
3836
3848
  const TableFormBodyCell = (props) => {
3837
3849
  const {
3838
3850
  column,
3839
- disabled,
3840
3851
  index: rowIndex,
3841
3852
  data,
3842
- onChange,
3843
3853
  latestData,
3854
+ validateTriggerType,
3844
3855
  isRowError,
3845
- onBlur
3856
+ getRowValidateResult,
3857
+ disabled,
3858
+ onChange,
3859
+ onBlur,
3860
+ validateAll
3846
3861
  } = props;
3862
+ const [validateResult, setValidateResult] = React.useState();
3863
+ const isTouched = React.useRef(false);
3847
3864
  const width = typeof column.width === "number" ? column.width + "px" : column.width;
3848
- const _onChange = React.useCallback(
3849
- (value, data2) => {
3850
- const newData = data2.map(
3851
- (row, i) => i === rowIndex ? __spreadProps$5(__spreadValues$5({}, row), { [column.key]: value }) : row
3852
- );
3853
- onChange == null ? void 0 : onChange(newData, rowIndex, column.key);
3865
+ const triggerValidate = React.useCallback(
3866
+ (currentValue) => {
3867
+ var _a;
3868
+ const value = currentValue || data[rowIndex][column.key];
3869
+ const rowData = __spreadProps$5(__spreadValues$5({}, data[rowIndex]), { [column.key]: value });
3870
+ const rowValidateRes = getRowValidateResult(rowData);
3871
+ if (rowValidateRes) {
3872
+ return;
3873
+ }
3874
+ const result = (_a = column.validator) == null ? void 0 : _a.call(column, {
3875
+ value,
3876
+ rowIndex,
3877
+ rowData: data[rowIndex]
3878
+ });
3879
+ const isError = result ? typeof result === "string" : false;
3880
+ setValidateResult({ msg: result || "", isError });
3854
3881
  },
3855
- [rowIndex, onChange, column]
3882
+ [data, column, rowIndex, getRowValidateResult]
3856
3883
  );
3884
+ React.useEffect(() => {
3885
+ if (validateAll) {
3886
+ isTouched.current = true;
3887
+ triggerValidate();
3888
+ }
3889
+ }, [validateAll, triggerValidate]);
3890
+ const _onChange = (value, data2) => {
3891
+ const newData = data2.map(
3892
+ (row, i) => i === rowIndex ? __spreadProps$5(__spreadValues$5({}, row), { [column.key]: value }) : row
3893
+ );
3894
+ onChange == null ? void 0 : onChange(newData, rowIndex, column.key);
3895
+ if (validateTriggerType === ValidateTriggerType.Normal && isTouched.current || validateTriggerType === ValidateTriggerType.Aggressive) {
3896
+ triggerValidate(value);
3897
+ }
3898
+ };
3857
3899
  const _onBlur = React.useCallback(() => {
3900
+ isTouched.current = true;
3901
+ triggerValidate();
3858
3902
  onBlur == null ? void 0 : onBlur(data, rowIndex, column.key);
3859
- }, [rowIndex, column, onBlur, data]);
3903
+ }, [rowIndex, column, onBlur, data, triggerValidate]);
3860
3904
  const renderDefaultComponent = () => {
3861
3905
  if (!column.type)
3862
3906
  return null;
3863
3907
  const CellComponent = ColumnBodyImpls[column.type];
3864
3908
  return /* @__PURE__ */ React.createElement(
3865
3909
  CellComponent,
3866
- __spreadProps$5(__spreadValues$5({}, props), {
3867
- customData: column.customData,
3910
+ {
3911
+ disabled,
3912
+ data,
3913
+ index: rowIndex,
3914
+ latestData,
3915
+ column,
3916
+ visible: props.visible,
3868
3917
  onChange: (val) => {
3869
3918
  _onChange(val, data);
3870
3919
  },
3871
3920
  onBlur: _onBlur
3872
- })
3921
+ }
3873
3922
  );
3874
3923
  };
3875
3924
  const Cell = column.render ? column.render({
@@ -3894,24 +3943,6 @@
3894
3943
  })) || null;
3895
3944
  return typeof Result === "string" ? /* @__PURE__ */ React.createElement("p", { className: core.cx(Typo.Label.l4_regular, "cell-description") }, Result) : Result;
3896
3945
  }, [rowIndex, data, latestData, column]);
3897
- const validateResult = React.useMemo(() => {
3898
- var _a;
3899
- if (isRowError) {
3900
- return {
3901
- msg: "",
3902
- isError: true
3903
- };
3904
- }
3905
- const value = data[rowIndex][column.key];
3906
- const result = (_a = column.validator) == null ? void 0 : _a.call(column, {
3907
- value,
3908
- rowIndex,
3909
- rowData: data[rowIndex]
3910
- });
3911
- if (typeof result === "string" && result) {
3912
- return { msg: result, isError: true };
3913
- }
3914
- }, [data, column, rowIndex, isRowError]);
3915
3946
  return /* @__PURE__ */ React.createElement(
3916
3947
  "div",
3917
3948
  {
@@ -3925,8 +3956,8 @@
3925
3956
  /* @__PURE__ */ React.createElement(
3926
3957
  FormItem,
3927
3958
  {
3928
- validateStatus: (validateResult == null ? void 0 : validateResult.isError) ? "error" : "",
3929
- message: (validateResult == null ? void 0 : validateResult.isError) && validateResult.msg ? validateResult.msg : void 0
3959
+ validateStatus: isRowError || (validateResult == null ? void 0 : validateResult.isError) ? "error" : "",
3960
+ message: isRowError ? "" : validateResult == null ? void 0 : validateResult.msg
3930
3961
  },
3931
3962
  Cell
3932
3963
  ),
@@ -3960,24 +3991,35 @@
3960
3991
  latestData,
3961
3992
  disabled,
3962
3993
  passwordVisible,
3963
- deletable,
3994
+ deleteConfig,
3964
3995
  draggable,
3965
3996
  rowIndex,
3966
3997
  provided,
3967
3998
  snapshot,
3999
+ validateTriggerType = ValidateTriggerType.Normal,
3968
4000
  updateData,
3969
4001
  onBodyBlur,
3970
4002
  renderRowDescription,
3971
- rowValidator
4003
+ rowValidator,
4004
+ validateAll
3972
4005
  } = props;
3973
4006
  const rowData = data[rowIndex];
3974
- const deleteRow = (index, data2) => {
3975
- const newData = [...data2];
3976
- newData.splice(index, 1);
3977
- updateData(newData);
3978
- };
3979
- const getRowActions = (index, rowDeletable) => {
3980
- const isRowDeleteDisabled = rowDeletable === false;
4007
+ const [rowError, setRowError] = React.useState();
4008
+ const deleteRow = React.useCallback(
4009
+ (index, data2) => {
4010
+ const newData = [...data2];
4011
+ newData.splice(index, 1);
4012
+ updateData(newData);
4013
+ },
4014
+ [updateData]
4015
+ );
4016
+ const RowActions = React.useMemo(() => {
4017
+ var _a;
4018
+ const isRowDeleteDisabled = (_a = deleteConfig == null ? void 0 : deleteConfig.specifyRowDeleteDisabled) == null ? void 0 : _a.call(
4019
+ deleteConfig,
4020
+ rowIndex,
4021
+ data
4022
+ );
3981
4023
  const DeleteIcon = /* @__PURE__ */ React.createElement(
3982
4024
  Icon,
3983
4025
  {
@@ -3987,20 +4029,21 @@
3987
4029
  onClick: () => {
3988
4030
  if (isRowDeleteDisabled)
3989
4031
  return;
3990
- deleteRow(index, data);
4032
+ deleteRow(rowIndex, data);
3991
4033
  }
3992
4034
  }
3993
4035
  );
3994
4036
  const FinalRenderIcon = isRowDeleteDisabled ? DeleteIcon : /* @__PURE__ */ React.createElement(Tooltip, { title: parrot.parrotI18n.t("components.remove") }, DeleteIcon);
3995
- return deletable ? [FinalRenderIcon] : void 0;
3996
- };
3997
- const RowValidateResult = React.useMemo(() => {
3998
- const result = rowValidator == null ? void 0 : rowValidator(rowIndex, data[rowIndex]);
3999
- if (typeof result === "string" && result) {
4000
- return /* @__PURE__ */ React.createElement("p", { className: core.cx(Typo.Label.l4_regular, "row-error-message") }, result);
4001
- }
4002
- return null;
4003
- }, [rowValidator, rowIndex, data]);
4037
+ return (deleteConfig == null ? void 0 : deleteConfig.deletable) ? [FinalRenderIcon] : void 0;
4038
+ }, [rowIndex, deleteConfig, data, deleteRow]);
4039
+ const getRowValidateResult = React.useCallback(
4040
+ (rowData2) => {
4041
+ const result = rowValidator == null ? void 0 : rowValidator(rowIndex, rowData2);
4042
+ setRowError(result);
4043
+ return result;
4044
+ },
4045
+ [rowValidator, rowIndex]
4046
+ );
4004
4047
  const Cells = columns.map((col) => {
4005
4048
  return /* @__PURE__ */ React.createElement(
4006
4049
  TableFormBodyCell,
@@ -4014,7 +4057,10 @@
4014
4057
  onChange: updateData,
4015
4058
  onBlur: onBodyBlur,
4016
4059
  visible: passwordVisible,
4017
- isRowError: !!RowValidateResult
4060
+ validateTriggerType,
4061
+ isRowError: !!rowError,
4062
+ getRowValidateResult,
4063
+ validateAll
4018
4064
  }
4019
4065
  );
4020
4066
  });
@@ -4044,11 +4090,11 @@
4044
4090
  "eagle-table-form-row",
4045
4091
  (snapshot == null ? void 0 : snapshot.isDragging) && "isDragging"
4046
4092
  ),
4047
- actions: getRowActions(rowIndex, rowData.deletable)
4093
+ actions: RowActions
4048
4094
  },
4049
4095
  DraggableHandle,
4050
4096
  Cells,
4051
- RowValidateResult,
4097
+ rowError ? /* @__PURE__ */ React.createElement("p", { className: core.cx(Typo.Label.l4_regular, "row-error-message") }, rowError) : null,
4052
4098
  RowDescription
4053
4099
  );
4054
4100
  };
@@ -4116,7 +4162,7 @@
4116
4162
  const [errMsg, setErrMsg] = React.useState();
4117
4163
  const width = Number.isNaN(Number(column.width)) ? column.width : column.width + "px";
4118
4164
  const headerOnChange = React.useCallback(
4119
- (value) => {
4165
+ (value, shouldUpdateData = false) => {
4120
4166
  var _a;
4121
4167
  const err = (_a = column.validator) == null ? void 0 : _a.call(column, { value, isHeader: true });
4122
4168
  setErrMsg(err || void 0);
@@ -4126,7 +4172,7 @@
4126
4172
  [column.key]: shouldAutoIncrease && typeof value === "string" ? increaseLastNumber(value, rowIndex) : value
4127
4173
  });
4128
4174
  });
4129
- onChange == null ? void 0 : onChange(newData, column.key);
4175
+ onChange == null ? void 0 : onChange(newData, column.key, shouldUpdateData);
4130
4176
  },
4131
4177
  [onChange, data, column]
4132
4178
  );
@@ -4162,14 +4208,14 @@
4162
4208
  visibility: column.hidden ? "hidden" : "visible"
4163
4209
  }
4164
4210
  },
4165
- /* @__PURE__ */ React.createElement(
4211
+ /* @__PURE__ */ React.createElement("p", { className: core.cx(Typo.Label.l3_bold_title, TitleStyle) }, column.title),
4212
+ disableBatchFilling ? null : /* @__PURE__ */ React.createElement(
4166
4213
  FormItem,
4167
4214
  {
4168
4215
  validateStatus: typeof errMsg === "string" && errMsg ? "error" : "",
4169
4216
  message: errMsg || void 0
4170
4217
  },
4171
- /* @__PURE__ */ React.createElement("p", { className: core.cx(Typo.Label.l3_bold_title, TitleStyle) }, column.title),
4172
- disableBatchFilling ? null : renderCell()
4218
+ renderCell()
4173
4219
  )
4174
4220
  );
4175
4221
  };
@@ -4196,16 +4242,18 @@
4196
4242
  const DEFAULT_ROW_COUNT = 3;
4197
4243
  const TableForm = React.forwardRef(
4198
4244
  ({
4199
- defaultData,
4245
+ defaultData = [],
4200
4246
  columns,
4201
4247
  disabled,
4202
4248
  rowAddConfig,
4203
- deletable,
4249
+ deleteConfig,
4204
4250
  size = "default",
4205
4251
  className,
4206
4252
  draggable,
4207
4253
  disableBatchFilling = false,
4208
4254
  rowSplitType = "border",
4255
+ validateTriggerType,
4256
+ maxHeight,
4209
4257
  renderRowDescription,
4210
4258
  rowValidator,
4211
4259
  onHeaderChange,
@@ -4213,12 +4261,10 @@
4213
4261
  onBodyChange,
4214
4262
  onBodyBlur
4215
4263
  }, ref) => {
4216
- const treatedDefaultData = React.useMemo(() => {
4217
- return defaultData || [...Array(DEFAULT_ROW_COUNT)].map(() => genEmptyRow(columns));
4218
- }, [defaultData, columns]);
4219
- const [data, setData] = React.useState(treatedDefaultData);
4264
+ const [data, setData] = React.useState(defaultData);
4220
4265
  const [passwordVisible, setPasswordVisible] = React.useState(false);
4221
- const [latestData, setLatestData] = React.useState(treatedDefaultData);
4266
+ const [latestData, setLatestData] = React.useState(defaultData);
4267
+ const [validateAll, setValidateAll] = React.useState(false);
4222
4268
  const updateData = React.useCallback(
4223
4269
  (value, rowIndex, columnKey) => {
4224
4270
  setLatestData(value);
@@ -4227,12 +4273,23 @@
4227
4273
  },
4228
4274
  [onBodyChange]
4229
4275
  );
4276
+ React.useLayoutEffect(() => {
4277
+ if (defaultData.length === 0) {
4278
+ updateData(
4279
+ [...Array(DEFAULT_ROW_COUNT)].map(() => genEmptyRow(columns))
4280
+ );
4281
+ }
4282
+ }, []);
4230
4283
  const handleBatchChange = React.useCallback(
4231
- (newData, columnKey) => {
4284
+ (newData, columnKey, shouldUpdateData) => {
4232
4285
  setLatestData(newData);
4233
4286
  onHeaderChange == null ? void 0 : onHeaderChange(newData, columnKey);
4287
+ if (shouldUpdateData) {
4288
+ setData(newData);
4289
+ onBodyChange == null ? void 0 : onBodyChange(newData, void 0, columnKey);
4290
+ }
4234
4291
  },
4235
- [onHeaderChange]
4292
+ [onHeaderChange, onBodyChange]
4236
4293
  );
4237
4294
  const handleBatchBlur = React.useCallback(
4238
4295
  (key, error) => {
@@ -4257,6 +4314,9 @@
4257
4314
  () => ({
4258
4315
  setData: (data2) => {
4259
4316
  updateData(data2);
4317
+ },
4318
+ validateWholeFields() {
4319
+ setValidateAll(true);
4260
4320
  }
4261
4321
  }),
4262
4322
  [updateData]
@@ -4277,31 +4337,46 @@
4277
4337
  }
4278
4338
  );
4279
4339
  });
4280
- return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(TableFormWrapper, { className: `table-form row-split-by-${rowSplitType}` }, /* @__PURE__ */ React.createElement(antd.List, { size, className: `size-${size}` }, /* @__PURE__ */ React.createElement(
4281
- antd.List.Item,
4340
+ const tableFormWrapperStyle = React.useMemo(
4341
+ () => maxHeight ? {
4342
+ maxHeight: typeof maxHeight === "number" ? maxHeight + "px" : maxHeight
4343
+ } : void 0,
4344
+ []
4345
+ );
4346
+ return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement(
4347
+ TableFormWrapper,
4282
4348
  {
4283
- className: "eagle-table-form-header",
4284
- actions: deletable ? [/* @__PURE__ */ React.createElement(React.Fragment, null)] : void 0
4349
+ className: `table-form row-split-by-${rowSplitType}`,
4350
+ style: tableFormWrapperStyle
4285
4351
  },
4286
- draggable ? /* @__PURE__ */ React.createElement(DraggableHandleWrapper, null) : null,
4287
- headerCells
4288
- ), /* @__PURE__ */ React.createElement(
4289
- TableFormBodyRows,
4290
- {
4291
- data,
4292
- latestData,
4293
- columns,
4294
- passwordVisible,
4295
- deletable,
4296
- disabled,
4297
- draggable,
4298
- rowSplitType,
4299
- onBodyBlur,
4300
- updateData,
4301
- renderRowDescription,
4302
- rowValidator
4303
- }
4304
- ))), (rowAddConfig == null ? void 0 : rowAddConfig.addible) ? /* @__PURE__ */ React.createElement(
4352
+ /* @__PURE__ */ React.createElement(antd.List, { size, className: `size-${size}` }, /* @__PURE__ */ React.createElement(
4353
+ antd.List.Item,
4354
+ {
4355
+ className: "eagle-table-form-header",
4356
+ actions: (deleteConfig == null ? void 0 : deleteConfig.deletable) ? [/* @__PURE__ */ React.createElement(React.Fragment, null)] : void 0
4357
+ },
4358
+ draggable ? /* @__PURE__ */ React.createElement(DraggableHandleWrapper, null) : null,
4359
+ headerCells
4360
+ ), /* @__PURE__ */ React.createElement(
4361
+ TableFormBodyRows,
4362
+ {
4363
+ data,
4364
+ latestData,
4365
+ columns,
4366
+ passwordVisible,
4367
+ deleteConfig,
4368
+ disabled,
4369
+ draggable,
4370
+ rowSplitType,
4371
+ validateTriggerType,
4372
+ onBodyBlur,
4373
+ updateData,
4374
+ renderRowDescription,
4375
+ rowValidator,
4376
+ validateAll
4377
+ }
4378
+ ))
4379
+ ), (rowAddConfig == null ? void 0 : rowAddConfig.addible) ? /* @__PURE__ */ React.createElement(
4305
4380
  AddRowButton,
4306
4381
  {
4307
4382
  config: rowAddConfig,
@@ -4409,7 +4484,7 @@
4409
4484
  input: {}
4410
4485
  }, defaultTz ? /* @__PURE__ */React.createElement(antd.Select.Option, {
4411
4486
  value: DefaultTimeValue,
4412
- label: parrot.parrotI18n.t("components.default_time_zone"),
4487
+ label: `${parrot.parrotI18n.t("components.default_time_zone")} (${getUTCOffsetText(defaultTz.offset)})`,
4413
4488
  className: OptionWrapperStyle
4414
4489
  }, /* @__PURE__ */React.createElement(TimeZoneOption, {
4415
4490
  key: DefaultTimeValue,
@@ -4417,7 +4492,7 @@
4417
4492
  timeZone: defaultTz
4418
4493
  })) : void 0, /* @__PURE__ */React.createElement(antd.Select.Option, {
4419
4494
  value: BrowserTimeValue,
4420
- label: parrot.parrotI18n.t("components.browser_time_zone"),
4495
+ label: `${parrot.parrotI18n.t("components.browser_time_zone")} (${getUTCOffsetText(browserTz.offset)})`,
4421
4496
  className: OptionWrapperStyle
4422
4497
  }, /* @__PURE__ */React.createElement(TimeZoneOption, {
4423
4498
  key: BrowserTimeValue,
@@ -4437,18 +4512,20 @@
4437
4512
  }
4438
4513
  })), timeZoneOptionGroups);
4439
4514
  };
4515
+ function getUTCOffsetText(offset) {
4516
+ if (offset === 0) {
4517
+ return "UTC";
4518
+ } else if (offset < 0) {
4519
+ return `UTC${offset}:00`;
4520
+ } else {
4521
+ return `UTC+${offset}:00`;
4522
+ }
4523
+ }
4440
4524
  const TimeZoneOption = ({
4441
4525
  timeZone,
4442
4526
  customLabel
4443
4527
  }) => {
4444
- let tagText = "";
4445
- if (timeZone.offset === 0) {
4446
- tagText = "UTC";
4447
- } else if (timeZone.offset < 0) {
4448
- tagText = `UTC${timeZone.offset}:00`;
4449
- } else {
4450
- tagText = `UTC+${timeZone.offset}:00`;
4451
- }
4528
+ let tagText = getUTCOffsetText(timeZone.offset);
4452
4529
  return /* @__PURE__ */React.createElement(React.Fragment, null, /* @__PURE__ */React.createElement("div", {
4453
4530
  className: OptionFirstLineStyle
4454
4531
  }, /* @__PURE__ */React.createElement("span", {
@@ -4726,6 +4803,7 @@
4726
4803
  exports.UIKitProvider = UIKitProvider;
4727
4804
  exports.UIKitStore = UIKitStore;
4728
4805
  exports.UserSource = UserSource;
4806
+ exports.ValidateTriggerType = ValidateTriggerType;
4729
4807
  exports.antdKit = antdKit;
4730
4808
  exports.closeModal = closeModal;
4731
4809
  exports.createBatchMessageMethods = createBatchMessageMethods;