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,
|
2022-09-12 23:10:32 +00:00
|
|
|
BubbleMenu,
|
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
|
|
|
EditorContent,
|
|
|
|
JSONContent,
|
|
|
|
Content,
|
|
|
|
Editor,
|
2022-08-23 00:45:23 +00:00
|
|
|
mergeAttributes,
|
2022-10-11 01:47:02 +00:00
|
|
|
Extensions,
|
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
|
|
|
} 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-10-11 19:52:27 +00:00
|
|
|
import { useCallback, 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'
|
2022-07-13 23:12:19 +00:00
|
|
|
import { linkClass } from './site-link'
|
2022-07-24 03:37:34 +00:00
|
|
|
import { DisplayMention } from './editor/mention'
|
2022-09-16 06:37:17 +00:00
|
|
|
import { DisplayContractMention } from './editor/contract-mention'
|
2022-10-13 15:25:15 +00:00
|
|
|
import GridComponent from './editor/tiptap-grid-cards'
|
|
|
|
|
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 {
|
2022-09-12 23:10:32 +00:00
|
|
|
CheckIcon,
|
2022-08-11 21:32:02 +00:00
|
|
|
CodeIcon,
|
2022-09-29 21:28:04 +00:00
|
|
|
EyeOffIcon,
|
2022-08-11 21:32:02 +00:00
|
|
|
PhotographIcon,
|
|
|
|
PresentationChartLineIcon,
|
2022-09-12 23:10:32 +00:00
|
|
|
TrashIcon,
|
2022-08-11 21:32:02 +00:00
|
|
|
} 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'
|
2022-09-12 23:10:32 +00:00
|
|
|
import BoldIcon from 'web/lib/icons/bold-icon'
|
|
|
|
import ItalicIcon from 'web/lib/icons/italic-icon'
|
|
|
|
import LinkIcon from 'web/lib/icons/link-icon'
|
|
|
|
import { getUrl } from 'common/util/parse'
|
2022-09-29 21:28:04 +00:00
|
|
|
import { TiptapSpoiler } from 'common/util/tiptap-spoiler'
|
2022-10-12 16:53:04 +00:00
|
|
|
import { ImageModal } from './editor/image-modal'
|
2022-10-11 19:52:27 +00:00
|
|
|
import {
|
|
|
|
storageStore,
|
|
|
|
usePersistentState,
|
|
|
|
} from 'web/hooks/use-persistent-state'
|
|
|
|
import { safeLocalStorage } from 'web/lib/util/local'
|
|
|
|
import { debounce } from 'lodash'
|
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: {
|
2022-10-13 23:23:20 +00:00
|
|
|
class: 'max-h-60 hover:max-h-[120rem] transition-all',
|
2022-08-10 02:04:55 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-08-23 00:45:23 +00:00
|
|
|
const DisplayLink = Link.extend({
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
delete HTMLAttributes.class // only use our classes (don't duplicate on paste)
|
|
|
|
return [
|
|
|
|
'a',
|
|
|
|
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
|
|
0,
|
|
|
|
]
|
|
|
|
},
|
|
|
|
}).configure({
|
2022-08-10 02:04:55 +00:00
|
|
|
HTMLAttributes: {
|
|
|
|
class: clsx('no-underline !text-indigo-700', linkClass),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2022-10-11 01:47:02 +00:00
|
|
|
export const editorExtensions = (simple = false): Extensions => [
|
|
|
|
StarterKit.configure({
|
|
|
|
heading: simple ? false : { levels: [1, 2, 3] },
|
|
|
|
horizontalRule: simple ? false : {},
|
|
|
|
}),
|
|
|
|
simple ? DisplayImage : Image,
|
|
|
|
DisplayLink,
|
|
|
|
DisplayMention,
|
|
|
|
DisplayContractMention,
|
2022-10-13 15:25:15 +00:00
|
|
|
GridComponent,
|
2022-10-11 01:47:02 +00:00
|
|
|
Iframe,
|
|
|
|
TiptapTweet,
|
|
|
|
TiptapSpoiler.configure({
|
|
|
|
spoilerOpenClass: 'rounded-sm bg-greyscale-2',
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
|
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-10-13 00:53:37 +00:00
|
|
|
'font-light prose-a:font-light prose-blockquote:font-light prose-sm'
|
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
|
2022-08-06 20:39:52 +00:00
|
|
|
simple?: boolean
|
2022-10-11 19:52:27 +00:00
|
|
|
key?: string // unique key for autosave. If set, plz call `clearContent(true)` on submit to clear autosave
|
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-10-13 00:25:17 +00:00
|
|
|
const { placeholder, max, defaultValue, simple, key } = props
|
2022-10-11 19:52:27 +00:00
|
|
|
|
|
|
|
const [content, saveContent] = usePersistentState<JSONContent | undefined>(
|
|
|
|
undefined,
|
|
|
|
{
|
|
|
|
key: `text ${key}`,
|
|
|
|
store: storageStore(safeLocalStorage()),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
const save = useCallback(debounce(saveContent, 500), [])
|
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]',
|
2022-09-01 03:52:12 +00:00
|
|
|
'outline-none pt-2 px-4',
|
|
|
|
'prose-img:select-auto',
|
2022-10-11 19:52:27 +00:00
|
|
|
'[&_.ProseMirror-selectednode]:outline-dotted [&_*]:outline-indigo-300' // selected img, embeds
|
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-09-08 20:02:50 +00:00
|
|
|
const editor = useEditor({
|
2022-10-11 19:52:27 +00:00
|
|
|
editorProps: {
|
|
|
|
attributes: { class: editorClass, spellcheck: simple ? 'true' : 'false' },
|
|
|
|
},
|
|
|
|
onUpdate: key ? ({ editor }) => save(editor.getJSON()) : undefined,
|
2022-09-08 20:02:50 +00:00
|
|
|
extensions: [
|
2022-10-11 01:47:02 +00:00
|
|
|
...editorExtensions(simple),
|
2022-09-08 20:02:50 +00:00
|
|
|
Placeholder.configure({
|
|
|
|
placeholder,
|
|
|
|
emptyEditorClass:
|
|
|
|
'before:content-[attr(data-placeholder)] before:text-slate-500 before:float-left before:h-0 cursor-text',
|
|
|
|
}),
|
|
|
|
CharacterCount.configure({ limit: max }),
|
|
|
|
],
|
2022-10-11 19:52:27 +00:00
|
|
|
content: defaultValue ?? (key && content ? content : ''),
|
2022-09-08 20:02:50 +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
|
|
|
|
|
|
|
const upload = useUploadMutation(editor)
|
|
|
|
|
|
|
|
editor?.setOptions({
|
|
|
|
editorProps: {
|
|
|
|
handlePaste(view, event) {
|
2022-09-01 00:18:35 +00:00
|
|
|
const imageFiles = getImages(event.clipboardData)
|
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
|
|
|
},
|
2022-09-01 00:18:35 +00:00
|
|
|
handleDrop(_view, event, _slice, moved) {
|
|
|
|
// if dragged from outside
|
|
|
|
if (!moved) {
|
|
|
|
event.preventDefault()
|
|
|
|
upload.mutate(getImages(event.dataTransfer))
|
|
|
|
}
|
|
|
|
},
|
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 { editor, upload }
|
|
|
|
}
|
|
|
|
|
2022-09-01 00:18:35 +00:00
|
|
|
const getImages = (data: DataTransfer | null) =>
|
|
|
|
Array.from(data?.files ?? []).filter((file) => file.type.startsWith('image'))
|
|
|
|
|
2022-07-23 16:19:49 +00:00
|
|
|
function isValidIframe(text: string) {
|
|
|
|
return /^<iframe.*<\/iframe>$/.test(text)
|
|
|
|
}
|
|
|
|
|
2022-09-12 23:10:32 +00:00
|
|
|
function FloatingMenu(props: { editor: Editor | null }) {
|
|
|
|
const { editor } = props
|
|
|
|
|
|
|
|
const [url, setUrl] = useState<string | null>(null)
|
|
|
|
|
|
|
|
if (!editor) return null
|
|
|
|
|
|
|
|
// current selection
|
|
|
|
const isBold = editor.isActive('bold')
|
|
|
|
const isItalic = editor.isActive('italic')
|
|
|
|
const isLink = editor.isActive('link')
|
2022-09-29 21:28:04 +00:00
|
|
|
const isSpoiler = editor.isActive('spoiler')
|
2022-09-12 23:10:32 +00:00
|
|
|
|
|
|
|
const setLink = () => {
|
|
|
|
const href = url && getUrl(url)
|
|
|
|
if (href) {
|
|
|
|
editor.chain().focus().extendMarkRange('link').setLink({ href }).run()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsetLink = () => editor.chain().focus().unsetLink().run()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BubbleMenu
|
|
|
|
editor={editor}
|
|
|
|
className="flex gap-2 rounded-sm bg-slate-700 p-1 text-white"
|
|
|
|
>
|
|
|
|
{url === null ? (
|
|
|
|
<>
|
|
|
|
<button onClick={() => editor.chain().focus().toggleBold().run()}>
|
|
|
|
<BoldIcon className={clsx('h-5', isBold && 'text-indigo-200')} />
|
|
|
|
</button>
|
|
|
|
<button onClick={() => editor.chain().focus().toggleItalic().run()}>
|
|
|
|
<ItalicIcon
|
|
|
|
className={clsx('h-5', isItalic && 'text-indigo-200')}
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
<button onClick={() => (isLink ? unsetLink() : setUrl(''))}>
|
|
|
|
<LinkIcon className={clsx('h-5', isLink && 'text-indigo-200')} />
|
|
|
|
</button>
|
2022-09-29 21:28:04 +00:00
|
|
|
<button onClick={() => editor.chain().focus().toggleSpoiler().run()}>
|
|
|
|
<EyeOffIcon
|
|
|
|
className={clsx('h-5', isSpoiler && 'text-indigo-200')}
|
|
|
|
/>
|
|
|
|
</button>
|
2022-09-12 23:10:32 +00:00
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="h-5 border-0 bg-inherit text-sm !shadow-none !ring-0"
|
|
|
|
placeholder="Type or paste a link"
|
|
|
|
onChange={(e) => setUrl(e.target.value)}
|
|
|
|
/>
|
|
|
|
<button onClick={() => (setLink(), setUrl(null))}>
|
|
|
|
<CheckIcon className="h-5 w-5" />
|
|
|
|
</button>
|
|
|
|
<button onClick={() => (unsetLink(), setUrl(null))}>
|
|
|
|
<TrashIcon className="h-5 w-5" />
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</BubbleMenu>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
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-10-12 16:53:04 +00:00
|
|
|
const [imageOpen, setImageOpen] = useState(false)
|
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-10-13 18:23:42 +00:00
|
|
|
{/* matches input styling */}
|
|
|
|
<div className="rounded-lg border border-gray-300 bg-white shadow-sm transition-colors focus-within:border-indigo-500 focus-within:ring-1 focus-within:ring-indigo-500">
|
2022-09-12 23:10:32 +00:00
|
|
|
<FloatingMenu editor={editor} />
|
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-09-01 03:52:12 +00:00
|
|
|
<Tooltip text="Add image" noTap noFade>
|
2022-10-12 16:53:04 +00:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => setImageOpen(true)}
|
2022-07-23 16:19:49 +00:00
|
|
|
className="-m-2.5 flex h-10 w-10 items-center justify-center rounded-full text-gray-400 hover:text-gray-500"
|
|
|
|
>
|
2022-10-12 16:53:04 +00:00
|
|
|
<ImageModal
|
|
|
|
editor={editor}
|
|
|
|
upload={upload}
|
|
|
|
open={imageOpen}
|
|
|
|
setOpen={setImageOpen}
|
|
|
|
/>
|
2022-07-23 16:19:49 +00:00
|
|
|
<PhotographIcon className="h-5 w-5" aria-hidden="true" />
|
2022-10-12 16:53:04 +00:00
|
|
|
</button>
|
2022-08-12 19:04:23 +00:00
|
|
|
</Tooltip>
|
2022-09-01 03:52:12 +00:00
|
|
|
<Tooltip text="Add embed" noTap noFade>
|
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>
|
2022-09-01 03:52:12 +00:00
|
|
|
<Tooltip text="Add market" noTap noFade>
|
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
|
2022-10-05 23:08:01 +00:00
|
|
|
let trans = editor.chain().focus()
|
|
|
|
urls.forEach((src) => {
|
|
|
|
trans = trans.createParagraphNear()
|
|
|
|
trans = trans.setImage({ src })
|
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-10-05 23:08:01 +00:00
|
|
|
trans.run()
|
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-12 03:18:01 +00:00
|
|
|
export function RichContent(props: {
|
2022-08-10 02:04:55 +00:00
|
|
|
content: JSONContent | string
|
2022-08-30 09:41:47 +00:00
|
|
|
className?: string
|
2022-08-10 02:04:55 +00:00
|
|
|
smallImage?: boolean
|
|
|
|
}) {
|
2022-08-30 09:41:47 +00:00
|
|
|
const { className, 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,
|
2022-09-06 23:55:33 +00:00
|
|
|
DisplayLink.configure({ openOnClick: false }), // stop link opening twice (browser still opens)
|
2022-07-24 03:37:34 +00:00
|
|
|
DisplayMention,
|
2022-10-11 01:47:02 +00:00
|
|
|
DisplayContractMention,
|
2022-10-13 15:25:15 +00:00
|
|
|
GridComponent,
|
2022-08-10 02:04:55 +00:00
|
|
|
Iframe,
|
2022-08-12 03:18:01 +00:00
|
|
|
TiptapTweet,
|
2022-09-29 21:28:04 +00:00
|
|
|
TiptapSpoiler.configure({
|
|
|
|
spoilerOpenClass: 'rounded-sm bg-greyscale-2 cursor-text',
|
|
|
|
spoilerCloseClass:
|
2022-10-03 18:55:10 +00:00
|
|
|
'rounded-sm bg-greyscale-6 text-transparent [&_*]:invisible cursor-pointer select-none',
|
2022-09-29 21:28:04 +00:00
|
|
|
}),
|
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,
|
|
|
|
})
|
2022-09-16 06:37:17 +00:00
|
|
|
useEffect(
|
|
|
|
// Check isDestroyed here so hot reload works, see https://github.com/ueberdosis/tiptap/issues/1451#issuecomment-941988769
|
|
|
|
() => void !editor?.isDestroyed && editor?.commands?.setContent(content),
|
|
|
|
[editor, content]
|
|
|
|
)
|
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-30 09:41:47 +00:00
|
|
|
return <EditorContent className={className} editor={editor} />
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// backwards compatibility: we used to store content as strings
|
2022-08-10 02:04:55 +00:00
|
|
|
export function Content(props: {
|
|
|
|
content: JSONContent | string
|
2022-08-30 09:41:47 +00:00
|
|
|
className?: string
|
2022-08-10 02:04:55 +00:00
|
|
|
smallImage?: boolean
|
|
|
|
}) {
|
2022-08-30 09:41:47 +00:00
|
|
|
const { className, content } = 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
|
|
|
return typeof content === 'string' ? (
|
2022-08-30 09:41:47 +00:00
|
|
|
<Linkify
|
|
|
|
className={clsx(
|
|
|
|
className,
|
|
|
|
'whitespace-pre-line font-light leading-relaxed'
|
|
|
|
)}
|
|
|
|
text={content}
|
|
|
|
/>
|
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
|
|
|
)
|
|
|
|
}
|