@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.
- package/es/APIClient.d.ts +1 -3
- package/es/BaseApplication.d.ts +2 -0
- package/es/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +29 -6
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +2 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +3 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- package/es/flow/components/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/ActionModelCore.d.ts +2 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +7 -1
- package/es/index.mjs +223 -135
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +220 -132
- package/package.json +7 -7
- package/src/APIClient.ts +1 -10
- package/src/Application.tsx +4 -0
- package/src/BaseApplication.tsx +2 -0
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +151 -24
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +239 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/app.test.tsx +18 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/authRedirect.ts +38 -0
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/index.ts +2 -0
- package/src/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +1084 -145
- package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +65 -8
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +46 -13
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +486 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +64 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +435 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +214 -2
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +76 -9
- package/src/flow/components/FlowRoute.tsx +185 -28
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/components/filter/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
- package/src/flow/index.ts +1 -0
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +21 -8
- package/src/flow/models/base/ActionModelCore.tsx +5 -0
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +186 -3
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -14
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +586 -1
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +1 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +13 -3
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +54 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +168 -10
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +13 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +19 -3
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +0 -1
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/utils.tsx +0 -6
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -18,6 +18,19 @@ class TestAclPlugin extends Plugin {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
class TestSettingsLinkPlugin extends Plugin {
|
|
22
|
+
async load() {
|
|
23
|
+
this.app.pluginSettingsManager.addMenuItem({ key: 'shared-settings', title: 'Shared settings' });
|
|
24
|
+
this.app.pluginSettingsManager.addPageTabItem({
|
|
25
|
+
menuKey: 'shared-settings',
|
|
26
|
+
key: 'target',
|
|
27
|
+
title: 'Target settings',
|
|
28
|
+
Component: () => <div>Target settings page</div>,
|
|
29
|
+
});
|
|
30
|
+
this.app.pluginSettingsManager.setPluginSettingsLink('demo-plugin', 'shared-settings.target');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
type MockClientApplication = ReturnType<typeof createMockClient>;
|
|
22
35
|
|
|
23
36
|
const renderApp = (app: MockClientApplication) => {
|
|
@@ -35,9 +48,9 @@ const waitForGetRequests = async (app: MockClientApplication, urls: string[]) =>
|
|
|
35
48
|
);
|
|
36
49
|
};
|
|
37
50
|
|
|
38
|
-
const setupApp = (pmList: any[]) => {
|
|
51
|
+
const setupApp = (pmList: any[], plugins: Array<typeof Plugin> = []) => {
|
|
39
52
|
const app = createMockClient({
|
|
40
|
-
plugins: [NocoBaseBuildInPlugin, TestAclPlugin],
|
|
53
|
+
plugins: [NocoBaseBuildInPlugin, TestAclPlugin, ...plugins],
|
|
41
54
|
router: { type: 'memory', initialEntries: ['/admin/settings/plugin-manager'] },
|
|
42
55
|
});
|
|
43
56
|
|
|
@@ -174,4 +187,33 @@ describe('plugin-manager page', () => {
|
|
|
174
187
|
expect(removeCall?.params).toMatchObject({ filterByTk: 'demo-plugin' });
|
|
175
188
|
});
|
|
176
189
|
});
|
|
190
|
+
|
|
191
|
+
it('shows Settings for a plugin linked to a different settings page', async () => {
|
|
192
|
+
const app = setupApp(
|
|
193
|
+
[
|
|
194
|
+
{
|
|
195
|
+
name: 'demo-plugin',
|
|
196
|
+
packageName: '@nocobase/demo-plugin',
|
|
197
|
+
displayName: 'Demo plugin',
|
|
198
|
+
description: 'A demo',
|
|
199
|
+
enabled: true,
|
|
200
|
+
builtIn: false,
|
|
201
|
+
removable: false,
|
|
202
|
+
version: '0.1.0',
|
|
203
|
+
isCompatible: true,
|
|
204
|
+
keywords: [],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
[TestSettingsLinkPlugin],
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
renderApp(app);
|
|
211
|
+
await waitForGetRequests(app, ['/auth:check', 'roles:check', 'pm:list']);
|
|
212
|
+
|
|
213
|
+
const card = await screen.findByRole('button', { name: 'Demo plugin' });
|
|
214
|
+
const settingsLink = within(card.closest('.ant-card') as HTMLElement).getByText('Settings');
|
|
215
|
+
fireEvent.click(settingsLink);
|
|
216
|
+
|
|
217
|
+
expect(await screen.findByText('Target settings page')).toBeInTheDocument();
|
|
218
|
+
});
|
|
177
219
|
});
|
|
@@ -14,7 +14,7 @@ import { message } from 'antd';
|
|
|
14
14
|
import { AdminSettingsLayoutModel as ClientV2AdminSettingsLayoutModel } from '../settings-center';
|
|
15
15
|
import { AdminSettingsLayoutModel as ClientV1AdminSettingsLayoutModel } from '../../../client/src/pm/AdminSettingsLayoutModel';
|
|
16
16
|
import { NocoBaseBuildInPlugin } from '../nocobase-buildin-plugin';
|
|
17
|
-
import { matchSettingsRoute } from '../settings-center/utils';
|
|
17
|
+
import { matchSettingsRoute, sortTopLevelSettings } from '../settings-center/utils';
|
|
18
18
|
|
|
19
19
|
class TestAclPlugin extends Plugin {
|
|
20
20
|
async load() {
|
|
@@ -168,6 +168,12 @@ describe('settings center', () => {
|
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
+
it('should sort system-settings with other top-level settings by normal ordering', () => {
|
|
172
|
+
const settings = [{ name: 'system-settings' }, { name: 'api-keys' }, { name: 'backups' }] as any;
|
|
173
|
+
|
|
174
|
+
expect(sortTopLevelSettings(settings).map((item) => item.name)).toEqual(['api-keys', 'backups', 'system-settings']);
|
|
175
|
+
});
|
|
176
|
+
|
|
171
177
|
it('should redirect /admin/settings to system-settings by default', async () => {
|
|
172
178
|
const app = createMockClient({
|
|
173
179
|
plugins: [NocoBaseBuildInPlugin, TestAclPlugin],
|
|
@@ -354,6 +360,39 @@ describe('settings center', () => {
|
|
|
354
360
|
expect(screen.getByRole('menuitem', { name: 'Menu ACL Demo' })).toBeInTheDocument();
|
|
355
361
|
});
|
|
356
362
|
|
|
363
|
+
it('should allow the settings sidebar menu to scroll independently', async () => {
|
|
364
|
+
class ManySettingsPlugin extends Plugin {
|
|
365
|
+
async load() {
|
|
366
|
+
for (let index = 0; index < 30; index += 1) {
|
|
367
|
+
this.pluginSettingsManager.addMenuItem({
|
|
368
|
+
key: `scroll-demo-${index}`,
|
|
369
|
+
title: `Scroll demo ${index}`,
|
|
370
|
+
});
|
|
371
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
372
|
+
menuKey: `scroll-demo-${index}`,
|
|
373
|
+
key: 'index',
|
|
374
|
+
title: `Scroll demo ${index}`,
|
|
375
|
+
Component: () => <div>{`Scroll demo page ${index}`}</div>,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const app = createMockClient({
|
|
382
|
+
plugins: [NocoBaseBuildInPlugin, TestAclPlugin, ManySettingsPlugin],
|
|
383
|
+
router: { type: 'memory', initialEntries: ['/admin/settings/scroll-demo-29'] },
|
|
384
|
+
});
|
|
385
|
+
mockAdminRuntime(app);
|
|
386
|
+
|
|
387
|
+
await renderApp(app);
|
|
388
|
+
await waitForGetRequests(app, ['/auth:check', 'roles:check']);
|
|
389
|
+
|
|
390
|
+
expect(await screen.findByText('Scroll demo page 29')).toBeInTheDocument();
|
|
391
|
+
|
|
392
|
+
const sidebar = screen.getByRole('menuitem', { name: 'Scroll demo 29' }).closest('.ant-layout-sider');
|
|
393
|
+
expect(sidebar).toHaveStyle({ overflowY: 'auto' });
|
|
394
|
+
});
|
|
395
|
+
|
|
357
396
|
it('should save system settings through systemSettings:put', async () => {
|
|
358
397
|
const app = createMockClient({
|
|
359
398
|
plugins: [NocoBaseBuildInPlugin, TestAclPlugin],
|
package/src/authRedirect.ts
CHANGED
|
@@ -204,6 +204,44 @@ function getDefaultV2AdminRedirectPath(app: AppLike) {
|
|
|
204
204
|
return joinRootRelativePath(getV2EffectiveBasePath(app), '/admin');
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
+
function isSafeRootRelativePath(value?: string | null) {
|
|
208
|
+
return !!value && value.startsWith('/') && !value.startsWith('//') && !value.startsWith('/\\');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function preserveTrailingSlash(originalPathname: string, value: string) {
|
|
212
|
+
if (originalPathname !== '/' && originalPathname.endsWith('/') && !value.endsWith('/')) {
|
|
213
|
+
return `${value}/`;
|
|
214
|
+
}
|
|
215
|
+
return value;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function normalizeV2RedirectPath(app: AppLike, target?: string | null, fallbackPath = '/admin/') {
|
|
219
|
+
// In a v2 sub-app, publicPath can be `/v/` while the active router
|
|
220
|
+
// basename is `/v/apps/a/`. Redirects must resolve under the basename.
|
|
221
|
+
const basePath = trimTrailingSlashes(getV2EffectiveBasePath(app)) || '/';
|
|
222
|
+
const fallbackTarget = isSafeRootRelativePath(fallbackPath) ? fallbackPath : '/admin/';
|
|
223
|
+
const rawTarget = isSafeRootRelativePath(target) ? target : fallbackTarget;
|
|
224
|
+
let { pathname, search, hash } = splitPathLike(rawTarget);
|
|
225
|
+
let normalizedPathname = normalizePathname(pathname);
|
|
226
|
+
|
|
227
|
+
// Already under the current v2 runtime, e.g. `/v/apps/a/admin/`.
|
|
228
|
+
if (basePath === '/' || normalizedPathname === basePath || normalizedPathname.startsWith(`${basePath}/`)) {
|
|
229
|
+
return `${preserveTrailingSlash(pathname, normalizedPathname)}${normalizeSearch(search)}${normalizeHash(hash)}`;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const publicPath = trimTrailingSlashes(getV2PublicPath(app)) || '/';
|
|
233
|
+
// Under v2 publicPath but outside the current basename, e.g. `/v/admin/`
|
|
234
|
+
// inside `/v/apps/a/`; use fallback so it lands on `/v/apps/a/admin/`.
|
|
235
|
+
if (publicPath !== '/' && (normalizedPathname === publicPath || normalizedPathname.startsWith(`${publicPath}/`))) {
|
|
236
|
+
({ pathname, search, hash } = splitPathLike(fallbackTarget));
|
|
237
|
+
normalizedPathname = normalizePathname(pathname);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Basename-relative target, e.g. `/admin/`, becomes `/v/apps/a/admin/`.
|
|
241
|
+
const joinedPathname = preserveTrailingSlash(pathname, joinRootRelativePath(basePath, normalizedPathname));
|
|
242
|
+
return `${joinedPathname}${normalizeSearch(search)}${normalizeHash(hash)}`;
|
|
243
|
+
}
|
|
244
|
+
|
|
207
245
|
/**
|
|
208
246
|
* 将当前 v2 页面地址转换为根相对 redirect 路径。
|
|
209
247
|
*
|
package/src/components/README.md
CHANGED
|
@@ -190,6 +190,10 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
190
190
|
<Form.Item name={['options', 'secure']} label={t('Secure')} initialValue={true}>
|
|
191
191
|
<TypedVariableInput types={['boolean']} namespaces={['$env']} />
|
|
192
192
|
</Form.Item>
|
|
193
|
+
|
|
194
|
+
// Inject a custom variable tree (e.g. a workflow node's upstream outputs,
|
|
195
|
+
// which are not in the global registry)
|
|
196
|
+
<TypedVariableInput types={['string', 'number']} metaTree={workflowMetaTree} />
|
|
193
197
|
```
|
|
194
198
|
|
|
195
199
|
Key props:
|
|
@@ -197,6 +201,7 @@ Key props:
|
|
|
197
201
|
- `types`: allowed constant types. Shape mirrors v1 `useTypedConstant` — pass bare type names (`['number', 'boolean']`) or `[type, editorProps]` tuples (`[['number', { min, max, step }]]`) to forward props to the underlying antd editor. Defaults to `['string', 'number', 'boolean', 'date']`. **Even when only one type is allowed, the `Constant` entry still expands into a typed submenu** (Number / Boolean / Date / String) — matches v1 so users can see what type the constant is
|
|
198
202
|
- `namespaces`: restrict the variable picker to specific top-level namespaces (e.g. `['$env']`). Omit to expose every namespace registered on `flowEngine.context`
|
|
199
203
|
- `extraNodes`: static leaves appended after the namespace-filtered nodes
|
|
204
|
+
- `metaTree`: **inject the variable tree directly** instead of reading the global `flowEngine.context` meta tree. When set, `namespaces`/`extraNodes` are ignored and this tree is used verbatim — for context-scoped variable sources that are not in the global registry (typically a workflow node's upstream outputs, `$jobsMapByNodeKey`). Nodes whose `children` is a thunk (`() => Promise<MetaTreeNode[]>`) are **lazy-loaded on expand** (via flow-engine's `loadMetaTreeChildren`)
|
|
200
205
|
- `nullable`: whether to expose the `Null` switcher entry. Default `true`. Combined with `Form.Item.rules={[{ required: true }]}`, the user can explicitly clear the field but submission is still blocked by validation — mirrors v1's "Null + required" pairing
|
|
201
206
|
- `delimiters`: variable-token delimiters, default `['{{', '}}']` — same as `VariableInput`
|
|
202
207
|
- `value` / `onChange` / `placeholder` / `disabled` / `style` / `className`: standard controlled-input props
|
|
@@ -212,9 +217,10 @@ When **not** to use it:
|
|
|
212
217
|
- **Pure literal fields** (users will never pass a variable) → use the antd primitive directly (`InputNumber` / `Select` / `DatePicker` / `Input`) and skip the Cascader column overhead
|
|
213
218
|
- **Pure variable fields** (users will never pass a literal) → use `EnvVariableInput` (`$env`-only, with optional password masking) or `VariableInput` (general-purpose)
|
|
214
219
|
|
|
220
|
+
Supported constant types: `string` / `number` / `boolean` / `date` / `object`. The `object` (JSON) type renders an inline monospace textarea (2 rows by default, drag-resizable) — it keeps the raw text as a draft while editing and `JSON.parse`s it back into an object on blur. On a parse failure it shows the raw `JSON.parse` message (e.g. `Expected property name or '}' in JSON at position …`, matching v1) on its own row below the input, and does not emit. Mirrors v1 `useTypedConstant`'s object form (default value `{}`).
|
|
221
|
+
|
|
215
222
|
Capabilities skipped (present in v1, not yet ported to v2):
|
|
216
223
|
|
|
217
|
-
- `object` constant type (JSON editor) — v2 has no inline "JSON editor + Cascader switcher" yet; add when there's a concrete caller
|
|
218
224
|
- Async `loadChildren` cascading — most MetaTree namespaces are already eagerly resolved by `useFilteredMetaTree`, so this hasn't been needed
|
|
219
225
|
|
|
220
226
|
#### FileSizeInput
|
|
@@ -190,6 +190,9 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
190
190
|
<Form.Item name={['options', 'secure']} label={t('安全模式')} initialValue={true}>
|
|
191
191
|
<TypedVariableInput types={['boolean']} namespaces={['$env']} />
|
|
192
192
|
</Form.Item>
|
|
193
|
+
|
|
194
|
+
// 注入自定义变量树(如工作流节点的上游输出,不在全局注册表里)
|
|
195
|
+
<TypedVariableInput types={['string', 'number']} metaTree={workflowMetaTree} />
|
|
193
196
|
```
|
|
194
197
|
|
|
195
198
|
主要属性:
|
|
@@ -197,6 +200,7 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
197
200
|
- `types`:允许的常量类型。形态对齐 v1 `useTypedConstant`,可以传裸类型名 `['number', 'boolean']`,也可以传 `[type, editorProps]` 元组 `[['number', { min, max, step }]]` 把 props 透传给底层 antd 编辑器。默认 `['string', 'number', 'boolean', 'date']`。**即使只允许一种类型,「常量」入口也会展开二级菜单**(数字 / 逻辑值 / 日期 / 字符串)——跟 v1 一致,让用户能直观看到当前常量是什么类型
|
|
198
201
|
- `namespaces`:限定变量 picker 可选的顶层命名空间(如 `['$env']`)。不传就用 `flowEngine.context` 里所有已注册命名空间
|
|
199
202
|
- `extraNodes`:在命名空间过滤后追加几条静态变量节点
|
|
203
|
+
- `metaTree`:**直接注入变量树**,取代读取全局 `flowEngine.context` 的 MetaTree。传了它就**忽略** `namespaces`/`extraNodes`,原样使用这棵树——用于不在全局注册表里的、上下文相关的变量源(典型如工作流节点的上游节点输出 `$jobsMapByNodeKey`)。树里 `children` 为函数(`() => Promise<MetaTreeNode[]>`)的节点会在用户展开 Cascader 时**按需懒加载**(复用 flow-engine 的 `loadMetaTreeChildren`)
|
|
200
204
|
- `nullable`:是否暴露「空值」入口,默认 `true`。配合 `Form.Item.rules={[{ required: true }]}` 可以让用户能手动清空、但提交时会被校验拦截——跟 v1 的「空值 + required」组合一致
|
|
201
205
|
- `delimiters`:变量 token 开闭分隔符,默认 `['{{', '}}']`,跟 `VariableInput` 一致
|
|
202
206
|
- `value` / `onChange` / `placeholder` / `disabled` / `style` / `className`:标准受控字段属性
|
|
@@ -212,9 +216,10 @@ import { TypedVariableInput } from '@nocobase/client-v2';
|
|
|
212
216
|
- **纯字面量字段**(用户不会想填变量)→ 直接用 antd `InputNumber` / `Select` / `DatePicker` / `Input`,省掉 Cascader 那一格的视觉开销
|
|
213
217
|
- **纯变量字段**(用户不会想填字面量)→ 用 `EnvVariableInput`(`$env` 专用,带 password mask)或 `VariableInput`(更通用)
|
|
214
218
|
|
|
219
|
+
支持的常量类型:`string` / `number` / `boolean` / `date` / `object`。其中 `object`(即 JSON)渲染为一个等宽字体的内联 textarea(默认两行、可拖拽拉伸),编辑时保留原始文本草稿、失焦(blur)时 `JSON.parse` 回写为对象;解析失败则在输入框**下方单独一行**显示原生 `JSON.parse` 的错误信息(如 `Expected property name or '}' in JSON at position …`,对齐 v1)且不回写。对齐 v1 `useTypedConstant` 的 object 形态(默认值 `{}`)。
|
|
220
|
+
|
|
215
221
|
跳过的能力(v1 有但 v2 还没补):
|
|
216
222
|
|
|
217
|
-
- `object` 类型(JSON 编辑器)——v2 还没对应的「内联 JSON 编辑器 + Cascader 切换」组件,等真有需求再补
|
|
218
223
|
- 异步 `loadChildren` 分支——大多数命名空间的 MetaTree 已经由 `useFilteredMetaTree` 提前展平,没遇到刚需
|
|
219
224
|
|
|
220
225
|
#### FileSizeInput
|
|
@@ -0,0 +1,210 @@
|
|
|
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 { MenuOutlined } from '@ant-design/icons';
|
|
11
|
+
import {
|
|
12
|
+
DndContext,
|
|
13
|
+
DragOverlay,
|
|
14
|
+
MouseSensor,
|
|
15
|
+
useDraggable,
|
|
16
|
+
useDroppable,
|
|
17
|
+
useSensor,
|
|
18
|
+
useSensors,
|
|
19
|
+
type DragEndEvent,
|
|
20
|
+
type DragStartEvent,
|
|
21
|
+
} from '@dnd-kit/core';
|
|
22
|
+
import { Badge, Button, Dropdown, Space, Tabs } from 'antd';
|
|
23
|
+
import type { TabsProps } from 'antd';
|
|
24
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A category descriptor for {@link SortableCategoryTabs}. The component is
|
|
28
|
+
* i18n-agnostic: `label` is rendered verbatim, so consumers pass an
|
|
29
|
+
* already-compiled/translated node. `color` is an antd preset color name or a
|
|
30
|
+
* hex string; `'default'` / `undefined` renders no badge color.
|
|
31
|
+
*/
|
|
32
|
+
export type SortableCategoryTabItem = {
|
|
33
|
+
id: string | number;
|
|
34
|
+
label: React.ReactNode;
|
|
35
|
+
color?: string;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export type SortableCategoryTabsProps = {
|
|
39
|
+
activeKey: string;
|
|
40
|
+
onChange: (key: string) => void;
|
|
41
|
+
/** Draggable category tabs (the fixed leading tab is configured via `allTab`). */
|
|
42
|
+
categories: SortableCategoryTabItem[];
|
|
43
|
+
/** The fixed, non-draggable leading tab, e.g. "All". */
|
|
44
|
+
allTab: { key: string; label: React.ReactNode };
|
|
45
|
+
/** Show the "+" add button and handle its click. */
|
|
46
|
+
onAdd?: () => void;
|
|
47
|
+
/** Per-category edit menu item handler; menu is hidden when omitted. */
|
|
48
|
+
onEdit?: (id: string | number) => void;
|
|
49
|
+
/** Per-category delete menu item handler; menu is hidden when omitted. */
|
|
50
|
+
onDelete?: (id: string | number) => void;
|
|
51
|
+
/** Reorder handler. Receives the dragged and dropped category ids. */
|
|
52
|
+
onSort?: (sourceId: string | number, targetId: string | number) => void | Promise<void>;
|
|
53
|
+
/** Consumer-translated labels for the per-category dropdown menu. */
|
|
54
|
+
menuLabels?: { edit?: string; delete?: string };
|
|
55
|
+
className?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function DraggableTab(props: { id: string; children: React.ReactNode }) {
|
|
59
|
+
const { attributes, listeners, setNodeRef } = useDraggable({ id: props.id });
|
|
60
|
+
return (
|
|
61
|
+
<div ref={setNodeRef} {...listeners} {...attributes}>
|
|
62
|
+
{props.children}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function DroppableTab(props: { id: string; children: React.ReactNode }) {
|
|
68
|
+
const { isOver, setNodeRef } = useDroppable({ id: props.id });
|
|
69
|
+
return (
|
|
70
|
+
<div ref={setNodeRef} style={isOver ? { color: 'green' } : undefined}>
|
|
71
|
+
{props.children}
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function CategoryTabContent(props: {
|
|
77
|
+
item: SortableCategoryTabItem;
|
|
78
|
+
onEdit?: (id: string | number) => void;
|
|
79
|
+
onDelete?: (id: string | number) => void;
|
|
80
|
+
menuLabels?: { edit?: string; delete?: string };
|
|
81
|
+
}) {
|
|
82
|
+
const { item, onEdit, onDelete, menuLabels } = props;
|
|
83
|
+
const hasMenu = Boolean(onEdit || onDelete);
|
|
84
|
+
const editLabel = menuLabels?.edit ?? 'Edit';
|
|
85
|
+
const deleteLabel = menuLabels?.delete ?? 'Delete';
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Space size={6}>
|
|
89
|
+
<Badge color={item.color === 'default' ? undefined : item.color} />
|
|
90
|
+
{item.label}
|
|
91
|
+
{hasMenu ? (
|
|
92
|
+
<Dropdown
|
|
93
|
+
trigger={['click']}
|
|
94
|
+
menu={{
|
|
95
|
+
items: [
|
|
96
|
+
onEdit ? { key: 'edit', label: editLabel } : null,
|
|
97
|
+
onDelete ? { key: 'delete', label: deleteLabel } : null,
|
|
98
|
+
].filter(Boolean) as { key: string; label: string }[],
|
|
99
|
+
onClick({ key, domEvent }) {
|
|
100
|
+
domEvent.stopPropagation();
|
|
101
|
+
if (key === 'edit') {
|
|
102
|
+
onEdit?.(item.id);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
onDelete?.(item.id);
|
|
106
|
+
},
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
109
|
+
<Button
|
|
110
|
+
aria-label={editLabel}
|
|
111
|
+
icon={<MenuOutlined />}
|
|
112
|
+
size="small"
|
|
113
|
+
type="text"
|
|
114
|
+
onClick={(event) => event.stopPropagation()}
|
|
115
|
+
/>
|
|
116
|
+
</Dropdown>
|
|
117
|
+
) : null}
|
|
118
|
+
</Space>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A draggable, editable category tab bar. Renders only the tab bar (no content
|
|
124
|
+
* panes) — the page renders its content below and reacts to `activeKey`.
|
|
125
|
+
*
|
|
126
|
+
* Shared by settings pages that group records under reorderable categories
|
|
127
|
+
* (data-source collections, workflows, …). Drag-to-reorder is powered by
|
|
128
|
+
* `@dnd-kit`; the "+" / per-tab edit-delete affordances are optional.
|
|
129
|
+
*/
|
|
130
|
+
export function SortableCategoryTabs(props: SortableCategoryTabsProps) {
|
|
131
|
+
const { activeKey, onChange, categories, allTab, onAdd, onEdit, onDelete, onSort, menuLabels, className } = props;
|
|
132
|
+
const [activeDragId, setActiveDragId] = useState<string | null>(null);
|
|
133
|
+
const sensors = useSensors(useSensor(MouseSensor, { activationConstraint: { distance: 10 } }));
|
|
134
|
+
|
|
135
|
+
const handleDragStart = useCallback((event: DragStartEvent) => {
|
|
136
|
+
setActiveDragId(String(event.active.id));
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
const handleDragEnd = useCallback(
|
|
140
|
+
async (event: DragEndEvent) => {
|
|
141
|
+
const { active, over } = event;
|
|
142
|
+
setActiveDragId(null);
|
|
143
|
+
if (!over || over.id === active.id) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
await onSort?.(active.id as string | number, over.id as string | number);
|
|
147
|
+
},
|
|
148
|
+
[onSort],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const items = useMemo<TabsProps['items']>(
|
|
152
|
+
() => [
|
|
153
|
+
{ key: allTab.key, label: allTab.label, closable: false },
|
|
154
|
+
...categories.map((item) => ({
|
|
155
|
+
key: String(item.id),
|
|
156
|
+
closable: false,
|
|
157
|
+
label: onSort ? (
|
|
158
|
+
<DroppableTab id={String(item.id)}>
|
|
159
|
+
<DraggableTab id={String(item.id)}>
|
|
160
|
+
<CategoryTabContent item={item} onEdit={onEdit} onDelete={onDelete} menuLabels={menuLabels} />
|
|
161
|
+
</DraggableTab>
|
|
162
|
+
</DroppableTab>
|
|
163
|
+
) : (
|
|
164
|
+
<CategoryTabContent item={item} onEdit={onEdit} onDelete={onDelete} menuLabels={menuLabels} />
|
|
165
|
+
),
|
|
166
|
+
})),
|
|
167
|
+
],
|
|
168
|
+
[allTab.key, allTab.label, categories, onSort, onEdit, onDelete, menuLabels],
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const activeDragItem = useMemo(
|
|
172
|
+
() => categories.find((item) => String(item.id) === activeDragId),
|
|
173
|
+
[categories, activeDragId],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const tabs = (
|
|
177
|
+
<Tabs
|
|
178
|
+
className={className}
|
|
179
|
+
activeKey={activeKey}
|
|
180
|
+
type="editable-card"
|
|
181
|
+
hideAdd={!onAdd}
|
|
182
|
+
items={items}
|
|
183
|
+
onChange={onChange}
|
|
184
|
+
onEdit={(_, action) => {
|
|
185
|
+
if (action === 'add') {
|
|
186
|
+
onAdd?.();
|
|
187
|
+
}
|
|
188
|
+
}}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
if (!onSort) {
|
|
193
|
+
return tabs;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<DndContext sensors={sensors} onDragStart={handleDragStart} onDragEnd={handleDragEnd}>
|
|
198
|
+
{tabs}
|
|
199
|
+
<DragOverlay dropAnimation={null}>
|
|
200
|
+
{activeDragItem ? (
|
|
201
|
+
<span style={{ whiteSpace: 'nowrap' }}>
|
|
202
|
+
<CategoryTabContent item={activeDragItem} menuLabels={menuLabels} />
|
|
203
|
+
</span>
|
|
204
|
+
) : null}
|
|
205
|
+
</DragOverlay>
|
|
206
|
+
</DndContext>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default SortableCategoryTabs;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export * from './SortableCategoryTabs';
|