@mintjamsinc/ichigojs 0.1.6 → 0.1.7
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 +50 -6
- package/dist/ichigo.esm.js +203 -7
- 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 +203 -7
- 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 +2 -1
- package/dist/types/ichigo/directives/VDirective.d.ts +2 -1
- package/dist/types/ichigo/directives/VOnDirective.d.ts +1 -1
- package/dist/types/ichigo/directives/VResizeDirective.d.ts +84 -0
- package/package.json +1 -1
package/dist/ichigo.umd.js
CHANGED
@@ -59,6 +59,7 @@
|
|
59
59
|
StandardDirectiveName["V_ON"] = "v-on";
|
60
60
|
StandardDirectiveName["V_BIND"] = "v-bind";
|
61
61
|
StandardDirectiveName["V_MODEL"] = "v-model";
|
62
|
+
StandardDirectiveName["V_RESIZE"] = "v-resize";
|
62
63
|
})(StandardDirectiveName || (StandardDirectiveName = {}));
|
63
64
|
|
64
65
|
// This file was generated. Do not modify manually!
|
@@ -9309,7 +9310,7 @@
|
|
9309
9310
|
* @update="onUpdate" - Called before the element is updated
|
9310
9311
|
* @updated="onUpdated" - Called after the element is updated
|
9311
9312
|
* @unmount="onUnmount" - Called before the element is removed from the DOM
|
9312
|
-
* @unmounted="onUnmounted" - Called after
|
9313
|
+
* @unmounted="onUnmounted" - Called after VNode cleanup is complete (element reference still available)
|
9313
9314
|
*
|
9314
9315
|
* This directive is essential for handling user interactions and lifecycle events in your application.
|
9315
9316
|
* Note that the methods referenced in the directive should be defined in the component's methods object.
|
@@ -9585,7 +9586,7 @@
|
|
9585
9586
|
};
|
9586
9587
|
}
|
9587
9588
|
/**
|
9588
|
-
* Creates a wrapper function for DOM event handlers (with event
|
9589
|
+
* Creates a wrapper function for DOM event handlers (with event and $ctx parameters).
|
9589
9590
|
* @param expression The expression string to evaluate.
|
9590
9591
|
* @returns A function that handles the event.
|
9591
9592
|
*/
|
@@ -9595,21 +9596,210 @@
|
|
9595
9596
|
// Return a function that handles the event with proper scope
|
9596
9597
|
return (event) => {
|
9597
9598
|
const bindings = vNode.bindings;
|
9599
|
+
const $ctx = {
|
9600
|
+
element: vNode.node,
|
9601
|
+
vnode: vNode,
|
9602
|
+
userData: vNode.userData
|
9603
|
+
};
|
9604
|
+
// If the expression is just a method name, call it with bindings as 'this'
|
9605
|
+
const trimmedExpr = expression.trim();
|
9606
|
+
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
9607
|
+
const methodName = trimmedExpr;
|
9608
|
+
const originalMethod = bindings?.get(methodName);
|
9609
|
+
// Call the method with bindings as 'this' context
|
9610
|
+
// Pass event as first argument and $ctx as second argument
|
9611
|
+
return originalMethod(event, $ctx);
|
9612
|
+
}
|
9613
|
+
// For inline expressions, evaluate normally
|
9614
|
+
// Note: inline expressions receive event and $ctx as parameters
|
9615
|
+
const values = identifiers.map(id => vNode.bindings?.get(id));
|
9616
|
+
const args = [...identifiers, 'event', '$ctx'].join(", ");
|
9617
|
+
const funcBody = `return (${expression});`;
|
9618
|
+
const func = new Function(args, funcBody);
|
9619
|
+
return func.call(bindings?.raw, ...values, event, $ctx);
|
9620
|
+
};
|
9621
|
+
}
|
9622
|
+
}
|
9623
|
+
|
9624
|
+
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9625
|
+
/**
|
9626
|
+
* Directive for observing element resize events using ResizeObserver.
|
9627
|
+
* The `v-resize` directive allows you to respond to changes in an element's size.
|
9628
|
+
*
|
9629
|
+
* Example usage:
|
9630
|
+
* <div v-resize="handleResize">Resizable content</div>
|
9631
|
+
*
|
9632
|
+
* The handler receives ResizeObserverEntry array as the first argument and $ctx as the second:
|
9633
|
+
* handleResize(entries, $ctx) {
|
9634
|
+
* const { width, height } = entries[0].contentRect;
|
9635
|
+
* console.log(`Size: ${width}x${height}`);
|
9636
|
+
* }
|
9637
|
+
*
|
9638
|
+
* This directive is useful for responsive layouts, charts, and other components
|
9639
|
+
* that need to adapt to size changes.
|
9640
|
+
*/
|
9641
|
+
class VResizeDirective {
|
9642
|
+
/**
|
9643
|
+
* The virtual node to which this directive is applied.
|
9644
|
+
*/
|
9645
|
+
#vNode;
|
9646
|
+
/**
|
9647
|
+
* A list of variable and function names used in the directive's expression.
|
9648
|
+
*/
|
9649
|
+
#dependentIdentifiers;
|
9650
|
+
/**
|
9651
|
+
* The resize handler wrapper function.
|
9652
|
+
*/
|
9653
|
+
#handlerWrapper;
|
9654
|
+
/**
|
9655
|
+
* The ResizeObserver instance.
|
9656
|
+
*/
|
9657
|
+
#resizeObserver;
|
9658
|
+
/**
|
9659
|
+
* @param context The context for parsing the directive.
|
9660
|
+
*/
|
9661
|
+
constructor(context) {
|
9662
|
+
this.#vNode = context.vNode;
|
9663
|
+
// Parse the expression to extract identifiers and create the handler wrapper
|
9664
|
+
const expression = context.attribute.value;
|
9665
|
+
if (expression) {
|
9666
|
+
this.#dependentIdentifiers = ExpressionUtils.extractIdentifiers(expression, context.vNode.vApplication.functionDependencies);
|
9667
|
+
this.#handlerWrapper = this.#createResizeHandlerWrapper(expression);
|
9668
|
+
}
|
9669
|
+
// Remove the directive attribute from the element
|
9670
|
+
this.#vNode.node.removeAttribute(context.attribute.name);
|
9671
|
+
}
|
9672
|
+
/**
|
9673
|
+
* @inheritdoc
|
9674
|
+
*/
|
9675
|
+
get name() {
|
9676
|
+
return StandardDirectiveName.V_RESIZE;
|
9677
|
+
}
|
9678
|
+
/**
|
9679
|
+
* @inheritdoc
|
9680
|
+
*/
|
9681
|
+
get vNode() {
|
9682
|
+
return this.#vNode;
|
9683
|
+
}
|
9684
|
+
/**
|
9685
|
+
* @inheritdoc
|
9686
|
+
*/
|
9687
|
+
get needsAnchor() {
|
9688
|
+
return false;
|
9689
|
+
}
|
9690
|
+
/**
|
9691
|
+
* @inheritdoc
|
9692
|
+
*/
|
9693
|
+
get bindingsPreparer() {
|
9694
|
+
return undefined;
|
9695
|
+
}
|
9696
|
+
/**
|
9697
|
+
* @inheritdoc
|
9698
|
+
*/
|
9699
|
+
get domUpdater() {
|
9700
|
+
return undefined;
|
9701
|
+
}
|
9702
|
+
/**
|
9703
|
+
* @inheritdoc
|
9704
|
+
*/
|
9705
|
+
get templatize() {
|
9706
|
+
return false;
|
9707
|
+
}
|
9708
|
+
/**
|
9709
|
+
* @inheritdoc
|
9710
|
+
*/
|
9711
|
+
get dependentIdentifiers() {
|
9712
|
+
return this.#dependentIdentifiers ?? [];
|
9713
|
+
}
|
9714
|
+
/**
|
9715
|
+
* @inheritdoc
|
9716
|
+
*/
|
9717
|
+
get onMount() {
|
9718
|
+
return undefined;
|
9719
|
+
}
|
9720
|
+
/**
|
9721
|
+
* @inheritdoc
|
9722
|
+
*/
|
9723
|
+
get onMounted() {
|
9724
|
+
if (!this.#handlerWrapper) {
|
9725
|
+
return undefined;
|
9726
|
+
}
|
9727
|
+
const element = this.#vNode.node;
|
9728
|
+
const handler = this.#handlerWrapper;
|
9729
|
+
return () => {
|
9730
|
+
// Create ResizeObserver and start observing
|
9731
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
9732
|
+
handler(entries);
|
9733
|
+
});
|
9734
|
+
this.#resizeObserver.observe(element);
|
9735
|
+
};
|
9736
|
+
}
|
9737
|
+
/**
|
9738
|
+
* @inheritdoc
|
9739
|
+
*/
|
9740
|
+
get onUpdate() {
|
9741
|
+
return undefined;
|
9742
|
+
}
|
9743
|
+
/**
|
9744
|
+
* @inheritdoc
|
9745
|
+
*/
|
9746
|
+
get onUpdated() {
|
9747
|
+
return undefined;
|
9748
|
+
}
|
9749
|
+
/**
|
9750
|
+
* @inheritdoc
|
9751
|
+
*/
|
9752
|
+
get onUnmount() {
|
9753
|
+
return undefined;
|
9754
|
+
}
|
9755
|
+
/**
|
9756
|
+
* @inheritdoc
|
9757
|
+
*/
|
9758
|
+
get onUnmounted() {
|
9759
|
+
return undefined;
|
9760
|
+
}
|
9761
|
+
/**
|
9762
|
+
* @inheritdoc
|
9763
|
+
*/
|
9764
|
+
destroy() {
|
9765
|
+
// Disconnect the ResizeObserver when the directive is destroyed
|
9766
|
+
if (this.#resizeObserver) {
|
9767
|
+
this.#resizeObserver.disconnect();
|
9768
|
+
this.#resizeObserver = undefined;
|
9769
|
+
}
|
9770
|
+
}
|
9771
|
+
/**
|
9772
|
+
* Creates a wrapper function for resize handlers.
|
9773
|
+
* @param expression The expression string to evaluate.
|
9774
|
+
* @returns A function that handles the resize event.
|
9775
|
+
*/
|
9776
|
+
#createResizeHandlerWrapper(expression) {
|
9777
|
+
const identifiers = this.#dependentIdentifiers ?? [];
|
9778
|
+
const vNode = this.#vNode;
|
9779
|
+
// Return a function that handles the resize event with proper scope
|
9780
|
+
return (entries) => {
|
9781
|
+
const bindings = vNode.bindings;
|
9782
|
+
const $ctx = {
|
9783
|
+
element: vNode.node,
|
9784
|
+
vnode: vNode,
|
9785
|
+
userData: vNode.userData
|
9786
|
+
};
|
9598
9787
|
// If the expression is just a method name, call it with bindings as 'this'
|
9599
9788
|
const trimmedExpr = expression.trim();
|
9600
9789
|
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
9601
9790
|
const methodName = trimmedExpr;
|
9602
9791
|
const originalMethod = bindings?.get(methodName);
|
9603
9792
|
// Call the method with bindings as 'this' context
|
9604
|
-
//
|
9605
|
-
return originalMethod(
|
9793
|
+
// Pass entries as first argument and $ctx as second argument
|
9794
|
+
return originalMethod(entries, $ctx);
|
9606
9795
|
}
|
9607
9796
|
// For inline expressions, evaluate normally
|
9797
|
+
// Note: inline expressions receive entries and $ctx as parameters
|
9608
9798
|
const values = identifiers.map(id => vNode.bindings?.get(id));
|
9609
|
-
const args = identifiers.join(", ");
|
9799
|
+
const args = [...identifiers, 'entries', '$ctx'].join(", ");
|
9610
9800
|
const funcBody = `return (${expression});`;
|
9611
9801
|
const func = new Function(args, funcBody);
|
9612
|
-
return func.call(bindings?.raw, ...values,
|
9802
|
+
return func.call(bindings?.raw, ...values, entries, $ctx);
|
9613
9803
|
};
|
9614
9804
|
}
|
9615
9805
|
}
|
@@ -9839,7 +10029,9 @@
|
|
9839
10029
|
context.attribute.name.startsWith(":") ||
|
9840
10030
|
// v-model, v-model.<modifier>
|
9841
10031
|
context.attribute.name === StandardDirectiveName.V_MODEL ||
|
9842
|
-
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".")
|
10032
|
+
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".") ||
|
10033
|
+
// v-resize
|
10034
|
+
context.attribute.name === StandardDirectiveName.V_RESIZE) {
|
9843
10035
|
return true;
|
9844
10036
|
}
|
9845
10037
|
return false;
|
@@ -9878,6 +10070,10 @@
|
|
9878
10070
|
context.attribute.name.startsWith(StandardDirectiveName.V_MODEL + ".")) {
|
9879
10071
|
return new VModelDirective(context);
|
9880
10072
|
}
|
10073
|
+
// v-resize
|
10074
|
+
if (context.attribute.name === StandardDirectiveName.V_RESIZE) {
|
10075
|
+
return new VResizeDirective(context);
|
10076
|
+
}
|
9881
10077
|
throw new Error(`The attribute "${context.attribute.name}" cannot be parsed by ${this.name}.`);
|
9882
10078
|
}
|
9883
10079
|
}
|