feat: add profile language preferences and refine toast, dropdown and history UI
This commit is contained in:
+14
-12
@@ -7,11 +7,13 @@
|
||||
* See LICENSE file in repository root for details.
|
||||
*/
|
||||
|
||||
import { t } from "@rustpad/i18n";
|
||||
|
||||
function selection(editor) {
|
||||
return { start: editor.selectionStart, end: editor.selectionEnd };
|
||||
}
|
||||
|
||||
function toggleWrap(editor, before, after = before, placeholder = "tekst") {
|
||||
function toggleWrap(editor, before, after = before, placeholder = t("editor.format.text", {}, "text")) {
|
||||
let { start, end } = selection(editor);
|
||||
const value = editor.value;
|
||||
const selected = value.slice(start, end);
|
||||
@@ -65,15 +67,15 @@ export function applyFormat(editor, format) {
|
||||
if (format === "number") togglePrefix(editor, index => `${index + 1}. `);
|
||||
if (format === "task") togglePrefix(editor, "- [ ] ");
|
||||
if (format === "quote") togglePrefix(editor, "> ");
|
||||
if (format === "link") toggleWrap(editor, "[", "](https://)", "description");
|
||||
if (format === "inline-code") toggleWrap(editor, "`", "`", "code");
|
||||
if (format === "highlight") toggleWrap(editor, "==", "==", "important");
|
||||
if (format === "link") toggleWrap(editor, "[", "](https://)", t("editor.format.description", {}, "description"));
|
||||
if (format === "inline-code") toggleWrap(editor, "`", "`", t("editor.format.code", {}, "code"));
|
||||
if (format === "highlight") toggleWrap(editor, "==", "==", t("editor.format.important", {}, "important"));
|
||||
if (format === "subscript") toggleWrap(editor, "~", "~", "2");
|
||||
if (format === "superscript") toggleWrap(editor, "^", "^", "2");
|
||||
if (format === "codeblock") toggleWrap(editor, "```text\n", "\n```", "code");
|
||||
if (format === "codeblock-lines") toggleWrap(editor, "```text=\n", "\n```", "code");
|
||||
if (format === "mermaid") toggleWrap(editor, "```mermaid\n", "\n```", "graph TD\n A[Start] --> B[End]");
|
||||
if (format === "details") toggleWrap(editor, "<details>\n<summary>Click me</summary>\n\n", "\n</details>", "Content");
|
||||
if (format === "codeblock") toggleWrap(editor, "```text\n", "\n```", t("editor.format.code", {}, "code"));
|
||||
if (format === "codeblock-lines") toggleWrap(editor, "```text=\n", "\n```", t("editor.format.code", {}, "code"));
|
||||
if (format === "mermaid") toggleWrap(editor, "```mermaid\n", "\n```", t("editor.format.diagram", {}, "graph TD\n A[Start] --> B[End]"));
|
||||
if (format === "details") toggleWrap(editor, `<details>\n<summary>${t("editor.format.detailsSummary", {}, "Click me")}</summary>\n\n`, "\n</details>", t("editor.format.content", {}, "Content"));
|
||||
if (format === "toc") {
|
||||
const { start, end } = selection(editor);
|
||||
const selected = editor.value.slice(start, end);
|
||||
@@ -81,11 +83,11 @@ export function applyFormat(editor, format) {
|
||||
}
|
||||
if (format.startsWith("alert-")) {
|
||||
const type = format.slice("alert-".length);
|
||||
toggleWrap(editor, `:::${type}\n`, "\n:::", "Alert content");
|
||||
toggleWrap(editor, `:::${type}\n`, "\n:::", t("editor.format.alertContent", {}, "Alert content"));
|
||||
}
|
||||
if (format === "table") toggleWrap(editor, "| Column 1 | Column 2 |\n| --- | --- |\n| ", " | value |", "value");
|
||||
if (format === "footnote") toggleWrap(editor, "", "[^1]\n\n[^1]: Footnote text", "Text with footnote");
|
||||
if (format === "definition") toggleWrap(editor, "", "\n: Definition", "Term");
|
||||
if (format === "table") toggleWrap(editor, `| ${t("editor.format.column1", {}, "Column 1")} | ${t("editor.format.column2", {}, "Column 2")} |\n| --- | --- |\n| `, ` | ${t("editor.format.value", {}, "value")} |`, t("editor.format.value", {}, "value"));
|
||||
if (format === "footnote") toggleWrap(editor, "", `[^1]\n\n[^1]: ${t("editor.format.footnote", {}, "Footnote text")}`, t("editor.format.textWithFootnote", {}, "Text with footnote"));
|
||||
if (format === "definition") toggleWrap(editor, "", `\n: ${t("editor.format.definition", {}, "Definition")}`, t("editor.format.term", {}, "Term"));
|
||||
if (format === "horizontal-rule") toggleWrap(editor, "\n---\n", "", "");
|
||||
editor.focus();
|
||||
editor.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
|
||||
Reference in New Issue
Block a user