misp-ui-library-test 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +113 -0
  2. package/dist/theme-chalk/alert/index.scss +152 -0
  3. package/dist/theme-chalk/avatar/index.scss +51 -0
  4. package/dist/theme-chalk/backtop/index.scss +38 -0
  5. package/dist/theme-chalk/badge/index.scss +63 -0
  6. package/dist/theme-chalk/breadcrumb/index.scss +36 -0
  7. package/dist/theme-chalk/breadcrumb-item/index.scss +36 -0
  8. package/dist/theme-chalk/button/index.scss +157 -0
  9. package/dist/theme-chalk/card/index.scss +38 -0
  10. package/dist/theme-chalk/chart/index.scss +21 -0
  11. package/dist/theme-chalk/checkbox/index.scss +358 -0
  12. package/dist/theme-chalk/col/index.scss +131 -0
  13. package/dist/theme-chalk/container/index.scss +40 -0
  14. package/dist/theme-chalk/css/alert.css +484 -0
  15. package/dist/theme-chalk/css/avatar.css +409 -0
  16. package/dist/theme-chalk/css/backtop.css +401 -0
  17. package/dist/theme-chalk/css/badge.css +419 -0
  18. package/dist/theme-chalk/css/breadcrumb-item.css +395 -0
  19. package/dist/theme-chalk/css/breadcrumb.css +395 -0
  20. package/dist/theme-chalk/css/button.css +587 -0
  21. package/dist/theme-chalk/css/card.css +397 -0
  22. package/dist/theme-chalk/css/chart.css +386 -0
  23. package/dist/theme-chalk/css/checkbox.css +648 -0
  24. package/dist/theme-chalk/css/col.css +2111 -0
  25. package/dist/theme-chalk/css/container.css +404 -0
  26. package/dist/theme-chalk/css/dialog.css +505 -0
  27. package/dist/theme-chalk/css/divider.css +405 -0
  28. package/dist/theme-chalk/css/drawer.css +546 -0
  29. package/dist/theme-chalk/css/empty.css +394 -0
  30. package/dist/theme-chalk/css/form.css +561 -0
  31. package/dist/theme-chalk/css/icon.css +1534 -0
  32. package/dist/theme-chalk/css/image.css +400 -0
  33. package/dist/theme-chalk/css/input-number.css +424 -0
  34. package/dist/theme-chalk/css/input.css +721 -0
  35. package/dist/theme-chalk/css/link.css +424 -0
  36. package/dist/theme-chalk/css/loading.css +483 -0
  37. package/dist/theme-chalk/css/message-box.css +479 -0
  38. package/dist/theme-chalk/css/message.css +456 -0
  39. package/dist/theme-chalk/css/no-data.css +397 -0
  40. package/dist/theme-chalk/css/notification.css +431 -0
  41. package/dist/theme-chalk/css/page-header.css +396 -0
  42. package/dist/theme-chalk/css/pagination.css +565 -0
  43. package/dist/theme-chalk/css/popover.css +421 -0
  44. package/dist/theme-chalk/css/popper.css +454 -0
  45. package/dist/theme-chalk/css/progress.css +451 -0
  46. package/dist/theme-chalk/css/radio.css +626 -0
  47. package/dist/theme-chalk/css/rate.css +414 -0
  48. package/dist/theme-chalk/css/result.css +403 -0
  49. package/dist/theme-chalk/css/row.css +433 -0
  50. package/dist/theme-chalk/css/scrollbar.css +422 -0
  51. package/dist/theme-chalk/css/select.css +1897 -0
  52. package/dist/theme-chalk/css/skeleton-item.css +407 -0
  53. package/dist/theme-chalk/css/skeleton.css +390 -0
  54. package/dist/theme-chalk/css/slider.css +460 -0
  55. package/dist/theme-chalk/css/spinner.css +403 -0
  56. package/dist/theme-chalk/css/statistic.css +396 -0
  57. package/dist/theme-chalk/css/status-timeline-chart.css +388 -0
  58. package/dist/theme-chalk/css/step.css +496 -0
  59. package/dist/theme-chalk/css/steps.css +496 -0
  60. package/dist/theme-chalk/css/switch.css +507 -0
  61. package/dist/theme-chalk/css/tab-pane.css +457 -0
  62. package/dist/theme-chalk/css/table.css +461 -0
  63. package/dist/theme-chalk/css/tabs-navigation.css +925 -0
  64. package/dist/theme-chalk/css/tabs.css +457 -0
  65. package/dist/theme-chalk/css/tag.css +599 -0
  66. package/dist/theme-chalk/css/time-picker.css +683 -0
  67. package/dist/theme-chalk/css/timeline-item.css +459 -0
  68. package/dist/theme-chalk/css/timeline.css +459 -0
  69. package/dist/theme-chalk/css/tooltip.css +485 -0
  70. package/dist/theme-chalk/css/tree.css +473 -0
  71. package/dist/theme-chalk/css/upload.css +665 -0
  72. package/dist/theme-chalk/dialog/index.scss +168 -0
  73. package/dist/theme-chalk/divider/index.scss +46 -0
  74. package/dist/theme-chalk/drawer/index.scss +172 -0
  75. package/dist/theme-chalk/empty/index.scss +36 -0
  76. package/dist/theme-chalk/fonts/element-icons.ttf +0 -0
  77. package/dist/theme-chalk/fonts/element-icons.woff +0 -0
  78. package/dist/theme-chalk/form/index.scss +220 -0
  79. package/dist/theme-chalk/icon/index.scss +1171 -0
  80. package/dist/theme-chalk/image/index.scss +39 -0
  81. package/dist/theme-chalk/index.scss +127 -0
  82. package/dist/theme-chalk/input/index.scss +363 -0
  83. package/dist/theme-chalk/input-number/index.scss +71 -0
  84. package/dist/theme-chalk/link/index.scss +75 -0
  85. package/dist/theme-chalk/loading/index.scss +131 -0
  86. package/dist/theme-chalk/message/index.scss +100 -0
  87. package/dist/theme-chalk/message-box/index.scss +131 -0
  88. package/dist/theme-chalk/mixins.scss +203 -0
  89. package/dist/theme-chalk/no-data/index.scss +36 -0
  90. package/dist/theme-chalk/notification/index.scss +76 -0
  91. package/dist/theme-chalk/page-header/index.scss +36 -0
  92. package/dist/theme-chalk/pagination/index.scss +225 -0
  93. package/dist/theme-chalk/popover/index.scss +56 -0
  94. package/dist/theme-chalk/popper/index.scss +89 -0
  95. package/dist/theme-chalk/progress/index.scss +105 -0
  96. package/dist/theme-chalk/radio/index.scss +328 -0
  97. package/dist/theme-chalk/rate/index.scss +56 -0
  98. package/dist/theme-chalk/reset.scss +262 -0
  99. package/dist/theme-chalk/result/index.scss +46 -0
  100. package/dist/theme-chalk/row/index.scss +88 -0
  101. package/dist/theme-chalk/scrollbar/index.scss +67 -0
  102. package/dist/theme-chalk/select/index.scss +223 -0
  103. package/dist/theme-chalk/skeleton/index.scss +30 -0
  104. package/dist/theme-chalk/skeleton-item/index.scss +49 -0
  105. package/dist/theme-chalk/slider/index.scss +113 -0
  106. package/dist/theme-chalk/spinner/index.scss +40 -0
  107. package/dist/theme-chalk/statistic/index.scss +38 -0
  108. package/dist/theme-chalk/status-timeline-chart/index.scss +23 -0
  109. package/dist/theme-chalk/step/index.scss +160 -0
  110. package/dist/theme-chalk/steps/index.scss +160 -0
  111. package/dist/theme-chalk/switch/index.scss +153 -0
  112. package/dist/theme-chalk/tab-pane/index.scss +112 -0
  113. package/dist/theme-chalk/table/index.scss +110 -0
  114. package/dist/theme-chalk/tabs/index.scss +112 -0
  115. package/dist/theme-chalk/tabs-navigation/index.scss +631 -0
  116. package/dist/theme-chalk/tag/index.scss +138 -0
  117. package/dist/theme-chalk/themes/blue.scss +76 -0
  118. package/dist/theme-chalk/themes/dark.scss +99 -0
  119. package/dist/theme-chalk/themes/index.scss +260 -0
  120. package/dist/theme-chalk/themes/light.scss +99 -0
  121. package/dist/theme-chalk/time-picker/index.scss +332 -0
  122. package/dist/theme-chalk/timeline/index.scss +119 -0
  123. package/dist/theme-chalk/timeline-item/index.scss +119 -0
  124. package/dist/theme-chalk/tooltip/index.scss +122 -0
  125. package/dist/theme-chalk/tree/index.scss +125 -0
  126. package/dist/theme-chalk/upload/index.scss +348 -0
  127. package/dist/theme-chalk/variables.scss +93 -0
  128. package/dist/vue2-ui-library.cjs.temp.js.map +1 -0
  129. package/dist/vue2-ui-library.common.js +28 -0
  130. package/dist/vue2-ui-library.common.js.map +1 -0
  131. package/dist/vue2-ui-library.esm.js +29 -0
  132. package/dist/vue2-ui-library.umd.js +27 -0
  133. package/package.json +161 -0
  134. package/src/directives/clickoutside/index.js +111 -0
  135. package/src/directives/init/index.js +50 -0
  136. package/src/directives/resize/index.js +69 -0
  137. package/src/index.js +174 -0
  138. package/src/mixins/emitter.js +47 -0
  139. package/src/mixins/focus.js +42 -0
  140. package/src/mixins/locale.js +24 -0
  141. package/src/mixins/migrating.js +46 -0
  142. package/src/packages/alert/index.js +12 -0
  143. package/src/packages/alert/src/main.vue +98 -0
  144. package/src/packages/aside/index.js +12 -0
  145. package/src/packages/aside/src/main.vue +20 -0
  146. package/src/packages/auto-grid-layout/index.js +18 -0
  147. package/src/packages/auto-grid-layout/prop.js +92 -0
  148. package/src/packages/auto-grid-layout/src/components/GridItem.vue +759 -0
  149. package/src/packages/auto-grid-layout/src/components/GridLayout.vue +367 -0
  150. package/src/packages/auto-grid-layout/src/main.vue +287 -0
  151. package/src/packages/auto-grid-layout/src/utils/DOM.js +46 -0
  152. package/src/packages/auto-grid-layout/src/utils/interact.js +333 -0
  153. package/src/packages/auto-grid-layout/src/utils/responsiveUtils.js +75 -0
  154. package/src/packages/auto-grid-layout/src/utils/utils.js +339 -0
  155. package/src/packages/autocomplete/index.js +12 -0
  156. package/src/packages/autocomplete/src/main.vue +170 -0
  157. package/src/packages/avatar/index.js +12 -0
  158. package/src/packages/avatar/src/main.vue +87 -0
  159. package/src/packages/backtop/index.js +12 -0
  160. package/src/packages/backtop/src/main.vue +120 -0
  161. package/src/packages/badge/index.js +12 -0
  162. package/src/packages/badge/src/main.vue +53 -0
  163. package/src/packages/breadcrumb/index.js +12 -0
  164. package/src/packages/breadcrumb/src/main.vue +34 -0
  165. package/src/packages/breadcrumb-item/index.js +12 -0
  166. package/src/packages/breadcrumb-item/src/main.vue +41 -0
  167. package/src/packages/button/index.js +13 -0
  168. package/src/packages/button/src/main.vue +106 -0
  169. package/src/packages/calendar/index.js +12 -0
  170. package/src/packages/calendar/src/main.vue +173 -0
  171. package/src/packages/card/index.js +12 -0
  172. package/src/packages/card/src/main.vue +26 -0
  173. package/src/packages/carousel/index.js +12 -0
  174. package/src/packages/carousel/src/main.vue +186 -0
  175. package/src/packages/carousel-item/index.js +12 -0
  176. package/src/packages/carousel-item/src/main.vue +34 -0
  177. package/src/packages/cascader/index.js +12 -0
  178. package/src/packages/cascader/src/main.vue +232 -0
  179. package/src/packages/chart/index.js +7 -0
  180. package/src/packages/chart/src/axis-chart.js +700 -0
  181. package/src/packages/chart/src/main.vue +828 -0
  182. package/src/packages/chart/src/utils.js +21 -0
  183. package/src/packages/checkbox/index.js +44 -0
  184. package/src/packages/checkbox/src/main.vue +312 -0
  185. package/src/packages/col/index.js +12 -0
  186. package/src/packages/col/src/main.vue +85 -0
  187. package/src/packages/collapse/index.js +12 -0
  188. package/src/packages/collapse/src/main.vue +69 -0
  189. package/src/packages/collapse-item/index.js +12 -0
  190. package/src/packages/collapse-item/src/main.vue +75 -0
  191. package/src/packages/color-picker/index.js +12 -0
  192. package/src/packages/color-picker/src/main.vue +206 -0
  193. package/src/packages/container/index.js +12 -0
  194. package/src/packages/container/src/main.vue +33 -0
  195. package/src/packages/date-picker/index.js +12 -0
  196. package/src/packages/date-picker/src/main.vue +246 -0
  197. package/src/packages/descriptions/index.js +12 -0
  198. package/src/packages/descriptions/src/main.vue +89 -0
  199. package/src/packages/descriptions-item/index.js +12 -0
  200. package/src/packages/descriptions-item/src/main.vue +26 -0
  201. package/src/packages/dialog/index.js +12 -0
  202. package/src/packages/dialog/src/main.vue +336 -0
  203. package/src/packages/divider/index.js +12 -0
  204. package/src/packages/divider/src/main.vue +37 -0
  205. package/src/packages/drawer/index.js +7 -0
  206. package/src/packages/drawer/src/main.vue +310 -0
  207. package/src/packages/dropdown/index.js +12 -0
  208. package/src/packages/dropdown/src/main.vue +82 -0
  209. package/src/packages/dropdown-menu-item/index.js +12 -0
  210. package/src/packages/dropdown-menu-item/src/main.vue +29 -0
  211. package/src/packages/empty/index.js +12 -0
  212. package/src/packages/empty/src/img-empty.vue +12 -0
  213. package/src/packages/empty/src/main.vue +49 -0
  214. package/src/packages/footer/index.js +12 -0
  215. package/src/packages/footer/src/main.vue +20 -0
  216. package/src/packages/form/index.js +13 -0
  217. package/src/packages/form/src/form-field.vue +790 -0
  218. package/src/packages/form/src/form-item.vue +464 -0
  219. package/src/packages/form/src/label-wrap.vue +127 -0
  220. package/src/packages/form/src/main.vue +442 -0
  221. package/src/packages/form-item/index.js +11 -0
  222. package/src/packages/header/index.js +12 -0
  223. package/src/packages/header/src/main.vue +20 -0
  224. package/src/packages/icon/index.js +12 -0
  225. package/src/packages/icon/src/main.vue +48 -0
  226. package/src/packages/image/index.js +12 -0
  227. package/src/packages/image/src/main.vue +224 -0
  228. package/src/packages/input/index.js +13 -0
  229. package/src/packages/input/src/calcTextareaHeight.js +123 -0
  230. package/src/packages/input/src/main.vue +510 -0
  231. package/src/packages/input-number/index.js +12 -0
  232. package/src/packages/input-number/src/main.vue +121 -0
  233. package/src/packages/link/index.js +12 -0
  234. package/src/packages/link/src/main.vue +53 -0
  235. package/src/packages/loading/index.js +17 -0
  236. package/src/packages/loading/src/directive.js +54 -0
  237. package/src/packages/loading/src/main.vue +38 -0
  238. package/src/packages/loading/src/service.js +63 -0
  239. package/src/packages/main/index.js +12 -0
  240. package/src/packages/main/src/main.vue +12 -0
  241. package/src/packages/menu/index.js +12 -0
  242. package/src/packages/menu/src/main.vue +117 -0
  243. package/src/packages/menu-item/index.js +12 -0
  244. package/src/packages/menu-item/src/main.vue +61 -0
  245. package/src/packages/message/index.js +95 -0
  246. package/src/packages/message/src/main.vue +131 -0
  247. package/src/packages/message-box/index.js +75 -0
  248. package/src/packages/message-box/src/main.vue +207 -0
  249. package/src/packages/no-data/index.js +8 -0
  250. package/src/packages/no-data/src/main.vue +23 -0
  251. package/src/packages/notification/index.js +72 -0
  252. package/src/packages/notification/src/main.vue +139 -0
  253. package/src/packages/option/index.js +13 -0
  254. package/src/packages/page-header/index.js +12 -0
  255. package/src/packages/page-header/src/main.vue +27 -0
  256. package/src/packages/pagination/index.js +12 -0
  257. package/src/packages/pagination/src/main.vue +255 -0
  258. package/src/packages/popconfirm/index.js +12 -0
  259. package/src/packages/popconfirm/src/main.vue +89 -0
  260. package/src/packages/popover/index.js +12 -0
  261. package/src/packages/popover/src/main.vue +452 -0
  262. package/src/packages/progress/index.js +12 -0
  263. package/src/packages/progress/src/main.vue +236 -0
  264. package/src/packages/radio/index.js +44 -0
  265. package/src/packages/radio/src/main.vue +291 -0
  266. package/src/packages/rate/index.js +12 -0
  267. package/src/packages/rate/src/main.vue +129 -0
  268. package/src/packages/result/index.js +12 -0
  269. package/src/packages/result/src/main.vue +52 -0
  270. package/src/packages/row/index.js +12 -0
  271. package/src/packages/row/src/main.vue +57 -0
  272. package/src/packages/scrollbar/index.js +12 -0
  273. package/src/packages/scrollbar/src/bar.vue +116 -0
  274. package/src/packages/scrollbar/src/main.vue +124 -0
  275. package/src/packages/select/index.js +15 -0
  276. package/src/packages/select/src/clickoutside.js +20 -0
  277. package/src/packages/select/src/main.vue +1055 -0
  278. package/src/packages/select/src/navigation-mixin.js +49 -0
  279. package/src/packages/select/src/option.vue +249 -0
  280. package/src/packages/select/src/select-dropdown.vue +95 -0
  281. package/src/packages/select/src/utils.js +5 -0
  282. package/src/packages/skeleton/index.js +12 -0
  283. package/src/packages/skeleton/src/main.vue +76 -0
  284. package/src/packages/skeleton-item/index.js +12 -0
  285. package/src/packages/skeleton-item/src/img-placeholder.vue +13 -0
  286. package/src/packages/skeleton-item/src/main.vue +22 -0
  287. package/src/packages/slider/index.js +12 -0
  288. package/src/packages/slider/src/main.vue +176 -0
  289. package/src/packages/spinner/index.js +12 -0
  290. package/src/packages/spinner/src/main.vue +27 -0
  291. package/src/packages/statistic/index.js +12 -0
  292. package/src/packages/statistic/src/main.vue +100 -0
  293. package/src/packages/status-timeline-chart/index.js +7 -0
  294. package/src/packages/status-timeline-chart/src/constants.js +20 -0
  295. package/src/packages/status-timeline-chart/src/main.vue +499 -0
  296. package/src/packages/status-timeline-chart/src/option-builder.js +475 -0
  297. package/src/packages/step/index.js +12 -0
  298. package/src/packages/step/src/main.vue +183 -0
  299. package/src/packages/steps/index.js +12 -0
  300. package/src/packages/steps/src/main.vue +57 -0
  301. package/src/packages/submenu/index.js +12 -0
  302. package/src/packages/submenu/src/main.vue +68 -0
  303. package/src/packages/switch/index.js +12 -0
  304. package/src/packages/switch/src/main.vue +166 -0
  305. package/src/packages/tab-pane/index.js +12 -0
  306. package/src/packages/tab-pane/src/main.vue +74 -0
  307. package/src/packages/table/index.js +8 -0
  308. package/src/packages/table/src/components/PagePagination.vue +82 -0
  309. package/src/packages/table/src/main.vue +153 -0
  310. package/src/packages/tabs/index.js +12 -0
  311. package/src/packages/tabs/src/main.vue +167 -0
  312. package/src/packages/tabs-navigation/index.js +7 -0
  313. package/src/packages/tabs-navigation/src/main.vue +462 -0
  314. package/src/packages/tag/index.js +12 -0
  315. package/src/packages/tag/src/main.vue +194 -0
  316. package/src/packages/time-picker/index.js +17 -0
  317. package/src/packages/time-picker/src/date-utils.js +455 -0
  318. package/src/packages/time-picker/src/main.vue +321 -0
  319. package/src/packages/time-picker/src/pane/date-range.vue +193 -0
  320. package/src/packages/time-picker/src/pane/date-time-range.vue +362 -0
  321. package/src/packages/time-picker/src/pane/date-time.vue +362 -0
  322. package/src/packages/time-picker/src/pane/date.vue +441 -0
  323. package/src/packages/time-picker/src/pane/time.vue +260 -0
  324. package/src/packages/time-picker/src/time-input.vue +203 -0
  325. package/src/packages/time-picker/src/time-range-input.vue +170 -0
  326. package/src/packages/timeline/index.js +12 -0
  327. package/src/packages/timeline/src/main.vue +24 -0
  328. package/src/packages/timeline-item/index.js +12 -0
  329. package/src/packages/timeline-item/src/main.vue +78 -0
  330. package/src/packages/tooltip/index.js +12 -0
  331. package/src/packages/tooltip/src/main.js +367 -0
  332. package/src/packages/transfer/index.js +8 -0
  333. package/src/packages/transfer/src/main.vue +229 -0
  334. package/src/packages/transfer/src/transfer-panel.vue +245 -0
  335. package/src/packages/transitions/collapse-transition.js +75 -0
  336. package/src/packages/tree/index.js +12 -0
  337. package/src/packages/tree/src/main.vue +322 -0
  338. package/src/packages/tree/src/model/node.js +348 -0
  339. package/src/packages/tree/src/model/tree-store.js +354 -0
  340. package/src/packages/tree/src/model/util.js +10 -0
  341. package/src/packages/tree/src/tree-node.vue +262 -0
  342. package/src/packages/upload/index.js +9 -0
  343. package/src/packages/upload/src/main.vue +415 -0
  344. package/src/playground/mixins/element.js +98 -0
  345. package/src/playground/types/element.js +197 -0
  346. package/src/playground/types/layout.js +80 -0
  347. package/src/plugins/i18n.js +125 -0
  348. package/src/styles/fonts/element-icons.ttf +0 -0
  349. package/src/styles/fonts/element-icons.woff +0 -0
  350. package/src/styles/index.scss +138 -0
  351. package/src/styles/reset.scss +257 -0
  352. package/src/styles/themes/blue.scss +75 -0
  353. package/src/styles/themes/dark.scss +98 -0
  354. package/src/styles/themes/index.scss +34 -0
  355. package/src/styles/themes/light.scss +98 -0
  356. package/src/styles/themes/variables.scss +233 -0
  357. package/src/styles/variables.scss +146 -0
  358. package/src/utils/async-validator/index.js +659 -0
  359. package/src/utils/browser/index.js +39 -0
  360. package/src/utils/color.js +76 -0
  361. package/src/utils/dom/index.js +421 -0
  362. package/src/utils/dom/scrollbar-width.js +49 -0
  363. package/src/utils/draggable/core.js +379 -0
  364. package/src/utils/draggable/draggable.js +478 -0
  365. package/src/utils/draggable/index.js +61 -0
  366. package/src/utils/draggable/sortable.js +751 -0
  367. package/src/utils/lodash/index.js +2395 -0
  368. package/src/utils/moment/index.js +909 -0
  369. package/src/utils/playground/index.js +37 -0
  370. package/src/utils/popper/index.js +308 -0
  371. package/src/utils/popper/popper.js +1132 -0
  372. package/src/utils/popper/popup-manager.js +288 -0
  373. package/src/utils/popper/popup.js +344 -0
@@ -0,0 +1,751 @@
1
+ /**
2
+ * @fileoverview Vue2 UI Library - Sortable 排序模块
3
+ * @description 实现类似 SortableJS 的列表拖拽排序功能(零外部依赖)
4
+ * @module utils/draggable/sortable
5
+ */
6
+
7
+ import { addClass, removeClass } from '../dom';
8
+ import {
9
+ isTouchEvent,
10
+ getEventCoords,
11
+ getRect,
12
+ getChildren,
13
+ closestInsert,
14
+ cloneElement,
15
+ bindDragEvents,
16
+ resolveDragTarget,
17
+ uniqueId,
18
+ assign,
19
+ preventDefault,
20
+ index
21
+ } from './core';
22
+
23
+ /**
24
+ * 全局存储所有 Sortable 实例
25
+ * @type {Object<string, Sortable>}
26
+ */
27
+ var sortableInstances = {};
28
+
29
+ /**
30
+ * 当前正在拖拽的 Sortable 实例
31
+ * @type {Sortable|null}
32
+ */
33
+ var activeSortable = null;
34
+
35
+ /**
36
+ * 当前拖拽的元素
37
+ * @type {HTMLElement|null}
38
+ */
39
+ var dragEl = null;
40
+
41
+ /**
42
+ * 拖拽元素的 ghost 副本
43
+ * @type {HTMLElement|null}
44
+ */
45
+ var ghostEl = null;
46
+
47
+ /**
48
+ * 拖拽元素的占位符(原位置)
49
+ * @type {HTMLElement|null}
50
+ */
51
+ var cloneEl = null;
52
+
53
+ /**
54
+ * 起始位置索引
55
+ * @type {number}
56
+ */
57
+ var startIndex = -1;
58
+
59
+ /**
60
+ * 起始父级元素
61
+ * @type {HTMLElement|null}
62
+ */
63
+ var startParent = null;
64
+
65
+ /**
66
+ * 是否正在拖拽中
67
+ * @type {boolean}
68
+ */
69
+ var isDragging = false;
70
+
71
+ /**
72
+ * 拖拽起始坐标
73
+ * @type {{x: number, y: number}}
74
+ */
75
+ var startCoords = { x: 0, y: 0 };
76
+
77
+ /**
78
+ * 上一次移动坐标
79
+ * @type {{x: number, y: number}}
80
+ */
81
+ // var lastCoords = { x: 0, y: 0 };
82
+
83
+ /**
84
+ * 默认配置
85
+ */
86
+ var defaults = {
87
+ group: null, // 分组名称,允许跨列表拖拽
88
+ sort: true, // 是否允许内部排序
89
+ delay: 0, // 延迟拖拽(ms)
90
+ delayOnTouchOnly: false,
91
+ touchStartThreshold: 5,// touch 移动阈值
92
+ disabled: false, // 是否禁用
93
+ animation: 150, // 动画时长(ms)
94
+ easing: '', // 动画缓动
95
+ handle: null, // 拖拽手柄选择器
96
+ filter: null, // 过滤选择器
97
+ draggable: null, // 可拖拽元素选择器
98
+ ghostClass: 'sortable-ghost',
99
+ chosenClass: 'sortable-chosen',
100
+ dragClass: 'sortable-drag',
101
+ forceFallback: false, // 强制使用 fallback
102
+ fallbackClass: 'sortable-fallback',
103
+ fallbackTolerance: 0,
104
+ scroll: true, // 是否自动滚动
105
+ scrollSensitivity: 30,
106
+ scrollSpeed: 10,
107
+ bubbleScroll: false,
108
+ direction: 'vertical', // 方向:vertical | horizontal
109
+ // 回调函数
110
+ onStart: null,
111
+ onEnd: null,
112
+ onAdd: null,
113
+ onRemove: null,
114
+ onUpdate: null,
115
+ onSort: null,
116
+ onMove: null,
117
+ onClone: null,
118
+ onChoose: null,
119
+ onUnchoose: null
120
+ };
121
+
122
+ /**
123
+ * 解析 group 配置
124
+ * @param {*} group
125
+ * @returns {{name: string|null, pull: boolean|string|Function, put: boolean|string|Function, revertClone: boolean}}
126
+ */
127
+ function parseGroup(group) {
128
+ if (!group) {
129
+ return { name: null, pull: true, put: true, revertClone: false };
130
+ }
131
+ if (typeof group === 'string') {
132
+ return { name: group, pull: true, put: true, revertClone: false };
133
+ }
134
+ return assign({
135
+ name: null,
136
+ pull: true,
137
+ put: true,
138
+ revertClone: false
139
+ }, group);
140
+ }
141
+
142
+ /**
143
+ * 检查是否允许拖入(put)
144
+ * @param {Sortable} fromSortable
145
+ * @param {Sortable} toSortable
146
+ * @returns {boolean}
147
+ */
148
+ function allowPut(fromSortable, toSortable) {
149
+ var fromGroup = parseGroup(fromSortable.options.group);
150
+ var toGroup = parseGroup(toSortable.options.group);
151
+
152
+ if (!fromGroup.name || !toGroup.name) return true;
153
+ if (fromGroup.name !== toGroup.name) return false;
154
+
155
+ var put = toGroup.put;
156
+ if (typeof put === 'function') {
157
+ return put(fromSortable.options.group, fromSortable, toSortable);
158
+ }
159
+ return !!put;
160
+ }
161
+
162
+ /**
163
+ * 检查是否允许拖出(pull)
164
+ * @param {Sortable} fromSortable
165
+ * @param {Sortable} toSortable
166
+ * @param {HTMLElement} dragItem
167
+ * @returns {boolean|string}
168
+ */
169
+ function allowPull(fromSortable, toSortable, dragItem) {
170
+ var fromGroup = parseGroup(fromSortable.options.group);
171
+ var pull = fromGroup.pull;
172
+
173
+ if (typeof pull === 'function') {
174
+ return pull(toSortable.options.group, dragItem, fromSortable, toSortable);
175
+ }
176
+ return pull;
177
+ }
178
+
179
+ /**
180
+ * 获取所有注册了相同 group 的 Sortable 实例
181
+ * @param {string} groupName
182
+ * @returns {Sortable[]}
183
+ */
184
+ function getSortablesByGroup(groupName) {
185
+ var result = [];
186
+ var keys = Object.keys(sortableInstances);
187
+ for (var i = 0; i < keys.length; i++) {
188
+ var s = sortableInstances[keys[i]];
189
+ var g = parseGroup(s.options.group);
190
+ if (g.name === groupName) {
191
+ result.push(s);
192
+ }
193
+ }
194
+ return result;
195
+ }
196
+
197
+ /**
198
+ * 创建 ghost 元素
199
+ * @param {HTMLElement} el
200
+ * @param {Object} options
201
+ * @returns {HTMLElement}
202
+ */
203
+ function createGhost(el, options) {
204
+ var ghost = cloneElement(el);
205
+ addClass(ghost, options.ghostClass);
206
+ ghost.style.opacity = '0.5';
207
+ ghost.style.position = 'fixed';
208
+ ghost.style.zIndex = '99999';
209
+ ghost.style.pointerEvents = 'none';
210
+ ghost.style.left = '-9999px';
211
+ ghost.style.top = '-9999px';
212
+ ghost.style.width = el.offsetWidth + 'px';
213
+ ghost.style.height = el.offsetHeight + 'px';
214
+ ghost.style.boxSizing = 'border-box';
215
+ return ghost;
216
+ }
217
+
218
+ /**
219
+ * 更新 ghost 位置
220
+ * @param {HTMLElement} ghost
221
+ * @param {number} x
222
+ * @param {number} y
223
+ * @param {HTMLElement} original
224
+ */
225
+ function moveGhost(ghost, x, y, original) {
226
+ var rect = getRect(original);
227
+ ghost.style.left = (x - rect.width / 2) + 'px';
228
+ ghost.style.top = (y - rect.height / 2) + 'px';
229
+ }
230
+
231
+ /**
232
+ * 自动滚动容器
233
+ * @param {HTMLElement} container
234
+ * @param {number} clientX
235
+ * @param {number} clientY
236
+ * @param {Object} options
237
+ */
238
+ function autoScroll(container, clientX, clientY, options) {
239
+ if (!options.scroll || !container) return;
240
+
241
+ var rect = getRect(container);
242
+ var sens = options.scrollSensitivity;
243
+ var speed = options.scrollSpeed;
244
+
245
+ if (clientY < rect.top + sens) {
246
+ container.scrollTop -= speed;
247
+ } else if (clientY > rect.bottom - sens) {
248
+ container.scrollTop += speed;
249
+ }
250
+
251
+ if (clientX < rect.left + sens) {
252
+ container.scrollLeft -= speed;
253
+ } else if (clientX > rect.right - sens) {
254
+ container.scrollLeft += speed;
255
+ }
256
+ }
257
+
258
+ /**
259
+ * 触发自定义事件
260
+ * @param {HTMLElement} el
261
+ * @param {string} name
262
+ * @param {Object} detail
263
+ * @returns {Event}
264
+ */
265
+ function dispatchEvent(el, name, detail) {
266
+ var evt = document.createEvent('CustomEvent');
267
+ evt.initCustomEvent(name, true, true, detail);
268
+ el.dispatchEvent(evt);
269
+ return evt;
270
+ }
271
+
272
+ /**
273
+ * Sortable 构造函数
274
+ * @param {HTMLElement} el - 容器元素
275
+ * @param {Object} options - 配置项
276
+ * @constructor
277
+ */
278
+ function Sortable(el, options) {
279
+ if (!(this instanceof Sortable)) {
280
+ return new Sortable(el, options);
281
+ }
282
+
283
+ this.el = el;
284
+ this.options = assign({}, defaults, options);
285
+ this.id = uniqueId();
286
+ this._unbindEvents = null;
287
+ this._delayTimer = null;
288
+ this._lastSwapEl = null;
289
+
290
+ sortableInstances[this.id] = this;
291
+ this._init();
292
+ }
293
+
294
+ Sortable.prototype = {
295
+
296
+ /**
297
+ * 初始化
298
+ * @private
299
+ */
300
+ _init: function() {
301
+ var self = this;
302
+ var el = this.el;
303
+
304
+ // 绑定拖拽事件
305
+ this._unbindEvents = bindDragEvents(el, {
306
+ start: function(evt) { self._onDragStart(evt); },
307
+ move: function(evt) { self._onDragMove(evt); },
308
+ end: function(evt) { self._onDragEnd(evt); }
309
+ });
310
+
311
+ // 添加实例引用到 DOM
312
+ el._sortableInstance = this;
313
+ },
314
+
315
+ /**
316
+ * 拖拽开始
317
+ * @param {Event} evt
318
+ * @private
319
+ */
320
+ _onDragStart: function(evt) {
321
+ if (this.options.disabled) return;
322
+
323
+ var target = evt.target;
324
+ var resolved = resolveDragTarget(target, this.el, this.options);
325
+
326
+ if (!resolved.canDrag) return;
327
+
328
+ var dragItem = resolved.target;
329
+ var self = this;
330
+ var opts = this.options;
331
+
332
+ // 延时拖拽
333
+ if (opts.delay && (!isTouchEvent(evt) || opts.delayOnTouchOnly)) {
334
+ this._delayTimer = setTimeout(function() {
335
+ self._startDrag(evt, dragItem);
336
+ }, opts.delay);
337
+ } else {
338
+ this._startDrag(evt, dragItem);
339
+ }
340
+ },
341
+
342
+ /**
343
+ * 真正开始拖拽
344
+ * @param {Event} evt
345
+ * @param {HTMLElement} dragItem
346
+ * @private
347
+ */
348
+ _startDrag: function(evt, dragItem) {
349
+ var opts = this.options;
350
+ var coords = getEventCoords(evt);
351
+
352
+ startCoords = { x: coords.clientX, y: coords.clientY };
353
+
354
+ dragEl = dragItem;
355
+ startIndex = index(dragEl);
356
+ startParent = dragEl.parentNode;
357
+ activeSortable = this;
358
+ isDragging = false;
359
+
360
+ // 触发 onChoose
361
+ if (typeof opts.onChoose === 'function') {
362
+ opts.onChoose.call(this, dragEl, this);
363
+ }
364
+ addClass(dragEl, opts.chosenClass);
365
+
366
+ // 延时后再真正创建 ghost(实现真正的 delay 效果)
367
+ // 但这里我们立即响应鼠标移动来决定是否开始真正拖拽
368
+ this._pendingDrag = true;
369
+ this._pendingItem = dragItem;
370
+ this._startEvt = evt;
371
+ },
372
+
373
+ /**
374
+ * 拖拽移动
375
+ * @param {Event} evt
376
+ * @private
377
+ */
378
+ _onDragMove: function(evt) {
379
+ if (!this._pendingDrag && !isDragging) return;
380
+
381
+ var coords = getEventCoords(evt);
382
+ var opts = this.options;
383
+
384
+ // 检查移动距离是否达到阈值
385
+ if (this._pendingDrag) {
386
+ var dist = Math.sqrt(
387
+ Math.pow(coords.clientX - startCoords.x, 2) +
388
+ Math.pow(coords.clientY - startCoords.y, 2)
389
+ );
390
+ var threshold = isTouchEvent(evt) ? opts.touchStartThreshold : 0;
391
+ if (dist < threshold) return;
392
+
393
+ this._pendingDrag = false;
394
+ isDragging = true;
395
+
396
+ // 创建 ghost
397
+ ghostEl = createGhost(dragEl, opts);
398
+ document.body.appendChild(ghostEl);
399
+
400
+ // 在原位置创建占位 clone
401
+ cloneEl = cloneElement(dragEl);
402
+ addClass(cloneEl, opts.dragClass);
403
+ dragEl.parentNode.insertBefore(cloneEl, dragEl);
404
+
405
+ // 隐藏原元素
406
+ dragEl.style.display = 'none';
407
+
408
+ // 触发 onStart
409
+ dispatchEvent(this.el, 'sortable:start', {
410
+ to: this.el,
411
+ from: this.el,
412
+ item: dragEl,
413
+ newIndex: startIndex,
414
+ oldIndex: startIndex
415
+ });
416
+
417
+ if (typeof opts.onStart === 'function') {
418
+ opts.onStart.call(this, {
419
+ to: this.el,
420
+ from: this.el,
421
+ item: dragEl,
422
+ newIndex: startIndex,
423
+ oldIndex: startIndex,
424
+ clone: cloneEl
425
+ });
426
+ }
427
+ }
428
+
429
+ if (!isDragging) return;
430
+
431
+ preventDefault(evt);
432
+
433
+ // lastCoords = { x: coords.clientX, y: coords.clientY };
434
+
435
+ // 移动 ghost
436
+ moveGhost(ghostEl, coords.clientX, coords.clientY, dragEl);
437
+
438
+ // 自动滚动
439
+ autoScroll(this.el, coords.clientX, coords.clientY, opts);
440
+
441
+ // 查找当前鼠标下的 Sortable 实例
442
+ var targetSortable = this._detectTargetSortable(coords.clientX, coords.clientY);
443
+ if (!targetSortable) return;
444
+
445
+ var targetEl = targetSortable.el;
446
+ var children = getChildren(targetEl, opts.draggable || '*');
447
+
448
+ // 过滤掉 ghost 和隐藏元素
449
+ children = children.filter(function(child) {
450
+ return child !== cloneEl && child.style.display !== 'none';
451
+ });
452
+
453
+ // 插入计算
454
+ var insert = closestInsert(children, coords.clientX, coords.clientY, opts.direction);
455
+
456
+ if (insert.target) {
457
+ var pullResult = allowPull(activeSortable, targetSortable, dragEl);
458
+ if (pullResult === false) return;
459
+ if (!allowPut(activeSortable, targetSortable)) return;
460
+
461
+ // 触发 onMove
462
+ if (typeof opts.onMove === 'function') {
463
+ var moveResult = opts.onMove.call(this, {
464
+ dragged: dragEl,
465
+ related: insert.target,
466
+ to: targetEl,
467
+ from: activeSortable.el,
468
+ willInsertAfter: insert.after
469
+ });
470
+ if (moveResult === false) return;
471
+ }
472
+
473
+ // 执行 DOM 插入
474
+ if (insert.after) {
475
+ insert.target.parentNode.insertBefore(cloneEl, insert.target.nextSibling);
476
+ } else {
477
+ insert.target.parentNode.insertBefore(cloneEl, insert.target);
478
+ }
479
+
480
+ // 动画效果
481
+ if (opts.animation) {
482
+ this._animate(cloneEl, opts.animation);
483
+ }
484
+
485
+ this._lastSwapEl = insert.target;
486
+ } else if (children.length === 0 && targetEl !== activeSortable.el) {
487
+ // 空列表插入
488
+ if (allowPut(activeSortable, targetSortable)) {
489
+ targetEl.appendChild(cloneEl);
490
+ }
491
+ }
492
+ },
493
+
494
+ /**
495
+ * 拖拽结束
496
+ * @param {Event} evt
497
+ * @private
498
+ */
499
+ _onDragEnd: function() {
500
+ clearTimeout(this._delayTimer);
501
+ this._delayTimer = null;
502
+ this._pendingDrag = false;
503
+
504
+ if (!isDragging) {
505
+ // 未真正开始拖拽,清除状态
506
+ if (dragEl) {
507
+ removeClass(dragEl, this.options.chosenClass);
508
+ }
509
+ dragEl = null;
510
+ activeSortable = null;
511
+ return;
512
+ }
513
+
514
+ var self = this;
515
+ var opts = this.options;
516
+ var fromEl = startParent;
517
+ var toEl = cloneEl.parentNode;
518
+ var oldIndex = startIndex;
519
+ var newIndex = index(cloneEl);
520
+
521
+ // 恢复 dragEl 显示并放到最终位置
522
+ dragEl.style.display = '';
523
+ cloneEl.parentNode.insertBefore(dragEl, cloneEl);
524
+ cloneEl.parentNode.removeChild(cloneEl);
525
+ cloneEl = null;
526
+
527
+ // 清理 ghost
528
+ if (ghostEl && ghostEl.parentNode) {
529
+ ghostEl.parentNode.removeChild(ghostEl);
530
+ }
531
+ ghostEl = null;
532
+
533
+ removeClass(dragEl, opts.chosenClass);
534
+
535
+ // 判断事件类型
536
+ var isSameParent = fromEl === toEl;
537
+ var eventData = {
538
+ to: toEl,
539
+ from: fromEl,
540
+ item: dragEl,
541
+ newIndex: newIndex,
542
+ oldIndex: oldIndex,
543
+ clone: null
544
+ };
545
+
546
+ // 触发对应回调
547
+ if (!isSameParent) {
548
+ // 跨列表
549
+ if (typeof opts.onRemove === 'function' && fromEl === this.el) {
550
+ opts.onRemove.call(this, assign({}, eventData));
551
+ }
552
+ if (typeof opts.onAdd === 'function' && toEl === this.el) {
553
+ opts.onAdd.call(this, assign({}, eventData));
554
+ }
555
+ } else {
556
+ if (oldIndex !== newIndex) {
557
+ if (typeof opts.onUpdate === 'function') {
558
+ opts.onUpdate.call(this, assign({}, eventData));
559
+ }
560
+ }
561
+ }
562
+
563
+ if (typeof opts.onSort === 'function') {
564
+ opts.onSort.call(this, assign({}, eventData));
565
+ }
566
+
567
+ dispatchEvent(this.el, 'sortable:end', eventData);
568
+
569
+ if (typeof opts.onEnd === 'function') {
570
+ opts.onEnd.call(this, assign({}, eventData));
571
+ }
572
+
573
+ if (typeof opts.onUnchoose === 'function') {
574
+ opts.onUnchoose.call(this, dragEl, this);
575
+ }
576
+
577
+ isDragging = false;
578
+ dragEl = null;
579
+ activeSortable = null;
580
+ startParent = null;
581
+ startIndex = -1;
582
+ },
583
+
584
+ /**
585
+ * 检测鼠标下的目标 Sortable 实例
586
+ * @param {number} clientX
587
+ * @param {number} clientY
588
+ * @returns {Sortable|null}
589
+ * @private
590
+ */
591
+ _detectTargetSortable: function(clientX, clientY) {
592
+ var group = parseGroup(this.options.group);
593
+ var sortables = group.name ? getSortablesByGroup(group.name) : [this];
594
+
595
+ // 优先检测当前实例
596
+ var currentRect = getRect(this.el);
597
+ if (
598
+ clientX >= currentRect.left &&
599
+ clientX <= currentRect.right &&
600
+ clientY >= currentRect.top &&
601
+ clientY <= currentRect.bottom
602
+ ) {
603
+ return this;
604
+ }
605
+
606
+ // 检测其他实例
607
+ for (var i = 0; i < sortables.length; i++) {
608
+ var s = sortables[i];
609
+ if (s === this) continue;
610
+ var rect = getRect(s.el);
611
+ if (
612
+ clientX >= rect.left &&
613
+ clientX <= rect.right &&
614
+ clientY >= rect.top &&
615
+ clientY <= rect.bottom
616
+ ) {
617
+ return s;
618
+ }
619
+ }
620
+
621
+ return this;
622
+ },
623
+
624
+ /**
625
+ * 简单动画效果
626
+ * @param {HTMLElement} el
627
+ * @param {number} duration
628
+ * @private
629
+ */
630
+ _animate: function(el, duration) {
631
+ if (!duration) return;
632
+ addClass(el, 'sortable-animate');
633
+ setTimeout(function() {
634
+ removeClass(el, 'sortable-animate');
635
+ }, duration);
636
+ },
637
+
638
+ // ==================== 公共方法 ====================
639
+
640
+ /**
641
+ * 获取当前子元素顺序对应的 id/data-id 数组
642
+ * @param {string} [attr] - 属性名,默认取 data-id
643
+ * @returns {string[]}
644
+ */
645
+ toArray: function(attr) {
646
+ attr = attr || 'data-id';
647
+ var children = getChildren(this.el, this.options.draggable || '*');
648
+ return children.map(function(child) {
649
+ return child.getAttribute(attr) || '';
650
+ });
651
+ },
652
+
653
+ /**
654
+ * 根据 id 数组排序 DOM
655
+ * @param {string[]} order
656
+ * @param {string} [attr]
657
+ */
658
+ sort: function(order, attr) {
659
+ attr = attr || 'data-id';
660
+ var children = getChildren(this.el, this.options.draggable || '*');
661
+ var map = {};
662
+ for (var k = 0; k < children.length; k++) {
663
+ var c = children[k];
664
+ var id = c.getAttribute(attr);
665
+ if (id) map[id] = c;
666
+ }
667
+
668
+ for (var i = 0; i < order.length; i++) {
669
+ var child = map[order[i]];
670
+ if (child) {
671
+ this.el.appendChild(child);
672
+ }
673
+ }
674
+ },
675
+
676
+ /**
677
+ * 保存当前排序(触发 store)
678
+ */
679
+ save: function() {
680
+ var store = this.options.store;
681
+ if (store && store.set) {
682
+ store.set(this);
683
+ }
684
+ },
685
+
686
+ /**
687
+ * 销毁实例
688
+ */
689
+ destroy: function() {
690
+ if (this._unbindEvents) {
691
+ this._unbindEvents();
692
+ this._unbindEvents = null;
693
+ }
694
+ clearTimeout(this._delayTimer);
695
+ delete sortableInstances[this.id];
696
+ delete this.el._sortableInstance;
697
+ },
698
+
699
+ /**
700
+ * 获取/设置选项
701
+ * @param {string} name
702
+ * @param {*} [value]
703
+ * @returns {*}
704
+ */
705
+ option: function(name, value) {
706
+ if (value === undefined) {
707
+ return this.options[name];
708
+ }
709
+ this.options[name] = value;
710
+ },
711
+
712
+ /**
713
+ * 获取最近的 Sortable 祖先实例
714
+ * @param {HTMLElement} el
715
+ * @returns {Sortable|null}
716
+ */
717
+ closest: function(el) {
718
+ var current = el;
719
+ while (current) {
720
+ if (current._sortableInstance) {
721
+ return current._sortableInstance;
722
+ }
723
+ current = current.parentElement;
724
+ }
725
+ return null;
726
+ }
727
+ };
728
+
729
+ // 静态方法
730
+
731
+ /**
732
+ * 获取元素关联的 Sortable 实例
733
+ * @param {HTMLElement} el
734
+ * @returns {Sortable|null}
735
+ */
736
+ Sortable.get = function(el) {
737
+ return el && el._sortableInstance || null;
738
+ };
739
+
740
+ /**
741
+ * 创建实例
742
+ * @param {HTMLElement} el
743
+ * @param {Object} options
744
+ * @returns {Sortable}
745
+ */
746
+ Sortable.create = function(el, options) {
747
+ return new Sortable(el, options);
748
+ };
749
+
750
+ export default Sortable;
751
+ export { Sortable };