This file contains hidden or 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
function useOnClickOutside( | |
ref: React.RefObject<HTMLDivElement>, | |
handler: (event: TouchEvent | MouseEvent) => void, | |
) { | |
useEffect(() => { | |
const listener = (event: TouchEvent | MouseEvent) => { | |
if (!ref.current || ref.current.contains(event.target as HTMLElement)) { | |
return; | |
} | |
handler(event); |
This file contains hidden or 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
// Пузырьковая сортировка | |
function bubbleSort(a){ | |
var n = a.length; | |
for (var i = 0; i < n-1; i++){ // Выполняется для каждого элемента массива, кроме последнего. | |
for (var j = 0; j < n-1-i; j++){ // Для всех последующих за текущим элементов | |
if (a[j+1] < a[j]){ // выпоняется проверка, и если следующий элемент меньше текущего | |
var t = a[j+1]; a[j+1] = a[j]; a[j] = t; // то эти элементы меняются местами. | |
} | |
} | |
} |
This file contains hidden or 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
... | |
import converter from './converter'; | |
... | |
logMarkup() { | |
const markup = converter(this.state.editorState.getCurrentContent()); // <-- [1] | |
document.getElementById('js-markup-container').innerHTML = markup; | |
console.log('markup ==> ', markup); // <-- [2] | |
const sliders = document.querySelectorAll('.js-slider');// <-- [3] |
This file contains hidden or 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
... | |
export const options = { // <-- [1] | |
styleToHTML, | |
blockToHTML, | |
entityToHTML, | |
}; | |
const converterFunction = convertToHTML(options); // <-- [2] | |
export default contentState => converterFunction(contentState); |
This file contains hidden or 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
import React from 'react'; | |
import { convertToHTML } from 'draft-convert'; | |
export const styleToHTML = (style) => { // <-- [1] | |
switch (style) { | |
case 'ITALIC': | |
return <em className="italic" />; | |
case 'BOLD': | |
return <strong className="bold" />; | |
case 'HIGHLIGHT': |
This file contains hidden or 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
updateData(data) { | |
const editorState = this.props.blockProps.getEditorState(); | |
const content = editorState.getCurrentContent(); | |
const selection = new SelectionState({ | |
anchorKey: this.props.block.key, | |
anchorOffset: 0, | |
focusKey: this.props.block.key, | |
focusOffset: this.props.block.getLength() | |
}); |
This file contains hidden or 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
handleDroppedFiles(selection, files) { | |
const filteredFiles = files | |
.filter(file => (file.type.indexOf('image/') === 0)); // <-- [1] | |
if (!filteredFiles.length) { | |
return 'not_handled'; | |
} | |
this.onChange(addNewBlockAt( // <-- [2] | |
this.state.editorState, |
This file contains hidden or 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
render() { | |
... | |
<Editor | |
editorState={editorState} | |
onChange={this.onChange} | |
handleKeyCommand={this.handleKeyCommand} | |
customStyleMap={customStyleMap} | |
handleDroppedFiles={this.handleDroppedFiles} // <-- [3] | |
handleReturn={this.handleReturn} // <-- [2] | |
blockRenderMap={RenderMap} // <-- [1] |
This file contains hidden or 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
constructor() { | |
... | |
this.getEditorState = () => this.state.editorState; | |
this.blockRendererFn = customBlockRenderer( | |
this.onChange, | |
this.getEditorState | |
); | |
} | |
... |
This file contains hidden or 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
function findLinkEntities(contentBlock, callback, contentState) { | |
contentBlock.findEntityRanges( | |
(character) => { | |
const entityKey = character.getEntity(); | |
return ( | |
entityKey !== null && | |
contentState.getEntity(entityKey).getType() === 'LINK' | |
); | |
}, | |
callback |
NewerOlder