@cniot/mdd-editor 0.2.0-beta.9 → 0.3.1

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 (75) hide show
  1. package/README.MD +308 -11
  2. package/build/index.cjs.js +27 -19
  3. package/build/index.es.js +3731 -446
  4. package/build/style.css +1 -1
  5. package/package.json +1 -1
  6. package/src/ai/LocalAIDrawer.jsx +217 -0
  7. package/src/ai/bridgeClient.js +168 -0
  8. package/src/ai/pageIR.js +148 -0
  9. package/src/components/address-select/formily.jsx +1 -1
  10. package/src/components/ajax-schema-form/formily-table-form-proxy.jsx +1 -1
  11. package/src/components/ajax-schema-form/formily.jsx +1 -1
  12. package/src/components/ajax-schema-form/table-form-proxy.jsx +1 -1
  13. package/src/components/ajax-schema-form/table-form.jsx +1 -1
  14. package/src/components/data-source-select/formily.jsx +1 -1
  15. package/src/components/dynamic-value/base/formily.jsx +1 -1
  16. package/src/components/dynamic-value/date/formily.jsx +1 -1
  17. package/src/components/formily-select/index.tsx +1 -1
  18. package/src/components/params-select/formily.jsx +1 -1
  19. package/src/components/time-range/formily.jsx +1 -1
  20. package/src/hooks/useSchema.jsx +5 -5
  21. package/src/hooks/useSwagger.jsx +2 -2
  22. package/src/schema/base-schema/AjaxSchema.js +1 -1
  23. package/src/schema/base-schema/AjaxSchemaQueue.js +1 -1
  24. package/src/schema/blocks/edit-table.js +57 -0
  25. package/src/schema/blocks/filter.js +49 -0
  26. package/src/schema/blocks/form.js +49 -0
  27. package/src/schema/blocks/index.js +32 -10
  28. package/src/schema/blocks/table.js +3 -4
  29. package/src/schema/detail/detail-item.js +5 -5
  30. package/src/schema/detail/index.js +26 -18
  31. package/src/schema/edit-table/header-toolbar.js +1 -1
  32. package/src/schema/edit-table/index.js +10 -5
  33. package/src/schema/edit-table/table.js +10 -2
  34. package/src/schema/formily-form/data-source.js +1 -1
  35. package/src/schema/formily-form/form-schema.js +1 -1
  36. package/src/schema/formily-form/index.js +8 -8
  37. package/src/schema/formily-form-v2/form-info.js +2 -2
  38. package/src/schema/formily-form-v2/form-items.js +1 -1
  39. package/src/schema/formily-form-v2/index.js +3 -3
  40. package/src/schema/ftp/data-source.js +1 -1
  41. package/src/schema/ftp/filter.js +2 -2
  42. package/src/schema/ftp/header-toolbar.js +1 -1
  43. package/src/schema/ftp/index.js +4 -4
  44. package/src/schema/ftp/middle-item.js +1 -1
  45. package/src/schema/ftp/table.js +9 -3
  46. package/src/schema/util.js +3 -3
  47. package/src/services/index.js +1 -1
  48. package/src/template/blocks/EditTable.jsx +62 -0
  49. package/src/template/blocks/Filter.jsx +137 -0
  50. package/src/template/blocks/Form.jsx +136 -0
  51. package/src/template/blocks/Table.jsx +4 -4
  52. package/src/template/const.js +18 -4
  53. package/src/template/detail/DetailItems.jsx +6 -1
  54. package/src/template/detail/components/Actions.jsx +1 -1
  55. package/src/template/detail/components/DetailCard.jsx +8 -5
  56. package/src/template/detail/components/DetailColumns.jsx +193 -113
  57. package/src/template/detail/components/DetailCustom.jsx +2 -2
  58. package/src/template/detail/components/DetailTable.jsx +13 -8
  59. package/src/template/detail/components/MultiAjaxSchemaForm.jsx +1 -1
  60. package/src/template/edit-table/HeaderToolbar.jsx +3 -2
  61. package/src/template/edit-table/Table.jsx +56 -3
  62. package/src/template/formily-form-v2/FormInfo.jsx +1 -1
  63. package/src/template/formily-form-v2/FormItems.jsx +4 -8
  64. package/src/template/formilyform/components/AsyncDataSourceSetter/index.tsx +1 -1
  65. package/src/template/formilyform/components/SubmitActionSetter/index.tsx +1 -1
  66. package/src/template/ftp/DataSource.jsx +1 -1
  67. package/src/template/ftp/Filter.jsx +14 -7
  68. package/src/template/ftp/HeaderToolbar.jsx +8 -4
  69. package/src/template/ftp/Middle.jsx +11 -7
  70. package/src/template/ftp/Table.jsx +143 -12
  71. package/src/template/simple-ftp/Table.jsx +2 -2
  72. package/src/toolbar.jsx +76 -14
  73. package/src/utils/buildFieldsToCompJson.js +3 -3
  74. package/src/utils/persistentStorage.js +1 -1
  75. package/src/utils/swagger/api2SchemaFromSwagger.js +7 -7
package/src/toolbar.jsx CHANGED
@@ -1,13 +1,17 @@
1
1
  import React from 'react';
2
2
  import { Dialog, CnIcon, CnButton, CnTooltip, CnDrawer, CnTab, CnTabItem, CnCard } from '@cainiaofe/cn-ui';
3
3
  import MDDRenderEngine, { JSONWatch } from '@cniot/mdd-render-engine';
4
- import Monaco from '@src/components/ajax-schema-form/monaco';
4
+ import Monaco from '$src/components/ajax-schema-form/monaco';
5
+ import LocalAIDrawer from '$src/ai/LocalAIDrawer';
5
6
 
6
- import { EVENT_KEY } from '@src/common/const';
7
+ import { EVENT_KEY } from '$src/common/const';
7
8
 
8
9
  import './index.less';
9
10
 
10
- const isDebug = window?.location?.search?.indexOf('debug') >= 0;
11
+ // window.localStorage.__l4_location_search_debug__ = true; // 调试使用
12
+ // window.localStorage.__l4_ftp_filter_expand__ = true; // 调试使用
13
+ const isDebug =
14
+ window?.location?.search?.indexOf('debug') >= 0 || window.localStorage?.__l4_location_search_debug__ === 'true';
11
15
 
12
16
  /**
13
17
  * 顶部操作区
@@ -21,18 +25,36 @@ const isDebug = window?.location?.search?.indexOf('debug') >= 0;
21
25
  * }
22
26
  */
23
27
  export default function Toolbar(props) {
24
- const { schema, scriptInfo = { script: '', style: '' }, showScript, scriptTopButtons } = props;
28
+ const {
29
+ schema,
30
+ scriptInfo = { script: '', style: '' },
31
+ showScript,
32
+ scriptTopButtons,
33
+ aiBridge = true,
34
+ pageMeta,
35
+ onSchemaApplied,
36
+ } = props;
25
37
  const [fullscreen, setFullscreen] = React.useState(false);
26
38
  const [codeVisible, setCodeVisible] = React.useState(false);
27
39
  const [schemaVisible, setSchemaVisible] = React.useState(false);
40
+ const [aiVisible, setAiVisible] = React.useState(false);
41
+ const [scriptEditorInfo, setScriptEditorInfo] = React.useState(scriptInfo);
42
+ const [schemaEditorCode, setSchemaEditorCode] = React.useState(
43
+ JSON.stringify(schema?.getAllJSON() || {}, null, 2),
44
+ );
28
45
 
29
- const scriptRef = React.useRef(scriptInfo);
30
- const schemaRef = React.useRef(JSON.stringify(schema?.getAllJSON() || {}, null, 2));
46
+ const scriptRef = React.useRef(scriptEditorInfo);
47
+ const schemaRef = React.useRef(schemaEditorCode);
31
48
 
32
49
  const editorHeight = 'calc(100vh - 146px)';
33
50
 
34
51
  const scriptChange = (scriptChangeCode) => {
35
- scriptRef.current.script = scriptChangeCode; // 缓存脚本
52
+ const nextScriptInfo = {
53
+ script: scriptChangeCode,
54
+ style: scriptRef.current.style,
55
+ };
56
+ scriptRef.current = nextScriptInfo; // 缓存脚本
57
+ setScriptEditorInfo(nextScriptInfo);
36
58
  schema.emit(EVENT_KEY.SCRIPT_UPDATE, {
37
59
  script: scriptChangeCode,
38
60
  style: scriptRef.current.style,
@@ -40,11 +62,13 @@ export default function Toolbar(props) {
40
62
  };
41
63
 
42
64
  const styleChange = (styleChangeCode) => {
43
- scriptRef.current.style = styleChangeCode; // 缓存样式
44
- schema.emit(EVENT_KEY.SCRIPT_UPDATE, {
65
+ const nextScriptInfo = {
45
66
  script: scriptRef.current.script,
46
67
  style: styleChangeCode,
47
- });
68
+ };
69
+ scriptRef.current = nextScriptInfo; // 缓存样式
70
+ setScriptEditorInfo(nextScriptInfo);
71
+ schema.emit(EVENT_KEY.SCRIPT_UPDATE, nextScriptInfo);
48
72
  };
49
73
 
50
74
  // schema change
@@ -52,6 +76,15 @@ export default function Toolbar(props) {
52
76
  schema.emit(EVENT_KEY.SCHEMA_UPDATE_FORCE, newSchemaCode);
53
77
  };
54
78
 
79
+ const onLocalAIApply = ({ schemaJson, scriptInfo: nextScriptInfo }) => {
80
+ scriptRef.current = nextScriptInfo;
81
+ setScriptEditorInfo(nextScriptInfo);
82
+ const nextSchemaCode = JSON.stringify(schemaJson || schema?.getAllJSON() || {}, null, 2);
83
+ schemaRef.current = nextSchemaCode;
84
+ setSchemaEditorCode(nextSchemaCode);
85
+ onSchemaApplied?.();
86
+ };
87
+
55
88
  return (
56
89
  <div>
57
90
  <div className="mdd-editor-toolbar">
@@ -77,7 +110,6 @@ export default function Toolbar(props) {
77
110
  脚本
78
111
  </CnTooltip>
79
112
  )}
80
-
81
113
  <CnTooltip
82
114
  trigger={
83
115
  <CnButton text onClick={() => setFullscreen(true)}>
@@ -87,6 +119,17 @@ export default function Toolbar(props) {
87
119
  >
88
120
  预览
89
121
  </CnTooltip>
122
+ {aiBridge !== false && (
123
+ <CnTooltip
124
+ trigger={
125
+ <CnButton type="primary" size="small" className="mdd-editor-ai-button" onClick={() => setAiVisible(true)}>
126
+ 本地 AI
127
+ </CnButton>
128
+ }
129
+ >
130
+ 本地 AI
131
+ </CnTooltip>
132
+ )}
90
133
  </div>
91
134
  <Dialog v2 title="预览" width="90vw" visible={fullscreen} onClose={() => setFullscreen(false)} footer={false}>
92
135
  <MDDRenderEngine
@@ -99,6 +142,24 @@ export default function Toolbar(props) {
99
142
  }
100
143
  />
101
144
  </Dialog>
145
+ {aiVisible && (
146
+ <CnDrawer
147
+ title="本地 AI 工作区"
148
+ width="720px"
149
+ footer={false}
150
+ visible={aiVisible}
151
+ onClose={() => setAiVisible(false)}
152
+ >
153
+ <LocalAIDrawer
154
+ schema={schema}
155
+ scriptInfo={scriptEditorInfo}
156
+ pageMeta={pageMeta}
157
+ bridgeConfig={aiBridge}
158
+ onApply={onLocalAIApply}
159
+ />
160
+ </CnDrawer>
161
+ )}
162
+
102
163
  {/* 代码编辑 */}
103
164
  <CnDrawer
104
165
  title="脚本编辑"
@@ -121,7 +182,7 @@ export default function Toolbar(props) {
121
182
  <Monaco
122
183
  defaultLanguage="javascript"
123
184
  height={editorHeight}
124
- defaultValue={scriptInfo.script}
185
+ value={scriptEditorInfo.script}
125
186
  onChange={scriptChange}
126
187
  />
127
188
  </CnTabItem>
@@ -129,7 +190,7 @@ export default function Toolbar(props) {
129
190
  <Monaco
130
191
  defaultLanguage="less"
131
192
  height={editorHeight}
132
- defaultValue={scriptInfo.style}
193
+ value={scriptEditorInfo.style}
133
194
  onChange={styleChange}
134
195
  />
135
196
  </CnTabItem>
@@ -164,9 +225,10 @@ export default function Toolbar(props) {
164
225
  <Monaco
165
226
  defaultLanguage="json"
166
227
  height={editorHeight}
167
- defaultValue={schemaRef.current}
228
+ value={schemaEditorCode}
168
229
  onChange={(v) => {
169
230
  schemaRef.current = v;
231
+ setSchemaEditorCode(v);
170
232
  }}
171
233
  />
172
234
  </CnCard>
@@ -1,6 +1,6 @@
1
- import { SWAGGER_DT } from '@src/common/const';
2
- import { calcWordWidth } from '@src/utils';
3
- import { propFields } from '@src/common/comp-schema/fields/propFields';
1
+ import { SWAGGER_DT } from '$src/common/const';
2
+ import { calcWordWidth } from '$src/utils';
3
+ import { propFields } from '$src/common/comp-schema/fields/propFields';
4
4
 
5
5
  // 不生成字段 黑名单
6
6
  const REMOVE_FIELDS_NAME = ['page', 'pageSize', 'pageNo', 'currentPage', 'userContext'];
@@ -1,5 +1,5 @@
1
1
  // 用于LS储存
2
- import { PERSISTENT_STORE_LS_KEY } from '@src/common/const';
2
+ import { PERSISTENT_STORE_LS_KEY } from '$src/common/const';
3
3
 
4
4
  class PersistentStorage {
5
5
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import merge from 'lodash/merge';
2
- import buildSwaggerApiJson from '@src/utils/buildSwaggerApiJson';
3
- import buildFieldsToCompJson from '@src/utils/buildFieldsToCompJson';
4
- import jsonSchemaRefParser from '@src/utils/jsonSchemaRefParser';
5
- import { getDefaultFomrLabelAlign } from '@src/utils';
2
+ import buildSwaggerApiJson from '$src/utils/buildSwaggerApiJson';
3
+ import buildFieldsToCompJson from '$src/utils/buildFieldsToCompJson';
4
+ import jsonSchemaRefParser from '$src/utils/jsonSchemaRefParser';
5
+ import { getDefaultFomrLabelAlign } from '$src/utils';
6
6
 
7
7
  /** 将swaggerjson 转换成前端能用的swagger对象 */
8
8
  export function getSwaggerInfoFromJson(swaggerJson) {
@@ -186,14 +186,14 @@ export function api2SchemaFromSwaggerApiInfo(api, schemaType, apiInfo, extraSche
186
186
  },
187
187
  tree: false,
188
188
  showIndex: false,
189
- hideCommonToolbar: false,
189
+ hideCommonToolbar: true,
190
190
  },
191
191
  headerToolbar: [],
192
192
  };
193
- } else if (schemaType === 'blocks-table') {
193
+ } else if (schemaType?.startsWith('blocks-')) {
194
194
  result.type = 'blocks';
195
195
  result.body = {
196
- type: 'blocks-table',
196
+ type: schemaType,
197
197
  blocks: [],
198
198
  };
199
199
  }