mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Remove the av-names attribute from block elements (#16424)
This commit is contained in:
parent
f6611ccc7f
commit
8a1703e34a
7 changed files with 25 additions and 8 deletions
|
|
@ -8,7 +8,6 @@ export const clearBlockElement = (element: Element) => {
|
||||||
element.querySelector(".protyle-attr--av")?.remove();
|
element.querySelector(".protyle-attr--av")?.remove();
|
||||||
element.querySelector(".protyle-attr--refcount")?.remove();
|
element.querySelector(".protyle-attr--refcount")?.remove();
|
||||||
element.removeAttribute("custom-avs");
|
element.removeAttribute("custom-avs");
|
||||||
element.removeAttribute("av-names");
|
|
||||||
element.getAttributeNames().forEach(attr => {
|
element.getAttributeNames().forEach(attr => {
|
||||||
if (attr.startsWith("custom-sy-av-s-text-")) {
|
if (attr.startsWith("custom-sy-av-s-text-")) {
|
||||||
element.removeAttribute(attr);
|
element.removeAttribute(attr);
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ialKeys.forEach((key: string) => {
|
ialKeys.forEach((key: string) => {
|
||||||
if (!["title-img", "title", "updated", "icon", "id", "type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth", "data-readonly"].includes(key)) {
|
if (!["title-img", "title", "updated", "icon", "id", "type", "class", "spellcheck", "contenteditable", "data-doc-type", "style", "data-realwidth", "data-readonly", "av-names"].includes(key)) {
|
||||||
this.element.setAttribute(key, ial[key]);
|
this.element.setAttribute(key, ial[key]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -611,13 +611,14 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
|
||||||
data.new.style += ";animation:addCard 450ms linear";
|
data.new.style += ";animation:addCard 450ms linear";
|
||||||
}
|
}
|
||||||
Object.keys(data.new).forEach(key => {
|
Object.keys(data.new).forEach(key => {
|
||||||
if ("id" === key) {
|
if ("id" === key || "av-names" === key) {
|
||||||
// 设置属性以后不应该给块元素添加 id 属性 No longer add the `id` attribute to block elements after setting the attribute https://github.com/siyuan-note/siyuan/issues/15327
|
// 设置属性以后不应该给块元素添加 id 属性 No longer add the `id` attribute to block elements after setting the attribute https://github.com/siyuan-note/siyuan/issues/15327
|
||||||
|
// av-names 属性仅用于生成角标,不添加到元素
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setAttribute(key, data.new[key]);
|
item.setAttribute(key, data.new[key]);
|
||||||
if (key === Constants.CUSTOM_RIFF_DECKS && data.new[Constants.CUSTOM_RIFF_DECKS] !== data.old[Constants.CUSTOM_RIFF_DECKS]) {
|
if (key === Constants.CUSTOM_RIFF_DECKS && key !== data.old[Constants.CUSTOM_RIFF_DECKS]) {
|
||||||
item.style.animation = "addCard 450ms linear";
|
item.style.animation = "addCard 450ms linear";
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (item.parentElement) {
|
if (item.parentElement) {
|
||||||
|
|
|
||||||
|
|
@ -2970,6 +2970,7 @@ func (tx *Transaction) setAttributeViewName(operation *Operation) (err error) {
|
||||||
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
oldAttrs := parse.IAL2Map(node.KramdownIAL)
|
||||||
node.SetIALAttr(av.NodeAttrViewNames, avNames)
|
node.SetIALAttr(av.NodeAttrViewNames, avNames)
|
||||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||||
|
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -3561,6 +3562,7 @@ func removeNodeAvID(node *ast.Node, avID string, tx *Transaction, tree *parse.Tr
|
||||||
node.RemoveIALAttr("custom-hidden")
|
node.RemoveIALAttr("custom-hidden")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var avNames string
|
||||||
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
|
if avs := attrs[av.NodeAttrNameAvs]; "" != avs {
|
||||||
avIDs := strings.Split(avs, ",")
|
avIDs := strings.Split(avs, ",")
|
||||||
avIDs = gulu.Str.RemoveElem(avIDs, avID)
|
avIDs = gulu.Str.RemoveElem(avIDs, avID)
|
||||||
|
|
@ -3577,7 +3579,7 @@ func removeNodeAvID(node *ast.Node, avID string, tx *Transaction, tree *parse.Tr
|
||||||
} else {
|
} else {
|
||||||
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
attrs[av.NodeAttrNameAvs] = strings.Join(avIDs, ",")
|
||||||
node.SetIALAttr(av.NodeAttrNameAvs, strings.Join(avIDs, ","))
|
node.SetIALAttr(av.NodeAttrNameAvs, strings.Join(avIDs, ","))
|
||||||
avNames := getAvNames(node.IALAttr(av.NodeAttrNameAvs))
|
avNames = getAvNames(node.IALAttr(av.NodeAttrNameAvs))
|
||||||
attrs[av.NodeAttrViewNames] = avNames
|
attrs[av.NodeAttrViewNames] = avNames
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3591,6 +3593,9 @@ func removeNodeAvID(node *ast.Node, avID string, tx *Transaction, tree *parse.Tr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if "" != avNames {
|
||||||
|
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5050,6 +5055,9 @@ func unbindBlockAv(tx *Transaction, avID, nodeID string) {
|
||||||
logging.LogWarnf("set node [%s] attrs failed: %s", nodeID, err)
|
logging.LogWarnf("set node [%s] attrs failed: %s", nodeID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if "" != avNames {
|
||||||
|
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5089,6 +5097,9 @@ func bindBlockAv0(tx *Transaction, avID string, node *ast.Node, tree *parse.Tree
|
||||||
logging.LogWarnf("set node [%s] attrs failed: %s", node.ID, err)
|
logging.LogWarnf("set node [%s] attrs failed: %s", node.ID, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if "" != avNames {
|
||||||
|
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5521,6 +5532,9 @@ func updateBoundBlockAvsAttribute(avIDs []string) {
|
||||||
}
|
}
|
||||||
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
cache.PutBlockIAL(node.ID, parse.IAL2Map(node.KramdownIAL))
|
||||||
pushBroadcastAttrTransactions(oldAttrs, node)
|
pushBroadcastAttrTransactions(oldAttrs, node)
|
||||||
|
if "" != avNames {
|
||||||
|
node.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -988,7 +988,6 @@ func DuplicateDoc(tree *parse.Tree) {
|
||||||
}
|
}
|
||||||
|
|
||||||
n.RemoveIALAttr(av.NodeAttrNameAvs)
|
n.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||||
n.RemoveIALAttr(av.NodeAttrViewNames)
|
|
||||||
n.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
n.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,11 @@ func renderBlockDOMByNodes(nodes []*ast.Node, luteEngine *lute.Lute) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 填充属性视图角标之后即可移除 av-names 属性
|
||||||
|
if n.IsBlock() && "" != n.IALAttr(av.NodeAttrViewNames) {
|
||||||
|
n.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rendererFunc := blockRenderer.RendererFuncs[n.Type]
|
rendererFunc := blockRenderer.RendererFuncs[n.Type]
|
||||||
|
|
|
||||||
|
|
@ -1073,6 +1073,7 @@ func (tx *Transaction) syncDelete2Block(node *ast.Node, nodeTree *parse.Tree) (c
|
||||||
oldAttrs := parse.IAL2Map(toChangNode.KramdownIAL)
|
oldAttrs := parse.IAL2Map(toChangNode.KramdownIAL)
|
||||||
toChangNode.SetIALAttr(av.NodeAttrViewNames, avNames)
|
toChangNode.SetIALAttr(av.NodeAttrViewNames, avNames)
|
||||||
pushBroadcastAttrTransactions(oldAttrs, toChangNode)
|
pushBroadcastAttrTransactions(oldAttrs, toChangNode)
|
||||||
|
toChangNode.RemoveIALAttr(av.NodeAttrViewNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tree := range trees {
|
for _, tree := range trees {
|
||||||
|
|
@ -1208,7 +1209,6 @@ func (tx *Transaction) doLargeInsert(previousID string) (ret *TxErr) {
|
||||||
|
|
||||||
// 复制为副本时移除数据库绑定状态 https://github.com/siyuan-note/siyuan/issues/12294
|
// 复制为副本时移除数据库绑定状态 https://github.com/siyuan-note/siyuan/issues/12294
|
||||||
insertedNode.RemoveIALAttr(av.NodeAttrNameAvs)
|
insertedNode.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||||
insertedNode.RemoveIALAttr(av.NodeAttrViewNames)
|
|
||||||
insertedNode.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
insertedNode.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
||||||
|
|
||||||
if ast.NodeAttributeView == insertedNode.Type {
|
if ast.NodeAttributeView == insertedNode.Type {
|
||||||
|
|
@ -1387,7 +1387,6 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||||
|
|
||||||
// 复制为副本时移除数据库绑定状态 https://github.com/siyuan-note/siyuan/issues/12294
|
// 复制为副本时移除数据库绑定状态 https://github.com/siyuan-note/siyuan/issues/12294
|
||||||
insertedNode.RemoveIALAttr(av.NodeAttrNameAvs)
|
insertedNode.RemoveIALAttr(av.NodeAttrNameAvs)
|
||||||
insertedNode.RemoveIALAttr(av.NodeAttrViewNames)
|
|
||||||
insertedNode.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
insertedNode.RemoveIALAttrsByPrefix(av.NodeAttrViewStaticText)
|
||||||
|
|
||||||
if ast.NodeAttributeView == insertedNode.Type {
|
if ast.NodeAttributeView == insertedNode.Type {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue