@flowgram.ai/node-variable-plugin 0.1.0

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,125 @@
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
+ // Hack: 新表单引擎暂时不支持 triggerSync
84
+ triggerSync: void 0
85
+ });
86
+ if (disposable) {
87
+ scope.toDispose.push(disposable);
88
+ }
89
+ transformValueToAST(params);
90
+ }
91
+ },
92
+ {
93
+ event: DataEvent.onValueChange,
94
+ effect: (params) => {
95
+ transformValueToAST(params);
96
+ }
97
+ }
98
+ ];
99
+ }
100
+
101
+ // src/form-v2/create-variable-provider-plugin.ts
102
+ import { DataEvent as DataEvent2, defineFormPluginCreator } from "@flowgram.ai/node";
103
+ var createVariableProviderPlugin = defineFormPluginCreator("VariableProviderPlugin", {
104
+ onInit: (ctx, opts) => {
105
+ },
106
+ effect: {
107
+ arr: [
108
+ {
109
+ event: DataEvent2.onValueInitOrChange,
110
+ effect: () => {
111
+ }
112
+ }
113
+ ]
114
+ },
115
+ onDispose: (ctx, opts) => {
116
+ }
117
+ });
118
+ export {
119
+ PrivateScopeProvider,
120
+ PublicScopeProvider,
121
+ createEffectFromVariableProvider,
122
+ createNodeVariablePlugin,
123
+ createVariableProviderPlugin
124
+ };
125
+ //# 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":["// 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","import 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","import 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","import 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","import { 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 // Hack: 新表单引擎暂时不支持 triggerSync\n triggerSync: undefined as any,\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","import { DataEvent, defineFormPluginCreator } from '@flowgram.ai/node';\n\nexport const createVariableProviderPlugin = defineFormPluginCreator('VariableProviderPlugin', {\n onInit: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin init', ctx, opts);\n },\n effect: {\n arr: [\n {\n event: DataEvent.onValueInitOrChange,\n effect: () => {\n // todo\n // console.log('>>> VariableProviderPlugin effect triggered');\n },\n },\n ],\n },\n onDispose: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin dispose', ctx, opts);\n },\n});\n"],"mappings":";AACA,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,UAA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;AAAA,MACE,OAAO,UAAU;AAAA,MACjB,QAAS,YAAU;AACjB,4BAAoB,MAAM;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;;;ACxEA,SAAS,aAAAC,YAAW,+BAA+B;AAE5C,IAAM,+BAA+B,wBAAwB,0BAA0B;AAAA,EAC5F,QAAQ,CAAC,KAAK,SAAS;AAAA,EAGvB;AAAA,EACA,QAAQ;AAAA,IACN,KAAK;AAAA,MACH;AAAA,QACE,OAAOA,WAAU;AAAA,QACjB,QAAQ,MAAM;AAAA,QAGd;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EACA,WAAW,CAAC,KAAK,SAAS;AAAA,EAG1B;AACF,CAAC;","names":["React","React","React","useMemo","FlowNodeVariableData","ScopeProvider","useEntityFromContext","FlowNodeVariableData","DataEvent"]}
@@ -0,0 +1,58 @@
1
+ import * as _flowgram_ai_core from '@flowgram.ai/core';
2
+ import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
3
+ import { FormItem } from '@flowgram.ai/form-core';
4
+ import { FlowNodeEntity } from '@flowgram.ai/document';
5
+ import { Disposable } from '@flowgram.ai/utils';
6
+ import React from 'react';
7
+ import * as _flowgram_ai_node from '@flowgram.ai/node';
8
+ import { EffectOptions } from '@flowgram.ai/node';
9
+
10
+ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
11
+
12
+ interface VariableAbilityCommonContext {
13
+ node: FlowNodeEntity;
14
+ formItem?: FormItem;
15
+ scope: Scope;
16
+ options: VariableAbilityOptions;
17
+ }
18
+ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
19
+ triggerSync: () => void;
20
+ }
21
+ interface VariableAbilityOptions {
22
+ key?: string;
23
+ private?: boolean;
24
+ namespace?: string;
25
+ scope?: 'private' | 'public';
26
+ onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
27
+ disableRemoveASTWhenFormItemDispose?: boolean;
28
+ [key: string]: any;
29
+ }
30
+ interface VariableAbilityParseContext extends VariableAbilityCommonContext {
31
+ }
32
+ interface VariableProviderAbilityOptions<V = any> extends VariableAbilityOptions {
33
+ parse: (v: V, ctx: VariableAbilityParseContext) => VariableDeclarationJSON[];
34
+ }
35
+ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions {
36
+ parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
37
+ }
38
+
39
+ interface VariableProviderProps$1 {
40
+ children: React.ReactElement;
41
+ }
42
+ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
43
+
44
+ interface VariableProviderProps {
45
+ children: React.ReactElement;
46
+ }
47
+ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
48
+
49
+ /**
50
+ * 根据 VariableProvider 生成 FormV2 的 Effect
51
+ * @param options
52
+ * @returns
53
+ */
54
+ declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
55
+
56
+ declare const createVariableProviderPlugin: (opts: unknown) => _flowgram_ai_node.FormPlugin<unknown>;
57
+
58
+ export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
@@ -0,0 +1,58 @@
1
+ import * as _flowgram_ai_core from '@flowgram.ai/core';
2
+ import { VariableDeclarationJSON, ASTNodeJSON, Scope } from '@flowgram.ai/variable-plugin';
3
+ import { FormItem } from '@flowgram.ai/form-core';
4
+ import { FlowNodeEntity } from '@flowgram.ai/document';
5
+ import { Disposable } from '@flowgram.ai/utils';
6
+ import React from 'react';
7
+ import * as _flowgram_ai_node from '@flowgram.ai/node';
8
+ import { EffectOptions } from '@flowgram.ai/node';
9
+
10
+ declare const createNodeVariablePlugin: _flowgram_ai_core.PluginCreator<unknown>;
11
+
12
+ interface VariableAbilityCommonContext {
13
+ node: FlowNodeEntity;
14
+ formItem?: FormItem;
15
+ scope: Scope;
16
+ options: VariableAbilityOptions;
17
+ }
18
+ interface VariableAbilityInitCtx extends VariableAbilityCommonContext {
19
+ triggerSync: () => void;
20
+ }
21
+ interface VariableAbilityOptions {
22
+ key?: string;
23
+ private?: boolean;
24
+ namespace?: string;
25
+ scope?: 'private' | 'public';
26
+ onInit?: (ctx: VariableAbilityInitCtx) => Disposable | undefined;
27
+ disableRemoveASTWhenFormItemDispose?: boolean;
28
+ [key: string]: any;
29
+ }
30
+ interface VariableAbilityParseContext extends VariableAbilityCommonContext {
31
+ }
32
+ interface VariableProviderAbilityOptions<V = any> extends VariableAbilityOptions {
33
+ parse: (v: V, ctx: VariableAbilityParseContext) => VariableDeclarationJSON[];
34
+ }
35
+ interface VariableConsumerAbilityOptions<V = any> extends VariableAbilityOptions {
36
+ parse: (v: V, ctx: VariableAbilityParseContext) => ASTNodeJSON | undefined;
37
+ }
38
+
39
+ interface VariableProviderProps$1 {
40
+ children: React.ReactElement;
41
+ }
42
+ declare const PrivateScopeProvider: ({ children }: VariableProviderProps$1) => React.JSX.Element;
43
+
44
+ interface VariableProviderProps {
45
+ children: React.ReactElement;
46
+ }
47
+ declare const PublicScopeProvider: ({ children }: VariableProviderProps) => React.JSX.Element;
48
+
49
+ /**
50
+ * 根据 VariableProvider 生成 FormV2 的 Effect
51
+ * @param options
52
+ * @returns
53
+ */
54
+ declare function createEffectFromVariableProvider(options: VariableProviderAbilityOptions): EffectOptions[];
55
+
56
+ declare const createVariableProviderPlugin: (opts: unknown) => _flowgram_ai_node.FormPlugin<unknown>;
57
+
58
+ export { PrivateScopeProvider, PublicScopeProvider, type VariableAbilityParseContext, type VariableConsumerAbilityOptions, type VariableProviderAbilityOptions, createEffectFromVariableProvider, createNodeVariablePlugin, createVariableProviderPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
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
+ // Hack: 新表单引擎暂时不支持 triggerSync
124
+ triggerSync: void 0
125
+ });
126
+ if (disposable) {
127
+ scope.toDispose.push(disposable);
128
+ }
129
+ transformValueToAST(params);
130
+ }
131
+ },
132
+ {
133
+ event: import_node.DataEvent.onValueChange,
134
+ effect: (params) => {
135
+ transformValueToAST(params);
136
+ }
137
+ }
138
+ ];
139
+ }
140
+
141
+ // src/form-v2/create-variable-provider-plugin.ts
142
+ var import_node2 = require("@flowgram.ai/node");
143
+ var createVariableProviderPlugin = (0, import_node2.defineFormPluginCreator)("VariableProviderPlugin", {
144
+ onInit: (ctx, opts) => {
145
+ },
146
+ effect: {
147
+ arr: [
148
+ {
149
+ event: import_node2.DataEvent.onValueInitOrChange,
150
+ effect: () => {
151
+ }
152
+ }
153
+ ]
154
+ },
155
+ onDispose: (ctx, opts) => {
156
+ }
157
+ });
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ PrivateScopeProvider,
161
+ PublicScopeProvider,
162
+ createEffectFromVariableProvider,
163
+ createNodeVariablePlugin,
164
+ createVariableProviderPlugin
165
+ });
166
+ //# 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":["export * 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","// 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","import 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","import 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","import 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","import { 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 // Hack: 新表单引擎暂时不支持 triggerSync\n triggerSync: undefined as any,\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","import { DataEvent, defineFormPluginCreator } from '@flowgram.ai/node';\n\nexport const createVariableProviderPlugin = defineFormPluginCreator('VariableProviderPlugin', {\n onInit: (ctx, opts) => {\n // todo\n // console.log('>>> VariableProviderPlugin init', ctx, opts);\n },\n effect: {\n arr: [\n {\n event: DataEvent.onValueInitOrChange,\n effect: () => {\n // todo\n // console.log('>>> VariableProviderPlugin effect triggered');\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;;;ACCA,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;;;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;AAM9B,IAAM,uBAAuB,CAAC,EAAE,SAAS,MAA6B;AAC3E,QAAM,WAAO,mCAAqB;AAElC,QAAM,mBAAsB,uBAAQ,MAA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,OAAO,sBAAU;AAAA,MACjB,QAAS,YAAU;AACjB,4BAAoB,MAAM;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AACF;;;ACxEA,IAAAC,eAAmD;AAE5C,IAAM,mCAA+B,sCAAwB,0BAA0B;AAAA,EAC5F,QAAQ,CAAC,KAAK,SAAS;AAAA,EAGvB;AAAA,EACA,QAAQ;AAAA,IACN,KAAK;AAAA,MACH;AAAA,QACE,OAAO,uBAAU;AAAA,QACjB,QAAQ,MAAM;AAAA,QAGd;AAAA,MACF;AAAA,IACF;AAAA,EACF;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,62 @@
1
+ {
2
+ "name": "@flowgram.ai/node-variable-plugin",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "exports": {
6
+ "types": "./dist/index.d.ts",
7
+ "import": "./dist/esm/index.js",
8
+ "require": "./dist/index.js"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "module": "./dist/esm/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "dependencies": {
17
+ "inversify": "^6.0.1",
18
+ "lodash": "^4.17.21",
19
+ "@flowgram.ai/core": "0.1.0",
20
+ "@flowgram.ai/document": "0.1.0",
21
+ "@flowgram.ai/form-core": "0.1.0",
22
+ "@flowgram.ai/node": "0.1.0",
23
+ "@flowgram.ai/utils": "0.1.0",
24
+ "@flowgram.ai/variable-plugin": "0.1.0"
25
+ },
26
+ "devDependencies": {
27
+ "@types/bezier-js": "4.1.3",
28
+ "@types/lodash": "^4.14.137",
29
+ "@types/react": "^18",
30
+ "@types/react-dom": "^18",
31
+ "@types/styled-components": "^5",
32
+ "@vitest/coverage-v8": "^0.32.0",
33
+ "eslint": "^8.54.0",
34
+ "react": "^18",
35
+ "react-dom": "^18",
36
+ "styled-components": "^5",
37
+ "tsup": "^8.0.1",
38
+ "typescript": "^5.0.4",
39
+ "vitest": "^0.34.6",
40
+ "@flowgram.ai/eslint-config": "0.1.0",
41
+ "@flowgram.ai/ts-config": "0.1.0"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=17",
45
+ "react-dom": ">=17",
46
+ "styled-components": ">=4"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "scripts": {
53
+ "build": "npm run build:fast -- --dts-resolve",
54
+ "build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
55
+ "build:watch": "npm run build:fast -- --dts-resolve",
56
+ "clean": "rimraf dist",
57
+ "test": "exit 0",
58
+ "test:cov": "exit 0",
59
+ "ts-check": "tsc --noEmit",
60
+ "watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
61
+ }
62
+ }