@nocobase/client-v2 2.2.0-alpha.2 → 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.
Files changed (44) hide show
  1. package/es/RouteRepository.d.ts +8 -0
  2. package/es/authRedirect.d.ts +1 -0
  3. package/es/components/form/TypedVariableInput.d.ts +9 -1
  4. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  5. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  6. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  7. package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
  8. package/es/flow/models/blocks/js-block/JSBlock.d.ts +1 -0
  9. package/es/index.d.ts +2 -0
  10. package/es/index.mjs +148 -116
  11. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  12. package/es/utils/index.d.ts +1 -0
  13. package/lib/index.js +149 -117
  14. package/package.json +7 -7
  15. package/src/RouteRepository.ts +25 -0
  16. package/src/__tests__/RouteRepository.test.ts +23 -0
  17. package/src/__tests__/authRedirect.test.ts +17 -0
  18. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  19. package/src/authRedirect.ts +38 -0
  20. package/src/components/form/JsonTextArea.tsx +4 -0
  21. package/src/components/form/TypedVariableInput.tsx +58 -34
  22. package/src/components/form/__tests__/TypedVariableInput.test.tsx +54 -0
  23. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  24. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  25. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  26. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  27. package/src/flow/actions/dateTimeFormat.tsx +2 -2
  28. package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
  29. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +177 -1
  30. package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +20 -0
  31. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
  32. package/src/flow/models/base/ActionModelCore.tsx +6 -4
  33. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +37 -0
  34. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
  35. package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
  36. package/src/flow/models/blocks/js-block/JSBlock.tsx +223 -2
  37. package/src/flow/models/blocks/js-block/__tests__/JSBlockModel.test.tsx +150 -0
  38. package/src/flow/models/blocks/table/TableColumnModel.tsx +6 -2
  39. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +51 -0
  40. package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +45 -13
  41. package/src/flow/utils/__tests__/dateTimeFormat.test.ts +42 -0
  42. package/src/index.ts +2 -0
  43. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  44. package/src/utils/index.tsx +1 -0
@@ -207,6 +207,48 @@ describe('dateTimeFormat', () => {
207
207
  expect(save).toHaveBeenCalled();
208
208
  });
209
209
 
210
+ it('syncs ordinary table column props when date time format settings are saved', async () => {
211
+ const setProps = vi.fn();
212
+ const save = vi.fn();
213
+ const setParentProps = vi.fn();
214
+ const model = {
215
+ context: {
216
+ collectionField: {
217
+ type: 'datetime',
218
+ interface: 'datetime',
219
+ },
220
+ },
221
+ setProps,
222
+ save,
223
+ parent: {
224
+ use: 'TableColumnModel',
225
+ setProps: setParentProps,
226
+ },
227
+ };
228
+ model.parent['subModels'] = {
229
+ field: model,
230
+ };
231
+
232
+ await dateTimeFormat.beforeParamsSave(
233
+ { model },
234
+ {
235
+ picker: 'date',
236
+ dateFormat: 'YYYY-MM-DD',
237
+ showTime: true,
238
+ timeFormat: 'HH:mm:ss',
239
+ },
240
+ );
241
+
242
+ expect(setParentProps).toHaveBeenCalledWith({
243
+ picker: 'date',
244
+ dateFormat: 'YYYY-MM-DD',
245
+ showTime: true,
246
+ timeFormat: 'HH:mm:ss',
247
+ format: 'YYYY-MM-DD HH:mm:ss',
248
+ });
249
+ expect(save).toHaveBeenCalled();
250
+ });
251
+
210
252
  it('hides time format for association title date-only fields', () => {
211
253
  const ctx = {
212
254
  model: {
package/src/index.ts CHANGED
@@ -30,6 +30,8 @@ export * from './layout-manager';
30
30
  export * from './hooks';
31
31
  export { default as languageCodes } from './locale/languageCodes';
32
32
  export * from './nocobase-buildin-plugin';
33
+ export { getRouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
34
+ export type { RouteRuntimeVersion } from './utils/getRouteRuntimeVersion';
33
35
  export * from './collection-field-interface/CollectionFieldInterface';
34
36
  export * from './collection-field-interface/CollectionFieldInterfaceManager';
35
37
  export * from './collection-manager/field-configure';
@@ -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
+ }
@@ -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) {