Rework documentation URLs as inline markdown. Redesign documentations with markdown text. Redesign way to document scripts/categories and present the documentation. Documentation is showed in an expandable box instead of tooltip. This is to allow writing longer documentation (tooltips are meant to be used for short text) and have better experience on mobile. If a node (script/category) has documentation it's now shown with single information icon (ℹ) aligned to right. Add support for rendering documentation as markdown. It automatically converts plain URLs to URLs with display names (e.g. https://docs.microsoft.com/..) will be rendered automatically like "docs.microsoft.com - Windows 11 Privacy...".
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
|
import { ICategory, IScript } from '@/domain/ICategory';
|
|
import { ScriptStub } from './ScriptStub';
|
|
|
|
export class CategoryStub extends BaseEntity<number> implements ICategory {
|
|
public name = `category-with-id-${this.id}`;
|
|
|
|
public readonly subCategories = new Array<ICategory>();
|
|
|
|
public readonly scripts = new Array<IScript>();
|
|
|
|
public readonly docs = new Array<string>();
|
|
|
|
public constructor(id: number) {
|
|
super(id);
|
|
}
|
|
|
|
public includes(script: IScript): boolean {
|
|
return this.getAllScriptsRecursively().some((s) => s.id === script.id);
|
|
}
|
|
|
|
public getAllScriptsRecursively(): readonly IScript[] {
|
|
return [
|
|
...this.scripts,
|
|
...this.subCategories.flatMap((c) => c.getAllScriptsRecursively()),
|
|
];
|
|
}
|
|
|
|
public withScriptIds(...scriptIds: string[]): CategoryStub {
|
|
return this.withScripts(
|
|
...scriptIds.map((id) => new ScriptStub(id)),
|
|
);
|
|
}
|
|
|
|
public withScripts(...scripts: IScript[]): CategoryStub {
|
|
for (const script of scripts) {
|
|
this.withScript(script);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public withCategories(...categories: ICategory[]): CategoryStub {
|
|
for (const category of categories) {
|
|
this.withCategory(category);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public withCategory(category: ICategory): CategoryStub {
|
|
this.subCategories.push(category);
|
|
return this;
|
|
}
|
|
|
|
public withScript(script: IScript): CategoryStub {
|
|
this.scripts.push(script);
|
|
return this;
|
|
}
|
|
|
|
public withName(categoryName: string) {
|
|
this.name = categoryName;
|
|
return this;
|
|
}
|
|
}
|