@aiti-ai/aiti-msg-share 0.1.8 → 0.1.11
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 +2 -3
- package/client/src/index.js +274 -12
- package/dist/aiti-msg-share-client.mjs +445 -15
- package/docs/README.zh-CN.md +2 -2
- package/icon.svg +1 -1
- package/index.ts +100 -6
- package/lib/provider-icons.mjs +63 -0
- package/package.json +12 -3
- package/test/provider-icons.test.mjs +47 -0
- package/test/share-core.test.mjs +14 -0
package/README.md
CHANGED
|
@@ -6,10 +6,9 @@ English · [简体中文](./docs/README.zh-CN.md)
|
|
|
6
6
|
|
|
7
7
|
## About aiti
|
|
8
8
|
|
|
9
|
-
This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/
|
|
9
|
+
This package is part of the **aiti** ecosystem — a personal AI development workbench powered by [pi](https://pi.dev): **aiti-agent** (a self-hosted web workbench built on the open-source [pi-web](https://github.com/aiti-ai/aiti-ai)) plus debug injection into mainstream dev tools (aiti-devtools) and a rich extension system.
|
|
10
10
|
|
|
11
|
-
- Workbench
|
|
12
|
-
- Ecosystem monorepo: <https://github.com/aiti-ai/aiti-ai>
|
|
11
|
+
- Workbench & monorepo: <https://github.com/aiti-ai/aiti-ai>
|
|
13
12
|
- Site: <https://aiti.pw>
|
|
14
13
|
|
|
15
14
|
Category: Content & sharing · Tags: `share` · `session` · `message` · `qrcode` · `redaction` · `sxcu` · `gitee` · `oss` · `joplin`
|
package/client/src/index.js
CHANGED
|
@@ -30,6 +30,18 @@ function contentKind() {
|
|
|
30
30
|
return "text";
|
|
31
31
|
}
|
|
32
32
|
function supportsKind(t, kind) { return !(t.kinds || []).length || (t.kinds || []).includes(kind); }
|
|
33
|
+
/** Mirror of the engine's {{title}} fallback: first meaningful line of the raw
|
|
34
|
+
* text (skips the page-info stamp block and markdown decoration) — prefills the
|
|
35
|
+
* title input so the user sees and can edit what will be sent. */
|
|
36
|
+
function deriveTitleLocal(text) {
|
|
37
|
+
for (const raw of String(text || "").split("\n")) {
|
|
38
|
+
const line = raw.trim();
|
|
39
|
+
if (!line || /^>\s*\*\*[^*]+\*\*\s*:/.test(line)) continue;
|
|
40
|
+
const stripped = line.replace(/^#{1,6}\s+/, "").replace(/[*_`]+/g, "").trim();
|
|
41
|
+
if (stripped) return stripped.length > 80 ? stripped.slice(0, 80).trim() : stripped;
|
|
42
|
+
}
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
33
45
|
function shareT(key, params) {
|
|
34
46
|
if (!tFn) return key;
|
|
35
47
|
try {
|
|
@@ -51,6 +63,12 @@ const state = {
|
|
|
51
63
|
targetId: null, meta: {}, redact: true, redactHits: [],
|
|
52
64
|
result: null, busy: false, error: "", errorDetail: "", errorCode: "", errorTarget: "", errorProvider: "", search: "", probe: [],
|
|
53
65
|
editing: null, form: {},
|
|
66
|
+
/** Container picker (notebook/folder selection): per-target cache + pending pick.
|
|
67
|
+
* containersByTarget[id] = { containers: [{id,label,parent,path}], label } */
|
|
68
|
+
containersByTarget: {}, containerFor: "", containerOpen: false, containerFilter: "",
|
|
69
|
+
containerExpanded: {}, containersLoading: false, containerError: "",
|
|
70
|
+
/** Keyboard navigation index over the currently visible picker rows (-1 = none). */
|
|
71
|
+
kbIndex: -1,
|
|
54
72
|
/** Local favourite sinks (share-sink topic): { ok, message, action } of the last run. */
|
|
55
73
|
sinkResult: null, sinkBusy: "",
|
|
56
74
|
};
|
|
@@ -109,10 +127,78 @@ function set(partial) { Object.assign(state, partial); emit(); }
|
|
|
109
127
|
/** Pick a target for the pending share and return to the share dialog. */
|
|
110
128
|
function chooseTarget(id) {
|
|
111
129
|
recentAdd(id);
|
|
112
|
-
set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "" });
|
|
130
|
+
set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "", containerOpen: false, containerFilter: "" });
|
|
131
|
+
syncContainerFor(id);
|
|
132
|
+
void ensureContainers(id);
|
|
113
133
|
}
|
|
114
134
|
function emit() { listeners.forEach((fn) => fn()); }
|
|
115
135
|
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// Container selection (Joplin notebooks, Obsidian dirs, …): a tree picker with
|
|
138
|
+
// last-selection memory. The pick is recorded server-side immediately so
|
|
139
|
+
// headless/AI shares land in the same notebook. No polling — fetch on demand.
|
|
140
|
+
|
|
141
|
+
/** Selection follows the target's recorded last pick when the target switches. */
|
|
142
|
+
function syncContainerFor(id) {
|
|
143
|
+
const t = state.targets.find((x) => x.id === id);
|
|
144
|
+
set({ containerFor: t?.lastContainer || "" });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Fetch the container list for a target (cached per session; force bypasses). */
|
|
148
|
+
async function ensureContainers(targetId, force = false) {
|
|
149
|
+
const t = state.targets.find((x) => x.id === targetId);
|
|
150
|
+
if (!t || !t.supportsContainers) return;
|
|
151
|
+
if (state.containersByTarget[targetId] && !force) return;
|
|
152
|
+
set({ containersLoading: true, containerError: "" });
|
|
153
|
+
try {
|
|
154
|
+
const r = await getJSON("containers", { method: "POST", headers: { "content-type": "application/json" },
|
|
155
|
+
body: JSON.stringify({ targetId }) });
|
|
156
|
+
set({ containersLoading: false,
|
|
157
|
+
containersByTarget: { ...state.containersByTarget,
|
|
158
|
+
[targetId]: { containers: r.containers || [], label: r.containerLabel || null } } });
|
|
159
|
+
} catch (e) { set({ containersLoading: false, containerError: e.message }); }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Open/close the picker panel; expands the selection's ancestor chain by default. */
|
|
163
|
+
function toggleContainerPanel() {
|
|
164
|
+
if (state.containerOpen) { set({ containerOpen: false, containerFilter: "" }); return; }
|
|
165
|
+
const items = state.containersByTarget[state.targetId]?.containers || [];
|
|
166
|
+
const expanded = {};
|
|
167
|
+
// One visible level below the roots by default (children keep their own names),
|
|
168
|
+
// plus the full ancestor chain of the current selection.
|
|
169
|
+
for (const c of items) if (!c.parent) expanded[c.id] = true;
|
|
170
|
+
const byId = new Map(items.map((c) => [c.id, c]));
|
|
171
|
+
let cur = byId.get(state.containerFor);
|
|
172
|
+
while (cur?.parent) { expanded[cur.parent] = true; cur = byId.get(cur.parent); }
|
|
173
|
+
set({ containerOpen: true, containerFilter: "", containerExpanded: expanded, kbIndex: -1 });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Record the pick immediately (even the explicit "service default" pick). */
|
|
177
|
+
function pickContainer(c) {
|
|
178
|
+
const id = c ? c.id : "";
|
|
179
|
+
const pathLabel = c ? (c.path || c.label) : "";
|
|
180
|
+
set({ containerFor: id, containerOpen: false, containerFilter: "", kbIndex: -1 });
|
|
181
|
+
void getJSON("targets/last-container", { method: "POST", headers: { "content-type": "application/json" },
|
|
182
|
+
body: JSON.stringify({ id: state.targetId, container: id, label: pathLabel }) })
|
|
183
|
+
.then((r) => set({ targets: state.targets.map((x) => x.id === state.targetId && r?.target
|
|
184
|
+
? { ...x, lastContainer: r.target.lastContainer, lastContainerLabel: r.target.lastContainerLabel,
|
|
185
|
+
recentContainers: r.target.recentContainers } : x) }))
|
|
186
|
+
.catch(() => {});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** parent→children map for tree rendering; orphans without a resolvable parent fall back to root. */
|
|
190
|
+
function containerTree(items) {
|
|
191
|
+
const ids = new Set(items.map((c) => c.id));
|
|
192
|
+
const childrenOf = new Map();
|
|
193
|
+
for (const c of items) {
|
|
194
|
+
const k = (c.parent && ids.has(c.parent)) ? c.parent : "";
|
|
195
|
+
if (!childrenOf.has(k)) childrenOf.set(k, []);
|
|
196
|
+
childrenOf.get(k).push(c);
|
|
197
|
+
}
|
|
198
|
+
for (const arr of childrenOf.values()) arr.sort((a, b) => String(a.label).localeCompare(String(b.label)));
|
|
199
|
+
return childrenOf;
|
|
200
|
+
}
|
|
201
|
+
|
|
116
202
|
// Content-kind labels resolved via shareT() at render time; status uses icons only.
|
|
117
203
|
const STATUS_ICONS = { recent: "🕘", recommended: "★", dead: "⚠", legacy: "⚠" };
|
|
118
204
|
const CFG_BADGE = {
|
|
@@ -120,6 +206,7 @@ const CFG_BADGE = {
|
|
|
120
206
|
ready: { icon: "✓", key: "share.cfg.ready", color: "var(--accent, #4d8dff)" },
|
|
121
207
|
"needs-setup": { icon: "🟠", key: "share.cfg.needs", color: "#d9a13c" },
|
|
122
208
|
dead: { icon: "💀", key: "share.cfg.dead", color: "var(--text-muted, #8b909b)" },
|
|
209
|
+
legacy: { icon: "⚠", key: "share.cfg.legacy", color: "#d9a13c" },
|
|
123
210
|
};
|
|
124
211
|
|
|
125
212
|
const ICONS = {
|
|
@@ -162,7 +249,7 @@ function openShare(payload = {}) {
|
|
|
162
249
|
const raw = payload.text || "";
|
|
163
250
|
primeSinks();
|
|
164
251
|
set({ open: true, manager: false, payload, kind,
|
|
165
|
-
text: raw, rawText: raw, baseText: raw, title: payload.title ||
|
|
252
|
+
text: raw, rawText: raw, baseText: raw, title: payload.title || deriveTitleLocal(raw),
|
|
166
253
|
tags: payload.tags || "", targetId: payload.targetId || null,
|
|
167
254
|
result: null, error: "", errorDetail: "", errorCode: "", errorTarget: "", errorProvider: "", redact: true, redactHits: [],
|
|
168
255
|
sinkResult: null, sinkBusy: "" });
|
|
@@ -181,20 +268,26 @@ async function refresh(force = false) {
|
|
|
181
268
|
const targets = catalog.targets || [];
|
|
182
269
|
set({ targets, history: history.items || [], probe: probe.services || [], loading: false,
|
|
183
270
|
targetId: state.targetId || targets.find((t) => t.recommended)?.id || targets[0]?.id });
|
|
271
|
+
syncContainerFor(state.targetId);
|
|
272
|
+
void ensureContainers(state.targetId);
|
|
184
273
|
if (force) await getJSON("refresh", { method: "POST" }).catch(() => {});
|
|
185
274
|
} catch (e) { set({ loading: false, error: e.message, errorDetail: e.detail || "catalog/history" }); }
|
|
186
275
|
}
|
|
187
276
|
|
|
188
277
|
function targetCard(target, selected, badge) {
|
|
189
|
-
const disabled = target.status === "dead" || target.enabled === false;
|
|
278
|
+
const disabled = target.status === "dead" || target.status === "legacy" || target.enabled === false;
|
|
190
279
|
return h("button", { type: "button", key: target.id, disabled,
|
|
191
|
-
onClick: () => set({ targetId: target.id, error: "" })
|
|
280
|
+
onClick: () => { set({ targetId: target.id, error: "", containerOpen: false, containerFilter: "" });
|
|
281
|
+
syncContainerFor(target.id); void ensureContainers(target.id); },
|
|
192
282
|
title: noteText(target.note) || target.name,
|
|
193
283
|
style: { display: "inline-flex", alignItems: "center", gap: 5, padding: "4px 9px",
|
|
194
284
|
border: "1px solid " + (selected ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"), borderRadius: 8,
|
|
195
285
|
background: selected ? "rgba(77, 141, 255, 0.15)" : "var(--bg-hover, #25272c)", color: disabled ? "var(--text-muted, #8b909b)" : "var(--text, #d8dade)",
|
|
196
286
|
fontSize: 12, cursor: "pointer", opacity: disabled ? 0.45 : 1 } },
|
|
197
|
-
h("span", null, STATUS_ICONS[badge] || "🔗"),
|
|
287
|
+
h("span", null, target.icon || STATUS_ICONS[badge] || "🔗"),
|
|
288
|
+
// Provider glyph first; the source marker (recent/recommended) stays as a small secondary hint.
|
|
289
|
+
...(target.icon && STATUS_ICONS[badge]
|
|
290
|
+
? [h("span", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)" } }, STATUS_ICONS[badge])] : []),
|
|
198
291
|
target.name || target.id,
|
|
199
292
|
...(target.kinds?.length ? [h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10 } },
|
|
200
293
|
target.kinds.map(kindLabel).join("/"))] : []),
|
|
@@ -320,7 +413,7 @@ function sinkSection() {
|
|
|
320
413
|
function targetSection() {
|
|
321
414
|
const recent = recentGet();
|
|
322
415
|
const kind = contentKind();
|
|
323
|
-
const compat = (x) => supportsKind(x, kind);
|
|
416
|
+
const compat = (x) => supportsKind(x, kind) && x.status !== "dead" && x.status !== "legacy";
|
|
324
417
|
const t = state.targets;
|
|
325
418
|
const byId = new Map(t.map((x) => [x.id, x]));
|
|
326
419
|
const recentItems = recent.map((id) => byId.get(id)).filter(Boolean).filter(compat).slice(0, 5);
|
|
@@ -348,6 +441,171 @@ function targetSection() {
|
|
|
348
441
|
h("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 } }, ...shown));
|
|
349
442
|
}
|
|
350
443
|
|
|
444
|
+
// --- Container picker UI (tree with named sub-items; search degrades to path list) ---
|
|
445
|
+
|
|
446
|
+
/** Visible picker rows in render order — keyboard navigation walks this list. */
|
|
447
|
+
let panelVisible = [];
|
|
448
|
+
|
|
449
|
+
function containerRow(c, depth, childCount, expanded, selected, highlighted, idx, kbActive) {
|
|
450
|
+
// Depth guides keep the hierarchy readable while every level keeps its own name.
|
|
451
|
+
const guides = [];
|
|
452
|
+
for (let i = 0; i < depth; i++) guides.push(h("span", { key: "g" + i,
|
|
453
|
+
style: { width: 14, textAlign: "center", flexShrink: 0, color: "var(--text-muted, #8b909b)", opacity: 0.45 } }, "│"));
|
|
454
|
+
return h("div", { key: c.id, "data-kb": String(idx), onClick: () => pickContainer(c), title: c.path || c.label,
|
|
455
|
+
style: { display: "flex", alignItems: "center", gap: 5, padding: "3px 6px", borderRadius: 6, cursor: "pointer", fontSize: 12,
|
|
456
|
+
background: selected ? "rgba(77, 141, 255, 0.18)" : kbActive ? "var(--bg-hover, #25272c)" : "transparent",
|
|
457
|
+
boxShadow: kbActive ? "inset 0 0 0 1px var(--accent, #4d8dff)" : undefined,
|
|
458
|
+
color: "var(--text, #d8dade)" } },
|
|
459
|
+
...guides,
|
|
460
|
+
h("span", { onClick: (e) => { if (!childCount) return; e.stopPropagation();
|
|
461
|
+
set({ containerExpanded: { ...state.containerExpanded, [c.id]: !expanded } }); },
|
|
462
|
+
style: { width: 14, textAlign: "center", flexShrink: 0,
|
|
463
|
+
color: childCount ? "var(--text-muted, #8b909b)" : "transparent",
|
|
464
|
+
cursor: childCount ? "pointer" : "default" } }, expanded ? "▾" : "▸"),
|
|
465
|
+
h("span", { style: { flex: 1, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis",
|
|
466
|
+
fontWeight: selected ? 600 : 400,
|
|
467
|
+
color: highlighted && !selected ? "var(--accent, #4d8dff)" : undefined } }, c.label),
|
|
468
|
+
selected ? h("span", { style: { color: "var(--accent, #4d8dff)", fontSize: 11, flexShrink: 0 } }, "✓") : null,
|
|
469
|
+
childCount && !expanded ? h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, flexShrink: 0 } }, childCount) : null);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Search keeps the tree: nodes matching by their own name + their ancestor chain.
|
|
473
|
+
* Each hit stays in context (named ancestors show WHERE it lives — real Joplin
|
|
474
|
+
* trees repeat names across roots), matches highlighted, branches force-expanded. */
|
|
475
|
+
function containerSearchState(items, query) {
|
|
476
|
+
const q = query.toLowerCase();
|
|
477
|
+
const match = new Set();
|
|
478
|
+
const ancestors = new Set();
|
|
479
|
+
const byId = new Map(items.map((c) => [c.id, c]));
|
|
480
|
+
for (const c of items) {
|
|
481
|
+
if (String(c.label).toLowerCase().includes(q)) {
|
|
482
|
+
match.add(c.id);
|
|
483
|
+
let cur = c;
|
|
484
|
+
while (cur?.parent && byId.has(cur.parent)) { ancestors.add(cur.parent); cur = byId.get(cur.parent); }
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return { match, ancestors };
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function renderContainerNodes(childrenOf, nodes, depth, search, flat) {
|
|
491
|
+
const out = [];
|
|
492
|
+
for (const c of nodes) {
|
|
493
|
+
if (search && !search.match.has(c.id) && !search.ancestors.has(c.id)) continue;
|
|
494
|
+
const kids = childrenOf.get(c.id) || [];
|
|
495
|
+
const expanded = search
|
|
496
|
+
? search.ancestors.has(c.id) || kids.some((k) => search.match.has(k.id) || search.ancestors.has(k.id))
|
|
497
|
+
: !!state.containerExpanded[c.id];
|
|
498
|
+
const idx = flat.length;
|
|
499
|
+
flat.push(c);
|
|
500
|
+
out.push(containerRow(c, depth, kids.length, expanded, state.containerFor === c.id,
|
|
501
|
+
!!search && search.match.has(c.id), idx, state.kbIndex === idx));
|
|
502
|
+
if (kids.length && expanded) out.push(...renderContainerNodes(childrenOf, kids, depth + 1, search, flat));
|
|
503
|
+
}
|
|
504
|
+
return out;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Quick-pick chips from the target's recent-container history (≥2 entries to be useful). */
|
|
508
|
+
function containerQuickRow() {
|
|
509
|
+
const t = state.targets.find((x) => x.id === state.targetId);
|
|
510
|
+
const recents = (t?.recentContainers || []).filter((r) => r && r.id);
|
|
511
|
+
if (recents.length < 2) return null;
|
|
512
|
+
return h("div", { style: { display: "flex", flexWrap: "wrap", gap: 4, alignItems: "center", padding: "0 2px 4px" } },
|
|
513
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, flexShrink: 0 } }, shareT("share.recent")),
|
|
514
|
+
...recents.map((r) => {
|
|
515
|
+
const sel = state.containerFor === r.id;
|
|
516
|
+
return h("button", { type: "button", key: r.id, title: r.label, onClick: () => pickContainer({ id: r.id, label: r.label, path: r.label }),
|
|
517
|
+
style: { border: "1px solid " + (sel ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"),
|
|
518
|
+
background: sel ? "rgba(77, 141, 255, 0.15)" : "var(--bg-hover, #25272c)",
|
|
519
|
+
color: "var(--text, #d8dade)", borderRadius: 6, padding: "2px 8px", fontSize: 11, cursor: "pointer",
|
|
520
|
+
maxWidth: 150, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, "🕘 " + r.label);
|
|
521
|
+
}));
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function containerPanel(items) {
|
|
525
|
+
const filter = state.containerFilter.trim();
|
|
526
|
+
const childrenOf = containerTree(items);
|
|
527
|
+
const roots = childrenOf.get("") || [];
|
|
528
|
+
const empty = h("div", { style: { padding: "8px 6px", fontSize: 11, color: "var(--text-muted, #8b909b)" } },
|
|
529
|
+
shareT("share.container.empty"));
|
|
530
|
+
panelVisible = [];
|
|
531
|
+
const flat = panelVisible;
|
|
532
|
+
const search = filter ? containerSearchState(items, filter) : null;
|
|
533
|
+
const rows = renderContainerNodes(childrenOf, roots, 0, search, flat);
|
|
534
|
+
const kbMove = (delta) => {
|
|
535
|
+
if (!panelVisible.length) return;
|
|
536
|
+
const next = state.kbIndex < 0 ? (delta > 0 ? 0 : panelVisible.length - 1)
|
|
537
|
+
: Math.min(Math.max(state.kbIndex + delta, 0), panelVisible.length - 1);
|
|
538
|
+
set({ kbIndex: next });
|
|
539
|
+
setTimeout(() => { try { document.querySelector(`[data-ext-float] [data-kb="${next}"]`)?.scrollIntoView({ block: "nearest" }); } catch (e) {} }, 0);
|
|
540
|
+
};
|
|
541
|
+
return h("div", { style: { border: "1px solid var(--border, #34363c)", borderRadius: 7, marginTop: 5,
|
|
542
|
+
background: "var(--bg-panel, #1e2021)", maxHeight: 320, overflowY: "auto", padding: 4 } },
|
|
543
|
+
h("div", { style: { position: "sticky", top: -4, margin: -4, marginBottom: 0, padding: 4,
|
|
544
|
+
background: "var(--bg-panel, #1e2021)", zIndex: 1 } },
|
|
545
|
+
h("input", { value: state.containerFilter, placeholder: shareT("share.container.search"),
|
|
546
|
+
onInput: (e) => set({ containerFilter: e.target.value, kbIndex: -1 }),
|
|
547
|
+
onKeyDown: (e) => {
|
|
548
|
+
if (e.key === "Escape") { set({ containerOpen: false, containerFilter: "" }); return; }
|
|
549
|
+
if (e.key === "ArrowDown") { e.preventDefault(); kbMove(1); return; }
|
|
550
|
+
if (e.key === "ArrowUp") { e.preventDefault(); kbMove(-1); return; }
|
|
551
|
+
if (e.key === "Enter") { e.preventDefault(); const c = panelVisible[state.kbIndex]; if (c) pickContainer(c); return; }
|
|
552
|
+
const c = panelVisible[state.kbIndex];
|
|
553
|
+
if ((e.key === "ArrowRight" || e.key === "ArrowLeft") && c) {
|
|
554
|
+
e.preventDefault();
|
|
555
|
+
const kids = childrenOf.get(c.id) || [];
|
|
556
|
+
const expanded = filter ? true : !!state.containerExpanded[c.id];
|
|
557
|
+
if (e.key === "ArrowRight" && kids.length && !expanded) set({ containerExpanded: { ...state.containerExpanded, [c.id]: true } });
|
|
558
|
+
if (e.key === "ArrowLeft" && !filter && expanded) set({ containerExpanded: { ...state.containerExpanded, [c.id]: false } });
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
ref: (el) => { el?.focus?.(); },
|
|
562
|
+
style: { width: "100%", boxSizing: "border-box", background: "var(--bg-hover, #25272c)",
|
|
563
|
+
border: "1px solid var(--border, #34363c)", borderRadius: 6, padding: "4px 8px", fontSize: 12,
|
|
564
|
+
color: "var(--text, #d8dade)" } }),
|
|
565
|
+
filter && rows.length ? h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)", marginTop: 3 } },
|
|
566
|
+
shareT("share.container.matches", { n: String(search.match.size) })) : null),
|
|
567
|
+
containerQuickRow(),
|
|
568
|
+
state.containersLoading ? h("div", { style: { padding: "6px", fontSize: 11, color: "var(--text-muted, #8b909b)" } }, "…") : null,
|
|
569
|
+
rows.length ? rows : empty);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** Container selection row: hidden unless the current target supports containers. */
|
|
573
|
+
function containerSection() {
|
|
574
|
+
const t = state.targets.find((x) => x.id === state.targetId);
|
|
575
|
+
if (!t || !t.supportsContainers) return null;
|
|
576
|
+
const cache = state.containersByTarget[state.targetId];
|
|
577
|
+
const items = cache?.containers || [];
|
|
578
|
+
const selected = items.find((c) => c.id === state.containerFor);
|
|
579
|
+
const label = noteText(cache?.label) || noteText(t.containerLabel) || shareT("share.container.label");
|
|
580
|
+
const missing = state.containerFor && items.length && !selected;
|
|
581
|
+
const btnLabel = selected ? (selected.path || selected.label) : shareT("share.container.default");
|
|
582
|
+
return h("div", null,
|
|
583
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 6 } },
|
|
584
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, flexShrink: 0 } },
|
|
585
|
+
"📓 " + label),
|
|
586
|
+
h("button", { type: "button", onClick: () => { void ensureContainers(state.targetId); toggleContainerPanel(); },
|
|
587
|
+
title: btnLabel,
|
|
588
|
+
style: { flex: 1, minWidth: 0, display: "flex", alignItems: "center", gap: 5, textAlign: "left",
|
|
589
|
+
border: "1px solid var(--border, #34363c)", background: "var(--bg-hover, #25272c)",
|
|
590
|
+
color: selected ? "var(--text, #d8dade)" : "var(--text-muted, #8b909b)", borderRadius: 7,
|
|
591
|
+
padding: "5px 9px", fontSize: 12, cursor: "pointer" } },
|
|
592
|
+
h("span", { style: { flex: 1, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, btnLabel),
|
|
593
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10 } }, state.containerOpen ? "▴" : "▾")),
|
|
594
|
+
h("button", { type: "button", onClick: () => { void ensureContainers(state.targetId, true); },
|
|
595
|
+
title: shareT("share.container.refresh"),
|
|
596
|
+
style: { border: "1px solid var(--border, #34363c)", background: "none",
|
|
597
|
+
color: "var(--text-muted, #8b909b)", borderRadius: 7, padding: "5px 8px", fontSize: 12,
|
|
598
|
+
cursor: "pointer", flexShrink: 0 } }, "⟳")),
|
|
599
|
+
missing ? h("div", { style: { color: "#d9a13c", fontSize: 10, marginTop: 4 } }, shareT("share.container.missing")) : null,
|
|
600
|
+
state.containerOpen ? containerPanel(items) : null,
|
|
601
|
+
state.containerError ? h("div", { style: { display: "flex", alignItems: "center", gap: 8,
|
|
602
|
+
color: "#e05d5d", fontSize: 11, marginTop: 4 } },
|
|
603
|
+
shareT("share.container.fail", { detail: state.containerError }),
|
|
604
|
+
h("button", { type: "button", onClick: () => { void ensureContainers(state.targetId, true); },
|
|
605
|
+
style: { border: "none", background: "none", color: "var(--accent, #4d8dff)", cursor: "pointer", fontSize: 11 } },
|
|
606
|
+
shareT("share.container.refresh"))) : null);
|
|
607
|
+
}
|
|
608
|
+
|
|
351
609
|
/** Collect page context for the optional "page info" stamp. */
|
|
352
610
|
function pageInfo() {
|
|
353
611
|
const ua = (typeof navigator !== "undefined" && navigator.userAgent) || "";
|
|
@@ -418,7 +676,7 @@ function errorText() {
|
|
|
418
676
|
disabled: "share.err.disabled", unknownTarget: "share.err.unknownTarget",
|
|
419
677
|
noSession: "share.err.noSession", imageFetch: "share.err.imageFetch", endpoint: "share.err.endpoint",
|
|
420
678
|
badRequest: "share.err.badRequest", badSxcu: "share.err.badSxcu", noProbe: "share.err.noProbe",
|
|
421
|
-
forbidden: "share.err.forbidden", kind: "share.err.kind",
|
|
679
|
+
forbidden: "share.err.forbidden", kind: "share.err.kind", containerFail: "share.container.fail",
|
|
422
680
|
}[code];
|
|
423
681
|
if (key) return shareT(key, { name, detail });
|
|
424
682
|
return state.error || shareT("share.err.generic", { detail });
|
|
@@ -514,7 +772,8 @@ async function doShare() {
|
|
|
514
772
|
// The textarea already shows the redacted text (preview-redact ran on load/toggle),
|
|
515
773
|
// so upload exactly what the user sees; no second redaction on the server.
|
|
516
774
|
const body = { ...(state.payload || {}), targetId: state.targetId, kind: state.kind,
|
|
517
|
-
text: state.text, title: state.title, tags: state.tags, redact: false
|
|
775
|
+
text: state.text, title: state.title, tags: state.tags, redact: false,
|
|
776
|
+
container: state.containerFor || "" };
|
|
518
777
|
// Images: load in the browser (same-origin /api/... or data: URLs — no CORS,
|
|
519
778
|
// no server-side fetch) and hand the server base64 bytes.
|
|
520
779
|
if (state.kind === "image" && body.imageSrc) {
|
|
@@ -571,7 +830,7 @@ function shareDialog() {
|
|
|
571
830
|
style: { background: "none", border: "none", color: "var(--text-muted, #8b909b)", cursor: "pointer", fontSize: 14 } }, "✕"));
|
|
572
831
|
const body = h("div", { ref: (el) => { dialogBodyEl = el; },
|
|
573
832
|
style: { padding: "12px 14px", display: "flex", flexDirection: "column", gap: 12, flex: 1, minHeight: 0, overflowY: "auto" } },
|
|
574
|
-
previewSection(), sinkSection(), targetSection(),
|
|
833
|
+
previewSection(), sinkSection(), targetSection(), containerSection(),
|
|
575
834
|
h("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 9 } },
|
|
576
835
|
h("input", { value: state.title, placeholder: shareT("share.titleField"), onInput: (e) => set({ title: e.target.value }),
|
|
577
836
|
style: { background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 7, padding: "6px 9px", fontSize: 12 } }),
|
|
@@ -613,10 +872,13 @@ function managerDialog() {
|
|
|
613
872
|
form: { ...((t.values && !Array.isArray(t.values)) ? t.values : {}) } }),
|
|
614
873
|
style: { display: "flex", alignItems: "center", gap: 7, padding: "5px 8px", borderRadius: 7, cursor: "pointer",
|
|
615
874
|
background: state.editing === t.id ? "rgba(77, 141, 255, 0.15)" : "none", opacity: t.status === "dead" ? 0.5 : 1 } },
|
|
616
|
-
h("span", null, t.status === "dead" ? "💀" : t.category === "archive" ? "📓" : "🔗"),
|
|
875
|
+
h("span", null, t.status === "dead" ? "💀" : (t.icon || (t.category === "archive" ? "📓" : "🔗"))),
|
|
617
876
|
h("div", { style: { flex: 1, minWidth: 0 } },
|
|
618
877
|
h("div", { style: { fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, t.name || t.id),
|
|
619
|
-
h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)"
|
|
878
|
+
h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } },
|
|
879
|
+
(t.kinds || []).map(kindLabel).join("/")
|
|
880
|
+
+ (() => { const n = noteText(t.note); return n ? " · " + n : ""; })()
|
|
881
|
+
+ (t.supportsContainers && t.lastContainerLabel ? " · 📓 " + t.lastContainerLabel : ""))),
|
|
620
882
|
(() => { const b = CFG_BADGE[t.configState]; return b ? h("span", { title: shareT(b.key),
|
|
621
883
|
style: { color: b.color, fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 } }, b.icon) : null; })(),
|
|
622
884
|
t.recommended ? h("span", { style: { color: "var(--accent, #4d8dff)", fontSize: 10 } }, "★") : null,
|
|
@@ -624,7 +886,7 @@ function managerDialog() {
|
|
|
624
886
|
!supportsKind(t, contentKind())
|
|
625
887
|
? h("span", { title: shareT("share.notCompatible", { kind: kindLabel(contentKind()) }),
|
|
626
888
|
style: { color: "var(--text-muted, #8b909b)", fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 } }, "∅")
|
|
627
|
-
: t.status !== "dead" && t.configState !== "needs-setup"
|
|
889
|
+
: t.status !== "dead" && t.status !== "legacy" && t.configState !== "needs-setup"
|
|
628
890
|
? h("button", { type: "button", title: shareT("share.useTarget"),
|
|
629
891
|
onClick: (e) => { e.stopPropagation(); chooseTarget(t.id); },
|
|
630
892
|
style: { border: "1px solid var(--accent, #4d8dff)", background: state.targetId === t.id ? "var(--accent, #4d8dff)" : "none",
|