shared.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { ISchema } from '@formily/json-schema'
  2. import { ReactionsSetter, DataSourceSetter, ValidatorSetter } from '@designable/formily-setters'
  3. import { FormItemSwitcher } from '../../common/FormItemSwitcher'
  4. import { AllSchemas } from '../../schemas'
  5. export const createComponentSchema = (component: ISchema, decorator: ISchema) => {
  6. return {
  7. 'component-group': component && {
  8. type: 'void',
  9. 'x-component': 'CollapseItem',
  10. 'x-reactions': {
  11. fulfill: {
  12. state: {
  13. visible: '{{!!$form.values["x-component"]}}'
  14. }
  15. }
  16. },
  17. properties: {
  18. 'x-component-props': component
  19. }
  20. },
  21. 'decorator-group': decorator && {
  22. type: 'void',
  23. 'x-component': 'CollapseItem',
  24. 'x-component-props': { defaultExpand: false },
  25. 'x-reactions': {
  26. fulfill: {
  27. state: {
  28. visible: '{{!!$form.values["x-decorator"]}}'
  29. }
  30. }
  31. },
  32. properties: {
  33. 'x-decorator-props': decorator
  34. }
  35. }
  36. // 'component-style-group': {
  37. // type: 'void',
  38. // 'x-component': 'CollapseItem',
  39. // 'x-component-props': { defaultExpand: false },
  40. // 'x-reactions': {
  41. // fulfill: {
  42. // state: {
  43. // visible: '{{!!$form.values["x-component"]}}'
  44. // }
  45. // }
  46. // },
  47. // properties: {
  48. // 'x-component-props.style': AllSchemas.CSSStyle
  49. // }
  50. // },
  51. // 'decorator-style-group': {
  52. // type: 'void',
  53. // 'x-component': 'CollapseItem',
  54. // 'x-component-props': { defaultExpand: false },
  55. // 'x-reactions': {
  56. // fulfill: {
  57. // state: {
  58. // visible: '{{!!$form.values["x-decorator"]}}'
  59. // }
  60. // }
  61. // },
  62. // properties: {
  63. // 'x-decorator-props.style': AllSchemas.CSSStyle
  64. // }
  65. // }
  66. }
  67. }
  68. export const createFieldSchema = (
  69. component?: ISchema,
  70. decorator: ISchema = AllSchemas.FormItem
  71. ): ISchema => {
  72. return {
  73. type: 'object',
  74. properties: {
  75. 'field-group': {
  76. type: 'void',
  77. 'x-component': 'CollapseItem',
  78. properties: {
  79. // name: {
  80. // type: 'string',
  81. // 'x-decorator': 'FormItem',
  82. // 'x-component': 'Input'
  83. // },
  84. title: {
  85. type: 'string',
  86. 'x-decorator': 'FormItem',
  87. 'x-component': 'Input'
  88. },
  89. description: {
  90. type: 'string',
  91. 'x-decorator': 'FormItem',
  92. 'x-component': 'Input.TextArea'
  93. },
  94. 'x-display': {
  95. type: 'string',
  96. enum: ['visible', 'hidden', 'none', ''],
  97. 'x-decorator': 'FormItem',
  98. 'x-component': 'Select',
  99. 'x-component-props': {
  100. defaultValue: 'visible'
  101. }
  102. },
  103. 'x-pattern': {
  104. type: 'string',
  105. enum: ['editable', 'disabled', 'readOnly', 'readPretty', ''],
  106. 'x-decorator': 'FormItem',
  107. 'x-component': 'Select',
  108. 'x-component-props': {
  109. defaultValue: 'editable'
  110. }
  111. },
  112. default: {
  113. 'x-decorator': 'FormItem',
  114. 'x-component': 'ValueInput'
  115. },
  116. enum: {
  117. 'x-decorator': 'FormItem',
  118. 'x-component': DataSourceSetter
  119. },
  120. 'x-reactions': {
  121. 'x-decorator': 'FormItem',
  122. 'x-component': ReactionsSetter
  123. },
  124. 'x-validator': {
  125. type: 'array',
  126. 'x-component': ValidatorSetter
  127. },
  128. required: {
  129. type: 'boolean',
  130. 'x-decorator': 'FormItem',
  131. 'x-component': 'Switch'
  132. }
  133. }
  134. },
  135. ...createComponentSchema(component, decorator)
  136. }
  137. }
  138. }
  139. export const createVoidFieldSchema = (
  140. component?: ISchema,
  141. decorator: ISchema = AllSchemas.FormItem
  142. ) => {
  143. return {
  144. type: 'object',
  145. properties: {
  146. 'field-group': {
  147. type: 'void',
  148. 'x-component': 'CollapseItem',
  149. properties: {
  150. name: {
  151. type: 'string',
  152. 'x-decorator': 'FormItem',
  153. 'x-component': 'Input'
  154. },
  155. title: {
  156. type: 'string',
  157. 'x-decorator': 'FormItem',
  158. 'x-component': 'Input',
  159. 'x-reactions': {
  160. fulfill: {
  161. state: {
  162. hidden: '{{$form.values["x-decorator"] !== "FormItem"}}'
  163. }
  164. }
  165. }
  166. },
  167. description: {
  168. type: 'string',
  169. 'x-decorator': 'FormItem',
  170. 'x-component': 'Input.TextArea',
  171. 'x-reactions': {
  172. fulfill: {
  173. state: {
  174. hidden: '{{$form.values["x-decorator"] !== "FormItem"}}'
  175. }
  176. }
  177. }
  178. },
  179. 'x-display': {
  180. type: 'string',
  181. enum: ['visible', 'hidden', 'none', ''],
  182. 'x-decorator': 'FormItem',
  183. 'x-component': 'Select',
  184. 'x-component-props': {
  185. defaultValue: 'visible'
  186. }
  187. },
  188. 'x-pattern': {
  189. type: 'string',
  190. enum: ['editable', 'disabled', 'readOnly', 'readPretty', ''],
  191. 'x-decorator': 'FormItem',
  192. 'x-component': 'Select',
  193. 'x-component-props': {
  194. defaultValue: 'editable'
  195. }
  196. },
  197. 'x-reactions': {
  198. 'x-decorator': 'FormItem',
  199. 'x-component': ReactionsSetter
  200. },
  201. 'x-decorator': {
  202. type: 'string',
  203. 'x-decorator': 'FormItem',
  204. 'x-component': FormItemSwitcher
  205. }
  206. }
  207. },
  208. ...createComponentSchema(component, decorator)
  209. }
  210. }
  211. }