gyosjs 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/core/composables.d.ts +3 -1
- package/dist/core/composables.d.ts.map +1 -1
- package/dist/core/portal.d.ts.map +1 -1
- package/dist/core/reactive.d.ts.map +1 -1
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/core/router/scroll.d.ts.map +1 -1
- package/dist/core/router/swap.d.ts.map +1 -1
- package/dist/core/scope-registry.d.ts.map +1 -1
- package/dist/form/form-validation.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +418 -215
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +418 -215
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +434 -231
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +434 -231
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +434 -231
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +434 -231
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +418 -215
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +418 -215
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/reactivity/signal.d.ts.map +1 -1
- package/dist/runtime/csp-evaluator.d.ts.map +1 -1
- package/dist/template/bindings.d.ts.map +1 -1
- package/dist/template/cleanup.d.ts +1 -0
- package/dist/template/cleanup.d.ts.map +1 -1
- package/dist/template/directives.d.ts.map +1 -1
- package/dist/template/effect-queue.d.ts +1 -1
- package/dist/template/effect-queue.d.ts.map +1 -1
- package/dist/template/events.d.ts.map +1 -1
- package/dist/template/process.d.ts.map +1 -1
- package/dist/template/structurals/structural.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gyos.csp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.5.
|
|
2
|
+
* GyosJS v0.5.4
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -6420,30 +6420,30 @@
|
|
|
6420
6420
|
throw cspError('Invalid assignment target', expression, node);
|
|
6421
6421
|
}
|
|
6422
6422
|
function evaluateCall(node, context, expression) {
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
throw cspError('Spread arguments are not supported', expression, argument);
|
|
6426
|
-
return evaluateNode(argument, context, expression);
|
|
6427
|
-
});
|
|
6423
|
+
let receiver = context.scope;
|
|
6424
|
+
let callable;
|
|
6428
6425
|
if (node.callee.type === 'MemberExpression') {
|
|
6429
6426
|
const [object, property] = memberParts(node.callee, context, expression);
|
|
6430
6427
|
if (object === optionalChainMiss)
|
|
6431
6428
|
return optionalChainMiss;
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
return method.apply(object, args);
|
|
6429
|
+
receiver = object;
|
|
6430
|
+
callable = object[property];
|
|
6431
|
+
}
|
|
6432
|
+
else {
|
|
6433
|
+
callable = evaluateNode(node.callee, context, expression);
|
|
6438
6434
|
}
|
|
6439
|
-
const callable = evaluateNode(node.callee, context, expression);
|
|
6440
6435
|
if (callable === optionalChainMiss)
|
|
6441
6436
|
return optionalChainMiss;
|
|
6442
6437
|
if (callable == null && node.optional)
|
|
6443
6438
|
return optionalChainMiss;
|
|
6439
|
+
const args = node.arguments.map((argument) => {
|
|
6440
|
+
if (argument.type === 'SpreadElement')
|
|
6441
|
+
throw cspError('Spread arguments are not supported', expression, argument);
|
|
6442
|
+
return evaluateNode(argument, context, expression);
|
|
6443
|
+
});
|
|
6444
6444
|
if (typeof callable !== 'function')
|
|
6445
6445
|
throw cspError('Called value is not a function', expression, node.callee);
|
|
6446
|
-
return callable.apply(
|
|
6446
|
+
return callable.apply(receiver, args);
|
|
6447
6447
|
}
|
|
6448
6448
|
function applyAssignment(operator, current, value, expression, node) {
|
|
6449
6449
|
switch (operator) {
|
|
@@ -6566,10 +6566,10 @@
|
|
|
6566
6566
|
}
|
|
6567
6567
|
case 'UpdateExpression': {
|
|
6568
6568
|
const reference = resolveReference(node.argument, context, expression);
|
|
6569
|
-
|
|
6570
|
-
const
|
|
6569
|
+
let next = reference.get();
|
|
6570
|
+
const previous = node.operator === '++' ? next++ : next--;
|
|
6571
6571
|
reference.set(next);
|
|
6572
|
-
return node.prefix ? next :
|
|
6572
|
+
return node.prefix ? next : previous;
|
|
6573
6573
|
}
|
|
6574
6574
|
case 'SequenceExpression': {
|
|
6575
6575
|
let value;
|
|
@@ -6739,25 +6739,30 @@
|
|
|
6739
6739
|
}
|
|
6740
6740
|
const cloned = {};
|
|
6741
6741
|
for (const key in obj) {
|
|
6742
|
-
if (
|
|
6742
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
6743
6743
|
cloned[key] = clone(obj[key]);
|
|
6744
6744
|
}
|
|
6745
6745
|
}
|
|
6746
6746
|
return cloned;
|
|
6747
6747
|
}
|
|
6748
6748
|
function deepEqual(a, b) {
|
|
6749
|
-
if (a
|
|
6749
|
+
if (Object.is(a, b))
|
|
6750
6750
|
return true;
|
|
6751
6751
|
if (typeof a !== 'object' || typeof b !== 'object' || a == null || b == null) {
|
|
6752
6752
|
return false;
|
|
6753
6753
|
}
|
|
6754
|
+
if (a instanceof Date || b instanceof Date) {
|
|
6755
|
+
return a instanceof Date && b instanceof Date && Object.is(a.getTime(), b.getTime());
|
|
6756
|
+
}
|
|
6757
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
6758
|
+
return false;
|
|
6754
6759
|
const keysA = Object.keys(a);
|
|
6755
6760
|
const keysB = Object.keys(b);
|
|
6756
6761
|
if (keysA.length !== keysB.length) {
|
|
6757
6762
|
return false;
|
|
6758
6763
|
}
|
|
6759
6764
|
for (const key of keysA) {
|
|
6760
|
-
if (!deepEqual(a[key], b[key])) {
|
|
6765
|
+
if (!Object.prototype.hasOwnProperty.call(b, key) || !deepEqual(a[key], b[key])) {
|
|
6761
6766
|
return false;
|
|
6762
6767
|
}
|
|
6763
6768
|
}
|
|
@@ -7293,8 +7298,11 @@
|
|
|
7293
7298
|
execute.__dependencies = dependencies;
|
|
7294
7299
|
execute.__versions = versions;
|
|
7295
7300
|
try {
|
|
7296
|
-
|
|
7297
|
-
|
|
7301
|
+
// The previous cleanup can dispose this effect before the next run.
|
|
7302
|
+
if (active) {
|
|
7303
|
+
const nextCleanup = fn();
|
|
7304
|
+
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
7305
|
+
}
|
|
7298
7306
|
}
|
|
7299
7307
|
catch (error) {
|
|
7300
7308
|
console.error('[Effect] Error in effect:', error);
|
|
@@ -7303,6 +7311,25 @@
|
|
|
7303
7311
|
finally {
|
|
7304
7312
|
initialized = true;
|
|
7305
7313
|
currentEffect = prevEffect;
|
|
7314
|
+
// stop() may have been called inside fn, before its cleanup was returned
|
|
7315
|
+
// or before later reads registered more dependencies.
|
|
7316
|
+
if (!active) {
|
|
7317
|
+
dependencies.forEach(dependency => dependency.delete(execute));
|
|
7318
|
+
dependencies.clear();
|
|
7319
|
+
versions.clear();
|
|
7320
|
+
effectQueue.delete(execute);
|
|
7321
|
+
batchedEffects.delete(execute);
|
|
7322
|
+
const finalCleanup = cleanup;
|
|
7323
|
+
cleanup = undefined;
|
|
7324
|
+
if (finalCleanup) {
|
|
7325
|
+
try {
|
|
7326
|
+
untrack(finalCleanup);
|
|
7327
|
+
}
|
|
7328
|
+
catch (error) {
|
|
7329
|
+
console.error('[Effect] Error in final cleanup:', error);
|
|
7330
|
+
}
|
|
7331
|
+
}
|
|
7332
|
+
}
|
|
7306
7333
|
effectDepth--;
|
|
7307
7334
|
runningEffects.delete(execute);
|
|
7308
7335
|
// Flush queue when we're back to top level
|
|
@@ -7327,8 +7354,10 @@
|
|
|
7327
7354
|
dependencies.clear();
|
|
7328
7355
|
versions.clear();
|
|
7329
7356
|
if (cleanup) {
|
|
7357
|
+
const finalCleanup = cleanup;
|
|
7358
|
+
cleanup = undefined;
|
|
7330
7359
|
try {
|
|
7331
|
-
untrack(
|
|
7360
|
+
untrack(finalCleanup);
|
|
7332
7361
|
}
|
|
7333
7362
|
catch (error) {
|
|
7334
7363
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -8056,11 +8085,6 @@
|
|
|
8056
8085
|
* @returns Evaluated value
|
|
8057
8086
|
*/
|
|
8058
8087
|
function evaluateSimpleExpression(expr, scope) {
|
|
8059
|
-
// Handle string literals
|
|
8060
|
-
if ((expr.startsWith("'") && expr.endsWith("'")) ||
|
|
8061
|
-
(expr.startsWith('"') && expr.endsWith('"'))) {
|
|
8062
|
-
return expr.slice(1, -1);
|
|
8063
|
-
}
|
|
8064
8088
|
// Handle numbers
|
|
8065
8089
|
if (!isNaN(Number(expr))) {
|
|
8066
8090
|
return Number(expr);
|
|
@@ -8107,6 +8131,8 @@
|
|
|
8107
8131
|
let instance = mountedScopes.get(el);
|
|
8108
8132
|
if (!instance)
|
|
8109
8133
|
return;
|
|
8134
|
+
// A hook may call cleanup again; each mount is disposed at most once.
|
|
8135
|
+
mountedScopes.delete(el);
|
|
8110
8136
|
// Cleanup all effects
|
|
8111
8137
|
if (instance.__gyos_effects__) {
|
|
8112
8138
|
instance.__gyos_effects__.forEach((cleanup) => {
|
|
@@ -8121,7 +8147,12 @@
|
|
|
8121
8147
|
}
|
|
8122
8148
|
// Call lifecycle hook
|
|
8123
8149
|
if (instance.onUnmount) {
|
|
8124
|
-
|
|
8150
|
+
try {
|
|
8151
|
+
instance.onUnmount.call(instance);
|
|
8152
|
+
}
|
|
8153
|
+
catch (error) {
|
|
8154
|
+
console.error('[Component] Error in onUnmount:', error);
|
|
8155
|
+
}
|
|
8125
8156
|
}
|
|
8126
8157
|
// Clear reference on element
|
|
8127
8158
|
el.__gyos_scope__ = null;
|
|
@@ -8158,6 +8189,9 @@
|
|
|
8158
8189
|
return effectQueueStack[effectQueueStack.length - 1];
|
|
8159
8190
|
}
|
|
8160
8191
|
function attachDispose(target, runner) {
|
|
8192
|
+
// An earlier queued content binding can replace this subtree during flush.
|
|
8193
|
+
if (!target.isConnected)
|
|
8194
|
+
return;
|
|
8161
8195
|
const dispose = effect(runner);
|
|
8162
8196
|
if (!target.__gyos_effects__) {
|
|
8163
8197
|
target.__gyos_effects__ = [];
|
|
@@ -9077,6 +9111,125 @@
|
|
|
9077
9111
|
return transitionManager.leave(element, transitionConfig, removeElement);
|
|
9078
9112
|
}
|
|
9079
9113
|
|
|
9114
|
+
/**
|
|
9115
|
+
* Portal/Teleport System - Render content in different DOM location
|
|
9116
|
+
* Useful for modals, tooltips, notifications that need to break out of parent containers
|
|
9117
|
+
*
|
|
9118
|
+
* @example
|
|
9119
|
+
* // Portal to body (for modals)
|
|
9120
|
+
* <div g-portal="body">
|
|
9121
|
+
* <div class="modal">Modal content</div>
|
|
9122
|
+
* </div>
|
|
9123
|
+
*
|
|
9124
|
+
* @example
|
|
9125
|
+
* // Portal to specific element
|
|
9126
|
+
* <div g-portal="#notifications">
|
|
9127
|
+
* <div class="toast">Toast message</div>
|
|
9128
|
+
* </div>
|
|
9129
|
+
*/
|
|
9130
|
+
/**
|
|
9131
|
+
* Create a portal - Move element to target location
|
|
9132
|
+
*
|
|
9133
|
+
* @param sourceEl - Element to teleport
|
|
9134
|
+
* @param targetSelector - CSS selector for destination
|
|
9135
|
+
*
|
|
9136
|
+
* @example
|
|
9137
|
+
* portalCreate(modalEl, 'body');
|
|
9138
|
+
* portalCreate(tooltipEl, '#tooltip-container');
|
|
9139
|
+
*/
|
|
9140
|
+
function portalCreate(sourceEl, targetSelector) {
|
|
9141
|
+
if (!sourceEl)
|
|
9142
|
+
return;
|
|
9143
|
+
const target = document.querySelector(targetSelector);
|
|
9144
|
+
if (!target) {
|
|
9145
|
+
console.warn(`[GyosJS] Portal target "${targetSelector}" not found`);
|
|
9146
|
+
return;
|
|
9147
|
+
}
|
|
9148
|
+
// Create placeholder comment to mark original position
|
|
9149
|
+
const placeholder = document.createComment('g-portal');
|
|
9150
|
+
sourceEl.parentNode?.insertBefore(placeholder, sourceEl);
|
|
9151
|
+
// Store original parent for restoration
|
|
9152
|
+
sourceEl.__portal_placeholder__ = placeholder;
|
|
9153
|
+
sourceEl.__portal_target__ = target;
|
|
9154
|
+
placeholder.__gyos_portal__ = sourceEl;
|
|
9155
|
+
// Move the entire element to target
|
|
9156
|
+
target.appendChild(sourceEl);
|
|
9157
|
+
DEBUG() && console.log('[Portal] Created - moved element to', targetSelector);
|
|
9158
|
+
}
|
|
9159
|
+
/**
|
|
9160
|
+
* Destroy a portal - Restore element to original position
|
|
9161
|
+
*
|
|
9162
|
+
* @param sourceEl - Element to restore
|
|
9163
|
+
*
|
|
9164
|
+
* @example
|
|
9165
|
+
* portalDestroy(modalEl); // Returns modal to original location
|
|
9166
|
+
*/
|
|
9167
|
+
function portalDestroy(sourceEl) {
|
|
9168
|
+
if (!sourceEl)
|
|
9169
|
+
return;
|
|
9170
|
+
const placeholder = sourceEl.__portal_placeholder__;
|
|
9171
|
+
if (placeholder && placeholder.parentNode) {
|
|
9172
|
+
delete placeholder.__gyos_portal__;
|
|
9173
|
+
// Move element back to original position
|
|
9174
|
+
placeholder.parentNode.insertBefore(sourceEl, placeholder);
|
|
9175
|
+
placeholder.remove();
|
|
9176
|
+
delete sourceEl.__portal_placeholder__;
|
|
9177
|
+
delete sourceEl.__portal_target__;
|
|
9178
|
+
DEBUG() && console.log('[Portal] Destroyed - restored element to original position');
|
|
9179
|
+
}
|
|
9180
|
+
}
|
|
9181
|
+
|
|
9182
|
+
/**
|
|
9183
|
+
* Cleanup utilities for disposing effects and event listeners
|
|
9184
|
+
*/
|
|
9185
|
+
/**
|
|
9186
|
+
* Dispose all effects attached to an element and its descendants
|
|
9187
|
+
* Handles both element effects (__gyos_effects__) and component lifecycle
|
|
9188
|
+
*/
|
|
9189
|
+
function disposeEffects(element = document.body, removeElement = false) {
|
|
9190
|
+
if (!element)
|
|
9191
|
+
return;
|
|
9192
|
+
disposeNode(element);
|
|
9193
|
+
if (removeElement)
|
|
9194
|
+
element.remove();
|
|
9195
|
+
}
|
|
9196
|
+
function disposeNode(element, removeElement = false) {
|
|
9197
|
+
untrack(() => disposeNodeInternal(element, removeElement));
|
|
9198
|
+
}
|
|
9199
|
+
function disposeNodeInternal(element, removeElement = false) {
|
|
9200
|
+
const portal = element.__gyos_portal__;
|
|
9201
|
+
if (portal) {
|
|
9202
|
+
delete element.__gyos_portal__;
|
|
9203
|
+
disposeNode(portal, removeElement);
|
|
9204
|
+
}
|
|
9205
|
+
// Include structural comment anchors. Snapshot before hooks mutate the tree.
|
|
9206
|
+
const children = Array.from(element.childNodes);
|
|
9207
|
+
const effects = element.__gyos_effects__;
|
|
9208
|
+
// Release ownership before callbacks to make reentrant cleanup safe.
|
|
9209
|
+
element.__gyos_effects__ = null;
|
|
9210
|
+
// Unmount scope if element has one (calls onUnmount + cleans instance.__gyos_effects__)
|
|
9211
|
+
if (element.hasAttribute?.('g-scope') || element.__gyos_scope__) {
|
|
9212
|
+
unmountScope(element);
|
|
9213
|
+
}
|
|
9214
|
+
// Dispose effects on this element (template effects like g-show, :class, {text})
|
|
9215
|
+
if (effects) {
|
|
9216
|
+
effects.forEach((dispose) => {
|
|
9217
|
+
try {
|
|
9218
|
+
dispose();
|
|
9219
|
+
}
|
|
9220
|
+
catch (error) {
|
|
9221
|
+
console.error('[GyosJS] Error disposing effect:', error);
|
|
9222
|
+
}
|
|
9223
|
+
});
|
|
9224
|
+
}
|
|
9225
|
+
// Recursively dispose effects on all descendants
|
|
9226
|
+
children.forEach(child => disposeNode(child));
|
|
9227
|
+
// Restore a portal to its placeholder before removing the owning tree.
|
|
9228
|
+
portalDestroy(element);
|
|
9229
|
+
if (removeElement)
|
|
9230
|
+
element.parentNode?.removeChild(element);
|
|
9231
|
+
}
|
|
9232
|
+
|
|
9080
9233
|
/**
|
|
9081
9234
|
* Directive Processing
|
|
9082
9235
|
* Handles built-in directives (g-show, g-html, g-text) and custom directives
|
|
@@ -9138,6 +9291,7 @@
|
|
|
9138
9291
|
const expr = element.getAttribute('g-html');
|
|
9139
9292
|
queueReactiveEffect(element, () => {
|
|
9140
9293
|
const value = evaluateExpression(expr, scope);
|
|
9294
|
+
Array.from(element.childNodes).forEach(child => disposeNode(child));
|
|
9141
9295
|
element.innerHTML = value;
|
|
9142
9296
|
});
|
|
9143
9297
|
}
|
|
@@ -9146,6 +9300,7 @@
|
|
|
9146
9300
|
const expr = element.getAttribute('g-text');
|
|
9147
9301
|
queueReactiveEffect(element, () => {
|
|
9148
9302
|
const value = evaluateExpression(expr, scope);
|
|
9303
|
+
Array.from(element.childNodes).forEach(child => disposeNode(child));
|
|
9149
9304
|
element.textContent = value;
|
|
9150
9305
|
});
|
|
9151
9306
|
}
|
|
@@ -9223,7 +9378,7 @@
|
|
|
9223
9378
|
* @param scope - Scope object for evaluation
|
|
9224
9379
|
*/
|
|
9225
9380
|
function processDirectivesStatic(el, scope) {
|
|
9226
|
-
const directives =
|
|
9381
|
+
const directives = [el, ...el.querySelectorAll('[g-show], [g-html], [g-text]')]
|
|
9227
9382
|
.filter(element => !isInIgnoredTree(element));
|
|
9228
9383
|
directives.forEach(elem => {
|
|
9229
9384
|
const element = elem;
|
|
@@ -9300,7 +9455,9 @@
|
|
|
9300
9455
|
return values;
|
|
9301
9456
|
}
|
|
9302
9457
|
function normalizeStyleProperty(property) {
|
|
9303
|
-
if (property.startsWith('--')
|
|
9458
|
+
if (property.startsWith('--'))
|
|
9459
|
+
return property;
|
|
9460
|
+
if (property.includes('-'))
|
|
9304
9461
|
return property.toLowerCase();
|
|
9305
9462
|
return property.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`);
|
|
9306
9463
|
}
|
|
@@ -9479,72 +9636,6 @@
|
|
|
9479
9636
|
}
|
|
9480
9637
|
}
|
|
9481
9638
|
|
|
9482
|
-
/**
|
|
9483
|
-
* Portal/Teleport System - Render content in different DOM location
|
|
9484
|
-
* Useful for modals, tooltips, notifications that need to break out of parent containers
|
|
9485
|
-
*
|
|
9486
|
-
* @example
|
|
9487
|
-
* // Portal to body (for modals)
|
|
9488
|
-
* <div g-portal="body">
|
|
9489
|
-
* <div class="modal">Modal content</div>
|
|
9490
|
-
* </div>
|
|
9491
|
-
*
|
|
9492
|
-
* @example
|
|
9493
|
-
* // Portal to specific element
|
|
9494
|
-
* <div g-portal="#notifications">
|
|
9495
|
-
* <div class="toast">Toast message</div>
|
|
9496
|
-
* </div>
|
|
9497
|
-
*/
|
|
9498
|
-
/**
|
|
9499
|
-
* Create a portal - Move element to target location
|
|
9500
|
-
*
|
|
9501
|
-
* @param sourceEl - Element to teleport
|
|
9502
|
-
* @param targetSelector - CSS selector for destination
|
|
9503
|
-
*
|
|
9504
|
-
* @example
|
|
9505
|
-
* portalCreate(modalEl, 'body');
|
|
9506
|
-
* portalCreate(tooltipEl, '#tooltip-container');
|
|
9507
|
-
*/
|
|
9508
|
-
function portalCreate(sourceEl, targetSelector) {
|
|
9509
|
-
if (!sourceEl)
|
|
9510
|
-
return;
|
|
9511
|
-
const target = document.querySelector(targetSelector);
|
|
9512
|
-
if (!target) {
|
|
9513
|
-
console.warn(`[GyosJS] Portal target "${targetSelector}" not found`);
|
|
9514
|
-
return;
|
|
9515
|
-
}
|
|
9516
|
-
// Create placeholder comment to mark original position
|
|
9517
|
-
const placeholder = document.createComment('g-portal');
|
|
9518
|
-
sourceEl.parentNode?.insertBefore(placeholder, sourceEl);
|
|
9519
|
-
// Store original parent for restoration
|
|
9520
|
-
sourceEl.__portal_placeholder__ = placeholder;
|
|
9521
|
-
sourceEl.__portal_target__ = target;
|
|
9522
|
-
// Move the entire element to target
|
|
9523
|
-
target.appendChild(sourceEl);
|
|
9524
|
-
DEBUG() && console.log('[Portal] Created - moved element to', targetSelector);
|
|
9525
|
-
}
|
|
9526
|
-
/**
|
|
9527
|
-
* Destroy a portal - Restore element to original position
|
|
9528
|
-
*
|
|
9529
|
-
* @param sourceEl - Element to restore
|
|
9530
|
-
*
|
|
9531
|
-
* @example
|
|
9532
|
-
* portalDestroy(modalEl); // Returns modal to original location
|
|
9533
|
-
*/
|
|
9534
|
-
function portalDestroy(sourceEl) {
|
|
9535
|
-
if (!sourceEl)
|
|
9536
|
-
return;
|
|
9537
|
-
const placeholder = sourceEl.__portal_placeholder__;
|
|
9538
|
-
if (placeholder && placeholder.parentNode) {
|
|
9539
|
-
// Move element back to original position
|
|
9540
|
-
placeholder.parentNode.insertBefore(sourceEl, placeholder);
|
|
9541
|
-
placeholder.remove();
|
|
9542
|
-
delete sourceEl.__portal_placeholder__;
|
|
9543
|
-
delete sourceEl.__portal_target__;
|
|
9544
|
-
DEBUG() && console.log('[Portal] Destroyed - restored element to original position');
|
|
9545
|
-
}
|
|
9546
|
-
}
|
|
9547
|
-
|
|
9548
9639
|
/**
|
|
9549
9640
|
* Validator registry
|
|
9550
9641
|
*/
|
|
@@ -9730,7 +9821,7 @@
|
|
|
9730
9821
|
* @example "min(18)"
|
|
9731
9822
|
*/
|
|
9732
9823
|
validator('min', (value, min) => {
|
|
9733
|
-
if (
|
|
9824
|
+
if (value == null || value === '')
|
|
9734
9825
|
return true;
|
|
9735
9826
|
const minVal = parseFloat(min);
|
|
9736
9827
|
return parseFloat(value) >= minVal || `Minimum value is ${minVal}`;
|
|
@@ -9741,7 +9832,7 @@
|
|
|
9741
9832
|
* @example "max(100)"
|
|
9742
9833
|
*/
|
|
9743
9834
|
validator('max', (value, max) => {
|
|
9744
|
-
if (
|
|
9835
|
+
if (value == null || value === '')
|
|
9745
9836
|
return true;
|
|
9746
9837
|
const maxVal = parseFloat(max);
|
|
9747
9838
|
return parseFloat(value) <= maxVal || `Maximum value is ${maxVal}`;
|
|
@@ -9762,9 +9853,9 @@
|
|
|
9762
9853
|
* @example "integer"
|
|
9763
9854
|
*/
|
|
9764
9855
|
validator('integer', (value) => {
|
|
9765
|
-
if (
|
|
9856
|
+
if (value == null || value === '')
|
|
9766
9857
|
return true;
|
|
9767
|
-
return Number.isInteger(
|
|
9858
|
+
return (String(value).trim() !== '' && Number.isInteger(Number(value))) || 'Must be an integer';
|
|
9768
9859
|
});
|
|
9769
9860
|
/**
|
|
9770
9861
|
* Numeric - Must contain only digits
|
|
@@ -9877,7 +9968,7 @@
|
|
|
9877
9968
|
return 'Invalid date format (use YYYY-MM-DD)';
|
|
9878
9969
|
}
|
|
9879
9970
|
const date = new Date(value);
|
|
9880
|
-
return !isNaN(date.getTime()) || 'Invalid date';
|
|
9971
|
+
return (!isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value) || 'Invalid date';
|
|
9881
9972
|
});
|
|
9882
9973
|
/**
|
|
9883
9974
|
* Before - Date must be before specified date
|
|
@@ -9957,7 +10048,7 @@
|
|
|
9957
10048
|
* @example "between(18,65)"
|
|
9958
10049
|
*/
|
|
9959
10050
|
validator('between', (value, min, max) => {
|
|
9960
|
-
if (
|
|
10051
|
+
if (value == null || value === '')
|
|
9961
10052
|
return true;
|
|
9962
10053
|
const num = parseFloat(value);
|
|
9963
10054
|
const minVal = parseFloat(min);
|
|
@@ -10211,8 +10302,16 @@
|
|
|
10211
10302
|
// Initialize error state - direct mutation
|
|
10212
10303
|
state.errors.value[modelAttr] = null;
|
|
10213
10304
|
state.touched.value[modelAttr] = false;
|
|
10214
|
-
|
|
10215
|
-
|
|
10305
|
+
let active = true;
|
|
10306
|
+
let generation = 0;
|
|
10307
|
+
let timeout;
|
|
10308
|
+
let latestValidation = Promise.resolve();
|
|
10309
|
+
// Each control publishes only its newest result. validateAll also waits for
|
|
10310
|
+
// a newer validation that superseded the request it originally started.
|
|
10311
|
+
const runValidation = async () => {
|
|
10312
|
+
if (!active)
|
|
10313
|
+
return;
|
|
10314
|
+
const request = ++generation;
|
|
10216
10315
|
const value = getControlValue(el, form);
|
|
10217
10316
|
// Get form context for validators that need it (like 'same')
|
|
10218
10317
|
const formData = {};
|
|
@@ -10227,7 +10326,26 @@
|
|
|
10227
10326
|
}
|
|
10228
10327
|
}
|
|
10229
10328
|
});
|
|
10230
|
-
|
|
10329
|
+
let error;
|
|
10330
|
+
try {
|
|
10331
|
+
error = await validate(value, rules, { form: formData, field: modelAttr });
|
|
10332
|
+
}
|
|
10333
|
+
catch (cause) {
|
|
10334
|
+
console.error('[GyosJS] Field validation failed:', cause);
|
|
10335
|
+
error = 'Validation failed. Please try again.';
|
|
10336
|
+
}
|
|
10337
|
+
if (!active)
|
|
10338
|
+
return;
|
|
10339
|
+
if (request !== generation) {
|
|
10340
|
+
await latestValidation;
|
|
10341
|
+
return;
|
|
10342
|
+
}
|
|
10343
|
+
// Input may have changed while its debounce timer has not fired yet.
|
|
10344
|
+
// A submit must validate the current value before publishing approval.
|
|
10345
|
+
if (value !== getControlValue(el, form)) {
|
|
10346
|
+
await validateField();
|
|
10347
|
+
return;
|
|
10348
|
+
}
|
|
10231
10349
|
// Update errors - only if changed
|
|
10232
10350
|
const currentErrors = state.errors.value;
|
|
10233
10351
|
if (currentErrors[modelAttr] !== error) {
|
|
@@ -10237,6 +10355,12 @@
|
|
|
10237
10355
|
updateFormState(state);
|
|
10238
10356
|
}
|
|
10239
10357
|
};
|
|
10358
|
+
const validateField = () => {
|
|
10359
|
+
clearTimeout(timeout);
|
|
10360
|
+
timeout = undefined;
|
|
10361
|
+
latestValidation = runValidation();
|
|
10362
|
+
return latestValidation;
|
|
10363
|
+
};
|
|
10240
10364
|
// Register validator for validateAll
|
|
10241
10365
|
if (!formValidators.has(form)) {
|
|
10242
10366
|
formValidators.set(form, []);
|
|
@@ -10254,7 +10378,6 @@
|
|
|
10254
10378
|
};
|
|
10255
10379
|
el.addEventListener('blur', blurListener);
|
|
10256
10380
|
// Validate on input (with debounce)
|
|
10257
|
-
let timeout;
|
|
10258
10381
|
const inputListener = () => {
|
|
10259
10382
|
clearTimeout(timeout);
|
|
10260
10383
|
timeout = setTimeout(() => {
|
|
@@ -10266,6 +10389,24 @@
|
|
|
10266
10389
|
el.__gyos_effects__ = [];
|
|
10267
10390
|
}
|
|
10268
10391
|
el.__gyos_effects__.push(() => {
|
|
10392
|
+
active = false;
|
|
10393
|
+
generation++;
|
|
10394
|
+
delete el[validationFieldKey];
|
|
10395
|
+
const validators = formValidators.get(form);
|
|
10396
|
+
const index = validators?.indexOf(validateField) ?? -1;
|
|
10397
|
+
if (index !== -1)
|
|
10398
|
+
validators.splice(index, 1);
|
|
10399
|
+
const sharesField = Array.from(form.querySelectorAll('input, textarea, select'))
|
|
10400
|
+
.some(control => control[validationFieldKey] === modelAttr);
|
|
10401
|
+
if (!sharesField) {
|
|
10402
|
+
const errors = { ...state.errors.peek };
|
|
10403
|
+
delete errors[modelAttr];
|
|
10404
|
+
const touched = { ...state.touched.peek };
|
|
10405
|
+
delete touched[modelAttr];
|
|
10406
|
+
state.errors.value = errors;
|
|
10407
|
+
state.touched.value = touched;
|
|
10408
|
+
updateFormState(state);
|
|
10409
|
+
}
|
|
10269
10410
|
el.removeEventListener('blur', blurListener);
|
|
10270
10411
|
el.removeEventListener('input', inputListener);
|
|
10271
10412
|
clearTimeout(timeout);
|
|
@@ -10338,7 +10479,9 @@
|
|
|
10338
10479
|
processFormDirective(root, scope);
|
|
10339
10480
|
}
|
|
10340
10481
|
// Then process g-validate
|
|
10341
|
-
root.querySelectorAll('[g-validate]').forEach(el => {
|
|
10482
|
+
[root, ...root.querySelectorAll('[g-validate]')].forEach(el => {
|
|
10483
|
+
if (!el.hasAttribute('g-validate'))
|
|
10484
|
+
return;
|
|
10342
10485
|
if (isInIgnoredTree(el))
|
|
10343
10486
|
return;
|
|
10344
10487
|
if (el instanceof HTMLElement) {
|
|
@@ -10346,7 +10489,9 @@
|
|
|
10346
10489
|
}
|
|
10347
10490
|
});
|
|
10348
10491
|
// Finally process g-errors
|
|
10349
|
-
root.querySelectorAll('[g-errors]').forEach(el => {
|
|
10492
|
+
[root, ...root.querySelectorAll('[g-errors]')].forEach(el => {
|
|
10493
|
+
if (!el.hasAttribute('g-errors'))
|
|
10494
|
+
return;
|
|
10350
10495
|
if (isInIgnoredTree(el))
|
|
10351
10496
|
return;
|
|
10352
10497
|
if (el instanceof HTMLElement) {
|
|
@@ -10377,12 +10522,13 @@
|
|
|
10377
10522
|
/**
|
|
10378
10523
|
* Execute handler with modifiers (prevent, stop)
|
|
10379
10524
|
*/
|
|
10380
|
-
function
|
|
10381
|
-
// Handle prevent/stop modifiers
|
|
10525
|
+
function applyEventModifiers(e, modifiers) {
|
|
10382
10526
|
if (modifiers.includes('prevent'))
|
|
10383
10527
|
e.preventDefault();
|
|
10384
10528
|
if (modifiers.includes('stop'))
|
|
10385
10529
|
e.stopPropagation();
|
|
10530
|
+
}
|
|
10531
|
+
function executeHandler(handler, scope, e) {
|
|
10386
10532
|
try {
|
|
10387
10533
|
expressionRuntime().execute(handler, scope, e);
|
|
10388
10534
|
}
|
|
@@ -10472,10 +10618,11 @@
|
|
|
10472
10618
|
if (target instanceof Element && target.closest('[g-ignore-outside-click]'))
|
|
10473
10619
|
return;
|
|
10474
10620
|
if (element !== target && !element.contains(target)) {
|
|
10621
|
+
applyEventModifiers(e, modifiers);
|
|
10475
10622
|
const currentScope = getScopeFromElement(element) || scope;
|
|
10476
10623
|
if (modifiers.includes('once'))
|
|
10477
10624
|
cleanup();
|
|
10478
|
-
executeHandler(handler, currentScope, e
|
|
10625
|
+
executeHandler(handler, currentScope, e);
|
|
10479
10626
|
}
|
|
10480
10627
|
};
|
|
10481
10628
|
// Cleanup function
|
|
@@ -10552,13 +10699,14 @@
|
|
|
10552
10699
|
return; // Key doesn't match, skip
|
|
10553
10700
|
}
|
|
10554
10701
|
// Execute handler with optional debounce
|
|
10702
|
+
applyEventModifiers(e, modifiers);
|
|
10555
10703
|
const execute = () => {
|
|
10556
10704
|
if (modifiers.includes('once'))
|
|
10557
10705
|
cleanup();
|
|
10558
10706
|
// Batch in case handler mutates multiple signals
|
|
10559
10707
|
batch(() => {
|
|
10560
10708
|
const currentScope = getScopeFromElement(element) || scope;
|
|
10561
|
-
executeHandler(handler, currentScope, e
|
|
10709
|
+
executeHandler(handler, currentScope, e);
|
|
10562
10710
|
});
|
|
10563
10711
|
};
|
|
10564
10712
|
if (debounceMs > 0) {
|
|
@@ -10808,60 +10956,6 @@
|
|
|
10808
10956
|
element.removeAttribute(modelAttr.name);
|
|
10809
10957
|
}
|
|
10810
10958
|
|
|
10811
|
-
/**
|
|
10812
|
-
* Cleanup utilities for disposing effects and event listeners
|
|
10813
|
-
*/
|
|
10814
|
-
/**
|
|
10815
|
-
* Dispose all effects attached to an element and its descendants
|
|
10816
|
-
* Handles both element effects (__gyos_effects__) and component lifecycle
|
|
10817
|
-
*/
|
|
10818
|
-
function disposeEffects(element = document.body, removeElement = false) {
|
|
10819
|
-
if (!element)
|
|
10820
|
-
return;
|
|
10821
|
-
// Unmount scope if element has one (calls onUnmount + cleans instance.__gyos_effects__)
|
|
10822
|
-
if (element.hasAttribute?.('g-scope') || element.__gyos_scope__) {
|
|
10823
|
-
unmountScope(element);
|
|
10824
|
-
}
|
|
10825
|
-
// Dispose effects on this element (template effects like g-show, :class, {text})
|
|
10826
|
-
if (element.__gyos_effects__) {
|
|
10827
|
-
const effects = element.__gyos_effects__;
|
|
10828
|
-
effects.forEach((dispose) => {
|
|
10829
|
-
try {
|
|
10830
|
-
dispose();
|
|
10831
|
-
}
|
|
10832
|
-
catch (error) {
|
|
10833
|
-
console.error('[GyosJS] Error disposing effect:', error);
|
|
10834
|
-
}
|
|
10835
|
-
});
|
|
10836
|
-
element.__gyos_effects__ = null;
|
|
10837
|
-
}
|
|
10838
|
-
// Recursively dispose effects on all descendants
|
|
10839
|
-
const descendants = element.querySelectorAll('*');
|
|
10840
|
-
descendants.forEach((child) => {
|
|
10841
|
-
// Unmount child scopes
|
|
10842
|
-
if (child.hasAttribute?.('g-scope') || child.__gyos_scope__) {
|
|
10843
|
-
unmountScope(child);
|
|
10844
|
-
}
|
|
10845
|
-
// Dispose child template effects
|
|
10846
|
-
if (child.__gyos_effects__) {
|
|
10847
|
-
const effects = child.__gyos_effects__;
|
|
10848
|
-
effects.forEach((dispose) => {
|
|
10849
|
-
try {
|
|
10850
|
-
dispose();
|
|
10851
|
-
}
|
|
10852
|
-
catch (error) {
|
|
10853
|
-
console.error('[GyosJS] Error disposing child effect:', error);
|
|
10854
|
-
}
|
|
10855
|
-
});
|
|
10856
|
-
child.__gyos_effects__ = null;
|
|
10857
|
-
}
|
|
10858
|
-
});
|
|
10859
|
-
// portal cleanup could be added here if needed
|
|
10860
|
-
portalDestroy(element);
|
|
10861
|
-
if (removeElement)
|
|
10862
|
-
element.remove();
|
|
10863
|
-
}
|
|
10864
|
-
|
|
10865
10959
|
const storeCache = new WeakMap();
|
|
10866
10960
|
const reactiveProxies = new WeakSet();
|
|
10867
10961
|
const fieldSignals = new WeakMap();
|
|
@@ -10876,7 +10970,7 @@
|
|
|
10876
10970
|
if (visited.has(ver))
|
|
10877
10971
|
return;
|
|
10878
10972
|
visited.add(ver);
|
|
10879
|
-
ver.value
|
|
10973
|
+
ver.update(value => value + 1);
|
|
10880
10974
|
const parents = versionParents.get(ver);
|
|
10881
10975
|
if (parents) {
|
|
10882
10976
|
parents.forEach(parentVer => bumpSignal(parentVer));
|
|
@@ -10914,7 +11008,7 @@
|
|
|
10914
11008
|
}
|
|
10915
11009
|
const STORE_MARKER = Symbol.for('gyos.store');
|
|
10916
11010
|
function markStore(obj) {
|
|
10917
|
-
if (
|
|
11011
|
+
if (Object.prototype.hasOwnProperty.call(obj, STORE_MARKER))
|
|
10918
11012
|
return obj;
|
|
10919
11013
|
Reflect.defineProperty(obj, STORE_MARKER, {
|
|
10920
11014
|
value: true,
|
|
@@ -10928,7 +11022,7 @@
|
|
|
10928
11022
|
// markRaw: đánh dấu object để reactive() bỏ qua, không tạo proxy
|
|
10929
11023
|
const RAW_MARKER = Symbol.for('gyos.raw');
|
|
10930
11024
|
function markRaw(obj) {
|
|
10931
|
-
if (
|
|
11025
|
+
if (Object.prototype.hasOwnProperty.call(obj, RAW_MARKER))
|
|
10932
11026
|
return obj;
|
|
10933
11027
|
Reflect.defineProperty(obj, RAW_MARKER, {
|
|
10934
11028
|
value: true,
|
|
@@ -10942,7 +11036,7 @@
|
|
|
10942
11036
|
// shallow: chỉ reactive "lớp ngoài", không reactive sâu bên trong
|
|
10943
11037
|
const SHALLOW_MARKER = Symbol.for('gyos.shallow');
|
|
10944
11038
|
function shallow(obj) {
|
|
10945
|
-
if (
|
|
11039
|
+
if (Object.prototype.hasOwnProperty.call(obj, SHALLOW_MARKER))
|
|
10946
11040
|
return obj;
|
|
10947
11041
|
Reflect.defineProperty(obj, SHALLOW_MARKER, {
|
|
10948
11042
|
value: true,
|
|
@@ -10976,6 +11070,25 @@
|
|
|
10976
11070
|
}
|
|
10977
11071
|
versionParentsSet.add(parentVersion);
|
|
10978
11072
|
}
|
|
11073
|
+
// Array [[DefineOwnProperty]] can change length or remove indices without
|
|
11074
|
+
// entering their individual Proxy traps. Keep already observed fields current.
|
|
11075
|
+
function syncArrayFields(target, previousLength) {
|
|
11076
|
+
if (previousLength === undefined)
|
|
11077
|
+
return;
|
|
11078
|
+
const array = target;
|
|
11079
|
+
if (array.length === previousLength)
|
|
11080
|
+
return;
|
|
11081
|
+
const signals = fieldSignals.get(target);
|
|
11082
|
+
signals?.get('length')?.update(() => array.length);
|
|
11083
|
+
if (array.length < previousLength) {
|
|
11084
|
+
signals?.forEach((sig, key) => {
|
|
11085
|
+
if (typeof key === 'string' && /^(0|[1-9]\d*)$/.test(key)
|
|
11086
|
+
&& Number(key) >= array.length && Number(key) < previousLength) {
|
|
11087
|
+
sig.update(() => Reflect.get(target, key));
|
|
11088
|
+
}
|
|
11089
|
+
});
|
|
11090
|
+
}
|
|
11091
|
+
}
|
|
10979
11092
|
function reactive(raw) {
|
|
10980
11093
|
if (!raw || typeof raw !== "object" || isBuiltInObject(raw)) {
|
|
10981
11094
|
return raw;
|
|
@@ -11013,6 +11126,8 @@
|
|
|
11013
11126
|
return value;
|
|
11014
11127
|
}
|
|
11015
11128
|
if (isStoreObject(value)) {
|
|
11129
|
+
if (hasCurrentEffect())
|
|
11130
|
+
getFieldSignal(target, key, value).value;
|
|
11016
11131
|
return value;
|
|
11017
11132
|
}
|
|
11018
11133
|
// Check if this is a getter property (computed property)
|
|
@@ -11089,10 +11204,6 @@
|
|
|
11089
11204
|
}
|
|
11090
11205
|
// capture old value BEFORE write to detect real changes
|
|
11091
11206
|
const oldValue = target[key];
|
|
11092
|
-
// VALUE LÀ STORE → set thẳng, KHÔNG tạo signal, KHÔNG trigger
|
|
11093
|
-
if (isStoreObject(value)) {
|
|
11094
|
-
return Reflect.set(target, key, value, receiver);
|
|
11095
|
-
}
|
|
11096
11207
|
const ok = Reflect.set(target, key, value, receiver);
|
|
11097
11208
|
if (!ok)
|
|
11098
11209
|
return false;
|
|
@@ -11134,7 +11245,9 @@
|
|
|
11134
11245
|
const oldDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
11135
11246
|
const oldValue = oldDesc && "value" in oldDesc ? oldDesc.value : undefined;
|
|
11136
11247
|
const newValue = "value" in descriptor ? descriptor.value : oldValue;
|
|
11248
|
+
const previousLength = Array.isArray(target) ? target.length : undefined;
|
|
11137
11249
|
const ok = Reflect.defineProperty(target, key, descriptor);
|
|
11250
|
+
syncArrayFields(target, previousLength);
|
|
11138
11251
|
if (!ok)
|
|
11139
11252
|
return false;
|
|
11140
11253
|
if ('value' in descriptor) {
|
|
@@ -11160,7 +11273,7 @@
|
|
|
11160
11273
|
// tạo 1 version signal cho root scope
|
|
11161
11274
|
const version = ensureVersion(source);
|
|
11162
11275
|
const proxy = reactive(source);
|
|
11163
|
-
if (!
|
|
11276
|
+
if (!Object.prototype.hasOwnProperty.call(proxy, SCOPE_VERSION)) {
|
|
11164
11277
|
Object.defineProperty(proxy, SCOPE_VERSION, {
|
|
11165
11278
|
value: version,
|
|
11166
11279
|
enumerable: false,
|
|
@@ -11282,6 +11395,20 @@
|
|
|
11282
11395
|
function setRootScope(element, scope) {
|
|
11283
11396
|
element.__gyos_scope__ = scope;
|
|
11284
11397
|
}
|
|
11398
|
+
function inheritScope(child, parent) {
|
|
11399
|
+
attachParentScope(child, parent);
|
|
11400
|
+
for (const key in parent) {
|
|
11401
|
+
if (!(key in child)) {
|
|
11402
|
+
Object.defineProperty(child, key, {
|
|
11403
|
+
get: () => parent[key],
|
|
11404
|
+
set: value => { parent[key] = value; },
|
|
11405
|
+
enumerable: true,
|
|
11406
|
+
configurable: true,
|
|
11407
|
+
});
|
|
11408
|
+
}
|
|
11409
|
+
}
|
|
11410
|
+
return child;
|
|
11411
|
+
}
|
|
11285
11412
|
/**
|
|
11286
11413
|
* Create child scope for *for loops
|
|
11287
11414
|
* Inherits parent scope properties via getters
|
|
@@ -11352,13 +11479,15 @@
|
|
|
11352
11479
|
template.removeAttribute('g-key');
|
|
11353
11480
|
const placeholder = document.createComment('*for');
|
|
11354
11481
|
element.parentNode?.replaceChild(placeholder, element);
|
|
11482
|
+
const end = document.createComment('/*for');
|
|
11483
|
+
placeholder.parentNode?.insertBefore(end, placeholder.nextSibling);
|
|
11355
11484
|
// Store previous items for key-based diffing
|
|
11356
11485
|
// WARNING: Use primitive keys (id, string, number) to avoid memory leaks
|
|
11357
11486
|
// Object keys will prevent garbage collection
|
|
11358
11487
|
let prevItemsMap = new Map();
|
|
11359
11488
|
let prevListRef = null;
|
|
11360
11489
|
let prevVersionValue = undefined;
|
|
11361
|
-
queueReactiveEffect(
|
|
11490
|
+
queueReactiveEffect(placeholder, () => {
|
|
11362
11491
|
// Parse: "item in items" or "item, index in items"
|
|
11363
11492
|
const match = expr.match(/(.+?)\s+in\s+(.+)/);
|
|
11364
11493
|
if (!match)
|
|
@@ -11385,7 +11514,7 @@
|
|
|
11385
11514
|
}
|
|
11386
11515
|
else {
|
|
11387
11516
|
// Simple re-render (no diffing)
|
|
11388
|
-
processForSimple(placeholder, template, list, itemVar, currentScope);
|
|
11517
|
+
processForSimple(placeholder, end, template, list, itemVar, currentScope);
|
|
11389
11518
|
}
|
|
11390
11519
|
});
|
|
11391
11520
|
});
|
|
@@ -11492,16 +11621,19 @@
|
|
|
11492
11621
|
/**
|
|
11493
11622
|
* Process *for without keys (simple re-render)
|
|
11494
11623
|
*/
|
|
11495
|
-
function processForSimple(placeholder, template, list, itemVar, currentScope) {
|
|
11624
|
+
function processForSimple(placeholder, end, template, list, itemVar, currentScope) {
|
|
11496
11625
|
// Remove all existing items
|
|
11497
11626
|
let next = placeholder.nextSibling;
|
|
11498
|
-
while (next && next
|
|
11627
|
+
while (next && next !== end) {
|
|
11499
11628
|
const toRemove = next;
|
|
11500
11629
|
next = next.nextSibling;
|
|
11501
11630
|
if (toRemove instanceof Element) {
|
|
11502
11631
|
unmountChildScopes(toRemove);
|
|
11503
11632
|
disposeEffects(toRemove, true);
|
|
11504
11633
|
}
|
|
11634
|
+
else {
|
|
11635
|
+
disposeNode(toRemove, true);
|
|
11636
|
+
}
|
|
11505
11637
|
}
|
|
11506
11638
|
// Render new items
|
|
11507
11639
|
// Track last inserted node to maintain order
|
|
@@ -11594,7 +11726,7 @@
|
|
|
11594
11726
|
element.parentNode?.replaceChild(placeholder, element);
|
|
11595
11727
|
let currentElement = null;
|
|
11596
11728
|
let currentIndex = -1;
|
|
11597
|
-
queueReactiveEffect(
|
|
11729
|
+
queueReactiveEffect(placeholder, () => {
|
|
11598
11730
|
// Find first truthy condition
|
|
11599
11731
|
let matchedIndex = -1;
|
|
11600
11732
|
for (let i = 0; i < templates.length; i++) {
|
|
@@ -11720,14 +11852,13 @@
|
|
|
11720
11852
|
const switchValue = evaluateExpression(switchExpr, currentScope, false);
|
|
11721
11853
|
// Find matching case
|
|
11722
11854
|
let matchedIndex = -1;
|
|
11855
|
+
let defaultIndex = -1;
|
|
11723
11856
|
for (let i = 0; i < templates.length; i++) {
|
|
11724
11857
|
const { value } = templates[i];
|
|
11725
11858
|
if (value === null) {
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
}
|
|
11730
|
-
break;
|
|
11859
|
+
if (defaultIndex === -1)
|
|
11860
|
+
defaultIndex = i;
|
|
11861
|
+
continue;
|
|
11731
11862
|
}
|
|
11732
11863
|
const caseValue = evaluateExpression(value, currentScope, false);
|
|
11733
11864
|
if (switchValue === caseValue) {
|
|
@@ -11735,6 +11866,8 @@
|
|
|
11735
11866
|
break;
|
|
11736
11867
|
}
|
|
11737
11868
|
}
|
|
11869
|
+
if (matchedIndex === -1)
|
|
11870
|
+
matchedIndex = defaultIndex;
|
|
11738
11871
|
// If same case, do nothing
|
|
11739
11872
|
if (matchedIndex === currentIndex)
|
|
11740
11873
|
return;
|
|
@@ -11853,6 +11986,7 @@
|
|
|
11853
11986
|
let requestVersion = 0;
|
|
11854
11987
|
// Helper to render state
|
|
11855
11988
|
const renderState = (state, data) => {
|
|
11989
|
+
currentState = state;
|
|
11856
11990
|
// Remove old element
|
|
11857
11991
|
if (currentElement) {
|
|
11858
11992
|
const elemToRemove = currentElement;
|
|
@@ -11878,20 +12012,19 @@
|
|
|
11878
12012
|
else if (state === 'fulfilled' && thenTemplate) {
|
|
11879
12013
|
template = thenTemplate.template;
|
|
11880
12014
|
// Create child scope with data if varName provided
|
|
11881
|
-
if (thenTemplate.varName
|
|
11882
|
-
scope = {
|
|
12015
|
+
if (thenTemplate.varName) {
|
|
12016
|
+
scope = inheritScope({ [thenTemplate.varName]: data }, currentScope);
|
|
11883
12017
|
}
|
|
11884
12018
|
}
|
|
11885
12019
|
else if (state === 'rejected' && catchTemplate) {
|
|
11886
12020
|
template = catchTemplate.template;
|
|
11887
12021
|
// Create child scope with error if varName provided
|
|
11888
|
-
if (catchTemplate.varName
|
|
11889
|
-
scope = {
|
|
12022
|
+
if (catchTemplate.varName) {
|
|
12023
|
+
scope = inheritScope({ [catchTemplate.varName]: data }, currentScope);
|
|
11890
12024
|
}
|
|
11891
12025
|
}
|
|
11892
12026
|
if (template) {
|
|
11893
12027
|
currentElement = getCachedTemplate(template);
|
|
11894
|
-
currentState = state;
|
|
11895
12028
|
setRootScope(currentElement, scope);
|
|
11896
12029
|
// Apply transition initial state
|
|
11897
12030
|
const elementsWithTransition = findElementsWithTransition(currentElement);
|
|
@@ -11919,8 +12052,6 @@
|
|
|
11919
12052
|
}
|
|
11920
12053
|
}
|
|
11921
12054
|
};
|
|
11922
|
-
// Initial state: pending
|
|
11923
|
-
renderState('pending');
|
|
11924
12055
|
// Track promise expression
|
|
11925
12056
|
queueReactiveEffect(element, () => {
|
|
11926
12057
|
const promiseOrValue = evaluateExpression(awaitExpr, currentScope, false);
|
|
@@ -11944,6 +12075,8 @@
|
|
|
11944
12075
|
renderState('rejected', error);
|
|
11945
12076
|
}
|
|
11946
12077
|
});
|
|
12078
|
+
// Both reruns and disposal invalidate callbacks from this request.
|
|
12079
|
+
return () => { requestVersion++; };
|
|
11947
12080
|
});
|
|
11948
12081
|
}
|
|
11949
12082
|
|
|
@@ -12011,6 +12144,9 @@
|
|
|
12011
12144
|
structuralElements.sort((a, b) => a.depth - b.depth);
|
|
12012
12145
|
// Process each structural directive
|
|
12013
12146
|
structuralElements.forEach(({ element, type }) => {
|
|
12147
|
+
// Parent directives parse their clones, not the detached original tree.
|
|
12148
|
+
if (!root.contains(element) || elementBelongsToAnotherScope(element, scope))
|
|
12149
|
+
return;
|
|
12014
12150
|
if (type === 'for') {
|
|
12015
12151
|
processForDirective(element, scope);
|
|
12016
12152
|
}
|
|
@@ -12046,6 +12182,10 @@
|
|
|
12046
12182
|
function processParse(element, scope, fromStructural = false) {
|
|
12047
12183
|
if (isInIgnoredTree(element))
|
|
12048
12184
|
return;
|
|
12185
|
+
if (fromStructural && element.hasAttribute('g-scope') && mountFunction) {
|
|
12186
|
+
mountFunction(element);
|
|
12187
|
+
return;
|
|
12188
|
+
}
|
|
12049
12189
|
beginEffectCollection();
|
|
12050
12190
|
const allElements = [
|
|
12051
12191
|
element,
|
|
@@ -12067,7 +12207,7 @@
|
|
|
12067
12207
|
return;
|
|
12068
12208
|
if (el.attributes.length === 0)
|
|
12069
12209
|
return; // Skip if no attributes
|
|
12070
|
-
if (elementBelongsToAnotherScope(el, scope)
|
|
12210
|
+
if (elementBelongsToAnotherScope(el, scope)) {
|
|
12071
12211
|
// (fromStructural allows processing newly created elements inside structurals)
|
|
12072
12212
|
return; // Skip if inside mounted scope
|
|
12073
12213
|
}
|
|
@@ -12075,8 +12215,9 @@
|
|
|
12075
12215
|
if (el.hasAttribute('g-static')) {
|
|
12076
12216
|
// Pre-process g-static elements (mark and render them before reactive processing)
|
|
12077
12217
|
processStaticElements(el, scope);
|
|
12218
|
+
return;
|
|
12078
12219
|
}
|
|
12079
|
-
if (el.hasAttribute('g-form')) {
|
|
12220
|
+
if (el.hasAttribute('g-form') || el.hasAttribute('g-validate') || el.hasAttribute('g-errors')) {
|
|
12080
12221
|
// Process form validation (g-form, g-validate, g-errors)
|
|
12081
12222
|
processFormValidation(el, scope);
|
|
12082
12223
|
}
|
|
@@ -12426,7 +12567,7 @@
|
|
|
12426
12567
|
const allElements = [...elements, ...elementsNotScope].filter(el => !isInIgnoredTree(el));
|
|
12427
12568
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
12428
12569
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
12429
|
-
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
12570
|
+
allElements.forEach(el => !el.hasAttribute('*if') && !el.hasAttribute('*for') && !hasStructuralParent(el) && mount(el));
|
|
12430
12571
|
diagnoseUnscopedReveals(document.body);
|
|
12431
12572
|
}
|
|
12432
12573
|
function mountTree(el) {
|
|
@@ -12437,7 +12578,7 @@
|
|
|
12437
12578
|
.filter(element => element.hasAttribute('g-scope') || hasAutoScope(element));
|
|
12438
12579
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
12439
12580
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
12440
|
-
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
12581
|
+
candidates.forEach(element => !element.hasAttribute('*if') && !element.hasAttribute('*for') && !hasStructuralParent(element) && mount(element));
|
|
12441
12582
|
diagnoseUnscopedReveals(el);
|
|
12442
12583
|
if (getMountedScope(el))
|
|
12443
12584
|
return;
|
|
@@ -12466,9 +12607,17 @@
|
|
|
12466
12607
|
/**
|
|
12467
12608
|
* Parse inline scope definition from HTML attribute
|
|
12468
12609
|
*/
|
|
12610
|
+
function decodeMarkupExpression(value) {
|
|
12611
|
+
try {
|
|
12612
|
+
return decodeURIComponent(value);
|
|
12613
|
+
}
|
|
12614
|
+
catch {
|
|
12615
|
+
return value;
|
|
12616
|
+
} // Plain expressions may contain a literal % or modulo.
|
|
12617
|
+
}
|
|
12469
12618
|
function parseInlineScope(scopeStr) {
|
|
12470
12619
|
// If scopeStr is encode urld, decode it first
|
|
12471
|
-
scopeStr =
|
|
12620
|
+
scopeStr = decodeMarkupExpression(scopeStr);
|
|
12472
12621
|
try {
|
|
12473
12622
|
// Check if it's an inline object definition (starts with '{')
|
|
12474
12623
|
const trimmed = scopeStr.trim();
|
|
@@ -12535,7 +12684,7 @@
|
|
|
12535
12684
|
// gm-method-name:args:arg2="expression"
|
|
12536
12685
|
if (attr.name.match(/^gm-.+/)) {
|
|
12537
12686
|
// If expr is encoded url, decode it first
|
|
12538
|
-
const expr =
|
|
12687
|
+
const expr = decodeMarkupExpression(attr.value.trim());
|
|
12539
12688
|
if (forbidden.some(f => expr.includes(f))) {
|
|
12540
12689
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
12541
12690
|
}
|
|
@@ -12646,15 +12795,11 @@
|
|
|
12646
12795
|
* Mount a specific scope
|
|
12647
12796
|
*/
|
|
12648
12797
|
function mountScope(el, scopeAttr) {
|
|
12649
|
-
const definition = handleDefinition(el, scopeAttr);
|
|
12650
12798
|
// Check if already mounted
|
|
12651
12799
|
if (getMountedScope(el)) {
|
|
12652
12800
|
return;
|
|
12653
12801
|
}
|
|
12654
|
-
|
|
12655
|
-
if (el.hasAttribute('g-static')) {
|
|
12656
|
-
return;
|
|
12657
|
-
}
|
|
12802
|
+
const definition = handleDefinition(el, scopeAttr);
|
|
12658
12803
|
// Check hydration strategy
|
|
12659
12804
|
const hydrationStrategy = getHydrationStrategy(el);
|
|
12660
12805
|
if (hydrationStrategy) {
|
|
@@ -12677,8 +12822,9 @@
|
|
|
12677
12822
|
if (typeof definition === 'object') {
|
|
12678
12823
|
instance = makeReactive(definition);
|
|
12679
12824
|
}
|
|
12680
|
-
//
|
|
12681
|
-
|
|
12825
|
+
// Factories receive context before their reactive instance exists. Resolve it
|
|
12826
|
+
// when an observer is registered so captured context also works in onMount.
|
|
12827
|
+
const context = createContext(el, () => instance);
|
|
12682
12828
|
// If function component, call it now with context
|
|
12683
12829
|
if (typeof definition === 'function' && !instance) {
|
|
12684
12830
|
const factoryResult = definition(context);
|
|
@@ -12718,13 +12864,21 @@
|
|
|
12718
12864
|
// Parse and bind template (portals will be processed inside *if)
|
|
12719
12865
|
// Pass onMount callback to be called after parsing (or after hydration triggers)
|
|
12720
12866
|
parseTemplate(el, instance, () => {
|
|
12867
|
+
// The hook may inspect or clean up its own mount. Register before calling
|
|
12868
|
+
// user code, and do not register again if the hook disposes the scope.
|
|
12869
|
+
registerMountedScope(el, instance);
|
|
12721
12870
|
// Call lifecycle hook after template is parsed
|
|
12722
12871
|
if (instance.onMount) {
|
|
12723
|
-
|
|
12872
|
+
try {
|
|
12873
|
+
Promise.resolve(instance.onMount.call(instance)).catch(console.error);
|
|
12874
|
+
}
|
|
12875
|
+
catch (error) {
|
|
12876
|
+
console.error('[Component] Error in onMount:', error);
|
|
12877
|
+
}
|
|
12724
12878
|
}
|
|
12725
12879
|
});
|
|
12726
|
-
|
|
12727
|
-
|
|
12880
|
+
if (getMountedScope(el) !== instance)
|
|
12881
|
+
return;
|
|
12728
12882
|
// Cache instance if g-scope-persist is set (with interpolation support)
|
|
12729
12883
|
getPersistKey$1(el, persistKey => {
|
|
12730
12884
|
if (!scopeCached.has(persistKey)) {
|
|
@@ -12735,12 +12889,12 @@
|
|
|
12735
12889
|
/**
|
|
12736
12890
|
* Create component context
|
|
12737
12891
|
*/
|
|
12738
|
-
function createContext(el,
|
|
12892
|
+
function createContext(el, getInstance) {
|
|
12739
12893
|
const refs = {};
|
|
12740
12894
|
const events = new Map();
|
|
12741
12895
|
// Find all refs within this scope only
|
|
12742
12896
|
el.querySelectorAll('[g-ref]').forEach(refEl => {
|
|
12743
|
-
if (isInIgnoredTree(refEl))
|
|
12897
|
+
if (isInIgnoredTree(refEl) || (refEl.closest('[g-scope]') || el) !== el)
|
|
12744
12898
|
return;
|
|
12745
12899
|
const refName = refEl.getAttribute('g-ref');
|
|
12746
12900
|
if (refName && !hasUnsafePropertyPath(refName)) {
|
|
@@ -12783,19 +12937,23 @@
|
|
|
12783
12937
|
},
|
|
12784
12938
|
$watch: (key, handler, options = {}) => {
|
|
12785
12939
|
// Watch a reactive property for changes (supports nested paths like 'xxx.count')
|
|
12940
|
+
const instance = getInstance();
|
|
12786
12941
|
if (!instance) {
|
|
12787
12942
|
DEBUG() && console.warn('[Component] $watch called before instance created');
|
|
12788
12943
|
return () => { };
|
|
12789
12944
|
}
|
|
12790
12945
|
const { immediate = false, deep = false, debounce = 0 } = options;
|
|
12791
12946
|
let timeoutId;
|
|
12947
|
+
let active = true;
|
|
12792
12948
|
if (debounce > 0) {
|
|
12793
12949
|
// Wrap handler with debounce
|
|
12794
12950
|
const originalHandler = handler;
|
|
12795
12951
|
handler = (...args) => {
|
|
12796
12952
|
clearTimeout(timeoutId);
|
|
12797
12953
|
timeoutId = setTimeout(() => {
|
|
12798
|
-
|
|
12954
|
+
timeoutId = undefined;
|
|
12955
|
+
if (active)
|
|
12956
|
+
untrack(() => originalHandler.call(instance, ...args));
|
|
12799
12957
|
}, debounce);
|
|
12800
12958
|
};
|
|
12801
12959
|
}
|
|
@@ -12824,31 +12982,38 @@
|
|
|
12824
12982
|
initialized = true;
|
|
12825
12983
|
// Call immediately if requested
|
|
12826
12984
|
if (immediate) {
|
|
12827
|
-
handler.call(instance, clonedValue, undefined);
|
|
12985
|
+
untrack(() => handler.call(instance, clonedValue, undefined));
|
|
12828
12986
|
}
|
|
12829
12987
|
return;
|
|
12830
12988
|
}
|
|
12831
12989
|
// Check if value actually changed
|
|
12832
12990
|
const changed = deep
|
|
12833
12991
|
? !deepEqual(oldValue, clonedValue)
|
|
12834
|
-
: oldValue
|
|
12992
|
+
: !Object.is(oldValue, clonedValue);
|
|
12835
12993
|
if (changed) {
|
|
12836
|
-
handler.call(instance, clonedValue, oldValue);
|
|
12994
|
+
untrack(() => handler.call(instance, clonedValue, oldValue));
|
|
12837
12995
|
oldValue = deep && typeof clonedValue === 'object'
|
|
12838
12996
|
? clone(clonedValue)
|
|
12839
12997
|
: clonedValue;
|
|
12840
12998
|
}
|
|
12841
12999
|
});
|
|
13000
|
+
const stopWatching = () => {
|
|
13001
|
+
active = false;
|
|
13002
|
+
clearTimeout(timeoutId);
|
|
13003
|
+
timeoutId = undefined;
|
|
13004
|
+
watchEffect();
|
|
13005
|
+
};
|
|
12842
13006
|
// Store cleanup for unmount
|
|
12843
13007
|
if (!instance.__gyos_effects__) {
|
|
12844
13008
|
instance.__gyos_effects__ = [];
|
|
12845
13009
|
}
|
|
12846
|
-
instance.__gyos_effects__.push(
|
|
13010
|
+
instance.__gyos_effects__.push(stopWatching);
|
|
12847
13011
|
// Return unwatch function
|
|
12848
|
-
return
|
|
13012
|
+
return stopWatching;
|
|
12849
13013
|
},
|
|
12850
13014
|
$effect: (fn) => {
|
|
12851
13015
|
// Shorthand for effect with auto cleanup on unmount
|
|
13016
|
+
const instance = getInstance();
|
|
12852
13017
|
if (!instance) {
|
|
12853
13018
|
DEBUG() && console.warn('[Component] $effect called before instance created');
|
|
12854
13019
|
return () => { };
|
|
@@ -13052,8 +13217,8 @@
|
|
|
13052
13217
|
*/
|
|
13053
13218
|
function once(event, handler) {
|
|
13054
13219
|
const wrapper = (...args) => {
|
|
13055
|
-
handler(...args);
|
|
13056
13220
|
off(event, wrapper);
|
|
13221
|
+
handler(...args);
|
|
13057
13222
|
};
|
|
13058
13223
|
return on(event, wrapper);
|
|
13059
13224
|
}
|
|
@@ -13091,23 +13256,34 @@
|
|
|
13091
13256
|
const data = signal(null);
|
|
13092
13257
|
const loading = signal(true);
|
|
13093
13258
|
const error = signal(null);
|
|
13259
|
+
let generation = 0;
|
|
13260
|
+
let active = true;
|
|
13094
13261
|
const fetchData = async () => {
|
|
13262
|
+
if (!active)
|
|
13263
|
+
return;
|
|
13264
|
+
const requestId = ++generation;
|
|
13095
13265
|
loading.value = true;
|
|
13096
13266
|
error.value = null;
|
|
13097
13267
|
data.value = null;
|
|
13098
13268
|
try {
|
|
13099
13269
|
const request = typeof url === 'function' ? await url() : url;
|
|
13270
|
+
if (requestId !== generation)
|
|
13271
|
+
return;
|
|
13100
13272
|
const response = typeof request === 'string' ? await fetch(request) : request;
|
|
13101
13273
|
if (!response.ok) {
|
|
13102
13274
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
13103
13275
|
}
|
|
13104
|
-
|
|
13276
|
+
const result = await response.json();
|
|
13277
|
+
if (requestId === generation)
|
|
13278
|
+
data.value = result;
|
|
13105
13279
|
}
|
|
13106
13280
|
catch (e) {
|
|
13107
|
-
|
|
13281
|
+
if (requestId === generation)
|
|
13282
|
+
error.value = e;
|
|
13108
13283
|
}
|
|
13109
13284
|
finally {
|
|
13110
|
-
|
|
13285
|
+
if (requestId === generation)
|
|
13286
|
+
loading.value = false;
|
|
13111
13287
|
}
|
|
13112
13288
|
};
|
|
13113
13289
|
return {
|
|
@@ -13115,7 +13291,8 @@
|
|
|
13115
13291
|
loading,
|
|
13116
13292
|
error,
|
|
13117
13293
|
refetch: fetchData,
|
|
13118
|
-
onMount: fetchData
|
|
13294
|
+
onMount: () => { active = true; return fetchData(); },
|
|
13295
|
+
onUnmount: () => { active = false; generation++; loading.value = false; }
|
|
13119
13296
|
};
|
|
13120
13297
|
}
|
|
13121
13298
|
/**
|
|
@@ -13373,17 +13550,26 @@
|
|
|
13373
13550
|
const data = signal(null);
|
|
13374
13551
|
const loading = signal(false);
|
|
13375
13552
|
const error = signal(null);
|
|
13553
|
+
let generation = 0;
|
|
13554
|
+
let active = true;
|
|
13376
13555
|
const execute = async () => {
|
|
13556
|
+
if (!active)
|
|
13557
|
+
return;
|
|
13558
|
+
const requestId = ++generation;
|
|
13377
13559
|
loading.value = true;
|
|
13378
13560
|
error.value = null;
|
|
13379
13561
|
try {
|
|
13380
|
-
|
|
13562
|
+
const result = await asyncFn();
|
|
13563
|
+
if (requestId === generation)
|
|
13564
|
+
data.value = result;
|
|
13381
13565
|
}
|
|
13382
13566
|
catch (e) {
|
|
13383
|
-
|
|
13567
|
+
if (requestId === generation)
|
|
13568
|
+
error.value = e;
|
|
13384
13569
|
}
|
|
13385
13570
|
finally {
|
|
13386
|
-
|
|
13571
|
+
if (requestId === generation)
|
|
13572
|
+
loading.value = false;
|
|
13387
13573
|
}
|
|
13388
13574
|
};
|
|
13389
13575
|
return {
|
|
@@ -13392,9 +13578,10 @@
|
|
|
13392
13578
|
error,
|
|
13393
13579
|
execute,
|
|
13394
13580
|
onMount: () => {
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
}
|
|
13581
|
+
active = true;
|
|
13582
|
+
return immediate ? execute() : undefined;
|
|
13583
|
+
},
|
|
13584
|
+
onUnmount: () => { active = false; generation++; loading.value = false; }
|
|
13398
13585
|
};
|
|
13399
13586
|
}
|
|
13400
13587
|
|
|
@@ -13868,7 +14055,10 @@
|
|
|
13868
14055
|
Array.from(source.attributes).forEach(attribute => {
|
|
13869
14056
|
sourceAttributes.add(attribute.name);
|
|
13870
14057
|
if (target.getAttribute(attribute.name) !== attribute.value) {
|
|
13871
|
-
|
|
14058
|
+
// HTML permits directive names such as @click and *if, while older
|
|
14059
|
+
// DOM implementations apply XML name validation in setAttribute.
|
|
14060
|
+
// Transfer the already-parsed Attr without validating its name again.
|
|
14061
|
+
target.setAttributeNodeNS(target.ownerDocument.importNode(attribute, true));
|
|
13872
14062
|
}
|
|
13873
14063
|
});
|
|
13874
14064
|
Array.from(target.attributes).forEach(attribute => {
|
|
@@ -14152,7 +14342,14 @@
|
|
|
14152
14342
|
// Hash scrolling
|
|
14153
14343
|
const hash = new URL(url).hash;
|
|
14154
14344
|
if (hash) {
|
|
14155
|
-
|
|
14345
|
+
// A URL fragment identifies an id, not a CSS selector. Numeric ids,
|
|
14346
|
+
// punctuation and percent-encoded Unicode must work without escaping.
|
|
14347
|
+
let id = hash.slice(1);
|
|
14348
|
+
try {
|
|
14349
|
+
id = decodeURIComponent(id);
|
|
14350
|
+
}
|
|
14351
|
+
catch { /* Keep malformed fragments literal. */ }
|
|
14352
|
+
const el = document.getElementById(id);
|
|
14156
14353
|
if (el) {
|
|
14157
14354
|
el.scrollIntoView({ behavior: 'smooth' });
|
|
14158
14355
|
return;
|
|
@@ -14732,6 +14929,12 @@
|
|
|
14732
14929
|
return fragment?.cloneNode(true);
|
|
14733
14930
|
}
|
|
14734
14931
|
function cloneHistoryTarget(target) {
|
|
14932
|
+
// Mounted templates have already consumed event/model attributes and text
|
|
14933
|
+
// expressions. A DOM clone cannot recreate their observers. Restore these
|
|
14934
|
+
// targets from response HTML (snapshot or fetch) instead of caching inert UI.
|
|
14935
|
+
if (getScopeFromElement(target) || Array.from(target.querySelectorAll('*'))
|
|
14936
|
+
.some(element => element.__gyos_scope__))
|
|
14937
|
+
return null;
|
|
14735
14938
|
const clone = target.cloneNode(true);
|
|
14736
14939
|
clone.querySelectorAll('.gyos-target-spinner').forEach(spinner => spinner.remove());
|
|
14737
14940
|
return clone;
|
|
@@ -15589,7 +15792,7 @@
|
|
|
15589
15792
|
portalCreate,
|
|
15590
15793
|
portalDestroy,
|
|
15591
15794
|
setCspNonce,
|
|
15592
|
-
version: '0.5.
|
|
15795
|
+
version: '0.5.4'
|
|
15593
15796
|
};
|
|
15594
15797
|
|
|
15595
15798
|
setExpressionRuntime(cspExpressionRuntime);
|