BlockAction.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import LazyLoad from 'react-lazyload'
  4. import cls from 'classnames'
  5. import newEventActions from 'actions/newEvent'
  6. import Block from './base/Block'
  7. // import BlockChildren from './base/BlockChildren'
  8. import BlockOrder from './base/BlockOrder'
  9. import BlockDel from './base/BlockDel'
  10. import BlockCite from './base/BlockCite'
  11. import BlockMemo from './base/BlockMemo'
  12. import BlockActionObject from './base/action/BlockActionObject'
  13. import BlockActionMethod from './base/action/BlockActionMethod'
  14. export default class BlockAction extends Block {
  15. constructor(props) {
  16. super(props)
  17. this.actionObject = React.createRef()
  18. this.actionMethod = React.createRef()
  19. this.onToggleParamsVisible = this.onToggleParamsVisible.bind(this)
  20. }
  21. onToggleParamsVisible(e) {
  22. let objDom = ReactDOM.findDOMNode(this.actionObject)
  23. let mthDom = ReactDOM.findDOMNode(this.actionMethod)
  24. if (
  25. !(
  26. (objDom && objDom.contains(e.target)) ||
  27. (mthDom && mthDom.contains(e.target))
  28. ) &&
  29. !(
  30. e.target &&
  31. e.target.classList &&
  32. e.target.classList.contains('objectPickerTooltip__item')
  33. )
  34. ) {
  35. newEventActions.toggleActionParamsVisible({
  36. blockId: this.props.bid,
  37. visible: 'part'
  38. })
  39. newEventActions.changeActionParamSubChildrenItemVisible({
  40. blockId: this.props.bid,
  41. visible: 'part'
  42. })
  43. }
  44. }
  45. render() {
  46. let jengaContent = document.getElementsByClassName('jenga-content')[0]
  47. let getRelChildComs = () => {
  48. return this.state.hasChildren ? (
  49. <React.Fragment>
  50. {this.state.isExpand ? (
  51. <span
  52. className={cls(
  53. 'index-line',
  54. 'index-main-line',
  55. 'index-line-' + this.getNextLineColor()
  56. )}
  57. style={this.indexLeftStyle()}
  58. />
  59. ) : null}
  60. <button
  61. className={cls(
  62. 'btn-clear btn-toggle-sub btn-expand',
  63. 'btn-toggle-sub-' +
  64. (this.state.isExpand ? 'expand-' : 'collapse-') +
  65. this.getLineColor()
  66. )}
  67. onClick={this.onToggleBlockExpand}
  68. />
  69. </React.Fragment>
  70. ) : (
  71. <div
  72. className={cls(
  73. 'btn-clear btn-toggle-sub btn-toggle-sub-empty',
  74. 'btn-toggle-sub-empty-' + this.getLineColor()
  75. )}
  76. />
  77. )
  78. }
  79. return (
  80. <LazyLoad height={45} overflow={true} scrollContainer={jengaContent}>
  81. <div className="block-wrap block-wrap-action f--h">
  82. <span
  83. className={cls('index-line', 'index-line-' + this.getLineColor(), {
  84. 'index-last-line': this.props.isLast,
  85. 'index-virtual-layer': this.props.virtualLayer
  86. })}
  87. style={this.indexLeftStyle()}
  88. />
  89. <div
  90. className={cls('flex-1', {
  91. 'flex-wrap-disabled': !this.state.isEnable
  92. })}
  93. >
  94. <div
  95. className={cls('block-item block-action f--h', {
  96. 'block-active': this.state.isActive
  97. })}
  98. // onDragOver={this.onDragOver}
  99. // onDrop={this.onDrop}
  100. onClick={this.onSelectBlock}
  101. onContextMenu={this.onContextMenu}
  102. >
  103. <BlockDel
  104. isActive={this.state.isActive}
  105. layer={this.props.layer}
  106. bid={this.props.bid}
  107. />
  108. <BlockOrder
  109. layer={this.props.layer}
  110. bid={this.props.bid}
  111. eventNodeId={this.props.eventNodeId}
  112. extraGapGroupLayer={this.extraGapGroupLayer()}
  113. />
  114. <div
  115. className="block-gap"
  116. style={{
  117. left: -this.getGapLeft() + 'px',
  118. padding: '0 ' + this.getGapLeft() / 2 + 'px'
  119. }}
  120. />
  121. {getRelChildComs()}
  122. <div
  123. id={'block-main-' + this.props.bid}
  124. className="block-main flex-1 f--h"
  125. style={this.blockMainStyle()}
  126. draggable={true}
  127. // onDragStart={this.onDragStart}
  128. // onDragEnd={this.onDragEnd}
  129. onClick={this.onToggleParamsVisible}
  130. >
  131. <div
  132. id={'over-cover-' + this.props.bid}
  133. className="over-cover"
  134. />
  135. <BlockActionObject
  136. ref={node => (this.actionObject = node)}
  137. bid={this.props.bid}
  138. isEnable={this.state.isEnable}
  139. loops={this.getLoops()}
  140. eventNodeId={this.props.eventNodeId}
  141. />
  142. <BlockActionMethod
  143. ref={node => (this.actionMethod = node)}
  144. bid={this.props.bid}
  145. groupLayer={this.props.groupLayer}
  146. nestGroupLayer={this.props.nestGroupLayer}
  147. extraGapGroupLayer={this.extraGapGroupLayer()}
  148. layer={this.props.layer}
  149. eventNodeId={this.props.eventNodeId}
  150. />
  151. </div>
  152. <BlockCite
  153. bid={this.props.bid}
  154. eventNodeId={this.props.eventNodeId}
  155. />
  156. <BlockMemo
  157. className="block-action-memo"
  158. active={this.state.isActive}
  159. bid={this.props.bid}
  160. eventNodeId={this.props.eventNodeId}
  161. />
  162. </div>
  163. {/* {this.state.isExpand ? (
  164. <BlockChildren
  165. loops={this.getLoops()}
  166. layer={this.props.layer + 1}
  167. groupLayer={this.props.groupLayer}
  168. nestGroupLayer={0}
  169. offspringInNestGroupLayer={this.props.nestGroupLayer}
  170. extraGapGroupLayer={this.extraGapGroupLayer()}
  171. parentBid={this.props.bid}
  172. eventNodeId={this.props.eventNodeId}
  173. visibleBlockIds={this.props.visibleBlockIds}
  174. />
  175. ) : null} */}
  176. </div>
  177. </div>
  178. </LazyLoad>
  179. )
  180. }
  181. }