amis 1.4.2-beta.13 → 1.4.2-beta.15

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 (128) hide show
  1. package/lib/Schema.d.ts +4 -3
  2. package/lib/Schema.js.map +1 -1
  3. package/lib/components/AssociatedSelection.js +2 -2
  4. package/lib/components/AssociatedSelection.js.map +2 -2
  5. package/lib/components/Checkbox.d.ts +20 -20
  6. package/lib/components/Collapse.d.ts +51 -23
  7. package/lib/components/Collapse.js +69 -11
  8. package/lib/components/Collapse.js.map +2 -2
  9. package/lib/components/CollapseGroup.d.ts +88 -0
  10. package/lib/components/CollapseGroup.js +81 -0
  11. package/lib/components/CollapseGroup.js.map +13 -0
  12. package/lib/components/Editor.d.ts +84 -84
  13. package/lib/components/GridNav.d.ts +52 -0
  14. package/lib/components/GridNav.js +123 -0
  15. package/lib/components/GridNav.js.map +13 -0
  16. package/lib/components/ListGroup.d.ts +21 -21
  17. package/lib/components/Tabs.d.ts +20 -20
  18. package/lib/components/TabsTransfer.d.ts +84 -84
  19. package/lib/components/Toast.d.ts +86 -85
  20. package/lib/components/Toast.js +6 -3
  21. package/lib/components/Toast.js.map +2 -2
  22. package/lib/components/Transfer.d.ts +84 -84
  23. package/lib/components/TransferDropDown.d.ts +84 -84
  24. package/lib/components/Tree.d.ts +115 -84
  25. package/lib/components/Tree.js +183 -30
  26. package/lib/components/Tree.js.map +2 -2
  27. package/lib/envOverwrite.d.ts +1 -1
  28. package/lib/envOverwrite.js +24 -9
  29. package/lib/envOverwrite.js.map +2 -2
  30. package/lib/factory.d.ts +11 -1
  31. package/lib/factory.js +31 -4
  32. package/lib/factory.js.map +2 -2
  33. package/lib/icons/drag-bar.js +10 -3
  34. package/lib/index.d.ts +2 -0
  35. package/lib/index.js +3 -1
  36. package/lib/index.js.map +2 -2
  37. package/lib/renderers/Collapse.d.ts +25 -20
  38. package/lib/renderers/Collapse.js +10 -73
  39. package/lib/renderers/Collapse.js.map +2 -2
  40. package/lib/renderers/CollapseGroup.d.ts +42 -0
  41. package/lib/renderers/CollapseGroup.js +33 -0
  42. package/lib/renderers/CollapseGroup.js.map +13 -0
  43. package/lib/renderers/Form/InputCity.d.ts +84 -84
  44. package/lib/renderers/Form/Item.js +2 -1
  45. package/lib/renderers/Form/Item.js.map +2 -2
  46. package/lib/renderers/GridNav.d.ts +99 -0
  47. package/lib/renderers/GridNav.js +82 -0
  48. package/lib/renderers/GridNav.js.map +13 -0
  49. package/lib/store/formItem.js +44 -4
  50. package/lib/store/formItem.js.map +2 -2
  51. package/lib/themes/ang-ie11.css +194 -27
  52. package/lib/themes/ang.css +194 -27
  53. package/lib/themes/ang.css.map +1 -1
  54. package/lib/themes/antd-ie11.css +194 -27
  55. package/lib/themes/antd.css +194 -27
  56. package/lib/themes/antd.css.map +1 -1
  57. package/lib/themes/cxd-ie11.css +201 -34
  58. package/lib/themes/cxd.css +201 -34
  59. package/lib/themes/cxd.css.map +1 -1
  60. package/lib/themes/dark-ie11.css +194 -27
  61. package/lib/themes/dark.css +194 -27
  62. package/lib/themes/dark.css.map +1 -1
  63. package/lib/themes/default.css +201 -34
  64. package/lib/themes/default.css.map +1 -1
  65. package/lib/types.d.ts +1 -1
  66. package/lib/types.js.map +1 -1
  67. package/lib/utils/api.d.ts +1 -0
  68. package/lib/utils/api.js +77 -6
  69. package/lib/utils/api.js.map +2 -2
  70. package/lib/utils/helper.d.ts +6 -0
  71. package/lib/utils/helper.js +18 -1
  72. package/lib/utils/helper.js.map +2 -2
  73. package/package.json +1 -1
  74. package/schema.json +242 -34
  75. package/scss/components/_anchor-nav.scss +1 -0
  76. package/scss/components/_collapse-group.scss +11 -0
  77. package/scss/components/_collapse.scss +33 -22
  78. package/scss/components/_grid-nav.scss +128 -0
  79. package/scss/components/_nav.scss +1 -1
  80. package/scss/components/_spinner.scss +5 -4
  81. package/scss/components/_table.scss +6 -0
  82. package/scss/components/form/_combo.scss +4 -0
  83. package/scss/components/form/_tree.scss +42 -0
  84. package/scss/themes/_common.scss +2 -0
  85. package/scss/themes/_cxd-variables.scss +6 -7
  86. package/scss/themes/cxd.scss +1 -0
  87. package/sdk/ang-ie11.css +227 -28
  88. package/sdk/ang.css +227 -27
  89. package/sdk/antd-ie11.css +227 -28
  90. package/sdk/antd.css +227 -27
  91. package/sdk/charts.js +13 -13
  92. package/sdk/color-picker.js +65 -65
  93. package/sdk/cropperjs.js +2 -2
  94. package/sdk/cxd-ie11.css +233 -32
  95. package/sdk/cxd.css +234 -34
  96. package/sdk/dark-ie11.css +227 -28
  97. package/sdk/dark.css +227 -27
  98. package/sdk/exceljs.js +1 -1
  99. package/sdk/markdown.js +69 -69
  100. package/sdk/papaparse.js +1 -1
  101. package/sdk/renderers/Form/CityDB.js +1 -1
  102. package/sdk/rest.js +18 -18
  103. package/sdk/rich-text.js +62 -62
  104. package/sdk/sdk-ie11.css +233 -32
  105. package/sdk/sdk.css +234 -34
  106. package/sdk/sdk.js +1179 -1145
  107. package/sdk/thirds/hls.js/hls.js +1 -1
  108. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  109. package/sdk/tinymce.js +57 -57
  110. package/src/Schema.ts +5 -1
  111. package/src/components/AssociatedSelection.tsx +3 -1
  112. package/src/components/Collapse.tsx +144 -20
  113. package/src/components/CollapseGroup.tsx +130 -0
  114. package/src/components/GridNav.tsx +233 -0
  115. package/src/components/Toast.tsx +23 -16
  116. package/src/components/Tree.tsx +194 -8
  117. package/src/envOverwrite.ts +20 -7
  118. package/src/factory.tsx +52 -6
  119. package/src/icons/drag-bar.svg +12 -6
  120. package/src/index.tsx +2 -0
  121. package/src/renderers/Collapse.tsx +70 -117
  122. package/src/renderers/CollapseGroup.tsx +80 -0
  123. package/src/renderers/GridNav.tsx +204 -0
  124. package/src/store/formItem.ts +94 -2
  125. package/src/types.ts +1 -1
  126. package/src/utils/api.ts +93 -6
  127. package/src/utils/helper.ts +19 -0
  128. package/tsconfig-for-declaration.json +1 -1
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,
@@ -1706,3 +1706,22 @@ export function isClickOnInput(e: React.MouseEvent<HTMLElement>) {
1706
1706
  }
1707
1707
  return false;
1708
1708
  }
1709
+
1710
+ /**
1711
+ * 遍历 schema
1712
+ * @param json
1713
+ * @param mapper
1714
+ */
1715
+ export function JSONTraverse(
1716
+ json: any,
1717
+ mapper: (value: any, key: string | number, host: Object) => any
1718
+ ) {
1719
+ Object.keys(json).forEach(key => {
1720
+ const value: any = json[key];
1721
+ if (isPlainObject(value) || Array.isArray(value)) {
1722
+ JSONTraverse(value, mapper);
1723
+ } else {
1724
+ mapper(value, key, json);
1725
+ }
1726
+ });
1727
+ }
@@ -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",