@nocobase/client-v2 2.2.0-beta.15 → 2.2.0-beta.17

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 (93) hide show
  1. package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -2
  2. package/es/flow/actions/linkageRules.d.ts +25 -0
  3. package/es/flow/components/FieldAssignValueInput.d.ts +4 -30
  4. package/es/flow/components/FlowRoute.d.ts +2 -2
  5. package/es/flow/components/field-value-variable/DateVariableEditor.d.ts +24 -0
  6. package/es/flow/components/field-value-variable/FieldValueVariableInput.d.ts +31 -0
  7. package/es/flow/components/field-value-variable/dateValue.d.ts +36 -0
  8. package/es/flow/components/field-value-variable/index.d.ts +11 -0
  9. package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
  10. package/es/flow/models/actions/UpdateRecordActionUtils.d.ts +8 -2
  11. package/es/flow/models/base/ActionModelCore.d.ts +4 -2
  12. package/es/flow/models/base/BlockGridModel.d.ts +3 -0
  13. package/es/flow/models/blocks/form/FormBlockModel.d.ts +6 -0
  14. package/es/flow/models/blocks/form/FormGridModel.d.ts +6 -0
  15. package/es/flow/models/blocks/form/value-runtime/rules.d.ts +1 -0
  16. package/es/flow/models/blocks/table/JSColumnModel.d.ts +2 -0
  17. package/es/flow/models/blocks/table/TableColumnModel.d.ts +1 -0
  18. package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
  19. package/es/index.d.ts +1 -0
  20. package/es/index.mjs +105 -111
  21. package/es/ui-operation/index.d.ts +15 -0
  22. package/es/ui-operation/ui-operation-codec.d.ts +10 -0
  23. package/lib/index.js +108 -114
  24. package/lib/locale/languageCodes.js +1 -0
  25. package/package.json +8 -7
  26. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +7 -2
  27. package/src/components/form/ScanInput/CodeScanner.tsx +61 -34
  28. package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
  29. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +114 -18
  30. package/src/components/form/ScanInput/useCodeScanner.ts +166 -23
  31. package/src/flow/__tests__/FlowRoute.test.tsx +126 -8
  32. package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
  33. package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
  34. package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
  35. package/src/flow/actions/__tests__/linkageRules.actionStates.test.ts +33 -0
  36. package/src/flow/actions/linkageRules.tsx +51 -13
  37. package/src/flow/common/Markdown/style.ts +4 -0
  38. package/src/flow/components/BlockItemCard.tsx +2 -2
  39. package/src/flow/components/FieldAssignValueInput.tsx +38 -621
  40. package/src/flow/components/FlowRoute.tsx +71 -29
  41. package/src/flow/components/field-value-variable/DateVariableEditor.tsx +181 -0
  42. package/src/flow/components/field-value-variable/FieldValueVariableInput.tsx +326 -0
  43. package/src/flow/components/field-value-variable/__tests__/FieldValueVariableInput.test.tsx +380 -0
  44. package/src/flow/components/field-value-variable/dateValue.ts +223 -0
  45. package/src/flow/components/field-value-variable/index.ts +12 -0
  46. package/src/flow/index.ts +2 -0
  47. package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
  48. package/src/flow/models/actions/UpdateRecordActionModel.tsx +18 -1
  49. package/src/flow/models/actions/UpdateRecordActionUtils.ts +18 -6
  50. package/src/flow/models/actions/__tests__/UpdateRecordActionModel.test.ts +76 -4
  51. package/src/flow/models/base/ActionModelCore.tsx +11 -2
  52. package/src/flow/models/base/BlockGridModel.tsx +26 -0
  53. package/src/flow/models/base/CollectionBlockModel.tsx +15 -2
  54. package/src/flow/models/base/PageModel/PageTabModel.tsx +67 -17
  55. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +509 -12
  56. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
  57. package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
  58. package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
  59. package/src/flow/models/base/__tests__/CollectionBlockModel.initialBeforeRenderRefresh.test.ts +60 -0
  60. package/src/flow/models/blocks/assign-form/AssignFormItemModel.tsx +28 -53
  61. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +27 -3
  62. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +32 -4
  63. package/src/flow/models/blocks/form/FormBlockModel.tsx +4 -0
  64. package/src/flow/models/blocks/form/FormGridModel.tsx +4 -0
  65. package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +8 -2
  66. package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +435 -0
  67. package/src/flow/models/blocks/form/value-runtime/rules.ts +67 -14
  68. package/src/flow/models/blocks/form/value-runtime/runtime.ts +43 -19
  69. package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
  70. package/src/flow/models/blocks/table/JSColumnModel.tsx +10 -1
  71. package/src/flow/models/blocks/table/TableBlockModel.tsx +3 -1
  72. package/src/flow/models/blocks/table/TableColumnModel.tsx +30 -1
  73. package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +52 -5
  74. package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
  75. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -0
  76. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/PopupSubTableFieldModel.tsx +8 -0
  77. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/__tests__/popupContext.test.ts +120 -0
  78. package/src/flow/models/fields/AssociationFieldModel/PopupSubTableFieldModel/actions/PopupSubTableEditActionModel.tsx +10 -2
  79. package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +46 -0
  80. package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
  81. package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
  82. package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
  83. package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
  84. package/src/flow/models/fields/mobile-components/MobileLazySelect.tsx +1 -0
  85. package/src/flow/models/fields/mobile-components/__tests__/MobileSelect.test.tsx +20 -2
  86. package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
  87. package/src/index.ts +1 -0
  88. package/src/layout-manager/LayoutContentRoute.tsx +2 -1
  89. package/src/layout-manager/LayoutRoute.tsx +2 -1
  90. package/src/layout-manager/__tests__/LayoutRoute.test.tsx +87 -1
  91. package/src/locale/languageCodes.ts +1 -0
  92. package/src/ui-operation/index.ts +33 -0
  93. package/src/ui-operation/ui-operation-codec.ts +54 -0
@@ -105,9 +105,6 @@ function resolveItemDependencyPath(ctx: FlowContext, depPath: NamePath): DataSco
105
105
  ctx,
106
106
  parseFieldIndexEntries((ctx.model as any)?.context?.fieldIndex ?? (ctx as any)?.fieldIndex),
107
107
  );
108
- if (!entries.length) {
109
- return wildcardDeps();
110
- }
111
108
 
112
109
  let parentDepth = 0;
113
110
  let cursor = [...depPath];
@@ -121,6 +118,10 @@ function resolveItemDependencyPath(ctx: FlowContext, depPath: NamePath): DataSco
121
118
  return wildcardDeps();
122
119
  }
123
120
 
121
+ if (!entries.length) {
122
+ return parentDepth === 0 ? resolveRootItemDependencyPath(cursor) : emptyDeps();
123
+ }
124
+
124
125
  if (parentDepth === entries.length) {
125
126
  return resolveRootItemDependencyPath(cursor);
126
127
  }
package/src/index.ts CHANGED
@@ -53,4 +53,5 @@ export {
53
53
  } from './flow-compat';
54
54
  export type { NocoBaseDesktopRoute } from './flow-compat';
55
55
  export * from './utils/markdownSanitize';
56
+ export * from './ui-operation';
56
57
  export { default as AntdAppProvider } from './theme/AntdAppProvider';
@@ -38,11 +38,12 @@ export const LayoutContentRoute = (props: LayoutContentRouteProps) => {
38
38
  id: lastMatch?.id,
39
39
  name: lastMatch?.id,
40
40
  pathname: location.pathname,
41
+ state: location.state,
41
42
  params: (lastMatch?.params || {}) as Record<string, string | undefined>,
42
43
  layoutRouteName: layout.routeName,
43
44
  layoutBasePathname: layoutMatch?.pathname,
44
45
  };
45
- }, [layout.routeName, location.pathname, matches]);
46
+ }, [layout.routeName, location.pathname, location.state, matches]);
46
47
  if (!model) {
47
48
  throw new Error(`[NocoBase] Layout '${layout.routeName}' model '${layout.uid}' is not mounted.`);
48
49
  }
@@ -71,11 +71,12 @@ export const LayoutRoute = (props: LayoutRouteProps) => {
71
71
  id: lastMatch?.id,
72
72
  name: lastMatch?.id,
73
73
  pathname: location.pathname,
74
+ state: location.state,
74
75
  params: lastMatchParams,
75
76
  layoutRouteName: layout.routeName,
76
77
  layoutBasePathname: layoutMatch?.pathname,
77
78
  };
78
- }, [lastMatch?.id, lastMatchParams, layout.routeName, layoutMatch?.pathname, location.pathname]);
79
+ }, [lastMatch?.id, lastMatchParams, layout.routeName, layoutMatch?.pathname, location.pathname, location.state]);
79
80
  const { loading, data, error } = useRequest(
80
81
  async () => {
81
82
  const existingModel = flowEngine.getModel<BaseLayoutModel>(layout.uid);
@@ -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' },
@@ -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
+ };