mirror of
https://github.com/Vendicated/Vencord
synced 2024-09-13 04:29:24 -04:00
renaming types and correcting grammar
This commit is contained in:
parent
5a2babb5c0
commit
574b7450f2
2 changed files with 30 additions and 23 deletions
|
@ -16,35 +16,42 @@ export interface Rule extends ParserRule {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Rules {
|
export interface SlateRule {
|
||||||
|
type: string;
|
||||||
|
after?: string;
|
||||||
|
before?: string;
|
||||||
|
[k: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ParserRules {
|
||||||
[k: string]: Rule;
|
[k: string]: Rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MarkDownRules {
|
export interface MarkdownRulesType {
|
||||||
RULES: Rules;
|
RULES: ParserRules;
|
||||||
CHANNEL_TOPIC_RULES: Rules;
|
CHANNEL_TOPIC_RULES: ParserRules;
|
||||||
VOICE_CHANNEL_STATUS_RULES: Rules;
|
VOICE_CHANNEL_STATUS_RULES: ParserRules;
|
||||||
EMBED_TITLE_RULES: Rules;
|
EMBED_TITLE_RULES: ParserRules;
|
||||||
INLINE_REPLY_RULES: Rules;
|
INLINE_REPLY_RULES: ParserRules;
|
||||||
GUILD_VERIFICATION_FORM_RULES: Rules;
|
GUILD_VERIFICATION_FORM_RULES: ParserRules;
|
||||||
GUILD_EVENT_RULES: Rules;
|
GUILD_EVENT_RULES: ParserRules;
|
||||||
PROFILE_BIO_RULES: Rules;
|
PROFILE_BIO_RULES: ParserRules;
|
||||||
AUTO_MODERATION_SYSTEM_MESSAGE_RULES: Rules;
|
AUTO_MODERATION_SYSTEM_MESSAGE_RULES: ParserRules;
|
||||||
NATIVE_SEARCH_RESULT_LINK_RULES: Rules;
|
NATIVE_SEARCH_RESULT_LINK_RULES: ParserRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PluginMarkDownRules = Partial<MarkDownRules>;
|
export type PluginMarkdownRulesType = Partial<MarkdownRulesType>;
|
||||||
|
|
||||||
export const Rules: MarkDownRules = {} as MarkDownRules;
|
export const MarkdownRules: MarkdownRulesType = {} as MarkdownRulesType;
|
||||||
|
|
||||||
export type PluginRulesFunction = (r: MarkDownRules) => MarkDownRules | PluginMarkDownRules;
|
export type PluginRulesFunction = (r: MarkdownRulesType) => MarkdownRulesType | PluginMarkdownRulesType;
|
||||||
|
|
||||||
const PendingRulesMap = new Map<string, PluginRulesFunction>();
|
const PendingRulesMap = new Map<string, PluginRulesFunction>();
|
||||||
|
|
||||||
export const AddAPendingRule = (name: string, rules: PluginRulesFunction) => PendingRulesMap.set(name, rules);
|
export const AddAPendingRule = (name: string, rules: PluginRulesFunction) => PendingRulesMap.set(name, rules);
|
||||||
export const RemoveAPendingRule = (name: string) => PendingRulesMap.delete(name);
|
export const RemoveAPendingRule = (name: string) => PendingRulesMap.delete(name);
|
||||||
|
|
||||||
export function patchMarkdownRules(originalRules: MarkDownRules) {
|
export function patchMarkdownRules(originalMarkdownRules: MarkdownRulesType) {
|
||||||
/**
|
/**
|
||||||
* patchs the markdown rules
|
* patchs the markdown rules
|
||||||
* by overwriting and/or adding each rule to the original rules entries
|
* by overwriting and/or adding each rule to the original rules entries
|
||||||
|
@ -58,24 +65,24 @@ export function patchMarkdownRules(originalRules: MarkDownRules) {
|
||||||
}
|
}
|
||||||
for (const [name, rule] of PendingRulesMap) {
|
for (const [name, rule] of PendingRulesMap) {
|
||||||
try {
|
try {
|
||||||
assignEntries(Rules, rule(originalRules));
|
assignEntries(MarkdownRules, rule(originalMarkdownRules));
|
||||||
RemoveAPendingRule(name);
|
RemoveAPendingRule(name);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to add Markdown rules for", name, e);
|
logger.error("Failed to add Markdown rules for", name, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assignEntries(originalRules, Rules);
|
assignEntries(originalMarkdownRules, MarkdownRules);
|
||||||
return originalRules;
|
return originalMarkdownRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function patchSlateRules(slate: any) {
|
export function patchSlateRules(slate: { [k: string]: SlateRule; }) {
|
||||||
/**
|
/**
|
||||||
* patchs the default slates
|
* patchs the default slates
|
||||||
* overwriting and/or adding each rule slate to the slate entries
|
* overwriting and/or adding each rule slate to the slate entries
|
||||||
* @param slate The original slate
|
* @param slate The original slate
|
||||||
* @returns The patched slate
|
* @returns The patched slate
|
||||||
*/
|
*/
|
||||||
for (const [name, rule] of Object.entries(Rules)) {
|
for (const [name, rule] of Object.entries(MarkdownRules)) {
|
||||||
slate[name] = rule.Slate ?? slate[name] ?? { type: "skip" };
|
slate[name] = rule.Slate ?? slate[name] ?? { type: "skip" };
|
||||||
}
|
}
|
||||||
return slate;
|
return slate;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import { Command } from "@api/Commands";
|
import { Command } from "@api/Commands";
|
||||||
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
import { NavContextMenuPatchCallback } from "@api/ContextMenu";
|
||||||
import { MarkDownRules, PluginMarkDownRules } from "@api/Markdown";
|
import { MarkdownRulesType, PluginMarkdownRulesType } from "@api/Markdown";
|
||||||
import { FluxEvents } from "@webpack/types";
|
import { FluxEvents } from "@webpack/types";
|
||||||
import { Promisable } from "type-fest";
|
import { Promisable } from "type-fest";
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ export interface PluginDef {
|
||||||
/**
|
/**
|
||||||
* Allows you to add custom Rules to markdown
|
* Allows you to add custom Rules to markdown
|
||||||
*/
|
*/
|
||||||
rules?(r: MarkDownRules): PluginMarkDownRules;
|
rules?(r: MarkdownRulesType): PluginMarkdownRulesType;
|
||||||
|
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue