amis 1.6.0 → 1.6.1-beta.0

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 (216) hide show
  1. package/README.md +1 -0
  2. package/lib/RootRenderer.d.ts +2 -0
  3. package/lib/RootRenderer.js +19 -1
  4. package/lib/RootRenderer.js.map +2 -2
  5. package/lib/SchemaRenderer.js +52 -1
  6. package/lib/SchemaRenderer.js.map +2 -2
  7. package/lib/Scoped.d.ts +2 -0
  8. package/lib/Scoped.js +27 -1
  9. package/lib/Scoped.js.map +2 -2
  10. package/lib/actions/Action.d.ts +33 -0
  11. package/lib/actions/Action.js +100 -0
  12. package/lib/actions/Action.js.map +13 -0
  13. package/lib/actions/AjaxAction.d.ts +14 -0
  14. package/lib/actions/AjaxAction.js +68 -0
  15. package/lib/actions/AjaxAction.js.map +13 -0
  16. package/lib/actions/BreakAction.d.ts +12 -0
  17. package/lib/actions/BreakAction.js +28 -0
  18. package/lib/actions/BreakAction.js.map +13 -0
  19. package/lib/actions/BroadcastAction.d.ts +12 -0
  20. package/lib/actions/BroadcastAction.js +40 -0
  21. package/lib/actions/BroadcastAction.js.map +13 -0
  22. package/lib/actions/CmptAction.d.ts +12 -0
  23. package/lib/actions/CmptAction.js +40 -0
  24. package/lib/actions/CmptAction.js.map +13 -0
  25. package/lib/actions/ContinueAction.d.ts +12 -0
  26. package/lib/actions/ContinueAction.js +28 -0
  27. package/lib/actions/ContinueAction.js.map +13 -0
  28. package/lib/actions/CopyAction.d.ts +12 -0
  29. package/lib/actions/CopyAction.js +35 -0
  30. package/lib/actions/CopyAction.js.map +13 -0
  31. package/lib/actions/CustomAction.d.ts +12 -0
  32. package/lib/actions/CustomAction.js +43 -0
  33. package/lib/actions/CustomAction.js.map +13 -0
  34. package/lib/actions/DialogAction.d.ts +12 -0
  35. package/lib/actions/DialogAction.js +31 -0
  36. package/lib/actions/DialogAction.js.map +13 -0
  37. package/lib/actions/DrawerAction.d.ts +12 -0
  38. package/lib/actions/DrawerAction.js +31 -0
  39. package/lib/actions/DrawerAction.js.map +13 -0
  40. package/lib/actions/EmailAction.d.ts +12 -0
  41. package/lib/actions/EmailAction.js +37 -0
  42. package/lib/actions/EmailAction.js.map +13 -0
  43. package/lib/actions/LoopAction.d.ts +12 -0
  44. package/lib/actions/LoopAction.js +93 -0
  45. package/lib/actions/LoopAction.js.map +13 -0
  46. package/lib/actions/OpenPageAction.d.ts +12 -0
  47. package/lib/actions/OpenPageAction.js +33 -0
  48. package/lib/actions/OpenPageAction.js.map +13 -0
  49. package/lib/actions/ParallelAction.d.ts +5 -0
  50. package/lib/actions/ParallelAction.js +33 -0
  51. package/lib/actions/ParallelAction.js.map +13 -0
  52. package/lib/actions/SwitchAction.d.ts +8 -0
  53. package/lib/actions/SwitchAction.js +45 -0
  54. package/lib/actions/SwitchAction.js.map +13 -0
  55. package/lib/actions/index.d.ts +18 -0
  56. package/lib/actions/index.js +22 -0
  57. package/lib/actions/index.js.map +13 -0
  58. package/lib/components/AnchorNav.d.ts +20 -20
  59. package/lib/components/Button.d.ts +20 -20
  60. package/lib/components/CalendarMobile.d.ts +112 -86
  61. package/lib/components/CalendarMobile.js +85 -31
  62. package/lib/components/CalendarMobile.js.map +2 -2
  63. package/lib/components/Collapse.d.ts +20 -20
  64. package/lib/components/DatePicker.js +9 -3
  65. package/lib/components/DatePicker.js.map +2 -2
  66. package/lib/components/DateRangePicker.js +1 -0
  67. package/lib/components/DateRangePicker.js.map +2 -2
  68. package/lib/components/InputBox.d.ts +21 -21
  69. package/lib/components/ListGroup.d.ts +21 -21
  70. package/lib/components/ListMenu.d.ts +84 -84
  71. package/lib/components/MonthRangePicker.js +2 -1
  72. package/lib/components/MonthRangePicker.js.map +2 -2
  73. package/lib/components/Radios.d.ts +21 -21
  74. package/lib/components/Rating.d.ts +21 -21
  75. package/lib/components/ResultBox.d.ts +84 -84
  76. package/lib/components/Select.d.ts +238 -238
  77. package/lib/components/Select.js +4 -3
  78. package/lib/components/Select.js.map +2 -2
  79. package/lib/components/Timeline.js +1 -1
  80. package/lib/components/Timeline.js.map +2 -2
  81. package/lib/components/TimelineItem.d.ts +3 -2
  82. package/lib/components/TimelineItem.js +8 -9
  83. package/lib/components/TimelineItem.js.map +2 -2
  84. package/lib/components/Tree.d.ts +84 -84
  85. package/lib/components/formula/plugin.js +0 -1
  86. package/lib/components/formula/plugin.js.map +2 -2
  87. package/lib/env.d.ts +4 -0
  88. package/lib/env.js.map +2 -2
  89. package/lib/factory.d.ts +2 -1
  90. package/lib/factory.js +78 -0
  91. package/lib/factory.js.map +2 -2
  92. package/lib/helper.css.map +1 -1
  93. package/lib/index.d.ts +2 -0
  94. package/lib/index.js +3 -1
  95. package/lib/index.js.map +2 -2
  96. package/lib/renderers/Action.d.ts +1 -1
  97. package/lib/renderers/Action.js +26 -10
  98. package/lib/renderers/Action.js.map +2 -2
  99. package/lib/renderers/Custom.d.ts +1 -1
  100. package/lib/renderers/Custom.js +1 -1
  101. package/lib/renderers/Custom.js.map +1 -1
  102. package/lib/renderers/Form/DiffEditor.d.ts +6 -0
  103. package/lib/renderers/Form/Editor.d.ts +6 -0
  104. package/lib/renderers/Form/Options.js +9 -7
  105. package/lib/renderers/Form/Options.js.map +2 -2
  106. package/lib/renderers/Form/Select.js +3 -3
  107. package/lib/renderers/Form/Select.js.map +2 -2
  108. package/lib/renderers/Form/index.js +8 -1
  109. package/lib/renderers/Form/index.js.map +2 -2
  110. package/lib/renderers/Link.d.ts +1 -1
  111. package/lib/renderers/Link.js +27 -6
  112. package/lib/renderers/Link.js.map +2 -2
  113. package/lib/renderers/Nav.d.ts +21 -21
  114. package/lib/renderers/Remark.d.ts +1 -1
  115. package/lib/store/formItem.js +1 -1
  116. package/lib/store/formItem.js.map +2 -2
  117. package/lib/themes/ang-ie11.css +180 -1
  118. package/lib/themes/ang.css +180 -1
  119. package/lib/themes/ang.css.map +1 -1
  120. package/lib/themes/antd-ie11.css +184 -2
  121. package/lib/themes/antd.css +184 -2
  122. package/lib/themes/antd.css.map +1 -1
  123. package/lib/themes/cxd-ie11.css +182 -8
  124. package/lib/themes/cxd.css +182 -8
  125. package/lib/themes/cxd.css.map +1 -1
  126. package/lib/themes/dark-ie11.css +182 -1
  127. package/lib/themes/dark.css +182 -1
  128. package/lib/themes/dark.css.map +1 -1
  129. package/lib/themes/default.css +182 -8
  130. package/lib/themes/default.css.map +1 -1
  131. package/lib/utils/api.js +14 -3
  132. package/lib/utils/api.js.map +2 -2
  133. package/lib/utils/debug.d.ts +26 -0
  134. package/lib/utils/debug.js +351 -0
  135. package/lib/utils/debug.js.map +13 -0
  136. package/lib/utils/renderer-event.d.ts +38 -0
  137. package/lib/utils/renderer-event.js +28 -0
  138. package/lib/utils/renderer-event.js.map +13 -0
  139. package/package.json +1 -1
  140. package/scss/_properties.scss +2 -0
  141. package/scss/_variables.scss +1 -0
  142. package/scss/components/_calendar.scss +4 -0
  143. package/scss/components/_debug.scss +167 -0
  144. package/scss/components/_popup.scss +1 -1
  145. package/scss/components/form/_date-range.scss +33 -0
  146. package/scss/components/form/_form.scss +2 -0
  147. package/scss/themes/_antd-variables.scss +4 -1
  148. package/scss/themes/_common.scss +2 -0
  149. package/scss/themes/_cxd-variables.scss +2 -0
  150. package/scss/themes/_dark-variables.scss +3 -0
  151. package/scss/themes/cxd.scss +0 -7
  152. package/sdk/ang-ie11.css +211 -1
  153. package/sdk/ang.css +213 -1
  154. package/sdk/antd-ie11.css +213 -2
  155. package/sdk/antd.css +217 -2
  156. package/sdk/charts.js +16 -16
  157. package/sdk/codemirror.js +7 -7
  158. package/sdk/color-picker.js +65 -65
  159. package/sdk/cropperjs.js +2 -2
  160. package/sdk/cxd-ie11.css +211 -8
  161. package/sdk/cxd.css +215 -8
  162. package/sdk/dark-ie11.css +211 -1
  163. package/sdk/dark.css +215 -1
  164. package/sdk/exceljs.js +1 -1
  165. package/sdk/helper.css.map +1 -1
  166. package/sdk/markdown.js +69 -69
  167. package/sdk/papaparse.js +1 -1
  168. package/sdk/renderers/Form/CityDB.js +1 -1
  169. package/sdk/rest.js +18 -18
  170. package/sdk/rich-text.js +62 -62
  171. package/sdk/sdk-ie11.css +211 -8
  172. package/sdk/sdk.css +215 -8
  173. package/sdk/sdk.js +1293 -1257
  174. package/sdk/thirds/hls.js/hls.js +1 -1
  175. package/sdk/thirds/mpegts.js/mpegts.js +1 -1
  176. package/sdk/tinymce.js +57 -57
  177. package/src/RootRenderer.tsx +27 -1
  178. package/src/SchemaRenderer.tsx +70 -4
  179. package/src/Scoped.tsx +46 -4
  180. package/src/actions/Action.ts +138 -0
  181. package/src/actions/AjaxAction.ts +58 -0
  182. package/src/actions/BreakAction.ts +27 -0
  183. package/src/actions/BroadcastAction.ts +41 -0
  184. package/src/actions/CmptAction.ts +36 -0
  185. package/src/actions/ContinueAction.ts +27 -0
  186. package/src/actions/CopyAction.ts +41 -0
  187. package/src/actions/CustomAction.ts +46 -0
  188. package/src/actions/DialogAction.ts +28 -0
  189. package/src/actions/DrawerAction.ts +28 -0
  190. package/src/actions/EmailAction.ts +38 -0
  191. package/src/actions/LoopAction.ts +77 -0
  192. package/src/actions/OpenPageAction.ts +39 -0
  193. package/src/actions/ParallelAction.ts +26 -0
  194. package/src/actions/SwitchAction.ts +35 -0
  195. package/src/actions/index.ts +20 -0
  196. package/src/components/CalendarMobile.tsx +127 -32
  197. package/src/components/DatePicker.tsx +32 -2
  198. package/src/components/DateRangePicker.tsx +2 -1
  199. package/src/components/MonthRangePicker.tsx +2 -1
  200. package/src/components/Select.tsx +4 -3
  201. package/src/components/Timeline.tsx +9 -4
  202. package/src/components/TimelineItem.tsx +62 -29
  203. package/src/components/formula/plugin.ts +0 -2
  204. package/src/env.tsx +22 -0
  205. package/src/factory.tsx +87 -1
  206. package/src/index.tsx +4 -0
  207. package/src/renderers/Action.tsx +11 -2
  208. package/src/renderers/Custom.tsx +1 -1
  209. package/src/renderers/Form/Options.tsx +15 -7
  210. package/src/renderers/Form/Select.tsx +7 -3
  211. package/src/renderers/Form/index.tsx +7 -1
  212. package/src/renderers/Link.tsx +18 -3
  213. package/src/store/formItem.ts +1 -1
  214. package/src/utils/api.ts +15 -2
  215. package/src/utils/debug.tsx +438 -0
  216. package/src/utils/renderer-event.ts +75 -0
@@ -865,7 +865,8 @@ export class DateRangePicker extends React.Component<
865
865
  {
866
866
  'is-disabled': disabled,
867
867
  'is-focused': isFocused,
868
- [`${ns}DateRangePicker--border${ucFirst(borderMode)}`]: borderMode
868
+ [`${ns}DateRangePicker--border${ucFirst(borderMode)}`]: borderMode,
869
+ 'is-mobile': useMobileUI && isMobile()
869
870
  },
870
871
  className
871
872
  )}
@@ -624,7 +624,8 @@ export class MonthRangePicker extends React.Component<
624
624
  `${ns}DateRangePicker`,
625
625
  {
626
626
  'is-disabled': disabled,
627
- 'is-focused': isFocused
627
+ 'is-focused': isFocused,
628
+ 'is-mobile': useMobileUI && isMobile()
628
629
  },
629
630
  className
630
631
  )}
@@ -184,7 +184,8 @@ export function normalizeOptions(
184
184
  } = {
185
185
  values: [],
186
186
  options: []
187
- }
187
+ },
188
+ valueField = 'value'
188
189
  ): Options {
189
190
  if (typeof options === 'string') {
190
191
  return options.split(',').map(item => {
@@ -225,7 +226,7 @@ export function normalizeOptions(
225
226
  });
226
227
  } else if (Array.isArray(options as Options)) {
227
228
  return (options as Options).map(item => {
228
- const value = item && item.value;
229
+ const value = item && item[valueField];
229
230
 
230
231
  const idx =
231
232
  value !== undefined && !item.children
@@ -242,7 +243,7 @@ export function normalizeOptions(
242
243
  };
243
244
 
244
245
  if (typeof option.children !== 'undefined') {
245
- option.children = normalizeOptions(option.children, share);
246
+ option.children = normalizeOptions(option.children, share, valueField);
246
247
  } else if (value !== undefined) {
247
248
  share.values.push(value);
248
249
  share.options.push(option);
@@ -15,7 +15,7 @@ export function Timeline(props: TimelineProps) {
15
15
  classnames: cx,
16
16
  direction = 'vertical',
17
17
  reverse = false,
18
- mode = 'right',
18
+ mode = 'right'
19
19
  } = props;
20
20
 
21
21
  const timelineDatasource = items?.slice();
@@ -23,9 +23,14 @@ export function Timeline(props: TimelineProps) {
23
23
  reverse && timelineDatasource?.reverse();
24
24
 
25
25
  return (
26
- <div className={cx('Timeline', `Timeline-${direction}`, `Timeline-${mode}`)}>
27
- {timelineDatasource?.map((item: TimelineItemProps) => <TimelineItem {...item} />)}
28
- </div>)
26
+ <div
27
+ className={cx('Timeline', `Timeline-${direction}`, `Timeline-${mode}`)}
28
+ >
29
+ {timelineDatasource?.map((item: TimelineItemProps, index: number) => (
30
+ <TimelineItem {...item} key={`TimelineItem-${index}`} />
31
+ ))}
32
+ </div>
33
+ );
29
34
  }
30
35
 
31
36
  export default themeable(Timeline);
@@ -13,11 +13,11 @@ export interface TimelineItemProps {
13
13
  /**
14
14
  * 事件名称
15
15
  */
16
- title?: string| ReactNode;
16
+ title?: string | ReactNode;
17
17
 
18
18
  /**
19
- * 详细内容
20
- */
19
+ * 详细内容
20
+ */
21
21
  detail?: string;
22
22
 
23
23
  /**
@@ -25,9 +25,9 @@ export interface TimelineItemProps {
25
25
  */
26
26
  detailCollapsedText?: string;
27
27
 
28
- /**
29
- * detail展开时文案
30
- */
28
+ /**
29
+ * detail展开时文案
30
+ */
31
31
  detailExpandedText?: string;
32
32
 
33
33
  /**
@@ -41,7 +41,12 @@ export interface TimelineItemProps {
41
41
  icon?: string | ReactNode;
42
42
  }
43
43
 
44
- export interface TimelineItem extends ThemeProps, LocaleProps, TimelineItemProps {}
44
+ export interface TimelineItem
45
+ extends ThemeProps,
46
+ LocaleProps,
47
+ TimelineItemProps {
48
+ key: string;
49
+ }
45
50
 
46
51
  export function TimelineItem(props: TimelineItem) {
47
52
  const {
@@ -54,25 +59,46 @@ export function TimelineItem(props: TimelineItem) {
54
59
  icon,
55
60
  classnames: cx,
56
61
  translate: __,
62
+ key
57
63
  } = props;
58
64
 
59
65
  const [detailVisible, setDetailVisible] = useState<boolean>(false);
60
66
 
61
- const renderDetail = (detail: string, detailCollapsedText: string = __('Timeline.collapseText'), detailExpandedText: string = __('Timeline.expandText')) : ReactNode => {
62
-
67
+ const renderDetail = (
68
+ detail: string,
69
+ detailCollapsedText: string = __('Timeline.collapseText'),
70
+ detailExpandedText: string = __('Timeline.expandText')
71
+ ): ReactNode => {
63
72
  return (
64
73
  <>
65
- <div className={cx('TimelineItem-detail-button')} onClick={() => setDetailVisible(!detailVisible)}>
74
+ <div
75
+ className={cx('TimelineItem-detail-button')}
76
+ onClick={() => setDetailVisible(!detailVisible)}
77
+ >
66
78
  {detailVisible ? detailExpandedText : detailCollapsedText}
67
- <div className={cx('TimelineItem-detail-arrow', `${detailVisible && 'TimelineItem-detail-arrow-top'}`)}>
68
- <Icon icon="tree-down"/>
79
+ <div
80
+ className={cx(
81
+ 'TimelineItem-detail-arrow',
82
+ `${detailVisible && 'TimelineItem-detail-arrow-top'}`
83
+ )}
84
+ >
85
+ <Icon icon="tree-down" />
69
86
  </div>
70
87
  </div>
71
- <div className={cx(`${detailVisible ? 'TimelineItem-detail-visible' : 'TimelineItem-detail-invisible'}`)}>
88
+ <div
89
+ className={cx(
90
+ `${
91
+ detailVisible
92
+ ? 'TimelineItem-detail-visible'
93
+ : 'TimelineItem-detail-invisible'
94
+ }`
95
+ )}
96
+ >
72
97
  {detail}
73
98
  </div>
74
- </>);
75
- }
99
+ </>
100
+ );
101
+ };
76
102
 
77
103
  // 判断是否为颜色值
78
104
  const isColorVal = color && /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(color);
@@ -81,27 +107,34 @@ export function TimelineItem(props: TimelineItem) {
81
107
  const levelColor = !isColorVal && color;
82
108
 
83
109
  return (
84
- <div className={cx('TimelineItem')}>
110
+ <div className={cx('TimelineItem')} key={key}>
85
111
  <div className={cx('TimelineItem-axle')}>
86
112
  <div className={cx('TimelineItem-line')}></div>
87
- {icon
88
- ? <div className={cx('TimelineItem-icon')}>
89
- <Icon icon={icon} className="icon"/>
90
- </div>
91
- : <div
92
- className={cx('TimelineItem-round',
93
- levelColor && `TimelineItem-round--${levelColor}`)}
94
- style={isColorVal ? {backgroundColor: color} : undefined}
95
- ></div>
96
- }
113
+ {icon ? (
114
+ <div className={cx('TimelineItem-icon')}>
115
+ <Icon icon={icon} className="icon" />
116
+ </div>
117
+ ) : (
118
+ <div
119
+ className={cx(
120
+ 'TimelineItem-round',
121
+ levelColor && `TimelineItem-round--${levelColor}`
122
+ )}
123
+ style={isColorVal ? {backgroundColor: color} : undefined}
124
+ ></div>
125
+ )}
97
126
  </div>
98
127
  <div className={cx('TimelineItem-content')}>
99
128
  <div className={cx('TimelineItem-time')}>{time}</div>
100
129
  <div className={cx('TimelineItem-title')}>{title}</div>
101
- {detail
102
- && <div className={cx('TimelineItem-detail')}>{renderDetail(detail, detailCollapsedText, detailExpandedText)}</div>}
130
+ {detail && (
131
+ <div className={cx('TimelineItem-detail')}>
132
+ {renderDetail(detail, detailCollapsedText, detailExpandedText)}
133
+ </div>
134
+ )}
103
135
  </div>
104
- </div>)
136
+ </div>
137
+ );
105
138
  }
106
139
 
107
140
  export default themeable(localeable(TimelineItem));
@@ -13,8 +13,6 @@ export function editorFactory(
13
13
  ) {
14
14
  registerLaunguageMode(cm);
15
15
 
16
- console.log('here', props.evalMode);
17
-
18
16
  return cm(dom, {
19
17
  value: props.value || '',
20
18
  autofocus: true,
package/src/env.tsx CHANGED
@@ -6,6 +6,11 @@ import {RendererConfig} from './factory';
6
6
  import {ThemeInstance} from './theme';
7
7
  import {Action, Api, Payload, Schema} from './types';
8
8
  import hoistNonReactStatic from 'hoist-non-react-statics';
9
+ import {
10
+ RendererEvent,
11
+ RendererEventListener,
12
+ EventListeners
13
+ } from './utils/renderer-event';
9
14
 
10
15
  export interface RendererEnv {
11
16
  fetcher: (api: Api, data?: any, options?: object) => Promise<Payload>;
@@ -54,6 +59,23 @@ export interface RendererEnv {
54
59
  ) => Promise<React.ReactType> | React.ReactType | JSX.Element | void;
55
60
  loadChartExtends?: () => void | Promise<void>;
56
61
  useMobileUI?: boolean;
62
+ bindEvent: (context: any) => (() => void) | undefined;
63
+ dispatchEvent: (
64
+ e:
65
+ | string
66
+ | React.ClipboardEvent<any>
67
+ | React.DragEvent<any>
68
+ | React.ChangeEvent<any>
69
+ | React.KeyboardEvent<any>
70
+ | React.TouchEvent<any>
71
+ | React.WheelEvent<any>
72
+ | React.AnimationEvent<any>
73
+ | React.TransitionEvent<any>
74
+ | React.MouseEvent<any>,
75
+ context: any,
76
+ data: any
77
+ ) => Promise<RendererEvent<any> | undefined>;
78
+ rendererEventListeners: RendererEventListener[];
57
79
  [propName: string]: any;
58
80
  }
59
81
 
package/src/factory.tsx CHANGED
@@ -4,6 +4,7 @@ import {getEnv, destroy} from 'mobx-state-tree';
4
4
  import {wrapFetcher} from './utils/api';
5
5
  import {normalizeLink} from './utils/normalizeLink';
6
6
  import {
7
+ createObject,
7
8
  findIndex,
8
9
  isObject,
9
10
  JSONTraverse,
@@ -33,6 +34,14 @@ import ScopedRootRenderer, {RootRenderProps} from './Root';
33
34
  import {HocStoreFactory} from './WithStore';
34
35
  import {EnvContext, RendererEnv} from './env';
35
36
  import {envOverwrite} from './envOverwrite';
37
+ import {
38
+ EventListeners,
39
+ createRendererEvent,
40
+ RendererEventListener,
41
+ OnEventProps,
42
+ RendererEvent
43
+ } from './utils/renderer-event';
44
+ import {runActions} from './actions/Action';
36
45
 
37
46
  export interface TestFunc {
38
47
  (
@@ -63,7 +72,7 @@ export interface RendererBasicConfig {
63
72
  // [propName:string]:any;
64
73
  }
65
74
 
66
- export interface RendererProps extends ThemeProps, LocaleProps {
75
+ export interface RendererProps extends ThemeProps, LocaleProps, OnEventProps {
67
76
  render: (region: string, node: SchemaNode, props?: any) => JSX.Element;
68
77
  env: RendererEnv;
69
78
  $path: string; // 当前组件所在的层级信息
@@ -259,6 +268,7 @@ const defaultOptions: RenderOptions = {
259
268
  richTextToken: '',
260
269
  useMobileUI: true, // 是否启用移动端原生 UI
261
270
  loadRenderer,
271
+ rendererEventListeners: [],
262
272
  fetcher() {
263
273
  return Promise.reject('fetcher is required');
264
274
  },
@@ -348,6 +358,82 @@ const defaultOptions: RenderOptions = {
348
358
  },
349
359
  // 用于跟踪用户在界面中的各种操作
350
360
  tracker(eventTrack: EventTrack, props: PlainObject) {},
361
+ // 返回解绑函数
362
+ bindEvent(renderer: any) {
363
+ const listeners: EventListeners = renderer.props.$schema.onEvent;
364
+ if (listeners) {
365
+ // 暂存
366
+ for (let key of Object.keys(listeners)) {
367
+ this.rendererEventListeners.push({
368
+ renderer,
369
+ type: key,
370
+ weight: listeners[key].weight || 0,
371
+ actions: listeners[key].actions
372
+ });
373
+ }
374
+
375
+ return () => {
376
+ this.rendererEventListeners = this.rendererEventListeners.filter(
377
+ (item: RendererEventListener) => item.renderer === renderer
378
+ );
379
+ };
380
+ }
381
+
382
+ return undefined;
383
+ },
384
+ async dispatchEvent(
385
+ e: string | React.MouseEvent<any>,
386
+ renderer: React.Component<RendererProps>,
387
+ data: any,
388
+ broadcast: RendererEvent<any>
389
+ ) {
390
+ const eventName = typeof e === 'string' ? e : e.type;
391
+ if (!broadcast) {
392
+ const eventConfig = renderer?.props?.onEvent?.[eventName];
393
+
394
+ if (!eventConfig) {
395
+ // 没命中也没关系
396
+ return Promise.resolve(undefined);
397
+ }
398
+ }
399
+
400
+ // 没有可处理的监听
401
+ if (!this.rendererEventListeners.length) {
402
+ return Promise.resolve();
403
+ }
404
+
405
+ // 如果是广播动作,就直接复用
406
+ const rendererEvent =
407
+ broadcast ||
408
+ createRendererEvent(eventName, {
409
+ env: this,
410
+ nativeEvent: e,
411
+ data
412
+ });
413
+
414
+ // 过滤&排序
415
+ const listeners = this.rendererEventListeners
416
+ .filter(
417
+ (item: RendererEventListener) =>
418
+ item.type === eventName &&
419
+ (broadcast ? true : item.renderer === renderer)
420
+ )
421
+ .sort(
422
+ (prev: RendererEventListener, next: RendererEventListener) =>
423
+ next.weight - prev.weight
424
+ );
425
+
426
+ for (let listener of listeners) {
427
+ await runActions(listener.actions, listener.renderer, rendererEvent);
428
+
429
+ // 停止后续监听器执行
430
+ if (rendererEvent.stoped) {
431
+ break;
432
+ }
433
+ }
434
+
435
+ return rendererEvent;
436
+ },
351
437
  rendererResolver: resolveRenderer,
352
438
  replaceTextIgnoreKeys: [
353
439
  'type',
package/src/index.tsx CHANGED
@@ -41,6 +41,8 @@ import {
41
41
 
42
42
  import './locale/zh-CN';
43
43
 
44
+ import './utils/debug';
45
+
44
46
  import animation from './utils/Animation';
45
47
 
46
48
  export * from './Schema';
@@ -212,6 +214,8 @@ import {
212
214
  } from './theme';
213
215
  const classPrefix = getClassPrefix();
214
216
 
217
+ import './actions';
218
+
215
219
  export * from './components/index';
216
220
 
217
221
  export {
@@ -405,6 +405,7 @@ import {generateIcon} from '../utils/icon';
405
405
  import {BadgeSchema, withBadge} from '../components/Badge';
406
406
  import {normalizeApi, str2AsyncFunction} from '../utils/api';
407
407
  import {TooltipWrapper} from '../components/TooltipWrapper';
408
+ import handleAction from '../utils/handleAction';
408
409
 
409
410
  // 构造一个假的 React 事件避免可能的报错,主要用于快捷键功能
410
411
  // 来自 https://stackoverflow.com/questions/27062455/reactjs-can-i-create-my-own-syntheticevent
@@ -828,8 +829,16 @@ export class ActionRenderer extends React.Component<
828
829
  }
829
830
  > {
830
831
  @autobind
831
- handleAction(e: React.MouseEvent<any> | void | null, action: any) {
832
- const {env, onAction, data, ignoreConfirm} = this.props;
832
+ async handleAction(e: React.MouseEvent<any> | void | null, action: any) {
833
+ const {env, onAction, data, ignoreConfirm, dispatchEvent} = this.props;
834
+
835
+ // 触发渲染器事件
836
+ const rendererEvent = await dispatchEvent(e as React.MouseEvent<any>, data);
837
+
838
+ // 阻止原有动作执行
839
+ if (rendererEvent?.prevented) {
840
+ return;
841
+ }
833
842
 
834
843
  if (!ignoreConfirm && action.confirmText && env.confirm) {
835
844
  env
@@ -100,7 +100,7 @@ export class Custom extends React.Component<CustomProps, object> {
100
100
  this.onMount(this.dom.current, value, onChange, this.props);
101
101
  }
102
102
 
103
- componentwillUnmount() {
103
+ componentWillUnmount() {
104
104
  this.onUnmount(this.props);
105
105
  }
106
106
 
@@ -300,7 +300,7 @@ export function registerOptionsControl(config: OptionsConfig) {
300
300
 
301
301
  if (formItem) {
302
302
  formItem.setOptions(
303
- normalizeOptions(options),
303
+ normalizeOptions(options, undefined, valueField),
304
304
  this.changeOptionValue,
305
305
  data
306
306
  );
@@ -383,14 +383,14 @@ export function registerOptionsControl(config: OptionsConfig) {
383
383
 
384
384
  if (prevProps.options !== props.options && formItem) {
385
385
  formItem.setOptions(
386
- normalizeOptions(props.options || []),
386
+ normalizeOptions(props.options || [], undefined, props.valueField),
387
387
  this.changeOptionValue,
388
388
  props.data
389
389
  );
390
390
  this.normalizeValue();
391
391
  } else if (
392
392
  config.autoLoadOptionsFromSource !== false &&
393
- props.formInited &&
393
+ (props.formInited || typeof props.formInited === 'undefined') &&
394
394
  props.source &&
395
395
  formItem &&
396
396
  (prevProps.source !== props.source || prevProps.data !== props.data)
@@ -409,7 +409,11 @@ export function registerOptionsControl(config: OptionsConfig) {
409
409
 
410
410
  if (prevOptions !== options) {
411
411
  formItem.setOptions(
412
- normalizeOptions(options || []),
412
+ normalizeOptions(
413
+ options || [],
414
+ undefined,
415
+ props.valueField || 'value'
416
+ ),
413
417
  this.changeOptionValue,
414
418
  props.data
415
419
  );
@@ -707,14 +711,16 @@ export function registerOptionsControl(config: OptionsConfig) {
707
711
 
708
712
  @autobind
709
713
  reloadOptions(setError?: boolean, isInit = false) {
710
- const {source, formItem, data, onChange, setPrinstineValue, selectFirst} =
714
+ const {source, formItem, data, onChange, setPrinstineValue, valueField} =
711
715
  this.props;
712
716
 
713
717
  if (formItem && isPureVariable(source as string)) {
714
718
  isAlive(formItem) &&
715
719
  formItem.setOptions(
716
720
  normalizeOptions(
717
- resolveVariableAndFilter(source as string, data, '| raw') || []
721
+ resolveVariableAndFilter(source as string, data, '| raw') || [],
722
+ undefined,
723
+ valueField
718
724
  ),
719
725
  this.changeOptionValue,
720
726
  data
@@ -808,7 +814,9 @@ export function registerOptionsControl(config: OptionsConfig) {
808
814
  const formItem = this.props.formItem as IFormItemStore;
809
815
  formItem &&
810
816
  formItem.setOptions(
811
- skipNormalize ? options : normalizeOptions(options || []),
817
+ skipNormalize
818
+ ? options
819
+ : normalizeOptions(options || [], undefined, this.props.valueField),
812
820
  this.changeOptionValue,
813
821
  this.props.data
814
822
  );
@@ -232,8 +232,12 @@ export default class SelectControl extends React.Component<SelectProps, any> {
232
232
  }
233
233
 
234
234
  mergeOptions(options: Array<object>) {
235
- const {selectedOptions} = this.props;
236
- let combinedOptions = normalizeOptions(options).concat();
235
+ const {selectedOptions, valueField = 'value'} = this.props;
236
+ let combinedOptions = normalizeOptions(
237
+ options,
238
+ undefined,
239
+ valueField
240
+ ).concat();
237
241
 
238
242
  if (Array.isArray(selectedOptions) && selectedOptions.length) {
239
243
  selectedOptions.forEach(option => {
@@ -322,7 +326,7 @@ export default class SelectControl extends React.Component<SelectProps, any> {
322
326
  popOverContainer={
323
327
  mobileUI && env && env.getModalContainer
324
328
  ? env.getModalContainer
325
- : undefined
329
+ : rest.popOverContainer
326
330
  }
327
331
  borderMode={borderMode}
328
332
  placeholder={placeholder}
@@ -1133,7 +1133,13 @@ export default class Form extends React.Component<FormProps, object> {
1133
1133
  });
1134
1134
  } else if (action.actionType === 'reload') {
1135
1135
  store.setCurrentAction(action);
1136
- action.target && this.reloadTarget(action.target, data);
1136
+ if (action.target) {
1137
+ this.reloadTarget(action.target, data);
1138
+ } else {
1139
+ // 刷自己
1140
+ this.receive(data);
1141
+ }
1142
+ // action.target && this.reloadTarget(action.target, data);
1137
1143
  } else if (onAction) {
1138
1144
  // 不识别的丢给上层去处理。
1139
1145
  return onAction(e, action, data, throwErrors, delegate || this.context);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import {Renderer, RendererProps} from '../factory';
3
3
  import {BaseSchema, SchemaTpl} from '../Schema';
4
- import {autobind, getPropValue} from '../utils/helper';
4
+ import {autobind, createObject, getPropValue} from '../utils/helper';
5
5
  import {filter} from '../utils/tpl';
6
6
  import {BadgeSchema, withBadge} from '../components/Badge';
7
7
  import Link from '../components/Link';
@@ -58,8 +58,8 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
58
58
  htmlTarget: ''
59
59
  };
60
60
 
61
- handleClick(href: string) {
62
- const {env, blank, body} = this.props;
61
+ async handleClick(href: string) {
62
+ const {env, blank, body, dispatchEvent, data} = this.props;
63
63
  env?.tracker(
64
64
  {
65
65
  eventType: 'url',
@@ -68,6 +68,21 @@ export class LinkCmpt extends React.Component<LinkProps, object> {
68
68
  },
69
69
  this.props
70
70
  );
71
+ // 触发渲染器事件
72
+ const rendererEvent = await dispatchEvent(
73
+ 'click',
74
+ createObject(data, {
75
+ // 注意:每个组件都必须把数据链带上
76
+ url: href,
77
+ blank,
78
+ label: body
79
+ })
80
+ );
81
+
82
+ // 阻止原有动作执行
83
+ if (rendererEvent?.prevented) {
84
+ return;
85
+ }
71
86
  }
72
87
 
73
88
  getHref() {}
@@ -595,7 +595,7 @@ export const FormItemStore = StoreNode.named('FormItemStore')
595
595
  json.data ||
596
596
  [];
597
597
 
598
- options = normalizeOptions(options as any);
598
+ options = normalizeOptions(options as any, undefined, self.valueField);
599
599
 
600
600
  if (config?.extendsOptions && self.selectedOptions.length > 0) {
601
601
  self.selectedOptions.forEach((item: any) => {
package/src/utils/api.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  uuid
16
16
  } from './helper';
17
17
  import isPlainObject from 'lodash/isPlainObject';
18
+ import {debug} from './debug';
18
19
 
19
20
  const rSchema = /(?:^|raw\:)(get|post|put|delete|patch|options|head|jsonp):/i;
20
21
 
@@ -265,7 +266,10 @@ export function responseAdaptor(ret: fetcherResult, api: ApiObject) {
265
266
  payload.errors = data.errors;
266
267
  }
267
268
 
269
+ debug('api', 'response', payload);
270
+
268
271
  if (payload.ok && api.responseData) {
272
+ debug('api', 'before dataMapping', payload.data);
269
273
  const responseData = dataMapping(
270
274
  api.responseData,
271
275
 
@@ -280,7 +284,7 @@ export function responseAdaptor(ret: fetcherResult, api: ApiObject) {
280
284
  undefined,
281
285
  api.convertKeyToPath
282
286
  );
283
- console.debug('responseData', responseData);
287
+ debug('api', 'after dataMapping', responseData);
284
288
  payload.data = responseData;
285
289
  }
286
290
 
@@ -294,7 +298,11 @@ export function wrapFetcher(
294
298
  return function (api, data, options) {
295
299
  api = buildApi(api, data, options) as ApiObject;
296
300
 
297
- api.requestAdaptor && (api = api.requestAdaptor(api) || api);
301
+ if (api.requestAdaptor) {
302
+ debug('api', 'before requestAdaptor', api);
303
+ api = api.requestAdaptor(api) || api;
304
+ debug('api', 'after requestAdaptor', api);
305
+ }
298
306
 
299
307
  if (api.data && (hasFile(api.data) || api.dataType === 'form-data')) {
300
308
  api.data =
@@ -319,6 +327,8 @@ export function wrapFetcher(
319
327
  api.headers['Content-Type'] = 'application/json';
320
328
  }
321
329
 
330
+ debug('api', 'request api', api);
331
+
322
332
  tracker?.(
323
333
  {eventType: 'api', eventData: omit(api, ['config', 'data', 'body'])},
324
334
  api.data
@@ -355,12 +365,15 @@ export function wrapAdaptor(promise: Promise<fetcherResult>, api: ApiObject) {
355
365
  return adaptor
356
366
  ? promise
357
367
  .then(async response => {
368
+ debug('api', 'before adaptor data', (response as any).data);
358
369
  let result = adaptor((response as any).data, response, api);
359
370
 
360
371
  if (result?.then) {
361
372
  result = await result;
362
373
  }
363
374
 
375
+ debug('api', 'after adaptor data', result);
376
+
364
377
  return {
365
378
  ...response,
366
379
  data: result