@vxe-ui/plugin-render-element 4.3.1 → 4.4.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.
package/src/index.ts CHANGED
@@ -1,124 +1,124 @@
1
- import { defineTableRender } from './table'
2
- import { defineFormRender } from './form'
3
- import { defineFormDesignRender } from './form-design'
4
- import { globalConfig, componentMaps } from './store'
5
- import XEUtils from 'xe-utils'
6
-
7
- import type { VxeUIPluginRenderElementOptions } from '../types'
8
- import type { VxeUIPluginObject, VxeGlobalInterceptorHandles } from 'vxe-pc-ui'
9
-
10
- // eslint-disable-next-line no-unused-vars
11
- let ElementPlus: any
12
-
13
- function getEventTarget (evnt: Event) {
14
- const target = evnt.target as HTMLElement | null
15
- if (target && (target as any).shadowRoot && evnt.composed) {
16
- return evnt.composedPath()[0] as HTMLElement || target
17
- }
18
- return target
19
- }
20
-
21
- /**
22
- * 检查触发源是否属于目标节点
23
- */
24
- function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
25
- let targetElem
26
- let target = getEventTarget(evnt)
27
- const rootEl = document.documentElement || document.querySelector('html')
28
- while (target && target.nodeType && target !== rootEl) {
29
- if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
30
- targetElem = target
31
- } else if (target === container) {
32
- return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
33
- }
34
- target = target.parentElement
35
- }
36
- return { flag: false }
37
- }
38
-
39
- function toComponentName (name: string) {
40
- if (name) {
41
- return name.slice(0, 1).toUpperCase() + name.slice(1)
42
- }
43
- return name
44
- }
45
-
46
- export const VxeUIPluginRenderElement: VxeUIPluginObject = {
47
- component (comp: any) {
48
- if (comp && comp.name) {
49
- const kcName = XEUtils.kebabCase(comp.name)
50
- const ccName = toComponentName(XEUtils.camelCase(comp.name))
51
- componentMaps[kcName] = comp
52
- componentMaps[ccName] = comp
53
- } else {
54
- console.error('[VUE_APP_VXE_PLUGIN_VERSION] error component.', comp)
55
- }
56
- },
57
- install (VxeUI, options?: VxeUIPluginRenderElementOptions) {
58
- const pluginOpts = Object.assign({}, options)
59
-
60
- if (options) {
61
- ElementPlus = options.ElementPlus
62
- Object.assign(globalConfig, options)
63
- }
64
-
65
- // 检查版本
66
- if (VxeUI.checkVersion) {
67
- const pVersion = 4
68
- const sVersion = 11
69
- if (!VxeUI.checkVersion(VxeUI.tableVersion, pVersion, sVersion)) {
70
- console.error(`[VUE_APP_VXE_PLUGIN_VERSION] ${VxeUI.getI18n('vxe.error.errorVersion', [`vxe-table@${VxeUI.tableVersion || '?'}`, `vxe-table v${pVersion}.${sVersion}+`])} VUE_APP_VXE_PLUGIN_DESCRIBE`)
71
- }
72
- } else {
73
- if (!/^(4)\./.test(VxeUI.uiVersion || VxeUI.tableVersion)) {
74
- console.error('[VUE_APP_VXE_PLUGIN_VERSION] Requires VUE_APP_VXE_TABLE_VERSION+ version. VUE_APP_VXE_PLUGIN_DESCRIBE')
75
- }
76
- }
77
-
78
- /**
79
- * 事件兼容性处理
80
- */
81
- function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
82
- const { $event } = params
83
- const bodyElem = document.body
84
- const prefixCls = `${pluginOpts.prefixCls || 'el'}`.replace(/-$/, '')
85
- if (
86
- // 远程搜索
87
- getEventTargetNode($event, bodyElem, `${prefixCls}-autocomplete-suggestion`).flag ||
88
- // 下拉框
89
- getEventTargetNode($event, bodyElem, `${prefixCls}-select-dropdown`).flag ||
90
- // 级联
91
- getEventTargetNode($event, bodyElem, `${prefixCls}-cascader__dropdown`).flag ||
92
- getEventTargetNode($event, bodyElem, `${prefixCls}-cascader-menus`).flag ||
93
- // 日期
94
- getEventTargetNode($event, bodyElem, `${prefixCls}-time-panel`).flag ||
95
- getEventTargetNode($event, bodyElem, `${prefixCls}-picker-panel`).flag ||
96
- // 颜色
97
- getEventTargetNode($event, bodyElem, `${prefixCls}-color-dropdown`).flag
98
- ) {
99
- return false
100
- }
101
- }
102
-
103
- defineTableRender(VxeUI)
104
- defineFormRender(VxeUI)
105
- defineFormDesignRender(VxeUI)
106
-
107
- VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
108
- VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
109
- VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
110
- // 兼容老版本
111
- VxeUI.interceptor.add('event.clearActived', handleClearEvent)
112
- }
113
- }
114
-
115
- if (typeof window !== 'undefined') {
116
- if (window.VxeUI && window.VxeUI.use) {
117
- window.VxeUI.use(VxeUIPluginRenderElement)
118
- }
119
- if ((window as any).ElementPlus) {
120
- globalConfig.ElementPlus = (window as any).ElementPlus
121
- }
122
- }
123
-
124
- export default VxeUIPluginRenderElement
1
+ import { defineTableRender } from './table'
2
+ import { defineFormRender } from './form'
3
+ import { defineFormDesignRender } from './form-design'
4
+ import { globalConfig, componentMaps } from './store'
5
+ import XEUtils from 'xe-utils'
6
+
7
+ import type { VxeUIPluginRenderElementOptions } from '../types'
8
+ import type { VxeUIPluginObject, VxeGlobalInterceptorHandles } from 'vxe-pc-ui'
9
+
10
+ // eslint-disable-next-line no-unused-vars
11
+ let ElementPlus: any
12
+
13
+ function getEventTarget (evnt: Event) {
14
+ const target = evnt.target as HTMLElement | null
15
+ if (target && (target as any).shadowRoot && evnt.composed) {
16
+ return evnt.composedPath()[0] as HTMLElement || target
17
+ }
18
+ return target
19
+ }
20
+
21
+ /**
22
+ * 检查触发源是否属于目标节点
23
+ */
24
+ function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
25
+ let targetElem
26
+ let target = getEventTarget(evnt)
27
+ const rootEl = document.documentElement || document.querySelector('html')
28
+ while (target && target.nodeType && target !== rootEl) {
29
+ if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
30
+ targetElem = target
31
+ } else if (target === container) {
32
+ return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
33
+ }
34
+ target = target.parentElement
35
+ }
36
+ return { flag: false }
37
+ }
38
+
39
+ function toComponentName (name: string) {
40
+ if (name) {
41
+ return name.slice(0, 1).toUpperCase() + name.slice(1)
42
+ }
43
+ return name
44
+ }
45
+
46
+ export const VxeUIPluginRenderElement: VxeUIPluginObject = {
47
+ component (comp: any) {
48
+ if (comp && comp.name) {
49
+ const kcName = XEUtils.kebabCase(comp.name)
50
+ const ccName = toComponentName(XEUtils.camelCase(comp.name))
51
+ componentMaps[kcName] = comp
52
+ componentMaps[ccName] = comp
53
+ } else {
54
+ console.error('[VUE_APP_VXE_PLUGIN_VERSION] error component.', comp)
55
+ }
56
+ },
57
+ install (VxeUI, options?: VxeUIPluginRenderElementOptions) {
58
+ const pluginOpts = Object.assign({}, options)
59
+
60
+ if (options) {
61
+ ElementPlus = options.ElementPlus
62
+ Object.assign(globalConfig, options)
63
+ }
64
+
65
+ // 检查版本
66
+ if (VxeUI.checkVersion) {
67
+ const pVersion = 4
68
+ const sVersion = 11
69
+ if (!VxeUI.checkVersion(VxeUI.tableVersion, pVersion, sVersion)) {
70
+ console.error(`[VUE_APP_VXE_PLUGIN_VERSION] ${VxeUI.getI18n('vxe.error.errorVersion', [`vxe-table@${VxeUI.tableVersion || '?'}`, `vxe-table v${pVersion}.${sVersion}+`])} VUE_APP_VXE_PLUGIN_DESCRIBE`)
71
+ }
72
+ } else {
73
+ if (!/^(4)\./.test(VxeUI.uiVersion || VxeUI.tableVersion)) {
74
+ console.error('[VUE_APP_VXE_PLUGIN_VERSION] Requires VUE_APP_VXE_TABLE_VERSION+ version. VUE_APP_VXE_PLUGIN_DESCRIBE')
75
+ }
76
+ }
77
+
78
+ /**
79
+ * 事件兼容性处理
80
+ */
81
+ function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
82
+ const { $event } = params
83
+ const bodyElem = document.body
84
+ const prefixCls = `${pluginOpts.prefixCls || 'el'}`.replace(/-$/, '')
85
+ if (
86
+ // 远程搜索
87
+ getEventTargetNode($event, bodyElem, `${prefixCls}-autocomplete-suggestion`).flag ||
88
+ // 下拉框
89
+ getEventTargetNode($event, bodyElem, `${prefixCls}-select-dropdown`).flag ||
90
+ // 级联
91
+ getEventTargetNode($event, bodyElem, `${prefixCls}-cascader__dropdown`).flag ||
92
+ getEventTargetNode($event, bodyElem, `${prefixCls}-cascader-menus`).flag ||
93
+ // 日期
94
+ getEventTargetNode($event, bodyElem, `${prefixCls}-time-panel`).flag ||
95
+ getEventTargetNode($event, bodyElem, `${prefixCls}-picker-panel`).flag ||
96
+ // 颜色
97
+ getEventTargetNode($event, bodyElem, `${prefixCls}-color-dropdown`).flag
98
+ ) {
99
+ return false
100
+ }
101
+ }
102
+
103
+ defineTableRender(VxeUI)
104
+ defineFormRender(VxeUI)
105
+ defineFormDesignRender(VxeUI)
106
+
107
+ VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
108
+ VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
109
+ VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
110
+ // 兼容老版本
111
+ VxeUI.interceptor.add('event.clearActived', handleClearEvent)
112
+ }
113
+ }
114
+
115
+ if (typeof window !== 'undefined') {
116
+ if (window.VxeUI && window.VxeUI.use) {
117
+ window.VxeUI.use(VxeUIPluginRenderElement)
118
+ }
119
+ if ((window as any).ElementPlus) {
120
+ globalConfig.ElementPlus = (window as any).ElementPlus
121
+ }
122
+ }
123
+
124
+ export default VxeUIPluginRenderElement
@@ -1,5 +1,5 @@
1
- import type { DefineComponent, ConcreteComponent } from 'vue'
2
- import type { VxeUIPluginRenderElementOptions } from '../../types'
3
-
4
- export const globalConfig: VxeUIPluginRenderElementOptions = {}
5
- export const componentMaps: Record<string, DefineComponent | ConcreteComponent> = {}
1
+ import type { DefineComponent, ConcreteComponent } from 'vue'
2
+ import type { VxeUIPluginRenderElementOptions } from '../../types'
3
+
4
+ export const globalConfig: VxeUIPluginRenderElementOptions = {}
5
+ export const componentMaps: Record<string, DefineComponent | ConcreteComponent> = {}