sillytavern-utils-lib 1.0.61 → 1.0.63
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/dist/character-utils.cjs +1 -0
- package/dist/character-utils.d.ts +1 -0
- package/dist/character-utils.js +48 -68
- package/dist/components/react/ConnectionProfileSelect.cjs +1 -0
- package/dist/components/{ConnectionProfileSelect.d.ts → react/ConnectionProfileSelect.d.ts} +2 -3
- package/dist/components/react/ConnectionProfileSelect.d.ts.map +1 -0
- package/dist/components/react/ConnectionProfileSelect.js +64 -0
- package/dist/components/react/Popup.cjs +1 -0
- package/dist/components/{Popup.d.ts → react/Popup.d.ts} +3 -2
- package/dist/components/react/Popup.d.ts.map +1 -0
- package/dist/components/react/Popup.js +180 -0
- package/dist/components/react/STButton.cjs +1 -0
- package/dist/components/{STButton.d.ts → react/STButton.d.ts} +1 -0
- package/dist/components/react/STButton.d.ts.map +1 -0
- package/dist/components/react/STButton.js +12 -0
- package/dist/components/react/STFancyDropdown.cjs +1 -0
- package/dist/components/{STFancyDropdown.d.ts → react/STFancyDropdown.d.ts} +1 -0
- package/dist/components/react/STFancyDropdown.d.ts.map +1 -0
- package/dist/components/react/STFancyDropdown.js +176 -0
- package/dist/components/react/STInput.cjs +1 -0
- package/dist/components/{STInput.d.ts → react/STInput.d.ts} +2 -1
- package/dist/components/react/STInput.d.ts.map +1 -0
- package/dist/components/react/STInput.js +19 -0
- package/dist/components/react/STPresetSelect.cjs +1 -0
- package/dist/components/{STPresetSelect.d.ts → react/STPresetSelect.d.ts} +1 -0
- package/dist/components/react/STPresetSelect.d.ts.map +1 -0
- package/dist/components/react/STPresetSelect.js +142 -0
- package/dist/components/react/STSelect.cjs +1 -0
- package/dist/components/{STSelect.d.ts → react/STSelect.d.ts} +1 -0
- package/dist/components/react/STSelect.d.ts.map +1 -0
- package/dist/components/react/STSelect.js +12 -0
- package/dist/components/react/STSortableList.cjs +1 -0
- package/dist/components/{STSortableList.d.ts → react/STSortableList.d.ts} +4 -3
- package/dist/components/react/STSortableList.d.ts.map +1 -0
- package/dist/components/react/STSortableList.js +148 -0
- package/dist/components/react/STTextarea.cjs +1 -0
- package/dist/components/{STTextarea.d.ts → react/STTextarea.d.ts} +1 -0
- package/dist/components/react/STTextarea.d.ts.map +1 -0
- package/dist/components/react/STTextarea.js +12 -0
- package/dist/components/react/index.cjs +1 -0
- package/dist/components/{index.d.ts → react/index.d.ts} +3 -2
- package/dist/components/react/index.d.ts.map +1 -0
- package/dist/components/react/index.js +22 -0
- package/dist/components/vue/STConnectionProfileSelect.vue.cjs +1 -0
- package/dist/components/vue/STConnectionProfileSelect.vue.d.ts +80 -0
- package/dist/components/vue/STConnectionProfileSelect.vue.d.ts.map +1 -0
- package/dist/components/vue/STConnectionProfileSelect.vue.js +83 -0
- package/dist/components/vue/STConnectionProfileSelect.vue2.cjs +1 -0
- package/dist/components/vue/STConnectionProfileSelect.vue2.js +4 -0
- package/dist/components/vue/index.cjs +1 -0
- package/dist/components/vue/index.d.ts +4 -0
- package/dist/components/vue/index.d.ts.map +1 -0
- package/dist/components/vue/index.js +4 -0
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.js +238 -177
- package/dist/extension-settings-manager.cjs +1 -0
- package/dist/extension-settings-manager.js +118 -182
- package/dist/fancy-dropdown.cjs +1 -0
- package/dist/fancy-dropdown.js +244 -524
- package/dist/generate.cjs +1 -0
- package/dist/generate.d.ts +1 -0
- package/dist/generate.js +78 -93
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +21 -10
- package/dist/preset-select.cjs +1 -0
- package/dist/preset-select.d.ts +1 -0
- package/dist/preset-select.js +124 -235
- package/dist/profile-utils.cjs +1 -0
- package/dist/profile-utils.d.ts +9 -0
- package/dist/profile-utils.d.ts.map +1 -0
- package/dist/profile-utils.js +17 -0
- package/dist/prompt-builder.cjs +6 -0
- package/dist/prompt-builder.d.ts +1 -0
- package/dist/prompt-builder.js +370 -516
- package/dist/sortable-list.cjs +1 -0
- package/dist/sortable-list.d.ts +2 -1
- package/dist/sortable-list.js +229 -405
- package/dist/tokenizer.cjs +1 -0
- package/dist/tokenizer.js +19 -18
- package/dist/types/chat-completion.cjs +1 -0
- package/dist/types/chat-completion.js +1 -2
- package/dist/types/context.cjs +1 -0
- package/dist/types/context.js +1 -2
- package/dist/types/index.cjs +1 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -74
- package/dist/types/instruct.cjs +1 -0
- package/dist/types/instruct.js +1 -2
- package/dist/types/popup.cjs +1 -0
- package/dist/types/popup.js +5 -15
- package/dist/types/profiles.cjs +1 -0
- package/dist/types/profiles.js +1 -2
- package/dist/types/regex.cjs +1 -0
- package/dist/types/regex.js +1 -2
- package/dist/types/sysprompt.cjs +1 -0
- package/dist/types/sysprompt.js +1 -2
- package/dist/types/text-completion.cjs +1 -0
- package/dist/types/text-completion.js +1 -2
- package/dist/types/translate.cjs +1 -0
- package/dist/types/translate.js +4 -8
- package/dist/types/world-info.cjs +1 -0
- package/dist/types/world-info.js +1 -2
- package/dist/vue-shim.d.ts +5 -0
- package/dist/world-info-utils.cjs +1 -0
- package/dist/world-info-utils.d.ts +1 -0
- package/dist/world-info-utils.js +87 -136
- package/package.json +59 -23
- package/dist/character-utils.js.map +0 -1
- package/dist/chat-utils.d.ts +0 -6
- package/dist/chat-utils.d.ts.map +0 -1
- package/dist/chat-utils.js +0 -14
- package/dist/chat-utils.js.map +0 -1
- package/dist/components/ConnectionProfileSelect.d.ts.map +0 -1
- package/dist/components/ConnectionProfileSelect.js +0 -126
- package/dist/components/ConnectionProfileSelect.js.map +0 -1
- package/dist/components/MyFancyButton.d.ts +0 -6
- package/dist/components/MyFancyButton.d.ts.map +0 -1
- package/dist/components/MyFancyButton.js +0 -22
- package/dist/components/MyFancyButton.js.map +0 -1
- package/dist/components/Popup.d.ts.map +0 -1
- package/dist/components/Popup.js +0 -179
- package/dist/components/Popup.js.map +0 -1
- package/dist/components/STButton.d.ts.map +0 -1
- package/dist/components/STButton.js +0 -20
- package/dist/components/STButton.js.map +0 -1
- package/dist/components/STFancyDropdown.d.ts.map +0 -1
- package/dist/components/STFancyDropdown.js +0 -135
- package/dist/components/STFancyDropdown.js.map +0 -1
- package/dist/components/STInput.d.ts.map +0 -1
- package/dist/components/STInput.js +0 -26
- package/dist/components/STInput.js.map +0 -1
- package/dist/components/STPresetSelect.d.ts.map +0 -1
- package/dist/components/STPresetSelect.js +0 -104
- package/dist/components/STPresetSelect.js.map +0 -1
- package/dist/components/STSelect.d.ts.map +0 -1
- package/dist/components/STSelect.js +0 -18
- package/dist/components/STSelect.js.map +0 -1
- package/dist/components/STSortableList.d.ts.map +0 -1
- package/dist/components/STSortableList.js +0 -90
- package/dist/components/STSortableList.js.map +0 -1
- package/dist/components/STTextarea.d.ts.map +0 -1
- package/dist/components/STTextarea.js +0 -18
- package/dist/components/STTextarea.js.map +0 -1
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -11
- package/dist/components/index.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/extension-settings-manager.js.map +0 -1
- package/dist/fancy-dropdown.js.map +0 -1
- package/dist/generate.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/macro-utils.d.ts +0 -2
- package/dist/macro-utils.d.ts.map +0 -1
- package/dist/macro-utils.js +0 -2
- package/dist/macro-utils.js.map +0 -1
- package/dist/preset-select.js.map +0 -1
- package/dist/prompt-builder.js.map +0 -1
- package/dist/sortable-list.js.map +0 -1
- package/dist/tokenizer.js.map +0 -1
- package/dist/types/chat-completion.js.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/instruct.js.map +0 -1
- package/dist/types/popup.js.map +0 -1
- package/dist/types/profiles.js.map +0 -1
- package/dist/types/regex.js.map +0 -1
- package/dist/types/sysprompt.js.map +0 -1
- package/dist/types/text-completion.js.map +0 -1
- package/dist/types/translate.js.map +0 -1
- package/dist/types/world-info.js.map +0 -1
- package/dist/world-info-utils.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var h=Object.defineProperty;var u=(e,t,a)=>t in e?h(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a;var n=(e,t,a)=>u(e,typeof t!="symbol"?t+"":t,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class c extends Error{constructor(a,s){super(a);n(this,"data");this.data=s}toString(){return this.message}}async function f(e,t){const a=SillyTavern.getContext(),s=new FormData;s.append("avatar",new Blob([JSON.stringify(e)],{type:"application/json"}),"character.json"),s.append("file_type","json");const r=a.getRequestHeaders();delete r["Content-Type"];const o=await fetch("/api/characters/import",{method:"POST",headers:r,body:s,cache:"no-cache"});if(!o.ok)throw new c(o.statusText,o);t&&await a.getCharacters()}async function l(e,t){var o;const a=SillyTavern.getContext();if(!e.avatar)throw new Error("`data.avatar` (character filename) is required to save character attributes.");e==null||delete e.json_data,(o=e==null?void 0:e.data)==null||delete o.json_data;const s=a.getRequestHeaders(),r=await fetch("/api/characters/merge-attributes",{method:"POST",headers:s,body:JSON.stringify(e),cache:"no-cache"});if(!r.ok){const i=await r.json().catch(()=>({message:r.statusText}));throw new c(i.message||`Request failed with status ${r.status}`,r)}t&&await a.getCharacters()}exports.CustomError=c;exports.createCharacter=f;exports.saveCharacter=l;
|
package/dist/character-utils.js
CHANGED
|
@@ -1,71 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var h = Object.defineProperty;
|
|
2
|
+
var p = (e, t, a) => t in e ? h(e, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[t] = a;
|
|
3
|
+
var n = (e, t, a) => p(e, typeof t != "symbol" ? t + "" : t, a);
|
|
4
|
+
class c extends Error {
|
|
5
|
+
constructor(a, s) {
|
|
6
|
+
super(a);
|
|
7
|
+
n(this, "data");
|
|
8
|
+
this.data = s;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
return this.message;
|
|
12
|
+
}
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
body: formData,
|
|
26
|
-
cache: 'no-cache',
|
|
27
|
-
});
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
throw new CustomError(response.statusText, response);
|
|
30
|
-
}
|
|
31
|
-
if (updateUI) {
|
|
32
|
-
await context.getCharacters();
|
|
33
|
-
}
|
|
14
|
+
async function f(e, t) {
|
|
15
|
+
const a = SillyTavern.getContext(), s = new FormData();
|
|
16
|
+
s.append("avatar", new Blob([JSON.stringify(e)], { type: "application/json" }), "character.json"), s.append("file_type", "json");
|
|
17
|
+
const r = a.getRequestHeaders();
|
|
18
|
+
delete r["Content-Type"];
|
|
19
|
+
const o = await fetch("/api/characters/import", {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: r,
|
|
22
|
+
body: s,
|
|
23
|
+
cache: "no-cache"
|
|
24
|
+
});
|
|
25
|
+
if (!o.ok)
|
|
26
|
+
throw new c(o.statusText, o);
|
|
27
|
+
t && await a.getCharacters();
|
|
34
28
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
delete data?.json_data;
|
|
54
|
-
delete data?.data?.json_data;
|
|
55
|
-
const headers = context.getRequestHeaders();
|
|
56
|
-
const response = await fetch('/api/characters/merge-attributes', {
|
|
57
|
-
method: 'POST',
|
|
58
|
-
headers,
|
|
59
|
-
body: JSON.stringify(data),
|
|
60
|
-
cache: 'no-cache',
|
|
61
|
-
});
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
// Attempt to parse a JSON error response from the server for a better error message.
|
|
64
|
-
const errorData = await response.json().catch(() => ({ message: response.statusText }));
|
|
65
|
-
throw new CustomError(errorData.message || `Request failed with status ${response.status}`, response);
|
|
66
|
-
}
|
|
67
|
-
if (updateUI) {
|
|
68
|
-
await context.getCharacters();
|
|
69
|
-
}
|
|
29
|
+
async function w(e, t) {
|
|
30
|
+
var o;
|
|
31
|
+
const a = SillyTavern.getContext();
|
|
32
|
+
if (!e.avatar)
|
|
33
|
+
throw new Error("`data.avatar` (character filename) is required to save character attributes.");
|
|
34
|
+
e == null || delete e.json_data, (o = e == null ? void 0 : e.data) == null || delete o.json_data;
|
|
35
|
+
const s = a.getRequestHeaders(), r = await fetch("/api/characters/merge-attributes", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: s,
|
|
38
|
+
body: JSON.stringify(e),
|
|
39
|
+
cache: "no-cache"
|
|
40
|
+
});
|
|
41
|
+
if (!r.ok) {
|
|
42
|
+
const i = await r.json().catch(() => ({ message: r.statusText }));
|
|
43
|
+
throw new c(i.message || `Request failed with status ${r.status}`, r);
|
|
44
|
+
}
|
|
45
|
+
t && await a.getCharacters();
|
|
70
46
|
}
|
|
71
|
-
|
|
47
|
+
export {
|
|
48
|
+
c as CustomError,
|
|
49
|
+
f as createCharacter,
|
|
50
|
+
w as saveCharacter
|
|
51
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),u=require("react"),m=require("./STSelect.cjs"),d=require("../../profile-utils.cjs"),o=SillyTavern.getContext(),C=({initialSelectedProfileId:I,allowedTypes:r={openai:"Chat Completion",textgenerationwebui:"Text Completion"},placeholder:x="Select a Connection Profile",onChange:s,onCreate:p,onUpdate:f,onDelete:S})=>{const[E,N]=u.useState(I??""),[T,v]=u.useState(Date.now()),{isEnabled:a,profiles:O,connectApiMap:c}=u.useMemo(()=>{var t,i;return((t=o.extensionSettings.disabledExtensions)==null?void 0:t.includes("connection-manager"))?(console.error("Connection Manager extension is disabled."),{isEnabled:!1,profiles:[],connectApiMap:{}}):{isEnabled:!0,profiles:((i=o.extensionSettings.connectionManager)==null?void 0:i.profiles)??[],connectApiMap:o.CONNECT_API_MAP}},[T]);u.useEffect(()=>{if(!a)return;const n=e=>{d.isProfileSupported(e,r,c)&&(v(Date.now()),p==null||p(e))},t=(e,b)=>{const M=d.isProfileSupported(e,r,c),P=d.isProfileSupported(b,r,c);(M||P)&&v(Date.now()),f==null||f(e,b),E===e.id&&!P&&(N(""),s==null||s(void 0))},i=e=>{d.isProfileSupported(e,r,c)&&(v(Date.now()),S==null||S(e),E===e.id&&(N(""),s==null||s(void 0)))};return o.eventSource.on("CONNECTION_PROFILE_CREATED",n),o.eventSource.on("CONNECTION_PROFILE_UPDATED",t),o.eventSource.on("CONNECTION_PROFILE_DELETED",i),()=>{o.eventSource.removeListener("CONNECTION_PROFILE_CREATED",n),o.eventSource.removeListener("CONNECTION_PROFILE_UPDATED",t),o.eventSource.removeListener("CONNECTION_PROFILE_DELETED",i)}},[a,E,r,c,s,p,f,S]);const _=u.useMemo(()=>{if(!a)return[];const n=O.filter(i=>d.isProfileSupported(i,r,c)),t={};for(const[i,e]of Object.entries(r))t[i]={label:e,profiles:[]};for(const i of n){const e=c[i.api];t[e.selected]&&t[e.selected].profiles.push(i)}for(const i of Object.values(t))i.profiles.sort((e,b)=>(e.name??"").localeCompare(b.name??""));return Object.values(t).filter(i=>i.profiles.length>0)},[a,O,r,c]),L=u.useCallback(n=>{const t=n.target.value;N(t);const i=O.find(e=>e.id===t);s==null||s(i)},[O,s]);return a?l.jsxs(m.STSelect,{value:E,onChange:L,children:[l.jsx("option",{value:"",children:x}),_.map(n=>l.jsx("optgroup",{label:n.label,children:n.profiles.map(t=>l.jsx("option",{value:t.id,children:t.name},t.id))},n.label))]}):l.jsx(m.STSelect,{disabled:!0,value:"",children:l.jsx("option",{children:"Connection Manager disabled"})})};exports.STConnectionProfileSelect=C;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare const isProfileSupported: (profile: ConnectionProfile | undefined, allowedTypes: Record<string, string>, connectApiMap: ConnectAPIMap) => boolean;
|
|
2
|
+
import { ConnectionProfile } from '../../types/profiles.js';
|
|
3
|
+
|
|
5
4
|
export interface STConnectionProfileSelectProps {
|
|
6
5
|
/**
|
|
7
6
|
* The initially selected profile ID. The component will manage its state internally afterwards.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectionProfileSelect.d.ts","sourceRoot":"","sources":["../../../src/components/react/ConnectionProfileSelect.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAA6C,MAAM,OAAO,CAAC;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAK5D,MAAM,WAAW,8BAA8B;IAC7C;;OAEG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAElF;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;CACjD;AAED;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,8BAA8B,CA4IxE,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx as a, jsxs as T } from "react/jsx-runtime";
|
|
2
|
+
import { useState as v, useMemo as I, useEffect as A, useCallback as R } from "react";
|
|
3
|
+
import { STSelect as _ } from "./STSelect.js";
|
|
4
|
+
import { isProfileSupported as d } from "../../profile-utils.js";
|
|
5
|
+
const r = SillyTavern.getContext(), q = ({
|
|
6
|
+
initialSelectedProfileId: L,
|
|
7
|
+
allowedTypes: s = { openai: "Chat Completion", textgenerationwebui: "Text Completion" },
|
|
8
|
+
placeholder: D = "Select a Connection Profile",
|
|
9
|
+
onChange: n,
|
|
10
|
+
onCreate: u,
|
|
11
|
+
onUpdate: p,
|
|
12
|
+
onDelete: f
|
|
13
|
+
}) => {
|
|
14
|
+
const [E, N] = v(L ?? ""), [x, S] = v(Date.now()), { isEnabled: l, profiles: O, connectApiMap: c } = I(() => {
|
|
15
|
+
var t, i;
|
|
16
|
+
return ((t = r.extensionSettings.disabledExtensions) == null ? void 0 : t.includes("connection-manager")) ? (console.error("Connection Manager extension is disabled."), { isEnabled: !1, profiles: [], connectApiMap: {} }) : {
|
|
17
|
+
isEnabled: !0,
|
|
18
|
+
profiles: ((i = r.extensionSettings.connectionManager) == null ? void 0 : i.profiles) ?? [],
|
|
19
|
+
connectApiMap: r.CONNECT_API_MAP
|
|
20
|
+
};
|
|
21
|
+
}, [x]);
|
|
22
|
+
A(() => {
|
|
23
|
+
if (!l) return;
|
|
24
|
+
const o = (e) => {
|
|
25
|
+
d(e, s, c) && (S(Date.now()), u == null || u(e));
|
|
26
|
+
}, t = (e, m) => {
|
|
27
|
+
const P = d(e, s, c), b = d(m, s, c);
|
|
28
|
+
(P || b) && S(Date.now()), p == null || p(e, m), E === e.id && !b && (N(""), n == null || n(void 0));
|
|
29
|
+
}, i = (e) => {
|
|
30
|
+
d(e, s, c) && (S(Date.now()), f == null || f(e), E === e.id && (N(""), n == null || n(void 0)));
|
|
31
|
+
};
|
|
32
|
+
return r.eventSource.on("CONNECTION_PROFILE_CREATED", o), r.eventSource.on("CONNECTION_PROFILE_UPDATED", t), r.eventSource.on("CONNECTION_PROFILE_DELETED", i), () => {
|
|
33
|
+
r.eventSource.removeListener("CONNECTION_PROFILE_CREATED", o), r.eventSource.removeListener("CONNECTION_PROFILE_UPDATED", t), r.eventSource.removeListener("CONNECTION_PROFILE_DELETED", i);
|
|
34
|
+
};
|
|
35
|
+
}, [l, E, s, c, n, u, p, f]);
|
|
36
|
+
const C = I(() => {
|
|
37
|
+
if (!l) return [];
|
|
38
|
+
const o = O.filter((i) => d(i, s, c)), t = {};
|
|
39
|
+
for (const [i, e] of Object.entries(s))
|
|
40
|
+
t[i] = { label: e, profiles: [] };
|
|
41
|
+
for (const i of o) {
|
|
42
|
+
const e = c[i.api];
|
|
43
|
+
t[e.selected] && t[e.selected].profiles.push(i);
|
|
44
|
+
}
|
|
45
|
+
for (const i of Object.values(t))
|
|
46
|
+
i.profiles.sort((e, m) => (e.name ?? "").localeCompare(m.name ?? ""));
|
|
47
|
+
return Object.values(t).filter((i) => i.profiles.length > 0);
|
|
48
|
+
}, [l, O, s, c]), M = R(
|
|
49
|
+
(o) => {
|
|
50
|
+
const t = o.target.value;
|
|
51
|
+
N(t);
|
|
52
|
+
const i = O.find((e) => e.id === t);
|
|
53
|
+
n == null || n(i);
|
|
54
|
+
},
|
|
55
|
+
[O, n]
|
|
56
|
+
);
|
|
57
|
+
return l ? /* @__PURE__ */ T(_, { value: E, onChange: M, children: [
|
|
58
|
+
/* @__PURE__ */ a("option", { value: "", children: D }),
|
|
59
|
+
C.map((o) => /* @__PURE__ */ a("optgroup", { label: o.label, children: o.profiles.map((t) => /* @__PURE__ */ a("option", { value: t.id, children: t.name }, t.id)) }, o.label))
|
|
60
|
+
] }) : /* @__PURE__ */ a(_, { disabled: !0, value: "", children: /* @__PURE__ */ a("option", { children: "Connection Manager disabled" }) });
|
|
61
|
+
};
|
|
62
|
+
export {
|
|
63
|
+
q as STConnectionProfileSelect
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),c=require("react"),A=require("react-dom"),o=require("../../types/popup.cjs");require("../../../../power-user.js");require("../../../../../script.js");require("../../../../world-info.js");require("../../../../slash-commands.js");require("../../../../personas.js");require("../../../../instruct-mode.js");require("../../../../chats.js");require("../../../../openai.js");require("../../../../authors-note.js");require("../../../../group-chats.js");require("../../../regex/engine.js");const v=require("../../../../utils.js");require("../../../../slash-commands/SlashCommandCommonEnumsProvider.js");require("../../../../slash-commands/SlashCommandEnumValue.js");const n=require("../../../../popup.js"),R=require("../../../../../lib/dialog-polyfill.esm.js"),F=SillyTavern.getContext(),O=({content:T,type:a,inputValue:b="",options:t={},preventEscape:L=!1,onComplete:U})=>{var x;const d=c.useRef(null),h=c.useRef(null),[y,E]=c.useState(!1),[w,q]=c.useState(null),C=c.useRef(F.uuidv4()),s=c.useRef({id:C.current,type:a,dlg:null,mainInput:null,lastFocus:null,value:void 0,result:void 0,inputResults:void 0});c.useEffect(()=>{const e=d.current;if(!e)return;const u=r=>{r.preventDefault(),L||f(o.POPUP_RESULT.CANCELLED)};return e.addEventListener("cancel",u),s.current.dlg=e,s.current.mainInput=h.current,n.Popup.util.popups.push(s.current),e.showModal||(e.classList.add("poly_dialog"),R.registerDialog(e),new ResizeObserver(i=>{for(const g of i)R.reposition(g.target)}).observe(e)),e.showModal(),n.fixToastrForDialogs(),()=>{v.removeFromArray(n.Popup.util.popups,s.current),n.fixToastrForDialogs(),e.removeEventListener("cancel",u)}},[]);const f=async e=>{var i,g;let u=e;if(a===o.POPUP_TYPE.INPUT&&(e>=o.POPUP_RESULT.AFFIRMATIVE?u=(i=h.current)==null?void 0:i.value:e===o.POPUP_RESULT.NEGATIVE?u=!1:e===o.POPUP_RESULT.CANCELLED?u=null:u=!1),(g=t.customInputs)!=null&&g.length){const P=new Map(t.customInputs.map(m=>{var p;const _=(p=d.current)==null?void 0:p.querySelector(`#${m.id}`);return[_.id,_.checked]}));s.current.inputResults=P}if(s.current.result=e,s.current.value=u,t.onClosing&&!await t.onClosing(s.current)){E(!0),s.current.value=void 0,s.current.result=void 0,s.current.inputResults=void 0;return}E(!1),n.Popup.util.lastResult={value:u,result:e,inputResults:s.current.inputResults};const r=d.current;r&&(r.setAttribute("closing",""),n.fixToastrForDialogs(),v.runAfterAnimation(r,async()=>{var P;if(r.close(),t.onClose&&await t.onClose(s.current),v.removeFromArray(n.Popup.util.popups,s.current),n.Popup.util.popups.length>0){const m=(P=document.activeElement)==null?void 0:P.closest(".popup"),_=m==null?void 0:m.getAttribute("data-id"),p=n.Popup.util.popups.find(S=>S.id===_);p&&p.lastFocus&&p.lastFocus.focus()}U(u)}))},I=e=>{e.target instanceof HTMLElement&&e.target!==d.current&&(q(e.target),s.current.lastFocus=e.target)},j=async e=>{},N=()=>{const e=["popup"];return t.wide&&e.push("wide_dialogue_popup"),t.wider&&e.push("wider_dialogue_popup"),t.large&&e.push("large_dialogue_popup"),t.transparent&&e.push("transparent_dialogue_popup"),t.allowHorizontalScrolling&&e.push("horizontal_scrolling_dialogue_popup"),t.allowVerticalScrolling&&e.push("vertical_scrolling_dialogue_popup"),t.animation&&e.push(`popup--animation-${t.animation}`),e.join(" ")};return A.createPortal(l.jsx("dialog",{ref:d,className:N(),"data-id":C.current,onKeyDown:j,onFocus:I,children:l.jsxs("div",{className:"popup-body",children:[l.jsx("div",{className:"popup-content",children:T}),a===o.POPUP_TYPE.INPUT&&l.jsx("textarea",{ref:h,className:"popup-input text_pole result-control auto-select",rows:t.rows??1,defaultValue:b,"data-result":"1","data-result-event":"submit"}),t.customInputs&&l.jsx("div",{className:"popup-inputs",children:t.customInputs.map(e=>l.jsxs("label",{className:"checkbox_label justifyCenter",htmlFor:e.id,children:[l.jsx("input",{type:"checkbox",id:e.id,defaultChecked:e.defaultState}),l.jsx("span",{"data-i18n":e.label,children:e.label}),e.tooltip&&l.jsx("div",{className:"fa-solid fa-circle-info opacity50p",title:e.tooltip,"data-i18n":`[title]${e.tooltip}`})]},e.id))}),a!==o.POPUP_TYPE.DISPLAY&&l.jsxs("div",{className:"popup-controls",children:[(x=t.customButtons)==null?void 0:x.map((e,u)=>{const r=typeof e=="string"?{text:e,result:u+2}:e;return l.jsx("div",{className:`menu_button popup-button-custom result-control ${r.classes??""}`,"data-result":r.result,onClick:()=>{var i;(i=r.action)==null||i.call(r),f(r.result??u+2)},"data-i18n":r.text,children:r.text},u)}),a!==o.POPUP_TYPE.DISPLAY&&t.okButton!==!1&&l.jsx("div",{className:"popup-button-ok menu_button result-control",onClick:()=>f(o.POPUP_RESULT.AFFIRMATIVE),"data-result":"1",children:typeof t.okButton=="string"?t.okButton:"OK"}),a!==o.POPUP_TYPE.DISPLAY&&t.cancelButton!==!1&&l.jsx("div",{className:"popup-button-cancel menu_button result-control",onClick:()=>f(o.POPUP_RESULT.NEGATIVE),"data-result":"0",children:typeof t.cancelButton=="string"?t.cancelButton:"Cancel"})]}),a===o.POPUP_TYPE.DISPLAY&&l.jsx("div",{className:"popup-button-close right_menu_button fa-solid fa-circle-xmark",onClick:()=>f(o.POPUP_RESULT.CANCELLED),"data-result":"0",title:"Close popup","data-i18n":"[title]Close popup"})]})}),document.body)};exports.Popup=O;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { POPUP_TYPE, PopupOptions } from '
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { POPUP_TYPE, PopupOptions } from '../../types/popup.js';
|
|
3
|
+
|
|
3
4
|
interface PopupProps {
|
|
4
5
|
content: React.ReactNode;
|
|
5
6
|
type: POPUP_TYPE;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../../src/components/react/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAgB,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAG9E,UAAU,UAAU;IAClB,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC;AAID,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA+RtC,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { jsx as s, jsxs as b } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as C, useState as A, useEffect as B } from "react";
|
|
3
|
+
import { createPortal as M } from "react-dom";
|
|
4
|
+
import { POPUP_TYPE as c, POPUP_RESULT as n } from "../../types/popup.js";
|
|
5
|
+
import "../../../../power-user.js";
|
|
6
|
+
import "../../../../../script.js";
|
|
7
|
+
import "../../../../world-info.js";
|
|
8
|
+
import "../../../../slash-commands.js";
|
|
9
|
+
import "../../../../personas.js";
|
|
10
|
+
import "../../../../instruct-mode.js";
|
|
11
|
+
import "../../../../chats.js";
|
|
12
|
+
import "../../../../openai.js";
|
|
13
|
+
import "../../../../authors-note.js";
|
|
14
|
+
import "../../../../group-chats.js";
|
|
15
|
+
import "../../../regex/engine.js";
|
|
16
|
+
import { removeFromArray as w, runAfterAnimation as O } from "../../../../utils.js";
|
|
17
|
+
import "../../../../slash-commands/SlashCommandCommonEnumsProvider.js";
|
|
18
|
+
import "../../../../slash-commands/SlashCommandEnumValue.js";
|
|
19
|
+
import { Popup as p, fixToastrForDialogs as I } from "../../../../popup.js";
|
|
20
|
+
import L from "../../../../../lib/dialog-polyfill.esm.js";
|
|
21
|
+
const V = SillyTavern.getContext(), it = ({
|
|
22
|
+
content: F,
|
|
23
|
+
type: u,
|
|
24
|
+
inputValue: R = "",
|
|
25
|
+
options: e = {},
|
|
26
|
+
preventEscape: k = !1,
|
|
27
|
+
onComplete: y
|
|
28
|
+
}) => {
|
|
29
|
+
var E;
|
|
30
|
+
const d = C(null), _ = C(null), [z, N] = A(!1), [U, x] = A(null), P = C(V.uuidv4()), o = C({
|
|
31
|
+
id: P.current,
|
|
32
|
+
type: u,
|
|
33
|
+
dlg: null,
|
|
34
|
+
mainInput: null,
|
|
35
|
+
lastFocus: null,
|
|
36
|
+
value: void 0,
|
|
37
|
+
result: void 0,
|
|
38
|
+
inputResults: void 0
|
|
39
|
+
});
|
|
40
|
+
B(() => {
|
|
41
|
+
const t = d.current;
|
|
42
|
+
if (!t) return;
|
|
43
|
+
const r = (l) => {
|
|
44
|
+
l.preventDefault(), k || m(n.CANCELLED);
|
|
45
|
+
};
|
|
46
|
+
return t.addEventListener("cancel", r), o.current.dlg = t, o.current.mainInput = _.current, p.util.popups.push(o.current), t.showModal || (t.classList.add("poly_dialog"), L.registerDialog(t), new ResizeObserver((a) => {
|
|
47
|
+
for (const h of a)
|
|
48
|
+
L.reposition(h.target);
|
|
49
|
+
}).observe(t)), t.showModal(), I(), () => {
|
|
50
|
+
w(p.util.popups, o.current), I(), t.removeEventListener("cancel", r);
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
const m = async (t) => {
|
|
54
|
+
var a, h;
|
|
55
|
+
let r = t;
|
|
56
|
+
if (u === c.INPUT && (t >= n.AFFIRMATIVE ? r = (a = _.current) == null ? void 0 : a.value : t === n.NEGATIVE ? r = !1 : t === n.CANCELLED ? r = null : r = !1), (h = e.customInputs) != null && h.length) {
|
|
57
|
+
const f = new Map(
|
|
58
|
+
e.customInputs.map((g) => {
|
|
59
|
+
var i;
|
|
60
|
+
const v = (i = d.current) == null ? void 0 : i.querySelector(`#${g.id}`);
|
|
61
|
+
return [v.id, v.checked];
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
o.current.inputResults = f;
|
|
65
|
+
}
|
|
66
|
+
if (o.current.result = t, o.current.value = r, e.onClosing && !await e.onClosing(o.current)) {
|
|
67
|
+
N(!0), o.current.value = void 0, o.current.result = void 0, o.current.inputResults = void 0;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
N(!1), p.util.lastResult = {
|
|
71
|
+
value: r,
|
|
72
|
+
result: t,
|
|
73
|
+
inputResults: o.current.inputResults
|
|
74
|
+
};
|
|
75
|
+
const l = d.current;
|
|
76
|
+
l && (l.setAttribute("closing", ""), I(), O(l, async () => {
|
|
77
|
+
var f;
|
|
78
|
+
if (l.close(), e.onClose && await e.onClose(o.current), w(p.util.popups, o.current), p.util.popups.length > 0) {
|
|
79
|
+
const g = (f = document.activeElement) == null ? void 0 : f.closest(".popup"), v = g == null ? void 0 : g.getAttribute("data-id"), i = p.util.popups.find((T) => T.id === v);
|
|
80
|
+
i && i.lastFocus && i.lastFocus.focus();
|
|
81
|
+
}
|
|
82
|
+
y(r);
|
|
83
|
+
}));
|
|
84
|
+
}, D = (t) => {
|
|
85
|
+
t.target instanceof HTMLElement && t.target !== d.current && (x(t.target), o.current.lastFocus = t.target);
|
|
86
|
+
}, S = async (t) => {
|
|
87
|
+
};
|
|
88
|
+
return M(
|
|
89
|
+
/* @__PURE__ */ s(
|
|
90
|
+
"dialog",
|
|
91
|
+
{
|
|
92
|
+
ref: d,
|
|
93
|
+
className: (() => {
|
|
94
|
+
const t = ["popup"];
|
|
95
|
+
return e.wide && t.push("wide_dialogue_popup"), e.wider && t.push("wider_dialogue_popup"), e.large && t.push("large_dialogue_popup"), e.transparent && t.push("transparent_dialogue_popup"), e.allowHorizontalScrolling && t.push("horizontal_scrolling_dialogue_popup"), e.allowVerticalScrolling && t.push("vertical_scrolling_dialogue_popup"), e.animation && t.push(`popup--animation-${e.animation}`), t.join(" ");
|
|
96
|
+
})(),
|
|
97
|
+
"data-id": P.current,
|
|
98
|
+
onKeyDown: S,
|
|
99
|
+
onFocus: D,
|
|
100
|
+
children: /* @__PURE__ */ b("div", { className: "popup-body", children: [
|
|
101
|
+
/* @__PURE__ */ s("div", { className: "popup-content", children: F }),
|
|
102
|
+
u === c.INPUT && /* @__PURE__ */ s(
|
|
103
|
+
"textarea",
|
|
104
|
+
{
|
|
105
|
+
ref: _,
|
|
106
|
+
className: "popup-input text_pole result-control auto-select",
|
|
107
|
+
rows: e.rows ?? 1,
|
|
108
|
+
defaultValue: R,
|
|
109
|
+
"data-result": "1",
|
|
110
|
+
"data-result-event": "submit"
|
|
111
|
+
}
|
|
112
|
+
),
|
|
113
|
+
e.customInputs && /* @__PURE__ */ s("div", { className: "popup-inputs", children: e.customInputs.map((t) => /* @__PURE__ */ b("label", { className: "checkbox_label justifyCenter", htmlFor: t.id, children: [
|
|
114
|
+
/* @__PURE__ */ s("input", { type: "checkbox", id: t.id, defaultChecked: t.defaultState }),
|
|
115
|
+
/* @__PURE__ */ s("span", { "data-i18n": t.label, children: t.label }),
|
|
116
|
+
t.tooltip && /* @__PURE__ */ s(
|
|
117
|
+
"div",
|
|
118
|
+
{
|
|
119
|
+
className: "fa-solid fa-circle-info opacity50p",
|
|
120
|
+
title: t.tooltip,
|
|
121
|
+
"data-i18n": `[title]${t.tooltip}`
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] }, t.id)) }),
|
|
125
|
+
u !== c.DISPLAY && /* @__PURE__ */ b("div", { className: "popup-controls", children: [
|
|
126
|
+
(E = e.customButtons) == null ? void 0 : E.map((t, r) => {
|
|
127
|
+
const l = typeof t == "string" ? { text: t, result: r + 2 } : t;
|
|
128
|
+
return /* @__PURE__ */ s(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
className: `menu_button popup-button-custom result-control ${l.classes ?? ""}`,
|
|
132
|
+
"data-result": l.result,
|
|
133
|
+
onClick: () => {
|
|
134
|
+
var a;
|
|
135
|
+
(a = l.action) == null || a.call(l), m(l.result ?? r + 2);
|
|
136
|
+
},
|
|
137
|
+
"data-i18n": l.text,
|
|
138
|
+
children: l.text
|
|
139
|
+
},
|
|
140
|
+
r
|
|
141
|
+
);
|
|
142
|
+
}),
|
|
143
|
+
u !== c.DISPLAY && e.okButton !== !1 && /* @__PURE__ */ s(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
className: "popup-button-ok menu_button result-control",
|
|
147
|
+
onClick: () => m(n.AFFIRMATIVE),
|
|
148
|
+
"data-result": "1",
|
|
149
|
+
children: typeof e.okButton == "string" ? e.okButton : "OK"
|
|
150
|
+
}
|
|
151
|
+
),
|
|
152
|
+
u !== c.DISPLAY && e.cancelButton !== !1 && /* @__PURE__ */ s(
|
|
153
|
+
"div",
|
|
154
|
+
{
|
|
155
|
+
className: "popup-button-cancel menu_button result-control",
|
|
156
|
+
onClick: () => m(n.NEGATIVE),
|
|
157
|
+
"data-result": "0",
|
|
158
|
+
children: typeof e.cancelButton == "string" ? e.cancelButton : "Cancel"
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
] }),
|
|
162
|
+
u === c.DISPLAY && /* @__PURE__ */ s(
|
|
163
|
+
"div",
|
|
164
|
+
{
|
|
165
|
+
className: "popup-button-close right_menu_button fa-solid fa-circle-xmark",
|
|
166
|
+
onClick: () => m(n.CANCELLED),
|
|
167
|
+
"data-result": "0",
|
|
168
|
+
title: "Close popup",
|
|
169
|
+
"data-i18n": "[title]Close popup"
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
] })
|
|
173
|
+
}
|
|
174
|
+
),
|
|
175
|
+
document.body
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
export {
|
|
179
|
+
it as Popup
|
|
180
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),a=require("react"),c=({children:s,className:e,overrideDefaults:n=!1,...o})=>{const u=a.useMemo(()=>{const t=[];return n||t.push("menu_button","interactable"),t.push(e),t.filter(Boolean).join(" ")},[n,e]);return r.jsx("button",{className:u,...o,children:s})};exports.STButton=c;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"STButton.d.ts","sourceRoot":"","sources":["../../../src/components/react/STButton.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,oBAAoB,EAAW,MAAM,OAAO,CAAC;AAE1D,MAAM,WAAW,aAAc,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IAC5E;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,EAAE,EAAE,CAAC,aAAa,CAkBtC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo as a } from "react";
|
|
3
|
+
const l = ({ children: s, className: o, overrideDefaults: n = !1, ...e }) => {
|
|
4
|
+
const r = a(() => {
|
|
5
|
+
const t = [];
|
|
6
|
+
return n || t.push("menu_button", "interactable"), t.push(o), t.filter(Boolean).join(" ");
|
|
7
|
+
}, [n, o]);
|
|
8
|
+
return /* @__PURE__ */ u("button", { className: r, ...e, children: s });
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
l as STButton
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),n=require("react"),E=require("fuse.js"),M=require("./STInput.cjs"),R=({items:t,value:r,onChange:u,placeholder:c="Select items...",closeOnSelect:l=!1,multiple:j=!0,disabled:p=!1,onBeforeSelection:g,enableSearch:a=!1,searchPlaceholder:C="Search...",searchNoResultsText:k="No results found",searchFuseOptions:y,inputClasses:I,containerClasses:S})=>{const[i,f]=n.useState(!1),[d,m]=n.useState(""),x=n.useRef(null);n.useEffect(()=>{const e=s=>{x.current&&!x.current.contains(s.target)&&f(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),n.useEffect(()=>{i||m("")},[i]);const v=n.useMemo(()=>{if(!a)return null;const e={includeScore:!1,threshold:.4,keys:["label","value"],...y};return new E(t,e)},[t,a,y]),h=n.useMemo(()=>!a||!d.trim()||!v?t:v.search(d.trim()).map(e=>e.item),[t,d,a,v]),T=async e=>{let s;j?s=r.includes(e)?r.filter(b=>b!==e):[...r,e]:s=r.includes(e)?[]:[e],!(g&&!await Promise.resolve(g(r,s)))&&(u(s),l&&f(!1))},N=n.useMemo(()=>{var e;return r.length===0?c:r.length===1?((e=t.find(s=>s.value===r[0]))==null?void 0:e.label)??r[0]:`${r.length} items selected`},[r,t,c]);return o.jsxs("div",{ref:x,className:`fancy-dropdown-container ${S??""}`,style:{position:"relative",userSelect:"none",opacity:p?.6:1,pointerEvents:p?"none":"auto"},children:[o.jsxs("div",{className:"fancy-dropdown-trigger",onClick:()=>!p&&f(!i),style:{padding:"8px 12px",border:"1px solid var(--border-color)",backgroundColor:"var(--bg-color)",color:"var(--text-color)",borderRadius:"4px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[o.jsx("span",{className:"fancy-dropdown-trigger-text",children:N}),o.jsx("i",{className:`fas ${i?"fa-chevron-up":"fa-chevron-down"}`,style:{marginLeft:"8px"}})]}),i&&o.jsxs("div",{className:"fancy-dropdown-list",style:{position:"absolute",top:"100%",left:"0",right:"0",maxHeight:"300px",zIndex:1050,border:"1px solid var(--border-color)",borderTop:"none",backgroundColor:"var(--bg-color-popup, var(--bg-color-secondary, var(--greyCAIbg, var(--grey30))))",color:"var(--text-color)",borderRadius:"0 0 4px 4px",boxShadow:"0 4px 8px var(--black50a)",overflowY:"auto",display:"flex",flexDirection:"column"},children:[a&&o.jsx("div",{style:{padding:"8px",borderBottom:"1px solid var(--border-color)",position:"sticky",top:0,backgroundColor:"inherit"},children:o.jsx(M.STInput,{type:"text",placeholder:C,value:d,onChange:e=>m(e.target.value),autoFocus:!0,className:I})}),o.jsx("ul",{style:{listStyle:"none",margin:0,padding:0},children:h.length>0?h.map(e=>o.jsx(w,{item:e,isSelected:r.includes(e.value),onClick:T},e.value)):o.jsx("div",{style:{padding:"8px 12px",textAlign:"center",color:"var(--text-color-secondary, var(--grey50))"},children:k})})]})]})},w=n.memo(({item:t,isSelected:r,onClick:u})=>{const[c,l]=n.useState(!1);return o.jsxs("li",{onClick:()=>u(t.value),onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),style:{padding:"8px 12px",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"space-between",backgroundColor:r?"var(--accent-color-bg, var(--link-color))":c?"var(--hover-color, var(--white20a))":"transparent"},children:[o.jsx("span",{children:t.label}),r&&o.jsx("i",{className:"checkmark fa-solid fa-check",style:{marginLeft:"8px"}})]})});exports.FancyDropdownItem=w;exports.STFancyDropdown=R;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"STFancyDropdown.d.ts","sourceRoot":"","sources":["../../../src/components/react/STFancyDropdown.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;AACxE,OAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG7C,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,oDAAoD;IACpD,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,8CAA8C;IAC9C,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iDAAiD;IACjD,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAExC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAGtG,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,iBAAiB,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,EAAE,CAAC,oBAAoB,CA4LpD,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,EAAE,CAAC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAyB5G,CAAC"}
|