formtress-js 0.1.3 → 0.1.4

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.
@@ -0,0 +1 @@
1
+ function d(){document.querySelectorAll('form[data-ft^="https://formtress"]').forEach(r=>{const n=r.dataset.ft;if(!n)return;const s=r.closest(".w-form");if(!s)return;const t=s.querySelector(".w-button"),l=s.querySelector(".w-form-done"),e=s.querySelector(".w-form-fail");if(!t||!l||!e)return;let a=e.querySelector("[data-ft-error]");a||(a=e.firstChild),r.addEventListener("submit",async function(c){c.preventDefault(),e.style.display="none";const i=t.value;t.value=t.dataset.wait||"Please wait...";const f=new FormData(r);try{const o=await fetch(n,{method:"POST",body:f,mode:"cors",credentials:"same-origin"}),u=await o.text();t.value=i,o.ok?(r.style.display="none",l.style.display="block"):(console.error("Form submission failed:",o.status,o.statusText),a.textContent=u,e.style.display="block")}catch(o){console.error("Error submitting form:",o),a.textContent="An error occurred. Please try again later.",e.style.display="block",t.value=i}})})}typeof window<"u"&&d();
@@ -0,0 +1 @@
1
+ (function(n){typeof define=="function"&&define.amd?define(n):n()})(function(){"use strict";function n(){document.querySelectorAll('form[data-ft^="https://formtress"]').forEach(s=>{const i=s.dataset.ft;if(!i)return;const r=s.closest(".w-form");if(!r)return;const t=r.querySelector(".w-button"),l=r.querySelector(".w-form-done"),e=r.querySelector(".w-form-fail");if(!t||!l||!e)return;let a=e.querySelector("[data-ft-error]");a||(a=e.firstChild),s.addEventListener("submit",async function(f){f.preventDefault(),e.style.display="none";const c=t.value;t.value=t.dataset.wait||"Please wait...";const u=new FormData(s);try{const o=await fetch(i,{method:"POST",body:u,mode:"cors",credentials:"same-origin"}),d=await o.text();t.value=c,o.ok?(s.style.display="none",l.style.display="block"):(console.error("Form submission failed:",o.status,o.statusText),a.textContent=d,e.style.display="block")}catch(o){console.error("Error submitting form:",o),a.textContent="An error occurred. Please try again later.",e.style.display="block",t.value=c}})})}typeof window<"u"&&n()});
package/package.json CHANGED
@@ -3,8 +3,8 @@
3
3
  "description": "A tiny library for managing Formtress forms",
4
4
  "private": false,
5
5
  "license": "MIT",
6
- "main": "dist/index.js",
7
- "version": "0.1.3",
6
+ "main": "dist/index.umd.js",
7
+ "version": "0.1.4",
8
8
  "type": "module",
9
9
  "homepage": "https://formtress.com",
10
10
  "author": "Christos Soulaki",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@types/node": "^22.14.1",
19
+ "glob": "^11.0.1",
19
20
  "typescript": "~5.7.2",
20
21
  "vite": "^6.3.1"
21
22
  }
package/vite.config.ts CHANGED
@@ -1,18 +1,41 @@
1
- import { resolve } from 'path'
1
+ import { globSync } from 'glob'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
2
4
  import { defineConfig } from "vite"
3
- import type { UserConfig } from "vite"
4
5
 
5
6
  export default defineConfig({
6
7
  base: "./",
7
8
  build: {
8
- lib: {
9
- entry: {
10
- webflow: resolve(__dirname, "src/webflow/index.ts"),
11
- index: resolve(__dirname, "src/index.ts"),
12
- },
13
- name: "formtress",
14
- formats: ["es"],
15
- fileName: (format, entryName) => `${entryName}.js`,
16
- },
9
+ rollupOptions: {
10
+ input: 'src/index.ts',
11
+ // input: Object.fromEntries(
12
+ // globSync('src/**/*.ts').map(file => [
13
+ // // This removes `src/` as well as the file extension from each
14
+ // // file, so e.g. src/nested/foo.js becomes nested/foo
15
+ // path.relative(
16
+ // 'src',
17
+ // file.slice(0, file.length - path.extname(file).length)
18
+ // ),
19
+ // // This expands the relative paths to absolute paths, so e.g.
20
+ // // src/nested/foo becomes /project/src/nested/foo.js
21
+ // fileURLToPath(new URL(file, import.meta.url))
22
+ // ])
23
+ // ),
24
+ output: [
25
+ {
26
+ dir: 'dist/mjs',
27
+ format: 'es',
28
+ entryFileNames: '[name].mjs',
29
+ inlineDynamicImports: false
30
+ },
31
+ {
32
+ dir: 'dist/umd',
33
+ format: 'umd',
34
+ name: 'Formtress',
35
+ entryFileNames: '[name].js',
36
+ inlineDynamicImports: false
37
+ },
38
+ ]
39
+ }
17
40
  },
18
- } satisfies UserConfig)
41
+ })
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- import { default as o } from "./webflow.js";
2
- export {
3
- o as webflow
4
- };
package/dist/webflow.js DELETED
@@ -1,32 +0,0 @@
1
- function d() {
2
- document.querySelectorAll('form[data-ft^="https://formtress"]').forEach((r) => {
3
- const n = r.dataset.ft;
4
- if (!n) return;
5
- const s = r.closest(".w-form");
6
- if (!s) return;
7
- const t = s.querySelector(".w-button"), l = s.querySelector(".w-form-done"), e = s.querySelector(".w-form-fail");
8
- if (!t || !l || !e) return;
9
- let a = e.querySelector("[data-ft-error]");
10
- a || (a = e.firstChild), r.addEventListener("submit", async function(c) {
11
- c.preventDefault(), e.style.display = "none";
12
- const i = t.value;
13
- t.value = t.dataset.wait || "Please wait...";
14
- const f = new FormData(r);
15
- try {
16
- const o = await fetch(n, {
17
- method: "POST",
18
- body: f,
19
- mode: "cors",
20
- credentials: "same-origin"
21
- }), u = await o.text();
22
- t.value = i, o.ok ? (r.style.display = "none", l.style.display = "block") : (console.error("Form submission failed:", o.status, o.statusText), a.textContent = u, e.style.display = "block");
23
- } catch (o) {
24
- console.error("Error submitting form:", o), a.textContent = "An error occurred. Please try again later.", e.style.display = "block", t.value = i;
25
- }
26
- });
27
- });
28
- }
29
- typeof window < "u" && d();
30
- export {
31
- d as default
32
- };