@flowgram.ai/node-variable-plugin 0.1.0-alpha.10

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.
@@ -0,0 +1,126 @@
1
+ // src/create-node-variable-plugin.ts
2
+ import { NodeManager } from "@flowgram.ai/form-core";
3
+ import { definePluginCreator } from "@flowgram.ai/core";
4
+
5
+ // src/with-node-variables.tsx
6
+ import React2 from "react";
7
+
8
+ // src/components/PublicScopeProvider.tsx
9
+ import React, { useMemo } from "react";
10
+ import { FlowNodeVariableData, ScopeProvider } from "@flowgram.ai/variable-plugin";
11
+ import { useEntityFromContext } from "@flowgram.ai/core";
12
+ var PublicScopeProvider = ({ children }) => {
13
+ const node = useEntityFromContext();
14
+ const publicScope = useMemo(() => node.getData(FlowNodeVariableData).public, [node]);
15
+ return /* @__PURE__ */ React.createElement(ScopeProvider, { value: { scope: publicScope } }, children);
16
+ };
17
+
18
+ // src/with-node-variables.tsx
19
+ var withNodeVariables = (Component) => (props) => /* @__PURE__ */ React2.createElement(PublicScopeProvider, null, /* @__PURE__ */ React2.createElement(Component, { ...props }));
20
+
21
+ // src/create-node-variable-plugin.ts
22
+ var createNodeVariablePlugin = definePluginCreator({
23
+ onInit(ctx) {
24
+ const nodeManager = ctx.get(NodeManager);
25
+ nodeManager.registerNodeRenderHoc(withNodeVariables);
26
+ }
27
+ });
28
+
29
+ // src/components/PrivateScopeProvider.tsx
30
+ import React3, { useMemo as useMemo2 } from "react";
31
+ import { FlowNodeVariableData as FlowNodeVariableData2, ScopeProvider as ScopeProvider2 } from "@flowgram.ai/variable-plugin";
32
+ import { useEntityFromContext as useEntityFromContext2 } from "@flowgram.ai/core";
33
+ var PrivateScopeProvider = ({ children }) => {
34
+ const node = useEntityFromContext2();
35
+ const privateScope = useMemo2(() => {
36
+ const variableData = node.getData(FlowNodeVariableData2);
37
+ if (!variableData.private) {
38
+ variableData.initPrivate();
39
+ }
40
+ return variableData.private;
41
+ }, [node]);
42
+ return /* @__PURE__ */ React3.createElement(ScopeProvider2, { value: { scope: privateScope } }, children);
43
+ };
44
+
45
+ // src/form-v2/create-provider-effect.ts
46
+ import { FlowNodeVariableData as FlowNodeVariableData3, ASTKind } from "@flowgram.ai/variable-plugin";
47
+ import { DataEvent } from "@flowgram.ai/node";
48
+ function createEffectFromVariableProvider(options) {
49
+ const getScope = (node) => {
50
+ const variableData = node.getData(FlowNodeVariableData3);
51
+ if (options.private) {
52
+ return variableData.initPrivate();
53
+ }
54
+ return variableData.public;
55
+ };
56
+ const transformValueToAST = ({ value, context }) => {
57
+ if (!context) {
58
+ return;
59
+ }
60
+ const { node } = context;
61
+ const scope = getScope(node);
62
+ scope.ast.set(options.namespace || "", {
63
+ kind: ASTKind.VariableDeclarationList,
64
+ declarations: options.parse(value, {
65
+ node,
66
+ scope,
67
+ options,
68
+ formItem: void 0
69
+ })
70
+ });
71
+ };
72
+ return [
73
+ {
74
+ event: DataEvent.onValueInit,
75
+ effect: (params) => {
76
+ const { context } = params;
77
+ const scope = getScope(context.node);
78
+ const disposable = options.onInit?.({
79
+ node: context.node,
80
+ scope,
81
+ options,
82
+ formItem: void 0
83
+ });
84
+ if (disposable) {
85
+ scope.toDispose.push(disposable);
86
+ }
87
+ transformValueToAST(params);
88
+ }
89
+ },
90
+ {
91
+ event: DataEvent.onValueChange,
92
+ effect: (params) => {
93
+ transformValueToAST(params);
94
+ }
95
+ }
96
+ ];
97
+ }
98
+
99
+ // src/form-v2/create-variable-provider-plugin.ts
100
+ import { DataEvent as DataEvent2, defineFormPluginCreator } from "@flowgram.ai/node";
101
+ var createVariableProviderPlugin = defineFormPluginCreator({
102
+ name: "VariableProviderPlugin",
103
+ onInit: (ctx, opts) => {
104
+ },
105
+ onSetupFormMeta({ mergeEffect }) {
106
+ mergeEffect({
107
+ arr: [
108
+ {
109
+ event: DataEvent2.onValueInitOrChange,
110
+ effect: () => {
111
+ }
112
+ }
113
+ ]
114
+ });
115
+ },
116
+ onDispose: (ctx, opts) => {
117
+ }
118
+ });
119
+ export {
120
+ PrivateScopeProvider,
121
+ PublicScopeProvider,
122
+ createEffectFromVariableProvider,
123
+ createNodeVariablePlugin,
124
+ createVariableProviderPlugin
125
+ };
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 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,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,c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,MACZ,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL;AAAA,MACE,OAAO,UAAU;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,UAAU;AAAA,MACjB,QAAS,CAAC,WAAW;AACnB,4BAAoB,MAAM;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;;;ACtEA,SAAS,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"]}
@@ -0,0 +1,85 @@
1
+ import * as _flowgram_ai_core from '@flowgram.ai/core';
2
+ import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
3
+ import { Disposable } from '@flowgram.ai/utils';
4
+ import { FormItem } from '@flowgram.ai/form-core';
5
+ import { FlowNodeEntity } from '@flowgram.ai/document';
6
+ import React from 'react';
7
+ import * as _flowgram_ai_node from '@flowgram.ai/node';
8
+ import { EffectOptions } from '@flowgram.ai/node';
9
+
10
+ /**
11
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
12
+ * SPDX-License-Identifier: MIT
13
+ */
14
+ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
15
+
16
+ /**
17
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
18
+ * SPDX-License-Identifier: MIT
19
+ */
20
+
21
+ interface VariableAbilityCommonContext {
22
+ node: FlowNodeEntity;
23
+ formItem?: FormItem;
24
+ scope: Scope;
25
+ options: VariableAbilityOptions;
26
+ }
27
+ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
28
+ }
29
+ interface VariableAbilityOptions {
30
+ key?: string;
31
+ private?: boolean;
32
+ namespace?: string;
33
+ scope?: 'private' | 'public';
34
+ onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
35
+ disableRemoveASTWhenFormItemDispose?: boolean;
36
+ [key: string]: any;
37
+ }
38
+ interface VariableAbilityParseContext extends VariableAbilityCommonContext {
39
+ }
40
+ interface VariableProviderAbilityOptions<V = any> extends VariableAbilityOptions {
41
+ parse: (v: V, ctx: VariableAbilityParseContext) => VariableDeclarationJSON[];
42
+ }
43
+ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions {
44
+ parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
45
+ }
46
+
47
+ /**
48
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
49
+ * SPDX-License-Identifier: MIT
50
+ */
51
+
52
+ interface VariableProviderProps$1 {
53
+ children: React.ReactElement;
54
+ }
55
+ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
56
+
57
+ /**
58
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
59
+ * SPDX-License-Identifier: MIT
60
+ */
61
+
62
+ interface VariableProviderProps {
63
+ children: React.ReactElement;
64
+ }
65
+ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
66
+
67
+ /**
68
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
69
+ * SPDX-License-Identifier: MIT
70
+ */
71
+
72
+ /**
73
+ * 根据 VariableProvider 生成 FormV2 的 Effect
74
+ * @param options
75
+ * @returns
76
+ */
77
+ declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
78
+
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>;
84
+
85
+ export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
@@ -0,0 +1,85 @@
1
+ import * as _flowgram_ai_core from '@flowgram.ai/core';
2
+ import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
3
+ import { Disposable } from '@flowgram.ai/utils';
4
+ import { FormItem } from '@flowgram.ai/form-core';
5
+ import { FlowNodeEntity } from '@flowgram.ai/document';
6
+ import React from 'react';
7
+ import * as _flowgram_ai_node from '@flowgram.ai/node';
8
+ import { EffectOptions } from '@flowgram.ai/node';
9
+
10
+ /**
11
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
12
+ * SPDX-License-Identifier: MIT
13
+ */
14
+ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
15
+
16
+ /**
17
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
18
+ * SPDX-License-Identifier: MIT
19
+ */
20
+
21
+ interface VariableAbilityCommonContext {
22
+ node: FlowNodeEntity;
23
+ formItem?: FormItem;
24
+ scope: Scope;
25
+ options: VariableAbilityOptions;
26
+ }
27
+ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
28
+ }
29
+ interface VariableAbilityOptions {
30
+ key?: string;
31
+ private?: boolean;
32
+ namespace?: string;
33
+ scope?: 'private' | 'public';
34
+ onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
35
+ disableRemoveASTWhenFormItemDispose?: boolean;
36
+ [key: string]: any;
37
+ }
38
+ interface VariableAbilityParseContext extends VariableAbilityCommonContext {
39
+ }
40
+ interface VariableProviderAbilityOptions<V = any> extends VariableAbilityOptions {
41
+ parse: (v: V, ctx: VariableAbilityParseContext) => VariableDeclarationJSON[];
42
+ }
43
+ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions {
44
+ parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
45
+ }
46
+
47
+ /**
48
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
49
+ * SPDX-License-Identifier: MIT
50
+ */
51
+
52
+ interface VariableProviderProps$1 {
53
+ children: React.ReactElement;
54
+ }
55
+ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
56
+
57
+ /**
58
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
59
+ * SPDX-License-Identifier: MIT
60
+ */
61
+
62
+ interface VariableProviderProps {
63
+ children: React.ReactElement;
64
+ }
65
+ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
66
+
67
+ /**
68
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
69
+ * SPDX-License-Identifier: MIT
70
+ */
71
+
72
+ /**
73
+ * 根据 VariableProvider 生成 FormV2 的 Effect
74
+ * @param options
75
+ * @returns
76
+ */
77
+ declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
78
+
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>;
84
+
85
+ export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ PrivateScopeProvider: () => PrivateScopeProvider,
34
+ PublicScopeProvider: () => PublicScopeProvider,
35
+ createEffectFromVariableProvider: () => createEffectFromVariableProvider,
36
+ createNodeVariablePlugin: () => createNodeVariablePlugin,
37
+ createVariableProviderPlugin: () => createVariableProviderPlugin
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+
41
+ // src/create-node-variable-plugin.ts
42
+ var import_form_core = require("@flowgram.ai/form-core");
43
+ var import_core2 = require("@flowgram.ai/core");
44
+
45
+ // src/with-node-variables.tsx
46
+ var import_react2 = __toESM(require("react"));
47
+
48
+ // src/components/PublicScopeProvider.tsx
49
+ var import_react = __toESM(require("react"));
50
+ var import_variable_plugin = require("@flowgram.ai/variable-plugin");
51
+ var import_core = require("@flowgram.ai/core");
52
+ var PublicScopeProvider = ({ children }) => {
53
+ const node = (0, import_core.useEntityFromContext)();
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, { value: { scope: publicScope } }, children);
56
+ };
57
+
58
+ // src/with-node-variables.tsx
59
+ var withNodeVariables = (Component) => (props) => /* @__PURE__ */ import_react2.default.createElement(PublicScopeProvider, null, /* @__PURE__ */ import_react2.default.createElement(Component, { ...props }));
60
+
61
+ // src/create-node-variable-plugin.ts
62
+ var createNodeVariablePlugin = (0, import_core2.definePluginCreator)({
63
+ onInit(ctx) {
64
+ const nodeManager = ctx.get(import_form_core.NodeManager);
65
+ nodeManager.registerNodeRenderHoc(withNodeVariables);
66
+ }
67
+ });
68
+
69
+ // src/components/PrivateScopeProvider.tsx
70
+ var import_react3 = __toESM(require("react"));
71
+ var import_variable_plugin2 = require("@flowgram.ai/variable-plugin");
72
+ var import_core3 = require("@flowgram.ai/core");
73
+ var PrivateScopeProvider = ({ children }) => {
74
+ const node = (0, import_core3.useEntityFromContext)();
75
+ const privateScope = (0, import_react3.useMemo)(() => {
76
+ const variableData = node.getData(import_variable_plugin2.FlowNodeVariableData);
77
+ if (!variableData.private) {
78
+ variableData.initPrivate();
79
+ }
80
+ return variableData.private;
81
+ }, [node]);
82
+ return /* @__PURE__ */ import_react3.default.createElement(import_variable_plugin2.ScopeProvider, { value: { scope: privateScope } }, children);
83
+ };
84
+
85
+ // src/form-v2/create-provider-effect.ts
86
+ var import_variable_plugin3 = require("@flowgram.ai/variable-plugin");
87
+ var import_node = require("@flowgram.ai/node");
88
+ function createEffectFromVariableProvider(options) {
89
+ const getScope = (node) => {
90
+ const variableData = node.getData(import_variable_plugin3.FlowNodeVariableData);
91
+ if (options.private) {
92
+ return variableData.initPrivate();
93
+ }
94
+ return variableData.public;
95
+ };
96
+ const transformValueToAST = ({ value, context }) => {
97
+ if (!context) {
98
+ return;
99
+ }
100
+ const { node } = context;
101
+ const scope = getScope(node);
102
+ scope.ast.set(options.namespace || "", {
103
+ kind: import_variable_plugin3.ASTKind.VariableDeclarationList,
104
+ declarations: options.parse(value, {
105
+ node,
106
+ scope,
107
+ options,
108
+ formItem: void 0
109
+ })
110
+ });
111
+ };
112
+ return [
113
+ {
114
+ event: import_node.DataEvent.onValueInit,
115
+ effect: (params) => {
116
+ const { context } = params;
117
+ const scope = getScope(context.node);
118
+ const disposable = options.onInit?.({
119
+ node: context.node,
120
+ scope,
121
+ options,
122
+ formItem: void 0
123
+ });
124
+ if (disposable) {
125
+ scope.toDispose.push(disposable);
126
+ }
127
+ transformValueToAST(params);
128
+ }
129
+ },
130
+ {
131
+ event: import_node.DataEvent.onValueChange,
132
+ effect: (params) => {
133
+ transformValueToAST(params);
134
+ }
135
+ }
136
+ ];
137
+ }
138
+
139
+ // src/form-v2/create-variable-provider-plugin.ts
140
+ var import_node2 = require("@flowgram.ai/node");
141
+ var createVariableProviderPlugin = (0, import_node2.defineFormPluginCreator)({
142
+ name: "VariableProviderPlugin",
143
+ onInit: (ctx, opts) => {
144
+ },
145
+ onSetupFormMeta({ mergeEffect }) {
146
+ mergeEffect({
147
+ arr: [
148
+ {
149
+ event: import_node2.DataEvent.onValueInitOrChange,
150
+ effect: () => {
151
+ }
152
+ }
153
+ ]
154
+ });
155
+ },
156
+ onDispose: (ctx, opts) => {
157
+ }
158
+ });
159
+ // Annotate the CommonJS export names for ESM import in node:
160
+ 0 && (module.exports = {
161
+ PrivateScopeProvider,
162
+ PublicScopeProvider,
163
+ createEffectFromVariableProvider,
164
+ createNodeVariablePlugin,
165
+ createVariableProviderPlugin
166
+ });
167
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 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,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O,QAAQ,MAAM;AAC1D,QAAI,CAAC,SAAS;AACZ;AAAA,IACF;AACA,UAAM,EAAE,KAAK,IAAI;AACjB,UAAM,QAAQ,SAAS,IAAI;AAE3B,UAAM,IAAI,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 ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@flowgram.ai/node-variable-plugin",
3
+ "version": "0.1.0-alpha.10",
4
+ "homepage": "https://flowgram.ai/",
5
+ "repository": "https://github.com/bytedance/flowgram.ai",
6
+ "license": "MIT",
7
+ "exports": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/esm/index.js",
10
+ "require": "./dist/index.js"
11
+ },
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/esm/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "dependencies": {
19
+ "inversify": "^6.0.1",
20
+ "reflect-metadata": "~0.2.2",
21
+ "lodash": "^4.17.21",
22
+ "@flowgram.ai/core": "0.1.0-alpha.10",
23
+ "@flowgram.ai/document": "0.1.0-alpha.10",
24
+ "@flowgram.ai/form-core": "0.1.0-alpha.10",
25
+ "@flowgram.ai/utils": "0.1.0-alpha.10",
26
+ "@flowgram.ai/node": "0.1.0-alpha.10",
27
+ "@flowgram.ai/variable-plugin": "0.1.0-alpha.10"
28
+ },
29
+ "devDependencies": {
30
+ "@types/bezier-js": "4.1.3",
31
+ "@types/lodash": "^4.14.137",
32
+ "@types/react": "^18",
33
+ "@types/react-dom": "^18",
34
+ "@types/styled-components": "^5",
35
+ "@vitest/coverage-v8": "^0.32.0",
36
+ "eslint": "^8.54.0",
37
+ "react": "^18",
38
+ "react-dom": "^18",
39
+ "styled-components": "^5",
40
+ "tsup": "^8.0.1",
41
+ "typescript": "^5.0.4",
42
+ "vitest": "^0.34.6",
43
+ "@flowgram.ai/eslint-config": "0.1.0-alpha.10",
44
+ "@flowgram.ai/ts-config": "0.1.0-alpha.10"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=16.8",
48
+ "react-dom": ">=16.8",
49
+ "styled-components": ">=4"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "scripts": {
56
+ "build": "npm run build:fast -- --dts-resolve",
57
+ "build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
58
+ "build:watch": "npm run build:fast -- --dts-resolve",
59
+ "clean": "rimraf dist",
60
+ "test": "exit 0",
61
+ "test:cov": "exit 0",
62
+ "ts-check": "tsc --noEmit",
63
+ "watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
64
+ }
65
+ }