@nocobase/flow-engine 2.0.51 → 2.0.52

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.
@@ -347,6 +347,7 @@ declare class BaseFlowEngineContext extends FlowContext {
347
347
  runAction: (actionName: string, params?: Record<string, any>) => Promise<any> | any;
348
348
  engine: FlowEngine;
349
349
  api: APIClient;
350
+ locale: string;
350
351
  viewer: FlowViewer;
351
352
  view: FlowView;
352
353
  modal: HookAPI;
@@ -2307,6 +2307,18 @@ const _FlowEngineContext = class _FlowEngineContext extends BaseFlowEngineContex
2307
2307
  this.defineMethod("t", (keyOrTemplate, options) => {
2308
2308
  return i18n.translate(keyOrTemplate, options);
2309
2309
  });
2310
+ this.defineProperty("locale", {
2311
+ get: /* @__PURE__ */ __name(() => {
2312
+ var _a, _b, _c;
2313
+ return ((_b = (_a = this.api) == null ? void 0 : _a.auth) == null ? void 0 : _b.locale) || ((_c = this.i18n) == null ? void 0 : _c.language);
2314
+ }, "get"),
2315
+ cache: false,
2316
+ meta: Object.assign(() => ({ type: "string", title: this.t("Current language"), sort: 970 }), {
2317
+ title: (0, import_utils.escapeT)("Current language"),
2318
+ sort: 970,
2319
+ hasChildren: false
2320
+ })
2321
+ });
2310
2322
  this.defineMethod("renderJson", function(template) {
2311
2323
  return this.resolveJsonTemplate(template);
2312
2324
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/flow-engine",
3
- "version": "2.0.51",
3
+ "version": "2.0.52",
4
4
  "private": false,
5
5
  "description": "A standalone flow engine for NocoBase, managing workflows, models, and actions.",
6
6
  "main": "lib/index.js",
@@ -8,8 +8,8 @@
8
8
  "dependencies": {
9
9
  "@formily/antd-v5": "1.x",
10
10
  "@formily/reactive": "2.x",
11
- "@nocobase/sdk": "2.0.51",
12
- "@nocobase/shared": "2.0.51",
11
+ "@nocobase/sdk": "2.0.52",
12
+ "@nocobase/shared": "2.0.52",
13
13
  "ahooks": "^3.7.2",
14
14
  "axios": "^1.7.0",
15
15
  "dayjs": "^1.11.9",
@@ -37,5 +37,5 @@
37
37
  ],
38
38
  "author": "NocoBase Team",
39
39
  "license": "Apache-2.0",
40
- "gitHead": "f77260e6a5471835f9dac39c55fe1aebd11b65f1"
40
+ "gitHead": "f843db103e286616a32bc0c6aa011bab9e1c1c10"
41
41
  }
@@ -160,6 +160,23 @@ describe('FlowContext properties and methods', () => {
160
160
  expect(ctx.shared).toBe('from delegate');
161
161
  });
162
162
 
163
+ it('should expose current language as a top-level variable', async () => {
164
+ const engine = new FlowEngine();
165
+ const ctx = engine.context;
166
+ ctx.defineProperty('api', { value: { auth: { locale: 'zh-CN' } } });
167
+ ctx.defineProperty('i18n', { value: { language: 'en-US' } });
168
+
169
+ expect(ctx.locale).toBe('zh-CN');
170
+ await expect(ctx.resolveJsonTemplate('{{ ctx.locale }}')).resolves.toBe('zh-CN');
171
+
172
+ const localeNode = ctx.getPropertyMetaTree().find((node) => node.name === 'locale');
173
+ expect(localeNode).toMatchObject({
174
+ name: 'locale',
175
+ title: '{{t("Current language")}}',
176
+ paths: ['locale'],
177
+ });
178
+ });
179
+
163
180
  it('should throw sync error in get', () => {
164
181
  const ctx = new FlowContext();
165
182
  ctx.defineProperty('error', {
@@ -1142,6 +1142,7 @@ describe('AddSubModelButton toggleable behavior', () => {
1142
1142
  },
1143
1143
  { timeout: 3000 },
1144
1144
  );
1145
+ await waitFor(() => expect(screen.getByRole('switch')).toHaveAttribute('aria-checked', 'true'));
1145
1146
 
1146
1147
  // dropdown should remain open and children should still be visible (no flicker / reload)
1147
1148
  expect(screen.getByText('Async Group')).toBeInTheDocument();
@@ -1158,6 +1159,7 @@ describe('AddSubModelButton toggleable behavior', () => {
1158
1159
 
1159
1160
  // ensure destroy has been called (avoid flakiness on exact call counts)
1160
1161
  await waitFor(() => {
1162
+ expect(screen.getByRole('switch')).toHaveAttribute('aria-checked', 'false');
1161
1163
  expect(repo.destroy).toHaveBeenCalled();
1162
1164
  });
1163
1165
  });
@@ -3034,6 +3034,7 @@ class BaseFlowEngineContext extends FlowContext {
3034
3034
  declare runAction: (actionName: string, params?: Record<string, any>) => Promise<any> | any;
3035
3035
  declare engine: FlowEngine;
3036
3036
  declare api: APIClient;
3037
+ declare locale: string;
3037
3038
  declare viewer: FlowViewer;
3038
3039
  declare view: FlowView;
3039
3040
  declare modal: HookAPI;
@@ -3144,6 +3145,15 @@ export class FlowEngineContext extends BaseFlowEngineContext {
3144
3145
  this.defineMethod('t', (keyOrTemplate: string, options?: any) => {
3145
3146
  return i18n.translate(keyOrTemplate, options);
3146
3147
  });
3148
+ this.defineProperty('locale', {
3149
+ get: () => this.api?.auth?.locale || this.i18n?.language,
3150
+ cache: false,
3151
+ meta: Object.assign(() => ({ type: 'string', title: this.t('Current language'), sort: 970 }), {
3152
+ title: escapeT('Current language'),
3153
+ sort: 970,
3154
+ hasChildren: false,
3155
+ }),
3156
+ });
3147
3157
  this.defineMethod('renderJson', function (template: any) {
3148
3158
  return this.resolveJsonTemplate(template);
3149
3159
  });