@signiphi/pdf-signer 0.2.0-beta.17 → 0.2.0-beta.19

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.
@@ -584,13 +584,20 @@ function extractFieldValue(field, fieldType) {
584
584
  try {
585
585
  switch (fieldType) {
586
586
  case "text":
587
+ case "date":
587
588
  return field.getText?.() || "";
588
589
  case "checkbox":
589
590
  return field.isChecked?.() ? "true" : "false";
590
591
  case "dropdown":
591
- case "optionlist":
592
+ case "optionlist": {
593
+ const selected = field.getSelected?.();
594
+ return Array.isArray(selected) ? selected[0] || "" : String(selected || "");
595
+ }
592
596
  case "radiogroup":
593
- return field.getSelected?.()?.[0] || "";
597
+ case "radio": {
598
+ const radioSelected = field.getSelected?.();
599
+ return radioSelected ? String(radioSelected) : "";
600
+ }
594
601
  default:
595
602
  return "";
596
603
  }
@@ -2317,6 +2324,7 @@ ${cssRules.join("\n")}`;
2317
2324
  }
2318
2325
  }
2319
2326
  logger.info(`[RADIO DETECT] Found ${Object.keys(radioGroups).length} radio groups:`, Object.keys(radioGroups));
2327
+ const processedRadioFieldNames = new Set(Object.keys(radioGroups));
2320
2328
  for (const [fieldName, radioButtons] of Object.entries(radioGroups)) {
2321
2329
  const selectedRadio = radioButtons.find(
2322
2330
  (rb) => rb.data && typeof rb.data === "object" && rb.data.value === true
@@ -2342,7 +2350,7 @@ ${cssRules.join("\n")}`;
2342
2350
  }
2343
2351
  for (const [id, data] of Object.entries(storedData)) {
2344
2352
  const fieldName = idToNameMap[id];
2345
- if (fieldName && values[fieldName]) {
2353
+ if (fieldName && (fieldName in values || processedRadioFieldNames.has(fieldName))) {
2346
2354
  continue;
2347
2355
  }
2348
2356
  if (fieldName) {
@@ -2359,13 +2367,13 @@ ${cssRules.join("\n")}`;
2359
2367
  } else if (data !== void 0 && data !== null) {
2360
2368
  extractedValue = String(data);
2361
2369
  }
2362
- if (extractedValue !== void 0 && extractedValue !== "") {
2370
+ if (extractedValue !== void 0) {
2363
2371
  values[fieldName] = extractedValue;
2364
2372
  }
2365
2373
  }
2366
2374
  }
2367
2375
  for (const [name, fields] of Object.entries(fieldObjects)) {
2368
- if (!values[name]) {
2376
+ if (!(name in values)) {
2369
2377
  const fieldArray = fields;
2370
2378
  const field = fieldArray[0];
2371
2379
  if (field && field.value !== void 0 && field.value !== null) {
@@ -5110,12 +5118,22 @@ function RadioGroupRenderer({
5110
5118
  className = ""
5111
5119
  }) {
5112
5120
  const options = field.options || [];
5121
+ const [localValue, setLocalValue] = React9.useState(value);
5122
+ React9.useEffect(() => {
5123
+ if (value && value !== localValue) {
5124
+ setLocalValue(value);
5125
+ }
5126
+ }, [value]);
5127
+ const handleChange = (newValue) => {
5128
+ setLocalValue(newValue);
5129
+ onChange(newValue);
5130
+ };
5113
5131
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("w-full", className), children: [
5114
5132
  /* @__PURE__ */ jsxRuntime.jsx(
5115
5133
  RadioGroup,
5116
5134
  {
5117
- value,
5118
- onValueChange: onChange,
5135
+ value: localValue,
5136
+ onValueChange: handleChange,
5119
5137
  required: field.required,
5120
5138
  className: "",
5121
5139
  children: options.map((option) => {
@@ -5124,7 +5142,7 @@ function RadioGroupRenderer({
5124
5142
  "div",
5125
5143
  {
5126
5144
  className: "flex items-center space-x-3 p-3 -ml-3 -mr-3 rounded-lg hover:bg-muted/50 cursor-pointer transition-colors duration-200",
5127
- onClick: () => onChange(option),
5145
+ onClick: () => handleChange(option),
5128
5146
  children: [
5129
5147
  /* @__PURE__ */ jsxRuntime.jsx(
5130
5148
  RadioGroupItem,
@@ -9030,6 +9048,9 @@ function SubmissionForm({
9030
9048
  }
9031
9049
  }
9032
9050
  }
9051
+ if (field.type === "radio" && (normalizedPdfValue === "true" || normalizedPdfValue === "false")) {
9052
+ normalizedPdfValue = void 0;
9053
+ }
9033
9054
  if (field.type === "date" && pdfValue) {
9034
9055
  const validation = parseAndValidateDate(pdfValue);
9035
9056
  if (!validation.isValid) {
@@ -9043,8 +9064,12 @@ function SubmissionForm({
9043
9064
  normalizedPdfValue = validation.isoString;
9044
9065
  }
9045
9066
  }
9046
- if (normalizedPdfValue && normalizedPdfValue !== currentReactValue) {
9067
+ const isUnresolvedRadioIndex = field.type === "radio" && normalizedPdfValue?.includes("__RADIO_OPTION_INDEX_");
9068
+ const pdfFieldReported = field.id in pdfValues;
9069
+ if (normalizedPdfValue && normalizedPdfValue !== currentReactValue && !isUnresolvedRadioIndex) {
9047
9070
  setFieldValue(field.id, normalizedPdfValue);
9071
+ } else if (pdfFieldReported && !normalizedPdfValue && currentReactValue) {
9072
+ setFieldValue(field.id, "");
9048
9073
  }
9049
9074
  }
9050
9075
  if (invalidDates.length > 0) {
@@ -9156,6 +9181,15 @@ function SubmissionForm({
9156
9181
  setFieldValue(currentDateField.id, dateValue);
9157
9182
  try {
9158
9183
  await setFormFieldValues({ [currentDateField.id]: dateValue });
9184
+ const pdfApp = viewerRef.current?.getPDFViewerApplication?.();
9185
+ const pdfDocument = pdfApp?.pdfDocument;
9186
+ if (pdfDocument?.annotationStorage && typeof pdfDocument.getFieldObjects === "function") {
9187
+ const fieldObjects = await pdfDocument.getFieldObjects() || {};
9188
+ const widgets = fieldObjects[currentDateField.id];
9189
+ if (widgets?.[0]?.id) {
9190
+ pdfDocument.annotationStorage.setValue(widgets[0].id, { value: dateValue });
9191
+ }
9192
+ }
9159
9193
  logger.info(`[DATE SELECT] Updated PDF field ${currentDateField.id}`);
9160
9194
  } catch (error) {
9161
9195
  logger.error(`[DATE SELECT] Failed to update PDF field:`, error);
@@ -9663,6 +9697,11 @@ function SubmissionForm({
9663
9697
  const currentSignatures = signaturesRef.current;
9664
9698
  const pdfFieldValues = await getFormFieldValues();
9665
9699
  const allFieldValues = { ...pdfFieldValues, ...currentFieldValues };
9700
+ for (const [fieldId, pdfVal] of Object.entries(pdfFieldValues)) {
9701
+ if (pdfVal === "") {
9702
+ allFieldValues[fieldId] = "";
9703
+ }
9704
+ }
9666
9705
  console.log("[VALIDATION] === MERGING SIGNATURES INTO allFieldValues ===");
9667
9706
  console.log("[VALIDATION] currentSignatures:", currentSignatures);
9668
9707
  for (const [fieldId, signatureValue] of Object.entries(currentSignatures)) {
@@ -9718,6 +9757,15 @@ function SubmissionForm({
9718
9757
  }
9719
9758
  }
9720
9759
  }
9760
+ const alreadyCheckedTypes = /* @__PURE__ */ new Set(["date", "signature", "initials"]);
9761
+ for (const field of filteredFields) {
9762
+ if (!field.required || alreadyCheckedTypes.has(field.type)) continue;
9763
+ if (field.id === "signature_field_main" || field.id === "initials_field_main") continue;
9764
+ const value = allFieldValues[field.id];
9765
+ if (!value || typeof value === "string" && value.trim() === "") {
9766
+ validationErrors2.push(`${getFieldDisplayName(field)} is required`);
9767
+ }
9768
+ }
9721
9769
  const isFieldsValid = validateFields(currentSignatures);
9722
9770
  if (!isFieldsValid) {
9723
9771
  for (const field of filteredFields) {
@@ -9827,6 +9875,11 @@ function SubmissionForm({
9827
9875
  const currentFieldValues = fieldValuesRef.current;
9828
9876
  const currentSignatures = signaturesRef.current;
9829
9877
  const finalFieldValues = { ...pdfFieldValues, ...currentFieldValues };
9878
+ for (const [fieldId, pdfVal] of Object.entries(pdfFieldValues)) {
9879
+ if (pdfVal === "") {
9880
+ finalFieldValues[fieldId] = "";
9881
+ }
9882
+ }
9830
9883
  console.log("[SUBMIT] === MERGING SIGNATURES INTO finalFieldValues FOR FLATTENING ===");
9831
9884
  console.log("[SUBMIT] currentSignatures:", currentSignatures);
9832
9885
  for (const [fieldId, signatureValue] of Object.entries(currentSignatures)) {