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,
|
|
|
|
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'
|
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 { 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-08-12 03:18:01 +00:00
|
|
|
import TiptapTweet from './editor/tiptap-tweet'
|
|
|
|
import { EmbedModal } from './editor/embed-modal'
|
2022-08-11 21:32:02 +00:00
|
|
|
import {
|
|
|
|
CodeIcon,
|
|
|
|
PhotographIcon,
|
|
|
|
PresentationChartLineIcon,
|
|
|
|
} from '@heroicons/react/solid'
|
|
|
|
import { MarketModal } from './editor/market-modal'
|
|
|
|
import { insertContent } from './editor/utils'
|
2022-08-12 19:04:23 +00:00
|
|
|
import { Tooltip } from './tooltip'
|
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-08-10 02:04:55 +00:00
|
|
|
const DisplayImage = Image.configure({
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: 'max-h-60',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
const DisplayLink = Link.configure({
|
|
|
|
HTMLAttributes: {
|
|
|
|
class: clsx('no-underline !text-indigo-700', linkClass),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-07-13 22:56:15 +00:00
|
|
|
const proseClass = clsx(
|
2022-08-09 17:17:44 +00:00
|
|
|
'prose prose-p:my-0 prose-ul:my-0 prose-ol:my-0 prose-li:my-0 prose-blockquote:not-italic max-w-none prose-quoteless leading-relaxed',
|
2022-07-18 21:02:27 +00:00
|
|
|
'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
|
2022-08-06 20:39:52 +00:00
|
|
|
simple?: boolean
|
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-08-06 20:39:52 +00:00
|
|
|
const { placeholder, max, defaultValue = '', disabled, simple } = props
|
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 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-08-06 20:39:52 +00:00
|
|
|
!simple && 'min-h-[6em]',
|
|
|
|
'outline-none pt-2 px-4'
|
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({
|
2022-08-06 20:39:52 +00:00
|
|
|
heading: simple ? false : { levels: [1, 2, 3] },
|
|
|
|
horizontalRule: simple ? false : {},
|
2022-07-24 03:37:34 +00:00
|
|
|
}),
|
|
|
|
Placeholder.configure({
|
|
|
|
placeholder,
|
|
|
|
emptyEditorClass:
|
2022-08-10 02:04:55 +00:00
|
|
|
'before:content-[attr(data-placeholder)] before:text-slate-500 before:float-left before:h-0 cursor-text',
|
2022-07-24 03:37:34 +00:00
|
|
|
}),
|
|
|
|
CharacterCount.configure({ limit: max }),
|
2022-08-10 02:04:55 +00:00
|
|
|
simple ? DisplayImage : Image,
|
|
|
|
DisplayLink,
|
2022-07-24 03:37:34 +00:00
|
|
|
DisplayMention.configure({
|
|
|
|
suggestion: mentionSuggestion(users),
|
|
|
|
}),
|
|
|
|
Iframe,
|
2022-08-12 03:18:01 +00:00
|
|
|
TiptapTweet,
|
2022-07-24 03:37:34 +00:00
|
|
|
],
|
|
|
|
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-08-11 21:32:02 +00:00
|
|
|
insertContent(editor, text)
|
2022-07-22 16:12:23 +00:00
|
|
|
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>
|
2022-08-06 20:39:52 +00:00
|
|
|
children?: React.ReactNode // additional toolbar buttons
|
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-08-06 20:39:52 +00:00
|
|
|
const { editor, upload, children } = props
|
2022-07-23 16:19:49 +00:00
|
|
|
const [iframeOpen, setIframeOpen] = useState(false)
|
2022-08-11 21:32:02 +00:00
|
|
|
const [marketOpen, setMarketOpen] = 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">
|
2022-08-10 02:04:55 +00:00
|
|
|
<div className="rounded-lg border border-gray-300 bg-white shadow-sm focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500">
|
2022-07-23 16:19:49 +00:00
|
|
|
<EditorContent editor={editor} />
|
2022-08-06 20:39:52 +00:00
|
|
|
{/* Toolbar, with buttons for images and embeds */}
|
|
|
|
<div className="flex h-9 items-center gap-5 pl-4 pr-1">
|
2022-08-12 19:04:23 +00:00
|
|
|
<Tooltip className="flex items-center" text="Add image" noTap>
|
2022-07-23 16:19:49 +00:00
|
|
|
<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" />
|
|
|
|
</FileUploadButton>
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
|
|
|
<Tooltip className="flex items-center" text="Add embed" noTap>
|
2022-07-23 16:19:49 +00:00
|
|
|
<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"
|
|
|
|
>
|
2022-08-12 03:18:01 +00:00
|
|
|
<EmbedModal
|
2022-07-23 16:19:49 +00:00
|
|
|
editor={editor}
|
|
|
|
open={iframeOpen}
|
|
|
|
setOpen={setIframeOpen}
|
|
|
|
/>
|
|
|
|
<CodeIcon className="h-5 w-5" aria-hidden="true" />
|
2022-08-11 21:32:02 +00:00
|
|
|
</button>
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
|
|
|
<Tooltip className="flex items-center" text="Add market" noTap>
|
2022-08-11 21:32:02 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setMarketOpen(true)}
|
|
|
|
className="-m-2.5 flex h-10 w-10 items-center justify-center rounded-full text-gray-400 hover:text-gray-500"
|
|
|
|
>
|
|
|
|
<MarketModal
|
|
|
|
editor={editor}
|
|
|
|
open={marketOpen}
|
|
|
|
setOpen={setMarketOpen}
|
|
|
|
/>
|
|
|
|
<PresentationChartLineIcon
|
|
|
|
className="h-5 w-5"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2022-07-23 16:19:49 +00:00
|
|
|
</button>
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
2022-08-10 02:04:55 +00:00
|
|
|
{/* Spacer that also focuses editor on click */}
|
|
|
|
<div
|
|
|
|
className="grow cursor-text self-stretch"
|
|
|
|
onMouseDown={() =>
|
|
|
|
editor?.chain().focus('end').createParagraphNear().run()
|
|
|
|
}
|
|
|
|
aria-hidden
|
|
|
|
/>
|
2022-08-06 20:39:52 +00:00
|
|
|
{children}
|
2022-07-23 16:19:49 +00:00
|
|
|
</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>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-12 03:18:01 +00:00
|
|
|
export function RichContent(props: {
|
2022-08-10 02:04:55 +00:00
|
|
|
content: JSONContent | string
|
|
|
|
smallImage?: boolean
|
|
|
|
}) {
|
|
|
|
const { content, smallImage } = props
|
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 editor = useEditor({
|
|
|
|
editorProps: { attributes: { class: proseClass } },
|
2022-07-24 03:37:34 +00:00
|
|
|
extensions: [
|
2022-08-10 02:04:55 +00:00
|
|
|
StarterKit,
|
|
|
|
smallImage ? DisplayImage : Image,
|
|
|
|
DisplayLink,
|
2022-07-24 03:37:34 +00:00
|
|
|
DisplayMention,
|
2022-08-10 02:04:55 +00:00
|
|
|
Iframe,
|
2022-08-12 03:18:01 +00:00
|
|
|
TiptapTweet,
|
2022-07-24 03:37:34 +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
|
|
|
content,
|
|
|
|
editable: false,
|
|
|
|
})
|
|
|
|
useEffect(() => void editor?.commands?.setContent(content), [editor, content])
|
|
|
|
|
|
|
|
return <EditorContent editor={editor} />
|
|
|
|
}
|
|
|
|
|
|
|
|
// backwards compatibility: we used to store content as strings
|
2022-08-10 02:04:55 +00:00
|
|
|
export function Content(props: {
|
|
|
|
content: JSONContent | string
|
|
|
|
smallImage?: boolean
|
|
|
|
}) {
|
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
|
|
|
|
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
|
|
|
) : (
|
2022-08-10 02:04:55 +00:00
|
|
|
<RichContent {...props} />
|
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
|
|
|
)
|
|
|
|
}
|