@nocobase/client-v2 2.2.0-alpha.7 → 2.2.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.
Files changed (50) hide show
  1. package/es/BaseApplication.d.ts +1 -1
  2. package/es/components/form/TypedVariableInput.d.ts +5 -31
  3. package/es/components/form/filter/CollectionFilter.d.ts +0 -2
  4. package/es/components/form/filter/CollectionFilterItem.d.ts +1 -11
  5. package/es/components/form/filter/CollectionFilterPanel.d.ts +0 -2
  6. package/es/components/form/filter/index.d.ts +0 -2
  7. package/es/components/form/filter/useFilterActionProps.d.ts +0 -2
  8. package/es/components/index.d.ts +0 -1
  9. package/es/flow/components/FieldAssignExactDatePicker.d.ts +0 -1
  10. package/es/flow/components/FieldAssignValueInput.d.ts +0 -3
  11. package/es/flow/components/RunJSValueEditor.d.ts +0 -1
  12. package/es/flow/index.d.ts +0 -1
  13. package/es/index.d.ts +0 -4
  14. package/es/index.mjs +99 -133
  15. package/es/utils/index.d.ts +0 -1
  16. package/lib/index.js +106 -140
  17. package/package.json +7 -8
  18. package/src/BaseApplication.tsx +6 -6
  19. package/src/__tests__/app.test.tsx +0 -26
  20. package/src/__tests__/browserChecker.test.ts +0 -61
  21. package/src/components/README.md +1 -7
  22. package/src/components/README.zh-CN.md +1 -6
  23. package/src/components/form/JsonTextArea.tsx +0 -4
  24. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +2 -145
  25. package/src/components/form/ScanInput/useCodeScanner.ts +2 -154
  26. package/src/components/form/TypedVariableInput.tsx +98 -445
  27. package/src/components/form/__tests__/TypedVariableInput.test.tsx +9 -320
  28. package/src/components/form/filter/CollectionFilter.tsx +0 -4
  29. package/src/components/form/filter/CollectionFilterItem.tsx +7 -32
  30. package/src/components/form/filter/CollectionFilterPanel.tsx +0 -4
  31. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +0 -38
  32. package/src/components/form/filter/index.ts +0 -2
  33. package/src/components/form/filter/useFilterActionProps.ts +6 -37
  34. package/src/components/index.ts +0 -1
  35. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +1 -0
  36. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +6 -253
  37. package/src/flow/components/FieldAssignExactDatePicker.tsx +11 -25
  38. package/src/flow/components/FieldAssignValueInput.tsx +9 -55
  39. package/src/flow/components/RunJSValueEditor.tsx +1 -9
  40. package/src/flow/index.ts +0 -1
  41. package/src/index.ts +0 -4
  42. package/src/utils/index.tsx +0 -1
  43. package/es/components/category-tabs/SortableCategoryTabs.d.ts +0 -55
  44. package/es/components/category-tabs/index.d.ts +0 -9
  45. package/es/utils/getRouteRuntimeVersion.d.ts +0 -23
  46. package/src/__tests__/getRouteRuntimeVersion.test.ts +0 -68
  47. package/src/components/category-tabs/SortableCategoryTabs.tsx +0 -210
  48. package/src/components/category-tabs/index.ts +0 -10
  49. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +0 -95
  50. package/src/utils/getRouteRuntimeVersion.ts +0 -185
@@ -1,55 +0,0 @@
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
- import React from 'react';
10
- /**
11
- * A category descriptor for {@link SortableCategoryTabs}. The component is
12
- * i18n-agnostic: `label` is rendered verbatim, so consumers pass an
13
- * already-compiled/translated node. `color` is an antd preset color name or a
14
- * hex string; `'default'` / `undefined` renders no badge color.
15
- */
16
- export type SortableCategoryTabItem = {
17
- id: string | number;
18
- label: React.ReactNode;
19
- color?: string;
20
- };
21
- export type SortableCategoryTabsProps = {
22
- activeKey: string;
23
- onChange: (key: string) => void;
24
- /** Draggable category tabs (the fixed leading tab is configured via `allTab`). */
25
- categories: SortableCategoryTabItem[];
26
- /** The fixed, non-draggable leading tab, e.g. "All". */
27
- allTab: {
28
- key: string;
29
- label: React.ReactNode;
30
- };
31
- /** Show the "+" add button and handle its click. */
32
- onAdd?: () => void;
33
- /** Per-category edit menu item handler; menu is hidden when omitted. */
34
- onEdit?: (id: string | number) => void;
35
- /** Per-category delete menu item handler; menu is hidden when omitted. */
36
- onDelete?: (id: string | number) => void;
37
- /** Reorder handler. Receives the dragged and dropped category ids. */
38
- onSort?: (sourceId: string | number, targetId: string | number) => void | Promise<void>;
39
- /** Consumer-translated labels for the per-category dropdown menu. */
40
- menuLabels?: {
41
- edit?: string;
42
- delete?: string;
43
- };
44
- className?: string;
45
- };
46
- /**
47
- * A draggable, editable category tab bar. Renders only the tab bar (no content
48
- * panes) — the page renders its content below and reacts to `activeKey`.
49
- *
50
- * Shared by settings pages that group records under reorderable categories
51
- * (data-source collections, workflows, …). Drag-to-reorder is powered by
52
- * `@dnd-kit`; the "+" / per-tab edit-delete affordances are optional.
53
- */
54
- export declare function SortableCategoryTabs(props: SortableCategoryTabsProps): React.JSX.Element;
55
- export default SortableCategoryTabs;
@@ -1,9 +0,0 @@
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
- export * from './SortableCategoryTabs';
@@ -1,23 +0,0 @@
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
- export type RouteRuntimeVersion = 'legacy' | 'modern';
10
- declare global {
11
- interface Window {
12
- __nocobase_modern_client_prefix__?: string;
13
- __nocobase_public_path__?: string;
14
- }
15
- }
16
- /** Resolve which client shell currently owns the route.
17
- *
18
- * - returns `modern` when the current page is actually mounted under the modern
19
- * client base path (`/v/`, `/nocobase/v/`, ...)
20
- * - returns `legacy` when the route is still under the legacy shell, even if the
21
- * modern prefix global has been injected into the page
22
- */
23
- export declare function getRouteRuntimeVersion(): RouteRuntimeVersion;
@@ -1,68 +0,0 @@
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 { afterEach, describe, expect, it } from 'vitest';
11
- import { getRouteRuntimeVersion } from '../utils/getRouteRuntimeVersion';
12
-
13
- function replacePathname(pathname: string) {
14
- Object.defineProperty(window, 'location', {
15
- configurable: true,
16
- value: {
17
- ...window.location,
18
- pathname,
19
- },
20
- });
21
- }
22
-
23
- describe('getRouteRuntimeVersion', () => {
24
- afterEach(() => {
25
- delete window.__nocobase_modern_client_prefix__;
26
- delete window.__nocobase_public_path__;
27
- replacePathname('/');
28
- });
29
-
30
- it('returns modern when the current pathname is inside the modern client prefix', () => {
31
- window.__nocobase_modern_client_prefix__ = 'v';
32
- window.__nocobase_public_path__ = '/nocobase/v/';
33
- replacePathname('/nocobase/v/admin/settings/workflow');
34
-
35
- expect(getRouteRuntimeVersion()).toBe('modern');
36
- });
37
-
38
- it('returns legacy when reused v2 components run under the v1 settings page', () => {
39
- window.__nocobase_modern_client_prefix__ = 'v';
40
- window.__nocobase_public_path__ = '/nocobase/';
41
- replacePathname('/nocobase/admin/settings/workflow/workflows/123');
42
-
43
- expect(getRouteRuntimeVersion()).toBe('legacy');
44
- });
45
-
46
- it('returns legacy when root public path is "/"', () => {
47
- window.__nocobase_modern_client_prefix__ = 'v';
48
- window.__nocobase_public_path__ = '/';
49
- replacePathname('/admin/settings/workflow/workflows/123');
50
-
51
- expect(getRouteRuntimeVersion()).toBe('legacy');
52
- });
53
-
54
- it('returns modern when root public path is "/v/"', () => {
55
- window.__nocobase_modern_client_prefix__ = 'v';
56
- window.__nocobase_public_path__ = '/v/';
57
- replacePathname('/v/admin/workflow/workflows/123');
58
-
59
- expect(getRouteRuntimeVersion()).toBe('modern');
60
- });
61
-
62
- it('falls back to pathname matching when public path is unavailable', () => {
63
- window.__nocobase_modern_client_prefix__ = 'v';
64
- replacePathname('/v/admin/workflow/workflows/123');
65
-
66
- expect(getRouteRuntimeVersion()).toBe('modern');
67
- });
68
- });
@@ -1,210 +0,0 @@
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;
@@ -1,10 +0,0 @@
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';
@@ -1,95 +0,0 @@
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 { FlowEngine, FlowEngineProvider, type Collection } from '@nocobase/flow-engine';
11
- import { renderHook } from '@testing-library/react';
12
- import React from 'react';
13
- import { describe, expect, it, vi } from 'vitest';
14
- import { useFilterActionProps } from '../useFilterActionProps';
15
-
16
- vi.mock('../../../flow/components/filter/useFilterOptions', () => ({
17
- useFilterOptions: () => [],
18
- }));
19
-
20
- vi.mock('../CollectionFilterItem', () => ({
21
- createCollectionFilterItem: () => undefined,
22
- }));
23
-
24
- function makeCollection(): Collection {
25
- return {
26
- getFields: () => [{ name: 'title' }, { name: 'type' }],
27
- } as unknown as Collection;
28
- }
29
-
30
- function makeWrapper() {
31
- const engine = new FlowEngine();
32
- const Wrapper: React.FC = ({ children }) => <FlowEngineProvider engine={engine}>{children}</FlowEngineProvider>;
33
- return Wrapper;
34
- }
35
-
36
- describe('useFilterActionProps', () => {
37
- it('seeds the editable group from defaultValue when initialValue is missing', () => {
38
- const { result } = renderHook(
39
- () =>
40
- useFilterActionProps({
41
- collection: makeCollection(),
42
- defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
43
- onApply: () => undefined,
44
- }),
45
- { wrapper: makeWrapper() },
46
- );
47
-
48
- expect(result.current.value).toMatchObject({
49
- logic: '$and',
50
- items: [
51
- { path: 'title', operator: '$includes', value: '' },
52
- { path: 'type', operator: '$eq', value: undefined },
53
- ],
54
- });
55
- });
56
-
57
- it('reset restores defaultValue and emits its compiled filter', () => {
58
- const onApply = vi.fn();
59
- const { result } = renderHook(
60
- () =>
61
- useFilterActionProps({
62
- collection: makeCollection(),
63
- defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
64
- initialValue: { $and: [{ title: { $includes: 'abc' } }] },
65
- onApply,
66
- }),
67
- { wrapper: makeWrapper() },
68
- );
69
-
70
- result.current.onReset();
71
-
72
- expect(result.current.value).toMatchObject({
73
- logic: '$and',
74
- items: [
75
- { path: 'title', operator: '$includes', value: '' },
76
- { path: 'type', operator: '$eq', value: undefined },
77
- ],
78
- });
79
- expect(onApply).toHaveBeenCalledWith(undefined, 'reset');
80
- });
81
-
82
- it('counts only effective compiled conditions, so empty default rows do not highlight the button', () => {
83
- const { result } = renderHook(
84
- () =>
85
- useFilterActionProps({
86
- collection: makeCollection(),
87
- defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
88
- onApply: () => undefined,
89
- }),
90
- { wrapper: makeWrapper() },
91
- );
92
-
93
- expect(result.current.conditionCount).toBe(0);
94
- });
95
- });
@@ -1,185 +0,0 @@
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
- }