@@ -146,26 +146,34 @@ window.createPopup = async function() {
146146 top : '20px' ,
147147 right : '20px' ,
148148 zIndex : '2147483647' ,
149- width : '550px' ,
150149 background : 'transparent' ,
151150 borderRadius : '21px' ,
152151 border : '0px' ,
153152 margin : '0px' ,
154153 padding : '0px' ,
155154 transform : 'translateY(0px)' ,
156155 boxSizing : 'border-box' ,
156+ width : '550px' , // Initial width
157+ height : '200px' , // Initial height
158+ transition : 'height 0.2s ease-out' // Smooth height transitions
157159 } ) ;
158160
159161 document . body . appendChild ( iframe ) ;
160162
163+ // Function to resize iframe based on content
164+ function resizeIframe ( ) {
165+ const doc = iframe . contentDocument || iframe . contentWindow . document ;
166+ const content = doc . querySelector ( '.archive-box-popup' ) ;
167+ if ( content ) {
168+ const height = content . offsetHeight ;
169+ const dropdown = doc . querySelector ( '.ARCHIVEBOX__autocomplete-dropdown' ) ;
170+ const dropdownHeight = dropdown && dropdown . style . display !== 'none' ? dropdown . offsetHeight : 0 ;
171+ iframe . style . height = ( height + dropdownHeight + 20 ) + 'px' ; // Add padding
172+ }
173+ }
174+
161175 // Create popup content inside iframe
162176 const doc = iframe . contentDocument || iframe . contentWindow . document ;
163-
164- // iframe.addEventListener('load', () => {
165- // // resize iframe to fit content
166- // iframe.style.width = doc.body.scrollWidth + 'px';
167- // iframe.style.height = doc.body.scrollHeight + 'px';
168- // });
169177
170178 // Add styles to iframe
171179 const style = doc . createElement ( 'style' ) ;
@@ -176,20 +184,21 @@ window.createPopup = async function() {
176184 font-family: system-ui, -apple-system, sans-serif;
177185 font-size: 14px;
178186 width: 100%;
187+ height: auto;
188+ overflow: visible;
179189 }
180190
181191 .archive-box-popup {
182- height: 65px ;
183- background: linear-gradient(45deg, #bf7070, rgb(200 50 50)) ;
192+ min- height: 90px ;
193+ background: #bf7070;
184194 margin: 0px;
185- padding: 0px ;
195+ padding: 6px ;
186196 color: white;
187- padding: 26px 13px 10px;
188197 box-shadow: 0 2px 10px rgba(0,0,0,0.1);
189198 font-family: system-ui, -apple-system, sans-serif;
190- transition: display 0.3s ease-in-out;
191- animation: slideDown 0.3s ease-in-out forwards;
199+ transition: all 0.2s ease-out;
192200 }
201+
193202 .archive-box-popup:hover {
194203 animation: slideDown -0.3s ease-in-out forwards;
195204 opacity: 1;
@@ -350,11 +359,11 @@ window.createPopup = async function() {
350359 .ARCHIVEBOX__autocomplete-dropdown {
351360 background: white;
352361 border: 1px solid #ddd;
353- border-radius: 0 0 4px 4px ;
362+ border-radius: 0 0 14px 14px ;
354363 box-shadow: 0 2px 4px rgba(0,0,0,0.1);
355364 max-height: 200px;
356365 overflow-y: auto;
357- z-index: 2147483647 ;
366+ transition: all 0.2s ease-out ;
358367 }
359368
360369 .ARCHIVEBOX__autocomplete-item {
@@ -376,8 +385,8 @@ window.createPopup = async function() {
376385 popup . innerHTML = `
377386 <a href="#" class="options-link" title="Open in ArchiveBox">🏛️</a> <input type="search" placeholder="Add tags + press ⏎ | ⎋ to close">
378387 <br/>
379- <div class="ARCHIVEBOX__current-tags"></div>
380388 <div class="ARCHIVEBOX__tag-suggestions"></div><br/>
389+ <div class="ARCHIVEBOX__current-tags"></div>
381390 <small>
382391 <span class="status-indicator"></span>
383392 Saved
@@ -452,20 +461,21 @@ window.createPopup = async function() {
452461 if ( filteredTags . length === 0 ) {
453462 dropdownContainer . style . display = 'none' ;
454463 selectedIndex = - 1 ;
455- return ;
464+ } else {
465+ dropdownContainer . innerHTML = filteredTags
466+ . map ( ( tag , index ) => `
467+ <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
468+ data-tag="${ tag } ">
469+ ${ tag }
470+ </div>
471+ ` )
472+ . join ( '' ) ;
473+
474+ dropdownContainer . style . display = 'block' ;
456475 }
457476
458- // Update dropdown content
459- dropdownContainer . innerHTML = filteredTags
460- . map ( ( tag , index ) => `
461- <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
462- data-tag="${ tag } ">
463- ${ tag }
464- </div>
465- ` )
466- . join ( '' ) ;
467-
468- dropdownContainer . style . display = 'block' ;
477+ // Trigger resize after dropdown visibility changes
478+ setTimeout ( resizeIframe , 0 ) ;
469479 }
470480
471481 // Handle input changes
@@ -565,6 +575,87 @@ window.createPopup = async function() {
565575
566576 input . focus ( ) ;
567577 console . log ( '+ Showed ArchiveBox popup in iframe' ) ;
578+
579+ // Add resize triggers
580+ const resizeObserver = new ResizeObserver ( ( ) => {
581+ resizeIframe ( ) ;
582+ } ) ;
583+
584+ // Observe the popup content for size changes
585+ resizeObserver . observe ( popup ) ;
586+
587+ // Additional resize triggers for dynamic content
588+ async function updateCurrentTags ( ) {
589+ if ( ! popup_element ) return ;
590+ const current_tags_div = popup_element . querySelector ( '.ARCHIVEBOX__current-tags' ) ;
591+ const status_div = popup_element . querySelector ( 'small' ) ;
592+ const { current_entry } = await getCurrentEntry ( ) ;
593+
594+ current_tags_div . innerHTML = current_entry . tags . length
595+ ? `${ current_entry . tags
596+ . map ( tag => `<span class="ARCHIVEBOX__tag-badge current" data-tag="${ tag } ">${ tag } </span>` )
597+ . join ( ' ' ) } `
598+ : '' ;
599+
600+ const result = await sendToArchiveBox ( current_entry . url , current_entry . tags ) ;
601+ status_div . innerHTML = `
602+ <span class="status-indicator ${ result . ok ? 'success' : 'error' } "></span>
603+ ${ result . status }
604+ ` ;
605+
606+ // Add click handlers for removing tags
607+ current_tags_div . querySelectorAll ( '.tag-badge.current' ) . forEach ( badge => {
608+ badge . addEventListener ( 'click' , async ( e ) => {
609+ if ( e . target . classList . contains ( 'current' ) ) {
610+ const { current_entry, entries } = await getCurrentEntry ( ) ;
611+ const tag_to_remove = e . target . dataset . tag ;
612+ current_entry . tags = current_entry . tags . filter ( tag => tag !== tag_to_remove ) ;
613+ await chrome . storage . local . set ( { entries } ) ;
614+ await updateCurrentTags ( ) ;
615+ await updateSuggestions ( ) ;
616+ }
617+ } ) ;
618+ } ) ;
619+
620+ resizeIframe ( ) ;
621+ }
622+
623+ async function updateDropdown ( ) {
624+ const inputValue = input . value . toLowerCase ( ) ;
625+ const allTags = await getAllTags ( ) ;
626+
627+ // Filter tags that match input and aren't already used
628+ const { current_entry } = await getCurrentEntry ( ) ;
629+ filteredTags = allTags
630+ . filter ( tag =>
631+ tag . toLowerCase ( ) . includes ( inputValue ) &&
632+ ! current_entry . tags . includes ( tag ) &&
633+ inputValue
634+ )
635+ . slice ( 0 , 5 ) ; // Limit to 5 suggestions
636+
637+ if ( filteredTags . length === 0 ) {
638+ dropdownContainer . style . display = 'none' ;
639+ selectedIndex = - 1 ;
640+ } else {
641+ dropdownContainer . innerHTML = filteredTags
642+ . map ( ( tag , index ) => `
643+ <div class="ARCHIVEBOX__autocomplete-item ${ index === selectedIndex ? 'selected' : '' } "
644+ data-tag="${ tag } ">
645+ ${ tag }
646+ </div>
647+ ` )
648+ . join ( '' ) ;
649+
650+ dropdownContainer . style . display = 'block' ;
651+ }
652+
653+ // Trigger resize after dropdown visibility changes
654+ setTimeout ( resizeIframe , 0 ) ;
655+ }
656+
657+ // Initial resize
658+ setTimeout ( resizeIframe , 0 ) ;
568659}
569660
570661window . createPopup ( ) ;
0 commit comments