@sustaina/shared-ui 1.70.8 → 1.80.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/index.js CHANGED
@@ -5543,77 +5543,6 @@ var DatePicker2 = (props) => {
5543
5543
  // src/components/advanceSearch/components/constants/index.ts
5544
5544
  var fallbackShortDateFormat = "DD/MM/YYYY";
5545
5545
  var UUIDregex = /^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$/i;
5546
- var RANGE_START_ERROR = "Start value must be before end value.";
5547
- var RANGE_END_ERROR = "End value must be after start value.";
5548
- var RANGE_VALIDATED_TYPES = ["date", "datetime", "datemonth"];
5549
- var sanitizeInput = (val) => {
5550
- if (!val) return val;
5551
- if (Array.isArray(val)) {
5552
- return val.map((v) => sanitizeInput(v));
5553
- }
5554
- if (val.includes("\n") || val.includes("\r") || /[\u2028\u2029]/u.test(val))
5555
- return "__INVALID_NEWLINE__";
5556
- if (/\\\\/.test(val)) return "__INVALID_ESCAPE__";
5557
- if (/\\(n|t|r|b|f|u[0-9a-fA-F]{4})/.test(val)) return "__INVALID_ESCAPE__";
5558
- if (/\p{Cf}/u.test(val)) return "__INVALID_UNICODE_WHITESPACE__";
5559
- if (/[\u00A0\u1680\u180E\u202F\u205F\u3000]/u.test(val)) return "__INVALID_UNICODE_WHITESPACE__";
5560
- const trimmed = val.trim();
5561
- if (/^\{.*\}$/s.test(trimmed) || /^\[.*\]$/s.test(trimmed)) return "__INVALID_JSON_LITERAL__";
5562
- if (/\\\{/.test(val) || /\\\}/.test(val)) return "__INVALID_JSON_ESCAPE__";
5563
- if (/[%*~^]/.test(trimmed)) return "__INVALID_WILDCARD__";
5564
- if (/[%><={}\\[\]"']/u.test(trimmed)) return "__INVALID_CHAR__";
5565
- if (/\p{Cc}/u.test(val)) return "__INVALID_CONTROL_CHAR__";
5566
- return val;
5567
- };
5568
- var numericTypes = ["number"];
5569
- var dateTypes = ["date", "datemonth"];
5570
- var validateByFieldType = (value, fieldType) => {
5571
- if (!value) return { valid: true };
5572
- if (Array.isArray(value)) {
5573
- return { valid: true };
5574
- }
5575
- if (numericTypes.includes(fieldType)) {
5576
- if (!/^-?\d+(\.\d+)?$/.test(value)) {
5577
- return { valid: false, message: "Please enter a valid number." };
5578
- }
5579
- }
5580
- if (fieldType === "uuid") {
5581
- if (!UUIDregex.test(value)) {
5582
- return { valid: false, message: "Please enter a valid UUID." };
5583
- }
5584
- }
5585
- if (dateTypes.includes(fieldType)) {
5586
- const normalized = fieldType === "datemonth" ? `${value}-01` : value;
5587
- const parsed = dateFns.parseISO(normalized);
5588
- if (!dateFns.isValid(parsed)) {
5589
- return { valid: false, message: "Invalid date format." };
5590
- }
5591
- }
5592
- return { valid: true };
5593
- };
5594
- var parseRangeValue = (raw, fieldType) => {
5595
- if (!raw) return void 0;
5596
- const normalized = fieldType === "datemonth" ? `${raw}-01` : raw;
5597
- const parsed = dateFns.parseISO(normalized);
5598
- return dateFns.isValid(parsed) ? parsed : void 0;
5599
- };
5600
- var validateDateRange = (which, row, formValues) => {
5601
- if (row.operator !== "between" || !RANGE_VALIDATED_TYPES.includes(row.fieldType)) return true;
5602
- const start = formValues[`value_${row.id}`];
5603
- const end = formValues[`value2_${row.id}`];
5604
- if (typeof start !== "string" || typeof end !== "string" || !start || !end) return true;
5605
- const d1 = parseRangeValue(start, row.fieldType);
5606
- const d2 = parseRangeValue(end, row.fieldType);
5607
- if (d1 && d2 && dateFns.isAfter(d1, d2)) {
5608
- return which === "value" ? RANGE_START_ERROR : RANGE_END_ERROR;
5609
- }
5610
- return true;
5611
- };
5612
- var buildValueRules = (which, row) => ({
5613
- required: "This field is required.",
5614
- validate: (_value, formValues) => validateDateRange(which, row, formValues),
5615
- deps: [which === "value" ? `value2_${row.id}` : `value_${row.id}`]
5616
- });
5617
5546
  var ConditionDateInput = ({
5618
5547
  row,
5619
5548
  control,
@@ -5637,9 +5566,8 @@ var ConditionDateInput = ({
5637
5566
  {
5638
5567
  control,
5639
5568
  name: fieldName,
5640
- rules: buildValueRules(which, row),
5569
+ rules: { required: "This field is required." },
5641
5570
  render: ({ field, fieldState }) => {
5642
- const { value: fieldValue, ...fieldRest } = field;
5643
5571
  const handleValueChange = (next) => {
5644
5572
  field.onChange(next ?? void 0);
5645
5573
  if (!next) {
@@ -5650,8 +5578,8 @@ var ConditionDateInput = ({
5650
5578
  /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
5651
5579
  DatePicker2,
5652
5580
  {
5653
- ...fieldRest,
5654
- value: fieldValue || void 0,
5581
+ ...field,
5582
+ value: field.value || void 0,
5655
5583
  onValueChange: handleValueChange,
5656
5584
  placeholder: dateFormat,
5657
5585
  ariaLabel: buildAriaLabel(options?.isEnd),
@@ -6160,10 +6088,9 @@ var ConditionMonthInput = ({ row, control, onClear }) => {
6160
6088
  {
6161
6089
  control,
6162
6090
  name: fieldName,
6163
- rules: buildValueRules(which, row),
6091
+ rules: { required: "This field is required." },
6164
6092
  render: ({ field, fieldState }) => {
6165
- const { value: fieldValue, ...fieldRest } = field;
6166
- const value = fieldValue || void 0;
6093
+ const value = field.value || void 0;
6167
6094
  const handleValueChange = (next) => {
6168
6095
  field.onChange(next ?? void 0);
6169
6096
  if (!next) {
@@ -6174,7 +6101,7 @@ var ConditionMonthInput = ({ row, control, onClear }) => {
6174
6101
  /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
6175
6102
  MonthPicker2,
6176
6103
  {
6177
- ...fieldRest,
6104
+ ...field,
6178
6105
  value,
6179
6106
  onValueChange: handleValueChange,
6180
6107
  placeholder,
@@ -8721,6 +8648,51 @@ function transformFilterKeys(obj, fieldMap = FILTER_FIELD_MAP) {
8721
8648
  }
8722
8649
  return obj;
8723
8650
  }
8651
+ var sanitizeInput = (val) => {
8652
+ if (!val) return val;
8653
+ if (Array.isArray(val)) {
8654
+ return val.map((v) => sanitizeInput(v));
8655
+ }
8656
+ if (val.includes("\n") || val.includes("\r") || /[\u2028\u2029]/u.test(val))
8657
+ return "__INVALID_NEWLINE__";
8658
+ if (/\\\\/.test(val)) return "__INVALID_ESCAPE__";
8659
+ if (/\\(n|t|r|b|f|u[0-9a-fA-F]{4})/.test(val)) return "__INVALID_ESCAPE__";
8660
+ if (/\p{Cf}/u.test(val)) return "__INVALID_UNICODE_WHITESPACE__";
8661
+ if (/[\u00A0\u1680\u180E\u202F\u205F\u3000]/u.test(val)) return "__INVALID_UNICODE_WHITESPACE__";
8662
+ const trimmed = val.trim();
8663
+ if (/^\{.*\}$/s.test(trimmed) || /^\[.*\]$/s.test(trimmed)) return "__INVALID_JSON_LITERAL__";
8664
+ if (/\\\{/.test(val) || /\\\}/.test(val)) return "__INVALID_JSON_ESCAPE__";
8665
+ if (/[%*~^]/.test(trimmed)) return "__INVALID_WILDCARD__";
8666
+ if (/[%><={}\\[\]"']/u.test(trimmed)) return "__INVALID_CHAR__";
8667
+ if (/\p{Cc}/u.test(val)) return "__INVALID_CONTROL_CHAR__";
8668
+ return val;
8669
+ };
8670
+ var numericTypes = ["number"];
8671
+ var dateTypes = ["date", "datemonth"];
8672
+ var validateByFieldType = (value, fieldType) => {
8673
+ if (!value) return { valid: true };
8674
+ if (Array.isArray(value)) {
8675
+ return { valid: true };
8676
+ }
8677
+ if (numericTypes.includes(fieldType)) {
8678
+ if (!/^-?\d+(\.\d+)?$/.test(value)) {
8679
+ return { valid: false, message: "Please enter a valid number." };
8680
+ }
8681
+ }
8682
+ if (fieldType === "uuid") {
8683
+ if (!UUIDregex.test(value)) {
8684
+ return { valid: false, message: "Please enter a valid UUID." };
8685
+ }
8686
+ }
8687
+ if (dateTypes.includes(fieldType)) {
8688
+ const normalized = fieldType === "datemonth" ? `${value}-01` : value;
8689
+ const parsed = dateFns.parseISO(normalized);
8690
+ if (!dateFns.isValid(parsed)) {
8691
+ return { valid: false, message: "Invalid date format." };
8692
+ }
8693
+ }
8694
+ return { valid: true };
8695
+ };
8724
8696
  var AdvanceSearch = ({
8725
8697
  fields,
8726
8698
  portalId,
@@ -8773,6 +8745,13 @@ var AdvanceSearch = ({
8773
8745
  },
8774
8746
  [resetField, clearErrors]
8775
8747
  );
8748
+ const parseRangeValue = React.useCallback((raw, fieldType) => {
8749
+ if (!raw) return void 0;
8750
+ if (Array.isArray(raw)) return void 0;
8751
+ const normalized = fieldType === "datemonth" ? `${raw}-01` : raw;
8752
+ const parsed = dateFns.parseISO(normalized);
8753
+ return dateFns.isValid(parsed) ? parsed : void 0;
8754
+ }, []);
8776
8755
  const onSubmit = React.useCallback(() => {
8777
8756
  const operatorValidation = {};
8778
8757
  rows.forEach((r) => {
@@ -8816,6 +8795,16 @@ var AdvanceSearch = ({
8816
8795
  setError(endField, { type: "validate", message: valid2.message });
8817
8796
  return null;
8818
8797
  }
8798
+ if (v1 && v2 && ["date", "datemonth"].includes(r.fieldType)) {
8799
+ const d1 = parseRangeValue(v1, r.fieldType);
8800
+ const d2 = parseRangeValue(v2, r.fieldType);
8801
+ if (d1 && d2 && dateFns.isAfter(d1, d2)) {
8802
+ hasError = true;
8803
+ setError(startField, { type: "validate", message: "Start value must be before end value." });
8804
+ setError(endField, { type: "validate", message: "End value must be after start value." });
8805
+ return null;
8806
+ }
8807
+ }
8819
8808
  return { ...r, value: v1, value2: v2 };
8820
8809
  }
8821
8810
  return { ...r, value: v1 };
@@ -8845,6 +8834,7 @@ var AdvanceSearch = ({
8845
8834
  rows,
8846
8835
  operatorsForField,
8847
8836
  getValues,
8837
+ parseRangeValue,
8848
8838
  setError,
8849
8839
  setOperatorErrors,
8850
8840
  filterFieldMap,
@@ -13884,8 +13874,8 @@ var GridSettingsModal = ({
13884
13874
  }
13885
13875
  }, [isOpen, currentColumns, form]);
13886
13876
  const addColumn = async () => {
13887
- const isValid6 = await trigger("columns");
13888
- if (isValid6) {
13877
+ const isValid7 = await trigger("columns");
13878
+ if (isValid7) {
13889
13879
  append({ id: "" });
13890
13880
  requestAnimationFrame(() => {
13891
13881
  const container = scrollRef.current;