修改 utils 文件路径

This commit is contained in:
yangchch6 2019-07-26 09:47:18 +08:00
parent acf9eb2ddb
commit 71021bd479
15 changed files with 329 additions and 341 deletions

View File

@ -26,7 +26,7 @@ var _TableHeader = require('./TableHeader');
var _TableHeader2 = _interopRequireDefault(_TableHeader);
var _utils = require('./utils');
var _utils = require('./lib/utils');
var _shallowequal = require('shallowequal');

View File

@ -20,7 +20,7 @@ var _propTypes2 = _interopRequireDefault(_propTypes);
var _throttleDebounce = require("throttle-debounce");
var _utils = require("./utils");
var _utils = require("./lib/utils");
var _FilterType = require("./FilterType");

View File

@ -12,7 +12,7 @@ var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _utils = require('./utils');
var _utils = require('./lib/utils');
var _TableCell = require('./TableCell');

View File

@ -12,7 +12,7 @@ var _react = require("react");
var _react2 = _interopRequireDefault(_react);
var _utils = require("../utils");
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

View File

@ -155,9 +155,9 @@ function removeClass(elm, className) {
});
}
/**
* 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象
/**
* 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象
*/
function ObjectAssign(obj) {
var b = obj instanceof Array;
@ -174,8 +174,8 @@ function ObjectAssign(obj) {
}
return tagObj;
}
/**
* 获取某个父元素
/**
* 获取某个父元素
* */
function closest(ele, selector) {
@ -289,8 +289,8 @@ var EventUtil = exports.EventUtil = {
}
}
/*
* 处理精度
/*
* 处理精度
*/
};function DicimalFormater(value, precision) {
var value = value + '',

View File

@ -47,10 +47,6 @@ const data23 = [
const DragColumnTable = dragColumn(Table);
const defaultProps23 = {
prefixCls: "bee-table"
};
class Demo23 extends Component {
constructor(props) {
super(props);
@ -69,7 +65,5 @@ class Demo23 extends Component {
/>;
}
}
Demo23.defaultProps = defaultProps23;
export default Demo23;

File diff suppressed because one or more lines are too long

22
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "2.1.7-beta.4",
"version": "2.1.7-beta.5",
"description": "Table ui component for react",
"keywords": [
"react",

View File

@ -3,14 +3,14 @@ import PropTypes from 'prop-types';
import classes from 'component-classes';
import TableRow from './TableRow';
import TableHeader from './TableHeader';
import { measureScrollbar, debounce, warningOnce ,getMaxColChildrenLength} from './utils';
import { measureScrollbar, debounce, warningOnce ,getMaxColChildrenLength} from './lib/utils';
import shallowequal from 'shallowequal';
import addEventListener from 'tinper-bee-core/lib/addEventListener';
import ColumnManager from './ColumnManager';
import createStore from './createStore';
import Loading from 'bee-loading';
import Icon from 'bee-icon';
import { Event,EventUtil,closest} from "./utils";
import { Event,EventUtil,closest} from "./lib/utils";
import i18n from "./lib/i18n";
import { getComponentLocale } from "bee-locale/build/tool";

View File

@ -2,7 +2,7 @@ import React, { Component } from "react";
import ReactDOM from 'react-dom';
import PropTypes from "prop-types";
import { debounce } from "throttle-debounce";
import { Event,EventUtil} from "./utils";
import { Event,EventUtil} from "./lib/utils";
import FilterType from "./FilterType";
const propTypes = {

View File

@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Event,EventUtil} from "./utils";
import { Event,EventUtil} from "./lib/utils";
import TableCell from './TableCell';
import ExpandIcon from './ExpandIcon';

View File

@ -1,6 +1,6 @@
import React from "react";
import {DicimalFormater} from "../utils";
import {DicimalFormater} from "./utils";
export default function sum(Table) {
return class SumTable extends React.Component {
//无状态

View File

@ -1,303 +1,303 @@
import warning from 'warning';
import parseInt from 'lodash/parseInt';
let scrollbarSize;
// Measure scrollbar width for padding body during modal show/hide
const scrollbarMeasure = {
position: 'absolute',
top: '-9999px',
width: '50px',
height: '50px',
overflow: 'scroll',
};
export function measureScrollbar(direction = 'vertical') {
if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0;
}
const tableDom =document.querySelector('.u-table');
let currentDom = tableDom?tableDom:document.body;
if (scrollbarSize) {
return scrollbarSize;
}
const scrollDiv = document.createElement('div');
Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
});
currentDom.appendChild(scrollDiv);
let size = 0;
if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
}
currentDom.removeChild(scrollDiv);
scrollbarSize = size;
return scrollbarSize;
}
export function debounce(func, wait, immediate) {
let timeout;
return function debounceFunc() {
const context = this;
const args = arguments;
// https://fb.me/react-event-pooling
if (args[0] && args[0].persist) {
args[0].persist();
}
const later = () => {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}
const warned = {};
export function warningOnce(condition, format, args) {
if (!warned[format]) {
warning(condition, format, args);
warned[format] = true;
}
}
export function getOffset (Node, offset ) {
if(!offset) {
offset = {};
offset.top = 0;
offset.left = 0;
}
if(Node == document.body) {
return offset;
}
offset.top += Node.offsetTop;
offset.left += Node.offsetLeft;
if(Node.offsetParent)
return getOffset(Node.offsetParent, offset);
else
return offset;
};
export const tryParseInt = (value, defaultValue = 0) => {
const resultValue = parseInt(value);
if (isNaN(resultValue)) {
return defaultValue;
}
return resultValue;
};
export function addClass(elm, className) {
if (!className) return;
const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => {
if (el.classList) {
el.classList.add(className.split(' '));
} else {
el.className += ` ${className}`;
}
});
}
export function removeClass(elm, className) {
if (!className) return;
const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => {
if (el.classList) {
el.classList.remove(className.split(' '));
} else {
el.className = el.className.replace(new RegExp(`(^|\\b)${className.split(' ').join('|')}(\\b|$)`, 'gi'), ' ');
}
});
}
/**
* 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象
*/
export function ObjectAssign(obj){
let b = obj instanceof Array;
let tagObj = b?[]:{};
if(b){//数组
obj.forEach(da => {
let _da = {};
Object.assign(_da,da);
tagObj.push(_da);
});
}else{
Object.assign(tagObj,obj);
}
return tagObj;
}
/**
* 获取某个父元素
* */
export function closest(ele, selector) {
const matches = ele.matches || ele.webkitMatchesSelector || ele.mozMatchesSelector || ele.msMatchesSelector;
if (matches) {
while (ele) {
if (matches.call(ele, selector)) {
return ele;
} else {
ele = ele.parentElement;
}
}
}
return null;
}
export function getMaxColChildrenLength(columns){
let arr=[];
arr = columns.map((item,index)=>{
let chilrenLen = 0;
if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1)
}
return chilrenLen
})
var max = Math.max.apply(null,arr);
return max;
}
export function getColChildrenLength(columns,chilrenLen){
columns.forEach((item,index)=>{
if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1);
}
})
return chilrenLen;
}
function addHandler(element,type,handler){
let event = null;
if(element.addEventListener){//检测是否为DOM2级方法
event = element.addEventListener(type, handler, false);
}else if (element.attachEvent){//检测是否为IE级方法
event = element.attachEvent("on" + type, handler);
} else {//检测是否为DOM0级方法
event = element["on" + type] = handler;
}
return event;
}
function removeHandler(element, type, handler){
if (element&&element.removeEventListener){//element&& ie11报错兼容
element.removeEventListener(type, handler, false);
} else if (element&&element.detachEvent){
element.detachEvent("on" + type, handler);
} else if(element) {
element["on" + type] = null;
}
}
//获取事件对象的兼容性写法
function getEvent(event){
return event ? event : window.event;
}
//获取事件对象目标的兼容性写法
function getTarget(event){
return event.target || event.srcElement;
}
function preventDefault(event){
if (event.preventDefault){
event.preventDefault();
} else {
event.returnValue = false;
}
}
function stopPropagation(event){
if (event.stopPropagation){
event.stopPropagation();
} else {
event.cancelBubble = true;
}
}
//用事件冒泡方式如果想兼容事件捕获只需要添加个bool参数
export const EventUtil = {
addHandler: function(element,type,handler) {
if (element.addEventListener) {
element.addEventListener(type,handler,false);
}
else if (element.attachEvent) {
element.attachEvent('on'+type,handler);
}
else {
element['on'+type] = handler;
}
},
removeHandler: function(element,type,handler) {//element&& ie11报错兼容
if (element&&element.removeEventListener)
{
element.removeEventListener(type,handler,false);
}
else if(element&&element.detachEvent) {
element.detachEvent('on' +type,handler);
}
else if(element){
element['on'+type] = null;
}
}
}
/*
* 处理精度
*/
export function DicimalFormater(value,precision) {
var value = value + '',
precision = precision?precision:0;
for (var i = 0; i < value.length; i++) {
if ("-0123456789.".indexOf(value.charAt(i)) == -1)
return "";
}
return checkDicimalInvalid(value, precision);
};
export function checkDicimalInvalid(value, precision) {
if (value == null || isNaN(value))
return "";
// 浮点数总位数不能超过10位
var digit = parseFloat(value);
var result = (digit * Math.pow(10, precision) / Math.pow(10, precision))
.toFixed(precision);
if (result == "NaN")
return "";
return result;
};
export const Event = {
addHandler,
removeHandler,
getEvent,
getTarget,
preventDefault,
stopPropagation
import warning from 'warning';
import parseInt from 'lodash/parseInt';
let scrollbarSize;
// Measure scrollbar width for padding body during modal show/hide
const scrollbarMeasure = {
position: 'absolute',
top: '-9999px',
width: '50px',
height: '50px',
overflow: 'scroll',
};
export function measureScrollbar(direction = 'vertical') {
if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0;
}
const tableDom =document.querySelector('.u-table');
let currentDom = tableDom?tableDom:document.body;
if (scrollbarSize) {
return scrollbarSize;
}
const scrollDiv = document.createElement('div');
Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp];
});
currentDom.appendChild(scrollDiv);
let size = 0;
if (direction === 'vertical') {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
} else if (direction === 'horizontal') {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight;
}
currentDom.removeChild(scrollDiv);
scrollbarSize = size;
return scrollbarSize;
}
export function debounce(func, wait, immediate) {
let timeout;
return function debounceFunc() {
const context = this;
const args = arguments;
// https://fb.me/react-event-pooling
if (args[0] && args[0].persist) {
args[0].persist();
}
const later = () => {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}
const warned = {};
export function warningOnce(condition, format, args) {
if (!warned[format]) {
warning(condition, format, args);
warned[format] = true;
}
}
export function getOffset (Node, offset ) {
if(!offset) {
offset = {};
offset.top = 0;
offset.left = 0;
}
if(Node == document.body) {
return offset;
}
offset.top += Node.offsetTop;
offset.left += Node.offsetLeft;
if(Node.offsetParent)
return getOffset(Node.offsetParent, offset);
else
return offset;
};
export const tryParseInt = (value, defaultValue = 0) => {
const resultValue = parseInt(value);
if (isNaN(resultValue)) {
return defaultValue;
}
return resultValue;
};
export function addClass(elm, className) {
if (!className) return;
const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => {
if (el.classList) {
el.classList.add(className.split(' '));
} else {
el.className += ` ${className}`;
}
});
}
export function removeClass(elm, className) {
if (!className) return;
const els = Array.isArray(elm) ? elm : [elm];
els.forEach((el) => {
if (el.classList) {
el.classList.remove(className.split(' '));
} else {
el.className = el.className.replace(new RegExp(`(^|\\b)${className.split(' ').join('|')}(\\b|$)`, 'gi'), ' ');
}
});
}
/**
* 简单数组数据对象拷贝
* @param {*} obj 要拷贝的对象
*/
export function ObjectAssign(obj){
let b = obj instanceof Array;
let tagObj = b?[]:{};
if(b){//数组
obj.forEach(da => {
let _da = {};
Object.assign(_da,da);
tagObj.push(_da);
});
}else{
Object.assign(tagObj,obj);
}
return tagObj;
}
/**
* 获取某个父元素
* */
export function closest(ele, selector) {
const matches = ele.matches || ele.webkitMatchesSelector || ele.mozMatchesSelector || ele.msMatchesSelector;
if (matches) {
while (ele) {
if (matches.call(ele, selector)) {
return ele;
} else {
ele = ele.parentElement;
}
}
}
return null;
}
export function getMaxColChildrenLength(columns){
let arr=[];
arr = columns.map((item,index)=>{
let chilrenLen = 0;
if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1)
}
return chilrenLen
})
var max = Math.max.apply(null,arr);
return max;
}
export function getColChildrenLength(columns,chilrenLen){
columns.forEach((item,index)=>{
if(item.children){
chilrenLen = getColChildrenLength(item.children,chilrenLen+1);
}
})
return chilrenLen;
}
function addHandler(element,type,handler){
let event = null;
if(element.addEventListener){//检测是否为DOM2级方法
event = element.addEventListener(type, handler, false);
}else if (element.attachEvent){//检测是否为IE级方法
event = element.attachEvent("on" + type, handler);
} else {//检测是否为DOM0级方法
event = element["on" + type] = handler;
}
return event;
}
function removeHandler(element, type, handler){
if (element&&element.removeEventListener){//element&& ie11报错兼容
element.removeEventListener(type, handler, false);
} else if (element&&element.detachEvent){
element.detachEvent("on" + type, handler);
} else if(element) {
element["on" + type] = null;
}
}
//获取事件对象的兼容性写法
function getEvent(event){
return event ? event : window.event;
}
//获取事件对象目标的兼容性写法
function getTarget(event){
return event.target || event.srcElement;
}
function preventDefault(event){
if (event.preventDefault){
event.preventDefault();
} else {
event.returnValue = false;
}
}
function stopPropagation(event){
if (event.stopPropagation){
event.stopPropagation();
} else {
event.cancelBubble = true;
}
}
//用事件冒泡方式如果想兼容事件捕获只需要添加个bool参数
export const EventUtil = {
addHandler: function(element,type,handler) {
if (element.addEventListener) {
element.addEventListener(type,handler,false);
}
else if (element.attachEvent) {
element.attachEvent('on'+type,handler);
}
else {
element['on'+type] = handler;
}
},
removeHandler: function(element,type,handler) {//element&& ie11报错兼容
if (element&&element.removeEventListener)
{
element.removeEventListener(type,handler,false);
}
else if(element&&element.detachEvent) {
element.detachEvent('on' +type,handler);
}
else if(element){
element['on'+type] = null;
}
}
}
/*
* 处理精度
*/
export function DicimalFormater(value,precision) {
var value = value + '',
precision = precision?precision:0;
for (var i = 0; i < value.length; i++) {
if ("-0123456789.".indexOf(value.charAt(i)) == -1)
return "";
}
return checkDicimalInvalid(value, precision);
};
export function checkDicimalInvalid(value, precision) {
if (value == null || isNaN(value))
return "";
// 浮点数总位数不能超过10位
var digit = parseFloat(value);
var result = (digit * Math.pow(10, precision) / Math.pow(10, precision))
.toFixed(precision);
if (result == "NaN")
return "";
return result;
};
export const Event = {
addHandler,
removeHandler,
getEvent,
getTarget,
preventDefault,
stopPropagation
}