diff --git a/ts/editor/Tag.svelte b/ts/editor/Tag.svelte index e9d4ac49e..f5cb51f5d 100644 --- a/ts/editor/Tag.svelte +++ b/ts/editor/Tag.svelte @@ -4,20 +4,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> {#if active} - active! + (active = false)} /> {:else} - - + (active = true)} + > + {name} {@html deleteIcon} {/if} diff --git a/ts/editor/TagAutocomplete.svelte b/ts/editor/TagAutocomplete.svelte new file mode 100644 index 000000000..921718a9d --- /dev/null +++ b/ts/editor/TagAutocomplete.svelte @@ -0,0 +1,98 @@ + + + + + + diff --git a/ts/editor/TagEditor.svelte b/ts/editor/TagEditor.svelte index c5f7be7e1..6d6dcfe86 100644 --- a/ts/editor/TagEditor.svelte +++ b/ts/editor/TagEditor.svelte @@ -6,24 +6,37 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import StickyBottom from "components/StickyBottom.svelte"; import Badge from "components/Badge.svelte"; import Tag from "./Tag.svelte"; + import TagInputNew from "./TagInputNew.svelte"; import { tagIcon } from "./icons"; + + export let tags = ["en::foobar", "zh::あっちこっち"]; + + let tagInputNew: HTMLInputElement; + let inputNew = false; + + function focusTagInputNew(): void { + inputNew = true; + tagInputNew.focus(); + } -
+
{@html tagIcon} - en::foobar - zh::あちこ + + {#each tags as tag} + + {/each} + + {#if inputNew} + (inputNew = false)} /> + {/if}
diff --git a/ts/editor/TagInput.svelte b/ts/editor/TagInput.svelte new file mode 100644 index 000000000..f9ef3d167 --- /dev/null +++ b/ts/editor/TagInput.svelte @@ -0,0 +1,108 @@ + + + + + + + + diff --git a/ts/editor/TagInputEdit.svelte b/ts/editor/TagInputEdit.svelte new file mode 100644 index 000000000..2c3c3328f --- /dev/null +++ b/ts/editor/TagInputEdit.svelte @@ -0,0 +1,42 @@ + + + + diff --git a/ts/editor/TagInputNew.svelte b/ts/editor/TagInputNew.svelte new file mode 100644 index 000000000..ab76633c3 --- /dev/null +++ b/ts/editor/TagInputNew.svelte @@ -0,0 +1,35 @@ + + + + diff --git a/ts/editor/tags.ts b/ts/editor/tags.ts new file mode 100644 index 000000000..301b2fd96 --- /dev/null +++ b/ts/editor/tags.ts @@ -0,0 +1,16 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +export function normalizeTagname(tagname: string): string { + let trimmed = tagname.trim(); + + while (true) { + if (trimmed.startsWith("::")) { + trimmed = trimmed.slice(2).trimStart(); + } else if (trimmed.endsWith("::")) { + trimmed = trimmed.slice(0, -2).trimEnd(); + } else { + return trimmed; + } + } +} diff --git a/ts/tsconfig.json b/ts/tsconfig.json index 91321c08f..0ef8d4f23 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -8,6 +8,7 @@ "es2019.array", "es2018.promise", "es2020.promise", + "es2019.string", "dom", "dom.iterable" ],