panel-funcs.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div class="flow-funcs__container">
  3. <!--<div class="flow-funcs__control">
  4. <button
  5. class="item"
  6. @click="funcsViewBlocks=!funcsViewBlocks">
  7. {{ funcsViewBlocks ? 'List':'Blocks' }} view
  8. </button>
  9. <button
  10. class="item"
  11. @click="$emit('toggleResizeable')">
  12. Resize
  13. </button>
  14. </div>-->
  15. <div class="flow-funcs__search">
  16. <input
  17. type="text"
  18. placeholder="search ... "
  19. v-model="search">
  20. </div>
  21. <div class="flow-funcs__inner">
  22. <div
  23. class="flow-funcs__collapsible"
  24. v-for="g in funcsGroups"
  25. :key="g">
  26. <hx-collapsible ref="funcGroup">
  27. <div
  28. class="flow-funcs__header"
  29. slot="header">{{ g }}</div>
  30. <div
  31. class="flow-funcs__group">
  32. <div
  33. ref="src"
  34. v-for="k in funcsGroupItems(g)"
  35. :key="k.src"
  36. class="flow-funcs__src hover"
  37. draggable="true"
  38. @dragstart="fnDrag($event,k.src)"
  39. :style="{ 'background': registry[k.src].style && registry[k.src].style.color, }"
  40. :title="k.src"
  41. v-html="k.label"
  42. />
  43. </div>
  44. </hx-collapsible>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. import {mapGetters} from 'vuex'
  51. import HxCollapsible from '@/components/shared/hx-collapsible'
  52. import utils from '@/utils/utils'
  53. export default {
  54. name: 'FlowPanel',
  55. components: {HxCollapsible},
  56. data () {
  57. return {
  58. search: null
  59. }
  60. },
  61. computed: {
  62. ...mapGetters('flow', ['registry']),
  63. funcsGroups () {
  64. // Set
  65. let group = new Set()
  66. for (let r in this.registry) {
  67. for (let c of this.registry[r].categories) {
  68. if (this.funcsGroupItems(c).length === 0) {
  69. continue
  70. }
  71. group.add(c)
  72. }
  73. }
  74. return [...group]
  75. },
  76. funcsGroupItems () {
  77. return (g) => {
  78. const ret = Object.keys(this.registry).filter(v => this.registry[v].categories.includes(g))
  79. .map(v => {
  80. return { src: v, label: v.split('.').join('<br/>') }
  81. })
  82. if (!this.search) {
  83. return ret
  84. }
  85. const filtered = []
  86. ret.forEach(e => {
  87. let r = utils.fuzzysearch(this.search, e.label)
  88. if (r !== false) {
  89. filtered.push({src: e.src, label: r})
  90. }
  91. })
  92. return filtered
  93. }
  94. }
  95. },
  96. watch: {
  97. search () {
  98. for (let g of this.$refs.funcGroup) {
  99. // Hack?
  100. g.state.active = true
  101. }
  102. }
  103. },
  104. methods: {
  105. fnDrag (ev, src) {
  106. ev.dataTransfer.setData('text/plain', src)
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. .flow-funcs {
  113. font-size:12px;
  114. flex:1;
  115. overflow:hidden;
  116. height: available;
  117. display:flex;
  118. flex-flow:column;
  119. color: var(--normal);
  120. padding:10px;
  121. }
  122. .flow-funcs__container {
  123. display:flex;
  124. flex-flow:column;
  125. white-space: nowrap;
  126. width:100%;
  127. flex-basis:100%;
  128. transition: all var(--transition-speed);
  129. overflow:hidden;
  130. }
  131. .flow-funcs__search {
  132. flex:0;
  133. }
  134. .flow-funcs__search input {
  135. background: transparent;
  136. padding:13px;
  137. min-width:50px;
  138. height:50px;
  139. box-shadow:none;
  140. }
  141. .flow-funcs__inner {
  142. display:flex;
  143. flex-flow:column;
  144. justify-content: flex-start;
  145. overflow-x:hidden;
  146. overflow-y:auto;
  147. }
  148. .flow-funcs__header {
  149. transition: all var(--transition-speed);
  150. }
  151. .flow-funcs__inner .hx-collapsible__header {
  152. font-size:14px;
  153. padding:5px 10px;
  154. transition: all var(--transition-speed);
  155. }
  156. .flow-funcs__group{
  157. display:grid;
  158. grid-template-columns: repeat(auto-fit, minmax(100px,auto));
  159. padding:10px;
  160. transition: all var(--transition-speed);
  161. }
  162. .flow-funcs__src {
  163. display:block;
  164. font-size:10px;
  165. padding:18px 4px;
  166. margin:1px;
  167. text-overflow: ellipsis;
  168. text-align:center;
  169. transition: all var(--transition-speed);
  170. position:relative;
  171. cursor: move;
  172. cursor: grab;
  173. cursor: -moz-grab;
  174. cursor: -webkit-grab;
  175. overflow:hidden;
  176. }
  177. .flow-funcs__src b{
  178. color: var(--primary-lighter);
  179. }
  180. </style>