|
| 1 | +<a name="vue_draggable_nested_tree"></a> |
| 2 | +# vue-draggable-nested-tree vue |
| 3 | +์ด ํ๋ก์ ํธ๋ ๋๋๊ทธ๊ฐ ๊ฐ๋ฅํ ํธ๋ฆฌ ์ปดํฌ๋ํธ์
๋๋ค. ์ด ์ปดํฌ๋ํธ๋ css๋ฅผ ํฌํจํ์ง ์์ผ๋ฉฐ, ๋ฐ๋ชจ๋ฅผ ์ฌ์ฉํ๊ธฐ์ํด ๋น์ ์ style์ ์ถ๊ฐํ ํ์๊ฐ ์์ต๋๋ค. ๋ฐ๋ชจ์ style์ ์ด๋ ต์ง ์์ต๋๋ค. |
| 4 | + |
| 5 | +* [๋ฐ๋ชจ](https://codepen.io/phphe/pen/KRapQm) |
| 6 | +* [ie11 ์์ ](https://github.com/phphe/vue-draggable-nested-tree/tree/master/ie11-example) |
| 7 | +* [์์ด ๋ฌธ์](https://github.com/phphe/vue-draggable-nested-tree/blob/master/README.md) |
| 8 | +* [์ค๊ตญ์ด ๋ฌธ์](https://github.com/phphe/vue-draggable-nested-tree/blob/master/README_CN.md) |
| 9 | + |
| 10 | +# ํฐ์น |
| 11 | +ํฐ์น๋ฅผ ์ง์ํฉ๋๋ค (1๊ฐ์ ์์ดํ
) |
| 12 | + |
| 13 | +# ๊ธฐ๋ถ |
| 14 | +[ํ์ดํ](https://www.paypal.me/phphe) | [์๋ฆฌํ์ด](https://github.com/phphe/my-alipay-wechat-qr-code/blob/master/alipay.jpg) | [์์ฑ](https://github.com/phphe/my-alipay-wechat-qr-code/blob/master/wechat.png) |
| 15 | + |
| 16 | +# ๋ชฉ์ฐจ |
| 17 | +* [vue-draggable-nested-tree](#vue_draggable_nested_tree) |
| 18 | +* [install](#install) |
| 19 | +* [usage](#usage) |
| 20 | + * [import](#import) |
| 21 | + * [data](#data) |
| 22 | + * [template](#template) |
| 23 | + * [template for old browsers(eg: IE)](#template_for_old_browsers) |
| 24 | +* [api](#api) |
| 25 | + * [Tree props](#tree_props) |
| 26 | + * [Noraml - Tree props](#noraml_tree_props) |
| 27 | + * [Hooks - Tree props](#hooks_tree_props) |
| 28 | + * [draggableHelperInfo: {event, options, store}](#draggable_helper_info) |
| 29 | + * [Tree properties](#tree_properties) |
| 30 | + * [Tree events](#tree_events) |
| 31 | + * [Tree methods](#tree_methods) |
| 32 | + * [node properties](#node_properties) |
| 33 | + * [node deep properties example](#node_deep_properties_example) |
| 34 | +* [other](#other) |
| 35 | + * [demo css](#demo_css) |
| 36 | + * [examples](#examples) |
| 37 | + * [draggable & droppable](#draggable_&_droppable) |
| 38 | + * [Traverse tree](#traverse_tree) |
| 39 | + * [draggable library](#draggable_library) |
| 40 | + |
| 41 | +<a name="install"></a> |
| 42 | +# ์ค์น |
| 43 | +```sh |
| 44 | +npm i vue-draggable-nested-tree |
| 45 | +``` |
| 46 | +<a name="usage"></a> |
| 47 | +# ์ฌ์ฉ |
| 48 | +<a name="import"></a> |
| 49 | +### ํจ์ import |
| 50 | +```js |
| 51 | +import {DraggableTree} from 'vue-draggable-nested-tree' |
| 52 | +// vue-draggable-nested-tree contains Tree, TreeNode, DraggableTree, DraggableTreeNode |
| 53 | +// import the component and register it as global or local component |
| 54 | +``` |
| 55 | +<a name="data"></a> |
| 56 | +### json ๋ฐ์ดํฐ |
| 57 | +```js |
| 58 | +data: [ |
| 59 | + {text: 'node 1'}, |
| 60 | + {text: 'node 2'}, |
| 61 | + {text: 'node 3 undraggable', draggable: false}, |
| 62 | + {text: 'node 4'}, |
| 63 | + {text: 'node 4 undroppable', droppable: false}, |
| 64 | + {text: 'node 5', children: [ |
| 65 | + {text: 'node 1'}, |
| 66 | + {text: 'node 2', children: [ |
| 67 | + {text: 'node 3'}, |
| 68 | + {text: 'node 4'}, |
| 69 | + ]}, |
| 70 | + {text: 'node 2 undroppable', droppable: false, children: [ |
| 71 | + {text: 'node 3'}, |
| 72 | + {text: 'node 4'}, |
| 73 | + ]}, |
| 74 | + {text: 'node 2', children: [ |
| 75 | + {text: 'node 3'}, |
| 76 | + {text: 'node 4 undroppable', droppable: false}, |
| 77 | + ]}, |
| 78 | + {text: 'node 3'}, |
| 79 | + {text: 'node 4'}, |
| 80 | + {text: 'node 3'}, |
| 81 | + {text: 'node 4'}, |
| 82 | + {text: 'node 3'}, |
| 83 | + {text: 'node 4'}, |
| 84 | + {text: 'node 3'}, |
| 85 | + {text: 'node 4'}, |
| 86 | + ]}, |
| 87 | +] |
| 88 | +``` |
| 89 | +<a name="template"></a> |
| 90 | +### template |
| 91 | +```pug |
| 92 | +Tree(:data="data" draggable crossTree) |
| 93 | + div(slot-scope="{data, store, vm}") |
| 94 | + //- data is node |
| 95 | + //- store is the tree |
| 96 | + //- vm is node Vue instance, you can get node level by vm.level |
| 97 | + template(v-if="!data.isDragPlaceHolder") |
| 98 | + b(v-if="data.children && data.children.length" @click="store.toggleOpen(data)") {{data.open ? '-' : '+'}} |
| 99 | + span {{data.text}} |
| 100 | +``` |
| 101 | +<a name="template_for_old_browsers"></a> |
| 102 | +### ์ค๋๋ ๋ธ๋ผ์ฐ์ ๋ฅผ ์ํ template(eg: IE) |
| 103 | +```pug |
| 104 | +//- slot-scope="{data, store, vm}" may not work in old browsers, replace with slot-scope="slot" |
| 105 | +Tree(:data="data" draggable crossTree) |
| 106 | + div(slot-scope="slot") |
| 107 | + //- data is node |
| 108 | + //- store is the tree |
| 109 | + //- vm is node Vue instance, you can get node level by vm.level |
| 110 | + template(v-if="!slot.data.isDragPlaceHolder") |
| 111 | + b(v-if="slot.data.children && slot.data.children.length" @click="slot.store.toggleOpen(slot.data)") {{slot.data.open ? '-' : '+'}} |
| 112 | + span {{slot.data.text}} |
| 113 | +``` |
| 114 | +<a name="api"></a> |
| 115 | +# api |
| 116 | +**'store'๋ tree์ ์๋ VM์
๋๋ค.** |
| 117 | +<a name="tree_props"></a> |
| 118 | +### Tree props |
| 119 | +<a name="noraml_tree_props"></a> |
| 120 | +###### ๊ธฐ๋ณธ - Tree props |
| 121 | +```js |
| 122 | +// base tree |
| 123 | +data: {}, // type Array |
| 124 | +indent: {default: 16}, |
| 125 | +activatedClass: {default: 'active'}, |
| 126 | +openedClass: {default: 'open'}, |
| 127 | +space: {default: 10}, // space between node, unit px |
| 128 | +// draggable tree |
| 129 | +preventSelect: {default: true}, // if to prevent drag handler text be selected when drag, excluding input and textarea |
| 130 | +getTriggerEl: {type: Function}, // get the el trigger drag, default is node self. arguments(nodeVm) |
| 131 | +draggable: {}, // is the tree draggable, default false |
| 132 | +droppable: {default: true}, // is the tree droppable, default true |
| 133 | +crossTree: {}, // can a node of the tree be dragged into other tree, or receive other tree node |
| 134 | +``` |
| 135 | +<a name="hooks_tree_props"></a> |
| 136 | +###### ํ
- Tree props |
| 137 | +```js |
| 138 | +ondragstart: {type: Function}, // hook. return false to prevent drag. arguments(node, draggableHelperInfo) |
| 139 | +ondragend: {type: Function}, // hook. return false to prevent drop. arguments(node, draggableHelperInfo) |
| 140 | +``` |
| 141 | +<a name="draggable_helper_info"></a> |
| 142 | +###### draggableHelperInfo |
| 143 | +{event, options, store} |
| 144 | +<a name="tree_properties"></a> |
| 145 | +### Tree properties |
| 146 | +```js |
| 147 | +// base |
| 148 | +rootData, // generated by tree |
| 149 | +// draggable |
| 150 | +dplh, // drag placeholder. globally unique. |
| 151 | +trees, // array, all trees in the app. globally unique. |
| 152 | +``` |
| 153 | +<a name="tree_events"></a> |
| 154 | +### Tree ์ด๋ฒคํธ |
| 155 | +```js |
| 156 | +// store is the tree vm |
| 157 | +drag(node), // on drag start. |
| 158 | +drop(node, targetTree, oldTree), // after drop. |
| 159 | +change(node, targetTree, oldTree), // after drop, only when the node position changed |
| 160 | +nodeOpenChanged(node) // on a node is closed or open |
| 161 | +``` |
| 162 | +* targetTree์ oldTree ๋ tree vm์
๋๋ค. |
| 163 | +* oldTree is ์ค์ง cross tree์์๋ง ์ฌ์ฉ์ด ๊ฐ๋ฅํฉ๋๋ค. ๊ทธ ์ธ์๋ null์
๋๋ค.. |
| 164 | +* ๋ง์ฝ cross tree๋ฅผ ์ฌ์ฉ์ค์ด๋ผ๋ฉด targetTree์ oldTree ๋ ๋๋กญํ ๋ ๊ฐ์ด ๋ฐ๋๊ฒ์
๋๋ค. |
| 165 | +<a name="tree_methods"></a> |
| 166 | +### Tree ํจ์ |
| 167 | +```js |
| 168 | +pure(node, withChildren, after) |
| 169 | +/* |
| 170 | +pure |
| 171 | +return a node data without runtime properties.(!: property which starts with '_' will be removed) |
| 172 | +withChildren: optional. after: Function, optional |
| 173 | +the code about after(t is computed node data): |
| 174 | +if (after) { |
| 175 | + return after(t, node) || t |
| 176 | +} |
| 177 | +return t |
| 178 | +*/ |
| 179 | +getNodeById(id) |
| 180 | +getActivated() |
| 181 | +getOpened() |
| 182 | +activeNode(node, inactiveOld) |
| 183 | +toggleActive(node, inactiveOld) |
| 184 | +openNode(node, closeOld) |
| 185 | +toggleOpen(node, closeOld) |
| 186 | +// follow methods are easy, so I paste their soure code |
| 187 | +getPureData(after) { return this.pure(this.rootData, true, after).children } // after: Function, optional |
| 188 | +deleteNode(node) { return hp.arrayRemove(node.parent.children, node) } |
| 189 | +// add node: like array. eg: node.children.push(newNodeData) |
| 190 | +// update node: just assign to the node properties directly |
| 191 | +isNodeDraggable(node) |
| 192 | +isNodeDroppable(node) |
| 193 | +``` |
| 194 | +<a name="node_properties"></a> |
| 195 | +### node ์์ฑ |
| 196 | +```js |
| 197 | +// base |
| 198 | +_id |
| 199 | +_vm |
| 200 | +parent |
| 201 | +children: [], |
| 202 | +open, |
| 203 | +active: false, |
| 204 | +style: {}, |
| 205 | +class: '', |
| 206 | +innerStyle: {}, |
| 207 | +innerClass: '', |
| 208 | +innerBackStyle: {}, |
| 209 | +innerBackClass: {}, |
| 210 | +// draggable |
| 211 | +draggable // default true. Please check 'draggable & droppable' below |
| 212 | +droppable // default true. Please check 'draggable & droppable' below |
| 213 | +isDragPlaceHolder |
| 214 | +``` |
| 215 | +<a name="node_deep_properties_example"></a> |
| 216 | +#### node์ ์๋ ์์ฑ ์์ |
| 217 | +```js |
| 218 | +node._vm // vm |
| 219 | +node._vm.level // ๋
ธ๋ ๋ ๋ฒจ |
| 220 | +node._vm.store // ํธ๋ฆฌ |
| 221 | +node.parent._vm // ๋ถ๋ชจ node vm |
| 222 | +node._vm.store |
| 223 | +``` |
| 224 | +<a name="other"></a> |
| 225 | +# ๊ธฐํ |
| 226 | +<a name="demo_css"></a> |
| 227 | +### ๋ฐ๋ชจ css |
| 228 | +```css |
| 229 | +.he-tree{ |
| 230 | + border: 1px solid #ccc; |
| 231 | + padding: 20px; |
| 232 | + width: 300px; |
| 233 | +} |
| 234 | +.tree-node{ |
| 235 | +} |
| 236 | +.tree-node-inner{ |
| 237 | + padding: 5px; |
| 238 | + border: 1px solid #ccc; |
| 239 | + cursor: pointer; |
| 240 | +} |
| 241 | +.draggable-placeholder{ |
| 242 | +} |
| 243 | +.draggable-placeholder-inner{ |
| 244 | + border: 1px dashed #0088F8; |
| 245 | + box-sizing: border-box; |
| 246 | + background: rgba(0, 136, 249, 0.09); |
| 247 | + color: #0088f9; |
| 248 | + text-align: center; |
| 249 | + padding: 0; |
| 250 | + display: flex; |
| 251 | + align-items: center; |
| 252 | +} |
| 253 | +``` |
| 254 | +<a name="examples"></a> |
| 255 | +### ์์ |
| 256 | +์ด ํจํค์ง๋ฅผ cloneํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ , |
| 257 | +```sh |
| 258 | +npm install |
| 259 | +npm run dev |
| 260 | +``` |
| 261 | +* [๊ธฐ๋ณธ ์์ ](https://github.com/phphe/vue-draggable-nested-tree/blob/master/src/examples/Base.vue) |
| 262 | +* [ํธ๋ฆฌ์ ์ต๋ ๋ ๋ฒจ์ค์ ](https://github.com/phphe/vue-draggable-nested-tree/blob/master/src/examples/MaxLevel.vue) |
| 263 | + |
| 264 | +<a name="draggable_&_droppable"></a> |
| 265 | +### draggable & droppable |
| 266 | +ํ๊ฐ์ node๋ ๊ธฐ๋ณธ์ผ๋ก ๋๋๊ทธ&๋๋์ด ์ฌ์ฉ ๊ฐ๋ฅํฉ๋๋ค. ๋น์ ์ node์ ์์ฑ์ ๋๋๊ทธ&๋๋์ผ๋ก ์ค์ ๊ฐ๋ฅํฉ๋๋ค. ๋ค๋ฅธ๋ฐฉ๋ฒ์ผ๋ก๋ 'drag'์ด๋ฒคํธ๋ฅผ ๊ธฐ๋ค๋ฆฌ๋ค๊ฐ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ๋๋๊ทธ ํน์ ๋๋์์ฑ์ผ๋ก ์ธํ
ํ๋๊ฒ์
๋๋ค. |
| 267 | +<a name="traverse_tree"></a> |
| 268 | +### Traverse tree |
| 269 | +๋์ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ธ [tree-helper](https://github.com/phphe/tree-helper)๋ฅผ ์ถ์ฒํ๋ค.. ๊ทธ๊ฒ์ 2๊ฐ์ง์ ๊ฐ๋กํธ๋ฆฌ๋ฅผ ์ง์ํ๋ค: depthFirstSearch, breadthFirstSearch. |
| 270 | +<a name="draggable_library"></a> |
| 271 | +### draggable library |
| 272 | +[draggable-helper](https://github.com/phphe/draggable-helper) ๋๋๊ทธ๋ฅผ ์ํ ์ ๊ฐ ๊ฐ๋ฐํ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์
๋๋ค.. ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ ์ด ์ปดํฌ๋ํธ๋ฅผ ํตํด ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๋๋๊ทธ ํจ์๋ฅผ ์ฌ์ฉํ ๋ ๋์์ด ๋ ๊ฒ์
๋๋ค. |
0 commit comments