@nocobase/plugin-workflow-dynamic-calculation 0.18.0-alpha.1 → 0.18.0-alpha.9

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.
@@ -3,5 +3,4 @@ export default class extends Plugin {
3
3
  afterAdd(): Promise<void>;
4
4
  beforeLoad(): Promise<void>;
5
5
  load(): Promise<void>;
6
- addComponents(): void;
7
6
  }
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("react-i18next"),require("@nocobase/plugin-workflow/client"),require("@formily/core"),require("@formily/react"),require("antd"),require("react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","react-i18next","@nocobase/plugin-workflow/client","@formily/core","@formily/react","antd","react"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-workflow-dynamic-calculation"]={},n["@nocobase/client"],n.jsxRuntime,n["react-i18next"],n["@nocobase/plugin-workflow"],n["@formily/core"],n["@formily/react"],n.antd,n.react))})(this,function(n,e,o,C,r,g,u,x,c){"use strict";var z=Object.defineProperty,L=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var v=(n,e,o)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,m=(n,e)=>{for(var o in e||(e={}))U.call(e,o)&&v(n,o,e[o]);if(F)for(var o of F(e))G.call(e,o)&&v(n,o,e[o]);return n},y=(n,e)=>L(n,_(e));var f=(n,e,o)=>(v(n,typeof e!="symbol"?e+"":e,o),o);var w=(n,e,o)=>new Promise((C,r)=>{var g=c=>{try{x(o.next(c))}catch(a){r(a)}},u=c=>{try{x(o.throw(c))}catch(a){r(a)}},x=c=>c.done?C(c.value):Promise.resolve(c.value).then(g,u);x((o=o.apply(n,e)).next())});const a="workflow-dynamic-calculation";function k(s,i={}){const{t}=I(i);return t(s)}function I(s){return C.useTranslation(a,s)}const{defaultProps:T}=e.interfacesProperties,P={name:"expression",type:"string",group:"advanced",order:1,title:`{{t("Expression", { ns: "${a}" })}}`,description:`{{t("An expression for calculation in each rows", { ns: "${a}" })}}`,sortable:!0,default:{type:"text",uiSchema:{"x-component":"DynamicExpression"}},properties:m({},T)};function E(s){const i=e.useCollectionManager();return o.jsx(e.CollectionManagerContext.Provider,{value:y(m({},i),{interfaces:y(m({},i.interfaces),{expression:P})}),children:s.children})}function M(s){var t;return["belongsTo","hasOne"].includes(s.type)?((t=this.getCollection(s.collectionName))==null?void 0:t.template)==="expression"?!0:this.getCollectionFields(s.target).some(l=>l.interface==="expression"):!1}function q({value:s,onChange:i}){const{getCollectionFields:t,getCollection:l}=e.useCollectionManager(),d=r.useWorkflowVariableOptions({types:[M.bind({getCollectionFields:t,getCollection:l})]});return o.jsx(e.Variable.Input,{value:s,onChange:i,scope:d})}class j extends r.Instruction{constructor(){super(...arguments);f(this,"title",`{{t("Dynamic Calculation", { ns: "${a}" })}}`);f(this,"type","dynamic-calculation");f(this,"group","extended");f(this,"description",`{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${a}" })}}`);f(this,"fieldset",{expression:{type:"string",title:`{{t("Calculation expression", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"DynamicExpression",required:!0},scope:{type:"string",title:`{{t("Variable datasource", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"WorkflowVariableInput","x-component-props":{changeOnSelect:!0,variableOptions:{types:[{type:"reference",options:{collection:"*",entity:!0}}]}},"x-reactions":{dependencies:["expression"],fulfill:{state:{visible:"{{$deps[0]}}"}}}}});f(this,"components",{DynamicExpression:q,WorkflowVariableInput:r.WorkflowVariableInput,ValueBlock:r.ValueBlock})}useVariables({key:t,title:l},{types:d,fieldNames:p=r.defaultFieldNames}){return d&&!d.some(h=>h in r.BaseTypeSets||Object.values(r.BaseTypeSets).some(b=>b.has(h)))?null:{[p.value]:t,[p.label]:l}}useInitializers(t){var l;return{name:`#${t.id}`,type:"item",title:(l=t.title)!=null?l:`#${t.id}`,Component:r.ValueBlock.Initializer,node:t,resultTitle:k("Calculation result")}}}const D=u.observer(s=>{const{onChange:i}=s,t=u.useField(),l=u.useForm(),p=[...t.path.segments.slice(0,-1),"sourceCollection"].join("."),[h,b]=c.useState(l.getValuesIn(p)),B=e.useCompile(),{getCollectionFields:W}=e.useCollectionManager();u.useFormEffects(()=>{g.onFormInitialValuesChange(V=>{b(V.getValuesIn(p))}),g.onFieldInputValueChange(p,V=>{b(V.value),i(null)})});const N=r.getCollectionFieldOptions({collection:h,compile:B,getCollectionFields:W});return o.jsx(e.Variable.TextArea,y(m({},s),{scope:N}))},{displayName:"InternalExpression"});function O(s){const{t:i}=C.useTranslation(),t=e.useRecord(),l=e.useCompile(),{getCollectionFields:d}=e.useCollectionManager(),p=c.useMemo(()=>r.getCollectionFieldOptions({collection:t.sourceCollection,compile:l,getCollectionFields:d}),[t.sourceCollection,t.sourceCollection]);return s.value?o.jsx(e.Variable.TextArea,y(m({},s),{scope:p})):o.jsx(x.Tag,{children:i("Unconfigured",{ns:a})})}const S=u.connect(D,u.mapReadPretty(O));class A extends e.Plugin{afterAdd(){return w(this,null,function*(){})}beforeLoad(){return w(this,null,function*(){})}load(){return w(this,null,function*(){this.app.addProvider(E);const i=this.app.pm.get("workflow"),t=new j;i.instructions.register(t.type,t)})}addComponents(){this.app.addComponents({DynamicExpression:S})}}n.default=A,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("react-i18next"),require("@nocobase/plugin-workflow/client"),require("@formily/core"),require("@formily/react"),require("antd"),require("react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","react-i18next","@nocobase/plugin-workflow/client","@formily/core","@formily/react","antd","react"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-workflow-dynamic-calculation"]={},n["@nocobase/client"],n.jsxRuntime,n["react-i18next"],n["@nocobase/plugin-workflow"],n["@formily/core"],n["@formily/react"],n.antd,n.react))})(this,function(n,e,o,C,r,g,u,x,c){"use strict";var z=Object.defineProperty,L=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var v=(n,e,o)=>e in n?z(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,m=(n,e)=>{for(var o in e||(e={}))U.call(e,o)&&v(n,o,e[o]);if(F)for(var o of F(e))G.call(e,o)&&v(n,o,e[o]);return n},y=(n,e)=>L(n,_(e));var f=(n,e,o)=>(v(n,typeof e!="symbol"?e+"":e,o),o);var w=(n,e,o)=>new Promise((C,r)=>{var g=c=>{try{x(o.next(c))}catch(a){r(a)}},u=c=>{try{x(o.throw(c))}catch(a){r(a)}},x=c=>c.done?C(c.value):Promise.resolve(c.value).then(g,u);x((o=o.apply(n,e)).next())});const a="workflow-dynamic-calculation";function k(s,i={}){const{t}=I(i);return t(s)}function I(s){return C.useTranslation(a,s)}const{defaultProps:T}=e.interfacesProperties,P={name:"expression",type:"string",group:"advanced",order:1,title:`{{t("Expression", { ns: "${a}" })}}`,description:`{{t("An expression for calculation in each rows", { ns: "${a}" })}}`,sortable:!0,default:{type:"text",uiSchema:{"x-component":"DynamicExpression"}},properties:m({},T)};function E(s){const i=e.useCollectionManager();return o.jsx(e.CollectionManagerContext.Provider,{value:y(m({},i),{interfaces:y(m({},i.interfaces),{expression:P})}),children:s.children})}function M(s){var t;return["belongsTo","hasOne"].includes(s.type)?((t=this.getCollection(s.collectionName))==null?void 0:t.template)==="expression"?!0:this.getCollectionFields(s.target).some(l=>l.interface==="expression"):!1}function q({value:s,onChange:i}){const{getCollectionFields:t,getCollection:l}=e.useCollectionManager(),d=r.useWorkflowVariableOptions({types:[M.bind({getCollectionFields:t,getCollection:l})]});return o.jsx(e.Variable.Input,{value:s,onChange:i,scope:d})}class j extends r.Instruction{constructor(){super(...arguments);f(this,"title",`{{t("Dynamic Calculation", { ns: "${a}" })}}`);f(this,"type","dynamic-calculation");f(this,"group","extended");f(this,"description",`{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${a}" })}}`);f(this,"fieldset",{expression:{type:"string",title:`{{t("Calculation expression", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"DynamicExpression",required:!0},scope:{type:"string",title:`{{t("Variable datasource", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"WorkflowVariableInput","x-component-props":{changeOnSelect:!0,variableOptions:{types:[{type:"reference",options:{collection:"*",entity:!0}}]}},"x-reactions":{dependencies:["expression"],fulfill:{state:{visible:"{{$deps[0]}}"}}}}});f(this,"components",{DynamicExpression:q,WorkflowVariableInput:r.WorkflowVariableInput,ValueBlock:r.ValueBlock})}useVariables({key:t,title:l},{types:d,fieldNames:p=r.defaultFieldNames}){return d&&!d.some(h=>h in r.BaseTypeSets||Object.values(r.BaseTypeSets).some(b=>b.has(h)))?null:{[p.value]:t,[p.label]:l}}useInitializers(t){var l;return{name:`#${t.id}`,type:"item",title:(l=t.title)!=null?l:`#${t.id}`,Component:r.ValueBlock.Initializer,node:t,resultTitle:k("Calculation result")}}}const D=u.observer(s=>{const{onChange:i}=s,t=u.useField(),l=u.useForm(),p=[...t.path.segments.slice(0,-1),"sourceCollection"].join("."),[h,b]=c.useState(l.getValuesIn(p)),B=e.useCompile(),{getCollectionFields:W}=e.useCollectionManager();u.useFormEffects(()=>{g.onFormInitialValuesChange(V=>{b(V.getValuesIn(p))}),g.onFieldInputValueChange(p,V=>{b(V.value),i(null)})});const N=r.getCollectionFieldOptions({collection:h,compile:B,getCollectionFields:W});return o.jsx(e.Variable.TextArea,y(m({},s),{scope:N}))},{displayName:"InternalExpression"});function O(s){const{t:i}=C.useTranslation(),t=e.useRecord(),l=e.useCompile(),{getCollectionFields:d}=e.useCollectionManager(),p=c.useMemo(()=>r.getCollectionFieldOptions({collection:t.sourceCollection,compile:l,getCollectionFields:d}),[t.sourceCollection,t.sourceCollection]);return s.value?o.jsx(e.Variable.TextArea,y(m({},s),{scope:p})):o.jsx(x.Tag,{children:i("Unconfigured",{ns:a})})}const S=u.connect(D,u.mapReadPretty(O));class A extends e.Plugin{afterAdd(){return w(this,null,function*(){})}beforeLoad(){return w(this,null,function*(){})}load(){return w(this,null,function*(){this.app.addProvider(E),this.app.addComponents({DynamicExpression:S});const i=this.app.pm.get("workflow"),t=new j;i.instructions.register(t.type,t)})}}n.default=A,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,13 +1,13 @@
1
1
  module.exports = {
2
2
  "react": "18.2.0",
3
- "@nocobase/client": "0.18.0-alpha.1",
4
- "@nocobase/plugin-workflow": "0.18.0-alpha.1",
3
+ "@nocobase/client": "0.18.0-alpha.9",
4
+ "@nocobase/plugin-workflow": "0.18.0-alpha.9",
5
5
  "@formily/core": "2.3.0",
6
6
  "@formily/react": "2.3.0",
7
7
  "antd": "5.12.2",
8
8
  "react-i18next": "11.18.6",
9
- "@nocobase/utils": "0.18.0-alpha.1",
10
- "@nocobase/evaluators": "0.18.0-alpha.1",
11
- "@nocobase/server": "0.18.0-alpha.1",
12
- "@nocobase/database": "0.18.0-alpha.1"
9
+ "@nocobase/utils": "0.18.0-alpha.9",
10
+ "@nocobase/evaluators": "0.18.0-alpha.9",
11
+ "@nocobase/server": "0.18.0-alpha.9",
12
+ "@nocobase/database": "0.18.0-alpha.9"
13
13
  };
@@ -2,6 +2,9 @@ import { FlowNodeModel, Instruction, Processor } from '@nocobase/plugin-workflow
2
2
  export declare class DynamicCalculation extends Instruction {
3
3
  run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
4
4
  result: any;
5
- status: number;
5
+ status: 1;
6
+ } | {
7
+ result: any;
8
+ status: -2;
6
9
  }>;
7
10
  }
@@ -1,6 +1,4 @@
1
1
  import { Plugin } from '@nocobase/server';
2
- import WorkflowPlugin from '@nocobase/plugin-workflow';
3
2
  export default class extends Plugin {
4
- workflow: WorkflowPlugin;
5
3
  load(): Promise<void>;
6
4
  }
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
  var Plugin_exports = {};
19
29
  __export(Plugin_exports, {
@@ -21,16 +31,15 @@ __export(Plugin_exports, {
21
31
  });
22
32
  module.exports = __toCommonJS(Plugin_exports);
23
33
  var import_server = require("@nocobase/server");
34
+ var import_plugin_workflow = __toESM(require("@nocobase/plugin-workflow"));
24
35
  var import_expression_field = require("./expression-field");
25
36
  var import_DynamicCalculation = require("./DynamicCalculation");
26
37
  class Plugin_default extends import_server.Plugin {
27
- workflow;
28
38
  async load() {
29
39
  this.db.registerFieldTypes({
30
40
  expression: import_expression_field.ExpressionField
31
41
  });
32
- const workflowPlugin = this.app.getPlugin("workflow");
33
- this.workflow = workflowPlugin;
34
- workflowPlugin.instructions.register("dynamic-calculation", new import_DynamicCalculation.DynamicCalculation(workflowPlugin));
42
+ const workflowPlugin = this.app.getPlugin(import_plugin_workflow.default);
43
+ workflowPlugin.registerInstruction("dynamic-calculation", import_DynamicCalculation.DynamicCalculation);
35
44
  }
36
45
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:动态表达式计算节点",
5
5
  "description": "Useful plugin for doing dynamic calculation based on expression collection records in workflow.",
6
6
  "description.zh-CN": "用于在工作流中进行基于数据行的动态表达式计算。",
7
- "version": "0.18.0-alpha.1",
7
+ "version": "0.18.0-alpha.9",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "devDependencies": {
@@ -24,10 +24,9 @@
24
24
  "@nocobase/evaluators": "0.x",
25
25
  "@nocobase/plugin-collection-manager": "0.x",
26
26
  "@nocobase/plugin-workflow": ">=0.17.0-alpha.3",
27
- "@nocobase/plugin-workflow-test": ">=0.17.0-alpha.3",
28
27
  "@nocobase/server": "0.x",
29
28
  "@nocobase/test": "0.x",
30
29
  "@nocobase/utils": "0.x"
31
30
  },
32
- "gitHead": "0f5f1c0a37dc397a9dc4c8eec0c4ec20fd8107b0"
31
+ "gitHead": "34ca0df4eede2e83fc86297b0fe19eba970e2b1b"
33
32
  }
@@ -15,14 +15,11 @@ export default class extends Plugin {
15
15
  // You can get and modify the app instance here
16
16
  async load() {
17
17
  this.app.addProvider(Provider);
18
- const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
19
- const dynamicCalculation = new DynamicCalculation();
20
- workflow.instructions.register(dynamicCalculation.type, dynamicCalculation);
21
- }
22
-
23
- addComponents() {
24
18
  this.app.addComponents({
25
19
  DynamicExpression,
26
20
  });
21
+ const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
22
+ const dynamicCalculation = new DynamicCalculation();
23
+ workflow.instructions.register(dynamicCalculation.type, dynamicCalculation);
27
24
  }
28
25
  }
@@ -5,15 +5,12 @@ import { ExpressionField } from './expression-field';
5
5
  import { DynamicCalculation } from './DynamicCalculation';
6
6
 
7
7
  export default class extends Plugin {
8
- workflow: WorkflowPlugin;
9
-
10
8
  async load() {
11
9
  this.db.registerFieldTypes({
12
10
  expression: ExpressionField,
13
11
  });
14
12
 
15
- const workflowPlugin = this.app.getPlugin('workflow') as WorkflowPlugin;
16
- this.workflow = workflowPlugin;
17
- workflowPlugin.instructions.register('dynamic-calculation', new DynamicCalculation(workflowPlugin));
13
+ const workflowPlugin = this.app.getPlugin<WorkflowPlugin>(WorkflowPlugin);
14
+ workflowPlugin.registerInstruction('dynamic-calculation', DynamicCalculation);
18
15
  }
19
16
  }