gyosjs 0.2.1 → 0.2.3
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/directive.d.ts.map +1 -1
- package/dist/core/reactive.d.ts.map +1 -1
- package/dist/core/reveal.d.ts +3 -0
- package/dist/core/reveal.d.ts.map +1 -0
- 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 +459 -45
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +459 -45
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.esm.js +459 -45
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +459 -45
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/template/bindings.d.ts.map +1 -1
- package/dist/template/directives.d.ts.map +1 -1
- package/dist/template/events.d.ts.map +1 -1
- package/dist/template/model.d.ts.map +1 -1
- package/dist/template/scope-chain.d.ts +3 -0
- package/dist/template/scope-chain.d.ts.map +1 -0
- package/dist/template/structurals/structural.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gyos.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.2.
|
|
2
|
+
* GyosJS v0.2.3
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -1584,6 +1584,162 @@
|
|
|
1584
1584
|
});
|
|
1585
1585
|
}
|
|
1586
1586
|
|
|
1587
|
+
const DEFAULT_OPTIONS = {
|
|
1588
|
+
classNames: ['is-revealed'],
|
|
1589
|
+
rootMargin: '0px',
|
|
1590
|
+
threshold: 0.1
|
|
1591
|
+
};
|
|
1592
|
+
const pools = new Map();
|
|
1593
|
+
const mountedRecords = new WeakMap();
|
|
1594
|
+
function clampThreshold(value) {
|
|
1595
|
+
const number = Number(value);
|
|
1596
|
+
if (!Number.isFinite(number))
|
|
1597
|
+
return DEFAULT_OPTIONS.threshold;
|
|
1598
|
+
return Math.min(1, Math.max(0, number));
|
|
1599
|
+
}
|
|
1600
|
+
function normalizeThreshold(value) {
|
|
1601
|
+
if (!Array.isArray(value))
|
|
1602
|
+
return clampThreshold(value);
|
|
1603
|
+
const values = Array.from(new Set(value.map(clampThreshold))).sort((a, b) => a - b);
|
|
1604
|
+
return values.length ? values : DEFAULT_OPTIONS.threshold;
|
|
1605
|
+
}
|
|
1606
|
+
function normalizeOptions(binding) {
|
|
1607
|
+
const value = binding.value && typeof binding.value === 'object' && !Array.isArray(binding.value)
|
|
1608
|
+
? binding.value
|
|
1609
|
+
: {};
|
|
1610
|
+
const args = new Set(binding.arg || []);
|
|
1611
|
+
const classNames = typeof value.className === 'string'
|
|
1612
|
+
? value.className.split(/\s+/).filter(Boolean)
|
|
1613
|
+
: DEFAULT_OPTIONS.classNames;
|
|
1614
|
+
return {
|
|
1615
|
+
classNames,
|
|
1616
|
+
once: typeof value.once === 'boolean' ? value.once : !args.has('repeat'),
|
|
1617
|
+
rootMargin: typeof value.rootMargin === 'string' ? value.rootMargin : DEFAULT_OPTIONS.rootMargin,
|
|
1618
|
+
target: value.target === 'parent' || args.has('parent') ? 'parent' : 'self',
|
|
1619
|
+
threshold: normalizeThreshold(value.threshold ?? DEFAULT_OPTIONS.threshold)
|
|
1620
|
+
};
|
|
1621
|
+
}
|
|
1622
|
+
function poolKey(options) {
|
|
1623
|
+
return JSON.stringify([options.rootMargin, options.threshold]);
|
|
1624
|
+
}
|
|
1625
|
+
function setRevealed(record, revealed) {
|
|
1626
|
+
const { element, options } = record;
|
|
1627
|
+
if (revealed) {
|
|
1628
|
+
element.setAttribute('data-gyos-revealed', '');
|
|
1629
|
+
for (const className of options.classNames)
|
|
1630
|
+
element.classList.add(className);
|
|
1631
|
+
}
|
|
1632
|
+
else {
|
|
1633
|
+
element.removeAttribute('data-gyos-revealed');
|
|
1634
|
+
for (const className of options.classNames)
|
|
1635
|
+
element.classList.remove(className);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
function removeRecord(record) {
|
|
1639
|
+
if (mountedRecords.get(record.element) !== record)
|
|
1640
|
+
return;
|
|
1641
|
+
mountedRecords.delete(record.element);
|
|
1642
|
+
const records = record.pool.records.get(record.observedTarget);
|
|
1643
|
+
if (records) {
|
|
1644
|
+
records.delete(record);
|
|
1645
|
+
if (records.size === 0) {
|
|
1646
|
+
record.pool.records.delete(record.observedTarget);
|
|
1647
|
+
record.pool.observer.unobserve(record.observedTarget);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
if (record.pool.records.size === 0) {
|
|
1651
|
+
record.pool.observer.disconnect();
|
|
1652
|
+
pools.delete(record.pool.key);
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
function createPool(options) {
|
|
1656
|
+
const key = poolKey(options);
|
|
1657
|
+
const existing = pools.get(key);
|
|
1658
|
+
if (existing)
|
|
1659
|
+
return existing;
|
|
1660
|
+
let pool;
|
|
1661
|
+
try {
|
|
1662
|
+
const records = new Map();
|
|
1663
|
+
const observer = new IntersectionObserver(entries => {
|
|
1664
|
+
for (const entry of entries) {
|
|
1665
|
+
const current = Array.from(records.get(entry.target) || []);
|
|
1666
|
+
for (const record of current) {
|
|
1667
|
+
if (entry.isIntersecting) {
|
|
1668
|
+
setRevealed(record, true);
|
|
1669
|
+
if (record.options.once)
|
|
1670
|
+
removeRecord(record);
|
|
1671
|
+
}
|
|
1672
|
+
else if (!record.options.once) {
|
|
1673
|
+
setRevealed(record, false);
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
}, { rootMargin: options.rootMargin, threshold: options.threshold });
|
|
1678
|
+
pool = { key, observer, records };
|
|
1679
|
+
}
|
|
1680
|
+
catch {
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
pools.set(key, pool);
|
|
1684
|
+
return pool;
|
|
1685
|
+
}
|
|
1686
|
+
function prefersReducedMotion() {
|
|
1687
|
+
return typeof window.matchMedia === 'function'
|
|
1688
|
+
&& window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
1689
|
+
}
|
|
1690
|
+
function mountReveal(element, binding) {
|
|
1691
|
+
unmountReveal(element);
|
|
1692
|
+
document.documentElement.classList.add('gyos-reveal-ready');
|
|
1693
|
+
const options = normalizeOptions(binding);
|
|
1694
|
+
if (options.once && element.hasAttribute('data-gyos-revealed')) {
|
|
1695
|
+
for (const className of options.classNames)
|
|
1696
|
+
element.classList.add(className);
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
if (prefersReducedMotion() || typeof window.IntersectionObserver !== 'function') {
|
|
1700
|
+
const fallback = { element, options };
|
|
1701
|
+
setRevealed(fallback, true);
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
const pool = createPool(options);
|
|
1705
|
+
if (!pool) {
|
|
1706
|
+
const fallback = { element, options };
|
|
1707
|
+
setRevealed(fallback, true);
|
|
1708
|
+
return;
|
|
1709
|
+
}
|
|
1710
|
+
const observedTarget = options.target === 'parent' ? element.parentElement || element : element;
|
|
1711
|
+
const record = { element, observedTarget, options, pool };
|
|
1712
|
+
let records = pool.records.get(observedTarget);
|
|
1713
|
+
if (!records) {
|
|
1714
|
+
records = new Set();
|
|
1715
|
+
pool.records.set(observedTarget, records);
|
|
1716
|
+
pool.observer.observe(observedTarget);
|
|
1717
|
+
}
|
|
1718
|
+
records.add(record);
|
|
1719
|
+
mountedRecords.set(element, record);
|
|
1720
|
+
}
|
|
1721
|
+
function unmountReveal(element) {
|
|
1722
|
+
const record = mountedRecords.get(element);
|
|
1723
|
+
if (!record)
|
|
1724
|
+
return;
|
|
1725
|
+
removeRecord(record);
|
|
1726
|
+
if (!record.options.once)
|
|
1727
|
+
setRevealed(record, false);
|
|
1728
|
+
}
|
|
1729
|
+
const revealDirective = {
|
|
1730
|
+
mounted: mountReveal,
|
|
1731
|
+
updated(element, binding) {
|
|
1732
|
+
const previous = normalizeOptions({ ...binding, value: binding.oldValue });
|
|
1733
|
+
const next = normalizeOptions(binding);
|
|
1734
|
+
for (const className of previous.classNames) {
|
|
1735
|
+
if (!next.classNames.includes(className))
|
|
1736
|
+
element.classList.remove(className);
|
|
1737
|
+
}
|
|
1738
|
+
mountReveal(element, binding);
|
|
1739
|
+
},
|
|
1740
|
+
unmounted: unmountReveal
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1587
1743
|
const directives = new Map();
|
|
1588
1744
|
/**
|
|
1589
1745
|
* Register a custom directive
|
|
@@ -1758,6 +1914,7 @@
|
|
|
1758
1914
|
el.innerHTML = html;
|
|
1759
1915
|
},
|
|
1760
1916
|
});
|
|
1917
|
+
directive('reveal', revealDirective);
|
|
1761
1918
|
|
|
1762
1919
|
/**
|
|
1763
1920
|
* Transitions System - Smooth animations for enter/leave
|
|
@@ -2307,11 +2464,14 @@
|
|
|
2307
2464
|
if (directive) {
|
|
2308
2465
|
// g-on needs the handler itself. The general evaluator intentionally
|
|
2309
2466
|
// invokes bare functions to support function-style computed values.
|
|
2310
|
-
const
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2467
|
+
const evaluateValue = () => {
|
|
2468
|
+
if (attr.value.trim() === '')
|
|
2469
|
+
return undefined;
|
|
2470
|
+
return directiveName === 'on' && typeof scope[attr.value] === 'function'
|
|
2471
|
+
? scope[attr.value]
|
|
2472
|
+
: evaluateExpression(attr.value, scope, false);
|
|
2473
|
+
};
|
|
2474
|
+
const value = evaluateValue();
|
|
2315
2475
|
let oldValue = directive.mounted ? value : undefined;
|
|
2316
2476
|
let initialized = !directive.mounted;
|
|
2317
2477
|
// Call mounted hook
|
|
@@ -2337,7 +2497,7 @@
|
|
|
2337
2497
|
// Setup reactive update if has updated hook
|
|
2338
2498
|
if (directive.updated) {
|
|
2339
2499
|
queueReactiveEffect(element, () => {
|
|
2340
|
-
const newValue =
|
|
2500
|
+
const newValue = evaluateValue();
|
|
2341
2501
|
if (!initialized) {
|
|
2342
2502
|
initialized = true;
|
|
2343
2503
|
oldValue = newValue;
|
|
@@ -2392,28 +2552,108 @@
|
|
|
2392
2552
|
/**
|
|
2393
2553
|
* Reactive attribute bindings (:class, :style, :aria-*, :data-*, and custom attributes).
|
|
2394
2554
|
*/
|
|
2395
|
-
function
|
|
2555
|
+
function createClassBindingState(el) {
|
|
2556
|
+
return {
|
|
2557
|
+
staticClasses: new Set(el.classList),
|
|
2558
|
+
dynamicClasses: new Set()
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
function classNamesFromBinding(value) {
|
|
2396
2562
|
if (typeof value === 'string') {
|
|
2397
|
-
|
|
2563
|
+
return new Set(value.split(/\s+/).filter(Boolean));
|
|
2398
2564
|
}
|
|
2399
|
-
|
|
2400
|
-
Object.entries(value)
|
|
2401
|
-
|
|
2565
|
+
if (value && typeof value === 'object') {
|
|
2566
|
+
return new Set(Object.entries(value)
|
|
2567
|
+
.filter(([, condition]) => Boolean(condition))
|
|
2568
|
+
.flatMap(([className]) => className.split(/\s+/).filter(Boolean)));
|
|
2569
|
+
}
|
|
2570
|
+
return new Set();
|
|
2571
|
+
}
|
|
2572
|
+
function handleClassBinding(el, value, state) {
|
|
2573
|
+
const nextClasses = classNamesFromBinding(value);
|
|
2574
|
+
if (value && typeof value === 'object') {
|
|
2575
|
+
for (const [className, condition] of Object.entries(value)) {
|
|
2576
|
+
if (!condition) {
|
|
2577
|
+
for (const token of className.split(/\s+/).filter(Boolean))
|
|
2578
|
+
el.classList.remove(token);
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
for (const className of state.dynamicClasses) {
|
|
2583
|
+
if (!nextClasses.has(className) && !state.staticClasses.has(className)) {
|
|
2584
|
+
el.classList.remove(className);
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
for (const className of nextClasses) {
|
|
2588
|
+
el.classList.add(className);
|
|
2589
|
+
}
|
|
2590
|
+
state.dynamicClasses = nextClasses;
|
|
2591
|
+
}
|
|
2592
|
+
function readStyleValues(style) {
|
|
2593
|
+
const values = new Map();
|
|
2594
|
+
for (let index = 0; index < style.length; index++) {
|
|
2595
|
+
const property = style.item(index);
|
|
2596
|
+
values.set(property, {
|
|
2597
|
+
priority: style.getPropertyPriority(property),
|
|
2598
|
+
value: style.getPropertyValue(property)
|
|
2402
2599
|
});
|
|
2403
2600
|
}
|
|
2601
|
+
return values;
|
|
2602
|
+
}
|
|
2603
|
+
function normalizeStyleProperty(property) {
|
|
2604
|
+
if (property.startsWith('--') || property.includes('-'))
|
|
2605
|
+
return property.toLowerCase();
|
|
2606
|
+
return property.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
|
|
2404
2607
|
}
|
|
2405
|
-
function
|
|
2608
|
+
function styleValuesFromBinding(value) {
|
|
2609
|
+
const scratch = document.createElement('div').style;
|
|
2610
|
+
const mentioned = new Set();
|
|
2406
2611
|
if (typeof value === 'string') {
|
|
2407
|
-
|
|
2612
|
+
scratch.cssText = value;
|
|
2613
|
+
for (const property of readStyleValues(scratch).keys())
|
|
2614
|
+
mentioned.add(property);
|
|
2408
2615
|
}
|
|
2409
2616
|
else if (value && typeof value === 'object') {
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2617
|
+
for (const [property, propertyValue] of Object.entries(value)) {
|
|
2618
|
+
const normalized = normalizeStyleProperty(property);
|
|
2619
|
+
mentioned.add(normalized);
|
|
2620
|
+
if (propertyValue == null || propertyValue === false)
|
|
2621
|
+
continue;
|
|
2622
|
+
if (property.startsWith('--'))
|
|
2623
|
+
scratch.setProperty(property, String(propertyValue));
|
|
2624
|
+
else
|
|
2625
|
+
scratch[property] = propertyValue;
|
|
2626
|
+
}
|
|
2413
2627
|
}
|
|
2414
|
-
|
|
2415
|
-
|
|
2628
|
+
return { mentioned, values: readStyleValues(scratch) };
|
|
2629
|
+
}
|
|
2630
|
+
function createStyleBindingState(el) {
|
|
2631
|
+
return {
|
|
2632
|
+
staticStyles: readStyleValues(el.style),
|
|
2633
|
+
dynamicProperties: new Set()
|
|
2634
|
+
};
|
|
2635
|
+
}
|
|
2636
|
+
function restoreStaticStyle(el, property, state) {
|
|
2637
|
+
const original = state.staticStyles.get(property);
|
|
2638
|
+
if (original)
|
|
2639
|
+
el.style.setProperty(property, original.value, original.priority);
|
|
2640
|
+
else
|
|
2641
|
+
el.style.removeProperty(property);
|
|
2642
|
+
}
|
|
2643
|
+
function handleStyleBinding(el, value, state) {
|
|
2644
|
+
const next = styleValuesFromBinding(value);
|
|
2645
|
+
for (const property of state.dynamicProperties) {
|
|
2646
|
+
if (!next.mentioned.has(property))
|
|
2647
|
+
restoreStaticStyle(el, property, state);
|
|
2648
|
+
}
|
|
2649
|
+
for (const property of next.mentioned) {
|
|
2650
|
+
const styleValue = next.values.get(property);
|
|
2651
|
+
if (styleValue)
|
|
2652
|
+
el.style.setProperty(property, styleValue.value, styleValue.priority);
|
|
2653
|
+
else
|
|
2654
|
+
el.style.removeProperty(property);
|
|
2416
2655
|
}
|
|
2656
|
+
state.dynamicProperties = next.mentioned;
|
|
2417
2657
|
}
|
|
2418
2658
|
const booleanAttributes = new Set([
|
|
2419
2659
|
'allowfullscreen', 'async', 'autofocus', 'autoplay', 'checked', 'controls',
|
|
@@ -2508,13 +2748,15 @@
|
|
|
2508
2748
|
for (const attribute of boundAttributes(element)) {
|
|
2509
2749
|
const attrName = attribute.name.slice(1);
|
|
2510
2750
|
const expression = attribute.value;
|
|
2751
|
+
const classState = attrName === 'class' ? createClassBindingState(element) : undefined;
|
|
2752
|
+
const styleState = attrName === 'style' ? createStyleBindingState(element) : undefined;
|
|
2511
2753
|
queueReactiveEffect(element, () => {
|
|
2512
2754
|
const currentScope = getScopeFromElement(element) || scope;
|
|
2513
2755
|
const value = evaluateExpression(expression, currentScope);
|
|
2514
2756
|
if (attrName === 'class')
|
|
2515
|
-
handleClassBinding(element, value);
|
|
2757
|
+
handleClassBinding(element, value, classState);
|
|
2516
2758
|
else if (attrName === 'style')
|
|
2517
|
-
handleStyleBinding(element, value);
|
|
2759
|
+
handleStyleBinding(element, value, styleState);
|
|
2518
2760
|
else
|
|
2519
2761
|
applyAttributeBinding(element, attrName, value);
|
|
2520
2762
|
});
|
|
@@ -2529,9 +2771,9 @@
|
|
|
2529
2771
|
const attrName = attribute.name.slice(1);
|
|
2530
2772
|
const value = evaluateExpression(attribute.value, scope);
|
|
2531
2773
|
if (attrName === 'class')
|
|
2532
|
-
handleClassBinding(element, value);
|
|
2774
|
+
handleClassBinding(element, value, createClassBindingState(element));
|
|
2533
2775
|
else if (attrName === 'style')
|
|
2534
|
-
handleStyleBinding(element, value);
|
|
2776
|
+
handleStyleBinding(element, value, createStyleBindingState(element));
|
|
2535
2777
|
else
|
|
2536
2778
|
applyAttributeBinding(element, attrName, value);
|
|
2537
2779
|
}
|
|
@@ -3024,6 +3266,33 @@
|
|
|
3024
3266
|
return (num >= minVal && num <= maxVal) || `Must be between ${minVal} and ${maxVal}`;
|
|
3025
3267
|
});
|
|
3026
3268
|
|
|
3269
|
+
const managedForms = new WeakSet();
|
|
3270
|
+
const approvedSubmissions = new WeakSet();
|
|
3271
|
+
// Coordinates the validation listener on a form with the Router's earlier
|
|
3272
|
+
// document-capture listener without exposing state on application elements.
|
|
3273
|
+
function registerValidatedForm(form) {
|
|
3274
|
+
managedForms.add(form);
|
|
3275
|
+
}
|
|
3276
|
+
function unregisterValidatedForm(form) {
|
|
3277
|
+
managedForms.delete(form);
|
|
3278
|
+
approvedSubmissions.delete(form);
|
|
3279
|
+
}
|
|
3280
|
+
function approveNextFormSubmission(form) {
|
|
3281
|
+
approvedSubmissions.add(form);
|
|
3282
|
+
}
|
|
3283
|
+
function cancelApprovedFormSubmission(form) {
|
|
3284
|
+
approvedSubmissions.delete(form);
|
|
3285
|
+
}
|
|
3286
|
+
function shouldDeferToFormValidation(form) {
|
|
3287
|
+
if (!managedForms.has(form))
|
|
3288
|
+
return false;
|
|
3289
|
+
if (approvedSubmissions.has(form)) {
|
|
3290
|
+
approvedSubmissions.delete(form);
|
|
3291
|
+
return false;
|
|
3292
|
+
}
|
|
3293
|
+
return true;
|
|
3294
|
+
}
|
|
3295
|
+
|
|
3027
3296
|
/**
|
|
3028
3297
|
* Form Validation Directives
|
|
3029
3298
|
* Provides g-form, g-validate, and g-errors directives for reactive form validation
|
|
@@ -3038,6 +3307,23 @@
|
|
|
3038
3307
|
const modelAttr = Array.from(el.attributes).find(attr => attr.name === 'g-model' || attr.name.startsWith('g-model.'));
|
|
3039
3308
|
return modelAttr?.value || el.getAttribute('name') || el.id;
|
|
3040
3309
|
}
|
|
3310
|
+
function getControlValue(el, form) {
|
|
3311
|
+
if (!(el instanceof HTMLInputElement))
|
|
3312
|
+
return el.value;
|
|
3313
|
+
if (el.type === 'checkbox')
|
|
3314
|
+
return el.checked ? el.value : '';
|
|
3315
|
+
if (el.type !== 'radio')
|
|
3316
|
+
return el.value;
|
|
3317
|
+
const fieldName = getFieldName(el);
|
|
3318
|
+
const checked = Array.from(form.querySelectorAll('input[type="radio"]')).find(candidate => {
|
|
3319
|
+
if (isInIgnoredTree(candidate) || !candidate.checked)
|
|
3320
|
+
return false;
|
|
3321
|
+
if (el.name && candidate.name === el.name)
|
|
3322
|
+
return true;
|
|
3323
|
+
return getFieldName(candidate) === fieldName;
|
|
3324
|
+
});
|
|
3325
|
+
return checked?.value ?? '';
|
|
3326
|
+
}
|
|
3041
3327
|
/**
|
|
3042
3328
|
* Get or create form validation state
|
|
3043
3329
|
*/
|
|
@@ -3089,6 +3375,7 @@
|
|
|
3089
3375
|
return;
|
|
3090
3376
|
form.removeAttribute('g-form');
|
|
3091
3377
|
const state = getFormState(form);
|
|
3378
|
+
registerValidatedForm(form);
|
|
3092
3379
|
// Create validateAll function
|
|
3093
3380
|
const validateAll = async () => {
|
|
3094
3381
|
const validators = formValidators.get(form) || [];
|
|
@@ -3122,30 +3409,77 @@
|
|
|
3122
3409
|
// Merge signals into existing object
|
|
3123
3410
|
Object.assign(scope[formName], formStateObj);
|
|
3124
3411
|
}
|
|
3125
|
-
|
|
3412
|
+
let replayingSubmission = false;
|
|
3413
|
+
let validatingSubmission = false;
|
|
3414
|
+
let replayScheduled = false;
|
|
3415
|
+
let replayTimer;
|
|
3416
|
+
let active = true;
|
|
3417
|
+
// Hold the first submit while validation runs, then replay a normal submit
|
|
3418
|
+
// so MPA Boost, native navigation, and user submit listeners keep working.
|
|
3126
3419
|
const submitListener = async (e) => {
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3420
|
+
if (replayingSubmission) {
|
|
3421
|
+
replayingSubmission = false;
|
|
3422
|
+
cancelApprovedFormSubmission(form);
|
|
3130
3423
|
return;
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3424
|
+
}
|
|
3425
|
+
e.preventDefault();
|
|
3426
|
+
e.stopImmediatePropagation();
|
|
3427
|
+
if (validatingSubmission || replayScheduled)
|
|
3135
3428
|
return;
|
|
3429
|
+
validatingSubmission = true;
|
|
3430
|
+
try {
|
|
3431
|
+
const isValid = await validateAll();
|
|
3432
|
+
if (!active || !isValid)
|
|
3433
|
+
return;
|
|
3434
|
+
const submitMethod = form.getAttribute('g-submit');
|
|
3435
|
+
// If not defined, replay through the normal submit event pipeline.
|
|
3436
|
+
if (!submitMethod) {
|
|
3437
|
+
const submitter = typeof SubmitEvent !== 'undefined' && e instanceof SubmitEvent && (e.submitter instanceof HTMLButtonElement || e.submitter instanceof HTMLInputElement) ? e.submitter : undefined;
|
|
3438
|
+
// Browsers ignore a re-entrant requestSubmit while the original
|
|
3439
|
+
// submission algorithm is still finishing. Replay in the next task.
|
|
3440
|
+
replayScheduled = true;
|
|
3441
|
+
replayTimer = setTimeout(() => {
|
|
3442
|
+
replayScheduled = false;
|
|
3443
|
+
replayTimer = undefined;
|
|
3444
|
+
if (!active)
|
|
3445
|
+
return;
|
|
3446
|
+
approveNextFormSubmission(form);
|
|
3447
|
+
replayingSubmission = true;
|
|
3448
|
+
try {
|
|
3449
|
+
form.requestSubmit(submitter);
|
|
3450
|
+
}
|
|
3451
|
+
finally {
|
|
3452
|
+
// requestSubmit dispatches synchronously. If native validation or
|
|
3453
|
+
// another capture listener stopped it, do not leak approval state.
|
|
3454
|
+
if (replayingSubmission) {
|
|
3455
|
+
replayingSubmission = false;
|
|
3456
|
+
cancelApprovedFormSubmission(form);
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
}, 0);
|
|
3460
|
+
return;
|
|
3461
|
+
}
|
|
3462
|
+
// Trigger custom submit handler if exists
|
|
3463
|
+
const submitHandler = scope[submitMethod];
|
|
3464
|
+
if (typeof submitHandler === 'function') {
|
|
3465
|
+
submitHandler.call(scope);
|
|
3466
|
+
}
|
|
3136
3467
|
}
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
if (typeof submitHandler === 'function') {
|
|
3140
|
-
submitHandler.call(scope);
|
|
3468
|
+
finally {
|
|
3469
|
+
validatingSubmission = false;
|
|
3141
3470
|
}
|
|
3142
3471
|
};
|
|
3143
|
-
form.addEventListener('submit', submitListener);
|
|
3472
|
+
form.addEventListener('submit', submitListener, true);
|
|
3144
3473
|
if (!form.__gyos_effects__) {
|
|
3145
3474
|
form.__gyos_effects__ = [];
|
|
3146
3475
|
}
|
|
3147
3476
|
form.__gyos_effects__.push(() => {
|
|
3148
|
-
|
|
3477
|
+
active = false;
|
|
3478
|
+
if (replayTimer !== undefined)
|
|
3479
|
+
clearTimeout(replayTimer);
|
|
3480
|
+
replayScheduled = false;
|
|
3481
|
+
form.removeEventListener('submit', submitListener, true);
|
|
3482
|
+
unregisterValidatedForm(form);
|
|
3149
3483
|
formStates.delete(form);
|
|
3150
3484
|
formValidators.delete(form);
|
|
3151
3485
|
});
|
|
@@ -3181,7 +3515,7 @@
|
|
|
3181
3515
|
state.touched.value[modelAttr] = false;
|
|
3182
3516
|
// Validation function
|
|
3183
3517
|
const validateField = async () => {
|
|
3184
|
-
const value = el
|
|
3518
|
+
const value = getControlValue(el, form);
|
|
3185
3519
|
// Get form context for validators that need it (like 'same')
|
|
3186
3520
|
const formData = {};
|
|
3187
3521
|
const formInputs = form.querySelectorAll('input, textarea, select');
|
|
@@ -3191,7 +3525,7 @@
|
|
|
3191
3525
|
if (input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement || input instanceof HTMLSelectElement) {
|
|
3192
3526
|
const fieldName = getFieldName(input);
|
|
3193
3527
|
if (fieldName) {
|
|
3194
|
-
formData[fieldName] = input
|
|
3528
|
+
formData[fieldName] = getControlValue(input, form);
|
|
3195
3529
|
}
|
|
3196
3530
|
}
|
|
3197
3531
|
});
|
|
@@ -3450,12 +3784,12 @@
|
|
|
3450
3784
|
// e.stopPropagation(); // Optional: prevent other click handlers
|
|
3451
3785
|
const target = e.target;
|
|
3452
3786
|
// Check if click is outside element AND element is still in DOM
|
|
3453
|
-
if (!document.body.contains(element)
|
|
3454
|
-
(target instanceof Element && target.hasAttribute('g-ignore-outside-click'))) {
|
|
3455
|
-
// Element removed, cleanup
|
|
3787
|
+
if (!document.body.contains(element)) {
|
|
3456
3788
|
cleanup();
|
|
3457
3789
|
return;
|
|
3458
3790
|
}
|
|
3791
|
+
if (target instanceof Element && target.closest('[g-ignore-outside-click]'))
|
|
3792
|
+
return;
|
|
3459
3793
|
if (element !== target && !element.contains(target)) {
|
|
3460
3794
|
const currentScope = getScopeFromElement(element) || scope;
|
|
3461
3795
|
if (modifiers.includes('once'))
|
|
@@ -3581,6 +3915,39 @@
|
|
|
3581
3915
|
});
|
|
3582
3916
|
}
|
|
3583
3917
|
|
|
3918
|
+
const PARENT_SCOPE = Symbol('gyos.parent-scope');
|
|
3919
|
+
function attachParentScope(childScope, parentScope) {
|
|
3920
|
+
Object.defineProperty(childScope, PARENT_SCOPE, {
|
|
3921
|
+
value: parentScope,
|
|
3922
|
+
configurable: false,
|
|
3923
|
+
enumerable: false,
|
|
3924
|
+
writable: false
|
|
3925
|
+
});
|
|
3926
|
+
}
|
|
3927
|
+
function parentOf(scope) {
|
|
3928
|
+
return scope?.[PARENT_SCOPE];
|
|
3929
|
+
}
|
|
3930
|
+
function ensureModelPropertyOwner(scope, property) {
|
|
3931
|
+
if (!parentOf(scope) || property in scope)
|
|
3932
|
+
return;
|
|
3933
|
+
let owner = scope;
|
|
3934
|
+
let parent = parentOf(owner);
|
|
3935
|
+
while (parent) {
|
|
3936
|
+
owner = parent;
|
|
3937
|
+
parent = parentOf(owner);
|
|
3938
|
+
}
|
|
3939
|
+
if (!(property in owner))
|
|
3940
|
+
owner[property] = undefined;
|
|
3941
|
+
Object.defineProperty(scope, property, {
|
|
3942
|
+
get: () => owner[property],
|
|
3943
|
+
set: value => {
|
|
3944
|
+
owner[property] = value;
|
|
3945
|
+
},
|
|
3946
|
+
configurable: true,
|
|
3947
|
+
enumerable: true
|
|
3948
|
+
});
|
|
3949
|
+
}
|
|
3950
|
+
|
|
3584
3951
|
/**
|
|
3585
3952
|
* Two-Way Binding (g-model)
|
|
3586
3953
|
* Handles form input binding with optional modifiers (debounce, number, trim, etc.)
|
|
@@ -3690,11 +4057,17 @@
|
|
|
3690
4057
|
DEBUG() && console.log('[g-model] Expression:', expr, 'Modifiers:', modifiers, 'Debounce:', debounceMs);
|
|
3691
4058
|
// Get current scope from element
|
|
3692
4059
|
const currentScope = getScopeFromElement(element) || scope;
|
|
4060
|
+
const modelParts = parsePath(expr);
|
|
4061
|
+
if (typeof modelParts[0] === 'string')
|
|
4062
|
+
ensureModelPropertyOwner(currentScope, modelParts[0]);
|
|
3693
4063
|
// Set initial value (no pipes in v-model)
|
|
3694
4064
|
const initialValue = evaluateExpression(expr, currentScope, false);
|
|
3695
4065
|
if (inputElement.type === 'checkbox') {
|
|
3696
4066
|
inputElement.checked = !!initialValue;
|
|
3697
4067
|
}
|
|
4068
|
+
else if (inputElement.type === 'radio') {
|
|
4069
|
+
inputElement.checked = String(unref(initialValue)) === inputElement.value;
|
|
4070
|
+
}
|
|
3698
4071
|
else {
|
|
3699
4072
|
inputElement.value = unref(initialValue);
|
|
3700
4073
|
}
|
|
@@ -3717,6 +4090,8 @@
|
|
|
3717
4090
|
};
|
|
3718
4091
|
const eventInput = (e) => {
|
|
3719
4092
|
const target = e.target;
|
|
4093
|
+
if (target.type === 'radio' && !target.checked)
|
|
4094
|
+
return;
|
|
3720
4095
|
const value = target.type === 'checkbox' ? target.checked : target.value;
|
|
3721
4096
|
debouncedUpdate(value);
|
|
3722
4097
|
};
|
|
@@ -3736,6 +4111,9 @@
|
|
|
3736
4111
|
if (inputElement.type === 'checkbox') {
|
|
3737
4112
|
inputElement.checked = !!newValue;
|
|
3738
4113
|
}
|
|
4114
|
+
else if (inputElement.type === 'radio') {
|
|
4115
|
+
inputElement.checked = String(unref(newValue)) === inputElement.value;
|
|
4116
|
+
}
|
|
3739
4117
|
else if (inputElement.value !== newValue) {
|
|
3740
4118
|
inputElement.value = unref(newValue);
|
|
3741
4119
|
}
|
|
@@ -3938,8 +4316,15 @@
|
|
|
3938
4316
|
proxy = new Proxy(raw, {
|
|
3939
4317
|
get(target, key, receiver) {
|
|
3940
4318
|
const value = Reflect.get(target, key, receiver);
|
|
3941
|
-
//
|
|
4319
|
+
// Missing own fields can become reactive later; prototype APIs stay untouched.
|
|
3942
4320
|
if (!Object.prototype.hasOwnProperty.call(target, key)) {
|
|
4321
|
+
if (typeof key !== 'symbol' && !isReservedKey(key) && !(key in target)) {
|
|
4322
|
+
const existingSig = fieldSignals.get(target)?.get(key);
|
|
4323
|
+
if (hasCurrentEffect())
|
|
4324
|
+
return (existingSig || getFieldSignal(target, key, undefined)).value;
|
|
4325
|
+
if (existingSig)
|
|
4326
|
+
return existingSig.peek;
|
|
4327
|
+
}
|
|
3943
4328
|
return value;
|
|
3944
4329
|
}
|
|
3945
4330
|
// symbol / key internal bỏ qua reactive
|
|
@@ -4030,6 +4415,7 @@
|
|
|
4030
4415
|
return true;
|
|
4031
4416
|
},
|
|
4032
4417
|
ownKeys(target) {
|
|
4418
|
+
ensureVersion(target).value;
|
|
4033
4419
|
return Reflect.ownKeys(target).filter(key => !isReservedKey(key));
|
|
4034
4420
|
},
|
|
4035
4421
|
getOwnPropertyDescriptor(target, key) {
|
|
@@ -4140,6 +4526,7 @@
|
|
|
4140
4526
|
*/
|
|
4141
4527
|
function createChildScope(parentScope, itemVar, list, index) {
|
|
4142
4528
|
const childScope = {};
|
|
4529
|
+
attachParentScope(childScope, parentScope);
|
|
4143
4530
|
const state = signal({ list, index });
|
|
4144
4531
|
Object.defineProperty(childScope, FOR_SCOPE_STATE, { value: state });
|
|
4145
4532
|
// handle itemVar include index (e.g., "item, idx in items")
|
|
@@ -4178,6 +4565,9 @@
|
|
|
4178
4565
|
if (!(key in childScope)) {
|
|
4179
4566
|
Object.defineProperty(childScope, key, {
|
|
4180
4567
|
get: () => parentScope[key],
|
|
4568
|
+
set: (value) => {
|
|
4569
|
+
parentScope[key] = value;
|
|
4570
|
+
},
|
|
4181
4571
|
enumerable: true,
|
|
4182
4572
|
configurable: true,
|
|
4183
4573
|
});
|
|
@@ -5375,6 +5765,7 @@
|
|
|
5375
5765
|
const attrs = node.getAttributeNames();
|
|
5376
5766
|
return attrs.some(attr => attr.startsWith('g-model'));
|
|
5377
5767
|
});
|
|
5768
|
+
const radioDefaults = new Map();
|
|
5378
5769
|
for (const node of walker) {
|
|
5379
5770
|
if (isInIgnoredTree(node))
|
|
5380
5771
|
continue;
|
|
@@ -5383,13 +5774,34 @@
|
|
|
5383
5774
|
if (!modelAttr)
|
|
5384
5775
|
continue;
|
|
5385
5776
|
// If prop exists or is nested, skip
|
|
5386
|
-
if (modelAttr.value
|
|
5777
|
+
if (modelAttr.value.includes('.'))
|
|
5387
5778
|
continue;
|
|
5388
5779
|
const element = node;
|
|
5780
|
+
if (element.type === 'radio') {
|
|
5781
|
+
if (modelAttr.value in scope)
|
|
5782
|
+
continue;
|
|
5783
|
+
if (!radioDefaults.has(modelAttr.value))
|
|
5784
|
+
radioDefaults.set(modelAttr.value, '');
|
|
5785
|
+
if (element.checked) {
|
|
5786
|
+
const value = modelAttr.name.split('.').includes('number')
|
|
5787
|
+
? Number(element.value)
|
|
5788
|
+
: element.value;
|
|
5789
|
+
radioDefaults.set(modelAttr.value, value);
|
|
5790
|
+
}
|
|
5791
|
+
continue;
|
|
5792
|
+
}
|
|
5793
|
+
if (modelAttr.value in scope)
|
|
5794
|
+
continue;
|
|
5389
5795
|
const valueAuto = element.type === 'checkbox' ? element.checked : element.value;
|
|
5390
5796
|
scope[modelAttr.value] = valueAuto;
|
|
5391
5797
|
DEBUG() && console.log(`[g-model] Auto-bound property "${modelAttr.value}" with initial value:`, valueAuto);
|
|
5392
5798
|
}
|
|
5799
|
+
for (const [prop, value] of radioDefaults) {
|
|
5800
|
+
if (prop in scope)
|
|
5801
|
+
continue;
|
|
5802
|
+
scope[prop] = value;
|
|
5803
|
+
DEBUG() && console.log(`[g-model] Auto-bound radio property "${prop}" with initial value:`, value);
|
|
5804
|
+
}
|
|
5393
5805
|
}
|
|
5394
5806
|
function getPersistKey$1(el, callback) {
|
|
5395
5807
|
if (!el.hasAttribute('g-scope-persist'))
|
|
@@ -7769,6 +8181,8 @@
|
|
|
7769
8181
|
return;
|
|
7770
8182
|
if (!(form.hasAttribute('g-boost') || hasGlobalBoost()))
|
|
7771
8183
|
return;
|
|
8184
|
+
if (shouldDeferToFormValidation(form))
|
|
8185
|
+
return;
|
|
7772
8186
|
event.preventDefault();
|
|
7773
8187
|
const action = form.action || window.location.href;
|
|
7774
8188
|
const method = (form.method || 'GET').toUpperCase();
|
|
@@ -7885,7 +8299,7 @@
|
|
|
7885
8299
|
onAfterNavigate,
|
|
7886
8300
|
portalCreate,
|
|
7887
8301
|
portalDestroy,
|
|
7888
|
-
version: '0.2.
|
|
8302
|
+
version: '0.2.3'
|
|
7889
8303
|
};
|
|
7890
8304
|
|
|
7891
8305
|
exports.applyDirective = applyDirective;
|