ci-plus 1.3.7 → 1.3.8

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.
@@ -0,0 +1,24 @@
1
+ <script lang="ts">
2
+ import { defineComponent } from 'vue'
3
+ export default defineComponent({
4
+ name: 'RenderCol',
5
+ props: {
6
+ row: Object,
7
+ render: Function,
8
+ index: Number,
9
+ column: {
10
+ type: Object,
11
+ default: null
12
+ }
13
+ },
14
+ render(ctx) {
15
+ // console.log(111, ctx)
16
+ const params: any = {
17
+ row: ctx.row,
18
+ index: ctx.index
19
+ }
20
+ if (ctx.column) params.column = ctx.column
21
+ return ctx.render(ctx?.row[ctx?.column?.prop], ctx.row, ctx.index)
22
+ }
23
+ })
24
+ </script>
@@ -0,0 +1,117 @@
1
+ import { isClient } from '@vueuse/core'
2
+ import type {
3
+ ComponentPublicInstance,
4
+ DirectiveBinding,
5
+ ObjectDirective,
6
+ } from 'vue'
7
+
8
+ type DocumentHandler = <T extends MouseEvent>(mouseup: T, mousedown: T) => void
9
+ type FlushList = Map<
10
+ HTMLElement,
11
+ {
12
+ documentHandler: DocumentHandler
13
+ bindingFn: (...args: unknown[]) => unknown
14
+ }[]
15
+ >
16
+
17
+ const nodeList: FlushList = new Map()
18
+
19
+ let startClick: MouseEvent
20
+
21
+ if (isClient) {
22
+ document.addEventListener('mousedown', (e: MouseEvent) => (startClick = e))
23
+ document.addEventListener('mouseup', (e: MouseEvent) => {
24
+ for (const handlers of nodeList.values()) {
25
+ for (const { documentHandler } of handlers) {
26
+ documentHandler(e as MouseEvent, startClick)
27
+ }
28
+ }
29
+ })
30
+ }
31
+
32
+ function createDocumentHandler(
33
+ el: HTMLElement,
34
+ binding: DirectiveBinding
35
+ ): DocumentHandler {
36
+ let excludes: HTMLElement[] = []
37
+ if (Array.isArray(binding.arg)) {
38
+ excludes = binding.arg
39
+ } else if ((binding.arg as unknown) instanceof HTMLElement) {
40
+ // due to current implementation on binding type is wrong the type casting is necessary here
41
+ excludes.push(binding.arg as unknown as HTMLElement)
42
+ }
43
+ return function (mouseup, mousedown) {
44
+ const popperRef = (
45
+ binding.instance as ComponentPublicInstance<{
46
+ popperRef: HTMLElement
47
+ }>
48
+ ).popperRef
49
+ const mouseUpTarget = mouseup.target as Node
50
+ const mouseDownTarget = mousedown?.target as Node
51
+ const isBound = !binding || !binding.instance
52
+ const isTargetExists = !mouseUpTarget || !mouseDownTarget
53
+ const isContainedByEl =
54
+ el.contains(mouseUpTarget) || el.contains(mouseDownTarget)
55
+ const isSelf = el === mouseUpTarget
56
+
57
+ const isTargetExcluded =
58
+ (excludes.length &&
59
+ excludes.some((item) => item?.contains(mouseUpTarget))) ||
60
+ (excludes.length && excludes.includes(mouseDownTarget as HTMLElement))
61
+ const isContainedByPopper =
62
+ popperRef &&
63
+ (popperRef.contains(mouseUpTarget) || popperRef.contains(mouseDownTarget))
64
+ if (
65
+ isBound ||
66
+ isTargetExists ||
67
+ isContainedByEl ||
68
+ isSelf ||
69
+ isTargetExcluded ||
70
+ isContainedByPopper
71
+ ) {
72
+ return
73
+ }
74
+ binding.value(mouseup, mousedown)
75
+ }
76
+ }
77
+
78
+ const ClickOutside: ObjectDirective = {
79
+ beforeMount(el: HTMLElement, binding: DirectiveBinding) {
80
+ // there could be multiple handlers on the element
81
+ if (!nodeList.has(el)) {
82
+ nodeList.set(el, [])
83
+ }
84
+
85
+ nodeList.get(el)!.push({
86
+ documentHandler: createDocumentHandler(el, binding),
87
+ bindingFn: binding.value,
88
+ })
89
+ },
90
+ updated(el: HTMLElement, binding: DirectiveBinding) {
91
+ if (!nodeList.has(el)) {
92
+ nodeList.set(el, [])
93
+ }
94
+
95
+ const handlers = nodeList.get(el)!
96
+ const oldHandlerIndex = handlers.findIndex(
97
+ (item) => item.bindingFn === binding.oldValue
98
+ )
99
+ const newHandler = {
100
+ documentHandler: createDocumentHandler(el, binding),
101
+ bindingFn: binding.value,
102
+ }
103
+
104
+ if (oldHandlerIndex >= 0) {
105
+ // replace the old handler to the new handler
106
+ handlers.splice(oldHandlerIndex, 1, newHandler)
107
+ } else {
108
+ handlers.push(newHandler)
109
+ }
110
+ },
111
+ unmounted(el: HTMLElement) {
112
+ // remove all listeners when a component unmounted
113
+ nodeList.delete(el)
114
+ },
115
+ }
116
+
117
+ export default ClickOutside