@nocobase/client-v2 2.1.0-beta.33 → 2.1.0-beta.35

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 (76) hide show
  1. package/es/APIClient.d.ts +16 -0
  2. package/es/Application.d.ts +2 -1
  3. package/es/BaseApplication.d.ts +6 -0
  4. package/es/PluginManager.d.ts +2 -0
  5. package/es/authRedirect.d.ts +9 -16
  6. package/es/components/form/EnvVariableInput.d.ts +8 -6
  7. package/es/components/form/VariableInput.d.ts +73 -0
  8. package/es/components/form/index.d.ts +1 -0
  9. package/es/components/form/table/RowOverlayPreview.d.ts +27 -0
  10. package/es/components/form/table/SelectionCell.d.ts +36 -0
  11. package/es/components/form/table/Table.d.ts +82 -0
  12. package/es/components/form/table/constants.d.ts +15 -0
  13. package/es/components/form/table/dnd/SortableRow.d.ts +40 -0
  14. package/es/components/form/table/dnd/index.d.ts +9 -0
  15. package/es/components/form/table/index.d.ts +9 -0
  16. package/es/components/form/table/styles.d.ts +41 -0
  17. package/es/components/form/table/utils.d.ts +44 -0
  18. package/es/components/index.d.ts +2 -0
  19. package/es/flow/components/TextAreaWithContextSelector.d.ts +15 -0
  20. package/es/flow/models/blocks/filter-form/FilterFormBlockModel.d.ts +9 -1
  21. package/es/flow/models/blocks/table/dragSort/dragSortComponents.d.ts +1 -6
  22. package/es/flow/models/blocks/table/dragSort/dragSortHooks.d.ts +5 -1
  23. package/es/flow-compat/passwordUtils.d.ts +1 -1
  24. package/es/index.d.ts +1 -0
  25. package/es/index.mjs +166 -99
  26. package/es/json-logic/globalOperators.d.ts +11 -0
  27. package/es/theme/globalStyles.d.ts +9 -0
  28. package/es/theme/index.d.ts +1 -0
  29. package/es/utils/globalDeps.d.ts +7 -0
  30. package/lib/index.js +173 -106
  31. package/package.json +9 -6
  32. package/src/APIClient.ts +68 -0
  33. package/src/Application.tsx +6 -2
  34. package/src/BaseApplication.tsx +8 -0
  35. package/src/PluginManager.ts +2 -0
  36. package/src/__tests__/app.test.tsx +8 -0
  37. package/src/__tests__/authRedirect.test.ts +170 -64
  38. package/src/__tests__/globalDeps.test.ts +2 -0
  39. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +6 -6
  40. package/src/__tests__/remotePlugins.test.ts +148 -0
  41. package/src/authRedirect.ts +23 -84
  42. package/src/components/form/EnvVariableInput.tsx +11 -46
  43. package/src/components/form/VariableInput.tsx +177 -0
  44. package/src/components/form/__tests__/EnvVariableInput.test.tsx +175 -0
  45. package/src/components/form/index.tsx +1 -0
  46. package/src/components/form/table/RowOverlayPreview.tsx +51 -0
  47. package/src/components/form/table/SelectionCell.tsx +72 -0
  48. package/src/components/form/table/Table.tsx +279 -0
  49. package/src/components/form/table/__tests__/Table.pagination.test.tsx +80 -0
  50. package/src/components/form/table/constants.ts +16 -0
  51. package/src/components/form/table/dnd/SortableRow.tsx +106 -0
  52. package/src/components/form/table/dnd/index.ts +10 -0
  53. package/src/components/form/table/index.tsx +13 -0
  54. package/src/components/form/table/styles.ts +110 -0
  55. package/src/components/form/table/utils.ts +75 -0
  56. package/src/components/index.ts +2 -0
  57. package/src/css-variable/CSSVariableProvider.tsx +1 -1
  58. package/src/flow/actions/filterFormDefaultValues.tsx +1 -2
  59. package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +2 -0
  60. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +111 -0
  61. package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +2 -1
  62. package/src/flow/components/TextAreaWithContextSelector.tsx +30 -6
  63. package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +81 -0
  64. package/src/flow/components/code-editor/hooks/useCodeRunner.ts +34 -2
  65. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +329 -5
  66. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +337 -0
  67. package/src/flow/models/blocks/table/dragSort/dragSortComponents.tsx +1 -81
  68. package/src/flow/models/fields/JSEditableFieldModel.tsx +107 -7
  69. package/src/flow/models/fields/__tests__/JSEditableFieldModel.test.tsx +97 -0
  70. package/src/index.ts +1 -0
  71. package/src/json-logic/globalOperators.js +731 -0
  72. package/src/nocobase-buildin-plugin/index.tsx +4 -4
  73. package/src/theme/globalStyles.ts +21 -0
  74. package/src/theme/index.tsx +1 -0
  75. package/src/utils/globalDeps.ts +50 -30
  76. package/src/utils/remotePlugins.ts +107 -6
@@ -11,6 +11,7 @@ import React from 'react';
11
11
  import { act, render, screen, waitFor } from '@testing-library/react';
12
12
  import { describe, expect, it, vi } from 'vitest';
13
13
  import { FlowEngine, FlowEngineProvider, FlowModel, FlowModelRenderer } from '@nocobase/flow-engine';
14
+ import { get as lodashGet, set as lodashSet } from 'lodash';
14
15
  import { JSEditableFieldModel } from '../JSEditableFieldModel';
15
16
 
16
17
  function createField(props?: Record<string, any>, code = '') {
@@ -73,6 +74,21 @@ const React = ctx.React;
73
74
  ctx.render(<span data-testid="js-readonly-state">{String(ctx.readOnly)}</span>);
74
75
  `;
75
76
 
77
+ const SET_VALUE_AND_RENDER_NAME_PATH_CODE = `
78
+ const React = ctx.React;
79
+ ctx.setValue?.('44');
80
+ ctx.render(<span data-testid="js-name-path">{JSON.stringify(ctx.namePath)}</span>);
81
+ `;
82
+
83
+ function createFormStub(initialValues: any = {}) {
84
+ const store = JSON.parse(JSON.stringify(initialValues));
85
+ return {
86
+ getFieldValue: (namePath: any) => lodashGet(store, namePath),
87
+ setFieldValue: (namePath: any, value: any) => lodashSet(store, namePath, value),
88
+ getFieldsValue: () => store,
89
+ };
90
+ }
91
+
76
92
  class ParentModel extends FlowModel<any> {
77
93
  render() {
78
94
  return <FlowModelRenderer model={this.subModels.field} />;
@@ -83,6 +99,11 @@ function renderParentFieldWithFlowRenderer(
83
99
  fieldProps?: Record<string, any>,
84
100
  parentProps?: Record<string, any>,
85
101
  code = EDITABLE_CODE,
102
+ options?: {
103
+ fieldIndex?: string[];
104
+ fieldStepParams?: Record<string, any>;
105
+ form?: any;
106
+ },
86
107
  ) {
87
108
  const engine = new FlowEngine();
88
109
  engine.registerModels({ JSEditableFieldModel, ParentModel });
@@ -96,6 +117,7 @@ function renderParentFieldWithFlowRenderer(
96
117
  uid: 'js-field-with-parent',
97
118
  props: fieldProps,
98
119
  stepParams: {
120
+ ...(options?.fieldStepParams || {}),
99
121
  jsSettings: {
100
122
  runJs: {
101
123
  code,
@@ -106,6 +128,13 @@ function renderParentFieldWithFlowRenderer(
106
128
  },
107
129
  });
108
130
 
131
+ if (options?.form) {
132
+ parent.context.defineProperty('form', { value: options.form });
133
+ }
134
+ if (options?.fieldIndex) {
135
+ parent.subModels.field.context.defineProperty('fieldIndex', { value: options.fieldIndex });
136
+ }
137
+
109
138
  render(
110
139
  <FlowEngineProvider engine={engine}>
111
140
  <FlowModelRenderer model={parent} />
@@ -207,4 +236,72 @@ describe('JSEditableFieldModel', () => {
207
236
  applyFlowSpy.mockRestore();
208
237
  }
209
238
  });
239
+
240
+ it('writes top-level form values through the effective name path', async () => {
241
+ const form = createFormStub({});
242
+
243
+ renderParentFieldWithFlowRenderer({ name: 'staffname' }, undefined, SET_VALUE_AND_RENDER_NAME_PATH_CODE, {
244
+ form,
245
+ fieldStepParams: {
246
+ fieldSettings: {
247
+ init: {
248
+ fieldPath: 'staffname',
249
+ },
250
+ },
251
+ },
252
+ });
253
+
254
+ await waitFor(() => {
255
+ expect(form.getFieldValue(['staffname'])).toBe('44');
256
+ expect(screen.getByTestId('js-name-path')).toHaveTextContent(JSON.stringify(['staffname']));
257
+ });
258
+ });
259
+
260
+ it('writes subform list values under the association path instead of the form root', async () => {
261
+ const form = createFormStub({ org_o2m: [{}] });
262
+
263
+ renderParentFieldWithFlowRenderer({ name: 'orgname' }, undefined, SET_VALUE_AND_RENDER_NAME_PATH_CODE, {
264
+ form,
265
+ fieldIndex: ['org_o2m:0'],
266
+ fieldStepParams: {
267
+ fieldSettings: {
268
+ init: {
269
+ fieldPath: 'orgname',
270
+ associationPathName: 'org_o2m',
271
+ },
272
+ },
273
+ },
274
+ });
275
+
276
+ await waitFor(() => {
277
+ expect(form.getFieldValue(['org_o2m', 0, 'orgname'])).toBe('44');
278
+ expect(form.getFieldValue(['orgname'])).toBeUndefined();
279
+ expect(screen.getByTestId('js-name-path')).toHaveTextContent(JSON.stringify(['org_o2m', 0, 'orgname']));
280
+ });
281
+ });
282
+
283
+ it('writes nested subform list values with the full field index chain', async () => {
284
+ const form = createFormStub({ users: [{ roles: [{}, {}] }] });
285
+
286
+ renderParentFieldWithFlowRenderer({ name: 'roleName' }, undefined, SET_VALUE_AND_RENDER_NAME_PATH_CODE, {
287
+ form,
288
+ fieldIndex: ['users:0', 'roles:1'],
289
+ fieldStepParams: {
290
+ fieldSettings: {
291
+ init: {
292
+ fieldPath: 'roleName',
293
+ associationPathName: 'users.roles',
294
+ },
295
+ },
296
+ },
297
+ });
298
+
299
+ await waitFor(() => {
300
+ expect(form.getFieldValue(['users', 0, 'roles', 1, 'roleName'])).toBe('44');
301
+ expect(form.getFieldValue(['roleName'])).toBeUndefined();
302
+ expect(screen.getByTestId('js-name-path')).toHaveTextContent(
303
+ JSON.stringify(['users', 0, 'roles', 1, 'roleName']),
304
+ );
305
+ });
306
+ });
210
307
  });
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  import 'antd/dist/reset.css';
11
11
 
12
+ export * from './APIClient';
12
13
  export * from './BaseApplication';
13
14
  export * from './Application';
14
15
  export * from './PinnedPluginListContext';