-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from virtualidentityag/release-2024-03-20
release 2024-03-20
- Loading branch information
Showing
35 changed files
with
1,159 additions
and
545 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 |
---|---|---|
|
@@ -39,15 +39,15 @@ jobs: | |
env: | ||
GITHUB_TOKEN: ${{ secrets.github_token }} | ||
- name: Bump version | ||
if: startsWith(env.BRANCH,'release') == true | ||
if: env.BRANCH == 'release' | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
yarn run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.github_token }} | ||
- name: Push changes | ||
if: startsWith(env.BRANCH,'release') == true | ||
if: env.BRANCH == 'release' | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
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
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,132 @@ | ||
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; | ||
import DisabledContext from 'antd/es/config-provider/DisabledContext'; | ||
import { | ||
ContentState, | ||
convertFromHTML, | ||
DraftEditorCommand, | ||
DraftHandleValue, | ||
EditorState, | ||
getDefaultKeyBinding, | ||
RichUtils, | ||
} from 'draft-js'; | ||
import { stateToHTML } from 'draft-js-export-html'; | ||
import PluginsEditor from '@draft-js-plugins/editor'; | ||
import classNames from 'classnames'; | ||
import createPlaceholderPlugin from '../../utils/draftjs/placeholderPlugin'; | ||
|
||
const Editor = ({ | ||
onChange, | ||
value = '', | ||
onSelectionChange, | ||
onInlineStyleChange, | ||
placeholders, | ||
onBlur, | ||
onFocus, | ||
placeholder, | ||
editorPlugins, | ||
}: any) => { | ||
const disabled = useContext(DisabledContext); | ||
|
||
const plugins = useMemo(() => [...editorPlugins, createPlaceholderPlugin({ placeholders })], [placeholders]); | ||
|
||
const [editorState, setEditorState] = useState<EditorState>(() => { | ||
const { contentBlocks, entityMap } = convertFromHTML(value); | ||
const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap); | ||
return EditorState.createWithContent(contentState); | ||
}); | ||
|
||
useEffect(() => { | ||
setEditorState((state) => { | ||
const contentState = state.getCurrentContent(); | ||
contentState.getAllEntities().forEach((entity, entityKey) => { | ||
contentState.mergeEntityData(entityKey, { disabled }); | ||
}); | ||
return EditorState.createWithContent(contentState, state.getDecorator()); | ||
}); | ||
}, [disabled]); | ||
|
||
useEffect(() => { | ||
const resetState = () => { | ||
if (editorState.getSelection().getHasFocus()) return; | ||
onSelectionChange(undefined); | ||
onInlineStyleChange(undefined); | ||
}; | ||
|
||
const selection = editorState.getSelection(); | ||
if (!selection.getHasFocus()) return resetState; | ||
onSelectionChange(selection); | ||
onInlineStyleChange(editorState.getCurrentInlineStyle()); | ||
|
||
return resetState; | ||
}, [editorState, onSelectionChange, onInlineStyleChange]); | ||
|
||
const handleChange = useCallback( | ||
(edited: EditorState) => { | ||
setEditorState(edited); | ||
const contentState = edited.getCurrentContent(); | ||
onChange(contentState.hasText() ? stateToHTML(contentState) : ''); | ||
}, | ||
[onChange], | ||
); | ||
|
||
// Just because the library isn't properly typed | ||
const extraProps = { onBlur, onFocus }; | ||
|
||
const className = [`RichEditor-editor`]; | ||
const contentState = editorState.getCurrentContent(); | ||
if (disabled) { | ||
className.push('RichEditor-disabled'); | ||
} else if (!contentState.hasText()) { | ||
if (contentState.getBlockMap().first().getType() !== 'unstyled') { | ||
className.push('RichEditor-hidePlaceholder'); | ||
} | ||
} | ||
|
||
const handleKeyCommand = useCallback((command: string, editorStat: EditorState): DraftHandleValue => { | ||
const newState = RichUtils.handleKeyCommand(editorStat, command); | ||
if (newState) { | ||
handleChange(newState); | ||
return 'handled'; | ||
} | ||
return 'not-handled'; | ||
}, []); | ||
|
||
const mapKeyToEditorCommand = useCallback( | ||
(e): DraftEditorCommand | null => { | ||
if (e.keyCode === 9) { | ||
const newEditorState = RichUtils.onTab(e, editorState, 4); | ||
if (newEditorState === editorState) { | ||
handleChange(newEditorState); | ||
} | ||
return null; | ||
} | ||
return getDefaultKeyBinding(e); | ||
}, | ||
[editorState], | ||
); | ||
|
||
const editorRef = useRef<any>(); | ||
const focus = useCallback(() => { | ||
editorRef.current.focus(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */} | ||
<div className={classNames(className)} onClick={focus}> | ||
<PluginsEditor | ||
ref={editorRef} | ||
editorState={editorState} | ||
onChange={handleChange} | ||
placeholder={placeholder} | ||
plugins={plugins} | ||
readOnly={disabled} | ||
{...extraProps} | ||
handleKeyCommand={handleKeyCommand} | ||
keyBindingFn={mapKeyToEditorCommand} | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
export default 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 |
---|---|---|
|
@@ -53,6 +53,10 @@ | |
} | ||
} | ||
|
||
&-disabled { | ||
cursor: not-allowed; | ||
} | ||
|
||
&-toolbar { | ||
&-link, | ||
&-image, | ||
|
Oops, something went wrong.