amis 1.5.6-beta.5 → 1.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/lib/components/Card.js +1 -1
  2. package/lib/components/Card.js.map +2 -2
  3. package/lib/components/Collapse.js +1 -1
  4. package/lib/components/Collapse.js.map +2 -2
  5. package/lib/components/Rating.d.ts +203 -73
  6. package/lib/components/Rating.js +147 -31
  7. package/lib/components/Rating.js.map +2 -2
  8. package/lib/components/icons.js +2 -0
  9. package/lib/components/icons.js.map +2 -2
  10. package/lib/icons/star.js +12 -0
  11. package/lib/index.js +1 -1
  12. package/lib/renderers/Form/InputRating.d.ts +37 -0
  13. package/lib/renderers/Form/InputRating.js +6 -2
  14. package/lib/renderers/Form/InputRating.js.map +2 -2
  15. package/lib/renderers/Json.js +7 -0
  16. package/lib/renderers/Json.js.map +2 -2
  17. package/lib/themes/ang-ie11.css +44 -10
  18. package/lib/themes/ang.css +44 -10
  19. package/lib/themes/ang.css.map +1 -1
  20. package/lib/themes/antd-ie11.css +44 -10
  21. package/lib/themes/antd.css +44 -10
  22. package/lib/themes/antd.css.map +1 -1
  23. package/lib/themes/cxd-ie11.css +45 -10
  24. package/lib/themes/cxd.css +45 -10
  25. package/lib/themes/cxd.css.map +1 -1
  26. package/lib/themes/dark-ie11.css +44 -10
  27. package/lib/themes/dark.css +44 -10
  28. package/lib/themes/dark.css.map +1 -1
  29. package/lib/themes/default.css +45 -10
  30. package/lib/themes/default.css.map +1 -1
  31. package/package.json +2 -2
  32. package/schema.json +59 -7
  33. package/scss/_properties.scss +3 -1
  34. package/scss/components/form/_rating.scss +60 -21
  35. package/scss/themes/_cxd-variables.scss +2 -0
  36. package/sdk/ang-ie11.css +47 -8
  37. package/sdk/ang.css +51 -10
  38. package/sdk/antd-ie11.css +47 -8
  39. package/sdk/antd.css +51 -10
  40. package/sdk/charts.js +13 -13
  41. package/sdk/codemirror.js +7 -7
  42. package/sdk/color-picker.js +65 -65
  43. package/sdk/cropperjs.js +2 -2
  44. package/sdk/cxd-ie11.css +47 -8
  45. package/sdk/cxd.css +52 -10
  46. package/sdk/dark-ie11.css +47 -8
  47. package/sdk/dark.css +51 -10
  48. package/sdk/exceljs.js +1 -1
  49. package/sdk/markdown.js +69 -69
  50. package/sdk/papaparse.js +1 -1
  51. package/sdk/renderers/Form/CityDB.js +1 -1
  52. package/sdk/rest.js +18 -18
  53. package/sdk/rich-text.js +62 -62
  54. package/sdk/sdk-ie11.css +47 -8
  55. package/sdk/sdk.css +52 -10
  56. package/sdk/sdk.js +1213 -1211
  57. package/sdk/thirds/hls.js/hls.js +1 -1
  58. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  59. package/sdk/tinymce.js +57 -57
  60. package/src/components/Card.tsx +2 -2
  61. package/src/components/Collapse.tsx +1 -1
  62. package/src/components/Rating.tsx +235 -47
  63. package/src/components/icons.tsx +2 -0
  64. package/src/icons/star.svg +12 -0
  65. package/src/renderers/Form/InputRating.tsx +66 -3
  66. package/src/renderers/Json.tsx +5 -0
@@ -176,7 +176,7 @@ export class Card extends React.Component<CardProps> {
176
176
  </div>
177
177
  </div>
178
178
  ) : (
179
- <div>
179
+ <>
180
180
  {heading}
181
181
  {body ? (
182
182
  <div className={cx('Card-body', bodyClassName)}>{body}</div>
@@ -193,7 +193,7 @@ export class Card extends React.Component<CardProps> {
193
193
  ) : null}
194
194
  </div>
195
195
  ) : null}
196
- </div>
196
+ </>
197
197
  )}
198
198
  </div>
199
199
  );
@@ -79,7 +79,7 @@ export class Collapse extends React.Component<CollapseProps, CollapseState> {
79
79
  super(props);
80
80
 
81
81
  this.toggleCollapsed = this.toggleCollapsed.bind(this);
82
- this.state.collapsed = !!props.collapsed;
82
+ this.state.collapsed = props.collapsable ? !!props.collapsed : false;
83
83
  }
84
84
 
85
85
  static getDerivedStateFromProps(
@@ -8,22 +8,33 @@ import React from 'react';
8
8
  import cx from 'classnames';
9
9
  import {ClassNamesFn, themeable} from '../theme';
10
10
 
11
+ import {isObject} from '../utils/helper';
12
+ import {Icon} from './icons';
13
+
14
+ export type textPositionType = 'left' | 'right';
15
+
11
16
  interface RatingProps {
12
17
  id?: string;
13
18
  key?: string | number;
14
19
  style?: React.CSSProperties;
15
20
  count: number;
16
21
  half: boolean;
17
- char: string;
18
- size: number;
22
+ char: string | React.ReactNode;
19
23
  className?: string;
20
- onChange?: (value: any) => void;
24
+ charClassName?: string;
25
+ textClassName?: string;
26
+ onChange?: (value: number) => void;
27
+ onHoverChange?: (value: number) => void;
21
28
  value: number;
22
- containerClass: string;
29
+ containerClass?: string;
23
30
  readOnly: boolean;
24
31
  classPrefix: string;
25
32
  disabled?: boolean;
26
33
  allowClear?: boolean;
34
+ inactiveColor?: string;
35
+ colors?: string | {[propName: string]: string};
36
+ texts?: {[propName: string]: string};
37
+ textPosition?: textPositionType;
27
38
  classnames: ClassNamesFn;
28
39
  }
29
40
 
@@ -35,13 +46,22 @@ export class Rating extends React.Component<RatingProps, any> {
35
46
  allowClear: true,
36
47
  value: 0,
37
48
  count: 5,
38
- char: '★',
39
- size: 24
49
+ char: <Icon icon="star" className="icon" />,
50
+ colors: {
51
+ '2': '#abadb1',
52
+ '3': '#787b81',
53
+ '5': '#ffa900'
54
+ },
55
+ textPosition: 'right' as textPositionType
40
56
  };
41
57
 
58
+ starsNode: Record<string, any>;
59
+
42
60
  constructor(props: RatingProps) {
43
61
  super(props);
44
62
 
63
+ this.starsNode = {};
64
+
45
65
  this.state = {
46
66
  value: props.value || 0,
47
67
  stars: [],
@@ -49,7 +69,10 @@ export class Rating extends React.Component<RatingProps, any> {
49
69
  halfStar: {
50
70
  at: Math.floor(props.value),
51
71
  hidden: props.half && props.value % 1 < 0.5
52
- }
72
+ },
73
+ showColor: '',
74
+ showText: null,
75
+ hoverValue: null
53
76
  };
54
77
 
55
78
  this.getRate = this.getRate.bind(this);
@@ -58,6 +81,8 @@ export class Rating extends React.Component<RatingProps, any> {
58
81
  this.mouseOver = this.mouseOver.bind(this);
59
82
  this.mouseLeave = this.mouseLeave.bind(this);
60
83
  this.handleClick = this.handleClick.bind(this);
84
+ this.saveRef = this.saveRef.bind(this);
85
+ this.handleStarMouseLeave = this.handleStarMouseLeave.bind(this);
61
86
  }
62
87
 
63
88
  componentDidMount() {
@@ -65,6 +90,8 @@ export class Rating extends React.Component<RatingProps, any> {
65
90
  this.setState({
66
91
  stars: this.getStars(value)
67
92
  });
93
+
94
+ this.getShowColorAndText(value);
68
95
  }
69
96
 
70
97
  componentDidUpdate(prevProps: RatingProps) {
@@ -82,6 +109,55 @@ export class Rating extends React.Component<RatingProps, any> {
82
109
  }
83
110
  }
84
111
 
112
+ sortKeys(map: {[propName: number]: string}) {
113
+ return Object.keys(map).sort(
114
+ (a: number | string, b: number | string) => Number(a) - Number(b)
115
+ );
116
+ }
117
+
118
+ getShowColorAndText(value: number) {
119
+ const {colors, texts, half} = this.props;
120
+
121
+ if (!value)
122
+ return this.setState({
123
+ showText: null
124
+ });
125
+
126
+ // 对 value 取整
127
+ if (half) {
128
+ value = Math.floor(Number(value) * 2) / 2;
129
+ } else {
130
+ value = Math.floor(value);
131
+ }
132
+
133
+ if (colors && typeof colors !== 'string') {
134
+ const keys: string[] = this.sortKeys(colors);
135
+ const showKey = keys.filter(item => Number(item) < value).length;
136
+
137
+ const showColor = keys[showKey] !== undefined && colors[keys[showKey]];
138
+ showColor &&
139
+ this.setState({
140
+ showColor
141
+ });
142
+ } else if (colors && typeof colors === 'string') {
143
+ this.setState({
144
+ showColor: colors
145
+ });
146
+ }
147
+
148
+ if (texts && isObject(texts)) {
149
+ const keys: string[] = this.sortKeys(texts);
150
+ const showKey = keys.filter(item => Number(item) < value).length;
151
+ const showText =
152
+ keys[showKey] !== undefined &&
153
+ texts[keys[showKey] as keyof typeof texts];
154
+ showText &&
155
+ this.setState({
156
+ showText
157
+ });
158
+ }
159
+ }
160
+
85
161
  getRate() {
86
162
  let stars;
87
163
  const {value} = this.state;
@@ -108,14 +184,28 @@ export class Rating extends React.Component<RatingProps, any> {
108
184
  return stars;
109
185
  }
110
186
 
111
- mouseOver(event: React.ChangeEvent<any>) {
187
+ saveRef(index: number) {
188
+ return (node: React.ReactNode) => {
189
+ this.starsNode[String(index)] = node;
190
+ };
191
+ }
192
+
193
+ mouseOver(event: React.ChangeEvent<any>, index: number) {
112
194
  const {isClear} = this.state;
113
195
  if (isClear) return;
114
- let {readOnly, size, half} = this.props;
196
+
197
+ const {readOnly, half} = this.props;
198
+
115
199
  if (readOnly) return;
116
- let index = Number(event.target.getAttribute('data-index'));
200
+
117
201
  if (half) {
118
- const isAtHalf = this.moreThanHalf(event, size);
202
+ const isAtHalf = this.moreThanHalf(event, index);
203
+
204
+ const tmpValue = isAtHalf ? index + 1 : index + 0.5;
205
+
206
+ this.getShowColorAndText(tmpValue);
207
+ this.onHoverChange(tmpValue);
208
+
119
209
  if (isAtHalf) index = index + 1;
120
210
  this.setState({
121
211
  halfStar: {
@@ -125,24 +215,43 @@ export class Rating extends React.Component<RatingProps, any> {
125
215
  });
126
216
  } else {
127
217
  index = index + 1;
218
+ this.onHoverChange(index);
219
+ this.getShowColorAndText(index);
128
220
  }
129
221
  this.setState({
130
222
  stars: this.getStars(index)
131
223
  });
132
224
  }
133
225
 
134
- moreThanHalf(event: any, size: number) {
135
- let {target} = event;
136
- let mouseAt = event.clientX - target.getBoundingClientRect().left;
137
- mouseAt = Math.round(Math.abs(mouseAt));
138
- return mouseAt > size / 2;
226
+ onHoverChange(value: number) {
227
+ const {onHoverChange} = this.props;
228
+ const {hoverValue} = this.state;
229
+
230
+ if (!hoverValue || (hoverValue && hoverValue !== value)) {
231
+ this.setState({
232
+ hoverValue: value
233
+ });
234
+ onHoverChange && onHoverChange(value);
235
+ }
236
+ }
237
+
238
+ moreThanHalf(event: any, index: number) {
239
+ const star = this.starsNode[index];
240
+ const leftPos = star.getBoundingClientRect().left;
241
+
242
+ return event.clientX - leftPos > star.clientWidth / 2;
139
243
  }
140
244
 
141
245
  mouseLeave() {
142
246
  const {value, isClear} = this.state;
143
247
  const {half, readOnly} = this.props;
144
248
  if (readOnly) return;
145
- if (isClear) return this.setState({isClear: false});
249
+ if (isClear)
250
+ return this.setState({
251
+ isClear: false,
252
+ hoverValue: null
253
+ });
254
+
146
255
  if (half) {
147
256
  this.setState({
148
257
  halfStar: {
@@ -152,18 +261,39 @@ export class Rating extends React.Component<RatingProps, any> {
152
261
  });
153
262
  }
154
263
  this.setState({
155
- stars: this.getStars()
264
+ stars: this.getStars(),
265
+ hoverValue: null
156
266
  });
267
+ this.getShowColorAndText(value);
157
268
  }
158
269
 
159
- handleClick(event: React.ChangeEvent<any>) {
160
- const {half, readOnly, onChange, size, allowClear} = this.props;
270
+ handleStarMouseLeave(event: any, index: number) {
271
+ const star = this.starsNode[index];
272
+ const leftSideX = star.getBoundingClientRect().left;
273
+ const {isClear} = this.state;
274
+
275
+ if (isClear) return this.setState({isClear: false});
276
+
277
+ // leave star from left side
278
+ if (event.clientX <= leftSideX) {
279
+ this.getShowColorAndText(index);
280
+ this.setState({
281
+ stars: this.getStars(index),
282
+ halfStar: {
283
+ at: index,
284
+ hidden: true
285
+ }
286
+ });
287
+ }
288
+ }
289
+
290
+ handleClick(event: React.ChangeEvent<any>, index: number) {
291
+ const {half, readOnly, onChange, allowClear} = this.props;
161
292
  if (readOnly) return;
162
- let index = Number(event.target.getAttribute('data-index'));
163
293
 
164
294
  let value;
165
295
  if (half) {
166
- const isAtHalf = this.moreThanHalf(event, size);
296
+ const isAtHalf = this.moreThanHalf(event, index);
167
297
  if (isAtHalf) index = index + 1;
168
298
  value = isAtHalf ? index : index + 0.5;
169
299
  this.setState({
@@ -183,41 +313,99 @@ export class Rating extends React.Component<RatingProps, any> {
183
313
  stars: this.getStars(index),
184
314
  isClear
185
315
  });
316
+
317
+ this.getShowColorAndText(value);
318
+
186
319
  onChange && onChange(value);
187
320
  }
188
321
 
189
322
  renderStars() {
190
- const {halfStar, stars} = this.state;
191
- const {char, half, disabled, readOnly, classnames: cx} = this.props;
192
- return stars.map((star: any, i: number) => {
193
- let className = cx('Rating', {
194
- 'Rating-half': half && !halfStar.hidden && halfStar.at === i,
195
- 'is-active': star.active,
196
- 'is-disabled': readOnly || disabled
197
- });
323
+ const {halfStar, stars, showColor} = this.state;
324
+ const {
325
+ inactiveColor,
326
+ char,
327
+ half,
328
+ disabled,
329
+ readOnly,
330
+ charClassName,
331
+ classnames: cx
332
+ } = this.props;
198
333
 
199
- return (
200
- <span
201
- className={className}
202
- key={i}
203
- data-index={i}
204
- data-forhalf={char}
205
- onMouseOver={this.mouseOver}
206
- onMouseMove={this.mouseOver}
207
- onMouseLeave={this.mouseLeave}
208
- onClick={this.handleClick}
209
- >
210
- {char}
211
- </span>
212
- );
213
- });
334
+ return (
335
+ <ul onMouseLeave={this.mouseLeave}>
336
+ {stars.map((star: any, i: number) => {
337
+ const isThisHalf = half && !halfStar.hidden && halfStar.at === i;
338
+
339
+ return (
340
+ <li
341
+ ref={this.saveRef(i)}
342
+ className={cx('Rating-star', charClassName, {
343
+ 'is-half': isThisHalf,
344
+ 'is-active': star.active,
345
+ 'is-disabled': readOnly || disabled
346
+ })}
347
+ key={i}
348
+ style={{
349
+ color: star.active ? showColor : inactiveColor
350
+ }}
351
+ onMouseOver={e => this.mouseOver(e, i)}
352
+ onMouseMove={e => this.mouseOver(e, i)}
353
+ onClick={e => this.handleClick(e, i)}
354
+ onMouseLeave={e => this.handleStarMouseLeave(e, i)}
355
+ >
356
+ {isThisHalf && (
357
+ <div
358
+ className={cx('Rating-star-half')}
359
+ style={{
360
+ color: showColor
361
+ }}
362
+ >
363
+ {char}
364
+ </div>
365
+ )}
366
+ {char}
367
+ </li>
368
+ );
369
+ })}
370
+ </ul>
371
+ );
372
+ }
373
+
374
+ renderText() {
375
+ const {showText} = this.state;
376
+ const {textClassName, textPosition, classnames: cx} = this.props;
377
+
378
+ if (!showText) return null;
379
+
380
+ return (
381
+ <span
382
+ className={cx('Rating-text', textClassName, {
383
+ [`Rating-text--${textPosition === 'left' ? 'left' : 'right'}`]:
384
+ textPosition
385
+ })}
386
+ >
387
+ {showText}
388
+ </span>
389
+ );
214
390
  }
215
391
 
216
392
  render() {
217
- let {className} = this.props;
393
+ const {className, textPosition, classnames: cx} = this.props;
218
394
 
219
395
  return (
220
- <div className={cx(className ? className : '')}>{this.renderStars()}</div>
396
+ <div className={cx('Rating', className)}>
397
+ {textPosition === 'left' ? (
398
+ <>
399
+ {this.renderText()}
400
+ {this.renderStars()}
401
+ </>
402
+ ) : (
403
+ <>
404
+ {this.renderStars()}
405
+ {this.renderText()}
406
+ </>
407
+ )}
408
+ </div>
221
409
  );
222
410
  }
223
411
  }
@@ -70,6 +70,7 @@ import ExpandAltIcon from '../icons/expand-alt.svg';
70
70
  import CompressAltIcon from '../icons/compress-alt.svg';
71
71
  import TransparentIcon from '../icons/transparent.svg';
72
72
  import LoadingOutline from '../icons/loading-outline.svg';
73
+ import Star from '../icons/star.svg';
73
74
  import AlertSuccess from '../icons/alert-success.svg';
74
75
  import AlertInfo from '../icons/alert-info.svg';
75
76
  import AlertWarning from '../icons/alert-warning.svg';
@@ -170,6 +171,7 @@ registerIcon('expand-alt', ExpandAltIcon);
170
171
  registerIcon('compress-alt', CompressAltIcon);
171
172
  registerIcon('transparent', TransparentIcon);
172
173
  registerIcon('loading-outline', LoadingOutline);
174
+ registerIcon('star', Star);
173
175
  registerIcon('alert-success', AlertSuccess);
174
176
  registerIcon('alert-info', AlertInfo);
175
177
  registerIcon('alert-warning', AlertWarning);
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="12px" height="11px" viewBox="0 0 12 11" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>星星</title>
4
+ <g id="页面-1" stroke-width="1" fill-rule="evenodd">
5
+ <g id="画板备份-8" transform="translate(-453.000000, -354.000000)">
6
+ <g id="编组" transform="translate(451.000000, 352.000000)">
7
+ <rect id="矩形" opacity="0" x="0.5" y="0.5" width="15" height="15"></rect>
8
+ <path d="M5.991,5.57 L3.50612104,5.93019955 C2.95954884,6.00942879 2.58069251,6.51674109 2.65992175,7.0633133 C2.69148792,7.28107625 2.79399678,7.48234825 2.95156285,7.63593881 L4.75,9.389 L4.75,9.389 L4.32487658,11.8655653 C4.23143888,12.4098886 4.59695386,12.9268961 5.14127715,13.0203338 C5.35808617,13.0575509 5.58111746,13.0222392 5.77582605,12.9198682 L7.999,11.751 L7.999,11.751 L10.223309,12.9201739 C10.712173,13.1771377 11.3167859,12.9891455 11.5737498,12.5002815 C11.6760846,12.3055935 11.7113789,12.0825978 11.6741677,11.8658233 L11.249,9.389 L11.249,9.389 L13.0473242,7.63660227 C13.4428666,7.25116142 13.4510555,6.6180494 13.0656146,6.22250699 C12.9120633,6.06493147 12.7108304,5.96239489 12.4930948,5.93078419 L10.008,5.57 L10.008,5.57 L8.89657099,3.31725295 C8.65221378,2.82196717 8.05261467,2.61854938 7.5573289,2.86290659 C7.36008347,2.96022079 7.20042315,3.11984957 7.10306997,3.31707577 L5.991,5.57 L5.991,5.57 Z" id="图标-填色"></path>
9
+ </g>
10
+ </g>
11
+ </g>
12
+ </svg>
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {FormItem, FormControlProps, FormBaseControl} from './Item';
3
- import Rating from '../../components/Rating';
3
+ import Rating, {textPositionType} from '../../components/Rating';
4
4
 
5
5
  /**
6
6
  * Rating
@@ -23,6 +23,50 @@ export interface RatingControlSchema extends FormBaseControl {
23
23
  * 是否允许再次点击后清除
24
24
  */
25
25
  allowClear?: boolean;
26
+
27
+ /**
28
+ * 是否只读
29
+ */
30
+ readonly?: boolean;
31
+
32
+ /**
33
+ * 星星被选中的颜色
34
+ */
35
+ // colors?: string | {
36
+ // [propName: string | number]: string;
37
+ // };
38
+
39
+ colors?: string | {[propName: string]: string};
40
+
41
+ /**
42
+ * 未被选中的星星的颜色
43
+ */
44
+ inactiveColor?: string;
45
+
46
+ /**
47
+ * 星星被选中时的提示文字
48
+ */
49
+ texts?: {[propName: string]: string};
50
+
51
+ /**
52
+ * 文字的位置
53
+ */
54
+ textPosition?: textPositionType;
55
+
56
+ /**
57
+ * 自定义字符
58
+ */
59
+ char?: string;
60
+
61
+ /**
62
+ * 自定义字符类名
63
+ */
64
+ charClassName?: string;
65
+
66
+ /**
67
+ * 自定义文字类名
68
+ */
69
+ textClassName?: string;
26
70
  }
27
71
 
28
72
  export interface RatingProps extends FormControlProps {
@@ -49,8 +93,15 @@ export default class RatingControl extends React.Component<RatingProps, any> {
49
93
  readOnly,
50
94
  disabled,
51
95
  onChange,
52
- size,
96
+ onHoverChange,
53
97
  allowClear,
98
+ char,
99
+ inactiveColor,
100
+ colors,
101
+ texts,
102
+ charClassName,
103
+ textClassName,
104
+ textPosition,
54
105
  classnames: cx
55
106
  } = this.props;
56
107
 
@@ -64,7 +115,19 @@ export default class RatingControl extends React.Component<RatingProps, any> {
64
115
  half={half}
65
116
  allowClear={allowClear}
66
117
  readOnly={readOnly}
67
- onChange={(value: any) => onChange(value)}
118
+ char={char}
119
+ inactiveColor={inactiveColor}
120
+ colors={colors}
121
+ texts={texts}
122
+ charClassName={charClassName}
123
+ textClassName={textClassName}
124
+ textPosition={textPosition}
125
+ onChange={(value: number) => {
126
+ onChange && onChange(value);
127
+ }}
128
+ onHoverChange={(value: number) => {
129
+ onHoverChange && onHoverChange(value);
130
+ }}
68
131
  />
69
132
  </div>
70
133
  );
@@ -94,6 +94,11 @@ export class JSONField extends React.Component<JSONProps, object> {
94
94
  let data = value;
95
95
  if (source !== undefined && isPureVariable(source)) {
96
96
  data = resolveVariableAndFilter(source, this.props.data, '| raw');
97
+ } else if (typeof value === 'string') {
98
+ // 尝试解析 json
99
+ try {
100
+ data = JSON.parse(value);
101
+ } catch (e) {}
97
102
  }
98
103
 
99
104
  let jsonThemeValue = jsonTheme;