-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c171d27
commit 1762ec9
Showing
18 changed files
with
2,350 additions
and
4,114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,5 @@ cypress/screenshots | |
|
||
# Instrumented code for cypress code coverage | ||
instrumented | ||
|
||
/tinymce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/sensenet/src/components/field-controls/tinymce-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @module FieldControls | ||
*/ | ||
import { ReactClientFieldSetting, TinymceEditor as SnTinymceEditor } from '@sensenet/controls-react' | ||
import React from 'react' | ||
import { useLocalization } from '../../hooks' | ||
|
||
/** | ||
* Field control that represents a RichText field. Available values will be populated from the FieldSettings. | ||
*/ | ||
export const TinymceEditor: React.FC<ReactClientFieldSetting> = (props) => { | ||
const localization = useLocalization() | ||
|
||
return <SnTinymceEditor {...props} localization={{ richTextEditor: localization.editor }} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { Editor as default } from '@sensenet/editor-react' | ||
export { Editor as default, TinymceEditor } from '@sensenet/editor-react' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/sn-controls-react/src/fieldcontrols/tinymce-editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* @module FieldControls | ||
*/ | ||
import { CircularProgress, createStyles, FormHelperText, InputLabel, makeStyles, Typography } from '@material-ui/core' | ||
import { deepMerge } from '@sensenet/client-utils' | ||
import { renderHtml } from '@sensenet/editor-react' | ||
import React, { lazy, Suspense } from 'react' | ||
import { changeTemplatedValue } from '../helpers' | ||
import { ReactClientFieldSetting } from './client-field-setting' | ||
import { defaultLocalization } from './localization' | ||
const Editor = lazy(() => import('../editor-wrapper').then((module) => ({ default: module.TinymceEditor }))) | ||
|
||
const useStyles = makeStyles(() => | ||
createStyles({ | ||
richTextEditor: {}, | ||
}), | ||
) | ||
|
||
type RichTextEditorClassKey = Partial<ReturnType<typeof useStyles>> | ||
|
||
interface ParsedRichTextFieldValue { | ||
text: string | ||
editor: string | ||
} | ||
|
||
const getFieldValue = (rawValue?: string) => { | ||
let value | ||
|
||
if (rawValue === undefined || rawValue === null) { | ||
return undefined | ||
} | ||
|
||
try { | ||
value = JSON.parse(rawValue) as ParsedRichTextFieldValue | ||
} catch (_) { | ||
return rawValue | ||
} | ||
|
||
try { | ||
return value.editor ? JSON.parse(value.editor) : value.text | ||
} catch (_) { | ||
return value.text | ||
} | ||
} | ||
|
||
/** | ||
* Field control that represents a LongText field. Available values will be populated from the FieldSettings. | ||
*/ | ||
export const TinymceEditor: React.FC< | ||
ReactClientFieldSetting & { classes?: RichTextEditorClassKey; fieldValue?: string } | ||
> = (props) => { | ||
const localization = deepMerge(defaultLocalization.richTextEditor, props.localization?.richTextEditor) | ||
|
||
const initialState = | ||
getFieldValue(props.fieldValue) || | ||
(props.actionName === 'new' && changeTemplatedValue(props.settings.DefaultValue)) || | ||
'' | ||
const classes = useStyles(props) | ||
|
||
switch (props.actionName) { | ||
case 'edit': | ||
case 'new': | ||
return ( | ||
<div className={classes.richTextEditor}> | ||
<InputLabel shrink htmlFor={props.settings.Name} required={props.settings.Compulsory}> | ||
{props.settings.DisplayName} | ||
</InputLabel> | ||
|
||
<Suspense | ||
fallback={ | ||
<div style={{ textAlign: 'center' }}> | ||
<CircularProgress /> | ||
<div>{localization.loading}</div> | ||
</div> | ||
}> | ||
<Editor | ||
initvalue={initialState} | ||
onChange={(content) => { | ||
props.fieldOnChange?.(props.settings.Name, content) | ||
}} | ||
/> | ||
</Suspense> | ||
|
||
{!props.hideDescription && <FormHelperText>{props.settings.Description}</FormHelperText>} | ||
</div> | ||
) | ||
case 'browse': | ||
default: | ||
return ( | ||
<div> | ||
<Typography variant="caption" gutterBottom={true}> | ||
{props.settings.DisplayName} | ||
</Typography> | ||
{initialState ? ( | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: typeof initialState === 'string' ? initialState : renderHtml(initialState), | ||
}} | ||
/> | ||
) : ( | ||
<Typography variant="body1" gutterBottom={true}> | ||
{localization.noValue} | ||
</Typography> | ||
)} | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,4 @@ typings/ | |
dist | ||
temp | ||
bundle | ||
/public/tinymce/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './components' | ||
export * from './context' | ||
export * from './utils' | ||
export * from './tinymce' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Editor, IAllProps } from '@tinymce/tinymce-react' | ||
import React, { FC, useRef } from 'react' | ||
import { Editor as TinyMCEEditor } from 'tinymce' | ||
|
||
export interface TinymceEditorProps { | ||
onChange?: IAllProps['onEditorChange'] | ||
initvalue?: string | ||
} | ||
|
||
export const TinymceEditor: FC<TinymceEditorProps> = (props) => { | ||
const editorRef = useRef<TinyMCEEditor | null>(null) | ||
return ( | ||
<> | ||
<Editor | ||
tinymceScriptSrc="/tinymce/tinymce.min.js" | ||
licenseKey="gpl" | ||
onInit={(_evt, editor) => (editorRef.current = editor)} | ||
initialValue={props.initvalue} | ||
init={{ | ||
height: 500, | ||
menubar: false, | ||
plugins: [ | ||
'advlist', | ||
'autolink', | ||
'lists', | ||
'link', | ||
'image', | ||
'charmap', | ||
'anchor', | ||
'searchreplace', | ||
'visualblocks', | ||
'code', | ||
'fullscreen', | ||
'insertdatetime', | ||
'media', | ||
'table', | ||
'preview', | ||
'help', | ||
'wordcount', | ||
], | ||
toolbar: | ||
'undo redo | blocks | ' + | ||
'bold italic forecolor | alignleft aligncenter ' + | ||
'alignright alignjustify | bullist numlist outdent indent | ' + | ||
'removeformat | help', | ||
content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }', | ||
}} | ||
onEditorChange={(e, editor) => { | ||
if (props.onChange) { | ||
props.onChange(e, editor) | ||
} | ||
}} | ||
/> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Editor' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path from 'path' | ||
import * as url from 'url' | ||
import fs from 'fs-extra' | ||
// const topDir = import.meta.dirname | ||
|
||
try { | ||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) | ||
fs.emptyDirSync(path.join(__dirname, 'apps', 'sensenet', 'tinymce')) | ||
fs.copySync(path.join(__dirname, 'node_modules', 'tinymce'), path.join(__dirname, 'apps', 'sensenet', 'tinymce'), { | ||
overwrite: true, | ||
}) | ||
|
||
console.log('tinymcye has been installed') | ||
} catch (error) { | ||
console.error(error) | ||
} |
Oops, something went wrong.