Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mention): remove mention* props #369

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,6 @@ import { render } from 'react-dom'

import { MattersArticleEditor, MattersCommentEditor } from '../src'

const demoMentionUsers = [
{ id: v4(), displayName: 'user1', userName: 'user1' },
{ id: v4(), displayName: 'user2', userName: 'user2' },
]

const DemoMentionList = ({
mentionLoading,
mentionSelection,
mentionUsers,
}) => {
const style = {
width: '100%',
padding: '0.8rem 1rem',
textAlign: 'left' as const,
}

const handleMentionClick = (user: any) => mentionSelection(user)

return (
<>
{mentionUsers.map((user) => {
return (
<button
key={user.id}
type="button"
onClick={() => handleMentionClick(user)}
style={style}
>
{user.userName}
</button>
)
})}
</>
)
}

const App = () => {
const eventName = 'demo-event'

Expand All @@ -65,11 +29,6 @@ const App = () => {
return { id: v4(), path: source }
}

const mentionKeywordChange = (keyword: string) => {
// TODO: add search mention user api
// here we use defined demoMentionUsers for demo.
}

React.useEffect(() => {
window.addEventListener(eventName, (data: any) => {
// TODO: Process data and hook your notifier.
Expand All @@ -88,10 +47,6 @@ const App = () => {
enableToolbar={true}
eventName={eventName}
language="zh_hant"
mentionLoading={false}
mentionKeywordChange={mentionKeywordChange}
mentionUsers={demoMentionUsers}
mentionListComponent={DemoMentionList}
readOnly={false}
theme="bubble"
titleDefaultValue=""
Expand All @@ -103,10 +58,6 @@ const App = () => {
editorUpdate={(params) => setCommentContent(params.content)}
eventName={eventName}
language="en"
mentionLoading={false}
mentionKeywordChange={mentionKeywordChange}
mentionUsers={demoMentionUsers}
mentionListComponent={DemoMentionList}
readOnly={false}
theme="bubble"
texts={{
Expand Down
36 changes: 0 additions & 36 deletions src/article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react'
import ReactQuill, { Quill } from 'react-quill'

import Util from './blots/Util'
import MattersEditorMention from './components/Mention'
import MattersEditorSummary from './components/Summary'
import MattersEditorTitle from './components/Title'
import MattersEditorToolbar from './components/Toolbar'
Expand All @@ -23,10 +22,6 @@ interface Props {
enableToolbar?: boolean
eventName: string
language: Language
mentionLoading: boolean
mentionKeywordChange: (keyword: string) => void
mentionUsers: any
mentionListComponent: any
readOnly: boolean
summaryDefaultValue?: string
summaryReadOnly?: boolean
Expand All @@ -41,7 +36,6 @@ interface Props {

interface State {
content: string
mentionInstance: any
toolbarPosition: number
toolbarVisible: boolean
}
Expand All @@ -53,13 +47,11 @@ export class MattersArticleEditor extends React.Component<Props, State> {
private baseConfig: Record<string, any> = {}

private editorReference = React.createRef<ReactQuill>()
private mentionReference = React.createRef<HTMLElement>()

constructor(props: Props) {
super(props)
this.state = {
content: this.props.editorContent,
mentionInstance: null,
toolbarPosition: 0,
toolbarVisible: false,
}
Expand Down Expand Up @@ -179,18 +171,6 @@ export class MattersArticleEditor extends React.Component<Props, State> {
handleImageDrop = async (file: any): Promise<ResultData> =>
this.props.editorUpload({ file })

handleMentionChange = (keyword: string) => {
this.props.mentionKeywordChange(keyword)
}

handleMentionSelection = ({ id, userName, displayName }) => {
this.state.mentionInstance.insertMention({
id,
displayName,
userName,
})
}

eventDispatcher = (event: string, data: any) => {
if (this.props.eventName && window) {
window.dispatchEvent(new CustomEvent(event, { detail: { ...data } }))
Expand All @@ -212,9 +192,6 @@ export class MattersArticleEditor extends React.Component<Props, State> {
}
}

storeMentionInstance = (instance: any) =>
this.setState({ mentionInstance: instance })

render() {
const classes = this.props.readOnly ? 'u-area-disable' : ''

Expand All @@ -226,12 +203,6 @@ export class MattersArticleEditor extends React.Component<Props, State> {
handleImageDrop: this.handleImageDrop,
texts: this.texts,
},
mention: {
mentionContainer:
this.mentionReference && this.mentionReference.current,
handleMentionChange: this.handleMentionChange,
storeMentionInstance: this.storeMentionInstance,
},
}

if (this.props.enableReviseMode) {
Expand Down Expand Up @@ -281,13 +252,6 @@ export class MattersArticleEditor extends React.Component<Props, State> {
uploadAudioSizeLimit={this.props.uploadAudioSizeLimit}
uploadImageSizeLimit={this.props.uploadImageSizeLimit}
/>
<MattersEditorMention
mentionLoading={this.props.mentionLoading}
mentionListComponent={this.props.mentionListComponent}
mentionSelection={this.handleMentionSelection}
mentionUsers={this.props.mentionUsers}
reference={this.mentionReference}
/>
</div>
</>
)
Expand Down
37 changes: 0 additions & 37 deletions src/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import _debounce from 'lodash/debounce'
import React from 'react'
import ReactQuill, { Quill } from 'react-quill'

import MattersEditorMention from './components/Mention'
import { FORMAT_CONFIG, MODULE_CONFIG } from './configs/comment'
import { DEBOUNCE_DELAY, LANGUAGE } from './enums/common'
import { TEXT, Texts } from './enums/text'
Expand All @@ -13,10 +12,6 @@ interface Props {
editorUpdate: (params: Params) => void
eventName: string
language: Language
mentionLoading: boolean
mentionKeywordChange: (keyword: string) => void
mentionUsers: any
mentionListComponent: any
readOnly: boolean
theme: string
texts?: Texts
Expand All @@ -25,20 +20,17 @@ interface Props {

interface State {
content: string
mentionInstance: any
}

export class MattersCommentEditor extends React.Component<Props, State> {
private instance: Quill | null = null
private editorReference = React.createRef<ReactQuill>()
private mentionReference = React.createRef<HTMLElement>()
private texts: Texts = null

constructor(props: Props) {
super(props)
this.state = {
content: this.props.editorContent,
mentionInstance: null,
}

this.texts = {
Expand Down Expand Up @@ -71,18 +63,6 @@ export class MattersCommentEditor extends React.Component<Props, State> {
})
}

handleMentionChange = (keyword: string) => {
this.props.mentionKeywordChange(keyword)
}

handleMentionSelection = ({ id, userName, displayName }) => {
this.state.mentionInstance.insertMention({
id,
displayName,
userName,
})
}

eventDispatcher = (event: string, data: any) => {
if (this.props.eventName && window) {
window.dispatchEvent(new CustomEvent(event, { detail: { ...data } }))
Expand All @@ -105,18 +85,9 @@ export class MattersCommentEditor extends React.Component<Props, State> {
}
}

storeMentionInstance = (instance: any) =>
this.setState({ mentionInstance: instance })

render() {
const modulesConfig = {
...MODULE_CONFIG,
mention: {
mentionContainer:
this.mentionReference && this.mentionReference.current,
handleMentionChange: this.handleMentionChange,
storeMentionInstance: this.storeMentionInstance,
},
}

return (
Expand All @@ -134,14 +105,6 @@ export class MattersCommentEditor extends React.Component<Props, State> {
bounds="#editor-comment-container"
scrollingContainer={this.props.scrollingContainer}
/>

<MattersEditorMention
mentionLoading={this.props.mentionLoading}
mentionListComponent={this.props.mentionListComponent}
mentionSelection={this.handleMentionSelection}
mentionUsers={this.props.mentionUsers}
reference={this.mentionReference}
/>
</div>
</>
)
Expand Down
45 changes: 0 additions & 45 deletions src/components/Mention/index.tsx

This file was deleted.