@sustaina/shared-ui 1.30.2 → 1.31.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.mjs CHANGED
@@ -652,7 +652,8 @@ var OPERATOR_MAP = {
652
652
  dropdown: ["is", "isNot"],
653
653
  lookup: ["containsAny", "containsOnly", "containsAll", "notContains"],
654
654
  uuid: ["equals", "notEquals", "gt", "gte", "lt", "lte"],
655
- json: ["equals", "notEquals", "containsAny"]
655
+ json: ["equals", "notEquals"]
656
+ // removed containsAny from json
656
657
  };
657
658
 
658
659
  // src/components/advanceSearch/hooks/useAdvanceSearch.ts
@@ -699,7 +700,8 @@ function makeNewRow(field) {
699
700
  operator: op,
700
701
  value: "",
701
702
  multiTableSearch: field.multiTableSearch,
702
- lookupFieldName: field.lookupFieldName
703
+ lookupFieldName: field.lookupFieldName,
704
+ allowRegex: field.type === "text" ? field.allowRegex : void 0
703
705
  };
704
706
  }
705
707
  function useAdvanceSearch({ fields, limitRows }) {
@@ -742,7 +744,8 @@ function useAdvanceSearch({ fields, limitRows }) {
742
744
  value2: "",
743
745
  multiTableSearch: r.multiTableSearch,
744
746
  jsonPath: r.jsonPath,
745
- lookupFieldName: r.lookupFieldName
747
+ lookupFieldName: r.lookupFieldName,
748
+ allowRegex: r.allowRegex
746
749
  } : {
747
750
  id: r.id,
748
751
  fieldName: r.fieldName,
@@ -751,7 +754,8 @@ function useAdvanceSearch({ fields, limitRows }) {
751
754
  value: "",
752
755
  multiTableSearch: r.multiTableSearch,
753
756
  jsonPath: r.jsonPath,
754
- lookupFieldName: r.lookupFieldName
757
+ lookupFieldName: r.lookupFieldName,
758
+ allowRegex: r.allowRegex
755
759
  };
756
760
  })
757
761
  );
@@ -799,7 +803,8 @@ function useAdvanceSearch({ fields, limitRows }) {
799
803
  lookupFieldName: r.lookupFieldName,
800
804
  jsonPath: r.jsonPath,
801
805
  operator,
802
- value: ""
806
+ value: "",
807
+ allowRegex: r.allowRegex
803
808
  };
804
809
  })
805
810
  );
@@ -1389,11 +1394,19 @@ var ConditionTextInput = ({ row, control, onClear }) => /* @__PURE__ */ jsx(
1389
1394
  field.onChange("");
1390
1395
  onClear("value");
1391
1396
  };
1397
+ const handleChange = (e) => {
1398
+ const val = e.target.value;
1399
+ if (val !== "" && row.allowRegex && !row.allowRegex.test(val)) {
1400
+ return;
1401
+ }
1402
+ field.onChange(val);
1403
+ };
1392
1404
  return /* @__PURE__ */ jsxs(FormItem, { className: "relative", children: [
1393
1405
  /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
1394
1406
  Input,
1395
1407
  {
1396
1408
  ...field,
1409
+ onChange: handleChange,
1397
1410
  value: field.value ?? "",
1398
1411
  autoComplete: "off",
1399
1412
  inputMode: "text",
@@ -2600,12 +2613,16 @@ var LookupSelect = ({
2600
2613
  (option) => {
2601
2614
  upsertOptionLabels([option]);
2602
2615
  addTag(option.value);
2603
- inputRef.current?.focus();
2604
- setTimeout(() => {
2605
- inputRef.current?.scrollIntoView({ behavior: "smooth" });
2606
- }, 100);
2616
+ if (multiple) {
2617
+ inputRef.current?.focus();
2618
+ setTimeout(() => {
2619
+ inputRef.current?.scrollIntoView({ behavior: "smooth" });
2620
+ }, 100);
2621
+ } else {
2622
+ inputRef.current?.blur();
2623
+ }
2607
2624
  },
2608
- [addTag, upsertOptionLabels]
2625
+ [addTag, multiple, upsertOptionLabels]
2609
2626
  );
2610
2627
  const handleKeyDown = useCallback(
2611
2628
  (e) => {
@@ -2765,7 +2782,7 @@ var LookupSelect = ({
2765
2782
  }
2766
2783
  return /* @__PURE__ */ jsx("div", { ref: assignDropdownContentRef, className: "absolute left-0 right-0 top-full z-10 mt-1", children: dropdownContent });
2767
2784
  };
2768
- return /* @__PURE__ */ jsxs("div", { className: "relative w-full", ref: containerRef, children: [
2785
+ return /* @__PURE__ */ jsxs("div", { className: "relative w-full truncate", ref: containerRef, children: [
2769
2786
  /* @__PURE__ */ jsxs(
2770
2787
  "div",
2771
2788
  {
@@ -2796,7 +2813,7 @@ var LookupSelect = ({
2796
2813
  `${tag}-${i}`
2797
2814
  );
2798
2815
  }),
2799
- !multiple && selectedLabel && /* @__PURE__ */ jsx("span", { className: "truncate text-sm text-gray-700", children: selectedLabel }),
2816
+ !multiple && selectedLabel && /* @__PURE__ */ jsx("span", { className: "truncate text-sm text-gray-700 max-w-full", children: selectedLabel }),
2800
2817
  /* @__PURE__ */ jsx(
2801
2818
  "input",
2802
2819
  {
@@ -2810,6 +2827,7 @@ var LookupSelect = ({
2810
2827
  setIsDropdownOpen(true);
2811
2828
  }
2812
2829
  },
2830
+ hidden: !multiple && selectedLabel !== void 0,
2813
2831
  placeholder: value.length === 0 && resolvedPlaceholder || "",
2814
2832
  className: "min-w-[120px] flex-1 border-none bg-transparent py-1 text-sm text-gray-600 placeholder:text-gray-400 outline-none",
2815
2833
  disabled: multiple && limitReached
@@ -2911,7 +2929,6 @@ var ConditionJSONInput = ({
2911
2929
  onClear: handleClear,
2912
2930
  error: Boolean(fieldState.error),
2913
2931
  placeholder: fieldSchema?.placeholder,
2914
- maxTags: row.operator === "containsAny" ? fieldSchema?.maxTags : 1,
2915
2932
  fetchSuggestions: fieldSchema?.fetchSuggestions,
2916
2933
  suggestionDebounce: fieldSchema?.suggestionDebounce,
2917
2934
  noOptionsMessage: fieldSchema?.noOptionsMessage,
@@ -3124,7 +3141,8 @@ var DatetimeBuilder = class {
3124
3141
  case "after":
3125
3142
  return {
3126
3143
  [row.fieldName]: helper(
3127
- { gte: dayStart.toISOString() },
3144
+ { gte: dayEnd.toISOString() },
3145
+ // use end of the day time
3128
3146
  { multiTableSearch: row.multiTableSearch }
3129
3147
  )
3130
3148
  };
@@ -3227,12 +3245,12 @@ var JSONBuilder = class {
3227
3245
  return {
3228
3246
  NOT: { [row.fieldName]: { path: row.jsonPath, equals: isArray ? row.value[0] : row.value } }
3229
3247
  };
3230
- case "containsAny":
3231
- if (!isArray)
3232
- return { [row.fieldName]: { path: row.jsonPath, equals: isArray ? row.value[0] : row.value } };
3233
- return {
3234
- OR: row.value.map((v) => ({ [row.fieldName]: { path: row.jsonPath, equals: v } }))
3235
- };
3248
+ // case "containsAny":
3249
+ // if (!isArray)
3250
+ // return { [row.fieldName]: { path: row.jsonPath, equals: isArray ? row.value[0] : row.value } };
3251
+ // return {
3252
+ // OR: (row.value as any[]).map((v) => ({ [row.fieldName]: { path: row.jsonPath, equals: v } }))
3253
+ // };
3236
3254
  default:
3237
3255
  return {};
3238
3256
  }
@@ -3505,7 +3523,9 @@ function transformFilterKeys(obj, fieldMap = FILTER_FIELD_MAP) {
3505
3523
  }
3506
3524
  var sanitizeInput = (val) => {
3507
3525
  if (!val) return val;
3508
- if (typeof val !== "string") return "__INVALID_TYPE__";
3526
+ if (Array.isArray(val)) {
3527
+ return val.map((v) => sanitizeInput(v));
3528
+ }
3509
3529
  if (val.includes("\n") || val.includes("\r") || /[\u2028\u2029]/u.test(val))
3510
3530
  return "__INVALID_NEWLINE__";
3511
3531
  if (/\\\\/.test(val)) return "__INVALID_ESCAPE__";
@@ -3524,6 +3544,9 @@ var numericTypes = ["number", "integer", "decimal"];
3524
3544
  var dateTypes = ["date", "datemonth"];
3525
3545
  var validateByFieldType = (value, fieldType) => {
3526
3546
  if (!value) return { valid: true };
3547
+ if (Array.isArray(value)) {
3548
+ return { valid: true };
3549
+ }
3527
3550
  if (numericTypes.includes(fieldType)) {
3528
3551
  if (!/^\d+(\.\d+)?$/.test(value)) {
3529
3552
  return { valid: false, message: "Please enter a valid number." };
@@ -3596,6 +3619,7 @@ var AdvanceSearch = ({
3596
3619
  );
3597
3620
  const parseRangeValue = useCallback((raw, fieldType) => {
3598
3621
  if (!raw) return void 0;
3622
+ if (Array.isArray(raw)) return void 0;
3599
3623
  const normalized = fieldType === "datemonth" ? `${raw}-01` : raw;
3600
3624
  const parsed = parseISO(normalized);
3601
3625
  return isValid(parsed) ? parsed : void 0;
@@ -3614,10 +3638,10 @@ var AdvanceSearch = ({
3614
3638
  const processedRows = rows.map((r) => {
3615
3639
  const startField = `value_${r.id}`;
3616
3640
  const endField = `value2_${r.id}`;
3617
- let v1 = currentValues[startField] ?? "";
3618
- let v2 = currentValues[endField] ?? "";
3641
+ let v1 = currentValues[startField];
3642
+ let v2 = currentValues[endField];
3619
3643
  const s1 = sanitizeInput(v1);
3620
- if (s1?.startsWith("__INVALID")) {
3644
+ if (Array.isArray(s1) && s1.some((v) => v?.startsWith("__INVALID")) || typeof s1 === "string" && s1?.startsWith("__INVALID")) {
3621
3645
  hasError = true;
3622
3646
  setError(startField, { type: "validate", message: "Invalid input." });
3623
3647
  return null;
@@ -3631,7 +3655,7 @@ var AdvanceSearch = ({
3631
3655
  }
3632
3656
  if (r.operator === "between") {
3633
3657
  const s2 = sanitizeInput(v2);
3634
- if (s2?.startsWith("__INVALID")) {
3658
+ if (Array.isArray(s2) && s2.some((v) => v?.startsWith("__INVALID")) || typeof s2 === "string" && s2?.startsWith("__INVALID")) {
3635
3659
  hasError = true;
3636
3660
  setError(endField, { type: "validate", message: "Invalid input." });
3637
3661
  return null;