mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Add scenes for expanding and collapsing headings https://github.com/siyuan-note/siyuan/issues/15726
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
b8e67bec2d
commit
3f7421a393
3 changed files with 63 additions and 0 deletions
|
|
@ -243,6 +243,28 @@ func getHeadingDeleteTransaction(c *gin.Context) {
|
|||
ret.Data = transaction
|
||||
}
|
||||
|
||||
func getHeadingInsertTransaction(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)
|
||||
|
||||
transaction, err := model.GetHeadingInsertTransaction(id)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = transaction
|
||||
}
|
||||
|
||||
func getHeadingLevelTransaction(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -214,6 +214,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/block/setBlockReminder", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setBlockReminder)
|
||||
ginServer.Handle("POST", "/api/block/getHeadingLevelTransaction", model.CheckAuth, getHeadingLevelTransaction)
|
||||
ginServer.Handle("POST", "/api/block/getHeadingDeleteTransaction", model.CheckAuth, getHeadingDeleteTransaction)
|
||||
ginServer.Handle("POST", "/api/block/getHeadingInsertTransaction", model.CheckAuth, getHeadingInsertTransaction)
|
||||
ginServer.Handle("POST", "/api/block/getHeadingChildrenIDs", model.CheckAuth, getHeadingChildrenIDs)
|
||||
ginServer.Handle("POST", "/api/block/getHeadingChildrenDOM", model.CheckAuth, getHeadingChildrenDOM)
|
||||
ginServer.Handle("POST", "/api/block/swapBlockRef", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, swapBlockRef)
|
||||
|
|
|
|||
|
|
@ -628,6 +628,46 @@ func GetHeadingDeleteTransaction(id string) (transaction *Transaction, err error
|
|||
return
|
||||
}
|
||||
|
||||
func GetHeadingInsertTransaction(id string) (transaction *Transaction, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
if nil == node {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(15), id))
|
||||
return
|
||||
}
|
||||
|
||||
if ast.NodeHeading != node.Type {
|
||||
return
|
||||
}
|
||||
|
||||
var nodes []*ast.Node
|
||||
nodes = append(nodes, node)
|
||||
nodes = append(nodes, treenode.HeadingChildren(node)...)
|
||||
|
||||
transaction = &Transaction{}
|
||||
luteEngine := util.NewLute()
|
||||
for _, n := range nodes {
|
||||
n.ID = ast.NewNodeID()
|
||||
n.SetIALAttr("id", n.ID)
|
||||
|
||||
op := &Operation{}
|
||||
op.ID = n.ID
|
||||
op.Action = "insert"
|
||||
op.Data = luteEngine.RenderNodeBlockDOM(n)
|
||||
transaction.DoOperations = append(transaction.DoOperations, op)
|
||||
|
||||
op = &Operation{}
|
||||
op.ID = n.ID
|
||||
op.Action = "delete"
|
||||
transaction.UndoOperations = append(transaction.UndoOperations, op)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetHeadingChildrenIDs(id string) (ret []string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue