@flowgram.ai/node-variable-plugin 0.2.15 → 0.2.17
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 +12 -11
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -79,9 +79,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
79
79
|
node: context.node,
|
|
80
80
|
scope,
|
|
81
81
|
options,
|
|
82
|
-
formItem: void 0
|
|
83
|
-
// Hack: 新表单引擎暂时不支持 triggerSync
|
|
84
|
-
triggerSync: void 0
|
|
82
|
+
formItem: void 0
|
|
85
83
|
});
|
|
86
84
|
if (disposable) {
|
|
87
85
|
scope.toDispose.push(disposable);
|
|
@@ -100,17 +98,20 @@ function createEffectFromVariableProvider(options) {
|
|
|
100
98
|
|
|
101
99
|
// src/form-v2/create-variable-provider-plugin.ts
|
|
102
100
|
import { DataEvent as DataEvent2, defineFormPluginCreator } from "@flowgram.ai/node";
|
|
103
|
-
var createVariableProviderPlugin = defineFormPluginCreator(
|
|
101
|
+
var createVariableProviderPlugin = defineFormPluginCreator({
|
|
102
|
+
name: "VariableProviderPlugin",
|
|
104
103
|
onInit: (ctx, opts) => {
|
|
105
104
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
onSetupFormMeta({ mergeEffect }) {
|
|
106
|
+
mergeEffect({
|
|
107
|
+
arr: [
|
|
108
|
+
{
|
|
109
|
+
event: DataEvent2.onValueInitOrChange,
|
|
110
|
+
effect: () => {
|
|
111
|
+
}
|
|
111
112
|
}
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
]
|
|
114
|
+
});
|
|
114
115
|
},
|
|
115
116
|
onDispose: (ctx, opts) => {
|
|
116
117
|
}
|
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":["// 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","
|
|
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 value={{ 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\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 value={{ 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) {\n return variableData.initPrivate();\n }\n return variableData.public;\n };\n\n const transformValueToAST: Effect = ({ value, context }) => {\n if (!context) {\n return;\n }\n const { node } = context;\n const scope = getScope(node);\n\n scope.ast.set(options.namespace || '', {\n kind: ASTKind.VariableDeclarationList,\n declarations: options.parse(value, {\n node,\n scope,\n options,\n formItem: undefined,\n }),\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 formItem: undefined,\n });\n\n if (disposable) {\n // 作用域销毁时同时销毁该监听\n scope.toDispose.push(disposable);\n }\n\n transformValueToAST(params);\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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AAC;","names":["React","React","React","useMemo","FlowNodeVariableData","ScopeProvider","useEntityFromContext","FlowNodeVariableData","DataEvent"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
|
|
3
|
+
import { Disposable } from '@flowgram.ai/utils';
|
|
3
4
|
import { FormItem } from '@flowgram.ai/form-core';
|
|
4
5
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
5
|
-
import { Disposable } from '@flowgram.ai/utils';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
8
8
|
import { EffectOptions } from '@flowgram.ai/node';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
12
|
+
* SPDX-License-Identifier: MIT
|
|
13
|
+
*/
|
|
10
14
|
declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
|
|
11
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
18
|
+
* SPDX-License-Identifier: MIT
|
|
19
|
+
*/
|
|
20
|
+
|
|
12
21
|
interface VariableAbilityCommonContext {
|
|
13
22
|
node: FlowNodeEntity;
|
|
14
23
|
formItem?: FormItem;
|
|
@@ -16,7 +25,6 @@ interface VariableAbilityCommonContext {
|
|
|
16
25
|
options: VariableAbilityOptions;
|
|
17
26
|
}
|
|
18
27
|
interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
19
|
-
triggerSync: () => void;
|
|
20
28
|
}
|
|
21
29
|
interface VariableAbilityOptions {
|
|
22
30
|
key?: string;
|
|
@@ -36,16 +44,31 @@ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions
|
|
|
36
44
|
parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
|
|
37
45
|
}
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
49
|
+
* SPDX-License-Identifier: MIT
|
|
50
|
+
*/
|
|
51
|
+
|
|
39
52
|
interface VariableProviderProps$1 {
|
|
40
53
|
children: React.ReactElement;
|
|
41
54
|
}
|
|
42
55
|
declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
|
|
43
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
59
|
+
* SPDX-License-Identifier: MIT
|
|
60
|
+
*/
|
|
61
|
+
|
|
44
62
|
interface VariableProviderProps {
|
|
45
63
|
children: React.ReactElement;
|
|
46
64
|
}
|
|
47
65
|
declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
|
|
48
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
69
|
+
* SPDX-License-Identifier: MIT
|
|
70
|
+
*/
|
|
71
|
+
|
|
49
72
|
/**
|
|
50
73
|
* 根据 VariableProvider 生成 FormV2 的 Effect
|
|
51
74
|
* @param options
|
|
@@ -53,6 +76,10 @@ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => Reac
|
|
|
53
76
|
*/
|
|
54
77
|
declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
81
|
+
* SPDX-License-Identifier: MIT
|
|
82
|
+
*/
|
|
83
|
+
declare const createVariableProviderPlugin: _flowgram_ai_node.FormPluginCreator<unknown>;
|
|
57
84
|
|
|
58
85
|
export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
|
|
3
|
+
import { Disposable } from '@flowgram.ai/utils';
|
|
3
4
|
import { FormItem } from '@flowgram.ai/form-core';
|
|
4
5
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
5
|
-
import { Disposable } from '@flowgram.ai/utils';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
8
8
|
import { EffectOptions } from '@flowgram.ai/node';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
12
|
+
* SPDX-License-Identifier: MIT
|
|
13
|
+
*/
|
|
10
14
|
declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
|
|
11
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
18
|
+
* SPDX-License-Identifier: MIT
|
|
19
|
+
*/
|
|
20
|
+
|
|
12
21
|
interface VariableAbilityCommonContext {
|
|
13
22
|
node: FlowNodeEntity;
|
|
14
23
|
formItem?: FormItem;
|
|
@@ -16,7 +25,6 @@ interface VariableAbilityCommonContext {
|
|
|
16
25
|
options: VariableAbilityOptions;
|
|
17
26
|
}
|
|
18
27
|
interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
19
|
-
triggerSync: () => void;
|
|
20
28
|
}
|
|
21
29
|
interface VariableAbilityOptions {
|
|
22
30
|
key?: string;
|
|
@@ -36,16 +44,31 @@ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions
|
|
|
36
44
|
parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
|
|
37
45
|
}
|
|
38
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
49
|
+
* SPDX-License-Identifier: MIT
|
|
50
|
+
*/
|
|
51
|
+
|
|
39
52
|
interface VariableProviderProps$1 {
|
|
40
53
|
children: React.ReactElement;
|
|
41
54
|
}
|
|
42
55
|
declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
|
|
43
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
59
|
+
* SPDX-License-Identifier: MIT
|
|
60
|
+
*/
|
|
61
|
+
|
|
44
62
|
interface VariableProviderProps {
|
|
45
63
|
children: React.ReactElement;
|
|
46
64
|
}
|
|
47
65
|
declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
|
|
48
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
69
|
+
* SPDX-License-Identifier: MIT
|
|
70
|
+
*/
|
|
71
|
+
|
|
49
72
|
/**
|
|
50
73
|
* 根据 VariableProvider 生成 FormV2 的 Effect
|
|
51
74
|
* @param options
|
|
@@ -53,6 +76,10 @@ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => Reac
|
|
|
53
76
|
*/
|
|
54
77
|
declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
81
|
+
* SPDX-License-Identifier: MIT
|
|
82
|
+
*/
|
|
83
|
+
declare const createVariableProviderPlugin: _flowgram_ai_node.FormPluginCreator<unknown>;
|
|
57
84
|
|
|
58
85
|
export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
|
package/dist/index.js
CHANGED
|
@@ -119,9 +119,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
119
119
|
node: context.node,
|
|
120
120
|
scope,
|
|
121
121
|
options,
|
|
122
|
-
formItem: void 0
|
|
123
|
-
// Hack: 新表单引擎暂时不支持 triggerSync
|
|
124
|
-
triggerSync: void 0
|
|
122
|
+
formItem: void 0
|
|
125
123
|
});
|
|
126
124
|
if (disposable) {
|
|
127
125
|
scope.toDispose.push(disposable);
|
|
@@ -140,17 +138,20 @@ function createEffectFromVariableProvider(options) {
|
|
|
140
138
|
|
|
141
139
|
// src/form-v2/create-variable-provider-plugin.ts
|
|
142
140
|
var import_node2 = require("@flowgram.ai/node");
|
|
143
|
-
var createVariableProviderPlugin = (0, import_node2.defineFormPluginCreator)(
|
|
141
|
+
var createVariableProviderPlugin = (0, import_node2.defineFormPluginCreator)({
|
|
142
|
+
name: "VariableProviderPlugin",
|
|
144
143
|
onInit: (ctx, opts) => {
|
|
145
144
|
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
onSetupFormMeta({ mergeEffect }) {
|
|
146
|
+
mergeEffect({
|
|
147
|
+
arr: [
|
|
148
|
+
{
|
|
149
|
+
event: import_node2.DataEvent.onValueInitOrChange,
|
|
150
|
+
effect: () => {
|
|
151
|
+
}
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
]
|
|
154
|
+
});
|
|
154
155
|
},
|
|
155
156
|
onDispose: (ctx, opts) => {
|
|
156
157
|
}
|
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":["
|
|
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 value={{ 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\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 value={{ 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) {\n return variableData.initPrivate();\n }\n return variableData.public;\n };\n\n const transformValueToAST: Effect = ({ value, context }) => {\n if (!context) {\n return;\n }\n const { node } = context;\n const scope = getScope(node);\n\n scope.ast.set(options.namespace || '', {\n kind: ASTKind.VariableDeclarationList,\n declarations: options.parse(value, {\n node,\n scope,\n options,\n formItem: undefined,\n }),\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 formItem: undefined,\n });\n\n if (disposable) {\n // 作用域销毁时同时销毁该监听\n scope.toDispose.push(disposable);\n }\n\n transformValueToAST(params);\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;AAM9B,IAAM,sBAAsB,CAAC,EAAE,SAAS,MAA6B;AAC1E,QAAM,WAAO,kCAAqB;AAElC,QAAM,kBAAqB,s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I,IAAI,QAAQ,aAAa,IAAI;AAAA,MACrC,MAAM,gCAAQ;AAAA,MACd,cAAc,QAAQ,MAAM,OAAO;AAAA,QACjC;AAAA,QACA;AAAA,QACA;AAAA,QACA,UAAU;AAAA,MACZ,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,MACE,OAAO,sBAAU;AAAA,MACjB,QAAS,CAAC,WAAW;AACnB,cAAM,EAAE,QAAQ,IAAI;AAEpB,cAAM,QAAQ,SAAS,QAAQ,IAAI;AACnC,cAAM,aAAa,QAAQ,SAAS;AAAA,UAClC,MAAM,QAAQ;AAAA,UACd;AAAA,UACA;AAAA,UACA,UAAU;AAAA,QACZ,CAAC;AAED,YAAI,YAAY;AAEd,gBAAM,UAAU,KAAK,UAAU;AAAA,QACjC;AAEA,4BAAoB,MAAM;AAAA,MAC5B;AAAA,IACF;AAAA,IACA;AAAA,MACE,OAAO,sBAAU;AAAA,MACjB,QAAS,CAAC,WAAW;AACnB,4BAAoB,MAAM;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;;;ACtEA,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.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"inversify": "^6.0.1",
|
|
20
20
|
"reflect-metadata": "~0.2.2",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
|
-
"@flowgram.ai/core": "0.2.
|
|
23
|
-
"@flowgram.ai/
|
|
24
|
-
"@flowgram.ai/
|
|
25
|
-
"@flowgram.ai/node": "0.2.
|
|
26
|
-
"@flowgram.ai/variable-plugin": "0.2.
|
|
27
|
-
"@flowgram.ai/utils": "0.2.
|
|
22
|
+
"@flowgram.ai/core": "0.2.17",
|
|
23
|
+
"@flowgram.ai/document": "0.2.17",
|
|
24
|
+
"@flowgram.ai/form-core": "0.2.17",
|
|
25
|
+
"@flowgram.ai/node": "0.2.17",
|
|
26
|
+
"@flowgram.ai/variable-plugin": "0.2.17",
|
|
27
|
+
"@flowgram.ai/utils": "0.2.17"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/bezier-js": "4.1.3",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"tsup": "^8.0.1",
|
|
41
41
|
"typescript": "^5.0.4",
|
|
42
42
|
"vitest": "^0.34.6",
|
|
43
|
-
"@flowgram.ai/eslint-config": "0.2.
|
|
44
|
-
"@flowgram.ai/ts-config": "0.2.
|
|
43
|
+
"@flowgram.ai/eslint-config": "0.2.17",
|
|
44
|
+
"@flowgram.ai/ts-config": "0.2.17"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=16.8",
|