Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(utils): extract the common methods in the dom.gloabl.type files to the untils package #2823

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/webdoc/faq-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ therefore, it can misjudge boundaries, leading to issues such as flipping and mi
**Solution:** Introducing 'popup global' configuration, assigning the 'window' of the main application to the 'viewportWindow' of the global configuration for boundary judgment

```js
import globalConfig from '@opentiny/vue-renderless/common/global'
import { global } from '@opentiny/utils'

// Determine if the app run in the sub application
if (window.__POWERED_BY_WUJIE__) {
// In sub applications, the window of the main application can be obtained through window. parent
globalConfig.viewportWindow = window.parent
global.globalConfig.viewportWindow = window.parent
}
```

Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/webdoc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
**解决方案:** 引入 `popup` 全局配置,将主应用的 `window` 赋值给全局配置的 `viewportWindow` 用于边界判断

```js
import globalConfig from '@opentiny/vue-renderless/common/global'
import { global } from '@opentiny/utils'

// 需要判断是否在子应用当中
if (window.__POWERED_BY_WUJIE__) {
// 子应用中可以通过 window.parent 获取主应用的 window
globalConfig.viewportWindow = window.parent
global.globalConfig.viewportWindow = window.parent
}
```

Expand Down
15 changes: 9 additions & 6 deletions packages/renderless/src/amount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
*
*/

import { on, off } from '../common/deps/dom'
import { dom, type as types } from '@opentiny/utils'
import { formatNumber } from '../common/decimal'
import { getMiniDecimal, equalsDecimal } from '../common/bigInt'
import { isNumber } from '../common/type'

export const initService = (service) => {
const { utils = {} } = service || {}
Expand Down Expand Up @@ -246,9 +245,9 @@ export const handelClick =

export const addOutSideEvent = (api) => (visible) => {
if (visible) {
on(document, 'click', api.handelClick)
dom.on(document, 'click', api.handelClick)
} else {
off(document, 'click', api.handelClick)
dom.off(document, 'click', api.handelClick)
}
}

Expand Down Expand Up @@ -325,12 +324,16 @@ export const getPrecision = ({ service, props, currency }) => {
zeroize: props.holdZero
}

fraction = isNumber(format.fraction) ? format.fraction : isNumber(serFra.fraction) ? serFra.fraction : digits
fraction = types.isNumber(format.fraction)
? format.fraction
: types.isNumber(serFra.fraction)
? serFra.fraction
: digits

if (r === false) {
rounding = 0
} else {
rounding = isNumber(rounding) ? rounding : isNumber(serFra.rounding) ? serFra.rounding : 5
rounding = types.isNumber(rounding) ? rounding : types.isNumber(serFra.rounding) ? serFra.rounding : 5
}

return { ...defaultFmt, fraction, rounding, ...serFmt, ...format }
Expand Down
8 changes: 4 additions & 4 deletions packages/renderless/src/anchor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
*/
import type { IAnchorRenderlessParams, IAnchorLinkItem } from '@/types'
import { addClass, removeClass } from '../common/deps/dom'
import { dom } from '@opentiny/utils'

const getEleMentBySelect = (parent, selector) =>
selector?.startsWith('#') ? document.getElementById(selector.slice(1)) : parent.querySelector(selector)
Expand All @@ -30,9 +30,9 @@ const setMarkClass = ({ state, props }: Pick<IAnchorRenderlessParams, 'state' |
const { markClass } = props
const activeContentEl = getEleMentBySelect(scrollContainer, `${state.currentLink}`)
if (markClass) {
addClass(activeContentEl, markClass)
dom.addClass(activeContentEl, markClass)
setTimeout(() => {
removeClass(activeContentEl, markClass)
dom.removeClass(activeContentEl, markClass)
}, 1000)
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ const updateSkidPosition = ({ vm, state, emit }: Pick<IAnchorRenderlessParams, '

const offsetTop = linkTitleClientTop - anchorClientTop
const offsetLeft = linkTitleClientLeft - anchorClientLeft
addClass(skidRef, 'tiny-anchor-orbit-skid--active')
dom.addClass(skidRef, 'tiny-anchor-orbit-skid--active')
skidRef.style.transform = `translateY(${offsetTop}px)`
skidRef.style.height = `${offsetHeight}px`
if (maskRef) {
Expand Down
9 changes: 4 additions & 5 deletions packages/renderless/src/base-select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import PopupManager from '../common/deps/popup-manager'
import debounce from '../common/deps/debounce'
import { getDataset } from '../common/dataset'
import Memorize from '../common/deps/memorize'
import { isEmptyObject } from '../common/type'
import { type } from '@opentiny/utils'
import { addResizeListener, removeResizeListener } from '../common/deps/resize-event'
import { extend } from '../common/object'
import { BROWSER_NAME } from '../common'
import browserInfo from '../common/browser'
import { isNull } from '../common/type'
import { fastdom } from '../common/deps/fastdom'
import { deepClone } from '../picker-column'
import { escapeRegexpString } from '../option'
Expand Down Expand Up @@ -216,7 +215,7 @@ export const getOption =
if (option) {
return option
}
} else if (!isEmptyObject(state.selected)) {
} else if (!type.isEmptyObject(state.selected)) {
return state.selected
}

Expand Down Expand Up @@ -249,7 +248,7 @@ export const getSelectedOption =
if (props.multiple) {
option = state.selected.find((v) => getObj(v, props.valueKey) === value)
} else {
if (!isEmptyObject(state.selected) && getObj(state.selected, props.valueKey) === value) {
if (!type.isEmptyObject(state.selected) && getObj(state.selected, props.valueKey) === value) {
option = state.selected
}
}
Expand Down Expand Up @@ -1806,7 +1805,7 @@ export const computedShowClose =
(state.inputHovering || (props.multiple && state.visible)) &&
(props.multiple
? Array.isArray(props.modelValue) && props.modelValue.length > 0
: !isNull(props.modelValue) && props.modelValue !== '')
: !type.isNull(props.modelValue) && props.modelValue !== '')

// tiny 新增: aui有自己的逻辑,移至defineConfig中去了
export const computedCollapseTagSize = (state) => () => state.selectSize
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/base-select/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import {
isTagClosable
} from './index'
import debounce from '../common/deps/debounce'
import { isNumber } from '../common/type'
import { type } from '@opentiny/utils'

export const api = [
'state',
Expand Down Expand Up @@ -265,7 +265,7 @@ const initStateAdd = ({ computed, props, api, parent }) => {
currentKey: props.modelValue,
updateId: '',
popperElm: null,
debounce: computed(() => (isNumber(props.queryDebounce) ? props.queryDebounce : props.remote ? 300 : 0)),
debounce: computed(() => (type.isNumber(props.queryDebounce) ? props.queryDebounce : props.remote ? 300 : 0)),
emptyText: computed(() => api.emptyText()),
emptyFlag: computed(() => api.emptyFlag()),
formItemSize: computed(() => (parent.formItem || { state: {} }).state.formItemSize),
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNull } from '../common/type'
import { type } from '@opentiny/utils'

export const handelIconClick =
({ emit }) =>
Expand Down Expand Up @@ -73,7 +73,7 @@ export const getModel =
const model = state.isGroup ? state.store : props.modelValue !== undefined ? props.modelValue : state.selfModel

if (state.isCheckbox) {
return isNull(model) ? [] : model
return type.isNull(model) ? [] : model
} else {
return state.store
}
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/cascader-panel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
*/

import { isNull } from '../common/type'
import { type } from '@opentiny/utils'
import { isEqual } from '../common/object'
import { isEmpty } from '../cascader'
import { KEY_CODE, CASCADER } from '../common'
Expand Down Expand Up @@ -90,7 +90,7 @@ export const syncActivePath =
.map((node) => api.getNodeByValue(node.getValue()))
.filter((node) => node) as ICascaderPanelNode[]

if (isNull(nodes[0])) {
if (type.isNull(nodes[0])) {
state.activePath = []
} else {
api.expandNodes(nodes)
Expand Down
4 changes: 2 additions & 2 deletions packages/renderless/src/cascader-panel/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {

import { isEqual } from '../common/object'
import { capitalize } from '../common/string'
import { isNull } from '../common/type'
import { type } from '@opentiny/utils'

let uid = 0

Expand Down Expand Up @@ -80,7 +80,7 @@ export default class Node {

if (lazy) {
const leafValue = data[leaf]
const isLeaf = !isNull(leafValue) ? leafValue : loaded ? !children.length : false
const isLeaf = !type.isNull(leafValue) ? leafValue : loaded ? !children.length : false

this.hasChildren = !isLeaf

Expand Down
8 changes: 4 additions & 4 deletions packages/renderless/src/cascader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import browser, { isBrowser } from '../common/browser'
import { isNull } from '../common/type'
import { type as types } from '@opentiny/utils'
import debounce from '../common/deps/debounce'
import { isEqual } from '../common/object'
import { addResizeListener } from '../common/deps/resize-event'
Expand Down Expand Up @@ -48,7 +48,7 @@ export const getConfig =
const { newProp, type } = migratingProps[oldProp]
let oldValue = $attrs[oldProp] || $attrs[kebabCase(oldProp)]

if (isNull(config[newProp]) && !isNull(oldProp)) {
if (types.isNull(config[newProp]) && !types.isNull(oldProp)) {
if (oldValue === '' && type === Boolean) {
oldValue = true
}
Expand Down Expand Up @@ -129,7 +129,7 @@ export const watchCheckedValue =
}

export const isEmpty = (val) => {
if (isNull(val)) {
if (types.isNull(val)) {
return true
}
if (typeof val === 'boolean') {
Expand Down Expand Up @@ -226,7 +226,7 @@ export const toggleDropDownVisible =

const { input } = vm.$refs

visible = !isNull(visible) ? visible : !state.dropDownVisible
visible = !types.isNull(visible) ? visible : !state.dropDownVisible
if (visible !== state.dropDownVisible) {
state.dropDownVisible = visible
if (visible) {
Expand Down
16 changes: 8 additions & 8 deletions packages/renderless/src/chart-bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { getFormated, getStackMap, get, set, cloneDeep } from '../chart-core/deps/utils'
import { itemPoint, itemLabel, itemContent } from '../chart-core/deps/constants'
import { isNull } from '../common/type'
import { type } from '@opentiny/utils'

// default opacity of bar while dim-axis type is 'value'
const VALUE_AXIS_OPACITY = 0.5
Expand Down Expand Up @@ -134,7 +134,7 @@ const getBarSeries = (args) => {
innerRows.forEach((row) => metrics.forEach((item) => seriesTemp[item].push(row[item])))

series = Object.keys(seriesTemp).map((item) => {
let name = !isNull(labelMap[item]) ? labelMap[item] : item
let name = !type.isNull(labelMap[item]) ? labelMap[item] : item
wuyiping0628 marked this conversation as resolved.
Show resolved Hide resolved
let type = ~showLine.indexOf(item) ? 'line' : 'bar'
let data = dimAxisType === 'value' ? getValueData(seriesTemp[item], dims) : seriesTemp[item]
let axisIndex = ~secondAxis.indexOf(item) ? '1' : '0'
Expand All @@ -155,10 +155,10 @@ const getBarSeries = (args) => {

if (Object.keys(stack).length) {
// 堆叠图
if (stackNum === Object.keys(stackMap).length - 1 || isNull(seriesItem.stack)) {
if (stackNum === Object.keys(stackMap).length - 1 || type.isNull(seriesItem.stack)) {
seriesItem.itemStyle = Object.assign(defaultItemStyle, seriesItem.itemStyle)
}
if (!isNull(seriesItem.stack)) {
if (!type.isNull(seriesItem.stack)) {
stackNum++
}

Expand All @@ -175,9 +175,9 @@ const getBarSeries = (args) => {
let itemOpacity = opacity || get(seriesItem, 'itemStyle.opacity')

dimAxisType === 'value' && Object.assign(seriesItem, { barGap, barCategoryGap: '1%' })
dimAxisType === 'value' && isNull(itemOpacity) && (itemOpacity = VALUE_AXIS_OPACITY)
dimAxisType === 'value' && type.isNull(itemOpacity) && (itemOpacity = VALUE_AXIS_OPACITY)

!isNull(itemOpacity) && set(seriesItem, 'itemStyle.opacity', itemOpacity)
!type.isNull(itemOpacity) && set(seriesItem, 'itemStyle.opacity', itemOpacity)

return seriesItem
})
Expand All @@ -192,12 +192,12 @@ const getLegend = (args) => {
return { data: metrics }
}

const data = labelMap ? metrics.map((item) => (isNull(labelMap[item]) ? item : labelMap[item])) : metrics
const data = labelMap ? metrics.map((item) => (type.isNull(labelMap[item]) ? item : labelMap[item])) : metrics

return {
data,
formatter(name) {
return !isNull(legendName[name]) ? legendName[name] : name
return !type.isNull(legendName[name]) ? legendName[name] : name
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/renderless/src/chart-candle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import { getFormated } from '../chart-core/deps/utils'
import { itemPoint, itemLabel, itemContent } from '../chart-core/deps/constants'
import { isNull } from '../common/type'
import { type } from '@opentiny/utils'
wuyiping0628 marked this conversation as resolved.
Show resolved Hide resolved

const DEF_MA = [5, 10, 20, 30]
const DEF_DOWN_COLOR = '#eb171f'
Expand All @@ -27,10 +27,10 @@ const getCandleLegend = (args) => {
let data = [defaultKName]

showMA && (data = data.concat(MA.map((v) => `MA${v}`)))
labelMap && (data = data.map((v) => (isNull(labelMap[v]) ? v : labelMap[v])))
labelMap && (data = data.map((v) => (type.isNull(labelMap[v]) ? v : labelMap[v])))

function formatter(name) {
return isNull(legendName[name]) ? name : legendName[name]
return type.isNull(legendName[name]) ? name : legendName[name]
}

return { data, formatter }
Expand All @@ -56,15 +56,15 @@ const getCandleTooltip = (args) => {
options.forEach((opt) => {
const { color, componentSubType, data, seriesName } = opt

const name = isNull(labelMap[seriesName]) ? seriesName : labelMap[seriesName]
const name = type.isNull(labelMap[seriesName]) ? seriesName : labelMap[seriesName]

tplt.push(`${itemPoint(color)}${itemContent(name)}: `)

if (componentSubType === 'candlestick') {
tplt.push('<br>')

metrics.slice(0, 4).forEach((m, i) => {
const name = isNull(labelMap[m]) ? m : labelMap[m]
const name = type.isNull(labelMap[m]) ? m : labelMap[m]
const value = getFormated(data[i + 1], dataType, digit)

tplt.push(`${itemLabel(`- ${name}`)}${itemContent(value)}<br>`)
Expand Down Expand Up @@ -162,13 +162,13 @@ const getCandleSeries = (args) => {
const { MA, digit, downColor, itemStyle, labelMap, showMA, showVol, upColor, values, volumes } = args
const style = itemStyle || { color: upColor, color0: downColor, borderColor: null, borderColor0: null }
const lineStyle = { opacity: 0.5 }
const name = isNull(labelMap[defaultKName]) ? defaultKName : labelMap[defaultKName]
const name = type.isNull(labelMap[defaultKName]) ? defaultKName : labelMap[defaultKName]
const series = [{ name, data: values, type: 'candlestick', itemStyle: style }]

if (showMA) {
MA.forEach((d) => {
const key = `MA${d}`
const serieName = isNull(labelMap[key]) ? key : labelMap[key]
const serieName = type.isNull(labelMap[key]) ? key : labelMap[key]
const serieData = calculateMA(d, values, digit)

series.push({ name: serieName, data: serieData, type: 'line', lineStyle, smooth: true })
Expand Down
Loading
Loading