Skip to content

Commit

Permalink
Update tsconfig and refactor (niuware#207)
Browse files Browse the repository at this point in the history
* Set noUnusedLocals in tsconfig

* Remove unused type

* Refactor setupStyleMap function

* Refactor setupBlockMap function

* Refactor blockRenderer function

* Remove unused parameter from styleRenderer function

* Bump package version
  • Loading branch information
niuware authored Nov 5, 2020
1 parent acf3eb9 commit 573cf34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mui-rte",
"version": "1.26.0",
"version": "1.26.1",
"description": "Material-UI Rich Text Editor and Viewer",
"keywords": [
"material-ui",
Expand Down
42 changes: 15 additions & 27 deletions src/MUIRichTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ type TPosition = {
left: number
}

type TCustomRenderers = {
style?: DraftStyleMap
block?: Immutable.Map<any, any>
}

const styles = ({ spacing, typography, palette }: Theme) => createStyles({
root: {
},
Expand Down Expand Up @@ -889,13 +884,10 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT

const setupStyleMap = () => {
const customStyleMap = JSON.parse(JSON.stringify(styleRenderMap))
if (props.customControls) {
props.customControls.forEach(control => {
if (control.type === "inline" && control.inlineStyle) {
customStyleMap[control.name.toUpperCase()] = control.inlineStyle
}
props.customControls?.filter(control => control.type === "inline" && control.inlineStyle)
.forEach(control => {
customStyleMap[control.name.toUpperCase()] = control.inlineStyle
})
}
customStyleMapRef.current = customStyleMap
}

Expand All @@ -908,16 +900,13 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT

const setupBlockMap = () => {
const customBlockMap: any = {}
if (props.customControls) {
props.customControls.forEach(control => {
if (control.type === "block" && control.blockWrapper) {
customBlockMap[control.name.toUpperCase()] = {
element: "div",
wrapper: control.blockWrapper
}
props.customControls?.filter(control => control.type === "block" && control.blockWrapper)
.forEach(control => {
customBlockMap[control.name.toUpperCase()] = {
element: "div",
wrapper: control.blockWrapper
}
})
}
customBlockMapRef.current = DefaultDraftBlockRenderMap.merge(blockRenderMap, Immutable.Map(customBlockMap))
}

Expand All @@ -940,21 +929,20 @@ const MUIRichTextEditor: RefForwardingComponent<TMUIRichTextEditorRef, IMUIRichT
}
} else {
const block = atomicBlockExists(type.toLowerCase(), props.customControls)
if (!block) {
return null
}
return {
component: block.atomicComponent,
editable: false,
props: contentState.getEntity(contentBlock.getEntityAt(0)).getData()
if (block) {
return {
component: block.atomicComponent,
editable: false,
props: contentState.getEntity(contentBlock.getEntityAt(0)).getData()
}
}
}
}
}
return null
}

const styleRenderer = (style: any, _block: ContentBlock): React.CSSProperties => {
const styleRenderer = (style: any): React.CSSProperties => {
const customStyleMap = getStyleMap()
const styleNames = style.toJS()
return styleNames.reduce((styles: any, styleName: string) => {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"esModuleInterop": true,
"noImplicitReturns": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"outDir": "dist",
"baseUrl": ".",
"jsx": "react",
Expand Down

0 comments on commit 573cf34

Please sign in to comment.