@bettercms-ai/convert 0.12.0 → 0.13.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/CHANGELOG.md +33 -0
- package/dist/cli.js +18 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -429,6 +429,16 @@ interface FormsReceipt {
|
|
|
429
429
|
pending: PendingForm[];
|
|
430
430
|
/** Prose a human has to act on — a draft form still 403s every submission. */
|
|
431
431
|
notes?: string[];
|
|
432
|
+
/**
|
|
433
|
+
* Every form on the site after this run, and the file its `<form>` is in — wired now, or by an
|
|
434
|
+
* earlier run. The server matches the file to the component recorded as that file's owner, so
|
|
435
|
+
* the Forms tab can say which component renders each form. OPTIONAL and ADDITIVE: `wired` stays
|
|
436
|
+
* a number, and a receipt without this list still adds up.
|
|
437
|
+
*/
|
|
438
|
+
wiredForms?: {
|
|
439
|
+
id: string;
|
|
440
|
+
file: string;
|
|
441
|
+
}[];
|
|
432
442
|
}
|
|
433
443
|
/** Raised when the receipt does not account for every form. Never caught inside this package. */
|
|
434
444
|
declare class FormInvariantError extends Error {
|
|
@@ -956,7 +966,7 @@ declare function isKnownHelper(content: string, dialect: Dialect): number | null
|
|
|
956
966
|
* renderer's constant occurs in it byte for byte, which is the only thing that keeps the copy a
|
|
957
967
|
* copy. Change it there first, then paste it here.
|
|
958
968
|
*/
|
|
959
|
-
declare const FORM_SCRIPT = "<script>\ndocument.querySelectorAll('form[data-bcms-form]').forEach(function(f){\n f.addEventListener('submit',function(e){\n e.preventDefault();\n var msg=f.querySelector('.bcms-form-msg');\n var data={};\n // A checkboxes group posts one entry per checked box under the SAME name; the old\n // one-at-a-time assignment kept only the last, so \"pick many\" delivered one answer.\n // One checked box still arrives as a scalar \u2014 FormData cannot tell a group from a\n // lone field \u2014 which is exactly why lib/forms/validate.ts's chosenValues() accepts\n // both an array and a comma string.\n new FormData(f).forEach(function(v,k){\n if(k==='cf-turnstile-response')return;\n if(Object.prototype.hasOwnProperty.call(data,k))data[k]=(Array.isArray(data[k])?data[k]:[data[k]]).concat(v);\n else data[k]=v;\n });\n var body={data:data};\n var tok=f.querySelector('[name=\"cf-turnstile-response\"]');\n if(tok&&tok.value)body['cf-turnstile-response']=tok.value;\n fetch(f.action,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})\n .then(function(r){return r.ok;})\n .then(function(ok){if(msg){msg.hidden=false;msg.textContent=ok?(f.getAttribute('data-bcms-form-success')||'Thanks! Your submission was received.'):'Sorry, something went wrong.';}if(ok)f.reset();})\n .catch(function(){if(msg){msg.hidden=false;msg.textContent='Sorry, something went wrong.';}});\n });\n});\n</script>";
|
|
969
|
+
declare const FORM_SCRIPT = "<script>\nfunction bcmsPhone(cc,raw,trunk){var d=String(raw||'').trim();if(!d)return '';if(d.charAt(0)==='+'){var i=d.replace(/D/g,'');return i?'+'+i:'';}if(!cc)return d;var n=d.replace(/D/g,'');if(trunk&&n.charAt(0)==='0')n=n.slice(1);return n?'+'+cc+n:'';}\ndocument.querySelectorAll('form[data-bcms-form]').forEach(function(f){\n f.addEventListener('submit',function(e){\n e.preventDefault();\n var msg=f.querySelector('.bcms-form-msg');\n var data={};\n // A checkboxes group posts one entry per checked box under the SAME name; the old\n // one-at-a-time assignment kept only the last, so \"pick many\" delivered one answer.\n // One checked box still arrives as a scalar \u2014 FormData cannot tell a group from a\n // lone field \u2014 which is exactly why lib/forms/validate.ts's chosenValues() accepts\n // both an array and a comma string.\n new FormData(f).forEach(function(v,k){\n if(k==='cf-turnstile-response')return;\n if(Object.prototype.hasOwnProperty.call(data,k))data[k]=(Array.isArray(data[k])?data[k]:[data[k]]).concat(v);\n else data[k]=v;\n });\n // Country-picker phone fields post ONE key. The __country select is scaffolding: it is\n // composed into the field's own value here, AFTER collection, so a showIf that points at a\n // phone key still compares the raw digits. Then it is removed from the body.\n f.querySelectorAll('select[name$=\"__country\"]').forEach(function(sel){\n var k=sel.name.slice(0,-9);\n var o=sel.options[sel.selectedIndex];\n data[k]=bcmsPhone(o?(o.getAttribute('data-cc')||''):'',data[k],o?o.getAttribute('data-trunk')==='1':false);\n delete data[k+'__country'];\n });\n var body={data:data};\n var tok=f.querySelector('[name=\"cf-turnstile-response\"]');\n if(tok&&tok.value)body['cf-turnstile-response']=tok.value;\n fetch(f.action,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)})\n .then(function(r){return r.ok;})\n .then(function(ok){if(msg){msg.hidden=false;msg.textContent=ok?(f.getAttribute('data-bcms-form-success')||'Thanks! Your submission was received.'):'Sorry, something went wrong.';}if(ok)f.reset();})\n .catch(function(){if(msg){msg.hidden=false;msg.textContent='Sorry, something went wrong.';}});\n });\n});\n</script>";
|
|
960
970
|
/**
|
|
961
971
|
* Wire every form the brief lists, and say what could not be.
|
|
962
972
|
*
|
package/dist/index.js
CHANGED
|
@@ -6331,6 +6331,7 @@ import MagicString4 from "magic-string";
|
|
|
6331
6331
|
var WIRABLE = ["html", "astro", "jsx"];
|
|
6332
6332
|
var CONTROLS = /* @__PURE__ */ new Set(["input", "select", "textarea"]);
|
|
6333
6333
|
var FORM_SCRIPT = `<script>
|
|
6334
|
+
function bcmsPhone(cc,raw,trunk){var d=String(raw||'').trim();if(!d)return '';if(d.charAt(0)==='+'){var i=d.replace(/D/g,'');return i?'+'+i:'';}if(!cc)return d;var n=d.replace(/D/g,'');if(trunk&&n.charAt(0)==='0')n=n.slice(1);return n?'+'+cc+n:'';}
|
|
6334
6335
|
document.querySelectorAll('form[data-bcms-form]').forEach(function(f){
|
|
6335
6336
|
f.addEventListener('submit',function(e){
|
|
6336
6337
|
e.preventDefault();
|
|
@@ -6346,6 +6347,15 @@ document.querySelectorAll('form[data-bcms-form]').forEach(function(f){
|
|
|
6346
6347
|
if(Object.prototype.hasOwnProperty.call(data,k))data[k]=(Array.isArray(data[k])?data[k]:[data[k]]).concat(v);
|
|
6347
6348
|
else data[k]=v;
|
|
6348
6349
|
});
|
|
6350
|
+
// Country-picker phone fields post ONE key. The __country select is scaffolding: it is
|
|
6351
|
+
// composed into the field's own value here, AFTER collection, so a showIf that points at a
|
|
6352
|
+
// phone key still compares the raw digits. Then it is removed from the body.
|
|
6353
|
+
f.querySelectorAll('select[name$="__country"]').forEach(function(sel){
|
|
6354
|
+
var k=sel.name.slice(0,-9);
|
|
6355
|
+
var o=sel.options[sel.selectedIndex];
|
|
6356
|
+
data[k]=bcmsPhone(o?(o.getAttribute('data-cc')||''):'',data[k],o?o.getAttribute('data-trunk')==='1':false);
|
|
6357
|
+
delete data[k+'__country'];
|
|
6358
|
+
});
|
|
6349
6359
|
var body={data:data};
|
|
6350
6360
|
var tok=f.querySelector('[name="cf-turnstile-response"]');
|
|
6351
6361
|
if(tok&&tok.value)body['cf-turnstile-response']=tok.value;
|
|
@@ -6511,11 +6521,11 @@ async function wireForms(briefIn, sources) {
|
|
|
6511
6521
|
}
|
|
6512
6522
|
if (attrOf(candidate.el, "data-bcms-form")) {
|
|
6513
6523
|
alreadyWired++;
|
|
6514
|
-
onSite.push(form);
|
|
6524
|
+
onSite.push({ form, file: candidate.file });
|
|
6515
6525
|
continue;
|
|
6516
6526
|
}
|
|
6517
6527
|
matched.push({ form, candidate });
|
|
6518
|
-
onSite.push(form);
|
|
6528
|
+
onSite.push({ form, file: candidate.file });
|
|
6519
6529
|
}
|
|
6520
6530
|
const contents = new Map(sources.map((s) => [s.path, s.content]));
|
|
6521
6531
|
const byFile = /* @__PURE__ */ new Map();
|
|
@@ -6533,7 +6543,7 @@ ${indent}${scriptFor(last.candidate.dialect)}`);
|
|
|
6533
6543
|
}
|
|
6534
6544
|
files.push({ path, operation: "modify", content: source.toString() });
|
|
6535
6545
|
}
|
|
6536
|
-
const notes = onSite.filter((
|
|
6546
|
+
const notes = onSite.filter(({ form }) => form.status === "draft").map(({ form }) => `publish form ${form.name} in the Forms tab \u2014 a draft form rejects every submission with 403.`);
|
|
6537
6547
|
return {
|
|
6538
6548
|
files,
|
|
6539
6549
|
receipt: {
|
|
@@ -6550,7 +6560,9 @@ ${indent}${scriptFor(last.candidate.dialect)}`);
|
|
|
6550
6560
|
wired: matched.length,
|
|
6551
6561
|
alreadyWired,
|
|
6552
6562
|
pending,
|
|
6553
|
-
...notes.length > 0 ? { notes } : {}
|
|
6563
|
+
...notes.length > 0 ? { notes } : {},
|
|
6564
|
+
// Always, even empty: a run where every form went pending must retire the files an earlier one named.
|
|
6565
|
+
wiredForms: onSite.map(({ form, file }) => ({ id: form.id, file }))
|
|
6554
6566
|
})
|
|
6555
6567
|
}
|
|
6556
6568
|
};
|