From 79d940d57539d47c3492341579584d74f3aafebb Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 8 Apr 2024 09:25:19 +0800 Subject: [PATCH 1/5] :art: Database primary key supports unbinding block https://github.com/siyuan-note/siyuan/issues/10849 --- kernel/model/attribute_view.go | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 791347376..f31f4c3bb 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -2039,23 +2039,29 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string, return } - // 不允许重复添加相同的块到属性视图中 + var content string + if !isDetached { + content = getNodeRefText(node) + } + + now := time.Now().UnixMilli() + + // 检查是否重复添加相同的块 blockValues := attrView.GetBlockKeyValues() for _, blockValue := range blockValues.Values { if blockValue.Block.ID == addingBlockID { if !isDetached { - // 重复绑定一下,比如剪切数据库块的场景需要 - bindBlockAv0(tx, avID, blockID, node, tree) + // 重复绑定一下,比如剪切数据库块、取消绑定块后再次添加的场景需要 + bindBlockAv0(tx, avID, node, tree) + blockValue.IsDetached = isDetached + blockValue.Block.Content = content + blockValue.UpdatedAt = now + err = av.SaveAttributeView(attrView) } return } } - var content string - if !isDetached { - content = getNodeRefText(node) - } - now := time.Now().UnixMilli() blockValue := &av.Value{ ID: ast.NewNodeID(), KeyID: blockValues.Key.ID, @@ -2148,7 +2154,7 @@ func addAttributeViewBlock(avID, blockID, previousBlockID, addingBlockID string, } if !isDetached { - bindBlockAv0(tx, avID, blockID, node, tree) + bindBlockAv0(tx, avID, node, tree) } for _, v := range attrView.Views { @@ -3069,6 +3075,11 @@ func unbindBlockAv(tx *Transaction, avID, blockID string) { node.SetIALAttr(av.NodeAttrNameAvs, strings.Join(avIDs, ",")) } + avNames := getAvNames(attrs[av.NodeAttrNameAvs]) + if "" != avNames { + attrs[av.NodeAttrViewNames] = avNames + } + if nil != tx { err = setNodeAttrsWithTx(tx, node, tree, attrs) } else { @@ -3087,11 +3098,11 @@ func bindBlockAv(tx *Transaction, avID, blockID string) { return } - bindBlockAv0(tx, avID, blockID, node, tree) + bindBlockAv0(tx, avID, node, tree) return } -func bindBlockAv0(tx *Transaction, avID, blockID string, node *ast.Node, tree *parse.Tree) { +func bindBlockAv0(tx *Transaction, avID string, node *ast.Node, tree *parse.Tree) { attrs := parse.IAL2Map(node.KramdownIAL) if "" == attrs[av.NodeAttrNameAvs] { attrs[av.NodeAttrNameAvs] = avID @@ -3114,7 +3125,7 @@ func bindBlockAv0(tx *Transaction, avID, blockID string, node *ast.Node, tree *p err = setNodeAttrs(node, tree, attrs) } if nil != err { - logging.LogWarnf("set node [%s] attrs failed: %s", blockID, err) + logging.LogWarnf("set node [%s] attrs failed: %s", node.ID, err) return } return From 2ed0721607c2284a70a439d3d6ad2a806775a09d Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 8 Apr 2024 09:48:54 +0800 Subject: [PATCH 2/5] :art: Updated README --- README.md | 5 +++-- README_zh_CN.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ba836cc6b..bf18ebbf7 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ Most features are free, even for commercial use. * Markdown WYSIWYG * List outline * Block zoom-in - * Block horizontal layout * Million-word large document editing * Mathematical formulas, charts, flowcharts, Gantt charts, timing charts, staffs, etc. * Web clipping @@ -64,7 +63,9 @@ Most features are free, even for commercial use. * Copy to WeChat MP, Zhihu and Yuque * Database * Table view -* Spaced repetition +* Flashcard spaced repetition +* AI writing and q/a chat via OpenAI API +* Tesseract OCR * Multi-tab, drag and drop to split screen * Template snippet * JavaScript/CSS snippet diff --git a/README_zh_CN.md b/README_zh_CN.md index 6261e87ac..21de9c956 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -53,7 +53,6 @@ * Markdown 所见即所得 * 列表大纲 * 块缩放聚焦 - * 块横向排版 * 百万字大文档编辑 * 数学公式、图表、流程图、甘特图、时序图、五线谱等 * 网页剪藏 @@ -65,7 +64,9 @@ * 复制到微信公众号、知乎和语雀 * 数据库 * 表格视图 -* 间隔重复 +* 闪卡间隔重复 +* 接入 OpenAI 接口支持人工智能写作和问答聊天 +* Tesseract OCR * 模板片段 * JavaScript/CSS 代码片段 * Android/iOS APP From ef48ca11092b42be5a4f68c8f9c87c4029da56d8 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 8 Apr 2024 09:49:52 +0800 Subject: [PATCH 3/5] :art: Updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf18ebbf7..e3c3736f5 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Most features are free, even for commercial use. * Database * Table view * Flashcard spaced repetition -* AI writing and q/a chat via OpenAI API +* AI writing and Q/A chat via OpenAI API * Tesseract OCR * Multi-tab, drag and drop to split screen * Template snippet From 8f566f251ca73ee088639a4ef6365226133f372e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 8 Apr 2024 09:50:48 +0800 Subject: [PATCH 4/5] :art: Updated README --- README.md | 22 +++++++++++----------- README_zh_CN.md | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e3c3736f5..65496e4f7 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Most features are free, even for commercial use. * Multi-tab, drag and drop to split screen * Template snippet * JavaScript/CSS snippet -* Android/iOS APP +* Android/iOS App * Docker deployment * [API](https://github.com/siyuan-note/siyuan/blob/master/API.md) * Community marketplace @@ -80,16 +80,16 @@ Some features are only available to paid members, for more details please refer ![SiYuan Arch](https://b3logfile.com/file/2023/05/SiYuan_Arch-Sgu8vXT.png "SiYuan Arch") -| Project | Description | Forks | Stars | -|----------------------------------------------------------|-------------------------|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------------| -| [lute](https://github.com/88250/lute) | Editor engine | ![GitHub forks](https://img.shields.io/github/forks/88250/lute) | ![GitHub Repo stars](https://img.shields.io/github/stars/88250/lute) | -| [chrome](https://github.com/siyuan-note/siyuan-chrome) | Chrome/Edge extension | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-chrome) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-chrome) | -| [bazaar](https://github.com/siyuan-note/bazaar) | Community marketplace | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/bazaar) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/bazaar) | -| [dejavu](https://github.com/siyuan-note/dejavu) | Data repo | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/dejavu) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/dejavu) | -| [petal](https://github.com/siyuan-note/petal) | Plugin API | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/petal) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/petal) | -| [android](https://github.com/siyuan-note/siyuan-android) | Android APP | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-android) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-android) | -| [ios](https://github.com/siyuan-note/siyuan-ios) | iOS APP | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-ios) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-ios) | -| [riff](https://github.com/siyuan-note/riff) | Spaced repetition | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/riff) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/riff) | +| Project | Description | Forks | Stars | +|----------------------------------------------------------|-----------------------|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------------| +| [lute](https://github.com/88250/lute) | Editor engine | ![GitHub forks](https://img.shields.io/github/forks/88250/lute) | ![GitHub Repo stars](https://img.shields.io/github/stars/88250/lute) | +| [chrome](https://github.com/siyuan-note/siyuan-chrome) | Chrome/Edge extension | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-chrome) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-chrome) | +| [bazaar](https://github.com/siyuan-note/bazaar) | Community marketplace | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/bazaar) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/bazaar) | +| [dejavu](https://github.com/siyuan-note/dejavu) | Data repo | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/dejavu) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/dejavu) | +| [petal](https://github.com/siyuan-note/petal) | Plugin API | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/petal) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/petal) | +| [android](https://github.com/siyuan-note/siyuan-android) | Android App | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-android) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-android) | +| [ios](https://github.com/siyuan-note/siyuan-ios) | iOS App | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-ios) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-ios) | +| [riff](https://github.com/siyuan-note/riff) | Spaced repetition | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/riff) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/riff) | ## 🌟 Star History diff --git a/README_zh_CN.md b/README_zh_CN.md index 21de9c956..dae3d2b70 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -69,7 +69,7 @@ * Tesseract OCR * 模板片段 * JavaScript/CSS 代码片段 -* Android/iOS APP +* Android/iOS App * Docker 部署 * [API](API_zh_CN.md) * 社区集市 @@ -87,8 +87,8 @@ | [bazaar](https://github.com/siyuan-note/bazaar) | 社区集市 | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/bazaar) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/bazaar) | | [dejavu](https://github.com/siyuan-note/dejavu) | 数据仓库 | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/dejavu) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/dejavu) | | [petal](https://github.com/siyuan-note/petal) | 插件 API | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/petal) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/petal) | -| [android](https://github.com/siyuan-note/siyuan-android) | Android APP | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-android) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-android) | -| [ios](https://github.com/siyuan-note/siyuan-ios) | iOS APP | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-ios) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-ios) | +| [android](https://github.com/siyuan-note/siyuan-android) | Android App | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-android) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-android) | +| [ios](https://github.com/siyuan-note/siyuan-ios) | iOS App | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/siyuan-ios) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/siyuan-ios) | | [riff](https://github.com/siyuan-note/riff) | 间隔重复 | ![GitHub forks](https://img.shields.io/github/forks/siyuan-note/riff) | ![GitHub Repo stars](https://img.shields.io/github/stars/siyuan-note/riff) | ## 🌟 Star History From de0b64f8caae71ca323a7896e1d685eb47d03735 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 8 Apr 2024 10:49:47 +0800 Subject: [PATCH 5/5] :art: https://github.com/siyuan-note/siyuan/issues/10884 --- kernel/model/transaction.go | 7 ++++++- kernel/util/websocket.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 0d258f42a..0bdd1f45d 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -1312,10 +1312,15 @@ func (tx *Transaction) commit() (err error) { if err = writeJSONQueue(tree); nil != err { return } + + var sources []interface{} + for _, op := range tx.DoOperations { + sources = append(sources, op.Action) + } + util.PushSaveDoc(tree.ID, "tx", sources) } refreshDynamicRefTexts(tx.nodes, tx.trees) IncSync() - tx.trees = nil tx.state.Store(2) tx.m.Unlock() return diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index 8643b776e..9cae9cd4c 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -220,6 +220,15 @@ func PushReloadDoc(rootID string) { BroadcastByType("main", "reloaddoc", 0, "", rootID) } +func PushSaveDoc(rootID, typ string, sources interface{}) { + data := map[string]interface{}{ + "rootID": rootID, + "type": typ, + "sources": sources, + } + BroadcastByType("main", "savedoc", 0, "", data) +} + func PushProtyleReload(rootID string) { BroadcastByType("protyle", "reload", 0, "", rootID) }