const fs = require('fs')
const path = require('path')
const DIRNAME = fs.realpathSync(process.cwd())
const PATHS = {
app: path.join(DIRNAME, 'src'),
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
class Store { | |
// Ordinal numbers sequence. | |
ordinal = null | |
// Ordinal numbers generator. | |
ordinalGenerator = function * () { | |
let i = 0 | |
while (true) { | |
yield i++ | |
} |
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
// Required Draf-js version: 0.10. | |
// Live example: https://jsfiddle.net/schabluk/gh2gt22n/ | |
import React from 'react' | |
import ReactDOM from 'react-dom' | |
import {Editor, EditorState, EditorBlock} from 'draft-js' | |
class Line extends React.Component { | |
render () { | |
const blockMap = this.props.contentState.getBlockMap().toArray() |
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
onDrop = (acceptedFiles, rejectedFiles) => { | |
const file = acceptedFiles.find(f => f) | |
const i = new Image() | |
i.onload = () => { | |
let reader = new FileReader() | |
reader.readAsDataURL(file) | |
reader.onload = () => { | |
console.log({ | |
src: file.preview, |
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
import React, { PropTypes } from 'react' | |
/** | |
* Moving click handler function outside of the component | |
* follows the separation of concerns principle (SoC). | |
*/ | |
const _handleClick = (onSelect, event, id) => { | |
// Additional steps before handling action. | |
event.preventDefault() | |
event.stopPropagation() |
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
const startKey = editorState.getSelection().getStartKey() | |
const startOffset = editorState.getSelection().getStartOffset() | |
const block = editorState.getCurrentContent().getBlockForKey(startKey) | |
const entityKey = block.getEntityAt(startOffset) |
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
const children = [].slice.call(this.snippetsList.node.children) | |
console.log( | |
data.node, | |
children.indexOf(data.node) | |
) |
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
const stylesFilter = v => v.hasStyle('HIGHLIGHT') | |
editorState.getCurrentContent().getBlockForKey(anchorKey).findStyleRanges(stylesFilter, (start, end) => { | |
contentState = removeStyle(contentState, anchorKey, start, end, 'HIGHLIGHT') | |
}) |
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
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e)))) | |
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a) | |
cartesian.apply(this, [["A", "B"], ["C", "D"]]) |
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
const hexToRGB = (hex, alpha) => { | |
const r = parseInt(hex.slice(1, 3), 16) | |
const g = parseInt(hex.slice(3, 5), 16) | |
const b = parseInt(hex.slice(5, 7), 16) | |
if (alpha) return `rgba(${r}, ${g}, ${b}, ${alpha})` | |
return `rgb(${r}, ${g}, ${b})` | |
} |
OlderNewer