From efed314065f2fff27b7b9881ce80c78b57634599 Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Wed, 4 Nov 2020 00:26:00 +0800 Subject: [PATCH] refactor: clear utils --- package.json | 2 +- src/_mixins/placeable/index.js | 2 +- src/_utils/composition/index.js | 41 ++++++++++--------- src/_utils/composition/use-delayed.js | 33 --------------- .../composition/use-last-click-position.js | 17 -------- .../{getParentNode.js => get-parent-node.js} | 0 ...etScrollParent.js => get-scroll-parent.js} | 4 +- ...erty.js => get-style-computed-property.js} | 0 src/_utils/index.js | 3 +- src/_utils/misc/index.js | 1 - src/_utils/misc/os.js | 3 -- src/_utils/vue/validateProp.js | 11 ----- src/affix/src/Affix.vue | 2 +- src/anchor/src/BaseAnchor.vue | 2 +- src/back-top/src/BackTop.vue | 2 +- src/modal/src/BodyWrapper.vue | 13 ++---- src/modal/src/Modal.js | 14 +++++-- src/scrollbar/src/ScrollBar.vue | 4 +- src/transfer/src/TransferButton.vue | 4 +- src/transfer/src/TransferHeaderCheckbox.vue | 7 ++-- src/transfer/src/TransferHeaderExtra.vue | 4 +- src/transfer/src/TransferSourceListItem.vue | 7 ++-- src/transfer/src/TransferTargetListItem.vue | 7 ++-- 23 files changed, 57 insertions(+), 126 deletions(-) delete mode 100644 src/_utils/composition/use-delayed.js delete mode 100644 src/_utils/composition/use-last-click-position.js rename src/_utils/dom/{getParentNode.js => get-parent-node.js} (100%) rename src/_utils/dom/{getScrollParent.js => get-scroll-parent.js} (92%) rename src/_utils/dom/{getStyleComputedProperty.js => get-style-computed-property.js} (100%) delete mode 100644 src/_utils/misc/os.js delete mode 100644 src/_utils/vue/validateProp.js diff --git a/package.json b/package.json index 76acf8053..bc5d83c3e 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/src/_mixins/placeable/index.js b/src/_mixins/placeable/index.js index cc9288a3c..b0d26e0b5 100644 --- a/src/_mixins/placeable/index.js +++ b/src/_mixins/placeable/index.js @@ -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, diff --git a/src/_utils/composition/index.js b/src/_utils/composition/index.js index 07030bd43..8e76d1c16 100644 --- a/src/_utils/composition/index.js +++ b/src/_utils/composition/index.js @@ -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 +} diff --git a/src/_utils/composition/use-delayed.js b/src/_utils/composition/use-delayed.js deleted file mode 100644 index 191108143..000000000 --- a/src/_utils/composition/use-delayed.js +++ /dev/null @@ -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 () { - -} diff --git a/src/_utils/composition/use-last-click-position.js b/src/_utils/composition/use-last-click-position.js deleted file mode 100644 index c29a61be7..000000000 --- a/src/_utils/composition/use-last-click-position.js +++ /dev/null @@ -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 -} diff --git a/src/_utils/dom/getParentNode.js b/src/_utils/dom/get-parent-node.js similarity index 100% rename from src/_utils/dom/getParentNode.js rename to src/_utils/dom/get-parent-node.js diff --git a/src/_utils/dom/getScrollParent.js b/src/_utils/dom/get-scroll-parent.js similarity index 92% rename from src/_utils/dom/getScrollParent.js rename to src/_utils/dom/get-scroll-parent.js index 22218db10..e21e2a284 100644 --- a/src/_utils/dom/getScrollParent.js +++ b/src/_utils/dom/get-scroll-parent.js @@ -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 diff --git a/src/_utils/dom/getStyleComputedProperty.js b/src/_utils/dom/get-style-computed-property.js similarity index 100% rename from src/_utils/dom/getStyleComputedProperty.js rename to src/_utils/dom/get-style-computed-property.js diff --git a/src/_utils/index.js b/src/_utils/index.js index ac76a8c4e..91867e373 100644 --- a/src/_utils/index.js +++ b/src/_utils/index.js @@ -18,8 +18,7 @@ export { } from './css' export * from './composition' export { - nextFrame, - isIos + nextFrame } from './misc' export { KEY_CODE diff --git a/src/_utils/misc/index.js b/src/_utils/misc/index.js index c1bdaa015..0c91372aa 100644 --- a/src/_utils/misc/index.js +++ b/src/_utils/misc/index.js @@ -1,2 +1 @@ export { default as nextFrame } from './next-frame' -export { isIos } from './os' diff --git a/src/_utils/misc/os.js b/src/_utils/misc/os.js deleted file mode 100644 index 34ab5bf13..000000000 --- a/src/_utils/misc/os.js +++ /dev/null @@ -1,3 +0,0 @@ -export const isIos = (/iPad|iPhone|iPod/.test(navigator.platform) || - (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) && - !window.MSStream diff --git a/src/_utils/vue/validateProp.js b/src/_utils/vue/validateProp.js deleted file mode 100644 index b80fd0386..000000000 --- a/src/_utils/vue/validateProp.js +++ /dev/null @@ -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 diff --git a/src/affix/src/Affix.vue b/src/affix/src/Affix.vue index f55146060..26bdba648 100644 --- a/src/affix/src/Affix.vue +++ b/src/affix/src/Affix.vue @@ -12,7 +12,7 @@