@flowgram.ai/node-variable-plugin 0.4.4 → 0.4.5
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 +3 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/esm/index.js
CHANGED
|
@@ -48,7 +48,7 @@ import { DataEvent } from "@flowgram.ai/node";
|
|
|
48
48
|
function createEffectFromVariableProvider(options) {
|
|
49
49
|
const getScope = (node) => {
|
|
50
50
|
const variableData = node.getData(FlowNodeVariableData3);
|
|
51
|
-
if (options.private) {
|
|
51
|
+
if (options.private || options.scope === "private") {
|
|
52
52
|
return variableData.initPrivate();
|
|
53
53
|
}
|
|
54
54
|
return variableData.public;
|
|
@@ -64,8 +64,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
64
64
|
declarations: options.parse(value, {
|
|
65
65
|
node,
|
|
66
66
|
scope,
|
|
67
|
-
options
|
|
68
|
-
formItem: void 0
|
|
67
|
+
options
|
|
69
68
|
})
|
|
70
69
|
});
|
|
71
70
|
};
|
|
@@ -78,8 +77,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
78
77
|
const disposable = options.onInit?.({
|
|
79
78
|
node: context.node,
|
|
80
79
|
scope,
|
|
81
|
-
options
|
|
82
|
-
formItem: void 0
|
|
80
|
+
options
|
|
83
81
|
});
|
|
84
82
|
if (disposable) {
|
|
85
83
|
scope.toDispose.push(disposable);
|
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 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
|
|
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 || options.scope === '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 }),\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 });\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,qBAAqB;AAChE,SAAS,4BAA4B;AAM9B,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,EAAE,OAAO,YAAY,KAAI,QAAS;AACjE;;;ADRO,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;AAM9B,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;AAE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AAC,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,7 +1,6 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
|
|
3
3
|
import { Disposable } from '@flowgram.ai/utils';
|
|
4
|
-
import { FormItem } from '@flowgram.ai/form-core';
|
|
5
4
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
6
5
|
import React from 'react';
|
|
7
6
|
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
@@ -20,7 +19,6 @@ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>
|
|
|
20
19
|
|
|
21
20
|
interface VariableAbilityCommonContext {
|
|
22
21
|
node: FlowNodeEntity;
|
|
23
|
-
formItem?: FormItem;
|
|
24
22
|
scope: Scope;
|
|
25
23
|
options: VariableAbilityOptions;
|
|
26
24
|
}
|
|
@@ -28,11 +26,13 @@ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
|
28
26
|
}
|
|
29
27
|
interface VariableAbilityOptions {
|
|
30
28
|
key?: string;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated use scope: 'private'
|
|
31
|
+
*/
|
|
31
32
|
private?: boolean;
|
|
32
33
|
namespace?: string;
|
|
33
34
|
scope?: 'private' | 'public';
|
|
34
35
|
onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
|
|
35
|
-
disableRemoveASTWhenFormItemDispose?: boolean;
|
|
36
36
|
[key: string]: any;
|
|
37
37
|
}
|
|
38
38
|
interface VariableAbilityParseContext extends VariableAbilityCommonContext {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
2
|
import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
|
|
3
3
|
import { Disposable } from '@flowgram.ai/utils';
|
|
4
|
-
import { FormItem } from '@flowgram.ai/form-core';
|
|
5
4
|
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
6
5
|
import React from 'react';
|
|
7
6
|
import * as _flowgram_ai_node from '@flowgram.ai/node';
|
|
@@ -20,7 +19,6 @@ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>
|
|
|
20
19
|
|
|
21
20
|
interface VariableAbilityCommonContext {
|
|
22
21
|
node: FlowNodeEntity;
|
|
23
|
-
formItem?: FormItem;
|
|
24
22
|
scope: Scope;
|
|
25
23
|
options: VariableAbilityOptions;
|
|
26
24
|
}
|
|
@@ -28,11 +26,13 @@ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
|
|
|
28
26
|
}
|
|
29
27
|
interface VariableAbilityOptions {
|
|
30
28
|
key?: string;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated use scope: 'private'
|
|
31
|
+
*/
|
|
31
32
|
private?: boolean;
|
|
32
33
|
namespace?: string;
|
|
33
34
|
scope?: 'private' | 'public';
|
|
34
35
|
onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
|
|
35
|
-
disableRemoveASTWhenFormItemDispose?: boolean;
|
|
36
36
|
[key: string]: any;
|
|
37
37
|
}
|
|
38
38
|
interface VariableAbilityParseContext extends VariableAbilityCommonContext {
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ var import_node = require("@flowgram.ai/node");
|
|
|
88
88
|
function createEffectFromVariableProvider(options) {
|
|
89
89
|
const getScope = (node) => {
|
|
90
90
|
const variableData = node.getData(import_variable_plugin3.FlowNodeVariableData);
|
|
91
|
-
if (options.private) {
|
|
91
|
+
if (options.private || options.scope === "private") {
|
|
92
92
|
return variableData.initPrivate();
|
|
93
93
|
}
|
|
94
94
|
return variableData.public;
|
|
@@ -104,8 +104,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
104
104
|
declarations: options.parse(value, {
|
|
105
105
|
node,
|
|
106
106
|
scope,
|
|
107
|
-
options
|
|
108
|
-
formItem: void 0
|
|
107
|
+
options
|
|
109
108
|
})
|
|
110
109
|
});
|
|
111
110
|
};
|
|
@@ -118,8 +117,7 @@ function createEffectFromVariableProvider(options) {
|
|
|
118
117
|
const disposable = options.onInit?.({
|
|
119
118
|
node: context.node,
|
|
120
119
|
scope,
|
|
121
|
-
options
|
|
122
|
-
formItem: void 0
|
|
120
|
+
options
|
|
123
121
|
});
|
|
124
122
|
if (disposable) {
|
|
125
123
|
scope.toDispose.push(disposable);
|
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 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
|
|
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 || options.scope === '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 }),\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 });\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,sBAAQ,MAAM,KAAK,QAAQ,2CAAoB,EAAE,QAAQ,CAAC,IAAI,CAAC;AAE1F,SAAO,6BAAAC,QAAA,cAAC,wCAAc,OAAO,EAAE,OAAO,YAAY,KAAI,QAAS;AACjE;;;ADRO,IAAM,oBAAmC,CAAC,cAAc,CAAC,UAE5D,8BAAAC,QAAA,cAAC,2BACC,8BAAAA,QAAA,cAAC,aAAW,GAAG,OAAO,CACxB;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B,cAAM,EAAE,QAAQ,IAAI;AAEpB,cAAM,QAAQ,SAAS,QAAQ,IAAI;AACnC,cAAM,aAAa,QAAQ,SAAS;AAAA,UAClC,MAAM,QAAQ;AAAA,UACd;AAAA,UACA;AAAA,QACF,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;;;ACpEA,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.4.
|
|
3
|
+
"version": "0.4.5",
|
|
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.4.
|
|
23
|
-
"@flowgram.ai/document": "0.4.
|
|
24
|
-
"@flowgram.ai/
|
|
25
|
-
"@flowgram.ai/
|
|
26
|
-
"@flowgram.ai/
|
|
27
|
-
"@flowgram.ai/variable-plugin": "0.4.
|
|
22
|
+
"@flowgram.ai/core": "0.4.5",
|
|
23
|
+
"@flowgram.ai/document": "0.4.5",
|
|
24
|
+
"@flowgram.ai/form-core": "0.4.5",
|
|
25
|
+
"@flowgram.ai/node": "0.4.5",
|
|
26
|
+
"@flowgram.ai/utils": "0.4.5",
|
|
27
|
+
"@flowgram.ai/variable-plugin": "0.4.5"
|
|
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.8.3",
|
|
42
42
|
"vitest": "^0.34.6",
|
|
43
|
-
"@flowgram.ai/eslint-config": "0.4.
|
|
44
|
-
"@flowgram.ai/ts-config": "0.4.
|
|
43
|
+
"@flowgram.ai/eslint-config": "0.4.5",
|
|
44
|
+
"@flowgram.ai/ts-config": "0.4.5"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"react": ">=16.8",
|