mirror of
https://github.com/ankitects/anki.git
synced 2025-11-10 22:57:11 -05:00
Remove TagInputEdit and TagInputNew
This commit is contained in:
parent
f056851c1e
commit
64a2ead2ca
6 changed files with 17 additions and 82 deletions
|
|
@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
let className = "";
|
let className = "";
|
||||||
export { className as class };
|
export { className as class };
|
||||||
export let tooltip: string | undefined;
|
export let tooltip: string | undefined = undefined;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { createEventDispatcher } from "svelte";
|
import { createEventDispatcher } from "svelte";
|
||||||
import Badge from "components/Badge.svelte";
|
import Badge from "components/Badge.svelte";
|
||||||
import TagInputEdit from "./TagInputEdit.svelte";
|
import TagInput from "./TagInput.svelte";
|
||||||
import { deleteIcon } from "./icons";
|
import { deleteIcon } from "./icons";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
|
@ -13,11 +13,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
let active = false;
|
let active = false;
|
||||||
|
let input: HTMLInputElement;
|
||||||
|
|
||||||
function checkForActivation(): void {
|
function checkForActivation(): void {
|
||||||
const selection = window.getSelection()!;
|
const selection = window.getSelection()!;
|
||||||
if (selection.isCollapsed) {
|
if (selection.isCollapsed) {
|
||||||
active = true;
|
active = true;
|
||||||
|
input.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,10 +34,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if active}
|
{#if active}
|
||||||
<TagInputEdit
|
<TagInput
|
||||||
bind:name
|
bind:name
|
||||||
|
bind:input
|
||||||
on:focusout={() => (active = false)}
|
on:focusout={() => (active = false)}
|
||||||
on:update={updateTag}
|
on:update={updateTag}
|
||||||
|
on:mount={(event) => event.detail.input.focus()}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<span
|
<span
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import StickyBottom from "components/StickyBottom.svelte";
|
import StickyBottom from "components/StickyBottom.svelte";
|
||||||
import AddTagBadge from "./AddTagBadge.svelte";
|
import AddTagBadge from "./AddTagBadge.svelte";
|
||||||
import Tag from "./Tag.svelte";
|
import Tag from "./Tag.svelte";
|
||||||
import TagInputNew from "./TagInputNew.svelte";
|
import TagInput from "./TagInput.svelte";
|
||||||
|
|
||||||
export let tags = ["en::foobar", "zh::あっちこっち"];
|
export let tags = ["en::foobar", "zh::あっちこっち"];
|
||||||
|
|
||||||
let tagInputNew: HTMLInputElement;
|
let tagInputNew: HTMLInputElement;
|
||||||
let inputNew = false;
|
let newName: string = "";
|
||||||
|
|
||||||
function focusInputNew(): void {
|
function focusInputNew(): void {
|
||||||
inputNew = true;
|
|
||||||
tagInputNew.focus();
|
tagInputNew.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,9 +31,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<Tag name={tag} on:tagdelete={deleteTag} />
|
<Tag name={tag} on:tagdelete={deleteTag} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<div d-none={!inputNew}>
|
<TagInput bind:input={tagInputNew} name={newName} />
|
||||||
<TagInputNew bind:input={tagInputNew} on:blur={() => (inputNew = false)} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</StickyBottom>
|
</StickyBottom>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { createEventDispatcher } from "svelte";
|
import type Dropdown from "bootstrap/js/dist/dropdown";
|
||||||
import TagAutocomplete from "./TagAutocomplete.svelte";
|
|
||||||
|
import { createEventDispatcher, onMount } from "svelte";
|
||||||
import { normalizeTagname } from "./tags";
|
import { normalizeTagname } from "./tags";
|
||||||
|
|
||||||
import type Dropdown from "bootstrap/js/dist/dropdown";
|
import TagAutocomplete from "./TagAutocomplete.svelte";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
export let input: HTMLInputElement;
|
export let input: HTMLInputElement;
|
||||||
|
|
@ -56,6 +57,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
function setTagname({ detail }: CustomEvent): void {
|
function setTagname({ detail }: CustomEvent): void {
|
||||||
name = detail.name;
|
name = detail.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => dispatch("mount", { input }));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<TagAutocomplete
|
<TagAutocomplete
|
||||||
|
|
@ -68,9 +71,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
>
|
>
|
||||||
<label id={triggerId} class={`ps-2 pe-1 ${triggerClass}`} data-value={name}>
|
<label id={triggerId} class={`ps-2 pe-1 ${triggerClass}`} data-value={name}>
|
||||||
<input
|
<input
|
||||||
|
bind:this={input}
|
||||||
type="text"
|
type="text"
|
||||||
size="1"
|
size="1"
|
||||||
bind:this={input}
|
|
||||||
bind:value={name}
|
bind:value={name}
|
||||||
on:focus={(event) => onFocus(event, dropdown)}
|
on:focus={(event) => onFocus(event, dropdown)}
|
||||||
on:blur={(event) => dropdownBlur(event, dropdown)}
|
on:blur={(event) => dropdownBlur(event, dropdown)}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<script lang="typescript">
|
|
||||||
import { onMount } from "svelte";
|
|
||||||
import TagInput from "./TagInput.svelte";
|
|
||||||
|
|
||||||
export let name: string;
|
|
||||||
|
|
||||||
let input: HTMLInputElement;
|
|
||||||
|
|
||||||
function moveCursorToEnd(element: HTMLInputElement): void {
|
|
||||||
element.selectionStart = element.selectionEnd = element.value.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
// Make sure Autocomplete was fully mounted
|
|
||||||
setTimeout(() => {
|
|
||||||
moveCursorToEnd(input);
|
|
||||||
input.focus();
|
|
||||||
}, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
function onKeydown(): void {
|
|
||||||
console.log("onkeydown");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* function stopPropagation(event: Event): void { */
|
|
||||||
/* event.stopPropagation(); */
|
|
||||||
/* } */
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<TagInput bind:name bind:input on:keydown={onKeydown} on:focusout on:update on:add />
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<script lang="typescript">
|
|
||||||
import { createEventDispatcher } from "svelte";
|
|
||||||
import TagInput from "./TagInput.svelte";
|
|
||||||
|
|
||||||
export let input: HTMLInputElement;
|
|
||||||
|
|
||||||
let name = "";
|
|
||||||
let active = true;
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
function onKeydown(): void {
|
|
||||||
console.log("onkeydown");
|
|
||||||
}
|
|
||||||
|
|
||||||
function translateToAdd({ detail }: CustomEvent): void {
|
|
||||||
if (name) {
|
|
||||||
dispatch("add", detail);
|
|
||||||
name = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<TagInput
|
|
||||||
bind:name
|
|
||||||
bind:input
|
|
||||||
on:keydown={onKeydown}
|
|
||||||
on:add
|
|
||||||
on:update={translateToAdd}
|
|
||||||
on:blur
|
|
||||||
/>
|
|
||||||
Loading…
Reference in a new issue