form-craft-package 1.10.6 → 1.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-craft-package",
3
- "version": "1.10.6",
3
+ "version": "1.10.7",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -56,22 +56,20 @@ function LayoutRenderer_Signature({
56
56
 
57
57
  const cacheSignatureVector = () => {
58
58
  const pad = sigCanvasRef.current
59
- if (!pad) return
60
- if (pad.isEmpty()) {
61
- padVectorRef.current = null
62
- return
63
- }
59
+ if (!pad || pad.isEmpty()) return
64
60
  const data = pad.toData()
65
- padVectorRef.current = data.length ? data : null
61
+ if (data.length) padVectorRef.current = data
66
62
  }
67
63
 
68
64
  const restoreSignatureVector = () => {
69
65
  const pad = sigCanvasRef.current
70
66
  const data = padVectorRef.current
71
- if (!pad || !data?.length || isRestoringRef.current) return
67
+ const dataUrl = savedSignatureBlobNameRef.current
68
+ if (!pad || isRestoringRef.current || (!data?.length && !dataUrl)) return
72
69
  isRestoringRef.current = true
73
70
  try {
74
- pad.fromData(data)
71
+ if (data?.length) pad.fromData(data)
72
+ else if (dataUrl) pad.fromDataURL(dataUrl)
75
73
  } finally {
76
74
  isRestoringRef.current = false
77
75
  }
@@ -115,6 +113,11 @@ function LayoutRenderer_Signature({
115
113
 
116
114
  const shouldBindPad = isNewFormDataPage(formDataId) && !isGeneratingPdf
117
115
 
116
+ useEffect(() => {
117
+ if (!shouldBindPad || !isReady) return
118
+ scheduleVectorRestore()
119
+ }, [isReady, shouldBindPad])
120
+
118
121
  useEffect(() => {
119
122
  if (!shouldBindPad || typeof window === 'undefined') return
120
123
  let raf = 0
@@ -135,7 +138,7 @@ function LayoutRenderer_Signature({
135
138
  if (existing?.length) {
136
139
  padVectorRef.current = existing
137
140
  sigCanvasRef.current?.fromData(existing)
138
- }
141
+ } else scheduleVectorRestore()
139
142
  }
140
143
  raf = window.requestAnimationFrame(init)
141
144
  return () => window.cancelAnimationFrame(raf)
@@ -210,8 +213,16 @@ function LayoutRenderer_Signature({
210
213
  sigCanvasRef.current?.clear()
211
214
  savedSignatureBlobNameRef.current = ''
212
215
  padVectorRef.current = null
213
- if (fieldKeyJoined)
214
- formRef?.setFieldsValue({ [FormPreservedItemKeys.SignatureFields]: { [fieldKeyJoined]: null } })
216
+ if (fieldKeyJoined) {
217
+ const existing =
218
+ (formRef?.getFieldValue(FormPreservedItemKeys.SignatureFields) as Record<
219
+ string,
220
+ string | null
221
+ >) || {}
222
+ formRef?.setFieldsValue({
223
+ [FormPreservedItemKeys.SignatureFields]: { ...existing, [fieldKeyJoined]: null },
224
+ })
225
+ }
215
226
  }}
216
227
  >
217
228
  {clearBtnLabel || 'Clear'}
@@ -238,10 +249,14 @@ function LayoutRenderer_Signature({
238
249
  const sigBase64 = sigCanvasRef.current?.toDataURL()
239
250
  if (sigBase64 && fieldKeyJoined) {
240
251
  savedSignatureBlobNameRef.current = sigBase64
241
- formRef?.setFieldsValue({ [FormPreservedItemKeys.SignatureFields]: { [fieldKeyJoined]: sigBase64 } })
252
+ const existing =
253
+ (formRef?.getFieldValue(FormPreservedItemKeys.SignatureFields) as Record<string, string | null>) || {}
254
+ formRef?.setFieldsValue({
255
+ [FormPreservedItemKeys.SignatureFields]: { ...existing, [fieldKeyJoined]: sigBase64 },
256
+ })
242
257
  }
243
- }}
244
- />
258
+ }}
259
+ />
245
260
  ) : savedSignatureBlobName ? (
246
261
  errorOccured ? (
247
262
  <span className="font-bold italic text-danger">