@nocobase/client-v2 2.2.0-alpha.3 → 2.2.0-alpha.4
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/RouteRepository.d.ts +8 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/form/TypedVariableInput.d.ts +9 -1
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/index.d.ts +2 -0
- package/es/index.mjs +146 -114
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +147 -115
- package/package.json +7 -7
- package/src/RouteRepository.ts +25 -0
- package/src/__tests__/RouteRepository.test.ts +23 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/authRedirect.ts +38 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +58 -34
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +52 -0
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/flow/actions/dateTimeFormat.tsx +2 -2
- package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
- package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
- package/src/index.ts +2 -0
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -0,0 +1,185 @@
|
|
|
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 type RouteRuntimeVersion = 'legacy' | 'modern';
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
__nocobase_modern_client_prefix__?: string;
|
|
15
|
+
__nocobase_public_path__?: string;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hasModernClientPrefix() {
|
|
20
|
+
return (
|
|
21
|
+
typeof window !== 'undefined' &&
|
|
22
|
+
typeof window.__nocobase_modern_client_prefix__ === 'string' &&
|
|
23
|
+
window.__nocobase_modern_client_prefix__.trim().length > 0
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function hasConfiguredPublicPath() {
|
|
28
|
+
return typeof window !== 'undefined' && typeof window.__nocobase_public_path__ === 'string';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Normalize any app/public-path-like input into a root-relative pathname:
|
|
32
|
+
*
|
|
33
|
+
* - `nocobase//v/` -> `/nocobase/v`
|
|
34
|
+
* - `/` -> `/`
|
|
35
|
+
*/
|
|
36
|
+
function normalizeRootRelativePath(value = '/') {
|
|
37
|
+
const normalized = `/${String(value || '/').trim() || '/'}`.replace(/\/{2,}/g, '/');
|
|
38
|
+
if (normalized !== '/' && normalized.endsWith('/')) {
|
|
39
|
+
return normalized.replace(/\/+$/g, '');
|
|
40
|
+
}
|
|
41
|
+
return normalized;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Public-path form always ends with `/`, so it can be compared as a base path:
|
|
45
|
+
*
|
|
46
|
+
* - `/nocobase/v` -> `/nocobase/v/`
|
|
47
|
+
* - `/` -> `/`
|
|
48
|
+
*/
|
|
49
|
+
function normalizePublicPath(value = '/') {
|
|
50
|
+
const normalized = normalizeRootRelativePath(value);
|
|
51
|
+
return normalized.endsWith('/') ? normalized : `${normalized}/`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Check whether a concrete pathname is rendered under a runtime base path:
|
|
55
|
+
*
|
|
56
|
+
* - pathname `/nocobase/v/admin/workflow/workflows/1`
|
|
57
|
+
* basePath `/nocobase/v/`
|
|
58
|
+
* => true
|
|
59
|
+
*
|
|
60
|
+
* - pathname `/nocobase/admin/settings/workflow/workflows/1`
|
|
61
|
+
* basePath `/nocobase/v/`
|
|
62
|
+
* => false
|
|
63
|
+
*/
|
|
64
|
+
function isPathnameInsideBasePath(pathname: string, basePath: string) {
|
|
65
|
+
const normalizedPathname = normalizeRootRelativePath(pathname);
|
|
66
|
+
const normalizedBasePath = normalizePublicPath(basePath);
|
|
67
|
+
const trimmedBasePath = normalizedBasePath.replace(/\/+$/g, '') || '/';
|
|
68
|
+
|
|
69
|
+
if (trimmedBasePath === '/') {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return normalizedPathname === trimmedBasePath || normalizedPathname.startsWith(`${trimmedBasePath}/`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getNormalizedModernClientPrefix() {
|
|
77
|
+
if (typeof window === 'undefined') {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const prefix = window.__nocobase_modern_client_prefix__?.trim();
|
|
82
|
+
return prefix ? prefix.replace(/^\/+|\/+$/g, '') : '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Derive the actual modern-client base path from injected globals.
|
|
86
|
+
*
|
|
87
|
+
* Only returns a value when `__nocobase_public_path__` itself already points to
|
|
88
|
+
* the modern client shell:
|
|
89
|
+
*
|
|
90
|
+
* - legacy shell:
|
|
91
|
+
* `__nocobase_public_path__ = "/nocobase/"`
|
|
92
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
93
|
+
* => `""`
|
|
94
|
+
*
|
|
95
|
+
* - modern shell:
|
|
96
|
+
* `__nocobase_public_path__ = "/nocobase/v/"`
|
|
97
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
98
|
+
* => `"/nocobase/v/"`
|
|
99
|
+
*/
|
|
100
|
+
function getModernClientBasePath() {
|
|
101
|
+
const normalizedPrefix = getNormalizedModernClientPrefix();
|
|
102
|
+
if (!normalizedPrefix) {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (typeof window === 'undefined') {
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const publicPath = window.__nocobase_public_path__?.trim();
|
|
111
|
+
if (publicPath && normalizePublicPath(publicPath).endsWith(`/${normalizedPrefix}/`)) {
|
|
112
|
+
return normalizePublicPath(publicPath);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return '';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** True only when the current page is actually running under the resolved
|
|
119
|
+
* modern-client base path.
|
|
120
|
+
*
|
|
121
|
+
* Example:
|
|
122
|
+
* - pathname `/v/admin/workflow/workflows/1`, modern base `/v/` => true
|
|
123
|
+
* - pathname `/admin/settings/workflow/workflows/1`, modern base `/v/` => false
|
|
124
|
+
*/
|
|
125
|
+
function isPathnameInModernClientRuntime() {
|
|
126
|
+
if (typeof window === 'undefined') {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const pathname = window.location?.pathname ?? '';
|
|
131
|
+
const modernClientBasePath = getModernClientBasePath();
|
|
132
|
+
if (!pathname || !modernClientBasePath) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return isPathnameInsideBasePath(pathname, modernClientBasePath);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Fallback for incomplete/mocked environments where public path was not
|
|
140
|
+
* injected but the modern prefix still exists.
|
|
141
|
+
*
|
|
142
|
+
* Example:
|
|
143
|
+
* - pathname `/v/admin/workflow/workflows/1`
|
|
144
|
+
* `__nocobase_modern_client_prefix__ = "v"`
|
|
145
|
+
* `__nocobase_public_path__` missing
|
|
146
|
+
* => true
|
|
147
|
+
*/
|
|
148
|
+
function isPathnameInModernClientRuntimeByPrefix() {
|
|
149
|
+
if (typeof window === 'undefined') {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const normalizedPrefix = getNormalizedModernClientPrefix();
|
|
154
|
+
const pathname = window.location?.pathname ?? '';
|
|
155
|
+
if (!normalizedPrefix || !pathname) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return isPathnameInsideBasePath(pathname, normalizePublicPath(normalizedPrefix));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Resolve which client shell currently owns the route.
|
|
163
|
+
*
|
|
164
|
+
* - returns `modern` when the current page is actually mounted under the modern
|
|
165
|
+
* client base path (`/v/`, `/nocobase/v/`, ...)
|
|
166
|
+
* - returns `legacy` when the route is still under the legacy shell, even if the
|
|
167
|
+
* modern prefix global has been injected into the page
|
|
168
|
+
*/
|
|
169
|
+
export function getRouteRuntimeVersion(): RouteRuntimeVersion {
|
|
170
|
+
if (typeof window === 'undefined') {
|
|
171
|
+
return hasModernClientPrefix() ? 'modern' : 'legacy';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (hasConfiguredPublicPath()) {
|
|
175
|
+
return isPathnameInModernClientRuntime() ? 'modern' : 'legacy';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Defensive fallback for incomplete test/mocked environments where public
|
|
179
|
+
// path was not injected but the modern prefix still exists.
|
|
180
|
+
if (isPathnameInModernClientRuntimeByPrefix()) {
|
|
181
|
+
return 'modern';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return 'legacy';
|
|
185
|
+
}
|
package/src/utils/index.tsx
CHANGED
|
@@ -11,6 +11,7 @@ import React, { ComponentType, FC } from 'react';
|
|
|
11
11
|
import { BlankComponent } from '../components';
|
|
12
12
|
|
|
13
13
|
export * from './appVersionHTML';
|
|
14
|
+
export * from './getRouteRuntimeVersion';
|
|
14
15
|
|
|
15
16
|
export function normalizeContainer(container: Element | ShadowRoot | string): Element | null {
|
|
16
17
|
if (!container) {
|