11import { Controller } from '@hotwired/stimulus' ;
22import TomSelect from 'tom-select' ;
33import type { TPluginHash } from 'tom-select/dist/types/contrib/microplugin' ;
4- import type { RecursivePartial , TomSettings , TomTemplates , TomLoadCallback } from 'tom-select/dist/types/types' ;
4+ import type {
5+ RecursivePartial ,
6+ TomSettings ,
7+ TomTemplates ,
8+ TomLoadCallback ,
9+ TomOption ,
10+ } from 'tom-select/dist/types/types' ;
11+ import type { escape_html } from 'tom-select/dist/types/utils' ;
512
613export interface AutocompletePreConnectOptions {
714 options : any ;
@@ -18,6 +25,7 @@ export default class extends Controller {
1825 loadingMoreText : String ,
1926 noResultsFoundText : String ,
2027 noMoreResultsText : String ,
28+ createOptionText : String ,
2129 minCharacters : Number ,
2230 tomSelectOptions : Object ,
2331 preload : String ,
@@ -28,6 +36,7 @@ export default class extends Controller {
2836 declare readonly loadingMoreTextValue : string ;
2937 declare readonly noMoreResultsTextValue : string ;
3038 declare readonly noResultsFoundTextValue : string ;
39+ declare readonly createOptionTextValue : string ;
3140 declare readonly minCharactersValue : number ;
3241 declare readonly hasMinCharactersValue : boolean ;
3342 declare readonly tomSelectOptionsValue : object ;
@@ -136,6 +145,9 @@ export default class extends Controller {
136145 no_results : ( ) => {
137146 return `<div class="no-results">${ this . noResultsFoundTextValue } </div>` ;
138147 } ,
148+ option_create : ( data : TomOption , escapeData : typeof escape_html ) : string => {
149+ return `<div class="create">${ this . createOptionTextValue . replace ( '%placeholder%' , `<strong>${ escapeData ( data . input ) } </strong>` ) } </div>` ;
150+ } ,
139151 } ;
140152
141153 const config : RecursivePartial < TomSettings > = {
@@ -240,6 +252,9 @@ export default class extends Controller {
240252 no_results : ( ) : string => {
241253 return `<div class="no-results">${ this . noResultsFoundTextValue } </div>` ;
242254 } ,
255+ option_create : ( data : TomOption , escapeData : typeof escape_html ) : string => {
256+ return `<div class="create">${ this . createOptionTextValue } <strong>${ escapeData ( data . input ) } </strong>…</div>` ;
257+ } ,
243258 } ,
244259 preload : this . preload ,
245260 } ) ;
0 commit comments