@aiti-ai/aiti-msg-share 0.1.8 → 0.1.10

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.
@@ -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)" } }, (t.kinds || []).map(kindLabel).join("/") + (() => { const n = noteText(t.note); return n ? " · " + n : ""; })())),
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",
@@ -2125,6 +2125,15 @@ function contentKind() {
2125
2125
  function supportsKind(t, kind) {
2126
2126
  return !(t.kinds || []).length || (t.kinds || []).includes(kind);
2127
2127
  }
2128
+ function deriveTitleLocal(text) {
2129
+ for (const raw of String(text || "").split("\n")) {
2130
+ const line = raw.trim();
2131
+ if (!line || /^>\s*\*\*[^*]+\*\*\s*:/.test(line)) continue;
2132
+ const stripped = line.replace(/^#{1,6}\s+/, "").replace(/[*_`]+/g, "").trim();
2133
+ if (stripped) return stripped.length > 80 ? stripped.slice(0, 80).trim() : stripped;
2134
+ }
2135
+ return "";
2136
+ }
2128
2137
  function shareT(key, params) {
2129
2138
  if (!tFn) return key;
2130
2139
  try {
@@ -2168,6 +2177,17 @@ var state = {
2168
2177
  probe: [],
2169
2178
  editing: null,
2170
2179
  form: {},
2180
+ /** Container picker (notebook/folder selection): per-target cache + pending pick.
2181
+ * containersByTarget[id] = { containers: [{id,label,parent,path}], label } */
2182
+ containersByTarget: {},
2183
+ containerFor: "",
2184
+ containerOpen: false,
2185
+ containerFilter: "",
2186
+ containerExpanded: {},
2187
+ containersLoading: false,
2188
+ containerError: "",
2189
+ /** Keyboard navigation index over the currently visible picker rows (-1 = none). */
2190
+ kbIndex: -1,
2171
2191
  /** Local favourite sinks (share-sink topic): { ok, message, action } of the last run. */
2172
2192
  sinkResult: null,
2173
2193
  sinkBusy: ""
@@ -2235,17 +2255,89 @@ function set(partial) {
2235
2255
  }
2236
2256
  function chooseTarget(id) {
2237
2257
  recentAdd(id);
2238
- set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "" });
2258
+ set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "", containerOpen: false, containerFilter: "" });
2259
+ syncContainerFor(id);
2260
+ void ensureContainers(id);
2239
2261
  }
2240
2262
  function emit() {
2241
2263
  listeners.forEach((fn) => fn());
2242
2264
  }
2265
+ function syncContainerFor(id) {
2266
+ const t = state.targets.find((x) => x.id === id);
2267
+ set({ containerFor: t?.lastContainer || "" });
2268
+ }
2269
+ async function ensureContainers(targetId, force = false) {
2270
+ const t = state.targets.find((x) => x.id === targetId);
2271
+ if (!t || !t.supportsContainers) return;
2272
+ if (state.containersByTarget[targetId] && !force) return;
2273
+ set({ containersLoading: true, containerError: "" });
2274
+ try {
2275
+ const r = await getJSON("containers", {
2276
+ method: "POST",
2277
+ headers: { "content-type": "application/json" },
2278
+ body: JSON.stringify({ targetId })
2279
+ });
2280
+ set({
2281
+ containersLoading: false,
2282
+ containersByTarget: {
2283
+ ...state.containersByTarget,
2284
+ [targetId]: { containers: r.containers || [], label: r.containerLabel || null }
2285
+ }
2286
+ });
2287
+ } catch (e) {
2288
+ set({ containersLoading: false, containerError: e.message });
2289
+ }
2290
+ }
2291
+ function toggleContainerPanel() {
2292
+ if (state.containerOpen) {
2293
+ set({ containerOpen: false, containerFilter: "" });
2294
+ return;
2295
+ }
2296
+ const items = state.containersByTarget[state.targetId]?.containers || [];
2297
+ const expanded = {};
2298
+ for (const c of items) if (!c.parent) expanded[c.id] = true;
2299
+ const byId = new Map(items.map((c) => [c.id, c]));
2300
+ let cur = byId.get(state.containerFor);
2301
+ while (cur?.parent) {
2302
+ expanded[cur.parent] = true;
2303
+ cur = byId.get(cur.parent);
2304
+ }
2305
+ set({ containerOpen: true, containerFilter: "", containerExpanded: expanded, kbIndex: -1 });
2306
+ }
2307
+ function pickContainer(c) {
2308
+ const id = c ? c.id : "";
2309
+ const pathLabel = c ? c.path || c.label : "";
2310
+ set({ containerFor: id, containerOpen: false, containerFilter: "", kbIndex: -1 });
2311
+ void getJSON("targets/last-container", {
2312
+ method: "POST",
2313
+ headers: { "content-type": "application/json" },
2314
+ body: JSON.stringify({ id: state.targetId, container: id, label: pathLabel })
2315
+ }).then((r) => set({ targets: state.targets.map((x) => x.id === state.targetId && r?.target ? {
2316
+ ...x,
2317
+ lastContainer: r.target.lastContainer,
2318
+ lastContainerLabel: r.target.lastContainerLabel,
2319
+ recentContainers: r.target.recentContainers
2320
+ } : x) })).catch(() => {
2321
+ });
2322
+ }
2323
+ function containerTree(items) {
2324
+ const ids = new Set(items.map((c) => c.id));
2325
+ const childrenOf = /* @__PURE__ */ new Map();
2326
+ for (const c of items) {
2327
+ const k = c.parent && ids.has(c.parent) ? c.parent : "";
2328
+ if (!childrenOf.has(k)) childrenOf.set(k, []);
2329
+ childrenOf.get(k).push(c);
2330
+ }
2331
+ for (const arr of childrenOf.values()) arr.sort((a, b) => String(a.label).localeCompare(String(b.label)));
2332
+ return childrenOf;
2333
+ }
2243
2334
  var STATUS_ICONS = { recent: "\u{1F558}", recommended: "\u2605", dead: "\u26A0", legacy: "\u26A0" };
2244
2335
  var CFG_BADGE = {
2245
2336
  anonymous: { icon: "\u{1F7E2}", key: "share.cfg.anonymous", color: "var(--accent, #4d8dff)" },
2246
2337
  ready: { icon: "\u2713", key: "share.cfg.ready", color: "var(--accent, #4d8dff)" },
2247
2338
  "needs-setup": { icon: "\u{1F7E0}", key: "share.cfg.needs", color: "#d9a13c" },
2248
- dead: { icon: "\u{1F480}", key: "share.cfg.dead", color: "var(--text-muted, #8b909b)" }
2339
+ dead: { icon: "\u{1F480}", key: "share.cfg.dead", color: "var(--text-muted, #8b909b)" },
2340
+ legacy: { icon: "\u26A0", key: "share.cfg.legacy", color: "#d9a13c" }
2249
2341
  };
2250
2342
  var ICONS = {
2251
2343
  share: '<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.6" y1="10.5" x2="15.4" y2="6.5"/><line x1="8.6" y1="13.5" x2="15.4" y2="17.5"/>',
@@ -2299,7 +2391,7 @@ function openShare(payload = {}) {
2299
2391
  text: raw,
2300
2392
  rawText: raw,
2301
2393
  baseText: raw,
2302
- title: payload.title || "",
2394
+ title: payload.title || deriveTitleLocal(raw),
2303
2395
  tags: payload.tags || "",
2304
2396
  targetId: payload.targetId || null,
2305
2397
  result: null,
@@ -2333,6 +2425,8 @@ async function refresh(force = false) {
2333
2425
  loading: false,
2334
2426
  targetId: state.targetId || targets.find((t) => t.recommended)?.id || targets[0]?.id
2335
2427
  });
2428
+ syncContainerFor(state.targetId);
2429
+ void ensureContainers(state.targetId);
2336
2430
  if (force) await getJSON("refresh", { method: "POST" }).catch(() => {
2337
2431
  });
2338
2432
  } catch (e) {
@@ -2340,14 +2434,18 @@ async function refresh(force = false) {
2340
2434
  }
2341
2435
  }
2342
2436
  function targetCard(target, selected, badge) {
2343
- const disabled = target.status === "dead" || target.enabled === false;
2437
+ const disabled = target.status === "dead" || target.status === "legacy" || target.enabled === false;
2344
2438
  return h(
2345
2439
  "button",
2346
2440
  {
2347
2441
  type: "button",
2348
2442
  key: target.id,
2349
2443
  disabled,
2350
- onClick: () => set({ targetId: target.id, error: "" }),
2444
+ onClick: () => {
2445
+ set({ targetId: target.id, error: "", containerOpen: false, containerFilter: "" });
2446
+ syncContainerFor(target.id);
2447
+ void ensureContainers(target.id);
2448
+ },
2351
2449
  title: noteText(target.note) || target.name,
2352
2450
  style: {
2353
2451
  display: "inline-flex",
@@ -2363,7 +2461,8 @@ function targetCard(target, selected, badge) {
2363
2461
  opacity: disabled ? 0.45 : 1
2364
2462
  }
2365
2463
  },
2366
- h("span", null, STATUS_ICONS[badge] || "\u{1F517}"),
2464
+ h("span", null, target.icon || STATUS_ICONS[badge] || "\u{1F517}"),
2465
+ ...target.icon && STATUS_ICONS[badge] ? [h("span", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)" } }, STATUS_ICONS[badge])] : [],
2367
2466
  target.name || target.id,
2368
2467
  ...target.kinds?.length ? [h(
2369
2468
  "span",
@@ -2530,7 +2629,7 @@ function sinkSection() {
2530
2629
  function targetSection() {
2531
2630
  const recent = recentGet();
2532
2631
  const kind = contentKind();
2533
- const compat = (x) => supportsKind(x, kind);
2632
+ const compat = (x) => supportsKind(x, kind) && x.status !== "dead" && x.status !== "legacy";
2534
2633
  const t = state.targets;
2535
2634
  const byId = new Map(t.map((x) => [x.id, x]));
2536
2635
  const recentItems = recent.map((id) => byId.get(id)).filter(Boolean).filter(compat).slice(0, 5);
@@ -2571,6 +2670,330 @@ function targetSection() {
2571
2670
  h("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 } }, ...shown)
2572
2671
  );
2573
2672
  }
2673
+ var panelVisible = [];
2674
+ function containerRow(c, depth, childCount, expanded, selected, highlighted, idx, kbActive) {
2675
+ const guides = [];
2676
+ for (let i = 0; i < depth; i++) guides.push(h("span", {
2677
+ key: "g" + i,
2678
+ style: { width: 14, textAlign: "center", flexShrink: 0, color: "var(--text-muted, #8b909b)", opacity: 0.45 }
2679
+ }, "\u2502"));
2680
+ return h(
2681
+ "div",
2682
+ {
2683
+ key: c.id,
2684
+ "data-kb": String(idx),
2685
+ onClick: () => pickContainer(c),
2686
+ title: c.path || c.label,
2687
+ style: {
2688
+ display: "flex",
2689
+ alignItems: "center",
2690
+ gap: 5,
2691
+ padding: "3px 6px",
2692
+ borderRadius: 6,
2693
+ cursor: "pointer",
2694
+ fontSize: 12,
2695
+ background: selected ? "rgba(77, 141, 255, 0.18)" : kbActive ? "var(--bg-hover, #25272c)" : "transparent",
2696
+ boxShadow: kbActive ? "inset 0 0 0 1px var(--accent, #4d8dff)" : void 0,
2697
+ color: "var(--text, #d8dade)"
2698
+ }
2699
+ },
2700
+ ...guides,
2701
+ h("span", {
2702
+ onClick: (e) => {
2703
+ if (!childCount) return;
2704
+ e.stopPropagation();
2705
+ set({ containerExpanded: { ...state.containerExpanded, [c.id]: !expanded } });
2706
+ },
2707
+ style: {
2708
+ width: 14,
2709
+ textAlign: "center",
2710
+ flexShrink: 0,
2711
+ color: childCount ? "var(--text-muted, #8b909b)" : "transparent",
2712
+ cursor: childCount ? "pointer" : "default"
2713
+ }
2714
+ }, expanded ? "\u25BE" : "\u25B8"),
2715
+ h("span", { style: {
2716
+ flex: 1,
2717
+ minWidth: 0,
2718
+ whiteSpace: "nowrap",
2719
+ overflow: "hidden",
2720
+ textOverflow: "ellipsis",
2721
+ fontWeight: selected ? 600 : 400,
2722
+ color: highlighted && !selected ? "var(--accent, #4d8dff)" : void 0
2723
+ } }, c.label),
2724
+ selected ? h("span", { style: { color: "var(--accent, #4d8dff)", fontSize: 11, flexShrink: 0 } }, "\u2713") : null,
2725
+ childCount && !expanded ? h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, flexShrink: 0 } }, childCount) : null
2726
+ );
2727
+ }
2728
+ function containerSearchState(items, query) {
2729
+ const q = query.toLowerCase();
2730
+ const match = /* @__PURE__ */ new Set();
2731
+ const ancestors = /* @__PURE__ */ new Set();
2732
+ const byId = new Map(items.map((c) => [c.id, c]));
2733
+ for (const c of items) {
2734
+ if (String(c.label).toLowerCase().includes(q)) {
2735
+ match.add(c.id);
2736
+ let cur = c;
2737
+ while (cur?.parent && byId.has(cur.parent)) {
2738
+ ancestors.add(cur.parent);
2739
+ cur = byId.get(cur.parent);
2740
+ }
2741
+ }
2742
+ }
2743
+ return { match, ancestors };
2744
+ }
2745
+ function renderContainerNodes(childrenOf, nodes, depth, search, flat) {
2746
+ const out = [];
2747
+ for (const c of nodes) {
2748
+ if (search && !search.match.has(c.id) && !search.ancestors.has(c.id)) continue;
2749
+ const kids = childrenOf.get(c.id) || [];
2750
+ const expanded = search ? search.ancestors.has(c.id) || kids.some((k) => search.match.has(k.id) || search.ancestors.has(k.id)) : !!state.containerExpanded[c.id];
2751
+ const idx = flat.length;
2752
+ flat.push(c);
2753
+ out.push(containerRow(
2754
+ c,
2755
+ depth,
2756
+ kids.length,
2757
+ expanded,
2758
+ state.containerFor === c.id,
2759
+ !!search && search.match.has(c.id),
2760
+ idx,
2761
+ state.kbIndex === idx
2762
+ ));
2763
+ if (kids.length && expanded) out.push(...renderContainerNodes(childrenOf, kids, depth + 1, search, flat));
2764
+ }
2765
+ return out;
2766
+ }
2767
+ function containerQuickRow() {
2768
+ const t = state.targets.find((x) => x.id === state.targetId);
2769
+ const recents = (t?.recentContainers || []).filter((r) => r && r.id);
2770
+ if (recents.length < 2) return null;
2771
+ return h(
2772
+ "div",
2773
+ { style: { display: "flex", flexWrap: "wrap", gap: 4, alignItems: "center", padding: "0 2px 4px" } },
2774
+ h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, flexShrink: 0 } }, shareT("share.recent")),
2775
+ ...recents.map((r) => {
2776
+ const sel = state.containerFor === r.id;
2777
+ return h("button", {
2778
+ type: "button",
2779
+ key: r.id,
2780
+ title: r.label,
2781
+ onClick: () => pickContainer({ id: r.id, label: r.label, path: r.label }),
2782
+ style: {
2783
+ border: "1px solid " + (sel ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"),
2784
+ background: sel ? "rgba(77, 141, 255, 0.15)" : "var(--bg-hover, #25272c)",
2785
+ color: "var(--text, #d8dade)",
2786
+ borderRadius: 6,
2787
+ padding: "2px 8px",
2788
+ fontSize: 11,
2789
+ cursor: "pointer",
2790
+ maxWidth: 150,
2791
+ overflow: "hidden",
2792
+ textOverflow: "ellipsis",
2793
+ whiteSpace: "nowrap"
2794
+ }
2795
+ }, "\u{1F558} " + r.label);
2796
+ })
2797
+ );
2798
+ }
2799
+ function containerPanel(items) {
2800
+ const filter = state.containerFilter.trim();
2801
+ const childrenOf = containerTree(items);
2802
+ const roots = childrenOf.get("") || [];
2803
+ const empty = h(
2804
+ "div",
2805
+ { style: { padding: "8px 6px", fontSize: 11, color: "var(--text-muted, #8b909b)" } },
2806
+ shareT("share.container.empty")
2807
+ );
2808
+ panelVisible = [];
2809
+ const flat = panelVisible;
2810
+ const search = filter ? containerSearchState(items, filter) : null;
2811
+ const rows = renderContainerNodes(childrenOf, roots, 0, search, flat);
2812
+ const kbMove = (delta) => {
2813
+ if (!panelVisible.length) return;
2814
+ const next = state.kbIndex < 0 ? delta > 0 ? 0 : panelVisible.length - 1 : Math.min(Math.max(state.kbIndex + delta, 0), panelVisible.length - 1);
2815
+ set({ kbIndex: next });
2816
+ setTimeout(() => {
2817
+ try {
2818
+ document.querySelector(`[data-ext-float] [data-kb="${next}"]`)?.scrollIntoView({ block: "nearest" });
2819
+ } catch (e) {
2820
+ }
2821
+ }, 0);
2822
+ };
2823
+ return h(
2824
+ "div",
2825
+ { style: {
2826
+ border: "1px solid var(--border, #34363c)",
2827
+ borderRadius: 7,
2828
+ marginTop: 5,
2829
+ background: "var(--bg-panel, #1e2021)",
2830
+ maxHeight: 320,
2831
+ overflowY: "auto",
2832
+ padding: 4
2833
+ } },
2834
+ h(
2835
+ "div",
2836
+ { style: {
2837
+ position: "sticky",
2838
+ top: -4,
2839
+ margin: -4,
2840
+ marginBottom: 0,
2841
+ padding: 4,
2842
+ background: "var(--bg-panel, #1e2021)",
2843
+ zIndex: 1
2844
+ } },
2845
+ h("input", {
2846
+ value: state.containerFilter,
2847
+ placeholder: shareT("share.container.search"),
2848
+ onInput: (e) => set({ containerFilter: e.target.value, kbIndex: -1 }),
2849
+ onKeyDown: (e) => {
2850
+ if (e.key === "Escape") {
2851
+ set({ containerOpen: false, containerFilter: "" });
2852
+ return;
2853
+ }
2854
+ if (e.key === "ArrowDown") {
2855
+ e.preventDefault();
2856
+ kbMove(1);
2857
+ return;
2858
+ }
2859
+ if (e.key === "ArrowUp") {
2860
+ e.preventDefault();
2861
+ kbMove(-1);
2862
+ return;
2863
+ }
2864
+ if (e.key === "Enter") {
2865
+ e.preventDefault();
2866
+ const c2 = panelVisible[state.kbIndex];
2867
+ if (c2) pickContainer(c2);
2868
+ return;
2869
+ }
2870
+ const c = panelVisible[state.kbIndex];
2871
+ if ((e.key === "ArrowRight" || e.key === "ArrowLeft") && c) {
2872
+ e.preventDefault();
2873
+ const kids = childrenOf.get(c.id) || [];
2874
+ const expanded = filter ? true : !!state.containerExpanded[c.id];
2875
+ if (e.key === "ArrowRight" && kids.length && !expanded) set({ containerExpanded: { ...state.containerExpanded, [c.id]: true } });
2876
+ if (e.key === "ArrowLeft" && !filter && expanded) set({ containerExpanded: { ...state.containerExpanded, [c.id]: false } });
2877
+ }
2878
+ },
2879
+ ref: (el) => {
2880
+ el?.focus?.();
2881
+ },
2882
+ style: {
2883
+ width: "100%",
2884
+ boxSizing: "border-box",
2885
+ background: "var(--bg-hover, #25272c)",
2886
+ border: "1px solid var(--border, #34363c)",
2887
+ borderRadius: 6,
2888
+ padding: "4px 8px",
2889
+ fontSize: 12,
2890
+ color: "var(--text, #d8dade)"
2891
+ }
2892
+ }),
2893
+ filter && rows.length ? h(
2894
+ "div",
2895
+ { style: { fontSize: 10, color: "var(--text-muted, #8b909b)", marginTop: 3 } },
2896
+ shareT("share.container.matches", { n: String(search.match.size) })
2897
+ ) : null
2898
+ ),
2899
+ containerQuickRow(),
2900
+ state.containersLoading ? h("div", { style: { padding: "6px", fontSize: 11, color: "var(--text-muted, #8b909b)" } }, "\u2026") : null,
2901
+ rows.length ? rows : empty
2902
+ );
2903
+ }
2904
+ function containerSection() {
2905
+ const t = state.targets.find((x) => x.id === state.targetId);
2906
+ if (!t || !t.supportsContainers) return null;
2907
+ const cache = state.containersByTarget[state.targetId];
2908
+ const items = cache?.containers || [];
2909
+ const selected = items.find((c) => c.id === state.containerFor);
2910
+ const label = noteText(cache?.label) || noteText(t.containerLabel) || shareT("share.container.label");
2911
+ const missing = state.containerFor && items.length && !selected;
2912
+ const btnLabel = selected ? selected.path || selected.label : shareT("share.container.default");
2913
+ return h(
2914
+ "div",
2915
+ null,
2916
+ h(
2917
+ "div",
2918
+ { style: { display: "flex", alignItems: "center", gap: 6 } },
2919
+ h(
2920
+ "span",
2921
+ { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, flexShrink: 0 } },
2922
+ "\u{1F4D3} " + label
2923
+ ),
2924
+ h(
2925
+ "button",
2926
+ {
2927
+ type: "button",
2928
+ onClick: () => {
2929
+ void ensureContainers(state.targetId);
2930
+ toggleContainerPanel();
2931
+ },
2932
+ title: btnLabel,
2933
+ style: {
2934
+ flex: 1,
2935
+ minWidth: 0,
2936
+ display: "flex",
2937
+ alignItems: "center",
2938
+ gap: 5,
2939
+ textAlign: "left",
2940
+ border: "1px solid var(--border, #34363c)",
2941
+ background: "var(--bg-hover, #25272c)",
2942
+ color: selected ? "var(--text, #d8dade)" : "var(--text-muted, #8b909b)",
2943
+ borderRadius: 7,
2944
+ padding: "5px 9px",
2945
+ fontSize: 12,
2946
+ cursor: "pointer"
2947
+ }
2948
+ },
2949
+ h("span", { style: { flex: 1, minWidth: 0, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, btnLabel),
2950
+ h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10 } }, state.containerOpen ? "\u25B4" : "\u25BE")
2951
+ ),
2952
+ h("button", {
2953
+ type: "button",
2954
+ onClick: () => {
2955
+ void ensureContainers(state.targetId, true);
2956
+ },
2957
+ title: shareT("share.container.refresh"),
2958
+ style: {
2959
+ border: "1px solid var(--border, #34363c)",
2960
+ background: "none",
2961
+ color: "var(--text-muted, #8b909b)",
2962
+ borderRadius: 7,
2963
+ padding: "5px 8px",
2964
+ fontSize: 12,
2965
+ cursor: "pointer",
2966
+ flexShrink: 0
2967
+ }
2968
+ }, "\u27F3")
2969
+ ),
2970
+ missing ? h("div", { style: { color: "#d9a13c", fontSize: 10, marginTop: 4 } }, shareT("share.container.missing")) : null,
2971
+ state.containerOpen ? containerPanel(items) : null,
2972
+ state.containerError ? h(
2973
+ "div",
2974
+ { style: {
2975
+ display: "flex",
2976
+ alignItems: "center",
2977
+ gap: 8,
2978
+ color: "#e05d5d",
2979
+ fontSize: 11,
2980
+ marginTop: 4
2981
+ } },
2982
+ shareT("share.container.fail", { detail: state.containerError }),
2983
+ h(
2984
+ "button",
2985
+ {
2986
+ type: "button",
2987
+ onClick: () => {
2988
+ void ensureContainers(state.targetId, true);
2989
+ },
2990
+ style: { border: "none", background: "none", color: "var(--accent, #4d8dff)", cursor: "pointer", fontSize: 11 }
2991
+ },
2992
+ shareT("share.container.refresh")
2993
+ )
2994
+ ) : null
2995
+ );
2996
+ }
2574
2997
  function pageInfo() {
2575
2998
  const ua = typeof navigator !== "undefined" && navigator.userAgent || "";
2576
2999
  let os = "";
@@ -2641,7 +3064,8 @@ function errorText() {
2641
3064
  badSxcu: "share.err.badSxcu",
2642
3065
  noProbe: "share.err.noProbe",
2643
3066
  forbidden: "share.err.forbidden",
2644
- kind: "share.err.kind"
3067
+ kind: "share.err.kind",
3068
+ containerFail: "share.container.fail"
2645
3069
  }[code];
2646
3070
  if (key) return shareT(key, { name, detail });
2647
3071
  return state.error || shareT("share.err.generic", { detail });
@@ -2830,7 +3254,8 @@ async function doShare() {
2830
3254
  text: state.text,
2831
3255
  title: state.title,
2832
3256
  tags: state.tags,
2833
- redact: false
3257
+ redact: false,
3258
+ container: state.containerFor || ""
2834
3259
  };
2835
3260
  if (state.kind === "image" && body.imageSrc) {
2836
3261
  const blob = await fetch(body.imageSrc).then((r2) => {
@@ -2921,6 +3346,7 @@ function shareDialog() {
2921
3346
  previewSection(),
2922
3347
  sinkSection(),
2923
3348
  targetSection(),
3349
+ containerSection(),
2924
3350
  h(
2925
3351
  "div",
2926
3352
  { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 9 } },
@@ -3036,15 +3462,19 @@ function managerDialog() {
3036
3462
  opacity: t.status === "dead" ? 0.5 : 1
3037
3463
  }
3038
3464
  },
3039
- h("span", null, t.status === "dead" ? "\u{1F480}" : t.category === "archive" ? "\u{1F4D3}" : "\u{1F517}"),
3465
+ h("span", null, t.status === "dead" ? "\u{1F480}" : t.icon || (t.category === "archive" ? "\u{1F4D3}" : "\u{1F517}")),
3040
3466
  h(
3041
3467
  "div",
3042
3468
  { style: { flex: 1, minWidth: 0 } },
3043
3469
  h("div", { style: { fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, t.name || t.id),
3044
- h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)" } }, (t.kinds || []).map(kindLabel).join("/") + (() => {
3045
- const n = noteText(t.note);
3046
- return n ? " \xB7 " + n : "";
3047
- })())
3470
+ h(
3471
+ "div",
3472
+ { style: { fontSize: 10, color: "var(--text-muted, #8b909b)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } },
3473
+ (t.kinds || []).map(kindLabel).join("/") + (() => {
3474
+ const n = noteText(t.note);
3475
+ return n ? " \xB7 " + n : "";
3476
+ })() + (t.supportsContainers && t.lastContainerLabel ? " \xB7 \u{1F4D3} " + t.lastContainerLabel : "")
3477
+ )
3048
3478
  ),
3049
3479
  (() => {
3050
3480
  const b = CFG_BADGE[t.configState];
@@ -3058,7 +3488,7 @@ function managerDialog() {
3058
3488
  !supportsKind(t, contentKind()) ? h("span", {
3059
3489
  title: shareT("share.notCompatible", { kind: kindLabel(contentKind()) }),
3060
3490
  style: { color: "var(--text-muted, #8b909b)", fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 }
3061
- }, "\u2205") : t.status !== "dead" && t.configState !== "needs-setup" ? h("button", {
3491
+ }, "\u2205") : t.status !== "dead" && t.status !== "legacy" && t.configState !== "needs-setup" ? h("button", {
3062
3492
  type: "button",
3063
3493
  title: shareT("share.useTarget"),
3064
3494
  onClick: (e) => {
package/index.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  import { join, dirname } from "node:path";
9
9
  // @ts-ignore pure JS core shared with tests
10
10
  import { ShareStore, makeRedactor, publicTarget, exportSessionMarkdown, classifyFile, MAX_SHARE_FILE_BYTES } from "./lib/share-core.mjs";
11
+ // @ts-ignore pure JS icon rules shared with tests
12
+ import { resolveProviderIcon } from "./lib/provider-icons.mjs";
11
13
 
12
14
  let configDir = "";
13
15
  let stateDir = "";
@@ -66,6 +68,7 @@ async function ensureSecretEngine() {
66
68
  /** Derive a target's setup state for the UI: anonymous / ready / needs-setup. */
67
69
  function configState(entry: any, userTarget: any, reg: any): string {
68
70
  if (entry.status === "dead") return "dead";
71
+ if (entry.status === "legacy") return "legacy";
69
72
  const provider = reg.get(entry.id) || reg.get(userTarget?.provider);
70
73
  const required = (provider?.metaFields || []).filter((f: any) => f.required);
71
74
  // A user-created target with all required fields filled → ready.
@@ -98,12 +101,14 @@ function allTargets(reg) {
98
101
  return { ...t, custom: true, auth: entry?.auth ?? (t.provider === "custom" ? "key" : "none"),
99
102
  kinds: entry?.kinds ?? ["text"], category: entry?.category ?? "publish",
100
103
  fields: targetFields(t.provider, reg),
104
+ ...containerInfo(reg, t.provider),
101
105
  configState: configState(entry || { id: t.provider }, t, reg) };
102
106
  }),
103
107
  ...entries.filter((e) => !userByProvider.has(e.id)).map((e) => ({ id: e.id, name: e.name, provider: e.id,
104
108
  kinds: e.kinds, category: e.category, auth: e.auth, recommended: e.recommended, note: e.note,
105
109
  status: e.status, source: e.source, values: {},
106
110
  fields: targetFields(e.id, reg),
111
+ ...containerInfo(reg, e.id),
107
112
  configState: configState(e, null, reg) })),
108
113
  ];
109
114
  }
@@ -115,6 +120,16 @@ function findTarget(reg, id) {
115
120
  return entry ? { id: entry.id, provider: entry.id, values: {}, name: entry.name, kinds: entry.kinds, category: entry.category } : null;
116
121
  }
117
122
 
123
+ /** Provider UI metadata surfaced to the client: container picker visibility/label
124
+ * and the picker glyph. The catalog has no icon metadata, so the glyph comes from
125
+ * curated keyword rules (lib/provider-icons.mjs); null lets the client fall back
126
+ * to its category/status glyph. */
127
+ function containerInfo(reg: any, providerId: string) {
128
+ const p = reg.get(providerId);
129
+ const c = p?.containers;
130
+ return { supportsContainers: !!c, containerLabel: c?.label || null, icon: resolveProviderIcon(providerId, p) };
131
+ }
132
+
118
133
  export default {
119
134
  id: "aiti-msg-share",
120
135
  name: "消息分享",
@@ -217,6 +232,15 @@ export default {
217
232
  "share.cfg.ready": "Configured",
218
233
  "share.cfg.needs": "Needs setup",
219
234
  "share.cfg.dead": "Unavailable",
235
+ "share.cfg.legacy": "Outdated — upload path broken",
236
+ "share.container.label": "Notebook",
237
+ "share.container.default": "Service default",
238
+ "share.container.refresh": "Refresh containers",
239
+ "share.container.search": "Search notebooks…",
240
+ "share.container.empty": "No containers found",
241
+ "share.container.fail": "Could not list containers: {detail}",
242
+ "share.container.missing": "Last selection no longer exists — using default",
243
+ "share.container.matches": "{n} matches",
220
244
  },
221
245
  "zh-CN": {
222
246
  "share.err.forbidden": "该路径不在允许范围内——只能分享会话工作区内的文件。",
@@ -302,6 +326,16 @@ export default {
302
326
  "share.cfg.ready": "已配置",
303
327
  "share.cfg.needs": "需配置",
304
328
  "share.cfg.dead": "不可用",
329
+ "share.cfg.legacy": "已過時(上傳通道異常)",
330
+ "share.cfg.legacy": "已过时(上传通道异常)",
331
+ "share.container.label": "笔记本",
332
+ "share.container.default": "默认位置",
333
+ "share.container.refresh": "刷新容器列表",
334
+ "share.container.search": "搜索笔记本…",
335
+ "share.container.empty": "未找到容器",
336
+ "share.container.fail": "容器列表获取失败:{detail}",
337
+ "share.container.missing": "上次选择的容器已不存在,使用默认位置",
338
+ "share.container.matches": "{n} 条匹配",
305
339
  },
306
340
  "zh-TW": {
307
341
  "share.err.forbidden": "該路徑不在允許範圍內——只能分享工作階段工作區內的檔案。",
@@ -384,9 +418,17 @@ export default {
384
418
  "share.deleteTarget": "刪除目標",
385
419
  "share.notSet": "(未設定)",
386
420
  "share.cfg.anonymous": "匿名可用",
387
- "share.cfg.ready": "已設定",
388
- "share.cfg.needs": "需設定",
421
+ "share.cfg.ready": "已配置",
422
+ "share.cfg.needs": "需配置",
389
423
  "share.cfg.dead": "不可用",
424
+ "share.container.label": "筆記本",
425
+ "share.container.default": "預設位置",
426
+ "share.container.refresh": "重新整理容器列表",
427
+ "share.container.search": "搜尋筆記本…",
428
+ "share.container.empty": "未找到容器",
429
+ "share.container.fail": "容器列表取得失敗:{detail}",
430
+ "share.container.missing": "上次選擇的容器已不存在,使用預設位置",
431
+ "share.container.matches": "{n} 筆匹配",
390
432
  },
391
433
  },
392
434
  dialogs: [{ id: "aiti-msg-share-dialog", label: "aiti-msg-share" }],
@@ -420,13 +462,13 @@ export default {
420
462
  return json({ ok: true, targets: allTargets(reg), count: reg.catalog().length });
421
463
  }
422
464
 
423
- // GET /targets — persisted user targets
424
- if (p[0] === "targets" && req.method === "GET") {
465
+ // GET /targets — persisted user targets (!p[1]: sub-resources have own handlers)
466
+ if (p[0] === "targets" && !p[1] && req.method === "GET") {
425
467
  return json({ ok: true, targets: store.readTargets().map((t) => publicTarget(t, reg.get(t.provider))) });
426
468
  }
427
469
 
428
470
  // POST /targets — upsert a target (secrets stored raw, 0600; masked in responses)
429
- if (p[0] === "targets" && req.method === "POST") {
471
+ if (p[0] === "targets" && !p[1] && req.method === "POST") {
430
472
  const body = await req.json();
431
473
  if (!body?.id || !body?.provider) return json({ ok: false, error: "id and provider required", errorCode: "badRequest" }, 400);
432
474
  const saved = store.upsertTarget({ id: body.id, provider: body.provider, name: body.name || body.id,
@@ -450,6 +492,49 @@ export default {
450
492
  return json(await provider.probe({ provider: body.provider, values: body.values || {} }));
451
493
  }
452
494
 
495
+ // POST /containers — list selectable containers (Joplin notebooks, Obsidian dirs, …).
496
+ // Saved target: credentials come from the stored values; setup form: ad-hoc values.
497
+ // Credentials never leave the server — only {id,label,parent,path} are returned.
498
+ if (p[0] === "containers" && req.method === "POST") {
499
+ const body = await req.json().catch(() => null);
500
+ let providerId: string = body?.provider || "";
501
+ let values: Record<string, string> = body?.values || {};
502
+ if (body?.targetId) {
503
+ const t = findTarget(reg, body.targetId);
504
+ if (!t) return json({ ok: false, error: "unknown target", errorCode: "unknownTarget" }, 404);
505
+ providerId = t.provider;
506
+ values = t.values || {};
507
+ }
508
+ const provider = providerId ? reg.get(providerId) : null;
509
+ if (!provider?.containers) return json({ ok: true, supportsContainers: false, containers: [] });
510
+ try {
511
+ const containers = await provider.containers.list({ provider: providerId, values, container: "" },
512
+ typeof body?.parent === "string" ? body.parent : undefined);
513
+ return json({ ok: true, supportsContainers: true, containerLabel: provider.containers.label || null, containers });
514
+ } catch (err: any) {
515
+ return json({ ok: false, errorCode: "containerFail", error: String(err?.message || err),
516
+ detail: String(err?.message || err) }, 502);
517
+ }
518
+ }
519
+
520
+ // POST /targets/last-container — record the user's container pick on the target.
521
+ // Persisted in targets.json (0600): survives restarts and browsers; AI/headless
522
+ // shares fall back to it when the request carries no explicit container.
523
+ // recentContainers keeps a small quick-pick history (most recent distinct first).
524
+ if (p[0] === "targets" && p[1] === "last-container" && req.method === "POST") {
525
+ const body = await req.json().catch(() => null);
526
+ const t = store.readTargets().find((x) => x.id === body?.id);
527
+ if (!t) return json({ ok: false, error: "unknown target", errorCode: "unknownTarget" }, 404);
528
+ const container = String(body?.container ?? "");
529
+ const label = body?.label ? String(body.label) : (container ? t.lastContainerLabel || "" : "");
530
+ const recents: Array<{ id: string; label: string }> = (Array.isArray(t.recentContainers) ? t.recentContainers : [])
531
+ .filter((r: any) => r && r.id && r.id !== container).slice(0, 2);
532
+ const recentContainers = container ? [{ id: container, label }, ...recents] : recents;
533
+ const saved = store.upsertTarget({ ...t, lastContainer: container, lastContainerLabel: label,
534
+ lastContainerAt: new Date().toISOString(), recentContainers });
535
+ return json({ ok: true, target: publicTarget(saved, reg.get(saved.provider)) });
536
+ }
537
+
453
538
  // POST /import-sxcu — register a config at runtime + persist as a target
454
539
  if (p[0] === "import-sxcu" && req.method === "POST") {
455
540
  const body = await req.json();
@@ -540,9 +625,12 @@ export default {
540
625
  detail: `${(provider as any).label} accepts: ${kinds.join(", ")}` }, 400);
541
626
  }
542
627
  let result;
628
+ // Container selection: an explicit request wins ("" = service default);
629
+ // otherwise fall back to the target's recorded last selection (AI/headless path).
630
+ const container = typeof body.container === "string" ? body.container : String(target.lastContainer || "");
543
631
  try {
544
632
  result = await cs.share(provider, content,
545
- { provider: target.provider, values: target.values || {}, tags: meta.tags, pathPrefix: target.pathPrefix },
633
+ { provider: target.provider, values: target.values || {}, tags: meta.tags, pathPrefix: target.pathPrefix, container },
546
634
  meta, hooks);
547
635
  } catch (err: any) {
548
636
  // Turn a bare "fetch failed" into an actionable message (target + cause + hint).
@@ -566,6 +654,12 @@ export default {
566
654
  store.appendHistory({ at: new Date().toISOString(), targetId: target.id, kind,
567
655
  title: meta.title, url: result.url, extra: result.extra, hits: result.hits,
568
656
  redacted: doRedact, bytes: "text" in content ? Buffer.byteLength(content.text) : content.buffer.byteLength });
657
+ // Refresh the last-selection memory on success (bump timestamp only when the
658
+ // value changed) so headless/AI shares keep landing in the same notebook.
659
+ const stored = store.readTargets().find((t) => t.id === target.id);
660
+ if (stored && String(stored.lastContainer || "") !== container) {
661
+ store.upsertTarget({ ...stored, lastContainer: container, lastContainerAt: new Date().toISOString() });
662
+ }
569
663
  return json({ ok: true, ...result });
570
664
  }
571
665
 
@@ -0,0 +1,63 @@
1
+ /**
2
+ * provider-icons — curated per-target glyphs for the share picker (pure data, no DOM).
3
+ *
4
+ * The content-share catalog carries no icon/favicon metadata (checked against
5
+ * @aiti-ai/content-share 0.1.17: catalog entries have id/name/kinds/category/
6
+ * source/auth/note/status only, and providers have no icon field), so the old
7
+ * `icon: p?.icon` was always null. Rather than fetching third-party favicons
8
+ * (privacy + offline), resolve a stable local glyph:
9
+ *
10
+ * 1. provider.icon when a future catalog version supplies one (string or { emoji })
11
+ * 2. ordered keyword rules over the target id (ids are domain-ish: "imgur.com",
12
+ * "0x0.st (URL shortener)", "aliyun-oss", "gitee-gist", …)
13
+ * 3. null → the client keeps its category/status glyph
14
+ *
15
+ * Order matters: specific families first, generic "shortener"/"file" last.
16
+ */
17
+
18
+ /** Curated glyphs keyed by exact target id (the few curated aiti entries). */
19
+ const EXACT = {
20
+ "aliyun-oss": "☁️",
21
+ "gitee-gist": "🟠",
22
+ "local-link": "🔗",
23
+ custom: "⚙️",
24
+ };
25
+
26
+ /** Ordered keyword rules over the lower-cased target id. */
27
+ const RULES = [
28
+ [/(^|[^a-z])github|(^|[^a-z])gist|gitlab|git\.io|gitee|codeberg|sourcehut/, "💻"],
29
+ [/catbox|litterbox/, "🐱"],
30
+ [/shortener|short\.?url|\bshort\b/, "✂️"],
31
+ [/imgur|imgbb|freeimage|gyazo|chevereto|postimag|epvpimg|\bimage\b|\bimg\b|\bpic\b|photo|lsky/, "🖼️"],
32
+ [/paste|haste|dpaste|ghostbin|privatebin|ix\.io|0x0\.st/, "📋"],
33
+ [/\boss\b|s3|storage|qiniu|tencent|upyun|wasabi|minio|backblaze|\bb2\b|\br2\b|bucket/, "☁️"],
34
+ [/joplin|obsidian|notion|evernote/, "📓"],
35
+ [/telegram|discord|slack|feishu|lark|flomo|\bim\b/, "💬"],
36
+ [/\bmail|smtp|email/, "✉️"],
37
+ [/ipfs|ipns/, "🌐"],
38
+ [/local-link/, "🔗"],
39
+ [/webhook|httpreq|httpbin/, "🔗"],
40
+ [/\bfile\b|gofile|transfer|dropfile|filebin|tmpfiles|uguu|fuwa|fuck\.it|catbox/, "📦"],
41
+ ];
42
+
43
+ /**
44
+ * Resolve the glyph for one target.
45
+ * @param {string} providerId target id from the catalog
46
+ * @param {{ icon?: unknown } | null | undefined} provider registry provider (future metadata)
47
+ * @returns {string | null} glyph, or null so the client falls back
48
+ */
49
+ export function resolveProviderIcon(providerId, provider) {
50
+ const fromProvider = provider?.icon;
51
+ if (typeof fromProvider === "string" && fromProvider.trim()) return fromProvider.trim();
52
+ if (fromProvider && typeof fromProvider === "object" && typeof fromProvider.emoji === "string") {
53
+ return fromProvider.emoji.trim() || null;
54
+ }
55
+ const id = String(providerId || "").trim();
56
+ if (!id) return null;
57
+ if (EXACT[id]) return EXACT[id];
58
+ const lower = id.toLowerCase();
59
+ for (const [pattern, glyph] of RULES) {
60
+ if (pattern.test(lower)) return glyph;
61
+ }
62
+ return null;
63
+ }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@aiti-ai/aiti-msg-share",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "description": "Share sessions, messages, selections, files and images through pluggable targets with secret redaction and QR codes",
6
6
  "license": "MIT",
7
7
  "aitiExtProtocol": "1.0",
8
8
  "soul": "分享出去,是为了让对话继续。",
9
9
  "dependencies": {
10
- "@aiti-ai/content-share": "^0.1.11",
10
+ "@aiti-ai/content-share": "^0.1.16",
11
11
  "@aiti-ai/secret-mask-core": "^0.1.0",
12
12
  "qrcode": "^1.5.4"
13
13
  },
@@ -27,5 +27,5 @@
27
27
  "bugs": {
28
28
  "url": "https://github.com/aiti-ai/aiti-ai/issues"
29
29
  },
30
- "contentHash": "603e2fa84e7f66a0"
30
+ "contentHash": "fdc082bfb2d6a3cf"
31
31
  }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * provider-icons — curated glyph rules for the share picker (pure, no DOM).
3
+ * Run: node --test extensions/aiti-msg-share/test/provider-icons.test.mjs
4
+ */
5
+ import test from "node:test";
6
+ import assert from "node:assert/strict";
7
+ import { resolveProviderIcon } from "../lib/provider-icons.mjs";
8
+
9
+ test("exact curated ids win", () => {
10
+ assert.equal(resolveProviderIcon("aliyun-oss"), "☁️");
11
+ assert.equal(resolveProviderIcon("gitee-gist"), "🟠");
12
+ assert.equal(resolveProviderIcon("local-link"), "🔗");
13
+ assert.equal(resolveProviderIcon("custom"), "⚙️");
14
+ });
15
+
16
+ test("domain-shaped catalog ids map to families", () => {
17
+ assert.equal(resolveProviderIcon("imgur.com"), "🖼️");
18
+ assert.equal(resolveProviderIcon("imgbb.com"), "🖼️");
19
+ assert.equal(resolveProviderIcon("catbox.moe"), "🐱");
20
+ assert.equal(resolveProviderIcon("paste.rs"), "📋");
21
+ assert.equal(resolveProviderIcon("ix.io"), "📋");
22
+ assert.equal(resolveProviderIcon("Discord post"), "💬");
23
+ assert.equal(resolveProviderIcon("joplin"), "📓");
24
+ assert.equal(resolveProviderIcon("ipfs.io"), "🌐");
25
+ assert.equal(resolveProviderIcon("file.io"), "📦");
26
+ assert.equal(resolveProviderIcon("github-gist"), "💻");
27
+ });
28
+
29
+ test("multi-variant ids resolve by their variant, not the base host", () => {
30
+ assert.equal(resolveProviderIcon("0x0.st (URL shortener)"), "✂️");
31
+ assert.equal(resolveProviderIcon("0x0.st (Image uploader)"), "🖼️");
32
+ });
33
+
34
+ test("unknown ids return null so the client keeps its category glyph", () => {
35
+ assert.equal(resolveProviderIcon("example"), null);
36
+ assert.equal(resolveProviderIcon(""), null);
37
+ assert.equal(resolveProviderIcon(undefined), null);
38
+ assert.equal(resolveProviderIcon(null), null);
39
+ });
40
+
41
+ test("future provider metadata wins; invalid metadata falls through", () => {
42
+ assert.equal(resolveProviderIcon("imgur.com", { icon: "🔒" }), "🔒");
43
+ assert.equal(resolveProviderIcon("imgur.com", { icon: { emoji: "🅰️" } }), "🅰️");
44
+ assert.equal(resolveProviderIcon("imgur.com", { icon: {} }), "🖼️");
45
+ assert.equal(resolveProviderIcon("imgur.com", { icon: 42 }), "🖼️");
46
+ assert.equal(resolveProviderIcon("unknown-id", { icon: " " }), null);
47
+ });
@@ -59,3 +59,17 @@ test("classifyFile: image / text / binary by extension", async () => {
59
59
  assert.deepEqual(classifyFile("archive.tar.gz"), { kind: "binary", mime: "application/octet-stream" });
60
60
  assert.deepEqual(classifyFile("noext"), { kind: "binary", mime: "application/octet-stream" });
61
61
  });
62
+
63
+ test("ShareStore persists container last-selection fields", () => {
64
+ const dir = mkdtempSync(join(tmpdir(), "share-store-"));
65
+ const store = new ShareStore(join(dir, "config"), join(dir, "state"));
66
+ store.upsertTarget({ id: "joplin", provider: "joplin", values: { token: "t" } });
67
+ const t = store.readTargets()[0];
68
+ store.upsertTarget({ ...t, lastContainer: "nb1", lastContainerLabel: "My Notebook / Work", lastContainerAt: "2026-11-20T00:00:00.000Z" });
69
+ const back = store.readTargets()[0];
70
+ assert.equal(back.lastContainer, "nb1");
71
+ assert.equal(back.lastContainerLabel, "My Notebook / Work");
72
+ // Clearing the selection keeps the label empty too.
73
+ store.upsertTarget({ ...back, lastContainer: "", lastContainerLabel: "" });
74
+ assert.equal(store.readTargets()[0].lastContainer, "");
75
+ });