amis 1.4.2-beta.1 → 1.4.2-beta.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 (91) hide show
  1. package/lib/components/ListGroup.d.ts +21 -21
  2. package/lib/components/ResultBox.d.ts +84 -84
  3. package/lib/components/SearchBox.js +4 -4
  4. package/lib/components/SearchBox.js.map +2 -2
  5. package/lib/components/WithRemoteConfig.js +1 -1
  6. package/lib/components/WithRemoteConfig.js.map +2 -2
  7. package/lib/index.js +1 -1
  8. package/lib/renderers/CRUD.d.ts +4 -0
  9. package/lib/renderers/CRUD.js.map +2 -2
  10. package/lib/renderers/Chart.js +1 -1
  11. package/lib/renderers/Chart.js.map +2 -2
  12. package/lib/renderers/DropDownButton.js +1 -1
  13. package/lib/renderers/DropDownButton.js.map +2 -2
  14. package/lib/renderers/Link.js +4 -2
  15. package/lib/renderers/Link.js.map +2 -2
  16. package/lib/renderers/Mapping.d.ts +9 -2
  17. package/lib/renderers/Mapping.js +18 -6
  18. package/lib/renderers/Mapping.js.map +2 -2
  19. package/lib/renderers/Nav.js +3 -3
  20. package/lib/renderers/Nav.js.map +2 -2
  21. package/lib/renderers/SearchBox.d.ts +6 -1
  22. package/lib/renderers/SearchBox.js +19 -5
  23. package/lib/renderers/SearchBox.js.map +2 -2
  24. package/lib/store/combo.d.ts +0 -14
  25. package/lib/store/crud.js +3 -7
  26. package/lib/store/crud.js.map +2 -2
  27. package/lib/store/form.js +2 -1
  28. package/lib/store/form.js.map +2 -2
  29. package/lib/store/service.js +5 -4
  30. package/lib/store/service.js.map +2 -2
  31. package/lib/themes/ang-ie11.css +8 -1
  32. package/lib/themes/ang.css +8 -1
  33. package/lib/themes/ang.css.map +1 -1
  34. package/lib/themes/antd-ie11.css +8 -1
  35. package/lib/themes/antd.css +8 -1
  36. package/lib/themes/antd.css.map +1 -1
  37. package/lib/themes/cxd-ie11.css +8 -1
  38. package/lib/themes/cxd.css +8 -1
  39. package/lib/themes/cxd.css.map +1 -1
  40. package/lib/themes/dark-ie11.css +8 -1
  41. package/lib/themes/dark.css +8 -1
  42. package/lib/themes/dark.css.map +1 -1
  43. package/lib/themes/default.css +8 -1
  44. package/lib/themes/default.css.map +1 -1
  45. package/lib/utils/api.d.ts +1 -0
  46. package/lib/utils/api.js +15 -1
  47. package/lib/utils/api.js.map +2 -2
  48. package/lib/utils/icon.js +3 -0
  49. package/lib/utils/icon.js.map +2 -2
  50. package/package.json +1 -1
  51. package/schema.json +8 -0
  52. package/scss/components/_mapping.scss +6 -0
  53. package/scss/components/_nav.scss +1 -1
  54. package/scss/themes/_common.scss +1 -0
  55. package/sdk/ang-ie11.css +9 -1
  56. package/sdk/ang.css +9 -1
  57. package/sdk/antd-ie11.css +9 -1
  58. package/sdk/antd.css +9 -1
  59. package/sdk/charts.js +15 -15
  60. package/sdk/color-picker.js +67 -67
  61. package/sdk/cropperjs.js +2 -2
  62. package/sdk/cxd-ie11.css +9 -1
  63. package/sdk/cxd.css +9 -1
  64. package/sdk/dark-ie11.css +9 -1
  65. package/sdk/dark.css +9 -1
  66. package/sdk/exceljs.js +1 -1
  67. package/sdk/markdown.js +69 -69
  68. package/sdk/papaparse.js +1 -1
  69. package/sdk/renderers/Form/CityDB.js +1 -1
  70. package/sdk/rest.js +22 -22
  71. package/sdk/rich-text.js +62 -62
  72. package/sdk/sdk-ie11.css +9 -1
  73. package/sdk/sdk.css +9 -1
  74. package/sdk/sdk.js +1128 -1128
  75. package/sdk/thirds/hls.js/hls.js +1 -1
  76. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  77. package/sdk/tinymce.js +57 -57
  78. package/src/components/SearchBox.tsx +4 -5
  79. package/src/components/WithRemoteConfig.tsx +7 -2
  80. package/src/renderers/CRUD.tsx +5 -0
  81. package/src/renderers/Chart.tsx +6 -2
  82. package/src/renderers/DropDownButton.tsx +1 -1
  83. package/src/renderers/Link.tsx +5 -4
  84. package/src/renderers/Mapping.tsx +27 -11
  85. package/src/renderers/Nav.tsx +3 -4
  86. package/src/renderers/SearchBox.tsx +23 -4
  87. package/src/store/crud.ts +3 -8
  88. package/src/store/form.ts +2 -1
  89. package/src/store/service.ts +5 -4
  90. package/src/utils/api.ts +13 -0
  91. package/src/utils/icon.tsx +4 -0
@@ -54,7 +54,7 @@ export class SearchBox extends React.Component<SearchBoxProps> {
54
54
 
55
55
  @autobind
56
56
  handleCancel() {
57
- const {onActiveChange, onChange, onCancel} = this.props;
57
+ const {onActiveChange, onCancel, onChange} = this.props;
58
58
  onActiveChange?.(false);
59
59
  onCancel?.();
60
60
  onChange?.('');
@@ -62,14 +62,14 @@ export class SearchBox extends React.Component<SearchBoxProps> {
62
62
 
63
63
  @autobind
64
64
  handleChange(e: React.ChangeEvent<HTMLInputElement>) {
65
- const {onChange, onSearch, searchImediately} = this.props;
65
+ const {searchImediately, onChange} = this.props;
66
66
  onChange?.(e.currentTarget.value);
67
67
  searchImediately && this.lazyEmitSearch();
68
68
  }
69
69
 
70
70
  @autobind
71
71
  handleSearch() {
72
- const {value, onSearch} = this.props;
72
+ const {onSearch, value} = this.props;
73
73
  onSearch?.(value || '');
74
74
  }
75
75
 
@@ -84,14 +84,13 @@ export class SearchBox extends React.Component<SearchBoxProps> {
84
84
  render() {
85
85
  const {
86
86
  classnames: cx,
87
- value,
88
87
  active,
89
88
  name,
90
89
  className,
91
- onChange,
92
90
  disabled,
93
91
  placeholder,
94
92
  mini,
93
+ value,
95
94
  translate: __
96
95
  } = this.props;
97
96
 
@@ -12,7 +12,12 @@ import {withStore} from './WithStore';
12
12
  import {EnvContext, RendererEnv} from '../env';
13
13
 
14
14
  import {flow, Instance, isAlive, types} from 'mobx-state-tree';
15
- import {buildApi, isEffectiveApi, normalizeApi} from '../utils/api';
15
+ import {
16
+ buildApi,
17
+ isEffectiveApi,
18
+ normalizeApi,
19
+ normalizeApiResponseData
20
+ } from '../utils/api';
16
21
  import {
17
22
  isPureVariable,
18
23
  resolveVariableAndFilter,
@@ -46,7 +51,7 @@ export const Store = types
46
51
  }
47
52
 
48
53
  if (ret.ok) {
49
- const data = ret.data || {};
54
+ const data = normalizeApiResponseData(ret.data);
50
55
  let options = config.adaptor
51
56
  ? config.adaptor(data, component.props)
52
57
  : data;
@@ -282,6 +282,11 @@ export interface CRUDCommonSchema extends BaseSchema {
282
282
  * 默认只有当分页数大于 1 是才显示,如果总是想显示请配置。
283
283
  */
284
284
  alwaysShowPagination?: boolean;
285
+
286
+ /**
287
+ * 开启查询区域,会根据列元素的searchable属性值,自动生成查询条件表单
288
+ */
289
+ autoGenerateFilter?: boolean;
285
290
  }
286
291
 
287
292
  export type CRUDCardsSchema = CRUDCommonSchema & {
@@ -12,7 +12,11 @@ import {
12
12
  isPureVariable,
13
13
  dataMapping
14
14
  } from '../utils/tpl-builtin';
15
- import {isApiOutdated, isEffectiveApi} from '../utils/api';
15
+ import {
16
+ isApiOutdated,
17
+ isEffectiveApi,
18
+ normalizeApiResponseData
19
+ } from '../utils/api';
16
20
  import {ScopedContext, IScopedContext} from '../Scoped';
17
21
  import {createObject, findObjectsWithKey} from '../utils/helper';
18
22
  import Spinner from '../components/Spinner';
@@ -342,7 +346,7 @@ export class Chart extends React.Component<ChartProps> {
342
346
  }
343
347
  delete this.reloadCancel;
344
348
 
345
- const data = result.data || {};
349
+ const data = normalizeApiResponseData(result.data);
346
350
  // 说明返回的是数据接口。
347
351
  if (!data.series && this.props.config) {
348
352
  const ctx = createObject(this.props.data, data);
@@ -339,7 +339,7 @@ export default class DropDownButton extends React.Component<
339
339
  {rightIconElement}
340
340
  {!hideCaret ? (
341
341
  <span className={cx('DropDown-caret')}>
342
- <Icon icon="ellipsis-v" className="icon" />
342
+ <Icon icon="caret" className="icon" />
343
343
  </span>
344
344
  ) : null}
345
345
  </button>
@@ -77,12 +77,14 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
77
77
 
78
78
  let value = getPropValue(this.props);
79
79
  const finnalHref = href ? filter(href, data, '| raw') : '';
80
- const text = body ? render('body', body) : finnalHref || value || __('link');
80
+ const text = body
81
+ ? render('body', body)
82
+ : finnalHref || value || __('link');
81
83
 
82
84
  return (
83
85
  <Link
84
86
  className={className}
85
- href={href}
87
+ href={finnalHref}
86
88
  body={text}
87
89
  blank={blank}
88
90
  disabled={disabled}
@@ -90,8 +92,7 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
90
92
  htmlTarget={htmlTarget}
91
93
  icon={icon}
92
94
  position={position}
93
- >
94
- </Link>
95
+ ></Link>
95
96
  );
96
97
  }
97
98
  }
@@ -20,7 +20,8 @@ import {
20
20
  buildApi,
21
21
  isApiOutdated,
22
22
  isEffectiveApi,
23
- normalizeApi
23
+ normalizeApi,
24
+ normalizeApiResponseData
24
25
  } from '../utils/api';
25
26
 
26
27
  /**
@@ -72,7 +73,7 @@ export const Store = StoreNode.named('MappingStore')
72
73
  const ret: Payload = yield env.fetcher(api, data);
73
74
 
74
75
  if (ret.ok) {
75
- const data = ret.data || {};
76
+ const data = normalizeApiResponseData(ret.data);
76
77
  (self as any).setMap(data);
77
78
  } else {
78
79
  throw new Error(ret.msg || 'fetch error');
@@ -175,7 +176,7 @@ export const MappingField = withStore(props =>
175
176
  }
176
177
  }
177
178
 
178
- render() {
179
+ renderSingleValue(key: any, reactKey?: number) {
179
180
  const {
180
181
  className,
181
182
  placeholder,
@@ -185,17 +186,13 @@ export const MappingField = withStore(props =>
185
186
  data,
186
187
  store
187
188
  } = this.props;
188
- const map = store.map;
189
-
190
- let key = getPropValue(this.props);
191
-
192
189
  let viewValue: React.ReactNode = (
193
190
  <span className="text-muted">{placeholder}</span>
194
191
  );
195
-
196
- key = typeof key === 'string' ? key.trim() : key; // trim 一下,干掉一些空白字符。
192
+ const map = store.map;
197
193
  let value: any = undefined;
198
-
194
+ // trim 一下,干掉一些空白字符。
195
+ key = typeof key === 'string' ? key.trim() : key;
199
196
  if (
200
197
  typeof key !== 'undefined' &&
201
198
  map &&
@@ -210,7 +207,26 @@ export const MappingField = withStore(props =>
210
207
  viewValue = render('tpl', value);
211
208
  }
212
209
 
213
- return <span className={cx('MappingField', className)}>{viewValue}</span>;
210
+ return (
211
+ <span key={`map-${reactKey}`} className={cx('MappingField', className)}>
212
+ {viewValue}
213
+ </span>
214
+ );
215
+ }
216
+
217
+ render() {
218
+ const mapKey = getPropValue(this.props);
219
+ if (Array.isArray(mapKey)) {
220
+ return (
221
+ <span>
222
+ {mapKey.map((singleKey: string, index: number) =>
223
+ this.renderSingleValue(singleKey, index)
224
+ )}
225
+ </span>
226
+ );
227
+ } else {
228
+ return this.renderSingleValue(mapKey, 0);
229
+ }
214
230
  }
215
231
  }
216
232
  );
@@ -363,7 +363,7 @@ export class Navigation extends React.Component<
363
363
  onClick={this.handleClick.bind(this, link)}
364
364
  style={{paddingLeft: depth * (parseInt(indentSize as any, 10) ?? 24)}}
365
365
  >
366
- {!disabled && draggable && links && links.length > 1 ? (
366
+ {!disabled && draggable ? (
367
367
  <div className={cx('Nav-itemDrager')}
368
368
  draggable
369
369
  onMouseDown={e => {this.toggleLink(link, true); e.stopPropagation()}}
@@ -480,7 +480,7 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({
480
480
  env &&
481
481
  env.isCurrentUrl(filter(link.to as string, data))
482
482
  )),
483
- __id: guid()
483
+ __id: link.__id || guid()
484
484
  };
485
485
 
486
486
  item.unfolded =
@@ -659,7 +659,7 @@ const ConditionBuilderWithRemoteOptions = withRemoteConfig({
659
659
  <ThemedNavigation
660
660
  {...rest}
661
661
  loading={loading}
662
- links={config || rest.links || []}
662
+ links={config || []}
663
663
  disabled={loading}
664
664
  onSelect={this.handleSelect}
665
665
  onToggle={this.toggleLink}
@@ -721,7 +721,6 @@ export class NavigationRenderer extends React.Component<RendererProps> {
721
721
 
722
722
  render() {
723
723
  const {...rest} = this.props;
724
-
725
724
  return (
726
725
  <ConditionBuilderWithRemoteOptions
727
726
  {...rest}
@@ -56,10 +56,17 @@ interface SearchBoxProps
56
56
  onQuery?: (query: {[propName: string]: string}) => void;
57
57
  }
58
58
 
59
+ export interface SearchBoxState {
60
+ value: string;
61
+ }
62
+
59
63
  @Renderer({
60
64
  type: 'search-box'
61
65
  })
62
- export class SearchBoxRenderer extends React.Component<SearchBoxProps> {
66
+ export class SearchBoxRenderer extends React.Component<
67
+ SearchBoxProps,
68
+ SearchBoxState
69
+ > {
63
70
  static defaultProps = {
64
71
  name: 'keywords',
65
72
  mini: false,
@@ -68,6 +75,18 @@ export class SearchBoxRenderer extends React.Component<SearchBoxProps> {
68
75
 
69
76
  static propsList: Array<string> = ['mini', 'searchImediately'];
70
77
 
78
+ constructor(props: SearchBoxProps) {
79
+ super(props);
80
+ this.state = {
81
+ value: getPropValue(props) || ''
82
+ };
83
+ }
84
+
85
+ @autobind
86
+ handleChange(value: string) {
87
+ this.setState({value});
88
+ }
89
+
71
90
  @autobind
72
91
  handleCancel() {
73
92
  const name = this.props.name;
@@ -100,7 +119,7 @@ export class SearchBoxRenderer extends React.Component<SearchBoxProps> {
100
119
  className
101
120
  } = this.props;
102
121
 
103
- const value = getPropValue(this.props);
122
+ const value = this.state.value;
104
123
 
105
124
  return (
106
125
  <SearchBox
@@ -109,13 +128,13 @@ export class SearchBoxRenderer extends React.Component<SearchBoxProps> {
109
128
  disabled={!onQuery}
110
129
  defaultActive={!!value}
111
130
  defaultValue={onChange ? undefined : value}
112
- value={onChange ? value : undefined}
131
+ value={value}
113
132
  mini={mini}
114
133
  searchImediately={searchImediately}
115
134
  onSearch={this.handleSearch}
116
135
  onCancel={this.handleCancel}
117
136
  placeholder={placeholder}
118
- onChange={onChange}
137
+ onChange={this.handleChange}
119
138
  />
120
139
  );
121
140
  }
package/src/store/crud.ts CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  import {Api, Payload, fetchOptions, Action, ApiObject} from '../types';
22
22
  import pick from 'lodash/pick';
23
23
  import {resolveVariableAndFilter} from '../utils/tpl-builtin';
24
+ import {normalizeApiResponseData} from '../utils/api';
24
25
 
25
26
  class ServerError extends Error {
26
27
  type = 'ServerError';
@@ -228,13 +229,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
228
229
  }
229
230
 
230
231
  self.updatedAt = Date.now();
231
- let result = json.data;
232
-
233
- if (Array.isArray(result)) {
234
- result = {
235
- items: result
236
- };
237
- }
232
+ let result = normalizeApiResponseData(json.data);
238
233
 
239
234
  const {
240
235
  total,
@@ -384,7 +379,7 @@ export const CRUDStore = ServiceStore.named('CRUDStore')
384
379
 
385
380
  if (!isEmpty(json.data) || json.ok) {
386
381
  self.updateData(
387
- json.data,
382
+ normalizeApiResponseData(json.data),
388
383
  {
389
384
  __saved: Date.now()
390
385
  },
package/src/store/form.ts CHANGED
@@ -29,6 +29,7 @@ import isEqual from 'lodash/isEqual';
29
29
  import flatten from 'lodash/flatten';
30
30
  import {getStoreById, removeStore} from './manager';
31
31
  import {filter} from '../utils/tpl';
32
+ import {normalizeApiResponseData} from '../utils/api';
32
33
 
33
34
  export const FormStore = ServiceStore.named('FormStore')
34
35
  .props({
@@ -305,7 +306,7 @@ export const FormStore = ServiceStore.named('FormStore')
305
306
  self.updatedAt = Date.now();
306
307
 
307
308
  setValues(
308
- json.data,
309
+ normalizeApiResponseData(json.data),
309
310
  json.ok
310
311
  ? {
311
312
  __saved: Date.now()
@@ -3,6 +3,7 @@ import {iRendererStore} from './iRenderer';
3
3
  import {Api, ApiObject, Payload, fetchOptions} from '../types';
4
4
  import {extendObject, isEmpty, isObject} from '../utils/helper';
5
5
  import {ServerError} from '../utils/errors';
6
+ import {normalizeApiResponseData} from '../utils/api';
6
7
 
7
8
  export const ServiceStore = iRendererStore
8
9
  .named('ServiceStore')
@@ -96,7 +97,7 @@ export const ServiceStore = iRendererStore
96
97
  let replace = !!(api as ApiObject).replaceData;
97
98
  let data = {
98
99
  ...(replace ? {} : self.data),
99
- ...json.data
100
+ ...normalizeApiResponseData(json.data)
100
101
  };
101
102
  reInitData(data, replace);
102
103
  self.hasRemoteData = true;
@@ -176,7 +177,7 @@ export const ServiceStore = iRendererStore
176
177
 
177
178
  json.data &&
178
179
  self.updateData(
179
- json.data,
180
+ normalizeApiResponseData(json.data),
180
181
  undefined,
181
182
  !!(api as ApiObject).replaceData
182
183
  );
@@ -264,7 +265,7 @@ export const ServiceStore = iRendererStore
264
265
 
265
266
  json.data &&
266
267
  self.updateData(
267
- json.data,
268
+ normalizeApiResponseData(json.data),
268
269
  undefined,
269
270
  !!(api as ApiObject).replaceData
270
271
  );
@@ -406,7 +407,7 @@ export const ServiceStore = iRendererStore
406
407
  : {
407
408
  type: 'wrapper',
408
409
  wrap: false,
409
- ...json.data
410
+ ...normalizeApiResponseData(json.data)
410
411
  };
411
412
  self.schemaKey = '' + Date.now();
412
413
  isObject(json.data.data) &&
package/src/utils/api.ts CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  createObject,
13
13
  qsparse
14
14
  } from './helper';
15
+ import isPlainObject from 'lodash/isPlainObject';
15
16
 
16
17
  const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head):/i;
17
18
 
@@ -469,4 +470,16 @@ export function clearApiCache() {
469
470
  apiCaches.splice(0, apiCaches.length);
470
471
  }
471
472
 
473
+ export function normalizeApiResponseData(data: any) {
474
+ if (typeof data === 'undefined') {
475
+ data = {};
476
+ } else if (!isPlainObject(data)) {
477
+ data = {
478
+ [Array.isArray(data) ? 'items' : 'result']: data
479
+ };
480
+ }
481
+
482
+ return data;
483
+ }
484
+
472
485
  // window.apiCaches = apiCaches;
@@ -17,6 +17,10 @@ export const generateIcon = (
17
17
  className?: string,
18
18
  classNameProp?: string
19
19
  ) => {
20
+ if (React.isValidElement(icon)) {
21
+ return icon;
22
+ }
23
+
20
24
  const isURLIcon = icon?.indexOf('.') !== -1;
21
25
 
22
26
  return icon ? (