@nocobase/flow-engine 2.0.0-beta.13 → 2.0.0-beta.14

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.
@@ -57,7 +57,6 @@ __export(flowContext_exports, {
57
57
  module.exports = __toCommonJS(flowContext_exports);
58
58
  var import_reactive = require("@formily/reactive");
59
59
  var antd = __toESM(require("antd"));
60
- var antdIcons = __toESM(require("@ant-design/icons"));
61
60
  var import_lodash = __toESM(require("lodash"));
62
61
  var import_qs = __toESM(require("qs"));
63
62
  var import_react = __toESM(require("react"));
@@ -78,6 +77,7 @@ var import_variablesParams = require("./utils/variablesParams");
78
77
  var import_registry = require("./runjs-context/registry");
79
78
  var import_createEphemeralContext = require("./utils/createEphemeralContext");
80
79
  var import_dayjs = __toESM(require("dayjs"));
80
+ var import_runjsLibs = require("./runjsLibs");
81
81
  var _proxy, _FlowContext_instances, createChildNodes_fn, findMetaByPath_fn, findMetaInDelegatesDeep_fn, findMetaInProperty_fn, resolvePathInMeta_fn, resolvePathInMetaAsync_fn, buildParentTitles_fn, toTreeNode_fn;
82
82
  function isRecordRefLike(val) {
83
83
  return !!(val && typeof val === "object" && "collection" in val && "filterByTk" in val);
@@ -1390,14 +1390,7 @@ const _FlowRunJSContext = class _FlowRunJSContext extends FlowContext {
1390
1390
  }, "createRoot")
1391
1391
  };
1392
1392
  this.defineProperty("ReactDOM", { value: ReactDOMShim });
1393
- const libs = Object.freeze({
1394
- React: import_react.default,
1395
- ReactDOM: ReactDOMShim,
1396
- antd,
1397
- dayjs: import_dayjs.default,
1398
- antdIcons
1399
- });
1400
- this.defineProperty("libs", { value: libs });
1393
+ (0, import_runjsLibs.setupRunJSLibs)(this);
1401
1394
  this.defineMethod(
1402
1395
  "render",
1403
1396
  function(vnode, container) {
@@ -63,6 +63,7 @@ var import__ = require(".");
63
63
  var import_useFlowSettingsContext = require("./hooks/useFlowSettingsContext");
64
64
  var import_utils = require("./utils");
65
65
  var import_useFlowStep = require("./hooks/useFlowStep");
66
+ var import_views = require("./views");
66
67
  var _forceEnabled, _emitter;
67
68
  const Panel = import_antd.Collapse.Panel;
68
69
  const _FlowSettings = class _FlowSettings {
@@ -536,12 +537,9 @@ const _FlowSettings = class _FlowSettings {
536
537
  };
537
538
  let modeProps = typeof resolvedUiMode === "object" && resolvedUiMode ? resolvedUiMode.props || {} : {};
538
539
  if (modeType === "embed") {
539
- const target = document.querySelector("#nocobase-embed-container");
540
+ const target = document.querySelector(`#${import_views.GLOBAL_EMBED_CONTAINER_ID}`);
540
541
  const onOpen = modeProps.onOpen;
541
542
  const onClose = modeProps.onClose;
542
- if (target) {
543
- target.innerHTML = "";
544
- }
545
543
  modeProps = {
546
544
  target,
547
545
  styles: {
@@ -551,15 +549,19 @@ const _FlowSettings = class _FlowSettings {
551
549
  },
552
550
  ...modeProps,
553
551
  onOpen() {
554
- target.style.width = modeProps.width || "33.3%";
555
- target.style.maxWidth = modeProps.maxWidth || "800px";
556
- target.style.minWidth = modeProps.minWidth || "0px";
552
+ if (target) {
553
+ target.style.width = modeProps.width || "33.3%";
554
+ target.style.maxWidth = modeProps.maxWidth || "800px";
555
+ target.style.minWidth = modeProps.minWidth || "0px";
556
+ }
557
557
  onOpen == null ? void 0 : onOpen();
558
558
  },
559
559
  onClose() {
560
- target.style.width = "auto";
561
- target.style.maxWidth = "none";
562
- target.style.minWidth = "auto";
560
+ if (target && target.dataset[import_views.EMBED_REPLACING_DATA_KEY] !== "1") {
561
+ target.style.width = "auto";
562
+ target.style.maxWidth = "none";
563
+ target.style.minWidth = "auto";
564
+ }
563
565
  onClose == null ? void 0 : onClose();
564
566
  }
565
567
  };
package/lib/index.d.ts CHANGED
@@ -9,6 +9,8 @@
9
9
  export * from './types';
10
10
  export * from './utils';
11
11
  export { compileRunJs } from './utils/jsxTransform';
12
+ export { registerRunJSLib } from './runjsLibs';
13
+ export type { RunJSLibCache, RunJSLibLoader } from './runjsLibs';
12
14
  export * from './resources';
13
15
  export * from './flowEngine';
14
16
  export * from './hooks';
package/lib/index.js CHANGED
@@ -38,12 +38,14 @@ __export(src_exports, {
38
38
  getRunJSScenesForModel: () => import_helpers.getRunJSScenesForModel,
39
39
  getSnippetBody: () => import_snippets.getSnippetBody,
40
40
  listSnippetsForContext: () => import_snippets.listSnippetsForContext,
41
+ registerRunJSLib: () => import_runjsLibs.registerRunJSLib,
41
42
  setupRunJSContexts: () => import_setup.setupRunJSContexts
42
43
  });
43
44
  module.exports = __toCommonJS(src_exports);
44
45
  __reExport(src_exports, require("./types"), module.exports);
45
46
  __reExport(src_exports, require("./utils"), module.exports);
46
47
  var import_jsxTransform = require("./utils/jsxTransform");
48
+ var import_runjsLibs = require("./runjsLibs");
47
49
  __reExport(src_exports, require("./resources"), module.exports);
48
50
  __reExport(src_exports, require("./flowEngine"), module.exports);
49
51
  __reExport(src_exports, require("./hooks"), module.exports);
@@ -78,6 +80,7 @@ var import_BlockScopedFlowEngine = require("./BlockScopedFlowEngine");
78
80
  getRunJSScenesForModel,
79
81
  getSnippetBody,
80
82
  listSnippetsForContext,
83
+ registerRunJSLib,
81
84
  setupRunJSContexts,
82
85
  ...require("./types"),
83
86
  ...require("./utils"),
@@ -67,14 +67,17 @@ function defineBaseContextMeta() {
67
67
  ReactDOM: "ReactDOM client API including createRoot for rendering React components. Also available via `ctx.libs.ReactDOM`.",
68
68
  antd: "Ant Design component library. Recommended access path: `ctx.libs.antd`.",
69
69
  libs: {
70
- description: "Namespace for third-party and shared libraries. Includes React, ReactDOM, Ant Design, and dayjs.",
70
+ description: "Namespace for third-party and shared libraries. Includes React, ReactDOM, Ant Design, dayjs, lodash, math.js, and formula.js.",
71
71
  detail: "Libraries namespace",
72
72
  properties: {
73
73
  React: "React namespace (same as ctx.React).",
74
74
  ReactDOM: "ReactDOM client API (same as ctx.ReactDOM).",
75
75
  antd: "Ant Design component library (same as ctx.antd).",
76
76
  dayjs: "dayjs date-time utility library.",
77
- antdIcons: "Ant Design icons library. Example: `ctx.libs.antdIcons.PlusOutlined`."
77
+ antdIcons: "Ant Design icons library. Example: `ctx.libs.antdIcons.PlusOutlined`.",
78
+ lodash: 'Lodash utility library. Example: `ctx.libs.lodash.get(obj, "a.b.c")`.',
79
+ math: 'Math.js library for mathematical operations. Example: `ctx.libs.math.evaluate("2 + 3 * 4")`.',
80
+ formula: "Formula.js library for spreadsheet-like formulas. Example: `ctx.libs.formula.SUM([1, 2, 3])`."
78
81
  }
79
82
  }
80
83
  },
@@ -156,14 +159,17 @@ function defineBaseContextMeta() {
156
159
  ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF0C\u542B createRoot \u7B49\u6E32\u67D3\u65B9\u6CD5\u3002\u63A8\u8350\u901A\u8FC7 `ctx.libs.ReactDOM` \u8BBF\u95EE\u3002",
157
160
  antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08RunJS \u73AF\u5883\u4E2D\u53EF\u7528\uFF09\u3002\u63A8\u8350\u4F7F\u7528 `ctx.libs.antd` \u8BBF\u95EE\u3002",
158
161
  libs: {
159
- description: "\u7B2C\u4E09\u65B9/\u901A\u7528\u5E93\u7684\u7EDF\u4E00\u547D\u540D\u7A7A\u95F4\uFF0C\u5305\u542B React\u3001ReactDOM\u3001Ant Design\u3001dayjs \u7B49\u3002\u540E\u7EED\u65B0\u589E\u5E93\u4F1A\u4F18\u5148\u6302\u5728\u6B64\u5904\u3002",
162
+ description: "\u7B2C\u4E09\u65B9/\u901A\u7528\u5E93\u7684\u7EDF\u4E00\u547D\u540D\u7A7A\u95F4\uFF0C\u5305\u542B React\u3001ReactDOM\u3001Ant Design\u3001dayjs\u3001lodash\u3001math.js\u3001formula.js \u7B49\u3002\u540E\u7EED\u65B0\u589E\u5E93\u4F1A\u4F18\u5148\u6302\u5728\u6B64\u5904\u3002",
160
163
  detail: "\u901A\u7528\u5E93\u547D\u540D\u7A7A\u95F4",
161
164
  properties: {
162
165
  React: "React \u547D\u540D\u7A7A\u95F4\uFF08\u7B49\u4EF7\u4E8E ctx.React\uFF09\u3002",
163
166
  ReactDOM: "ReactDOM \u5BA2\u6237\u7AEF API\uFF08\u7B49\u4EF7\u4E8E ctx.ReactDOM\uFF09\u3002",
164
167
  antd: "Ant Design \u7EC4\u4EF6\u5E93\uFF08\u7B49\u4EF7\u4E8E ctx.antd\uFF09\u3002",
165
168
  dayjs: "dayjs \u65E5\u671F\u65F6\u95F4\u5DE5\u5177\u5E93\u3002",
166
- antdIcons: "Ant Design \u56FE\u6807\u5E93\u3002 \u4F8B\u5982\uFF1A`ctx.libs.antdIcons.PlusOutlined`\u3002"
169
+ antdIcons: "Ant Design \u56FE\u6807\u5E93\u3002 \u4F8B\u5982\uFF1A`ctx.libs.antdIcons.PlusOutlined`\u3002",
170
+ lodash: 'Lodash \u5DE5\u5177\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.lodash.get(obj, "a.b.c")`\u3002',
171
+ math: 'Math.js \u6570\u5B66\u8FD0\u7B97\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.math.evaluate("2 + 3 * 4")`\u3002',
172
+ formula: "Formula.js \u7535\u5B50\u8868\u683C\u516C\u5F0F\u5E93\u3002\u4F8B\u5982\uFF1A`ctx.libs.formula.SUM([1, 2, 3])`\u3002"
167
173
  }
168
174
  }
169
175
  },
@@ -0,0 +1,15 @@
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 type { FlowContext } from './flowContext';
10
+ export type RunJSLibCache = 'global' | 'context';
11
+ export type RunJSLibLoader<T = any> = (ctx: FlowContext) => T | Promise<T>;
12
+ export declare function registerRunJSLib(name: string, loader: RunJSLibLoader, options?: {
13
+ cache?: RunJSLibCache;
14
+ }): void;
15
+ export declare function setupRunJSLibs(ctx: FlowContext): void;
@@ -0,0 +1,223 @@
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 __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var runjsLibs_exports = {};
39
+ __export(runjsLibs_exports, {
40
+ registerRunJSLib: () => registerRunJSLib,
41
+ setupRunJSLibs: () => setupRunJSLibs
42
+ });
43
+ module.exports = __toCommonJS(runjsLibs_exports);
44
+ var antdIcons = __toESM(require("@ant-design/icons"));
45
+ const __runjsLibRegistry = /* @__PURE__ */ new Map();
46
+ const __runjsLibResolvedCache = /* @__PURE__ */ new Map();
47
+ const __runjsLibPendingCache = /* @__PURE__ */ new Map();
48
+ const __runjsLibPendingByCtx = /* @__PURE__ */ new WeakMap();
49
+ function __runjsGetPendingMapForCtx(ctx) {
50
+ let m = __runjsLibPendingByCtx.get(ctx);
51
+ if (!m) {
52
+ m = /* @__PURE__ */ new Map();
53
+ __runjsLibPendingByCtx.set(ctx, m);
54
+ }
55
+ return m;
56
+ }
57
+ __name(__runjsGetPendingMapForCtx, "__runjsGetPendingMapForCtx");
58
+ function registerRunJSLib(name, loader, options) {
59
+ if (typeof name !== "string" || !name) return;
60
+ if (typeof loader !== "function") return;
61
+ __runjsLibRegistry.set(name, { loader, cache: (options == null ? void 0 : options.cache) || "global" });
62
+ __runjsLibResolvedCache.delete(name);
63
+ __runjsLibPendingCache.delete(name);
64
+ }
65
+ __name(registerRunJSLib, "registerRunJSLib");
66
+ function __runjsIsObject(val) {
67
+ return !!val && typeof val === "object";
68
+ }
69
+ __name(__runjsIsObject, "__runjsIsObject");
70
+ function __runjsHasOwn(obj, key) {
71
+ return __runjsIsObject(obj) && Object.prototype.hasOwnProperty.call(obj, key);
72
+ }
73
+ __name(__runjsHasOwn, "__runjsHasOwn");
74
+ function __runjsIsPromiseLike(val) {
75
+ if (!__runjsIsObject(val)) return false;
76
+ const then = val.then;
77
+ return typeof then === "function";
78
+ }
79
+ __name(__runjsIsPromiseLike, "__runjsIsPromiseLike");
80
+ function __runjsGetCtxValue(ctx, key) {
81
+ return ctx[key];
82
+ }
83
+ __name(__runjsGetCtxValue, "__runjsGetCtxValue");
84
+ async function __runjsEnsureLib(ctx, name) {
85
+ const libs = ctx == null ? void 0 : ctx.libs;
86
+ if (__runjsHasOwn(libs, name)) {
87
+ const existing = libs[name];
88
+ if (typeof existing !== "undefined") return existing;
89
+ }
90
+ const entry = __runjsLibRegistry.get(name);
91
+ if (!entry) return __runjsIsObject(libs) ? libs[name] : void 0;
92
+ const setLib = /* @__PURE__ */ __name((v2) => {
93
+ if (__runjsIsObject(libs)) libs[name] = v2;
94
+ }, "setLib");
95
+ if (entry.cache === "context") {
96
+ const pendingMap = __runjsGetPendingMapForCtx(ctx);
97
+ const existingPending2 = pendingMap.get(name);
98
+ if (existingPending2) {
99
+ const v3 = await existingPending2;
100
+ setLib(v3);
101
+ return v3;
102
+ }
103
+ const task2 = Promise.resolve().then(() => entry.loader(ctx)).then(
104
+ (v3) => {
105
+ pendingMap.delete(name);
106
+ return v3;
107
+ },
108
+ (err) => {
109
+ pendingMap.delete(name);
110
+ throw err;
111
+ }
112
+ );
113
+ pendingMap.set(name, task2);
114
+ const v2 = await task2;
115
+ setLib(v2);
116
+ return v2;
117
+ }
118
+ if (__runjsLibResolvedCache.has(name)) {
119
+ const v2 = __runjsLibResolvedCache.get(name);
120
+ setLib(v2);
121
+ return v2;
122
+ }
123
+ const existingPending = __runjsLibPendingCache.get(name);
124
+ if (existingPending) {
125
+ const v2 = await existingPending;
126
+ setLib(v2);
127
+ return v2;
128
+ }
129
+ const task = Promise.resolve().then(() => entry.loader(ctx)).then(
130
+ (v2) => {
131
+ __runjsLibResolvedCache.set(name, v2);
132
+ __runjsLibPendingCache.delete(name);
133
+ return v2;
134
+ },
135
+ (err) => {
136
+ __runjsLibPendingCache.delete(name);
137
+ throw err;
138
+ }
139
+ );
140
+ __runjsLibPendingCache.set(name, task);
141
+ const v = await task;
142
+ setLib(v);
143
+ return v;
144
+ }
145
+ __name(__runjsEnsureLib, "__runjsEnsureLib");
146
+ function setupRunJSLibAPIs(ctx) {
147
+ if (!ctx || typeof ctx !== "object") return;
148
+ if (typeof ctx.defineMethod !== "function") return;
149
+ ctx.defineMethod("__ensureLib", async function(name) {
150
+ if (typeof name !== "string" || !name) return void 0;
151
+ return await __runjsEnsureLib(this, name);
152
+ });
153
+ ctx.defineMethod("__ensureLibs", async function(names) {
154
+ if (!Array.isArray(names)) return;
155
+ for (const n of names) {
156
+ if (typeof n !== "string" || !n) continue;
157
+ await __runjsEnsureLib(this, n);
158
+ }
159
+ });
160
+ }
161
+ __name(setupRunJSLibAPIs, "setupRunJSLibAPIs");
162
+ const DEFAULT_RUNJS_LIBS = [
163
+ { name: "React", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "React"), "loader") },
164
+ { name: "ReactDOM", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "ReactDOM"), "loader") },
165
+ { name: "antd", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "antd"), "loader") },
166
+ { name: "dayjs", cache: "context", loader: /* @__PURE__ */ __name((ctx) => __runjsGetCtxValue(ctx, "dayjs"), "loader") },
167
+ { name: "antdIcons", cache: "global", loader: /* @__PURE__ */ __name(() => antdIcons, "loader") },
168
+ { name: "lodash", cache: "global", loader: /* @__PURE__ */ __name(() => import("lodash").then((m) => m.default || m), "loader") },
169
+ { name: "formula", cache: "global", loader: /* @__PURE__ */ __name(() => import("@formulajs/formulajs").then((m) => m.default || m), "loader") },
170
+ { name: "math", cache: "global", loader: /* @__PURE__ */ __name(() => import("mathjs").then((m) => m), "loader") }
171
+ ];
172
+ let __defaultRunJSLibsRegistered = false;
173
+ function ensureDefaultRunJSLibsRegistered() {
174
+ if (__defaultRunJSLibsRegistered) return;
175
+ __defaultRunJSLibsRegistered = true;
176
+ for (const { name, loader, cache } of DEFAULT_RUNJS_LIBS) {
177
+ if (__runjsLibRegistry.has(name)) continue;
178
+ registerRunJSLib(name, loader, { cache });
179
+ }
180
+ }
181
+ __name(ensureDefaultRunJSLibsRegistered, "ensureDefaultRunJSLibsRegistered");
182
+ function resolveRegisteredLibSync(ctx, name) {
183
+ const entry = __runjsLibRegistry.get(name);
184
+ if (!entry) return void 0;
185
+ if (entry.cache === "global" && __runjsLibResolvedCache.has(name)) {
186
+ return __runjsLibResolvedCache.get(name);
187
+ }
188
+ const v = entry.loader(ctx);
189
+ if (__runjsIsPromiseLike(v)) return void 0;
190
+ if (entry.cache === "global") __runjsLibResolvedCache.set(name, v);
191
+ return v;
192
+ }
193
+ __name(resolveRegisteredLibSync, "resolveRegisteredLibSync");
194
+ function setupRunJSLibs(ctx) {
195
+ if (!ctx || typeof ctx !== "object") return;
196
+ if (typeof ctx.defineProperty !== "function") return;
197
+ ensureDefaultRunJSLibsRegistered();
198
+ const libs = {};
199
+ for (const { name } of DEFAULT_RUNJS_LIBS) {
200
+ Object.defineProperty(libs, name, {
201
+ configurable: true,
202
+ enumerable: true,
203
+ get() {
204
+ const v = resolveRegisteredLibSync(ctx, name);
205
+ Object.defineProperty(libs, name, {
206
+ configurable: true,
207
+ enumerable: true,
208
+ writable: true,
209
+ value: v
210
+ });
211
+ return v;
212
+ }
213
+ });
214
+ }
215
+ ctx.defineProperty("libs", { value: libs });
216
+ setupRunJSLibAPIs(ctx);
217
+ }
218
+ __name(setupRunJSLibs, "setupRunJSLibs");
219
+ // Annotate the CommonJS export names for ESM import in node:
220
+ 0 && (module.exports = {
221
+ registerRunJSLib,
222
+ setupRunJSLibs
223
+ });