@magicx-eng/ai-autocomplete-react 0.1.16 → 0.1.18
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 +157 -129
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.mts +40 -11
- package/dist/index.d.ts +40 -11
- package/dist/index.js +87 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var fe=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Ue=(o,e)=>{for(var t in e)fe(o,t,{get:e[t],enumerable:!0})},Qe=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ve(e))!qe.call(o,r)&&r!==t&&fe(o,r,{get:()=>e[r],enumerable:!(i=Fe(e,r))||i.enumerable});return o};var je=o=>Qe(fe({},"__esModule",{value:!0}),o);var mt={};Ue(mt,{AIAutocomplete:()=>Ke,AIAutocompleteDropdown:()=>Z,useAIAutocomplete:()=>de});module.exports=je(mt);var P=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-cc65f4cc")){let o=document.createElement("style");o.id="ac-style-cc65f4cc",o.textContent=`.AIAutocomplete-module_container_KKjFU {
|
|
2
2
|
position: relative;
|
|
3
3
|
font-family: "IBM Plex Sans", sans-serif;
|
|
4
4
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
.AIAutocomplete-module_inputWrapper_FLq1b {
|
|
7
7
|
min-height: 60px;
|
|
8
8
|
padding: 24px;
|
|
9
|
-
border: 1px solid var(--
|
|
9
|
+
border: 1px solid var(--aia-color-border-default, #9ea5b2);
|
|
10
10
|
border-radius: 23px;
|
|
11
11
|
background: transparent;
|
|
12
12
|
overflow: hidden;
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
white-space: pre-wrap;
|
|
30
30
|
word-break: break-word;
|
|
31
31
|
font-family: inherit;
|
|
32
|
-
font-size: 19px;
|
|
32
|
+
font-size: var(--aia-written-text-font-size, 19px);
|
|
33
33
|
line-height: 38px;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
.AIAutocomplete-module_sizerTextVisible_HR-5h {
|
|
41
|
-
color: var(--
|
|
41
|
+
color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
|
|
42
|
+
font-size: var(--aia-written-text-font-size, inherit);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
.AIAutocomplete-module_textareaHidden_UayJt {
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
.AIAutocomplete-module_placeholderText_K3ayy {
|
|
49
|
-
color: var(--
|
|
50
|
+
color: var(--aia-color-text-muted, #c1c4cb);
|
|
50
51
|
opacity: 0.7;
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -59,10 +60,10 @@
|
|
|
59
60
|
padding: 0;
|
|
60
61
|
border: none;
|
|
61
62
|
background: transparent;
|
|
62
|
-
color: var(--
|
|
63
|
-
caret-color: var(--
|
|
63
|
+
color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
|
|
64
|
+
caret-color: var(--aia-written-text-color, var(--aia-color-text-default, #fff));
|
|
64
65
|
font-family: inherit;
|
|
65
|
-
font-size: 19px;
|
|
66
|
+
font-size: var(--aia-written-text-font-size, 19px);
|
|
66
67
|
line-height: 38px;
|
|
67
68
|
white-space: pre-wrap;
|
|
68
69
|
word-break: break-word;
|
|
@@ -72,7 +73,7 @@
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
.AIAutocomplete-module_textarea_eyn6A::placeholder {
|
|
75
|
-
color: var(--
|
|
76
|
+
color: var(--aia-color-text-muted, #c1c4cb);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
.AIAutocomplete-module_submitButton_sl1Mi {
|
|
@@ -81,8 +82,8 @@
|
|
|
81
82
|
height: 36px;
|
|
82
83
|
border-radius: 50%;
|
|
83
84
|
border: none;
|
|
84
|
-
background: var(--
|
|
85
|
-
color: var(--
|
|
85
|
+
background: var(--aia-color-text-default, #fff);
|
|
86
|
+
color: var(--aia-color-bg-default, #000);
|
|
86
87
|
cursor: pointer;
|
|
87
88
|
display: flex;
|
|
88
89
|
align-items: center;
|
|
@@ -111,12 +112,12 @@
|
|
|
111
112
|
color: transparent;
|
|
112
113
|
background: linear-gradient(
|
|
113
114
|
120deg,
|
|
114
|
-
var(--
|
|
115
|
-
var(--
|
|
115
|
+
var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 0%,
|
|
116
|
+
var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 44%,
|
|
116
117
|
#b0b0b0 48%,
|
|
117
118
|
#b0b0b0 52%,
|
|
118
|
-
var(--
|
|
119
|
-
var(--
|
|
119
|
+
var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 56%,
|
|
120
|
+
var(--aia-written-text-color, var(--aia-color-text-default, #fff)) 100%
|
|
120
121
|
);
|
|
121
122
|
background-size: 200% 100%;
|
|
122
123
|
-webkit-background-clip: text;
|
|
@@ -139,30 +140,85 @@
|
|
|
139
140
|
.AIAutocomplete-module_shimmerHidden_45-Pf {
|
|
140
141
|
color: transparent !important;
|
|
141
142
|
}
|
|
142
|
-
`,document.head.appendChild(
|
|
143
|
+
`,document.head.appendChild(o)}var k={container:"AIAutocomplete-module_container_KKjFU",inputWrapper:"AIAutocomplete-module_inputWrapper_FLq1b",editorArea:"AIAutocomplete-module_editorArea_7rBWq",sizerContent:"AIAutocomplete-module_sizerContent_DQgmV",sizerText:"AIAutocomplete-module_sizerText_iZIMK",sizerTextVisible:"AIAutocomplete-module_sizerTextVisible_HR-5h",textareaHidden:"AIAutocomplete-module_textareaHidden_UayJt",placeholderText:"AIAutocomplete-module_placeholderText_K3ayy",textarea:"AIAutocomplete-module_textarea_eyn6A",submitButton:"AIAutocomplete-module_submitButton_sl1Mi",shimmer:"AIAutocomplete-module_shimmer_13AnY",shimmerRevealed:"AIAutocomplete-module_shimmerRevealed_RR8dp",shimmerSweep:"AIAutocomplete-module_shimmerSweep_ARCon",textShimmer:"AIAutocomplete-module_textShimmer_eCLdq",shimmerHidden:"AIAutocomplete-module_shimmerHidden_45-Pf"};if(typeof document<"u"&&!document.getElementById("ac-style-2eef895d")){let o=document.createElement("style");o.id="ac-style-2eef895d",o.textContent=`.AIAutocompleteDropdown-module_dropdown_yz2KC {
|
|
143
144
|
position: absolute;
|
|
144
145
|
left: 0;
|
|
145
146
|
right: 0;
|
|
146
147
|
top: 100%;
|
|
147
148
|
margin-top: 6px;
|
|
148
|
-
|
|
149
|
-
border-radius: 23px;
|
|
149
|
+
border-radius: 1rem;
|
|
150
150
|
overflow: hidden;
|
|
151
151
|
z-index: 10;
|
|
152
152
|
opacity: 0;
|
|
153
153
|
pointer-events: none;
|
|
154
154
|
transition: opacity 400ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
155
|
+
background: transparent;
|
|
156
|
+
backdrop-filter: blur(12px);
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
.AIAutocompleteDropdown-module_visible_QCoXj {
|
|
158
160
|
opacity: 1;
|
|
159
161
|
pointer-events: auto;
|
|
160
162
|
}
|
|
161
|
-
|
|
163
|
+
|
|
164
|
+
.AIAutocompleteDropdown-module_pillBar_pwTXe {
|
|
165
|
+
padding: 27px 27px 0px 27px;
|
|
166
|
+
}
|
|
167
|
+
`,document.head.appendChild(o)}var J={dropdown:"AIAutocompleteDropdown-module_dropdown_yz2KC",visible:"AIAutocompleteDropdown-module_visible_QCoXj",pillBar:"AIAutocompleteDropdown-module_pillBar_pwTXe"};if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let o=document.createElement("style");o.id="ac-style-b745b4fb",o.textContent=`.PillList-module_list_qvLqO {
|
|
168
|
+
position: relative;
|
|
169
|
+
z-index: 1;
|
|
170
|
+
pointer-events: auto;
|
|
171
|
+
display: inline-flex;
|
|
172
|
+
gap: 5px;
|
|
173
|
+
align-items: center;
|
|
174
|
+
vertical-align: middle;
|
|
175
|
+
transform: translateY(-3px);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.PillList-module_pill_osSyz {
|
|
179
|
+
display: inline-flex;
|
|
180
|
+
align-items: center;
|
|
181
|
+
justify-content: center;
|
|
182
|
+
height: 36px;
|
|
183
|
+
padding: 13px 13px;
|
|
184
|
+
border: none;
|
|
185
|
+
border-radius: 999px;
|
|
186
|
+
background: rgba(49, 50, 85, 0.25);
|
|
187
|
+
background: color-mix(
|
|
188
|
+
in srgb,
|
|
189
|
+
var(--aia-pill-bg, var(--aia-color-background-supportive, #313255)) 25%,
|
|
190
|
+
transparent
|
|
191
|
+
);
|
|
192
|
+
color: var(--aia-pill-color, var(--aia-color-text-muted, #c1c4cb));
|
|
193
|
+
font-family: "IBM Plex Sans", sans-serif;
|
|
194
|
+
font-size: var(--aia-pill-font-size, 19px);
|
|
195
|
+
line-height: 30px;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
white-space: nowrap;
|
|
198
|
+
animation: PillList-module_fadeIn_Aezob 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.PillList-module_rounded_WvXy4 {
|
|
202
|
+
border-radius: 999px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.PillList-module_pill_osSyz:hover {
|
|
206
|
+
filter: brightness(1.2);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.PillList-module_active_Oll-- {
|
|
210
|
+
outline: 1px solid #5a5b8a;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@keyframes PillList-module_fadeIn_Aezob {
|
|
214
|
+
from {
|
|
215
|
+
opacity: 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
`,document.head.appendChild(o)}var U={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",rounded:"PillList-module_rounded_WvXy4",active:"PillList-module_active_Oll--"};var he=require("react/jsx-runtime");function Ge(o){return o===0?.4:o===1?.3:.15}function Y({pills:o,activePillIndex:e,onSelectPill:t,rounded:i}){return(0,he.jsx)("span",{className:U.list,children:o.map((r,n)=>(0,he.jsx)("button",{type:"button",className:`${U.pill} ${i?U.rounded:""} ${n===e?U.active:""}`,style:{opacity:Ge(n)},onClick:()=>t(n),children:r.text},`${r.type}-${r.text}`))})}if(typeof document<"u"&&!document.getElementById("ac-style-d91f2b06")){let o=document.createElement("style");o.id="ac-style-d91f2b06",o.textContent=`.SuggestionGrid-module_grid_jvaPb {
|
|
162
219
|
display: grid;
|
|
163
220
|
grid-template-columns: 1fr 1fr;
|
|
164
|
-
|
|
165
|
-
padding: 18px 24px;
|
|
221
|
+
padding: 13px 13px;
|
|
166
222
|
max-height: 192px;
|
|
167
223
|
overflow-y: auto;
|
|
168
224
|
scrollbar-width: thin;
|
|
@@ -181,20 +237,20 @@
|
|
|
181
237
|
background: rgba(255, 255, 255, 0.3);
|
|
182
238
|
border-radius: 3px;
|
|
183
239
|
}
|
|
184
|
-
`,document.head.appendChild(
|
|
240
|
+
`,document.head.appendChild(o)}var Se={grid:"SuggestionGrid-module_grid_jvaPb"};var B=require("react");if(typeof document<"u"&&!document.getElementById("ac-style-f6bdc634")){let o=document.createElement("style");o.id="ac-style-f6bdc634",o.textContent=`.SuggestionItem-module_item_d4vpD {
|
|
185
241
|
position: relative;
|
|
186
242
|
overflow: visible;
|
|
187
243
|
display: flex;
|
|
188
244
|
align-items: center;
|
|
189
245
|
font-family: "IBM Plex Sans", sans-serif;
|
|
190
|
-
font-size: 19px;
|
|
246
|
+
font-size: var(--aia-option-font-size, 19px);
|
|
191
247
|
line-height: 30px;
|
|
192
|
-
color: var(--
|
|
248
|
+
color: var(--aia-option-color, var(--aia-color-text-muted, #c1c4cb));
|
|
193
249
|
white-space: normal;
|
|
194
250
|
word-break: break-word;
|
|
195
|
-
opacity: 0.
|
|
251
|
+
opacity: 0.4;
|
|
196
252
|
border-radius: 12px;
|
|
197
|
-
padding:
|
|
253
|
+
padding: 13px 13px;
|
|
198
254
|
animation: SuggestionItem-module_fadeIn_I8u35 500ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
199
255
|
}
|
|
200
256
|
|
|
@@ -214,7 +270,7 @@
|
|
|
214
270
|
}
|
|
215
271
|
|
|
216
272
|
.SuggestionItem-module_tappable_70KcX:hover {
|
|
217
|
-
color: var(--
|
|
273
|
+
color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
|
|
218
274
|
}
|
|
219
275
|
|
|
220
276
|
.SuggestionItem-module_nonTappable_xSZM- {
|
|
@@ -223,7 +279,8 @@
|
|
|
223
279
|
}
|
|
224
280
|
|
|
225
281
|
.SuggestionItem-module_highlighted_Hb0SU {
|
|
226
|
-
color: var(--
|
|
282
|
+
color: var(--aia-option-color-selected, var(--aia-color-text-default, #fff));
|
|
283
|
+
background: var(--aia-option-bg, transparent);
|
|
227
284
|
opacity: 0.5;
|
|
228
285
|
}
|
|
229
286
|
|
|
@@ -235,7 +292,7 @@
|
|
|
235
292
|
|
|
236
293
|
.SuggestionItem-module_pressed_98o-r {
|
|
237
294
|
opacity: 0.8;
|
|
238
|
-
color: var(--
|
|
295
|
+
color: var(--aia-color-text-default, #fff);
|
|
239
296
|
background: rgba(255, 255, 255, 0.06);
|
|
240
297
|
animation:
|
|
241
298
|
SuggestionItem-module_glassFade_oyiSj 500ms ease forwards,
|
|
@@ -487,47 +544,5 @@
|
|
|
487
544
|
box-shadow: 0 0 24px 10px rgba(255, 255, 255, 0.02);
|
|
488
545
|
}
|
|
489
546
|
}
|
|
490
|
-
`,document.head.appendChild(e)}var W={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};var oe=require("react/jsx-runtime");function $e({option:e,isHighlighted:r,onSelect:t,onHighlight:o,id:n}){let[a,l]=(0,fe.useState)(!1),m=(0,fe.useRef)(void 0),d=()=>{!e.is_tappable||a||(l(!0),t(e),clearTimeout(m.current),m.current=setTimeout(()=>l(!1),400))},c=[W.item,r?W.highlighted:"",e.is_tappable?W.tappable:W.nonTappable,a?W.pressed:""].filter(Boolean).join(" ");return(0,oe.jsxs)("div",{id:n,role:"option","aria-selected":r,className:c,tabIndex:e.is_tappable?0:-1,onClick:d,onKeyDown:u=>{e.is_tappable&&(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),d())},onMouseEnter:o,children:[(0,oe.jsx)("div",{className:W.streaks}),(0,oe.jsx)("div",{className:W.streaksVert}),(0,oe.jsxs)("span",{className:W.content,children:[e.icon?`${e.icon} ${e.text}`:e.text,e.tag&&(0,oe.jsx)("span",{className:W.tag,children:e.tag})]})]})}var Ce=require("react/jsx-runtime");function De({options:e,activeIndex:r,onSelect:t,onHighlight:o,listboxId:n}){return(0,Ce.jsx)("div",{className:Ue.grid,children:e.map((a,l)=>(0,Ce.jsx)($e,{option:a,isHighlighted:l===r,onSelect:t,onHighlight:()=>o(l),id:`${n}-option-${l}`},a.text))})}var Re=require("react/jsx-runtime");function be({suggestions:e,activeIndex:r,onSelect:t,onHighlight:o,isOpen:n,id:a,className:l}){let d=e[0]?.options??[],c=n&&d.length>0;return(0,Re.jsx)("div",{id:a,role:"listbox",className:`${ke.dropdown} ${c?ke.visible:""} ${l??""}`,onMouseDown:u=>u.preventDefault(),children:d.length>0&&(0,Re.jsx)(De,{options:d,activeIndex:r,onSelect:t,onHighlight:o,listboxId:a})})}if(typeof document<"u"&&!document.getElementById("ac-style-b745b4fb")){let e=document.createElement("style");e.id="ac-style-b745b4fb",e.textContent=`.PillList-module_list_qvLqO {
|
|
491
|
-
position: relative;
|
|
492
|
-
z-index: 1;
|
|
493
|
-
pointer-events: auto;
|
|
494
|
-
display: inline-flex;
|
|
495
|
-
gap: 5px;
|
|
496
|
-
align-items: center;
|
|
497
|
-
vertical-align: middle;
|
|
498
|
-
transform: translateY(-3px);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
.PillList-module_pill_osSyz {
|
|
502
|
-
display: inline-flex;
|
|
503
|
-
align-items: center;
|
|
504
|
-
justify-content: center;
|
|
505
|
-
height: 36px;
|
|
506
|
-
padding: 7px 9px;
|
|
507
|
-
border: none;
|
|
508
|
-
border-radius: 6px;
|
|
509
|
-
background: var(--ac-color-background-supportive, #313255);
|
|
510
|
-
color: var(--ac-color-text-muted, #c1c4cb);
|
|
511
|
-
font-family: "IBM Plex Sans", sans-serif;
|
|
512
|
-
font-size: 19px;
|
|
513
|
-
line-height: 30px;
|
|
514
|
-
cursor: pointer;
|
|
515
|
-
white-space: nowrap;
|
|
516
|
-
animation: PillList-module_fadeIn_Aezob 400ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
.PillList-module_pill_osSyz:hover {
|
|
520
|
-
filter: brightness(1.2);
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
.PillList-module_active_Oll-- {
|
|
524
|
-
outline: 1px solid #5a5b8a;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
@keyframes PillList-module_fadeIn_Aezob {
|
|
528
|
-
from {
|
|
529
|
-
opacity: 0;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
`,document.head.appendChild(e)}var he={list:"PillList-module_list_qvLqO",pill:"PillList-module_pill_osSyz",fadeIn:"PillList-module_fadeIn_Aezob",active:"PillList-module_active_Oll--"};var Oe=require("react/jsx-runtime");function dt(e){return e===0?.4:e===1?.3:.15}function He({pills:e,activePillIndex:r,onSelectPill:t}){return(0,Oe.jsx)("span",{className:he.list,children:e.map((o,n)=>(0,Oe.jsx)("button",{type:"button",className:`${he.pill} ${n===r?he.active:""}`,style:{opacity:dt(n)},onClick:()=>t(n),children:o.text},`${o.type}-${o.text}`))})}var p=require("react");function ae(e,r,t){let o=e.slice(r);if(t||r===0||e[r-1]===" ")return o;let n=o.indexOf(" ");return n===-1?"":o.slice(n+1)}function xe(e,r){if(!e)return[];let t=r.trimStart();if(!t)return e;let o=t.toLowerCase();return e.filter(n=>!n.is_tappable||n.text.toLowerCase().includes(o))}function me(e,r){if(!e)return null;let t=r.trim();if(!t)return null;let o=t.toLowerCase();return e.find(n=>n.is_tappable&&n.text.toLowerCase()===o)??null}function Ne(e,r){let t=[],o=0;for(let a of r){let l=e.indexOf(a.text,o);l!==-1&&(l>o&&t.push({type:"text",value:e.slice(o,l)}),t.push({type:"completed",value:a.text,param:a}),o=l+a.text.length)}let n=e.slice(o);return n&&t.push({type:"text",value:n}),t}function Ve(e,r){let t=[],o=[],n=0;for(let a of r){let l=e.indexOf(a.text,n);l===-1?o.push(a):(t.push(a),n=l+a.text.length)}return{valid:t,invalid:o}}var U=require("react");var mt="0.1.16",je=!1;function gt(){return crypto.randomUUID()}function ft(e,r){return{placeholder:e.placeholder,type:e.type,...r&&{text:e.text},kind:e.kind}}async function Be(e,r,t){let o=t?.apiConfig,n=o?.apiKey??"";!n&&!je&&(je=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header."));let a=o?.authScheme??"Bearer",l=!t?.maskCompletedText,m=r.find(f=>f.type==="contact"&&f.metadata?.contact_account_count)?.metadata?.contact_account_count,d=typeof m=="number"?m:void 0,c={data:{raw_query:e,completed_params:r.map(f=>ft(f,l)),...d!=null&&{contact_account_count:d}},meta:{request_id:gt(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:mt}},u={"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers};n&&(u.Authorization=a==="Basic"?`Basic ${btoa(n)}`:`Bearer ${n}`);let g=await fetch(o?.endpoint??"/ac/suggest",{method:"POST",headers:u,body:JSON.stringify(c),signal:t?.signal});if(!g.ok)throw new Error(`API error: ${g.status} ${g.statusText}`);return g.json()}function se(e,r){let t=e,o={},n=[];for(let a of r){let l=(o[a.type]??0)+1;o[a.type]=l;let d=`{{${a.type.toUpperCase().replace(/\s+/g,"_")}_${l}}}`,c=t.indexOf(a.text);c!==-1&&(t=t.slice(0,c)+d+t.slice(c+a.text.length)),n.push({...a,placeholder:d})}return{rawQuery:t,completedParams:n}}function Ke(e,r){return r?e.map(t=>{let o=r[t.type];if(!o)return t;let n=o("");if(n.length===0)return t;let a=new Set(n.map(m=>m.text)),l=(t.options??[]).filter(m=>!a.has(m.text));return{...t,options:[...n,...l]}}):e}var bt=100,ht=300,xt=2;function qe({textRef:e,suggestionsRef:r,filterBaseRef:t,filterInProgressRef:o,maskCompletedTextRef:n,apiConfigRef:a,optionOverridesRef:l,onErrorRef:m,setCompletedParams:d,setSuggestions:c,setActiveDropdownIndex:u}){let[g,f]=(0,U.useState)(!1),[_,z]=(0,U.useState)(null),[w,b]=(0,U.useState)(!1),S=(0,U.useRef)(0),A=(0,U.useRef)(null),x=(0,U.useRef)(""),v=(0,U.useCallback)(async(B,I)=>{A.current?.abort();let P=new AbortController;A.current=P;let i=++S.current,s=e.current.length;r.current.some(L=>L.type!=="placeholder")||f(!0),z(null);try{let L=await Be(B,I,{maskCompletedText:n.current,signal:P.signal,apiConfig:a.current});if(i!==S.current)return;let O=Ke(L.data.suggestions??[],l.current);b(L.data.is_ready??!1),x.current=B;let ee=L.data.input??[],J=ee[ee.length-1],$=e.current;if(J?.state==="in_progress"){o.current=!0;let K=$.toLowerCase().lastIndexOf(J.text.toLowerCase());K!==-1?t.current=K:t.current=s}else o.current=!1,t.current=s;let V=O.filter(K=>K.type!=="placeholder")[0];if(V){let K=ae($,t.current,o.current),X=me(V.options,K);X&&(d(y=>[...y,{id:crypto.randomUUID(),placeholder:"",type:V.type,text:X.text,kind:X.kind,suggestionType:V.type,suggestionPlaceholder:V.text,options:V.options??[],metadata:X.metadata}]),O=O.filter(y=>y!==V))}c(O),f(!1),u(-1)}catch(L){if(i===S.current){let O=L instanceof Error?L:new Error(String(L));z(O),f(!1),m.current?.(O)}}},[e,r,t,o,n,a,l,m,d,c,u]);return(0,U.useEffect)(()=>(v("",[]),()=>{A.current?.abort()}),[v]),{doFetch:v,isLoading:g,error:_,isReady:w,lastRawQueryRef:x}}function Qe({text:e,completedParams:r,doFetch:t,filterBaseRef:o,filterInProgressRef:n,skipNextFetchRef:a,suggestionsRef:l,lastRawQueryRef:m}){let d=(0,U.useRef)(null),c=(0,U.useRef)(null),u=(0,U.useRef)(!0);(0,U.useEffect)(()=>{if(d.current&&clearTimeout(d.current),c.current&&clearTimeout(c.current),a.current){a.current=!1;return}let g=f=>{if(!e&&r.length===0)return u.current?(t("",[]),!0):(u.current=!0,!1);let _=ae(e,o.current,n.current),b=l.current.filter(s=>s.type!=="placeholder")[0],A=(b?xe(b.options,_):[]).filter(s=>s.is_tappable),x=b?me(b.options,_)!==null:!1,v=_.trim().length>0;if(A.length>0&&!x&&v)return!1;let{rawQuery:B,completedParams:I}=se(e,r),P=B.length<m.current.length,i=Math.abs(B.length-m.current.length);return P||i>=f?(t(B,I),!0):!1};return d.current=setTimeout(()=>{g(xt)&&c.current&&clearTimeout(c.current)},bt),c.current=setTimeout(()=>g(1),ht),()=>{d.current&&clearTimeout(d.current),c.current&&clearTimeout(c.current)}},[e,r,t,o,n,a,l,m])}var Te=require("react");function Ge({activeDropdownIndex:e,setActiveDropdownIndex:r,filteredOptions:t,selectOption:o,onSubmitRef:n,text:a,completedParams:l,isDropdownOpen:m,hasPlaceholder:d,placeholderText:c,suggestions:u,actionableSuggestions:g,setActivePill:f,listboxId:_,pillTappedRef:z,filterBaseRef:w,columns:b,setText:S,setCompletedParams:A,setSuggestions:x}){let v=(0,Te.useCallback)(()=>{let I=t.map((i,s)=>i.is_tappable?s:-1).filter(i=>i!==-1),P=Array.from({length:b},()=>[]);for(let i of I)P[i%b].push(i);return P.flat()},[t,b]);return{handleKeyDown:(0,Te.useCallback)(I=>{let P=v();switch(I.key){case"ArrowDown":{let i=I.target;if(!(i.selectionStart!=null&&i.selectionStart===i.value.length)&&e<0)break;if(I.preventDefault(),!m&&g.length>0){z.current=!0;let O=P[0];r(O??0);break}if(P.length===0)return;let C=P.indexOf(e),L=C<P.length-1?C+1:0;r(P[L]);break}case"ArrowUp":{if(P.length===0||e<0)break;if(I.preventDefault(),e<b){r(-1);break}let s=P.indexOf(e),C=s>0?s-1:P.length-1;r(P[C]);break}case"ArrowRight":{if(e<0){let s=I.target;s.selectionStart!=null&&s.selectionStart===s.value.length&&g.length>1&&(I.preventDefault(),f(1));break}if(e%b<b-1){let s=e+1;s<t.length&&t[s]?.is_tappable&&(I.preventDefault(),r(s))}break}case"ArrowLeft":{if(e<0)break;if(e%b>0){let i=e-1;i>=0&&t[i]?.is_tappable&&(I.preventDefault(),r(i))}break}case"Enter":{if(I.preventDefault(),e>=0&&t[e]?.is_tappable){let i=document.getElementById(`${_}-option-${e}`);i?i.click():o(t[e])}else if(n.current){let{rawQuery:i,completedParams:s}=se(a,l),C={query:a.trim(),raw_query:i,completed_params:s};n.current(C)}break}case"Tab":{if(e>=0&&t[e]?.is_tappable){I.preventDefault();let i=document.getElementById(`${_}-option-${e}`);i?i.click():o(t[e])}else if(m){let i=t.findIndex(s=>s.is_tappable);if(i>=0){I.preventDefault();let s=document.getElementById(`${_}-option-${i}`);s?s.click():o(t[i])}}else if(!a&&d){I.preventDefault();let i=u.find(s=>s.type==="placeholder");i?(S(c),w.current=c.length,A(s=>[...s,{id:crypto.randomUUID(),placeholder:"",type:i.type,text:c,kind:null,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[]}]),x(s=>s.filter(C=>C!==i))):(S(c),w.current=c.length)}break}case"Escape":r(-1);break}},[g,e,b,l,t,w,v,d,_,z,m,n,c,o,r,f,A,x,S,u,a]),getTappableIndices:v}}var ye=require("react");function We({completedParams:e,suggestions:r,setCompletedParams:t,setSuggestions:o,setActiveDropdownIndex:n,filterBaseRef:a,pillTappedRef:l}){let m=(0,ye.useCallback)(u=>{let g=r.filter(w=>w.type!=="placeholder");if(u<0||u>=g.length)return;let f=g[u],_=g.filter((w,b)=>b!==u),z=r.filter(w=>w.type==="placeholder");o([...z,f,..._]),l.current=!0,n(-1)},[r,o,n,l]),d=(0,ye.useCallback)(()=>{if(e.length===0)return;let u=e[e.length-1],g={type:u.suggestionType,text:u.suggestionPlaceholder,required:!0,options:u.options};t(f=>f.slice(0,-1)),o(f=>[g,...f]),n(-1)},[e,t,o,n]),c=(0,ye.useCallback)(u=>{let g={type:u.suggestionType,text:u.suggestionPlaceholder,required:!0,options:u.options};return{apply:f=>{f(_=>{let z=0;for(let w of e){let b=_.indexOf(w.text,z);if(b!==-1){if(w.id===u.id){let S=_.slice(0,b),A=_.slice(b+u.text.length),x=(S+A).replace(/ {2,}/g," ");return a.current=Math.min(a.current,x.length),x}z=b+w.text.length}}return _}),t(_=>_.filter(z=>z.id!==u.id)),o(_=>[g,..._]),n(-1),l.current=!0}}},[e,t,o,n,a,l]);return{setActivePill:m,removeLastParam:d,reEditParam:c}}var yt=0;function _t(){let e=(0,p.useRef)(null);return e.current===null&&(e.current=`:ac-${++yt}:`),e.current}function _e({onSubmit:e,onError:r,optionOverrides:t,maskCompletedText:o,placeholder:n,apiConfig:a,columns:l=2,value:m,completedParams:d,onChange:c,onParamsChange:u}){let g=m!==void 0,f=d!==void 0,[_,z]=(0,p.useState)(""),[w,b]=(0,p.useState)([]),[S,A]=(0,p.useState)([]),[x,v]=(0,p.useState)(-1),[B,I]=(0,p.useState)(null),P=(0,p.useCallback)(()=>I(null),[]),i=g?m:_,s=f?d:w,C=(0,p.useRef)(e);C.current=e;let L=(0,p.useRef)(c);L.current=c;let O=(0,p.useRef)(u);O.current=u;let ee=(0,p.useRef)(m);ee.current=m;let J=(0,p.useRef)(d);J.current=d;let $=(0,p.useCallback)(h=>{if(typeof h=="function")if(g){let R=h(ee.current??"");L.current?.(R)}else z(R=>{let T=h(R);return L.current?.(T),T});else g||z(h),L.current?.(h)},[g]),N=(0,p.useCallback)(h=>{if(typeof h=="function")if(f){let R=h(J.current??[]);O.current?.(R)}else b(R=>{let T=h(R);return O.current?.(T),T});else f||b(h),O.current?.(h)},[f]),V=(0,p.useRef)(r);V.current=r;let K=(0,p.useRef)(t);K.current=t;let X=(0,p.useRef)(o);X.current=o;let y=(0,p.useRef)(a);y.current=a;let H=(0,p.useRef)(i);H.current=i;let re=(0,p.useRef)(S);re.current=S;let M=(0,p.useRef)(0),q=(0,p.useRef)(!1),j=(0,p.useRef)(!1),le=(0,p.useRef)(!1),Z=_t(),{doFetch:ue,isLoading:Ee,error:Xe,isReady:Ze,lastRawQueryRef:Se}=qe({textRef:H,suggestionsRef:re,filterBaseRef:M,filterInProgressRef:q,maskCompletedTextRef:X,apiConfigRef:y,optionOverridesRef:K,onErrorRef:V,setCompletedParams:N,setSuggestions:A,setActiveDropdownIndex:v});Qe({text:i,completedParams:s,doFetch:ue,filterBaseRef:M,filterInProgressRef:q,skipNextFetchRef:le,suggestionsRef:re,lastRawQueryRef:Se});let Ye=(0,p.useMemo)(()=>Ne(i,s),[i,s]);M.current=Math.min(M.current,i.length);let Ae=ae(i,M.current,q.current),ne=(0,p.useMemo)(()=>S.filter(R=>R.type==="placeholder").map(R=>R.text).join(" ")||n||"",[S,n]),ce=(0,p.useMemo)(()=>S.filter(h=>h.type!=="placeholder"),[S]),k=ce[0],ze=k?t?.[k.type]:void 0,Le=k?ze?ze(Ae.trim()):k.options??[]:[],ve=(0,p.useMemo)(()=>xe(Le,Ae),[Le,Ae]),Me=ne.length>0,Ie=!Ee&&ve.length>0&&(!!i||j.current||!Me),Fe=(0,p.useCallback)(h=>{if(!k)return;let R=M.current,T=H.current.slice(0,R),ie=T.length===0&&H.current.length===0;if(ie&&ne&&(T=ne+" "),T.length>0&&!T.endsWith(" ")){let te=T.split(/\s+/).pop()??"";te&&h.text.toLowerCase().startsWith(te.toLowerCase())&&(T=T.slice(0,T.length-te.length))}let we=T.length>0&&T[T.length-1]!==" ",Y=T+(we?" ":"")+h.text+" ",Q=ie&&Y.length>0?Y[0].toUpperCase()+Y.slice(1):Y,G=Q.toLowerCase().lastIndexOf(h.text.toLowerCase()),de=G>=0?Q.slice(G,G+h.text.length):h.text,ge={id:crypto.randomUUID(),placeholder:"",type:k.type,text:de,kind:h.kind,suggestionType:k.type,suggestionPlaceholder:k.text,options:k.options??[],metadata:h.metadata};$(Q),M.current=Q.length,N(te=>[...te,ge]),I(ge.id),j.current=!1,v(-1),ce.length-1>0&&(le.current=!0),setTimeout(()=>{A(te=>te.filter(it=>it!==k))},400)},[k,ce,ne,$,N]),et=(0,p.useCallback)(h=>{let R=h.target.value,ie=R.length>0&&!h.nativeEvent?.isComposing&&R[0]!==R[0].toUpperCase()?R[0].toUpperCase()+R.slice(1):R;$(ie),j.current=!1,v(-1);let{valid:we,invalid:Y}=Ve(ie,s);if(Y.length>0){N(()=>we);for(let Q of Y)A(G=>[{type:Q.suggestionType,text:Q.suggestionPlaceholder,required:!0,options:Q.options},...G])}if(k&&Y.length===0){let Q=ae(ie,M.current,q.current),G=me(k.options,Q);G&&(N(de=>[...de,{id:crypto.randomUUID(),placeholder:"",type:k.type,text:G.text,kind:G.kind,suggestionType:k.type,suggestionPlaceholder:k.text,options:k.options??[],metadata:G.metadata}]),A(de=>de.filter(ge=>ge!==k)))}},[s,k,$,N]),pe=We({completedParams:s,suggestions:S,setCompletedParams:N,setSuggestions:A,setActiveDropdownIndex:v,filterBaseRef:M,pillTappedRef:j}),tt=(0,p.useCallback)(h=>{pe.reEditParam(h).apply($)},[pe,$]),{handleKeyDown:ot}=Ge({activeDropdownIndex:x,setActiveDropdownIndex:v,filteredOptions:ve,selectOption:Fe,onSubmitRef:C,text:i,completedParams:s,isDropdownOpen:Ie,hasPlaceholder:Me,placeholderText:ne,suggestions:S,actionableSuggestions:ce,setActivePill:pe.setActivePill,listboxId:Z,pillTappedRef:j,filterBaseRef:M,columns:l,setText:$,setCompletedParams:N,setSuggestions:A}),rt=(0,p.useCallback)(()=>{$(""),N(()=>[]),A([]),v(-1),M.current=0,q.current=!1,Se.current="",ue("",[])},[ue,$,N,Se]),nt=x>=0?`${Z}-option-${x}`:void 0;return{completedParams:s,suggestionPills:ce,setActivePill:pe.setActivePill,removeLastParam:pe.removeLastParam,reEditParam:tt,segments:Ye,newParamId:B,clearNewParamId:P,suggestions:S,activeIndex:x,isReady:Ze,isLoading:Ee,error:Xe,inputProps:{value:i,placeholder:ne||void 0,onChange:et,onKeyDown:ot,role:"combobox","aria-expanded":Ie,"aria-activedescendant":nt,"aria-autocomplete":"list","aria-controls":Z},reset:rt,dropdownProps:{suggestions:k?[{...k,options:ve}]:[],activeIndex:x,onSelect:Fe,onHighlight:v,isOpen:Ie,id:Z}}}var E=require("react/jsx-runtime"),Je=(0,D.forwardRef)(function({onSubmit:r,onError:t,optionOverrides:o,maskCompletedText:n,placeholder:a,className:l,apiConfig:m,columns:d,typewriterEffect:c=!0,value:u,completedParams:g,onChange:f,onParamsChange:_},z){let w=(0,D.useRef)(null),b=(0,D.useRef)(()=>{}),[S,A]=(0,D.useState)(0),x=(0,D.useRef)(void 0);(0,D.useEffect)(()=>(w.current?.focus(),()=>{x.current&&cancelAnimationFrame(x.current)}),[]);let{completedParams:v,suggestionPills:B,setActivePill:I,segments:P,newParamId:i,clearNewParamId:s,inputProps:C,dropdownProps:L,reset:O}=_e({onSubmit:y=>b.current(y),onError:t,optionOverrides:o,maskCompletedText:n,placeholder:a,apiConfig:m,columns:d,value:u,completedParams:g,onChange:f,onParamsChange:_});(0,D.useEffect)(()=>{if(x.current&&cancelAnimationFrame(x.current),!i){A(0);return}let y=v.find(j=>j.id===i);if(!y)return;let H=y.text.length;if(!c){A(H);let j=window.setTimeout(()=>s(),650);return()=>window.clearTimeout(j)}A(0);let re=performance.now(),M=300,q=()=>{let j=performance.now()-re,le=Math.min(j/M,1),Z=Math.ceil(le*H);A(Z),Z<H?x.current=requestAnimationFrame(q):x.current=requestAnimationFrame(()=>{s()})};return x.current=requestAnimationFrame(q),()=>{x.current&&cancelAnimationFrame(x.current)}},[i,v,s,c]),(0,D.useImperativeHandle)(z,()=>({focus:()=>w.current?.focus(),reset:O}),[O]);let ee=()=>{w.current?.focus()},J=!!C.value||v.length>0,$=(0,D.useCallback)(()=>{if(!J)return;let{rawQuery:y,completedParams:H}=se(C.value,v);r({query:C.value.trim(),raw_query:y,completed_params:H}),O()},[J,C.value,v,r,O]);b.current=$;let{onChange:N,placeholder:V,...K}=C,X=!C.value;return(0,E.jsxs)("div",{className:`${F.container} ${l??""}`,children:[(0,E.jsx)(be,{...L}),(0,E.jsxs)("div",{className:F.inputWrapper,onClick:ee,children:[(0,E.jsxs)("div",{className:F.editorArea,children:[(0,E.jsxs)("div",{className:F.sizerContent,"aria-hidden":"true",children:[X&&V?(0,E.jsxs)("span",{className:F.placeholderText,children:[V," "]}):(0,E.jsxs)("span",{className:`${F.sizerText} ${i?F.sizerTextVisible:""}`,children:[P.map((y,H)=>{if(y.type==="completed"&&y.param.id===i){if(!c){let ue=`${F.shimmerRevealed} ${F.shimmerSweep}`;return(0,E.jsx)("span",{className:ue,children:y.value},`${H}-${y.type}`)}let M=y.value.length,q=y.value.slice(0,S),j=y.value.slice(S),Z=`${100-(M>0?S/M:0)*100}% 0`;return(0,E.jsxs)("span",{className:F.shimmer,children:[(0,E.jsx)("span",{className:F.shimmerRevealed,style:{backgroundPosition:Z},children:q}),(0,E.jsx)("span",{className:F.shimmerHidden,children:j})]},`${H}-${y.type}`)}return(0,E.jsx)("span",{children:y.value},`${H}-${y.type}`)}),P.length===0&&"\xA0"]})," ",(0,E.jsx)(He,{pills:B,activePillIndex:0,onSelectPill:I})]}),(0,E.jsx)("textarea",{ref:w,className:`${F.textarea} ${i?F.textareaHidden:""}`,rows:1,onChange:N,...K})]}),(0,E.jsx)("button",{type:"button",className:F.submitButton,disabled:!J,onClick:y=>{y.stopPropagation(),$()},"aria-label":"Submit",children:(0,E.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,E.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
|
|
547
|
+
`,document.head.appendChild(o)}var O={item:"SuggestionItem-module_item_d4vpD",fadeIn:"SuggestionItem-module_fadeIn_I8u35",content:"SuggestionItem-module_content_T-Qba",tappable:"SuggestionItem-module_tappable_70KcX",nonTappable:"SuggestionItem-module_nonTappable_xSZM-",highlighted:"SuggestionItem-module_highlighted_Hb0SU",tag:"SuggestionItem-module_tag_e3Fwe",pressed:"SuggestionItem-module_pressed_98o-r",glassFade:"SuggestionItem-module_glassFade_oyiSj",tapDown:"SuggestionItem-module_tapDown_G3WGz",streaks:"SuggestionItem-module_streaks_d9PEB",streaksVert:"SuggestionItem-module_streaksVert_ERlV1",streakHorizRight:"SuggestionItem-module_streakHorizRight_aboGz",streakHorizLeft:"SuggestionItem-module_streakHorizLeft_BreWJ",streakVertUp:"SuggestionItem-module_streakVertUp_to1GD",streakVertDown:"SuggestionItem-module_streakVertDown_OrcLh"};var M=require("react/jsx-runtime");function Ie({option:o,isHighlighted:e,onSelect:t,onHighlight:i,id:r}){let[n,a]=(0,B.useState)(!1),d=(0,B.useRef)(void 0);(0,B.useEffect)(()=>()=>clearTimeout(d.current),[]);let s=()=>{!o.is_tappable||n||(a(!0),t(o),clearTimeout(d.current),d.current=setTimeout(()=>a(!1),400))},l=[O.item,e?O.highlighted:"",o.is_tappable?O.tappable:O.nonTappable,n?O.pressed:""].filter(Boolean).join(" ");return(0,M.jsxs)("div",{id:r,role:"option","aria-selected":e,className:l,tabIndex:o.is_tappable?0:-1,onClick:s,onKeyDown:p=>{o.is_tappable&&(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),s())},onMouseEnter:i,children:[(0,M.jsx)("div",{className:O.streaks}),(0,M.jsx)("div",{className:O.streaksVert}),(0,M.jsxs)("span",{className:O.content,children:[o.icon?`${o.icon} ${o.text}`:o.text,o.tag&&(0,M.jsx)("span",{className:O.tag,children:o.tag})]})]})}var xe=require("react/jsx-runtime");function _e({options:o,activeIndex:e,onSelect:t,onHighlight:i,listboxId:r}){return(0,xe.jsx)("div",{className:Se.grid,children:o.map((n,a)=>(0,xe.jsx)(Ie,{option:n,isHighlighted:a===e,onSelect:t,onHighlight:()=>i(a),id:`${r}-option-${a}`},n.text))})}var N=require("react/jsx-runtime");function Z({suggestions:o,activeIndex:e,onSelect:t,onHighlight:i,isOpen:r,id:n,className:a,pills:d,onPillClick:s,showPills:l=!0}){let c=o[0]?.options??[],m=l&&d&&d.length>0&&s,g=r&&c.length>0||r&&m;return(0,N.jsxs)("div",{id:n,role:"listbox","data-aia-dropdown":"",className:`${J.dropdown} ${g?J.visible:""} ${a??""}`,onMouseDown:y=>y.preventDefault(),children:[m&&(0,N.jsx)("div",{className:J.pillBar,children:(0,N.jsx)(Y,{pills:d,activePillIndex:0,onSelectPill:s,rounded:!0})}),c.length>0&&(0,N.jsx)(_e,{options:c,activeIndex:e,onSelect:t,onHighlight:i,listboxId:n})]})}var x=require("react");function Q(o,e,t){let i=o.slice(e);if(t||e===0||o[e-1]===" ")return i;let r=i.indexOf(" ");return r===-1?"":i.slice(r+1)}function Pe(o,e){let t=o.trimEnd().replace(/\s+/g," ");if(t.length===0||e.length===0)return 0;let i=t.split(" "),r=e.toLowerCase();for(let n=0;n<i.length;n++){let a=i.slice(n).join(" ");if(r.startsWith(a.toLowerCase())){let d=t.length-a.length;return o.length-d}}return 0}function ee(o,e){if(!o)return[];let t=e.trimStart();if(!t)return o;let i=t.toLowerCase();return o.filter(r=>!r.is_tappable||r.text.toLowerCase().includes(i))}function be(o,e){if(!o)return null;let t=e.trim();if(!t)return null;let i=t.toLowerCase();return o.find(r=>r.is_tappable&&r.text.toLowerCase()===i)??null}var K=class{constructor(e,t="auto"){this.container=e;this.mode=t;this.mediaQuery=null;this.onSystemChange=e=>{this.container.dataset.mode=e.matches?"dark":"light"};this.apply()}setMode(e){this.detachListener(),this.mode=e,this.apply()}destroy(){this.detachListener()}apply(){this.mode==="auto"?(this.mediaQuery??(this.mediaQuery=window.matchMedia("(prefers-color-scheme: dark)")),this.mediaQuery.addEventListener("change",this.onSystemChange),this.container.dataset.mode=this.mediaQuery.matches?"dark":"light"):this.container.dataset.mode=this.mode}detachListener(){this.mediaQuery?.removeEventListener("change",this.onSystemChange)}};function Ce(o,e){let t=[],i=0;for(let n of e){let a=o.indexOf(n.text,i);a!==-1&&(a>i&&t.push({type:"text",value:o.slice(i,a)}),t.push({type:"completed",value:n.text,param:n}),i=a+n.text.length)}let r=o.slice(i);return r&&t.push({type:"text",value:r}),t}function Ae(o,e){let t=[],i=[],r=0;for(let n of e){let a=o.indexOf(n.text,r);a===-1?i.push(n):(t.push(n),r=a+n.text.length)}return{valid:t,invalid:i}}var te=class{constructor(e){this.config=e;this.current=null;this.expiresAt=null;this.inFlightRefresh=null;e.accessToken&&(this.current=e.accessToken)}async getToken(e=!1){if(!e&&this.current&&!this.isExpired())return this.current;if(!e&&this.inFlightRefresh)return this.inFlightRefresh;this.inFlightRefresh=this.refresh();try{return await this.inFlightRefresh}finally{this.inFlightRefresh=null}}async refresh(){let e=await this.config.getAccessToken();return this.current=e.accessToken,this.expiresAt=e.expiresAt??null,this.current}isExpired(){return this.expiresAt==null?!1:Date.now()>=this.expiresAt-3e4}};var We="0.1.18",ke=!1;function Xe(){return crypto.randomUUID()}function Je(o,e){return{placeholder:o.placeholder,type:o.type,...e&&{text:o.text},kind:o.kind}}function De(o){return o?.type==="accessToken"}function Ye(o){if(!(!o||De(o)))return o}var Te=new WeakMap;function Ze(o){let e=Te.get(o.getAccessToken);return e||(e=new te(o),Te.set(o.getAccessToken,e)),e}function et(o,e,t){let i=e.find(n=>n.type==="contact"&&n.metadata?.contact_account_count)?.metadata?.contact_account_count,r=typeof i=="number"?i:void 0;return{data:{raw_query:o,completed_params:e.map(n=>Je(n,t)),...r!=null&&{contact_account_count:r}},meta:{request_id:Xe(),request_at:new Date().toISOString(),language:typeof navigator<"u"?navigator.language:"en-US",client_version:We}}}function tt(o){return{"Content-Type":"application/json",...o?.appIdentifier&&{"X-App-Identifier":o.appIdentifier},...o?.headers}}async function Oe(o,e,t,i,r){return fetch(o,{method:"POST",headers:{...e,Authorization:`Bearer ${t}`},body:i,signal:r})}async function Ee(o,e,t){let i=t?.apiConfig,r=!t?.maskCompletedText,n=et(o,e,r),a=tt(i),d=i?.endpoint??"/ac/suggest",s=JSON.stringify(n);if(De(i)){let m=Ze(i),f=await m.getToken(),g=await Oe(d,a,f,s,t?.signal);if(g.status===401){let y=await m.getToken(!0);g=await Oe(d,a,y,s,t?.signal)}if(!g.ok)throw new Error(`API error: ${g.status} ${g.statusText}`);return g.json()}let l=Ye(i),p=l?.apiKey??"";if(!p&&!ke&&(ke=!0,console.warn("[AIAutocomplete] No apiKey in apiConfig. Requests will be sent without an Authorization header.")),p){let m=l?.authScheme??"Bearer";a.Authorization=m==="Basic"?`Basic ${btoa(p)}`:`Bearer ${p}`}let c=await fetch(d,{method:"POST",headers:a,body:s,signal:t?.signal});if(!c.ok)throw new Error(`API error: ${c.status} ${c.statusText}`);return c.json()}function L(o,e){let t=o,i={},r=[];for(let n of e){let a=(i[n.type]??0)+1;i[n.type]=a;let s=`{{${n.type.toUpperCase().replace(/\s+/g,"_")}_${a}}}`,l=t.indexOf(n.text);l!==-1&&(t=t.slice(0,l)+s+t.slice(l+n.text.length)),r.push({...n,placeholder:s})}return{rawQuery:t,completedParams:r}}function Le(o,e){return e?o.map(t=>{let i=e[t.type];if(!i)return t;let r=i("");if(r.length===0)return t;let n=new Set(r.map(d=>d.text)),a=(t.options??[]).filter(d=>!n.has(d.text));return{...t,options:[...r,...a]}}):o}var ot=100,it=300,nt=2,oe=class{constructor(e,t,i,r,n){this.store=e;this.getApiConfig=t;this.getOptionOverrides=i;this.getMaskCompletedText=r;this.getOnError=n;this.fetchVersion=0;this.abortController=null;this.debounceTimer=null;this.slowDebounceTimer=null;this.unsubscribe=null}start(){this.doFetch("",[]);let e=this.store.get().text,t=this.store.get().completedParams;this.unsubscribe=this.store.subscribe(i=>{(i.text!==e||i.completedParams!==t)&&(e=i.text,t=i.completedParams,this.scheduleFetch())})}dispose(){this.abortController?.abort(),this.clearTimers(),this.unsubscribe?.()}async doFetch(e,t){this.abortController?.abort();let i=new AbortController;this.abortController=i;let r=++this.fetchVersion,n=this.store.get(),a=n.text.length;n.suggestions.some(s=>s.type!=="placeholder")||this.store.set({isLoading:!0}),this.store.set({error:null});try{let s=await Ee(e,t,{maskCompletedText:this.getMaskCompletedText(),signal:i.signal,apiConfig:this.getApiConfig()});if(r!==this.fetchVersion)return;let l=Le(s.data.suggestions??[],this.getOptionOverrides()),p=s.data.input??[],c=p[p.length-1],m=this.store.get().text,f,g;if(c?.state==="in_progress"){g=!0;let C=m.toLowerCase().lastIndexOf(c.text.toLowerCase());f=C!==-1?C:a}else g=!1,f=a;let v=l.filter(C=>C.type!=="placeholder")[0],S=null;if(v){let C=Q(m,f,g),u=be(v.options,C);u&&(S={id:crypto.randomUUID(),placeholder:"",type:v.type,text:u.text,kind:u.kind,suggestionType:v.type,suggestionPlaceholder:v.text,options:v.options??[],metadata:u.metadata},l=l.filter(I=>I!==v))}this.store.set(C=>({suggestions:l,isLoading:!1,isReady:s.data.is_ready??!1,lastRawQuery:e,activeDropdownIndex:-1,filterBase:f,filterInProgress:g,...S?{completedParams:[...C.completedParams,S]}:{}}))}catch(s){if(r===this.fetchVersion){let l=s instanceof Error?s:new Error(String(s));this.store.set({error:l,isLoading:!1}),this.getOnError()?.(l)}}}scheduleFetch(){if(this.clearTimers(),this.store.get().skipNextFetch){this.store.set({skipNextFetch:!1});return}let t=i=>{let r=this.store.get();if(!r.text&&r.completedParams.length===0)return this.doFetch("",[]),!0;let n=Q(r.text,r.filterBase,r.filterInProgress),d=r.suggestions.filter(v=>v.type!=="placeholder")[0],l=(d?ee(d.options,n):[]).filter(v=>v.is_tappable),p=d?be(d.options,n)!==null:!1,c=n.trim().length>0;if(l.length>0&&!p&&c)return!1;let{rawQuery:m,completedParams:f}=L(r.text,r.completedParams),g=m.length<r.lastRawQuery.length,y=Math.abs(m.length-r.lastRawQuery.length);return g||y>=i?(this.doFetch(m,f),!0):!1};this.debounceTimer=setTimeout(()=>{t(nt)&&this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer)},ot),this.slowDebounceTimer=setTimeout(()=>t(1),it)}clearTimers(){this.debounceTimer&&clearTimeout(this.debounceTimer),this.slowDebounceTimer&&clearTimeout(this.slowDebounceTimer),this.debounceTimer=null,this.slowDebounceTimer=null}};var ie=class{constructor(e,t){this.store=e;this.ctx=t}handleKeyDown(e){let t=this.store.get(),{columns:i,listboxId:r,getOnSubmit:n}=this.ctx,a=n(),d=this.getTappableIndices();switch(e.key){case"ArrowDown":{let s=e.target;if(!(s.selectionStart!=null&&s.selectionStart===s.value.length)&&t.activeDropdownIndex<0)break;if(e.preventDefault(),!t.isDropdownOpen&&t.actionableSuggestions.length>0){this.store.set({pillTapped:!0,activeDropdownIndex:d[0]??0});break}if(d.length===0)return;let p=d.indexOf(t.activeDropdownIndex),c=p<d.length-1?p+1:0;this.store.set({activeDropdownIndex:d[c]});break}case"ArrowUp":{if(d.length===0||t.activeDropdownIndex<0)break;if(e.preventDefault(),t.activeDropdownIndex<i){this.store.set({activeDropdownIndex:-1});break}let s=d.indexOf(t.activeDropdownIndex),l=s>0?s-1:d.length-1;this.store.set({activeDropdownIndex:d[l]});break}case"ArrowRight":{if(t.activeDropdownIndex<0){let l=e.target;l.selectionStart!=null&&l.selectionStart===l.value.length&&t.actionableSuggestions.length>1&&(e.preventDefault(),this.pillsSetActivePill(1));break}if(t.activeDropdownIndex%i<i-1){let l=t.activeDropdownIndex+1;l<t.filteredOptions.length&&t.filteredOptions[l]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:l}))}break}case"ArrowLeft":{if(t.activeDropdownIndex<0)break;if(t.activeDropdownIndex%i>0){let s=t.activeDropdownIndex-1;s>=0&&t.filteredOptions[s]?.is_tappable&&(e.preventDefault(),this.store.set({activeDropdownIndex:s}))}break}case"Enter":{if(e.preventDefault(),t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,r);else if(a){let{rawQuery:s,completedParams:l}=L(t.text,t.completedParams);a({query:t.text.trim(),raw_query:s,completed_params:l})}break}case"Tab":{if(t.activeDropdownIndex>=0&&t.filteredOptions[t.activeDropdownIndex]?.is_tappable)e.preventDefault(),this.clickOrSelect(t.activeDropdownIndex,t.filteredOptions,r);else if(t.isDropdownOpen){let s=t.filteredOptions.findIndex(l=>l.is_tappable);s>=0&&(e.preventDefault(),this.clickOrSelect(s,t.filteredOptions,r))}else if(!t.text&&t.placeholderText){e.preventDefault();let s=t.suggestions.find(l=>l.type==="placeholder");s?this.store.set(l=>({text:t.placeholderText,filterBase:t.placeholderText.length,completedParams:[...l.completedParams,{id:crypto.randomUUID(),placeholder:"",type:s.type,text:t.placeholderText,kind:null,suggestionType:s.type,suggestionPlaceholder:s.text,options:s.options??[]}],suggestions:l.suggestions.filter(p=>p!==s)})):this.store.set({text:t.placeholderText,filterBase:t.placeholderText.length})}break}case"Escape":this.store.set({activeDropdownIndex:-1});break}}getTappableIndices(){let e=this.store.get(),{columns:t}=this.ctx,i=e.filteredOptions.map((n,a)=>n.is_tappable?a:-1).filter(n=>n!==-1),r=Array.from({length:t},()=>[]);for(let n of i)r[n%t].push(n);return r.flat()}clickOrSelect(e,t,i){let r=document.getElementById(`${i}-option-${e}`);r?r.click():this.ctx.selectOption(t[e])}pillsSetActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}};var ne=class{constructor(e){this.store=e}setActivePill(e){let t=this.store.get(),i=t.suggestions.filter(d=>d.type!=="placeholder");if(e<0||e>=i.length)return;let r=i[e],n=i.filter((d,s)=>s!==e),a=t.suggestions.filter(d=>d.type==="placeholder");this.store.set({suggestions:[...a,r,...n],pillTapped:!0,activeDropdownIndex:-1})}removeLastParam(){let e=this.store.get();if(e.completedParams.length===0)return;let t=e.completedParams[e.completedParams.length-1],i={type:t.suggestionType,text:t.suggestionPlaceholder,required:!0,options:t.options};this.store.set(r=>({completedParams:r.completedParams.slice(0,-1),suggestions:[i,...r.suggestions],activeDropdownIndex:-1}))}};function rt(o){return o===0?.4:o===1?.3:.15}function re(o,e,t,i,r=!1){let n=o.querySelector(".magicx-aia-pill-list");n||(n=document.createElement("span"),n.className="magicx-aia-pill-list",o.appendChild(n));let a=new Map;for(let s of n.querySelectorAll(".magicx-aia-pill"))a.set(s.dataset.pillKey??"",s);let d=new Set;for(let s=0;s<e.length;s++){let l=e[s],p=`${l.type}-${l.text}`;d.add(p);let c=a.get(p);c||(c=document.createElement("button"),c.type="button",c.dataset.pillKey=p,c.textContent=l.text),c.className=`magicx-aia-pill${r?" magicx-aia-pill--rounded":""}${s===t?" magicx-aia-pill--active":""}`,c.style.opacity=String(rt(s)),c.onclick=()=>i(s),n.children[s]!==c&&n.insertBefore(c,n.children[s]??null)}for(let[s,l]of a)d.has(s)||l.remove()}function se(o){let e=document.createElement("div");return e.id=o,e.setAttribute("role","listbox"),e.setAttribute("data-aia-dropdown",""),e.className="magicx-aia-dropdown",e.addEventListener("mousedown",t=>t.preventDefault()),e}function ae(o,e){let{filteredOptions:t,activeIndex:i,isOpen:r,pills:n,showPills:a,onSelect:d,onHighlight:s,onPillClick:l}=e,p=a&&n.length>0;r&&t.length>0||r&&p?o.classList.add("magicx-aia-dropdown--visible"):o.classList.remove("magicx-aia-dropdown--visible");let f=o.querySelector(".magicx-aia-pill-bar");p?(f||(f=document.createElement("div"),f.className="magicx-aia-pill-bar",o.insertBefore(f,o.firstChild)),re(f,n,0,l,!0)):f&&f.remove();let g=o.querySelector(".magicx-aia-grid");t.length>0?(g||(g=document.createElement("div"),g.className="magicx-aia-grid",o.appendChild(g)),st(g,t,i,d,s,e.listboxId)):g&&(g.innerHTML="")}function st(o,e,t,i,r,n){let a=e.map(l=>l.text).join("\0"),d=o.dataset.optionsKey??"",s=a!==d;if(o.dataset.optionsKey=a,s){let l=document.createDocumentFragment();for(let p=0;p<e.length;p++){let c=e[p],m=at(c,p,t,i,r,n);l.appendChild(m)}o.innerHTML="",o.appendChild(l)}else{let l=o.querySelectorAll(".magicx-aia-option");for(let p=0;p<l.length;p++){let c=l[p],m=p===t;c.setAttribute("aria-selected",String(m)),m?c.classList.add("magicx-aia-option--highlighted"):c.classList.remove("magicx-aia-option--highlighted")}}}function at(o,e,t,i,r,n){let a=document.createElement("div");a.id=`${n}-option-${e}`,a.setAttribute("role","option"),a.setAttribute("aria-selected",String(e===t)),a.tabIndex=o.is_tappable?0:-1;let d=["magicx-aia-option"];e===t&&d.push("magicx-aia-option--highlighted"),o.is_tappable?d.push("magicx-aia-option--tappable"):d.push("magicx-aia-option--non-tappable"),a.className=d.join(" ");let s=document.createElement("div");s.className="magicx-aia-streaks",a.appendChild(s);let l=document.createElement("div");l.className="magicx-aia-streaks-vert",a.appendChild(l);let p=document.createElement("span");if(p.className="magicx-aia-option-content",p.textContent=o.icon?`${o.icon} ${o.text}`:o.text,o.tag){let c=document.createElement("span");c.className="magicx-aia-option-tag",c.textContent=o.tag,p.appendChild(c)}return a.appendChild(p),o.is_tappable&&a.addEventListener("click",()=>{a.classList.add("magicx-aia-option--pressed"),i(o),setTimeout(()=>a.classList.remove("magicx-aia-option--pressed"),400)}),a.addEventListener("mouseenter",()=>r(e)),a}function Re(o,e){let t=se(e.listboxId);return o.appendChild(t),{dropdown:t}}function ve(o,e,t){ae(o.dropdown,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:!0,onSelect:t.selectOption,onHighlight:i=>t.store.set({activeDropdownIndex:i}),onPillClick:t.setActivePill})}function Me(o,e,t,i,r){let n=o.querySelector(".magicx-aia-sizer-text"),a=o.querySelector(".magicx-aia-placeholder");if(i&&r){n&&(n.style.display="none"),a||(a=document.createElement("span"),a.className="magicx-aia-placeholder",o.insertBefore(a,o.firstChild)),a.style.display="",a.textContent=`${r} `,o.dataset.segmentKey="";return}a&&(a.style.display="none"),n||(n=document.createElement("span"),n.className="magicx-aia-sizer-text",o.insertBefore(n,o.firstChild)),n.style.display="",n.className=`magicx-aia-sizer-text${t?" magicx-aia-sizer-text--visible":""}`;let d=e.map(p=>`${p.type}:${p.value}`).join("\0"),s=o.dataset.segmentKey??"",l=o.dataset.newParamId??"";if(!(d===s&&(t??"")===l)){o.dataset.segmentKey=d,o.dataset.newParamId=t??"",n.innerHTML="";for(let p of e){let c=document.createElement("span");p.type==="completed"&&(p.param.id===t?c.className="magicx-aia-shimmer-revealed magicx-aia-shimmer-sweep":c.className="magicx-aia-segment magicx-aia-segment--completed"),c.textContent=p.value,n.appendChild(c)}e.length===0&&(n.textContent="\xA0")}}var lt='<svg width="18" height="18" viewBox="0 0 18 18" fill="none" role="img" aria-label="Submit"><path d="M9 14V4M9 4L4 9M9 4L14 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function ze(o,e){let{listboxId:t}=e,i=se(t);o.appendChild(i);let r=document.createElement("div");r.className="magicx-aia-input-wrapper",o.appendChild(r);let n=document.createElement("div");n.className="magicx-aia-editor",r.appendChild(n);let a=document.createElement("div");a.className="magicx-aia-sizer",a.setAttribute("aria-hidden","true"),n.appendChild(a);let d=document.createElement("span");a.appendChild(document.createTextNode(" ")),a.appendChild(d);let s=document.createElement("textarea");s.className="magicx-aia-textarea",s.rows=1,s.setAttribute("role","combobox"),s.setAttribute("aria-autocomplete","list"),s.setAttribute("aria-controls",t),n.appendChild(s);let l=document.createElement("button");return l.type="button",l.className="magicx-aia-submit",l.setAttribute("aria-label","Submit"),l.innerHTML=lt,r.appendChild(l),r.addEventListener("click",()=>s.focus()),s.addEventListener("input",()=>{let p=s.value,m=p.length>0&&p[0]!==p[0].toUpperCase()?p[0].toUpperCase()+p.slice(1):p;e.handleChange(m)}),s.addEventListener("keydown",p=>e.handleKeyDown(p)),l.addEventListener("click",p=>{p.stopPropagation();let c=e.store.get();if(!(!!c.text||c.completedParams.length>0)||!e.onSubmit)return;let{rawQuery:f,completedParams:g}=L(c.text,c.completedParams);e.onSubmit({query:c.text.trim(),raw_query:f,completed_params:g})}),s.focus(),{textarea:s,dropdown:i,sizer:a,submitButton:l,inlinePillContainer:d}}function ye(o,e,t){let{textarea:i,dropdown:r,sizer:n,submitButton:a,inlinePillContainer:d}=o,{pillPlacement:s,setActivePill:l,selectOption:p,store:c}=t;i.value!==e.text&&(i.value=e.text),e.placeholderText?i.placeholder=e.placeholderText:i.removeAttribute("placeholder"),i.setAttribute("aria-expanded",String(e.isDropdownOpen));let m=e.activeDropdownIndex>=0?`${t.listboxId}-option-${e.activeDropdownIndex}`:"";m?i.setAttribute("aria-activedescendant",m):i.removeAttribute("aria-activedescendant"),e.newParamId?i.classList.add("magicx-aia-textarea--hidden"):i.classList.remove("magicx-aia-textarea--hidden");let f=!!e.text||e.completedParams.length>0;a.disabled=!f,Me(n,e.segments,e.newParamId,!e.text,e.placeholderText),s==="inline"?re(d,e.actionableSuggestions,0,l):d.innerHTML="",ae(r,{suggestions:e.actionableSuggestions.length>0?[{...e.actionableSuggestions[0],options:e.filteredOptions}]:[],filteredOptions:e.filteredOptions,activeIndex:e.activeDropdownIndex,isOpen:e.isDropdownOpen,listboxId:t.listboxId,pills:e.actionableSuggestions,showPills:s==="dropdown",onSelect:p,onHighlight:g=>c.set({activeDropdownIndex:g}),onPillClick:l})}function He(o){let e=o,t=new Set;return{get:()=>e,set:i=>{let r=typeof i=="function"?i(e):i,n={...e,...r},a=e;e=n;for(let d of t)d(n,a)},subscribe:i=>(t.add(i),()=>{t.delete(i)})}}var we=!1;function Be(){if(we||typeof document>"u")return;if(document.querySelector("style[data-magicx-aia]")){we=!0;return}we=!0;let o=document.createElement("style");o.setAttribute("data-magicx-aia",""),o.textContent=dt,document.head.appendChild(o)}var dt=__MAGICX_AC_STYLES__;var pt=0;function ct(){return`:ac-${++pt}:`}function Ne(){return{text:"",completedParams:[],suggestions:[],activeDropdownIndex:-1,newParamId:null,isLoading:!1,isReady:!1,error:null,segments:[],actionableSuggestions:[],filteredOptions:[],placeholderText:"",isDropdownOpen:!1,filterBase:0,filterInProgress:!1,pillTapped:!1,skipNextFetch:!1,lastRawQuery:""}}var le=class{constructor(e,t={}){this.store=He(Ne());this._listboxId=ct();this.modeController=null;this.unsubscribers=[];this.derivedInProgress=!1;this.domRefs=null;this.dropdownRefs=null;this.externalListeners=new Set;this.container=e,this.opts=t,this.renderMode=t.renderMode??"full",t.value!==void 0&&this.store.set({text:t.value}),t.completedParams!==void 0&&this.store.set({completedParams:t.completedParams}),this.pillsController=new ne(this.store),this.fetchController=new oe(this.store,()=>this.opts.apiConfig,()=>this.opts.optionOverrides,()=>this.opts.maskCompletedText,()=>this.opts.onError),this.keyboardController=new ie(this.store,{columns:t.columns??2,listboxId:this.listboxId,getOnSubmit:()=>this.opts.onSubmit,selectOption:i=>this.selectOption(i)}),this.unsubscribers.push(this.store.subscribe((i,r)=>{this.recomputeDerived(i,r)})),this.unsubscribers.push(this.store.subscribe((i,r)=>{i.text!==r.text&&this.opts.onChange?.(i.text),i.completedParams!==r.completedParams&&this.opts.onParamsChange?.(i.completedParams),this.opts.onStateChange?.(i)})),this.renderMode!=="headless"&&(Be(),this.setupContainer()),this.renderMode==="full"?this.buildAndRenderFull():this.renderMode==="dropdown"&&this.buildAndRenderDropdown(),this.fetchController.start()}focus(){this.domRefs?.textarea.focus()}reset(){this.store.set({...Ne()}),this.fetchController.doFetch("",[])}destroy(){this.fetchController.dispose(),this.modeController?.destroy(),this.newParamTimer&&clearTimeout(this.newParamTimer),this.suggestionRemovalTimer&&clearTimeout(this.suggestionRemovalTimer),this.externalListeners.clear();for(let e of this.unsubscribers)e();this.unsubscribers=[],this.domRefs=null,this.dropdownRefs=null,this.renderMode!=="headless"&&(this.container.innerHTML="")}setMode(e){this.modeController?.setMode(e)}setValue(e){this.store.set({text:e})}setCompletedParams(e){this.store.set({completedParams:e})}setActivePill(e){this.pillsController.setActivePill(e)}removeLastParam(){this.pillsController.removeLastParam()}clearNewParamId(){this.store.set({newParamId:null})}setActiveDropdownIndex(e){this.store.set({activeDropdownIndex:e})}handleTextChange(e){this.handleChange(e)}handleKeyDown(e){this.keyboardController.handleKeyDown(e)}subscribe(e){return this.externalListeners.add(e),()=>{this.externalListeners.delete(e)}}getState(){return this.store.get()}get listboxId(){return this._listboxId}get isReady(){return this.store.get().isReady}on(e,t){switch(e){case"submit":return this.opts.onSubmit=t,()=>{this.opts.onSubmit=void 0};case"error":return this.opts.onError=t,()=>{this.opts.onError=void 0};case"change":return this.opts.onChange=t,()=>{this.opts.onChange=void 0};case"paramsChange":return this.opts.onParamsChange=t,()=>{this.opts.onParamsChange=void 0};case"stateChange":return this.opts.onStateChange=t,()=>{this.opts.onStateChange=void 0};default:return()=>{}}}update(e){Object.assign(this.opts,e),e.mode!==void 0&&this.modeController?.setMode(e.mode),e.optionsPosition!==void 0&&(this.container.dataset.optionsPosition=e.optionsPosition),e.animations!==void 0&&(this.container.dataset.animations=e.animations?"on":"off"),e.pillPlacement!==void 0&&(this.container.dataset.pillPlacement=e.pillPlacement,this.store.set({})),e.dropdownTrigger!==void 0&&this.store.set({}),e.value!==void 0&&this.store.set({text:e.value}),e.completedParams!==void 0&&this.store.set({completedParams:e.completedParams})}selectOption(e){let t=this.store.get(),i=t.actionableSuggestions[0];if(!i)return;let r=t.filterBase,n=t.text.slice(0,r),a=n.length===0&&t.text.length===0;a&&t.placeholderText&&(n=`${t.placeholderText} `);let d=Pe(n,e.text);d>0&&(n=n.slice(0,n.length-d));let s=n.length>0&&n[n.length-1]!==" ",l=`${n}${s?" ":""}${e.text} `,p=a&&l.length>0?l[0].toUpperCase()+l.slice(1):l,c=p.toLowerCase().lastIndexOf(e.text.toLowerCase()),m=c>=0?p.slice(c,c+e.text.length):e.text,f={id:crypto.randomUUID(),placeholder:"",type:i.type,text:m,kind:e.kind,suggestionType:i.type,suggestionPlaceholder:i.text,options:i.options??[],metadata:e.metadata},g=t.actionableSuggestions.length-1;this.store.set(y=>({text:p,filterBase:p.length,completedParams:[...y.completedParams,f],newParamId:f.id,pillTapped:!1,activeDropdownIndex:-1,skipNextFetch:g>0})),this.suggestionRemovalTimer=window.setTimeout(()=>{this.store.set(y=>({suggestions:y.suggestions.filter(v=>v!==i)}))},400)}recomputeDerived(e,t){if(this.derivedInProgress)return;this.derivedInProgress=!0;let i=Ce(e.text,e.completedParams),r=e.suggestions.filter(S=>S.type!=="placeholder"),n=r[0],a=n?this.opts.optionOverrides?.[n.type]:void 0,d=Math.min(e.filterBase,e.text.length),l=e.lastRawQuery!==""||d>0?Q(e.text,d,e.filterInProgress):"",p=n?a?a(l.trim()):n.options??[]:[],c=ee(p,l),m=e.suggestions.filter(S=>S.type==="placeholder").map(S=>S.text).join(" ")||this.opts.placeholder||"",f=m.length>0,g=this.opts.dropdownTrigger??"auto",y=!1;g==="auto"?y=!e.isLoading&&c.length>0&&(!!e.text||e.pillTapped||!f):g==="manual"&&(y=!e.isLoading&&c.length>0&&e.pillTapped),this.store.set({segments:i,actionableSuggestions:r,filteredOptions:c,placeholderText:m,isDropdownOpen:y}),this.derivedInProgress=!1;let v=this.store.get();for(let S of this.externalListeners)S(v)}setupContainer(){this.container.classList.add("magicx-aia"),this.container.dataset.pillPlacement=this.renderMode==="dropdown"?"dropdown":this.opts.pillPlacement??"inline",this.container.dataset.optionsPosition=this.opts.optionsPosition??"below",this.container.dataset.animations=this.opts.animations??!0?"on":"off",this.modeController=new K(this.container,this.opts.mode??"auto")}buildAndRenderFull(){let e=this,t={store:this.store,listboxId:this.listboxId,get pillPlacement(){return e.opts.pillPlacement??"inline"},get onSubmit(){return e.opts.onSubmit},selectOption:i=>this.selectOption(i),setActivePill:i=>this.pillsController.setActivePill(i),handleKeyDown:i=>this.keyboardController.handleKeyDown(i),handleChange:i=>this.handleChange(i)};this.domRefs=ze(this.container,t),this.subscribeBatchedRender(()=>{this.domRefs&&ye(this.domRefs,this.store.get(),t)}),ye(this.domRefs,this.store.get(),t),this.subscribeNewParamTimer()}buildAndRenderDropdown(){let e={store:this.store,listboxId:this.listboxId,selectOption:t=>this.selectOption(t),setActivePill:t=>this.pillsController.setActivePill(t)};this.dropdownRefs=Re(this.container,e),this.subscribeBatchedRender(()=>{this.dropdownRefs&&ve(this.dropdownRefs,this.store.get(),e)}),ve(this.dropdownRefs,this.store.get(),e),this.subscribeNewParamTimer()}subscribeBatchedRender(e){let t=!1;this.unsubscribers.push(this.store.subscribe(()=>{t||(t=!0,queueMicrotask(()=>{t=!1,e()}))}))}subscribeNewParamTimer(){this.unsubscribers.push(this.store.subscribe((e,t)=>{e.newParamId&&e.newParamId!==t.newParamId&&(this.newParamTimer&&clearTimeout(this.newParamTimer),this.newParamTimer=window.setTimeout(()=>{this.store.set({newParamId:null})},650))}))}handleChange(e){let t=this.store.get();this.store.set({text:e,pillTapped:!1,activeDropdownIndex:-1});let{valid:i,invalid:r}=Ae(e,t.completedParams);r.length>0&&this.store.set(n=>({completedParams:i,suggestions:[...r.map(a=>({type:a.suggestionType,text:a.suggestionPlaceholder,required:!0,options:a.options})),...n.suggestions]}))}};function de({onSubmit:o,onError:e,optionOverrides:t,maskCompletedText:i,placeholder:r,apiConfig:n,columns:a=2,dropdownTrigger:d,value:s,completedParams:l,onChange:p,onParamsChange:c}){let m=(0,x.useRef)(null),[f,g]=(0,x.useState)(null),y=(0,x.useRef)(o);y.current=o;let v=(0,x.useRef)(e);v.current=e;let S=(0,x.useRef)(p);S.current=p;let C=(0,x.useRef)(c);C.current=c,!m.current&&typeof document<"u"&&(m.current=new le(document.createElement("div"),{renderMode:"headless",apiConfig:n,optionOverrides:t,maskCompletedText:i,placeholder:r,columns:a,dropdownTrigger:d,value:s,completedParams:l,onSubmit:(...h)=>y.current?.(...h),onError:(...h)=>v.current?.(...h),onChange:(...h)=>S.current?.(...h),onParamsChange:(...h)=>C.current?.(...h)}));let u=m.current,I=(0,x.useCallback)(()=>{},[]);(0,x.useEffect)(()=>{if(!u)return;g(u.getState());let h=u.subscribe(A=>{g(A)});return()=>{h(),u.destroy(),m.current=null}},[u]),(0,x.useEffect)(()=>{s!==void 0&&u?.setValue(s)},[s,u]),(0,x.useEffect)(()=>{l!==void 0&&u?.setCompletedParams(l)},[l,u]);let j=JSON.stringify(n??null),T=(0,x.useRef)(t),z=(0,x.useRef)(0);if(t!==T.current){let h=T.current,A=t,b=Object.keys(h??{}),D=Object.keys(A??{});(b.length!==D.length||D.some(X=>!h?.[X]||A[X]!==h[X]))&&z.current++,T.current=t}(0,x.useEffect)(()=>{u?.update({apiConfig:n,optionOverrides:t,dropdownTrigger:d})},[j,z.current,d,u]);let pe=(0,x.useCallback)(h=>{if(!u)return;let A=h.target.value,D=A.length>0&&!h.nativeEvent?.isComposing&&A[0]!==A[0].toUpperCase()?A[0].toUpperCase()+A.slice(1):A;u.handleTextChange(D)},[u]),ce=(0,x.useCallback)(h=>{u?.handleKeyDown(h.nativeEvent)},[u]),$=(0,x.useCallback)(h=>u?.setActivePill(h),[u]),R=(0,x.useCallback)(()=>u?.removeLastParam(),[u]),G=(0,x.useCallback)(()=>u?.clearNewParamId(),[u]),E=(0,x.useCallback)(()=>u?.reset(),[u]),ue=(0,x.useCallback)(h=>u?.selectOption(h),[u]),H=(0,x.useCallback)(h=>u?.setActiveDropdownIndex(h),[u]);if(!u)return{completedParams:l??[],suggestionPills:[],setActivePill:I,removeLastParam:I,segments:[],newParamId:null,clearNewParamId:I,suggestions:[],activeIndex:-1,isReady:!1,isLoading:!0,error:null,inputProps:{value:s??"",placeholder:r,onChange:I,onKeyDown:I,role:"combobox","aria-expanded":!1,"aria-activedescendant":void 0,"aria-autocomplete":"list","aria-controls":""},reset:I,dropdownProps:{suggestions:[],activeIndex:-1,onSelect:I,onHighlight:I,isOpen:!1,id:"",pills:[],onPillClick:I}};let w=f??u.getState(),F=s!==void 0?s:w.text,W=l!==void 0?l:w.completedParams,V=w.actionableSuggestions,q=V[0],me=w.filteredOptions,ge=w.activeDropdownIndex>=0?`${u.listboxId}-option-${w.activeDropdownIndex}`:void 0;return{completedParams:W,suggestionPills:V,setActivePill:$,removeLastParam:R,segments:w.segments,newParamId:w.newParamId,clearNewParamId:G,suggestions:w.suggestions,activeIndex:w.activeDropdownIndex,isReady:w.isReady,isLoading:w.isLoading,error:w.error,inputProps:{value:F,placeholder:w.placeholderText||void 0,onChange:pe,onKeyDown:ce,role:"combobox","aria-expanded":w.isDropdownOpen,"aria-activedescendant":ge,"aria-autocomplete":"list","aria-controls":u.listboxId},reset:E,dropdownProps:{suggestions:q?[{...q,options:me}]:[],activeIndex:w.activeDropdownIndex,onSelect:ue,onHighlight:H,isOpen:w.isDropdownOpen,id:u.listboxId,pills:V,onPillClick:$}}}var _=require("react/jsx-runtime");function ut(o){return o!=="auto"?o:typeof window>"u"||window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}var Ke=(0,P.forwardRef)(function({onSubmit:e,onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,className:a,apiConfig:d,columns:s,pillPlacement:l="inline",mode:p="auto",optionsPosition:c="below",animations:m=!0,dropdownTrigger:f,value:g,completedParams:y,onChange:v,onParamsChange:S},C){let u=(0,P.useRef)(null),I=(0,P.useRef)(null),j=(0,P.useRef)(()=>{}),T=(0,P.useRef)(null);(0,P.useEffect)(()=>{I.current?.focus()},[]),(0,P.useEffect)(()=>{let b=u.current;if(b)return T.current?T.current.setMode(p):T.current=new K(b,p),()=>{T.current?.destroy(),T.current=null}},[p]);let{completedParams:z,suggestionPills:pe,setActivePill:ce,segments:$,newParamId:R,clearNewParamId:G,inputProps:E,dropdownProps:ue,reset:H}=de({onSubmit:b=>j.current(b),onError:t,optionOverrides:i,maskCompletedText:r,placeholder:n,apiConfig:d,columns:s,dropdownTrigger:f,value:g,completedParams:y,onChange:v,onParamsChange:S});(0,P.useEffect)(()=>{if(!R)return;let b=window.setTimeout(()=>G(),650);return()=>window.clearTimeout(b)},[R,G]),(0,P.useImperativeHandle)(C,()=>({focus:()=>I.current?.focus(),reset:H,setMode:b=>T.current?.setMode(b)}),[H]);let w=()=>{I.current?.focus()},F=!!E.value||z.length>0,W=(0,P.useCallback)(()=>{if(!F)return;let{rawQuery:b,completedParams:D}=L(E.value,z);e({query:E.value.trim(),raw_query:b,completed_params:D}),H()},[F,E.value,z,e,H]);j.current=W;let{onChange:V,placeholder:q,...me}=E,ge=!E.value,h=l==="inline",A=l==="dropdown";return(0,_.jsxs)("div",{ref:u,className:`magicx-aia ${k.container} ${a??""}`,"data-pill-placement":l,"data-options-position":c,"data-animations":m?"on":"off","data-mode":ut(p),children:[(0,_.jsx)(Z,{...ue,showPills:A}),(0,_.jsxs)("div",{className:k.inputWrapper,onClick:w,children:[(0,_.jsxs)("div",{className:k.editorArea,children:[(0,_.jsxs)("div",{className:k.sizerContent,"aria-hidden":"true",children:[ge&&q?(0,_.jsxs)("span",{className:k.placeholderText,children:[q," "]}):(0,_.jsxs)("span",{className:`${k.sizerText} ${R?k.sizerTextVisible:""}`,children:[$.map((b,D)=>{if(b.type==="completed"&&b.param.id===R){let $e=`${k.shimmerRevealed} ${k.shimmerSweep}`;return(0,_.jsx)("span",{className:$e,children:b.value},`${D}-${b.type}`)}return(0,_.jsx)("span",{children:b.value},`${D}-${b.type}`)}),$.length===0&&"\xA0"]})," ",h&&(0,_.jsx)(Y,{pills:pe,activePillIndex:0,onSelectPill:ce})]}),(0,_.jsx)("textarea",{ref:I,className:`${k.textarea} ${R?k.textareaHidden:""}`,rows:1,onChange:V,...me})]}),(0,_.jsx)("button",{type:"button",className:k.submitButton,disabled:!F,onClick:b=>{b.stopPropagation(),W()},"aria-label":"Submit",children:(0,_.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",role:"img","aria-label":"Submit",children:(0,_.jsx)("path",{d:"M9 14V4M9 4L4 9M9 4L14 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})});0&&(module.exports={AIAutocomplete,AIAutocompleteDropdown,useAIAutocomplete});
|
|
533
548
|
//# sourceMappingURL=index.js.map
|