@flowgram.ai/form-materials 0.3.2 → 0.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowgram.ai/form-materials",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "homepage": "https://flowgram.ai/",
5
5
  "repository": "https://github.com/bytedance/flowgram.ai",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "@codemirror/view": "~6.38.0",
35
35
  "@codemirror/state": "~6.5.2",
36
36
  "typescript": "^5.8.3",
37
- "@flowgram.ai/json-schema": "0.3.2",
38
- "@flowgram.ai/editor": "0.3.2"
37
+ "@flowgram.ai/editor": "0.3.3",
38
+ "@flowgram.ai/json-schema": "0.3.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/lodash": "^4.14.137",
@@ -51,8 +51,8 @@
51
51
  "tsup": "^8.0.1",
52
52
  "typescript": "^5.8.3",
53
53
  "vitest": "^0.34.6",
54
- "@flowgram.ai/ts-config": "0.3.2",
55
- "@flowgram.ai/eslint-config": "0.3.2"
54
+ "@flowgram.ai/eslint-config": "0.3.3",
55
+ "@flowgram.ai/ts-config": "0.3.3"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": ">=16.8",
@@ -8,3 +8,5 @@ export * from './auto-rename-ref';
8
8
  export * from './provide-json-schema-outputs';
9
9
  export * from './sync-variable-title';
10
10
  export * from './validate-when-variable-sync';
11
+ export * from './listen-ref-value-change';
12
+ export * from './listen-ref-schema-change';
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "listen-ref-schema-change",
3
+ "depMaterials": [
4
+ "flow-value"
5
+ ],
6
+ "depPackages": [
7
+ "lodash",
8
+ "@flowgram.ai/json-schema"
9
+ ]
10
+ }
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';
7
+ import {
8
+ BaseType,
9
+ DataEvent,
10
+ Effect,
11
+ EffectFuncProps,
12
+ EffectOptions,
13
+ getNodeScope,
14
+ } from '@flowgram.ai/editor';
15
+
16
+ import { IFlowRefValue } from '../../typings';
17
+
18
+ /**
19
+ * Example:
20
+ * const formMeta = {
21
+ * effect: {
22
+ * 'inputsValues.*': listenRefSchemaChange(({ name, schema, form }) => {
23
+ * form.setValueIn(`${name}.schema`, schema);
24
+ * })
25
+ * }
26
+ * }
27
+ * @param cb
28
+ * @returns
29
+ */
30
+ export const listenRefSchemaChange = (
31
+ cb: (props: EffectFuncProps<IFlowRefValue> & { schema?: IJsonSchema }) => void
32
+ ): EffectOptions[] => [
33
+ {
34
+ event: DataEvent.onValueInitOrChange,
35
+ effect: ((params) => {
36
+ const { context, value } = params;
37
+
38
+ if (value?.type !== 'ref') {
39
+ return () => null;
40
+ }
41
+
42
+ const disposable = getNodeScope(context.node).available.trackByKeyPath<BaseType | undefined>(
43
+ value?.content || [],
44
+ (_type) => {
45
+ cb({ ...params, schema: JsonSchemaUtils.astToSchema(_type) });
46
+ },
47
+ {
48
+ selector: (_v) => _v?.type,
49
+ }
50
+ );
51
+ return () => {
52
+ disposable.dispose();
53
+ };
54
+ }) as Effect,
55
+ },
56
+ ];
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "listen-ref-value-change",
3
+ "depMaterials": [
4
+ "flow-value"
5
+ ],
6
+ "depPackages": [
7
+ "lodash"
8
+ ]
9
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import {
7
+ BaseVariableField,
8
+ DataEvent,
9
+ Effect,
10
+ EffectFuncProps,
11
+ EffectOptions,
12
+ getNodeScope,
13
+ } from '@flowgram.ai/editor';
14
+
15
+ import { IFlowRefValue } from '../../typings';
16
+
17
+ /**
18
+ * Example:
19
+ * const formMeta = {
20
+ * effect: {
21
+ * 'inputsValues.*': listenRefValueChange(({ name, variable, form }) => {
22
+ * const schema = JsonSchemaUtils.astToSchema(variable?.type);
23
+ * form.setValueIn(`${name}.schema`, schema);
24
+ * })
25
+ * }
26
+ * }
27
+ * @param cb
28
+ * @returns
29
+ */
30
+ export const listenRefValueChange = (
31
+ cb: (props: EffectFuncProps<IFlowRefValue> & { variable?: BaseVariableField }) => void
32
+ ): EffectOptions[] => [
33
+ {
34
+ event: DataEvent.onValueInitOrChange,
35
+ effect: ((params) => {
36
+ const { context, value } = params;
37
+
38
+ if (value?.type !== 'ref') {
39
+ return () => null;
40
+ }
41
+
42
+ const disposable = getNodeScope(context.node).available.trackByKeyPath(
43
+ value?.content || [],
44
+ (v) => {
45
+ cb({ ...params, variable: v });
46
+ }
47
+ );
48
+ return () => {
49
+ disposable.dispose();
50
+ };
51
+ }) as Effect,
52
+ },
53
+ ];
@@ -10,6 +10,7 @@ import {
10
10
  useTypeManager as useOriginTypeManager,
11
11
  TypePresetProvider as OriginTypePresetProvider,
12
12
  JsonSchemaTypeManager,
13
+ type JsonSchemaBasicType,
13
14
  } from '@flowgram.ai/json-schema';
14
15
 
15
16
  import { jsonSchemaTypePreset } from './type-definition';
@@ -36,4 +37,5 @@ export {
36
37
  JsonSchemaUtils,
37
38
  JsonSchemaTypeRegistry,
38
39
  ConstantRendererProps,
40
+ JsonSchemaBasicType,
39
41
  };