@nocobase/plugin-workflow-dynamic-calculation 0.19.0-alpha.9 → 0.20.0-alpha.2
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.
- package/dist/client/expression.d.ts +35 -3
- package/dist/client/index.js +1 -1
- package/dist/externalVersion.js +6 -6
- package/package.json +4 -3
- package/src/client/DynamicCalculation.tsx +2 -2
- package/src/client/DynamicExpression.tsx +3 -3
- package/src/client/expression.tsx +14 -14
- package/src/client/index.ts +2 -2
- package/dist/client/Provider.d.ts +0 -2
- package/src/client/Provider.tsx +0 -22
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare
|
|
3
|
-
|
|
1
|
+
import { CollectionFieldInterface } from '@nocobase/client';
|
|
2
|
+
export declare class ExpressionFieldInterface extends CollectionFieldInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
group: string;
|
|
6
|
+
order: number;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
sortable: boolean;
|
|
10
|
+
default: {
|
|
11
|
+
type: string;
|
|
12
|
+
uiSchema: {
|
|
13
|
+
'x-component': string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
properties: {
|
|
17
|
+
'uiSchema.title': {
|
|
18
|
+
type: string;
|
|
19
|
+
title: string;
|
|
20
|
+
required: boolean;
|
|
21
|
+
'x-decorator': string;
|
|
22
|
+
'x-component': string;
|
|
23
|
+
};
|
|
24
|
+
name: {
|
|
25
|
+
type: string;
|
|
26
|
+
title: string;
|
|
27
|
+
required: boolean;
|
|
28
|
+
'x-disabled': string;
|
|
29
|
+
'x-decorator': string;
|
|
30
|
+
'x-component': string;
|
|
31
|
+
'x-validator': string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@nocobase/plugin-workflow/client"),require("react-i18next"),require("@formily/core"),require("@formily/react"),require("antd"),require("react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@nocobase/plugin-workflow/client","react-i18next","@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["@nocobase/plugin-workflow"],n["react-i18next"],n["@formily/core"],n["@formily/react"],n.antd,n.react))})(this,function(n,e,o,r,m,y,p,x,u){"use strict";var W=Object.defineProperty,N=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var F=(n,e,o)=>e in n?W(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,b=(n,e)=>{for(var o in e||(e={}))L.call(e,o)&&F(n,o,e[o]);if(V)for(var o of V(e))U.call(e,o)&&F(n,o,e[o]);return n},I=(n,e)=>N(n,z(e));var i=(n,e,o)=>(F(n,typeof e!="symbol"?e+"":e,o),o);var h=(n,e,o)=>new Promise((r,m)=>{var y=u=>{try{x(o.next(u))}catch(a){m(a)}},p=u=>{try{x(o.throw(u))}catch(a){m(a)}},x=u=>u.done?r(u.value):Promise.resolve(u.value).then(y,p);x((o=o.apply(n,e)).next())});const a="workflow-dynamic-calculation";function k(s,l={}){const{t}=T(l);return t(s)}function T(s){return m.useTranslation(a,s)}function E(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(c=>c.interface==="expression"):!1}function v({value:s,onChange:l}){const{getCollectionFields:t,getCollection:c}=e.useCollectionManager_deprecated(),f=r.useWorkflowVariableOptions({types:[E.bind({getCollectionFields:t,getCollection:c})]});return o.jsx(e.Variable.Input,{value:s,onChange:l,scope:f})}class P extends r.Instruction{constructor(){super(...arguments);i(this,"title",`{{t("Dynamic Calculation", { ns: "${a}" })}}`);i(this,"type","dynamic-calculation");i(this,"group","extended");i(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}" })}}`);i(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]}}"}}}}});i(this,"components",{DynamicExpression:v,WorkflowVariableInput:r.WorkflowVariableInput,ValueBlock:r.ValueBlock})}useVariables({key:t,title:c},{types:f,fieldNames:d=r.defaultFieldNames}){return f&&!f.some(g=>g in r.BaseTypeSets||Object.values(r.BaseTypeSets).some(C=>C.has(g)))?null:{[d.value]:t,[d.label]:c}}useInitializers(t){var c;return{name:`#${t.id}`,type:"item",title:(c=t.title)!=null?c:`#${t.id}`,Component:r.ValueBlock.Initializer,node:t,resultTitle:k("Calculation result")}}}const q=p.observer(s=>{const{onChange:l}=s,t=p.useField(),c=p.useForm(),d=[...t.path.segments.slice(0,-1),"sourceCollection"].join("."),[g,C]=u.useState(c.getValuesIn(d)),A=e.useCompile(),{getCollectionFields:B}=e.useCollectionManager_deprecated();p.useFormEffects(()=>{y.onFormInitialValuesChange(w=>{C(w.getValuesIn(d))}),y.onFieldInputValueChange(d,w=>{C(w.value),l(null)})});const _=r.getCollectionFieldOptions({collection:g,compile:A,getCollectionFields:B});return o.jsx(e.Variable.TextArea,I(b({},s),{scope:_}))},{displayName:"InternalExpression"});function M(s){const{t:l}=m.useTranslation(),t=e.useRecord(),c=e.useCompile(),{getCollectionFields:f}=e.useCollectionManager_deprecated(),d=u.useMemo(()=>r.getCollectionFieldOptions({collection:t.sourceCollection,compile:c,getCollectionFields:f}),[t.sourceCollection,t.sourceCollection]);return s.value?o.jsx(e.Variable.TextArea,I(b({},s),{scope:d})):o.jsx(x.Tag,{children:l("Unconfigured",{ns:a})})}const S=p.connect(q,p.mapReadPretty(M)),{defaultProps:j}=e.interfacesProperties;class D extends e.CollectionFieldInterface{constructor(){super(...arguments);i(this,"name","expression");i(this,"type","string");i(this,"group","advanced");i(this,"order",1);i(this,"title",`{{t("Expression", { ns: "${a}" })}}`);i(this,"description",`{{t("Used to store expressions for use in workflows so that different expressions can be called for different data.", { ns: "${a}" })}}`);i(this,"sortable",!0);i(this,"default",{type:"text",uiSchema:{"x-component":"DynamicExpression"}});i(this,"properties",b({},j))}}class O extends e.Plugin{afterAdd(){return h(this,null,function*(){})}beforeLoad(){return h(this,null,function*(){})}load(){return h(this,null,function*(){this.app.dataSourceManager.addFieldInterfaces([D]),this.app.addComponents({DynamicExpression:S});const l=this.app.pm.get("workflow"),t=new P;l.instructions.register(t.type,t)})}}n.default=O,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
"react": "18.2.0",
|
|
3
|
-
"@nocobase/client": "0.
|
|
4
|
-
"@nocobase/plugin-workflow": "0.
|
|
3
|
+
"@nocobase/client": "0.20.0-alpha.2",
|
|
4
|
+
"@nocobase/plugin-workflow": "0.20.0-alpha.2",
|
|
5
5
|
"@formily/core": "2.3.0",
|
|
6
6
|
"@formily/react": "2.3.0",
|
|
7
7
|
"antd": "5.12.8",
|
|
8
8
|
"react-i18next": "11.18.6",
|
|
9
|
-
"@nocobase/utils": "0.
|
|
10
|
-
"@nocobase/evaluators": "0.
|
|
11
|
-
"@nocobase/server": "0.
|
|
12
|
-
"@nocobase/database": "0.
|
|
9
|
+
"@nocobase/utils": "0.20.0-alpha.2",
|
|
10
|
+
"@nocobase/evaluators": "0.20.0-alpha.2",
|
|
11
|
+
"@nocobase/server": "0.20.0-alpha.2",
|
|
12
|
+
"@nocobase/database": "0.20.0-alpha.2"
|
|
13
13
|
};
|
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.
|
|
7
|
+
"version": "0.20.0-alpha.2",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/plugins/workflow-dynamic-calculation",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"@nocobase/test": "0.x",
|
|
31
31
|
"@nocobase/utils": "0.x"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "6fb885dfc3554e4b0f29e9a7a1eecbbe85d0eebb",
|
|
34
34
|
"keywords": [
|
|
35
|
-
"Workflow"
|
|
35
|
+
"Workflow",
|
|
36
|
+
"Collections"
|
|
36
37
|
]
|
|
37
38
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { SchemaInitializerItemType, Variable,
|
|
3
|
+
import { SchemaInitializerItemType, Variable, useCollectionManager_deprecated } from '@nocobase/client';
|
|
4
4
|
import {
|
|
5
5
|
BaseTypeSets,
|
|
6
6
|
Instruction,
|
|
@@ -25,7 +25,7 @@ function useDynamicExpressionCollectionFieldMatcher(field): boolean {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function DynamicExpression({ value, onChange }) {
|
|
28
|
-
const { getCollectionFields, getCollection } =
|
|
28
|
+
const { getCollectionFields, getCollection } = useCollectionManager_deprecated();
|
|
29
29
|
const scope = useWorkflowVariableOptions({
|
|
30
30
|
types: [useDynamicExpressionCollectionFieldMatcher.bind({ getCollectionFields, getCollection })],
|
|
31
31
|
});
|
|
@@ -4,7 +4,7 @@ import { Tag } from 'antd';
|
|
|
4
4
|
import React, { useMemo, useState } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useCollectionManager_deprecated, useCompile, useRecord, Variable } from '@nocobase/client';
|
|
8
8
|
import { getCollectionFieldOptions } from '@nocobase/plugin-workflow/client';
|
|
9
9
|
|
|
10
10
|
import { NAMESPACE } from '../locale';
|
|
@@ -19,7 +19,7 @@ const InternalExpression = observer(
|
|
|
19
19
|
const collectionPath = [...basePath, 'sourceCollection'].join('.');
|
|
20
20
|
const [collection, setCollection] = useState(form.getValuesIn(collectionPath));
|
|
21
21
|
const compile = useCompile();
|
|
22
|
-
const { getCollectionFields } =
|
|
22
|
+
const { getCollectionFields } = useCollectionManager_deprecated();
|
|
23
23
|
|
|
24
24
|
useFormEffects(() => {
|
|
25
25
|
onFormInitialValuesChange((form) => {
|
|
@@ -42,7 +42,7 @@ function Result(props) {
|
|
|
42
42
|
const { t } = useTranslation();
|
|
43
43
|
const values = useRecord();
|
|
44
44
|
const compile = useCompile();
|
|
45
|
-
const { getCollectionFields } =
|
|
45
|
+
const { getCollectionFields } = useCollectionManager_deprecated();
|
|
46
46
|
const options = useMemo(
|
|
47
47
|
() => getCollectionFieldOptions({ collection: values.sourceCollection, compile, getCollectionFields }),
|
|
48
48
|
[values.sourceCollection, values.sourceCollection],
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CollectionFieldInterface, interfacesProperties } from '@nocobase/client';
|
|
2
2
|
|
|
3
3
|
import { NAMESPACE } from '../locale';
|
|
4
4
|
|
|
5
5
|
const { defaultProps } = interfacesProperties;
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
name
|
|
9
|
-
type
|
|
10
|
-
group
|
|
11
|
-
order
|
|
12
|
-
title
|
|
13
|
-
description
|
|
14
|
-
sortable
|
|
15
|
-
default
|
|
7
|
+
export class ExpressionFieldInterface extends CollectionFieldInterface {
|
|
8
|
+
name = 'expression';
|
|
9
|
+
type = 'string';
|
|
10
|
+
group = 'advanced';
|
|
11
|
+
order = 1;
|
|
12
|
+
title = `{{t("Expression", { ns: "${NAMESPACE}" })}}`;
|
|
13
|
+
description = `{{t("Used to store expressions for use in workflows so that different expressions can be called for different data.", { ns: "${NAMESPACE}" })}}`;
|
|
14
|
+
sortable = true;
|
|
15
|
+
default = {
|
|
16
16
|
type: 'text',
|
|
17
17
|
uiSchema: {
|
|
18
18
|
'x-component': 'DynamicExpression',
|
|
19
19
|
},
|
|
20
|
-
}
|
|
21
|
-
properties
|
|
20
|
+
};
|
|
21
|
+
properties = {
|
|
22
22
|
...defaultProps,
|
|
23
|
-
}
|
|
24
|
-
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/src/client/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Plugin } from '@nocobase/client';
|
|
2
2
|
import WorkflowPlugin from '@nocobase/plugin-workflow/client';
|
|
3
3
|
|
|
4
|
-
import { Provider } from './Provider';
|
|
5
4
|
import DynamicCalculation from './DynamicCalculation';
|
|
6
5
|
import { DynamicExpression } from './DynamicExpression';
|
|
6
|
+
import { ExpressionFieldInterface } from './expression';
|
|
7
7
|
|
|
8
8
|
export default class extends Plugin {
|
|
9
9
|
async afterAdd() {
|
|
@@ -14,7 +14,7 @@ export default class extends Plugin {
|
|
|
14
14
|
|
|
15
15
|
// You can get and modify the app instance here
|
|
16
16
|
async load() {
|
|
17
|
-
this.app.
|
|
17
|
+
this.app.dataSourceManager.addFieldInterfaces([ExpressionFieldInterface]);
|
|
18
18
|
this.app.addComponents({
|
|
19
19
|
DynamicExpression,
|
|
20
20
|
});
|
package/src/client/Provider.tsx
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
import { CollectionManagerContext, useCollectionManager } from '@nocobase/client';
|
|
4
|
-
|
|
5
|
-
import expression from './expression';
|
|
6
|
-
|
|
7
|
-
export function Provider(props) {
|
|
8
|
-
const cmCtx = useCollectionManager();
|
|
9
|
-
return (
|
|
10
|
-
<CollectionManagerContext.Provider
|
|
11
|
-
value={{
|
|
12
|
-
...cmCtx,
|
|
13
|
-
interfaces: {
|
|
14
|
-
...cmCtx.interfaces,
|
|
15
|
-
expression,
|
|
16
|
-
},
|
|
17
|
-
}}
|
|
18
|
-
>
|
|
19
|
-
{props.children}
|
|
20
|
-
</CollectionManagerContext.Provider>
|
|
21
|
-
);
|
|
22
|
-
}
|