Merge branch 'siyuan-note:main' into add_per_dev_condition_and_so_on

This commit is contained in:
n0trealtricktre 2024-03-28 16:25:27 +08:00 committed by GitHub
commit 8e97e886b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 161 additions and 15 deletions

View file

@ -1,6 +1,24 @@
# Changelog # Changelog
## 0.3.2 2024-01 ## 0.3.5 2024-03
## 0.3.4 2024-02-20
* [Add plugin event bus `click-flashcard-action`](https://github.com/siyuan-note/siyuan/issues/10318)
## 0.3.3 2024-01-24
* Update dock icon class
## 0.3.2 2024-01-09
* [Add plugin `protyleOptions`](https://github.com/siyuan-note/siyuan/issues/10090)
* [Add plugin api `uninstall`](https://github.com/siyuan-note/siyuan/issues/10063)
* [Add plugin method `updateCards`](https://github.com/siyuan-note/siyuan/issues/10065)
* [Add plugin function `lockScreen`](https://github.com/siyuan-note/siyuan/issues/10063)
* [Add plugin event bus `lock-screen`](https://github.com/siyuan-note/siyuan/pull/9967)
* [Add plugin event bus `open-menu-inbox`](https://github.com/siyuan-note/siyuan/pull/9967)
## 0.3.1 2023-12-06 ## 0.3.1 2023-12-06

View file

@ -3,7 +3,7 @@
[中文版](./README_zh_CN.md) [中文版](./README_zh_CN.md)
> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.2](https://github.com/siyuan-note/plugin-sample/tree/v0.3.2) > Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.4](https://github.com/siyuan-note/plugin-sample/tree/v0.3.4)
@ -233,3 +233,56 @@ If you insist on removing all svelte dependencies so that they do not pollute yo
- Line 20: `svelte(),` - Line 20: `svelte(),`
4. delete line 37 of `tsconfig.json` from `"svelte"` 5. 4. delete line 37 of `tsconfig.json` from `"svelte"` 5.
5. re-run `pnpm i` 5. re-run `pnpm i`
## Developer's Guide
Developers of SiYuan need to pay attention to the following specifications.
### 1. File Reading and Writing Specifications
If plugins or external extensions require direct reading or writing of files under the `data` directory, please use the kernel API to achieve this. **Do not call `fs` or other electron or nodejs APIs directly**, as it may result in data loss during synchronization and cause damage to cloud data.
Related APIs can be found at: `/api/file/*` (e.g., `/api/file/getFile`).
### 2. Daily Note Attribute Specifications
When creating a diary in SiYuan, a custom-dailynote-yyyymmdd attribute will be automatically added to the document to distinguish it from regular documents.
> For more details, please refer to [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807).
Developers should pay attention to the following when developing the functionality to manually create Daily Notes:
- If `/api/filetree/createDailyNote` is called to create a diary, the attribute will be automatically added to the document, and developers do not need to handle it separately.
- If a document is created manually by developer's code (e.g., using the `createDocWithMd` API to create a diary), please manually add this attribute to the document.
Here is a reference code:
```ts
/*
* Copyright (c) 2023 by frostime. All Rights Reserved.
* @Author : frostime
* @Url : https://github.com/frostime/siyuan-dailynote-today/blob/v1.3.0/src/func/dailynote/dn-attr.ts
*/
export function formatDate(date?: Date, sep=''): string {
date = date === undefined ? new Date() : date;
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
return `${year}${sep}${month < 10 ? '0' + month : month}${sep}${day < 10 ? '0' + day : day}`;
}
/**
* Set custom attribute: `custom-dailynote-yyyyMMdd`: yyyyMMdd
* https://github.com/siyuan-note/siyuan/issues/9807
* @param doc_id Id of daily note
*/
export function setCustomDNAttr(doc_id: string, date?: Date) {
let td = formatDate(date);
let attr = `custom-dailynote-${td}`;
// 构建 attr: td
let attrs: { [key: string]: string } = {};
attrs[attr] = td;
serverApi.setBlockAttrs(doc_id, attrs);
}
```

View file

@ -4,7 +4,7 @@
[English](./README.md) [English](./README.md)
> 本例同 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.2](https://github.com/siyuan-note/plugin-sample/tree/v0.3.2) > 本例同 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.4](https://github.com/siyuan-note/plugin-sample/tree/v0.3.4)
1. 使用 vite 打包 1. 使用 vite 打包
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发 2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
@ -224,3 +224,57 @@ PR 社区集市仓库。
- 第二十行: `svelte(),` - 第二十行: `svelte(),`
4. 删掉 `tsconfig.json` 中 37 行 `"svelte"` 4. 删掉 `tsconfig.json` 中 37 行 `"svelte"`
5. 重新执行 `pnpm i` 5. 重新执行 `pnpm i`
## 开发者须知
思源开发者需注意以下规范。
### 1. 读写文件规范
插件或者外部扩展如果有直接读取或者写入 data 下文件的需求,请通过调用内核 API 来实现,**不要自行调用 `fs` 或者其他 electron、nodejs API**,否则可能会导致数据同步时分块丢失,造成云端数据损坏。
相关 API 见: `/api/file/*`(例如 `/api/file/getFile` 等)。
### 2. Daily Note 属性规范
思源在创建日记的时候会自动为文档添加 custom-dailynote-yyyymmdd 属性, 以方便将日记文档同普通文档区分。
> 详情请见 [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807)。
开发者在开发手动创建 Daily Note 的功能时请注意:
- 如果调用了 `/api/filetree/createDailyNote` 创建日记,那么文档会自动添加这个属性,无需开发者特别处理。
- 如果是开发者代码手动创建文档(例如使用 `createDocWithMd` API 创建日记),请手动为文档添加该属性。
参考代码:
```ts
/*
* Copyright (c) 2023 by frostime. All Rights Reserved.
* @Author : frostime
* @Url : https://github.com/frostime/siyuan-dailynote-today/blob/v1.3.0/src/func/dailynote/dn-attr.ts
*/
export function formatDate(date?: Date, sep=''): string {
date = date === undefined ? new Date() : date;
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
return `${year}${sep}${month < 10 ? '0' + month : month}${sep}${day < 10 ? '0' + day : day}`;
}
/**
* Set custom attribute: `custom-dailynote-yyyyMMdd`: yyyyMMdd
* https://github.com/siyuan-note/siyuan/issues/9807
* @param doc_id Id of daily note
*/
export function setCustomDNAttr(doc_id: string, date?: Date) {
let td = formatDate(date);
let attr = `custom-dailynote-${td}`;
// 构建 attr: td
let attrs: { [key: string]: string } = {};
attrs[attr] = td;
serverApi.setBlockAttrs(doc_id, attrs);
}
```

View file

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before After
Before After

View file

@ -13,20 +13,20 @@
"build": "vite build" "build": "vite build"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.0.3", "@sveltejs/vite-plugin-svelte": "^2.4.1",
"@tsconfig/svelte": "^4.0.1", "@tsconfig/svelte": "^4.0.1",
"@types/node": "^20.2.0", "@types/node": "^20.3.0",
"eslint": "^8.42.0", "eslint": "^8.42.0",
"fast-glob": "^3.2.12", "fast-glob": "^3.2.12",
"glob": "^7.2.3", "glob": "^7.2.3",
"minimist": "^1.2.8", "minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5", "rollup-plugin-livereload": "^2.0.5",
"sass": "^1.62.1", "sass": "^1.63.3",
"siyuan": "0.9.2", "siyuan": "0.9.4",
"svelte": "^3.57.0", "svelte": "^3.59.1",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^5.0.4", "typescript": "^5.1.3",
"vite": "^4.3.7", "vite": "^4.5.2",
"vite-plugin-static-copy": "^0.15.0", "vite-plugin-static-copy": "^0.15.0",
"vite-plugin-zip-pack": "^1.0.5" "vite-plugin-zip-pack": "^1.0.5"
} }

View file

@ -2,8 +2,8 @@
"name": "plugin-sample-vite-svelte", "name": "plugin-sample-vite-svelte",
"author": "frostime", "author": "frostime",
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte", "url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
"version": "0.3.2", "version": "0.3.4",
"minAppVersion": "2.12.1", "minAppVersion": "3.0.0",
"backends": [ "backends": [
"windows", "windows",
"linux", "linux",

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

View file

@ -120,6 +120,7 @@ export default class PluginSample extends Plugin {
size: { width: 200, height: 0 }, size: { width: 200, height: 0 },
icon: "iconSaving", icon: "iconSaving",
title: "Custom Dock", title: "Custom Dock",
hotkey: "⌥⌘W",
}, },
data: { data: {
text: "This is my custom dock" text: "This is my custom dock"
@ -145,11 +146,11 @@ export default class PluginSample extends Plugin {
dock.element.innerHTML = `<div class="fn__flex-1 fn__flex-column"> dock.element.innerHTML = `<div class="fn__flex-1 fn__flex-column">
<div class="block__icons"> <div class="block__icons">
<div class="block__logo"> <div class="block__logo">
<svg><use xlink:href="#iconEmoji"></use></svg> <svg class="block__logoicon"><use xlink:href="#iconEmoji"></use></svg>
Custom Dock Custom Dock
</div> </div>
<span class="fn__flex-1 fn__space"></span> <span class="fn__flex-1 fn__space"></span>
<span data-type="min" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="Min ${adaptHotkey("W")}"><svg><use xlink:href="#iconMin"></use></svg></span> <span data-type="min" class="block__icon b3-tooltips b3-tooltips__sw" aria-label="Min ${adaptHotkey("W")}"><svg class="block__logoicon"><use xlink:href="#iconMin"></use></svg></span>
</div> </div>
<div class="fn__flex-1 plugin-sample__custom-dock"> <div class="fn__flex-1 plugin-sample__custom-dock">
${dock.data.text} ${dock.data.text}
@ -655,6 +656,18 @@ export default class PluginSample extends Plugin {
click: () => { click: () => {
this.eventBus.off("click-editortitleicon", this.eventBusLog); this.eventBus.off("click-editortitleicon", this.eventBusLog);
} }
}, {
icon: "iconSelect",
label: "On click-flashcard-action",
click: () => {
this.eventBus.on("click-flashcard-action", this.eventBusLog);
}
}, {
icon: "iconClose",
label: "Off click-flashcard-action",
click: () => {
this.eventBus.off("click-flashcard-action", this.eventBusLog);
}
}, { }, {
icon: "iconSelect", icon: "iconSelect",
label: "On open-noneditableblock", label: "On open-noneditableblock",

View file

@ -34,6 +34,14 @@ export default defineConfig({
{ {
src: "./plugin.json", src: "./plugin.json",
dest: "./", dest: "./",
},
{
src: "./preview.png",
dest: "./",
},
{
src: "./icon.png",
dest: "./",
} }
], ],
}), }),
@ -79,7 +87,7 @@ export default defineConfig({
name: 'watch-external', name: 'watch-external',
async buildStart() { async buildStart() {
const files = await fg([ const files = await fg([
'public/**', 'public/i18n/**',
'./README*.md', './README*.md',
'./plugin.json' './plugin.json'
]); ]);