Merge pull request #1856 from alixander/delete-label-near
d2oracle: delete nested label/icon fields
This commit is contained in:
commit
ff9150a75c
5 changed files with 352 additions and 5 deletions
|
|
@ -1248,16 +1248,23 @@ func deleteReserved(g *d2graph.Graph, baseAST *d2ast.Map, mk *d2ast.Key) (*d2gra
|
||||||
return recompile(g)
|
return recompile(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
isStyleKey := false
|
isNestedKey := false
|
||||||
imported := false
|
imported := false
|
||||||
for _, id := range d2graph.Key(targetKey) {
|
parts := d2graph.Key(targetKey)
|
||||||
|
for i, id := range parts {
|
||||||
_, ok := d2graph.ReservedKeywords[id]
|
_, ok := d2graph.ReservedKeywords[id]
|
||||||
if ok {
|
if ok {
|
||||||
if id == "style" {
|
if id == "style" {
|
||||||
isStyleKey = true
|
isNestedKey = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if isStyleKey {
|
if id == "label" || id == "icon" {
|
||||||
|
if i < len(parts)-1 {
|
||||||
|
isNestedKey = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if isNestedKey {
|
||||||
if imported {
|
if imported {
|
||||||
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
mk.Value = d2ast.MakeValueBox(&d2ast.Null{})
|
||||||
appendMapKey(baseAST, mk)
|
appendMapKey(baseAST, mk)
|
||||||
|
|
@ -1306,6 +1313,8 @@ func deleteMapField(m *d2ast.Map, field string) {
|
||||||
if n.MapKey.Key.Path[0].Unbox().ScalarString() == field {
|
if n.MapKey.Key.Path[0].Unbox().ScalarString() == field {
|
||||||
deleteFromMap(m, n.MapKey)
|
deleteFromMap(m, n.MapKey)
|
||||||
} else if n.MapKey.Key.Path[0].Unbox().ScalarString() == "style" ||
|
} else if n.MapKey.Key.Path[0].Unbox().ScalarString() == "style" ||
|
||||||
|
n.MapKey.Key.Path[0].Unbox().ScalarString() == "label" ||
|
||||||
|
n.MapKey.Key.Path[0].Unbox().ScalarString() == "icon" ||
|
||||||
n.MapKey.Key.Path[0].Unbox().ScalarString() == "source-arrowhead" ||
|
n.MapKey.Key.Path[0].Unbox().ScalarString() == "source-arrowhead" ||
|
||||||
n.MapKey.Key.Path[0].Unbox().ScalarString() == "target-arrowhead" {
|
n.MapKey.Key.Path[0].Unbox().ScalarString() == "target-arrowhead" {
|
||||||
if n.MapKey.Value.Map != nil {
|
if n.MapKey.Value.Map != nil {
|
||||||
|
|
@ -1354,7 +1363,9 @@ func deleteObjField(g *d2graph.Graph, obj *d2graph.Object, field string) error {
|
||||||
ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == obj.ID) ||
|
ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == obj.ID) ||
|
||||||
(len(ref.Key.Path) >= 3 &&
|
(len(ref.Key.Path) >= 3 &&
|
||||||
ref.Key.Path[len(ref.Key.Path)-1].Unbox().ScalarString() == field &&
|
ref.Key.Path[len(ref.Key.Path)-1].Unbox().ScalarString() == field &&
|
||||||
ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == "style" &&
|
(ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == "style" ||
|
||||||
|
ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == "label" ||
|
||||||
|
ref.Key.Path[len(ref.Key.Path)-2].Unbox().ScalarString() == "icon") &&
|
||||||
ref.Key.Path[len(ref.Key.Path)-3].Unbox().ScalarString() == obj.ID) {
|
ref.Key.Path[len(ref.Key.Path)-3].Unbox().ScalarString() == obj.ID) {
|
||||||
tmpNodes := make([]d2ast.MapNodeBox, len(ref.Scope.Nodes))
|
tmpNodes := make([]d2ast.MapNodeBox, len(ref.Scope.Nodes))
|
||||||
copy(tmpNodes, ref.Scope.Nodes)
|
copy(tmpNodes, ref.Scope.Nodes)
|
||||||
|
|
|
||||||
|
|
@ -7427,6 +7427,24 @@ a.link: null
|
||||||
key: `a.style.fill`,
|
key: `a.style.fill`,
|
||||||
exp: `...@meow
|
exp: `...@meow
|
||||||
a.style.fill: null
|
a.style.fill: null
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "label-near/1",
|
||||||
|
|
||||||
|
text: `yes: {label.near: center-center}
|
||||||
|
`,
|
||||||
|
key: `yes.label.near`,
|
||||||
|
exp: `yes
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "label-near/2",
|
||||||
|
|
||||||
|
text: `yes.label.near: center-center
|
||||||
|
`,
|
||||||
|
key: `yes.label.near`,
|
||||||
|
exp: `yes
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
106
testdata/d2oracle/TestDelete/label-near.exp.json
generated
vendored
Normal file
106
testdata/d2oracle/TestDelete/label-near.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-1:0:4",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-0:3:3",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": null,
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"id": "yes",
|
||||||
|
"id_val": "yes",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "yes"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
106
testdata/d2oracle/TestDelete/label-near/1.exp.json
generated
vendored
Normal file
106
testdata/d2oracle/TestDelete/label-near/1.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-1:0:4",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-0:3:3",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": null,
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"id": "yes",
|
||||||
|
"id_val": "yes",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/1.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "yes"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
106
testdata/d2oracle/TestDelete/label-near/2.exp.json
generated
vendored
Normal file
106
testdata/d2oracle/TestDelete/label-near/2.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-1:0:4",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-0:3:3",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": null,
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"id": "yes",
|
||||||
|
"id_val": "yes",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-0:3:3",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/label-near/2.d2,0:0:0-0:3:3",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "yes",
|
||||||
|
"raw_string": "yes"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "yes"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue