mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-03 04:21:34 +08:00
refactor: clear utils
This commit is contained in:
parent
c2aa7f67fd
commit
efed314065
@ -85,7 +85,7 @@
|
||||
"lodash-es": "^4.17.15",
|
||||
"treemate": "^0.1.9",
|
||||
"vicons": "0.0.1",
|
||||
"vooks": "0.0.1-alpha.1",
|
||||
"vooks": "0.0.1-alpha.3",
|
||||
"vue": "^3.0.2",
|
||||
"vueuc": "0.1.0-alpha.9"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { nextTick } from 'vue'
|
||||
import scrollDelegate from '../../_utils/delegate/scrollDelegate'
|
||||
import resizeDelegate from '../../_utils/delegate/resizeDelegate'
|
||||
import getScrollParent from '../../_utils/dom/getScrollParent'
|
||||
import getScrollParent from '../../_utils/dom/get-scroll-parent'
|
||||
import { warn } from '../../_utils/naive/warn'
|
||||
import {
|
||||
getAdjustedPlacementOfTrackingElement,
|
||||
|
@ -5,26 +5,9 @@ import {
|
||||
inject,
|
||||
toRef,
|
||||
getCurrentInstance,
|
||||
onBeforeUnmount,
|
||||
nextTick
|
||||
onBeforeUnmount
|
||||
} from 'vue'
|
||||
|
||||
export function useDisabledUntilMounted (durationTickCount = 0) {
|
||||
const disabled = ref(true)
|
||||
onMounted(() => {
|
||||
function countDown () {
|
||||
if (!durationTickCount) {
|
||||
disabled.value = false
|
||||
} else {
|
||||
durationTickCount -= 1
|
||||
nextTick(countDown)
|
||||
}
|
||||
}
|
||||
countDown()
|
||||
})
|
||||
return disabled
|
||||
}
|
||||
|
||||
export function useInjectionRef (injectionName, key, fallback) {
|
||||
const injection = inject(injectionName)
|
||||
if (!injection && arguments.length > 2) return fallback
|
||||
@ -87,5 +70,23 @@ export function useInjectionElementCollection (injectionName, collectionKey, get
|
||||
})
|
||||
}
|
||||
|
||||
export { default as useLastClickPosition } from './use-last-click-position'
|
||||
export { useDelayedTrue } from './use-delayed'
|
||||
export function useDelayedTrue (valueRef, delay, shouldDelayRef) {
|
||||
if (!delay) return valueRef
|
||||
const delayedRef = ref(valueRef.value)
|
||||
let timerId = null
|
||||
watch(valueRef, value => {
|
||||
if (timerId !== null) clearTimeout(timerId)
|
||||
if (value === true) {
|
||||
if (shouldDelayRef && shouldDelayRef.value === false) {
|
||||
delayedRef.value = true
|
||||
} else {
|
||||
timerId = setTimeout(() => {
|
||||
delayedRef.value = true
|
||||
}, delay)
|
||||
}
|
||||
} else {
|
||||
delayedRef.value = false
|
||||
}
|
||||
})
|
||||
return delayedRef
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
import {
|
||||
ref,
|
||||
watch
|
||||
} from 'vue'
|
||||
|
||||
export function useDelayedTrue (valueRef, delay, shouldDelayRef) {
|
||||
if (!delay) return valueRef
|
||||
const delayedRef = ref(valueRef.value)
|
||||
let timerId = null
|
||||
watch(valueRef, value => {
|
||||
if (timerId !== null) clearTimeout(timerId)
|
||||
if (value === true) {
|
||||
if (shouldDelayRef && shouldDelayRef.value === false) {
|
||||
delayedRef.value = true
|
||||
} else {
|
||||
timerId = setTimeout(() => {
|
||||
delayedRef.value = true
|
||||
}, delay)
|
||||
}
|
||||
} else {
|
||||
delayedRef.value = false
|
||||
}
|
||||
})
|
||||
return delayedRef
|
||||
}
|
||||
|
||||
export function useDelayedValue () {
|
||||
|
||||
}
|
||||
|
||||
export function useDelayedFalse () {
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
const mousePositionRef = ref(null)
|
||||
|
||||
document.documentElement.addEventListener('click', (e) => {
|
||||
mousePositionRef.value = {
|
||||
x: e.clientX,
|
||||
y: e.clientY
|
||||
}
|
||||
window.setTimeout(() => {
|
||||
mousePositionRef.value = null
|
||||
}, 32)
|
||||
}, true)
|
||||
|
||||
export default function useLastClickPosition () {
|
||||
return mousePositionRef
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import getStyleComputedProperty from './getStyleComputedProperty'
|
||||
import getParentNode from './getParentNode'
|
||||
import getStyleComputedProperty from './get-style-computed-property'
|
||||
import getParentNode from './get-parent-node'
|
||||
|
||||
const NOT_FOUND = 'NOT_FOUND'
|
||||
const CACHE_DURATION = 60000
|
@ -18,8 +18,7 @@ export {
|
||||
} from './css'
|
||||
export * from './composition'
|
||||
export {
|
||||
nextFrame,
|
||||
isIos
|
||||
nextFrame
|
||||
} from './misc'
|
||||
export {
|
||||
KEY_CODE
|
||||
|
@ -1,2 +1 @@
|
||||
export { default as nextFrame } from './next-frame'
|
||||
export { isIos } from './os'
|
||||
|
@ -1,3 +0,0 @@
|
||||
export const isIos = (/iPad|iPhone|iPod/.test(navigator.platform) ||
|
||||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
|
||||
!window.MSStream
|
@ -1,11 +0,0 @@
|
||||
function createValidator (types) {
|
||||
return value => {
|
||||
for (let i = 0; i < types.length; ++i) {
|
||||
// eslint-disable-next-line valid-typeof
|
||||
if (typeof value === types[i]) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default createValidator
|
@ -12,7 +12,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import getScrollParent from '../../_utils/dom/getScrollParent'
|
||||
import getScrollParent from '../../_utils/dom/get-scroll-parent'
|
||||
import { usecssr } from '../../_mixins'
|
||||
import styles from './styles/index.js'
|
||||
import getTarget from '../../_utils/dom/get-target'
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
<script>
|
||||
import { nextTick, ref, markRaw } from 'vue'
|
||||
import getScrollParent from '../../_utils/dom/getScrollParent'
|
||||
import getScrollParent from '../../_utils/dom/get-scroll-parent'
|
||||
import {
|
||||
configurable,
|
||||
themeable,
|
||||
|
@ -53,7 +53,7 @@
|
||||
<script>
|
||||
import { ref, computed, toRef, watch, nextTick } from 'vue'
|
||||
import { useIsMounted, useMergedState } from 'vooks'
|
||||
import getScrollParent from '../../_utils/dom/getScrollParent'
|
||||
import getScrollParent from '../../_utils/dom/get-scroll-parent'
|
||||
import {
|
||||
configurable,
|
||||
themeable,
|
||||
|
@ -78,7 +78,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { nextTick, reactive, toRefs, toRef, watch, ref } from 'vue'
|
||||
import { nextTick, reactive, toRefs, toRef, watch, ref, inject } from 'vue'
|
||||
import NScrollbar from '../../scrollbar'
|
||||
import NDialog from '../../dialog/src/Dialog.vue'
|
||||
import NCard from '../../card'
|
||||
@ -86,7 +86,6 @@ import themeable from '../../_mixins/themeable'
|
||||
import presetProps from './presetProps'
|
||||
import clickoutside from '../../_directives/clickoutside'
|
||||
import { useCompitable } from 'vooks'
|
||||
import { useLastClickPosition } from '../../_utils/composition'
|
||||
|
||||
export default {
|
||||
name: 'ModalBody',
|
||||
@ -107,11 +106,6 @@ export default {
|
||||
NDrawerBody: null
|
||||
}
|
||||
},
|
||||
inject: {
|
||||
NModal: {
|
||||
default: null
|
||||
}
|
||||
},
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
@ -161,17 +155,18 @@ export default {
|
||||
watch(toRef(props, 'show'), value => {
|
||||
if (value) dataRefs.displayed.value = true
|
||||
})
|
||||
const NModal = inject('NModal', null)
|
||||
return {
|
||||
NModal,
|
||||
mousePosition: toRef(NModal, 'mousePosition'),
|
||||
compitableBodyStyle: useCompitable(props, [
|
||||
'overlayStyle',
|
||||
'bodyStyle'
|
||||
]),
|
||||
mousePosition: useLastClickPosition(),
|
||||
bodyRef: ref(null),
|
||||
...dataRefs
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
styleTransformOrigin () {
|
||||
const {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { h, withDirectives, Transition, ref } from 'vue'
|
||||
import { h, withDirectives, Transition, ref, computed } from 'vue'
|
||||
import { zindexable } from '../../_directives'
|
||||
import { configurable, themeable, usecssr } from '../../_mixins'
|
||||
import presetProps from './presetProps'
|
||||
import { useIsMounted } from 'vooks'
|
||||
import { useIsMounted, useClicked, useClickPosition } from 'vooks'
|
||||
import { warn } from '../../_utils/naive/warn'
|
||||
import { omit } from '../../_utils/vue'
|
||||
import NLazyTeleport from '../../_base/lazy-teleport'
|
||||
@ -100,9 +100,17 @@ export default {
|
||||
}
|
||||
},
|
||||
setup () {
|
||||
const clickedRef = useClicked(64)
|
||||
const clickedPositionRef = useClickPosition()
|
||||
return {
|
||||
isMounted: useIsMounted(),
|
||||
containerRef: ref(null)
|
||||
containerRef: ref(null),
|
||||
mousePosition: computed(() => {
|
||||
if (clickedRef.value) {
|
||||
return clickedPositionRef.value
|
||||
}
|
||||
return null
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -105,7 +105,7 @@ import {
|
||||
usecssr
|
||||
} from '../../_mixins'
|
||||
import styles from './styles/index.js'
|
||||
import { isIos } from '../../_utils'
|
||||
import { useIsIos } from 'vooks'
|
||||
|
||||
export default {
|
||||
name: 'Scrollbar',
|
||||
@ -191,7 +191,7 @@ export default {
|
||||
memoXLeft: null,
|
||||
memoMouseX: null,
|
||||
memoMouseY: null,
|
||||
isIos
|
||||
isIos: useIsIos()
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -21,8 +21,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
|
||||
export default {
|
||||
inject: {
|
||||
NTransfer: {
|
||||
@ -31,7 +29,7 @@ export default {
|
||||
},
|
||||
props: {
|
||||
to: {
|
||||
validator: createValidator(['boolean']),
|
||||
validator: Boolean,
|
||||
default: false
|
||||
},
|
||||
onClick: {
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
<script>
|
||||
import NCheckbox from '../../checkbox/src/Checkbox.vue'
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
|
||||
export default {
|
||||
name: 'NTransferHeaderCheckbox',
|
||||
@ -25,15 +24,15 @@ export default {
|
||||
},
|
||||
props: {
|
||||
theme: {
|
||||
validator: createValidator(['string']),
|
||||
validator: String,
|
||||
default: null
|
||||
},
|
||||
source: {
|
||||
validator: createValidator(['boolean']),
|
||||
validator: Boolean,
|
||||
default: false
|
||||
},
|
||||
onChange: {
|
||||
validator: createValidator(['function']),
|
||||
validator: Function,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
@ -13,8 +13,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
|
||||
export default {
|
||||
name: 'NTransferHeaderExtra',
|
||||
inject: {
|
||||
@ -24,7 +22,7 @@ export default {
|
||||
},
|
||||
props: {
|
||||
source: {
|
||||
validator: createValidator(['boolean']),
|
||||
validator: Boolean,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
<script>
|
||||
import { inject } from 'vue'
|
||||
import NCheckbox from '../../checkbox/src/Checkbox.vue'
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
import { useMemo } from 'vooks'
|
||||
|
||||
export default {
|
||||
@ -40,15 +39,15 @@ export default {
|
||||
},
|
||||
props: {
|
||||
label: {
|
||||
validator: createValidator(['string']),
|
||||
validator: String,
|
||||
required: true
|
||||
},
|
||||
value: {
|
||||
validator: createValidator(['string', 'number']),
|
||||
validator: [String, Number],
|
||||
required: true
|
||||
},
|
||||
disabled: {
|
||||
validator: createValidator(['boolean']),
|
||||
validator: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
@ -25,7 +25,6 @@
|
||||
<script>
|
||||
import { inject } from 'vue'
|
||||
import NCheckbox from '../../checkbox/src/Checkbox.vue'
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
import { useMemo } from 'vooks'
|
||||
|
||||
export default {
|
||||
@ -40,15 +39,15 @@ export default {
|
||||
},
|
||||
props: {
|
||||
label: {
|
||||
validator: createValidator(['string']),
|
||||
validator: String,
|
||||
required: true
|
||||
},
|
||||
value: {
|
||||
validator: createValidator(['string', 'number']),
|
||||
validator: [String, Number],
|
||||
required: true
|
||||
},
|
||||
disabled: {
|
||||
validator: createValidator(['boolean']),
|
||||
validator: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user