@king-design/intact 3.6.2-beta.1 → 3.7.0

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 (281) hide show
  1. package/components/.DS_Store +0 -0
  2. package/components/anchor/constants.ts +3 -0
  3. package/components/anchor/demos/basic.md +34 -0
  4. package/components/anchor/demos/container.md +76 -0
  5. package/components/anchor/demos/events.md +100 -0
  6. package/components/anchor/demos/horizontal.md +33 -0
  7. package/components/anchor/demos/nested.md +132 -0
  8. package/components/anchor/index.md +38 -0
  9. package/components/anchor/index.spec.ts +171 -0
  10. package/components/anchor/index.ts +159 -0
  11. package/components/anchor/index.vdt +24 -0
  12. package/components/anchor/link.ts +44 -0
  13. package/components/anchor/link.vdt +49 -0
  14. package/components/anchor/styles.ts +50 -0
  15. package/components/anchor/useScroll.ts +221 -0
  16. package/components/config/demos/basic.md +11 -3
  17. package/components/descriptions/.DS_Store +0 -0
  18. package/components/dialog/base.vdt +3 -1
  19. package/components/drawer/demos/resizable.md +67 -0
  20. package/components/drawer/index.md +1 -0
  21. package/components/drawer/index.spec.ts +43 -0
  22. package/components/drawer/index.ts +14 -0
  23. package/components/drawer/index.vdt +20 -3
  24. package/components/drawer/styles.ts +44 -0
  25. package/components/drawer/useDrawerResizable.ts +190 -0
  26. package/components/icon/demos/color.md +1 -1
  27. package/components/icon/demos/icons.md +18 -0
  28. package/components/menu/.DS_Store +0 -0
  29. package/components/menu/demos/.DS_Store +0 -0
  30. package/components/menu/demos/collapse.md +2 -2
  31. package/components/menu/demos/showCollapseArrow.md +3 -3
  32. package/components/menu/demos/size.md +4 -4
  33. package/components/menu/styles.ts +7 -3
  34. package/components/notification/demos/basic.md +27 -0
  35. package/components/notification/demos/close.md +52 -0
  36. package/components/notification/demos/duration.md +43 -0
  37. package/components/notification/demos/events.md +39 -0
  38. package/components/notification/demos/hideClose.md +30 -0
  39. package/components/notification/demos/icon.md +47 -0
  40. package/components/notification/demos/position.md +39 -0
  41. package/components/notification/demos/types.md +38 -0
  42. package/components/notification/index.md +62 -0
  43. package/components/notification/index.spec.ts +211 -0
  44. package/components/notification/index.ts +2 -0
  45. package/components/notification/notification.ts +185 -0
  46. package/components/notification/notification.vdt +62 -0
  47. package/components/notification/notifications.ts +46 -0
  48. package/components/notification/notifications.vdt +16 -0
  49. package/components/notification/styles.ts +179 -0
  50. package/components/select/styles.ts +2 -0
  51. package/components/table/.DS_Store +0 -0
  52. package/components/table/demos/hidden.md +8 -2
  53. package/components/table/demos/sort.md +4 -4
  54. package/components/table/styles.ts +6 -2
  55. package/components/tabs/useActiveBar.ts +3 -3
  56. package/components/tag/base.ts +4 -0
  57. package/components/tag/demos/border.md +1 -1
  58. package/components/tag/demos/color.md +40 -0
  59. package/components/tag/demos/draggable.md +1 -1
  60. package/components/tag/demos/tags.md +1 -1
  61. package/components/tag/index.md +1 -0
  62. package/components/tag/index.spec.ts +8 -0
  63. package/components/tag/index.vdt +6 -4
  64. package/components/tag/styles.ts +23 -0
  65. package/components/tag/useColor.ts +79 -0
  66. package/components/timepicker/index.spec.ts +16 -5
  67. package/components/timepicker/useDefaultValue.ts +16 -7
  68. package/components/timepicker/useStep.ts +3 -2
  69. package/components/tour/.DS_Store +0 -0
  70. package/components/transfer/demos/customFilter.md +1 -1
  71. package/components/transfer/demos/customList.md +1 -1
  72. package/components/transfer/demos/getData.md +1 -1
  73. package/components/transfer/demos/leftChecked.md +1 -1
  74. package/components/transfer/demos/pagination.md +63 -0
  75. package/components/transfer/demos/table.md +248 -0
  76. package/components/transfer/demos/tree.md +1 -1
  77. package/components/transfer/index.md +2 -0
  78. package/components/transfer/index.spec.ts +147 -0
  79. package/components/transfer/index.ts +7 -0
  80. package/components/transfer/index.vdt +30 -4
  81. package/components/transfer/styles.ts +11 -1
  82. package/components/transfer/useCheck.ts +5 -5
  83. package/components/transfer/usePagination.ts +92 -0
  84. package/components/virtualList/.DS_Store +0 -0
  85. package/components/virtualList/demos/.DS_Store +0 -0
  86. package/dist/fonts/iconfont.eot +0 -0
  87. package/dist/fonts/iconfont.svg +235 -0
  88. package/dist/fonts/iconfont.ttf +0 -0
  89. package/dist/fonts/iconfont.woff +0 -0
  90. package/dist/fonts/iconfont.woff2 +0 -0
  91. package/dist/fonts/ionicons.eot +0 -0
  92. package/dist/fonts/ionicons.svg +2230 -0
  93. package/dist/fonts/ionicons.ttf +0 -0
  94. package/dist/fonts/ionicons.woff +0 -0
  95. package/dist/fonts/ionicons.woff2 +0 -0
  96. package/dist/i18n/en-US.js +1411 -0
  97. package/dist/i18n/en-US.js.map +1 -0
  98. package/dist/i18n/en-US.min.js +1 -0
  99. package/dist/i18n/index.js +283 -0
  100. package/dist/i18n/index.js.map +1 -0
  101. package/dist/i18n/index.min.js +1 -0
  102. package/dist/kpc.js +50764 -0
  103. package/dist/kpc.js.map +1 -0
  104. package/dist/kpc.min.js +1 -0
  105. package/dist/kpc.react.js +58380 -0
  106. package/dist/kpc.react.js.map +1 -0
  107. package/dist/kpc.react.min.js +1 -0
  108. package/dist/kpc.tmp.js.map +1 -0
  109. package/dist/kpc.vue-legacy.js +58272 -0
  110. package/dist/kpc.vue-legacy.js.map +1 -0
  111. package/dist/kpc.vue-legacy.min.js +1 -0
  112. package/dist/kpc.vue.js +58128 -0
  113. package/dist/kpc.vue.js.map +1 -0
  114. package/dist/kpc.vue.min.js +1 -0
  115. package/es/components/anchor/constants.d.ts +2 -0
  116. package/es/components/anchor/constants.js +2 -0
  117. package/es/components/anchor/index.d.ts +41 -0
  118. package/es/components/anchor/index.js +141 -0
  119. package/es/components/anchor/index.spec.d.ts +1 -0
  120. package/es/components/anchor/index.spec.js +230 -0
  121. package/es/components/anchor/index.vdt.js +31 -0
  122. package/es/components/anchor/link.d.ts +16 -0
  123. package/es/components/anchor/link.js +52 -0
  124. package/es/components/anchor/link.vdt.js +49 -0
  125. package/es/components/anchor/styles.d.ts +5 -0
  126. package/es/components/anchor/styles.js +30 -0
  127. package/es/components/anchor/useScroll.d.ts +7 -0
  128. package/es/components/anchor/useScroll.js +218 -0
  129. package/es/components/dialog/base.vdt.js +1 -1
  130. package/es/components/drawer/index.d.ts +3 -0
  131. package/es/components/drawer/index.js +22 -3
  132. package/es/components/drawer/index.spec.js +83 -0
  133. package/es/components/drawer/index.vdt.js +23 -3
  134. package/es/components/drawer/styles.js +1 -1
  135. package/es/components/drawer/useDrawerResizable.d.ts +10 -0
  136. package/es/components/drawer/useDrawerResizable.js +162 -0
  137. package/es/components/menu/styles.d.ts +1 -0
  138. package/es/components/menu/styles.js +4 -1
  139. package/es/components/notification/index.d.ts +1 -0
  140. package/es/components/notification/index.js +1 -0
  141. package/es/components/notification/index.spec.d.ts +1 -0
  142. package/es/components/notification/index.spec.js +317 -0
  143. package/es/components/notification/notification.d.ts +39 -0
  144. package/es/components/notification/notification.js +183 -0
  145. package/es/components/notification/notification.vdt.js +56 -0
  146. package/es/components/notification/notifications.d.ts +16 -0
  147. package/es/components/notification/notifications.js +51 -0
  148. package/es/components/notification/notifications.vdt.js +24 -0
  149. package/es/components/notification/styles.d.ts +9 -0
  150. package/es/components/notification/styles.js +110 -0
  151. package/es/components/select/styles.js +1 -1
  152. package/es/components/table/styles.js +1 -1
  153. package/es/components/tabs/useActiveBar.js +7 -3
  154. package/es/components/tag/base.d.ts +2 -0
  155. package/es/components/tag/base.js +3 -0
  156. package/es/components/tag/index.spec.js +17 -0
  157. package/es/components/tag/index.vdt.js +12 -5
  158. package/es/components/tag/styles.d.ts +9 -0
  159. package/es/components/tag/styles.js +14 -1
  160. package/es/components/tag/useColor.d.ts +7 -0
  161. package/es/components/tag/useColor.js +71 -0
  162. package/es/components/timepicker/index.spec.js +70 -42
  163. package/es/components/timepicker/useDefaultValue.js +12 -7
  164. package/es/components/timepicker/useStep.js +4 -2
  165. package/es/components/transfer/index.d.ts +13 -0
  166. package/es/components/transfer/index.js +6 -2
  167. package/es/components/transfer/index.spec.js +197 -0
  168. package/es/components/transfer/index.vdt.js +28 -5
  169. package/es/components/transfer/styles.js +4 -1
  170. package/es/components/transfer/useCheck.js +2 -1
  171. package/es/components/transfer/usePagination.d.ts +12 -0
  172. package/es/components/transfer/usePagination.js +79 -0
  173. package/es/index.d.ts +4 -2
  174. package/es/index.js +4 -2
  175. package/es/site/data/components/anchor/demos/basic/index.d.ts +11 -0
  176. package/es/site/data/components/anchor/demos/basic/index.js +18 -0
  177. package/es/site/data/components/anchor/demos/basic/react.d.ts +11 -0
  178. package/es/site/data/components/anchor/demos/basic/react.js +46 -0
  179. package/es/site/data/components/anchor/demos/container/index.d.ts +12 -0
  180. package/es/site/data/components/anchor/demos/container/index.js +19 -0
  181. package/es/site/data/components/anchor/demos/container/react.d.ts +12 -0
  182. package/es/site/data/components/anchor/demos/container/react.js +52 -0
  183. package/es/site/data/components/anchor/demos/events/index.d.ts +17 -0
  184. package/es/site/data/components/anchor/demos/events/index.js +36 -0
  185. package/es/site/data/components/anchor/demos/events/react.d.ts +17 -0
  186. package/es/site/data/components/anchor/demos/events/react.js +88 -0
  187. package/es/site/data/components/anchor/demos/horizontal/index.d.ts +11 -0
  188. package/es/site/data/components/anchor/demos/horizontal/index.js +18 -0
  189. package/es/site/data/components/anchor/demos/horizontal/react.d.ts +11 -0
  190. package/es/site/data/components/anchor/demos/horizontal/react.js +46 -0
  191. package/es/site/data/components/anchor/demos/nested/index.d.ts +12 -0
  192. package/es/site/data/components/anchor/demos/nested/index.js +19 -0
  193. package/es/site/data/components/anchor/demos/nested/react.d.ts +12 -0
  194. package/es/site/data/components/anchor/demos/nested/react.js +100 -0
  195. package/es/site/data/components/anchor/index.d.ts +57 -0
  196. package/es/site/data/components/anchor/index.js +32 -0
  197. package/es/site/data/components/config/demos/basic/index.d.ts +1 -0
  198. package/es/site/data/components/config/demos/basic/index.js +8 -1
  199. package/es/site/data/components/config/demos/basic/react.d.ts +1 -0
  200. package/es/site/data/components/config/demos/basic/react.js +15 -3
  201. package/es/site/data/components/drawer/demos/resizable/index.d.ts +15 -0
  202. package/es/site/data/components/drawer/demos/resizable/index.js +26 -0
  203. package/es/site/data/components/drawer/demos/resizable/react.d.ts +15 -0
  204. package/es/site/data/components/drawer/demos/resizable/react.js +63 -0
  205. package/es/site/data/components/icon/demos/icons/index.js +1 -1
  206. package/es/site/data/components/menu/demos/collapse/index.d.ts +6 -1
  207. package/es/site/data/components/menu/demos/collapse/react.d.ts +6 -1
  208. package/es/site/data/components/menu/demos/showCollapseArrow/index.d.ts +8 -1
  209. package/es/site/data/components/menu/demos/showCollapseArrow/react.d.ts +8 -1
  210. package/es/site/data/components/menu/demos/size/index.d.ts +7 -2
  211. package/es/site/data/components/menu/demos/size/react.d.ts +7 -2
  212. package/es/site/data/components/notification/demos/basic/index.d.ts +6 -0
  213. package/es/site/data/components/notification/demos/basic/index.js +21 -0
  214. package/es/site/data/components/notification/demos/basic/react.d.ts +5 -0
  215. package/es/site/data/components/notification/demos/basic/react.js +24 -0
  216. package/es/site/data/components/notification/demos/close/index.d.ts +13 -0
  217. package/es/site/data/components/notification/demos/close/index.js +38 -0
  218. package/es/site/data/components/notification/demos/close/react.d.ts +13 -0
  219. package/es/site/data/components/notification/demos/close/react.js +52 -0
  220. package/es/site/data/components/notification/demos/duration/index.d.ts +7 -0
  221. package/es/site/data/components/notification/demos/duration/index.js +33 -0
  222. package/es/site/data/components/notification/demos/duration/react.d.ts +6 -0
  223. package/es/site/data/components/notification/demos/duration/react.js +38 -0
  224. package/es/site/data/components/notification/demos/events/index.d.ts +6 -0
  225. package/es/site/data/components/notification/demos/events/index.js +31 -0
  226. package/es/site/data/components/notification/demos/events/react.d.ts +5 -0
  227. package/es/site/data/components/notification/demos/events/react.js +34 -0
  228. package/es/site/data/components/notification/demos/hideClose/index.d.ts +6 -0
  229. package/es/site/data/components/notification/demos/hideClose/index.js +25 -0
  230. package/es/site/data/components/notification/demos/hideClose/react.d.ts +5 -0
  231. package/es/site/data/components/notification/demos/hideClose/react.js +28 -0
  232. package/es/site/data/components/notification/demos/icon/index.d.ts +7 -0
  233. package/es/site/data/components/notification/demos/icon/index.js +33 -0
  234. package/es/site/data/components/notification/demos/icon/react.d.ts +6 -0
  235. package/es/site/data/components/notification/demos/icon/react.js +42 -0
  236. package/es/site/data/components/notification/demos/position/index.d.ts +9 -0
  237. package/es/site/data/components/notification/demos/position/index.js +27 -0
  238. package/es/site/data/components/notification/demos/position/react.d.ts +8 -0
  239. package/es/site/data/components/notification/demos/position/react.js +40 -0
  240. package/es/site/data/components/notification/demos/types/index.d.ts +9 -0
  241. package/es/site/data/components/notification/demos/types/index.js +26 -0
  242. package/es/site/data/components/notification/demos/types/react.d.ts +8 -0
  243. package/es/site/data/components/notification/demos/types/react.js +39 -0
  244. package/es/site/data/components/notification/index.d.ts +57 -0
  245. package/es/site/data/components/notification/index.js +32 -0
  246. package/es/site/data/components/table/demos/hidden/react.js +21 -3
  247. package/es/site/data/components/tag/demos/color/index.d.ts +10 -0
  248. package/es/site/data/components/tag/demos/color/index.js +19 -0
  249. package/es/site/data/components/tag/demos/color/react.d.ts +10 -0
  250. package/es/site/data/components/tag/demos/color/react.js +34 -0
  251. package/es/site/data/components/transfer/demos/pagination/index.d.ts +19 -0
  252. package/es/site/data/components/transfer/demos/pagination/index.js +42 -0
  253. package/es/site/data/components/transfer/demos/pagination/react.d.ts +20 -0
  254. package/es/site/data/components/transfer/demos/pagination/react.js +65 -0
  255. package/es/site/data/components/transfer/demos/table/index.d.ts +33 -0
  256. package/es/site/data/components/transfer/demos/table/index.js +132 -0
  257. package/es/site/data/components/transfer/demos/table/react.d.ts +35 -0
  258. package/es/site/data/components/transfer/demos/table/react.js +246 -0
  259. package/es/site/src/router/index.js +4 -33
  260. package/es/styles/fonts/iconfont.eot +0 -0
  261. package/es/styles/fonts/iconfont.js +1 -1
  262. package/es/styles/fonts/iconfont.svg +38 -0
  263. package/es/styles/fonts/iconfont.ttf +0 -0
  264. package/es/styles/fonts/iconfont.woff +0 -0
  265. package/es/styles/fonts/iconfont.woff2 +0 -0
  266. package/es/styles/theme.d.ts +8 -0
  267. package/es/styles/theme.js +5 -1
  268. package/index.ts +4 -2
  269. package/package.json +2 -2
  270. package/styles/.DS_Store +0 -0
  271. package/styles/fonts/demo_index.html +443 -6
  272. package/styles/fonts/iconfont.css +82 -6
  273. package/styles/fonts/iconfont.eot +0 -0
  274. package/styles/fonts/iconfont.js +1 -1
  275. package/styles/fonts/iconfont.json +133 -0
  276. package/styles/fonts/iconfont.svg +38 -0
  277. package/styles/fonts/iconfont.ts +76 -0
  278. package/styles/fonts/iconfont.ttf +0 -0
  279. package/styles/fonts/iconfont.woff +0 -0
  280. package/styles/fonts/iconfont.woff2 +0 -0
  281. package/styles/theme.ts +4 -0
@@ -0,0 +1,159 @@
1
+ import {Component, TypeDefs, provide, Children} from 'intact';
2
+ import template from './index.vdt';
3
+ import {ANCHOR} from './constants';
4
+ import {Sizes, sizes} from '../../styles/utils';
5
+ import {useScroll} from './useScroll';
6
+ import type {Events} from '../types';
7
+ import { useConfigContext } from '../config';
8
+ import {AnchorLink} from './link';
9
+ import {eachChildren, isComponentVNode} from '../utils';
10
+ import type { AnchorLinkProps } from './link';
11
+
12
+ export * from './link';
13
+
14
+ export interface AnchorProps {
15
+ value?: string;
16
+ offset?: number;
17
+ container?: string | HTMLElement;
18
+ threshold?: number;
19
+ vertical?: boolean;
20
+ size?: Sizes;
21
+ duration?: number;
22
+ }
23
+
24
+ export interface AnchorEvents {
25
+ change: [string];
26
+ click: [MouseEvent, AnchorLinkProps];
27
+ }
28
+
29
+ const typeDefs: Required<TypeDefs<AnchorProps>> = {
30
+ value: String,
31
+ offset: Number,
32
+ container: [String, Object],
33
+ threshold: Number,
34
+ vertical: Boolean,
35
+ size: sizes,
36
+ duration: Number,
37
+ };
38
+
39
+ const defaults = (): Partial<AnchorProps> => ({
40
+ offset: 0,
41
+ threshold: 50,
42
+ vertical: true,
43
+ size: 'default',
44
+ duration: 700,
45
+ });
46
+
47
+ const events: Events<AnchorEvents> = {
48
+ change: true,
49
+ click: true,
50
+ };
51
+
52
+ export class Anchor extends Component<AnchorProps, AnchorEvents> {
53
+ static template = template;
54
+ static typeDefs = typeDefs;
55
+ static defaults = defaults;
56
+ static events = events;
57
+
58
+ private scroll = useScroll();
59
+ public config = useConfigContext();
60
+ private links: string[] = [];
61
+ private cleanup?: () => void;
62
+ // 标记是否是滚动触发的 value 变化
63
+ private isSettingFromScroll = false;
64
+ // 元素引用缓存,避免重复的 getElementById 调用
65
+ private elementCache = new Map<string, HTMLElement | null>();
66
+
67
+ init() {
68
+ provide(ANCHOR, this);
69
+
70
+ this.scroll.setIsSettingFromScroll = (value: boolean) => {
71
+ this.isSettingFromScroll = value;
72
+ };
73
+
74
+ this.watch('value', (newValue, oldValue) => {
75
+ if (newValue !== oldValue && newValue !== undefined && newValue !== null) {
76
+ this.trigger('change', newValue as string);
77
+ // 只有非滚动触发的 value 变化才 scrollTo
78
+ // 即:用户点击 tab 或外部 set 时才会 scrollTo
79
+ if (!this.isSettingFromScroll) {
80
+ const element = this.getTargetElement(newValue);
81
+ // 元素存在且可见
82
+ if (element && element.getClientRects().length > 0) {
83
+ this.scroll.scrollTo(element);
84
+ }
85
+ }
86
+ }
87
+ }, {inited: true});
88
+ }
89
+
90
+ mounted() {
91
+ this.updateLinks();
92
+ this.cleanup = this.scroll.init();
93
+ }
94
+
95
+ beforeUnmount() {
96
+ if (this.cleanup) {
97
+ this.cleanup();
98
+ }
99
+ // 清理元素缓存
100
+ this.elementCache.clear();
101
+ }
102
+
103
+ updated() {
104
+ this.updateLinks();
105
+ }
106
+
107
+ private updateLinks() {
108
+ const links: string[] = [];
109
+ const children = this.get('children') as Children;
110
+
111
+ // 递归收集所有层级的 AnchorLink 的 href
112
+ const collectLinks = (children: Children) => {
113
+ if (!children) return;
114
+
115
+ eachChildren(children, (vNode) => {
116
+ if (isComponentVNode(vNode, AnchorLink)) {
117
+ const props = vNode.props || {};
118
+ if (props.href) {
119
+ links.push(props.href);
120
+ }
121
+ if (vNode.props && vNode.props.children) {
122
+ collectLinks(vNode.props.children);
123
+ }
124
+ }
125
+ });
126
+ };
127
+
128
+ collectLinks(children);
129
+ this.links = links;
130
+
131
+ // 清理不在当前链接列表中的缓存
132
+ this.elementCache.forEach((_, href) => {
133
+ if (!links.includes(href)) {
134
+ this.elementCache.delete(href);
135
+ }
136
+ });
137
+ }
138
+
139
+ public getLinks(): string[] {
140
+ return this.links;
141
+ }
142
+
143
+ public getTargetElement(href: string): HTMLElement | null {
144
+ if (!href) return null;
145
+
146
+ if (this.elementCache.has(href)) {
147
+ return this.elementCache.get(href)!;
148
+ }
149
+
150
+ const id = href.startsWith('#') ? href.slice(1) : href;
151
+ const element = document.getElementById(id);
152
+
153
+ this.elementCache.set(href, element);
154
+
155
+ return element;
156
+ }
157
+
158
+ }
159
+
@@ -0,0 +1,24 @@
1
+ import {Tabs} from '../tabs';
2
+ import {getRestProps} from '../utils';
3
+ import {makeStyles} from './styles';
4
+
5
+ const {className, children, vertical, size, value} = this.get();
6
+ const { k } = this.config;
7
+
8
+ const classNameObj = {
9
+ [`${k}-anchor`]: true,
10
+ [className]: className,
11
+ [`${k}-anchor-vertical`]: vertical,
12
+ [makeStyles(k, vertical)]: true,
13
+ };
14
+
15
+ <div class={classNameObj} {...getRestProps(this)}>
16
+ <Tabs
17
+ v-model="value"
18
+ vertical={vertical}
19
+ size={size}
20
+ >
21
+ {children}
22
+ </Tabs>
23
+ </div>
24
+
@@ -0,0 +1,44 @@
1
+ import {Component, TypeDefs, inject, provide, VNode} from 'intact';
2
+ import template from './link.vdt';
3
+ import {ANCHOR, ANCHOR_LINK_LEVEL} from './constants';
4
+ import type {Anchor} from './';
5
+ import {bind} from '../utils';
6
+ import { useConfigContext } from '../config';
7
+
8
+ export interface AnchorLinkProps {
9
+ href?: string;
10
+ title?: string | VNode;
11
+ disabled?: boolean;
12
+ }
13
+
14
+ const typeDefs: Required<TypeDefs<AnchorLinkProps>> = {
15
+ href: String,
16
+ title: [String, VNode],
17
+ disabled: Boolean,
18
+ };
19
+
20
+ export class AnchorLink extends Component<AnchorLinkProps> {
21
+ static template = template;
22
+ static typeDefs = typeDefs;
23
+
24
+ private anchor = inject<Anchor>(ANCHOR)!;
25
+ private config = useConfigContext();
26
+ private level = inject<number>(ANCHOR_LINK_LEVEL, 0);
27
+
28
+ init() {
29
+ provide(ANCHOR_LINK_LEVEL, this.level + 1);
30
+ }
31
+
32
+ @bind
33
+ private onClick(e: MouseEvent) {
34
+ const { title, href, disabled } = this.get();
35
+ if (href) {
36
+ this.anchor.trigger('click', e, { title, href, disabled });
37
+ }
38
+ }
39
+
40
+ public getLevel(): number {
41
+ return this.level;
42
+ }
43
+ }
44
+
@@ -0,0 +1,49 @@
1
+ import {Tab} from '../tabs';
2
+ import {getRestProps, eachChildren, isComponentVNode} from '../utils';
3
+ import {isNullOrUndefined} from 'intact-shared';
4
+ import {AnchorLink} from './link';
5
+
6
+ const {href, title, children, className, disabled} = this.get();
7
+ const {value: currentValue, vertical} = this.anchor.get();
8
+ const { k } = this.config;
9
+ const level = this.level;
10
+ const verticalMode = vertical !== false; // 默认为 true
11
+
12
+ // 检查是否有嵌套的 AnchorLink 仅在 vertical 模式下支持嵌套
13
+ const nestedLinks = [];
14
+ const otherChildren = [];
15
+
16
+ if (children) {
17
+ eachChildren(children, (vNode) => {
18
+ if (isComponentVNode(vNode, AnchorLink)) {
19
+ nestedLinks.push(vNode);
20
+ } else {
21
+ otherChildren.push(vNode);
22
+ }
23
+ });
24
+ }
25
+
26
+ const hasNestedLinks = nestedLinks.length > 0 && verticalMode;
27
+ // 如果有嵌套的 AnchorLink,显示 title;否则显示 title 或 children
28
+ const displayTitle = title || (hasNestedLinks ? null : (otherChildren.length > 0 ? otherChildren : null));
29
+
30
+ const classNameObj = {
31
+ [`${k}-anchor-link`]: true,
32
+ [`${k}-anchor-link-nested`]: hasNestedLinks,
33
+ [`${k}-anchor-link-level-${level}`]: level > 0 && verticalMode,
34
+ [className]: className,
35
+ };
36
+
37
+ <template>
38
+ <Tab
39
+ {...getRestProps(this)}
40
+ class={classNameObj}
41
+ value={href}
42
+ disabled={disabled}
43
+ ev-click={this.onClick}
44
+ >
45
+ {displayTitle}
46
+ </Tab>
47
+ {hasNestedLinks ? nestedLinks : null}
48
+ </template>
49
+
@@ -0,0 +1,50 @@
1
+ import {css} from '@emotion/css';
2
+ import {theme, setDefault} from '../../styles/theme';
3
+ import {deepDefaults} from '../../styles/utils';
4
+ import '../../styles/global';
5
+ import { cache } from '../utils';
6
+
7
+ const defaults = {
8
+ get transition() { return theme.transition.middle },
9
+ link: {
10
+ padding: 16,
11
+ },
12
+ };
13
+
14
+ let anchor: typeof defaults;
15
+ setDefault(() => {
16
+ anchor = deepDefaults(theme, {anchor: defaults}).anchor;
17
+ makeStyles?.clearCache();
18
+ });
19
+
20
+ export const makeStyles = cache(function makeStyles(k: string, vertical?: boolean) {
21
+ return css`
22
+ &.${k}-anchor-vertical {
23
+ .${k}-tabs.${k}-vertical {
24
+ border-right: none;
25
+ border-left: 1px solid ${theme.color.border};
26
+ .${k}-tabs-active-bar {
27
+ left: 0;
28
+ right: auto;
29
+ }
30
+ }
31
+ }
32
+ .${k}-anchor-link {
33
+ &.${k}-tab {
34
+ transition: color ${anchor.transition};
35
+ text-align: ${vertical ? 'left' : 'center'};
36
+ }
37
+
38
+ ${Array.from({ length: 10 }, (_, i) => {
39
+ const level = i + 1;
40
+ const paddingLeft = anchor.link.padding + anchor.link.padding * level;
41
+ return css`
42
+ &.${k}-anchor-link-level-${level}.${k}-tab {
43
+ padding-left: ${paddingLeft}px;
44
+ }
45
+ `;
46
+ })}
47
+ }
48
+ `;
49
+ });
50
+
@@ -0,0 +1,221 @@
1
+ import {useInstance, nextTick} from 'intact';
2
+ import {useState} from '../../hooks/useState';
3
+ import type {Anchor} from './';
4
+
5
+ export function useScroll() {
6
+ const instance = useInstance() as Anchor;
7
+ const isScrolling = useState(false);
8
+
9
+ let scrollTimer: number | null = null;
10
+ let rafId: number | null = null;
11
+ let scrollContainer: HTMLElement | Window = window;
12
+ // 回调函数,用于通知外部这是滚动触发的 value 变化
13
+ let setIsSettingFromScroll: ((value: boolean) => void) | null = null;
14
+
15
+ function getScrollContainer() {
16
+ const {container} = instance.get();
17
+ if (!container) {
18
+ return window;
19
+ }
20
+ if (typeof container === 'string') {
21
+ const el = document.querySelector(container) as HTMLElement;
22
+ return el || window;
23
+ }
24
+ return container;
25
+ }
26
+
27
+ // 获取当前滚动距离
28
+ function getScrollTop(): number {
29
+ if (scrollContainer === window) {
30
+ return window.scrollY || document.documentElement.scrollTop;
31
+ }
32
+ return (scrollContainer as HTMLElement).scrollTop;
33
+ }
34
+
35
+ // 获取滚动容器的高度
36
+ function getScrollHeight(): number {
37
+ if (scrollContainer === window) {
38
+ return document.documentElement.scrollHeight;
39
+ }
40
+ return (scrollContainer as HTMLElement).scrollHeight;
41
+ }
42
+
43
+ // 获取视口高度
44
+ function getViewportHeight(): number {
45
+ if (scrollContainer === window) {
46
+ return window.innerHeight;
47
+ }
48
+ return (scrollContainer as HTMLElement).clientHeight;
49
+ }
50
+
51
+ function getElementTop(element: HTMLElement, container: HTMLElement | Window): number {
52
+ if (container === window) {
53
+ // window: 累加 offsetTop
54
+ let offsetTop = 0;
55
+ let currentElement: HTMLElement | null = element;
56
+ while (currentElement && currentElement !== document.body) {
57
+ offsetTop += currentElement.offsetTop;
58
+ currentElement = currentElement.offsetParent as HTMLElement | null;
59
+ }
60
+ return offsetTop;
61
+ }
62
+
63
+ // 自定义容器: 使用 getBoundingClientRect
64
+ const containerEl = container as HTMLElement;
65
+ const elementRect = element.getBoundingClientRect();
66
+ const containerRect = containerEl.getBoundingClientRect();
67
+
68
+ // 元素相对于容器内容区的位置 =
69
+ // (元素到视口顶部的距离 - 容器到视口顶部的距离) + 容器已滚动的距离
70
+ return elementRect.top - containerRect.top + containerEl.scrollTop;
71
+ }
72
+
73
+ function scrollTo(target: HTMLElement) {
74
+ const {offset = 0, duration = 700} = instance.get();
75
+
76
+ // 目标位置
77
+ const targetTop = getElementTop(target, scrollContainer) - offset;
78
+ // 当前位置
79
+ const currentTop = getScrollTop();
80
+ if (Math.abs(currentTop - targetTop) < 1) return;
81
+
82
+ if (scrollTimer) {
83
+ clearTimeout(scrollTimer);
84
+ }
85
+ isScrolling.set(true);
86
+
87
+ if (scrollContainer === window) {
88
+ window.scrollTo({
89
+ top: targetTop,
90
+ behavior: 'smooth'
91
+ });
92
+ } else {
93
+ (scrollContainer as HTMLElement).scrollTo({
94
+ top: targetTop,
95
+ behavior: 'smooth'
96
+ });
97
+ }
98
+
99
+ scrollTimer = window.setTimeout(() => {
100
+ isScrolling.set(false);
101
+ }, duration);
102
+ }
103
+
104
+ // 滚动触发的 value 更新
105
+ function setValueFromScroll(href: string) {
106
+ if (setIsSettingFromScroll) {
107
+ setIsSettingFromScroll(true);
108
+ }
109
+ try {
110
+ instance.set('value', href);
111
+ } finally {
112
+ if (setIsSettingFromScroll) {
113
+ setIsSettingFromScroll(false);
114
+ }
115
+ }
116
+ }
117
+
118
+ // 更新当前激活的锚点
119
+ function updateActive() {
120
+ if (isScrolling.value) return;
121
+
122
+ const {offset = 0, threshold = 50} = instance.get();
123
+ const links = instance.getLinks();
124
+
125
+ // 只处理当前存在且可见的锚点
126
+ const candidates = [];
127
+ for (const href of links) {
128
+ const element = instance.getTargetElement(href);
129
+ if (element && element.getClientRects().length > 0) {
130
+ candidates.push({ href, element });
131
+ }
132
+ }
133
+
134
+ if (candidates.length === 0) return;
135
+
136
+ const scrollTop = getScrollTop();
137
+ const viewportHeight = getViewportHeight();
138
+ const totalHeight = getScrollHeight();
139
+
140
+ let activeHref: string = candidates[0].href;
141
+
142
+ if (scrollTop + viewportHeight >= totalHeight - 10) {
143
+ // 接近底部,激活最后一个可见锚点
144
+ activeHref = candidates[candidates.length - 1].href;
145
+ } else if (scrollTop <= threshold) {
146
+ // 接近顶部,激活第一个可见锚点
147
+ activeHref = candidates[0].href;
148
+ } else {
149
+ // 正常滚动,寻找最后一个被“滚到”的锚点
150
+ for (const { href, element } of candidates) {
151
+ const sectionTop = getElementTop(element, scrollContainer) - offset - threshold;
152
+ if (scrollTop >= sectionTop) {
153
+ activeHref = href;
154
+ } else {
155
+ break;
156
+ }
157
+ }
158
+ }
159
+
160
+ if (activeHref !== instance.get('value')) {
161
+ setValueFromScroll(activeHref);
162
+ }
163
+ }
164
+
165
+ // 滚动事件处理
166
+ function onScroll() {
167
+ if (isScrolling.value) return;
168
+
169
+ if (rafId) {
170
+ cancelAnimationFrame(rafId);
171
+ }
172
+ // 使用 requestAnimationFrame 优化滚动性能
173
+ rafId = requestAnimationFrame(updateActive);
174
+ }
175
+
176
+ // 挂载后的初始化
177
+ function init() {
178
+ setTimeout(() => {
179
+ scrollContainer = getScrollContainer();
180
+
181
+ if (scrollContainer === window) {
182
+ window.addEventListener('scroll', onScroll, {passive: true});
183
+ } else {
184
+ (scrollContainer as HTMLElement).addEventListener('scroll', onScroll, {passive: true});
185
+ }
186
+ const initialValue = instance.get('value');
187
+ if (initialValue) {
188
+ const element = instance.getTargetElement(initialValue);
189
+ if (element) {
190
+ scrollTo(element);
191
+ return;
192
+ }
193
+ }
194
+ }, 100);
195
+
196
+ return () => {
197
+ if (scrollTimer) {
198
+ clearTimeout(scrollTimer);
199
+ }
200
+ if (rafId) {
201
+ cancelAnimationFrame(rafId);
202
+ }
203
+ const currentContainer = scrollContainer;
204
+ if (currentContainer === window) {
205
+ window.removeEventListener('scroll', onScroll);
206
+ } else {
207
+ (currentContainer as HTMLElement).removeEventListener('scroll', onScroll);
208
+ }
209
+ };
210
+ }
211
+
212
+ return {
213
+ scrollTo,
214
+ updateActive,
215
+ init,
216
+ isScrolling,
217
+ set setIsSettingFromScroll(fn: (value: boolean) => void) {
218
+ setIsSettingFromScroll = fn;
219
+ },
220
+ };
221
+ }
@@ -7,13 +7,14 @@ order: 0
7
7
 
8
8
  > 本例中,我们将前缀设为`kd`,可以打开调试工具查看
9
9
 
10
- > 对于`Message`组件,由于它是静态方法调用,我们可以通过`Message.classNamePrefix`设置样式名前缀
10
+ > 对于`Message` 和 `Notification` 组件,由于它是静态方法调用,我们可以通过`Message.classNamePrefix` 、 `Notification.classNamePrefix` 设置样式名前缀
11
11
 
12
12
  ```vdt
13
13
  import {ConfigProvider, Button, Input} from 'kpc';
14
14
 
15
15
  <ConfigProvider value={{classNamePrefix: 'kd'}}>
16
- <Button ev-click={this.showMessage}>Button</Button>
16
+ <Button ev-click={this.showMessage} style="margin-right: 16px;">Show Message</Button>
17
+ <Button ev-click={this.showNotification}>Show Notification</Button>
17
18
  <div style="margin-top: 8px;">
18
19
  <Input />
19
20
  </div>
@@ -21,7 +22,7 @@ import {ConfigProvider, Button, Input} from 'kpc';
21
22
  ```
22
23
 
23
24
  ```ts
24
- import {Message} from 'kpc';
25
+ import {Message, Notification} from 'kpc';
25
26
 
26
27
  export default class extends Component {
27
28
  static template = template;
@@ -30,5 +31,12 @@ export default class extends Component {
30
31
  Message.classNamePrefix = 'kd';
31
32
  Message.info('Message with classNamePrefix');
32
33
  }
34
+ showNotification() {
35
+ Notification.classNamePrefix = 'kd';
36
+ Notification.info({
37
+ title: 'Notification',
38
+ content: 'Notification with classNamePrefix'
39
+ });
40
+ }
33
41
  }
34
42
  ```
@@ -8,12 +8,14 @@ import {makeDialogStyles, makeWrapperStyles} from './styles';
8
8
 
9
9
  const {
10
10
  size, container, hideClose,
11
- overlay, value, width,
11
+ overlay, value,
12
12
  mode, className, cancelText,
13
13
  okText, loading, disabledOk,
14
14
  title, children,
15
15
  } = this.get();
16
16
 
17
+ const width = $props.width !== undefined ? $props.width : this.get('width');
18
+
17
19
  const isHide = mode === 'hide';
18
20
  const { k } = this.config;
19
21
  const classNameObj = {
@@ -0,0 +1,67 @@
1
+ ---
2
+ title: 可调整大小
3
+ order: 0.3
4
+ ---
5
+
6
+ 添加`resizable`属性,可以通过拖拽边缘来调整 drawer 的大小。
7
+
8
+ ```vdt
9
+ import {Drawer, Button, ButtonGroup} from 'kpc';
10
+
11
+ <div>
12
+ <ButtonGroup checkType="radio" v-model="placement">
13
+ <Button value="top">top</Button>
14
+ <Button value="bottom">bottom</Button>
15
+ <Button value="left">left</Button>
16
+ <Button value="right">right</Button>
17
+ </ButtonGroup>
18
+ <br /><br />
19
+ <Button ev-click={this.showDrawer}>打开 Drawer</Button>
20
+
21
+ <Drawer v-model='show'
22
+ title='可调整大小的 Drawer'
23
+ placement={this.get('placement')}
24
+ resizable={true}
25
+ >
26
+ <div>
27
+ <p>可以通过拖拽边缘来调整 drawer 的大小:</p>
28
+ <ul>
29
+ <li><strong>top/bottom</strong>:
30
+ <ul>
31
+ <li>宽度:可以通过拖拽右侧边缘来调整宽度,调整时会自动保持居中</li>
32
+ <li>高度:可以通过拖拽底部(top)或顶部(bottom)边缘来调整高度</li>
33
+ </ul>
34
+ </li>
35
+ <li><strong>left</strong>:可以通过拖拽右侧边缘来调整宽度</li>
36
+ <li><strong>right</strong>:可以通过拖拽左侧边缘来调整宽度</li>
37
+ </ul>
38
+ <p>当前 placement: {this.get('placement')}</p>
39
+ </div>
40
+ </Drawer>
41
+ </div>
42
+ ```
43
+
44
+ ```ts
45
+ import {bind, DrawerProps} from 'kpc';
46
+
47
+ interface Props {
48
+ show?: boolean
49
+ placement: DrawerProps['placement']
50
+ }
51
+
52
+ export default class extends Component<Props> {
53
+ static template = template;
54
+
55
+ static defaults() {
56
+ return {
57
+ show: false,
58
+ placement: 'right' as Props['placement'],
59
+ };
60
+ }
61
+
62
+ @bind
63
+ showDrawer() {
64
+ this.set('show', true);
65
+ }
66
+ }
67
+ ```
@@ -27,6 +27,7 @@ sidebar: doc
27
27
  | width | 指定弹窗宽度,`number`类型时,单位为`px`;`string`类型时,需要指定单位 | `number` &#124; `string` | `undefined` |
28
28
  | mode | 指定主体元素在关闭状态下的渲染方式,`"destroy"`代表直接销毁,`"hide"`代表只是隐藏 | `"destroy"` &#124; `"hide"` | `"hide"` |
29
29
  | placement | 自定义位置 | `"top"` &#124; `"bottom"` &#124;`"left"` &#124;`"right"`|`"right"`|
30
+ | resizable | 是否可调整大小。 | `boolean` | `false` |
30
31
 
31
32
  # 扩展点
32
33