Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

alaska-field-number

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alaska-field-number - npm Package Compare versions

Comparing version 0.11.22 to 0.12.0

50

index.js

@@ -1,16 +0,21 @@

// @flow
'use strict';
import { Field } from 'alaska';
import numeral from 'numeral';
Object.defineProperty(exports, "__esModule", {
value: true
});
export default class NumberField extends Field {
static plain = Number;
static dbOptions = ['min', 'max'];
static viewOptions = ['min', 'max', 'format', 'addonBefore', 'addonAfter', 'placeholder'];
static defaultOptions = {
cell: 'NumberFieldCell',
view: 'NumberFieldView',
filter: 'NumberFieldFilter',
};
var _alaska = require('alaska');
var _numeral = require('numeral');
var _numeral2 = _interopRequireDefault(_numeral);
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class NumberField extends _alaska.Field {
init() {

@@ -20,3 +25,3 @@ let field = this;

if (format) {
return numeral(this.get(field.path)).format(format);
return (0, _numeral2.default)(this.get(field.path)).format(format);
}

@@ -27,3 +32,3 @@ return this.get(field.path);

createFilter(filter: Object): any {
createFilter(filter) {
let value;

@@ -37,3 +42,3 @@ if (typeof filter === 'object') {

let v = parseFloat(value);
return isNaN(v) ? undefined : v;
return _lodash2.default.isNaN(v) ? undefined : v;
}

@@ -53,3 +58,3 @@

let end = parseFloat(bt[1]);
if (isNaN(start) || isNaN(end)) return null;
if (_lodash2.default.isNaN(start) || _lodash2.default.isNaN(end)) return null;
return { $gte: start, $lte: end };

@@ -59,7 +64,7 @@ }

//比较
['gt', 'gte', 'lt', 'lte'].forEach((key) => {
['gt', 'gte', 'lt', 'lte'].forEach(key => {
let val = filter[key] || filter['$' + key];
if (val === undefined) return;
val = parseFloat(val);
if (isNaN(val)) return;
if (_lodash2.default.isNaN(val)) return;
if (!value) {

@@ -78,1 +83,10 @@ value = {};

}
exports.default = NumberField;
NumberField.plain = Number;
NumberField.dbOptions = ['min', 'max'];
NumberField.viewOptions = ['min', 'max', 'format', 'addonBefore', 'addonAfter', 'placeholder'];
NumberField.defaultOptions = {
cell: 'NumberFieldCell',
view: 'NumberFieldView',
filter: 'NumberFieldFilter'
};
{
"name": "alaska-field-number",
"version": "0.11.22",
"version": "0.12.0",
"description": "Alaska number field",

@@ -9,5 +9,6 @@ "keywords": [

],
"alaska": "field",
"main": "index.js",
"scripts": {},
"repository": "https://github.com/maichong/alaska/tree/master/packages/alaska-field-number",
"repository": "https://github.com/maichong/alaska/tree/master/src/alaska-field-number",
"author": "Liang <liang@maichong.it> (https://github.com/liangxingchen)",

@@ -14,0 +15,0 @@ "license": "MIT",

@@ -8,5 +8,4 @@ // @flow

export default class NumberFieldCell extends React.Component {
shouldComponentUpdate(props: Object) {
export default class NumberFieldCell extends React.Component<Alaska$view$Field$Cell$Props> {
shouldComponentUpdate(props: Alaska$view$Field$Cell$Props) {
return props.value != this.props.value;

@@ -13,0 +12,0 @@ }

@@ -8,4 +8,10 @@ // @flow

export default class NumberFieldFilter extends React.Component {
type State = {
value1: any,
value2: any,
error: boolean,
mode: 1 | 2 | 3 | 4 | 5 | 6
};
export default class NumberFieldFilter extends React.Component<Alaska$view$Field$Filter$Props, State> {
static contextTypes = {

@@ -15,24 +21,10 @@ t: PropTypes.func,

props: {
className: string,
field: Object,
onChange: Function,
onClose: Function,
};
handleMode1: () => void;
handleMode2: () => void;
handleMode3: () => void;
handleMode4: () => void;
handleMode5: () => void;
handleMode6: () => void;
state: {
value1:any;
value2:any;
error:boolean;
mode: 1|2|3|4|5|6
};
handleMode1: ()=>void;
handleMode2: ()=>void;
handleMode3: ()=>void;
handleMode4: ()=>void;
handleMode5: ()=>void;
handleMode6: ()=>void;
constructor(props: Object) {
constructor(props: Alaska$view$Field$Filter$Props) {
super(props);

@@ -91,7 +83,7 @@ let value = props.value || {};

handleMode(mode: 1|2|3|4|5|6) {
handleMode(mode: 1 | 2 | 3 | 4 | 5 | 6) {
this.setState({ mode }, () => this.handleBlur());
}
handleChange1 = (event: ReactInputEvent) => {
handleChange1 = (event: SyntheticInputEvent<*>) => {
this.setState({

@@ -102,3 +94,3 @@ value1: event.target.value

handleChange2 = (event: ReactInputEvent) => {
handleChange2 = (event: SyntheticInputEvent<*>) => {
this.setState({

@@ -136,5 +128,7 @@ value2: event.target.value

render() {
const t = this.context.t;
const { t } = this.context;
let { className, field, onClose } = this.props;
const { mode, value1, value2, error } = this.state;
const {
mode, value1, value2, error
} = this.state;
const buttonClassName = 'btn btn-default';

@@ -161,19 +155,24 @@ const buttonClassNameActive = buttonClassName + ' btn-success';

onClick={this.handleMode1}
>=</a>
>=
</a>
<a
className={mode === 2 ? buttonClassNameActive : buttonClassName}
onClick={this.handleMode2}
>&gt;</a>
>&gt;
</a>
<a
className={mode === 3 ? buttonClassNameActive : buttonClassName}
onClick={this.handleMode3}
>&lt;</a>
>&lt;
</a>
<a
className={mode === 4 ? buttonClassNameActive : buttonClassName}
onClick={this.handleMode4}
>&gt;=</a>
>&gt;=
</a>
<a
className={mode === 5 ? buttonClassNameActive : buttonClassName}
onClick={this.handleMode5}
>&lt;=</a>
>&lt;=
</a>
<a

@@ -180,0 +179,0 @@ className={mode === 6 ? buttonClassNameActive : buttonClassName}

@@ -9,5 +9,9 @@ // @flow

import shallowEqualWithout from 'shallow-equal-without';
import _ from 'lodash';
export default class NumberFieldView extends React.Component {
type State = {
display: string
};
export default class NumberFieldView extends React.Component<Alaska$view$Field$View$Props, State> {
static contextTypes = {

@@ -17,25 +21,8 @@ t: PropTypes.func,

props: {
className: string,
value: any,
model: Object,
data: Object,
field: Object,
disabled: boolean,
errorText: string,
onChange: Function,
};
state: {
value: any;
display:string;
};
focused: boolean;
constructor(props: Object) {
constructor(props: Alaska$view$Field$View$Props) {
super(props);
this.state = {
display: props.value,
value: props.value
display: props.value
};

@@ -47,9 +34,5 @@ if (props.field.format) {

componentWillReceiveProps(nextProps: Object) {
componentWillReceiveProps(nextProps: Alaska$view$Field$View$Props) {
let newState = {};
if (typeof nextProps.value !== 'undefined' || typeof nextProps.field.default === 'undefined') {
newState.value = nextProps.value;
if (this.props.field.format) {
newState.value = numeral(nextProps.value).format(this.props.field.format);
}
if (this.focused) {

@@ -60,3 +43,3 @@ //正在输入

//不在输入状态
newState.display = newState.value;
newState.display = numeral(nextProps.value).format(this.props.field.format);
}

@@ -67,8 +50,8 @@ }

shouldComponentUpdate(props: Object, state: Object) {
return !shallowEqualWithout(props, this.props, 'data', 'onChange', 'model')
shouldComponentUpdate(props: Alaska$view$Field$View$Props, state: State) {
return !shallowEqualWithout(props, this.props, 'record', 'onChange', 'model')
|| !shallowEqualWithout(state, this.state);
}
handleChange = (event: ReactInputEvent) => {
handleChange = (event: SyntheticInputEvent<*>) => {
let display = event.target.value;

@@ -84,3 +67,3 @@ this.setState({ display });

this.focused = false;
let field = this.props.field;
const { field } = this.props;
let value = this.state.display;

@@ -90,3 +73,3 @@ let unfomarted;

unfomarted = numeral(value).value();
if (isNaN(unfomarted)) {
if (_.isNaN(unfomarted)) {
unfomarted = 0;

@@ -117,4 +100,4 @@ }

} = this.props;
const t = this.context.t;
let help = field.help;
const { t } = this.context;
let { help } = field;
className += ' number-field';

@@ -121,0 +104,0 @@ if (errorText) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc