@@ -41,16 +41,25 @@ import {
4141 closeMenu ,
4242 closeAllMenus ,
4343 setDisabledCategories ,
44+ setHiddenItems ,
4445} from './actions' ;
4546import { mergeUISchema } from './utils/schema-merger' ;
46- import { generateUIStylesheet , StylesheetConfig } from './utils' ;
47+ import {
48+ generateUIStylesheet ,
49+ extractItemCategories ,
50+ computeHiddenItems ,
51+ StylesheetConfig ,
52+ } from './utils' ;
4753
4854export class UIPlugin extends BasePlugin < UIPluginConfig , UICapability , UIState , UIAction > {
4955 static readonly id = 'ui' as const ;
5056
5157 private schema : UISchema ;
5258 private stylesheetConfig : StylesheetConfig ;
5359
60+ // Item categories mapping for computing hidden items
61+ private itemCategories : Map < string , string [ ] > ;
62+
5463 // Stylesheet caching with locale awareness
5564 private cachedStylesheet : string | null = null ;
5665 private cachedLocale : string | null = null ;
@@ -60,7 +69,10 @@ export class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, UIState,
6069 private i18nCleanup : ( ( ) => void ) | null = null ;
6170
6271 // Events
63- private readonly categoryChanged$ = createBehaviorEmitter < { disabledCategories : string [ ] } > ( ) ;
72+ private readonly categoryChanged$ = createBehaviorEmitter < {
73+ disabledCategories : string [ ] ;
74+ hiddenItems : string [ ] ;
75+ } > ( ) ;
6476 private readonly stylesheetInvalidated$ = createEmitter < void > ( ) ;
6577
6678 private readonly toolbarChanged$ = createScopedEmitter <
@@ -90,9 +102,15 @@ export class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, UIState,
90102 this . schema = config . schema ;
91103 this . stylesheetConfig = config . stylesheetConfig || { } ;
92104
105+ // Extract item categories for computing hidden items
106+ this . itemCategories = extractItemCategories ( this . schema ) ;
107+
93108 // Initialize disabled categories from config
94109 if ( config . disabledCategories ?. length ) {
95110 this . dispatch ( setDisabledCategories ( config . disabledCategories ) ) ;
111+ // Also compute and dispatch hidden items
112+ const hiddenItems = computeHiddenItems ( this . itemCategories , config . disabledCategories ) ;
113+ this . dispatch ( setHiddenItems ( hiddenItems ) ) ;
96114 }
97115
98116 this . i18n = registry . getPlugin < I18nPlugin > ( 'i18n' ) ?. provides ( ) ?? null ;
@@ -206,17 +224,23 @@ export class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, UIState,
206224 const current = new Set ( this . state . disabledCategories ) ;
207225 if ( ! current . has ( category ) ) {
208226 current . add ( category ) ;
209- this . dispatch ( setDisabledCategories ( Array . from ( current ) ) ) ;
210- this . categoryChanged$ . emit ( { disabledCategories : Array . from ( current ) } ) ;
227+ const categories = Array . from ( current ) ;
228+ this . dispatch ( setDisabledCategories ( categories ) ) ;
229+ const hiddenItems = computeHiddenItems ( this . itemCategories , categories ) ;
230+ this . dispatch ( setHiddenItems ( hiddenItems ) ) ;
231+ this . categoryChanged$ . emit ( { disabledCategories : categories , hiddenItems } ) ;
211232 }
212233 }
213234
214235 private enableCategoryImpl ( category : string ) : void {
215236 const current = new Set ( this . state . disabledCategories ) ;
216237 if ( current . has ( category ) ) {
217238 current . delete ( category ) ;
218- this . dispatch ( setDisabledCategories ( Array . from ( current ) ) ) ;
219- this . categoryChanged$ . emit ( { disabledCategories : Array . from ( current ) } ) ;
239+ const categories = Array . from ( current ) ;
240+ this . dispatch ( setDisabledCategories ( categories ) ) ;
241+ const hiddenItems = computeHiddenItems ( this . itemCategories , categories ) ;
242+ this . dispatch ( setHiddenItems ( hiddenItems ) ) ;
243+ this . categoryChanged$ . emit ( { disabledCategories : categories , hiddenItems } ) ;
220244 }
221245 }
222246
@@ -230,7 +254,10 @@ export class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, UIState,
230254
231255 private setDisabledCategoriesImpl ( categories : string [ ] ) : void {
232256 this . dispatch ( setDisabledCategories ( categories ) ) ;
233- this . categoryChanged$ . emit ( { disabledCategories : categories } ) ;
257+ // Compute and dispatch hidden items based on disabled categories
258+ const hiddenItems = computeHiddenItems ( this . itemCategories , categories ) ;
259+ this . dispatch ( setHiddenItems ( hiddenItems ) ) ;
260+ this . categoryChanged$ . emit ( { disabledCategories : categories , hiddenItems } ) ;
234261 }
235262
236263 // ─────────────────────────────────────────────────────────
@@ -268,6 +295,7 @@ export class UIPlugin extends BasePlugin<UIPluginConfig, UICapability, UIState,
268295 setDisabledCategories : ( categories ) => this . setDisabledCategoriesImpl ( categories ) ,
269296 getDisabledCategories : ( ) => this . state . disabledCategories ,
270297 isCategoryDisabled : ( category ) => this . state . disabledCategories . includes ( category ) ,
298+ getHiddenItems : ( ) => this . state . hiddenItems ,
271299
272300 // Events
273301 onToolbarChanged : this . toolbarChanged$ . onGlobal ,
0 commit comments