@max-null/dsh-memory 0.3.8 → 0.4.1
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/client.js +62 -1
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -32,6 +32,62 @@ __export(index_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(index_exports);
|
|
33
33
|
var import_react = require("react");
|
|
34
34
|
var inject = ["slots", "locale"];
|
|
35
|
+
var FILE_REF_RE = /@("([^"]+)"|([^\s"@]+))/g;
|
|
36
|
+
function looksLikePath(path) {
|
|
37
|
+
if (path.includes("\\")) return true;
|
|
38
|
+
if (path.startsWith("./") || path.startsWith("../") || path.startsWith("/") || path.startsWith("~/")) return true;
|
|
39
|
+
if (path.includes("/")) {
|
|
40
|
+
return path.includes(".");
|
|
41
|
+
}
|
|
42
|
+
const m = /\.([A-Za-z0-9]{1,6})$/.exec(path);
|
|
43
|
+
if (m === null) return false;
|
|
44
|
+
const ext = m[1].toLowerCase();
|
|
45
|
+
const COMMON_EXTS = /* @__PURE__ */ new Set(["md", "txt", "ts", "tsx", "js", "mjs", "cjs", "json", "yml", "yaml", "toml", "png", "jpg", "jpeg", "gif", "webp", "svg", "ico", "css", "scss", "html", "py", "rs", "go", "java", "c", "h", "cpp", "sh", "ps1", "bat", "exe", "zip", "tar", "gz", "pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "log", "env", "lock", "csv", "xml", "sql", "db", "wasm"]);
|
|
46
|
+
return COMMON_EXTS.has(ext);
|
|
47
|
+
}
|
|
48
|
+
function splitFileRefs(text) {
|
|
49
|
+
const parts = [];
|
|
50
|
+
let last = 0;
|
|
51
|
+
let m;
|
|
52
|
+
FILE_REF_RE.lastIndex = 0;
|
|
53
|
+
while ((m = FILE_REF_RE.exec(text)) !== null) {
|
|
54
|
+
if (m.index > last) parts.push({ kind: "text", text: text.slice(last, m.index) });
|
|
55
|
+
const path = m[2] ?? m[3];
|
|
56
|
+
if (m[2] !== void 0 || looksLikePath(path)) {
|
|
57
|
+
parts.push({ kind: "ref", ref: { raw: m[0], path } });
|
|
58
|
+
} else {
|
|
59
|
+
parts.push({ kind: "text", text: m[0] });
|
|
60
|
+
}
|
|
61
|
+
last = m.index + m[0].length;
|
|
62
|
+
}
|
|
63
|
+
if (last < text.length) parts.push({ kind: "text", text: text.slice(last) });
|
|
64
|
+
return parts;
|
|
65
|
+
}
|
|
66
|
+
var openFileRef = null;
|
|
67
|
+
function ContentWithRefs({ text, style }) {
|
|
68
|
+
const parts = splitFileRefs(text);
|
|
69
|
+
if (parts.every((p) => p.kind === "text")) return text;
|
|
70
|
+
return (0, import_react.createElement)(
|
|
71
|
+
"span",
|
|
72
|
+
{ style: { whiteSpace: "pre-wrap", wordBreak: "break-all" } },
|
|
73
|
+
parts.map((p, i) => p.kind === "text" ? (0, import_react.createElement)("span", { key: i, style }, p.text) : (0, import_react.createElement)("span", {
|
|
74
|
+
key: i,
|
|
75
|
+
title: "open file",
|
|
76
|
+
onClick: () => {
|
|
77
|
+
openFileRef?.(p.ref.path, p.ref.path);
|
|
78
|
+
},
|
|
79
|
+
style: {
|
|
80
|
+
...style,
|
|
81
|
+
cursor: "pointer",
|
|
82
|
+
borderRadius: 4,
|
|
83
|
+
padding: "0 3px",
|
|
84
|
+
background: "var(--dsw-alias-state-business-tertiary, rgba(79,195,247,.16))",
|
|
85
|
+
color: "var(--dsw-alias-state-business-primary, #4FC3F7)",
|
|
86
|
+
textDecoration: "underline dotted"
|
|
87
|
+
}
|
|
88
|
+
}, p.ref.raw))
|
|
89
|
+
);
|
|
90
|
+
}
|
|
35
91
|
var BRAIN_PATHS = [
|
|
36
92
|
"M9.5 2A2.5 2.5 0 0 1 12 4.5v15a2.5 2.5 0 0 1-4.96.44 2.5 2.5 0 0 1-2.96-3.08 3 3 0 0 1-.34-5.58 2.5 2.5 0 0 1 1.32-4.24 2.5 2.5 0 0 1 1.98-3A2.5 2.5 0 0 1 9.5 2Z",
|
|
37
93
|
"M14.5 2A2.5 2.5 0 0 0 12 4.5v15a2.5 2.5 0 0 0 4.96.44 2.5 2.5 0 0 0 2.96-3.08 3 3 0 0 0 .34-5.58 2.5 2.5 0 0 0-1.32-4.24 2.5 2.5 0 0 0-1.98-3A2.5 2.5 0 0 0 14.5 2Z"
|
|
@@ -428,7 +484,7 @@ function MemoryView(props) {
|
|
|
428
484
|
group.items.map((record) => (0, import_react.createElement)(
|
|
429
485
|
"div",
|
|
430
486
|
{ key: record.id, style: ssid.card },
|
|
431
|
-
(0, import_react.createElement)("div", { style: ssid.text }, record.content),
|
|
487
|
+
(0, import_react.createElement)("div", { style: ssid.text }, ContentWithRefs({ text: record.content })),
|
|
432
488
|
// keywords 展示(0.3.5:设计约定 UI 显示 keywords)
|
|
433
489
|
record.keywords !== void 0 && record.keywords.length > 0 ? (0, import_react.createElement)(
|
|
434
490
|
"div",
|
|
@@ -527,6 +583,11 @@ function apply(ctx) {
|
|
|
527
583
|
root.inject(["betterSidebar"], (sidebarCtx) => {
|
|
528
584
|
const service = sidebarCtx.betterSidebar;
|
|
529
585
|
if (service?.registerTab === void 0) return;
|
|
586
|
+
if (typeof service.openFile === "function") {
|
|
587
|
+
openFileRef = (path, title) => {
|
|
588
|
+
service.openFile?.({}, path, title);
|
|
589
|
+
};
|
|
590
|
+
}
|
|
530
591
|
const tabCtx = ctx;
|
|
531
592
|
service.registerTab({
|
|
532
593
|
id: "@max-null/dsh-memory:memory",
|
package/package.json
CHANGED