BlockAction.jsx 5.6 KB

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