From 4bbdca4d47d8d79a340d5a726f4cd060876f0465 Mon Sep 17 00:00:00 2001 From: Rajyavardhan Singh Date: Tue, 28 Oct 2025 19:10:25 +0530 Subject: [PATCH] impr: update custom generator based on feedback - Move presets to top and change to dropdown - Change character input to textarea - Remove special characters from bigrams/trigrams - Remove custom button styles --- frontend/src/html/popups.html | 25 +++--- frontend/src/styles/popups.scss | 40 ++-------- frontend/src/ts/modals/custom-generator.ts | 92 ++++++---------------- 3 files changed, 44 insertions(+), 113 deletions(-) diff --git a/frontend/src/html/popups.html b/frontend/src/html/popups.html index 0c1781f5b..d7a0c81bb 100644 --- a/frontend/src/html/popups.html +++ b/frontend/src/html/popups.html @@ -785,15 +785,26 @@
+
+
presets
+ +
character set
- + >
min length
@@ -827,16 +838,6 @@ title="word count" />
-
-
presets
-
- - - - - -
-
diff --git a/frontend/src/styles/popups.scss b/frontend/src/styles/popups.scss index 5febdad5a..ebce3ec61 100644 --- a/frontend/src/styles/popups.scss +++ b/frontend/src/styles/popups.scss @@ -481,33 +481,13 @@ body.darkMode { column-gap: 1rem; } - .presetButtons { - display: flex; - gap: 0.5rem; - flex-wrap: wrap; - - button { - padding: 0.5rem 1rem; - background: var(--sub-alt-color); - color: var(--sub-color); - border: none; - border-radius: var(--roundness); - cursor: pointer; - transition: all 0.125s; - - &:hover { - background: var(--sub-color); - color: var(--bg-color); - } - } - } - .tip { color: var(--sub-color); font-size: 0.8rem; } - input { + input, + textarea { width: 100%; padding: 0.5rem; background: var(--sub-alt-color); @@ -520,19 +500,9 @@ body.darkMode { } } - button.setButton, - button.addButton { - padding: 0.5rem 1rem; - background: var(--main-color); - color: var(--bg-color); - border: none; - border-radius: var(--roundness); - cursor: pointer; - transition: all 0.125s; - - &:hover { - filter: brightness(1.2); - } + textarea { + min-height: 100px; + resize: vertical; } } } diff --git a/frontend/src/ts/modals/custom-generator.ts b/frontend/src/ts/modals/custom-generator.ts index 83e593fe6..af4d91bdb 100644 --- a/frontend/src/ts/modals/custom-generator.ts +++ b/frontend/src/ts/modals/custom-generator.ts @@ -1,5 +1,6 @@ import * as CustomText from "../test/custom-text"; import * as Notifications from "../elements/notifications"; +import SlimSelect from "slim-select"; import AnimatedModal, { HideOptions, ShowOptions, @@ -46,36 +47,6 @@ const presets: Record = { "it", "al", "as", - "=>", - "::", - "//", - "/*", - "*/", - "{}", - "[]", - "()", - "<>", - "!=", - "==", - ">=", - "<=", - "&&", - "||", - "++", - "--", - "+=", - "-=", - "*=", - "/=", - "->", - ":=", - "??", - "?.", - "!.", - "..", - ";;", - ",,", - "|>", ], }, trigrams: { @@ -99,33 +70,38 @@ const presets: Record = { "are", "rea", "int", - "var", - "let", - "def", - "fun", - "str", - "obj", - "arr", - "new", - "try", - "ret", - "if(", - "(){", - "});", - "===", - "!==", - "...", - "/**", - "**/", - "```", - "---", ], }, }; +let _presetSelect: SlimSelect | undefined = undefined; + export async function show(showOptions?: ShowOptions): Promise { void modal.show({ ...showOptions, + beforeAnimation: async (modalEl) => { + _presetSelect = new SlimSelect({ + select: "#customGeneratorModal .presetInput", + settings: { + contentLocation: modalEl, + }, + events: { + afterChange: (newVal) => { + const presetName = newVal[0]?.value; + if ( + presetName !== undefined && + presetName !== "" && + presets[presetName] + ) { + const preset = presets[presetName]; + $("#customGeneratorModal .characterInput").val( + preset.characters.join(" ") + ); + } + }, + }, + }); + }, }); } @@ -191,22 +167,6 @@ async function apply(set: boolean): Promise { } async function setup(modalEl: HTMLElement): Promise { - for (const button of modalEl.querySelectorAll(".presetButton")) { - button.addEventListener("click", (e) => { - const presetName = (e.target as HTMLButtonElement).dataset["preset"]; - if ( - presetName !== undefined && - presetName !== "" && - presets[presetName] - ) { - const preset = presets[presetName]; - $("#customGeneratorModal .characterInput").val( - preset.characters.join(" ") - ); - } - }); - } - modalEl.querySelector(".setButton")?.addEventListener("click", () => { void apply(true); });