11import { FC as FunctionComponent , useState , useEffect , useMemo } from "react" ;
22
3- import { Box , Flex , Typography } from "@strapi/design-system" ;
3+ import { Flex , Field } from "@strapi/design-system" ;
44import type { Schema } from "@strapi/types" ;
55import MDEditor , { commands , ICommand } from "@uiw/react-md-editor" ;
66import { useIntl } from "react-intl" ;
@@ -9,7 +9,7 @@ import { styled } from "styled-components";
99import "@uiw/react-markdown-preview/markdown.css" ;
1010
1111import { PLUGIN_ID } from '../utils/pluginId' ;
12- import { MediaLib } from "./MediaLib" ;
12+ import MediaLib from "./MediaLib" ;
1313import { useField } from "@strapi/strapi/admin" ;
1414
1515const Wrapper = styled . div `
@@ -34,6 +34,9 @@ const Wrapper = styled.div`
3434 img {
3535 max-width: 100%;
3636 }
37+ ul,ol{
38+ list-style:inherit;
39+ }
3740 .w-md-editor-preview {
3841 display: block;
3942 strong {
@@ -73,15 +76,19 @@ interface EditorProps {
7376 defaultMessage : string ;
7477 } ;
7578 required ?: boolean ;
79+ attribute ?: any ; // TO FIX
80+ labelAction ?: React . ReactNode ; //TO FIX TO CHECK
7681}
7782
7883const Editor : FunctionComponent < EditorProps > = ( {
84+ attribute,
7985 name,
80- intlLabel,
8186 disabled,
82- error,
83- description,
87+ labelAction,
8488 required,
89+ description,
90+ error,
91+ intlLabel,
8592} ) => {
8693 // const { formatMessage } = useIntl();
8794 const { onChange, value } : any = useField ( name ) ;
@@ -94,6 +101,7 @@ const Editor: FunctionComponent<EditorProps> = ({
94101
95102 const handleChangeAssets = ( assets : Schema . Attribute . MediaValue < true > ) => {
96103 let newValue = value ? value : "" ;
104+
97105 assets . map ( ( asset ) => {
98106 if ( asset . mime . includes ( "image" ) ) {
99107 const imgTag = `` ;
@@ -121,9 +129,9 @@ const Editor: FunctionComponent<EditorProps> = ({
121129
122130 const toolbarCommands = useMemo ( ( ) => {
123131 const strapiMediaLibrary : ICommand = {
124- name : "image " ,
125- keyCommand : "image " ,
126- buttonProps : { "aria-label" : "Insert image " } ,
132+ name : "media " ,
133+ keyCommand : "media " ,
134+ buttonProps : { "aria-label" : "Insert media " } ,
127135 icon : (
128136 < svg width = "12" height = "12" viewBox = "0 0 20 20" >
129137 < path
@@ -187,42 +195,36 @@ const Editor: FunctionComponent<EditorProps> = ({
187195 } , [ ] ) ;
188196
189197 return (
190- < Flex gap = { 0 } style = { { margin : 0 , padding : 0 } } >
191- < Box >
192- < Typography variant = "pi" fontWeight = "bold" >
193- { formatMessage ( intlLabel ) }
194- </ Typography >
195- { required && (
196- < Typography variant = "pi" fontWeight = "bold" textColor = "danger600" >
197- *
198- </ Typography >
199- ) }
200- </ Box >
201- < Wrapper >
202- < MDEditor
203- hidden = { disabled }
204- commands = { toolbarCommands }
205- value = { value || "" }
206- onChange = { ( newValue ) => {
207- onChange ( { target : { name, value : newValue || "" } } ) ;
208- } }
209- />
210- < div style = { { padding : "50px 0 0 0" } } />
211- { /* <MediaLib
212- isOpen={mediaLibVisible}
213- onChange={handleChangeAssets}
214- onToggle={handleToggleMediaLib}
215- /> */ }
216- </ Wrapper >
217- { error && (
218- < Typography variant = "pi" textColor = "danger600" >
219- { formatMessage ( { id : error , defaultMessage : error } ) }
220- </ Typography >
221- ) }
222- { description && (
223- < Typography variant = "pi" > { formatMessage ( description ) } </ Typography >
224- ) }
225- </ Flex >
198+ < Field . Root
199+ name = { name }
200+ id = { name }
201+ error = { error }
202+ hint = { description && formatMessage ( description ) }
203+ >
204+ < Flex spacing = { 1 } alignItems = "normal" style = { { 'flexDirection' : 'column' } } >
205+ < Field . Label action = { labelAction } required = { required } >
206+ { intlLabel ? formatMessage ( intlLabel ) : name }
207+ </ Field . Label >
208+ < Wrapper >
209+ < MDEditor
210+ hidden = { disabled }
211+ commands = { toolbarCommands }
212+ value = { value || "" }
213+ onChange = { ( newValue ) => {
214+ onChange ( { target : { name, value : newValue || "" } } ) ;
215+ } }
216+ />
217+ </ Wrapper >
218+ < Field . Hint />
219+ < Field . Error />
220+ </ Flex >
221+ < MediaLib
222+ /*allowedTypes={['images']}*/
223+ isOpen = { mediaLibVisible }
224+ onChange = { handleChangeAssets }
225+ onToggle = { handleToggleMediaLib }
226+ />
227+ </ Field . Root >
226228 ) ;
227229} ;
228230
0 commit comments