gyosjs 0.2.1 → 0.2.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/README.md +1 -1
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/form/form-submission.d.ts +6 -0
- package/dist/form/form-submission.d.ts.map +1 -0
- package/dist/form/form-validation.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +143 -19
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +143 -19
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.esm.js +143 -19
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +143 -19
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/template/model.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ GyosJS is not trying to replace a full SPA framework. If your app is primarily c
|
|
|
33
33
|
Use the browser auto-init build when you want HTML-first usage with minimal setup.
|
|
34
34
|
|
|
35
35
|
```html
|
|
36
|
-
<script src="https://cdn.jsdelivr.net/npm/gyosjs@0.2.
|
|
36
|
+
<script src="https://cdn.jsdelivr.net/npm/gyosjs@0.2.2/dist/gyos.auto.min.js"></script>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
That build attaches `window.Gyos`, starts the router when `g-boost` exists, injects transition styles, and mounts scopes when the page is ready.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,aAAa;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,eAAe;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IAC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D;AA+JD,iBAAS,gBAAgB,IAAI,IAAI,CAsBhC;AAGD,eAAO,MAAM,YAAY;;;;;;CAMxB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function registerValidatedForm(form: HTMLFormElement): void;
|
|
2
|
+
export declare function unregisterValidatedForm(form: HTMLFormElement): void;
|
|
3
|
+
export declare function approveNextFormSubmission(form: HTMLFormElement): void;
|
|
4
|
+
export declare function cancelApprovedFormSubmission(form: HTMLFormElement): void;
|
|
5
|
+
export declare function shouldDeferToFormValidation(form: HTMLFormElement): boolean;
|
|
6
|
+
//# sourceMappingURL=form-submission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-submission.d.ts","sourceRoot":"","sources":["../../src/form/form-submission.ts"],"names":[],"mappings":"AAMA,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAEjE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAGnE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAErE;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAExE;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAO1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-validation.d.ts","sourceRoot":"","sources":["../../src/form/form-validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"form-validation.d.ts","sourceRoot":"","sources":["../../src/form/form-validation.ts"],"names":[],"mappings":"AAqGA;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAmI5E;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CA6F9D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,CAiD5D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI,CAqBzE"}
|
package/dist/gyos.auto.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.2.
|
|
2
|
+
* GyosJS v0.2.2
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -3018,6 +3018,33 @@ validator('between', (value, min, max) => {
|
|
|
3018
3018
|
return (num >= minVal && num <= maxVal) || `Must be between ${minVal} and ${maxVal}`;
|
|
3019
3019
|
});
|
|
3020
3020
|
|
|
3021
|
+
const managedForms = new WeakSet();
|
|
3022
|
+
const approvedSubmissions = new WeakSet();
|
|
3023
|
+
// Coordinates the validation listener on a form with the Router's earlier
|
|
3024
|
+
// document-capture listener without exposing state on application elements.
|
|
3025
|
+
function registerValidatedForm(form) {
|
|
3026
|
+
managedForms.add(form);
|
|
3027
|
+
}
|
|
3028
|
+
function unregisterValidatedForm(form) {
|
|
3029
|
+
managedForms.delete(form);
|
|
3030
|
+
approvedSubmissions.delete(form);
|
|
3031
|
+
}
|
|
3032
|
+
function approveNextFormSubmission(form) {
|
|
3033
|
+
approvedSubmissions.add(form);
|
|
3034
|
+
}
|
|
3035
|
+
function cancelApprovedFormSubmission(form) {
|
|
3036
|
+
approvedSubmissions.delete(form);
|
|
3037
|
+
}
|
|
3038
|
+
function shouldDeferToFormValidation(form) {
|
|
3039
|
+
if (!managedForms.has(form))
|
|
3040
|
+
return false;
|
|
3041
|
+
if (approvedSubmissions.has(form)) {
|
|
3042
|
+
approvedSubmissions.delete(form);
|
|
3043
|
+
return false;
|
|
3044
|
+
}
|
|
3045
|
+
return true;
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3021
3048
|
/**
|
|
3022
3049
|
* Form Validation Directives
|
|
3023
3050
|
* Provides g-form, g-validate, and g-errors directives for reactive form validation
|
|
@@ -3032,6 +3059,23 @@ function getFieldName(el) {
|
|
|
3032
3059
|
const modelAttr = Array.from(el.attributes).find(attr => attr.name === 'g-model' || attr.name.startsWith('g-model.'));
|
|
3033
3060
|
return modelAttr?.value || el.getAttribute('name') || el.id;
|
|
3034
3061
|
}
|
|
3062
|
+
function getControlValue(el, form) {
|
|
3063
|
+
if (!(el instanceof HTMLInputElement))
|
|
3064
|
+
return el.value;
|
|
3065
|
+
if (el.type === 'checkbox')
|
|
3066
|
+
return el.checked ? el.value : '';
|
|
3067
|
+
if (el.type !== 'radio')
|
|
3068
|
+
return el.value;
|
|
3069
|
+
const fieldName = getFieldName(el);
|
|
3070
|
+
const checked = Array.from(form.querySelectorAll('input[type="radio"]')).find(candidate => {
|
|
3071
|
+
if (isInIgnoredTree(candidate) || !candidate.checked)
|
|
3072
|
+
return false;
|
|
3073
|
+
if (el.name && candidate.name === el.name)
|
|
3074
|
+
return true;
|
|
3075
|
+
return getFieldName(candidate) === fieldName;
|
|
3076
|
+
});
|
|
3077
|
+
return checked?.value ?? '';
|
|
3078
|
+
}
|
|
3035
3079
|
/**
|
|
3036
3080
|
* Get or create form validation state
|
|
3037
3081
|
*/
|
|
@@ -3083,6 +3127,7 @@ function processFormDirective(form, scope) {
|
|
|
3083
3127
|
return;
|
|
3084
3128
|
form.removeAttribute('g-form');
|
|
3085
3129
|
const state = getFormState(form);
|
|
3130
|
+
registerValidatedForm(form);
|
|
3086
3131
|
// Create validateAll function
|
|
3087
3132
|
const validateAll = async () => {
|
|
3088
3133
|
const validators = formValidators.get(form) || [];
|
|
@@ -3116,30 +3161,77 @@ function processFormDirective(form, scope) {
|
|
|
3116
3161
|
// Merge signals into existing object
|
|
3117
3162
|
Object.assign(scope[formName], formStateObj);
|
|
3118
3163
|
}
|
|
3119
|
-
|
|
3164
|
+
let replayingSubmission = false;
|
|
3165
|
+
let validatingSubmission = false;
|
|
3166
|
+
let replayScheduled = false;
|
|
3167
|
+
let replayTimer;
|
|
3168
|
+
let active = true;
|
|
3169
|
+
// Hold the first submit while validation runs, then replay a normal submit
|
|
3170
|
+
// so MPA Boost, native navigation, and user submit listeners keep working.
|
|
3120
3171
|
const submitListener = async (e) => {
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3172
|
+
if (replayingSubmission) {
|
|
3173
|
+
replayingSubmission = false;
|
|
3174
|
+
cancelApprovedFormSubmission(form);
|
|
3124
3175
|
return;
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3176
|
+
}
|
|
3177
|
+
e.preventDefault();
|
|
3178
|
+
e.stopImmediatePropagation();
|
|
3179
|
+
if (validatingSubmission || replayScheduled)
|
|
3129
3180
|
return;
|
|
3181
|
+
validatingSubmission = true;
|
|
3182
|
+
try {
|
|
3183
|
+
const isValid = await validateAll();
|
|
3184
|
+
if (!active || !isValid)
|
|
3185
|
+
return;
|
|
3186
|
+
const submitMethod = form.getAttribute('g-submit');
|
|
3187
|
+
// If not defined, replay through the normal submit event pipeline.
|
|
3188
|
+
if (!submitMethod) {
|
|
3189
|
+
const submitter = typeof SubmitEvent !== 'undefined' && e instanceof SubmitEvent && (e.submitter instanceof HTMLButtonElement || e.submitter instanceof HTMLInputElement) ? e.submitter : undefined;
|
|
3190
|
+
// Browsers ignore a re-entrant requestSubmit while the original
|
|
3191
|
+
// submission algorithm is still finishing. Replay in the next task.
|
|
3192
|
+
replayScheduled = true;
|
|
3193
|
+
replayTimer = setTimeout(() => {
|
|
3194
|
+
replayScheduled = false;
|
|
3195
|
+
replayTimer = undefined;
|
|
3196
|
+
if (!active)
|
|
3197
|
+
return;
|
|
3198
|
+
approveNextFormSubmission(form);
|
|
3199
|
+
replayingSubmission = true;
|
|
3200
|
+
try {
|
|
3201
|
+
form.requestSubmit(submitter);
|
|
3202
|
+
}
|
|
3203
|
+
finally {
|
|
3204
|
+
// requestSubmit dispatches synchronously. If native validation or
|
|
3205
|
+
// another capture listener stopped it, do not leak approval state.
|
|
3206
|
+
if (replayingSubmission) {
|
|
3207
|
+
replayingSubmission = false;
|
|
3208
|
+
cancelApprovedFormSubmission(form);
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
}, 0);
|
|
3212
|
+
return;
|
|
3213
|
+
}
|
|
3214
|
+
// Trigger custom submit handler if exists
|
|
3215
|
+
const submitHandler = scope[submitMethod];
|
|
3216
|
+
if (typeof submitHandler === 'function') {
|
|
3217
|
+
submitHandler.call(scope);
|
|
3218
|
+
}
|
|
3130
3219
|
}
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
if (typeof submitHandler === 'function') {
|
|
3134
|
-
submitHandler.call(scope);
|
|
3220
|
+
finally {
|
|
3221
|
+
validatingSubmission = false;
|
|
3135
3222
|
}
|
|
3136
3223
|
};
|
|
3137
|
-
form.addEventListener('submit', submitListener);
|
|
3224
|
+
form.addEventListener('submit', submitListener, true);
|
|
3138
3225
|
if (!form.__gyos_effects__) {
|
|
3139
3226
|
form.__gyos_effects__ = [];
|
|
3140
3227
|
}
|
|
3141
3228
|
form.__gyos_effects__.push(() => {
|
|
3142
|
-
|
|
3229
|
+
active = false;
|
|
3230
|
+
if (replayTimer !== undefined)
|
|
3231
|
+
clearTimeout(replayTimer);
|
|
3232
|
+
replayScheduled = false;
|
|
3233
|
+
form.removeEventListener('submit', submitListener, true);
|
|
3234
|
+
unregisterValidatedForm(form);
|
|
3143
3235
|
formStates.delete(form);
|
|
3144
3236
|
formValidators.delete(form);
|
|
3145
3237
|
});
|
|
@@ -3175,7 +3267,7 @@ function processValidateDirective(el) {
|
|
|
3175
3267
|
state.touched.value[modelAttr] = false;
|
|
3176
3268
|
// Validation function
|
|
3177
3269
|
const validateField = async () => {
|
|
3178
|
-
const value = el
|
|
3270
|
+
const value = getControlValue(el, form);
|
|
3179
3271
|
// Get form context for validators that need it (like 'same')
|
|
3180
3272
|
const formData = {};
|
|
3181
3273
|
const formInputs = form.querySelectorAll('input, textarea, select');
|
|
@@ -3185,7 +3277,7 @@ function processValidateDirective(el) {
|
|
|
3185
3277
|
if (input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement || input instanceof HTMLSelectElement) {
|
|
3186
3278
|
const fieldName = getFieldName(input);
|
|
3187
3279
|
if (fieldName) {
|
|
3188
|
-
formData[fieldName] = input
|
|
3280
|
+
formData[fieldName] = getControlValue(input, form);
|
|
3189
3281
|
}
|
|
3190
3282
|
}
|
|
3191
3283
|
});
|
|
@@ -3689,6 +3781,9 @@ function processModel(element, scope, root) {
|
|
|
3689
3781
|
if (inputElement.type === 'checkbox') {
|
|
3690
3782
|
inputElement.checked = !!initialValue;
|
|
3691
3783
|
}
|
|
3784
|
+
else if (inputElement.type === 'radio') {
|
|
3785
|
+
inputElement.checked = String(unref(initialValue)) === inputElement.value;
|
|
3786
|
+
}
|
|
3692
3787
|
else {
|
|
3693
3788
|
inputElement.value = unref(initialValue);
|
|
3694
3789
|
}
|
|
@@ -3711,6 +3806,8 @@ function processModel(element, scope, root) {
|
|
|
3711
3806
|
};
|
|
3712
3807
|
const eventInput = (e) => {
|
|
3713
3808
|
const target = e.target;
|
|
3809
|
+
if (target.type === 'radio' && !target.checked)
|
|
3810
|
+
return;
|
|
3714
3811
|
const value = target.type === 'checkbox' ? target.checked : target.value;
|
|
3715
3812
|
debouncedUpdate(value);
|
|
3716
3813
|
};
|
|
@@ -3730,6 +3827,9 @@ function processModel(element, scope, root) {
|
|
|
3730
3827
|
if (inputElement.type === 'checkbox') {
|
|
3731
3828
|
inputElement.checked = !!newValue;
|
|
3732
3829
|
}
|
|
3830
|
+
else if (inputElement.type === 'radio') {
|
|
3831
|
+
inputElement.checked = String(unref(newValue)) === inputElement.value;
|
|
3832
|
+
}
|
|
3733
3833
|
else if (inputElement.value !== newValue) {
|
|
3734
3834
|
inputElement.value = unref(newValue);
|
|
3735
3835
|
}
|
|
@@ -5369,6 +5469,7 @@ function autoBindModelProp(el, scope) {
|
|
|
5369
5469
|
const attrs = node.getAttributeNames();
|
|
5370
5470
|
return attrs.some(attr => attr.startsWith('g-model'));
|
|
5371
5471
|
});
|
|
5472
|
+
const radioDefaults = new Map();
|
|
5372
5473
|
for (const node of walker) {
|
|
5373
5474
|
if (isInIgnoredTree(node))
|
|
5374
5475
|
continue;
|
|
@@ -5377,13 +5478,34 @@ function autoBindModelProp(el, scope) {
|
|
|
5377
5478
|
if (!modelAttr)
|
|
5378
5479
|
continue;
|
|
5379
5480
|
// If prop exists or is nested, skip
|
|
5380
|
-
if (modelAttr.value
|
|
5481
|
+
if (modelAttr.value.includes('.'))
|
|
5381
5482
|
continue;
|
|
5382
5483
|
const element = node;
|
|
5484
|
+
if (element.type === 'radio') {
|
|
5485
|
+
if (modelAttr.value in scope)
|
|
5486
|
+
continue;
|
|
5487
|
+
if (!radioDefaults.has(modelAttr.value))
|
|
5488
|
+
radioDefaults.set(modelAttr.value, '');
|
|
5489
|
+
if (element.checked) {
|
|
5490
|
+
const value = modelAttr.name.split('.').includes('number')
|
|
5491
|
+
? Number(element.value)
|
|
5492
|
+
: element.value;
|
|
5493
|
+
radioDefaults.set(modelAttr.value, value);
|
|
5494
|
+
}
|
|
5495
|
+
continue;
|
|
5496
|
+
}
|
|
5497
|
+
if (modelAttr.value in scope)
|
|
5498
|
+
continue;
|
|
5383
5499
|
const valueAuto = element.type === 'checkbox' ? element.checked : element.value;
|
|
5384
5500
|
scope[modelAttr.value] = valueAuto;
|
|
5385
5501
|
DEBUG() && console.log(`[g-model] Auto-bound property "${modelAttr.value}" with initial value:`, valueAuto);
|
|
5386
5502
|
}
|
|
5503
|
+
for (const [prop, value] of radioDefaults) {
|
|
5504
|
+
if (prop in scope)
|
|
5505
|
+
continue;
|
|
5506
|
+
scope[prop] = value;
|
|
5507
|
+
DEBUG() && console.log(`[g-model] Auto-bound radio property "${prop}" with initial value:`, value);
|
|
5508
|
+
}
|
|
5387
5509
|
}
|
|
5388
5510
|
function getPersistKey$1(el, callback) {
|
|
5389
5511
|
if (!el.hasAttribute('g-scope-persist'))
|
|
@@ -7763,6 +7885,8 @@ function onSubmitCapture(event) {
|
|
|
7763
7885
|
return;
|
|
7764
7886
|
if (!(form.hasAttribute('g-boost') || hasGlobalBoost()))
|
|
7765
7887
|
return;
|
|
7888
|
+
if (shouldDeferToFormValidation(form))
|
|
7889
|
+
return;
|
|
7766
7890
|
event.preventDefault();
|
|
7767
7891
|
const action = form.action || window.location.href;
|
|
7768
7892
|
const method = (form.method || 'GET').toUpperCase();
|
|
@@ -7879,7 +8003,7 @@ const Gyos = {
|
|
|
7879
8003
|
onAfterNavigate,
|
|
7880
8004
|
portalCreate,
|
|
7881
8005
|
portalDestroy,
|
|
7882
|
-
version: '0.2.
|
|
8006
|
+
version: '0.2.2'
|
|
7883
8007
|
};
|
|
7884
8008
|
|
|
7885
8009
|
var _a, _b, _c;
|