sillytavern-utils-lib 1.0.55 → 1.0.57

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.
Files changed (55) hide show
  1. package/dist/components/ConnectionProfileSelect.d.ts +43 -0
  2. package/dist/components/ConnectionProfileSelect.d.ts.map +1 -0
  3. package/dist/components/ConnectionProfileSelect.js +126 -0
  4. package/dist/components/ConnectionProfileSelect.js.map +1 -0
  5. package/dist/components/MyFancyButton.d.ts +6 -0
  6. package/dist/components/MyFancyButton.d.ts.map +1 -0
  7. package/dist/components/MyFancyButton.js +22 -0
  8. package/dist/components/MyFancyButton.js.map +1 -0
  9. package/dist/components/Popup.d.ts +12 -0
  10. package/dist/components/Popup.d.ts.map +1 -0
  11. package/dist/components/Popup.js +168 -0
  12. package/dist/components/Popup.js.map +1 -0
  13. package/dist/components/STButton.d.ts +23 -0
  14. package/dist/components/STButton.d.ts.map +1 -0
  15. package/dist/components/STButton.js +20 -0
  16. package/dist/components/STButton.js.map +1 -0
  17. package/dist/components/STFancyDropdown.d.ts +35 -0
  18. package/dist/components/STFancyDropdown.d.ts.map +1 -0
  19. package/dist/components/STFancyDropdown.js +135 -0
  20. package/dist/components/STFancyDropdown.js.map +1 -0
  21. package/dist/components/STInput.d.ts +25 -0
  22. package/dist/components/STInput.d.ts.map +1 -0
  23. package/dist/components/STInput.js +26 -0
  24. package/dist/components/STInput.js.map +1 -0
  25. package/dist/components/STPresetSelect.d.ts +59 -0
  26. package/dist/components/STPresetSelect.d.ts.map +1 -0
  27. package/dist/components/STPresetSelect.js +95 -0
  28. package/dist/components/STPresetSelect.js.map +1 -0
  29. package/dist/components/STSelect.d.ts +18 -0
  30. package/dist/components/STSelect.d.ts.map +1 -0
  31. package/dist/components/STSelect.js +18 -0
  32. package/dist/components/STSelect.js.map +1 -0
  33. package/dist/components/STSortableList.d.ts +44 -0
  34. package/dist/components/STSortableList.d.ts.map +1 -0
  35. package/dist/components/STSortableList.js +90 -0
  36. package/dist/components/STSortableList.js.map +1 -0
  37. package/dist/components/STTextarea.d.ts +18 -0
  38. package/dist/components/STTextarea.d.ts.map +1 -0
  39. package/dist/components/STTextarea.js +18 -0
  40. package/dist/components/STTextarea.js.map +1 -0
  41. package/dist/components/index.d.ts +12 -0
  42. package/dist/components/index.d.ts.map +1 -0
  43. package/dist/components/index.js +11 -0
  44. package/dist/components/index.js.map +1 -0
  45. package/dist/config.d.ts +4 -1
  46. package/dist/config.d.ts.map +1 -1
  47. package/dist/config.js +6 -2
  48. package/dist/config.js.map +1 -1
  49. package/dist/generate.d.ts +2 -14
  50. package/dist/generate.d.ts.map +1 -1
  51. package/dist/generate.js +2 -2
  52. package/dist/generate.js.map +1 -1
  53. package/dist/types/index.d.ts +16 -8
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/package.json +16 -3
@@ -0,0 +1,43 @@
1
+ import { FC } from 'react';
2
+ import { ConnectAPIMap } from '../types/index.js';
3
+ import { ConnectionProfile } from '../types/profiles.js';
4
+ export declare const isProfileSupported: (profile: ConnectionProfile | undefined, allowedTypes: Record<string, string>, connectApiMap: ConnectAPIMap) => boolean;
5
+ export interface STConnectionProfileSelectProps {
6
+ /**
7
+ * The initially selected profile ID. The component will manage its state internally afterwards.
8
+ */
9
+ initialSelectedProfileId?: string;
10
+ /**
11
+ * The allowed API types to display in the dropdown, mapping the internal type to a display label.
12
+ * @default { openai: 'Chat Completion', textgenerationwebui: 'Text Completion' }
13
+ */
14
+ allowedTypes?: Record<string, string>;
15
+ /**
16
+ * Placeholder text for when no profile is selected.
17
+ * @default 'Select a Connection Profile'
18
+ */
19
+ placeholder?: string;
20
+ /**
21
+ * Callback fired when the user selects a different profile from the dropdown.
22
+ * Also fires with `undefined` if the currently selected profile is deleted or becomes unsupported.
23
+ */
24
+ onChange?: (profile?: ConnectionProfile) => void;
25
+ /**
26
+ * Callback fired when a new, supported profile is created in SillyTavern.
27
+ */
28
+ onCreate?: (profile: ConnectionProfile) => void;
29
+ /**
30
+ * Callback fired when a profile is updated in SillyTavern.
31
+ */
32
+ onUpdate?: (oldProfile: ConnectionProfile, newProfile: ConnectionProfile) => void;
33
+ /**
34
+ * Callback fired when a supported profile is deleted in SillyTavern.
35
+ */
36
+ onDelete?: (profile: ConnectionProfile) => void;
37
+ }
38
+ /**
39
+ * A React component that renders a dropdown of supported SillyTavern connection profiles.
40
+ * It automatically updates when profiles are created, updated, or deleted.
41
+ */
42
+ export declare const STConnectionProfileSelect: FC<STConnectionProfileSelectProps>;
43
+ //# sourceMappingURL=ConnectionProfileSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionProfileSelect.d.ts","sourceRoot":"","sources":["../../src/components/ConnectionProfileSelect.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAA6C,MAAM,OAAO,CAAC;AAE7E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAKzD,eAAO,MAAM,kBAAkB,GAC7B,SAAS,iBAAiB,GAAG,SAAS,EACtC,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,eAAe,aAAa,KAC3B,OAmBF,CAAC;AAEF,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,126 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useMemo, useCallback } from 'react';
3
+ import { STSelect } from './STSelect.js';
4
+ const globalContext = SillyTavern.getContext();
5
+ // Helper function to replicate the filtering logic from the original source
6
+ export const isProfileSupported = (profile, allowedTypes, connectApiMap) => {
7
+ if (!profile || !profile.api) {
8
+ return false;
9
+ }
10
+ const apiMap = connectApiMap[profile.api];
11
+ if (!apiMap || !Object.hasOwn(allowedTypes, apiMap.selected)) {
12
+ return false;
13
+ }
14
+ // The original logic checks for a valid source/type depending on the API
15
+ switch (apiMap.selected) {
16
+ case 'openai':
17
+ return !!apiMap.source;
18
+ case 'textgenerationwebui':
19
+ return !!apiMap.type;
20
+ }
21
+ return false;
22
+ };
23
+ /**
24
+ * A React component that renders a dropdown of supported SillyTavern connection profiles.
25
+ * It automatically updates when profiles are created, updated, or deleted.
26
+ */
27
+ export const STConnectionProfileSelect = ({ initialSelectedProfileId, allowedTypes = { openai: 'Chat Completion', textgenerationwebui: 'Text Completion' }, placeholder = 'Select a Connection Profile', onChange, onCreate, onUpdate, onDelete, }) => {
28
+ const [selectedId, setSelectedId] = useState(initialSelectedProfileId ?? '');
29
+ const [lastUpdated, setLastUpdated] = useState(Date.now()); // State to force re-render on global changes
30
+ const { isEnabled, profiles, connectApiMap } = useMemo(() => {
31
+ const isConnectionManagerDisabled = globalContext.extensionSettings.disabledExtensions?.includes('connection-manager');
32
+ if (isConnectionManagerDisabled) {
33
+ console.error('Connection Manager extension is disabled.');
34
+ return { isEnabled: false, profiles: [], connectApiMap: {} };
35
+ }
36
+ return {
37
+ isEnabled: true,
38
+ profiles: globalContext.extensionSettings.connectionManager?.profiles ?? [],
39
+ connectApiMap: globalContext.CONNECT_API_MAP,
40
+ };
41
+ }, [lastUpdated]); // Reruns when we detect a change from events
42
+ useEffect(() => {
43
+ if (!isEnabled)
44
+ return;
45
+ // Handler for creation
46
+ const handleCreate = (profile) => {
47
+ if (isProfileSupported(profile, allowedTypes, connectApiMap)) {
48
+ setLastUpdated(Date.now());
49
+ onCreate?.(profile);
50
+ }
51
+ };
52
+ // Handler for updates
53
+ const handleUpdate = (oldProfile, newProfile) => {
54
+ const wasSupported = isProfileSupported(oldProfile, allowedTypes, connectApiMap);
55
+ const isNowSupported = isProfileSupported(newProfile, allowedTypes, connectApiMap);
56
+ // If the profile was or is now supported, we need to update the list
57
+ if (wasSupported || isNowSupported) {
58
+ setLastUpdated(Date.now());
59
+ }
60
+ onUpdate?.(oldProfile, newProfile);
61
+ // If the currently selected profile is the one being updated and it's no longer supported, deselect it.
62
+ if (selectedId === oldProfile.id && !isNowSupported) {
63
+ setSelectedId('');
64
+ onChange?.(undefined);
65
+ }
66
+ };
67
+ // Handler for deletions
68
+ const handleDelete = (profile) => {
69
+ if (isProfileSupported(profile, allowedTypes, connectApiMap)) {
70
+ setLastUpdated(Date.now());
71
+ onDelete?.(profile);
72
+ // If the deleted profile was the one selected, deselect it.
73
+ if (selectedId === profile.id) {
74
+ setSelectedId('');
75
+ onChange?.(undefined);
76
+ }
77
+ }
78
+ };
79
+ // @ts-ignore - ST event types are not formally defined
80
+ globalContext.eventSource.on('CONNECTION_PROFILE_CREATED', handleCreate);
81
+ // @ts-ignore
82
+ globalContext.eventSource.on('CONNECTION_PROFILE_UPDATED', handleUpdate);
83
+ // @ts-ignore
84
+ globalContext.eventSource.on('CONNECTION_PROFILE_DELETED', handleDelete);
85
+ return () => {
86
+ // @ts-ignore
87
+ globalContext.eventSource.removeListener('CONNECTION_PROFILE_CREATED', handleCreate);
88
+ // @ts-ignore
89
+ globalContext.eventSource.removeListener('CONNECTION_PROFILE_UPDATED', handleUpdate);
90
+ // @ts-ignore
91
+ globalContext.eventSource.removeListener('CONNECTION_PROFILE_DELETED', handleDelete);
92
+ };
93
+ }, [isEnabled, selectedId, allowedTypes, connectApiMap, onChange, onCreate, onUpdate, onDelete]);
94
+ // Memoize the expensive filtering and sorting logic
95
+ const groupedAndSortedProfiles = useMemo(() => {
96
+ if (!isEnabled)
97
+ return [];
98
+ const supported = profiles.filter((p) => isProfileSupported(p, allowedTypes, connectApiMap));
99
+ const groups = {};
100
+ for (const [apiType, groupLabel] of Object.entries(allowedTypes)) {
101
+ groups[apiType] = { label: groupLabel, profiles: [] };
102
+ }
103
+ for (const profile of supported) {
104
+ const apiMap = connectApiMap[profile.api];
105
+ if (groups[apiMap.selected]) {
106
+ groups[apiMap.selected].profiles.push(profile);
107
+ }
108
+ }
109
+ // Sort profiles within each group alphabetically by name
110
+ for (const group of Object.values(groups)) {
111
+ group.profiles.sort((a, b) => (a.name ?? '').localeCompare(b.name ?? ''));
112
+ }
113
+ return Object.values(groups).filter((g) => g.profiles.length > 0);
114
+ }, [isEnabled, profiles, allowedTypes, connectApiMap]);
115
+ const handleSelectChange = useCallback((event) => {
116
+ const newId = event.target.value;
117
+ setSelectedId(newId);
118
+ const profile = profiles.find((p) => p.id === newId);
119
+ onChange?.(profile);
120
+ }, [profiles, onChange]);
121
+ if (!isEnabled) {
122
+ return _jsx(STSelect, { disabled: true, value: "", children: _jsx("option", { children: "Connection Manager disabled" }) });
123
+ }
124
+ return (_jsxs(STSelect, { value: selectedId, onChange: handleSelectChange, children: [_jsx("option", { value: "", children: placeholder }), groupedAndSortedProfiles.map((group) => (_jsx("optgroup", { label: group.label, children: group.profiles.map((profile) => (_jsx("option", { value: profile.id, children: profile.name }, profile.id))) }, group.label)))] }));
125
+ };
126
+ //# sourceMappingURL=ConnectionProfileSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConnectionProfileSelect.js","sourceRoot":"","sources":["../../src/components/ConnectionPro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,YAC3C,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAC/B,iBAAyB,KAAK,EAAE,OAAO,CAAC,EAAE,YACvC,OAAO,CAAC,IAAI,IADF,OAAO,CAAC,EAAE,CAEd,CACV,CAAC,IALW,KAAK,CAAC,KAAK,CAMf,CACZ,CAAC,IACO,CACZ,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { FC, ButtonHTMLAttributes } from 'react';
2
+ export interface MyFancyButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
3
+ variant?: 'primary' | 'secondary';
4
+ }
5
+ export declare const MyFancyButton: FC<MyFancyButtonProps>;
6
+ //# sourceMappingURL=MyFancyButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MyFancyButton.d.ts","sourceRoot":"","sources":["../../src/components/MyFancyButton.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB,CAAC,iBAAiB,CAAC;IACjF,OAAO,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;CACnC;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,kBAAkB,CAyBhD,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export const MyFancyButton = ({ children, variant = 'primary', ...props }) => {
3
+ const baseStyle = {
4
+ padding: '10px 15px',
5
+ border: 'none',
6
+ borderRadius: '5px',
7
+ cursor: 'pointer',
8
+ fontWeight: 'bold',
9
+ };
10
+ const variantStyle = {
11
+ primary: {
12
+ backgroundColor: '#007bff',
13
+ color: 'white',
14
+ },
15
+ secondary: {
16
+ backgroundColor: '#6c757d',
17
+ color: 'white',
18
+ },
19
+ }[variant];
20
+ return (_jsx("button", { style: { ...baseStyle, ...variantStyle }, ...props, children: children }));
21
+ };
22
+ //# sourceMappingURL=MyFancyButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MyFancyButton.js","sourceRoot":"","sources":["../../src/components/MyFancyButton.tsx"],"names":[],"mappings":";AAMA,MAAM,CAAC,MAAM,aAAa,GAA2B,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACnG,MAAM,SAAS,GAAwB;QACrC,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,MAAM;QACd,YAAY,EAAE,KAAK;QACnB,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,MAAM;KACnB,CAAC;IAEF,MAAM,YAAY,GAAwB;QACxC,OAAO,EAAE;YACP,eAAe,EAAE,SAAS;YAC1B,KAAK,EAAE,OAAO;SACf;QACD,SAAS,EAAE;YACT,eAAe,EAAE,SAAS;YAC1B,KAAK,EAAE,OAAO;SACf;KACF,CAAC,OAAO,CAAC,CAAC;IAEX,OAAO,CACL,iBAAQ,KAAK,EAAE,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,EAAE,KAAM,KAAK,YACxD,QAAQ,GACF,CACV,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { POPUP_TYPE, PopupOptions } from '../types/popup.js';
3
+ interface PopupProps {
4
+ content: React.ReactNode;
5
+ type: POPUP_TYPE;
6
+ inputValue?: string;
7
+ options?: PopupOptions;
8
+ onComplete: (value: any) => void;
9
+ }
10
+ export declare const Popup: React.FC<PopupProps>;
11
+ export {};
12
+ //# sourceMappingURL=Popup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../../src/components/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,EAAgB,UAAU,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3E,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,UAAU,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAClC;AAID,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,UAAU,CA0QtC,CAAC"}
@@ -0,0 +1,168 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import { POPUP_RESULT, POPUP_TYPE } from '../types/popup.js';
5
+ import { dialogPolyfill, fixToastrForDialogs, removeFromArray, runAfterAnimation, STPopup } from '../config.js';
6
+ const globalContext = SillyTavern.getContext();
7
+ export const Popup = ({ content, type, inputValue = '', options = {}, onComplete }) => {
8
+ const dialogRef = useRef(null);
9
+ const mainInputRef = useRef(null);
10
+ const [isClosingPrevented, setIsClosingPrevented] = useState(false);
11
+ const [lastFocus, setLastFocus] = useState(null);
12
+ const id = useRef(globalContext.uuidv4());
13
+ // Create a reference object that mimics the original Popup instance
14
+ const popupRef = useRef({
15
+ id: id.current,
16
+ type,
17
+ dlg: null,
18
+ mainInput: null,
19
+ lastFocus: null,
20
+ value: undefined,
21
+ result: undefined,
22
+ inputResults: undefined,
23
+ });
24
+ useEffect(() => {
25
+ const dialog = dialogRef.current;
26
+ if (!dialog)
27
+ return;
28
+ // Update the popup reference
29
+ popupRef.current.dlg = dialog;
30
+ popupRef.current.mainInput = mainInputRef.current;
31
+ // Add to STPopup utility's popup array
32
+ STPopup.util.popups.push(popupRef.current);
33
+ if (!dialog.showModal) {
34
+ dialog.classList.add('poly_dialog');
35
+ dialogPolyfill.registerDialog(dialog);
36
+ const resizeObserver = new ResizeObserver((entries) => {
37
+ for (const entry of entries) {
38
+ dialogPolyfill.reposition(entry.target);
39
+ }
40
+ });
41
+ resizeObserver.observe(dialog);
42
+ }
43
+ dialog.showModal();
44
+ fixToastrForDialogs();
45
+ return () => {
46
+ // Remove from STPopup utility's popup array
47
+ removeFromArray(STPopup.util.popups, popupRef.current);
48
+ // Don't call dialog.close() here since it's handled in handleComplete
49
+ fixToastrForDialogs();
50
+ };
51
+ }, []);
52
+ const handleComplete = async (result) => {
53
+ let value = result;
54
+ if (type === POPUP_TYPE.INPUT) {
55
+ if (result >= POPUP_RESULT.AFFIRMATIVE)
56
+ value = mainInputRef.current?.value;
57
+ else if (result === POPUP_RESULT.NEGATIVE)
58
+ value = false;
59
+ else if (result === POPUP_RESULT.CANCELLED)
60
+ value = null;
61
+ else
62
+ value = false;
63
+ }
64
+ if (options.customInputs?.length) {
65
+ const inputResults = new Map(options.customInputs.map((input) => {
66
+ const inputControl = dialogRef.current?.querySelector(`#${input.id}`);
67
+ return [inputControl.id, inputControl.checked];
68
+ }));
69
+ popupRef.current.inputResults = inputResults;
70
+ }
71
+ // Update the popup reference with result and value
72
+ popupRef.current.result = result;
73
+ popupRef.current.value = value;
74
+ if (options.onClosing) {
75
+ const shouldClose = await options.onClosing(popupRef.current);
76
+ if (!shouldClose) {
77
+ setIsClosingPrevented(true);
78
+ // Set values back if we cancel out of closing the popup
79
+ popupRef.current.value = undefined;
80
+ popupRef.current.result = undefined;
81
+ popupRef.current.inputResults = undefined;
82
+ return;
83
+ }
84
+ }
85
+ setIsClosingPrevented(false);
86
+ // Update STPopup's lastResult
87
+ STPopup.util.lastResult = {
88
+ value,
89
+ result,
90
+ inputResults: popupRef.current.inputResults,
91
+ };
92
+ // Start hiding process
93
+ const dialog = dialogRef.current;
94
+ if (!dialog)
95
+ return;
96
+ // We close the dialog, first running the animation
97
+ dialog.setAttribute('closing', '');
98
+ // Once the hiding starts, we need to fix the toastr to the layer below
99
+ fixToastrForDialogs();
100
+ // After the dialog is actually completely closed, remove it from the DOM
101
+ runAfterAnimation(dialog, async () => {
102
+ // Call the close on the dialog
103
+ dialog.close();
104
+ // Run a possible custom handler right before DOM removal
105
+ if (options.onClose) {
106
+ await options.onClose(popupRef.current);
107
+ }
108
+ // Remove it from the popup references
109
+ removeFromArray(STPopup.util.popups, popupRef.current);
110
+ // If there is any popup below this one, see if we can set the focus
111
+ if (STPopup.util.popups.length > 0) {
112
+ const activeDialog = document.activeElement?.closest('.popup');
113
+ const id = activeDialog?.getAttribute('data-id');
114
+ // @ts-ignore
115
+ const popup = STPopup.util.popups.find((x) => x.id === id);
116
+ if (popup) {
117
+ if (popup.lastFocus)
118
+ popup.lastFocus.focus();
119
+ }
120
+ }
121
+ // Don't manually remove the dialog - let React handle it
122
+ onComplete(value);
123
+ });
124
+ };
125
+ const handleFocusIn = (evt) => {
126
+ if (evt.target instanceof HTMLElement && evt.target !== dialogRef.current) {
127
+ setLastFocus(evt.target);
128
+ popupRef.current.lastFocus = evt.target;
129
+ }
130
+ };
131
+ const handleKeyDown = async (evt) => {
132
+ // if (evt.key === 'Enter' && !evt.altKey && !evt.shiftKey) {
133
+ // const textarea = evt.target as HTMLTextAreaElement;
134
+ // if (textarea.tagName === 'TEXTAREA' && !shouldSendOnEnter()) return;
135
+ // const input = evt.target as HTMLInputElement;
136
+ // if (input.tagName === 'INPUT' && input.type === 'text' && !shouldSendOnEnter()) return;
137
+ // evt.preventDefault();
138
+ // evt.stopPropagation();
139
+ // await handleComplete(options.defaultResult ?? POPUP_RESULT.AFFIRMATIVE);
140
+ // }
141
+ };
142
+ const getClassNames = () => {
143
+ const classes = ['popup'];
144
+ if (options.wide)
145
+ classes.push('wide_dialogue_popup');
146
+ if (options.wider)
147
+ classes.push('wider_dialogue_popup');
148
+ if (options.large)
149
+ classes.push('large_dialogue_popup');
150
+ if (options.transparent)
151
+ classes.push('transparent_dialogue_popup');
152
+ if (options.allowHorizontalScrolling)
153
+ classes.push('horizontal_scrolling_dialogue_popup');
154
+ if (options.allowVerticalScrolling)
155
+ classes.push('vertical_scrolling_dialogue_popup');
156
+ if (options.animation)
157
+ classes.push(`popup--animation-${options.animation}`);
158
+ return classes.join(' ');
159
+ };
160
+ return createPortal(_jsx("dialog", { ref: dialogRef, className: getClassNames(), "data-id": id.current, onKeyDown: handleKeyDown, onFocus: handleFocusIn, children: _jsxs("div", { className: "popup-body", children: [_jsx("div", { className: "popup-content", children: content }), type === POPUP_TYPE.INPUT && (_jsx("textarea", { ref: mainInputRef, className: "popup-input text_pole result-control auto-select", rows: options.rows ?? 1, defaultValue: inputValue, "data-result": "1", "data-result-event": "submit" })), options.customInputs && (_jsx("div", { className: "popup-inputs", children: options.customInputs.map((input) => (_jsxs("label", { className: "checkbox_label justifyCenter", htmlFor: input.id, children: [_jsx("input", { type: "checkbox", id: input.id, defaultChecked: input.defaultState }), _jsx("span", { "data-i18n": input.label, children: input.label }), input.tooltip && (_jsx("div", { className: "fa-solid fa-circle-info opacity50p", title: input.tooltip, "data-i18n": `[title]${input.tooltip}` }))] }, input.id))) })), type !== POPUP_TYPE.DISPLAY && (_jsxs("div", { className: "popup-controls", children: [options.customButtons?.map((button, index) => {
161
+ const buttonConfig = typeof button === 'string' ? { text: button, result: index + 2 } : button;
162
+ return (_jsx("div", { className: `menu_button popup-button-custom result-control ${buttonConfig.classes ?? ''}`, "data-result": buttonConfig.result, onClick: () => {
163
+ buttonConfig.action?.();
164
+ handleComplete(buttonConfig.result ?? index + 2);
165
+ }, "data-i18n": buttonConfig.text, children: buttonConfig.text }, index));
166
+ }), type !== POPUP_TYPE.DISPLAY && options.okButton !== false && (_jsx("div", { className: "popup-button-ok menu_button result-control", onClick: () => handleComplete(POPUP_RESULT.AFFIRMATIVE), "data-result": "1", children: typeof options.okButton === 'string' ? options.okButton : 'OK' })), type !== POPUP_TYPE.DISPLAY && options.cancelButton !== false && (_jsx("div", { className: "popup-button-cancel menu_button result-control", onClick: () => handleComplete(POPUP_RESULT.NEGATIVE), "data-result": "0", children: typeof options.cancelButton === 'string' ? options.cancelButton : 'Cancel' }))] })), type === POPUP_TYPE.DISPLAY && (_jsx("div", { className: "popup-button-close right_menu_button fa-solid fa-circle-xmark", onClick: () => handleComplete(POPUP_RESULT.CANCELLED), "data-result": "0", title: "Close popup", "data-i18n": "[title]Close popup" }))] }) }), document.body);
167
+ };
168
+ //# sourceMappingURL=Popup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popup.js","sourceRoot":"","sources":["../../src/components/Popup.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAgB,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,eAAe,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAUhH,MAAM,aAAa,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC;AAE/C,MAAM,CAAC,MAAM,KAAK,GAAyB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;IAC1G,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAsB,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAC;IACrE,MAAM,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAE1C,oEAAoE;IACpE,MAAM,QAAQ,GAAG,MAAM,CAAC;QACtB,EAAE,EAAE,EAAE,CAAC,OAAO;QACd,IAAI;QACJ,GAAG,EAAE,IAAgC;QACrC,SAAS,EAAE,IAAkC;QAC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,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,iBACxC,GAAG,YAEd,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,GACvE,CACP,IACG,CACP,EAEA,IAAI,KAAK,UAAU,CAAC,OAAO,IAAI,CAC9B,cACE,SAAS,EAAC,+DAA+D,EACzE,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,YAAY,CAAC,SAAS,CAAC,iBACzC,GAAG,EACf,KAAK,EAAC,aAAa,eACT,oBAAoB,GAC9B,CACH,IACG,GACC,EACT,QAAQ,CAAC,IAAI,CACd,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { FC, ButtonHTMLAttributes } from 'react';
2
+ export interface STButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
3
+ /**
4
+ * Custom class name(s) to append to the default SillyTavern classes.
5
+ * This can include utility classes or icon classes (e.g., 'fa-solid fa-plus').
6
+ * If `overrideDefaults` is true, this class name will replace the default classes.
7
+ */
8
+ className?: string;
9
+ /**
10
+ * If set to true, the default SillyTavern classes ('menu_button', 'interactable') will NOT be applied.
11
+ * This allows for complete control over the button's classes via the `className` prop.
12
+ * @default false
13
+ */
14
+ overrideDefaults?: boolean;
15
+ }
16
+ /**
17
+ * A common button component styled for SillyTavern.
18
+ * It applies 'menu_button interactable' classes by default.
19
+ * The original MyFancyButton component has been replaced with this.
20
+ * For clarity, you may want to rename the file from `MyFancyButton.tsx` to `STButton.tsx`.
21
+ */
22
+ export declare const STButton: FC<STButtonProps>;
23
+ //# sourceMappingURL=STButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STButton.d.ts","sourceRoot":"","sources":["../../src/components/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,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useMemo } from 'react';
3
+ /**
4
+ * A common button component styled for SillyTavern.
5
+ * It applies 'menu_button interactable' classes by default.
6
+ * The original MyFancyButton component has been replaced with this.
7
+ * For clarity, you may want to rename the file from `MyFancyButton.tsx` to `STButton.tsx`.
8
+ */
9
+ export const STButton = ({ children, className, overrideDefaults = false, ...props }) => {
10
+ const finalClassName = useMemo(() => {
11
+ const classes = [];
12
+ if (!overrideDefaults) {
13
+ classes.push('menu_button', 'interactable');
14
+ }
15
+ classes.push(className);
16
+ return classes.filter(Boolean).join(' ');
17
+ }, [overrideDefaults, className]);
18
+ return (_jsx("button", { className: finalClassName, ...props, children: children }));
19
+ };
20
+ //# sourceMappingURL=STButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STButton.js","sourceRoot":"","sources":["../../src/components/STButton.tsx"],"names":[],"mappings":";AAAA,OAAO,EAA4B,OAAO,EAAE,MAAM,OAAO,CAAC;AAkB1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAsB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACzG,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,EAAE;QAClC,MAAM,OAAO,GAA2B,EAAE,CAAC;QAE3C,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC,CAAC;IAElC,OAAO,CACL,iBAAQ,SAAS,EAAE,cAAc,KAAM,KAAK,YACzC,QAAQ,GACF,CACV,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { FC } from 'react';
2
+ import { IFuseOptions } from 'fuse.js';
3
+ export interface DropdownItem {
4
+ value: string;
5
+ label: string;
6
+ }
7
+ export interface STFancyDropdownProps {
8
+ /** The list of available items for the dropdown. */
9
+ items: DropdownItem[];
10
+ /** The currently selected value or values. */
11
+ value: string[];
12
+ /** Callback fired when the selection changes. */
13
+ onChange: (newValues: string[]) => void;
14
+ placeholder?: string;
15
+ closeOnSelect?: boolean;
16
+ multiple?: boolean;
17
+ disabled?: boolean;
18
+ /** Optional callback to control selection changes. Return false to prevent selection. */
19
+ onBeforeSelection?: (currentValues: string[], proposedValues: string[]) => Promise<boolean> | boolean;
20
+ enableSearch?: boolean;
21
+ searchPlaceholder?: string;
22
+ searchNoResultsText?: string;
23
+ searchFuseOptions?: IFuseOptions<DropdownItem>;
24
+ }
25
+ /**
26
+ * A controlled component that provides a multi-select dropdown with fuzzy search capabilities.
27
+ * This is the React version of the original `buildFancyDropdown` utility.
28
+ */
29
+ export declare const STFancyDropdown: FC<STFancyDropdownProps>;
30
+ export declare const FancyDropdownItem: FC<{
31
+ item: DropdownItem;
32
+ isSelected: boolean;
33
+ onClick: (value: string) => void;
34
+ }>;
35
+ //# sourceMappingURL=STFancyDropdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"STFancyDropdown.d.ts","sourceRoot":"","sources":["../../src/components/STFancyDropdown.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,EAAE,EAAwC,MAAM,OAAO,CAAC;A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