improve form submission handling and frontend assets

Replace Alpine form bindings with accessible vanilla JavaScript submission states and unique field IDs. Add the bundled frontend script and Rolldown build configuration, update the generated stylesheet, and extend submission handler tests.
This commit is contained in:
2026-11-25 15:56:26 +01:00
parent a07e3ad8d9
commit 102fbc9464
8 changed files with 731 additions and 80 deletions
+133 -35
View File
@@ -9,6 +9,7 @@
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
"Courier New", monospace;
--spacing: 0.25rem;
--container-md: 28rem;
--container-2xl: 42rem;
--text-xs: 0.75rem;
--text-xs--line-height: calc(1 / 0.75);
@@ -24,12 +25,14 @@
--text-3xl--line-height: calc(2.25 / 1.875);
--text-4xl: 2.25rem;
--text-4xl--line-height: calc(2.5 / 2.25);
--text-6xl: 3.75rem;
--text-6xl--line-height: 1;
--font-weight-medium: 500;
--font-weight-semibold: 600;
--font-weight-bold: 700;
--tracking-tight: -0.025em;
--tracking-wide: 0.025em;
--radius-lg: 0.5rem;
--leading-relaxed: 1.625;
--radius-xl: 0.75rem;
--radius-2xl: 1rem;
--default-transition-duration: 150ms;
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
--default-font-family: var(--font-sans);
@@ -223,8 +226,8 @@
.mb-2 {
margin-bottom: calc(var(--spacing) * 2);
}
.mb-4 {
margin-bottom: calc(var(--spacing) * 4);
.mb-3 {
margin-bottom: calc(var(--spacing) * 3);
}
.mb-5 {
margin-bottom: calc(var(--spacing) * 5);
@@ -235,15 +238,36 @@
.ml-1 {
margin-left: var(--spacing);
}
.line-clamp-3 {
overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
.flex {
display: flex;
}
.grid {
display: grid;
}
.hidden {
display: none;
}
.table {
display: table;
}
.size-10 {
width: calc(var(--spacing) * 10);
height: calc(var(--spacing) * 10);
}
.size-11 {
width: calc(var(--spacing) * 11);
height: calc(var(--spacing) * 11);
}
.size-14 {
width: calc(var(--spacing) * 14);
height: calc(var(--spacing) * 14);
}
.h-16 {
height: calc(var(--spacing) * 16);
}
@@ -268,15 +292,30 @@
.max-w-2xl {
max-width: var(--container-2xl);
}
.max-w-72 {
max-width: calc(var(--spacing) * 72);
}
.max-w-md {
max-width: var(--container-md);
}
.min-w-40 {
min-width: calc(var(--spacing) * 40);
}
.min-w-\[36rem\] {
min-width: 36rem;
}
.min-w-\[48rem\] {
min-width: 48rem;
}
.min-w-full {
min-width: 100%;
}
.flex-1 {
flex: 1;
}
.shrink-0 {
flex-shrink: 0;
}
.cursor-grab {
cursor: grab;
}
@@ -292,6 +331,9 @@
.flex-wrap {
flex-wrap: wrap;
}
.place-items-center {
place-items: center;
}
.items-center {
align-items: center;
}
@@ -319,6 +361,9 @@
.gap-4 {
gap: calc(var(--spacing) * 4);
}
.gap-5 {
gap: calc(var(--spacing) * 5);
}
:where(.space-y-1 > :not(:last-child)) {
--tw-space-y-reverse: 0;
margin-block-start: calc(var(--spacing) * var(--tw-space-y-reverse));
@@ -329,11 +374,6 @@
margin-block-start: calc(calc(var(--spacing) * 2) * var(--tw-space-y-reverse));
margin-block-end: calc(calc(var(--spacing) * 2) * calc(1 - var(--tw-space-y-reverse)));
}
:where(.space-y-3 > :not(:last-child)) {
--tw-space-y-reverse: 0;
margin-block-start: calc(calc(var(--spacing) * 3) * var(--tw-space-y-reverse));
margin-block-end: calc(calc(var(--spacing) * 3) * calc(1 - var(--tw-space-y-reverse)));
}
:where(.space-y-4 > :not(:last-child)) {
--tw-space-y-reverse: 0;
margin-block-start: calc(calc(var(--spacing) * 4) * var(--tw-space-y-reverse));
@@ -344,17 +384,25 @@
margin-block-start: calc(calc(var(--spacing) * 5) * var(--tw-space-y-reverse));
margin-block-end: calc(calc(var(--spacing) * 5) * calc(1 - var(--tw-space-y-reverse)));
}
:where(.space-y-6 > :not(:last-child)) {
--tw-space-y-reverse: 0;
margin-block-start: calc(calc(var(--spacing) * 6) * var(--tw-space-y-reverse));
margin-block-end: calc(calc(var(--spacing) * 6) * calc(1 - var(--tw-space-y-reverse)));
}
.self-start {
align-self: flex-start;
}
.overflow-x-auto {
overflow-x: auto;
}
.rounded {
border-radius: 0.25rem;
.rounded-2xl {
border-radius: var(--radius-2xl);
}
.rounded-full {
border-radius: calc(infinity * 1px);
}
.rounded-lg {
border-radius: var(--radius-lg);
.rounded-xl {
border-radius: var(--radius-xl);
}
.border {
border-style: var(--tw-border-style);
@@ -364,6 +412,10 @@
border-style: var(--tw-border-style);
border-width: 2px;
}
.border-t {
border-top-style: var(--tw-border-style);
border-top-width: 1px;
}
.border-b {
border-bottom-style: var(--tw-border-style);
border-bottom-width: 1px;
@@ -376,15 +428,12 @@
--tw-border-style: dashed;
border-style: dashed;
}
.p-0 {
padding: 0px;
}
.p-2 {
padding: calc(var(--spacing) * 2);
}
.p-3 {
padding: calc(var(--spacing) * 3);
}
.p-4 {
padding: calc(var(--spacing) * 4);
}
.px-0 {
padding-inline: 0px;
}
@@ -394,26 +443,32 @@
.px-4 {
padding-inline: calc(var(--spacing) * 4);
}
.px-5 {
padding-inline: calc(var(--spacing) * 5);
}
.py-2 {
padding-block: calc(var(--spacing) * 2);
}
.py-8 {
padding-block: calc(var(--spacing) * 8);
}
.py-16 {
padding-block: calc(var(--spacing) * 16);
.py-10 {
padding-block: calc(var(--spacing) * 10);
}
.pt-2 {
padding-top: calc(var(--spacing) * 2);
.py-12 {
padding-block: calc(var(--spacing) * 12);
}
.pt-4 {
padding-top: calc(var(--spacing) * 4);
}
.pt-5 {
padding-top: calc(var(--spacing) * 5);
}
.pb-4 {
padding-bottom: calc(var(--spacing) * 4);
}
.pl-3 {
padding-left: calc(var(--spacing) * 3);
}
.pl-8 {
padding-left: calc(var(--spacing) * 8);
.pb-5 {
padding-bottom: calc(var(--spacing) * 5);
}
.text-center {
text-align: center;
@@ -436,10 +491,6 @@
font-size: var(--text-4xl);
line-height: var(--tw-leading, var(--text-4xl--line-height));
}
.text-6xl {
font-size: var(--text-6xl);
line-height: var(--tw-leading, var(--text-6xl--line-height));
}
.text-lg {
font-size: var(--text-lg);
line-height: var(--tw-leading, var(--text-lg--line-height));
@@ -456,6 +507,10 @@
font-size: var(--text-xs);
line-height: var(--tw-leading, var(--text-xs--line-height));
}
.leading-relaxed {
--tw-leading: var(--leading-relaxed);
line-height: var(--leading-relaxed);
}
.font-bold {
--tw-font-weight: var(--font-weight-bold);
font-weight: var(--font-weight-bold);
@@ -464,10 +519,25 @@
--tw-font-weight: var(--font-weight-medium);
font-weight: var(--font-weight-medium);
}
.font-semibold {
--tw-font-weight: var(--font-weight-semibold);
font-weight: var(--font-weight-semibold);
}
.tracking-\[0\.18em\] {
--tw-tracking: 0.18em;
letter-spacing: 0.18em;
}
.tracking-tight {
--tw-tracking: var(--tracking-tight);
letter-spacing: var(--tracking-tight);
}
.tracking-wide {
--tw-tracking: var(--tracking-wide);
letter-spacing: var(--tracking-wide);
}
.break-words {
overflow-wrap: break-word;
}
.uppercase {
text-transform: uppercase;
}
@@ -496,14 +566,37 @@
.sm\:items-center {
align-items: center;
}
.sm\:items-end {
align-items: flex-end;
}
.sm\:justify-between {
justify-content: space-between;
}
.sm\:justify-end {
justify-content: flex-end;
}
.sm\:pl-4 {
padding-left: calc(var(--spacing) * 4);
.sm\:self-center {
align-self: center;
}
.sm\:p-4 {
padding: calc(var(--spacing) * 4);
}
.sm\:p-5 {
padding: calc(var(--spacing) * 5);
}
.sm\:p-6 {
padding: calc(var(--spacing) * 6);
}
.sm\:py-16 {
padding-block: calc(var(--spacing) * 16);
}
.sm\:pl-9 {
padding-left: calc(var(--spacing) * 9);
}
}
@media (width >= 64rem) {
.lg\:p-8 {
padding: calc(var(--spacing) * 8);
}
}
}
@@ -668,6 +761,10 @@
inherits: false;
initial-value: solid;
}
@property --tw-leading {
syntax: "*";
inherits: false;
}
@property --tw-font-weight {
syntax: "*";
inherits: false;
@@ -746,6 +843,7 @@
*, ::before, ::after, ::backdrop {
--tw-space-y-reverse: 0;
--tw-border-style: solid;
--tw-leading: initial;
--tw-font-weight: initial;
--tw-tracking: initial;
--tw-shadow: 0 0 #0000;
+1
View File
@@ -0,0 +1 @@
(()=>{let e=`Your submission could not be completed. Please try again.`;function t(e,t){e&&(e.hidden=!t,e.classList.toggle(`hidden`,!t))}function n(e){let t=Array.from(e.querySelectorAll(`input[type="checkbox"]`));t.length!==0&&(t[0].required=!t.some(e=>e.checked))}function r(e){let t={},n=Array.from(e.querySelectorAll(`input[name], select[name], textarea[name]`)).filter(e=>!e.matches(`:disabled`)),r=/* @__PURE__ */ new Map;return n.forEach(e=>{e instanceof HTMLInputElement&&[`button`,`submit`,`reset`,`image`].includes(e.type)||(r.has(e.name)||r.set(e.name,[]),r.get(e.name).push(e))}),r.forEach((e,n)=>{let r=e[0];if(r instanceof HTMLInputElement&&r.type===`checkbox`)t[n]=e.filter(e=>e.checked).map(e=>e.value);else if(r instanceof HTMLInputElement&&r.type===`radio`){let r=e.find(e=>e.checked);t[n]=r?r.value:``}else t[n]=r.value}),{fields:t}}function i(e,n){let r=e.querySelector(`[data-form-submit]`),i=e.querySelector(`[data-form-submit-idle]`),a=e.querySelector(`[data-form-submit-busy]`);e.setAttribute(`aria-busy`,String(n)),r&&(r.disabled=n,r.setAttribute(`aria-busy`,String(n))),t(i,!n),t(a,n)}function a(){document.querySelectorAll(`[data-field-type="checkbox"][data-field-required="true"]`).forEach(n)}document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,a,{once:!0}):a(),document.addEventListener(`change`,e=>{if(!(e.target instanceof HTMLInputElement)||e.target.type!==`checkbox`)return;let t=e.target.closest(`[data-field-type="checkbox"][data-field-required="true"]`);t&&n(t)}),document.addEventListener(`submit`,async n=>{let a=n.target;if(!(a instanceof HTMLFormElement)||!a.matches(`[data-form-wrapper]`)||(n.preventDefault(),a.dataset.submitting===`true`))return;a.dataset.submitting=`true`;let o=a.parentElement,s=o.querySelector(`[data-form-error]`),c=o.querySelector(`[data-form-success]`);t(s,!1),s&&(s.textContent=``),i(a,!0);try{let n=await fetch(`/ext--form/submit?id=${encodeURIComponent(a.dataset.formId)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(r(a))}),i=await n.json();if(!n.ok||!i||!i.success){let t=i&&Array.isArray(i.errors)?i.errors.join(` `):``;throw Error(t||e)}a.hidden=!0,a.classList.add(`hidden`),t(c,!0)}catch(n){s&&(s.textContent=n instanceof Error&&n.message?n.message:e,t(s,!0))}finally{i(a,!1),delete a.dataset.submitting}})})();
+145
View File
@@ -0,0 +1,145 @@
(() => {
const defaultErrorMessage = 'Your submission could not be completed. Please try again.';
function setVisible(element, visible) {
if (!element) {
return;
}
element.hidden = !visible;
element.classList.toggle('hidden', !visible);
}
function updateCheckboxGroupRequired(group) {
const checkboxes = Array.from(group.querySelectorAll('input[type="checkbox"]'));
if (checkboxes.length === 0) {
return;
}
checkboxes[0].required = !checkboxes.some(checkbox => checkbox.checked);
}
function collectFields(form) {
const fields = {};
const controls = Array.from(form.querySelectorAll('input[name], select[name], textarea[name]'))
.filter(control => !control.matches(':disabled'));
const groups = new Map();
controls.forEach(control => {
if (control instanceof HTMLInputElement && ['button', 'submit', 'reset', 'image'].includes(control.type)) {
return;
}
if (!groups.has(control.name)) {
groups.set(control.name, []);
}
groups.get(control.name).push(control);
});
groups.forEach((groupControls, name) => {
const firstControl = groupControls[0];
if (firstControl instanceof HTMLInputElement && firstControl.type === 'checkbox') {
fields[name] = groupControls
.filter(control => control.checked)
.map(control => control.value);
return;
}
if (firstControl instanceof HTMLInputElement && firstControl.type === 'radio') {
const selectedControl = groupControls.find(control => control.checked);
fields[name] = selectedControl ? selectedControl.value : '';
return;
}
fields[name] = firstControl.value;
});
return { fields };
}
function setBusy(form, busy) {
const submitButton = form.querySelector('[data-form-submit]');
const idleContent = form.querySelector('[data-form-submit-idle]');
const busyContent = form.querySelector('[data-form-submit-busy]');
form.setAttribute('aria-busy', String(busy));
if (submitButton) {
submitButton.disabled = busy;
submitButton.setAttribute('aria-busy', String(busy));
}
setVisible(idleContent, !busy);
setVisible(busyContent, busy);
}
function initializeCheckboxGroups() {
document.querySelectorAll('[data-field-type="checkbox"][data-field-required="true"]')
.forEach(updateCheckboxGroupRequired);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeCheckboxGroups, { once: true });
} else {
initializeCheckboxGroups();
}
document.addEventListener('change', event => {
if (!(event.target instanceof HTMLInputElement) || event.target.type !== 'checkbox') {
return;
}
const group = event.target.closest('[data-field-type="checkbox"][data-field-required="true"]');
if (group) {
updateCheckboxGroupRequired(group);
}
});
document.addEventListener('submit', async event => {
const form = event.target;
if (!(form instanceof HTMLFormElement) || !form.matches('[data-form-wrapper]')) {
return;
}
event.preventDefault();
if (form.dataset.submitting === 'true') {
return;
}
form.dataset.submitting = 'true';
const formContainer = form.parentElement;
const errorMessage = formContainer.querySelector('[data-form-error]');
const successMessage = formContainer.querySelector('[data-form-success]');
setVisible(errorMessage, false);
if (errorMessage) {
errorMessage.textContent = '';
}
setBusy(form, true);
try {
const response = await fetch(`/ext--form/submit?id=${encodeURIComponent(form.dataset.formId)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(collectFields(form))
});
const result = await response.json();
if (!response.ok || !result || !result.success) {
const errors = result && Array.isArray(result.errors) ? result.errors.join(' ') : '';
throw new Error(errors || defaultErrorMessage);
}
form.hidden = true;
form.classList.add('hidden');
setVisible(successMessage, true);
} catch (error) {
if (errorMessage) {
errorMessage.textContent = error instanceof Error && error.message
? error.message
: defaultErrorMessage;
setVisible(errorMessage, true);
}
} finally {
setBusy(form, false);
delete form.dataset.submitting;
}
});
})();
@@ -5,44 +5,27 @@ if ($id > 0):
$form = $formRepository->findWithId($id);
$fields = json_decode($form["fields"], true);
$formInstanceId = uniqid("form-$id-");
?>
<div class="mx-auto w-full max-w-2xl">
<div x-data="{data: {fields : {}}, status: 'idle', submitted: false, errorMessage: ''}" class="space-y-4">
<form x-show="!submitted" x-transition:leave x-transition:leave-opacity-0 x-on:submit.prevent="
status = 'busy';
errorMessage = '';
try {
const response = await fetch('/ext--form/submit?id=<?= $id ?>', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(data)
});
const result = await response.json();
if (!response.ok || !result.success) {
throw new Error((result.errors || []).join(' ') || 'Your submission could not be completed. Please try again.');
}
submitted = true;
} catch (error) {
errorMessage = error.message || 'Your submission could not be completed. Please try again.';
} finally {
status = 'idle';
}
">
<?php foreach ($fields as $field):
<div class="space-y-4">
<form data-form-wrapper data-form-id="<?= phpb_e($id) ?>" aria-busy="false">
<?php foreach ($fields as $fieldIndex => $field):
$fieldName = $field["name"];
$fieldLabel = $field["label"];
$fieldType = $field["type"];
$fieldId = $formInstanceId . "-field-" . (int) $fieldIndex;
$fieldRequired =
isset($field["required"]) && $field["required"];
$fieldOptions = isset($field["options"])
? $field["options"]
: [];
?>
<div class="form-control mb-5">
<?php if ($fieldType === "checkbox" || $fieldType === "radio"): ?>
<fieldset class="space-y-2">
?>
<div class="form-control mb-5">
<?php if ($fieldType === "checkbox" || $fieldType === "radio"): ?>
<fieldset class="space-y-2" data-field-type="<?= phpb_e($fieldType) ?>" data-field-required="<?= $fieldRequired ? "true" : "false" ?>">
<legend class="label mb-1 px-0">
<span class="label-text font-medium">
<?= phpb_e($fieldLabel) ?>
@@ -53,7 +36,7 @@ if ($id > 0):
</span>
</legend>
<?php else: ?>
<label for="form-field-<?= phpb_e($fieldName) ?>" class="label mb-1 px-0">
<label for="<?= phpb_e($fieldId) ?>" class="label mb-1 px-0">
<span class="label-text font-medium">
<?= phpb_e($fieldLabel) ?>
<?php if ($fieldRequired): ?>
@@ -64,7 +47,7 @@ if ($id > 0):
</label>
<?php endif; ?>
<?php if ($fieldType === "select"): ?>
<select id="form-field-<?= phpb_e($fieldName) ?>" x-model="data.fields.<?= $fieldName ?>" class="select select-bordered w-full" <?= $fieldRequired
<select id="<?= phpb_e($fieldId) ?>" name="<?= phpb_e($fieldName) ?>" class="select select-bordered w-full" <?= $fieldRequired
? "required"
: "" ?>>
<option value="" disabled selected>Please select</option>
@@ -76,11 +59,11 @@ if ($id > 0):
</select>
<?php elseif ($fieldType === "checkbox"): ?>
<div class="space-y-2">
<?php foreach ($fieldOptions as $option): ?>
<?php foreach ($fieldOptions as $optionIndex => $option): ?>
<label class="label cursor-pointer justify-start gap-3 rounded-box border border-base-300 px-3 py-2">
<input type="checkbox" value="<?= phpb_e($option[
<input type="checkbox" name="<?= phpb_e($fieldName) ?>" value="<?= phpb_e($option[
"value"
]) ?>" x-model="data.fields.<?= $fieldName ?>" class="checkbox checkbox-sm checkbox-primary" />
]) ?>" <?= $fieldRequired && $optionIndex === 0 ? "required" : "" ?> class="checkbox checkbox-sm checkbox-primary" />
<span class="label-text"><?= phpb_e($option[
"label"
]) ?></span>
@@ -89,11 +72,11 @@ if ($id > 0):
</div>
<?php elseif ($fieldType === "radio"): ?>
<div class="space-y-2">
<?php foreach ($fieldOptions as $option): ?>
<?php foreach ($fieldOptions as $optionIndex => $option): ?>
<label class="label cursor-pointer justify-start gap-3 rounded-box border border-base-300 px-3 py-2">
<input type="radio" name="<?= phpb_e($fieldName) ?>" value="<?= phpb_e($option[
<input type="radio" id="<?= phpb_e($fieldId) ?>-<?= (int) $optionIndex ?>" name="<?= phpb_e($fieldName) ?>" value="<?= phpb_e($option[
"value"
]) ?>" x-model="data.fields.<?= $fieldName ?>" class="radio radio-sm radio-primary" />
]) ?>" <?= $fieldRequired && $optionIndex === 0 ? "required" : "" ?> class="radio radio-sm radio-primary" />
<span class="label-text"><?= phpb_e($option[
"label"
]) ?></span>
@@ -101,11 +84,11 @@ if ($id > 0):
<?php endforeach; ?>
</div>
<?php elseif ($fieldType === "textarea"): ?>
<textarea id="form-field-<?= phpb_e($fieldName) ?>" x-model="data.fields.<?= $fieldName ?>" class="textarea textarea-bordered w-full" placeholder="<?= phpb_e($fieldLabel) ?>" <?= $fieldRequired
<textarea id="<?= phpb_e($fieldId) ?>" name="<?= phpb_e($fieldName) ?>" class="textarea textarea-bordered w-full" placeholder="<?= phpb_e($fieldLabel) ?>" <?= $fieldRequired
? "required"
: "" ?> rows="4"></textarea>
<?php else: ?>
<input id="form-field-<?= phpb_e($fieldName) ?>" type="<?= phpb_e($fieldType) ?>" x-model="data.fields.<?= $fieldName ?>" class="input input-bordered w-full" placeholder="<?= phpb_e($fieldLabel) ?>" <?= $fieldRequired
<input id="<?= phpb_e($fieldId) ?>" name="<?= phpb_e($fieldName) ?>" type="<?= phpb_e($fieldType) ?>" class="input input-bordered w-full" placeholder="<?= phpb_e($fieldLabel) ?>" <?= $fieldRequired
? "required"
: "" ?>>
<?php endif; ?>
@@ -116,20 +99,20 @@ if ($id > 0):
<?php
endforeach; ?>
<div class="mt-6">
<button type="submit" class="btn btn-primary w-full" :disabled="status === 'busy'" :aria-busy="status === 'busy'">
<span x-show="status === 'idle'" aria-live="polite">
<button type="submit" class="btn btn-primary w-full" data-form-submit aria-busy="false">
<span data-form-submit-idle aria-live="polite">
<i class="ph-duotone ph-paper-plane-tilt" aria-hidden="true"></i>
Submit
</span>
<span x-show="status === 'busy'" role="status" aria-live="polite">
<span data-form-submit-busy class="hidden" hidden role="status" aria-live="polite">
<span class="loading loading-spinner loading-sm" aria-hidden="true"></span>
Sending...
</span>
</button>
</div>
</form>
<div x-show="errorMessage" x-text="errorMessage" class="alert alert-error mt-4 shadow-sm" role="alert" aria-live="assertive" aria-atomic="true"></div>
<div x-show="submitted" x-transition:enter x-transition:enter-opacity-0 x-transition:enter-delay-100 class="card mt-4 border border-success/30 bg-base-100 shadow-sm" role="status" aria-live="polite">
<div data-form-error class="alert alert-error mt-4 shadow-sm hidden" hidden role="alert" aria-live="assertive" aria-atomic="true"></div>
<div data-form-success class="card mt-4 border border-success/30 bg-base-100 shadow-sm hidden" hidden role="status" aria-live="polite">
<div class="card-body items-center text-center">
<div class="mb-2 flex h-16 w-16 items-center justify-center rounded-full bg-success/20">
<i class="ph-duotone ph-check text-3xl text-success" aria-hidden="true"></i>
+5
View File
@@ -20,6 +20,11 @@ return [
"type" => "style",
"location" => "header",
],
[
"src" => "/assets/dist.js",
"type" => "script",
"location" => "footer",
],
],
"tables" => [
"entries" => [
+405 -1
View File
@@ -1,5 +1,5 @@
{
"name": "dev_plugi-ext-form",
"name": "plugi-ext-form",
"lockfileVersion": 3,
"requires": true,
"packages": {
@@ -7,6 +7,43 @@
"dependencies": {
"@tailwindcss/cli": "^4.3.5",
"tailwindcss": "^4.3.5"
},
"devDependencies": {
"rolldown": "^1.3.3"
}
},
"node_modules/@emnapi/core": {
"version": "2.0.0-beta.2",
"resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz",
"integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"@emnapi/wasi-threads": "2.2.0",
"tslib": "^2.4.0"
}
},
"node_modules/@emnapi/runtime": {
"version": "2.0.0-beta.2",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz",
"integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/@emnapi/wasi-threads": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz",
"integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
@@ -54,6 +91,38 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@napi-rs/wasm-runtime": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz",
"integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"@tybys/wasm-util": "^0.10.3"
},
"engines": {
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
},
"funding": {
"type": "github",
"url": "https://github.com/sponsors/Brooooooklyn"
},
"peerDependencies": {
"@emnapi/core": "^1.7.1 || 2.0.0-beta.2",
"@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2"
}
},
"node_modules/@oxc-project/types": {
"version": "0.159.0",
"resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.159.0.tgz",
"integrity": "sha512-QWjWhxheluOJ82kDHNyps00UvRpQCtI34B5A/SzpgQycUD/79FuvT4I0aQIfE/bdPwKmX4QPftnywFBH6FxJhQ==",
"dev": true,
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/oxc-project"
}
},
"node_modules/@parcel/watcher": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.6.0.tgz",
@@ -328,6 +397,287 @@
"url": "https://opencollective.com/parcel"
}
},
"node_modules/@rolldown/binding-android-arm-eabi": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.3.3.tgz",
"integrity": "sha512-K1itOg1Xl50XyjLDa4qQZqaYsfiQbFbFRWXOEOupOsGr3whhm5ed4lgySd6Inohv2TB0+sdU4AxORKuS/TGang==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-android-arm64": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.3.3.tgz",
"integrity": "sha512-re+E0E3YSJXjEFzdOvBgkVUev1Gg49ileia04qy+Djn0lIMBr7pnwVOYQ+4vc9XbLClCmMziasqXHM7KTmKNKQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"android"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-darwin-arm64": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.3.3.tgz",
"integrity": "sha512-6pMLYsUiQJXPkUj/CG447hOBKtbe+hjWw/wbxe/mucoPKgnLSVRTzey7s0kXfqrjxhDd3gQ2hj6lgUKRumsIzw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-darwin-x64": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.3.3.tgz",
"integrity": "sha512-Lz+TskwvhceQgwnP+0ox5ZeL7HDDXHKWVRpOqC1Eo05y6rYyfvvep0msGqC95kQTykXrmGgP6qwJB1NdgNZVhg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-freebsd-x64": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.3.3.tgz",
"integrity": "sha512-sIzqNDbA7GFDXU8k9/vcJyV1p45mCe+xHOLo9qD7gdbTbMlwB+SpnFoP7WSpC2iYdGfOX9pjBxCfViRn/Nu3Jw==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-arm-gnueabihf": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.3.3.tgz",
"integrity": "sha512-HYysnZZ7HD3FM5RIBN6wDMoxtOjw4LS9HhRuQ57MsZt5XGpGRPxVpplvr7vUXRN+9MD8zb6vn1JRP06PXIuMYQ==",
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-arm64-gnu": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.3.3.tgz",
"integrity": "sha512-XAyLqWSoEKVc8wsDbCIz5o2sBY6ye+0YByK9ib5QxFReoM1KHyThSHsdUODa1DKNzlEfae+p9QwK62LsVwo6Nw==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-arm64-musl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.3.3.tgz",
"integrity": "sha512-oVyicDPj6vUVFRnuoQS7M2Ab8EkGWoq3a5ntyQqjtZoXfgVykIJqN2IAJSi9q9UyNoQUW0vbBLQSgGtlPJ40Kg==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-ppc64-gnu": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.3.3.tgz",
"integrity": "sha512-k7aFSWgUoi/X7jCst7UEof7pS5jc5ymD8mT/pdFE+pO1IBBI2+JU5Os4HEDqS/tYhetRggwM7MOiLP3cg1bSBQ==",
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-s390x-gnu": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.3.3.tgz",
"integrity": "sha512-D5mxHpr1qIb1Pt5UT+Bm2p6vJ7+VxcxWcxZCYVDFzZwWRq9iLiEg4/ROsaXFQl1O8sDQZZJ55UoRWWMK64uH5w==",
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-x64-gnu": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.3.3.tgz",
"integrity": "sha512-nmW1O4BbNEmQI9+KTHbJgbDv0EuyZy64oBnRlMCtLJ8lQMIJ/H/iziQ0g2IUlHEhNrSebGvs9cRrlRj8oEfP+g==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-linux-x64-musl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.3.3.tgz",
"integrity": "sha512-ivU4JFHK5nFzrRbzp3+vwYdLj8mFckH4oz3hEl5LH/YeThr9/m2N2vF3NvLevtHq6e0COimgrEVyYTwQhh4ODg==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-openharmony-arm64": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.3.3.tgz",
"integrity": "sha512-XxZoRIkNZ/7pFgvOA8QJmx3uFjMyVz7zS2/urzlaFffoOGclDvpUAMu3AHKT551E8JBKXLxIjpYxYMdF6Mz9vQ==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"openharmony"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-wasm32-wasi": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.3.3.tgz",
"integrity": "sha512-bBl1MB2gF26PSPy3CiDLiv+A6JGI546WbsDR34LfKAywSGeBeQXaDanoDG6QdZDJs53M1QyJir5MTKTu1n4ptA==",
"cpu": [
"wasm32"
],
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"@emnapi/core": "2.0.0-beta.2",
"@emnapi/runtime": "2.0.0-beta.2",
"@napi-rs/wasm-runtime": "1.2.6"
},
"engines": {
"node": "^20.19.0 || ^22.13.0 || >=23.5.0"
}
},
"node_modules/@rolldown/binding-win32-arm64-msvc": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.3.3.tgz",
"integrity": "sha512-6rZur0hyen4LPhOxWIg7az1YX+Eo8Vvauc0D6lFYGK/QCvN+1XpnB8aFe3jQc/PBUGIReJJnLX3sS8h33/5v7A==",
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/binding-win32-x64-msvc": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.3.3.tgz",
"integrity": "sha512-Ggzyuq1mN7claruAZH10aiiM1N3LRCoMP5xDXPdU514ulL0D2bksCWgFqEmEM2/pDzEP7Dq+dcv7IH452jtr1w==",
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
}
},
"node_modules/@rolldown/pluginutils": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz",
"integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==",
"dev": true,
"license": "MIT"
},
"node_modules/@tailwindcss/cli": {
"version": "4.3.5",
"resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.3.5.tgz",
@@ -649,6 +999,17 @@
"node": ">= 20"
}
},
"node_modules/@tybys/wasm-util": {
"version": "0.10.5",
"resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz",
"integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==",
"dev": true,
"license": "MIT",
"optional": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/detect-libc": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
@@ -998,6 +1359,41 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/rolldown": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.3.3.tgz",
"integrity": "sha512-ksB1g74e7haRy02OYm4lOQAlr6sK6hBpAY5R+YC30Gkv4L1COwF6M9umBAYAPxWpGow6Vr+IXtyDjH9fq7A+Zg==",
"dev": true,
"license": "MIT",
"dependencies": {
"@oxc-project/types": "=0.159.0",
"@rolldown/pluginutils": "^1.0.0"
},
"bin": {
"rolldown": "bin/cli.mjs"
},
"engines": {
"node": "^20.19.0 || >=22.12.0"
},
"optionalDependencies": {
"@rolldown/binding-android-arm-eabi": "1.3.3",
"@rolldown/binding-android-arm64": "1.3.3",
"@rolldown/binding-darwin-arm64": "1.3.3",
"@rolldown/binding-darwin-x64": "1.3.3",
"@rolldown/binding-freebsd-x64": "1.3.3",
"@rolldown/binding-linux-arm-gnueabihf": "1.3.3",
"@rolldown/binding-linux-arm64-gnu": "1.3.3",
"@rolldown/binding-linux-arm64-musl": "1.3.3",
"@rolldown/binding-linux-ppc64-gnu": "1.3.3",
"@rolldown/binding-linux-s390x-gnu": "1.3.3",
"@rolldown/binding-linux-x64-gnu": "1.3.3",
"@rolldown/binding-linux-x64-musl": "1.3.3",
"@rolldown/binding-openharmony-arm64": "1.3.3",
"@rolldown/binding-wasm32-wasi": "1.3.3",
"@rolldown/binding-win32-arm64-msvc": "1.3.3",
"@rolldown/binding-win32-x64-msvc": "1.3.3"
}
},
"node_modules/source-map-js": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz",
@@ -1025,6 +1421,14 @@
"type": "opencollective",
"url": "https://opencollective.com/webpack"
}
},
"node_modules/tslib": {
"version": "2.9.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
"integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
"dev": true,
"license": "0BSD",
"optional": true
}
}
}
+7 -1
View File
@@ -1,10 +1,16 @@
{
"type": "module",
"dependencies": {
"@tailwindcss/cli": "^4.3.5",
"tailwindcss": "^4.3.5"
},
"devDependencies": {
"rolldown": "^1.3.3"
},
"scripts": {
"dev": "npx -y @tailwindcss/cli -i ./assets/main.css -o ./assets/dist.css --watch",
"build": "npx -y @tailwindcss/cli -i ./assets/main.css -o ./assets/dist.css"
"build": "npm run build:js && npm run build:css",
"build:css": "npx -y @tailwindcss/cli -i ./assets/main.css -o ./assets/dist.css",
"build:js": "rolldown assets/main.js --file assets/dist.js -m"
}
}
@@ -256,12 +256,21 @@ namespace {
assertSameValue(422, $result['status'], 'Malformed action options must be rejected');
$view = file_get_contents(dirname(__DIR__) . '/blocks/form-wrapper/view.php');
if (strpos($view, '!response.ok || !result.success') === false || strpos($view, 'x-show="errorMessage"') === false) {
$frontendScript = file_get_contents(dirname(__DIR__) . '/assets/main.js');
if (strpos($view, 'data-form-wrapper') === false || preg_match('/\bx-(?:data|model|show|on|transition|text)\b/', $view) === 1) {
throw new \RuntimeException('The public form wrapper must use vanilla JavaScript hooks without Alpine directives.');
}
if (strpos($frontendScript, 'if (!response.ok || !result || !result.success)') === false || strpos($frontendScript, 'setVisible(errorMessage, true)') === false) {
throw new \RuntimeException('The frontend must check the response and expose a retryable error state.');
}
if (preg_match('/if \(!response\.ok \|\| !result\.success\).*?submitted = true;/s', $view) !== 1) {
$responseCheck = strpos($frontendScript, 'if (!response.ok || !result || !result.success)');
$successState = strpos($frontendScript, 'setVisible(successMessage, true)');
if ($successState === false || $responseCheck === false || $responseCheck > $successState) {
throw new \RuntimeException('The frontend may only show its success state after a successful response.');
}
if (strpos($frontendScript, 'finally') === false || strpos($frontendScript, 'setBusy(form, false)') === false) {
throw new \RuntimeException('The frontend must restore its busy state after a submission attempt.');
}
$editor = file_get_contents(dirname(__DIR__) . '/admin/Views/EditForm.php');
foreach (['finisherDefinitions', 'getFinisherSettings', 'finisher.options[setting.name]', 'setting.type'] as $setting) {