-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit-content) add language variable to wysiwyg and autodetect la…
…nguage code (#30419) ### Proposed Changes * Add support to WYSIWYG to add Language Variables * Auto-detect language in code. * Add Velocity to code detection ### Checklist - [x] Tests - [ ] Translations - [ ] Security Implications Contemplated (add notes if applicable) ### Additional Info ** any additional useful context or info ** ### Screenshots https://github.com/user-attachments/assets/3f8ac8bd-e89b-471f-a669-e044b675154a
- Loading branch information
Showing
18 changed files
with
856 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
...-wysiwyg-field/components/dot-wysiwyg-monaco/custom-languages/velocity-monaco-language.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Velocity language definition for Monaco Editor | ||
export const dotVelocityLanguageDefinition: monaco.languages.IMonarchLanguage = { | ||
defaultToken: '', | ||
tokenPostfix: '.vtl', | ||
ignoreCase: true, | ||
|
||
brackets: [ | ||
{ open: '{', close: '}', token: 'delimiter.curly' }, | ||
{ open: '[', close: ']', token: 'delimiter.square' }, | ||
{ open: '(', close: ')', token: 'delimiter.parenthesis' }, | ||
{ open: '<', close: '>', token: 'delimiter.angle' } | ||
], | ||
|
||
keywords: [ | ||
'foreach', | ||
'if', | ||
'else', | ||
'elseif', | ||
'end', | ||
'set', | ||
'parse', | ||
'include', | ||
'macro', | ||
'stop', | ||
'dotParse' | ||
], | ||
|
||
tokenizer: { | ||
root: [ | ||
// HTML Comments | ||
[/<!--/, 'comment.html', '@htmlComment'], | ||
|
||
// Velocity Directives | ||
|
||
[/#(foreach|if|else|elseif|end|set|parse|include|macro|stop)\b/, 'keyword.velocity'], | ||
|
||
[/#(dotParse)\b/, 'keyword.dotparse.velocity'], | ||
|
||
// Velocity Variables (más inclusivo) | ||
[ | ||
/(\$!?)(\{?)([a-zA-Z_][\w-]*(?:\.[a-zA-Z_][\w-]*)*)/, | ||
{ | ||
cases: { | ||
'$2=={': [ | ||
'variable.velocity.delimiter', | ||
'variable.velocity.delimiter', | ||
{ token: 'variable.velocity', next: '@velocityVariable' } | ||
], | ||
'$1==$': ['variable.velocity.delimiter', '', 'variable.velocity'], | ||
'@default': ['', '', 'variable.velocity'] | ||
} | ||
} | ||
], | ||
|
||
// Variables simples que comienzan con $ | ||
[/\$[a-zA-Z][\w-]*/, 'variable.velocity'], | ||
|
||
// HTML Tags | ||
[/<\/?[\w\-:.]+/, 'tag.html'], | ||
|
||
// HTML Attributes | ||
[/[a-zA-Z][a-zA-Z0-9_-]*(?=\s*=)/, 'attribute.name.html'], | ||
[/"[^"]*"|'[^']*'/, 'attribute.value.html'], | ||
|
||
// Velocity Comments | ||
[/##[^\n]*/, 'comment.velocity'], | ||
[/#\*(?!\*)/, 'comment.velocity', '@velocityComment'], | ||
|
||
// Strings | ||
[/"/, 'string.velocity', '@string_double'], | ||
[/'/, 'string.velocity', '@string_single'], | ||
|
||
// Other syntax | ||
[/[{}()[\]]/, 'delimiter.velocity'], | ||
[/[<>]/, 'delimiter.angle.velocity'], | ||
[/[;,.]/, 'delimiter.velocity'] | ||
], | ||
|
||
htmlComment: [ | ||
[/[^-]+/, 'comment.html'], | ||
[/-->/, 'comment.html', '@pop'], | ||
[/-/, 'comment.html'] | ||
], | ||
|
||
htmlAttributeValue: [ | ||
[/[^"]+/, 'string.html'], | ||
[ | ||
/(\$!?\{?)([a-zA-Z][\w-]*(?:\.[a-zA-Z][\w-]*)*(?:\([^)]*\))?)(\})?/, | ||
['variable.velocity', 'variable.velocity', 'variable.velocity'] | ||
], | ||
[/\$[a-zA-Z][\w-]*/, 'variable.velocity'], | ||
[/"/, { token: 'string.html', next: '@pop' }] | ||
], | ||
|
||
string_double: [ | ||
[/[^\\"$]+/, 'string.velocity'], | ||
[/\\./, 'string.escape.velocity'], | ||
[ | ||
/(\$!?\{?)([a-zA-Z][\w-]*(?:\.[a-zA-Z][\w-]*)*(?:\([^)]*\))?)(\})?/, | ||
['variable.velocity', 'variable.velocity', 'variable.velocity'] | ||
], | ||
[/\$[a-zA-Z][\w-]*/, 'variable.velocity'], | ||
[/"/, 'string.velocity', '@pop'] | ||
], | ||
|
||
string_single: [ | ||
[/[^\\'$]+/, 'string.velocity'], | ||
[/\\./, 'string.escape.velocity'], | ||
[ | ||
/(\$!?\{?)([a-zA-Z][\w-]*(?:\.[a-zA-Z][\w-]*)*(?:\([^)]*\))?)(\})?/, | ||
['variable.velocity', 'variable.velocity', 'variable.velocity'] | ||
], | ||
[/\$[a-zA-Z][\w-]*/, 'variable.velocity'], | ||
[/'/, 'string.velocity', '@pop'] | ||
], | ||
|
||
velocityComment: [ | ||
[/[^*#]+/, 'comment.velocity'], | ||
[/#\*/, 'comment.velocity', '@push'], | ||
[/\*#/, 'comment.velocity', '@pop'], | ||
[/[*#]/, 'comment.velocity'] | ||
], | ||
|
||
velocityVariable: [ | ||
[/\}/, 'variable.velocity.delimiter', '@pop'], | ||
[/\(/, 'delimiter.parenthesis', '@velocityMethod'], | ||
[/[^}()]/, 'variable.velocity'] | ||
], | ||
|
||
velocityMethod: [ | ||
[/\)/, 'delimiter.parenthesis', '@pop'], | ||
[/\(/, 'delimiter.parenthesis', '@push'], | ||
[/[^()]/, 'variable.velocity'] | ||
] | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
...dit-content-wysiwyg-field/components/dot-wysiwyg-monaco/dot-wysiwyg-monaco.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
...dit-content-wysiwyg-field/components/dot-wysiwyg-monaco/dot-wysiwyg-monaco.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
@use "variables" as *; | ||
|
||
ngx-monaco-editor { | ||
height: 300px; | ||
width: 100%; | ||
border: $field-border-size solid $color-palette-gray-400; | ||
border-radius: $border-radius-md; | ||
display: flex; | ||
:host { | ||
ngx-monaco-editor { | ||
height: 400px; | ||
width: 100%; | ||
padding: $spacing-0; | ||
display: flex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.