UNPKG

@nocobase/flow-engine

Version:

A standalone flow engine for NocoBase, managing workflows, models, and actions.

172 lines (170 loc) 6.96 kB
/** * This file is part of the NocoBase (R) project. * Copyright (c) 2020-2024 NocoBase Co., Ltd. * Authors: NocoBase Team. * * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. * For more information, please refer to: https://www.nocobase.com/agreement. */ var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var createViewMeta_exports = {}; __export(createViewMeta_exports, { createViewMeta: () => createViewMeta }); module.exports = __toCommonJS(createViewMeta_exports); var import_variablesParams = require("../utils/variablesParams"); function isPlainObject(val) { if (val === null || typeof val !== "object") return false; const proto = Object.getPrototypeOf(val); return proto === Object.prototype || proto === null; } __name(isPlainObject, "isPlainObject"); function makeMetaFromValue(value, title, seen) { const t = typeof value; if (value === null || value === void 0) return { type: "any", title }; if (Array.isArray(value)) { return { type: "array", title, properties: /* @__PURE__ */ __name(async () => { const max = Math.min(value.length || 0, 10); const children = {}; const nextSeen = seen ?? /* @__PURE__ */ new WeakSet(); for (let i = 0; i < max; i++) { children[String(i)] = makeMetaFromValue(value[i], `#${i}`, nextSeen); } return children; }, "properties") }; } if (t === "string") return { type: "string", title }; if (t === "number") return { type: "number", title }; if (t === "boolean") return { type: "boolean", title }; if (t === "object" && isPlainObject(value)) { return { type: "object", title, properties: /* @__PURE__ */ __name(async () => { const nextSeen = seen ?? /* @__PURE__ */ new WeakSet(); if (nextSeen.has(value)) { return {}; } nextSeen.add(value); const props = {}; Object.keys(value || {}).forEach((k) => { props[k] = makeMetaFromValue(value[k], k, nextSeen); }); return props; }, "properties") }; } return { type: "any", title }; } __name(makeMetaFromValue, "makeMetaFromValue"); function buildNavigationMeta(ctx, getView) { const t = /* @__PURE__ */ __name((key) => { var _a; return ((_a = ctx == null ? void 0 : ctx.t) == null ? void 0 : _a.call(ctx, key)) || key; }, "t"); return { type: "object", title: t("\u5BFC\u822A"), properties: /* @__PURE__ */ __name(async () => { const view = getView(); const nav = view == null ? void 0 : view.navigation; const props = {}; const stack = Array.isArray(nav == null ? void 0 : nav.viewStack) ? nav.viewStack : []; const stackMeta = { type: "array", title: t("\u89C6\u56FE\u5806\u6808"), properties: void 0 }; if (stack.length) { const children = {}; const max = Math.min(stack.length, 20); for (let i = 0; i < max; i++) { const item = stack[i] || {}; children[String(i)] = { type: "object", title: `#${i}`, properties: { viewUid: { type: "string", title: "viewUid" }, tabUid: { type: "string", title: "tabUid" }, filterByTk: { type: "string", title: "filterByTk" }, sourceId: { type: "string", title: "sourceId" } } }; } stackMeta.properties = children; } props.viewStack = stackMeta; return props; }, "properties") }; } __name(buildNavigationMeta, "buildNavigationMeta"); function createViewMeta(ctx, getView) { var _a; const viewTitle = ((_a = ctx == null ? void 0 : ctx.t) == null ? void 0 : _a.call(ctx, "\u5F53\u524D\u89C6\u56FE")) || "\u5F53\u524D\u89C6\u56FE"; const factory = /* @__PURE__ */ __name(async () => { var _a2; const recordMeta = await (0, import_variablesParams.buildRecordMeta)( () => { var _a3, _b, _c, _d; try { const ref = (0, import_variablesParams.inferRecordRef)(ctx); if (!(ref == null ? void 0 : ref.collection)) return null; const ds = (_b = (_a3 = ctx.dataSourceManager) == null ? void 0 : _a3.getDataSource) == null ? void 0 : _b.call(_a3, ref.dataSourceKey || "main"); return ((_d = (_c = ds == null ? void 0 : ds.collectionManager) == null ? void 0 : _c.getCollection) == null ? void 0 : _d.call(_c, ref.collection)) || null; } catch (e) { return null; } }, ((_a2 = ctx == null ? void 0 : ctx.t) == null ? void 0 : _a2.call(ctx, "\u5F53\u524D\u89C6\u56FE\u8BB0\u5F55")) || "\u5F53\u524D\u89C6\u56FE\u8BB0\u5F55", (c) => (0, import_variablesParams.inferRecordRef)(c) ); const view = getView(); return { type: "object", title: viewTitle, buildVariablesParams: /* @__PURE__ */ __name((c) => { const ref = (0, import_variablesParams.inferRecordRef)(c); return ref ? { record: ref } : void 0; }, "buildVariablesParams"), properties: /* @__PURE__ */ __name(async () => { var _a3, _b, _c; const props = {}; if (recordMeta) props.record = recordMeta; props.type = { type: "string", title: ((_a3 = ctx == null ? void 0 : ctx.t) == null ? void 0 : _a3.call(ctx, "\u7C7B\u578B")) || "\u7C7B\u578B" }; props.preventClose = { type: "boolean", title: ((_b = ctx == null ? void 0 : ctx.t) == null ? void 0 : _b.call(ctx, "\u662F\u5426\u5141\u8BB8\u5173\u95ED")) || "\u662F\u5426\u5141\u8BB8\u5173\u95ED" }; props.inputArgs = makeMetaFromValue(view == null ? void 0 : view.inputArgs, ((_c = ctx == null ? void 0 : ctx.t) == null ? void 0 : _c.call(ctx, "\u8F93\u5165\u53C2\u6570")) || "\u8F93\u5165\u53C2\u6570"); props.navigation = buildNavigationMeta(ctx, getView); return props; }, "properties") }; }, "factory"); factory.title = viewTitle; return factory; } __name(createViewMeta, "createViewMeta"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createViewMeta });