@mytools-all/mytools-search 0.1.0 → 0.1.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/README.md +27 -21
- package/app.mjs +476 -391
- package/common.mjs +69 -69
- package/index.html +246 -231
- package/package.json +42 -41
- package/plugin.json +2 -1
- package/resultPresentation.mjs +22 -0
- package/searchQuery.mjs +22 -22
- package/tool.css +295 -295
- package/utils.mjs +201 -201
package/package.json
CHANGED
|
@@ -1,41 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mytools-all/mytools-search",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "本地搜索",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "index.html",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"author": "MyTools Contributors",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/mytools-all/mytools-search.git"
|
|
12
|
-
},
|
|
13
|
-
"homepage": "https://github.com/mytools-all/mytools-search#readme",
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/mytools-all/mytools-search/issues"
|
|
16
|
-
},
|
|
17
|
-
"publishConfig": {
|
|
18
|
-
"access": "public",
|
|
19
|
-
"registry": "https://registry.npmjs.org/"
|
|
20
|
-
},
|
|
21
|
-
"files": [
|
|
22
|
-
"plugin.json",
|
|
23
|
-
"*.html",
|
|
24
|
-
"*.css",
|
|
25
|
-
"*.svg",
|
|
26
|
-
"*.png",
|
|
27
|
-
"vendor/",
|
|
28
|
-
"LICENSE",
|
|
29
|
-
"THIRD_PARTY.md",
|
|
30
|
-
"README.md",
|
|
31
|
-
"app.mjs",
|
|
32
|
-
"common.mjs",
|
|
33
|
-
"searchQuery.mjs",
|
|
34
|
-
"utils.mjs",
|
|
35
|
-
"*.js",
|
|
36
|
-
"*.LICENSE"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mytools-all/mytools-search",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "本地搜索",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.html",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "MyTools Contributors",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/mytools-all/mytools-search.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/mytools-all/mytools-search#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/mytools-all/mytools-search/issues"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"plugin.json",
|
|
23
|
+
"*.html",
|
|
24
|
+
"*.css",
|
|
25
|
+
"*.svg",
|
|
26
|
+
"*.png",
|
|
27
|
+
"vendor/",
|
|
28
|
+
"LICENSE",
|
|
29
|
+
"THIRD_PARTY.md",
|
|
30
|
+
"README.md",
|
|
31
|
+
"app.mjs",
|
|
32
|
+
"common.mjs",
|
|
33
|
+
"searchQuery.mjs",
|
|
34
|
+
"utils.mjs",
|
|
35
|
+
"*.js",
|
|
36
|
+
"*.LICENSE",
|
|
37
|
+
"resultPresentation.mjs"
|
|
38
|
+
],
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "node --test"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/plugin.json
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
"apiVersion": 1,
|
|
5
5
|
"main": "index.html",
|
|
6
6
|
"pluginName": "本地搜索",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.1",
|
|
8
8
|
"capabilities": [
|
|
9
9
|
"fs.searchstatus",
|
|
10
10
|
"fs.globalsearch",
|
|
11
11
|
"fs.searchpreview",
|
|
12
|
+
"fs.searchicons",
|
|
12
13
|
"shell.open",
|
|
13
14
|
"shell.reveal",
|
|
14
15
|
"clipboard.write",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function resultName(entry) {
|
|
2
|
+
const path = String(entry.path || "");
|
|
3
|
+
const clean = path.replace(/[\\/]+$/, "");
|
|
4
|
+
const parts = clean.split(/[\\/]/).filter(Boolean);
|
|
5
|
+
const name = parts.at(-1) || String(entry.name || "");
|
|
6
|
+
if (/^[a-z]:$/i.test(clean)) return clean + "\\";
|
|
7
|
+
return name || (entry.directory ? "未命名目录" : "未命名文件");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function resultParent(entry) {
|
|
11
|
+
const path = String(entry.path || "").replace(/[\\/]+$/, "");
|
|
12
|
+
const index = Math.max(path.lastIndexOf("\\"), path.lastIndexOf("/"));
|
|
13
|
+
if (index < 0) return path;
|
|
14
|
+
return path.slice(0, index + (/^[a-z]:$/i.test(path.slice(0,index)) ? 1 : 0));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function placeholderIcon(directory) {
|
|
18
|
+
const shape = directory
|
|
19
|
+
? '<path fill="#e9b346" d="M3 8a3 3 0 0 1 3-3h7l3 4h10a3 3 0 0 1 3 3v13a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3z"/><path fill="#f5ca66" d="M3 13h26v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3z"/>'
|
|
20
|
+
: '<path fill="#f3f6fb" stroke="#8eabc8" stroke-width="1.5" d="M7 3h12l7 7v19H7z"/><path fill="#c4d6e8" d="M19 3v8h7"/><path stroke="#8eabc8" stroke-width="1.5" d="M11 17h11M11 21h11"/>';
|
|
21
|
+
return 'data:image/svg+xml,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">'+shape+'</svg>');
|
|
22
|
+
}
|
package/searchQuery.mjs
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export function buildSearchQuery({ query = "", category = "", extension = "", excluded = "", from = "", to = "", period = "" }) {
|
|
2
|
-
if ((!period || period === "custom") && from && to && from > to) throw Error("开始日期不能晚于结束日期");
|
|
3
|
-
const parts = [category, query.trim() ? `<${query.trim()}>` : ""];
|
|
4
|
-
const extensions = extension.split(/[;,,\s]+/).map(x => x.replace(/^\./, "")).filter(Boolean);
|
|
5
|
-
if (extensions.some(x => !/^[\w-]+$/.test(x))) throw Error("扩展名仅填写字母、数字,例如 txt;md");
|
|
6
|
-
if (extensions.length) parts.push("ext:" + extensions.join(";"));
|
|
7
|
-
for (const word of excluded.split(/[;;\n]+/).map(x => x.trim()).filter(Boolean)) {
|
|
8
|
-
if (word.includes('"')) throw Error("排除内容不能包含双引号");
|
|
9
|
-
parts.push('!"' + word + '"');
|
|
10
|
-
}
|
|
11
|
-
if (period && period !== "custom") parts.push("dm:" + period);
|
|
12
|
-
else {
|
|
13
|
-
if (from) parts.push("dm:>=" + from);
|
|
14
|
-
if (to) parts.push("dm:<" + nextDay(to));
|
|
15
|
-
}
|
|
16
|
-
return parts.filter(Boolean).join(" ");
|
|
17
|
-
}
|
|
18
|
-
function nextDay(value) {
|
|
19
|
-
const date = new Date(value + "T00:00:00Z");
|
|
20
|
-
date.setUTCDate(date.getUTCDate() + 1);
|
|
21
|
-
return date.toISOString().slice(0, 10);
|
|
22
|
-
}
|
|
1
|
+
export function buildSearchQuery({ query = "", category = "", extension = "", excluded = "", from = "", to = "", period = "" }) {
|
|
2
|
+
if ((!period || period === "custom") && from && to && from > to) throw Error("开始日期不能晚于结束日期");
|
|
3
|
+
const parts = [category, query.trim() ? `<${query.trim()}>` : ""];
|
|
4
|
+
const extensions = extension.split(/[;,,\s]+/).map(x => x.replace(/^\./, "")).filter(Boolean);
|
|
5
|
+
if (extensions.some(x => !/^[\w-]+$/.test(x))) throw Error("扩展名仅填写字母、数字,例如 txt;md");
|
|
6
|
+
if (extensions.length) parts.push("ext:" + extensions.join(";"));
|
|
7
|
+
for (const word of excluded.split(/[;;\n]+/).map(x => x.trim()).filter(Boolean)) {
|
|
8
|
+
if (word.includes('"')) throw Error("排除内容不能包含双引号");
|
|
9
|
+
parts.push('!"' + word + '"');
|
|
10
|
+
}
|
|
11
|
+
if (period && period !== "custom") parts.push("dm:" + period);
|
|
12
|
+
else {
|
|
13
|
+
if (from) parts.push("dm:>=" + from);
|
|
14
|
+
if (to) parts.push("dm:<" + nextDay(to));
|
|
15
|
+
}
|
|
16
|
+
return parts.filter(Boolean).join(" ");
|
|
17
|
+
}
|
|
18
|
+
function nextDay(value) {
|
|
19
|
+
const date = new Date(value + "T00:00:00Z");
|
|
20
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
21
|
+
return date.toISOString().slice(0, 10);
|
|
22
|
+
}
|