Skip to content

Commit

Permalink
✨ feat: 能为文档树右键菜单提供“子文档/文档树”文档流功能吗? close #30
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Mar 31, 2024
1 parent b0ebe75 commit 49a079f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- 修复设置面板样式错误
- 「显示文档树」的规则改为深度优先顺序 [#53](https://github.com/frostime/sy-docs-flow/issues/53)
- 文档块菜单添加按钮,通过文档流打开文档的反链 [#34](https://github.com/frostime/sy-docs-flow/issues/34)
- 文档块菜单添加按钮,通过文档流打开文档的子文裆/文档树 [#30](https://github.com/frostime/sy-docs-flow/issues/30)


## v0.4.3
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ After enabling the plugin, click the icon in the top bar and select the desired

1. Clicking on a menu of an SQL embedd block, open the SQL query in the document flow.

2. Clicking on a document block menu, open the backlinks of the document in the document flow.
2. Clicking on a document block menu, open these in a document flow:

- The backlinks of the document
- The child document
- The offspring document

## Inside the document stream

Expand Down
6 changes: 5 additions & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@

1. 点击一个 SQL 嵌入块的菜单,可以将 SQL 代码在文档流中打开

2. 点击一个文档块菜单,可以将文档的反链在文档流中打开
2. 点击一个文档块菜单,可以在文档流中打开

- 文档的反链
- 文档的子文裆
- 文档下属的文档树

## 文档流内

Expand Down
1 change: 1 addition & 0 deletions src/i18n/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- 修复设置面板样式错误
- 「显示文档树」的规则改为深度优先顺序 [#53](https://github.com/frostime/sy-docs-flow/issues/53)
- 文档块菜单添加按钮,通过文档流打开文档的反链 [#34](https://github.com/frostime/sy-docs-flow/issues/34)
- 文档块菜单添加按钮,通过文档流打开文档的子文裆/文档树 [#30](https://github.com/frostime/sy-docs-flow/issues/30)

---

Expand Down
6 changes: 3 additions & 3 deletions src/i18n/en_US.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "Document flow",
"name": "Docflow",
"rules": {
"child": "Child document",
"docBacklinks": "Document backlinks",
"docBackmentions": "Document mentions",
"sql": "SQL query",
"customID": "Custom ID",
"offspringDocument": "Offspring Document"
"offspringDocument": "Offspring document"
},
"button": {
"alterSaved": "Alter these",
"saved": "Saved rules",
"openInDocFlow": "Open in docflow",
"openBackInDocFlow": "Open backlinks in docflow",
"openBackInDocFlow": "Docflow-Backlinks",
"moreConfig": "More"
},
"msg": {
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"alterSaved": "更改上述规则",
"saved": "已保存的规则",
"openInDocFlow": "文档流中打开",
"openBackInDocFlow": "文档流中打开反链",
"openBackInDocFlow": "文档流-反链",
"moreConfig": "更多配置"
},
"msg": {
Expand Down
17 changes: 16 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,26 @@ export default class DocsFlowPlugin extends Plugin {

this.eventBus.on("click-blockicon", this.onGutterClicked.bind(this));
this.eventBus.on("click-editortitleicon", ({ detail }) => {
const rootID = detail.data.rootID;
detail.menu.addItem({
icon: "iconFlow",
label: `${i18n.name}-${i18n.rules.child}`,
click: () => {
this.tabHub.open(RuleFactory("ChildDocument", rootID));
}
});
detail.menu.addItem({
icon: "iconFlow",
label: `${i18n.name}-${i18n.rules.offspringDocument}`,
click: () => {
this.tabHub.open(RuleFactory("OffspringDocument", rootID));
}
});

if (detail.data.refCount === 0 ) {
return;
}
console.log("click-editortitleicon", detail);

detail.menu.addItem({
icon: "iconFlow",
label: i18n.button.openBackInDocFlow,
Expand Down
48 changes: 23 additions & 25 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author : Yp Z
* @Date : 2023-07-29 15:17:15
* @FilePath : /src/rules.ts
* @LastEditTime : 2024-03-31 21:40:29
* @LastEditTime : 2024-03-31 21:47:04
* @Description :
*/
import { showMessage } from "siyuan";
Expand Down Expand Up @@ -91,21 +91,21 @@ export abstract class MatchRule {
}

class ChildDocument extends MatchRule {
constructor() {
constructor(docId?: DocumentId) {
super("ChildDocument");
this.input = null;
const currentDocument = getActiveTab();

this.hash = `ChildDocument`;

if (!currentDocument) {
return;
if (docId === undefined) {
const currentDocument = getActiveTab();
if (!currentDocument) {
return;
}
const eleTitle = currentDocument.querySelector(".protyle-title");
docId = eleTitle.getAttribute("data-node-id");
}

const eleTitle = currentDocument.querySelector(".protyle-title");
let dataId = eleTitle.getAttribute("data-node-id");
this.input = dataId;
this.hash = `ChildDocument@${dataId}`;
this.input = docId;
this.hash = `ChildDocument@${docId}`;
}

async next() {
Expand All @@ -119,21 +119,19 @@ class ChildDocument extends MatchRule {
}

class OffspringDocument extends MatchRule {
constructor() {
constructor(docId?: DocumentId) {
super("OffspringDocument");
this.input = null;
const currentDocument = getActiveTab();

this.hash = `OffspringDocument`;

if (!currentDocument) {
return;
if (docId === undefined) {
const currentDocument = getActiveTab();
if (!currentDocument) {
return;
}
const eleTitle = currentDocument.querySelector(".protyle-title");
docId = eleTitle.getAttribute("data-node-id");
}

const eleTitle = currentDocument.querySelector(".protyle-title");
let dataId = eleTitle.getAttribute("data-node-id");
this.input = dataId;
this.hash = `OffspringDocument@${dataId}`;
this.input = docId;
this.hash = `OffspringDocument@${docId}`;
this.config.dynamicLoading.enabled = true; //默认开启
}

Expand Down Expand Up @@ -309,9 +307,9 @@ class IdList extends MatchRule {
export const RuleFactory = (type: TRuleType, input?: any) => {
switch (type) {
case "ChildDocument":
return new ChildDocument();
return new ChildDocument(input);
case "OffspringDocument":
return new OffspringDocument();
return new OffspringDocument(input);
case "DocBacklinks":
return new DocBacklinks();
case "DocBackmentions":
Expand Down

0 comments on commit 49a079f

Please sign in to comment.