1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. var __generator = (this && this.__generator) || function (thisArg, body) {
  12. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
  13. return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  14. function verb(n) { return function (v) { return step([n, v]); }; }
  15. function step(op) {
  16. if (f) throw new TypeError("Generator is already executing.");
  17. while (g && (g = 0, op[0] && (_ = 0)), _) try {
  18. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  19. if (y = 0, t) op = [op[0] & 2, t.value];
  20. switch (op[0]) {
  21. case 0: case 1: t = op; break;
  22. case 4: _.label++; return { value: op[1], done: false };
  23. case 5: _.label++; y = op[1]; op = [0]; continue;
  24. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  25. default:
  26. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  27. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  28. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  29. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  30. if (t[2]) _.ops.pop();
  31. _.trys.pop(); continue;
  32. }
  33. op = body.call(thisArg, _);
  34. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  35. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  36. }
  37. };
  38. Object.defineProperty(exports, "__esModule", { value: true });
  39. exports.Forms = void 0;
  40. // @ts-ignore
  41. var react_native_1 = require("react-native");
  42. var FormElement_1 = require("./FormElement");
  43. var FormField_1 = require("./FormField");
  44. /**
  45. * @class Forms
  46. * @description The Forms class provides methods for managing form fields in the document.
  47. * @hideconstructor
  48. */
  49. var Forms = /** @class */ (function () {
  50. function Forms(pdfViewRef) {
  51. this.pdfViewRef = pdfViewRef;
  52. }
  53. /**
  54. * @method getFormElements
  55. * @memberof Forms
  56. * @description Gets all the form elements for the current document.
  57. * @example
  58. * const result = await this.pdfRef.current?.getDocument().forms.getFormElements();
  59. * @returns { Promise<Array<FormElement>> } A promise containing an array of the FormElement objects.
  60. */
  61. Forms.prototype.getFormElements = function () {
  62. return __awaiter(this, void 0, void 0, function () {
  63. var formElements;
  64. return __generator(this, function (_a) {
  65. switch (_a.label) {
  66. case 0: return [4 /*yield*/, react_native_1.NativeModules.PDFDocumentManager.getFormElements((0, react_native_1.findNodeHandle)(this.pdfViewRef))];
  67. case 1:
  68. formElements = _a.sent();
  69. return [2 /*return*/, formElements.map(function (element) {
  70. var formElement;
  71. // Create the appropriate FormElement type based on the element type
  72. switch (element.formTypeName) {
  73. case 'button':
  74. case 'checkBox':
  75. case 'radioButton':
  76. formElement = new FormElement_1.ButtonFormElement(element);
  77. break;
  78. case 'choice':
  79. case 'listBox':
  80. case 'comboBox':
  81. formElement = new FormElement_1.ChoiceFormElement(element);
  82. break;
  83. case 'signature':
  84. formElement = new FormElement_1.SignatureFormElement(element);
  85. break;
  86. case 'textField':
  87. formElement = new FormElement_1.TextFieldFormElement(element);
  88. break;
  89. default:
  90. formElement = new FormElement_1.FormElement(element);
  91. }
  92. // If the element has a formField property, create the appropriate FormField type
  93. if (element.formField) {
  94. switch (element.formTypeName) {
  95. case 'button':
  96. case 'checkBox':
  97. case 'radioButton':
  98. formElement.formField = new FormField_1.ButtonFormField(element.formField);
  99. break;
  100. case 'choice':
  101. case 'listBox':
  102. case 'comboBox':
  103. formElement.formField = new FormField_1.ChoiceFormField(element.formField);
  104. break;
  105. case 'signature':
  106. formElement.formField = new FormField_1.SignatureFormField(element.formField);
  107. break;
  108. case 'textField':
  109. formElement.formField = new FormField_1.TextFormField(element.formField);
  110. break;
  111. default:
  112. // If type is unknown, create a base FormField
  113. formElement.formField = new FormField_1.FormField(element.formField);
  114. }
  115. }
  116. return formElement;
  117. })];
  118. }
  119. });
  120. });
  121. };
  122. /**
  123. * @method updateButtonFormFieldValue
  124. * @memberof Forms
  125. * @param {string} fullyQualifiedName The fully qualified name of the button form field to update.
  126. * @param {boolean} selected The new value of the button form field (true for selected, false for deselected).
  127. * @description Updates a button form field value on the document. This is used for checkboxes and radio buttons.
  128. * @example
  129. * const result = await this.pdfRef.current?.getDocument().forms.updateButtonFormFieldValue(name, true);
  130. * @returns { Promise<boolean> } A promise containing the result of the operation.
  131. */
  132. Forms.prototype.updateButtonFormFieldValue = function (fullyQualifiedName, value) {
  133. return react_native_1.NativeModules.PDFDocumentManager.updateFormFieldValue((0, react_native_1.findNodeHandle)(this.pdfViewRef), fullyQualifiedName, value);
  134. };
  135. /**
  136. * @method updateChoiceFormFieldValue
  137. * @memberof Forms
  138. * @param {string} fullyQualifiedName The fully qualified name of the choice form field to update.
  139. * @param {number[]} selectedIndices The indices of the selected options in the choice form field.
  140. * @description Updates a choice form field value on the document. This is used for combo boxes and list boxes.
  141. * @example
  142. * const result = await this.pdfRef.current?.getDocument().forms.updateChoiceFormFieldValue(name, [0, 2]);
  143. * @returns { Promise<boolean> } A promise containing the result of the operation.
  144. */
  145. Forms.prototype.updateChoiceFormFieldValue = function (fullyQualifiedName, selectedIndices) {
  146. return react_native_1.NativeModules.PDFDocumentManager.updateFormFieldValue((0, react_native_1.findNodeHandle)(this.pdfViewRef), fullyQualifiedName, selectedIndices);
  147. };
  148. /**
  149. * @method updateTextFormFieldValue
  150. * @memberof Forms
  151. * @param {string} fullyQualifiedName The fully qualified name of the text form field to update.
  152. * @param {string} value The new text value.
  153. * @description Updates a text form field value on the document.
  154. * @example
  155. * const result = await this.pdfRef.current?.getDocument().forms.updateTextFormFieldValue(name, 'New text');
  156. * @returns { Promise<boolean> } A promise containing the result of the operation.
  157. */
  158. Forms.prototype.updateTextFormFieldValue = function (fullyQualifiedName, value) {
  159. return react_native_1.NativeModules.PDFDocumentManager.updateFormFieldValue((0, react_native_1.findNodeHandle)(this.pdfViewRef), fullyQualifiedName, value);
  160. };
  161. return Forms;
  162. }());
  163. exports.Forms = Forms;