mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 00:50:56 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
bb4419d65f
2
app/stage/protyle/js/lute/lute.min.js
vendored
2
app/stage/protyle/js/lute/lute.min.js
vendored
File diff suppressed because one or more lines are too long
39
kernel/api/av.go
Normal file
39
kernel/api/av.go
Normal file
@ -0,0 +1,39 @@
|
||||
// SiYuan - Build Your Eternal Digital Garden
|
||||
// Copyright (c) 2020-present, b3log.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func renderAttributeView(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
ret.Data = model.RenderAttributeView(id)
|
||||
}
|
@ -325,4 +325,6 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
ginServer.Handle("POST", "/api/snippet/setSnippet", model.CheckAuth, setSnippet)
|
||||
ginServer.Handle("POST", "/api/snippet/removeSnippet", model.CheckAuth, removeSnippet)
|
||||
ginServer.Handle("GET", "/snippets/*filepath", serveSnippets)
|
||||
|
||||
ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView)
|
||||
}
|
||||
|
@ -17,13 +17,6 @@
|
||||
package av
|
||||
|
||||
type Cell struct {
|
||||
ID string `json:"id"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
type CellBlock struct {
|
||||
*Cell
|
||||
}
|
||||
|
||||
func NewCellBlock(blockID string) *CellBlock {
|
||||
return &CellBlock{&Cell{Value: blockID}}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ require (
|
||||
github.com/88250/clipboard v0.1.5
|
||||
github.com/88250/css v0.1.2
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0
|
||||
github.com/88250/lute v1.7.6-0.20230303043953-04b4d2f358fd
|
||||
github.com/88250/lute v1.7.6-0.20230303060605-b654e00909d4
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
|
||||
github.com/ClarkThan/ahocorasick v0.0.0-20230220142845-f237b6348b3e
|
||||
|
@ -8,12 +8,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5 h1:8HdZozCsXS
|
||||
github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0 h1:hZn2F/kNKcxoK41JhfoTfJ5BYHoWG3fSYk/BlOPYqLo=
|
||||
github.com/88250/gulu v1.2.3-0.20230223100136-26e5f16ac3c0/go.mod h1:pTWnjt+6qUqNnP9xltswsJxgCBVu3C7eW09u48LWX0k=
|
||||
github.com/88250/lute v1.7.6-0.20230302102529-4dd94587d7da h1:HPz4B8anvSVxuJGCKADZ3uYKdDeO6HfHPT0jhHwjHlc=
|
||||
github.com/88250/lute v1.7.6-0.20230302102529-4dd94587d7da/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230303043637-f075ff078228 h1:KE7Z2HgKn1ycRzpEapyowUby0GdLMNzaQy+EM/HCyL8=
|
||||
github.com/88250/lute v1.7.6-0.20230303043637-f075ff078228/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230303043953-04b4d2f358fd h1:6gD0wQUTwXQhWExyCRujk4Mb1gcfEcRg767WidA5JVc=
|
||||
github.com/88250/lute v1.7.6-0.20230303043953-04b4d2f358fd/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/lute v1.7.6-0.20230303060605-b654e00909d4 h1:Iw6OJn6z20P3QNXMmacRKOvOAoQ0m56FYkqN5ldX8Js=
|
||||
github.com/88250/lute v1.7.6-0.20230303060605-b654e00909d4/go.mod h1:+wUqx/1kdFDbWtxn9LYJlaCOAeol2pjSO6w+WJTVQsg=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390 h1:q2AR33VoQ87WYtvZ4pEvwj5gZkv22HK/yMlPWwF1oyc=
|
||||
github.com/88250/pdfcpu v0.3.14-0.20230224021324-e51076eb6390/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
|
||||
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
|
||||
|
@ -28,6 +28,17 @@ import (
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
)
|
||||
|
||||
func RenderAttributeView(avID string) (dom string) {
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
_ = attrView
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr) {
|
||||
firstSrcID := operation.SrcIDs[0]
|
||||
tree, err := tx.loadTree(firstSrcID)
|
||||
@ -38,7 +49,7 @@ func (tx *Transaction) doInsertAttrViewBlock(operation *Operation) (ret *TxErr)
|
||||
|
||||
avID := operation.ParentID
|
||||
for _, id := range operation.SrcIDs {
|
||||
if err = addAttributeViewBlock(id, avID, tree); nil != err {
|
||||
if err = addAttributeViewBlock(id, avID, tree, tx); nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID, msg: err.Error()}
|
||||
}
|
||||
}
|
||||
@ -55,7 +66,7 @@ func (tx *Transaction) doRemoveAttrViewBlock(operation *Operation) (ret *TxErr)
|
||||
|
||||
avID := operation.ParentID
|
||||
for _, id := range operation.SrcIDs {
|
||||
if err = removeAttributeViewBlock(id, avID, tree); nil != err {
|
||||
if err = removeAttributeViewBlock(id, avID, tree, tx); nil != err {
|
||||
return &TxErr{code: TxErrWriteAttributeView, id: avID}
|
||||
}
|
||||
}
|
||||
@ -82,7 +93,7 @@ func AddAttributeViewColumn(name string, typ string, columnIndex int, avID strin
|
||||
return
|
||||
}
|
||||
|
||||
func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
|
||||
func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
@ -105,7 +116,7 @@ func removeAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error
|
||||
return
|
||||
}
|
||||
|
||||
func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
|
||||
func addAttributeViewBlock(blockID, avID string, tree *parse.Tree, tx *Transaction) (err error) {
|
||||
node := treenode.GetNodeInTree(tree, blockID)
|
||||
if nil == node {
|
||||
err = ErrBlockNotFound
|
||||
@ -136,22 +147,22 @@ func addAttributeViewBlock(blockID, avID string, tree *parse.Tree) (err error) {
|
||||
}
|
||||
|
||||
row := av.NewRow()
|
||||
row.Cells = append(row.Cells, &av.Cell{Value: blockID})
|
||||
row.Cells = append(row.Cells, &av.Cell{ID: ast.NewNodeID(), Value: blockID})
|
||||
if 1 < len(attrView.Columns) {
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
// 将列作为属性添加到块中
|
||||
|
||||
attrs := parse.IAL2Map(node.KramdownIAL)
|
||||
for _, col := range attrView.Columns[1:] {
|
||||
colName := col.Name
|
||||
attrs[colName] = ""
|
||||
}
|
||||
|
||||
if err = setNodeAttrs(node, tree, attrs); nil != err {
|
||||
if err = setNodeAttrsWithTx(tx, node, tree, attrs); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
attrView.Rows = append(attrView.Rows, row)
|
||||
|
||||
err = av.SaveAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
@ -110,22 +110,9 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
||||
}
|
||||
|
||||
func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
for name := range nameValues {
|
||||
for i := 0; i < len(name); i++ {
|
||||
if !lex.IsASCIILetterNumHyphen(name[i]) {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(25), node.ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, value := range nameValues {
|
||||
if "" == value {
|
||||
node.RemoveIALAttr(name)
|
||||
} else {
|
||||
node.SetIALAttr(name, value)
|
||||
}
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if 1 == len(nameValues) && "" != nameValues["scroll"] {
|
||||
@ -142,19 +129,56 @@ func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string
|
||||
IncSync()
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: node.ID}
|
||||
trans := []*Transaction{{
|
||||
DoOperations: []*Operation{doOp},
|
||||
UndoOperations: []*Operation{},
|
||||
}}
|
||||
pushBroadcastAttrTransactions(trans)
|
||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||
return
|
||||
}
|
||||
|
||||
func pushBroadcastAttrTransactions(transactions []*Transaction) {
|
||||
func setNodeAttrsWithTx(tx *Transaction, node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
IncSync()
|
||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||
return
|
||||
}
|
||||
|
||||
func setNodeAttrs0(node *ast.Node, nameValues map[string]string) (oldAttrs map[string]string, err error) {
|
||||
oldAttrs = parse.IAL2Map(node.KramdownIAL)
|
||||
|
||||
for name := range nameValues {
|
||||
for i := 0; i < len(name); i++ {
|
||||
if !lex.IsASCIILetterNumHyphen(name[i]) {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(25), node.ID))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for name, value := range nameValues {
|
||||
if "" == value {
|
||||
node.RemoveIALAttr(name)
|
||||
} else {
|
||||
node.SetIALAttr(name, value)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func pushBroadcastAttrTransactions(oldAttrs map[string]string, node *ast.Node) {
|
||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: node.ID}
|
||||
evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcast)
|
||||
evt.Data = transactions
|
||||
evt.Data = []*Transaction{{
|
||||
DoOperations: []*Operation{doOp},
|
||||
UndoOperations: []*Operation{},
|
||||
}}
|
||||
util.PushEvent(evt)
|
||||
}
|
||||
|
||||
|
@ -592,14 +592,7 @@ func removeBlocksDeckAttr(blockIDs []string, deckID string) (err error) {
|
||||
}
|
||||
|
||||
cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: blockID}
|
||||
trans := []*Transaction{{
|
||||
DoOperations: []*Operation{doOp},
|
||||
UndoOperations: []*Operation{},
|
||||
}}
|
||||
pushBroadcastAttrTransactions(trans)
|
||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||
}
|
||||
|
||||
return
|
||||
@ -674,14 +667,7 @@ func AddFlashcards(deckID string, blockIDs []string) (err error) {
|
||||
}
|
||||
|
||||
cache.PutBlockIAL(blockID, parse.IAL2Map(node.KramdownIAL))
|
||||
|
||||
newAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||
doOp := &Operation{Action: "updateAttrs", Data: map[string]interface{}{"old": oldAttrs, "new": newAttrs}, ID: blockID}
|
||||
trans := []*Transaction{{
|
||||
DoOperations: []*Operation{doOp},
|
||||
UndoOperations: []*Operation{},
|
||||
}}
|
||||
pushBroadcastAttrTransactions(trans)
|
||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||
}
|
||||
|
||||
deck := Decks[deckID]
|
||||
|
Loading…
Reference in New Issue
Block a user