Skip to content

Commit

Permalink
refactor(VuetifyTiptap): override configurations for duplicate extens…
Browse files Browse the repository at this point in the history
…ions, update tsconfig
  • Loading branch information
yikoyu committed Jan 27, 2024
1 parent 8bfc5d9 commit 8830fe3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
14 changes: 12 additions & 2 deletions examples/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@
<script setup lang="ts">
import { computed, ref, unref } from 'vue'
import { useTheme } from 'vuetify'
import { locale, type VuetifyTiptapOnChange } from 'vuetify-pro-tiptap'
import { BaseKit, Heading, locale, type VuetifyTiptapOnChange } from 'vuetify-pro-tiptap'
import JsonEditorVue from 'json-editor-vue'

import CustomLang from './components/CustomLang.vue'
import preview from './extensions/preview'
import { jsonValue } from './html'

const extensions = [preview.configure({ spacer: true })]
const extensions = [
preview.configure({ spacer: true }),
BaseKit.configure({
placeholder: {
placeholder: 'Placeholder...'
}
}),
Heading.configure({
levels: [1, 2, 3, 4]
})
]

const theme = useTheme()

Expand Down
6 changes: 2 additions & 4 deletions examples/extensions/preview.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { ButtonView, GeneralOptions } from 'vuetify-pro-tiptap'
import type { GeneralOptions } from 'vuetify-pro-tiptap'
import { Extension } from '@tiptap/core'

import PreviewActionButton from '../components/PreviewActionButton.vue'

export interface PreviewOptions extends GeneralOptions {
button: ButtonView
}
export type PreviewOptions = GeneralOptions<PreviewOptions>

export default Extension.create<PreviewOptions>({
name: 'preview',
Expand Down
15 changes: 12 additions & 3 deletions src/components/VuetifyTiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { EDITOR_UPDATE_THROTTLE_WAIT_TIME, EDITOR_UPDATE_WATCH_THROTTLE_WAIT_TIM
import { useMarkdownTheme, useProvideTiptapStore } from '@/hooks'
import { useLocale } from '@/locales'
import { VuetifyTiptapOnChange } from '@/type'
import { getUnitWithPxAsDefault, hasExtension, isBoolean, isEqual, throttle } from '@/utils/utils'
import { differenceBy, getUnitWithPxAsDefault, hasExtension, isBoolean, isEqual, throttle } from '@/utils/utils'
type HandleKeyDown = NonNullable<EditorOptions['editorProps']['handleKeyDown']>
type OnUpdate = NonNullable<EditorOptions['onUpdate']>
Expand Down Expand Up @@ -81,8 +81,17 @@ const { markdownThemeStyle } = useMarkdownTheme(
)
const sortExtensions = computed<AnyExtension[]>(() => {
const exts = [...state.extensions, ...props.extensions]
return exts.map((k, i) => k.configure({ sort: i }))
const diff = differenceBy(props.extensions, state.extensions, 'name')
// Override configurations for duplicate extensions
const exts = state.extensions.map((k, i) => {
const find = props.extensions.find(ext => ext.name === k.name)
if (!find) return k
return k.configure(find.options)
})
return [...exts, ...diff].map((k, i) => k.configure({ sort: i }))
})
const editor = new Editor({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export function hasExtension(editor: Editor, name: string): boolean {
return true
}

export { isEqual, throttle } from 'lodash-unified'
export { differenceBy, isEqual, throttle } from 'lodash-unified'
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"types": ["vite/client", "vuetify"],
"lib": ["esnext", "dom"],
"paths": {
"@/*":["./src/*"],
"*": ["./node_modules/*"]
"@/*":["./src/*"]
}
},
"vueCompilerOptions": {
Expand Down

0 comments on commit 8830fe3

Please sign in to comment.