toolbar-appear-fix
This commit is contained in:
parent
595e2b8a4b
commit
76dea4341d
|
@ -156,7 +156,7 @@ export const CommentsTree = (props: Props) => {
|
||||||
>
|
>
|
||||||
<MiniEditor
|
<MiniEditor
|
||||||
placeholder={t('Write a comment...')}
|
placeholder={t('Write a comment...')}
|
||||||
onSubmit={(value) => handleSubmitComment(value)}
|
onSubmit={handleSubmitComment}
|
||||||
/>
|
/>
|
||||||
<Show when={posting()}>
|
<Show when={posting()}>
|
||||||
<Loading />
|
<Loading />
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import { Show, createEffect, createSignal, on } from 'solid-js'
|
import { Accessor, Show, createEffect, createSignal, on } from 'solid-js'
|
||||||
import { createEditorTransaction } from 'solid-tiptap'
|
import { createEditorTransaction } from 'solid-tiptap'
|
||||||
import { Icon } from '~/components/_shared/Icon/Icon'
|
import { Icon } from '~/components/_shared/Icon/Icon'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
|
@ -10,7 +10,7 @@ import styles from '../SimplifiedEditor.module.scss'
|
||||||
|
|
||||||
export interface MicroToolbarProps {
|
export interface MicroToolbarProps {
|
||||||
showing?: boolean
|
showing?: boolean
|
||||||
editor?: Editor
|
editor: Accessor<Editor|undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MicroToolbar = (props: MicroToolbarProps) => {
|
export const MicroToolbar = (props: MicroToolbarProps) => {
|
||||||
|
@ -19,7 +19,7 @@ export const MicroToolbar = (props: MicroToolbarProps) => {
|
||||||
// show / hide for menu
|
// show / hide for menu
|
||||||
const [showSimpleMenu, setShowSimpleMenu] = createSignal(!props.showing)
|
const [showSimpleMenu, setShowSimpleMenu] = createSignal(!props.showing)
|
||||||
const selection = createEditorTransaction(
|
const selection = createEditorTransaction(
|
||||||
() => props.editor,
|
props.editor,
|
||||||
(instance) => instance?.state.selection
|
(instance) => instance?.state.selection
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@ export const MicroToolbar = (props: MicroToolbarProps) => {
|
||||||
createEffect(on([selection, showLinkInput], ([s, l]) => !l && setShowSimpleMenu(!s?.empty)))
|
createEffect(on([selection, showLinkInput], ([s, l]) => !l && setShowSimpleMenu(!s?.empty)))
|
||||||
|
|
||||||
// focus on link input when it shows up
|
// focus on link input when it shows up
|
||||||
createEffect(on(showLinkInput, (x?: boolean) => x && props.editor?.chain().focus().run()))
|
createEffect(on(showLinkInput, (x?: boolean) => x && props.editor()?.chain().focus().run()))
|
||||||
|
|
||||||
const [storedSelection, setStoredSelection] = createSignal<Editor['state']['selection']>()
|
const [storedSelection, setStoredSelection] = createSignal<Editor['state']['selection']>()
|
||||||
const recoverSelection = () => {
|
const recoverSelection = () => {
|
||||||
if (!storedSelection()?.empty) {
|
if (!storedSelection()?.empty) {
|
||||||
createEditorTransaction(
|
createEditorTransaction(
|
||||||
() => props.editor,
|
props.editor,
|
||||||
(instance?: Editor) => {
|
(instance?: Editor) => {
|
||||||
const r = selection()
|
const r = selection()
|
||||||
if (instance && r) {
|
if (instance && r) {
|
||||||
|
@ -48,14 +48,14 @@ export const MicroToolbar = (props: MicroToolbarProps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const storeSelection = () => {
|
const storeSelection = () => {
|
||||||
const selection = props.editor?.state.selection
|
const selection = props.editor()?.state.selection
|
||||||
if (!selection?.empty) {
|
if (!selection?.empty) {
|
||||||
setStoredSelection(selection)
|
setStoredSelection(selection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const toggleShowLink = () => {
|
const toggleShowLink = () => {
|
||||||
if (showLinkInput()) {
|
if (showLinkInput()) {
|
||||||
props.editor?.chain().focus().run()
|
props.editor()?.chain().focus().run()
|
||||||
recoverSelection()
|
recoverSelection()
|
||||||
} else {
|
} else {
|
||||||
storeSelection()
|
storeSelection()
|
||||||
|
@ -63,7 +63,7 @@ export const MicroToolbar = (props: MicroToolbarProps) => {
|
||||||
setShowLinkInput(!showLinkInput())
|
setShowLinkInput(!showLinkInput())
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Show when={props.editor} keyed>
|
<Show when={props.editor()} keyed>
|
||||||
{(instance) => (
|
{(instance) => (
|
||||||
<Show when={!showSimpleMenu()}>
|
<Show when={!showSimpleMenu()}>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import { Editor } from '@tiptap/core'
|
import { Editor } from '@tiptap/core'
|
||||||
import { Show, createEffect, createSignal, on } from 'solid-js'
|
import { Accessor, Show, createEffect, createSignal, on } from 'solid-js'
|
||||||
|
import { createEditorTransaction } from 'solid-tiptap'
|
||||||
import { Icon } from '~/components/_shared/Icon/Icon'
|
import { Icon } from '~/components/_shared/Icon/Icon'
|
||||||
import { useLocalize } from '~/context/localize'
|
import { useLocalize } from '~/context/localize'
|
||||||
import { useUI } from '~/context/ui'
|
import { useUI } from '~/context/ui'
|
||||||
import { InsertLinkForm } from '../InsertLinkForm/InsertLinkForm'
|
import { InsertLinkForm } from '../InsertLinkForm/InsertLinkForm'
|
||||||
import { ToolbarControl as Control } from './ToolbarControl'
|
import { ToolbarControl as Control } from './ToolbarControl'
|
||||||
|
|
||||||
import { createEditorTransaction } from 'solid-tiptap'
|
|
||||||
import styles from '../SimplifiedEditor.module.scss'
|
import styles from '../SimplifiedEditor.module.scss'
|
||||||
|
|
||||||
interface MiniToolbarProps {
|
interface MiniToolbarProps {
|
||||||
editor?: Editor
|
editor: Accessor<Editor | undefined>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MiniToolbar = (props: MiniToolbarProps) => {
|
export const MiniToolbar = (props: MiniToolbarProps) => {
|
||||||
|
@ -21,17 +21,17 @@ export const MiniToolbar = (props: MiniToolbarProps) => {
|
||||||
const [showLinkInput, setShowLinkInput] = createSignal(false)
|
const [showLinkInput, setShowLinkInput] = createSignal(false)
|
||||||
|
|
||||||
// focus on link input when it shows up
|
// focus on link input when it shows up
|
||||||
createEffect(on(showLinkInput, (x?: boolean) => x && props.editor?.chain().focus().run()))
|
createEffect(on(showLinkInput, (x?: boolean) => x && props.editor()?.chain().focus().run()))
|
||||||
|
|
||||||
const selection = createEditorTransaction(
|
const selection = createEditorTransaction(
|
||||||
() => props.editor,
|
props.editor,
|
||||||
(instance) => instance?.state.selection
|
(instance) => instance?.state.selection
|
||||||
)
|
)
|
||||||
const [storedSelection, setStoredSelection] = createSignal<Editor['state']['selection']>()
|
const [storedSelection, setStoredSelection] = createSignal<Editor['state']['selection']>()
|
||||||
const recoverSelection = () => {
|
const recoverSelection = () => {
|
||||||
if (!storedSelection()?.empty) {
|
if (!storedSelection()?.empty) {
|
||||||
createEditorTransaction(
|
createEditorTransaction(
|
||||||
() => props.editor,
|
props.editor,
|
||||||
(instance?: Editor) => {
|
(instance?: Editor) => {
|
||||||
const r = selection()
|
const r = selection()
|
||||||
if (instance && r) {
|
if (instance && r) {
|
||||||
|
@ -43,14 +43,14 @@ export const MiniToolbar = (props: MiniToolbarProps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const storeSelection = () => {
|
const storeSelection = () => {
|
||||||
const selection = props.editor?.state.selection
|
const selection = props.editor()?.state.selection
|
||||||
if (!selection?.empty) {
|
if (!selection?.empty) {
|
||||||
setStoredSelection(selection)
|
setStoredSelection(selection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const toggleShowLink = () => {
|
const toggleShowLink = () => {
|
||||||
if (showLinkInput()) {
|
if (showLinkInput()) {
|
||||||
props.editor?.chain().focus().run()
|
props.editor()?.chain().focus().run()
|
||||||
recoverSelection()
|
recoverSelection()
|
||||||
} else {
|
} else {
|
||||||
storeSelection()
|
storeSelection()
|
||||||
|
@ -60,7 +60,7 @@ export const MiniToolbar = (props: MiniToolbarProps) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ 'background-color': 'white', display: 'inline-flex' }}>
|
<div style={{ 'background-color': 'white', display: 'inline-flex' }}>
|
||||||
<Show when={props.editor} keyed>
|
<Show when={props.editor()} keyed>
|
||||||
{(instance) => (
|
{(instance) => (
|
||||||
<div class={styles.controls}>
|
<div class={styles.controls}>
|
||||||
<div class={styles.actions}>
|
<div class={styles.actions}>
|
||||||
|
|
|
@ -43,7 +43,7 @@ export const MicroEditor = (props: MicroEditorProps): JSX.Element => {
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<MicroToolbar />
|
<MicroToolbar editor={editor} />
|
||||||
|
|
||||||
<div id="micro-editor" ref={setEditorElement} style={styles.minimal} />
|
<div id="micro-editor" ref={setEditorElement} style={styles.minimal} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,7 +53,7 @@ export default function MiniEditor(props: MiniEditorProps): JSX.Element {
|
||||||
<div>
|
<div>
|
||||||
<div id="mini-editor" ref={setEditorElement} />
|
<div id="mini-editor" ref={setEditorElement} />
|
||||||
|
|
||||||
<MiniToolbar />
|
<MiniToolbar editor={editor} />
|
||||||
|
|
||||||
<Show when={counter() > 0}>
|
<Show when={counter() > 0}>
|
||||||
<small class={styles.limit}>
|
<small class={styles.limit}>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user