@cocreate/resize 1.13.1 → 1.14.0
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/index.js +48 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.13.1...v1.14.0) (2025-04-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update observer obseve param to type and and attributeName to attributeFilter ([1bb5e14](https://github.com/CoCreate-app/CoCreate-resize/commit/1bb5e14ae342a0e836bce36551bb4b80c4cd9cba))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* auto height handling for select fields ([11a7bc9](https://github.com/CoCreate-app/CoCreate-resize/commit/11a7bc9b6832361dcc50910ee742693ef9606fbd))
|
|
12
|
+
|
|
1
13
|
## [1.13.1](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.13.0...v1.13.1) (2025-01-18)
|
|
2
14
|
|
|
3
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/resize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"description": "A light weight resize handler make any element resizable by adding data attributes or usinng init object. Great for Customized text box or text area.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"resize",
|
package/src/index.js
CHANGED
|
@@ -599,19 +599,24 @@ CoCreateResize.prototype = {
|
|
|
599
599
|
|
|
600
600
|
// Function to auto-resize the element based on its content
|
|
601
601
|
function autoResizeElement(element) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
602
|
+
if (!element) return;
|
|
603
|
+
|
|
604
|
+
if (element.tagName === "TEXTAREA") {
|
|
605
|
+
element.style.height = "auto";
|
|
606
|
+
|
|
607
|
+
let scrollHeight;
|
|
608
|
+
if (element.contentDocument) {
|
|
609
|
+
scrollHeight = element.contentDocument.body.scrollHeight;
|
|
610
|
+
} else {
|
|
611
|
+
// For other elements, get scrollHeight directly
|
|
612
|
+
scrollHeight = element.scrollHeight;
|
|
613
|
+
}
|
|
612
614
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
+
// Set the height of the element to the calculated scrollHeight
|
|
616
|
+
element.style.height = scrollHeight + "px";
|
|
617
|
+
} else if (element.tagName === "SELECT" && element.multiple) {
|
|
618
|
+
element.size = Math.max(element.options.length, 1); // Ensure at least 1 visible option
|
|
619
|
+
}
|
|
615
620
|
}
|
|
616
621
|
|
|
617
622
|
// Observe the resize of the element
|
|
@@ -630,9 +635,9 @@ function initAutoHeight(element) {
|
|
|
630
635
|
!(element instanceof HTMLCollection) &&
|
|
631
636
|
!(element instanceof NodeList) &&
|
|
632
637
|
!Array.isArray(element)
|
|
633
|
-
)
|
|
638
|
+
) {
|
|
634
639
|
element = [element];
|
|
635
|
-
else if (!element) {
|
|
640
|
+
} else if (!element) {
|
|
636
641
|
element = document.querySelectorAll('[height="auto"]');
|
|
637
642
|
|
|
638
643
|
// Add event listener for iframes on load
|
|
@@ -647,25 +652,28 @@ function initAutoHeight(element) {
|
|
|
647
652
|
false
|
|
648
653
|
);
|
|
649
654
|
|
|
650
|
-
if (element.contentDocument) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
655
|
+
// if (element.contentDocument) {
|
|
656
|
+
// // Create a MutationObserver for changes within the iframe's body
|
|
657
|
+
// const observer = new MutationObserver(autoResizeElement);
|
|
658
|
+
// observer.observe(iframeDocument.body, {
|
|
659
|
+
// childList: true,
|
|
660
|
+
// subtree: true
|
|
661
|
+
// });
|
|
662
|
+
|
|
663
|
+
// // Handle iframe document changes (e.g., if src or srcdoc is modified)
|
|
664
|
+
// element.addEventListener("load", () => {
|
|
665
|
+
// observer.disconnect(); // Disconnect the previous observer
|
|
666
|
+
// observeIframeContent(); // Reinitialize the observer on new document
|
|
667
|
+
// });
|
|
668
|
+
// }
|
|
664
669
|
}
|
|
665
670
|
|
|
666
671
|
for (let i = 0; i < element.length; i++) {
|
|
672
|
+
if (element[i].tagName === "TEXTAREA") {
|
|
673
|
+
element[i].rows = 1;
|
|
674
|
+
}
|
|
667
675
|
autoResizeElement(element[i]);
|
|
668
|
-
observeElementResize(element[i]); // Observe resize changes
|
|
676
|
+
observeElementResize(element[i]); // Observe resize changes.
|
|
669
677
|
}
|
|
670
678
|
}
|
|
671
679
|
|
|
@@ -673,7 +681,7 @@ initAutoHeight();
|
|
|
673
681
|
|
|
674
682
|
observer.init({
|
|
675
683
|
name: "CoCreateResize",
|
|
676
|
-
|
|
684
|
+
types: ["addedNodes"],
|
|
677
685
|
selector: "[resizable]:not([resizable='false'])",
|
|
678
686
|
callback: function (mutation) {
|
|
679
687
|
coCreateResize.initElement(mutation.target);
|
|
@@ -682,13 +690,22 @@ observer.init({
|
|
|
682
690
|
|
|
683
691
|
observer.init({
|
|
684
692
|
name: "CoCreateResize",
|
|
685
|
-
|
|
693
|
+
types: ["addedNodes"],
|
|
686
694
|
selector: "[height='auto']",
|
|
687
695
|
callback: function (mutation) {
|
|
688
696
|
initAutoHeight(mutation.target);
|
|
689
697
|
}
|
|
690
698
|
});
|
|
691
699
|
|
|
700
|
+
observer.init({
|
|
701
|
+
name: "CoCreateResize",
|
|
702
|
+
types: ["addedNodes"],
|
|
703
|
+
selector: "[height='auto'] option",
|
|
704
|
+
callback: function (mutation) {
|
|
705
|
+
autoResizeElement(mutation.target.parentElement);
|
|
706
|
+
}
|
|
707
|
+
});
|
|
708
|
+
|
|
692
709
|
coCreateResize.init({
|
|
693
710
|
selector: "[resizable]:not([resizable='false'])",
|
|
694
711
|
dragLeft: "[resize='left']",
|