@universe-platform/ui 0.1.0-beta.66 → 0.1.0-beta.68

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
@@ -713,6 +713,187 @@ function formatFileSize(bytes) {
713
713
  return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + " " + sizes[i];
714
714
  }
715
715
 
716
+ // ../shared/src/formulaFilters.ts
717
+ var MAX_FILTER_CONDITIONS = 5;
718
+ var MAX_VALUE_LENGTH = 200;
719
+ function filterKindOfType(type) {
720
+ const t = String(type || "").toUpperCase();
721
+ if (t === "NUMBER" || t === "CURRENCY") return "number";
722
+ if (t === "DATE") return "date";
723
+ if (t === "BOOLEAN") return "boolean";
724
+ if (t === "RELATION") return "relation";
725
+ return "text";
726
+ }
727
+ var op = (id, label, needsValue = true) => ({ id, label, needsValue });
728
+ var EMPTY_OPS = [op("empty", "\u05E8\u05D9\u05E7", false), op("notempty", "\u05DC\u05D0 \u05E8\u05D9\u05E7", false)];
729
+ var OPS_BY_KIND = {
730
+ text: [
731
+ op("eq", "\u05E9\u05D5\u05D5\u05D4 \u05DC"),
732
+ op("ne", "\u05E9\u05D5\u05E0\u05D4 \u05DE"),
733
+ op("contains", "\u05DE\u05DB\u05D9\u05DC"),
734
+ op("notcontains", "\u05DC\u05D0 \u05DE\u05DB\u05D9\u05DC"),
735
+ op("starts", "\u05DE\u05EA\u05D7\u05D9\u05DC \u05D1"),
736
+ op("ends", "\u05DE\u05E1\u05EA\u05D9\u05D9\u05DD \u05D1"),
737
+ op("in", "\u05D0\u05D7\u05D3 \u05DE\u05EA\u05D5\u05DA (\u05DE\u05D5\u05E4\u05E8\u05D3\u05D9\u05DD \u05D1\u05E4\u05E1\u05D9\u05E7)"),
738
+ ...EMPTY_OPS
739
+ ],
740
+ relation: [
741
+ op("eq", "\u05E9\u05D5\u05D5\u05D4 \u05DC"),
742
+ op("ne", "\u05E9\u05D5\u05E0\u05D4 \u05DE"),
743
+ op("contains", "\u05DE\u05DB\u05D9\u05DC"),
744
+ op("in", "\u05D0\u05D7\u05D3 \u05DE\u05EA\u05D5\u05DA (\u05DE\u05D5\u05E4\u05E8\u05D3\u05D9\u05DD \u05D1\u05E4\u05E1\u05D9\u05E7)"),
745
+ ...EMPTY_OPS
746
+ ],
747
+ number: [
748
+ op("eq", "\u05E9\u05D5\u05D5\u05D4 \u05DC"),
749
+ op("ne", "\u05E9\u05D5\u05E0\u05D4 \u05DE"),
750
+ op("gt", "\u05D2\u05D3\u05D5\u05DC \u05DE"),
751
+ op("lt", "\u05E7\u05D8\u05DF \u05DE"),
752
+ op("ge", "\u05D2\u05D3\u05D5\u05DC \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4 \u05DC"),
753
+ op("le", "\u05E7\u05D8\u05DF \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4 \u05DC"),
754
+ ...EMPTY_OPS
755
+ ],
756
+ date: [
757
+ op("eq", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA"),
758
+ op("ne", "\u05DC\u05D0 \u05D1\u05EA\u05D0\u05E8\u05D9\u05DA"),
759
+ op("gt", "\u05D0\u05D7\u05E8\u05D9"),
760
+ op("lt", "\u05DC\u05E4\u05E0\u05D9"),
761
+ op("ge", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA \u05D0\u05D5 \u05D0\u05D7\u05E8\u05D9\u05D5"),
762
+ op("le", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA \u05D0\u05D5 \u05DC\u05E4\u05E0\u05D9\u05D5"),
763
+ ...EMPTY_OPS
764
+ ],
765
+ boolean: [op("yes", "\u05DE\u05E1\u05D5\u05DE\u05DF (\u05DB\u05DF)", false), op("no", "\u05DC\u05D0 \u05DE\u05E1\u05D5\u05DE\u05DF (\u05DC\u05D0)", false)]
766
+ };
767
+ var getFilterOps = (type) => OPS_BY_KIND[filterKindOfType(type)];
768
+ var ALL_OPS = new Set(Object.values(OPS_BY_KIND).flat().map((o) => o.id));
769
+ var NEEDS_VALUE = new Map(Object.values(OPS_BY_KIND).flat().map((o) => [o.id, o.needsValue]));
770
+ function sanitizeRefFilter(raw) {
771
+ if (!raw || typeof raw !== "object") return null;
772
+ const r = raw;
773
+ if (!Array.isArray(r.conditions)) return null;
774
+ const conditions = [];
775
+ for (const c of r.conditions.slice(0, MAX_FILTER_CONDITIONS)) {
776
+ if (!c || typeof c !== "object") continue;
777
+ const field = typeof c.field === "string" ? c.field.trim().slice(0, MAX_VALUE_LENGTH) : "";
778
+ const opId = typeof c.op === "string" ? c.op : "";
779
+ if (!field || !ALL_OPS.has(opId)) continue;
780
+ const needs = NEEDS_VALUE.get(opId) === true;
781
+ const value = typeof c.value === "string" ? c.value.trim().slice(0, MAX_VALUE_LENGTH) : typeof c.value === "number" ? String(c.value) : "";
782
+ if (needs && value === "") continue;
783
+ conditions.push({ field, op: opId, value: needs ? value : "" });
784
+ }
785
+ if (conditions.length === 0) return null;
786
+ return { join: r.join === "OR" ? "OR" : "AND", conditions };
787
+ }
788
+ function filterSignature(f) {
789
+ var _a;
790
+ if (!f || !((_a = f.conditions) == null ? void 0 : _a.length)) return "";
791
+ return `${f.join}:${f.conditions.map((c) => `${c.field}${c.op}${c.value}`).join("")}`;
792
+ }
793
+ var SHORT_LABELS = {
794
+ eq: "=",
795
+ ne: "\u2260",
796
+ gt: ">",
797
+ lt: "<",
798
+ ge: "\u2265",
799
+ le: "\u2264",
800
+ contains: "\u05DE\u05DB\u05D9\u05DC",
801
+ notcontains: "\u05DC\u05D0 \u05DE\u05DB\u05D9\u05DC",
802
+ starts: "\u05DE\u05EA\u05D7\u05D9\u05DC \u05D1",
803
+ ends: "\u05DE\u05E1\u05EA\u05D9\u05D9\u05DD \u05D1",
804
+ in: "\u05D0\u05D7\u05D3 \u05DE\u05EA\u05D5\u05DA",
805
+ empty: "\u05E8\u05D9\u05E7",
806
+ notempty: "\u05DC\u05D0 \u05E8\u05D9\u05E7",
807
+ yes: "\u05DE\u05E1\u05D5\u05DE\u05DF",
808
+ no: "\u05DC\u05D0 \u05DE\u05E1\u05D5\u05DE\u05DF"
809
+ };
810
+ function describeRefFilter(f) {
811
+ var _a;
812
+ if (!f || !((_a = f.conditions) == null ? void 0 : _a.length)) return "";
813
+ const sep = f.join === "OR" ? " \u05D0\u05D5 " : " \u05D5\u05D2\u05DD ";
814
+ return f.conditions.map((c) => {
815
+ const needs = NEEDS_VALUE.get(c.op) === true;
816
+ return needs ? `${c.field} ${SHORT_LABELS[c.op]} ${c.value}` : `${c.field} ${SHORT_LABELS[c.op]}`;
817
+ }).join(sep);
818
+ }
819
+ var norm = (x) => String(x != null ? x : "").trim().toLowerCase();
820
+ var isBlankValue = (x) => x === null || x === void 0 || typeof x === "string" && x.trim() === "" || Array.isArray(x) && x.every(isBlankValue);
821
+ var isoDate = (x) => typeof x === "string" && /^\d{4}-\d{2}-\d{2}/.test(x.trim()) ? x.trim().slice(0, 10) : null;
822
+ var numOf = (x) => {
823
+ if (typeof x === "number") return Number.isFinite(x) ? x : null;
824
+ if (typeof x === "string" && x.trim() !== "") {
825
+ const n = Number(x);
826
+ return Number.isFinite(n) ? n : null;
827
+ }
828
+ return null;
829
+ };
830
+ function compare(l, r) {
831
+ const ld = isoDate(l), rd = isoDate(r);
832
+ if (ld && rd) return ld < rd ? -1 : ld > rd ? 1 : 0;
833
+ const ln = numOf(l), rn = numOf(r);
834
+ if (ln !== null && rn !== null) return ln < rn ? -1 : ln > rn ? 1 : 0;
835
+ const a = norm(l), b = norm(r);
836
+ return a < b ? -1 : a > b ? 1 : 0;
837
+ }
838
+ var NEGATED = { ne: "eq", notcontains: "contains" };
839
+ function matchSingle(opId, v, target) {
840
+ switch (opId) {
841
+ case "eq":
842
+ return !isBlankValue(v) && compare(v, target) === 0;
843
+ case "ne":
844
+ return isBlankValue(v) || compare(v, target) !== 0;
845
+ case "contains":
846
+ return norm(v).includes(norm(target));
847
+ case "notcontains":
848
+ return !norm(v).includes(norm(target));
849
+ case "starts":
850
+ return norm(v).startsWith(norm(target));
851
+ case "ends":
852
+ return norm(v).endsWith(norm(target));
853
+ case "in": {
854
+ const list = target.split(",").map(norm).filter(Boolean);
855
+ return list.includes(norm(v));
856
+ }
857
+ case "gt":
858
+ return !isBlankValue(v) && compare(v, target) > 0;
859
+ case "lt":
860
+ return !isBlankValue(v) && compare(v, target) < 0;
861
+ case "ge":
862
+ return !isBlankValue(v) && compare(v, target) >= 0;
863
+ case "le":
864
+ return !isBlankValue(v) && compare(v, target) <= 0;
865
+ case "empty":
866
+ return isBlankValue(v);
867
+ case "notempty":
868
+ return !isBlankValue(v);
869
+ case "yes": {
870
+ if (v === true) return true;
871
+ if (typeof v === "number") return v !== 0;
872
+ return ["true", "1", "yes", "\u05DB\u05DF"].includes(norm(v));
873
+ }
874
+ case "no":
875
+ return !matchSingle("yes", v, target);
876
+ default:
877
+ return false;
878
+ }
879
+ }
880
+ function matchCondition(c, raw) {
881
+ if (c.op === "empty") return isBlankValue(raw);
882
+ if (c.op === "notempty") return !isBlankValue(raw);
883
+ if (Array.isArray(raw)) {
884
+ const positive = NEGATED[c.op];
885
+ if (positive) return !raw.some((item) => matchSingle(positive, item, c.value));
886
+ return raw.some((item) => matchSingle(c.op, item, c.value));
887
+ }
888
+ return matchSingle(c.op, raw, c.value);
889
+ }
890
+ function matchesRefFilter(filter, getValue) {
891
+ var _a;
892
+ if (!filter || !((_a = filter.conditions) == null ? void 0 : _a.length)) return true;
893
+ const test = (c) => matchCondition(c, getValue(c.field));
894
+ return filter.join === "OR" ? filter.conditions.some(test) : filter.conditions.every(test);
895
+ }
896
+
716
897
  // ../shared/src/formula.ts
717
898
  var FORMULA_COLUMN_TYPE = "FORMULA";
718
899
  var FORMULA_SOURCE_TYPES = ["NUMBER", "CURRENCY", "STRING", "BOOLEAN", "DATE", "TIME", "PHONE"];
@@ -739,7 +920,10 @@ function makeCellRefKey(existing, field, agg) {
739
920
  for (let n = 2; (existing || []).some((r) => r.key === key); n++) key = `${base} (${n})`;
740
921
  return key;
741
922
  }
742
- var perRecordRefValueKey = (r) => `ref:${r.tableId}::${r.agg ? "" : r.recordId || ""}::${r.field}::${r.agg || ""}`;
923
+ var perRecordRefValueKey = (r) => {
924
+ const sig = r.agg ? filterSignature(r.filter) : "";
925
+ return `ref:${r.tableId}::${r.agg ? "" : r.recordId || ""}::${r.field}::${r.agg || ""}${sig ? `::${sig}` : ""}`;
926
+ };
743
927
  function sanitizeRefs(raw) {
744
928
  var _a, _b, _c, _d;
745
929
  if (!Array.isArray(raw)) return [];
@@ -752,15 +936,16 @@ function sanitizeRefs(raw) {
752
936
  const field = typeof r.field === "string" ? r.field : "";
753
937
  if (!key.startsWith("@") || seen.has(key) || !tableId || !field) continue;
754
938
  const agg = PER_RECORD_SOURCE_AGGS.includes(r.agg) ? r.agg : void 0;
939
+ const filter = agg ? sanitizeRefFilter(r.filter) : null;
755
940
  seen.add(key);
756
- out.push(__spreadValues({
941
+ out.push(__spreadValues(__spreadValues({
757
942
  key,
758
943
  tableId,
759
944
  tableName: String((_b = r.tableName) != null ? _b : "").slice(0, 200),
760
945
  recordId: agg ? "" : String((_c = r.recordId) != null ? _c : ""),
761
946
  recordLabel: agg ? "" : String((_d = r.recordLabel) != null ? _d : "").slice(0, 200),
762
947
  field
763
- }, agg ? { agg } : {}));
948
+ }, agg ? { agg } : {}), filter ? { filter } : {}));
764
949
  }
765
950
  return out;
766
951
  }
@@ -787,7 +972,8 @@ function describePerRecordFormula(f) {
787
972
  if (!f) return "";
788
973
  let text2 = f.expression;
789
974
  for (const r of f.refs) {
790
- const path = r.agg ? `${PER_RECORD_AGG_LABELS[r.agg]} ${r.tableName} \u203A ${r.field}` : `${r.tableName} \u203A ${r.recordLabel || "\u05E8\u05E9\u05D5\u05DE\u05D4"} \u203A ${r.field}`;
975
+ const filterText = r.agg ? describeRefFilter(r.filter) : "";
976
+ const path = r.agg ? `${PER_RECORD_AGG_LABELS[r.agg]} ${r.tableName} \u203A ${r.field}${filterText ? ` [${filterText}]` : ""}` : `${r.tableName} \u203A ${r.recordLabel || "\u05E8\u05E9\u05D5\u05DE\u05D4"} \u203A ${r.field}`;
791
977
  text2 = text2.split(`{${r.key}}`).join(`[${path}]`);
792
978
  }
793
979
  return text2;
@@ -837,10 +1023,10 @@ function tokenize(src) {
837
1023
  i += id[0].length;
838
1024
  continue;
839
1025
  }
840
- const op = /^(>=|<=|<>|[-+*/%(),<>=&])/.exec(rest);
841
- if (op) {
842
- toks.push({ k: "op", v: op[0] });
843
- i += op[0].length;
1026
+ const op2 = /^(>=|<=|<>|[-+*/%(),<>=&])/.exec(rest);
1027
+ if (op2) {
1028
+ toks.push({ k: "op", v: op2[0] });
1029
+ i += op2[0].length;
844
1030
  continue;
845
1031
  }
846
1032
  throw new Error(`\u05EA\u05D5 \u05DC\u05D0 \u05DE\u05D5\u05DB\u05E8 \u05D1\u05E0\u05D5\u05E1\u05D7\u05D4: ${c}`);
@@ -854,7 +1040,7 @@ var toNum = (x) => {
854
1040
  };
855
1041
  var isBlank = (x) => x === null || x === void 0 || x === "";
856
1042
  var isNumLike = (x) => typeof x === "number" || typeof x === "string" && x.trim() !== "" && Number.isFinite(Number(x));
857
- var isoDate = (x) => typeof x === "string" && /^\d{4}-\d{2}-\d{2}/.test(x) ? x.slice(0, 10) : null;
1043
+ var isoDate2 = (x) => typeof x === "string" && /^\d{4}-\d{2}-\d{2}/.test(x) ? x.slice(0, 10) : null;
858
1044
  var truthy = (x) => {
859
1045
  if (x === null || x === "") return false;
860
1046
  if (typeof x === "number") return x !== 0 && !Number.isNaN(x);
@@ -863,7 +1049,7 @@ var truthy = (x) => {
863
1049
  };
864
1050
  var text = (x) => String(x != null ? x : "").trim().toLowerCase();
865
1051
  function compareValues(l, r) {
866
- const ld = isoDate(l), rd = isoDate(r);
1052
+ const ld = isoDate2(l), rd = isoDate2(r);
867
1053
  if (ld && rd) return ld < rd ? -1 : ld > rd ? 1 : 0;
868
1054
  if ((isNumLike(l) || isBlank(l)) && (isNumLike(r) || isBlank(r))) {
869
1055
  const a2 = toNum(l), b2 = toNum(r);
@@ -904,9 +1090,9 @@ function evaluateFormula(expr, getField) {
904
1090
  function parseExpr() {
905
1091
  let l = parseConcat();
906
1092
  while (isOp(">", "<", ">=", "<=", "=", "<>")) {
907
- const op = eat().v, r = parseConcat();
1093
+ const op2 = eat().v, r = parseConcat();
908
1094
  const c = compareValues(l, r);
909
- l = (op === ">" ? c > 0 : op === "<" ? c < 0 : op === ">=" ? c >= 0 : op === "<=" ? c <= 0 : op === "=" ? c === 0 : c !== 0) ? 1 : 0;
1095
+ l = (op2 === ">" ? c > 0 : op2 === "<" ? c < 0 : op2 === ">=" ? c >= 0 : op2 === "<=" ? c <= 0 : op2 === "=" ? c === 0 : c !== 0) ? 1 : 0;
910
1096
  }
911
1097
  return l;
912
1098
  }
@@ -922,17 +1108,17 @@ function evaluateFormula(expr, getField) {
922
1108
  function parseAdd() {
923
1109
  let l = parseMul();
924
1110
  while (isOp("+", "-")) {
925
- const op = eat().v, r = parseMul();
926
- l = op === "+" ? toNum(l) + toNum(r) : toNum(l) - toNum(r);
1111
+ const op2 = eat().v, r = parseMul();
1112
+ l = op2 === "+" ? toNum(l) + toNum(r) : toNum(l) - toNum(r);
927
1113
  }
928
1114
  return l;
929
1115
  }
930
1116
  function parseMul() {
931
1117
  let l = parseUnary();
932
1118
  while (isOp("*", "/", "%")) {
933
- const op = eat().v, r = parseUnary();
1119
+ const op2 = eat().v, r = parseUnary();
934
1120
  const a = toNum(l), b = toNum(r);
935
- l = op === "*" ? a * b : op === "/" ? a / b : a % b;
1121
+ l = op2 === "*" ? a * b : op2 === "/" ? a / b : a % b;
936
1122
  }
937
1123
  return l;
938
1124
  }
@@ -1016,7 +1202,7 @@ function evaluateFormula(expr, getField) {
1016
1202
  case "ISEMPTY":
1017
1203
  return isBlank(args[0]) ? 1 : 0;
1018
1204
  case "DAYS": {
1019
- const a = isoDate(args[0]), b = isoDate(args[1]);
1205
+ const a = isoDate2(args[0]), b = isoDate2(args[1]);
1020
1206
  return a && b ? Math.round((dayNumber(a) - dayNumber(b)) / 864e5) : null;
1021
1207
  }
1022
1208
  default:
@@ -1141,12 +1327,31 @@ function renameCopyTarget(col, oldName, newName) {
1141
1327
 
1142
1328
  // ../shared/src/relationButtons.ts
1143
1329
  var RELATION_BUTTON_COUNTS_ACTION = "FETCH_RELATION_BUTTON_COUNTS";
1330
+ var BOOLEAN_BUTTON_TRUE_ID = "true";
1331
+ var BOOLEAN_BUTTON_FALSE_ID = "false";
1332
+ var DEFAULT_BOOLEAN_TRUE_LABEL = "\u05DB\u05DF";
1333
+ var DEFAULT_BOOLEAN_FALSE_LABEL = "\u05DC\u05D0";
1144
1334
  function isRelationButtonsColumn(col) {
1145
1335
  var _a, _b;
1146
1336
  return !!col && String(col.type).toUpperCase() === "RELATION" && ((_a = col.config) == null ? void 0 : _a.showAsButtons) === true && !!((_b = col.config) == null ? void 0 : _b.referencedTableId);
1147
1337
  }
1338
+ function isBooleanButtonsColumn(col) {
1339
+ var _a;
1340
+ return !!col && String(col.type).toUpperCase() === "BOOLEAN" && ((_a = col.config) == null ? void 0 : _a.showAsButtons) === true;
1341
+ }
1342
+ function getBooleanButtonLabels(col) {
1343
+ var _a, _b, _c, _d;
1344
+ const t = String((_b = (_a = col == null ? void 0 : col.config) == null ? void 0 : _a.buttonsTrueLabel) != null ? _b : "").trim();
1345
+ const f = String((_d = (_c = col == null ? void 0 : col.config) == null ? void 0 : _c.buttonsFalseLabel) != null ? _d : "").trim();
1346
+ return {
1347
+ trueLabel: t || DEFAULT_BOOLEAN_TRUE_LABEL,
1348
+ falseLabel: f || DEFAULT_BOOLEAN_FALSE_LABEL
1349
+ };
1350
+ }
1148
1351
  function getRelationButtonColumns(columns) {
1149
- return (columns || []).filter((c) => isRelationButtonsColumn(c) && c.name !== "_id");
1352
+ return (columns || []).filter(
1353
+ (c) => (isRelationButtonsColumn(c) || isBooleanButtonsColumn(c)) && c.name !== "_id"
1354
+ );
1150
1355
  }
1151
1356
 
1152
1357
  // ../shared/src/defaultFilters.ts
@@ -1198,8 +1403,158 @@ function cleanPlacementFilterDefaults(defaults, allowedKeys) {
1198
1403
  return Object.keys(out).length > 0 ? out : void 0;
1199
1404
  }
1200
1405
 
1406
+ // ../shared/src/formulaBuilder.ts
1407
+ var FORMULA_TYPE_LABELS = {
1408
+ NUMBER: "\u05DE\u05E1\u05E4\u05E8",
1409
+ CURRENCY: "\u05DE\u05D8\u05D1\u05E2",
1410
+ STRING: "\u05D8\u05E7\u05E1\u05D8",
1411
+ PHONE: "\u05D8\u05DC\u05E4\u05D5\u05DF",
1412
+ TIME: "\u05E9\u05E2\u05D4",
1413
+ DATE: "\u05EA\u05D0\u05E8\u05D9\u05DA",
1414
+ BOOLEAN: "\u05DB\u05DF/\u05DC\u05D0"
1415
+ };
1416
+ var FORMULA_OPERATOR_GROUPS = [
1417
+ {
1418
+ label: "\u05D7\u05E9\u05D1\u05D5\u05DF",
1419
+ items: [
1420
+ { label: "+ \u05D7\u05D9\u05D1\u05D5\u05E8", insert: " + " },
1421
+ { label: "- \u05D7\u05D9\u05E1\u05D5\u05E8", insert: " - " },
1422
+ { label: "* \u05DB\u05E4\u05DC", insert: " * " },
1423
+ { label: "/ \u05D7\u05D9\u05DC\u05D5\u05E7", insert: " / " },
1424
+ { label: "% \u05E9\u05D0\u05E8\u05D9\u05EA", insert: " % " }
1425
+ ]
1426
+ },
1427
+ {
1428
+ label: "\u05D4\u05E9\u05D5\u05D5\u05D0\u05D4",
1429
+ items: [
1430
+ { label: "= \u05E9\u05D5\u05D5\u05D4", insert: " = " },
1431
+ { label: "<> \u05E9\u05D5\u05E0\u05D4", insert: " <> " },
1432
+ { label: "> \u05D2\u05D3\u05D5\u05DC \u05DE", insert: " > " },
1433
+ { label: "< \u05E7\u05D8\u05DF \u05DE", insert: " < " },
1434
+ { label: ">= \u05D2\u05D3\u05D5\u05DC \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4", insert: " >= " },
1435
+ { label: "<= \u05E7\u05D8\u05DF \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4", insert: " <= " }
1436
+ ]
1437
+ },
1438
+ { label: "\u05D8\u05E7\u05E1\u05D8", items: [{ label: "& \u05D7\u05D9\u05D1\u05D5\u05E8 \u05D8\u05E7\u05E1\u05D8\u05D9\u05DD", insert: " & " }] },
1439
+ {
1440
+ label: "\u05E1\u05D9\u05DE\u05E0\u05D9\u05DD",
1441
+ items: [
1442
+ { label: "( \u05E4\u05EA\u05D9\u05D7\u05EA \u05E1\u05D5\u05D2\u05E8\u05D9\u05D9\u05DD", insert: "(" },
1443
+ { label: ") \u05E1\u05D2\u05D9\u05E8\u05EA \u05E1\u05D5\u05D2\u05E8\u05D9\u05D9\u05DD", insert: ")" },
1444
+ { label: ", \u05E4\u05E1\u05D9\u05E7 (\u05D1\u05D9\u05DF \u05E4\u05E8\u05DE\u05D8\u05E8\u05D9\u05DD)", insert: ", " }
1445
+ ]
1446
+ }
1447
+ ];
1448
+ var FORMULA_FUNCTION_GROUPS = [
1449
+ {
1450
+ label: "\u05EA\u05E0\u05D0\u05D9\u05DD \u05D5\u05DC\u05D5\u05D2\u05D9\u05E7\u05D4",
1451
+ items: [
1452
+ { label: "\u05D0\u05DD... \u05D0\u05D6... \u05D0\u05D7\u05E8\u05EA (IF)", template: "IF(, , )" },
1453
+ { label: "\u05D5\u05D2\u05DD (AND)", template: "AND(, )" },
1454
+ { label: "\u05D0\u05D5 (OR)", template: "OR(, )" },
1455
+ { label: "\u05DC\u05D0 (NOT)", template: "NOT()" },
1456
+ { label: "\u05D4\u05D0\u05DD \u05E8\u05D9\u05E7 (ISEMPTY)", template: "ISEMPTY()" }
1457
+ ]
1458
+ },
1459
+ {
1460
+ label: "\u05D8\u05E7\u05E1\u05D8",
1461
+ items: [
1462
+ { label: "\u05DE\u05DB\u05D9\u05DC \u05D8\u05E7\u05E1\u05D8 (CONTAINS)", template: 'CONTAINS(, "")' },
1463
+ { label: "\u05DE\u05EA\u05D7\u05D9\u05DC \u05D1 (STARTSWITH)", template: 'STARTSWITH(, "")' },
1464
+ { label: "\u05DE\u05E1\u05EA\u05D9\u05D9\u05DD \u05D1 (ENDSWITH)", template: 'ENDSWITH(, "")' }
1465
+ ]
1466
+ },
1467
+ {
1468
+ label: "\u05DE\u05E1\u05E4\u05E8\u05D9\u05DD",
1469
+ items: [
1470
+ { label: "\u05E2\u05D9\u05D2\u05D5\u05DC (ROUND)", template: "ROUND(, 2)" },
1471
+ { label: "\u05DE\u05D9\u05E0\u05D9\u05DE\u05D5\u05DD (MIN)", template: "MIN(, )" },
1472
+ { label: "\u05DE\u05E7\u05E1\u05D9\u05DE\u05D5\u05DD (MAX)", template: "MAX(, )" },
1473
+ { label: "\u05E2\u05E8\u05DA \u05DE\u05D5\u05D7\u05DC\u05D8 (ABS)", template: "ABS()" }
1474
+ ]
1475
+ },
1476
+ {
1477
+ label: "\u05EA\u05D0\u05E8\u05D9\u05DB\u05D9\u05DD",
1478
+ items: [{ label: "\u05D4\u05E4\u05E8\u05E9 \u05D9\u05DE\u05D9\u05DD (DAYS: \u05E1\u05D5\u05E3, \u05D4\u05EA\u05D7\u05DC\u05D4)", template: "DAYS(, )" }]
1479
+ }
1480
+ ];
1481
+ var NUMBER_RE = /^-?\d+(\.\d+)?$/;
1482
+ var isFieldRef = (s) => s.startsWith("{") && s.endsWith("}");
1483
+ var quote = (s) => `"${s.replace(/"/g, "")}"`;
1484
+ var literal = (raw, forceText) => {
1485
+ const v = raw.trim();
1486
+ if (isFieldRef(v)) return v;
1487
+ if (!forceText && NUMBER_RE.test(v)) return v;
1488
+ return quote(v);
1489
+ };
1490
+ var operand = (raw) => {
1491
+ const v = raw.trim();
1492
+ if (v === "") return '""';
1493
+ if (isFieldRef(v) || NUMBER_RE.test(v)) return v;
1494
+ return quote(v);
1495
+ };
1496
+ var cmp = (id, label, sym) => ({
1497
+ id,
1498
+ label,
1499
+ needsValue: true,
1500
+ build: (f, v, t) => `${f} ${sym} ${literal(v, t)}`
1501
+ });
1502
+ var EMPTY_OPS2 = [
1503
+ { id: "empty", label: "\u05E8\u05D9\u05E7", needsValue: false, build: (f) => `ISEMPTY(${f})` },
1504
+ { id: "notempty", label: "\u05DC\u05D0 \u05E8\u05D9\u05E7", needsValue: false, build: (f) => `NOT(ISEMPTY(${f}))` }
1505
+ ];
1506
+ var NUMBER_OPS = [
1507
+ cmp("eq", "\u05E9\u05D5\u05D5\u05D4 \u05DC", "="),
1508
+ cmp("ne", "\u05E9\u05D5\u05E0\u05D4 \u05DE", "<>"),
1509
+ cmp("gt", "\u05D2\u05D3\u05D5\u05DC \u05DE", ">"),
1510
+ cmp("lt", "\u05E7\u05D8\u05DF \u05DE", "<"),
1511
+ cmp("ge", "\u05D2\u05D3\u05D5\u05DC \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4 \u05DC", ">="),
1512
+ cmp("le", "\u05E7\u05D8\u05DF \u05D0\u05D5 \u05E9\u05D5\u05D5\u05D4 \u05DC", "<="),
1513
+ ...EMPTY_OPS2
1514
+ ];
1515
+ var DATE_OPS = [
1516
+ cmp("eq", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA", "="),
1517
+ cmp("ne", "\u05DC\u05D0 \u05D1\u05EA\u05D0\u05E8\u05D9\u05DA", "<>"),
1518
+ cmp("gt", "\u05D0\u05D7\u05E8\u05D9", ">"),
1519
+ cmp("lt", "\u05DC\u05E4\u05E0\u05D9", "<"),
1520
+ cmp("ge", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA \u05D0\u05D5 \u05D0\u05D7\u05E8\u05D9\u05D5", ">="),
1521
+ cmp("le", "\u05D1\u05EA\u05D0\u05E8\u05D9\u05DA \u05D0\u05D5 \u05DC\u05E4\u05E0\u05D9\u05D5", "<="),
1522
+ ...EMPTY_OPS2
1523
+ ];
1524
+ var TEXT_OPS = [
1525
+ cmp("eq", "\u05E9\u05D5\u05D5\u05D4 \u05DC", "="),
1526
+ cmp("ne", "\u05E9\u05D5\u05E0\u05D4 \u05DE", "<>"),
1527
+ { id: "contains", label: "\u05DE\u05DB\u05D9\u05DC", needsValue: true, build: (f, v) => `CONTAINS(${f}, ${literal(v, true)})` },
1528
+ { id: "starts", label: "\u05DE\u05EA\u05D7\u05D9\u05DC \u05D1", needsValue: true, build: (f, v) => `STARTSWITH(${f}, ${literal(v, true)})` },
1529
+ { id: "ends", label: "\u05DE\u05E1\u05EA\u05D9\u05D9\u05DD \u05D1", needsValue: true, build: (f, v) => `ENDSWITH(${f}, ${literal(v, true)})` },
1530
+ ...EMPTY_OPS2
1531
+ ];
1532
+ var BOOL_OPS = [
1533
+ { id: "yes", label: "\u05DE\u05E1\u05D5\u05DE\u05DF (\u05DB\u05DF)", needsValue: false, build: (f) => `${f} = 1` },
1534
+ { id: "no", label: "\u05DC\u05D0 \u05DE\u05E1\u05D5\u05DE\u05DF (\u05DC\u05D0)", needsValue: false, build: (f) => `${f} = 0` }
1535
+ ];
1536
+ var opsOf = (type) => type === "NUMBER" || type === "CURRENCY" ? NUMBER_OPS : type === "DATE" ? DATE_OPS : type === "BOOLEAN" ? BOOL_OPS : TEXT_OPS;
1537
+ var isTextual = (type) => !(type === "NUMBER" || type === "CURRENCY");
1538
+ var EMPTY_IF_CONDITION = { field: "", op: "", value: "" };
1539
+ var getIfConditionOps = (type) => opsOf(type).map(({ id, label, needsValue }) => ({ id, label, needsValue }));
1540
+ function buildIfConditionExpression(columns, c) {
1541
+ const col = columns.find((x) => x.name === c.field);
1542
+ if (!col) return null;
1543
+ const op2 = opsOf(col.type).find((o) => o.id === c.op);
1544
+ if (!op2) return null;
1545
+ if (op2.needsValue && !c.value.trim()) return null;
1546
+ return op2.build(`{${col.name}}`, c.value.trim(), isTextual(col.type));
1547
+ }
1548
+ function buildIfExpression(columns, conds, joiner, thenVal, elseVal) {
1549
+ const parts = conds.map((c) => buildIfConditionExpression(columns, c));
1550
+ if (parts.some((p) => p === null)) return { error: "\u05D9\u05E9 \u05DC\u05D4\u05E9\u05DC\u05D9\u05DD \u05D1\u05DB\u05DC \u05EA\u05E0\u05D0\u05D9: \u05E9\u05D3\u05D4, \u05E4\u05E2\u05D5\u05DC\u05D4 \u05D5\u05E2\u05E8\u05DA" };
1551
+ const condText = parts.length === 1 ? parts[0] : `${joiner}(${parts.join(", ")})`;
1552
+ if (thenVal === void 0 || elseVal === void 0) return { expression: condText };
1553
+ return { expression: `IF(${condText}, ${operand(thenVal)}, ${operand(elseVal)})` };
1554
+ }
1555
+
1201
1556
  // src/components/TableBlock/TableBlockClient.tsx
1202
- import React14, { useState as useState16, useMemo as useMemo8, useEffect as useEffect14, useCallback as useCallback12, useRef as useRef14 } from "react";
1557
+ import React15, { useState as useState16, useMemo as useMemo8, useEffect as useEffect14, useCallback as useCallback13, useRef as useRef15 } from "react";
1203
1558
 
1204
1559
  // src/hooks/useToast.ts
1205
1560
  import { useContext as useContext2 } from "react";
@@ -3857,6 +4212,8 @@ var NUMERIC = ["NUMBER", "CURRENCY"];
3857
4212
  var OPS = ["+", "-", "*", "/", "(", ")"];
3858
4213
  var selCls = "w-full px-2 py-1 border border-slate-300 rounded text-sm bg-white";
3859
4214
  var lblCls = "block text-[11px] text-slate-600 mb-0.5";
4215
+ var smallBtn = "px-2 py-1 text-xs rounded border border-slate-300 bg-white hover:bg-slate-100";
4216
+ var typeLabel = (t) => FORMULA_TYPE_LABELS[t] || (t === "RELATION" ? "\u05E7\u05E9\u05E8" : t === "FORMULA" ? "\u05E0\u05D5\u05E1\u05D7\u05D4" : t);
3860
4217
  var RecordPicker = ({ tableId, executeAction, value, onPick }) => {
3861
4218
  const [q, setQ] = useState8("");
3862
4219
  const [options, setOptions] = useState8([]);
@@ -3904,7 +4261,88 @@ var RecordPicker = ({ tableId, executeAction, value, onPick }) => {
3904
4261
  )
3905
4262
  ] });
3906
4263
  };
3907
- var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear, onClose }) => {
4264
+ var FilterEditor = ({ columns, conds, join, onChange }) => {
4265
+ const update = (i, patch) => onChange(conds.map((c, idx) => idx === i ? __spreadValues(__spreadValues({}, c), patch) : c), join);
4266
+ return /* @__PURE__ */ jsxs8("div", { className: "space-y-1.5 pt-1.5 border-t border-slate-200", children: [
4267
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05E1\u05D9\u05E0\u05D5\u05DF: \u05DC\u05E1\u05DB\u05DD \u05E8\u05E7 \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05E9\u05E2\u05D5\u05DE\u05D3\u05D5\u05EA \u05D1\u05EA\u05E0\u05D0\u05D9 (\u05DC\u05D0 \u05D7\u05D5\u05D1\u05D4)" }),
4268
+ conds.map((c, i) => {
4269
+ const col = columns.find((x) => x.name === c.field);
4270
+ const ops = col ? getFilterOps(col.type) : [];
4271
+ const op2 = ops.find((o) => o.id === c.op);
4272
+ const kind = filterKindOfType(col == null ? void 0 : col.type);
4273
+ return /* @__PURE__ */ jsxs8("div", { className: "space-y-1 p-1.5 rounded bg-white border border-slate-200", children: [
4274
+ /* @__PURE__ */ jsxs8("div", { className: "flex items-center justify-between", children: [
4275
+ /* @__PURE__ */ jsx8("span", { className: "text-[11px] font-medium text-slate-600", children: i === 0 ? "\u05E8\u05E7 \u05D0\u05DD" : join === "AND" ? "\u05D5\u05D2\u05DD" : "\u05D0\u05D5" }),
4276
+ /* @__PURE__ */ jsx8(
4277
+ "button",
4278
+ {
4279
+ type: "button",
4280
+ className: "text-[11px] text-rose-600 hover:underline",
4281
+ onClick: () => onChange(conds.filter((_, idx) => idx !== i), join),
4282
+ children: "\u05D4\u05E1\u05E8"
4283
+ }
4284
+ )
4285
+ ] }),
4286
+ /* @__PURE__ */ jsxs8(
4287
+ "select",
4288
+ {
4289
+ className: selCls,
4290
+ value: c.field,
4291
+ onChange: (e) => update(i, { field: e.target.value, op: "", value: "" }),
4292
+ children: [
4293
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05E9\u05D3\u05D4 --" }),
4294
+ columns.map((x) => /* @__PURE__ */ jsxs8("option", { value: x.name, children: [
4295
+ x.name,
4296
+ " (",
4297
+ typeLabel(x.type),
4298
+ ")"
4299
+ ] }, x.name))
4300
+ ]
4301
+ }
4302
+ ),
4303
+ col && /* @__PURE__ */ jsxs8("select", { className: selCls, value: c.op, onChange: (e) => update(i, { op: e.target.value, value: "" }), children: [
4304
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05E4\u05E2\u05D5\u05DC\u05D4 --" }),
4305
+ ops.map((o) => /* @__PURE__ */ jsx8("option", { value: o.id, children: o.label }, o.id))
4306
+ ] }),
4307
+ (op2 == null ? void 0 : op2.needsValue) && /* @__PURE__ */ jsx8(
4308
+ "input",
4309
+ {
4310
+ className: selCls,
4311
+ type: kind === "date" ? "date" : "text",
4312
+ value: c.value,
4313
+ onChange: (e) => update(i, { value: e.target.value }),
4314
+ placeholder: kind === "relation" ? "\u05D4\u05E2\u05E8\u05DA \u05DB\u05E4\u05D9 \u05E9\u05DE\u05D5\u05E6\u05D2 \u05D1\u05D8\u05D1\u05DC\u05D4" : "\u05E2\u05E8\u05DA \u05DC\u05D4\u05E9\u05D5\u05D5\u05D0\u05D4"
4315
+ }
4316
+ )
4317
+ ] }, i);
4318
+ }),
4319
+ /* @__PURE__ */ jsxs8("div", { className: "flex items-center gap-2", children: [
4320
+ /* @__PURE__ */ jsx8(
4321
+ "button",
4322
+ {
4323
+ type: "button",
4324
+ disabled: conds.length >= MAX_FILTER_CONDITIONS,
4325
+ className: smallBtn,
4326
+ onClick: () => onChange([...conds, { field: "", op: "", value: "" }], join),
4327
+ children: "+ \u05D4\u05D5\u05E1\u05E3 \u05EA\u05E0\u05D0\u05D9 \u05E1\u05D9\u05E0\u05D5\u05DF"
4328
+ }
4329
+ ),
4330
+ conds.length > 1 && /* @__PURE__ */ jsxs8(
4331
+ "select",
4332
+ {
4333
+ className: "px-2 py-1 border border-slate-300 rounded text-xs bg-white",
4334
+ value: join,
4335
+ onChange: (e) => onChange(conds, e.target.value),
4336
+ children: [
4337
+ /* @__PURE__ */ jsx8("option", { value: "AND", children: "\u05DB\u05DC \u05D4\u05EA\u05E0\u05D0\u05D9\u05DD (\u05D5\u05D2\u05DD)" }),
4338
+ /* @__PURE__ */ jsx8("option", { value: "OR", children: "\u05DC\u05E4\u05D7\u05D5\u05EA \u05D0\u05D7\u05D3 (\u05D0\u05D5)" })
4339
+ ]
4340
+ }
4341
+ )
4342
+ ] })
4343
+ ] });
4344
+ };
4345
+ var CellFormulaEditor = ({ initial, rowColumns, context, anchor, onApply, onClear, onClose }) => {
3908
4346
  const executeAction = context == null ? void 0 : context.executeAction;
3909
4347
  const taRef = useRef8(null);
3910
4348
  const [expression, setExpression] = useState8((initial == null ? void 0 : initial.expression) || "");
@@ -3917,6 +4355,13 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
3917
4355
  const [rec, setRec] = useState8({ id: "", label: "" });
3918
4356
  const [fld, setFld] = useState8("");
3919
4357
  const [agg, setAgg] = useState8("SUM");
4358
+ const [fConds, setFConds] = useState8([]);
4359
+ const [fJoin, setFJoin] = useState8("AND");
4360
+ const [ifConds, setIfConds] = useState8([__spreadValues({}, EMPTY_IF_CONDITION)]);
4361
+ const [ifJoin, setIfJoin] = useState8("AND");
4362
+ const [thenVal, setThenVal] = useState8("");
4363
+ const [elseVal, setElseVal] = useState8("");
4364
+ const [builderError, setBuilderError] = useState8("");
3920
4365
  useEffect7(() => {
3921
4366
  (async () => {
3922
4367
  var _a, _b;
@@ -3931,8 +4376,11 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
3931
4376
  })();
3932
4377
  }, [executeAction]);
3933
4378
  const table = tables == null ? void 0 : tables.find((t) => t.id === tId);
3934
- const tableFields = ((table == null ? void 0 : table.columns) || []).filter((c) => panel === "agg" ? NUMERIC.includes(c.type) : true);
3935
- const insert = (text2) => {
4379
+ const valueFields = ((table == null ? void 0 : table.columns) || []).filter(
4380
+ (c) => FORMULA_SOURCE_TYPES.includes(c.type) && (panel === "agg" ? NUMERIC.includes(c.type) : true)
4381
+ );
4382
+ const rowFieldNames = useMemo4(() => rowColumns.map((c) => c.name), [rowColumns]);
4383
+ const insert = (text2, caret) => {
3936
4384
  var _a, _b;
3937
4385
  const el = taRef.current;
3938
4386
  const s = (_a = el == null ? void 0 : el.selectionStart) != null ? _a : expression.length;
@@ -3940,38 +4388,53 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
3940
4388
  const next = expression.slice(0, s) + text2 + expression.slice(e);
3941
4389
  setExpression(next);
3942
4390
  setError("");
4391
+ const pos = s + (caret != null ? caret : text2.length);
3943
4392
  requestAnimationFrame(() => {
3944
4393
  el == null ? void 0 : el.focus();
3945
- const p = s + text2.length;
3946
- el == null ? void 0 : el.setSelectionRange(p, p);
4394
+ el == null ? void 0 : el.setSelectionRange(pos, pos);
3947
4395
  });
3948
4396
  };
4397
+ const readFilter = () => {
4398
+ const started = fConds.filter((c) => c.field || c.op || c.value);
4399
+ const filter = sanitizeRefFilter({ join: fJoin, conditions: started });
4400
+ const incomplete = started.length > 0 && (!filter || filter.conditions.length !== started.length);
4401
+ return { filter, incomplete };
4402
+ };
3949
4403
  const addRef = () => {
3950
4404
  if (!table || !fld) return;
3951
4405
  if (panel === "cell" && !rec.id) return;
3952
4406
  const isAgg = panel === "agg";
3953
- const same = refs.find((r) => r.tableId === table.id && r.field === fld && (isAgg ? r.agg === agg : !r.agg && r.recordId === rec.id));
4407
+ const { filter, incomplete } = isAgg ? readFilter() : { filter: null, incomplete: false };
4408
+ if (incomplete) {
4409
+ setError("\u05D9\u05E9 \u05DC\u05D4\u05E9\u05DC\u05D9\u05DD \u05D1\u05DB\u05DC \u05EA\u05E0\u05D0\u05D9 \u05E1\u05D9\u05E0\u05D5\u05DF: \u05E9\u05D3\u05D4, \u05E4\u05E2\u05D5\u05DC\u05D4 \u05D5\u05E2\u05E8\u05DA (\u05D0\u05D5 \u05DC\u05D4\u05E1\u05D9\u05E8 \u05D0\u05D5\u05EA\u05D5)");
4410
+ return;
4411
+ }
4412
+ const sig = filterSignature(filter);
4413
+ const same = refs.find((r) => r.tableId === table.id && r.field === fld && (isAgg ? r.agg === agg && filterSignature(r.filter) === sig : !r.agg && r.recordId === rec.id));
3954
4414
  let key;
3955
4415
  if (same) key = same.key;
3956
4416
  else {
3957
4417
  key = makeCellRefKey(refs, fld, isAgg ? agg : void 0);
3958
- setRefs((prev) => [...prev, __spreadValues({
4418
+ setRefs((prev) => [...prev, __spreadValues(__spreadValues({
3959
4419
  key,
3960
4420
  tableId: table.id,
3961
4421
  tableName: table.name,
3962
4422
  recordId: isAgg ? "" : rec.id,
3963
4423
  recordLabel: isAgg ? "" : rec.label,
3964
4424
  field: fld
3965
- }, isAgg ? { agg } : {})]);
4425
+ }, isAgg ? { agg } : {}), isAgg && filter ? { filter } : {})]);
3966
4426
  }
3967
4427
  insert(`{${key}}`);
4428
+ setError("");
3968
4429
  setPanel("");
3969
4430
  setFld("");
4431
+ setFConds([]);
3970
4432
  };
3971
4433
  const used = useMemo4(() => new Set(extractFormulaFields(expression)), [expression]);
3972
4434
  const usedRefs = refs.filter((r) => used.has(r.key));
4435
+ const live = expression.trim() ? validateFormula(expression, [...rowFieldNames, ...refs.map((r) => r.key)]) : null;
3973
4436
  const apply = () => {
3974
- const err = validateFormula(expression, [...rowFields, ...refs.map((r) => r.key)]);
4437
+ const err = validateFormula(expression, [...rowFieldNames, ...refs.map((r) => r.key)]);
3975
4438
  if (err) {
3976
4439
  setError(err);
3977
4440
  return;
@@ -3983,7 +4446,28 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
3983
4446
  setTId("");
3984
4447
  setFld("");
3985
4448
  setRec({ id: "", label: "" });
4449
+ setFConds([]);
4450
+ setError("");
4451
+ };
4452
+ const updateIfCond = (i, patch) => setIfConds((prev) => prev.map((c, idx) => idx === i ? __spreadValues(__spreadValues({}, c), patch) : c));
4453
+ const insertBuilt = (withIf) => {
4454
+ const res = withIf ? buildIfExpression(rowColumns, ifConds, ifJoin, thenVal, elseVal) : buildIfExpression(rowColumns, ifConds, ifJoin);
4455
+ if ("error" in res) {
4456
+ setBuilderError(res.error);
4457
+ return;
4458
+ }
4459
+ setBuilderError("");
4460
+ insert(res.expression);
3986
4461
  };
4462
+ const rowFieldOptions = /* @__PURE__ */ jsxs8(Fragment3, { children: [
4463
+ /* @__PURE__ */ jsx8("option", { value: "", children: rowColumns.length === 0 ? "-- \u05D0\u05D9\u05DF \u05E9\u05D3\u05D5\u05EA \u05DE\u05EA\u05D0\u05D9\u05DE\u05D9\u05DD \u05D1\u05D8\u05D1\u05DC\u05D4 \u05D4\u05D6\u05D5 --" : "-- \u05D1\u05D7\u05E8 \u05E9\u05D3\u05D4 --" }),
4464
+ rowColumns.map((c) => /* @__PURE__ */ jsxs8("option", { value: c.name, children: [
4465
+ c.name,
4466
+ " (",
4467
+ typeLabel(c.type),
4468
+ ")"
4469
+ ] }, c.name))
4470
+ ] });
3987
4471
  return createPortal3(
3988
4472
  /* @__PURE__ */ jsxs8(Fragment3, { children: [
3989
4473
  /* @__PURE__ */ jsx8("div", { className: "fixed inset-0 z-[9998]", onClick: onClose }),
@@ -3991,7 +4475,7 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
3991
4475
  "div",
3992
4476
  {
3993
4477
  dir: "rtl",
3994
- className: "fixed z-[9999] w-[340px] max-h-[80vh] overflow-auto p-3 bg-white border border-slate-200 rounded-lg shadow-xl space-y-2",
4478
+ className: "fixed z-[9999] w-[380px] max-h-[85vh] overflow-auto p-3 bg-white border border-slate-200 rounded-lg shadow-xl space-y-2",
3995
4479
  style: { top: anchor.top, left: anchor.left },
3996
4480
  children: [
3997
4481
  /* @__PURE__ */ jsx8("div", { className: "text-sm font-semibold text-slate-700", children: "\u05E0\u05D5\u05E1\u05D7\u05D4 \u05DC\u05EA\u05D0" }),
@@ -4000,7 +4484,7 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4000
4484
  {
4001
4485
  ref: taRef,
4002
4486
  dir: "ltr",
4003
- rows: 2,
4487
+ rows: 3,
4004
4488
  value: expression,
4005
4489
  onChange: (e) => {
4006
4490
  setExpression(e.target.value);
@@ -4010,6 +4494,7 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4010
4494
  className: "w-full px-2 py-1.5 border border-slate-300 rounded text-sm font-mono bg-white"
4011
4495
  }
4012
4496
  ),
4497
+ live && /* @__PURE__ */ jsx8("div", { className: "text-[11px] text-rose-500", children: live }),
4013
4498
  usedRefs.length > 0 && /* @__PURE__ */ jsx8("div", { className: "flex flex-wrap gap-1", children: usedRefs.map((r) => /* @__PURE__ */ jsxs8(
4014
4499
  "span",
4015
4500
  {
@@ -4021,11 +4506,55 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4021
4506
  /* @__PURE__ */ jsxs8("span", { className: "text-slate-400", children: [
4022
4507
  "\xB7 ",
4023
4508
  r.tableName
4509
+ ] }),
4510
+ r.filter && /* @__PURE__ */ jsxs8("span", { className: "text-amber-600", children: [
4511
+ " \xB7 ",
4512
+ describeRefFilter(r.filter)
4024
4513
  ] })
4025
4514
  ]
4026
4515
  },
4027
4516
  r.key
4028
4517
  )) }),
4518
+ /* @__PURE__ */ jsxs8("div", { className: "grid grid-cols-3 gap-1.5", children: [
4519
+ /* @__PURE__ */ jsxs8("div", { children: [
4520
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D4\u05D5\u05E1\u05E3 \u05E9\u05D3\u05D4" }),
4521
+ /* @__PURE__ */ jsx8(
4522
+ "select",
4523
+ {
4524
+ className: selCls,
4525
+ value: "",
4526
+ disabled: rowColumns.length === 0,
4527
+ onChange: (e) => e.target.value && insert(`{${e.target.value}}`),
4528
+ children: rowFieldOptions
4529
+ }
4530
+ )
4531
+ ] }),
4532
+ /* @__PURE__ */ jsxs8("div", { children: [
4533
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D4\u05D5\u05E1\u05E3 \u05D0\u05D5\u05E4\u05E8\u05D8\u05D5\u05E8" }),
4534
+ /* @__PURE__ */ jsxs8("select", { className: selCls, value: "", onChange: (e) => e.target.value && insert(e.target.value), children: [
4535
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 --" }),
4536
+ FORMULA_OPERATOR_GROUPS.map((g) => /* @__PURE__ */ jsx8("optgroup", { label: g.label, children: g.items.map((it) => /* @__PURE__ */ jsx8("option", { value: it.insert, children: it.label }, it.label)) }, g.label))
4537
+ ] })
4538
+ ] }),
4539
+ /* @__PURE__ */ jsxs8("div", { children: [
4540
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D4\u05D5\u05E1\u05E3 \u05E4\u05D5\u05E0\u05E7\u05E6\u05D9\u05D4" }),
4541
+ /* @__PURE__ */ jsxs8(
4542
+ "select",
4543
+ {
4544
+ className: selCls,
4545
+ value: "",
4546
+ onChange: (e) => {
4547
+ const tpl = e.target.value;
4548
+ if (tpl) insert(tpl, tpl.indexOf("(") + 1);
4549
+ },
4550
+ children: [
4551
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 --" }),
4552
+ FORMULA_FUNCTION_GROUPS.map((g) => /* @__PURE__ */ jsx8("optgroup", { label: g.label, children: g.items.map((it) => /* @__PURE__ */ jsx8("option", { value: it.template, children: it.label }, it.label)) }, g.label))
4553
+ ]
4554
+ }
4555
+ )
4556
+ ] })
4557
+ ] }),
4029
4558
  /* @__PURE__ */ jsx8("div", { className: "flex items-center gap-1", style: { direction: "ltr" }, children: OPS.map((o) => /* @__PURE__ */ jsx8(
4030
4559
  "button",
4031
4560
  {
@@ -4036,13 +4565,6 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4036
4565
  },
4037
4566
  o
4038
4567
  )) }),
4039
- rowFields.length > 0 && /* @__PURE__ */ jsxs8("div", { children: [
4040
- /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05E9\u05D3\u05D4 \u05DE\u05D0\u05D5\u05EA\u05D4 \u05E9\u05D5\u05E8\u05D4" }),
4041
- /* @__PURE__ */ jsxs8("select", { className: selCls, value: "", onChange: (e) => e.target.value && insert(`{${e.target.value}}`), children: [
4042
- /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D4\u05D5\u05E1\u05E3 \u05E9\u05D3\u05D4 --" }),
4043
- rowFields.map((f) => /* @__PURE__ */ jsx8("option", { value: f, children: f }, f))
4044
- ] })
4045
- ] }),
4046
4568
  /* @__PURE__ */ jsxs8("div", { className: "flex gap-1.5", children: [
4047
4569
  /* @__PURE__ */ jsx8(
4048
4570
  "button",
@@ -4069,14 +4591,23 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4069
4591
  tables && /* @__PURE__ */ jsxs8(Fragment3, { children: [
4070
4592
  /* @__PURE__ */ jsxs8("div", { children: [
4071
4593
  /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D8\u05D1\u05DC\u05D4" }),
4072
- /* @__PURE__ */ jsxs8("select", { className: selCls, value: tId, onChange: (e) => {
4073
- setTId(e.target.value);
4074
- setFld("");
4075
- setRec({ id: "", label: "" });
4076
- }, children: [
4077
- /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05D8\u05D1\u05DC\u05D4 --" }),
4078
- tables.filter((t) => panel === "cell" || t.columns.some((c) => NUMERIC.includes(c.type))).map((t) => /* @__PURE__ */ jsx8("option", { value: t.id, children: t.name }, t.id))
4079
- ] })
4594
+ /* @__PURE__ */ jsxs8(
4595
+ "select",
4596
+ {
4597
+ className: selCls,
4598
+ value: tId,
4599
+ onChange: (e) => {
4600
+ setTId(e.target.value);
4601
+ setFld("");
4602
+ setRec({ id: "", label: "" });
4603
+ setFConds([]);
4604
+ },
4605
+ children: [
4606
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05D8\u05D1\u05DC\u05D4 --" }),
4607
+ tables.filter((t) => panel === "cell" || t.columns.some((c) => NUMERIC.includes(c.type))).map((t) => /* @__PURE__ */ jsx8("option", { value: t.id, children: t.name }, t.id))
4608
+ ]
4609
+ }
4610
+ )
4080
4611
  ] }),
4081
4612
  panel === "cell" && tId && /* @__PURE__ */ jsxs8("div", { children: [
4082
4613
  /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05E8\u05E9\u05D5\u05DE\u05D4" }),
@@ -4094,13 +4625,26 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4094
4625
  /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05E2\u05DE\u05D5\u05D3\u05D4" }),
4095
4626
  /* @__PURE__ */ jsxs8("select", { className: selCls, value: fld, onChange: (e) => setFld(e.target.value), children: [
4096
4627
  /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05E2\u05DE\u05D5\u05D3\u05D4 --" }),
4097
- tableFields.filter((c) => FORMULA_SOURCE_TYPES.includes(c.type)).map((c) => /* @__PURE__ */ jsx8("option", { value: c.name, children: c.name }, c.name))
4628
+ valueFields.map((c) => /* @__PURE__ */ jsx8("option", { value: c.name, children: c.name }, c.name))
4098
4629
  ] })
4099
4630
  ] }),
4100
4631
  panel === "agg" && /* @__PURE__ */ jsxs8("div", { children: [
4101
4632
  /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05E4\u05E2\u05D5\u05DC\u05D4" }),
4102
4633
  /* @__PURE__ */ jsx8("select", { className: selCls, value: agg, onChange: (e) => setAgg(e.target.value), children: PER_RECORD_SOURCE_AGGS.map((a) => /* @__PURE__ */ jsx8("option", { value: a, children: PER_RECORD_AGG_LABELS[a] }, a)) })
4103
4634
  ] }),
4635
+ panel === "agg" && table && /* @__PURE__ */ jsx8(
4636
+ FilterEditor,
4637
+ {
4638
+ columns: table.columns.filter((c) => !String(c.name).startsWith("_")),
4639
+ conds: fConds,
4640
+ join: fJoin,
4641
+ onChange: (c, j) => {
4642
+ setFConds(c);
4643
+ setFJoin(j);
4644
+ setError("");
4645
+ }
4646
+ }
4647
+ ),
4104
4648
  /* @__PURE__ */ jsx8(
4105
4649
  "button",
4106
4650
  {
@@ -4113,6 +4657,138 @@ var CellFormulaEditor = ({ initial, rowFields, context, anchor, onApply, onClear
4113
4657
  )
4114
4658
  ] })
4115
4659
  ] }),
4660
+ /* @__PURE__ */ jsxs8("details", { className: "rounded border border-slate-200 bg-white", children: [
4661
+ /* @__PURE__ */ jsx8("summary", { className: "cursor-pointer select-none px-2 py-1.5 text-xs font-semibold text-slate-700", children: "\u05D1\u05D5\u05E0\u05D4 \u05EA\u05E0\u05D0\u05D9 (\u05D0\u05DD... \u05D0\u05D6... \u05D0\u05D7\u05E8\u05EA)" }),
4662
+ /* @__PURE__ */ jsxs8("div", { className: "p-2 space-y-2 border-t border-slate-200", children: [
4663
+ ifConds.map((c, i) => {
4664
+ const col = rowColumns.find((x) => x.name === c.field);
4665
+ const ops = col ? getIfConditionOps(col.type) : [];
4666
+ const op2 = ops.find((o) => o.id === c.op);
4667
+ return /* @__PURE__ */ jsxs8("div", { className: "space-y-1.5 p-2 rounded bg-slate-50 border border-slate-200", children: [
4668
+ /* @__PURE__ */ jsxs8("div", { className: "flex items-center justify-between", children: [
4669
+ /* @__PURE__ */ jsx8("span", { className: "text-[11px] font-medium text-slate-600", children: i === 0 ? "\u05D0\u05DD" : ifJoin === "AND" ? "\u05D5\u05D2\u05DD" : "\u05D0\u05D5" }),
4670
+ ifConds.length > 1 && /* @__PURE__ */ jsx8(
4671
+ "button",
4672
+ {
4673
+ type: "button",
4674
+ className: "text-[11px] text-rose-600 hover:underline",
4675
+ onClick: () => setIfConds((prev) => prev.filter((_, idx) => idx !== i)),
4676
+ children: "\u05D4\u05E1\u05E8 \u05EA\u05E0\u05D0\u05D9"
4677
+ }
4678
+ )
4679
+ ] }),
4680
+ /* @__PURE__ */ jsx8(
4681
+ "select",
4682
+ {
4683
+ className: selCls,
4684
+ value: c.field,
4685
+ onChange: (e) => updateIfCond(i, { field: e.target.value, op: "", value: "" }),
4686
+ children: rowFieldOptions
4687
+ }
4688
+ ),
4689
+ col && /* @__PURE__ */ jsxs8("select", { className: selCls, value: c.op, onChange: (e) => updateIfCond(i, { op: e.target.value, value: "" }), children: [
4690
+ /* @__PURE__ */ jsx8("option", { value: "", children: "-- \u05D1\u05D7\u05E8 \u05E4\u05E2\u05D5\u05DC\u05D4 --" }),
4691
+ ops.map((o) => /* @__PURE__ */ jsx8("option", { value: o.id, children: o.label }, o.id))
4692
+ ] }),
4693
+ (op2 == null ? void 0 : op2.needsValue) && /* @__PURE__ */ jsxs8("div", { className: "grid grid-cols-2 gap-1.5", children: [
4694
+ /* @__PURE__ */ jsx8(
4695
+ "input",
4696
+ {
4697
+ type: (col == null ? void 0 : col.type) === "DATE" ? "date" : "text",
4698
+ value: c.value,
4699
+ onChange: (e) => updateIfCond(i, { value: e.target.value }),
4700
+ placeholder: "\u05E2\u05E8\u05DA \u05DC\u05D4\u05E9\u05D5\u05D5\u05D0\u05D4",
4701
+ className: selCls
4702
+ }
4703
+ ),
4704
+ /* @__PURE__ */ jsxs8(
4705
+ "select",
4706
+ {
4707
+ className: selCls,
4708
+ value: "",
4709
+ onChange: (e) => e.target.value && updateIfCond(i, { value: `{${e.target.value}}` }),
4710
+ children: [
4711
+ /* @__PURE__ */ jsx8("option", { value: "", children: "...\u05D0\u05D5 \u05E9\u05D3\u05D4 \u05D0\u05D7\u05E8" }),
4712
+ rowColumns.filter((s) => s.name !== c.field).map((s) => /* @__PURE__ */ jsx8("option", { value: s.name, children: s.name }, s.name))
4713
+ ]
4714
+ }
4715
+ )
4716
+ ] })
4717
+ ] }, i);
4718
+ }),
4719
+ /* @__PURE__ */ jsxs8("div", { className: "flex items-center gap-2", children: [
4720
+ /* @__PURE__ */ jsx8(
4721
+ "button",
4722
+ {
4723
+ type: "button",
4724
+ disabled: ifConds.length >= 5,
4725
+ className: smallBtn,
4726
+ onClick: () => setIfConds((prev) => [...prev, __spreadValues({}, EMPTY_IF_CONDITION)]),
4727
+ children: "+ \u05D4\u05D5\u05E1\u05E3 \u05EA\u05E0\u05D0\u05D9"
4728
+ }
4729
+ ),
4730
+ ifConds.length > 1 && /* @__PURE__ */ jsxs8(
4731
+ "select",
4732
+ {
4733
+ className: "px-2 py-1 border border-slate-300 rounded text-xs bg-white",
4734
+ value: ifJoin,
4735
+ onChange: (e) => setIfJoin(e.target.value),
4736
+ children: [
4737
+ /* @__PURE__ */ jsx8("option", { value: "AND", children: "\u05DB\u05DC \u05D4\u05EA\u05E0\u05D0\u05D9\u05DD (\u05D5\u05D2\u05DD)" }),
4738
+ /* @__PURE__ */ jsx8("option", { value: "OR", children: "\u05DC\u05E4\u05D7\u05D5\u05EA \u05D0\u05D7\u05D3 (\u05D0\u05D5)" })
4739
+ ]
4740
+ }
4741
+ )
4742
+ ] }),
4743
+ /* @__PURE__ */ jsxs8("div", { className: "grid grid-cols-2 gap-2", children: [
4744
+ /* @__PURE__ */ jsxs8("div", { children: [
4745
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D0\u05DD \u05D4\u05EA\u05E0\u05D0\u05D9 \u05DE\u05EA\u05E7\u05D9\u05D9\u05DD, \u05D4\u05EA\u05D5\u05E6\u05D0\u05D4:" }),
4746
+ /* @__PURE__ */ jsx8("input", { value: thenVal, onChange: (e) => setThenVal(e.target.value), placeholder: "\u05DE\u05E1\u05E4\u05E8, \u05D8\u05E7\u05E1\u05D8 \u05D0\u05D5 \u05E9\u05D3\u05D4", className: selCls }),
4747
+ /* @__PURE__ */ jsxs8(
4748
+ "select",
4749
+ {
4750
+ className: `${selCls} mt-1`,
4751
+ value: "",
4752
+ onChange: (e) => e.target.value && setThenVal(`{${e.target.value}}`),
4753
+ children: [
4754
+ /* @__PURE__ */ jsx8("option", { value: "", children: "...\u05D0\u05D5 \u05E9\u05D3\u05D4" }),
4755
+ rowColumns.map((s) => /* @__PURE__ */ jsx8("option", { value: s.name, children: s.name }, s.name))
4756
+ ]
4757
+ }
4758
+ )
4759
+ ] }),
4760
+ /* @__PURE__ */ jsxs8("div", { children: [
4761
+ /* @__PURE__ */ jsx8("label", { className: lblCls, children: "\u05D0\u05D7\u05E8\u05EA, \u05D4\u05EA\u05D5\u05E6\u05D0\u05D4:" }),
4762
+ /* @__PURE__ */ jsx8("input", { value: elseVal, onChange: (e) => setElseVal(e.target.value), placeholder: "\u05DE\u05E1\u05E4\u05E8, \u05D8\u05E7\u05E1\u05D8 \u05D0\u05D5 \u05E9\u05D3\u05D4", className: selCls }),
4763
+ /* @__PURE__ */ jsxs8(
4764
+ "select",
4765
+ {
4766
+ className: `${selCls} mt-1`,
4767
+ value: "",
4768
+ onChange: (e) => e.target.value && setElseVal(`{${e.target.value}}`),
4769
+ children: [
4770
+ /* @__PURE__ */ jsx8("option", { value: "", children: "...\u05D0\u05D5 \u05E9\u05D3\u05D4" }),
4771
+ rowColumns.map((s) => /* @__PURE__ */ jsx8("option", { value: s.name, children: s.name }, s.name))
4772
+ ]
4773
+ }
4774
+ )
4775
+ ] })
4776
+ ] }),
4777
+ builderError && /* @__PURE__ */ jsx8("p", { className: "text-[11px] text-rose-500", children: builderError }),
4778
+ /* @__PURE__ */ jsxs8("div", { className: "flex flex-wrap gap-2", children: [
4779
+ /* @__PURE__ */ jsx8(
4780
+ "button",
4781
+ {
4782
+ type: "button",
4783
+ onClick: () => insertBuilt(true),
4784
+ className: "px-3 py-1.5 text-xs rounded bg-slate-800 text-white hover:bg-slate-700",
4785
+ children: "\u05D4\u05D5\u05E1\u05E3 \u05EA\u05E0\u05D0\u05D9 IF \u05DC\u05E0\u05D5\u05E1\u05D7\u05D4"
4786
+ }
4787
+ ),
4788
+ /* @__PURE__ */ jsx8("button", { type: "button", onClick: () => insertBuilt(false), className: smallBtn, children: "\u05D4\u05D5\u05E1\u05E3 \u05E8\u05E7 \u05D0\u05EA \u05D4\u05EA\u05E0\u05D0\u05D9" })
4789
+ ] })
4790
+ ] })
4791
+ ] }),
4116
4792
  error && /* @__PURE__ */ jsx8("div", { className: "text-xs text-red-600", children: error }),
4117
4793
  /* @__PURE__ */ jsxs8("div", { className: "flex gap-2 pt-1", children: [
4118
4794
  /* @__PURE__ */ jsx8(
@@ -4160,16 +4836,16 @@ var PerRecordSourceCell = ({ value, column, onChange, readOnly, context }) => {
4160
4836
  const btnRef = useRef8(null);
4161
4837
  const [open, setOpen] = useState8(false);
4162
4838
  const [pos, setPos] = useState8({ top: 0, left: 0 });
4163
- const rowFields = useMemo4(() => {
4839
+ const rowColumns = useMemo4(() => {
4164
4840
  const cols = Array.isArray(context == null ? void 0 : context.columns) ? context.columns : [];
4165
- return cols.filter((c) => (c == null ? void 0 : c.name) && c.name !== column.name && !String(c.name).startsWith("_") && FORMULA_SOURCE_TYPES.includes(String(c.type).toUpperCase())).map((c) => c.name);
4841
+ return cols.filter((c) => (c == null ? void 0 : c.name) && c.name !== column.name && !String(c.name).startsWith("_") && FORMULA_SOURCE_TYPES.includes(String(c.type).toUpperCase())).map((c) => ({ name: c.name, type: String(c.type).toUpperCase() }));
4166
4842
  }, [context == null ? void 0 : context.columns, column.name]);
4167
4843
  const openEditor = () => {
4168
4844
  var _a2;
4169
4845
  const r = (_a2 = btnRef.current) == null ? void 0 : _a2.getBoundingClientRect();
4170
4846
  if (r) {
4171
- const left = Math.max(8, Math.min(r.left, window.innerWidth - 356));
4172
- const top = Math.min(r.bottom + 4, Math.max(8, window.innerHeight - 420));
4847
+ const left = Math.max(8, Math.min(r.left, window.innerWidth - 396));
4848
+ const top = Math.min(r.bottom + 4, Math.max(8, window.innerHeight - 440));
4173
4849
  setPos({ top, left });
4174
4850
  }
4175
4851
  setOpen(true);
@@ -4192,7 +4868,7 @@ var PerRecordSourceCell = ({ value, column, onChange, readOnly, context }) => {
4192
4868
  CellFormulaEditor,
4193
4869
  {
4194
4870
  initial: current,
4195
- rowFields,
4871
+ rowColumns,
4196
4872
  context,
4197
4873
  anchor: pos,
4198
4874
  onClose: () => setOpen(false),
@@ -6525,68 +7201,139 @@ function RelationFilterPopover({
6525
7201
  }
6526
7202
 
6527
7203
  // src/components/TableBlock/RelationButtonsBar.tsx
6528
- import { useEffect as useEffect12, useMemo as useMemo7, useRef as useRef12, useState as useState14 } from "react";
7204
+ import { useCallback as useCallback12, useEffect as useEffect12, useMemo as useMemo7, useRef as useRef13, useState as useState14 } from "react";
6529
7205
 
6530
7206
  // src/components/TableBlock/RelationButtonsView.tsx
7207
+ import { useRef as useRef12 } from "react";
6531
7208
  import { jsx as jsx15, jsxs as jsxs13 } from "react/jsx-runtime";
6532
- function RelationButtonsView({ groups, onSelect, disabled, stacked = false }) {
7209
+ var MIN_GROUP_WIDTH = 140;
7210
+ function RelationButtonsView({
7211
+ groups,
7212
+ onSelect,
7213
+ disabled,
7214
+ stacked = false,
7215
+ widths,
7216
+ onResize,
7217
+ onResizeEnd
7218
+ }) {
7219
+ const containerRef = useRef12(null);
7220
+ const dragRef = useRef12(null);
7221
+ const resizable = !stacked && !!onResize;
6533
7222
  const visible = groups.filter((g) => g.options.length > 0);
6534
7223
  if (visible.length === 0) return null;
6535
- return /* @__PURE__ */ jsx15("div", { className: `grid grid-cols-1 gap-2.5 ${stacked ? "" : "md:grid-cols-2"}`, children: visible.map((group) => {
6536
- const titleIsDuplicate = group.options.some(
6537
- (opt) => opt.label.trim() === group.title.trim()
6538
- );
6539
- return /* @__PURE__ */ jsx15(
6540
- "div",
6541
- {
6542
- className: "bg-white border border-slate-200 rounded-xl px-3 py-2.5 shadow-2xs",
6543
- children: /* @__PURE__ */ jsxs13("div", { className: "flex flex-wrap items-end gap-x-2 gap-y-2.5", children: [
6544
- !titleIsDuplicate && /* @__PURE__ */ jsx15(
6545
- "span",
6546
- {
6547
- className: "self-end h-8 inline-flex items-center text-xs font-bold text-slate-800 max-w-[10rem] truncate",
6548
- title: group.title,
6549
- children: group.title
6550
- }
6551
- ),
6552
- group.options.map((opt) => {
6553
- const active = group.activeId === opt.id;
6554
- return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center gap-0.5", children: [
6555
- /* @__PURE__ */ jsx15(
6556
- "span",
6557
- {
6558
- className: `text-[11px] font-bold leading-none ${active ? "text-indigo-700" : "text-slate-500"}`,
6559
- children: opt.count
6560
- }
6561
- ),
6562
- /* @__PURE__ */ jsx15(
6563
- "button",
7224
+ const handlePointerDown = (e, key) => {
7225
+ var _a, _b;
7226
+ if (!onResize) return;
7227
+ e.preventDefault();
7228
+ const box = e.currentTarget.parentElement;
7229
+ const rtl = getComputedStyle(box).direction === "rtl";
7230
+ dragRef.current = {
7231
+ key,
7232
+ startX: e.clientX,
7233
+ startWidth: box.getBoundingClientRect().width,
7234
+ // הידית בקצה הסופי של המתחם: ב-RTL זה הצד השמאלי (גרירה שמאלה מגדילה), ב-LTR הצד הימני
7235
+ sign: rtl ? -1 : 1,
7236
+ max: (_b = (_a = containerRef.current) == null ? void 0 : _a.clientWidth) != null ? _b : 4e3
7237
+ };
7238
+ e.currentTarget.setPointerCapture(e.pointerId);
7239
+ };
7240
+ const handlePointerMove = (e) => {
7241
+ const d = dragRef.current;
7242
+ if (!d || !onResize) return;
7243
+ const next = d.startWidth + (e.clientX - d.startX) * d.sign;
7244
+ const clamped = Math.max(MIN_GROUP_WIDTH, Math.min(d.max, next));
7245
+ onResize(d.key, Math.round(clamped));
7246
+ };
7247
+ const handlePointerUp = () => {
7248
+ if (!dragRef.current) return;
7249
+ dragRef.current = null;
7250
+ onResizeEnd == null ? void 0 : onResizeEnd();
7251
+ };
7252
+ return /* @__PURE__ */ jsx15(
7253
+ "div",
7254
+ {
7255
+ ref: containerRef,
7256
+ className: `flex gap-2.5 ${stacked ? "flex-col" : "flex-wrap items-start"}`,
7257
+ children: visible.map((group) => {
7258
+ const titleIsDuplicate = group.options.some(
7259
+ (opt) => opt.label.trim() === group.title.trim()
7260
+ );
7261
+ const customWidth = resizable ? widths == null ? void 0 : widths[group.key] : void 0;
7262
+ const sizeClass = stacked ? "w-full" : customWidth ? "" : "w-full md:w-[calc(50%_-_5px)]";
7263
+ return /* @__PURE__ */ jsxs13(
7264
+ "div",
7265
+ {
7266
+ style: customWidth ? { width: customWidth, maxWidth: "100%" } : void 0,
7267
+ className: `relative min-w-0 bg-white border border-slate-200 rounded-xl px-3 py-2.5 shadow-2xs ${sizeClass}`,
7268
+ children: [
7269
+ /* @__PURE__ */ jsxs13("div", { className: "flex flex-wrap items-end gap-x-2 gap-y-2.5", children: [
7270
+ !titleIsDuplicate && /* @__PURE__ */ jsx15(
7271
+ "span",
7272
+ {
7273
+ className: "self-end h-8 inline-flex items-center text-xs font-bold text-slate-800 max-w-[10rem] truncate",
7274
+ title: group.title,
7275
+ children: group.title
7276
+ }
7277
+ ),
7278
+ group.options.map((opt) => {
7279
+ const active = group.activeId === opt.id;
7280
+ return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col items-center gap-0.5", children: [
7281
+ /* @__PURE__ */ jsx15(
7282
+ "span",
7283
+ {
7284
+ className: `text-[11px] font-bold leading-none ${active ? "text-indigo-700" : "text-slate-500"}`,
7285
+ children: opt.count
7286
+ }
7287
+ ),
7288
+ /* @__PURE__ */ jsx15(
7289
+ "button",
7290
+ {
7291
+ type: "button",
7292
+ disabled,
7293
+ onClick: () => onSelect(group.key, active ? void 0 : opt.id),
7294
+ title: active ? "\u05DC\u05D7\u05E5 \u05DC\u05D1\u05D9\u05D8\u05D5\u05DC \u05D4\u05E1\u05D9\u05E0\u05D5\u05DF" : `\u05E1\u05E0\u05DF \u05DC\u05E4\u05D9: ${opt.label}`,
7295
+ "aria-pressed": active,
7296
+ className: `px-3 h-8 rounded-md border text-xs font-semibold whitespace-nowrap shadow-2xs transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none ${active ? "bg-indigo-600 border-indigo-600 text-white hover:bg-indigo-700" : "bg-white border-slate-300 text-slate-700 hover:bg-slate-50 hover:border-slate-400"}`,
7297
+ children: opt.label
7298
+ }
7299
+ )
7300
+ ] }, opt.id);
7301
+ }),
7302
+ group.activeId ? /* @__PURE__ */ jsx15(
7303
+ "button",
7304
+ {
7305
+ type: "button",
7306
+ onClick: () => onSelect(group.key, void 0),
7307
+ className: "self-end h-8 inline-flex items-center px-1 text-[11px] font-semibold text-rose-600 hover:text-rose-700 hover:underline cursor-pointer shrink-0 whitespace-nowrap",
7308
+ children: "\u05E0\u05E7\u05D4 \u05E1\u05D9\u05E0\u05D5\u05DF"
7309
+ }
7310
+ ) : null
7311
+ ] }),
7312
+ resizable && /* @__PURE__ */ jsx15(
7313
+ "div",
6564
7314
  {
6565
- type: "button",
6566
- disabled,
6567
- onClick: () => onSelect(group.key, active ? void 0 : opt.id),
6568
- title: active ? "\u05DC\u05D7\u05E5 \u05DC\u05D1\u05D9\u05D8\u05D5\u05DC \u05D4\u05E1\u05D9\u05E0\u05D5\u05DF" : `\u05E1\u05E0\u05DF \u05DC\u05E4\u05D9: ${opt.label}`,
6569
- "aria-pressed": active,
6570
- className: `px-3 h-8 rounded-md border text-xs font-semibold whitespace-nowrap shadow-2xs transition-colors cursor-pointer disabled:opacity-50 disabled:pointer-events-none ${active ? "bg-indigo-600 border-indigo-600 text-white hover:bg-indigo-700" : "bg-white border-slate-300 text-slate-700 hover:bg-slate-50 hover:border-slate-400"}`,
6571
- children: opt.label
7315
+ role: "separator",
7316
+ "aria-orientation": "vertical",
7317
+ title: "\u05D2\u05E8\u05D5\u05E8 \u05DC\u05E9\u05D9\u05E0\u05D5\u05D9 \u05D4\u05E8\u05D5\u05D7\u05D1 (\u05DC\u05D7\u05D9\u05E6\u05D4 \u05DB\u05E4\u05D5\u05DC\u05D4 \u05DC\u05D0\u05D9\u05E4\u05D5\u05E1)",
7318
+ onPointerDown: (e) => handlePointerDown(e, group.key),
7319
+ onPointerMove: handlePointerMove,
7320
+ onPointerUp: handlePointerUp,
7321
+ onPointerCancel: handlePointerUp,
7322
+ onDoubleClick: () => {
7323
+ onResize == null ? void 0 : onResize(group.key, void 0);
7324
+ onResizeEnd == null ? void 0 : onResizeEnd();
7325
+ },
7326
+ className: "group/handle absolute top-0 bottom-0 end-0 w-2.5 cursor-col-resize touch-none z-10 flex items-center justify-center",
7327
+ children: /* @__PURE__ */ jsx15("span", { className: "h-8 w-0.5 rounded-full bg-slate-300 group-hover/handle:bg-brand transition-colors" })
6572
7328
  }
6573
7329
  )
6574
- ] }, opt.id);
6575
- }),
6576
- group.activeId ? /* @__PURE__ */ jsx15(
6577
- "button",
6578
- {
6579
- type: "button",
6580
- onClick: () => onSelect(group.key, void 0),
6581
- className: "self-end h-8 inline-flex items-center px-1 text-[11px] font-semibold text-rose-600 hover:text-rose-700 hover:underline cursor-pointer shrink-0 whitespace-nowrap",
6582
- children: "\u05E0\u05E7\u05D4 \u05E1\u05D9\u05E0\u05D5\u05DF"
6583
- }
6584
- ) : null
6585
- ] })
6586
- },
6587
- group.key
6588
- );
6589
- }) });
7330
+ ]
7331
+ },
7332
+ group.key
7333
+ );
7334
+ })
7335
+ }
7336
+ );
6590
7337
  }
6591
7338
 
6592
7339
  // src/components/TableBlock/RelationButtonsBar.tsx
@@ -6608,9 +7355,40 @@ function RelationButtonsBar({
6608
7355
  const buttonCols = useMemo7(() => getRelationButtonColumns(columns), [columns]);
6609
7356
  const colsKey = useMemo7(() => buttonCols.map((c) => c.name).join("|"), [buttonCols]);
6610
7357
  const [counts, setCounts] = useState14({});
6611
- const requestIdRef = useRef12(0);
6612
- const actionRef = useRef12(executeAction);
7358
+ const requestIdRef = useRef13(0);
7359
+ const actionRef = useRef13(executeAction);
6613
7360
  actionRef.current = executeAction;
7361
+ const widthsStorageKey = tableId ? `relation_buttons_widths_${tableId}` : "";
7362
+ const [widths, setWidths] = useState14({});
7363
+ const widthsRef = useRef13({});
7364
+ widthsRef.current = widths;
7365
+ useEffect12(() => {
7366
+ if (typeof window === "undefined" || !widthsStorageKey) return;
7367
+ try {
7368
+ const saved = localStorage.getItem(widthsStorageKey);
7369
+ setWidths(saved ? JSON.parse(saved) : {});
7370
+ } catch (e) {
7371
+ console.error(`Failed to load relation button widths for key "${widthsStorageKey}":`, e);
7372
+ }
7373
+ }, [widthsStorageKey]);
7374
+ const handleResize = useCallback12((colName, width) => {
7375
+ setWidths((prev) => {
7376
+ const next = __spreadValues({}, prev);
7377
+ if (width === void 0) delete next[colName];
7378
+ else next[colName] = width;
7379
+ return next;
7380
+ });
7381
+ }, []);
7382
+ const handleResizeEnd = useCallback12(() => {
7383
+ if (typeof window === "undefined" || !widthsStorageKey) return;
7384
+ setTimeout(() => {
7385
+ try {
7386
+ localStorage.setItem(widthsStorageKey, JSON.stringify(widthsRef.current));
7387
+ } catch (e) {
7388
+ console.error(`Failed to save relation button widths for key "${widthsStorageKey}":`, e);
7389
+ }
7390
+ }, 0);
7391
+ }, [widthsStorageKey]);
6614
7392
  useEffect12(() => {
6615
7393
  if (!colsKey || !tableId || !actionRef.current) return;
6616
7394
  const myId = ++requestIdRef.current;
@@ -6625,7 +7403,12 @@ function RelationButtonsBar({
6625
7403
  const groups = useMemo7(
6626
7404
  () => buttonCols.map((col) => {
6627
7405
  const v = columnFilters == null ? void 0 : columnFilters[col.name];
6628
- const activeId = Array.isArray(v) && v.length === 1 ? String(v[0]) : null;
7406
+ let activeId = null;
7407
+ if (isBooleanButtonsColumn(col)) {
7408
+ activeId = v === "true" || v === "false" ? v : null;
7409
+ } else {
7410
+ activeId = Array.isArray(v) && v.length === 1 ? String(v[0]) : null;
7411
+ }
6629
7412
  return {
6630
7413
  key: col.name,
6631
7414
  title: col.name,
@@ -6635,6 +7418,19 @@ function RelationButtonsBar({
6635
7418
  }),
6636
7419
  [buttonCols, counts, columnFilters]
6637
7420
  );
7421
+ const handleSelect = useCallback12(
7422
+ (colName, id) => {
7423
+ const col = buttonCols.find((c) => c.name === colName);
7424
+ if (id === void 0) {
7425
+ onApplyFilter(colName, void 0);
7426
+ } else if (isBooleanButtonsColumn(col)) {
7427
+ onApplyFilter(colName, id);
7428
+ } else {
7429
+ onApplyFilter(colName, [id]);
7430
+ }
7431
+ },
7432
+ [buttonCols, onApplyFilter]
7433
+ );
6638
7434
  if (buttonCols.length === 0 || groups.every((g) => g.options.length === 0)) return null;
6639
7435
  return /* @__PURE__ */ jsx16(
6640
7436
  "div",
@@ -6646,7 +7442,10 @@ function RelationButtonsBar({
6646
7442
  {
6647
7443
  groups,
6648
7444
  disabled,
6649
- onSelect: (colName, id) => onApplyFilter(colName, id ? [id] : void 0)
7445
+ onSelect: handleSelect,
7446
+ widths,
7447
+ onResize: handleResize,
7448
+ onResizeEnd: handleResizeEnd
6650
7449
  }
6651
7450
  )
6652
7451
  }
@@ -6654,7 +7453,7 @@ function RelationButtonsBar({
6654
7453
  }
6655
7454
 
6656
7455
  // src/components/TableBlock/useDefaultColumnFilters.ts
6657
- import { useEffect as useEffect13, useRef as useRef13, useState as useState15 } from "react";
7456
+ import { useEffect as useEffect13, useRef as useRef14, useState as useState15 } from "react";
6658
7457
  var RESOLVE_TIMEOUT_MS = 8e3;
6659
7458
  function unwrap2(res) {
6660
7459
  const body = (res == null ? void 0 : res.data) && typeof res.data === "object" && !Array.isArray(res.data) ? res.data : res;
@@ -6664,10 +7463,10 @@ function unwrap2(res) {
6664
7463
  function useDefaultColumnFilters({ columns, tableId, executeAction, onResolved }) {
6665
7464
  const hasDefaults = getDefaultFilterColumns(columns).length > 0;
6666
7465
  const [ready, setReady] = useState15(() => !hasDefaults);
6667
- const doneRef = useRef13(false);
6668
- const onResolvedRef = useRef13(onResolved);
7466
+ const doneRef = useRef14(false);
7467
+ const onResolvedRef = useRef14(onResolved);
6669
7468
  onResolvedRef.current = onResolved;
6670
- const actionRef = useRef13(executeAction);
7469
+ const actionRef = useRef14(executeAction);
6671
7470
  actionRef.current = executeAction;
6672
7471
  useEffect13(() => {
6673
7472
  if (doneRef.current || !hasDefaults) return;
@@ -6728,7 +7527,7 @@ function TableBlockClient({
6728
7527
  const { showError, addToast } = useToast();
6729
7528
  const [isExporting, setIsExporting] = useState16(false);
6730
7529
  const [isExportMenuOpen, setIsExportMenuOpen] = useState16(false);
6731
- const exportMenuRef = useRef14(null);
7530
+ const exportMenuRef = useRef15(null);
6732
7531
  useEffect14(() => {
6733
7532
  if (!isExportMenuOpen) return;
6734
7533
  const handleClickOutside = (e) => {
@@ -6764,7 +7563,7 @@ function TableBlockClient({
6764
7563
  return calculateMinColumnWidth(colName, false, col == null ? void 0 : col.type);
6765
7564
  }
6766
7565
  });
6767
- const executeActionRef = useRef14(executeAction);
7566
+ const executeActionRef = useRef15(executeAction);
6768
7567
  useEffect14(() => {
6769
7568
  executeActionRef.current = executeAction;
6770
7569
  }, [executeAction]);
@@ -6824,7 +7623,7 @@ function TableBlockClient({
6824
7623
  return __spreadProps(__spreadValues({}, row), { id: String(row.id || ""), data: rowData });
6825
7624
  });
6826
7625
  };
6827
- const mergeColumnDefs = useCallback12((existingCols, incomingCols) => {
7626
+ const mergeColumnDefs = useCallback13((existingCols, incomingCols) => {
6828
7627
  if (!incomingCols || incomingCols.length === 0) return existingCols || [];
6829
7628
  if (!existingCols || existingCols.length === 0) return incomingCols;
6830
7629
  const existingMap = new Map(existingCols.map((c) => [c.name, c]));
@@ -6851,11 +7650,11 @@ function TableBlockClient({
6851
7650
  }
6852
7651
  }, [schema == null ? void 0 : schema.columns, mergeColumnDefs]);
6853
7652
  const [dirty, setDirty] = useState16({ added: [], modified: {}, deleted: [] });
6854
- const dirtyRef = useRef14(dirty);
7653
+ const dirtyRef = useRef15(dirty);
6855
7654
  useEffect14(() => {
6856
7655
  dirtyRef.current = dirty;
6857
7656
  }, [dirty]);
6858
- const mergeWithDirty = useCallback12((baseRecords) => {
7657
+ const mergeWithDirty = useCallback13((baseRecords) => {
6859
7658
  const { added, modified, deleted } = dirtyRef.current;
6860
7659
  const nonDeleted = (baseRecords || []).filter((r) => !deleted.includes(r.id));
6861
7660
  const modifiedRecords = nonDeleted.map((r) => {
@@ -6896,15 +7695,15 @@ function TableBlockClient({
6896
7695
  const [searchQuery, setSearchQuery] = useState16("");
6897
7696
  const [columnFilters, setColumnFilters] = useState16({});
6898
7697
  const [activeSearchCol, setActiveSearchCol] = useState16(null);
6899
- const activeSearchRef = useRef14(null);
7698
+ const activeSearchRef = useRef15(null);
6900
7699
  const [activeRelationCol, setActiveRelationCol] = useState16(null);
6901
7700
  const [relationTriggerRect, setRelationTriggerRect] = useState16(null);
6902
- const filterButtonRefs = useRef14({});
7701
+ const filterButtonRefs = useRef15({});
6903
7702
  const [relationOptions, setRelationOptions] = useState16({});
6904
7703
  const [relationFilterOptions, setRelationFilterOptions] = useState16({});
6905
7704
  const [loadingFilterCol, setLoadingFilterCol] = useState16(null);
6906
- const relationDictionaryRef = useRef14({});
6907
- const mergeRelationOptions = useCallback12((colName, newOptions) => {
7705
+ const relationDictionaryRef = useRef15({});
7706
+ const mergeRelationOptions = useCallback13((colName, newOptions) => {
6908
7707
  if (!Array.isArray(newOptions) || newOptions.length === 0) return;
6909
7708
  if (!relationDictionaryRef.current[colName]) {
6910
7709
  relationDictionaryRef.current[colName] = /* @__PURE__ */ new Map();
@@ -6961,7 +7760,7 @@ function TableBlockClient({
6961
7760
  }, 300);
6962
7761
  return () => clearTimeout(timer);
6963
7762
  }, [searchQuery]);
6964
- const isSearchMountedRef = useRef14(false);
7763
+ const isSearchMountedRef = useRef15(false);
6965
7764
  useEffect14(() => {
6966
7765
  if (!isSearchMountedRef.current) {
6967
7766
  isSearchMountedRef.current = true;
@@ -6970,8 +7769,8 @@ function TableBlockClient({
6970
7769
  setPage(1);
6971
7770
  }, [debouncedSearch]);
6972
7771
  const [isFetching, setIsFetching] = useState16(false);
6973
- const fetchRequestIdRef = useRef14(0);
6974
- const fetchTableData = useCallback12((targetPage, targetLimit, targetSearch, targetFiltersKey) => {
7772
+ const fetchRequestIdRef = useRef15(0);
7773
+ const fetchTableData = useCallback13((targetPage, targetLimit, targetSearch, targetFiltersKey) => {
6975
7774
  const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
6976
7775
  const action = executeActionRef.current;
6977
7776
  if (!tableId || !action) {
@@ -7060,12 +7859,12 @@ function TableBlockClient({
7060
7859
  setLocalColumns((prev) => mergeColumnDefs(prev, res.schema.columns));
7061
7860
  }
7062
7861
  if (res.records && Array.isArray(res.records)) {
7063
- const norm = normalizeRecords(res.records);
7862
+ const norm2 = normalizeRecords(res.records);
7064
7863
  const map = /* @__PURE__ */ new Map();
7065
- norm.forEach((r) => map.set(r.id, __spreadValues({}, r.data)));
7864
+ norm2.forEach((r) => map.set(r.id, __spreadValues({}, r.data)));
7066
7865
  setBaseRecordsMap(map);
7067
- setServerRecords(norm);
7068
- setData(mergeWithDirty(norm));
7866
+ setServerRecords(norm2);
7867
+ setData(mergeWithDirty(norm2));
7069
7868
  }
7070
7869
  if (res.meta) {
7071
7870
  const total = typeof res.meta.totalRecords === "number" ? res.meta.totalRecords : 0;
@@ -7101,13 +7900,13 @@ function TableBlockClient({
7101
7900
  }, [page, limit, debouncedSearch, filtersKey, fetchTableData, defaultFiltersReady]);
7102
7901
  useEffect14(() => {
7103
7902
  if (initialRecords && defaultFiltersReady) {
7104
- const norm = normalizeRecords(initialRecords);
7105
- setServerRecords(norm);
7903
+ const norm2 = normalizeRecords(initialRecords);
7904
+ setServerRecords(norm2);
7106
7905
  const hasActiveFilters = Boolean(debouncedSearch) || Object.keys(columnFilters).length > 0;
7107
7906
  if (hasActiveFilters && executeActionRef.current) {
7108
7907
  fetchTableData(page, limit, debouncedSearch, filtersKey);
7109
7908
  } else if (hasActiveFilters) {
7110
- let locallyFiltered = norm;
7909
+ let locallyFiltered = norm2;
7111
7910
  if (debouncedSearch) {
7112
7911
  const q = debouncedSearch.toLowerCase();
7113
7912
  locallyFiltered = locallyFiltered.filter(
@@ -7158,14 +7957,14 @@ function TableBlockClient({
7158
7957
  }
7159
7958
  setData(mergeWithDirty(locallyFiltered));
7160
7959
  } else {
7161
- setData(mergeWithDirty(norm));
7960
+ setData(mergeWithDirty(norm2));
7162
7961
  }
7163
7962
  }
7164
7963
  }, [initialRecords, mergeWithDirty, debouncedSearch, columnFilters, fetchTableData, page, limit, filtersKey, defaultFiltersReady]);
7165
- const refetchTableData = useCallback12(() => {
7964
+ const refetchTableData = useCallback13(() => {
7166
7965
  return fetchTableData(page, limit, debouncedSearch, filtersKey);
7167
7966
  }, [page, limit, debouncedSearch, filtersKey, fetchTableData]);
7168
- const handleApplyColumnFilter = useCallback12((colName, nextVal) => {
7967
+ const handleApplyColumnFilter = useCallback13((colName, nextVal) => {
7169
7968
  setColumnFilters((prev) => {
7170
7969
  const next = __spreadValues({}, prev);
7171
7970
  if (nextVal === void 0 || Array.isArray(nextVal) && nextVal.length === 0 || typeof nextVal === "string" && !nextVal.trim() || typeof nextVal === "object" && "values" in nextVal && Array.isArray(nextVal.values) && nextVal.values.length === 0) {
@@ -7191,7 +7990,7 @@ function TableBlockClient({
7191
7990
  setPage((prev) => Math.min(totalPages, prev + 1));
7192
7991
  };
7193
7992
  const [selectedIds, setSelectedIds] = useState16(/* @__PURE__ */ new Set());
7194
- const isExternalSyncRef = useRef14(false);
7993
+ const isExternalSyncRef = useRef15(false);
7195
7994
  useEffect14(() => {
7196
7995
  if (selectedRowIds !== void 0) {
7197
7996
  const nextSet = new Set(selectedRowIds);
@@ -7204,7 +8003,7 @@ function TableBlockClient({
7204
8003
  });
7205
8004
  }
7206
8005
  }, [selectedRowIds]);
7207
- const isFirstSelectionChangeRef = useRef14(true);
8006
+ const isFirstSelectionChangeRef = useRef15(true);
7208
8007
  useEffect14(() => {
7209
8008
  if (isFirstSelectionChangeRef.current) {
7210
8009
  isFirstSelectionChangeRef.current = false;
@@ -7222,7 +8021,7 @@ function TableBlockClient({
7222
8021
  const [isSaveSuccess, setIsSaveSuccess] = useState16(false);
7223
8022
  const [expandedRowIds, setExpandedRowIds] = useState16(/* @__PURE__ */ new Set());
7224
8023
  const schemaColsString = useMemo8(() => JSON.stringify(localColumns || []), [localColumns]);
7225
- const refetchRelation = useCallback12(async (colName, params) => {
8024
+ const refetchRelation = useCallback13(async (colName, params) => {
7226
8025
  var _a, _b, _c, _d, _e, _f, _g;
7227
8026
  let parsedCols = [];
7228
8027
  try {
@@ -7261,7 +8060,7 @@ function TableBlockClient({
7261
8060
  }
7262
8061
  return [];
7263
8062
  }, [schemaColsString, executeAction, mergeRelationOptions]);
7264
- const fetchRelationFilterOptions = useCallback12(async (colName) => {
8063
+ const fetchRelationFilterOptions = useCallback13(async (colName) => {
7265
8064
  var _a;
7266
8065
  let parsedCols = [];
7267
8066
  try {
@@ -7297,7 +8096,7 @@ function TableBlockClient({
7297
8096
  setLoadingFilterCol(null);
7298
8097
  }
7299
8098
  }, [schemaColsString, schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.id, executeAction, mergeRelationOptions]);
7300
- const requestedRelationIdsRef = useRef14({});
8099
+ const requestedRelationIdsRef = useRef15({});
7301
8100
  useEffect14(() => {
7302
8101
  if (!executeAction || !data || data.length === 0) return;
7303
8102
  let parsedCols = [];
@@ -7388,7 +8187,7 @@ function TableBlockClient({
7388
8187
  return normalizedColumns.filter((col) => !systemFields.includes(col.name));
7389
8188
  }, [normalizedColumns]);
7390
8189
  const [isColumnsDropdownOpen, setIsColumnsDropdownOpen] = useState16(false);
7391
- const dropdownRef = useRef14(null);
8190
+ const dropdownRef = useRef15(null);
7392
8191
  useEffect14(() => {
7393
8192
  const handleClickOutside = (e) => {
7394
8193
  if (dropdownRef.current && !dropdownRef.current.contains(e.target)) {
@@ -7631,7 +8430,7 @@ function TableBlockClient({
7631
8430
  setData((prev) => [newRow, ...prev]);
7632
8431
  setDirty((prev) => __spreadProps(__spreadValues({}, prev), { added: [newRow, ...prev.added] }));
7633
8432
  };
7634
- const handleCellChange = useCallback12((rowId, colName, value) => {
8433
+ const handleCellChange = useCallback13((rowId, colName, value) => {
7635
8434
  setData((prev) => prev.map(
7636
8435
  (row) => row.id === rowId ? __spreadProps(__spreadValues({}, row), { data: __spreadProps(__spreadValues({}, row.data), { [colName]: value }) }) : row
7637
8436
  ));
@@ -7664,13 +8463,13 @@ function TableBlockClient({
7664
8463
  });
7665
8464
  }, [baseRecordsMap]);
7666
8465
  const handleCellChangeWithCopy = useRelationCopyHandler({ columns: localColumns, handleCellChange });
7667
- const triggerSaveSuccess = useCallback12(() => {
8466
+ const triggerSaveSuccess = useCallback13(() => {
7668
8467
  setIsSaveSuccess(true);
7669
8468
  setTimeout(() => {
7670
8469
  setIsSaveSuccess(false);
7671
8470
  }, 2500);
7672
8471
  }, []);
7673
- const handleQuietCellChange = useCallback12((rowId, colName, value) => {
8472
+ const handleQuietCellChange = useCallback13((rowId, colName, value) => {
7674
8473
  setData((prev) => prev.map(
7675
8474
  (row) => row.id === rowId ? __spreadProps(__spreadValues({}, row), { data: __spreadProps(__spreadValues({}, row.data), { [colName]: value }) }) : row
7676
8475
  ));
@@ -7694,12 +8493,12 @@ function TableBlockClient({
7694
8493
  });
7695
8494
  }
7696
8495
  }, []);
7697
- const toggleSelectAll = useCallback12((checked) => {
8496
+ const toggleSelectAll = useCallback13((checked) => {
7698
8497
  onRowToggle == null ? void 0 : onRowToggle("ALL", checked);
7699
8498
  const next = checked ? new Set(filteredData.map((r) => r.id)) : /* @__PURE__ */ new Set();
7700
8499
  setSelectedIds(next);
7701
8500
  }, [filteredData, onRowToggle]);
7702
- const toggleSelectRow = useCallback12((rowId, checked) => {
8501
+ const toggleSelectRow = useCallback13((rowId, checked) => {
7703
8502
  onRowToggle == null ? void 0 : onRowToggle(rowId, checked);
7704
8503
  setSelectedIds((prev) => {
7705
8504
  const next = new Set(prev);
@@ -7708,7 +8507,7 @@ function TableBlockClient({
7708
8507
  return next;
7709
8508
  });
7710
8509
  }, [onRowToggle]);
7711
- const handleToggleExpand = useCallback12((rowId) => {
8510
+ const handleToggleExpand = useCallback13((rowId) => {
7712
8511
  setExpandedRowIds((prev) => {
7713
8512
  const next = new Set(prev);
7714
8513
  if (next.has(rowId)) next.delete(rowId);
@@ -7716,7 +8515,7 @@ function TableBlockClient({
7716
8515
  return next;
7717
8516
  });
7718
8517
  }, []);
7719
- const handleMarkForDeletion = useCallback12((fileId) => {
8518
+ const handleMarkForDeletion = useCallback13((fileId) => {
7720
8519
  setPendingDeletions((prev) => [...prev, fileId]);
7721
8520
  }, []);
7722
8521
  const handleDeleteSelected = () => {
@@ -7945,7 +8744,7 @@ function TableBlockClient({
7945
8744
  setIsSaving(false);
7946
8745
  }
7947
8746
  };
7948
- const getRowRelationLabels = useCallback12((rowVal, col) => {
8747
+ const getRowRelationLabels = useCallback13((rowVal, col) => {
7949
8748
  const ids = normalizeRelationValue(rowVal);
7950
8749
  if (ids.length === 0) return [];
7951
8750
  const options = relationOptions[col.name] || [];
@@ -7964,7 +8763,7 @@ function TableBlockClient({
7964
8763
  return "";
7965
8764
  }).filter(Boolean);
7966
8765
  }, [relationOptions]);
7967
- const getUniqueRelationOptions = useCallback12((col) => {
8766
+ const getUniqueRelationOptions = useCallback13((col) => {
7968
8767
  if (relationFilterOptions[col.name]) {
7969
8768
  return relationFilterOptions[col.name];
7970
8769
  }
@@ -8805,7 +9604,7 @@ function ExpandedSubTables({
8805
9604
  ) })
8806
9605
  ] }) });
8807
9606
  }
8808
- var TableRow = React14.memo(function TableRow2({
9607
+ var TableRow = React15.memo(function TableRow2({
8809
9608
  row,
8810
9609
  isSelected,
8811
9610
  rowStatus,
@@ -8838,7 +9637,7 @@ var TableRow = React14.memo(function TableRow2({
8838
9637
  renderRowExtra
8839
9638
  }) {
8840
9639
  const lockedCopyTargets = getRelationCopyLockedTargets(schema == null ? void 0 : schema.columns);
8841
- return /* @__PURE__ */ jsxs14(React14.Fragment, { children: [
9640
+ return /* @__PURE__ */ jsxs14(React15.Fragment, { children: [
8842
9641
  /* @__PURE__ */ jsxs14("tr", { className: `transition-colors group hover:bg-blue-50 ${isSelected ? "bg-blue-50" : ""}`, children: [
8843
9642
  /* @__PURE__ */ jsx17("td", { className: "border-b border-l border-slate-200 p-1.5 text-center bg-white group-hover:bg-transparent", style: { width: 80, minWidth: 80, maxWidth: 80 }, children: /* @__PURE__ */ jsxs14("div", { className: "flex items-center justify-center gap-1.5", children: [
8844
9643
  rowStatus && (() => {
@@ -8990,7 +9789,7 @@ var TableRow = React14.memo(function TableRow2({
8990
9789
  });
8991
9790
 
8992
9791
  // src/components/TableBlock/formTracking/FormTrackingTableBlock.tsx
8993
- import { useCallback as useCallback13, useState as useState17 } from "react";
9792
+ import { useCallback as useCallback14, useState as useState17 } from "react";
8994
9793
 
8995
9794
  // src/components/TableBlock/formTracking/formTracking.types.ts
8996
9795
  function getFormTrackingConfig(settings) {
@@ -9033,7 +9832,7 @@ function FormTrackingTableBlock(props) {
9033
9832
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (settings == null ? void 0 : settings.tableId) || (settings == null ? void 0 : settings.id);
9034
9833
  const [sentOverrides, setSentOverrides] = useState17({});
9035
9834
  const [busyKey, setBusyKey] = useState17(null);
9036
- const copyLink = useCallback13(
9835
+ const copyLink = useCallback14(
9037
9836
  async (rowId, step) => {
9038
9837
  if (!executeAction || !tableId) return;
9039
9838
  setBusyKey(`${rowId}|${step.formId}|link`);
@@ -9059,7 +9858,7 @@ function FormTrackingTableBlock(props) {
9059
9858
  },
9060
9859
  [executeAction, tableId, addToast, showError]
9061
9860
  );
9062
- const setSent = useCallback13(
9861
+ const setSent = useCallback14(
9063
9862
  async (rowId, step, value) => {
9064
9863
  if (!executeAction || !tableId || !step.sentColumn) return;
9065
9864
  setBusyKey(`${rowId}|${step.formId}|sent`);
@@ -9081,7 +9880,7 @@ function FormTrackingTableBlock(props) {
9081
9880
  );
9082
9881
  const firstFormStep = config == null ? void 0 : config.steps.find((s) => s.kind === "create");
9083
9882
  const firstFormUrl = firstFormStep && tableId ? `${getPlatformOrigin()}/embed/form/${tableId}?form=${firstFormStep.formId}` : "";
9084
- const copyFirstFormLink = useCallback13(async () => {
9883
+ const copyFirstFormLink = useCallback14(async () => {
9085
9884
  if (!firstFormUrl) return;
9086
9885
  try {
9087
9886
  await navigator.clipboard.writeText(firstFormUrl);
@@ -9090,7 +9889,7 @@ function FormTrackingTableBlock(props) {
9090
9889
  window.prompt(`\u05D4\u05E7\u05D9\u05E9\u05D5\u05E8 \u05DC"${firstFormStep == null ? void 0 : firstFormStep.label}" - \u05D4\u05E2\u05EA\u05E7 \u05D9\u05D3\u05E0\u05D9\u05EA:`, firstFormUrl);
9091
9890
  }
9092
9891
  }, [firstFormUrl, firstFormStep, addToast]);
9093
- const renderRowExtra = useCallback13(
9892
+ const renderRowExtra = useCallback14(
9094
9893
  (row) => {
9095
9894
  var _a;
9096
9895
  if (!config) return null;
@@ -9178,7 +9977,7 @@ function TableBlock(props) {
9178
9977
  }
9179
9978
 
9180
9979
  // src/components/PlacementBlock/PlacementBlock.tsx
9181
- import { useState as useState18, useEffect as useEffect15, useRef as useRef15, useCallback as useCallback14, useMemo as useMemo10 } from "react";
9980
+ import { useState as useState18, useEffect as useEffect15, useRef as useRef16, useCallback as useCallback15, useMemo as useMemo10 } from "react";
9182
9981
  import { AgGridReact } from "ag-grid-react";
9183
9982
  import {
9184
9983
  ModuleRegistry,
@@ -9187,7 +9986,7 @@ import {
9187
9986
  import { Filter as Filter2 } from "lucide-react";
9188
9987
 
9189
9988
  // src/components/PlacementBlock/PlacementSettings.tsx
9190
- import React16 from "react";
9989
+ import React17 from "react";
9191
9990
 
9192
9991
  // src/components/PlacementBlock/placementColumns.ts
9193
9992
  var RELATION_SEP = "::";
@@ -9309,7 +10108,7 @@ var SummaryRow = ({ label, value, hint }) => /* @__PURE__ */ jsxs16("div", { cla
9309
10108
  ] });
9310
10109
  var PlacementStatusEditor = ({ config, onChange }) => {
9311
10110
  var _a;
9312
- const radioName = `placement-default-status-${React16.useId()}`;
10111
+ const radioName = `placement-default-status-${React17.useId()}`;
9313
10112
  const statuses = ((_a = config.statusColors) == null ? void 0 : _a.length) ? config.statusColors : DEFAULT_PLACEMENT_STATUS_COLORS;
9314
10113
  const defaultStatusId = resolveDefaultStatusId(statuses, config.defaultReturnStatusId);
9315
10114
  const setStatuses = (next, defId = defaultStatusId) => {
@@ -9792,7 +10591,7 @@ var CheckHeader = (props) => /* @__PURE__ */ jsx22("div", { className: "flex ite
9792
10591
  }
9793
10592
  ) });
9794
10593
  var RelationFilterHeader = (props) => {
9795
- const btnRef = useRef15(null);
10594
+ const btnRef = useRef16(null);
9796
10595
  return /* @__PURE__ */ jsxs18("div", { className: "flex flex-col items-center justify-center w-full min-w-0 leading-tight select-none", title: props.displayName, children: [
9797
10596
  /* @__PURE__ */ jsx22(
9798
10597
  "button",
@@ -9840,9 +10639,9 @@ var PlacementBlock = (props) => {
9840
10639
  const targetTableId = config == null ? void 0 : config.targetTableId;
9841
10640
  const displayField = (config == null ? void 0 : config.sourceDisplayFieldId) || "name";
9842
10641
  const assignmentField = config == null ? void 0 : config.targetAssignmentFieldId;
9843
- const executeActionRef = useRef15(executeAction);
10642
+ const executeActionRef = useRef16(executeAction);
9844
10643
  executeActionRef.current = executeAction;
9845
- const legacyRef = useRef15({ fetchSourceData, fetchTargetData, updateAssignment });
10644
+ const legacyRef = useRef16({ fetchSourceData, fetchTargetData, updateAssignment });
9846
10645
  legacyRef.current = { fetchSourceData, fetchTargetData, updateAssignment };
9847
10646
  const [sourceRows, setSourceRows] = useState18([]);
9848
10647
  const [sourceColumns, setSourceColumns] = useState18([]);
@@ -9864,7 +10663,7 @@ var PlacementBlock = (props) => {
9864
10663
  const [colFilters, setColFilters] = useState18({ source: {}, cand: {} });
9865
10664
  const [filterPopover, setFilterPopover] = useState18(null);
9866
10665
  const [targetFilters, setTargetFilters] = useState18({});
9867
- const loadTable = useCallback14(async (tableId, kind) => {
10666
+ const loadTable = useCallback15(async (tableId, kind) => {
9868
10667
  const exec = executeActionRef.current;
9869
10668
  if (exec) {
9870
10669
  const res = await exec("FETCH_TABLE_DATA", { tableId, tableMetaId: tableId, limit: FETCH_LIMIT, skip: 0 });
@@ -9905,7 +10704,7 @@ var PlacementBlock = (props) => {
9905
10704
  cancelled = true;
9906
10705
  };
9907
10706
  }, [sourceTableId, targetTableId, loadTable]);
9908
- const displayValue = useCallback14((col, val) => {
10707
+ const displayValue = useCallback15((col, val) => {
9909
10708
  var _a2, _b2, _c, _d, _e;
9910
10709
  let text2 = cellText(val);
9911
10710
  if (text2 && /^[a-fA-F0-9]{24}$/.test(text2)) {
@@ -9938,7 +10737,7 @@ var PlacementBlock = (props) => {
9938
10737
  });
9939
10738
  return maps;
9940
10739
  }, [sourceRelOptions]);
9941
- const relationLabelsOf = useCallback14((row, colName) => {
10740
+ const relationLabelsOf = useCallback15((row, colName) => {
9942
10741
  var _a2;
9943
10742
  const map = relationLabelMaps[colName];
9944
10743
  const ids = normalizeRelationValue((_a2 = row.data) == null ? void 0 : _a2[colName]);
@@ -9947,7 +10746,7 @@ var PlacementBlock = (props) => {
9947
10746
  const txt = cellText(readColumnValue(row.data, colName));
9948
10747
  return txt && !/^[a-fA-F0-9]{24}$/.test(txt) ? txt.split(", ").filter(Boolean) : [];
9949
10748
  }, [relationLabelMaps]);
9950
- const rowPassesColFilters = useCallback14((row, filters) => {
10749
+ const rowPassesColFilters = useCallback15((row, filters) => {
9951
10750
  return Object.entries(filters).every(([colName, f]) => {
9952
10751
  if (!f) return true;
9953
10752
  const labels = relationLabelsOf(row, colName);
@@ -9956,7 +10755,7 @@ var PlacementBlock = (props) => {
9956
10755
  return true;
9957
10756
  });
9958
10757
  }, [relationLabelsOf]);
9959
- const setColFilter = useCallback14((grid, colName, payload) => {
10758
+ const setColFilter = useCallback15((grid, colName, payload) => {
9960
10759
  setColFilters((prev) => {
9961
10760
  const next = __spreadValues({}, prev[grid]);
9962
10761
  if (payload === void 0) delete next[colName];
@@ -9964,10 +10763,10 @@ var PlacementBlock = (props) => {
9964
10763
  return __spreadProps(__spreadValues({}, prev), { [grid]: next });
9965
10764
  });
9966
10765
  }, []);
9967
- const openColFilter = useCallback14((grid, colName, rect) => {
10766
+ const openColFilter = useCallback15((grid, colName, rect) => {
9968
10767
  setFilterPopover((cur) => cur && cur.grid === grid && cur.colName === colName ? null : { grid, colName, rect });
9969
10768
  }, []);
9970
- const closeColFilter = useCallback14(() => setFilterPopover(null), []);
10769
+ const closeColFilter = useCallback15(() => setFilterPopover(null), []);
9971
10770
  const filterColumns = useMemo10(() => {
9972
10771
  const definedFilters = (config == null ? void 0 : config.filterFields) || [];
9973
10772
  const legacyFilters = [config == null ? void 0 : config.targetFilterField1Id, config == null ? void 0 : config.targetFilterField2Id].filter(Boolean);
@@ -10022,7 +10821,7 @@ var PlacementBlock = (props) => {
10022
10821
  setSelectedTargetId("");
10023
10822
  }
10024
10823
  }, [filteredTargetRows, selectedTargetId]);
10025
- const appliedDefaultsKeyRef = useRef15("");
10824
+ const appliedDefaultsKeyRef = useRef16("");
10026
10825
  useEffect15(() => {
10027
10826
  const defaults = config == null ? void 0 : config.targetFilterDefaults;
10028
10827
  if (isLoading || !defaults || targetRows.length === 0 || targetColumns.length === 0) return;
@@ -10041,7 +10840,7 @@ var PlacementBlock = (props) => {
10041
10840
  const assignmentColumn = useMemo10(() => targetColumns.find((c) => c.name === assignmentField), [targetColumns, assignmentField]);
10042
10841
  const isRelationField = ((_b = assignmentColumn == null ? void 0 : assignmentColumn.type) == null ? void 0 : _b.toUpperCase()) === "RELATION";
10043
10842
  const assignmentLabel = (assignmentColumn == null ? void 0 : assignmentColumn.label) || (assignmentColumn == null ? void 0 : assignmentColumn.name) || assignmentField || "";
10044
- const nameOf = useCallback14((row) => cellText(readColumnValue(row.data, displayField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD", [displayField]);
10843
+ const nameOf = useCallback15((row) => cellText(readColumnValue(row.data, displayField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD", [displayField]);
10045
10844
  const assignedIds = useMemo10(() => {
10046
10845
  var _a2;
10047
10846
  const target = targetRows.find((r) => r.id === selectedTargetId);
@@ -10056,13 +10855,13 @@ var PlacementBlock = (props) => {
10056
10855
  }).filter((id) => !!id && sourceRows.some((s) => s.id === id));
10057
10856
  return Array.from(new Set(ids));
10058
10857
  }, [selectedTargetId, targetRows, sourceRows, assignmentField, isRelationField, nameOf]);
10059
- const assignedIdsRef = useRef15(assignedIds);
10858
+ const assignedIdsRef = useRef16(assignedIds);
10060
10859
  assignedIdsRef.current = assignedIds;
10061
10860
  useEffect15(() => {
10062
10861
  setCandidateIds(assignedIdsRef.current);
10063
10862
  setCheckedIds(assignedIdsRef.current);
10064
10863
  }, [selectedTargetId, sourceRows]);
10065
- const toGridRow = useCallback14((r, checked = false) => __spreadProps(__spreadValues({}, r.data), { id: r.id, __label: nameOf(r), __checked: checked, statusId: statusMap[r.id] || defaultStatusId }), [nameOf, statusMap, defaultStatusId]);
10864
+ const toGridRow = useCallback15((r, checked = false) => __spreadProps(__spreadValues({}, r.data), { id: r.id, __label: nameOf(r), __checked: checked, statusId: statusMap[r.id] || defaultStatusId }), [nameOf, statusMap, defaultStatusId]);
10066
10865
  const candidateRows = useMemo10(() => candidateIds.map((id) => sourceRows.find((r) => r.id === id)).filter((r) => !!r), [candidateIds, sourceRows]);
10067
10866
  const candidateGridData = useMemo10(() => {
10068
10867
  const checked = new Set(checkedIds);
@@ -10077,7 +10876,7 @@ var PlacementBlock = (props) => {
10077
10876
  return wanted.filter((name) => sourceColumns.some((c) => (c == null ? void 0 : c.name) === name && String(c == null ? void 0 : c.type).toUpperCase() === "RELATION"));
10078
10877
  }, [config, sourceColumns]);
10079
10878
  const hasRelationButtons = relationButtonColumns.length > 0;
10080
- const handleRelationFilterChange = useCallback14((colName, id) => {
10879
+ const handleRelationFilterChange = useCallback15((colName, id) => {
10081
10880
  setSourceRelFilters((prev) => __spreadProps(__spreadValues({}, prev), { [colName]: id }));
10082
10881
  }, []);
10083
10882
  const availableGridData = useMemo10(() => {
@@ -10085,7 +10884,7 @@ var PlacementBlock = (props) => {
10085
10884
  const byButtons = active.length === 0 ? availableRows : availableRows.filter((r) => active.every(([name, v]) => rowMatchesRelationFilter(r, name, v)));
10086
10885
  return byButtons.filter((r) => rowPassesColFilters(r, colFilters.source)).map((r) => toGridRow(r));
10087
10886
  }, [availableRows, sourceRelFilters, relationButtonColumns, toGridRow, rowPassesColFilters, colFilters.source]);
10088
- const persistAssignment = useCallback14(async (nextIds) => {
10887
+ const persistAssignment = useCallback15(async (nextIds) => {
10089
10888
  const exec = executeActionRef.current;
10090
10889
  if (exec && targetTableId && assignmentField && selectedTargetId) {
10091
10890
  const value = isRelationField ? nextIds : nextIds.map((id) => sourceRows.find((r) => r.id === id)).filter((r) => !!r).map(nameOf).join(", ");
@@ -10097,33 +10896,33 @@ var PlacementBlock = (props) => {
10097
10896
  for (const id of nextIds.filter((i) => !assignedIds.includes(i))) await legacyRef.current.updateAssignment(selectedTargetId, id);
10098
10897
  }
10099
10898
  }, [targetTableId, assignmentField, selectedTargetId, isRelationField, sourceRows, nameOf, assignedIds]);
10100
- const moveToCandidates = useCallback14((id) => {
10899
+ const moveToCandidates = useCallback15((id) => {
10101
10900
  setCandidateIds((prev) => prev.includes(id) ? prev : [...prev, id]);
10102
10901
  }, []);
10103
- const moveToSource = useCallback14((id) => {
10902
+ const moveToSource = useCallback15((id) => {
10104
10903
  setCandidateIds((prev) => prev.filter((x) => x !== id));
10105
10904
  setCheckedIds((prev) => prev.filter((x) => x !== id));
10106
10905
  setStatusMap((prev) => __spreadProps(__spreadValues({}, prev), { [id]: defaultStatusId }));
10107
10906
  }, [defaultStatusId]);
10108
- const moveToCandidatesRef = useRef15(moveToCandidates);
10907
+ const moveToCandidatesRef = useRef16(moveToCandidates);
10109
10908
  moveToCandidatesRef.current = moveToCandidates;
10110
- const moveToSourceRef = useRef15(moveToSource);
10909
+ const moveToSourceRef = useRef16(moveToSource);
10111
10910
  moveToSourceRef.current = moveToSource;
10112
- const toggleChecked = useCallback14((id) => {
10911
+ const toggleChecked = useCallback15((id) => {
10113
10912
  setCheckedIds((prev) => prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]);
10114
10913
  }, []);
10115
10914
  const allChecked = candidateIds.length > 0 && candidateIds.every((id) => checkedIds.includes(id));
10116
10915
  const someChecked = candidateIds.some((id) => checkedIds.includes(id));
10117
- const toggleAll = useCallback14(() => {
10916
+ const toggleAll = useCallback15(() => {
10118
10917
  setCheckedIds(allChecked ? [] : [...candidateIds]);
10119
10918
  }, [allChecked, candidateIds]);
10120
- const returnAll = useCallback14(() => {
10919
+ const returnAll = useCallback15(() => {
10121
10920
  setCandidateIds([]);
10122
10921
  setCheckedIds([]);
10123
10922
  }, []);
10124
10923
  const checkedCandidates = useMemo10(() => candidateIds.filter((id) => checkedIds.includes(id)), [candidateIds, checkedIds]);
10125
10924
  const isDirty = checkedCandidates.length !== assignedIds.length || checkedCandidates.some((id) => !assignedIds.includes(id));
10126
- const submitAssignment = useCallback14(async () => {
10925
+ const submitAssignment = useCallback15(async () => {
10127
10926
  if (!selectedTargetId) {
10128
10927
  alert("\u05D0\u05E0\u05D0 \u05D1\u05D7\u05E8 \u05E7\u05D5\u05D3\u05DD \u05E8\u05E9\u05D5\u05DE\u05EA \u05D9\u05E2\u05D3 \u05DC\u05E4\u05E0\u05D9 \u05D4\u05E9\u05D9\u05D1\u05D5\u05E5");
10129
10928
  return;
@@ -10139,14 +10938,14 @@ var PlacementBlock = (props) => {
10139
10938
  setIsSaving(false);
10140
10939
  }
10141
10940
  }, [selectedTargetId, persistAssignment, checkedCandidates]);
10142
- const cycleStatus = useCallback14((recordId) => {
10941
+ const cycleStatus = useCallback15((recordId) => {
10143
10942
  setStatusMap((prev) => {
10144
10943
  const current = prev[recordId] || defaultStatusId;
10145
10944
  const idx = statuses.findIndex((c) => c.id === current);
10146
10945
  return __spreadProps(__spreadValues({}, prev), { [recordId]: statuses[(idx + 1) % statuses.length].id });
10147
10946
  });
10148
10947
  }, [statuses, defaultStatusId]);
10149
- const cancelAssignment = useCallback14(async () => {
10948
+ const cancelAssignment = useCallback15(async () => {
10150
10949
  if (!selectedTargetId || assignedIds.length === 0) return;
10151
10950
  if (!window.confirm(`\u05DC\u05D1\u05D8\u05DC \u05D0\u05EA \u05D4\u05E9\u05D9\u05D1\u05D5\u05E5 \u05D5\u05DC\u05DE\u05D7\u05D5\u05E7 \u05D0\u05EA \u05D4\u05E0\u05EA\u05D5\u05DF \u05DE\u05E9\u05D3\u05D4 "${assignmentLabel}"?`)) return;
10152
10951
  const removed = new Set(assignedIds);
@@ -10162,7 +10961,7 @@ var PlacementBlock = (props) => {
10162
10961
  setIsSaving(false);
10163
10962
  }
10164
10963
  }, [selectedTargetId, assignedIds, assignmentLabel, persistAssignment]);
10165
- const makeColDefs = useCallback14((columns, fallbackName, grid, withCheckbox = false) => {
10964
+ const makeColDefs = useCallback15((columns, fallbackName, grid, withCheckbox = false) => {
10166
10965
  const gridFilters = colFilters[grid];
10167
10966
  const defs = [];
10168
10967
  if (withCheckbox) {
@@ -10214,10 +11013,10 @@ var PlacementBlock = (props) => {
10214
11013
  var _a2;
10215
11014
  return (_a2 = d.colId) != null ? _a2 : d.field;
10216
11015
  }).filter(Boolean);
10217
- const expandColumns = useCallback14((api) => {
11016
+ const expandColumns = useCallback15((api) => {
10218
11017
  api == null ? void 0 : api.sizeColumnsToFit();
10219
11018
  }, []);
10220
- const shrinkColumns = useCallback14((api, defs) => {
11019
+ const shrinkColumns = useCallback15((api, defs) => {
10221
11020
  api == null ? void 0 : api.autoSizeColumns(scrollableColIds(defs));
10222
11021
  }, []);
10223
11022
  const popoverOptions = useMemo10(() => {
@@ -10231,9 +11030,9 @@ var PlacementBlock = (props) => {
10231
11030
  () => filterPopover ? sourceColumns.find((c) => c.name === filterPopover.colName) : void 0,
10232
11031
  [filterPopover, sourceColumns]
10233
11032
  );
10234
- const getRowId = useCallback14((p) => p.data.id, []);
10235
- const sourceContainerRef = useRef15(null);
10236
- const assignedContainerRef = useRef15(null);
11033
+ const getRowId = useCallback15((p) => p.data.id, []);
11034
+ const sourceContainerRef = useRef16(null);
11035
+ const assignedContainerRef = useRef16(null);
10237
11036
  const [sourceApi, setSourceApi] = useState18(null);
10238
11037
  const [assignedApi, setAssignedApi] = useState18(null);
10239
11038
  useEffect15(() => {
@@ -10268,7 +11067,7 @@ var PlacementBlock = (props) => {
10268
11067
  [assignedIds, sourceRows, nameOf]
10269
11068
  );
10270
11069
  const activeTarget = targetRows.find((r) => r.id === selectedTargetId);
10271
- const targetLabel = useCallback14((r) => {
11070
+ const targetLabel = useCallback15((r) => {
10272
11071
  const col = targetColumns.find((c) => c.name === selectorField || c.id === selectorField);
10273
11072
  return displayValue(col || { name: selectorField }, readColumnValue(r.data, selectorField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD";
10274
11073
  }, [selectorField, targetColumns, displayValue]);
@@ -10435,7 +11234,7 @@ var PlacementBlock = (props) => {
10435
11234
  };
10436
11235
 
10437
11236
  // src/components/PaymentReportsBlock/PaymentReportsBlock.tsx
10438
- import { useCallback as useCallback16, useEffect as useEffect16, useMemo as useMemo14, useRef as useRef18, useState as useState23 } from "react";
11237
+ import { useCallback as useCallback17, useEffect as useEffect16, useMemo as useMemo14, useRef as useRef19, useState as useState23 } from "react";
10439
11238
 
10440
11239
  // src/components/PaymentReportsBlock/PaymentReportsBlock.types.ts
10441
11240
  var PAYMENT_REPORTS_REQUIRED = [
@@ -10634,7 +11433,7 @@ function displayCell(item, col, relationOptions, symbol) {
10634
11433
  }
10635
11434
 
10636
11435
  // src/components/PaymentReportsBlock/UnpaidReportsTab.tsx
10637
- import { useMemo as useMemo11, useRef as useRef16, useState as useState20 } from "react";
11436
+ import { useMemo as useMemo11, useRef as useRef17, useState as useState20 } from "react";
10638
11437
  import { AgGridReact as AgGridReact2 } from "ag-grid-react";
10639
11438
  import { ModuleRegistry as ModuleRegistry2, AllCommunityModule as AllCommunityModule2 } from "ag-grid-community";
10640
11439
 
@@ -10694,7 +11493,7 @@ var ConfirmModal = ({ title, message, confirmLabel, danger, busy, onConfirm, onC
10694
11493
  );
10695
11494
 
10696
11495
  // src/components/PaymentReportsBlock/useGridColumnWidths.ts
10697
- import { useCallback as useCallback15, useState as useState19 } from "react";
11496
+ import { useCallback as useCallback16, useState as useState19 } from "react";
10698
11497
  function useGridColumnWidths(storageKey) {
10699
11498
  const [widths, setWidths] = useState19(() => {
10700
11499
  if (typeof window === "undefined") return {};
@@ -10704,7 +11503,7 @@ function useGridColumnWidths(storageKey) {
10704
11503
  return {};
10705
11504
  }
10706
11505
  });
10707
- const onColumnResized = useCallback15(
11506
+ const onColumnResized = useCallback16(
10708
11507
  (e) => {
10709
11508
  var _a;
10710
11509
  if (!e.finished || e.source !== "uiColumnResized" || !((_a = e.columns) == null ? void 0 : _a.length)) return;
@@ -10720,7 +11519,7 @@ function useGridColumnWidths(storageKey) {
10720
11519
  },
10721
11520
  [storageKey]
10722
11521
  );
10723
- const applyWidths = useCallback15(
11522
+ const applyWidths = useCallback16(
10724
11523
  (defs) => defs.map((d) => {
10725
11524
  const w = d.colId ? widths[d.colId] : void 0;
10726
11525
  return w ? __spreadProps(__spreadValues({}, d), { width: w, flex: 0 }) : d;
@@ -10762,7 +11561,7 @@ var UnpaidReportsTab = ({
10762
11561
  handlers
10763
11562
  }) => {
10764
11563
  var _a;
10765
- const apiRef = useRef16(null);
11564
+ const apiRef = useRef17(null);
10766
11565
  const { onColumnResized, applyWidths } = useGridColumnWidths(`payment-reports:${config.reportsTableId}:unpaid`);
10767
11566
  const [selectedIds, setSelectedIds] = useState20([]);
10768
11567
  const [confirmOpen, setConfirmOpen] = useState20(false);
@@ -10964,10 +11763,10 @@ import { AgGridReact as AgGridReact3 } from "ag-grid-react";
10964
11763
  import { ModuleRegistry as ModuleRegistry3, AllCommunityModule as AllCommunityModule3 } from "ag-grid-community";
10965
11764
 
10966
11765
  // src/components/PaymentReportsBlock/ProofCell.tsx
10967
- import { useRef as useRef17, useState as useState21 } from "react";
11766
+ import { useRef as useRef18, useState as useState21 } from "react";
10968
11767
  import { Fragment as Fragment6, jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
10969
11768
  var ProofCell = ({ files, editable, onUpload, onRemove }) => {
10970
- const inputRef = useRef17(null);
11769
+ const inputRef = useRef18(null);
10971
11770
  const [busy, setBusy] = useState21(false);
10972
11771
  const file = files[0];
10973
11772
  const href = (file == null ? void 0 : file.fileUrl) || (file == null ? void 0 : file.url);
@@ -11401,9 +12200,9 @@ var PaymentReportsBlock = (props) => {
11401
12200
  const [details, setDetails] = useState23(null);
11402
12201
  const [confirm, setConfirm] = useState23(null);
11403
12202
  const [confirmBusy, setConfirmBusy] = useState23(false);
11404
- const toastOk = useCallback16((message) => addToast({ type: "success", message }), [addToast]);
11405
- const toastErr = useCallback16((e) => addToast({ type: "error", message: (e == null ? void 0 : e.message) || String(e) }), [addToast]);
11406
- const load = useCallback16(
12203
+ const toastOk = useCallback17((message) => addToast({ type: "success", message }), [addToast]);
12204
+ const toastErr = useCallback17((e) => addToast({ type: "error", message: (e == null ? void 0 : e.message) || String(e) }), [addToast]);
12205
+ const load = useCallback17(
11407
12206
  async (silent = false) => {
11408
12207
  if (!config || missing.length) return;
11409
12208
  if (!silent) setLoading(true);
@@ -11457,7 +12256,7 @@ var PaymentReportsBlock = (props) => {
11457
12256
  return m;
11458
12257
  }, [model.payments, symbol]);
11459
12258
  const base = { reportsTableId: config == null ? void 0 : config.reportsTableId, paymentsTableId: config == null ? void 0 : config.paymentsTableId };
11460
- const handlers = useRef18(null);
12259
+ const handlers = useRef19(null);
11461
12260
  handlers.current = {
11462
12261
  onPay: async (reportIds) => {
11463
12262
  var _a;
@@ -11647,11 +12446,11 @@ var PaymentReportsBlock = (props) => {
11647
12446
  };
11648
12447
 
11649
12448
  // src/components/WhatsAppComponent/WhatsAppComponent.tsx
11650
- import React27 from "react";
12449
+ import React28 from "react";
11651
12450
  import { CheckCircle2 as CheckCircle24, AlertCircle as AlertCircle5, X as X12, Loader2 as Loader28, Phone as Phone4, Send as Send3, Image as ImageIcon3, FileText as FileText4, Video as Video3 } from "lucide-react";
11652
12451
 
11653
12452
  // src/components/WhatsAppComponent/CreateTemplateModal.tsx
11654
- import { useState as useState24, useEffect as useEffect17, useRef as useRef19, useMemo as useMemo15 } from "react";
12453
+ import { useState as useState24, useEffect as useEffect17, useRef as useRef20, useMemo as useMemo15 } from "react";
11655
12454
  import {
11656
12455
  X as X9,
11657
12456
  Plus,
@@ -11814,14 +12613,14 @@ function CreateTemplateModal({
11814
12613
  const [fileBase64, setFileBase64] = useState24("");
11815
12614
  const [buttons, setButtons] = useState24([]);
11816
12615
  const [isAddButtonOpen, setIsAddButtonOpen] = useState24(false);
11817
- const addButtonDropdownRef = useRef19(null);
12616
+ const addButtonDropdownRef = useRef20(null);
11818
12617
  const [isSubmitting, setIsSubmitting] = useState24(false);
11819
12618
  const [submittingStep, setSubmittingStep] = useState24("");
11820
12619
  const [submitError, setSubmitError] = useState24(null);
11821
12620
  const [fileError, setFileError] = useState24(null);
11822
- const textareaRef = useRef19(null);
11823
- const fileInputRef = useRef19(null);
11824
- const emojiPickerRef = useRef19(null);
12621
+ const textareaRef = useRef20(null);
12622
+ const fileInputRef = useRef20(null);
12623
+ const emojiPickerRef = useRef20(null);
11825
12624
  const [isEmojiPickerOpen, setIsEmojiPickerOpen] = useState24(false);
11826
12625
  useEffect17(() => {
11827
12626
  function handleClickOutside(event) {
@@ -12886,7 +13685,7 @@ function CreateTemplateModal({
12886
13685
  }
12887
13686
 
12888
13687
  // src/components/WhatsAppComponent/hooks/useWhatsAppState.ts
12889
- import { useState as useState25, useEffect as useEffect18, useRef as useRef20, useMemo as useMemo16, useCallback as useCallback17 } from "react";
13688
+ import { useState as useState25, useEffect as useEffect18, useRef as useRef21, useMemo as useMemo16, useCallback as useCallback18 } from "react";
12890
13689
 
12891
13690
  // src/components/WhatsAppComponent/utils/recipientEngine.ts
12892
13691
  var STORAGE_KEY_TEST_PHONE = "whatsapp_test_phone";
@@ -14208,12 +15007,12 @@ function useWhatsAppState(props) {
14208
15007
  const [filters, setFilters] = useState25({});
14209
15008
  const [selectedRowIds, setSelectedRowIds] = useState25([]);
14210
15009
  const [autoSelectCount, setAutoSelectCount] = useState25(null);
14211
- const isAutoSelectingRef = useRef20(false);
14212
- const isManualOverrideRef = useRef20(false);
14213
- const prevAutoSelectCountRef = useRef20(null);
14214
- const fetchedTableIdsRef = useRef20(/* @__PURE__ */ new Set());
14215
- const fullyFetchedRelationKeysRef = useRef20(/* @__PURE__ */ new Set());
14216
- const loadTableData = useCallback17(async () => {
15010
+ const isAutoSelectingRef = useRef21(false);
15011
+ const isManualOverrideRef = useRef21(false);
15012
+ const prevAutoSelectCountRef = useRef21(null);
15013
+ const fetchedTableIdsRef = useRef21(/* @__PURE__ */ new Set());
15014
+ const fullyFetchedRelationKeysRef = useRef21(/* @__PURE__ */ new Set());
15015
+ const loadTableData = useCallback18(async () => {
14217
15016
  var _a2;
14218
15017
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableId);
14219
15018
  if (!tableId || !executeAction) return;
@@ -14477,10 +15276,10 @@ function useWhatsAppState(props) {
14477
15276
  });
14478
15277
  const [broadcastSummary, setBroadcastSummary] = useState25(null);
14479
15278
  const [rowStatusMap, setRowStatusMap] = useState25({});
14480
- const clearBroadcastSummary = useCallback17(() => {
15279
+ const clearBroadcastSummary = useCallback18(() => {
14481
15280
  setBroadcastSummary(null);
14482
15281
  }, []);
14483
- const handleTestPhoneChange = useCallback17((val) => {
15282
+ const handleTestPhoneChange = useCallback18((val) => {
14484
15283
  setTestPhoneNumber(val);
14485
15284
  if (typeof window !== "undefined") {
14486
15285
  try {
@@ -14490,7 +15289,7 @@ function useWhatsAppState(props) {
14490
15289
  }
14491
15290
  }
14492
15291
  }, []);
14493
- const getRelationOptionsForCol = useCallback17(
15292
+ const getRelationOptionsForCol = useCallback18(
14494
15293
  (colName, parentColName) => {
14495
15294
  var _a2, _b2, _c, _d;
14496
15295
  if (parentColName) {
@@ -14781,7 +15580,7 @@ function useWhatsAppState(props) {
14781
15580
  isManualOverrideRef.current = false;
14782
15581
  prevAutoSelectCountRef.current = autoSelectCount;
14783
15582
  }, [autoSelectCount, filteredData]);
14784
- const embeddedTableExecuteAction = useCallback17(async (actionType, payload) => {
15583
+ const embeddedTableExecuteAction = useCallback18(async (actionType, payload) => {
14785
15584
  if (actionType === "FETCH_TABLE_DATA") {
14786
15585
  const colFilters = (payload == null ? void 0 : payload.columnFilters) || (payload == null ? void 0 : payload.filters);
14787
15586
  const searchQuery = payload == null ? void 0 : payload.search;
@@ -14827,7 +15626,7 @@ function useWhatsAppState(props) {
14827
15626
  const activeFiltersCount = useMemo16(() => {
14828
15627
  return Object.values(filters).filter((v) => v !== "").length;
14829
15628
  }, [filters]);
14830
- const handleSelectionChange = useCallback17((selectedIds) => {
15629
+ const handleSelectionChange = useCallback18((selectedIds) => {
14831
15630
  setSelectedRowIds((prev) => {
14832
15631
  if (prev.length === selectedIds.length && prev.every((id, idx) => id === selectedIds[idx])) {
14833
15632
  return prev;
@@ -14841,13 +15640,13 @@ function useWhatsAppState(props) {
14841
15640
  return selectedIds;
14842
15641
  });
14843
15642
  }, [autoSelectCount]);
14844
- const handleRowToggle = useCallback17((rowId, checked) => {
15643
+ const handleRowToggle = useCallback18((rowId, checked) => {
14845
15644
  if (autoSelectCount !== null && autoSelectCount > 0) {
14846
15645
  isManualOverrideRef.current = true;
14847
15646
  setAutoSelectCount(null);
14848
15647
  }
14849
15648
  }, [autoSelectCount]);
14850
- const toggleRowSelection = useCallback17((rowId, checked) => {
15649
+ const toggleRowSelection = useCallback18((rowId, checked) => {
14851
15650
  if (autoSelectCount !== null && autoSelectCount > 0) {
14852
15651
  isManualOverrideRef.current = true;
14853
15652
  setAutoSelectCount(null);
@@ -14871,7 +15670,7 @@ function useWhatsAppState(props) {
14871
15670
  const [isDropdownOpen, setIsDropdownOpen] = useState25(false);
14872
15671
  const [isDeleting, setIsDeleting] = useState25(false);
14873
15672
  const [feedback, setFeedback] = useState25(null);
14874
- const loadTemplates = useCallback17(async () => {
15673
+ const loadTemplates = useCallback18(async () => {
14875
15674
  var _a2, _b2;
14876
15675
  if (!executeAction) {
14877
15676
  setIsLoading(false);
@@ -14966,7 +15765,7 @@ function useWhatsAppState(props) {
14966
15765
  setHeaderMediaUrl("");
14967
15766
  }
14968
15767
  }, [templateHeaderComp, selectedTemplate == null ? void 0 : selectedTemplate.name]);
14969
- const handleHeaderMediaUrlChange = useCallback17(
15768
+ const handleHeaderMediaUrlChange = useCallback18(
14970
15769
  (newUrl) => {
14971
15770
  setHeaderMediaUrl(newUrl);
14972
15771
  if ((selectedTemplate == null ? void 0 : selectedTemplate.name) && typeof window !== "undefined") {
@@ -14985,7 +15784,7 @@ function useWhatsAppState(props) {
14985
15784
  },
14986
15785
  [selectedTemplate == null ? void 0 : selectedTemplate.name]
14987
15786
  );
14988
- const handleResetHeaderMediaUrl = useCallback17(() => {
15787
+ const handleResetHeaderMediaUrl = useCallback18(() => {
14989
15788
  if ((selectedTemplate == null ? void 0 : selectedTemplate.name) && typeof window !== "undefined") {
14990
15789
  try {
14991
15790
  localStorage.removeItem(`whatsapp_template_media_${selectedTemplate.name}`);
@@ -15000,7 +15799,7 @@ function useWhatsAppState(props) {
15000
15799
  setHeaderMediaUrl(defaultUrl || "");
15001
15800
  }, [templateHeaderComp, selectedTemplate == null ? void 0 : selectedTemplate.name]);
15002
15801
  const [isUploadingMedia, setIsUploadingMedia] = useState25(false);
15003
- const handleFileUpload = useCallback17(
15802
+ const handleFileUpload = useCallback18(
15004
15803
  async (file, templateName) => {
15005
15804
  const tplName = templateName || (selectedTemplate == null ? void 0 : selectedTemplate.name) || "";
15006
15805
  if (!file) return;
@@ -15257,7 +16056,7 @@ function useWhatsAppState(props) {
15257
16056
  setIsSendingTest(false);
15258
16057
  }
15259
16058
  };
15260
- const handleSendMessages = useCallback17(async () => {
16059
+ const handleSendMessages = useCallback18(async () => {
15261
16060
  var _a2, _b2;
15262
16061
  if (isSendDisabled || isSendingBroadcast) return;
15263
16062
  const recipients = preparedRecipients;
@@ -15563,7 +16362,7 @@ function useWhatsAppState(props) {
15563
16362
  }
15564
16363
 
15565
16364
  // src/components/WhatsAppComponent/ui/TemplateSelectionBlock.tsx
15566
- import { useRef as useRef21 } from "react";
16365
+ import { useRef as useRef22 } from "react";
15567
16366
  import {
15568
16367
  FileText as FileText3,
15569
16368
  Trash2 as Trash23,
@@ -15606,7 +16405,7 @@ function TemplateSelectionBlock({
15606
16405
  isUploadingMedia = false,
15607
16406
  handleFileUpload
15608
16407
  }) {
15609
- const fileInputRef = useRef21(null);
16408
+ const fileInputRef = useRef22(null);
15610
16409
  return /* @__PURE__ */ jsxs27("div", { className: "col-span-12 lg:col-span-5 min-h-[26rem] h-full flex flex-col bg-slate-50/70 border border-slate-200 rounded-2xl p-3.5 relative", children: [
15611
16410
  /* @__PURE__ */ jsxs27("div", { className: "space-y-1.5 shrink-0", children: [
15612
16411
  /* @__PURE__ */ jsxs27("div", { className: "flex items-center justify-between pb-1.5 border-b border-slate-200/70 shrink-0 gap-2", children: [
@@ -16573,7 +17372,7 @@ function SettingsAndActionsBlock({
16573
17372
  }
16574
17373
 
16575
17374
  // src/components/WhatsAppComponent/inbox/useInboxState.ts
16576
- import { useState as useState26, useEffect as useEffect19, useCallback as useCallback18, useRef as useRef22 } from "react";
17375
+ import { useState as useState26, useEffect as useEffect19, useCallback as useCallback19, useRef as useRef23 } from "react";
16577
17376
  function useInboxState(orgId, actions) {
16578
17377
  const [conversations, setConversations] = useState26([]);
16579
17378
  const [activeConversationId, setActiveConversationId] = useState26(null);
@@ -16581,11 +17380,11 @@ function useInboxState(orgId, actions) {
16581
17380
  const [isLoading, setIsLoading] = useState26(false);
16582
17381
  const [isSending, setIsSending] = useState26(false);
16583
17382
  const [error, setError] = useState26(null);
16584
- const actionsRef = useRef22(actions);
17383
+ const actionsRef = useRef23(actions);
16585
17384
  useEffect19(() => {
16586
17385
  actionsRef.current = actions;
16587
17386
  });
16588
- const fetchConversations = useCallback18(async () => {
17387
+ const fetchConversations = useCallback19(async () => {
16589
17388
  if (!orgId) return;
16590
17389
  const res = await actionsRef.current.getConversations(orgId);
16591
17390
  if (res.success && res.data) {
@@ -16594,7 +17393,7 @@ function useInboxState(orgId, actions) {
16594
17393
  setError(res.error);
16595
17394
  }
16596
17395
  }, [orgId]);
16597
- const fetchMessages = useCallback18(async (conversationId, silent = false) => {
17396
+ const fetchMessages = useCallback19(async (conversationId, silent = false) => {
16598
17397
  if (!silent) setIsLoading(true);
16599
17398
  const res = await actionsRef.current.getMessages(conversationId);
16600
17399
  if (res.success && res.data) {
@@ -16706,12 +17505,12 @@ function ConversationList({ conversations, activeId, onSelect }) {
16706
17505
  }
16707
17506
 
16708
17507
  // src/components/WhatsAppComponent/inbox/ChatWindow.tsx
16709
- import { useState as useState27, useRef as useRef23, useEffect as useEffect20 } from "react";
17508
+ import { useState as useState27, useRef as useRef24, useEffect as useEffect20 } from "react";
16710
17509
  import { Send as Send2, User as User2, Loader2 as Loader27 } from "lucide-react";
16711
17510
  import { jsx as jsx37, jsxs as jsxs31 } from "react/jsx-runtime";
16712
17511
  function ChatWindow({ activeConversation, messages, isLoading, isSending, onSendMessage }) {
16713
17512
  const [inputText, setInputText] = useState27("");
16714
- const messagesTopRef = useRef23(null);
17513
+ const messagesTopRef = useRef24(null);
16715
17514
  const scrollToTop = () => {
16716
17515
  var _a;
16717
17516
  (_a = messagesTopRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
@@ -16832,7 +17631,7 @@ function WhatsAppComponent(props) {
16832
17631
  var _a;
16833
17632
  const { className = "", settings, orgId, componentId, executeAction } = props;
16834
17633
  const state = useWhatsAppState(props);
16835
- const [activeTab, setActiveTab] = React27.useState("broadcast");
17634
+ const [activeTab, setActiveTab] = React28.useState("broadcast");
16836
17635
  return /* @__PURE__ */ jsxs33(
16837
17636
  "div",
16838
17637
  {
@@ -17242,7 +18041,7 @@ import { Loader2 as Loader29, CheckCircle2 as CheckCircle25 } from "lucide-react
17242
18041
  import { jsx as jsx40, jsxs as jsxs34 } from "react/jsx-runtime";
17243
18042
 
17244
18043
  // src/components/FormBlock/StyledFormBlock.tsx
17245
- import { useState as useState29, useEffect as useEffect22, useId, useRef as useRef24 } from "react";
18044
+ import { useState as useState29, useEffect as useEffect22, useId, useRef as useRef25 } from "react";
17246
18045
  import { Loader2 as Loader210, CheckCircle2 as CheckCircle26 } from "lucide-react";
17247
18046
 
17248
18047
  // src/components/FormBlock/formDesign.ts
@@ -17509,16 +18308,16 @@ function StyledFormBlock({
17509
18308
  const [isSubmitted, setIsSubmitted] = useState29(false);
17510
18309
  const [formError, setFormError] = useState29(null);
17511
18310
  const [missingNames, setMissingNames] = useState29([]);
17512
- const errorRef = useRef24(null);
18311
+ const errorRef = useRef25(null);
17513
18312
  const [columns, setColumns] = useState29((schema == null ? void 0 : schema.columns) || []);
17514
18313
  const [isLoadingSchema, setIsLoadingSchema] = useState29(false);
17515
18314
  const [dragName, setDragName] = useState29(null);
17516
18315
  const [drop, setDrop] = useState29(null);
17517
18316
  const [resizing, setResizing] = useState29(null);
17518
- const resizeRef = useRef24(null);
17519
- const gridRef = useRef24(null);
17520
- const relationDictRef = useRef24({});
17521
- const relationRequestedRef = useRef24(/* @__PURE__ */ new Set());
18317
+ const resizeRef = useRef25(null);
18318
+ const gridRef = useRef25(null);
18319
+ const relationDictRef = useRef25({});
18320
+ const relationRequestedRef = useRef25(/* @__PURE__ */ new Set());
17522
18321
  const [, bumpRelationLabels] = useState29(0);
17523
18322
  const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
17524
18323
  useEffect22(() => {
@@ -18099,7 +18898,7 @@ function StyledFormBlock({
18099
18898
  }
18100
18899
 
18101
18900
  // src/themes/ThemeScope.tsx
18102
- import * as React30 from "react";
18901
+ import * as React31 from "react";
18103
18902
  import { jsx as jsx42 } from "react/jsx-runtime";
18104
18903
  var UNIVERSE_THEME_IDS = ["classic", "clean", "ocean", "warm"];
18105
18904
  function resolveUniverseTheme(value) {
@@ -18110,7 +18909,7 @@ function withThemeScope(Component) {
18110
18909
  var _a, _b, _c;
18111
18910
  const p = props;
18112
18911
  const theme = resolveUniverseTheme((_c = (_a = p.settings) == null ? void 0 : _a.theme) != null ? _c : (_b = p.config) == null ? void 0 : _b.theme);
18113
- return /* @__PURE__ */ jsx42("div", { "data-theme": theme, style: { display: "contents" }, children: React30.createElement(Component, props) });
18912
+ return /* @__PURE__ */ jsx42("div", { "data-theme": theme, style: { display: "contents" }, children: React31.createElement(Component, props) });
18114
18913
  }
18115
18914
  ThemeScoped.displayName = `ThemeScoped(${Component.displayName || Component.name || "Component"})`;
18116
18915
  return ThemeScoped;
@@ -18125,19 +18924,28 @@ var UNIVERSE_COMPONENTS = {
18125
18924
  PAYMENT_REPORTS: withThemeScope(PaymentReportsBlock)
18126
18925
  };
18127
18926
  export {
18927
+ BOOLEAN_BUTTON_FALSE_ID,
18928
+ BOOLEAN_BUTTON_TRUE_ID,
18128
18929
  COLUMN_CAPABILITIES,
18129
18930
  COLUMN_DEFAULT_INPUT_CONFIG,
18130
18931
  COLUMN_TYPES,
18131
18932
  COLUMN_TYPE_LABELS,
18132
18933
  ColumnHeaderTitle,
18133
18934
  CreateTemplateModal,
18935
+ DEFAULT_BOOLEAN_FALSE_LABEL,
18936
+ DEFAULT_BOOLEAN_TRUE_LABEL,
18134
18937
  DEFAULT_FILTER_COLUMN_TYPES,
18135
18938
  DEFAULT_PLACEMENT_STATUS_COLORS,
18136
18939
  DatePickerCell,
18137
18940
  DynamicFiltersBlock,
18941
+ EMPTY_IF_CONDITION,
18138
18942
  FORMULA_COLUMN_TYPE,
18943
+ FORMULA_FUNCTION_GROUPS,
18944
+ FORMULA_OPERATOR_GROUPS,
18139
18945
  FORMULA_SOURCE_TYPES,
18946
+ FORMULA_TYPE_LABELS,
18140
18947
  LinkPickerCell,
18948
+ MAX_FILTER_CONDITIONS,
18141
18949
  NON_TEXT_TYPES,
18142
18950
  PASTEL_PALETTES,
18143
18951
  PAYMENT_REPORTS_ACTIONS,
@@ -18173,6 +18981,8 @@ export {
18173
18981
  applyFormulaColumns,
18174
18982
  applyRelationCopy,
18175
18983
  buildColumnOptions,
18984
+ buildIfConditionExpression,
18985
+ buildIfExpression,
18176
18986
  buildRelationCopyPatch,
18177
18987
  buildRelationRef,
18178
18988
  calculateMinColumnWidth,
@@ -18182,11 +18992,14 @@ export {
18182
18992
  columnRefLabel,
18183
18993
  computeFormulaValue,
18184
18994
  describePerRecordFormula,
18995
+ describeRefFilter,
18185
18996
  enrichRowsWithRelations,
18186
18997
  evaluateFormula,
18187
18998
  extractFormulaFields,
18188
18999
  extractUniqueVariableIndices,
18189
19000
  extractVariableIndices,
19001
+ filterKindOfType,
19002
+ filterSignature,
18190
19003
  findVariableAtPosition,
18191
19004
  formatConflictCellValue,
18192
19005
  formatFileSize,
@@ -18194,10 +19007,13 @@ export {
18194
19007
  formatTimeInput,
18195
19008
  formatTimeIso,
18196
19009
  generateWhatsAppLink,
19010
+ getBooleanButtonLabels,
18197
19011
  getColumnDefaultFilter,
18198
19012
  getDefaultFilterColumns,
18199
19013
  getDeterministicPastelBadge,
18200
19014
  getEligibleCopyTargets,
19015
+ getFilterOps,
19016
+ getIfConditionOps,
18201
19017
  getNextVariableIndex,
18202
19018
  getRelationButtonColumns,
18203
19019
  getRelationCopyLockedTargets,
@@ -18209,6 +19025,7 @@ export {
18209
19025
  hasConsecutiveVariables,
18210
19026
  hasFloatingVariables,
18211
19027
  hasInsufficientContextBetweenVariables,
19028
+ isBooleanButtonsColumn,
18212
19029
  isDuplicateTemplate,
18213
19030
  isDuplicateTemplateName,
18214
19031
  isPerRecordSourceColumn,
@@ -18222,6 +19039,7 @@ export {
18222
19039
  isValidTemplateName,
18223
19040
  isWordToken,
18224
19041
  makeCellRefKey,
19042
+ matchesRefFilter,
18225
19043
  measureTextWidth,
18226
19044
  missingPaymentReportsFields,
18227
19045
  normalizePerRecordFormula,
@@ -18241,6 +19059,7 @@ export {
18241
19059
  resolveUniverseTheme,
18242
19060
  sanitizeDefaultFilter,
18243
19061
  sanitizePhoneNumber,
19062
+ sanitizeRefFilter,
18244
19063
  sanitizeTemplateNameInput,
18245
19064
  seamlessVariableEngine,
18246
19065
  splitHeaderTitle,