Allow to configure editor heading levels and set level 2 as start for posts

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-11-02 18:09:26 +01:00
parent 3ddf360e11
commit e69e8a5044
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 42 additions and 9 deletions

View File

@ -44,8 +44,18 @@
<button <button
v-if="!isBasicMode" v-if="!isBasicMode"
class="menubar__button" class="menubar__button"
:class="{ 'is-active': editor?.isActive('heading', { level: 3 }) }" :class="{
@click="editor?.chain().focus().toggleHeading({ level: 3 }).run()" 'is-active': editor?.isActive('heading', {
level: props.headingLevel[0],
}),
}"
@click="
editor
?.chain()
.focus()
.toggleHeading({ level: props.headingLevel[0] })
.run()
"
type="button" type="button"
:title="t('Heading Level 1')" :title="t('Heading Level 1')"
> >
@ -55,8 +65,18 @@
<button <button
v-if="!isBasicMode" v-if="!isBasicMode"
class="menubar__button" class="menubar__button"
:class="{ 'is-active': editor?.isActive('heading', { level: 4 }) }" :class="{
@click="editor?.chain().focus().toggleHeading({ level: 4 }).run()" 'is-active': editor?.isActive('heading', {
level: props.headingLevel[1],
}),
}"
@click="
editor
?.chain()
.focus()
.toggleHeading({ level: props.headingLevel[1] })
.run()
"
type="button" type="button"
:title="t('Heading Level 2')" :title="t('Heading Level 2')"
> >
@ -66,8 +86,18 @@
<button <button
v-if="!isBasicMode" v-if="!isBasicMode"
class="menubar__button" class="menubar__button"
:class="{ 'is-active': editor?.isActive('heading', { level: 5 }) }" :class="{
@click="editor?.chain().focus().toggleHeading({ level: 5 }).run()" 'is-active': editor?.isActive('heading', {
level: props.headingLevel[2],
}),
}"
@click="
editor
?.chain()
.focus()
.toggleHeading({ level: props.headingLevel[2] })
.run()
"
type="button" type="button"
:title="t('Heading Level 3')" :title="t('Heading Level 3')"
> >
@ -196,7 +226,7 @@
import { useEditor, EditorContent, BubbleMenu } from "@tiptap/vue-3"; import { useEditor, EditorContent, BubbleMenu } from "@tiptap/vue-3";
import Blockquote from "@tiptap/extension-blockquote"; import Blockquote from "@tiptap/extension-blockquote";
import BulletList from "@tiptap/extension-bullet-list"; import BulletList from "@tiptap/extension-bullet-list";
import Heading from "@tiptap/extension-heading"; import Heading, { Level } from "@tiptap/extension-heading";
import Document from "@tiptap/extension-document"; import Document from "@tiptap/extension-document";
import Paragraph from "@tiptap/extension-paragraph"; import Paragraph from "@tiptap/extension-paragraph";
import Bold from "@tiptap/extension-bold"; import Bold from "@tiptap/extension-bold";
@ -248,10 +278,12 @@ const props = withDefaults(
ariaLabel?: string; ariaLabel?: string;
currentActor: IPerson; currentActor: IPerson;
placeholder?: string; placeholder?: string;
headingLevel?: Level[];
}>(), }>(),
{ {
mode: "description", mode: "description",
maxSize: 100_000_000, maxSize: 100_000_000,
headingLevel: () => [3, 4, 5],
} }
); );
@ -310,7 +342,7 @@ const editor = useEditor({
Blockquote, Blockquote,
BulletList, BulletList,
Heading.configure({ Heading.configure({
levels: [3, 4, 5], levels: props.headingLevel,
}), }),
Document, Document,
Paragraph, Paragraph,

View File

@ -43,6 +43,7 @@
:aria-label="t('Post body')" :aria-label="t('Post body')"
:current-actor="currentActor" :current-actor="currentActor"
:placeholder="t('Write your post')" :placeholder="t('Write your post')"
:headingLevel="[2, 3, 4]"
/> />
</o-field> </o-field>
<h2 class="mt-2">{{ t("Who can view this post") }}</h2> <h2 class="mt-2">{{ t("Who can view this post") }}</h2>

View File

@ -111,7 +111,7 @@
" "
> >
<router-link <router-link
class="flex gap-1 whitespace-nowrap" class="flex gap-1 whitespace-nowrap flex-1"
:to="{ :to="{
name: RouteName.POST_EDIT, name: RouteName.POST_EDIT,
params: { slug: post.slug }, params: { slug: post.slug },