Compare commits

..

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
39b8ad2b09 [autofix.ci] apply automated fixes 2025-10-11 21:20:54 +00:00
Justin Greywolf
709880178e feat: add support for link statements within namespace blocks in class diagrams
Resolves #4700
2025-10-11 14:13:48 -07:00
6 changed files with 66 additions and 9 deletions

View File

@@ -702,6 +702,7 @@ classDiagram
It is possible to bind a click event to a node. The click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`.
You would define these actions on a separate line after all classes have been declared.
If you have classes defined within a namespace, you can also add interaction definitions within the namespace definition, after the class(es) is defined
```
action className "reference" "tooltip"

View File

@@ -78,7 +78,7 @@
"d3-sankey": "^0.12.3",
"dagre-d3-es": "7.0.11",
"dayjs": "^1.11.18",
"dompurify": "^3.2.7",
"dompurify": "^3.2.5",
"katex": "^0.16.22",
"khroma": "^2.1.0",
"lodash-es": "^4.17.21",

View File

@@ -88,6 +88,50 @@ describe('given a basic class diagram, ', function () {
expect(relations[0].title).toBe('generates');
});
it('should handle link statements within namespaces', function () {
spyOn(classDb, 'setLink');
const str = `classDiagram
namespace MyNamespace {
class UserService {
+createUser()
+deleteUser()
}
class PaymentService {
+processPayment()
+refund()
}
link UserService "https://example.com/user-service"
link PaymentService "https://example.com/payment-service" "Payment Service Documentation"
}`;
parser.parse(str);
// Verify setLink was called for both classes
expect(classDb.setLink).toHaveBeenCalledWith(
'UserService',
'https://example.com/user-service'
);
expect(classDb.setLink).toHaveBeenCalledWith(
'PaymentService',
'https://example.com/payment-service'
);
// Verify the classes have the correct links and are in the namespace
const userService = classDb.getClass('UserService');
const paymentService = classDb.getClass('PaymentService');
expect(userService.parent).toBe('MyNamespace');
expect(userService.link).toBe('https://example.com/user-service');
expect(userService.cssClasses).toBe('default clickable');
expect(paymentService.parent).toBe('MyNamespace');
expect(paymentService.link).toBe('https://example.com/payment-service');
expect(paymentService.tooltip).toBe('Payment Service Documentation');
expect(paymentService.cssClasses).toBe('default clickable');
});
it('should handle accTitle and accDescr', function () {
const str = `classDiagram
accTitle: My Title

View File

@@ -275,14 +275,25 @@ statement
;
namespaceStatement
: namespaceIdentifier STRUCT_START classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $3); }
| namespaceIdentifier STRUCT_START NEWLINE classStatements STRUCT_STOP { yy.addClassesToNamespace($1, $4); }
: namespaceIdentifier STRUCT_START namespaceBodyStatements STRUCT_STOP { yy.addClassesToNamespace($1, $3); }
| namespaceIdentifier STRUCT_START NEWLINE namespaceBodyStatements STRUCT_STOP { yy.addClassesToNamespace($1, $4); }
;
namespaceIdentifier
: NAMESPACE namespaceName { $$=$2; yy.addNamespace($2); }
;
namespaceBodyStatements
: namespaceBodyStatement { $$=[$1].filter(s => s !== null); }
| namespaceBodyStatement NEWLINE { $$=[$1].filter(s => s !== null); }
| namespaceBodyStatement NEWLINE namespaceBodyStatements { var filtered = [$1].filter(s => s !== null); $3.unshift(...filtered); $$=$3; }
;
namespaceBodyStatement
: classStatement { $$=$1; }
| clickStatement { $$=null; /* clickStatements don't return class names, but are processed for side effects */ }
;
classStatements
: classStatement {$$=[$1]}
| classStatement NEWLINE {$$=[$1]}

View File

@@ -452,6 +452,7 @@ classDiagram
It is possible to bind a click event to a node. The click can lead to either a javascript callback or to a link which will be opened in a new browser tab. **Note**: This functionality is disabled when using `securityLevel='strict'` and enabled when using `securityLevel='loose'`.
You would define these actions on a separate line after all classes have been declared.
If you have classes defined within a namespace, you can also add interaction definitions within the namespace definition, after the class(es) is defined
```
action className "reference" "tooltip"

12
pnpm-lock.yaml generated
View File

@@ -257,8 +257,8 @@ importers:
specifier: ^1.11.18
version: 1.11.18
dompurify:
specifier: ^3.2.7
version: 3.2.7
specifier: ^3.2.5
version: 3.2.6
katex:
specifier: ^0.16.22
version: 0.16.22
@@ -5166,8 +5166,8 @@ packages:
resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==}
engines: {node: '>= 4'}
dompurify@3.2.7:
resolution: {integrity: sha512-WhL/YuveyGXJaerVlMYGWhvQswa7myDG17P7Vu65EWC05o8vfeNbvNf4d/BOvH99+ZW+LlQsc1GDKMa1vNK6dw==}
dompurify@3.2.6:
resolution: {integrity: sha512-/2GogDQlohXPZe6D6NOgQvXLPSYBqIWMnZ8zzOhn09REE4eyAzb+Hed3jhoM9OkuaJ8P6ZGTTVWQKAi8ieIzfQ==}
domutils@3.2.2:
resolution: {integrity: sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==}
@@ -13803,7 +13803,7 @@ snapshots:
class-variance-authority: 0.7.1
clsx: 2.1.1
color-string: 2.1.2
dompurify: 3.2.7
dompurify: 3.2.6
highlight.js: 10.7.3
html-to-image: 1.11.13
immer: 10.1.3
@@ -15416,7 +15416,7 @@ snapshots:
dependencies:
domelementtype: 2.3.0
dompurify@3.2.7:
dompurify@3.2.6:
optionalDependencies:
'@types/trusted-types': 2.0.7