fix eslint and prettier

This commit is contained in:
delta 2023-05-07 15:01:04 +02:00
parent a50ae94eb1
commit 7bfed967d0
5 changed files with 98 additions and 39 deletions

View file

@ -1,6 +1,6 @@
{
"printWidth": 100,
"tabWidth": 2,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,

View file

@ -23,6 +23,7 @@
"license": "GPL-3.0-or-later",
"devDependencies": {
"@types/node": "^18.16.5",
"@types/react": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"eslint": "^8.40.0",

View file

@ -4,6 +4,9 @@ devDependencies:
'@types/node':
specifier: ^18.16.5
version: 18.16.5
'@types/react':
specifier: ^18.2.6
version: 18.2.6
'@typescript-eslint/eslint-plugin':
specifier: ^5.59.2
version: 5.59.2(@typescript-eslint/parser@5.59.2)(eslint@8.40.0)(typescript@5.0.4)
@ -1433,6 +1436,22 @@ packages:
resolution: {integrity: sha512-seOA34WMo9KB+UA78qaJoCO20RJzZGVXQ5Sh6FWu0g/hfT44nKXnej3/tCQl7FL97idFpBhisLYCTB50S0EirA==}
dev: true
/@types/prop-types@15.7.5:
resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==}
dev: true
/@types/react@18.2.6:
resolution: {integrity: sha512-wRZClXn//zxCFW+ye/D2qY65UsYP1Fpex2YXorHc8awoNamkMZSvBxwxdYVInsHOZZd2Ppq8isnSzJL5Mpf8OA==}
dependencies:
'@types/prop-types': 15.7.5
'@types/scheduler': 0.16.3
csstype: 3.1.2
dev: true
/@types/scheduler@0.16.3:
resolution: {integrity: sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==}
dev: true
/@types/semver@7.3.13:
resolution: {integrity: sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==}
dev: true
@ -1995,6 +2014,10 @@ packages:
css-tree: 1.1.3
dev: true
/csstype@3.1.2:
resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==}
dev: true
/data-uri-to-buffer@4.0.1:
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
engines: {node: '>= 12'}

View file

@ -1,12 +1,12 @@
import { components, util, common } from "replugged";
import { cfg, logger, macroPrefix } from "./index.ts";
import { cfg, macroPrefix, Macros } from "./index";
import "./Settings.css";
const { FormItem, TextArea, TextInput, Category, Text, Button, Divider, FormNotice } = components;
const { React, lodash } = common;
// from https://stackoverflow.com/a/55387306
const interleave = (arr: any[], x: any) => arr.flatMap(e => [e, x]).slice(0, -1)
const interleave = (arr: any[], x: any) => arr.flatMap((e) => [e, x]).slice(0, -1);
function swap(arr: any[], a: any, b: any) {
let tmp = arr.slice();
@ -14,53 +14,70 @@ function swap(arr: any[], a: any, b: any) {
return tmp;
}
function Macro({ macro, expansion, id, macros, setMacros }) {
let idx = lodash.findIndex(macros, ["id", id])
function Macro({
macro,
expansion,
id,
macros,
setMacros,
}: {
macro: string;
expansion: string;
id: string;
macros: Macros;
setMacros: (macros: Macros) => void;
}) {
let idx = lodash.findIndex(macros, ["id", id]);
function handleClick() {
setMacros(lodash.reject(macros, ["id", id]))
setMacros(lodash.reject(macros, ["id", id]));
}
function handleDownSwap() {
setMacros(swap(macros, idx, idx + 1))
setMacros(swap(macros, idx, idx + 1));
}
function handleUpSwap() {
setMacros(swap(macros, idx, idx - 1))
setMacros(swap(macros, idx, idx - 1));
}
return (
<div className="macro">
<div className="macro-inner">
<Text variant="heading-lg/semibold" className="macro-name" selectable={true}>
{ macro }
{macro}
</Text>
{idx !== macros.length - 1 &&
{idx !== macros.length - 1 && (
<Button className="down-button" onClick={handleDownSwap}>
Down
</Button>
}
{idx !== 0 &&
)}
{idx !== 0 && (
<Button className="up-button" onClick={handleUpSwap}>
Up
</Button>
}
)}
<Button color={Button.Colors.RED} onClick={handleClick}>
Delete
</Button>
</div>
<Divider className="divider-inner" />
<Text.Normal className="macro-expansion" selectable={true}>
{ expansion }
{expansion}
</Text.Normal>
</div>
)
);
}
function CreateMacro({ macros, setMacros }) {
function CreateMacro({
macros,
setMacros,
}: {
macros: Macros;
setMacros: (macros: Macros) => void;
}) {
const [macro, setMacro] = React.useState("");
const [expansion, setExpansion] = React.useState("");
function handleClick() {
if (macro.length < 1 || expansion.length < 1) {
@ -80,12 +97,20 @@ function CreateMacro({ macros, setMacros }) {
<TextArea value={expansion} onChange={(content: string) => setExpansion(content)} />
</FormItem>
<div>
{ macro.length < 1 ? <FormNotice body="Macro must be at least one character long" className="form-notice" /> : null }
{ expansion.length < 1 ? <FormNotice body="Expansion must be at least one character long" className="form-notice" /> : null }
{macro.length < 1 ? (
<FormNotice
body="Macro must be at least one character long"
className="form-notice"
/>
) : null}
{expansion.length < 1 ? (
<FormNotice
body="Expansion must be at least one character long"
className="form-notice"
/>
) : null}
</div>
<Button onClick={handleClick}>
Create
</Button>
<Button onClick={handleClick}>Create</Button>
</>
);
}
@ -99,11 +124,14 @@ export function Settings() {
<TextInput {...util.useSetting(cfg, "prefix")} placeholder={macroPrefix} />
</FormItem>
<Divider className="divider-default" />
<CreateMacro macros={macros} setMacros={setMacros}/>
<CreateMacro macros={macros} setMacros={setMacros} />
<Divider className="divider-default" />
<Category title="Macros">
{interleave(macros.map(e => <Macro {...e} macros={macros} setMacros={setMacros} />), <Divider className="divider-inner" />)}
{interleave(
macros.map((e) => <Macro {...e} macros={macros} setMacros={setMacros} />),
<Divider className="divider-inner" />,
)}
</Category>
</div>
);

View file

@ -1,34 +1,41 @@
import { Injector, Logger, webpack, settings } from "replugged";
import { Injector, Logger, settings, types, webpack } from "replugged";
const inject = new Injector();
export const logger = Logger.plugin("MMM");
export const macroPrefix = "^";
export type Macros = Array<{ macro: string; expansion: string; id: string }>;
interface Settings {
macros?: { macro: string, expansion: string, id: string }[],
prefix?: string
macros?: Macros;
prefix?: string;
}
const defaultSettings = {
macros: [],
prefix: macroPrefix
} satisfies Partial<Settings>
prefix: macroPrefix,
} satisfies Partial<Settings>;
export const cfg = await settings.init<Settings, keyof typeof defaultSettings>("dev.delta.MMM", defaultSettings);
export const cfg = await settings.init<Settings, keyof typeof defaultSettings>(
"dev.delta.MMM",
defaultSettings,
);
export async function start(): Promise<void> {
const messageMod = await webpack.waitForProps("sendMessage", "getSendMessageOptionsForReply");
const messageMod = (await webpack.waitForProps("sendMessage")) as unknown as {
sendMessage: types.AnyFunction;
};
if (messageMod) {
inject.before(messageMod, "sendMessage", props => {
let content: string = props[1].content;
inject.before(messageMod, "sendMessage", (props) => {
let { content } = props[1];
let prefix = cfg.get("prefix") || macroPrefix;
cfg.get("macros").forEach(({ macro, expansion }) => {
let regex = RegExp(`(?<!\\\\)\\${prefix}${macro}`, "g")
content = content.replaceAll(regex, expansion)
})
props[1].content = content
return props
let regex = RegExp(`(?<!\\\\)\\${prefix}${macro}`, "g");
content = content.replaceAll(regex, expansion);
});
props[1].content = content;
return props;
});
}
}
@ -37,4 +44,4 @@ export function stop(): void {
inject.uninjectAll();
}
export { Settings } from "./Settings.tsx"
export { Settings } from "./Settings";