2023-11-17 20:51:13 +03:00
|
|
|
/**
|
2023-12-26 14:23:51 +03:00
|
|
|
* Module: API for miscellaneous frontend model types. Future targets for refactoring aimed at extracting modules.
|
2023-11-17 20:51:13 +03:00
|
|
|
*/
|
2024-03-26 12:49:38 +03:00
|
|
|
import { DependencyMode, FontStyle, ILibraryFilter, LibraryFilterStrategy } from './miscellaneous';
|
2023-11-17 20:51:13 +03:00
|
|
|
import { IConstituenta, IRSForm } from './rsform';
|
|
|
|
|
2024-03-26 12:49:38 +03:00
|
|
|
/**
|
|
|
|
* Create style name from {@link FontStyle}.
|
|
|
|
*/
|
|
|
|
export function getFontClassName(style: FontStyle): string {
|
|
|
|
return `font-${style}`;
|
|
|
|
}
|
|
|
|
|
2023-11-17 20:51:13 +03:00
|
|
|
/**
|
2024-03-18 16:21:39 +03:00
|
|
|
* Filter list of {@link ILibraryItem} to a given graph query.
|
2023-11-17 20:51:13 +03:00
|
|
|
*/
|
|
|
|
export function applyGraphFilter(target: IRSForm, start: number, mode: DependencyMode): IConstituenta[] {
|
|
|
|
if (mode === DependencyMode.ALL) {
|
2023-12-28 14:04:44 +03:00
|
|
|
return target.items;
|
2023-11-17 20:51:13 +03:00
|
|
|
}
|
2024-03-18 16:21:39 +03:00
|
|
|
const ids: number[] | undefined = (() => {
|
|
|
|
switch (mode) {
|
|
|
|
case DependencyMode.OUTPUTS: {
|
|
|
|
return target.graph.nodes.get(start)?.outputs;
|
|
|
|
}
|
|
|
|
case DependencyMode.INPUTS: {
|
|
|
|
return target.graph.nodes.get(start)?.inputs;
|
|
|
|
}
|
|
|
|
case DependencyMode.EXPAND_OUTPUTS: {
|
|
|
|
return target.graph.expandOutputs([start]);
|
|
|
|
}
|
|
|
|
case DependencyMode.EXPAND_INPUTS: {
|
|
|
|
return target.graph.expandInputs([start]);
|
|
|
|
}
|
2023-12-28 14:04:44 +03:00
|
|
|
}
|
2024-03-18 16:21:39 +03:00
|
|
|
return undefined;
|
|
|
|
})();
|
|
|
|
if (ids) {
|
|
|
|
return target.items.filter(cst => ids.find(id => id === cst.id));
|
2023-11-17 20:51:13 +03:00
|
|
|
} else {
|
2024-03-18 16:21:39 +03:00
|
|
|
return target.items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter list of {@link ILibraryItem} to a given text query.
|
|
|
|
*/
|
|
|
|
export function filterFromStrategy(strategy: LibraryFilterStrategy): ILibraryFilter {
|
|
|
|
// prettier-ignore
|
|
|
|
switch (strategy) {
|
|
|
|
case LibraryFilterStrategy.MANUAL: return {};
|
|
|
|
case LibraryFilterStrategy.COMMON: return { is_common: true };
|
|
|
|
case LibraryFilterStrategy.CANONICAL: return { is_canonical: true };
|
|
|
|
case LibraryFilterStrategy.PERSONAL: return { is_personal: true };
|
|
|
|
case LibraryFilterStrategy.SUBSCRIBE: return { is_subscribed: true };
|
|
|
|
case LibraryFilterStrategy.OWNED: return { is_owned: true };
|
2023-11-17 20:51:13 +03:00
|
|
|
}
|
2023-12-28 14:04:44 +03:00
|
|
|
}
|