@universe-platform/ui 0.1.0-beta.31 → 0.1.0-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -93,7 +93,9 @@ __export(src_exports, {
93
93
  UNIVERSE_COMPONENTS: () => UNIVERSE_COMPONENTS,
94
94
  WhatsAppComponent: () => WhatsAppComponent,
95
95
  applyFormulaColumns: () => applyFormulaColumns,
96
+ applyRelationCopy: () => applyRelationCopy,
96
97
  buildColumnOptions: () => buildColumnOptions,
98
+ buildRelationCopyPatch: () => buildRelationCopyPatch,
97
99
  buildRelationRef: () => buildRelationRef,
98
100
  calculateMinColumnWidth: () => calculateMinColumnWidth,
99
101
  checkElementTruncation: () => checkElementTruncation,
@@ -113,8 +115,12 @@ __export(src_exports, {
113
115
  formatTimeIso: () => formatTimeIso,
114
116
  generateWhatsAppLink: () => generateWhatsAppLink,
115
117
  getDeterministicPastelBadge: () => getDeterministicPastelBadge,
118
+ getEligibleCopyTargets: () => getEligibleCopyTargets,
116
119
  getNextVariableIndex: () => getNextVariableIndex,
120
+ getRelationCopyLockedTargets: () => getRelationCopyLockedTargets,
121
+ getRelationCopyTargetNames: () => getRelationCopyTargetNames,
117
122
  getRolePermissions: () => getRolePermissions,
123
+ getSelectedRelationId: () => getSelectedRelationId,
118
124
  getStatusConfig: () => getStatusConfig,
119
125
  hasBracketSpaces: () => hasBracketSpaces,
120
126
  hasConsecutiveVariables: () => hasConsecutiveVariables,
@@ -138,6 +144,7 @@ __export(src_exports, {
138
144
  parseTimeParts: () => parseTimeParts,
139
145
  readColumnValue: () => readColumnValue,
140
146
  reindexVariables: () => reindexVariables,
147
+ renameCopyTarget: () => renameCopyTarget,
141
148
  resolveDefaultStatusId: () => resolveDefaultStatusId,
142
149
  resolveProtocol: () => resolveProtocol,
143
150
  sanitizePhoneNumber: () => sanitizePhoneNumber,
@@ -151,6 +158,7 @@ __export(src_exports, {
151
158
  useToast: () => useToast,
152
159
  useWhatsAppState: () => useWhatsAppState,
153
160
  validateFormula: () => validateFormula,
161
+ validateRelationCopyTargets: () => validateRelationCopyTargets,
154
162
  validateSequentialVariables: () => validateSequentialVariables,
155
163
  validateTemplateBody: () => validateTemplateBody,
156
164
  validateTemplateButtons: () => validateTemplateButtons,
@@ -414,18 +422,18 @@ function getStatusConfig(rawStatus) {
414
422
  isSelectable: false
415
423
  };
416
424
  }
417
- function reindexVariables(text) {
418
- if (!text) return "";
425
+ function reindexVariables(text2) {
426
+ if (!text2) return "";
419
427
  let counter = 1;
420
- return text.replace(/\{\{\s*\d+\s*\}\}/g, () => {
428
+ return text2.replace(/\{\{\s*\d+\s*\}\}/g, () => {
421
429
  const replacement = `{{${counter}}}`;
422
430
  counter++;
423
431
  return replacement;
424
432
  });
425
433
  }
426
- function seamlessVariableEngine(text) {
427
- if (!text) return "";
428
- let result = text;
434
+ function seamlessVariableEngine(text2) {
435
+ if (!text2) return "";
436
+ let result = text2;
429
437
  result = result.replace(/\{\{([^}]*)\}\}/g, (_match, inner) => {
430
438
  const digits = inner.replace(/\D/g, "");
431
439
  if (!digits) return "";
@@ -488,40 +496,40 @@ function isDuplicateTemplateName(name, existingNames = [], language) {
488
496
  return false;
489
497
  });
490
498
  }
491
- function hasBracketSpaces(text) {
492
- if (!text) return false;
493
- return /\{\s+\{|\}\s+\}|\{\{\s+\d+|\d+\s+\}\}/.test(text);
499
+ function hasBracketSpaces(text2) {
500
+ if (!text2) return false;
501
+ return /\{\s+\{|\}\s+\}|\{\{\s+\d+|\d+\s+\}\}/.test(text2);
494
502
  }
495
- function hasConsecutiveVariables(text) {
496
- if (!text) return false;
497
- return /\{\{\s*\d+\s*\}\}\{\{\s*\d+\s*\}\}/.test(text);
503
+ function hasConsecutiveVariables(text2) {
504
+ if (!text2) return false;
505
+ return /\{\{\s*\d+\s*\}\}\{\{\s*\d+\s*\}\}/.test(text2);
498
506
  }
499
- function extractVariableIndices(text) {
500
- if (!text) return [];
501
- const matches = text.match(/\{\{\s*(\d+)\s*\}\}/g) || [];
507
+ function extractVariableIndices(text2) {
508
+ if (!text2) return [];
509
+ const matches = text2.match(/\{\{\s*(\d+)\s*\}\}/g) || [];
502
510
  return matches.map((m) => parseInt(m.replace(/[\{\}\s]/g, ""), 10));
503
511
  }
504
- function extractUniqueVariableIndices(text) {
505
- if (!text) return [];
506
- const indices = extractVariableIndices(text);
512
+ function extractUniqueVariableIndices(text2) {
513
+ if (!text2) return [];
514
+ const indices = extractVariableIndices(text2);
507
515
  return Array.from(new Set(indices)).sort((a, b) => a - b);
508
516
  }
509
- function getNextVariableIndex(text) {
510
- const indices = extractVariableIndices(text);
517
+ function getNextVariableIndex(text2) {
518
+ const indices = extractVariableIndices(text2);
511
519
  if (indices.length === 0) return 1;
512
520
  return Math.max(...indices) + 1;
513
521
  }
514
522
  function isWordToken(token) {
515
523
  return /[\p{L}\p{N}]/u.test(token);
516
524
  }
517
- function hasFloatingVariables(text) {
525
+ function hasFloatingVariables(text2) {
518
526
  var _a, _b;
519
- if (!text) return { hasFloating: false };
520
- const varMatches = Array.from(text.matchAll(/\{\{\s*\d+\s*\}\}/g));
527
+ if (!text2) return { hasFloating: false };
528
+ const varMatches = Array.from(text2.matchAll(/\{\{\s*\d+\s*\}\}/g));
521
529
  if (varMatches.length === 0) return { hasFloating: false };
522
530
  const firstMatch = varMatches[0];
523
531
  const lastMatch = varMatches[varMatches.length - 1];
524
- const beforeText = text.slice(0, (_a = firstMatch.index) != null ? _a : 0);
532
+ const beforeText = text2.slice(0, (_a = firstMatch.index) != null ? _a : 0);
525
533
  const wordsBefore = beforeText.trim().split(/\s+/).filter(isWordToken);
526
534
  if (wordsBefore.length === 0) {
527
535
  return {
@@ -530,7 +538,7 @@ function hasFloatingVariables(text) {
530
538
  };
531
539
  }
532
540
  const lastMatchEnd = ((_b = lastMatch.index) != null ? _b : 0) + lastMatch[0].length;
533
- const afterText = text.slice(lastMatchEnd);
541
+ const afterText = text2.slice(lastMatchEnd);
534
542
  const wordsAfter = afterText.trim().split(/\s+/).filter(isWordToken);
535
543
  if (wordsAfter.length === 0) {
536
544
  return {
@@ -540,17 +548,17 @@ function hasFloatingVariables(text) {
540
548
  }
541
549
  return { hasFloating: false };
542
550
  }
543
- function hasInsufficientContextBetweenVariables(text) {
551
+ function hasInsufficientContextBetweenVariables(text2) {
544
552
  var _a, _b;
545
- if (!text) return { insufficient: false };
546
- const varMatches = Array.from(text.matchAll(/\{\{\s*\d+\s*\}\}/g));
553
+ if (!text2) return { insufficient: false };
554
+ const varMatches = Array.from(text2.matchAll(/\{\{\s*\d+\s*\}\}/g));
547
555
  if (varMatches.length < 2) return { insufficient: false };
548
556
  for (let i = 0; i < varMatches.length - 1; i++) {
549
557
  const currentMatch = varMatches[i];
550
558
  const nextMatch = varMatches[i + 1];
551
559
  const startIndex = ((_a = currentMatch.index) != null ? _a : 0) + currentMatch[0].length;
552
560
  const endIndex = (_b = nextMatch.index) != null ? _b : 0;
553
- const textBetween = text.slice(startIndex, endIndex);
561
+ const textBetween = text2.slice(startIndex, endIndex);
554
562
  const wordsBetween = textBetween.trim().split(/\s+/).filter(isWordToken);
555
563
  if (wordsBetween.length < 2) {
556
564
  return {
@@ -561,13 +569,13 @@ function hasInsufficientContextBetweenVariables(text) {
561
569
  }
562
570
  return { insufficient: false };
563
571
  }
564
- function validateWordToVariableRatio(text) {
565
- if (!text) {
572
+ function validateWordToVariableRatio(text2) {
573
+ if (!text2) {
566
574
  return { isValid: false, reason: "\u05D9\u05E9 \u05DC\u05D4\u05D6\u05D9\u05DF \u05EA\u05D5\u05DB\u05DF \u05DC\u05D4\u05D5\u05D3\u05E2\u05D4", staticWordsCount: 0, variableCount: 0 };
567
575
  }
568
- const allVars = text.match(/\{\{\s*\d+\s*\}\}/g) || [];
576
+ const allVars = text2.match(/\{\{\s*\d+\s*\}\}/g) || [];
569
577
  const variableCount = allVars.length;
570
- const staticText = text.replace(/\{\{\s*\d+\s*\}\}/g, " ");
578
+ const staticText = text2.replace(/\{\{\s*\d+\s*\}\}/g, " ");
571
579
  const staticWords = staticText.trim().split(/\s+/).filter(isWordToken);
572
580
  const staticWordsCount = staticWords.length;
573
581
  if (variableCount > 0) {
@@ -591,9 +599,9 @@ function validateWordToVariableRatio(text) {
591
599
  }
592
600
  return { isValid: true, staticWordsCount, variableCount };
593
601
  }
594
- function validateSequentialVariables(text) {
595
- if (!text) return { isValid: true, uniqueIndices: [], maxIndex: 0 };
596
- const uniqueIndices = extractUniqueVariableIndices(text);
602
+ function validateSequentialVariables(text2) {
603
+ if (!text2) return { isValid: true, uniqueIndices: [], maxIndex: 0 };
604
+ const uniqueIndices = extractUniqueVariableIndices(text2);
597
605
  if (uniqueIndices.length === 0) return { isValid: true, uniqueIndices: [], maxIndex: 0 };
598
606
  const maxIndex = uniqueIndices[uniqueIndices.length - 1];
599
607
  const uniqueSet = new Set(uniqueIndices);
@@ -617,11 +625,11 @@ function validateSequentialVariables(text) {
617
625
  }
618
626
  return { isValid: true, uniqueIndices, maxIndex };
619
627
  }
620
- function findVariableAtPosition(text, cursorPos, isBackspace) {
621
- if (!text) return null;
628
+ function findVariableAtPosition(text2, cursorPos, isBackspace) {
629
+ if (!text2) return null;
622
630
  const regex = /\{\{\s*\d+\s*\}\}/g;
623
631
  let match;
624
- while ((match = regex.exec(text)) !== null) {
632
+ while ((match = regex.exec(text2)) !== null) {
625
633
  const start = match.index;
626
634
  const end = match.index + match[0].length;
627
635
  if (isBackspace) {
@@ -702,17 +710,17 @@ function validateTemplateButtons(buttons) {
702
710
  return;
703
711
  }
704
712
  const type = btn.type;
705
- const text = (btn.text || "").trim();
713
+ const text2 = (btn.text || "").trim();
706
714
  if (type === "QUICK_REPLY") {
707
- if (!text) {
715
+ if (!text2) {
708
716
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D9\u05E9 \u05DC\u05D4\u05D6\u05D9\u05DF \u05D8\u05E7\u05E1\u05D8 \u05DC\u05DB\u05E4\u05EA\u05D5\u05E8 \u05EA\u05D2\u05D5\u05D1\u05D4 \u05DE\u05D4\u05D9\u05E8\u05D4`);
709
- } else if (text.length > 25) {
717
+ } else if (text2.length > 25) {
710
718
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D8\u05E7\u05E1\u05D8 \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D0\u05D9\u05E0\u05D5 \u05D9\u05DB\u05D5\u05DC \u05DC\u05E2\u05DC\u05D5\u05EA \u05E2\u05DC 25 \u05EA\u05D5\u05D5\u05D9\u05DD`);
711
719
  }
712
720
  } else if (type === "URL") {
713
- if (!text) {
721
+ if (!text2) {
714
722
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D9\u05E9 \u05DC\u05D4\u05D6\u05D9\u05DF \u05D8\u05E7\u05E1\u05D8 \u05DC\u05DB\u05E4\u05EA\u05D5\u05E8 \u05E7\u05D9\u05E9\u05D5\u05E8`);
715
- } else if (text.length > 25) {
723
+ } else if (text2.length > 25) {
716
724
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D8\u05E7\u05E1\u05D8 \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D0\u05D9\u05E0\u05D5 \u05D9\u05DB\u05D5\u05DC \u05DC\u05E2\u05DC\u05D5\u05EA \u05E2\u05DC 25 \u05EA\u05D5\u05D5\u05D9\u05DD`);
717
725
  }
718
726
  const url = (btn.url || "").trim();
@@ -724,9 +732,9 @@ function validateTemplateButtons(buttons) {
724
732
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05DB\u05EA\u05D5\u05D1\u05EA \u05D4\u05D0\u05EA\u05E8 \u05D0\u05D9\u05E0\u05D4 \u05EA\u05E7\u05D9\u05E0\u05D4 (\u05D7\u05D9\u05D9\u05D1\u05EA \u05DC\u05D4\u05EA\u05D7\u05D9\u05DC \u05D1-http:// \u05D0\u05D5 https:// \u05DC\u05DC\u05D0 \u05E8\u05D5\u05D5\u05D7\u05D9\u05DD)`);
725
733
  }
726
734
  } else if (type === "PHONE_NUMBER") {
727
- if (!text) {
735
+ if (!text2) {
728
736
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D9\u05E9 \u05DC\u05D4\u05D6\u05D9\u05DF \u05D8\u05E7\u05E1\u05D8 \u05DC\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D7\u05D9\u05D5\u05D2`);
729
- } else if (text.length > 25) {
737
+ } else if (text2.length > 25) {
730
738
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D8\u05E7\u05E1\u05D8 \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D0\u05D9\u05E0\u05D5 \u05D9\u05DB\u05D5\u05DC \u05DC\u05E2\u05DC\u05D5\u05EA \u05E2\u05DC 25 \u05EA\u05D5\u05D5\u05D9\u05DD`);
731
739
  }
732
740
  const phone = (btn.phone_number || "").trim();
@@ -738,7 +746,7 @@ function validateTemplateButtons(buttons) {
738
746
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05DE\u05E1\u05E4\u05E8 \u05D4\u05D8\u05DC\u05E4\u05D5\u05DF \u05D0\u05D9\u05E0\u05D5 \u05EA\u05E7\u05D9\u05DF (\u05E4\u05D5\u05E8\u05DE\u05D8 \u05D7\u05D5\u05D1\u05D4: +[\u05E7\u05D9\u05D3\u05D5\u05DE\u05EA][\u05DE\u05E1\u05E4\u05E8], \u05DC\u05D3\u05D5\u05D2\u05DE\u05D4: +972501234567)`);
739
747
  }
740
748
  } else if (type === "COPY_CODE") {
741
- if (text && text.length > 25) {
749
+ if (text2 && text2.length > 25) {
742
750
  errors.push(`\u05DB\u05E4\u05EA\u05D5\u05E8 ${btnNum}: \u05D8\u05E7\u05E1\u05D8 \u05D4\u05DB\u05E4\u05EA\u05D5\u05E8 \u05D0\u05D9\u05E0\u05D5 \u05D9\u05DB\u05D5\u05DC \u05DC\u05E2\u05DC\u05D5\u05EA \u05E2\u05DC 25 \u05EA\u05D5\u05D5\u05D9\u05DD`);
743
751
  }
744
752
  const example = (btn.example || "").trim();
@@ -838,7 +846,7 @@ function formatFileSize(bytes) {
838
846
 
839
847
  // ../shared/src/formula.ts
840
848
  var FORMULA_COLUMN_TYPE = "FORMULA";
841
- var FORMULA_SOURCE_TYPES = ["NUMBER", "CURRENCY", "STRING"];
849
+ var FORMULA_SOURCE_TYPES = ["NUMBER", "CURRENCY", "STRING", "BOOLEAN", "DATE", "TIME", "PHONE"];
842
850
  function extractFormulaFields(expr) {
843
851
  const out = /* @__PURE__ */ new Set();
844
852
  for (const m of (expr || "").matchAll(/\{([^{}]+)\}/g)) out.add(m[1].trim());
@@ -895,6 +903,42 @@ var toNum = (x) => {
895
903
  const n = typeof x === "number" ? x : Number(x);
896
904
  return Number.isFinite(n) ? n : NaN;
897
905
  };
906
+ var isBlank = (x) => x === null || x === void 0 || x === "";
907
+ var isNumLike = (x) => typeof x === "number" || typeof x === "string" && x.trim() !== "" && Number.isFinite(Number(x));
908
+ var isoDate = (x) => typeof x === "string" && /^\d{4}-\d{2}-\d{2}/.test(x) ? x.slice(0, 10) : null;
909
+ var truthy = (x) => {
910
+ if (x === null || x === "") return false;
911
+ if (typeof x === "number") return x !== 0 && !Number.isNaN(x);
912
+ const s = x.trim().toLowerCase();
913
+ return s !== "" && s !== "0" && s !== "false";
914
+ };
915
+ var text = (x) => String(x != null ? x : "").trim().toLowerCase();
916
+ function compareValues(l, r) {
917
+ const ld = isoDate(l), rd = isoDate(r);
918
+ if (ld && rd) return ld < rd ? -1 : ld > rd ? 1 : 0;
919
+ if ((isNumLike(l) || isBlank(l)) && (isNumLike(r) || isBlank(r))) {
920
+ const a2 = toNum(l), b2 = toNum(r);
921
+ return a2 < b2 ? -1 : a2 > b2 ? 1 : 0;
922
+ }
923
+ const a = text(l), b = text(r);
924
+ return a < b ? -1 : a > b ? 1 : 0;
925
+ }
926
+ var dayNumber = (iso) => Date.UTC(+iso.slice(0, 4), +iso.slice(5, 7) - 1, +iso.slice(8, 10));
927
+ var ARITY = {
928
+ ROUND: [1, 2],
929
+ MIN: [1, 99],
930
+ MAX: [1, 99],
931
+ ABS: [1, 1],
932
+ IF: [3, 3],
933
+ AND: [1, 99],
934
+ OR: [1, 99],
935
+ NOT: [1, 1],
936
+ CONTAINS: [2, 2],
937
+ STARTSWITH: [2, 2],
938
+ ENDSWITH: [2, 2],
939
+ ISEMPTY: [1, 1],
940
+ DAYS: [2, 2]
941
+ };
898
942
  function evaluateFormula(expr, getField) {
899
943
  const toks = tokenize(expr);
900
944
  let p = 0;
@@ -912,8 +956,8 @@ function evaluateFormula(expr, getField) {
912
956
  let l = parseConcat();
913
957
  while (isOp(">", "<", ">=", "<=", "=", "<>")) {
914
958
  const op = eat().v, r = parseConcat();
915
- const a = toNum(l), b = toNum(r);
916
- l = (op === ">" ? a > b : op === "<" ? a < b : op === ">=" ? a >= b : op === "<=" ? a <= b : op === "=" ? a === b : a !== b) ? 1 : 0;
959
+ const c = compareValues(l, r);
960
+ l = (op === ">" ? c > 0 : op === "<" ? c < 0 : op === ">=" ? c >= 0 : op === "<=" ? c <= 0 : op === "=" ? c === 0 : c !== 0) ? 1 : 0;
917
961
  }
918
962
  return l;
919
963
  }
@@ -964,8 +1008,11 @@ function evaluateFormula(expr, getField) {
964
1008
  }
965
1009
  if (t.k === "field") {
966
1010
  p++;
967
- const v = getField(t.v);
968
- return v === void 0 || v === null ? null : v;
1011
+ const raw = getField(t.v);
1012
+ if (raw === void 0 || raw === null) return null;
1013
+ if (typeof raw === "boolean") return raw ? 1 : 0;
1014
+ if (typeof raw === "number" || typeof raw === "string") return raw;
1015
+ return null;
969
1016
  }
970
1017
  if (isOp("(")) {
971
1018
  eat();
@@ -985,6 +1032,12 @@ function evaluateFormula(expr, getField) {
985
1032
  }
986
1033
  }
987
1034
  eat(")");
1035
+ const ar = ARITY[t.v];
1036
+ if (!ar) throw new Error(`\u05E4\u05D5\u05E0\u05E7\u05E6\u05D9\u05D4 \u05DC\u05D0 \u05DE\u05D5\u05DB\u05E8\u05EA: ${t.v}`);
1037
+ if (args.length < ar[0] || args.length > ar[1]) {
1038
+ const need = ar[1] === 99 ? `\u05DC\u05E4\u05D7\u05D5\u05EA ${ar[0]}` : ar[0] === ar[1] ? `${ar[0]}` : `${ar[0]}-${ar[1]}`;
1039
+ throw new Error(`\u05D4\u05E4\u05D5\u05E0\u05E7\u05E6\u05D9\u05D4 ${t.v} \u05DE\u05E7\u05D1\u05DC\u05EA ${need} \u05E4\u05E8\u05DE\u05D8\u05E8\u05D9\u05DD`);
1040
+ }
988
1041
  const n = args.map(toNum);
989
1042
  switch (t.v) {
990
1043
  case "ROUND": {
@@ -998,7 +1051,25 @@ function evaluateFormula(expr, getField) {
998
1051
  case "ABS":
999
1052
  return Math.abs(n[0]);
1000
1053
  case "IF":
1001
- return toNum(args[0]) ? (_b = args[1]) != null ? _b : null : (_c = args[2]) != null ? _c : null;
1054
+ return truthy(args[0]) ? (_b = args[1]) != null ? _b : null : (_c = args[2]) != null ? _c : null;
1055
+ case "AND":
1056
+ return args.every(truthy) ? 1 : 0;
1057
+ case "OR":
1058
+ return args.some(truthy) ? 1 : 0;
1059
+ case "NOT":
1060
+ return truthy(args[0]) ? 0 : 1;
1061
+ case "CONTAINS":
1062
+ return text(args[0]).includes(text(args[1])) ? 1 : 0;
1063
+ case "STARTSWITH":
1064
+ return text(args[0]).startsWith(text(args[1])) ? 1 : 0;
1065
+ case "ENDSWITH":
1066
+ return text(args[0]).endsWith(text(args[1])) ? 1 : 0;
1067
+ case "ISEMPTY":
1068
+ return isBlank(args[0]) ? 1 : 0;
1069
+ case "DAYS": {
1070
+ const a = isoDate(args[0]), b = isoDate(args[1]);
1071
+ return a && b ? Math.round((dayNumber(a) - dayNumber(b)) / 864e5) : null;
1072
+ }
1002
1073
  default:
1003
1074
  throw new Error(`\u05E4\u05D5\u05E0\u05E7\u05E6\u05D9\u05D4 \u05DC\u05D0 \u05DE\u05D5\u05DB\u05E8\u05EA: ${t.v}`);
1004
1075
  }
@@ -1042,8 +1113,85 @@ function applyFormulaColumns(data, columns) {
1042
1113
  return data;
1043
1114
  }
1044
1115
 
1116
+ // ../shared/src/relationCopy.ts
1117
+ var isRelation = (c) => !!c && String(c.type).toUpperCase() === "RELATION";
1118
+ function getSelectedRelationId(value) {
1119
+ if (value === null || value === void 0 || value === "") return null;
1120
+ const first = Array.isArray(value) ? value[0] : value;
1121
+ if (first === null || first === void 0 || first === "") return null;
1122
+ if (typeof first === "object") {
1123
+ const id = first.id || first._id || first.value;
1124
+ return id ? String(id) : null;
1125
+ }
1126
+ return String(first);
1127
+ }
1128
+ function getRelationCopyTargetNames(col) {
1129
+ var _a, _b;
1130
+ if (!isRelation(col) || ((_a = col.config) == null ? void 0 : _a.allowMultiple)) return [];
1131
+ const list = (_b = col.config) == null ? void 0 : _b.copyTargets;
1132
+ return Array.isArray(list) ? list.filter((n) => typeof n === "string" && n) : [];
1133
+ }
1134
+ function getEligibleCopyTargets(referencedTableId, columns, ownName) {
1135
+ if (!referencedTableId) return [];
1136
+ return (columns || []).filter(
1137
+ (c) => {
1138
+ var _a;
1139
+ return isRelation(c) && c.name !== ownName && c.name !== "_id" && ((_a = c.config) == null ? void 0 : _a.referencedTableId) === referencedTableId && getRelationCopyTargetNames(c).length === 0;
1140
+ }
1141
+ // עמודה ראשית אחרת לא יכולה להיות נלווית
1142
+ );
1143
+ }
1144
+ function resolveTargets(master, columns) {
1145
+ var _a;
1146
+ const refId = (_a = master.config) == null ? void 0 : _a.referencedTableId;
1147
+ return getRelationCopyTargetNames(master).filter((n) => {
1148
+ var _a2;
1149
+ const t = columns.find((c) => c.name === n);
1150
+ return isRelation(t) && ((_a2 = t.config) == null ? void 0 : _a2.referencedTableId) === refId && n !== master.name;
1151
+ });
1152
+ }
1153
+ function getRelationCopyLockedTargets(columns) {
1154
+ const out = /* @__PURE__ */ new Set();
1155
+ const cols = columns || [];
1156
+ for (const c of cols) for (const n of resolveTargets(c, cols)) out.add(n);
1157
+ return out;
1158
+ }
1159
+ function buildRelationCopyPatch(master, masterValue, columns) {
1160
+ const id = getSelectedRelationId(masterValue);
1161
+ const patch = {};
1162
+ for (const n of resolveTargets(master, columns)) patch[n] = id ? [id] : [];
1163
+ return patch;
1164
+ }
1165
+ function applyRelationCopy(data, columns, changedKeys, existing) {
1166
+ var _a;
1167
+ for (const master of columns || []) {
1168
+ const targets = resolveTargets(master, columns);
1169
+ if (targets.length === 0) continue;
1170
+ if (changedKeys && !changedKeys.includes(master.name)) {
1171
+ for (const t of targets) {
1172
+ if (changedKeys.includes(t)) data[t] = (_a = existing == null ? void 0 : existing[t]) != null ? _a : [];
1173
+ }
1174
+ continue;
1175
+ }
1176
+ Object.assign(data, buildRelationCopyPatch(master, data[master.name], columns));
1177
+ }
1178
+ return data;
1179
+ }
1180
+ function validateRelationCopyTargets(targets, referencedTableId, columns, ownName) {
1181
+ if (targets.length === 0) return "\u05E1\u05D9\u05DE\u05E0\u05EA \u05D4\u05E2\u05EA\u05E7\u05EA \u05E0\u05EA\u05D5\u05E0\u05D9\u05DD - \u05D9\u05E9 \u05DC\u05D1\u05D7\u05D5\u05E8 \u05DC\u05E4\u05D7\u05D5\u05EA \u05E2\u05DE\u05D5\u05D3\u05D4 \u05D0\u05D7\u05EA";
1182
+ const eligible = getEligibleCopyTargets(referencedTableId, columns, ownName).map((c) => c.name);
1183
+ const bad = targets.find((n) => !eligible.includes(n));
1184
+ return bad ? `\u05D4\u05E2\u05DE\u05D5\u05D3\u05D4 "${bad}" \u05D0\u05D9\u05E0\u05D4 \u05E2\u05DE\u05D5\u05D3\u05EA \u05E7\u05E9\u05E8 \u05DC\u05D0\u05D5\u05EA\u05D4 \u05D8\u05D1\u05DC\u05D4 \u05D5\u05DC\u05DB\u05DF \u05D0\u05D9 \u05D0\u05E4\u05E9\u05E8 \u05DC\u05D1\u05D7\u05D5\u05E8 \u05D1\u05D4` : null;
1185
+ }
1186
+ function renameCopyTarget(col, oldName, newName) {
1187
+ var _a;
1188
+ const list = (_a = col == null ? void 0 : col.config) == null ? void 0 : _a.copyTargets;
1189
+ if (!Array.isArray(list)) return;
1190
+ col.config.copyTargets = list.map((n) => n === oldName ? newName : n);
1191
+ }
1192
+
1045
1193
  // src/components/TableBlock/TableBlockClient.tsx
1046
- var import_react15 = __toESM(require("react"));
1194
+ var import_react16 = __toESM(require("react"));
1047
1195
 
1048
1196
  // src/hooks/useToast.ts
1049
1197
  var import_react2 = require("react");
@@ -1644,8 +1792,8 @@ var import_jsx_runtime3 = require("react/jsx-runtime");
1644
1792
  var checkElementTruncation = (el) => {
1645
1793
  if (!el) return false;
1646
1794
  const isInput = el instanceof HTMLInputElement || el.tagName === "INPUT";
1647
- const text = isInput ? el.value : el.textContent;
1648
- if (!text) return false;
1795
+ const text2 = isInput ? el.value : el.textContent;
1796
+ if (!text2) return false;
1649
1797
  if (!isInput && typeof document !== "undefined" && document.createRange) {
1650
1798
  try {
1651
1799
  const range = document.createRange();
@@ -1713,8 +1861,8 @@ function useSmartTooltip() {
1713
1861
  window.removeEventListener("resize", handleWindowEvents);
1714
1862
  };
1715
1863
  }, [showBubble]);
1716
- const renderTooltip = (text, dir) => {
1717
- if (!showBubble || !isTruncated || !text || typeof document === "undefined") return null;
1864
+ const renderTooltip = (text2, dir) => {
1865
+ if (!showBubble || !isTruncated || !text2 || typeof document === "undefined") return null;
1718
1866
  return (0, import_react_dom.createPortal)(
1719
1867
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1720
1868
  "div",
@@ -1726,7 +1874,7 @@ function useSmartTooltip() {
1726
1874
  left: coords ? Math.max(12, Math.min(coords.left, (typeof window !== "undefined" ? window.innerWidth : 800) - 280)) : 0,
1727
1875
  transform: coords && coords.top > 36 ? "translateY(-100%)" : void 0
1728
1876
  },
1729
- children: text
1877
+ children: text2
1730
1878
  }
1731
1879
  ),
1732
1880
  document.body
@@ -1744,7 +1892,7 @@ function useSmartTooltip() {
1744
1892
  };
1745
1893
  }
1746
1894
  var TruncatedTooltip = ({
1747
- text,
1895
+ text: text2,
1748
1896
  tooltipText,
1749
1897
  dir = "auto",
1750
1898
  className = "",
@@ -1756,7 +1904,7 @@ var TruncatedTooltip = ({
1756
1904
  const [coords, setCoords] = (0, import_react4.useState)(null);
1757
1905
  const containerRef = (0, import_react4.useRef)(null);
1758
1906
  const spanRef = (0, import_react4.useRef)(null);
1759
- const content = text !== void 0 && text !== null ? String(text) : "";
1907
+ const content = text2 !== void 0 && text2 !== null ? String(text2) : "";
1760
1908
  const tooltipContent = tooltipText !== void 0 ? tooltipText : content;
1761
1909
  const handleMouseEnter = () => {
1762
1910
  const el = spanRef.current;
@@ -2133,13 +2281,13 @@ function DatePickerCell({ value, onChange, readOnly = false }) {
2133
2281
  };
2134
2282
  }, [isOpen, updatePopoverPosition]);
2135
2283
  const handleInputChange = (e) => {
2136
- const text = e.target.value;
2137
- setRawInput(text);
2138
- if (!text.trim()) {
2284
+ const text2 = e.target.value;
2285
+ setRawInput(text2);
2286
+ if (!text2.trim()) {
2139
2287
  onChange(null);
2140
2288
  return;
2141
2289
  }
2142
- const parts = parseDateParts(text);
2290
+ const parts = parseDateParts(text2);
2143
2291
  if (parts) {
2144
2292
  const iso = formatDateIso(parts.year, parts.month, parts.day);
2145
2293
  onChange(iso);
@@ -2486,23 +2634,23 @@ function TimePickerCell({ value, onChange, readOnly = false }) {
2486
2634
  }
2487
2635
  };
2488
2636
  const handleInputBlur = () => {
2489
- let text = rawInput.trim();
2490
- if (!text) {
2637
+ let text2 = rawInput.trim();
2638
+ if (!text2) {
2491
2639
  onChange(null);
2492
2640
  return;
2493
2641
  }
2494
- if (!text.includes(":")) {
2495
- if (text.length === 1 || text.length === 2) {
2496
- text = `${text}:00`;
2497
- } else if (text.length === 3) {
2498
- text = `0${text[0]}:${text.slice(1)}`;
2499
- } else if (text.length === 4) {
2500
- text = `${text.slice(0, 2)}:${text.slice(2)}`;
2642
+ if (!text2.includes(":")) {
2643
+ if (text2.length === 1 || text2.length === 2) {
2644
+ text2 = `${text2}:00`;
2645
+ } else if (text2.length === 3) {
2646
+ text2 = `0${text2[0]}:${text2.slice(1)}`;
2647
+ } else if (text2.length === 4) {
2648
+ text2 = `${text2.slice(0, 2)}:${text2.slice(2)}`;
2501
2649
  }
2502
- } else if (text.endsWith(":")) {
2503
- text = `${text}00`;
2650
+ } else if (text2.endsWith(":")) {
2651
+ text2 = `${text2}00`;
2504
2652
  }
2505
- const parts = parseTimeParts(text);
2653
+ const parts = parseTimeParts(text2);
2506
2654
  if (parts) {
2507
2655
  const iso = formatTimeIso(parts.hour, parts.minute);
2508
2656
  setRawInput(iso);
@@ -3679,19 +3827,19 @@ function formatFormulaValue(value, column) {
3679
3827
  if (value === null || value === void 0 || value === "") return "";
3680
3828
  const f = (_a = column == null ? void 0 : column.config) == null ? void 0 : _a.formula;
3681
3829
  if (typeof value === "number") {
3682
- const text = new Intl.NumberFormat("en-US", { maximumFractionDigits: 6 }).format(value);
3830
+ const text2 = new Intl.NumberFormat("en-US", { maximumFractionDigits: 6 }).format(value);
3683
3831
  if ((f == null ? void 0 : f.resultType) === "CURRENCY") {
3684
3832
  const code = f.currencySymbol;
3685
3833
  const s = code ? SYMBOLS[code.toUpperCase()] || code : "";
3686
- return s ? `${s} ${text}` : text;
3834
+ return s ? `${s} ${text2}` : text2;
3687
3835
  }
3688
- return text;
3836
+ return text2;
3689
3837
  }
3690
3838
  return String(value);
3691
3839
  }
3692
3840
  var FormulaDisplay = ({ value, column }) => {
3693
- const text = formatFormulaValue(value, column);
3694
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SmartTextCell, { value: text, tooltipText: text, readOnly: true });
3841
+ const text2 = formatFormulaValue(value, column);
3842
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SmartTextCell, { value: text2, tooltipText: text2, readOnly: true });
3695
3843
  };
3696
3844
  var FormulaInputRenderer = ({ value, column, context }) => {
3697
3845
  const live = (context == null ? void 0 : context.rowData) ? computeFormulaValue(column, context.rowData) : value;
@@ -4253,15 +4401,15 @@ function useColumnReorder({
4253
4401
  var import_react12 = require("react");
4254
4402
  var import_jsx_runtime10 = require("react/jsx-runtime");
4255
4403
  var canvas = null;
4256
- function measureTextWidth(text, font = '600 14px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif') {
4257
- if (typeof document === "undefined") return text.length * 9;
4404
+ function measureTextWidth(text2, font = '600 14px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif') {
4405
+ if (typeof document === "undefined") return text2.length * 9;
4258
4406
  if (!canvas) {
4259
4407
  canvas = document.createElement("canvas");
4260
4408
  }
4261
4409
  const ctx = canvas.getContext("2d");
4262
- if (!ctx) return text.length * 9;
4410
+ if (!ctx) return text2.length * 9;
4263
4411
  ctx.font = font;
4264
- return ctx.measureText(text).width;
4412
+ return ctx.measureText(text2).width;
4265
4413
  }
4266
4414
  function splitHeaderTitle(name) {
4267
4415
  if (!name) return { isSingleWord: true, line1: "" };
@@ -4347,8 +4495,8 @@ function formatConflictCellValue(rawVal, colDef, relationOptionsMap) {
4347
4495
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-rose-50 text-rose-700 border border-rose-200 truncate max-w-[150px]", title: fileName || "\u05E7\u05D5\u05D1\u05E5 \u05DE\u05E6\u05D5\u05E8\u05E3", children: fileName ? String(fileName) : "\u05E7\u05D5\u05D1\u05E5 \u05DE\u05E6\u05D5\u05E8\u05E3" });
4348
4496
  }
4349
4497
  if (colType === "LINK" || typeof rawVal === "object" && rawVal !== null && ("url" in rawVal || "label" in rawVal)) {
4350
- const text = (rawVal == null ? void 0 : rawVal.label) || (rawVal == null ? void 0 : rawVal.url);
4351
- return text ? String(text) : "-";
4498
+ const text2 = (rawVal == null ? void 0 : rawVal.label) || (rawVal == null ? void 0 : rawVal.url);
4499
+ return text2 ? String(text2) : "-";
4352
4500
  }
4353
4501
  if (colType === "SUB_TABLE" || Array.isArray(rawVal) && rawVal.length > 0 && typeof rawVal[0] === "object" && ("recordId" in rawVal[0] || "id" in rawVal[0])) {
4354
4502
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { className: "inline-flex items-center px-1.5 py-0.5 rounded text-[11px] font-medium bg-amber-50 text-amber-700 border border-amber-200", children: [
@@ -5606,8 +5754,23 @@ function SubTableViewer({ rowId, column, value, onChange, context, readOnly }) {
5606
5754
  // src/components/TableBlock/TableBlockClient.tsx
5607
5755
  var import_lucide_react9 = require("lucide-react");
5608
5756
 
5609
- // src/components/TableBlock/RelationFilterPopover.tsx
5757
+ // src/components/TableBlock/useRelationCopy.ts
5610
5758
  var import_react14 = require("react");
5759
+ function useRelationCopyHandler({ columns, handleCellChange }) {
5760
+ const latest = (0, import_react14.useRef)({ columns, handleCellChange });
5761
+ latest.current = { columns, handleCellChange };
5762
+ return (0, import_react14.useCallback)((rowId, colName, value) => {
5763
+ const { columns: cols, handleCellChange: change } = latest.current;
5764
+ change(rowId, colName, value);
5765
+ const col = (cols || []).find((c) => (c == null ? void 0 : c.name) === colName);
5766
+ if (getRelationCopyTargetNames(col).length === 0) return;
5767
+ const patch = buildRelationCopyPatch(col, value, cols);
5768
+ for (const [target, v] of Object.entries(patch)) change(rowId, target, v);
5769
+ }, []);
5770
+ }
5771
+
5772
+ // src/components/TableBlock/RelationFilterPopover.tsx
5773
+ var import_react15 = require("react");
5611
5774
  var import_lucide_react8 = require("lucide-react");
5612
5775
  var import_jsx_runtime12 = require("react/jsx-runtime");
5613
5776
  function calculatePopoverCoords(rect) {
@@ -5641,18 +5804,18 @@ function RelationFilterPopover({
5641
5804
  onSelectionChange,
5642
5805
  isLoading = false
5643
5806
  }) {
5644
- const popoverRef = (0, import_react14.useRef)(null);
5645
- const searchInputRef = (0, import_react14.useRef)(null);
5646
- const selectAllRef = (0, import_react14.useRef)(null);
5647
- const [searchQuery, setSearchQuery] = (0, import_react14.useState)("");
5648
- const [coords, setCoords] = (0, import_react14.useState)(
5807
+ const popoverRef = (0, import_react15.useRef)(null);
5808
+ const searchInputRef = (0, import_react15.useRef)(null);
5809
+ const selectAllRef = (0, import_react15.useRef)(null);
5810
+ const [searchQuery, setSearchQuery] = (0, import_react15.useState)("");
5811
+ const [coords, setCoords] = (0, import_react15.useState)(
5649
5812
  () => calculatePopoverCoords(triggerRect)
5650
5813
  );
5651
- const [mode, setMode] = (0, import_react14.useState)("include");
5652
- const [checkedSet, setCheckedSet] = (0, import_react14.useState)(/* @__PURE__ */ new Set());
5653
- const [excludedSet, setExcludedSet] = (0, import_react14.useState)(/* @__PURE__ */ new Set());
5654
- const prevIsOpenRef = (0, import_react14.useRef)(isOpen);
5655
- (0, import_react14.useEffect)(() => {
5814
+ const [mode, setMode] = (0, import_react15.useState)("include");
5815
+ const [checkedSet, setCheckedSet] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
5816
+ const [excludedSet, setExcludedSet] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
5817
+ const prevIsOpenRef = (0, import_react15.useRef)(isOpen);
5818
+ (0, import_react15.useEffect)(() => {
5656
5819
  const justOpened = isOpen && !prevIsOpenRef.current;
5657
5820
  prevIsOpenRef.current = isOpen;
5658
5821
  if (justOpened) {
@@ -5672,11 +5835,11 @@ function RelationFilterPopover({
5672
5835
  }
5673
5836
  }
5674
5837
  }, [isOpen, filterValue, selectedValues]);
5675
- const updatePosition = (0, import_react14.useCallback)(() => {
5838
+ const updatePosition = (0, import_react15.useCallback)(() => {
5676
5839
  const next = calculatePopoverCoords(triggerRect);
5677
5840
  if (next) setCoords(next);
5678
5841
  }, [triggerRect]);
5679
- (0, import_react14.useEffect)(() => {
5842
+ (0, import_react15.useEffect)(() => {
5680
5843
  if (isOpen) {
5681
5844
  updatePosition();
5682
5845
  setTimeout(() => {
@@ -5687,7 +5850,7 @@ function RelationFilterPopover({
5687
5850
  setSearchQuery("");
5688
5851
  }
5689
5852
  }, [isOpen, updatePosition]);
5690
- (0, import_react14.useEffect)(() => {
5853
+ (0, import_react15.useEffect)(() => {
5691
5854
  if (!isOpen) return;
5692
5855
  const handleScrollOrResize = () => updatePosition();
5693
5856
  window.addEventListener("scroll", handleScrollOrResize, true);
@@ -5697,7 +5860,7 @@ function RelationFilterPopover({
5697
5860
  window.removeEventListener("resize", handleScrollOrResize);
5698
5861
  };
5699
5862
  }, [isOpen, updatePosition]);
5700
- (0, import_react14.useEffect)(() => {
5863
+ (0, import_react15.useEffect)(() => {
5701
5864
  if (!isOpen) return;
5702
5865
  const handleMouseDown = (e) => {
5703
5866
  if (popoverRef.current && !popoverRef.current.contains(e.target)) {
@@ -5709,7 +5872,7 @@ function RelationFilterPopover({
5709
5872
  document.removeEventListener("mousedown", handleMouseDown);
5710
5873
  };
5711
5874
  }, [isOpen, onClose]);
5712
- (0, import_react14.useEffect)(() => {
5875
+ (0, import_react15.useEffect)(() => {
5713
5876
  if (!isOpen) return;
5714
5877
  const handleKeyDown = (e) => {
5715
5878
  if (e.key === "Escape") {
@@ -5721,12 +5884,12 @@ function RelationFilterPopover({
5721
5884
  window.removeEventListener("keydown", handleKeyDown);
5722
5885
  };
5723
5886
  }, [isOpen, onClose]);
5724
- const filteredOptions = (0, import_react14.useMemo)(() => {
5887
+ const filteredOptions = (0, import_react15.useMemo)(() => {
5725
5888
  if (!searchQuery.trim()) return options;
5726
5889
  const q = searchQuery.trim().toLowerCase();
5727
5890
  return options.filter((opt) => opt.label.toLowerCase().includes(q));
5728
5891
  }, [options, searchQuery]);
5729
- const isOptionChecked = (0, import_react14.useCallback)(
5892
+ const isOptionChecked = (0, import_react15.useCallback)(
5730
5893
  (label) => {
5731
5894
  if (mode === "exclude") {
5732
5895
  return !excludedSet.has(label);
@@ -5735,14 +5898,14 @@ function RelationFilterPopover({
5735
5898
  },
5736
5899
  [mode, excludedSet, checkedSet]
5737
5900
  );
5738
- const allFilteredSelected = (0, import_react14.useMemo)(() => {
5901
+ const allFilteredSelected = (0, import_react15.useMemo)(() => {
5739
5902
  if (filteredOptions.length === 0) return false;
5740
5903
  return filteredOptions.every((opt) => isOptionChecked(opt.label));
5741
5904
  }, [filteredOptions, isOptionChecked]);
5742
- const someFilteredSelected = (0, import_react14.useMemo)(() => {
5905
+ const someFilteredSelected = (0, import_react15.useMemo)(() => {
5743
5906
  return filteredOptions.some((opt) => isOptionChecked(opt.label));
5744
5907
  }, [filteredOptions, isOptionChecked]);
5745
- (0, import_react14.useEffect)(() => {
5908
+ (0, import_react15.useEffect)(() => {
5746
5909
  if (selectAllRef.current) {
5747
5910
  selectAllRef.current.indeterminate = !allFilteredSelected && someFilteredSelected;
5748
5911
  }
@@ -5801,7 +5964,7 @@ function RelationFilterPopover({
5801
5964
  onSelectionChange(void 0);
5802
5965
  };
5803
5966
  if (!isOpen || !coords) return null;
5804
- const selectedCount = (0, import_react14.useMemo)(() => {
5967
+ const selectedCount = (0, import_react15.useMemo)(() => {
5805
5968
  if (mode === "exclude") {
5806
5969
  return Math.max(0, options.length - excludedSet.size);
5807
5970
  }
@@ -5970,7 +6133,7 @@ function TableBlockClient({
5970
6133
  editModelUrl
5971
6134
  }) {
5972
6135
  const { showError, addToast } = useToast();
5973
- const [isExporting, setIsExporting] = (0, import_react15.useState)(false);
6136
+ const [isExporting, setIsExporting] = (0, import_react16.useState)(false);
5974
6137
  const resolvedRole = role ? getRolePermissions(role) : void 0;
5975
6138
  const effectivePermissions = permissions || (resolvedRole == null ? void 0 : resolvedRole.permissions) || {
5976
6139
  canCreate: !readOnly,
@@ -5989,18 +6152,18 @@ function TableBlockClient({
5989
6152
  return calculateMinColumnWidth(colName, false, col == null ? void 0 : col.type);
5990
6153
  }
5991
6154
  });
5992
- const executeActionRef = (0, import_react15.useRef)(executeAction);
5993
- (0, import_react15.useEffect)(() => {
6155
+ const executeActionRef = (0, import_react16.useRef)(executeAction);
6156
+ (0, import_react16.useEffect)(() => {
5994
6157
  executeActionRef.current = executeAction;
5995
6158
  }, [executeAction]);
5996
- const [isMounted, setIsMounted] = (0, import_react15.useState)(false);
5997
- const [isInitialLoading, setIsInitialLoading] = (0, import_react15.useState)(true);
5998
- const [page, setPage] = (0, import_react15.useState)(1);
5999
- const [limit, setLimit] = (0, import_react15.useState)(50);
6000
- const [totalRecords, setTotalRecords] = (0, import_react15.useState)(0);
6001
- const [totalPages, setTotalPages] = (0, import_react15.useState)(1);
6002
- const [showSummary, setShowSummary] = (0, import_react15.useState)(false);
6003
- (0, import_react15.useEffect)(() => {
6159
+ const [isMounted, setIsMounted] = (0, import_react16.useState)(false);
6160
+ const [isInitialLoading, setIsInitialLoading] = (0, import_react16.useState)(true);
6161
+ const [page, setPage] = (0, import_react16.useState)(1);
6162
+ const [limit, setLimit] = (0, import_react16.useState)(50);
6163
+ const [totalRecords, setTotalRecords] = (0, import_react16.useState)(0);
6164
+ const [totalPages, setTotalPages] = (0, import_react16.useState)(1);
6165
+ const [showSummary, setShowSummary] = (0, import_react16.useState)(false);
6166
+ (0, import_react16.useEffect)(() => {
6004
6167
  if (typeof window !== "undefined") {
6005
6168
  const savedSummary = localStorage.getItem(`table_summary_${tableKey}`);
6006
6169
  if (savedSummary !== null) {
@@ -6049,7 +6212,7 @@ function TableBlockClient({
6049
6212
  return __spreadProps(__spreadValues({}, row), { id: String(row.id || ""), data: rowData });
6050
6213
  });
6051
6214
  };
6052
- const mergeColumnDefs = (0, import_react15.useCallback)((existingCols, incomingCols) => {
6215
+ const mergeColumnDefs = (0, import_react16.useCallback)((existingCols, incomingCols) => {
6053
6216
  if (!incomingCols || incomingCols.length === 0) return existingCols || [];
6054
6217
  if (!existingCols || existingCols.length === 0) return incomingCols;
6055
6218
  const existingMap = new Map(existingCols.map((c) => [c.name, c]));
@@ -6069,18 +6232,18 @@ function TableBlockClient({
6069
6232
  return ((_a = a.order) != null ? _a : 0) - ((_b = b.order) != null ? _b : 0);
6070
6233
  });
6071
6234
  }, []);
6072
- const [localColumns, setLocalColumns] = (0, import_react15.useState)(() => (schema == null ? void 0 : schema.columns) || []);
6073
- (0, import_react15.useEffect)(() => {
6235
+ const [localColumns, setLocalColumns] = (0, import_react16.useState)(() => (schema == null ? void 0 : schema.columns) || []);
6236
+ (0, import_react16.useEffect)(() => {
6074
6237
  if ((schema == null ? void 0 : schema.columns) && schema.columns.length > 0) {
6075
6238
  setLocalColumns((prev) => mergeColumnDefs(prev, schema.columns));
6076
6239
  }
6077
6240
  }, [schema == null ? void 0 : schema.columns, mergeColumnDefs]);
6078
- const [dirty, setDirty] = (0, import_react15.useState)({ added: [], modified: {}, deleted: [] });
6079
- const dirtyRef = (0, import_react15.useRef)(dirty);
6080
- (0, import_react15.useEffect)(() => {
6241
+ const [dirty, setDirty] = (0, import_react16.useState)({ added: [], modified: {}, deleted: [] });
6242
+ const dirtyRef = (0, import_react16.useRef)(dirty);
6243
+ (0, import_react16.useEffect)(() => {
6081
6244
  dirtyRef.current = dirty;
6082
6245
  }, [dirty]);
6083
- const mergeWithDirty = (0, import_react15.useCallback)((baseRecords) => {
6246
+ const mergeWithDirty = (0, import_react16.useCallback)((baseRecords) => {
6084
6247
  const { added, modified, deleted } = dirtyRef.current;
6085
6248
  const nonDeleted = (baseRecords || []).filter((r) => !deleted.includes(r.id));
6086
6249
  const modifiedRecords = nonDeleted.map((r) => {
@@ -6093,8 +6256,8 @@ function TableBlockClient({
6093
6256
  const uniqueAdded = added.filter((r) => !baseIds.has(r.id));
6094
6257
  return [...uniqueAdded, ...modifiedRecords];
6095
6258
  }, []);
6096
- const [data, setData] = (0, import_react15.useState)(() => normalizeRecords(initialRecords));
6097
- const [serverRecords, setServerRecords] = (0, import_react15.useState)(() => normalizeRecords(initialRecords));
6259
+ const [data, setData] = (0, import_react16.useState)(() => normalizeRecords(initialRecords));
6260
+ const [serverRecords, setServerRecords] = (0, import_react16.useState)(() => normalizeRecords(initialRecords));
6098
6261
  const filteredData = data;
6099
6262
  const isEqualValues = (a, b) => {
6100
6263
  if (a === b) return true;
@@ -6106,30 +6269,30 @@ function TableBlockClient({
6106
6269
  }
6107
6270
  return false;
6108
6271
  };
6109
- const [baseRecordsMap, setBaseRecordsMap] = (0, import_react15.useState)(() => {
6272
+ const [baseRecordsMap, setBaseRecordsMap] = (0, import_react16.useState)(() => {
6110
6273
  const map = /* @__PURE__ */ new Map();
6111
6274
  (normalizeRecords(initialRecords) || []).forEach((r) => map.set(r.id, __spreadValues({}, r.data)));
6112
6275
  return map;
6113
6276
  });
6114
- (0, import_react15.useEffect)(() => {
6277
+ (0, import_react16.useEffect)(() => {
6115
6278
  if (initialRecords && initialRecords.length > 0) {
6116
6279
  const map = /* @__PURE__ */ new Map();
6117
6280
  (normalizeRecords(initialRecords) || []).forEach((r) => map.set(r.id, __spreadValues({}, r.data)));
6118
6281
  setBaseRecordsMap(map);
6119
6282
  }
6120
6283
  }, [initialRecords]);
6121
- const [searchQuery, setSearchQuery] = (0, import_react15.useState)("");
6122
- const [columnFilters, setColumnFilters] = (0, import_react15.useState)({});
6123
- const [activeSearchCol, setActiveSearchCol] = (0, import_react15.useState)(null);
6124
- const activeSearchRef = (0, import_react15.useRef)(null);
6125
- const [activeRelationCol, setActiveRelationCol] = (0, import_react15.useState)(null);
6126
- const [relationTriggerRect, setRelationTriggerRect] = (0, import_react15.useState)(null);
6127
- const filterButtonRefs = (0, import_react15.useRef)({});
6128
- const [relationOptions, setRelationOptions] = (0, import_react15.useState)({});
6129
- const [relationFilterOptions, setRelationFilterOptions] = (0, import_react15.useState)({});
6130
- const [loadingFilterCol, setLoadingFilterCol] = (0, import_react15.useState)(null);
6131
- const relationDictionaryRef = (0, import_react15.useRef)({});
6132
- const mergeRelationOptions = (0, import_react15.useCallback)((colName, newOptions) => {
6284
+ const [searchQuery, setSearchQuery] = (0, import_react16.useState)("");
6285
+ const [columnFilters, setColumnFilters] = (0, import_react16.useState)({});
6286
+ const [activeSearchCol, setActiveSearchCol] = (0, import_react16.useState)(null);
6287
+ const activeSearchRef = (0, import_react16.useRef)(null);
6288
+ const [activeRelationCol, setActiveRelationCol] = (0, import_react16.useState)(null);
6289
+ const [relationTriggerRect, setRelationTriggerRect] = (0, import_react16.useState)(null);
6290
+ const filterButtonRefs = (0, import_react16.useRef)({});
6291
+ const [relationOptions, setRelationOptions] = (0, import_react16.useState)({});
6292
+ const [relationFilterOptions, setRelationFilterOptions] = (0, import_react16.useState)({});
6293
+ const [loadingFilterCol, setLoadingFilterCol] = (0, import_react16.useState)(null);
6294
+ const relationDictionaryRef = (0, import_react16.useRef)({});
6295
+ const mergeRelationOptions = (0, import_react16.useCallback)((colName, newOptions) => {
6133
6296
  if (!Array.isArray(newOptions) || newOptions.length === 0) return;
6134
6297
  if (!relationDictionaryRef.current[colName]) {
6135
6298
  relationDictionaryRef.current[colName] = /* @__PURE__ */ new Map();
@@ -6152,7 +6315,7 @@ function TableBlockClient({
6152
6315
  }));
6153
6316
  }
6154
6317
  }, []);
6155
- (0, import_react15.useEffect)(() => {
6318
+ (0, import_react16.useEffect)(() => {
6156
6319
  if (!activeSearchCol) return;
6157
6320
  const handleMouseDown = (e) => {
6158
6321
  if (activeSearchRef.current && !activeSearchRef.current.contains(e.target)) {
@@ -6164,7 +6327,7 @@ function TableBlockClient({
6164
6327
  document.removeEventListener("mousedown", handleMouseDown);
6165
6328
  };
6166
6329
  }, [activeSearchCol]);
6167
- const filtersKey = (0, import_react15.useMemo)(() => {
6330
+ const filtersKey = (0, import_react16.useMemo)(() => {
6168
6331
  const active = {};
6169
6332
  Object.entries(columnFilters).forEach(([k, v]) => {
6170
6333
  if (Array.isArray(v) && v.length > 0) active[k] = v;
@@ -6173,24 +6336,24 @@ function TableBlockClient({
6173
6336
  });
6174
6337
  return JSON.stringify(active);
6175
6338
  }, [columnFilters]);
6176
- const [debouncedSearch, setDebouncedSearch] = (0, import_react15.useState)(searchQuery);
6177
- (0, import_react15.useEffect)(() => {
6339
+ const [debouncedSearch, setDebouncedSearch] = (0, import_react16.useState)(searchQuery);
6340
+ (0, import_react16.useEffect)(() => {
6178
6341
  const timer = setTimeout(() => {
6179
6342
  setDebouncedSearch(searchQuery.trim());
6180
6343
  }, 300);
6181
6344
  return () => clearTimeout(timer);
6182
6345
  }, [searchQuery]);
6183
- const isSearchMountedRef = (0, import_react15.useRef)(false);
6184
- (0, import_react15.useEffect)(() => {
6346
+ const isSearchMountedRef = (0, import_react16.useRef)(false);
6347
+ (0, import_react16.useEffect)(() => {
6185
6348
  if (!isSearchMountedRef.current) {
6186
6349
  isSearchMountedRef.current = true;
6187
6350
  return;
6188
6351
  }
6189
6352
  setPage(1);
6190
6353
  }, [debouncedSearch]);
6191
- const [isFetching, setIsFetching] = (0, import_react15.useState)(false);
6192
- const fetchRequestIdRef = (0, import_react15.useRef)(0);
6193
- const fetchTableData = (0, import_react15.useCallback)((targetPage, targetLimit, targetSearch, targetFiltersKey) => {
6354
+ const [isFetching, setIsFetching] = (0, import_react16.useState)(false);
6355
+ const fetchRequestIdRef = (0, import_react16.useRef)(0);
6356
+ const fetchTableData = (0, import_react16.useCallback)((targetPage, targetLimit, targetSearch, targetFiltersKey) => {
6194
6357
  const tableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
6195
6358
  const action = executeActionRef.current;
6196
6359
  if (!tableId || !action) {
@@ -6314,10 +6477,10 @@ function TableBlockClient({
6314
6477
  }
6315
6478
  });
6316
6479
  }, [schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.id, mergeColumnDefs, mergeWithDirty, mergeRelationOptions]);
6317
- (0, import_react15.useEffect)(() => {
6480
+ (0, import_react16.useEffect)(() => {
6318
6481
  fetchTableData(page, limit, debouncedSearch, filtersKey);
6319
6482
  }, [page, limit, debouncedSearch, filtersKey, fetchTableData]);
6320
- (0, import_react15.useEffect)(() => {
6483
+ (0, import_react16.useEffect)(() => {
6321
6484
  if (initialRecords) {
6322
6485
  const norm = normalizeRecords(initialRecords);
6323
6486
  setServerRecords(norm);
@@ -6380,10 +6543,10 @@ function TableBlockClient({
6380
6543
  }
6381
6544
  }
6382
6545
  }, [initialRecords, mergeWithDirty, debouncedSearch, columnFilters, fetchTableData, page, limit, filtersKey]);
6383
- const refetchTableData = (0, import_react15.useCallback)(() => {
6546
+ const refetchTableData = (0, import_react16.useCallback)(() => {
6384
6547
  return fetchTableData(page, limit, debouncedSearch, filtersKey);
6385
6548
  }, [page, limit, debouncedSearch, filtersKey, fetchTableData]);
6386
- const handleApplyColumnFilter = (0, import_react15.useCallback)((colName, nextVal) => {
6549
+ const handleApplyColumnFilter = (0, import_react16.useCallback)((colName, nextVal) => {
6387
6550
  setColumnFilters((prev) => {
6388
6551
  const next = __spreadValues({}, prev);
6389
6552
  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) {
@@ -6408,9 +6571,9 @@ function TableBlockClient({
6408
6571
  const handleNextPage = () => {
6409
6572
  setPage((prev) => Math.min(totalPages, prev + 1));
6410
6573
  };
6411
- const [selectedIds, setSelectedIds] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
6412
- const isExternalSyncRef = (0, import_react15.useRef)(false);
6413
- (0, import_react15.useEffect)(() => {
6574
+ const [selectedIds, setSelectedIds] = (0, import_react16.useState)(/* @__PURE__ */ new Set());
6575
+ const isExternalSyncRef = (0, import_react16.useRef)(false);
6576
+ (0, import_react16.useEffect)(() => {
6414
6577
  if (selectedRowIds !== void 0) {
6415
6578
  const nextSet = new Set(selectedRowIds);
6416
6579
  setSelectedIds((prev) => {
@@ -6422,8 +6585,8 @@ function TableBlockClient({
6422
6585
  });
6423
6586
  }
6424
6587
  }, [selectedRowIds]);
6425
- const isFirstSelectionChangeRef = (0, import_react15.useRef)(true);
6426
- (0, import_react15.useEffect)(() => {
6588
+ const isFirstSelectionChangeRef = (0, import_react16.useRef)(true);
6589
+ (0, import_react16.useEffect)(() => {
6427
6590
  if (isFirstSelectionChangeRef.current) {
6428
6591
  isFirstSelectionChangeRef.current = false;
6429
6592
  if (selectedIds.size === 0) return;
@@ -6434,13 +6597,13 @@ function TableBlockClient({
6434
6597
  }
6435
6598
  onSelectionChange == null ? void 0 : onSelectionChange(Array.from(selectedIds));
6436
6599
  }, [selectedIds, onSelectionChange]);
6437
- const [pendingDeletions, setPendingDeletions] = (0, import_react15.useState)([]);
6438
- const [isSaving, setIsSaving] = (0, import_react15.useState)(false);
6600
+ const [pendingDeletions, setPendingDeletions] = (0, import_react16.useState)([]);
6601
+ const [isSaving, setIsSaving] = (0, import_react16.useState)(false);
6439
6602
  const isUpdatingActive = Boolean(isUpdating || isSaving);
6440
- const [isSaveSuccess, setIsSaveSuccess] = (0, import_react15.useState)(false);
6441
- const [expandedRowIds, setExpandedRowIds] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
6442
- const schemaColsString = (0, import_react15.useMemo)(() => JSON.stringify(localColumns || []), [localColumns]);
6443
- const refetchRelation = (0, import_react15.useCallback)(async (colName, params) => {
6603
+ const [isSaveSuccess, setIsSaveSuccess] = (0, import_react16.useState)(false);
6604
+ const [expandedRowIds, setExpandedRowIds] = (0, import_react16.useState)(/* @__PURE__ */ new Set());
6605
+ const schemaColsString = (0, import_react16.useMemo)(() => JSON.stringify(localColumns || []), [localColumns]);
6606
+ const refetchRelation = (0, import_react16.useCallback)(async (colName, params) => {
6444
6607
  var _a, _b, _c, _d, _e, _f, _g;
6445
6608
  let parsedCols = [];
6446
6609
  try {
@@ -6479,7 +6642,7 @@ function TableBlockClient({
6479
6642
  }
6480
6643
  return [];
6481
6644
  }, [schemaColsString, executeAction, mergeRelationOptions]);
6482
- const fetchRelationFilterOptions = (0, import_react15.useCallback)(async (colName) => {
6645
+ const fetchRelationFilterOptions = (0, import_react16.useCallback)(async (colName) => {
6483
6646
  var _a;
6484
6647
  let parsedCols = [];
6485
6648
  try {
@@ -6515,8 +6678,8 @@ function TableBlockClient({
6515
6678
  setLoadingFilterCol(null);
6516
6679
  }
6517
6680
  }, [schemaColsString, schema == null ? void 0 : schema.tableMetaId, schema == null ? void 0 : schema.tableId, schema == null ? void 0 : schema.id, executeAction, mergeRelationOptions]);
6518
- const requestedRelationIdsRef = (0, import_react15.useRef)({});
6519
- (0, import_react15.useEffect)(() => {
6681
+ const requestedRelationIdsRef = (0, import_react16.useRef)({});
6682
+ (0, import_react16.useEffect)(() => {
6520
6683
  if (!executeAction || !data || data.length === 0) return;
6521
6684
  let parsedCols = [];
6522
6685
  try {
@@ -6569,7 +6732,7 @@ function TableBlockClient({
6569
6732
  }
6570
6733
  });
6571
6734
  }, [data, schemaColsString, executeAction, relationOptions, mergeRelationOptions]);
6572
- (0, import_react15.useEffect)(() => {
6735
+ (0, import_react16.useEffect)(() => {
6573
6736
  let parsedCols = [];
6574
6737
  try {
6575
6738
  parsedCols = JSON.parse(schemaColsString);
@@ -6583,7 +6746,7 @@ function TableBlockClient({
6583
6746
  refetchRelation(col.name);
6584
6747
  });
6585
6748
  }, [schemaColsString, refetchRelation]);
6586
- const normalizedColumns = (0, import_react15.useMemo)(() => {
6749
+ const normalizedColumns = (0, import_react16.useMemo)(() => {
6587
6750
  return (localColumns || []).map((col, idx) => {
6588
6751
  const isRequired = col.isRequired === true || String(col.isRequired) === "true";
6589
6752
  const isUnique = col.isUnique === true || String(col.isUnique) === "true";
@@ -6597,17 +6760,17 @@ function TableBlockClient({
6597
6760
  return ((_a = a.order) != null ? _a : 0) - ((_b = b.order) != null ? _b : 0);
6598
6761
  });
6599
6762
  }, [localColumns]);
6600
- const filteredColumns = (0, import_react15.useMemo)(() => {
6763
+ const filteredColumns = (0, import_react16.useMemo)(() => {
6601
6764
  const systemFields = ["_id", "createdAt", "updatedAt", "orgId", "tableId"];
6602
6765
  return normalizedColumns.filter((col) => !systemFields.includes(col.name) && !col.isHidden);
6603
6766
  }, [normalizedColumns]);
6604
- const customizableColumns = (0, import_react15.useMemo)(() => {
6767
+ const customizableColumns = (0, import_react16.useMemo)(() => {
6605
6768
  const systemFields = ["_id", "createdAt", "updatedAt", "orgId", "tableId"];
6606
6769
  return normalizedColumns.filter((col) => !systemFields.includes(col.name));
6607
6770
  }, [normalizedColumns]);
6608
- const [isColumnsDropdownOpen, setIsColumnsDropdownOpen] = (0, import_react15.useState)(false);
6609
- const dropdownRef = (0, import_react15.useRef)(null);
6610
- (0, import_react15.useEffect)(() => {
6771
+ const [isColumnsDropdownOpen, setIsColumnsDropdownOpen] = (0, import_react16.useState)(false);
6772
+ const dropdownRef = (0, import_react16.useRef)(null);
6773
+ (0, import_react16.useEffect)(() => {
6611
6774
  const handleClickOutside = (e) => {
6612
6775
  if (dropdownRef.current && !dropdownRef.current.contains(e.target)) {
6613
6776
  setIsColumnsDropdownOpen(false);
@@ -6817,7 +6980,7 @@ function TableBlockClient({
6817
6980
  setData((prev) => [newRow, ...prev]);
6818
6981
  setDirty((prev) => __spreadProps(__spreadValues({}, prev), { added: [newRow, ...prev.added] }));
6819
6982
  };
6820
- const handleCellChange = (0, import_react15.useCallback)((rowId, colName, value) => {
6983
+ const handleCellChange = (0, import_react16.useCallback)((rowId, colName, value) => {
6821
6984
  setData((prev) => prev.map(
6822
6985
  (row) => row.id === rowId ? __spreadProps(__spreadValues({}, row), { data: __spreadProps(__spreadValues({}, row.data), { [colName]: value }) }) : row
6823
6986
  ));
@@ -6849,13 +7012,14 @@ function TableBlockClient({
6849
7012
  });
6850
7013
  });
6851
7014
  }, [baseRecordsMap]);
6852
- const triggerSaveSuccess = (0, import_react15.useCallback)(() => {
7015
+ const handleCellChangeWithCopy = useRelationCopyHandler({ columns: localColumns, handleCellChange });
7016
+ const triggerSaveSuccess = (0, import_react16.useCallback)(() => {
6853
7017
  setIsSaveSuccess(true);
6854
7018
  setTimeout(() => {
6855
7019
  setIsSaveSuccess(false);
6856
7020
  }, 2500);
6857
7021
  }, []);
6858
- const handleQuietCellChange = (0, import_react15.useCallback)((rowId, colName, value) => {
7022
+ const handleQuietCellChange = (0, import_react16.useCallback)((rowId, colName, value) => {
6859
7023
  setData((prev) => prev.map(
6860
7024
  (row) => row.id === rowId ? __spreadProps(__spreadValues({}, row), { data: __spreadProps(__spreadValues({}, row.data), { [colName]: value }) }) : row
6861
7025
  ));
@@ -6879,12 +7043,12 @@ function TableBlockClient({
6879
7043
  });
6880
7044
  }
6881
7045
  }, []);
6882
- const toggleSelectAll = (0, import_react15.useCallback)((checked) => {
7046
+ const toggleSelectAll = (0, import_react16.useCallback)((checked) => {
6883
7047
  onRowToggle == null ? void 0 : onRowToggle("ALL", checked);
6884
7048
  const next = checked ? new Set(filteredData.map((r) => r.id)) : /* @__PURE__ */ new Set();
6885
7049
  setSelectedIds(next);
6886
7050
  }, [filteredData, onRowToggle]);
6887
- const toggleSelectRow = (0, import_react15.useCallback)((rowId, checked) => {
7051
+ const toggleSelectRow = (0, import_react16.useCallback)((rowId, checked) => {
6888
7052
  onRowToggle == null ? void 0 : onRowToggle(rowId, checked);
6889
7053
  setSelectedIds((prev) => {
6890
7054
  const next = new Set(prev);
@@ -6893,7 +7057,7 @@ function TableBlockClient({
6893
7057
  return next;
6894
7058
  });
6895
7059
  }, [onRowToggle]);
6896
- const handleToggleExpand = (0, import_react15.useCallback)((rowId) => {
7060
+ const handleToggleExpand = (0, import_react16.useCallback)((rowId) => {
6897
7061
  setExpandedRowIds((prev) => {
6898
7062
  const next = new Set(prev);
6899
7063
  if (next.has(rowId)) next.delete(rowId);
@@ -6901,7 +7065,7 @@ function TableBlockClient({
6901
7065
  return next;
6902
7066
  });
6903
7067
  }, []);
6904
- const handleMarkForDeletion = (0, import_react15.useCallback)((fileId) => {
7068
+ const handleMarkForDeletion = (0, import_react16.useCallback)((fileId) => {
6905
7069
  setPendingDeletions((prev) => [...prev, fileId]);
6906
7070
  }, []);
6907
7071
  const handleDeleteSelected = () => {
@@ -7129,7 +7293,7 @@ function TableBlockClient({
7129
7293
  setIsSaving(false);
7130
7294
  }
7131
7295
  };
7132
- const getRowRelationLabels = (0, import_react15.useCallback)((rowVal, col) => {
7296
+ const getRowRelationLabels = (0, import_react16.useCallback)((rowVal, col) => {
7133
7297
  const ids = normalizeRelationValue(rowVal);
7134
7298
  if (ids.length === 0) return [];
7135
7299
  const options = relationOptions[col.name] || [];
@@ -7148,7 +7312,7 @@ function TableBlockClient({
7148
7312
  return "";
7149
7313
  }).filter(Boolean);
7150
7314
  }, [relationOptions]);
7151
- const getUniqueRelationOptions = (0, import_react15.useCallback)((col) => {
7315
+ const getUniqueRelationOptions = (0, import_react16.useCallback)((col) => {
7152
7316
  if (relationFilterOptions[col.name]) {
7153
7317
  return relationFilterOptions[col.name];
7154
7318
  }
@@ -7180,7 +7344,7 @@ function TableBlockClient({
7180
7344
  return results.sort((a, b) => a.label.localeCompare(b.label));
7181
7345
  }, [data, relationOptions, relationFilterOptions]);
7182
7346
  const errorMessage = error ? typeof error === "string" ? error : error.message || String(error) : null;
7183
- const columnTotals = (0, import_react15.useMemo)(() => {
7347
+ const columnTotals = (0, import_react16.useMemo)(() => {
7184
7348
  const totals = {};
7185
7349
  if (!showSummary) return totals;
7186
7350
  filteredColumns.forEach((col) => {
@@ -7576,7 +7740,7 @@ function TableBlockClient({
7576
7740
  const isDragOver = canReorderColumns && dragOverColName === col.name;
7577
7741
  const colMinWidth = calculateMinColumnWidth(col.name, false, col.type);
7578
7742
  const currentWidth = Math.max(colMinWidth, columnWidths[col.name] || 200);
7579
- const isRelation = ((_a = col.type) == null ? void 0 : _a.toUpperCase()) === "RELATION";
7743
+ const isRelation2 = ((_a = col.type) == null ? void 0 : _a.toUpperCase()) === "RELATION";
7580
7744
  const filterVal = columnFilters[col.name];
7581
7745
  const hasActiveFilter = Array.isArray(filterVal) ? filterVal.length > 0 : filterVal && typeof filterVal === "object" && "values" in filterVal ? filterVal.values.length > 0 : Boolean(filterVal && filterVal.trim() !== "");
7582
7746
  let filterTooltip = "\u05D7\u05E4\u05E9 \u05D5\u05E1\u05E0\u05DF \u05D1\u05E2\u05DE\u05D5\u05D3\u05D4 \u05D6\u05D5";
@@ -7607,7 +7771,7 @@ function TableBlockClient({
7607
7771
  title: "\u05E9\u05E0\u05D4 \u05D2\u05D5\u05D3\u05DC \u05E2\u05DE\u05D5\u05D3\u05D4"
7608
7772
  }
7609
7773
  ),
7610
- isSearching && !isRelation ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
7774
+ isSearching && !isRelation2 ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
7611
7775
  "div",
7612
7776
  {
7613
7777
  ref: activeSearchRef,
@@ -7664,7 +7828,7 @@ function TableBlockClient({
7664
7828
  onClick: (e) => {
7665
7829
  e.stopPropagation();
7666
7830
  e.preventDefault();
7667
- if (isRelation) {
7831
+ if (isRelation2) {
7668
7832
  if (activeRelationCol === col.name) {
7669
7833
  setActiveRelationCol(null);
7670
7834
  setRelationTriggerRect(null);
@@ -7680,7 +7844,7 @@ function TableBlockClient({
7680
7844
  setActiveSearchCol(col.name);
7681
7845
  }
7682
7846
  },
7683
- className: `p-0.5 rounded transition-colors cursor-pointer mb-0.5 shrink-0 ${hasActiveFilter ? "opacity-100 text-blue-600 bg-blue-100 hover:bg-blue-200" : activeRelationCol === col.name ? "opacity-100 text-blue-600 bg-blue-100" : isRelation ? "opacity-100 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60" : "opacity-0 group-hover:opacity-100 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60"}`,
7847
+ className: `p-0.5 rounded transition-colors cursor-pointer mb-0.5 shrink-0 ${hasActiveFilter ? "opacity-100 text-blue-600 bg-blue-100 hover:bg-blue-200" : activeRelationCol === col.name ? "opacity-100 text-blue-600 bg-blue-100" : isRelation2 ? "opacity-100 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60" : "opacity-0 group-hover:opacity-100 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60"}`,
7684
7848
  title: filterTooltip,
7685
7849
  children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_lucide_react9.Filter, { className: "w-3 h-3" })
7686
7850
  }
@@ -7725,7 +7889,7 @@ function TableBlockClient({
7725
7889
  isUpdatingActive,
7726
7890
  onToggleSelect: toggleSelectRow,
7727
7891
  onToggleExpand: handleToggleExpand,
7728
- handleCellChange,
7892
+ handleCellChange: handleCellChangeWithCopy,
7729
7893
  handleQuietCellChange,
7730
7894
  handleUpdateColumnConfig,
7731
7895
  onMarkForDeletion: handleMarkForDeletion,
@@ -7857,7 +8021,7 @@ function ExpandedSubTables({
7857
8021
  context
7858
8022
  }) {
7859
8023
  var _a;
7860
- const [activeTab, setActiveTab] = (0, import_react15.useState)((_a = subTableColumns[0]) == null ? void 0 : _a.name);
8024
+ const [activeTab, setActiveTab] = (0, import_react16.useState)((_a = subTableColumns[0]) == null ? void 0 : _a.name);
7861
8025
  if (subTableColumns.length === 0) return null;
7862
8026
  if (subTableColumns.length === 1) {
7863
8027
  const stCol = subTableColumns[0];
@@ -7898,7 +8062,7 @@ function ExpandedSubTables({
7898
8062
  ) })
7899
8063
  ] }) });
7900
8064
  }
7901
- var TableRow = import_react15.default.memo(function TableRow2({
8065
+ var TableRow = import_react16.default.memo(function TableRow2({
7902
8066
  row,
7903
8067
  isSelected,
7904
8068
  rowStatus,
@@ -7929,7 +8093,8 @@ var TableRow = import_react15.default.memo(function TableRow2({
7929
8093
  readOnly,
7930
8094
  permissions
7931
8095
  }) {
7932
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react15.default.Fragment, { children: [
8096
+ const lockedCopyTargets = getRelationCopyLockedTargets(schema == null ? void 0 : schema.columns);
8097
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react16.default.Fragment, { children: [
7933
8098
  /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { className: `transition-colors group hover:bg-blue-50 ${isSelected ? "bg-blue-50" : ""}`, children: [
7934
8099
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("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__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center justify-center gap-1.5", children: [
7935
8100
  rowStatus && (() => {
@@ -8024,7 +8189,7 @@ var TableRow = import_react15.default.memo(function TableRow2({
8024
8189
  column: col,
8025
8190
  rowId: row.id,
8026
8191
  onChange: (v) => handleCellChange(row.id, col.name, v),
8027
- readOnly,
8192
+ readOnly: readOnly || lockedCopyTargets.has(col.name),
8028
8193
  context: {
8029
8194
  tableName: (schema == null ? void 0 : schema.name) || (schema == null ? void 0 : schema.tableName) || (schema == null ? void 0 : schema.title) || (schema == null ? void 0 : schema.id) || "Table",
8030
8195
  tableId: (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id),
@@ -8085,12 +8250,12 @@ function TableBlock(props) {
8085
8250
  }
8086
8251
 
8087
8252
  // src/components/PlacementBlock/PlacementBlock.tsx
8088
- var import_react17 = require("react");
8253
+ var import_react18 = require("react");
8089
8254
  var import_ag_grid_react = require("ag-grid-react");
8090
8255
  var import_ag_grid_community = require("ag-grid-community");
8091
8256
 
8092
8257
  // src/components/PlacementBlock/PlacementSettings.tsx
8093
- var import_react16 = __toESM(require("react"));
8258
+ var import_react17 = __toESM(require("react"));
8094
8259
 
8095
8260
  // src/components/PlacementBlock/placementColumns.ts
8096
8261
  var RELATION_SEP = "::";
@@ -8212,7 +8377,7 @@ var SummaryRow = ({ label, value, hint }) => /* @__PURE__ */ (0, import_jsx_runt
8212
8377
  ] });
8213
8378
  var PlacementStatusEditor = ({ config, onChange }) => {
8214
8379
  var _a;
8215
- const radioName = `placement-default-status-${import_react16.default.useId()}`;
8380
+ const radioName = `placement-default-status-${import_react17.default.useId()}`;
8216
8381
  const statuses = ((_a = config.statusColors) == null ? void 0 : _a.length) ? config.statusColors : DEFAULT_PLACEMENT_STATUS_COLORS;
8217
8382
  const defaultStatusId = resolveDefaultStatusId(statuses, config.defaultReturnStatusId);
8218
8383
  const setStatuses = (next, defId = defaultStatusId) => {
@@ -8561,20 +8726,20 @@ var CheckHeader = (props) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div"
8561
8726
  var PlacementBlock = (props) => {
8562
8727
  var _a, _b;
8563
8728
  const { executeAction, fetchSourceData, fetchTargetData, updateAssignment, className = "" } = props;
8564
- const config = (0, import_react17.useMemo)(() => {
8729
+ const config = (0, import_react18.useMemo)(() => {
8565
8730
  var _a2, _b2, _c;
8566
8731
  const raw = (_a2 = props.config) != null ? _a2 : props.settings;
8567
8732
  if (!raw) return void 0;
8568
8733
  return ((_b2 = raw.config) == null ? void 0 : _b2.sourceTableId) || ((_c = raw.config) == null ? void 0 : _c.targetTableId) ? raw.config : raw;
8569
8734
  }, [props.config, props.settings]);
8570
- const statuses = (0, import_react17.useMemo)(
8735
+ const statuses = (0, import_react18.useMemo)(
8571
8736
  () => {
8572
8737
  var _a2;
8573
8738
  return ((_a2 = config == null ? void 0 : config.statusColors) == null ? void 0 : _a2.length) ? config.statusColors : DEFAULT_PLACEMENT_STATUS_COLORS;
8574
8739
  },
8575
8740
  [config == null ? void 0 : config.statusColors]
8576
8741
  );
8577
- const defaultStatusId = (0, import_react17.useMemo)(
8742
+ const defaultStatusId = (0, import_react18.useMemo)(
8578
8743
  () => resolveDefaultStatusId(statuses, config == null ? void 0 : config.defaultReturnStatusId),
8579
8744
  [statuses, config == null ? void 0 : config.defaultReturnStatusId]
8580
8745
  );
@@ -8582,27 +8747,27 @@ var PlacementBlock = (props) => {
8582
8747
  const targetTableId = config == null ? void 0 : config.targetTableId;
8583
8748
  const displayField = (config == null ? void 0 : config.sourceDisplayFieldId) || "name";
8584
8749
  const assignmentField = config == null ? void 0 : config.targetAssignmentFieldId;
8585
- const executeActionRef = (0, import_react17.useRef)(executeAction);
8750
+ const executeActionRef = (0, import_react18.useRef)(executeAction);
8586
8751
  executeActionRef.current = executeAction;
8587
- const legacyRef = (0, import_react17.useRef)({ fetchSourceData, fetchTargetData, updateAssignment });
8752
+ const legacyRef = (0, import_react18.useRef)({ fetchSourceData, fetchTargetData, updateAssignment });
8588
8753
  legacyRef.current = { fetchSourceData, fetchTargetData, updateAssignment };
8589
- const [sourceRows, setSourceRows] = (0, import_react17.useState)([]);
8590
- const [sourceColumns, setSourceColumns] = (0, import_react17.useState)([]);
8591
- const [targetRows, setTargetRows] = (0, import_react17.useState)([]);
8592
- const [targetColumns, setTargetColumns] = (0, import_react17.useState)([]);
8593
- const [targetRelOptions, setTargetRelOptions] = (0, import_react17.useState)({});
8594
- const [selectedTargetId, setSelectedTargetId] = (0, import_react17.useState)("");
8595
- const [candidateIds, setCandidateIds] = (0, import_react17.useState)([]);
8596
- const [checkedIds, setCheckedIds] = (0, import_react17.useState)([]);
8597
- const [isSaving, setIsSaving] = (0, import_react17.useState)(false);
8598
- const [sourceSearch, setSourceSearch] = (0, import_react17.useState)("");
8599
- const [candidateSearch, setCandidateSearch] = (0, import_react17.useState)("");
8600
- const [statusMap, setStatusMap] = (0, import_react17.useState)({});
8601
- const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
8602
- const [loadError, setLoadError] = (0, import_react17.useState)(null);
8603
- const [saveError, setSaveError] = (0, import_react17.useState)(null);
8604
- const [targetFilters, setTargetFilters] = (0, import_react17.useState)({});
8605
- const loadTable = (0, import_react17.useCallback)(async (tableId, kind) => {
8754
+ const [sourceRows, setSourceRows] = (0, import_react18.useState)([]);
8755
+ const [sourceColumns, setSourceColumns] = (0, import_react18.useState)([]);
8756
+ const [targetRows, setTargetRows] = (0, import_react18.useState)([]);
8757
+ const [targetColumns, setTargetColumns] = (0, import_react18.useState)([]);
8758
+ const [targetRelOptions, setTargetRelOptions] = (0, import_react18.useState)({});
8759
+ const [selectedTargetId, setSelectedTargetId] = (0, import_react18.useState)("");
8760
+ const [candidateIds, setCandidateIds] = (0, import_react18.useState)([]);
8761
+ const [checkedIds, setCheckedIds] = (0, import_react18.useState)([]);
8762
+ const [isSaving, setIsSaving] = (0, import_react18.useState)(false);
8763
+ const [sourceSearch, setSourceSearch] = (0, import_react18.useState)("");
8764
+ const [candidateSearch, setCandidateSearch] = (0, import_react18.useState)("");
8765
+ const [statusMap, setStatusMap] = (0, import_react18.useState)({});
8766
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
8767
+ const [loadError, setLoadError] = (0, import_react18.useState)(null);
8768
+ const [saveError, setSaveError] = (0, import_react18.useState)(null);
8769
+ const [targetFilters, setTargetFilters] = (0, import_react18.useState)({});
8770
+ const loadTable = (0, import_react18.useCallback)(async (tableId, kind) => {
8606
8771
  const exec = executeActionRef.current;
8607
8772
  if (exec) {
8608
8773
  const res = await exec("FETCH_TABLE_DATA", { tableId, tableMetaId: tableId, limit: FETCH_LIMIT, skip: 0 });
@@ -8615,7 +8780,7 @@ var PlacementBlock = (props) => {
8615
8780
  }
8616
8781
  throw new Error("executeAction \u05DC\u05D0 \u05D4\u05D5\u05E2\u05D1\u05E8 \u05DC\u05E8\u05DB\u05D9\u05D1 \u05D4\u05E9\u05D9\u05D1\u05D5\u05E5");
8617
8782
  }, []);
8618
- (0, import_react17.useEffect)(() => {
8783
+ (0, import_react18.useEffect)(() => {
8619
8784
  if (!sourceTableId || !targetTableId) return;
8620
8785
  let cancelled = false;
8621
8786
  (async () => {
@@ -8642,10 +8807,10 @@ var PlacementBlock = (props) => {
8642
8807
  cancelled = true;
8643
8808
  };
8644
8809
  }, [sourceTableId, targetTableId, loadTable]);
8645
- const displayValue = (0, import_react17.useCallback)((col, val) => {
8810
+ const displayValue = (0, import_react18.useCallback)((col, val) => {
8646
8811
  var _a2, _b2, _c, _d, _e;
8647
- let text = cellText(val);
8648
- if (text && /^[a-fA-F0-9]{24}$/.test(text)) {
8812
+ let text2 = cellText(val);
8813
+ if (text2 && /^[a-fA-F0-9]{24}$/.test(text2)) {
8649
8814
  let opts = targetRelOptions[col == null ? void 0 : col.name] || targetRelOptions[col == null ? void 0 : col.id] || [];
8650
8815
  if (opts.length === 0 && ((_a2 = col == null ? void 0 : col.name) == null ? void 0 : _a2.includes(RELATION_SEP))) {
8651
8816
  const baseName = col.name.split(RELATION_SEP)[0];
@@ -8657,12 +8822,12 @@ var PlacementBlock = (props) => {
8657
8822
  if (opts.length === 0) {
8658
8823
  opts = [...targetRows.map((r) => r.data), ...sourceRows.map((r) => r.data)];
8659
8824
  }
8660
- const found = opts.find((o) => String(o.id) === text || String(o._id) === text || String(o.value) === text);
8825
+ const found = opts.find((o) => String(o.id) === text2 || String(o._id) === text2 || String(o.value) === text2);
8661
8826
  if (found) return cellText((_e = (_d = (_c = (_b2 = found.label) != null ? _b2 : found.title) != null ? _c : found.name) != null ? _d : found.value) != null ? _e : found);
8662
8827
  }
8663
- return text;
8828
+ return text2;
8664
8829
  }, [targetRelOptions, targetRows, sourceRows]);
8665
- const filterColumns = (0, import_react17.useMemo)(() => {
8830
+ const filterColumns = (0, import_react18.useMemo)(() => {
8666
8831
  const definedFilters = (config == null ? void 0 : config.filterFields) || [];
8667
8832
  const legacyFilters = [config == null ? void 0 : config.targetFilterField1Id, config == null ? void 0 : config.targetFilterField2Id].filter(Boolean);
8668
8833
  const fieldsToUse = definedFilters.length > 0 ? definedFilters : legacyFilters;
@@ -8688,7 +8853,7 @@ var PlacementBlock = (props) => {
8688
8853
  return targetColumns.filter((c) => isUserColumn(c) && c.name !== assignmentField && !["id", "_id", "id_", "statusId"].includes(c.name)).slice(0, 3);
8689
8854
  }, [targetColumns, assignmentField, config]);
8690
8855
  const rawSelectorField = (config == null ? void 0 : config.targetSelectorFieldId) || (config == null ? void 0 : config.targetDisplayFieldId) || ((_a = filterColumns[0]) == null ? void 0 : _a.name) || "";
8691
- const selectorField = (0, import_react17.useMemo)(() => {
8856
+ const selectorField = (0, import_react18.useMemo)(() => {
8692
8857
  const { relationColumn } = parseColumnRef(rawSelectorField);
8693
8858
  if (relationColumn && !targetColumns.some((c) => c.name === rawSelectorField) && targetColumns.some((c) => {
8694
8859
  var _a2;
@@ -8698,7 +8863,7 @@ var PlacementBlock = (props) => {
8698
8863
  }
8699
8864
  return rawSelectorField;
8700
8865
  }, [rawSelectorField, targetColumns]);
8701
- const filteredTargetRows = (0, import_react17.useMemo)(() => {
8866
+ const filteredTargetRows = (0, import_react18.useMemo)(() => {
8702
8867
  return targetRows.filter((r) => {
8703
8868
  return filterColumns.every((col) => {
8704
8869
  const filterVal = targetFilters[col.name];
@@ -8707,7 +8872,7 @@ var PlacementBlock = (props) => {
8707
8872
  });
8708
8873
  });
8709
8874
  }, [targetRows, targetFilters, filterColumns, displayValue]);
8710
- (0, import_react17.useEffect)(() => {
8875
+ (0, import_react18.useEffect)(() => {
8711
8876
  if (filteredTargetRows.length > 0) {
8712
8877
  if (!selectedTargetId || !filteredTargetRows.some((r) => r.id === selectedTargetId)) {
8713
8878
  setSelectedTargetId(filteredTargetRows[0].id);
@@ -8716,11 +8881,11 @@ var PlacementBlock = (props) => {
8716
8881
  setSelectedTargetId("");
8717
8882
  }
8718
8883
  }, [filteredTargetRows, selectedTargetId]);
8719
- const assignmentColumn = (0, import_react17.useMemo)(() => targetColumns.find((c) => c.name === assignmentField), [targetColumns, assignmentField]);
8884
+ const assignmentColumn = (0, import_react18.useMemo)(() => targetColumns.find((c) => c.name === assignmentField), [targetColumns, assignmentField]);
8720
8885
  const isRelationField = ((_b = assignmentColumn == null ? void 0 : assignmentColumn.type) == null ? void 0 : _b.toUpperCase()) === "RELATION";
8721
8886
  const assignmentLabel = (assignmentColumn == null ? void 0 : assignmentColumn.label) || (assignmentColumn == null ? void 0 : assignmentColumn.name) || assignmentField || "";
8722
- const nameOf = (0, import_react17.useCallback)((row) => cellText(readColumnValue(row.data, displayField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD", [displayField]);
8723
- const assignedIds = (0, import_react17.useMemo)(() => {
8887
+ const nameOf = (0, import_react18.useCallback)((row) => cellText(readColumnValue(row.data, displayField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD", [displayField]);
8888
+ const assignedIds = (0, import_react18.useMemo)(() => {
8724
8889
  var _a2;
8725
8890
  const target = targetRows.find((r) => r.id === selectedTargetId);
8726
8891
  if (!target || !assignmentField) return [];
@@ -8734,22 +8899,22 @@ var PlacementBlock = (props) => {
8734
8899
  }).filter((id) => !!id && sourceRows.some((s) => s.id === id));
8735
8900
  return Array.from(new Set(ids));
8736
8901
  }, [selectedTargetId, targetRows, sourceRows, assignmentField, isRelationField, nameOf]);
8737
- const assignedIdsRef = (0, import_react17.useRef)(assignedIds);
8902
+ const assignedIdsRef = (0, import_react18.useRef)(assignedIds);
8738
8903
  assignedIdsRef.current = assignedIds;
8739
- (0, import_react17.useEffect)(() => {
8904
+ (0, import_react18.useEffect)(() => {
8740
8905
  setCandidateIds(assignedIdsRef.current);
8741
8906
  setCheckedIds(assignedIdsRef.current);
8742
8907
  }, [selectedTargetId, sourceRows]);
8743
- const toGridRow = (0, import_react17.useCallback)((r, checked = false) => __spreadProps(__spreadValues({}, r.data), { id: r.id, __label: nameOf(r), __checked: checked, statusId: statusMap[r.id] || defaultStatusId }), [nameOf, statusMap, defaultStatusId]);
8744
- const candidateGridData = (0, import_react17.useMemo)(() => {
8908
+ const toGridRow = (0, import_react18.useCallback)((r, checked = false) => __spreadProps(__spreadValues({}, r.data), { id: r.id, __label: nameOf(r), __checked: checked, statusId: statusMap[r.id] || defaultStatusId }), [nameOf, statusMap, defaultStatusId]);
8909
+ const candidateGridData = (0, import_react18.useMemo)(() => {
8745
8910
  const checked = new Set(checkedIds);
8746
8911
  return candidateIds.map((id) => sourceRows.find((r) => r.id === id)).filter((r) => !!r).map((r) => toGridRow(r, checked.has(r.id)));
8747
8912
  }, [candidateIds, checkedIds, sourceRows, toGridRow]);
8748
- const availableGridData = (0, import_react17.useMemo)(() => {
8913
+ const availableGridData = (0, import_react18.useMemo)(() => {
8749
8914
  const set = new Set(candidateIds);
8750
8915
  return sourceRows.filter((r) => !set.has(r.id)).map((r) => toGridRow(r));
8751
8916
  }, [candidateIds, sourceRows, toGridRow]);
8752
- const persistAssignment = (0, import_react17.useCallback)(async (nextIds) => {
8917
+ const persistAssignment = (0, import_react18.useCallback)(async (nextIds) => {
8753
8918
  const exec = executeActionRef.current;
8754
8919
  if (exec && targetTableId && assignmentField && selectedTargetId) {
8755
8920
  const value = isRelationField ? nextIds : nextIds.map((id) => sourceRows.find((r) => r.id === id)).filter((r) => !!r).map(nameOf).join(", ");
@@ -8761,33 +8926,33 @@ var PlacementBlock = (props) => {
8761
8926
  for (const id of nextIds.filter((i) => !assignedIds.includes(i))) await legacyRef.current.updateAssignment(selectedTargetId, id);
8762
8927
  }
8763
8928
  }, [targetTableId, assignmentField, selectedTargetId, isRelationField, sourceRows, nameOf, assignedIds]);
8764
- const moveToCandidates = (0, import_react17.useCallback)((id) => {
8929
+ const moveToCandidates = (0, import_react18.useCallback)((id) => {
8765
8930
  setCandidateIds((prev) => prev.includes(id) ? prev : [...prev, id]);
8766
8931
  }, []);
8767
- const moveToSource = (0, import_react17.useCallback)((id) => {
8932
+ const moveToSource = (0, import_react18.useCallback)((id) => {
8768
8933
  setCandidateIds((prev) => prev.filter((x) => x !== id));
8769
8934
  setCheckedIds((prev) => prev.filter((x) => x !== id));
8770
8935
  setStatusMap((prev) => __spreadProps(__spreadValues({}, prev), { [id]: defaultStatusId }));
8771
8936
  }, [defaultStatusId]);
8772
- const moveToCandidatesRef = (0, import_react17.useRef)(moveToCandidates);
8937
+ const moveToCandidatesRef = (0, import_react18.useRef)(moveToCandidates);
8773
8938
  moveToCandidatesRef.current = moveToCandidates;
8774
- const moveToSourceRef = (0, import_react17.useRef)(moveToSource);
8939
+ const moveToSourceRef = (0, import_react18.useRef)(moveToSource);
8775
8940
  moveToSourceRef.current = moveToSource;
8776
- const toggleChecked = (0, import_react17.useCallback)((id) => {
8941
+ const toggleChecked = (0, import_react18.useCallback)((id) => {
8777
8942
  setCheckedIds((prev) => prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]);
8778
8943
  }, []);
8779
8944
  const allChecked = candidateIds.length > 0 && candidateIds.every((id) => checkedIds.includes(id));
8780
8945
  const someChecked = candidateIds.some((id) => checkedIds.includes(id));
8781
- const toggleAll = (0, import_react17.useCallback)(() => {
8946
+ const toggleAll = (0, import_react18.useCallback)(() => {
8782
8947
  setCheckedIds(allChecked ? [] : [...candidateIds]);
8783
8948
  }, [allChecked, candidateIds]);
8784
- const returnAll = (0, import_react17.useCallback)(() => {
8949
+ const returnAll = (0, import_react18.useCallback)(() => {
8785
8950
  setCandidateIds([]);
8786
8951
  setCheckedIds([]);
8787
8952
  }, []);
8788
- const checkedCandidates = (0, import_react17.useMemo)(() => candidateIds.filter((id) => checkedIds.includes(id)), [candidateIds, checkedIds]);
8953
+ const checkedCandidates = (0, import_react18.useMemo)(() => candidateIds.filter((id) => checkedIds.includes(id)), [candidateIds, checkedIds]);
8789
8954
  const isDirty = checkedCandidates.length !== assignedIds.length || checkedCandidates.some((id) => !assignedIds.includes(id));
8790
- const submitAssignment = (0, import_react17.useCallback)(async () => {
8955
+ const submitAssignment = (0, import_react18.useCallback)(async () => {
8791
8956
  if (!selectedTargetId) {
8792
8957
  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");
8793
8958
  return;
@@ -8803,14 +8968,14 @@ var PlacementBlock = (props) => {
8803
8968
  setIsSaving(false);
8804
8969
  }
8805
8970
  }, [selectedTargetId, persistAssignment, checkedCandidates]);
8806
- const cycleStatus = (0, import_react17.useCallback)((recordId) => {
8971
+ const cycleStatus = (0, import_react18.useCallback)((recordId) => {
8807
8972
  setStatusMap((prev) => {
8808
8973
  const current = prev[recordId] || defaultStatusId;
8809
8974
  const idx = statuses.findIndex((c) => c.id === current);
8810
8975
  return __spreadProps(__spreadValues({}, prev), { [recordId]: statuses[(idx + 1) % statuses.length].id });
8811
8976
  });
8812
8977
  }, [statuses, defaultStatusId]);
8813
- const cancelAssignment = (0, import_react17.useCallback)(async () => {
8978
+ const cancelAssignment = (0, import_react18.useCallback)(async () => {
8814
8979
  if (!selectedTargetId || assignedIds.length === 0) return;
8815
8980
  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;
8816
8981
  const removed = new Set(assignedIds);
@@ -8826,7 +8991,7 @@ var PlacementBlock = (props) => {
8826
8991
  setIsSaving(false);
8827
8992
  }
8828
8993
  }, [selectedTargetId, assignedIds, assignmentLabel, persistAssignment]);
8829
- const makeColDefs = (0, import_react17.useCallback)((columns, fallbackName, withCheckbox = false) => {
8994
+ const makeColDefs = (0, import_react18.useCallback)((columns, fallbackName, withCheckbox = false) => {
8830
8995
  const defs = [];
8831
8996
  if (withCheckbox) {
8832
8997
  defs.push({
@@ -8863,14 +9028,14 @@ var PlacementBlock = (props) => {
8863
9028
  return defs;
8864
9029
  }, [cycleStatus, statuses, defaultStatusId, displayField, displayValue, toggleChecked, toggleAll, allChecked, someChecked]);
8865
9030
  const sourceHeader = displayField === "name" ? "\u05E9\u05DD" : columnRefLabel(displayField);
8866
- const sourceColDefs = (0, import_react17.useMemo)(() => makeColDefs(sourceColumns, sourceHeader), [makeColDefs, sourceColumns, sourceHeader]);
8867
- const candidateColDefs = (0, import_react17.useMemo)(() => makeColDefs(sourceColumns, sourceHeader, true), [makeColDefs, sourceColumns, sourceHeader]);
8868
- const getRowId = (0, import_react17.useCallback)((p) => p.data.id, []);
8869
- const sourceContainerRef = (0, import_react17.useRef)(null);
8870
- const assignedContainerRef = (0, import_react17.useRef)(null);
8871
- const [sourceApi, setSourceApi] = (0, import_react17.useState)(null);
8872
- const [assignedApi, setAssignedApi] = (0, import_react17.useState)(null);
8873
- (0, import_react17.useEffect)(() => {
9031
+ const sourceColDefs = (0, import_react18.useMemo)(() => makeColDefs(sourceColumns, sourceHeader), [makeColDefs, sourceColumns, sourceHeader]);
9032
+ const candidateColDefs = (0, import_react18.useMemo)(() => makeColDefs(sourceColumns, sourceHeader, true), [makeColDefs, sourceColumns, sourceHeader]);
9033
+ const getRowId = (0, import_react18.useCallback)((p) => p.data.id, []);
9034
+ const sourceContainerRef = (0, import_react18.useRef)(null);
9035
+ const assignedContainerRef = (0, import_react18.useRef)(null);
9036
+ const [sourceApi, setSourceApi] = (0, import_react18.useState)(null);
9037
+ const [assignedApi, setAssignedApi] = (0, import_react18.useState)(null);
9038
+ (0, import_react18.useEffect)(() => {
8874
9039
  if (!sourceApi || !assignedApi) return;
8875
9040
  const toAssigned = { getContainer: () => assignedContainerRef.current, onDragStop: (p) => {
8876
9041
  var _a2, _b2;
@@ -8893,20 +9058,20 @@ var PlacementBlock = (props) => {
8893
9058
  }
8894
9059
  };
8895
9060
  }, [sourceApi, assignedApi]);
8896
- const selectorLabel = (0, import_react17.useMemo)(() => {
9061
+ const selectorLabel = (0, import_react18.useMemo)(() => {
8897
9062
  const col = targetColumns.find((c) => c.name === selectorField || c.id === selectorField);
8898
9063
  return (col == null ? void 0 : col.label) || columnRefLabel(selectorField) || "\u05D1\u05D7\u05D9\u05E8\u05EA \u05E8\u05E9\u05D5\u05DE\u05D4 \u05DC\u05E9\u05D9\u05D1\u05D5\u05E5";
8899
9064
  }, [targetColumns, selectorField]);
8900
- const assignedText = (0, import_react17.useMemo)(
9065
+ const assignedText = (0, import_react18.useMemo)(
8901
9066
  () => assignedIds.map((id) => sourceRows.find((r) => r.id === id)).filter((r) => !!r).map(nameOf).join(", "),
8902
9067
  [assignedIds, sourceRows, nameOf]
8903
9068
  );
8904
9069
  const activeTarget = targetRows.find((r) => r.id === selectedTargetId);
8905
- const targetLabel = (0, import_react17.useCallback)((r) => {
9070
+ const targetLabel = (0, import_react18.useCallback)((r) => {
8906
9071
  const col = targetColumns.find((c) => c.name === selectorField || c.id === selectorField);
8907
9072
  return displayValue(col || { name: selectorField }, readColumnValue(r.data, selectorField)) || "\u05DC\u05DC\u05D0 \u05E9\u05DD";
8908
9073
  }, [selectorField, targetColumns, displayValue]);
8909
- const previewColumns = (0, import_react17.useMemo)(() => targetColumns.filter((c) => isUserColumn(c) && c.name !== assignmentField && !["id", "_id", "id_", "statusId"].includes(c.name)), [targetColumns, assignmentField]);
9074
+ const previewColumns = (0, import_react18.useMemo)(() => targetColumns.filter((c) => isUserColumn(c) && c.name !== assignmentField && !["id", "_id", "id_", "statusId"].includes(c.name)), [targetColumns, assignmentField]);
8910
9075
  if (!config || !sourceTableId || !targetTableId) {
8911
9076
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "p-4 text-xs text-slate-500 border border-dashed border-slate-300 rounded-xl", dir: "rtl", children: "\u05E8\u05DB\u05D9\u05D1 \u05D4\u05E9\u05D9\u05D1\u05D5\u05E5 \u05DC\u05D0 \u05D4\u05D5\u05D2\u05D3\u05E8 (\u05D7\u05E1\u05E8\u05D5\u05EA \u05D8\u05D1\u05DC\u05EA \u05DE\u05E7\u05D5\u05E8 / \u05D8\u05D1\u05DC\u05EA \u05D9\u05E2\u05D3)." });
8912
9077
  }
@@ -8922,15 +9087,15 @@ var PlacementBlock = (props) => {
8922
9087
  ] }),
8923
9088
  activeTarget ? /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "space-y-2 text-xs text-slate-700 overflow-y-auto pr-1 max-h-32", children: [
8924
9089
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "font-bold text-slate-900 text-sm mb-1", children: targetLabel(activeTarget) }),
8925
- previewColumns.map((col) => ({ col, text: displayValue(col, readColumnValue(activeTarget.data, col.name)) })).filter(({ col, text }) => {
9090
+ previewColumns.map((col) => ({ col, text: displayValue(col, readColumnValue(activeTarget.data, col.name)) })).filter(({ col, text: text2 }) => {
8926
9091
  var _a2;
8927
- return text && (col.type === "RELATION" || typeof ((_a2 = activeTarget.data) == null ? void 0 : _a2[col.name]) !== "object");
8928
- }).map(({ col, text }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex gap-2 items-start", children: [
9092
+ return text2 && (col.type === "RELATION" || typeof ((_a2 = activeTarget.data) == null ? void 0 : _a2[col.name]) !== "object");
9093
+ }).map(({ col, text: text2 }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex gap-2 items-start", children: [
8929
9094
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "font-semibold shrink-0", children: [
8930
9095
  col.label || col.name,
8931
9096
  ":"
8932
9097
  ] }),
8933
- /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "break-words line-clamp-2", children: text })
9098
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "break-words line-clamp-2", children: text2 })
8934
9099
  ] }, col.name)),
8935
9100
  assignmentField && assignedText && /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex gap-2 items-start", children: [
8936
9101
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("span", { className: "font-semibold shrink-0", children: [
@@ -9040,11 +9205,11 @@ var PlacementBlock = (props) => {
9040
9205
  };
9041
9206
 
9042
9207
  // src/components/WhatsAppComponent/WhatsAppComponent.tsx
9043
- var import_react23 = __toESM(require("react"));
9208
+ var import_react24 = __toESM(require("react"));
9044
9209
  var import_lucide_react16 = require("lucide-react");
9045
9210
 
9046
9211
  // src/components/WhatsAppComponent/CreateTemplateModal.tsx
9047
- var import_react18 = require("react");
9212
+ var import_react19 = require("react");
9048
9213
  var import_lucide_react10 = require("lucide-react");
9049
9214
  var import_emoji_picker_react = __toESM(require("emoji-picker-react"));
9050
9215
 
@@ -9174,26 +9339,26 @@ function CreateTemplateModal({
9174
9339
  executeAction,
9175
9340
  orgId
9176
9341
  }) {
9177
- const [templateName, setTemplateName] = (0, import_react18.useState)("");
9178
- const [language, setLanguage] = (0, import_react18.useState)("he");
9179
- const [category, setCategory] = (0, import_react18.useState)("MARKETING");
9180
- const [bodyText, setBodyText] = (0, import_react18.useState)("");
9181
- const [variableSamples, setVariableSamples] = (0, import_react18.useState)({});
9182
- const [hasFileHeader, setHasFileHeader] = (0, import_react18.useState)(false);
9183
- const [selectedFile, setSelectedFile] = (0, import_react18.useState)(null);
9184
- const [fileBase64, setFileBase64] = (0, import_react18.useState)("");
9185
- const [buttons, setButtons] = (0, import_react18.useState)([]);
9186
- const [isAddButtonOpen, setIsAddButtonOpen] = (0, import_react18.useState)(false);
9187
- const addButtonDropdownRef = (0, import_react18.useRef)(null);
9188
- const [isSubmitting, setIsSubmitting] = (0, import_react18.useState)(false);
9189
- const [submittingStep, setSubmittingStep] = (0, import_react18.useState)("");
9190
- const [submitError, setSubmitError] = (0, import_react18.useState)(null);
9191
- const [fileError, setFileError] = (0, import_react18.useState)(null);
9192
- const textareaRef = (0, import_react18.useRef)(null);
9193
- const fileInputRef = (0, import_react18.useRef)(null);
9194
- const emojiPickerRef = (0, import_react18.useRef)(null);
9195
- const [isEmojiPickerOpen, setIsEmojiPickerOpen] = (0, import_react18.useState)(false);
9196
- (0, import_react18.useEffect)(() => {
9342
+ const [templateName, setTemplateName] = (0, import_react19.useState)("");
9343
+ const [language, setLanguage] = (0, import_react19.useState)("he");
9344
+ const [category, setCategory] = (0, import_react19.useState)("MARKETING");
9345
+ const [bodyText, setBodyText] = (0, import_react19.useState)("");
9346
+ const [variableSamples, setVariableSamples] = (0, import_react19.useState)({});
9347
+ const [hasFileHeader, setHasFileHeader] = (0, import_react19.useState)(false);
9348
+ const [selectedFile, setSelectedFile] = (0, import_react19.useState)(null);
9349
+ const [fileBase64, setFileBase64] = (0, import_react19.useState)("");
9350
+ const [buttons, setButtons] = (0, import_react19.useState)([]);
9351
+ const [isAddButtonOpen, setIsAddButtonOpen] = (0, import_react19.useState)(false);
9352
+ const addButtonDropdownRef = (0, import_react19.useRef)(null);
9353
+ const [isSubmitting, setIsSubmitting] = (0, import_react19.useState)(false);
9354
+ const [submittingStep, setSubmittingStep] = (0, import_react19.useState)("");
9355
+ const [submitError, setSubmitError] = (0, import_react19.useState)(null);
9356
+ const [fileError, setFileError] = (0, import_react19.useState)(null);
9357
+ const textareaRef = (0, import_react19.useRef)(null);
9358
+ const fileInputRef = (0, import_react19.useRef)(null);
9359
+ const emojiPickerRef = (0, import_react19.useRef)(null);
9360
+ const [isEmojiPickerOpen, setIsEmojiPickerOpen] = (0, import_react19.useState)(false);
9361
+ (0, import_react19.useEffect)(() => {
9197
9362
  function handleClickOutside(event) {
9198
9363
  if (emojiPickerRef.current && !emojiPickerRef.current.contains(event.target)) {
9199
9364
  setIsEmojiPickerOpen(false);
@@ -9217,7 +9382,7 @@ function CreateTemplateModal({
9217
9382
  document.removeEventListener("keydown", handleKeyDown2);
9218
9383
  };
9219
9384
  }, [isEmojiPickerOpen, isAddButtonOpen]);
9220
- (0, import_react18.useEffect)(() => {
9385
+ (0, import_react19.useEffect)(() => {
9221
9386
  if (isOpen) {
9222
9387
  setTemplateName("");
9223
9388
  setLanguage("he");
@@ -9236,10 +9401,10 @@ function CreateTemplateModal({
9236
9401
  setIsEmojiPickerOpen(false);
9237
9402
  }
9238
9403
  }, [isOpen]);
9239
- const uniqueVariables = (0, import_react18.useMemo)(() => {
9404
+ const uniqueVariables = (0, import_react19.useMemo)(() => {
9240
9405
  return extractUniqueVariableIndices(bodyText);
9241
9406
  }, [bodyText]);
9242
- (0, import_react18.useEffect)(() => {
9407
+ (0, import_react19.useEffect)(() => {
9243
9408
  setVariableSamples((prev) => {
9244
9409
  const next = {};
9245
9410
  uniqueVariables.forEach((idx) => {
@@ -9250,7 +9415,7 @@ function CreateTemplateModal({
9250
9415
  }, [uniqueVariables]);
9251
9416
  const isNameEmpty = templateName.trim().length === 0;
9252
9417
  const isNamePatternValid = isValidTemplateName(templateName);
9253
- const isNameDuplicate = (0, import_react18.useMemo)(() => {
9418
+ const isNameDuplicate = (0, import_react19.useMemo)(() => {
9254
9419
  const trimmedName = templateName.trim().toLowerCase();
9255
9420
  if (!trimmedName) return false;
9256
9421
  if (existingTemplates && existingTemplates.length > 0) {
@@ -9260,9 +9425,9 @@ function CreateTemplateModal({
9260
9425
  }
9261
9426
  return isDuplicateTemplateName(trimmedName, existingTemplateNames, language);
9262
9427
  }, [templateName, language, existingTemplates, existingTemplateNames]);
9263
- const ratioInfo = (0, import_react18.useMemo)(() => validateWordToVariableRatio(bodyText), [bodyText]);
9264
- const seqInfo = (0, import_react18.useMemo)(() => validateSequentialVariables(bodyText), [bodyText]);
9265
- const validationResult = (0, import_react18.useMemo)(() => {
9428
+ const ratioInfo = (0, import_react19.useMemo)(() => validateWordToVariableRatio(bodyText), [bodyText]);
9429
+ const seqInfo = (0, import_react19.useMemo)(() => validateSequentialVariables(bodyText), [bodyText]);
9430
+ const validationResult = (0, import_react19.useMemo)(() => {
9266
9431
  return validateWhatsAppTemplate({
9267
9432
  name: templateName,
9268
9433
  language,
@@ -10256,7 +10421,7 @@ function CreateTemplateModal({
10256
10421
  }
10257
10422
 
10258
10423
  // src/components/WhatsAppComponent/hooks/useWhatsAppState.ts
10259
- var import_react19 = require("react");
10424
+ var import_react20 = require("react");
10260
10425
 
10261
10426
  // src/components/WhatsAppComponent/utils/recipientEngine.ts
10262
10427
  var STORAGE_KEY_TEST_PHONE = "whatsapp_test_phone";
@@ -11561,29 +11726,29 @@ function useWhatsAppState(props) {
11561
11726
  data: injectedData
11562
11727
  } = props;
11563
11728
  const orgId = props.orgId || props.organizationId || (settings == null ? void 0 : settings.orgId) || (settings == null ? void 0 : settings.organizationId) || (injectedData == null ? void 0 : injectedData.orgId) || (injectedData == null ? void 0 : injectedData.organizationId);
11564
- const [tableColumns2, setTableColumns] = (0, import_react19.useState)(() => {
11729
+ const [tableColumns2, setTableColumns] = (0, import_react20.useState)(() => {
11565
11730
  return Array.isArray(settings == null ? void 0 : settings.columns) ? settings.columns : [];
11566
11731
  });
11567
- const [rawRecords, setRawRecords] = (0, import_react19.useState)(() => {
11732
+ const [rawRecords, setRawRecords] = (0, import_react20.useState)(() => {
11568
11733
  if (Array.isArray(injectedData)) return injectedData;
11569
11734
  if (Array.isArray(injectedData == null ? void 0 : injectedData.records)) return injectedData.records;
11570
11735
  return [];
11571
11736
  });
11572
- const [relationOptions, setRelationOptions] = (0, import_react19.useState)(() => {
11737
+ const [relationOptions, setRelationOptions] = (0, import_react20.useState)(() => {
11573
11738
  return (injectedData == null ? void 0 : injectedData.relationOptions) || {};
11574
11739
  });
11575
- const [isLoadingTableData, setIsLoadingTableData] = (0, import_react19.useState)(() => Boolean(settings == null ? void 0 : settings.tableMetaId));
11576
- const [activeSubtableScans, setActiveSubtableScans] = (0, import_react19.useState)(0);
11577
- const [tableError, setTableError] = (0, import_react19.useState)(null);
11578
- const [filters, setFilters] = (0, import_react19.useState)({});
11579
- const [selectedRowIds, setSelectedRowIds] = (0, import_react19.useState)([]);
11580
- const [autoSelectCount, setAutoSelectCount] = (0, import_react19.useState)(null);
11581
- const isAutoSelectingRef = (0, import_react19.useRef)(false);
11582
- const isManualOverrideRef = (0, import_react19.useRef)(false);
11583
- const prevAutoSelectCountRef = (0, import_react19.useRef)(null);
11584
- const fetchedTableIdsRef = (0, import_react19.useRef)(/* @__PURE__ */ new Set());
11585
- const fullyFetchedRelationKeysRef = (0, import_react19.useRef)(/* @__PURE__ */ new Set());
11586
- const loadTableData = (0, import_react19.useCallback)(async () => {
11740
+ const [isLoadingTableData, setIsLoadingTableData] = (0, import_react20.useState)(() => Boolean(settings == null ? void 0 : settings.tableMetaId));
11741
+ const [activeSubtableScans, setActiveSubtableScans] = (0, import_react20.useState)(0);
11742
+ const [tableError, setTableError] = (0, import_react20.useState)(null);
11743
+ const [filters, setFilters] = (0, import_react20.useState)({});
11744
+ const [selectedRowIds, setSelectedRowIds] = (0, import_react20.useState)([]);
11745
+ const [autoSelectCount, setAutoSelectCount] = (0, import_react20.useState)(null);
11746
+ const isAutoSelectingRef = (0, import_react20.useRef)(false);
11747
+ const isManualOverrideRef = (0, import_react20.useRef)(false);
11748
+ const prevAutoSelectCountRef = (0, import_react20.useRef)(null);
11749
+ const fetchedTableIdsRef = (0, import_react20.useRef)(/* @__PURE__ */ new Set());
11750
+ const fullyFetchedRelationKeysRef = (0, import_react20.useRef)(/* @__PURE__ */ new Set());
11751
+ const loadTableData = (0, import_react20.useCallback)(async () => {
11587
11752
  var _a2;
11588
11753
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableId);
11589
11754
  if (!tableId || !executeAction) return;
@@ -11650,10 +11815,10 @@ function useWhatsAppState(props) {
11650
11815
  executeAction,
11651
11816
  orgId
11652
11817
  ]);
11653
- (0, import_react19.useEffect)(() => {
11818
+ (0, import_react20.useEffect)(() => {
11654
11819
  loadTableData();
11655
11820
  }, [loadTableData]);
11656
- const filterableColumns = (0, import_react19.useMemo)(() => {
11821
+ const filterableColumns = (0, import_react20.useMemo)(() => {
11657
11822
  return (tableColumns2 || []).filter((col) => {
11658
11823
  var _a2;
11659
11824
  if (!col || col.name === "_id" || col.id === "_id") return false;
@@ -11661,15 +11826,15 @@ function useWhatsAppState(props) {
11661
11826
  return type === "RELATION" || type === "BOOLEAN";
11662
11827
  });
11663
11828
  }, [tableColumns2]);
11664
- const [referencedTableSchemas, setReferencedTableSchemas] = (0, import_react19.useState)({});
11665
- const subtableCols = (0, import_react19.useMemo)(() => {
11829
+ const [referencedTableSchemas, setReferencedTableSchemas] = (0, import_react20.useState)({});
11830
+ const subtableCols = (0, import_react20.useMemo)(() => {
11666
11831
  return (tableColumns2 || []).filter((col) => {
11667
11832
  var _a2;
11668
11833
  const type = (_a2 = col.type) == null ? void 0 : _a2.toUpperCase();
11669
11834
  return type === "RELATION" || type === "SUB_TABLE" || type === "SUBTABLE";
11670
11835
  });
11671
11836
  }, [tableColumns2]);
11672
- (0, import_react19.useEffect)(() => {
11837
+ (0, import_react20.useEffect)(() => {
11673
11838
  if (!executeAction) return;
11674
11839
  const unrequestedCols = subtableCols.filter((col) => {
11675
11840
  var _a2;
@@ -11715,20 +11880,20 @@ function useWhatsAppState(props) {
11715
11880
  const isScanningPhoneColumns = Boolean(
11716
11881
  isLoadingTableData || activeSubtableScans > 0 || tableColumns2.length === 0 && Boolean(settings == null ? void 0 : settings.tableMetaId)
11717
11882
  );
11718
- const targetPhoneOptions = (0, import_react19.useMemo)(() => {
11883
+ const targetPhoneOptions = (0, import_react20.useMemo)(() => {
11719
11884
  const cols = tableColumns2 && tableColumns2.length > 0 ? tableColumns2 : Array.isArray(settings == null ? void 0 : settings.columns) ? settings.columns : [];
11720
11885
  return scanTargetPhoneOptions(cols, referencedTableSchemas);
11721
11886
  }, [tableColumns2, settings == null ? void 0 : settings.columns, referencedTableSchemas]);
11722
- const phoneColumns = (0, import_react19.useMemo)(() => {
11887
+ const phoneColumns = (0, import_react20.useMemo)(() => {
11723
11888
  return targetPhoneOptions.map((opt) => ({ name: opt.label, id: opt.id, type: "PHONE" }));
11724
11889
  }, [targetPhoneOptions]);
11725
- const [phoneColumnId, setPhoneColumnId] = (0, import_react19.useState)("");
11726
- const [subtableFilterColumn, setSubtableFilterColumn] = (0, import_react19.useState)("");
11727
- const [subtableFilterValue, setSubtableFilterValue] = (0, import_react19.useState)("");
11728
- const [subtableSendLimit, setSubtableSendLimit] = (0, import_react19.useState)(
11890
+ const [phoneColumnId, setPhoneColumnId] = (0, import_react20.useState)("");
11891
+ const [subtableFilterColumn, setSubtableFilterColumn] = (0, import_react20.useState)("");
11892
+ const [subtableFilterValue, setSubtableFilterValue] = (0, import_react20.useState)("");
11893
+ const [subtableSendLimit, setSubtableSendLimit] = (0, import_react20.useState)(
11729
11894
  (settings == null ? void 0 : settings.subtableSendLimit) || "PRIMARY"
11730
11895
  );
11731
- (0, import_react19.useEffect)(() => {
11896
+ (0, import_react20.useEffect)(() => {
11732
11897
  if (targetPhoneOptions.length > 0) {
11733
11898
  const isValid = targetPhoneOptions.some(
11734
11899
  (opt) => opt.id === phoneColumnId || opt.columnName === phoneColumnId
@@ -11740,13 +11905,13 @@ function useWhatsAppState(props) {
11740
11905
  setPhoneColumnId("");
11741
11906
  }
11742
11907
  }, [targetPhoneOptions, phoneColumnId]);
11743
- const selectedPhoneOption = (0, import_react19.useMemo)(() => {
11908
+ const selectedPhoneOption = (0, import_react20.useMemo)(() => {
11744
11909
  if (!phoneColumnId) return targetPhoneOptions[0] || null;
11745
11910
  return targetPhoneOptions.find(
11746
11911
  (opt) => opt.id === phoneColumnId || opt.columnName === phoneColumnId
11747
11912
  ) || targetPhoneOptions[0] || null;
11748
11913
  }, [targetPhoneOptions, phoneColumnId]);
11749
- const subtableFilterableColumns = (0, import_react19.useMemo)(() => {
11914
+ const subtableFilterableColumns = (0, import_react20.useMemo)(() => {
11750
11915
  var _a2, _b2, _c;
11751
11916
  if (!selectedPhoneOption || selectedPhoneOption.type !== "SUBTABLE") {
11752
11917
  return [];
@@ -11765,14 +11930,14 @@ function useWhatsAppState(props) {
11765
11930
  return type === "BOOLEAN" || type === "RELATION";
11766
11931
  });
11767
11932
  }, [selectedPhoneOption, referencedTableSchemas, tableColumns2]);
11768
- const selectedSubtableFilterCol = (0, import_react19.useMemo)(() => {
11933
+ const selectedSubtableFilterCol = (0, import_react20.useMemo)(() => {
11769
11934
  return subtableFilterableColumns.find((c) => c.name === subtableFilterColumn);
11770
11935
  }, [subtableFilterableColumns, subtableFilterColumn]);
11771
- const [enablePostSendAction, setEnablePostSendAction] = (0, import_react19.useState)(false);
11772
- const [postSendActionColumn, setPostSendActionColumn] = (0, import_react19.useState)("");
11773
- const [postSendActionValue, setPostSendActionValue] = (0, import_react19.useState)("");
11774
- const [postSendActionTargetType, setPostSendActionTargetType] = (0, import_react19.useState)("MAIN");
11775
- const postSendActionTargetOptions = (0, import_react19.useMemo)(() => {
11936
+ const [enablePostSendAction, setEnablePostSendAction] = (0, import_react20.useState)(false);
11937
+ const [postSendActionColumn, setPostSendActionColumn] = (0, import_react20.useState)("");
11938
+ const [postSendActionValue, setPostSendActionValue] = (0, import_react20.useState)("");
11939
+ const [postSendActionTargetType, setPostSendActionTargetType] = (0, import_react20.useState)("MAIN");
11940
+ const postSendActionTargetOptions = (0, import_react20.useMemo)(() => {
11776
11941
  var _a2, _b2, _c;
11777
11942
  const options = [];
11778
11943
  (tableColumns2 || []).forEach((col) => {
@@ -11817,14 +11982,14 @@ function useWhatsAppState(props) {
11817
11982
  }
11818
11983
  return options;
11819
11984
  }, [tableColumns2, selectedPhoneOption, referencedTableSchemas]);
11820
- const selectedPostSendOption = (0, import_react19.useMemo)(() => {
11985
+ const selectedPostSendOption = (0, import_react20.useMemo)(() => {
11821
11986
  return postSendActionTargetOptions.find(
11822
11987
  (opt) => opt.id === postSendActionColumn || opt.columnName === postSendActionColumn
11823
11988
  );
11824
11989
  }, [postSendActionTargetOptions, postSendActionColumn]);
11825
11990
  const selectedPostSendCol = selectedPostSendOption;
11826
- const [isTestPromptOpen, setIsTestPromptOpen] = (0, import_react19.useState)(false);
11827
- const [testPhoneNumber, setTestPhoneNumber] = (0, import_react19.useState)(() => {
11991
+ const [isTestPromptOpen, setIsTestPromptOpen] = (0, import_react20.useState)(false);
11992
+ const [testPhoneNumber, setTestPhoneNumber] = (0, import_react20.useState)(() => {
11828
11993
  if (typeof window !== "undefined") {
11829
11994
  try {
11830
11995
  return localStorage.getItem(STORAGE_KEY_TEST_PHONE) || "";
@@ -11834,10 +11999,10 @@ function useWhatsAppState(props) {
11834
11999
  }
11835
12000
  return "";
11836
12001
  });
11837
- const [testFeedback, setTestFeedback] = (0, import_react19.useState)(null);
11838
- const [isSendingTest, setIsSendingTest] = (0, import_react19.useState)(false);
11839
- const [isSendingBroadcast, setIsSendingBroadcast] = (0, import_react19.useState)(false);
11840
- const [broadcastProgress, setBroadcastProgress] = (0, import_react19.useState)({
12002
+ const [testFeedback, setTestFeedback] = (0, import_react20.useState)(null);
12003
+ const [isSendingTest, setIsSendingTest] = (0, import_react20.useState)(false);
12004
+ const [isSendingBroadcast, setIsSendingBroadcast] = (0, import_react20.useState)(false);
12005
+ const [broadcastProgress, setBroadcastProgress] = (0, import_react20.useState)({
11841
12006
  current: 0,
11842
12007
  total: 0,
11843
12008
  successful: 0,
@@ -11845,12 +12010,12 @@ function useWhatsAppState(props) {
11845
12010
  skipped: 0,
11846
12011
  percent: 0
11847
12012
  });
11848
- const [broadcastSummary, setBroadcastSummary] = (0, import_react19.useState)(null);
11849
- const [rowStatusMap, setRowStatusMap] = (0, import_react19.useState)({});
11850
- const clearBroadcastSummary = (0, import_react19.useCallback)(() => {
12013
+ const [broadcastSummary, setBroadcastSummary] = (0, import_react20.useState)(null);
12014
+ const [rowStatusMap, setRowStatusMap] = (0, import_react20.useState)({});
12015
+ const clearBroadcastSummary = (0, import_react20.useCallback)(() => {
11851
12016
  setBroadcastSummary(null);
11852
12017
  }, []);
11853
- const handleTestPhoneChange = (0, import_react19.useCallback)((val) => {
12018
+ const handleTestPhoneChange = (0, import_react20.useCallback)((val) => {
11854
12019
  setTestPhoneNumber(val);
11855
12020
  if (typeof window !== "undefined") {
11856
12021
  try {
@@ -11860,7 +12025,7 @@ function useWhatsAppState(props) {
11860
12025
  }
11861
12026
  }
11862
12027
  }, []);
11863
- const getRelationOptionsForCol = (0, import_react19.useCallback)(
12028
+ const getRelationOptionsForCol = (0, import_react20.useCallback)(
11864
12029
  (colName, parentColName) => {
11865
12030
  var _a2, _b2, _c, _d;
11866
12031
  if (parentColName) {
@@ -11903,7 +12068,7 @@ function useWhatsAppState(props) {
11903
12068
  },
11904
12069
  [relationOptions, subtableFilterableColumns, postSendActionTargetOptions, tableColumns2, filterableColumns]
11905
12070
  );
11906
- (0, import_react19.useEffect)(() => {
12071
+ (0, import_react20.useEffect)(() => {
11907
12072
  var _a2, _b2, _c, _d, _e;
11908
12073
  if (!executeAction) return;
11909
12074
  const targets = [];
@@ -11997,7 +12162,7 @@ function useWhatsAppState(props) {
11997
12162
  }
11998
12163
  });
11999
12164
  }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns2, executeAction, selectedPostSendOption, orgId]);
12000
- (0, import_react19.useEffect)(() => {
12165
+ (0, import_react20.useEffect)(() => {
12001
12166
  var _a2, _b2, _c;
12002
12167
  if (!executeAction || !selectedSubtableFilterCol) return;
12003
12168
  if (((_a2 = selectedSubtableFilterCol.type) == null ? void 0 : _a2.toUpperCase()) !== "RELATION") return;
@@ -12048,7 +12213,7 @@ function useWhatsAppState(props) {
12048
12213
  }
12049
12214
  })();
12050
12215
  }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, orgId]);
12051
- (0, import_react19.useEffect)(() => {
12216
+ (0, import_react20.useEffect)(() => {
12052
12217
  var _a2, _b2;
12053
12218
  if (!executeAction || !selectedPostSendOption) return;
12054
12219
  if (selectedPostSendOption.type !== "RELATION") return;
@@ -12101,7 +12266,7 @@ function useWhatsAppState(props) {
12101
12266
  }
12102
12267
  })();
12103
12268
  }, [selectedPostSendOption, executeAction, orgId]);
12104
- const filteredRecords = (0, import_react19.useMemo)(() => {
12269
+ const filteredRecords = (0, import_react20.useMemo)(() => {
12105
12270
  const activeEntries = Object.entries(filters).filter(
12106
12271
  ([_, val]) => val !== void 0 && val !== null && val !== ""
12107
12272
  );
@@ -12133,7 +12298,7 @@ function useWhatsAppState(props) {
12133
12298
  });
12134
12299
  }, [rawRecords, filters, filterableColumns]);
12135
12300
  const filteredData = filteredRecords;
12136
- (0, import_react19.useEffect)(() => {
12301
+ (0, import_react20.useEffect)(() => {
12137
12302
  if (autoSelectCount !== null && autoSelectCount > 0) {
12138
12303
  isAutoSelectingRef.current = true;
12139
12304
  const sliced = filteredData.slice(0, autoSelectCount);
@@ -12151,7 +12316,7 @@ function useWhatsAppState(props) {
12151
12316
  isManualOverrideRef.current = false;
12152
12317
  prevAutoSelectCountRef.current = autoSelectCount;
12153
12318
  }, [autoSelectCount, filteredData]);
12154
- const embeddedTableExecuteAction = (0, import_react19.useCallback)(async (actionType, payload) => {
12319
+ const embeddedTableExecuteAction = (0, import_react20.useCallback)(async (actionType, payload) => {
12155
12320
  if (actionType === "FETCH_TABLE_DATA") {
12156
12321
  const colFilters = (payload == null ? void 0 : payload.columnFilters) || (payload == null ? void 0 : payload.filters);
12157
12322
  const searchQuery = payload == null ? void 0 : payload.search;
@@ -12194,10 +12359,10 @@ function useWhatsAppState(props) {
12194
12359
  const handleClearFilters = () => {
12195
12360
  setFilters({});
12196
12361
  };
12197
- const activeFiltersCount = (0, import_react19.useMemo)(() => {
12362
+ const activeFiltersCount = (0, import_react20.useMemo)(() => {
12198
12363
  return Object.values(filters).filter((v) => v !== "").length;
12199
12364
  }, [filters]);
12200
- const handleSelectionChange = (0, import_react19.useCallback)((selectedIds) => {
12365
+ const handleSelectionChange = (0, import_react20.useCallback)((selectedIds) => {
12201
12366
  setSelectedRowIds((prev) => {
12202
12367
  if (prev.length === selectedIds.length && prev.every((id, idx) => id === selectedIds[idx])) {
12203
12368
  return prev;
@@ -12211,13 +12376,13 @@ function useWhatsAppState(props) {
12211
12376
  return selectedIds;
12212
12377
  });
12213
12378
  }, [autoSelectCount]);
12214
- const handleRowToggle = (0, import_react19.useCallback)((rowId, checked) => {
12379
+ const handleRowToggle = (0, import_react20.useCallback)((rowId, checked) => {
12215
12380
  if (autoSelectCount !== null && autoSelectCount > 0) {
12216
12381
  isManualOverrideRef.current = true;
12217
12382
  setAutoSelectCount(null);
12218
12383
  }
12219
12384
  }, [autoSelectCount]);
12220
- const toggleRowSelection = (0, import_react19.useCallback)((rowId, checked) => {
12385
+ const toggleRowSelection = (0, import_react20.useCallback)((rowId, checked) => {
12221
12386
  if (autoSelectCount !== null && autoSelectCount > 0) {
12222
12387
  isManualOverrideRef.current = true;
12223
12388
  setAutoSelectCount(null);
@@ -12233,15 +12398,15 @@ function useWhatsAppState(props) {
12233
12398
  return prev;
12234
12399
  });
12235
12400
  }, [autoSelectCount]);
12236
- const [templates, setTemplates] = (0, import_react19.useState)([]);
12237
- const [selectedTemplateId, setSelectedTemplateId] = (0, import_react19.useState)(null);
12238
- const [isLoading, setIsLoading] = (0, import_react19.useState)(true);
12239
- const [fetchError, setFetchError] = (0, import_react19.useState)(null);
12240
- const [isModalOpen, setIsModalOpen] = (0, import_react19.useState)(false);
12241
- const [isDropdownOpen, setIsDropdownOpen] = (0, import_react19.useState)(false);
12242
- const [isDeleting, setIsDeleting] = (0, import_react19.useState)(false);
12243
- const [feedback, setFeedback] = (0, import_react19.useState)(null);
12244
- const loadTemplates = (0, import_react19.useCallback)(async () => {
12401
+ const [templates, setTemplates] = (0, import_react20.useState)([]);
12402
+ const [selectedTemplateId, setSelectedTemplateId] = (0, import_react20.useState)(null);
12403
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(true);
12404
+ const [fetchError, setFetchError] = (0, import_react20.useState)(null);
12405
+ const [isModalOpen, setIsModalOpen] = (0, import_react20.useState)(false);
12406
+ const [isDropdownOpen, setIsDropdownOpen] = (0, import_react20.useState)(false);
12407
+ const [isDeleting, setIsDeleting] = (0, import_react20.useState)(false);
12408
+ const [feedback, setFeedback] = (0, import_react20.useState)(null);
12409
+ const loadTemplates = (0, import_react20.useCallback)(async () => {
12245
12410
  var _a2, _b2;
12246
12411
  if (!executeAction) {
12247
12412
  setIsLoading(false);
@@ -12293,13 +12458,13 @@ function useWhatsAppState(props) {
12293
12458
  setIsLoading(false);
12294
12459
  }
12295
12460
  }, [executeAction, orgId]);
12296
- (0, import_react19.useEffect)(() => {
12461
+ (0, import_react20.useEffect)(() => {
12297
12462
  loadTemplates();
12298
12463
  }, [loadTemplates]);
12299
- const selectedTemplate = (0, import_react19.useMemo)(() => {
12464
+ const selectedTemplate = (0, import_react20.useMemo)(() => {
12300
12465
  return templates.find((t) => t.id === selectedTemplateId) || null;
12301
12466
  }, [templates, selectedTemplateId]);
12302
- const templateBodyText = (0, import_react19.useMemo)(() => {
12467
+ const templateBodyText = (0, import_react20.useMemo)(() => {
12303
12468
  if (!(selectedTemplate == null ? void 0 : selectedTemplate.components)) return "";
12304
12469
  const bodyComp = selectedTemplate.components.find(
12305
12470
  (c) => {
@@ -12309,7 +12474,7 @@ function useWhatsAppState(props) {
12309
12474
  );
12310
12475
  return (bodyComp == null ? void 0 : bodyComp.text) || "";
12311
12476
  }, [selectedTemplate]);
12312
- const templateHeaderComp = (0, import_react19.useMemo)(() => {
12477
+ const templateHeaderComp = (0, import_react20.useMemo)(() => {
12313
12478
  if (!(selectedTemplate == null ? void 0 : selectedTemplate.components)) return null;
12314
12479
  return selectedTemplate.components.find(
12315
12480
  (c) => {
@@ -12318,8 +12483,8 @@ function useWhatsAppState(props) {
12318
12483
  }
12319
12484
  ) || null;
12320
12485
  }, [selectedTemplate]);
12321
- const [headerMediaUrl, setHeaderMediaUrl] = (0, import_react19.useState)("");
12322
- (0, import_react19.useEffect)(() => {
12486
+ const [headerMediaUrl, setHeaderMediaUrl] = (0, import_react20.useState)("");
12487
+ (0, import_react20.useEffect)(() => {
12323
12488
  if (!templateHeaderComp) {
12324
12489
  setHeaderMediaUrl("");
12325
12490
  return;
@@ -12336,7 +12501,7 @@ function useWhatsAppState(props) {
12336
12501
  setHeaderMediaUrl("");
12337
12502
  }
12338
12503
  }, [templateHeaderComp, selectedTemplate == null ? void 0 : selectedTemplate.name]);
12339
- const handleHeaderMediaUrlChange = (0, import_react19.useCallback)(
12504
+ const handleHeaderMediaUrlChange = (0, import_react20.useCallback)(
12340
12505
  (newUrl) => {
12341
12506
  setHeaderMediaUrl(newUrl);
12342
12507
  if ((selectedTemplate == null ? void 0 : selectedTemplate.name) && typeof window !== "undefined") {
@@ -12355,7 +12520,7 @@ function useWhatsAppState(props) {
12355
12520
  },
12356
12521
  [selectedTemplate == null ? void 0 : selectedTemplate.name]
12357
12522
  );
12358
- const handleResetHeaderMediaUrl = (0, import_react19.useCallback)(() => {
12523
+ const handleResetHeaderMediaUrl = (0, import_react20.useCallback)(() => {
12359
12524
  if ((selectedTemplate == null ? void 0 : selectedTemplate.name) && typeof window !== "undefined") {
12360
12525
  try {
12361
12526
  localStorage.removeItem(`whatsapp_template_media_${selectedTemplate.name}`);
@@ -12369,8 +12534,8 @@ function useWhatsAppState(props) {
12369
12534
  );
12370
12535
  setHeaderMediaUrl(defaultUrl || "");
12371
12536
  }, [templateHeaderComp, selectedTemplate == null ? void 0 : selectedTemplate.name]);
12372
- const [isUploadingMedia, setIsUploadingMedia] = (0, import_react19.useState)(false);
12373
- const handleFileUpload = (0, import_react19.useCallback)(
12537
+ const [isUploadingMedia, setIsUploadingMedia] = (0, import_react20.useState)(false);
12538
+ const handleFileUpload = (0, import_react20.useCallback)(
12374
12539
  async (file, templateName) => {
12375
12540
  const tplName = templateName || (selectedTemplate == null ? void 0 : selectedTemplate.name) || "";
12376
12541
  if (!file) return;
@@ -12411,14 +12576,14 @@ function useWhatsAppState(props) {
12411
12576
  },
12412
12577
  [selectedTemplate == null ? void 0 : selectedTemplate.name]
12413
12578
  );
12414
- const templateVariables = (0, import_react19.useMemo)(() => {
12579
+ const templateVariables = (0, import_react20.useMemo)(() => {
12415
12580
  return extractTemplateVariables(selectedTemplate);
12416
12581
  }, [selectedTemplate]);
12417
- const [variableMapping, setVariableMapping] = (0, import_react19.useState)({});
12418
- (0, import_react19.useEffect)(() => {
12582
+ const [variableMapping, setVariableMapping] = (0, import_react20.useState)({});
12583
+ (0, import_react20.useEffect)(() => {
12419
12584
  setVariableMapping({});
12420
12585
  }, [selectedTemplateId]);
12421
- const textableColumnOptions = (0, import_react19.useMemo)(() => {
12586
+ const textableColumnOptions = (0, import_react20.useMemo)(() => {
12422
12587
  return getTextableColumnOptions({
12423
12588
  tableColumns: tableColumns2,
12424
12589
  selectedPhoneOption,
@@ -12444,7 +12609,7 @@ function useWhatsAppState(props) {
12444
12609
  });
12445
12610
  });
12446
12611
  };
12447
- const existingTemplateNames = (0, import_react19.useMemo)(() => {
12612
+ const existingTemplateNames = (0, import_react20.useMemo)(() => {
12448
12613
  return templates.map((t) => t.name);
12449
12614
  }, [templates]);
12450
12615
  const handleDeleteTemplate = async () => {
@@ -12491,14 +12656,14 @@ function useWhatsAppState(props) {
12491
12656
  postSendActionColumn,
12492
12657
  postSendActionValue
12493
12658
  );
12494
- const isStaticVariableMissing = (0, import_react19.useMemo)(() => {
12659
+ const isStaticVariableMissing = (0, import_react20.useMemo)(() => {
12495
12660
  return isStaticVariableIncomplete(templateVariables, variableMapping);
12496
12661
  }, [templateVariables, variableMapping]);
12497
- const currentRecords = (0, import_react19.useMemo)(() => {
12662
+ const currentRecords = (0, import_react20.useMemo)(() => {
12498
12663
  var _a2;
12499
12664
  return rawRecords && rawRecords.length > 0 ? rawRecords : Array.isArray(props.data) ? props.data : Array.isArray((_a2 = props.data) == null ? void 0 : _a2.records) ? props.data.records : [];
12500
12665
  }, [rawRecords, props.data]);
12501
- const preparedRecipients = (0, import_react19.useMemo)(() => {
12666
+ const preparedRecipients = (0, import_react20.useMemo)(() => {
12502
12667
  return prepareRecipients({
12503
12668
  selectedIds: selectedRowIds,
12504
12669
  records: currentRecords,
@@ -12518,7 +12683,7 @@ function useWhatsAppState(props) {
12518
12683
  selectedSubtableFilterCol
12519
12684
  ]);
12520
12685
  const finalRecipientCount = preparedRecipients.length;
12521
- const validMainRowsCount = (0, import_react19.useMemo)(() => {
12686
+ const validMainRowsCount = (0, import_react20.useMemo)(() => {
12522
12687
  const rowIdSet = new Set(
12523
12688
  preparedRecipients.map((r) => r.mainRowId).filter(Boolean)
12524
12689
  );
@@ -12627,7 +12792,7 @@ function useWhatsAppState(props) {
12627
12792
  setIsSendingTest(false);
12628
12793
  }
12629
12794
  };
12630
- const handleSendMessages = (0, import_react19.useCallback)(async () => {
12795
+ const handleSendMessages = (0, import_react20.useCallback)(async () => {
12631
12796
  var _a2, _b2;
12632
12797
  if (isSendDisabled || isSendingBroadcast) return;
12633
12798
  const recipients = preparedRecipients;
@@ -12933,7 +13098,7 @@ function useWhatsAppState(props) {
12933
13098
  }
12934
13099
 
12935
13100
  // src/components/WhatsAppComponent/ui/TemplateSelectionBlock.tsx
12936
- var import_react20 = require("react");
13101
+ var import_react21 = require("react");
12937
13102
  var import_lucide_react11 = require("lucide-react");
12938
13103
  var import_jsx_runtime18 = require("react/jsx-runtime");
12939
13104
  function TemplateSelectionBlock({
@@ -12961,7 +13126,7 @@ function TemplateSelectionBlock({
12961
13126
  isUploadingMedia = false,
12962
13127
  handleFileUpload
12963
13128
  }) {
12964
- const fileInputRef = (0, import_react20.useRef)(null);
13129
+ const fileInputRef = (0, import_react21.useRef)(null);
12965
13130
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("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: [
12966
13131
  /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "space-y-1.5 shrink-0", children: [
12967
13132
  /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: "flex items-center justify-between pb-1.5 border-b border-slate-200/70 shrink-0 gap-2", children: [
@@ -13913,19 +14078,19 @@ function SettingsAndActionsBlock({
13913
14078
  }
13914
14079
 
13915
14080
  // src/components/WhatsAppComponent/inbox/useInboxState.ts
13916
- var import_react21 = require("react");
14081
+ var import_react22 = require("react");
13917
14082
  function useInboxState(orgId, actions) {
13918
- const [conversations, setConversations] = (0, import_react21.useState)([]);
13919
- const [activeConversationId, setActiveConversationId] = (0, import_react21.useState)(null);
13920
- const [messages, setMessages] = (0, import_react21.useState)([]);
13921
- const [isLoading, setIsLoading] = (0, import_react21.useState)(false);
13922
- const [isSending, setIsSending] = (0, import_react21.useState)(false);
13923
- const [error, setError] = (0, import_react21.useState)(null);
13924
- const actionsRef = (0, import_react21.useRef)(actions);
13925
- (0, import_react21.useEffect)(() => {
14083
+ const [conversations, setConversations] = (0, import_react22.useState)([]);
14084
+ const [activeConversationId, setActiveConversationId] = (0, import_react22.useState)(null);
14085
+ const [messages, setMessages] = (0, import_react22.useState)([]);
14086
+ const [isLoading, setIsLoading] = (0, import_react22.useState)(false);
14087
+ const [isSending, setIsSending] = (0, import_react22.useState)(false);
14088
+ const [error, setError] = (0, import_react22.useState)(null);
14089
+ const actionsRef = (0, import_react22.useRef)(actions);
14090
+ (0, import_react22.useEffect)(() => {
13926
14091
  actionsRef.current = actions;
13927
14092
  });
13928
- const fetchConversations = (0, import_react21.useCallback)(async () => {
14093
+ const fetchConversations = (0, import_react22.useCallback)(async () => {
13929
14094
  if (!orgId) return;
13930
14095
  const res = await actionsRef.current.getConversations(orgId);
13931
14096
  if (res.success && res.data) {
@@ -13934,7 +14099,7 @@ function useInboxState(orgId, actions) {
13934
14099
  setError(res.error);
13935
14100
  }
13936
14101
  }, [orgId]);
13937
- const fetchMessages = (0, import_react21.useCallback)(async (conversationId, silent = false) => {
14102
+ const fetchMessages = (0, import_react22.useCallback)(async (conversationId, silent = false) => {
13938
14103
  if (!silent) setIsLoading(true);
13939
14104
  const res = await actionsRef.current.getMessages(conversationId);
13940
14105
  if (res.success && res.data) {
@@ -13947,7 +14112,7 @@ function useInboxState(orgId, actions) {
13947
14112
  }
13948
14113
  if (!silent) setIsLoading(false);
13949
14114
  }, []);
13950
- (0, import_react21.useEffect)(() => {
14115
+ (0, import_react22.useEffect)(() => {
13951
14116
  fetchConversations();
13952
14117
  const interval = setInterval(() => {
13953
14118
  fetchConversations();
@@ -13961,18 +14126,18 @@ function useInboxState(orgId, actions) {
13961
14126
  setActiveConversationId(id);
13962
14127
  fetchMessages(id);
13963
14128
  };
13964
- const handleSendMessage = async (text) => {
13965
- if (!activeConversationId || !text.trim()) return;
14129
+ const handleSendMessage = async (text2) => {
14130
+ if (!activeConversationId || !text2.trim()) return;
13966
14131
  setIsSending(true);
13967
14132
  const tempMsg = {
13968
14133
  id: Date.now().toString(),
13969
14134
  direction: "OUTBOUND",
13970
- content: text,
14135
+ content: text2,
13971
14136
  status: "SENDING",
13972
14137
  createdAt: /* @__PURE__ */ new Date()
13973
14138
  };
13974
14139
  setMessages((prev) => [tempMsg, ...prev]);
13975
- const res = await actions.sendMessage(activeConversationId, text, orgId);
14140
+ const res = await actions.sendMessage(activeConversationId, text2, orgId);
13976
14141
  if (res.success && res.data) {
13977
14142
  setMessages((prev) => prev.map((m) => m.id === tempMsg.id ? res.data : m));
13978
14143
  fetchConversations();
@@ -14046,17 +14211,17 @@ function ConversationList({ conversations, activeId, onSelect }) {
14046
14211
  }
14047
14212
 
14048
14213
  // src/components/WhatsAppComponent/inbox/ChatWindow.tsx
14049
- var import_react22 = require("react");
14214
+ var import_react23 = require("react");
14050
14215
  var import_lucide_react15 = require("lucide-react");
14051
14216
  var import_jsx_runtime22 = require("react/jsx-runtime");
14052
14217
  function ChatWindow({ activeConversation, messages, isLoading, isSending, onSendMessage }) {
14053
- const [inputText, setInputText] = (0, import_react22.useState)("");
14054
- const messagesTopRef = (0, import_react22.useRef)(null);
14218
+ const [inputText, setInputText] = (0, import_react23.useState)("");
14219
+ const messagesTopRef = (0, import_react23.useRef)(null);
14055
14220
  const scrollToTop = () => {
14056
14221
  var _a;
14057
14222
  (_a = messagesTopRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
14058
14223
  };
14059
- (0, import_react22.useEffect)(() => {
14224
+ (0, import_react23.useEffect)(() => {
14060
14225
  scrollToTop();
14061
14226
  }, [messages.length, activeConversation == null ? void 0 : activeConversation.id]);
14062
14227
  const handleSend = (e) => {
@@ -14172,7 +14337,7 @@ function WhatsAppComponent(props) {
14172
14337
  var _a;
14173
14338
  const { className = "", settings, orgId, componentId, executeAction } = props;
14174
14339
  const state = useWhatsAppState(props);
14175
- const [activeTab, setActiveTab] = import_react23.default.useState("broadcast");
14340
+ const [activeTab, setActiveTab] = import_react24.default.useState("broadcast");
14176
14341
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
14177
14342
  "div",
14178
14343
  {
@@ -14225,12 +14390,12 @@ function WhatsAppComponent(props) {
14225
14390
  return { success: false, error: (e == null ? void 0 : e.message) || "\u05E9\u05D2\u05D9\u05D0\u05D4 \u05D1\u05D8\u05E2\u05D9\u05E0\u05EA \u05D4\u05D5\u05D3\u05E2\u05D5\u05EA" };
14226
14391
  }
14227
14392
  },
14228
- sendInboxMessageAction: async (convId, text, currentOrgId) => {
14393
+ sendInboxMessageAction: async (convId, text2, currentOrgId) => {
14229
14394
  if (!executeAction) return { success: false, error: "executeAction missing" };
14230
14395
  try {
14231
14396
  const data = await executeAction("SEND_WHATSAPP_INBOX_MESSAGE", {
14232
14397
  conversationId: convId,
14233
- text,
14398
+ text: text2,
14234
14399
  orgId: currentOrgId
14235
14400
  });
14236
14401
  return { success: true, data };
@@ -14577,18 +14742,18 @@ function WhatsAppComponent(props) {
14577
14742
  }
14578
14743
 
14579
14744
  // src/components/FormBlock/FormBlock.tsx
14580
- var import_react24 = require("react");
14745
+ var import_react25 = require("react");
14581
14746
  var import_lucide_react17 = require("lucide-react");
14582
14747
  var import_jsx_runtime25 = require("react/jsx-runtime");
14583
14748
  function FormBlock({ settings: schema, executeAction, componentId, className = "", onSuccess }) {
14584
14749
  const { showError, addToast } = useToast();
14585
- const [formData, setFormData] = (0, import_react24.useState)({});
14586
- const [isSubmitting, setIsSubmitting] = (0, import_react24.useState)(false);
14587
- const [isSubmitted, setIsSubmitted] = (0, import_react24.useState)(false);
14588
- const [columns, setColumns] = (0, import_react24.useState)((schema == null ? void 0 : schema.columns) || []);
14589
- const [isLoadingSchema, setIsLoadingSchema] = (0, import_react24.useState)(false);
14750
+ const [formData, setFormData] = (0, import_react25.useState)({});
14751
+ const [isSubmitting, setIsSubmitting] = (0, import_react25.useState)(false);
14752
+ const [isSubmitted, setIsSubmitted] = (0, import_react25.useState)(false);
14753
+ const [columns, setColumns] = (0, import_react25.useState)((schema == null ? void 0 : schema.columns) || []);
14754
+ const [isLoadingSchema, setIsLoadingSchema] = (0, import_react25.useState)(false);
14590
14755
  const targetTableId = (schema == null ? void 0 : schema.tableMetaId) || (schema == null ? void 0 : schema.tableId) || (schema == null ? void 0 : schema.id);
14591
- (0, import_react24.useEffect)(() => {
14756
+ (0, import_react25.useEffect)(() => {
14592
14757
  let isMounted = true;
14593
14758
  if ((!(schema == null ? void 0 : schema.columns) || schema.columns.length === 0) && targetTableId && executeAction) {
14594
14759
  setIsLoadingSchema(true);
@@ -14781,7 +14946,9 @@ var UNIVERSE_COMPONENTS = {
14781
14946
  UNIVERSE_COMPONENTS,
14782
14947
  WhatsAppComponent,
14783
14948
  applyFormulaColumns,
14949
+ applyRelationCopy,
14784
14950
  buildColumnOptions,
14951
+ buildRelationCopyPatch,
14785
14952
  buildRelationRef,
14786
14953
  calculateMinColumnWidth,
14787
14954
  checkElementTruncation,
@@ -14801,8 +14968,12 @@ var UNIVERSE_COMPONENTS = {
14801
14968
  formatTimeIso,
14802
14969
  generateWhatsAppLink,
14803
14970
  getDeterministicPastelBadge,
14971
+ getEligibleCopyTargets,
14804
14972
  getNextVariableIndex,
14973
+ getRelationCopyLockedTargets,
14974
+ getRelationCopyTargetNames,
14805
14975
  getRolePermissions,
14976
+ getSelectedRelationId,
14806
14977
  getStatusConfig,
14807
14978
  hasBracketSpaces,
14808
14979
  hasConsecutiveVariables,
@@ -14826,6 +14997,7 @@ var UNIVERSE_COMPONENTS = {
14826
14997
  parseTimeParts,
14827
14998
  readColumnValue,
14828
14999
  reindexVariables,
15000
+ renameCopyTarget,
14829
15001
  resolveDefaultStatusId,
14830
15002
  resolveProtocol,
14831
15003
  sanitizePhoneNumber,
@@ -14839,6 +15011,7 @@ var UNIVERSE_COMPONENTS = {
14839
15011
  useToast,
14840
15012
  useWhatsAppState,
14841
15013
  validateFormula,
15014
+ validateRelationCopyTargets,
14842
15015
  validateSequentialVariables,
14843
15016
  validateTemplateBody,
14844
15017
  validateTemplateButtons,