@decentnetwork/beagle 0.1.153 → 0.1.154
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/dist/desktop/app.js +430 -10
- package/package.json +2 -2
package/dist/desktop/app.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
window.__DK_UI_VERSION="0.1.
|
|
1
|
+
window.__DK_UI_VERSION="0.1.154";
|
|
2
2
|
"use strict";
|
|
3
3
|
(() => {
|
|
4
4
|
// packages/beagle-ui/dist/beagle-ui.js
|
|
@@ -2203,9 +2203,276 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2203
2203
|
return ["ok", zh ? "WebRTC \u5931\u8D25,\u5DF2\u901A\u8FC7 Carrier \u53D1\u9001" : "WebRTC failed \u2014 sent via Carrier"];
|
|
2204
2204
|
return ["ok", successFlash(done, lang)];
|
|
2205
2205
|
}
|
|
2206
|
+
var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
|
|
2207
|
+
var DROP = /* @__PURE__ */ new Set(["script", "style", "head", "title", "template", "noscript", "svg", "math", "iframe", "object", "canvas", "video", "audio", "select", "button", "textarea"]);
|
|
2208
|
+
var PARA = /* @__PURE__ */ new Set(["p", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "pre", "blockquote", "table", "hr", "figure", "section", "article", "header", "footer", "main", "aside", "nav", "dl"]);
|
|
2209
|
+
var LINE = /* @__PURE__ */ new Set(["div", "li", "tr", "dt", "dd", "figcaption", "address", "details", "summary", "caption"]);
|
|
2210
|
+
var SEMANTIC = /<(h[1-6]|b|strong|i|em|a\s|ul|ol|li|code|pre|table|blockquote)\b|font-weight:\s*(bold|[6-9]00)|font-style:\s*italic/i;
|
|
2211
|
+
var ENT = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " ", ensp: " ", emsp: " ", thinsp: " ", hellip: "\u2026", mdash: "\u2014", ndash: "\u2013", lsquo: "\u2018", rsquo: "\u2019", ldquo: "\u201C", rdquo: "\u201D", bull: "\u2022", middot: "\xB7", copy: "\xA9", reg: "\xAE", trade: "\u2122", times: "\xD7" };
|
|
2212
|
+
function decodeEntities(s) {
|
|
2213
|
+
return String(s).replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e) => {
|
|
2214
|
+
if (e[0] === "#") {
|
|
2215
|
+
const n = e[1] === "x" || e[1] === "X" ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
2216
|
+
try {
|
|
2217
|
+
return n > 0 && n < 1114112 ? String.fromCodePoint(n) : m;
|
|
2218
|
+
} catch (x) {
|
|
2219
|
+
return m;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
const v = ENT[e.toLowerCase()];
|
|
2223
|
+
return v != null ? v : m;
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
function attrsOf(src) {
|
|
2227
|
+
const out = {};
|
|
2228
|
+
const re = /([^\s=/>]+)(?:\s*=\s*("([^"]*)"|'([^']*)'|([^\s>]+)))?/g;
|
|
2229
|
+
let m;
|
|
2230
|
+
while (m = re.exec(src))
|
|
2231
|
+
out[m[1].toLowerCase()] = decodeEntities(m[3] != null ? m[3] : m[4] != null ? m[4] : m[5] != null ? m[5] : "");
|
|
2232
|
+
return out;
|
|
2233
|
+
}
|
|
2234
|
+
function parseHtml(html) {
|
|
2235
|
+
const root = { tag: "#root", attrs: {}, children: [] };
|
|
2236
|
+
const stack = [root];
|
|
2237
|
+
const top = () => stack[stack.length - 1];
|
|
2238
|
+
const src = String(html || "");
|
|
2239
|
+
const re = /<!--[\s\S]*?(?:-->|$)|<!\[CDATA\[[\s\S]*?\]\]>|<![^>]*>|<\?[^>]*>|<\/\s*([a-zA-Z][\w:-]*)\s*>|<([a-zA-Z][\w:-]*)((?:[^>"']|"[^"]*"|'[^']*')*)>/g;
|
|
2240
|
+
let last = 0;
|
|
2241
|
+
let m;
|
|
2242
|
+
const text = (s) => {
|
|
2243
|
+
if (s)
|
|
2244
|
+
top().children.push({ text: decodeEntities(s) });
|
|
2245
|
+
};
|
|
2246
|
+
const closeTo = (tag) => {
|
|
2247
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
2248
|
+
if (stack[i].tag === tag) {
|
|
2249
|
+
stack.length = i;
|
|
2250
|
+
return true;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
return false;
|
|
2254
|
+
};
|
|
2255
|
+
while (m = re.exec(src)) {
|
|
2256
|
+
text(src.slice(last, m.index));
|
|
2257
|
+
last = re.lastIndex;
|
|
2258
|
+
if (m[1]) {
|
|
2259
|
+
closeTo(m[1].toLowerCase());
|
|
2260
|
+
continue;
|
|
2261
|
+
}
|
|
2262
|
+
if (!m[2])
|
|
2263
|
+
continue;
|
|
2264
|
+
const tag = m[2].toLowerCase();
|
|
2265
|
+
const raw = m[3] || "";
|
|
2266
|
+
if (DROP.has(tag) && !/\/\s*$/.test(raw)) {
|
|
2267
|
+
const end = new RegExp("</\\s*" + tag + "\\s*>", "ig");
|
|
2268
|
+
end.lastIndex = last;
|
|
2269
|
+
const e = end.exec(src);
|
|
2270
|
+
last = re.lastIndex = e ? end.lastIndex : src.length;
|
|
2271
|
+
continue;
|
|
2272
|
+
}
|
|
2273
|
+
if (PARA.has(tag) || tag === "li" || LINE.has(tag)) {
|
|
2274
|
+
if (top().tag === "p")
|
|
2275
|
+
stack.pop();
|
|
2276
|
+
}
|
|
2277
|
+
if (tag === "li") {
|
|
2278
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
2279
|
+
if (stack[i].tag === "ul" || stack[i].tag === "ol")
|
|
2280
|
+
break;
|
|
2281
|
+
if (stack[i].tag === "li") {
|
|
2282
|
+
stack.length = i;
|
|
2283
|
+
break;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
const node = { tag, attrs: attrsOf(raw), children: [] };
|
|
2288
|
+
top().children.push(node);
|
|
2289
|
+
if (!VOID.has(tag) && !/\/\s*$/.test(raw))
|
|
2290
|
+
stack.push(node);
|
|
2291
|
+
}
|
|
2292
|
+
text(src.slice(last));
|
|
2293
|
+
return root;
|
|
2294
|
+
}
|
|
2295
|
+
var styleOf = (n) => String(n.attrs && n.attrs.style || "").toLowerCase();
|
|
2296
|
+
var isBoldStyle = (s) => /font-weight:\s*(bold|bolder|[6-9]00)\b/.test(s);
|
|
2297
|
+
var isPlainWeight = (s) => /font-weight:\s*(normal|[1-4]00)\b/.test(s);
|
|
2298
|
+
function safeHref(h) {
|
|
2299
|
+
const v = String(h || "").trim();
|
|
2300
|
+
return /^(https?:|mailto:)/i.test(v) ? v : "";
|
|
2301
|
+
}
|
|
2302
|
+
function wrap(s, mark) {
|
|
2303
|
+
const mm = /^(\s*)([\s\S]*?)(\s*)$/.exec(s);
|
|
2304
|
+
if (!mm[2])
|
|
2305
|
+
return s;
|
|
2306
|
+
return mm[1] + mm[2].split("\n").map((l) => l.trim() ? mark + l.trim() + mark : l).join("\n") + mm[3];
|
|
2307
|
+
}
|
|
2308
|
+
function inline(n, ctx) {
|
|
2309
|
+
if (n.text != null)
|
|
2310
|
+
return ctx.pre ? n.text : n.text.replace(/[ \t\r\n\f ]+/g, " ");
|
|
2311
|
+
const tag = n.tag;
|
|
2312
|
+
if (tag === "br")
|
|
2313
|
+
return "\n";
|
|
2314
|
+
if (tag === "img" || VOID.has(tag))
|
|
2315
|
+
return "";
|
|
2316
|
+
const st = styleOf(n);
|
|
2317
|
+
let bold = tag === "b" || tag === "strong" || isBoldStyle(st);
|
|
2318
|
+
if ((tag === "b" || tag === "strong") && isPlainWeight(st))
|
|
2319
|
+
bold = false;
|
|
2320
|
+
const italic = tag === "i" || tag === "em" || /font-style:\s*italic/.test(st);
|
|
2321
|
+
if (tag === "code" && !ctx.pre) {
|
|
2322
|
+
const t = n.children.map((c) => inline(c, { ...ctx, code: true })).join("");
|
|
2323
|
+
return t.trim() ? "`" + t.replace(/`/g, "'").replace(/\n/g, " ") + "`" : t;
|
|
2324
|
+
}
|
|
2325
|
+
const inner = n.children.map((c) => inline(c, { ...ctx, bold: ctx.bold || bold, italic: ctx.italic || italic })).join("");
|
|
2326
|
+
if (tag === "a") {
|
|
2327
|
+
const href = safeHref(n.attrs.href);
|
|
2328
|
+
const label = inner.replace(/\s+/g, " ").trim();
|
|
2329
|
+
if (!href)
|
|
2330
|
+
return inner;
|
|
2331
|
+
if (!label || label === href || label === href.replace(/^mailto:/i, ""))
|
|
2332
|
+
return " " + href + " ";
|
|
2333
|
+
return "[" + label.replace(/[[\]]/g, "") + "](" + href.replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\s/g, "%20") + ")";
|
|
2334
|
+
}
|
|
2335
|
+
let out = inner;
|
|
2336
|
+
if (bold && !ctx.bold && !ctx.code)
|
|
2337
|
+
out = wrap(out, "**");
|
|
2338
|
+
if (italic && !ctx.italic && !ctx.code && !(bold && !ctx.bold))
|
|
2339
|
+
out = wrap(out, "*");
|
|
2340
|
+
return out;
|
|
2341
|
+
}
|
|
2342
|
+
function rawText(n) {
|
|
2343
|
+
if (n.text != null)
|
|
2344
|
+
return n.text;
|
|
2345
|
+
if (n.tag === "br")
|
|
2346
|
+
return "\n";
|
|
2347
|
+
return n.children.map(rawText).join("");
|
|
2348
|
+
}
|
|
2349
|
+
function hasBlock(n) {
|
|
2350
|
+
return (n.children || []).some((c) => c.text == null && (PARA.has(c.tag) || LINE.has(c.tag) || hasBlock(c)));
|
|
2351
|
+
}
|
|
2352
|
+
function blocks(n, ctx, out) {
|
|
2353
|
+
let buf = "";
|
|
2354
|
+
const flush = (gap) => {
|
|
2355
|
+
const t = buf.split("\n").map((l) => l.replace(/[ \t]+/g, " ").trim()).join("\n").replace(/^\n+|\n+$/g, "");
|
|
2356
|
+
if (t)
|
|
2357
|
+
out.push({ text: (ctx.prefix || "") + t.split("\n").join("\n" + (ctx.cont || ctx.prefix || "")), gap });
|
|
2358
|
+
buf = "";
|
|
2359
|
+
};
|
|
2360
|
+
for (const c of n.children) {
|
|
2361
|
+
if (c.text == null && !(PARA.has(c.tag) || LINE.has(c.tag)) && hasBlock(c)) {
|
|
2362
|
+
flush(out.length ? 1 : 0);
|
|
2363
|
+
blocks(c, ctx, out);
|
|
2364
|
+
continue;
|
|
2365
|
+
}
|
|
2366
|
+
if (c.text != null || !(PARA.has(c.tag) || LINE.has(c.tag))) {
|
|
2367
|
+
buf += inline(c, ctx);
|
|
2368
|
+
continue;
|
|
2369
|
+
}
|
|
2370
|
+
flush(out.length ? 1 : 0);
|
|
2371
|
+
const tag = c.tag;
|
|
2372
|
+
const h = /^h([1-6])$/.exec(tag);
|
|
2373
|
+
if (h) {
|
|
2374
|
+
const t = c.children.map((x) => inline(x, { ...ctx, bold: true })).join("").replace(/\s+/g, " ").trim();
|
|
2375
|
+
if (t)
|
|
2376
|
+
out.push({ text: "#".repeat(Number(h[1])) + " " + t, gap: 2 });
|
|
2377
|
+
} else if (tag === "pre") {
|
|
2378
|
+
const code = rawText(c).replace(/\n+$/, "");
|
|
2379
|
+
if (code.trim())
|
|
2380
|
+
out.push({ text: "```\n" + code + "\n```", gap: 2 });
|
|
2381
|
+
} else if (tag === "hr") {
|
|
2382
|
+
} else if (tag === "ul" || tag === "ol") {
|
|
2383
|
+
listLines(c, 0, ctx).forEach((t, i) => out.push({ text: t, gap: i === 0 ? 2 : 1 }));
|
|
2384
|
+
} else if (tag === "blockquote") {
|
|
2385
|
+
const sub = [];
|
|
2386
|
+
blocks(c, { ...ctx, prefix: "", cont: "" }, sub);
|
|
2387
|
+
const t = joinBlocks(sub);
|
|
2388
|
+
if (t)
|
|
2389
|
+
out.push({ text: t.split("\n").map((l) => "> " + l).join("\n"), gap: 2 });
|
|
2390
|
+
} else if (tag === "table") {
|
|
2391
|
+
const rows = [];
|
|
2392
|
+
const walk = (x) => {
|
|
2393
|
+
for (const y of x.children || []) {
|
|
2394
|
+
if (y.tag === "tr")
|
|
2395
|
+
rows.push(y);
|
|
2396
|
+
else if (y.children)
|
|
2397
|
+
walk(y);
|
|
2398
|
+
}
|
|
2399
|
+
};
|
|
2400
|
+
walk(c);
|
|
2401
|
+
const lines = rows.map((r) => r.children.filter((d) => d.tag === "td" || d.tag === "th").map((d) => d.children.map((x) => inline(x, ctx)).join("").replace(/\s+/g, " ").trim()).join(" | ")).filter(Boolean);
|
|
2402
|
+
if (lines.length)
|
|
2403
|
+
out.push({ text: lines.join("\n"), gap: 2 });
|
|
2404
|
+
} else {
|
|
2405
|
+
const sub = [];
|
|
2406
|
+
blocks(c, ctx, sub);
|
|
2407
|
+
const gap = PARA.has(tag) ? 2 : 1;
|
|
2408
|
+
sub.forEach((s, i) => out.push({ text: s.text, gap: i === 0 ? gap : s.gap }));
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
flush(out.length ? 1 : 0);
|
|
2412
|
+
return out;
|
|
2413
|
+
}
|
|
2414
|
+
function listLines(list, depth, ctx) {
|
|
2415
|
+
const lines = [];
|
|
2416
|
+
let k = Number(list.attrs && list.attrs.start) || 1;
|
|
2417
|
+
const isList = (x) => x.tag === "ul" || x.tag === "ol";
|
|
2418
|
+
for (const li of list.children) {
|
|
2419
|
+
if (isList(li)) {
|
|
2420
|
+
lines.push(...listLines(li, depth + 1, ctx));
|
|
2421
|
+
continue;
|
|
2422
|
+
}
|
|
2423
|
+
if (li.tag !== "li")
|
|
2424
|
+
continue;
|
|
2425
|
+
const own = { tag: "li", attrs: {}, children: li.children.filter((x) => !isList(x)) };
|
|
2426
|
+
const text = joinBlocks(blocks(own, ctx, [])).replace(/\s*\n\s*/g, " ").trim();
|
|
2427
|
+
lines.push(" ".repeat(depth) + (list.tag === "ol" ? k++ + ". " : "- ") + text);
|
|
2428
|
+
for (const sub of li.children)
|
|
2429
|
+
if (isList(sub))
|
|
2430
|
+
lines.push(...listLines(sub, depth + 1, ctx));
|
|
2431
|
+
}
|
|
2432
|
+
return lines;
|
|
2433
|
+
}
|
|
2434
|
+
function joinBlocks(list) {
|
|
2435
|
+
let s = "";
|
|
2436
|
+
for (const b of list) {
|
|
2437
|
+
if (!b.text)
|
|
2438
|
+
continue;
|
|
2439
|
+
s += s ? (b.gap >= 2 ? "\n\n" : "\n") + b.text : b.text;
|
|
2440
|
+
}
|
|
2441
|
+
return s;
|
|
2442
|
+
}
|
|
2443
|
+
function hasFormatting(html) {
|
|
2444
|
+
return SEMANTIC.test(String(html || ""));
|
|
2445
|
+
}
|
|
2446
|
+
function htmlToMarkdown(html) {
|
|
2447
|
+
let src = String(html || "");
|
|
2448
|
+
const fs = src.indexOf("<!--StartFragment-->");
|
|
2449
|
+
const fe = src.indexOf("<!--EndFragment-->");
|
|
2450
|
+
if (fs >= 0 && fe > fs)
|
|
2451
|
+
src = src.slice(fs + 20, fe);
|
|
2452
|
+
const tree = parseHtml(src);
|
|
2453
|
+
const md = joinBlocks(blocks(tree, {}, [])).replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").replace(/\*\*\*\*/g, "").trim();
|
|
2454
|
+
return md;
|
|
2455
|
+
}
|
|
2456
|
+
function pasteText(html, plain) {
|
|
2457
|
+
if (!html || !hasFormatting(html))
|
|
2458
|
+
return null;
|
|
2459
|
+
const md = htmlToMarkdown(html);
|
|
2460
|
+
if (!md)
|
|
2461
|
+
return null;
|
|
2462
|
+
return md;
|
|
2463
|
+
}
|
|
2464
|
+
function pastedFileName(file, i = 0, now = /* @__PURE__ */ new Date()) {
|
|
2465
|
+
const ext = (/\/(png|jpe?g|gif|webp|bmp|heic|avif)$/i.exec(file && file.type || "") || [])[1] || "png";
|
|
2466
|
+
const p = (n) => String(n).padStart(2, "0");
|
|
2467
|
+
const stamp = now.getFullYear() + p(now.getMonth() + 1) + p(now.getDate()) + "-" + p(now.getHours()) + p(now.getMinutes()) + p(now.getSeconds());
|
|
2468
|
+
const generic = !file || !file.name || /^image\.(png|jpe?g|gif|webp|bmp)$/i.test(file.name);
|
|
2469
|
+
if (!generic)
|
|
2470
|
+
return file.name;
|
|
2471
|
+
return "pasted-" + stamp + (i ? "-" + (i + 1) : "") + "." + ext.toLowerCase().replace("jpeg", "jpg");
|
|
2472
|
+
}
|
|
2206
2473
|
var PROOF_KEY = { eth: "proof.eth", sol: "proof.sol" };
|
|
2207
2474
|
var HEAD = "Beagle wallet binding";
|
|
2208
|
-
var
|
|
2475
|
+
var LINE2 = "I bind this wallet to my Beagle identity.";
|
|
2209
2476
|
var ADDRESS_RE = { eth: /^0x[0-9a-fA-F]{40}$/, sol: /^[1-9A-HJ-NP-Za-km-z]{32,44}$/ };
|
|
2210
2477
|
var USERID_RE = /^[1-9A-HJ-NP-Za-km-z]{32,48}$/;
|
|
2211
2478
|
var ISSUED_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
@@ -2223,7 +2490,7 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
2223
2490
|
throw new Error("wallet proof: bad chain or address");
|
|
2224
2491
|
if (!ISSUED_RE.test(String(issued || "")))
|
|
2225
2492
|
throw new Error("wallet proof: bad issued time");
|
|
2226
|
-
return [HEAD, "",
|
|
2493
|
+
return [HEAD, "", LINE2, "", `userid: ${userid}`, `chain: ${chain}`, `address: ${address}`, `issued: ${issued}`].join("\n");
|
|
2227
2494
|
}
|
|
2228
2495
|
var B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2229
2496
|
function base58Encode(bytes) {
|
|
@@ -3833,6 +4100,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
3833
4100
|
const rtcFile = !mine && !m.file ? dkRtcFileFromText(peer.userId || peer.id, m.text) : null;
|
|
3834
4101
|
const callRec = !m.file ? dkCallFromText(m.text) : null;
|
|
3835
4102
|
const mentionsMe = isGroup && !mine && !m.file && typeof m.text === "string" && messageMentionsMe(m.text, mentionNames());
|
|
4103
|
+
const copyText = !m.file && !nativeMedia && !rtcFile && !callRec && typeof read.text === "string" && read.text.trim() ? read.text : "";
|
|
4104
|
+
const [copied, setCopied] = React.useState(false);
|
|
3836
4105
|
return /* @__PURE__ */ React.createElement(
|
|
3837
4106
|
"div",
|
|
3838
4107
|
{
|
|
@@ -4199,7 +4468,24 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
4199
4468
|
return null;
|
|
4200
4469
|
const title = mine ? via === "offline" ? T.viaOutOffline || "posted to the offline relay \u2014 they get it when they come online" : T.viaOutOnline || "sent over a live session (online)" : via === "offline" ? "delivered via express relay (offline)" : "delivered over a live session (online)";
|
|
4201
4470
|
return /* @__PURE__ */ React.createElement("span", { title, style: { fontFamily: "var(--mono)", fontSize: 9, color: via === "offline" ? "#f59e0b" : "var(--faint)" } }, via === "offline" ? "\u79BB\u7EBF" : "\u5728\u7EBF");
|
|
4202
|
-
})(), !selMode &&
|
|
4471
|
+
})(), !selMode && copyText && /* @__PURE__ */ React.createElement(
|
|
4472
|
+
"button",
|
|
4473
|
+
{
|
|
4474
|
+
"data-testid": "msg-copy",
|
|
4475
|
+
title: copied ? T.copied || "copied" : T.copyMarkdown || "copy (Markdown)",
|
|
4476
|
+
onClick: (e) => {
|
|
4477
|
+
e.stopPropagation();
|
|
4478
|
+
dkCopy(copyText).then((ok) => {
|
|
4479
|
+
if (ok !== false) {
|
|
4480
|
+
setCopied(true);
|
|
4481
|
+
setTimeout(() => setCopied(false), 1200);
|
|
4482
|
+
}
|
|
4483
|
+
});
|
|
4484
|
+
},
|
|
4485
|
+
style: { background: "none", border: "none", cursor: "pointer", padding: 0, marginLeft: 2, display: "inline-flex", opacity: copied ? 1 : 0.55 }
|
|
4486
|
+
},
|
|
4487
|
+
/* @__PURE__ */ React.createElement(Icon, { name: copied ? "check" : "copy", size: 11, stroke: 2, color: copied ? "var(--accent)" : "var(--faint)" })
|
|
4488
|
+
), !selMode && m.id && /* @__PURE__ */ React.createElement(
|
|
4203
4489
|
"button",
|
|
4204
4490
|
{
|
|
4205
4491
|
title: T.delete || "delete",
|
|
@@ -4563,6 +4849,88 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
4563
4849
|
React.useEffect(() => {
|
|
4564
4850
|
setDraft("");
|
|
4565
4851
|
}, [peer.id]);
|
|
4852
|
+
React.useLayoutEffect(() => {
|
|
4853
|
+
const el = inputRef.current;
|
|
4854
|
+
if (!el)
|
|
4855
|
+
return;
|
|
4856
|
+
el.style.height = "auto";
|
|
4857
|
+
el.style.height = Math.min(el.scrollHeight + 2, 180) + "px";
|
|
4858
|
+
}, [draft]);
|
|
4859
|
+
const [pending, setPending] = React.useState([]);
|
|
4860
|
+
const pendingRef = React.useRef(pending);
|
|
4861
|
+
pendingRef.current = pending;
|
|
4862
|
+
const dropPending = (keep) => setPending((arr) => {
|
|
4863
|
+
arr.forEach((p) => {
|
|
4864
|
+
if (p.url && !(keep && keep.includes(p)))
|
|
4865
|
+
URL.revokeObjectURL(p.url);
|
|
4866
|
+
});
|
|
4867
|
+
return keep || [];
|
|
4868
|
+
});
|
|
4869
|
+
React.useEffect(() => () => pendingRef.current.forEach((p) => p.url && URL.revokeObjectURL(p.url)), []);
|
|
4870
|
+
React.useEffect(() => {
|
|
4871
|
+
dropPending();
|
|
4872
|
+
}, [peer.id]);
|
|
4873
|
+
const addPending = (files, pasted) => {
|
|
4874
|
+
const list = Array.from(files || []).filter(Boolean);
|
|
4875
|
+
if (!list.length || peer.app)
|
|
4876
|
+
return;
|
|
4877
|
+
const items = list.map((f, i) => {
|
|
4878
|
+
const file = pasted ? new File([f], pastedFileName(f, i), { type: f.type || "image/png" }) : f;
|
|
4879
|
+
const image = /^image\//.test(file.type || "");
|
|
4880
|
+
return { id: Math.random().toString(36).slice(2), file, image, url: image ? URL.createObjectURL(file) : null };
|
|
4881
|
+
});
|
|
4882
|
+
setPending((arr) => arr.concat(items).slice(0, 20));
|
|
4883
|
+
};
|
|
4884
|
+
const removePending = (id) => {
|
|
4885
|
+
dropPending(pendingRef.current.filter((p) => p.id !== id));
|
|
4886
|
+
requestAnimationFrame(() => inputRef.current && inputRef.current.focus());
|
|
4887
|
+
};
|
|
4888
|
+
const insertAtCaret = (text) => {
|
|
4889
|
+
const el = inputRef.current;
|
|
4890
|
+
const a = el ? el.selectionStart : draft.length;
|
|
4891
|
+
const b = el ? el.selectionEnd : draft.length;
|
|
4892
|
+
const next = draft.slice(0, a) + text + draft.slice(b);
|
|
4893
|
+
setDraft(next);
|
|
4894
|
+
histIdx.current = null;
|
|
4895
|
+
const caret = a + text.length;
|
|
4896
|
+
requestAnimationFrame(() => {
|
|
4897
|
+
const e2 = inputRef.current;
|
|
4898
|
+
if (e2) {
|
|
4899
|
+
e2.focus();
|
|
4900
|
+
try {
|
|
4901
|
+
e2.setSelectionRange(caret, caret);
|
|
4902
|
+
} catch (x) {
|
|
4903
|
+
}
|
|
4904
|
+
}
|
|
4905
|
+
});
|
|
4906
|
+
};
|
|
4907
|
+
const onPaste = (e) => {
|
|
4908
|
+
const cd = e.clipboardData;
|
|
4909
|
+
if (!cd)
|
|
4910
|
+
return;
|
|
4911
|
+
const files = [];
|
|
4912
|
+
for (const it of Array.from(cd.items || [])) {
|
|
4913
|
+
if (it.kind === "file") {
|
|
4914
|
+
const f = it.getAsFile();
|
|
4915
|
+
if (f)
|
|
4916
|
+
files.push(f);
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
if (!files.length && cd.files && cd.files.length)
|
|
4920
|
+
files.push(...Array.from(cd.files));
|
|
4921
|
+
const md = pasteText(cd.getData("text/html"), cd.getData("text/plain"));
|
|
4922
|
+
if (files.length && !peer.app) {
|
|
4923
|
+
e.preventDefault();
|
|
4924
|
+
addPending(files, true);
|
|
4925
|
+
if (md)
|
|
4926
|
+
insertAtCaret(md);
|
|
4927
|
+
return;
|
|
4928
|
+
}
|
|
4929
|
+
if (md) {
|
|
4930
|
+
e.preventDefault();
|
|
4931
|
+
insertAtCaret(md);
|
|
4932
|
+
}
|
|
4933
|
+
};
|
|
4566
4934
|
React.useEffect(() => {
|
|
4567
4935
|
setTheater(null);
|
|
4568
4936
|
}, [peer.id]);
|
|
@@ -4577,6 +4945,11 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
4577
4945
|
return () => window.removeEventListener("keydown", onKey);
|
|
4578
4946
|
}, [theater]);
|
|
4579
4947
|
const sendDraft = () => {
|
|
4948
|
+
if (pending.length) {
|
|
4949
|
+
followScrollRef.current = true;
|
|
4950
|
+
sendFiles(pending.map((p) => p.file));
|
|
4951
|
+
dropPending();
|
|
4952
|
+
}
|
|
4580
4953
|
if (draft.trim()) {
|
|
4581
4954
|
followScrollRef.current = true;
|
|
4582
4955
|
rememberCommand(draft.trim());
|
|
@@ -4614,7 +4987,8 @@ ${lines}`, { assistant: { kind: "adopt", rows: fresh } }));
|
|
|
4614
4987
|
const onDrop = (e) => {
|
|
4615
4988
|
e.preventDefault();
|
|
4616
4989
|
setDragOver(false);
|
|
4617
|
-
|
|
4990
|
+
addPending(e.dataTransfer.files, false);
|
|
4991
|
+
requestAnimationFrame(() => inputRef.current && inputRef.current.focus());
|
|
4618
4992
|
};
|
|
4619
4993
|
return /* @__PURE__ */ React.createElement(
|
|
4620
4994
|
"div",
|
|
@@ -4810,7 +5184,48 @@ ${peer.address}`
|
|
|
4810
5184
|
},
|
|
4811
5185
|
lang === "zh" ? "\u5173\u95ED" : "dismiss"
|
|
4812
5186
|
)
|
|
4813
|
-
))), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex",
|
|
5187
|
+
))), pending.length > 0 && /* @__PURE__ */ React.createElement("div", { "data-testid": "composer-attachments", style: { maxWidth: 1200, margin: "0 auto 8px", display: "flex", flexWrap: "wrap", gap: 8 } }, pending.map((p) => /* @__PURE__ */ React.createElement(
|
|
5188
|
+
"div",
|
|
5189
|
+
{
|
|
5190
|
+
key: p.id,
|
|
5191
|
+
"data-testid": "composer-attachment",
|
|
5192
|
+
title: p.file.name + " \xB7 " + dkFileSize(p.file.size),
|
|
5193
|
+
style: {
|
|
5194
|
+
position: "relative",
|
|
5195
|
+
borderRadius: 9,
|
|
5196
|
+
border: "1px solid var(--line)",
|
|
5197
|
+
background: "var(--panel-2)",
|
|
5198
|
+
overflow: "hidden",
|
|
5199
|
+
...p.image ? { width: 72, height: 72 } : { height: 40, maxWidth: 220, display: "flex", alignItems: "center", gap: 6, padding: "0 28px 0 10px" }
|
|
5200
|
+
}
|
|
5201
|
+
},
|
|
5202
|
+
p.image ? /* @__PURE__ */ React.createElement("img", { src: p.url, alt: p.file.name, style: { width: "100%", height: "100%", objectFit: "cover", display: "block" } }) : /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Icon, { name: "paperclip", size: 14, stroke: 2, color: "var(--faint)" }), /* @__PURE__ */ React.createElement("span", { style: { fontFamily: "var(--mono)", fontSize: 11.5, color: "var(--dim)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" } }, p.file.name)),
|
|
5203
|
+
/* @__PURE__ */ React.createElement(
|
|
5204
|
+
"button",
|
|
5205
|
+
{
|
|
5206
|
+
"data-testid": "composer-attachment-remove",
|
|
5207
|
+
onClick: () => removePending(p.id),
|
|
5208
|
+
title: lang === "zh" ? "\u79FB\u9664" : "Remove",
|
|
5209
|
+
"aria-label": lang === "zh" ? "\u79FB\u9664" : "Remove",
|
|
5210
|
+
style: {
|
|
5211
|
+
position: "absolute",
|
|
5212
|
+
top: 3,
|
|
5213
|
+
right: 3,
|
|
5214
|
+
width: 20,
|
|
5215
|
+
height: 20,
|
|
5216
|
+
borderRadius: 999,
|
|
5217
|
+
border: "none",
|
|
5218
|
+
cursor: "pointer",
|
|
5219
|
+
padding: 0,
|
|
5220
|
+
background: "rgba(0,0,0,0.62)",
|
|
5221
|
+
display: "flex",
|
|
5222
|
+
alignItems: "center",
|
|
5223
|
+
justifyContent: "center"
|
|
5224
|
+
}
|
|
5225
|
+
},
|
|
5226
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "x", size: 12, stroke: 2.4, color: "#fff" })
|
|
5227
|
+
)
|
|
5228
|
+
))), /* @__PURE__ */ React.createElement("div", { style: { maxWidth: 1200, margin: "0 auto", display: "flex", alignItems: "flex-end", gap: phone ? 6 : 10 } }, /* @__PURE__ */ React.createElement(
|
|
4814
5229
|
"input",
|
|
4815
5230
|
{
|
|
4816
5231
|
ref: fileRef,
|
|
@@ -4864,10 +5279,13 @@ ${peer.address}`
|
|
|
4864
5279
|
/* @__PURE__ */ React.createElement("span", { style: { fontWeight: 600, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, "@", c.insert),
|
|
4865
5280
|
c.insert !== c.sender && /* @__PURE__ */ React.createElement("span", { style: { fontSize: 11, color: "var(--faint)", whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, c.sender)
|
|
4866
5281
|
))), /* @__PURE__ */ React.createElement(
|
|
4867
|
-
"
|
|
5282
|
+
"textarea",
|
|
4868
5283
|
{
|
|
4869
5284
|
ref: inputRef,
|
|
5285
|
+
rows: 1,
|
|
5286
|
+
"data-testid": "composer",
|
|
4870
5287
|
value: draft,
|
|
5288
|
+
onPaste,
|
|
4871
5289
|
onChange: (e) => {
|
|
4872
5290
|
histIdx.current = null;
|
|
4873
5291
|
setDraft(e.target.value);
|
|
@@ -4900,18 +5318,18 @@ ${peer.address}`
|
|
|
4900
5318
|
return;
|
|
4901
5319
|
}
|
|
4902
5320
|
}
|
|
4903
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
5321
|
+
if (e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing) {
|
|
4904
5322
|
e.preventDefault();
|
|
4905
5323
|
sendDraft();
|
|
4906
5324
|
return;
|
|
4907
5325
|
}
|
|
4908
|
-
if (e.key === "ArrowUp" || e.key === "ArrowDown") {
|
|
5326
|
+
if ((e.key === "ArrowUp" || e.key === "ArrowDown") && !draft.includes("\n")) {
|
|
4909
5327
|
if (walkHistory(e.key === "ArrowUp" ? -1 : 1))
|
|
4910
5328
|
e.preventDefault();
|
|
4911
5329
|
}
|
|
4912
5330
|
},
|
|
4913
5331
|
placeholder: phone ? `${T.message}\u2026` : `${T.message} ${verifiedLabel(peer.app ? null : peer.userId, peer.alias) || shortKey(peer.userId, 6, 4)}\u2026`,
|
|
4914
|
-
style: { flex: 1,
|
|
5332
|
+
style: { flex: 1, minHeight: 38, maxHeight: 180, boxSizing: "border-box", resize: "none", overflowY: "auto", borderRadius: 9, border: "1px solid var(--line)", background: "var(--panel-2)", color: "var(--text)", fontFamily: "var(--ui)", fontSize: 13.5, lineHeight: "18px", padding: "9px 14px", outline: "none", minWidth: 0 }
|
|
4915
5333
|
}
|
|
4916
5334
|
)), /* @__PURE__ */ React.createElement(Btn, { tone: "solid", icon: "arrowUp", title: T.send, onClick: sendDraft }))),
|
|
4917
5335
|
theater && /* @__PURE__ */ React.createElement("div", { onClick: () => setTheater(null), style: {
|
|
@@ -8550,6 +8968,7 @@ ${peer.address}`
|
|
|
8550
8968
|
copy: "Copy",
|
|
8551
8969
|
copied: "Copied",
|
|
8552
8970
|
copyFailed: "Copy failed",
|
|
8971
|
+
copyMarkdown: "Copy (Markdown)",
|
|
8553
8972
|
needProfile: "Set your name first \u2014 a friend request with no name is just a key.",
|
|
8554
8973
|
dangerZone: "Danger zone",
|
|
8555
8974
|
deleteNode: "Delete this node",
|
|
@@ -8796,6 +9215,7 @@ ${peer.address}`
|
|
|
8796
9215
|
copy: "\u590D\u5236",
|
|
8797
9216
|
copied: "\u5DF2\u590D\u5236",
|
|
8798
9217
|
copyFailed: "\u590D\u5236\u5931\u8D25",
|
|
9218
|
+
copyMarkdown: "\u590D\u5236\uFF08Markdown\uFF09",
|
|
8799
9219
|
needProfile: "\u5148\u8BBE\u7F6E\u6635\u79F0 \u2014\u2014 \u6CA1\u6709\u540D\u5B57\u7684\u597D\u53CB\u8BF7\u6C42\u5C31\u53EA\u662F\u4E00\u4E32\u5BC6\u94A5\u3002",
|
|
8800
9220
|
dangerZone: "\u5371\u9669\u64CD\u4F5C",
|
|
8801
9221
|
deleteNode: "\u5220\u9664\u6B64\u8282\u70B9",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decentnetwork/beagle",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.154",
|
|
4
4
|
"description": "Beagle — P2P chat, file transfer and calls for regular users, on the Decent Network. No admin privilege required.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"start": "node dist/cli.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@decentnetwork/beagle-ui": "^0.2.
|
|
29
|
+
"@decentnetwork/beagle-ui": "^0.2.56",
|
|
30
30
|
"@decentnetwork/chat-components": "^0.1.3",
|
|
31
31
|
"@decentnetwork/lan": "^0.1.316",
|
|
32
32
|
"@decentnetwork/peer": "^0.1.178",
|