joplin-plugin-explorer 1.3.1 → 1.3.3
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 +65 -65
- package/package.json +25 -25
- package/publish/index.js +1 -1
- package/publish/manifest.json +13 -13
- package/publish/plugin.jpl +0 -0
- package/publish/webview/panel.css +621 -621
- package/publish/webview/panel.js +1 -1
package/README.md
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
# Joplin Explorer
|
|
2
|
-
|
|
3
|
-
A unified sidebar plugin for [Joplin](https://joplinapp.org/) that displays notebooks and notes together in a single tree view — like a file explorer.
|
|
4
|
-
|
|
5
|
-
[中文说明](README-CN.md)
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Unified Tree View** — Notebooks and notes displayed in one collapsible panel
|
|
10
|
-
- **Custom Icons** — Shows emoji icons set in notebook settings; customize folder and pinned section icons via settings (emoji / image URL / data URI / local file path)
|
|
11
|
-
- **Toggle Arrow Visibility** — Hide expand/collapse arrows for a cleaner look
|
|
12
|
-
- **Live Updates** — Notes refresh in-place when their title or todo state changes
|
|
13
|
-
- **Favorites (Pin)** — Pin notes and notebooks to a collapsible section at the top of the tree; drag items to the pinned section to pin, drag within to reorder; persists across restarts
|
|
14
|
-
- **Enhanced Search** — Search notes, notebooks, and tags simultaneously with keyword highlighting; results grouped in collapsible sections; local title substring matching for partial queries (e.g. "8121R" finds "KY8121R")
|
|
15
|
-
- **Sort** — Toggle between sorting by update time or title (ascending/descending)
|
|
16
|
-
- **Context Menus**
|
|
17
|
-
- Notebooks: pin/unpin, new note, new to-do, new sub-notebook, rename, export, delete
|
|
18
|
-
- Notes: pin/unpin, open, open in new window, copy Markdown link, duplicate, switch note/to-do type, toggle completed, rename, view properties, delete
|
|
19
|
-
- **Drag & Drop** — Move notes between notebooks, reorganize folder hierarchy; drag to empty area to create a new notebook; drag to pinned section to pin
|
|
20
|
-
- **Sync Button** — Trigger synchronization with status feedback (syncing → done)
|
|
21
|
-
- **Auto Expand** — Automatically expands to the currently selected note on startup
|
|
22
|
-
- **Collapse All** — One-click collapse all notebooks
|
|
23
|
-
- **Scroll Position** — Preserved when navigating between notes
|
|
24
|
-
- **i18n** — Supports English, Simplified Chinese, Traditional Chinese, Japanese, and Russian (follows Joplin's locale setting)
|
|
25
|
-
|
|
26
|
-
## Install
|
|
27
|
-
|
|
28
|
-
### From File
|
|
29
|
-
|
|
30
|
-
1. Download `joplin-explorer.jpl` from the [latest release](https://github.com/lim0513/joplin-explorer/releases/latest)
|
|
31
|
-
2. In Joplin, go to **Tools → Options → Plugins**
|
|
32
|
-
3. Click the gear icon and select **Install from file**
|
|
33
|
-
4. Choose the downloaded `.jpl` file
|
|
34
|
-
5. Restart Joplin
|
|
35
|
-
|
|
36
|
-
## Usage
|
|
37
|
-
|
|
38
|
-
After installation, the Explorer panel appears on the side of the editor. You can:
|
|
39
|
-
|
|
40
|
-
- **Click** a notebook to expand/collapse it
|
|
41
|
-
- **Click** a note to open it
|
|
42
|
-
- **Right-click** for context menu actions (including pin/unpin)
|
|
43
|
-
- **Drag** notes or notebooks to reorganize; drag to the bottom zone to create a new notebook; drag to the pinned section to pin
|
|
44
|
-
- Use the **toolbar** at the top for quick actions (new notebook/note/to-do, sort, collapse all)
|
|
45
|
-
- Use the **search bar** to search notes, notebooks, and tags
|
|
46
|
-
- Click **Sync** at the bottom to trigger synchronization
|
|
47
|
-
|
|
48
|
-
## Development
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# Install dependencies
|
|
52
|
-
npm install
|
|
53
|
-
|
|
54
|
-
# Build
|
|
55
|
-
npm run dist
|
|
56
|
-
|
|
57
|
-
# Watch mode
|
|
58
|
-
npm run dev
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
The built plugin is output to the `publish/` directory. To test locally, set `plugins.devPluginPaths` in Joplin's settings to point to the `publish/` directory.
|
|
62
|
-
|
|
63
|
-
## License
|
|
64
|
-
|
|
65
|
-
MIT
|
|
1
|
+
# Joplin Explorer
|
|
2
|
+
|
|
3
|
+
A unified sidebar plugin for [Joplin](https://joplinapp.org/) that displays notebooks and notes together in a single tree view — like a file explorer.
|
|
4
|
+
|
|
5
|
+
[中文说明](README-CN.md)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Unified Tree View** — Notebooks and notes displayed in one collapsible panel
|
|
10
|
+
- **Custom Icons** — Shows emoji icons set in notebook settings; customize folder and pinned section icons via settings (emoji / image URL / data URI / local file path)
|
|
11
|
+
- **Toggle Arrow Visibility** — Hide expand/collapse arrows for a cleaner look
|
|
12
|
+
- **Live Updates** — Notes refresh in-place when their title or todo state changes
|
|
13
|
+
- **Favorites (Pin)** — Pin notes and notebooks to a collapsible section at the top of the tree; drag items to the pinned section to pin, drag within to reorder; persists across restarts
|
|
14
|
+
- **Enhanced Search** — Search notes, notebooks, and tags simultaneously with keyword highlighting; results grouped in collapsible sections; local title substring matching for partial queries (e.g. "8121R" finds "KY8121R")
|
|
15
|
+
- **Sort** — Toggle between sorting by update time or title (ascending/descending)
|
|
16
|
+
- **Context Menus**
|
|
17
|
+
- Notebooks: pin/unpin, new note, new to-do, new sub-notebook, rename, export, delete
|
|
18
|
+
- Notes: pin/unpin, open, open in new window, copy Markdown link, duplicate, switch note/to-do type, toggle completed, rename, view properties, delete
|
|
19
|
+
- **Drag & Drop** — Move notes between notebooks, reorganize folder hierarchy; drag to empty area to create a new notebook; drag to pinned section to pin
|
|
20
|
+
- **Sync Button** — Trigger synchronization with status feedback (syncing → done)
|
|
21
|
+
- **Auto Expand** — Automatically expands to the currently selected note on startup
|
|
22
|
+
- **Collapse All** — One-click collapse all notebooks
|
|
23
|
+
- **Scroll Position** — Preserved when navigating between notes
|
|
24
|
+
- **i18n** — Supports English, Simplified Chinese, Traditional Chinese, Japanese, and Russian (follows Joplin's locale setting)
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
### From File
|
|
29
|
+
|
|
30
|
+
1. Download `joplin-explorer.jpl` from the [latest release](https://github.com/lim0513/joplin-explorer/releases/latest)
|
|
31
|
+
2. In Joplin, go to **Tools → Options → Plugins**
|
|
32
|
+
3. Click the gear icon and select **Install from file**
|
|
33
|
+
4. Choose the downloaded `.jpl` file
|
|
34
|
+
5. Restart Joplin
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
After installation, the Explorer panel appears on the side of the editor. You can:
|
|
39
|
+
|
|
40
|
+
- **Click** a notebook to expand/collapse it
|
|
41
|
+
- **Click** a note to open it
|
|
42
|
+
- **Right-click** for context menu actions (including pin/unpin)
|
|
43
|
+
- **Drag** notes or notebooks to reorganize; drag to the bottom zone to create a new notebook; drag to the pinned section to pin
|
|
44
|
+
- Use the **toolbar** at the top for quick actions (new notebook/note/to-do, sort, collapse all)
|
|
45
|
+
- Use the **search bar** to search notes, notebooks, and tags
|
|
46
|
+
- Click **Sync** at the bottom to trigger synchronization
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Install dependencies
|
|
52
|
+
npm install
|
|
53
|
+
|
|
54
|
+
# Build
|
|
55
|
+
npm run dist
|
|
56
|
+
|
|
57
|
+
# Watch mode
|
|
58
|
+
npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The built plugin is output to the `publish/` directory. To test locally, set `plugins.devPluginPaths` in Joplin's settings to point to the `publish/` directory.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "joplin-plugin-explorer",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "A unified sidebar that displays notebooks and notes together in a single tree view",
|
|
5
|
-
"author": "lim0513",
|
|
6
|
-
"homepage": "https://github.com/lim0513/joplin-explorer",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/lim0513/joplin-explorer.git"
|
|
10
|
-
},
|
|
11
|
-
"scripts": {
|
|
12
|
-
"dist": "webpack --env production && node scripts/pack-jpl.js",
|
|
13
|
-
"dev": "webpack --watch"
|
|
14
|
-
},
|
|
15
|
-
"keywords": ["joplin-plugin", "joplin", "sidebar", "explorer", "tree-view", "notebooks"],
|
|
16
|
-
"license": "MIT",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"copy-webpack-plugin": "^11.0.0",
|
|
19
|
-
"ts-loader": "^9.5.1",
|
|
20
|
-
"typescript": "^5.3.3",
|
|
21
|
-
"webpack": "^5.89.0",
|
|
22
|
-
"webpack-cli": "^5.1.4"
|
|
23
|
-
},
|
|
24
|
-
"files": ["publish"]
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "joplin-plugin-explorer",
|
|
3
|
+
"version": "1.3.3",
|
|
4
|
+
"description": "A unified sidebar that displays notebooks and notes together in a single tree view",
|
|
5
|
+
"author": "lim0513",
|
|
6
|
+
"homepage": "https://github.com/lim0513/joplin-explorer",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/lim0513/joplin-explorer.git"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"dist": "webpack --env production && node scripts/pack-jpl.js",
|
|
13
|
+
"dev": "webpack --watch"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["joplin-plugin", "joplin", "sidebar", "explorer", "tree-view", "notebooks"],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"copy-webpack-plugin": "^11.0.0",
|
|
19
|
+
"ts-loader": "^9.5.1",
|
|
20
|
+
"typescript": "^5.3.3",
|
|
21
|
+
"webpack": "^5.89.0",
|
|
22
|
+
"webpack-cli": "^5.1.4"
|
|
23
|
+
},
|
|
24
|
+
"files": ["publish"]
|
|
25
|
+
}
|
package/publish/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={982(e){e.exports=require("crypto")},896(e){e.exports=require("fs")},928(e){e.exports=require("path")}},t={};function o(n){var i=t[n];if(void 0!==i)return i.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,o),a.exports}const n={zh_CN:{newNotebook:"新建笔记本",newNote:"新建笔记",newTodo:"新建待办",sort:"排序",collapseAll:"全部折叠",expandAll:"全部展开",search:"搜索笔记内容...",searchResultCount:"找到 {count} 条结果",searchNoResult:"没有找到匹配的笔记",searching:"搜索中...",sync:"同步",syncing:"同步中...",syncDone:"✔ 同步完成",syncFailed:"⚠ 同步失败",loading:"加载中...",sortUpdatedDesc:"↓ 修改时间",sortUpdatedAsc:"↑ 修改时间",sortTitleAsc:"↑ 标题",sortTitleDesc:"↓ 标题",sortManual:"⇅ 手动排序",ctxNewNoteHere:"在此新建笔记",ctxNewTodoHere:"在此新建待办",ctxNewSubNotebook:"新建子笔记本",ctxRenameFolder:"重命名",ctxExportFolder:"导出笔记本",ctxDeleteFolder:"删除笔记本",ctxOpenNote:"打开笔记",ctxOpenInNewWindow:"在新窗口中打开",ctxCopyLink:"复制 Markdown 链接",ctxDuplicateNote:"复制副本",ctxSwitchNoteType:"笔记/待办 切换",ctxToggleTodo:"切换完成状态",ctxRenameNote:"重命名",ctxMoveNote:"移动到笔记本...",ctxNoteInfo:"笔记属性",ctxDeleteNote:"删除笔记",confirmDeleteFolder:"确定删除此笔记本及其所有内容吗?",confirmDeleteNote:"确定删除此笔记吗?",promptRename:"请输入新名称:",promptMoveNote:"请输入目标笔记本名称:",promptNewNotebookName:"请输入新笔记本名称:",dropCreateNotebook:"释放以创建新笔记本",searchSectionNotes:"笔记",searchSectionTags:"标签",searchSectionFolders:"笔记本",searchTagNoteCount:"{count} 条笔记",pinned:"收藏夹",ctxPin:"📌 收藏",ctxUnpin:"取消收藏",cancel:"取消"},zh_TW:{newNotebook:"新建筆記本",newNote:"新建筆記",newTodo:"新建待辦",sort:"排序",collapseAll:"全部摺疊",expandAll:"全部展開",search:"搜尋筆記內容...",searchResultCount:"找到 {count} 條結果",searchNoResult:"沒有找到匹配的筆記",searching:"搜尋中...",sync:"同步",syncing:"同步中...",syncDone:"✔ 同步完成",syncFailed:"⚠ 同步失敗",loading:"載入中...",sortUpdatedDesc:"↓ 修改時間",sortUpdatedAsc:"↑ 修改時間",sortTitleAsc:"↑ 標題",sortTitleDesc:"↓ 標題",sortManual:"⇅ 手動排序",ctxNewNoteHere:"在此新建筆記",ctxNewTodoHere:"在此新建待辦",ctxNewSubNotebook:"新建子筆記本",ctxRenameFolder:"重新命名",ctxExportFolder:"匯出筆記本",ctxDeleteFolder:"刪除筆記本",ctxOpenNote:"開啟筆記",ctxOpenInNewWindow:"在新視窗中開啟",ctxCopyLink:"複製 Markdown 連結",ctxDuplicateNote:"複製副本",ctxSwitchNoteType:"筆記/待辦 切換",ctxToggleTodo:"切換完成狀態",ctxRenameNote:"重新命名",ctxMoveNote:"移動到筆記本...",ctxNoteInfo:"筆記屬性",ctxDeleteNote:"刪除筆記",confirmDeleteFolder:"確定刪除此筆記本及其所有內容嗎?",confirmDeleteNote:"確定刪除此筆記嗎?",promptRename:"請輸入新名稱:",promptMoveNote:"請輸入目標筆記本名稱:",promptNewNotebookName:"請輸入新筆記本名稱:",dropCreateNotebook:"釋放以建立新筆記本",searchSectionNotes:"筆記",searchSectionTags:"標籤",searchSectionFolders:"筆記本",searchTagNoteCount:"{count} 條筆記",pinned:"收藏夾",ctxPin:"📌 收藏",ctxUnpin:"取消收藏",cancel:"取消"},en_US:{newNotebook:"New Notebook",newNote:"New Note",newTodo:"New To-do",sort:"Sort",collapseAll:"Collapse All",expandAll:"Expand All",search:"Search note contents...",searchResultCount:"{count} results found",searchNoResult:"No matching notes found",searching:"Searching...",sync:"Synchronise",syncing:"Syncing...",syncDone:"✔ Sync Done",syncFailed:"⚠ Sync Failed",loading:"Loading...",sortUpdatedDesc:"↓ Updated",sortUpdatedAsc:"↑ Updated",sortTitleAsc:"↑ Title",sortTitleDesc:"↓ Title",sortManual:"⇅ Manual",ctxNewNoteHere:"New Note Here",ctxNewTodoHere:"New To-do Here",ctxNewSubNotebook:"New Sub-notebook",ctxRenameFolder:"Rename",ctxExportFolder:"Export Notebook",ctxDeleteFolder:"Delete Notebook",ctxOpenNote:"Open Note",ctxOpenInNewWindow:"Open in New Window",ctxCopyLink:"Copy Markdown Link",ctxDuplicateNote:"Duplicate",ctxSwitchNoteType:"Switch Note/To-do",ctxToggleTodo:"Toggle Completed",ctxRenameNote:"Rename",ctxMoveNote:"Move to Notebook...",ctxNoteInfo:"Note Properties",ctxDeleteNote:"Delete Note",confirmDeleteFolder:"Delete this notebook and all its contents?",confirmDeleteNote:"Delete this note?",promptRename:"Enter new name:",promptMoveNote:"Enter target notebook name:",promptNewNotebookName:"Enter new notebook name:",dropCreateNotebook:"Release to create a new notebook",searchSectionNotes:"Notes",searchSectionTags:"Tags",searchSectionFolders:"Notebooks",searchTagNoteCount:"{count} notes",pinned:"Pinned",ctxPin:"📌 Pin",ctxUnpin:"Unpin",cancel:"Cancel"},ru:{newNotebook:"Новый блокнот",newNote:"Новая заметка",newTodo:"Новая задача",sort:"Сортировка",collapseAll:"Свернуть все",expandAll:"Развернуть все",search:"Искать в содержимом заметок...",searchResultCount:"Найдено результатов: {count}",searchNoResult:"Заметки не найдены",searching:"Поиск...",sync:"Синхронизировать",syncing:"Синхронизация...",syncDone:"✔ Синхронизация завершена",syncFailed:"⚠ Ошибка синхронизации",loading:"Загрузка...",sortUpdatedDesc:"↓ Обновлено",sortUpdatedAsc:"↑ Обновлено",sortTitleAsc:"↑ Название",sortTitleDesc:"↓ Название",sortManual:"⇅ Вручную",ctxNewNoteHere:"Создать заметку здесь",ctxNewTodoHere:"Создать задачу здесь",ctxNewSubNotebook:"Новый вложенный блокнот",ctxRenameFolder:"Переименовать",ctxExportFolder:"Экспортировать блокнот",ctxDeleteFolder:"Удалить блокнот",ctxOpenNote:"Открыть заметку",ctxOpenInNewWindow:"Открыть в новом окне",ctxCopyLink:"Скопировать Markdown-ссылку",ctxDuplicateNote:"Создать копию",ctxSwitchNoteType:"Переключить между заметкой и задачей",ctxToggleTodo:"Переключить статус выполнения",ctxRenameNote:"Переименовать",ctxMoveNote:"Переместить в блокнот...",ctxNoteInfo:"Свойства заметки",ctxDeleteNote:"Удалить заметку",confirmDeleteFolder:"Удалить блокнот и все его содержимое?",confirmDeleteNote:"Удалить заметку?",promptRename:"Введите новое название:",promptMoveNote:"Переместить в блокнот:",promptNewNotebookName:"Введите название нового блокнота:",dropCreateNotebook:"Отпустите, чтобы создать новый блокнот",searchSectionNotes:"Заметки",searchSectionTags:"Метки",searchSectionFolders:"Блокноты",searchTagNoteCount:"Заметок: {count}",pinned:"Закрепленные",ctxPin:"📌 Закрепить",ctxUnpin:"Открепить",cancel:"Отмена"},ja_JP:{newNotebook:"新規ノートブック",newNote:"新規ノート",newTodo:"新規タスク",sort:"並べ替え",collapseAll:"すべて折りたたむ",expandAll:"すべて展開",search:"ノート内容を検索...",searchResultCount:"{count} 件の結果",searchNoResult:"一致するノートが見つかりません",searching:"検索中...",sync:"同期",syncing:"同期中...",syncDone:"✔ 同期完了",syncFailed:"⚠ 同期に失敗しました",loading:"読み込み中...",sortUpdatedDesc:"↓ 更新日時",sortUpdatedAsc:"↑ 更新日時",sortTitleAsc:"↑ タイトル",sortTitleDesc:"↓ タイトル",sortManual:"⇅ 手動",ctxNewNoteHere:"ここに新規ノート",ctxNewTodoHere:"ここに新規タスク",ctxNewSubNotebook:"新規サブノートブック",ctxRenameFolder:"名前を変更",ctxExportFolder:"ノートブックをエクスポート",ctxDeleteFolder:"ノートブックを削除",ctxOpenNote:"ノートを開く",ctxOpenInNewWindow:"新しいウィンドウで開く",ctxCopyLink:"Markdownリンクをコピー",ctxDuplicateNote:"複製",ctxSwitchNoteType:"ノート/タスク切り替え",ctxToggleTodo:"完了状態を切り替え",ctxRenameNote:"名前を変更",ctxMoveNote:"ノートブックに移動...",ctxNoteInfo:"ノートプロパティ",ctxDeleteNote:"ノートを削除",confirmDeleteFolder:"このノートブックとその内容をすべて削除しますか?",confirmDeleteNote:"このノートを削除しますか?",promptRename:"新しい名前を入力:",promptMoveNote:"移動先のノートブック名:",promptNewNotebookName:"新しいノートブック名を入力:",dropCreateNotebook:"ドロップして新規ノートブックを作成",searchSectionNotes:"ノート",searchSectionTags:"タグ",searchSectionFolders:"ノートブック",searchTagNoteCount:"{count} 件のノート",pinned:"ピン留め",ctxPin:"📌 ピン留め",ctxUnpin:"ピン解除",cancel:"キャンセル"}},i=o(896),a=o(928),s=o(982);function l(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const r={".gif":"image/gif",".ico":"image/x-icon",".jpeg":"image/jpeg",".jpg":"image/jpeg",".png":"image/png",".svg":"image/svg+xml",".webp":"image/webp"};function d(e,t){const o="icon"+(t?" "+t:"");return"image"===e.type?'<span class="'+o+'"><img class="custom-icon" src="'+l(e.value)+'" /></span>':'<span class="'+o+'">'+l(e.value)+"</span>"}const c={};async function p(e,t,o,n){const l=o+":"+String(e);if(c[l])return c[l];const d=await async function(e,t,o,n){const l="string"==typeof e?e.trim():"";if(!l)return{type:"text",value:t};if(/^data:image\//i.test(l)||/^https?:\/\//i.test(l))return{type:"image",value:l};const d=function(e){const t=e.trim();return/^file:\/\//i.test(t)?decodeURIComponent(t.replace(/^file:\/\//i,"")):0===t.indexOf("~/")&&process&&process.env&&process.env.HOME?a.join(process.env.HOME,t.substring(2)):a.isAbsolute(t)?t:null}(l);if(!d)return{type:"text",value:l};const c=a.extname(d).toLowerCase(),p=r[c];if(!p)return console.warn("Joplin Explorer: unsupported icon file type",d),{type:"text",value:t};const u=a.join(n,"custom-icons"),w=s.createHash("sha1").update(d).digest("hex"),f=a.join(u,o+"-"+w+c);try{await i.promises.mkdir(u,{recursive:!0}),(await i.promises.stat(d)).isFile()&&await i.promises.copyFile(d,f)}catch(e){console.warn("Joplin Explorer: failed to copy icon file",d,e)}try{return{type:"image",value:"data:"+p+";base64,"+(await i.promises.readFile(f)).toString("base64")}}catch(e){return console.warn("Joplin Explorer: failed to load icon file",f,e),{type:"text",value:t}}}(e,t,o,n);return c[l]=d,d}function u(e,t){const o=e.order||0,n=t.order||0;return o!==n?n-o:(e.title||"").localeCompare(t.title||"")}function w(e,t=!0,o={type:"text",value:"📂"},n={type:"text",value:"📁"}){let i=e.icon;if(i&&"string"==typeof i)try{i=JSON.parse(i)}catch(e){i=null}return i&&i.emoji?{type:"text",value:String(i.emoji)}:t?n:o}function f(e){return e.is_todo?e.todo_completed?"☑":"☐":"📝"}function m(e,t,o,n=0,i=!0,a={type:"text",value:"📂"},s={type:"text",value:"📁"}){let r="";for(const c of e){const e=8+18*n;if("folder"===c.type){const p=c.total_count||c.note_count||0,u=!0===o[c.id],f=u?"▶":"▼",g=u?"toggle":"toggle expanded";r+='<div class="tree-item folder'+(u?" collapsed":"")+'" style="padding-left:'+e+'px" data-id="'+c.id+'" data-type="folder">',i&&(r+='<span class="'+g+'">'+f+"</span>"),r+=d(w(c,!1,a,s),"folder-icon icon-when-open"),r+=d(w(c,!0,a,s),"folder-icon icon-when-collapsed"),r+='<span class="label">'+l(c.title)+"</span>",r+='<span class="count">'+p+"</span>",r+="</div>",r+='<div class="children'+(u?" collapsed":"")+'" data-folder-id="'+c.id+'">',c.children&&(r+=m(c.children,t,o,n+1,i,a,s)),r+="</div>"}else{const o=c.id===t?" selected":"",n=f(c);r+='<div class="tree-item note'+o+'" style="padding-left:'+e+'px" data-id="'+c.id+'" data-type="note">',r+='<span class="icon note-icon">'+n+"</span>",r+='<span class="label">'+l(c.title)+"</span>",r+="</div>"}}return r}function g(e,t){const o=e.slice();switch(t){case"title_asc":o.sort((e,t)=>(e.title||"").localeCompare(t.title||""));break;case"title_desc":o.sort((e,t)=>(t.title||"").localeCompare(e.title||""));break;case"updated_asc":o.sort((e,t)=>(e.user_updated_time||0)-(t.user_updated_time||0));break;case"manual":o.sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(t.user_updated_time||0)-(e.user_updated_time||0)});break;default:o.sort((e,t)=>(t.user_updated_time||0)-(e.user_updated_time||0))}return o}joplin.plugins.register({onStart:async function(){const e=(o=await joplin.settings.globalValue("locale")||"en_US",n[o]||n[o.split("_")[0]]||n.en_US),t=await joplin.views.panels.create("notesInListPanel");var o;await joplin.views.panels.addScript(t,"webview/panel.css"),await joplin.views.panels.addScript(t,"webview/panel.js"),await joplin.views.panels.setHtml(t,'<div id="notes-in-list-root"><p style="padding:12px;">'+e.loading+"</p></div>"),await joplin.views.panels.show(t,!0);try{await joplin.settings.registerSection("joplinExplorer",{label:"Joplin Explorer",iconName:"fas fa-columns"}),await joplin.settings.registerSettings({pinnedItems:{section:"joplinExplorer",type:2,value:'{"notes":[],"folders":[]}',public:!1,label:"Pinned Items (JSON)"},folderOrder:{section:"joplinExplorer",type:2,value:"{}",public:!1,label:"Folder Manual Order (JSON)"},showFolderToggles:{section:"joplinExplorer",type:3,value:!0,public:!0,label:"Show toggle arrows",description:"Show expand/collapse arrows before folders and the pinned section."},openFolderIcon:{section:"joplinExplorer",type:2,value:"📂",public:!0,label:"Open folder icon",description:"Emoji, image URL, data URI, or local image path for expanded folders without a custom notebook icon."},closedFolderIcon:{section:"joplinExplorer",type:2,value:"📁",public:!0,label:"Closed folder icon",description:"Emoji, image URL, data URI, or local image path for collapsed folders without a custom notebook icon."},openPinnedIcon:{section:"joplinExplorer",type:2,value:"📌",public:!0,label:"Open pinned icon",description:"Emoji, image URL, data URI, or local image path for the expanded pinned section."},closedPinnedIcon:{section:"joplinExplorer",type:2,value:"📌",public:!0,label:"Closed pinned icon",description:"Emoji, image URL, data URI, or local image path for the collapsed pinned section."}})}catch(e){console.error("Joplin Explorer: failed to register settings",e)}const i=await joplin.views.dialogs.create("explorerInputDialog"),a=await joplin.views.dialogs.create("explorerConfirmDialog"),s=await joplin.views.dialogs.create("explorerInfoDialog");async function r(t){return await joplin.views.dialogs.setHtml(a,'<div style="padding:10px;min-width:280px;"><div style="font-size:13px;">'+l(t)+"</div></div>"),await joplin.views.dialogs.setButtons(a,[{id:"ok",title:"OK"},{id:"cancel",title:e.cancel||"Cancel"}]),"ok"===(await joplin.views.dialogs.open(a)).id}async function y(e,t){await joplin.views.dialogs.setHtml(s,'<div style="padding:10px;min-width:320px;"><div style="font-size:14px;font-weight:bold;margin-bottom:10px;">'+l(e)+'</div><div style="font-size:12px;line-height:1.8;white-space:pre-wrap;">'+l(t)+"</div></div>"),await joplin.views.dialogs.setButtons(s,[{id:"ok",title:"OK"}]),await joplin.views.dialogs.open(s)}async function x(t,o){await joplin.views.dialogs.setHtml(i,'<div style="padding:10px;min-width:300px;"><div style="margin-bottom:8px;font-size:13px;">'+l(t)+'</div><form name="inputForm"><input name="value" type="text" value="'+l(o||"")+'" style="width:100%;box-sizing:border-box;padding:6px 8px;font-size:13px;" /></form></div>'),await joplin.views.dialogs.setButtons(i,[{id:"ok",title:"OK"},{id:"cancel",title:e.cancel||"Cancel"}]);const n=await joplin.views.dialogs.open(i);return"ok"===n.id&&n.formData&&n.formData.inputForm&&n.formData.inputForm.value||null}let N="",h={},b="updated_desc",_=[],v={},j=[],k=[],S=!1,T={},I=!0;const D=await joplin.plugins.dataDir();let F=null,O=null,C={};async function E(){try{await joplin.settings.setValue("pinnedItems",JSON.stringify(k))}catch(e){console.error("Joplin Explorer: failed to save pinned items",e)}}async function M(){try{await joplin.settings.setValue("folderOrder",JSON.stringify(T))}catch(e){console.error("Joplin Explorer: failed to save folder order",e)}}function R(e){let t=e;for(;t;){delete h[t];const e=v[t];t=e?e.parent_id:null}}async function A(){try{const o=await async function(){let e=[],t=1,o=!0;for(;o;){const n=await joplin.data.get(["folders"],{fields:["id","title","parent_id","icon"],page:t,limit:100});e=e.concat(n.items),o=n.has_more,t++}return e}();await async function(){try{const e=await joplin.settings.value("folderOrder"),t=e?JSON.parse(e):{};T=t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch(e){T={}}}();let n=!1;const i=new Set(o.map(e=>e.id));for(const e of Object.keys(T))i.has(e)||(delete T[e],n=!0);n&&await M();for(const e of o)e.order=T[e.id]||0;_=o,v={};for(const e of o)v[e.id]=e;if(I){for(const e of o)h[e.id]=!0;const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),I=!1}const a=await async function(){let e=[],t=1,o=!0;for(;o;){const n=await joplin.data.get(["notes"],{fields:["id","title","parent_id","is_todo","todo_completed","updated_time","user_updated_time","order"],page:t,limit:100});e=e.concat(n.items),o=n.has_more,t++}return e}(),s={};for(const e of o)s[e.id]=[];for(const e of a)s[e.parent_id]&&s[e.parent_id].push(e);for(const e of Object.keys(s))s[e]=g(s[e],b);const r=[];for(const e of Object.keys(s))for(const t of s[e])r.push(t);j=r;const c=await joplin.settings.value("showFolderToggles"),y=await joplin.settings.value("openFolderIcon"),x=await joplin.settings.value("closedFolderIcon"),F=await joplin.settings.value("openPinnedIcon"),O=await joplin.settings.value("closedPinnedIcon"),C=await p(y,"📂","openFolderIcon",D),A=await p(x,"📁","closedFolderIcon",D),U=await p(F,"📌","openPinnedIcon",D),J=await p(O,"📌","closedPinnedIcon",D),L=!1!==c,P=function(e,t){const o={},n={},i={};for(const t of e)o[t.id]={type:"folder",id:t.id,title:t.title,parent_id:t.parent_id,icon:t.icon,order:t.order||0,note_count:0,children:[]},n[t.id]=[],i[t.id]=[];for(const e of Object.keys(t))if(i[e])for(const o of t[e])i[e].push({type:"note",id:o.id,title:o.title||"(untitled)",is_todo:o.is_todo,todo_completed:o.todo_completed});const a=[];for(const t of e){const e=o[t.id];t.parent_id&&o[t.parent_id]?n[t.parent_id].push(e):a.push(e)}function s(e){const t=n[e.id].sort(u);for(const e of t)s(e);e.note_count=i[e.id].length,e.children=t.concat(i[e.id])}a.sort(u);for(const e of a)s(e);const l=a;function r(e){let t=0;if(!e.children)return 0;for(const o of e.children)"note"===o.type?t++:"folder"===o.type&&(r(o),t+=o.total_count||0);return e.total_count=t,t}for(const e of l)r(e);return l}(o,s),H=m(P,N,h,0,L,C,A);await async function(){try{const e=await joplin.settings.value("pinnedItems");if(!e)return;const t=JSON.parse(e);if(t&&!Array.isArray(t)&&t.notes&&t.folders){k=[];for(const e of t.folders)k.push({id:e,type:"folder"});for(const e of t.notes)k.push({id:e,type:"note"});await E()}else Array.isArray(t)&&(k=t)}catch(e){k=[]}}();const z=new Set(o.map(e=>e.id)),W=new Set(r.map(e=>e.id)),q=k.length;k=k.filter(e=>"folder"===e.type?z.has(e.id):W.has(e.id)),k.length!==q&&await E();let B="";const K=k.length;if(K>0){B+='<div class="pinned-section-header'+(S?" collapsed":"")+'" id="pinned-header">',L&&(B+='<span class="toggle">'+(S?"▶":"▼")+"</span>"),B+=d(U,"icon-when-open")+d(J,"icon-when-collapsed")+'<span class="label">'+e.pinned+" ("+K+")</span></div>",B+='<div class="pinned-section-body'+(S?" collapsed":"")+'" id="pinned-body">';for(const e of k)if("folder"===e.type){const t=v[e.id]||null;if(t){const e=w(t,!0,C,A);B+='<div class="tree-item folder pinned-item" data-id="'+t.id+'" data-type="folder">',B+=d(e,"folder-icon"),B+='<span class="label">'+l(t.title)+"</span>",B+="</div>"}}else{let t=null;for(const o of r)if(o.id===e.id){t=o;break}if(t){const e=t.id===N?" selected":"",o=f(t);B+='<div class="tree-item note pinned-item'+e+'" data-id="'+t.id+'" data-type="note">',B+='<span class="icon note-icon">'+o+"</span>",B+='<span class="label">'+l(t.title)+"</span>",B+="</div>"}}B+="</div>"}const V=l(JSON.stringify(k)),G={updated_desc:e.sortUpdatedDesc,updated_asc:e.sortUpdatedAsc,title_asc:e.sortTitleAsc,title_desc:e.sortTitleDesc,manual:e.sortManual},Q='<div id="notes-in-list-root" data-i18n="'+l(JSON.stringify(e))+'" data-pinned="'+V+'" data-sort="'+l(b)+'"> <div class="toolbar"> <button id="btn-new-notebook" title="'+e.newNotebook+'">📁+</button> <button id="btn-new-note" title="'+e.newNote+'">📝+</button> <button id="btn-new-todo" title="'+e.newTodo+'">☐+</button> <button id="btn-sort" title="'+e.sort+'">'+G[b]+'</button> <button id="btn-collapse-all" title="'+e.collapseAll+'">▲</button> </div> <div class="search-bar"> <input id="search-input" type="text" placeholder="🔍 '+e.search+'" /> </div> <div id="tree-container">'+B+H+' <div id="drop-zone-empty" class="drop-zone-empty">+ '+e.dropCreateNotebook+'</div> </div> <div id="search-results" style="display:none;"></div> <div class="bottom-bar"> <button id="btn-sync" title="'+e.sync+'">🔄 '+e.sync+"</button> </div></div>";await joplin.views.panels.setHtml(t,Q)}catch(e){console.error("Notes In List: refresh error",e),await joplin.views.panels.setHtml(t,'<div style="padding:12px;color:red;">Error: '+l(String(e))+"</div>")}}async function U(e){try{const o=j.findIndex(t=>t.id===e),n=await joplin.data.get(["notes",e],{fields:["id","title","parent_id","is_todo","todo_completed","updated_time","user_updated_time","order"]});if(o<0||j[o].parent_id!==n.parent_id)return void await A();const i=j[o],a=0===b.indexOf("title_")&&(i.title||"")!==(n.title||""),s=0===b.indexOf("updated_")&&i.user_updated_time!==n.user_updated_time;if(j[o]=n,a||s)return void await A();await joplin.views.panels.postMessage(t,{name:"updateNote",id:n.id,title:n.title||"(untitled)",icon:f(n)})}catch(e){await A()}}await joplin.settings.onChange(async e=>{e.keys&&(e.keys.indexOf("showFolderToggles")>=0||e.keys.indexOf("openFolderIcon")>=0||e.keys.indexOf("closedFolderIcon")>=0||e.keys.indexOf("openPinnedIcon")>=0||e.keys.indexOf("closedPinnedIcon")>=0)&&(function(){for(const e of Object.keys(c))delete c[e]}(),await A())}),await joplin.views.panels.onMessage(t,async o=>{if("openNote"===o.name)N=o.id,await joplin.commands.execute("openNote",o.id);else if("refresh"===o.name)await A();else if("toggleFolder"===o.name)h[o.id]?delete h[o.id]:h[o.id]=!0;else if("collapseAll"===o.name)for(const e of _)h[e.id]=!0;else if("expandAll"===o.name)h={},await A();else if("newNotebook"===o.name){const o=await x(e.promptNewNotebookName,"");if(!o||!o.trim())return;const n=await joplin.data.post(["folders"],null,{title:o.trim()});delete h[n.id],await A(),await joplin.views.panels.postMessage(t,{name:"scrollToFolder",folderId:n.id})}else if("newNote"===o.name){await joplin.commands.execute("newNote");const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),await A()}else if("newTodo"===o.name){await joplin.commands.execute("newTodo");const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),await A()}else if("search"===o.name)await async function(e){const o=e.query;if(o&&o.trim())try{const n=o.toLowerCase(),i={};for(const e of _)i[e.id]=e.title;let a=[],s=1,l=!0;for(;l&&a.length<100;){const e=await joplin.data.get(["search"],{query:o,fields:["id","title","body","parent_id","is_todo","todo_completed"],page:s,limit:20});a=a.concat(e.items),l=e.has_more,s++}const r=new Set(a.map(e=>e.id)),d=[];for(const e of j)!r.has(e.id)&&(e.title||"").toLowerCase().indexOf(n)>=0&&d.push(e);for(let e=0;e<d.length&&e<50;e++)try{const t=await joplin.data.get(["notes",d[e].id],{fields:["id","title","body","parent_id","is_todo","todo_completed"]});a.push(t)}catch(e){}const c=[];for(const e of a){let t="";const o=e.body||"",a=o.toLowerCase().indexOf(n);if(a>=0){const e=Math.max(0,a-40),i=Math.min(o.length,a+n.length+80);t=(e>0?"...":"")+o.substring(e,i).replace(/\n/g," ")+(i<o.length?"...":"")}else t=o.substring(0,120).replace(/\n/g," ")+(o.length>120?"...":"");c.push({id:e.id,title:e.title||"(untitled)",is_todo:e.is_todo,todo_completed:e.todo_completed,snippet:t,folderName:i[e.parent_id]||""})}let p=[],u=1,w=!0;for(;w;){const e=await joplin.data.get(["tags"],{fields:["id","title"],page:u,limit:100});p=p.concat(e.items),w=e.has_more,u++}const f=[];for(const e of p)if((e.title||"").toLowerCase().indexOf(n)>=0){let t=0;try{const o=await joplin.data.get(["tags",e.id,"notes"],{fields:["id"],limit:100});t=o.has_more?o.items.length+"+":o.items.length}catch(e){}f.push({id:e.id,title:e.title,noteCount:t})}const m=[];for(const e of _)if((e.title||"").toLowerCase().indexOf(n)>=0){let t="";if(e.icon&&"string"==typeof e.icon)try{const o=JSON.parse(e.icon);o&&o.emoji&&(t=String(o.emoji))}catch(e){}m.push({id:e.id,title:e.title,parent_id:e.parent_id,iconEmoji:t})}await joplin.views.panels.postMessage(t,{name:"searchResults",notes:c,tags:f,folders:m,query:o,searchId:e.searchId})}catch(e){console.error("Joplin Explorer: search error",e)}else await joplin.views.panels.postMessage(t,{name:"searchResults",results:null,query:"",searchId:e.searchId})}(o);else if("loadTagNotes"===o.name)try{const e=o.tagId;let n=[],i=1,a=!0;for(;a&&n.length<100;){const t=await joplin.data.get(["tags",e,"notes"],{fields:["id","title","parent_id","is_todo","todo_completed"],page:i,limit:50});n=n.concat(t.items),a=t.has_more,i++}const s={};for(const e of _)s[e.id]=e.title;const l=n.map(e=>({id:e.id,title:e.title||"(untitled)",is_todo:e.is_todo,todo_completed:e.todo_completed,snippet:"",folderName:s[e.parent_id]||""}));await joplin.views.panels.postMessage(t,{name:"tagNotes",tagId:e,notes:l})}catch(e){console.error("Joplin Explorer: loadTagNotes error",e)}else if("locateFolder"===o.name)try{R(o.folderId),await A(),await joplin.views.panels.postMessage(t,{name:"exitSearchAndLocate",folderId:o.folderId})}catch(e){console.error("Joplin Explorer: locateFolder error",e)}else if("locatePinnedFolder"===o.name)try{R(o.folderId),await A(),await joplin.views.panels.postMessage(t,{name:"scrollToFolder",folderId:o.folderId})}catch(e){console.error("Joplin Explorer: locatePinnedFolder error",e)}else if("reorderPinned"===o.name)try{const e=o.dragId,t=o.targetId,n=o.position,i=k.findIndex(t=>t.id===e);if(i<0)return;const a=k[i];k.splice(i,1);let s=k.findIndex(e=>e.id===t);s<0?k.push(a):("after"===n&&s++,k.splice(s,0,a)),await E(),await A()}catch(e){console.error("Joplin Explorer: reorderPinned error",e)}else if("togglePinnedCollapse"===o.name)S=!S;else if("cycleSort"===o.name){const e=["updated_desc","updated_asc","title_asc","title_desc","manual"],t=e.indexOf(b);b=e[(t+1)%e.length],await A()}else if("sync"===o.name)try{await joplin.commands.execute("synchronize")}catch(o){console.error("Joplin Explorer: sync command failed",o),await joplin.views.panels.postMessage(t,{name:"syncState",state:"error"});const n=o&&o.message?String(o.message):String(o);await y(e.syncFailed,n)}else if("contextMenu"===o.name)await async function(o){const n=o.action,i=o.id,a=o.itemType;try{if("folder"===a)switch(n){case"newNote":{const t=await joplin.data.post(["notes"],null,{title:e.newNote,parent_id:i});await joplin.commands.execute("openNote",t.id),N=t.id,R(i);break}case"newTodo":{const t=await joplin.data.post(["notes"],null,{title:e.newTodo,parent_id:i,is_todo:1});await joplin.commands.execute("openNote",t.id),N=t.id,R(i);break}case"newSubNotebook":{const t=await x(e.newNotebook,"");if(t&&t.trim()){const e=await joplin.data.post(["folders"],null,{title:t.trim(),parent_id:i});delete h[i],delete h[e.id]}break}case"deleteFolder":{const t=await joplin.data.get(["folders",i],{fields:["title"]});await r(e.confirmDeleteFolder+"\n\n"+t.title)&&await joplin.data.delete(["folders",i]);break}case"renameFolder":{const t=await joplin.data.get(["folders",i],{fields:["title"]}),o=await x(e.promptRename,t.title);o&&o.trim()&&await joplin.data.put(["folders",i],null,{title:o.trim()});break}case"exportFolder":try{await joplin.commands.execute("exportFolders",[i])}catch(e){}break;case"pinFolder":k.some(e=>e.id===i)||(k.push({id:i,type:"folder"}),await E());break;case"unpinFolder":k=k.filter(e=>e.id!==i),await E()}else if("note"===a)switch(n){case"openNote":await joplin.commands.execute("openNote",i),N=i;break;case"openInNewWindow":try{await joplin.commands.execute("openNoteInNewWindow",i)}catch(e){await joplin.commands.execute("openNote",i)}break;case"copyLink":{const e=await joplin.data.get(["notes",i],{fields:["id","title"]}),o="["+e.title+"](:/"+e.id+")";try{await joplin.clipboard.writeText(o)}catch(e){await joplin.views.panels.postMessage(t,{name:"copyText",text:o})}break}case"duplicateNote":{const e=await joplin.data.get(["notes",i],{fields:["title","body","parent_id","is_todo"]}),t=await joplin.data.post(["notes"],null,{title:e.title+" (copy)",body:e.body,parent_id:e.parent_id,is_todo:e.is_todo});await joplin.commands.execute("openNote",t.id),N=t.id;break}case"switchNoteType":{const e=await joplin.data.get(["notes",i],{fields:["is_todo"]});await joplin.data.put(["notes",i],null,{is_todo:e.is_todo?0:1});break}case"toggleTodo":{const e=await joplin.data.get(["notes",i],{fields:["is_todo","todo_completed"]});e.is_todo&&await joplin.data.put(["notes",i],null,{todo_completed:e.todo_completed?0:Date.now()});break}case"renameNote":{const t=await joplin.data.get(["notes",i],{fields:["title"]}),o=await x(e.promptRename,t.title);o&&o.trim()&&await joplin.data.put(["notes",i],null,{title:o.trim()});break}case"moveNote":if(o.targetFolderName){let e=null;for(const t of _)if(t.title===o.targetFolderName){e=t;break}e&&await joplin.data.put(["notes",i],null,{parent_id:e.id})}break;case"noteInfo":{const t=await joplin.data.get(["notes",i],{fields:["id","title","created_time","updated_time","is_todo","parent_id","body"]}),o=v[t.parent_id]?v[t.parent_id].title:"",n=(t.body||"").length,a="ID: "+t.id+"\n"+(e.ctxRenameNote||"Title")+": "+t.title+"\n"+(e.newNotebook||"Notebook")+": "+o+"\n"+(e.sortUpdatedDesc?e.sortUpdatedDesc.replace(/[↓↑\u2193\u2191]\s*/,""):"Created")+": "+new Date(t.created_time).toLocaleString()+"\n"+(e.sortUpdatedAsc?e.sortUpdatedAsc.replace(/[↓↑\u2193\u2191]\s*/,""):"Updated")+": "+new Date(t.updated_time).toLocaleString()+"\nType: "+(t.is_todo?"To-do":"Note")+"\nSize: "+n+" chars";await y(t.title,a);break}case"deleteNote":{const t=await joplin.data.get(["notes",i],{fields:["title"]});await r(e.confirmDeleteNote+"\n\n"+t.title)&&await joplin.data.delete(["notes",i]);break}case"pinNote":k.some(e=>e.id===i)||(k.push({id:i,type:"note"}),await E());break;case"unpinNote":k=k.filter(e=>e.id!==i),await E()}await A()}catch(e){console.error("Notes In List: context menu error",e)}}(o);else if("dragDrop"===o.name)await async function(e){try{const t=e.dragId,o=e.dragType,n=e.targetId,i=e.position;if("note"===o)if(v[n])await joplin.data.put(["notes",t],null,{parent_id:n});else{const e=await joplin.data.get(["notes",n],{fields:["parent_id"]});"manual"!==b||"above"!==i&&"below"!==i?await joplin.data.put(["notes",t],null,{parent_id:e.parent_id}):await async function(e,t,o){const n=(await joplin.data.get(["notes",t],{fields:["parent_id"]})).parent_id,i=j.filter(t=>t.parent_id===n&&t.id!==e).sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(t.user_updated_time||0)-(e.user_updated_time||0)}),a=i.findIndex(e=>e.id===t),s=a<0?i.length:"above"===o?a:a+1,l=s>0?i[s-1]:null,r=s<i.length?i[s]:null,d=l?l.order||0:null,c=r?r.order||0:null,p=1e6;if(i.every(e=>0===(e.order||0))||null!==d&&null!==c&&d-c<2){const t=Date.now(),o=i.slice();o.splice(s,0,null);let a=t;const l=[];for(let e=0;e<o.length;e++){const n=t-e*p,i=o[e];null===i?a=n:l.push(joplin.data.put(["notes",i.id],null,{order:n}))}return await Promise.all(l),void await joplin.data.put(["notes",e],null,{parent_id:n,order:a})}let u;u=null!==d&&null!==c?(d+c)/2:null!==d?d-p:null!==c?c+p:Date.now(),await joplin.data.put(["notes",e],null,{parent_id:n,order:u})}(t,n,i)}else if("folder"===o){const e=!!v[n];"into"===i?e&&t!==n&&await joplin.data.put(["folders",t],null,{parent_id:n}):!e||"above"!==i&&"below"!==i||await async function(e,t,o){const n=v[t],i=v[e];if(!n||!i||e===t)return;const a=n.parent_id||"";let s=a;for(;s;){if(s===e)return;s=v[s]&&v[s].parent_id||""}const l=_.filter(t=>(t.parent_id||"")===a&&t.id!==e).sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(e.title||"").localeCompare(t.title||"")}),r=l.findIndex(e=>e.id===t),d=r<0?l.length:"above"===o?r:r+1,c=d>0?l[d-1]:null,p=d<l.length?l[d]:null,u=c?c.order||0:null,w=p?p.order||0:null,f=l.every(e=>0===(e.order||0)),m=null!==u&&null!==w&&u-w<2,g=1e6;if((i.parent_id||"")!==a&&await joplin.data.put(["folders",e],null,{parent_id:a}),f||m){const t=Date.now(),o=l.slice();o.splice(d,0,null);for(let n=0;n<o.length;n++){const i=t-n*g,a=o[n];null===a?T[e]=i:T[a.id]=i}return void await M()}let y;y=null!==u&&null!==w?(u+w)/2:null!==u?u-g:null!==w?w+g:Date.now(),T[e]=y,await M()}(t,n,i)}await A()}catch(e){console.error("Notes In List: drag drop error",e)}}(o);else if("dragToEmpty"===o.name)try{const t=o.dragId,n=o.dragType,i=await x(e.promptNewNotebookName,"");if(!i||!i.trim())return;const a=await joplin.data.post(["folders"],null,{title:i.trim()});"note"===n?await joplin.data.put(["notes",t],null,{parent_id:a.id}):"folder"===n&&t!==a.id&&await joplin.data.put(["folders",t],null,{parent_id:a.id}),await A()}catch(e){console.error("Notes In List: drag to empty error",e)}}),await joplin.workspace.onNoteSelectionChange(async()=>{const e=await joplin.workspace.selectedNote();e&&e.id!==N&&(N=e.id,await joplin.views.panels.postMessage(t,{name:"selectNote",id:e.id}))}),await joplin.workspace.onNoteChange(async e=>{var t;e&&e.id?(t=e.id,C[t]=!0,O&&clearTimeout(O),O=setTimeout(async()=>{O=null;const e=Object.keys(C);C={};for(const t of e)await U(t)},600)):function(e=600){F&&clearTimeout(F),F=setTimeout(async()=>{F=null,await A()},e)}()});try{await joplin.workspace.onSyncStart(async()=>{await joplin.views.panels.postMessage(t,{name:"syncState",state:"syncing"})})}catch(e){console.warn("Joplin Explorer: onSyncStart not available",e)}try{await joplin.workspace.onSyncComplete(async o=>{const n=!(!o||!o.withErrors);await A(),await joplin.views.panels.postMessage(t,{name:"syncState",state:n?"error":"done"}),n&&await y(e.syncFailed,"Joplin reported errors during synchronisation. Open the Synchronisation Status screen (Tools → Synchronisation Status) to see the details.")})}catch(e){console.warn("Joplin Explorer: onSyncComplete not available",e)}await A()}})})();
|
|
1
|
+
(()=>{"use strict";var e={982(e){e.exports=require("crypto")},896(e){e.exports=require("fs")},928(e){e.exports=require("path")}},t={};function o(n){var i=t[n];if(void 0!==i)return i.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,o),a.exports}const n={zh_CN:{newNotebook:"新建笔记本",newNote:"新建笔记",newTodo:"新建待办",sort:"排序",collapseAll:"全部折叠",expandAll:"全部展开",search:"搜索笔记内容...",searchResultCount:"找到 {count} 条结果",searchNoResult:"没有找到匹配的笔记",searching:"搜索中...",sync:"同步",syncing:"同步中...",syncDone:"✔ 同步完成",syncFailed:"⚠ 同步失败",loading:"加载中...",sortUpdatedDesc:"↓ 修改时间",sortUpdatedAsc:"↑ 修改时间",sortTitleAsc:"↑ 标题",sortTitleDesc:"↓ 标题",sortManual:"⇅ 手动排序",ctxNewNoteHere:"在此新建笔记",ctxNewTodoHere:"在此新建待办",ctxNewSubNotebook:"新建子笔记本",ctxRenameFolder:"重命名",ctxExportFolder:"导出笔记本",ctxDeleteFolder:"删除笔记本",ctxOpenNote:"打开笔记",ctxOpenInNewWindow:"在新窗口中打开",ctxCopyLink:"复制 Markdown 链接",ctxDuplicateNote:"复制副本",ctxSwitchNoteType:"笔记/待办 切换",ctxToggleTodo:"切换完成状态",ctxRenameNote:"重命名",ctxMoveNote:"移动到笔记本...",ctxNoteInfo:"笔记属性",ctxDeleteNote:"删除笔记",confirmDeleteFolder:"确定删除此笔记本及其所有内容吗?",confirmDeleteNote:"确定删除此笔记吗?",promptRename:"请输入新名称:",promptMoveNote:"请输入目标笔记本名称:",promptNewNotebookName:"请输入新笔记本名称:",dropCreateNotebook:"释放以创建新笔记本",searchSectionNotes:"笔记",searchSectionTags:"标签",searchSectionFolders:"笔记本",searchTagNoteCount:"{count} 条笔记",pinned:"收藏夹",ctxPin:"📌 收藏",ctxUnpin:"取消收藏",cancel:"取消"},zh_TW:{newNotebook:"新建筆記本",newNote:"新建筆記",newTodo:"新建待辦",sort:"排序",collapseAll:"全部摺疊",expandAll:"全部展開",search:"搜尋筆記內容...",searchResultCount:"找到 {count} 條結果",searchNoResult:"沒有找到匹配的筆記",searching:"搜尋中...",sync:"同步",syncing:"同步中...",syncDone:"✔ 同步完成",syncFailed:"⚠ 同步失敗",loading:"載入中...",sortUpdatedDesc:"↓ 修改時間",sortUpdatedAsc:"↑ 修改時間",sortTitleAsc:"↑ 標題",sortTitleDesc:"↓ 標題",sortManual:"⇅ 手動排序",ctxNewNoteHere:"在此新建筆記",ctxNewTodoHere:"在此新建待辦",ctxNewSubNotebook:"新建子筆記本",ctxRenameFolder:"重新命名",ctxExportFolder:"匯出筆記本",ctxDeleteFolder:"刪除筆記本",ctxOpenNote:"開啟筆記",ctxOpenInNewWindow:"在新視窗中開啟",ctxCopyLink:"複製 Markdown 連結",ctxDuplicateNote:"複製副本",ctxSwitchNoteType:"筆記/待辦 切換",ctxToggleTodo:"切換完成狀態",ctxRenameNote:"重新命名",ctxMoveNote:"移動到筆記本...",ctxNoteInfo:"筆記屬性",ctxDeleteNote:"刪除筆記",confirmDeleteFolder:"確定刪除此筆記本及其所有內容嗎?",confirmDeleteNote:"確定刪除此筆記嗎?",promptRename:"請輸入新名稱:",promptMoveNote:"請輸入目標筆記本名稱:",promptNewNotebookName:"請輸入新筆記本名稱:",dropCreateNotebook:"釋放以建立新筆記本",searchSectionNotes:"筆記",searchSectionTags:"標籤",searchSectionFolders:"筆記本",searchTagNoteCount:"{count} 條筆記",pinned:"收藏夾",ctxPin:"📌 收藏",ctxUnpin:"取消收藏",cancel:"取消"},en_US:{newNotebook:"New Notebook",newNote:"New Note",newTodo:"New To-do",sort:"Sort",collapseAll:"Collapse All",expandAll:"Expand All",search:"Search note contents...",searchResultCount:"{count} results found",searchNoResult:"No matching notes found",searching:"Searching...",sync:"Synchronise",syncing:"Syncing...",syncDone:"✔ Sync Done",syncFailed:"⚠ Sync Failed",loading:"Loading...",sortUpdatedDesc:"↓ Updated",sortUpdatedAsc:"↑ Updated",sortTitleAsc:"↑ Title",sortTitleDesc:"↓ Title",sortManual:"⇅ Manual",ctxNewNoteHere:"New Note Here",ctxNewTodoHere:"New To-do Here",ctxNewSubNotebook:"New Sub-notebook",ctxRenameFolder:"Rename",ctxExportFolder:"Export Notebook",ctxDeleteFolder:"Delete Notebook",ctxOpenNote:"Open Note",ctxOpenInNewWindow:"Open in New Window",ctxCopyLink:"Copy Markdown Link",ctxDuplicateNote:"Duplicate",ctxSwitchNoteType:"Switch Note/To-do",ctxToggleTodo:"Toggle Completed",ctxRenameNote:"Rename",ctxMoveNote:"Move to Notebook...",ctxNoteInfo:"Note Properties",ctxDeleteNote:"Delete Note",confirmDeleteFolder:"Delete this notebook and all its contents?",confirmDeleteNote:"Delete this note?",promptRename:"Enter new name:",promptMoveNote:"Enter target notebook name:",promptNewNotebookName:"Enter new notebook name:",dropCreateNotebook:"Release to create a new notebook",searchSectionNotes:"Notes",searchSectionTags:"Tags",searchSectionFolders:"Notebooks",searchTagNoteCount:"{count} notes",pinned:"Pinned",ctxPin:"📌 Pin",ctxUnpin:"Unpin",cancel:"Cancel"},ru:{newNotebook:"Новый блокнот",newNote:"Новая заметка",newTodo:"Новая задача",sort:"Сортировка",collapseAll:"Свернуть все",expandAll:"Развернуть все",search:"Искать в содержимом заметок...",searchResultCount:"Найдено результатов: {count}",searchNoResult:"Заметки не найдены",searching:"Поиск...",sync:"Синхронизировать",syncing:"Синхронизация...",syncDone:"✔ Синхронизация завершена",syncFailed:"⚠ Ошибка синхронизации",loading:"Загрузка...",sortUpdatedDesc:"↓ Обновлено",sortUpdatedAsc:"↑ Обновлено",sortTitleAsc:"↑ Название",sortTitleDesc:"↓ Название",sortManual:"⇅ Вручную",ctxNewNoteHere:"Создать заметку здесь",ctxNewTodoHere:"Создать задачу здесь",ctxNewSubNotebook:"Новый вложенный блокнот",ctxRenameFolder:"Переименовать",ctxExportFolder:"Экспортировать блокнот",ctxDeleteFolder:"Удалить блокнот",ctxOpenNote:"Открыть заметку",ctxOpenInNewWindow:"Открыть в новом окне",ctxCopyLink:"Скопировать Markdown-ссылку",ctxDuplicateNote:"Создать копию",ctxSwitchNoteType:"Переключить между заметкой и задачей",ctxToggleTodo:"Переключить статус выполнения",ctxRenameNote:"Переименовать",ctxMoveNote:"Переместить в блокнот...",ctxNoteInfo:"Свойства заметки",ctxDeleteNote:"Удалить заметку",confirmDeleteFolder:"Удалить блокнот и все его содержимое?",confirmDeleteNote:"Удалить заметку?",promptRename:"Введите новое название:",promptMoveNote:"Переместить в блокнот:",promptNewNotebookName:"Введите название нового блокнота:",dropCreateNotebook:"Отпустите, чтобы создать новый блокнот",searchSectionNotes:"Заметки",searchSectionTags:"Метки",searchSectionFolders:"Блокноты",searchTagNoteCount:"Заметок: {count}",pinned:"Закрепленные",ctxPin:"📌 Закрепить",ctxUnpin:"Открепить",cancel:"Отмена"},ja_JP:{newNotebook:"新規ノートブック",newNote:"新規ノート",newTodo:"新規タスク",sort:"並べ替え",collapseAll:"すべて折りたたむ",expandAll:"すべて展開",search:"ノート内容を検索...",searchResultCount:"{count} 件の結果",searchNoResult:"一致するノートが見つかりません",searching:"検索中...",sync:"同期",syncing:"同期中...",syncDone:"✔ 同期完了",syncFailed:"⚠ 同期に失敗しました",loading:"読み込み中...",sortUpdatedDesc:"↓ 更新日時",sortUpdatedAsc:"↑ 更新日時",sortTitleAsc:"↑ タイトル",sortTitleDesc:"↓ タイトル",sortManual:"⇅ 手動",ctxNewNoteHere:"ここに新規ノート",ctxNewTodoHere:"ここに新規タスク",ctxNewSubNotebook:"新規サブノートブック",ctxRenameFolder:"名前を変更",ctxExportFolder:"ノートブックをエクスポート",ctxDeleteFolder:"ノートブックを削除",ctxOpenNote:"ノートを開く",ctxOpenInNewWindow:"新しいウィンドウで開く",ctxCopyLink:"Markdownリンクをコピー",ctxDuplicateNote:"複製",ctxSwitchNoteType:"ノート/タスク切り替え",ctxToggleTodo:"完了状態を切り替え",ctxRenameNote:"名前を変更",ctxMoveNote:"ノートブックに移動...",ctxNoteInfo:"ノートプロパティ",ctxDeleteNote:"ノートを削除",confirmDeleteFolder:"このノートブックとその内容をすべて削除しますか?",confirmDeleteNote:"このノートを削除しますか?",promptRename:"新しい名前を入力:",promptMoveNote:"移動先のノートブック名:",promptNewNotebookName:"新しいノートブック名を入力:",dropCreateNotebook:"ドロップして新規ノートブックを作成",searchSectionNotes:"ノート",searchSectionTags:"タグ",searchSectionFolders:"ノートブック",searchTagNoteCount:"{count} 件のノート",pinned:"ピン留め",ctxPin:"📌 ピン留め",ctxUnpin:"ピン解除",cancel:"キャンセル"}},i=o(896),a=o(928),s=o(982);function l(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const r={".gif":"image/gif",".ico":"image/x-icon",".jpeg":"image/jpeg",".jpg":"image/jpeg",".png":"image/png",".svg":"image/svg+xml",".webp":"image/webp"};function d(e,t){const o="icon"+(t?" "+t:"");return"image"===e.type?'<span class="'+o+'"><img class="custom-icon" src="'+l(e.value)+'" /></span>':'<span class="'+o+'">'+l(e.value)+"</span>"}const c={};async function p(e,t,o,n){const l=o+":"+String(e);if(c[l])return c[l];const d=await async function(e,t,o,n){const l="string"==typeof e?e.trim():"";if(!l)return{type:"text",value:t};if(/^data:image\//i.test(l)||/^https?:\/\//i.test(l))return{type:"image",value:l};const d=function(e){const t=e.trim();return/^file:\/\//i.test(t)?decodeURIComponent(t.replace(/^file:\/\//i,"")):0===t.indexOf("~/")&&process&&process.env&&process.env.HOME?a.join(process.env.HOME,t.substring(2)):a.isAbsolute(t)?t:null}(l);if(!d)return{type:"text",value:l};const c=a.extname(d).toLowerCase(),p=r[c];if(!p)return console.warn("Joplin Explorer: unsupported icon file type",d),{type:"text",value:t};const u=a.join(n,"custom-icons"),w=s.createHash("sha1").update(d).digest("hex"),f=a.join(u,o+"-"+w+c);try{await i.promises.mkdir(u,{recursive:!0}),(await i.promises.stat(d)).isFile()&&await i.promises.copyFile(d,f)}catch(e){console.warn("Joplin Explorer: failed to copy icon file",d,e)}try{return{type:"image",value:"data:"+p+";base64,"+(await i.promises.readFile(f)).toString("base64")}}catch(e){return console.warn("Joplin Explorer: failed to load icon file",f,e),{type:"text",value:t}}}(e,t,o,n);return c[l]=d,d}function u(e,t){const o=e.order||0,n=t.order||0;return o!==n?n-o:(e.title||"").localeCompare(t.title||"")}function w(e,t=!0,o={type:"text",value:"📂"},n={type:"text",value:"📁"}){let i=e.icon;if(i&&"string"==typeof i)try{i=JSON.parse(i)}catch(e){i=null}return i&&i.emoji?{type:"text",value:String(i.emoji)}:t?n:o}function f(e){return e.is_todo?e.todo_completed?"☑":"☐":"📝"}function m(e,t,o,n=0,i=!0,a={type:"text",value:"📂"},s={type:"text",value:"📁"}){let r="";for(const c of e){const e=8+18*n;if("folder"===c.type){const p=c.total_count||c.note_count||0,u=!0===o[c.id],f=u?"▶":"▼",g=u?"toggle":"toggle expanded";r+='<div class="tree-item folder'+(u?" collapsed":"")+'" style="padding-left:'+e+'px" data-id="'+c.id+'" data-type="folder">',i&&(r+='<span class="'+g+'">'+f+"</span>"),r+=d(w(c,!1,a,s),"folder-icon icon-when-open"),r+=d(w(c,!0,a,s),"folder-icon icon-when-collapsed"),r+='<span class="label">'+l(c.title)+"</span>",r+='<span class="count">'+p+"</span>",r+="</div>",r+='<div class="children'+(u?" collapsed":"")+'" data-folder-id="'+c.id+'">',c.children&&(r+=m(c.children,t,o,n+1,i,a,s)),r+="</div>"}else{const o=c.id===t?" selected":"",n=f(c);r+='<div class="tree-item note'+o+'" style="padding-left:'+e+'px" data-id="'+c.id+'" data-type="note" data-todo="'+(c.is_todo?1:0)+'">',r+='<span class="icon note-icon">'+n+"</span>",r+='<span class="label">'+l(c.title)+"</span>",r+="</div>"}}return r}function g(e,t){const o=e.slice();switch(t){case"title_asc":o.sort((e,t)=>(e.title||"").localeCompare(t.title||""));break;case"title_desc":o.sort((e,t)=>(t.title||"").localeCompare(e.title||""));break;case"updated_asc":o.sort((e,t)=>(e.user_updated_time||0)-(t.user_updated_time||0));break;case"manual":o.sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(t.user_updated_time||0)-(e.user_updated_time||0)});break;default:o.sort((e,t)=>(t.user_updated_time||0)-(e.user_updated_time||0))}return o}joplin.plugins.register({onStart:async function(){const e=(o=await joplin.settings.globalValue("locale")||"en_US",n[o]||n[o.split("_")[0]]||n.en_US),t=await joplin.views.panels.create("notesInListPanel");var o;await joplin.views.panels.addScript(t,"webview/panel.css"),await joplin.views.panels.addScript(t,"webview/panel.js"),await joplin.views.panels.setHtml(t,'<div id="notes-in-list-root"><p style="padding:12px;">'+e.loading+"</p></div>"),await joplin.views.panels.show(t,!0);try{await joplin.settings.registerSection("joplinExplorer",{label:"Joplin Explorer",iconName:"fas fa-columns"}),await joplin.settings.registerSettings({pinnedItems:{section:"joplinExplorer",type:2,value:'{"notes":[],"folders":[]}',public:!1,label:"Pinned Items (JSON)"},folderOrder:{section:"joplinExplorer",type:2,value:"{}",public:!1,label:"Folder Manual Order (JSON)"},noteSortMode:{section:"joplinExplorer",type:2,value:"updated_desc",public:!1,label:"Note Sort Mode"},showFolderToggles:{section:"joplinExplorer",type:3,value:!0,public:!0,label:"Show toggle arrows",description:"Show expand/collapse arrows before folders and the pinned section."},openFolderIcon:{section:"joplinExplorer",type:2,value:"📂",public:!0,label:"Open folder icon",description:"Emoji, image URL, data URI, or local image path for expanded folders without a custom notebook icon."},closedFolderIcon:{section:"joplinExplorer",type:2,value:"📁",public:!0,label:"Closed folder icon",description:"Emoji, image URL, data URI, or local image path for collapsed folders without a custom notebook icon."},openPinnedIcon:{section:"joplinExplorer",type:2,value:"📌",public:!0,label:"Open pinned icon",description:"Emoji, image URL, data URI, or local image path for the expanded pinned section."},closedPinnedIcon:{section:"joplinExplorer",type:2,value:"📌",public:!0,label:"Closed pinned icon",description:"Emoji, image URL, data URI, or local image path for the collapsed pinned section."}})}catch(e){console.error("Joplin Explorer: failed to register settings",e)}const i=await joplin.views.dialogs.create("explorerInputDialog"),a=await joplin.views.dialogs.create("explorerConfirmDialog"),s=await joplin.views.dialogs.create("explorerInfoDialog");async function r(t){return await joplin.views.dialogs.setHtml(a,'<div style="padding:10px;min-width:280px;"><div style="font-size:13px;">'+l(t)+"</div></div>"),await joplin.views.dialogs.setButtons(a,[{id:"ok",title:"OK"},{id:"cancel",title:e.cancel||"Cancel"}]),"ok"===(await joplin.views.dialogs.open(a)).id}async function y(e,t){await joplin.views.dialogs.setHtml(s,'<div style="padding:10px;min-width:320px;"><div style="font-size:14px;font-weight:bold;margin-bottom:10px;">'+l(e)+'</div><div style="font-size:12px;line-height:1.8;white-space:pre-wrap;">'+l(t)+"</div></div>"),await joplin.views.dialogs.setButtons(s,[{id:"ok",title:"OK"}]),await joplin.views.dialogs.open(s)}async function x(t,o){await joplin.views.dialogs.setHtml(i,'<div style="padding:10px;min-width:300px;"><div style="margin-bottom:8px;font-size:13px;">'+l(t)+'</div><form name="inputForm"><input name="value" type="text" value="'+l(o||"")+'" style="width:100%;box-sizing:border-box;padding:6px 8px;font-size:13px;" /></form></div>'),await joplin.views.dialogs.setButtons(i,[{id:"ok",title:"OK"},{id:"cancel",title:e.cancel||"Cancel"}]);const n=await joplin.views.dialogs.open(i);return"ok"===n.id&&n.formData&&n.formData.inputForm&&n.formData.inputForm.value||null}let N="",h={},b="updated_desc";try{const e=String(await joplin.settings.value("noteSortMode")||"");["updated_desc","updated_asc","title_asc","title_desc","manual"].indexOf(e)>=0&&(b=e)}catch(e){}let _=[],v={},j=[],k=[],S=!1,T={},I=!0;const D=await joplin.plugins.dataDir();let F=null,O=null,C={};async function M(){try{await joplin.settings.setValue("pinnedItems",JSON.stringify(k))}catch(e){console.error("Joplin Explorer: failed to save pinned items",e)}}async function E(){try{await joplin.settings.setValue("folderOrder",JSON.stringify(T))}catch(e){console.error("Joplin Explorer: failed to save folder order",e)}}function R(e){let t=e;for(;t;){delete h[t];const e=v[t];t=e?e.parent_id:null}}async function A(){try{const o=await async function(){let e=[],t=1,o=!0;for(;o;){const n=await joplin.data.get(["folders"],{fields:["id","title","parent_id","icon"],page:t,limit:100});e=e.concat(n.items),o=n.has_more,t++}return e}();await async function(){try{const e=await joplin.settings.value("folderOrder"),t=e?JSON.parse(e):{};T=t&&"object"==typeof t&&!Array.isArray(t)?t:{}}catch(e){T={}}}();let n=!1;const i=new Set(o.map(e=>e.id));for(const e of Object.keys(T))i.has(e)||(delete T[e],n=!0);n&&await E();for(const e of o)e.order=T[e.id]||0;_=o,v={};for(const e of o)v[e.id]=e;if(I){for(const e of o)h[e.id]=!0;const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),I=!1}const a=await async function(){let e=[],t=1,o=!0;for(;o;){const n=await joplin.data.get(["notes"],{fields:["id","title","parent_id","is_todo","todo_completed","updated_time","user_updated_time","order"],page:t,limit:100});e=e.concat(n.items),o=n.has_more,t++}return e}(),s={};for(const e of o)s[e.id]=[];for(const e of a)s[e.parent_id]&&s[e.parent_id].push(e);for(const e of Object.keys(s))s[e]=g(s[e],b);const r=[];for(const e of Object.keys(s))for(const t of s[e])r.push(t);j=r;const c=await joplin.settings.value("showFolderToggles"),y=await joplin.settings.value("openFolderIcon"),x=await joplin.settings.value("closedFolderIcon"),F=await joplin.settings.value("openPinnedIcon"),O=await joplin.settings.value("closedPinnedIcon"),C=await p(y,"📂","openFolderIcon",D),A=await p(x,"📁","closedFolderIcon",D),U=await p(F,"📌","openPinnedIcon",D),J=await p(O,"📌","closedPinnedIcon",D),L=!1!==c,P=function(e,t){const o={},n={},i={};for(const t of e)o[t.id]={type:"folder",id:t.id,title:t.title,parent_id:t.parent_id,icon:t.icon,order:t.order||0,note_count:0,children:[]},n[t.id]=[],i[t.id]=[];for(const e of Object.keys(t))if(i[e])for(const o of t[e])i[e].push({type:"note",id:o.id,title:o.title||"(untitled)",is_todo:o.is_todo,todo_completed:o.todo_completed});const a=[];for(const t of e){const e=o[t.id];t.parent_id&&o[t.parent_id]?n[t.parent_id].push(e):a.push(e)}function s(e){const t=n[e.id].sort(u);for(const e of t)s(e);e.note_count=i[e.id].length,e.children=t.concat(i[e.id])}a.sort(u);for(const e of a)s(e);const l=a;function r(e){let t=0;if(!e.children)return 0;for(const o of e.children)"note"===o.type?t++:"folder"===o.type&&(r(o),t+=o.total_count||0);return e.total_count=t,t}for(const e of l)r(e);return l}(o,s),H=m(P,N,h,0,L,C,A);await async function(){try{const e=await joplin.settings.value("pinnedItems");if(!e)return;const t=JSON.parse(e);if(t&&!Array.isArray(t)&&t.notes&&t.folders){k=[];for(const e of t.folders)k.push({id:e,type:"folder"});for(const e of t.notes)k.push({id:e,type:"note"});await M()}else Array.isArray(t)&&(k=t)}catch(e){k=[]}}();const z=new Set(o.map(e=>e.id)),W=new Set(r.map(e=>e.id)),q=k.length;k=k.filter(e=>"folder"===e.type?z.has(e.id):W.has(e.id)),k.length!==q&&await M();let V="";const B=k.length;if(B>0){V+='<div class="pinned-section-header'+(S?" collapsed":"")+'" id="pinned-header">',L&&(V+='<span class="toggle">'+(S?"▶":"▼")+"</span>"),V+=d(U,"icon-when-open")+d(J,"icon-when-collapsed")+'<span class="label">'+e.pinned+" ("+B+")</span></div>",V+='<div class="pinned-section-body'+(S?" collapsed":"")+'" id="pinned-body">';for(const e of k)if("folder"===e.type){const t=v[e.id]||null;if(t){const e=w(t,!0,C,A);V+='<div class="tree-item folder pinned-item" data-id="'+t.id+'" data-type="folder">',V+=d(e,"folder-icon"),V+='<span class="label">'+l(t.title)+"</span>",V+="</div>"}}else{let t=null;for(const o of r)if(o.id===e.id){t=o;break}if(t){const e=t.id===N?" selected":"",o=f(t);V+='<div class="tree-item note pinned-item'+e+'" data-id="'+t.id+'" data-type="note" data-todo="'+(t.is_todo?1:0)+'">',V+='<span class="icon note-icon">'+o+"</span>",V+='<span class="label">'+l(t.title)+"</span>",V+="</div>"}}V+="</div>"}const K=l(JSON.stringify(k)),G={updated_desc:e.sortUpdatedDesc,updated_asc:e.sortUpdatedAsc,title_asc:e.sortTitleAsc,title_desc:e.sortTitleDesc,manual:e.sortManual},Q='<div id="notes-in-list-root" data-i18n="'+l(JSON.stringify(e))+'" data-pinned="'+K+'" data-sort="'+l(b)+'"> <div class="toolbar"> <button id="btn-new-notebook" title="'+e.newNotebook+'">📁+</button> <button id="btn-new-note" title="'+e.newNote+'">📝+</button> <button id="btn-new-todo" title="'+e.newTodo+'">☐+</button> <button id="btn-sort" title="'+e.sort+'">'+G[b]+'</button> <button id="btn-collapse-all" title="'+e.collapseAll+'">▲</button> </div> <div class="search-bar"> <input id="search-input" type="text" placeholder="🔍 '+e.search+'" /> </div> <div id="tree-container">'+V+H+' <div id="drop-zone-empty" class="drop-zone-empty">+ '+e.dropCreateNotebook+'</div> </div> <div id="search-results" style="display:none;"></div> <div class="bottom-bar"> <button id="btn-sync" title="'+e.sync+'">🔄 '+e.sync+"</button> </div></div>";await joplin.views.panels.setHtml(t,Q)}catch(e){console.error("Notes In List: refresh error",e),await joplin.views.panels.setHtml(t,'<div style="padding:12px;color:red;">Error: '+l(String(e))+"</div>")}}async function U(e){try{const o=j.findIndex(t=>t.id===e),n=await joplin.data.get(["notes",e],{fields:["id","title","parent_id","is_todo","todo_completed","updated_time","user_updated_time","order"]});if(o<0||j[o].parent_id!==n.parent_id)return void await A();const i=j[o],a=0===b.indexOf("title_")&&(i.title||"")!==(n.title||""),s=0===b.indexOf("updated_")&&i.user_updated_time!==n.user_updated_time;if(j[o]=n,a||s)return void await A();await joplin.views.panels.postMessage(t,{name:"updateNote",id:n.id,title:n.title||"(untitled)",icon:f(n)})}catch(e){await A()}}await joplin.settings.onChange(async e=>{e.keys&&(e.keys.indexOf("showFolderToggles")>=0||e.keys.indexOf("openFolderIcon")>=0||e.keys.indexOf("closedFolderIcon")>=0||e.keys.indexOf("openPinnedIcon")>=0||e.keys.indexOf("closedPinnedIcon")>=0)&&(function(){for(const e of Object.keys(c))delete c[e]}(),await A())}),await joplin.views.panels.onMessage(t,async o=>{if("openNote"===o.name)N=o.id,await joplin.commands.execute("openNote",o.id);else if("refresh"===o.name)await A();else if("toggleFolder"===o.name)h[o.id]?delete h[o.id]:h[o.id]=!0;else if("collapseAll"===o.name)for(const e of _)h[e.id]=!0;else if("expandAll"===o.name)h={},await A();else if("newNotebook"===o.name){const o=await x(e.promptNewNotebookName,"");if(!o||!o.trim())return;const n=await joplin.data.post(["folders"],null,{title:o.trim()});delete h[n.id],await A(),await joplin.views.panels.postMessage(t,{name:"scrollToFolder",folderId:n.id})}else if("newNote"===o.name){await joplin.commands.execute("newNote");const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),await A()}else if("newTodo"===o.name){await joplin.commands.execute("newTodo");const e=await joplin.workspace.selectedNote();e&&(N=e.id,R(e.parent_id)),await A()}else if("search"===o.name)await async function(e){const o=e.query;if(o&&o.trim())try{const n=o.toLowerCase(),i={};for(const e of _)i[e.id]=e.title;let a=[],s=1,l=!0;for(;l&&a.length<100;){const e=await joplin.data.get(["search"],{query:o,fields:["id","title","body","parent_id","is_todo","todo_completed"],page:s,limit:20});a=a.concat(e.items),l=e.has_more,s++}const r=new Set(a.map(e=>e.id)),d=[];for(const e of j)!r.has(e.id)&&(e.title||"").toLowerCase().indexOf(n)>=0&&d.push(e);for(let e=0;e<d.length&&e<50;e++)try{const t=await joplin.data.get(["notes",d[e].id],{fields:["id","title","body","parent_id","is_todo","todo_completed"]});a.push(t)}catch(e){}const c=[];for(const e of a){let t="";const o=e.body||"",a=o.toLowerCase().indexOf(n);if(a>=0){const e=Math.max(0,a-40),i=Math.min(o.length,a+n.length+80);t=(e>0?"...":"")+o.substring(e,i).replace(/\n/g," ")+(i<o.length?"...":"")}else t=o.substring(0,120).replace(/\n/g," ")+(o.length>120?"...":"");c.push({id:e.id,title:e.title||"(untitled)",is_todo:e.is_todo,todo_completed:e.todo_completed,snippet:t,folderName:i[e.parent_id]||""})}let p=[],u=1,w=!0;for(;w;){const e=await joplin.data.get(["tags"],{fields:["id","title"],page:u,limit:100});p=p.concat(e.items),w=e.has_more,u++}const f=[];for(const e of p)if((e.title||"").toLowerCase().indexOf(n)>=0){let t=0;try{const o=await joplin.data.get(["tags",e.id,"notes"],{fields:["id"],limit:100});t=o.has_more?o.items.length+"+":o.items.length}catch(e){}f.push({id:e.id,title:e.title,noteCount:t})}const m=[];for(const e of _)if((e.title||"").toLowerCase().indexOf(n)>=0){let t="";if(e.icon&&"string"==typeof e.icon)try{const o=JSON.parse(e.icon);o&&o.emoji&&(t=String(o.emoji))}catch(e){}m.push({id:e.id,title:e.title,parent_id:e.parent_id,iconEmoji:t})}await joplin.views.panels.postMessage(t,{name:"searchResults",notes:c,tags:f,folders:m,query:o,searchId:e.searchId})}catch(e){console.error("Joplin Explorer: search error",e)}else await joplin.views.panels.postMessage(t,{name:"searchResults",results:null,query:"",searchId:e.searchId})}(o);else if("loadTagNotes"===o.name)try{const e=o.tagId;let n=[],i=1,a=!0;for(;a&&n.length<100;){const t=await joplin.data.get(["tags",e,"notes"],{fields:["id","title","parent_id","is_todo","todo_completed"],page:i,limit:50});n=n.concat(t.items),a=t.has_more,i++}const s={};for(const e of _)s[e.id]=e.title;const l=n.map(e=>({id:e.id,title:e.title||"(untitled)",is_todo:e.is_todo,todo_completed:e.todo_completed,snippet:"",folderName:s[e.parent_id]||""}));await joplin.views.panels.postMessage(t,{name:"tagNotes",tagId:e,notes:l})}catch(e){console.error("Joplin Explorer: loadTagNotes error",e)}else if("locateFolder"===o.name)try{R(o.folderId),await A(),await joplin.views.panels.postMessage(t,{name:"exitSearchAndLocate",folderId:o.folderId})}catch(e){console.error("Joplin Explorer: locateFolder error",e)}else if("locatePinnedFolder"===o.name)try{R(o.folderId),await A(),await joplin.views.panels.postMessage(t,{name:"scrollToFolder",folderId:o.folderId})}catch(e){console.error("Joplin Explorer: locatePinnedFolder error",e)}else if("reorderPinned"===o.name)try{const e=o.dragId,t=o.targetId,n=o.position,i=k.findIndex(t=>t.id===e);if(i<0)return;const a=k[i];k.splice(i,1);let s=k.findIndex(e=>e.id===t);s<0?k.push(a):("after"===n&&s++,k.splice(s,0,a)),await M(),await A()}catch(e){console.error("Joplin Explorer: reorderPinned error",e)}else if("togglePinnedCollapse"===o.name)S=!S;else if("cycleSort"===o.name){const e=["updated_desc","updated_asc","title_asc","title_desc","manual"],t=e.indexOf(b);b=e[(t+1)%e.length];try{await joplin.settings.setValue("noteSortMode",b)}catch(e){}await A()}else if("sync"===o.name)try{await joplin.commands.execute("synchronize")}catch(o){console.error("Joplin Explorer: sync command failed",o),await joplin.views.panels.postMessage(t,{name:"syncState",state:"error"});const n=o&&o.message?String(o.message):String(o);await y(e.syncFailed,n)}else if("contextMenu"===o.name)await async function(o){const n=o.action,i=o.id,a=o.itemType;try{if("folder"===a)switch(n){case"newNote":{const t=await joplin.data.post(["notes"],null,{title:e.newNote,parent_id:i});await joplin.commands.execute("openNote",t.id),N=t.id,R(i);break}case"newTodo":{const t=await joplin.data.post(["notes"],null,{title:e.newTodo,parent_id:i,is_todo:1});await joplin.commands.execute("openNote",t.id),N=t.id,R(i);break}case"newSubNotebook":{const t=await x(e.newNotebook,"");if(t&&t.trim()){const e=await joplin.data.post(["folders"],null,{title:t.trim(),parent_id:i});delete h[i],delete h[e.id]}break}case"deleteFolder":{const t=await joplin.data.get(["folders",i],{fields:["title"]});await r(e.confirmDeleteFolder+"\n\n"+t.title)&&await joplin.data.delete(["folders",i]);break}case"renameFolder":{const t=await joplin.data.get(["folders",i],{fields:["title"]}),o=await x(e.promptRename,t.title);o&&o.trim()&&await joplin.data.put(["folders",i],null,{title:o.trim()});break}case"exportFolder":try{await joplin.commands.execute("exportFolders",[i])}catch(e){}break;case"pinFolder":k.some(e=>e.id===i)||(k.push({id:i,type:"folder"}),await M());break;case"unpinFolder":k=k.filter(e=>e.id!==i),await M()}else if("note"===a)switch(n){case"openNote":await joplin.commands.execute("openNote",i),N=i;break;case"openInNewWindow":try{await joplin.commands.execute("openNoteInNewWindow",i)}catch(e){await joplin.commands.execute("openNote",i)}break;case"copyLink":{const e=await joplin.data.get(["notes",i],{fields:["id","title"]}),o="["+e.title+"](:/"+e.id+")";try{await joplin.clipboard.writeText(o)}catch(e){await joplin.views.panels.postMessage(t,{name:"copyText",text:o})}break}case"duplicateNote":{const e=await joplin.data.get(["notes",i],{fields:["title","body","parent_id","is_todo"]}),t=await joplin.data.post(["notes"],null,{title:e.title+" (copy)",body:e.body,parent_id:e.parent_id,is_todo:e.is_todo});await joplin.commands.execute("openNote",t.id),N=t.id;break}case"switchNoteType":{const e=await joplin.data.get(["notes",i],{fields:["is_todo"]});await joplin.data.put(["notes",i],null,{is_todo:e.is_todo?0:1});break}case"toggleTodo":{const e=await joplin.data.get(["notes",i],{fields:["is_todo","todo_completed"]});e.is_todo&&await joplin.data.put(["notes",i],null,{todo_completed:e.todo_completed?0:Date.now()});break}case"renameNote":{const t=await joplin.data.get(["notes",i],{fields:["title"]}),o=await x(e.promptRename,t.title);o&&o.trim()&&await joplin.data.put(["notes",i],null,{title:o.trim()});break}case"moveNote":if(o.targetFolderName){let e=null;for(const t of _)if(t.title===o.targetFolderName){e=t;break}e&&await joplin.data.put(["notes",i],null,{parent_id:e.id})}break;case"noteInfo":{const t=await joplin.data.get(["notes",i],{fields:["id","title","created_time","updated_time","is_todo","parent_id","body"]}),o=v[t.parent_id]?v[t.parent_id].title:"",n=(t.body||"").length,a="ID: "+t.id+"\n"+(e.ctxRenameNote||"Title")+": "+t.title+"\n"+(e.newNotebook||"Notebook")+": "+o+"\n"+(e.sortUpdatedDesc?e.sortUpdatedDesc.replace(/[↓↑\u2193\u2191]\s*/,""):"Created")+": "+new Date(t.created_time).toLocaleString()+"\n"+(e.sortUpdatedAsc?e.sortUpdatedAsc.replace(/[↓↑\u2193\u2191]\s*/,""):"Updated")+": "+new Date(t.updated_time).toLocaleString()+"\nType: "+(t.is_todo?"To-do":"Note")+"\nSize: "+n+" chars";await y(t.title,a);break}case"deleteNote":{const t=await joplin.data.get(["notes",i],{fields:["title"]});await r(e.confirmDeleteNote+"\n\n"+t.title)&&await joplin.data.delete(["notes",i]);break}case"pinNote":k.some(e=>e.id===i)||(k.push({id:i,type:"note"}),await M());break;case"unpinNote":k=k.filter(e=>e.id!==i),await M()}await A()}catch(e){console.error("Notes In List: context menu error",e)}}(o);else if("dragDrop"===o.name)await async function(e){try{const t=e.dragId,o=e.dragType,n=e.targetId,i=e.position;if("note"===o)if(v[n])await joplin.data.put(["notes",t],null,{parent_id:n});else{const e=await joplin.data.get(["notes",n],{fields:["parent_id"]});"manual"!==b||"above"!==i&&"below"!==i?await joplin.data.put(["notes",t],null,{parent_id:e.parent_id}):await async function(e,t,o){const n=(await joplin.data.get(["notes",t],{fields:["parent_id"]})).parent_id,i=j.filter(t=>t.parent_id===n&&t.id!==e).sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(t.user_updated_time||0)-(e.user_updated_time||0)}),a=i.findIndex(e=>e.id===t),s=a<0?i.length:"above"===o?a:a+1,l=s>0?i[s-1]:null,r=s<i.length?i[s]:null,d=l?l.order||0:null,c=r?r.order||0:null,p=1e6;if(i.every(e=>0===(e.order||0))||null!==d&&null!==c&&d-c<2){const t=Date.now(),o=i.slice();o.splice(s,0,null);let a=t;const l=[];for(let e=0;e<o.length;e++){const n=t-e*p,i=o[e];null===i?a=n:l.push(joplin.data.put(["notes",i.id],null,{order:n}))}return await Promise.all(l),void await joplin.data.put(["notes",e],null,{parent_id:n,order:a})}let u;u=null!==d&&null!==c?(d+c)/2:null!==d?d-p:null!==c?c+p:Date.now(),await joplin.data.put(["notes",e],null,{parent_id:n,order:u})}(t,n,i)}else if("folder"===o){const e=!!v[n];"into"===i?e&&t!==n&&await joplin.data.put(["folders",t],null,{parent_id:n}):!e||"above"!==i&&"below"!==i||await async function(e,t,o){const n=v[t],i=v[e];if(!n||!i||e===t)return;const a=n.parent_id||"";let s=a;for(;s;){if(s===e)return;s=v[s]&&v[s].parent_id||""}const l=_.filter(t=>(t.parent_id||"")===a&&t.id!==e).sort((e,t)=>{const o=e.order||0,n=t.order||0;return o!==n?n-o:(e.title||"").localeCompare(t.title||"")}),r=l.findIndex(e=>e.id===t),d=r<0?l.length:"above"===o?r:r+1,c=d>0?l[d-1]:null,p=d<l.length?l[d]:null,u=c?c.order||0:null,w=p?p.order||0:null,f=l.every(e=>0===(e.order||0)),m=null!==u&&null!==w&&u-w<2,g=1e6;if((i.parent_id||"")!==a&&await joplin.data.put(["folders",e],null,{parent_id:a}),f||m){const t=Date.now(),o=l.slice();o.splice(d,0,null);for(let n=0;n<o.length;n++){const i=t-n*g,a=o[n];null===a?T[e]=i:T[a.id]=i}return void await E()}let y;y=null!==u&&null!==w?(u+w)/2:null!==u?u-g:null!==w?w+g:Date.now(),T[e]=y,await E()}(t,n,i)}await A()}catch(e){console.error("Notes In List: drag drop error",e)}}(o);else if("dragToEmpty"===o.name)try{const t=o.dragId,n=o.dragType,i=await x(e.promptNewNotebookName,"");if(!i||!i.trim())return;const a=await joplin.data.post(["folders"],null,{title:i.trim()});"note"===n?await joplin.data.put(["notes",t],null,{parent_id:a.id}):"folder"===n&&t!==a.id&&await joplin.data.put(["folders",t],null,{parent_id:a.id}),await A()}catch(e){console.error("Notes In List: drag to empty error",e)}}),await joplin.workspace.onNoteSelectionChange(async()=>{const e=await joplin.workspace.selectedNote();e&&e.id!==N&&(N=e.id,await joplin.views.panels.postMessage(t,{name:"selectNote",id:e.id}))}),await joplin.workspace.onNoteChange(async e=>{var t;e&&e.id?(t=e.id,C[t]=!0,O&&clearTimeout(O),O=setTimeout(async()=>{O=null;const e=Object.keys(C);C={};for(const t of e)await U(t)},600)):function(e=600){F&&clearTimeout(F),F=setTimeout(async()=>{F=null,await A()},e)}()});try{await joplin.workspace.onSyncStart(async()=>{await joplin.views.panels.postMessage(t,{name:"syncState",state:"syncing"})})}catch(e){console.warn("Joplin Explorer: onSyncStart not available",e)}try{await joplin.workspace.onSyncComplete(async o=>{const n=!(!o||!o.withErrors);await A(),await joplin.views.panels.postMessage(t,{name:"syncState",state:n?"error":"done"}),n&&await y(e.syncFailed,"Joplin reported errors during synchronisation. Open the Synchronisation Status screen (Tools → Synchronisation Status) to see the details.")})}catch(e){console.warn("Joplin Explorer: onSyncComplete not available",e)}await A()}})})();
|
package/publish/manifest.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"manifest_version": 1,
|
|
3
|
-
"id": "com.github.joplin-explorer",
|
|
4
|
-
"app_min_version": "2.6.0",
|
|
5
|
-
"version": "1.3.
|
|
6
|
-
"name": "Joplin Explorer",
|
|
7
|
-
"description": "A unified sidebar that displays notebooks and notes together in a single tree view",
|
|
8
|
-
"author": "lim0513",
|
|
9
|
-
"homepage_url": "https://github.com/lim0513/joplin-explorer",
|
|
10
|
-
"repository_url": "https://github.com/lim0513/joplin-explorer",
|
|
11
|
-
"keywords": ["sidebar", "explorer", "tree-view", "notebooks", "notes"],
|
|
12
|
-
"categories": ["appearance", "productivity"]
|
|
13
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 1,
|
|
3
|
+
"id": "com.github.joplin-explorer",
|
|
4
|
+
"app_min_version": "2.6.0",
|
|
5
|
+
"version": "1.3.3",
|
|
6
|
+
"name": "Joplin Explorer",
|
|
7
|
+
"description": "A unified sidebar that displays notebooks and notes together in a single tree view",
|
|
8
|
+
"author": "lim0513",
|
|
9
|
+
"homepage_url": "https://github.com/lim0513/joplin-explorer",
|
|
10
|
+
"repository_url": "https://github.com/lim0513/joplin-explorer",
|
|
11
|
+
"keywords": ["sidebar", "explorer", "tree-view", "notebooks", "notes"],
|
|
12
|
+
"categories": ["appearance", "productivity"]
|
|
13
|
+
}
|
package/publish/plugin.jpl
CHANGED
|
Binary file
|