Skip to content

Commit 4abb0c2

Browse files
committed
Broadcast common CSS classes to components
Integrated event-based broadcasting to share common CSS classes across modal-related components. Replaced direct class addition with event listeners to enhance modularity and flexibility. This facilitates easier maintenance and further customization of component behavior.
1 parent 0692765 commit 4abb0c2

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/libs/Modals/Modal/Modal.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ImplementsStatic } from 'src/classes/decorators/ImplementsStatic';
22
import type { ILogger, ILogger_ } from 'src/interfaces/ILogger';
3+
import { broadcastEvent, DIComponent } from 'src/libs/DIComponent';
34
import type { IFlow_, IFlowApi } from 'src/libs/HTMLFlow/interfaces/IFlow';
45
import { Opts } from 'src/libs/HTMLFlow/Opts';
56
import { IFlowConfig } from 'src/libs/HTMLFlow/types/IFlowDelegates';
@@ -22,7 +23,6 @@ import {
2223
IOpenCallback,
2324
IShouldOpenCallback,
2425
} from './types/IModalCallbacks';
25-
import { DIComponent } from '../../DIComponent/DIComponent';
2626

2727
/**
2828
* Represents a custom modal, which can be dragged around
@@ -233,6 +233,15 @@ export class Modal extends DIComponent implements IModal, IModalFluentApi {
233233
*/
234234
public override onload(): void {
235235
this._open();
236+
237+
/**
238+
* Broadcast the common window classes to the plugin.
239+
*/
240+
if (this._draggableElement?.className != null) {
241+
this[broadcastEvent]('common-window-classes', [
242+
this._draggableElement.className,
243+
]);
244+
}
236245
}
237246

238247
/**

src/libs/Settings/SettingColumns/Input.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import createFuzzySearch from '@nozbe/microfuzz';
22
import { ImplementsStatic } from 'src/classes/decorators/ImplementsStatic';
33
import type { IApp } from 'src/interfaces/IApp';
44
import type { ILogger, ILogger_ } from 'src/interfaces/ILogger';
5+
import { onEvent } from 'src/libs/DIComponent';
56
import { DIComponent } from 'src/libs/DIComponent/DIComponent';
67
import type { IFlow_, IFlowApi } from 'src/libs/HTMLFlow/interfaces/IFlow';
78
import { Opts } from 'src/libs/HTMLFlow/Opts';
@@ -154,15 +155,6 @@ export class Input
154155
)(input).map((result) => result.item.value);
155156
},
156157
);
157-
158-
const draggableClassName =
159-
this.parentSettingItem?.parentModal?.draggableClassName;
160-
161-
if (draggableClassName != null) {
162-
this._suggester.suggestContainerEl?.classList.add(
163-
draggableClassName,
164-
);
165-
}
166158
}
167159

168160
public readonly parentSettingItem: ISettingRowProtected;
@@ -198,6 +190,13 @@ export class Input
198190
);
199191

200192
this.addChild(flow);
193+
194+
/**
195+
* Adds the common window classes to the suggester container.
196+
*/
197+
this[onEvent]('common-window-classes', (classes: string[]) => {
198+
this._suggester?.suggestContainerEl?.classList.add(...classes);
199+
});
201200
}
202201

203202
/**

src/libs/Settings/SettingColumns/TagSearch.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import createFuzzySearch from '@nozbe/microfuzz';
22
import { LazzyLoading } from 'src/classes/decorators/LazzyLoading';
33
import type { IApp } from 'src/interfaces/IApp';
44
import type { ILogger_, ILogger } from 'src/interfaces/ILogger';
5+
import { onEvent } from 'src/libs/DIComponent';
56
import { DIComponent } from 'src/libs/DIComponent/DIComponent';
67
import type { ITag, ITag_ } from 'src/libs/Tags/interfaces/ITag';
78
import type { ITags, ITags_ } from 'src/libs/Tags/interfaces/ITags';
@@ -149,6 +150,13 @@ export class TagSearch
149150
public override onload(): void {
150151
this._configurator?.(this);
151152
this.build();
153+
154+
/**
155+
* Adds the common window classes to the suggester container.
156+
*/
157+
this[onEvent]('common-window-classes', (classes: string[]) => {
158+
this._suggester?.suggestContainerEl?.classList.add(...classes);
159+
});
152160
}
153161

154162
/**
@@ -226,15 +234,6 @@ export class TagSearch
226234
return filteredItems;
227235
},
228236
);
229-
230-
const draggableClassName =
231-
this.parentSettingItem?.parentModal?.draggableClassName;
232-
233-
if (draggableClassName != null) {
234-
this._suggester.suggestContainerEl?.classList.add(
235-
draggableClassName,
236-
);
237-
}
238237
}
239238
}
240239

0 commit comments

Comments
 (0)