@mintjamsinc/ichigojs 0.1.6 → 0.1.8
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 +101 -8
- package/dist/ichigo.esm.js +493 -10
- package/dist/ichigo.esm.js.map +1 -1
- package/dist/ichigo.esm.min.js +1 -1
- package/dist/ichigo.esm.min.js.map +1 -1
- package/dist/ichigo.umd.js +493 -10
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/dist/ichigo.umd.min.js.map +1 -1
- package/dist/types/ichigo/directives/StandardDirectiveName.d.ts +3 -1
- package/dist/types/ichigo/directives/VBindDirective.d.ts +9 -0
- package/dist/types/ichigo/directives/VDirective.d.ts +2 -1
- package/dist/types/ichigo/directives/VDirectiveManager.d.ts +18 -0
- package/dist/types/ichigo/directives/VIntersectionDirective.d.ts +91 -0
- package/dist/types/ichigo/directives/VOnDirective.d.ts +2 -2
- package/dist/types/ichigo/directives/VResizeDirective.d.ts +84 -0
- package/package.json +1 -1
package/dist/ichigo.esm.js
CHANGED
@@ -53,6 +53,8 @@ var StandardDirectiveName;
|
|
53
53
|
StandardDirectiveName["V_ON"] = "v-on";
|
54
54
|
StandardDirectiveName["V_BIND"] = "v-bind";
|
55
55
|
StandardDirectiveName["V_MODEL"] = "v-model";
|
56
|
+
StandardDirectiveName["V_RESIZE"] = "v-resize";
|
57
|
+
StandardDirectiveName["V_INTERSECTION"] = "v-intersection";
|
56
58
|
})(StandardDirectiveName || (StandardDirectiveName = {}));
|
57
59
|
|
58
60
|
// This file was generated. Do not modify manually!
|
@@ -6867,6 +6869,19 @@ class VBindDirective {
|
|
6867
6869
|
get isKey() {
|
6868
6870
|
return (this.#attributeName === 'key');
|
6869
6871
|
}
|
6872
|
+
/**
|
6873
|
+
* Indicates if this directive is binding the "options" attribute or any of its sub-properties (e.g., "options.intersection").
|
6874
|
+
* The "options" attribute is special and is used for passing options to certain directives like VIntersectionDirective.
|
6875
|
+
*/
|
6876
|
+
get isOptions() {
|
6877
|
+
return (this.#attributeName === 'options' || this.#attributeName?.startsWith('options.') === true);
|
6878
|
+
}
|
6879
|
+
/**
|
6880
|
+
* Gets the name of the attribute being bound (e.g., "src", "class", "options", "options.intersection").
|
6881
|
+
*/
|
6882
|
+
get attributeName() {
|
6883
|
+
return this.#attributeName;
|
6884
|
+
}
|
6870
6885
|
/**
|
6871
6886
|
* Gets the original expression string from the directive.
|
6872
6887
|
*/
|
@@ -6919,8 +6934,8 @@ class VBindDirective {
|
|
6919
6934
|
* Renders the bound attribute by evaluating the expression and updating the DOM element.
|
6920
6935
|
*/
|
6921
6936
|
#render() {
|
6922
|
-
//
|
6923
|
-
if (this.isKey) {
|
6937
|
+
// Do nothing for special attributes
|
6938
|
+
if (this.isKey || this.isOptions) {
|
6924
6939
|
return;
|
6925
6940
|
}
|
6926
6941
|
const element = this.#vNode.node;
|
@@ -7364,16 +7379,47 @@ class VBindings {
|
|
7364
7379
|
}
|
7365
7380
|
|
7366
7381
|
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
7382
|
+
/**
|
7383
|
+
* Manages directives associated with a virtual node (VNode).
|
7384
|
+
* This class is responsible for parsing, storing, and managing the lifecycle of directives.
|
7385
|
+
* It also provides access to bindings preparers and DOM updaters from the associated directives.
|
7386
|
+
*/
|
7367
7387
|
class VDirectiveManager {
|
7368
7388
|
/**
|
7369
7389
|
* The virtual node to which this directive handler is associated.
|
7370
7390
|
*/
|
7371
7391
|
#vNode;
|
7392
|
+
/**
|
7393
|
+
* The list of directives associated with the virtual node.
|
7394
|
+
* This may be undefined if there are no directives.
|
7395
|
+
*/
|
7372
7396
|
#directives;
|
7397
|
+
/**
|
7398
|
+
* The anchor comment node used for certain directives (e.g., v-if, v-for).
|
7399
|
+
* This may be undefined if no directive requires an anchor.
|
7400
|
+
*/
|
7373
7401
|
#anchorNode;
|
7402
|
+
/**
|
7403
|
+
* The list of bindings preparers from the associated directives.
|
7404
|
+
* This may be undefined if no directive provides a bindings preparer.
|
7405
|
+
*/
|
7374
7406
|
#bindingsPreparers;
|
7407
|
+
/**
|
7408
|
+
* The list of DOM updaters from the associated directives.
|
7409
|
+
* This may be undefined if no directive provides a DOM updater.
|
7410
|
+
*/
|
7375
7411
|
#domUpdaters;
|
7412
|
+
/**
|
7413
|
+
* The directive that binds the ":key" or "v-bind:key" attribute, if any.
|
7414
|
+
* This directive is special and is used for optimizing rendering of lists.
|
7415
|
+
* If no such directive exists, this is undefined.
|
7416
|
+
*/
|
7376
7417
|
#keyDirective;
|
7418
|
+
/**
|
7419
|
+
* A cache of VBindDirectives for options specific to certain directives.
|
7420
|
+
* The keys are directive names (e.g., 'options', 'options.intersection').
|
7421
|
+
*/
|
7422
|
+
#optionsDirectives = {};
|
7377
7423
|
constructor(vNode) {
|
7378
7424
|
// Directives can only be associated with element nodes
|
7379
7425
|
if (vNode.nodeType !== Node.ELEMENT_NODE) {
|
@@ -7431,6 +7477,35 @@ class VDirectiveManager {
|
|
7431
7477
|
get keyDirective() {
|
7432
7478
|
return this.#keyDirective;
|
7433
7479
|
}
|
7480
|
+
/**
|
7481
|
+
* Gets a record of VBindDirectives for options specific to certain directives.
|
7482
|
+
* The keys are directive names (e.g., 'options', 'options.intersection').
|
7483
|
+
*/
|
7484
|
+
get optionsDirectives() {
|
7485
|
+
return this.#optionsDirectives;
|
7486
|
+
}
|
7487
|
+
/**
|
7488
|
+
* Gets the VBindDirective for options specific to the given directive name.
|
7489
|
+
* Searches in order: `:options.{directive}` -> `:options`
|
7490
|
+
*
|
7491
|
+
* @param directive The directive name (e.g., 'intersection', 'resize')
|
7492
|
+
* @returns The VBindDirective instance or undefined
|
7493
|
+
*/
|
7494
|
+
optionsDirective(directive) {
|
7495
|
+
if (!this.#directives || this.#directives.length === 0) {
|
7496
|
+
return undefined;
|
7497
|
+
}
|
7498
|
+
// Search for `:options.{directive}` or `v-bind:options.{directive}` first
|
7499
|
+
const specificAttrName = `options.${directive}`;
|
7500
|
+
if (this.#optionsDirectives[specificAttrName]) {
|
7501
|
+
return this.#optionsDirectives[specificAttrName];
|
7502
|
+
}
|
7503
|
+
// Fallback: search for `:options` or `v-bind:options`
|
7504
|
+
if (this.#optionsDirectives['options']) {
|
7505
|
+
return this.#optionsDirectives['options'];
|
7506
|
+
}
|
7507
|
+
return undefined;
|
7508
|
+
}
|
7434
7509
|
/**
|
7435
7510
|
* Cleans up any resources used by the directive handler.
|
7436
7511
|
*/
|
@@ -7490,6 +7565,10 @@ class VDirectiveManager {
|
|
7490
7565
|
if (directive.name === StandardDirectiveName.V_BIND && directive.isKey) {
|
7491
7566
|
this.#keyDirective = directive;
|
7492
7567
|
}
|
7568
|
+
// If this is an options binding directive, cache it
|
7569
|
+
if (directive.name === StandardDirectiveName.V_BIND && directive.isOptions) {
|
7570
|
+
this.#optionsDirectives[directive.name] = directive;
|
7571
|
+
}
|
7493
7572
|
}
|
7494
7573
|
}
|
7495
7574
|
// Sort directives by priority: v-for > v-if > v-else-if > v-else > v-show > others
|
@@ -8977,6 +9056,209 @@ class VIfDirective extends VConditionalDirective {
|
|
8977
9056
|
}
|
8978
9057
|
}
|
8979
9058
|
|
9059
|
+
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9060
|
+
/**
|
9061
|
+
* Directive for observing element intersection with viewport or ancestor elements using IntersectionObserver.
|
9062
|
+
* The `v-intersection` directive allows you to respond to changes in an element's visibility.
|
9063
|
+
*
|
9064
|
+
* Example usage:
|
9065
|
+
* <div v-intersection="handleIntersection">Observable content</div>
|
9066
|
+
* <div v-intersection="handleIntersection" :options.intersection="{threshold: 0.5}">Observable content</div>
|
9067
|
+
*
|
9068
|
+
* The handler receives IntersectionObserverEntry array as the first argument and $ctx as the second:
|
9069
|
+
* handleIntersection(entries, $ctx) {
|
9070
|
+
* const entry = entries[0];
|
9071
|
+
* if (entry.isIntersecting) {
|
9072
|
+
* console.log('Element is visible!');
|
9073
|
+
* }
|
9074
|
+
* }
|
9075
|
+
*
|
9076
|
+
* Options can be provided via :options or :options.intersection attribute:
|
9077
|
+
* :options="{root: null, threshold: 0.5, rootMargin: '0px'}"
|
9078
|
+
* :options.intersection="{root: null, threshold: 0.5, rootMargin: '0px'}"
|
9079
|
+
*
|
9080
|
+
* This directive is useful for lazy-loading, infinite scrolling, animation triggers,
|
9081
|
+
* and other features that depend on element visibility.
|
9082
|
+
*/
|
9083
|
+
class VIntersectionDirective {
|
9084
|
+
/**
|
9085
|
+
* The virtual node to which this directive is applied.
|
9086
|
+
*/
|
9087
|
+
#vNode;
|
9088
|
+
/**
|
9089
|
+
* A list of variable and function names used in the directive's expression.
|
9090
|
+
*/
|
9091
|
+
#dependentIdentifiers;
|
9092
|
+
/**
|
9093
|
+
* The intersection handler wrapper function.
|
9094
|
+
*/
|
9095
|
+
#handlerWrapper;
|
9096
|
+
/**
|
9097
|
+
* The IntersectionObserver instance.
|
9098
|
+
*/
|
9099
|
+
#intersectionObserver;
|
9100
|
+
/**
|
9101
|
+
* @param context The context for parsing the directive.
|
9102
|
+
*/
|
9103
|
+
constructor(context) {
|
9104
|
+
this.#vNode = context.vNode;
|
9105
|
+
// Parse the expression to extract identifiers and create the handler wrapper
|
9106
|
+
const expression = context.attribute.value;
|
9107
|
+
if (expression) {
|
9108
|
+
this.#dependentIdentifiers = ExpressionUtils.extractIdentifiers(expression, context.vNode.vApplication.functionDependencies);
|
9109
|
+
this.#handlerWrapper = this.#createIntersectionHandlerWrapper(expression);
|
9110
|
+
}
|
9111
|
+
// Remove the directive attribute from the element
|
9112
|
+
this.#vNode.node.removeAttribute(context.attribute.name);
|
9113
|
+
}
|
9114
|
+
/**
|
9115
|
+
* @inheritdoc
|
9116
|
+
*/
|
9117
|
+
get name() {
|
9118
|
+
return StandardDirectiveName.V_INTERSECTION;
|
9119
|
+
}
|
9120
|
+
/**
|
9121
|
+
* @inheritdoc
|
9122
|
+
*/
|
9123
|
+
get vNode() {
|
9124
|
+
return this.#vNode;
|
9125
|
+
}
|
9126
|
+
/**
|
9127
|
+
* @inheritdoc
|
9128
|
+
*/
|
9129
|
+
get needsAnchor() {
|
9130
|
+
return false;
|
9131
|
+
}
|
9132
|
+
/**
|
9133
|
+
* @inheritdoc
|
9134
|
+
*/
|
9135
|
+
get bindingsPreparer() {
|
9136
|
+
return undefined;
|
9137
|
+
}
|
9138
|
+
/**
|
9139
|
+
* @inheritdoc
|
9140
|
+
*/
|
9141
|
+
get domUpdater() {
|
9142
|
+
return undefined;
|
9143
|
+
}
|
9144
|
+
/**
|
9145
|
+
* @inheritdoc
|
9146
|
+
*/
|
9147
|
+
get templatize() {
|
9148
|
+
return false;
|
9149
|
+
}
|
9150
|
+
/**
|
9151
|
+
* @inheritdoc
|
9152
|
+
*/
|
9153
|
+
get dependentIdentifiers() {
|
9154
|
+
return this.#dependentIdentifiers ?? [];
|
9155
|
+
}
|
9156
|
+
/**
|
9157
|
+
* @inheritdoc
|
9158
|
+
*/
|
9159
|
+
get onMount() {
|
9160
|
+
return undefined;
|
9161
|
+
}
|
9162
|
+
/**
|
9163
|
+
* @inheritdoc
|
9164
|
+
*/
|
9165
|
+
get onMounted() {
|
9166
|
+
if (!this.#handlerWrapper) {
|
9167
|
+
return undefined;
|
9168
|
+
}
|
9169
|
+
const element = this.#vNode.node;
|
9170
|
+
const handler = this.#handlerWrapper;
|
9171
|
+
return () => {
|
9172
|
+
// Get options from :options.intersection or :options directive
|
9173
|
+
let optionsDirective = this.#vNode.directiveManager?.optionsDirective('intersection');
|
9174
|
+
// Evaluate the options expression
|
9175
|
+
let options;
|
9176
|
+
if (optionsDirective && optionsDirective.expression) {
|
9177
|
+
// Evaluate the options expression
|
9178
|
+
const identifiers = optionsDirective.dependentIdentifiers;
|
9179
|
+
const values = identifiers.map(id => this.#vNode.bindings?.get(id));
|
9180
|
+
const args = identifiers.join(", ");
|
9181
|
+
const funcBody = `return (${optionsDirective.expression});`;
|
9182
|
+
const func = new Function(args, funcBody);
|
9183
|
+
options = func(...values);
|
9184
|
+
}
|
9185
|
+
// Create IntersectionObserver and start observing
|
9186
|
+
this.#intersectionObserver = new IntersectionObserver((entries) => {
|
9187
|
+
handler(entries);
|
9188
|
+
}, options);
|
9189
|
+
this.#intersectionObserver.observe(element);
|
9190
|
+
};
|
9191
|
+
}
|
9192
|
+
/**
|
9193
|
+
* @inheritdoc
|
9194
|
+
*/
|
9195
|
+
get onUpdate() {
|
9196
|
+
return undefined;
|
9197
|
+
}
|
9198
|
+
/**
|
9199
|
+
* @inheritdoc
|
9200
|
+
*/
|
9201
|
+
get onUpdated() {
|
9202
|
+
return undefined;
|
9203
|
+
}
|
9204
|
+
/**
|
9205
|
+
* @inheritdoc
|
9206
|
+
*/
|
9207
|
+
get onUnmount() {
|
9208
|
+
return undefined;
|
9209
|
+
}
|
9210
|
+
/**
|
9211
|
+
* @inheritdoc
|
9212
|
+
*/
|
9213
|
+
get onUnmounted() {
|
9214
|
+
return undefined;
|
9215
|
+
}
|
9216
|
+
/**
|
9217
|
+
* @inheritdoc
|
9218
|
+
*/
|
9219
|
+
destroy() {
|
9220
|
+
// Disconnect the IntersectionObserver when the directive is destroyed
|
9221
|
+
if (this.#intersectionObserver) {
|
9222
|
+
this.#intersectionObserver.disconnect();
|
9223
|
+
this.#intersectionObserver = undefined;
|
9224
|
+
}
|
9225
|
+
}
|
9226
|
+
/**
|
9227
|
+
* Creates a wrapper function for intersection handlers.
|
9228
|
+
* @param expression The expression string to evaluate.
|
9229
|
+
* @returns A function that handles the intersection event.
|
9230
|
+
*/
|
9231
|
+
#createIntersectionHandlerWrapper(expression) {
|
9232
|
+
const identifiers = this.#dependentIdentifiers ?? [];
|
9233
|
+
const vNode = this.#vNode;
|
9234
|
+
// Return a function that handles the intersection event with proper scope
|
9235
|
+
return (entries) => {
|
9236
|
+
const bindings = vNode.bindings;
|
9237
|
+
const $ctx = {
|
9238
|
+
element: vNode.node,
|
9239
|
+
vnode: vNode,
|
9240
|
+
userData: vNode.userData
|
9241
|
+
};
|
9242
|
+
// If the expression is just a method name, call it with bindings as 'this'
|
9243
|
+
const trimmedExpr = expression.trim();
|
9244
|
+
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
9245
|
+
const methodName = trimmedExpr;
|
9246
|
+
const originalMethod = bindings?.get(methodName);
|
9247
|
+
// Call the method with bindings as 'this' context
|
9248
|
+
// Pass entries as first argument and $ctx as second argument
|
9249
|
+
return originalMethod(entries, $ctx);
|
9250
|
+
}
|
9251
|
+
// For inline expressions, evaluate normally
|
9252
|
+
// Note: inline expressions receive entries and $ctx as parameters
|
9253
|
+
const values = identifiers.map(id => vNode.bindings?.get(id));
|
9254
|
+
const args = [...identifiers, 'entries', '$ctx'].join(", ");
|
9255
|
+
const funcBody = `return (${expression});`;
|
9256
|
+
const func = new Function(args, funcBody);
|
9257
|
+
return func.call(bindings?.raw, ...values, entries, $ctx);
|
9258
|
+
};
|
9259
|
+
}
|
9260
|
+
}
|
9261
|
+
|
8980
9262
|
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
8981
9263
|
/**
|
8982
9264
|
* Directive for two-way data binding on form input elements.
|
@@ -9302,8 +9584,8 @@ class VModelDirective {
|
|
9302
9584
|
* @mounted="onMounted" - Called after the element is inserted into the DOM
|
9303
9585
|
* @update="onUpdate" - Called before the element is updated
|
9304
9586
|
* @updated="onUpdated" - Called after the element is updated
|
9305
|
-
* @unmount="onUnmount" - Called before
|
9306
|
-
* @unmounted="onUnmounted" - Called after
|
9587
|
+
* @unmount="onUnmount" - Called before VNode cleanup begins
|
9588
|
+
* @unmounted="onUnmounted" - Called after VNode cleanup is complete (element reference still available)
|
9307
9589
|
*
|
9308
9590
|
* This directive is essential for handling user interactions and lifecycle events in your application.
|
9309
9591
|
* Note that the methods referenced in the directive should be defined in the component's methods object.
|
@@ -9579,7 +9861,7 @@ class VOnDirective {
|
|
9579
9861
|
};
|
9580
9862
|
}
|
9581
9863
|
/**
|
9582
|
-
* Creates a wrapper function for DOM event handlers (with event
|
9864
|
+
* Creates a wrapper function for DOM event handlers (with event and $ctx parameters).
|
9583
9865
|
* @param expression The expression string to evaluate.
|
9584
9866
|
* @returns A function that handles the event.
|
9585
9867
|
*/
|
@@ -9589,21 +9871,210 @@ class VOnDirective {
|
|
9589
9871
|
// Return a function that handles the event with proper scope
|
9590
9872
|
return (event) => {
|
9591
9873
|
const bindings = vNode.bindings;
|
9874
|
+
const $ctx = {
|
9875
|
+
element: vNode.node,
|
9876
|
+
vnode: vNode,
|
9877
|
+
userData: vNode.userData
|
9878
|
+
};
|
9879
|
+
// If the expression is just a method name, call it with bindings as 'this'
|
9880
|
+
const trimmedExpr = expression.trim();
|
9881
|
+
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
9882
|
+
const methodName = trimmedExpr;
|
9883
|
+
const originalMethod = bindings?.get(methodName);
|
9884
|
+
// Call the method with bindings as 'this' context
|
9885
|
+
// Pass event as first argument and $ctx as second argument
|
9886
|
+
return originalMethod(event, $ctx);
|
9887
|
+
}
|
9888
|
+
// For inline expressions, evaluate normally
|
9889
|
+
// Note: inline expressions receive event and $ctx as parameters
|
9890
|
+
const values = identifiers.map(id => vNode.bindings?.get(id));
|
9891
|
+
const args = [...identifiers, 'event', '$ctx'].join(", ");
|
9892
|
+
const funcBody = `return (${expression});`;
|
9893
|
+
const func = new Function(args, funcBody);
|
9894
|
+
return func.call(bindings?.raw, ...values, event, $ctx);
|
9895
|
+
};
|
9896
|
+
}
|
9897
|
+
}
|
9898
|
+
|
9899
|
+
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9900
|
+
/**
|
9901
|
+
* Directive for observing element resize events using ResizeObserver.
|
9902
|
+
* The `v-resize` directive allows you to respond to changes in an element's size.
|
9903
|
+
*
|
9904
|
+
* Example usage:
|
9905
|
+
* <div v-resize="handleResize">Resizable content</div>
|
9906
|
+
*
|
9907
|
+
* The handler receives ResizeObserverEntry array as the first argument and $ctx as the second:
|
9908
|
+
* handleResize(entries, $ctx) {
|
9909
|
+
* const { width, height } = entries[0].contentRect;
|
9910
|
+
* console.log(`Size: ${width}x${height}`);
|
9911
|
+
* }
|
9912
|
+
*
|
9913
|
+
* This directive is useful for responsive layouts, charts, and other components
|
9914
|
+
* that need to adapt to size changes.
|
9915
|
+
*/
|
9916
|
+
class VResizeDirective {
|
9917
|
+
/**
|
9918
|
+
* The virtual node to which this directive is applied.
|
9919
|
+
*/
|
9920
|
+
#vNode;
|
9921
|
+
/**
|
9922
|
+
* A list of variable and function names used in the directive's expression.
|
9923
|
+
*/
|
9924
|
+
#dependentIdentifiers;
|
9925
|
+
/**
|
9926
|
+
* The resize handler wrapper function.
|
9927
|
+
*/
|
9928
|
+
#handlerWrapper;
|
9929
|
+
/**
|
9930
|
+
* The ResizeObserver instance.
|
9931
|
+
*/
|
9932
|
+
#resizeObserver;
|
9933
|
+
/**
|
9934
|
+
* @param context The context for parsing the directive.
|
9935
|
+
*/
|
9936
|
+
constructor(context) {
|
9937
|
+
this.#vNode = context.vNode;
|
9938
|
+
// Parse the expression to extract identifiers and create the handler wrapper
|
9939
|
+
const expression = context.attribute.value;
|
9940
|
+
if (expression) {
|
9941
|
+
this.#dependentIdentifiers = ExpressionUtils.extractIdentifiers(expression, context.vNode.vApplication.functionDependencies);
|
9942
|
+
this.#handlerWrapper = this.#createResizeHandlerWrapper(expression);
|
9943
|
+
}
|
9944
|
+
// Remove the directive attribute from the element
|
9945
|
+
this.#vNode.node.removeAttribute(context.attribute.name);
|
9946
|
+
}
|
9947
|
+
/**
|
9948
|
+
* @inheritdoc
|
9949
|
+
*/
|
9950
|
+
get name() {
|
9951
|
+
return StandardDirectiveName.V_RESIZE;
|
9952
|
+
}
|
9953
|
+
/**
|
9954
|
+
* @inheritdoc
|
9955
|
+
*/
|
9956
|
+
get vNode() {
|
9957
|
+
return this.#vNode;
|
9958
|
+
}
|
9959
|
+
/**
|
9960
|
+
* @inheritdoc
|
9961
|
+
*/
|
9962
|
+
get needsAnchor() {
|
9963
|
+
return false;
|
9964
|
+
}
|
9965
|
+
/**
|
9966
|
+
* @inheritdoc
|
9967
|
+
*/
|
9968
|
+
get bindingsPreparer() {
|
9969
|
+
return undefined;
|
9970
|
+
}
|
9971
|
+
/**
|
9972
|
+
* @inheritdoc
|
9973
|
+
*/
|
9974
|
+
get domUpdater() {
|
9975
|
+
return undefined;
|
9976
|
+
}
|
9977
|
+
/**
|
9978
|
+
* @inheritdoc
|
9979
|
+
*/
|
9980
|
+
get templatize() {
|
9981
|
+
return false;
|
9982
|
+
}
|
9983
|
+
/**
|
9984
|
+
* @inheritdoc
|
9985
|
+
*/
|
9986
|
+
get dependentIdentifiers() {
|
9987
|
+
return this.#dependentIdentifiers ?? [];
|
9988
|
+
}
|
9989
|
+
/**
|
9990
|
+
* @inheritdoc
|
9991
|
+
*/
|
9992
|
+
get onMount() {
|
9993
|
+
return undefined;
|
9994
|
+
}
|
9995
|
+
/**
|
9996
|
+
* @inheritdoc
|
9997
|
+
*/
|
9998
|
+
get onMounted() {
|
9999
|
+
if (!this.#handlerWrapper) {
|
10000
|
+
return undefined;
|
10001
|
+
}
|
10002
|
+
const element = this.#vNode.node;
|
10003
|
+
const handler = this.#handlerWrapper;
|
10004
|
+
return () => {
|
10005
|
+
// Create ResizeObserver and start observing
|
10006
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
10007
|
+
handler(entries);
|
10008
|
+
});
|
10009
|
+
this.#resizeObserver.observe(element);
|
10010
|
+
};
|
10011
|
+
}
|
10012
|
+
/**
|
10013
|
+
* @inheritdoc
|
10014
|
+
*/
|
10015
|
+
get onUpdate() {
|
10016
|
+
return undefined;
|
10017
|
+
}
|
10018
|
+
/**
|
10019
|
+
* @inheritdoc
|
10020
|
+
*/
|
10021
|
+
get onUpdated() {
|
10022
|
+
return undefined;
|
10023
|
+
}
|
10024
|
+
/**
|
10025
|
+
* @inheritdoc
|
10026
|
+
*/
|
10027
|
+
get onUnmount() {
|
10028
|
+
return undefined;
|
10029
|
+
}
|
10030
|
+
/**
|
10031
|
+
* @inheritdoc
|
10032
|
+
*/
|
10033
|
+
get onUnmounted() {
|
10034
|
+
return undefined;
|
10035
|
+
}
|
10036
|
+
/**
|
10037
|
+
* @inheritdoc
|
10038
|
+
*/
|
10039
|
+
destroy() {
|
10040
|
+
// Disconnect the ResizeObserver when the directive is destroyed
|
10041
|
+
if (this.#resizeObserver) {
|
10042
|
+
this.#resizeObserver.disconnect();
|
10043
|
+
this.#resizeObserver = undefined;
|
10044
|
+
}
|
10045
|
+
}
|
10046
|
+
/**
|
10047
|
+
* Creates a wrapper function for resize handlers.
|
10048
|
+
* @param expression The expression string to evaluate.
|
10049
|
+
* @returns A function that handles the resize event.
|
10050
|
+
*/
|
10051
|
+
#createResizeHandlerWrapper(expression) {
|
10052
|
+
const identifiers = this.#dependentIdentifiers ?? [];
|
10053
|
+
const vNode = this.#vNode;
|
10054
|
+
// Return a function that handles the resize event with proper scope
|
10055
|
+
return (entries) => {
|
10056
|
+
const bindings = vNode.bindings;
|
10057
|
+
const $ctx = {
|
10058
|
+
element: vNode.node,
|
10059
|
+
vnode: vNode,
|
10060
|
+
userData: vNode.userData
|
10061
|
+
};
|
9592
10062
|
// If the expression is just a method name, call it with bindings as 'this'
|
9593
10063
|
const trimmedExpr = expression.trim();
|
9594
10064
|
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
9595
10065
|
const methodName = trimmedExpr;
|
9596
10066
|
const originalMethod = bindings?.get(methodName);
|
9597
10067
|
// Call the method with bindings as 'this' context
|
9598
|
-
//
|
9599
|
-
return originalMethod(
|
10068
|
+
// Pass entries as first argument and $ctx as second argument
|
10069
|
+
return originalMethod(entries, $ctx);
|
9600
10070
|
}
|
9601
10071
|
// For inline expressions, evaluate normally
|
10072
|
+
// Note: inline expressions receive entries and $ctx as parameters
|
9602
10073
|
const values = identifiers.map(id => vNode.bindings?.get(id));
|
9603
|
-
const args = identifiers.join(", ");
|
10074
|
+
const args = [...identifiers, 'entries', '$ctx'].join(", ");
|
9604
10075
|
const funcBody = `return (${expression});`;
|
9605
10076
|
const func = new Function(args, funcBody);
|
9606
|
-
return func.call(bindings?.raw, ...values,
|
10077
|
+
return func.call(bindings?.raw, ...values, entries, $ctx);
|
9607
10078
|
};
|
9608
10079
|
}
|
9609
10080
|
}
|
@@ -9833,7 +10304,11 @@ class VStandardDirectiveParser {
|
|
9833
10304
|
context.attribute.name.startsWith(":") ||
|
9834
10305
|
// v-model, v-model.<modifier>
|
9835
10306
|
context.attribute.name === StandardDirectiveName.V_MODEL ||
|
9836
|
-
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".")
|
10307
|
+
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".") ||
|
10308
|
+
// v-resize
|
10309
|
+
context.attribute.name === StandardDirectiveName.V_RESIZE ||
|
10310
|
+
// v-intersection
|
10311
|
+
context.attribute.name === StandardDirectiveName.V_INTERSECTION) {
|
9837
10312
|
return true;
|
9838
10313
|
}
|
9839
10314
|
return false;
|
@@ -9872,6 +10347,14 @@ class VStandardDirectiveParser {
|
|
9872
10347
|
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".")) {
|
9873
10348
|
return new VModelDirective(context);
|
9874
10349
|
}
|
10350
|
+
// v-resize
|
10351
|
+
if (context.attribute.name === StandardDirectiveName.V_RESIZE) {
|
10352
|
+
return new VResizeDirective(context);
|
10353
|
+
}
|
10354
|
+
// v-intersection
|
10355
|
+
if (context.attribute.name === StandardDirectiveName.V_INTERSECTION) {
|
10356
|
+
return new VIntersectionDirective(context);
|
10357
|
+
}
|
9875
10358
|
throw new Error(`The attribute "${context.attribute.name}" cannot be parsed by ${this.name}.`);
|
9876
10359
|
}
|
9877
10360
|
}
|