Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
import CharacterCount from '@tiptap/extension-character-count'
|
|
|
|
import Placeholder from '@tiptap/extension-placeholder'
|
|
|
|
import {
|
|
|
|
useEditor,
|
|
|
|
EditorContent,
|
|
|
|
FloatingMenu,
|
|
|
|
JSONContent,
|
|
|
|
Content,
|
|
|
|
Editor,
|
|
|
|
} from '@tiptap/react'
|
|
|
|
import StarterKit from '@tiptap/starter-kit'
|
|
|
|
import { Image } from '@tiptap/extension-image'
|
2022-07-13 22:56:15 +00:00
|
|
|
import { Link } from '@tiptap/extension-link'
|
2022-07-24 03:37:34 +00:00
|
|
|
import { Mention } from '@tiptap/extension-mention'
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
import clsx from 'clsx'
|
2022-07-23 16:19:49 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
import { Linkify } from './linkify'
|
|
|
|
import { uploadImage } from 'web/lib/firebase/storage'
|
|
|
|
import { useMutation } from 'react-query'
|
|
|
|
import { exhibitExts } from 'common/util/parse'
|
|
|
|
import { FileUploadButton } from './file-upload-button'
|
2022-07-13 23:12:19 +00:00
|
|
|
import { linkClass } from './site-link'
|
2022-07-24 03:37:34 +00:00
|
|
|
import { useUsers } from 'web/hooks/use-users'
|
|
|
|
import { mentionSuggestion } from './editor/mention-suggestion'
|
|
|
|
import { DisplayMention } from './editor/mention'
|
2022-07-22 16:12:23 +00:00
|
|
|
import Iframe from 'common/util/tiptap-iframe'
|
2022-07-23 16:19:49 +00:00
|
|
|
import { CodeIcon, PhotographIcon } from '@heroicons/react/solid'
|
|
|
|
import { Modal } from './layout/modal'
|
|
|
|
import { Col } from './layout/col'
|
|
|
|
import { Button } from './button'
|
|
|
|
import { Row } from './layout/row'
|
|
|
|
import { Spacer } from './layout/spacer'
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
|
2022-07-13 22:56:15 +00:00
|
|
|
const proseClass = clsx(
|
2022-07-18 21:02:27 +00:00
|
|
|
'prose prose-p:my-0 prose-li:my-0 prose-blockquote:not-italic max-w-none prose-quoteless leading-relaxed',
|
|
|
|
'font-light prose-a:font-light prose-blockquote:font-light'
|
2022-07-13 22:56:15 +00:00
|
|
|
)
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
|
|
|
|
export function useTextEditor(props: {
|
|
|
|
placeholder?: string
|
|
|
|
max?: number
|
|
|
|
defaultValue?: Content
|
|
|
|
disabled?: boolean
|
|
|
|
}) {
|
|
|
|
const { placeholder, max, defaultValue = '', disabled } = props
|
|
|
|
|
2022-07-24 03:37:34 +00:00
|
|
|
const users = useUsers()
|
|
|
|
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
const editorClass = clsx(
|
|
|
|
proseClass,
|
2022-07-23 16:19:49 +00:00
|
|
|
'min-h-[6em] resize-none outline-none border-none pt-3 px-4 focus:ring-0'
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
)
|
|
|
|
|
2022-07-24 03:37:34 +00:00
|
|
|
const editor = useEditor(
|
|
|
|
{
|
|
|
|
editorProps: { attributes: { class: editorClass } },
|
|
|
|
extensions: [
|
|
|
|
StarterKit.configure({
|
|
|
|
heading: { levels: [1, 2, 3] },
|
|
|
|
}),
|
|
|
|
Placeholder.configure({
|
|
|
|
placeholder,
|
|
|
|
emptyEditorClass:
|
|
|
|
'before:content-[attr(data-placeholder)] before:text-slate-500 before:float-left before:h-0',
|
|
|
|
}),
|
|
|
|
CharacterCount.configure({ limit: max }),
|
|
|
|
Image,
|
|
|
|
Link.configure({
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: clsx('no-underline !text-indigo-700', linkClass),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
DisplayMention.configure({
|
|
|
|
suggestion: mentionSuggestion(users),
|
|
|
|
}),
|
|
|
|
Iframe,
|
|
|
|
],
|
|
|
|
content: defaultValue,
|
|
|
|
},
|
|
|
|
[!users.length] // passed as useEffect dependency. (re-render editor when users load, to update mention menu)
|
|
|
|
)
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
|
|
|
|
const upload = useUploadMutation(editor)
|
|
|
|
|
|
|
|
editor?.setOptions({
|
|
|
|
editorProps: {
|
|
|
|
handlePaste(view, event) {
|
|
|
|
const imageFiles = Array.from(event.clipboardData?.files ?? []).filter(
|
|
|
|
(file) => file.type.startsWith('image')
|
|
|
|
)
|
|
|
|
|
2022-07-22 16:12:23 +00:00
|
|
|
if (imageFiles.length) {
|
|
|
|
event.preventDefault()
|
|
|
|
upload.mutate(imageFiles)
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
}
|
|
|
|
|
2022-07-22 16:12:23 +00:00
|
|
|
// If the pasted content is iframe code, directly inject it
|
|
|
|
const text = event.clipboardData?.getData('text/plain').trim() ?? ''
|
2022-07-23 16:19:49 +00:00
|
|
|
if (isValidIframe(text)) {
|
2022-07-22 16:12:23 +00:00
|
|
|
editor.chain().insertContent(text).run()
|
|
|
|
return true // Prevent the code from getting pasted as text
|
|
|
|
}
|
|
|
|
|
|
|
|
return // Otherwise, use default paste handler
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
editor?.setEditable(!disabled)
|
|
|
|
}, [editor, disabled])
|
|
|
|
|
|
|
|
return { editor, upload }
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:19:49 +00:00
|
|
|
function isValidIframe(text: string) {
|
|
|
|
return /^<iframe.*<\/iframe>$/.test(text)
|
|
|
|
}
|
|
|
|
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
export function TextEditor(props: {
|
|
|
|
editor: Editor | null
|
|
|
|
upload: ReturnType<typeof useUploadMutation>
|
|
|
|
}) {
|
|
|
|
const { editor, upload } = props
|
2022-07-23 16:19:49 +00:00
|
|
|
const [iframeOpen, setIframeOpen] = useState(false)
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{/* hide placeholder when focused */}
|
2022-07-23 16:19:49 +00:00
|
|
|
<div className="relative w-full [&:focus-within_p.is-empty]:before:content-none">
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
{editor && (
|
|
|
|
<FloatingMenu
|
|
|
|
editor={editor}
|
2022-07-18 21:02:27 +00:00
|
|
|
className={clsx(proseClass, '-ml-2 mr-2 w-full text-slate-300 ')}
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
>
|
2022-07-16 17:19:53 +00:00
|
|
|
Type <em>*markdown*</em>. Paste or{' '}
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
<FileUploadButton
|
|
|
|
className="link text-blue-300"
|
|
|
|
onFiles={upload.mutate}
|
|
|
|
>
|
2022-07-16 17:19:53 +00:00
|
|
|
upload
|
|
|
|
</FileUploadButton>{' '}
|
|
|
|
images!
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
</FloatingMenu>
|
|
|
|
)}
|
2022-07-23 16:19:49 +00:00
|
|
|
<div className="overflow-hidden rounded-lg border border-gray-300 shadow-sm focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500">
|
|
|
|
<EditorContent editor={editor} />
|
|
|
|
{/* Spacer element to match the height of the toolbar */}
|
|
|
|
<div className="py-2" aria-hidden="true">
|
|
|
|
{/* Matches height of button in toolbar (1px border + 36px content height) */}
|
|
|
|
<div className="py-px">
|
|
|
|
<div className="h-9" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{/* Toolbar, with buttons for image and embeds */}
|
|
|
|
<div className="absolute inset-x-0 bottom-0 flex justify-between py-2 pl-3 pr-2">
|
|
|
|
<div className="flex items-center space-x-5">
|
|
|
|
<div className="flex items-center">
|
|
|
|
<FileUploadButton
|
|
|
|
onFiles={upload.mutate}
|
|
|
|
className="-m-2.5 flex h-10 w-10 items-center justify-center rounded-full text-gray-400 hover:text-gray-500"
|
|
|
|
>
|
|
|
|
<PhotographIcon className="h-5 w-5" aria-hidden="true" />
|
|
|
|
<span className="sr-only">Upload an image</span>
|
|
|
|
</FileUploadButton>
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setIframeOpen(true)}
|
|
|
|
className="-m-2.5 flex h-10 w-10 items-center justify-center rounded-full text-gray-400 hover:text-gray-500"
|
|
|
|
>
|
|
|
|
<IframeModal
|
|
|
|
editor={editor}
|
|
|
|
open={iframeOpen}
|
|
|
|
setOpen={setIframeOpen}
|
|
|
|
/>
|
|
|
|
<CodeIcon className="h-5 w-5" aria-hidden="true" />
|
|
|
|
<span className="sr-only">Embed an iframe</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
</div>
|
|
|
|
{upload.isLoading && <span className="text-xs">Uploading image...</span>}
|
|
|
|
{upload.isError && (
|
|
|
|
<span className="text-error text-xs">Error uploading image :(</span>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-23 16:19:49 +00:00
|
|
|
function IframeModal(props: {
|
|
|
|
editor: Editor | null
|
|
|
|
open: boolean
|
|
|
|
setOpen: (open: boolean) => void
|
|
|
|
}) {
|
|
|
|
const { editor, open, setOpen } = props
|
|
|
|
const [embedCode, setEmbedCode] = useState('')
|
|
|
|
const valid = isValidIframe(embedCode)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal open={open} setOpen={setOpen}>
|
|
|
|
<Col className="gap-2 rounded bg-white p-6">
|
|
|
|
<label
|
|
|
|
htmlFor="embed"
|
|
|
|
className="block text-sm font-medium text-gray-700"
|
|
|
|
>
|
|
|
|
Embed a market, Youtube video, etc.
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
name="embed"
|
|
|
|
id="embed"
|
|
|
|
className="block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
|
|
|
|
placeholder='e.g. <iframe src="..."></iframe>'
|
|
|
|
value={embedCode}
|
|
|
|
onChange={(e) => setEmbedCode(e.target.value)}
|
|
|
|
/>
|
|
|
|
|
|
|
|
{/* Preview the embed if it's valid */}
|
|
|
|
{valid ? <RichContent content={embedCode} /> : <Spacer h={2} />}
|
|
|
|
|
|
|
|
<Row className="gap-2">
|
|
|
|
<Button
|
|
|
|
disabled={!valid}
|
|
|
|
onClick={() => {
|
|
|
|
if (editor && valid) {
|
|
|
|
editor.chain().insertContent(embedCode).run()
|
|
|
|
setEmbedCode('')
|
|
|
|
setOpen(false)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Embed
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
color="gray"
|
|
|
|
onClick={() => {
|
|
|
|
setEmbedCode('')
|
|
|
|
setOpen(false)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
const useUploadMutation = (editor: Editor | null) =>
|
|
|
|
useMutation(
|
|
|
|
(files: File[]) =>
|
2022-07-16 18:37:28 +00:00
|
|
|
// TODO: Images should be uploaded under a particular username
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
Promise.all(files.map((file) => uploadImage('default', file))),
|
|
|
|
{
|
|
|
|
onSuccess(urls) {
|
|
|
|
if (!editor) return
|
|
|
|
let trans = editor.view.state.tr
|
|
|
|
urls.forEach((src: any) => {
|
|
|
|
const node = editor.view.state.schema.nodes.image.create({ src })
|
|
|
|
trans = trans.insert(editor.view.state.selection.to, node)
|
|
|
|
})
|
|
|
|
editor.view.dispatch(trans)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-07-23 16:19:49 +00:00
|
|
|
function RichContent(props: { content: JSONContent | string }) {
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
const { content } = props
|
|
|
|
const editor = useEditor({
|
|
|
|
editorProps: { attributes: { class: proseClass } },
|
2022-07-24 03:37:34 +00:00
|
|
|
extensions: [
|
|
|
|
// replace tiptap's Mention with ours, to add style and link
|
|
|
|
...exhibitExts.filter((ex) => ex.name !== Mention.name),
|
|
|
|
DisplayMention,
|
|
|
|
],
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
content,
|
|
|
|
editable: false,
|
|
|
|
})
|
|
|
|
useEffect(() => void editor?.commands?.setContent(content), [editor, content])
|
|
|
|
|
|
|
|
return <EditorContent editor={editor} />
|
|
|
|
}
|
|
|
|
|
|
|
|
// backwards compatibility: we used to store content as strings
|
|
|
|
export function Content(props: { content: JSONContent | string }) {
|
|
|
|
const { content } = props
|
|
|
|
return typeof content === 'string' ? (
|
2022-07-18 21:02:27 +00:00
|
|
|
<div className="whitespace-pre-line font-light leading-relaxed">
|
2022-07-18 05:22:44 +00:00
|
|
|
<Linkify text={content} />
|
|
|
|
</div>
|
Rich content (#620)
* Add TipTap editor and renderer components
* Change market description editor to rich text
* Type description as JSON, fix string-based logic
- Delete make-predictions.tsx
- Delete feed logic that showed descriptions
* wip Fix API validation
* fix type error
* 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.
* Stop load on fail create market, improve warning
* Refactor editor as hook / fix infinite submit bug
Move state of editor back up to parent
We have to do this later anyways to allow parent to edit
* Add images - display, paste + uploading
* add uploading state of image
* Fix placeholder, misc styling
min height, quote
* Fix appending to description
* code review fixes: rename, refactor, chop carets
* Add hint & upload button on new lines
- bump to Tailwind 3.1 for arbitrary variants
* clean up, run prettier
* rename FileButton to FileUploadButton
* add image extension as functions dependency
2022-07-13 18:58:22 +00:00
|
|
|
) : (
|
|
|
|
<RichContent content={content} />
|
|
|
|
)
|
|
|
|
}
|