Skip to content

Commit

Permalink
Merge pull request #98 from maglevhq/feat-rte-superscript
Browse files Browse the repository at this point in the history
feat: add the superscript command in the RTE input
  • Loading branch information
did authored Dec 15, 2024
2 parents cfbd114 + 61a7a24 commit c8e2cdf
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:isFocused="isFocused"
:lineBreak="options.lineBreak"
:rows="options.nbRows"
:table="options.htmlTable"
:extraExtensions="options.extraExtensions"
@blur="$emit('blur')"
v-model="inputValue"
v-if="setting.type == 'text' && options.html"
Expand Down
16 changes: 11 additions & 5 deletions app/frontend/editor/components/kit/rich-text-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
</div>
<div class="mt-1">
<editor-menu-bar :editor="editor" v-slot="{ commands, isActive }">
<div class="flex sticky top-0 z-10 pb-2 bg-white space-x-1">
<div class="flex sticky top-0 z-10 pb-2 bg-white space-x-1 overflow-x-auto">
<editor-block-button
:commands="commands"
:isActive="isActive"
class="relative"
v-if="!lineBreak"
/>

<editor-format-buttons :commands="commands" :isActive="isActive" />
<editor-format-buttons
:commands="commands"
:isActive="isActive"
:extraExtensions="extraExtensions"
/>

<editor-list-buttons
:commands="commands"
Expand All @@ -35,7 +39,7 @@
:commands="commands"
:isActive="isActive"
class="relative"
v-if="!lineBreak && table"
v-if="!lineBreak && extraExtensions.table"
/>
</div>
</editor-menu-bar>
Expand Down Expand Up @@ -69,11 +73,12 @@ import {
Table,
TableHeader,
TableCell,
TableRow,
TableRow
} from 'tiptap-extensions'
import Doc from './rich-text-input/extensions/Doc'
import LineBreak from './rich-text-input/extensions/LineBreak'
import Link from './rich-text-input/extensions/marks/Link'
import Superscript from './rich-text-input/extensions/marks/Superscript'
import EditorBlockButton from './rich-text-input/block-button.vue'
import EditorFormatButtons from './rich-text-input/format-buttons.vue'
import EditorListButtons from './rich-text-input/list-buttons.vue'
Expand All @@ -98,7 +103,7 @@ export default {
value: { type: String },
lineBreak: { type: Boolean, default: false },
rows: { type: Number, default: 2 },
table: { type: Boolean, default: false },
extraExtensions: { type: Object, default: () => ({ table: false, superscript: false }) },
},
data() {
return { editor: null }
Expand Down Expand Up @@ -151,6 +156,7 @@ export default {
new Underline(),
new Strike(),
new Link({ openOnClick: false, target: null }),
new Superscript(),
new History(),
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Mark } from 'tiptap'
import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'

export default class Superscript extends Mark {

get name() {
return 'sup'
}

get schema() {
return {
parseDOM: [
{
tag: 'sup',
},
],
toDOM: () => ['sup', 0],
}
}

keys({ type }) {
return {
'Mod-^': toggleMark(type),
}
}

commands({ type }) {
return () => toggleMark(type)
}

// NOTE: "^^" are used as delimiters to trigger the superscript formatting
inputRules({ type }) {
return [
markInputRule(/(?:\^\^|__)([^\^*_]+)(?:\^\^|__)$/, type),
]
}

pasteRules({ type }) {
return [
markPasteRule(/(?:\^\^|__)([^\^*_]+)(?:\^\^|__)/g, type),
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
:isActive="isActive.strike()"
@click="commands.strike"
/>
<editor-menu-button
iconName="format-superscript"
class="rounded-r-sm"
:isActive="isActive.sup()"
@click="commands.sup"
v-if="extraExtensions.superscript"
/>
</div>
</template>

Expand All @@ -34,6 +41,7 @@ export default {
props: {
commands: { type: Object, required: true },
isActive: { type: Object, required: true },
},
extraExtensions: { type: Object, default: () => ({ table: false, superscript: false }) },
}
}
</script>

0 comments on commit c8e2cdf

Please sign in to comment.