@nuasite/components 0.13.1 → 0.14.0

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
@@ -2,7 +2,7 @@
2
2
  "name": "@nuasite/components",
3
3
  "description": "Nua Site astro components.",
4
4
  "license": "Apache-2.0",
5
- "version": "0.13.1",
5
+ "version": "0.14.0",
6
6
  "files": [
7
7
  "dist/**",
8
8
  "src/**",
@@ -17,6 +17,9 @@ const {
17
17
  ...rest
18
18
  } = Astro.props
19
19
 
20
+ const hasCustomSuccess = 'successMessage' in Astro.props
21
+ const hasCustomError = 'errorMessage' in Astro.props
22
+
20
23
  const slotContent = await Astro.slots.render("default")
21
24
 
22
25
  if (!submitButtonRegex.test(slotContent)) {
@@ -37,10 +40,12 @@ const tokenId = `${tokenFieldName}_${formId}`
37
40
  <astro-form>
38
41
  <form
39
42
  action={action}
40
- class="astro-from"
43
+ class="astro-form"
41
44
  data-form-id={formId}
42
45
  data-token-field={tokenFieldName}
43
46
  data-success-message={successMessage}
47
+ data-custom-success={hasCustomSuccess || undefined}
48
+ data-custom-error={hasCustomError || undefined}
44
49
  data-error-message={errorMessage}
45
50
  data-submitting-message={submittingMessage}
46
51
  data-network-error-message={networkErrorMessage}
@@ -131,6 +136,8 @@ const tokenId = `${tokenFieldName}_${formId}`
131
136
  const networkErrorMessage = form.dataset.networkErrorMessage
132
137
  const tryAgainMessage = form.dataset.tryAgainMessage
133
138
  const fastSubmitMessage = form.dataset.fastSubmitMessage
139
+ const hasCustomSuccess = form.dataset.customSuccess != null
140
+ const hasCustomError = form.dataset.customError != null
134
141
  this.honeypotFieldNames = form.dataset.requiredFields?.split(',') || []
135
142
 
136
143
  const statusContainer = document.getElementById(`${formId}-status`)
@@ -217,21 +224,6 @@ const tokenId = `${tokenFieldName}_${formId}`
217
224
  return
218
225
  }
219
226
 
220
- for (const fieldName of this.honeypotFieldNames) {
221
- const field = form.querySelector(`[name="${fieldName}"]`) as HTMLInputElement;
222
- if (field && field.value.trim()) {
223
- showError(tryAgainMessage)
224
- return
225
- }
226
- }
227
-
228
- // Check CSS honeypot
229
- const cssHoneypot = form.querySelector('input[style*="position: absolute; left: -9999px"]') as HTMLInputElement;
230
- if (cssHoneypot && cssHoneypot.value.trim()) {
231
- showError(tryAgainMessage)
232
- return
233
- }
234
-
235
227
  const elapsed = performance.now() - activationTime
236
228
  if (minSubmitDelay > 0 && elapsed < minSubmitDelay) {
237
229
  showError(fastSubmitMessage || tryAgainMessage)
@@ -258,12 +250,12 @@ const tokenId = `${tokenFieldName}_${formId}`
258
250
  try { result = await response.json() } catch {}
259
251
 
260
252
  if (response.ok && 'success' in result && result.success) {
261
- const message = result.message || successMessage
253
+ const message = hasCustomSuccess ? successMessage : (result.message || successMessage)
262
254
  showSuccess(message)
263
255
  form.reset()
264
256
  refreshSubmissionGuards()
265
257
  } else {
266
- const message = result.error || result.message || errorMessage
258
+ const message = hasCustomError ? errorMessage : (result.error || result.message || errorMessage)
267
259
  showError(message)
268
260
  }
269
261
  } catch (err) {