@clagentic/console 1.6.0-beta.1 → 1.6.0-beta.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.
- package/README.md +18 -0
- package/lib/daemon.js +94 -0
- package/lib/project-sessions.js +26 -0
- package/lib/public/css/base.css +18 -0
- package/lib/public/css/diagnostics.css +8 -0
- package/lib/public/css/icon-strip.css +201 -0
- package/lib/public/css/menus.css +2 -2
- package/lib/public/css/mobile-nav.css +24 -0
- package/lib/public/css/server-settings.css +100 -0
- package/lib/public/index.html +13 -0
- package/lib/public/modules/app-header.js +4 -7
- package/lib/public/modules/app-home-hub.js +31 -7
- package/lib/public/modules/app-messages.js +5 -0
- package/lib/public/modules/app-notifications.js +5 -1
- package/lib/public/modules/app-projects.js +10 -5
- package/lib/public/modules/command-palette.js +16 -5
- package/lib/public/modules/custom-icons-settings.js +399 -0
- package/lib/public/modules/custom-icons.js +114 -0
- package/lib/public/modules/diagnostics.js +10 -0
- package/lib/public/modules/emoji-picker.js +253 -6
- package/lib/public/modules/popover-position.js +192 -0
- package/lib/public/modules/project-icon.js +113 -0
- package/lib/public/modules/project-settings.js +2 -2
- package/lib/public/modules/project-switcher.js +2 -1
- package/lib/public/modules/scheduler-config.js +5 -8
- package/lib/public/modules/scheduler.js +5 -6
- package/lib/public/modules/server-settings.js +6 -0
- package/lib/public/modules/sidebar-mobile.js +4 -6
- package/lib/public/modules/sidebar-projects.js +35 -90
- package/lib/public/modules/sidebar-sessions.js +6 -20
- package/lib/public/modules/sticky-notes.js +4 -4
- package/lib/public/modules/terminal.js +5 -12
- package/lib/server-settings.js +221 -1
- package/lib/server.js +2 -0
- package/lib/sessions.js +16 -9
- package/lib/ws-schema.js +2 -0
- package/package.json +2 -1
|
@@ -24,6 +24,7 @@ import { handleFsList, handleFsRead, handleFileChanged, handleDirChanged, handle
|
|
|
24
24
|
import { getPendingNavigate, peekPendingNavigate } from './pending-navigate.js';
|
|
25
25
|
import { isProjectSettingsOpen, refreshProjectSettingsModels, handleInstructionsRead, handleInstructionsWrite, handleProjectEnv, handleProjectEnvSaved, handleProjectSharedEnv, handleProjectSharedEnvSaved, handleProjectOwnerChanged, updateLiteVisibility, handleLiteProjectStatus, handleLiteEnrollResult, handleLiteUnenrollResult } from './project-settings.js';
|
|
26
26
|
import { updateSettingsModels, updateSettingsStats, updateDaemonConfig, handleSetPinResult, handleKeepAwakeChanged, handleAutoContinueChanged, handleRefreshAgentsResult, handleRestartResult, handleShutdownResult, handleSharedEnv, handleSharedEnvSaved, handleGlobalClaudeMdRead, handleGlobalClaudeMdWrite, updateSsLiteVisibility } from './server-settings.js';
|
|
27
|
+
import { handleRenameCustomIconResult } from './custom-icons-settings.js';
|
|
27
28
|
import { handleTermList, handleTermCreated, sendTerminalCommand, handleTermOutput, handleTermResized, handleTermExited, handleTermClosed } from './terminal.js';
|
|
28
29
|
import { updateTerminalList, handleContextSourcesState } from './context-sources.js';
|
|
29
30
|
import { handleNotesList, handleNoteCreated, handleNoteUpdated, handleNoteDeleted } from './sticky-notes.js';
|
|
@@ -1219,6 +1220,10 @@ export function processMessage(msg) {
|
|
|
1219
1220
|
updateProjectList(msg);
|
|
1220
1221
|
break;
|
|
1221
1222
|
|
|
1223
|
+
case "rename_custom_icon_result":
|
|
1224
|
+
handleRenameCustomIconResult(msg);
|
|
1225
|
+
break;
|
|
1226
|
+
|
|
1222
1227
|
case "project_owner_changed":
|
|
1223
1228
|
store.set({ currentProjectOwnerId: msg.ownerId });
|
|
1224
1229
|
handleProjectOwnerChanged(msg);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { refreshIcons, iconHtml } from './icons.js';
|
|
6
6
|
import { escapeHtml } from './utils.js';
|
|
7
|
+
import { projectIconHtml } from './project-icon.js';
|
|
7
8
|
import { store } from './store.js';
|
|
8
9
|
import { getWs } from './ws-ref.js';
|
|
9
10
|
import { getCachedProjects } from './app-projects.js';
|
|
@@ -101,7 +102,10 @@ function showBanner(notif, autoDismissMs) {
|
|
|
101
102
|
: isAuthRequired
|
|
102
103
|
? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic:Console" style="border-radius:8px">'
|
|
103
104
|
: projectIcon
|
|
104
|
-
|
|
105
|
+
// projectIconHtml() routes custom (:slug:) icons to a safe <img> tag and
|
|
106
|
+
// emoji to escaped text — the raw `projectIcon` interpolation previously
|
|
107
|
+
// showed ':slug:' as literal text (lr-a6da).
|
|
108
|
+
? '<span class="notif-banner-emoji">' + projectIconHtml(projectIcon) + '</span>'
|
|
105
109
|
: isEmpty
|
|
106
110
|
? '<img src="/icon-banded-76.png" width="32" height="32" alt="Clagentic:Console" style="border-radius:8px">'
|
|
107
111
|
: iconHtml("folder");
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { escapeHtml, showToast } from './utils.js';
|
|
5
5
|
import { refreshIcons } from './icons.js';
|
|
6
6
|
import { parseEmojis } from './markdown.js';
|
|
7
|
+
import { renderProjectIcon } from './project-icon.js';
|
|
7
8
|
import { store } from './store.js';
|
|
8
9
|
import { getWs, setWs } from './ws-ref.js';
|
|
9
10
|
import { getMessagesEl, getStatusDot } from './dom-refs.js';
|
|
@@ -344,8 +345,7 @@ export function renderProjectList() {
|
|
|
344
345
|
if (tbIcon) {
|
|
345
346
|
var pIcon = cachedProjects[pi].icon || null;
|
|
346
347
|
if (pIcon) {
|
|
347
|
-
tbIcon
|
|
348
|
-
parseEmojis(tbIcon);
|
|
348
|
+
renderProjectIcon(pIcon, tbIcon, parseEmojis);
|
|
349
349
|
tbIcon.classList.add("has-icon");
|
|
350
350
|
try { localStorage.setItem("clagentic-project-icon-" + (st.currentSlug || "default"), pIcon); } catch (e) {}
|
|
351
351
|
} else {
|
|
@@ -360,8 +360,7 @@ export function renderProjectList() {
|
|
|
360
360
|
var indName = cachedProjects[pi].title || cachedProjects[pi].project || "";
|
|
361
361
|
var indIcon = cachedProjects[pi].icon || null;
|
|
362
362
|
if (indIcon) {
|
|
363
|
-
inputIndicator
|
|
364
|
-
parseEmojis(inputIndicator);
|
|
363
|
+
renderProjectIcon(indIcon, inputIndicator, parseEmojis);
|
|
365
364
|
inputIndicator.removeAttribute("data-abbrev");
|
|
366
365
|
} else {
|
|
367
366
|
// Abbreviation fallback — first two initials
|
|
@@ -739,7 +738,13 @@ function renderRemovedProjectsList() {
|
|
|
739
738
|
});
|
|
740
739
|
var iconEl = document.createElement("span");
|
|
741
740
|
iconEl.className = "add-project-removed-icon";
|
|
742
|
-
|
|
741
|
+
if (rp.icon) {
|
|
742
|
+
// renderProjectIcon() routes custom (:slug:) icons to <img>; the prior
|
|
743
|
+
// textContent assignment showed ':slug:' as literal text (lr-a6da).
|
|
744
|
+
renderProjectIcon(rp.icon, iconEl, parseEmojis);
|
|
745
|
+
} else {
|
|
746
|
+
iconEl.textContent = "\uD83D\uDCC1";
|
|
747
|
+
}
|
|
743
748
|
item.appendChild(iconEl);
|
|
744
749
|
var info = document.createElement("div");
|
|
745
750
|
info.className = "add-project-removed-info";
|
|
@@ -3,6 +3,7 @@ import { escapeHtml } from './utils.js';
|
|
|
3
3
|
import { refreshIcons } from './icons.js';
|
|
4
4
|
import { openSearch as openSessionSearch } from './session-search.js';
|
|
5
5
|
import { pushOverlayState, popOverlayState } from './overlay-history.js';
|
|
6
|
+
import { projectIconHtml } from './project-icon.js';
|
|
6
7
|
|
|
7
8
|
function formatRelativeDate(ts) {
|
|
8
9
|
if (!ts) return "";
|
|
@@ -259,8 +260,11 @@ function renderHome(filter) {
|
|
|
259
260
|
for (var r = 0; r < recentSessions.length; r++) {
|
|
260
261
|
var s = recentSessions[r];
|
|
261
262
|
items.push({ type: "session", data: s });
|
|
262
|
-
|
|
263
|
-
|
|
263
|
+
// projectIconHtml() routes custom (:slug:) icons to a safe <img> tag and
|
|
264
|
+
// emoji to escaped text — the prior raw s.projectIcon interpolation
|
|
265
|
+
// showed ':slug:' as literal text (lr-a6da).
|
|
266
|
+
var iconHtml = projectIconHtml(s.projectIcon, '<i data-lucide="message-square"></i>');
|
|
267
|
+
var projLabel = projectIconHtml(s.projectIcon) + " " + escapeHtml(s.projectTitle || s.projectSlug);
|
|
264
268
|
html += renderItem(flatIndex, iconHtml, escapeHtml(s.sessionTitle || "New Session"), projLabel.trim(), null, s.lastActivity);
|
|
265
269
|
flatIndex++;
|
|
266
270
|
}
|
|
@@ -319,7 +323,11 @@ function renderHome(filter) {
|
|
|
319
323
|
items.push({ type: "project", data: proj });
|
|
320
324
|
var pName = escapeHtml(proj.title || proj.project || proj.slug);
|
|
321
325
|
var sessLabel = proj.sessions ? proj.sessions + " sessions" : "";
|
|
322
|
-
|
|
326
|
+
// projectIconHtml() routes custom (:slug:) icons to a safe <img> tag;
|
|
327
|
+
// the prior raw proj.icon interpolation (via refreshIcons(), which only
|
|
328
|
+
// converts <i data-lucide> placeholders) showed ':slug:' as literal
|
|
329
|
+
// text (lr-a6da).
|
|
330
|
+
html += renderItem(flatIndex, projectIconHtml(proj.icon, '<i data-lucide="box"></i>'), pName, sessLabel, null);
|
|
323
331
|
flatIndex++;
|
|
324
332
|
}
|
|
325
333
|
}
|
|
@@ -382,8 +390,11 @@ function appendHomeSearchResults(results, query) {
|
|
|
382
390
|
for (var i = 0; i < newResults.length; i++) {
|
|
383
391
|
var r = newResults[i];
|
|
384
392
|
items.push({ type: "search-result", data: r, query: query });
|
|
385
|
-
|
|
386
|
-
|
|
393
|
+
// projectIconHtml() routes custom (:slug:) icons to a safe <img> tag and
|
|
394
|
+
// emoji to escaped text — the prior raw r.projectIcon interpolation
|
|
395
|
+
// showed ':slug:' as literal text (lr-a6da).
|
|
396
|
+
var srIconHtml = projectIconHtml(r.projectIcon, '<i data-lucide="message-square"></i>');
|
|
397
|
+
var projLabel = projectIconHtml(r.projectIcon) + " " + escapeHtml(r.projectTitle || r.projectSlug);
|
|
387
398
|
var snippet = r.snippet ? escapeHtml(r.snippet) : "";
|
|
388
399
|
html += renderItem(flatIndex, srIconHtml, escapeHtml(r.sessionTitle || "New Session"), projLabel.trim(), snippet, r.lastActivity);
|
|
389
400
|
flatIndex++;
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
// custom-icons-settings.js — Server Settings > Custom Icons management surface (lr-d1d9).
|
|
2
|
+
//
|
|
3
|
+
// Global-scope list/upload/rename/delete UI for the shared custom-icon
|
|
4
|
+
// namespace (lr-a68f). Reuses the shared upload/list/delete helpers from
|
|
5
|
+
// custom-icons.js (also used by emoji-picker.js) so the two surfaces never
|
|
6
|
+
// diverge, and renders thumbnails via renderProjectIcon() (DOM API, not
|
|
7
|
+
// innerHTML) for XSS parity with every other custom-icon render site.
|
|
8
|
+
//
|
|
9
|
+
// Usage ("Used by N") is computed entirely client-side from the already-cached
|
|
10
|
+
// project list + folder metadata — no server usage route exists or is needed.
|
|
11
|
+
//
|
|
12
|
+
// Rename is a daemon WS op (rename_custom_icon), not a bare HTTP route: file
|
|
13
|
+
// rename + config reference rewrite + projects_updated broadcast must be one
|
|
14
|
+
// atomic operation (see lib/daemon.js onRenameCustomIcon).
|
|
15
|
+
|
|
16
|
+
import { escapeHtml } from './utils.js';
|
|
17
|
+
import { refreshIcons, iconHtml } from './icons.js';
|
|
18
|
+
import { renderProjectIcon } from './project-icon.js';
|
|
19
|
+
import { fetchCustomIconList, uploadCustomIcon, deleteCustomIcon, slugifyFilename, matchesCustomIconQuery } from './custom-icons.js';
|
|
20
|
+
import { getCachedProjects, getCachedFolderMeta } from './app-projects.js';
|
|
21
|
+
|
|
22
|
+
var ctx = null;
|
|
23
|
+
var containerEl = null;
|
|
24
|
+
var cachedList = [];
|
|
25
|
+
var pendingRenameSlug = null; // slug currently being renamed inline, or null
|
|
26
|
+
var filterQuery = ""; // lr-0847: current text in #custom-icons-filter-input
|
|
27
|
+
|
|
28
|
+
export function initCustomIconsSettings(appCtx) {
|
|
29
|
+
ctx = appCtx;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Compute usage references for every custom-icon slug from the already-cached
|
|
34
|
+
* project list and folder metadata (client-side only — no server round trip).
|
|
35
|
+
*
|
|
36
|
+
* @returns {Object<string, {projects: string[], folders: string[]}>} keyed by slug
|
|
37
|
+
*/
|
|
38
|
+
function computeUsage() {
|
|
39
|
+
var usage = {};
|
|
40
|
+
function ensure(slug) {
|
|
41
|
+
if (!usage[slug]) usage[slug] = { projects: [], folders: [] };
|
|
42
|
+
return usage[slug];
|
|
43
|
+
}
|
|
44
|
+
function slugOf(iconStr) {
|
|
45
|
+
if (!iconStr || typeof iconStr !== "string") return null;
|
|
46
|
+
var m = /^:([a-z0-9_-]{1,64}):$/.exec(iconStr);
|
|
47
|
+
return m ? m[1] : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var projects = getCachedProjects() || [];
|
|
51
|
+
for (var i = 0; i < projects.length; i++) {
|
|
52
|
+
var slug = slugOf(projects[i].icon);
|
|
53
|
+
if (slug) ensure(slug).projects.push(projects[i].title || projects[i].project || projects[i].slug);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var folderMeta = getCachedFolderMeta() || {};
|
|
57
|
+
var folderNames = Object.keys(folderMeta);
|
|
58
|
+
for (var j = 0; j < folderNames.length; j++) {
|
|
59
|
+
var fSlug = slugOf(folderMeta[folderNames[j]] && folderMeta[folderNames[j]].icon);
|
|
60
|
+
if (fSlug) ensure(fSlug).folders.push(folderNames[j]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return usage;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function usageCount(usage, slug) {
|
|
67
|
+
var u = usage[slug];
|
|
68
|
+
if (!u) return 0;
|
|
69
|
+
return u.projects.length + u.folders.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function usageLabel(usage, slug) {
|
|
73
|
+
var u = usage[slug];
|
|
74
|
+
if (!u || (u.projects.length === 0 && u.folders.length === 0)) return null;
|
|
75
|
+
var names = u.projects.concat(u.folders.map(function (f) { return f + " (folder)"; }));
|
|
76
|
+
return names.join(", ");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Load (or reload) the custom icons list and render it into the settings section.
|
|
81
|
+
*/
|
|
82
|
+
export function loadCustomIcons() {
|
|
83
|
+
var body = document.getElementById("custom-icons-list");
|
|
84
|
+
if (!body) return;
|
|
85
|
+
body.innerHTML = '<div class="admin-loading">Loading...</div>';
|
|
86
|
+
fetchCustomIconList().then(function (list) {
|
|
87
|
+
cachedList = list;
|
|
88
|
+
renderList();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatSize(bytes) {
|
|
93
|
+
if (typeof bytes !== "number") return "";
|
|
94
|
+
if (bytes >= 1048576) return (bytes / 1048576).toFixed(1) + " MB";
|
|
95
|
+
if (bytes >= 1024) return (bytes / 1024).toFixed(1) + " KB";
|
|
96
|
+
return bytes + " B";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function renderList() {
|
|
100
|
+
var body = document.getElementById("custom-icons-list");
|
|
101
|
+
if (!body) return;
|
|
102
|
+
containerEl = body;
|
|
103
|
+
var usage = computeUsage();
|
|
104
|
+
|
|
105
|
+
body.innerHTML = "";
|
|
106
|
+
|
|
107
|
+
if (cachedList.length === 0) {
|
|
108
|
+
var empty = document.createElement("div");
|
|
109
|
+
empty.className = "settings-hint";
|
|
110
|
+
empty.textContent = "No custom icons uploaded yet.";
|
|
111
|
+
body.appendChild(empty);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// lr-0847: filter by hyphen/underscore-segment match (shared with the
|
|
116
|
+
// emoji-picker Custom tab search via matchesCustomIconQuery) so this list
|
|
117
|
+
// and the picker never drift on tokenization the way upload error
|
|
118
|
+
// handling drifted between the two surfaces.
|
|
119
|
+
var visible = [];
|
|
120
|
+
for (var fi = 0; fi < cachedList.length; fi++) {
|
|
121
|
+
if (matchesCustomIconQuery(cachedList[fi].slug, filterQuery)) visible.push(cachedList[fi]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (visible.length === 0) {
|
|
125
|
+
var noMatch = document.createElement("div");
|
|
126
|
+
noMatch.className = "settings-hint";
|
|
127
|
+
noMatch.textContent = "No custom icons match \"" + filterQuery + "\".";
|
|
128
|
+
body.appendChild(noMatch);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var list = document.createElement("div");
|
|
133
|
+
list.className = "custom-icons-list";
|
|
134
|
+
|
|
135
|
+
for (var i = 0; i < visible.length; i++) {
|
|
136
|
+
list.appendChild(buildRow(visible[i], usage));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
body.appendChild(list);
|
|
140
|
+
refreshIcons(body);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function buildRow(entry, usage) {
|
|
144
|
+
var row = document.createElement("div");
|
|
145
|
+
row.className = "custom-icons-row";
|
|
146
|
+
row.dataset.slug = entry.slug;
|
|
147
|
+
|
|
148
|
+
// Thumbnail — rendered via renderProjectIcon (DOM <img>, not innerHTML).
|
|
149
|
+
var thumbWrap = document.createElement("span");
|
|
150
|
+
thumbWrap.className = "custom-icons-thumb";
|
|
151
|
+
// Cache-bust: the server serves custom-emoji bytes with an immutable
|
|
152
|
+
// Cache-Control header (server-settings.js), so a browser that already
|
|
153
|
+
// cached the old bytes for this slug (e.g. after an overwrite-upload) would
|
|
154
|
+
// otherwise keep showing stale pixels here. The query param busts that
|
|
155
|
+
// cache without touching the immutable-cache header itself.
|
|
156
|
+
renderProjectIcon(":" + entry.slug + ":", thumbWrap, null);
|
|
157
|
+
var img = thumbWrap.querySelector("img");
|
|
158
|
+
if (img) img.src = img.src + "?v=" + (entry.size || 0);
|
|
159
|
+
row.appendChild(thumbWrap);
|
|
160
|
+
|
|
161
|
+
// Meta: slug, size/type, usage badge
|
|
162
|
+
var meta = document.createElement("div");
|
|
163
|
+
meta.className = "custom-icons-meta";
|
|
164
|
+
|
|
165
|
+
var slugEl = document.createElement("div");
|
|
166
|
+
slugEl.className = "custom-icons-slug";
|
|
167
|
+
slugEl.textContent = ":" + entry.slug + ":";
|
|
168
|
+
meta.appendChild(slugEl);
|
|
169
|
+
|
|
170
|
+
var detailEl = document.createElement("div");
|
|
171
|
+
detailEl.className = "custom-icons-detail settings-hint";
|
|
172
|
+
var detailParts = [];
|
|
173
|
+
if (entry.ext) detailParts.push(entry.ext.toUpperCase());
|
|
174
|
+
if (typeof entry.size === "number") detailParts.push(formatSize(entry.size));
|
|
175
|
+
var count = usageCount(usage, entry.slug);
|
|
176
|
+
var label = usageLabel(usage, entry.slug);
|
|
177
|
+
detailParts.push("Used by " + count);
|
|
178
|
+
detailEl.textContent = detailParts.join(" · ");
|
|
179
|
+
if (label) detailEl.title = label;
|
|
180
|
+
meta.appendChild(detailEl);
|
|
181
|
+
|
|
182
|
+
row.appendChild(meta);
|
|
183
|
+
|
|
184
|
+
// Actions
|
|
185
|
+
var actions = document.createElement("div");
|
|
186
|
+
actions.className = "custom-icons-actions";
|
|
187
|
+
|
|
188
|
+
var renameBtn = document.createElement("button");
|
|
189
|
+
renameBtn.className = "settings-btn-sm";
|
|
190
|
+
renameBtn.innerHTML = iconHtml("pencil");
|
|
191
|
+
renameBtn.title = "Rename";
|
|
192
|
+
renameBtn.addEventListener("click", function () { startRename(entry.slug, row, usage); });
|
|
193
|
+
actions.appendChild(renameBtn);
|
|
194
|
+
|
|
195
|
+
var deleteBtn = document.createElement("button");
|
|
196
|
+
deleteBtn.className = "settings-btn-sm settings-btn-danger";
|
|
197
|
+
deleteBtn.innerHTML = iconHtml("trash-2");
|
|
198
|
+
deleteBtn.title = "Delete";
|
|
199
|
+
deleteBtn.addEventListener("click", function () { confirmDelete(entry.slug, usage); });
|
|
200
|
+
actions.appendChild(deleteBtn);
|
|
201
|
+
|
|
202
|
+
row.appendChild(actions);
|
|
203
|
+
return row;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function startRename(oldSlug, row, usage) {
|
|
207
|
+
if (pendingRenameSlug) return; // one inline rename at a time
|
|
208
|
+
pendingRenameSlug = oldSlug;
|
|
209
|
+
|
|
210
|
+
var slugEl = row.querySelector(".custom-icons-slug");
|
|
211
|
+
if (!slugEl) return;
|
|
212
|
+
var originalText = slugEl.textContent;
|
|
213
|
+
|
|
214
|
+
var form = document.createElement("div");
|
|
215
|
+
form.className = "custom-icons-rename-form";
|
|
216
|
+
var input = document.createElement("input");
|
|
217
|
+
input.type = "text";
|
|
218
|
+
input.maxLength = 64;
|
|
219
|
+
input.spellcheck = false;
|
|
220
|
+
input.autocomplete = "off";
|
|
221
|
+
input.value = oldSlug;
|
|
222
|
+
input.className = "custom-icons-rename-input";
|
|
223
|
+
var okBtn = document.createElement("button");
|
|
224
|
+
okBtn.className = "settings-btn-sm primary";
|
|
225
|
+
okBtn.textContent = "Save";
|
|
226
|
+
var cancelBtn = document.createElement("button");
|
|
227
|
+
cancelBtn.className = "settings-btn-sm settings-btn-ghost";
|
|
228
|
+
cancelBtn.textContent = "Cancel";
|
|
229
|
+
var errorEl = document.createElement("div");
|
|
230
|
+
errorEl.className = "settings-hint custom-icons-rename-error hidden";
|
|
231
|
+
|
|
232
|
+
form.appendChild(input);
|
|
233
|
+
form.appendChild(okBtn);
|
|
234
|
+
form.appendChild(cancelBtn);
|
|
235
|
+
|
|
236
|
+
slugEl.replaceWith(form);
|
|
237
|
+
row.appendChild(errorEl);
|
|
238
|
+
input.focus();
|
|
239
|
+
input.select();
|
|
240
|
+
|
|
241
|
+
function endRename() {
|
|
242
|
+
pendingRenameSlug = null;
|
|
243
|
+
form.replaceWith(slugEl);
|
|
244
|
+
slugEl.textContent = originalText;
|
|
245
|
+
errorEl.remove();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function submitRename() {
|
|
249
|
+
var newSlug = input.value.trim().toLowerCase()
|
|
250
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
251
|
+
.replace(/^-+|-+$/g, "")
|
|
252
|
+
.slice(0, 64);
|
|
253
|
+
if (!newSlug || !/^[a-z0-9_-]{1,64}$/.test(newSlug)) {
|
|
254
|
+
errorEl.textContent = "Invalid slug — use lowercase letters, numbers, dashes, underscores.";
|
|
255
|
+
errorEl.classList.remove("hidden");
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (newSlug === oldSlug) { endRename(); return; }
|
|
259
|
+
|
|
260
|
+
var label = usageLabel(usage, oldSlug);
|
|
261
|
+
var count = usageCount(usage, oldSlug);
|
|
262
|
+
if (count > 0) {
|
|
263
|
+
var proceed = window.confirm(
|
|
264
|
+
":" + oldSlug + ": is used by " + count + " item" + (count === 1 ? "" : "s") +
|
|
265
|
+
(label ? " (" + label + ")" : "") +
|
|
266
|
+
". Renaming will update all references to :" + newSlug + ":. Continue?"
|
|
267
|
+
);
|
|
268
|
+
if (!proceed) return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
okBtn.disabled = true;
|
|
272
|
+
sendRename(oldSlug, newSlug).then(function (result) {
|
|
273
|
+
okBtn.disabled = false;
|
|
274
|
+
if (!result.ok) {
|
|
275
|
+
errorEl.textContent = result.error || "Rename failed";
|
|
276
|
+
errorEl.classList.remove("hidden");
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
pendingRenameSlug = null;
|
|
280
|
+
loadCustomIcons();
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
okBtn.addEventListener("click", function (e) { e.stopPropagation(); submitRename(); });
|
|
285
|
+
cancelBtn.addEventListener("click", function (e) { e.stopPropagation(); endRename(); });
|
|
286
|
+
input.addEventListener("keydown", function (e) {
|
|
287
|
+
e.stopPropagation();
|
|
288
|
+
if (e.key === "Enter") { e.preventDefault(); submitRename(); }
|
|
289
|
+
if (e.key === "Escape") { e.preventDefault(); endRename(); }
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// In-flight rename WS round-trip, keyed so a stray late reply can't resolve
|
|
294
|
+
// a newer request's promise.
|
|
295
|
+
var _pendingRenameResolvers = {};
|
|
296
|
+
var _renameReqSeq = 0;
|
|
297
|
+
|
|
298
|
+
function sendRename(oldSlug, newSlug) {
|
|
299
|
+
return new Promise(function (resolve) {
|
|
300
|
+
var ws = ctx && ctx.ws;
|
|
301
|
+
if (!ws || ws.readyState !== 1) {
|
|
302
|
+
resolve({ ok: false, error: "Not connected" });
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
var reqId = ++_renameReqSeq;
|
|
306
|
+
_pendingRenameResolvers[reqId] = resolve;
|
|
307
|
+
ws.send(JSON.stringify({ type: "rename_custom_icon", oldSlug: oldSlug, newSlug: newSlug, _reqId: reqId }));
|
|
308
|
+
// Safety timeout — don't leave the UI spinner stuck if the daemon never replies.
|
|
309
|
+
setTimeout(function () {
|
|
310
|
+
if (_pendingRenameResolvers[reqId]) {
|
|
311
|
+
delete _pendingRenameResolvers[reqId];
|
|
312
|
+
resolve({ ok: false, error: "Rename timed out" });
|
|
313
|
+
}
|
|
314
|
+
}, 10000);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Handle the rename_custom_icon_result WS message (wired from app-messages.js).
|
|
320
|
+
*/
|
|
321
|
+
export function handleRenameCustomIconResult(msg) {
|
|
322
|
+
var reqId = msg._reqId;
|
|
323
|
+
if (reqId && _pendingRenameResolvers[reqId]) {
|
|
324
|
+
var resolve = _pendingRenameResolvers[reqId];
|
|
325
|
+
delete _pendingRenameResolvers[reqId];
|
|
326
|
+
resolve(msg);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
// No matching in-flight request (e.g. reload happened) — still refresh the
|
|
330
|
+
// list so the UI doesn't show stale data if the rename succeeded elsewhere.
|
|
331
|
+
if (msg.ok) loadCustomIcons();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function confirmDelete(slug, usage) {
|
|
335
|
+
var count = usageCount(usage, slug);
|
|
336
|
+
var label = usageLabel(usage, slug);
|
|
337
|
+
var message = "Delete :" + slug + ":?";
|
|
338
|
+
if (count > 0) {
|
|
339
|
+
message += " It is used by " + count + " item" + (count === 1 ? "" : "s") +
|
|
340
|
+
(label ? " (" + label + ")" : "") +
|
|
341
|
+
". Those references will show a fallback icon after deletion — this cannot be undone.";
|
|
342
|
+
}
|
|
343
|
+
if (!window.confirm(message)) return;
|
|
344
|
+
deleteCustomIcon(slug).then(function () { loadCustomIcons(); });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// --- Upload ---
|
|
348
|
+
|
|
349
|
+
function handleUploadFile(file) {
|
|
350
|
+
if (!file) return;
|
|
351
|
+
var suggested = slugifyFilename(file.name);
|
|
352
|
+
var slug = window.prompt("Slug for this icon (letters, numbers, dashes, underscores):", suggested);
|
|
353
|
+
if (slug === null) return; // cancelled
|
|
354
|
+
slug = slug.trim().toLowerCase()
|
|
355
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
356
|
+
.replace(/^-+|-+$/g, "")
|
|
357
|
+
.slice(0, 64);
|
|
358
|
+
if (!slug || !/^[a-z0-9_-]{1,64}$/.test(slug)) {
|
|
359
|
+
window.alert("Invalid slug.");
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
var hasDup = cachedList.some(function (e) { return e.slug === slug; });
|
|
363
|
+
if (hasDup && !window.confirm(":" + slug + ": already exists — overwrite?")) return;
|
|
364
|
+
|
|
365
|
+
uploadCustomIcon(slug, file).then(function (result) {
|
|
366
|
+
if (!result.ok) {
|
|
367
|
+
window.alert(result.error || "Upload failed");
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
loadCustomIcons();
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Wire the Upload button + hidden file input, and the slug filter box
|
|
376
|
+
* (lr-0847). Called once from server-settings.js's initServerSettings
|
|
377
|
+
* (idempotent — safe if elements are absent, e.g. in tests without the full
|
|
378
|
+
* DOM).
|
|
379
|
+
*/
|
|
380
|
+
export function initCustomIconsUpload() {
|
|
381
|
+
var uploadBtn = document.getElementById("custom-icons-upload-btn");
|
|
382
|
+
var fileInput = document.getElementById("custom-icons-file-input");
|
|
383
|
+
if (uploadBtn && fileInput) {
|
|
384
|
+
uploadBtn.addEventListener("click", function () { fileInput.click(); });
|
|
385
|
+
fileInput.addEventListener("change", function () {
|
|
386
|
+
var file = fileInput.files && fileInput.files[0];
|
|
387
|
+
fileInput.value = "";
|
|
388
|
+
handleUploadFile(file);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
var filterInput = document.getElementById("custom-icons-filter-input");
|
|
393
|
+
if (filterInput) {
|
|
394
|
+
filterInput.addEventListener("input", function () {
|
|
395
|
+
filterQuery = filterInput.value;
|
|
396
|
+
renderList();
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// custom-icons.js — Shared client-side helper for the global custom-icon
|
|
2
|
+
// namespace (lr-a68f). Extracted from emoji-picker.js (lr-d1d9) so the emoji
|
|
3
|
+
// picker's "Custom" panel and the Server Settings > Custom Icons management
|
|
4
|
+
// surface share one implementation of slugify/list-fetch/upload/delete
|
|
5
|
+
// instead of maintaining two copies that can drift.
|
|
6
|
+
//
|
|
7
|
+
// DOM-free: safe to import from both browser modules and Node test files.
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Derive a slug candidate from an uploaded filename: strip extension,
|
|
11
|
+
* lowercase, collapse anything outside [a-z0-9_-] into a single dash,
|
|
12
|
+
* trim leading/trailing dashes, cap at 64 chars. Falls back to "custom"
|
|
13
|
+
* if the result would be empty (e.g. an all-symbol filename).
|
|
14
|
+
*
|
|
15
|
+
* Mirrors the server's SLUG_RE (^[a-z0-9_-]{1,64}$) — the caller must still
|
|
16
|
+
* validate the final (possibly user-edited) slug against that pattern
|
|
17
|
+
* before uploading, since this is only a best-effort starting suggestion.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} filename
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
export function slugifyFilename(filename) {
|
|
23
|
+
var base = String(filename || "").replace(/\.[^.]+$/, "").toLowerCase()
|
|
24
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
25
|
+
.replace(/^-+|-+$/g, "")
|
|
26
|
+
.slice(0, 64);
|
|
27
|
+
return base || "custom";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Fetch the full list of custom-icon uploads.
|
|
32
|
+
* Resolves to [] on any network/parse error rather than rejecting, so
|
|
33
|
+
* callers can render an empty state without a try/catch at every call site.
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<Array<{slug: string, url: string, size?: number, ext?: string}>>}
|
|
36
|
+
*/
|
|
37
|
+
export function fetchCustomIconList() {
|
|
38
|
+
return fetch("/api/custom-emoji")
|
|
39
|
+
.then(function (r) { return r.json(); })
|
|
40
|
+
.then(function (data) { return Array.isArray(data) ? data : []; })
|
|
41
|
+
.catch(function () { return []; });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Upload a File/Blob as a new (or replacement) custom icon under the given
|
|
46
|
+
* slug. Caller is responsible for slug validation/confirmation UX (e.g. the
|
|
47
|
+
* duplicate-overwrite confirm dialog in emoji-picker.js) before calling this.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} slug
|
|
50
|
+
* @param {File|Blob} file
|
|
51
|
+
* @returns {Promise<{ok: boolean, slug?: string, url?: string, error?: string}>}
|
|
52
|
+
*/
|
|
53
|
+
export function uploadCustomIcon(slug, file) {
|
|
54
|
+
return new Promise(function (resolve) {
|
|
55
|
+
var reader = new FileReader();
|
|
56
|
+
reader.onload = function (ev) {
|
|
57
|
+
fetch("/api/custom-emoji/" + encodeURIComponent(slug), {
|
|
58
|
+
method: "POST",
|
|
59
|
+
body: ev.target.result,
|
|
60
|
+
}).then(function (r) {
|
|
61
|
+
if (!r.ok) {
|
|
62
|
+
return r.json().catch(function () { return {}; }).then(function (body) {
|
|
63
|
+
resolve({ ok: false, error: (body && body.error) || "Upload failed" });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return r.json().then(function (body) { resolve(Object.assign({ ok: true }, body)); });
|
|
67
|
+
}).catch(function () {
|
|
68
|
+
resolve({ ok: false, error: "Upload failed" });
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
reader.onerror = function () { resolve({ ok: false, error: "Failed to read file" }); };
|
|
72
|
+
reader.readAsArrayBuffer(file);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Delete a custom icon by slug.
|
|
78
|
+
* @param {string} slug
|
|
79
|
+
* @returns {Promise<{ok: boolean}>}
|
|
80
|
+
*/
|
|
81
|
+
export function deleteCustomIcon(slug) {
|
|
82
|
+
return fetch("/api/custom-emoji/" + encodeURIComponent(slug), { method: "DELETE" })
|
|
83
|
+
.then(function () { return { ok: true }; })
|
|
84
|
+
.catch(function () { return { ok: false }; });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Test whether a custom-icon slug matches a search query (lr-0847).
|
|
89
|
+
*
|
|
90
|
+
* Matches if the query is a substring of the whole slug OR a substring of
|
|
91
|
+
* any hyphen/underscore-delimited segment. Whole-slug substring match alone
|
|
92
|
+
* already covers segment prefixes (e.g. "clage" -> "clagentic-console"),
|
|
93
|
+
* but NOT a later segment on its own (e.g. "console" was previously unable
|
|
94
|
+
* to match "clagentic-console" since custom icons had no search wiring at
|
|
95
|
+
* all — this is the shared match rule for both the emoji-picker Custom tab
|
|
96
|
+
* search and the Server Settings > Custom Icons list filter, so the two
|
|
97
|
+
* surfaces can't drift on tokenization the way they drifted on upload
|
|
98
|
+
* error handling).
|
|
99
|
+
*
|
|
100
|
+
* @param {string} slug
|
|
101
|
+
* @param {string} query
|
|
102
|
+
* @returns {boolean}
|
|
103
|
+
*/
|
|
104
|
+
export function matchesCustomIconQuery(slug, query) {
|
|
105
|
+
var q = String(query || "").toLowerCase().trim();
|
|
106
|
+
if (!q) return true;
|
|
107
|
+
var s = String(slug || "").toLowerCase();
|
|
108
|
+
if (s.indexOf(q) !== -1) return true;
|
|
109
|
+
var segments = s.split(/[-_]+/);
|
|
110
|
+
for (var i = 0; i < segments.length; i++) {
|
|
111
|
+
if (segments[i].indexOf(q) !== -1) return true;
|
|
112
|
+
}
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
@@ -69,6 +69,16 @@ export function initDiagnostics() {
|
|
|
69
69
|
closePanelAndRefocus();
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
// Click-outside dismiss: the panel is a non-modal surface (no backdrop
|
|
74
|
+
// element), so listen on the document and close when a click lands
|
|
75
|
+
// outside the panel and outside its topbar toggle button (lr-b580).
|
|
76
|
+
document.addEventListener("click", function (e) {
|
|
77
|
+
if (panelEl.classList.contains("hidden")) return;
|
|
78
|
+
if (panelEl.contains(e.target)) return;
|
|
79
|
+
if (panelToggleBtn && panelToggleBtn.contains(e.target)) return;
|
|
80
|
+
closePanelAndRefocus();
|
|
81
|
+
});
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
// ============================================================
|