fix extension import (backend)

In firebase, typescript compiles imports into common js imports
like `const StarterKit = require("@tiptap/starter-kit")`

Even though StarterKit is exported from the cjs file, it gets imported
as undefined. But it magically works if we import *

If you're reading this in the future, consider replacing StarterKit with
the entire list of extensions.
This commit is contained in:
Sinclair Chen 2022-07-06 15:50:31 -07:00
parent db22da3e2c
commit f354c9e118
2 changed files with 6 additions and 3 deletions

View File

@ -8,6 +8,7 @@
},
"sideEffects": false,
"dependencies": {
"@tiptap/starter-kit": "^2.0.0-beta.190",
"lodash": "4.17.21"
},
"devDependencies": {

View File

@ -1,6 +1,6 @@
import { MAX_TAG_LENGTH } from '../contract'
import { generateText, JSONContent } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'
import { generateText, JSONContent, Extension } from '@tiptap/core'
import * as StarterKit from '@tiptap/starter-kit' // needed for cjs import to work on firebase
export function parseTags(text: string) {
const regex = /(?:^|\s)(?:[#][a-z0-9_]+)/gi
@ -31,5 +31,7 @@ export function parseWordsAsTags(text: string) {
}
export function richTextToString(text: JSONContent | string) {
return typeof text === 'string' ? text : generateText(text, [StarterKit])
return typeof text === 'string'
? text
: generateText(text, [StarterKit as unknown as Extension])
}