mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-13 13:59:04 +08:00
refactor: rename some util scripts
This commit is contained in:
parent
d9d2c51e65
commit
a8d4f4a486
@ -82,7 +82,7 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
show (value) {
|
||||
if (value) this.$emit('shohw')
|
||||
if (value) this.$emit('show')
|
||||
return this.$emit('hide')
|
||||
}
|
||||
},
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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',
|
||||
|
@ -8,7 +8,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import render from '../../../_utils/render'
|
||||
import render from '../../../_utils/vue/render'
|
||||
|
||||
export default {
|
||||
name: 'NDataTableCell',
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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'
|
||||
|
@ -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 {
|
||||
|
@ -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],
|
||||
|
@ -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 {
|
||||
|
@ -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',
|
||||
|
@ -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')
|
||||
|
@ -38,7 +38,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import render from '../../_utils/render'
|
||||
import render from '../../_utils/vue/render'
|
||||
|
||||
export default {
|
||||
name: 'NMenuItemContent',
|
||||
|
@ -9,7 +9,7 @@
|
||||
</li>
|
||||
</template>
|
||||
<script>
|
||||
import render from '../../_utils/render'
|
||||
import render from '../../_utils/vue/render'
|
||||
|
||||
export default {
|
||||
name: 'NMenuItemGroup',
|
||||
|
@ -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
|
||||
|
@ -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: {
|
||||
|
@ -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
|
||||
|
@ -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: {
|
||||
|
@ -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
|
||||
|
@ -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 = {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import createValidator from '../../_utils/validateProp'
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
|
||||
export default {
|
||||
props: {
|
||||
|
@ -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',
|
||||
|
@ -21,7 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import createValidator from '../../_utils/validateProp'
|
||||
import createValidator from '../../_utils/vue/validateProp'
|
||||
|
||||
export default {
|
||||
name: 'NTransferHeaderExtra',
|
||||
|
@ -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',
|
||||
|
@ -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',
|
||||
|
@ -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,
|
||||
|
@ -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
|
@ -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
|
||||
}
|
33
src/_utils/deprecated/vNodeUtils.js
Normal file
33
src/_utils/deprecated/vNodeUtils.js
Normal 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
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
export default function genId () {
|
||||
return Math.random()
|
||||
.toString(36)
|
||||
.slice(2)
|
||||
}
|
@ -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
|
||||
}
|
9
src/_utils/naive/styleScheme.js
Normal file
9
src/_utils/naive/styleScheme.js
Normal 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
|
17
src/_utils/vue/getVNodeComponentName.js
Normal file
17
src/_utils/vue/getVNodeComponentName.js
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user