@flowgram.ai/node-variable-plugin 0.5.4 → 0.5.6
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/esm/index.js +16 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +16 -9
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { useEntityFromContext } from "@flowgram.ai/core";
|
|
|
12
12
|
var PublicScopeProvider = ({ children }) => {
|
|
13
13
|
const node = useEntityFromContext();
|
|
14
14
|
const publicScope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);
|
|
15
|
-
return /* @__PURE__ */ React.createElement(ScopeProvider, {
|
|
15
|
+
return /* @__PURE__ */ React.createElement(ScopeProvider, { scope: publicScope }, children);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// src/with-node-variables.tsx
|
|
@@ -39,7 +39,7 @@ var PrivateScopeProvider = ({ children }) => {
|
|
|
39
39
|
}
|
|
40
40
|
return variableData.private;
|
|
41
41
|
}, [node]);
|
|
42
|
-
return /* @__PURE__ */ React3.createElement(ScopeProvider2, {
|
|
42
|
+
return /* @__PURE__ */ React3.createElement(ScopeProvider2, { scope: privateScope }, children);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
// src/form-v2/create-provider-effect.ts
|
|
@@ -53,19 +53,23 @@ function createEffectFromVariableProvider(options) {
|
|
|
53
53
|
}
|
|
54
54
|
return variableData.public;
|
|
55
55
|
};
|
|
56
|
-
const transformValueToAST = ({ value, name, context }) => {
|
|
56
|
+
const transformValueToAST = ({ value, name, context, formValues, form }) => {
|
|
57
57
|
if (!context) {
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const { node } = context;
|
|
61
61
|
const scope = getScope(node);
|
|
62
|
+
const parsedValue = options.parse(value, {
|
|
63
|
+
node,
|
|
64
|
+
scope,
|
|
65
|
+
options,
|
|
66
|
+
name,
|
|
67
|
+
formValues,
|
|
68
|
+
form
|
|
69
|
+
});
|
|
62
70
|
scope.ast.set(options.namespace || name || "", {
|
|
63
71
|
kind: ASTKind.VariableDeclarationList,
|
|
64
|
-
declarations:
|
|
65
|
-
node,
|
|
66
|
-
scope,
|
|
67
|
-
options
|
|
68
|
-
})
|
|
72
|
+
declarations: Array.isArray(parsedValue) ? parsedValue : [parsedValue]
|
|
69
73
|
});
|
|
70
74
|
};
|
|
71
75
|
return [
|
|
@@ -77,7 +81,10 @@ function createEffectFromVariableProvider(options) {
|
|
|
77
81
|
const disposable = options.onInit?.({
|
|
78
82
|
node: context.node,
|
|
79
83
|
scope,
|
|
80
|
-
options
|
|
84
|
+
options,
|
|
85
|
+
name: params.name,
|
|
86
|
+
formValues: params.formValues,
|
|
87
|
+
form: params.form
|
|
81
88
|
});
|
|
82
89
|
transformValueToAST(params);
|
|
83
90
|
return () => {
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/create-node-variable-plugin.ts","../../src/with-node-variables.tsx","../../src/components/PublicScopeProvider.tsx","../../src/components/PrivateScopeProvider.tsx","../../src/form-v2/create-provider-effect.ts","../../src/form-v2/create-variable-provider-plugin.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n// import { FormManager } from '@flowgram.ai/form-core';\nimport { NodeManager } from '@flowgram.ai/form-core';\nimport { definePluginCreator } from '@flowgram.ai/core';\n\nimport { withNodeVariables } from './with-node-variables';\n\n// import { withNodeVariables } from './with-node-variables';\n\nexport const createNodeVariablePlugin = definePluginCreator({\n onInit(ctx) {\n const nodeManager = ctx.get<NodeManager>(NodeManager);\n nodeManager.registerNodeRenderHoc(withNodeVariables);\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { NodeRenderHoc, type NodeRenderProps } from '@flowgram.ai/form-core';\n\nimport { PublicScopeProvider } from './components/PublicScopeProvider';\n\n// eslint-disable-next-line react/display-name\nexport const withNodeVariables: NodeRenderHoc = (Component) => (props: NodeRenderProps) =>\n (\n <PublicScopeProvider>\n <Component {...props} />\n </PublicScopeProvider>\n );\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\nexport const PublicScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const publicScope: Scope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);\n\n return <ScopeProvider
|
|
1
|
+
{"version":3,"sources":["../../src/create-node-variable-plugin.ts","../../src/with-node-variables.tsx","../../src/components/PublicScopeProvider.tsx","../../src/components/PrivateScopeProvider.tsx","../../src/form-v2/create-provider-effect.ts","../../src/form-v2/create-variable-provider-plugin.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n// import { FormManager } from '@flowgram.ai/form-core';\nimport { NodeManager } from '@flowgram.ai/form-core';\nimport { definePluginCreator } from '@flowgram.ai/core';\n\nimport { withNodeVariables } from './with-node-variables';\n\n// import { withNodeVariables } from './with-node-variables';\n\nexport const createNodeVariablePlugin = definePluginCreator({\n onInit(ctx) {\n const nodeManager = ctx.get<NodeManager>(NodeManager);\n nodeManager.registerNodeRenderHoc(withNodeVariables);\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { NodeRenderHoc, type NodeRenderProps } from '@flowgram.ai/form-core';\n\nimport { PublicScopeProvider } from './components/PublicScopeProvider';\n\n// eslint-disable-next-line react/display-name\nexport const withNodeVariables: NodeRenderHoc = (Component) => (props: NodeRenderProps) =>\n (\n <PublicScopeProvider>\n <Component {...props} />\n </PublicScopeProvider>\n );\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\n/**\n * PublicScopeProvider provides the public scope to its children via context.\n */\nexport const PublicScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const publicScope: Scope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);\n\n return <ScopeProvider scope={publicScope}>{children}</ScopeProvider>;\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\n/**\n * PrivateScopeProvider provides the private scope to its children via context.\n */\nexport const PrivateScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const privateScope: Scope = useMemo(() => {\n const variableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n if (!variableData.private) {\n variableData.initPrivate();\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return variableData.private!;\n }, [node]);\n\n return <ScopeProvider scope={privateScope}>{children}</ScopeProvider>;\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowNodeVariableData, type Scope, ASTKind } from '@flowgram.ai/variable-plugin';\nimport { DataEvent, type Effect, type EffectOptions } from '@flowgram.ai/node';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { type VariableProviderAbilityOptions } from '../types';\n\n/**\n * 根据 VariableProvider 生成 FormV2 的 Effect\n * @param options\n * @returns\n */\nexport function createEffectFromVariableProvider(\n options: VariableProviderAbilityOptions\n): EffectOptions[] {\n const getScope = (node: FlowNodeEntity): Scope => {\n const variableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n\n if (options.private || options.scope === 'private') {\n return variableData.initPrivate();\n }\n return variableData.public;\n };\n\n const transformValueToAST: Effect = ({ value, name, context, formValues, form }) => {\n if (!context) {\n return;\n }\n const { node } = context;\n const scope = getScope(node);\n\n const parsedValue = options.parse(value, {\n node,\n scope,\n options,\n name,\n formValues,\n form,\n });\n\n // Fix: When parsedValue is not an array, transform it to array\n scope.ast.set(options.namespace || name || '', {\n kind: ASTKind.VariableDeclarationList,\n declarations: Array.isArray(parsedValue) ? parsedValue : [parsedValue],\n });\n };\n\n return [\n {\n event: DataEvent.onValueInit,\n effect: ((params) => {\n const { context } = params;\n\n const scope = getScope(context.node);\n const disposable = options.onInit?.({\n node: context.node,\n scope,\n options,\n name: params.name,\n formValues: params.formValues,\n form: params.form,\n });\n\n transformValueToAST(params);\n\n return () => {\n disposable?.dispose();\n };\n }) as Effect,\n },\n {\n event: DataEvent.onValueChange,\n effect: ((params) => {\n transformValueToAST(params);\n }) as Effect,\n },\n ];\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { DataEvent, defineFormPluginCreator } from '@flowgram.ai/node';\n\nexport const createVariableProviderPlugin = defineFormPluginCreator({\n name: 'VariableProviderPlugin',\n onInit: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin init', ctx, opts);\n },\n onSetupFormMeta({ mergeEffect }) {\n mergeEffect({\n arr: [\n {\n event: DataEvent.onValueInitOrChange,\n effect: () => {\n // todo\n // console.log('>>> VariableProviderPlugin effect triggered');\n },\n },\n ],\n });\n },\n onDispose: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin dispose', ctx, opts);\n },\n});\n"],"mappings":";AAMA,SAAS,mBAAmB;AAC5B,SAAS,2BAA2B;;;ACFpC,OAAOA,YAAW;;;ACAlB,OAAO,SAAS,eAAe;AAE/B,SAAS,sBAAkC,qBAAqB;AAChE,SAAS,4BAA4B;AAS9B,IAAM,sBAAsB,CAAC,EAAE,SAAS,MAA6B;AAC1E,QAAM,OAAO,qBAAqB;AAElC,QAAM,cAAqB,QAAQ,MAAM,KAAK,QAAQ,oBAAoB,EAAE,QAAQ,CAAC,IAAI,CAAC;AAE1F,SAAO,oCAAC,iBAAc,OAAO,eAAc,QAAS;AACtD;;;ADXO,IAAM,oBAAmC,CAAC,cAAc,CAAC,UAE5D,gBAAAC,OAAA,cAAC,2BACC,gBAAAA,OAAA,cAAC,aAAW,GAAG,OAAO,CACxB;;;ADHG,IAAM,2BAA2B,oBAAoB;AAAA,EAC1D,OAAO,KAAK;AACV,UAAM,cAAc,IAAI,IAAiB,WAAW;AACpD,gBAAY,sBAAsB,iBAAiB;AAAA,EACrD;AACF,CAAC;;;AGbD,OAAOC,UAAS,WAAAC,gBAAe;AAE/B,SAAS,wBAAAC,uBAAkC,iBAAAC,sBAAqB;AAChE,SAAS,wBAAAC,6BAA4B;AAS9B,IAAM,uBAAuB,CAAC,EAAE,SAAS,MAA6B;AAC3E,QAAM,OAAOA,sBAAqB;AAElC,QAAM,eAAsBH,SAAQ,MAAM;AACxC,UAAM,eAAqC,KAAK,QAAQC,qBAAoB;AAC5E,QAAI,CAAC,aAAa,SAAS;AACzB,mBAAa,YAAY;AAAA,IAC3B;AAEA,WAAO,aAAa;AAAA,EACtB,GAAG,CAAC,IAAI,CAAC;AAET,SAAO,gBAAAF,OAAA,cAACG,gBAAA,EAAc,OAAO,gBAAe,QAAS;AACvD;;;ACzBA,SAAS,wBAAAE,uBAAkC,eAA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aAAAC,YAAW,+BAA+B;AAE5C,IAAM,+BAA+B,wBAAwB;AAAA,EAClE,MAAM;AAAA,EACN,QAAQ,CAAC,KAAK,SAAS;AAAA,EAGvB;AAAA,EACA,gBAAgB,EAAE,YAAY,GAAG;AAC/B,gBAAY;AAAA,MACV,KAAK;AAAA,QACH;AAAA,UACE,OAAOA,WAAU;AAAA,UACjB,QAAQ,MAAM;AAAA,UAGd;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,WAAW,CAAC,KAAK,SAAS;AAAA,EAG1B;AACF,CAAC;","names":["React","React","React","useMemo","FlowNodeVariableData","ScopeProvider","useEntityFromContext","FlowNodeVariableData","DataEvent"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { Scope, VariableDeclarationJSON, ASTNodeJSON } from '@flowgram.ai/variable-plugin';
|
|
3
3
|
import { Disposable } from '@flowgram.ai/utils';
|
|
4
|
+
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
5
|
+
import { EffectFuncProps, EffectOptions } from '@flowgram.ai/node';
|
|
4
6
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
5
7
|
import React from 'react';
|
|
6
|
-
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
7
|
-
import { EffectOptions } from '@flowgram.ai/node';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
@@ -21,6 +21,9 @@ interface VariableAbilityCommonContext {
|
|
|
21
21
|
node: FlowNodeEntity;
|
|
22
22
|
scope: Scope;
|
|
23
23
|
options: VariableAbilityOptions;
|
|
24
|
+
name: string;
|
|
25
|
+
formValues: EffectFuncProps['formValues'];
|
|
26
|
+
form: EffectFuncProps['form'];
|
|
24
27
|
}
|
|
25
28
|
interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
26
29
|
}
|
|
@@ -51,6 +54,9 @@ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions
|
|
|
51
54
|
interface VariableProviderProps$1 {
|
|
52
55
|
children: React.ReactElement;
|
|
53
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* PrivateScopeProvider provides the private scope to its children via context.
|
|
59
|
+
*/
|
|
54
60
|
declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
|
|
55
61
|
|
|
56
62
|
/**
|
|
@@ -61,6 +67,9 @@ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => R
|
|
|
61
67
|
interface VariableProviderProps {
|
|
62
68
|
children: React.ReactElement;
|
|
63
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* PublicScopeProvider provides the public scope to its children via context.
|
|
72
|
+
*/
|
|
64
73
|
declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
|
|
65
74
|
|
|
66
75
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { Scope, VariableDeclarationJSON, ASTNodeJSON } from '@flowgram.ai/variable-plugin';
|
|
3
3
|
import { Disposable } from '@flowgram.ai/utils';
|
|
4
|
+
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
5
|
+
import { EffectFuncProps, EffectOptions } from '@flowgram.ai/node';
|
|
4
6
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
5
7
|
import React from 'react';
|
|
6
|
-
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
7
|
-
import { EffectOptions } from '@flowgram.ai/node';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
@@ -21,6 +21,9 @@ interface VariableAbilityCommonContext {
|
|
|
21
21
|
node: FlowNodeEntity;
|
|
22
22
|
scope: Scope;
|
|
23
23
|
options: VariableAbilityOptions;
|
|
24
|
+
name: string;
|
|
25
|
+
formValues: EffectFuncProps['formValues'];
|
|
26
|
+
form: EffectFuncProps['form'];
|
|
24
27
|
}
|
|
25
28
|
interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
26
29
|
}
|
|
@@ -51,6 +54,9 @@ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions
|
|
|
51
54
|
interface VariableProviderProps$1 {
|
|
52
55
|
children: React.ReactElement;
|
|
53
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* PrivateScopeProvider provides the private scope to its children via context.
|
|
59
|
+
*/
|
|
54
60
|
declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
|
|
55
61
|
|
|
56
62
|
/**
|
|
@@ -61,6 +67,9 @@ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => R
|
|
|
61
67
|
interface VariableProviderProps {
|
|
62
68
|
children: React.ReactElement;
|
|
63
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* PublicScopeProvider provides the public scope to its children via context.
|
|
72
|
+
*/
|
|
64
73
|
declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
|
|
65
74
|
|
|
66
75
|
/**
|
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var import_core = require("@flowgram.ai/core");
|
|
|
52
52
|
var PublicScopeProvider = ({ children }) => {
|
|
53
53
|
const node = (0, import_core.useEntityFromContext)();
|
|
54
54
|
const publicScope = (0, import_react.useMemo)(() => node.getData(import_variable_plugin.FlowNodeVariableData).public, [node]);
|
|
55
|
-
return /* @__PURE__ */ import_react.default.createElement(import_variable_plugin.ScopeProvider, {
|
|
55
|
+
return /* @__PURE__ */ import_react.default.createElement(import_variable_plugin.ScopeProvider, { scope: publicScope }, children);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
// src/with-node-variables.tsx
|
|
@@ -79,7 +79,7 @@ var PrivateScopeProvider = ({ children }) => {
|
|
|
79
79
|
}
|
|
80
80
|
return variableData.private;
|
|
81
81
|
}, [node]);
|
|
82
|
-
return /* @__PURE__ */ import_react3.default.createElement(import_variable_plugin2.ScopeProvider, {
|
|
82
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_variable_plugin2.ScopeProvider, { scope: privateScope }, children);
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
// src/form-v2/create-provider-effect.ts
|
|
@@ -93,19 +93,23 @@ function createEffectFromVariableProvider(options) {
|
|
|
93
93
|
}
|
|
94
94
|
return variableData.public;
|
|
95
95
|
};
|
|
96
|
-
const transformValueToAST = ({ value, name, context }) => {
|
|
96
|
+
const transformValueToAST = ({ value, name, context, formValues, form }) => {
|
|
97
97
|
if (!context) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
const { node } = context;
|
|
101
101
|
const scope = getScope(node);
|
|
102
|
+
const parsedValue = options.parse(value, {
|
|
103
|
+
node,
|
|
104
|
+
scope,
|
|
105
|
+
options,
|
|
106
|
+
name,
|
|
107
|
+
formValues,
|
|
108
|
+
form
|
|
109
|
+
});
|
|
102
110
|
scope.ast.set(options.namespace || name || "", {
|
|
103
111
|
kind: import_variable_plugin3.ASTKind.VariableDeclarationList,
|
|
104
|
-
declarations:
|
|
105
|
-
node,
|
|
106
|
-
scope,
|
|
107
|
-
options
|
|
108
|
-
})
|
|
112
|
+
declarations: Array.isArray(parsedValue) ? parsedValue : [parsedValue]
|
|
109
113
|
});
|
|
110
114
|
};
|
|
111
115
|
return [
|
|
@@ -117,7 +121,10 @@ function createEffectFromVariableProvider(options) {
|
|
|
117
121
|
const disposable = options.onInit?.({
|
|
118
122
|
node: context.node,
|
|
119
123
|
scope,
|
|
120
|
-
options
|
|
124
|
+
options,
|
|
125
|
+
name: params.name,
|
|
126
|
+
formValues: params.formValues,
|
|
127
|
+
form: params.form
|
|
121
128
|
});
|
|
122
129
|
transformValueToAST(params);
|
|
123
130
|
return () => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/create-node-variable-plugin.ts","../src/with-node-variables.tsx","../src/components/PublicScopeProvider.tsx","../src/components/PrivateScopeProvider.tsx","../src/form-v2/create-provider-effect.ts","../src/form-v2/create-variable-provider-plugin.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nexport * from './create-node-variable-plugin';\nexport {\n VariableProviderAbilityOptions,\n VariableConsumerAbilityOptions,\n VariableAbilityParseContext,\n} from './types';\nexport { PrivateScopeProvider } from './components/PrivateScopeProvider';\nexport { PublicScopeProvider } from './components/PublicScopeProvider';\nexport { createEffectFromVariableProvider } from './form-v2/create-provider-effect';\nexport { createVariableProviderPlugin } from './form-v2/create-variable-provider-plugin';\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n// import { FormManager } from '@flowgram.ai/form-core';\nimport { NodeManager } from '@flowgram.ai/form-core';\nimport { definePluginCreator } from '@flowgram.ai/core';\n\nimport { withNodeVariables } from './with-node-variables';\n\n// import { withNodeVariables } from './with-node-variables';\n\nexport const createNodeVariablePlugin = definePluginCreator({\n onInit(ctx) {\n const nodeManager = ctx.get<NodeManager>(NodeManager);\n nodeManager.registerNodeRenderHoc(withNodeVariables);\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { NodeRenderHoc, type NodeRenderProps } from '@flowgram.ai/form-core';\n\nimport { PublicScopeProvider } from './components/PublicScopeProvider';\n\n// eslint-disable-next-line react/display-name\nexport const withNodeVariables: NodeRenderHoc = (Component) => (props: NodeRenderProps) =>\n (\n <PublicScopeProvider>\n <Component {...props} />\n </PublicScopeProvider>\n );\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\nexport const PublicScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const publicScope: Scope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);\n\n return <ScopeProvider
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-node-variable-plugin.ts","../src/with-node-variables.tsx","../src/components/PublicScopeProvider.tsx","../src/components/PrivateScopeProvider.tsx","../src/form-v2/create-provider-effect.ts","../src/form-v2/create-variable-provider-plugin.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nexport * from './create-node-variable-plugin';\nexport {\n VariableProviderAbilityOptions,\n VariableConsumerAbilityOptions,\n VariableAbilityParseContext,\n} from './types';\nexport { PrivateScopeProvider } from './components/PrivateScopeProvider';\nexport { PublicScopeProvider } from './components/PublicScopeProvider';\nexport { createEffectFromVariableProvider } from './form-v2/create-provider-effect';\nexport { createVariableProviderPlugin } from './form-v2/create-variable-provider-plugin';\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\n// import { FormManager } from '@flowgram.ai/form-core';\nimport { NodeManager } from '@flowgram.ai/form-core';\nimport { definePluginCreator } from '@flowgram.ai/core';\n\nimport { withNodeVariables } from './with-node-variables';\n\n// import { withNodeVariables } from './with-node-variables';\n\nexport const createNodeVariablePlugin = definePluginCreator({\n onInit(ctx) {\n const nodeManager = ctx.get<NodeManager>(NodeManager);\n nodeManager.registerNodeRenderHoc(withNodeVariables);\n },\n});\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React from 'react';\n\nimport { NodeRenderHoc, type NodeRenderProps } from '@flowgram.ai/form-core';\n\nimport { PublicScopeProvider } from './components/PublicScopeProvider';\n\n// eslint-disable-next-line react/display-name\nexport const withNodeVariables: NodeRenderHoc = (Component) => (props: NodeRenderProps) =>\n (\n <PublicScopeProvider>\n <Component {...props} />\n </PublicScopeProvider>\n );\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\n/**\n * PublicScopeProvider provides the public scope to its children via context.\n */\nexport const PublicScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const publicScope: Scope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);\n\n return <ScopeProvider scope={publicScope}>{children}</ScopeProvider>;\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport React, { useMemo } from 'react';\n\nimport { FlowNodeVariableData, type Scope, ScopeProvider } from '@flowgram.ai/variable-plugin';\nimport { useEntityFromContext } from '@flowgram.ai/core';\n\ninterface VariableProviderProps {\n children: React.ReactElement;\n}\n\n/**\n * PrivateScopeProvider provides the private scope to its children via context.\n */\nexport const PrivateScopeProvider = ({ children }: VariableProviderProps) => {\n const node = useEntityFromContext();\n\n const privateScope: Scope = useMemo(() => {\n const variableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n if (!variableData.private) {\n variableData.initPrivate();\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return variableData.private!;\n }, [node]);\n\n return <ScopeProvider scope={privateScope}>{children}</ScopeProvider>;\n};\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { FlowNodeVariableData, type Scope, ASTKind } from '@flowgram.ai/variable-plugin';\nimport { DataEvent, type Effect, type EffectOptions } from '@flowgram.ai/node';\nimport { FlowNodeEntity } from '@flowgram.ai/document';\n\nimport { type VariableProviderAbilityOptions } from '../types';\n\n/**\n * 根据 VariableProvider 生成 FormV2 的 Effect\n * @param options\n * @returns\n */\nexport function createEffectFromVariableProvider(\n options: VariableProviderAbilityOptions\n): EffectOptions[] {\n const getScope = (node: FlowNodeEntity): Scope => {\n const variableData: FlowNodeVariableData = node.getData(FlowNodeVariableData);\n\n if (options.private || options.scope === 'private') {\n return variableData.initPrivate();\n }\n return variableData.public;\n };\n\n const transformValueToAST: Effect = ({ value, name, context, formValues, form }) => {\n if (!context) {\n return;\n }\n const { node } = context;\n const scope = getScope(node);\n\n const parsedValue = options.parse(value, {\n node,\n scope,\n options,\n name,\n formValues,\n form,\n });\n\n // Fix: When parsedValue is not an array, transform it to array\n scope.ast.set(options.namespace || name || '', {\n kind: ASTKind.VariableDeclarationList,\n declarations: Array.isArray(parsedValue) ? parsedValue : [parsedValue],\n });\n };\n\n return [\n {\n event: DataEvent.onValueInit,\n effect: ((params) => {\n const { context } = params;\n\n const scope = getScope(context.node);\n const disposable = options.onInit?.({\n node: context.node,\n scope,\n options,\n name: params.name,\n formValues: params.formValues,\n form: params.form,\n });\n\n transformValueToAST(params);\n\n return () => {\n disposable?.dispose();\n };\n }) as Effect,\n },\n {\n event: DataEvent.onValueChange,\n effect: ((params) => {\n transformValueToAST(params);\n }) as Effect,\n },\n ];\n}\n","/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport { DataEvent, defineFormPluginCreator } from '@flowgram.ai/node';\n\nexport const createVariableProviderPlugin = defineFormPluginCreator({\n name: 'VariableProviderPlugin',\n onInit: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin init', ctx, opts);\n },\n onSetupFormMeta({ mergeEffect }) {\n mergeEffect({\n arr: [\n {\n event: DataEvent.onValueInitOrChange,\n effect: () => {\n // todo\n // console.log('>>> VariableProviderPlugin effect triggered');\n },\n },\n ],\n });\n },\n onDispose: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin dispose', ctx, opts);\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,uBAA4B;AAC5B,IAAAA,eAAoC;;;ACFpC,IAAAC,gBAAkB;;;ACAlB,mBAA+B;AAE/B,6BAAgE;AAChE,kBAAqC;AAS9B,IAAM,sBAAsB,CAAC,EAAE,SAAS,MAA6B;AAC1E,QAAM,WAAO,kCAAqB;AAElC,QAAM,kBAAqB,sBAAQ,MAAM,KAAK,QAAQ,2CAAoB,EAAE,QAAQ,CAAC,IAAI,CAAC;AAE1F,SAAO,6BAAAC,QAAA,cAAC,wCAAc,OAAO,eAAc,QAAS;AACtD;;;ADXO,IAAM,oBAAmC,CAAC,cAAc,CAAC,UAE5D,8BAAAC,QAAA,cAAC,2BACC,8BAAAA,QAAA,cAAC,aAAW,GAAG,OAAO,CACxB;;;ADHG,IAAM,+BAA2B,kCAAoB;AAAA,EAC1D,OAAO,KAAK;AACV,UAAM,cAAc,IAAI,IAAiB,4BAAW;AACpD,gBAAY,sBAAsB,iBAAiB;AAAA,EACrD;AACF,CAAC;;;AGbD,IAAAC,gBAA+B;AAE/B,IAAAC,0BAAgE;AAChE,IAAAC,eAAqC;AAS9B,IAAM,uBAAuB,CAAC,EAAE,SAAS,MAA6B;AAC3E,QAAM,WAAO,mCAAqB;AAElC,QAAM,mBAAsB,uBAAQ,MAAM;AACxC,UAAM,eAAqC,KAAK,QAAQ,4CAAoB;AAC5E,QAAI,CAAC,aAAa,SAAS;AACzB,mBAAa,YAAY;AAAA,IAC3B;AAEA,WAAO,aAAa;AAAA,EACtB,GAAG,CAAC,IAAI,CAAC;AAET,SAAO,8BAAAC,QAAA,cAAC,yCAAc,OAAO,gBAAe,QAAS;AACvD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;AACF;;;AC5EA,IAAAC,eAAmD;AAE5C,IAAM,mCAA+B,sCAAwB;AAAA,EAClE,MAAM;AAAA,EACN,QAAQ,CAAC,KAAK,SAAS;AAAA,EAGvB;AAAA,EACA,gBAAgB,EAAE,YAAY,GAAG;AAC/B,gBAAY;AAAA,MACV,KAAK;AAAA,QACH;AAAA,UACE,OAAO,uBAAU;AAAA,UACjB,QAAQ,MAAM;AAAA,UAGd;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,WAAW,CAAC,KAAK,SAAS;AAAA,EAG1B;AACF,CAAC;","names":["import_core","import_react","React","React","import_react","import_variable_plugin","import_core","React","import_variable_plugin","import_node"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/node-variable-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"inversify": "^6.0.1",
|
|
20
20
|
"reflect-metadata": "~0.2.2",
|
|
21
|
-
"@flowgram.ai/
|
|
22
|
-
"@flowgram.ai/
|
|
23
|
-
"@flowgram.ai/
|
|
24
|
-
"@flowgram.ai/
|
|
25
|
-
"@flowgram.ai/utils": "0.5.
|
|
26
|
-
"@flowgram.ai/variable-plugin": "0.5.
|
|
21
|
+
"@flowgram.ai/core": "0.5.6",
|
|
22
|
+
"@flowgram.ai/document": "0.5.6",
|
|
23
|
+
"@flowgram.ai/node": "0.5.6",
|
|
24
|
+
"@flowgram.ai/form-core": "0.5.6",
|
|
25
|
+
"@flowgram.ai/utils": "0.5.6",
|
|
26
|
+
"@flowgram.ai/variable-plugin": "0.5.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/bezier-js": "4.1.3",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"tsup": "^8.0.1",
|
|
37
37
|
"typescript": "^5.8.3",
|
|
38
38
|
"vitest": "^3.2.4",
|
|
39
|
-
"@flowgram.ai/
|
|
40
|
-
"@flowgram.ai/
|
|
39
|
+
"@flowgram.ai/eslint-config": "0.5.6",
|
|
40
|
+
"@flowgram.ai/ts-config": "0.5.6"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=16.8",
|