11import { inject , injectable , optional } from "inversify" ;
22import "./constraintMenu.css" ;
33import { AbstractUIExtension , IActionDispatcher , LocalModelSource , TYPES } from "sprotty" ;
4- import { Constraint , ConstraintRegistry } from "./constraintRegistry" ;
4+ import { ConstraintRegistry } from "./constraintRegistry" ;
55
66// Enable hover feature that is used to show validation errors.
77// Inline completions are enabled to allow autocompletion of keywords and inputs/label types/label values.
@@ -19,7 +19,7 @@ import { LabelTypeRegistry } from "../labels/labelTypeRegistry";
1919import { EditorModeController } from "../editorMode/editorModeController" ;
2020import { Switchable , ThemeManager } from "../settingsMenu/themeManager" ;
2121import { AnalyzeDiagramAction } from "../serialize/analyze" ;
22- import { ChooseConstraintAction } from "./actions" ;
22+ import { ChooseConstraintAction } from "./actions" ;
2323
2424@injectable ( )
2525export class ConstraintMenu extends AbstractUIExtension implements Switchable {
@@ -236,7 +236,7 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
236236 const btn = document . createElement ( "button" ) ;
237237 btn . id = "constraint-options-button" ;
238238 btn . title = "Filter…" ;
239- btn . innerHTML = "⋮" ; // or insert a font-awesome icon
239+ btn . innerHTML = "⋮" ; // or insert a font-awesome icon
240240 btn . onclick = ( ) => this . toggleOptionsMenu ( ) ;
241241 return btn ;
242242 }
@@ -253,46 +253,39 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
253253 this . optionsMenu = document . createElement ( "div" ) ;
254254 this . optionsMenu . id = "constraint-options-menu" ;
255255
256- // 2) add the “All constraints” checkbox at the top
257- const allConstraints = document . createElement ( "label" ) ;
258- allConstraints . classList . add ( "options-item" ) ;
259-
260- const allCb = document . createElement ( "input" ) ;
261- allCb . type = "checkbox" ;
262- allCb . value = "ALL" ;
263- // initially checked if no specific constraint is selected
264- allCb . checked = this . constraintRegistry . getSelectedConstraints ( ) . includes ( "ALL" ) ;
265-
266- allCb . onchange = ( ) => {
267- if ( ! this . optionsMenu ) return ;
268- if ( allCb . checked ) {
269- // uncheck every other constraint-checkbox
270- this . optionsMenu
271- . querySelectorAll < HTMLInputElement > ( "input[type=checkbox]" )
272- . forEach ( cb => {
273- if ( cb !== allCb ) cb . checked = false ;
274- } ) ;
275- // dispatch with empty array to mean “all”
276- this . dispatcher . dispatch (
277- ChooseConstraintAction . create ( [ "ALL" ] )
278- ) ;
279- } else {
280- this . dispatcher . dispatch (
281- ChooseConstraintAction . create ( [ ] )
282- ) ;
283- }
284-
285- } ;
286-
287- allConstraints . appendChild ( allCb ) ;
288- allConstraints . appendChild ( document . createTextNode ( "All constraints" ) ) ;
256+ // 2) add the “All constraints” checkbox at the top
257+ const allConstraints = document . createElement ( "label" ) ;
258+ allConstraints . classList . add ( "options-item" ) ;
259+
260+ const allCb = document . createElement ( "input" ) ;
261+ allCb . type = "checkbox" ;
262+ allCb . value = "ALL" ;
263+ // initially checked if no specific constraint is selected
264+ allCb . checked = this . constraintRegistry . getSelectedConstraints ( ) . includes ( "ALL" ) ;
265+
266+ allCb . onchange = ( ) => {
267+ if ( ! this . optionsMenu ) return ;
268+ if ( allCb . checked ) {
269+ // uncheck every other constraint-checkbox
270+ this . optionsMenu . querySelectorAll < HTMLInputElement > ( "input[type=checkbox]" ) . forEach ( ( cb ) => {
271+ if ( cb !== allCb ) cb . checked = false ;
272+ } ) ;
273+ // dispatch with empty array to mean “all”
274+ this . dispatcher . dispatch ( ChooseConstraintAction . create ( [ "ALL" ] ) ) ;
275+ } else {
276+ this . dispatcher . dispatch ( ChooseConstraintAction . create ( [ ] ) ) ;
277+ }
278+ } ;
279+
280+ allConstraints . appendChild ( allCb ) ;
281+ allConstraints . appendChild ( document . createTextNode ( "All constraints" ) ) ;
289282 this . optionsMenu . appendChild ( allConstraints ) ;
290283
291284 // 2) pull your dynamic items (replace with your real API)
292285 const items = this . constraintRegistry . getConstraintList ( ) ;
293286
294287 // 3) for each item build a checkbox
295- items . forEach ( item => {
288+ items . forEach ( ( item ) => {
296289 const label = document . createElement ( "label" ) ;
297290 label . classList . add ( "options-item" ) ;
298291
@@ -305,14 +298,12 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
305298 if ( cb . checked ) allCb . checked = false ;
306299
307300 const selected = Array . from (
308- this . optionsMenu ! . querySelectorAll < HTMLInputElement > ( "input[type=checkbox]:checked" )
309- ) . map ( cb => cb . value ) ;
301+ this . optionsMenu ! . querySelectorAll < HTMLInputElement > ( "input[type=checkbox]:checked" ) ,
302+ ) . map ( ( cb ) => cb . value ) ;
310303
311304 // dispatch your action with either an array or
312305 // a comma-joined string—whatever your action expects
313- this . dispatcher . dispatch (
314- ChooseConstraintAction . create ( selected )
315- ) ;
306+ this . dispatcher . dispatch ( ChooseConstraintAction . create ( selected ) ) ;
316307 } ;
317308
318309 label . appendChild ( cb ) ;
@@ -324,8 +315,11 @@ export class ConstraintMenu extends AbstractUIExtension implements Switchable {
324315
325316 // optional: click-outside handler
326317 const onClickOutside = ( e : MouseEvent ) => {
327- if ( this . optionsMenu && ! this . optionsMenu . contains ( e . target as Node )
328- && ! ( e . target as Element ) . matches ( "#constraint-options-button" ) ) {
318+ if (
319+ this . optionsMenu &&
320+ ! this . optionsMenu . contains ( e . target as Node ) &&
321+ ! ( e . target as Element ) . matches ( "#constraint-options-button" )
322+ ) {
329323 this . toggleOptionsMenu ( ) ;
330324 document . removeEventListener ( "click" , onClickOutside ) ;
331325 }
0 commit comments