mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Add slide out animation to EditingArea, RichTextInput and PlainTextInput
only for collapsing, because it is choppy on expansion (common issue with Svelte transitions).
This commit is contained in:
parent
3dca559f88
commit
9a2b3410d0
3 changed files with 66 additions and 58 deletions
|
@ -51,6 +51,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
import { fontFamilyKey, fontSizeKey } from "../lib/context-keys";
|
||||
import FocusTrap from "./FocusTrap.svelte";
|
||||
import { slide } from "svelte/transition";
|
||||
|
||||
export let fontFamily: string;
|
||||
const fontFamilyStore = writable(fontFamily);
|
||||
|
@ -177,7 +178,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
<FocusTrap bind:this={focusTrap} on:focus={focusEditingInputInsteadIfAvailable} />
|
||||
|
||||
<div bind:this={editingArea} class="editing-area" on:focusout={trapFocusOnBlurOut}>
|
||||
<div
|
||||
bind:this={editingArea}
|
||||
class="editing-area"
|
||||
on:focusout={trapFocusOnBlurOut}
|
||||
out:slide={{ duration: 200 }}
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import { context as noteEditorContext } from "../NoteEditor.svelte";
|
||||
import removeProhibitedTags from "./remove-prohibited";
|
||||
import { storedToUndecorated, undecoratedToStored } from "./transform";
|
||||
import { slide } from "svelte/transition";
|
||||
|
||||
export let hidden: boolean;
|
||||
|
||||
|
@ -140,20 +141,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
setupLifecycleHooks(api);
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="plain-text-input"
|
||||
class:light-theme={!$pageTheme.isDark}
|
||||
class:hidden
|
||||
on:focusin={() => ($focusedInput = api)}
|
||||
>
|
||||
<CodeMirror
|
||||
{configuration}
|
||||
{code}
|
||||
{hidden}
|
||||
bind:api={codeMirror}
|
||||
on:change={onChange}
|
||||
/>
|
||||
</div>
|
||||
{#if !hidden}
|
||||
<div
|
||||
class="plain-text-input"
|
||||
class:light-theme={!$pageTheme.isDark}
|
||||
on:focusin={() => ($focusedInput = api)}
|
||||
out:slide={{ duration: 200 }}
|
||||
>
|
||||
<CodeMirror
|
||||
{configuration}
|
||||
{code}
|
||||
{hidden}
|
||||
bind:api={codeMirror}
|
||||
on:change={onChange}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.plain-text-input {
|
||||
|
@ -166,10 +169,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
:global(.CodeMirror-lines) {
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
&.hidden {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
:global(.CodeMirror) {
|
||||
|
|
|
@ -69,6 +69,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
import useRichTextResolve from "./rich-text-resolve";
|
||||
import RichTextStyles from "./RichTextStyles.svelte";
|
||||
import { fragmentToStored, storedToFragment } from "./transform";
|
||||
import { slide } from "svelte/transition";
|
||||
|
||||
export let hidden: boolean;
|
||||
|
||||
|
@ -200,46 +201,48 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
setupLifecycleHooks(api);
|
||||
</script>
|
||||
|
||||
<div class="rich-text-input" on:focusin={setFocus} {hidden}>
|
||||
{#if $content.length === 0}
|
||||
<div
|
||||
class="rich-text-placeholder"
|
||||
style:font-family={$fontFamily}
|
||||
style:font-size={$fontSize + "px"}
|
||||
style:direction={$direction}
|
||||
>
|
||||
{$description}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<RichTextStyles
|
||||
color={$pageTheme.isDark ? "white" : "black"}
|
||||
fontFamily={$fontFamily}
|
||||
fontSize={$fontSize}
|
||||
direction={$direction}
|
||||
callback={stylesResolve}
|
||||
let:attachToShadow={attachStyles}
|
||||
let:stylesDidLoad
|
||||
>
|
||||
<div
|
||||
bind:this={richTextDiv}
|
||||
class={className}
|
||||
class:night-mode={$pageTheme.isDark}
|
||||
use:attachShadow
|
||||
use:attachStyles
|
||||
use:attachContentEditable={{ stylesDidLoad }}
|
||||
on:focusin
|
||||
on:focusout
|
||||
/>
|
||||
|
||||
{#await Promise.all([richTextPromise, stylesDidLoad]) then _}
|
||||
<div class="rich-text-widgets">
|
||||
<slot />
|
||||
{#if !hidden}
|
||||
<div class="rich-text-input" on:focusin={setFocus} out:slide={{ duration: 200 }}>
|
||||
{#if $content.length === 0}
|
||||
<div
|
||||
class="rich-text-placeholder"
|
||||
style:font-family={$fontFamily}
|
||||
style:font-size={$fontSize + "px"}
|
||||
style:direction={$direction}
|
||||
>
|
||||
{$description}
|
||||
</div>
|
||||
{/await}
|
||||
</RichTextStyles>
|
||||
<slot name="plain-text-badge" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<RichTextStyles
|
||||
color={$pageTheme.isDark ? "white" : "black"}
|
||||
fontFamily={$fontFamily}
|
||||
fontSize={$fontSize}
|
||||
direction={$direction}
|
||||
callback={stylesResolve}
|
||||
let:attachToShadow={attachStyles}
|
||||
let:stylesDidLoad
|
||||
>
|
||||
<div
|
||||
bind:this={richTextDiv}
|
||||
class={className}
|
||||
class:night-mode={$pageTheme.isDark}
|
||||
use:attachShadow
|
||||
use:attachStyles
|
||||
use:attachContentEditable={{ stylesDidLoad }}
|
||||
on:focusin
|
||||
on:focusout
|
||||
/>
|
||||
|
||||
{#await Promise.all([richTextPromise, stylesDidLoad]) then _}
|
||||
<div class="rich-text-widgets">
|
||||
<slot />
|
||||
</div>
|
||||
{/await}
|
||||
</RichTextStyles>
|
||||
<slot name="plain-text-badge" />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style lang="scss">
|
||||
.rich-text-input {
|
||||
|
|
Loading…
Reference in a new issue