@nelsonlongxiang/dsh-prompt-templates 0.4.4 → 0.13.2

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 (50) hide show
  1. package/README.md +113 -62
  2. package/README_zh.md +112 -62
  3. package/cordis.patch.yml +4 -0
  4. package/lib/cli/app.js +169 -0
  5. package/lib/cli/database.js +162 -0
  6. package/lib/cli/main.js +6 -0
  7. package/lib/cli/model.js +247 -0
  8. package/lib/client/Library.js +290 -0
  9. package/lib/client/Panel.js +37 -201
  10. package/lib/client/PanelButton.js +27 -3
  11. package/lib/client/PromptTab.js +11 -0
  12. package/lib/client/api.js +16 -0
  13. package/lib/client/filter.js +27 -0
  14. package/lib/client/index.js +53 -36
  15. package/lib/client/locales.js +34 -2
  16. package/lib/client/meta.js +10 -0
  17. package/lib/client/service.js +57 -37
  18. package/lib/client/slots.js +5 -3
  19. package/lib/client/store.js +12 -1
  20. package/lib/client/tab.js +32 -0
  21. package/lib/client.js +798 -286
  22. package/lib/client.js.map +1 -1
  23. package/lib/index.js +35 -16
  24. package/lib/inject.js +236 -0
  25. package/lib/invariant.js +1 -1
  26. package/lib/store.js +108 -32
  27. package/lib/types/cli/app.d.ts +1 -0
  28. package/lib/types/cli/database.d.ts +69 -0
  29. package/lib/types/cli/main.d.ts +2 -0
  30. package/lib/types/cli/model.d.ts +62 -0
  31. package/lib/types/client/Library.d.ts +34 -0
  32. package/lib/types/client/Panel.d.ts +1 -1
  33. package/lib/types/client/PanelButton.d.ts +10 -9
  34. package/lib/types/client/PromptTab.d.ts +17 -0
  35. package/lib/types/client/api.d.ts +11 -1
  36. package/lib/types/client/filter.d.ts +10 -0
  37. package/lib/types/client/index.d.ts +6 -2
  38. package/lib/types/client/locales.d.ts +34 -2
  39. package/lib/types/client/meta.d.ts +6 -0
  40. package/lib/types/client/service.d.ts +50 -6
  41. package/lib/types/client/slots.d.ts +57 -5
  42. package/lib/types/client/store.d.ts +14 -1
  43. package/lib/types/client/tab.d.ts +31 -0
  44. package/lib/types/index.d.ts +8 -1
  45. package/lib/types/inject.d.ts +150 -0
  46. package/lib/types/store.d.ts +27 -4
  47. package/lib/types/types.d.ts +49 -0
  48. package/lib/types/variables.d.ts +24 -0
  49. package/lib/variables.js +36 -0
  50. package/package.json +98 -105
@@ -0,0 +1,290 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The template library: the search bar, category tabs, row list, inline
4
+ * forms, and footer shared by BOTH surfaces — the floating shell.overlay
5
+ * panel and the right-sidebar tab body. This component owns the list state
6
+ * (rows, categories, query, active tab, in-place edit) and loads on mount;
7
+ * each host surface decides placement around it. The delivery target is
8
+ * passed in as `sessionId` (the overlay reads it from its composer-entry
9
+ * attachment; the sidebar tab reads it straight from its standard props).
10
+ */
11
+ import { useCallback, useEffect, useRef, useState } from 'react';
12
+ import { IconEditOutlineRegular, IconGlobeOutlineRegular, IconPlusOutlineRegular, IconQueueOutlineRegular, IconSendOutlineRegular, IconTrashOutlineRegular } from '@deepseek-ai/dsh-client-ui-primitives';
13
+ import { filterTemplateRows, searchableTemplateRows } from "./filter.js";
14
+ import { GITHUB_REPOSITORY_URL, PLUGIN_VERSION, templateCountLabel } from "./meta.js";
15
+ import css from './Panel.module.css';
16
+ function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onMakeGlobal, onToggleInject, sortable, onDragStart, onDropOn, t }) {
17
+ const injectTitle = template.inject_enabled && template.inject_every !== null
18
+ ? `${t('panel.inject')} · ${template.inject_every}${template.mode === 'visible' ? ' · ' + t('panel.modeVisible') : ''}`
19
+ : t('panel.inject');
20
+ return (_jsxs("div", { className: css.row, "data-prompt-template": true, onMouseDown: (e) => { e.preventDefault(); }, draggable: sortable, onDragStart: () => { if (sortable)
21
+ onDragStart(template.id); }, onDragOver: (e) => { if (sortable)
22
+ e.preventDefault(); }, onDrop: (e) => { if (sortable) {
23
+ e.preventDefault();
24
+ e.stopPropagation();
25
+ onDropOn(template.id);
26
+ } }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template.content); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsxs("button", { type: "button", className: template.inject_enabled ? css.injectBtnActive : css.injectBtn, onClick: () => { onToggleInject(template); }, "aria-label": t('panel.inject'), "aria-pressed": template.inject_enabled, title: injectTitle, children: ["\u27F3", template.inject_enabled && template.inject_every !== null ? template.inject_every : ''] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template.content); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template.content); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutlineRegular, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutlineRegular, { size: 12 }) })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutlineRegular, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutlineRegular, { size: 12 }) })] }));
27
+ }
28
+ /** The template inline form: creation (with scope + category pickers) and in-place edit. */
29
+ function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
30
+ const [name, setName] = useState(initial?.name ?? '');
31
+ const [content, setContent] = useState(initial?.content ?? '');
32
+ // Edit seeds BOTH pickers with the row's stored facts, so opening a
33
+ // category tab's edit form pre-selects that category (and the matching
34
+ // scope) instead of resetting to 全局/无分类.
35
+ const [scope, setScope] = useState(initial?.scope ?? 'global');
36
+ const [category, setCategory] = useState(initial?.category ?? null);
37
+ // Auto-inject facts: the interval edits as text so a half-typed value never
38
+ // silently rounds; it is parsed (and rejected) on submit only.
39
+ const [injectOn, setInjectOn] = useState(initial?.injectEnabled ?? false);
40
+ const [injectEvery, setInjectEvery] = useState(initial?.injectEvery != null ? String(initial.injectEvery) : '5');
41
+ const [mode, setMode] = useState(initial?.mode ?? 'inject');
42
+ const [busy, setBusy] = useState(false);
43
+ const [error, setError] = useState(null);
44
+ const submit = useCallback(async () => {
45
+ const trimmedName = name.trim();
46
+ const trimmedContent = content.trim();
47
+ if (trimmedName === '' || trimmedContent === '')
48
+ return;
49
+ if (allowScope && scope === 'session' && sessionId === null) {
50
+ setError(t('panel.error'));
51
+ return;
52
+ }
53
+ let every = null;
54
+ if (injectOn) {
55
+ const parsed = Number(injectEvery);
56
+ if (!Number.isInteger(parsed) || parsed < 1) {
57
+ setError(t('panel.error'));
58
+ return;
59
+ }
60
+ every = parsed;
61
+ }
62
+ setBusy(true);
63
+ setError(null);
64
+ const ok = await onSubmit(trimmedName, trimmedContent, scope, category, injectOn, every, mode);
65
+ setBusy(false);
66
+ if (!ok) {
67
+ setError(t('panel.error'));
68
+ return;
69
+ }
70
+ onDone();
71
+ }, [name, content, scope, category, injectOn, injectEvery, mode, allowScope, sessionId, onSubmit, t, onDone]);
72
+ // Categories selectable for the CURRENT scope pick (matching partition).
73
+ const scopeCategories = categories.filter((cat) => cat.scope === scope && (cat.scope === 'global' || cat.session_id === sessionId));
74
+ return (_jsxs("div", { className: css.addForm, "data-prompt-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.addName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.addName') }), _jsx("textarea", { className: css.contentInput, placeholder: t('panel.addContent'), value: content, onChange: (e) => { setContent(e.target.value); }, rows: 3, "aria-label": t('panel.addContent') }), _jsx("div", { className: css.variablesHint, children: t('panel.variablesHint') }), _jsxs("div", { className: css.injectRow, children: [_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { type: "checkbox", checked: injectOn, onChange: (e) => { setInjectOn(e.target.checked); } }), t('panel.inject')] }), injectOn && (_jsxs("label", { className: css.injectLabel, children: [_jsx("input", { className: css.injectEveryInput, type: "number", min: 1, step: 1, value: injectEvery, onChange: (e) => { setInjectEvery(e.target.value); }, "aria-label": t('panel.injectEvery') }), t('panel.injectEvery')] })), injectOn && (_jsx("label", { className: css.injectLabel, title: t('panel.modeHint'), children: _jsxs("select", { value: mode, onChange: (e) => { setMode(e.target.value); }, "aria-label": t('panel.modeLabel'), children: [_jsx("option", { value: "inject", children: t('panel.modeInject') }), _jsx("option", { value: "visible", children: t('panel.modeVisible') })] }) }))] }), _jsxs("div", { className: css.addRow, children: [allowScope && (_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); setCategory(null); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) })), _jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: category ?? '', onChange: (e) => { setCategory(e.target.value === '' ? null : e.target.value); }, "aria-label": t('panel.category'), children: [_jsx("option", { value: "", children: t('panel.categoryNone') }), scopeCategories.map((cat) => _jsx("option", { value: cat.name, children: cat.name }, `${cat.scope}:${cat.name}`))] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), onCancel !== undefined && (_jsx("button", { type: "button", className: css.cancelBtn, onClick: onCancel, disabled: busy, children: t('panel.addCancel') })), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '' || content.trim() === '', children: submitLabel })] })] })] }));
75
+ }
76
+ /** Inline form creating one category tab: name + scope (global, or the current session). */
77
+ function CategoryForm({ sessionId, createCategory, t, onDone }) {
78
+ const [name, setName] = useState('');
79
+ const [scope, setScope] = useState('global');
80
+ const [busy, setBusy] = useState(false);
81
+ const [error, setError] = useState(null);
82
+ const submit = async () => {
83
+ const trimmed = name.trim();
84
+ if (trimmed === '')
85
+ return;
86
+ if (scope === 'session' && sessionId === null) {
87
+ setError(t('panel.error'));
88
+ return;
89
+ }
90
+ setBusy(true);
91
+ setError(null);
92
+ const result = await createCategory({
93
+ name: trimmed,
94
+ scope,
95
+ session_id: scope === 'session' ? sessionId : null,
96
+ });
97
+ setBusy(false);
98
+ if (!result.ok) {
99
+ setError(t('panel.error'));
100
+ return;
101
+ }
102
+ onDone();
103
+ };
104
+ return (_jsxs("div", { className: css.addForm, "data-prompt-category-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.categoryName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.categoryName') }), _jsxs("div", { className: css.addRow, children: [_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '', children: t('panel.addSave') })] })] })] }));
105
+ }
106
+ /**
107
+ * The shared template library: toolbar (title + row count), live search,
108
+ * category tabs, the row list with inline edit/create forms, and the
109
+ * footer. Loads everything on mount; the parent decides placement and
110
+ * lifetime (the overlay mounts it only while open, the sidebar tab mounts
111
+ * it for the tab's lifetime).
112
+ * @param props - target session, shared verbs, locale, optional title-row takeover.
113
+ */
114
+ export function TemplateLibrary({ sessionId, face, t, header, headerExtra }) {
115
+ const { refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory } = face;
116
+ const [templates, setTemplates] = useState([]);
117
+ const [categories, setCategories] = useState([]);
118
+ const [showAdd, setShowAdd] = useState(false);
119
+ // Live search filter over name + content, case-insensitive.
120
+ const [query, setQuery] = useState('');
121
+ // In-place editing: the id whose row swaps to the edit form, null = none.
122
+ const [editingId, setEditingId] = useState(null);
123
+ // Active tab: 'global' / 'session' (the implicit default tabs) or
124
+ // `cat:<scope>:<name>` for one user-created category tab.
125
+ const [activeTab, setActiveTab] = useState('global');
126
+ const [showCatForm, setShowCatForm] = useState(false);
127
+ // Row drag-sort: the id currently being dragged (HTML5 DnD).
128
+ const dragRowRef = useRef(null);
129
+ // Row-toggle failures surface above the list until the next good write.
130
+ const [rowError, setRowError] = useState(null);
131
+ const load = useCallback(async () => {
132
+ const items = await refresh();
133
+ setTemplates(items);
134
+ }, [refresh]);
135
+ const loadCategories = useCallback(async () => {
136
+ setCategories(await refreshCategories());
137
+ }, [refreshCategories]);
138
+ useEffect(() => {
139
+ void load();
140
+ void loadCategories();
141
+ }, [load, loadCategories]);
142
+ // Toolbar badge `⟳N`: the target session's latest scheduled injection,
143
+ // polled every 30s (and re-read whenever the target changes). null hides
144
+ // the badge — the route is memory-only, so polling stays O(1).
145
+ const [injected, setInjected] = useState(null);
146
+ const pollStatus = useCallback(async () => {
147
+ if (sessionId === null) {
148
+ setInjected(null);
149
+ return;
150
+ }
151
+ setInjected(await injectStatus(sessionId));
152
+ }, [injectStatus, sessionId]);
153
+ useEffect(() => {
154
+ void pollStatus();
155
+ const timer = setInterval(() => { void pollStatus(); }, 30_000);
156
+ return () => { clearInterval(timer); };
157
+ }, [pollStatus]);
158
+ // Badge dropdown: the recent-injection history for the target session,
159
+ // fetched on demand (on open, on target change, and whenever a new
160
+ // injection lands while open) so the 30s badge poll stays O(1).
161
+ const [historyOpen, setHistoryOpen] = useState(false);
162
+ const [history, setHistory] = useState([]);
163
+ const loadHistory = useCallback(async () => {
164
+ if (sessionId === null) {
165
+ setHistory([]);
166
+ return;
167
+ }
168
+ setHistory(await injectionHistory(sessionId));
169
+ }, [injectionHistory, sessionId]);
170
+ useEffect(() => {
171
+ if (historyOpen)
172
+ void loadHistory();
173
+ }, [historyOpen, loadHistory, injected]);
174
+ useEffect(() => { setHistoryOpen(false); }, [sessionId]);
175
+ const handleInsert = useCallback((content) => {
176
+ if (sessionId === null)
177
+ return;
178
+ insert(sessionId, content);
179
+ }, [insert, sessionId]);
180
+ const handleSend = useCallback((content) => {
181
+ if (sessionId === null)
182
+ return;
183
+ send(sessionId, content);
184
+ }, [send, sessionId]);
185
+ const handleInterject = useCallback((content) => {
186
+ if (sessionId === null)
187
+ return;
188
+ interject(sessionId, content);
189
+ }, [interject, sessionId]);
190
+ const handleRemove = useCallback(async (id) => {
191
+ const result = await remove(id);
192
+ if (result.ok)
193
+ void load();
194
+ }, [remove, load]);
195
+ const handleMakeGlobal = useCallback(async (id) => {
196
+ const result = await makeGlobal(id);
197
+ if (result.ok)
198
+ void load();
199
+ }, [makeGlobal, load]);
200
+ // Flip one row's auto-inject switch. First-time setup (no interval yet)
201
+ // routes into the edit form, where the interval gets typed and confirmed.
202
+ // A failed toggle surfaces the envelope error next to the list instead of
203
+ // failing silently — the switch only flips after a confirmed write.
204
+ const handleToggleInject = useCallback(async (template) => {
205
+ if (!template.inject_enabled && template.inject_every === null) {
206
+ setEditingId(template.id);
207
+ return;
208
+ }
209
+ const result = await update(template.id, { inject_enabled: !template.inject_enabled });
210
+ if (result.ok) {
211
+ setRowError(null);
212
+ void load();
213
+ }
214
+ else {
215
+ setRowError(result.error.message);
216
+ }
217
+ }, [update, load]);
218
+ // Visible user-category tabs: global ones always, session ones only for
219
+ // the current session.
220
+ const visibleCategories = categories.filter((cat) => cat.scope === 'global' || (cat.scope === 'session' && cat.session_id === sessionId));
221
+ const activeCategory = activeTab.startsWith('cat:')
222
+ ? visibleCategories.find((cat) => `cat:${cat.scope}:${cat.name}` === activeTab)
223
+ : undefined;
224
+ // A deleted (or no-longer-visible) category tab falls back to 全局.
225
+ const effectiveTab = activeTab.startsWith('cat:') && activeCategory === undefined ? 'global' : activeTab;
226
+ // With no query the active tab owns the list. A query searches across every
227
+ // category, but never leaks another session's private templates.
228
+ const needle = query.trim().toLowerCase();
229
+ const tabRows = filterTemplateRows(templates, query, effectiveTab, activeCategory, sessionId);
230
+ const searchableCount = searchableTemplateRows(templates, sessionId).length;
231
+ const countLabel = templateCountLabel(tabRows.length, searchableCount, needle !== '');
232
+ // Drop one dragged row onto another: reorder within the tab by writing the
233
+ // full position sequence back (idempotent and partition-local).
234
+ const handleRowDrop = (targetId) => {
235
+ const draggedId = dragRowRef.current;
236
+ dragRowRef.current = null;
237
+ if (draggedId === null || draggedId === targetId)
238
+ return;
239
+ const ids = tabRows.map((row) => row.id);
240
+ const from = ids.indexOf(draggedId);
241
+ const to = ids.indexOf(targetId);
242
+ if (from === -1 || to === -1)
243
+ return;
244
+ ids.splice(to, 0, ...ids.splice(from, 1));
245
+ void (async () => {
246
+ await Promise.all(ids.map((id, index) => update(id, { position: index })));
247
+ void load();
248
+ })();
249
+ };
250
+ /** One list row: the edit form while being edited, the rendered row otherwise. */
251
+ const renderTemplateRow = (row) => (editingId === row.id
252
+ ? (_jsx(TemplateForm, { initial: { name: row.name, content: row.content, scope: row.scope, category: row.category, injectEnabled: row.inject_enabled, injectEvery: row.inject_every, mode: row.mode }, allowScope: false, sessionId: sessionId, categories: visibleCategories, t: t, submitLabel: t('panel.addSave'), onSubmit: async (name, content, _scope, category, injectEnabled, injectEvery, mode) => {
253
+ // Disabling keeps the stored interval: only enabling sends a new one.
254
+ const result = await update(row.id, {
255
+ name,
256
+ content,
257
+ category,
258
+ inject_enabled: injectEnabled,
259
+ ...(injectEnabled ? { inject_every: injectEvery, mode } : {}),
260
+ });
261
+ return result.ok;
262
+ }, onDone: () => { setEditingId(null); void load(); }, onCancel: () => { setEditingId(null); } }, row.id))
263
+ : (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, onToggleInject: (tpl) => { void handleToggleInject(tpl); }, sortable: needle === '', onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
264
+ return (_jsxs("div", { className: css.library, "data-prompt-library": true, children: [_jsxs("div", { className: header !== undefined ? `${css.toolbar} ${css.toolbarDraggable}` : css.toolbar, title: header?.hint, onPointerDown: header?.onPointerDown, onPointerMove: header?.onPointerMove, onPointerUp: header?.onPointerUp, onDoubleClick: header?.onDoubleClick, children: [_jsxs("span", { className: css.titleGroup, children: [_jsx("span", { className: css.title, children: t('panel.title') }), _jsx("span", { className: css.countBadge, "data-template-count": true, title: needle !== '' ? t('panel.searchCount') : t('panel.tabCount'), children: countLabel }), injected !== null && (_jsxs("button", { type: "button", className: `${css.injectBadge} ${css.injectBadgeButton}`, "data-prompt-injected": true, title: `${t('panel.injectedAt')} ${injected.turn} · ${new Date(injected.at).toLocaleTimeString()} · ${injected.templates.join(', ')}`, "aria-label": t('panel.historyTitle'), "aria-expanded": historyOpen, onClick: () => { setHistoryOpen(open => !open); }, children: ["\u27F3", injected.turn] }))] }), headerExtra] }), historyOpen && (_jsxs("div", { className: css.injectHistory, "data-prompt-inject-history": true, role: "dialog", "aria-label": t('panel.historyTitle'), children: [_jsx("div", { className: css.injectHistoryTitle, children: t('panel.historyTitle') }), history.length === 0 && _jsx("div", { className: css.injectHistoryEmpty, children: t('panel.historyEmpty') }), history.map(entry => (_jsxs("div", { className: css.injectHistoryItem, children: [_jsxs("div", { className: css.injectHistoryHead, children: ["\u27F3", entry.turn, " \u00B7 ", new Date(entry.at).toLocaleTimeString(), " \u00B7 ", entry.templates.join(', ')] }), _jsx("div", { className: css.injectHistoryContent, children: entry.content })] }, `${entry.turn}-${entry.at}`)))] })), _jsx("div", { className: css.searchBar, children: _jsx("input", { type: "search", className: css.searchInput, value: query, onChange: (e) => { setQuery(e.target.value); }, placeholder: t('panel.search'), "aria-label": t('panel.search') }) }), _jsxs("div", { className: css.tabsBar, children: [_jsx("button", { type: "button", className: effectiveTab === 'global' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('global'); }, children: t('panel.global') }), _jsx("button", { type: "button", className: effectiveTab === 'session' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('session'); }, disabled: sessionId === null, children: t('panel.session') }), visibleCategories.map((cat) => {
265
+ const key = `cat:${cat.scope}:${cat.name}`;
266
+ return (_jsxs("span", { className: effectiveTab === key ? `${css.tab} ${css.tabActive}` : css.tab, children: [_jsx("button", { type: "button", onClick: () => { setActiveTab(key); }, children: cat.name }), _jsx("button", { type: "button", className: css.tabDelete, "aria-label": t('panel.deleteCategory'), title: t('panel.deleteCategory'), onClick: () => {
267
+ void (async () => {
268
+ const result = await removeCategory(cat.name, cat.scope, cat.session_id);
269
+ if (result.ok) {
270
+ if (effectiveTab === key)
271
+ setActiveTab('global');
272
+ void loadCategories();
273
+ void load();
274
+ }
275
+ })();
276
+ }, children: "\u00D7" })] }, key));
277
+ }), _jsx("button", { type: "button", className: css.tabAdd, "aria-label": t('panel.newCategory'), title: t('panel.newCategory'), onClick: () => { setShowCatForm(v => !v); }, children: _jsx(IconPlusOutlineRegular, { size: 10 }) })] }), showCatForm && (_jsx(CategoryForm, { sessionId: sessionId, createCategory: createCategory, t: t, onDone: () => { setShowCatForm(false); void loadCategories(); } })), _jsxs("div", { className: css.body, children: [rowError !== null && (_jsxs("div", { className: css.error, role: "alert", "data-prompt-row-error": true, children: [t('panel.error'), " \u00B7 ", rowError] })), tabRows.length === 0 && !showAdd && !showCatForm && (_jsx("div", { className: css.empty, children: needle !== '' ? t('panel.noMatch') : t('panel.empty') })), tabRows.length > 0 && (_jsx("div", { className: css.group, onDragOver: (e) => { e.preventDefault(); }, children: tabRows.map(row => renderTemplateRow(row)) })), showAdd && (_jsx(TemplateForm, { sessionId: sessionId, categories: visibleCategories, t: t, allowScope: true, submitLabel: t('panel.addSave'), onSubmit: async (name, content, scope, category, injectEnabled, injectEvery, mode) => {
278
+ const result = await create({
279
+ name,
280
+ content,
281
+ scope,
282
+ session_id: scope === 'session' ? sessionId : null,
283
+ category,
284
+ inject_enabled: injectEnabled,
285
+ inject_every: injectEvery,
286
+ mode,
287
+ });
288
+ return result.ok;
289
+ }, onDone: () => { setShowAdd(false); void load(); }, onCancel: () => { setShowAdd(false); } }))] }), _jsxs("div", { className: css.footer, children: [_jsxs("span", { className: css.meta, children: [_jsxs("span", { "data-plugin-version": true, children: ["v", PLUGIN_VERSION] }), _jsx("a", { className: css.githubLink, href: GITHUB_REPOSITORY_URL, target: "_blank", rel: "noopener noreferrer", title: t('panel.github'), children: "GitHub \u2197" })] }), _jsxs("button", { type: "button", className: css.addBtn, onClick: () => { setShowAdd(v => !v); }, children: [_jsx(IconPlusOutlineRegular, { size: 12 }), " ", t('panel.add')] })] })] }));
290
+ }
@@ -1,49 +1,15 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /**
3
3
  * Quick prompt panel: the right-anchored floating surface registered into
4
- * shell.overlay. Lists global templates plus the current session's private
5
- * ones; clicking a row inserts its content into the composer draft. The
6
- * injected face carries the CRUD verbs and insert; the panel store holds
7
- * visibility; the current session arrives through the standard kit.
4
+ * shell.overlay. The shell owns only placement (drag-by-title, persisted
5
+ * position) and visibility; the template library itself — search, tabs,
6
+ * rows, forms, footer — is the shared TemplateLibrary component, also
7
+ * mounted by the right-sidebar tab. The current session arrives through
8
+ * the composer entry attachment (targetSession), never the session list.
8
9
  */
9
- import { useCallback, useEffect, useRef, useState } from 'react';
10
- import { IconEditOutline16, IconGlobeOutline14, IconPlusOutline16, IconQueueOutline14, IconSendOutline16, IconTrashOutline16 } from '@deepseek-ai/dsh-client-ui-primitives';
10
+ import { useRef, useState, useSyncExternalStore } from 'react';
11
+ import { TemplateLibrary } from "./Library.js";
11
12
  import css from './Panel.module.css';
12
- function TemplateRow({ template, onInsert, onSend, onInterject, onEdit, onDelete, onMakeGlobal, onDragStart, onDropOn, t }) {
13
- return (_jsxs("div", { className: css.row, "data-prompt-template": true, onMouseDown: (e) => { e.preventDefault(); }, draggable: true, onDragStart: () => { onDragStart(template.id); }, onDragOver: (e) => { e.preventDefault(); }, onDrop: (e) => { e.preventDefault(); e.stopPropagation(); onDropOn(template.id); }, children: [_jsxs("button", { type: "button", className: css.insert, onClick: () => { onInsert(template.content); }, title: t('panel.insert'), children: [_jsx("span", { className: css.name, children: template.name }), _jsx("span", { className: css.preview, children: template.content })] }), _jsx("button", { type: "button", className: css.interjectBtn, onClick: () => { onInterject(template.content); }, "aria-label": t('panel.interject'), title: t('panel.interject'), children: _jsx(IconQueueOutline14, { size: 12 }) }), _jsx("button", { type: "button", className: css.sendBtn, onClick: () => { onSend(template.content); }, "aria-label": t('panel.sendNow'), title: t('panel.sendNow'), children: _jsx(IconSendOutline16, { size: 12 }) }), onMakeGlobal !== undefined && (_jsx("button", { type: "button", className: css.globalBtn, onClick: () => { onMakeGlobal(template.id); }, "aria-label": t('panel.makeGlobal'), title: t('panel.makeGlobal'), children: _jsx(IconGlobeOutline14, { size: 12 }) })), _jsx("button", { type: "button", className: css.editBtn, onClick: () => { onEdit(template.id); }, "aria-label": t('panel.edit'), title: t('panel.edit'), children: _jsx(IconEditOutline16, { size: 12 }) }), _jsx("button", { type: "button", className: css.deleteBtn, onClick: () => { onDelete(template.id); }, "aria-label": t('panel.delete'), children: _jsx(IconTrashOutline16, { size: 12 }) })] }));
14
- }
15
- /** The template inline form: creation (with scope + category pickers) and in-place edit. */
16
- function TemplateForm({ initial, allowScope, sessionId, categories, t, submitLabel, onSubmit, onDone, onCancel }) {
17
- const [name, setName] = useState(initial?.name ?? '');
18
- const [content, setContent] = useState(initial?.content ?? '');
19
- const [scope, setScope] = useState('global');
20
- const [category, setCategory] = useState(null);
21
- const [busy, setBusy] = useState(false);
22
- const [error, setError] = useState(null);
23
- const submit = useCallback(async () => {
24
- const trimmedName = name.trim();
25
- const trimmedContent = content.trim();
26
- if (trimmedName === '' || trimmedContent === '')
27
- return;
28
- if (allowScope && scope === 'session' && sessionId === null) {
29
- setError(t('panel.error'));
30
- return;
31
- }
32
- setBusy(true);
33
- setError(null);
34
- const ok = await onSubmit(trimmedName, trimmedContent, scope, category);
35
- setBusy(false);
36
- if (!ok) {
37
- setError(t('panel.error'));
38
- return;
39
- }
40
- onDone();
41
- }, [name, content, scope, category, allowScope, sessionId, onSubmit, t, onDone]);
42
- // Categories selectable for the CURRENT scope pick (matching partition).
43
- const scopeCategories = categories.filter((cat) => cat.scope === scope && (cat.scope === 'global' || cat.session_id === sessionId));
44
- return (_jsxs("div", { className: css.addForm, "data-prompt-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.addName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.addName') }), _jsx("textarea", { className: css.contentInput, placeholder: t('panel.addContent'), value: content, onChange: (e) => { setContent(e.target.value); }, rows: 3, "aria-label": t('panel.addContent') }), _jsxs("div", { className: css.addRow, children: [allowScope && (_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); setCategory(null); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) })), _jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: category ?? '', onChange: (e) => { setCategory(e.target.value === '' ? null : e.target.value); }, "aria-label": t('panel.category'), children: [_jsx("option", { value: "", children: t('panel.categoryNone') }), scopeCategories.map((cat) => _jsx("option", { value: cat.name, children: cat.name }, `${cat.scope}:${cat.name}`))] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), onCancel !== undefined && (_jsx("button", { type: "button", className: css.cancelBtn, onClick: onCancel, disabled: busy, children: t('panel.addCancel') })), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '' || content.trim() === '', children: submitLabel })] })] })] }));
45
- }
46
- /** Panel width used for viewport clamping (mirrors the CSS `.panel` width). */
47
13
  const PANEL_WIDTH = 320;
48
14
  /**
49
15
  * Clamp a restored panel position into the current viewport so a placement
@@ -63,26 +29,24 @@ function clampToViewport(position) {
63
29
  };
64
30
  }
65
31
  /**
66
- * The prompt-templates panel body.
32
+ * The prompt-templates floating panel shell.
67
33
  * @param props - runtime kit, injected face members, store handle, and locale.
68
34
  */
69
35
  export function PromptPanel(props) {
70
- const { useStore, useSessions, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, panelPosition, savePanelPosition, resetPanelPosition, actions, t, } = props;
36
+ const { useStore, refresh, refreshCategories, createCategory, removeCategory, create, update, remove, makeGlobal, insert, send, interject, injectStatus, injectionHistory, targetSession, targetVersion, subscribeTarget, panelPosition, savePanelPosition, resetPanelPosition, actions, t, } = props;
71
37
  const open = useStore(s => s.open);
72
- const currentSession = useSessions(s => s.current);
73
- const [templates, setTemplates] = useState([]);
74
- const [categories, setCategories] = useState([]);
75
- const [showAdd, setShowAdd] = useState(false);
76
- // Live search filter over name + content, case-insensitive.
77
- const [query, setQuery] = useState('');
78
- // In-place editing: the id whose row swaps to the edit form, null = none.
79
- const [editingId, setEditingId] = useState(null);
80
- // Active tab: 'global' / 'session' (the implicit default tabs) or
81
- // `cat:<scope>:<name>` for one user-created category tab.
82
- const [activeTab, setActiveTab] = useState('global');
83
- const [showCatForm, setShowCatForm] = useState(false);
84
- // Row drag-sort: the id currently being dragged (HTML5 DnD).
85
- const dragRowRef = useRef(null);
38
+ // Re-render whenever the delivery target changes: the composer entry
39
+ // attaches its session whenever its composer becomes the visible one, so
40
+ // switching conversations bumps the version and the open panel re-reads
41
+ // the target. Without this the panel's handlers keep the previous
42
+ // render's sessionId closure and sends after a switch land nowhere.
43
+ useSyncExternalStore(subscribeTarget, targetVersion);
44
+ // Delivery target: the composer entry attachment, never the session list.
45
+ // The 0.2.0 session list has no selection field (SessionListState.current
46
+ // is gone), so guessing ids[0] would target the newest list row — a
47
+ // foreign session on any busy host.
48
+ const currentSession = targetSession();
49
+ const sessionId = currentSession ?? null;
86
50
  // Drag placement: seeded from the persisted position, live-updated while
87
51
  // dragging, committed to the settings document on release. A null with no
88
52
  // drag in flight keeps the CSS right-anchored default. The restored value
@@ -92,46 +56,7 @@ export function PromptPanel(props) {
92
56
  const [dragPos, setDragPos] = useState(null);
93
57
  const dragRef = useRef(null);
94
58
  const panelRef = useRef(null);
95
- const sessionId = currentSession ?? null;
96
- const load = useCallback(async () => {
97
- const items = await refresh();
98
- setTemplates(items);
99
- }, [refresh]);
100
- const loadCategories = useCallback(async () => {
101
- setCategories(await refreshCategories());
102
- }, [refreshCategories]);
103
- useEffect(() => {
104
- if (open) {
105
- void load();
106
- void loadCategories();
107
- }
108
- }, [open, load, loadCategories]);
109
- const handleInsert = useCallback((content) => {
110
- if (sessionId === null)
111
- return;
112
- insert(sessionId, content);
113
- }, [insert, sessionId]);
114
- const handleSend = useCallback((content) => {
115
- if (sessionId === null)
116
- return;
117
- send(sessionId, content);
118
- }, [send, sessionId]);
119
- const handleInterject = useCallback((content) => {
120
- if (sessionId === null)
121
- return;
122
- interject(sessionId, content);
123
- }, [interject, sessionId]);
124
- const handleRemove = useCallback(async (id) => {
125
- const result = await remove(id);
126
- if (result.ok)
127
- void load();
128
- }, [remove, load]);
129
- const handleMakeGlobal = useCallback(async (id) => {
130
- const result = await makeGlobal(id);
131
- if (result.ok)
132
- void load();
133
- }, [makeGlobal, load]);
134
- // Drag-by-header: capture the pointer, track the offset, clamp so the
59
+ // Drag-by-title: capture the pointer, track the offset, clamp so the
135
60
  // header always stays reachable inside the viewport, commit on release.
136
61
  const onHeaderPointerDown = (event) => {
137
62
  if (event.button !== 0)
@@ -153,7 +78,7 @@ export function PromptPanel(props) {
153
78
  const drag = dragRef.current;
154
79
  if (drag === null || event.pointerId !== drag.pointerId)
155
80
  return;
156
- const width = panelRef.current?.getBoundingClientRect().width ?? 320;
81
+ const width = panelRef.current?.getBoundingClientRect().width ?? PANEL_WIDTH;
157
82
  const maxX = Math.max(0, window.innerWidth - width);
158
83
  const maxY = Math.max(0, window.innerHeight - 40);
159
84
  const x = Math.min(Math.max(event.clientX - drag.offX, 0), maxX);
@@ -171,62 +96,13 @@ export function PromptPanel(props) {
171
96
  if (dragPos !== null)
172
97
  savePanelPosition(dragPos);
173
98
  };
174
- // Double-click the header to forget the placement and re-anchor right.
99
+ // Double-click the title to forget the placement and re-anchor right.
175
100
  const onHeaderDoubleClick = () => {
176
101
  setDragPos(null);
177
102
  resetPanelPosition();
178
103
  };
179
104
  if (!open)
180
105
  return null;
181
- // The full set is loaded; filtering happens here. The search query
182
- // narrows by name + content, case-insensitive.
183
- const needle = query.trim().toLowerCase();
184
- const matches = (row) => needle === ''
185
- || row.name.toLowerCase().includes(needle)
186
- || row.content.toLowerCase().includes(needle);
187
- // Visible user-category tabs: global ones always, session ones only for
188
- // the current session.
189
- const visibleCategories = categories.filter((cat) => cat.scope === 'global' || (cat.scope === 'session' && cat.session_id === sessionId));
190
- const activeCategory = activeTab.startsWith('cat:')
191
- ? visibleCategories.find((cat) => `cat:${cat.scope}:${cat.name}` === activeTab)
192
- : undefined;
193
- // A deleted (or no-longer-visible) category tab falls back to 全局.
194
- const effectiveTab = activeTab.startsWith('cat:') && activeCategory === undefined ? 'global' : activeTab;
195
- // The active tab decides the visible partition; rows sort by position.
196
- const tabRows = templates.filter((row) => {
197
- if (!matches(row))
198
- return false;
199
- if (effectiveTab === 'global')
200
- return row.scope === 'global' && row.category === null;
201
- if (effectiveTab === 'session')
202
- return row.scope === 'session' && row.session_id === sessionId && row.category === null;
203
- return activeCategory !== undefined
204
- && row.category === activeCategory.name
205
- && row.scope === activeCategory.scope
206
- && (activeCategory.scope === 'global' || row.session_id === sessionId);
207
- });
208
- // Drop one dragged row onto another: reorder within the tab by writing the
209
- // full position sequence back (idempotent and partition-local).
210
- const handleRowDrop = (targetId) => {
211
- const draggedId = dragRowRef.current;
212
- dragRowRef.current = null;
213
- if (draggedId === null || draggedId === targetId)
214
- return;
215
- const ids = tabRows.map((row) => row.id);
216
- const from = ids.indexOf(draggedId);
217
- const to = ids.indexOf(targetId);
218
- if (from === -1 || to === -1)
219
- return;
220
- ids.splice(to, 0, ...ids.splice(from, 1));
221
- void (async () => {
222
- await Promise.all(ids.map((id, index) => update(id, { position: index })));
223
- void load();
224
- })();
225
- };
226
- /** One list row: the edit form while being edited, the rendered row otherwise. */
227
- const renderTemplateRow = (row) => (editingId === row.id
228
- ? (_jsx(TemplateForm, { initial: { name: row.name, content: row.content }, allowScope: false, sessionId: sessionId, categories: visibleCategories, t: t, submitLabel: t('panel.addSave'), onSubmit: async (name, content, _scope, category) => (await update(row.id, { name, content, category: row.scope === 'global' ? category : category })).ok, onDone: () => { setEditingId(null); void load(); }, onCancel: () => { setEditingId(null); } }, row.id))
229
- : (_jsx(TemplateRow, { template: row, onInsert: (c) => { handleInsert(c); }, onSend: (c) => { handleSend(c); }, onInterject: (c) => { handleInterject(c); }, onEdit: (id) => { setEditingId(id); }, onDelete: (id) => { void handleRemove(id); }, onMakeGlobal: row.scope === 'session' ? (id) => { void handleMakeGlobal(id); } : undefined, onDragStart: (id) => { dragRowRef.current = id; }, onDropOn: (id) => { handleRowDrop(id); }, t: t }, row.id)));
230
106
  const placement = dragPos ?? persisted;
231
107
  // With bottom:auto the fixed panel's height is content-driven, so a long
232
108
  // list would stretch past the viewport with no internal scroll. Cap the
@@ -241,57 +117,17 @@ export function PromptPanel(props) {
241
117
  bottom: 'auto',
242
118
  maxHeight: `calc(100vh - ${placement.y}px - 16px)`,
243
119
  };
244
- return (_jsxs("div", { className: css.panel, "data-prompt-panel": true, ref: panelRef, style: placementStyle, children: [_jsxs("div", { className: css.header, title: t('panel.dragHint'), onPointerDown: onHeaderPointerDown, onPointerMove: onHeaderPointerMove, onPointerUp: onHeaderPointerUp, onDoubleClick: onHeaderDoubleClick, children: [_jsx("span", { className: css.title, children: t('panel.title') }), _jsx("button", { type: "button", className: css.closeBtn, onClick: () => { actions.close(); }, "aria-label": t('panel.close'), children: "\u00D7" })] }), _jsx("div", { className: css.searchBar, children: _jsx("input", { type: "search", className: css.searchInput, value: query, onChange: (e) => { setQuery(e.target.value); }, placeholder: t('panel.search'), "aria-label": t('panel.search') }) }), _jsxs("div", { className: css.tabsBar, children: [_jsx("button", { type: "button", className: effectiveTab === 'global' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('global'); }, children: t('panel.global') }), _jsx("button", { type: "button", className: effectiveTab === 'session' ? `${css.tab} ${css.tabActive}` : css.tab, onClick: () => { setActiveTab('session'); }, disabled: sessionId === null, children: t('panel.session') }), visibleCategories.map((cat) => {
245
- const key = `cat:${cat.scope}:${cat.name}`;
246
- return (_jsxs("span", { className: effectiveTab === key ? `${css.tab} ${css.tabActive}` : css.tab, children: [_jsx("button", { type: "button", onClick: () => { setActiveTab(key); }, children: cat.name }), _jsx("button", { type: "button", className: css.tabDelete, "aria-label": t('panel.deleteCategory'), title: t('panel.deleteCategory'), onClick: () => {
247
- void (async () => {
248
- const result = await removeCategory(cat.name, cat.scope, cat.session_id);
249
- if (result.ok) {
250
- if (effectiveTab === key)
251
- setActiveTab('global');
252
- void loadCategories();
253
- void load();
254
- }
255
- })();
256
- }, children: "\u00D7" })] }, key));
257
- }), _jsx("button", { type: "button", className: css.tabAdd, "aria-label": t('panel.newCategory'), title: t('panel.newCategory'), onClick: () => { setShowCatForm(v => !v); }, children: _jsx(IconPlusOutline16, { size: 10 }) })] }), showCatForm && (_jsx(CategoryForm, { sessionId: sessionId, createCategory: createCategory, t: t, onDone: () => { setShowCatForm(false); void loadCategories(); } })), _jsxs("div", { className: css.body, children: [tabRows.length === 0 && !showAdd && !showCatForm && (_jsx("div", { className: css.empty, children: needle !== '' ? t('panel.noMatch') : t('panel.empty') })), tabRows.length > 0 && (_jsx("div", { className: css.group, onDragOver: (e) => { e.preventDefault(); }, children: tabRows.map(row => renderTemplateRow(row)) })), showAdd && (_jsx(TemplateForm, { sessionId: sessionId, categories: visibleCategories, t: t, allowScope: true, submitLabel: t('panel.addSave'), onSubmit: async (name, content, scope, category) => {
258
- const result = await create({
259
- name,
260
- content,
261
- scope,
262
- session_id: scope === 'session' ? sessionId : null,
263
- category,
264
- });
265
- return result.ok;
266
- }, onDone: () => { setShowAdd(false); void load(); }, onCancel: () => { setShowAdd(false); } }))] }), _jsx("div", { className: css.footer, children: _jsxs("button", { type: "button", className: css.addBtn, onClick: () => { setShowAdd(v => !v); }, children: [_jsx(IconPlusOutline16, { size: 12 }), " ", t('panel.add')] }) })] }));
267
- }
268
- /** Inline form creating one category tab: name + scope (global, or the current session). */
269
- function CategoryForm({ sessionId, createCategory, t, onDone }) {
270
- const [name, setName] = useState('');
271
- const [scope, setScope] = useState('global');
272
- const [busy, setBusy] = useState(false);
273
- const [error, setError] = useState(null);
274
- const submit = async () => {
275
- const trimmed = name.trim();
276
- if (trimmed === '')
277
- return;
278
- if (scope === 'session' && sessionId === null) {
279
- setError(t('panel.error'));
280
- return;
281
- }
282
- setBusy(true);
283
- setError(null);
284
- const result = await createCategory({
285
- name: trimmed,
286
- scope,
287
- session_id: scope === 'session' ? sessionId : null,
288
- });
289
- setBusy(false);
290
- if (!result.ok) {
291
- setError(t('panel.error'));
292
- return;
293
- }
294
- onDone();
120
+ // The library verbs are the face minus the overlay-only placement knobs.
121
+ const libraryFace = {
122
+ refresh, refreshCategories, createCategory, removeCategory,
123
+ create, update, remove, makeGlobal,
124
+ insert, send, interject, injectStatus, injectionHistory,
295
125
  };
296
- return (_jsxs("div", { className: css.addForm, "data-prompt-category-add": true, children: [_jsx("input", { className: css.nameInput, type: "text", placeholder: t('panel.categoryName'), value: name, onChange: (e) => { setName(e.target.value); }, "aria-label": t('panel.categoryName') }), _jsxs("div", { className: css.addRow, children: [_jsx("label", { className: css.scopeLabel, children: _jsxs("select", { value: scope, onChange: (e) => { setScope(e.target.value); }, "aria-label": "scope", children: [_jsx("option", { value: "global", children: t('panel.global') }), _jsx("option", { value: "session", disabled: sessionId === null, children: t('panel.session') })] }) }), _jsxs("div", { className: css.addActions, children: [error !== null && _jsx("span", { className: css.error, role: "alert", children: error }), _jsx("button", { type: "button", className: css.saveBtn, onClick: () => void submit(), disabled: busy || name.trim() === '', children: t('panel.addSave') })] })] })] }));
126
+ return (_jsx("div", { className: css.panel, "data-prompt-panel": true, ref: panelRef, style: placementStyle, children: _jsx(TemplateLibrary, { sessionId: sessionId, face: libraryFace, t: t, header: {
127
+ onPointerDown: onHeaderPointerDown,
128
+ onPointerMove: onHeaderPointerMove,
129
+ onPointerUp: onHeaderPointerUp,
130
+ onDoubleClick: onHeaderDoubleClick,
131
+ hint: t('panel.dragHint'),
132
+ }, headerExtra: (_jsx("button", { type: "button", className: css.closeBtn, onClick: () => { actions.close(); }, "aria-label": t('panel.close'), children: "\u00D7" })) }) }));
297
133
  }