|
|
@ -5,20 +5,12 @@ export const isDef = value => typeof value !== 'undefined'; |
|
|
export const hasWin = () => typeof window !== 'undefined'; |
|
|
export const hasWin = () => typeof window !== 'undefined'; |
|
|
|
|
|
|
|
|
export const getGlobal = () => |
|
|
export const getGlobal = () => |
|
|
typeof globalThis !== 'undefined' |
|
|
typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : global; |
|
|
? globalThis |
|
|
|
|
|
: typeof window !== 'undefined' |
|
|
|
|
|
? window |
|
|
|
|
|
: global; |
|
|
|
|
|
|
|
|
|
|
|
export const toLowerCase = str => (str || '').toLowerCase(); |
|
|
export const toLowerCase = str => (str || '').toLowerCase(); |
|
|
|
|
|
|
|
|
const elProt = hasWin() ? window.Element.prototype : {}; |
|
|
const elProt = hasWin() ? window.Element.prototype : {}; |
|
|
const matches = |
|
|
const matches = elProt.matches || elProt.webkitMatchesSelector || elProt.mozMatchesSelector || elProt.msMatchesSelector; |
|
|
elProt.matches || |
|
|
|
|
|
elProt.webkitMatchesSelector || |
|
|
|
|
|
elProt.mozMatchesSelector || |
|
|
|
|
|
elProt.msMatchesSelector; |
|
|
|
|
|
|
|
|
|
|
|
export const getUiClass = (em, defCls) => { |
|
|
export const getUiClass = (em, defCls) => { |
|
|
const { stylePrefix, customUI } = em.getConfig(); |
|
|
const { stylePrefix, customUI } = em.getConfig(); |
|
|
@ -35,10 +27,7 @@ const appendStyles = (styles, opts = {}) => { |
|
|
if (stls.length) { |
|
|
if (stls.length) { |
|
|
const href = stls.shift(); |
|
|
const href = stls.shift(); |
|
|
|
|
|
|
|
|
if ( |
|
|
if (href && (!opts.unique || !document.querySelector(`link[href="${href}"]`))) { |
|
|
href && |
|
|
|
|
|
(!opts.unique || !document.querySelector(`link[href="${href}"]`)) |
|
|
|
|
|
) { |
|
|
|
|
|
const { head } = document; |
|
|
const { head } = document; |
|
|
const link = document.createElement('link'); |
|
|
const link = document.createElement('link'); |
|
|
link.href = href; |
|
|
link.href = href; |
|
|
@ -121,8 +110,7 @@ const getUnitFromValue = value => { |
|
|
const upFirst = value => value[0].toUpperCase() + value.toLowerCase().slice(1); |
|
|
const upFirst = value => value[0].toUpperCase() + value.toLowerCase().slice(1); |
|
|
|
|
|
|
|
|
const camelCase = value => { |
|
|
const camelCase = value => { |
|
|
const values = value.split('-').filter(String); |
|
|
return value.replace(/-./g, x => x[1].toUpperCase()); |
|
|
return values[0].toLowerCase() + values.slice(1).map(upFirst); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const normalizeFloat = (value, step = 1, valueDef = 0) => { |
|
|
const normalizeFloat = (value, step = 1, valueDef = 0) => { |
|
|
@ -139,10 +127,7 @@ const normalizeFloat = (value, step = 1, valueDef = 0) => { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const hasDnd = em => { |
|
|
const hasDnd = em => { |
|
|
return ( |
|
|
return 'draggable' in document.createElement('i') && (em ? em.get('Config').nativeDnD : 1); |
|
|
'draggable' in document.createElement('i') && |
|
|
|
|
|
(em ? em.get('Config').nativeDnD : 1) |
|
|
|
|
|
); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -211,7 +196,7 @@ const getElRect = el => { |
|
|
top: 0, |
|
|
top: 0, |
|
|
left: 0, |
|
|
left: 0, |
|
|
width: 0, |
|
|
width: 0, |
|
|
height: 0 |
|
|
height: 0, |
|
|
}; |
|
|
}; |
|
|
if (!el) return def; |
|
|
if (!el) return def; |
|
|
let rectText; |
|
|
let rectText; |
|
|
@ -223,9 +208,7 @@ const getElRect = el => { |
|
|
range.detach(); |
|
|
range.detach(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ( |
|
|
return rectText || (el.getBoundingClientRect ? el.getBoundingClientRect() : def); |
|
|
rectText || (el.getBoundingClientRect ? el.getBoundingClientRect() : def) |
|
|
|
|
|
); |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -233,8 +216,7 @@ const getElRect = el => { |
|
|
* @param {Event} ev |
|
|
* @param {Event} ev |
|
|
* @return {Event} |
|
|
* @return {Event} |
|
|
*/ |
|
|
*/ |
|
|
const getPointerEvent = ev => |
|
|
const getPointerEvent = ev => (ev.touches && ev.touches[0] ? ev.touches[0] : ev); |
|
|
ev.touches && ev.touches[0] ? ev.touches[0] : ev; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Get cross-browser keycode |
|
|
* Get cross-browser keycode |
|
|
@ -245,8 +227,7 @@ const getKeyCode = ev => ev.which || ev.keyCode; |
|
|
const getKeyChar = ev => String.fromCharCode(getKeyCode(ev)); |
|
|
const getKeyChar = ev => String.fromCharCode(getKeyCode(ev)); |
|
|
const isEscKey = ev => getKeyCode(ev) === 27; |
|
|
const isEscKey = ev => getKeyCode(ev) === 27; |
|
|
const isEnterKey = ev => getKeyCode(ev) === 13; |
|
|
const isEnterKey = ev => getKeyCode(ev) === 13; |
|
|
const isObject = val => |
|
|
const isObject = val => val !== null && !Array.isArray(val) && typeof val === 'object'; |
|
|
val !== null && !Array.isArray(val) && typeof val === 'object'; |
|
|
|
|
|
const isEmptyObj = val => Object.keys(val).length <= 0; |
|
|
const isEmptyObj = val => Object.keys(val).length <= 0; |
|
|
|
|
|
|
|
|
const capitalize = str => str && str.charAt(0).toUpperCase() + str.substring(1); |
|
|
const capitalize = str => str && str.charAt(0).toUpperCase() + str.substring(1); |
|
|
@ -260,8 +241,7 @@ const setViewEl = (el, view) => { |
|
|
|
|
|
|
|
|
const createId = (length = 16) => { |
|
|
const createId = (length = 16) => { |
|
|
let result = ''; |
|
|
let result = ''; |
|
|
const chars = |
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
|
|
|
|
|
const len = chars.length; |
|
|
const len = chars.length; |
|
|
for (let i = 0; i < length; i++) { |
|
|
for (let i = 0; i < length; i++) { |
|
|
result += chars.charAt(Math.floor(Math.random() * len)); |
|
|
result += chars.charAt(Math.floor(Math.random() * len)); |
|
|
@ -296,5 +276,5 @@ export { |
|
|
isEmptyObj, |
|
|
isEmptyObj, |
|
|
isComponent, |
|
|
isComponent, |
|
|
createId, |
|
|
createId, |
|
|
isRule |
|
|
isRule, |
|
|
}; |
|
|
}; |
|
|
|