refactor: rename some util scripts

This commit is contained in:
07akioni 2020-02-14 16:27:42 +08:00
parent d9d2c51e65
commit a8d4f4a486
42 changed files with 93 additions and 174 deletions

View File

@ -82,7 +82,7 @@ export default {
},
watch: {
show (value) {
if (value) this.$emit('shohw')
if (value) this.$emit('show')
return this.$emit('hide')
}
},

View File

@ -25,7 +25,7 @@
<script>
import CheckMark from './CheckMark'
import LineMark from './LineMark'
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
name: 'NSimpleCheckbox',

View File

@ -1,7 +1,7 @@
<script>
import withapp from '../../_mixins/withapp'
import themeable from '../../_mixins/themeable'
import styleScheme from '../../_utils/colors'
import styleScheme from '../../_utils/naive/styleScheme'
export default {
name: 'NConfigConsumer',

View File

@ -1,6 +1,6 @@
import ConfirmPlugin from './src/ConfirmPlugin.js'
import Confirm from './src/Confirm'
import { install } from '../_utils/installThemeAwarableProperty'
import { install } from '../_utils/naive/installThemeAwarableProperty'
ConfirmPlugin.install = function (Vue) {
ConfirmPlugin.Vue = Vue

View File

@ -78,7 +78,7 @@ import iosHelpCircle from '../../_icons/ios-help-circle'
import iosCloseCircle from '../../_icons/ios-close-circle'
import withapp from '../../_mixins/withapp'
import themeable from '../../_mixins/themeable'
import render from '../../_utils/render'
import render from '../../_utils/vue/render'
export default {
name: 'NConfirm',

View File

@ -8,7 +8,7 @@
</template>
<script>
import render from '../../../_utils/render'
import render from '../../../_utils/vue/render'
export default {
name: 'NDataTableCell',

View File

@ -74,7 +74,7 @@
import SortButton from '../HeaderButton/SortButton'
import FilterButton from '../HeaderButton/FilterButton'
import { createCustomWidthStyle } from '../utils'
import render from '../../../_utils/render'
import render from '../../../_utils/vue/render'
function isColumnSortable (column) {
return !!column.sorter

View File

@ -149,7 +149,7 @@ import iosCalendar from '../../_icons/ios-calendar'
import format from 'date-fns/format'
import getTime from 'date-fns/getTime'
import isValid from 'date-fns/isValid'
import { strictParse } from '../../_utils/dateUtils'
import { strictParse } from '../../_utils/component/datePicker'
import isEqual from 'lodash-es/isEqual'
const DATE_FORMAT = {

View File

@ -257,7 +257,7 @@ import getYear from 'date-fns/getYear'
import getMonth from 'date-fns/getMonth'
import getDate from 'date-fns/getDate'
import isValid from 'date-fns/isValid'
import { strictParse } from '../../../_utils/dateUtils'
import { strictParse } from '../../../_utils/component/datePicker'
const DATETIME_FORMAT = 'yyyy-MM-dd HH:mm:ss'
const DATE_FORMAT = 'yyyy-MM-dd'

View File

@ -9,7 +9,7 @@ import isValid from 'date-fns/isValid'
import getHours from 'date-fns/getHours'
import getMinutes from 'date-fns/getMinutes'
import getSeconds from 'date-fns/getSeconds'
import { dateArray } from '../../../_utils/dateUtils'
import { dateArray } from '../../../_utils/component/datePicker'
import commonCalendarMixin from './commonCalendarMixin'
export default {

View File

@ -11,7 +11,7 @@ import getDate from 'date-fns/getDate'
import isValid from 'date-fns/isValid'
import startOfHour from 'date-fns/startOfHour'
import setHours from 'date-fns/setHours'
import { dateArray, strictParse } from '../../../_utils/dateUtils'
import { dateArray, strictParse } from '../../../_utils/component/datePicker'
export default {
mixins: [commonCalendarMixin],

View File

@ -2,7 +2,7 @@
import withapp from '../../_mixins/withapp'
import themeable from '../../_mixins/themeable'
import { getRootDropdownMenu, createSelectOptions } from './utils'
import { KEY_CODE } from '../../_utils/keyCode'
import { KEY_CODE } from '../../_utils/event/keyCode'
import NBaseSelectMenu from '../../_base/SelectMenu'
export default {

View File

@ -2,7 +2,7 @@
import withapp from '../../_mixins/withapp'
import themeable from '../../_mixins/themeable'
import asthemecontext from '../../_mixins/asthemecontext'
import styleScheme from '../../_utils/colors'
import styleScheme from '../../_utils/naive/styleScheme'
export default {
name: 'NElement',

View File

@ -1,6 +1,6 @@
/* istanbul ignore file */
import LoadingBarPlugin from './src/LoadingBarPlugin.js'
import { install } from '../_utils/installThemeAwarableProperty'
import { install } from '../_utils/naive/installThemeAwarableProperty'
LoadingBarPlugin.install = function (Vue) {
install(Vue, LoadingBarPlugin, '$NLoadingBar')

View File

@ -38,7 +38,7 @@
</template>
<script>
import render from '../../_utils/render'
import render from '../../_utils/vue/render'
export default {
name: 'NMenuItemContent',

View File

@ -9,7 +9,7 @@
</li>
</template>
<script>
import render from '../../_utils/render'
import render from '../../_utils/vue/render'
export default {
name: 'NMenuItemGroup',

View File

@ -1,5 +1,5 @@
import MessagePlugin from './src/MessagePlugin'
import { install } from '../_utils/installThemeAwarableProperty'
import { install } from '../_utils/naive/installThemeAwarableProperty'
MessagePlugin.install = function (Vue) {
MessagePlugin.Vue = Vue

View File

@ -6,7 +6,7 @@ import mdInformationCircle from '../../_icons/md-information-circle'
import mdCloseCircle from '../../_icons/md-close-circle'
import NBaseLoading from '../../_base/Loading'
import IconSwitchTransition from '../../_transition/IconSwitchTransition'
import render from '../../_utils/render'
import render from '../../_utils/vue/render'
export default {
props: {

View File

@ -1,5 +1,5 @@
import Notification from './src/NotificationPlugin'
import { install } from '../_utils/installThemeAwarableProperty'
import { install } from '../_utils/naive/installThemeAwarableProperty'
Notification.install = function (Vue) {
Notification.Vue = Vue

View File

@ -64,7 +64,7 @@ import mdCheckmarkCircle from '../../_icons/md-checkmark-circle'
import mdAlert from '../../_icons/md-alert'
import mdInformationCircle from '../../_icons/md-information-circle'
import mdCloseCircle from '../../_icons/md-close-circle'
import render from '../../_utils/render'
import render from '../../_utils/vue/render'
export default {
components: {

View File

@ -2,7 +2,12 @@ import NBaseContext from '../../_base/Context'
import NBasePortal from '../../_base/Portal'
import NPopoverContent from './PopoverContent'
import activatorMixin from './activatorMixin'
import genId from '../../_utils/genId'
function createId () {
return Math.random()
.toString(36)
.slice(2)
}
function mixin (component, mixins) {
component.mixins = component.mixins || []
@ -112,7 +117,7 @@ export default {
staticClass: 'n-popover-text-wrapper'
}, [activatorVNode])
}
const id = genId()
const id = createId()
const props = context.props
const listeners = context.listeners
const controller = context.props.controller

View File

@ -171,7 +171,7 @@ import getTime from 'date-fns/getTime'
import getMinutes from 'date-fns/getMinutes'
import getHours from 'date-fns/getHours'
import getSeconds from 'date-fns/getSeconds'
import { strictParse } from '../../_utils/dateUtils'
import { strictParse } from '../../_utils/component/datePicker'
const DEFAULT_FORMAT = 'HH:mm:ss'
const TIME_CONST = {

View File

@ -1,9 +1,7 @@
/* istanbul ignore file */
import Transfer from './src/Transfer.vue'
import installPropsUnsafeTransition from '../_utils/installPropsUnsafeTransition'
Transfer.install = function (Vue) {
installPropsUnsafeTransition(Vue)
Vue.component(Transfer.name, Transfer)
}

View File

@ -21,7 +21,7 @@
</template>
<script>
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
props: {

View File

@ -10,7 +10,7 @@
<script>
import NSimpleCheckbox from '../../Checkbox/src/SimpleCheckbox'
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
name: 'NTransferHeaderCheckbox',

View File

@ -21,7 +21,7 @@
</template>
<script>
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
name: 'NTransferHeaderExtra',

View File

@ -26,7 +26,7 @@
<script>
import NSimpleCheckbox from '../../Checkbox/src/SimpleCheckbox'
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
name: 'NTransferListItem',

View File

@ -26,7 +26,7 @@
<script>
import NSimpleCheckbox from '../../Checkbox/src/SimpleCheckbox'
import createValidator from '../../_utils/validateProp'
import createValidator from '../../_utils/vue/validateProp'
export default {
name: 'NTransferListItem',

View File

@ -98,7 +98,7 @@ import NBaseLightBar from '../../LightBar'
import NEmpty from '../../../Empty'
import { RecycleScroller } from 'vue-virtual-scroller'
import debounce from 'lodash-es/debounce'
import render from '../../../_utils/render'
import render from '../../../_utils/vue/render'
import {
getPrevAvailableIndex,
getNextAvailableIndex,

View File

@ -1,9 +0,0 @@
import darkstyleScheme from '../_themes/darkstyleScheme.scss'
import lightstyleScheme from '../_themes/lightstyleScheme.scss'
const styleScheme = {
dark: darkstyleScheme,
light: lightstyleScheme
}
export default styleScheme

View File

@ -1,82 +0,0 @@
/** deprecated */
const DROPDOWN_RELATED_COMPONENT = ['NDropdownItem', 'NDropdownSubmenu', 'NMenuItem', 'NSubmenu']
const SELECT_OPTION_LIKE_COMPONENT = ['NBaseSelectOption', 'NDropdownItem', 'NDropdownSubmenu', 'NMenuItem', 'NSubmenu']
function isSelectOptionLikeComponent (vNode) {
return SELECT_OPTION_LIKE_COMPONENT.includes(getComponentNameOf(vNode))
}
function isDropdownRelatedComponent (vNode) {
return DROPDOWN_RELATED_COMPONENT.includes(getComponentNameOf(vNode))
}
function getComponentNameOf (vNode) {
/**
* Functional component
*/
if (vNode.fnOptions && vNode.fnOptions.name) {
return vNode.fnOptions.name
}
if (
vNode.componentOptions &&
vNode.componentOptions.Ctor &&
vNode.componentOptions.Ctor.extendOptions &&
vNode.componentOptions.Ctor.extendOptions.name
) {
return vNode.componentOptions.Ctor.extendOptions.name
}
return null
}
function getDefaultSlotOf (componentInstance) {
return getSlotOf(componentInstance, 'default')
}
function getSlotOf (componentInstance, slotName) {
if (componentInstance.$slots[slotName]) return componentInstance.$slots[slotName] || []
if (componentInstance.$scopedSlots[slotName]) return componentInstance.$scopedSlots[slotName]() || []
return []
}
function getOptionPropsDataOf (vNode) {
/**
* Functional component
*/
const propsData =
(vNode.componentOptions && vNode.componentOptions.propsData) ||
vNode.data.props ||
{}
if (!isDropdownRelatedComponent(vNode)) {
/**
* Select Option
* value is required!
* label should be set here
*/
if (!propsData.label) {
if (vNode.componentOptions.children) {
try {
propsData.label = vNode.componentOptions.children[0].text.trim()
} catch (err) {
// console.error(['[naive-ui/select-option]: Select Option only accept pure text as children.'])
propsData.label = null
}
} else if (propsData.value) {
propsData.label = String(propsData.value)
}
}
} else {
/**
* DropdownItem & DropdownSubmenu
*/
}
return propsData
}
export {
getSlotOf,
getDefaultSlotOf,
getComponentNameOf,
getOptionPropsDataOf,
isDropdownRelatedComponent,
isSelectOptionLikeComponent
}

View File

@ -0,0 +1,33 @@
function getComponentNameOf (vNode) {
/**
* Functional component
*/
if (vNode.fnOptions && vNode.fnOptions.name) {
return vNode.fnOptions.name
}
if (
vNode.componentOptions &&
vNode.componentOptions.Ctor &&
vNode.componentOptions.Ctor.extendOptions &&
vNode.componentOptions.Ctor.extendOptions.name
) {
return vNode.componentOptions.Ctor.extendOptions.name
}
return null
}
function getDefaultSlotOf (componentInstance) {
return getSlotOf(componentInstance, 'default')
}
function getSlotOf (componentInstance, slotName) {
if (componentInstance.$slots[slotName]) return componentInstance.$slots[slotName] || []
if (componentInstance.$scopedSlots[slotName]) return componentInstance.$scopedSlots[slotName]() || []
return []
}
export {
getSlotOf,
getDefaultSlotOf,
getComponentNameOf
}

View File

@ -1,5 +0,0 @@
export default function genId () {
return Math.random()
.toString(36)
.slice(2)
}

View File

@ -1,47 +0,0 @@
import getScrollParent from './dom/getScrollParent'
const isObject = (o) => {
let type = Object.prototype.toString.call(o)
return type === '[object Array]' || type === '[object Object]'
}
const _isObject = (o) => {
return (typeof o === 'object' || typeof o === 'function') && o !== null
}
const deepClone = (obj) => {
if (!isObject(obj)) {
return obj
}
let isArray = Array.isArray(obj)
let cloneObj = isArray ? [] : {}
for (let key in obj) {
cloneObj[key] = _isObject(obj[key]) ? deepClone(obj[key]) : obj[key]
}
return cloneObj
}
// const getObjValue = (obj, keys) => {
// return keys.reduce((res, n) => (res !== undefined && res[n] !== undefined ? res[n] : null), obj)
// }
/**
* transfer function into promise
*/
const funcToPromise = (fn, receiver) => {
return (...args) => {
return new Promise((resolve, reject) => {
fn.apply(receiver, [...args, (err, res) => {
return err ? reject(err) : resolve(res)
}])
})
}
}
export {
getScrollParent,
deepClone,
funcToPromise
}

View File

@ -0,0 +1,9 @@
import darkstyleScheme from '../../_themes/darkStyleScheme.scss'
import lightstyleScheme from '../../_themes/lightStyleScheme.scss'
const styleScheme = {
dark: darkstyleScheme,
light: lightstyleScheme
}
export default styleScheme

View File

@ -0,0 +1,17 @@
export default function getVNodeComponentName (vNode) {
/**
* Functional component
*/
if (vNode.fnOptions && vNode.fnOptions.name) {
return vNode.fnOptions.name
}
if (
vNode.componentOptions &&
vNode.componentOptions.Ctor &&
vNode.componentOptions.Ctor.extendOptions &&
vNode.componentOptions.Ctor.extendOptions.name
) {
return vNode.componentOptions.Ctor.extendOptions.name
}
return null
}