@luck-design-biz/luckda 0.0.25-4 → 0.0.25-7

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 (141) hide show
  1. package/es/components/LDActions/index.less +1 -1
  2. package/es/components/LdAutoForm/index.js +24 -8
  3. package/es/components/LdFormList/index.js +25 -18
  4. package/es/components/LdGrid/index.js +3 -2
  5. package/es/components/LdGridForm/index.js +16 -6
  6. package/es/components/LdTree/index.js +3 -2
  7. package/es/helper/form.js +6 -3
  8. package/es/locales/zh-CN.js +1 -0
  9. package/es/lowcode/constants/api-url.js +13 -11
  10. package/es/lowcode/engine/factory/panel-item-factory/SelectStrategy.js +5 -2
  11. package/es/lowcode/engine/factory/panel-item-factory/SwitchStrategy.js +5 -2
  12. package/es/lowcode/engine/meta/dialog.props.default.json +10 -5
  13. package/es/lowcode/engine/meta/dialog.props.json +72 -42
  14. package/es/lowcode/engine/meta/form.props.json +3 -3
  15. package/es/lowcode/engine/meta/table.props.json +4 -4
  16. package/es/lowcode/engine/meta/tree.props.default.json +1 -0
  17. package/es/lowcode/engine/meta/tree.props.json +7 -0
  18. package/es/lowcode/engine/provider/ContextProvider/index.js +8 -40
  19. package/es/lowcode/engine/provider/RemoteSourceProvider.js +16 -20
  20. package/es/lowcode/engine/tools/helper.js +2 -3
  21. package/es/lowcode/engine/tools/useCanvasRender.js +3 -2
  22. package/es/lowcode/engine/tools/usePageDataStore.js +174 -0
  23. package/es/lowcode/engine/tools/usePromiseState.js +12 -23
  24. package/es/lowcode/engine/tools/useTodo.js +20 -10
  25. package/es/lowcode/painter/DesignOperator.js +11 -22
  26. package/es/lowcode/painter/DesignToolbar.js +8 -44
  27. package/es/lowcode/painter/Outline.js +2 -4
  28. package/es/lowcode/painter/Panel.js +26 -25
  29. package/es/lowcode/painter/components/ActionBindModal.js +5 -11
  30. package/es/lowcode/painter/components/AttrsPanel.js +26 -19
  31. package/es/lowcode/painter/components/DragDrop/DragDropContext.js +1 -1
  32. package/es/lowcode/painter/components/code-editor/BaseEditor.js +3 -2
  33. package/es/lowcode/painter/components/field-setting/SettingUI.js +7 -7
  34. package/es/lowcode/painter/panel-section/BlocksEditor/index.js +11 -11
  35. package/es/lowcode/painter/panel-section/ButtonType.js +4 -2
  36. package/es/lowcode/painter/panel-section/DataSetSelector.js +4 -1
  37. package/es/lowcode/painter/panel-section/FieldsSetting.js +5 -1
  38. package/es/lowcode/painter/panel-section/SerialsSelector.js +4 -2
  39. package/es/lowcode/painter/panel-section/TreeRootEditor.js +2 -2
  40. package/es/lowcode/painter/style/design.less +1 -1
  41. package/es/lowcode/painter/style/panel-item.less +1 -1
  42. package/es/lowcode/view/Canvas.js +6 -7
  43. package/es/lowcode/view/Page.js +2 -3
  44. package/es/lowcode/view/lc-components/Dialog/FunctionDesign.js +3 -10
  45. package/es/lowcode/view/lc-components/Dialog/index.js +89 -19
  46. package/es/lowcode/view/lc-components/Dialog/meta.json +65 -42
  47. package/es/lowcode/view/lc-components/Form/FunctionDesign.js +23 -33
  48. package/es/lowcode/view/lc-components/Form/index.js +20 -6
  49. package/es/lowcode/view/lc-components/Form/meta.json +3 -3
  50. package/es/lowcode/view/lc-components/Layout/FunctionDesign.js +12 -19
  51. package/es/lowcode/view/lc-components/PageContent/index.js +8 -9
  52. package/es/lowcode/view/lc-components/PageFooter/index.js +2 -5
  53. package/es/lowcode/view/lc-components/PageHeader/index.js +5 -6
  54. package/es/lowcode/view/lc-components/PageModal/index.js +12 -15
  55. package/es/lowcode/view/lc-components/Section/FunctionDesign.js +3 -9
  56. package/es/lowcode/view/lc-components/Split/FunctionDesign.js +11 -18
  57. package/es/lowcode/view/lc-components/Table/index.js +67 -25
  58. package/es/lowcode/view/lc-components/Table/meta.json +4 -4
  59. package/es/lowcode/view/lc-components/Tabs/FunctionDesign.js +9 -17
  60. package/es/lowcode/view/lc-components/Tree/index.js +8 -1
  61. package/es/lowcode/view/lc-components/Tree/meta.json +7 -0
  62. package/es/lowcode/view/lc-components/Wrapper.js +9 -11
  63. package/es/services.js +0 -24
  64. package/es/upload/FilesWall/file.png +0 -0
  65. package/es/upload/FilesWall/index.js +422 -0
  66. package/es/upload/FilesWall/index.less +74 -0
  67. package/es/upload/Form/index.js +2 -1
  68. package/es/upload/FormItem/index.js +2 -1
  69. package/es/upload/index.js +2 -1
  70. package/es/utils/action.js +2 -2
  71. package/lib/components/LDActions/index.less +1 -1
  72. package/lib/components/LdAutoForm/index.js +23 -7
  73. package/lib/components/LdFormList/index.js +25 -18
  74. package/lib/components/LdGrid/index.js +3 -2
  75. package/lib/components/LdGridForm/index.js +14 -4
  76. package/lib/components/LdTree/index.js +3 -2
  77. package/lib/helper/form.js +6 -3
  78. package/lib/locales/zh-CN.js +1 -0
  79. package/lib/lowcode/constants/api-url.js +14 -10
  80. package/lib/lowcode/engine/factory/panel-item-factory/SelectStrategy.js +7 -4
  81. package/lib/lowcode/engine/factory/panel-item-factory/SwitchStrategy.js +6 -3
  82. package/lib/lowcode/engine/meta/dialog.props.default.json +10 -5
  83. package/lib/lowcode/engine/meta/dialog.props.json +72 -42
  84. package/lib/lowcode/engine/meta/form.props.json +3 -3
  85. package/lib/lowcode/engine/meta/table.props.json +4 -4
  86. package/lib/lowcode/engine/meta/tree.props.default.json +1 -0
  87. package/lib/lowcode/engine/meta/tree.props.json +7 -0
  88. package/lib/lowcode/engine/provider/ContextProvider/index.js +25 -41
  89. package/lib/lowcode/engine/provider/RemoteSourceProvider.js +16 -20
  90. package/lib/lowcode/engine/tools/helper.js +2 -3
  91. package/lib/lowcode/engine/tools/useCanvasRender.js +3 -2
  92. package/lib/lowcode/engine/tools/usePageDataStore.js +181 -0
  93. package/lib/lowcode/engine/tools/usePromiseState.js +11 -21
  94. package/lib/lowcode/engine/tools/useTodo.js +19 -9
  95. package/lib/lowcode/painter/DesignOperator.js +10 -21
  96. package/lib/lowcode/painter/DesignToolbar.js +7 -43
  97. package/lib/lowcode/painter/Outline.js +1 -3
  98. package/lib/lowcode/painter/Panel.js +25 -24
  99. package/lib/lowcode/painter/components/ActionBindModal.js +5 -11
  100. package/lib/lowcode/painter/components/AttrsPanel.js +26 -19
  101. package/lib/lowcode/painter/components/DragDrop/DragDropContext.js +1 -1
  102. package/lib/lowcode/painter/components/code-editor/BaseEditor.js +3 -2
  103. package/lib/lowcode/painter/components/field-setting/SettingUI.js +7 -7
  104. package/lib/lowcode/painter/panel-section/BlocksEditor/index.js +10 -10
  105. package/lib/lowcode/painter/panel-section/ButtonType.js +4 -2
  106. package/lib/lowcode/painter/panel-section/DataSetSelector.js +4 -1
  107. package/lib/lowcode/painter/panel-section/FieldsSetting.js +5 -1
  108. package/lib/lowcode/painter/panel-section/SerialsSelector.js +4 -2
  109. package/lib/lowcode/painter/panel-section/TreeRootEditor.js +2 -2
  110. package/lib/lowcode/painter/style/design.less +1 -1
  111. package/lib/lowcode/painter/style/panel-item.less +1 -1
  112. package/lib/lowcode/view/Canvas.js +5 -6
  113. package/lib/lowcode/view/Page.js +2 -3
  114. package/lib/lowcode/view/lc-components/Dialog/FunctionDesign.js +2 -9
  115. package/lib/lowcode/view/lc-components/Dialog/index.js +89 -19
  116. package/lib/lowcode/view/lc-components/Dialog/meta.json +65 -42
  117. package/lib/lowcode/view/lc-components/Form/FunctionDesign.js +20 -31
  118. package/lib/lowcode/view/lc-components/Form/index.js +20 -6
  119. package/lib/lowcode/view/lc-components/Form/meta.json +3 -3
  120. package/lib/lowcode/view/lc-components/Layout/FunctionDesign.js +11 -18
  121. package/lib/lowcode/view/lc-components/PageContent/index.js +7 -8
  122. package/lib/lowcode/view/lc-components/PageFooter/index.js +2 -5
  123. package/lib/lowcode/view/lc-components/PageHeader/index.js +4 -5
  124. package/lib/lowcode/view/lc-components/PageModal/index.js +11 -14
  125. package/lib/lowcode/view/lc-components/Section/FunctionDesign.js +2 -8
  126. package/lib/lowcode/view/lc-components/Split/FunctionDesign.js +10 -17
  127. package/lib/lowcode/view/lc-components/Table/index.js +66 -24
  128. package/lib/lowcode/view/lc-components/Table/meta.json +4 -4
  129. package/lib/lowcode/view/lc-components/Tabs/FunctionDesign.js +8 -16
  130. package/lib/lowcode/view/lc-components/Tree/index.js +8 -1
  131. package/lib/lowcode/view/lc-components/Tree/meta.json +7 -0
  132. package/lib/lowcode/view/lc-components/Wrapper.js +8 -10
  133. package/lib/services.js +0 -25
  134. package/lib/upload/FilesWall/file.png +0 -0
  135. package/lib/upload/FilesWall/index.js +429 -0
  136. package/lib/upload/FilesWall/index.less +74 -0
  137. package/lib/upload/Form/index.js +2 -1
  138. package/lib/upload/FormItem/index.js +2 -1
  139. package/lib/upload/index.js +8 -1
  140. package/lib/utils/action.js +2 -2
  141. package/package.json +4 -3
@@ -38,7 +38,7 @@
38
38
  {
39
39
  "key": "saveTitle",
40
40
  "name": "保存按钮标题",
41
- "type": "string",
41
+ "type": "_I18nInput",
42
42
  "default": "保存"
43
43
  },
44
44
  {
@@ -125,7 +125,7 @@
125
125
  {
126
126
  "key": "name",
127
127
  "name": "区块名称",
128
- "type": "string"
128
+ "type": "_I18nInput"
129
129
  },
130
130
  {
131
131
  "key": "serial",
@@ -543,7 +543,7 @@
543
543
  {
544
544
  "key": "zipName",
545
545
  "name": "压缩包命名",
546
- "type": "string"
546
+ "type": "_I18nInput"
547
547
  },
548
548
  {
549
549
  "key": "uploadUrl",
@@ -66,7 +66,7 @@
66
66
  "moreText": "操作",
67
67
  "todoList": []
68
68
  },
69
- "defaultCode": "function todo(instance) { \n \n}",
69
+ "defaultCode": "function todo() { \n \n}",
70
70
  "wrapper": "collapse"
71
71
  },
72
72
  {
@@ -115,7 +115,7 @@
115
115
  "moreText": "更多操作",
116
116
  "todoList": []
117
117
  },
118
- "defaultCode": "function onActionClick(data) {\n\n}",
118
+ "defaultCode": "function onActionClick(data, rowIndex, params) {\n\n}",
119
119
  "wrapper": "collapse",
120
120
  "wrapperProps": {
121
121
  "suppressIcon": true
@@ -383,13 +383,13 @@
383
383
  "key": "onMount",
384
384
  "name": "组件首次渲染时",
385
385
  "desc": "在组件首次渲染时,执行方法",
386
- "func": "(params, instance)=>{\n\t\n}"
386
+ "func": "(params)=>{\n\t\n}"
387
387
  },
388
388
  {
389
389
  "key": "onUnmount",
390
390
  "name": "组件卸载时",
391
391
  "desc": "在组件卸载时,执行方法。",
392
- "func": "(instance)=>{\n\t\n}"
392
+ "func": "()=>{\n\t\n}"
393
393
  },
394
394
  {
395
395
  "key": "onRowClick",
@@ -18,6 +18,7 @@
18
18
  "showIcon": true,
19
19
  "treeNodeIcon": [],
20
20
  "showRootAdd": true,
21
+ "onlyRoot": false,
21
22
  "rootAddSetting": {},
22
23
  "actions": {
23
24
  "todoList": []
@@ -170,6 +170,13 @@
170
170
  "type": "switch",
171
171
  "default": true
172
172
  },
173
+ {
174
+ "key": "onlyRoot",
175
+ "name": "根节点唯一",
176
+ "desc": "树组件仅一个根节点,如数据根节点数大于0,则不允许根节点新增",
177
+ "type": "switch",
178
+ "default": false
179
+ },
173
180
  {
174
181
  "key": "rootAddSetting",
175
182
  "name": "根节点配置",
@@ -3,62 +3,28 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import React, { createContext, useContext as useReactContext, useRef } from 'react';
4
4
  import { history } from 'umi';
5
5
  import { useMemoizedFn, useSetState } from 'ahooks';
6
- import { get, isNil, isArray, isFunction, isObject, isString, reduce } from 'lodash';
7
6
  import { useLDEventBus } from "../EventBusProvider";
8
7
  import RemoteSourceProvider, { RemoteSourceContext } from "../RemoteSourceProvider";
9
8
  import useTodo from "../../tools/useTodo";
10
- import { findNodeAndParent } from "../../tools/dataProcess";
11
9
  import * as topics from "../../../constants/event-topics";
12
10
  export var Context = /*#__PURE__*/createContext(null);
13
11
  export var useContext = function useContext() {
14
12
  return useReactContext(Context);
15
13
  };
16
- export var usePageData = function usePageData(_) {
17
- var _useReactContext = useReactContext(RemoteSourceContext),
18
- pageData = _useReactContext.pageData,
19
- loading = _useReactContext.loading,
20
- setPageData = _useReactContext.setPageData,
21
- back = _useReactContext.back,
22
- forward = _useReactContext.forward,
23
- backLength = _useReactContext.backLength,
24
- forwardLength = _useReactContext.forwardLength;
25
- var _pageData;
26
- if (isNil(_)) {
27
- _pageData = pageData;
28
- } else if (isFunction(_)) {
29
- _pageData = _(pageData);
30
- } else if (isArray(_)) {
31
- _pageData = reduce(_, function (r, k) {
32
- r.push(get(pageData, k));
33
- return r;
34
- }, []);
35
- } else if (isObject(_) && _.id) {
36
- var _findNodeAndParent;
37
- _pageData = (_findNodeAndParent = findNodeAndParent(_.id, pageData)) === null || _findNodeAndParent === void 0 ? void 0 : _findNodeAndParent.node;
38
- } else if (isString(_)) {
39
- _pageData = get(pageData, _);
40
- }
41
- return [_pageData, {
42
- loading: loading,
43
- setPageData: setPageData,
44
- back: back,
45
- forward: forward,
46
- backLength: backLength,
47
- forwardLength: forwardLength
48
- }];
49
- };
50
14
  export var useRemoteSource = function useRemoteSource() {
51
15
  return useReactContext(RemoteSourceContext);
52
16
  };
17
+ export * from "../../tools/usePageDataStore";
53
18
  var PRIVATE_KEYS = ['componentList', 'componentMap'];
54
19
  export default (function (_ref) {
55
20
  var children = _ref.children,
56
21
  code = _ref.code;
57
22
  var eventBus = useLDEventBus();
58
23
  var _useTodo = useTodo(),
59
- _useTodo2 = _slicedToArray(_useTodo, 2),
24
+ _useTodo2 = _slicedToArray(_useTodo, 3),
60
25
  todo = _useTodo2[0],
61
- callBehavior = _useTodo2[1];
26
+ callBehavior = _useTodo2[1],
27
+ loading = _useTodo2[2];
62
28
 
63
29
  /**
64
30
  * 页面公共资源
@@ -66,7 +32,7 @@ export default (function (_ref) {
66
32
  var _useSetState = useSetState(null),
67
33
  _useSetState2 = _slicedToArray(_useSetState, 2),
68
34
  pagePublicResource = _useSetState2[0],
69
- _setPagePublicResource = _useSetState2[1];
35
+ setPagePublicResource = _useSetState2[1];
70
36
 
71
37
  /**
72
38
  * 组件列表
@@ -129,13 +95,15 @@ export default (function (_ref) {
129
95
  */
130
96
  var getUrlParams = useMemoizedFn(function () {});
131
97
  var ctx = new Proxy(_objectSpread({
132
- _setPagePublicResource: _setPagePublicResource,
133
98
  _register: _register,
134
99
  _unregister: _unregister,
135
100
  pagePublicResource: pagePublicResource,
101
+ setPagePublicResource: setPagePublicResource,
102
+ loading: loading,
136
103
  history: history,
137
104
  callBehavior: callBehavior,
138
105
  topics: topics,
106
+ PRIMARY_KEY: window.appConfig.constraintKeys.PRIMARY,
139
107
  getElementById: getElementById,
140
108
  /**
141
109
  * @method
@@ -9,7 +9,7 @@ import React, { createContext, useRef } from 'react';
9
9
  import { useRequest, useSetState, useAsyncEffect, useMemoizedFn, useCookieState, useCreation, useUnmount } from 'ahooks';
10
10
  import { LuckDaContext } from "../../../components/Builder";
11
11
  import { doAction as doActionUtils } from "../../../helper/action";
12
- import usePromiseState from "../tools/usePromiseState";
12
+ import usePageDataStore from "../tools/usePageDataStore";
13
13
  import { decompress } from "../tools/dataProcess";
14
14
  import { fetchPageData, fetchDesignModlueData, fetchPreviewModlueData, fetchModlueData, fetchAllDataset, fetchAllSerials } from "../../constants/api-url";
15
15
  import { RUNTIME, COOKIE_RUNTIME_KEY, DATA_MODEL_CODE_KEY } from "../../constants";
@@ -18,15 +18,16 @@ export default (function (_ref) {
18
18
  var children = _ref.children,
19
19
  code = _ref.code,
20
20
  runtime = _ref.runtime;
21
- var _usePromiseState = usePromiseState(null),
22
- _usePromiseState2 = _slicedToArray(_usePromiseState, 3),
23
- pageData = _usePromiseState2[0],
24
- setPageData = _usePromiseState2[1],
25
- _usePromiseState2$ = _usePromiseState2[2],
26
- back = _usePromiseState2$.back,
27
- forward = _usePromiseState2$.forward,
28
- backLength = _usePromiseState2$.backLength,
29
- forwardLength = _usePromiseState2$.forwardLength;
21
+ var _usePageDataStore = usePageDataStore(function (state) {
22
+ return {
23
+ initialize: state.initialize,
24
+ initializeModule: state.initializeModule,
25
+ reset: state.reset
26
+ };
27
+ }),
28
+ initialize = _usePageDataStore.initialize,
29
+ initializeModule = _usePageDataStore.initializeModule,
30
+ reset = _usePageDataStore.reset;
30
31
  var _useSetState = useSetState({}),
31
32
  _useSetState2 = _slicedToArray(_useSetState, 2),
32
33
  remoteSource = _useSetState2[0],
@@ -43,6 +44,7 @@ export default (function (_ref) {
43
44
  }
44
45
  }, []);
45
46
  useUnmount(function () {
47
+ reset();
46
48
  setRuntime(prevRuntime.current);
47
49
  });
48
50
 
@@ -62,6 +64,7 @@ export default (function (_ref) {
62
64
  setRemoteSource({
63
65
  module: data
64
66
  });
67
+ initializeModule(data);
65
68
  }
66
69
  }
67
70
  }),
@@ -137,7 +140,7 @@ export default (function (_ref) {
137
140
  relationship: data
138
141
  }, info)
139
142
  });
140
- setPageData(decompress(source));
143
+ initialize(decompress(source));
141
144
  case 13:
142
145
  case "end":
143
146
  return _context.stop();
@@ -151,20 +154,13 @@ export default (function (_ref) {
151
154
  });
152
155
  });
153
156
  return /*#__PURE__*/React.createElement(RemoteSourceContext.Provider, {
154
- value: _objectSpread(_objectSpread({
155
- pageData: pageData
156
- }, remoteSource), {}, {
157
+ value: _objectSpread(_objectSpread({}, remoteSource), {}, {
157
158
  loading: fetchPageDataLoading || fetchModlueDataLoading,
158
159
  fetchAllDatasetLoading: fetchAllDatasetLoading,
159
160
  fetchAllSerialsLoading: fetchAllSerialsLoading,
160
161
  refreshModlueData: refreshModlueData,
161
162
  refreshDataset: refreshDataset,
162
- refreshSerials: refreshSerials,
163
- setPageData: setPageData,
164
- back: back,
165
- forward: forward,
166
- backLength: backLength,
167
- forwardLength: forwardLength
163
+ refreshSerials: refreshSerials
168
164
  })
169
165
  }, /*#__PURE__*/React.createElement(LuckDaContext.Provider, {
170
166
  value: _objectSpread(_objectSpread({}, remoteSource.module), {}, {
@@ -96,9 +96,8 @@ export function listReducer(state, action) {
96
96
  }
97
97
  }
98
98
  export function getCtx(context) {
99
- return omitBy(context, function (_, key) {
100
- return startsWith(key, '_');
101
- });
99
+ return context;
100
+ // return omitBy(context, (_, key) => startsWith(key, '_'));
102
101
  }
103
102
  export function getFuncBody(funcCode) {
104
103
  var regex = /{([\s\S]*?)}(?![\s\S]*})/;
@@ -13,8 +13,9 @@ import { LC_BUILDIN_UNIT_KEY_LIST } from "../../constants";
13
13
  export default function useCanvasRender(data, deps) {
14
14
  var dynamicCompMap = useRef({});
15
15
  var ctx = useContext();
16
- var render = useMemoizedFn(function (_ref) {
17
- var props = _ref.props,
16
+ var render = useMemoizedFn(function () {
17
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
18
+ props = _ref.props,
18
19
  children = _ref.children,
19
20
  childrenMap = _objectWithoutProperties(_ref, _excluded);
20
21
  if (props && !LC_BUILDIN_UNIT_KEY_LIST.includes(props.id)) {
@@ -0,0 +1,174 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
3
+ import { useRef, useEffect, useCallback } from 'react';
4
+ import { create } from 'zustand';
5
+ import { immer } from 'zustand/middleware/immer';
6
+ import { subscribeWithSelector } from 'zustand/middleware';
7
+ import { useShallow } from 'zustand/react/shallow';
8
+ import { isObject, isArray, isNil, isFunction, isString, get, set as _set, forOwn, omit } from 'lodash';
9
+ import { getPathNodesById, findNodeAndParent } from "./dataProcess";
10
+ import { LC_BUILDIN_UNIT_KEY } from "../../constants";
11
+ var findNode = function findNode(obj, id) {
12
+ for (var key in obj) {
13
+ if (!['props', 'children'].includes(key)) {
14
+ if (key === id) {
15
+ return {
16
+ target: obj[key],
17
+ parent: obj
18
+ };
19
+ }
20
+ if (_typeof(obj[key]) === 'object' && !Array.isArray(obj[key])) {
21
+ var result = findNode(obj[key], id);
22
+ if (result) {
23
+ return result;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return null;
29
+ };
30
+ var usePageDataStore = create()(immer(subscribeWithSelector(function (set) {
31
+ return {
32
+ pageData: null,
33
+ moduleData: null,
34
+ initialize: function initialize(data) {
35
+ return set(function (state) {
36
+ state.pageData = data;
37
+ });
38
+ },
39
+ initializeModule: function initializeModule(data) {
40
+ return set(function (state) {
41
+ state.moduleData = data;
42
+ });
43
+ },
44
+ reset: function reset(data) {
45
+ return set(function (state) {
46
+ state.pageData = data || null;
47
+ });
48
+ }
49
+ };
50
+ })));
51
+ export default usePageDataStore;
52
+ export var resetPageData = function resetPageData(data) {
53
+ usePageDataStore.setState(function (state) {
54
+ state.pageData = data || null;
55
+ });
56
+ };
57
+ export var addNode = function addNode(parentId, id, data) {
58
+ usePageDataStore.setState(function (state) {
59
+ if (parentId === LC_BUILDIN_UNIT_KEY.PAGE_ROOT) {
60
+ state.pageData.children.push(id);
61
+ state.pageData[id] = {
62
+ props: _objectSpread(_objectSpread({}, data), {}, {
63
+ id: id,
64
+ parentId: parentId
65
+ })
66
+ };
67
+ return;
68
+ }
69
+ var _ref = findNode(state.pageData, parentId) || {},
70
+ target = _ref.target;
71
+ if (!target) return;
72
+ if (!target.hasOwnProperty('children')) {
73
+ target.children = [];
74
+ }
75
+ if (!target.children.includes(id)) {
76
+ target.children.push(id);
77
+ target[id] = {
78
+ props: _objectSpread(_objectSpread({}, data), {}, {
79
+ id: id,
80
+ parentId: parentId
81
+ })
82
+ };
83
+ }
84
+ });
85
+ };
86
+ export var deleteNode = function deleteNode(id) {
87
+ usePageDataStore.setState(function (state) {
88
+ var _parent$children;
89
+ var _ref2 = findNode(state.pageData, id) || {},
90
+ parent = _ref2.parent;
91
+ if (!parent || !((_parent$children = parent.children) !== null && _parent$children !== void 0 && _parent$children.length)) return;
92
+ parent.children.splice(parent.children.indexOf(id), 1);
93
+ if (parent.children.length === 0) {
94
+ delete parent['children'];
95
+ }
96
+ delete parent[id];
97
+ });
98
+ };
99
+ export var modifyNode = function modifyNode(id, data) {
100
+ usePageDataStore.setState(function (state) {
101
+ if (id === LC_BUILDIN_UNIT_KEY.PAGE_ROOT) {
102
+ assign(state.pageData.props, omit(data, ['id', 'parentId', 'component', 'buildIn']));
103
+ return;
104
+ }
105
+ var _ref3 = findNode(state.pageData, id) || {},
106
+ target = _ref3.target;
107
+ if (!target) return;
108
+ forOwn(omit(data, ['id', 'parentId', 'component', 'buildIn']), function (_val, _key) {
109
+ _set(target.props, _key, _val);
110
+ });
111
+ });
112
+ };
113
+ export var useTask = function useTask(type) {
114
+ var promiseRef = useRef(null);
115
+ var task = useCallback(function () {
116
+ for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
117
+ args[_key2] = arguments[_key2];
118
+ }
119
+ return new Promise(function (resolve) {
120
+ promiseRef.current = resolve;
121
+ switch (type) {
122
+ case 'add':
123
+ addNode.apply(void 0, args);
124
+ break;
125
+ case 'update':
126
+ case 'modify':
127
+ modifyNode.apply(void 0, args);
128
+ break;
129
+ case 'delete':
130
+ deleteNode.apply(void 0, args);
131
+ break;
132
+ default:
133
+ break;
134
+ }
135
+ });
136
+ }, []);
137
+ useEffect(function () {
138
+ var unsub = usePageDataStore.subscribe(function (state, prevState) {
139
+ if (!promiseRef.current) {
140
+ return;
141
+ }
142
+ promiseRef.current(state.pageData, prevState.pageData);
143
+ promiseRef.current = null;
144
+ });
145
+ return unsub;
146
+ }, []);
147
+ return task;
148
+ };
149
+ export var useGet = function useGet(_) {
150
+ var result = usePageDataStore(useShallow(function (state) {
151
+ if (isNil(_)) {
152
+ return state.pageData;
153
+ } else if (isFunction(_)) {
154
+ return _(state.pageData);
155
+ } else if (isArray(_)) {
156
+ return _.map(function (k) {
157
+ var _findNode;
158
+ return k.includes('.') ? get(state.pageData, k) : (_findNode = findNode(state.pageData, k)) === null || _findNode === void 0 ? void 0 : _findNode.target;
159
+ });
160
+ } else if (isObject(_) && _.id) {
161
+ var _findNode2;
162
+ return _.id === LC_BUILDIN_UNIT_KEY.PAGE_ROOT ? state.pageData : (_findNode2 = findNode(state.pageData, _.id)) === null || _findNode2 === void 0 ? void 0 : _findNode2.target;
163
+ } else if (isString(_)) {
164
+ return get(state.pageData, _);
165
+ }
166
+ }));
167
+ return result;
168
+ };
169
+ export var getLevelNodes = function getLevelNodes(id) {
170
+ return getPathNodesById(usePageDataStore.getState().pageData, id);
171
+ };
172
+ export var getSelfAndParent = function getSelfAndParent(id) {
173
+ return findNodeAndParent(id, usePageDataStore.getState().pageData);
174
+ };
@@ -1,35 +1,24 @@
1
- import { useRef, useCallback } from 'react';
2
- import { useHistoryTravel, useUpdateLayoutEffect } from 'ahooks';
3
- import { isEqual } from 'lodash';
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useRef, useState, useCallback } from 'react';
3
+ import { useUpdateLayoutEffect } from 'ahooks';
4
4
  var usePromiseState = function usePromiseState(initialState) {
5
- var _useHistoryTravel = useHistoryTravel(initialState),
6
- value = _useHistoryTravel.value,
7
- setValue = _useHistoryTravel.setValue,
8
- backLength = _useHistoryTravel.backLength,
9
- forwardLength = _useHistoryTravel.forwardLength,
10
- back = _useHistoryTravel.back,
11
- forward = _useHistoryTravel.forward;
5
+ var _useState = useState(initialState),
6
+ _useState2 = _slicedToArray(_useState, 2),
7
+ state = _useState2[0],
8
+ setState = _useState2[1];
12
9
  var promiseRef = useRef(null);
13
- var setStatePromise = useCallback(function (_value) {
10
+ var setStatePromise = useCallback(function (_state) {
14
11
  return new Promise(function (resolve) {
15
12
  promiseRef.current = resolve;
16
- var _valStr = JSON.stringify(_value);
17
- if (!isEqual(value, _valStr)) {
18
- setValue(_valStr);
19
- }
13
+ setState(_state);
20
14
  });
21
15
  }, []);
22
16
  useUpdateLayoutEffect(function () {
23
17
  if (promiseRef.current) {
24
- promiseRef.current(JSON.parse(value));
18
+ promiseRef.current(state);
25
19
  promiseRef.current = null;
26
20
  }
27
- }, [value]);
28
- return [JSON.parse(value), setStatePromise, {
29
- backLength: backLength - 1,
30
- forwardLength: forwardLength,
31
- back: back,
32
- forward: forward
33
- }];
21
+ }, [state]);
22
+ return [state, setStatePromise];
34
23
  };
35
24
  export default usePromiseState;
@@ -5,7 +5,8 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  var _excluded = ["datasetCode"];
6
6
  import { useBoolean, useMemoizedFn } from 'ahooks';
7
7
  import { message } from 'luck-design/antd';
8
- import { keys, isNil } from 'lodash';
8
+ import { keys, isNil, isFunction } from 'lodash';
9
+ import usePageDataStore from "./usePageDataStore";
9
10
  import { executeCode } from "./helper";
10
11
  import { fetchCallBehavior } from "../../constants/api-url";
11
12
  var useTodo = function useTodo() {
@@ -25,10 +26,13 @@ var useTodo = function useTodo() {
25
26
  behaviorKey: behaviorKey
26
27
  }, params), data);
27
28
  });
29
+ var moduleData = usePageDataStore(function (state) {
30
+ return state.moduleData;
31
+ });
28
32
  var todo = useMemoizedFn(function (ctx, actionPool) {
29
33
  var argsMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
30
34
  if (isNil(actionPool)) {
31
- return;
35
+ return Promise.resolve();
32
36
  }
33
37
  var dsCode = argsMap.datasetCode,
34
38
  args = _objectWithoutProperties(argsMap, _excluded);
@@ -47,21 +51,27 @@ var useTodo = function useTodo() {
47
51
  return Promise.resolve(executeCode.apply(void 0, [ctx, info.code, argsName].concat(_toConsumableArray(_args))));
48
52
  case 'page-action':
49
53
  {
50
- var _JSON$parse = JSON.parse(info.code || '{}'),
51
- moduleCode = _JSON$parse.moduleCode,
52
- datasetCode = _JSON$parse.datasetCode,
53
- params = _JSON$parse.params,
54
- data = _JSON$parse.data;
54
+ var _ref4 = executeCode.apply(void 0, [ctx, info.code, argsName].concat(_toConsumableArray(_args))) || {},
55
+ moduleCode = _ref4.moduleCode,
56
+ datasetCode = _ref4.datasetCode,
57
+ params = _ref4.params,
58
+ data = _ref4.data,
59
+ after = _ref4.after;
60
+ var _moduleCode = moduleCode || moduleData.moduleCode;
55
61
  var _dscode = datasetCode || dsCode;
56
- if (!moduleCode || !_dscode) {
62
+ if (!_moduleCode || !_dscode) {
57
63
  message.warning('接口重要参数(模块编码或数据集编码)丢失');
58
64
  return;
59
65
  }
60
66
  return callBehavior({
61
67
  datasetCode: _dscode,
62
- moduleCode: moduleCode,
68
+ moduleCode: _moduleCode,
63
69
  behaviorKey: actionKey
64
- }, params, data);
70
+ }, params, data).then(function (res) {
71
+ if (isFunction(after)) {
72
+ after(ctx, res);
73
+ }
74
+ });
65
75
  }
66
76
  case 'trigger':
67
77
  return Promise.resolve();
@@ -5,8 +5,7 @@ import { useEventListener, useSetState, useMemoizedFn, useCreation, useSize, use
5
5
  import { Icon, Dropdown, message } from 'luck-design/antd';
6
6
  import { reverse } from 'lodash';
7
7
  import { suid } from '@luck-design-biz/base/utils';
8
- import { useContext, usePageData } from "../engine/provider/ContextProvider";
9
- import { add, deleteById } from "../engine/tools/dataProcess";
8
+ import { useContext, addNode, deleteNode } from "../engine/provider/ContextProvider";
10
9
  import { LC_BUILDIN_UNIT_KEY, LC_COMPONENT_UNIT_KEY, LC_COMPONENT_UNIT, CONTAINER_UNITS } from "../constants";
11
10
  import styles from "./style/design.less";
12
11
  var _MODAL_COMPONENT_ = ['Dialog', 'Drawer'];
@@ -29,10 +28,6 @@ var DesignOperator = function DesignOperator(_ref) {
29
28
  var _getDomById, _getDomById2;
30
29
  var target = _ref.target;
31
30
  var context = useContext();
32
- var _usePageData = usePageData(),
33
- _usePageData2 = _slicedToArray(_usePageData, 2),
34
- pageData = _usePageData2[0],
35
- setPageData = _usePageData2[1].setPageData;
36
31
  var size = useSize(target);
37
32
  var _useState = useState(suid()),
38
33
  _useState2 = _slicedToArray(_useState, 2),
@@ -64,27 +59,24 @@ var DesignOperator = function DesignOperator(_ref) {
64
59
  var handleDelete = useMemoizedFn(function (_ref2) {
65
60
  var id = _ref2.id;
66
61
  context.$publisher(context.topics.COMPONENT_DELETE, {
67
- id: id,
68
- pageData: pageData
62
+ id: id
69
63
  });
70
64
  });
71
65
  var addComponent = useMemoizedFn(function (data, targetId) {
72
- var json = require("../engine/meta/".concat(data.component.toLowerCase(), ".props.default.json"));
73
- var _id = "".concat(data.component.toLowerCase(), "_").concat(suid());
74
- add(pageData, targetId, _id, json);
75
66
  context.$subscriber(context.topics.COMPONENT_MOUNT).once(function (_ref3) {
76
67
  var mountCompId = _ref3.id;
77
68
  if (mountCompId === _id) {
78
69
  context.$publisher(context.topics.COMPONENT_APPEND, {
79
- id: _id,
80
- pageData: pageData
70
+ id: _id
81
71
  });
82
72
  context.$publisher(context.topics.COMPONENT_ACTIVE, {
83
73
  id: _id
84
74
  });
85
75
  }
86
76
  }).watch();
87
- setPageData(pageData);
77
+ var json = require("../engine/meta/".concat(data.component.toLowerCase(), ".props.default.json"));
78
+ var _id = "".concat(data.component.toLowerCase(), "_").concat(suid());
79
+ addNode(targetId, _id, json);
88
80
  });
89
81
  var acticeProps = useCreation(function () {
90
82
  if (!operatorId.selector) return null;
@@ -191,8 +183,7 @@ var DesignOperator = function DesignOperator(_ref) {
191
183
  }).watch();
192
184
  var acid = context.$subscriber(context.topics.COMPONENT_ACTIVE).on(function (payload) {
193
185
  if (payload.id) {
194
- var _context$componentMap2 = context.componentMap.get(payload.id).api.getSelfAndParentLCData(),
195
- node = _context$componentMap2.node;
186
+ var node = context.componentMap.get(payload.id).api.getSelfData();
196
187
  setOperatorId({
197
188
  selector: payload.id,
198
189
  deletable: node.props.buildIn !== true,
@@ -207,14 +198,14 @@ var DesignOperator = function DesignOperator(_ref) {
207
198
  var cmtid = context.$subscriber(context.topics.COMPONENT_MODAL_TOGGLE).on(function (_ref6) {
208
199
  var toggle = _ref6.toggle,
209
200
  id = _ref6.id;
210
- if (toggle) {
201
+ if (toggle && id !== currentModal.current) {
211
202
  target.current.style.setProperty('overflow', 'hidden');
212
203
  var _modal = context.componentMap.get(id);
213
204
  var _prevModal = currentModal.current ? context.componentMap.get(currentModal.current) : null;
214
205
  _prevModal === null || _prevModal === void 0 || _prevModal.api.doClose();
215
206
  _modal.api.doOpen();
216
207
  currentModal.current = id;
217
- } else {
208
+ } else if (!toggle) {
218
209
  target.current.style.removeProperty('overflow');
219
210
  var _id = id || currentModal.current;
220
211
  if (_id) {
@@ -225,13 +216,11 @@ var DesignOperator = function DesignOperator(_ref) {
225
216
  }
226
217
  }).watch();
227
218
  var cdid = context.$subscriber(context.topics.COMPONENT_DELETE).on(function (_ref7) {
228
- var id = _ref7.id,
229
- pageData = _ref7.pageData;
219
+ var id = _ref7.id;
230
220
  if (lastSelectorId.current === id) {
231
221
  context.$publisher(context.topics.COMPONENT_ACTIVE, null);
232
222
  }
233
- deleteById(pageData, id);
234
- setPageData(pageData);
223
+ deleteNode(id);
235
224
  });
236
225
  return function () {
237
226
  context.$unsubscriber(context.topics.COMPONENT_SETTING_CLICK, csid);