@nocobase/client-v2 2.1.31 → 2.2.0-alpha.10

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 (170) hide show
  1. package/es/APIClient.d.ts +1 -3
  2. package/es/BaseApplication.d.ts +2 -0
  3. package/es/PluginSettingsManager.d.ts +33 -0
  4. package/es/RouteRepository.d.ts +29 -6
  5. package/es/RouterManager.d.ts +15 -0
  6. package/es/authRedirect.d.ts +1 -0
  7. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  8. package/es/components/category-tabs/index.d.ts +9 -0
  9. package/es/components/form/TypedVariableInput.d.ts +31 -5
  10. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  11. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  12. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  13. package/es/components/form/filter/index.d.ts +2 -0
  14. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  15. package/es/components/index.d.ts +2 -0
  16. package/es/entry-actions/EntryActionManager.d.ts +24 -0
  17. package/es/entry-actions/index.d.ts +9 -0
  18. package/es/flow/actions/index.d.ts +1 -1
  19. package/es/flow/actions/linkageRules.d.ts +2 -0
  20. package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
  21. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
  22. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +3 -0
  23. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
  24. package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
  25. package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
  26. package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
  27. package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
  28. package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
  29. package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
  30. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  31. package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
  32. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  33. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  34. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  35. package/es/flow/index.d.ts +1 -0
  36. package/es/flow/models/base/ActionModelCore.d.ts +2 -0
  37. package/es/flow/models/base/GridModel.d.ts +1 -1
  38. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  39. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  40. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  41. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
  42. package/es/flow-compat/routeTypes.d.ts +1 -0
  43. package/es/index.d.ts +7 -1
  44. package/es/index.mjs +223 -135
  45. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  46. package/es/utils/index.d.ts +1 -0
  47. package/lib/index.js +220 -132
  48. package/package.json +7 -7
  49. package/src/APIClient.ts +1 -10
  50. package/src/Application.tsx +4 -0
  51. package/src/BaseApplication.tsx +2 -0
  52. package/src/PluginSettingsManager.ts +53 -0
  53. package/src/RouteRepository.ts +151 -24
  54. package/src/RouterManager.tsx +142 -1
  55. package/src/__tests__/PluginSettingsManager.test.ts +13 -0
  56. package/src/__tests__/RouteRepository.test.ts +239 -0
  57. package/src/__tests__/RouterManager.test.ts +125 -0
  58. package/src/__tests__/app.test.tsx +18 -0
  59. package/src/__tests__/authRedirect.test.ts +17 -0
  60. package/src/__tests__/browserChecker.test.ts +61 -0
  61. package/src/__tests__/exports.test.ts +16 -0
  62. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  63. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
  64. package/src/__tests__/plugin-manager.test.tsx +44 -2
  65. package/src/__tests__/settings-center.test.tsx +40 -1
  66. package/src/authRedirect.ts +38 -0
  67. package/src/components/README.md +7 -1
  68. package/src/components/README.zh-CN.md +6 -1
  69. package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
  70. package/src/components/category-tabs/index.ts +10 -0
  71. package/src/components/form/JsonTextArea.tsx +4 -0
  72. package/src/components/form/TypedVariableInput.tsx +452 -101
  73. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  74. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  75. package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
  76. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  77. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
  78. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  79. package/src/components/form/filter/index.ts +2 -0
  80. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  81. package/src/components/index.ts +2 -0
  82. package/src/entry-actions/EntryActionManager.ts +76 -0
  83. package/src/entry-actions/index.ts +10 -0
  84. package/src/flow/__tests__/FlowRoute.test.tsx +1084 -145
  85. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  86. package/src/flow/actions/customVariable.tsx +1 -2
  87. package/src/flow/actions/index.ts +2 -0
  88. package/src/flow/actions/linkageRules.tsx +65 -8
  89. package/src/flow/actions/runjs.tsx +2 -14
  90. package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
  91. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +46 -13
  92. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +486 -0
  93. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +64 -8
  94. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
  95. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
  96. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
  97. package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
  98. package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
  99. package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
  100. package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
  101. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +435 -0
  102. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
  103. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
  104. package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +214 -2
  105. package/src/flow/admin-shell/admin-layout/index.ts +1 -0
  106. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
  107. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
  108. package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
  109. package/src/flow/components/DefaultValue.tsx +1 -2
  110. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  111. package/src/flow/components/FieldAssignValueInput.tsx +76 -9
  112. package/src/flow/components/FlowRoute.tsx +185 -28
  113. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  114. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
  115. package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
  116. package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
  117. package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
  118. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  119. package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
  120. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  121. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  122. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
  123. package/src/flow/index.ts +1 -0
  124. package/src/flow/models/actions/JSActionModel.tsx +2 -7
  125. package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
  126. package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
  127. package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
  128. package/src/flow/models/base/ActionModel.tsx +21 -8
  129. package/src/flow/models/base/ActionModelCore.tsx +5 -0
  130. package/src/flow/models/base/GridModel.tsx +38 -7
  131. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  132. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  133. package/src/flow/models/base/PageModel/PageTabModel.tsx +186 -3
  134. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -14
  135. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  136. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  137. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +586 -1
  138. package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
  139. package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
  140. package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
  141. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
  142. package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
  143. package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
  144. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
  145. package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
  146. package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
  147. package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
  148. package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
  149. package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +1 -1
  150. package/src/flow/models/blocks/table/TableBlockModel.tsx +13 -3
  151. package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +54 -0
  152. package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
  153. package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
  154. package/src/flow/models/fields/JSFieldModel.tsx +2 -7
  155. package/src/flow/models/fields/JSItemModel.tsx +2 -14
  156. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  157. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  158. package/src/flow/models/topbar/TopbarActionModel.tsx +168 -10
  159. package/src/flow-compat/Popover.tsx +43 -4
  160. package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
  161. package/src/flow-compat/routeTypes.ts +1 -0
  162. package/src/index.ts +13 -1
  163. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
  164. package/src/nocobase-buildin-plugin/index.tsx +19 -3
  165. package/src/settings-center/AdminSettingsLayout.tsx +10 -2
  166. package/src/settings-center/SystemSettingsPage.tsx +0 -1
  167. package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
  168. package/src/settings-center/utils.tsx +0 -6
  169. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  170. package/src/utils/index.tsx +1 -0
@@ -0,0 +1,289 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { SettingOutlined } from '@ant-design/icons';
11
+ import { css } from '@emotion/css';
12
+ import { Icon } from '../../../components';
13
+ import { ActionModel } from '../../models/base';
14
+ import {
15
+ AddSubModelButton,
16
+ DndProvider,
17
+ DragHandler,
18
+ Droppable,
19
+ FlowModel,
20
+ FlowModelRenderer,
21
+ FlowSettingsButton,
22
+ mergeSubModelItems,
23
+ observer,
24
+ type SubModelItem,
25
+ type SubModelItemsType,
26
+ } from '@nocobase/flow-engine';
27
+ import { Avatar, Button, Card, Tooltip, Typography } from 'antd';
28
+ import React from 'react';
29
+
30
+ const defaultIconColors = ['#3d8bff', '#00a8b5', '#35b26b', '#f5a623', '#ff7a45', '#e85d75', '#9254de', '#597ef7'];
31
+
32
+ function getDefaultIconColor(title?: React.ReactNode) {
33
+ const source = typeof title === 'string' ? title : '';
34
+ const hash = Array.from(source).reduce((sum, char) => sum + char.charCodeAt(0), 0);
35
+ return defaultIconColors[hash % defaultIconColors.length];
36
+ }
37
+
38
+ type AppSwitcherActionPanelStructure = {
39
+ subModels: {
40
+ actions?: ActionModel[];
41
+ };
42
+ };
43
+
44
+ function isRenderableActionModel(action: unknown): action is ActionModel {
45
+ if (!action || typeof action !== 'object') {
46
+ return false;
47
+ }
48
+
49
+ const candidate = action as Partial<ActionModel>;
50
+ return typeof candidate.getTitle === 'function' && typeof candidate.onClick === 'function';
51
+ }
52
+
53
+ type EntryActionAvailability = {
54
+ isEntryActionAvailable?: () => boolean;
55
+ getEntryActionUnavailableMessage?: () => string | undefined;
56
+ };
57
+
58
+ function isEntryActionUnavailable(action: ActionModel) {
59
+ const candidate = action as ActionModel & EntryActionAvailability;
60
+ return typeof candidate.isEntryActionAvailable === 'function' && !candidate.isEntryActionAvailable();
61
+ }
62
+
63
+ function getEntryActionUnavailableMessage(action: ActionModel) {
64
+ const candidate = action as ActionModel & EntryActionAvailability;
65
+ return candidate.getEntryActionUnavailableMessage?.();
66
+ }
67
+
68
+ export class AppSwitcherActionPanelModel extends FlowModel<AppSwitcherActionPanelStructure> {
69
+ getConfigureActionsItems(): SubModelItemsType {
70
+ const linkAction: SubModelItem = {
71
+ key: 'app-switcher:link',
72
+ label: this.context.t('Link'),
73
+ createModelOptions: {
74
+ use: 'LinkActionModel',
75
+ },
76
+ };
77
+ const jsAction: SubModelItem = {
78
+ key: 'app-switcher:js-action',
79
+ label: this.context.t('JS action'),
80
+ createModelOptions: {
81
+ use: 'JSActionModel',
82
+ },
83
+ };
84
+
85
+ return mergeSubModelItems([[linkAction], this.context.app.entryActionManager.getItems('app-switcher'), [jsAction]]);
86
+ }
87
+
88
+ renderConfigureActions() {
89
+ return <AppSwitcherConfigureActionsButton model={this} />;
90
+ }
91
+
92
+ private getRenderableActions(options: { includeHidden?: boolean; includeUnavailable?: boolean } = {}) {
93
+ return this.mapSubModels('actions', (action) => action)
94
+ .filter(isRenderableActionModel)
95
+ .filter((action) => options.includeUnavailable || !isEntryActionUnavailable(action))
96
+ .filter((action) => options.includeHidden || !action.hidden);
97
+ }
98
+
99
+ hasActions() {
100
+ return this.getRenderableActions().length > 0;
101
+ }
102
+
103
+ renderContent() {
104
+ const token = this.context.themeToken;
105
+ const designable = !!this.context.flowSettingsEnabled;
106
+ const actions = this.getRenderableActions({ includeHidden: designable, includeUnavailable: designable });
107
+ const columnCount = Math.min(Math.max(actions.length || 1, 1), 2);
108
+ const buttonResetClass = css`
109
+ &.ant-btn {
110
+ display: block;
111
+ width: 100%;
112
+ height: 100%;
113
+ padding: 0;
114
+ border: none;
115
+ box-shadow: none;
116
+ background: none;
117
+ color: ${token.colorText};
118
+ text-align: left;
119
+ }
120
+ &.ant-btn > span {
121
+ display: block;
122
+ width: 100%;
123
+ height: 100%;
124
+ }
125
+ .ant-btn-icon {
126
+ display: none;
127
+ }
128
+ `;
129
+ const contentClass = css`
130
+ max-width: calc(100vw - 48px);
131
+ max-height: calc(100vh - 48px);
132
+ overflow: auto;
133
+ padding: ${token.paddingXS}px;
134
+ `;
135
+ const listClass = css`
136
+ display: grid;
137
+ grid-template-columns: repeat(${columnCount}, 260px);
138
+ gap: ${token.marginXXS}px;
139
+ margin: 0;
140
+ padding: 0;
141
+ list-style: none;
142
+ `;
143
+
144
+ return (
145
+ <div className={contentClass}>
146
+ {actions.length ? (
147
+ <DndProvider>
148
+ <ul className={listClass}>
149
+ {actions.map((action) => {
150
+ const { icon = 'AppstoreOutlined', color } = action.props;
151
+ const title = action.getTitle();
152
+ const entryActionUnavailable = isEntryActionUnavailable(action);
153
+ const renderActionContent = (compact = false) => (
154
+ <Card
155
+ bordered={false}
156
+ className={css`
157
+ height: 56px;
158
+ border-radius: ${token.borderRadius}px;
159
+ box-shadow: none !important;
160
+ opacity: ${compact ? token.opacityLoading : 1};
161
+
162
+ &:hover {
163
+ background: ${token.colorBgTextHover};
164
+ box-shadow: none !important;
165
+ }
166
+
167
+ .ant-card-body {
168
+ height: 100%;
169
+ padding: ${token.paddingXS}px;
170
+ display: flex;
171
+ align-items: center;
172
+ gap: ${token.marginXS}px;
173
+ }
174
+ `}
175
+ styles={{ body: { background: 'transparent' } }}
176
+ >
177
+ <Avatar
178
+ size={32}
179
+ shape="square"
180
+ icon={<Icon type={icon as string} />}
181
+ style={{
182
+ flex: '0 0 auto',
183
+ borderRadius: 6,
184
+ background: color || getDefaultIconColor(title),
185
+ }}
186
+ />
187
+ <Typography.Text
188
+ ellipsis
189
+ title={typeof title === 'string' ? title : undefined}
190
+ style={{
191
+ minWidth: 0,
192
+ color: token.colorText,
193
+ fontSize: token.fontSize,
194
+ lineHeight: token.lineHeight,
195
+ }}
196
+ >
197
+ {title}
198
+ </Typography.Text>
199
+ </Card>
200
+ );
201
+ action.enableEditDanger = false;
202
+ action.enableEditType = false;
203
+ action.enableEditIconOnly = false;
204
+ action.enableEditColor = true;
205
+ action.renderButton = () => {
206
+ if (entryActionUnavailable) {
207
+ return (
208
+ <Tooltip title={getEntryActionUnavailableMessage(action)}>
209
+ <Button className={buttonResetClass} onClick={action.onClick.bind(action)}>
210
+ {renderActionContent(true)}
211
+ </Button>
212
+ </Tooltip>
213
+ );
214
+ }
215
+ return (
216
+ <Button className={buttonResetClass} onClick={action.onClick.bind(action)}>
217
+ {renderActionContent()}
218
+ </Button>
219
+ );
220
+ };
221
+ action.renderHiddenInConfig = () => (
222
+ <Tooltip
223
+ title={
224
+ entryActionUnavailable
225
+ ? getEntryActionUnavailableMessage(action)
226
+ : this.context.t('The button is hidden and only visible when the UI Editor is active')
227
+ }
228
+ >
229
+ <Button className={buttonResetClass} onClick={action.onClick.bind(action)}>
230
+ {renderActionContent(true)}
231
+ </Button>
232
+ </Tooltip>
233
+ );
234
+
235
+ return (
236
+ <li key={action.uid} style={{ width: 260, height: 56, listStyle: 'none' }}>
237
+ <Droppable model={action}>
238
+ <FlowModelRenderer
239
+ model={action}
240
+ showFlowSettings={{ showBackground: false, showBorder: false, toolbarPosition: 'above' }}
241
+ extraToolbarItems={
242
+ designable
243
+ ? [
244
+ {
245
+ key: 'drag-handler',
246
+ component: DragHandler,
247
+ sort: 1,
248
+ },
249
+ ]
250
+ : []
251
+ }
252
+ />
253
+ </Droppable>
254
+ </li>
255
+ );
256
+ })}
257
+ </ul>
258
+ </DndProvider>
259
+ ) : (
260
+ <div style={{ width: 260, minHeight: token.marginXS }} />
261
+ )}
262
+ {designable && <div style={{ marginTop: token.marginXS }}>{this.renderConfigureActions()}</div>}
263
+ </div>
264
+ );
265
+ }
266
+ }
267
+
268
+ AppSwitcherActionPanelModel.define({
269
+ label: 'App switcher actions',
270
+ children: false,
271
+ createModelOptions: {
272
+ use: 'AppSwitcherActionPanelModel',
273
+ },
274
+ });
275
+
276
+ const AppSwitcherConfigureActionsButton = observer(({ model }: { model: AppSwitcherActionPanelModel }) => {
277
+ const entryActionsRevision = model.context.app.entryActionManager.revision;
278
+ return (
279
+ <AddSubModelButton
280
+ key={`app-switcher-add-actions-${entryActionsRevision}`}
281
+ model={model}
282
+ items={model.getConfigureActionsItems()}
283
+ subModelKey="actions"
284
+ keepDropdownOpen
285
+ >
286
+ <FlowSettingsButton icon={<SettingOutlined />}>{model.context.t('Actions')}</FlowSettingsButton>
287
+ </AddSubModelButton>
288
+ );
289
+ });