@nocobase/flow-engine 2.2.0-beta.7 → 2.2.0-beta.8

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/lib/components/MobilePopup.style.js +16 -5
  2. package/lib/flowContext.d.ts +1 -1
  3. package/lib/flowContext.js +22 -6
  4. package/lib/locale/en-US.json +1 -0
  5. package/lib/locale/index.d.ts +2 -0
  6. package/lib/locale/zh-CN.json +1 -0
  7. package/lib/resources/apiResource.js +2 -1
  8. package/lib/resources/baseRecordResource.js +6 -17
  9. package/lib/resources/multiRecordResource.js +13 -3
  10. package/lib/resources/singleRecordResource.js +7 -2
  11. package/lib/utils/dataSourceDirty.d.ts +20 -0
  12. package/lib/utils/dataSourceDirty.js +139 -0
  13. package/lib/utils/dirtyAwareApiClient.d.ts +11 -0
  14. package/lib/utils/dirtyAwareApiClient.js +378 -0
  15. package/lib/utils/index.d.ts +1 -0
  16. package/lib/utils/index.js +11 -0
  17. package/lib/utils/openViewRouteState.d.ts +28 -0
  18. package/lib/utils/openViewRouteState.js +125 -0
  19. package/lib/utils/parsePathnameToViewParams.d.ts +3 -0
  20. package/lib/utils/parsePathnameToViewParams.js +18 -1
  21. package/lib/views/ViewNavigation.js +5 -0
  22. package/package.json +4 -4
  23. package/src/__tests__/flowContext.test.ts +88 -0
  24. package/src/__tests__/flowEngine.dataSourceDirty.test.ts +51 -0
  25. package/src/__tests__/runjsRuntimeFeatures.test.ts +15 -2
  26. package/src/components/MobilePopup.style.ts +22 -6
  27. package/src/components/__tests__/MobilePopup.style.test.tsx +103 -0
  28. package/src/flowContext.ts +32 -7
  29. package/src/locale/en-US.json +1 -0
  30. package/src/locale/zh-CN.json +1 -0
  31. package/src/resources/apiResource.ts +2 -1
  32. package/src/resources/baseRecordResource.ts +6 -23
  33. package/src/resources/multiRecordResource.ts +13 -3
  34. package/src/resources/singleRecordResource.ts +6 -1
  35. package/src/utils/__tests__/dirtyAwareApiClient.test.ts +392 -0
  36. package/src/utils/__tests__/openViewRouteState.test.ts +40 -0
  37. package/src/utils/__tests__/parsePathnameToViewParams.test.ts +36 -0
  38. package/src/utils/dataSourceDirty.ts +126 -0
  39. package/src/utils/dirtyAwareApiClient.ts +430 -0
  40. package/src/utils/index.ts +10 -0
  41. package/src/utils/openViewRouteState.ts +107 -0
  42. package/src/utils/parsePathnameToViewParams.ts +23 -1
  43. package/src/views/ViewNavigation.ts +6 -1
  44. package/src/views/__tests__/ViewNavigation.test.ts +15 -0
@@ -0,0 +1,378 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var dirtyAwareApiClient_exports = {};
29
+ __export(dirtyAwareApiClient_exports, {
30
+ SKIP_DATA_SOURCE_DIRTY: () => SKIP_DATA_SOURCE_DIRTY,
31
+ getDirtyAwareApiClient: () => getDirtyAwareApiClient
32
+ });
33
+ module.exports = __toCommonJS(dirtyAwareApiClient_exports);
34
+ var import_dataSourceDirty = require("./dataSourceDirty");
35
+ const SKIP_DATA_SOURCE_DIRTY = "__nocobaseSkipDataSourceDirty";
36
+ const dirtyAwareApiClientCache = /* @__PURE__ */ new WeakMap();
37
+ const dirtyAwareApiClientProxies = /* @__PURE__ */ new WeakSet();
38
+ const MUTATING_RESOURCE_ACTIONS = [
39
+ "add",
40
+ "bulkdestroy",
41
+ "bulkupdate",
42
+ "create",
43
+ "delete",
44
+ "destroy",
45
+ "execute",
46
+ "firstorcreate",
47
+ "import",
48
+ "move",
49
+ "remove",
50
+ "save",
51
+ "saveastemplate",
52
+ "set",
53
+ "setfields",
54
+ "submit",
55
+ "update",
56
+ "updateorcreate",
57
+ "upsert"
58
+ ];
59
+ function isApiClientLike(value) {
60
+ if (!value || typeof value !== "object") {
61
+ return false;
62
+ }
63
+ const candidate = value;
64
+ return typeof candidate.resource === "function" && typeof candidate.request === "function";
65
+ }
66
+ __name(isApiClientLike, "isApiClientLike");
67
+ function isMutatingResourceAction(actionName) {
68
+ const normalized = String(actionName || "").trim();
69
+ if (!normalized) {
70
+ return false;
71
+ }
72
+ const baseActionName = normalized.split("/")[0];
73
+ const lowerBaseActionName = baseActionName.toLowerCase();
74
+ return MUTATING_RESOURCE_ACTIONS.some((action) => {
75
+ if (lowerBaseActionName === action) {
76
+ return true;
77
+ }
78
+ if (!lowerBaseActionName.startsWith(action) || baseActionName.length <= action.length) {
79
+ return false;
80
+ }
81
+ const nextChar = baseActionName[action.length];
82
+ return nextChar === "-" || nextChar === "_" || nextChar >= "A" && nextChar <= "Z";
83
+ });
84
+ }
85
+ __name(isMutatingResourceAction, "isMutatingResourceAction");
86
+ function getCurrentOrigin() {
87
+ var _a;
88
+ return typeof window === "undefined" ? void 0 : (_a = window.location) == null ? void 0 : _a.origin;
89
+ }
90
+ __name(getCurrentOrigin, "getCurrentOrigin");
91
+ function parseUrl(value, base) {
92
+ try {
93
+ return new URL(value, base);
94
+ } catch {
95
+ return void 0;
96
+ }
97
+ }
98
+ __name(parseUrl, "parseUrl");
99
+ function stripSearchAndHash(path) {
100
+ const index = path.search(/[?#]/);
101
+ return index === -1 ? path : path.slice(0, index);
102
+ }
103
+ __name(stripSearchAndHash, "stripSearchAndHash");
104
+ function stripKnownApiPrefix(path) {
105
+ const cleanPath = stripSearchAndHash(path).trim();
106
+ if (!cleanPath) {
107
+ return void 0;
108
+ }
109
+ const normalizedPath = cleanPath.replace(/^\/+/, "");
110
+ if (!normalizedPath || normalizedPath === "api") {
111
+ return void 0;
112
+ }
113
+ if (normalizedPath.startsWith("api/")) {
114
+ return normalizedPath.slice("api/".length);
115
+ }
116
+ return normalizedPath;
117
+ }
118
+ __name(stripKnownApiPrefix, "stripKnownApiPrefix");
119
+ function normalizePathname(pathname) {
120
+ return pathname.endsWith("/") ? pathname : `${pathname}/`;
121
+ }
122
+ __name(normalizePathname, "normalizePathname");
123
+ function getAppApiUrl(app) {
124
+ if (!(app == null ? void 0 : app.getApiUrl)) {
125
+ return void 0;
126
+ }
127
+ try {
128
+ return parseUrl(app.getApiUrl(), getCurrentOrigin());
129
+ } catch {
130
+ return void 0;
131
+ }
132
+ }
133
+ __name(getAppApiUrl, "getAppApiUrl");
134
+ function stripConfiguredApiPrefix(path, apiPathname) {
135
+ const cleanPath = stripSearchAndHash(path).trim();
136
+ if (!cleanPath.startsWith("/")) {
137
+ return void 0;
138
+ }
139
+ const apiPath = normalizePathname(apiPathname);
140
+ const requestPath = normalizePathname(cleanPath);
141
+ if (!requestPath.startsWith(apiPath)) {
142
+ return void 0;
143
+ }
144
+ const apiPathWithoutTrailingSlash = apiPath.replace(/\/$/, "");
145
+ return cleanPath.slice(apiPathWithoutTrailingSlash.length).replace(/^\/+/, "") || void 0;
146
+ }
147
+ __name(stripConfiguredApiPrefix, "stripConfiguredApiPrefix");
148
+ function getDirtyResourcePathFromAbsoluteUrl(url, app) {
149
+ if (!["http:", "https:"].includes(url.protocol)) {
150
+ return void 0;
151
+ }
152
+ if (app == null ? void 0 : app.getApiUrl) {
153
+ const apiUrl = getAppApiUrl(app);
154
+ if (!apiUrl || url.origin !== apiUrl.origin) {
155
+ return void 0;
156
+ }
157
+ return stripConfiguredApiPrefix(url.pathname, apiUrl.pathname);
158
+ }
159
+ const currentOrigin = getCurrentOrigin();
160
+ if (!currentOrigin || url.origin !== currentOrigin) {
161
+ return void 0;
162
+ }
163
+ return stripKnownApiPrefix(url.pathname);
164
+ }
165
+ __name(getDirtyResourcePathFromAbsoluteUrl, "getDirtyResourcePathFromAbsoluteUrl");
166
+ function getDirtyResourcePathFromUrl(url, context) {
167
+ if (typeof url !== "string") {
168
+ return void 0;
169
+ }
170
+ const trimmedUrl = url.trim();
171
+ if (!trimmedUrl || trimmedUrl.startsWith("//")) {
172
+ return void 0;
173
+ }
174
+ if (/^https?:\/\//i.test(trimmedUrl)) {
175
+ const parsedUrl = parseUrl(trimmedUrl);
176
+ if (!parsedUrl) {
177
+ return void 0;
178
+ }
179
+ return getDirtyResourcePathFromAbsoluteUrl(parsedUrl, context.app);
180
+ }
181
+ const appApiUrl = getAppApiUrl(context.app);
182
+ const configuredResourcePath = appApiUrl ? stripConfiguredApiPrefix(trimmedUrl, appApiUrl.pathname) : void 0;
183
+ if (configuredResourcePath) {
184
+ return configuredResourcePath;
185
+ }
186
+ return stripKnownApiPrefix(trimmedUrl);
187
+ }
188
+ __name(getDirtyResourcePathFromUrl, "getDirtyResourcePathFromUrl");
189
+ function decodeResourcePathSegment(segment) {
190
+ try {
191
+ return decodeURIComponent(segment);
192
+ } catch {
193
+ return segment;
194
+ }
195
+ }
196
+ __name(decodeResourcePathSegment, "decodeResourcePathSegment");
197
+ function getDataSourceKeyFromResourceOf(resourceOf) {
198
+ const dataSourceKey = String(resourceOf ?? "").trim();
199
+ return dataSourceKey || void 0;
200
+ }
201
+ __name(getDataSourceKeyFromResourceOf, "getDataSourceKeyFromResourceOf");
202
+ function parseResourceActionFromSegments(segments) {
203
+ const resourceSegments = [];
204
+ let actionName;
205
+ let actionSegmentIndex = -1;
206
+ for (let index = 0; index < segments.length; index += 2) {
207
+ const segment = segments[index];
208
+ const actionDelimiterIndex = segment.lastIndexOf(":");
209
+ const resourceSegment = actionDelimiterIndex === -1 ? segment : segment.slice(0, actionDelimiterIndex);
210
+ if (!resourceSegment) {
211
+ return void 0;
212
+ }
213
+ resourceSegments.push(decodeResourcePathSegment(resourceSegment));
214
+ if (actionDelimiterIndex !== -1) {
215
+ actionName = decodeResourcePathSegment(segment.slice(actionDelimiterIndex + 1)).trim();
216
+ actionSegmentIndex = index;
217
+ break;
218
+ }
219
+ }
220
+ if (!actionName || !resourceSegments.length) {
221
+ return void 0;
222
+ }
223
+ if (segments.length > actionSegmentIndex + 2) {
224
+ return void 0;
225
+ }
226
+ return {
227
+ resourceName: resourceSegments.join("."),
228
+ actionName
229
+ };
230
+ }
231
+ __name(parseResourceActionFromSegments, "parseResourceActionFromSegments");
232
+ function parseDirtyResourceActionFromUrl(url, context) {
233
+ const resourcePath = getDirtyResourcePathFromUrl(url, context);
234
+ if (!resourcePath) {
235
+ return void 0;
236
+ }
237
+ const segments = stripSearchAndHash(resourcePath).split("/").filter(Boolean);
238
+ const firstSegment = decodeResourcePathSegment(segments[0] || "");
239
+ if (firstSegment === "dataSources" && segments.length >= 3) {
240
+ const dataSourceKey = getDataSourceKeyFromResourceOf(decodeResourcePathSegment(segments[1]));
241
+ const parsed = parseResourceActionFromSegments(segments.slice(2));
242
+ if (dataSourceKey && parsed) {
243
+ return {
244
+ ...parsed,
245
+ dataSourceKey
246
+ };
247
+ }
248
+ }
249
+ return parseResourceActionFromSegments(segments);
250
+ }
251
+ __name(parseDirtyResourceActionFromUrl, "parseDirtyResourceActionFromUrl");
252
+ function resolveDirtyResourceActionFromResource(resourceName, resourceOf, actionName, context) {
253
+ const normalizedResourceName = resourceName.trim();
254
+ const normalizedActionName = actionName.trim();
255
+ if (!normalizedResourceName || !normalizedActionName) {
256
+ return void 0;
257
+ }
258
+ if (normalizedResourceName.includes("/")) {
259
+ const parsed = parseDirtyResourceActionFromUrl(`${normalizedResourceName}:${normalizedActionName}`, context);
260
+ if (parsed) {
261
+ return parsed;
262
+ }
263
+ }
264
+ const dataSourcesPrefix = "dataSources.";
265
+ if (normalizedResourceName.startsWith(dataSourcesPrefix)) {
266
+ const dataSourceKey = getDataSourceKeyFromResourceOf(resourceOf);
267
+ const nestedResourceName = normalizedResourceName.slice(dataSourcesPrefix.length).trim();
268
+ if (dataSourceKey && nestedResourceName) {
269
+ return {
270
+ dataSourceKey,
271
+ resourceName: nestedResourceName,
272
+ actionName: normalizedActionName
273
+ };
274
+ }
275
+ }
276
+ return {
277
+ resourceName: normalizedResourceName,
278
+ actionName: normalizedActionName
279
+ };
280
+ }
281
+ __name(resolveDirtyResourceActionFromResource, "resolveDirtyResourceActionFromResource");
282
+ function resolveDirtyResourceAction(options, context) {
283
+ const resourceName = typeof (options == null ? void 0 : options.resource) === "string" ? options.resource : void 0;
284
+ const actionName = typeof (options == null ? void 0 : options.action) === "string" ? options.action : void 0;
285
+ if (resourceName && actionName) {
286
+ return resolveDirtyResourceActionFromResource(resourceName, options.resourceOf, actionName, context);
287
+ }
288
+ return parseDirtyResourceActionFromUrl(options == null ? void 0 : options.url, context);
289
+ }
290
+ __name(resolveDirtyResourceAction, "resolveDirtyResourceAction");
291
+ function markResourceActionDataSourceDirty(context, dirtyResourceAction, headers) {
292
+ (0, import_dataSourceDirty.markDataSourceDirty)({
293
+ engine: context.engine,
294
+ dataSourceKey: dirtyResourceAction.dataSourceKey || (0, import_dataSourceDirty.getDataSourceKeyFromHeaders)(headers),
295
+ resourceName: dirtyResourceAction.resourceName,
296
+ includePreviousEngines: true
297
+ });
298
+ }
299
+ __name(markResourceActionDataSourceDirty, "markResourceActionDataSourceDirty");
300
+ function createDirtyAwareResource(context, resource, resourceName, resourceOf, headers) {
301
+ return new Proxy(resource, {
302
+ get(target, prop, receiver) {
303
+ const original = Reflect.get(target, prop, receiver);
304
+ if (typeof prop !== "string" || typeof original !== "function" || !isMutatingResourceAction(prop)) {
305
+ return original;
306
+ }
307
+ const action = original;
308
+ return async (...args) => {
309
+ const result = await action(...args);
310
+ const dirtyResourceAction = resolveDirtyResourceActionFromResource(resourceName, resourceOf, prop, context);
311
+ if (dirtyResourceAction) {
312
+ markResourceActionDataSourceDirty(context, dirtyResourceAction, headers);
313
+ }
314
+ return result;
315
+ };
316
+ }
317
+ });
318
+ }
319
+ __name(createDirtyAwareResource, "createDirtyAwareResource");
320
+ function createDirtyAwareApiClient(api, context) {
321
+ const resource = /* @__PURE__ */ __name((name, of, headers, cancel) => {
322
+ const targetResource = api.resource(name, of, headers, cancel);
323
+ return createDirtyAwareResource(context, targetResource, name, of, headers);
324
+ }, "resource");
325
+ const request = /* @__PURE__ */ __name((config) => {
326
+ const options = config;
327
+ const skipDataSourceDirty = options == null ? void 0 : options[SKIP_DATA_SOURCE_DIRTY];
328
+ const dirtyResourceAction = skipDataSourceDirty ? void 0 : resolveDirtyResourceAction(options, context);
329
+ const { [SKIP_DATA_SOURCE_DIRTY]: _skipDataSourceDirty, ...cleanConfig } = options;
330
+ return api.request(cleanConfig).then((result) => {
331
+ if (dirtyResourceAction && isMutatingResourceAction(dirtyResourceAction.actionName)) {
332
+ markResourceActionDataSourceDirty(context, dirtyResourceAction, options.headers);
333
+ }
334
+ return result;
335
+ });
336
+ }, "request");
337
+ const proxy = new Proxy(api, {
338
+ get(target, prop, receiver) {
339
+ if (prop === "resource") {
340
+ return resource;
341
+ }
342
+ if (prop === "request") {
343
+ return request;
344
+ }
345
+ return Reflect.get(target, prop, receiver);
346
+ }
347
+ });
348
+ dirtyAwareApiClientProxies.add(proxy);
349
+ return proxy;
350
+ }
351
+ __name(createDirtyAwareApiClient, "createDirtyAwareApiClient");
352
+ function getDirtyAwareApiClient(value, context) {
353
+ if (!isApiClientLike(value)) {
354
+ return value;
355
+ }
356
+ if (dirtyAwareApiClientProxies.has(value)) {
357
+ return value;
358
+ }
359
+ const api = value;
360
+ let contextCache = dirtyAwareApiClientCache.get(api);
361
+ if (!contextCache) {
362
+ contextCache = /* @__PURE__ */ new WeakMap();
363
+ dirtyAwareApiClientCache.set(api, contextCache);
364
+ }
365
+ const cached = contextCache.get(context);
366
+ if (cached) {
367
+ return cached;
368
+ }
369
+ const wrapped = createDirtyAwareApiClient(value, context);
370
+ contextCache.set(context, wrapped);
371
+ return wrapped;
372
+ }
373
+ __name(getDirtyAwareApiClient, "getDirtyAwareApiClient");
374
+ // Annotate the CommonJS export names for ESM import in node:
375
+ 0 && (module.exports = {
376
+ SKIP_DATA_SOURCE_DIRTY,
377
+ getDirtyAwareApiClient
378
+ });
@@ -20,6 +20,7 @@ export { buildRecordMeta, collectContextParamsForTemplate, createCurrentRecordMe
20
20
  export { extractPropertyPath, formatPathToVariable, isVariableExpression } from './context';
21
21
  export { clearAutoFlowError, getAutoFlowError, setAutoFlowError, type AutoFlowError } from './autoFlowError';
22
22
  export { parsePathnameToViewParams, type ViewParam } from './parsePathnameToViewParams';
23
+ export { createOpenViewRouteState, decodeOpenViewRouteState, encodeOpenViewRouteState, isOpenViewRouteStateToken, RUNJS_OPEN_VIEW_ROUTE_STATE, type OpenViewRouteMode, type OpenViewRouteSize, type OpenViewRouteState, } from './openViewRouteState';
23
24
  export { decodeBase64Url, encodeBase64Url, isCompleteCtxDatePath, isCtxDatePathPrefix, isCtxDateExpression, parseCtxDateExpression, resolveCtxDatePath, serializeCtxDateValue, } from './dateVariable';
24
25
  export { isRunJSValue, normalizeRunJSValue, extractUsedVariablePathsFromRunJS, type RunJSValue } from './runjsValue';
25
26
  export { resolveRunJSObjectValues } from './resolveRunJSObjectValues';
@@ -33,6 +33,7 @@ __export(utils_exports, {
33
33
  FlowExitAllException: () => import_exceptions.FlowExitAllException,
34
34
  FlowExitException: () => import_exceptions.FlowExitException,
35
35
  MENU_KEYS: () => import_constants.MENU_KEYS,
36
+ RUNJS_OPEN_VIEW_ROUTE_STATE: () => import_openViewRouteState.RUNJS_OPEN_VIEW_ROUTE_STATE,
36
37
  buildRecordMeta: () => import_variablesParams.buildRecordMeta,
37
38
  clearAutoFlowError: () => import_autoFlowError.clearAutoFlowError,
38
39
  collectContextParamsForTemplate: () => import_variablesParams.collectContextParamsForTemplate,
@@ -42,11 +43,14 @@ __export(utils_exports, {
42
43
  createCollectionContextMeta: () => import_createCollectionContextMeta.createCollectionContextMeta,
43
44
  createCurrentRecordMetaFactory: () => import_variablesParams.createCurrentRecordMetaFactory,
44
45
  createEphemeralContext: () => import_createEphemeralContext.createEphemeralContext,
46
+ createOpenViewRouteState: () => import_openViewRouteState.createOpenViewRouteState,
45
47
  createRecordMetaFactory: () => import_variablesParams.createRecordMetaFactory,
46
48
  createRecordResolveOnServerWithLocal: () => import_variablesParams.createRecordResolveOnServerWithLocal,
47
49
  decodeBase64Url: () => import_dateVariable.decodeBase64Url,
50
+ decodeOpenViewRouteState: () => import_openViewRouteState.decodeOpenViewRouteState,
48
51
  defineAction: () => import_flow_definitions.defineAction,
49
52
  encodeBase64Url: () => import_dateVariable.encodeBase64Url,
53
+ encodeOpenViewRouteState: () => import_openViewRouteState.encodeOpenViewRouteState,
50
54
  escapeT: () => import_translation.escapeT,
51
55
  extractPropertyPath: () => import_context.extractPropertyPath,
52
56
  extractUsedVariableNames: () => import_variablesParams.extractUsedVariableNames,
@@ -62,6 +66,7 @@ __export(utils_exports, {
62
66
  isCtxDateExpression: () => import_dateVariable.isCtxDateExpression,
63
67
  isCtxDatePathPrefix: () => import_dateVariable.isCtxDatePathPrefix,
64
68
  isInheritedFrom: () => import_inheritance.isInheritedFrom,
69
+ isOpenViewRouteStateToken: () => import_openViewRouteState.isOpenViewRouteStateToken,
65
70
  isRunJSValue: () => import_runjsValue.isRunJSValue,
66
71
  isVariableExpression: () => import_context.isVariableExpression,
67
72
  normalizeRunJSValue: () => import_runjsValue.normalizeRunJSValue,
@@ -102,6 +107,7 @@ var import_variablesParams = require("./variablesParams");
102
107
  var import_context = require("./context");
103
108
  var import_autoFlowError = require("./autoFlowError");
104
109
  var import_parsePathnameToViewParams = require("./parsePathnameToViewParams");
110
+ var import_openViewRouteState = require("./openViewRouteState");
105
111
  var import_dateVariable = require("./dateVariable");
106
112
  var import_runjsValue = require("./runjsValue");
107
113
  var import_resolveRunJSObjectValues = require("./resolveRunJSObjectValues");
@@ -120,6 +126,7 @@ var import_randomId = require("./randomId");
120
126
  FlowExitAllException,
121
127
  FlowExitException,
122
128
  MENU_KEYS,
129
+ RUNJS_OPEN_VIEW_ROUTE_STATE,
123
130
  buildRecordMeta,
124
131
  clearAutoFlowError,
125
132
  collectContextParamsForTemplate,
@@ -129,11 +136,14 @@ var import_randomId = require("./randomId");
129
136
  createCollectionContextMeta,
130
137
  createCurrentRecordMetaFactory,
131
138
  createEphemeralContext,
139
+ createOpenViewRouteState,
132
140
  createRecordMetaFactory,
133
141
  createRecordResolveOnServerWithLocal,
134
142
  decodeBase64Url,
143
+ decodeOpenViewRouteState,
135
144
  defineAction,
136
145
  encodeBase64Url,
146
+ encodeOpenViewRouteState,
137
147
  escapeT,
138
148
  extractPropertyPath,
139
149
  extractUsedVariableNames,
@@ -149,6 +159,7 @@ var import_randomId = require("./randomId");
149
159
  isCtxDateExpression,
150
160
  isCtxDatePathPrefix,
151
161
  isInheritedFrom,
162
+ isOpenViewRouteStateToken,
152
163
  isRunJSValue,
153
164
  isVariableExpression,
154
165
  normalizeRunJSValue,
@@ -0,0 +1,28 @@
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
+ declare const OPEN_VIEW_ROUTE_MODES: readonly ["drawer", "dialog", "embed"];
10
+ declare const OPEN_VIEW_ROUTE_SIZES: readonly ["small", "medium", "large"];
11
+ export type OpenViewRouteMode = (typeof OPEN_VIEW_ROUTE_MODES)[number];
12
+ export type OpenViewRouteSize = (typeof OPEN_VIEW_ROUTE_SIZES)[number];
13
+ export type OpenViewRouteState = {
14
+ mode?: OpenViewRouteMode;
15
+ size?: OpenViewRouteSize;
16
+ };
17
+ export declare const RUNJS_OPEN_VIEW_ROUTE_STATE: unique symbol;
18
+ export declare function createOpenViewRouteState(input?: {
19
+ mode?: unknown;
20
+ size?: unknown;
21
+ }): OpenViewRouteState | undefined;
22
+ export declare function isOpenViewRouteStateToken(value: unknown): value is string;
23
+ export declare function encodeOpenViewRouteState(viewUid: string, input?: {
24
+ mode?: unknown;
25
+ size?: unknown;
26
+ }): string;
27
+ export declare function decodeOpenViewRouteState(viewUid: string, token: unknown): OpenViewRouteState;
28
+ export {};
@@ -0,0 +1,125 @@
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
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var openViewRouteState_exports = {};
29
+ __export(openViewRouteState_exports, {
30
+ RUNJS_OPEN_VIEW_ROUTE_STATE: () => RUNJS_OPEN_VIEW_ROUTE_STATE,
31
+ createOpenViewRouteState: () => createOpenViewRouteState,
32
+ decodeOpenViewRouteState: () => decodeOpenViewRouteState,
33
+ encodeOpenViewRouteState: () => encodeOpenViewRouteState,
34
+ isOpenViewRouteStateToken: () => isOpenViewRouteStateToken
35
+ });
36
+ module.exports = __toCommonJS(openViewRouteState_exports);
37
+ const OPEN_VIEW_ROUTE_MODES = ["drawer", "dialog", "embed"];
38
+ const OPEN_VIEW_ROUTE_SIZES = ["small", "medium", "large"];
39
+ const OPEN_VIEW_ROUTE_STATE_TOKEN_ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
40
+ const OPEN_VIEW_ROUTE_STATE_TOKEN_LENGTH = 8;
41
+ const RUNJS_OPEN_VIEW_ROUTE_STATE = Symbol.for("nocobase.runjs.openViewRouteState");
42
+ function isOpenViewRouteMode(value) {
43
+ return typeof value === "string" && OPEN_VIEW_ROUTE_MODES.includes(value);
44
+ }
45
+ __name(isOpenViewRouteMode, "isOpenViewRouteMode");
46
+ function isOpenViewRouteSize(value) {
47
+ return typeof value === "string" && OPEN_VIEW_ROUTE_SIZES.includes(value);
48
+ }
49
+ __name(isOpenViewRouteSize, "isOpenViewRouteSize");
50
+ function createOpenViewRouteState(input) {
51
+ const state = {};
52
+ if (isOpenViewRouteMode(input == null ? void 0 : input.mode)) {
53
+ state.mode = input.mode;
54
+ }
55
+ if (isOpenViewRouteSize(input == null ? void 0 : input.size)) {
56
+ state.size = input.size;
57
+ }
58
+ return state.mode || state.size ? state : void 0;
59
+ }
60
+ __name(createOpenViewRouteState, "createOpenViewRouteState");
61
+ function hashString(value) {
62
+ let hash = 2166136261;
63
+ for (let i = 0; i < value.length; i++) {
64
+ hash ^= value.charCodeAt(i);
65
+ hash = Math.imul(hash, 16777619);
66
+ }
67
+ return hash >>> 0;
68
+ }
69
+ __name(hashString, "hashString");
70
+ function stateToCode(state) {
71
+ const modeIndex = state.mode ? OPEN_VIEW_ROUTE_MODES.indexOf(state.mode) + 1 : 0;
72
+ const sizeIndex = state.size ? OPEN_VIEW_ROUTE_SIZES.indexOf(state.size) + 1 : 0;
73
+ const code = modeIndex * 4 + sizeIndex;
74
+ return code > 0 ? code : void 0;
75
+ }
76
+ __name(stateToCode, "stateToCode");
77
+ function codeToState(code) {
78
+ const modeIndex = Math.floor(code / 4);
79
+ const sizeIndex = code % 4;
80
+ return createOpenViewRouteState({
81
+ mode: modeIndex ? OPEN_VIEW_ROUTE_MODES[modeIndex - 1] : void 0,
82
+ size: sizeIndex ? OPEN_VIEW_ROUTE_SIZES[sizeIndex - 1] : void 0
83
+ });
84
+ }
85
+ __name(codeToState, "codeToState");
86
+ function tokenForCode(viewUid, code) {
87
+ let seed = hashString(`${viewUid}:${code}`);
88
+ let token = "";
89
+ for (let i = 0; i < OPEN_VIEW_ROUTE_STATE_TOKEN_LENGTH; i++) {
90
+ seed = Math.imul(seed ^ code + i * 17, 16777619) >>> 0;
91
+ token += OPEN_VIEW_ROUTE_STATE_TOKEN_ALPHABET[seed % OPEN_VIEW_ROUTE_STATE_TOKEN_ALPHABET.length];
92
+ }
93
+ return token;
94
+ }
95
+ __name(tokenForCode, "tokenForCode");
96
+ function isOpenViewRouteStateToken(value) {
97
+ return typeof value === "string" && value.length === OPEN_VIEW_ROUTE_STATE_TOKEN_LENGTH && [...value].every((char) => OPEN_VIEW_ROUTE_STATE_TOKEN_ALPHABET.includes(char));
98
+ }
99
+ __name(isOpenViewRouteStateToken, "isOpenViewRouteStateToken");
100
+ function encodeOpenViewRouteState(viewUid, input) {
101
+ const state = createOpenViewRouteState(input);
102
+ const code = state ? stateToCode(state) : void 0;
103
+ return code ? tokenForCode(viewUid, code) : void 0;
104
+ }
105
+ __name(encodeOpenViewRouteState, "encodeOpenViewRouteState");
106
+ function decodeOpenViewRouteState(viewUid, token) {
107
+ if (!isOpenViewRouteStateToken(token)) {
108
+ return void 0;
109
+ }
110
+ for (let code = 1; code < 16; code++) {
111
+ if (tokenForCode(viewUid, code) === token) {
112
+ return codeToState(code);
113
+ }
114
+ }
115
+ return void 0;
116
+ }
117
+ __name(decodeOpenViewRouteState, "decodeOpenViewRouteState");
118
+ // Annotate the CommonJS export names for ESM import in node:
119
+ 0 && (module.exports = {
120
+ RUNJS_OPEN_VIEW_ROUTE_STATE,
121
+ createOpenViewRouteState,
122
+ decodeOpenViewRouteState,
123
+ encodeOpenViewRouteState,
124
+ isOpenViewRouteStateToken
125
+ });
@@ -6,6 +6,7 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
+ import { type OpenViewRouteState } from './openViewRouteState';
9
10
  export interface ViewParam {
10
11
  /** 视图唯一标识符,一般为某个 Model 实例的 uid */
11
12
  viewUid: string;
@@ -15,6 +16,8 @@ export interface ViewParam {
15
16
  filterByTk?: string | Record<string, string | number>;
16
17
  /** source Id */
17
18
  sourceId?: string;
19
+ /** RunJS ctx.openView runtime display overrides decoded from URL. */
20
+ openViewRouteState?: OpenViewRouteState;
18
21
  }
19
22
  export interface ParsePathnameToViewParamsOptions {
20
23
  rootPrefix?: string;
@@ -30,6 +30,7 @@ __export(parsePathnameToViewParams_exports, {
30
30
  parsePathnameToViewParams: () => parsePathnameToViewParams
31
31
  });
32
32
  module.exports = __toCommonJS(parsePathnameToViewParams_exports);
33
+ var import_openViewRouteState = require("./openViewRouteState");
33
34
  const normalizePathname = /* @__PURE__ */ __name((pathname) => {
34
35
  if (!pathname || pathname === "/") {
35
36
  return "/";
@@ -77,7 +78,23 @@ const parsePathnameToViewParams = /* @__PURE__ */ __name((pathname, options = {}
77
78
  } else {
78
79
  break;
79
80
  }
80
- } else if (currentView && i + 1 < segments.length) {
81
+ } else if (currentView) {
82
+ if (segment === "opts") {
83
+ if (i + 1 < segments.length) {
84
+ const routeState = (0, import_openViewRouteState.decodeOpenViewRouteState)(currentView.viewUid, segments[i + 1]);
85
+ if (routeState) {
86
+ currentView.openViewRouteState = routeState;
87
+ }
88
+ i += 2;
89
+ } else {
90
+ i++;
91
+ }
92
+ continue;
93
+ }
94
+ if (i + 1 >= segments.length) {
95
+ i++;
96
+ continue;
97
+ }
81
98
  const rawValue = segments[i + 1];
82
99
  let decoded = rawValue;
83
100
  try {
@@ -32,6 +32,7 @@ __export(ViewNavigation_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(ViewNavigation_exports);
34
34
  var import_reactive = require("../reactive");
35
+ var import_utils = require("../utils");
35
36
  function encodeFilterByTk(val) {
36
37
  if (val === void 0 || val === null) return "";
37
38
  if (val && typeof val === "object" && !Array.isArray(val)) {
@@ -63,6 +64,10 @@ function generatePathnameFromViewParams(viewParams, options = {}) {
63
64
  segments.push("view");
64
65
  }
65
66
  segments.push(viewParam.viewUid);
67
+ const openViewRouteStateToken = (0, import_utils.encodeOpenViewRouteState)(viewParam.viewUid, viewParam.openViewRouteState);
68
+ if (openViewRouteStateToken) {
69
+ segments.push("opts", openViewRouteStateToken);
70
+ }
66
71
  if (viewParam.tabUid) {
67
72
  segments.push("tab", viewParam.tabUid);
68
73
  }