@saastro/forms 0.6.1 → 0.6.2

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 CHANGED
@@ -6129,19 +6129,31 @@ function turnstilePlugin(config) {
6129
6129
  } = config;
6130
6130
  let scriptElement = null;
6131
6131
  let createdContainer = null;
6132
+ let renderedEl = null;
6132
6133
  let widgetId;
6133
6134
  let lastToken = null;
6134
6135
  let pending = null;
6136
+ const markNoTranslate = (el) => {
6137
+ el.setAttribute("translate", "no");
6138
+ el.classList.add("notranslate");
6139
+ };
6135
6140
  const resolveContainer = () => {
6136
6141
  if (container) {
6137
6142
  const found = document.querySelector(container);
6138
- if (found) return found;
6143
+ if (found) {
6144
+ markNoTranslate(found);
6145
+ return found;
6146
+ }
6139
6147
  }
6140
6148
  const byData = document.querySelector("[data-saastro-turnstile]");
6141
- if (byData) return byData;
6142
- if (!createdContainer) {
6149
+ if (byData) {
6150
+ markNoTranslate(byData);
6151
+ return byData;
6152
+ }
6153
+ if (!createdContainer || !document.body.contains(createdContainer)) {
6143
6154
  createdContainer = document.createElement("div");
6144
6155
  createdContainer.setAttribute("data-saastro-turnstile-fallback", "");
6156
+ markNoTranslate(createdContainer);
6145
6157
  createdContainer.style.position = "fixed";
6146
6158
  createdContainer.style.bottom = "12px";
6147
6159
  createdContainer.style.right = "12px";
@@ -6150,10 +6162,19 @@ function turnstilePlugin(config) {
6150
6162
  }
6151
6163
  return createdContainer;
6152
6164
  };
6165
+ const widgetAlive = () => widgetId !== void 0 && !!renderedEl && document.contains(renderedEl) && renderedEl.childElementCount > 0;
6153
6166
  const ensureWidget = async () => {
6154
6167
  const api = await waitForTurnstile();
6155
- if (widgetId === void 0) {
6168
+ if (!widgetAlive()) {
6169
+ if (widgetId !== void 0) {
6170
+ try {
6171
+ api.remove(widgetId);
6172
+ } catch {
6173
+ }
6174
+ widgetId = void 0;
6175
+ }
6156
6176
  const el = resolveContainer();
6177
+ renderedEl = el;
6157
6178
  widgetId = api.render(el, {
6158
6179
  sitekey: siteKey,
6159
6180
  appearance,
@@ -6230,6 +6251,7 @@ function turnstilePlugin(config) {
6230
6251
  }
6231
6252
  }
6232
6253
  widgetId = void 0;
6254
+ renderedEl = null;
6233
6255
  lastToken = null;
6234
6256
  pending = null;
6235
6257
  if (createdContainer?.parentNode) {
@@ -7187,7 +7209,7 @@ function HubForm({
7187
7209
  };
7188
7210
  return /* @__PURE__ */ jsxs11(Fragment3, { children: [
7189
7211
  /* @__PURE__ */ jsx14(Form, { ...formProps, config }),
7190
- captcha?.provider === "turnstile" ? /* @__PURE__ */ jsx14("div", { "data-saastro-turnstile": true }) : null
7212
+ captcha?.provider === "turnstile" ? /* @__PURE__ */ jsx14("div", { "data-saastro-turnstile": true, translate: "no", className: "notranslate" }) : null
7191
7213
  ] });
7192
7214
  }
7193
7215
  var loadingStyle = {