tiptapify 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -132,8 +132,15 @@ function addToolbarItem(_toolbarItems: toolbarItemsType, itemsList: Array<any>,
|
|
|
132
132
|
_itemOptions.splice(paragraphIndex, 1)
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
const inlineIndex = _itemOptions.findIndex((item: string) => item === 'inline')
|
|
136
|
+
const inline = inlineIndex > -1
|
|
137
|
+
if (inline) {
|
|
138
|
+
_itemOptions.splice(inlineIndex, 1)
|
|
139
|
+
}
|
|
140
|
+
|
|
135
141
|
component.props = {
|
|
136
142
|
withParagraph,
|
|
143
|
+
inline,
|
|
137
144
|
customHeadingLevels: _itemOptions.map((item: string) => parseInt(item)),
|
|
138
145
|
}
|
|
139
146
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest'
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
2
|
import { createSSRApp, h, provide, ref } from 'vue'
|
|
3
3
|
import { renderToString } from 'vue/server-renderer'
|
|
4
4
|
import { createVuetify } from 'vuetify'
|
|
5
5
|
import Items from '@tiptapify/components/Toolbar/Items.vue'
|
|
6
6
|
import HeadingButton from '@tiptapify/extensions/components/style/heading/Button.vue'
|
|
7
|
+
import { headingLevels } from '@tiptapify/constants/style'
|
|
7
8
|
|
|
8
9
|
const editor = {
|
|
9
10
|
instanceId: 1,
|
|
@@ -21,7 +22,7 @@ const items = [
|
|
|
21
22
|
},
|
|
22
23
|
]
|
|
23
24
|
|
|
24
|
-
async function renderToolbar () {
|
|
25
|
+
async function renderToolbar (toolbarItems: typeof items = items) {
|
|
25
26
|
const warnings: string[] = []
|
|
26
27
|
const warn = vi.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
|
|
27
28
|
warnings.push(args.map(String).join(' '))
|
|
@@ -32,7 +33,7 @@ async function renderToolbar () {
|
|
|
32
33
|
provide('tiptapifyEditor', ref(editor))
|
|
33
34
|
provide('tiptapifyI18n', { t: (key: string) => key })
|
|
34
35
|
|
|
35
|
-
return () => h(Items, { items })
|
|
36
|
+
return () => h(Items, { items: toolbarItems })
|
|
36
37
|
},
|
|
37
38
|
})
|
|
38
39
|
app.use(createVuetify())
|
|
@@ -44,10 +45,31 @@ async function renderToolbar () {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
describe('Toolbar Items', () => {
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
headingLevels.value = [1, 2, 3, 4, 5, 6]
|
|
50
|
+
})
|
|
51
|
+
|
|
47
52
|
it('does not pass undeclared attributes to toolbar buttons', async () => {
|
|
48
53
|
const { html, warnings } = await renderToolbar()
|
|
49
54
|
|
|
50
55
|
expect(html).toContain('tiptapify-heading-button-1')
|
|
51
56
|
expect(warnings.join('\n')).not.toContain('Extraneous non-props attributes')
|
|
52
57
|
})
|
|
58
|
+
|
|
59
|
+
it('renders heading levels as separate buttons in inline mode', async () => {
|
|
60
|
+
const { html } = await renderToolbar([
|
|
61
|
+
{
|
|
62
|
+
section: 'style',
|
|
63
|
+
group: true,
|
|
64
|
+
components: [{
|
|
65
|
+
name: 'heading',
|
|
66
|
+
component: HeadingButton,
|
|
67
|
+
props: { inline: true, withParagraph: true, customHeadingLevels: [2, 3] },
|
|
68
|
+
}],
|
|
69
|
+
},
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
expect(html).not.toContain('tiptapify-heading-button-1')
|
|
73
|
+
expect(html.match(/<button/g)).toHaveLength(3)
|
|
74
|
+
})
|
|
53
75
|
})
|
|
@@ -11,6 +11,7 @@ import { inject, Ref } from 'vue'
|
|
|
11
11
|
const props = defineProps({
|
|
12
12
|
customHeadingLevels: { type: Array<Level>, default: () => [] },
|
|
13
13
|
withParagraph: { type: Boolean, default: () => true },
|
|
14
|
+
inline: { type: Boolean, default: () => false },
|
|
14
15
|
})
|
|
15
16
|
|
|
16
17
|
const { variantBtn } = useTiptapifyConfig()
|
|
@@ -28,41 +29,69 @@ setHeadingLevels(props.customHeadingLevels)
|
|
|
28
29
|
</script>
|
|
29
30
|
|
|
30
31
|
<template>
|
|
31
|
-
<
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
<template v-if="inline">
|
|
33
|
+
<VBtn
|
|
34
|
+
v-if="withParagraph"
|
|
35
|
+
:color="editor.isActive('paragraph') ? 'primary' : ''"
|
|
36
|
+
:variant="variantBtn"
|
|
37
|
+
size="32"
|
|
38
|
+
@click="editor.chain().focus().setParagraph().run()"
|
|
39
|
+
>
|
|
40
|
+
<Tooltip :label="t('style.paragraph')" hotkey="Mod-Alt-0" />
|
|
41
|
+
<BtnIcon :icon="`mdiSvg:${mdiIcons['mdiFormatParagraph']}`" />
|
|
42
|
+
</VBtn>
|
|
43
|
+
<VBtn
|
|
44
|
+
v-for="headingLevel in headingLevels"
|
|
45
|
+
:key="headingLevel"
|
|
46
|
+
:color="editor.isActive('heading', { level: headingLevel }) ? 'primary' : ''"
|
|
47
|
+
:variant="variantBtn"
|
|
48
|
+
size="32"
|
|
49
|
+
@click="editor.chain().focus().toggleHeading({ level: headingLevel }).run()"
|
|
50
|
+
>
|
|
51
|
+
<Tooltip :label="t(`style.headings.h${headingLevel}`)" :hotkey="`Mod-Alt-${headingLevel}`" />
|
|
52
|
+
<BtnIcon :icon="`mdiSvg:${mdiIcons[`mdiFormatHeader${headingLevel}`]}`" />
|
|
53
|
+
</VBtn>
|
|
54
|
+
</template>
|
|
41
55
|
|
|
42
|
-
<
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
<template v-else>
|
|
57
|
+
<VBtn
|
|
58
|
+
:id="`tiptapify-heading-button-${editor.instanceId}`"
|
|
59
|
+
:color="editor.isActive('heading') ? 'primary' : ''"
|
|
60
|
+
:variant="variantBtn"
|
|
61
|
+
size="32"
|
|
62
|
+
@click="editor.chain().focus().redo().run()"
|
|
63
|
+
>
|
|
64
|
+
<Tooltip :label="t('style.heading')" hotkey="Mod-Alt-1..6" />
|
|
65
|
+
<BtnIcon :icon="`mdiSvg:${mdi.mdiFormatHeaderPound}`" />
|
|
66
|
+
</VBtn>
|
|
67
|
+
|
|
68
|
+
<VMenu :activator="`#tiptapify-heading-button-${editor.instanceId}`">
|
|
69
|
+
<VList density="compact">
|
|
70
|
+
<VListItem
|
|
71
|
+
v-if="withParagraph"
|
|
72
|
+
link
|
|
73
|
+
:color="editor.isActive('paragraph') ? 'primary' : ''"
|
|
74
|
+
@click="editor.chain().focus().setParagraph().run()"
|
|
75
|
+
>
|
|
76
|
+
<Tooltip :label="t('style.paragraph')" hotkey="Mod-Alt-0" />
|
|
77
|
+
<VListItemTitle class="d-flex justify-center align-center">
|
|
78
|
+
<BtnIcon :icon="`mdiSvg:${mdiIcons['mdiFormatParagraph']}`" />
|
|
79
|
+
</VListItemTitle>
|
|
80
|
+
</VListItem>
|
|
81
|
+
<VListItem
|
|
82
|
+
v-for="headingLevel in headingLevels"
|
|
83
|
+
:key="headingLevel"
|
|
84
|
+
:color="editor.isActive('heading', { level: headingLevel }) ? 'primary' : ''"
|
|
85
|
+
@click="editor.chain().focus().toggleHeading({ level: headingLevel }).run()"
|
|
86
|
+
>
|
|
87
|
+
<Tooltip :label="t(`style.headings.h${headingLevel}`)" :hotkey="`Mod-Alt-${headingLevel}`" />
|
|
88
|
+
<VListItemTitle class="d-flex justify-center align-center">
|
|
89
|
+
<BtnIcon :icon="`mdiSvg:${mdiIcons[`mdiFormatHeader${headingLevel}`]}`" />
|
|
90
|
+
</VListItemTitle>
|
|
91
|
+
</VListItem>
|
|
92
|
+
</VList>
|
|
93
|
+
</VMenu>
|
|
94
|
+
</template>
|
|
66
95
|
</template>
|
|
67
96
|
|
|
68
97
|
<style lang="scss" scoped>
|