amis 1.4.2-beta.13 → 1.4.2-beta.18

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 (190) hide show
  1. package/lib/Schema.d.ts +4 -3
  2. package/lib/Schema.js.map +1 -1
  3. package/lib/components/Alert2.d.ts +26 -21
  4. package/lib/components/Alert2.js +11 -4
  5. package/lib/components/Alert2.js.map +2 -2
  6. package/lib/components/AssociatedSelection.js +2 -2
  7. package/lib/components/AssociatedSelection.js.map +2 -2
  8. package/lib/components/Button.js +1 -1
  9. package/lib/components/Button.js.map +2 -2
  10. package/lib/components/Checkbox.d.ts +20 -20
  11. package/lib/components/Collapse.d.ts +51 -23
  12. package/lib/components/Collapse.js +70 -11
  13. package/lib/components/Collapse.js.map +2 -2
  14. package/lib/components/CollapseGroup.d.ts +88 -0
  15. package/lib/components/CollapseGroup.js +81 -0
  16. package/lib/components/CollapseGroup.js.map +13 -0
  17. package/lib/components/ColorPicker.d.ts +5 -1
  18. package/lib/components/ColorPicker.js +17 -4
  19. package/lib/components/ColorPicker.js.map +2 -2
  20. package/lib/components/Editor.d.ts +84 -84
  21. package/lib/components/GridNav.d.ts +52 -0
  22. package/lib/components/GridNav.js +123 -0
  23. package/lib/components/GridNav.js.map +13 -0
  24. package/lib/components/ListGroup.d.ts +21 -21
  25. package/lib/components/Overlay.js +5 -0
  26. package/lib/components/Overlay.js.map +2 -2
  27. package/lib/components/PopOver.d.ts +1 -0
  28. package/lib/components/PopOver.js +12 -1
  29. package/lib/components/PopOver.js.map +2 -2
  30. package/lib/components/Tabs.d.ts +20 -20
  31. package/lib/components/TabsTransfer.d.ts +84 -84
  32. package/lib/components/Toast.d.ts +90 -87
  33. package/lib/components/Toast.js +15 -5
  34. package/lib/components/Toast.js.map +2 -2
  35. package/lib/components/Transfer.d.ts +84 -84
  36. package/lib/components/TransferDropDown.d.ts +84 -84
  37. package/lib/components/Tree.d.ts +115 -84
  38. package/lib/components/Tree.js +183 -30
  39. package/lib/components/Tree.js.map +2 -2
  40. package/lib/components/condition-builder/Field.js +2 -3
  41. package/lib/components/condition-builder/Field.js.map +2 -2
  42. package/lib/components/icons.js +8 -0
  43. package/lib/components/icons.js.map +2 -2
  44. package/lib/envOverwrite.d.ts +1 -1
  45. package/lib/envOverwrite.js +24 -9
  46. package/lib/envOverwrite.js.map +2 -2
  47. package/lib/factory.d.ts +11 -1
  48. package/lib/factory.js +31 -4
  49. package/lib/factory.js.map +2 -2
  50. package/lib/icons/alert-danger.js +7 -0
  51. package/lib/icons/alert-info.js +7 -0
  52. package/lib/icons/alert-success.js +7 -0
  53. package/lib/icons/alert-warning.js +7 -0
  54. package/lib/icons/drag-bar.js +10 -3
  55. package/lib/index.d.ts +2 -0
  56. package/lib/index.js +3 -1
  57. package/lib/index.js.map +2 -2
  58. package/lib/renderers/Alert.d.ts +21 -1
  59. package/lib/renderers/Alert.js.map +2 -2
  60. package/lib/renderers/Card.d.ts +1 -0
  61. package/lib/renderers/Card.js +7 -2
  62. package/lib/renderers/Card.js.map +2 -2
  63. package/lib/renderers/Collapse.d.ts +25 -20
  64. package/lib/renderers/Collapse.js +10 -73
  65. package/lib/renderers/Collapse.js.map +2 -2
  66. package/lib/renderers/CollapseGroup.d.ts +42 -0
  67. package/lib/renderers/CollapseGroup.js +33 -0
  68. package/lib/renderers/CollapseGroup.js.map +13 -0
  69. package/lib/renderers/Form/ConditionBuilder.js +2 -2
  70. package/lib/renderers/Form/ConditionBuilder.js.map +2 -2
  71. package/lib/renderers/Form/InputCity.d.ts +84 -84
  72. package/lib/renderers/Form/InputColor.d.ts +2 -1
  73. package/lib/renderers/Form/InputColor.js +1 -1
  74. package/lib/renderers/Form/InputColor.js.map +2 -2
  75. package/lib/renderers/Form/Item.js +2 -1
  76. package/lib/renderers/Form/Item.js.map +2 -2
  77. package/lib/renderers/GridNav.d.ts +99 -0
  78. package/lib/renderers/GridNav.js +82 -0
  79. package/lib/renderers/GridNav.js.map +13 -0
  80. package/lib/renderers/Page.d.ts +18 -0
  81. package/lib/renderers/Page.js +53 -9
  82. package/lib/renderers/Page.js.map +2 -2
  83. package/lib/store/formItem.js +44 -4
  84. package/lib/store/formItem.js.map +2 -2
  85. package/lib/themes/ang-ie11.css +324 -49
  86. package/lib/themes/ang.css +324 -49
  87. package/lib/themes/ang.css.map +1 -1
  88. package/lib/themes/antd-ie11.css +324 -49
  89. package/lib/themes/antd.css +324 -49
  90. package/lib/themes/antd.css.map +1 -1
  91. package/lib/themes/cxd-ie11.css +331 -58
  92. package/lib/themes/cxd.css +331 -58
  93. package/lib/themes/cxd.css.map +1 -1
  94. package/lib/themes/dark-ie11.css +324 -49
  95. package/lib/themes/dark.css +324 -49
  96. package/lib/themes/dark.css.map +1 -1
  97. package/lib/themes/default.css +331 -58
  98. package/lib/themes/default.css.map +1 -1
  99. package/lib/types.d.ts +1 -1
  100. package/lib/types.js.map +1 -1
  101. package/lib/utils/api.d.ts +1 -0
  102. package/lib/utils/api.js +77 -6
  103. package/lib/utils/api.js.map +2 -2
  104. package/lib/utils/helper.d.ts +8 -0
  105. package/lib/utils/helper.js +33 -2
  106. package/lib/utils/helper.js.map +2 -2
  107. package/lib/utils/tpl-builtin.js +5 -0
  108. package/lib/utils/tpl-builtin.js.map +2 -2
  109. package/package.json +1 -1
  110. package/schema.json +365 -49
  111. package/scss/_properties.scss +2 -1
  112. package/scss/components/_alert.scss +28 -5
  113. package/scss/components/_anchor-nav.scss +1 -0
  114. package/scss/components/_button.scss +5 -0
  115. package/scss/components/_card.scss +1 -1
  116. package/scss/components/_collapse-group.scss +15 -0
  117. package/scss/components/_collapse.scss +33 -23
  118. package/scss/components/_grid-nav.scss +128 -0
  119. package/scss/components/_nav.scss +2 -7
  120. package/scss/components/_page.scss +35 -2
  121. package/scss/components/_spinner.scss +5 -4
  122. package/scss/components/_table.scss +6 -0
  123. package/scss/components/_toast.scss +41 -11
  124. package/scss/components/form/_color.scss +32 -3
  125. package/scss/components/form/_combo.scss +4 -0
  126. package/scss/components/form/_fieldset.scss +1 -0
  127. package/scss/components/form/_transfer.scss +1 -0
  128. package/scss/components/form/_tree.scss +42 -0
  129. package/scss/themes/_common.scss +2 -0
  130. package/scss/themes/_cxd-variables.scss +9 -4
  131. package/scss/themes/cxd.scss +1 -7
  132. package/sdk/ang-ie11.css +375 -53
  133. package/sdk/ang.css +377 -53
  134. package/sdk/antd-ie11.css +375 -53
  135. package/sdk/antd.css +377 -53
  136. package/sdk/charts.js +13 -13
  137. package/sdk/color-picker.js +69 -65
  138. package/sdk/cropperjs.js +2 -2
  139. package/sdk/cxd-ie11.css +379 -60
  140. package/sdk/cxd.css +384 -62
  141. package/sdk/dark-ie11.css +375 -53
  142. package/sdk/dark.css +377 -53
  143. package/sdk/exceljs.js +1 -1
  144. package/sdk/markdown.js +69 -69
  145. package/sdk/papaparse.js +1 -1
  146. package/sdk/renderers/Form/CityDB.js +1 -1
  147. package/sdk/rest.js +16 -20
  148. package/sdk/rich-text.js +62 -62
  149. package/sdk/sdk-ie11.css +379 -60
  150. package/sdk/sdk.css +384 -62
  151. package/sdk/sdk.js +1215 -1173
  152. package/sdk/thirds/hls.js/hls.js +1 -1
  153. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  154. package/sdk/tinymce.js +57 -57
  155. package/src/Schema.ts +5 -1
  156. package/src/components/Alert2.tsx +32 -4
  157. package/src/components/AssociatedSelection.tsx +3 -1
  158. package/src/components/Button.tsx +1 -0
  159. package/src/components/Collapse.tsx +139 -20
  160. package/src/components/CollapseGroup.tsx +130 -0
  161. package/src/components/ColorPicker.tsx +32 -10
  162. package/src/components/GridNav.tsx +233 -0
  163. package/src/components/Overlay.tsx +6 -0
  164. package/src/components/PopOver.tsx +15 -1
  165. package/src/components/Toast.tsx +48 -21
  166. package/src/components/Tree.tsx +194 -8
  167. package/src/components/condition-builder/Field.tsx +3 -1
  168. package/src/components/icons.tsx +8 -0
  169. package/src/envOverwrite.ts +20 -7
  170. package/src/factory.tsx +52 -6
  171. package/src/icons/alert-danger.svg +1 -0
  172. package/src/icons/alert-info.svg +1 -0
  173. package/src/icons/alert-success.svg +1 -0
  174. package/src/icons/alert-warning.svg +1 -0
  175. package/src/icons/drag-bar.svg +12 -6
  176. package/src/index.tsx +2 -0
  177. package/src/renderers/Alert.tsx +31 -1
  178. package/src/renderers/Card.tsx +13 -2
  179. package/src/renderers/Collapse.tsx +70 -117
  180. package/src/renderers/CollapseGroup.tsx +80 -0
  181. package/src/renderers/Form/ConditionBuilder.tsx +2 -2
  182. package/src/renderers/Form/InputColor.tsx +4 -2
  183. package/src/renderers/GridNav.tsx +204 -0
  184. package/src/renderers/Page.tsx +62 -1
  185. package/src/store/formItem.ts +94 -2
  186. package/src/types.ts +1 -1
  187. package/src/utils/api.ts +93 -6
  188. package/src/utils/helper.ts +33 -0
  189. package/src/utils/tpl-builtin.ts +6 -0
  190. package/tsconfig-for-declaration.json +1 -1
@@ -617,12 +617,104 @@ export const FormItemStore = StoreNode.named('FormItemStore')
617
617
  return json;
618
618
  });
619
619
 
620
+ const tryDeferLoadLeftOptions: (
621
+ option: any,
622
+ api: Api,
623
+ data?: object,
624
+ config?: fetchOptions
625
+ ) => Promise<Payload | null> = flow(function* (
626
+ option: any,
627
+ api: string,
628
+ data: object,
629
+ config?: fetchOptions
630
+ ) {
631
+ if (
632
+ self.options.length != 1 ||
633
+ !Array.isArray(self.options[0].leftOptions)
634
+ ) {
635
+ return;
636
+ }
637
+
638
+ let leftOptions = self.options[0].leftOptions as any;
639
+
640
+ const indexes = findTreeIndex(leftOptions, item => item === option);
641
+ if (!indexes) {
642
+ return;
643
+ }
644
+
645
+ setOptions(
646
+ [
647
+ {
648
+ ...self.options[0],
649
+ leftOptions: spliceTree(leftOptions, indexes, 1, {
650
+ ...option,
651
+ loading: true
652
+ })
653
+ }
654
+ ],
655
+ undefined,
656
+ data
657
+ );
658
+
659
+ let json = yield fetchOptions(
660
+ api,
661
+ data,
662
+ {
663
+ ...config,
664
+ silent: true
665
+ },
666
+ false
667
+ );
668
+ if (!json) {
669
+ setOptions(
670
+ [
671
+ {
672
+ ...self.options[0],
673
+ leftOptions: spliceTree(leftOptions, indexes, 1, {
674
+ ...option,
675
+ loading: false,
676
+ error: true
677
+ })
678
+ }
679
+ ],
680
+ undefined,
681
+ data
682
+ );
683
+ return;
684
+ }
685
+
686
+ let options: Array<IOption> =
687
+ json.data?.options ||
688
+ json.data.items ||
689
+ json.data.rows ||
690
+ json.data ||
691
+ [];
692
+
693
+ setOptions(
694
+ [
695
+ {
696
+ ...self.options[0],
697
+ leftOptions: spliceTree(leftOptions, indexes, 1, {
698
+ ...option,
699
+ loading: false,
700
+ loaded: true,
701
+ children: options
702
+ })
703
+ }
704
+ ],
705
+ undefined,
706
+ data
707
+ );
708
+
709
+ return json;
710
+ });
711
+
620
712
  const deferLoadOptions: (
621
713
  option: any,
622
714
  api: Api,
623
715
  data?: object,
624
716
  config?: fetchOptions
625
- ) => Promise<Payload | null> = flow(function* getInitData(
717
+ ) => Promise<Payload | null> = flow(function* (
626
718
  option: any,
627
719
  api: string,
628
720
  data: object,
@@ -630,7 +722,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
630
722
  ) {
631
723
  const indexes = findTreeIndex(self.options, item => item === option);
632
724
  if (!indexes) {
633
- return;
725
+ return yield tryDeferLoadLeftOptions(option, api, data, config);
634
726
  }
635
727
 
636
728
  setOptions(
package/src/types.ts CHANGED
@@ -31,7 +31,7 @@ export interface fetcherResult {
31
31
  }
32
32
 
33
33
  export interface fetchOptions {
34
- method?: 'get' | 'post' | 'put' | 'patch' | 'delete';
34
+ method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'jsonp';
35
35
  successMessage?: string;
36
36
  errorMessage?: string;
37
37
  autoAppend?: boolean;
package/src/utils/api.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import omit from 'lodash/omit';
2
2
  import {Api, ApiObject, EventTrack, fetcherResult, Payload} from '../types';
3
3
  import {fetcherConfig} from '../factory';
4
- import {tokenize, dataMapping} from './tpl-builtin';
4
+ import {tokenize, dataMapping, escapeHtml} from './tpl-builtin';
5
5
  import {evalExpression} from './tpl';
6
6
  import {
7
7
  isObject,
@@ -11,11 +11,12 @@ import {
11
11
  qsstringify,
12
12
  cloneObject,
13
13
  createObject,
14
- qsparse
14
+ qsparse,
15
+ uuid
15
16
  } from './helper';
16
17
  import isPlainObject from 'lodash/isPlainObject';
17
18
 
18
- const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head):/i;
19
+ const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head|jsonp):/i;
19
20
 
20
21
  interface ApiCacheConfig extends ApiObject {
21
22
  cachedPromise: Promise<any>;
@@ -125,7 +126,7 @@ export function buildApi(
125
126
  }
126
127
 
127
128
  // get 类请求,把 data 附带到 url 上。
128
- if (api.method === 'get') {
129
+ if (api.method === 'get' || api.method === 'jsonp') {
129
130
  if (!~raw.indexOf('$') && !api.data && autoAppend) {
130
131
  api.query = api.data = data;
131
132
  } else if (
@@ -195,13 +196,28 @@ export function str2AsyncFunction(
195
196
  }
196
197
 
197
198
  export function responseAdaptor(ret: fetcherResult, api: ApiObject) {
198
- const data = ret.data;
199
+ let data = ret.data;
199
200
  let hasStatusField = true;
200
201
 
201
202
  if (!data) {
202
203
  throw new Error('Response is empty');
203
204
  }
204
205
 
206
+ if (typeof data === 'string') {
207
+ try {
208
+ data = JSON.parse(data);
209
+ if (typeof data === 'undefined') {
210
+ throw new Error('Response should be JSON');
211
+ }
212
+ } catch (e) {
213
+ const responseBrief =
214
+ typeof data === 'string'
215
+ ? escapeHtml((data as string).substring(0, 100))
216
+ : '';
217
+ throw new Error(`Response should be JSON\n ${responseBrief}`);
218
+ }
219
+ }
220
+
205
221
  // 兼容几种常见写法
206
222
  if (data.hasOwnProperty('errorCode')) {
207
223
  // 阿里 Java 规范
@@ -247,7 +263,7 @@ export function responseAdaptor(ret: fetcherResult, api: ApiObject) {
247
263
  }
248
264
 
249
265
  if (payload.ok && api.responseData) {
250
- payload.data = dataMapping(
266
+ const responseData = dataMapping(
251
267
  api.responseData,
252
268
 
253
269
  createObject(
@@ -261,6 +277,8 @@ export function responseAdaptor(ret: fetcherResult, api: ApiObject) {
261
277
  undefined,
262
278
  api.convertKeyToPath
263
279
  );
280
+ console.debug('responseData', responseData);
281
+ payload.data = responseData;
264
282
  }
265
283
 
266
284
  return payload;
@@ -303,6 +321,10 @@ export function wrapFetcher(
303
321
  api.data
304
322
  );
305
323
 
324
+ if (api.method?.toLocaleLowerCase() === 'jsonp') {
325
+ return wrapAdaptor(jsonpFetcher(api), api);
326
+ }
327
+
306
328
  if (typeof api.cache === 'number' && api.cache > 0) {
307
329
  const apiCache = getApiCache(api);
308
330
  return wrapAdaptor(
@@ -345,6 +367,71 @@ export function wrapAdaptor(promise: Promise<fetcherResult>, api: ApiObject) {
345
367
  : promise.then(ret => responseAdaptor(ret, api));
346
368
  }
347
369
 
370
+ export function jsonpFetcher(api: ApiObject): Promise<fetcherResult> {
371
+ return new Promise((resolve, reject) => {
372
+ let script: HTMLScriptElement | null = document.createElement('script');
373
+ let src = api.url;
374
+
375
+ script.async = true;
376
+
377
+ function remove() {
378
+ if (script) {
379
+ // @ts-ignore
380
+ script.onload = script.onreadystatechange = script.onerror = null;
381
+
382
+ if (script.parentNode) {
383
+ script.parentNode.removeChild(script);
384
+ }
385
+
386
+ script = null;
387
+ }
388
+ }
389
+
390
+ const jsonp = api.query?.callback || 'axiosJsonpCallback' + uuid();
391
+ const old = (window as any)[jsonp];
392
+
393
+ (window as any)[jsonp] = function (responseData: any) {
394
+ (window as any)[jsonp] = old;
395
+
396
+ const response = {
397
+ data: responseData,
398
+ status: 200,
399
+ headers: {}
400
+ };
401
+
402
+ resolve(response);
403
+ };
404
+
405
+ const additionalParams: any = {
406
+ _: new Date().getTime(),
407
+ _callback: jsonp
408
+ };
409
+
410
+ src += (src.indexOf('?') >= 0 ? '&' : '?') + qsstringify(additionalParams);
411
+
412
+ // @ts-ignore IE 为script.onreadystatechange
413
+ script.onload = script.onreadystatechange = function () {
414
+ // @ts-ignore
415
+ if (!script.readyState || /loaded|complete/.test(script.readyState)) {
416
+ remove();
417
+ }
418
+ };
419
+
420
+ script.onerror = function () {
421
+ remove();
422
+ const errResponse = {
423
+ status: 0,
424
+ headers: {}
425
+ };
426
+
427
+ reject(errResponse);
428
+ };
429
+
430
+ script.src = src;
431
+ document.head.appendChild(script);
432
+ });
433
+ }
434
+
348
435
  export function isApiOutdated(
349
436
  prevApi: Api | undefined,
350
437
  nextApi: Api | undefined,
@@ -16,6 +16,12 @@ import {
16
16
  } from './tpl-builtin';
17
17
  import {isObservable} from 'mobx';
18
18
 
19
+ export function preventDefault(event: TouchEvent | Event): void {
20
+ if (typeof event.cancelable !== 'boolean' || event.cancelable) {
21
+ event.preventDefault();
22
+ }
23
+ }
24
+
19
25
  export function isMobile() {
20
26
  return (window as any).matchMedia?.('(max-width: 768px)').matches;
21
27
  }
@@ -1706,3 +1712,30 @@ export function isClickOnInput(e: React.MouseEvent<HTMLElement>) {
1706
1712
  }
1707
1713
  return false;
1708
1714
  }
1715
+
1716
+ // 计算字符串 hash
1717
+ export function hashCode(s: string): number {
1718
+ return s.split('').reduce((a, b) => {
1719
+ a = (a << 5) - a + b.charCodeAt(0);
1720
+ return a & a;
1721
+ }, 0);
1722
+ }
1723
+
1724
+ /**
1725
+ * 遍历 schema
1726
+ * @param json
1727
+ * @param mapper
1728
+ */
1729
+ export function JSONTraverse(
1730
+ json: any,
1731
+ mapper: (value: any, key: string | number, host: Object) => any
1732
+ ) {
1733
+ Object.keys(json).forEach(key => {
1734
+ const value: any = json[key];
1735
+ if (isPlainObject(value) || Array.isArray(value)) {
1736
+ JSONTraverse(value, mapper);
1737
+ } else {
1738
+ mapper(value, key, json);
1739
+ }
1740
+ });
1741
+ }
@@ -514,6 +514,12 @@ export const filters: {
514
514
  );
515
515
  },
516
516
 
517
+ substring: (input, start, end) => {
518
+ return input && typeof input === 'string'
519
+ ? input.substring(start, end)
520
+ : input;
521
+ },
522
+
517
523
  lowerCase: input =>
518
524
  input && typeof input === 'string' ? input.toLowerCase() : input,
519
525
  upperCase: input =>
@@ -3,7 +3,7 @@
3
3
  "outDir": "output/",
4
4
  "module": "commonjs",
5
5
  "target": "es5",
6
- "lib": ["es6", "dom", "ES2015"],
6
+ "lib": ["ES6", "DOM", "ES2015", "ES2021"],
7
7
  "sourceMap": true,
8
8
  "jsx": "react",
9
9
  "moduleResolution": "node",