λ§μ μ¬λλ€κ³Ό λ§μ°¬κ°μ§λ‘ λμκ²λ μ λ ¬ κ°λ₯ν μΉ΄λ λͺ©λ‘μ΄ μμ΅λλ€. μ κ²½μ°μλ κ° μΉ΄λκ° λΈλ‘κ·Έ κ²μλ¬Όμ μ½ν
μΈ λΈλ‘μ΄κ³ μ΄ μ€ μΌλΆλ react-codemirror
λ λλ§λ μ½λ μ‘°κ°μ
λλ€. μ€λν«μ λν λλκ·Έ 미리보기μλ codemirrorμ μ½λ νΈμ§κΈ° λ΄ ν
μ€νΈμ λλΉ λ° λμ΄μ λμΌν ν° ν°μ λ°°κ²½μ΄ ν¬ν¨λμμ΅λλ€. μ΄κ²μ λ°λμ§νμ§ μμ CSSλ‘ μμ νλ €κ³ μλνμ§λ§ μ΄μ΄ μμμ΅λλ€. λ λ§μ λ¬Έμλ₯Ό μ½μΌλ©΄μ μλ‘μ΄ ν΄λμ€λ μ€νμΌμ΄ μ μ©λκΈ° μ μ dndκ° dom λ
Έλλ₯Ό μ€ν¬λ¦°μ·νκΈ° λλ¬Έμ λΆκ°λ₯νλ€κ³ μκ°ν©λλ€. λ¬Όλ‘ κ·Έκ²μ΄ μλͺ»λ κ²½μ°)
CSSλ₯Ό μλν μ μμκΈ° λλ¬Έμ μ¬μ©μ μ μ λλκ·Έ λ μ΄μ΄λ₯Ό μ¬μ©νμ¬ λ―Έλ¦¬λ³΄κΈ°μ λν΄ λ€λ₯Έ κ²μ νμνλ €κ³ νμ΅λλ€. μ΄κ²μ μ΄μ μ μ€μ λ‘ λ§€μ° λΆλλ¬μ λ λλκ·Έκ° μ€μ λ‘ κ³ λ₯΄μ§ μκ² λλ κ²μ μ μΈνκ³ λ νλ₯νκ² μλν©λλ€.
λ€μμ λ°©κΈ μ€λͺ ν λ¬Έμ λ₯Ό 보μ¬μ£Όλ λΉλμ€μ λλ€.
https://drive.google.com/file/d/0Bzbw-6Q_sVTySUNiNmJGcFVIQ00/view?usp=sharing
κ·Έλ¦¬κ³ λλ λΉμ μ΄ λν λͺ κ°μ§ μ½λλ₯Ό λ³΄κ³ μΆμ΄ν κ²μ΄λΌκ³ μκ°ν©λλ€. μ¬κΈ° λ΄ μ¬μ©μ μ μ λλκ·Έ λ μ΄μ΄κ° μμ΅λλ€
import React, { Component, PropTypes } from 'react'
import { DragLayer } from 'react-dnd'
function collect(monitor) {
return {
item: monitor.getItem(),
currentOffset: monitor.getSourceClientOffset(),
isDragging: monitor.isDragging()
}
}
const layerStyles = {
position: 'fixed',
pointerEvents: 'none',
zIndex: 100,
left: 0,
top: 0,
width: '20%',
height: '100%'
}
function getItemStyles(props) {
var currentOffset = props.currentOffset
if (!currentOffset) {
return {
display: 'none'
}
}
var x = currentOffset.x
var y = currentOffset.y
var transform = 'translate(' + x + 'px, ' + y + 'px)'
return {
transform: transform,
WebkitTransform: transform
}
}
class CardDragLayer extends Component {
static propTypes = {
item: PropTypes.object
}
render() {
const { item, isDragging } = this.props
if (!isDragging)
return false
return (
<div style={layerStyles}>
<div className='drag-preview' style={getItemStyles(this.props)}>
<i className='fa fa-hand-scissors-o fa-6'></i>
</div>
</div>
)
}
}
export default DragLayer(collect)(CardDragLayer)
λλκ·Έ μμ€ λ° λλ‘ λμμ λν κ΅¬μ± μ΅μ μ λ€μκ³Ό κ°μ΅λλ€.
export const cardSource = {
beginDrag(props) {
return {
index: props.index
}
}
}
export const cardTarget = {
hover(props, monitor, component) {
const dragIndex = monitor.getItem().index
const hoverIndex = props.index
if (dragIndex === hoverIndex)
return
props.swap(dragIndex, hoverIndex)
monitor.getItem().index = hoverIndex;
}
}
export function collectSource(connect, monitor) {
return {
connectDragSource: connect.dragSource(),
connectDragPreview: connect.dragPreview(),
isDragging: monitor.isDragging()
}
}
export function collectTarget(connect) {
return {
connectDropTarget: connect.dropTarget()
}
}
κ·Έλ¦¬κ³ μ¬κΈ°μ λλκ·Έλλ Card
κ΅¬μ± μμκ° μμ΅λλ€.
import React, { PropTypes, Component } from 'react'
import { Snippet, Markdown } from './Show'
import { DragSource, DropTarget } from 'react-dnd'
import { getEmptyImage } from 'react-dnd-html5-backend'
import { cardSource, cardTarget, collectSource, collectTarget } from './dragDropConfig'
import classnames from 'classnames'
class SnippetCard extends Component {
options() {
return {
readOnly: true,
scrollbarStyle: 'null',
viewportMargin: Infinity
}
}
render() {
const { language, text } = this.props
return(
<Snippet
options={this.options()}
language={language.value}
text={text.value} />
)
}
}
class MarkdownCard extends Component {
render() {
const { text } = this.props
return (
<div className='markdown-card'>
<div className='card-content'>
<Markdown text={text.value} />
</div>
</div>
)
}
}
const components = {
snippet: SnippetCard,
markdown: MarkdownCard
}
class Card extends Component {
static propTypes = {
connectDragSource: PropTypes.func.isRequired,
connectDropTarget: PropTypes.func.isRequired,
index: PropTypes.number.isRequired,
block: PropTypes.object.isRequired,
swap: PropTypes.func.isRequired
}
componentDidMount() {
const { connectDragPreview } = this.props
connectDragPreview(getEmptyImage(), {
captureDraggingState: true
})
}
render() {
const { isDragging, block, connectDragSource, connectDropTarget } = this.props
const Component = components[block.format.value]
const classes = classnames('card', {
dragging: isDragging
})
return connectDragSource(connectDropTarget((
<div className={classes}>
<div className='card-header'>
<div>
<label>
{block.format.value}
</label>
</div>
<Component {...block} />
</div>
</div>
)))
}
}
const Source = DragSource('card', cardSource, collectSource)(Card)
export default DropTarget('card', cardTarget, collectTarget)(Source)
κ·Έλ³΄λ€ λ λ§μ μ½λκ° νμνλ©΄ μλ €μ£Όμμμ€. μ΄ μ λλ©΄ μΆ©λΆνλ€κ³ μκ°ν©λλ€.
a) CSSλ₯Ό μ¬μ©νμ¬ ν°μ λ°°κ²½μ μ¨κΈ°λ λ°©λ² λλ b) μ¬μ©μ μ μ λλκ·Έ 미리보기 λλκ·Έλ₯Ό λ λΆλλ½κ² λ§λλ λ°©λ²μ λν μ μμ λ§€μ° κ°μ¬νκ² μ΅λλ€!
μ΄ μμ μ react/reduxλ₯Ό μ¬μ©νμ¬ μ±μ λΉλνλ μ€ν¬λ¦°μΊμ€νΈ κ³Όμ μ μΌλΆμ΄λ©° μ λ ¬ κ°λ₯ν μ½ν μΈ λΈλ‘ μΉ΄λκ° κ΅¬νλλ λ°©λ²μ 보μ¬μ£ΌκΈ° μν΄ react-dndμμ 2-3κ°μ 짧μ λΉλμ€λ₯Ό λ§λ€ κ³νμ λλ€. κ°λ₯ν 빨리 μΆμλκΈ°λ₯Ό λ°λλλ€!
μ¬μ©μ μ μ dragLayerμμλ κ³ λ₯΄μ§ λͺ»ν νμμ λ°κ²¬νμ΅λλ€(μΉ μ¬μ΄νΈ μμ μ€ν): http://gaearon.github.io/react-dnd/examples-drag-around-custom-drag-layer.html
Chromeμμλ λͺ¨λ μ μμ΄μ§λ§ Firefoxμμλ μ λλ©μ΄μ μ΄ κ³ λ₯΄μ§ μμ΅λλ€. (리λ μ€ λ―ΌνΈ, νμ΄μ΄νμ€ 46.0.1)
그건 κ·Έλ κ³ λ©μ§ λμκ΄!
@sslotsky μ΄κ²μ μμλΈ μ μ΄ μμ΅λκΉ?
κ·Έλ μ§ μμ κ²½μ° μ΄ λ¬Έμ μ λν΄ μμΈν μμλ³΄κ³ CSSμμ μ°λ¦¬κ° ν μ μλ μ리ν κ²μ΄ μλμ§ λλ κ³ λ₯΄μ§ λͺ»ν κ²μ μ€μ΄κΈ° μν΄ ν μ μλ κ²μ΄ μλμ§ νμΈν μ μμ΅λλ€. λ€λ₯Έ μ¬λλ€μ μ¬μ©μ μ μ λλκ·Έ λ μ΄μ΄ μ±λ₯μ΄ λ§μ΄ λΆμ‘±νλ€κ³ λ³΄κ³ νμ΅λλ€.
μλμ, μμ§ μμλ΄μ§ λͺ»νμ΅λλ€. λ€μ λΉλμ€λ₯Ό λ Ήννλ €κ³ ν λ μ루μ μ΄ μ’μ κ²μ λλ€!
μ°λ¦¬λ λν μ΄κ²μ λ³΄κ³ μμΌλ©° λͺ¨λ μ λ°μ΄νΈλ₯Ό μν΄ μ΄ λ¬Έμ λ₯Ό ꡬλ ν©λλ€.
@kesne μ΄κ²μ μ μ§νκΈ° μν΄ λκΈμ
λ€, μ λ μ΄μ λν ν΄κ²°μ± μ μν©λλ€. λ¨μν λλκ·Έ κ°λ₯ν κ°μ²΄μ μ€ν¬λ¦°μ· μ΄μμ ꡬννλ €κ³ νμ§λ§ λ³Έμ§μ μΌλ‘ λ§€μ° κ°λ¨ν λ°μ κ΅¬μ± μμλ₯Ό ꡬννλ €κ³ ν©λλ€.
μ΄κ²λ λμ§κ² μ΅λλ€. μ°λ¦¬λ κ°μ λ¬Έμ λ₯Ό λ³΄κ³ μμ΅λλ€.
λλ μ΄κ²μΌλ‘ μ€ννκ³ μμ΅λλ€. κ°λ¨ν λλκ·Έ μ€ λλ‘μ΄ μ μλν©λλ€. κ·Έλ¬λ λ무 볡μ‘ν ꡬνμ΄ μλλ° μ΄κ²μ΄ μΌμ΄λκ³ μμ΅λλ€.
κ°μ λ¬Έμ κ° μμ΅λλ€. μ무λ ν΄κ²°μ± μ΄λ ν΄κ²° λ°©λ²μ μκ°ν΄ λμ΅λκΉ?
@alexey-belous μ°λ¦¬λ μ΄ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ€ν¬λ©νκ³ https://github.com/bevacqua/react-dragulaλ₯Ό μ¬μ©νμ΅λλ€.
μ¬κΈ°μ λμΌν λ¬Έμ κ° μμΌλ©΄ μΆκ° μκ²¬μ΄ μμΌλ©΄ κΈ°μ κ²μ λλ€.
μ΄ λ¬Έμ λ₯Ό μ‘°μ¬ν κ²°κ³Ό dom λ Έλλ₯Ό λλκ·Ένλ μ€ν¬λ¦°μ·μ΄ λΈλΌμ°μ μ 무κ΄νκ² Windowsμμλ§ ν¬λͺ νλ€λ κ²μ μμλμ΅λλ€.
getItemStyles(props) λ©μλμμ console.log()λ₯Ό μ κ±°νμ¬ νμ§μ ν¬κ² ν₯μμν¬ μ μμμ΅λλ€. μ΄κ²μ OPμ λμμ΄ λμ§ μμ§λ§ μλ§λ λ€λ₯Έ λκ΅°κ°κ° μ¬κΈ°μ κ±Έλ € λμ΄μ§ μ μμ΅λλ€.
κ·Έλμ μ΄κ²μ 볡μ νκ³ dev μλ²λ₯Ό μ€ννλλ° μ¬μ©μ μ§μ λλκ·Έ 미리 보기 μμ λ κ³ λ₯΄μ§ μμ΅λλ€. κ·Έλ¬λ μ¬μ΄νΈλ₯Ό λΉλν λ( npm run build-site
) μ¬μ΄νΈκ° μΌλ° λ§ν¬μ
(React κ΅¬μ± μμ μ°Έμ‘° μμ΄)μΌλ‘ λ³νλκ³ μ΄μ λλκ·Έ 미리 보기 μμ κ° μννκ² μ€νλ©λλ€.
κ·Έλμ λ΄ κ°μ€μ ReactDOM.renderToString(
μ΄κ²μ μ¬μ ν ββμ€μν λ¬Έμ μ λλ€ ... :(
@gaearon μ°λ¦¬λ λΉμ μ μ¬λν©λλ€ λ¨μ! μ°λ¦¬λ₯Ό κ΅μνμ μ²νκ² λμ§ λ§μμμ€! μ¬λ°λ₯Έ λ°©ν₯μΌλ‘ μ°λ¦¬λ₯Ό κ°λ¦¬ν€λ©΄ μ°λ¦¬κ° κ·Έκ²μ κ³ μΉ κ²μ΄λΌκ³ νμ ν©λλ€. :)
μ¬μ©μ μ μ λλκ·Έ λ μ΄μ΄μμ κ³ λ₯΄μ§ λͺ»ν μ λλ©μ΄μ μ λ¬Έμ κ° μμλλ° μ΄κ²μ΄ λ§€μ° λ³΅μ‘ν DOM νΈλ¦¬ λλ¬Έμ΄λΌλ κ²μ λ°κ²¬νμ΅λλ€.
μ λ μ λΉ 4κ°μ DOM μμμ κ°μ κ²μ μμ±νλ ν μ΄λΈ νμ λ°μ΄ν°μ μ΅λ μμ² νκ³Ό μ΄μ νμν μ μλ ν μ΄λΈ κ΅¬μ± μμκ° μλ μ±μμ μμ ν©λλ€. ν μ΄λΈμ΄ λΉμ΄ μμ λλ λλκ·Έ λ μ΄μ΄κ° μ μμ μΌλ‘ μλνμ§λ§, ν μ΄λΈμ νμλλ λ°μ΄ν° μμ΄ λ§μμλ‘ μ¬μ©μ μ μ λλκ·Έ λ μ΄μ΄μ μ±λ₯μ΄ λλ €μ§λλ€. (μ΄ κ²½μ° ν μ΄λΈμ λλκ·Έ μμ€λ λλ νκ²μ λμμ μ ν κ΄μ¬νμ§ μμ΅λλ€.)
μ΄ κ²½μ° Firefoxμ μ±λ₯μ λ³κ²½λμ§ μμ λ°λ©΄ Chromeμ μ±λ₯μ DOM νΈλ¦¬μ 볡μ‘μ±μ΄ μ¦κ°ν μλ‘ κ·Ήμ μΌλ‘ μ νλμμ΅λλ€.
λΉ 3D λ³ν μμ± transform: translate3d(0, 0, 0)
μΌλ‘ μ€νμΌμ μ§μ νμ¬ Chromeμ μ체 ν©μ± λ μ΄μ΄λ‘ ν
μ΄λΈμ λ°μ΄ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμμ΅λλ€.
κ·Έ ν μ±λ₯μ λ°λͺ¨ νμ΄μ§μ λΉμ·νμ΅λλ€. μ΄ λΌμ΄λΈλ¬λ¦¬μ λν μλ―Έκ° λ¬΄μμΈμ§ μ λͺ¨λ₯΄κ² μ§λ§ μμ© νλ‘κ·Έλ¨ DOM νΈλ¦¬μ 볡μ‘ν λΆλΆμ λ³λμ ν©μ± λ μ΄μ΄λ‘ λ°μ΄ λ£μΌλ©΄ μ±λ₯ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμ΅λλ€.
@mgerring μ΄λ»κ² νλμ§μ λν μμΈν μ λ³΄κ° μμ΅λκΉ? λ΄ μ±μμ μ¬μ©ν΄λ³΄κ³ μΆμ΅λλ€.
μ, λ¨Όμ λ¬Έμ λ₯Ό μΌμΌν€λ κ΅¬μ± μμλ₯Ό μ°ΎκΈ° μν΄ λͺ¨λ κ΅¬μ± μμλ₯Ό μ κ±°νλ κ²μΌλ‘ μμνμΌλ©°, μΌλ¨ μ°ΎμΌλ©΄ μλ μ νλ₯Ό μ λ°νλ λΆλΆμΌλ‘ λ릴λ€μ΄ν λ€μ style
μ(λ₯Ό) νμ©ν μ μλ κ°μ₯ λ°κΉ₯μͺ½ μμμ λν΄ λ릴λ€μ΄νμ΅λλ€. style={{transform: translate3d(0, 0, 0)}}
#592μ μ΄ λκΈμ λ¨κΈ°κ³ μΆμμ§λ§ μ¬κΈ°μλ μ μ©λλ κ² κ°μ΅λλ€.
@mgerring μ루μ μ΄ μ μκ²
@alexey-belous μ°λ¦¬λ μ΄ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ€ν¬λ©νκ³ https://github.com/bevacqua/react-dragulaλ₯Ό μ¬μ©νμ΅λλ€.
+1
μ΄ λ¬Έμ λ μ΅κ·Ό νλμ΄ μμκΈ° λλ¬Έμ μλμΌλ‘ μ€λλ κ²μΌλ‘ νμλμμ΅λλ€. λ μ΄μμ νλμ΄ μμΌλ©΄ νμλ©λλ€. κ·νμ κΈ°μ¬μ κ°μ¬λ립λλ€.
κ°μ₯ μ μ©ν λκΈ
μ, λ¨Όμ λ¬Έμ λ₯Ό μΌμΌν€λ κ΅¬μ± μμλ₯Ό μ°ΎκΈ° μν΄ λͺ¨λ κ΅¬μ± μμλ₯Ό μ κ±°νλ κ²μΌλ‘ μμνμΌλ©°, μΌλ¨ μ°ΎμΌλ©΄ μλ μ νλ₯Ό μ λ°νλ λΆλΆμΌλ‘ λ릴λ€μ΄ν λ€μ
style
μ(λ₯Ό) νμ©ν μ μλ κ°μ₯ λ°κΉ₯μͺ½ μμμ λν΄ λ릴λ€μ΄νμ΅λλ€.style={{transform: translate3d(0, 0, 0)}}