@nocobase/plugin-graph-collection-manager 0.11.1-alpha.5 → 0.12.0-alpha.2

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 (100) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +65917 -0
  4. package/{lib → dist}/client/utils.d.ts +4 -3
  5. package/{lib → dist}/index.d.ts +1 -0
  6. package/dist/index.js +18 -0
  7. package/dist/locale/en-US.js +19 -0
  8. package/dist/locale/es-ES.js +19 -0
  9. package/dist/locale/fr-FR.js +19 -0
  10. package/dist/locale/ja-JP.js +17 -0
  11. package/dist/locale/pt-BR.js +19 -0
  12. package/dist/locale/zh-CN.js +20 -0
  13. package/dist/server/collections/graphPositions.js +26 -0
  14. package/dist/server/index.js +23 -0
  15. package/package.json +17 -28
  16. package/server.d.ts +2 -3
  17. package/server.js +1 -1
  18. package/lib/client/GraphCollectionProvider.js +0 -51
  19. package/lib/client/GraphCollectionShortcut.js +0 -169
  20. package/lib/client/GraphDrawPage.js +0 -1546
  21. package/lib/client/action-hooks.js +0 -318
  22. package/lib/client/components/AddCollectionAction.js +0 -58
  23. package/lib/client/components/AddFieldAction.js +0 -69
  24. package/lib/client/components/CollectionNodeProvder.js +0 -34
  25. package/lib/client/components/EditCollectionAction.js +0 -47
  26. package/lib/client/components/EditFieldAction.js +0 -63
  27. package/lib/client/components/Entity.js +0 -529
  28. package/lib/client/components/FieldSummary.js +0 -69
  29. package/lib/client/components/OverrideFieldAction.js +0 -64
  30. package/lib/client/components/ViewFieldAction.js +0 -45
  31. package/lib/client/components/ViewNode.js +0 -33
  32. package/lib/client/index.js +0 -27
  33. package/lib/client/locale/index.js +0 -4
  34. package/lib/client/style.js +0 -233
  35. package/lib/client/utils.js +0 -540
  36. package/lib/index.js +0 -13
  37. package/lib/locale/en-US.js +0 -22
  38. package/lib/locale/es-ES.js +0 -22
  39. package/lib/locale/fr-FR.js +0 -22
  40. package/lib/locale/ja-JP.js +0 -20
  41. package/lib/locale/pt-BR.js +0 -22
  42. package/lib/locale/zh-CN.js +0 -23
  43. package/lib/server/collections/graphPositions.js +0 -30
  44. package/lib/server/index.js +0 -37
  45. package/src/client/GraphCollectionProvider.tsx +0 -33
  46. package/src/client/GraphCollectionShortcut.tsx +0 -141
  47. package/src/client/GraphDrawPage.tsx +0 -1382
  48. package/src/client/action-hooks.tsx +0 -237
  49. package/src/client/components/AddCollectionAction.tsx +0 -28
  50. package/src/client/components/AddFieldAction.tsx +0 -37
  51. package/src/client/components/CollectionNodeProvder.tsx +0 -28
  52. package/src/client/components/EditCollectionAction.tsx +0 -21
  53. package/src/client/components/EditFieldAction.tsx +0 -30
  54. package/src/client/components/Entity.tsx +0 -495
  55. package/src/client/components/FieldSummary.tsx +0 -42
  56. package/src/client/components/OverrideFieldAction.tsx +0 -30
  57. package/src/client/components/ViewFieldAction.tsx +0 -12
  58. package/src/client/components/ViewNode.tsx +0 -22
  59. package/src/client/index.tsx +0 -10
  60. package/src/client/locale/index.ts +0 -3
  61. package/src/client/style.tsx +0 -227
  62. package/src/client/utils.tsx +0 -548
  63. package/src/index.ts +0 -1
  64. package/src/locale/en-US.ts +0 -15
  65. package/src/locale/es-ES.ts +0 -15
  66. package/src/locale/fr-FR.ts +0 -15
  67. package/src/locale/ja-JP.ts +0 -13
  68. package/src/locale/pt-BR.ts +0 -15
  69. package/src/locale/zh-CN.ts +0 -16
  70. package/src/server/actions/.gitkeep +0 -0
  71. package/src/server/collections/.gitkeep +0 -0
  72. package/src/server/collections/graphPositions.ts +0 -22
  73. package/src/server/index.ts +0 -13
  74. package/src/server/models/.gitkeep +0 -0
  75. package/src/server/repositories/.gitkeep +0 -0
  76. /package/{lib → dist}/client/GraphCollectionProvider.d.ts +0 -0
  77. /package/{lib → dist}/client/GraphCollectionShortcut.d.ts +0 -0
  78. /package/{lib → dist}/client/GraphDrawPage.d.ts +0 -0
  79. /package/{lib → dist}/client/action-hooks.d.ts +0 -0
  80. /package/{lib → dist}/client/components/AddCollectionAction.d.ts +0 -0
  81. /package/{lib → dist}/client/components/AddFieldAction.d.ts +0 -0
  82. /package/{lib → dist}/client/components/CollectionNodeProvder.d.ts +0 -0
  83. /package/{lib → dist}/client/components/EditCollectionAction.d.ts +0 -0
  84. /package/{lib → dist}/client/components/EditFieldAction.d.ts +0 -0
  85. /package/{lib → dist}/client/components/Entity.d.ts +0 -0
  86. /package/{lib → dist}/client/components/FieldSummary.d.ts +0 -0
  87. /package/{lib → dist}/client/components/OverrideFieldAction.d.ts +0 -0
  88. /package/{lib → dist}/client/components/ViewFieldAction.d.ts +0 -0
  89. /package/{lib → dist}/client/components/ViewNode.d.ts +0 -0
  90. /package/{lib → dist}/client/index.d.ts +0 -0
  91. /package/{lib → dist}/client/locale/index.d.ts +0 -0
  92. /package/{lib → dist}/client/style.d.ts +0 -0
  93. /package/{lib → dist}/locale/en-US.d.ts +0 -0
  94. /package/{lib → dist}/locale/es-ES.d.ts +0 -0
  95. /package/{lib → dist}/locale/fr-FR.d.ts +0 -0
  96. /package/{lib → dist}/locale/ja-JP.d.ts +0 -0
  97. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  98. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  99. /package/{lib → dist}/server/collections/graphPositions.d.ts +0 -0
  100. /package/{lib → dist}/server/index.d.ts +0 -0
@@ -1,237 +0,0 @@
1
- import { observer, useForm } from '@formily/react';
2
- import { action } from '@formily/reactive';
3
- import {
4
- useAPIClient,
5
- useActionContext,
6
- useCollectionFieldFormValues,
7
- useCollectionManager,
8
- useCompile,
9
- useRequest,
10
- } from '@nocobase/client';
11
- import { error } from '@nocobase/utils/client';
12
- import { Select, message } from 'antd';
13
- import { lodash } from '@nocobase/utils/client'
14
- import React, { useContext, useEffect } from 'react';
15
- import { useTranslation } from 'react-i18next';
16
- import { GraphCollectionContext } from './components/CollectionNodeProvder';
17
-
18
- export const useValuesFromRecord = (options, data) => {
19
- const result = useRequest(() => Promise.resolve({ data }), {
20
- ...options,
21
- manual: true,
22
- });
23
- const ctx = useActionContext();
24
- useEffect(() => {
25
- if (ctx.visible) {
26
- result.run();
27
- }
28
- }, [ctx.visible]);
29
- return result;
30
- };
31
-
32
- export const SourceCollection = observer(
33
- () => {
34
- const { record } = useContext(GraphCollectionContext);
35
- const compile = useCompile();
36
- return (
37
- <div>
38
- <Select
39
- popupMatchSelectWidth={false}
40
- disabled
41
- value={record.name}
42
- options={[{ value: record.name, label: compile(record.title) }]}
43
- />
44
- </div>
45
- );
46
- },
47
- { displayName: 'SourceCollection' },
48
- );
49
-
50
- export const useCancelAction = () => {
51
- const form = useForm();
52
- const ctx = useActionContext();
53
- return {
54
- async run() {
55
- ctx.setVisible(false);
56
- form.reset();
57
- },
58
- };
59
- };
60
-
61
- export const useCreateActionAndRefreshCM = (setTargetNode) => {
62
- const form = useForm();
63
- const api = useAPIClient();
64
- const ctx = useActionContext();
65
- const { refreshCM } = useCollectionManager();
66
-
67
- return {
68
- async run() {
69
- await form.submit();
70
- await api.resource('collections').create({ values: form.values });
71
- ctx.setVisible(false);
72
- await form.reset();
73
- setTargetNode('last');
74
- await refreshCM();
75
- },
76
- };
77
- };
78
-
79
- export const useCreateAction = (collectionName, targetId?) => {
80
- const form = useForm();
81
- const api = useAPIClient();
82
- const ctx = useActionContext();
83
- const { refreshCM } = useCollectionManager();
84
- const { positionTargetNode, openPorts } = useContext(GraphCollectionContext);
85
- const { getValues } = useCollectionFieldFormValues();
86
-
87
- return {
88
- async run() {
89
- await form.submit();
90
- const values = getValues();
91
- const formValues = lodash.omit(values, [
92
- 'key',
93
- 'uiSchemaUid',
94
- 'collectionName',
95
- 'autoCreateReverseField',
96
- 'uiSchema.x-uid',
97
- 'reverseField.key',
98
- 'reverseField.uiSchemaUid',
99
- ]);
100
- const isOpenPorts = !['obo', 'oho', 'o2o', 'o2m', 'm2o', 'm2m', 'linkTo', 'id'].includes(values.interface);
101
- const {
102
- data: { data },
103
- } = await api.resource('collections.fields', collectionName).create({
104
- values: formValues,
105
- });
106
- targetId &&
107
- (await api.resource('fields').move({
108
- sourceId: data.key,
109
- targetId,
110
- targetScope: collectionName,
111
- method: 'insertAfter',
112
- }));
113
- ctx.setVisible(false);
114
- await form.reset();
115
- positionTargetNode();
116
- isOpenPorts && openPorts && openPorts();
117
- await refreshCM();
118
- },
119
- };
120
- };
121
-
122
- export const useUpdateFieldAction = ({ collectionName, name, key }) => {
123
- const { refreshCM } = useCollectionManager();
124
- const { t } = useTranslation();
125
- const form = useForm();
126
- const ctx = useActionContext();
127
- const api = useAPIClient();
128
- const { positionTargetNode, node } = useContext(GraphCollectionContext);
129
- return {
130
- async run() {
131
- await form.submit();
132
- await api.resource('collections.fields', collectionName).update({
133
- filterByTk: name,
134
- values: form.values,
135
- });
136
- ctx.setVisible(false);
137
- message.success(t('Saved successfully'));
138
- positionTargetNode();
139
- refreshCM();
140
- node.setPortProp(key, 'uiSchema', { title: form.values?.uiSchema.title });
141
- await form.reset();
142
- },
143
- };
144
- };
145
-
146
- export const useUpdateCollectionActionAndRefreshCM = () => {
147
- const { t } = useTranslation();
148
- const form = useForm();
149
- const ctx = useActionContext();
150
- const { name } = form.values;
151
- const api = useAPIClient();
152
- const { refreshCM } = useCollectionManager();
153
- const { positionTargetNode } = useContext(GraphCollectionContext);
154
- return {
155
- async run() {
156
- await form.submit();
157
- await api.resource('collections').update({
158
- filterByTk: name,
159
- values: { ...lodash.omit(form.values, ['fields']) },
160
- });
161
- ctx.setVisible(false);
162
- message.success(t('Saved successfully'));
163
- await form.reset();
164
- positionTargetNode();
165
- refreshCM();
166
- },
167
- };
168
- };
169
-
170
- const useDestroyAction = (name) => {
171
- const api = useAPIClient();
172
- return {
173
- async run() {
174
- await api.resource('collections').destroy({
175
- filterByTk: name,
176
- });
177
- await api.resource('graphPositions').destroy({
178
- filter: { collectionName: name },
179
- });
180
- },
181
- };
182
- };
183
-
184
- export const useDestroyActionAndRefreshCM = (props) => {
185
- const { name } = props;
186
- const { run } = useDestroyAction(name);
187
- const { refreshCM } = useCollectionManager();
188
- const { positionTargetNode } = useContext(GraphCollectionContext);
189
- return {
190
- async run() {
191
- await run();
192
- positionTargetNode('destory');
193
- await refreshCM();
194
- },
195
- };
196
- };
197
-
198
- const useDestroyFieldAction = (collectionName, name) => {
199
- const api = useAPIClient();
200
- const { positionTargetNode } = useContext(GraphCollectionContext);
201
- return {
202
- async run() {
203
- await api.resource('collections.fields', collectionName).destroy({
204
- filterByTk: name,
205
- });
206
- positionTargetNode();
207
- },
208
- };
209
- };
210
-
211
- export const useDestroyFieldActionAndRefreshCM = (props) => {
212
- const { collectionName, name } = props;
213
- const { refreshCM } = useCollectionManager();
214
- const { run } = useDestroyFieldAction(collectionName, name);
215
- return {
216
- async run() {
217
- await run();
218
- await refreshCM();
219
- },
220
- };
221
- };
222
-
223
- export const useAsyncDataSource = (service: any) => {
224
- return (field: any, { targetScope }) => {
225
- field.loading = true;
226
- service(targetScope)
227
- .then(
228
- action.bound((data: any) => {
229
- field.dataSource = data;
230
- field.loading = false;
231
- }),
232
- )
233
- .catch((err) => {
234
- error(err);
235
- });
236
- };
237
- };
@@ -1,28 +0,0 @@
1
- import { PlusOutlined } from '@ant-design/icons';
2
- import { AddCollection } from '@nocobase/client';
3
- import { Button } from 'antd';
4
- import React from 'react';
5
- import { useCancelAction } from '../action-hooks';
6
- import { getPopupContainer } from '../utils';
7
-
8
- export const AddCollectionAction = ({ item: record }) => {
9
- return (
10
- <AddCollection
11
- trigger={['click']}
12
- align={{
13
- overflow: {
14
- adjustY: false, // 关闭溢出位置调整
15
- },
16
- }}
17
- item={record}
18
- scope={{
19
- useCancelAction,
20
- }}
21
- getContainer={getPopupContainer}
22
- >
23
- <Button type="primary">
24
- <PlusOutlined />
25
- </Button>
26
- </AddCollection>
27
- );
28
- };
@@ -1,37 +0,0 @@
1
- import { PlusOutlined } from '@ant-design/icons';
2
- import { AddFieldAction as AddCollectionFieldAction } from '@nocobase/client';
3
- import React from 'react';
4
- import { useCancelAction, useCreateAction } from '../action-hooks';
5
- import { getPopupContainer } from '../utils';
6
-
7
- const useCreateCollectionField = (record) => {
8
- const title = record.collectionName;
9
- const { run } = useCreateAction(title, record.key);
10
- return {
11
- async run() {
12
- await run();
13
- },
14
- };
15
- };
16
-
17
- export const AddFieldAction = ({ item: record, database }) => {
18
- return (
19
- <AddCollectionFieldAction
20
- trigger={['click']}
21
- align={{
22
- overflow: {
23
- adjustY: false, // 关闭溢出位置调整
24
- },
25
- }}
26
- item={record}
27
- database={database}
28
- scope={{
29
- useCancelAction,
30
- useCreateCollectionField: () => useCreateCollectionField(record),
31
- }}
32
- getContainer={getPopupContainer}
33
- >
34
- <PlusOutlined className="btn-add" id="graph_btn_add_field" />
35
- </AddCollectionFieldAction>
36
- );
37
- };
@@ -1,28 +0,0 @@
1
- import React, { createContext } from 'react';
2
-
3
- interface CollectionNodeOptions {
4
- setTargetNode?: Function;
5
- node?: Node | any;
6
- record?: Object;
7
- handelOpenPorts?: Function;
8
- }
9
- export const GraphCollectionContext = createContext(null);
10
-
11
- export const CollectionNodeProvder: React.FC<CollectionNodeOptions> = (props: any) => {
12
- const { record, setTargetNode, node, handelOpenPorts } = props;
13
-
14
- return (
15
- <GraphCollectionContext.Provider
16
- value={{
17
- node,
18
- record,
19
- positionTargetNode: (target) => {
20
- setTargetNode(target || node);
21
- },
22
- openPorts: handelOpenPorts,
23
- }}
24
- >
25
- {props.children}
26
- </GraphCollectionContext.Provider>
27
- );
28
- };
@@ -1,21 +0,0 @@
1
- import { EditOutlined } from '@ant-design/icons';
2
- import { EditCollection } from '@nocobase/client';
3
- import React from 'react';
4
- import { useCancelAction, useUpdateCollectionActionAndRefreshCM } from '../action-hooks';
5
- import { getPopupContainer } from '../utils';
6
-
7
- export const EditCollectionAction = ({ item: record, className }) => {
8
- return (
9
- <EditCollection
10
- item={record}
11
- scope={{
12
- useCancelAction,
13
- useUpdateCollectionActionAndRefreshCM,
14
- createOnly: false,
15
- }}
16
- getContainer={getPopupContainer}
17
- >
18
- <EditOutlined className={className} />
19
- </EditCollection>
20
- );
21
- };
@@ -1,30 +0,0 @@
1
- import { EditOutlined } from '@ant-design/icons';
2
- import { EditFieldAction as EditCollectionFieldAction } from '@nocobase/client';
3
- import React from 'react';
4
- import { useCancelAction, useUpdateFieldAction } from '../action-hooks';
5
- import { getPopupContainer } from '../utils';
6
-
7
- const useUpdateCollectionField = (record) => {
8
- const collectionName = record.collectionName;
9
- const { run } = useUpdateFieldAction({ collectionName, name: record.name, key: record.key });
10
- return {
11
- async run() {
12
- await run();
13
- },
14
- };
15
- };
16
-
17
- export const EditFieldAction = ({ item: record }) => {
18
- return (
19
- <EditCollectionFieldAction
20
- item={record}
21
- scope={{
22
- useCancelAction,
23
- useUpdateCollectionField: () => useUpdateCollectionField(record),
24
- }}
25
- getContainer={getPopupContainer}
26
- >
27
- <EditOutlined className="btn-edit" />
28
- </EditCollectionFieldAction>
29
- );
30
- };