@unlev/exeq 0.1.6 → 0.1.7
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 +38 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1355,11 +1355,18 @@ function SignerView({
|
|
|
1355
1355
|
const [fields, setFields] = (0, import_react4.useState)([]);
|
|
1356
1356
|
const [selectedFieldId, setSelectedFieldId] = (0, import_react4.useState)(null);
|
|
1357
1357
|
const [signer, setSigner] = (0, import_react4.useState)(initialSigner || "Signer 1");
|
|
1358
|
+
const initializedRef = (0, import_react4.useRef)(false);
|
|
1358
1359
|
const [loading, setLoading] = (0, import_react4.useState)(false);
|
|
1359
1360
|
const [submitting, setSubmitting] = (0, import_react4.useState)(false);
|
|
1360
1361
|
const [pdfSource, setPdfSource] = (0, import_react4.useState)(null);
|
|
1361
1362
|
const [callbackUrl, setCallbackUrl] = (0, import_react4.useState)(initialCallbackUrl || "");
|
|
1362
1363
|
const containerRef = (0, import_react4.useRef)(null);
|
|
1364
|
+
(0, import_react4.useEffect)(() => {
|
|
1365
|
+
if (initialSigner) {
|
|
1366
|
+
setSigner(initialSigner);
|
|
1367
|
+
setSelectedFieldId(null);
|
|
1368
|
+
}
|
|
1369
|
+
}, [initialSigner]);
|
|
1363
1370
|
(0, import_react4.useEffect)(() => {
|
|
1364
1371
|
if (initialTemplate) {
|
|
1365
1372
|
let templateFields = initialTemplate.fields;
|
|
@@ -1373,7 +1380,15 @@ function SignerView({
|
|
|
1373
1380
|
return value !== void 0 ? { ...f, value } : f;
|
|
1374
1381
|
});
|
|
1375
1382
|
}
|
|
1376
|
-
|
|
1383
|
+
if (initializedRef.current) {
|
|
1384
|
+
setFields((prev) => {
|
|
1385
|
+
const valueMap = new Map(prev.filter((f) => f.value).map((f) => [f.id, f.value]));
|
|
1386
|
+
return templateFields.map((f) => valueMap.has(f.id) ? { ...f, value: valueMap.get(f.id) } : f);
|
|
1387
|
+
});
|
|
1388
|
+
} else {
|
|
1389
|
+
setFields(templateFields);
|
|
1390
|
+
initializedRef.current = true;
|
|
1391
|
+
}
|
|
1377
1392
|
if (initialPdfUrl) loadPdf(initialPdfUrl);
|
|
1378
1393
|
return;
|
|
1379
1394
|
}
|
|
@@ -1386,11 +1401,31 @@ function SignerView({
|
|
|
1386
1401
|
if (cbUrl) setCallbackUrl(cbUrl);
|
|
1387
1402
|
if (pdfUrl) loadPdf(pdfUrl);
|
|
1388
1403
|
if (fieldsUrl) {
|
|
1389
|
-
fetch(fieldsUrl).then((r) => r.json()).then((template) =>
|
|
1404
|
+
fetch(fieldsUrl).then((r) => r.json()).then((template) => {
|
|
1405
|
+
if (initializedRef.current) {
|
|
1406
|
+
setFields((prev) => {
|
|
1407
|
+
const valueMap = new Map(prev.filter((f) => f.value).map((f) => [f.id, f.value]));
|
|
1408
|
+
return template.fields.map((f) => valueMap.has(f.id) ? { ...f, value: valueMap.get(f.id) } : f);
|
|
1409
|
+
});
|
|
1410
|
+
} else {
|
|
1411
|
+
setFields(template.fields);
|
|
1412
|
+
initializedRef.current = true;
|
|
1413
|
+
}
|
|
1414
|
+
}).catch((err) => console.error("Failed to load fields:", err));
|
|
1390
1415
|
}
|
|
1391
1416
|
const handleMessage = (e) => {
|
|
1392
1417
|
if (e.data?.type === "load-signing") {
|
|
1393
|
-
if (e.data.fields)
|
|
1418
|
+
if (e.data.fields) {
|
|
1419
|
+
if (initializedRef.current) {
|
|
1420
|
+
setFields((prev) => {
|
|
1421
|
+
const valueMap = new Map(prev.filter((f) => f.value).map((f) => [f.id, f.value]));
|
|
1422
|
+
return e.data.fields.map((f) => valueMap.has(f.id) ? { ...f, value: valueMap.get(f.id) } : f);
|
|
1423
|
+
});
|
|
1424
|
+
} else {
|
|
1425
|
+
setFields(e.data.fields);
|
|
1426
|
+
initializedRef.current = true;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1394
1429
|
if (e.data.pdfUrl) loadPdf(e.data.pdfUrl);
|
|
1395
1430
|
if (e.data.signer) setSigner(e.data.signer);
|
|
1396
1431
|
if (e.data.callbackUrl) setCallbackUrl(e.data.callbackUrl);
|