tiptapify 0.3.0 → 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/index.d.ts CHANGED
@@ -62,6 +62,7 @@ import '@tiptap/extension-invisible-characters'
62
62
 
63
63
  import Tiptapify from './src/components/Tiptapify.vue'
64
64
  import TiptapifyDialog from './src/components/UI/TiptapifyDialog.vue'
65
+ import { TIPTAPIFY_CONFIG_KEY, useTiptapifyConfig, TiptapifyConfig } from './src/composables/useTiptapifyConfig'
65
66
  import * as mdi from '@mdi/js'
66
67
 
67
68
  export type TiptapifyFooterAlignment = 'start' | 'center' | 'end'
@@ -188,6 +189,8 @@ export {
188
189
  mdi,
189
190
  Tiptapify,
190
191
  TiptapifyDialog,
192
+ TIPTAPIFY_CONFIG_KEY,
193
+ useTiptapifyConfig,
191
194
  TiptapEditor,
192
195
  nodeViewProps,
193
196
  NodeViewWrapper,
@@ -225,6 +228,8 @@ export type {
225
228
  SingleCommands,
226
229
  }
227
230
 
231
+ export type { TiptapifyConfig }
232
+
228
233
  declare module '@vue/runtime-core' {
229
234
  interface GlobalComponents {
230
235
  Tiptapify: typeof Tiptapify
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tiptapify",
3
3
  "types": "./index.d.ts",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "description": "Tiptap3 editor with Vuetify3 menu implementation",
6
6
  "exports": {
7
7
  ".": {
@@ -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
  }
@@ -0,0 +1,75 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest'
2
+ import { createSSRApp, h, provide, ref } from 'vue'
3
+ import { renderToString } from 'vue/server-renderer'
4
+ import { createVuetify } from 'vuetify'
5
+ import Items from '@tiptapify/components/Toolbar/Items.vue'
6
+ import HeadingButton from '@tiptapify/extensions/components/style/heading/Button.vue'
7
+ import { headingLevels } from '@tiptapify/constants/style'
8
+
9
+ const editor = {
10
+ instanceId: 1,
11
+ isActive: () => false,
12
+ can: () => ({ chain: () => ({ focus: () => ({ toggleHeading: () => ({ run: () => false }) }) }) }),
13
+ chain: () => ({ focus: () => ({ redo: () => ({ run: () => false }) }) }),
14
+ commands: {},
15
+ }
16
+
17
+ const items = [
18
+ {
19
+ section: 'style',
20
+ group: true,
21
+ components: [{ name: 'heading', component: HeadingButton }],
22
+ },
23
+ ]
24
+
25
+ async function renderToolbar (toolbarItems: typeof items = items) {
26
+ const warnings: string[] = []
27
+ const warn = vi.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
28
+ warnings.push(args.map(String).join(' '))
29
+ })
30
+
31
+ const app = createSSRApp({
32
+ setup () {
33
+ provide('tiptapifyEditor', ref(editor))
34
+ provide('tiptapifyI18n', { t: (key: string) => key })
35
+
36
+ return () => h(Items, { items: toolbarItems })
37
+ },
38
+ })
39
+ app.use(createVuetify())
40
+
41
+ const html = await renderToString(app)
42
+ warn.mockRestore()
43
+
44
+ return { html, warnings }
45
+ }
46
+
47
+ describe('Toolbar Items', () => {
48
+ afterEach(() => {
49
+ headingLevels.value = [1, 2, 3, 4, 5, 6]
50
+ })
51
+
52
+ it('does not pass undeclared attributes to toolbar buttons', async () => {
53
+ const { html, warnings } = await renderToolbar()
54
+
55
+ expect(html).toContain('tiptapify-heading-button-1')
56
+ expect(warnings.join('\n')).not.toContain('Extraneous non-props attributes')
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
+ })
75
+ })
@@ -22,7 +22,7 @@ const { variantBtn } = useTiptapifyConfig()
22
22
  <template v-else>
23
23
  <VBtnGroup v-if="item.group" elevation="4" :class="{ 'tiptapify-btn-group--elevated': variantBtn === 'elevated' }">
24
24
  <template v-for="sectionItem in item.components" :key="sectionItem.name">
25
- <component :is="sectionItem.component" v-bind="{ variantBtn, ...sectionItem.props ?? {} }" />
25
+ <component :is="sectionItem.component" v-bind="sectionItem.props ?? {}" />
26
26
  </template>
27
27
  </VBtnGroup>
28
28
  <template v-else>
@@ -30,7 +30,7 @@ const { variantBtn } = useTiptapifyConfig()
30
30
  :is="sectionItem.component"
31
31
  v-for="sectionItem in item.components"
32
32
  :key="sectionItem.name"
33
- v-bind="{ variantBtn, ...sectionItem.props ?? {} }"
33
+ v-bind="sectionItem.props ?? {}"
34
34
  />
35
35
  </template>
36
36
  <div class="menu-divider" />
@@ -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
- <VBtn
32
- :id="`tiptapify-heading-button-${editor.instanceId}`"
33
- :color="editor.isActive('heading') ? 'primary' : ''"
34
- :variant="variantBtn"
35
- size="32"
36
- @click="editor.chain().focus().redo().run()"
37
- >
38
- <Tooltip :label="t('style.heading')" hotkey="Mod-Alt-1..6" />
39
- <BtnIcon :icon="`mdiSvg:${mdi.mdiFormatHeaderPound}`" />
40
- </VBtn>
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
- <VMenu :activator="`#tiptapify-heading-button-${editor.instanceId}`">
43
- <VList density="compact">
44
- <VListItem
45
- v-if="withParagraph"
46
- link
47
- :color="editor.isActive('paragraph') ? 'primary' : ''"
48
- @click="editor.chain().focus().setParagraph().run()"
49
- >
50
- <VListItemTitle class="d-flex justify-center align-center">
51
- <BtnIcon :icon="`mdiSvg:${mdiIcons['mdiFormatParagraph']}`" />
52
- </VListItemTitle>
53
- </VListItem>
54
- <VListItem
55
- v-for="headingLevel in headingLevels"
56
- :key="headingLevel"
57
- :color="editor.isActive('heading', { level: headingLevel }) ? 'primary' : ''"
58
- @click="editor.chain().focus().toggleHeading({ level: headingLevel }).run()"
59
- >
60
- <VListItemTitle class="d-flex justify-center align-center">
61
- <BtnIcon :icon="`mdiSvg:${mdiIcons[`mdiFormatHeader${headingLevel}`]}`" />
62
- </VListItemTitle>
63
- </VListItem>
64
- </VList>
65
- </VMenu>
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>