Merge remote-tracking branch 'upstream/master' into issue-2409

This commit is contained in:
melsonic 2025-03-29 14:51:22 +05:30
commit e8926f71d4
No known key found for this signature in database
GPG key ID: DFA426742F621CD7
4 changed files with 561 additions and 3 deletions

View file

@ -36,7 +36,7 @@
const input = document.getElementById("input").value;
try {
const result = await d2.compile(input);
const svg = await d2.render(result.diagram);
const svg = await d2.render(result.diagram, result.renderOptions);
document.getElementById("output").innerHTML = svg;
} catch (err) {
console.error(err);

View file

@ -398,7 +398,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
if baseAST != g.AST || imported {
writeableRefs := GetWriteableRefs(obj, baseAST)
for _, ref := range writeableRefs {
if ref.MapKey != nil && ref.MapKey.Value.Map != nil {
if ref.MapKey != nil && ref.MapKey.Value.Map != nil && ref.MapKey.Key == mk.Key {
maybeNewScope = ref.MapKey.Value.Map
}
}

View file

@ -30,6 +30,7 @@ func TestCreate(t *testing.T) {
boardPath []string
name string
text string
fsTexts map[string]string
key string
expKey string
@ -805,6 +806,35 @@ steps: {
d 2
}
}
`,
},
{
name: "image-edge",
text: `...@k
a.b: {
icon: https://icons.terrastruct.com/essentials/004-picture.svg
shape: image
}
`,
fsTexts: map[string]string{
"k.d2": `
a: {
b
c
}
`,
},
key: `a.b -> a.c`,
boardPath: []string{},
expKey: `a.(b -> c)[0]`,
exp: `...@k
a.b: {
icon: https://icons.terrastruct.com/essentials/004-picture.svg
shape: image
}
a.(b -> c)
`,
},
}
@ -816,7 +846,8 @@ steps: {
var newKey string
et := editTest{
text: tc.text,
text: tc.text,
fsTexts: tc.fsTexts,
testFunc: func(g *d2graph.Graph) (*d2graph.Graph, error) {
var err error
g, newKey, err = d2oracle.Create(g, tc.boardPath, tc.key)

527
testdata/d2oracle/TestCreate/image-edge.exp.json generated vendored Normal file
View file

@ -0,0 +1,527 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "index.d2,0:0:0-6:0:106",
"nodes": [
{
"import": {
"range": "index.d2,0:0:0-0:5:5",
"spread": true,
"pre": "",
"path": [
{
"unquoted_string": {
"range": "index.d2,0:4:4-0:5:5",
"value": [
{
"string": "k",
"raw_string": "k"
}
]
}
}
]
}
},
{
"map_key": {
"range": "index.d2,1:0:6-4:1:94",
"key": {
"range": "index.d2,1:0:6-1:3:9",
"path": [
{
"unquoted_string": {
"range": "index.d2,1:0:6-1:1:7",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "index.d2,1:2:8-1:3:9",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "index.d2,1:5:11-4:1:94",
"nodes": [
{
"map_key": {
"range": "index.d2,2:2:15-2:64:77",
"key": {
"range": "index.d2,2:2:15-2:6:19",
"path": [
{
"unquoted_string": {
"range": "index.d2,2:2:15-2:6:19",
"value": [
{
"string": "icon",
"raw_string": "icon"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "index.d2,2:8:21-2:64:77",
"value": [
{
"string": "https://icons.terrastruct.com/essentials/004-picture.svg",
"raw_string": "https://icons.terrastruct.com/essentials/004-picture.svg"
}
]
}
}
}
},
{
"map_key": {
"range": "index.d2,3:2:80-3:14:92",
"key": {
"range": "index.d2,3:2:80-3:7:85",
"path": [
{
"unquoted_string": {
"range": "index.d2,3:2:80-3:7:85",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "index.d2,3:9:87-3:14:92",
"value": [
{
"string": "image",
"raw_string": "image"
}
]
}
}
}
}
]
}
}
}
},
{
"map_key": {
"range": "index.d2,5:0:95-5:10:105",
"key": {
"range": "index.d2,5:0:95-5:1:96",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:0:95-5:1:96",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"edges": [
{
"range": "index.d2,5:3:98-5:9:104",
"src": {
"range": "index.d2,5:3:98-5:4:99",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:3:98-5:4:99",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"src_arrow": "",
"dst": {
"range": "index.d2,5:8:103-5:9:104",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:8:103-5:9:104",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"dst_arrow": ">"
}
],
"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": [
{
"index": 0,
"isCurve": false,
"src_arrow": false,
"dst_arrow": true,
"references": [
{
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
],
"objects": [
{
"id": "a",
"id_val": "a",
"references": [
{
"key": {
"range": "k.d2,1:0:1-1:1:2",
"path": [
{
"unquoted_string": {
"range": "k.d2,1:0:1-1:1:2",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "index.d2,1:0:6-1:3:9",
"path": [
{
"unquoted_string": {
"range": "index.d2,1:0:6-1:1:7",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "index.d2,1:2:8-1:3:9",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "index.d2,5:0:95-5:1:96",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:0:95-5:1:96",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "a"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
{
"id": "b",
"id_val": "b",
"references": [
{
"key": {
"range": "k.d2,2:2:8-2:3:9",
"path": [
{
"unquoted_string": {
"range": "k.d2,2:2:8-2:3:9",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "index.d2,1:0:6-1:3:9",
"path": [
{
"unquoted_string": {
"range": "index.d2,1:0:6-1:1:7",
"value": [
{
"string": "a",
"raw_string": "a"
}
]
}
},
{
"unquoted_string": {
"range": "index.d2,1:2:8-1:3:9",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 1,
"map_key_edge_index": -1
},
{
"key": {
"range": "index.d2,5:3:98-5:4:99",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:3:98-5:4:99",
"value": [
{
"string": "b",
"raw_string": "b"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "b"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"icon": {
"Scheme": "https",
"Opaque": "",
"User": null,
"Host": "icons.terrastruct.com",
"Path": "/essentials/004-picture.svg",
"RawPath": "",
"OmitHost": false,
"ForceQuery": false,
"RawQuery": "",
"Fragment": "",
"RawFragment": ""
},
"near_key": null,
"shape": {
"value": "image"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
{
"id": "c",
"id_val": "c",
"references": [
{
"key": {
"range": "k.d2,3:2:12-3:3:13",
"path": [
{
"unquoted_string": {
"range": "k.d2,3:2:12-3:3:13",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
},
{
"key": {
"range": "index.d2,5:8:103-5:9:104",
"path": [
{
"unquoted_string": {
"range": "index.d2,5:8:103-5:9:104",
"value": [
{
"string": "c",
"raw_string": "c"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": 0
}
],
"attributes": {
"label": {
"value": "c"
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
}
]
},
"err": "<nil>"
}