resolver-egretimp-plus 0.1.30 → 0.1.32

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 (50) hide show
  1. package/dist/h5/index.js +18 -18
  2. package/dist/theme/element/index.css +1 -1
  3. package/dist/theme/element/src/components/form.scss +2 -0
  4. package/dist/web/index.js +128 -128
  5. package/dist/web/index.js.LICENSE.txt +15 -0
  6. package/package.json +5 -1
  7. package/scripts/webpack.config.js +18 -2
  8. package/src/components/packages-web/CustomComponentTable.jsx +8 -5
  9. package/src/components/table/index.ts +29 -0
  10. package/src/components/table/src/composables/use-scrollbar.ts +30 -0
  11. package/src/components/table/src/config.ts +256 -0
  12. package/src/components/table/src/filter-panel.vue +260 -0
  13. package/src/components/table/src/h-helper.ts +34 -0
  14. package/src/components/table/src/layout-observer.ts +78 -0
  15. package/src/components/table/src/store/current.ts +85 -0
  16. package/src/components/table/src/store/expand.ts +76 -0
  17. package/src/components/table/src/store/helper.ts +74 -0
  18. package/src/components/table/src/store/index.ts +246 -0
  19. package/src/components/table/src/store/tree.ts +230 -0
  20. package/src/components/table/src/store/watcher.ts +543 -0
  21. package/src/components/table/src/table/defaults.ts +402 -0
  22. package/src/components/table/src/table/key-render-helper.ts +27 -0
  23. package/src/components/table/src/table/style-helper.ts +378 -0
  24. package/src/components/table/src/table/utils-helper.ts +47 -0
  25. package/src/components/table/src/table-body/defaults.ts +52 -0
  26. package/src/components/table/src/table-body/events-helper.ts +203 -0
  27. package/src/components/table/src/table-body/index.ts +119 -0
  28. package/src/components/table/src/table-body/render-helper.ts +283 -0
  29. package/src/components/table/src/table-body/styles-helper.ts +164 -0
  30. package/src/components/table/src/table-column/defaults.ts +237 -0
  31. package/src/components/table/src/table-column/index.ts +202 -0
  32. package/src/components/table/src/table-column/render-helper.ts +214 -0
  33. package/src/components/table/src/table-column/watcher-helper.ts +88 -0
  34. package/src/components/table/src/table-footer/index.ts +128 -0
  35. package/src/components/table/src/table-footer/mapState-helper.ts +33 -0
  36. package/src/components/table/src/table-footer/style-helper.ts +51 -0
  37. package/src/components/table/src/table-header/event-helper.ts +213 -0
  38. package/src/components/table/src/table-header/index.ts +244 -0
  39. package/src/components/table/src/table-header/style.helper.ts +119 -0
  40. package/src/components/table/src/table-header/utils-helper.ts +94 -0
  41. package/src/components/table/src/table-layout.ts +259 -0
  42. package/src/components/table/src/table.vue +389 -0
  43. package/src/components/table/src/tableColumn.ts +3 -0
  44. package/src/components/table/src/tokens.ts +5 -0
  45. package/src/components/table/src/util.ts +521 -0
  46. package/src/components/table/style/css.ts +5 -0
  47. package/src/components/table/style/index.ts +5 -0
  48. package/src/theme/element/components/form.scss +2 -0
  49. package/tsconfig.json +19 -0
  50. package/vue-shims.d.ts +4 -0
@@ -0,0 +1,230 @@
1
+ // @ts-nocheck
2
+ import { computed, getCurrentInstance, ref, unref, watch } from 'vue'
3
+ import { getRowIdentity, walkTreeNode } from '../util'
4
+
5
+ import type { WatcherPropsData } from '.'
6
+ import type { Table, TableProps } from '../table/defaults'
7
+
8
+ function useTree<T>(watcherData: WatcherPropsData<T>) {
9
+ const expandRowKeys = ref<string[]>([])
10
+ const treeData = ref<unknown>({})
11
+ const indent = ref(16)
12
+ const lazy = ref(false)
13
+ const lazyTreeNodeMap = ref({})
14
+ const lazyColumnIdentifier = ref('hasChildren')
15
+ const childrenColumnName = ref('children')
16
+ const instance = getCurrentInstance() as Table<T>
17
+ const normalizedData = computed(() => {
18
+ if (!watcherData.rowKey.value) return {}
19
+ const data = watcherData.data.value || []
20
+ return normalize(data)
21
+ })
22
+ const normalizedLazyNode = computed(() => {
23
+ const rowKey = watcherData.rowKey.value
24
+ const keys = Object.keys(lazyTreeNodeMap.value)
25
+ const res = {}
26
+ if (!keys.length) return res
27
+ keys.forEach((key) => {
28
+ if (lazyTreeNodeMap.value[key].length) {
29
+ const item = { children: [] }
30
+ lazyTreeNodeMap.value[key].forEach((row) => {
31
+ const currentRowKey = getRowIdentity(row, rowKey)
32
+ item.children.push(currentRowKey)
33
+ if (row[lazyColumnIdentifier.value] && !res[currentRowKey]) {
34
+ res[currentRowKey] = { children: [] }
35
+ }
36
+ })
37
+ res[key] = item
38
+ }
39
+ })
40
+ return res
41
+ })
42
+
43
+ const normalize = (data) => {
44
+ const rowKey = watcherData.rowKey.value
45
+ const res = {}
46
+ walkTreeNode(
47
+ data,
48
+ (parent, children, level) => {
49
+ const parentId = getRowIdentity(parent, rowKey)
50
+ if (Array.isArray(children)) {
51
+ res[parentId] = {
52
+ children: children.map((row) => getRowIdentity(row, rowKey)),
53
+ level,
54
+ }
55
+ } else if (lazy.value) {
56
+ // 当 children 不存在且 lazy 为 true,该节点即为懒加载的节点
57
+ res[parentId] = {
58
+ children: [],
59
+ lazy: true,
60
+ level,
61
+ }
62
+ }
63
+ },
64
+ childrenColumnName.value,
65
+ lazyColumnIdentifier.value
66
+ )
67
+ return res
68
+ }
69
+
70
+ const updateTreeData = (
71
+ ifChangeExpandRowKeys = false,
72
+ ifExpandAll = instance.store?.states.defaultExpandAll.value
73
+ ) => {
74
+ const nested = normalizedData.value
75
+ const normalizedLazyNode_ = normalizedLazyNode.value
76
+ const keys = Object.keys(nested)
77
+ const newTreeData = {}
78
+ if (keys.length) {
79
+ const oldTreeData = unref(treeData)
80
+ const rootLazyRowKeys = []
81
+ const getExpanded = (oldValue, key) => {
82
+ if (ifChangeExpandRowKeys) {
83
+ if (expandRowKeys.value) {
84
+ return ifExpandAll || expandRowKeys.value.includes(key)
85
+ } else {
86
+ return !!(ifExpandAll || oldValue?.expanded)
87
+ }
88
+ } else {
89
+ const included =
90
+ ifExpandAll ||
91
+ (expandRowKeys.value && expandRowKeys.value.includes(key))
92
+ return !!(oldValue?.expanded || included)
93
+ }
94
+ }
95
+ // 合并 expanded 与 display,确保数据刷新后,状态不变
96
+ keys.forEach((key) => {
97
+ const oldValue = oldTreeData[key]
98
+ const newValue = { ...nested[key] }
99
+ newValue.expanded = getExpanded(oldValue, key)
100
+ if (newValue.lazy) {
101
+ const { loaded = false, loading = false } = oldValue || {}
102
+ newValue.loaded = !!loaded
103
+ newValue.loading = !!loading
104
+ rootLazyRowKeys.push(key)
105
+ }
106
+ newTreeData[key] = newValue
107
+ })
108
+ // 根据懒加载数据更新 treeData
109
+ const lazyKeys = Object.keys(normalizedLazyNode_)
110
+ if (lazy.value && lazyKeys.length && rootLazyRowKeys.length) {
111
+ lazyKeys.forEach((key) => {
112
+ const oldValue = oldTreeData[key]
113
+ const lazyNodeChildren = normalizedLazyNode_[key].children
114
+ if (rootLazyRowKeys.includes(key)) {
115
+ // 懒加载的 root 节点,更新一下原有的数据,原来的 children 一定是空数组
116
+ if (newTreeData[key].children.length !== 0) {
117
+ throw new Error('[ElTable]children must be an empty array.')
118
+ }
119
+ newTreeData[key].children = lazyNodeChildren
120
+ } else {
121
+ const { loaded = false, loading = false } = oldValue || {}
122
+ newTreeData[key] = {
123
+ lazy: true,
124
+ loaded: !!loaded,
125
+ loading: !!loading,
126
+ expanded: getExpanded(oldValue, key),
127
+ children: lazyNodeChildren,
128
+ level: '',
129
+ }
130
+ }
131
+ })
132
+ }
133
+ }
134
+ treeData.value = newTreeData
135
+ instance.store?.updateTableScrollY()
136
+ }
137
+
138
+ watch(
139
+ () => expandRowKeys.value,
140
+ () => {
141
+ updateTreeData(true)
142
+ }
143
+ )
144
+
145
+ watch(
146
+ () => normalizedData.value,
147
+ () => {
148
+ updateTreeData()
149
+ }
150
+ )
151
+ watch(
152
+ () => normalizedLazyNode.value,
153
+ () => {
154
+ updateTreeData()
155
+ }
156
+ )
157
+
158
+ const updateTreeExpandKeys = (value: string[]) => {
159
+ expandRowKeys.value = value
160
+ updateTreeData()
161
+ }
162
+
163
+ const toggleTreeExpansion = (row: T, expanded?: boolean) => {
164
+ instance.store.assertRowKey()
165
+
166
+ const rowKey = watcherData.rowKey.value
167
+ const id = getRowIdentity(row, rowKey)
168
+ const data = id && treeData.value[id]
169
+ if (id && data && 'expanded' in data) {
170
+ const oldExpanded = data.expanded
171
+ expanded = typeof expanded === 'undefined' ? !data.expanded : expanded
172
+ treeData.value[id].expanded = expanded
173
+ if (oldExpanded !== expanded) {
174
+ instance.emit('expand-change', row, expanded)
175
+ }
176
+ instance.store.updateTableScrollY()
177
+ }
178
+ }
179
+
180
+ const loadOrToggle = (row) => {
181
+ instance.store.assertRowKey()
182
+ const rowKey = watcherData.rowKey.value
183
+ const id = getRowIdentity(row, rowKey)
184
+ const data = treeData.value[id]
185
+ if (lazy.value && data && 'loaded' in data && !data.loaded) {
186
+ loadData(row, id, data)
187
+ } else {
188
+ toggleTreeExpansion(row, undefined)
189
+ }
190
+ }
191
+
192
+ const loadData = (row: T, key: string, treeNode) => {
193
+ const { load } = instance.props as unknown as TableProps<T>
194
+ if (load && !treeData.value[key].loaded) {
195
+ treeData.value[key].loading = true
196
+ load(row, treeNode, (data) => {
197
+ if (!Array.isArray(data)) {
198
+ throw new TypeError('[ElTable] data must be an array')
199
+ }
200
+ treeData.value[key].loading = false
201
+ treeData.value[key].loaded = true
202
+ treeData.value[key].expanded = true
203
+ if (data.length) {
204
+ lazyTreeNodeMap.value[key] = data
205
+ }
206
+ instance.emit('expand-change', row, true)
207
+ })
208
+ }
209
+ }
210
+
211
+ return {
212
+ loadData,
213
+ loadOrToggle,
214
+ toggleTreeExpansion,
215
+ updateTreeExpandKeys,
216
+ updateTreeData,
217
+ normalize,
218
+ states: {
219
+ expandRowKeys,
220
+ treeData,
221
+ indent,
222
+ lazy,
223
+ lazyTreeNodeMap,
224
+ lazyColumnIdentifier,
225
+ childrenColumnName,
226
+ },
227
+ }
228
+ }
229
+
230
+ export default useTree