@meethive/components 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 (303) hide show
  1. package/es/AutoComplete/AutoComplete.js +84 -0
  2. package/es/AutoComplete/index.js +7 -0
  3. package/es/BadgeStatus/Badge.js +51 -0
  4. package/es/BadgeStatus/color.js +14 -0
  5. package/es/BadgeStatus/index.js +8 -0
  6. package/es/CardSelect/CardSelect.js +141 -0
  7. package/es/CardSelect/index.js +7 -0
  8. package/es/CardSelect/style/index.js +29 -0
  9. package/es/CheckButton/CheckButton.js +122 -0
  10. package/es/CheckButton/index.js +7 -0
  11. package/es/CheckButton/style/index.js +44 -0
  12. package/es/ConfigProvider/ConfigProvider.js +73 -0
  13. package/es/ConfigProvider/context.js +26 -0
  14. package/es/ConfigProvider/index.js +9 -0
  15. package/es/DragModal/DragModal.js +212 -0
  16. package/es/DragModal/index.js +7 -0
  17. package/es/DragModal/style/index.js +86 -0
  18. package/es/EditTable/Body.js +189 -0
  19. package/es/EditTable/CellRender.js +12 -0
  20. package/es/EditTable/EditTable.js +434 -0
  21. package/es/EditTable/FormItem.js +169 -0
  22. package/es/EditTable/Group.js +204 -0
  23. package/es/EditTable/Header.js +63 -0
  24. package/es/EditTable/HeaderRender.js +12 -0
  25. package/es/EditTable/components/ContextMenu/Menu.js +86 -0
  26. package/es/EditTable/components/ContextMenu/index.js +96 -0
  27. package/es/EditTable/components/Search/Search.js +163 -0
  28. package/es/EditTable/components/Search/Sort.js +119 -0
  29. package/es/EditTable/components/Search/index.js +2 -0
  30. package/es/EditTable/consts.js +13 -0
  31. package/es/EditTable/context.js +88 -0
  32. package/es/EditTable/hooks/index.js +19 -0
  33. package/es/EditTable/hooks/useGroup.js +48 -0
  34. package/es/EditTable/hooks/useResizeObserver.js +27 -0
  35. package/es/EditTable/hooks/useValidate.js +112 -0
  36. package/es/EditTable/index.js +25 -0
  37. package/es/EditTable/props.js +60 -0
  38. package/es/EditTable/style/body.js +63 -0
  39. package/es/EditTable/style/form.js +33 -0
  40. package/es/EditTable/style/group.js +33 -0
  41. package/es/EditTable/style/header.js +72 -0
  42. package/es/EditTable/style/index.js +52 -0
  43. package/es/EditTable/style/menu.js +27 -0
  44. package/es/EditTable/style/table.js +46 -0
  45. package/es/EditTable/utils.js +110 -0
  46. package/es/Ellipsis/Ellipsis.js +148 -0
  47. package/es/Ellipsis/index.js +7 -0
  48. package/es/Ellipsis/style/index.js +26 -0
  49. package/es/Empty/Empty.js +63 -0
  50. package/es/Empty/image.js +3 -0
  51. package/es/Empty/index.js +7 -0
  52. package/es/FullPage/FullPage.js +19 -0
  53. package/es/FullPage/index.js +7 -0
  54. package/es/Icon/Icon.js +49 -0
  55. package/es/Icon/index.js +7 -0
  56. package/es/LocaleProvider/LocaleProvider.js +31 -0
  57. package/es/LocaleProvider/index.js +7 -0
  58. package/es/LocaleReciver/index.js +24 -0
  59. package/es/Markdown/Markdown.js +118 -0
  60. package/es/Markdown/index.js +7 -0
  61. package/es/PermissionButton/PermissionButton.js +118 -0
  62. package/es/PermissionButton/confirm.js +94 -0
  63. package/es/PermissionButton/index.js +9 -0
  64. package/es/PermissionButton/shared.js +1 -0
  65. package/es/ProLayout/Basic/BasicLayout.js +422 -0
  66. package/es/ProLayout/Basic/BasicLayoutStyle.js +51 -0
  67. package/es/ProLayout/Basic/Header.js +111 -0
  68. package/es/ProLayout/Basic/HeaderStyle.js +10 -0
  69. package/es/ProLayout/PageContainer/index.js +354 -0
  70. package/es/ProLayout/PageContainer/style.js +85 -0
  71. package/es/ProLayout/RouteContext.js +28 -0
  72. package/es/ProLayout/SiderMenu/BaseMenu.js +241 -0
  73. package/es/ProLayout/SiderMenu/SiderMenu.js +274 -0
  74. package/es/ProLayout/SiderMenu/index.js +2 -0
  75. package/es/ProLayout/SiderMenu/style.js +204 -0
  76. package/es/ProLayout/TopHeader/index.js +170 -0
  77. package/es/ProLayout/TopHeader/style.js +154 -0
  78. package/es/ProLayout/defaultSettings.js +113 -0
  79. package/es/ProLayout/index.js +10 -0
  80. package/es/ProLayout/style/index.js +14 -0
  81. package/es/ProLayout/util.js +58 -0
  82. package/es/ProTable/Alert.js +40 -0
  83. package/es/ProTable/Content.js +97 -0
  84. package/es/ProTable/Header.js +33 -0
  85. package/es/ProTable/Pagination.js +55 -0
  86. package/es/ProTable/ProTable.js +279 -0
  87. package/es/ProTable/hooks/index.js +2 -0
  88. package/es/ProTable/hooks/useTableInject.js +6 -0
  89. package/es/ProTable/hooks/useTableSelection.js +115 -0
  90. package/es/ProTable/index.js +8 -0
  91. package/es/ProTable/setting.js +138 -0
  92. package/es/ProTable/style/index.js +113 -0
  93. package/es/RadioButton/RadioButton.js +53 -0
  94. package/es/RadioButton/index.js +8 -0
  95. package/es/RadioButton/style/index.js +25 -0
  96. package/es/Scrollbar/Bar.js +76 -0
  97. package/es/Scrollbar/Scrollbar.js +161 -0
  98. package/es/Scrollbar/Thumb.js +150 -0
  99. package/es/Scrollbar/constants.js +1 -0
  100. package/es/Scrollbar/index.js +7 -0
  101. package/es/Scrollbar/scrollbarProps.js +100 -0
  102. package/es/Scrollbar/style/index.js +85 -0
  103. package/es/Scrollbar/thumbProps.js +10 -0
  104. package/es/Scrollbar/util.js +39 -0
  105. package/es/Search/Item.js +239 -0
  106. package/es/Search/Search.js +90 -0
  107. package/es/Search/hooks/index.js +117 -0
  108. package/es/Search/hooks/useRouteQuery.js +86 -0
  109. package/es/Search/hooks/useSearchItems.js +50 -0
  110. package/es/Search/hooks/useTermOptions.js +29 -0
  111. package/es/Search/index.js +10 -0
  112. package/es/Search/setting.js +245 -0
  113. package/es/Search/style/index.js +5 -0
  114. package/es/Search/style/item.js +40 -0
  115. package/es/Search/style/search.js +177 -0
  116. package/es/Search/util.js +270 -0
  117. package/es/Skeleton/Skeleton.js +27 -0
  118. package/es/Skeleton/components/DashBoardCard.js +27 -0
  119. package/es/Skeleton/components/DashBoardChart.js +27 -0
  120. package/es/Skeleton/components/Detail.js +27 -0
  121. package/es/Skeleton/components/Drawer.js +27 -0
  122. package/es/Skeleton/components/Item.js +54 -0
  123. package/es/Skeleton/components/List.js +27 -0
  124. package/es/Skeleton/components/ListCard.js +28 -0
  125. package/es/Skeleton/components/ListCardItem.js +20 -0
  126. package/es/Skeleton/components/ListTable.js +27 -0
  127. package/es/Skeleton/components/Page.js +26 -0
  128. package/es/Skeleton/components/Search.js +16 -0
  129. package/es/Skeleton/components/Tree.js +27 -0
  130. package/es/Skeleton/index.js +28 -0
  131. package/es/Skeleton/style/index.js +195 -0
  132. package/es/TimeFormat/TimeFormat.js +36 -0
  133. package/es/TimeFormat/index.js +7 -0
  134. package/es/Title/Title.js +26 -0
  135. package/es/Title/index.js +7 -0
  136. package/es/Title/style/index.js +34 -0
  137. package/es/ValueItem/ValueItem.js +113 -0
  138. package/es/ValueItem/index.js +7 -0
  139. package/es/ValueItem/util.js +17 -0
  140. package/es/VirtualTable/VirtualTable.js +271 -0
  141. package/es/VirtualTable/data.js +60 -0
  142. package/es/VirtualTable/index.js +7 -0
  143. package/es/VirtualTable/style/index.js +34 -0
  144. package/es/components.js +21 -0
  145. package/es/index.js +17 -0
  146. package/es/locale/en-US.js +120 -0
  147. package/es/locale/zh-CN.js +120 -0
  148. package/es/style/styleRegister.js +19 -0
  149. package/es/style/variable.js +4 -0
  150. package/es/style.js +1 -0
  151. package/es/utils/constants.js +10 -0
  152. package/lib/AutoComplete/AutoComplete.js +84 -0
  153. package/lib/AutoComplete/index.js +7 -0
  154. package/lib/BadgeStatus/Badge.js +51 -0
  155. package/lib/BadgeStatus/color.js +14 -0
  156. package/lib/BadgeStatus/index.js +8 -0
  157. package/lib/CardSelect/CardSelect.js +141 -0
  158. package/lib/CardSelect/index.js +7 -0
  159. package/lib/CardSelect/style/index.js +29 -0
  160. package/lib/CheckButton/CheckButton.js +122 -0
  161. package/lib/CheckButton/index.js +7 -0
  162. package/lib/CheckButton/style/index.js +44 -0
  163. package/lib/ConfigProvider/ConfigProvider.js +73 -0
  164. package/lib/ConfigProvider/context.js +26 -0
  165. package/lib/ConfigProvider/index.js +9 -0
  166. package/lib/DragModal/DragModal.js +212 -0
  167. package/lib/DragModal/index.js +7 -0
  168. package/lib/DragModal/style/index.js +86 -0
  169. package/lib/EditTable/Body.js +189 -0
  170. package/lib/EditTable/CellRender.js +12 -0
  171. package/lib/EditTable/EditTable.js +434 -0
  172. package/lib/EditTable/FormItem.js +169 -0
  173. package/lib/EditTable/Group.js +204 -0
  174. package/lib/EditTable/Header.js +63 -0
  175. package/lib/EditTable/HeaderRender.js +12 -0
  176. package/lib/EditTable/components/ContextMenu/Menu.js +86 -0
  177. package/lib/EditTable/components/ContextMenu/index.js +96 -0
  178. package/lib/EditTable/components/Search/Search.js +163 -0
  179. package/lib/EditTable/components/Search/Sort.js +119 -0
  180. package/lib/EditTable/components/Search/index.js +2 -0
  181. package/lib/EditTable/consts.js +13 -0
  182. package/lib/EditTable/context.js +88 -0
  183. package/lib/EditTable/hooks/index.js +19 -0
  184. package/lib/EditTable/hooks/useGroup.js +48 -0
  185. package/lib/EditTable/hooks/useResizeObserver.js +27 -0
  186. package/lib/EditTable/hooks/useValidate.js +112 -0
  187. package/lib/EditTable/index.js +25 -0
  188. package/lib/EditTable/props.js +60 -0
  189. package/lib/EditTable/style/body.js +63 -0
  190. package/lib/EditTable/style/form.js +33 -0
  191. package/lib/EditTable/style/group.js +33 -0
  192. package/lib/EditTable/style/header.js +72 -0
  193. package/lib/EditTable/style/index.js +52 -0
  194. package/lib/EditTable/style/menu.js +27 -0
  195. package/lib/EditTable/style/table.js +46 -0
  196. package/lib/EditTable/utils.js +110 -0
  197. package/lib/Ellipsis/Ellipsis.js +148 -0
  198. package/lib/Ellipsis/index.js +7 -0
  199. package/lib/Ellipsis/style/index.js +26 -0
  200. package/lib/Empty/Empty.js +63 -0
  201. package/lib/Empty/image.js +3 -0
  202. package/lib/Empty/index.js +7 -0
  203. package/lib/FullPage/FullPage.js +19 -0
  204. package/lib/FullPage/index.js +7 -0
  205. package/lib/Icon/Icon.js +49 -0
  206. package/lib/Icon/index.js +7 -0
  207. package/lib/LocaleProvider/LocaleProvider.js +31 -0
  208. package/lib/LocaleProvider/index.js +7 -0
  209. package/lib/LocaleReciver/index.js +24 -0
  210. package/lib/Markdown/Markdown.js +118 -0
  211. package/lib/Markdown/index.js +7 -0
  212. package/lib/PermissionButton/PermissionButton.js +118 -0
  213. package/lib/PermissionButton/confirm.js +94 -0
  214. package/lib/PermissionButton/index.js +9 -0
  215. package/lib/PermissionButton/shared.js +1 -0
  216. package/lib/ProLayout/Basic/BasicLayout.js +422 -0
  217. package/lib/ProLayout/Basic/BasicLayoutStyle.js +51 -0
  218. package/lib/ProLayout/Basic/Header.js +111 -0
  219. package/lib/ProLayout/Basic/HeaderStyle.js +10 -0
  220. package/lib/ProLayout/PageContainer/index.js +354 -0
  221. package/lib/ProLayout/PageContainer/style.js +85 -0
  222. package/lib/ProLayout/RouteContext.js +28 -0
  223. package/lib/ProLayout/SiderMenu/BaseMenu.js +241 -0
  224. package/lib/ProLayout/SiderMenu/SiderMenu.js +274 -0
  225. package/lib/ProLayout/SiderMenu/index.js +2 -0
  226. package/lib/ProLayout/SiderMenu/style.js +204 -0
  227. package/lib/ProLayout/TopHeader/index.js +170 -0
  228. package/lib/ProLayout/TopHeader/style.js +154 -0
  229. package/lib/ProLayout/defaultSettings.js +113 -0
  230. package/lib/ProLayout/index.js +10 -0
  231. package/lib/ProLayout/style/index.js +14 -0
  232. package/lib/ProLayout/util.js +58 -0
  233. package/lib/ProTable/Alert.js +40 -0
  234. package/lib/ProTable/Content.js +97 -0
  235. package/lib/ProTable/Header.js +33 -0
  236. package/lib/ProTable/Pagination.js +55 -0
  237. package/lib/ProTable/ProTable.js +279 -0
  238. package/lib/ProTable/hooks/index.js +2 -0
  239. package/lib/ProTable/hooks/useTableInject.js +6 -0
  240. package/lib/ProTable/hooks/useTableSelection.js +115 -0
  241. package/lib/ProTable/index.js +8 -0
  242. package/lib/ProTable/setting.js +138 -0
  243. package/lib/ProTable/style/index.js +113 -0
  244. package/lib/RadioButton/RadioButton.js +53 -0
  245. package/lib/RadioButton/index.js +8 -0
  246. package/lib/RadioButton/style/index.js +25 -0
  247. package/lib/Scrollbar/Bar.js +76 -0
  248. package/lib/Scrollbar/Scrollbar.js +161 -0
  249. package/lib/Scrollbar/Thumb.js +150 -0
  250. package/lib/Scrollbar/constants.js +1 -0
  251. package/lib/Scrollbar/index.js +7 -0
  252. package/lib/Scrollbar/scrollbarProps.js +100 -0
  253. package/lib/Scrollbar/style/index.js +85 -0
  254. package/lib/Scrollbar/thumbProps.js +10 -0
  255. package/lib/Scrollbar/util.js +39 -0
  256. package/lib/Search/Item.js +239 -0
  257. package/lib/Search/Search.js +90 -0
  258. package/lib/Search/hooks/index.js +117 -0
  259. package/lib/Search/hooks/useRouteQuery.js +86 -0
  260. package/lib/Search/hooks/useSearchItems.js +50 -0
  261. package/lib/Search/hooks/useTermOptions.js +29 -0
  262. package/lib/Search/index.js +10 -0
  263. package/lib/Search/setting.js +245 -0
  264. package/lib/Search/style/index.js +5 -0
  265. package/lib/Search/style/item.js +40 -0
  266. package/lib/Search/style/search.js +177 -0
  267. package/lib/Search/util.js +270 -0
  268. package/lib/Skeleton/Skeleton.js +27 -0
  269. package/lib/Skeleton/components/DashBoardCard.js +27 -0
  270. package/lib/Skeleton/components/DashBoardChart.js +27 -0
  271. package/lib/Skeleton/components/Detail.js +27 -0
  272. package/lib/Skeleton/components/Drawer.js +27 -0
  273. package/lib/Skeleton/components/Item.js +54 -0
  274. package/lib/Skeleton/components/List.js +27 -0
  275. package/lib/Skeleton/components/ListCard.js +28 -0
  276. package/lib/Skeleton/components/ListCardItem.js +20 -0
  277. package/lib/Skeleton/components/ListTable.js +27 -0
  278. package/lib/Skeleton/components/Page.js +26 -0
  279. package/lib/Skeleton/components/Search.js +16 -0
  280. package/lib/Skeleton/components/Tree.js +27 -0
  281. package/lib/Skeleton/index.js +28 -0
  282. package/lib/Skeleton/style/index.js +195 -0
  283. package/lib/TimeFormat/TimeFormat.js +36 -0
  284. package/lib/TimeFormat/index.js +7 -0
  285. package/lib/Title/Title.js +26 -0
  286. package/lib/Title/index.js +7 -0
  287. package/lib/Title/style/index.js +34 -0
  288. package/lib/ValueItem/ValueItem.js +113 -0
  289. package/lib/ValueItem/index.js +7 -0
  290. package/lib/ValueItem/util.js +17 -0
  291. package/lib/VirtualTable/VirtualTable.js +271 -0
  292. package/lib/VirtualTable/data.js +60 -0
  293. package/lib/VirtualTable/index.js +7 -0
  294. package/lib/VirtualTable/style/index.js +34 -0
  295. package/lib/components.js +21 -0
  296. package/lib/index.js +17 -0
  297. package/lib/locale/en-US.js +120 -0
  298. package/lib/locale/zh-CN.js +120 -0
  299. package/lib/style/styleRegister.js +19 -0
  300. package/lib/style/variable.js +4 -0
  301. package/lib/style.js +1 -0
  302. package/lib/utils/constants.js +10 -0
  303. package/package.json +164 -0
@@ -0,0 +1,53 @@
1
+
2
+ import { defineComponent, ref, computed, watch } from 'vue'
3
+ import useRadioButtonStyle from './style'
4
+
5
+ export default defineComponent({
6
+ name: 'JRadioButton',
7
+ props: {
8
+ value: {
9
+ type: [String, Number],
10
+ default: undefined
11
+ },
12
+ options: {
13
+ type: Array,
14
+ default: () => []
15
+ },
16
+ columns: {
17
+ type: Number,
18
+ default: 3
19
+ }
20
+ },
21
+ emits: ['update:value'],
22
+ setup(props, { emit }) {
23
+ const prefixCls = computed(() => 'j-radio-button')
24
+ const [wrapSSR, hashId] = useRadioButtonStyle(prefixCls)
25
+
26
+ const myValue = ref(props.value)
27
+
28
+ const styles = computed(() => {
29
+ return {
30
+ 'grid-template-columns': `repeat(${props.columns}, 1fr)`
31
+ }
32
+ })
33
+
34
+ const onClick = (record) => {
35
+ if (myValue.value !== record.value) {
36
+ myValue.value = record.value
37
+ emit('update:value', record.value)
38
+ emit('select', record.value)
39
+ }
40
+ }
41
+
42
+ watch(() => props.value, () => {
43
+ myValue.value = props.value
44
+ })
45
+
46
+ return {
47
+ hashId,
48
+ myValue,
49
+ styles,
50
+ onClick
51
+ }
52
+ }
53
+ })
@@ -0,0 +1,8 @@
1
+ import RadioButton from './RadioButton.js'
2
+
3
+ RadioButton.install = function (app) {
4
+ app.component(RadioButton.name, RadioButton)
5
+ return app
6
+ }
7
+
8
+ export default RadioButton
@@ -0,0 +1,25 @@
1
+ import genComponentStyle from '../../style/styleRegister'
2
+
3
+ const genRadioButtonStyle = (config) => {
4
+ const { token } = config
5
+ return {
6
+ '.j-radio-button': {
7
+ display: 'grid',
8
+ gap: '16px',
9
+ '.j-radio-button-item': {
10
+ padding: '6px 12px',
11
+ textAlign: 'center',
12
+ height: '100%',
13
+ borderRadius: '2px',
14
+ backgroundColor: '#f5f5f5',
15
+ cursor: 'pointer',
16
+ '&.active': {
17
+ color: '#fff',
18
+ backgroundColor: token.colorPrimary
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ export default genComponentStyle([genRadioButtonStyle])
@@ -0,0 +1,76 @@
1
+ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+ import { defineComponent, inject, ref } from 'vue'
3
+ import { GAP } from './util'
4
+ import Thumb from './Thumb.js'
5
+ import { scrollbarContextKey } from './constants'
6
+
7
+ export default defineComponent({
8
+ name: 'ScrollbarBar',
9
+ components: { Thumb },
10
+ props: {
11
+ always: {
12
+ type: Boolean,
13
+ default: true
14
+ },
15
+ minSize: {
16
+ type: Number,
17
+ required: true
18
+ }
19
+ },
20
+ setup(props, { expose }) {
21
+ const scrollbar = inject(scrollbarContextKey)
22
+
23
+ const moveX = ref(0)
24
+ const moveY = ref(0)
25
+ const sizeWidth = ref('')
26
+ const sizeHeight = ref('')
27
+ const ratioY = ref(1)
28
+ const ratioX = ref(1)
29
+
30
+ const handleScroll = (wrap) => {
31
+ if (wrap) {
32
+ const offsetHeight = wrap.offsetHeight - GAP
33
+ const offsetWidth = wrap.offsetWidth - GAP
34
+
35
+ moveY.value = ((wrap.scrollTop * 100) / offsetHeight) * ratioY.value
36
+ moveX.value = ((wrap.scrollLeft * 100) / offsetWidth) * ratioX.value
37
+ }
38
+ }
39
+
40
+ const update = () => {
41
+ const wrap = _optionalChain([scrollbar, 'optionalAccess', _ => _.wrapElement])
42
+ if (!wrap) return
43
+
44
+ const offsetHeight = wrap.offsetHeight - GAP
45
+ const offsetWidth = wrap.offsetWidth - GAP
46
+
47
+ const originalHeight = offsetHeight ** 2 / wrap.scrollHeight
48
+ const originalWidth = offsetWidth ** 2 / wrap.scrollWidth
49
+
50
+ const height = Math.max(originalHeight, props.minSize)
51
+ const width = Math.max(originalWidth, props.minSize)
52
+
53
+ ratioY.value =
54
+ originalHeight / (offsetHeight - originalHeight) / (height / (offsetHeight - height))
55
+ ratioX.value =
56
+ originalWidth / (offsetWidth - originalWidth) / (width / (offsetWidth - width))
57
+
58
+ sizeHeight.value = height + GAP < offsetHeight ? `${height}px` : ''
59
+ sizeWidth.value = width + GAP < offsetWidth ? `${width}px` : ''
60
+ }
61
+
62
+ expose({
63
+ handleScroll,
64
+ update
65
+ })
66
+
67
+ return {
68
+ moveX,
69
+ moveY,
70
+ sizeWidth,
71
+ sizeHeight,
72
+ ratioY,
73
+ ratioX
74
+ }
75
+ }
76
+ })
@@ -0,0 +1,161 @@
1
+ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+ import {
3
+ defineComponent,
4
+ computed,
5
+ nextTick,
6
+ onMounted,
7
+ onUpdated,
8
+ provide,
9
+ reactive,
10
+ ref,
11
+ watch
12
+ } from 'vue'
13
+ import { useEventListener, useResizeObserver } from '@vueuse/core'
14
+ import { isNumber, isObject } from '@meethive/utils'
15
+ import Bar from './Bar.js'
16
+ import { scrollbarContextKey } from './constants'
17
+ import { scrollbarEmits, scrollbarProps } from './scrollbarProps'
18
+ import useScrollbarStyle from './style'
19
+
20
+ const COMPONENT_NAME = 'JScrollbar'
21
+
22
+ export default defineComponent({
23
+ name: COMPONENT_NAME,
24
+ components: { Bar },
25
+ props: scrollbarProps,
26
+ emits: scrollbarEmits,
27
+ setup(props, { expose, emit }) {
28
+ const prefixCls = computed(() => 'j-scrollbar')
29
+ const [wrapSSR, hashId] = useScrollbarStyle(prefixCls)
30
+
31
+ let stopResizeObserver = undefined
32
+ let stopResizeListener = undefined
33
+
34
+ const scrollbarRef = ref()
35
+ const wrapRef = ref()
36
+ const resizeRef = ref()
37
+ const barRef = ref()
38
+
39
+ const wrapStyle = computed(() => {
40
+ const style = {}
41
+ if (props.height) style.height = `${props.height}px`
42
+ if (props.maxHeight) style.maxHeight = `${props.maxHeight}px`
43
+ return [props.wrapStyle, style]
44
+ })
45
+
46
+ const wrapKls = computed(() => {
47
+ return ['j-scrollbar__wrap', 'j-scrollbar__wrap--hidden-default']
48
+ })
49
+
50
+ const resizeKls = computed(() => {
51
+ return ['j-scrollbar__view', props.viewClass]
52
+ })
53
+
54
+ const handleScroll = () => {
55
+ if (wrapRef.value) {
56
+ _optionalChain([barRef, 'access', _ => _.value, 'optionalAccess', _2 => _2.handleScroll, 'call', _3 => _3(wrapRef.value)])
57
+ emit('scroll', {
58
+ scrollTop: wrapRef.value.scrollTop,
59
+ scrollLeft: wrapRef.value.scrollLeft
60
+ })
61
+ }
62
+ }
63
+
64
+ function scrollTo(arg1, arg2) {
65
+ if (isObject(arg1)) {
66
+ wrapRef.value.scrollTo(arg1 )
67
+ } else if (isNumber(arg1) && isNumber(arg2)) {
68
+ wrapRef.value.scrollTo(arg1, arg2)
69
+ }
70
+ }
71
+
72
+ const setScrollTop = (value) => {
73
+ if (!isNumber(value)) {
74
+ throw new Error('value must be a number')
75
+ }
76
+ wrapRef.value.scrollTop = value
77
+ }
78
+
79
+ const setScrollLeft = (value) => {
80
+ if (!isNumber(value)) {
81
+ throw new Error(`[${COMPONENT_NAME}] value must be a number`)
82
+ }
83
+ wrapRef.value.scrollLeft = value
84
+ }
85
+
86
+ const update = () => {
87
+ _optionalChain([barRef, 'access', _4 => _4.value, 'optionalAccess', _5 => _5.update, 'call', _6 => _6()])
88
+ }
89
+
90
+ watch(
91
+ () => props.noresize,
92
+ (noResize) => {
93
+ if (noResize) {
94
+ _optionalChain([stopResizeObserver, 'optionalCall', _7 => _7()])
95
+ _optionalChain([stopResizeListener, 'optionalCall', _8 => _8()])
96
+ } else {
97
+ ;({ stop: stopResizeObserver } = useResizeObserver(resizeRef, update))
98
+ stopResizeListener = useEventListener('resize', update)
99
+ }
100
+ },
101
+ { immediate: true }
102
+ )
103
+
104
+ watch(
105
+ () => [props.maxHeight, props.height],
106
+ () => {
107
+ if (!props.native)
108
+ nextTick(() => {
109
+ update()
110
+ if (wrapRef.value) {
111
+ _optionalChain([barRef, 'access', _9 => _9.value, 'optionalAccess', _10 => _10.handleScroll, 'call', _11 => _11(wrapRef.value)])
112
+ }
113
+ })
114
+ }
115
+ )
116
+
117
+ provide(
118
+ scrollbarContextKey,
119
+ reactive({
120
+ scrollbarElement: scrollbarRef,
121
+ wrapElement: wrapRef
122
+ })
123
+ )
124
+
125
+ onMounted(() => {
126
+ if (!props.native)
127
+ nextTick(() => {
128
+ update()
129
+ })
130
+ })
131
+
132
+ onUpdated(() => update())
133
+
134
+ expose({
135
+ /** @description scrollbar wrap ref */
136
+ wrapRef,
137
+ /** @description update scrollbar state manually */
138
+ update,
139
+ /** @description scrolls to a particular set of coordinates */
140
+ scrollTo,
141
+ /** @description set distance to scroll top */
142
+ setScrollTop,
143
+ /** @description set distance to scroll left */
144
+ setScrollLeft,
145
+ /** @description handle scroll event */
146
+ handleScroll
147
+ })
148
+
149
+ return {
150
+ hashId,
151
+ scrollbarRef,
152
+ wrapRef,
153
+ resizeRef,
154
+ barRef,
155
+ wrapStyle,
156
+ wrapKls,
157
+ resizeKls,
158
+ handleScroll
159
+ }
160
+ }
161
+ })
@@ -0,0 +1,150 @@
1
+ function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+ import { defineComponent, computed, inject, onBeforeUnmount, ref, toRef } from 'vue'
3
+ import { useEventListener } from '@vueuse/core'
4
+ import { isClient } from '@meethive/utils'
5
+ import { scrollbarContextKey } from './constants'
6
+ import { BAR_MAP, renderThumbStyle } from './util'
7
+ import { thumbProps } from './thumbProps'
8
+ import useScrollbarStyle from './style'
9
+
10
+ export default defineComponent({
11
+ name: 'ScrollbarThumb',
12
+ props: thumbProps,
13
+ setup(props) {
14
+ const scrollbar = inject(scrollbarContextKey)
15
+ if (!scrollbar) throw new Error('can not inject scrollbar context')
16
+
17
+ const instance = ref()
18
+ const thumb = ref()
19
+ const thumbState = ref({})
20
+ const visible = ref(false)
21
+
22
+ const prefixCls = computed(() => 'j-scrollbar')
23
+ const [wrapSSR, hashId] = useScrollbarStyle(prefixCls)
24
+
25
+ let cursorDown = false
26
+ let cursorLeave = false
27
+ let originalOnSelectStart = isClient
28
+ ? document.onselectstart
29
+ : null
30
+
31
+ const bar = computed(() => BAR_MAP[props.vertical ? 'vertical' : 'horizontal'])
32
+
33
+ const thumbStyle = computed(() =>
34
+ renderThumbStyle({
35
+ size: props.size ,
36
+ move: props.move ,
37
+ bar: bar.value
38
+ })
39
+ )
40
+
41
+ const offsetRatio = computed(
42
+ () =>
43
+ _optionalChain([(instance.value ), 'optionalAccess', _ => _[bar.value.offset]]) ** 2 /
44
+ scrollbar.wrapElement[bar.value.scrollSize] /
45
+ props.ratio /
46
+ _optionalChain([(thumb.value ), 'optionalAccess', _2 => _2[bar.value.offset]])
47
+ )
48
+
49
+ const clickThumbHandler = (e) => {
50
+ // prevent click event of middle and right button
51
+ e.stopPropagation()
52
+ if (e.ctrlKey || [1, 2].includes(e.button)) return
53
+
54
+ _optionalChain([window, 'access', _3 => _3.getSelection, 'call', _4 => _4(), 'optionalAccess', _5 => _5.removeAllRanges, 'call', _6 => _6()])
55
+ startDrag(e)
56
+
57
+ const el = e.currentTarget
58
+ if (!el) return
59
+
60
+ thumbState.value[bar.value.axis] =
61
+ (el )[bar.value.offset] -
62
+ (e[bar.value.client] - el.getBoundingClientRect()[bar.value.direction])
63
+ }
64
+
65
+ const clickTrackHandler = (e) => {
66
+ if (!thumb.value || !instance.value || !scrollbar.wrapElement) return
67
+
68
+ const offset = Math.abs(
69
+ (e.target ).getBoundingClientRect()[bar.value.direction] - e[bar.value.client]
70
+ )
71
+ const thumbHalf = (thumb.value )[bar.value.offset] / 2
72
+ const thumbPositionPercentage =
73
+ ((offset - thumbHalf) * 100 * offsetRatio.value) /
74
+ (instance.value )[bar.value.offset]
75
+
76
+ scrollbar.wrapElement[bar.value.scroll] =
77
+ (thumbPositionPercentage * scrollbar.wrapElement[bar.value.scrollSize]) / 100
78
+ }
79
+
80
+ const startDrag = (e) => {
81
+ e.stopImmediatePropagation()
82
+ cursorDown = true
83
+ document.addEventListener('mousemove', mouseMoveDocumentHandler)
84
+ document.addEventListener('mouseup', mouseUpDocumentHandler)
85
+ originalOnSelectStart = document.onselectstart
86
+ document.onselectstart = () => false
87
+ }
88
+
89
+ const mouseMoveDocumentHandler = (e) => {
90
+ if (!instance.value || !thumb.value) return
91
+ if (cursorDown === false) return
92
+
93
+ const prevPage = thumbState.value[bar.value.axis]
94
+ if (!prevPage) return
95
+
96
+ const offset =
97
+ (instance.value.getBoundingClientRect()[bar.value.direction] - e[bar.value.client]) * -1
98
+ const thumbClickPosition = (thumb.value )[bar.value.offset] - prevPage
99
+ const thumbPositionPercentage =
100
+ ((offset - thumbClickPosition) * 100 * offsetRatio.value) /
101
+ (instance.value )[bar.value.offset]
102
+
103
+ scrollbar.wrapElement[bar.value.scroll] =
104
+ (thumbPositionPercentage * scrollbar.wrapElement[bar.value.scrollSize]) / 100
105
+ }
106
+
107
+ const mouseUpDocumentHandler = () => {
108
+ cursorDown = false
109
+ thumbState.value[bar.value.axis] = 0
110
+ document.removeEventListener('mousemove', mouseMoveDocumentHandler)
111
+ document.removeEventListener('mouseup', mouseUpDocumentHandler)
112
+ restoreOnselectstart()
113
+ if (cursorLeave) visible.value = false
114
+ }
115
+
116
+ const mouseMoveScrollbarHandler = () => {
117
+ cursorLeave = false
118
+ visible.value = !!props.size
119
+ }
120
+
121
+ const mouseLeaveScrollbarHandler = () => {
122
+ cursorLeave = true
123
+ visible.value = cursorDown
124
+ }
125
+
126
+ onBeforeUnmount(() => {
127
+ restoreOnselectstart()
128
+ document.removeEventListener('mouseup', mouseUpDocumentHandler)
129
+ })
130
+
131
+ const restoreOnselectstart = () => {
132
+ if (document.onselectstart !== originalOnSelectStart)
133
+ document.onselectstart = originalOnSelectStart
134
+ }
135
+
136
+ useEventListener(toRef(scrollbar, 'scrollbarElement'), 'mousemove', mouseMoveScrollbarHandler)
137
+ useEventListener(toRef(scrollbar, 'scrollbarElement'), 'mouseleave', mouseLeaveScrollbarHandler)
138
+
139
+ return {
140
+ props,
141
+ instance,
142
+ thumb,
143
+ visible,
144
+ hashId,
145
+ thumbStyle,
146
+ clickThumbHandler,
147
+ clickTrackHandler
148
+ }
149
+ }
150
+ })
@@ -0,0 +1 @@
1
+ export const scrollbarContextKey = Symbol('scrollbarContextKey')
@@ -0,0 +1,7 @@
1
+ import Scrollbar from './Scrollbar.js'
2
+
3
+ Scrollbar.install = function (app) {
4
+ app.component(Scrollbar.name, Scrollbar)
5
+ }
6
+
7
+ export default Scrollbar
@@ -0,0 +1,100 @@
1
+ import { isNumber } from '@meethive/utils'
2
+
3
+ export const scrollbarProps = {
4
+ /**
5
+ * @description height of scrollbar
6
+ */
7
+ height: {
8
+ type: [String, Number],
9
+ default: ''
10
+ },
11
+ /**
12
+ * @description max height of scrollbar
13
+ */
14
+ maxHeight: {
15
+ type: [String, Number],
16
+ default: ''
17
+ },
18
+ /**
19
+ * @description whether to use the native scrollbar
20
+ */
21
+ native: {
22
+ type: Boolean,
23
+ default: false
24
+ },
25
+ /**
26
+ * @description style of wrap
27
+ */
28
+ wrapStyle: {
29
+ type: [String, Object, Array],
30
+ default: ''
31
+ },
32
+ /**
33
+ * @description class of wrap
34
+ */
35
+ wrapClass: {
36
+ type: [String, Array],
37
+ default: ''
38
+ },
39
+ /**
40
+ * @description class of view
41
+ */
42
+ viewClass: {
43
+ type: [String, Array],
44
+ default: ''
45
+ },
46
+ /**
47
+ * @description style of view
48
+ */
49
+ viewStyle: {
50
+ type: [String, Array, Object],
51
+ default: ''
52
+ },
53
+ /**
54
+ * @description do not respond to container size changes, if the container size does not change, it is better to set it to optimize performance
55
+ */
56
+ noresize: Boolean,
57
+ /**
58
+ * @description element tag of the view
59
+ */
60
+ tag: {
61
+ type: String,
62
+ default: 'div'
63
+ },
64
+ /**
65
+ * @description always show
66
+ */
67
+ always: Boolean,
68
+ /**
69
+ * @description minimum size of scrollbar
70
+ */
71
+ minSize: {
72
+ type: Number,
73
+ default: 20
74
+ },
75
+ /**
76
+ * @description id of view
77
+ */
78
+ id: String,
79
+ /**
80
+ * @description role of view
81
+ */
82
+ role: String,
83
+ /**
84
+ * @description aria-label of view
85
+ */
86
+ ariaLabel: String,
87
+ /**
88
+ * @description aria-orientation of view
89
+ */
90
+ ariaOrientation: {
91
+ type: String,
92
+ values: ['horizontal', 'vertical']
93
+ }
94
+ }
95
+
96
+ export const scrollbarEmits = {
97
+ scroll: ({ scrollTop, scrollLeft }) => {
98
+ return [scrollTop, scrollLeft].every(isNumber)
99
+ }
100
+ }
@@ -0,0 +1,85 @@
1
+ import genComponentStyle from '../../style/styleRegister'
2
+
3
+ const scrollbarBgColor = '#909399'
4
+ const scrollbarHoverBgColor = '#909399'
5
+ const scrollbarHoverOpacity = 0.5
6
+ const scrollbarOpacity = 0.3
7
+ const transitionDuration = '0.3s'
8
+
9
+ const genScrollbarStyle = (config) => {
10
+ const { componentCls, token } = config
11
+
12
+ return {
13
+ [componentCls]: {
14
+ overflow: 'hidden',
15
+ position: 'relative',
16
+ height: '100%',
17
+
18
+ [`${componentCls}__wrap`]: {
19
+ overflow: 'auto',
20
+ height: '100%',
21
+
22
+ [`${componentCls}--hidden-default`]: {
23
+ scrollbarWidth: 'none',
24
+ '&::-webkit-scrollbar': {
25
+ display: 'none'
26
+ }
27
+ }
28
+ },
29
+
30
+ [`${componentCls}__thumb`]: {
31
+ position: 'relative',
32
+ display: 'block',
33
+ width: 0,
34
+ height: 0,
35
+ cursor: 'pointer',
36
+ borderRadius: 'inherit',
37
+ backgroundColor: scrollbarBgColor,
38
+ transition: `${transitionDuration} background-color`,
39
+ opacity: scrollbarOpacity,
40
+ '&:hover': {
41
+ backgroundColor: scrollbarHoverBgColor,
42
+ opacity: scrollbarOpacity
43
+ }
44
+ },
45
+
46
+ [`${componentCls}__bar`]: {
47
+ position: 'absolute',
48
+ right: '2px',
49
+ bottom: '2px',
50
+ zIndex: 1,
51
+ borderRadius: '4px',
52
+
53
+ '&.is-vertical': {
54
+ width: '6px',
55
+ top: '2px',
56
+ '> div': {
57
+ width: '100%'
58
+ }
59
+ },
60
+
61
+ '&.is-horizontal': {
62
+ height: '6px',
63
+ left: '2px',
64
+ '> div': {
65
+ height: '100%'
66
+ }
67
+ }
68
+ }
69
+ },
70
+
71
+ [`${componentCls}-fade`]: {
72
+ [`${componentCls}-fade-enter-active`]: {
73
+ transition: 'opacity 340ms ease-out'
74
+ },
75
+ [`${componentCls}-fade-leave-active`]: {
76
+ transition: 'opacity 120ms ease-out'
77
+ },
78
+ [`${componentCls}-fade-enter-from,${componentCls}-fade-leave-active`]: {
79
+ opacity: 0
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ export default genComponentStyle([genScrollbarStyle])
@@ -0,0 +1,10 @@
1
+ export const thumbProps = {
2
+ vertical: Boolean,
3
+ size: String,
4
+ move: Number,
5
+ ratio: {
6
+ type: Number,
7
+ required: true
8
+ },
9
+ always: Boolean
10
+ }