@nocobase/client-v2 2.3.0-alpha.1 → 2.3.0-beta.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 +12 -0
- package/es/components/form/ScanInput/useCodeScanner.d.ts +12 -2
- package/es/components/form/ScanInput/zxingWasmDecoder.d.ts +9 -0
- package/es/flow/actions/linkageRules.d.ts +25 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +6 -30
- package/es/flow/components/FlowRoute.d.ts +2 -2
- package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
- package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +32 -0
- package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
- package/es/flow/components/field-value-variable/index.d.ts +11 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +7 -0
- package/es/flow/components/placeholders/BlockPlaceholder.d.ts +1 -0
- package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
- package/es/flow/internal/utils/operatorSchemaHelper.d.ts +2 -2
- package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
- package/es/flow/models/base/ActionModelCore.d.ts +4 -2
- package/es/flow/models/base/BlockGridModel.d.ts +3 -0
- package/es/flow/models/base/CollectionBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/details/DetailsBlockModel.d.ts +3 -0
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
- package/es/flow/models/blocks/filter-form/FilterFormSubmitActionModel.d.ts +3 -1
- package/es/flow/models/blocks/form/FormBlockModel.d.ts +7 -0
- package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
- package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
- package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
- package/es/flow/models/blocks/table/TableBlockModel.d.ts +1 -0
- package/es/flow/models/blocks/table/TableColumnModel.d.ts +12 -0
- package/es/flow/models/blocks/table/utils.d.ts +1 -0
- package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +2 -1
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +0 -17
- package/es/flow/models/fields/AssociationFieldModel/recordSelectShared.d.ts +41 -0
- package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
- package/es/flow-compat/passwordUtils.d.ts +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.mjs +148 -145
- package/es/ui-operation/index.d.ts +15 -0
- package/es/ui-operation/ui-operation-codec.d.ts +10 -0
- package/lib/index.js +170 -167
- package/lib/locale/languageCodes.js +1 -0
- package/package.json +10 -8
- package/src/APIClient.ts +92 -0
- package/src/Application.tsx +3 -1
- package/src/__tests__/APIClient.test.tsx +58 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +7 -2
- package/src/__tests__/settings-center.test.tsx +270 -6
- package/src/acl/ACLProvider.tsx +2 -0
- package/src/acl/__tests__/ACLProvider.test.tsx +92 -0
- package/src/collection-manager/__tests__/field-configure.test.ts +52 -0
- package/src/collection-manager/field-configure.ts +2 -2
- package/src/components/form/ScanInput/CodeScanner.tsx +64 -35
- package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +107 -0
- package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +294 -24
- package/src/components/form/ScanInput/__tests__/zxingWasmDecoder.test.ts +78 -0
- package/src/components/form/ScanInput/useCodeScanner.ts +281 -23
- package/src/components/form/ScanInput/zxingWasmDecoder.ts +64 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +4 -2
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +17 -0
- package/src/components/form/table/Table.tsx +81 -6
- package/src/components/form/table/__tests__/Table.columnWidth.test.tsx +433 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +126 -8
- package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
- package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
- package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
- package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
- package/src/flow/actions/__tests__/linkageRules.subFormSetFieldProps.test.ts +72 -0
- package/src/flow/actions/linkageRules.tsx +59 -16
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +78 -59
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +228 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +42 -23
- package/src/flow/common/Markdown/style.ts +4 -0
- package/src/flow/components/BlockItemCard.tsx +2 -2
- package/src/flow/components/FieldAssignValueInput.tsx +42 -621
- package/src/flow/components/FlowRoute.tsx +71 -29
- package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
- package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +335 -0
- package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +389 -0
- package/src/flow/components/field-value-variable/dateValue.ts +223 -0
- package/src/flow/components/field-value-variable/index.ts +12 -0
- package/src/flow/components/filter/VariableFilterItem.tsx +23 -6
- package/src/flow/components/filter/__tests__/VariableFilterItem.rightMetaTree.test.tsx +158 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +125 -0
- package/src/flow/components/placeholders/BlockPlaceholder.tsx +70 -23
- package/src/flow/components/placeholders/__tests__/BlockPlaceholder.test.tsx +57 -7
- package/src/flow/index.ts +2 -0
- package/src/flow/internal/components/Markdown/DisplayMarkdown.tsx +14 -9
- package/src/flow/internal/components/Markdown/__tests__/DisplayMarkdown.test.tsx +46 -0
- package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
- package/src/flow/internal/utils/operatorSchemaHelper.ts +3 -2
- package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
- package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
- package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
- package/src/flow/models/base/ActionModelCore.tsx +11 -2
- package/src/flow/models/base/BlockGridModel.tsx +26 -0
- package/src/flow/models/base/CollectionBlockModel.tsx +38 -3
- package/src/flow/models/base/GridModel.tsx +0 -1
- package/src/flow/models/base/PageModel/PageTabModel.tsx +67 -17
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +509 -12
- package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
- package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
- package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +125 -9
- package/src/flow/models/blocks/assign-form/AssignFormGridModel.tsx +22 -1
- package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +36 -50
- package/src/flow/models/blocks/assign-form/__tests__/assignFieldValuesFlow.editor.test.tsx +140 -0
- package/src/flow/models/blocks/details/DetailsBlockModel.tsx +8 -3
- package/src/flow/models/blocks/details/__tests__/DetailsBlockModel.initialPaginationChangeRefresh.test.ts +32 -1
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +27 -3
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +36 -5
- package/src/flow/models/blocks/filter-form/FilterFormItemModel.tsx +129 -14
- package/src/flow/models/blocks/filter-form/FilterFormSubmitActionModel.tsx +57 -4
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.onModelCreated.test.ts +174 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +29 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.defineChildren.test.ts +359 -1
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormItemModel.getFilterValue.test.ts +72 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormSubmitActionModel.lifecycle.test.ts +90 -0
- package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +32 -4
- package/src/flow/models/blocks/filter-form/fields/FieldComponentProps.tsx +1 -1
- package/src/flow/models/blocks/filter-form/fields/__tests__/FieldComponentProps.options.test.tsx +61 -0
- package/src/flow/models/blocks/filter-manager/FilterManager.ts +5 -0
- package/src/flow/models/blocks/filter-manager/__tests__/FilterManager.test.ts +40 -0
- package/src/flow/models/blocks/form/FormBlockModel.tsx +73 -5
- package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +153 -2
- package/src/flow/models/blocks/form/__tests__/popupLinkage.test.tsx +175 -0
- package/src/flow/models/blocks/form/__tests__/runJsFormSubmit.test.ts +131 -0
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
- package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
- package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +28 -2
- package/src/flow/models/blocks/table/TableColumnModel.tsx +48 -9
- package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.filterReset.test.ts +78 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -0
- package/src/flow/models/blocks/table/utils.ts +7 -0
- package/src/flow/models/fields/AssociationFieldModel/CascadeSelectFieldModel.tsx +33 -1
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +8 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
- package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
- package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +29 -3
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +9 -136
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +191 -3
- package/src/flow/models/fields/AssociationFieldModel/recordSelectShared.tsx +156 -0
- package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
- package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
- package/src/flow/models/fields/DisplayAssociationField/DisplaySubTableFieldModel.tsx +42 -7
- package/src/flow/models/fields/DisplayAssociationField/__tests__/DisplaySubTableFieldModel.test.tsx +351 -0
- package/src/flow/models/fields/DisplayHtmlFieldModel.tsx +2 -1
- package/src/flow/models/fields/DisplayNumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
- package/src/flow/models/fields/NumberFieldModel.tsx +1 -1
- package/src/flow/models/fields/RichTextFieldModel/__tests__/RichTextFieldModel.test.tsx +74 -0
- package/src/flow/models/fields/RichTextFieldModel/index.tsx +27 -6
- package/src/flow/models/fields/__tests__/DisplayNumberFieldModel.test.ts +33 -0
- package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
- package/src/flow/models/fields/__tests__/NumberFieldModel.test.tsx +47 -0
- package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +6 -0
- package/src/flow/models/fields/mobile-components/MobileSelect.tsx +27 -2
- package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +139 -13
- package/src/flow/models/topbar/TopbarActionModel.tsx +5 -5
- package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
- package/src/index.ts +1 -0
- package/src/layout-manager/LayoutContentRoute.tsx +2 -1
- package/src/layout-manager/LayoutRoute.tsx +2 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
- package/src/locale/languageCodes.ts +1 -0
- package/src/settings-center/AdminSettingsLayout.tsx +23 -2
- package/src/ui-operation/index.ts +33 -0
- package/src/ui-operation/ui-operation-codec.ts +54 -0
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { FlowEngine, FlowEngineProvider, observer } from '@nocobase/flow-engine';
|
|
11
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
11
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import { createMemoryRouter, Outlet, RouterProvider, useOutlet } from 'react-router-dom';
|
|
14
14
|
import { describe, expect, it, vi } from 'vitest';
|
|
@@ -106,6 +106,64 @@ describe('LayoutRoute', () => {
|
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
it('syncs updated router state when navigating to the same layout pathname', async () => {
|
|
110
|
+
const syncLayoutRoute = vi.fn();
|
|
111
|
+
|
|
112
|
+
class StateTrackingLayoutModel extends TestLayoutModel {
|
|
113
|
+
syncLayoutRoute(routeLike: Parameters<BaseLayoutModel['syncLayoutRoute']>[0]) {
|
|
114
|
+
syncLayoutRoute(routeLike);
|
|
115
|
+
return super.syncLayoutRoute(routeLike);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const stateTrackingLayout: LayoutDefinition = {
|
|
120
|
+
...layout,
|
|
121
|
+
layoutModelClass: 'StateTrackingLayoutModel',
|
|
122
|
+
};
|
|
123
|
+
const engine = new FlowEngine();
|
|
124
|
+
engine.registerModels({ StateTrackingLayoutModel });
|
|
125
|
+
engine.context.defineProperty('app', {
|
|
126
|
+
value: {
|
|
127
|
+
layoutManager: {
|
|
128
|
+
getLayout: () => stateTrackingLayout,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const router = createMemoryRouter(
|
|
134
|
+
[
|
|
135
|
+
{
|
|
136
|
+
id: layout.routeName,
|
|
137
|
+
path: layout.routePath,
|
|
138
|
+
element: <LayoutRoute layoutRouteName="test" />,
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
{
|
|
142
|
+
initialEntries: ['/test'],
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
render(
|
|
147
|
+
<FlowEngineProvider engine={engine}>
|
|
148
|
+
<RouterProvider router={router} />
|
|
149
|
+
</FlowEngineProvider>,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(await screen.findByTestId('layout-route')).toHaveTextContent('test');
|
|
153
|
+
syncLayoutRoute.mockClear();
|
|
154
|
+
|
|
155
|
+
const routeState = {
|
|
156
|
+
__nocobaseOpenViewInputArgs: { popup: { formData: { status: 'todo' } } },
|
|
157
|
+
};
|
|
158
|
+
await act(async () => {
|
|
159
|
+
await router.navigate('/test', { state: routeState });
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
await waitFor(() => {
|
|
163
|
+
expect(syncLayoutRoute).toHaveBeenCalledWith(expect.objectContaining({ state: routeState }));
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
109
167
|
it('does not activate desktop route loading for generic layouts', async () => {
|
|
110
168
|
const activateLayout = vi.fn(() => vi.fn());
|
|
111
169
|
const engine = new FlowEngine();
|
|
@@ -413,6 +471,34 @@ describe('LayoutContentRoute', () => {
|
|
|
413
471
|
});
|
|
414
472
|
});
|
|
415
473
|
|
|
474
|
+
it('syncs updated router state when navigating to the same content pathname', async () => {
|
|
475
|
+
const syncLayoutRoute = vi.fn();
|
|
476
|
+
|
|
477
|
+
class StateTrackingLayoutModel extends TestLayoutModel {
|
|
478
|
+
syncLayoutRoute(routeLike: Parameters<BaseLayoutModel['syncLayoutRoute']>[0]) {
|
|
479
|
+
syncLayoutRoute(routeLike);
|
|
480
|
+
return super.syncLayoutRoute(routeLike);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const { router } = setup('/test/page-1/view/popup', layout, StateTrackingLayoutModel);
|
|
485
|
+
await waitFor(() => {
|
|
486
|
+
expect(syncLayoutRoute).toHaveBeenCalled();
|
|
487
|
+
});
|
|
488
|
+
syncLayoutRoute.mockClear();
|
|
489
|
+
|
|
490
|
+
const routeState = {
|
|
491
|
+
__nocobaseOpenViewInputArgs: { popup: { formData: { status: 'todo' } } },
|
|
492
|
+
};
|
|
493
|
+
await act(async () => {
|
|
494
|
+
await router.navigate('/test/page-1/view/popup', { state: routeState });
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
await waitFor(() => {
|
|
498
|
+
expect(syncLayoutRoute).toHaveBeenCalledWith(expect.objectContaining({ state: routeState }));
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
|
|
416
502
|
it('parses nested layout route by matched layout pathname', async () => {
|
|
417
503
|
const nestedLayout: LayoutDefinition = {
|
|
418
504
|
...layout,
|
|
@@ -54,6 +54,7 @@ export const languageCodes: Record<string, LocaleOptions> = {
|
|
|
54
54
|
'ml-IN': { label: 'മലയാളം' },
|
|
55
55
|
'mn-MN': { label: 'Монгол хэл' },
|
|
56
56
|
'ms-MY': { label: 'بهاس ملايو' },
|
|
57
|
+
'my-MM': { label: 'မြန်မာဘာသာ' },
|
|
57
58
|
'nb-NO': { label: 'Norsk bokmål' },
|
|
58
59
|
'ne-NP': { label: 'नेपाली' },
|
|
59
60
|
'nl-BE': { label: 'Vlaams' },
|
|
@@ -14,7 +14,7 @@ import { FlowModelRenderer, useFlowEngine } from '@nocobase/flow-engine';
|
|
|
14
14
|
import { Layout, Menu, Result, theme } from 'antd';
|
|
15
15
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
16
16
|
import { useTranslation } from 'react-i18next';
|
|
17
|
-
import { Navigate, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
17
|
+
import { generatePath, Navigate, Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
18
18
|
import { useACLRoleContext } from '../acl';
|
|
19
19
|
import { ADMIN_SETTINGS_PATH, type PluginSettingsPageType } from '../PluginSettingsManager';
|
|
20
20
|
import { useApp } from '../hooks/useApp';
|
|
@@ -68,6 +68,9 @@ export const InternalAdminSettingsLayout = () => {
|
|
|
68
68
|
const navigate = useNavigate();
|
|
69
69
|
const location = useLocation();
|
|
70
70
|
const params = useParams();
|
|
71
|
+
const routeParams = Object.fromEntries(
|
|
72
|
+
Object.entries(params).filter((entry): entry is [string, string] => typeof entry[1] === 'string'),
|
|
73
|
+
);
|
|
71
74
|
const { token } = theme.useToken();
|
|
72
75
|
const { t } = useTranslation();
|
|
73
76
|
const { snippets = [] } = useACLRoleContext();
|
|
@@ -174,7 +177,25 @@ export const InternalAdminSettingsLayout = () => {
|
|
|
174
177
|
return <SettingsEmpty type="route" />;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
if (
|
|
180
|
+
if (currentSetting.isAllow === false) {
|
|
181
|
+
const firstVisibleTabPath = currentVisibleTabs
|
|
182
|
+
.map((tab) => getDefaultSettingsPath([tab]))
|
|
183
|
+
.filter((path): path is string => typeof path === 'string')
|
|
184
|
+
.map((path) => {
|
|
185
|
+
try {
|
|
186
|
+
return generatePath(path, routeParams);
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
.find((path): path is string => typeof path === 'string');
|
|
192
|
+
if (firstVisibleTabPath) {
|
|
193
|
+
return <Navigate replace to={firstVisibleTabPath} />;
|
|
194
|
+
}
|
|
195
|
+
if (!defaultSettingsPath) {
|
|
196
|
+
return <Navigate replace to="/admin" />;
|
|
197
|
+
}
|
|
198
|
+
|
|
178
199
|
return <SettingsEmpty type="route" />;
|
|
179
200
|
}
|
|
180
201
|
|
|
@@ -0,0 +1,33 @@
|
|
|
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 {
|
|
11
|
+
decodeUIOperation as decode,
|
|
12
|
+
encodeUIOperation as encode,
|
|
13
|
+
parseUIOperation as parse,
|
|
14
|
+
removeUIOperation,
|
|
15
|
+
UI_OPERATION_QUERY_KEY,
|
|
16
|
+
type UIOperation,
|
|
17
|
+
} from '@nocobase/shared';
|
|
18
|
+
import { browserUIOperationCodec } from './ui-operation-codec';
|
|
19
|
+
|
|
20
|
+
export function parseUIOperation(search: string): UIOperation | undefined {
|
|
21
|
+
return parse(search, browserUIOperationCodec);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function decodeUIOperation(encoded: string): UIOperation | undefined {
|
|
25
|
+
return decode(encoded, browserUIOperationCodec);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function encodeUIOperation(operation: UIOperation): string {
|
|
29
|
+
return encode(operation, browserUIOperationCodec);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { browserUIOperationCodec, removeUIOperation, UI_OPERATION_QUERY_KEY };
|
|
33
|
+
export type { UIOperation };
|
|
@@ -0,0 +1,54 @@
|
|
|
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 type { UIOperationCodec } from '@nocobase/shared';
|
|
11
|
+
|
|
12
|
+
const base64UrlPattern = /^[A-Za-z0-9_-]*$/;
|
|
13
|
+
const utf8Encoder = new TextEncoder();
|
|
14
|
+
const utf8Decoder = new TextDecoder('utf-8', { fatal: true });
|
|
15
|
+
|
|
16
|
+
function bytesToBinaryString(bytes: Uint8Array): string {
|
|
17
|
+
let result = '';
|
|
18
|
+
for (const byte of bytes) {
|
|
19
|
+
result += String.fromCharCode(byte);
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function binaryStringToBytes(value: string): Uint8Array {
|
|
25
|
+
const bytes = new Uint8Array(value.length);
|
|
26
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
27
|
+
bytes[index] = value.charCodeAt(index);
|
|
28
|
+
}
|
|
29
|
+
return bytes;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function encodeBrowserUIOperation(value: string): string {
|
|
33
|
+
return btoa(bytesToBinaryString(utf8Encoder.encode(value)))
|
|
34
|
+
.replace(/\+/g, '-')
|
|
35
|
+
.replace(/\//g, '_')
|
|
36
|
+
.replace(/=+$/, '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const browserUIOperationCodec: UIOperationCodec = {
|
|
40
|
+
encode: encodeBrowserUIOperation,
|
|
41
|
+
decode(value) {
|
|
42
|
+
if (!base64UrlPattern.test(value) || value.length % 4 === 1) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const paddedValue = `${value.replace(/-/g, '+').replace(/_/g, '/')}${'='.repeat((4 - (value.length % 4)) % 4)}`;
|
|
48
|
+
const decoded = utf8Decoder.decode(binaryStringToBytes(atob(paddedValue)));
|
|
49
|
+
return encodeBrowserUIOperation(decoded) === value ? decoded : undefined;
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|