@@ -9,8 +9,6 @@ class ChatFilePanel {
99 this . closeIconEl = document . getElementById ( 'chat-file-panel-close-icon' ) ;
1010 this . refreshIconEl = document . getElementById ( 'chat-file-refresh-icon' ) ;
1111 this . onVisibilityChange = typeof options . onVisibilityChange === 'function' ? options . onVisibilityChange : null ;
12- this . onFullTextToggle = typeof options . onFullTextToggle === 'function' ? options . onFullTextToggle : null ;
13- this . fullTextToggleEl = options . fullTextToggleEl || document . getElementById ( 'chat-fulltext-toggle' ) ;
1412 this . runtime = {
1513 fileTreeData : null ,
1614 expanded : new Set ( ) ,
@@ -31,7 +29,6 @@ class ChatFilePanel {
3129 || 'http://localhost:8000/api/document/upload-status' ;
3230 this . loadInFlight = null ;
3331 this . pendingSelectionBroadcast = null ;
34- this . fullTextEnabled = Boolean ( this . fullTextToggleEl ?. checked ) ;
3532 this . initialize ( ) ;
3633 }
3734
@@ -48,7 +45,6 @@ class ChatFilePanel {
4845
4946 this . bindPanelToggle ( ) ;
5047 this . bindKeyboardShortcuts ( ) ;
51- this . bindFullTextToggle ( ) ;
5248
5349 if ( this . container ) {
5450 this . container . addEventListener ( 'contextmenu' , ( event ) => {
@@ -62,25 +58,6 @@ class ChatFilePanel {
6258 }
6359 }
6460
65- bindFullTextToggle ( ) {
66- if ( ! this . fullTextToggleEl ) {
67- return ;
68- }
69- this . fullTextToggleEl . checked = this . fullTextEnabled ;
70- this . fullTextToggleEl . setAttribute ( 'aria-checked' , this . fullTextEnabled ? 'true' : 'false' ) ;
71- this . fullTextToggleEl . addEventListener ( 'change' , ( ) => {
72- this . fullTextEnabled = Boolean ( this . fullTextToggleEl . checked ) ;
73- this . fullTextToggleEl . setAttribute ( 'aria-checked' , this . fullTextEnabled ? 'true' : 'false' ) ;
74- if ( typeof this . onFullTextToggle === 'function' ) {
75- this . onFullTextToggle ( this . fullTextEnabled ) ;
76- }
77- const evt = new CustomEvent ( 'chatFullTextModeChanged' , {
78- detail : { enabled : this . fullTextEnabled }
79- } ) ;
80- document . dispatchEvent ( evt ) ;
81- } ) ;
82- }
83-
8461 bindPanelToggle ( ) {
8562 if ( this . toggleBtn ) {
8663 this . toggleBtn . addEventListener ( 'click' , ( ) => {
@@ -266,11 +243,11 @@ class ChatFilePanel {
266243 if ( isFolder ) {
267244 item . classList . add ( 'folder-item' ) ;
268245 } else {
269- item . classList . add ( 'file-item-file' , 'is-selectable' ) ;
246+ item . classList . add ( 'file-item-file' ) ;
270247 }
271248 item . dataset . path = node . path ;
272249 item . dataset . relativePath = relativePath ;
273- const fileType = isFolder ? 'folder' : ( this . isImageNode ( node ) ? 'image' : 'file' ) ;
250+ const fileType = this . resolveNodeFileType ( node , isFolder ) ;
274251 item . dataset . type = fileType ;
275252 item . dataset . fileType = fileType ;
276253 this . fileTypeLookup . set ( node . path , fileType ) ;
@@ -287,11 +264,22 @@ class ChatFilePanel {
287264 }
288265 }
289266 item . setAttribute ( 'aria-selected' , this . runtime . selected . has ( node . path ) ? 'true' : 'false' ) ;
290- if ( this . runtime . selected . has ( node . path ) ) {
267+ if ( this . runtime . selected . has ( node . path ) && fileType !== 'unsupported' ) {
291268 item . dataset . selected = 'true' ;
292269 }
270+ if ( ! isFolder ) {
271+ item . dataset . fileName = node . name ;
272+ if ( fileType === 'unsupported' ) {
273+ item . classList . add ( 'is-disabled' ) ;
274+ item . setAttribute ( 'aria-disabled' , 'true' ) ;
275+ } else {
276+ item . classList . add ( 'is-selectable' ) ;
277+ }
278+ }
279+ if ( fileType === 'unsupported' ) {
280+ this . runtime . selected . delete ( node . path ) ;
281+ }
293282 this . nodeLookup . set ( node . path , node ) ;
294-
295283 const content = document . createElement ( 'div' ) ;
296284 content . className = 'file-item-content' ;
297285 item . appendChild ( content ) ;
@@ -300,10 +288,6 @@ class ChatFilePanel {
300288 nameWrapper . className = 'file-name' ;
301289 content . appendChild ( nameWrapper ) ;
302290
303- if ( ! isFolder ) {
304- item . dataset . fileName = node . name ;
305- }
306-
307291 const bullet = document . createElement ( 'span' ) ;
308292 bullet . className = 'file-bullet' ;
309293 bullet . textContent = '•' ;
@@ -325,6 +309,10 @@ class ChatFilePanel {
325309 this . toggleFolder ( node . path ) ;
326310 return ;
327311 }
312+ if ( fileType === 'unsupported' ) {
313+ this . showSelectionWarning ( '暂不支持选择 Excel 文件,请选择其它类型的文档。' ) ;
314+ return ;
315+ }
328316 this . toggleSelection ( node . path ) ;
329317 } ) ;
330318
@@ -479,6 +467,9 @@ class ChatFilePanel {
479467 return ;
480468 }
481469 const type = this . getFileTypeByPath ( path ) ;
470+ if ( type === 'unsupported' ) {
471+ return ;
472+ }
482473 const relativePath = this . getRelativePathByPath ( path ) ;
483474 entries . push ( {
484475 path,
@@ -550,10 +541,12 @@ class ChatFilePanel {
550541 }
551542 this . container . querySelectorAll ( '.file-item-file' ) . forEach ( ( item ) => {
552543 const type = item . dataset . fileType ;
553- if ( imageOnly && type !== 'image' ) {
544+ const baseDisabled = type === 'unsupported' ;
545+ const disabledForImageSelection = imageOnly && type !== 'image' ;
546+ if ( baseDisabled || disabledForImageSelection ) {
554547 item . classList . add ( 'is-disabled' ) ;
555548 item . setAttribute ( 'aria-disabled' , 'true' ) ;
556- } else {
549+ } else if ( ! baseDisabled ) {
557550 item . classList . remove ( 'is-disabled' ) ;
558551 item . removeAttribute ( 'aria-disabled' ) ;
559552 }
@@ -568,6 +561,27 @@ class ChatFilePanel {
568561 return / \. ( p n g | j p e ? g | g i f | b m p | w e b p | s v g ) $ / i. test ( name ) ;
569562 }
570563
564+ isUnsupportedNode ( node ) {
565+ if ( ! node || node . children ) {
566+ return false ;
567+ }
568+ const name = node . name || '' ;
569+ return / \. ( x l s x | x l s ) $ / i. test ( name ) ;
570+ }
571+
572+ resolveNodeFileType ( node , isFolder ) {
573+ if ( isFolder ) {
574+ return 'folder' ;
575+ }
576+ if ( this . isImageNode ( node ) ) {
577+ return 'image' ;
578+ }
579+ if ( this . isUnsupportedNode ( node ) ) {
580+ return 'unsupported' ;
581+ }
582+ return 'file' ;
583+ }
584+
571585 showSelectionWarning ( message ) {
572586 if ( typeof window . showAlert === 'function' ) {
573587 window . showAlert ( message , 'warning' ) ;
0 commit comments